[quake3-commits] r1990 - trunk/code/qcommon
DONOTREPLY at icculus.org
DONOTREPLY at icculus.org
Sun May 15 10:55:47 EDT 2011
Author: thilo
Date: 2011-05-15 10:55:47 -0400 (Sun, 15 May 2011)
New Revision: 1990
Modified:
trunk/code/qcommon/q_math.c
Log:
Optimise VectorNormalize functions, patch by Matt Turner
Modified: trunk/code/qcommon/q_math.c
===================================================================
--- trunk/code/qcommon/q_math.c 2011-05-15 14:49:38 UTC (rev 1989)
+++ trunk/code/qcommon/q_math.c 2011-05-15 14:55:47 UTC (rev 1990)
@@ -787,10 +787,12 @@
float length, ilength;
length = v[0]*v[0] + v[1]*v[1] + v[2]*v[2];
- length = sqrt (length);
if ( length ) {
- ilength = 1/length;
+ /* writing it this way allows gcc to recognize that rsqrt can be used */
+ ilength = 1/(float)sqrt (length);
+ /* sqrt(length) = length * (1 / sqrt(length)) */
+ length *= ilength;
v[0] *= ilength;
v[1] *= ilength;
v[2] *= ilength;
@@ -803,11 +805,13 @@
float length, ilength;
length = v[0]*v[0] + v[1]*v[1] + v[2]*v[2];
- length = sqrt (length);
if (length)
{
- ilength = 1/length;
+ /* writing it this way allows gcc to recognize that rsqrt can be used */
+ ilength = 1/(float)sqrt (length);
+ /* sqrt(length) = length * (1 / sqrt(length)) */
+ length *= ilength;
out[0] = v[0]*ilength;
out[1] = v[1]*ilength;
out[2] = v[2]*ilength;
More information about the quake3-commits
mailing list