Commit Graph

772 Commits

Author SHA1 Message Date
Tue Ly 355e56f5b2 [libc][trivial] Make LlvmLibcExhaustiveTest::check method purely virtual. 2022-01-13 14:35:11 -05:00
Tue Ly 8cd81274ff [libc] Add multithreading support for exhaustive testing and MPFRUtils.
Add threading support for exhaustive testing and MPFRUtils.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D117028
2022-01-13 13:46:14 -05:00
Tue Ly cce6507767 [libc] Add rounding mode support for MPFR testing macros.
Add an extra argument for rounding mode to EXPECT_MPFR_MATCH and ASSERT_MPFR_MATCH macros.

Reviewed By: sivachandra, michaelrj

Differential Revision: https://reviews.llvm.org/D116777
2022-01-13 13:28:50 -05:00
Michael Jones 04e8c8f997 [libc] fix strtold_test formatting on ARM
I missed a variable when reformatting the tests. This fixes that.

Differential Revision: https://reviews.llvm.org/D117161
2022-01-12 14:34:57 -08:00
Michael Jones ba6a3972d7 [libc] add working ARM entrypoints
Some functions were added to x86_64 that were untested on Aarch64. Now
that I've had an opportunity to test them, they all work on Aarch64 with
the minor formatting change included.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D117146
2022-01-12 14:24:18 -08:00
Siva Chandra Reddy 134e9d1914 [libc][NFC] Move sys/mman entrypoints to the default build configs.
Specifically, mmap and munmap have been moved to the default build list
of entrypoints. To support this, certain deps and includes have been
adjusted. The use of errno in some cases has been updated.
2022-01-11 16:51:10 +00:00
Siva Chandra 371779fac1 [libc] Add linux aarch64 syscall implementation.
Add mmap and munmap to the linux aarch64 entrypoint list as the first
user of these syscalls.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D116949
2022-01-10 15:53:17 -08:00
Siva Chandra Reddy cd4deef28e [libc] Re-enable thrd_test.
Other threads related tests have been using the API that is tested here
without any problems. The main reason for disabling the test has also been
fixed many months ago.
2022-01-10 06:18:51 +00:00
Siva Chandra Reddy 60509623c4 [libc][obvious] Fix style of MPFRWrapper. 2021-12-23 23:19:42 +00:00
Michael Jones 3e52096809 [libc][NFC] fix variable name
A variable was named in a way that doesn't match the format. This patch
renames it to match the format.

Differential Revision: https://reviews.llvm.org/D116228
2021-12-23 10:42:30 -08:00
Tue Ly 12779edd71 [libc] Add performance tests for hypotf and hypot.
Add performance tests for hypotf and hypot.

Reviewed By: sivachandra, michaelrj

Differential Revision: https://reviews.llvm.org/D116122
2021-12-23 00:44:43 -05:00
Michael Jones 9b39737129 [libc] add modified Eisel-Lemire for long doubles
The Eisel-Lemire algorithm is an effecient way to handle converting to
floating point numbers from strings, but in its base form it only
supports up to 64 bit floating point numbers. This adds an
implementation to handle long doubles.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D115280
2021-12-22 16:45:22 -08:00
Siva Chandra Reddy e8a0af8013 [libc][Obvious] Add target OSUtil tests only if the target OS/arch match. 2021-12-22 22:38:03 +00:00
Siva Chandra Reddy 3cc2161c89 [libc] Move the x86_64 syscall functions to OSUtil.
Reviewed By: michaelrj, lntue

Differential Revision: https://reviews.llvm.org/D116177
2021-12-22 21:48:57 +00:00
Michael Jones 79abf89303 [libc][obvious] fix formatting mistake
I missed two instances of "SetUp" being replaced by "set_up" and
"TearDown" being replaced by "tear_down" when finalizing the formatting
change. This fixes that.

