On Wed, Aug 07, 2024 at 11:13:51AM +0800, Xiao Zeng wrote: > gcc/ChangeLog: > > * builtin-types.def (BT_COMPLEX_BFLOAT16): Support BF16 node. > (BT_BFLOAT16_PTR): Ditto. > (BT_FN_BFLOAT16): New. > (BT_FN_BFLOAT16_BFLOAT16): Ditto. > (BT_FN_COMPLEX_BFLOAT16_COMPLEX_BFLOAT16): Ditto. > (BT_FN_BFLOAT16_COMPLEX_BFLOAT16): Ditto. > (BT_FN_INT_BFLOAT16): Ditto. > (BT_FN_LONG_BFLOAT16): Ditto. > (BT_FN_LONGLONG_BFLOAT16): Ditto. > (BT_FN_BFLOAT16_BFLOAT16_BFLOAT16PTR): Ditto. > (BT_FN_BFLOAT16_BFLOAT16_INT): Ditto. > (BT_FN_BFLOAT16_BFLOAT16_INTPTR): Ditto. > (BT_FN_BFLOAT16_BFLOAT16_LONG): Ditto. > (BT_FN_COMPLEX_BFLOAT16_COMPLEX_BFLOAT16_COMPLEX_BFLOAT16): Ditto. > (BT_FN_BFLOAT16_BFLOAT16_BFLOAT16_BFLOAT16): Ditto. > (BT_FN_BFLOAT16_BFLOAT16_BFLOAT16_INTPTR): Ditto. > * builtins.cc (expand_builtin_classify_type): Support BF16. > (mathfn_built_in_2): Ditto. > (CASE_MATHFN_FLOATN): Ditto. > * builtins.def (DEF_GCC_FLOATN_NX_BUILTINS): Ditto. > (DEF_EXT_LIB_FLOATN_NX_BUILTINS): Ditto. > (BUILT_IN_NANSF16B): Added in general processing, redundant > is removed here. > (BUILT_IN_NEXTAFTERF16B): Ditto. > * fold-const-call.cc (fold_const_call): Ditto. > (fold_const_call_sss): Ditto. > * gencfn-macros.cc: Support BF16. > * match.pd: Like FP16, add optimization for BF16. > * tree.h (CASE_FLT_FN_FLOATN_NX): Support BF16. > > gcc/c-family/ChangeLog: > > * c-cppbuiltin.cc (c_cpp_builtins): Modify suffix names to avoid > conflicts. > > libgcc/ChangeLog: > > * Makefile.in: Add _mulbc3 and _divbc3. > * libgcc2.c (if): Ditto. > (defined): Ditto. > (MTYPE): Macros defined for BF16. > (CTYPE): Ditto. > (AMTYPE): Ditto. > (MODE): Ditto. > (CEXT): Ditto. > (NOTRUNC): Ditto. > * libgcc2.h (LIBGCC2_HAS_BF_MODE): Support BF16. > (__attribute__): Ditto. > (__divbc3): Add __divbc3 declaration. > (__mulbc3): Add __mulbc3 declaration. > > Signed-off-by: Xiao Zeng <zengx...@eswincomputing.com>
This looks all wrong to me. On all the other targets that already do support __bf16 type it is a storage only type, so all arithmetics on it is expected to be done on float, not in __bf16. Therefore, those targets really don't want any of those other builtins, there will be no libm support for it, and they don't want support in libgcc either, that is just wasted code. Intentionally the only builtins provided are the minimum required for proper C++23 support, __builtin_nansf16b and __builtin_nextafterf16b, because those need to be constexpr friendly and can't be dealt with by extending to float and using float builtins. So, if riscv wants something different (will there by e.g. any libm implementation with all the __bf16 APIs though?), it should ask for it some way (target hook or whatever) and only in that case it should enable the other builtins, libgcc APIs etc. Jakub