nvptx: Improved support for HFMode including neghf2 and abshf2
authorRoger Sayle <roger@nextmovesoftware.com>
Thu, 3 Feb 2022 08:07:22 +0000 (09:07 +0100)
committerTom de Vries <tdevries@suse.de>
Thu, 10 Feb 2022 08:01:54 +0000 (09:01 +0100)
commit91a7e1daa7520489fafc0001d03c68bad4304f15
tree34afa78cd5152a911732ce857a68276b08cf00ed
parentbcbe280931535109544cae15b1e575dd53b5c647
nvptx: Improved support for HFMode including neghf2 and abshf2

This patch adds more support for _Float16 (HFmode) to the nvptx backend.
Currently negation, absolute value and floating point comparisons are
implemented by promoting to float (SFmode).  This patch adds suitable
define_insns to nvptx.md, most conditional on TARGET_SM53 (-misa=sm_53).
This patch also adds support for HFmode fused multiply-add.

One subtlety is that neghf2 and abshf2 are implemented by (HImode)
bit manipulation operations to update the sign bit.  The NVidia PTX
ISA documentation for neg.f16 and abs.f16 contains the caution
"Future implementations may comply with the IEEE 754 standard by preserving
the (NaN) payload and modifying only the sign bit".  Given the availability
of suitable replacements, I thought it best to provide IEEE 754 compliant
implementations.  If anyone observes a performance penalty from this
choice I'm happy to provide a -ffast-math variant (or revisit this
decision).

This patch has been tested on nvptx-none hosted on x86_64-pc-linux-gnu
(including newlib) with a make and make -k check with no new failures.

gcc/ChangeLog:

* config/nvptx/nvptx.md (*cmpf): New define_insn.
(cstorehf4): New define_expand.
(fmahf4): New define_insn.
(neghf2): New define_insn.
(abshf2): New define_insn.

gcc/testsuite/ChangeLog:

* gcc.target/nvptx/float16-3.c: New test case for neghf2.
* gcc.target/nvptx/float16-4.c: New test case for abshf2.
* gcc.target/nvptx/float16-5.c: New test case for fmahf4.
* gcc.target/nvptx/float16-6.c: New test case.
gcc/config/nvptx/nvptx.md
gcc/testsuite/gcc.target/nvptx/float16-3.c [new file with mode: 0644]
gcc/testsuite/gcc.target/nvptx/float16-4.c [new file with mode: 0644]
gcc/testsuite/gcc.target/nvptx/float16-5.c [new file with mode: 0644]
gcc/testsuite/gcc.target/nvptx/float16-6.c [new file with mode: 0644]