[Mesa-dev] [PATCH 2/3] util: Use win32 intrinsics for util_last_bit if present.

Mathias.Froehlich at gmx.net Mathias.Froehlich at gmx.net
Sat Aug 6 06:42:19 UTC 2016


From: Mathias Fröhlich <mathias.froehlich at web.de>

v2: Split into two patches.

Signed-off-by: Mathias Fröhlich <Mathias.Froehlich at web.de>
---
 src/util/bitscan.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/src/util/bitscan.h b/src/util/bitscan.h
index 0743fe7..a5bb34e 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;
+   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;
+   else
+      return 0;
 #else
    unsigned r = 0;
    while (u) {
-- 
2.5.5



More information about the mesa-dev mailing list