[前][次][番号順一覧][スレッド一覧]

ruby-changes:59666

From: =E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3 <ko1@a...>
Date: Fri, 10 Jan 2020 21:17:38 +0900 (JST)
Subject: [ruby-changes:59666] 7fed7eb50b (master): fix Windows breakage

https://git.ruby-lang.org/ruby.git/commit/?id=7fed7eb50b

From 7fed7eb50b2b95ac4eeb3d29af3ce7b7d500032a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?=
 <shyouhei@r...>
Date: Fri, 10 Jan 2020 19:24:59 +0900
Subject: 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.

diff --git a/internal/bits.h b/internal/bits.h
index 802a8af..9d4e71f 100644
--- a/internal/bits.h
+++ b/internal/bits.h
@@ -215,7 +215,7 @@ nlz_int32(uint32_t x) https://github.com/ruby/ruby/blob/trunk/internal/bits.h#L215
 
 #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) https://github.com/ruby/ruby/blob/trunk/internal/bits.h#L244
 
 #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) {
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]