[libc-commits] [libc] [libc][math] Rebase constexpr-math onto main and migrate to LIBC_USE_CONSTEXPR (continues #195623) (PR #234340)
via libc-commits
libc-commits at lists.llvm.org
Wed Oct 21 12:47:11 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Linisha (linisha15)
<details>
<summary>Changes</summary>
## Summary
This PR continues @<!-- -->bassiounix's work in #<!-- -->195623 ("Qualify all math functions to be constexpr"). Since I don't have push access to that PR's head branch, I'm continuing it from my fork.
#<!-- -->195623 had gone stale (branched ~24k commits behind `main`) and conflicted. This PR brings it up to date and migrates it onto the current constexpr macro setup. It is intentionally **staged**: this first step produces a clean, buildable baseline; re-qualifying the functions that `main` has since rewritten, and restoring the full constexpr test suite, will follow.
## What this PR does
- Merges latest `main` into the constexpr-math branch and resolves all 17 conflicts.
- Migrates the old `LIBC_HAS_CONSTANT_EVALUATION` guard marker to the new `LIBC_USE_CONSTEXPR` marker (e.g. in `FEnvImpl.h`), per the macro setup introduced in #<!-- -->197774. (The old name is now a *value* macro, so the old `!defined(...)` guards would silently break.)
- Combines the PR's `constexpr`/macro qualifiers with `main`'s type/namespace refactors where they collided: `atan2f16`, `exp`, `log1p`, `nextafterl`, `sqrtf128`, `tan`. (`tan::newton_raphson_div` uses `LIBC_BIT_CAST_CONSTEXPR`, matching `main`'s `LIBC_BIT_CAST_CONSTEXPR_VAR` on its local — its constexpr-ability depends on `__builtin_bit_cast`.)
- Drops `inv_trigf_utils.h` (renamed to `atan_utils.h` on `main`).
## What is intentionally deferred (follow-up)
To keep this a clean, reviewable baseline and isolate CI signal:
- **constexpr on functions `main` substantially rewrote**: `hypot`, `log10f`, `powf`, `sinf`, `tanf`. `main`'s current implementations are taken as-is; re-applying `constexpr` to them is left to follow-up changes, preferring plain `constexpr` where the minimum supported compilers accept it and falling back to the macros only where they don't.
- **The constexpr test suite** (`shared_math_constexpr_test.cpp` and its `CMakeLists.txt`): `main`'s versions are taken here; per-function constexpr tests will be re-added as each function is re-qualified and confirmed by CI.
## Why draft
Marked as Draft because the re-qualification pass above is pending. This PR exists to (1) get the stale branch rebased and conflict-free, and (2) let the older-GCC CI confirm the baseline compiles across the supported compiler range (Clang 5+, GCC 7.4+).
cc @<!-- -->bassiounix
Generated with the help of ai
---
Patch is 84.34 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/234340.diff
126 Files Affected:
- (modified) libc/src/__support/FPUtil/FEnvImpl.h (+10-6)
- (modified) libc/src/__support/FPUtil/FMA.h (+4-3)
- (modified) libc/src/__support/FPUtil/Hypot.h (+5-5)
- (modified) libc/src/__support/FPUtil/ManipulationFunctions.h (+1-1)
- (modified) libc/src/__support/FPUtil/double_double.h (+6-6)
- (modified) libc/src/__support/FPUtil/dyadic_float.h (+1-1)
- (modified) libc/src/__support/FPUtil/generic/FMA.h (+12-11)
- (modified) libc/src/__support/FPUtil/nearest_integer.h (+5-3)
- (modified) libc/src/__support/math/acospif.h (+1-1)
- (modified) libc/src/__support/math/asin.h (+1-1)
- (modified) libc/src/__support/math/asinpi.h (+1-1)
- (modified) libc/src/__support/math/asinpif.h (+1-1)
- (modified) libc/src/__support/math/asinpif16.h (+1-1)
- (modified) libc/src/__support/math/atan2f16.h (+1-1)
- (modified) libc/src/__support/math/atanbf16.h (+1-1)
- (modified) libc/src/__support/math/atanf_float.h (+2-2)
- (modified) libc/src/__support/math/atanpif16.h (+1-1)
- (modified) libc/src/__support/math/bf16add.h (+1-1)
- (modified) libc/src/__support/math/bf16addf.h (+1-1)
- (modified) libc/src/__support/math/bf16addf128.h (+1-1)
- (modified) libc/src/__support/math/bf16addl.h (+1-1)
- (modified) libc/src/__support/math/bf16div.h (+1-1)
- (modified) libc/src/__support/math/bf16divf.h (+1-1)
- (modified) libc/src/__support/math/bf16divf128.h (+1-1)
- (modified) libc/src/__support/math/bf16divl.h (+1-1)
- (modified) libc/src/__support/math/bf16fma.h (+1-1)
- (modified) libc/src/__support/math/bf16fmaf.h (+1-1)
- (modified) libc/src/__support/math/bf16fmaf128.h (+2-1)
- (modified) libc/src/__support/math/bf16fmal.h (+2-1)
- (modified) libc/src/__support/math/bf16mul.h (+1-1)
- (modified) libc/src/__support/math/bf16mulf.h (+1-1)
- (modified) libc/src/__support/math/bf16mulf128.h (+1-1)
- (modified) libc/src/__support/math/bf16mull.h (+1-1)
- (modified) libc/src/__support/math/cbrt.h (+4-4)
- (modified) libc/src/__support/math/cbrtbf16.h (+1-1)
- (modified) libc/src/__support/math/ceill.h (+3-1)
- (modified) libc/src/__support/math/cos_integer_eval.h (+1-1)
- (modified) libc/src/__support/math/daddf128.h (+1-1)
- (modified) libc/src/__support/math/daddl.h (+1-1)
- (modified) libc/src/__support/math/dfmaf128.h (+1-1)
- (modified) libc/src/__support/math/dfmal.h (+2-1)
- (modified) libc/src/__support/math/dsubf128.h (+1-1)
- (modified) libc/src/__support/math/dsubl.h (+1-1)
- (modified) libc/src/__support/math/erfcf16.h (+4-4)
- (modified) libc/src/__support/math/erff16.h (+1-1)
- (modified) libc/src/__support/math/exp.h (+9-8)
- (modified) libc/src/__support/math/exp10f16_utils.h (+1-1)
- (modified) libc/src/__support/math/expf16_utils.h (+2-1)
- (modified) libc/src/__support/math/expxf16_utils.h (+1-1)
- (modified) libc/src/__support/math/f16div.h (+1-1)
- (modified) libc/src/__support/math/f16divf.h (+1-1)
- (modified) libc/src/__support/math/f16divf128.h (+1-1)
- (modified) libc/src/__support/math/f16divl.h (+1-1)
- (modified) libc/src/__support/math/f16fma.h (+1-1)
- (modified) libc/src/__support/math/f16fmaf.h (+1-1)
- (modified) libc/src/__support/math/f16fmaf128.h (+2-1)
- (modified) libc/src/__support/math/f16fmal.h (+2-1)
- (modified) libc/src/__support/math/f16mul.h (+1-1)
- (modified) libc/src/__support/math/f16mulf.h (+1-1)
- (modified) libc/src/__support/math/f16mulf128.h (+1-1)
- (modified) libc/src/__support/math/f16mull.h (+1-1)
- (modified) libc/src/__support/math/f16sqrtf128.h (+3-1)
- (modified) libc/src/__support/math/f16sub.h (+1-1)
- (modified) libc/src/__support/math/f16subf.h (+1-1)
- (modified) libc/src/__support/math/f16subf128.h (+1-1)
- (modified) libc/src/__support/math/f16subl.h (+1-1)
- (modified) libc/src/__support/math/ffma.h (+1-1)
- (modified) libc/src/__support/math/ffmaf128.h (+1-1)
- (modified) libc/src/__support/math/ffmal.h (+2-1)
- (modified) libc/src/__support/math/fma.h (+1-1)
- (modified) libc/src/__support/math/fmabf16.h (+1-1)
- (modified) libc/src/__support/math/fmaf.h (+1-1)
- (modified) libc/src/__support/math/fmaf16.h (+1-1)
- (modified) libc/src/__support/math/fmaxf.h (+1-1)
- (modified) libc/src/__support/math/hypotbf16.h (+1-1)
- (modified) libc/src/__support/math/hypotf.h (+2-2)
- (modified) libc/src/__support/math/hypotf16.h (+1-1)
- (modified) libc/src/__support/math/log10.h (+2-2)
- (modified) libc/src/__support/math/log10f16.h (+1-1)
- (modified) libc/src/__support/math/log10p1f16.h (+1-1)
- (modified) libc/src/__support/math/log1p.h (+3-3)
- (modified) libc/src/__support/math/log1pf.h (+1-1)
- (modified) libc/src/__support/math/log2.h (+2-2)
- (modified) libc/src/__support/math/log2f.h (+1-1)
- (modified) libc/src/__support/math/log2f16.h (+1-1)
- (modified) libc/src/__support/math/log2p1f16.h (+1-1)
- (modified) libc/src/__support/math/log_bf16.h (+1-1)
- (modified) libc/src/__support/math/logf.h (+1-1)
- (modified) libc/src/__support/math/logf16.h (+1-1)
- (modified) libc/src/__support/math/nextafter.h (+1-1)
- (modified) libc/src/__support/math/nextafterbf16.h (+1-1)
- (modified) libc/src/__support/math/nextafterf.h (+1-1)
- (modified) libc/src/__support/math/nextafterf128.h (+1-1)
- (modified) libc/src/__support/math/nextafterf16.h (+1-1)
- (modified) libc/src/__support/math/nextafterl.h (+2-1)
- (modified) libc/src/__support/math/nexttoward.h (+1-1)
- (modified) libc/src/__support/math/nexttowardbf16.h (+1-1)
- (modified) libc/src/__support/math/nexttowardf.h (+1-1)
- (modified) libc/src/__support/math/nexttowardf16.h (+1-2)
- (modified) libc/src/__support/math/nexttowardl.h (+2-1)
- (modified) libc/src/__support/math/pow.h (+1-1)
- (modified) libc/src/__support/math/range_reduction.h (+3-2)
- (modified) libc/src/__support/math/range_reduction_double_common.h (+1-1)
- (modified) libc/src/__support/math/range_reduction_double_fma.h (+2-1)
- (modified) libc/src/__support/math/range_reduction_double_nofma.h (+2-1)
- (modified) libc/src/__support/math/range_reduction_fma.h (+3-2)
- (modified) libc/src/__support/math/sin_integer_eval.h (+1-1)
- (modified) libc/src/__support/math/sincos.h (+1-1)
- (modified) libc/src/__support/math/sincos_integer_utils.h (+4-4)
- (modified) libc/src/__support/math/sincosf.h (+1-1)
- (modified) libc/src/__support/math/sincosf_utils.h (+10-8)
- (modified) libc/src/__support/math/sinf16.h (+2-2)
- (modified) libc/src/__support/math/sinhfcoshf_utils.h (+4-4)
- (modified) libc/src/__support/math/sinpif.h (+1-1)
- (modified) libc/src/__support/math/sinpif16.h (+1-1)
- (modified) libc/src/__support/math/sqrt.h (+3-1)
- (modified) libc/src/__support/math/sqrtbf16.h (+3-1)
- (modified) libc/src/__support/math/sqrtf.h (+3-1)
- (modified) libc/src/__support/math/sqrtf128.h (+1-1)
- (modified) libc/src/__support/math/tan.h (+9-8)
- (modified) libc/src/__support/math/tanf16.h (+2-2)
- (modified) libc/src/__support/math/tanhf.h (+1-1)
- (modified) libc/src/__support/math/tanhf16.h (+1-1)
- (modified) libc/src/__support/math/tanpif.h (+2-2)
- (modified) libc/src/__support/math/tanpif16.h (+1-1)
- (modified) libc/test/shared/shared_math_test.cpp (+2-5)
``````````diff
diff --git a/libc/src/__support/FPUtil/FEnvImpl.h b/libc/src/__support/FPUtil/FEnvImpl.h
index d556a3cbf4d39f..74804e90f635af 100644
--- a/libc/src/__support/FPUtil/FEnvImpl.h
+++ b/libc/src/__support/FPUtil/FEnvImpl.h
@@ -32,7 +32,8 @@
#undef LIBC_MATH_USE_SYSTEM_FENV
#endif // LIBC_FULL_BUILD
-#if defined(LIBC_MATH_USE_SYSTEM_FENV) && !defined(LIBC_MATH_HAS_NO_EXCEPT)
+#if defined(LIBC_MATH_USE_SYSTEM_FENV) && !defined(LIBC_MATH_HAS_NO_EXCEPT) && \
+ !defined(LIBC_USE_CONSTEXPR)
// Simply call the system libc fenv.h functions, only for those that are used in
// math function implementations.
@@ -101,7 +102,8 @@ LIBC_INLINE int set_env(const fenv_t *env) {
#else // !LIBC_MATH_USE_SYSTEM_FENV
-#if defined(LIBC_TARGET_ARCH_IS_AARCH64) && defined(__ARM_FP)
+#if defined(LIBC_TARGET_ARCH_IS_AARCH64) && defined(__ARM_FP) && \
+ !defined(LIBC_USE_CONSTEXPR)
#if defined(__APPLE__)
#include "aarch64/fenv_darwin_impl.h"
#else
@@ -112,12 +114,14 @@ LIBC_INLINE int set_env(const fenv_t *env) {
// the dummy implementations below. Once a proper x86_64 darwin fenv is set up,
// the apple condition here should be removed.
// TODO: fully support fenv for MSVC.
-#elif defined(LIBC_TARGET_ARCH_IS_X86) && !defined(__APPLE__)
+#elif defined(LIBC_TARGET_ARCH_IS_X86) && !defined(__APPLE__) && \
+ !defined(LIBC_USE_CONSTEXPR)
#include "x86_64/FEnvImpl.h"
#elif defined(LIBC_TARGET_ARCH_IS_ARM) && defined(__ARM_FP) && \
- !defined(LIBC_COMPILER_IS_MSVC)
+ !defined(LIBC_COMPILER_IS_MSVC) && !defined(LIBC_USE_CONSTEXPR)
#include "arm/FEnvImpl.h"
-#elif defined(LIBC_TARGET_ARCH_IS_ANY_RISCV) && defined(__riscv_flen)
+#elif defined(LIBC_TARGET_ARCH_IS_ANY_RISCV) && defined(__riscv_flen) && \
+ !defined(LIBC_USE_CONSTEXPR)
#include "riscv/FEnvImpl.h"
#elif defined(LIBC_TARGET_ARCH_IS_HEXAGON)
#include "hexagon/FEnvImpl.h"
@@ -142,7 +146,7 @@ LIBC_INLINE int enable_except(int) { return 0; }
LIBC_INLINE int disable_except(int) { return 0; }
-LIBC_INLINE int get_round() { return FE_TONEAREST; }
+LIBC_INLINE constexpr int get_round() { return FE_TONEAREST; }
LIBC_INLINE int set_round(int rounding_mode) {
return (rounding_mode == FE_TONEAREST) ? 0 : 1;
diff --git a/libc/src/__support/FPUtil/FMA.h b/libc/src/__support/FPUtil/FMA.h
index 2cafb4c0974e31..e56de4bb64b9fb 100644
--- a/libc/src/__support/FPUtil/FMA.h
+++ b/libc/src/__support/FPUtil/FMA.h
@@ -19,11 +19,11 @@ namespace LIBC_NAMESPACE_DECL {
namespace fputil {
template <typename OutType, typename InType>
-LIBC_INLINE OutType fma(InType x, InType y, InType z) {
+LIBC_INLINE constexpr OutType fma(InType x, InType y, InType z) {
return generic::fma<OutType>(x, y, z);
}
-#ifdef LIBC_TARGET_CPU_HAS_FMA
+#if defined(LIBC_TARGET_CPU_HAS_FMA) && !defined(LIBC_HAS_CONSTANT_EVALUATION)
#ifdef LIBC_TARGET_CPU_HAS_FMA_FLOAT
template <> LIBC_INLINE float fma(float x, float y, float z) {
@@ -44,7 +44,8 @@ template <> LIBC_INLINE double fma(double x, double y, double z) {
#endif
}
#endif // LIBC_TARGET_CPU_HAS_FMA_DOUBLE
-#endif // LIBC_TARGET_CPU_HAS_FMA
+#endif // defined(LIBC_TARGET_CPU_HAS_FMA) &&
+ // !defined(LIBC_HAS_CONSTANT_EVALUATION)
} // namespace fputil
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/__support/FPUtil/Hypot.h b/libc/src/__support/FPUtil/Hypot.h
index b28b4ac9de97df..a1d7f31ee6d0d3 100644
--- a/libc/src/__support/FPUtil/Hypot.h
+++ b/libc/src/__support/FPUtil/Hypot.h
@@ -105,7 +105,7 @@ template <> struct DoubleLength<uint64_t> {
// - HYPOT(x, y) is NaN if x or y is NaN.
//
template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0>
-LIBC_INLINE T hypot(T x, T y) {
+LIBC_INLINE constexpr T hypot(T x, T y) {
using FPBits_t = FPBits<T>;
using StorageType = typename FPBits<T>::StorageType;
using DStorageType = typename DoubleLength<StorageType>::Type;
@@ -150,8 +150,8 @@ LIBC_INLINE T hypot(T x, T y) {
uint64_t out_exp = a_exp;
StorageType a_mant = a_bits.get_mantissa();
StorageType b_mant = b_bits.get_mantissa();
- DStorageType a_mant_sq, b_mant_sq;
- bool sticky_bits;
+ DStorageType a_mant_sq{}, b_mant_sq{};
+ bool sticky_bits{};
// Add an extra bit to simplify the final rounding bit computation.
constexpr StorageType ONE = StorageType(1) << (FPBits_t::FRACTION_LEN + 1);
@@ -159,8 +159,8 @@ LIBC_INLINE T hypot(T x, T y) {
a_mant <<= 1;
b_mant <<= 1;
- StorageType leading_one;
- int y_mant_width;
+ StorageType leading_one{};
+ int y_mant_width{};
if (a_exp != 0) {
leading_one = ONE;
a_mant |= ONE;
diff --git a/libc/src/__support/FPUtil/ManipulationFunctions.h b/libc/src/__support/FPUtil/ManipulationFunctions.h
index 02dded2f47913c..bb1f83e0711d4c 100644
--- a/libc/src/__support/FPUtil/ManipulationFunctions.h
+++ b/libc/src/__support/FPUtil/ManipulationFunctions.h
@@ -214,7 +214,7 @@ template <typename T, typename U,
cpp::is_floating_point_v<U> &&
(sizeof(T) <= sizeof(U)),
int> = 0>
-LIBC_INLINE constexpr T nextafter(T from, U to) {
+LIBC_INLINE LIBC_CONSTEXPR T nextafter(T from, U to) {
FPBits<T> from_bits(from);
if (from_bits.is_nan())
return from;
diff --git a/libc/src/__support/FPUtil/double_double.h b/libc/src/__support/FPUtil/double_double.h
index 6e41bb9b2a4bed..4e4b8d34e8fa3c 100644
--- a/libc/src/__support/FPUtil/double_double.h
+++ b/libc/src/__support/FPUtil/double_double.h
@@ -167,15 +167,16 @@ LIBC_INLINE LIBC_CONSTEXPR NumberPair<T> exact_mult(T a, T b) {
}
template <typename T = double>
-LIBC_INLINE NumberPair<T> quick_mult(T a, const NumberPair<T> &b) {
+LIBC_INLINE LIBC_CONSTEXPR NumberPair<T> quick_mult(T a,
+ const NumberPair<T> &b) {
NumberPair<T> r = exact_mult(a, b.hi);
r.lo = multiply_add(a, b.lo, r.lo);
return r;
}
template <size_t SPLIT_B = 27>
-LIBC_INLINE constexpr DoubleDouble quick_mult(const DoubleDouble &a,
- const DoubleDouble &b) {
+LIBC_INLINE LIBC_CONSTEXPR DoubleDouble quick_mult(const DoubleDouble &a,
+ const DoubleDouble &b) {
DoubleDouble r = exact_mult<double, SPLIT_B>(a.hi, b.hi);
double t1 = multiply_add(a.hi, b.lo, r.lo);
double t2 = multiply_add(a.lo, b.hi, t1);
@@ -185,9 +186,8 @@ LIBC_INLINE constexpr DoubleDouble quick_mult(const DoubleDouble &a,
// Assuming |c| >= |a * b|.
template <>
-LIBC_INLINE DoubleDouble multiply_add<DoubleDouble>(const DoubleDouble &a,
- const DoubleDouble &b,
- const DoubleDouble &c) {
+LIBC_INLINE LIBC_CONSTEXPR DoubleDouble multiply_add<DoubleDouble>(
+ const DoubleDouble &a, const DoubleDouble &b, const DoubleDouble &c) {
return add(c, quick_mult(a, b));
}
diff --git a/libc/src/__support/FPUtil/dyadic_float.h b/libc/src/__support/FPUtil/dyadic_float.h
index 80335cc9f7801c..d185d70d9a3e09 100644
--- a/libc/src/__support/FPUtil/dyadic_float.h
+++ b/libc/src/__support/FPUtil/dyadic_float.h
@@ -367,7 +367,7 @@ template <size_t Bits> struct DyadicFloat {
bool sticky_bit = !(mantissa & sticky_mask).is_zero();
int round_and_sticky = int(round_bit) * 2 + int(sticky_bit);
- T d_lo;
+ T d_lo{};
if (LIBC_UNLIKELY(exp_lo <= 0)) {
// d_lo is denormal, but the output is normal.
diff --git a/libc/src/__support/FPUtil/generic/FMA.h b/libc/src/__support/FPUtil/generic/FMA.h
index f08f92d8febc0a..751cffd09f474c 100644
--- a/libc/src/__support/FPUtil/generic/FMA.h
+++ b/libc/src/__support/FPUtil/generic/FMA.h
@@ -18,7 +18,7 @@
#include "src/__support/FPUtil/dyadic_float.h"
#include "src/__support/FPUtil/rounding_mode.h"
#include "src/__support/big_int.h"
-#include "src/__support/macros/attributes.h" // LIBC_INLINE
+#include "src/__support/macros/attributes.h" // LIBC_INLINE
#include "src/__support/macros/config.h"
#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
@@ -29,16 +29,16 @@ namespace fputil {
namespace generic {
template <typename OutType, typename InType>
-LIBC_INLINE cpp::enable_if_t<cpp::is_floating_point_v<OutType> &&
- cpp::is_floating_point_v<InType> &&
- sizeof(OutType) <= sizeof(InType),
- OutType>
+LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_floating_point_v<OutType> &&
+ cpp::is_floating_point_v<InType> &&
+ sizeof(OutType) <= sizeof(InType),
+ OutType>
fma(InType x, InType y, InType z);
// TODO(lntue): Implement fmaf that is correctly rounded to all rounding modes.
// The implementation below only is only correct for the default rounding mode,
// round-to-nearest tie-to-even.
-template <> LIBC_INLINE float fma<float>(float x, float y, float z) {
+template <> LIBC_INLINE constexpr float fma<float>(float x, float y, float z) {
// Product is exact.
double prod = static_cast<double>(x) * static_cast<double>(y);
double z_d = static_cast<double>(z);
@@ -90,7 +90,8 @@ namespace internal {
// Extract the sticky bits and shift the `mantissa` to the right by
// `shift_length`.
template <typename T>
-LIBC_INLINE cpp::enable_if_t<is_unsigned_integral_or_big_int_v<T>, bool>
+LIBC_INLINE constexpr cpp::enable_if_t<is_unsigned_integral_or_big_int_v<T>,
+ bool>
shift_mantissa(int shift_length, T &mant) {
if (shift_length >= cpp::numeric_limits<T>::digits) {
mant = 0;
@@ -105,10 +106,10 @@ shift_mantissa(int shift_length, T &mant) {
} // namespace internal
template <typename OutType, typename InType>
-LIBC_INLINE cpp::enable_if_t<cpp::is_floating_point_v<OutType> &&
- cpp::is_floating_point_v<InType> &&
- sizeof(OutType) <= sizeof(InType),
- OutType>
+LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_floating_point_v<OutType> &&
+ cpp::is_floating_point_v<InType> &&
+ sizeof(OutType) <= sizeof(InType),
+ OutType>
fma(InType x, InType y, InType z) {
using OutFPBits = FPBits<OutType>;
using OutStorageType = typename OutFPBits::StorageType;
diff --git a/libc/src/__support/FPUtil/nearest_integer.h b/libc/src/__support/FPUtil/nearest_integer.h
index f131181fd2c61a..6fd34072d3beba 100644
--- a/libc/src/__support/FPUtil/nearest_integer.h
+++ b/libc/src/__support/FPUtil/nearest_integer.h
@@ -15,11 +15,13 @@
#include "src/__support/macros/properties/architectures.h"
#include "src/__support/macros/properties/cpu_features.h"
-#if (defined(LIBC_TARGET_ARCH_IS_X86_64) && defined(LIBC_TARGET_CPU_HAS_SSE4_2))
+#if !defined(LIBC_HAS_CONSTANT_EVALUATION) && \
+ defined(LIBC_TARGET_ARCH_IS_X86_64) && defined(LIBC_TARGET_CPU_HAS_SSE4_2)
#include "x86_64/nearest_integer.h"
-#elif (defined(LIBC_TARGET_ARCH_IS_AARCH64) && defined(__ARM_FP))
+#elif !defined(LIBC_HAS_CONSTANT_EVALUATION) && \
+ defined(LIBC_TARGET_ARCH_IS_AARCH64) && defined(__ARM_FP)
#include "aarch64/nearest_integer.h"
-#elif defined(LIBC_TARGET_ARCH_IS_GPU)
+#elif !defined(LIBC_HAS_CONSTANT_EVALUATION) && defined(LIBC_TARGET_ARCH_IS_GPU)
namespace LIBC_NAMESPACE_DECL {
namespace fputil {
diff --git a/libc/src/__support/math/acospif.h b/libc/src/__support/math/acospif.h
index f193a34f95316e..e3084af0e834d7 100644
--- a/libc/src/__support/math/acospif.h
+++ b/libc/src/__support/math/acospif.h
@@ -21,7 +21,7 @@
namespace LIBC_NAMESPACE_DECL {
namespace math {
-LIBC_INLINE float acospif(float x) {
+LIBC_INLINE LIBC_CONSTEXPR float acospif(float x) {
using FPBits = fputil::FPBits<float>;
FPBits xbits(x);
diff --git a/libc/src/__support/math/asin.h b/libc/src/__support/math/asin.h
index cf4c2736c3e209..1fe6d78b624abd 100644
--- a/libc/src/__support/math/asin.h
+++ b/libc/src/__support/math/asin.h
@@ -25,7 +25,7 @@ namespace LIBC_NAMESPACE_DECL {
namespace math {
-LIBC_INLINE double asin(double x) {
+LIBC_INLINE LIBC_CONSTEXPR double asin(double x) {
using namespace asin_internal;
using FPBits = fputil::FPBits<double>;
diff --git a/libc/src/__support/math/asinpi.h b/libc/src/__support/math/asinpi.h
index 90532fb46ab2f6..bb5cc019984159 100644
--- a/libc/src/__support/math/asinpi.h
+++ b/libc/src/__support/math/asinpi.h
@@ -25,7 +25,7 @@ namespace LIBC_NAMESPACE_DECL {
namespace math {
-LIBC_INLINE double asinpi(double x) {
+LIBC_INLINE LIBC_CONSTEXPR double asinpi(double x) {
using namespace asin_internal;
using FPBits = fputil::FPBits<double>;
diff --git a/libc/src/__support/math/asinpif.h b/libc/src/__support/math/asinpif.h
index 0a823c2bce627d..69c89efe993684 100644
--- a/libc/src/__support/math/asinpif.h
+++ b/libc/src/__support/math/asinpif.h
@@ -22,7 +22,7 @@
namespace LIBC_NAMESPACE_DECL {
namespace math {
-LIBC_INLINE float asinpif(float x) {
+LIBC_INLINE LIBC_CONSTEXPR float asinpif(float x) {
using FPBits = fputil::FPBits<float>;
FPBits xbits(x);
diff --git a/libc/src/__support/math/asinpif16.h b/libc/src/__support/math/asinpif16.h
index 7aefc35f82d01f..f6e23d2f50d0f1 100644
--- a/libc/src/__support/math/asinpif16.h
+++ b/libc/src/__support/math/asinpif16.h
@@ -27,7 +27,7 @@ namespace LIBC_NAMESPACE_DECL {
namespace math {
-LIBC_INLINE float16 asinpif16(float16 x) {
+LIBC_INLINE LIBC_CONSTEXPR float16 asinpif16(float16 x) {
using FPBits = fputil::FPBits<float16>;
FPBits xbits(x);
diff --git a/libc/src/__support/math/atan2f16.h b/libc/src/__support/math/atan2f16.h
index 0621ab4fd05477..f09204ae786c16 100644
--- a/libc/src/__support/math/atan2f16.h
+++ b/libc/src/__support/math/atan2f16.h
@@ -25,7 +25,7 @@ namespace LIBC_NAMESPACE_DECL {
namespace math {
-LIBC_INLINE float16 atan2f16(float16 y, float16 x) {
+LIBC_INLINE LIBC_CONSTEXPR float16 atan2f16(float16 y, float16 x) {
using namespace atan_internal;
using FPBits = fputil::FPBits<float16>;
diff --git a/libc/src/__support/math/atanbf16.h b/libc/src/__support/math/atanbf16.h
index 563b8325b84285..0584a1e01eebb7 100644
--- a/libc/src/__support/math/atanbf16.h
+++ b/libc/src/__support/math/atanbf16.h
@@ -22,7 +22,7 @@ namespace LIBC_NAMESPACE_DECL {
namespace math {
-LIBC_INLINE bfloat16 atanbf16(bfloat16 x) {
+LIBC_INLINE LIBC_CONSTEXPR bfloat16 atanbf16(bfloat16 x) {
// Generated by Sollya using the following command:
// > display = hexadecimal;
// > round(pi/2, SG, RN);
diff --git a/libc/src/__support/math/atanf_float.h b/libc/src/__support/math/atanf_float.h
index 56db2ad2955e61..fe61e9e3741fd9 100644
--- a/libc/src/__support/math/atanf_float.h
+++ b/libc/src/__support/math/atanf_float.h
@@ -66,7 +66,7 @@ LIBC_INLINE_VAR constexpr float ATANF_REDUCED_ARG[17] = {
// Approximating atan( u / (1 + u * k/16) )
// atan( u / (1 + u * k/16) ) / u ~ 1 - k/16 * u + (k^2/256 - 1/3) * u^2 +
// + (k/16 - (k/16)^3) * u^3 + O(u^4)
-LIBC_INLINE float atanf_eval(float u, float k_over_16) {
+LIBC_INLINE LIBC_CONSTEXPR float atanf_eval(float u, float k_over_16) {
// (k/16)^2
float c2 = k_over_16 * k_over_16;
// -(k/16)^3
@@ -85,7 +85,7 @@ LIBC_INLINE float atanf_eval(float u, float k_over_16) {
// There are several range reduction steps we can take for atan2(y, x) as
// follow:
-LIBC_INLINE float atanf(float x) {
+LIBC_INLINE LIBC_CONSTEXPR float atanf(float x) {
using namespace atanf_internal;
using FPBits = typename fputil::FPBits<float>;
using FPBits = typename fputil::FPBits<float>;
diff --git a/libc/src/__support/math/atanpif16.h b/libc/src/__support/math/atanpif16.h
index e0eaff6678fc58..e8547de8d84af2 100644
--- a/libc/src/__support/math/atanpif16.h
+++ b/libc/src/__support/math/atanpif16.h
@@ -73,7 +73,7 @@ namespace math {
// g(x)'s primary range of accuracy (i.e., if 0.5 < 1/|x| <= 1), the rule
// from Case 2 must be applied recursively to 1/|x|.
-LIBC_INLINE float16 atanpif16(float16 x) {
+LIBC_INLINE LIBC_CONSTEXPR float16 atanpif16(float16 x) {
using FPBits = fputil::FPBits<float16>;
FPBits xbits(x);
diff --git a/libc/src/__support/math/bf16add.h b/libc/src/__support/math/bf16add.h
index 7d7a24d9bc134f..2fe6e33922fa34 100644
--- a/libc/src/__support/math/bf16add.h
+++ b/libc/src/__support/math/bf16add.h
@@ -16,7 +16,7 @@
namespace LIBC_NAMESPACE_DECL {
namespace math {
-LIBC_INLINE bfloat16 bf16add(double x, double y) {
+LIBC_INLINE constexpr bfloat16 bf16add(double x, double y) {
return fputil::generic::add<bfloat16>(x, y);
}
diff --git a/libc/src/__support/math/bf16addf.h b/libc/src/__support/math/bf16addf.h
index 28a836030d1279..658686ea120f69 100644
--- a/libc/src/__support/math/bf16addf.h
+++ b/libc/src/__support/math/bf16addf.h
@@ -16,7 +16,7 @@
namespace LIBC_NAMESPACE_DECL {
namespace math {
-LIBC_INLINE bfloat16 bf16addf(float x, float y) {
+LIBC_INLINE constexpr bfloat16 bf16addf(float x, float y) {
return fputil::generic::add<bfloat16>(x, y);
}
diff --git a/libc/src/__support/math/bf16addf128.h b/libc/src/__support/math/bf16addf128.h
index 33a891992e3622..47c5736ffc7838 100644
--- a/libc/src/__support/math/bf16addf128.h
+++ b/libc/src/__support/math/bf16addf128.h
@@ -20,7 +20,7 @@
namespace LIBC_NAMESPACE_DECL {
namespace math {
-LIBC_INLINE bfloat16 bf16addf128(float128 x, float128 y) {
+LIBC_INLINE constexpr bfloat16 bf16addf128(float128 x, float128 y) {
return fputil::generic::add<bfloat16>(x, y);
}
diff --git a/libc/src/__support/math/bf16addl.h b/libc/src/__support/math/bf16addl.h
index f9e27cb48ea092..940c74aef28670 100644
--- a/libc/src/__support/math/bf16addl.h
+++ b/libc/src/__support/math/bf16addl.h
@@ -16,7 +16,7 @@
namespace LIBC_NAMESPACE_DECL {
namespace math {
-LIBC_INLINE bfloat16 bf16addl(long double x, long double y) {
+LIBC_INLINE constexpr bfloat16 bf16addl(long double x, long double y) {
return fputil::generic::add<bfloat16>(x, y);
}
diff --git a/libc/src/__support/math/bf16div.h b/libc/src/__support/math/bf16div.h
index 060105b88cd11e..e8adc3c379a25e 100644
--- a/libc/src/__support/math/bf16div.h
+++ b/libc/src/__support/math/bf16div.h
@@ -16,7 +16,7 @@
namespace LIBC_NAMESPACE_DECL {
namespace math {
-LIBC_INLINE bfloat16 bf16div(double x, double y) {
+LIBC_INLINE constexpr bfloat16 bf16div(double x, double y) {
return fputil::generic::div<bfloat16>(x, y);
}
diff --git a/libc/src/__support/math/bf16divf.h b/libc/src/__support/math/bf16divf.h
index 0e201f8a124ed0..ad5cb57aac8285 100644
--- a/libc/src/__support/math/bf16divf.h
+++ b/libc/src/__support/math/bf16divf.h
@@ -17,7 +17,7 @@ namespace LIBC_NAMESPACE_DECL {
namespace math {
-LIBC_INLINE bfloat16 bf16divf(float x, float y) {
+LIBC_INLINE constexpr bfloat16 bf16divf(float x, float y) {
return fputil::generic::div<bfloat16>(x, y);
}
diff --git a/libc/src/__support/math/bf16divf128.h b/libc/src/__support/math/bf16divf128.h
index 63d9cc28d1a334..c3312d6c70fa3f 100644
--- a/libc/src/__support/math/bf16divf128.h
+++ b/libc/src/__support/math/bf16divf128.h
@@ -21,7 +21,7 @@
namespace LIBC_NAMESPACE_DECL {
namespace math {
-LIBC_INLINE bfloat16 bf16divf128(float128 x, float128 y) {
+LIBC_INLINE constexpr bfloat16 bf16divf128(float128 x, float128 y) {
return fputil::generic::div<bfloat16>(x, y);
}
diff --git a/libc/src/__support/math/bf16divl.h b/libc/src/__support/math/bf16divl.h
index ec5a9244b98d6f..b6283c386be548 100644
--- a/libc/src/__support/math/bf16divl.h
+++ b/libc/src/__support/math/bf16divl.h
@@ -16,7 +16,7 @@
namespace LIBC_NAMESPACE_DECL {
namespace math {
-LIBC_INLINE bfloat16 bf16divl(long double x, long double y) {
+LIBC_INLINE constexpr bfloat16 bf16divl(long double x, long double y) {
return fputil::generic::div<bfloat16>(x, y);
}
diff --git a/libc/src/__support/math/bf16fma.h b/libc/src/__support/math/bf16fma.h
index da88d5753f6bb7..83fea3cd90d796 100644
--- a/libc/src/__support/math/bf16fma.h
+++ b/libc/src/__support/math/bf16fma.h
@@ -16,7 +16,7 @@
namespace LIBC_NAMESPACE_DECL {
namespace math {
-LIBC_INLINE bfloa...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/234340
More information about the libc-commits
mailing list