[libc-commits] [libc] [llvm] [libc][math] Refactor ffmal to Header Only. (PR #176989)
Harrishan Raveendran via libc-commits
libc-commits at lists.llvm.org
Sun Jan 25 07:54:10 PST 2026
https://github.com/Harrish92 updated https://github.com/llvm/llvm-project/pull/176989
>From 66eb033cfb47c225f60418d149997c934afee6c9 Mon Sep 17 00:00:00 2001
From: Harrish92 <harrishan.raveendran at epfl.ch>
Date: Sun, 25 Jan 2026 16:53:12 +0100
Subject: [PATCH] [libc][math] Refactor ffmal to Header Only.
---
libc/shared/math.h | 1 +
libc/shared/math/ffmal.h | 23 ++++++++++++++++
libc/src/__support/math/CMakeLists.txt | 10 +++++++
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 +
libc/test/shared/shared_math_test.cpp | 2 ++
.../llvm-project-overlay/libc/BUILD.bazel | 11 +++++++-
9 files changed, 77 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 5126e46c9772e..470a2a799066b 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -61,6 +61,7 @@
#include "math/expm1f16.h"
#include "math/f16fma.h"
#include "math/f16fmal.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..6493fbf727782
--- /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 d18ebc03ba7b8..05592314b2a03 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -658,6 +658,16 @@ add_header_library(
libc.include.llvm-libc-macros.float16_macros
)
+add_header_library(
+ ffmal
+ HDRS
+ ffmal.h
+ DEPENDS
+ libc.src.__support.FPUtil.fma
+ libc.src.__support.common
+ libc.src.__support.macros.config
+)
+
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..8ab13f07bc89c
--- /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/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 3addfab6c6603..583ba90fb4800 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -3362,7 +3362,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 dabf5f6b168cc..8e53afb682559 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -57,6 +57,7 @@ add_fp_unittest(
libc.src.__support.math.expf16
libc.src.__support.math.f16fma
libc.src.__support.math.f16fmal
+ 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 cd389c41cb7b2..7b73949a1b591 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -116,6 +116,8 @@ TEST(LlvmLibcSharedMathTest, AllDouble) {
TEST(LlvmLibcSharedMathTest, AllLongDouble) {
EXPECT_FP_EQ(0x0p+0L,
LIBC_NAMESPACE::shared::dfmal(0x0.p+0L, 0x0.p+0L, 0x0.p+0L));
+ EXPECT_FP_EQ(0x0p+0L,
+ LIBC_NAMESPACE::shared::ffmal(0x0.p+0L, 0x0.p+0L, 0x0.p+0L));
EXPECT_EQ(0, LIBC_NAMESPACE::shared::ilogbl(0x1.p+0L));
}
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 346864d2276c0..6ac08f929c4cb 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -2885,6 +2885,15 @@ libc_support_library(
":__support_fputil_fma",
":__support_macros_config",
":llvm_libc_macros_float16_macros",
+)
+
+libc_support_library(
+ name = "__support_math_ffmal",
+ hdrs = ["src/__support/math/ffmal.h"],
+ deps = [
+ ":__support_common",
+ ":__support_fputil_fma",
+ ":__support_macros_config",
],
)
@@ -4302,7 +4311,7 @@ libc_math_function(
libc_math_function(
name = "ffmal",
additional_deps = [
- ":__support_fputil_fma",
+ ":__support_math_ffmal",
],
)
More information about the libc-commits
mailing list