Commit Graph

633 Commits

Author SHA1 Message Date
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
Guillaume Chatelet 541f107871 [libc] Simplifies multi implementations and benchmarks
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),
 - makes sure all implementations are benchmarkable (provided the host can run them).

Differential Revision: https://reviews.llvm.org/D101895
2021-05-10 08:23:30 +00:00
Guillaume Chatelet ed4f4edea2 [libc] Allow target architecture customization
This patch provides a way to specify the default target cpu optimizations to use when compiling llvm-libc.
This ensures we don't rely on current compiler's default and allows compiling and cross compiling for a particular target.

Differential Revision: https://reviews.llvm.org/D101991
2021-05-10 07:53:48 +00:00
Guillaume Chatelet 7c2ece523d [libc] Normalize LIBC_TARGET_MACHINE
Current implementation defines LIBC_TARGET_MACHINE with the use of CMAKE_SYSTEM_PROCESSOR.
Unfortunately CMAKE_SYSTEM_PROCESSOR is OS dependent and can produce different results.
An evidence of this is the various matchers used to detect whether the architecture is x86.

This patch normalizes LIBC_TARGET_MACHINE and renames it LIBC_TARGET_ARCHITECTURE.
I've added many architectures but we may want to limit ourselves to x86 and ARM.

Differential Revision: https://reviews.llvm.org/D101524
2021-05-05 15:52:42 +00:00
Raman Tenneti a72499e475 [libc] Introduce asctime, asctime_r to LLVM libc
[libc] Introduce asctime, asctime_r to LLVM libc

asctime and asctime_r share the same common code. They call asctime_internal
a static inline function.

asctime uses snprintf to return the string representation in a buffer.
It uses the following format (26 characters is the buffer size) as per
7.27.3.1 section in http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2478.pdf.
The buf parameter for asctime_r shall point to a buffer of at least 26 bytes.

snprintf(buf, 26, "%.3s %.3s%3d %.2d:%.2d:%.2d %d\n",...)

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D99686
2021-05-03 17:15:00 -07:00
Guillaume Chatelet 0e97e84a65 [libc] warns about missing linting only in full build mode
Differential Revision: https://reviews.llvm.org/D101609
2021-05-03 08:39:26 +00:00
Siva Chandra Reddy c6aa206b42 [libc] Add differential quality and perf analysis targets for sinf and cosf.
Infrastructure needed for setting up the diff binaries has been added.
 Along the way, an exhaustive test for sinf and cosf have also been added.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D101276
2021-04-26 19:39:33 +00:00
Guillaume Chatelet b5f04d81a2 [libc] Use different alignment for memcpy between ARM and x86.
Aligned copy used to be 'destination aligned' for x86 but this decision was reverted in D93457 where we noticed that it was better for ARM to be 'source aligned'.
More benchmarking confirmed that it can be up to 30% faster to align copy to destination for x86. This Patch offers both implementations and switches x86 back to destination aligned.
It also fixes alignment to 32 byte on x86.

Differential Revision: https://reviews.llvm.org/D101296
2021-04-26 19:30:00 +00:00
Guillaume Chatelet fa404ae43a [libc] Enhance ArrayRef + unittests
This patch mostly adds unittests for `ArrayRef` and `MutableArrayRef`, additionnaly:
 - We mimic the behavior of `std::vector` and disallow CV qualified type (`ArrayRef<const X>` is not allowed).
   This is to make sure that the type traits are always valid (e.g. `value_type`, `pointer`, ...).
 - In the previous implementation `ArrayRef` would define `value_type` as `const T` but this is not correct, it should be `T` for both `MutableArrayRef` and `ArrayRef`.
 - We add the `equals` method to ease testing,
 - We define the constructor taking an `Array` outside of the base implementation to ensure we match `const Array<T>&` and not `Array<const T>&` in the case of `ArrayRef`.

Differential Revision: https://reviews.llvm.org/D100732
2021-04-21 13:25:24 +00:00
Siva Chandra Reddy f76fb7d420 [libc] Add fma to the C standard spec. 2021-04-21 06:00:35 +00:00
Siva Chandra Reddy 653345155a [libc] Disable fma and fmaf for x86_64.
The version of clang installed on the buildbot workers is not able to
compile them. However, the version of gcc installed is able to compile
them fine. So, this change disables them until we can find a way to
compile them using clang on the buildbot workers.
2021-04-21 05:01:15 +00:00
Siva Chandra 95934c3a37 [libc] Add hardware implementations of fma and fmaf for x86_64 and aarch64.
The current generic implementation of the fmaf function has been moved
to the FPUtil directory. This allows one use the fma operation from
implementations of other math functions like the trignometric functions
without depending on/requiring the fma/fmaf/fmal function targets. If
this pattern ends being convenient, we will switch all generic math
implementations to this pattern.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D100811
2021-04-21 04:31:27 +00:00
Siva Chandra bbba69425c [libc][NFC] Use explicit conversion in aarch64 FEnv. 2021-04-16 22:53:12 -07:00
Siva Chandra Reddy 7db1102a10 [libc]NFC] Use explicit conversion on frexpl_test and logbl_test. 2021-04-17 05:50:00 +00:00
Siva Chandra Reddy bb8aa2ad1a [libc][NFC] Use explicit conversion in modfl_test. 2021-04-17 05:42:17 +00:00
Siva Chandra Reddy fb706e086c [libc][NFC] Make conversion from FPBits to the float point type explicit.
This will help us catch errors like the ones fixed by the commit
31ed45d9cf
2021-04-17 05:22:20 +00:00
Siva Chandra Reddy fb69b92c7b [libc][NFC] Add common template test class for sqrt, sqrtf and sqrtl. 2021-04-17 05:13:27 +00:00
Guillaume Chatelet 2bfe15810d [libc] Fix wrongly deduced type 2021-04-16 21:59:25 +00:00
Guillaume Chatelet 7e075ad0b2 [libc] Add endianness support
Add endianness detection support. This will be useful to implement `memcmp`.

Differential Revision: https://reviews.llvm.org/D100571
2021-04-16 21:35:08 +00:00
Guillaume Chatelet 7c02dc22e4 [libc] Extends the testing framework to support typed test
This patch provides `TYPED_TEST` and `TYPED_TEST_F` (similar in functionnality to gtest).
This is needed to extensively test building blocks for memory functions.

Example for `TYPED_TEST_F`:
```
template <typename T> class LlvmLibcMyTestFixture : public testing::Test {};

using Types = testing::TypeList<char, int, long>;

TYPED_TEST_F(LlvmLibcMyTestFixture, Simple, Types) {
  EXPECT_LE(sizeof(ParamType), 8UL);
}
```

Example for `TYPED_TEST`:
```
using Types = testing::TypeList<char, int, long>;

TYPED_TEST(LlvmLibcMyTest, Simple, Types) {
  EXPECT_LE(sizeof(ParamType), 8UL);
}
```

