[Bf-blender-cvs] [05dbd65] master: Curve Fitting: inline dot-product (avoid temp vector)

Campbell Barton noreply at git.blender.org
Sun Sep 25 04:19:15 CEST 2016


Commit: 05dbd650986717e9c131b06943b38f6d96a4903b
Author: Campbell Barton
Date:   Sun Sep 25 11:40:18 2016 +1000
Branches: master
https://developer.blender.org/rB05dbd650986717e9c131b06943b38f6d96a4903b

Curve Fitting: inline dot-product (avoid temp vector)

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

M	extern/curve_fit_nd/intern/curve_fit_cubic.c

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

diff --git a/extern/curve_fit_nd/intern/curve_fit_cubic.c b/extern/curve_fit_nd/intern/curve_fit_cubic.c
index 1ca3850..ea482a1 100644
--- a/extern/curve_fit_nd/intern/curve_fit_cubic.c
+++ b/extern/curve_fit_nd/intern/curve_fit_cubic.c
@@ -665,13 +665,11 @@ static void cubic_from_points(
 	double alpha_l, alpha_r;
 #ifdef USE_VLA
 	double a[2][dims];
-	double tmp[dims];
 #else
 	double *a[2] = {
 	    alloca(sizeof(double) * dims),
 	    alloca(sizeof(double) * dims),
 	};
-	double *tmp = alloca(sizeof(double) * dims);
 #endif
 
 	{
@@ -682,22 +680,22 @@ static void cubic_from_points(
 			mul_vnvn_fl(a[0], tan_l, B1(u_prime[i]), dims);
 			mul_vnvn_fl(a[1], tan_r, B2(u_prime[i]), dims);
 
-			c[0][0] += dot_vnvn(a[0], a[0], dims);
-			c[0][1] += dot_vnvn(a[0], a[1], dims);
-			c[1][1] += dot_vnvn(a[1], a[1], dims);
+			const double b0_plus_b1 = B0plusB1(u_prime[i]);
+			const double b2_plus_b3 = B2plusB3(u_prime[i]);
 
-			c[1][0] = c[0][1];
+			/* inline dot product */
+			for (uint j = 0; j < dims; j++) {
+				const double tmp = (pt[j] - (p0[j] * b0_plus_b1)) + (p3[j] * b2_plus_b3);
 
-			{
-				const double b0_plus_b1 = B0plusB1(u_prime[i]);
-				const double b2_plus_b3 = B2plusB3(u_prime[i]);
-				for (uint j = 0; j < dims; j++) {
-					tmp[j] = (pt[j] - (p0[j] * b0_plus_b1)) + (p3[j] * b2_plus_b3);
-				}
+				x[0] += a[0][j] * tmp;
+				x[1] += a[1][j] * tmp;
 
-				x[0] += dot_vnvn(a[0], tmp, dims);
-				x[1] += dot_vnvn(a[1], tmp, dims);
+				c[0][0] += a[0][j] * a[0][j];
+				c[0][1] += a[0][j] * a[1][j];
+				c[1][1] += a[1][j] * a[1][j];
 			}
+
+			c[1][0] = c[0][1];
 		}
 
 		double det_C0_C1 = c[0][0] * c[1][1] - c[0][1] * c[1][0];




More information about the Bf-blender-cvs mailing list