Commit Graph

1089 Commits

Author SHA1 Message Date
Siva Chandra Reddy 8fbc3c1179 [libc][Obvious] Use the correct StringView constructor in dirent_test. 2022-07-25 20:47:17 +00:00
Siva Chandra Reddy 35ea84ad6a [libc] Add dirent.h functions opendir, readdir, closedir and dirfd.
Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D130459
2022-07-25 20:23:25 +00:00
Siva Chandra Reddy 5edc7ce235 [libc] Add a simple StringStream class.
This class will be used in future changes to construct simple strings.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D130334
2022-07-25 18:27:29 +00:00
Tue Ly 83193a5e72 [libc] Raise FE_INVALID for sinf with +- inf inputs. 2022-07-25 10:20:32 -04:00
Michael Jones 3b0c78fe3b [libc][nfc] move printf inf/nan to separate function
The floating point functions all use the same inf and nan formatting. By
separating this functionality out of the %a conversion I make it
available for reuse by %f/e/g.

Reviewed By: lntue, sivachandra

Differential Revision: https://reviews.llvm.org/D129665
2022-07-22 10:29:35 -07:00
Alex Brachet 5e2d5071ff [libc] Don't call user comparator function for equal pointers
The standard says two equal pointers must compare equal
so there is no need to call the user comparator function
in this case.

Differential Revision: https://reviews.llvm.org/D130310
2022-07-22 17:03:16 +00:00
Tue Ly 600172a72b [libc] Temporarily disable arm32's sinf, cosf, sincosf entrypoints.
With correctly rounded implementations, these functions will be tested for all
rounding modes.  Since fegetround and fesetround are not implemented for arm32,
these tests will fail in all non-default rounding modes.  We will re-enable
these entrypoints and tests once fegetround and fesetround are implemented for
arm32.
2022-07-22 10:46:23 -04:00
Tue Ly d883a4ad02 [libc] Implement sinf function that is correctly rounded to all rounding modes.
Implement sinf function that is correctly rounded to all rounding modes.

- We use a simple range reduction for `pi/16 < |x|` :
    Let `k = round(x / pi)` and `y = (x/pi) - k`.
    So `k` is an integer and `-0.5 <= y <= 0.5`.
Then
```
sin(x) = sin(y*pi + k*pi)
          = (-1)^(k & 1) * sin(y*pi)
          ~ (-1)^(k & 1) * y * P(y^2)
```
    where `y*P(y^2)` is a degree-15 minimax polynomial generated by Sollya with:
```
> P = fpminimax(sin(x*pi)/x, [|0, 2, 4, 6, 8, 10, 12, 14|], [|D...|], [0, 0.5]);
```

- 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 sinf
CORE-MATH reciprocal throughput   : 17.892
System LIBC reciprocal throughput : 25.559
LIBC reciprocal throughput        : 29.381
```
After this patch (correctly rounded):
```
$ CORE_MATH_PERF_MODE="rdtsc" ./perf.sh sinf
CORE-MATH reciprocal throughput   : 17.896
System LIBC reciprocal throughput : 25.740

LIBC reciprocal throughput        : 27.872
LIBC reciprocal throughput        : 20.012     (with `-msse4.2` flag)
LIBC reciprocal throughput        : 14.244     (with `-mfma` flag)
```

Reviewed By: zimmermann6

Differential Revision: https://reviews.llvm.org/D123154
2022-07-22 10:07:31 -04:00
Tue Ly ed261e7106 [libc] Add float type and flag for nearest_integer to enable SSE4.2.
Add float type and flag for nearest integer to automatically test with
and without SSE4.2 flag.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D129916
2022-07-22 09:29:41 -04:00
Siva Chandra Reddy 7c666c14f8 [libc] Add a convenience class and function for integer to string conversion.
Printf's integer converter has been modified to use the new converter. In
future, it will be used to implement other parts of the libc.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D130227
2022-07-21 20:18:59 +00:00
Siva Chandra Reddy f8322d1351 [libc] Add a method `find_last_of` to StringView.
Reviewed By: jeffbailey

Differential Revision: https://reviews.llvm.org/D130112
2022-07-19 22:43:43 +00:00
Michael Jones bf7f01d857 [libc] fix strtofloatingpoint on rare edge case
Currently, there are two string parsers that can be used in a call to
strtofloatingpoint. There is the main parser used by Clinger's fast path
and Eisel-Lemire, and the backup parser used by Simple Decimal
Conversion. There was a bug in the backup parser where if the number had
more than 800 digits (the size of the SDC buffer) before the decimal
point, it would just ignore the digits after the 800th and not count
them into the exponent. This patch fixes that issue and adds regression
tests.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D130032
2022-07-18 14:23:33 -07:00
Jeff Bailey 8aad330eeb [libc] Fix API for remove_{prefix, suffix}
The API in StringView.h for remove_prefix was incorrect and was returning a
new StringView rather than just altering the view.

As part of this, also removed some of the safety features.  The comment
correctly noted that the behaviour is undefined in some cases,
but the code and test cases checked for that.

One caller was relying on the old behaviour, so fixed it and added some
comments.

Tested:
check-libc
llvmlibc
libc-loader-tests

Reviewed By: gchatelet

Differential Revision: https://reviews.llvm.org/D129950
2022-07-18 14:40:09 +00:00
Kazu Hirata 8dfdb80f72 Ensure newlines at the end of files (NFC) 2022-07-17 15:37:45 -07:00
Michael Jones 3b3b816f29 [libc] add rounding modes to printf float conv
This adds functionality for rounding towards negative inf, positive inf,
and zero to the float hex conversion (%a).

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D129702
2022-07-15 11:11:32 -07:00
Michael Jones 9fa6a88a16 [libc][arm32] add string stdlib & math entrypoints
This patch adds all the string and stdlib entrypoints, as well as a few
math entrypoints to the arm32 build.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D129821
2022-07-15 10:10:58 -07:00
Siva Chandra 98fdabecf5 [libc] Enable a few stdlib and time functions on aarch64. 2022-07-14 14:37:50 -07:00
Siva Chandra 75a628925e [libc] Enable few stdio functions on aarch64. 2022-07-14 13:40:48 -07:00
Siva Chandra edee61b55c [libc] Enable few pthread and threads functions on aarch64. 2022-07-14 13:25:21 -07:00
Siva Chandra Reddy 8dc42802f7 [libc] Add implementations of pthread_equal and pthread_self.
Reviewed By: michaelrj, lntue

Differential Revision: https://reviews.llvm.org/D129729
2022-07-14 20:12:35 +00:00
Tue Ly 0f782b84cb [libc] Add nearest integer instructions to fputil.
Add round to nearest integer instructions to fputil.  This will be
used in sinf implementation https://reviews.llvm.org/D123154

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D129776
2022-07-14 13:20:35 -04:00
Jeff Bailey 897b80147d Add support for three more string_view functions
Add support for three more string_view functions

1) starts_with(char)
2) ends_with(char)
3) find_first_of(char, size_t)

Reimplemented trim in terms of the new starts_with and ends_with.

Tested:
New unit tests.

Reviewed By: gchatelet

Differential Revision: https://reviews.llvm.org/D129618
2022-07-14 14:20:20 +00:00
Siva Chandra Reddy 5e61b9c556 [libc][NFC] Make all integration tests depend on the threads implementation.
The integration tests use the loader which sets up the main thread's
self object. So, all integration tests have to depend on the threads
implementation.
2022-07-13 20:51:12 +00:00
Siva Chandra Reddy 859c189727 [libc] Linux threads - Setup TLS area of a new thread and cleanup at exit.
Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D129543
2022-07-13 20:46:18 +00:00
Alex Brachet 04c681d195 [libc] Specify rounding mode for strto[f|d] tests
The specified rounding mode will be used and restored
to what it was before the test ran.

Additionally, it moves ForceRoundingMode and RoundingMode
out of MPFRUtils to be used in more places.

Differential Revision: https://reviews.llvm.org/D129685
2022-07-13 20:20:30 +00:00
Alex Brachet 31cccebb5c [libc][NFC] Make explicit casts for gcc 2022-07-13 16:53:39 +00:00
Alex Brachet 2e8fa86e09 [libc] Add explicit casts for gcc 2022-07-13 16:52:13 +00:00
Alex Brachet 4f281fa2a8 [libc] Reset rounding mode after fsetround tests
Differential Revision: https://reviews.llvm.org/D129619
2022-07-13 15:42:47 +00:00
Siva Chandra Reddy 3c5d6312c4 [libc][NFC] Move thread platform data pointer to thread attributes.
Along the way, added constexpr constructors to the Thread data
structures.
2022-07-13 07:09:40 +00:00
Guillaume Chatelet e0aece276f [libc][utils] Add more methods to StringView
Differential Revision: https://reviews.llvm.org/D128908
2022-07-12 07:42:29 +00:00
Michael Jones 9e421a1633 [libc] clean up printf error codes
Move the constants for printf's return values into core_structs, and
update the converters to match.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D128767
2022-07-11 16:49:47 -07:00
Alex Brachet c179bcc151 [libc] Add imaxabs
Differential Revision: https://reviews.llvm.org/D129517
2022-07-11 21:28:21 +00:00
Siva Chandra Reddy 9b9ff63b03 [libc][NFC] Make thread_detach_test an integration test.
This is simple switch from a unittest to an integration test. It is
being done as a preparatory step to adding TLS support to thread
creation. TLS setup and initialization is tightly coupled with the
loader and hence all thread related tests should be integration tests.
2022-07-11 06:48:54 +00:00
Siva Chandra Reddy badda4ac3c [libc] Linux threads - Set CLEAR_TID addr to 0 when exiting a detached thread.
A detached thread cleans itself up at completion. So, the CLEAR_TID memory is
also gone by the time the kernel tries to signal potential waiters. By nulling
the CLEAR_TID address, we prevent the kernel from signalling at a non-existent
futex location.
2022-07-11 04:42:59 +00:00
Siva Chandra Reddy 379428c2ac [libc] Linux threads - store a ptr to the thread attribs in the start args.
Previosly, a pointer to the thread data structure was stored in the
start args. However, the thread data structure need not have the
lifetime of the thread. On the the other hand, thread attributes are
stored on the thread stack so they live as long as the thread lives.
2022-07-10 05:02:45 +00:00
Siva Chandra Reddy 9c78d92557 [libc][NFC] Remove the now used thread_attrib target. 2022-07-09 18:28:28 +00:00
Michael Jones f9f8693be3 [libc] add printf hexadecimal float conversion
This patch adds the %a/A conversions to printf, as well as the compiler
flag to disable floating point handling entirely. This will allow our
printf implementation to display every type of argument allowed by
printf, although some formats are still incomplete.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D129240
2022-07-08 15:58:20 -07:00
Michael Jones 8bf8385ef0 [libc] add dependencies to generic sqrt tests
This adds dependencies on the corresponding sqrt function to each
generic sqrt test. This is so that on platforms that don't support the
math functions, the tests are not run.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D129388
2022-07-08 15:41:11 -07:00
Michael Jones 6656029a49 [libc][nfc] update get_explicit_mantissa
The get_explicit_mantissa function returns the mantissa of an FPBits
floating point value with the implicit leading 1, if appropriate. This
function existed previously, but did not handle non-normal numbers
properly.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D129241
2022-07-07 10:13:24 -07:00
Alex Brachet a442c62888 [libc] Make div test names unique
In Fuchsia, all tests in a directory, ie stdlib, are linked
into one executable, this causes problems for multiple
definitions of the vtables of the div tests because their
class has the same name. This patch just trivially changes
their name to be unique between all div tests.

Differential revision: https://reviews.llvm.org/D129248
2022-07-07 15:06:52 +00:00
Alex Brachet 7c23138f1b [libc][NFC] Make explicit casts 2022-07-07 02:10:05 +00:00
Jeff Bailey bc70ba814d Use add_llvm_install_targets for install-llvmlibc
Using the LLVM rules for install ensures that DESTDIR and other expected
variables for an LLVM install work correctly.

Tested:
Manually with DESTDIR=/tmp/testinstall/ ninja install-llvmlibc

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D129041
2022-07-04 17:18:36 +00:00
Tue Ly 4e6c30c835 [libc] Add a separate algorithm_test.
Differential Revision: https://reviews.llvm.org/D128994
2022-07-04 13:56:35 +00:00
Kirill Okhotnikov fdf1fda5a8 [libc][math] Improved ExhaustiveTest performance.
Previous implementation splits value ranges around threads. Because of
very different performance of testing functions over different ranges,
CPU utilization were poor. Current implementation split test range
over small pieces and threads take the pieces when they finish with
previous. Therefore the CPU load is constant during testing.

Differential Revision: https://reviews.llvm.org/D128995
2022-07-01 18:32:54 +02:00
Guillaume Chatelet b66d02eaa0 Revert "[reland] algorithm_test.cpp"
This reverts commit 1514acb20f.
2022-07-01 10:48:57 +00:00
Guillaume Chatelet 1514acb20f [reland] algorithm_test.cpp
Removing `-ffreestanding` for the tests should allow us to use `<iostream>`

Differential Revision: https://reviews.llvm.org/D128916
2022-07-01 10:45:29 +00:00
Tue Ly ae5c82502e [libc][Obvious] Do not add __NO_ to targets with FLAG__NO suffix. 2022-06-30 10:45:59 -04:00
Guillaume Chatelet 98007e9753 Revert "[libc][test] Remove dependency on sstream in algorithm_test.cpp"
This reverts commit 292b281caf.
2022-06-29 15:12:24 +00:00
Guillaume Chatelet 292b281caf [libc][test] Remove dependency on sstream in algorithm_test.cpp
Bots have been failing in full build mode because ´#include <sstream>´ would pull pthread which is not possible when code is compiled with ´-freestanding´.

Differential Revision: https://reviews.llvm.org/D128809
2022-06-29 14:53:53 +00:00
Michael Jones 88b801392c [libc] add integer writing to printf
This patch adds %n to printf, as well as a compiler flag to disable it.
This is due to it having serious security issues when misused.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D127517
2022-06-28 14:00:46 -07:00
Michael Jones 1088d4ad74 [libc] disable algorithm_test.cpp temporarily
The unit tests introduced in patch D128335 are causing build failures,
and the fix is non-trivial. This patch disables these tests temporarily
until a proper fix can be implemented.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D128746
2022-06-28 11:22:45 -07:00
Michael Jones 03a26c34a7 [libc] Fix compile options for algorithm test
This patch fixes the problem the bots were having with the algorithm
test not including pthreads correctly. They will likely need a manual
forced clean build for this to take effect.

Differential Revision: https://reviews.llvm.org/D128742
2022-06-28 10:22:15 -07:00
Guillaume Chatelet f6f53e990d [libc] Disable use of inlined builtins for tests 2022-06-28 10:17:46 +00:00
Guillaume Chatelet 81863dd303 [libc] Fix missing static_cast 2022-06-28 09:50:54 +00:00
Guillaume Chatelet 5ae9b42efb [libc] Use ASSERT_ instead of EXPECT_ in memcmp tests 2022-06-28 09:36:04 +00:00
Guillaume Chatelet 7f5d7bc827 [libc][mem*] Introduce Algorithms for new mem framework
This patch is a subpart of D125768 intented to make the review easier.

This patch introduces the same algorithms as in `libc/src/string/memory_utils/elements.h` but using the new API.

Differential Revision: https://reviews.llvm.org/D128335
2022-06-28 09:23:49 +00:00
Michael Jones 6ec465ab8f [libc] add printf oct conversion
The oct converter handles the %o conversion.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D127985
2022-06-27 15:36:50 -07:00
Kirill Okhotnikov 5358457089 [libc][docs] Added fmod performance results. 2022-06-27 19:31:54 +02:00
Siva Chandra Reddy 8bb1dd7d34 [libc] Add a simple arm32 config.
This will be expanded in future as more functions are brought up on arm32.
2022-06-27 09:03:22 +00:00
Siva Chandra Reddy fe8017476c [libc][NFC] Make the support thread library an object library.
It was previously a header library. Making it an object library will
allow us to declare thread local variables which can used to setup a
thread's self object.
2022-06-27 08:47:05 +00:00
Siva Chandra Reddy 4965cea2f3 [libc] Add compound assignment and pre-increment operators to UInt. 2022-06-25 06:38:24 +00:00
Siva Chandra Reddy a83034ef2b [libc][Obvious] Compare values of the same type in memory_utils/backend_test. 2022-06-25 04:50:04 +00:00
Siva Chandra Reddy bcdd9fbf08 [libc][Obvious] Fix incorrect nested namespace name. 2022-06-25 04:47:21 +00:00
Siva Chandra Reddy 66a6c1073a [libc] Add a cacheline size of arm target.
It is set arbitrarily at 32 now. It can be adjusted as required in
future.
2022-06-25 04:42:40 +00:00
Kirill Okhotnikov 27aca975b6 [libc][math] Fix broken compilation due to __builtin_inf/nan functions. 2022-06-25 01:39:32 +02:00
Kirill Okhotnikov 349fee08d5 [libc][math] Fix broken aarch64 due to clz refactoring. 2022-06-24 23:59:26 +02:00
Kirill Okhotnikov b8e8012aa2 [libc][math] fmod/fmodf implementation.
This is a implementation of find remainder fmod function from standard libm.
The underline algorithm is developed by myself, but probably it was first
invented before.
Some features of the implementation:
1. The code is written on more-or-less modern C++.
2. One general implementation for both float and double precision numbers.
3. Spitted platform/architecture dependent and independent code and tests.
4. Tests covers 100% of the code for both float and double numbers. Tests cases with NaN/Inf etc is copied from glibc.
5. The new implementation in general 2-4 times faster for “regular” x,y values. It can be 20 times faster for x/y huge value, but can also be 2 times slower for double denormalized range (according to perf tests provided).
6. Two different implementation of division loop are provided. In some platforms division can be very time consuming operation. Depend on platform it can be 3-10 times slower than multiplication.

Performance tests:

The test is based on core-math project (https://gitlab.inria.fr/core-math/core-math). By Tue Ly suggestion I took hypot function and use it as template for fmod. Preserving all test cases.

`./check.sh <--special|--worst> fmodf` passed.
`CORE_MATH_PERF_MODE=rdtsc ./perf.sh fmodf` results are

```
GNU libc version: 2.35
GNU libc release: stable
21.166 <-- FPU
51.031 <-- current glibc
37.659 <-- this fmod version.
```
2022-06-24 23:09:14 +02:00
Siva Chandra Reddy 300f8da8e8 [libc] Add Uint128 type as a fallback when __uint128_t is not available.
Also, the unused specializations of __int128_t have been removed.

Differential Revision: https://reviews.llvm.org/D128304
2022-06-24 16:03:35 +00:00
Siva Chandra Reddy f4580c6d5a [libc][NFC] Remove the templatization from the linux implementation of thread.
This enables setting up a single "self" thread object to be returned by
API like thrd_self and pthread_self.
2022-06-24 08:22:53 +00:00
Siva Chandra Reddy ba93b23eb3 [libc] Revert "Eliminate the internal header library target."
This reverts commit 306f2731f4. The CMake
version used by the bots does like it.
2022-06-23 20:53:09 +00:00
Siva Chandra Reddy 306f2731f4 [libc][NFC] Eliminate the internal header library target.
The internal header library target with name suffix .__header_library
has been removed as it serves no purpose now.
2022-06-23 20:45:25 +00:00
Siva Chandra Reddy 0a537a1299 [libc][NFC] Convert pthread tests which create threads to integration tests. 2022-06-23 20:36:20 +00:00
Siva Chandra Reddy d5475af2f7 [libc][NFC] Convert threads unittests in to integration tests.
This is mostly a mechanical change. In a future pass, all tests from
pthread which create threads will also be converted to integration tests.

Some of thread related features are tightly coupled with the loader. So,
they can only be tested with the in-house loader. Hence, going forward, all
tests which create threads will have to be integration tests.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D128381
2022-06-23 20:32:33 +00:00
Guillaume Chatelet aeccc16497 Re-land [libc] Apply no-builtin everywhere, remove unnecessary flags
This is a reland of D126773 / b2a9ea4420.

The removal of `-mllvm -combiner-global-alias-analysis` has landed separately
in D128051 / 7b73f53790.

And the removal of `-mllvm --tail-merge-threshold=0` is scheduled for
removal in a subsequent patch.
2022-06-22 12:30:20 +00:00
Guillaume Chatelet 67fe3bd33c [libc][mem*] Introduce Sized/Backends for new mem framework
This patch is a subpart of D125768 intented to make the review easier.

The `SizedOp` struct represents operations to be performed on a certain number of bytes.
It is responsible for breaking them down into platform types and forwarded to the `Backend`.

The `Backend` struct represents a lower level abstraction that works only on types (`uint8_t`, `__m128i`, ...).
It is similar to instruction selection.

Differential Revision: https://reviews.llvm.org/D126768
2022-06-22 11:21:06 +00:00
Siva Chandra Reddy 5aa9efbab5 [libc] Fix bug in UInt comparison operators.
Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D128303
2022-06-22 05:41:07 +00:00
Siva Chandra Reddy a5cb6edb47 [libc] Revert: Temporary disable environment tests for PATH variable.
This reverts commit 2846c2bb4f. The reason
for the disable is not relevant anymore.
2022-06-19 21:39:10 +00:00
Tue Ly 2846c2bb4f [libc] Temporary disable environment tests for PATH variable.
This is blocking fullbuild bot.
2022-06-18 23:04:33 -04:00
Tue Ly c5ca7649e3 [libc][Obvious] Fix c++20-designator warnings for tests that use TmHelper.h. 2022-06-18 22:55:57 -04:00
Siva Chandra be6af89f85 [libc] Add TLS image initialization to aarch64 startup code.
The TLS loader test has been enabled for aarch64.
Handling of PT_TLS' filesz and memsz for x86_64 has also been fixed.

Reviewed By: jeffbailey

Differential Revision: https://reviews.llvm.org/D128032
2022-06-17 22:50:14 -07:00
Michael Jones 121c645414 [libc] add printf pointer conv
The pointer converter handles the %p conversion. It uses the hex
converter for most of the conversion.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D127995
2022-06-17 17:18:13 -07:00
Michael Jones ad709a752d [libc][obvious] fix sign warning in file_writer
In the sign writer, a size_t was being compared to an int. This patch
casts the size_t to an int so that the comparison doesn't cause a sign
comparison warning.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D127984
2022-06-17 09:48:04 -07:00
Guillaume Chatelet 7b73f53790 [libc] Rely on __builtin_memcpy_inline for memcpy implementation
This patch removes usage of `-mllvm -combiner-global-alias-analysis`
and relies on compiler builtin to implement `memcpy`.

Note that `-mllvm -combiner-global-alias-analysis` is actually only useful for
functions where buffers can alias (namely `memcpy` and `memmove`). The other
memory functions where not benefiting from the flag anyways.

The upside is that the memory functions can now be compiled from source with
thinlto (thinlto would not be able to carry on the flag when doing inlining).

The downside is that for compilers other than clang (i.e. not providing
`__builtin_memcpy_inline`) the codegen may be worse.

Differential Revision: https://reviews.llvm.org/D128051
2022-06-17 14:22:26 +00:00
Tue Ly 6441bfb886 [libc][Obvious] Fix hyperlink and typo in math status page. 2022-06-17 09:35:51 -04:00
Tue Ly 72c1effb34 [libc] Add a status page for math functions.
Add a status page for math functions.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D127920
2022-06-16 17:41:46 -04:00
Michael Jones 1e6c819d6d [libc][obvious] fix address test on windows
On windows size_t != unsigned long.

Differential Revision: https://reviews.llvm.org/D127989
2022-06-16 10:53:54 -07:00
Michael Jones 5bcda1d3a9 [libc] fix line buffered empty file writes
Previously, any line buffered write of size 0 would cause an error.
The variable used to track the index of the last newline started at
the size of the write - 1, which underflowed. Now it's handled properly,
and a test has been added to prevent regressions.

Reviewed By: sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D127914
2022-06-16 09:54:57 -07:00
Michael Jones 652ecb251e [libc] add printf hex conversion
The hex converter handles the %x and %X conversions.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D126082
2022-06-16 09:51:09 -07:00
Alex Brachet 40a55fff05 [libc][NFC] Make explicit uint16_t casts in fenv 2022-06-16 16:18:44 +00:00
Guillaume Chatelet 4a6929f811 Revert "[libc] Apply no-builtin everywhere, remove unnecessary flags"
This reverts commit b2a9ea4420.
2022-06-16 09:28:17 +00:00
Siva Chandra f8fae5b660 [libc][Obvious] Include arm_acle.h only for aarch64 builds. 2022-06-15 23:06:34 -07:00
Siva Chandra 33d14e3cd3 [libc][aarch64] Set frame pointer of the new thread to the stack pointer.
This allows sniffing thread start args in a robust fashion.
2022-06-15 22:58:49 -07:00
Michael Jones ad233c6047 [libc] add printf
This patch adds the entrypoint for printf. With this, building a
"hello world" program with just LLVM-libc is possible.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D126831
2022-06-15 11:45:38 -07:00
Michael Jones 2e6eccfe34 [libc] refactor printf file writing
Add return values to converter functions to allow for better error
handling when writing files. Also move the file writing code around to
be easier to read.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D127773
2022-06-15 11:45:36 -07:00
Siva Chandra Reddy 0f72a0d2ae [libc][Obvious] Removed few unused vars. 2022-06-15 08:13:38 +00:00
Siva Chandra Reddy f0e608de27 [libc] Add linux threads targets only if __support/OSUtil targets are available. 2022-06-15 07:18:57 +00:00
Siva Chandra Reddy a099139fa9 [libc][NFC] Add src.__support.OSUtil targets conditionally.
Before this change, they were unconditionally added, irrespective of the
availability of the architecture specific pieces.
2022-06-15 06:33:31 +00:00
Siva Chandra Reddy 2eafb96289 [libc][NFC] Use uint32_t to represent futex words.
Futexes are 32 bits in size on all platforms, including 64-bit systems.
2022-06-15 05:44:00 +00:00
Alex Brachet 60d4a10710 [libc] Guard common macro names
Differential revision: https://reviews.llvm.org/D127692
2022-06-14 15:05:16 +00:00
Alex Brachet 6d1543a167 [libc] Add explicit casts for string functions
This fixes warnings from `-Wimplicit-int-conversion`

Differential revision: https://reviews.llvm.org/D127694
2022-06-13 21:07:45 +00:00
Alex Brachet 15db8c306d [libc] Add Fuchsia implementation of ::testing::Test 2022-06-13 21:03:51 +00:00
Siva Chandra Reddy 5db4177817 [libc] Add pthread_detach and thrd_detach.
Tests for pthread_detach and thrd_detach have not been added. Instead, a
test for the underlying implementation has been added as it makes use of
an internal wait method to synchronize with detached threads.

Reviewed By: lntue, michaelrj

Differential Revision: https://reviews.llvm.org/D127479
2022-06-11 05:29:40 +00:00
Tue Ly ee89927707 [libc] Implement double precision FMA for targets without FMA instructions.
Implement double precision FMA (Fused Multiply-Add) for targets without
FMA instructions using __uint128_t to store the intermediate results.

Reviewed By: michaelrj, sivachandra

Differential Revision: https://reviews.llvm.org/D124495
2022-06-10 20:57:27 -04:00
Michael Jones 02f4affe2d [libc] add EXP_MAT_MASK to x87 long double
A previous patch added the constant EXP_MANT_MASK to the FloatProperties
for other types of long double. This patch adds it to the special 80-bit
x87 long double.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D127550
2022-06-10 16:26:29 -07:00
Tue Ly 2a746ebf1a [libc][Obvious] Change all __builtin_clz* calls to clz in builtin_wrappers.h. 2022-06-10 16:03:10 -04:00
Michael Jones 6ce490e5a6 [libc] add buffering to FILE writes
Previously all FILE objects were fully buffered, this patch adds line
buffering and unbuffered output, as well as applying them to stdout and
stderr.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D126829
2022-06-10 09:58:46 -07:00
Benjamin Kramer 6ee5baeb97 [libc][math] Add EXP_MANT_MASK when long double is double or quad 2022-06-10 18:48:31 +02:00
Kirill Okhotnikov b03567fe2b [libc][math] Improved FBits performance and readablity.
Some function added in preparation to fmod commit.

Differential Revision: https://reviews.llvm.org/D127097
2022-06-10 10:21:44 +02:00
Kirill Okhotnikov 76b57ef88c [libc][math] Differential "diff" test for hypot/hypotf functions.
Added test handler in preparation to fmod/fmodf commit.

Differential Revision: https://reviews.llvm.org/D127091
2022-06-10 10:08:47 +02:00
Kirill Okhotnikov 081aba27b1 [libc][math] Separated builtin function in special FPUtils header.
A small refactoring of builtin functions in preparation to adding fmod/fmodf function.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D127088
2022-06-10 03:18:35 +02:00
Michael Jones e1c54d4ddc [libc] move printf_main in to object library
Previously printf_main was a header library, but header library
dependencies don't work properly so it's been moved to an object
library. Additionally, the writers have been marked inline.

Reviewed By: sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D126830
2022-06-09 14:35:18 -07:00
Michael Jones 1be3669dda [libc] add printf base 10 integer conversion
This patch adds support for d, i, and u conversions in printf, as well
as comprehensive unit tests.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D125929
2022-06-09 10:27:11 -07:00
Siva Chandra Reddy 214be9d1cd [libc] Add compile options to pthread_create target.
The compile options now match that of thrd_create. Two compile options
are of importance:
1. -O3 - This is required so that stack is not used between the clone
   syscall and the start function in the child thread.
2. -fno-omit-frame-pointer - This is required so that we can sniff out
   the thread start args from the child thread's stack memory.

Without these two options, pthread_create will exhibit flaky behavior.

Reviewed By: lntue, michaelrj

Differential Revision: https://reviews.llvm.org/D127381
2022-06-09 17:26:19 +00:00
Michael Jones 0bff6a3e39 [libc] simplify printf converter tests
previously the printf converter tests reused the same string_writer,
which meant that each test depended on the tests before it to succeed.
This makes a new string_writer for each test to simplify and clarify the
tests.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D127341
2022-06-09 10:05:22 -07:00
Alex Brachet 6504b15992 [libc][NFC] Mark some methods constexpr
gcc is complaining that these methods are being called
from a function that is marked constexpr but these
aren't.
2022-06-08 22:41:09 +00:00
Alex Brachet 122da690b3 [libc] Fix build when __FE_DENORM is defined
Differential revision: https://reviews.llvm.org/D127222
2022-06-08 16:21:53 +00:00
Jeff Bailey ef3db4fcab Replace Goals and Why section with Introduction
Rewrite the introduction of the page to state clearly the goals of
LLVM's libc project.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D127174
2022-06-07 06:53:54 +00:00
Siva Chandra 0539a6b420 [libc] Align the new thread stack as required by the target ABI. 2022-06-06 14:45:43 -07:00
Tue Ly 667863d8a8 [libc] Fix cmake compatibility issue with list(POP_FRONT).
list(POP_FRONT) is only added to cmake in 3.15, while our base line
version is 3.13

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D127129
2022-06-06 13:36:03 -04:00
Fangrui Song d86a206f06 Remove unneeded cl::ZeroOrMore for cl::opt/cl::list options 2022-06-05 00:31:44 -07:00
Tue Ly 484319f497 [libc] Make expm1f correctly rounded when the targets have no FMA instructions.
Add another exceptional value and fix the case when |x| is small.

Performance tests with CORE-MATH project scripts:
With FMA instructions on Ryzen 1700:
```
$ ./perf.sh expm1f
LIBC-location: /home/lnt/experiment/llvm/llvm-project/build/projects/libc/lib/libllvmlibc.a
CORE-MATH reciprocal throughput   : 15.362
System LIBC reciprocal throughput : 53.194
LIBC reciprocal throughput        : 14.595
$ ./perf.sh expm1f --latency
LIBC-location: /home/lnt/experiment/llvm/llvm-project/build/projects/libc/lib/libllvmlibc.a
CORE-MATH latency   : 57.755
System LIBC latency : 147.020
LIBC latency        : 60.269
```
Without FMA instructions:
```
$ ./perf.sh expm1f
LIBC-location: /home/lnt/experiment/llvm/llvm-project/build/projects/libc/lib/libllvmlibc.a
CORE-MATH reciprocal throughput   : 15.362
System LIBC reciprocal throughput : 53.300
LIBC reciprocal throughput        : 18.020
$ ./perf.sh expm1f --latency
LIBC-location: /home/lnt/experiment/llvm/llvm-project/build/projects/libc/lib/libllvmlibc.a
CORE-MATH latency   : 57.758
System LIBC latency : 147.025
LIBC latency        : 70.304
```

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D123440
2022-06-03 15:57:48 -04:00
Tue Ly 614567a7bf [libc] Automatically add -mfma flag for architectures supporting FMA.
Detect if the architecture supports FMA instructions and if
the targets depend on fma.

Reviewed By: gchatelet

Differential Revision: https://reviews.llvm.org/D123615
2022-06-03 01:21:20 -04:00
Siva Chandra Reddy 70c8d12b79 [libc] Add pthread_create and pthread_join functions.
They do not yet support all the feature/attributes in pthread_attr_t.
Future changes will add such support.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D126718
2022-06-02 01:47:24 +00:00
Siva Chandra Reddy ad89cf4e2d [libc] Keep all thread state information separate from the thread structure.
The state is now stored on the thread's stack memory. This enables
implementing pthread API like pthread_detach which takes the pthread_t
structure argument by value.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D126716
2022-06-01 17:36:58 +00:00
Guillaume Chatelet b2a9ea4420 [libc] Apply no-builtin everywhere, remove unnecessary flags
Note, this is a re-submission of D125894 with `features = ["-header_modules"]`
added to the main BUILD.bazel file.

Some functions like `stpncpy` are implemented in terms of `memset` but are not
currently using `-fno-builtin-memset`. This is somewhat hidden by the fact that
we use `-ffreestanding` globally and that `-ffreestanding` implies
`-fno-builtin` for Clang.

This patch also removes `-mllvm -combiner-global-alias-analysis` that is Clang
specific and that does not bring substantial gains on modern processors.

Also we keep `-mllvm --tail-merge-threshold=0` for aarch64 in CMakeLists.txt
but we omit it in the Bazel config. This is because Bazel consumes the source
files directly and so it can use PGO to take optimal decisions locally.

Differential Revision: https://reviews.llvm.org/D126773
2022-06-01 13:34:36 +00:00
Guillaume Chatelet 4cbfd2e7eb [libc][mem*] Address facility + test enum support
This patch is a subpart of D125768 intented to make the review easier.

The `Address` struct represents a pointer but also adds compile time knowledge
like alignment or temporal/non-temporal that helps with downstream instruction
selection.

Differential Revision: https://reviews.llvm.org/D125966
2022-06-01 09:09:43 +00:00
Guillaume Chatelet 299baac64d [libc] Add support for enum in EXPECT_EQ 2022-06-01 08:42:18 +00:00
Tue Ly 800051487f [libc] Implement FLAGS option for generating all combinations for targets.
Add FLAGS option for add_header_library, add_object_library,
add_entrypoint_object, and add_libc_unittest.

In general, a flag is a string provided for supported functions under the
multi-valued option `FLAGS`.  It should be one of the following forms:
  FLAG_NAME
  FLAG_NAME__NO
  FLAG_NAME__ONLY
A target will inherit all the flags of its upstream dependency.

When we create a target `TARGET_NAME` with a flag using (add_header_library,
add_object_library, ...), its behavior will depend on the flag form as follow:
- FLAG_NAME: The following 2 targets will be generated:
    `TARGET_NAME` that has `FLAG_NAME` in its `FLAGS` property.
    `TARGET_NAME.__NO_FLAG_NAME` that depends on `DEP.__NO_FLAG_NAME` if
       `TARGET_NAME` depends on `DEP` and `DEP` has `FLAG_NAME` in its `FLAGS`
       property.
- FLAG_NAME__ONLY: Only generate 1 target `TARGET_NAME` that has `FLAG_NAME`
    in its `FLAGS` property.
- FLAG_NAME__NO: Only generate 1 target `TARGET_NAME.__NO_FLAG_NAME` that
    depends on `DEP.__NO_FLAG_NAME` if `DEP` is in its DEPENDS list and `DEP`
    has `FLAG_NAME` in its `FLAGS` property.

To show all the targets generated, pass SHOW_INTERMEDIATE_OBJECTS=ON to cmake.
To show all the targets' dependency and flags, pass
`SHOW_INTERMEDIATE_OBJECTS=DEPS` to cmake.

To completely disable a flag FLAG_NAME expansion, set the variable
`SKIP_FLAG_EXPANSION_FLAG_NAME=TRUE`.

Reviewed By: michaelrj, sivachandra

Differential Revision: https://reviews.llvm.org/D125174
2022-06-01 00:54:07 -04:00
Michael Jones ba7e1cddda [libc] add fprintf and file_writer
This patch adds the file_writer header, which just provides a wrapper
for File->write, as well as fprintf to use it. There are no unit tests
for file_writer since it's too simple to need them, but fprintf does
have a simple test of writing to a file.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D125939
2022-05-31 13:59:19 -07:00
Siva Chandra Reddy 9b8ca3c1f1 [libc] Add global stdout and stderr objects.
They are added as entrypoint object targets. The header-gen
infrastructure has been extended to enable handling standard required
global objects. The libc-api-test has also been extended to verify the
global object declarations.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D126329
2022-05-27 05:43:49 +00:00
Siva Chandra Reddy 2a5d5078d5 [libc] Add the pthread_mutex_t type.
Simple implementations of the functions pthread_mutex_init,
pthread_mutex_destroy, pthread_mutex_lock and pthread_mutex_unlock have
have also been added. Future patches will extend these functions to add
features required by the POSIX specification.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D126235
2022-05-24 22:48:14 +00:00
Alex Brachet 8725dc5e2f [libc][docs] Use same formatting for headers in source_layout
utils looks different from the other directory names
in the docs, see
https://libc.llvm.org/source_layout.html#the-utils-directory

Differential revision: https://reviews.llvm.org/D126211
2022-05-23 21:47:22 +00:00
Guillaume Chatelet 0443bfabe7 Revert "[libc] Apply no-builtin everywhere, remove unnecessary flags"
This reverts commit 94d6dd9057.
2022-05-20 14:37:17 +00:00
Alex Brachet b1183305f8 [libc] Add strlcat
Differential Revision: https://reviews.llvm.org/D125978
2022-05-19 21:48:39 +00:00
Guillaume Chatelet 94d6dd9057 [libc] Apply no-builtin everywhere, remove unnecessary flags
Some functions like `stpncpy` are implemented in terms of `memset` but are not
currently using `-fno-builtin-memset`. This is somewhat hidden by the fact that
we use `-ffreestanding` globally and that `-ffreestanding` implies
`-fno-builtin` for Clang.

This patch also removes `-mllvm -combiner-global-alias-analysis` that is Clang
specific and that does not bring substantial gains on modern processors.

Also we keep `-mllvm --tail-merge-threshold=0` for aarch64 in CMakeLists.txt
but we omit it in the Bazel config. This is because Bazel consumes the source
files directly and so it can use PGO to take optimal decisions locally.

Differential Revision: https://reviews.llvm.org/D125894
2022-05-19 09:08:42 +00:00
Michael Jones 72f6dfb378 [libc][windows] fix strlcpy tests
Generally, size_t is an alias for unsigned long long. In the strlcpy
tests, the return value of strlcpy (a size_t) is compared to an unsigned
long. On Linux unsigned long and unsigned long long are both 64 bits,
but on windows unsigned long is 32 bits. Since the macros require
identical types for both sides, this caused a build failure on windows.
This patch changes the constants to be explicit size_t values.

Differential Revision: https://reviews.llvm.org/D125917
2022-05-18 14:11:53 -07:00
Michael Jones f8ae591fc9 [libc] fix missing semicolon in bsd_ext.td
Fix typo in previous commit

Differential Revision: https://reviews.llvm.org/D125913
2022-05-18 11:22:26 -07:00
Alex Brachet 6adbcd2b10 [libc] Add String to bsd headers 2022-05-18 18:01:02 +00:00
Alex Brachet fc2c8b2371 [libc] Add strlcpy
Differential Revision: https://reviews.llvm.org/D125806
2022-05-18 17:45:05 +00:00
Michael Jones 9f1d905f39 [libc] add snprintf
After adding sprintf, snprintf is simple. The functions are very
similar. The tests only cover the behavior of the max length since the
sprintf tests should cover the other behavior.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D125826
2022-05-17 13:32:59 -07:00
Michael Jones ff6fe39eca [libc] add sprintf
This adds the sprintf entrypoint, as well as unit tests. Currently
sprintf only supports %%, %s, and %c, but the other conversions are on
the way.

Reviewed By: sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D125573
2022-05-17 11:32:20 -07:00
Michael Jones 6a22b185d6 [libc] add printf converter
This adds the main pieces of the last piece of printf, the converter.
This takes the completed format section from the parser and then
converts it to a string for the writer, which is why it was the last
piece to be written. So far it supports chars and strings, but more
pieces are coming. Additionally, it supports replacing all of the
conversion functions with user supplied versions at compile time to
allow for additional functionality.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D125327
2022-05-12 13:10:05 -07:00
Michael Jones 12aae7d9a6 [libc][docs] Add doc for libc stdio functions
This patch adds a document describing the status of the string functions
in LLVM-libc.

Reviewed By: sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D123823
2022-05-12 13:02:23 -07:00
Michael Jones dd7f30464b [libc] fix uint includes and libc bazel
This patch fixes the includes for the new UInt class so that the api
test now passes, additionally it fixes the bazel files to account for
the new dependencies.

Differential Revision: https://reviews.llvm.org/D125490
2022-05-12 11:40:52 -07:00
Michael Jones 1170951c73 [libc] add uint128 implementation
Some platforms don't support proper 128 bit integers, but some
algorithms use them, such as any that use long doubles. This patch
modifies the existing UInt class to support the necessary operators.
This does not put this new class into use, that will be in followup
patches.

Reviewed By: sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D124959
2022-05-12 11:16:53 -07:00
Tue Ly 6d92f4022d [libc][Obvious] Fix cmake usage of list PREPEND (unavailable pre-3.15). 2022-05-08 13:58:05 -04:00
Tue Ly 13f358376a [libc] Add LINK_LIBRARIES option to add_fp_unittest and add_libc_unittest.
This is needed to prepare for adding FLAGS option.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D125055
2022-05-08 17:33:45 +00:00
Michael Jones 945fa672c6 [libc][NFC] add index mode to printf parser
This patch is a followup to the previous patch which implemented the
main printf parsing logic as well as sequential mode. This patch adds
index mode.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D123424
2022-05-06 12:06:08 -07:00
Michael Jones 270ca878d9 [libc] Update windows entrypoint list
The entrypoint list for windows hasn't been updated in a while, this
adds all of the entrypoints that are working for windows now.

Reviewed By: sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D125058
2022-05-06 11:30:50 -07:00
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