Differential Revision: https://reviews.llvm.org/D116178
2021-12-22 11:40:08 -08:00
Michael Jones 25226f3e4a [libc] apply formatting to tests
Apply the formatting rules that were applied to the libc/src directory
to the libc/test directory, as well as the files in libc/utils that are
included by the tests. This does not include automated enforcement.

Reviewed By: sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D116127
2021-12-22 10:53:25 -08:00
Tue Ly db8716a2ec [libc] Show average runtime for math single-input-single-output performance tests.
Run performance tests in denormal and normal ranges separately and show more detailed results.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D116112
2021-12-21 14:22:20 -05:00
Tue Ly 9369aa1444 [libc][Obvious] Change func_ to <func>_ in add_math_function.md. 2021-12-17 13:32:51 -05:00
Michael Jones 467b5017e2 [libc] fix memcpy builtin looping
previously, memcpy could get stuck in a loop, calling __builtin_memcpy
which would redirect to itself. This patch removes that path.

Reviewed By: gchatelet, sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D115542
2021-12-16 13:54:35 -08:00
Tue Ly 4036b12d96 [libc] Fix problem with using isnan in test/src/math/logf_test.cpp.
The default isnan returns an int, and hence failing the EXPECT_TRUE tests.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D115892
2021-12-16 14:51:10 -05:00
Tue Ly d08a801b5f [libc] Implement correctly rounded logf based on RLIBM library.
Implement correctly rounded logf based on RLIBM library: https://people.cs.rutgers.edu/~sn349/rlibm/.

Reviewed By: sivachandra, santoshn, jpl169, zimmermann6

Differential Revision: https://reviews.llvm.org/D115408
2021-12-16 13:43:15 -05:00
Tue Ly a2b3e6bed8 [libc] Add documentation about how to add a math function to LLVM-libc.
Add documentation about how to add a math function to LLVM-libc.

Differential Revision: https://reviews.llvm.org/D115608
2021-12-16 12:12:21 -05:00
Siva Chandra Reddy 2cf203d9f6 [libc] Disable signal.h API and its users.
The signal.h header file from LLVM libc is incorrect. The signal API and
its users will be enabled once signal.h is fixed.
2021-12-16 05:52:28 +00:00
Siva Chandra Reddy 261c17c1d3 [libc][NFC] Remove dependecies on entrypoints from loader tests.
A small collection of utils called osutils has been added. These utils
are now used in loader tests instead of the equivalent entrypoints.
The loader can now be built and tested without depending on any entrypoint.
In a follow up change, the relevent entrypoints will be updated to use the
newly added osutils.

Reviewed By: lntue, michaelrj

Differential Revision: https://reviews.llvm.org/D115655
2021-12-13 19:29:29 +00:00
Michael Jones aa1902f917 [libc] add basic strtold implementation
Due to the differences between the types of long double, this function
is effectively three functions in one. This patch adds basic support for
the types of long double, although it's just using the fast path and the
fallback for the moment. I still need to implement a version of
Eisel-Lemire for performance, but the existing algorithms should be
correct.

