[llvm-branch-commits] [libc] [llvm] [libc][math] Refactor cos implementation to header-only in src/__support/math folder. (PR #151883)

2025-08-04 Thread Muhammad Bassiouni via llvm-branch-commits

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

>From 14a8e8add569e7e423cfc57ecf85c722063f0835 Mon Sep 17 00:00:00 2001
From: bassiounix 
Date: Sun, 3 Aug 2025 22:24:35 +0300
Subject: [PATCH] [libc][math] Refactor cos implementation to header-only in
 src/__support/math folder.

---
 libc/shared/math.h|   1 +
 libc/shared/math/cos.h|  23 +++
 libc/src/__support/math/CMakeLists.txt|  47 +
 libc/src/__support/math/cos.h | 173 ++
 .../math}/range_reduction_double_common.h |  24 ++-
 .../math}/range_reduction_double_fma.h|  18 +-
 .../math}/range_reduction_double_nofma.h  |  16 +-
 .../generic => __support/math}/sincos_eval.h  |   8 +-
 libc/src/math/generic/CMakeLists.txt  |  50 +
 libc/src/math/generic/cos.cpp | 155 +---
 libc/src/math/generic/sin.cpp |  14 +-
 libc/src/math/generic/sincos.cpp  |  14 +-
 libc/src/math/generic/tan.cpp |   7 +-
 libc/test/shared/CMakeLists.txt   |   1 +
 libc/test/shared/shared_math_test.cpp |   3 +-
 .../llvm-project-overlay/libc/BUILD.bazel | 101 +-
 16 files changed, 377 insertions(+), 278 deletions(-)
 create mode 100644 libc/shared/math/cos.h
 create mode 100644 libc/src/__support/math/cos.h
 rename libc/src/{math/generic => 
__support/math}/range_reduction_double_common.h (97%)
 rename libc/src/{math/generic => __support/math}/range_reduction_double_fma.h 
(97%)
 rename libc/src/{math/generic => 
__support/math}/range_reduction_double_nofma.h (97%)
 rename libc/src/{math/generic => __support/math}/sincos_eval.h (98%)

diff --git a/libc/shared/math.h b/libc/shared/math.h
index ea645f0afedbc..a5581ed4272a3 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -32,6 +32,7 @@
 #include "math/atanhf16.h"
 #include "math/cbrt.h"
 #include "math/cbrtf.h"
+#include "math/cos.h"
 #include "math/erff.h"
 #include "math/exp.h"
 #include "math/exp10.h"
diff --git a/libc/shared/math/cos.h b/libc/shared/math/cos.h
new file mode 100644
index 0..c498550f098b4
--- /dev/null
+++ b/libc/shared/math/cos.h
@@ -0,0 +1,23 @@
+//===-- Shared cos 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_COS_H
+#define LLVM_LIBC_SHARED_MATH_COS_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/cos.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::cos;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_COS_H
diff --git a/libc/src/__support/math/CMakeLists.txt 
b/libc/src/__support/math/CMakeLists.txt
index fe928a8fadd5e..24844063fcd24 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -357,6 +357,24 @@ add_header_library(
 libc.src.__support.macros.optimization
 )
 
