Commit Graph

1109 Commits

Author SHA1 Message Date
Michael Jones dbca7b4b2e [libc] disable syscall test without fullbuild
Our syscall implementation depends on a specific macro that's only
defined in our headers. If we're not using our headers, then the test
doesn't work. I've disabled the test in this case because there's no
point in testing the system libc's syscall implementation.

Differential Revision: https://reviews.llvm.org/D134994
2022-09-30 15:57:10 -07:00
Michael Jones 1801c356f6 [libc] add syscall function
Add the syscall wrapper function and tests. It's implemented using a
macro to guarantee the minimum number of arguments.

Reviewed By: sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D134919
2022-09-30 15:46:28 -07:00
Siva Chandra Reddy 215c9fa4de [libc] Re-enable functions from signal.h and re-enable abort.
They were disabled because we were including linux/signal.h from our
signal.h. Linux's signal.h is not designed to be included from user
programs as it causes a lot of non-standard name pollution. Also, it is
not self-contained. This change defines types and macros relevant for
signal related syscalls within libc's headers and removes inclusion of
Linux headers.

This patch enables the funtions only for x86_64. They will be enabled
for aarch64 also in a follow up patch after testing.

Reviewed By: abrachet, lntue

Differential Revision: https://reviews.llvm.org/D134567
2022-09-30 07:31:50 +00:00
Michael Jones 073534cb6f [libc][windows] rename fenv internals for windows
On windows, including math.h causes macros for "OVERFLOW" and
"UNDERFLOW" to be defined. This patch renames some variables internal to
FEnvImpl.h to avoid colliding with those.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D134775
2022-09-29 16:55:02 -07:00
Siva Chandra 5e56e294ae [libc][Obvious] Enable some of the recently added functions on aarch64. 2022-09-29 15:06:44 -07:00
Siva Chandra Reddy 545b954251 [libc] Add GNU extension functions sched_getaffinity and sched_setaffinity.
Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D134858
2022-09-29 20:31:46 +00:00
Michael Jones b49d626cb4 [libc] add clock_gettime
Add the clock_gettime syscall wrapper and tests.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D134773
2022-09-29 10:23:21 -07:00
Guillaume Chatelet 060a43ced2 [libc][NFC] Move alignment utils to utils.h 2022-09-29 13:51:35 +00:00
Guillaume Chatelet e095c3ed7c [libc][test] Better reporting for MemoryMatcher 2022-09-29 12:14:05 +00:00
Siva Chandra Reddy 3367539010 [libc] Add implementation of pthread_once.
The existing thrd_once function has been refactored so that the
implementation can be shared between thrd_once and pthread_once
functions.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D134716
2022-09-28 06:54:48 +00:00
Michael Jones 943dcf87e3 [libc][windows] fix small build issues.
The windows build has fallen behind a little, this patch fixes some
issues that were preventing it from building.
Specifically: Some subfolders weren't being included, leading to missing
targets in the cmake.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D134676
2022-09-27 15:59:01 -07:00
Tue Ly e15b2da42f [libc][math] Simplify tanf implementation and improve its performance.
Simplify `tanf` implementation and improve its performance.

Completely reuse the implementation of `sinf`, `cosf`, `sincosf` and use
the definition `tan(x) = sin(x)/cos(x)`.

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

BEFORE:
LIBC reciprocal throughput        : 36.480
LIBC reciprocal throughput        : 27.217    (with `-msse4.2` flag)
LIBC reciprocal throughput        : 20.205    (with `-mfma` flag)

AFTER:
LIBC reciprocal throughput        : 30.337
LIBC reciprocal throughput        : 21.072    (with `-msse4.2` flag)
LIBC reciprocal throughput        : 15.804    (with `-mfma` flag)

$ CORE_MATH_PERF_MODE="rdtsc" ./perf.sh tanf --latency
GNU libc version: 2.35
GNU libc release: stable
CORE-MATH latency   : 56.702
System LIBC latency : 107.206

