[Bf-blender-cvs] [2a82b8a] master: Math Lib: add power of 2 min/max for unsigned ints

Campbell Barton noreply at git.blender.org
Sat Apr 5 12:54:37 CEST 2014


Commit: 2a82b8ade50836e186a78d3b52362cb8c59f3a39
Author: Campbell Barton
Date:   Sat Apr 5 21:39:46 2014 +1100
https://developer.blender.org/rB2a82b8ade50836e186a78d3b52362cb8c59f3a39

Math Lib: add power of 2 min/max for unsigned ints

===================================================================

M	source/blender/blenlib/BLI_math_base.h
M	source/blender/blenlib/intern/math_base_inline.c

===================================================================

diff --git a/source/blender/blenlib/BLI_math_base.h b/source/blender/blenlib/BLI_math_base.h
index 63a9bac..5458def 100644
--- a/source/blender/blenlib/BLI_math_base.h
+++ b/source/blender/blenlib/BLI_math_base.h
@@ -231,6 +231,9 @@ MINLINE int is_power_of_2_i(int n);
 MINLINE int power_of_2_max_i(int n);
 MINLINE int power_of_2_min_i(int n);
 
+MINLINE unsigned int power_of_2_max_u(unsigned int x);
+MINLINE unsigned int power_of_2_min_u(unsigned int x);
+
 MINLINE int iroundf(float a);
 MINLINE int divide_round_i(int a, int b);
 MINLINE int mod_i(int i, int n);
diff --git a/source/blender/blenlib/intern/math_base_inline.c b/source/blender/blenlib/intern/math_base_inline.c
index facc715..82c6e68 100644
--- a/source/blender/blenlib/intern/math_base_inline.c
+++ b/source/blender/blenlib/intern/math_base_inline.c
@@ -151,6 +151,27 @@ MINLINE int power_of_2_min_i(int n)
 	return n;
 }
 
+MINLINE unsigned int power_of_2_max_u(unsigned int x)
+{
+	x -= 1;
+	x |= (x >>  1);
+	x |= (x >>  2);
+	x |= (x >>  4);
+	x |= (x >>  8);
+	x |= (x >> 16);
+	return x + 1;
+}
+
+MINLINE unsigned power_of_2_min_u(unsigned x)
+{
+	x |= (x >>  1);
+	x |= (x >>  2);
+	x |= (x >>  4);
+	x |= (x >>  8);
+	x |= (x >> 16);
+	return x - (x >> 1);
+}
+
 MINLINE int iroundf(float a)
 {
 	return (int)floorf(a + 0.5f);




More information about the Bf-blender-cvs mailing list