Commit Graph

476 Commits

Author SHA1 Message Date
Michael Jones d52f0aeca5 [libc] Add strtol, strtoul, and strtoull
Updates the internal string conversion function so that it
uses the new Limits.h added in a previous commit for max and min values,
and has a templated type. This makes implementing the other strto*
functions very simple.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D107999
2021-08-17 21:05:37 +00:00
Siva Chandra Reddy 9a56d71f61 [libc][NFC] Disable double precision cos, sin and tan on Windows.
The current x86_64 implementations do not build on the windows bot
machine. We will enable them back after fixing the problem.
2021-08-17 16:47:20 +00:00
Guillaume Chatelet 83457d398d [libc] dedup handling of size 4 for memset 2021-08-16 22:29:10 +00:00
Guillaume Chatelet 8e4efad991 [libc] Optimize Loop strategy
Since the precondition for loop is `size >= T::kSize` we always expect
at least one run of the loop. This patch transforms the for-loop into a
do/while-loop which saves at least one test.

We also add a second template parameter to allow the Tail operation to
differ from the loop operation.
2021-08-16 22:17:56 +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 b062d639bb [libc] add strtoll function and backend
This change adds the stroll function, but most of the implementation is
in the new file str_conv_utils.h since many of the other integer
conversion functions are implemented through what are effectively calls
to strtoll.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D107792
2021-08-11 23:37:23 +00:00
Guillaume Chatelet c82ba4b820 [libc] Update size distributions for memory benchmarks
All distributions have been updated using 7 days worth of data.
2021-08-09 14:22:32 +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 a9628e96ca [libc] Add diff and perf targets for more math functions
Comparing the run time of math functions from LLVM libc
with the MSVCRT libc:
|function	|perf-LLVM libc		    |perf-MSVCRT
|ceilf		|2.36 mins (141491389600 ns)|47.10 sec (47100940100 ns)
|exp2f             |6.37 mins (358441794700 ns)|12.39 mins (719404388300 ns)
|expf		|6.35 mins (381204661800 ns)|6.17 mins (346150163200 ns)
|fabsf		|1.18 mins (78425546600 ns) |53.75 sec (53745301900 ns)
|floorf		|3.15 mins (164770963800 ns)|45.94 sec (45935988400 ns)
|logbf		|4.38 mins (262508058800 ns)|55.47 sec (55466377700 ns)
|nearbyintf	|3.20 mins (167972868000 ns)|9.13 mins (523822963600 ns)
|rintf		|3.20 mins (168001498700 ns)|22.35 mins (1341266448800 ns)
|roundf		|2.35 mins (141151500600 ns)|1.42 mins (85326429800 ns)
|truncf		|2.31 mins (114846424000 ns)|59.41 sec (59414309100 ns)

Evaluating the number of differing results in Windows:
|function	|diff
|ceilf          |8388606 differing results
|exp2f         |213303887 differing results
|expf           |193922 differing results
|fabsf          |8388606 differing results
|floorf         |8388606 differing results
|logbf          |0 differing results
|nearbyintf     |0 differing results
|rintf          |0 differing results
|roundf         |0 differing results
|truncf 	|0 differing results

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D107462
2021-08-05 17:57:04 +00:00
Michael Jones 6ed60fb8a2 [libc] add integration tests for scudo in libc
This change adds tests to make sure that SCUDO is being properly
included with llvm libc. This change also adds the toggles to properly
use SCUDO, as GWP-ASan is enabled by default and must be included for
SCUDO to function.

Reviewed By: sivachandra, hctim

Differential Revision: https://reviews.llvm.org/D106919
2021-08-04 20:06:09 +00:00
Andre Vieira 2f002817fb [libc] Fix Memory Benchmarks code after rename
Differential Revision: https://reviews.llvm.org/D107376
2021-08-04 09:17:12 +01:00
Guillaume Chatelet e4dee76224 [libc] Allow benchmarking several implementations at the same time.
Next step is to generate an archive with all implementations and a header listing them all.

Differential Revision: https://reviews.llvm.org/D107336
2021-08-03 10:53:11 +00:00
Hedin Garca 2ab18d57d7 [libc] Add differential and performance targets for sqrtf
Comparing the runtime of the sqrt functions from LLVM libc with the system libc:
|function       |perf - LLVM libc          |perf - MSVCRT
|sqrtf - Windows|44.05 sec (44051715500 ns)| 417.84 sec (417843359900 ns) = 6.96 mins

|function       |perf - LLVM libc          |perf - glibc
|sqrtf - Linux  |30.48 sec (30479458632 ns)|43.72 sec (43716901527 ns)

By running the differential test:
|function       |diff
|sqrtf - Windows|0 differing results
|sqrtf - Linux  |0 differing results

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D107229
2021-08-02 19:29:48 +00:00
Guillaume Chatelet 59198d062f [libc] Add a Google Benchmark target to support continuous monitoring of memory operation performance
The next step is to be able to benchmark several implementations at once and compare which one performs best on a particular machine.

