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.
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
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
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
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
__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
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
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
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
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
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
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
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.)
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.
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
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
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.
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
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
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
[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
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
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
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
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.
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
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
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
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>
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
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
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
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.
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.
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
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
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
Namely, implementations of fegetexceptfflag, fesetexceptflag,
fegetenv, fesetenv, feholdexcept and feupdateenv have been added.
Reviewed By: lntue
Differential Revision: https://reviews.llvm.org/D96935
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.
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.
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
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
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
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
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