Skip to content

[libc][math] Refactor ilogbl to Header Only.#176500

Merged
bassiounix merged 2 commits intollvm:mainfrom
AnonMiraj:refactor_ilogbl
Jan 17, 2026
Merged

[libc][math] Refactor ilogbl to Header Only.#176500
bassiounix merged 2 commits intollvm:mainfrom
AnonMiraj:refactor_ilogbl

Conversation

@AnonMiraj
Copy link
Copy Markdown
Contributor

builds with both Clang and GCC 12.2.

Closes #175349.

CC @bassiounix

@llvmbot llvmbot added libc bazel "Peripheral" support tier build system: utils/bazel labels Jan 16, 2026
@llvmbot
Copy link
Copy Markdown
Member

llvmbot commented Jan 16, 2026

@llvm/pr-subscribers-libc

Author: Anonmiraj (AnonMiraj)

Changes

builds 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:

  • (modified) libc/shared/math.h (+1)
  • (added) libc/shared/math/ilogbl.h (+23)
  • (modified) libc/src/__support/math/CMakeLists.txt (+10)
  • (added) libc/src/__support/math/ilogbl.h (+28)
  • (modified) libc/src/math/generic/CMakeLists.txt (+2-1)
  • (modified) libc/src/math/generic/ilogbl.cpp (+2-6)
  • (modified) libc/test/shared/CMakeLists.txt (+1)
  • (modified) libc/test/shared/shared_math_test.cpp (+1)
  • (modified) utils/bazel/llvm-project-overlay/libc/BUILD.bazel (+12-1)
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 bassiounix merged commit 6397207 into llvm:main Jan 17, 2026
24 of 28 checks passed
Priyanshu3820 pushed a commit to Priyanshu3820/llvm-project that referenced this pull request Jan 18, 2026
BStott6 pushed a commit to BStott6/llvm-project that referenced this pull request Jan 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bazel "Peripheral" support tier build system: utils/bazel libc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[libc][math] Refactor ilogbl to Header Only.

3 participants