Reviewed By: sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D113710
2021-12-13 10:40:44 -08:00
Siva Chandra Reddy d37d0aadbf [libc][NFC] Add back NOLINT anntotations to PolyEval.
They were accidentally removed in a previous change.
2021-12-13 07:08:08 +00:00
Tue Ly 08aa40b9e6 [libc] Add ADD_FMA_FLAG macro to add -mfma flag to functions that requires it.
Add ADD_FMA_FLAG macro to add -mfma flag to functions that requires it.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D115572
2021-12-11 16:21:33 -05:00
Siva Chandra Reddy e5d104b280 [libc][NFC] Add NOLINT annotations at call sites to immintrin functions.
These annotations are intended to be temporary while we understand why
clang-tidy is not able to treat them as builtin exceptions.
2021-12-10 06:38:45 +00:00
Tue Ly cdf6a581b9 [libc] Use intrinsics for x86-64 fma and optimize PolyEval for x86-64 with degree 3 & 5 polynomials.
- Use intrinsics for x86-64 fma
- Optimize PolyEval for x86-64 with degree 3 & 5 polynomials.
- There might be a slight loss of accuracy compared to Horner's scheme due to usages of higher powers x^2 and x^3 in the computations.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D115347
2021-12-09 18:34:18 -05:00
Siva Chandra Reddy a5a79f69d6 [libc] Add a .clang-tidy file for the toplevel libc directory.
Generation of the .yaml has been removed to prevent lint from
running with every ninja invocation. The new .clang-tidy file is copied
to the libc build directory so that generated files also get checked.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D115405
2021-12-09 00:19:25 +00:00
Siva Chandra Reddy 45927444e7 [libc][Obvious] Fix variable naming in the generic sqrt implementations. 2021-12-08 19:57:46 +00:00
Haojian Wu 5bb0a9075c [libc] Fix two missing cases in 1c92911e9e
Fix the broken build.
2021-12-08 15:14:21 +01:00
Mircea Trofin 5dda2efde5 Re-Reland "[benchmarks] Move libcxx's fork of google/benchmark and llvm/utils'"
This reverts commit b2fbd45d23. D114922
fixed the reason of the 2nd revert.

This patch also re-applies 39e9f5d368.

Differential Revision: https://reviews.llvm.org/D112012
2021-12-07 17:10:41 -08:00
Michael Jones 5b3a51fda1 [libc][obvious] fix missed rename
In https://reviews.llvm.org/D114302 I renamed ForLoopCopy to
for_loop_copy, but these got missed.

Differential Revision: https://reviews.llvm.org/D115303
2021-12-07 16:09:37 -08:00
Michael Jones 2b197888e0 [libc] fix the .yaml files not being tracked
adds the .yaml files clang-tidy generates as byproducts, which means
that they will be updated properly and cleaned by `ninja -t clean`

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D115290
2021-12-07 16:04:46 -08:00
Michael Jones 1c92911e9e [libc] apply new lint rules
This patch applies the lint rules described in the previous patch. There
was also a significant amount of effort put into manually fixing things,
since all of the templated functions, or structs defined in /spec, were
not updated and had to be handled manually.

Reviewed By: sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D114302
2021-12-07 10:49:47 -08:00
Michael Jones 43e2f7cd24 [libc] update tidy rules to fix variable formatting
This commit changes the clang-tidy rules for LLVM-libc to follow the new
format. The next commit applies these rules to the codebase.

The rules are as follows:

CamelCase for classes
lower_case for variables
lower_case for functions
UPPER_CASE for constexpr variables

There are also some exceptions, but the most important one is that any
function or variable that starts with an underscore is exempt from the
formatting.

Reviewed By: sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D114301
2021-12-07 10:49:45 -08:00
Guillaume Chatelet b902b314ff [libc] Fix invalid include for SqrtLongDouble.h 2021-12-03 16:13:59 +00:00
Guillaume Chatelet 71405d90f0 [libc] Select FPUtils implementations via code instead of build
We want to simplify the build system and rely on code to do the implementation selection.
This is in preparation of adding a Bazel configuration (D114712).

Differential Revision: https://reviews.llvm.org/D115034
2021-12-03 15:48:41 +00:00
Tue Ly dbed678f4b [libc] Fix bugs with negative and mixed normal/denormal inputs in hypot implementation.
Fix a bug with negative and mixed normal/denormal inputs in hypot implementation.

Differential Revision: https://reviews.llvm.org/D114726
2021-12-03 10:14:04 -05:00
Guillaume Chatelet cca8e1e415
[libc][NFC] Fix typo in CMakeLists documentation 2021-12-03 13:52:09 +01:00
Guillaume Chatelet 1479a211d2
Fix typos in FPUtil README 2021-12-03 10:22:00 +01:00
Tue Ly 32568fc95e [libc] Fix a bug in MPFRUtils making ULP values off by 2^(-mantissaWidth).
Fix a bug in MPFRUtils making ULP values off by 2^(-mantissaWidth) and incorrect eps for denormal numbers.

