llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: None (parthtyagi27)
<details>
<summary>Changes</summary>
Changes for refactoring ffmaf128 from this issue: [#<!-- -->175325 ](https://github.com/llvm/llvm-project/issues/175325)
---
Full diff: https://github.com/llvm/llvm-project/pull/177873.diff
9 Files Affected:
- (modified) libc/shared/math.h (+1)
- (added) libc/shared/math/ffmaf128.h (+23)
- (modified) libc/src/__support/math/CMakeLists.txt (+8)
- (added) libc/src/__support/math/ffmaf128.h (+27)
- (modified) libc/src/math/generic/CMakeLists.txt (+1-1)
- (modified) libc/src/math/generic/ffmaf128.cpp (+6-5)
- (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 (+9-1)
``````````diff
diff --git a/libc/shared/math.h b/libc/shared/math.h
index 7fb4c43f509c4..22ad93765fd1a 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -60,6 +60,7 @@
#include "math/frexpf.h"
#include "math/frexpf128.h"
#include "math/frexpf16.h"
+#include "math/ffmaf128.h"
#include "math/ldexpf.h"
#include "math/ldexpf128.h"
#include "math/ldexpf16.h"
diff --git a/libc/shared/math/ffmaf128.h b/libc/shared/math/ffmaf128.h
new file mode 100644
index 0000000000000..f468312a8234f
--- /dev/null
+++ b/libc/shared/math/ffmaf128.h
@@ -0,0 +1,23 @@
+//===-- 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 "shared/libc_common.h"
+#include "src/__support/math/ffmaf128.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::ffmaf128;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_FFMAF128_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 741da7432c94f..982c1333c41ac 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -594,6 +594,14 @@ add_header_library(
libc.src.__support.math.exp10_float16_constants
)
+add_header_library(
+ ffmaf128
+ HDRS
+ ffmaf128.h
+ DEPENDS
+ libc.src.__support.FPUtil.fma
+)
+
add_header_library(
frexpf128
HDRS
diff --git a/libc/src/__support/math/ffmaf128.h b/libc/src/__support/math/ffmaf128.h
new file mode 100644
index 0000000000000..8c6fdd2690879
--- /dev/null
+++ b/libc/src/__support/math/ffmaf128.h
@@ -0,0 +1,27 @@
+//===-- 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 "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 constexpr float ffmaf128(float128 x, float128 y, float128 z) {
+ return fputil::fma<float>(x, y, z);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#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 9c0da076b6cf0..7543ddee40a42 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -3438,7 +3438,7 @@ add_entrypoint_object(
../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..442ecd0bb73e6 100644
--- a/libc/src/math/generic/ffmaf128.cpp
+++ b/libc/src/math/generic/ffmaf128.cpp
@@ -7,14 +7,15 @@
//===----------------------------------------------------------------------===//
#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/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 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 0f23162798a8b..cfa0c744e75bc 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -53,6 +53,7 @@ add_fp_unittest(
libc.src.__support.math.exp10f16
libc.src.__support.math.expf
libc.src.__support.math.expf16
+ libc.src.__support.math.ffmaf128
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 f823d414e2afd..8103bfac3ee42 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -108,6 +108,7 @@ TEST(LlvmLibcSharedMathTest, AllFloat128) {
LIBC_NAMESPACE::shared::ldexpf128(float128(8), 5));
ASSERT_FP_EQ(float128(-1 * (8 << 5)),
LIBC_NAMESPACE::shared::ldexpf128(float128(-8), 5));
+ EXPECT_FP_EQ(0x0p+0, LIBC_NAMESPACE::shared::ffmaf128(float128(0.0), float128(0.0), float128(0.0)));
}
#endif // LIBC_TYPES_HAS_FLOAT128
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 210c25dddd0b9..f1e8f1a17d4f2 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -2804,6 +2804,14 @@ libc_support_library(
],
)
+libc_support_library(
+ name = "__support_math_ffmaf128",
+ hdrs = ["src/__support/math/ffmaf128.h"],
+ deps = [
+ ":__support_macros_properties_types",
+ ],
+)
+
libc_support_library(
name = "__support_math_frexpf128",
hdrs = ["src/__support/math/frexpf128.h"],
@@ -4013,7 +4021,7 @@ libc_math_function(
libc_math_function(
name = "ffmaf128",
additional_deps = [
- ":__support_fputil_fma",
+ ":__support_math_ffmaf128",
],
)
``````````
</details>
https://github.com/llvm/llvm-project/pull/177873