Commit Graph

2085 Commits

Author SHA1 Message Date
Michael Jones
222d7cf17f [libc][NFC] Fix warning in uint operator T
This code is creating a warning on Fuchsia, this patch should fix that
warning.

Reviewed By: mcgrathr

Differential Revision: https://reviews.llvm.org/D157546
2023-08-11 14:35:41 -07:00
Guillaume Chatelet
bc2b1193b5 [libc] add the CPP algorithm header for min/max
Reviewed By: jhuber6, sivachandra

Differential Revision: https://reviews.llvm.org/D157405
2023-08-10 08:00:18 +00:00
Joseph Huber
fe04baf1f7 [libc] Silence integer shortening warnings on NVPTX masks
Nvidia uses a 32-bit mask, but we store it in a common 64-bit integer to
provide it with a compatible ABI with the AMD implementaiton which may
use a 64-bit mask. Silence these warnings by explicitly casting to the
smaller value, we know this is always legal as the result will always
fit into the smaller value if it was generated on NVPTX.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D157548
2023-08-09 17:18:07 -05:00
Joseph Huber
d2024bbce3 [libc][Fix] Move generic stdio implementations to a new directory
For whatever reason, the CMake did not like having the `generic_`
version live in the same directory. This patch pushes them to a new
directory, which is probably clearer anyway.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D157544
2023-08-09 15:32:34 -05:00
Joseph Huber
0c898b26b9 [libc][Obvious] Fix incorrect dependency for alias target
Summary:
This was not updated correctly, causing the alias to not be set as
expected. Fix this by using the correct `generic_` prefix.
2023-08-09 14:46:55 -05:00
Roland McGrath
5207451dd0 [libc] Compile with -Wconversion -Wno-sign-conversion
This more closely matches the stricter warnings used for
this same code in the Fuchsia build.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D156630
2023-08-09 12:46:20 -07:00
Joseph Huber
d04494ccc9 [libc] Rework the file handling for the GPU
The GPU has much tighter requirements for handling IO functions.
Previously we attempted to define the GPU as one of the platform files.
Using a common interface allowed us to easily define these functions
without much extra work. However, it became more clear that this was a
poor fit for the GPU. The file interface uses function pointers, which
prevented inlining and caused bad perfromance and resource usage on the
GPU. Further, using an actual `FILE` type rather than referring to it as
a host stub prevented us from usin files coming from the host on the GPU
device.

After talking with @sivachandra, the approach now is to simply define
GPU specific versions of the functions we intend to support. Also, we
are ignoring `errno` for the time being as it is unlikely we will ever
care about supporting it fully.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D157427
2023-08-09 14:42:20 -05:00
Michael Jones
8b37431024 [libc] Fix vfprintf test colliding with fprintf
Sometimes the vfprintf test was failing, I suspect that's due to it
using the same filename as the fprintf test. This patch fixes that
problem by changing the filename of the vfprintf output file.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D157523
2023-08-09 10:31:58 -07:00
Michael Jones
e328d19302 [libc] Fix final conversion warnings
This patch fixes the floating point conversion warnings found with
`-Wconversion` and `-Wno-sign-conversion`. These were the last warnings
I found, meaning that once this lands https://reviews.llvm.org/D156630
should be unblocked.

Reviewed By: mcgrathr, lntue

Differential Revision: https://reviews.llvm.org/D157449
2023-08-09 10:24:03 -07:00
Mikhail R. Gadelha
860d38bf57 [libc] Support poky system
This patch adds support for yocto images, which are custom Linux-base
systems created by yocto.

$CMAKE_HOST_SYSTEM_NAME returns "poky" as the system name, but it is a
linux image, so we just replace the name with "linux", so libc can use
the correct path.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D157404
2023-08-09 10:40:19 -03:00
Guillaume Chatelet
b555912e70 [libc] Better IntegerToString API
This patch is an alternative to D155902. It provides the following benefits:
 - No buffer manual allocation and error handling for the general case
 - More flexible API : width specifier, sign and prefix handling
 - Simpler code

The more flexible API removes the need for manually tweaking the buffer afterwards, and so prevents relying on implementation details of IntegerToString.

Reviewed By: michaelrj, jhuber6

Differential Revision: https://reviews.llvm.org/D156981
2023-08-09 07:33:29 +00:00
Guillaume Chatelet
6632b25841 [libc] Make add_libc_unittest compile with -ffreestanding
tests not compile with `-ffreestanding` can pull unwanted dependencies like `limits.h` which defines `PTHREAD_STACK_MIN`.
This is what caused the build bot failure in https://reviews.llvm.org/D156981#4570776.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D157444
2023-08-09 07:31:59 +00:00
Guillaume Chatelet
98ab87f44d Revert "[libc] Better IntegerToString API"
This reverts commit 910cc05aae.
2023-08-08 20:52:50 +00:00
Guillaume Chatelet
910cc05aae [libc] Better IntegerToString API
This patch is an alternative to D155902. It provides the following benefits:
 - No buffer manual allocation and error handling for the general case
 - More flexible API : width specifier, sign and prefix handling
 - Simpler code

