From c4693cc86f5e8b4de5c30263954dc55b866fc9cb Mon Sep 17 00:00:00 2001 From: Joao Paulo Magalhaes Date: Mon, 16 Nov 2020 11:58:03 +0000 Subject: [PATCH] re #33: win32 is working --- include/fast_float/float_common.h | 18 +++++++++++++++--- tests/basictest.cpp | 24 +++++++++++++++++++++--- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/include/fast_float/float_common.h b/include/fast_float/float_common.h index a98a54b..93782e9 100644 --- a/include/fast_float/float_common.h +++ b/include/fast_float/float_common.h @@ -90,6 +90,7 @@ struct value128 { /* result might be undefined when input_num is zero */ fastfloat_really_inline int leading_zeroes(uint64_t input_num) { #ifdef FASTFLOAT_VISUAL_STUDIO +#if defined(_M_X64) || defined(_M_ARM64) unsigned long leading_zero = 0; // Search the mask data from most significant bit (MSB) // to least significant bit (LSB) for a set bit (1). @@ -97,6 +98,17 @@ fastfloat_really_inline int leading_zeroes(uint64_t input_num) { return (int)(63 - leading_zero); else return 64; +#else + if(!input_num) return 64; + int n = 0; + if(input_num & uint64_t(0xffffffff00000000)) input_num >>= 32, n |= 32; + if(input_num & uint64_t( 0xffff0000)) input_num >>= 16, n |= 16; + if(input_num & uint64_t( 0xff00)) input_num >>= 8, n |= 8; + if(input_num & uint64_t( 0xf0)) input_num >>= 4, n |= 4; + if(input_num & uint64_t( 0xc)) input_num >>= 2, n |= 2; + if(input_num & uint64_t( 0x2)) input_num >>= 1, n |= 1; + return 63 - n; +#endif #else return __builtin_clzll(input_num); #endif @@ -109,9 +121,9 @@ fastfloat_really_inline int leading_zeroes(uint64_t input_num) { #if !defined(_M_X64) && !defined(_M_ARM64) // _umul128 for x86, arm // this is a slow emulation routine for 32-bit Windows // -fastfloat_really_inline uint64_t __emulu(uint32_t x, uint32_t y) { - return x * (uint64_t)y; -} +//fastfloat_really_inline uint64_t __emulu(uint32_t x, uint32_t y) { +// return x * (uint64_t)y; +//} fastfloat_really_inline uint64_t _umul128(uint64_t ab, uint64_t cd, uint64_t *hi) { uint64_t ad = __emulu((uint32_t)(ab >> 32), (uint32_t)cd); diff --git a/tests/basictest.cpp b/tests/basictest.cpp index 8acb9ca..8d9d750 100644 --- a/tests/basictest.cpp +++ b/tests/basictest.cpp @@ -1,9 +1,14 @@ #include "fast_float/fast_float.h" #include -inline void Assert(bool Assertion) { - if (!Assertion) - throw std::runtime_error("bug"); +#define Q(x) #x +#define QUOTE(x) Q(x) +#define Assert(assertion) \ + if (!(assertion)) {\ + AssertionFailed(__FILE__ ":" QUOTE(__LINE__) ": assertion failed: " #assertion);\ + } +inline void AssertionFailed(const char *msg) { + throw std::runtime_error(msg); } template std::string to_string(T d) { @@ -327,7 +332,20 @@ bool test_fixed_only() { return true; } + void test_leading_zeroes() + { + constexpr const uint64_t bit = 1; + Assert(fast_float::leading_zeroes(0) == 64); + Assert(fast_float::leading_zeroes(bit << 0) == 63); + Assert(fast_float::leading_zeroes(bit << 1) == 62); + Assert(fast_float::leading_zeroes(bit << 2) == 61); + Assert(fast_float::leading_zeroes(bit << 61) == 2); + Assert(fast_float::leading_zeroes(bit << 62) == 1); + Assert(fast_float::leading_zeroes(bit << 63) == 0); + } + int main() { + test_leading_zeroes(); Assert(test_fixed_only()); Assert(test_scientific_only()); Assert(issue8());