[libc-commits] [libc] [libc][math] Qualify all functions to be constexpr (PR #195623)
via libc-commits
libc-commits at lists.llvm.org
Mon May 4 07:43:47 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Muhammad Bassiouni (bassiounix)
<details>
<summary>Changes</summary>
---
Patch is 137.25 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/195623.diff
144 Files Affected:
- (modified) libc/src/__support/FPUtil/FEnvImpl.h (+9-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/generic/sqrt_80_bit_long_double.h (+2-2)
- (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/bf16sub.h (+1-1)
- (modified) libc/src/__support/math/bf16subf.h (+1-1)
- (modified) libc/src/__support/math/bf16subf128.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/hypot.h (+3-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/inv_trigf_utils.h (+1-1)
- (modified) libc/src/__support/math/log10.h (+2-2)
- (modified) libc/src/__support/math/log10f.h (+1-1)
- (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/powf.h (+4-4)
- (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/setpayloadsig.h (+1-1)
- (modified) libc/src/__support/math/setpayloadsigbf16.h (+1-1)
- (modified) libc/src/__support/math/setpayloadsigf.h (+1-1)
- (modified) libc/src/__support/math/setpayloadsigf128.h (+1-1)
- (modified) libc/src/__support/math/setpayloadsigf16.h (+1-1)
- (modified) libc/src/__support/math/setpayloadsigl.h (+1-1)
- (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/sinf.h (+3-3)
- (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-7)
- (modified) libc/src/__support/math/tanf.h (+2-2)
- (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/CMakeLists.txt (+211-7)
- (modified) libc/test/shared/shared_math_constexpr_test.cpp (+460-29)
- (modified) libc/test/shared/shared_math_test.cpp (+2-6)
``````````diff
diff --git a/libc/src/__support/FPUtil/FEnvImpl.h b/libc/src/__support/FPUtil/FEnvImpl.h
index a21f511bd72b8..e999933e0da8c 100644
--- a/libc/src/__support/FPUtil/FEnvImpl.h
+++ b/libc/src/__support/FPUtil/FEnvImpl.h
@@ -25,7 +25,7 @@
#undef LIBC_MATH_USE_SYSTEM_FENV
#endif // LIBC_FULL_BUILD
-#if defined(LIBC_MATH_USE_SYSTEM_FENV)
+#if defined(LIBC_MATH_USE_SYSTEM_FENV) && !defined(LIBC_HAS_CONSTANT_EVALUATION)
// Simply call the system libc fenv.h functions, only for those that are used in
// math function implementations.
@@ -65,7 +65,8 @@ LIBC_INLINE int set_round(int rounding_mode) {
#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_HAS_CONSTANT_EVALUATION)
#if defined(__APPLE__)
#include "aarch64/fenv_darwin_impl.h"
#else
@@ -76,12 +77,14 @@ LIBC_INLINE int set_round(int rounding_mode) {
// 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_HAS_CONSTANT_EVALUATION)
#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_HAS_CONSTANT_EVALUATION)
#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_HAS_CONSTANT_EVALUATION)
#include "riscv/FEnvImpl.h"
#else
@@ -104,7 +107,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 2cafb4c0974e3..e56de4bb64b9f 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 292140065c754..5e4c84914073e 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 16dc094deda47..bf66a037bc4bc 100644
--- a/libc/src/__support/FPUtil/ManipulationFunctions.h
+++ b/libc/src/__support/FPUtil/ManipulationFunctions.h
@@ -210,7 +210,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 31049ced5a934..31147759602ba 100644
--- a/libc/src/__support/FPUtil/double_double.h
+++ b/libc/src/__support/FPUtil/double_double.h
@@ -146,15 +146,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);
@@ -164,9 +165,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 8ce041247716b..975bb9821ebdf 100644
--- a/libc/src/__support/FPUtil/dyadic_float.h
+++ b/libc/src/__support/FPUtil/dyadic_float.h
@@ -343,7 +343,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 7b46978d0c8af..8b51949afc6d1 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/generic/sqrt_80_bit_long_double.h b/libc/src/__support/FPUtil/generic/sqrt_80_bit_long_double.h
index 0ba836d17a085..c179353bd5748 100644
--- a/libc/src/__support/FPUtil/generic/sqrt_80_bit_long_double.h
+++ b/libc/src/__support/FPUtil/generic/sqrt_80_bit_long_double.h
@@ -32,12 +32,12 @@ LIBC_INLINE void normalize(int &exponent,
// if constexpr statement in sqrt.h still requires x86::sqrt to be declared
// even when it's not used.
-LIBC_INLINE long double sqrt(long double x);
+LIBC_INLINE constexpr long double sqrt(long double x);
// Correctly rounded SQRT for all rounding modes.
// Shift-and-add algorithm.
#if defined(LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80)
-LIBC_INLINE long double sqrt(long double x) {
+LIBC_INLINE constexpr long double sqrt(long double x) {
using LDBits = FPBits<long double>;
using StorageType = typename LDBits::StorageType;
constexpr StorageType ONE = StorageType(1) << int(LDBits::FRACTION_LEN);
diff --git a/libc/src/__support/FPUtil/nearest_integer.h b/libc/src/__support/FPUtil/nearest_integer.h
index fabd309bd3520..d5b47ea9526eb 100644
--- a/libc/src/__support/FPUtil/nearest_integer.h
+++ b/libc/src/__support/FPUtil/nearest_integer.h
@@ -14,11 +14,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 acf2b9748975b..5a0bf6953e8aa 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 98e77d0b97454..f3934cc87aa46 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 a088ae322ad79..5df60bc4d4dcc 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 79d3ebbe63b5b..409f0700619f6 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 7aefc35f82d01..f6e23d2f50d0f 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 297167a429d9f..ccdf7ddf7ae6c 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 inv_trigf_utils_internal;
using FPBits = fputil::FPBits<float16>;
diff --git a/libc/src/__support/math/atanbf16.h b/libc/src/__support/math/atanbf16.h
index 563b8325b8428..0584a1e01eebb 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 56db2ad2955e6..fe61e9e3741fd 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 e0eaff6678fc5..e8547de8d84af 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 7d7a24d9bc134..2fe6e33922fa3 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 28a836030d127..658686ea120f6 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 2bd1d10e38d7d..5af5658b371a3 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 f9e27cb48ea09..940c74aef2867 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 060105b88cd11..e8adc3c379a25 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 0e201f8a124ed..ad5cb57aac828 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 8ed5335099e71..ad2b0f2fb57df 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 bf16d...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/195623
More information about the libc-commits
mailing list