[Mesa-dev] [PATCH 12/28] util: add fp64 -> fp32 conversion support for RTNE and RTZ rounding modes

Samuel Iglesias Gonsálvez siglesias at igalia.com
Mon Dec 10 16:25:40 UTC 2018


On 07/12/2018 03:03, Matt Turner wrote:
> On Wed, Dec 5, 2018 at 7:56 AM Samuel Iglesias Gonsálvez
> <siglesias at igalia.com> wrote:
>>
>> Signed-off-by: Samuel Iglesias Gonsálvez <siglesias at 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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20181210/b7530921/attachment.sig>


More information about the mesa-dev mailing list