Commit Graph

879 Commits

Author SHA1 Message Date
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