From 52d571e189d5ba48dbbc2ad0cf24608f30c6bbc2 Mon Sep 17 00:00:00 2001 From: Sergej Reich Date: Tue, 11 Nov 2014 18:16:20 +0100 Subject: Avoid calling powf with integer exponent in more places Move powX functions from particle code into math library and use them. --- source/blender/blenlib/BLI_math_base.h | 5 +++++ source/blender/blenlib/intern/math_base_inline.c | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) (limited to 'source/blender/blenlib') diff --git a/source/blender/blenlib/BLI_math_base.h b/source/blender/blenlib/BLI_math_base.h index 07de074e717..5711d09b530 100644 --- a/source/blender/blenlib/BLI_math_base.h +++ b/source/blender/blenlib/BLI_math_base.h @@ -157,6 +157,11 @@ static const int NAN_INT = 0x7FC00000; /******************************* Float ******************************/ +MINLINE float pow2f(float x); +MINLINE float pow3f(float x); +MINLINE float pow4f(float x); +MINLINE float pow7f(float x); + MINLINE float sqrt3f(float f); MINLINE double sqrt3d(double d); diff --git a/source/blender/blenlib/intern/math_base_inline.c b/source/blender/blenlib/intern/math_base_inline.c index e6217329145..39116d6f30f 100644 --- a/source/blender/blenlib/intern/math_base_inline.c +++ b/source/blender/blenlib/intern/math_base_inline.c @@ -44,6 +44,24 @@ # define UNLIKELY(x) (x) #endif +/* powf is really slow for raising to integer powers. */ +MINLINE float pow2f(float x) +{ + return x * x; +} +MINLINE float pow3f(float x) +{ + return pow2f(x) * x; +} +MINLINE float pow4f(float x) +{ + return pow2f(pow2f(x)); +} +MINLINE float pow7f(float x) +{ + return pow2f(pow3f(x)) * x; +} + MINLINE float sqrt3f(float f) { if (UNLIKELY(f == 0.0f)) return 0.0f; -- cgit v1.2.3