From 2a82b8ade50836e186a78d3b52362cb8c59f3a39 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 5 Apr 2014 21:39:46 +1100 Subject: Math Lib: add power of 2 min/max for unsigned ints --- source/blender/blenlib/intern/math_base_inline.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'source/blender/blenlib/intern/math_base_inline.c') 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); -- cgit v1.2.3