[Bf-blender-cvs] [de9e5a09265] master: Math utils: Go away form naive code for highest_order_bit_uint
Sergey Sharybin
noreply at git.blender.org
Fri Dec 15 16:59:18 CET 2017
Commit: de9e5a092659cf2424b55dca4ac6f149966fe427
Author: Sergey Sharybin
Date: Fri Dec 15 16:28:53 2017 +0100
Branches: master
https://developer.blender.org/rBde9e5a092659cf2424b55dca4ac6f149966fe427
Math utils: Go away form naive code for highest_order_bit_uint
===================================================================
M source/blender/blenlib/intern/math_bits_inline.c
===================================================================
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)
More information about the Bf-blender-cvs
mailing list