Commit Graph

47 Commits

Author SHA1 Message Date
Tue Ly 700aebaf74 [libc] Set default CXX_STANDARD to C++17 and let targets set their own standard if needed.
CMAKE_CXX_STANDARD 14 is set in the llvm-project/llvm folder overriding all COMPILE_OPTIONS -std=c++17.  We need to override the CXX_STANDARD property of the target in order to set the correct C++ standard flags.

Reviewed By: gchatelet

Differential Revision: https://reviews.llvm.org/D118871
2022-02-04 09:59:21 -05:00
Tue Ly e581841e8c [libc] Implement log10f correctly rounded for all rounding modes.
Based on RLIBM implementation similar to logf and log2f.  Most of the exceptional inputs are the exact powers of 10.

Reviewed By: sivachandra, zimmermann6, santoshn, jpl169

Differential Revision: https://reviews.llvm.org/D118093
2022-01-25 10:33:39 -05:00
Tue Ly 63d2df003e [libc] Implement correctly rounded log2f based on RLIBM library.
Implement log2f based on RLIBM library correctly rounded for all rounding modes.

Reviewed By: sivachandra, michaelrj, santoshn, jpl169, zimmermann6

Differential Revision: https://reviews.llvm.org/D115828
2022-01-14 12:40:49 -05:00
Tue Ly c386d6eb2d [libc] Fix precision constants for long double in MPFRUtils.cpp. 2022-01-13 21:33:05 -05:00
Tue Ly 8cd81274ff [libc] Add multithreading support for exhaustive testing and MPFRUtils.
Add threading support for exhaustive testing and MPFRUtils.

Reviewed By: sivachandra

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

Reviewed By: sivachandra, michaelrj

Differential Revision: https://reviews.llvm.org/D116777
2022-01-13 13:28:50 -05:00
Siva Chandra Reddy 60509623c4 [libc][obvious] Fix style of MPFRWrapper. 2021-12-23 23:19:42 +00:00
Tue Ly d08a801b5f [libc] Implement correctly rounded logf based on RLIBM library.
Implement correctly rounded logf based on RLIBM library: https://people.cs.rutgers.edu/~sn349/rlibm/.

Reviewed By: sivachandra, santoshn, jpl169, zimmermann6

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

Reviewed By: sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D114302
2021-12-07 10:49:47 -08:00
Tue Ly 32568fc95e [libc] Fix a bug in MPFRUtils making ULP values off by 2^(-mantissaWidth).
Fix a bug in MPFRUtils making ULP values off by 2^(-mantissaWidth) and incorrect eps for denormal numbers.

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

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

Differential Revision: https://reviews.llvm.org/D112818
2021-10-29 20:15:12 +00:00
Siva Chandra Reddy 6c3f53c7ba [libc][NFC] Move test related pieces from FPUtil to util/UnitTest.
Reviewed By: michaelrj

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

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D112653
2021-10-28 15:50:00 +00:00
Siva Chandra Reddy ca6b354229 [libc] Add range reduction functions based on Paine and Hanek algorithm.
These functions will be used in a future patch to implement
trigonometric functions. Unit tests have been added but to the
libc-long-running-tests suite. The unit tests long running because we
compare against MPFR computations performed at 1280 bits of precision.

Some cleanups or elimination of repeated patterns can be done as follow
up changes.

Differential Revision: https://reviews.llvm.org/D104817
2021-08-23 05:18:41 +00:00
Michael Jones c120edc7b3 [libc][nfc] move ctype_utils and FPUtils to __support
Some ctype functions are called from other libc functions (e.g. isspace
is used in atoi). By moving ctype_utils.h to __support it becomes easier
to include just the implementations of these functions. For these
reasons the implementation for isspace was moved into
ctype_utils as well.

FPUtils was moved to simplify the build order, and to clarify which
files are a part of the actual libc.

Many files were modified to accomodate these changes, mostly changing
the #include paths.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D107600
2021-08-06 17:29:41 +00:00
Hedin Garca 8baa87d918 [libc] Enable MPFR library for math functions test
Included more math functions to Windows's entrypoints
and made a cmake option (-DLLVM_LIBC_MPFR_INSTALL_PATH)
where the user can specify the install path where the MPFR
library was built so it can be linked. The try_compile was
moved to LLVMLibCCheckMPFR.cmake, so the variable that is
set after this process can retain its value in other files
of the same parent file. A direct reason for this is for
LIBC_TESTS_CAN_USE_MPFR to be true when the user specifies
MPFR's path and retain its value even after leaving the file.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D106894
2021-07-27 20:40:04 +00:00
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
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
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 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
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
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
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 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 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
Guillaume Chatelet 00d6e7116c [libc] Add missing LibcFPTestHelpers library
Differential Revision: https://reviews.llvm.org/D87690
2020-09-15 14:25:34 +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
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 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 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
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
Siva Chandra Reddy 139018265b [libc] Add implementations long double fabsl and truncl functions.
Current implementations of single precision and double precision
floating point operations operate on bits of the integer type of
same size. The code made use of magic masks which were listed as
literal integer values. This is not possible in the case of long
double type as the mantissa of quad-precision long double type used
on non-x86 architectures is wider that the widest integer type for
which we can list literal values. So, in this patch, to avoid
using magic masks specified with literal values, we use packed
bit-field struct types and let the compiler generate the masks.
This new scheme allows us to implement long double flavors of the
various floating point operations. To keep the size of the patch
small, only the implementations of fabs and trunc have been
switched to the new scheme. In following patches, all exisiting
implementations will be switched to the new scheme.

Reviewers: asteinhauser

Differential Revision: https://reviews.llvm.org/D82036
2020-06-18 11:08:26 -07:00
Siva Chandra Reddy 1caedd0c55 [libc] Add implementations of ceil[f], floor[f] and trunc[f] from math.h.
Reviewers: abrachet

Differential Revision: https://reviews.llvm.org/D80612
2020-06-01 08:36:59 -07:00
Siva Chandra Reddy 9f69d3d0bc [libc][NFC][Obvious] Convert the MPFR operations enum to an enum class.
This was suggested in https://reviews.llvm.org/D79149.
2020-05-26 22:26:41 -07:00
Siva Chandra Reddy 96d85726b0 [libc] Move implementations of expf and exp2f from the AOR to src/math.
Reviewers: phosek

Differential Revision: https://reviews.llvm.org/D79149
2020-05-15 12:43:03 -07:00
Siva Chandra Reddy 4a39a33d44 [libc] Add implementation of fabs and fabsf.
Reviewers: phosek

Differential Revision: https://reviews.llvm.org/D79725
2020-05-15 11:10:43 -07:00
Siva Chandra Reddy 32a22a423c [libc] Consolidate floating point utils into a single utils library.
A new utils library named 'fputil' is added. This library is used in
math tests and the MPFR wrapper. The math implementations will be
modified to use this library in a later round.

Reviewers: phosek

Differential Revision: https://reviews.llvm.org/D79724
2020-05-15 11:08:41 -07:00
Siva Chandra Reddy a7e1149699 [libc] Fix how math results are compared with MPFR results.
Summary:
Math results are compared with MPFR results by checking if they are
within a tolerance level of the MPFR result. The tolerance level is set
using additional bits of precision of the fractional part of a floating
point value. Hence, the actual value of the tolerance depends on not
only the additional bits, but also on the exponent part of the floating
point number.

Previously, the exponent part was not considered in evaluating the
tolerance value. While it was OK for small values less than 1 (hence
sinf, cosf, sincosf tests were OK), it breaks for large values which
functions like exp and friends produce. This change uses the exponent
value also to evaluate the tolerance value. LLVM libc produced results
can now be compared with MPFR produced results for large values also.

Reviewers: abrachet

Differential Revision: https://reviews.llvm.org/D79278
2020-05-06 10:47:23 -07:00
Siva Chandra Reddy fbaaa16802 [libc] Add no_sanitize("address") attribute to the getMPFRMatcher function.
This dramtically reduces the run time of tests. For example,
sincosf_test takes over 25 minutes without this attribute but only 8
seconds with this attribute.
2020-05-05 13:30:30 -07:00
Siva Chandra Reddy d69cbd826a [libc] Improve information printed on failure of a math test which uses MPFR.
A new test matcher class MPFRMatcher is added along with helper macros
EXPECT|ASSERT_MPFR_MATCH.

New type traits classes RemoveCV and IsFloatingPointType have been
added and used to implement the above class and its helpers.

Reviewers: abrachet, phosek

Differential Revision: https://reviews.llvm.org/D79256
2020-05-05 10:26:29 -07:00
Siva Chandra Reddy 1e2772c0a3 [libc] Link mpfr and gmp wrapper to the libcMPFRWrapper.
This will fix building the wrapper shared library when
BUILD_SHARED_LIBS is ON.

Reviewers: PaulkaToast

Differential Revision: https://reviews.llvm.org/D78737
2020-04-23 11:37:13 -07:00
Siva Chandra Reddy 5fedf7f420 [libc] Move implementations of cosf, sinf, sincosf to src/math directory.
NFC intended in the implementaton. Only mechanical changes to fit the LLVM
libc implementation standard have been done.

Math testing infrastructure has been added. This infrastructure compares the
results produced by the libc with the high precision results from MPFR.
Tests making use of this infrastructure have been added for cosf, sinf and
sincosf.

Reviewers: abrachet, phosek

Differential Revision: https://reviews.llvm.org/D76825
2020-04-16 08:46:10 -07:00