bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Missing _BitScanReverse64()


From: Pádraig Brady
Subject: Re: Missing _BitScanReverse64()
Date: Mon, 05 Jan 2015 21:09:07 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0

On 05/01/15 20:05, Gisle Vanem wrote:
> I'm on Win-XP (32bit, MSVC v16) and get a link error on a
> missing '__BitScanReverse64()' in test-count-leading-zeros.c:.
> Here is the dis-asm:
> 
>   _count_leading_zeros_ll:
>           push            ebp
>           mov             ebp,esp
>           sub             esp,0x00000008
>   X$72:
>           mov             eax,dword ptr 0xc[ebp]
>           push            eax
>           mov             ecx,dword ptr 0x8[ebp]
>           push            ecx
>           lea             edx,-0x4[ebp]
>           push            edx
>           call            j^__BitScanReverse64
> 
> According to MSVC's <intrin.h>, the intrinsic for this function only
> exists on 64-bit machines:
> 
> /*__MACHINEW64          : WIN64(tm), 64 bit compilers only */
>    __MACHINEW64(unsigned char _BitScanForward64(unsigned long* Index,
>                 unsigned __int64 Mask))

Does the following address the issue for you?
It should drop back to the more generic slow path on 32 bit.
BTW do we have the same issue with __popcnt64 in count-one-bits.h?

thanks,
Pádraig

diff --git a/lib/count-leading-zeros.h b/lib/count-leading-zeros.h
index 722615f..77a72ed 100644
--- a/lib/count-leading-zeros.h
+++ b/lib/count-leading-zeros.h
@@ -37,7 +37,7 @@ _GL_INLINE_HEADER_BEGIN
 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
 # define COUNT_LEADING_ZEROS(BUILTIN, MSC_BUILTIN, TYPE)                \
   return x ? BUILTIN (x) : CHAR_BIT * sizeof x;
-#elif _MSC_VER
+#elif _MSC_VER && defined _M_X64
 # pragma intrinsic _BitReverse
 # pragma intrinsic _BitReverse64
 # define COUNT_LEADING_ZEROS(BUILTIN, MSC_BUILTIN, TYPE)                \





reply via email to

[Prev in Thread] Current Thread [Next in Thread]