From: Bruno Haible Date: Sat, 18 May 2024 00:20:59 +0000 (+0200) Subject: stdbit-h: Fix compilation error with MSVC in C++ mode. X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=e38aef1f0eabcd74745598416d2831d13c787ad8;p=gnulib.git stdbit-h: Fix compilation error with MSVC in C++ mode. * lib/stdbit.in.h (_BitScanReverse, _BitScanReverse64, _BitScanForward, _BitScanForward64, __cpuid, __popcnt, __popcnt64): Declare with a prototype. * lib/count-leading-zeros.h (_BitScanReverse, _BitScanReverse64): Likewise. * lib/count-trailing-zeros.h (_BitScanForward, _BitScanForward64): Likewise. * lib/count-one-bits.h (__cpuid, __popcnt, __popcnt64): Likewise. --- diff --git a/ChangeLog b/ChangeLog index c71376beb3..535d7ba382 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2024-05-17 Bruno Haible + + stdbit-h: Fix compilation error with MSVC in C++ mode. + * lib/stdbit.in.h (_BitScanReverse, _BitScanReverse64, _BitScanForward, + _BitScanForward64, __cpuid, __popcnt, __popcnt64): Declare with a + prototype. + * lib/count-leading-zeros.h (_BitScanReverse, _BitScanReverse64): + Likewise. + * lib/count-trailing-zeros.h (_BitScanForward, _BitScanForward64): + Likewise. + * lib/count-one-bits.h (__cpuid, __popcnt, __popcnt64): Likewise. + 2024-05-17 Paul Eggert byteswap: port better to limited platforms diff --git a/lib/count-leading-zeros.h b/lib/count-leading-zeros.h index 545749d6d2..a4b68c2106 100644 --- a/lib/count-leading-zeros.h +++ b/lib/count-leading-zeros.h @@ -45,8 +45,10 @@ extern "C" { # define COUNT_LEADING_ZEROS(BUILTIN, MSC_BUILTIN, TYPE) \ return x ? BUILTIN (x) : CHAR_BIT * sizeof x; #elif _MSC_VER +extern unsigned char _BitScanReverse (unsigned long *, unsigned long); # pragma intrinsic (_BitScanReverse) # if defined _M_X64 +extern unsigned char _BitScanReverse64 (unsigned long *, unsigned long long); # pragma intrinsic (_BitScanReverse64) # endif # define COUNT_LEADING_ZEROS(BUILTIN, MSC_BUILTIN, TYPE) \ diff --git a/lib/count-one-bits.h b/lib/count-one-bits.h index 8d67f8718a..24bf8cc232 100644 --- a/lib/count-one-bits.h +++ b/lib/count-one-bits.h @@ -85,9 +85,12 @@ count_one_bits_32 (unsigned int x) # include # else /* Don't pollute the namespace with too many MSVC intrinsics. */ +extern void __cpuid (int[4], int); # pragma intrinsic (__cpuid) +extern unsigned int __popcnt (unsigned int); # pragma intrinsic (__popcnt) # if defined _M_X64 +extern unsigned long long __popcnt64 (unsigned long long); # pragma intrinsic (__popcnt64) # endif # endif diff --git a/lib/count-trailing-zeros.h b/lib/count-trailing-zeros.h index ed1e013114..82de8731ec 100644 --- a/lib/count-trailing-zeros.h +++ b/lib/count-trailing-zeros.h @@ -45,8 +45,10 @@ extern "C" { # define COUNT_TRAILING_ZEROS(BUILTIN, MSC_BUILTIN, TYPE) \ return x ? BUILTIN (x) : CHAR_BIT * sizeof x; #elif _MSC_VER +extern unsigned char _BitScanForward (unsigned long *, unsigned long); # pragma intrinsic (_BitScanForward) # if defined _M_X64 +extern unsigned char _BitScanForward64 (unsigned long *, unsigned long long); # pragma intrinsic (_BitScanForward64) # endif # define COUNT_TRAILING_ZEROS(BUILTIN, MSC_BUILTIN, TYPE) \ diff --git a/lib/stdbit.in.h b/lib/stdbit.in.h index a466a45d77..9f9e60a5d3 100644 --- a/lib/stdbit.in.h +++ b/lib/stdbit.in.h @@ -149,10 +149,16 @@ __gl_stdbit_clzll (unsigned long long int n) return n ? __builtin_clzll (n) : 8 * sizeof n; } #elif defined _MSC_VER + +/* Declare the few MSVC intrinsics that we need. We prefer not to include + because it would pollute the namespace. */ +extern unsigned char _BitScanReverse (unsigned long *, unsigned long); # pragma intrinsic (_BitScanReverse) # ifdef _M_X64 +extern unsigned char _BitScanReverse64 (unsigned long *, unsigned long long); # pragma intrinsic (_BitScanReverse64) # endif + _GL_STDBIT_INLINE int __gl_stdbit_clzl (unsigned long int n) { @@ -222,10 +228,16 @@ __gl_stdbit_ctzll (unsigned long long int n) return n ? __builtin_ctzll (n) : 8 * sizeof n; } #elif defined _MSC_VER + +/* Declare the few MSVC intrinsics that we need. We prefer not to include + because it would pollute the namespace. */ +extern unsigned char _BitScanForward (unsigned long *, unsigned long); # pragma intrinsic (_BitScanForward) # ifdef _M_X64 +extern unsigned char _BitScanForward64 (unsigned long *, unsigned long long); # pragma intrinsic (_BitScanForward64) # endif + _GL_STDBIT_INLINE int __gl_stdbit_ctzl (unsigned long int n) { @@ -324,9 +336,14 @@ __gl_stdbit_popcount_wide (unsigned long long int n) # ifdef _MSC_VER # if 1500 <= _MSC_VER && (defined _M_IX86 || defined _M_X64) +/* Declare the few MSVC intrinsics that we need. We prefer not to include + because it would pollute the namespace. */ +extern void __cpuid (int[4], int); # pragma intrinsic (__cpuid) +extern unsigned int __popcnt (unsigned int); # pragma intrinsic (__popcnt) # ifdef _M_X64 +extern unsigned long long __popcnt64 (unsigned long long); # pragma intrinsic (__popcnt64) # else _GL_STDC_COUNT_ONES_INLINE int