diff options
author | Chris Robinson <[email protected]> | 2018-12-15 20:28:52 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2018-12-15 20:28:52 -0800 |
commit | a6a5634adb1bdec44fa7cb8557e5b6d59642d7aa (patch) | |
tree | fc68e681fd6da605f3cb43847f15ad0ac9019dfa /Alc/panning.cpp | |
parent | dea077cbae1f180a5c7ee77517ea73901f59aff2 (diff) |
Reorder some math terms to help optimizations
Because floating-point math is not associative ((a*b)*c does not necessarily
give the same result as a*(b*c)), the ordering of terms can inhibit reuse of
temporary values. For example, both
coeffs[9] = 2.091650066f * y * (3.0f*x*x - y*y);
and
coeffs[15] = 2.091650066f * x * (x*x - 3.0f*y*y);
contain x*x and y*y terms that could be calculated once, stored in temporary
registers, and reused to multiply with 3. But since 3.0f*(x*x) would produce
different results, the compiler is not allowed to make that optimization. If,
however, the multiply with 3 is moved to the right side:
coeffs[9] = 2.091650066f * y * (x*x*3.0f - y*y);
and
coeffs[15] = 2.091650066f * x * (x*x - y*y*3.0f);
in both cases x*x and y*y are calculated first in their respective groups,
guaranteeing the same results for both instances prior to the multiply with 3
and allowing the compiler to reuse those intermediate values.
Diffstat (limited to 'Alc/panning.cpp')
-rw-r--r-- | Alc/panning.cpp | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/Alc/panning.cpp b/Alc/panning.cpp index cffb6e46..37559620 100644 --- a/Alc/panning.cpp +++ b/Alc/panning.cpp @@ -808,17 +808,17 @@ void CalcAmbiCoeffs(const ALfloat y, const ALfloat z, const ALfloat x, const ALf /* Second-order */ coeffs[4] = 3.872983346f * x * y; /* ACN 4 = sqrt(15) * X * Y */ coeffs[5] = 3.872983346f * y * z; /* ACN 5 = sqrt(15) * Y * Z */ - coeffs[6] = 1.118033989f * (3.0f*z*z - 1.0f); /* ACN 6 = sqrt(5)/2 * (3*Z*Z - 1) */ + coeffs[6] = 1.118033989f * (z*z*3.0f - 1.0f); /* ACN 6 = sqrt(5)/2 * (3*Z*Z - 1) */ coeffs[7] = 3.872983346f * x * z; /* ACN 7 = sqrt(15) * X * Z */ coeffs[8] = 1.936491673f * (x*x - y*y); /* ACN 8 = sqrt(15)/2 * (X*X - Y*Y) */ /* Third-order */ - coeffs[9] = 2.091650066f * y * (3.0f*x*x - y*y); /* ACN 9 = sqrt(35/8) * Y * (3*X*X - Y*Y) */ + coeffs[9] = 2.091650066f * y * (x*x*3.0f - y*y); /* ACN 9 = sqrt(35/8) * Y * (3*X*X - Y*Y) */ coeffs[10] = 10.246950766f * z * x * y; /* ACN 10 = sqrt(105) * Z * X * Y */ - coeffs[11] = 1.620185175f * y * (5.0f*z*z - 1.0f); /* ACN 11 = sqrt(21/8) * Y * (5*Z*Z - 1) */ - coeffs[12] = 1.322875656f * z * (5.0f*z*z - 3.0f); /* ACN 12 = sqrt(7)/2 * Z * (5*Z*Z - 3) */ - coeffs[13] = 1.620185175f * x * (5.0f*z*z - 1.0f); /* ACN 13 = sqrt(21/8) * X * (5*Z*Z - 1) */ + coeffs[11] = 1.620185175f * y * (z*z*5.0f - 1.0f); /* ACN 11 = sqrt(21/8) * Y * (5*Z*Z - 1) */ + coeffs[12] = 1.322875656f * z * (z*z*5.0f - 3.0f); /* ACN 12 = sqrt(7)/2 * Z * (5*Z*Z - 3) */ + coeffs[13] = 1.620185175f * x * (z*z*5.0f - 1.0f); /* ACN 13 = sqrt(21/8) * X * (5*Z*Z - 1) */ coeffs[14] = 5.123475383f * z * (x*x - y*y); /* ACN 14 = sqrt(105)/2 * Z * (X*X - Y*Y) */ - coeffs[15] = 2.091650066f * x * (x*x - 3.0f*y*y); /* ACN 15 = sqrt(35/8) * X * (X*X - 3*Y*Y) */ + coeffs[15] = 2.091650066f * x * (x*x - y*y*3.0f); /* ACN 15 = sqrt(35/8) * X * (X*X - 3*Y*Y) */ /* Fourth-order */ /* ACN 16 = sqrt(35)*3/2 * X * Y * (X*X - Y*Y) */ /* ACN 17 = sqrt(35/2)*3/2 * (3*X*X - Y*Y) * Y * Z */ |