`ParamType` is displayed as fully qualified canonical type which can be difficult to read, the user can provide a more readable name by using the `REGISTER_TYPE_NAME` macro.

Differential Revision: https://reviews.llvm.org/D100631
2021-04-16 21:21:35 +00:00
Siva Chandra Reddy 80e166f81a [libc][NFC] Add template tests for a bunch of math functions.
Namely, template tests have been added for the following functions:
ceil, copysign, fabs, fmax, fmin, floor, trunc, round.
2021-04-16 17:28:17 +00:00
Guillaume Chatelet 907b52d1a7 [libc] Fix typo 2021-04-16 08:09:28 +00:00
Guillaume Chatelet f6b6568536 [libc] Add slice/take/drop methods to ArrayRef
Add various methods from llvm::ArrayRef. Refactor implementation to remove code duplication.

Differential Revision: https://reviews.llvm.org/D100569
2021-04-16 07:54:48 +00:00
Guillaume Chatelet 03375089f5 [libc] Add index operator[] to StringView 2021-04-15 15:55:37 +00:00
Siva Chandra Reddy 31ed45d9cf [libc][Obvious] Fix nextafter* implementation.
It broke when FPBits was converted to a union.
2021-04-13 11:38:24 -07:00
Siva Chandra Reddy 6666e0d7a2 [libc] Make FPBits a union.
This helps us avoid the uncomfortable reinterpret-casts. Avoiding the
reinterpret casts prevents us from tripping the sanitizers as well.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D100360
2021-04-13 09:21:35 -07:00
Nathan Chancellor 4e0045cc9b
libc: Default LIBC_INSTALL_PREFIX to ${CMAKE_INSTALL_PREFIX}
b22f448c21 added a rule to install libllvmlibc.a to
${LIBC_INSTALL_PREFIX}/${LIBC_INSTALL_LIBRARY_DIR}, which will be /lib
by default, which is disruptive to builds that stay within a user's
/home holder:

  $ ninja install
  ...
  -- Installing: /lib/libllvmlibc.a
  CMake Error at projects/libc/lib/cmake_install.cmake:54 (file):
    file INSTALL cannot copy file
   "/home/nathan/cbl/github/tc-build/build/llvm/stage1/projects/libc/lib/libllvmlibc.a"
    to "/lib/libllvmlibc.a": Permission denied.
  Call Stack (most recent call first):
    projects/libc/cmake_install.cmake:51 (include)
    projects/cmake_install.cmake:47 (include)
    cmake_install.cmake:76 (include)
  ...

Change LIBC_INSTALL_PREFIX's default value to ${CMAKE_INSTALL_PREFIX} so
that 'ninja install' does not attempt to install anything outside of the
user's requested installation location.

Differential Revision: https://reviews.llvm.org/D99636

Reviewed By: sivachandra

Signed-off-by: Nathan Chancellor <nathan@kernel.org>
2021-03-30 21:43:25 -07:00
Guillaume Chatelet 77d81c2270 [libc] Fix msan/asan memcpy reentrancy
This is needed to prevent asan/msan instrumentation to redirect CopyBlock to `__asan_memcpy` (resp. `__msan_memcpy`).
These functions would then differ operation to `memcpy` which leads to reentrancy issues.

With this patch, `memcpy` is fully instrumented and covered by asan/msan.

If this turns out to be too expensive, instrumentation can be selectively or fully disabled through the use of the `__attribute__((no_sanitize(address, memory)))` annotation.

Differential Revision: https://reviews.llvm.org/D99598
2021-03-30 15:28:47 +00:00
Raman Tenneti 8b35159ac7 [libc] Introduces gmtime_r to LLVM libc, based on C99/C2X/Single Unix Sp.
gmtime and gmtime_r share the same common code. They call gmtime_internal
a static inline function. Thus added only validation tests for gmtime_r.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D99046
2021-03-22 14:04:05 -07:00
Siva Chandra 1e01f2f410 [libc][NFC] Add an alias named "check-llvmlibc" for "check-libc". 2021-03-22 16:55:34 +00:00
Siva Chandra b22f448c21 [libc] Add a target "install-llvmlibc" to install LLVM libc static archive. 2021-03-22 04:45:14 +00:00
Siva Chandra 3d155157bf [libc] Use add_library in add_entrypoint_library instead of invoking ar. 2021-03-20 04:25:51 +00:00
Raman Tenneti eaae52c1fd This introduces gmtime to LLVM libc, based on C99/C2X/Single Unix Spec.
This change doesn't handle TIMEZONE, tm_isdst and leap seconds.

Moved shared code between mktime and gmtime into time_utils.cpp.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D98467
2021-03-16 16:44:48 -07:00
Siva Chandra Reddy 7c0179129f [libc][Obvious] Fix except flags reading overflow detected by asan. 2021-03-13 16:30:33 -08:00
Siva Chandra Reddy 7b5ab956b1 [libc][Obvious] Add string tests to non-full-build mode. 2021-03-12 14:01:18 -08:00
Siva Chandra 954a7289d2 [libc] Adjust full build entrypoints for aarch64. 2021-03-12 13:50:56 -08:00
Siva Chandra Reddy e9e788d145 [libc] Introduce a full build mode CMake option.
This option will build LLVM libc as a full libc by itself. In this mode,
it is not expected that it will be mixed with other libcs. The
non-full-build mode will be the default LLVM libc build mode. In a future
where LLVM libc is complete enough, the full libc build will be made the
default mode.
2021-03-12 13:28:40 -08:00
Siva Chandra Reddy b937908c37 [libc][NFC] Move the template implementation of integer_abs to __support.
This eliminates cross-header dependency from stdlib to string.
2021-03-11 20:20:18 -08:00
Leonard Chan baf637dcde Rename top-level LICENSE.txt files to LICENSE.TXT
This makes all the license filenames uniform across subprojects.

Differential Revision: https://reviews.llvm.org/D98380
2021-03-10 21:26:24 -08:00
Siva Chandra Reddy 3f3f88fb95 [libc][Obvious] Add a file which was missed in 001a12ed59. 2021-03-08 15:39:29 -08:00
Siva Chandra Reddy 001a12ed59 [libc][NFC] Make x86_64 fenv functions msan safe.
These functions used inline asm to read FPU state. This change adds
explicit unpoisoning in these functions as the sanitizers don't see the
read operations.
2021-03-08 15:20:08 -08:00
Siva Chandra Reddy 9550f8ba9a [libc][NFC] Make few fenv functions work with fexcept_t from other libcs. 2021-03-04 11:25:28 -08:00
Siva Chandra Reddy 35e2e448ce [libc] Remove redundant header files included from internal paths. 2021-03-03 21:29:46 -08:00
Siva Chandra Reddy 6628387c9a [libc][NFC] Exclude few targets from the `all` target. 2021-02-24 08:59:55 -08:00
Siva Chandra Reddy 5f0800cc18 [libc][NFC] Remove headergen for the cacheline size macro.
We want to be able to build and test the string functions in contexts
like that of Fuchsia where LLVM pieces like tablegen are not available.
Since header generation uses tablegen, we are removing the dependency on
headergen here.

