[libc][math] Refactor f16sqrtf to Header Only.#180749
Conversation
|
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
|
@llvm/pr-subscribers-libc Author: iLeGend (jinyouzhi) Changesfix #175329 Full diff: https://github.com/llvm/llvm-project/pull/180749.diff 9 Files Affected:
diff --git a/libc/shared/math.h b/libc/shared/math.h
index 66132326c2257..6248df5662977 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -64,6 +64,7 @@
#include "math/f16fmaf128.h"
#include "math/f16fmal.h"
#include "math/f16sqrt.h"
+#include "math/f16sqrtf.h"
#include "math/f16sqrtl.h"
#include "math/ffmal.h"
#include "math/frexpf.h"
diff --git a/libc/shared/math/f16sqrtf.h b/libc/shared/math/f16sqrtf.h
new file mode 100644
index 0000000000000..65f580cb3fed8
--- /dev/null
+++ b/libc/shared/math/f16sqrtf.h
@@ -0,0 +1,29 @@
+//===-- Shared f16sqrtf 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_F16SQRTF_H
+#define LLVM_LIBC_SHARED_MATH_F16SQRTF_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "shared/libc_common.h"
+#include "src/__support/math/f16sqrtf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::f16sqrtf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SHARED_MATH_F16SQRTF_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index c0293c0969217..c8555f61ca018 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -613,6 +613,16 @@ add_header_library(
libc.src.__support.macros.config
)
+add_header_library(
+ f16sqrtf
+ HDRS
+ f16sqrtf.h
+ DEPENDS
+ libc.src.__support.FPUtil.sqrt
+ libc.src.__support.common
+ libc.src.__support.macros.config
+)
+
add_header_library(
f16sqrtl
HDRS
diff --git a/libc/src/__support/math/f16sqrtf.h b/libc/src/__support/math/f16sqrtf.h
new file mode 100644
index 0000000000000..e6b513cc8e617
--- /dev/null
+++ b/libc/src/__support/math/f16sqrtf.h
@@ -0,0 +1,32 @@
+//===-- Implementation header for f16sqrtf ----------------------*- 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_F16SQRTF_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_F16SQRTF_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/FPUtil/sqrt.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr float16 f16sqrtf(float x) {
+ return fputil::sqrt<float16>(x);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_F16SQRTF_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 96dc0e7ca4851..01824aab9b12c 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -5072,8 +5072,7 @@ add_entrypoint_object(
HDRS
../f16sqrtf.h
DEPENDS
- libc.src.__support.macros.properties.types
- libc.src.__support.FPUtil.sqrt
+ libc.src.__support.math.f16sqrtf
)
add_entrypoint_object(
diff --git a/libc/src/math/generic/f16sqrtf.cpp b/libc/src/math/generic/f16sqrtf.cpp
index be43a77787fae..6ac777d4dca9a 100644
--- a/libc/src/math/generic/f16sqrtf.cpp
+++ b/libc/src/math/generic/f16sqrtf.cpp
@@ -7,14 +7,10 @@
//===----------------------------------------------------------------------===//
#include "src/math/f16sqrtf.h"
-#include "src/__support/FPUtil/sqrt.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/f16sqrtf.h"
namespace LIBC_NAMESPACE_DECL {
-LLVM_LIBC_FUNCTION(float16, f16sqrtf, (float x)) {
- return fputil::sqrt<float16>(x);
-}
+LLVM_LIBC_FUNCTION(float16, f16sqrtf, (float x)) { return math::f16sqrtf(x); }
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 7d72ced3e057c..1ba11aa0f7cc0 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -60,6 +60,7 @@ add_fp_unittest(
libc.src.__support.math.f16fmaf128
libc.src.__support.math.f16fmal
libc.src.__support.math.f16sqrt
+ libc.src.__support.math.f16sqrtf
libc.src.__support.math.f16sqrtl
libc.src.__support.math.ffmal
libc.src.__support.math.frexpf
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 9e024387efbfa..2bbed3215b0da 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -50,6 +50,8 @@ TEST(LlvmLibcSharedMathTest, AllFloat16) {
EXPECT_FP_EQ(0x0p+0f16, LIBC_NAMESPACE::shared::f16sqrt(0.0));
+ EXPECT_FP_EQ(0x0p+0f16, LIBC_NAMESPACE::shared::f16sqrtf(0.0f));
+
EXPECT_FP_EQ(float16(10.0),
LIBC_NAMESPACE::shared::f16fmal(2.0L, 3.0L, 4.0L));
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 3eae5e4a05b51..b2796c29c2764 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -1421,6 +1421,17 @@ libc_support_library(
],
)
+libc_support_library(
+ name = "__support_math_f16sqrtf",
+ hdrs = ["src/__support/math/f16sqrtf.h"],
+ deps = [
+ ":__support_common",
+ ":__support_fputil_sqrt",
+ ":__support_macros_config",
+ ":llvm_libc_macros_float16_macros",
+ ],
+)
+
libc_support_library(
name = "__support_math_f16sqrtl",
hdrs = ["src/__support/math/f16sqrtl.h"],
@@ -4407,7 +4418,7 @@ libc_math_function(
libc_math_function(
name = "f16sqrtf",
- additional_deps = [":__support_fputil_sqrt"],
+ additional_deps = [":__support_math_f16sqrtf"],
)
libc_math_function(
|
bassiounix
left a comment
There was a problem hiding this comment.
LGTM overall with some nits
bassiounix
left a comment
There was a problem hiding this comment.
LGTM.
Thank you for the refactor!
|
@jinyouzhi Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
fix #175329