Commit Graph

641 Commits

Author SHA1 Message Date
Michael Jones 9830518082 [libc][obvious] fix strdup being listed twice
strdup was being included even if malloc wasn't and that was causing
a build failure.

Differential Revision: https://reviews.llvm.org/D112641
2021-10-27 11:13:08 -07:00
Michael Jones 65bb6593e5 [libc] add strdup implementation
Add an implementation for strdup.

Reviewed By: lntue, sivachandra

Differential Revision: https://reviews.llvm.org/D111584
2021-10-27 10:21:04 -07:00
Michael Jones 7dcdbabb3b [libc] add malloc funcs as external entrypoints
malloc, calloc, realloc, and free are all functions that other libc
functions depend on, but are pulled from external sources, instead of
having an internal implementation. This patch adds a way to include
functions like that as entrypoints in the list of external entrypoints,
and includes the malloc functions using this new path.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D112104
2021-10-27 10:21:01 -07:00
Michael Jones 53804d4eb2 [libc] fix strtol returning the wrong length
Previously, strtol/ll/ul/ull would return a pointer to the end of its
parsing, regardless of if it detected a number. Now it will return a
length of 0 when it doesn't find a number.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D112176
2021-10-25 15:00:45 -07:00
Joe Loser 59cf6a7403
[libc][NFC] Remove extra space in libc/CMakeLists.txt 2021-10-25 16:29:14 -04:00
Joe Loser 46c82753f6
[libc][NFC] Remove extra slash in path in libc/CMakeLists.txt
Remove extra `/` in path to match the include filepath from the previous
line.

Differential Revision: https://reviews.llvm.org/D112476
2021-10-25 16:26:49 -04:00
Kazu Hirata d8e4170b0a Ensure newlines at the end of files (NFC) 2021-10-23 08:45:29 -07:00
Michael Jones 87c016078a [libc] add atof, strtof and strtod
Add the string to floating point conversion functions.
Long doubles aren't supported yet, but floats and doubles are. The
primary algorithm used is the Eisel-Lemire ParseNumberF64 algorithm,
with the Simple Decimal Conversion algorithm as backup.

Links for more information on the algorithms:

