diff options
author | Campbell Barton <ideasman42@gmail.com> | 2014-04-05 14:39:46 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2014-04-05 14:54:20 +0400 |
commit | 2a82b8ade50836e186a78d3b52362cb8c59f3a39 (patch) | |
tree | 7483753c3ef3c14fe217ff7b529d5f84a191a462 /source/blender/blenlib/intern/math_base_inline.c | |
parent | 95ac6bc9e5a909fba2a248fcd619cf3ac9bdb7a4 (diff) |
Math Lib: add power of 2 min/max for unsigned ints
Diffstat (limited to 'source/blender/blenlib/intern/math_base_inline.c')
-rw-r--r-- | source/blender/blenlib/intern/math_base_inline.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/math_base_inline.c b/source/blender/blenlib/intern/math_base_inline.c index facc7150ab8..82c6e68ccc2 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); |