aboutsummaryrefslogtreecommitdiff
path: root/zencore
diff options
context:
space:
mode:
authorMartin Ridgers <[email protected]>2021-09-09 13:21:57 +0200
committerMartin Ridgers <[email protected]>2021-09-14 14:29:27 +0200
commit8011e1285e1a5fb069b023b3932c451f3b775f2b (patch)
tree098603e7f7a9ffcc35d6b582045530828b360c19 /zencore
parentnullptr_t -> std::nullptr_t (diff)
downloadzen-8011e1285e1a5fb069b023b3932c451f3b775f2b.tar.xz
zen-8011e1285e1a5fb069b023b3932c451f3b775f2b.zip
Implementations of_BitScan*() intrinsics for non-MSVC toolchains
Diffstat (limited to 'zencore')
-rw-r--r--zencore/include/zencore/intmath.h42
1 files changed, 40 insertions, 2 deletions
diff --git a/zencore/include/zencore/intmath.h b/zencore/include/zencore/intmath.h
index 792b8b2b4..f5b9361d7 100644
--- a/zencore/include/zencore/intmath.h
+++ b/zencore/include/zencore/intmath.h
@@ -9,8 +9,46 @@
//////////////////////////////////////////////////////////////////////////
-#pragma intrinsic(_BitScanReverse)
-#pragma intrinsic(_BitScanReverse64)
+#if ZEN_COMPILER_MSC
+# pragma intrinsic(_BitScanReverse)
+# pragma intrinsic(_BitScanReverse64)
+#else
+inline uint8_t
+_BitScanReverse(unsigned long* Index, uint32_t Mask)
+{
+ if (Mask == 0)
+ {
+ return 0;
+ }
+
+ *Index = __builtin_clz(Mask);
+ return 1;
+}
+
+inline uint8_t
+_BitScanReverse64(unsigned long* Index, uint64_t Mask)
+{
+ if (Mask == 0)
+ {
+ return 0;
+ }
+
+ *Index = __builtin_clzll(Mask);
+ return 0;
+}
+
+inline uint8_t
+_BitScanForward64(unsigned long* Index, uint64_t Mask)
+{
+ if (Mask == 0)
+ {
+ return 0;
+ }
+
+ *Index = __builtin_ctzll(Mask);
+ return 0;
+}
+#endif
namespace zen {