[Bf-blender-cvs] [490b73f] master: cloth: Avoid calling powf with integer exponent

Sergej Reich noreply at git.blender.org
Tue Nov 11 18:18:14 CET 2014


Commit: 490b73ff22ce554eaed6f0804b1fd1e9f36ceb43
Author: Sergej Reich
Date:   Tue Nov 11 18:08:15 2014 +0100
Branches: master
https://developer.blender.org/rB490b73ff22ce554eaed6f0804b1fd1e9f36ceb43

cloth: Avoid calling powf with integer exponent

This is pretty slow and even shows up in profiling.

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

M	source/blender/blenkernel/intern/implicit.c

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

diff --git a/source/blender/blenkernel/intern/implicit.c b/source/blender/blenkernel/intern/implicit.c
index 9a8c32c..fe64af1 100644
--- a/source/blender/blenkernel/intern/implicit.c
+++ b/source/blender/blenkernel/intern/implicit.c
@@ -686,14 +686,18 @@ int	implicit_free(ClothModifierData *clmd)
 DO_INLINE float fb(float length, float L)
 {
 	float x = length / L;
-	return (-11.541f * powf(x, 4) + 34.193f * powf(x, 3) - 39.083f * powf(x, 2) + 23.116f * x - 9.713f);
+	float xx = x * x;
+	float xxx = xx * x;
+	float xxxx = xxx * x;
+	return (-11.541f * xxxx + 34.193f * xxx - 39.083f * xx + 23.116f * x - 9.713f);
 }
 
 DO_INLINE float fbderiv(float length, float L)
 {
 	float x = length/L;
-
-	return (-46.164f * powf(x, 3) + 102.579f * powf(x, 2) - 78.166f * x + 23.116f);
+	float xx = x * x;
+	float xxx = xx * x;
+	return (-46.164f * xxx + 102.579f * xx - 78.166f * x + 23.116f);
 }
 
 DO_INLINE float fbstar(float length, float L, float kb, float cb)




More information about the Bf-blender-cvs mailing list