public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug math/30989] New: fesetexcept raises floating-point exception traps on i386
@ 2023-10-22 22:52 bruno at clisp dot org
  2023-10-22 22:52 ` [Bug math/30989] " bruno at clisp dot org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: bruno at clisp dot org @ 2023-10-22 22:52 UTC (permalink / raw)
  To: glibc-bugs

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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug math/30989] fesetexcept raises floating-point exception traps on i386
  2023-10-22 22:52 [Bug math/30989] New: fesetexcept raises floating-point exception traps on i386 bruno at clisp dot org
@ 2023-10-22 22:52 ` 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
  2 siblings, 0 replies; 4+ messages in thread
From: bruno at clisp dot org @ 2023-10-22 22:52 UTC (permalink / raw)
  To: glibc-bugs

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

Bruno Haible <bruno at clisp dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
               Host|                            |i386-linux-gnu

--- Comment #1 from Bruno Haible <bruno at clisp dot org> ---
Seen on:
- glibc 2.35 (Ubuntu 22.04)
- glibc 2.33 (Slackware 15)

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug math/30989] fesetexcept raises floating-point exception traps on i386
  2023-10-22 22:52 [Bug math/30989] New: fesetexcept raises floating-point exception traps on i386 bruno at clisp dot org
  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
  2 siblings, 0 replies; 4+ messages in thread
From: bruno at clisp dot org @ 2023-10-23 18:50 UTC (permalink / raw)
  To: glibc-bugs

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

Bruno Haible <bruno at clisp dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://sourceware.org/bugz
                   |                            |illa/show_bug.cgi?id=30990

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug math/30989] fesetexcept raises floating-point exception traps on i386
  2023-10-22 22:52 [Bug math/30989] New: fesetexcept raises floating-point exception traps on i386 bruno at clisp dot org
  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
  2 siblings, 0 replies; 4+ messages in thread
From: adhemerval.zanella at linaro dot org @ 2023-12-19 18:37 UTC (permalink / raw)
  To: glibc-bugs

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

Adhemerval Zanella <adhemerval.zanella at linaro dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |FIXED
                 CC|                            |adhemerval.zanella at linaro dot o
                   |                            |rg
   Target Milestone|---                         |2.39
           Assignee|unassigned at sourceware dot org   |adhemerval.zanella at linaro dot o
                   |                            |rg

--- Comment #2 from Adhemerval Zanella <adhemerval.zanella at linaro dot org> ---
Fixed on 2.39 (47a9eeb9ba72fd30766bdf4faa7d46b8ca33a7fd).

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-12-19 18:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-22 22:52 [Bug math/30989] New: fesetexcept raises floating-point exception traps on i386 bruno at clisp dot org
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

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).