From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
To: libc-alpha@sourceware.org
Cc: "H . J . Lu" <hjl.tools@gmail.com>
Subject: [PATCH v2 00/10] Improve rounding to interger function for C23
Date: Wed, 3 Apr 2024 09:11:40 -0300 [thread overview]
Message-ID: <20240403121150.1018799-1-adhemerval.zanella@linaro.org> (raw)
As indicated by GCC documentation [1], ISO C23 does not allow that C
bindings ceil, floor, round, and trunc (in all floating point formats)
to raise inexact exceptions (different than ISO C99/C11 where this is
allowed).
A recent MIPS patch to used some arch-specific instructions raised this
issue [1] and it was not caught because there was no proper testing. By
adding the missing tests, some implementations do indeed raise inexact
exceptions.
The generic implementation all uses integer operation, so they are not
subject to this issue. The powerpc (for power4 and lower) and the riscv
avoid the inexact exception by disabling/enabling exceptions. The x86
uses some arch-specific implementation for long double and on i386 (due
to the use of x87 instruction).
Instead of adding newer symbols depending on the required standard
version, the patchset adapts the faulty ones to avoid raising the
inexact exception. The x86 version already saves/restore the floating
point status, so I think it is unlikely the patch would yield much
performance difference (I did not do any performance analysis on whether
a generic implementation would yield better performance).
I checked on powerpc, powerpc64, aarch64, armhf, x86, and did some
regression checks on riscv.
[1] https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#index-fno-fp-int-builtin-inexact
[2] https://sourceware.org/pipermail/libc-alpha/2023-December/153528.html
Changes from v1:
* Updated Copyright years.
Adhemerval Zanella (10):
math: Add test to check if ceil raise inexact floating-point exception
math: Add test to check if floor raise inexact floating-point
exception
math: Add test to check if trunc raise inexact floating-point
exception
math: Add test to check if round raise inexact floating-point
exception
x86: Do not raise inexact exception on ceill
x86: Do not raise inexact exception on floorl
x86: Do not raise inexact exception on truncl
x86: Do not raise inexact exception on floor/floorf
i386: Do not raise inexact exception on ceil/ceilf
i386: Do not raise inexact exception on trunc/truncf
math/Makefile | 17 ++++
math/test-ceil-except-2.c | 67 +++++++++++++++
math/test-ceil-except.c | 85 +++++++++++++++++++
math/test-floor-except-2.c | 67 +++++++++++++++
math/test-floor-except.c | 85 +++++++++++++++++++
math/test-round-except-2.c | 67 +++++++++++++++
math/test-round-except.c | 85 +++++++++++++++++++
math/test-trunc-except-2.c | 67 +++++++++++++++
math/test-trunc-except.c | 85 +++++++++++++++++++
sysdeps/i386/fpu/s_ceil.S | 34 --------
sysdeps/i386/fpu/s_ceil.c | 38 +++++++++
sysdeps/i386/fpu/s_ceilf.S | 34 --------
sysdeps/i386/fpu/s_ceilf.c | 38 +++++++++
sysdeps/i386/fpu/s_ceill.S | 39 ---------
sysdeps/i386/fpu/s_floor.S | 34 --------
sysdeps/i386/fpu/s_floor.c | 38 +++++++++
sysdeps/i386/fpu/s_floorf.S | 34 --------
sysdeps/i386/fpu/s_floorf.c | 38 +++++++++
sysdeps/i386/fpu/s_floorl.S | 39 ---------
sysdeps/i386/fpu/{s_trunc.S => s_trunc.c} | 37 ++++----
sysdeps/i386/fpu/{s_truncf.S => s_truncf.c} | 37 ++++----
.../fpu/s_truncl.S => x86/fpu/s_ceill.c} | 38 +++++----
sysdeps/x86/fpu/s_floorl.c | 38 +++++++++
.../fpu/s_truncl.S => x86/fpu/s_truncl.c} | 40 +++++----
sysdeps/x86_64/fpu/s_ceill.S | 34 --------
sysdeps/x86_64/fpu/s_floorl.S | 33 -------
26 files changed, 892 insertions(+), 356 deletions(-)
create mode 100644 math/test-ceil-except-2.c
create mode 100644 math/test-ceil-except.c
create mode 100644 math/test-floor-except-2.c
create mode 100644 math/test-floor-except.c
create mode 100644 math/test-round-except-2.c
create mode 100644 math/test-round-except.c
create mode 100644 math/test-trunc-except-2.c
create mode 100644 math/test-trunc-except.c
delete mode 100644 sysdeps/i386/fpu/s_ceil.S
create mode 100644 sysdeps/i386/fpu/s_ceil.c
delete mode 100644 sysdeps/i386/fpu/s_ceilf.S
create mode 100644 sysdeps/i386/fpu/s_ceilf.c
delete mode 100644 sysdeps/i386/fpu/s_ceill.S
delete mode 100644 sysdeps/i386/fpu/s_floor.S
create mode 100644 sysdeps/i386/fpu/s_floor.c
delete mode 100644 sysdeps/i386/fpu/s_floorf.S
create mode 100644 sysdeps/i386/fpu/s_floorf.c
delete mode 100644 sysdeps/i386/fpu/s_floorl.S
rename sysdeps/i386/fpu/{s_trunc.S => s_trunc.c} (61%)
rename sysdeps/i386/fpu/{s_truncf.S => s_truncf.c} (61%)
rename sysdeps/{x86_64/fpu/s_truncl.S => x86/fpu/s_ceill.c} (57%)
create mode 100644 sysdeps/x86/fpu/s_floorl.c
rename sysdeps/{i386/fpu/s_truncl.S => x86/fpu/s_truncl.c} (61%)
delete mode 100644 sysdeps/x86_64/fpu/s_ceill.S
delete mode 100644 sysdeps/x86_64/fpu/s_floorl.S
--
2.34.1
next reply other threads:[~2024-04-03 12:12 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-03 12:11 Adhemerval Zanella [this message]
2024-04-03 12:11 ` [PATCH v2 01/10] math: Add test to check if ceil raise inexact floating-point exception Adhemerval Zanella
2024-04-03 12:54 ` H.J. Lu
2024-04-03 12:11 ` [PATCH v2 02/10] math: Add test to check if floor " Adhemerval Zanella
2024-04-03 12:55 ` H.J. Lu
2024-04-03 12:11 ` [PATCH v2 03/10] math: Add test to check if trunc " Adhemerval Zanella
2024-04-03 12:55 ` H.J. Lu
2024-04-03 12:11 ` [PATCH v2 04/10] math: Add test to check if round " Adhemerval Zanella
2024-04-03 12:56 ` H.J. Lu
2024-04-03 12:11 ` [PATCH v2 05/10] x86: Do not raise inexact exception on ceill Adhemerval Zanella
2024-04-03 13:04 ` H.J. Lu
2024-04-03 13:15 ` Adhemerval Zanella Netto
2024-04-03 13:28 ` H.J. Lu
2024-04-03 12:11 ` [PATCH v2 06/10] x86: Do not raise inexact exception on floorl Adhemerval Zanella
2024-04-03 12:11 ` [PATCH v2 07/10] x86: Do not raise inexact exception on truncl Adhemerval Zanella
2024-04-03 12:11 ` [PATCH v2 08/10] x86: Do not raise inexact exception on floor/floorf Adhemerval Zanella
2024-04-03 12:11 ` [PATCH v2 09/10] i386: Do not raise inexact exception on ceil/ceilf Adhemerval Zanella
2024-04-03 12:11 ` [PATCH v2 10/10] i386: Do not raise inexact exception on trunc/truncf Adhemerval Zanella
2024-04-03 15:03 ` [PATCH v2 00/10] Improve rounding to interger function for C23 Joseph Myers
2024-04-03 17:10 ` Adhemerval Zanella Netto
2024-04-04 5:25 ` Paul Zimmermann
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
List information: https://www.gnu.org/software/libc/involved.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240403121150.1018799-1-adhemerval.zanella@linaro.org \
--to=adhemerval.zanella@linaro.org \
--cc=hjl.tools@gmail.com \
--cc=libc-alpha@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).