Commit Graph

97 Commits

Author SHA1 Message Date
Tue Ly
9af8dca70f [libc][math] Update range reduction step for log10f and reduce its latency.
Simplify the range reduction steps by choosing the reduction constants
carefully so that the reduced arguments v = r*m_x - 1 and v^2 are exact in double
precision, even without FMA instructions, and -2^-8 <= v < 2^-7.  This allows the
polynomial evaluations to be parallelized more efficiently.

Reviewed By: zimmermann6

Differential Revision: https://reviews.llvm.org/D147676
2023-04-07 10:31:46 -04:00
Siva Chandra Reddy
08b9835072 [libc][docs] Add a section about allocations and deallocations to the style doc.
Fixes #59277 - The main part of that bug has already been addressed. This commit
just adds documentation.

Reviewed By: jeffbailey

Differential Revision: https://reviews.llvm.org/D146115
2023-03-15 20:41:51 -07:00
Siva Chandra Reddy
be721a38c6 [libc][docs] Move the link to "Compiler Support" under "Status".
Also, fixed a minor typo in compiler_support.rst.

Reviewed By: jeffbailey, gchatelet

Differential Revision: https://reviews.llvm.org/D146112
2023-03-15 20:41:10 -07:00
Jeff Bailey
1b89aeb517 [libc] Add instructions for linux headers
Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D146049
2023-03-15 03:02:16 +00:00
Jeff Bailey
ea471e2aa8 [libc] Update cross-compilation instructions
* Add various options so that it uses the build lld and compiler-rt
 * Add instructions on how to use the newly built libc
 * Remove trailing comments in code-block for cut and pastability

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D145878
2023-03-14 05:31:20 +00:00
Michael Jones
08df6c78b5 [libc][docs] update list of completed stdio funcs
Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D145633
2023-03-09 10:44:50 -08:00
Michael Jones
60178f04fc [libc][docs] add link to join the discord
Previously we only linked to the channel within the discord.

Differential Revision: https://reviews.llvm.org/D145283
2023-03-07 16:33:27 -08:00
Siva Chandra Reddy
4155503b71 [libc] Add a note about using assertions in the libc runtime code.
Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D145466
2023-03-07 10:16:50 -08:00
Siva Chandra Reddy
4052bc8674 [libc] Make errno an entrypoint.
The entrypoint has been added to the various entrypoint lists. The libc
code style doc has been updated with information on how errno should be
set from the libc runtime code.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D145179
2023-03-03 06:59:19 +00:00
Siva Chandra Reddy
54faf22f7b [libc][NFC] Move all developer docs into a sub-directory docs/dev. 2023-03-02 10:59:49 -08:00
Tue Ly
6c7894a8e6 [libc][doc] Move docs/math.rst to docs/math/index.rst
Move docs/math.rst to docs/math/index.rst

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D144028
2023-02-14 13:41:44 -05:00
Renyi Chen
6cb14adbfa [libc][math] Implement scalbn, scalbnf, scalbnl.
Implement scalbn via `fptuil::ldexp` for `FLT_RADIX==2` case.
"unimplemented" otherwise.

Reviewed By: lntue, sivachandra

Differential Revision: https://reviews.llvm.org/D143116
2023-02-09 05:55:34 +00:00
Guillaume Chatelet
a2569a76e0 [libc][NFC] Rename macros 2023-02-07 20:43:33 +00:00
Guillaume Chatelet
83e98c8556 [libc][doc] Update compiler
Differential Revision: https://reviews.llvm.org/D143389
2023-02-07 09:32:34 +00:00
Guillaume Chatelet
c1832e903e [libc][doc] Add macros guidelines
This is a first follow up on the libc tuning RFC
https://discourse.llvm.org/t/rfc-llvm-libc-tuning/67980

Once we agree on the format. I'll land a couple of patches to match the guidelines.

Differential Revision: https://reviews.llvm.org/D143413
2023-02-07 09:29:36 +00:00
Tue Ly
a48c4a45e0 [libc][Obvious] Change ninja llvmlibc to ninja libc in the documentations. 2023-02-03 15:16:01 -05:00
Tue Ly
1ad8d9d66d [libc][bazel] Add bazel targets and unit tests for math functions.
Add bazel targets and unit tests for single precision exponential,
logarithm, trigonometric, inverse trig, hyperbolic, and inverse hyperbolic
functions.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D143275
2023-02-03 15:11:20 -05:00
David Spickett
008acfb519 [libc] Fix quotation marks in overlay mode instructions
These were using ” ("right double quotation mark") instead of
the usual ". This means CMake took the value literally and you
got:
```
CMake Error at CMakeLists.txt:139 (MESSAGE):
  ”libc” isn't a known project:
  bolt;clang;clang-tools-extra;compiler-rt;cross-project-tests;libc;libclc;lld;lldb;mlir;openmp;polly;pstl;flang.
  Did you mean to enable it as a runtime in LLVM_ENABLE_RUNTIMES?
```
`="libc"` works fine.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D143254
2023-02-03 14:44:40 +00:00
Tue Ly
9b30f6b6d7 [libc][math] Implement acoshf function correctly rounded to all rounding modes.
Implement acoshf function correctly rounded to all rounding modes.

Reviewed By: zimmermann6

Differential Revision: https://reviews.llvm.org/D142781
2023-02-01 11:35:15 -05:00
Tue Ly
46b15fd19e [libc][math] Implement asinhf function correctly rounded for all rounding modes.
Implement asinhf function correctly rounded for all rounding modes.

Reviewed By: zimmermann6

Differential Revision: https://reviews.llvm.org/D142681
2023-01-27 11:12:27 -05:00
Siva Chandra Reddy
05d9cc4799 [libc][NFC] Replace "inline" keyword with "LIBC_INLINE".
This is the first of patches doing similar cleanup. A section in the
code style doc has been added explaining where and how LIBC_INLINE is to
be used.

Reviewed By: jeffbailey, lntue

Differential Revision: https://reviews.llvm.org/D142434
2023-01-24 19:35:34 +00:00
Tue Ly
5814b7b279 [libc][math] Implement log10 function correctly rounded for all rounding modes
Implement double precision log10 function correctly rounded for all
rounding modes.  This implementation currently needs FMA instructions for
correctness.

Use 2 passes:
Fast pass:
- 1 step range reduction with a lookup table of `2^7 = 128` elements to reduce the ranges to `[-2^-7, 2^-7]`.
- Use a degree-7 minimax polynomial generated by Sollya, evaluated using a mixed of double-double and double precisions.
- Apply Ziv's test for accuracy.
Accurate pass:
- Apply 5 more range reduction steps to reduce the ranges further to [-2^-27, 2^-27].
- Use a degree-4 minimax polynomial generated by Sollya, evaluated using 192-bit precisions.
- By the result of Lefevre (add quote), this is more than enough for correct rounding to all rounding modes.

In progress: Adding detail documentations about the algorithm.

Depend on: https://reviews.llvm.org/D136799

Reviewed By: zimmermann6

Differential Revision: https://reviews.llvm.org/D139846
2023-01-08 17:41:54 -05:00
Guillaume Chatelet
062a7ea591 [libc] Add a section about supported compilers in the documentation
Context https://github.com/llvm/llvm-project/issues/59368

Differential Revision: https://reviews.llvm.org/D141045
2023-01-06 09:30:50 +00:00
Siva Chandra Reddy
fbe0b51767 [libc] Make the sidebar colors have a higher constract in the white background.
Reviewed By: jeffbailey

Differential Revision: https://reviews.llvm.org/D141039
2023-01-05 09:43:59 -08:00
Siva Chandra Reddy
36de85f93f [libc] Add document for a recipe to do a full standalone cross-build.
Reviewed By: jeffbailey

Differential Revision: https://reviews.llvm.org/D141037
2023-01-05 09:37:21 -08:00
Jeff Bailey
6e5c35819e [libc] Add documentation on hacking with vscode
Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D140826
2023-01-05 17:27:32 +00:00
Jeff Bailey
bc09f1e5c3 [libc] [nfc] Fix heading underline.
Differential Revision: https://reviews.llvm.org/D140825
2023-01-01 20:53:10 +00:00
Siva Chandra Reddy
4f9c10eb48 [libc] Add support for standalone cross compilation of libc.
One should be able to do a cross build of the libc now. For example, using
clang on a x86_64 linux host, one can build for an aarch64 linux target by
specifying -DLIBC_TARGET_TRIPLE=aarch64-linux-gnu.

Follow up changes will add a baremetal config and also appropriate
documentation about cross compiling the libc for CPU targets.

Reviewed By: jhuber6

Differential Revision: https://reviews.llvm.org/D140351
2022-12-20 00:33:35 +00:00
Siva Chandra Reddy
9a07780687 [libc][NFC] Rename "loader" to "startup".
Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D140049
2022-12-15 19:54:21 +00:00
Guillaume Chatelet
436c8f4420 [reland][libc] Add bcopy
Differential Revision: https://reviews.llvm.org/D138994
2022-12-01 10:07:04 +00:00
Guillaume Chatelet
c5fe7eb216 Revert D138994 "[libc] Add bcopy"
Broke build bot

This reverts commit 186a15f7a9.
2022-12-01 09:55:36 +00:00
Guillaume Chatelet
186a15f7a9 [libc] Add bcopy
Differential Revision: https://reviews.llvm.org/D138994
2022-12-01 09:52:10 +00:00
Joseph Huber
db923a610b [libc][docs] Fix code block not being emitted 2022-11-30 09:33:40 -06:00
Joseph Huber
194788b2fd [libc][docs] Add documentation for the new GPU mode
This patch introduces documentation for the new GPU mode added in
D138608. The documentation includes instructions for building and using
the library, along with a description of the supported functions and
headers.

Reviewed By: sivachandra, lntue, michaelrj

Differential Revision: https://reviews.llvm.org/D138856
2022-11-29 14:51:55 -06:00
Raman Tenneti
78f172e45a [libc] Implement gettimeofday
Implement gettimeofday per
.../onlinepubs/9699919799/functions/gettimeofday.html.
This call clock_gettime to implement gettimeofday function.

Tested:
Limited unit test: This makes a call and checks that no error was
returned. Used nanosleep for 100 microseconds and verfified it
returns a value that elapses more than 100 microseconds and less
than 300 microseconds.

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

Differential Revision: https://reviews.llvm.org/D137881
2022-11-11 18:02:33 -08:00
Siva Chandra Reddy
b12c677033 [libc][docs] Add a build and test document. 2022-11-05 01:06:01 -07:00
Siva Chandra Reddy
64821f178e [libc][docs] Fix typos. 2022-11-05 00:21:09 -07:00
Siva Chandra Reddy
1bb6f1bb8f [libc][docs] Move links to internal developer guides out of the main side bar.
The links are all now from a "Developer Guides" page which is linked from the
main side bar.
2022-11-05 00:04:50 -07:00
Siva Chandra Reddy
136b927c9e [libc] Add a doc about the libc fullbuild mode.
Reviewed By: jeffbailey

Differential Revision: https://reviews.llvm.org/D137061
2022-11-02 08:18:48 -07:00
Siva Chandra Reddy
f7fd4f319a [libc] Add links to libc Discourse and to the libc Discord channel.
Reviewed By: jeffbailey

Differential Revision: https://reviews.llvm.org/D137229
2022-11-02 08:03:53 -07:00
Siva Chandra Reddy
a2a87ee7e9 [libc] Add a contributing guide to the docs.
Reviewed By: jeffbailey

Differential Revision: https://reviews.llvm.org/D136961
2022-11-02 08:02:11 -07:00
Siva Chandra Reddy
9dd7388668 [libc] Add a porting guide to the docs.
Reviewed By: jeffbailey

Differential Revision: https://reviews.llvm.org/D136960
2022-11-02 07:59:07 -07:00
Siva Chandra
227eb3d72d [libc] Cleanup stale documentation. 2022-10-26 22:53:15 -07:00
Siva Chandra Reddy
89ba240f4b [libc] Add a doc about the libc overlay mode.
Reviewed By: jeffbailey

Differential Revision: https://reviews.llvm.org/D136810
2022-10-26 21:53:29 -07:00
Raman Tenneti
12204429f2 [libc] Add implementation of difftime function.
The difftime function computes the difference between two calendar
times: time1 - time0 as per as per 7.27.2.2 section in
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2478.pdf.

  double difftime(time_t time1, time_t time0);

Tested:
Unit tests

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

Reviewed By: jeffbailey

Differential Revision: https://reviews.llvm.org/D136631
2022-10-24 15:14:26 -07:00
Jeff Bailey
7caae24473 [libc]Identify which processors are completed for Math
Switch from green checkmarks to the following legend:

X = x86_64
A = aarch64
a = arm32

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D136020
2022-10-18 03:12:44 +00:00
Jeff Bailey
998d1ebb27 [libc][cleanup] Docs clean up
* Make consistent heading names
 * Factor out |check| into an include for reuse
 * Use it everywhere (No more YES or UTF-8)
 * Remove unneeded summary from pages. People know why they're there.
 * Ensure source location headers everywhere.

Differential Revision: https://reviews.llvm.org/D136016
2022-10-15 15:29:48 +00:00
Jeff Bailey
aa8ab5b213 [libc] Document which date funcs are needed/done
Reviewed By: rtenneti

Differential Revision: https://reviews.llvm.org/D135501
2022-10-08 00:06:22 +00: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
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