Number Parsing at a Gigabyte per Second, Software: Practice and
Experience 51 (8), 2021 (https://arxiv.org/abs/2101.11408)
https://nigeltao.github.io/blog/2020/eisel-lemire.html
https://nigeltao.github.io/blog/2020/parse-number-f64-simple.html

Differential Revision: https://reviews.llvm.org/D109261
2021-10-18 16:10:03 -07:00
Guillaume Chatelet 4a9bcb605b [libc] Memory function benchmarks: rename MemcmpConfiguration in MemcmpOrBcmpConfiguration
This will help make sense of the double use of the same type in https://reviews.llvm.org/D111622#inline-1065560.

Differential Revision: https://reviews.llvm.org/D111868
2021-10-15 13:42:29 +00:00
Michael Jones db8a88fef8 [libc] add memccpy and mempcpy
Add an implementation for memccpy and mempcpy. These functions are
posix extensions for the moment.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D111762
2021-10-14 16:38:00 -07:00
Michael Jones 9e9803bf82 [libc] Add strncat and fix strcat
This adds strncat to llvm libc. In addition, an error was found with
strcat and that was fixed.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D111583
2021-10-12 18:18:18 +00:00
Guillaume Chatelet ad82fe7b28 [libc] Add rep;movsb as an accelerator under x86 2021-10-08 14:31:55 +00:00
Guillaume Chatelet f256c39541 [libc] ifdef guard element architecture implementations 2021-10-08 14:25:26 +00:00
Guillaume Chatelet d01ae990e1 Revert "[libc] Add rep;movsb as an accelerator under x86"
This reverts commit 1c7160300d.
2021-10-08 13:44:37 +00:00
Guillaume Chatelet 1c7160300d [libc] Add rep;movsb as an accelerator under x86 2021-10-08 13:34:59 +00:00
Michael Jones 6f80339b18 [libc][NFC] Add supporting class for atof implementation
This change adds the High Precision Decimal described here:
https://nigeltao.github.io/blog/2020/parse-number-f64-simple.html
It will be used for the atof implementation later, but is complete and
tested now.

The code is inspired by the golang implmentation of the HPD class, which
can be found here: https://github.com/golang/go/blob/release-branch.go1.16/src/strconv/decimal.go

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D110454
2021-10-04 21:08:02 +00:00
Guillaume Chatelet adc18ad6ac [libc] move benchmark function registration to a different file 2021-09-30 13:11:33 +00:00
Michael Jones b62d72f3c5 [libc] Add support for 128 bit ints in limits.h
Also, this adds unit tests to check that limits.h complies with the C
standard.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D110643
2021-09-28 23:50:16 +00:00
Siva Chandra Reddy 8379fc4a53 [libc] Add implementations of the C standard condition variable functions.
Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D108948
2021-09-28 21:18:45 +00:00
Siva Chandra Reddy 5c3c716bb1 [libc] Add FE_DFL_ENV and handle it in fesetenv.
Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D110611
2021-09-28 18:09:52 +00:00
Michael Jones 43c543aab7 [libc][NFC] Make strchr and strrchr more consistent
Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D110581
2021-09-28 17:42:03 +00:00
Siva Chandra Reddy 5eb6b82729 [libc] Add an implementation of qsort.
A fuzzer for qsort has also been added.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D110382
2021-09-24 19:22:45 +00:00
Andre Vieira 8b87c3d573 [libc] Add optimized memset for AArch64
Differential Revision: https://reviews.llvm.org/D107848
2021-09-23 09:19:47 +01:00
Siva Chandra Reddy 32a5007865 [libc] Add an implementation of bsearch.
Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D110222
2021-09-22 16:37:03 +00:00
Siva Chandra Reddy f5b8f1247c [libc][obvious] Add inttypes.h and stdlib.h as deps to *div functions. 2021-09-20 05:54:32 +00:00
Siva Chandra Reddy 5252aa2981 [libc][obvious] Make *abs and *div functions buildable in default mode. 2021-09-20 05:44:49 +00:00
Siva Chandra Reddy 74670e79b0 [libc] Add implementations of div, ldiv, lldiv and imaxdiv.
Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D109952
2021-09-20 04:51:42 +00:00
Cheng Wang 3582828748 [libc][Obvious] Some clean work with memmove. 2021-09-14 17:30:37 +08:00
Guillaume Chatelet cc84ce9129 Revert "[libc] Some clean work with memmove."
This reverts commit b659b789c0.
2021-09-13 14:32:08 +00:00
Siva Chandra Reddy 0da5ac1a75 [libc] Add extension functions fedisableexcept, feenableexcept and fegetexcept.
Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D109613
2021-09-10 18:44:53 +00:00
Cheng Wang 2fc1913505 [libc] Check signs instead of values in memcmp unittests.
The C standard only guarantees the sign of return value. The exact return
value is implementation defined.

Reviewed By: gchatelet

Differential Revision: https://reviews.llvm.org/D109588
2021-09-10 18:35:10 +08:00
Cheng Wang b659b789c0 [libc] Some clean work with memmove.
- Replace `move_byte_forward()` with `memcpy`. In `memcpy` implementation,
it copies bytes forward from beginning to end. Otherwise, `memmove` unit
tests will break.
- Make `memmove` unit tests work.

Reviewed By: gchatelet

Differential Revision: https://reviews.llvm.org/D109316
2021-09-10 16:52:42 +08:00
Siva Chandra Reddy c5cfbe40de [libc] Skip fenv exception tests on aarch64 if HW doesn't support exceptions.
Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D109538
2021-09-09 20:47:59 +00:00
Guillaume Chatelet 219a1d217d [libc] Fix running benchmarks under msan/asan
asan/msan intercepts `aligned_malloc` and misbehave when the requested
alignment is greater than 512.
b041b613e6/compiler-rt/lib/asan/asan_allocator.cpp (L430-L431)
2021-09-08 14:43:55 +00:00
Siva Chandra Reddy 2bf8be79b1 [libc][NFC] Add fenv and string headers to x86_64 headers list. 2021-09-07 21:06:39 +00:00
Cheng Wang 9b015383f1 [libc][Obvious] Reorder CMakelists alphabetically. 2021-09-05 11:01:05 +08:00
Cheng Wang 7abd8f6c6e [libc][Obvious] Fix typos 2021-09-05 10:54:52 +08:00
Michael Jones 37ce7349f7 [libc] fix strtointeger hex prefix parsing
Fix edge case where "0x" would be considered a complete hexadecimal
number for purposes of str_end. Now the hexadecimal prefix needs a valid
digit after it, else just the 0 will be counted as the number.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D109084
2021-09-03 20:39:15 +00:00
Siva Chandra Reddy 2f4f452f16 [libc] Add a skeleton for C standard condition variable functions.
This patch adds a skeleton as a preparatory step for the next patch which
adds the actual implementations of the condition variable functions.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D108947
2021-09-01 19:41:52 +00:00
Siva Chandra Reddy 0239adac4a [libc] Mark return value of memcpy in strcpy as initialized for msan.
Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D109045
2021-09-01 19:01:25 +00:00
Michael Jones 7f2ce19d1c [libc][nfc][obvious] fix typos in FPUtil
Fix minor typos in FPUtil comments.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D108952
2021-08-30 22:39:02 +00:00
Siva Chandra Reddy 7a2a765745 [libc] Add mtx_destroy which does nothing.
There is not cleanup to be done for the mutex type so mtx_destroy does
nothing.
2021-08-30 20:43:46 +00:00
Siva Chandra Reddy 3383ec5fdd [libc] Ensure the result of the clone syscall is not on stack in thrd_create.
Also, added a call to munmap on error in thrd_create.
2021-08-30 04:35:40 +00:00
Siva Chandra Reddy f7e572b4f4 [libc][NFC] Add a check to catch mismatch in internal and public mutex types. 2021-08-30 04:08:35 +00:00
Roland McGrath 225eb8a22d [libc][NFC] Fix onre more -Wconversion warning in strtoul test code.
The last change missed one spot.

Differential Revision: https://reviews.llvm.org/D108845
2021-08-27 14:12:39 -07:00
Roland McGrath 4e1a164d7b [libc] Fix various -Wconversion warnings in strto*l test code.
The Fuchsia build compiles the libc and test code with lots
of warnings enabled, including all the integer conversion warnings.
There was some sloppy type usage here that triggered some of those.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D108800
2021-08-27 14:04:00 -07:00
Siva Chandra Reddy 8e284be04f [libc][Obvious] Add header guards for the generated linux syscall header file. 2021-08-27 16:17:53 +00:00
Siva Chandra Reddy 004c7b1da6 [libc][NFC] Move the mutex implementation into a utility class.
This allows others parts of the libc to use the mutex types without
actually pulling in public function implementations.

Along the way, few cleanups have been done, like using a uniform type to
refer the linux futex word.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D108749
2021-08-26 18:49:20 +00:00
Michael Jones 035325275c [libc] add inttypes header
Add inttypes.h to llvm libc. As its first functions strtoimax and
strtoumax are included.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D108736
2021-08-26 18:04:21 +00:00
Michael Jones fdee2d768d [libc] Fix too long number in strtoul_test
I think this is the last windows type conversion fix, the rest of the
build seems to be okay.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D108659
2021-08-24 20:17:09 +00:00
Michael Jones 6bbfd6a9c1 [libc] Fix type errors on Windows
Fix the errors caused by having some numbers too large for a 32 bit
number in the tests for windows. Also fix the base causing some type
confusion.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D108653
2021-08-24 19:42:13 +00:00
Michael Jones 1d02a8bcd3 [libc] fix string conversion tests for windows
There were some copy paste errors as well as some oddities around how
windows handles the difference between long and long long types. This
change fixes those.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D108591
2021-08-24 18:06:21 +00:00
Michael Jones eff11176c5 [libc] Enable string to integer conversion functions in the default build
Adds atoi, atol, atoll, strtol, strtoll, strtoul, and strtoull to the
list of entrypoints for Windows and aarch64 linux, as well as moving
them out of the LLVM_LIBC_FULL_BUILD condition for x86_64 linux.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D108477
2021-08-23 21:18:14 +00:00
Alfonso Gregory 9cdd4ea06f [libc][NFC] Add explicit casts to ctype functions
Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D106902
2021-08-23 18:17:20 +00:00
Siva Chandra Reddy 8e488c3cc0 [libc] Add a multi-waiter mutex test.
A corresponding adjustment to mtx_lock has also been made.
2021-08-23 05:47:30 +00:00
Siva Chandra Reddy ca6b354229 [libc] Add range reduction functions based on Paine and Hanek algorithm.
These functions will be used in a future patch to implement
trigonometric functions. Unit tests have been added but to the
libc-long-running-tests suite. The unit tests long running because we
compare against MPFR computations performed at 1280 bits of precision.

Some cleanups or elimination of repeated patterns can be done as follow
up changes.

Differential Revision: https://reviews.llvm.org/D104817
2021-08-23 05:18:41 +00:00
Siva Chandra Reddy 5e147d3058 [libc] Add a new suite called "libc-long-running-tests".
This suite is helpful is adding long running tests which take a long
time to finish that they can be run on the public builders. They
will probably be run on special builders in future.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D104816
2021-08-21 05:01:28 +00:00
Fangrui Song 40aab0412f [test] Migrate -gcc-toolchain with space separator to --gcc-toolchain=
Space separated driver options are uncommon but Clang traditionally
did not do a good job. --gcc-toolchain= is the preferred form.
2021-08-20 15:24:58 -07:00
Michael Jones 6ce6fa4ad4 [libc] make the scudo integration test run
adds a custom command for libc-scudo-integration-test that makes it run
when it is built.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D108409
2021-08-20 17:51:11 +00:00
Guillaume Chatelet 791d88f35f [libc] Align to 32B instead of 16B for optimized memcmp 2021-08-20 13:09:35 +00:00
Guillaume Chatelet b460534ac7 [libc] Add an optimized version for memcmp
Differential Revision: https://reviews.llvm.org/D108406
2021-08-20 06:40:37 +00:00
Siva Chandra Reddy 1cd3d19271 [libc] Add bcmp to the windows config. 2021-08-20 04:51:09 +00:00
Siva Chandra Reddy aeee014428 [libc][Obvious] Fix llvm_libc_ext.td. 2021-08-19 18:54:43 +00:00
Michael Jones bad3168b99 [libc] add atoi, atol, and atoll
This is based on the work done to add strtoll and the other strto
functions. The atoi functions also were added to stdc and
entrypoints.txt.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D108330
2021-08-19 18:02:51 +00:00
Guillaume Chatelet c8f79892af [libc] Add a trivial implementation for bcmp
Differential Revision: https://reviews.llvm.org/D108225
2021-08-19 17:55:16 +00:00
Michael Jones d52f0aeca5 [libc] Add strtol, strtoul, and strtoull
Updates the internal string conversion function so that it
uses the new Limits.h added in a previous commit for max and min values,
and has a templated type. This makes implementing the other strto*
functions very simple.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D107999
2021-08-17 21:05:37 +00:00
Siva Chandra Reddy 9a56d71f61 [libc][NFC] Disable double precision cos, sin and tan on Windows.
The current x86_64 implementations do not build on the windows bot
machine. We will enable them back after fixing the problem.
2021-08-17 16:47:20 +00:00
Guillaume Chatelet 83457d398d [libc] dedup handling of size 4 for memset 2021-08-16 22:29:10 +00:00
Guillaume Chatelet 8e4efad991 [libc] Optimize Loop strategy
Since the precondition for loop is `size >= T::kSize` we always expect
at least one run of the loop. This patch transforms the for-loop into a
do/while-loop which saves at least one test.

We also add a second template parameter to allow the Tail operation to
differ from the loop operation.
2021-08-16 22:17:56 +00:00
Michael Jones 472fa04de8 [libc][nfc] add CPP Limits.h for numeric_limits
Add an implementation of numeric_limits for use in str_conv_utils.
It currently only supports the basic integer types, with more types
coming as needed.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D107987
2021-08-12 21:31:16 +00:00
Michael Jones b062d639bb [libc] add strtoll function and backend
This change adds the stroll function, but most of the implementation is
in the new file str_conv_utils.h since many of the other integer
conversion functions are implemented through what are effectively calls
to strtoll.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D107792
2021-08-11 23:37:23 +00:00
Guillaume Chatelet c82ba4b820 [libc] Update size distributions for memory benchmarks
All distributions have been updated using 7 days worth of data.
2021-08-09 14:22:32 +00:00
Michael Jones c120edc7b3 [libc][nfc] move ctype_utils and FPUtils to __support
Some ctype functions are called from other libc functions (e.g. isspace
is used in atoi). By moving ctype_utils.h to __support it becomes easier
to include just the implementations of these functions. For these
reasons the implementation for isspace was moved into
ctype_utils as well.

FPUtils was moved to simplify the build order, and to clarify which
files are a part of the actual libc.

Many files were modified to accomodate these changes, mostly changing
the #include paths.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D107600
2021-08-06 17:29:41 +00:00
Hedin Garca a9628e96ca [libc] Add diff and perf targets for more math functions
Comparing the run time of math functions from LLVM libc
with the MSVCRT libc:
|function	|perf-LLVM libc		    |perf-MSVCRT
|ceilf		|2.36 mins (141491389600 ns)|47.10 sec (47100940100 ns)
|exp2f             |6.37 mins (358441794700 ns)|12.39 mins (719404388300 ns)
|expf		|6.35 mins (381204661800 ns)|6.17 mins (346150163200 ns)
|fabsf		|1.18 mins (78425546600 ns) |53.75 sec (53745301900 ns)
|floorf		|3.15 mins (164770963800 ns)|45.94 sec (45935988400 ns)
|logbf		|4.38 mins (262508058800 ns)|55.47 sec (55466377700 ns)
|nearbyintf	|3.20 mins (167972868000 ns)|9.13 mins (523822963600 ns)
|rintf		|3.20 mins (168001498700 ns)|22.35 mins (1341266448800 ns)
|roundf		|2.35 mins (141151500600 ns)|1.42 mins (85326429800 ns)
|truncf		|2.31 mins (114846424000 ns)|59.41 sec (59414309100 ns)

Evaluating the number of differing results in Windows:
|function	|diff
|ceilf          |8388606 differing results
|exp2f         |213303887 differing results
|expf           |193922 differing results
|fabsf          |8388606 differing results
|floorf         |8388606 differing results
|logbf          |0 differing results
|nearbyintf     |0 differing results
|rintf          |0 differing results
|roundf         |0 differing results
|truncf 	|0 differing results

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D107462
2021-08-05 17:57:04 +00:00
Michael Jones 6ed60fb8a2 [libc] add integration tests for scudo in libc
This change adds tests to make sure that SCUDO is being properly
included with llvm libc. This change also adds the toggles to properly
use SCUDO, as GWP-ASan is enabled by default and must be included for
SCUDO to function.

Reviewed By: sivachandra, hctim

Differential Revision: https://reviews.llvm.org/D106919
2021-08-04 20:06:09 +00:00
Andre Vieira 2f002817fb [libc] Fix Memory Benchmarks code after rename
Differential Revision: https://reviews.llvm.org/D107376
2021-08-04 09:17:12 +01:00
Guillaume Chatelet e4dee76224 [libc] Allow benchmarking several implementations at the same time.
Next step is to generate an archive with all implementations and a header listing them all.

Differential Revision: https://reviews.llvm.org/D107336
2021-08-03 10:53:11 +00:00
Hedin Garca 2ab18d57d7 [libc] Add differential and performance targets for sqrtf
Comparing the runtime of the sqrt functions from LLVM libc with the system libc:
|function       |perf - LLVM libc          |perf - MSVCRT
|sqrtf - Windows|44.05 sec (44051715500 ns)| 417.84 sec (417843359900 ns) = 6.96 mins

|function       |perf - LLVM libc          |perf - glibc
|sqrtf - Linux  |30.48 sec (30479458632 ns)|43.72 sec (43716901527 ns)

By running the differential test:
|function       |diff
|sqrtf - Windows|0 differing results
|sqrtf - Linux  |0 differing results

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D107229
2021-08-02 19:29:48 +00:00
Guillaume Chatelet 59198d062f [libc] Add a Google Benchmark target to support continuous monitoring of memory operation performance
The next step is to be able to benchmark several implementations at once and compare which one performs best on a particular machine.

Differential Revision: https://reviews.llvm.org/D107265
2021-08-02 12:14:11 +00:00
Siva Chandra Reddy 66d92efc66 [libc] Add trigonometric and exponential functions to the windows config. 2021-07-31 01:30:26 +00:00
Siva Chandra Reddy 3d758e68a7 [libc] Move FPExceptMatcher out of TestHelpers.h
TestHelpers.h pulls few pieces from LLVM libc's unittest framework
which aren't available on platforms like Fuchsia which use their own
unittest framework. So, by moving FPExceptMatcher to a different file
we can exclude LLVM libc specific pieces in a cleaner way.

In a later pass, it might make more sense to rename TestHelpers.h also
to FPMatcher.h. That way, we can make macros like EXPECT_FP_EQ to be
equivalent to EXPECT_EQ on platforms like Fuchsia.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D107129
2021-07-30 23:44:29 +00:00
Siva Chandra Reddy 381f9affab [libc][NFC] Add dummy errno target to satisfy mixed mode builds.
In mixed mode builds, we should not be including errno as part of
LLVM libc - errno from another library (or the system library) should be
used. But, other entrypoints which use errno list LLVM libc's errno as a
dep ta satisfy the full build mode. So, we add a dummy errno
implementation with empty files to make both mixed mode and full build
mode happy.
2021-07-30 17:42:48 +00:00
Guillaume Chatelet cd2f5d5b49 [libc] rewrite aarch64 memcmp implementation
This patch is simply rearranging the code layout so it's easier to understand.

Differential Revision: https://reviews.llvm.org/D106641
2021-07-29 14:41:12 +00:00
Alfonso Gregory 640ed21cce [libc][NFC] Add noreturn and constexpr qualifiers where appropriate
These functions make it clear to the compiler and user what the intended
behavior is so llvm can make them go as fast as possible.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D106807
2021-07-29 04:50:05 +00:00
Michael Jones c6d03b583b [libc] add strncmp to strings
Add strncmp as a function to strings.h. Also adds unit tests, and adds
strncmp as an entrypoint for all current platforms.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D106901
2021-07-28 21:37:12 +00:00
Guillaume Chatelet d3c70d9f77 [libc] Simplify implementation of benchmarks
This also allows to run the distribution benchmarks in other frameworks
like the Google Benchmark facility.
2021-07-28 15:04:19 +00:00
Alfonso Gregory 0784e62c3c [libc] Fix strtok_r crash when src and *saveptr are both nullptr
While working and testing my refactoring of multiple string functions in libc, I came across a bug that needs to be addressed in a patch on its own: src is checked for nullptr and assigned to *saveptr if it is nullptr. However, saveptr is initially nullptr when it comes to reentry. This could cause a problem if both saveptr and src are null; we need to do the check first and return nullptr if both are nullptr.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D106885
2021-07-27 21:49:23 +00:00
Siva Chandra Reddy dd8b93a9e7 [libc] Fix x86_64 fenv implementation for windows
All fenv functions are also enabled for windows. Since two tests,
enabled_exceptions_test and feholdexcept_test are still failing on
windows, they have been disabled.

Reviewed By: aeubanks

Differential Revision: https://reviews.llvm.org/D106808
2021-07-27 20:53:01 +00:00
Hedin Garca 8baa87d918 [libc] Enable MPFR library for math functions test
Included more math functions to Windows's entrypoints
and made a cmake option (-DLLVM_LIBC_MPFR_INSTALL_PATH)
where the user can specify the install path where the MPFR
library was built so it can be linked. The try_compile was
moved to LLVMLibCCheckMPFR.cmake, so the variable that is
set after this process can retain its value in other files
of the same parent file. A direct reason for this is for
LIBC_TESTS_CAN_USE_MPFR to be true when the user specifies
MPFR's path and retain its value even after leaving the file.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D106894
2021-07-27 20:40:04 +00:00
Michael Jones 016ae7df95 [libc] add scudo wrappers to llvm libc
The previous patch included the implementations for the scudo allocator,
but not the wrappers. This change fixes that.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D106718
2021-07-26 17:24:52 +00:00
Guillaume Chatelet 47afd43eaa [libc] fix LibcUnitTestMain when building with shared libraries 2021-07-26 08:43:45 +00:00
Siva Chandra Reddy c24c18bba6 [libc] Accommodate Fuchsia's death test framework in fenv tests.
Fuchsia's death test framework runs the closure which can die in a
different thread. Hence, the FP exceptions which cause the closure to
die should be enalbed in the closure.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D106683
2021-07-23 22:19:04 +00:00
Caitlyn Cano 5d679fc502 [libc] Clean up Windows macros
This clean-up removes checks for _WIN64, as the _WIN32 macro returns 1
whenever the compilation targe is 32- or 64-bit ARM.

Reviewed By: aeubanks

Differential Revision: https://reviews.llvm.org/D106706
2021-07-23 21:12:36 +00:00
Michael Jones da06d1795a [libc] add option to use SCUDO as the allocator
This patch adds LLVM_LIBC_INCLUDE_SCUDO as a flag. When enabled it
should link in the standalone version of SCUDO as the allocator for LLVM
libc.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D106502
2021-07-23 17:36:09 +00:00
Caitlyn Cano fa7a9ef178 [libc] Add option to run specific tests
This addition reads command line input to run specific single tests
within a larger call to run all the tests for a particular function.
When the user adds a second argument to the command line, the code skips
all the tests that don't match the user's specified binary. If the user
doesn't specify a test correctly and/or no tests are run, a failure
message prints.

Reviewed By: sivachandra, aeubanks

Differential Revision: https://reviews.llvm.org/D105843
2021-07-23 16:08:13 +00:00
Guillaume Chatelet 24ffb98f9d [libc] optimize bzero/memset for x86
This is simpy using the x86 optimized elements when targetting x86 cpus.

Differential Revision: https://reviews.llvm.org/D106551
2021-07-23 12:21:46 +00:00
Siva Chandra Reddy c698be47ff [libc] Raise denormal exception if the libc defines __FE_DENORM.
Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D106604
2021-07-23 05:42:18 +00:00
Hedin Garca 049cfc464d [libc] Rename FEnv.h and refactor subsequent files
Because Windows's pathnames are not case sensitive,
to avoid include conflicts between our header file FEnv.h and the
one from the C Standard library, <fenv.h>, the prior file was renamed.
The motive for the relabel came to fix this include error in
TestHelpers.cpp since a conflict arose with a file in the same
directory when #include <fenv.h> was being used.

Reviewed By: sivachandra, aeubanks

Differential Revision: https://reviews.llvm.org/D106470
2021-07-22 00:07:39 +00:00
John Ericson e7fe4433f8 Remove `LIBC_INSTALL_PREFIX`
This matches the decision made in D99697.

It also shouldn't reintroduce the issue fixed in D99636.

The variable was originally introduced in
b22f448c21 but is not essential to that
change.

Once we finish adding `GnuInstallDirs` support in D100810 and D99484,
setting `CMAKE_INSTALL_LIBDIR` would also work to change the
installation directory (though for more than libc).

`GnuInstallDirs` support also brings up an issue which is avoided if
variables like `LIBC_INSTALL_PREFIX` don't exist. Because the
`GnuInstallDirs` variables can be absolute paths, it is a bit unclear
how the per-project prefixes would work: does the project-agnostic
role-specific variable (e.g. `CMAKE_INSTALL_LIBDIR`), or project-specfic
role-agnostic (e.g. `LIBC_INSTALL_PREFIX`) take priority? Each is more
specific than the other on one axis, but not the other.

Reviewed By: phosek

Differential Revision: https://reviews.llvm.org/D105740
2021-07-21 23:07:36 +00:00
Hedin Garca efa2115266 [libc] Include nextafter's functions to Windows's entrypoints
Incorporated the varied functions for nextafter and refactored
NextAfterTest.h to correctly define bitWidthOfType for both
Linux and Windows; by letting FloatProperties take care
of the directives' logic based on the platform being used.
This allows to successfully run nextafter's tests.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D106395
2021-07-21 13:28:01 +00:00
Hedin Garca f49f2e2d1f [libc] Append math functions to Window's entrypoints
Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D106391
2021-07-21 13:21:55 +00:00
Hedin Garca 137740eced [libc] Exclude few unused bits from x86 state for Windows
Windows fenv_t does not include the MXCSR register and
the unused bits at the end of the x87 status. So we
exclude them in our struct definitions to make it
easy to read/write the state. getEnv and setEnv
were also excluded to avoid using MXCSR, but a
forthcoming patch will handle these functions.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D106386
2021-07-21 13:11:10 +00:00
Siva Chandra Reddy a31f6d2ccf [libc][Obvious] Fix few typos in FPUtil/TestHelpers.cpp 2021-07-21 08:07:35 +00:00
Siva Chandra Reddy ff384700f2 [libc][NFC] Adjust enabled_exceptions_test wrt FE_INEXACT.
Since exceptions like FE_DIVBYZERO can raise FE_INEXACT, we need to
ensure that we don't raise FE_DIVBYZERO (or others which can also raise
FE_INEXACT) when FE_INEXACT is enabled.
2021-07-21 05:49:19 +00:00
Siva Chandra Reddy ec14ab9624 [libc] Add a new test matcher for tests raising floating point exceptions.
This new matcher does not use death tests to check if SIGFPE is raised.
Instead, that a SIGFPE was raised is checked using a SIGFPE signal handler.

Reviewed By: mcgrathr

Differential Revision: https://reviews.llvm.org/D106086
2021-07-21 04:59:39 +00:00
Roland McGrath 8f053eadbe [libc] Fix typos in x86_64/FEnv.h
Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D106105
2021-07-15 15:21:07 -07:00
Hedin Garca c97cb11efd [libc] Relocate the closing directive of #ifdef
Changed where an #endif was placed because previously it
prevented three macro definitions from being enable in Windows.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D106087
2021-07-15 20:24:29 +00:00
Hedin Garca a5a337e55e [libc] Capture floating point encoding and arrange it sequentially in memory
Redefined FPBits.h and LongDoubleBitsX86 so its implementation works for the Windows
and Linux platform while maintaining a packed memory alignment of the precision floating
point numbers. For its size in memory to be the same as the data type of the float point number.
This change was necessary because the previous attribute((packed)) specification in the struct was not working
for Windows like it was for Linux and consequently static_asserts in the FPBits.h file were failing.

Reviewed By: aeubanks, sivachandra

Differential Revision: https://reviews.llvm.org/D105561
2021-07-13 20:43:54 +00:00
Caitlyn Cano a16071e409 [libc] Don't pass -fpie/-ffreestanding on Windows
The current compile options function hardcodes the -fpie and
-ffreestanding flags, which don't exist on Windows. This patch sets the
compilation flags conditionally based on the OS specifics.

