Replacing a / b by a * (1 / b), which gmqcc sometimes does, can cause an accuracy loss.
See explanations on gcc's -freciprocal-math and why it's not default but only part of -funsafe-math-optimizations.
Attached an incomplete patch to do this. It lacks the case for vector / float division - that "folding" actually emulates the missing DIV_VF QC instruction, and as such, a different emulation has to be provided when the folding is to be turned off.
As such, with the optimization flag, v / f should be implemented like now as v * (1 / f), whereas without the flag, it should be implemented as vec3(v_x / f, v_y / f, v_z / f), which admittedly incurs an insane amount of QC instructions.
move-reciprocal-division-to-non-default-flag.diff.txt
Replacing
a / bbya * (1 / b), which gmqcc sometimes does, can cause an accuracy loss.See explanations on gcc's
-freciprocal-mathand why it's not default but only part of-funsafe-math-optimizations.Attached an incomplete patch to do this. It lacks the case for vector / float division - that "folding" actually emulates the missing DIV_VF QC instruction, and as such, a different emulation has to be provided when the folding is to be turned off.
As such, with the optimization flag,
v / fshould be implemented like now asv * (1 / f), whereas without the flag, it should be implemented asvec3(v_x / f, v_y / f, v_z / f), which admittedly incurs an insane amount of QC instructions.move-reciprocal-division-to-non-default-flag.diff.txt