x86 denormal flag handling
I've been following the recent changes to better support denormal handling and I don't think they are doing the right thing for x86.
I tried a simple program to convert a denormal float value (0x1.0p-127) to a double. With the default of DAZ being 0 in MXCSR, x86 sets DE, but QEMU doesn't. This is the opposite behavior of AARCH64 which sets their denormal input flag when it flushes a denormal input to 0.
Here's what I tried:
#include <stdio.h>
#include <immintrin.h>
volatile float f = 0x1.0p-127;
int main()
{
double d = f;
printf("Converting a denormal float to a double %s the DE bit in MXCSR\n",
_mm_getcsr() & _MM_EXCEPT_DENORM ? "sets" : "does not set");
return 0;
}When run on a native machine, it prints:
Converting a denormal float to a double sets the DE bit in MXCSR
But when run using QEMU, it prints:
Converting a denormal float to a double does not set the DE bit in MXCSR
Quoted 6 lines · Michael Morrell
I’ve been following the recent changes to better support denormal handling and I don’t think they are doing the right thing for x86.
I tried a simple program to convert a denormal float value (0x1.0p-127) to a double. With the default of DAZ being 0 in MXCSR, x86 sets DE, but QEMU doesn’t. This is the opposite behavior of AARCH64 which sets their denormal input flag when it flushes a denormal input to 0.
Yes. None of the changes to fix denormal handling have actually landed in git yet, so what you see at the moment is still the behaviour QEMU has had for years, where it doesn't either detect "this denormal input was used without being flushed" or set the MXCSR DE flag with the correct semantics.
I have a work in progress branch at
https://git.linaro.org/people/peter.maydell/qemu-arm.git/log/?h=feat-afp
which has the new handling and also at the end the target/i386 changes to get the DE flag right. If you build a QEMU with those patches then it produces the right result with your test program.
thanks
-- PMM