Commit Graph

683 Commits

Author SHA1 Message Date
Michael Jones 7eb5cb7f9e [libc] Fix allocator inclusion
Previously, allocator functions were only available if they were included
from scudo or by using the system libc headers (i.e. by turning off the
full build). This patch changes the logic to include the prototypes for
the allocator functitons in all cases, which allows the linker to link
in the system's allocator.

Reviewed By: sivachandra, abrachet

Differential Revision: https://reviews.llvm.org/D119587
2022-02-11 14:58:21 -08:00
Michael Jones 03731ed393 [libc][obvious] only include vector with malloc
the vector class, due to being dynamically resized, needs malloc. This
fixes the build so that it only includes it when malloc should be
available.

Differential Revision: https://reviews.llvm.org/D119464
2022-02-10 11:17:35 -08:00
Michael Jones 06cfb7a345 [libc] add a vector internal class
Add a basic implementation of the vector class for use internally to
LLVM-libc.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D118954
2022-02-10 11:04:18 -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
Siva Chandra Reddy 545331abf3 [libc][Obvious] Fix typo in mkdir and mkdirat implementations.
Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D119265
2022-02-08 21:48:12 +00:00
Guillaume Chatelet 7e7ecef980 [libc] Replace type punning with bit_cast
Although type punning is defined for union in C, it is UB in C++.
This patch introduces a bit_cast function to convert between types in a safe way.

This is necessary to get llvm-libc compile with GCC.
This patch is extracted from D119002.

Differential Revision: https://reviews.llvm.org/D119145
2022-02-08 20:45:59 +00:00
Alex Brachet 70ae480c82 [libc][NFC] Remove all Linux specific code to respective linux/ directories
These were all the non OS agnostic implementations I could find in general directories.

Currently none of these functions are actually enabled, but for when they do it makes sense that they be in linux/ specific directories.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D119164
2022-02-08 18:32:18 +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 f231599666 [libc] Don't use Clang flags on other compilers
This is necessary to get llvm-libc compile with GCC.
This patch is extracted from D119002.

Differential Revision: https://reviews.llvm.org/D119143
2022-02-08 11:00:48 +00:00
Guillaume Chatelet a33e98543a [libc] Disable rtti/expections
llvm-libc exhibits a C interface but its source is C++.
This patch explicitly disables the use of exceptions and RTTI when compiling the entrypoints.

Differential Revision: https://reviews.llvm.org/D118889
2022-02-08 10:46:28 +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 e5e93f60ee [libc] Return a float NaN for log1pf instead of double NaN. 2022-02-07 21:07:09 -05:00
Tue Ly 6472421840 [libc] Fix mixed-sign comparison warnings and an out-of-bound access in high_precision_decimal.h
Fix mixed-sign comparison warnings and an out-of-bound access in high_precision_decimal.h

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D119156
2022-02-07 16:23:09 -05:00
Tue Ly 5753218852 [libc][Obvious] Suppress unused-variable warnings from syscall_unittest.
The unused vararibles in the tests are intentional.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D119183
2022-02-07 16:22:08 -05: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 25d50a00c5 [libc][Obvious] Fix a mismatch signature of HighPrecisionDecimal::should_round_up.
Its input should be int32_t instead of uint32_t.

Reviewed By: michaelrj, sivachandra

Differential Revision: https://reviews.llvm.org/D118791
2022-02-03 22:36:03 -05:00
Guillaume Chatelet d5bb0de75e
[libc] Populate rtti/eh flags for all targets 2022-02-02 15:15:39 +01:00
Guillaume Chatelet 36c36c1ee3 [libc] use llvm_update_compile_flags to populate rtti/exception compilation flags 2022-02-02 13:36:30 +00:00
Guillaume Chatelet 02022ccccc [NFC][libc] Remove unneeded gtest and benchmark configuration
Differential Revision: https://reviews.llvm.org/D118770
2022-02-02 12:23:44 +00:00
Guillaume Chatelet b840f30d1e [libc] Fix automemcpy test by adding memmove configuration 2022-02-02 11:28:06 +00:00
Siva Chandra be7c865af1 [libc] Add a few missing deps, includes, and fix a few typos.
This allows us to enable rmdir, mkdir, mkdirat, unlink and unlinkat for
aarch64.
2022-02-01 00:26:36 -08:00
Siva Chandra Reddy 4c1b44160a [libc] Adjust few fcntl macros for aarch64. 2022-02-01 08:14:32 +00:00
Siva Chandra Reddy b8385162c2 [libc] Add implementations of POSIX mkdir, mkdirat, rmdir, unlink and unlinkat.
Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D118641
2022-02-01 05:17:10 +00:00
Jeff Bailey 4465c29906 Move LLVM Proposal to doc directory, create index
The LLVM Libc project is no longer just a proposal and should have
a webpage tracking the status of the project.  This changes
puts the pieces into the right place so that the webpage can be
created.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D117436
2022-01-29 00:29:31 +00:00
Siva Chandra 0e91c48df0 [libc] Enable creat, fsync, open, openat, read and write for aarch64. 2022-01-28 12:06:08 -08:00
Siva Chandra Reddy 4abfe47e1f [libc] Add implementations of the POSIX creat and openat functions.
Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D118435
2022-01-28 19:28:12 +00:00
Tue Ly ad4ee2d778 [libc] Refactor sqrt implementations and add tests for generic sqrt implementations.
Re-apply https://reviews.llvm.org/D118173 with fix for aarch64.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D118433
2022-01-28 13:39:03 -05:00
Siva Chandra Reddy a858e25f1c [libc][NFC] Create file with all permissions for the user in read_write_test. 2022-01-28 16:41:52 +00:00
Dominic Chen 3f72f9da43 [libc] Fix 64-bit Apple ARM support and header includes
Summary:

Reviewers: sivachandra

Subscribers:

Differential Revision: https://reviews.llvm.org/D114236
2022-01-28 00:22:47 -08:00
Siva Chandra Reddy 4beba3a32a [libc] Revert "Refactor sqrt implementations and add tests for generic sqrt implementations."
This reverts commit 21c4c82c20.
2022-01-27 21:06:14 +00:00
Siva Chandra Reddy fdd4269f2e [libc] Revert "Guard sqrt_80_bit_long_double.h header to not be included with aarch64."
This reverts commit 4a979c4256.
2022-01-27 21:05:54 +00:00
Siva Chandra Reddy dc2b01b3f7 [libc] Add POSIX close, fsync, open, read and write functions.
They are implemented as simple syscall wrappers. The file creation
macros have been put in a header file as a temporary solution until we
have a cleaner approach to listing platform relevant macros.

Reviewed By: abrachet

Differential Revision: https://reviews.llvm.org/D118396
2022-01-27 20:32:02 +00:00
Tue Ly 4a979c4256 [libc] Guard sqrt_80_bit_long_double.h header to not be included with aarch64.
Guard sqrt_80_bit_long_double.h header to not be included with aarch64.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D118389
2022-01-27 13:36:39 -05:00
Siva Chandra Reddy 09f2f81ce8 [libc][NFC] Move the POSIX write function to the default build on linux. 2022-01-27 17:29:13 +00:00
Siva Chandra Reddy 07c9903a8b [libc][NFC] Let var args be treated as a named type in the spec.
The type names in the spec are just sugar used by the header generator to
generate the function prototype. Giving the VarArgType a name of "..."
allows the header generator to treat and generate the "type name" for var
arg parameters similar to how it does for any other type.
2022-01-27 17:07:21 +00:00
Tue Ly 21c4c82c20 [libc] Refactor sqrt implementations and add tests for generic sqrt implementations.
Refactor sqrt implementations:
- Move architecture specific instructions from `src/math/<arch>` to `src/__support/FPUtil/<arch>` folder.
- Move generic implementation of `sqrt` to `src/__support/FPUtil/generic` folder and add it as a header library.
- Use `src/__support/FPUtil/sqrt.h` for architecture/generic selections.
- Add unit tests for generic implementation of `sqrt`.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D118173
2022-01-27 11:54:54 -05:00
Tue Ly 82df72cc67 [libc] Make logf function correctly rounded for all rounding modes.
Make logf function correctly rounded for all rounding modes.

Reviewed By: sivachandra, zimmermann6, santoshn, jpl169

Differential Revision: https://reviews.llvm.org/D118149
2022-01-25 15:22:21 -05:00
Alex Brachet ce368e1aa5 [libc][NFC] Workaround clang assertion in inline asm
The clobber list "cc" is added to inline assembly to workaround a clang assertion that triggers when building with a clang built with assertions enabled. See bug [53391](https://github.com/llvm/llvm-project/issues/53391).

See https://godbolt.org/z/z3bc6a9PM showing functionally same output assembly.

Reviewed By: sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D118099
2022-01-25 16:39:55 +00: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
Siva Chandra Reddy 7f0f4cab18 [libc][NFC] Add 'struct_' prefix to type headers defining struct types.
This allows header generator to generate type inclusion boiler plate in
a straightforward manner.
2022-01-21 07:04:32 +00:00
Clint Caywood d92e5412ea [libc] Use __builtin_clz to find leading 1 in hypot
This is an optimization that using a single CPU instruction on supported
architectures (amd64 and aarch64, but possibly others) to replace what was
previously an iterative look-up-table algorithm.

Originally I suggested using inline assembly for this in
https://reviews.llvm.org/D117584.

Reviewed By: lntue, sivachandra

Differential Revision: https://reviews.llvm.org/D117684
2022-01-20 23:32:34 +00:00
Siva Chandra Reddy 284cd693f1 [libc] Move the remaining public types to their own type headers.
Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D117838
2022-01-20 23:04:26 +00:00
Tue Ly 1f3f90ab88 [libc] Make log2f correctly rounded for all rounding modes when FMA is not available.
Add to log2f 2 more exceptional cases got when not using fma for polyeval.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D117812
2022-01-20 16:16:11 -05:00
Tue Ly d4baf3b132 [libc] Use get_round() instead of floating point tricks in generic hypot implementation.
The floating point tricks used to get rounding mode require -frounding-math flag, which behaves differently on aarch64.  Reverting back to use get_round instead.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D117824
2022-01-20 14:54:57 -05:00
Tue Ly aad04534c4 [libc] Implement correct rounding with all rounding modes for hypot functions.
Update the rounding logic for generic hypot function so that it will round correctly with all rounding modes.

Reviewed By: sivachandra, zimmermann6

Differential Revision: https://reviews.llvm.org/D117590
2022-01-20 13:33:20 -05:00
Siva Chandra Reddy 10ed3c9d2c [libc] Move type definitions to their own self contained header files.
Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D117282
2022-01-20 00:13:32 +00:00
Siva Chandra Reddy 75d2fcb03f [libc] Add a naming rule for global constants.
Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D117645
2022-01-19 22:11:16 +00:00