Commit Graph

1089 Commits

Author SHA1 Message Date
Michael Jones 096463d08e [libc] move printf to use StringViews
The FormatSection and the writer functions both previously took a char*
and a length to represent a string. Now they use the StringView class to
represent that more succinctly. This change also required fixing
everywhere these were used, so it touches a lot of files.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D131994
2022-08-24 10:28:31 -07:00
Siva Chandra d00e97df0f [libc][Obvious] Fix typo is chmod implementation.
This now allows enabling the chmod function on aarch64.
2022-08-23 15:01:21 -07:00
Siva Chandra 8856137ce7 [libc] Enable a few entrypoints on aarch64 which are now available on x86_64. 2022-08-23 12:31:42 -07:00
Siva Chandra Reddy 055322891c [libc] Add Linux implementations of POSIX chdir, fchdir, chmod and fchmod.
Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D132445
2022-08-23 17:16:49 +00:00
Guillaume Chatelet 1e5b3ce707 [reland][NFC][libc] standardize string_view 2022-08-23 12:40:49 +00:00
Guillaume Chatelet eebe9b2964 Revert "[reland][NFC][libc] standardize string_view"
This reverts commit df99774ef7.
2022-08-23 12:40:48 +00:00
Guillaume Chatelet df99774ef7 [reland][NFC][libc] standardize string_view 2022-08-23 12:10:28 +00:00
Guillaume Chatelet 54cfe5f778 Revert "[reland][NFC][libc] standardize string_view"
This reverts commit 522d29a6a7.
2022-08-23 11:50:56 +00:00
Guillaume Chatelet 522d29a6a7 [reland][NFC][libc] standardize string_view 2022-08-23 11:48:53 +00:00
Guillaume Chatelet 0df7e1b0e5 Revert "[reland][NFC][libc] standardize string_view"
This reverts commit 187099da1c.
2022-08-23 11:00:22 +00:00
Guillaume Chatelet 187099da1c [reland][NFC][libc] standardize string_view 2022-08-23 10:55:57 +00:00
Guillaume Chatelet abed700019 Revert "[NFC][libc] standardize string_view"
This reverts commit abe0fa6b17.
2022-08-23 10:43:22 +00:00
Guillaume Chatelet abe0fa6b17 [NFC][libc] standardize string_view 2022-08-23 09:57:20 +00:00
Siva Chandra Reddy 3496dd3bb6 [libc][Obvious] Move some macros definitions to sys/stat.h.
They were previously incorrectly listed in fcntl.h
2022-08-22 23:19:18 +00:00
Guillaume Chatelet 41d4067d0b [NFC][libc] clarify CPP folder documentation 2022-08-22 15:41:41 +00:00
Guillaume Chatelet aa59c9810a [libc][NFC] Use STL case for string_view 2022-08-22 15:25:14 +00:00
Guillaume Chatelet c860fd3f25 [NFC][libc] Remove ArrayRef which is replaced with span 2022-08-22 10:52:28 +00:00
Guillaume Chatelet 4d2319123a [NFC][libc] Switch File impl to span instead of ArrayRef 2022-08-22 10:27:07 +00:00
Guillaume Chatelet 22bc0fde55 [NFC][libc] Switch mem* tests from ArrayRef to span 2022-08-22 09:58:35 +00:00
Guillaume Chatelet f890f80d67 [libc] Allow span views over mutable data 2022-08-22 09:43:08 +00:00
Guillaume Chatelet e5d5146323 [libc] Allow construction of const span from mutable span 2022-08-22 08:54:31 +00:00
Guillaume Chatelet a1c42cb803 [reland][NFC][libc] Use span instead of ArrayRef 2022-08-22 08:22:38 +00:00
Guillaume Chatelet 70ca9a6600 Revert "[NFC][libc] Use span instead of ArrayRef"
This reverts commit e7b250b8a6.
2022-08-22 08:14:22 +00:00
Guillaume Chatelet e7b250b8a6 [NFC][libc] Use span instead of ArrayRef 2022-08-22 08:09:57 +00:00
Guillaume Chatelet 5541e6bc05 [libc] Add a span facility
This is intended to replace ArrayRef.

