Commit Graph

599 Commits

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