Differential Revision: https://reviews.llvm.org/D107265
2021-08-02 12:14:11 +00:00
Siva Chandra Reddy 66d92efc66 [libc] Add trigonometric and exponential functions to the windows config. 2021-07-31 01:30:26 +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
Siva Chandra Reddy 381f9affab [libc][NFC] Add dummy errno target to satisfy mixed mode builds.
In mixed mode builds, we should not be including errno as part of
LLVM libc - errno from another library (or the system library) should be
used. But, other entrypoints which use errno list LLVM libc's errno as a
dep ta satisfy the full build mode. So, we add a dummy errno
implementation with empty files to make both mixed mode and full build
mode happy.
2021-07-30 17:42:48 +00:00
Guillaume Chatelet cd2f5d5b49 [libc] rewrite aarch64 memcmp implementation
This patch is simply rearranging the code layout so it's easier to understand.

Differential Revision: https://reviews.llvm.org/D106641
2021-07-29 14:41:12 +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
Michael Jones c6d03b583b [libc] add strncmp to strings
Add strncmp as a function to strings.h. Also adds unit tests, and adds
strncmp as an entrypoint for all current platforms.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D106901
2021-07-28 21:37:12 +00:00
Guillaume Chatelet d3c70d9f77 [libc] Simplify implementation of benchmarks
This also allows to run the distribution benchmarks in other frameworks
like the Google Benchmark facility.
2021-07-28 15:04:19 +00:00
Alfonso Gregory 0784e62c3c [libc] Fix strtok_r crash when src and *saveptr are both nullptr
While working and testing my refactoring of multiple string functions in libc, I came across a bug that needs to be addressed in a patch on its own: src is checked for nullptr and assigned to *saveptr if it is nullptr. However, saveptr is initially nullptr when it comes to reentry. This could cause a problem if both saveptr and src are null; we need to do the check first and return nullptr if both are nullptr.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D106885
2021-07-27 21:49:23 +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
Michael Jones 016ae7df95 [libc] add scudo wrappers to llvm libc
The previous patch included the implementations for the scudo allocator,
but not the wrappers. This change fixes that.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D106718
2021-07-26 17:24:52 +00:00
Guillaume Chatelet 47afd43eaa [libc] fix LibcUnitTestMain when building with shared libraries 2021-07-26 08:43:45 +00:00
Siva Chandra Reddy c24c18bba6 [libc] Accommodate Fuchsia's death test framework in fenv tests.
Fuchsia's death test framework runs the closure which can die in a
different thread. Hence, the FP exceptions which cause the closure to
die should be enalbed in the closure.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D106683
2021-07-23 22:19:04 +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
Michael Jones da06d1795a [libc] add option to use SCUDO as the allocator
This patch adds LLVM_LIBC_INCLUDE_SCUDO as a flag. When enabled it
should link in the standalone version of SCUDO as the allocator for LLVM
libc.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D106502
2021-07-23 17:36:09 +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
Guillaume Chatelet 24ffb98f9d [libc] optimize bzero/memset for x86
This is simpy using the x86 optimized elements when targetting x86 cpus.

Differential Revision: https://reviews.llvm.org/D106551
2021-07-23 12:21:46 +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
John Ericson e7fe4433f8 Remove `LIBC_INSTALL_PREFIX`
This matches the decision made in D99697.

It also shouldn't reintroduce the issue fixed in D99636.

The variable was originally introduced in
b22f448c21 but is not essential to that
change.

Once we finish adding `GnuInstallDirs` support in D100810 and D99484,
setting `CMAKE_INSTALL_LIBDIR` would also work to change the
installation directory (though for more than libc).

`GnuInstallDirs` support also brings up an issue which is avoided if
variables like `LIBC_INSTALL_PREFIX` don't exist. Because the
`GnuInstallDirs` variables can be absolute paths, it is a bit unclear
how the per-project prefixes would work: does the project-agnostic
role-specific variable (e.g. `CMAKE_INSTALL_LIBDIR`), or project-specfic
role-agnostic (e.g. `LIBC_INSTALL_PREFIX`) take priority? Each is more
specific than the other on one axis, but not the other.

Reviewed By: phosek

Differential Revision: https://reviews.llvm.org/D105740
2021-07-21 23:07:36 +00:00
Hedin Garca efa2115266 [libc] Include nextafter's functions to Windows's entrypoints
Incorporated the varied functions for nextafter and refactored
NextAfterTest.h to correctly define bitWidthOfType for both
Linux and Windows; by letting FloatProperties take care
of the directives' logic based on the platform being used.
This allows to successfully run nextafter's tests.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D106395
2021-07-21 13:28:01 +00:00
Hedin Garca f49f2e2d1f [libc] Append math functions to Window's entrypoints
Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D106391
2021-07-21 13:21:55 +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 ff384700f2 [libc][NFC] Adjust enabled_exceptions_test wrt FE_INEXACT.
Since exceptions like FE_DIVBYZERO can raise FE_INEXACT, we need to
ensure that we don't raise FE_DIVBYZERO (or others which can also raise
FE_INEXACT) when FE_INEXACT is enabled.
2021-07-21 05:49:19 +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
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