[libc-commits] [libc] [libc][FPUtil] Make hardware helpers usable in constant expressions (PR #242283)
via libc-commits
libc-commits at lists.llvm.org
Sun Nov 15 12:27:16 PST 2026
================
@@ -63,40 +63,51 @@ multiply_add(T x, T y, T z) {
// use the generic fma implementation from generic/FMA.h. But currently that
// implementation will use dyadic_float.h , which in turns including this
// multiply_add.h . We will need to break the dependency to enable constexpr
-// for other math functions.
+// for other math functions. Until then, constant evaluation falls back to the
+// non-fused `x * y + z`, exactly like the generic implementation above.
namespace LIBC_NAMESPACE_DECL {
namespace fputil {
#ifdef LIBC_TARGET_CPU_HAS_FMA_FLOAT
-LIBC_INLINE float multiply_add(float x, float y, float z) {
+LIBC_INLINE LIBC_CONSTEXPR_DEFAULT float multiply_add(float x, float y,
+ float z) {
+ if (cpp::is_constant_evaluated()) {
+ return x * y + z;
----------------
linisha15 wrote:
on FMA targets the constexpr branch does an unfused x * y + z, so compile-time results can differ from runtime. I tried calling generic::fma there, but it hits the include cycle multiply_add.h → FMA.h → generic/FMA.h → dyadic_float.h → multiply_add.h, and forward-declaring it breaks TUs that include dyadic_float.h without FMA.h
https://github.com/llvm/llvm-project/pull/242283
More information about the libc-commits
mailing list