diff --git a/lib/count-leading-zeros.h b/lib/count-leading-zeros.h index 5904eb7..39cce09 100644 --- a/lib/count-leading-zeros.h +++ b/lib/count-leading-zeros.h @@ -38,8 +38,23 @@ _GL_INLINE_HEADER_BEGIN # define COUNT_LEADING_ZEROS(BUILTIN, MSC_BUILTIN, TYPE) \ return x ? BUILTIN (x) : CHAR_BIT * sizeof x; #elif _MSC_VER -# pragma intrinsic _BitScanReverse -# pragma intrinsic _BitScanReverse64 +# pragma intrinsic (_BitScanReverse) +# ifndef _M_IX86 +# pragma intrinsic (_BitScanReverse64) +# else +COUNT_LEADING_ZEROS_INLINE unsigned char +_BitScanReverse64 (unsigned long *r, unsigned __int64 x) +{ + unsigned char c = _BitScanReverse (r, x >> 32); + if (! c) + { + c = _BitScanReverse (r, x); + if (c) + *r += 32; + } + return c; +} +# endif # define COUNT_LEADING_ZEROS(BUILTIN, MSC_BUILTIN, TYPE) \ do \ { \ diff --git a/lib/count-one-bits.h b/lib/count-one-bits.h index d54397f..528e3f0 100644 --- a/lib/count-one-bits.h +++ b/lib/count-one-bits.h @@ -72,9 +72,7 @@ count_one_bits_32 (unsigned int x) /* While gcc falls back to its own generic code if the machine on which it's running doesn't support popcount, with Microsoft's compiler we need to detect and fallback ourselves. */ -# pragma intrinsic __cpuid -# pragma intrinsic __popcnt -# pragma intrinsic __popcnt64 +# pragma intrinsic (__cpuid, __popcnt, __popcnt64) /* Return nonzero if popcount is supported. */ diff --git a/lib/count-trailing-zeros.h b/lib/count-trailing-zeros.h index 83ce2fb..b93236a 100644 --- a/lib/count-trailing-zeros.h +++ b/lib/count-trailing-zeros.h @@ -38,8 +38,22 @@ _GL_INLINE_HEADER_BEGIN # define COUNT_TRAILING_ZEROS(BUILTIN, MSC_BUILTIN, TYPE) \ return x ? BUILTIN (x) : CHAR_BIT * sizeof x; #elif _MSC_VER -# pragma intrinsic _BitScanForward -# pragma intrinsic _BitScanForward64 +# pragma intrinsic (_BitScanForward) +# ifndef _M_IX86 +# pragma intrinsic (_BitScanForward64) +# else +COUNT_TRAILING_ZEROS_INLINE unsigned char +_BitScanForward64 (unsigned long *r, unsigned __int64 x) +{ + unsigned char c = _BitScanForward (r, x); + if (! c) + { + c = _BitScanForward (r, x >> 32); + if (c) + *r += 32; + } + return c; +} # define COUNT_TRAILING_ZEROS(BUILTIN, MSC_BUILTIN, TYPE) \ do \ { \