[libc][math] Refactor ilogbf128 to Header Only#175396
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: Ramshankar (Ramshankar07) ChangesRefactors the ilogbf128 implementation to be header-only and available via shared math. This is part of the ongoing effort to make math functions constexpr-capable that fixes: #175345 Changes:
Full diff: https://github.com/llvm/llvm-project/pull/175396.diff 7 Files Affected:
diff --git a/libc/shared/math.h b/libc/shared/math.h
index 7fb4c43f509c4..6932de634a545 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/ilogbf128.h"
#include "math/ldexpf.h"
#include "math/ldexpf128.h"
#include "math/ldexpf16.h"
@@ -67,4 +68,5 @@
#include "math/rsqrtf16.h"
#include "math/sin.h"
+
#endif // LLVM_LIBC_SHARED_MATH_H
diff --git a/libc/shared/math/ilogbf128.h b/libc/shared/math/ilogbf128.h
new file mode 100644
index 0000000000000..b58915fb432ad
--- /dev/null
+++ b/libc/shared/math/ilogbf128.h
@@ -0,0 +1,29 @@
+//===-- Shared ilogbf128 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_ILOGBF128_H
+#define LLVM_LIBC_SHARED_MATH_ILOGBF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "shared/libc_common.h"
+#include "src/__support/math/ilogbf128.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::ilogbf128;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_MATH_ILogBF128_H
\ No newline at end of file
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 741da7432c94f..7d4ee136c7994 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -603,6 +603,16 @@ add_header_library(
libc.src.__support.FPUtil.manipulation_functions
)
+add_header_library(
+ ilogbf128
+ HDRS
+ ilogbf128.h
+ DEPENDS
+ libc.src.__support.macros.properties.types
+ libc.src.__support.FPUtil.manipulation_functions
+ libc.include.llvm-libc-types.float128
+)
+
add_header_library(
inv_trigf_utils
HDRS
diff --git a/libc/src/__support/math/ilogbf128.h b/libc/src/__support/math/ilogbf128.h
new file mode 100644
index 0000000000000..6849114933fc0
--- /dev/null
+++ b/libc/src/__support/math/ilogbf128.h
@@ -0,0 +1,34 @@
+//===-- Implementation header for ilogbf128 ----------------------*- 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_ILOGBF128_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_ILOGBF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "src/__support/FPUtil/ManipulationFunctions.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE static constexpr int ilogbf128(float128 x) {
+ return fputil::intlogb<int>(x);
+}
+
+} // namespace math
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_ILOGBF128_H
\ No newline at end of file
diff --git a/libc/src/math/generic/ilogbf128.cpp b/libc/src/math/generic/ilogbf128.cpp
index 4abc670188a3a..593e36b064d55 100644
--- a/libc/src/math/generic/ilogbf128.cpp
+++ b/libc/src/math/generic/ilogbf128.cpp
@@ -10,11 +10,11 @@
#include "src/__support/FPUtil/ManipulationFunctions.h"
#include "src/__support/common.h"
#include "src/__support/macros/config.h"
-
+#include "lib/shared/math/ilogbf128.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, ilogbf128, (float128 x)) {
- return fputil::intlogb<int>(x);
+ return shared::ilogbf128(x);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index f823d414e2afd..392dab3317725 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -103,7 +103,9 @@ TEST(LlvmLibcSharedMathTest, AllFloat128) {
EXPECT_FP_EQ_ALL_ROUNDING(float128(0.75), LIBC_NAMESPACE::shared::frexpf128(
float128(24), &exponent));
EXPECT_EQ(exponent, 5);
-
+
+ EXPECT_EQ(3, LIBC_NAMESPACE::shared::ilogbf128(float128(8.0)));
+ EXPECT_EQ(4, LIBC_NAMESPACE::shared::ilogbf128(float128(16.0)));
ASSERT_FP_EQ(float128(8 << 5),
LIBC_NAMESPACE::shared::ldexpf128(float128(8), 5));
ASSERT_FP_EQ(float128(-1 * (8 << 5)),
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 210c25dddd0b9..874bbe92d02cc 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -2813,6 +2813,16 @@ libc_support_library(
],
)
+libc_support_library(
+ name = "__support_math_ilogbf128",
+ hdrs = ["src/__support/math/ilogbf128.h"],
+ deps = [
+ ":__support_fputil_manipulation_functions",
+ ":__support_macros_properties_types",
+ ":llvm_libc_types_float128",
+ ],
+)
+
libc_support_library(
name = "__support_math_inv_trigf_utils",
hdrs = ["src/__support/math/inv_trigf_utils.h"],
@@ -4308,7 +4318,12 @@ libc_math_function(name = "ilogbf")
libc_math_function(name = "ilogbl")
-libc_math_function(name = "ilogbf128")
+libc_math_function(
+ name = "ilogbf128",
+ additional_deps = [
+ ":__support_math_ilogbf128",
+ ],
+)
libc_math_function(name = "ilogbf16")
|
|
When you finish working on this please give me a mention |
|
✅ 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. |
Co-authored-by: Muhammad Bassiouni <60100307+bassiounix@users.noreply.github.com>
Co-authored-by: Muhammad Bassiouni <60100307+bassiounix@users.noreply.github.com>
Co-authored-by: Muhammad Bassiouni <60100307+bassiounix@users.noreply.github.com>
Co-authored-by: Muhammad Bassiouni <60100307+bassiounix@users.noreply.github.com>
|
Hi @bassiounix , I couldn't test it in my Mac because float128 isn't available for macOS. Let me know If I still make any |
Co-authored-by: Muhammad Bassiouni <60100307+bassiounix@users.noreply.github.com>
|
@bassiounix Thanks for reviewing minute changes, I'm new to open source contribution. |
|
please format the code |
Co-authored-by: Muhammad Bassiouni <60100307+bassiounix@users.noreply.github.com>
Co-authored-by: Muhammad Bassiouni <60100307+bassiounix@users.noreply.github.com>
Co-authored-by: Muhammad Bassiouni <60100307+bassiounix@users.noreply.github.com>
|
@Ramshankar07 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! |
|
Thank you for helping me in code formatting and tweaks @bassiounix , I love to learn more and contribute. |
Refactors the ilogbf128 implementation to be header-only and available via shared math. fixes: llvm#175345
Refactors the ilogbf128 implementation to be header-only and available via shared math. fixes: llvm#175345
Refactors the ilogbf128 implementation to be header-only and available via shared math. fixes: llvm#175345
Refactors the ilogbf128 implementation to be header-only and available via shared math.
This is part of the ongoing effort to make math functions constexpr-capable
in LLVM libc.
that fixes: #175345
Changes: