151 Commits

Author SHA1 Message Date
Krishna Pandey
550dbec03a
[libc][math][c++23] Add {,u}fromfp{,x}bf16 math functions (#153992)
This PR adds the following basic math functions for BFloat16 type along
with the tests:
- fromfpbf16
- fromfpxbf16
- ufromfpbf16
- ufromfpxbf16

---------

Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-08-19 22:19:03 +05:30
Krishna Pandey
41c9510d72
[libc][math][c++23] Add bf16fma{,f,l,f128} math functions (#153231)
This PR adds the following basic math functions for BFloat16 type along
with the tests:
- bf16fma
- bf16fmaf
- bf16fmal
- bf16fmaf128

---------

Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-08-13 23:26:15 +05:30
Krishna Pandey
c819c246f3
[libc][math][c++23] Add bf16div{,f,l,f128} math functions (#153191)
This PR adds the following basic math functions for BFloat16 type along
with the tests:
- bf16div
- bf16divf
- bf16divl
- bf16divf128

---------

Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-08-12 21:46:22 +05:30
Krishna Pandey
8c5e9399f6
[libc][math][c++23] Add f{max,min}imum{,_mag,_mag_num,_num}bf16 math functions (#152881)
This PR adds the following basic math functions for BFloat16 type along
with the tests:
- fmaximumbf16
- fmaximum_magbf16
- fmaximum_mag_numbf16
- fmaximum_numbf16
- fminimumbf16
- fminimum_magbf16
- fminimum_mag_numbf16
- fminimum_numbf16

---------

Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-08-12 20:37:31 +05:30
Krishna Pandey
628c0e33e4
[libc][math][c++23] Add bf16mul{,f,l,f128} math functions (#152847)
This PR adds the following basic math functions for BFloat16 type along
with the tests:
- bf16mul
- bf16mulf
- bf16mull
- bf16mulf128

---------

Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-08-10 21:38:27 -04:00
Krishna Pandey
246f92324f
[libc][math][c++23] Add f{max,min}bf16 math functions (#152782)
Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-08-08 17:54:02 -04:00
Krishna Pandey
10088b64ef
[libc][math] Update entrypoints for bf16{add,sub}{,f,l,f128} math functions (#152784)
Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-08-08 17:06:48 -04:00
Krishna Pandey
15a705dc93
[libc][math][c++23] Add {ceil,floor,round,roundeven,trunc}bf16 math functions (#152352)
This PR implements the following basic math functions for BFloat16 type
along with the tests:
- ceilbf16
- floorbf16
- roundbf16
- roundevenbf16
- truncbf16

---------

Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-08-08 00:15:22 -04:00
Leandro Lacerda
448c88478d
[libc] Enable the acoshf math function on AMD GPUs (#152157)
This patch adds the `acoshf` math function to the AMDGPU build.
2025-08-05 13:33:11 -05:00
Leandro Lacerda
cd19fbad09
[libc] Enable float math functions on the GPU (#151841)
This patch adds the `tanpif` math functions to the GPU build. It also
adds the `cospif` and `sinpif` math functions to the `math.h` header.
2025-08-02 22:13:04 -05:00
William Huynh
82bddc3e64
[libc] Mutex implementation for single-threaded baremetal (#145358)
Part of https://github.com/llvm/llvm-project/issues/145349. Required to
allow `atexit` to work. As part of `HermeticTestUtils.cpp`, there is a
reference to `atexit()`, which eventually instantiates an instance of a
Mutex.

Instead of copying the implementation from
`libc/src/__support/threads/gpu/mutex.h`, we allow platforms to select
an implementation based on configurations, allowing the GPU and
single-threaded baremetal platforms to share an implementation. This can
be configured or overridden.

Later, when the threading API is more complete, we can add an option to
support multithreading (or set it as the default), but having
single-threading (in tandem) is in line with other libraries for
embedded devices.
2025-07-31 12:16:44 +01:00
Krishna Pandey
111edfcab8
[libc][math][c++23] Add fabsbf16 math function (#148398)
This PR implements fabsbf16 math function for BFloat16 type along with
the tests.

---------

Signed-off-by: krishna2803 <kpandey81930@gmail.com>
Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
Co-authored-by: OverMighty <its.overmighty@gmail.com>
2025-07-29 12:19:21 -04:00
lntue
66603dd1f1
[libc][NFC] Add stdint.h proxy header to fix dependency issue with <stdint.h> includes. (#150303)
https://github.com/llvm/llvm-project/issues/149993
2025-07-23 20:19:52 -04:00
Joseph Huber
46c8cc7e51
[libc] Enable all f16 math functions on the GPU (#145813)
Summary:
This patch adds all the new f16 math functions to the GPU build. These
should all pass except exp2m1f16 on AMDGPU for some reason. I'll
investigate that later.
2025-06-25 20:03:40 -05:00
Joseph Huber
525726a520
[libc] Cleanup unimplemented math functions (#143173)
Summary:
This patch cleans up the leftoever files that were either implemented or
are still unimplemented stubs.
2025-06-06 12:27:13 -05:00
Mohamed Emad
4840895467
[libc] implement memalignment (#132493)
This patch adds the `memalignment` function to LLVM-libc, following its
description in [WG14 N3220,
§7.24.2.1](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3220.pdf#page=387).

- [x] Add the implementation of `memalignment` in
[`/src/stdlib`](https://github.com/llvm/llvm-project/tree/main/libc/src/stdlib)
- [x] Add tests for `memalignment` in
[`/test/src/stdlib`](https://github.com/llvm/llvm-project/tree/main/libc/test/src/stdlib)
- [x] Add `memalignment` to
[`entrypoints.txt`](https://github.com/llvm/llvm-project/blob/main/libc/config/linux/x86_64/entrypoints.txt)
for at least x86_64 and whatever you're building on
- [x] Add `memalignment` to
[`include/stdlib.yaml`](https://github.com/llvm/llvm-project/blob/main/libc/include/stdlib.yaml)




Closes #132300

---------

Co-authored-by: Joseph Huber <huberjn@outlook.com>
2025-03-28 16:07:57 -07:00
Joseph Huber
4abe47c6fc
[libc] Enable 'mktime' for the GPU (#133437)
Summary:
This is a dependency on `strftime` which we provide, so we should have
this.
2025-03-28 11:14:51 -05:00
Harrison Hao
445837a363
[libc][math][c23] Add fmaf16 C23 math function. (#130757)
Implementation of fmaf16 function for 16-bit inputs.
2025-03-23 10:48:56 +08:00
Joseph Huber
598e882ee8
[libc] Template the writing mode for the writer class (#111559)
Summary:
Currently we dispatch the writing mode off of a runtime enum passed in
by the constructor. This causes very unfortunate codegen for the GPU
targets where we get worst-case codegen because of the unused function
pointer for `sprintf`. Instead, this patch moves all of this to a
template so it can be masked out. This results in no dynamic stack and
uses 60 VGPRs instead of 117. It also compiles about 5x as fast.
2025-03-12 13:51:44 -05:00
Joseph Huber
6b3e7657cf
[libc] Enable 'strftime' for the GPU targets (#128220)
Summary:
These should allow us to build with locale support for libcxx.
2025-02-21 16:29:15 -06:00
Nick Desaulniers
631a6e0004
[libc][wchar] implement wcslen (#124150)
Update string_utils' string_length to work with char* or wchar_t*, so that it
may be reusable when implementing wmemchr, wcspbrk, wcsrchr, wcsstr.

Link: #121183
Link: #124027

Co-authored-by: Nick Desaulniers <ndesaulniers@google.com>

---------

Co-authored-by: Tristan Ross <tristan.ross@midstall.com>
2025-01-23 13:33:04 -08:00
Joseph Huber
f4bab06c97
[libc] Split AMDGPU and NVPTX configs into separate folders (#120153)
Summary:
This is a holdover from when these targets were merged. They're
basically the same but there's no reason they should be treated as
identical. I think we will live with a little duplication.
2025-01-06 13:49:19 -06:00
Joseph Huber
3bbd53ce97
[libc] Remove old RPC host call extension for GPU (#120800)
Summary:
This was originally a hacked together function that served to just
implement some features for OpenMP. That has been moved into OpenMP
itself now that we have exported RPC properly. This can now be deleted.
2024-12-20 19:34:05 -06:00
Joseph Huber
958de20b30
[libc] Enable 'timespec_get' for the GPU build (#120304)
Summary:
Currently fails to build libc++ because this is missing.
2024-12-17 15:31:07 -06:00
Nick Desaulniers
431ea2d076
[libc] move bcmp, bzero, bcopy, index, rindex, strcasecmp, strncasecmp to strings.h (#118899)
docgen relies on the convention that we have a file foo.cpp in
libc/src/\<header\>/. Because the above functions weren't in libc/src/strings/
but rather libc/src/string/, docgen could not find that we had implemented
these.

Rather than add special carve outs to docgen, let's fix up our sources for
these 7 functions to stick with the existing conventions the rest of the
codebase follows.

Link: #118860
Fixes: #118875
2024-12-10 08:58:45 -08:00
Nick Desaulniers
e0ae7793fc
[libc] delete hdrgen (#117220)
Thanks to the effort of @RoseZhang03 and @aaryanshukla under the
guidance of
@michaelrj-google and @amykhuang, we now have newhdrgen and no longer
have a
dependency on TableGen and thus LLVM in order to start bootstrapping a
full
build.

This PR removes:
- LIBC_HDRGEN_EXE; the in tree newhdrgen is the only hdrgen that can be
used.
- LIBC_USE_NEW_HEADER_GEN; newhdrgen is the default and only option.
- LIBC_HDRGEN_ONLY; there is no need to have a distinct build step for
old
  hdrgen.
- libc-api-test and libc-api-test-tidy build targets.
- Deletes all .td files.

It does not rename newhdrgen to just hdrgen. Will follow up with a
distinct PR
for that.

Link: #117209
Link: #117254
Fixes: #117208
2024-12-03 12:34:26 -08:00
OverMighty
d97f6d1ae9
[libc][math][c23] Add sqrtf16 C23 math function (#112406)
Part of #95250.
2024-10-19 01:41:52 +02:00
OverMighty
69d3a44ede
[libc][math][c23] Add log10f16 C23 math function (#106091)
Part of #95250.
2024-10-19 01:40:40 +02:00
OverMighty
6d347fdfbd
[libc][math][c23] Add log2f16 C23 math function (#106084)
Part of #95250.
2024-10-19 01:10:32 +02:00
OverMighty
65cf7afb6d
[libc][math][c23] Add logf16 C23 math function (#106072)
Part of #95250.
2024-10-18 22:35:12 +02:00
OverMighty
fdd7c0353f
[libc][math][c23] Add tanhf16 C23 math function (#106006)
Part of #95250.
2024-10-18 14:22:45 +02:00
OverMighty
ed3d051782
[libc][math][c23] Add sinhf16 and coshf16 C23 math functions (#105947)
Part of #95250.
2024-10-17 20:44:23 +02:00
OverMighty
95c24cb9de
[libc][math][c23] Add exp10m1f16 C23 math function (#105706)
Part of #95250.
2024-10-16 16:33:13 +02:00
Joseph Huber
fe6a3d46aa
[libc] Implement the 'rename' function on the GPU (#109814)
Summary:
Straightforward implementation like the other `stdio.h` functions.
2024-09-24 09:32:42 -07:00
Joseph Huber
3bbe0f90f3
[libc] Add 'strings.h' header on the GPU (#109661)
Summary:
These are GNU extensions but still show up, the entrypoints were enabled
but we weren't emitting the header so they couldn't be used.
2024-09-23 14:19:33 -07:00
Joseph Huber
16d11e26f3
[libc] Add GPU support for the 'system' function (#109687)
Summary:
This function can easily be implemented by forwarding it to the host
process. This shows up in a few places that we might want to test the
GPU so it should be provided. Also, I find the idea of the GPU
offloading work to the CPU via `system` very funny.
2024-09-23 14:04:28 -07:00
Michael Jones
f009f72df5
[libc] Add printf strerror conversion (%m) (#105891)
This patch adds the %m conversion to printf, which prints the
strerror(errno). Explanation of why is below, this patch also updates
the docs, tests, and build system to accomodate this.

The standard for syslog in posix specifies it uses the same format as
printf, but adds %m which prints the error message string for the
current value of errno. For ease of implementation, it's standard
practice for libc implementers to just add %m to printf instead of
creating a separate parser for syslog.
2024-09-19 10:48:08 -07:00
Joseph Huber
5c019bdb7a
[libc] Add support for 'string.h' locale variants (#105719)
Summary:
This adds the locale variants of the string functions. As previously,
these do not use the locale information at all and simply copy the
non-locale version which expects the "C" locale.
2024-08-29 14:20:15 -05:00
Joseph Huber
a87105121d
[libc] Implement locale variants for 'stdlib.h' functions (#105718)
Summary:
This provides the `_l` variants for the `stdlib.h` functions. These are
just copies of the same entrypoint and don't do anything with the locale
information.
2024-08-29 14:18:37 -05:00
Joseph Huber
439d7de14d [libc] Disable failing scanf test on AMDGPU temporarily
Summary:
This test currently fails in the `amdgpu-attributor` pass. I haven't
figured out anything beyond that yet as it's difficult to reduce.
2024-08-28 07:04:15 -05:00
Joseph Huber
856dadb33c [libc] Add ctype.h locale variants (#102711)
Summary:
This patch adds all the libc ctype variants. These ignore the locale
ingormation completely, so they're pretty much just stubs. Because these
use locale information, which is system scope, we do not enable building
them outisde of full build mode.
2024-08-22 13:51:54 -05:00
Joseph Huber
78d8ab2ab9
[libc] Initial support for 'locale.h' in the LLVM libc (#102689)
Summary:
This patch adds the macros and entrypoints associated with the
`locale.h` entrypoints.  These are mostly stubs, as we (for now and the
forseeable future) only expect to support the C and maybe C.UTF-8
locales in the LLVM libc.
2024-08-22 12:58:46 -05:00
Joseph Huber
2f4232db0b Revert " [libc] Add ctype.h locale variants (#102711)"
This reverts commit 8f005f8306dc52577b3b9482d271fb463f0152a5.
2024-08-22 12:45:16 -05:00
Joseph Huber
8f005f8306
[libc] Add ctype.h locale variants (#102711)
Summary:
This patch adds all the libc ctype variants. These ignore the locale
ingormation completely, so they're pretty much just stubs. Because these
use locale information, which is system scope, we do not enable building
them outisde of full build mode.
2024-08-22 12:41:20 -05:00
Joseph Huber
6b98a72365
[libc] Add scanf support to the GPU build (#104812)
Summary:
The `scanf` function has a "system file" configuration, which is pretty
much what the GPU implementation does at this point. So we should be
able to use it in much the same way.
2024-08-21 18:02:04 -05:00
Joseph Huber
bd9f2c2ba0
[libc] Add missing math definitions for round and scal for GPU (#104636)
Summary:
These can be enabled
2024-08-16 16:27:03 -05:00
Joseph Huber
55aa4ea1c7
[libc] Add definition for atan2l on 64-bit long double platforms (#104489)
Summary:
This just adds `atan2l` for platforms that can implement it as an alias
to `atan2`.
2024-08-15 14:59:28 -05:00
Joseph Huber
dc2f39e96c
[libc] Enable all supported math functions on the GPU (#102563)
Summary:
Simply copies the x64 versions to the GPU directory. Ignoring f128 for
now, but adding long double entrypoints which are identical to `double`
on the target.
2024-08-12 13:12:44 -05:00
aaryanshukla
d0fe470fd2
[libc][math] Add scalbln{,f,l,f128} math functions (#102219)
Co-authored-by: OverMighty <its.overmighty@gmail.com>
2024-08-08 14:33:50 -07:00
Joseph Huber
1a92cc5a0a
[libc] Implement 'getenv' on the GPU target (#102376)
Summary:
This patch implements 'getenv'. I was torn on how to implement this,
since realistically we only have access to this environment pointer in
the "loader" interface. An alternative would be to use an RPC call every
time, but I think that's overkill for what this will be used for. A
better solution is just to emit a common `DataEnvironment` that contains
all of the host visible resources to initialize. Right now this is the
`env_ptr`, `clock_freq`, and `rpc_client`.

I did this by making the `app.h` interface that Linux uses more general,
could possibly move that into a separate patch, but I figured it's
easier to see with the usage.
2024-08-08 06:45:42 -05:00