BEFORE
LIBC latency        : 97.598
LIBC latency        : 91.119   (with `-msse4.2` flag)
LIBC latency        : 82.655    (with `-mfma` flag)

AFTER
LIBC latency        : 74.560
LIBC latency        : 66.575    (with `-msse4.2` flag)
LIBC latency        : 61.636    (with `-mfma` flag)
```

Reviewed By: zimmermann6

Differential Revision: https://reviews.llvm.org/D134575
2022-09-26 21:36:12 -04:00
Guillaume Chatelet aec908f9b2 [libc][NFC] Move bzero_inline to separate file
This allows for easier discovery.
2022-09-26 12:57:51 +00:00
Guillaume Chatelet 2188cf9fa4 [libc][NFC] Remove new framework, a simpler one is coming 2022-09-26 12:42:38 +00:00
Guillaume Chatelet 8a55dafdd0 [libc][NFC] introduce inline_bzero 2022-09-26 12:34:10 +00:00
Raman Tenneti 8f1e362ee9 Implement nanosleep per https://pubs.opengroup.org/onlinepubs/009695399/basedefs/time.h.html
Tested:
Limited unit test: This makes a call and checks that no error was
returned, but we currently don't have the ability to ensure that
time has elapsed as expected.

Co-authored-by: Jeff Bailey <jeffbailey@google.com>

Reviewed By: sivachandra, jeffbailey

Differential Revision: https://reviews.llvm.org/D134095
2022-09-24 00:13:58 +00:00
Michael Jones 736e215ca7 [libc][obvious] disable mprotect test under sanitizers
fixes a build failure in my previous patch

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D134552
2022-09-23 10:05:09 -07:00
Michael Jones 85c70da732 [libc] add madvise and posix_madvise
Add the madvise and posix_madvise syscall wrappers and tests.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D134498
2022-09-23 09:36:40 -07:00
Michael Jones 47b724048b [libc] add mprotect
Add the mprotect syscall wrapper and tests.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D134497
2022-09-23 09:36:37 -07:00
Michael Jones 8d615a5e8a [libc] move sys/mman macros to /include
Previously the mman macros were in api.td, but platform differences are
easier to handle with preprocessor macros so they have been moved to
include. Also I completed the list of macros (at least for what I need
soon) and fixed some previously incorrect values.

Reviewed By: sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D134491
2022-09-23 09:36:34 -07:00
Siva Chandra Reddy 4f1474daec [libc] Add implementations of POSIX getpid, getppid, getuid, geteuid functions.
Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D134338
2022-09-21 18:41:20 +00:00
Siva Chandra Reddy e310f8bddf [libc] Add implementation of functions stat, fstat and lstat.
All supporting type and macro definitions have also been added.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D134262
2022-09-21 18:35:02 +00:00
Michael Jones a9e0dbefdd [libc] add fputs and puts
add fputs, puts, and the EOF macro that they use.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D134328
2022-09-21 11:10:20 -07:00
Michael Jones 42bcb35c0f [libc] add strerror
Strerror maps error numbers to strings. Additionally, a utility for
mapping errors to strings was added so that it could be reused for
perror and similar.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D134074
2022-09-20 16:23:36 -07:00
Jeff Bailey faeb237bac [libc] Fix TWS issues in .td files
Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D134256
2022-09-20 14:25:53 +00:00
Jeff Bailey 6007a4a619 [libc] Remove unneeded extra include
Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D134255
2022-09-20 14:24:46 +00:00
Tue Ly 354ee3814c [libc][Obvious] Fix exp10f spec. 2022-09-19 11:21:01 -04:00
Tue Ly 47c4a87641 [libc][Obvious] Remove constexpr qualifier from Exp10Base::powb_lo. 2022-09-19 10:13:29 -04:00
Tue Ly a752460d73 [libc][math] Implement exp10f function correctly rounded to all rounding modes.
Implement exp10f function correctly rounded to all rounding modes.

Algorithm: perform range reduction to reduce
```
  10^x = 2^(hi + mid) * 10^lo
```
where:
```
  hi is an integer,
  0 <= mid * 2^5 < 2^5
  -log10(2) / 2^6 <= lo <= log10(2) / 2^6
```
Then `2^mid` is stored in a table of 32 entries and the product `2^hi * 2^mid` is
performed by adding `hi` into the exponent field of `2^mid`.
`10^lo` is then approximated by a degree-5 minimax polynomials generated by Sollya with:
```
  > P = fpminimax((10^x - 1)/x, 4, [|D...|], [-log10(2)/64. log10(2)/64]);
```
Performance benchmark using perf tool from the CORE-MATH project on Ryzen 1700:
```
$ CORE_MATH_PERF_MODE="rdtsc" ./perf.sh exp10f
GNU libc version: 2.35
GNU libc release: stable
CORE-MATH reciprocal throughput   : 10.215
System LIBC reciprocal throughput : 7.944

LIBC reciprocal throughput        : 38.538
LIBC reciprocal throughput        : 12.175   (with `-msse4.2` flag)
LIBC reciprocal throughput        : 9.862    (with `-mfma` flag)

$ CORE_MATH_PERF_MODE="rdtsc" ./perf.sh exp10f --latency
GNU libc version: 2.35
GNU libc release: stable
CORE-MATH latency   : 40.744
System LIBC latency : 37.546

BEFORE
LIBC latency        : 48.989
LIBC latency        : 44.486   (with `-msse4.2` flag)
LIBC latency        : 40.221   (with `-mfma` flag)
```
This patch relies on https://reviews.llvm.org/D134002

Reviewed By: orex, zimmermann6

Differential Revision: https://reviews.llvm.org/D134104
2022-09-19 10:01:40 -04:00
Tue Ly cd1d71c5f1 [libc][Obvious] Remove constexpr qualifier from ExpBase::powb_lo. 2022-09-19 09:29:37 -04:00
Tue Ly 4973eee122 [libc][math] Improve tanhf performance.
Optimize the core part of `tanhf` implementation that is to compute `e^x`
similar to https://reviews.llvm.org/D133870.  Factor the constants and
polynomial approximation out so that it can be used for `exp10f`

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

BEFORE:
LIBC reciprocal throughput        : 75.674
LIBC reciprocal throughput        : 33.242    (with `-msse4.2` flag)
LIBC reciprocal throughput        : 25.927    (with `-mfma` flag)

AFTER:
LIBC reciprocal throughput        : 26.359
LIBC reciprocal throughput        : 18.888    (with `-msse4.2` flag)
LIBC reciprocal throughput        : 14.243    (with `-mfma` flag)

$ CORE_MATH_PERF_MODE="rdtsc" ./perf.sh tanhf --latency
GNU libc version: 2.35
GNU libc release: stable
CORE-MATH latency   : 43.365
System LIBC latency : 123.499

BEFORE
LIBC latency        : 112.968
LIBC latency        : 104.908   (with `-msse4.2` flag)
LIBC latency        : 92.310    (with `-mfma` flag)

AFTER
LIBC latency        : 69.828
LIBC latency        : 63.874    (with `-msse4.2` flag)
LIBC latency        : 57.427    (with `-mfma` flag)
```

Reviewed By: orex, zimmermann6

