Commit Graph

1336 Commits

Author SHA1 Message Date
Tue Ly
05727d94de [libc][Obvious] Fix typos in LLVMLibCArchitectures.cmake defining target architectures.
Fix typos in LLVMLibCArchitectures.cmake defining target architectures.

Differential Revision: https://reviews.llvm.org/D141314
2023-01-09 15:53:22 -05:00
Alex Brachet
3af4e4031d Revert "[libc] Templatize str{,n}cmp"
This reverts commit c6dcbed2e5.

Broke tests on arm and aarch64
2023-01-09 20:24:16 +00:00
Alex Brachet
dc1b614bb8 [libc] Move b* string functions to strings.h
Traditionally these functions are exposed in string*s*.h not string.h

Differential Revision: https://reviews.llvm.org/D141237
2023-01-09 20:16:20 +00:00
Alex Brachet
c6dcbed2e5 [libc] Templatize str{,n}cmp
This will be used to implement the case insensitive str{,n}casecmp

Differential Revision: https://reviews.llvm.org/D141235
2023-01-09 20:13:02 +00:00
Tue Ly
9e5fde59a4 [libc][Obvious] Temporarily disable log10_test for further investigation. 2023-01-08 18:21:30 -05:00
Tue Ly
1b9c21fda9 [libc][Obvious] Remove constexpr fomr exact_mult in double_double.h 2023-01-08 17:52:46 -05: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
Siva Chandra Reddy
8304f6de94 [libc] Add a separate install target for the libc static archives.
Also, skip installing startup objects for baremetal targets for now.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D141112
2023-01-06 23:32:07 +00:00
Michael Jones
9b8a64b88d [libc] add noexcept to external function headers
To improve code generation for C++ code that directly includes our
headers, the external function definitions will now be marked noexcept.
This may not be necessary for the internal definitions since we build
with the -fno-exceptions flag.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D141095
2023-01-06 11:43:43 -08: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
Guillaume Chatelet
abcdc26a81 [libc] get_table_negative cannot be constexpr
GCC complains about if conditions not being constant expressions.
As-is get_table_negative cannot be marked constexpr.

Differential Revision: https://reviews.llvm.org/D140967
2023-01-05 14:28:50 +00:00
Guillaume Chatelet
79c730218e [libc] Fix invalid constructor declaration 2023-01-05 14:01:37 +00:00
Guillaume Chatelet
c25af9bb1e [libc][NFC] Use a function instead of templated static member functions for TYPE_DESC
I'm surprised that clang accepts the current code.
It seems odd to me to specialize templated static member variables.

GCC rejects them: https://godbolt.org/z/3ecE9Ps7T

This patch is in the context of https://github.com/llvm/llvm-project/issues/59368

Differential Revision: https://reviews.llvm.org/D140981
2023-01-05 10:02:57 +00:00
Guillaume Chatelet
feb0778862 [libc][NFC] Remove unused variable 2023-01-04 15:27:04 +00:00
Siva Chandra Reddy
fa715e2dad [libc][NFC] Remove a constexpr marking to fix GCC build. 2023-01-03 18:00:57 +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
Guillaume Chatelet
4e9ac30816 [reland][libc][NFC] Add -fno-lax-vector-conversions compilation flag
Now that a3d2c344773cc4fc95136fd67245880b34d8e335 has been submitted.
2022-12-27 10:32:41 +00:00
Guillaume Chatelet
56ab6f783b [libc][NFC] Fix lax vector conversion for aarch64 2022-12-27 10:16:37 +00:00
Guillaume Chatelet
d065472c9e Revert "[libc][NFC] Add -fno-lax-vector-conversions compilation flag"
This breaks aarch64 build.

This reverts commit 32f4c3f103.
2022-12-27 08:30:19 +00:00
Guillaume Chatelet
32f4c3f103 [libc][NFC] Add -fno-lax-vector-conversions compilation flag 2022-12-27 08:25:32 +00:00
Siva Chandra Reddy
c89db6ad39 [libc][obvious] Remove a spurious statement leftover from a previous change. 2022-12-23 06:50:28 +00:00
Siva Chandra Reddy
f112960190 [libc][NFC] Use operator new and operator delete in POSIX file actions API.
Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D140597
2022-12-23 05:58:25 +00:00
Siva Chandra Reddy
f9868aa729 [libc][NFC] Use operator delete to cleanup a File object.
The File API has been refactored to allow cleanup using operator delete.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D140574
2022-12-22 22:31:06 +00:00
Michael Jones
a484c9bd2e [libc][obvious] fix errno for 32 bit long test
one of the tests in StrtolTest.h is intended to detect that 32 bit longs
are handled correctly, but it wasn't using the correct value for errno
causing failures.

Differential Revision: https://reviews.llvm.org/D140577
2022-12-22 12:02:38 -08:00
Siva Chandra Reddy
d06308df8b [libc] Handle allocation failures gracefully in FILE related API.
Few uses of free have not yet been replaced by the custom operator
delete yet. They will be done in a follow up patch.

Reviewed By: lntue, michaelrj

Differential Revision: https://reviews.llvm.org/D140526
2022-12-22 19:30:16 +00:00
Michael Jones
39f370aefd [libc] change str to int tests to be templated
Previously the tests were copy/pasted into several files, this changes
them to be instead templated and sharing one file.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D140441
2022-12-22 10:40:24 -08:00
Michael Jones
5112651826 [libc] add exponent format to printf
Add support for the %e/E conversion in printf, as well as unit tests. It
does not yet support long doubles.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D140042
2022-12-22 10:20:59 -08:00
Siva Chandra Reddy
b5415f3015 [libc][Obvious] Fix an off-by-one error introduced by eb9cc253cb. 2022-12-21 21:11:08 +00:00
Siva Chandra Reddy
eb9cc253cb [libc] Gracefully handle allocation failures around BlockStore.
Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D140459
2022-12-21 21:05:09 +00:00
Siva Chandra Reddy
c2f17bfbff [libc][NFC] Use the custom operator new from strndup.
Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D140461
2022-12-21 20:58:40 +00:00
Siva Chandra Reddy
e5ae5cec06 [libc][Obvious] Remove the unused cpp::vector class.
This can be easily resurrected if required in future. It calls malloc
directly. So, instead of updating an unused piece to the newer pattern
of using the custom operator new, this patch just deletes it.
2022-12-20 23:26:12 +00:00
Siva Chandra Reddy
3beb054170 [libc] Add a baremetal config.
The config currently includes ctype, math, stdlib, inttypes and string
functions.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D140378
2022-12-20 19:43:45 +00:00
Joseph Huber
ae20ff7526 [libc] Add check for locally installed GPUs
We need to know which, if any, GPUs the user has on their system if we
want to be able to test the `libc` source code for the GPU. This patch
adds a basic check using the `amdgpu-arch` utility which is provided by
`clang`.

Checking for NVIDIA GPUs will be done later as this is a little
problematic right now. CMake provides a method that we use for Clang but
it will soon be deprecated, the replacement requires a newer CMake
version that we will have in the LLVM 17 branch in the future. CUDA also
provides `__nvcc_device_query` but it's very new so I'm not sure if we
should rely on it. I may introduce a new tool to do it similar to
`amdgpu-arch`.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D140422
2022-12-20 13:37:11 -06:00
Siva Chandra Reddy
740db97ad1 [libc][NFC] Simplify how the definiton of NULL macro is added to string.h.
We do not list macro definitions in api.td files anymore. Not all macros
definitions have been moved out. This change moves the definition of the
NULL macro out.

Reviewed By: lntue, jhuber6

Differential Revision: https://reviews.llvm.org/D140376
2022-12-20 19:14:27 +00:00
Siva Chandra Reddy
5e750b86ca [libc] Simplify generation of errno.h.
Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D140375
2022-12-20 19:04:13 +00:00
Michael Jones
f1990feb35 [libc] add fuzz target for strtointeger functions
The string to integer conversion functions are well suited to
differential fuzzing, and this patch adds a target to enable just that.
It also fixes a bug in the fuzzing comparison logic and changes atoi
slightly to match the behavior described in the C standard.

Reviewed By: sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D140178
2022-12-20 10:48:34 -08:00
Michael Jones
ce4d6717f8 [libc][NFC] make atoi undefined cases match std
The standard describes atoi as:

"equivalent to atoi: (int)strtol(nptr, (char **)NULL, 10)"

Previously, our behavior was slightly different on numbers larger than
INT_MAX, but this patch changes it to just do the cast instead. Both of
these are valid since the standard says

"If the value of the result cannot be represented, the
behavior is undefined."

But matching existing behavior makes differential fuzzing easier.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D140350
2022-12-20 10:21:25 -08:00
Archibald Elliott
2a261a7b57 [libc] Add Missing TargetParser Dependency 2022-12-20 11:31:14 +00:00
Archibald Elliott
f09cf34d00 [Support] Move TargetParsers to new component
This is a fairly large changeset, but it can be broken into a few
pieces:
- `llvm/Support/*TargetParser*` are all moved from the LLVM Support
  component into a new LLVM Component called "TargetParser". This
  potentially enables using tablegen to maintain this information, as
  is shown in https://reviews.llvm.org/D137517. This cannot currently
  be done, as llvm-tblgen relies on LLVM's Support component.
- This also moves two files from Support which use and depend on
  information in the TargetParser:
  - `llvm/Support/Host.{h,cpp}` which contains functions for inspecting
    the current Host machine for info about it, primarily to support
    getting the host triple, but also for `-mcpu=native` support in e.g.
    Clang. This is fairly tightly intertwined with the information in
    `X86TargetParser.h`, so keeping them in the same component makes
    sense.
  - `llvm/ADT/Triple.h` and `llvm/Support/Triple.cpp`, which contains
    the target triple parser and representation. This is very intertwined
    with the Arm target parser, because the arm architecture version
    appears in canonical triples on arm platforms.
- I moved the relevant unittests to their own directory.

And so, we end up with a single component that has all the information
about the following, which to me seems like a unified component:
- Triples that LLVM Knows about
- Architecture names and CPUs that LLVM knows about
- CPU detection logic for LLVM

Given this, I have also moved `RISCVISAInfo.h` into this component, as
it seems to me to be part of that same set of functionality.

If you get link errors in your components after this patch, you likely
need to add TargetParser into LLVM_LINK_COMPONENTS in CMake.

Differential Revision: https://reviews.llvm.org/D137838
2022-12-20 11:05:50 +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
Joseph Huber
4293af5ebc [libc] Fix full build check for the GPU build
Summary:
This condition should fire when the full build is set OFF instead of
when it is ON.
2022-12-19 14:42:55 -06:00
Siva Chandra Reddy
8d681955b8 [libc][gpu][NFC] Move CMake logic to prepare GPU build to a separate file.
Reviewed By: jhuber6

Differential Revision: https://reviews.llvm.org/D140309
2022-12-19 18:20:10 +00:00
Guillaume Chatelet
93ac449369 [libc] Make string functions buildable with GCC
Differential Revision: https://reviews.llvm.org/D139939
2022-12-18 14:56:01 +00:00
Guillaume Chatelet
6d9d387f73 Use -Wstrict-prototypes with clang only 2022-12-18 15:54:21 +01:00
Siva Chandra Reddy
70432da8db [libc][Obvious] Add missing deps for a few targets. 2022-12-17 00:20:34 +00:00
Siva Chandra Reddy
9b29436a1c [libc] Handle allocation failures in the dirent API gracefully.
Along the way, setting of errno has been moved out of the internal code.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D140078
2022-12-15 21:05:40 +00:00
Michael Jones
c4b7e8a035 [libc] fix shifting exact multiples of 64 in uint
The internal uint class had a bug introduced recently when optimizing
the shift routines. When calculating the value of a block, it would
shift an adjacent block by 64 - the shift amount. If the shift amount
was 0, this would be a shift of 64, which is undefined for a 64 bit
integer. This patch fixes this by adding a conditional to catch this
case.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D140070
2022-12-15 13:01:32 -08:00