Reviewed By: sivachandra, aeubanks

Differential Revision: https://reviews.llvm.org/D105643
2021-07-13 20:39:51 +00:00
Hedin Garca d12a7f142e [libc] Add on float properties for precision floating point numbers in FloatProperties.h
Defined constant that express the number of bits for exponent in single and double precision. Added bit masks values and other properties for quad precision floating point numbers that specifically targets architectures defined in PlatfromDefs.h. The exponentWidth values were added to be used in LongDoubleBitsX86.h where the implementation to set the exponent component uses this and the bitWidth value. The need occurred because of the 80-bit quad precision implementation.

Reviewed By: aeubanks

Differential Revision: https://reviews.llvm.org/D105153
2021-07-13 20:15:54 +00:00
Guillaume Chatelet 8724a7ec11 [libc] update benchmark distributions
All distributions (expect D) have been updated using 7 days worth of data.
Distributions are smoother.
This patch also moves data from header file to individual csv file. It
helps the editor and allows easier export/plotting of the data.

Differential Revision: https://reviews.llvm.org/D105766
2021-07-13 09:59:25 +00:00
Guillaume Chatelet 223261cbaa Fix broken libc test 2021-07-07 16:47:49 +00:00
Andre Vieira 366805ea17 [LIBC] Add an optimized memcmp implementation for AArch64
Differential Revision: https://reviews.llvm.org/D105441
2021-07-07 15:59:14 +01:00
Siva Chandra Reddy dba74c6817 [libc] Make ULP error reflect the bit distance more closely.
Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D105334
2021-07-02 16:56:01 +00:00
Caitlyn Cano e4b9fecd39 [libc] Add minimal Windows config
A README file with procedure for building/testing LLVM libc on Windows
has also been added.

Reviewed By: sivachandra, aeubanks

Differential Revision: https://reviews.llvm.org/D105231
2021-07-01 20:45:57 +00:00
Siva Chandra Reddy e7e71e9454 [libc][NFC] Remove few deprecated FPUtil header files and test patterns.
Few tests have been converted to the new test patterns to facilitate
this.
2021-06-30 22:09:23 +00:00
Siva Chandra 578a4cfe19 [libc][NFC] Clear all exceptions in exception_flags_test before raising another.
This is because, raising some exceptions can raise other ones. For
example, raising FE_OVERFLOW can raise FE_INEXACT. So, we need to clear all
exceptions if we want a clean slate.
2021-06-30 13:48:07 -07:00
Siva Chandra Reddy 230df8a419 [libc] Allow reading and writing __FE_DENORM if available on x86_64.
Some libcs define __FE_DENORM on x86_64. This change allows reading the
bits corresponding to that non-standard exception.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D105004
2021-06-30 17:32:24 +00:00
Siva Chandra Reddy 804dc3dcf2 [libc] Clear all exceptions before setting in fesetexceptflag.
Previously, exceptions from the flag were being added. This patch
changes it such that only the exceptions in the flag will be set.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D105085
2021-06-30 17:29:48 +00:00
Siva Chandra Reddy 9474ddc3ac [libc] Fix feclearexcept for x86_64.
Previously, feclearexcept cleared all exceptions irrespective of the
argument. This change brings it in line with the aarch64 flavors wherein
only those exceptions listed in the argument will be cleared.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D105081
2021-06-30 17:28:06 +00:00
Siva Chandra Reddy 58af0d567d [libc] Allow target architecture independent configs
Previously, we required entrypoints.txt for every target architecture
supported by a target OS. With this change, we allow architecture
independent config for a target OS. That is, if an architecture specific
entrypoints.txt is missing, then a generic entrypoints.txt for that
target OS will be used.

