From 823fd5b4933cd67c1965a29a2fa2743635dd4d9b Mon Sep 17 00:00:00 2001 From: jasnell Date: Fri, 8 Feb 2019 09:18:29 -0800 Subject: [PATCH] deps: float fix for building HdrHistogram on Win x86 From: https://github.com/mcollina/native-hdr-histogram/commit/c63e97151dcff9b9aed1d8ea5e4f5964c69be32fideps: PR-URL: https://github.com/nodejs/node/pull/25378 Reviewed-By: Matteo Collina Reviewed-By: Gireesh Punathil Reviewed-By: Stephen Belanger Reviewed-By: Richard Lau Reviewed-By: Anna Henningsen --- deps/histogram/src/hdr_histogram.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/deps/histogram/src/hdr_histogram.c b/deps/histogram/src/hdr_histogram.c index 1d7343442d3b67..d9565b802e3564 100644 --- a/deps/histogram/src/hdr_histogram.c +++ b/deps/histogram/src/hdr_histogram.c @@ -91,14 +91,29 @@ static int64_t power(int64_t base, int64_t exp) } #if defined(_MSC_VER) -#pragma intrinsic(_BitScanReverse64) +# if defined(_WIN64) +# pragma intrinsic(_BitScanReverse64) +# else +# pragma intrinsic(_BitScanReverse) +# endif #endif static int32_t get_bucket_index(const struct hdr_histogram* h, int64_t value) { #if defined(_MSC_VER) uint32_t leading_zero = 0; - _BitScanReverse64(&leading_zero, value | h->sub_bucket_mask); + int64_t masked_value = value | h->sub_bucket_mask; +# if defined(_WIN64) + _BitScanReverse64(&leading_zero, masked_value); +# else + uint32_t high = masked_value >> 32; + if (_BitScanReverse(&leading_zero, high)) { + leading_zero += 32; + } else { + uint32_t low = masked_value & 0x00000000FFFFFFFF; + _BitScanReverse(&leading_zero, low); + } +# endif int32_t pow2ceiling = 64 - (63 - leading_zero); /* smallest power of 2 containing value */ #else int32_t pow2ceiling = 64 - __builtin_clzll(value | h->sub_bucket_mask); /* smallest power of 2 containing value */