Commit Graph

204 Commits

Author SHA1 Message Date
Tue Ly ffb410d3f9 [libc] Add testing macros for errno and floating point exceptions.
Add testing macros for errno and floating point exceptions.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D121235
2022-03-08 15:49:43 -05:00
Michael Jones bf0ded805a [libc][NFC] split standalone_cpp into single headers
Previously, the entire support/CPP folder was in one header library,
which meant that a lot of headers were included where they shouldn't be.
This patch splits each header into its own target, as well as adjusting
each place they were included to only include what is used.

Reviewed By: sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D121237
2022-03-08 11:56:08 -08:00
Guillaume Chatelet d2c5954662 [libc] undefined reference in LibcTest.cpp
GCC complains about undefined reference in LibcTest.cpp and indeed the wrong version of the template has been explicitly instanciated.
This is necessary to get llvm-libc compile with GCC.

Mentionning D119002 here for navigability.

Differential Revision: https://reviews.llvm.org/D119242
2022-02-09 20:45:56 +00:00
Guillaume Chatelet 83f9b13d8c [libc] Optimized version of memmove
This implementation relies on storing data in registers for sizes up to 128B.
Then depending on whether `dst` is less (resp. greater) than `src` we move data forward (resp. backward) by chunks of 32B.
We first make sure one of the pointers is aligned to increase performance on large move sizes.

Differential Revision: https://reviews.llvm.org/D114637
2022-02-08 11:55:09 +00:00
Guillaume Chatelet c28a522fc7 [libc][NFC] moving template specialization outside class declaration
This is necessary to get llvm-libc compile with GCC.
This patch is extracted from D119002.

Differential Revision: https://reviews.llvm.org/D119142
2022-02-08 10:35:44 +00:00
Tue Ly 9e7688c71e [libc] Implement log1pf correctly rounded to all rounding modes.
Implement log1pf correctly rounded to all rounding modes relying on logf implementation for exponent > 2^(-8).

Reviewed By: sivachandra, zimmermann6

Differential Revision: https://reviews.llvm.org/D118962
2022-02-07 16:17:18 -05:00
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
Siva Chandra Reddy 59eb542f60 [libc] Let header generator generate the type header inclusion boiler plate.
Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D117855
2022-01-24 23:25:19 +00:00
John Ericson 0a3d946e7b [libc][cmake] Make `add_tablegen` calls match others
in all the other `add_tablegen` calls, the project name is so transformed so it
can be a prefix of a CMake variable. I think it is better to do do that here
too for consistency.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D117979
2022-01-24 18:36:37 +00: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
Michael Jones 25226f3e4a [libc] apply formatting to tests
Apply the formatting rules that were applied to the libc/src directory
to the libc/test directory, as well as the files in libc/utils that are
included by the tests. This does not include automated enforcement.

Reviewed By: sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D116127
2021-12-22 10:53:25 -08: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
Michael Jones 6f80339b18 [libc][NFC] Add supporting class for atof implementation
This change adds the High Precision Decimal described here:
https://nigeltao.github.io/blog/2020/parse-number-f64-simple.html
It will be used for the atof implementation later, but is complete and
tested now.

The code is inspired by the golang implmentation of the HPD class, which
can be found here: https://github.com/golang/go/blob/release-branch.go1.16/src/strconv/decimal.go

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D110454
2021-10-04 21:08:02 +00:00
Michael Jones b62d72f3c5 [libc] Add support for 128 bit ints in limits.h
Also, this adds unit tests to check that limits.h complies with the C
standard.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D110643
2021-09-28 23:50:16 +00:00
Michael Jones 1d02a8bcd3 [libc] fix string conversion tests for windows
There were some copy paste errors as well as some oddities around how
windows handles the difference between long and long long types. This
change fixes those.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D108591
2021-08-24 18:06:21 +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 472fa04de8 [libc][nfc] add CPP Limits.h for numeric_limits
Add an implementation of numeric_limits for use in str_conv_utils.
It currently only supports the basic integer types, with more types
coming as needed.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D107987
2021-08-12 21:31:16 +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
Siva Chandra Reddy 3d758e68a7 [libc] Move FPExceptMatcher out of TestHelpers.h
TestHelpers.h pulls few pieces from LLVM libc's unittest framework
which aren't available on platforms like Fuchsia which use their own
unittest framework. So, by moving FPExceptMatcher to a different file
we can exclude LLVM libc specific pieces in a cleaner way.

