[libc-commits] [libc] [libc][math] Fix GPU build fails (PR #175474)

Muhammad Bassiouni via libc-commits libc-commits at lists.llvm.org
Sun Jan 11 17:23:20 PST 2026


https://github.com/bassiounix updated https://github.com/llvm/llvm-project/pull/175474

>From 0372504217ddc737fff9ff459a620b6cf8fb4ef4 Mon Sep 17 00:00:00 2001
From: bassiounix <muhammad.m.bassiouni at gmail.com>
Date: Mon, 12 Jan 2026 03:08:06 +0200
Subject: [PATCH 1/2] [libc][math] Fix GPU build fails

---
 libc/src/__support/math/CMakeLists.txt | 6 +++---
 libc/src/__support/math/log.h          | 5 ++---
 libc/src/math/generic/log10.cpp        | 3 +--
 libc/src/math/generic/log2.cpp         | 3 +--
 4 files changed, 7 insertions(+), 10 deletions(-)

diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index e46d83e6e2754..7219800a3e9d2 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -1026,11 +1026,12 @@ add_header_library(
 )
 
 add_header_library(
-  log 
+  log
   HDRS
     log.h
   DEPENDS
     .log_range_reduction
+    .common_constants
     libc.src.__support.FPUtil.double_double
     libc.src.__support.FPUtil.dyadic_float
     libc.src.__support.FPUtil.fenv_impl
@@ -1039,7 +1040,6 @@ add_header_library(
     libc.src.__support.FPUtil.polyeval
     libc.src.__support.integer_literals
     libc.src.__support.macros.optimization
-    libc.src.__support.math.common_constants
 )
 
 add_header_library(
@@ -1047,7 +1047,7 @@ add_header_library(
   HDRS
     log_range_reduction.h
   DEPENDS
-    libc.src.__support.fputil.dyadic_float
+    libc.src.__support.FPUtil.dyadic_float
     libc.src.__support.math.common_constants
     libc.src.__support.uint128
 )
diff --git a/libc/src/__support/math/log.h b/libc/src/__support/math/log.h
index 97d64378d99ef..7640e6a5707c1 100644
--- a/libc/src/__support/math/log.h
+++ b/libc/src/__support/math/log.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_LIBC_SRC___SUPPORT_MATH_LOG_H
 #define LLVM_LIBC_SRC___SUPPORT_MATH_LOG_H
 
+#include "common_constants.h"
 #include "log_range_reduction.h"
 #include "src/__support/FPUtil/FEnvImpl.h"
 #include "src/__support/FPUtil/FPBits.h"
@@ -20,7 +21,6 @@
 #include "src/__support/integer_literals.h"
 #include "src/__support/macros/config.h"
 #include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
-#include "src/__support/math/common_constants.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
@@ -32,6 +32,7 @@ using Float128 = typename fputil::DyadicFloat<128>;
 using LIBC_NAMESPACE::operator""_u128;
 
 using namespace common_constants_internal;
+using namespace log_range_reduction_internal;
 
 #ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
 // A simple upper bound for the error of e_x * log(2) - log(r).
@@ -52,8 +53,6 @@ LIBC_INLINE_VAR constexpr Float128
     LOG_2(Sign::POS, /*exponent=*/-128, /*mantissa=*/
           0xb17217f7'd1cf79ab'c9e3b398'03f2f6af_u128);
 
-using math::log_range_reduction_internal::LogRR;
-
 alignas(16) LIBC_INLINE_VAR constexpr LogRR LOG_TABLE = {
     // -log(r) with 128-bit precision generated by SageMath with:
     // for i in range(128):
diff --git a/libc/src/math/generic/log10.cpp b/libc/src/math/generic/log10.cpp
index 600d6ed7b551c..60c057d8057a7 100644
--- a/libc/src/math/generic/log10.cpp
+++ b/libc/src/math/generic/log10.cpp
@@ -31,6 +31,7 @@ using LIBC_NAMESPACE::operator""_u128;
 namespace {
 
 using namespace common_constants_internal;
+using namespace math::log_range_reduction_internal;
 
 constexpr fputil::DoubleDouble LOG10_E = {0x1.95355baaafad3p-57,
                                           0x1.bcb7b1526e50ep-2};
@@ -53,8 +54,6 @@ constexpr double P_ERR = 0x1.0p-51;
 constexpr Float128 LOG10_2(Sign::POS, /*exponent=*/-129, /*mantissa=*/
                            0x9a209a84'fbcff798'8f8959ac'0b7c9178_u128);
 
-using math::log_range_reduction_internal::LogRR;
-
 alignas(16) constexpr LogRR LOG10_TABLE = {
     // -log10(r) with 128-bit precision generated by SageMath with:
     //
diff --git a/libc/src/math/generic/log2.cpp b/libc/src/math/generic/log2.cpp
index d902886338da8..ae7a6588e8c70 100644
--- a/libc/src/math/generic/log2.cpp
+++ b/libc/src/math/generic/log2.cpp
@@ -31,6 +31,7 @@ using LIBC_NAMESPACE::operator""_u128;
 namespace {
 
 using namespace common_constants_internal;
+using namespace math::log_range_reduction_internal;
 
 constexpr fputil::DoubleDouble LOG2_E = {0x1.777d0ffda0d24p-56,
                                          0x1.71547652b82fep0};
@@ -170,8 +171,6 @@ alignas(16) const fputil::DoubleDouble LOG_R1[128] = {
 // Extra errors from P is from using x^2 to reduce evaluation latency.
 constexpr double P_ERR = 0x1.0p-49;
 
-using math::log_range_reduction_internal::LogRR;
-
 alignas(16) constexpr LogRR LOG2_TABLE = {
     // -log2(r) with 128-bit precision generated by SageMath with:
     // def format_hex(value):

>From a70e6bd265ba64df30d355c7ec9ff54ff65edd03 Mon Sep 17 00:00:00 2001
From: bassiounix <muhammad.m.bassiouni at gmail.com>
Date: Mon, 12 Jan 2026 03:23:51 +0200
Subject: [PATCH 2/2] add new line

---
 libc/shared/math/log.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libc/shared/math/log.h b/libc/shared/math/log.h
index ca940512ab552..9bcfa3722aea9 100644
--- a/libc/shared/math/log.h
+++ b/libc/shared/math/log.h
@@ -19,4 +19,4 @@ using math::log;
 
 } // namespace LIBC_NAMESPACE_DECL
 
-#endif // LLVM_LIBC_SHARED_MATH_LOG_H
\ No newline at end of file
+#endif // LLVM_LIBC_SHARED_MATH_LOG_H



More information about the libc-commits mailing list