[libc][math][c23] implement C23 acospif math function#183661
Merged
Conversation
Member
|
@llvm/pr-subscribers-libc @llvm/pr-subscribers-backend-amdgpu Author: Mohamed Emad (hulxv) ChangesImplementing C23 Patch is 29.14 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/183661.diff 30 Files Affected:
diff --git a/libc/config/baremetal/aarch64/entrypoints.txt b/libc/config/baremetal/aarch64/entrypoints.txt
index 582e7c52726fe..1c04ee2b6d040 100644
--- a/libc/config/baremetal/aarch64/entrypoints.txt
+++ b/libc/config/baremetal/aarch64/entrypoints.txt
@@ -336,6 +336,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.acos
libc.src.math.acosf
libc.src.math.acoshf
+ libc.src.math.acospif
libc.src.math.asin
libc.src.math.asinf
libc.src.math.asinhf
diff --git a/libc/config/baremetal/arm/entrypoints.txt b/libc/config/baremetal/arm/entrypoints.txt
index 98374e6cede73..ad6b6d922b57a 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -339,6 +339,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.acos
libc.src.math.acosf
libc.src.math.acoshf
+ libc.src.math.acospif
libc.src.math.asin
libc.src.math.asinf
libc.src.math.asinhf
diff --git a/libc/config/baremetal/riscv/entrypoints.txt b/libc/config/baremetal/riscv/entrypoints.txt
index b45b388ec9634..29be47dfbfd53 100644
--- a/libc/config/baremetal/riscv/entrypoints.txt
+++ b/libc/config/baremetal/riscv/entrypoints.txt
@@ -338,6 +338,7 @@ set(TARGET_LIBM_ENTRYPOINTS
# math.h entrypoints
libc.src.math.acosf
libc.src.math.acoshf
+ libc.src.math.acospif
libc.src.math.asinf
libc.src.math.asinhf
libc.src.math.asinpif
diff --git a/libc/config/darwin/aarch64/entrypoints.txt b/libc/config/darwin/aarch64/entrypoints.txt
index 5488bf1d0c7de..b4a1ee70764cb 100644
--- a/libc/config/darwin/aarch64/entrypoints.txt
+++ b/libc/config/darwin/aarch64/entrypoints.txt
@@ -153,6 +153,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.acos
libc.src.math.acosf
libc.src.math.acoshf
+ libc.src.math.acospif
libc.src.math.asin
libc.src.math.asinf
libc.src.math.asinhf
diff --git a/libc/config/gpu/amdgpu/entrypoints.txt b/libc/config/gpu/amdgpu/entrypoints.txt
index 856bf1d55f3be..a65b6f0274fd8 100644
--- a/libc/config/gpu/amdgpu/entrypoints.txt
+++ b/libc/config/gpu/amdgpu/entrypoints.txt
@@ -283,6 +283,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.acos
libc.src.math.acosf
libc.src.math.acoshf
+ libc.src.math.acospif
libc.src.math.asin
libc.src.math.asinf
libc.src.math.asinhf
diff --git a/libc/config/gpu/nvptx/entrypoints.txt b/libc/config/gpu/nvptx/entrypoints.txt
index 8765cf189f325..fee0038c88cc0 100644
--- a/libc/config/gpu/nvptx/entrypoints.txt
+++ b/libc/config/gpu/nvptx/entrypoints.txt
@@ -283,6 +283,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.acos
libc.src.math.acosf
libc.src.math.acoshf
+ libc.src.math.acospif
libc.src.math.asin
libc.src.math.asinf
libc.src.math.asinhf
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index d27dabaff5c19..960958b7cf90a 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -423,6 +423,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.acos
libc.src.math.acosf
libc.src.math.acoshf
+ libc.src.math.acospif
libc.src.math.asin
libc.src.math.asinf
libc.src.math.asinhf
diff --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt
index 714bd024dad1c..e76bf81670ce5 100644
--- a/libc/config/linux/arm/entrypoints.txt
+++ b/libc/config/linux/arm/entrypoints.txt
@@ -253,6 +253,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.acos
libc.src.math.acosf
libc.src.math.acoshf
+ libc.src.math.acospif
libc.src.math.asin
libc.src.math.asinf
libc.src.math.asinhf
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index b823e1b25e6cc..a69d1a1b0a642 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -427,6 +427,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.acos
libc.src.math.acosf
libc.src.math.acoshf
+ libc.src.math.acospif
libc.src.math.asin
libc.src.math.asinf
libc.src.math.asinhf
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index f1b3e90cfd031..bb4973628d588 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -469,6 +469,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.acos
libc.src.math.acosf
libc.src.math.acoshf
+ libc.src.math.acospif
libc.src.math.asin
libc.src.math.asinf
libc.src.math.asinhf
diff --git a/libc/config/windows/entrypoints.txt b/libc/config/windows/entrypoints.txt
index d88a49c9850ee..f777fc6c94bc2 100644
--- a/libc/config/windows/entrypoints.txt
+++ b/libc/config/windows/entrypoints.txt
@@ -133,9 +133,9 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.acos
libc.src.math.acosf
libc.src.math.acoshf
+ libc.src.math.acospif
libc.src.math.asin
libc.src.math.asinf
- libc.src.math.asinpif
libc.src.math.asinhf
libc.src.math.asinpif
libc.src.math.atan2
diff --git a/libc/shared/math/acospif.h b/libc/shared/math/acospif.h
new file mode 100644
index 0000000000000..79a2ef697a85d
--- /dev/null
+++ b/libc/shared/math/acospif.h
@@ -0,0 +1,23 @@
+//===-- Shared acospif header -----------------------------------*- 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_ACOSPIF_H
+#define LLVM_LIBC_SHARED_MATH_ACOSPIF_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/acospif.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::acospif;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_ACOSPIF_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 75a55c2939e19..505ba8b80709f 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -94,6 +94,23 @@ add_header_library(
libc.src.__support.macros.optimization
)
+
+add_header_library(
+ acospif
+ HDRS
+ acospif.h
+ DEPENDS
+ .inv_trigf_utils
+ libc.src.__support.FPUtil.except_value_utils
+ libc.src.__support.FPUtil.fp_bits
+ libc.src.__support.FPUtil.multiply_add
+ libc.src.__support.FPUtil.polyeval
+ libc.src.__support.FPUtil.sqrt
+ libc.src.__support.macros.optimization
+)
+
+
+
add_header_library(
acospif16
HDRS
@@ -177,12 +194,11 @@ add_header_library(
HDRS
asinpif.h
DEPENDS
- libc.src.__support.FPUtil.fenv_impl
- libc.src.__support.FPUtil.fp_bits
- libc.src.__support.FPUtil.polyeval
- libc.src.__support.FPUtil.cast
+ .inv_trigf_utils
libc.src.__support.FPUtil.except_value_utils
+ libc.src.__support.FPUtil.fp_bits
libc.src.__support.FPUtil.multiply_add
+ libc.src.__support.FPUtil.polyeval
libc.src.__support.FPUtil.sqrt
libc.src.__support.macros.optimization
)
diff --git a/libc/src/__support/math/acospif.h b/libc/src/__support/math/acospif.h
new file mode 100644
index 0000000000000..8fe0c3c232f45
--- /dev/null
+++ b/libc/src/__support/math/acospif.h
@@ -0,0 +1,114 @@
+//===-- Implementation header for acospif -----------------------*- 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_ACOSPIF_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_ACOSPIF_H
+
+#include "inv_trigf_utils.h"
+#include "src/__support/FPUtil/FEnvImpl.h"
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/FPUtil/PolyEval.h"
+#include "src/__support/FPUtil/cast.h"
+#include "src/__support/FPUtil/except_value_utils.h"
+#include "src/__support/FPUtil/multiply_add.h"
+#include "src/__support/FPUtil/sqrt.h"
+#include "src/__support/macros/optimization.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE float acospif(float x) {
+#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+ constexpr size_t N_EXCEPTS = 0;
+ constexpr fputil::ExceptValues<float, N_EXCEPTS> ACOSPIF_EXCEPTS = {{
+ // (inputs, RZ output, RU offset, RD offset, RN offset)
+ }};
+#endif // !LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+
+ using FPBits = fputil::FPBits<float>;
+
+ FPBits xbits(x);
+ bool is_neg = xbits.is_neg();
+ double x_abs = fputil::cast<double>(xbits.abs().get_val());
+
+ auto signed_result = [is_neg](auto r) -> auto { return is_neg ? -r : r; };
+
+ if (LIBC_UNLIKELY(x_abs > 1.0)) {
+ if (xbits.is_nan()) {
+ if (xbits.is_signaling_nan()) {
+ fputil::raise_except_if_required(FE_INVALID);
+ return FPBits::quiet_nan().get_val();
+ }
+ return x;
+ }
+
+ fputil::raise_except_if_required(FE_INVALID);
+ fputil::set_errno_if_required(EDOM);
+ return FPBits::quiet_nan().get_val();
+ }
+
+#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+ auto r = ACOSPIF_EXCEPTS.lookup(xbits.uintval());
+ if (LIBC_UNLIKELY(r.has_value()))
+ return r.value();
+#endif // !LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+
+ // acospif(x) = 1/2 - asinpif(x)
+ //
+ // if |x| <= 0.5:
+ // acospif(x) = 0.5 - x * (c0 + x^2 * P1(x^2))
+ if (LIBC_UNLIKELY(x_abs <= 0.5)) {
+ double x_d = fputil::cast<double>(x);
+ double v2 = x_d * x_d;
+ double result = x_d * fputil::multiply_add(
+ v2, inv_trigf_utils_internal::asinpi_eval(v2),
+ inv_trigf_utils_internal::ASINPI_COEFFS[0]);
+ return fputil::cast<float>(0.5 - result);
+ }
+
+ // If |x| > 0.5, we use the identity:
+ // asinpif(x) = sign(x) * (0.5 - 2 * sqrt(u) * P(u))
+ // where u = (1 - |x|) / 2, P(u) ~ asin(sqrt(u)) / (pi * sqrt(u))
+ //
+ // Then:
+ // acospif(x) = 0.5 - asinpif(x)
+ //
+ // For x > 0.5:
+ // acospif(x) = 0.5 - (0.5 - 2*sqrt(u)*P(u)) = 2*sqrt(u)*P(u)
+ //
+ // For x < -0.5:
+ // acospif(x) = 0.5 - (-(0.5 - 2*sqrt(u)*P(u))) = 1 - 2*sqrt(u)*P(u)
+
+ constexpr double ONE_OVER_PI_HI = 0x1.45f306dc9c883p-2;
+ constexpr double ONE_OVER_PI_LO = -0x1.6b01ec5417056p-56;
+ // C0_MINUS_1OVERPI = c0 - 1/pi = DELTA_C0 + ONE_OVER_PI_LO
+ constexpr double C0_MINUS_1OVERPI =
+ (inv_trigf_utils_internal::ASINPI_COEFFS[0] - ONE_OVER_PI_HI) +
+ ONE_OVER_PI_LO;
+
+ double u = fputil::multiply_add(-0.5, x_abs, 0.5);
+ double sqrt_u = fputil::sqrt<double>(u);
+ double neg2_sqrt_u = -2.0 * sqrt_u;
+
+ // tail = (c0 - 1/pi) + u * P1(u)
+ double tail = fputil::multiply_add(
+ u, inv_trigf_utils_internal::asinpi_eval(u), C0_MINUS_1OVERPI);
+
+ double result_hi = fputil::multiply_add(neg2_sqrt_u, ONE_OVER_PI_HI, 0.5);
+ double result = fputil::multiply_add(tail, neg2_sqrt_u, result_hi);
+
+ // For x > 0.5: acospif(x) = 2*sqrt(u)*P(u)
+ // For x < -0.5: acospif(x) = 1 - 2*sqrt(u)*P(u)
+
+ return fputil::cast<float>(0.5 - signed_result(result));
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_ACOSPIF_H
diff --git a/libc/src/__support/math/asinpif.h b/libc/src/__support/math/asinpif.h
index 398d64b4f131e..9a5daf6198a42 100644
--- a/libc/src/__support/math/asinpif.h
+++ b/libc/src/__support/math/asinpif.h
@@ -9,6 +9,7 @@
#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_ASINPIF_H
#define LLVM_LIBC_SRC___SUPPORT_MATH_ASINPIF_H
+#include "inv_trigf_utils.h"
#include "src/__support/FPUtil/FEnvImpl.h"
#include "src/__support/FPUtil/FPBits.h"
#include "src/__support/FPUtil/PolyEval.h"
@@ -66,50 +67,14 @@ LIBC_INLINE float asinpif(float x) {
return r.value();
#endif // !LIBC_MATH_HAS_SKIP_ACCURATE_PASS
- // the coefficients for the polynomial approximation of asin(x)/(pi*x) in the
- // range [0, 0.5] extracted using Sollya.
- //
- // Sollya code:
- // > prec = 200;
- // > display = hexadecimal;
- // > g = asin(x) / (pi * x);
- // > P = fpminimax(g, [|0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20|],
- // > [|D...|], [0, 0.5]);
- // > for i from 0 to degree(P) do coeff(P, i);
- // > print("Error:", dirtyinfnorm(P - g, [1e-30; 0.25]));
- // Error: 0x1.45c281e1cf9b58p-50 ~= 2^−49.652
- //
- // Non-zero coefficients (even powers only):
- constexpr double ASINPI_POLY_COEFFS[] = {
- 0x1.45f306dc9c881p-2, // x^0
- 0x1.b2995e7b7e756p-5, // x^2
- 0x1.8723a1d12f828p-6, // x^4
- 0x1.d1a45564b9545p-7, // x^6
- 0x1.3ce4ceaa0e1e9p-7, // x^8
- 0x1.d2c305898ea13p-8, // x^10
- 0x1.692212e27a5f9p-8, // x^12
- 0x1.2b22cc744d25bp-8, // x^14
- 0x1.8427b864479ffp-9, // x^16
- 0x1.815522d7a2bf1p-8, // x^18
- -0x1.f6df98438aef4p-9, // x^20
- 0x1.4b50c2eb13708p-7 // x^22
- };
- // Evaluates P1(v2) = c1 + c2*v2 + c3*v2^2 + ... (tail of P without c0)
- auto asinpi_polyeval = [&](double v2) -> double {
- return fputil::polyeval(
- v2, ASINPI_POLY_COEFFS[1], ASINPI_POLY_COEFFS[2], ASINPI_POLY_COEFFS[3],
- ASINPI_POLY_COEFFS[4], ASINPI_POLY_COEFFS[5], ASINPI_POLY_COEFFS[6],
- ASINPI_POLY_COEFFS[7], ASINPI_POLY_COEFFS[8], ASINPI_POLY_COEFFS[9],
- ASINPI_POLY_COEFFS[10], ASINPI_POLY_COEFFS[11]);
- };
-
// if |x| <= 0.5:
// asinpi(x) = x * (c0 + x^2 * P1(x^2))
if (LIBC_UNLIKELY(x_abs <= 0.5)) {
double x_d = fputil::cast<double>(x);
double v2 = x_d * x_d;
- double result = x_d * fputil::multiply_add(v2, asinpi_polyeval(v2),
- ASINPI_POLY_COEFFS[0]);
+ double result = x_d * fputil::multiply_add(
+ v2, inv_trigf_utils_internal::asinpi_eval(v2),
+ inv_trigf_utils_internal::ASINPI_COEFFS[0]);
return fputil::cast<float>(result);
}
@@ -131,14 +96,16 @@ LIBC_INLINE float asinpif(float x) {
constexpr double ONE_OVER_PI_LO = -0x1.6b01ec5417056p-56;
// C0_MINUS_1OVERPI = c0 - 1/pi = DELTA_C0 + ONE_OVER_PI_LO
constexpr double C0_MINUS_1OVERPI =
- (ASINPI_POLY_COEFFS[0] - ONE_OVER_PI_HI) + ONE_OVER_PI_LO;
+ (inv_trigf_utils_internal::ASINPI_COEFFS[0] - ONE_OVER_PI_HI) +
+ ONE_OVER_PI_LO;
double u = fputil::multiply_add(-0.5, x_abs, 0.5);
double sqrt_u = fputil::sqrt<double>(u);
double neg2_sqrt_u = -2.0 * sqrt_u;
// tail = (c0 - 1/pi) + u * P1(u)
- double tail = fputil::multiply_add(u, asinpi_polyeval(u), C0_MINUS_1OVERPI);
+ double tail = fputil::multiply_add(
+ u, inv_trigf_utils_internal::asinpi_eval(u), C0_MINUS_1OVERPI);
double result_hi = fputil::multiply_add(neg2_sqrt_u, ONE_OVER_PI_HI, 0.5);
double result = fputil::multiply_add(tail, neg2_sqrt_u, result_hi);
diff --git a/libc/src/__support/math/inv_trigf_utils.h b/libc/src/__support/math/inv_trigf_utils.h
index 6eab68d8bbe01..7a93831333db0 100644
--- a/libc/src/__support/math/inv_trigf_utils.h
+++ b/libc/src/__support/math/inv_trigf_utils.h
@@ -177,6 +177,43 @@ LIBC_INLINE double asin_eval(double xsq) {
return fputil::multiply_add(xsq, r2, r1);
}
+// the coefficients for the polynomial approximation of asin(x)/(pi*x) in the
+// range [0, 0.5] extracted using Sollya.
+//
+// Sollya code:
+// > prec = 200;
+// > display = hexadecimal;
+// > g = asin(x) / (pi * x);
+// > P = fpminimax(g, [|0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20|],
+// > [|D...|], [0, 0.5]);
+// > for i from 0 to degree(P) do coeff(P, i);
+// > print("Error:", dirtyinfnorm(P - g, [1e-30; 0.25]));
+// Error: 0x1.45c281e1cf9b58p-50 ~= 2^−49.652
+//
+// Non-zero coefficients (even powers only):
+LIBC_INLINE_VAR constexpr double ASINPI_COEFFS[13] = {
+ 0x1.45f306dc9c881p-2, // x^0
+ 0x1.b2995e7b7e756p-5, // x^2
+ 0x1.8723a1d12f828p-6, // x^4
+ 0x1.d1a45564b9545p-7, // x^6
+ 0x1.3ce4ceaa0e1e9p-7, // x^8
+ 0x1.d2c305898ea13p-8, // x^10
+ 0x1.692212e27a5f9p-8, // x^12
+ 0x1.2b22cc744d25bp-8, // x^14
+ 0x1.8427b864479ffp-9, // x^16
+ 0x1.815522d7a2bf1p-8, // x^18
+ -0x1.f6df98438aef4p-9, // x^20
+ 0x1.4b50c2eb13708p-7 // x^22
+};
+
+// Evaluates P1(v2) = c1 + c2*v2 + c3*v2^2 + ... (tail of P without c0)
+LIBC_INLINE double asinpi_eval(double v2) {
+ return fputil::polyeval(
+ v2, ASINPI_COEFFS[1], ASINPI_COEFFS[2], ASINPI_COEFFS[3],
+ ASINPI_COEFFS[4], ASINPI_COEFFS[5], ASINPI_COEFFS[6], ASINPI_COEFFS[7],
+ ASINPI_COEFFS[8], ASINPI_COEFFS[9], ASINPI_COEFFS[10], ASINPI_COEFFS[11]);
+}
+
} // namespace inv_trigf_utils_internal
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index 7a9370fe487e2..e617950368994 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -48,6 +48,7 @@ add_math_entrypoint_object(acosh)
add_math_entrypoint_object(acoshf)
add_math_entrypoint_object(acoshf16)
+add_math_entrypoint_object(acospif)
add_math_entrypoint_object(acospif16)
add_math_entrypoint_object(asin)
diff --git a/libc/src/math/acospif.h b/libc/src/math/acospif.h
new file mode 100644
index 0000000000000..80e001a60d1ad
--- /dev/null
+++ b/libc/src/math/acospif.h
@@ -0,0 +1,20 @@
+//===-- Implementation header for acospif -----------------------*- 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_MATH_ACOSPIF_H
+#define LLVM_LIBC_SRC_MATH_ACOSPIF_H
+
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+float acospif(float x);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_ACOSPIF_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index f8834c5c12705..96e79833bad04 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -3985,6 +3985,18 @@ add_entrypoint_object(
libc.src.errno.errno
)
+add_entrypoint_object(
+ acospif
+ SRCS
+ acospif.cpp
+ HDRS
+ ../acospif.h
+ DEPENDS
+ libc.src.__support.math.acospif
+)
+
+
+
add_entrypoint_object(
asinhf
SRCS
diff --git a/libc/src/math/generic/acospif.cpp b/libc/src/math/generic/acospif.cpp
new file mode 100644
index 0000000000000..928c2cba1441f
--- /dev/null
+++ b/libc/src/math/generic/acospif.cpp
@@ -0,0 +1,16 @@
+//===-- Single-precision acospif(x) function ------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/math/acospif.h"
+#include "src/__support/math/acospif.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(float, acospif, (float x)) { return math::acospif(x); }
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 490e498aaf9e8..79c0cb66a703c 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -13,6 +13,7 @@ add_fp_unittest(
libc.src.__support.math.acosf16
libc.src.__support.math.acoshf
libc.src.__support.math.acoshf16
+ libc.src.__support.math.acospif
libc.src.__support.math.acospif16
libc.src.__support.math.asin
libc.src.__support.math.asinf
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 43ff7610e384b..7e607b5772616 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -146,6 +146,7 @@ TEST(LlvmLibcSharedMathTest, AllFloat) {
EXPECT_FP_EQ(0x1.921fb6p+0, LIBC_NAMESPACE::shared::acosf(0.0f));
EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::acoshf(1.0f));
+ EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::acospif(1.0f));
EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::asinf(0.0f));
EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared:...
[truncated]
|
🐧 Linux x64 Test Results✅ The build succeeded and no tests ran. This is expected in some build configurations. |
5fb453f to
13407ca
Compare
13407ca to
bd42e80
Compare
lntue
reviewed
Feb 27, 2026
lntue
reviewed
Feb 27, 2026
lntue
approved these changes
Feb 27, 2026
bassiounix
requested changes
Feb 27, 2026
bassiounix
approved these changes
Feb 28, 2026
sahas3
pushed a commit
to sahas3/llvm-project
that referenced
this pull request
Mar 4, 2026
Implementing C23 `acospi` math function for single-precision with the header-only approach that is followed since llvm#147386
sujianIBM
pushed a commit
to sujianIBM/llvm-project
that referenced
this pull request
Mar 5, 2026
Implementing C23 `acospi` math function for single-precision with the header-only approach that is followed since llvm#147386
This was referenced Apr 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implementing C23
acospimath function for single-precision with the header-only approach that is followed since #147386