Commit Graph

840 Commits

Author SHA1 Message Date
Michael Jones e072a123d3 [libc] add printf writer
The printf implmentation is made up of three main pieces, the parser,
the converter, and the writer. This patch adds the implementation for
the writer, as well as the function for writing to a string, along with
tests.

Reviewed By: sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D124421
2022-05-03 10:15:04 -07:00
Michael Jones 5d1dbe1119 [libc] fix strtold tests on 32 bit systems
This patch fixes the string to long double tests for systems that use
long double is double, and don't support uint128.

Reviewed By: sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D124803
2022-05-03 10:07:21 -07:00
Siva Chandra Reddy 9db0037bf1 [libc] Add implementations of feof, ferror and clearerr.
The corresponding _unlocked functions have also been added.

Reviewed By: lntue, michaelrj

Differential Revision: https://reviews.llvm.org/D124311
2022-04-29 23:04:35 +00:00
Dominic Chen ce6bfd102a [libc] Support 32-bit ARM platform tests
Set LONG_DOUBLE_IS_DOUBLE, add ifdefs for 128-bit integer types

Differential Revision: https://reviews.llvm.org/D124204
2022-04-28 12:00:28 -07:00
Dominic Chen 684b1f03e3 Fix [libc] Minor test signedness fixes
Add namespace specifier

Differential Revision: https://reviews.llvm.org/D124468
2022-04-26 17:14:52 -07:00
Dominic Chen de94cf5286 [libc] Minor test signedness fixes
Resolve compiler warnings about signed conversion

Differential Revision: https://reviews.llvm.org/D124468
2022-04-26 17:10:33 -07:00
Siva Chandra 3f5287125a [libc] Add stdio entrypoints to aarch64 fullbuild. 2022-04-26 00:25:12 -07:00
Siva Chandra e161d36cea [libc][Obvious] Add deps of fopencookie_test only if it is enabled. 2022-04-26 00:10:29 -07:00
Michael Jones ef6614e4a2 [libc] Fix PrintfMatcher Cmake Rule
The PrintfMatcher depends on printf which is in stdio. Stdio is
currently fullbuild only, but the matcher wasn't, causing failing builds
when fullbuild was off. This patch adds the fullbuild condition to the
PrintfMatcher cmake.

Differential Revision: https://reviews.llvm.org/D124304
2022-04-22 14:40:21 -07:00
Michael Jones ff1374785f [libc] Add Printf FormatSection Matcher
This patch changes the printf parser tests to use a more robust matcher.
This allows for better debugging of parsing issues. This does not affect
the actual printf code at all, only the tests.

Reviewed By: sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D124130
2022-04-22 14:21:39 -07:00
Siva Chandra Reddy 19a6dd33ee [libc] Add the implementation of the GNU extension function fopencookie.
Reviewed By: lntue, michaelrj

Differential Revision: https://reviews.llvm.org/D124141
2022-04-22 08:02:25 +00:00
Dominic Chen e8572aca0c [libc] Use correct mnemonic for arm64_32 architecture
arm64_32 is an ILP32 platform

Differential Revision: https://reviews.llvm.org/D124134
2022-04-21 15:13:07 -07:00
Siva Chandra Reddy 22f9dca113 [libc] Add the implementation of the fflush function.
Note that the underlying flush implementation does not yet fully implement
the POSIX standard. It is complete with respect to the C standard
however. A future change will add the POSIX behavior. It should not affect
the implementation of the fflush function however as the POSIX behavior
will be added in a lower layer.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D124073
2022-04-20 19:43:39 +00:00
Siva Chandra Reddy 945e0220fd [libc] Add GNU extention functions fread_unlocked and fwrite_unlocked.
POSIX locking and unlocking functions flockfile and funlockfile have
also been added. The locking is not recursive yet. A future patch will
make the underlying lock a recursive lock.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D123986
2022-04-20 15:39:27 +00:00
Siva Chandra Reddy e6d56802f8 [libc][docs] Update the fuzzing doc to better reflect the current state.
Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D123923
2022-04-20 15:33:20 +00:00
Siva Chandra Reddy f8cdbeb471 [libc][docs] Remove the description of a "www" directory.
We plan to use the "docs" directory as the home for our "www" pages,
similar to how it is for the libcxx project.
2022-04-18 07:16:21 +00:00
Siva Chandra Reddy 6b4ee566e9 [libc] Add a doc describing the current status of libc runtimes build.
A section briefly mentioning the planned future enhancements has also
been included.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D123761
2022-04-18 06:48:43 +00:00
Michael Jones f14334ffa1 [libc][docs] Add doc for libc string functions
This patch adds a document describing the status of the string functions
in LLVM-libc.

Reviewed By: sivachandra, jeffbailey

Differential Revision: https://reviews.llvm.org/D123645
2022-04-14 13:03:01 -07:00
Tue Ly 5c6db1dc9b [libc] Fix nested namespace issues with multiply_add.h.
The FMA header was included inside namespaces in multiply_add.h.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D123539
2022-04-11 17:30:02 -04:00
Siva Chandra Reddy 0258f56646 [libc] Add a definition of pthread_attr_t and its getters and setters.
Not all attributes have been added to phtread_attr_t in this patch. They
will be added gradually in future patches.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D123423
2022-04-11 16:08:49 +00:00
Michael Jones 4f4752ee6f [libc][NFC] implement printf parser
This patch adds the sequential mode implementation of the printf parser,
as well as unit tests for it. In addition it adjusts the surrounding
files to accomodate changes in the design found in the implementation
process.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D123339
2022-04-08 14:21:13 -07:00
Tue Ly c5f8a0a1e9 [libc] Add support for x86-64 targets that do not have FMA instructions.
Make FMA flag checks more accurate for x86-64 targets, and refactor
polyeval to use multiply and add instead when FMA instructions are not
available.

Reviewed By: michaelrj, sivachandra

Differential Revision: https://reviews.llvm.org/D123335
2022-04-08 14:12:24 -04:00
Siva Chandra Reddy 2ce09e680a [libc] Add a linux Thread class in __support/threads.
This change is essentially a mechanical change which moves the thread
creation and join implementations from src/threads/linux to
src/__support/threads/linux/thread.h. The idea being that, in future, a
pthread implementation can reuse the common thread implementations in
src/__support/threads.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D123287
2022-04-07 16:13:21 +00:00
Michael Jones 5561ab3495 [libc] Add holder class for va_lists
This class is intended to be used in cases where a class is being used
on a va_list. It provides destruction and copy semantics with small
overhead. This is intended to be used in printf.

Reviewed By: sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D123061
2022-04-05 11:39:57 -07:00
Siva Chandra Reddy 83f153ce34 [libc] Add pthread_mutexattr_t type and its setters and getters.
A simple implementation of the getters and setters has been added. More
logic can be added to them in future as required.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D122969
2022-04-04 18:11:12 +00:00
Siva Chandra Reddy 6a7cd4a1df [libc][NFC] Do not call mmap and munmap from thread functions.
Instead, memory is allocated and deallocated using mmap and munmap
syscalls directly.

Reviewed By: lntue, michaelrj

Differential Revision: https://reviews.llvm.org/D122876
2022-04-02 05:12:08 +00:00
Michael Jones c4a1b07d09 [libc][NFC] add outline of printf
This patch adds the headers for printf. It contains minimal actual code,
and is more intended to be used for design review. The code is not built
yet, and may have minor errors.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D122773
2022-04-01 14:36:17 -07:00
Siva Chandra 97417e0300 [libc] Enable threads.h functions on aarch64.
Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D122788
2022-03-31 08:42:07 -07:00
Tue Ly a5466f0436 [libc] Improve the performance of expm1f.
Improve the performance of expm1f:
- Rearrange the selection logic for different cases to improve the overall
throughput.
- Use the same degree-4 polynomial for large inputs as `expf`
(https://reviews.llvm.org/D122418), reduced from a degree-7 polynomial.

Performance benchmark using perf tool from CORE-MATH project
(https://gitlab.inria.fr/core-math/core-math/-/tree/master):
Before this patch:
```
$ ./perf.sh expm1f

CORE-MATH reciprocal throughput   : 15.362
System LIBC reciprocal throughput : 53.288
LIBC reciprocal throughput        : 54.572

$ ./perf.sh expm1f --latency

CORE-MATH latency   : 57.759
System LIBC latency : 147.146
LIBC latency        : 118.057
```

After this patch:
```
$ ./perf.sh expm1f

CORE-MATH reciprocal throughput   : 15.359
System LIBC reciprocal throughput : 53.188
LIBC reciprocal throughput        : 14.600

$ ./perf.sh expm1f --latency

CORE-MATH latency   : 57.774
System LIBC latency : 147.119
LIBC latency        : 60.280

```

Reviewed By: michaelrj, santoshn, zimmermann6

Differential Revision: https://reviews.llvm.org/D122538
2022-03-30 19:23:25 -04:00
Michael Jones 9276074271 [libc][obvious] Add mfma to log2f
In the previous patch adding -mfma to functions that need it for windows
builds I missed log2f.

Differential Revision: https://reviews.llvm.org/D122693
2022-03-29 16:34:52 -07:00
Michael Jones 2f8829aba3 [libc] Add mfma option to functions that use fma
On Windows the functions that use fma don't properly include the fma
intrinsics unless -mfma is added to the compile options. This patch adds
the compile option to all of the functions that need it.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D122689
2022-03-29 16:23:36 -07:00
Michael Jones 4ac3f7e41a [libc][obvious] fix sqrt when long double is double
Previously, the "fsqrt" instruction was used on all x86_64 platforms
for finding the square root of long doubles. On long double is double
platforms (e.g. windows) this created errors. This patch changes square
root function for long doubles to be the same as the one for doubles if
long doubles are doubles.

Reviewed By: sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D122688
2022-03-29 16:05:40 -07:00
Guillaume Chatelet df838dbcfa [NFC][libc] Disable benchmarks when the LLVM benchmark target is not available
Fixes https://github.com/llvm/llvm-project/issues/53686

Differential Revision: https://reviews.llvm.org/D122481
2022-03-29 08:45:53 +00:00
Siva Chandra Reddy 2c20c9003b [libc] Set rtlib to compiler-rt in integration tests.
The clang driver to picks up compiler runtime files using full paths.
Without this, at least for aarch64, the driver tries to pick up the
compiler runtime files from the working directory.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D122617
2022-03-28 23:46:21 +00:00
Tue Ly 6168b42225 [libc] Improve the performance of expf.
Reduce the polynomial's degree from 7 down to 4.

Currently we use a degree-7 minimax polynomial on an interval of length 2^-7
around 0 to compute `expf`. Based on the suggestion of @santoshn and the RLIBM
project (https://github.com/rutgers-apl/rlibm-all/blob/main/source/float/exp.c)
and the improvement we made with `exp2f` in https://reviews.llvm.org/D122346,
it is possible to have a good polynomial of degree-4 on a subinterval of length
2^(-7) to approximate e^x.

We did try to either reduce the degree of the polynomial down to 3 or increase
the interval size to 2^(-6), but in both cases the number of exceptional values
exploded. So we settle with using a degree-4 polynomial of the interval of
size 2^(-7) around 0.

Reviewed By: sivachandra, zimmermann6, santoshn

Differential Revision: https://reviews.llvm.org/D122418
2022-03-25 12:20:20 -04:00
Tue Ly b9d87d7466 [libc] Improve the performance of exp2f.
Reduce the range-reduction table size from 128 entries down to 64 entries, and
reduce the polynomial's degree from 6 down to 4.

Currently we use a degree-6 minimax polynomial on an interval of length 2^-7
around 0 to compute exp2f.  Based on the suggestion of @santoshn and the RLIBM
project (https://github.com/rutgers-apl/rlibm-prog/blob/main/libm/float/exp2.c)
it is possible to have a good polynomial of degree-4 on a subinterval of length
2^(-6) to approximate 2^x.

We did try to either reduce the degree of the polynomial down to 3 or increase
the interval size to 2^(-5), but in both cases the number of exceptional values
exploded.  So we settle with using a degree-4 polynomial of the interval of
size 2^(-6) around 0.

Reviewed By: michaelrj, sivachandra, zimmermann6, santoshn

Differential Revision: https://reviews.llvm.org/D122346
2022-03-24 18:06:37 -04:00
Michael Jones 6d8ce42825 [libc][obvious] only test FILE on working platforms
The main code for the FILE struct is only enabled on platforms that it
works on, but before this patch the tests were included unconditionally.

Reviewed By: sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D122363
2022-03-24 10:19:34 -07:00
Siva Chandra Reddy 107ce71849 [libc] Use real objects and archives in integration tests.
Previously, we used empty, non-ELF crti.o, crtn.o, libm.a and libc++.a
files. Instead, we now still use dummies but they are real ELF object
files and archives.
2022-03-24 07:02:33 +00:00
Siva Chandra Reddy 441606f5ff [libc] Add implementations of fopen, flose, fread, fwrite and fseek.
A follow up patch will add feof and ferror.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D122327
2022-03-24 04:20:12 +00:00
Michael Jones 6d0f5d95ad [libc][obvious] add aligned_alloc as entrypoint
This patch adds aligned_alloc as an entrypoint. Previously it was being
included implicitly.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D122362
2022-03-23 16:44:15 -07:00
Siva Chandra Reddy 316f9fd638 [libc] Link the SCUDO integration tests to a special entrypoint collection.
We were previously linking to libllvmlibc.a. But, with libllvmlibc.a now
including functions which depend on the loader, we will have to use the
LLVM libc loader as well. To avoid this, we will link to a special
library which is just a collection of SCUDO allocator entrypoints.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D122360
2022-03-23 23:27:23 +00:00
Michael Jones 805899e68a [libc] Change FEnv to use MXCSR as source of truth
This patch primarily fixes the fenv implementation on Windows, since
Windows uses the MXCSR in place of the x87 status registers for storing
information about the floating point environment. This allows FEnv to
work correctly on Windows, and successfully build.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D121839
2022-03-23 16:08:00 -07:00
Siva Chandra Reddy 7fdb50c813 [libc] Add a new rule add_integration_test.
All existing loader tests are switched to an integration test added with
the new rule. Also, the getenv test is now enabled as an integration test.

All loader tests have been moved to test/integration. Also, the simple
checker library for the previous loader tests has been moved to a
separate directory of its own.

A follow up change will perform more cleanup of the loader CMake rules
to eliminate now redundent options.

Reviewed By: lntue, michaelrj

Differential Revision: https://reviews.llvm.org/D122266
2022-03-23 20:57:29 +00:00
Siva Chandra Reddy 3bfbb68e1e [libc] Rename libc-integration-test to libc-api-test.
Reviewed By: jeffbailey, michaelrj

Differential Revision: https://reviews.llvm.org/D122272
2022-03-23 20:25:34 +00:00
Siva Chandra Reddy a0f6d12cd4 [libc][File] Fix a bug under fseek(..., SEEK_CUR).
Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D122284
2022-03-23 16:24:15 +00:00
Siva Chandra Reddy b950a0d44d [libc][Obvious] Remove an unnecessary dep and use inline_memcpy.
An unnecessary dep of the getenv function is removed. From the x86_64
loader, a call to __llvm_libc::memcpy is replaced with call to
__llvm_libc::inline_memcpy.
2022-03-22 07:08:57 +00:00
Siva Chandra Reddy df4814d45d [libc] Add a linux file implementation.
Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D121976
2022-03-21 07:07:22 +00:00
Siva Chandra Reddy c236b41e45 [libc][NFC] Add the platform independent file target only if mutex is available.
The platform independent file implementation is not an entrypoint so it
cannot be excluded via the entrypoints.txt file. Hence, we need a
special treatment to exclude it from the build.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D121947
2022-03-18 03:34:38 +00:00
Siva Chandra Reddy 29a631a273 [libc][NFC] Add a separate flag for capturing the '+' in fopen mode string.
Having a separate flag helps in setting up proper flags when
implementing, say the Linux specialization of File.

Along the way, a signature for a function which is to be used to open
files has been added. The implementation of the function is to be
included in platform specializations.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D121889
2022-03-17 15:44:04 +00:00
Siva Chandra Reddy 2e7cb8c786 [libc] Remove references to the std threads library from __support/threads. 2022-03-16 19:35:40 +00:00
Siva Chandra Reddy 9527a2f58f [libc][NFC] Keep the mutex with the base File data structure.
This is now possible because we have a platform independent abstraction
for mutexes.

Reviewed By: lntue, michaelrj

Differential Revision: https://reviews.llvm.org/D121773
2022-03-16 19:05:23 +00:00
Siva Chandra Reddy 2ebe971103 [libc][Obvious] Add missing licence headers and fix an include pattern. 2022-03-16 18:51:37 +00:00
Tue Ly 4c9bfec67c [libc] Let exhaustive tests indicate each interval PASSED/FAILED.
Let exhaustive tests indicate each interval PASSED/FAILED.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D121564
2022-03-16 09:56:03 -04:00
Alex Brachet 89aa4bd3fb [libc] Unlock after pop_back 2022-03-16 04:00:26 +00:00
Alex Brachet 968c1aa54f [libc][NFC] Use more common variable naming convention
We were in between two styles when this file was initially
checked in.
2022-03-16 03:34:54 +00:00
Siva Chandra Reddy e9c9ee9fe6 [libc][NFC] Fix typos and reduntent code triggering compiler warinings. 2022-03-15 21:51:12 +00:00
Siva Chandra Reddy 827575a7f8 [libc] Add implementation of POSIX lseek function.
Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D121676
2022-03-15 16:24:48 +00:00
Alex Brachet ae4b59f179 [libc] Fix exit not calling new handlers registered from a call to atexit in atexit handler 2022-03-15 15:18:41 +00:00
Alex Brachet d7c920e1a0 [libc][BlockStore] Add back, pop_back and empty methods
Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D121656
2022-03-15 15:11:57 +00:00
Tue Ly 64af346b18 [libc] Implement expm1f function that is correctly rounded for all rounding modes.
Implement expm1f function that is correctly rounded for all rounding modes.  This is based on expf implementation.

From exhaustive testings, using expf implementation, and subtract 1.0 before rounding the final result to single precision
gives correctly rounded results for all |x| > 2^-4 with 1 exception.  When |x| < 2^-25, we use x + x^2 (implemented with a
single fma).  And for 2^-25 <= |x| <= 2^-4, we use a single degree-8 minimax polynomial generated by Sollya.

Reviewed By: sivachandra, zimmermann6

Differential Revision: https://reviews.llvm.org/D121574
2022-03-15 10:24:56 -04:00
Siva Chandra Reddy 1ceb007939 [libc][Obvious] Fix typo in CMake file. 2022-03-15 08:32:05 +00:00
Tue Ly 58edd26255 [libc] Include -150 to the special cases at the beginning of exp2f function. 2022-03-14 10:06:27 -04:00
Tue Ly 64721a3312 [libc] Implement exp2f function that is correctly rounded for all rounding modes.
Implement exp2f function that is correctly rounded for all rounding modes.

Reviewed By: sivachandra, zimmermann6

Differential Revision: https://reviews.llvm.org/D121463
2022-03-14 09:42:37 -04:00
Tue Ly 38cadd90b7 [libc] Implement expf function that is correctly rounded for all rounding modes.
Implement expf function that is correctly rounded for all rounding modes.

Reviewed By: sivachandra, zimmermann6

Differential Revision: https://reviews.llvm.org/D121440
2022-03-11 07:16:47 -05:00
Siva Chandra Reddy 1f45a1071d [libc][Obvious] Destroy the block store var in block store test. 2022-03-10 21:36:46 +00:00
Siva Chandra Reddy 19c6098097 [libc] Add a resizable container with constexpr constructor and destructor.
The new container is used to store atexit callbacks. This way, we avoid
the possibility of the destructor of the container itself getting added
as an at exit callback.

Reviewed By: abrachet

Differential Revision: https://reviews.llvm.org/D121350
2022-03-10 21:28:23 +00:00
Tue Ly 0f031daea8 [libc] Initial support for darwin-aarch64.
Add initial support for darwin-aarch64 (macOS M1).

Some differences compared to linux-aarch64:
- `math.h` defined `math_errhandling` by the compiler builtin `__math_errhandling()` but Apple Clang 13.0.0 on M1 does not support `__math_errhandling()` builtin as a macro function or a constexpr function.
- `math.h` defines `UNDERFLOW` and `OVERFLOW` macros.
- Besides 5 usual floating point exceptions: `FE_INEXACT`, `FE_UNDERFLOW`, `FE_OVERFLOW`, `FE_DIVBYZERO`, and `FE_INVALID`, `fenv.h` also has another floating point exception: `FE_FLUSHTOZERO`.  The corresponding trap for `FE_FLUSHTOZERO` in the control register is at the different location compared to the status register.
- `FE_FLUSHTOZERO` exception flag cannot be raised with the default CPU floating point operation mode.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D120914
2022-03-10 09:26:09 -05:00
Siva Chandra Reddy 83b8878fbb [libc] Use the constexpr constructor to initialize exit handlers mutex.
Reviewed By: abrachet

Differential Revision: https://reviews.llvm.org/D121334
2022-03-10 02:52:35 +00:00
Tue Ly ffb410d3f9 [libc] Add testing macros for errno and floating point exceptions.
Add testing macros for errno and floating point exceptions.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D121235
2022-03-08 15:49:43 -05:00
Michael Jones e1dcda966e [libc][NFC] remove completed TODOs
There were some "TODO" messages that were for things that I have already
completed. This patch removes those.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D121232
2022-03-08 11:58:14 -08:00
Michael Jones bf0ded805a [libc][NFC] split standalone_cpp into single headers
Previously, the entire support/CPP folder was in one header library,
which meant that a lot of headers were included where they shouldn't be.
This patch splits each header into its own target, as well as adjusting
each place they were included to only include what is used.

Reviewed By: sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D121237
2022-03-08 11:56:08 -08:00
Siva Chandra Reddy fe2cc14ad4 [libc] Align the stack pointer in the start function.
The loader TLS test for x86_64, which now passes, has been enabled.
A future change should enable the test for aarch64 as well.

Reviewed By: jeffbailey

Differential Revision: https://reviews.llvm.org/D121091
2022-03-07 19:45:53 +00:00
Siva Chandra Reddy c74c344263 [libc] Fix alignment logic in TLS image size calculation. 2022-03-07 09:21:37 +00:00
Stella Laurenzo 38151a08c2 Reapply "[cmake] Prefix gtest and gtest_main with "llvm_"."
This reverts commit 7cdda6b8ce.

Differential Revision: https://reviews.llvm.org/D121020
2022-03-04 13:45:43 -08:00
Tue Ly db46c7770f [libc] Fix small bugs in aarch64/FEnvImpl.h and simplify feclearexcept_test.
Fix small bugs in aarch64/EFnvImpl.h and simplify feclearexcept_test.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D120997
2022-03-04 15:18:03 -05:00
Tue Ly 76ec69a911 [libc] Remove the redundant header FPUtil/FEnvUtils.h
Remove the redundant header FPUtil/FEnvUtils.h, use FPUtil/FEnvImpl.h header instead.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D120965
2022-03-04 14:09:47 -05:00
Siva Chandra Reddy a5ee8183c0 [libc][NFC] Add a platform independent thread support library.
The idea is that, other parts of the libc which require thread/lock
support will be able to use this platform independent setup.

With this change, only the linux implementation of a mutex type has been
moved to the new library. Because of this, there is some duplication
between the new library and src/threads/linux. A follow up change will
move all of src/threads/linux to the new library. The duplication should
be eliminated with that move.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D120795
2022-03-04 18:33:46 +00:00
Tue Ly bccc88b384 [libc][Obvious] Add build folder to .gitignore. 2022-03-04 13:16:55 -05:00
Siva Chandra Reddy dd33f9cdef [libc] Make the errno macro resolve to the thread local variable directly.
With modern architectures having a thread pointer and language supporting
thread locals, there is no reason to use a function intermediary to access
the thread local errno value.

The entrypoint corresponding to errno has been replaced with an object
library as there is no formal entrypoint for errno anymore.

Reviewed By: jeffbailey, michaelrj

Differential Revision: https://reviews.llvm.org/D120920
2022-03-04 17:29:49 +00:00
Siva Chandra Reddy c8b614cd74 [libc][Obvious] Add a few missing deps listings. 2022-03-03 16:27:46 +00:00
Stella Laurenzo 7cdda6b8ce Revert "[cmake] Prefix gtest and gtest_main with "llvm_"."
lldb buildbot failure. will investigate and roll forward.

This reverts commit 9f37775472.
2022-03-02 11:13:46 -08:00
Stella Laurenzo 9f37775472 [cmake] Prefix gtest and gtest_main with "llvm_".
The upstream project ships CMake rules for building vanilla gtest/gmock which conflict with the names chosen by LLVM. Since LLVM's build rules here are quite specific to LLVM, prefixing them to avoid collision is the right thing (i.e. there does not appear to be a path to letting someone *replace* LLVM's googletest with one they bring, so co-existence should be the goal).

This allows LLVM to be included with testing enabled within projects that themselves have a dependency on an official gtest release.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D120789
2022-03-02 10:53:32 -08:00
Siva Chandra Reddy 32a50c6b93 [libc][NFC] Add a static assert for futex size. 2022-03-01 22:56:56 +00:00
Siva Chandra Reddy 75747c7394 [libc] Remove the remaining uses of stdatomic.h.
New methods to the Atomic class have been added as required. Futex
related types have been consolidated at a common place.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D120705
2022-03-01 17:12:39 +00:00
Tue Ly 4816bfa838 [libc] Add LLVM_LIBC_CLANG_TIDY option and allow LLVM_LIBC_ENABLE_LINTING without full build.
Add LLVM_LIBC_CLANG_TIDY option and allow LLVM_LIBC_ENABLE_LINTING without full build.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D119180
2022-03-01 11:04:29 -05:00
Siva Chandra Reddy 1137255585 [libc] Add a class "Atomic" as a simple equivalent of std::atomic.
Only the methods currently required by the libc have been added.
Most of the existing uses of atomic operations have been switched over
to this new class. A future change will clean up the rest of uses.

This change now allows building mutex and condition variable code with a
C++ compiler which does not have stdatomic.h, for example g++.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D120642
2022-02-28 23:51:44 +00:00
Clint Caywood 1768cb3a67 Use __builtin_clz to find leading 1 in generic sqrt (where possible)
__builtin_clz requires just a single instruction on x86 and arm, so this is a performance improvement.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D120579
2022-02-28 17:33:49 -05:00
Guillaume Chatelet 07f93a1e39 [libc][automemcpy] Discard aggrated samples from JSON
The benchmark framework synthesizes fake "aggregate" Samples representing mean, median and cv.
We're only interested in "iteration" samples.

Differential Revision: https://reviews.llvm.org/D120062
2022-02-18 15:24:13 +00:00
Alex Brachet d66983861a [libc] Add exit and atexit
Often atexit is implemented using __cxa_atexit. I have not implemented __cxa_atexit here because it potentially requires more discussion. It is unique for llvm-libc (I think) that it is an exported symbol that wouldn’t be defined in any spec file because it doesn’t have a header. Implementing it will be trivial given what is here already, but I figured it would be more contentious so it can be implemented later.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D119512
2022-02-17 17:21:55 +00:00
Guillaume Chatelet da5a4f16e8 [libc][automemcpy] Introduce geomean of scores as a tie breaker
Differential Revision: https://reviews.llvm.org/D120040
2022-02-17 13:37:05 +00:00
Guillaume Chatelet 48e0e6cedc [llvm][automemcpy] Allow distribution filtering in analysis
Differential Revision: https://reviews.llvm.org/D120037
2022-02-17 13:10:46 +00:00
Guillaume Chatelet b254a2a703 [libc][automemcpy] Add mean/variance and simplify implementation
Differential Revision: https://reviews.llvm.org/D120031
2022-02-17 12:11:05 +00:00
Alex Brachet 64f5f6d759 [libc] Use '+' constraint on inline assembly
As suggested by @mcgrathr in D118099

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D119978
2022-02-17 03:00:17 +00:00
Tue Ly f1ec99f973 [libc] Improve hypotf performance with different algorithm correctly rounded to all rounding modes.
Algorithm for hypotf: compute (a*a + b*b) in double precision, then use Dekker's algorithm to find the rounding error, and then correcting it after taking its square-root.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D118157
2022-02-16 09:48:51 -05:00
Siva Chandra Reddy 86bebe1a90 [lib][Obvious] Fix style in a few include directives. 2022-02-16 05:57:12 +00:00
Jeff Bailey 171cb8f53f Rewrite much of the index page for libc
The prior page was the proposal doc, this one is now
more about what the project intends to do, written in the
present tense.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D119379
2022-02-16 03:46:20 +00:00
Jeff Bailey 55120aad4e Implement basic loader for Linux aarch64
This implements a basic arm64 loader for Linux, and all the currently
enabled linker tests pass.  TLS is not implemented, and functions
using it will have undefined behaviour.  Notably, the TLS test is
currently disabled on x86_64.

Much of the structure is copied from x86_64 to allow for a refactoring
of the start code between architectures.

Tested:
ninja libc_loader_tests on aarch64-linux.

Co-authored-by: Raman Tenneti <rtenneti@google.com>

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D119641
2022-02-16 03:42:44 +00:00
Michael Jones 148a4b240e [libc] change ASAN condition to generator expression
Previously, building LLVM-libc with GWP ASAN was conditioned on the flag
COMPILER_RT_BUILD_GWP_ASAN, which caused issues do to the default value
of the flag being set in the compiler-rt cmake, which is seperate. Now
GWP ASAN is included based on if it exists as a target, which is more
consistent.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D119789
2022-02-15 16:12:12 -08:00
Tue Ly 9371d95ed2 [libc] Improve performance of generic hypot when the exponent difference is sufficiently large.
Simplify the logic when the exponent difference is at least MantissaLength + 2, while still maintaining correct rounding for all rounding modes.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D119843
2022-02-15 11:57:36 -05:00
Siva Chandra Reddy 4ef02da094 [libc] Add a platform independent buffered file IO data structure.
Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D119458
2022-02-15 05:34:29 +00:00