diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2017-12-15 18:28:53 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2017-12-15 18:54:28 +0300 |
commit | de9e5a092659cf2424b55dca4ac6f149966fe427 (patch) | |
tree | 7553b653ad9bd7d930c1bd85795fd332507ef70e /source/blender/blenlib/intern | |
parent | 412de222f8711893f7ed66630b6b8a1473810ab2 (diff) |
Math utils: Go away form naive code for highest_order_bit_uint
Diffstat (limited to 'source/blender/blenlib/intern')
-rw-r--r-- | source/blender/blenlib/intern/math_bits_inline.c | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/source/blender/blenlib/intern/math_bits_inline.c b/source/blender/blenlib/intern/math_bits_inline.c index fdef0f9c9c6..e967ecbb3a3 100644 --- a/source/blender/blenlib/intern/math_bits_inline.c +++ b/source/blender/blenlib/intern/math_bits_inline.c @@ -63,12 +63,10 @@ MINLINE unsigned int bitscan_reverse_uint(unsigned int a) MINLINE unsigned int highest_order_bit_uint(unsigned int n) { - n |= (n >> 1); - n |= (n >> 2); - n |= (n >> 4); - n |= (n >> 8); - n |= (n >> 16); - return n - (n >> 1); + if (n == 0) { + return 0; + } + return 1 << (sizeof(unsigned int) * 8 - bitscan_reverse_uint(n)); } MINLINE unsigned short highest_order_bit_s(unsigned short n) |