crt: Fix x86 __mingw_setfp() to not mask all exceptions on noop operation
x87 fnstenv instruction saves the current FPU operating environment at the
memory location specified with the destination operand, and then masks all
floating-point exceptions.
So if the x87 fnstenv instruction was called, it is required to call
follow-up x87 fldenv instruction which will restore previous masking state
of floating-point exceptions. Hence x87 fldenv instruction must be always
called, and not only when new cw or sw value differs from the old one.
__mingw_setfp is currently calling x87 fldenv instruction only when the new
cw or sw value differs from the old one. And this behavior cause breaking
of following code:
fedisableexcept(FE_ALL_EXCEPT);
feenableexcept(FE_INVALID);
feenableexcept(FE_INVALID);
The third line disables all exceptions, including the FE_INVALID.
Co-authored-by: LIU Hao <lh_mouse@126.com>
Signed-off-by: LIU Hao <lh_mouse@126.com>
1 file changed