[libc][math] Refactor sqrtf16 to Header Only#177726
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: Prajwal KP (Prajwal-kp-18) Changescloses: #177651 Full diff: https://github.com/llvm/llvm-project/pull/177726.diff 9 Files Affected:
diff --git a/libc/shared/math.h b/libc/shared/math.h
index a331abcc033c7..83c541dd683ef 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -84,6 +84,7 @@
#include "math/rsqrtf.h"
#include "math/rsqrtf16.h"
#include "math/sin.h"
+#include "math/sqrtf16.h"
#include "math/tan.h"
#endif // LLVM_LIBC_SHARED_MATH_H
diff --git a/libc/shared/math/sqrtf16.h b/libc/shared/math/sqrtf16.h
new file mode 100644
index 0000000000000..9c2043582307a
--- /dev/null
+++ b/libc/shared/math/sqrtf16.h
@@ -0,0 +1,29 @@
+//===-- Shared sqrtf16 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_SQRTF16_H
+#define LLVM_LIBC_SHARED_MATH_SQRTF16_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "shared/libc_common.h"
+#include "src/__support/math/sqrtf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::sqrtf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SHARED_MATH_SQRTF16_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index a03952d5c5ed0..9a53f840e3297 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -1072,6 +1072,14 @@ add_header_library(
libc.src.__support.macros.optimization
)
+add_header_library(
+ sqrtf16
+ HDRS
+ sqrtf16.h
+ DEPENDS
+ libc.src.__support.FPUtil.sqrt
+)
+
add_header_library(
sincos_eval
HDRS
diff --git a/libc/src/__support/math/sqrtf16.h b/libc/src/__support/math/sqrtf16.h
new file mode 100644
index 0000000000000..8c9e1e65177de
--- /dev/null
+++ b/libc/src/__support/math/sqrtf16.h
@@ -0,0 +1,31 @@
+//===-- Implementation header for sqrtf16 -----------------------*- 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_SQRTF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_SQRTF16_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/FPUtil/sqrt.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE static constexpr float16 sqrtf16(float16 x) {
+ return fputil::sqrt<float16>(x);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_SQRTF16_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 04ad1aa896613..a73f55a15cdf0 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -3066,7 +3066,7 @@ add_entrypoint_object(
HDRS
../sqrtf16.h
DEPENDS
- libc.src.__support.FPUtil.sqrt
+ libc.src.__support.math.sqrtf16
)
add_entrypoint_object(
diff --git a/libc/src/math/generic/sqrtf16.cpp b/libc/src/math/generic/sqrtf16.cpp
index 0aa4a201b3e68..d175f69f39ba4 100644
--- a/libc/src/math/generic/sqrtf16.cpp
+++ b/libc/src/math/generic/sqrtf16.cpp
@@ -7,14 +7,9 @@
//===----------------------------------------------------------------------===//
#include "src/math/sqrtf16.h"
-#include "src/__support/FPUtil/sqrt.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/sqrtf16.h"
namespace LIBC_NAMESPACE_DECL {
-LLVM_LIBC_FUNCTION(float16, sqrtf16, (float16 x)) {
- return fputil::sqrt<float16>(x);
-}
-
+LLVM_LIBC_FUNCTION(float16, sqrtf16, (float16 x)) { return math::sqrtf16(x); }
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 4f82d00cc6c84..5a7a9a7b50af4 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -79,6 +79,7 @@ add_fp_unittest(
libc.src.__support.math.llogbf
libc.src.__support.math.rsqrtf
libc.src.__support.math.rsqrtf16
+ libc.src.__support.math.sqrtf16
libc.src.__support.math.sin
libc.src.__support.math.tan
)
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 5ec8a7b23081e..90b18e41c826e 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -18,6 +18,7 @@ TEST(LlvmLibcSharedMathTest, AllFloat16) {
EXPECT_FP_EQ(0x0p+0f16, LIBC_NAMESPACE::shared::acoshf16(1.0f16));
EXPECT_FP_EQ(0x0p+0f16, LIBC_NAMESPACE::shared::acospif16(1.0f16));
EXPECT_FP_EQ(0x1p+0f16, LIBC_NAMESPACE::shared::rsqrtf16(1.0f16));
+ EXPECT_FP_EQ(0x1p+0f16, LIBC_NAMESPACE::shared::sqrtf16(1.0f16));
EXPECT_FP_EQ(0x0p+0f16, LIBC_NAMESPACE::shared::asinf16(0.0f16));
EXPECT_FP_EQ(0x0p+0f16, LIBC_NAMESPACE::shared::asinhf16(0.0f16));
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index c53b9c9a91573..b7b8799d8c423 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -2405,6 +2405,14 @@ libc_support_library(
],
)
+libc_support_library(
+ name = "__support_math_sqrtf16",
+ hdrs = ["src/__support/math/sqrtf16.h"],
+ deps = [
+ ":__support_fputil_sqrt",
+ ],
+)
+
libc_support_library(
name = "__support_math_asin_utils",
hdrs = ["src/__support/math/asin_utils.h"],
@@ -5151,7 +5159,7 @@ libc_math_function(
libc_math_function(
name = "sqrtf16",
additional_deps = [
- ":__support_fputil_sqrt",
+ ":__support_math_sqrtf16",
],
)
|
|
@bassiounix Added the suggested lines. Thanks for the review! |
273990f to
95d32c0
Compare
bassiounix
left a comment
There was a problem hiding this comment.
LGTM.
Thank you for the refactor!
|
@Prajwal-kp-18 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! |
closes: #177651