2571 Commits

Author SHA1 Message Date
Mohamed Emad
40833eea21
Reland "[libc][math][c23] Implement C23 math function asinpif16" (#152690)
#146226 with fixing asinpi MPFR number function and make it work when
mpfr < `4.2.0`
2025-08-18 00:04:47 +03:00
Muhammad Bassiouni
9ddc85f6d5
[libc][math] Refactor coshf implementation to header-only in src/__support/math folder. (#153427)
Part of #147386

in preparation for:
https://discourse.llvm.org/t/rfc-make-clang-builtin-math-functions-constexpr-with-llvm-libc-to-support-c-23-constexpr-math-functions/86450
2025-08-14 17:19:47 +03:00
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
Muhammad Bassiouni
0f6d3ad0fe
[libc][math] Refactor cosf16 implementation to header-only in src/__support/math folder. (#152871)
Part of #147386

in preparation for: https://discourse.llvm.org/t/rfc-make-clang-builtin-math-functions-constexpr-with-llvm-libc-to-support-c-23-constexpr-math-functions/86450
2025-08-13 18:04:35 +03:00
Jin Huang
91de0a2c43
[libc] Refactor libc code to improve readability. (#153308)
The PR is going to improve the readability for the files under
`llvm-project/libc/src/wchar` directory.

---------

Co-authored-by: Jin Huang <jingold@google.com>
2025-08-12 21:41:21 -07:00
Alexey Samsonov
04081caa09
[libc] Remove LIBC_ERRNO_MODE_SYSTEM mode. (#153077)
Use LIBC_ERRNO_MODE_SYSTEM_INLINE instead as the default for the "public
packaging" (i.e. release mode) of an overlay build. The Bazel build has
already switched to use it by default in
5ccc734fa0355f971f8f515457a0bece33ab6642. This should be a safe change,
as LIBC_ERRNO_MODE_SYSTEM_INLINE works a drop-in (but simpler)
LIBC_ERRNO_MODE_SYSTEM replacement. Remove the associated code paths and
config settings.

Fixes issue #143454.
2025-08-12 19:52:40 -07:00
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
Joseph Huber
005895290d
[libc] Simplifiy slab waiting in GPU memory allocator (#152872)
Summary:
This moves the waiting to be done inside of the `try_lock` routine
instead. This makes the logic much simpler since it's just a single loop
on a load. We should have the same effect here, and since we don't care
about this being a generic interface it shouldn't matter that it waits
abit. Still wait free since it's guaranteed to make progress
*eventually*.
2025-08-11 13:11:39 -05:00
Muhammad Bassiouni
200a99073f
[libc][math] Refactor cosf implementation to header-only in src/__support/math folder. (#152069)
Part of #147386

in preparation for: https://discourse.llvm.org/t/rfc-make-clang-builtin-math-functions-constexpr-with-llvm-libc-to-support-c-23-constexpr-math-functions/86450
2025-08-11 21:08:21 +03:00
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
Muhammad Bassiouni
e86c9b6b1b
[libc][math] Refactor cos implementation to header-only in src/__support/math folder. (#151883)
Part of #147386

in preparation for: https://discourse.llvm.org/t/rfc-make-clang-builtin-math-functions-constexpr-with-llvm-libc-to-support-c-23-constexpr-math-functions/86450
2025-08-09 18:51:54 +03: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
Joseph Huber
ca006898b3
[libc] Cache old slabs when allocating GPU memory (#151866)
Summary:
This patch introduces a lock-free stack used to store a fixed number of
slabs. Instead of going directly through RPC memory, we instead can
consult the cache and use that. Currently, this means that ~64 MiB of
memory will remain in-use if the user completely fills the cache.
However, because we always fully destroy the object, the chunk size can
be reset so they can be fully reused.

This greatly improves performance in cases where the user has previously
accessed malloc, lowering the difference between an implementation that
does not free slabs at all and one that does.

We can also skip the expensive zeroing step if the old chunk size was
smaller than the previous one. Smaller chunk sizes need a larger
bitfield, and because we know for a fact that the number of users
remaining in this slab is zero thanks to the reference counting we can
guarantee that the bitfield is all zero like when it was initialized.
2025-08-08 14:28:41 -05:00
Krishna Pandey
1ffb99520d
[libc][math][c++23] Add bf16{add,sub}{,f,l,f128} math functions (#152774)
This PR adds implements following basic math functions for BFloat16 type
along with the tests:
- bf16add
- bf16addf
- bf16addl
- bf16addf128
- bf16sub
- bf16subf
- bf16subl
- bf16subf128

---------

Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-08-08 15:20:24 -04:00
Muhammad Bassiouni
66734f4c3c
[libc][math] Refactor cbrtf implementation to header-only in src/__support/math folder. (#151846)
Part of #147386

in preparation for: https://discourse.llvm.org/t/rfc-make-clang-builtin-math-functions-constexpr-with-llvm-libc-to-support-c-23-constexpr-math-functions/86450
2025-08-08 18:28:50 +03: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
Caslyn Tonelli
b8195e3a8e
[libc] Fix typo and amend restrict qualifier (#152410)
This removes an extraneous ',' in the generated dlfcn header.

This also adds `__restrict` to `dladdr`'s declaration per POSIX. Another
fix is made: the C standard `restrict` keyword is removed from
dlinfo.cpp/dlinfo.h (but note that dlfcn.yaml still annotates
`__restrict` for dlinfo's decl).
2025-08-07 16:45:14 -07:00
Caslyn Tonelli
e1171e6a98
[libc][dlfcn] Remove unused errno dep (#152222)
This removes the errno dep for the stub libdl functions, since there is
no need for it.
2025-08-07 07:48:28 -07:00
Uzair Nawaz
c4846d29cd
[libc] Move CharacterConverter template specialization to cpp file (#152405)
Fixes build errors caused by #152204
2025-08-06 23:32:23 +00:00
Uzair Nawaz
e83abd774a
[libc] Template StringConverter pop function to avoid duplicate code (#152204)
Addressed TODO to template the StringConverter pop functions to have a
single implementation (combine popUTF8 and popUTF32 into a single
templated pop function)
2025-08-06 15:46:41 -07:00
lntue
885ddf4a3a
[libc] Fix constexpr FPUtils rounding_mode.h functions. (#152342) 2025-08-06 22:05:12 +00:00
Michael Jones
503c0908c3
[libc] fix iswalpha signiture and test (#152343)
The iswalpha function is only working for characters in the ascii range
right now, which isn't ideal. Also it was returning a bool when the
function is supposed to return an int.
2025-08-06 11:05:08 -07:00
Krishna Pandey
0e3a17c70d
[libc][math] Fix gcc buildbot failure (#152320)
Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-08-06 11:53:21 -04:00
Schrodinger ZHU Yifan
df0325a3e5
[libc] add getrandom vDSO symbol (#151630) 2025-08-06 10:55:41 -04:00
Krishna Pandey
a4ff76e819
[libc][math][c++23] Implement basic arithmetic operations for BFloat16 (#151228)
This PR implements addition, subtraction, multiplication and division
operations for BFloat16.

---------

Signed-off-by: krishna2803 <kpandey81930@gmail.com>
Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
Co-authored-by: OverMighty <its.overmighty@gmail.com>
2025-08-06 10:42:55 -04:00
William Huynh
0b1639581a
[libc] Change LIBC_THREAD_LOCAL to be dependent on LIBC_THREAD_MODE (#151527)
When single-threaded mode is selected, all instances of the keyword
`LIBC_THREAD_LOCAL` are stubbed out, similar to how it currently works
on the GPU. This allows baremetal builds to avoid using thread_local.

However, libcxx uses shared headers, so we need to be careful there.
Thankfully, there is already an option to disable multithreading in
libcxx, so a flag is added such that single-threaded mode is propagated
down to libc.
2025-08-06 15:04:26 +01:00
Caslyn Tonelli
5a076e3b4d
[libc] Add dladdr to dlfcn.h (#149872)
A initial commit for #97929, this adds a stub implementation for
`dladdr` and includes the definition for the `DL_info` type used as one
of its arguments.

While the `dladdr` implementation relies on dynamic linker support, this
patch will add its prototype in the generated `dlfcn.h` header so that
it can be used by downstream platforms that have their own `dladdr`
implementation.
2025-08-05 15:06:08 -07:00
Caslyn Tonelli
cfd1ee781f
[libc] Add dlinfo + RTLD_DI_* macros to dlfcn.h (#149938)
An initial commit for #149911, this adds a stub implementation for
dlinfo and the enums list of `RTLD_DI_*` values.

While the dlinfo implementation relies on dynamic linker support, this
patch will add its prototype in the generated dlfcn.h header so that it
can be used by downstream platforms that have their own dlinfo
implementation.
2025-08-05 13:34:30 -07:00
sribee8
9a4c6f9b3c
[libc][obvious] Removed mbstate_t include (#152046)
Internal function does not use the external mbstate_t but still had the
include for it.

Co-authored-by: Sriya Pratipati <sriyap@google.com>
2025-08-05 16:36:07 +00:00
Krishna Pandey
52b7b22cfa
[libc][math] Fix division by infinity in fputil::div (#152092)
Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-08-05 07:39:03 -04:00
Krishna Pandey
771d9ab701
[libc][math] Fix subtraction of infinity in fputil::add_or_sub (#152017)
Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-08-04 18:15:40 -04:00
Muhammad Bassiouni
d7f00a9f95
[libc] fix build errors caused by cbrt. (#151879) 2025-08-03 21:27:54 +03:00
Muhammad Bassiouni
003f6ada15
[libc][math] Refactor cbrt implementation to header-only in src/__support/math folder. (#151837)
Part of #147386

in preparation for: https://discourse.llvm.org/t/rfc-make-clang-builtin-math-functions-constexpr-with-llvm-libc-to-support-c-23-constexpr-math-functions/86450
2025-08-03 21:02:53 +03:00
Muhammad Bassiouni
5f8338749a
[libc] fix build errors caused by atanhf16. (#151838) 2025-08-02 23:43:09 +03:00
Muhammad Bassiouni
bb3cd6221b
[libc][math] Refactor atanhf16 implementation to header-only in src/__support/math folder. (#151779)
Part of #147386

in preparation for: https://discourse.llvm.org/t/rfc-make-clang-builtin-math-functions-constexpr-with-llvm-libc-to-support-c-23-constexpr-math-functions/86450
2025-08-02 23:04:02 +03:00
Muhammad Bassiouni
99cd1d8aef
[libc][math] Refactor atanhf implementation to header-only in src/__support/math folder. (#151399)
Part of #147386

in preparation for: https://discourse.llvm.org/t/rfc-make-clang-builtin-math-functions-constexpr-with-llvm-libc-to-support-c-23-constexpr-math-functions/86450
2025-08-02 02:54:13 +03:00
Muhammad Bassiouni
920079b793
[libc][math] Refactor atan2f128 implementation to header-only in src/__support/math folder. (#151012)
Part of #147386

in preparation for: https://discourse.llvm.org/t/rfc-make-clang-builtin-math-functions-constexpr-with-llvm-libc-to-support-c-23-constexpr-math-functions/86450
2025-08-02 00:18:57 +03:00
Aiden Grossman
605f652cba
[libc] Add struct_sched_param proxy header (#151722)
This enables cleaning up the remaining sched.h includes littered around
the code base.
2025-08-01 11:34:06 -07:00
enh-google
b36f05ce48
[libc] Fix wcstok() "subsequent searches" behavior. (#151589)
POSIX says "If no such wide-character code is found, the current token
extends to the end of the wide-character string pointed to by ws1, and
subsequent searches for a token shall return a null pointer", but the
current implementation only returns nullptr the first time. This failed
an existing bionic test when I tried to switch over to llvm-libc
wcstok().
2025-08-01 14:15:34 -04:00
Muhammad Bassiouni
9af2c21be4
[libc][math] Refactor atan2f implementation to header-only in src/__support/math folder. (#150993)
Part of #147386

in preparation for: https://discourse.llvm.org/t/rfc-make-clang-builtin-math-functions-constexpr-with-llvm-libc-to-support-c-23-constexpr-math-functions/86450
2025-08-01 16:06:09 +03:00
Joseph Huber
b5cd8c34a7 [libc] Fix leader calculation when done in wave64 mode
Summary:
Wave 64 mode touches the upper limit of this, which had an off-by-one
error. This caused it to return the same leader which gave an invalid
view of memory.
2025-07-31 21:26:31 -05:00
William Huynh
38fa11f5b4
[libc] Remove constexpr from asin_eval() (#151528)
fputil::multiply_add is conditionally constexpr, on some architectures,
it selects the non-constexpr version, resulting in a compile error.
2025-07-31 13:20:37 -04: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
Aiden Grossman
5906ff67ae
[libc] Remove some sched.h includes (#151425)
This patch removes some sched.h includes, preferring the proxy headers.
This patch does not clean them all up as some proxy type headers need to
be added, like for `struct sched_param`.
2025-07-30 18:20:55 -07:00
Muhammad Bassiouni
2b2f5791f2
[libc][math] fix atan2l build failure. (#151413) 2025-07-31 02:18:33 +03:00
Muhammad Bassiouni
c8b6ddf3a3
[libc][math] Refactor atan2 implementation to header-only in src/__support/math folder. (#150968)
Part of #147386

in preparation for: https://discourse.llvm.org/t/rfc-make-clang-builtin-math-functions-constexpr-with-llvm-libc-to-support-c-23-constexpr-math-functions/86450
2025-07-31 01:07:55 +03:00
Joseph Huber
1a0121cbed [libc] Start slab search at number of allocated bits
Summary:
This patch changes the slab search to start at the number of allocated
bits. Previously we would randomly search, but this gives very good
performance when doing nothing but allocating, which is a common
configuration. This will degrade performance when mixing malloc and free
close to eachother as this is more likely to fail when the counter
starts decreasing.
2025-07-30 16:05:55 -05:00
Muhammad Bassiouni
729b0d1b61
[libc][math] Refactor atanf16 implementation to header-only in src/__support/math folder. (#150868)
Part of #147386

in preparation for: https://discourse.llvm.org/t/rfc-make-clang-builtin-math-functions-constexpr-with-llvm-libc-to-support-c-23-constexpr-math-functions/86450
2025-07-30 23:31:07 +03:00
Aiden Grossman
fc5976118d
[libc] Add implementation of getcpu syscall wrapper (#150871)
This patch adds the getcpu syscall wrapper. This has been supported in
glibc since v2.29.
2025-07-30 09:45:19 -07:00