Commit Graph

2209 Commits

Author SHA1 Message Date
Tue Ly
84c899b235 [libc][math] Extract non-MPFR math tests into libc-math-smoke-tests.
Extract non-MPFR math tests into libc-math-smoke-tests.

Reviewed By: sivachandra, jhuber6

Differential Revision: https://reviews.llvm.org/D159477
2023-09-19 12:10:21 -04:00
Jeff Bailey
acfb99d9fd
[libc] Specify path for making include/ subdirs (#66589)
When doing a clean build from vscode, it makes the subdirectories in the
source tree rather than in the build folder. Elsehwere in LLVM, they
prefix the MAKE_DIRECTORY calls, so this appears to be the correct
approach.
2023-09-18 21:00:51 -07:00
Joseph Huber
c354ee8d18
[libc][GPU] Fix dependencies for externally installed stub files (#66653)
Summary:
The GPU build has a lot of magic around how we package the output.
Generally, the GPU needs to exist as a secondary fatbinary image for
offloading languages. This is because offloading languages pretend like
offloading to an accelerator is a single file. This then needs to be put
into a single file to make it mesh with the existing build
infrastructure. To work with this, the `libc` makes an installed version
of the library that simply embeds the GPU code into an empty stub file.

This wasn't being updated correctly, which lead to the installed `libc`
static library not being updated correctly when the underlying file was
changed. The previous behaviour only updated when the entrypoint itself
was modified, but not any of its headers. By adding a dependcy on the
actual *object* file we should now capture the regular CMake semantics.
2023-09-18 10:15:02 -05:00
Joseph Huber
b8f64431ea
[libc] Add GPU config file using the new format (#66635)
Summary:
This patch copies a config file for the GPU similar to the
baremetal/embedded implementation. This will configure the
implementations of functions like `sprintf` and `snprintf` to be
compiled into more simple versions that can be run on the GPU. These
functions cannot be enabled yet as Vararg support hasn't landed, but it
will be used then.
2023-09-18 08:06:59 -05:00
Siva Chandra
7d7df7f237
[libc] Add a developer doc about adding new config options. (#66432) 2023-09-15 14:34:25 -07:00
Guillaume Chatelet
c21be63228
[libc][cmake] Report invalid clang-tidy path (#66475)
Adds better error reporting for missing clang-tidy.
2023-09-15 17:43:48 +02:00
Guillaume Chatelet
2dbdc9fc85
[libc] Add invoke / invoke_result type traits (#65750) 2023-09-15 11:15:41 +02:00
Joseph Huber
bbe7eb92b4 [libc][Obvious] Fix missing entrypoints after moving to generic
Summary:
The previous patch moved the implementations of these to generic/ and
accidentally did not add the unlocked variants. This patch fixes that
2023-09-14 15:59:08 -05:00
Joseph Huber
a1be5d69df
[libc] Implement more input functions on the GPU (#66288)
Summary:
This patch implements the `fgets`, `getc`, `fgetc`, and `getchar`
functions on the GPU. Their implementations are straightforward enough.
One thing worth noting is that the implementation of `fgets` will be
extremely slow due to the high latency to read a single char. A faster
solution would be to make a new RPC call to call `fgets` (due to the
special rule that newline or null breaks the stream). But this is left
out because performance isn't the primary concern here.
2023-09-14 15:39:29 -05:00
Mikhail R. Gadelha
72e6f06119
[libc] Fix start up crash on 32 bit systems (#66210)
This patch changes the default types of argc/argv so it's no longer a
uint64_t in all systems, instead, it's now a uintptr_t, which fixes
crashes in 32-bit systems that expect 32-bit types. This patch also adds
two uintptr_t types (EnvironType and AuxEntryType) for the same reason.

The patch also adds a PgrHdrTableType type behind an ifdef that's
Elf64_Phdr in 64-bit systems and Elf32_Phdr in 32-bit systems.
2023-09-14 09:02:35 -04:00
Alex Brachet
2ad7a06cb1
[libc] Fix some warnings (#66366)
Some compilers will warn about dangling else and missleading lack of
parentheses.
2023-09-14 08:47:21 -04:00
Guillaume Chatelet
aee8f8784a
[libc][utils] cpp::always_false to enable static_assert(false) (#66209) 2023-09-14 10:28:43 +02:00
Siva Chandra
f8f934e22c
[libc][NFC] Make the dummy header target under overlay build a library. (#66329)
This fixes the broken overlay builders.
2023-09-13 22:52:20 -07:00
Siva Chandra
17114f8b19
[libc] Remove common_libc_tuners.cmake and move options into config.json. (#66226)
The name has been changed to adhere to the config option naming format.
The necessary build changes to use the new option have also been made.
2023-09-13 22:17:00 -07:00
Michael Jones
3fb63c2921 [libc] simplify printf float writing
The two decimal float printing styles are similar, but different in how
they end. For simplicity of writing I initially gave them different
"write_last_block" functions. This patch unifies them into one function.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D158036
2023-09-13 13:53:29 -07:00
Michael Jones
aa1eacd10c [libc][docs] Printf behavior doc
In the document on undefined behavior, I noted that writing down your
decisions is very important. This document contains all the information
for compile flags and undefined behavior for our printf.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D158311
2023-09-13 13:42:30 -07:00
Joseph Huber
089b81105a [libc][NFC][Docs] Update some GPU testing information
Summary:
This comment is outddated and can be removed, also mention an option for
limiting parallelism during tests in the documentation.
2023-09-13 14:30:30 -05:00
michaelrj-google
380eb46b13
[libc] Move long double table option to new config (#66151)
This patch adds the long double table option for printf into the new
configuration scheme. This allows it to be set for most targets but
unset for baremetal.
2023-09-13 10:43:05 -07:00
Joseph Huber
bf85f27370
[libc] Implement 'qsort' and 'bsearch' on the GPU (#66230)
Summary:
This patch simply adds the necessary config to enable qsort and bsearch
on the GPU. It is *highly* unlikely that anyone will use these, as they
are single threaded, but we may as well support all entrypoints that we
can.
2023-09-13 12:06:34 -05:00
Siva Chandra
d25b4fae93
[libc][NFC] Make entrypoint alias targets real library targets. (#66044)
This is part of a libc wide CMake cleanup which aims to eliminate
certain explicitly duplicated logic which is available in CMake-3.20.
This change in particular makes the entrypoint aliases real library
targets so that they can be treated as normal library targets by other
libc build rules.
2023-09-13 08:35:23 -07:00
Mikhail R. Gadelha
75398f28eb [libc] Make time_t 64 bits long on all platforms but arm32
This patch changes the size of time_t to be an int64_t. This still
follows the POSIX standard which only requires time_t to be an integer.

Making time_t a 64-bit integer also fixes two cases in 32 bits platforms
that use SYS_clock_nanosleep_time64 and SYS_clock_gettime64, as the name
of these calls implies, they require a 64-bit time_t. For instance, in rv32,
the 32-bit version of these syscalls is not available.

We also follow glibc here, where time_t is still a 32-bit integer in
arm32.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D159125
2023-09-13 10:49:39 -03:00
Joseph Huber
ef169f5707
[libc] Improve the implementation of the rand() function (#66131)
Summary:
This patch improves the implementation of the standard `rand()` function
by implementing it in terms of the xorshift64star pRNG as described in
https://en.wikipedia.org/wiki/Xorshift#xorshift*. This is a good,
general purpose random number generator that is sufficient for most
applications that do not require an extremely long period. This patch
also correctly initializes the seed to be `1` as described by the
standard. We also increase the `RAND_MAX` value to be `INT_MAX` as the
standard only specifies that it can be larger than 32768.
2023-09-12 16:52:20 -05:00
Joseph Huber
688019851e
[libc][NFC] Factor GPU exiting into a common function (#66093)
Summary:
We currently call the GPU routine to terminate the current thread in
three separate locations .This should be wrapped into a helper function
to simplify the implementation.
2023-09-12 14:59:02 -05:00
Siva Chandra
c5ad6c7781
[libc] Fix a typo in a CMakeLists.txt - replace DEPS with DEPENDS. (#66130) 2023-09-12 12:24:27 -07:00
Siva Chandra
0f31e5697b
[libc] Add missing deps for header libraries. (#66125)
Also, we removed CMP0076 exception sometime back but did not adjust the
build rules. The adjustment in the build rules is also done in this
patch.
2023-09-12 11:53:03 -07:00
Siva Chandra
9048aa71af
[libc] Make add_header and add_gen_header targets normal library targets. (#66045)
This way, they can be added as deps to other library targets without any
special handling.
2023-09-12 08:50:05 -07:00
Guillaume Chatelet
7329816285
[libc] Add is_object (#65749)
Add the is_object type traits.
Implementation comes from
https://en.cppreference.com/w/cpp/types/is_object
2023-09-12 10:35:22 +02:00
Siva Chandra
eb06125604
[libc][NFC] Eliminate the internal header library target. (#65837)
The internal header library target with name suffix `.__header_library`
has been removed as it serves no purpose now. It was added to make older
versions of CMake happy.
2023-09-11 11:22:33 -07:00
Joseph Huber
76af6e77c0
[libc] Manually set the AMDGPU code object version (#65986)
Summary:
There is currently effort to change over the default AMDGPU code object
version https://github.com/llvm/llvm-project/pull/65410. However, this
unfortunately causes problems in the LLVM LibC test suite that leads to
a hang while executing. This is most likely a bug to do with indirect
call optimization, as it can be avoided without optimizations or with
manually preventing inlining in the AMDGPU startup code.

This patch sets the AMDGPU code object version to be four explicitly on
the LibC test suite. This should unblock the efforts to move the default
to 5 without breaking the test suite. This isn't a great solution, but
there is currently some time pressure to get COV5 landed and this seems
to be the easiest solution.
2023-09-11 13:07:56 -05:00
Guillaume Chatelet
a1f5a495e0
[libc] Add type_traits tests (#65956)
This is not exhaustive for now but it provides a placeholder for
`invoke_result` test mentioned in #65750.
2023-09-11 14:15:12 +00:00
Guillaume Chatelet
d557e2b076
[libc][NFC] Fix missing header in CMakelists.txt (#65960) 2023-09-11 14:12:58 +00:00
Guillaume Chatelet
88348252a6
[libc] Add missing add_lvalue_reference_t (#65940) 2023-09-11 11:31:37 +02:00
Joseph Huber
60c0d303d6
[libc] Implement stdio writing functions for the GPU port (#65809)
Summary:
This patch implements fwrite, putc, putchar, and fputc on the GPU. These
are very straightforward, the main difference for the GPU implementation
is that we are currently ignoring `errno`. This patch also introduces a
minimal smoke test for `putc` that is an exact copy of the `puts` test
except we print the string char by char. This also modifies the `fopen`
test to use `fwrite` to mirror its use of `fread` so that it is tested
as well.
2023-09-09 13:27:07 -05:00
Siva Chandra
b0068b5b06
[libc][NFC] Make add_header_library rule support COMPILE_OPTIONS. (#65821)
The options added via COMPILE_OPTIONS will be treated as INTERFACE
options. This will help in setting compile options based on libc config
options in future patches.
2023-09-08 20:34:00 -07:00
Siva Chandra
ca2a4e76ea
[libc] Generate configure.rst from the JSON config information. (#65791) 2023-09-08 13:11:09 -07:00
Joseph Huber
31d4f0692f
[libc][NFC] Cleanup the GPU file I/O utility header (#65680)
Summary:
The GPU uses separate implementations to perform file IO. This is all
done through the RPC interface and we kept it minimal such that we could
treat a `stdin`, `stdout`, or `stderr` handle from the CPU correctly on
the GPU. The RPC implementation uses different opcodes for whether or
not we are using one of the standard streams. This is so we do not need
to initialize anything to access the CPU's standard stream, because the
server knows that it should print to `stdout` if it gets the `STDOUT`
variant of the opcode. It also saves us an RPC call, which are expensive
relatively  speaking. This patch simply cleans up this interface to make
them all use a common function. This is done in preparation to implement
some more file IO functions like getc or putc.
2023-09-08 14:15:53 -05:00
Siva Chandra
1d0d57e89a
[libc][docs] Fix docs/gpu/support.rst. (#65790) 2023-09-08 11:45:20 -07:00
Joseph Huber
71168f6889
[libc] Build the libc objects using a generic AMDGPU ABI (#65782)
Summary:
AMDGPU binaries use a "code object" as the ABI indicator. We are
currently trying to move over to a newer code object. We want these
library functions to use the "generic" or default ABI such that it is
specified when linked into the user application. Currently this will
default to v4 as the startup code will use whatever the current default
is.
2023-09-08 13:17:00 -05:00
Mikhail R. Gadelha
123bf08402
[libc] Unify gettime implementations (#65383)
Similar to D159208, this patch unifies the calls to a syscall, in this
patch it is the syscall SYS_clock_gettime/SYS_clock_gettime64.

This patch also fixes calls to SYS_clock_gettime64 by creating a
timespec64 object, passing it to the syscall and rewriting the timespec
given by the caller with timespec64 object's contents. This fixes cases
where timespec has a 4 bytes long time_t member, but SYS_clock_gettime
is not available (e.g., rv32).
2023-09-08 12:41:29 -04:00
Guillaume Chatelet
74971db140
[libc] Add is_scalar (#65740)
Adds the is_scalar traits based on implementation in
https://en.cppreference.com/w/cpp/types/is_scalar
2023-09-08 12:45:17 +00:00
Guillaume Chatelet
eebf8faf3e
[libc] Add is_member_pointer_v (#65631)
Implementation from
https://en.cppreference.com/w/cpp/types/is_member_pointer
2023-09-08 11:36:19 +02:00
Michael Jones
dd51ae81d8 [libc] Fix printf %p format
The %p format wasn't correctly passing along flags and modifiers to the
integer conversion behind the scenes. This patch fixes that behavior, as
well as changing the nullptr behavior to be a string conversion behind
the scenes.

Reviewed By: lntue, jhuber6

Differential Revision: https://reviews.llvm.org/D159458
2023-09-07 14:13:35 -07:00
Mikhail R. Gadelha
9ff0a447d0 [libc] Fix setrlimit/getrlimit on 32-bit systems
libc uses SYS_prlimit64 (which takes a struct rlimit64) to implement
setrlimt and getrlimit (which take a struct rlimit). In 64-bit bits
systems this is not an issue since the members of struct rlimit64 and
struct rlimit are 64 bits long, however, in 32-bit systems the members
of struct rlimit are only 32 bits long, causing wrong values being
passed to SYS_prlimit64.

This patch changes rlim_t to be __UINT64_TYPE__ (which also changes
rlimit as a side-effect), fixing the problem of mismatching types in
the syscall.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D159104
2023-09-07 16:02:32 -03:00
Joseph Huber
4792ae5cd5
[libc] Fix building the RPC server with LIBC_NAMESPACE (#65642)
A recent patch required the implementation to define `LIBC_NAMESPACE`.
For GPU offloading we provide a static library whose internal
implementation relies on the `libc` headers. This is a separate library
that is constructed during the "bootstrap" phase. This patch moves the
definition of the `LIBC_NAMESPACE` CMake variable up so its available
during bootstrapping and adds it to the definition of the RPC server.
2023-09-07 12:47:36 -05:00
Joseph Huber
d6cc3410ab
[libc] Fix missing GPU math implementations (#65616)
These functions were implemented by simply calling their `__builtin_*`
equivalents.
The builtins were resolving to the libc functions back again. This patch
adds explicit
vendor versions for these functions to avoid the recursion.
2023-09-07 11:48:44 -05:00
Guillaume Chatelet
260036ab1e
[libc] move in_place_t in utility (#65623)
This is needed because `cpp::in_place_t` is also used by `cpp::expected`
https://en.cppreference.com/w/cpp/utility/in_place
2023-09-07 18:12:50 +02:00
Guillaume Chatelet
a279bf0d78
[libc] Add is_null_pointer_v (#65627) 2023-09-07 18:07:24 +02:00
Guillaume Chatelet
f72d41b5b1
[libc] Add missing include in type_traits/remove_all_extents.h (#65626) 2023-09-07 17:57:47 +02:00
Guillaume Chatelet
26ddf2c935
[libc] fix missing default template parameter value in enable_if (#65622) 2023-09-07 17:42:00 +02:00
Tue Ly
f0d05bb699 [libc][math] Fix signed zeros for acosf, acoshf, and atanf in FE_DOWNWARD mode.
Fix signed zeros for acosf, acoshf, and atanf in FE_DOWNWARD mode.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D159476
2023-09-07 15:21:33 +00:00