2199 Commits

Author SHA1 Message Date
Hanliang Xu (Leon)
03d453a51a
[libc][math] Fix FP add/sub for signed-zero operands (#183243)
(-0.0) + (-0.0) and (-0.0) - (+0.0) returned +0.0 instead of -0.0.

Ensure these cases comply with IEEE 754 §6.3 rule.
2026-03-05 18:30:42 -05:00
Zorojuro
9548db811e
[libc][math] Refactor ffmaf128 into a header only. (#184751)
closes #175325 
part of #147386
2026-03-05 23:31:40 +02:00
Joseph Huber
10ade36650 [libc] Rework slab cache data structure for GPU allocator
Summary:
This was previously a Trieber stack, which is a perfectly fine generic
and lock-free data structure. However, this used some expensive CAS
operations and had issues with ABA. Because the only user of this was
the slab cache mechanism, we can pretty safely specialize it. Instead,
we simply search a fixed size buffer for some sentinal values and CAS
into it.

For allocations that only ever hit the cache, this improves performance
from ~9000 cycles to ~6000 cycles and similar improvements for workloads
that feel the pain of small thread counts hitting the cache.
2026-03-05 12:30:05 -06:00
Jeff Bailey
7b7c8b2eb3
[libc] Extend check-libc-lit to cover include, integration, and all src tests (#184366)
The lit-based test runner introduced in c776a52f only discovered
libc.test.src tests with a strict __unit__.__build__ or
__hermetic__.__build__ suffix. This missed four categories of tests:

1. libc.test.include.* tests (e.g. isnan_test, signbit_test)
2. libc.test.integration.* tests (e.g. pthread, unistd, startup)
3. libc.test.src.* tests that have no __unit__/__hermetic__ marker (e.g.
errno_test, dirent_test, htonl)
4. libc.test.src.* tests with extra option suffixes between the type
marker and .__build__ (e.g. __unit__.__NO_FMA_OPT.__build__)

Wire up the two missing build dependencies so that check-libc-lit builds
include and integration tests before running them, and update
_isTestExecutable() to recognise all four patterns.

The pattern documentation was consolidated into the _isTestExecutable()
docstring, where it is next to the code it describes, to avoid the two
diverging in future.

Tested:
Compared the test count from a full `ninja check-libc` run (2765 tests)
against `llvm-lit --show-tests libc/test` after this change and
confirmed the counts match exactly.
2026-03-03 17:42:48 +00:00
Pengxiang Huang
5b976c9301
[libc][sys] add header and functions for sys ipc (#182700)
Split from a larger change. This PR contains the base impl for sys ipc,
sys sem will come after this. @SchrodingerZhu

this PR implements for:
https://github.com/llvm/llvm-project/issues/182161

see the last PR for more detail:
https://github.com/llvm/llvm-project/pull/182683
2026-03-03 09:48:18 -05:00
Jeff Bailey
1175046d14
[libc] Fix GPU loader propagation to lit test infrastructure (#184105)
The lit-based test execution added in c776a52fa263 did not propagate the
GPU loader executable to the lit site configuration. When building for
GPU targets, the loader (amdhsa-loader, nvptx-loader, or a
user-specified LIBC_GPU_LOADER_EXECUTABLE) was resolved into the
libc.utils.gpu.loader target but never passed through to the generated
lit.site.cfg.py.

Fix this by resolving the executable path from the libc.utils.gpu.loader
target property and including it in configure_lit_site_cfg's PATHS list.
In lit.site.cfg.py.in, if no explicit LIBC_TEST_CMD is set but a GPU
loader is present, construct libc_test_cmd from the loader path,
mirroring the logic in add_libc_hermetic() in LLVMLibCTestRules.cmake.

Tested:
* GPU build with LIBC_GPU_LOADER_EXECUTABLE set to /bin/echo used to
fail (tried to run the binary), now it works.
 * Native compiler check-libc-lit continues to work after this change.
2026-03-02 14:07:23 +00:00
Mohamed Emad
62cfe1659e
[libc][math][c23] implement C23 acospif math function (#183661)
Implementing C23 `acospi` math function for single-precision with the
header-only approach that is followed since #147386
2026-02-28 04:32:45 +02:00
Mohamed Emad
fb6b470cae
[libc][math] Refactor floor family to header-only (#182194)
Refactors the floor math family to be header-only.

Closes https://github.com/llvm/llvm-project/issues/182193

Target Functions:
  - floor
  - floorbf16
  - floorf
  - floorf128
  - floorf16
  - floorl
2026-02-28 04:32:22 +02:00
Mohamed Emad
ca04a70891
[libc][math] Refactor bf16sub family to header-only (#182115)
Refactors the bf16sub math family to be header-only.

Closes https://github.com/llvm/llvm-project/issues/182114

Target Functions:
  - bf16sub
  - bf16subf
  - bf16subf128
2026-02-27 21:38:30 +02:00
Anonmiraj
7e39b280e8
[libc][math] Refactor nextafter family to header-only (#181673)
closes #181672
2026-02-27 01:52:57 +02:00
Zorojuro
27905b1196
[libc][math] Refactor f16sqrtf128 to Header Only. (#183542)
closes  #175328
part of https://github.com/llvm/llvm-project/issues/147386
2026-02-26 20:48:56 +02:00
Muhammad Bassiouni
e3735ce4b3
[libc][math] Disable float16 on Clang 11 and older (#183574)
This also reverts
c5d6feb315
2026-02-26 20:47:29 +02:00
Weiwen He
3839878d20
[libc][math] Refactor tanpif16 to header-only (#181240)
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

Closes #181207
2026-02-26 17:49:50 +00:00
lntue
b654416f2c
[libc][math] Fix atan2f128 when the exponent difference is larger than the precision. (#183552) 2026-02-26 11:30:50 -05:00
Muhammad Bassiouni
b7989de510
[libc][math] Disable shared math tests on AArch64 2026-02-26 15:01:46 +02:00
Mohamed Emad
8f3dd82a0a
[libc][math][c23] implement asinpif function (#181511)
Implementing `asinpi` for single-precision. it continues what is done in
#152690 that implemented `asinpif16` with header-only approach that is
followed since #147386
2026-02-26 05:05:49 +02:00
Mohamed Emad
d7cdfa1096
[libc][math] Refactor fdim family to header-only (#182190)
Refactors the fdim math family to be header-only.

Closes https://github.com/llvm/llvm-project/issues/182188

Target Functions:
  - fdim
  - fdimbf16
  - fdimf
  - fdimf128
  - fdimf16
  - fdiml
2026-02-25 21:06:01 +00:00
Anonmiraj
bfaa15ee56
[libc][math] Refactor float16 basic operations to header-only (#181745)
closes: #181744
2026-02-25 20:56:33 +02:00
Anonmiraj
d2d862a544
[libc][math] Refactor nexttoward family to header-only (#181685)
Closes https://github.com/llvm/llvm-project/issues/181684
2026-02-25 18:20:18 +00:00
Anonmiraj
af1bdad42c
[libc][math] Refactor nextup family to header-only (#181688)
Closes https://github.com/llvm/llvm-project/issues/181687
2026-02-25 17:58:11 +00:00
Alexey Samsonov
4d70d8787f
[libc] Add atan2l implementation fallback to atan2f128. (#182587)
Add implementation for `atan2l` that falls back to `atan2f128` if
float128 support is available.

We do this for now in lieu of 80-bit-specific implementation. Going
forward, we should be choosing 64-bit, 80-bit, or 128-bit specific
implementation based on the specific "long double"
implementation. Also, once llvm-libc will have its own software
implementation of float128, depending on host type presence
would not be needed.

`atan2l` is one of the remaining dependencies needed for building libc++
against llvm-libc (it's used in `<complex>` header).
2026-02-25 09:27:59 -08:00
Alexey Samsonov
8cbbd5b561
[libc] Add backwards-compatibility macro to struct stat. (#182601)
Older code may use `st_atime` which recorded timestamps with one-second
precision, instead of `struct timespec st_atim` that is available in
later POSIX versions.

Add `#define st_atime` (& friends) to type declaration as suggested in
https://man7.org/linux/man-pages/man3/stat.3type.html
2026-02-24 22:28:30 +00:00
Jeff Bailey
d1e29a4bf1
[libc] Enable ifunc support in static startup (#182841)
Resolves ifunc targets before `main()` runs in static libc

This enables static binaries to use ifunc-based dispatch during early
process startup, so optimized implementations can be selected based on
CPU features. Without this relocation step in startup, those targets are
not ready when program code begins executing.

This change:
- adds IRELATIVE relocation handling for x86_64, AArch64, ARMv7 and RISC-V,
- reads `AT_HWCAP` / `AT_HWCAP2` from auxv and passes them to resolvers
where required (notably AArch64),
- runs IRELATIVE processing after base-address discovery and before TLS
setup,
- adds integration tests for both the ifunc path and the no-ifunc path,
- Changed the load bias type for ptrdiff_t to intptr_t to align with
IRELATIVE handling, which uses intptr_t for load bias calculations.
2026-02-24 21:03:05 +00:00
Anonmiraj
4ef6a8a16e
[libc][math] Refactor nextdown family to header-only (#181679)
closes #181678
2026-02-24 21:38:33 +02:00
Anonmiraj
4a1f565c85
[libc][math] Refactor setpayloadsig family to header-only (#183113)
closes : #181823
2026-02-24 20:47:20 +02:00
Zorojuro
fa29419041
[libc][math] Bfloat16 *= (Multiply assign) operator support (#182882)
This PR intends to add *= operator support for Bfloat16 and tests for
it.
2026-02-24 13:12:31 -05:00
Julian Pokrovsky
8ed290cd1d
[libc][math] Refactor asinpif16 to Header Only (#179021)
Resolves https://github.com/llvm/llvm-project/issues/178103

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
2026-02-24 19:55:16 +02:00
Anonmiraj
03388af319
[libc][math] Refactor setpayload family to header-only (#182922)
part of #181823
2026-02-24 19:50:07 +02:00
Mohamed Emad
05a039489d
[libc][math] Refactor bf16mul family to header-only (#182018)
Refactors the bf16mul math family to be header-only.

Closes https://github.com/llvm/llvm-project/issues/182017

Target Functions:
  - bf16mul
  - bf16mulf
  - bf16mulf128
  - bf16mull
2026-02-24 02:24:01 +00:00
Armillus
3b9c27d1fc
[libc][math] Refactor bf16addl implementation to header-only in src/__support/math folder. (#182561)
Resolves https://github.com/llvm/llvm-project/issues/181019
Part of https://github.com/llvm/llvm-project/issues/147386
2026-02-23 19:29:55 +00:00
Anonmiraj
b19a0e0107
[libc][math] Refactor getpayload family functions to header-only (#181824)
Refactors the payload_functions math family to be header-only.

part of: https://github.com/llvm/llvm-project/issues/181823

Target Functions:
  - getpayload
  - getpayloadbf16
  - getpayloadf
  - getpayloadf128
  - getpayloadf16
2026-02-23 21:19:48 +02:00
Mohamed Emad
5bccf343e6
[libc][math] Refactor bf16fmaf128 to header-only (#182009)
Close #181627
2026-02-23 21:06:20 +02:00
Mohamed Emad
13e6ffda47
[libc][math] Refactor fadd family to header-only (#182185)
Refactors the fadd math family to be header-only.

Closes https://github.com/llvm/llvm-project/issues/182184

Target Functions:
  - fadd
  - faddf128
  - faddl
2026-02-19 23:59:33 +00:00
Mohamed Emad
b19d21a1e5
[libc][math] Refactor fmax family to header-only (#182165)
Refactors the fmax math family to be header-only.

Closes https://github.com/llvm/llvm-project/issues/182164

Target Functions:
  - fmax
  - fmaxbf16
  - fmaxf
  - fmaxf128
  - fmaxf16
  - fmaxl
2026-02-19 23:40:52 +00:00
Joseph Huber
6cdee8f3d8
[libc] Fix RPC server with independent thread scheduling (#182211)
Summary:
The NVIDIA ITS protocol allows lanes to diverge inside of a warp. We
previously had contingencies around this, but there were cases where
issues would still show up under highly stressed usage.

The rules state that as long as the PC is the same, threads can
reconverge. This means that we can see a 'convergent' warp even when
they took completely divergent paths to get there. This resulted in the
'index' value in the RPC port lookup loop thinking we were in a
convergent group while all the indices were different. Fix this with a
broadcast to force the expected behavior

Additionally, we did not force that the threads were actually done with
their 'work_fn'. If the work included something that caused divergence
the other threads could continue and toggle the mailbox, resulting in
the server seeing unfinished work. Fix this with an explicit sync and
have one thread do it.

Add a test to make sure this actually works.
2026-02-19 17:38:49 -06:00
Mohamed Emad
6ac9c2ed7f
[libc][math] Refactor ceil family to header-only (#182121)
Refactors the ceil math family to be header-only.

Closes https://github.com/llvm/llvm-project/issues/182120

Target Functions:
  - ceil
  - ceilbf16
  - ceilf
  - ceilf128
  - ceilf16
  - ceill
2026-02-20 01:32:17 +02:00
DylanFleming-arm
efb397ce70
[libc][mathvec] Initial commit for LIBC vector math component (#173058)
Created mathvec directories and unittest framework for vector math
functions, as well as an initial implementation of vector expf, which is
presently CR for round-to-nearest.

---------

Co-authored-by: Pierre Blanchard <pierre.blanchard@arm.com>
2026-02-19 14:54:28 -05:00
Mohamed Emad
8a1dff765c
[libc][math][test] add missed mpfr test for ceilf128 (#182201)
This PR adds an MPFR test for `ceilf128` that was missed.
2026-02-19 08:43:42 +02:00
lntue
0ef0d6c8d7
[libc][math] Update BFloat16 basic operation exhaustive tests to include mixed signs. (#182131)
https://github.com/llvm/llvm-project/issues/181121
2026-02-18 16:58:35 -05:00
Serosh
3fafed392d
[libc][math] change bf16fmal to be header-only and constexpr-compat (#181666)
Closes: #181628 
Part of: #147386
2026-02-18 20:14:51 +02:00
AbdallahRashed
7ad2a632a3
[libc][math] Refactor bf16divl to header-only (#181535)
Part of https://github.com/llvm/llvm-project/issues/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
Closes #181025
2026-02-18 14:09:18 +00:00
Vachan
79f8eba842
[libc][math] Refactor logbl to header only (#181659)
Closes #175366
2026-02-18 14:03:17 +00:00
Atharv Mane
b92ab89ed6
[libc][math] Refactor f16add Math Functions to Header Only (#181777)
Resolves #181630
Part of #147386
2026-02-18 15:55:53 +02:00
Xinlong Chen
b576429342
[libc][math] Refactor tanpif to header only (#181525)
Part of https://github.com/llvm/llvm-project/issues/147386
2026-02-18 15:53:27 +02:00
Xinlong Chen
1cb86450d8
[libc][math] Refactor tanf16 to header only (#181523)
Part of https://github.com/llvm/llvm-project/issues/147386
2026-02-18 15:50:11 +02:00
Abhijeet
61616f2d59
[libc][math] Refactored bf16fmaf to Header Only (#181919)
Fixes #181626
2026-02-18 00:34:02 +02:00
Ash
cc5909b3e3
[libc][math] Refactor sincos implementation to header only (#177522)
Part of llvm#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

Closes #177638
2026-02-17 23:57:05 +02:00
bala-bhargav
0eaf12321e
[libc][math] Refactor bf16divf implementation to header-only in src/__support/math folder. (#181086) 2026-02-17 23:52:03 +02:00
Dhruv
9bf11863d1
[libc][math] Refactor logb implementation to header-only (#175719)
Fixes #175365
2026-02-17 21:34:38 +00:00
Viktor Moros
550c48b02e
[libc][math] Refactor bf16addf to header only (#181230)
Resolves #181017 
Part of #147386
2026-02-17 21:31:57 +00:00