On MSVC 14 in 64-bit mode, in a testdir of the modules
  stdbit count-leading-zeros count-one-bits count-trailing-zeros ffs ffsl ffsll
I see these 7 test failures:

FAIL: test-stdc_bit_ceil.exe
FAIL: test-stdc_bit_floor.exe
FAIL: test-stdc_bit_width.exe
PASS: test-stdc_count_ones.exe
PASS: test-stdc_count_zeros.exe
FAIL: test-stdc_first_leading_one.exe
FAIL: test-stdc_first_leading_zero.exe
PASS: test-stdc_first_trailing_one.exe
PASS: test-stdc_first_trailing_zero.exe
PASS: test-stdc_has_single_bit.exe
FAIL: test-stdc_leading_ones.exe
FAIL: test-stdc_leading_zeros.exe
PASS: test-stdc_trailing_ones.exe
PASS: test-stdc_trailing_zeros.exe

This patch fixes it.


2024-05-17  Bruno Haible  <br...@clisp.org>

        stdbit-h: Fix leading-zeros/ones functions on 64-bit MSVC.
        * lib/stdbit.in.h (__gl_stdbit_clzll) [_MSC_VER]: On x86_64, use
        _BitScanReverse64.

diff --git a/lib/stdbit.in.h b/lib/stdbit.in.h
index b5b5870eba..a466a45d77 100644
--- a/lib/stdbit.in.h
+++ b/lib/stdbit.in.h
@@ -169,7 +169,7 @@ __gl_stdbit_clzll (unsigned long long int n)
 {
 # ifdef _M_X64
   unsigned long int r;
-  return 8 * sizeof n - (_BitScanReverse (&r, n) ? r + 1 : 0);
+  return 8 * sizeof n - (_BitScanReverse64 (&r, n) ? r + 1 : 0);
 # else
   unsigned long int hi = n >> 32;
   return __gl_stdbit_clzl (hi ? hi : n) + (hi ? 0 : 32);




Reply via email to