Reviewed By: gchatelet

Differential Revision: https://reviews.llvm.org/D97363
2021-02-24 07:29:09 -08:00
Siva Chandra Reddy 8d4ac5337f [libc][NFC] Merge llvmlibc and llvmlibm targets in to a single target.
The single target is called llvmlibc. We can add back smaller libm and
other targets in future if required.
2021-02-23 21:29:06 -08:00
Siva Chandra Reddy dbb131d53a [libc] Add a standalone flavor of an equivalent of std::string_view.
This class is to serve as a replacement for llvm::StringRef as part of
the plans to limit dependency on other parts of LLVM. One use of
llvm::StringRef in MPFRWrapper has been replaced with the new class.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D97330
2021-02-23 15:40:26 -08:00
Tue Ly b79507a4ac [libc] Add exhaustive test for sqrtf.
Differential Revision: https://reviews.llvm.org/D96985
2021-02-23 18:39:33 -05:00
Siva Chandra Reddy 881402ce62 [libc][NFC] Eliminate couple of dependencies on llvm/ADT/StringExtras.h. 2021-02-22 21:41:24 -08:00
Raman Tenneti 80bea4a0d5 [libc] [Obvious] Fix. 2021-02-22 19:15:35 -08:00
Raman Tenneti 034f562925 Changes to mktime to handle invalid dates, overflow and underflow andcalculating the correct date and thenumber of seconds even if invalid datesare passed as arguments.
Added tests for invalid dates like the following
  Date 1970-01-01 00:00:-1 is treated as 1969-12-31 23:59:59 and seconds
  are returned for the modified date.

Tested the code by doing ninja check-libc (and cmake).

Reviewed By: sivachandra, rtenneti

Differential Revision: https://reviews.llvm.org/D96684
2021-02-22 18:37:40 -08:00
Siva Chandra Reddy b7e05c874b [libc] Add implementations of the remaining fenv functions.
Namely, implementations of fegetexceptfflag, fesetexceptflag,
fegetenv, fesetenv, feholdexcept and feupdateenv have been added.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D96935
2021-02-18 13:29:40 -08:00
Siva Chandra Reddy dba14814a6 [libc][NFC] Make few maths functions buildable outside of LLVM libc build.
Few math functions manipulate errno. They assumed that LLVM libc's errno
is available. However, that might not be the case when these functions
are used in a libc which does not use LLVM libc's errno. This change
switches such uses of LLVM libc's errno to the normal public errno macro.
This does not affect LLVM libc's build because the include order ensures
we get LLVM libc's errno. Also, the header check rule ensures we are only
including LLVM libc's errno.h.
2021-02-16 09:14:29 -08:00
Guillaume Chatelet 74916008a8 Fix errors in distributions 2021-02-11 21:53:50 +00:00
Siva Chandra 53fcf6bb62 [libc][aarch64] Enable a bunch of math functions.
Namely, these are the functions enabled: rint*, lrint*, llrint*, lround*,
llround*, nearbyint*. They were previously not enabled because they
required rounding mode and FP exception support. Now that rounding mode
and FP exception support is available for Aarch64, they can be enabled.
2021-02-05 15:11:17 -08:00
Siva Chandra c90c8d38d3 [libc] Add aarch64 flavors of floor, round, sqrt and trunc.
Only single and double precision flavors have been added.

Reviewed By: lntue, sdesmalen

Differential Revision: https://reviews.llvm.org/D95999
2021-02-05 10:41:32 -08:00
Siva Chandra bbb7555403 [libc][NFC] Move generic math implementations to the generic directory.
This expands the pattern suggest in https://reviews.llvm.org/D95850 to all
math functions.
2021-02-03 10:46:00 -08:00
Andre Vieira 369f7de313 [LIBC] Add optimized memcpy routine for AArch64
This patch adds an optimized memcpy routine for AArch64 tuned and benchmarked
on Neoverse-N1.

Differential Revision: https://reviews.llvm.org/D92235
2021-02-03 09:30:55 +00:00
Siva Chandra 2668714747 [libc] Add hardware implementations of ceil and ceilf for aarch64.
This change also introduces a new source layout for adding machine
specific and generic implementations. To keep the scope of this change
small, this new pattern is only applied for ceil, ceilf and ceill.
Follow up changes will switch all math functions in to the new pattern.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D95850
2021-02-02 15:36:19 -08:00
Michael Jones c73c23f2a9 [libc][NFC] Add a death test API adaptation macro
Fuchsia's zxtest has a slightly different death test definition, and
this macro makes our death test API work on Fuchsia.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D95648
2021-02-01 19:19:04 +00:00
Michael Jones cb2e2d5068 [libc] Small adjustments to fenv tests
Some libcs define non-standard FE_* macros and include them in
FE_ALL_EXCEPT. This change adjusts the fenv tests so that the
non-standard FE_* macros do not interfere when compiled with
fenv.h from another libc.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D95650
2021-02-01 18:40:32 +00:00
Cheng Wang 1c762a81d2 [libc][Obvious] Fix typo 2021-01-29 17:43:41 +08:00
Cheng Wang 83bd242202 [libc][Obvious] Remove DEPS for unistd.h in CMake file of memmove. 2021-01-29 17:05:24 +08:00
Michael Jones d4eea5cf0f [libc][NFC] Add a few casts to suppress loss of precision warnings
Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D95646
2021-01-29 01:16:03 +00:00
Petr Hosek 1daaa6432e [CMake][libc] Support cross-compiling libc-hdrgen
This is useful when cross-compiling libc to another target in which
case we first need to compile libc-hdrgen for host. We rely on the
existing LLVM CMake infrastructure for that.

Differential Revision: https://reviews.llvm.org/D95205
2021-01-28 13:13:06 -08:00
Petr Hosek c4819eec1a [CMake][libc] Don't do CPU feature detection when cross-compiling
We won't be able to run the compiled program since it will be compiled
for different system. We instead allow passing the CPU features via
CMake option in that case.

Differential Revision: https://reviews.llvm.org/D95203
2021-01-28 12:54:37 -08:00
Siva Chandra ec5a782c10 [libc] Fix list of public headers usable on aarch64. 2021-01-27 12:43:18 -08:00
Siva Chandra e958d49157 [libc] Fix the CMake var name of the list of public headers. 2021-01-27 12:13:35 -08:00
Siva Chandra d90bb66dd9 [libc] Include only the relevant header files in the integration test. 2021-01-27 11:15:12 -08:00
Siva Chandra 74c87a363f [libc] Disable sqrtl_test on non-x86 platforms.
The added comment explains why it has been disabled for now. We will
enable back when we fix the problem.
2021-01-27 10:30:54 -08:00
Siva Chandra Reddy 7cd420649f [libc][NFC] Use a end of list marker for cpu feature detection.
Without this, the array can end up being an empty array leading to
compiler failures.
2021-01-27 01:24:15 -08:00
Petr Hosek b014335263 [libc] Distinguish compiler and run failures
This is useful for debugging issues, for example when cross-compiling.

