5139 Commits

Author SHA1 Message Date
lntue
6ae395a875
[libc][NFC] Guard long double type in shared_math_tests. (#189373)
Skip long double tests when long double is double-double.
Also adjust constant literals.
2026-03-30 10:05:16 -04:00
Mohamed Emad
1bb03026b6
[libc][math][c23] implement double-precision asinpi (#188158)
Implement the double precision version of the asinpi c23 math function
2026-03-29 10:18:07 -04:00
Shikhar Soni
f0ce26d06d
[libc][math][c23] Add log2p1f16 C23 math function (#186754)
Signed-off-by: Shikhar Soni <shikharish05@gmail.com>
2026-03-28 11:34:42 -04:00
Alexey Samsonov
ae63230c23
[libc] Remove more header template files (#189066)
Get rid of several .h.def files which were used to ensure that the
macro definitions from llvm-libc-macro would be included in the public
header. Replace this logic with YAML instead - add entries to the
"macros" list that point to the correct "macro_header" to ensure it
would be included.

For C standard library headers, list several standard-define macros
to document their availability. For POSIX/Linux headers, only reference
a handful of macro, since more planning is needed to decide how to
represent platform-specific macro in YAML.
2026-03-27 16:06:39 -07:00
Jeff Bailey
d6ff5e7778
[libc][docs] Parse inline macro_value from YAML in docgen (#189118)
The docgen script was previously hardcoded to assume all implemented
macros must be placed in a *-macros.h header. This updates docgen to
read inline macro_value properties directly from the source YAML files,
correctly recognizing them as implemented.
2026-03-27 22:19:29 +00:00
Jeff Bailey
0aba82eb70
[libc] Add missing POSIX macros to cpio.h (#188840)
Define the POSIX cpio.h header and its standard macros in the libc build
system. Configure the macros directly in the YAML specification to allow
automated header generation without a custom definition template.
2026-03-27 22:08:13 +00:00
Alexey Samsonov
ead9ac8331
[libc] Remove header templates from several C standard headers. (#188878)
Switches the following headers to hdrgen-produced ones by referencing
some macro from C standard and the file containing the declarations in
corresponding YAML files:

* limits.h (referenced _WIDTH / _MAX / _MIN families).
* locale.h (referenced LC_ family).
* time.h (referenced CLOCKS_PER_SEC).
* wchar.h (referenced WEOF).
2026-03-27 17:55:37 +00:00
Jeff Bailey
030ef70908
[libc][docs] Document libc-shared-tests ninja target (#189062)
Added a brief description of the libc-shared-tests target to the
Building and Testing page.

This target allows running tests for shared standalone components like
math primitives without the full libc runtime.
2026-03-27 17:39:38 +00:00
Petter Berntsson
2af95b2fa2
[libc][docs] Fix POSIX basedefs links for nested headers (#188738)
Fix broken POSIX basedefs links for nested headers in llvm-libc docs.

The docgen script currently emits paths like `sys/wait.h.html`, but the
Open Group uses `sys_wait.h.html`, for example:
-
https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/sys_wait.h.html

This updates nested-header link generation while leaving flat headers
unchanged.
2026-03-27 17:30:43 +00:00
Michael Jones
166f996c44
[libc][bazel] Add generation for public headers (#184889)
Previously there was a single rule for stdbit, this PR adds generated
header targets for the rest of the linux headers. It also adds a
cc_library
for all of the public headers which also includes the types and macros
headers.
2026-03-27 09:44:32 -07:00
Jeff Bailey
b2f5992412
[libc][docs][NFC] Document cross-compilation testing with QEMU (#188838)
Added a "Building and Testing with an Emulator" section to
full_cross_build.rst using riscv64 and qemu-riscv64 as the example.
Outlined necessary CMake flags for cross-compiling with Clang, including
CMAKE_C_COMPILER_TARGET, CMAKE_CXX_COMPILER_TARGET, and
LLVM_ENABLE_LLD=ON. Switched from CMAKE_SYSROOT to LIBC_KERNEL_HEADERS
and added the gcc-riscv64-linux-gnu package dependency to ensure sysroot
issues on Debian-based systems are avoided while retaining access to
cross-compiler runtime objects.

Explained the self-hosted libc-hermetic-tests target as the required
target for executing tests during a standalone cross build, since the
standard check-libc tests are not hermetic.

Refactored existing CMake examples in full_cross_build.rst to use -S and
-B flags instead of cd and mkdir.

Removed prompt characters from code blocks and separated host
environment setup into explicit code blocks for easier copy-pasting.
Also removed the initial 'cd llvm-project' directory changes to reduce
boilerplate.

Added a cross-reference to the new emulator section in
build_and_test.rst.
2026-03-27 15:14:38 +00:00
Anonmiraj
e06b5e53a2
[libc][math] Implement C23 half precision erfc function (#180930)
Add support for the half-precision complementary error function
`erfcf16``, using a Sollya generated polynomial implementation with
proper handling of special cases.

Extend the MPFR utilities with erfc support to allow tests.

closes: #180927
2026-03-27 10:42:03 -04:00
lntue
924a4ada31
[libc] Guard long double shared math functions against double-double. (#188909) 2026-03-27 01:51:17 -04:00
Jeff Bailey
ecfcdd6e2a
[libc] Fix check-libc-lit running tests during build (#188081)
Updated check-libc-lit to depend only on build-only targets. Added
libc-integration-tests-build to track integration test executables and
updated LLVMLibCTestRules.cmake to populate it.

Removed incorrect dependencies on execution suites in include and
integration tests that were introduced in #184366.
2026-03-26 21:00:28 +00:00
Alexey Samsonov
968b6aaef1
[libc][hdrgen] Print __BEGIN_C_DECLS / __END_C_DECLS conditionally. (#188830)
Clean up the `%public_api` printer code slightly - get rid of explicit
`\n` and ensure we only print `__BEGIN_C_DECLS` and `__END_C_DECLS` if
the generated header actually contains functions or objects to declare.

I've noticed that after 27ba9e2a44c11f8123528c350227db2c9a707c8f landed,
generated errno.h header has two blocks of `__BEGIN_C_DECLS` /
`__END_C_DECLS`: an empty one was generated automatically from
`%public_api` section that was intended to only add the `errno_t` type
declaration.
2026-03-26 20:02:34 +00:00
Zorojuro
a9c6f38e8d
[libc] Fixes all guard comments of libc (#188701)
This PR intends to fix ALL the wrong guard comments for libc


Script used:
[guard_checker](https://github.com/Sukumarsawant/guard_checker/blob/main/check_headers.py)
2026-03-26 15:23:49 -04:00
Joseph Huber
3a56470a0e
[libc] Increase the maximum RPC port size for future hardware (#188756)
Summary:
We store the locks in local device memory for performance and
simplicity. The number here needs to correspond to the maximum occupancy
so that we never have a situation where a GPU thread is blocking another
GPU thread.

The number now is sufficient for most hardware, but modern compute chips
like the MI300x are already pushing ~12000 resident waves. This has ABI
impliciations so I'd like to bump it up sooner rather than later. The
ABI change is within what OpenMP expects, LLVM major versions, and it
will be caught statically so there's no risk of silent corruption (size
doesn't match).
2026-03-26 10:17:52 -05:00
Joseph Huber
cc4727ae3b
[LLVM] Replace use of LLVM_RUNTIMES_TARGET with LLVM_DEFAULT_TARGET_TRIPLE (#188303)
Summary:
This PR primarily changes using `LLVM_RUNTIMES_TARGET` to
`LLVM_DEFAULT_TARGET_TRIPLE`. The reason is that the default target
triple is the true cross-compiling architecture we are using, while the
runtimes_target can contain multilib strings like `+debug` or similar.

Additionally add the proper path handling to the OpenMP / Offload
libraries.
2026-03-26 08:52:32 -05:00
Jeff Bailey
9e6bd128f2
[libc][doc] Remove ToC incompatible with Furo (#188720)
Thanks to @Sukumarsawant for spotting this!
2026-03-26 13:42:03 +00:00
lntue
5a2fedf91d
[libc][msvc] Re-enable __builtin_is_constant_evaluated for MSVC. (#188663) 2026-03-25 23:21:53 -04:00
lntue
67113d9d2f
[libc] Allow LLVM_LIBC_FUNCTION macro to take another parameter for function alias. (#187154) 2026-03-25 18:25:54 -04:00
Zorojuro
9a8b8153be
[libc] Fix all guard comments for cos and Acos functions (#188612)
This PR intends to fix all the wrong guard comments for cos and Acos
function
2026-03-25 17:40:46 -04:00
Jeff Bailey
4bfc9bd4cf
[libc][docs] Add guide for implementing a function (#188499)
Added implementing_a_function.rst providing a checklist for adding a new
function to LLVM-libc.

Updated dev/index.rst to include the new guide in the toctree.
2026-03-25 20:43:49 +00:00
lntue
2c24f02924
[libc][math] Switch log1pf to use the same log_eval from inverse hyperbolic functions. (#188388)
- Switch log1pf to use the same log_eval from inverse hyperbolic
functions.
- Optimize log_eval to use the same range reduction scheme as double
precision log
- Reduce the table size needed for log range reduction.
- This lower the overall latency of log1pf and inverse hyperbolic
functions.
2026-03-25 16:41:54 -04:00
Ilya Tokar
267b0ea6e8
[libc][x86] add MEMCPY_X86_USE_NTA_STORES to config (#188321)
Add LIBC_CONF_COPT_MEMCPY_X86_USE_NTA_STORES to cmake/bazel/json config.
2026-03-25 15:14:27 -04:00
Jeff Bailey
4dbcc3f029
[libc] implement fflush(NULL) support (#188217)
Implement support for flushing all open streams when fflush is called
with a NULL pointer.

* Added a global linked list to track all open File objects.
* Updated File class to include prev/next pointers and list management
methods.
* Implemented POSIX requirement for fflush to sync seekable input
streams back to the host environment.
* Updated Linux-specific file creation to register new files in the
global list.
* Fixed a memory safety bug in create_file_from_fd using delete instead
of free.
* Added unit test for fflush(NULL).
* Added explanatory comments to fflush.cpp and file.cpp.
2026-03-25 14:51:57 +00:00
Victor Campos
2baa2cdce9
[libc] Follow up on Annex K's rsize_t (#187707)
- Fix header guard name.
- Define `__STDC_WANT_LIB_EXT1__` in `hdr/types/rsize_t.h` so that the
type is available for internal use.
- In accordance to the standard, make `stdio.h`, `stdlib.h`, `string.h`,
`time.h` and `wchar.h` define the type. It should already be available
in `stddef.h` as it's provided by Clang, not LLVM libc.
2026-03-25 13:16:34 +00:00
Victor Campos
27ba9e2a44
[libc] Define Annex K's errno_t in specified headers (#187700)
- Change `errno.h.def` to include a placeholder where hdrgen emits the
public API, which contains the `errno_t` definition.
- Make headers `stdio.h`, `stdlib.h`, `string.h` and `time.h` also
define `errno_t` as specified in the standard.
2026-03-25 12:30:19 +00:00
Fabio D'Urso
5999c53e32
[libc] Declare free_sized and free_aligned_sized in stdlib.h / malloc.h (#188364) 2026-03-25 11:48:07 +01:00
Jeff Bailey
458d3a8f05
[libc] Fix unused variable warning in utimes.cpp (#188347) (#188448)
Moved the declaration of 'ret' inside the SYS_utimes block to prevent an
unused variable warning on the libc-riscv32-qemu-yocto-fullbuild-dbg
builder, which doesn't define SYS_utimes.
2026-03-25 09:54:30 +00:00
Jakob Koschel
952dc12124
Force to inline syscall_impl on all platforms (#186849)
With currently only LIBC_INLINE, we just hint the compiler to inline the
function which however in practice is not always the case.

Since we added `[[gnu::always_inline]]` on linux/x86_64 it makes sense
to do it on all platforms consistently and add a comment explaining why
we need it.
2026-03-25 09:55:37 +01:00
Jeff Bailey
4c4c1db7c6
[libc] Add utimensat syscall wrapper and entrypoint (#188347)
Implemented the utimensat syscall for Linux and added the entrypoint to
sys/stat.h.

* Added utimensat syscall wrapper to OSUtil
* Updated utimes to use the utimensat wrapper
* Added utimensat unit tests to sys/stat
* Configured entrypoints for x86_64, riscv, and aarch64
2026-03-25 07:53:29 +00:00
Jeff Bailey
f0b58c16e1
[libc][docs][NFC] Expand entrypoints technical reference (#4) (#188255)
Expanded entrypoints.rst with details about definitions, registration
rules, and the lifecycle of an entrypoint.

Updated multiple documents to remove redundant technical details and
link to the centralized entrypoints reference:

- libc/docs/dev/cmake_build_rules.rst
- libc/docs/dev/implementation_standard.rst
- libc/docs/porting.rst
- libc/docs/dev/source_tree_layout.rst
2026-03-25 07:05:52 +00:00
Zorojuro
408bb4d4b2
[libc] Wrong guards for totalorderbf16 and totalordermagbf16 (#188241)
Currently the guards for `totalorderbf16` and `totalordermagbf16` are as
follows:
```
#ifndef LLVM_LIBC_SRC_MATH_TOTALORDERMAGF16_H
#define LLVM_LIBC_SRC_MATH_TOTALORDERMAGF16_H
-
#endif // LLVM_LIBC_SRC_MATH_TOTALORDERMAGF16_H
```
and 
```
#ifndef LLVM_LIBC_SRC_MATH_TOTALORDERF16_H
#define LLVM_LIBC_SRC_MATH_TOTALORDERF16_H
-
#endif // LLVM_LIBC_SRC_MATH_TOTALORDERF16_H
```
As we can see these are for F16 and not BF16 .
This Pr intends to fix that with correct guards as `TOTALORDERBF16` and
`TOTALORDERMAGBF16`
2026-03-24 20:54:31 -04:00
Zorojuro
9999f7fe08
[libc] Wrong header guard comment for atanpif16 (#188310)
This PR intends to fix a small nit caused in
[1c1135b](1c1135b3fc)
```
#endif // LLVM_LIBC_SRC_MATH_ASINIF16_H
```
to 
```
#endif // LLVM_LIBC_SRC_MATH_ATANPIF16_H
```
2026-03-24 20:53:29 -04:00
Jeff Bailey
4e290b3429
[libc][strings] Refactor load_aligned for cleaner endianness handling (#186360)
Replace the explicit `if constexpr` branching for big and little
endianness with compile-time calculated shift constants `VAL_SHIFT` and
`NEXT_SHIFT`. This simplifies the logic and reduces code duplication,
relying on the compiler to constant-fold the zero shifts into no-ops.
2026-03-24 20:40:22 +00:00
Zorojuro
6638cee0d8
[libc] Remove redundant and incorrect comments in logf.cpp (#188236)
This PR intends to fix the nit (mostly caused during the refactor in
693a018dcf08e )

- During refactor we move the implementation along with the explanation
comments to header.
```CPP
// This is an algorithm for log(x) in single precision which is correctly
// rounded for all rounding modes, based on the implementation of log(x) from
// the RLIBM project at:
// https://people.cs.rutgers.edu/~sn349/rlibm

// Step 1 - Range reduction:
//   For x = 2^m * 1.mant, log(x) = m * log(2) + log(1.m)
//   If x is denormal, we normalize it by multiplying x by 2^23 and subtracting
.....
// Symposium on Principles of Programming Languages (POPL-2022), Philadelphia,
// USA, January 16-22, 2022.
// https://people.cs.rutgers.edu/~sn349/papers/rlibmall-popl-2022.pdf
```

Though the explanation comments were copied and moved to header in
d2492c1 . It wasn't deleted from the `cpp` file.
Along with this in the same,

`#include "src/__support/math/logf.h" // Lookup table for (1/f) and
log(f)`

is wrong as it is actually for 
`#include "src/__support/math/common_constants.h" // Lookup table for
(1/f) and log(f)`
2026-03-24 14:35:40 +00:00
Petter Berntsson
da439d5426
[libc][docs] Avoid docgen target collisions and restore pthread docs (#188221)
Fixes llvm/llvm-project#123821.

Re-enabling pthread docs created a global CMake utility target named
`pthread`, which collides in combined runtime builds where `pthread` is
expected to be a library name. Namespace the internal libc docgen helper
targets under `libc-docgen-*` and restore the generated pthread docs
page. `docs-libc-html` is unchanged.
2026-03-24 14:33:34 +00:00
Joseph Huber
4961700c10
[libc] Support AMDGPU device interrupts for the RPC interface (#188067)
Summary:
One of the main disadvantages to using the RPC interface is that it
requires a server thread to spin on the mailboxes checking for work.
The vast majority of the time, there will be no work and work will come
in large bursts.

The HSA / KFD interface supports device-side interrupts and already has
handling for binding these events to an HSA signal. This means that we
can send interrupts from the GPU to wake a sleeping thread on the CPU.
The sleeping thread will be descheduled with a blocking HSA wait call
and woken up when its event ID is raised through the kernel driver's
interrupt.

This is very target-specific handling, but I believe it is valuable
enough to warrant it being in the protocol. It is completely optional,
as it is ignored if uninitialized. This should bring this support at
parity with the interface HIP expects.
2026-03-24 08:48:52 -05:00
Zorojuro
c15edf8208
[libc] cbrtf guard to sync with general format (#188207)
This PR intends to make the cbrtf guard sync with the general format (
as other functions consistently use `LLVM_LIBC_SHARED_MATH_<func>_H`).
This was found during refactoring cbrtbf16.
2026-03-24 10:56:54 +00:00
Muhammad Bassiouni
b4f50cfd4a
[libc][math] Qualify ceil functions to constexpr (#184948) 2026-03-24 00:25:42 +02:00
lntue
599d74fdc3
[libc][math] Reduce memory usage for single precision inverse hyperbolic functions for LIBC_MATH_HAS_SMALL_TABLES option. (#188110) 2026-03-23 21:41:21 +00:00
Jeff Bailey
079be4e739
[libc] Support Windows test executables in LibcTest lit format (#188057)
Updated LibcTest to handle Windows test executables:

* Added support for .exe extensions when identifying test executables.
* Skipped the executable bit check on Windows as it is not applicable.
* Updated .params file discovery to look for both <test>.exe.params and
<test>.params.

This allows running libc tests on Windows hosts.
2026-03-23 16:39:40 +00:00
lntue
75ac07d369
[libc][math] Use Estrin's scheme to improve asinf and acosf performance. (#187885) 2026-03-23 10:27:51 -04:00
Zorojuro
95951fca84
[libc] Add missing shared_math docs in add_math_function.md (#188026)
This PR intends to add/update the following things:

- Add missing doc for CMake for shared_math
- Add missing testing command for shared_math_test
- Nits (e.g., grammar, spaces, missing colons, etc.)
2026-03-23 13:10:44 +00:00
Zorojuro
aa62224a73
[libc][math] Refactor sqrtbf16 function header-only (#187849) 2026-03-22 00:51:40 +02:00
Muhammad Bassiouni
eea589f951
[libc][math] Qualify log with constant evaluation support (#184745)
Lay the ground for C++26 `constexpr` math functions:
- Introduce `LIBC_ENABLE_CONSTEXPR` macro switch to specify the desire
of `constexpr`-only code route.
- Introduce `LIBC_HAS_CONSTANT_EVALUATION` to indicate that we are using
`constexpr`-only code in all dependent functions.
- Introduce `LIBC_CONSTEXPR` macro qualifier to aid in altering the
signature of non-`constexpr` functions.

Note that non-`constexpr` qualified functions are caused by the
exploitation of non-`constexpr` compatible utils, resulting in
non-qualified dependent function, but it can be modified to be qualified
using other code routes.

If the function is `constexpr` compatible, then it's prohibited to use
`LIBC_CONSTEXPR` as a function qualifier. We only qualify it with
`constexpr` as usual.

`LIBC_CONSTEXPR` may or may not evaluate to `constexpr` depending on the
environment configurations, thus it's only used to modify the function
signature in constant evaluation context and remove the qualifier if
it's not desired (depending on provided configurations).

Possible side effects:
- Current qualified routes may or may not produce the desired ULP, this
is implementation dependent (function by function basis) and needs
further testing of the chosen code route.
- The shared tests in the current configuration can still compile with
unsupported compiler. I didn't want to raise compilation error with
unsupported compilers now, but we need to push compiler support with
newer versions for this one to work as intended.
2026-03-21 23:55:05 +02:00
Zorojuro
7d7cd745af
[libc][math][c23] Add atanbf16 function (#184019)
This PR intends to add atanbf16 higher math function for BFloat16 type
along with the tests.
2026-03-21 11:09:11 -04:00
Jeff Bailey
2b47497f6e
[libc][docs][NFC] Restructure Getting Started guide and update Build Concepts. (#187701)
Restructured the Getting Started guide into a numbered step-by-step path
for easier readability. Added a Hello World verification step to confirm
build integrity after build completion.

Additionally, updated build_concepts.rst and the Getting Started guide
to clarify that Overlay Mode is intended for augmenting the system's C
library rather than incremental adoption.
2026-03-21 00:56:38 +00:00
Alexey Samsonov
a60b3a83cf
[libc] Fix function prototypes for <threads.h> C11 header. (#187808)
Fix return types and/or function arguments of several functions:
* mtx_destroy
* tss_delete
* thrd_exit
2026-03-20 16:17:29 -07:00