In a later pass, it might make more sense to rename TestHelpers.h also
to FPMatcher.h. That way, we can make macros like EXPECT_FP_EQ to be
equivalent to EXPECT_EQ on platforms like Fuchsia.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D107129
2021-07-30 23:44:29 +00:00
Alfonso Gregory 640ed21cce [libc][NFC] Add noreturn and constexpr qualifiers where appropriate
These functions make it clear to the compiler and user what the intended
behavior is so llvm can make them go as fast as possible.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D106807
2021-07-29 04:50:05 +00:00
Siva Chandra Reddy dd8b93a9e7 [libc] Fix x86_64 fenv implementation for windows
All fenv functions are also enabled for windows. Since two tests,
enabled_exceptions_test and feholdexcept_test are still failing on
windows, they have been disabled.

Reviewed By: aeubanks

Differential Revision: https://reviews.llvm.org/D106808
2021-07-27 20:53:01 +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
Guillaume Chatelet 47afd43eaa [libc] fix LibcUnitTestMain when building with shared libraries 2021-07-26 08:43:45 +00:00
Caitlyn Cano 5d679fc502 [libc] Clean up Windows macros
This clean-up removes checks for _WIN64, as the _WIN32 macro returns 1
whenever the compilation targe is 32- or 64-bit ARM.

Reviewed By: aeubanks

Differential Revision: https://reviews.llvm.org/D106706
2021-07-23 21:12:36 +00:00
Caitlyn Cano fa7a9ef178 [libc] Add option to run specific tests
This addition reads command line input to run specific single tests
within a larger call to run all the tests for a particular function.
When the user adds a second argument to the command line, the code skips
all the tests that don't match the user's specified binary. If the user
doesn't specify a test correctly and/or no tests are run, a failure
message prints.

Reviewed By: sivachandra, aeubanks

Differential Revision: https://reviews.llvm.org/D105843
2021-07-23 16:08:13 +00:00
Siva Chandra Reddy c698be47ff [libc] Raise denormal exception if the libc defines __FE_DENORM.
Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D106604
2021-07-23 05:42:18 +00:00
Hedin Garca 049cfc464d [libc] Rename FEnv.h and refactor subsequent files
Because Windows's pathnames are not case sensitive,
to avoid include conflicts between our header file FEnv.h and the
one from the C Standard library, <fenv.h>, the prior file was renamed.
The motive for the relabel came to fix this include error in
TestHelpers.cpp since a conflict arose with a file in the same
directory when #include <fenv.h> was being used.

Reviewed By: sivachandra, aeubanks

Differential Revision: https://reviews.llvm.org/D106470
2021-07-22 00:07:39 +00:00
Hedin Garca 137740eced [libc] Exclude few unused bits from x86 state for Windows
Windows fenv_t does not include the MXCSR register and
the unused bits at the end of the x87 status. So we
exclude them in our struct definitions to make it
easy to read/write the state. getEnv and setEnv
were also excluded to avoid using MXCSR, but a
forthcoming patch will handle these functions.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D106386
2021-07-21 13:11:10 +00:00
Siva Chandra Reddy a31f6d2ccf [libc][Obvious] Fix few typos in FPUtil/TestHelpers.cpp 2021-07-21 08:07:35 +00:00
Siva Chandra Reddy ec14ab9624 [libc] Add a new test matcher for tests raising floating point exceptions.
This new matcher does not use death tests to check if SIGFPE is raised.
Instead, that a SIGFPE was raised is checked using a SIGFPE signal handler.

Reviewed By: mcgrathr

Differential Revision: https://reviews.llvm.org/D106086
2021-07-21 04:59:39 +00:00
Roland McGrath 8f053eadbe [libc] Fix typos in x86_64/FEnv.h
Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D106105
2021-07-15 15:21:07 -07:00
Hedin Garca c97cb11efd [libc] Relocate the closing directive of #ifdef
Changed where an #endif was placed because previously it
prevented three macro definitions from being enable in Windows.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D106087
2021-07-15 20:24:29 +00:00
Hedin Garca a5a337e55e [libc] Capture floating point encoding and arrange it sequentially in memory
Redefined FPBits.h and LongDoubleBitsX86 so its implementation works for the Windows
and Linux platform while maintaining a packed memory alignment of the precision floating
point numbers. For its size in memory to be the same as the data type of the float point number.
This change was necessary because the previous attribute((packed)) specification in the struct was not working
for Windows like it was for Linux and consequently static_asserts in the FPBits.h file were failing.

Reviewed By: aeubanks, sivachandra

Differential Revision: https://reviews.llvm.org/D105561
2021-07-13 20:43:54 +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
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 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 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 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