Commit 91a831e2d0a3062756b395abc8c1e33b1f80022c

Cameron Gutman 2021-01-03T14:02:55

Implement SDL_MostSignificantBitIndex32 using MSVC intrinsics

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
diff --git a/include/SDL_bits.h b/include/SDL_bits.h
index d4c2816..f073abe 100644
--- a/include/SDL_bits.h
+++ b/include/SDL_bits.h
@@ -73,6 +73,12 @@ SDL_MostSignificantBitIndex32(Uint32 x)
         return -1;
     }
     return 31 - _SDL_clz_watcom(x);
+#elif defined(_MSC_VER)
+    unsigned long index;
+    if (_BitScanReverse(&index, x)) {
+        return index;
+    }
+    return -1;
 #else
     /* Based off of Bit Twiddling Hacks by Sean Eron Anderson
      * <seander@cs.stanford.edu>, released in the public domain.