Differential Revision: https://reviews.llvm.org/D114878
2021-12-02 09:07:46 -05:00
Guillaume Chatelet bdcc5aadf5 [libc] Add _64 element to aarch64 2021-12-01 08:20:21 +00:00
Michael Jones 155f5a6dac [libc][clang-tidy] fix namespace check for externals
Up until now, all references to `errno` were marked with `NOLINT`, since
it was technically calling an external function. This fixes the lint
rules so that `errno`, as well as `malloc`, `calloc`, `realloc`, and
`free` are all allowed to be called as external functions. All of the
relevant `NOLINT` comments have been removed, and the documentation has
been updated.

Reviewed By: sivachandra, lntue, aaron.ballman

Differential Revision: https://reviews.llvm.org/D113946
2021-11-30 11:44:24 -08:00
Guillaume Chatelet af059dfef5 [libc] Add a reasonably optimized version for bcmp
This is based on current memcmp implementation.

Differential Revision: https://reviews.llvm.org/D114432
2021-11-30 10:52:34 +00:00
Guillaume Chatelet de21f34691 [libc] Add memmove benchmarks
This patch enables the benchmarking of `memmove`.
Ideally, this should be submitted before D114637.

Differential Revision: https://reviews.llvm.org/D114694
2021-11-30 10:46:16 +00:00
Siva Chandra Reddy 7b59fcb7de [libc] Make string entrypoints mutualy exclusive.
For example, strcpy does not pull memcpy now.

Reviewed By: gchatelet

Differential Revision: https://reviews.llvm.org/D114300
2021-11-26 16:29:22 +00:00
Guillaume Chatelet 408c0cc4eb [libc] Fix wrong type for load/store of Repeated elements 2021-11-24 14:13:13 +00:00
Guillaume Chatelet 1b927b68b6 [libc] add memmove basic building blocks
Differential Revision: https://reviews.llvm.org/D113321
2021-11-22 14:31:56 +00:00
Guillaume Chatelet 2f1c037bbd [libc] Remove unused variable 2021-11-22 10:12:46 +00:00
Siva Chandra Reddy d9bbad277c [libc][Obvious][NFC] A bunch of cosmetic cleanup.
* Added missing header guards.
* Fixed license header format in a few files.
* Renamed files to more suitable names.
2021-11-19 17:02:55 +00:00
Michael Jones 47d0c83e1f [libc] fix strtof/d/ld NaN parsing
Fix the fact that previously strtof/d/ld would only accept a NaN as
having parentheses if the thing in the parentheses was a valid number,
now it will accept any combination of letters and numbers, but will only
put valid numbers in the mantissa.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D113790
2021-11-17 11:00:54 -08:00
Guillaume Chatelet 649d953716 [libc] Use more consistent if defined syntax 2021-11-17 15:16:28 +00:00
Guillaume Chatelet 5ee5acf7d9 [libc] Fix missing restricts 2021-11-17 15:16:25 +00:00
Guillaume Chatelet 392da6428d [libc] Fix documentation typo 2021-11-17 15:16:05 +00:00
Guillaume Chatelet 13744e3d73 [libc][benchmark] add memmove to size distribution, also update other distributions
Differential Revision: https://reviews.llvm.org/D113260
2021-11-17 09:22:05 +00:00
Mircea Trofin 67de95b8c9 Revert "[libc][NFC][Obvious] Fix the benchmarks after the switch to llvm/third-party"
This reverts commit 39e9f5d368.

