Commit Graph

456 Commits

Author SHA1 Message Date
Siva Chandra Reddy 12df3080fe [libc] Compile integration tests with -ffreestanding to avoid mixup with system libc. 2022-07-30 03:06:08 +00:00
Tue Ly 2ff187fbc9 [libc] Implement cosf function that is correctly rounded to all rounding modes.
Implement cosf function that is correctly rounded to all rounding
modes.

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 cosf
CORE-MATH reciprocal throughput   : 19.043
System LIBC reciprocal throughput : 26.328
LIBC reciprocal throughput        : 30.955

$ CORE_MATH_PERF_MODE="rdtsc" ./perf.sh cosf --latency
GNU libc version: 2.31
GNU libc release: stable
CORE-MATH latency   : 49.995
System LIBC latency : 59.286
LIBC latency        : 60.174

```
After this patch (correctly rounded):
```
$ CORE_MATH_PERF_MODE="rdtsc" ./perf.sh cosf
GNU libc version: 2.31
GNU libc release: stable
CORE-MATH reciprocal throughput   : 19.072
System LIBC reciprocal throughput : 26.286
LIBC reciprocal throughput        : 13.631

$ CORE_MATH_PERF_MODE="rdtsc" ./perf.sh cosf --latency
GNU libc version: 2.31
GNU libc release: stable
CORE-MATH latency   : 49.872
System LIBC latency : 59.468
LIBC latency        : 56.119
```

Reviewed By: orex, zimmermann6

Differential Revision: https://reviews.llvm.org/D130644
2022-07-29 21:08:31 -04:00
Kirill Okhotnikov a7f55f0805 [libc][math] Added sinhf function.
Differential Revision: https://reviews.llvm.org/D129278
2022-07-29 17:20:53 +02:00
Kirill Okhotnikov fcb9d7e2cf [libc][math] Added coshf function.
Differential Revision: https://reviews.llvm.org/D129275
2022-07-29 16:57:28 +02:00
Guillaume Chatelet f72261508a [libc][NFC] Use STL case for type_traits
Migrating all private STL code to the standard STL case but keeping it under the CPP namespace to avoid confusion. Starting with the type_traits header.

Differential Revision: https://reviews.llvm.org/D130727
2022-07-29 09:57:03 +00:00
Kirill Okhotnikov 4b41e7b436 [libc][math] Universal exp function for cosh/sinh calculation.
Added a function and test, which can be used later for cosh/sinh
and possibly for expf/expm1f.

Differential Revision: https://reviews.llvm.org/D129215
2022-07-28 11:24:09 +02:00
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 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
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
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
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
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 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 4f281fa2a8 [libc] Reset rounding mode after fsetround tests
Differential Revision: https://reviews.llvm.org/D129619
2022-07-13 15:42:47 +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
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 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
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
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
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 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
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
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 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 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