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/alcontext.h | |
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/alcontext.h')
0 files changed, 0 insertions, 0 deletions