]> git.ipfire.org Git - thirdparty/gcc.git/commit
Implement __builtin_issignaling
authorJakub Jelinek <jakub@redhat.com>
Fri, 26 Aug 2022 07:39:51 +0000 (09:39 +0200)
committerJakub Jelinek <jakub@redhat.com>
Fri, 26 Aug 2022 07:39:51 +0000 (09:39 +0200)
commit0982edd371d5429d24615442e96e76ba6bc4faa9
tree67abe3deb6d101e0f7d0eb15075b2fee1057a1b8
parent530dc5aaaeb67c223fd0e3986d635408dcea4343
Implement __builtin_issignaling

The following patch implements a new builtin, __builtin_issignaling,
which can be used to implement the ISO/IEC TS 18661-1  issignaling
macro.

It is implemented as type-generic function, so there is just one
builtin, not many with various suffixes.
This patch doesn't address PR56831 nor PR58416, but I think compared to
using glibc issignaling macro could make some cases better (as
the builtin is expanded always inline and for SFmode/DFmode just
reinterprets a memory or pseudo register as SImode/DImode, so could
avoid some raising of exception + turning sNaN into qNaN before the
builtin can analyze it).

For floading point modes that do not have NaNs it will return 0,
otherwise I've tried to implement this for all the other supported
real formats.
It handles both the MIPS/PA floats where a sNaN has the mantissa
MSB set and the rest where a sNaN has it cleared, with the exception
of format which are known never to be in the MIPS/PA form.
The MIPS/PA floats are handled using a test like
(x & mask) == mask,
the other usually as
((x ^ bit) & mask) > val
where bit, mask and val are some constants.
IBM double double is done by doing DFmode test on the most significant
half, and Intel/Motorola extended (12 or 16 bytes) and IEEE quad are
handled by extracting 32-bit/16-bit words or 64-bit parts from the
value and testing those.
On x86, XFmode is handled by a special optab so that even pseudo numbers
are considered signaling, like in glibc and like the i386 specific testcase
tests.

2022-08-26  Jakub Jelinek  <jakub@redhat.com>

gcc/
* builtins.def (BUILT_IN_ISSIGNALING): New built-in.
* builtins.cc (expand_builtin_issignaling): New function.
(expand_builtin_signbit): Don't overwrite target.
(expand_builtin): Handle BUILT_IN_ISSIGNALING.
(fold_builtin_classify): Likewise.
(fold_builtin_1): Likewise.
* optabs.def (issignaling_optab): New.
* fold-const-call.cc (fold_const_call_ss): Handle
BUILT_IN_ISSIGNALING.
* config/i386/i386.md (issignalingxf2): New expander.
* doc/extend.texi (__builtin_issignaling): Document.
(__builtin_isinf, __builtin_isnan): Clarify behavior with
-ffinite-math-only.
* doc/md.texi (issignaling<mode>2): Likewise.
gcc/c-family/
* c-common.cc (check_builtin_function_arguments): Handle
BUILT_IN_ISSIGNALING.
gcc/c/
* c-typeck.cc (convert_arguments): Handle BUILT_IN_ISSIGNALING.
gcc/fortran/
* f95-lang.cc (gfc_init_builtin_functions): Initialize
BUILT_IN_ISSIGNALING.
gcc/testsuite/
* gcc.dg/torture/builtin-issignaling-1.c: New test.
* gcc.dg/torture/builtin-issignaling-2.c: New test.
* gcc.dg/torture/float16-builtin-issignaling-1.c: New test.
* gcc.dg/torture/float32-builtin-issignaling-1.c: New test.
* gcc.dg/torture/float32x-builtin-issignaling-1.c: New test.
* gcc.dg/torture/float64-builtin-issignaling-1.c: New test.
* gcc.dg/torture/float64x-builtin-issignaling-1.c: New test.
* gcc.dg/torture/float128-builtin-issignaling-1.c: New test.
* gcc.dg/torture/float128x-builtin-issignaling-1.c: New test.
* gcc.target/i386/builtin-issignaling-1.c: New test.
20 files changed:
gcc/builtins.cc
gcc/builtins.def
gcc/c-family/c-common.cc
gcc/c/c-typeck.cc
gcc/config/i386/i386.md
gcc/doc/extend.texi
gcc/doc/md.texi
gcc/fold-const-call.cc
gcc/fortran/f95-lang.cc
gcc/optabs.def
gcc/testsuite/gcc.dg/torture/builtin-issignaling-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/builtin-issignaling-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/float128-builtin-issignaling-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/float128x-builtin-issignaling-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/float16-builtin-issignaling-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/float32-builtin-issignaling-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/float32x-builtin-issignaling-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/float64-builtin-issignaling-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/float64x-builtin-issignaling-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/builtin-issignaling-1.c [new file with mode: 0644]