Skip to content

Commit 2dc4e9d

Browse files
authored
d2s_small_table.h: fix small table POW5_INV_OFFSETS (#256)
Oddly enough, the Java generator was already updated, but apparently I forgot to update the file. Fixes #255.
1 parent bf6b14e commit 2dc4e9d

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

ryu/d2s_small_table.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#ifndef RYU_D2S_SMALL_TABLE_H
1818
#define RYU_D2S_SMALL_TABLE_H
1919

20+
#include <assert.h>
21+
2022
// Defines HAS_UINT128 and uint128_t if applicable.
2123
#include "ryu/d2s_intrinsics.h"
2224

@@ -41,11 +43,11 @@ static const uint64_t DOUBLE_POW5_INV_SPLIT2[15][2] = {
4143
{ 10313493231639821582u, 1313665730009899186u },
4244
{ 12701016819766672773u, 2032799256770390445u }
4345
};
44-
static const uint32_t POW5_INV_OFFSETS[19] = {
46+
static const uint32_t POW5_INV_OFFSETS[22] = {
4547
0x54544554, 0x04055545, 0x10041000, 0x00400414, 0x40010000, 0x41155555,
4648
0x00000454, 0x00010044, 0x40000000, 0x44000041, 0x50454450, 0x55550054,
4749
0x51655554, 0x40004000, 0x01000001, 0x00010500, 0x51515411, 0x05555554,
48-
0x00000000
50+
0x50411500, 0x40040000, 0x05040110, 0x00000000
4951
};
5052

5153
static const uint64_t DOUBLE_POW5_SPLIT2[13][2] = {
@@ -117,6 +119,7 @@ static inline void double_computeInvPow5(const uint32_t i, uint64_t* const resul
117119
const uint128_t b0 = ((uint128_t) m) * (mul[0] - 1);
118120
const uint128_t b2 = ((uint128_t) m) * mul[1]; // 1/5^base2 * 5^offset = 1/5^(base2-offset) = 1/5^i
119121
const uint32_t delta = pow5bits(base2) - pow5bits(i);
122+
assert(i / 16 < sizeof(POW5_INV_OFFSETS) / sizeof(POW5_INV_OFFSETS[0]));
120123
const uint128_t shiftedSum =
121124
((b0 >> delta) + (b2 << (64 - delta))) + 1 + ((POW5_INV_OFFSETS[i / 16] >> ((i % 16) << 1)) & 3);
122125
result[0] = (uint64_t) shiftedSum;
@@ -173,6 +176,7 @@ static inline void double_computeInvPow5(const uint32_t i, uint64_t* const resul
173176
}
174177
// high1 | sum | low0
175178
const uint32_t delta = pow5bits(base2) - pow5bits(i);
179+
assert(i / 16 < sizeof(POW5_INV_OFFSETS) / sizeof(POW5_INV_OFFSETS[0]));
176180
result[0] = shiftright128(low0, sum, delta) + 1 + ((POW5_INV_OFFSETS[i / 16] >> ((i % 16) << 1)) & 3);
177181
result[1] = shiftright128(sum, high1, delta);
178182
}

0 commit comments

Comments
 (0)