Skip to content

Commit cecf96f

Browse files
committed
Optimize bitlen <= 53 as pure 32-bit
1 parent 0244384 commit cecf96f

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

erts/emulator/beam/big.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2429,20 +2429,26 @@ big_to_double(Eterm x, double* resp)
24292429
msd_bits = erts_fit_in_bits_uint(msd);
24302430
bitlen = (Uint64)(xl-1) * D_EXP + msd_bits;
24312431

2432+
#if D_EXP == 64
2433+
ERTS_CT_ASSERT(SMALL_BITS > 53);
2434+
ASSERT(bitlen > 53);
2435+
#elif D_EXP == 32
24322436
if (bitlen <= 53) {
24332437
/*
24342438
* The value fits the double mantissa exactly, so accumulating
24352439
* digit by digit cannot round.
24362440
*/
2437-
double dbase = ((double)(D_MASK)+1);
2441+
ASSERT(xl == 1 || xl == 2);
24382442

2439-
d = 0.0;
2440-
for (i = xl; i-- > 0; ) {
2441-
d = d * dbase + v[i];
2443+
d = (double) v[0];
2444+
if (xl == 2) {
2445+
const double dbase = ((double)(D_MASK)+1);
2446+
d += ((double) v[1]) * dbase;
24422447
}
24432448
*resp = xsgn ? -d : d;
24442449
return 0;
24452450
}
2451+
#endif
24462452

24472453
/*
24482454
* More than 1024 bits is at least 2^1024, above the largest finite double

0 commit comments

Comments
 (0)