-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[libc][math] Refactor fmaf16 implementation to header-only in src/__support/math folder. #163977
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bassiounix
wants to merge
1
commit into
users/bassiounix/spr/10-17-_libc_math_refactor_fmaf_implementation_to_header-only_in_src___support_math_folder
Choose a base branch
from
users/bassiounix/spr/10-17-_libc_math_refactor_fmaf16_implementation_to_header-only_in_src___support_math_folder
base: users/bassiounix/spr/10-17-_libc_math_refactor_fmaf_implementation_to_header-only_in_src___support_math_folder
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+86
−8
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…upport/math folder.
This was referenced Oct 17, 2025
Merged
Merged
Merged
Merged
Merged
Merged
Merged
Merged
Merged
Merged
Merged
Merged
Merged
Merged
Merged
Merged
Merged
Merged
Merged
Merged
Merged
[libc][math] Refactor exp10m1f16 implementation to header-only in src/__support/math folder.
#161119
Merged
Merged
Merged
This was referenced Oct 17, 2025
Open
Open
Open
@llvm/pr-subscribers-libc Author: Muhammad Bassiouni (bassiounix) ChangesPart of #147386 in preparation for: https://discourse.llvm.org/t/rfc-make-clang-builtin-math-functions-constexpr-with-llvm-libc-to-support-c-23-constexpr-math-functions/86450 Full diff: https://github.com/llvm/llvm-project/pull/163977.diff 9 Files Affected:
diff --git a/libc/shared/math.h b/libc/shared/math.h
index 2198ffdc74459..050b67f0efb5f 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -59,6 +59,7 @@
#include "math/expm1f16.h"
#include "math/fma.h"
#include "math/fmaf.h"
+#include "math/fmaf16.h"
#include "math/frexpf.h"
#include "math/frexpf128.h"
#include "math/frexpf16.h"
diff --git a/libc/shared/math/fmaf16.h b/libc/shared/math/fmaf16.h
new file mode 100644
index 0000000000000..a6da1bfa58a3a
--- /dev/null
+++ b/libc/shared/math/fmaf16.h
@@ -0,0 +1,29 @@
+//===-- Shared fmaf16 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_FMAF16_H
+#define LLVM_LIBC_SHARED_MATH_FMAF16_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+#include "shared/libc_common.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/math/fmaf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::fmaf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SHARED_MATH_FMAF16_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 56229957a4c56..404c5281437d9 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -609,6 +609,14 @@ add_header_library(
libc.src.__support.FPUtil.fma
)
+add_header_library(
+ fmaf16
+ HDRS
+ fmaf16.h
+ DEPENDS
+ libc.src.__support.FPUtil.fma
+)
+
add_header_library(
frexpf128
HDRS
diff --git a/libc/src/__support/math/fmaf16.h b/libc/src/__support/math/fmaf16.h
new file mode 100644
index 0000000000000..e15a646190ad2
--- /dev/null
+++ b/libc/src/__support/math/fmaf16.h
@@ -0,0 +1,33 @@
+//===-- Implementation header for fmaf16 ------------------------*- 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_FMAF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_FMAF16_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/FPUtil/FMA.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE static float16 fmaf16(float16 x, float16 y, float16 z) {
+ return fputil::fma<float16>(x, y, z);
+}
+
+} // namespace math
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FMAF16_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 55055803731ae..a6e82c18003d3 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -4711,8 +4711,7 @@ add_entrypoint_object(
HDRS
../fmaf16.h
DEPENDS
- libc.src.__support.FPUtil.fma
- libc.src.__support.macros.properties.types
+ libc.src.__support.math.fmaf16
)
add_entrypoint_object(
diff --git a/libc/src/math/generic/fmaf16.cpp b/libc/src/math/generic/fmaf16.cpp
index 4f712f5de764f..e21240900c2f5 100644
--- a/libc/src/math/generic/fmaf16.cpp
+++ b/libc/src/math/generic/fmaf16.cpp
@@ -7,14 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/fmaf16.h"
-#include "src/__support/FPUtil/FMA.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/fmaf16.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(float16, fmaf16, (float16 x, float16 y, float16 z)) {
- return fputil::fma<float16>(x, y, z);
+ return math::fmaf16(x, y, z);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index f5c42c145c318..43fd47bf5a82f 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -55,6 +55,7 @@ add_fp_unittest(
libc.src.__support.math.expf16
libc.src.__support.math.fma
libc.src.__support.math.fmaf
+ libc.src.__support.math.fmaf16
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 d81ae4df562b6..c5cd655312289 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -32,7 +32,8 @@ TEST(LlvmLibcSharedMathTest, AllFloat16) {
EXPECT_FP_EQ(0x0p+0f16, LIBC_NAMESPACE::shared::exp2m1f16(0.0f16));
EXPECT_FP_EQ(0x1p+0f16, LIBC_NAMESPACE::shared::expf16(0.0f16));
EXPECT_FP_EQ(0x0p+0f16, LIBC_NAMESPACE::shared::expm1f16(0.0f16));
-
+ EXPECT_FP_EQ(0x0p+0f16,
+ LIBC_NAMESPACE::shared::fmaf16(0.0f16, 0.0f16, 0.0f16));
ASSERT_FP_EQ(float16(8 << 5), LIBC_NAMESPACE::shared::ldexpf16(8.0f16, 5));
ASSERT_FP_EQ(float16(-1 * (8 << 5)),
LIBC_NAMESPACE::shared::ldexpf16(-8.0f16, 5));
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index d3f3168f31a0d..82e719569fa25 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -2807,6 +2807,14 @@ libc_support_library(
],
)
+libc_support_library(
+ name = "__support_math_fmaf16",
+ hdrs = ["src/__support/math/fmaf16.h"],
+ deps = [
+ ":__support_fputil_fma",
+ ],
+)
+
libc_support_library(
name = "__support_math_frexpf128",
hdrs = ["src/__support/math/frexpf128.h"],
@@ -4031,7 +4039,7 @@ libc_math_function(
libc_math_function(
name = "fmaf16",
additional_deps = [
- ":__support_fputil_fma",
+ ":__support_math_fmaf16",
],
)
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.