Differential Revision: https://reviews.llvm.org/D95118
2021-01-21 15:27:34 -08:00
Michael Jones 689de5841c [libc][NFC][obvious] fix the names of MPFR tests
I missed the MPFR tests in my previous commit. They have now been fixed
to not fail the prefix check in the test macro.
2021-01-20 23:42:01 +00:00
Michael Jones 1df0dbfcb5 [libc][NFC] add "LlvmLibc" as a prefix to all test names
Summary:
Having a consistent prefix makes selecting all of the llvm libc tests
easier on any platform that is also using the gtest framework.
This also modifies the TEST and TEST_F macros to enforce this change
moving forward.

Reviewers: sivachandra

Subscribers:
2021-01-20 23:15:36 +00:00
Siva Chandra 7bd3702b64 [libc] Extend the current fenv functions to aarch64.
This change does not try to move the common parts of x86 and aarch64 and
build few abstractions over them. While this is possible, x86 story
needs a bit of cleanup, especially around manipulation of the mxcsr
register. Moreover, on x86 one can raise exceptions without performing
exception raising operations. So, all of this can be done in follow up
patches.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D94947
2021-01-19 12:47:54 -08:00
Guillaume Chatelet e517dff50a [libc][NFC] remove dependency on non standard ssize_t
`ssize_t` is from POSIX and is not standard unfortunately.
Rewritting the code so it doesn't depend on it.

Differential Revision: https://reviews.llvm.org/D94760
2021-01-19 08:12:38 +00:00
Guillaume Chatelet d4bb3ef532 [libc][NFC] Remove dead code 2021-01-19 08:11:45 +00:00
Siva Chandra ffb254978c [libc][NFC][Obvious] Add a missing dep. 2021-01-18 22:04:20 -08:00
Siva Chandra Reddy bfbbb62b22 [libc][NFC] Use ASSERT_EQ instead of EXPECT_EQ in fenv/exception_status_test 2021-01-18 21:38:11 -08:00
Guillaume Chatelet 5bf47e142b [libc] CopyAlignedBlocks can now specify alignment on top of block size
This has been requested in D92236

Differential Revision: https://reviews.llvm.org/D94770
2021-01-15 15:32:02 +00:00
Guillaume Chatelet a10300a2b2 [libc] Allow customization of memcpy via flags.
- Adds LLVM_LIBC_IS_DEFINED macro to libc/src/__support/common.h
 - Adds a few knobs to memcpy to help with experimentations:
   - LLVM_LIBC_MEMCPY_X86_USE_ONLY_REPMOVSB replaces the implementation with a single call to rep;movsb
   - LLVM_LIBC_MEMCPY_X86_USE_REPMOVSB_FROM_SIZE customizes where the usage of rep;movsb

Differential Revision: https://reviews.llvm.org/D94692
2021-01-15 09:26:45 +00:00
Cheng Wang 2423ec5837 [libc] Add memmove implementation.
Use `memcpy` rather than copying bytes one by one, for there might be large
size structs to move.

Reviewed By: gchatelet, sivachandra

Differential Revision: https://reviews.llvm.org/D93195
2021-01-15 12:08:25 +08:00
Roland McGrath e7228062b2 [libc] Use #undef isascii in specific header
Standard C allows all standard headers to declare macros for all
their functions.  So after possibly including any standard header
like <ctype.h>, it's perfectly normal for any and all of the
functions it declares to be defined as macros.  Standard C requires
explicit `#undef` before using that identifier in a way that is not
compatible with function-like macro definitions.

The C standard's rules for this are extended to POSIX as well for
the interfaces it defines, and it's the expected norm for
nonstandard extensions declared by standard C library headers too.

So far the only place this has come up for llvm-libc's code is with
the isascii function in Fuchsia's libc.  But other cases can arise
for any standard (or common extension) function names that source
code in llvm-libc is using in nonstandard ways, i.e. as C++
identifiers.

The only correct and robust way to handle the possible inclusion of
standard C library headers when building llvm-libc source code is to
use `#undef` explicitly for each identifier before using it.  The
easy and obvious place to do that is in the per-function header.
This requires that all code, such as test code, that might include
any standard C library headers, e.g. via utils/UnitTest/Test.h, make
sure to include those *first* before the per-function header.

This change does that for isascii and its test.  But it should be
done uniformly for all the code and documented as a consistent
convention so new implementation files are sure to get this right.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D94642
2021-01-14 13:25:05 -08:00
Michael Jones ea8034ec35 [libc][NFC] change isblank and iscntrl from implicit casting
isblank and iscntrl were casting an int to a char implicitly and this
was throwing errors under Fuchsia. I've added a static cast to resolve
this issue.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D94634
2021-01-13 22:06:56 +00:00
Michael Jones 4cfccd5133 [libc][NFC] add macro for fuchsia to switch test backend to zxtest
This moves utils/UnitTest/Test.[h/cpp] to LibcTest.[h/cpp] and adds a
new Test.h that acts as a switcher so that Fuchsia can use the zxtest
backend for running our tests as part of their build.

FuchsiaTest.h is for including fuchsia's zxtest library and anything
else needed to make the tests work under fuchsia (currently just
undefining the isascii macro for the test).

Downstream users, please fix your build instead of reverting.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D94625
2021-01-13 21:28:02 +00:00
Guillaume Chatelet ab57780716 [libc] Refresh benchmark progress bar when needed. 2021-01-13 14:06:51 +00:00
Siva Chandra Reddy 0c8466c001 [libc][NFC] Use more specific comparison macros in LdExpTest.h. 2021-01-12 16:13:10 -08:00
Michael Jones 04edcc0263 [libc] add isascii and toascii implementations
adding both at once since these are trivial functions.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D94558
2021-01-12 23:41:20 +00:00
Siva Chandra Reddy aefeb5f136 [libc][NFC] Make __support/common.h an in tree header.
It was previously a generated header. It can easily converted to a
generated header if required in future.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D94445
2021-01-11 13:10:56 -08:00
Michael Jones b02ca0969e [libc][NFC] add includes for internal headers to all libc functions
this will make sure that all of the functions are using the correct
prototypes. Explained much better in the comments of this diff:
https://reviews.llvm.org/D94195
2021-01-09 00:39:18 +00:00
Michael Jones a0b65a7bcd [libc] Switch to use a macro which does not insert a section for every libc function.
Summary:
The new macro also inserts the C alias for the C++ implementations
without needing an objcopy based post processing step. The CMake
rules have been updated to reflect this. More CMake cleanup can be
taken up in future rounds and appropriate TODOs have been added for them.

Reviewers: mcgrathr, sivachandra

