Commit Graph

145 Commits

Author SHA1 Message Date
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 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 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 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
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
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
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 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 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
Siva Chandra Reddy 881402ce62 [libc][NFC] Eliminate couple of dependencies on llvm/ADT/StringExtras.h. 2021-02-22 21:41:24 -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
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 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
Siva Chandra d90bb66dd9 [libc] Include only the relevant header files in the integration test. 2021-01-27 11:15:12 -08: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
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 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
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
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 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
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
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 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 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
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
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 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
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
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 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