Reverting, as we needed to re-revert the benchmarks move because it was
causing a build failure in the Fuchsia bots due to the way they consume
libcxx's CMakeLists. I want to make sure I understand where the fix
should be for that. After that, I'll incorporate the change here in the
re-reland.
2021-11-16 16:59:14 -08:00
Mircea Trofin b2fbd45d23 Revert "Reland "[benchmarks] Move libcxx's fork of google/benchmark and llvm/utils'"""
This reverts commit 1ee32055ea.

We hit additional bot failures; in particular, Fuchsia's seems to be
related to how CMakeLists are ingested, see https://ci.chromium.org/ui/p/fuchsia/builders/toolchain.ci/clang-linux-x64/b8830380874445931681/overview
2021-11-16 16:35:06 -08:00
Siva Chandra Reddy 39e9f5d368 [libc][NFC][Obvious] Fix the benchmarks after the switch to llvm/third-party 2021-11-16 22:24:49 +00:00
Tue Ly 201cc2d885 [libc] Correct rounding for hexadecimalStringToFloat with long inputs.
Update binaryExpTofloat so that it will round correctly for long inputs when converting hexadecimal strings to floating points.

Differential Revision: https://reviews.llvm.org/D113815
2021-11-16 14:29:39 -05:00
Mircea Trofin 1ee32055ea Reland "[benchmarks] Move libcxx's fork of google/benchmark and llvm/utils'""
This reverts commit e7568b68da and relands
c6f7b720ec.

The culprit was: missed that libc also had a dependency on one of the
copies of `google-benchmark`

Also opportunistically fixed indentation from prev. change.

Differential Revision: https://reviews.llvm.org/D112012
2021-11-16 10:33:31 -08:00
Shao-Ce SUN 0c660256eb [NFC] Trim trailing whitespace in *.rst 2021-11-15 09:17:08 +08:00
Tue Ly 499ca806dc [libc] Simplify decimalStringToFloat and hexadecimalStringToFloat and improve their performance.
Combine two loops in decimalStringToFloat and hexadecimalStringToFloat that extract the digits and re-arrange them a little bit.  This slightly improves the performance of strtof and strtod:
Running libc_str_to_float_comparison_test parse-number-fxx-test_data/data/* on my machine (Ryzen 1700)
- with glibc: ~1.92 seconds
- with current implementation: ~1.78 seconds
- with this change: ~1.67 seconds

Differential Revision: https://reviews.llvm.org/D113681
2021-11-11 18:33:24 -05:00
Michael Jones 4cdf9884b6 [libc] tweak strtof errno behavior
When strtof/d/ld return a subnormal number they may set errno to
ERANGE. This change makes this behavior more consistent by making any
decimal number converting to a subnormal set errno to ERANGE. This
brings it in line with hexadecimals, which currently only set errno to
ERANGE if the number is truncated when converting to a subnormal.

Reviewed By: sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D113626
2021-11-11 10:17:38 -08:00
Michael Jones 18da0c0a28 [libc] clean up FPUtil long doubles
Add quietNaNMask consts to FloatProperties and make LongDoubleBitsX86
clear the extra bits that aren't set when initializing with an 80 bit
long double.

Reviewed By: sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D113625
2021-11-11 10:17:36 -08:00
Michael Jones 8298424cae [libc] refactor atof string parsing
Split the code for parsing hexadecimal floating point numbers from the
code for parsing the decimal floating point numbers so that the parsing
can be faster for both of them.

This decreases the time for the benchmark in release mode by about 15%,
which noticeably beats GLibc.

Old version: 2.299s
New version: 1.893s
GLibc: 2.133s

Tests run by running the following command 10 times for each version:
time ~/llvm-project/build/bin/libc_str_to_float_comparison_test ~/parse-number-fxx-test-data/data/*

the parse-number-fxx-test-data-repository is here:
fe94de252c

It's important to build llvm-libc in Release mode for accurate
performance comparisons against glibc (set -DCMAKE_BUILD_TYPE=Release in
your cmake).
You also have to build the libc_str_to_float_comparison_test target.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D113036
2021-11-09 10:12:18 -08:00
Michael Jones 9b6f8b985c [libc] add stpcpy and stpncpy
Adds an implementation for stpcpy and stpncpy, which are posix extension
functions.

Reviewed By: sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D111913
2021-11-04 11:39:26 -07:00
Guillaume Chatelet c02aa15438 [libc][NFC] Allow memset (and bzero) to be inlined
This allows shipping individual functions without also having to provide
memset or bzero at the expense of bigger functions.

Similar to D113097.

Differential Revision: https://reviews.llvm.org/D113108
2021-11-04 13:48:18 +00:00
Guillaume Chatelet 4f3511e28f [libc][NFC] Allow memcmp to be inlined
Similar to D113097 although not strictly necessary for now. It helps
keeping the same structure for all memory functions.

Differential Revision: https://reviews.llvm.org/D113103
2021-11-04 13:47:50 +00:00
Guillaume Chatelet c2ce8f02ed [libc][NFC] Allow memcpy to be inlined
This allows shipping individual functions without also having to provide
`memcpy` at the expense of bigger functions.
Next is to use this `inlined_memcpy` in:
 - loader/linux/x86_64/start.cpp
 - src/string/memmove.cpp
 - src/string/mempcpy.cpp
 - src/string/strcpy.cpp
 - src/string/strdup.cpp
 - src/string/strndup.cpp

Differential Revision: https://reviews.llvm.org/D113097
2021-11-04 13:47:19 +00:00
Michael Jones 31d797f41e [libc][NFC] rename str_conv_utils to str_to_integer
rename str_conv_utils to str_to_integer to be more
in line with str_to_float.

Reviewed By: sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D113061
2021-11-03 15:56:28 -07:00
Guillaume Chatelet 0aea170b97 [libc] Add more robust compile time architecture detection
We may want to restrict the detected platforms to only `x86_64` and `aarch64`.
There are still custom detection in api.td but I don't think we can handle these:
 - config/linux/api.td:205
 - config/linux/api.td:199

Differential Revision: https://reviews.llvm.org/D112818
2021-11-02 11:00:33 +00:00
Michael Jones 3bbbec1ae7 [libc] add strndup
add an implementation of strndup

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D112846
2021-11-01 12:52:51 -07:00
Guillaume Chatelet fe953b15cf Revert "[libc] Add more robust compile time architecture detection"
This reverts commit a72e249986.
2021-10-29 20:25:55 +00:00
Guillaume Chatelet a72e249986 [libc] Add more robust compile time architecture detection
We may want to restrict the detected platforms to only `x86_64` and `aarch64`.
There are still custom detection in api.td but I don't think we can handle these:
 - config/linux/api.td:205
 - config/linux/api.td:199

Differential Revision: https://reviews.llvm.org/D112818
2021-10-29 20:15:12 +00:00
Guillaume Chatelet d7cc760f3b [libc][NFC] Fix typo and unused variable
Differential Revision: https://reviews.llvm.org/D112823
2021-10-29 19:42:51 +00:00
Michael Jones 62c187cb55 [libc] add fast path to string to float conversion
Add the fast path first described by Clinger [1] with additions by Gay [2].
This speeds up conversion by about 10% by handling numbers with fewer digits
more efficiently.

[1] Clinger WD. How to Read Floating Point Numbers Accurately.
SIGPLAN Not 1990 Jun;25(6):92–101. https://doi.org/10.1145/93548.93557.
[2] Gay DM, Correctly rounded binary-decimal and decimal-binary conversions;
1990. AT&T Bell Laboratories Numerical Analysis Manuscript 90-10.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D112580
2021-10-29 10:50:03 -07:00
Siva Chandra Reddy 6c3f53c7ba [libc][NFC] Move test related pieces from FPUtil to util/UnitTest.
Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D112673
2021-10-29 15:37:30 +00:00
Siva Chandra Reddy f362aea42d [libc][NFC] Move utils/CPP to src/__support/CPP.
The idea is to move all pieces related to the actual libc sources to the
"src" directory. This allows downstream users to ship and build just the
"src" directory.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D112653
2021-10-28 15:50:00 +00:00
Guillaume Chatelet 00c943a548 [libc] automemcpy 2021-10-28 11:10:15 +00:00
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