Commit b855c3f7 authored by Milo Yip's avatar Milo Yip

Minor optimization of strtod

parent 3679c280
...@@ -102,8 +102,8 @@ struct DiyFp { ...@@ -102,8 +102,8 @@ struct DiyFp {
unsigned long index; unsigned long index;
_BitScanReverse64(&index, f); _BitScanReverse64(&index, f);
return DiyFp(f << (63 - index), e - (63 - index)); return DiyFp(f << (63 - index), e - (63 - index));
#elif 0//defined(__GNUC__) #elif defined(__GNUC__) && __GNUC__ >= 4
int s = __builtin_clzll(f) + 1; int s = __builtin_clzll(f);
return DiyFp(f << s, e - s); return DiyFp(f << s, e - s);
#else #else
DiyFp res = *this; DiyFp res = *this;
...@@ -111,22 +111,11 @@ struct DiyFp { ...@@ -111,22 +111,11 @@ struct DiyFp {
res.f <<= 1; res.f <<= 1;
res.e--; 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; return res;
#endif #endif
} }
DiyFp NormalizeBoundary() const { 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; DiyFp res = *this;
while (!(res.f & (kDpHiddenBit << 1))) { while (!(res.f & (kDpHiddenBit << 1))) {
res.f <<= 1; res.f <<= 1;
...@@ -135,7 +124,6 @@ struct DiyFp { ...@@ -135,7 +124,6 @@ struct DiyFp {
res.f <<= (kDiySignificandSize - kDpSignificandSize - 2); res.f <<= (kDiySignificandSize - kDpSignificandSize - 2);
res.e = res.e - (kDiySignificandSize - kDpSignificandSize - 2); res.e = res.e - (kDiySignificandSize - kDpSignificandSize - 2);
return res; return res;
#endif
} }
void NormalizedBoundaries(DiyFp* minus, DiyFp* plus) const { void NormalizedBoundaries(DiyFp* minus, DiyFp* plus) const {
......
...@@ -179,7 +179,8 @@ inline bool StrtodDiyFp(const char* decimals, size_t length, size_t decimalPosit ...@@ -179,7 +179,8 @@ inline bool StrtodDiyFp(const char* decimals, size_t length, size_t decimalPosit
DiyFp(RAPIDJSON_UINT64_C2(0xf4240000, 00000000), -44), // 10^6 DiyFp(RAPIDJSON_UINT64_C2(0xf4240000, 00000000), -44), // 10^6
DiyFp(RAPIDJSON_UINT64_C2(0x98968000, 00000000), -40) // 10^7 DiyFp(RAPIDJSON_UINT64_C2(0x98968000, 00000000), -40) // 10^7
}; };
int adjustment = dExp - actualExp - 1; int adjustment = dExp - actualExp - 1;
RAPIDJSON_ASSERT(adjustment >= 0 && adjustment < 7);
v = v * kPow10[adjustment]; v = v * kPow10[adjustment];
if (length + adjustment > 19) // has more digits than decimal digits in 64-bit if (length + adjustment > 19) // has more digits than decimal digits in 64-bit
error += kUlp / 2; error += kUlp / 2;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment