3123 Commits

Author SHA1 Message Date
Petr Hosek
3584a82333
[libc] Only use COMPILER_RESOURCE_DIR if available (#97465)
This avoids build error when COMPILER_RESOURCE_DIR is unset.
2024-07-02 12:48:48 -07:00
Petr Hosek
b8bbc57b68
[libc] Use -nostdlibinc in the full build mode (#97461)
This avoids accidentally including system headers.
2024-07-02 12:34:06 -07:00
OverMighty
12a1e6dd12
[libc][math][c23] Add f16{add,sub}f C23 math functions (#96787)
Part of #93566.
2024-07-02 09:16:12 -04:00
Job Henandez Lara
6f60d2b807
[libc] Add mpfr tests for fmul. (#97376)
Fixes https://github.com/llvm/llvm-project/issues/94834
2024-07-02 00:38:15 -04:00
aaryanshukla
03e46475f5
[libc] implemented add_function to yaml hdrgen (#97079)
users can now input a new function in the CLI: the yaml, and .h will
be updated instantly
tested on different cases and does not change the yaml format in anyway
except decreasing extra spaces if present
2024-07-01 15:43:59 -07:00
Hendrik Hübner
ea93c538c7
[libc][math][c23] Implemented sinpif function correctly rounded for all rounding modes. (#97149)
This implements the sinpif function. An exhaustive test shows it's
correct for all rounding modes.

Issue:  #94895
2024-07-01 16:38:03 -04:00
OverMighty
a3f700a3d6
[libc][math][c23] Add MPFR unit test for f16sqrtf (#97062) 2024-07-01 08:46:29 -04:00
OverMighty
44a2589cfc
[libc][math] Add MPFR unit tests for nearbyint{,f,l,f16} (#94479) 2024-07-01 08:45:36 -04:00
Joseph Huber
3c64a98180
[libc] Partially implement 'errno' on the GPU (#97107)
Summary:
The `errno` variable is expected to be `thread_local` by the standard.
However, the GPU targets do not support `thread_local` and implementing
that would be a large endeavor. Because of that, we previously didn't
provide the `errno` symbol at all. However, to build some programs we at
least need to be able to link against `errno`. Many things that would
normally set `errno` completely ignore it currently (i.e. stdio) but
some programs still need to be able to link against correct C programs.

For this purpose this patch exports the `errno` symbol as a simple
global. Internally, this will be updated atomically so it's at least not
racy. Externally, this will be on the user. I've updated the
documentation to state as such. This is required to get `libc++` to
build.
2024-07-01 06:30:15 -05:00
Joseph Huber
ec0e6ef09b
[libc] Implement the 'remove' function on the GPU (#97096)
Summary:
Straightforward RPC implementation of the `remove` function for the GPU.
Copies over the string and calls `remove` on it, passing the result
back. This is required for building some `libc++` functionality.
2024-07-01 06:29:48 -05:00
OverMighty
6c1c451b86
[libc][math][c23] Add f16sqrt{,l,f128} C23 math functions (#96642)
Part of #95250.
2024-06-30 19:20:39 -04:00
OverMighty
2a6e32ea34
[libc][math][c23] Temporarily disable f16div{l,f128} on AArch64 (#97182)
Due to Clang 11 backend error ("Unsupported library call operation!").

See Buildbot failures:

- https://lab.llvm.org/buildbot/#/builders/104/builds/1105
- https://lab.llvm.org/buildbot/#/builders/71/builds/1100
2024-06-29 19:02:10 -04:00
OverMighty
56ef6a2eb2
[libc][math][c23] Add f16div{,l,f128} C23 math functions (#97054)
Part of #93566.
2024-06-29 18:48:12 -04:00
lntue
b8450d4ec8
[libc] Fix incomplete sincos_test. (#97174) 2024-06-29 17:21:00 -04:00
RoseZhang03
371e924605
[libc] added rest of yaml files for new headergen (#96977)
Added yaml files containing functions from only one standard.
Also added one combined standard yaml file (errno.yaml).
assert.yaml is still work in progress.
2024-06-28 22:42:35 +00:00
Izaak Schroeder
74852bfa4c
[libc]: fix missing linux/error-number-macros.h (#97101)
The headers installation previously missed platform-specific number
macros, and this fixes that. From discussion on LLVM discord with
`michaelrj` – ccing @michaelrj-google who hopefully is the same person 😅

N.B. I have tested this manually in my Linux Dockerfile and it appears
to do the right thing; I haven't done much more than that.
2024-06-28 14:55:25 -05:00
Michael Jones
808e0f1c46
[libc] remove include_file headergen usage (#96970)
Previously headergen had a mechanism to copy the contents of one file
inot another. This wasn't ever used properly, and isn't supported by the
new headergen design. We will investigate better ways to support
different syscall definitions in future.
2024-06-28 10:27:32 -07:00
aaryanshukla
e17b17d86e
[libc] added yaml_combined files, frontend for new headergen (#96833)
These are the yaml files that have combined functions from different
libraries
Rose will be adding the rest of the yaml in the next pr
Missing assert.yaml -- work in progress
2024-06-28 08:59:08 -07:00
OverMighty
7f68675f64
[libc] Fix compilation error on targets without 128-bit int types (#97039)
See Buildbot failures:

- https://lab.llvm.org/buildbot/#/builders/11/builds/743
- https://lab.llvm.org/buildbot/#/builders/182/builds/362
2024-06-28 07:35:31 -04:00
OverMighty
7a03666401
[libc] Fix compilation errors that occur when building with GCC (#96976) 2024-06-27 15:05:43 -07:00
Petr Hosek
6b55ec1198
[libc] Sort entrypoints alphabetically (#96955)
This makes it easier to diff the different configurations.
2024-06-27 14:27:14 -07:00
OverMighty
aa8409fdca
[libc][math][c23] Temporarily disable f16fma{,l,f128} on AArch64 (#96952)
See Buildbot failures:

- https://lab.llvm.org/buildbot/#/builders/104/builds/936
- https://lab.llvm.org/buildbot/#/builders/71/builds/932
- https://lab.llvm.org/buildbot/#/builders/131/builds/913
2024-06-27 15:08:42 -04:00
OverMighty
e34dbb127a
[libc][math][c23] Add f16fma{,l,f128} C23 math function (#96711)
Part of #93566.
2024-06-27 14:44:19 -04:00
Petr Hosek
aae8e5cb74
[libc] Include additional math functions in baremetal config (#96926)
These are all supported on arm32 and riscv32.
2024-06-27 11:34:32 -07:00
Schrodinger ZHU Yifan
6d61d83736
[libc] inline fast path of callonce (#96226)
Split from #91572

---------

Co-authored-by: Nick Desaulniers (paternity leave) <nickdesaulniers@users.noreply.github.com>
2024-06-27 08:48:13 -07:00
lntue
4080f174ab
[libc][math] Implement double precision sincos correctly rounded to all rounding modes. (#96719)
Sharing the same algorithm as double precision sin:
https://github.com/llvm/llvm-project/pull/95736 and cos:
https://github.com/llvm/llvm-project/pull/96591
2024-06-27 10:15:22 -04:00
aaryanshukla
1fa9f506d3
[libc] added newhdrgen python script and class file (#96671)
python script uses yaml and classes to generate c headers
header.py is only the main class file, the rest will be in another pr
more files to be added in multiple prs
2024-06-26 16:37:25 -07:00
Joseph Huber
f23a5f08f4
[libc] Remove atomic alignment diagnostics globally (#96803)
Summary:
These warnings mean that it will lower to a libcall. Previously we just
disabled it locally, which didn't work with GCC. This patch does it
globally in the compiler options if the compiler is clang.
2024-06-26 18:12:46 -05:00
jameshu15869
02b57dedb7
[libc] NVPTX Profiling (#92009)
PR for adding microbenchmarking infrastructure for NVPTX. `nvlink`
cannot perform LTO, so we cannot inline `libc` functions and this
function call overhead is not adjusted for during microbenchmarking.
2024-06-26 16:38:39 -05:00
RoseZhang03
57d3d07050
[libc] added newhdrgen class implementation (#96710)
Added a class representation of a libc header file, allowing for easier
conversion from YAML to .h file output.

Classes include:
- Function (representing function headers)
- Include (representing various include statements found on a header
  file)
- Macro (representing macro definitions)
- Enumeration (representing enum definitions)
- Type (representing include statements for NamedTypes)
- Object (representing ObjectSpec defintitions)
2024-06-26 20:06:21 +00:00
Schrodinger ZHU Yifan
133492fe18
[libc] add proxy header for struct_sigaction (#96224) 2024-06-26 12:46:15 -07:00
Xu Zhang
7c4fc9ccc0
[libc][fcntl] Simplify the handling of the return value from syscall … (#96325)
Fixes #95570
2024-06-26 09:53:20 -07:00
Joseph Huber
e1015ae55d
[libc][docs] List rand and srand as supported on the GPU (#96757)
Summary:
I initially didn't report these as supported because they didn't provide
expected behavior and were very wasteful. The recent patch moved them to
a lock-free atomic implementation so they can now actually be used.
2024-06-26 11:45:47 -05:00
Joseph Huber
d0527ab697
[libc] Fix Fuscia builder failing on atomic warnings (#96791)
Summary:
This function uses atomics now, which emit warnings on some platforms
that don't support full lock-free atomics. These aren't specifically
wrong, and in the future we could investigate a libc configuration
specialized for single-threaded microprocessors, but for now we should
get the bot running again.
2024-06-26 11:24:48 -05:00
Joseph Huber
86860be288
[libc] Make 'rand()' thread-safe using atomics instead of TLS (#96692)
Summary:
Currently, we implement the `rand` function using thread-local storage.
This is somewhat problematic because not every target supports TLS, and
even more do not support non-zero initializers on TLS.

The C standard states that the `rand()` function need not be thread,
safe. However, many implementations provide thread-safety anyway.
There's some confusing language in the 'rationale' section of
https://pubs.opengroup.org/onlinepubs/9699919799/functions/rand.html,
but given that `glibc` uses a lock, I think we should make this thread
safe as well. it mentions that threaded behavior is desirable and can be
done in the two ways:

1. A single per-process sequence of pseudo-random numbers that is shared
by all threads that call rand()
2. A different sequence of pseudo-random numbers for each thread that
calls rand()

The current implementation is (2.) and this patch moves it to (1.). This
is beneficial for the GPU case and more generic support. The downside is
that it's slightly slower to do these atomic operations, the fast path
will be two atomic reads and an atomic write.
2024-06-26 07:03:28 -05:00
PiJoules
54ca5a800d
[libc][fixedvector] Add const_iterator begin/end (#96714) 2024-06-25 16:33:36 -07:00
Nick Desaulniers (paternity leave)
e214ed9d70
[libc][arm] move setjmp+longjmp to fullbuild-only entrypoints (#96708)
The opaque type jmp_buf should only be tested in fullbuild mode.
2024-06-25 15:35:24 -07:00
lntue
88f80aeb0c
[libc][math] Implement double precision cos correctly rounded to all rounding modes. (#96591)
Sharing the same algorithm as double precision sin:
https://github.com/llvm/llvm-project/pull/95736
2024-06-25 16:51:31 -04:00
OverMighty
ef05b03223
[libc][math][c23] Add MPFR exhaustive test for fmodf16 (#94656) 2024-06-25 16:44:47 -04:00
Nick Desaulniers (paternity leave)
4c87212d63
[libc][thumb] support syscalls from thumb mode (#96558)
r7 is reserved in thumb2 (typically for the frame pointer, as opposed to r11 in
ARM mode), so assigning to a variable with explicit register storage in r7 will
produce an error.

But r7 is where the Linux kernel expects the syscall number to be placed. We
can use a temporary to get the register allocator to pick a temporary, which we
save+restore the previous value of r7 in.

Fixes: #93738
2024-06-25 09:58:50 -07:00
Nick Desaulniers (paternity leave)
dca49d739d
[libc][arm32] define argc type and stack alignment (#96367)
https://github.com/ARM-software/abi-aa/blob/main/aapcs32/aapcs32.rst#6212stack-constraints-at-a-public-interface
mentions that the stack on ARM32 is double word aligned.

Remove confused comments around ArgcType. argc is always an int, passed on the
stack, so we need to store a pointer to it (regardless of ILP32 or LP64).
2024-06-25 09:04:19 -07:00
OverMighty
edbe698ead
[libc][math][c23] Add f16divf C23 math function (#96131)
Part of #93566.
2024-06-25 08:48:28 -04:00
Joseph Huber
6c9916d0d8
[libc] Configure CMAKE_REQUIRED_FLAGS so the GPU can use flag checks (#95424)
Summary:
This patch adds `CMAKE_REQUIRED_FLAGS` for the GPU build so checks like
`check_cxx_compiler_flags` work as expected. This is required because we
need to hack around the potential lack of `nvlink` and `ptxas` for NVPTX
targets and the fact that the AMDGPU target needs `-nogpulib` to avoid
errors on lack of ROCm. This makes a few of the checks pass and also
allows us to just check `-mcpu=native` for architecture detection
instead of finding the tools manually.
2024-06-25 07:02:57 -05:00
Joseph Huber
dc27ff1049 [libc] Disable freelist test on NVPTX temporarily
Summary:
This test fails due to alignment issues, it's likely that it's
misaligned on other targets too and they just don't crash on it.
@PiJoules maybe we should run this with ubsan?
2024-06-24 18:05:00 -05:00
lntue
16903ace18
[libc][math] Implement double precision sin correctly rounded to all rounding modes. (#95736)
- Algorithm:
- Step 1 - Range reduction: for a double precision input `x`, return `k`
and `u` such that
    - k is an integer
    - u = x - k * pi / 128, and |u| < pi/256
- Step 2 - Calculate `sin(u)` and `cos(u)` in double-double using Taylor
polynomials with errors < 2^-70 with FMA or < 2^-66 w/o FMA.
- Step 3 - Calculate `sin(x) = sin(k*pi/128) * cos(u) + cos(k*pi/128) *
sin(u)` using look-up table for `sin(k*pi/128)` and `cos(k*pi/128)`.
- Step 4 - Use Ziv's rounding test to decide if the result is correctly
rounded.
- Step 4' - If the Ziv's rounding test failed, redo step 1-3 using
128-bit precision.
- Currently, without FMA instructions, the large range reduction only
works correctly for the default rounding mode (FE_TONEAREST).
- Provide `LIBC_MATH` flag so that users can set `LIBC_MATH =
LIBC_MATH_SKIP_ACCURATE_PASS` to build the `sin` function without step 4
and 4'.
2024-06-24 17:57:08 -04:00
Nick Desaulniers (paternity leave)
bea7f3d873
[libc][startup] create header for ElfW and use in startup (#96510)
This is necessary for 32b platforms such as ARM and i386.

Link: #94128
2024-06-24 14:37:50 -07:00
Nick Desaulniers (paternity leave)
9eba835dec
[libc][arm] add malloc/free/aligned_alloc to entrypoints (#96516)
Necessary for arm32 cross full build.
2024-06-24 09:51:38 -07:00
lntue
c2735d2d5a
[libc][stdlib] Bring all GPU's alloc/free entrypoints under the same conditional. (#96373) 2024-06-21 23:29:15 -04:00
lntue
38458144bf
[libc][stdlib] Fix skipped libc.src.stdlib.freelist_malloc target for baremetal. (#96372)
Downstream build issue reported:
https://ci.chromium.org/ui/p/fuchsia/builders/toolchain.ci/clang-linux-x64/b8744479865106393873/overview
2024-06-21 22:42:07 -04:00
Nick Desaulniers (paternity leave)
781d5cf32a
[libc][startup] check that we're cross compiling and using LLD (#96357)
We only need to set `--target=` for LLD when cross compiling. This should fix
the host build using BFD or targeting the host.

Fixes: #96342
2024-06-21 14:33:27 -07:00