+add_header_library(
+  cos
+  HDRS
+cos.h
+  DEPENDS
+libc.src.__support.math.sincos_eval
+libc.hdr.errno_macros
+libc.src.errno.errno
+libc.src.__support.FPUtil.double_double
+libc.src.__support.FPUtil.dyadic_float
+libc.src.__support.FPUtil.except_value_utils
+libc.src.__support.FPUtil.fenv_impl
+libc.src.__support.FPUtil.fp_bits
+libc.src.__support.math.range_reduction_double
+libc.src.__support.macros.optimization
+)
+
+
 add_header_library(
   erff
   HDRS
@@ -613,3 +631,32 @@ add_header_library(
 libc.src.__support.macros.optimization
 libc.src.__support.macros.properties.cpu_features
 )
+
+add_header_library(
+  range_reduction_double
+  HDRS
+range_reduction_double_common.h
+range_reduction_double_fma.h
+range_reduction_double_nofma.h
+  DEPENDS
+libc.src.__support.FPUtil.double_double
+libc.src.__support.FPUtil.dyadic_float
+libc.src.__support.FPUtil.fp_bits
+libc.src.__support.FPUtil.fma
+libc.src.__support.FPUtil.multiply_add
+libc.src.__support.FPUtil.nearest_integer
+libc.src.__support.common
+libc.src.__support.integer_literals
+)
+
+add_header_library(
+  sincos_eval
+  HDRS
+sincos_eval.h
+  DEPENDS
+libc.src.__support.FPUtil.double_double
+libc.src.__support.FPUtil.dyadic_float
+libc.src.__support.FPUtil.multiply_add
+libc.src.__support.FPUtil.polyeval
+libc.src.__support.integer_literals
+)
diff --git a/libc/src/__support/math/cos.h b/libc/src/__support/math/cos.h
new file mode 100644
index 0..0802f9e4f6e49
--- /dev/null
+++ b/libc/src/__support/math/cos.h
@@ -0,0 +1,173 @@
+//===-- Implementation header for cos ---*- C

[llvm-branch-commits] [libc] [llvm] [libc][math] Refactor cos implementation to header-only in src/__support/math folder. (PR #151883)

2025-08-04 Thread Muhammad Bassiouni via llvm-branch-commits

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

>From 14a8e8add569e7e423cfc57ecf85c722063f0835 Mon Sep 17 00:00:00 2001
From: bassiounix 
Date: Sun, 3 Aug 2025 22:24:35 +0300
Subject: [PATCH] [libc][math] Refactor cos implementation to header-only in
 src/__support/math folder.

---
 libc/shared/math.h|   1 +
 libc/shared/math/cos.h|  23 +++
 libc/src/__support/math/CMakeLists.txt|  47 +
 libc/src/__support/math/cos.h | 173 ++
 .../math}/range_reduction_double_common.h |  24 ++-
 .../math}/range_reduction_double_fma.h|  18 +-
 .../math}/range_reduction_double_nofma.h  |  16 +-
 .../generic => __support/math}/sincos_eval.h  |   8 +-
 libc/src/math/generic/CMakeLists.txt  |  50 +
 libc/src/math/generic/cos.cpp | 155 +---
 libc/src/math/generic/sin.cpp |  14 +-
 libc/src/math/generic/sincos.cpp  |  14 +-
 libc/src/math/generic/tan.cpp |   7 +-
 libc/test/shared/CMakeLists.txt   |   1 +
 libc/test/shared/shared_math_test.cpp |   3 +-
 .../llvm-project-overlay/libc/BUILD.bazel | 101 +-
 16 files changed, 377 insertions(+), 278 deletions(-)
 create mode 100644 libc/shared/math/cos.h
 create mode 100644 libc/src/__support/math/cos.h
 rename libc/src/{math/generic => 
__support/math}/range_reduction_double_common.h (97%)
 rename libc/src/{math/generic => __support/math}/range_reduction_double_fma.h 
(97%)
 rename libc/src/{math/generic => 
__support/math}/range_reduction_double_nofma.h (97%)
 rename libc/src/{math/generic => __support/math}/sincos_eval.h (98%)

diff --git a/libc/shared/math.h b/libc/shared/math.h
index ea645f0afedbc..a5581ed4272a3 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -32,6 +32,7 @@
 #include "math/atanhf16.h"
 #include "math/cbrt.h"
 #include "math/cbrtf.h"
+#include "math/cos.h"
 #include "math/erff.h"
 #include "math/exp.h"
 #include "math/exp10.h"
diff --git a/libc/shared/math/cos.h b/libc/shared/math/cos.h
new file mode 100644
index 0..c498550f098b4
--- /dev/null
+++ b/libc/shared/math/cos.h
@@ -0,0 +1,23 @@
+//===-- Shared cos 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_COS_H
+#define LLVM_LIBC_SHARED_MATH_COS_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/cos.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::cos;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_COS_H
diff --git a/libc/src/__support/math/CMakeLists.txt 
b/libc/src/__support/math/CMakeLists.txt
index fe928a8fadd5e..24844063fcd24 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -357,6 +357,24 @@ add_header_library(
 libc.src.__support.macros.optimization
 )
 
+add_header_library(
+  cos
+  HDRS
+cos.h
+  DEPENDS
+libc.src.__support.math.sincos_eval
+libc.hdr.errno_macros
+libc.src.errno.errno
+libc.src.__support.FPUtil.double_double
+libc.src.__support.FPUtil.dyadic_float
+libc.src.__support.FPUtil.except_value_utils
+libc.src.__support.FPUtil.fenv_impl
+libc.src.__support.FPUtil.fp_bits
+libc.src.__support.math.range_reduction_double
+libc.src.__support.macros.optimization
+)
+
+
 add_header_library(
   erff
   HDRS
@@ -613,3 +631,32 @@ add_header_library(
 libc.src.__support.macros.optimization
 libc.src.__support.macros.properties.cpu_features
 )
+
+add_header_library(
+  range_reduction_double
+  HDRS
+range_reduction_double_common.h
+range_reduction_double_fma.h
+range_reduction_double_nofma.h
+  DEPENDS
+libc.src.__support.FPUtil.double_double
+libc.src.__support.FPUtil.dyadic_float
+libc.src.__support.FPUtil.fp_bits
+libc.src.__support.FPUtil.fma
+libc.src.__support.FPUtil.multiply_add
+libc.src.__support.FPUtil.nearest_integer
+libc.src.__support.common
+libc.src.__support.integer_literals
+)
+
+add_header_library(
+  sincos_eval
+  HDRS
+sincos_eval.h
+  DEPENDS
+libc.src.__support.FPUtil.double_double
+libc.src.__support.FPUtil.dyadic_float
+libc.src.__support.FPUtil.multiply_add
+libc.src.__support.FPUtil.polyeval
+libc.src.__support.integer_literals
+)
diff --git a/libc/src/__support/math/cos.h b/libc/src/__support/math/cos.h
new file mode 100644
index 0..0802f9e4f6e49
--- /dev/null
+++ b/libc/src/__support/math/cos.h
@@ -0,0 +1,173 @@
+//===-- Implementation header for cos ---*- C

[llvm-branch-commits] [libc] [llvm] [libc][math] Refactor cos implementation to header-only in src/__support/math folder. (PR #151883)

2025-08-04 Thread Muhammad Bassiouni via llvm-branch-commits

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

>From 37848d777f74c5052a8332033e51446a3f7a152f Mon Sep 17 00:00:00 2001
From: bassiounix 
Date: Sun, 3 Aug 2025 22:24:35 +0300
Subject: [PATCH] [libc][math] Refactor cos implementation to header-only in
 src/__support/math folder.

---
 libc/shared/math.h|   1 +
 libc/shared/math/cos.h|  23 +++
 libc/src/__support/math/CMakeLists.txt|  47 +
 libc/src/__support/math/cos.h | 173 ++
 .../math}/range_reduction_double_common.h |  24 ++-
 .../math}/range_reduction_double_fma.h|  18 +-
 .../math}/range_reduction_double_nofma.h  |  16 +-
 .../generic => __support/math}/sincos_eval.h  |   8 +-
 libc/src/math/generic/CMakeLists.txt  |  50 +
 libc/src/math/generic/cos.cpp | 155 +---
 libc/src/math/generic/sin.cpp |  14 +-
 libc/src/math/generic/sincos.cpp  |  14 +-
 libc/src/math/generic/tan.cpp |   7 +-
 libc/test/shared/CMakeLists.txt   |   1 +
 libc/test/shared/shared_math_test.cpp |   3 +-
 .../llvm-project-overlay/libc/BUILD.bazel | 101 +-
 16 files changed, 377 insertions(+), 278 deletions(-)
 create mode 100644 libc/shared/math/cos.h
 create mode 100644 libc/src/__support/math/cos.h
 rename libc/src/{math/generic => 
__support/math}/range_reduction_double_common.h (97%)
 rename libc/src/{math/generic => __support/math}/range_reduction_double_fma.h 
