[libc][math] Refactor ilogbl to Header Only.#176500
Merged
bassiounix merged 2 commits intollvm:mainfrom Jan 17, 2026
Merged
Conversation
Member
|
@llvm/pr-subscribers-libc Author: Anonmiraj (AnonMiraj) Changesbuilds with both Clang and GCC 12.2. Closes #175349. CC @bassiounix Full diff: https://github.com/llvm/llvm-project/pull/176500.diff 9 Files Affected:
diff --git a/libc/shared/math.h b/libc/shared/math.h
index 51fd4006feb4d..69729ad705a3e 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -64,6 +64,7 @@
#include "math/fsqrt.h"
#include "math/hypotf.h"
#include "math/ilogbf16.h"
+#include "math/ilogbl.h"
#include "math/ldexpf.h"
#include "math/ldexpf128.h"
#include "math/ldexpf16.h"
diff --git a/libc/shared/math/ilogbl.h b/libc/shared/math/ilogbl.h
new file mode 100644
index 0000000000000..c264f56c3dff2
--- /dev/null
+++ b/libc/shared/math/ilogbl.h
@@ -0,0 +1,23 @@
+//===-- Shared ilogbl 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_ILOGBL_H
+#define LLVM_LIBC_SHARED_MATH_ILOGBL_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/ilogbl.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::ilogbl;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_ILOGBL_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 0f3b17d467579..864f2dfac9dbb 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -956,6 +956,16 @@ add_header_library(
libc.src.__support.macros.optimization
)
+add_header_library(
+ ilogbl
+ HDRS
+ ilogbl.h
+ DEPENDS
+ libc.src.__support.FPUtil.manipulation_functions
+ libc.src.__support.common
+ libc.src.__support.macros.config
+)
+
add_header_library(
range_reduction_double
HDRS
diff --git a/libc/src/__support/math/ilogbl.h b/libc/src/__support/math/ilogbl.h
new file mode 100644
index 0000000000000..1d6a8b568fe06
--- /dev/null
+++ b/libc/src/__support/math/ilogbl.h
@@ -0,0 +1,28 @@
+//===-- Implementation header for ilogbl ------------------------*- 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_ILOGBL_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_ILOGBL_H
+
+#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 ilogbl(long double x) {
+ return fputil::intlogb<int>(x);
+}
+
+} // namespace math
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_ILOGBL_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 95398f4c9e074..7dd1bab072c8f 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -1782,7 +1782,8 @@ add_entrypoint_object(
HDRS
../ilogbl.h
DEPENDS
- libc.src.__support.FPUtil.manipulation_functions
+ libc.src.__support.math.ilogbl
+ libc.src.errno.errno
)
add_entrypoint_object(
diff --git a/libc/src/math/generic/ilogbl.cpp b/libc/src/math/generic/ilogbl.cpp
index 12460a8b154ee..b496b5312a1b7 100644
--- a/libc/src/math/generic/ilogbl.cpp
+++ b/libc/src/math/generic/ilogbl.cpp
@@ -7,14 +7,10 @@
//===----------------------------------------------------------------------===//
#include "src/math/ilogbl.h"
-#include "src/__support/FPUtil/ManipulationFunctions.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/ilogbl.h"
namespace LIBC_NAMESPACE_DECL {
-LLVM_LIBC_FUNCTION(int, ilogbl, (long double x)) {
- return fputil::intlogb<int>(x);
-}
+LLVM_LIBC_FUNCTION(int, ilogbl, (long double x)) { return math::ilogbl(x); }
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index d0800cf84dcd5..7e8a8140b94a2 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -70,4 +70,5 @@ add_fp_unittest(
libc.src.__support.math.rsqrtf
libc.src.__support.math.rsqrtf16
libc.src.__support.math.sin
+ libc.src.__support.math.ilogbl
)
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 79a15f127d853..b8b740df7855c 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -102,6 +102,7 @@ TEST(LlvmLibcSharedMathTest, AllDouble) {
TEST(LlvmLibcSharedMathTest, AllLongDouble) {
EXPECT_FP_EQ(0x0p+0L,
LIBC_NAMESPACE::shared::dfmal(0x0.p+0L, 0x0.p+0L, 0x0.p+0L));
+ EXPECT_EQ(0, LIBC_NAMESPACE::shared::ilogbl(0x1.p+0L));
}
#ifdef LIBC_TYPES_HAS_FLOAT128
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 953565e75a096..d14a5fed14825 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -4392,7 +4392,10 @@ libc_math_function(name = "ilogb")
libc_math_function(name = "ilogbf")
-libc_math_function(name = "ilogbl")
+libc_math_function(
+ name = "ilogbl",
+ additional_deps = ["__support_math_ilogbl"],
+)
libc_math_function(name = "ilogbf128")
@@ -7931,3 +7934,11 @@ libc_function(
":types_wchar_t",
],
)
+
+libc_support_library(
+ name = "__support_math_ilogbl",
+ hdrs = ["src/__support/math/ilogbl.h"],
+ deps = [
+ ":__support_fputil_manipulation_functions",
+ ],
+)
|
bassiounix
reviewed
Jan 17, 2026
bassiounix
reviewed
Jan 17, 2026
bassiounix
reviewed
Jan 17, 2026
bassiounix
approved these changes
Jan 17, 2026
Priyanshu3820
pushed a commit
to Priyanshu3820/llvm-project
that referenced
this pull request
Jan 18, 2026
builds with both Clang and GCC 12.2. Closes llvm#175349.
BStott6
pushed a commit
to BStott6/llvm-project
that referenced
this pull request
Jan 22, 2026
builds with both Clang and GCC 12.2. Closes llvm#175349.
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
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.
builds with both Clang and GCC 12.2.
Closes #175349.
CC @bassiounix