public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "bruno at clisp dot org" <sourceware-bugzilla@sourceware.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	[thread overview]
Message-ID: <bug-30989-131@http.sourceware.org/bugzilla/> (raw)

https://sourceware.org/bugzilla/show_bug.cgi?id=30989

            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=15188&action=edit
test case foo.c

According to ISO C 23 § 7.6.4.4, fesetexcept is supposed to set floating-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, but
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 
(gdb) run
Starting program: /home/bruno/a.out 
[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
=> 0x565562a7 <main+102>:       fld1   


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=30988 .

-- 
You are receiving this mail because:
You are on the CC list for the bug.

             reply	other threads:[~2023-10-22 22:52 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-22 22:52 bruno at clisp dot org [this message]
2023-10-22 22:52 ` [Bug math/30989] " bruno at clisp dot org
2023-10-23 18:50 ` bruno at clisp dot org
2023-12-19 18:37 ` adhemerval.zanella at linaro dot org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-30989-131@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=glibc-bugs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).