The more flexible API removes the need for manually tweaking the buffer afterwards, and so prevents relying on implementation details of IntegerToString.

Reviewed By: michaelrj, jhuber6

Differential Revision: https://reviews.llvm.org/D156981
2023-08-08 20:39:13 +00:00
Guillaume Chatelet
0abce1e4a5
[libc] add <limits> specialization for signed char 2023-08-08 17:04:55 +02:00
Joseph Huber
e74281a3c3 [libc] Allow NVPTX to use aliases
Summrary:
Following D156014 we can now use aliases for NVPTX, removing this source
of divergence. We require at least +ptx63 and at least sm_30 for
`.alias` but this is already within what we build for with `libc`
support.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D157323
2023-08-08 08:59:35 -05:00
Guillaume Chatelet
575310330b [libc][doc] Update macros documentation
Update documentaiton now that macros are laid out in a more structured way.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D143911
2023-08-08 08:02:30 +00:00
Vitaly Buka
9abc1e080d [test][libc] Fix aligned_alloc argument
Size must be multiple of Alignment.

Reviewed By: gchatelet

Differential Revision: https://reviews.llvm.org/D157247
2023-08-07 16:36:20 -07:00
Michael Jones
f0a3954ef1 [libc][cleanup] Fix most conversion warnings
This patch is large, but is almost entirely just adding casts to calls
to syscall_impl. Much of the work was done programatically, with human
checking when the syntax or types got confusing.

Reviewed By: mcgrathr

Differential Revision: https://reviews.llvm.org/D156950
2023-08-07 15:03:01 -07:00
Michael Jones
f6ba352988 [libc] Add nullptr check option to printf %s
Some printf implementations perform a null check on pointers passed to
%s. While that's not in the standard, this patch adds it as an option
for compatibility. It also puts a similar check in %n behind the same
flag.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D156923
2023-08-07 14:47:09 -07:00
Roland McGrath
019a477c88 [libc] Clean up required LIBC_INLINE uses in src/string
This was generated using clang-tidy and clang-apply-replacements,
on src/string/*.cpp for just the llvmlibc-inline-function-decl
check, after applying https://reviews.llvm.org/D157164, and then
some manual fixup.

Reviewed By: abrachet

Differential Revision: https://reviews.llvm.org/D157169
2023-08-07 12:21:22 -07:00
Michael Jones
16d5c24226 [libc] Add v variants of printf functions
The v variants of the printf functions take their variadic arguments as
a va_list instead of as individual arguments. They are otherwise
identical to the corresponding printf variants. This patch adds them
(vprintf, vfprintf, vsprintf, and vsnprintf) as well as tests.

Reviewed By: phosek

Differential Revision: https://reviews.llvm.org/D157138
2023-08-04 14:50:24 -07:00
Guillaume Chatelet
cdbc3ab7d6 [libc] Add support for cpp::make_signed 2023-08-03 13:45:04 +00:00
Mikhail R. Gadelha
29dec35212 [libc] NFC: Fix build on systems that don't have linux/time_types.h
This broke some bots that don't have linux/time_types.h available
(libc-x86_64-debian-*).

The header is needed because of __kernel_timespec, and since this is
only needed when SYS_sched_rr_get_interval_time64 is available, guarding
the include should fix the broken bot.
2023-08-03 10:30:21 -03:00
Guillaume Chatelet
51f91e1045 [libc] Add string construct/assign from string_view 2023-08-03 13:25:53 +00:00
Mikhail R. Gadelha
c9783d2bda [libc] Add support to compile some syscalls on 32 bit platform
This patch adds a bunch of ifdefs to handle the 32 bit versions of
some syscalls, which often only append a 64 to the name of the syscall
(with exception of SYS_lseek -> SYS_llseek and SYS_futex ->
SYS_futex_time64)

This patch also tries to handle cases where wait4 is not available
(as in riscv32): to implement wait, wait4 and waitpid when wait4 is
not available, we check for alternative wait calls and ultimately rely
on waitid to implement them all.

In riscv32, only waitid is available, so we need it to support this
platform.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D148371
2023-08-03 10:08:01 -03:00
Roland McGrath
cd328c10ad [libc] Use ASSERT_DEATH for EXPECT_DEATH under Fuchsia zxtest
The Fuchsia zxtest library has ASSERT_DEATH but not EXPECT_DEATH.
The latter may be added in the future, but for now just use the
former as substitute.

Reviewed By: abrachet

Differential Revision: https://reviews.llvm.org/D156940
2023-08-02 17:57:44 -07:00
Michael Jones
ad844632b9 [libc] Support underscores in NaN char sequences
Other libc implementations support underscores in NaN(n-char-sequence)
strings. Us not supporting that is causing fuzz failures, so this patch
solves the problem.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D156927
2023-08-02 13:02:47 -07:00
Mikhail R. Gadelha
44bf4c8944 [libc] Fix float to string conversion in 32-bit systems
In 32-bit systems, sizeof(size_t) is 4, so we fail to build an 128-bit
integer in mul_shift_mod_1e9, which ends up ignoring the top bits in the
mantissa.

This patch fixes the issue by calling the Uint constructor directly. If
it's a system that supports 128-bit integers, the constructor that takes
a value will be called, if the system doesn't support 128-bit integers
(like rv32), mantissa is already a UInt.

Reviewed By: lntue, michaelrj

Differential Revision: https://reviews.llvm.org/D156813
2023-08-02 09:50:45 -03:00
Joseph Huber
a82b154eb6 [libc] Disable nextafter tests for NVPTX
Summary:
These tests pass just fine on my local system, but the buildbot doesn't
like it. Disable these until we can figure out an alternative.
2023-08-01 16:52:50 -05:00
Anton Rydahl
53f5bfdb58 [libc][libm][GPU] Populating 'libmgpu.a' for math on the GPU
This commit populates `libmgpu.a` with wrappers for the following built-ins
- modf, modff
- nearbyint, nearbyintf
- remainder, remainderf
- remquo, remquof
- rint, rintf
- scalbn, scalbnf
- sqrt, sqrtf
- tan, tanf
- tanh, tanhf
- trunc, truncf
and wrappers the following vendor implementations
- nextafter, nextafterf
- sincos, sincosf
- sinh, sinhf
- sinf
- tan, tanf
- tanh, tanhf

Reviewed By: jhuber6

Differential Revision: https://reviews.llvm.org/D153395
2023-08-01 13:34:43 -07:00
Michael Jones
15994529e0 [libc][NFC] Fix str_to_float and uint warnings
More Wconversion and Wno-sign-conversion warning fixes.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D156812
2023-08-01 11:08:10 -07:00
Mikhail R. Gadelha
943d194fd9 [libc] Fix sched_getscheduler return value
This patch fixes the return time for sched_getscheduler which was set to
always zero. The syscall documentation, however, defines:

On success, sched_getscheduler() returns the policy for the thread (a
nonnegative integer).

I also changed the return type for sched_setscheduler, but this change
didn't impact and test case.

This patch also removes the duplicated code from param_and_scheduler_test.cpp
and adds SCHED_BATCH and SCHED_IDLE to the tests.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D156700
2023-08-01 14:26:41 -03:00
Joseph Huber
3926feb84e [libc] Add basic wrappers for the backend address spaces
The GPU makes use of different address spaces. We generally work with
global memory, thread private memory, and thread shared memory. This
patch simply adds a few preliminary wrappers to map these concepts to
the numerical values the backend uses. Obviously casts between these
will need to be checked by the user.

Reviewed By: arsenm

Differential Revision: https://reviews.llvm.org/D156731
2023-08-01 07:41:10 -05:00
Roland McGrath
0ed4b17707 [libc] Quiet initializer warnings in getopt
This prevents -Wmissing-braces warnings.

Reviewed By: michaelrj, Caslyn

Differential Revision: https://reviews.llvm.org/D156629
2023-07-31 16:50:40 -07:00
Michael Jones
e9bdf4afa0 [libc][NFC] clean up type warnings in printf
In preparation for https://reviews.llvm.org/D156630 this patch cleans up
all integer size and sign conversion warnings in printf.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D156723
2023-07-31 13:19:34 -07:00
Joseph Huber
9ffde19d11 [libc] Add PAUSE instruction for the RPC spin loop
The other architectures use a brief sleep to defer work during this spin
loop that checks the RPC mailboxes. This patch adds one for x64 to
improve usage when running the server.

Reviewed By: tianshilei1992

Differential Revision: https://reviews.llvm.org/D156566
2023-07-28 18:09:01 -05:00
Michael Jones
63f8922f49 [libc] Fix printf g conversion with high precision
The number of trailing zeroes was being calculated incorrectly. It was
assuming that it could add all of the implicit leading zeroes in the
final block, not accounting for the number of digits actually reqested
by the precision.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D156489
2023-07-28 14:07:00 -07:00
Alfred Persson Forsberg
fe9c3c7868 [libc] _INCLUDE_SCUDO: check for compiler-rt in enabled RUNTIMES too
Previously including SCUDO in a libc build with runtimes/ as root was
not possible since this code only checked for compiler-rt enabled via
LLVM_ENABLED_PROJECTS.

Reviewed By: thesamesam

Differential Revision: https://reviews.llvm.org/D156388
2023-07-27 05:11:54 +01:00
Joseph Huber
334bbc0d67 [libc] Add support for the 'fread' function on the GPU
This patch adds support for `fread` on the GPU via the RPC mechanism.
Here we simply pass the size of the read to the server and then copy it
back to the client via the RPC channel. This should allow us to do the
basic operations on files now. This will obviously be slow for large
sizes due ot the number of RPC calls involved, this could be optimized
further by having a special RPC call that can initiate a memcpy between
the two pointers.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D155121
2023-07-26 13:51:35 -05:00
Michael Jones
91eb99b841 [libc][NFC] fix sprintf test on 32 bit systems
The expected number for the max ptrdiff value was expected to be exactly
4294967296 (2**32) for 32 bit systems, when it should be
4294967295 (2**32 - 1). This also adds a second test to check for this
case on non-32 bit systems.

Reviewed By: lntue, mikhail.ramalho

Differential Revision: https://reviews.llvm.org/D156257
2023-07-26 11:33:53 -07:00
Joseph Huber
be9a4926d2 [libc] Disable ilogb functions on NVPTX
Summary:
These fail tests, disbale them until we can figure out how to get them
passing.
2023-07-26 12:59:15 -05:00
Joseph Huber
a42c1f8d97 [libc][Obvious] Fix use of fwrite in the RPC server
Summary:
The RPC server used the size field which meant we didn't get the correct
return value for partial reads. We fix that here.
2023-07-26 11:13:38 -05:00
Joseph Huber
d1417f431f [libc] Fix missing bitcode flags passed to GPU vendor math
Summary:
A previous patch missed adding these to all the definitions.
2023-07-26 09:53:38 -05:00
Joseph Huber
b06617f1ec [libc] Fix GPU tests failing after recent changes
Summray:
We landed some extra math support, which is apparently broken on the
max / min functions. the `mod` functions cannot be tested as they use
`std::limits` which don't exist in a freestanding environment. Also the
`blockstore` test seems to be broken. We will need to fix these in the
future but for now we need something in a workable state.

Reviewed By: jplehr

Differential Revision: https://reviews.llvm.org/D156329
2023-07-26 09:06:19 -05:00
Ethan Luis McDonough
546c9b3f6a
[libc] Add math functions to AMD/NVPTX libm
Related to D152486.  The following functions are included in this revision: `acosf`, `acoshf`, `asinf`, `asinhf`, `atanf`, `atanhf`, `ceil`, `ceilf`, `copysign`, `copysignf`, `cos`, `cosf`, `cosh`, `coshf`, `exp10f`, `exp2f`, `expf`, `expm1f`, `fabs`, `fabsf`, `fdim`, `fdimf`, `floor`, `floorf`, `fma`, `fmaf`, `fmax`, `fmaxf`, `fmin`, `fminf`, `fmod`, `fmodf`, `frexp`, `frexpf`, `hypot`, `hypotf`, `ilogb`, `ilogbf`, `ldexp`, `ldexpf`, `llrint`, `llrintf`, `llround`, `llroundf`, `pow`, and `powf`.

Reviewed By: jhuber6

Differential Revision: https://reviews.llvm.org/D152603
2023-07-26 03:02:24 -05:00
Alfred Persson Forsberg
c1ce7c8341 [libc] pthread.h.def: add PTHREAD_MUTEX_INITIALIZER
Adds PTHREAD_MUTEX_INITIALIZER for compiler-rt's builtins/emutls.c

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D156276
2023-07-25 16:47:15 -07:00
Michael Jones
49eb1aed89 [libc] Add back report_assertion_failure
It's necessary for the assert_fail function, so it needs to stay in for
the moment.

Reviewed By: alfredfo

Differential Revision: https://reviews.llvm.org/D156275
2023-07-25 16:34:53 -07:00
Michael Jones
65fe1ac30a [libc][NFC] Simplify assert message generation
Previously displaying a failed assert would involve a runtime integer to
string conversion. This patch changes that to be a compile time string
conversion.

This was inspired by a comment by JonChesterfield on https://reviews.llvm.org/D155899

Reviewed By: lntue, sivachandra, JonChesterfield

Differential Revision: https://reviews.llvm.org/D156168
2023-07-25 11:45:45 -07:00
Joseph Huber
7c8a52f90c [libc][Obvious] Fix AMDGPU control constant for vendor sqrt
Summary:
This is supposed to be enabled to say that we want correct sqrt by
default.
2023-07-25 07:59:23 -05:00