[libc-commits] [libc] 82204a4 - [libc][math] Refactor ilogbf implementation to header-only in src/__support/math folder. (#175522)

via libc-commits libc-commits at lists.llvm.org
Mon Jan 19 07:57:41 PST 2026


Author: Anonymous
Date: 2026-01-19T17:57:36+02:00
New Revision: 82204a482bf7d1496560a6cd0cc61165d38a0ee2

URL: https://github.com/llvm/llvm-project/commit/82204a482bf7d1496560a6cd0cc61165d38a0ee2
DIFF: https://github.com/llvm/llvm-project/commit/82204a482bf7d1496560a6cd0cc61165d38a0ee2.diff

LOG: [libc][math] Refactor ilogbf implementation to header-only in src/__support/math folder. (#175522)

closes #175347 , part of #175344

Added: 
    libc/shared/math/ilogbf.h
    libc/src/__support/math/ilogbf.h

Modified: 
    libc/shared/math.h
    libc/src/__support/math/CMakeLists.txt
    libc/src/math/generic/CMakeLists.txt
    libc/src/math/generic/ilogbf.cpp
    libc/test/shared/CMakeLists.txt
    libc/test/shared/shared_math_test.cpp
    utils/bazel/llvm-project-overlay/libc/BUILD.bazel

Removed: 
    


################################################################################
diff  --git a/libc/shared/math.h b/libc/shared/math.h
index 6b66c5e75e457..d58238703701d 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -65,6 +65,7 @@
 #include "math/fsqrt.h"
 #include "math/fsqrtf128.h"
 #include "math/hypotf.h"
+#include "math/ilogbf.h"
 #include "math/ilogbf16.h"
 #include "math/ilogbl.h"
 #include "math/ldexpf.h"

diff  --git a/libc/shared/math/ilogbf.h b/libc/shared/math/ilogbf.h
new file mode 100644
index 0000000000000..c50972a0dc50a
--- /dev/null
+++ b/libc/shared/math/ilogbf.h
@@ -0,0 +1,22 @@
+//===-- Shared ilogbf 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_ILOGBF_H
+#define LLVM_LIBC_SHARED_MATH_ILOGBF_H
+
+#include "src/__support/math/ilogbf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::ilogbf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_ILOGBF_H

diff  --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 0e7a082434fb5..bf1c4463b8066 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -390,7 +390,6 @@ add_header_library(
     cosf.h
   DEPENDS
     .sincosf_utils
-    libc.src.errno.errno
     libc.src.__support.FPUtil.basic_operations
     libc.src.__support.FPUtil.fenv_impl
     libc.src.__support.FPUtil.fp_bits
@@ -660,6 +659,16 @@ add_header_library(
     libc.include.llvm-libc-macros.float16_macros
 )
 
+add_header_library(
+  ilogbf
+  HDRS
+    ilogbf.h
+  DEPENDS
+    libc.src.__support.macros.config
+    libc.src.__support.macros.properties.types
+    libc.src.__support.FPUtil.manipulation_functions
+)
+
 add_header_library(
   ldexpf128
   HDRS

diff  --git a/libc/src/__support/math/ilogbf.h b/libc/src/__support/math/ilogbf.h
new file mode 100644
index 0000000000000..dfc8f62510354
--- /dev/null
+++ b/libc/src/__support/math/ilogbf.h
@@ -0,0 +1,26 @@
+//===-- Implementation header for ilogbf ----------------------*- 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_ILOGBF_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_ILOGBF_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 constexpr int ilogbf(float x) { return fputil::intlogb<int>(x); }
+
+} // namespace math
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_ILOGBF_H

diff  --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index bf799ce41363c..b578d1805f2a8 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -1772,7 +1772,7 @@ add_entrypoint_object(
   HDRS
     ../ilogbf.h
   DEPENDS
-    libc.src.__support.FPUtil.manipulation_functions
+    libc.src.__support.math.ilogbf
 )
 
 add_entrypoint_object(

diff  --git a/libc/src/math/generic/ilogbf.cpp b/libc/src/math/generic/ilogbf.cpp
index 7da2aff3de316..0ed2cb569fd2e 100644
--- a/libc/src/math/generic/ilogbf.cpp
+++ b/libc/src/math/generic/ilogbf.cpp
@@ -7,12 +7,10 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/ilogbf.h"
-#include "src/__support/FPUtil/ManipulationFunctions.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/ilogbf.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
-LLVM_LIBC_FUNCTION(int, ilogbf, (float x)) { return fputil::intlogb<int>(x); }
+LLVM_LIBC_FUNCTION(int, ilogbf, (float x)) { return math::ilogbf(x); }
 
 } // namespace LIBC_NAMESPACE_DECL

diff  --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 3be8f992aa486..cfc2eda1aaec9 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -61,6 +61,7 @@ add_fp_unittest(
     libc.src.__support.math.fsqrt
     libc.src.__support.math.fsqrtf128
     libc.src.__support.math.hypotf
+    libc.src.__support.math.ilogbf
     libc.src.__support.math.ilogbf16
     libc.src.__support.math.ilogbl
     libc.src.__support.math.log

diff  --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 655d96692f1b8..88e6ecc98a0a7 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -78,6 +78,8 @@ TEST(LlvmLibcSharedMathTest, AllFloat) {
                             LIBC_NAMESPACE::shared::frexpf(24.0f, &exponent));
   EXPECT_EQ(exponent, 5);
 
+  EXPECT_EQ(0, LIBC_NAMESPACE::shared::ilogbf(1.0f));
+
   ASSERT_FP_EQ(float(8 << 5), LIBC_NAMESPACE::shared::ldexpf(8.0f, 5));
   ASSERT_FP_EQ(float(-1 * (8 << 5)), LIBC_NAMESPACE::shared::ldexpf(-8.0f, 5));
 

diff  --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 7251f491bc757..90b1da0e3376e 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -2881,6 +2881,16 @@ libc_support_library(
     ],
 )
 
+libc_support_library(
+    name = "__support_math_ilogbf",
+    hdrs = ["src/__support/math/ilogbf.h"],
+    deps = [
+        ":__support_common",
+        ":__support_fputil_manipulation_functions",
+        ":__support_macros_config",
+    ],
+)
+
 libc_support_library(
     name = "__support_math_ilogbl",
     hdrs = ["src/__support/math/ilogbl.h"],
@@ -4427,7 +4437,12 @@ libc_math_function(
 
 libc_math_function(name = "ilogb")
 
-libc_math_function(name = "ilogbf")
+libc_math_function(
+    name = "ilogbf",
+    additional_deps = [
+        ":__support_math_ilogbf",
+    ],
+)
 
 libc_math_function(
     name = "ilogbl",


        


More information about the libc-commits mailing list