}
/* Returns the number of trailing 0-bits in 'n'. Undefined if 'n' == 0. */
-#if __GNUC__ >= 4
+#if __GNUC__ >= 4 || _MSC_VER
/* Defined inline in util.h. */
#else
/* Returns the number of trailing 0-bits in 'n'. Undefined if 'n' == 0. */
{
return __builtin_clzll(n);
}
+#elif _MSC_VER
+static inline int
+raw_ctz(uint64_t n)
+{
+#ifdef _WIN64
+ uint32_t r = 0;
+ _BitScanForward64(&r, n);
+ return r;
+#else
+ uint32_t low = n, high, r = 0;
+ if (_BitScanForward(&r, low)) {
+ return r;
+ }
+ high = n >> 32;
+ _BitScanForward(&r, high);
+ return r + 32;
+#endif
+}
+
+static inline int
+raw_clz64(uint64_t n)
+{
+#ifdef _WIN64
+ uint32_t r = 0;
+ _BitScanReverse64(&r, n);
+ return 63 - r;
+#else
+ uint32_t low, high = n >> 32, r = 0;
+ if (_BitScanReverse(&r, high)) {
+ return 31 - r;
+ }
+ low = n;
+ _BitScanReverse(&r, low);
+ return 63 - r;
+#endif
+}
#else
/* Defined in util.c. */
int raw_ctz(uint64_t n);