On 07/12/2018 03:03, Matt Turner wrote: > On Wed, Dec 5, 2018 at 7:56 AM Samuel Iglesias Gonsálvez > <sigles...@igalia.com> wrote: >> >> Signed-off-by: Samuel Iglesias Gonsálvez <sigles...@igalia.com> >> --- >> src/util/Makefile.sources | 2 + >> src/util/double.c | 197 ++++++++++++++++++++++++++++++++++++++ >> src/util/double.h | 46 +++++++++ >> src/util/meson.build | 2 + >> 4 files changed, 247 insertions(+) >> create mode 100644 src/util/double.c >> create mode 100644 src/util/double.h > > Why do we need software routines for this? Couldn't we set/reset the > rounding mode (fegetround/fegetround) around a double -> float > conversion? >
Yes, that was my first idea. However, I found an issue with GCC that forces me to do these software routines instead. I implemented _mesa_double_to_float_rtz() as: float _mesa_double_to_float_rtz(double val) { int curr_method = fegetround(); float result; fesetround(FE_TOWARDZERO); result = val; fesetround(curr_method); return result; } If I add a printf, I got the proper value. However if I remove it, the result value is using the default's rounding mode (FE_TONEAREST). I think it is reordering instructions or optimizing something. I have set #pragma STDC FENV_ACCESS ON but it doesn't work either. Updated news: I give it another spin. I defined result as volatile variable and that seems to work :) My GCC knowledge is limited, so if someone brings a better idea to fix this, I will be delighted to test it. If not, I will send a v2 version with the volatile and fesetround()/fegetround() functions. Thanks for the feedback! Sam
signature.asc
Description: OpenPGP digital signature
_______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev