From b855c3f73a63b60387e37361b65ee531e0384465 Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Sun, 23 Nov 2014 16:45:07 +0800 Subject: [PATCH] Minor optimization of strtod --- include/rapidjson/internal/diyfp.h | 16 ++-------------- include/rapidjson/internal/strtod.h | 3 ++- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/include/rapidjson/internal/diyfp.h b/include/rapidjson/internal/diyfp.h index e6937ec..a8e47e1 100644 --- a/include/rapidjson/internal/diyfp.h +++ b/include/rapidjson/internal/diyfp.h @@ -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 { diff --git a/include/rapidjson/internal/strtod.h b/include/rapidjson/internal/strtod.h index ee34766..9a4daea 100644 --- a/include/rapidjson/internal/strtod.h +++ b/include/rapidjson/internal/strtod.h @@ -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(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]; if (length + adjustment > 19) // has more digits than decimal digits in 64-bit error += kUlp / 2;