diff options
author | lntue <35648136+lntue@users.noreply.github.com> | 2024-06-24 17:57:08 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-24 17:57:08 -0400 |
commit | 16903ace180755b7558234ff2b2e8d89b00dcb88 (patch) | |
tree | 1158c0aef94cca9903d1238e0eef7abdf3e4cb91 /libc/config | |
parent | 5ae50698a0d6a3022af2e79d405a7eb6c8c790f0 (diff) | |
download | llvm-16903ace180755b7558234ff2b2e8d89b00dcb88.zip llvm-16903ace180755b7558234ff2b2e8d89b00dcb88.tar.gz llvm-16903ace180755b7558234ff2b2e8d89b00dcb88.tar.bz2 |
[libc][math] Implement double precision sin correctly rounded to all rounding modes. (#95736)
- Algorithm:
- Step 1 - Range reduction: for a double precision input `x`, return `k`
and `u` such that
- k is an integer
- u = x - k * pi / 128, and |u| < pi/256
- Step 2 - Calculate `sin(u)` and `cos(u)` in double-double using Taylor
polynomials with errors < 2^-70 with FMA or < 2^-66 w/o FMA.
- Step 3 - Calculate `sin(x) = sin(k*pi/128) * cos(u) + cos(k*pi/128) *
sin(u)` using look-up table for `sin(k*pi/128)` and `cos(k*pi/128)`.
- Step 4 - Use Ziv's rounding test to decide if the result is correctly
rounded.
- Step 4' - If the Ziv's rounding test failed, redo step 1-3 using
128-bit precision.
- Currently, without FMA instructions, the large range reduction only
works correctly for the default rounding mode (FE_TONEAREST).
- Provide `LIBC_MATH` flag so that users can set `LIBC_MATH =
LIBC_MATH_SKIP_ACCURATE_PASS` to build the `sin` function without step 4
and 4'.
Diffstat (limited to 'libc/config')
-rw-r--r-- | libc/config/darwin/arm/entrypoints.txt | 1 | ||||
-rw-r--r-- | libc/config/linux/aarch64/entrypoints.txt | 1 | ||||
-rw-r--r-- | libc/config/linux/arm/entrypoints.txt | 1 | ||||
-rw-r--r-- | libc/config/linux/riscv/entrypoints.txt | 1 |
4 files changed, 4 insertions, 0 deletions
diff --git a/libc/config/darwin/arm/entrypoints.txt b/libc/config/darwin/arm/entrypoints.txt index e130326..d486916 100644 --- a/libc/config/darwin/arm/entrypoints.txt +++ b/libc/config/darwin/arm/entrypoints.txt @@ -226,6 +226,7 @@ set(TARGET_LIBM_ENTRYPOINTS libc.src.math.scalbnl libc.src.math.sincosf libc.src.math.sinhf + libc.src.math.sin libc.src.math.sinf libc.src.math.sqrt libc.src.math.sqrtf diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt index 63238ec..2d2e1b5 100644 --- a/libc/config/linux/aarch64/entrypoints.txt +++ b/libc/config/linux/aarch64/entrypoints.txt @@ -481,6 +481,7 @@ set(TARGET_LIBM_ENTRYPOINTS libc.src.math.scalbnl libc.src.math.sincosf libc.src.math.sinhf + libc.src.math.sin libc.src.math.sinf libc.src.math.sqrt libc.src.math.sqrtf diff --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt index 00df445..53cdcc3 100644 --- a/libc/config/linux/arm/entrypoints.txt +++ b/libc/config/linux/arm/entrypoints.txt @@ -354,6 +354,7 @@ set(TARGET_LIBM_ENTRYPOINTS libc.src.math.scalbnf libc.src.math.scalbnl libc.src.math.sincosf + libc.src.math.sin libc.src.math.sinf libc.src.math.sinhf libc.src.math.sqrt diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt index e12d6b3..18968f5 100644 --- a/libc/config/linux/riscv/entrypoints.txt +++ b/libc/config/linux/riscv/entrypoints.txt @@ -489,6 +489,7 @@ set(TARGET_LIBM_ENTRYPOINTS libc.src.math.scalbnl libc.src.math.sincosf libc.src.math.sinhf + libc.src.math.sin libc.src.math.sinf libc.src.math.sqrt libc.src.math.sqrtf |