Subscribers:
2021-01-08 23:52:35 +00:00
Siva Chandra Reddy f9e858f5fd [libc] Use a wrapper for rand instead of calling std::rand in fma tests.
Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D94198
2021-01-06 15:07:44 -08:00
Tue Ly 4726bec8f2 [libc] Add implementation of fmaf.
Differential Revision: https://reviews.llvm.org/D94018
2021-01-06 17:14:20 -05:00
Guillaume Chatelet aa9db51ef6 [libc] Align src buffer instead of dst buffer
We used to align destination buffer instead of source buffer for the loop of block copy.
This is a mistake.

Differential Revision: https://reviews.llvm.org/D93457
2021-01-06 12:04:53 +00:00
Guillaume Chatelet 223a6f94c5 [libc] remove modulo from CircularArrayRef iterator 2021-01-06 12:03:52 +00:00
Siva Chandra Reddy 7f7b0dc4e1 [libc] Add implementations of nextafter[f|l] functions.
A differential fuzzer for these functions has also been added.
Along the way, a small correction has been done to the normal/subnormal
limits of x86 long double values.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D94109
2021-01-05 22:32:39 -08:00
Siva Chandra Reddy 993d8ac5cb [libc] Add implementations of nearbyint[f|l].
The implementation is exactly the same as rint* as even rint does not
raise any floating point exceptions currently. [Note that the standards
do not specify that floating point exceptions must be raised - they
leave it up to the implementation to choose to raise FE_INEXACT when
rounding non-integral values.]

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D94112
2021-01-05 21:51:10 -08:00
Siva Chandra Reddy cc07d52511 [libc][NFC] Use ASSERT_FP_EQ to compare nan values in tests.
This change "fixes" one of the uses that was missed in
0524da67b4.
2020-12-30 13:06:40 -08:00
Siva Chandra Reddy ff6fd38552 [libc] Add implementations of rounding functions which depend rounding mode.
Namely, implementations for rint, rintf, rintl, lrint, lrintf, lrintl,
llrint, llrintf and llrintl have been added.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D93889
2020-12-29 22:22:02 -08:00
Siva Chandra Reddy 2d9ae1d217 [libc][NFC] Use `#include <math.h>` in utils/FPUtil/ManipulationFunctions.h.
This reverts commit 352cba2441.
"add back math.h #include utils/FPUtil/ManipulationFunctions.h".

Using `<math.h>` correct so downstream setup should be fixed.
2020-12-18 00:05:02 -08:00
Siva Chandra Reddy d599ed49b3 [libc][NFC] Use ASSERT_FP_EQ to comapre NaN values in tests.
This is a continuation of the previous CL which did a similar change in
other tests. To elaborate a little about why we need this - under C++
compilation with headers not from LLVM libc, libraries like libc++ and
libstdc++ provide their own math.h which undefine macros like `isnan`
and provide the overloaded C++ isnan functions which return a boolean
value instead of an integer value returned by the isnan macro.
2020-12-17 23:16:26 -08:00
Siva Chandra Reddy e1a5b234ef [libc][Obvious] Fix typo is wrappergen unittest. 2020-12-17 09:13:23 -08:00
Paula Toth 17b3ff511c [libc] Add python3 to libc buildbot depedencies.
Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D93463
2020-12-17 08:59:13 -08:00
Siva Chandra Reddy bf03eba1f9 [libc] Refactor WrapperGen to make the flow cleaner.
Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D93417
2020-12-17 08:56:45 -08:00
Guillaume Chatelet cfe096d1f6
Fix dead link 2020-12-17 15:49:28 +01:00
Guillaume Chatelet deae7e982a [libc] revamp memory function benchmark
The benchmarking infrastructure can now run in two modes:
 - Sweep Mode: which generates a ramp of size values (same as before),
 - Distribution Mode: allows the user to select a distribution for the size paramater that is representative from production.

The analysis tool has also been updated to handle both modes.

Differential Revision: https://reviews.llvm.org/D93210
2020-12-17 13:23:33 +00:00
Krasimir Georgiev 352cba2441 [libc] add back math.h #include utils/FPUtil/ManipulationFunctions.h
This partially reverts cee1e7d14f4628d6174b33640d502bff3b54ae45:
  [libc][NFC][Obvious] Remove few unnecessary #include directives in tests.

That commit causes a test failure in our configuration:
[ RUN      ] ILogbTest.SpecialNumbers_ilogb
third_party/llvm/llvm-project/libc/test/src/math/ILogbTest.h:28: FAILURE
      Expected: FP_ILOGBNAN
      Which is: 2147483647
To be equal to: func(__llvm_libc::fputil::FPBits<T>::buildNaN(1))
      Which is: -2147483648
2020-12-17 11:16:08 +01:00
Siva Chandra Reddy 0524da67b4 [libc][NFC] Use ASSERT_FP_EQ to comapre NaN values in tests. 2020-12-15 23:48:54 -08:00
Siva Chandra Reddy f66cf13d5d [libc][NFC] Rename global `nan` in tests to `aNaN`.
The name `nan` conflicts with the function `nan` defined declared in
math.h.
2020-12-15 22:37:02 -08:00
Siva Chandra Reddy cee1e7d14f [libc][NFC][Obvious] Remove few unnecessary #include directives in tests. 2020-12-15 21:41:44 -08:00
Siva Chandra f0cd6aa614 [libc] Add remainder[f|l] and remquo[f|l] to the list of aarch64 entrypoints. 2020-12-14 18:06:05 -08:00
Siva Chandra b1067a9b3c [libc][NFC] Skip adding dummy targets for skipped unit tests. 2020-12-14 17:52:47 -08:00
Cheng Wang af68c3b892 [libc] Add memcmp implementation.
Reviewed By: gchatelet

Differential Revision: https://reviews.llvm.org/D93009
2020-12-15 09:47:29 +08:00
Siva Chandra Reddy b266c818e7 [libc][Obvious] Mark functions in DummyFEnv.h as static inline. 2020-12-14 17:12:54 -08:00
Siva Chandra Reddy 9ad2091e78 [libc][Obvious] Include <fenv.h> from DummyFenv.h. 2020-12-14 08:51:54 -08:00
Siva Chandra Reddy 9ab6c1a99f [libc] Let wrappergen pick LLVM libc mangled name from aliasee file.
Along the way, made a change to run tool unittests when the target
"check-libc" is run by introducing a libc testsuite for tool unittests.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D93142
2020-12-11 14:33:03 -08:00
Siva Chandra Reddy 7aeb3804c4 [libc] Add implementations of lround[f|l] and llround[f|l].
A new function to MPFRWrapper has been added, which is used to set up
the unit tests.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D93007
2020-12-11 11:12:40 -08:00
Cheng Wang 1fd32dcb29 [libc] Add [l|ll]abs implementation.
Implement abs, labs and llabs with template.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D92626
2020-12-11 09:25:20 +08:00
Siva Chandra Reddy ab3cbe4bc0 [libc] Raise x87 exceptions by synchronizing with "fwait".
Couple of helper functions enableExcept and disableExcept have been
added. In a later round, they will be used to implemented the GNU
extension functions feenableexcept and fedisableexcept.