Reviewed By: caitlyncano

Differential Revision: https://reviews.llvm.org/D105147
2021-06-29 20:41:28 +00:00
Siva Chandra 487f74a6c4 [libc][Obvious] Fix typo in implementation of aarch64 clearExcept.
Instead of reading and updating the status word, control word was being
updated.
2021-06-28 23:17:37 -07:00
Siva Chandra Reddy 2e9c75daff [libc] Use __builtin_ctzll instead of __builtin_ctzl in elements_x86.h.
__builtin_ctzl takes an unsigned long argument which need not be 64-bit
long on all platforms. Using __builtin_ctzll, which takes an unsigned
long long argument, ensures that 64-bit values will be handled on a
wider range of platforms.

Without this change, the test corresponding to M512 fails in Windows.

Reviewed By: gchatelet

Differential Revision: https://reviews.llvm.org/D104897
2021-06-25 22:58:13 +00:00
Siva Chandra Reddy d5700bb694 [libc] Calculate ulp error after rounding MPFR result to the result type.
Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D104615
2021-06-23 20:29:46 +00:00
Guillaume Chatelet 87065c0d24 [libc] add benchmarks for memcmp and bzero
Differential Revision: https://reviews.llvm.org/D104511
2021-06-23 14:19:40 +00:00
Siva Chandra Reddy 7a1e4f1846 [libc][Obvious] Add the new header file PlatformDefs.h to the fputil target. 2021-06-18 07:37:06 +00:00
Siva Chandra Reddy 37afd67c38 [libc] Add few macro definitions to make it easy to accommodate Windows.
The new macro definitions have been used to add Windows specific
specializations.
2021-06-18 07:17:36 +00:00
Guillaume Chatelet 8d64ed8544 [libc] Generate one benchmark per implementation
We now generate as many benchmarks as there are implementations.

