]> gitweb.factorcode.org Git - factor.git/blobdiff - vm/bitwise_hacks.hpp
vm: Tweak Factor VM to compile with Microsoft Visual Studio on Windows, in addition...
[factor.git] / vm / bitwise_hacks.hpp
old mode 100644 (file)
new mode 100755 (executable)
index 6cd2a5b..1927cd4
@@ -4,8 +4,18 @@ namespace factor
 inline cell log2(cell x)
 {
        cell n;
-#if defined(FACTOR_X86) || defined(FACTOR_AMD64)
-       asm ("bsr %1, %0;":"=r"(n):"r"(x));
+#if defined(FACTOR_X86)
+       #if defined(_MSC_VER)
+               _BitScanReverse(&n,x);
+       #else
+               asm ("bsr %1, %0;":"=r"(n):"r"(x));
+       #endif
+#elif defined(FACTOR_AMD64)
+       #if defined(_MSC_VER)
+               _BitScanReverse64(&n,x);
+       #else
+               asm ("bsr %1, %0;":"=r"(n):"r"(x));
+       #endif
 #elif defined(FACTOR_PPC)
        asm ("cntlzw %1, %0;":"=r"(n):"r"(x));
        n = (31 - n);
@@ -22,7 +32,7 @@ inline cell rightmost_clear_bit(cell x)
 
 inline cell rightmost_set_bit(cell x)
 {
-       return log2(x & -x);
+       return log2(x & (~x + 1));
 }
 
 inline cell popcount(cell x)