Differential Revision: https://reviews.llvm.org/D92821
2020-12-08 13:16:19 -08:00
Michael Jones e60f2cbd0c [libc] add tests to WrapperGen
This adds an initial test that can serve as a basis for other tests on
wrappergen.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D92137
2020-12-04 18:14:17 +00:00
Siva Chandra Reddy 3a375125b0 [libc][NFC] Remove dependence on xmmintrin.h to read/write MXCSR.
The version of clang on the bots is unhappy with using xmmintrin.h.
So, this change removes dependence on xmmintrin by using inline
assembly.
2020-12-03 13:49:17 -08:00
Siva Chandra Reddy 4fff2a7e89 [libc] Add simple x86_64 floating point exception and rounding mode support.
Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D92546
2020-12-03 12:55:12 -08:00
Tue Ly 3b487d51e2 [libc] Add implementation of hypot.
Refactor src/math/hypotf.cpp and test/src/math/hypotf_test.cpp and reuse them for hypot and hypot_test

Differential Revision: https://reviews.llvm.org/D91831
2020-12-03 11:08:20 -05:00
Siva Chandra Reddy 19c3894f94 [libc] Fix couple of corner cases in remquo.
These two cases are fixed:
1. If numerator is not zero and denominator is infinity, then the
numerator is returned as the remainder.
2. If numerator and denominator are equal in magnitude, then quotient
with the right sign is returned.

The differet tests of remquo, remquof and remquol have been unified
into a single file to avoid duplication.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D92353
2020-12-02 11:48:49 -08:00
Cheng Wang 60cef89362 [libc] Add strncpy implementation.
Add libc strncpy implementation.

Reviewed By: sivachandra, gchatelet

Differential Revision: https://reviews.llvm.org/D91399
2020-12-02 20:45:51 +08:00
Raman Tenneti 6f0f844e9a Initial commit of mktime.
This introduces mktime to LLVM libc, based on C99/C2X/Single Unix Spec.

Co-authored-by: Jeff Bailey <jeffbailey@google.com>

This change doesn't handle TIMEZONE,  tm_isdst and leap seconds.  It returns -1 for invalid dates. I have verified the return results for all the possible dates with glibc's mktime.

TODO:
+ Handle leap seconds.
+ Handle out of range time and date values that don't overflow or underflow.
+ Implement the following suggestion Siva - As we start accumulating the seconds, we should be able to check if the next amount of seconds to be added can lead to an overflow. If it does, return the overflow value.  If not keep accumulating. The benefit is that, we don't have to validate every input, and also do not need the special cases for sizeof(time_t) == 4.
+ Handle timezone and update of tm_isdst

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D91551
2020-11-30 21:07:16 -08:00
Guillaume Chatelet 699d17d4d6 [libc] Improve memcpy copy loop
Rewriting loop so the terminating condition does not depend on the loop body

