Reorder some math terms to help optimizations
commita6a5634adb1bdec44fa7cb8557e5b6d59642d7aa
authorChris Robinson <chris.kcat@gmail.com>
Sun, 16 Dec 2018 04:28:52 +0000 (15 20:28 -0800)
committerChris Robinson <chris.kcat@gmail.com>
Sun, 16 Dec 2018 04:28:52 +0000 (15 20:28 -0800)
treefc68e681fd6da605f3cb43847f15ad0ac9019dfa
parentdea077cbae1f180a5c7ee77517ea73901f59aff2
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.
Alc/panning.cpp