summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
author卜部昌平 <shyouhei@ruby-lang.org>2020-01-10 19:24:59 +0900
committer卜部昌平 <shyouhei@ruby-lang.org>2020-01-10 21:17:15 +0900
commit7fed7eb50b2b95ac4eeb3d29af3ce7b7d500032a (patch)
tree72204697edb01f2f3866a99efeba690198d59f4b /internal
parentdb0398dc04a5eb1e76955f6a80fcfe3041782371 (diff)
fix Windows breakage
Fixing typo revealed that _BitScanReverse is BSR, which behaves differently than LZCNT. What we want here is LZCNT so we have to emulate.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/2824
Diffstat (limited to 'internal')
-rw-r--r--internal/bits.h4
1 files changed, 2 insertions, 2 deletions
diff --git a/internal/bits.h b/internal/bits.h
index 802a8af7eb..9d4e71fc8f 100644
--- a/internal/bits.h
+++ b/internal/bits.h
@@ -215,7 +215,7 @@ nlz_int32(uint32_t x)
#elif defined(_MSC_VER) && defined(_WIN64) /* &&! defined(__AVX2__) */
unsigned long r;
- return _BitScanReverse(&r, x) ? (int)r : 32;
+ return _BitScanReverse(&r, x) ? (31 - (int)r) : 32;
#elif __has_builtin(__builtin_clz)
STATIC_ASSERT(sizeof_int, sizeof(int) * CHAR_BIT == 32);
@@ -244,7 +244,7 @@ nlz_int64(uint64_t x)
#elif defined(_MSC_VER) && defined(_WIN64) /* &&! defined(__AVX2__) */
unsigned long r;
- return _BitScanReverse64(&r, x) ? (unsigned int)r : 64;
+ return _BitScanReverse64(&r, x) ? (63u - (unsigned int)r) : 64;
#elif __has_builtin(__builtin_clzl)
if (x == 0) {