[libc-commits] [libc] [llvm] [libc][math] Refactor ffmal to Header Only. (PR #176989)
Harrishan Raveendran via libc-commits
libc-commits at lists.llvm.org
Tue Jan 20 10:21:25 PST 2026
https://github.com/Harrish92 created https://github.com/llvm/llvm-project/pull/176989
Closes #175326
>From 35a918df3e39e1a4ecfdeb3d7847844bd692b3a7 Mon Sep 17 00:00:00 2001
From: Harrish92 <harrishan.raveendran at epfl.ch>
Date: Tue, 20 Jan 2026 19:00:31 +0100
Subject: [PATCH 1/2] [libc][math] Refactor `ffmal` to Header Only.
---
libc/shared/math.h | 1 +
libc/shared/math/ffmal.h | 23 ++++++++++++++++
libc/src/__support/math/CMakeLists.txt | 8 ++++++
libc/src/__support/math/ffmal.h | 27 +++++++++++++++++++
libc/src/math/generic/CMakeLists.txt | 2 +-
libc/src/math/generic/ffmal.cpp | 6 ++---
libc/test/shared/CMakeLists.txt | 1 +
.../llvm-project-overlay/libc/BUILD.bazel | 10 ++++++-
8 files changed, 72 insertions(+), 6 deletions(-)
create mode 100644 libc/shared/math/ffmal.h
create mode 100644 libc/src/__support/math/ffmal.h
diff --git a/libc/shared/math.h b/libc/shared/math.h
index d58238703701d..d13360daf6720 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -59,6 +59,7 @@
#include "math/expm1f.h"
#include "math/expm1f16.h"
#include "math/f16fma.h"
+#include "math/ffmal.h"
#include "math/frexpf.h"
#include "math/frexpf128.h"
#include "math/frexpf16.h"
diff --git a/libc/shared/math/ffmal.h b/libc/shared/math/ffmal.h
new file mode 100644
index 0000000000000..5e557cfe3895b
--- /dev/null
+++ b/libc/shared/math/ffmal.h
@@ -0,0 +1,23 @@
+//===-- Shared ffmal function -----------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_FFMAL_H
+#define LLVM_LIBC_SHARED_MATH_FFMAL_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/ffmal.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+ using math::ffmal;
+
+} //namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif //LLVM_LIBC_SHARED_MATH_FFMAL_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index bf1c4463b8066..985ed97a5cf50 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -648,6 +648,14 @@ add_header_library(
libc.include.llvm-libc-macros.float16_macros
)
+add_header_library(
+ fmmal
+ HDRS
+ ffmal.h
+ DEPENDS
+ libc.src.__support.FPUtil.fma
+)
+
add_header_library(
ilogbf16
HDRS
diff --git a/libc/src/__support/math/ffmal.h b/libc/src/__support/math/ffmal.h
new file mode 100644
index 0000000000000..10c64c1178a5d
--- /dev/null
+++ b/libc/src/__support/math/ffmal.h
@@ -0,0 +1,27 @@
+//===-- Implementation header for ffmal ------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_FFMAL_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_FFMAL_H
+
+#include "src/__support/FPUtil/FMA.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+static constexpr float ffmal(long double x, long double y, long double z) {
+ return fputil::fma<float>(x, y, z);
+}
+
+} // namespace math
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FFMAL_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index b578d1805f2a8..23f17469640c7 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -3406,7 +3406,7 @@ add_entrypoint_object(
HDRS
../ffmal.h
DEPENDS
- libc.src.__support.FPUtil.fma
+ libc.src.__support.math.ffmal
)
add_entrypoint_object(
diff --git a/libc/src/math/generic/ffmal.cpp b/libc/src/math/generic/ffmal.cpp
index d5cd4f763cbe5..fe4b75423a2e0 100644
--- a/libc/src/math/generic/ffmal.cpp
+++ b/libc/src/math/generic/ffmal.cpp
@@ -7,15 +7,13 @@
//===----------------------------------------------------------------------===//
#include "src/math/ffmal.h"
-#include "src/__support/FPUtil/FMA.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/ffmal.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(float, ffmal,
(long double x, long double y, long double z)) {
- return fputil::fma<float>(x, y, z);
+ return math::ffmal(x, y, z);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index cfc2eda1aaec9..5c734973701dd 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -55,6 +55,7 @@ add_fp_unittest(
libc.src.__support.math.expf
libc.src.__support.math.expf16
libc.src.__support.math.f16fma
+ libc.src.__support.math.ffmal
libc.src.__support.math.frexpf
libc.src.__support.math.frexpf128
libc.src.__support.math.frexpf16
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 90b1da0e3376e..2102243044b6c 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -2814,6 +2814,14 @@ libc_support_library(
],
)
+libc_support_library(
+ name = "__support_math_ffmal",
+ hdrs = ["src/__support/math/ffmal.h"],
+ deps = [
+ ":__support_fputil_fma",
+ ],
+)
+
libc_support_library(
name = "__support_math_frexpf128",
hdrs = ["src/__support/math/frexpf128.h"],
@@ -4138,7 +4146,7 @@ libc_math_function(
libc_math_function(
name = "ffmal",
additional_deps = [
- ":__support_fputil_fma",
+ ":__support_math_ffmal",
],
)
>From 2c95068ed5f8a4ebe8c9a332c5c81b41d2d93863 Mon Sep 17 00:00:00 2001
From: Harrish92 <harrishan.raveendran at epfl.ch>
Date: Tue, 20 Jan 2026 19:14:54 +0100
Subject: [PATCH 2/2] style: run clang-format
---
libc/shared/math/ffmal.h | 6 +++---
libc/src/__support/math/ffmal.h | 7 ++++---
libc/src/math/generic/ffmal.cpp | 2 +-
3 files changed, 8 insertions(+), 7 deletions(-)
diff --git a/libc/shared/math/ffmal.h b/libc/shared/math/ffmal.h
index 5e557cfe3895b..6493fbf727782 100644
--- a/libc/shared/math/ffmal.h
+++ b/libc/shared/math/ffmal.h
@@ -15,9 +15,9 @@
namespace LIBC_NAMESPACE_DECL {
namespace shared {
- using math::ffmal;
+using math::ffmal;
-} //namespace shared
+} // namespace shared
} // namespace LIBC_NAMESPACE_DECL
-#endif //LLVM_LIBC_SHARED_MATH_FFMAL_H
+#endif // LLVM_LIBC_SHARED_MATH_FFMAL_H
diff --git a/libc/src/__support/math/ffmal.h b/libc/src/__support/math/ffmal.h
index 10c64c1178a5d..872ce70ed78b2 100644
--- a/libc/src/__support/math/ffmal.h
+++ b/libc/src/__support/math/ffmal.h
@@ -1,4 +1,5 @@
-//===-- Implementation header for ffmal ------------------------------------===//
+//===-- Implementation header for ffmal
+//------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -17,11 +18,11 @@ namespace LIBC_NAMESPACE_DECL {
namespace math {
static constexpr float ffmal(long double x, long double y, long double z) {
- return fputil::fma<float>(x, y, z);
+ return fputil::fma<float>(x, y, z);
}
} // namespace math
} // namespace LIBC_NAMESPACE_DECL
-#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FFMAL_H
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FFMAL_H
diff --git a/libc/src/math/generic/ffmal.cpp b/libc/src/math/generic/ffmal.cpp
index fe4b75423a2e0..c5d0d421c42a4 100644
--- a/libc/src/math/generic/ffmal.cpp
+++ b/libc/src/math/generic/ffmal.cpp
@@ -13,7 +13,7 @@ namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(float, ffmal,
(long double x, long double y, long double z)) {
- return math::ffmal(x, y, z);
+ return math::ffmal(x, y, z);
}
} // namespace LIBC_NAMESPACE_DECL
More information about the libc-commits
mailing list