diff options
author | Mathias Fröhlich <[email protected]> | 2016-08-06 07:26:51 +0200 |
---|---|---|
committer | Mathias Fröhlich <[email protected]> | 2016-08-10 09:30:07 +0200 |
commit | 0ce5ec8ece78f7936dc7bf0ad58fa1ed01783e25 (patch) | |
tree | 3e40f1729f82ee4b900fa963c9e7497c2b2b01c6 /src/util/bitscan.h | |
parent | 3f100b77f9a80828fbb3651ea013f9dd3913d047 (diff) |
util: Use win32 intrinsics for util_last_bit if present.
v2: Split into two patches.
v3: Fix off by one problem.
Signed-off-by: Mathias Fröhlich <[email protected]>
Reviewed-by: Brian Paul <[email protected]>
Tested-by: Brian Paul <[email protected]>
Diffstat (limited to 'src/util/bitscan.h')
-rw-r--r-- | src/util/bitscan.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/util/bitscan.h b/src/util/bitscan.h index 0743fe7d321..8afef81a990 100644 --- a/src/util/bitscan.h +++ b/src/util/bitscan.h @@ -157,6 +157,12 @@ util_last_bit(unsigned u) { #if defined(HAVE___BUILTIN_CLZ) return u == 0 ? 0 : 32 - __builtin_clz(u); +#elif defined(_MSC_VER) && (_M_IX86 || _M_ARM || _M_AMD64 || _M_IA64) + unsigned long index; + if (_BitScanReverse(&index, u)) + return index + 1; + else + return 0; #else unsigned r = 0; while (u) { @@ -177,6 +183,12 @@ util_last_bit64(uint64_t u) { #if defined(HAVE___BUILTIN_CLZLL) return u == 0 ? 0 : 64 - __builtin_clzll(u); +#elif defined(_MSC_VER) && (_M_AMD64 || _M_ARM || _M_IA64) + unsigned long index; + if (_BitScanReverse64(&index, u)) + return index + 1; + else + return 0; #else unsigned r = 0; while (u) { |