diff mbox

[v2,0/1] RISC-V: Support BF16 interfaces in libgcc

Message ID 20240807031351.46105-1-zengxiao@eswincomputing.com
State New
Headers show

Commit Message

Xiao Zeng Aug. 7, 2024, 3:13 a.m. UTC
1 Why should bf16 be modified to f16b?
--------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------	    

There is such code:
--------------------------------------------------------------------------------------------------------------
DEF_C99_BUILTIN        (BUILT_IN_LOGB, "logb", BT_FN_DOUBLE_DOUBLE, ATTR_MATHFN_FPROUNDING_ERRNO)
DEF_C99_BUILTIN        (BUILT_IN_LOGBF, "logbf", BT_FN_FLOAT_FLOAT, ATTR_MATHFN_FPROUNDING_ERRNO)
--------------------------------------------------------------------------------------------------------------
bf16 and f16 will conflict when expanded, but f16b and f16 will not.

The previous code also used the symbol f16b:
--------------------------------------------------------------------------------------------------------------
-DEF_GCC_BUILTIN        (BUILT_IN_NANSF16B, "nansf16b", BT_FN_BFLOAT16_CONST_STRING, ATTR_CONST_NOTHROW_NONNULL)
-DEF_GCC_BUILTIN        (BUILT_IN_NEXTAFTERF16B, "nextafterf16b", BT_FN_BFLOAT16_BFLOAT16_BFLOAT16, ATTR_MATHFN_ERRNO)
--------------------------------------------------------------------------------------------------------------

2 Why should BUILT_IN_NANSF16B and BUILT_IN_NEXTAFTERF16B be deleted? 
--------------------------------------------------------------------------------------------------------------
-DEF_GCC_BUILTIN        (BUILT_IN_NANSF16B, "nansf16b", BT_FN_BFLOAT16_CONST_STRING, ATTR_CONST_NOTHROW_NONNULL)
-DEF_GCC_BUILTIN        (BUILT_IN_NEXTAFTERF16B, "nextafterf16b", BT_FN_BFLOAT16_BFLOAT16_BFLOAT16, ATTR_MATHFN_ERRNO)
--------------------------------------------------------------------------------------------------------------

In the general macro definition, it has already been processed to remove redundant code.
--------------------------------------------------------------------------------------------------------------
 #define DEF_GCC_FLOATN_NX_BUILTINS(ENUM, NAME, TYPE_MACRO, ATTRS)      \
+  DEF_GCC_BUILTIN (ENUM ## F16B, NAME "f16b", TYPE_MACRO (BFLOAT16), ATTRS) \
   DEF_GCC_BUILTIN (ENUM ## F16, NAME "f16", TYPE_MACRO (FLOAT16), ATTRS) \
   DEF_GCC_BUILTIN (ENUM ## F32, NAME "f32", TYPE_MACRO (FLOAT32), ATTRS) \
   DEF_GCC_BUILTIN (ENUM ## F64, NAME "f64", TYPE_MACRO (FLOAT64), ATTRS) \

// and
 #define DEF_EXT_LIB_FLOATN_NX_BUILTINS(ENUM, NAME, TYPE_MACRO, ATTRS)  \
+  DEF_FLOATN_BUILTIN (ENUM ## F16B, NAME "f16b", TYPE_MACRO (BFLOAT16), ATTRS) \
   DEF_FLOATN_BUILTIN (ENUM ## F16, NAME "f16", TYPE_MACRO (FLOAT16), ATTRS) \
   DEF_FLOATN_BUILTIN (ENUM ## F32, NAME "f32", TYPE_MACRO (FLOAT32), ATTRS) \
   DEF_FLOATN_BUILTIN (ENUM ## F64, NAME "f64", TYPE_MACRO (FLOAT64), ATTRS) \
--------------------------------------------------------------------------------------------------------------

3 This modification will have an impact on all architectures that support BF16.

I have completed the following tests:
x86_64 bootstrap based on 18eb6ca136fcd22b381d222cab81265d812ea7b9 passed.
riscv64 bootstrap based on a59c4e496fa916cb9a484a649aa1b4cebd6550f2 passed.
The riscv64 regression passed.
   

Xiao Zeng (1):
  RISC-V: Support BF16 interfaces in libgcc

 gcc/builtin-types.def        | 30 ++++++++++++++++++++++++++++++
 gcc/builtins.cc              |  6 ++++++
 gcc/builtins.def             | 22 +++++++++++-----------
 gcc/c-family/c-cppbuiltin.cc |  2 +-
 gcc/fold-const-call.cc       |  2 --
 gcc/gencfn-macros.cc         |  5 +++--
 gcc/match.pd                 |  9 ++++++---
 gcc/tree.h                   |  2 +-
 libgcc/Makefile.in           |  6 +++---
 libgcc/libgcc2.c             | 20 ++++++++++++++------
 libgcc/libgcc2.h             | 14 ++++++++++++++
 11 files changed, 89 insertions(+), 29 deletions(-)
diff mbox

Patch

diff --git a/gcc/c-family/c-cppbuiltin.cc b/gcc/c-family/c-cppbuiltin.cc
index a80372c8991..273bb9cf028 100644
--- a/gcc/c-family/c-cppbuiltin.cc
+++ b/gcc/c-family/c-cppbuiltin.cc
@@ -1422,7 +1422,7 @@  c_cpp_builtins (cpp_reader *pfile)
          else if (bfloat16_type_node
                   && mode == TYPE_MODE (bfloat16_type_node))
            {
-             memcpy (suffix, "bf16", 5);
+             memcpy (suffix, "f16b", 5);
              memcpy (float_h_prefix, "BFLT16", 7);
            }
          else