Differential Revision: https://reviews.llvm.org/D91976
2020-11-30 08:24:10 +00:00
Cheng Wang a8beb4ada4 [libc] Fix typo in buildbot README.txt.
Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D90381
2020-11-27 19:01:21 +08:00
Cheng Wang a513be4900 [libc][Obvious] Fix typo in strnlen_test.cpp. 2020-11-27 15:56:19 +08:00
Guillaume Chatelet d899f9970e Fix case mismatch between definition and declaration 2020-11-25 14:23:31 +00:00
Michael Jones 8a4ee3550b [libc] Make more of the libc unit testing llvm independent
(WIP, hopefully I'll add more to this patch before submitting)

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D91665
2020-11-21 00:27:08 +00:00
Michael Jones 3e18fb3390 [libc] Switch functions to using global headers
This switches all of the files in src/string, src/math, and
test/src/math from using relative paths (e.g. `#include “include/string.h”`)
to global paths (e.g. `#include <string.h>`) to make bringing up those
functions on other platforms, such as fuchsia, easier.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D91394
2020-11-21 00:07:17 +00:00
Siva Chandra Reddy 4766a86cf2 [libc] Combine all math differential fuzzers into one target.
Also added diffing of a few more math functions. Combining the diff check
for all of these functions helps us meet the OSS fuzz bar of a minimum of
100 program edges.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D91817
2020-11-20 07:46:15 -08:00
Siva Chandra Reddy 892ed1f150 [libc] Add differential fuzzers for ldexp and remquo.
Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D91763
2020-11-19 08:32:05 -08:00
Siva Chandra Reddy 4d8dede5e5 [libc] Fix the overflow check condition of ldexp.
Targeted tests have been added.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D91752
2020-11-18 21:35:48 -08:00
Siva Chandra Reddy d1b921e3bf [libc][NFC][Obvious] Remove few unnecessary pieces from ilogb tests. 2020-11-18 11:26:05 -08:00
Siva Chandra Reddy ad0e764ead [libc][obvious] Fix fdim[f|l] signatures in stdc spec. 2020-11-18 07:39:11 -08:00
Siva Chandra Reddy bb8f2585c6 [libc] Add implementations of ldexp[f|l].
The rounding behavior of NormalFloat to float format has been changed
to round to nearest. Also, a bug in NormalFloat to subnormal number
conversion has been fixed.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D91591
2020-11-17 15:05:42 -08:00
Michael Jones a200d6cdf0 [libc] make part of libc's unit test framework independent of llvm
This is mostly changing stringref to std::string, outs() to cout,
and small supporting changes. This will make running unit tests possible
on systems that are only grabbing the libc part of llvm.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D91568
2020-11-17 18:43:15 +00:00
Tue Ly d41280467d [libc] Add implementations of fdim[f|l].
Implementing fdim, fdimf, and fdiml for llvm-libc.

Differential Revision: https://reviews.llvm.org/D90906
2020-11-10 18:48:11 -05:00
Siva Chandra Reddy d50149b42e [libc] Extend WrapperGen to emit aliases.
Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D90985
2020-11-06 16:12:10 -08:00
Siva Chandra Reddy 573ade4bef [libc][WrapperGen] Replace the C _Noreturn annotation with C++ [[noreturn]].
Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D90900
2020-11-06 11:37:48 -08:00
Siva Chandra Reddy 930cf1cb9f [libc] Add implementations of ilogb[f|l].
Depends on D90805.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D90806
2020-11-05 16:27:44 -08:00
Siva Chandra Reddy 0e3532da98 [libc][NFC] Make test macros callable from helper methods of test classes.
This is acheived by making the RunContext a state variable of the test
classes.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D90805
2020-11-05 16:14:24 -08:00
Michael Jones 5c801de13c [libc] Fix WrapperGen seeing no arguments as a void argument.
This corrects WrapperGen generating incorrect wrappers for functions
that take no arguments. Previously it would generate a wrapper with a
single argument of type `void`.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D90800
2020-11-05 19:13:37 +00:00
Siva Chandra Reddy 50c2f2b6f0 [libc][NFC][Obvious] Use the new macro to declare special constants in tests. 2020-11-03 15:44:06 -08:00
Michael Jones 5080840d28 [LIBC][NFC] Rename errno and assert files to match other files with functions
Rename the files containing the `__errno_location` function
to `__errno_location.h/cpp` to match the other files and move
the `llvmlibc_errno` macro to its own file.

Split assert.h into `__assert_fail.h` (contains the function prototype)
and assert.h (contains the assert macro).

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D90653
2020-11-03 21:29:32 +00:00
Siva Chandra Reddy e4be4bcf83 [libc][NFC] Use a convenience macro to declare special floating point constants.
Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D90262
2020-10-27 16:55:16 -07:00
Michael Jones ba24ba7e9c [libc] Add LLVM libc specific functions to llvm_libc_ext.td.
Also moved most of the common type definitions from libc/spec/stdc.td
to libc/spec/spec.td so that they can be used to list functions in llvm_libc_ext.td.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D89436
2020-10-19 18:21:25 +00:00
Michael Jones f6bf2823c4 [libc] Use entrypoints.txt as the single source of list of functions for a platform.
The function listings in api.td are removed. The same lists are now deduced using the information
in entrypoints.txt.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D89267
2020-10-15 20:46:13 +00:00
Guillaume Chatelet c400e01c62 [libc][NFC] Add probability distributions for memory function sizes
This patch adds memory function size distributions sampled from different applications running in production.
This will be used to benchmark and compare memory functions implementations.

Differential Revision: https://reviews.llvm.org/D89401
2020-10-15 08:15:58 +00:00
Guillaume Chatelet cba533febc Fix conjuntion of -Werror,-Wsuggest-override with google/benchmark 2020-10-14 15:26:55 +00:00
Paula Toth f60686f35c [libc] Update buildbot worker version to 2.8.4.
Tested locally by connecting to LLVM master. (:
http://lab.llvm.org:8011/#/builders/78/builds/1

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D89069
2020-10-08 13:43:53 -07:00
Anthony Steinhauser ef36e8380a [libc] Using llvm_libc memcpy in mem* benchmarks.
Currently the mem* benchmarks use memcpy from Glibc and memset from LLVM libc.
That's misleading and produces inconsistent results and behaviors.

This change makes Memcpy.cpp consistent with Memset.cpp:
https://github.com/llvm/llvm-project/blob/master/libc/benchmarks/Memset.cpp#L49

Reviewers: sivachandra

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D88271
2020-09-24 22:03:52 -07:00
Tue Ly f55963d501 [libc] Add implementation for hypotf
Truncating the sum of squares, and then use shift-and-add algorithm to compute its square root.
Required MPFR testing infra is updated in https://reviews.llvm.org/D87514

Differential Revision: https://reviews.llvm.org/D87516
2020-09-17 23:28:36 -04:00
Guillaume Chatelet c3fd2a50ba [libc] Remove special case for 8 and 16 bytes
They don't seem to gain much in real apps and its better to favor less branches and smaller code.
2020-09-15 20:48:27 +00:00
Guillaume Chatelet c19fda9aa0 [libc] use stddef instead of string header 2020-09-15 20:12:55 +00:00
Guillaume Chatelet 00ba1a3de7 [libc] remove useless headers 2020-09-15 20:04:12 +00:00
Guillaume Chatelet e328456a9e [libc] Add missing TableGen dependency
Differential Revision: https://reviews.llvm.org/D87689
2020-09-15 14:26:04 +00:00
Guillaume Chatelet 00d6e7116c [libc] Add missing LibcFPTestHelpers library
Differential Revision: https://reviews.llvm.org/D87690
2020-09-15 14:25:34 +00:00
Guillaume Chatelet 85763e0758 [libc] Fix typo in platform_defs.h.inc
Differential Revision: https://reviews.llvm.org/D87687
2020-09-15 14:25:01 +00:00
Tue Ly abf1c82dcc [libc] Extend MPFRMatcher to handle 2-input-1-output and support hypot function.
Differential Revision: https://reviews.llvm.org/D87514
2020-09-14 14:53:46 -04:00
cgyurgyik c92d1aa44b [libc] Decouple string functions.
This revision removes dependencies that exist between different string functions. This allows for the libc user to use a specific function X of this library without also depending on Y and Z.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D87421
2020-09-14 12:22:05 -04:00
Siva Chandra Reddy cb19e8c6d1 [libc][obvious] Include Sqrt.h in SqrtLongDoubleX86.h.
This makes SqrtLongDoubleX86.h includable by itself.
2020-09-10 13:25:54 -07:00
Siva Chandra Reddy 878cb5170d [libc][NFC][obvious] Remove a redudant dep of strcmp implementation. 2020-09-10 12:34:32 -07:00
Siva Chandra Reddy fb542b0b8c [libc][MPFRWrapper] Provide a way to include MPFR header in downstream repos.
Reviewed By: asteinhauser

Differential Revision: https://reviews.llvm.org/D87412
2020-09-09 12:58:58 -07:00
Siva Chandra Reddy ba5b1371ec [libc][NFC] Add spec files as dependencies of integration test. 2020-09-09 10:22:27 -07:00
Siva Chandra Reddy e59d829971 [libc][obvious] Fix strtok_r signature in the spec. 2020-09-09 09:50:17 -07:00
Siva Chandra Reddy 17ac4543d4 [libc][obvious] Use constants of type double in remquo_test. 2020-09-03 22:26:25 -07:00
Siva Chandra Reddy 8514ecb02d [libc] Add implementations of remquo[f|l] and remainder[f|l].
The implementation is not fully standards compliant in the sense that
errno is not set on error, and floating point exceptions are not raised.

Subnormal range and normal range are tested separately in the tests.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D86666
2020-09-03 22:00:17 -07:00
Pavel Labath 9cb222e749 [cmake] Make gtest include directories a part of the library interface
This applies the same fix that D84748 did for macro definitions.
Appropriate include path is now automatically set for all libraries
which link against gtest targets, which avoids the need to set
include_directories in various parts of the project.

Differential Revision: https://reviews.llvm.org/D86616
2020-08-27 15:35:57 +02:00
Tue Ly 5078825aa9 [libc] Add implementations for sqrt, sqrtf, and sqrtl.
Differential Revision: https://reviews.llvm.org/D84726
2020-08-26 09:46:18 -04:00
Siva Chandra Reddy fe44992b79 [libc][NFC] For remquo quotient, compare only 3 bits of MPFR and libc results. 2020-08-25 23:42:06 -07:00
Siva Chandra Reddy 1948acb61b [libc][obvious] Add back the accidentally removed MPFRNumber destructor. 2020-08-25 21:57:46 -07:00
Siva Chandra Reddy 3f4674a557 [libc] Extend MPFRMatcher to handle multiple-input-multiple-output functions.
Tests for frexp[f|l] now use the new capability. Not all input-output
combinations have been addressed by this change. Support for newer combinations
can be added in future as needed.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D86506
2020-08-25 21:42:49 -07:00
Siva Chandra Reddy 87bf0b0ee9 [libc] Add a class called NormalFloat which represents normalized floats.
This class helps in dealing with normal and subnormal numbers uniformly.
Moreover, since this class has been designed to handle all floating
formats across platforms, it helps implement floating point functions in
a uniform manner.

The implementations of frexp and logb have been switched to use this new
class as it allows us to use just one implementation across all
different floating point formats.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D86241
2020-08-20 09:00:35 -07:00
Siva Chandra Reddy ed8982da3e [libc][NFC] Switch math tests to the new ULP based tolerance.
Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D86267
2020-08-20 08:31:31 -07:00
Siva Chandra Reddy e2645488ca [libc][obvious] Fix x86 long double conversion to integer.
Fixes incorrectly constructed ceill tests.
2020-08-19 14:48:55 -07:00
Siva Chandra Reddy f768eb216f [libc][obvious] Fix link order of math tests. 2020-08-18 11:04:58 -07:00
Tue Ly 9887a70e7a [libc] Add ULP function to MPFRNumber class to test correctly rounded functions such as SQRT, FMA.
Add ULP function to MPFRNumber class to test correctly rounded functions.

Differential Revision: https://reviews.llvm.org/D84725
2020-08-18 13:51:58 -04:00
Anthony Steinhauser 25d759c143 [libc] Make benchmark boxplots transparent.
So that the configuration box does not make a part of the plot invisible.

Reviewers: sivachandra

Differential Revision: https://reviews.llvm.org/D85953
2020-08-17 07:34:26 -07:00
cgyurgyik 79ce64ea08 [libc] Add restrict qualifiers to string library; give consistent naming scheme to TableGen files.
Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D85945
2020-08-14 15:41:02 -04:00
Chris Gyurgyik d28f67292e
[libc] [obvious] Fix typographical error. 2020-08-14 08:34:42 -04:00
parallels bc45bab7eb [libc] Add strtok_r implementation.
Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D85779
2020-08-13 15:51:38 -04:00
Siva Chandra 578ac8bfa5 [libc][obvious] Remove the unused file utils/CPP/StringRef.h. 2020-08-12 12:19:11 -07:00
Siva Chandra a87576592c [libc][obvious] Switch copysign[f|l] and fabs[f|l] to the new test matchers. 2020-08-12 00:20:58 -07:00
Siva Chandra 01b99c6e1d [libc][obvious] Switch nearest integer function tests to the new matchers. 2020-08-11 23:33:15 -07:00
Siva Chandra df79e18796 [libc][obvious] Remove a commented out block. 2020-08-11 13:31:17 -07:00
cgyurgyik 667843cc07 [libc] Add strtok implementation.
Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D85615
2020-08-11 13:44:53 -04:00
Siva Chandra Reddy f6d74b29d6 [libc][NFC] Disable a loader test as ld.gold fails to link.
Will be reenabled after investigating and fixing the problem.
2020-08-07 23:45:18 -07:00
Siva Chandra Reddy db936e0e91 [libc][NFC] Add library of floating point test matchers.
This eliminates UnitTest's dependency on FPUtil and hence prevents
non-math tests from depending indirectly on FPUtil. The patch
essentially moves some of the existing pieces into a library of its own.

Along the way, renamed add_math_unittest to add_fp_unittest.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D85486
2020-08-07 23:34:15 -07:00
Siva Chandra Reddy 5d59385ba6 [libc] Setup TLS in x86_64 loader.
The new code added is still very x86_64 specific. AArch64 support will
be added very soon and refactoring of the loader code will be done as
part of the patches adding it.

Reviewed By: asteinhauser

Differential Revision: https://reviews.llvm.org/D82700
2020-08-07 23:19:03 -07:00
cgyurgyik dc13a9a781 [libc] Add strcpsn and strpbrk implementation.
Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D85386
2020-08-07 16:14:32 -04:00
cgyurgyik 128bf458ab [libc] Add tolower, toupper implementation.
Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D85326
2020-08-06 15:21:38 -04:00
cgyurgyik f3b4150255 [libc] Add strspn implementation and std::bitset
Reviewed By: sivachandra, abrachet

Differential Revision: https://reviews.llvm.org/D85103
2020-08-05 16:48:38 -04:00
Chris Gyurgyik 049f6ad4f6
[libc] [obvious] Add ctype functions to linux api.
Adds isspace, isprint, and isxdigit to Linux API to fix failed integration test.
2020-08-05 11:05:50 -04:00
cgyurgyik 1fdab96130 [libc] Add isspace, isprint, isxdigit implementations.
Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D85270
2020-08-05 10:51:43 -04:00
cgyurgyik 6cd50e7b75 [libc] Add implementations for isblank, iscntrl, isgraph, ispunct.
Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D85059
2020-08-04 15:16:58 -04:00
cgyurgyik 1b35c4fed2 [libc] [obvious] In strrchr, remove cast to unsigned char before
comparison.
2020-07-31 20:14:34 -04:00
cgyurgyik 5954755939 [libc] [obvious] Fix strchr and strrchr tests so that constness is
actually verified.
2020-07-31 20:00:59 -04:00
Chris Gyurgyik 7212ad067e
[libc] [obvious] Add rest of strrchr test. 2020-07-31 14:57:46 -04:00
cgyurgyik e8a2af28af [libc] Adds strrchr implementation.
Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D84875
2020-07-31 14:38:34 -04:00
cgyurgyik e2d4bf6cec [libc] Add islower and isupper implementation.
Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D84960
2020-07-31 14:05:27 -04:00
Siva Chandra Reddy a32af8252f [libc] Add a tool called WrapperGen.
This tool will be used to generate C wrappers for the C++ LLVM libc
implementations. This change does not hook this tool up to anything yet.
However, it can be useful for cases where one does not want to run the
objcopy step (to insert the C symbol in the object file) but can make use
of LTO to eliminate the cost of the additional wrapper call. This can be
relevant for certain downstream platforms. If this tool can benefit other
libc platforms in general, then it can be integrated into the build system
with options to use or not use the wrappers. An example of such a
platform is CUDA.

Reviewed By: abrachet

Differential Revision: https://reviews.llvm.org/D84848
2020-07-30 16:07:26 -07:00
cgyurgyik e263dcc3ef [libc] Implements isdigit and isalnum. Adds a utility header to inline
functions to avoid overhead of function calls.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D84893
2020-07-30 12:37:30 -04:00
cgyurgyik e14a7ff762 [libc] Adds fuzz test for strstr and alphabetizes string fuzz CMakeList.
Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D84611
2020-07-29 16:35:59 -04:00
Chris Gyurgyik 33abb7292e
[libc] [obvious] Fix typo in binary header. 2020-07-29 08:18:07 -04:00
Siva Chandra Reddy cd7a5c3cd9 [libc][obvious] Add license headers to APIIndexer.[cpp|h]. 2020-07-28 17:04:03 -07:00
Siva Chandra Reddy 462b3564f1 [libc][obvious] Add the new ctype.h target to the list of x86_64 headers.
This will fix the integration test which is failing currently.
2020-07-28 16:42:25 -07:00