[all-commits] [llvm/llvm-project] 513f9c: [libc][math] Add float-only implementation for sin...
lntue via All-commits
all-commits at lists.llvm.org
Tue Oct 21 10:33:32 PDT 2025
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 513f9c50e74e55b7f8dedf65105bdc1083d4f83d
https://github.com/llvm/llvm-project/commit/513f9c50e74e55b7f8dedf65105bdc1083d4f83d
Author: lntue <lntue at google.com>
Date: 2025-10-21 (Tue, 21 Oct 2025)
Changed paths:
M libc/src/__support/FPUtil/double_double.h
M libc/src/__support/math/CMakeLists.txt
M libc/src/__support/math/cosf.h
A libc/src/__support/math/sincosf_float_eval.h
M libc/src/math/generic/sinf.cpp
M libc/test/src/math/CMakeLists.txt
A libc/test/src/math/cosf_float_test.cpp
M libc/test/src/math/exhaustive/CMakeLists.txt
A libc/test/src/math/exhaustive/cosf_float_test.cpp
M libc/test/src/math/exhaustive/exhaustive_test.h
A libc/test/src/math/exhaustive/sinf_float_test.cpp
A libc/test/src/math/sinf_float_test.cpp
M utils/bazel/llvm-project-overlay/libc/BUILD.bazel
Log Message:
-----------
[libc][math] Add float-only implementation for sinf / cosf. (#161680)
Based on the double precision's sin/cos fast path algorithm:
Step 1: Perform range reduction `y = x mod pi/8` with target errors <
2^-54.
This is because the worst case mod pi/8 for single precision is ~2^-31,
so to have up to 1 ULP errors from
the range reduction, the targeted errors should `be 2^(-31 - 23) =
2^-54`.
Step 2: Polynomial approximation
We use degree-5 and degree-4 polynomials to approximate sin and cos of
the reduced angle respectively.
Step 3: Combine the results using trig identities
```math
\begin{align*}
\sin(x) &= \sin(y) \cdot \cos(k \cdot \frac{\pi}{8}) + \cos(y) \cdot \sin(k \cdot \frac{\pi}{8}) \\
\cos(x) &= \cos(y) \cdot \cos(k \cdot \frac{\pi}{8}) - \sin(y) \cdot \sin(k \cdot \frac{\pi}{8})
\end{align*}
```
Overall errors: <= 3 ULPs for default rounding modes (tested
exhaustively).
Current limitation: large range reduction requires FMA instructions for
binary32. This restriction will be removed in the followup PR.
---------
Co-authored-by: Petr Hosek <phosek at google.com>
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list