Differential Revision: https://reviews.llvm.org/D132254
2022-08-22 07:27:00 +00:00
Guillaume Chatelet f00567eceb [libc][NFC] Move blockstore out of the CPP folder 2022-08-19 21:51:53 +00:00
Guillaume Chatelet e2d7975843 [libc][NFC] Use STL case for bitset and simplify implementation 2022-08-19 21:39:14 +00:00
Guillaume Chatelet d769cd8cdc [reland][libc][NFC] Use STL case for bit 2022-08-19 21:26:26 +00:00
Guillaume Chatelet 175560fc21 Revert "[libc][NFC] Use STL case for bit"
This reverts commit 7ba14b8611.
2022-08-19 21:17:48 +00:00
Guillaume Chatelet 7ba14b8611 [libc][NFC] Use STL case for bit 2022-08-19 21:10:27 +00:00
Siva Chandra Reddy 4d97766316 [libc] Install startup files with the install-libc target.
Differential Revision: https://reviews.llvm.org/D132212
2022-08-19 20:15:16 +00:00
Guillaume Chatelet 7799b5c0e6 [reland][NFC][libc] rearrange aarch64 memset code to better match new implementation
Differential Revision: https://reviews.llvm.org/D132121
2022-08-19 15:31:45 +00:00
Guillaume Chatelet 31fbcccb31 Revert "[NFC][libc] rearrange aarch64 memset code to better match new implementation"
This reverts commit 4d931b6e1e.
2022-08-19 15:02:16 +00:00
Guillaume Chatelet 4d931b6e1e [NFC][libc] rearrange aarch64 memset code to better match new implementation
Differential Revision: https://reviews.llvm.org/D132121
2022-08-19 14:48:17 +00:00
Siva Chandra Reddy 84517b6fb1 [libc] Add more headers to the linux x86_64 and aarch64 configs. 2022-08-19 07:15:08 +00:00
Siva Chandra Reddy 857286f757 [libc][NFC] Change the libc fullbuild target name to "libc". 2022-08-19 07:07:30 +00:00
John Ericson e941b031d3 Revert "[cmake] Use `CMAKE_INSTALL_LIBDIR` too"
This reverts commit f7a33090a9.

Unfortunately this causes a number of failures that didn't show up in my
local build.
2022-08-18 22:46:32 -04:00
John Ericson f7a33090a9 [cmake] Use `CMAKE_INSTALL_LIBDIR` too
We held off on this before as `LLVM_LIBDIR_SUFFIX` conflicted with it.
Now we return this.

`LLVM_LIBDIR_SUFFIX` is kept as a deprecated way to set
`CMAKE_INSTALL_LIBDIR`. The other `*_LIBDIR_SUFFIX` are just removed
entirely.

I imagine this is too potentially-breaking to make LLVM 15. That's fine.
I have a more minimal version of this in the disto (NixOS) patches for
LLVM 15 (like previous versions). This more expansive version I will
test harder after the release is cut.

Reviewed By: sebastian-ne, ldionne, #libc, #libc_abi

Differential Revision: https://reviews.llvm.org/D130586
2022-08-18 15:33:35 -04:00
Vitaly Buka 4e5d64e83e [NFC][libc] Detect HWASAN support macro 2022-08-18 10:19:18 -07:00
Siva Chandra Reddy d20e632853 [libc][Obvious] Update the static archive target name for libc-api-test. 2022-08-17 23:18:33 +00:00
Siva Chandra Reddy e5edd74bb7 [libc] Add a target to install libc in the full build mode.
* In the full build mode, `ninja install-libc` will install the headers as
  well the static archive named libc.a.
* In the default mode, `ninja install-llvmlibc` will only install the
  static archive libllvmlibc.a.

Reviewed By: jeffbailey

Differential Revision: https://reviews.llvm.org/D132015
2022-08-17 22:49:02 +00:00
Siva Chandra Reddy eb0715e3c7 [libc][NFC] Make IntegerToString simpler to use at call-sites.
Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D131943
2022-08-17 07:57:06 +00:00
Siva Chandra Reddy 8e99ad6546 [libc][Obvious] Rearrange few header targets to satisfy dependency order. 2022-08-16 22:33:45 +00:00
Siva Chandra Reddy e17ff7dd2a [libc][Obvious] Convert an add_header target to add_header_library target. 2022-08-16 20:33:24 +00:00
Michael Jones 438d1f18a5 [libc] add guard for file pieces of printf
In the printf_core CMake, the file pieces are defined as object
libraries that depend on the File data structure. If these are added
unconditionally they'll try to evaluate that dependancy even when there
is no File available. This patch adds a guard to prevent that error.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D131921
2022-08-15 15:43:24 -07:00
Michael Jones e0e7fa36d3 [libc] enable s(n)printf without fullbuild
To use the FILE data structure, LLVM-libc must be in fullbuild mode
since it expects its own implementation. This means that (f)printf can't
be used without fullbuild, but s(n)printf only uses strings. This patch
adjusts the CMake to allow for this.

Reviewed By: sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D131913
2022-08-15 13:45:34 -07:00
Michael Jones 0e27dfd560 [libc] add sprintf size comparison
To accurately measure the size of sprintf in a finished binary, the
easiest method is to simply build a binary with and without sprintf.
This patch adds an integration test that can be built with and without
sprintf, as well as targets to build it.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D131735
2022-08-12 11:46:55 -07:00
Siva Chandra Reddy e4efe2cfc6 [libc] Pack memory functions in the integration test libc.a files.
Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D131752
2022-08-12 17:27:26 +00:00
Tue Ly af59bac4ca [libc] Add missing header and Windows entrypoints for tanf. 2022-08-12 09:34:33 -04:00
Tue Ly 82d6e77048 [libc] Implement tanf function correctly rounded for all rounding modes.
Implement tanf function correctly rounded for all rounding modes.

We use the range reduction that is shared with `sinf`, `cosf`, and `sincosf`:
```
  k = round(x * 32/pi) and y = x * (32/pi) - k.
```
Then we use the tangent of sum formula:
```
  tan(x) = tan((k + y)* pi/32) = tan((k mod 32) * pi / 32 + y * pi/32)
         = (tan((k mod 32) * pi/32) + tan(y * pi/32)) / (1 - tan((k mod 32) * pi/32) * tan(y * pi/32))
```
We need to make a further reduction when `k mod 32 >= 16` due to the pole at `pi/2` of `tan(x)` function:
```
  if (k mod 32 >= 16): k = k - 31, y = y - 1.0
```
And to compute the final result, we store `tan(k * pi/32)` for `k = -15..15` in a table of 32 double values,
and evaluate `tan(y * pi/32)` with a degree-11 minimax odd polynomial generated by Sollya with:
```
>  P = fpminimax(tan(y * pi/32)/y, [|0, 2, 4, 6, 8, 10|], [|D...|], [0, 1.5]);
```

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

LIBC reciprocal throughput        : 33.823
LIBC reciprocal throughput        : 25.161     (with `-msse4.2` flag)
LIBC reciprocal throughput        : 19.157     (with `-mfma` flag)

$ CORE_MATH_PERF_MODE="rdtsc" ./perf.sh tanf --latency
GNU libc version: 2.31
GNU libc release: stable
CORE-MATH latency   : 55.630
System LIBC latency : 106.264

LIBC latency        : 96.060
LIBC latency        : 90.727    (with `-msse4.2` flag)
LIBC latency        : 82.361    (with `-mfma` flag)
```

Reviewed By: orex

Differential Revision: https://reviews.llvm.org/D131715
2022-08-12 09:21:05 -04:00
Siva Chandra Reddy 4a738ee822 [libc] Add implemementations of thread specific data related API.
Specifically, POSIX functions pthread_key_create, pthread_key_delete,
pthread_setspecific and pthread_getspecific have been added. The C
standard equivalents tss_create, tss_delete, tss_set and tss_get have
also been added.

Reviewed By: lntue, michaelrj

Differential Revision: https://reviews.llvm.org/D131647
2022-08-12 05:28:40 +00:00
Michael Jones 5e22ef3198 [libc] move int conversion out of base template
The convert_alpha_numeric function is intentionally non-templated so
that its code can be reused for different bases in code-size sensitive
cases. Previously it was inside the IntegerToString class which created
a different version for each base.

Reviewed By: sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D131725
2022-08-11 16:56:27 -07:00
Siva Chandra Reddy 57afb48057 [libc][Obvious] Fix thrd_join's first arg.
First argument to thrd_join was incorrectly listed as a pointer
to a thrd_t value. It should instead be a thrd_t value argument.
2022-08-11 19:18:11 +00:00
Tue Ly 42f183792c [libc] Change sinf/cosf range reduction to mod pi/32 to be shared with tanf.
Change sinf/cosf range reduction to mod pi/32 to be shared with tanf,
since polynomial approximations for tanf on subintervals of length pi/16 do not
provide enough accuracy.

Reviewed By: orex

Differential Revision: https://reviews.llvm.org/D131652
2022-08-11 09:41:45 -04:00
Michael Jones 3510082a1c [libc] move to combined integer converter
The functions converting integers into decimal, hexadecimal, and octal,
are all very similar. This patch moves to a combined converter to save
code size.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D131302
2022-08-10 14:48:30 -07:00
Michael Jones 42e2946f51 [libc][NFC] add arrow operator to optional
Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D131610
2022-08-10 14:47:04 -07:00
Michael Jones 276e108bf9 [libc][NFC] clean int to string static templates
Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D131611
2022-08-10 13:11:29 -07:00
Michael Jones 23ace05e0a [libc] add int to string for extended bases
The default IntegerToString class only supports base 10, this patch adds
a version which supports any base between 2 and 36 inclusive. This will
be used in an upcoming patch.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D131301
2022-08-10 11:28:14 -07:00
Michael Jones 5dd8553423 [libc] Support StringView equality tests
Previously, the integer_to_string tests used EXPECT_TRUE(.equals)
which doesn't have useful error messages. Now they properly check
equality with the EXPECT_EQ macro, which allows for comparing the
strings more naturally.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D131300
2022-08-10 11:23:53 -07:00
Siva Chandra Reddy 0071a79532 [libc] Add implementation of pthread_exit and thrd_exit.
Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D131451
2022-08-10 06:28:47 +00:00
Siva Chandra Reddy 80652d270a [libc][NFC] Fix a few compiler warnings. 2022-08-09 22:30:40 +00:00
Siva Chandra Reddy c6dcc359ac [libc] Add __cxa_atexit support to the atexit function.
Reviewed By: abrachet

Differential Revision: https://reviews.llvm.org/D131219
2022-08-09 21:42:41 +00:00
Siva Chandra Reddy daa44a2309 [libc] Add a utility data structure named FixedVector.
This data structure uses a backing cpp::array object and supports a
vector like push_back API. In comparison with a traditional vector
data structure, it is of a fixed capacity and cannot be resized.

Differential Revision: https://reviews.llvm.org/D131377
2022-08-09 21:29:54 +00:00
Jeff Bailey 7889c41938 [libc] Website fixes (sidebar and mobile)
Add "using" and "status" sections to the sidebar to make getting these
easier.

Fixed mobile formatting not overflow left and right.

Tested:
Chrome on Desktop, using mobile restrictions in devtools.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D131369
2022-08-08 18:38:01 +00:00
Jeff Bailey f493b21e16 [libc] Update look and feel of libc.llvm.org
This design is borrowed from the lldb folks (thank you!) to declutter
the page.

 * The version number at the top is removed.
 * Links are pushed over to a sidebar
 * The sidebar has headings

There are other minor changes:

* The warning about this project not being ready is now an RST "warning"
* Links to the Bug Reports and the Source Code are Added
* Refer to this project as either "The LLVM C LIbrary" or "The libc"

Tested:
Built locally

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D131242
2022-08-05 18:18:40 +00:00
Tue Ly 131dda9acc [libc] Implement sincosf function correctly rounded to all rounding modes.
Refactor common range reductions and evaluations for sinf, cosf, and
sincosf.  Added exhaustive tests for sincosf.

Performance before the patch:
```
System LIBC reciprocal throughput : 30.205
LIBC reciprocal throughput        : 30.533

System LIBC latency : 67.961
LIBC latency        : 61.564
```
Performance after the patch:
```
System LIBC reciprocal throughput : 30.409
LIBC reciprocal throughput        : 20.273

System LIBC latency : 67.527
LIBC latency        : 61.959
```

Reviewed By: orex

Differential Revision: https://reviews.llvm.org/D130901
2022-08-05 09:58:01 -04:00
Jeff Bailey 3b631e47fe [libc] Trivial implementation of std::optional
This class has only the minimum functionality in it to provide what the
TZ variable parsing needs.  In particular, the standard makes guarantees
about how trivial the destructors are, throws an expception if it's used
incorrectly, etc.  There are also missing features.

Tested:
Trivial testsuite added, and use in development.

Reviewed By: gchatelet

Differential Revision: https://reviews.llvm.org/D129920
2022-08-05 02:51:44 +00:00
Tue Ly c308a88716 [libc] Add subtraction for UInt<N> class.
Add subtraction operators (-, -=) for UInt<N> class.

Reviewed By: michaelrj, orex

Differential Revision: https://reviews.llvm.org/D131196
2022-08-04 20:37:43 -04:00
Siva Chandra Reddy 2e4ef9b6ef [libc][NFC] Add a few compiler warning flags.
A bunch of cleanup to supress the new warnings is also done.

Reviewed By: abrachet

Differential Revision: https://reviews.llvm.org/D130723
2022-08-04 23:46:38 +00:00
Tue Ly d1a9ba7b67 [libc] Prevent overflow from intermediate results when adding UInt<N> values.
Prevent overflow from intermediate results when adding UInt<N> values.

Reviewed By: orex

Differential Revision: https://reviews.llvm.org/D131095
2022-08-04 15:01:16 -04:00
Siva Chandra c9e1ecd46d [libc] Adjust aarch64 startup code to reliably sniff out the start args.
Since this now allows, the init/fini array iteration has been added in
a similar fashion to x86_64 and the corresponding test enabled.

Reviewed By: jeffbailey

Differential Revision: https://reviews.llvm.org/D131133
2022-08-03 23:12:02 -07:00
Siva Chandra f0bb276794 [libc] Disable the loader init_fini_array_test for non-x86_64 targets.
Loader for aarch64 will be extended in a future pass and this test will
be enabled back again.
2022-08-03 12:06:13 -07:00
Siva Chandra Reddy f23076f6c5 [libc] Add init and fini array iteration to the loader.
Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D130966
2022-08-03 17:53:23 +00:00
Siva Chandra Reddy 658c84e415 [libc] Add GNU extension functions pthread_setname_np and pthread_getname_np.
Reviewed By: michaelrj, lntue

Differential Revision: https://reviews.llvm.org/D130872
2022-08-02 01:57:03 +00:00
Tue Ly 69cc240534 [libc][doc] Update implementation status of tanhf. 2022-08-01 17:45:40 -04:00
Kirill Okhotnikov 2a558b6bff [libc][math] Build fail fix: obsolete header. 2022-08-01 22:55:15 +02:00
Kirill Okhotnikov 5ef987c985 [libc][math] Added tanhf function.
Correct rounding function. Performance ~2x faster than glibc analog.

Performance (llvm 12 intel):
```
CORE_MATH_PERF_MODE=rdtsc PERF_ARGS='' ./perf.sh tanhf
GNU libc version: 2.31
GNU libc release: stable
13.279
37.492
18.145
CORE_MATH_PERF_MODE=rdtsc PERF_ARGS='--latency' ./perf.sh tanhf
GNU libc version: 2.31
GNU libc release: stable
40.658
109.582
66.568
```

Differential Revision: https://reviews.llvm.org/D130780
2022-08-01 22:43:00 +02:00
Guillaume Chatelet 49eb58063f [libc][NFC] Use STL case for utility
Migrating all private STL code to the standard STL case but keeping it under the CPP namespace to avoid confusion.

Differential Revision: https://reviews.llvm.org/D130771
2022-08-01 09:27:37 +00:00
Guillaume Chatelet 91eb0b6584 [libc][NFC] Use STL case for limits
Migrating all private STL code to the standard STL case but keeping it under the CPP namespace to avoid confusion.

Differential Revision: https://reviews.llvm.org/D130762
2022-08-01 09:18:25 +00:00
Guillaume Chatelet 3f3bbd7370 [libc][NFC] Use STL case for functional
Migrating all private STL code to the standard STL case but keeping it under the CPP namespace to avoid confusion.

Differential Revision: https://reviews.llvm.org/D130760
2022-08-01 09:10:59 +00:00
Guillaume Chatelet d3d498fbf6 Reland [libc][NFC] Use STL case for array
This is a reland of https://reviews.llvm.org/D130773
2022-08-01 08:47:27 +00:00
Guillaume Chatelet de00bd573e Revert "[libc][NFC] Use STL case for array"
This reverts commit 7add0e5fdc.
2022-08-01 08:44:52 +00:00
Guillaume Chatelet 7add0e5fdc [libc][NFC] Use STL case for array
Migrating all private STL code to the standard STL case but keeping it under the CPP namespace to avoid confusion.

Differential Revision: https://reviews.llvm.org/D130773
2022-08-01 08:43:05 +00:00
Siva Chandra Reddy 89e5c20ca9 [libc][NFC] Mark a constructor of StringView to be constexpr. 2022-08-01 07:13:20 +00:00
Siva Chandra Reddy f1d274b5c6 [libc][NFC] Make the buffer size of the integer to string converter public.
This allows users of the IntegerToString class to size their buffers
appropriately at compile time.
2022-08-01 06:54:17 +00:00
Siva Chandra Reddy d52e8708ae [libc][NFC] Mark a few methods of StringView to constexpr. 2022-08-01 06:06:49 +00:00
Tue Ly 17df74214c [libc][doc] Update implementation status of exp2f, sinhf, and coshf. 2022-07-31 16:32:21 -04:00
Siva Chandra Reddy 12df3080fe [libc] Compile integration tests with -ffreestanding to avoid mixup with system libc. 2022-07-30 03:06:08 +00:00
Tue Ly 2ff187fbc9 [libc] Implement cosf function that is correctly rounded to all rounding modes.
Implement cosf function that is correctly rounded to all rounding
modes.

Performance benchmark using perf tool from CORE-MATH project

(https://gitlab.inria.fr/core-math/core-math/-/tree/master) on Ryzen 1700:
Before this patch (not correctly rounded):
```
$ CORE_MATH_PERF_MODE="rdtsc" ./perf.sh cosf
CORE-MATH reciprocal throughput   : 19.043
System LIBC reciprocal throughput : 26.328
LIBC reciprocal throughput        : 30.955

$ CORE_MATH_PERF_MODE="rdtsc" ./perf.sh cosf --latency
GNU libc version: 2.31
GNU libc release: stable
CORE-MATH latency   : 49.995
System LIBC latency : 59.286
LIBC latency        : 60.174

```
After this patch (correctly rounded):
```
$ CORE_MATH_PERF_MODE="rdtsc" ./perf.sh cosf
GNU libc version: 2.31
GNU libc release: stable
CORE-MATH reciprocal throughput   : 19.072
System LIBC reciprocal throughput : 26.286
LIBC reciprocal throughput        : 13.631

$ CORE_MATH_PERF_MODE="rdtsc" ./perf.sh cosf --latency
GNU libc version: 2.31
GNU libc release: stable
CORE-MATH latency   : 49.872
System LIBC latency : 59.468
LIBC latency        : 56.119
```

Reviewed By: orex, zimmermann6

Differential Revision: https://reviews.llvm.org/D130644
2022-07-29 21:08:31 -04:00
Kirill Okhotnikov a7f55f0805 [libc][math] Added sinhf function.
Differential Revision: https://reviews.llvm.org/D129278
2022-07-29 17:20:53 +02:00
Kirill Okhotnikov fcb9d7e2cf [libc][math] Added coshf function.
Differential Revision: https://reviews.llvm.org/D129275
2022-07-29 16:57:28 +02:00
Guillaume Chatelet 0c3037dfc5 [libc] Fix prototype_test_gen 2022-07-29 10:18:54 +00:00
Guillaume Chatelet e5e0e7963c [libc] Fix prototype_test_gen 2022-07-29 10:07:34 +00:00
Guillaume Chatelet 039fb3e5a1 Fix typo in FPUtil/aarch64/FMA.h 2022-07-29 10:04:11 +00:00
Guillaume Chatelet f72261508a [libc][NFC] Use STL case for type_traits
Migrating all private STL code to the standard STL case but keeping it under the CPP namespace to avoid confusion. Starting with the type_traits header.

Differential Revision: https://reviews.llvm.org/D130727
2022-07-29 09:57:03 +00:00
Kirill Okhotnikov 4b41e7b436 [libc][math] Universal exp function for cosh/sinh calculation.
Added a function and test, which can be used later for cosh/sinh
and possibly for expf/expm1f.

Differential Revision: https://reviews.llvm.org/D129215
2022-07-28 11:24:09 +02:00
Kirill Okhotnikov c78144e1c7 [libc][math] Improved performance of exp2f function.
New exp2 function algorithm:
1) Improved performance: 8.176 vs 15.270 by core-math perf tool.
2) Improved accuracy. Only two special values left.
3) Lookup table size reduced twice.

Differential Revision: https://reviews.llvm.org/D129005
2022-07-28 10:57:16 +02:00
Tue Ly 15b9380dfd [libc] Change sinf range reduction to mod pi/16 to be shared with cosf.
Change `sinf` range reduction to mod pi/16 to be shared with `cosf`.

Previously, `sinf` used range reduction `mod pi`, but this cannot be used to implement `cosf` since the minimax algorithm for `cosf` does not converge due to critical points at `pi/2`.  In order to be able to share the same range reduction functions for both `sinf` and `cosf`, we change the range reduction to `mod pi/16` for the following reasons:
- The table size is sufficiently small: 32 entries for `sin(k * pi/16)` with `k = 0..31`.  It could be reduced to 16 entries if we treat the final sign separately, with an extra multiplication at the end.
- The polynomials' degrees are reduced to 7/8 from 15, with extra computations to combine `sin` and `cos` with trig sum equality.
- The number of exceptional cases reduced to 2 (with FMA) and 3 (without FMA).
- The latency is reduced while maintaining similar throughput as before.

Reviewed By: zimmermann6

Differential Revision: https://reviews.llvm.org/D130629
2022-07-27 12:23:36 -04:00
Tue Ly 628fbbef81 [libc] Use nearest_integer instructions to improve expm1f performance.
Use nearest_integer instructions to improve expf performance.

Performance tests with CORE-MATH's perf tool:

Before the patch:
```
$ ./perf.sh expm1f
LIBC-location: /home/lnt/experiment/llvm/llvm-project/build/projects/libc/lib/libllvmlibc.a
GNU libc version: 2.31
GNU libc release: stable
CORE-MATH reciprocal throughput   : 10.096
System LIBC reciprocal throughput : 44.036
LIBC reciprocal throughput        : 11.575

$ ./perf.sh expm1f --latency
LIBC-location: /home/lnt/experiment/llvm/llvm-project/build/projects/libc/lib/libllvmlibc.a
GNU libc version: 2.31
GNU libc release: stable
CORE-MATH latency   : 42.239
System LIBC latency : 122.815
LIBC latency        : 50.122
```
After the patch:
```
$ ./perf.sh expm1f
LIBC-location: /home/lnt/experiment/llvm/llvm-project/build/projects/libc/lib/libllvmlibc.a
GNU libc version: 2.31
GNU libc release: stable
CORE-MATH reciprocal throughput   : 10.046
System LIBC reciprocal throughput : 43.899
LIBC reciprocal throughput        : 9.179

$ ./perf.sh expm1f --latency
LIBC-location: /home/lnt/experiment/llvm/llvm-project/build/projects/libc/lib/libllvmlibc.a
GNU libc version: 2.31
GNU libc release: stable
CORE-MATH latency   : 42.078
System LIBC latency : 120.488
LIBC latency        : 41.528
```

Reviewed By: zimmermann6

Differential Revision: https://reviews.llvm.org/D130502
2022-07-26 09:12:37 -04:00
Tue Ly 91ee672062 [libc] Use nearest_integer instructions to improve expf performance.
Use nearest_integer instructions to improve expf performance.

Performance tests with CORE-MATH's perf tool:

Before the patch:
```
$ ./perf.sh expf
LIBC-location: /home/lnt/experiment/llvm-project/build/projects/libc/lib/libllvmlibc.a
GNU libc version: 2.31
GNU libc release: stable
CORE-MATH reciprocal throughput   : 9.860
System LIBC reciprocal throughput : 7.728
LIBC reciprocal throughput        : 12.363

$ ./perf.sh expf --latency
LIBC-location: /home/lnt/experiment/llvm-project/build/projects/libc/lib/libllvmlibc.a
GNU libc version: 2.31
GNU libc release: stable
CORE-MATH latency   : 42.802
System LIBC latency : 35.941
LIBC latency        : 49.808
```

After the patch:
```
$ ./perf.sh expf
LIBC-location: /home/lnt/experiment/llvm/llvm-project/build/projects/libc/lib/libllvmlibc.a
GNU libc version: 2.31
GNU libc release: stable
CORE-MATH reciprocal throughput   : 9.441
System LIBC reciprocal throughput : 7.382
LIBC reciprocal throughput        : 8.843

$ ./perf.sh expf --latency
LIBC-location: /home/lnt/experiment/llvm/llvm-project/build/projects/libc/lib/libllvmlibc.a
GNU libc version: 2.31
GNU libc release: stable
CORE-MATH latency   : 44.192
System LIBC latency : 37.693
LIBC latency        : 44.145
```

Reviewed By: zimmermann6

Differential Revision: https://reviews.llvm.org/D130498
2022-07-26 09:11:27 -04:00