[libc-commits] [libc] [llvm] [libc][math] Refactor ffmal to Header Only. (PR #179069)
via libc-commits
libc-commits at lists.llvm.org
Sat Feb 7 05:55:36 PST 2026
https://github.com/Sukumarsawant updated https://github.com/llvm/llvm-project/pull/179069
>From 43df21697c70a6d313b975b9a05b52f97ce81e37 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Sun, 1 Feb 2026 01:36:05 +0530
Subject: [PATCH 1/5] intial commit without build/format/test
---
libc/shared/math.h | 1 +
libc/shared/math/ffmal.h | 25 ++++++++++++
libc/src/__support/math/CMakeLists.txt | 10 +++++
libc/src/__support/math/ffmal.h | 28 +++++++++++++
libc/src/math/generic/CMakeLists.txt | 2 +-
libc/src/math/generic/ffmal.cpp | 40 +++++++++----------
libc/test/shared/CMakeLists.txt | 1 +
libc/test/shared/shared_math_test.cpp | 1 +
.../llvm-project-overlay/libc/BUILD.bazel | 12 +++++-
9 files changed, 97 insertions(+), 23 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 110b4bfe81073..abd40c43f18f3 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -65,6 +65,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 3d43eccfdbe2c..a085b8159c25d 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..5bf3c83715e6c
--- /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 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 be3f724e10a8b..4d1e51d2d7322 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..6ad1f7da563dc 100644
--- a/libc/src/math/generic/ffmal.cpp
+++ b/libc/src/math/generic/ffmal.cpp
@@ -1,21 +1,19 @@
-//===-- Implementation of ffmal function ----------------------------------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#include "src/math/ffmal.h"
-#include "src/__support/FPUtil/FMA.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.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);
-}
-
-} // namespace LIBC_NAMESPACE_DECL
+//===-- Implementation of ffmal function ----------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/math/ffmal.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 math::ffmal(x, y, z);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 7143ce6e84458..b23ad2e97b9ba 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -61,6 +61,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 73d6d836227b3..0c127ffdc3890 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -94,6 +94,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 b91a13b29d3c6..b10cc828e4f78 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -2944,6 +2944,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"],
@@ -4568,7 +4578,7 @@ libc_math_function(
libc_math_function(
name = "ffmal",
additional_deps = [
- ":__support_fputil_fma",
+ ":__support_math_ffmal",
],
)
>From 701eff7b64790237ed5ce3ecf64886b2e1bfae2d Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Sun, 1 Feb 2026 01:42:00 +0530
Subject: [PATCH 2/5] fixed 1 crlf and 1 overwritten
---
libc/src/math/generic/ffmal.cpp | 37 ++++++++++++++++-----------------
1 file changed, 18 insertions(+), 19 deletions(-)
diff --git a/libc/src/math/generic/ffmal.cpp b/libc/src/math/generic/ffmal.cpp
index 6ad1f7da563dc..f14cbdca7aee0 100644
--- a/libc/src/math/generic/ffmal.cpp
+++ b/libc/src/math/generic/ffmal.cpp
@@ -1,19 +1,18 @@
-//===-- Implementation of ffmal function ----------------------------------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#include "src/math/ffmal.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 math::ffmal(x, y, z);
-}
-
-} // namespace LIBC_NAMESPACE_DECL
+//===-- Implementation of ffmal function ----------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/math/ffmal.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 math::ffmal(x, y, z);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
>From 6b1aa1fa1a5f1273dc118c7e86d03770b2acda52 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Fri, 6 Feb 2026 08:43:54 +0530
Subject: [PATCH 3/5] reflecting 823e3e0 + formatted + testing )
---
libc/src/math/generic/ffmal.cpp | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/libc/src/math/generic/ffmal.cpp b/libc/src/math/generic/ffmal.cpp
index f14cbdca7aee0..c5d0d421c42a4 100644
--- a/libc/src/math/generic/ffmal.cpp
+++ b/libc/src/math/generic/ffmal.cpp
@@ -11,7 +11,8 @@
namespace LIBC_NAMESPACE_DECL {
-LLVM_LIBC_FUNCTION(float, ffmal,(long double x, long double y, long double z)) {
+LLVM_LIBC_FUNCTION(float, ffmal,
+ (long double x, long double y, long double z)) {
return math::ffmal(x, y, z);
}
>From d8f783cc04a2d2b6327719cc863172ee474c6919 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Fri, 6 Feb 2026 08:51:57 +0530
Subject: [PATCH 4/5] clang-format
---
libc/src/__support/math/ffmal.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/src/__support/math/ffmal.h b/libc/src/__support/math/ffmal.h
index 5bf3c83715e6c..b03c45ea25cf2 100644
--- a/libc/src/__support/math/ffmal.h
+++ b/libc/src/__support/math/ffmal.h
@@ -17,7 +17,7 @@ namespace LIBC_NAMESPACE_DECL {
namespace math {
-LIBC_INLINE float ffmal(long double x, long double y,long double z) {
+LIBC_INLINE float ffmal(long double x, long double y, long double z) {
return fputil::fma<float>(x, y, z);
}
>From dca0739e8d18f9d1717fb097b6c5e2faeca13efe Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Sat, 7 Feb 2026 19:22:45 +0530
Subject: [PATCH 5/5] moved test to allLongDouble
---
libc/test/shared/shared_math_test.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 0c127ffdc3890..a36a09d10c223 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -94,7 +94,6 @@ 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));
@@ -150,6 +149,7 @@ TEST(LlvmLibcSharedMathTest, AllLongDouble) {
LIBC_NAMESPACE::shared::dfmal(0x0.p+0L, 0x0.p+0L, 0x0.p+0L));
EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::fsqrtl(0.0L));
EXPECT_EQ(0, LIBC_NAMESPACE::shared::ilogbl(0x1.p+0L));
+ EXPECT_FP_EQ(10.0f, LIBC_NAMESPACE::shared::ffmal(2.0L, 3.0, 4.0L));
}
#ifdef LIBC_TYPES_HAS_FLOAT128
More information about the libc-commits
mailing list