]> Savannah Git Hosting - gnulib.git/commitdiff
stdbit-h: Fix compilation error with MSVC in C++ mode.
authorBruno Haible <bruno@clisp.org>
Sat, 18 May 2024 00:20:59 +0000 (02:20 +0200)
committerBruno Haible <bruno@clisp.org>
Sat, 18 May 2024 00:20:59 +0000 (02:20 +0200)
* 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.

ChangeLog
lib/count-leading-zeros.h
lib/count-one-bits.h
lib/count-trailing-zeros.h
lib/stdbit.in.h

index c71376beb333dbf505749bd63ea7cc23d33287f0..535d7ba3824ca7467ef60cd2c0402a3a7d9abe36 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2024-05-17  Bruno Haible  <bruno@clisp.org>
+
+       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  <eggert@cs.ucla.edu>
 
        byteswap: port better to limited platforms
index 545749d6d2753cb51d81e928924b900eaccea5bb..a4b68c210645361d0e478768e04816334d374b5a 100644 (file)
@@ -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)                \
index 8d67f8718a4e29767ef71383e1d34aff85fa7aca..24bf8cc2327795c61159f9e701ee0119124b7012 100644 (file)
@@ -85,9 +85,12 @@ count_one_bits_32 (unsigned int x)
 #   include <intrin.h>
 #  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
index ed1e013114704cbcbdeb492e98aff00190880743..82de8731ec120523312b12aa4fa6f4664eaca05b 100644 (file)
@@ -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)               \
index a466a45d7718088da393b448c09a25edb5aa8ba5..9f9e60a5d38f2cd339f6d0caaa95a3c640b8c528 100644 (file)
@@ -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
+   <intrin.h> 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
+   <intrin.h> 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
+   <intrin.h> 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