From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 632F13858D37; Sun, 22 Oct 2023 22:52:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 632F13858D37 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1698015153; bh=k9UpYBbYIg4d/rN2KagtApkfjM1xxQppIAY8vhfZ8tE=; h=From:To:Subject:Date:From; b=PPc/FEodxS2FOfFsP7YOVYa7P28fUS77n6vYDUjqviUlOL7wzH9Sf/36rv5RltOys JFO+Gzx08gPG4D+mks+NYVFm7zt1ad6NQ0DxNQSENiFonoiKqGxWordjkE5SaAz6KU GvDa0Hj5w26NnTwFYBR2JO2aRzfXUGJC0UNYdw2o= From: "bruno at clisp dot org" To: glibc-bugs@sourceware.org Subject: [Bug math/30989] New: fesetexcept raises floating-point exception traps on i386 Date: Sun, 22 Oct 2023 22:52:32 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: glibc X-Bugzilla-Component: math X-Bugzilla-Version: 2.35 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: bruno at clisp dot org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://sourceware.org/bugzilla/show_bug.cgi?id=3D30989 Bug ID: 30989 Summary: fesetexcept raises floating-point exception traps on i386 Product: glibc Version: 2.35 Status: UNCONFIRMED Severity: normal Priority: P2 Component: math Assignee: unassigned at sourceware dot org Reporter: bruno at clisp dot org Target Milestone: --- Created attachment 15188 --> https://sourceware.org/bugzilla/attachment.cgi?id=3D15188&action=3Ded= it test case foo.c According to ISO C 23 =C2=A7 7.6.4.4, fesetexcept is supposed to set floati= ng-point exception flags without raising a trap. (Unlike feraiseexcept, which is supposed to raise a trap if feenableexcept() was called with the appropriate argument.) "This function changes the state of the floating-point exception flags, b= ut does not cause any other side effects that might be associated with raising floating-point exceptions. 267) Footnote 267) Implementation extensions like traps for floating-point exceptions and IEC 60559 exception handling do not occur." That's not how glibc's implementation does it on 32-bit x86. How to reproduce: 1. Compile the attached program foo.c. On i386 hosts: $ gcc -Wall foo.c -lm or on x86_64 hosts: $ i686-linux-gnu-gcc -Wall foo.c -lm or $ gcc -m32 -Wall foo.c -lm 2. Run it. $ ./a.out Floating point exception 3. Run it under gdb. $ gdb a.out=20 (gdb) run Starting program: /home/bruno/a.out=20 [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". Program received signal SIGFPE, Arithmetic exception. 0x565562a7 in main () (gdb) x/i $eip =3D> 0x565562a7 : fld1=20=20=20 I think it is a hardware limitation that on i386 CPUs, setting a floating-point exception flag in the 387 unit triggers a trap, when traps are enabled for the particular exception. But setting a floating-point exception flag in the SSE unit does not have this problem, cf. glibc/sysdeps/x86_64/fpu/fesetexcept.c. Therefore I would expect the fesetexcept() function to operate correctly when the hardware has an SSE unit (determined e.g. like in sysdeps/i386/fpu/ftestexcept.c). And only in the case where the CPU has only the 387 unit, I would expect the fesetexcept() function to return a non-zero value (as error indicator) and not modify the 387 floating-point control register, like I suggest for powerpc hardware in https://sourceware.org/bugzilla/show_bug.cgi?id=3D3= 0988 . --=20 You are receiving this mail because: You are on the CC list for the bug.=