[libc-commits] [libc] [llvm] [libc][math] Refactor llogbf128 to header-only (PR #175617)

via libc-commits libc-commits at lists.llvm.org
Tue Jan 27 02:57:23 PST 2026


https://github.com/Abdelrhmansersawy updated https://github.com/llvm/llvm-project/pull/175617

>From d06d57498e38d795fd3deed18cb126e17c83e183 Mon Sep 17 00:00:00 2001
From: abdelrhmansersawy <abdelrhmansersawy at gmail.com>
Date: Mon, 12 Jan 2026 20:16:52 +0200
Subject: [PATCH] [libc][math] Refactor llogbf128 to header-only

---
 libc/shared/math.h                            |  1 +
 libc/shared/math/llogbf128.h                  | 29 ++++++++++++++++
 libc/src/__support/math/CMakeLists.txt        | 10 ++++++
 libc/src/__support/math/Untitled              |  2 ++
 libc/src/__support/math/llogbf128.h           | 34 +++++++++++++++++++
 libc/src/math/generic/CMakeLists.txt          |  3 +-
 libc/src/math/generic/llogbf128.cpp           |  9 ++---
 libc/test/shared/CMakeLists.txt               |  1 +
 libc/test/shared/shared_math_test.cpp         |  2 ++
 .../llvm-project-overlay/libc/BUILD.bazel     | 17 +++++++++-
 10 files changed, 99 insertions(+), 9 deletions(-)
 create mode 100644 libc/shared/math/llogbf128.h
 create mode 100644 libc/src/__support/math/Untitled
 create mode 100644 libc/src/__support/math/llogbf128.h

diff --git a/libc/shared/math.h b/libc/shared/math.h
index 7b2a12ac2bfaa..a8d51e5fbdcf2 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -77,6 +77,7 @@
 #include "math/ldexpf16.h"
 #include "math/llogb.h"
 #include "math/llogbf.h"
+#include "math/llogbf128.h"
 #include "math/log.h"
 #include "math/log10.h"
 #include "math/log1p.h"
diff --git a/libc/shared/math/llogbf128.h b/libc/shared/math/llogbf128.h
new file mode 100644
index 0000000000000..46529c8b07fec
--- /dev/null
+++ b/libc/shared/math/llogbf128.h
@@ -0,0 +1,29 @@
+//===-- Shared llogbf128 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_LLOGBF128_H
+#define LLVM_LIBC_SHARED_MATH_LLOGBF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "shared/libc_common.h"
+#include "src/__support/math/llogbf128.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::llogbf128;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_MATH_LLOGBF128_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index c0efa3dfc9c25..9004edf3d1313 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -708,6 +708,16 @@ add_header_library(
     libc.include.llvm-libc-types.float128
 )
 
+add_header_library(
+  llogbf128
+  HDRS
+    llogbf128.h
+  DEPENDS
+    libc.src.__support.macros.config
+    libc.src.__support.FPUtil.manipulation_functions
+    libc.include.llvm-libc-types.float128
+)
+
 add_header_library(
   ldexpf16
   HDRS
diff --git a/libc/src/__support/math/Untitled b/libc/src/__support/math/Untitled
new file mode 100644
index 0000000000000..2e1961daefca8
--- /dev/null
+++ b/libc/src/__support/math/Untitled
@@ -0,0 +1,2 @@
+    llogbf128.h
+
diff --git a/libc/src/__support/math/llogbf128.h b/libc/src/__support/math/llogbf128.h
new file mode 100644
index 0000000000000..5168647f49c02
--- /dev/null
+++ b/libc/src/__support/math/llogbf128.h
@@ -0,0 +1,34 @@
+//===-- Implementation header for llogbf128 ---------------------*- 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_LLOGBF128_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_LLOGBF128_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 long llogbf128(float128 x) {
+  return fputil::intlogb<long>(x);
+}
+
+} // namespace math
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_LLOGBF128_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index f369206c39a16..b9e9ed9bb01bd 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -1843,8 +1843,7 @@ add_entrypoint_object(
   HDRS
     ../llogbf128.h
   DEPENDS
-    libc.src.__support.macros.properties.types
-    libc.src.__support.FPUtil.manipulation_functions
+    libc.src.__support.math.llogbf128
 )
 
 add_entrypoint_object(
diff --git a/libc/src/math/generic/llogbf128.cpp b/libc/src/math/generic/llogbf128.cpp
index 9106731d3415a..611b84923f5ee 100644
--- a/libc/src/math/generic/llogbf128.cpp
+++ b/libc/src/math/generic/llogbf128.cpp
@@ -7,14 +7,11 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/llogbf128.h"
-#include "src/__support/FPUtil/ManipulationFunctions.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+
+#include "src/__support/math/llogbf128.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
-LLVM_LIBC_FUNCTION(long, llogbf128, (float128 x)) {
-  return fputil::intlogb<long>(x);
-}
+LLVM_LIBC_FUNCTION(long, llogbf128, (float128 x)) { return math::llogbf128(x); }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 0a19dfd9dbba9..9a160b70a30b4 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -82,6 +82,7 @@ add_fp_unittest(
     libc.src.__support.math.ldexpf128
     libc.src.__support.math.ldexpf16
     libc.src.__support.math.llogbf
+    libc.src.__support.math.llogbf128
     libc.src.__support.math.rsqrtf
     libc.src.__support.math.rsqrtf16
     libc.src.__support.math.sin
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index da1c62520042d..2d7433d391d6b 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -145,6 +145,8 @@ TEST(LlvmLibcSharedMathTest, AllFloat128) {
   EXPECT_FP_EQ(float128(0.0), LIBC_NAMESPACE::shared::logbf128(float128(1.0)));
   EXPECT_FP_EQ(0.0, LIBC_NAMESPACE::shared::dfmaf128(
                         float128(0.0), float128(0.0), float128(0.0)));
+
+  EXPECT_EQ(0L, LIBC_NAMESPACE::shared::llogbf128(float128(1.0)));
 }
 
 #endif // 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 9d6641a5847f1..1c3bf378a19ba 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -3004,6 +3004,16 @@ libc_support_library(
     ],
 )
 
+libc_support_library(
+    name = "__support_math_llogbf128",
+    hdrs = ["src/__support/math/llogbf128.h"],
+    deps = [
+        ":__support_fputil_manipulation_functions",
+        ":__support_macros_config",
+        ":llvm_libc_types_float128",
+    ],
+)
+
 libc_support_library(
     name = "__support_math_ldexpf16",
     hdrs = ["src/__support/math/ldexpf16.h"],
@@ -4759,7 +4769,12 @@ libc_math_function(
 
 libc_math_function(name = "llogbl")
 
-libc_math_function(name = "llogbf128")
+libc_math_function(
+    name = "llogbf128",
+    additional_deps = [
+        ":__support_math_llogbf128",
+    ],
+)
 
 libc_math_function(name = "llogbf16")
 



More information about the libc-commits mailing list