[libc-commits] [libc] [llvm] [libc][math] Fix LIBC_MATH_HAS_SMALL_TABLES check in sin.cpp and cos.cpp (PR #240076)

via libc-commits libc-commits at lists.llvm.org
Sat Nov 7 16:57:47 PST 2026


https://github.com/lntue created https://github.com/llvm/llvm-project/pull/240076

None

>From 74bb104f901489ac6cbf5b42aae54aa7d4024952 Mon Sep 17 00:00:00 2001
From: Tue Ly <lntue.h at gmail.com>
Date: Sat, 7 Nov 2026 23:08:08 +0000
Subject: [PATCH] [libc][math] Fix LIBC_MATH_HAS_SMALL_TABLES check in sin.cpp
 and cos.cpp.

`LIBC_MATH_SMALL_TABLES` is an unconditionally defined flag constant (`0x02`),
whereas `LIBC_MATH_HAS_SMALL_TABLES` is the feature macro defined only when
`((LIBC_MATH) & LIBC_MATH_SMALL_TABLES)` is non-zero.

Check `defined(LIBC_MATH_HAS_SMALL_TABLES)` in `sin.cpp` and `cos.cpp` so that
`math::integer_only::{sin,cos}` are selected only when small tables are enabled,
and add the missing `optimization.h` / `cpu_features.h` includes and build
dependencies.
---
 libc/src/math/generic/CMakeLists.txt              | 2 ++
 libc/src/math/generic/cos.cpp                     | 4 +++-
 libc/src/math/generic/sin.cpp                     | 2 +-
 utils/bazel/llvm-project-overlay/libc/BUILD.bazel | 1 +
 4 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 1d628e75ecd80..ac2da02e814ac 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -306,6 +306,7 @@ add_entrypoint_object(
   HDRS
     ../cos.h
   DEPENDS
+    libc.src.__support.macros.optimization
     libc.src.__support.macros.properties.cpu_features
     libc.src.__support.math.cos
     libc.src.__support.math.cos_integer_eval
@@ -358,6 +359,7 @@ add_entrypoint_object(
   HDRS
     ../sin.h
   DEPENDS
+    libc.src.__support.macros.optimization
     libc.src.__support.macros.properties.cpu_features
     libc.src.__support.math.sin
     libc.src.__support.math.sin_integer_eval
diff --git a/libc/src/math/generic/cos.cpp b/libc/src/math/generic/cos.cpp
index 469ceadd035c6..3f319bb029678 100644
--- a/libc/src/math/generic/cos.cpp
+++ b/libc/src/math/generic/cos.cpp
@@ -7,6 +7,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/cos.h"
+#include "src/__support/macros/optimization.h"
+#include "src/__support/macros/properties/cpu_features.h"
 #include "src/__support/math/cos.h"
 #include "src/__support/math/cos_integer_eval.h"
 
@@ -14,7 +16,7 @@ namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(double, cos, (double x)) {
 #if defined(LIBC_MATH_HAS_SKIP_ACCURATE_PASS) &&                               \
-    defined(LIBC_MATH_SMALL_TABLES) &&                                         \
+    defined(LIBC_MATH_HAS_SMALL_TABLES) &&                                     \
     !defined(LIBC_TARGET_CPU_HAS_FPU_DOUBLE)
   return math::integer_only::cos(x);
 #else
diff --git a/libc/src/math/generic/sin.cpp b/libc/src/math/generic/sin.cpp
index 39e297efde46c..a20a0265b01e5 100644
--- a/libc/src/math/generic/sin.cpp
+++ b/libc/src/math/generic/sin.cpp
@@ -16,7 +16,7 @@ namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(double, sin, (double x)) {
 #if defined(LIBC_MATH_HAS_SKIP_ACCURATE_PASS) &&                               \
-    defined(LIBC_MATH_SMALL_TABLES) &&                                         \
+    defined(LIBC_MATH_HAS_SMALL_TABLES) &&                                     \
     !defined(LIBC_TARGET_CPU_HAS_FPU_DOUBLE)
   return math::integer_only::sin(x);
 #else
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 89c312fa4fe87..722b4fcd4b7dd 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -13956,6 +13956,7 @@ libc_math_function(
 libc_math_function(
     name = "cos",
     additional_deps = [
+        ":__support_macros_optimization",
         ":__support_macros_properties_cpu_features",
         ":__support_math_cos",
         ":__support_math_cos_integer_eval",



More information about the libc-commits mailing list