[libc-commits] [libc] [llvm] [libc][math] Refactor ffmaf128 into a header only. (PR #184751)
via libc-commits
libc-commits at lists.llvm.org
Wed Mar 4 23:33:20 PST 2026
https://github.com/Sukumarsawant created https://github.com/llvm/llvm-project/pull/184751
closes #175325
part of #147386
>From 05c393915783b838d399ae2bc8324dcc46bc1b47 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Thu, 5 Mar 2026 12:49:23 +0530
Subject: [PATCH 1/2] refactor ffmaf128
---
libc/shared/math.h | 1 +
libc/shared/math/ffmaf128.h | 29 +++++++++++++++
libc/src/__support/math/CMakeLists.txt | 11 ++++++
libc/src/__support/math/ffmaf128.h | 35 +++++++++++++++++++
libc/src/math/generic/CMakeLists.txt | 3 +-
libc/src/math/generic/ffmaf128.cpp | 6 ++--
libc/test/shared/CMakeLists.txt | 1 +
libc/test/shared/shared_math_test.cpp | 2 ++
.../llvm-project-overlay/libc/BUILD.bazel | 13 ++++++-
9 files changed, 94 insertions(+), 7 deletions(-)
create mode 100644 libc/shared/math/ffmaf128.h
create mode 100644 libc/src/__support/math/ffmaf128.h
diff --git a/libc/shared/math.h b/libc/shared/math.h
index a7d735ffa1746..ede0ebd5371ac 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -124,6 +124,7 @@
#include "math/fdimf16.h"
#include "math/fdiml.h"
#include "math/ffma.h"
+#include "math/ffmaf128.h"
#include "math/ffmal.h"
#include "math/floor.h"
#include "math/floorbf16.h"
diff --git a/libc/shared/math/ffmaf128.h b/libc/shared/math/ffmaf128.h
new file mode 100644
index 0000000000000..5c76ed36a28e4
--- /dev/null
+++ b/libc/shared/math/ffmaf128.h
@@ -0,0 +1,29 @@
+//===-- Shared ffmaf128 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_FFMAF128_H
+#define LLVM_LIBC_SHARED_MATH_FFMAF128_H
+
+#include "include/llvm-libc-types/float128.h"
+#include "shared/libc_common.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "src/__support/math/ffmaf128.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::ffmaf128;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_MATH_FFMAF128_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 79278b6e77a3b..0df8262cfb5f2 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -1163,6 +1163,17 @@ add_header_library(
libc.src.__support.macros.config
)
+add_header_library(
+ ffmaf128
+ HDRS
+ ffmaf128.h
+ DEPENDS
+ libc.src.__support.common
+ libc.src.__support.FPUtil.fma
+ libc.src.__support.macros.config
+ libc.include.llvm-libc-types.float128
+)
+
add_header_library(
ffmal
HDRS
diff --git a/libc/src/__support/math/ffmaf128.h b/libc/src/__support/math/ffmaf128.h
new file mode 100644
index 0000000000000..8b95e22bad0c1
--- /dev/null
+++ b/libc/src/__support/math/ffmaf128.h
@@ -0,0 +1,35 @@
+//===-- Implementation header for ffmaf128 ------------ ----------*- 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_FFMAF128_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_FFMAF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#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 ffmaf128(float128 x, float128 y, float128 z) {
+ return fputil::fma<float>(x, y, z);
+}
+
+} // namespace math
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FFMAF128_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index f8ec25be61d12..418cf85b84a20 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -3155,8 +3155,7 @@ add_entrypoint_object(
HDRS
../ffmaf128.h
DEPENDS
- libc.src.__support.macros.properties.types
- libc.src.__support.FPUtil.fma
+ libc.src.__support.math.ffmaf128
)
add_entrypoint_object(
diff --git a/libc/src/math/generic/ffmaf128.cpp b/libc/src/math/generic/ffmaf128.cpp
index 55da93020faf3..15c0308b0b9c4 100644
--- a/libc/src/math/generic/ffmaf128.cpp
+++ b/libc/src/math/generic/ffmaf128.cpp
@@ -7,14 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/ffmaf128.h"
-#include "src/__support/FPUtil/FMA.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/ffmaf128.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(float, ffmaf128, (float128 x, float128 y, float128 z)) {
- return fputil::fma<float>(x, y, z);
+ return math::ffmaf128(x, y, z);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index a04a15cdabcb7..c90e5687d8c33 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -121,6 +121,7 @@ add_fp_unittest(
libc.src.__support.math.fdimf16
libc.src.__support.math.fdiml
libc.src.__support.math.ffma
+ libc.src.__support.math.ffmaf128
libc.src.__support.math.ffmal
libc.src.__support.math.floor
libc.src.__support.math.floorbf16
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 460449e4fcb2e..17045ce5edfdb 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -339,6 +339,8 @@ TEST(LlvmLibcSharedMathTest, AllFloat128) {
EXPECT_FP_EQ(float128(0x0p+0),
LIBC_NAMESPACE::shared::atan2f128(float128(0.0), float128(0.0)));
+ EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::ffmaf128(
+ float128(0.0), float128(0.0), float128(0.0)));
EXPECT_FP_EQ(0x1p+0f, LIBC_NAMESPACE::shared::fsqrtf128(float128(1.0f)));
EXPECT_FP_EQ_ALL_ROUNDING(float128(0.75), LIBC_NAMESPACE::shared::frexpf128(
float128(24), &exponent));
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 87d1d88e971bf..31a229d94a187 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -3915,6 +3915,17 @@ libc_support_library(
],
)
+libc_support_library(
+ name = "__support_math_ffmaf128",
+ hdrs = ["src/__support/math/ffmaf128.h"],
+ deps = [
+ ":__support_common",
+ ":__support_fputil_fma",
+ ":__support_macros_config",
+ ":llvm_libc_types_float128",
+ ],
+)
+
libc_support_library(
name = "__support_math_floor",
hdrs = ["src/__support/math/floor.h"],
@@ -6694,7 +6705,7 @@ libc_math_function(
libc_math_function(
name = "ffmaf128",
additional_deps = [
- ":__support_fputil_fma",
+ ":__support_math_ffmaf128",
],
)
>From 3f978a99330e3dca17a1bd115516f63b128004c1 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Thu, 5 Mar 2026 13:00:19 +0530
Subject: [PATCH 2/2] chore: nit
---
libc/shared/math/ffmaf128.h | 2 +-
libc/src/__support/math/ffmaf128.h | 3 +--
2 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/libc/shared/math/ffmaf128.h b/libc/shared/math/ffmaf128.h
index 5c76ed36a28e4..b22e6a1f08d3e 100644
--- a/libc/shared/math/ffmaf128.h
+++ b/libc/shared/math/ffmaf128.h
@@ -10,10 +10,10 @@
#define LLVM_LIBC_SHARED_MATH_FFMAF128_H
#include "include/llvm-libc-types/float128.h"
-#include "shared/libc_common.h"
#ifdef LIBC_TYPES_HAS_FLOAT128
+#include "shared/libc_common.h"
#include "src/__support/math/ffmaf128.h"
namespace LIBC_NAMESPACE_DECL {
diff --git a/libc/src/__support/math/ffmaf128.h b/libc/src/__support/math/ffmaf128.h
index 8b95e22bad0c1..c4b5a58e145fa 100644
--- a/libc/src/__support/math/ffmaf128.h
+++ b/libc/src/__support/math/ffmaf128.h
@@ -1,5 +1,4 @@
-//===-- Implementation header for ffmaf128 ------------ ----------*- C++
-//-*-===//
+//===-- Implementation header for ffmaf128 ----------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
More information about the libc-commits
mailing list