llvm-project/libc
Tue Ly 463dcc8749 [libc][math] Implement acosf function correctly rounded for all rounding modes.
Implement acosf function correctly rounded for all rounding modes.

We perform range reduction as follows:

- When `|x| < 2^(-10)`, we use cubic Taylor polynomial:
```
  acos(x) = pi/2 - asin(x) ~ pi/2 - x - x^3 / 6.
```
- When `2^(-10) <= |x| <= 0.5`, we use the same approximation that is used for `asinf(x)` when `|x| <= 0.5`:
```
  acos(x) = pi/2 - asin(x) ~ pi/2 - x - x^3 * P(x^2).
```
- When `0.5 < x <= 1`, we use the double angle formula: `cos(2y) = 1 - 2 * sin^2 (y)` to reduce to:
```
  acos(x) = 2 * asin( sqrt( (1 - x)/2 ) )
```
- When `-1 <= x < -0.5`, we reduce to the positive case above using the formula:
```
  acos(x) = pi - acos(-x)
```

Performance benchmark using perf tool from the CORE-MATH project on Ryzen 1700:
```
$ CORE_MATH_PERF_MODE="rdtsc" ./perf.sh acosf
GNU libc version: 2.35
GNU libc release: stable
CORE-MATH reciprocal throughput   : 28.613
System LIBC reciprocal throughput : 29.204
LIBC reciprocal throughput        : 24.271

$ CORE_MATH_PERF_MODE="rdtsc" ./perf.sh asinf --latency
GNU libc version: 2.35
GNU libc release: stable
CORE-MATH latency   : 55.554
System LIBC latency : 76.879
LIBC latency        : 62.118
```

Reviewed By: orex, zimmermann6

Differential Revision: https://reviews.llvm.org/D133550
2022-09-09 09:55:30 -04:00
..
AOR_v20.02
benchmarks Remove unneeded cl::ZeroOrMore for cl::opt/cl::list options 2022-06-05 00:31:44 -07:00
cmake/modules [libc] Add a target to install libc in the full build mode. 2022-08-17 22:49:02 +00:00
config [libc][math] Implement acosf function correctly rounded for all rounding modes. 2022-09-09 09:55:30 -04:00
docs [libc][math] Implement acosf function correctly rounded for all rounding modes. 2022-09-09 09:55:30 -04:00
fuzzing [libc][cmake] split fputil into individual targets 2022-08-31 10:44:52 -07:00
include [libc] Add Linux implementation of GNU extension function sendfile. 2022-08-26 19:13:40 +00:00
lib [libc][NFC] Change the libc fullbuild target name to "libc". 2022-08-19 07:07:30 +00:00
loader [libc] Enable a few entrypoints on aarch64 which are now available on x86_64. 2022-08-23 12:31:42 -07:00
spec [libc][math] Implement acosf function correctly rounded for all rounding modes. 2022-09-09 09:55:30 -04:00
src [libc][math] Implement acosf function correctly rounded for all rounding modes. 2022-09-09 09:55:30 -04:00
test [libc][math] Implement acosf function correctly rounded for all rounding modes. 2022-09-09 09:55:30 -04:00
utils [libc][math] Implement acosf function correctly rounded for all rounding modes. 2022-09-09 09:55:30 -04:00
.clang-tidy
.gitignore
CMakeLists.txt [libc] Install startup files with the install-libc target. 2022-08-19 20:15:16 +00:00
LICENSE.TXT
README.txt

README.txt

LLVM libc
=========

This directory and its subdirectories contain source code for llvm-libc,
a retargetable implementation of the C standard library.

LLVM is open source software. You may freely distribute it under the terms of
the license agreement found in LICENSE.txt.