(97%)
 rename libc/src/{math/generic => 
__support/math}/range_reduction_double_nofma.h (97%)
 rename libc/src/{math/generic => __support/math}/sincos_eval.h (98%)

diff --git a/libc/shared/math.h b/libc/shared/math.h
index ea645f0afedbc..a5581ed4272a3 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -32,6 +32,7 @@
 #include "math/atanhf16.h"
 #include "math/cbrt.h"
 #include "math/cbrtf.h"
+#include "math/cos.h"
 #include "math/erff.h"
 #include "math/exp.h"
 #include "math/exp10.h"
diff --git a/libc/shared/math/cos.h b/libc/shared/math/cos.h
new file mode 100644
index 0..c498550f098b4
--- /dev/null
+++ b/libc/shared/math/cos.h
@@ -0,0 +1,23 @@
+//===-- Shared cos 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_COS_H
+#define LLVM_LIBC_SHARED_MATH_COS_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/cos.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::cos;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_COS_H
diff --git a/libc/src/__support/math/CMakeLists.txt 
b/libc/src/__support/math/CMakeLists.txt
index fe928a8fadd5e..24844063fcd24 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -357,6 +357,24 @@ add_header_library(
 libc.src.__support.macros.optimization
 )
 
+add_header_library(
+  cos
+  HDRS
+cos.h
+  DEPENDS
+libc.src.__support.math.sincos_eval
+libc.hdr.errno_macros
+libc.src.errno.errno
+libc.src.__support.FPUtil.double_double
+libc.src.__support.FPUtil.dyadic_float
+libc.src.__support.FPUtil.except_value_utils
+libc.src.__support.FPUtil.fenv_impl
+libc.src.__support.FPUtil.fp_bits
+libc.src.__support.math.range_reduction_double
+libc.src.__support.macros.optimization
+)
+
+
 add_header_library(
   erff
   HDRS
@@ -613,3 +631,32 @@ add_header_library(
 libc.src.__support.macros.optimization
 libc.src.__support.macros.properties.cpu_features
 )
+
+add_header_library(
+  range_reduction_double
+  HDRS
+range_reduction_double_common.h
+range_reduction_double_fma.h
+range_reduction_double_nofma.h
+  DEPENDS
+libc.src.__support.FPUtil.double_double
+libc.src.__support.FPUtil.dyadic_float
+libc.src.__support.FPUtil.fp_bits
+libc.src.__support.FPUtil.fma
+libc.src.__support.FPUtil.multiply_add
+libc.src.__support.FPUtil.nearest_integer
+libc.src.__support.common
+libc.src.__support.integer_literals
+)
+
+add_header_library(
+  sincos_eval
+  HDRS
+sincos_eval.h
+  DEPENDS
+libc.src.__support.FPUtil.double_double
+libc.src.__support.FPUtil.dyadic_float
+libc.src.__support.FPUtil.multiply_add
+libc.src.__support.FPUtil.polyeval
+libc.src.__support.integer_literals
+)
diff --git a/libc/src/__support/math/cos.h b/libc/src/__support/math/cos.h
new file mode 100644
index 0..0802f9e4f6e49
--- /dev/null
+++ b/libc/src/__support/math/cos.h
@@ -0,0 +1,173 @@
+//===-- Implementation header for cos ---*- C

[llvm-branch-commits] [libc] [llvm] [libc][math] Refactor cos implementation to header-only in src/__support/math folder. (PR #151883)

2025-08-03 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-libc

Author: Muhammad Bassiouni (bassiounix)


Changes

Part of #147386

in preparation for: 
https://discourse.llvm.org/t/rfc-make-clang-builtin-math-functions-constexpr-with-llvm-libc-to-support-c-23-constexpr-math-functions/86450

---

Patch is 33.10 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/151883.diff


16 Files Affected:

- (modified) libc/shared/math.h (+1) 
- (added) libc/shared/math/cos.h (+23) 
- (modified) libc/src/__support/math/CMakeLists.txt (+47) 
- (added) libc/src/__support/math/cos.h (+173) 
- (renamed) libc/src/__support/math/range_reduction_double_common.h (+14-4) 
- (renamed) libc/src/__support/math/range_reduction_double_fma.h (+9-1) 
- (renamed) libc/src/__support/math/range_reduction_double_nofma.h (+9-1) 
- (renamed) libc/src/__support/math/sincos_eval.h (+6-2) 
- (modified) libc/src/math/generic/CMakeLists.txt (+6-44) 
- (modified) libc/src/math/generic/cos.cpp (+2-153) 
- (modified) libc/src/math/generic/sin.cpp (+8-6) 
- (modified) libc/src/math/generic/sincos.cpp (+8-6) 
- (modified) libc/src/math/generic/tan.cpp (+4-3) 
- (modified) libc/test/shared/CMakeLists.txt (+1) 
- (modified) libc/test/shared/shared_math_test.cpp (+2-1) 
- (modified) utils/bazel/llvm-project-overlay/libc/BUILD.bazel (+55-46) 


``diff
diff --git a/libc/shared/math.h b/libc/shared/math.h
index ea645f0afedbc..a5581ed4272a3 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -32,6 +32,7 @@
 #include "math/atanhf16.h"
 #include "math/cbrt.h"
 #include "math/cbrtf.h"
+#include "math/cos.h"
 #include "math/erff.h"
 #include "math/exp.h"
 #include "math/exp10.h"
diff --git a/libc/shared/math/cos.h b/libc/shared/math/cos.h
new file mode 100644
index 0..c498550f098b4
--- /dev/null
+++ b/libc/shared/math/cos.h
@@ -0,0 +1,23 @@
+//===-- Shared cos 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_COS_H
+#define LLVM_LIBC_SHARED_MATH_COS_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/cos.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::cos;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_COS_H
diff --git a/libc/src/__support/math/CMakeLists.txt 
b/libc/src/__support/math/CMakeLists.txt
index fe928a8fadd5e..24844063fcd24 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -357,6 +357,24 @@ add_header_library(
 libc.src.__support.macros.optimization
 )
 
+add_header_library(
+  cos
+  HDRS
+cos.h
+  DEPENDS
+libc.src.__support.math.sincos_eval
+libc.hdr.errno_macros
+libc.src.errno.errno
+libc.src.__support.FPUtil.double_double
+libc.src.__support.FPUtil.dyadic_float
+libc.src.__support.FPUtil.except_value_utils
+libc.src.__support.FPUtil.fenv_impl
+libc.src.__support.FPUtil.fp_bits
+libc.src.__support.math.range_reduction_double
+libc.src.__support.macros.optimization
+)
+
+
 add_header_library(
   erff
   HDRS
@@ -613,3 +631,32 @@ add_header_library(
 libc.src.__support.macros.optimization
 libc.src.__support.macros.properties.cpu_features
 )
+
+add_header_library(
+  range_reduction_double
+  HDRS
+range_reduction_double_common.h
+range_reduction_double_fma.h
+range_reduction_double_nofma.h
+  DEPENDS
+libc.src.__support.FPUtil.double_double
+libc.src.__support.FPUtil.dyadic_float
+libc.src.__support.FPUtil.fp_bits
+libc.src.__support.FPUtil.fma
+libc.src.__support.FPUtil.multiply_add
+libc.src.__support.FPUtil.nearest_integer
+libc.src.__support.common
+libc.src.__support.integer_literals
+)
+
+add_header_library(
+  sincos_eval
+  HDRS
+sincos_eval.h
+  DEPENDS
+libc.src.__support.FPUtil.double_double
+libc.src.__support.FPUtil.dyadic_float
+libc.src.__support.FPUtil.multiply_add
+libc.src.__support.FPUtil.polyeval
+libc.src.__support.integer_literals
+)
diff --git a/libc/src/__support/math/cos.h b/libc/src/__support/math/cos.h
new file mode 100644
index 0..0802f9e4f6e49
--- /dev/null
+++ b/libc/src/__support/math/cos.h
@@ -0,0 +1,173 @@
+//===-- Implementation header for cos ---*- 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 LIBC_SRC___SUPPORT_MATH_COS_H
+#define LIBC_SRC___SUPPORT_MATH_COS_H
+

[llvm-branch-commits] [libc] [llvm] [libc][math] Refactor cos implementation to header-only in src/__support/math folder. (PR #151883)

2025-08-03 Thread Muhammad Bassiouni via llvm-branch-commits

https://github.com/bassiounix edited 
https://github.com/llvm/llvm-project/pull/151883
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libc] [llvm] [libc][math] Refactor cos implementation to header-only in src/__support/math folder. (PR #151883)

2025-08-03 Thread Muhammad Bassiouni via llvm-branch-commits

bassiounix wrote:

> [!WARNING]
> This pull request is not mergeable via GitHub because a downstack PR is 
> open. Once all requirements are satisfied, merge this PR as a stack  href="https://app.graphite.dev/github/pr/llvm/llvm-project/151883?utm_source=stack-comment-downstack-mergeability-warning";
>  >on Graphite.
> https://graphite.dev/docs/merge-pull-requests";>Learn more

* **#151883** https://app.graphite.dev/github/pr/llvm/llvm-project/151883?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/151883?utm_source=stack-comment-view-in-graphite";
 target="_blank">(View in Graphite)
* **#151846** https://app.graphite.dev/github/pr/llvm/llvm-project/151846?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#151837** https://app.graphite.dev/github/pr/llvm/llvm-project/151837?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#151779** https://app.graphite.dev/github/pr/llvm/llvm-project/151779?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#151399** https://app.graphite.dev/github/pr/llvm/llvm-project/151399?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#151012** https://app.graphite.dev/github/pr/llvm/llvm-project/151012?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#150993** https://app.graphite.dev/github/pr/llvm/llvm-project/150993?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#150968** https://app.graphite.dev/github/pr/llvm/llvm-project/150968?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#150868** https://app.graphite.dev/github/pr/llvm/llvm-project/150868?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#150854** https://app.graphite.dev/github/pr/llvm/llvm-project/150854?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#150852** https://app.graphite.dev/github/pr/llvm/llvm-project/150852?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#150849** https://app.graphite.dev/github/pr/llvm/llvm-project/150849?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#150843** https://app.graphite.dev/github/pr/llvm/llvm-project/150843?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* `main`




This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn 
more about https://stacking.dev/?utm_source=stack-comment";>stacking.


https://github.com/llvm/llvm-project/pull/151883
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libc] [llvm] [libc][math] Refactor cos implementation to header-only in src/__support/math folder. (PR #151883)

2025-08-03 Thread Muhammad Bassiouni via llvm-branch-commits

https://github.com/bassiounix ready_for_review 
https://github.com/llvm/llvm-project/pull/151883
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libc] [llvm] [libc][math] Refactor cos implementation to header-only in src/__support/math folder. (PR #151883)

2025-08-03 Thread Muhammad Bassiouni via llvm-branch-commits

https://github.com/bassiounix created 
https://github.com/llvm/llvm-project/pull/151883

None

>From a9b861153d10cc62444d1d893a23d0292848937e Mon Sep 17 00:00:00 2001
From: bassiounix 
Date: Sun, 3 Aug 2025 22:24:35 +0300
Subject: [PATCH] [libc][math] Refactor cos implementation to header-only in
 src/__support/math folder.

---
 libc/shared/math.h|   1 +
 libc/shared/math/cos.h|  23 +++
 libc/src/__support/math/CMakeLists.txt|  47 +
 libc/src/__support/math/cos.h | 173 ++
 .../math}/range_reduction_double_common.h |  18 +-
 .../math}/range_reduction_double_fma.h|  10 +-
 .../math}/range_reduction_double_nofma.h  |  10 +-
 .../generic => __support/math}/sincos_eval.h  |   8 +-
 libc/src/math/generic/CMakeLists.txt  |  50 +
 libc/src/math/generic/cos.cpp | 155 +---
 libc/src/math/generic/sin.cpp |  14 +-
 libc/src/math/generic/sincos.cpp  |  14 +-
 libc/src/math/generic/tan.cpp |   7 +-
 libc/test/shared/CMakeLists.txt   |   1 +
 libc/test/shared/shared_math_test.cpp |   3 +-
 .../llvm-project-overlay/libc/BUILD.bazel | 101 +-
 16 files changed, 368 insertions(+), 267 deletions(-)
 create mode 100644 libc/shared/math/cos.h
 create mode 100644 libc/src/__support/math/cos.h
 rename libc/src/{math/generic => 
__support/math}/range_reduction_double_common.h (98%)
 rename libc/src/{math/generic => __support/math}/range_reduction_double_fma.h 
(98%)
 rename libc/src/{math/generic => 
__support/math}/range_reduction_double_nofma.h (98%)
 rename libc/src/{math/generic => __support/math}/sincos_eval.h (98%)

diff --git a/libc/shared/math.h b/libc/shared/math.h
index ea645f0afedbc..a5581ed4272a3 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -32,6 +32,7 @@
 #include "math/atanhf16.h"
 #include "math/cbrt.h"
 #include "math/cbrtf.h"
+#include "math/cos.h"
 #include "math/erff.h"
 #include "math/exp.h"
 #include "math/exp10.h"
diff --git a/libc/shared/math/cos.h b/libc/shared/math/cos.h
new file mode 100644
index 0..c498550f098b4
--- /dev/null
+++ b/libc/shared/math/cos.h
@@ -0,0 +1,23 @@
+//===-- Shared cos 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_COS_H
+#define LLVM_LIBC_SHARED_MATH_COS_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/cos.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::cos;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_COS_H
diff --git a/libc/src/__support/math/CMakeLists.txt 
b/libc/src/__support/math/CMakeLists.txt
index fe928a8fadd5e..24844063fcd24 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -357,6 +357,24 @@ add_header_library(
 libc.src.__support.macros.optimization
 )
 
+add_header_library(
+  cos
+  HDRS
+cos.h
+  DEPENDS
+libc.src.__support.math.sincos_eval
+libc.hdr.errno_macros
+libc.src.errno.errno
+libc.src.__support.FPUtil.double_double
+libc.src.__support.FPUtil.dyadic_float
+libc.src.__support.FPUtil.except_value_utils
+libc.src.__support.FPUtil.fenv_impl
+libc.src.__support.FPUtil.fp_bits
+libc.src.__support.math.range_reduction_double
+libc.src.__support.macros.optimization
+)
+
+
 add_header_library(
   erff
   HDRS
@@ -613,3 +631,32 @@ add_header_library(
 libc.src.__support.macros.optimization
 libc.src.__support.macros.properties.cpu_features
 )
+
+add_header_library(
+  range_reduction_double
+  HDRS
+range_reduction_double_common.h
+range_reduction_double_fma.h
+range_reduction_double_nofma.h
+  DEPENDS
+libc.src.__support.FPUtil.double_double
+libc.src.__support.FPUtil.dyadic_float
+libc.src.__support.FPUtil.fp_bits
+libc.src.__support.FPUtil.fma
+libc.src.__support.FPUtil.multiply_add
+libc.src.__support.FPUtil.nearest_integer
+libc.src.__support.common
+libc.src.__support.integer_literals
+)
+
+add_header_library(
+  sincos_eval
+  HDRS
+sincos_eval.h
+  DEPENDS
+libc.src.__support.FPUtil.double_double
+libc.src.__support.FPUtil.dyadic_float
+libc.src.__support.FPUtil.multiply_add
+libc.src.__support.FPUtil.polyeval
+libc.src.__support.integer_literals
+)
diff --git a/libc/src/__support/math/cos.h b/libc/src/__support/math/cos.h
new file mode 100644
index 0..0802f9e4f6e49
--- /dev/null
+++ b/libc/src/__support/math/cos.h
@@ -0,0 +1,173 @@
+//===-- Implementation header for cos --