Differential Revision: https://reviews.llvm.org/D102156
2021-06-17 12:14:10 +00:00
Guillaume Chatelet 7fff39d9b0 [libc] Add a set of elementary operations
Resubmission of D100646 now making sure that we handle cases were `__builtin_memcpy_inline` is not available.

Original commit message:
Each of these elementary operations can be assembled to support higher order constructs (Overlapping access, Loop, Aligned Loop).
The patch does not compile yet as it depends on other ones (D100571, D100631) but it allows to get the conversation started.

A self-contained version of this code is available at https://godbolt.org/z/e1x6xdaxM
2021-06-16 12:11:45 +00:00
Guillaume Chatelet c3242238b7 Revert "[libc] Add a set of elementary operations"
This reverts commit 4694321fbe.
2021-06-16 11:22:46 +00:00
Guillaume Chatelet 4694321fbe [libc] Add a set of elementary operations
Resubmission of D100646 now making sure that we handle cases were `__builtin_memcpy_inline` is not available.

Original commit message:
Each of these elementary operations can be assembled to support higher order constructs (Overlapping access, Loop, Aligned Loop).
The patch does not compile yet as it depends on other ones (D100571, D100631) but it allows to get the conversation started.

A self-contained version of this code is available at https://godbolt.org/z/e1x6xdaxM
2021-06-16 11:16:24 +00:00
Siva Chandra Reddy 3af3e7dc57 [libc][NFC] Disable thrd_test as it is exhibiting flaky behavior on the bots. 2021-06-15 20:58:36 +00:00
Guillaume Chatelet 2e286f233e Revert "[libc] Add a set of elementary operations"
This reverts commit 8387187c2f.
2021-06-15 15:00:21 +00:00
Guillaume Chatelet 8387187c2f [libc] Add a set of elementary operations
Resubmission of D100646 now making sure that we handle cases were `__builtin_memcpy_inline` is not available.

Original commit message:
Each of these elementary operations can be assembled to support higher order constructs (Overlapping access, Loop, Aligned Loop).
The patch does not compile yet as it depends on other ones (D100571, D100631) but it allows to get the conversation started.

