https://gcc.gnu.org/g:2be5c020f6a9190b521ef8a35abca5939e56ee1f

commit 2be5c020f6a9190b521ef8a35abca5939e56ee1f
Author: Michael Meissner <[email protected]>
Date:   Thu Jun 25 04:08:46 2026 -0400

    Add initial 16-bit floating point support.
    
    This patch adds the initial support for the 16-bit floating point formats.
    _Float16 is the IEEE 754 half precision format.  __bfloat16 is the Google 
Brain
    16-bit format.
    
    In order to use both _Float16 and __bfloat16, the user has to use the 
-mfloat16
    option to enable the support.
    
    In this patch only the machine indepndent support is used.  In order to be
    usable, the next patch will also need to be installed. That patch will add
    support in libgcc for 16-bit floating point support.
    
    2026-06-25  Michael Meissner  <[email protected]>
    
    gcc/
    
            * config.gcc (powerpc*-*-*): Add support for the configuration 
option
            --with-powerpc-float16 and --with-powerpc-float16-disable-warning.
            * config/rs6000/rs6000-cpus.def (TARGET_16BIT_FLOATING_POINT): 
Likewise.
            (ISA_2_7_MASKS_SERVER): Likewise.
            (POWERPC_MASKS): Add -mfloat16.
            * config/rs6000/constraints.md (eZ): New constraint for -0.0.
            * config/rs6000/float16.md: New file to add basic 16-bit floating 
point
            support.
            * config/rs6000/predicates.md (easy_fp_constant): Add support for 
HFmode
            and BFmode constants.
            (easy_vector_constant): Add support for V8HFmode and V8BFmode to 
load up
            the vector -0.0 constant.
            (minus_zero_constant): New predicate.
            (fp16_xxspltiw_constant): Likewise.
            * config/rs6000/rs6000-builtin.cc (rs6000_type_string): Add support 
for
            16-bit floating point types.
            (rs6000_init_builtins): Create the bfloat16_type_node if needed.
            * config/rs6000/rs6000-c.cc (rs6000_target_modify_macros): Define
            __FLOAT16__ and __BFLOAT16__ if 16-bit floating pont is enabled.
            * config/rs6000/rs6000-call.cc (init_cumulative_args): Warn if a
            function returns a 16-bit floating point value unless -Wno-psabi is
            used or if this warning is disabled via the configuration option
            --with-powerpc-float16-disable-warning.
            (rs6000_function_arg): Warn if a 16-bit floating point value is 
passed
            to a function unless -Wno-psabi is ued or if this warning is 
disabled
            via the configuration option --with-powerpc-float16-disable-warning.
            * config/rs6000/rs6000-protos.h (vec_const_128bit_type): Add mode 
field
            to detect initializing 16-bit floating constants.
            * config/rs6000/rs6000.cc (rs6000_hard_regno_mode_ok_uncached): Add
            support for 16-bit floating point.
            (rs6000_modes_tieable_p): Don't allow 16-bit floating point modes 
to tie
            with other modes.
            (rs6000_debug_reg_global): Add BFmode and HFmode.
            (rs6000_setup_reg_addr_masks): Add support for 16-bit floating point
            types.
            (rs6000_setup_reg_addr_masks): Likewise.
            (rs6000_init_hard_regno_mode_ok): Likewise.
            (rs6000_option_override_internal): Add a check whether -mfloat16 
can be
            used.
            (easy_altivec_constant): Add suport for 16-bit floating point.
            (xxspltib_constant_p): Likewise.
            (rs6000_expand_vector_init): Likewise.
            (rs6000_expand_vector_set): Likewise.
            (rs6000_expand_vector_extract): Likewise.
            (rs6000_split_vec_extract_var): Likewise.
            (reg_offset_addressing_ok_p): Likewise.
            (rs6000_legitimate_offset_address_p): Likewise.
            (legitimate_lo_sum_address_p): Likewise.
            (rs6000_secondary_reload_simple_move): Likewise.
            (rs6000_preferred_reload_class): Likewise.
            (rs6000_can_change_mode_class): Likewise.
            (rs6000_output_move_128bit): Likewise.
            (rs6000_load_constant_and_splat): Likewise.
            (rs6000_scalar_mode_supported_p): Likewise.
            (rs6000_libgcc_floating_mode_supported_p): Return true for HFmode 
and
            BFmode if -mfloat16.
            (rs6000_floatn_mode): Enable _Float16 if -mfloat16.
            (rs6000_opt_masks): Add -mfloat16.
            (constant_fp_to_128bit_vector): Add support for 16-bit floating 
point.
            (vec_const_128bit_to_bytes): Likewise.
            (constant_generates_xxspltiw): Likewise.
            * config/rs6000/rs6000.h (FP16_SCALAR_MODE_P): Ne macro.
            (FP16_VECTOR_MODE_P): Likewise.
            (TARGET_BFLOAT16_HW): New macro.
            (TARGET_FLOAT16_HW): Likewise.
            (TARGET_BFLOAT16_HW_VECTOR): Likewise.
            (TARGET_FLOAT16_HW_VECTOR): Likewise.
            * config/rs6000/rs6000.md (wd): Add BFmode and HFmode.
            (toplevel): Include float16.md.
            * config/rs6000/rs6000.opt (-mloat16): New option.
            * doc/invoke.texi (RS/6000 and PowerPC Options): Document -mfloat16.

Diff:
---
 gcc/config/rs6000/constraints.md | 5 +++++
 gcc/config/rs6000/predicates.md  | 3 +++
 2 files changed, 8 insertions(+)

diff --git a/gcc/config/rs6000/constraints.md b/gcc/config/rs6000/constraints.md
index e02d3fd8f4b9..326eb89d9742 100644
--- a/gcc/config/rs6000/constraints.md
+++ b/gcc/config/rs6000/constraints.md
@@ -237,6 +237,11 @@
   (and (match_code "const_int")
        (match_operand 0 "paddis_paddi_operand")))
 
+;; A negative 0 constant
+(define_constraint "eZ"
+  "A floating point -0.0 constant."
+  (match_operand 0 "minus_zero_constant"))
+
 ;; Floating-point constraints.  These two are defined so that insn
 ;; length attributes can be calculated exactly.
 
diff --git a/gcc/config/rs6000/predicates.md b/gcc/config/rs6000/predicates.md
index 41e150fb2a80..f549c762eb51 100644
--- a/gcc/config/rs6000/predicates.md
+++ b/gcc/config/rs6000/predicates.md
@@ -2374,6 +2374,7 @@
 
   return constant_generates_xxspltiw (&vsx_const);
 })
+<<<<<<< HEAD
 
 ;; Return 1 if this is a 16-bit floating point operand that can be used
 ;; in an add, subtract, or multiply operation that uses the vector
@@ -2450,3 +2451,5 @@
 
   return false;
 })
+=======
+>>>>>>> 657f8abb6c6 (Add initial 16-bit floating point support.)

Reply via email to