]> gitweb.factorcode.org Git - factor.git/blobdiff - vm/bitwise_hacks.hpp
Put brackets around ipv6 addresses in `inet6 present`
[factor.git] / vm / bitwise_hacks.hpp
index 0c04fa6e6e9b8141348f5980e9d6c30454a757ee..ed338dd3039794708a4a9b8ebb1f1f3c1759dbe0 100644 (file)
@@ -8,6 +8,7 @@ inline cell log2(cell x) {
 #else
   asm("bsr %1, %0;" : "=r"(n) : "r"(x));
 #endif
+
 #elif defined(FACTOR_AMD64)
 #if defined(_MSC_VER)
   n = 0;
@@ -15,18 +16,36 @@ inline cell log2(cell 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
@@ -59,11 +78,11 @@ inline cell popcount(cell x) {
   cell ks = 24;
 #endif
 
-  x = x - ((x >> 1) & k1);         /* put count of each 2 bits into those 2 bits */
-  x = (x & k2) + ((x >> 2) & k2);  /* put count of each 4 bits into those 4 bits */
-  x = (x + (x >> 4)) & k4;         /* put count of each 8 bits into those 8 bits */
-  x = (x * kf) >> ks;  /* returns 8 most significant bits of x + (x<<8) +
-                          (x<<16) + (x<<24) + ... */
+  x = x - ((x >> 1) & k1);         // put count of each 2 bits into those 2 bits
+  x = (x & k2) + ((x >> 2) & k2);  // put count of each 4 bits into those 4 bits
+  x = (x + (x >> 4)) & k4;         // put count of each 8 bits into those 8 bits
+  x = (x * kf) >> ks;  // returns 8 most significant bits of x + (x<<8) +
+                       // (x<<16) + (x<<24) + ...
 
   return x;
 #endif