]> gitweb.factorcode.org Git - factor.git/blobdiff - vm/bitwise_hacks.hpp
xmode.marker: more correct faster update-match-group
[factor.git] / vm / bitwise_hacks.hpp
index 86e4b3b85d1962e27eda6553a8f3fae7c5193986..ed338dd3039794708a4a9b8ebb1f1f3c1759dbe0 100644 (file)
@@ -4,29 +4,48 @@ inline cell log2(cell x) {
   cell n;
 #if defined(FACTOR_X86)
 #if defined(_MSC_VER)
-  _BitScanReverse(&n, x);
+  _BitScanReverse((unsigned long*)&n, x);
 #else
   asm("bsr %1, %0;" : "=r"(n) : "r"(x));
 #endif
+
 #elif defined(FACTOR_AMD64)
 #if defined(_MSC_VER)
   n = 0;
-  _BitScanReverse64((DWORD*)&n, x);
+  _BitScanReverse64((unsigned long*)&n, x);
 #else
   asm("bsr %1, %0;" : "=r"(n) : "r"(x));
 #endif
-#elif defined(FACTOR_PPC64)
-#if defined(__GNUC__)
-  n = (63 - __builtin_clzll(x));
+
+#elif defined(FACTOR_ARM)
+#if defined(_MSC_VER)
+  _BitScanReverse((unsigned long*)&n, x);
 #else
-#error Unsupported compiler
+  n = (31 - __builtin_clz(x));
 #endif
+
+#elif defined(FACTOR_ARM64)
+#if defined(_MSC_VER)
+  n = 0;
+  _BitScanReverse64((unsigned long*)&n, x);
+#else
+  n = (63 - __builtin_clzll(x));
+#endif
+
 #elif defined(FACTOR_PPC32)
 #if defined(__GNUC__)
   n = (31 - __builtin_clz(x));
 #else
 #error Unsupported compiler
 #endif
+
+#elif defined(FACTOR_PPC64)
+#if defined(__GNUC__)
+  n = (63 - __builtin_clzll(x));
+#else
+#error Unsupported compiler
+#endif
+
 #else
 #error Unsupported CPU
 #endif
@@ -46,16 +65,16 @@ inline cell popcount(cell x) {
 #endif
 #else
 #ifdef FACTOR_64
-  u64 k1 = 0x5555555555555555ll;
-  u64 k2 = 0x3333333333333333ll;
-  u64 k4 = 0x0f0f0f0f0f0f0f0fll;
-  u64 kf = 0x0101010101010101ll;
+  uint64_t k1 = 0x5555555555555555ll;
+  uint64_t k2 = 0x3333333333333333ll;
+  uint64_t k4 = 0x0f0f0f0f0f0f0f0fll;
+  uint64_t kf = 0x0101010101010101ll;
   cell ks = 56;
 #else
-  u32 k1 = 0x55555555;
-  u32 k2 = 0x33333333;
-  u32 k4 = 0xf0f0f0f;
-  u32 kf = 0x1010101;
+  uint32_t k1 = 0x55555555;
+  uint32_t k2 = 0x33333333;
+  uint32_t k4 = 0xf0f0f0f;
+  uint32_t kf = 0x1010101;
   cell ks = 24;
 #endif
 
@@ -69,7 +88,7 @@ inline cell popcount(cell x) {
 #endif
 }
 
-inline bool bitmap_p(u8* bitmap, cell index) {
+inline bool bitmap_p(uint8_t* bitmap, cell index) {
   cell byte = index >> 3;
   cell bit = index & 7;
   return (bitmap[byte] & (1 << bit)) != 0;