From c2565a31c1622ab0926aeef4a6579413e121b9f9 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Fri, 14 Oct 2022 09:37:01 +0200 Subject: middle-end, c++, i386, libgcc: std::bfloat16_t and __bf16 arithmetic support Here is a complete patch to add std::bfloat16_t support on x86 (AArch64 and ARM left for later). Almost no BFmode optabs are added by the patch, so for binops/unops it extends to SFmode first and then truncates back to BFmode. For {HF,SF,DF,XF,TF}mode -> BFmode conversions libgcc has implementations of all those conversions so that we avoid double rounding, for BFmode -> {DF,XF,TF}mode conversions to avoid growing libgcc too much it emits BFmode -> SFmode conversion first and then converts to the even wider mode, neither step should be imprecise. For BFmode -> HFmode, it first emits a precise BFmode -> SFmode conversion and then SFmode -> HFmode, because neither format is subset or superset of the other, while SFmode is superset of both. expr.cc then contains a -ffast-math optimization of the BF -> SF and SF -> BF conversions if we don't optimize for space (and for the latter if -frounding-math isn't enabled either). For x86, perhaps truncsfbf2 optab could be defined for TARGET_AVX512BF16 but IMNSHO should FAIL if !flag_finite_math || flag_rounding_math || !flag_unsafe_math_optimizations, because I think the insn doesn't raise on sNaNs, hardcodes round to nearest and flushes denormals to zero. By default (unless x86 -fexcess-precision=16) we use float excess precision for BFmode, so truncate only on explicit casts and assignments. The patch introduces a single __bf16 builtin - __builtin_nansf16b, because (__bf16) __builtin_nansf ("") will drop the sNaN into qNaN, and uses f16b suffix instead of bf16 because there would be ambiguity on log vs. logb - __builtin_logbf16 could be either log with bf16 suffix or logb with f16 suffix. In other cases libstdc++ should mostly use __builtin_*f for std::bfloat16_t overloads (we have a problem with std::nextafter though but that one we have also for std::float16_t). 2022-10-14 Jakub Jelinek gcc/ * tree-core.h (enum tree_index): Add TI_BFLOAT16_TYPE. * tree.h (bfloat16_type_node): Define. * tree.cc (excess_precision_type): Promote bfloat16_type_mode like float16_type_mode. (build_common_tree_nodes): Initialize bfloat16_type_node if BFmode is supported. * expmed.h (maybe_expand_shift): Declare. * expmed.cc (maybe_expand_shift): No longer static. * expr.cc (convert_mode_scalar): Don't ICE on BF -> HF or HF -> BF conversions. If there is no optab, handle BF -> {DF,XF,TF,HF} conversions as separate BF -> SF -> {DF,XF,TF,HF} conversions, add -ffast-math generic implementation for BF -> SF and SF -> BF conversions. * builtin-types.def (BT_BFLOAT16, BT_FN_BFLOAT16_CONST_STRING): New. * builtins.def (BUILT_IN_NANSF16B): New builtin. * fold-const-call.cc (fold_const_call): Handle CFN_BUILT_IN_NANSF16B. * config/i386/i386.cc (classify_argument): Handle E_BCmode. (ix86_libgcc_floating_mode_supported_p): Also return true for BFmode for -msse2. (ix86_mangle_type): Mangle BFmode as DF16b. (ix86_invalid_conversion, ix86_invalid_unary_op, ix86_invalid_binary_op): Remove. (TARGET_INVALID_CONVERSION, TARGET_INVALID_UNARY_OP, TARGET_INVALID_BINARY_OP): Don't redefine. * config/i386/i386-builtins.cc (ix86_bf16_type_node): Remove. (ix86_register_bf16_builtin_type): Use bfloat16_type_node rather than ix86_bf16_type_node, only create it if still NULL. * config/i386/i386-builtin-types.def (BFLOAT16): Likewise. * config/i386/i386.md (cbranchbf4, cstorebf4): New expanders. gcc/c-family/ * c-cppbuiltin.cc (c_cpp_builtins): If bfloat16_type_node, predefine __BFLT16_*__ macros and for C++23 also __STDCPP_BFLOAT16_T__. Predefine bfloat16_type_node related macros for -fbuilding-libgcc. * c-lex.cc (interpret_float): Handle CPP_N_BFLOAT16. gcc/c/ * c-typeck.cc (convert_arguments): Don't promote __bf16 to double. gcc/cp/ * cp-tree.h (extended_float_type_p): Return true for bfloat16_type_node. * typeck.cc (cp_compare_floating_point_conversion_ranks): Set extended{1,2} if mv{1,2} is bfloat16_type_node. Adjust comment. gcc/testsuite/ * lib/target-supports.exp (check_effective_target_bfloat16, check_effective_target_bfloat16_runtime, add_options_for_bfloat16): New. * gcc.dg/torture/bfloat16-basic.c: New test. * gcc.dg/torture/bfloat16-builtin.c: New test. * gcc.dg/torture/bfloat16-builtin-issignaling-1.c: New test. * gcc.dg/torture/bfloat16-complex.c: New test. * gcc.dg/torture/builtin-issignaling-1.c: Allow to be includable from bfloat16-builtin-issignaling-1.c. * gcc.dg/torture/floatn-basic.h: Allow to be includable from bfloat16-basic.c. * gcc.target/i386/vect-bfloat16-typecheck_2.c: Adjust expected diagnostics. * gcc.target/i386/sse2-bfloat16-scalar-typecheck.c: Likewise. * gcc.target/i386/vect-bfloat16-typecheck_1.c: Likewise. * g++.target/i386/bfloat_cpp_typecheck.C: Likewise. libcpp/ * include/cpplib.h (CPP_N_BFLOAT16): Define. * expr.cc (interpret_float_suffix): Handle bf16 and BF16 suffixes for C++. libgcc/ * config/i386/t-softfp (softfp_extensions): Add bfsf. (softfp_truncations): Add tfbf xfbf dfbf sfbf hfbf. (CFLAGS-extendbfsf2.c, CFLAGS-truncsfbf2.c, CFLAGS-truncdfbf2.c, CFLAGS-truncxfbf2.c, CFLAGS-trunctfbf2.c, CFLAGS-trunchfbf2.c): Add -msse2. * config/i386/libgcc-glibc.ver (GCC_13.0.0): Export __extendbfsf2 and __trunc{s,d,x,t,h}fbf2. * config/i386/sfp-machine.h (_FP_NANSIGN_B): Define. * config/i386/64/sfp-machine.h (_FP_NANFRAC_B): Define. * config/i386/32/sfp-machine.h (_FP_NANFRAC_B): Define. * soft-fp/brain.h: New file. * soft-fp/truncsfbf2.c: New file. * soft-fp/truncdfbf2.c: New file. * soft-fp/truncxfbf2.c: New file. * soft-fp/trunctfbf2.c: New file. * soft-fp/trunchfbf2.c: New file. * soft-fp/truncbfhf2.c: New file. * soft-fp/extendbfsf2.c: New file. libiberty/ * cp-demangle.h (D_BUILTIN_TYPE_COUNT): Increment. * cp-demangle.c (cplus_demangle_builtin_types): Add std::bfloat16_t entry. (cplus_demangle_type): Demangle DF16b. * testsuite/demangle-expected (_Z3xxxDF16b): New test. --- gcc/fold-const-call.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'gcc/fold-const-call.cc') diff --git a/gcc/fold-const-call.cc b/gcc/fold-const-call.cc index 7295387..7e0d671 100644 --- a/gcc/fold-const-call.cc +++ b/gcc/fold-const-call.cc @@ -1301,6 +1301,7 @@ fold_const_call (combined_fn fn, tree type, tree arg) CASE_CFN_NANS: CASE_FLT_FN_FLOATN_NX (CFN_BUILT_IN_NANS): + case CFN_BUILT_IN_NANSF16B: case CFN_BUILT_IN_NANSD32: case CFN_BUILT_IN_NANSD64: case CFN_BUILT_IN_NANSD128: -- cgit v1.1 From 7f940822816917fea276654514eccdc8eacd5e93 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Mon, 31 Oct 2022 09:05:02 +0100 Subject: builtins: Add various __builtin_*f{16,32,64,128,32x,64x,128x} builtins When working on libstdc++ extended float support in , I found that we need various builtins for the _Float{16,32,64,128,32x,64x,128x} types. Glibc 2.26 and later provides the underlying libm routines (except for _Float16 and _Float128x for the time being) and in libstdc++ I think we need at least the _Float128 builtins on x86_64, i?86, powerpc64le and ia64 (when long double is IEEE quad, we can handle it by using __builtin_*l instead), because without the builtins the overloads couldn't be constexpr (say when it would declare the *f128 extern "C" routines itself and call them). The testcase covers just types of those builtins and their constant folding, so doesn't need actual libm support. 2022-10-31 Jakub Jelinek * builtin-types.def (BT_FLOAT16_PTR, BT_FLOAT32_PTR, BT_FLOAT64_PTR, BT_FLOAT128_PTR, BT_FLOAT32X_PTR, BT_FLOAT64X_PTR, BT_FLOAT128X_PTR): New DEF_PRIMITIVE_TYPE. (BT_FN_INT_FLOAT16, BT_FN_INT_FLOAT32, BT_FN_INT_FLOAT64, BT_FN_INT_FLOAT128, BT_FN_INT_FLOAT32X, BT_FN_INT_FLOAT64X, BT_FN_INT_FLOAT128X, BT_FN_LONG_FLOAT16, BT_FN_LONG_FLOAT32, BT_FN_LONG_FLOAT64, BT_FN_LONG_FLOAT128, BT_FN_LONG_FLOAT32X, BT_FN_LONG_FLOAT64X, BT_FN_LONG_FLOAT128X, BT_FN_LONGLONG_FLOAT16, BT_FN_LONGLONG_FLOAT32, BT_FN_LONGLONG_FLOAT64, BT_FN_LONGLONG_FLOAT128, BT_FN_LONGLONG_FLOAT32X, BT_FN_LONGLONG_FLOAT64X, BT_FN_LONGLONG_FLOAT128X): New DEF_FUNCTION_TYPE_1. (BT_FN_FLOAT16_FLOAT16_FLOAT16PTR, BT_FN_FLOAT32_FLOAT32_FLOAT32PTR, BT_FN_FLOAT64_FLOAT64_FLOAT64PTR, BT_FN_FLOAT128_FLOAT128_FLOAT128PTR, BT_FN_FLOAT32X_FLOAT32X_FLOAT32XPTR, BT_FN_FLOAT64X_FLOAT64X_FLOAT64XPTR, BT_FN_FLOAT128X_FLOAT128X_FLOAT128XPTR, BT_FN_FLOAT16_FLOAT16_INT, BT_FN_FLOAT32_FLOAT32_INT, BT_FN_FLOAT64_FLOAT64_INT, BT_FN_FLOAT128_FLOAT128_INT, BT_FN_FLOAT32X_FLOAT32X_INT, BT_FN_FLOAT64X_FLOAT64X_INT, BT_FN_FLOAT128X_FLOAT128X_INT, BT_FN_FLOAT16_FLOAT16_INTPTR, BT_FN_FLOAT32_FLOAT32_INTPTR, BT_FN_FLOAT64_FLOAT64_INTPTR, BT_FN_FLOAT128_FLOAT128_INTPTR, BT_FN_FLOAT32X_FLOAT32X_INTPTR, BT_FN_FLOAT64X_FLOAT64X_INTPTR, BT_FN_FLOAT128X_FLOAT128X_INTPTR, BT_FN_FLOAT16_FLOAT16_LONG, BT_FN_FLOAT32_FLOAT32_LONG, BT_FN_FLOAT64_FLOAT64_LONG, BT_FN_FLOAT128_FLOAT128_LONG, BT_FN_FLOAT32X_FLOAT32X_LONG, BT_FN_FLOAT64X_FLOAT64X_LONG, BT_FN_FLOAT128X_FLOAT128X_LONG): New DEF_FUNCTION_TYPE_2. (BT_FN_FLOAT16_FLOAT16_FLOAT16_INTPTR, BT_FN_FLOAT32_FLOAT32_FLOAT32_INTPTR, BT_FN_FLOAT64_FLOAT64_FLOAT64_INTPTR, BT_FN_FLOAT128_FLOAT128_FLOAT128_INTPTR, BT_FN_FLOAT32X_FLOAT32X_FLOAT32X_INTPTR, BT_FN_FLOAT64X_FLOAT64X_FLOAT64X_INTPTR, BT_FN_FLOAT128X_FLOAT128X_FLOAT128X_INTPTR): New DEF_FUNCTION_TYPE_3. * builtins.def (ACOSH_TYPE, ATAN2_TYPE, ATANH_TYPE, COSH_TYPE, FDIM_TYPE, HUGE_VAL_TYPE, HYPOT_TYPE, ILOGB_TYPE, LDEXP_TYPE, LGAMMA_TYPE, LLRINT_TYPE, LOG10_TYPE, LRINT_TYPE, MODF_TYPE, NEXTAFTER_TYPE, REMQUO_TYPE, SCALBLN_TYPE, SCALBN_TYPE, SINH_TYPE): Define and undefine later. (FMIN_TYPE, SQRT_TYPE): Undefine at a later line. (INF_TYPE): Define at a later line. (BUILT_IN_ACOSH, BUILT_IN_ACOS, BUILT_IN_ASINH, BUILT_IN_ASIN, BUILT_IN_ATAN2, BUILT_IN_ATANH, BUILT_IN_ATAN, BUILT_IN_CBRT, BUILT_IN_COSH, BUILT_IN_COS, BUILT_IN_ERFC, BUILT_IN_ERF, BUILT_IN_EXP2, BUILT_IN_EXP, BUILT_IN_EXPM1, BUILT_IN_FDIM, BUILT_IN_FMOD, BUILT_IN_FREXP, BUILT_IN_HYPOT, BUILT_IN_ILOGB, BUILT_IN_LDEXP, BUILT_IN_LGAMMA, BUILT_IN_LLRINT, BUILT_IN_LLROUND, BUILT_IN_LOG10, BUILT_IN_LOG1P, BUILT_IN_LOG2, BUILT_IN_LOGB, BUILT_IN_LOG, BUILT_IN_LRINT, BUILT_IN_LROUND, BUILT_IN_MODF, BUILT_IN_NEXTAFTER, BUILT_IN_POW, BUILT_IN_REMAINDER, BUILT_IN_REMQUO, BUILT_IN_SCALBLN, BUILT_IN_SCALBN, BUILT_IN_SINH, BUILT_IN_SIN, BUILT_IN_TANH, BUILT_IN_TAN, BUILT_IN_TGAMMA): Add DEF_EXT_LIB_FLOATN_NX_BUILTINS. (BUILT_IN_HUGE_VAL): Use HUGE_VAL_TYPE instead of INF_TYPE in DEF_GCC_FLOATN_NX_BUILTINS. * fold-const-call.cc (fold_const_call_ss): Add various CASE_CFN_*_FN: cases when CASE_CFN_* is present. (fold_const_call_sss): Likewise. * builtins.cc (mathfn_built_in_2): Use CASE_MATHFN_FLOATN instead of CASE_MATHFN for various builtins in SEQ_OF_CASE_MATHFN macro. (builtin_with_linkage_p): Add CASE_FLT_FN_FLOATN_NX for various builtins next to CASE_FLT_FN. * fold-const.cc (tree_call_nonnegative_warnv_p): Add CASE_CFN_*_FN: next to CASE_CFN_*: for various builtins. * tree-call-cdce.cc (can_test_argument_range): Add CASE_FLT_FN_FLOATN_NX next to CASE_FLT_FN for various builtins. (edom_only_function): Likewise. * gcc.dg/torture/floatn-builtin.h: Add tests for newly added builtins. --- gcc/fold-const-call.cc | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'gcc/fold-const-call.cc') diff --git a/gcc/fold-const-call.cc b/gcc/fold-const-call.cc index 7e0d671..5f15815 100644 --- a/gcc/fold-const-call.cc +++ b/gcc/fold-const-call.cc @@ -734,64 +734,82 @@ fold_const_call_ss (real_value *result, combined_fn fn, && do_mpfr_arg1 (result, mpfr_sqrt, arg, format)); CASE_CFN_CBRT: + CASE_CFN_CBRT_FN: return do_mpfr_arg1 (result, mpfr_cbrt, arg, format); CASE_CFN_ASIN: + CASE_CFN_ASIN_FN: return (real_compare (GE_EXPR, arg, &dconstm1) && real_compare (LE_EXPR, arg, &dconst1) && do_mpfr_arg1 (result, mpfr_asin, arg, format)); CASE_CFN_ACOS: + CASE_CFN_ACOS_FN: return (real_compare (GE_EXPR, arg, &dconstm1) && real_compare (LE_EXPR, arg, &dconst1) && do_mpfr_arg1 (result, mpfr_acos, arg, format)); CASE_CFN_ATAN: + CASE_CFN_ATAN_FN: return do_mpfr_arg1 (result, mpfr_atan, arg, format); CASE_CFN_ASINH: + CASE_CFN_ASINH_FN: return do_mpfr_arg1 (result, mpfr_asinh, arg, format); CASE_CFN_ACOSH: + CASE_CFN_ACOSH_FN: return (real_compare (GE_EXPR, arg, &dconst1) && do_mpfr_arg1 (result, mpfr_acosh, arg, format)); CASE_CFN_ATANH: + CASE_CFN_ATANH_FN: return (real_compare (GE_EXPR, arg, &dconstm1) && real_compare (LE_EXPR, arg, &dconst1) && do_mpfr_arg1 (result, mpfr_atanh, arg, format)); CASE_CFN_SIN: + CASE_CFN_SIN_FN: return do_mpfr_arg1 (result, mpfr_sin, arg, format); CASE_CFN_COS: + CASE_CFN_COS_FN: return do_mpfr_arg1 (result, mpfr_cos, arg, format); CASE_CFN_TAN: + CASE_CFN_TAN_FN: return do_mpfr_arg1 (result, mpfr_tan, arg, format); CASE_CFN_SINH: + CASE_CFN_SINH_FN: return do_mpfr_arg1 (result, mpfr_sinh, arg, format); CASE_CFN_COSH: + CASE_CFN_COSH_FN: return do_mpfr_arg1 (result, mpfr_cosh, arg, format); CASE_CFN_TANH: + CASE_CFN_TANH_FN: return do_mpfr_arg1 (result, mpfr_tanh, arg, format); CASE_CFN_ERF: + CASE_CFN_ERF_FN: return do_mpfr_arg1 (result, mpfr_erf, arg, format); CASE_CFN_ERFC: + CASE_CFN_ERFC_FN: return do_mpfr_arg1 (result, mpfr_erfc, arg, format); CASE_CFN_TGAMMA: + CASE_CFN_TGAMMA_FN: return do_mpfr_arg1 (result, mpfr_gamma, arg, format); CASE_CFN_EXP: + CASE_CFN_EXP_FN: return do_mpfr_arg1 (result, mpfr_exp, arg, format); CASE_CFN_EXP2: + CASE_CFN_EXP2_FN: return do_mpfr_arg1 (result, mpfr_exp2, arg, format); CASE_CFN_EXP10: @@ -799,21 +817,26 @@ fold_const_call_ss (real_value *result, combined_fn fn, return do_mpfr_arg1 (result, mpfr_exp10, arg, format); CASE_CFN_EXPM1: + CASE_CFN_EXPM1_FN: return do_mpfr_arg1 (result, mpfr_expm1, arg, format); CASE_CFN_LOG: + CASE_CFN_LOG_FN: return (real_compare (GT_EXPR, arg, &dconst0) && do_mpfr_arg1 (result, mpfr_log, arg, format)); CASE_CFN_LOG2: + CASE_CFN_LOG2_FN: return (real_compare (GT_EXPR, arg, &dconst0) && do_mpfr_arg1 (result, mpfr_log2, arg, format)); CASE_CFN_LOG10: + CASE_CFN_LOG10_FN: return (real_compare (GT_EXPR, arg, &dconst0) && do_mpfr_arg1 (result, mpfr_log10, arg, format)); CASE_CFN_LOG1P: + CASE_CFN_LOG1P_FN: return (real_compare (GT_EXPR, arg, &dconstm1) && do_mpfr_arg1 (result, mpfr_log1p, arg, format)); @@ -877,6 +900,7 @@ fold_const_call_ss (real_value *result, combined_fn fn, return false; CASE_CFN_LOGB: + CASE_CFN_LOGB_FN: return fold_const_logb (result, arg, format); CASE_CFN_SIGNIFICAND: @@ -909,6 +933,7 @@ fold_const_call_ss (wide_int *result, combined_fn fn, return true; CASE_CFN_ILOGB: + CASE_CFN_ILOGB_FN: /* For ilogb we don't know FP_ILOGB0, so only handle normal values. Proceed iff radix == 2. In GCC, normalized significands are in the range [0.5, 1.0). We want the exponent as if they were @@ -934,13 +959,17 @@ fold_const_call_ss (wide_int *result, combined_fn fn, CASE_CFN_IROUND: CASE_CFN_LROUND: + CASE_CFN_LROUND_FN: CASE_CFN_LLROUND: + CASE_CFN_LLROUND_FN: return fold_const_conversion (result, real_round, arg, precision, format); CASE_CFN_IRINT: CASE_CFN_LRINT: + CASE_CFN_LRINT_FN: CASE_CFN_LLRINT: + CASE_CFN_LLRINT_FN: /* Not yet folded to a constant. */ return false; @@ -1370,18 +1399,23 @@ fold_const_call_sss (real_value *result, combined_fn fn, { CASE_CFN_DREM: CASE_CFN_REMAINDER: + CASE_CFN_REMAINDER_FN: return do_mpfr_arg2 (result, mpfr_remainder, arg0, arg1, format); CASE_CFN_ATAN2: + CASE_CFN_ATAN2_FN: return do_mpfr_arg2 (result, mpfr_atan2, arg0, arg1, format); CASE_CFN_FDIM: + CASE_CFN_FDIM_FN: return do_mpfr_arg2 (result, mpfr_dim, arg0, arg1, format); CASE_CFN_FMOD: + CASE_CFN_FMOD_FN: return do_mpfr_arg2 (result, mpfr_fmod, arg0, arg1, format); CASE_CFN_HYPOT: + CASE_CFN_HYPOT_FN: return do_mpfr_arg2 (result, mpfr_hypot, arg0, arg1, format); CASE_CFN_COPYSIGN: @@ -1399,9 +1433,11 @@ fold_const_call_sss (real_value *result, combined_fn fn, return do_mpfr_arg2 (result, mpfr_max, arg0, arg1, format); CASE_CFN_POW: + CASE_CFN_POW_FN: return fold_const_pow (result, arg0, arg1, format); CASE_CFN_NEXTAFTER: + CASE_CFN_NEXTAFTER_FN: CASE_CFN_NEXTTOWARD: return fold_const_nextafter (result, arg0, arg1, format); @@ -1425,10 +1461,13 @@ fold_const_call_sss (real_value *result, combined_fn fn, switch (fn) { CASE_CFN_LDEXP: + CASE_CFN_LDEXP_FN: return fold_const_builtin_load_exponent (result, arg0, arg1, format); CASE_CFN_SCALBN: + CASE_CFN_SCALBN_FN: CASE_CFN_SCALBLN: + CASE_CFN_SCALBLN_FN: return (format->b == 2 && fold_const_builtin_load_exponent (result, arg0, arg1, format)); -- cgit v1.1 From 29490c2a1dc00944f2420eb59374705f180a2e53 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Mon, 31 Oct 2022 09:07:04 +0100 Subject: builtins: Add __builtin_nextafterf16b builtin The following patch adds another needed builtin. The earlier patch adds among other things __builtin_nextafterf16 builtin which we need in order to constexpr evaluate std::nextafter(_Float16) overload (patch for that has been posted already). While there is inline implementation of the overload, it isn't constant evaluation friendly, and the builtin doesn't need libm implementation because it will be used only during constant expression evaluation. We need the same thing also for std::nextafter(__gnu_cxx::__bfloat16_t) though and this patch does that. 2022-10-31 Jakub Jelinek * builtin-types.def (BT_FN_BFLOAT16_BFLOAT16_BFLOAT16): New. * builtins.def (BUILT_IN_NEXTAFTERF16B): New builtin. * fold-const-call.cc (fold_const_call_sss): Handle CFN_BUILT_IN_NEXTAFTERF16B. --- gcc/fold-const-call.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'gcc/fold-const-call.cc') diff --git a/gcc/fold-const-call.cc b/gcc/fold-const-call.cc index 5f15815..ab1b098 100644 --- a/gcc/fold-const-call.cc +++ b/gcc/fold-const-call.cc @@ -1438,6 +1438,7 @@ fold_const_call_sss (real_value *result, combined_fn fn, CASE_CFN_NEXTAFTER: CASE_CFN_NEXTAFTER_FN: + case CFN_BUILT_IN_NEXTAFTERF16B: CASE_CFN_NEXTTOWARD: return fold_const_nextafter (result, arg0, arg1, format); -- cgit v1.1 From 259a11555c90783e53c046c310080407ee54a31e Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Mon, 31 Oct 2022 09:09:48 +0100 Subject: builtins: Add various complex builtins for _Float{16,32,64,128,32x,64x,128x} The following patch adds some complex builtins which have libm implementation in glibc 2.26 and later on various arches. It is needed for libstdc++ _Float128 support when long double is not IEEE quad. 2022-10-31 Jakub Jelinek * builtin-types.def (BT_COMPLEX_FLOAT16, BT_COMPLEX_FLOAT32, BT_COMPLEX_FLOAT64, BT_COMPLEX_FLOAT128, BT_COMPLEX_FLOAT32X, BT_COMPLEX_FLOAT64X, BT_COMPLEX_FLOAT128X, BT_FN_COMPLEX_FLOAT16_COMPLEX_FLOAT16, BT_FN_COMPLEX_FLOAT32_COMPLEX_FLOAT32, BT_FN_COMPLEX_FLOAT64_COMPLEX_FLOAT64, BT_FN_COMPLEX_FLOAT128_COMPLEX_FLOAT128, BT_FN_COMPLEX_FLOAT32X_COMPLEX_FLOAT32X, BT_FN_COMPLEX_FLOAT64X_COMPLEX_FLOAT64X, BT_FN_COMPLEX_FLOAT128X_COMPLEX_FLOAT128X, BT_FN_FLOAT16_COMPLEX_FLOAT16, BT_FN_FLOAT32_COMPLEX_FLOAT32, BT_FN_FLOAT64_COMPLEX_FLOAT64, BT_FN_FLOAT128_COMPLEX_FLOAT128, BT_FN_FLOAT32X_COMPLEX_FLOAT32X, BT_FN_FLOAT64X_COMPLEX_FLOAT64X, BT_FN_FLOAT128X_COMPLEX_FLOAT128X, BT_FN_COMPLEX_FLOAT16_COMPLEX_FLOAT16_COMPLEX_FLOAT16, BT_FN_COMPLEX_FLOAT32_COMPLEX_FLOAT32_COMPLEX_FLOAT32, BT_FN_COMPLEX_FLOAT64_COMPLEX_FLOAT64_COMPLEX_FLOAT64, BT_FN_COMPLEX_FLOAT128_COMPLEX_FLOAT128_COMPLEX_FLOAT128, BT_FN_COMPLEX_FLOAT32X_COMPLEX_FLOAT32X_COMPLEX_FLOAT32X, BT_FN_COMPLEX_FLOAT64X_COMPLEX_FLOAT64X_COMPLEX_FLOAT64X, BT_FN_COMPLEX_FLOAT128X_COMPLEX_FLOAT128X_COMPLEX_FLOAT128X): New. * builtins.def (CABS_TYPE, CACOSH_TYPE, CARG_TYPE, CASINH_TYPE, CPOW_TYPE, CPROJ_TYPE): Define and undefine later. (BUILT_IN_CABS, BUILT_IN_CACOSH, BUILT_IN_CACOS, BUILT_IN_CARG, BUILT_IN_CASINH, BUILT_IN_CASIN, BUILT_IN_CATANH, BUILT_IN_CATAN, BUILT_IN_CCOSH, BUILT_IN_CCOS, BUILT_IN_CEXP, BUILT_IN_CLOG, BUILT_IN_CPOW, BUILT_IN_CPROJ, BUILT_IN_CSINH, BUILT_IN_CSIN, BUILT_IN_CSQRT, BUILT_IN_CTANH, BUILT_IN_CTAN): Add DEF_EXT_LIB_FLOATN_NX_BUILTINS. * fold-const-call.cc (fold_const_call_sc, fold_const_call_cc, fold_const_call_ccc): Add various CASE_CFN_*_FN: cases when CASE_CFN_* is present. * gimple-ssa-backprop.cc (backprop::process_builtin_call_use): Likewise. * builtins.cc (expand_builtin, fold_builtin_1): Likewise. * fold-const.cc (negate_mathfn_p, tree_expr_finite_p, tree_expr_maybe_signaling_nan_p, tree_expr_maybe_nan_p, tree_expr_maybe_real_minus_zero_p, tree_call_nonnegative_warnv_p): Likewise. --- gcc/fold-const-call.cc | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'gcc/fold-const-call.cc') diff --git a/gcc/fold-const-call.cc b/gcc/fold-const-call.cc index ab1b098..8ceed8f 100644 --- a/gcc/fold-const-call.cc +++ b/gcc/fold-const-call.cc @@ -1112,6 +1112,7 @@ fold_const_call_sc (real_value *result, combined_fn fn, switch (fn) { CASE_CFN_CABS: + CASE_CFN_CABS_FN: return do_mpfr_arg2 (result, mpfr_hypot, arg_real, arg_imag, format); default: @@ -1135,14 +1136,17 @@ fold_const_call_cc (real_value *result_real, real_value *result_imag, switch (fn) { CASE_CFN_CCOS: + CASE_CFN_CCOS_FN: return do_mpc_arg1 (result_real, result_imag, mpc_cos, arg_real, arg_imag, format); CASE_CFN_CCOSH: + CASE_CFN_CCOSH_FN: return do_mpc_arg1 (result_real, result_imag, mpc_cosh, arg_real, arg_imag, format); CASE_CFN_CPROJ: + CASE_CFN_CPROJ_FN: if (real_isinf (arg_real) || real_isinf (arg_imag)) { *result_real = dconstinf; @@ -1157,54 +1161,67 @@ fold_const_call_cc (real_value *result_real, real_value *result_imag, return true; CASE_CFN_CSIN: + CASE_CFN_CSIN_FN: return do_mpc_arg1 (result_real, result_imag, mpc_sin, arg_real, arg_imag, format); CASE_CFN_CSINH: + CASE_CFN_CSINH_FN: return do_mpc_arg1 (result_real, result_imag, mpc_sinh, arg_real, arg_imag, format); CASE_CFN_CTAN: + CASE_CFN_CTAN_FN: return do_mpc_arg1 (result_real, result_imag, mpc_tan, arg_real, arg_imag, format); CASE_CFN_CTANH: + CASE_CFN_CTANH_FN: return do_mpc_arg1 (result_real, result_imag, mpc_tanh, arg_real, arg_imag, format); CASE_CFN_CLOG: + CASE_CFN_CLOG_FN: return do_mpc_arg1 (result_real, result_imag, mpc_log, arg_real, arg_imag, format); CASE_CFN_CSQRT: + CASE_CFN_CSQRT_FN: return do_mpc_arg1 (result_real, result_imag, mpc_sqrt, arg_real, arg_imag, format); CASE_CFN_CASIN: + CASE_CFN_CASIN_FN: return do_mpc_arg1 (result_real, result_imag, mpc_asin, arg_real, arg_imag, format); CASE_CFN_CACOS: + CASE_CFN_CACOS_FN: return do_mpc_arg1 (result_real, result_imag, mpc_acos, arg_real, arg_imag, format); CASE_CFN_CATAN: + CASE_CFN_CATAN_FN: return do_mpc_arg1 (result_real, result_imag, mpc_atan, arg_real, arg_imag, format); CASE_CFN_CASINH: + CASE_CFN_CASINH_FN: return do_mpc_arg1 (result_real, result_imag, mpc_asinh, arg_real, arg_imag, format); CASE_CFN_CACOSH: + CASE_CFN_CACOSH_FN: return do_mpc_arg1 (result_real, result_imag, mpc_acosh, arg_real, arg_imag, format); CASE_CFN_CATANH: + CASE_CFN_CATANH_FN: return do_mpc_arg1 (result_real, result_imag, mpc_atanh, arg_real, arg_imag, format); CASE_CFN_CEXP: + CASE_CFN_CEXP_FN: return do_mpc_arg1 (result_real, result_imag, mpc_exp, arg_real, arg_imag, format); @@ -1532,6 +1549,7 @@ fold_const_call_ccc (real_value *result_real, real_value *result_imag, switch (fn) { CASE_CFN_CPOW: + CASE_CFN_CPOW_FN: return do_mpc_arg2 (result_real, result_imag, mpc_pow, arg0_real, arg0_imag, arg1_real, arg1_imag, format); -- cgit v1.1