Minor optimization of strtod

This commit is contained in:
Milo Yip 2014-11-23 16:45:07 +08:00
parent 3679c280dd
commit b855c3f73a
2 changed files with 4 additions and 15 deletions

View File

@ -102,8 +102,8 @@ struct DiyFp {
unsigned long index;
_BitScanReverse64(&index, f);
return DiyFp(f << (63 - index), e - (63 - index));
#elif 0//defined(__GNUC__)
int s = __builtin_clzll(f) + 1;
#elif defined(__GNUC__) && __GNUC__ >= 4
int s = __builtin_clzll(f);
return DiyFp(f << s, e - s);
#else
DiyFp res = *this;
@ -111,22 +111,11 @@ struct DiyFp {
res.f <<= 1;
res.e--;
}
// while (!(res.f & kDpHiddenBit)) {
// res.f <<= 1;
// res.e--;
// }
// res.f <<= (kDiySignificandSize - kDpSignificandSize - 1);
// res.e = res.e - (kDiySignificandSize - kDpSignificandSize - 1);
return res;
#endif
}
DiyFp NormalizeBoundary() const {
#if defined(_MSC_VER) && defined(_M_AMD64)
unsigned long index;
_BitScanReverse64(&index, f);
return DiyFp (f << (63 - index), e - (63 - index));
#else
DiyFp res = *this;
while (!(res.f & (kDpHiddenBit << 1))) {
res.f <<= 1;
@ -135,7 +124,6 @@ struct DiyFp {
res.f <<= (kDiySignificandSize - kDpSignificandSize - 2);
res.e = res.e - (kDiySignificandSize - kDpSignificandSize - 2);
return res;
#endif
}
void NormalizedBoundaries(DiyFp* minus, DiyFp* plus) const {

View File

@ -180,6 +180,7 @@ inline bool StrtodDiyFp(const char* decimals, size_t length, size_t decimalPosit
DiyFp(RAPIDJSON_UINT64_C2(0x98968000, 00000000), -40) // 10^7
};
int adjustment = dExp - actualExp - 1;
RAPIDJSON_ASSERT(adjustment >= 0 && adjustment < 7);
v = v * kPow10[adjustment];
if (length + adjustment > 19) // has more digits than decimal digits in 64-bit
error += kUlp / 2;