A self-contained version of this code is available at https://godbolt.org/z/e1x6xdaxM
2021-06-15 14:39:04 +00:00
Guillaume Chatelet c11032ad9a Revert "[libc] Add a set of elementary operations"
This reverts commit 454d92ac3b.
2021-06-15 08:01:59 +00:00
Guillaume Chatelet 454d92ac3b [libc] Add a set of elementary operations
Resubmission of D100646 now making sure that we handle cases were `__builtin_memcpy_inline` is not available.

Original commit message:
Each of these elementary operations can be assembled to support higher order constructs (Overlapping access, Loop, Aligned Loop).
The patch does not compile yet as it depends on other ones (D100571, D100631) but it allows to get the conversation started.

A self-contained version of this code is available at https://godbolt.org/z/e1x6xdaxM
2021-06-15 07:57:13 +00:00
Siva Chandra Reddy a58b2827fe [libc] Add hardware implementations of x86_64 sqrt functions. 2021-06-14 21:25:37 +00:00
Guillaume Chatelet ab45c1f21f Revert "[libc] Add a set of elementary operations"
This reverts commit e63f27a3cf.
2021-06-14 09:34:03 +00:00
Guillaume Chatelet e63f27a3cf [libc] Add a set of elementary operations
Each of these elementary operations can be assembled to support higher order constructs (Overlapping access, Loop, Aligned Loop).
The patch does not compile yet as it depends on other ones (D100571, D100631) but it allows to get the conversation started.

Differential Revision: https://reviews.llvm.org/D100646
2021-06-14 09:01:06 +00:00
Tue Ly 4e5f8b4d8d [libc] Add implementation of expm1f.
Use expm1f(x) = exp(x) - 1 for |x| > ln(2).
For |x| <= ln(2), divide it into 3 subintervals: [-ln2, -1/8], [-1/8, 1/8], [1/8, ln2]
and use a degree-6 polynomial approximation generated by Sollya's fpminmax for each interval.
Errors < 1.5 ULPs when we use fma to evaluate the polynomials.

Differential Revision: https://reviews.llvm.org/D101134
2021-06-10 14:58:34 -04:00
Siva Chandra Reddy b5d6da3587 [libc] Remove libc-fuzzer as a dependency to check-libc. 2021-06-10 05:06:03 +00:00
Siva Chandra Reddy 3d515cb185 [libc][NFC][Obvious] Compare against size_t values in ArrayRef tests.
Different platforms treat size_t differently so we should compare sizes
of ArrayRef objects with size_t values (instead of the current unsigned
long values.)
2021-06-09 00:14:05 +00:00
Siva Chandra Reddy 6344a583ca [libc] Add a macro to include/exclude subprocess tests.
This is useful when bringing up LLVM libc on a new OS on which we do not
yet have the subprocess related helper functions.
2021-06-08 23:30:21 +00:00
Siva Chandra Reddy f4c8fd12d5 [libc][NFC] Use add_library instead of add_llvm_library for a few libraries.
These libraries do not depend on LLVM libraries anymore so they do not
have to be added using add_llvm_library.
2021-06-08 23:15:24 +00:00
Simon Pilgrim c2ab3d2c85 LibcBenchmark.h - add missing implicit cmath header dependency. NFCI.
Noticed while investigating if we can remove an unnecessary MathExtras.h include from SmallVector.h
2021-06-06 10:39:31 +01:00
Siva Chandra Reddy b47539a14d [libc] Enable fmaf and fma on x86_64.
They require clang-11 or above for building and hence had to be disabled
as the bots did not have clang-11 or higher. Bots have now been upgraded
so we can enable these functions now.
2021-05-13 20:51:15 +00:00
Siva Chandra Reddy 7deb5ef44f [libc][NFC] Instead of erroring, skip math targets with missing implementations.
Fixes Aarch64 bot.
2021-05-13 19:22:11 +00:00
Siva Chandra Reddy 861dc75906 [libc] Add x86_64 implementations of double precision cos, sin and tan.
The implementations use the x86_64 FPU instructions. These instructions
are extremely slow compared to a polynomial based software
implementation. Also, their accuracy falls drastically once the input
goes beyond 2PI. To improve both the speed and accuracy, we will be
taking the following approach going forward:
1. As a follow up to this CL, we will implement a range reduction algorithm
which will expand the accuracy to the entire double precision range.
2. After that, we will replace the HW instructions with a polynomial
implementation to improve the run time.

After step 2, the implementations will be accurate, performant and target
architecture independent.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D102384
2021-05-13 19:02:00 +00:00
Guillaume Chatelet 6351993da7 [libc] Simplifies multi implementations
This is a roll forward of D101895 with two additional fixes:

Original Patch description:
> This is a follow up on D101524 which:
>
> - simplifies cpu features detection and usage,
> - flattens target dependent optimizations so it's obvious which implementations are generated,
> - provides an implementation targeting the host (march/mtune=native) for the mem* functions,
> - makes sure all implementations are unittested (provided the host can run them).

Additional fixes:
 - Fix uninitialized ALL_CPU_FEATURES
 - Use non pseudo microarch as it is only supported from Clang 12 on

Differential Revision: https://reviews.llvm.org/D102233
2021-05-12 07:24:53 +00:00
Siva Chandra Reddy 0c64cef894 [libc] Rever "Simplifies multi implementations and benchmarks".
This reverts commit 541f107871 as the bots
are failing with unknown architecture "x86-64-v*". Will let the original
author decide on the right course of action to correct the problem and
reland.
2021-05-10 19:20:27 +00:00