diff options
author | Dmitri Smirnov <dmitrism@microsoft.com> | 2016-02-23 19:39:02 (GMT) |
---|---|---|
committer | Jason Evans <jasone@canonware.com> | 2016-02-24 02:55:45 (GMT) |
commit | b41a07c31a53cb91729f69b4a23e3a8801ee9846 (patch) | |
tree | bb0b940b7e6ffe24f316e2758d8e675ea23f3fad /include/msvc_compat | |
parent | ae45142adc12d39793c45ecac4dafad5674a4591 (diff) | |
download | jemalloc-b41a07c31a53cb91729f69b4a23e3a8801ee9846.zip jemalloc-b41a07c31a53cb91729f69b4a23e3a8801ee9846.tar.gz jemalloc-b41a07c31a53cb91729f69b4a23e3a8801ee9846.tar.bz2 |
Fix Windows build issues
This resolves #333.
Diffstat (limited to 'include/msvc_compat')
-rw-r--r-- | include/msvc_compat/strings.h | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/include/msvc_compat/strings.h b/include/msvc_compat/strings.h index f01ffdd..a3ee250 100644 --- a/include/msvc_compat/strings.h +++ b/include/msvc_compat/strings.h @@ -21,7 +21,37 @@ static __forceinline int ffs(int x) return (ffsl(x)); } +# ifdef _M_X64 +# pragma intrinsic(_BitScanForward64) +# endif + +static __forceinline int ffsll(unsigned __int64 x) +{ + unsigned long i; +#ifdef _M_X64 + if (_BitScanForward64(&i, x)) + return (i + 1); + return (0); +#else +// Fallback for 32-bit build where 64-bit version not available +// assuming little endian + union { + unsigned __int64 ll; + unsigned long l[2]; + } s; + + s.ll = x; + + if (_BitScanForward(&i, s.l[0])) + return (i + 1); + else if(_BitScanForward(&i, s.l[1])) + return (i + 33); + return (0); +#endif +} + #else +# define ffsll(x) __builtin_ffsll(x) # define ffsl(x) __builtin_ffsl(x) # define ffs(x) __builtin_ffs(x) #endif |