diff --git a/source/blender/blenlib/BLI_math_base.h b/source/blender/blenlib/BLI_math_base.h index 63a9bac288e..5458def8de1 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 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);