[libc] [math] Refactor fsqrtl to be header-only#176169
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: Atharv Mane (Atharva062006) ChangesThis PR refactors fsqrtl to be header only as discussed. No functional change intended. Test and build files were updated as required by the refactor Full diff: https://github.com/llvm/llvm-project/pull/176169.diff 9 Files Affected:
diff --git a/libc/shared/math.h b/libc/shared/math.h
index 287f3aea1565a..8fe5f82da696b 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/fsqrtl.h"
#include "math/ilogbf16.h"
#include "math/ldexpf.h"
#include "math/ldexpf128.h"
diff --git a/libc/shared/math/fsqrtl.h b/libc/shared/math/fsqrtl.h
new file mode 100644
index 0000000000000..9e99c229431ae
--- /dev/null
+++ b/libc/shared/math/fsqrtl.h
@@ -0,0 +1,24 @@
+//===-- Shared header for fsqrtl ---------------------------------*- 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_FSQRTL_H
+#define LLVM_LIBC_SHARED_MATH_FSQRTL_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/fsqrtl.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace shared {
+
+using math::fsqrtl;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_FSQRTL_H
\ No newline at end of file
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 4139a1b1d3444..005ad69b487d5 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -1078,3 +1078,11 @@ add_header_library(
libc.src.__support.math.sincos_eval
libc.src.__support.macros.optimization
)
+
+add_header_library(
+ fsqrtl
+ HDRS
+ fsqrtl.h
+ DEPENDS
+ libc.src.__support.FPUtil.generic.sqrt
+)
diff --git a/libc/src/__support/math/fsqrtl.h b/libc/src/__support/math/fsqrtl.h
new file mode 100644
index 0000000000000..5a21ea6c9d25c
--- /dev/null
+++ b/libc/src/__support/math/fsqrtl.h
@@ -0,0 +1,26 @@
+//===-- Implementation header for fsqrtl ------------------------*- 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_FSQRTL_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_FSQRTL_H
+
+#include "src/__support/FPUtil/generic/sqrt.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE static constexpr float fsqrt(long double x) {
+ return fputil::sqrt<float>(x);
+}
+
+} // namespace math
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FSQRTL_H
\ No newline at end of file
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 6de4cf376bf02..895bf77b12ee5 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -5234,7 +5234,7 @@ add_entrypoint_object(
HDRS
../fsqrtl.h
DEPENDS
- libc.src.__support.FPUtil.generic.sqrt
+ libc.src.__support.math.fsqrtl
)
add_entrypoint_object(
diff --git a/libc/src/math/generic/fsqrtl.cpp b/libc/src/math/generic/fsqrtl.cpp
index b896a84aeded8..9deb86b558ea7 100644
--- a/libc/src/math/generic/fsqrtl.cpp
+++ b/libc/src/math/generic/fsqrtl.cpp
@@ -10,11 +10,10 @@
#include "src/__support/FPUtil/generic/sqrt.h"
#include "src/__support/common.h"
#include "src/__support/macros/config.h"
+#include "src/__support/math/fsqrtl.h"
namespace LIBC_NAMESPACE_DECL {
-LLVM_LIBC_FUNCTION(float, fsqrtl, (long double x)) {
- return fputil::sqrt<float>(x);
-}
+LLVM_LIBC_FUNCTION(float, fsqrtl, (long double x)) { return math::fsqrtl(x); }
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index c5955ecfd54cb..ab74a1fff22a6 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -56,6 +56,7 @@ add_fp_unittest(
libc.src.__support.math.frexpf
libc.src.__support.math.frexpf128
libc.src.__support.math.frexpf16
+ libc.src.__support.math.fsqrtl
libc.src.__support.math.ilogbf16
libc.src.__support.math.log
libc.src.__support.math.ldexpf
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 20a98a1a9138c..d1480977dda19 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -92,6 +92,7 @@ TEST(LlvmLibcSharedMathTest, AllDouble) {
EXPECT_FP_EQ(0x1p+0, LIBC_NAMESPACE::shared::exp2(0.0));
EXPECT_FP_EQ(0x1p+0, LIBC_NAMESPACE::shared::exp10(0.0));
EXPECT_FP_EQ(0x0p+0, LIBC_NAMESPACE::shared::expm1(0.0));
+ EXPECT_FP_EQ(0x0p+0, LIBC_NAMESPACE::shared::fsqrtl(0.0));
EXPECT_FP_EQ(0x0p+0, LIBC_NAMESPACE::shared::log(1.0));
EXPECT_FP_EQ(0.0, LIBC_NAMESPACE::shared::sin(0.0));
}
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index c03c21b834895..cf2ad3bdcb039 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -2813,6 +2813,14 @@ libc_support_library(
],
)
+libc_support_library(
+ name = "__support_math_fsqrtl",
+ hdrs = ["src/__support/math/fsqrtl.h"],
+ deps = [
+ ":__support_fputil_sqrt",
+ ],
+)
+
libc_support_library(
name = "__support_math_inv_trigf_utils",
hdrs = ["src/__support/math/inv_trigf_utils.h"],
@@ -4285,7 +4293,7 @@ libc_math_function(
libc_math_function(
name = "fsqrtl",
additional_deps = [
- ":__support_fputil_sqrt",
+ ":__support_math_fsqrtl",
],
)
|
bassiounix
left a comment
There was a problem hiding this comment.
Thank you for you PR, you are on the right track with some changes.
libc/src/__support/math/fsqrtl.h
Outdated
|
|
||
| } // namespace LIBC_NAMESPACE_DECL | ||
|
|
||
| #endif // LLVM_LIBC_SRC___SUPPORT_MATH_FSQRTL_H No newline at end of file |
There was a problem hiding this comment.
| #endif // LLVM_LIBC_SRC___SUPPORT_MATH_FSQRTL_H | |
| #endif // LLVM_LIBC_SRC___SUPPORT_MATH_FSQRTL_H | |
libc/src/math/generic/fsqrtl.cpp
Outdated
| #include "src/__support/FPUtil/generic/sqrt.h" | ||
| #include "src/__support/common.h" | ||
| #include "src/__support/macros/config.h" |
There was a problem hiding this comment.
Cleanup
| #include "src/__support/FPUtil/generic/sqrt.h" | |
| #include "src/__support/common.h" | |
| #include "src/__support/macros/config.h" |
| EXPECT_FP_EQ(0x1p+0, LIBC_NAMESPACE::shared::exp2(0.0)); | ||
| EXPECT_FP_EQ(0x1p+0, LIBC_NAMESPACE::shared::exp10(0.0)); | ||
| EXPECT_FP_EQ(0x0p+0, LIBC_NAMESPACE::shared::expm1(0.0)); | ||
| EXPECT_FP_EQ(0x0p+0, LIBC_NAMESPACE::shared::fsqrtl(0.0)); |
There was a problem hiding this comment.
There's a new section for long double functions, please fetch the latest changes and move your function there
|
|
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
🐧 Linux x64 Test Results✅ The build succeeded and no tests ran. This is expected in some build configurations. |
1cb8bb9 to
058bbb3
Compare
|
@bassiounix i did all the recommended changes, does this look okay? |
058bbb3 to
ec8ded2
Compare
| TEST(LlvmLibcSharedMathTest, AllLongDouble) { | ||
| EXPECT_FP_EQ(0x0p+0L, | ||
| LIBC_NAMESPACE::shared::dfmal(0x0.p+0L, 0x0.p+0L, 0x0.p+0L)); | ||
| EXPECT_FP_EQ(0x0p+0, LIBC_NAMESPACE::shared::fsqrtl(0.0)); |
There was a problem hiding this comment.
Please add the long literal type suffix
ec8ded2 to
ce66633
Compare
|
@bassiounix Done |
libc/src/__support/math/fsqrtl.h
Outdated
|
|
||
| namespace math { | ||
|
|
||
| LIBC_INLINE static constexpr float fsqrt(long double x) { |
There was a problem hiding this comment.
| LIBC_INLINE static constexpr float fsqrt(long double x) { | |
| LIBC_INLINE static constexpr float fsqrtl(long double x) { |
b08e00b to
3da7e10
Compare
|
please check code formatting |
3da7e10 to
d734ae5
Compare
|
@bassiounix used clang-format, should be fixed |
I can't accept this PR unless you resolve this. |
|
@Atharva062006 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! |
This PR refactors fsqrtl to be header only as discussed. No functional change intended. Test and build files were updated as required by the refactor Fixes llvm#175335
This PR refactors fsqrtl to be header only as discussed. No functional change intended. Test and build files were updated as required by the refactor Fixes llvm#175335
This PR refactors fsqrtl to be header only as discussed. No functional change intended. Test and build files were updated as required by the refactor
Fixes #175335