This patch adds support to generate xscvhpdp and xscvdphp on Power9 systems and
later, to convert between _Float16 and float scalar values.

2025-11-04  Michael Meissner  <[email protected]>

gcc/

        * config/rs6000/float16.md (FP16_HW): New mode iterator.
        (extendhf<mode>2): Add support converting between HFmode and
        SFmode/DFmoded if we are on power9 or later.
        (trunc<mode>hf2): Likewise.
---
 gcc/config/rs6000/float16.md | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/gcc/config/rs6000/float16.md b/gcc/config/rs6000/float16.md
index fec4bb87fd0..13f3b32e86c 100644
--- a/gcc/config/rs6000/float16.md
+++ b/gcc/config/rs6000/float16.md
@@ -25,6 +25,10 @@
 (define_mode_iterator FP16 [(BF "TARGET_FLOAT16")
                            (HF "TARGET_FLOAT16")])
 
+;; Mode iterator for 16-bit floating point modes on machines with
+;; hardware support both as a scalar and as a vector.
+(define_mode_iterator FP16_HW [(HF "TARGET_FLOAT16_HW")])
+
 ;; Mode attribute giving the vector mode for a 16-bit floating point
 ;; scalar in both upper and lower case.
 (define_mode_attr FP16_VECTOR8 [(BF "V8BF")
@@ -122,3 +126,21 @@ (define_insn "*vecdup<mode>_const"
 }
   [(set_attr "type" "veclogical,vecperm")
    (set_attr "prefixed" "*,yes")])
+
+;; Convert IEEE 16-bit floating point to/from other floating point modes.
+
+(define_insn "extendhf<mode>2"
+  [(set (match_operand:SFDF 0 "vsx_register_operand" "=wa")
+       (float_extend:SFDF
+        (match_operand:HF 1 "vsx_register_operand" "wa")))]
+  "TARGET_FLOAT16_HW"
+  "xscvhpdp %x0,%x1"
+  [(set_attr "type" "fpsimple")])
+
+(define_insn "trunc<mode>hf2"
+  [(set (match_operand:HF 0 "vsx_register_operand" "=wa")
+       (float_truncate:HF
+        (match_operand:SFDF 1 "vsx_register_operand" "wa")))]
+  "TARGET_FLOAT16_HW"
+  "xscvdphp %x0,%x1"
+  [(set_attr "type" "fpsimple")])
-- 
2.51.1


-- 
Michael Meissner, IBM
PO Box 98, Ayer, Massachusetts, USA, 01432
email: [email protected]

Reply via email to