diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2017-12-15 18:41:31 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2017-12-15 18:54:28 +0300 |
commit | 5e28b71457e8c8ce20e19a28ce44c9d9b5f47844 (patch) | |
tree | 712007ae2ce57a282bf265eb434838f495c6a9cc /source/blender/blenlib/intern | |
parent | de9e5a092659cf2424b55dca4ac6f149966fe427 (diff) |
math utils: Add utilities to scan bit and clear it
Diffstat (limited to 'source/blender/blenlib/intern')
-rw-r--r-- | source/blender/blenlib/intern/math_bits_inline.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/math_bits_inline.c b/source/blender/blenlib/intern/math_bits_inline.c index e967ecbb3a3..d96cf969dae 100644 --- a/source/blender/blenlib/intern/math_bits_inline.c +++ b/source/blender/blenlib/intern/math_bits_inline.c @@ -44,6 +44,18 @@ MINLINE unsigned int bitscan_forward_uint(unsigned int a) return (unsigned int)bitscan_forward_i((int)a); } +MINLINE int bitscan_forward_clear_i(int *a) +{ + int i = bitscan_forward_i(*a); + *a &= (*a) - 1; + return i; +} + +MINLINE unsigned int bitscan_forward_clear_uint(unsigned int *a) +{ + return (unsigned int)bitscan_forward_clear_i((int *)a); +} + MINLINE int bitscan_reverse_i(int a) { BLI_assert(a != 0); @@ -61,6 +73,19 @@ MINLINE unsigned int bitscan_reverse_uint(unsigned int a) return (unsigned int)bitscan_reverse_i((int)a); } +MINLINE int bitscan_reverse_clear_i(int *a) +{ + int i = bitscan_reverse_i(*a); + /* TODO(sergey): This could probably be optimized. */ + *a &= ~(1 << (sizeof(int) * 8 - i - 1)); + return i; +} + +MINLINE unsigned int bitscan_reverse_clear_uint(unsigned int *a) +{ + return (unsigned int)bitscan_reverse_clear_i((int *)a); +} + MINLINE unsigned int highest_order_bit_uint(unsigned int n) { if (n == 0) { |