Differential Revision: https://reviews.llvm.org/D134002
2022-09-19 08:43:03 -04:00
Michael Jones 70f1f302ca [libc][cmake] separate installing headers
Now libc headers can be installed separately from installing the rest of
the libc.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D133960
2022-09-16 15:50:28 -07:00
Siva Chandra Reddy 7fb96fb5d3 [libc] Add implementation of POSIX "uname" function.
Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D134065
2022-09-16 21:21:29 +00:00
Siva Chandra Reddy 9050a59c66 [libc][Obvious] Fix typo in struct rlimit name - remove the "_t" suffix. 2022-09-16 21:07:17 +00:00
Siva Chandra Reddy f5cbbb9988 [libc] Add implementation of POSIX setrlimit and getrlimit functions.
Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D134016
2022-09-16 20:50:28 +00:00
Siva Chandra Reddy d23d858d04 [libc] Add the implementation of the "remove" function.
Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D133922
2022-09-15 17:32:02 +00:00
Tue Ly 1c89ae71ea [libc][math] Improve sinhf and coshf performance.
Optimize `sinhf` and `coshf` by computing exp(x) and exp(-x) simultaneously.

Currently `sinhf` and `coshf` are implemented using the following formulas:
```
  sinh(x) = 0.5 *(exp(x) - 1) - 0.5*(exp(-x) - 1)
  cosh(x) = 0.5*exp(x) + 0.5*exp(-x)
```
where `exp(x)` and `exp(-x)` are calculated separately using the formula:
```
  exp(x) ~ 2^hi * 2^mid * exp(dx)
         ~ 2^hi * 2^mid * P(dx)
```
By expanding the polynomial `P(dx)` into even and odd parts
```
  P(dx) = P_even(dx) + dx * P_odd(dx)
```
we can see that the computations of `exp(x)` and `exp(-x)` have many things in common,
namely:
```
  exp(x)  ~ 2^(hi + mid) * (P_even(dx) + dx * P_odd(dx))
  exp(-x) ~ 2^(-(hi + mid)) * (P_even(dx) - dx * P_odd(dx))
```
Expanding `sinh(x)` and `cosh(x)` with respect to the above formulas, we can compute
these two functions as follow in order to maximize the sharing parts:
```
  sinh(x) = (e^x - e^(-x)) / 2
          ~ 0.5 * (P_even * (2^(hi + mid) - 2^(-(hi + mid))) +
                  dx * P_odd * (2^(hi + mid) + 2^(-(hi + mid))))
  cosh(x) = (e^x + e^(-x)) / 2
          ~ 0.5 * (P_even * (2^(hi + mid) + 2^(-(hi + mid))) +
                  dx * P_odd * (2^(hi + mid) - 2^(-(hi + mid))))
```
So in this patch, we perform the following optimizations for `sinhf` and `coshf`:
  # Use the above formulas to maximize sharing intermediate results,
  # Apply similar optimizations from https://reviews.llvm.org/D133870

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

BEFORE:
LIBC reciprocal throughput        : 90.116
LIBC reciprocal throughput        : 28.554    (with `-msse4.2` flag)
LIBC reciprocal throughput        : 22.577    (with `-mfma` flag)

AFTER:
LIBC reciprocal throughput        : 36.482
LIBC reciprocal throughput        : 16.955    (with `-msse4.2` flag)
LIBC reciprocal throughput        : 13.943    (with `-mfma` flag)

$ CORE_MATH_PERF_MODE="rdtsc" ./perf.sh sinhf --latency
GNU libc version: 2.35
GNU libc release: stable
CORE-MATH latency   : 48.821
System LIBC latency : 137.019

BEFORE
LIBC latency        : 97.122
LIBC latency        : 84.214    (with `-msse4.2` flag)
LIBC latency        : 71.611    (with `-mfma` flag)

AFTER
LIBC latency        : 54.555
LIBC latency        : 50.865    (with `-msse4.2` flag)
LIBC latency        : 48.700    (with `-mfma` flag)
```
For `coshf`:
```
$ CORE_MATH_PERF_MODE="rdtsc" ./perf.sh coshf
GNU libc version: 2.35
GNU libc release: stable
CORE-MATH reciprocal throughput   : 16.939
System LIBC reciprocal throughput : 19.695

BEFORE:
LIBC reciprocal throughput        : 52.845
LIBC reciprocal throughput        : 29.174    (with `-msse4.2` flag)
LIBC reciprocal throughput        : 22.553    (with `-mfma` flag)

