[libc-commits] [libc] [llvm] [libc][math] Refactor ffmal to Header Only. (PR #179069)
via libc-commits
libc-commits at lists.llvm.org
Sat Jan 31 12:58:15 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Zorojuro (Sukumarsawant)
<details>
<summary>Changes</summary>
closes #<!-- -->175326
Part of #<!-- -->147386
@<!-- -->bassiounix
---
Full diff: https://github.com/llvm/llvm-project/pull/179069.diff
9 Files Affected:
- (modified) libc/shared/math.h (+1)
- (added) libc/shared/math/ffmal.h (+25)
- (modified) libc/src/__support/math/CMakeLists.txt (+10)
- (added) libc/src/__support/math/ffmal.h (+28)
- (modified) libc/src/math/generic/CMakeLists.txt (+1-1)
- (modified) libc/src/math/generic/ffmal.cpp (+2-4)
- (modified) libc/test/shared/CMakeLists.txt (+1)
- (modified) libc/test/shared/shared_math_test.cpp (+1)
- (modified) utils/bazel/llvm-project-overlay/libc/BUILD.bazel (+11-1)
``````````diff
diff --git a/libc/shared/math.h b/libc/shared/math.h
index b58d29d1ee480..460a56ef510a7 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -63,6 +63,7 @@
#include "math/f16fmal.h"
#include "math/f16sqrt.h"
#include "math/f16sqrtl.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..51e20cbed70f5
--- /dev/null
+++ b/libc/shared/math/ffmal.h
@@ -0,0 +1,25 @@
+//===-- 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 58e4040911f8e..a157529229650 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -593,6 +593,16 @@ add_header_library(
libc.src.__support.math.exp10_float16_constants
)
+add_header_library(
+ ffmal
+ HDRS
+ ffmal.h
+ DEPENDS
+ libc.src.__support.common
+ libc.src.__support.FPUtil.fma
+ libc.src.__support.macros.config
+)
+
add_header_library(
f16sqrt
HDRS
diff --git a/libc/src/__support/math/ffmal.h b/libc/src/__support/math/ffmal.h
new file mode 100644
index 0000000000000..d99e98afbda84
--- /dev/null
+++ b/libc/src/__support/math/ffmal.h
@@ -0,0 +1,28 @@
+//===-- Implementation header for ffmal -------------------------*- 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_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 {
+
+LIBC_INLINE static 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 1b18388ed60f8..c69bc674f41d3 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -3309,7 +3309,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..c5d0d421c42a4 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 07ccd0ca1bc4b..1ad3ab930f759 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -59,6 +59,7 @@ add_fp_unittest(
libc.src.__support.math.f16fmal
libc.src.__support.math.f16sqrt
libc.src.__support.math.f16sqrtl
+ libc.src.__support.math.ffmal
libc.src.__support.math.frexpf
libc.src.__support.math.frexpf128
libc.src.__support.math.frexpf16
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index ec70025f0f4ea..97b07503cd64d 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -84,6 +84,7 @@ TEST(LlvmLibcSharedMathTest, AllFloat) {
EXPECT_FP_EQ(0x1p+0f, LIBC_NAMESPACE::shared::expf(0.0f));
EXPECT_FP_EQ(0x1p+0f, LIBC_NAMESPACE::shared::exp2f(0.0f));
EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::expm1f(0.0f));
+ EXPECT_FP_EQ(10.0f, LIBC_NAMESPACE::shared::ffmal(2.0L, 3.0, 4.0L));
EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::hypotf(0.0f, 0.0f));
EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::logf(1.0f));
EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::sinhf(0.0f));
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 83b752ce1214b..e8e72ffa81a10 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -2919,6 +2919,16 @@ libc_support_library(
],
)
+libc_support_library(
+ name = "__support_math_ffmal",
+ hdrs = ["src/__support/math/ffmal.h"],
+ deps = [
+ ":__support_common",
+ ":__support_fputil_fma",
+ ":__support_macros_config",
+ ],
+)
+
libc_support_library(
name = "__support_math_frexpf128",
hdrs = ["src/__support/math/frexpf128.h"],
@@ -4543,7 +4553,7 @@ libc_math_function(
libc_math_function(
name = "ffmal",
additional_deps = [
- ":__support_fputil_fma",
+ ":__support_math_ffmal",
],
)
``````````
</details>
https://github.com/llvm/llvm-project/pull/179069
More information about the libc-commits
mailing list