cygwin 3.5.4-1: signal handling destroys 'long double' values
Brian Inglis
Brian.Inglis@SystematicSW.ab.ca
Tue Oct 8 16:14:56 GMT 2024
On 2024-10-08 05:20, Takashi Yano via Cygwin wrote:
> On Mon, 7 Oct 2024 15:11:52 +0200
> Christian Franke wrote:
>> $ gcc -o sigtest -O2 sigtest.c
>>
>> $ ./sigtest > out.txt
>> (press ^C 42x :-)
>>
>> $ sort out.txt | uniq -c
>> 3 x = 0x1.23456789p+0, y = -nan, d = -nan
>> 6 x = 0x1.23456789p+0, y = 0x1.23456789p+0, d = -nan
>> 33 x = 0x1.23456789p+0, y = 0x1.23456789p+0, d = 0x0p+0
>>
>> The problem also occurs if compiled without -O2, but less often. No
>> problem occurs if compiled with -DWORKS which suggests that only 'long
>> double' is affected.
>
> Thanks for the report. I looked into this problem and might find the
> cause. It seems due to a bug of scripts/gendef. It generates signal
> handler caller (sigfe.s) which stores/restores the registers.
>
> In sigdelayed, control word is stored/restored by fnstcw/fldcw instruction,
> however, fninit instruction destroys some status registers in FPU (x87).
>
> I think we shold use fnstenv/fldenv rather than fnstcw/fldcw and fninit.
> However, I'm not familiar with x87 instructions, so I may overlook
> something.
>
> Could anyone expert of x87 instructions and sigfe stuff give some
> comments?
AIUI x87 FP handling is outdated and mainly unused on current systems, as
current systems do more and use more than the legacy x87 instructions and stack.
See https://en.cppreference.com/w/c/numeric/fenv and related docs for more
modern approaches.
You would have to look into the AMD/Intel/IEEE docs for lower level details.
--
Take care. Thanks, Brian Inglis Calgary, Alberta, Canada
La perfection est atteinte Perfection is achieved
non pas lorsqu'il n'y a plus rien à ajouter not when there is no more to add
mais lorsqu'il n'y a plus rien à retirer but when there is no more to cut
-- Antoine de Saint-Exupéry
More information about the Cygwin
mailing list