AFTER:
LIBC reciprocal throughput        : 37.169
LIBC reciprocal throughput        : 17.805    (with `-msse4.2` flag)
LIBC reciprocal throughput        : 14.691    (with `-mfma` flag)

$ CORE_MATH_PERF_MODE="rdtsc" ./perf.sh coshf --latency
GNU libc version: 2.35
GNU libc release: stable
CORE-MATH latency   : 48.478
System LIBC latency : 48.044

BEFORE
LIBC latency        : 99.123
LIBC latency        : 85.595    (with `-msse4.2` flag)
LIBC latency        : 72.776    (with `-mfma` flag)

AFTER
LIBC latency        : 57.760
LIBC latency        : 53.967    (with `-msse4.2` flag)
LIBC latency        : 50.987    (with `-mfma` flag)
```

Reviewed By: orex, zimmermann6

Differential Revision: https://reviews.llvm.org/D133913
2022-09-15 09:20:39 -04:00
Siva Chandra Reddy 6e675fba3a [libc] Add POSIX functions pread and pwrite.
Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D133888
2022-09-14 20:52:20 +00:00
Tue Ly e6226e6b72 [libc][math] Improve exp2f performance.
Reduce the number of subintervals that need lookup table and optimize
the evaluation steps.

Currently, `exp2f` is computed by reducing to `2^hi * 2^mid * 2^lo` where
`-16/32 <= mid <= 15/32` and `-1/64 <= lo <= 1/64`, and `2^lo` is then
approximated by a degree 6 polynomial.

Experiment with Sollya showed that by using a degree 6 polynomial, we
can approximate `2^lo` for a bigger range with reasonable errors:
```
> P = fpminimax((2^x - 1)/x, 5, [|D...|], [-1/64, 1/64]);
> dirtyinfnorm(2^x - 1 - x*P, [-1/64, 1/64]);
0x1.e18a1bc09114def49eb851655e2e5c4dd08075ac2p-63

> P = fpminimax((2^x - 1)/x, 5, [|D...|], [-1/32, 1/32]);
> dirtyinfnorm(2^x - 1 - x*P, [-1/32, 1/32]);
0x1.05627b6ed48ca417fe53e3495f7df4baf84a05e2ap-56
```
So we can optimize the implementation a bit with:
# Reduce the range to `mid = i/16` for `i = 0..15` and `-1/32 <= lo <= 1/32`
# Store the table `2^mid` in bits, and add `hi` directly to its exponent field to compute `2^hi * 2^mid`
# Rearrange the order of evaluating the polynomial approximating `2^lo`.

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

BEFORE:
LIBC reciprocal throughput        : 21.405
LIBC reciprocal throughput        : 15.241    (with `-msse4.2` flag)
LIBC reciprocal throughput        : 11.111    (with `-mfma` flag)

AFTER:
LIBC reciprocal throughput        : 18.617
LIBC reciprocal throughput        : 12.852    (with `-msse4.2` flag)
LIBC reciprocal throughput        : 9.253     (with `-mfma` flag)

$ CORE_MATH_PERF_MODE="rdtsc" ./perf.sh exp2f --latency
GNU libc version: 2.35
GNU libc release: stable
CORE-MATH latency   : 40.869
System LIBC latency : 30.580

BEFORE
LIBC latency        : 64.888
LIBC latency        : 61.027    (with `-msse4.2` flag)
LIBC latency        : 48.778    (with `-mfma` flag)

AFTER
LIBC latency        : 48.803
LIBC latency        : 45.047    (with `-msse4.2` flag)
LIBC latency        : 37.487    (with `-mfma` flag)
```

Reviewed By: sivachandra, orex

Differential Revision: https://reviews.llvm.org/D133870
2022-09-14 14:44:25 -04:00
Siva Chandra cae9c64f08 [libc][Obvious] Fix typo in the alternate path of the POSIX "access" function. 2022-09-14 01:03:07 -07:00
Siva Chandra Reddy 419580c699 [libc] Add implementation of POSIX function "access".
Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D133814
2022-09-14 07:44:47 +00:00
Siva Chandra Reddy ef3e80b6bd [libc][Obvious] Use unique test file names in dup, dup2 and dup3 tests. 2022-09-13 18:20:04 +00:00
Siva Chandra Reddy 8989aa003f [libc] Add POSIX functions dup, dup2, and GNU extension function dup3.
Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D133748
2022-09-13 18:06:30 +00:00
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
Tue Ly e2f065c2a3 [libc][math] Implement asinf function correctly rounded for all rounding modes.
Implement asinf function correctly rounded for all rounding modes.

For `|x| <= 0.5`, we approximate `asin(x)` by
```
  asin(x) = x * P(x^2)
```
where `P(X^2) = Q(X)` is a degree-20 minimax even polynomial approximating
`asin(x)/x` on `[0, 0.5]` generated by Sollya with:
```
  > Q = fpminimax(asin(x)/x, [|0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20|],
                 [|1, D...|], [0, 0.5]);
```

When `|x| > 0.5`, we perform range reduction as follow:
Assume further that `0.5 < x <= 1`, and let:
```
  y = asin(x)
```
We will use the double angle formula:
```
  cos(2X) = 1 - 2 sin^2(X)
```
and the complement angle identity:
```
  x = sin(y) = cos(pi/2 - y)
              = 1 - 2 sin^2 (pi/4 - y/2)
```
So:
```
  sin(pi/4 - y/2) = sqrt( (1 - x)/2 )
```
And hence:
```
  pi/4 - y/2 = asin( sqrt( (1 - x)/2 ) )
```
Equivalently:
```
  asin(x) = y = pi/2 - 2 * asin( sqrt( (1 - x)/2 ) )
```
Let `u = (1 - x)/2`, then
```
  asin(x) = pi/2 - 2 * asin(u)
```
Moreover, since `0.5 < x <= 1`,
```
  0 <= u < 1/4, and 0 <= sqrt(u) < 0.5.
```
And hence we can reuse the same polynomial approximation of `asin(x)` when
`|x| <= 0.5`:
```
  asin(x) = pi/2 - 2 * u * P(u^2).
```

Performance benchmark using `perf` tool from the CORE-MATH project on Ryzen 1700:
```
$ CORE_MATH_PERF_MODE="rdtsc" ./perf.sh asinf
CORE-MATH reciprocal throughput   : 23.418
System LIBC reciprocal throughput : 27.310
LIBC reciprocal throughput        : 22.741

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

Reviewed By: orex, zimmermann6

Differential Revision: https://reviews.llvm.org/D133400
2022-09-07 19:27:47 -04:00
Tue Ly bb6966aa53 [libc] Return correct values for hypot when overflowed.
Hypot incorrectly returns +Inf when overflowed with FE_DOWNWARD and
FE_TOWARDZERO rounding modes.

Reviewed By: sivachandra, zimmermann6

Differential Revision: https://reviews.llvm.org/D133370
2022-09-07 19:23:11 -04:00
Alex Brachet 5c78c154df [libc][NFC] clang-format 2022-09-02 21:17:34 +00:00
Alex Brachet e66a1a5a39 [libc][NFC] Use no_sanitize("all")
This function cannot have any instrumentation because it's
assembly must match exactly what the debugger is expecting.

Previously it was just a list of what sanitizers we expect
libc would be sanitized with but this is untenable.
2022-09-02 19:07:39 +00:00
Jeff Bailey 0dcbe0e1df [libc] Add Buildbot to External Links
Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D133186
2022-09-02 14:11:09 +00:00
Tue Ly a4d48e3b0b [libc][NFC] Use cpp::optional for checking exceptional values of math functions.
Update the utility functions for checking exceptional values of math
functions to use cpp::optional return values.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D133134
2022-09-01 17:39:12 -04:00