diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2017-12-15 18:22:54 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2017-12-15 18:54:28 +0300 |
commit | 412de222f8711893f7ed66630b6b8a1473810ab2 (patch) | |
tree | bc16800b475eb5d2891c9f387f2b9e287c4a869c /source/blender/blenlib/intern/math_bits_inline.c | |
parent | 02ec0b53df0a966048500e659389dbb987847c49 (diff) |
Math utils: Add bit scan operations
Diffstat (limited to 'source/blender/blenlib/intern/math_bits_inline.c')
-rw-r--r-- | source/blender/blenlib/intern/math_bits_inline.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/math_bits_inline.c b/source/blender/blenlib/intern/math_bits_inline.c index 9f502d367cb..fdef0f9c9c6 100644 --- a/source/blender/blenlib/intern/math_bits_inline.c +++ b/source/blender/blenlib/intern/math_bits_inline.c @@ -27,6 +27,40 @@ #include "BLI_math_bits.h" +MINLINE int bitscan_forward_i(int a) +{ + BLI_assert(a != 0); +# ifdef _MSC_VER + unsigned long ctz; + _BitScanForward(&ctz, a); + return ctz; +#else + return __builtin_ctz((unsigned int)a); +#endif +} + +MINLINE unsigned int bitscan_forward_uint(unsigned int a) +{ + return (unsigned int)bitscan_forward_i((int)a); +} + +MINLINE int bitscan_reverse_i(int a) +{ + BLI_assert(a != 0); +# ifdef _MSC_VER + unsigned long clz; + _BitScanReverse(&clz, a); + return clz; +#else + return __builtin_clz((unsigned int)a); +#endif +} + +MINLINE unsigned int bitscan_reverse_uint(unsigned int a) +{ + return (unsigned int)bitscan_reverse_i((int)a); +} + MINLINE unsigned int highest_order_bit_uint(unsigned int n) { n |= (n >> 1); |