183 Commits

Author SHA1 Message Date
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
Joseph Huber
b5745e1e28
[libc] Support basic 'complex.h' functionality on GPUs (#189999)
Summary:
This PR adds the basic complex functions needed by some targets. This is
an attempt to provide the standard interface needed by
'https://github.com/llvm/llvm-project/pull/187831'
2026-04-01 13:27:24 -05: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
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
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
Xinlong Chen
458096d5f8
[libc][math][c23] Add atan2f16 function (#183531)
Add atan2f16 function

closes https://github.com/llvm/llvm-project/issues/180969
Part of https://github.com/llvm/llvm-project/issues/95250.

also refactor to header only, it's a part of
https://github.com/llvm/llvm-project/issues/147386
2026-03-13 22:12:44 +02:00
Anonmiraj
785581213c
[libc][math] Implement C23 half precision erf function (#179251)
The implementation reuses the approach in `erff`


Closes #133112
2026-03-13 10:16:59 -04:00
Zorojuro
ad054822eb
[libc][math][c23] Add hypotbf16 function (#183460)
This PR intends to add hypotbf16 higher math function for BFloat16 type
along with the tests.
2026-03-13 10:11:33 -04:00
Shikhar Soni
a7d1a87b30
[libc][math][c23] Add log10p1f16 C23 math function (#184739)
Closes #133202

---------

Signed-off-by: Shikhar Soni <shikharish05@gmail.com>
2026-03-13 09:59:26 -04:00
Zorojuro
0bebee6782
[libc][math][c++23] Add Fmabf16 math function (#182836)
closes #180171 
part of #177259 

Here are some extra changes apart from the usual which were needed
1. `libc/src/__support/FPUtil/generic/add_sub.h` → +0 -0 error
2. `libc/src/__support/FPUtil/generic/FMA.h` → implemented to handle
fmabf16(Normal,Normal,+/-INF)

```jsx
/home/runner/work/llvm-project/llvm-project/libc/test/src/math/fmabf16_test.cpp:62: FAILURE
Failed to match __llvm_libc_23_0_0_git::fmabf16(x, y, z) against LIBC_NAMESPACE::testing::mpfr::get_mpfr_matcher<mpfr::Operation::Fma>( input, __llvm_libc_23_0_0_git::fmabf16(x, y, z), 0.5, mpfr::RoundingMode::Nearest).
Input decimal: x: 338953138925153547590470800371487866880.00000000000000000000000000000000000000000000000000 y: 338953138925153547590470800371487866880.00000000000000000000000000000000000000000000000000 z: -inf
 First input bits: 0x7F7F = (S: 0, E: 0x00FE, M: 0x007F)
Second input bits: 0x7F7F = (S: 0, E: 0x00FE, M: 0x007F)
 Third input bits: (-Infinity)
Libc result: nan
MPFR result: -inf
Libc floating point result bits: (NaN)
              MPFR rounded bits: (-Infinity)
```

1. ~~`libc/src/__support/FPUtil/bfloat16.h` → to handle *= operator for
Bfloat16 ( uses the already available mult operator)~~
moved to  #182882 

The exhaustive test currently includes subnormal range and for checking
for specific edge cases . This is due to the repeated failure at <2^32
input space specifically only for ubuntu 24.04 and 24.04-arm
The removed tests included -> PositiveRange and NegativeRange for
Normals and an extra positive test for subnormals/Denormals

Let me know if there are any changes expected or anything I missed in
this .
 cc: @lntue @krishna2803 @overmighty
2026-03-13 05:33:52 +00:00
sohail
cd7e200e42
[libc][math] Add cbrtbf16 math function (#180327)
Add a bfloat16 implementation of cbrt along with corresponding smoke
tests and an MPFR-based exhaustive unit test.

Fixes #179729
2026-03-10 12:59:26 -04: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
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
fineg74
ab3d742f6f
[libc] Add basic support for building SPIR-V libraries (#181049)
This is to add support to build libc for building with spirv backend,
for use with OpenMP kernels
2026-02-16 20:27:39 -06:00
Joseph Huber
a512065206 [libc] Do not use stack protectors or frame pointers on GPU
Summary:
This doesn't work because they're unused in some contexts. Added in
https://github.com/llvm/llvm-project/pull/178136
2026-01-28 08:24:48 -06:00
Krishna Pandey
1fda257728
[libc][math][c++23] Add log_bf16 math function (#157811)
This PR adds log_bf16 higher math function for BFloat16 type along with
the tests.

---------

Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-09-24 20:47:10 +05:30
Krishna Pandey
8dda18f836
[libc][math][c++23] Add sqrtbf16 math function (#156654)
This PR adds sqrtbf16 higher math function for BFloat16 type along with
the tests.

---------

Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-09-06 14:36:02 +05:30
Krishna Pandey
96b1dfb57f
[libc][math][c++23] Add fmodbf16 math function (#155575)
This PR adds fmodbf16 basic math function for BFloat16 type along with
the tests.

---------

Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-09-03 22:20:07 +05:30
Joseph Huber
c7df8839d8
[libc] Use intermediate float operations on the GPU (#155869)
Summary:
Move the GPU config to the common directory instead of copying it and
enable the intermediate float option in the math library.
2025-08-28 13:03:55 -05:00
Krishna Pandey
a985be6fdf
[libc][math][c++23] Add scalb{,l}nbf16 math functions (#155569)
This PR adds the following basic math functions for BFloat16 type along
with the tests:
- scalbnbf16
- scalblnbf16

---------

Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-08-28 20:29:03 +05:30
Krishna Pandey
691f231579
[libc][math][c++23] Add totalorder{,mag}bf16 math functions (#155568)
This PR adds the following basic math functions for BFloat16 type along
with the tests:
- totalorderbf16
- totalordermagbf16

---------

Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-08-28 19:37:07 +05:30
Krishna Pandey
3d2b282044
[libc][math][c++23] Add {canonicalize,iscanonical,fdim,copysign,issignaling}bf16 math functions (#155567)
This PR adds the following basic math functions for BFloat16 type along
with the tests:
- canonicalizebf16
- iscanonicalbf16
- fdimbf16
- copysignbf16
- issignalingbf16

---------

Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-08-27 22:31:17 +05:30
Krishna Pandey
f005e2cb7a
[libc][math][c++23] Add {modf,remainder,remquo}bf16 math functions (#154652)
This PR adds the following basic math functions for BFloat16 type along
with the tests:
- modfbf16
- remainderbf16
- remquobf16

---------

Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
Co-authored-by: OverMighty <its.overmighty@gmail.com>
2025-08-27 11:42:09 +05:30
Krishna Pandey
c11acac4dc
[libc][math][c++23] Add {frexp,ilogb,ldexp,llogb,logb}bf16 math functions (#154427)
This PR adds the following basic math functions for BFloat16 type along
with the tests:
- frexpbf16
- ilobbf16
- ldexpbf16
- llogbbf16
- logbbf16

---------

Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-08-25 11:46:25 +05:30
Krishna Pandey
60743358d1
[libc][math][c++23] Add {nearbyint,rint,lrint,llrint,lround,llround}bf16 math functions (#153882)
This PR adds the following basic math functions for BFloat16 type along
with the tests:
- nearbyintbf16
- rintbf16
- lrintbf16
- llrintbf16
- lroundbf16
- llroundbf16

---------

Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-08-24 20:51:02 +05:30
Krishna Pandey
699f15426f
[libc][math][c++23] Add nanbf16 math function (#153995)
This PR adds the nanbf16 basic math function for BFloat16 type along
with the tests.

---------

Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-08-23 14:45:53 +05:30
Krishna Pandey
de6bd152b9
[libc][math][c++23] Add {get,set}payloadbf16 and setpayloadsigbf16 math functions (#153994)
This PR adds the following basic math functions for BFloat16 type along
with the tests:
- getpayloadbf16
- setpayloadbf16
- setpayloadsigbf16

---------

Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-08-23 01:02:02 +05:30
Krishna Pandey
eac19d46d8
[libc][math][c++23] Add next{after,down,toward,up}bf16 math functions (#153993)
This PR adds the following basic math functions for BFloat16 type along
with the tests:
- nextafterbf16
- nextdownbf16
- nexttowardbf16
- nextupbf16

---------

Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
Co-authored-by: OverMighty <its.overmighty@gmail.com>
2025-08-22 22:01:49 +05:30
Leandro Lacerda
15a192cde5
[libc] Enable double math functions on the GPU (#154857)
This patch adds the `acos` math function to the NVPTX build. It also
adds the `sincos` math function to the `math.h` header.
2025-08-22 06:52:13 -05:00
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