2981 Commits

Author SHA1 Message Date
Schrodinger ZHU Yifan
d6534f437d
[libc][signal] remove wrongly added constexpr (#190424)
Hotfix for CI failure
2026-04-03 23:04:20 +00:00
Schrodinger ZHU Yifan
463f6cb576
[libc] update abort implementation and lift it for internal usage (#189756) 2026-04-03 18:40:52 -04:00
lntue
c34c0442ee
[libc] Add str_to_* and rpc_* shared tests. (#190351)
Also fix several things for LIBC_TYPES_LONG_DOUBLE_IS_DOUBLE_DOUBLE to
make them build.
2026-04-03 16:34:23 -04:00
Roland McGrath
71122d8694
[libc] Move LLVM_LIBC_IS_DEFINED macro to its own header (#190081)
This moves the LLVM_LIBC_IS_DEFINED macro to its own header is
__support/macros.  Its implementation leverages cpp::string_view
instead of rolling its own strcmp; this necessitated fixing
several missing constexpr in the string_view implementation.

The new __support/macros/macro-utils.h is also broken out to hold
the stringification macro and can be used in future for token
pasting shenanigans and other such generic macro machinery.
2026-04-02 14:13:51 -07:00
Joseph Huber
b2d3a6574c
[libc] Rename rpc::Status to rpc::RPCStatus to reduce conflicts (#190239)
Summary:
`Status` is unfortunately heavily overloaded in practice. Things like
X11 define it as a macro. Best to just remove that possibility entirely.
2026-04-02 14:55:57 -05:00
lntue
096f9d0aa8
[libc] Initial support so that libc-shared-tests can be built with pp64le (#188882) 2026-04-01 20:55:44 -04:00
Zorojuro
52fb23eef8
[libc][math] Remove static from log1pf implementation (#190042)
Reflecting changes according to
823e3e0017
2026-04-01 19:01:44 -04:00
lntue
e87ea848b7
Reapply "[libc] Finetune libc.src.__support.OSUtil.osutil dependency." (#190033) (#190065)
This reverts commit 84f23eb3113f2e75d1a2e45db1b5c570a5d2f4c5 and fix GPU
builds.
2026-04-01 18:38:32 -04:00
Jan Patrick Lehr
84f23eb311
Revert "[libc] Finetune libc.src.__support.OSUtil.osutil dependency." (#190033)
Reverts llvm/llvm-project#189501

Buildbot failure on libc for GPU buildbots
2026-04-01 22:02:27 +02:00
lntue
35ceec6a78
[libc] Finetune libc.src.__support.OSUtil.osutil dependency. (#189501)
Several key targets unconditionally depend on `OSUtil.osutil` target,
causing errors when it is unnecessarily linked, or not available. This
PR fine-tuning the dependency on `OSUtil.osutil` to cleanly decouple
those targets, and gracefully skip targets that need `osutil`. Main
changes include:

* Make `LIBC_COPT_USE_C_ASSERT` to a cmake config, allowing
`LIBC_ASSERT` to use system's `assert` and not depending on `osutil`.
* Adjust cmake dependency for the following targets:
  - libc.src.__support.libc_assert
  - libc.src.__support.time.*
  - libc.src.time.linux.*
  - libc.src.unistd.*
  - LibcTest
* Give an option for `TestLogger` to use system's `fprintf` instead of
`osutil`.
2026-04-01 14:59:02 -04:00
Schrodinger ZHU Yifan
c6b25b4df3
[libc] separate raw_rwlock and unix_rwlock to make it internally usable (#189773) 2026-04-01 10:09:18 -04:00
lntue
ec45f95799
[libc] Add libc_set_definition and libc_add_definition to properly pass definitions to MSVC. (#189664) 2026-03-31 13:15:13 -04:00
Schrodinger ZHU Yifan
5a89da7d13
[libc][signal] cleanup sigaction implementation (#189512) 2026-03-31 09:43:50 -04:00
Schrodinger ZHU Yifan
10ea3deb87
[libc][syscall] lift raise to syscall wrapper (#189507) 2026-03-31 09:33:14 -04:00
Michael Jones
7b52dd6ad9
[libc][NFC] Add LIBC_INLINE and cleanup wchar internals (#188856)
Some of the functions were missing LIBC_INLINE and some of the variable
names were less descriptive than I liked. This PR fixes both as well as
cleaning up dependencies.
2026-03-30 23:03:06 +00:00
Schrodinger ZHU Yifan
74c4243225
[libc][tsearch] add tsearch functions (#172625) 2026-03-30 17:51:36 -04:00
Zorojuro
15a7c45163
[libc][math][c23] Add asinbf16 math function (#184170)
Co-authored-by: bassiounix <muhammad.m.bassiouni@gmail.com>
2026-03-30 21:29:55 +02:00
Joseph Huber
a6ffdb595f
[Clang] Improve scan in gpuintrin.h (#189381)
Summary:
Right now the scan checks to avoid the unspecified behavior in
`clzg(0)`. This is used as the source to the shuffle instruction, but
the argument is discarded at zero anyway. So, we simply pass unspecified
behavior to shuffle and then discard it. This should be fine. The scan
routines are expected to be optimal.

Also renames `sum` to `add`.
2026-03-30 14:16:21 -05: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
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
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
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
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
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
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
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
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
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
Ilya Tokar
bb369f1c30
[libc][x86] Add Non-temporal code path for large memcpy (#187108)
Large memcopies are pretty rare, but are more common in ML workloads
(copying large matrixes/tensors, often to/from CPU host).

For large copies NTA stores can provide performance advantages for both
memcpy itself and the rest of the workload (by reducing cache
pollution). Other runtimes already have NTA path for large copies, so
add 1 to the llvm-libc.

Internal whole-program loadtests shows small, but statistically
significant improvement of 0.1%. ML specific bencahmrks showed 10-20%
performance gain, and fleetbench (https://github.com/google/fleetbench,
which has more up-to-date version of libc benchmarks) shows ~3% gain
(ns/byte for distributions taken from various applications).

```
[Memcpy_0]_L1      0.01950n ± 3%   0.01900n ± 5%       ~ (p=0.390 n=20)
[Memcpy_0]_L2      0.02300n ± 0%   0.02300n ± 0%       ~ (p=0.256 n=20)
[Memcpy_0]_LLC     0.1335n ± 1%    0.1310n ± 1%   -1.87% (p=0.000 n=20)
[Memcpy_0]_Cold    0.1540n ± 2%    0.1520n ± 1%   -1.30% (p=0.021 n=20)
[Memcpy_1]_L1      0.04300n ± 5%   0.04200n ± 2%  -2.33% (p=0.000 n=20)
[Memcpy_1]_L2      0.05000n ± 2%   0.04800n ± 0%  -4.00% (p=0.000 n=20)
[Memcpy_1]_LLC     0.2500n ± 2%    0.2390n ± 1%   -4.40% (p=0.000 n=20)
[Memcpy_1]_Cold    0.2750n ± 1%    0.2640n ± 1%   -4.00% (p=0.000 n=20)
[Memcpy_2]_L1      0.03800n ± 3%   0.03800n ± 3%       ~ (p=0.420 n=20)
[Memcpy_2]_L2      0.04400n ± 2%   0.04300n ± 0%  -2.27% (p=0.000 n=20)
[Memcpy_2]_LLC     0.2320n ± 1%    0.2220n ± 1%   -4.31% (p=0.000 n=20)
[Memcpy_2]_Cold    0.2565n ± 1%    0.2460n ± 1%   -4.09% (p=0.000 n=20)
[Memcpy_3]_L1      0.1380n ± 1%    0.1355n ± 2%        ~ (p=0.095 n=20)
[Memcpy_3]_L2      0.1490n ± 1%    0.1430n ± 1%   -4.03% (p=0.000 n=20)
[Memcpy_3]_LLC     0.7955n ± 1%    0.7450n ± 0%   -6.35% (p=0.000 n=20)
[Memcpy_3]_Cold    0.8495n ± 1%    0.7935n ± 0%   -6.59% (p=0.000 n=20)
[Memcpy_4]_L1      0.04000n ± 3%   0.03900n ± 3%       ~ (p=0.466 n=20)
[Memcpy_4]_L2      0.04500n ± 2%   0.04400n ± 2%       ~ (p=0.130 n=20)
[Memcpy_4]_LLC     0.2040n ± 1%    0.1950n ± 1%   -4.41% (p=0.000 n=20)
[Memcpy_4]_Cold    0.2240n ± 1%    0.2150n ± 1%   -4.02% (p=0.000 n=20)
[Memcpy_5]_L1      0.05800n ± 3%   0.06050n ± 1%  +4.31% (p=0.000 n=20)
[Memcpy_5]_L2      0.06400n ± 0%   0.06400n ± 2%   0.00% (p=0.004 n=20)
[Memcpy_5]_LLC     0.3320n ± 1%    0.3140n ± 1%   -5.42% (p=0.000 n=20)
[Memcpy_5]_Cold    0.3620n ± 1%    0.3430n ± 0%   -5.25% (p=0.000 n=20)
[Memcpy_6]_L1      0.05700n ± 2%   0.05750n ± 3%       ~ (p=0.403 n=20)
[Memcpy_6]_L2      0.06500n ± 0%   0.06250n ± 1%  -3.85% (p=0.000 n=20)
[Memcpy_6]_LLC     0.3410n ± 1%    0.3205n ± 1%   -6.01% (p=0.000 n=20)
[Memcpy_6]_Cold    0.3670n ± 1%    0.3470n ± 1%   -5.45% (p=0.000 n=20)
[Memcpy_7]_L1      0.05900n ± 2%   0.05900n ± 2%       ~ (p=0.296 n=20)
[Memcpy_7]_L2      0.06400n ± 2%   0.06400n ± 0%       ~ (p=0.327 n=20)
[Memcpy_7]_LLC     0.3145n ± 1%    0.2965n ± 1%   -5.72% (p=0.000 n=20)
[Memcpy_7]_Cold    0.3410n ± 1%    0.3220n ± 0%   -5.57% (p=0.000 n=20)
[Memcpy_8]_L1      0.03600n ± 3%   0.03600n ± 3%       ~ (p=0.804 n=20)
[Memcpy_8]_L2      0.04200n ± 0%   0.04100n ± 2%  -2.38% (p=0.000 n=20)
[Memcpy_8]_LLC     0.2210n ± 1%    0.2090n ± 1%   -5.43% (p=0.000 n=20)
[Memcpy_8]_Cold    0.2415n ± 1%    0.2300n ± 1%   -4.76% (p=0.000 n=20)
geomean            0.1184n         0.1148n        -3.03%
```
2026-03-20 15:36:08 -04:00
Jeff Bailey
2600c723e1
[libc][NFC] Fix typo in file.cpp (#91192) (#187688)
Corrected language and spelling errors in a comment within file.cpp.

Credit GH user @iBlanket for identifying this typo.
2026-03-20 12:27:28 +00:00
Daniel Thornburgh
7efcd6198c
[libc] Modular printf option (float only) (#147426)
This adds LIBC_CONF_PRINTF_MODULAR, which causes floating point support
(later, others) to be weakly linked into the implementation.
__printf_modular becomes the main entry point of the implementaiton, an
printf itself wraps __printf_modular. printf it also contains a
BFD_RELOC_NONE relocation to bring in the float aspect.

See issue #146159 for context.
2026-03-19 14:22:03 -07:00
lntue
2632ffeab1
[libc][stdio] Fix standard streams in overlay mode. (#187522)
https://github.com/llvm/llvm-project/pull/184669 changed the behavior of
standard streams in overlay mode, bringing in some symbols that are only
available in full build mode.
2026-03-19 15:42:12 -04:00
neonetizen
adbb122717
[libc] Implement iswprint entrypoint (#185251)
Implemented the iswprint entrypoint and tests for issue #185136
2026-03-19 12:36:56 -07:00
Pengxiang Huang
bed9fa2de5
[libc][sys/sem] Add sys v sem headers and syscall wrapper implementation (#185914)
Fix #182161
Based on the last PR #182700 implementing sys/ipc.
2026-03-19 10:12:06 -04:00
Mohamed Emad
4db2ce4d54
[libc][math] Refactor dadd family to header-only (#182142)
Closes https://github.com/llvm/llvm-project/issues/182141
2026-03-19 06:37:35 +02:00
Manthan Singla
42b75ed85f
[libc][math] Refactor bf16divf128 to Header Only (#186641)
closes #181024
2026-03-19 01:47:22 +02:00
Anonmiraj
c0064f744c
[libc][math] Fix missing underflow exception in DyadicFloat::generic_as (#186734)
The `generic_as` function in `dyadic_float.h` had a missing `underflow =
true` at the exact boundary where `unbiased_exp == -EXP_BIAS -
FRACTION_LEN`.
At this boundary, the mantissa MSB maps exactly to the round bit, so
out_mantissa is 0 and the result can only be 0 or min_subnormal. The
value is at most min_subnormal / 2, so it is always tiny and always
inexact `underflow` must be signaled. The < case and the general
subnormal range both already set underflow = true this boundary case was
the only gap.

this specifically fix this error in the erfcf16 function 
```
Extracted erfcf16.cpp.o from archive for linking
Running exhaustive check in --rndn mode...
Missing underflow exception for x=0x1.eacp+1 (y=0x1p-24)
```

this fix may also apply to other bfloat16 missing exceptions
(@Sukumarsawant)

part of: #186483 

CC: @lntue
2026-03-18 10:02:36 -04:00