[libc-commits] [libc] [libc][FPUtil] Make hardware helpers usable in constant expressions (PR #242283)

Muhammad Bassiouni via libc-commits libc-commits at lists.llvm.org
Sat Nov 14 10:22:51 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;
----------------
bassiounix wrote:

Don't we have FMA class for compile-time fma ops?

https://github.com/llvm/llvm-project/pull/242283


More information about the libc-commits mailing list