diff options
| -rw-r--r-- | zencore/include/zencore/intmath.h | 42 |
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 { |