Commit Graph

1832 Commits

Author SHA1 Message Date
sribee8
e38375310e [libc] wcscpy implementation (#142228)
Implemented wcscpy as well as tests for the function.

---------

Co-authored-by: Sriya Pratipati <sriyap@google.com>
2025-06-02 11:20:25 -07:00
wldfngrs
573545c712 [libc][math][c23] Add atanf16() function (#141612)
- Implementation of atan (tan inverse) function for 16-bit inputs.
- Exhaustive tests across the 16-bit input range
2025-06-01 13:36:16 +02:00
sribee8
328f40f408 [libc] wmemcmp nullptr handling (#142058)
Added nullptr handling for wmemcmp

---------

Co-authored-by: Sriya Pratipati <sriyap@google.com>
2025-05-30 14:38:01 -07:00
sribee8
226d06ba43 [libc] wmemcpy implementation (#142070)
Implemented wmemcpy and tests for the function.

---------

Co-authored-by: Sriya Pratipati <sriyap@google.com>
2025-05-30 14:23:18 -07:00
Uzair Nawaz
d721d4e280 [libc] Implemented wcspbrk (#142040)
Implemented wcspbrk and added tests
2025-05-30 14:12:22 -07:00
sribee8
d4791f56f3 [libc] wcsspn implementation (#142034)
Implemented wcsspn as well as tests for the function.

---------

Co-authored-by: Sriya Pratipati <sriyap@google.com>
2025-05-30 12:52:43 -07:00
lntue
6d3b72aa6e [libc] Pass config flags to unit tests. (#142085) 2025-05-30 10:00:14 -04:00
sribee8
a8c6a5017d [libc] wmemcmp implementation (#141880)
Implemented wmemcmp as well as tests for the function.

Fixes Issue #141857

---------

Co-authored-by: Sriya Pratipati <sriyap@google.com>
2025-05-29 13:34:23 -07:00
lntue
637e92bf47 [libc] Fix asin_test smoke test for DAZ modes due to mis-optimization on newer clang. (#141996) 2025-05-29 13:59:15 -04:00
Uzair Nawaz
6cf53da79d [libc] Implemented wmemset and added tests (#141691)
Implemented and tests the wmemset function in libc.
2025-05-29 10:31:49 -07:00
Alexey Samsonov
f22122aa7f [libc] Migrate sys/ tests to ErrnoCheckingTest. (#141871)
See PR #132823 for a previous change to sys/epoll tests, and prior
changes before that.

ErrnoCheckingTest ensures that errno is properly reset at the beginning
of the test case, and is validated at the end of it. This change removes
many instances of manual errno manipulation.
2025-05-28 22:18:22 -07:00
sribee8
cfba7718d2 WCSChr Implementation (#141690)
implemented wcschr and tests

---------

Co-authored-by: Sriya Pratipati <sriyap@google.com>
2025-05-28 14:08:03 -07:00
Joseph Huber
b4bc8c6f83 [libc] Implement efficient 'malloc' on the GPU (#140156)
Summary:
This is the big patch that implements an efficient device-side `malloc`
on the GPU. This is the first pass and many improvements will be made
later.

The scheme revolves around using a global reference counted pointer to
hand out access to a dynamically created and destroyed slab interface.
The slab is simply a large bitfield with one bit for each slab. All
allocations are the same size in a slab, so different sized allocations
are done through different slabs.

Allocation is thus searching for or creating a slab for the desired
slab, reserving space, and then searching for a free bit. Freeing is
clearing the bit and then releasing the space.

This interface allows memory to dynamically grow and shrink. Future
patches will have different modes to allow fast first-time-use as well
as a non-RPC version.
2025-05-28 08:21:43 -05:00
Tristan Ross
865fb9c1a5 [libc][uefi] add crt1 (#132150)
Adds `crt1.o` for the UEFI platform in the LLVM C library. This makes
things start to become useful.
2025-05-09 09:02:33 -07:00
lntue
78cc822aa6 [libc][math] Implement double precision acos correctly rounded for all rounding modes. (#138308)
We reduce computation of `acos` to `asin` as follow:

When `|x| < 0.5`:
```math
acos(x) = \frac{\pi}{2} - asin(x).
```
For `0.5 <= |x| < 1`, let
```math
u = \frac{1 - \left| x \right|}{2},
```
then
```math
acos(x) = \begin{cases}
  2 \cdot asin \left( \sqrt{u} \right) &, 0.5 \leq x < 1 \\
  \pi - 2 \cdot asin \left( \sqrt{u} \right) &, -1 < x \leq 0.5 
\end{cases}
```
2025-05-08 23:23:09 -04:00
Mikhail R. Gadelha
52e5889d0e [libc] Enable exp10m1f on RISC-V (#138768)
Previously, the test failed due to isnan() and isinf() not being
defined.

This patch follows other tests in the same directory and calls isnan and
isinf from the FBits class.

---------

Co-authored-by: OverMighty <its.overmighty@gmail.com>
2025-05-07 13:22:09 -03:00
Joseph Huber
7f5bf77c65 [libc] Temporarily disable hanging test on sm_60 (#138561) 2025-05-05 13:17:17 -05:00
enh-google
0e9fb5202c [libc] lsearch_test.cpp: put helpers in anonymous namespace. (#137964) 2025-04-30 11:55:35 -04:00
enh-google
a24457eb99 [libc] lfind_test.cpp: put helpers in an anonymous namespace. (#137821)
This matches other tests and allows the tests to be built together (as
Android is doing).
2025-04-29 18:16:59 -04:00
Schrodinger ZHU Yifan
6695976d16 Reland "[libc] build fix for sigsetjmp (#137047)" (#137214)
Reland `sigsetjmp` patches with build fixes.

We wrap every target replying on the epilogue library into conditional
checks.

---------

Co-authored-by: Petr Hosek <phosek@google.com>
2025-04-29 09:28:42 -04:00
lntue
ade502a8c4 [libc][math] Implement double precision asin correctly rounded for all rounding modes. (#134401)
Main algorithm:

The Taylor series expansion of `asin(x)` is:
```math
\begin{align*}
  asin(x) &= x + x^3 / 6 + 3x^5 / 40 + ... \\
       &= x \cdot P(x^2) \\
       &= x \cdot P(u) &\text{, where } u = x^2.
\end{align*}
```
For the fast path, we perform range reduction mod 1/64 and use degree-7
(minimax + Taylor) polynomials to approximate `P(x^2)`.

When `|x| >= 0.5`, we use the transformation:
```math
  u = \frac{1 + x}{2}
```
and apply half-angle formula to reduce `asin(x)` to:
```math
\begin{align*}
  asin(x) &= sign(x) \cdot \left( \frac{\pi}{2} - 2 \cdot asin(\sqrt{u}) \right) \\
       &= sign(x) \cdot \left( \frac{\pi}{2} - 2 \cdot \sqrt{u} \cdot P(u) \right).
\end{align*}
```
Since `0.5 <= |x| <= 1`, `|u| <= 0.5`. So we can reuse the polynomial
evaluation of `P(u)` when `|x| < 0.5`.

For the accurate path, we redo the computations in 128-bit precision
with degree-15 (minimax + Taylor) polynomials to approximate `P(u)`.
2025-04-25 09:55:21 -04:00
Krishna Pandey
5ff277462d [libc][stdfix] Implement idivfx functions in LLVM libc (#133005)
This PR implements the following 8 functions along with the tests.

```c++
int idivr(fract, fract);
long int idivlr(long fract, long fract);
int idivk(accum, accum);
long int idivlk(long accum, long accum);

unsigned int idivur(unsigned fract, unsigned fract);
unsigned long int idivulr(unsigned long fract, unsigned long fract);
unsigned int idivuk(unsigned accum, unsigned accum);
unsigned long int idivulk(unsigned long accum, unsigned long accum);
```

ref: https://www.iso.org/standard/51126.html

Fixes #129125

---------

Signed-off-by: krishna2803 <kpandey81930@gmail.com>
2025-04-25 07:58:16 -04:00
Harrison Hao
accee2b553 [libc][math][c23] Add atanhf16 C23 math function. (#132612)
Implementation of atanhf16 function for 16-bit inputs.

Closes: https://github.com/llvm/llvm-project/issues/132209
2025-04-25 07:53:52 -04:00
Anton
851f7c7421 [libc][math][c23] Add acospif16() function (#134664)
Addresses #132211  #132754
Part of #95250
2025-04-24 18:03:24 -04:00
Tejas Vipin
dde00f5e22 [libc][math] Improve performance test framework (#134501)
- Merges `BinaryOpSingleOutputPerf.h` and
`SingleInputSingleOutputPerf.h` files into a unified `PerfTest.h` and
update all performance tests to use this.
- Improve the output printed to log file for tests.
- Removes unused `run_diff` method and redundant `run_perf` call in
`BINARY_INPUT_SINGLE_OUTPUT_PERF_EX` (previously
`BINARY_OP_SINGLE_OUTPUT_PERF_EX`)
- Change `BINARY_INPUT_SINGLE_OUTPUT_PERF_EX` and
`SINGLE_INPUT_SINGLE_OUTPUT_PERF` to not define `main`
2025-04-24 07:22:21 -04:00
gulfemsavrun
0d00b6bc3b Revert "[libc] build fix for sigsetjmp (#137047)" (#137077)
This reverts commit f07511a0e0.

This reverts commit 5bb4cf9d91.

It caused a CMake configuration issue.
2025-04-23 15:49:55 -07:00
Schrodinger ZHU Yifan
5bb4cf9d91 [libc] implement sigsetjmp/siglongjmp for x86-64 (#136072) 2025-04-23 14:19:47 -04:00
Daniel Thornburgh
710ffb69bf [libc] Fix warnings for freelist_heap_test/fuzz (#136634)
Fixes #122367
2025-04-22 11:11:31 -07:00
Tsz Chan
f5c5f9f926 [libc] Implement getitimer and setitimer, add proxy headers for itimerval (#134773)
#133983
2025-04-14 13:39:42 -07:00
Muhammad Bassiouni
785d69e317 [libc][test] make str_to_float_comparison_test independent of C++ headers. (#133978)
This is an attempt to move away from C++ headers to be able to run the
test without `libcxx`.
closes #129838

cc @lntue @RossComputerGuy
2025-04-09 14:11:02 -07:00
wldfngrs
fdf20941a8 [libc][math] Fix signaling NaN handling for math functions. (#133347)
Add tests for signaling NaNs, and fix function behavior for handling
signaling NaN input.

Fixes https://github.com/llvm/llvm-project/issues/124812
2025-04-08 15:23:38 +02:00
Michael Jones
e8b52acca2 [libc][NFC] replace NULL with nullptr (#134464)
Simple cleanup
2025-04-04 16:55:43 -07:00
Michael Jones
4c182df633 [libc] Fix suseconds_t definition and utimes_test (#134326)
The main issue was that the kernel expected `suseconds_t` to be 64 bits
but ours was 32. This caused inconsistent failures since all valid
`suseconds_t` values are less than 1000000 (1 million), and some
configurations caused `struct timeval` to be padded to 128 bits.

Also: forgot to use TEST_FILE instead of FILE_PATH in some places.
2025-04-04 12:53:46 -07:00
Michael Jones
c0079ba3dd [libc] Make utimes_test more stable (#134321)
The test for utimes added in #134167 might fail if the file for one test
hasn't been cleaned up by the OS before the second test starts. This
patch makes the tests use different files.
2025-04-03 16:53:55 -07:00
Aditya Tejpaul
d33ae41c62 [libc] Implemented utimes (Issue #133953) (#134167)
This pull request implements the `utimes` command in libc ([Issue
#133953](https://github.com/llvm/llvm-project/issues/133953)).

- [x] Add the implementation of `utimes` in `/src/sys/time`.
- [x] Add tests for `utimes` in `/test/src/sys/time`. 
- [x] Add `utimes` 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 `utimes` to
[include/sys/time.yaml](https://github.com/llvm/llvm-project/blob/main/libc/include/sys/time.yaml)
2025-04-03 16:19:12 -07:00
Abhinav Kumar
51d1c72886 [libc] Added support for fixed-points in `is_signed and is_unsigned`. (#133371)
Fixes #133365

## Changes Done
- Changed the signed checking to 
```cpp
struct is_signed : bool_constant<((is_fixed_point<T> || is_arithmetic_v<T>) && (T(-1) < T(0)))>
```
in ``/libc/src/__support/CPP/type_traits/is_signed.h``. Added check for
fixed-points.
- But, got to know that this will fail for ``unsigned _Fract`` or any
unsigned fixed-point because ``unsigned _Fract`` can’t represent -1 in
T(-1), while ``unsigned int`` can handle it via wrapping.
- That's why I explicity added ``is_signed`` check for ``unsigned``
fixed-points.
- Same changes to ``/libc/src/__support/CPP/type_traits/is_unsigned.h``.
- Added tests for ``is_signed`` and ``is_unsigned``.
2025-04-02 16:41:47 -04:00
lntue
44b87e4206 [libc] Reduce the range of hypotf exhaustive test to be run automatically. (#133944)
The current setup of `hypotf` exhaustive tests might take days to
finish.
2025-04-01 13:29:28 -04:00
lntue
65ad6267e8 [libc] Fix atan2f128 test for aarch64. (#133924) 2025-04-01 11:37:57 -04:00
lntue
8741412bdf [libc][math] Implement a fast pass for atan2f128 with 1ULP error using DyadicFloat<128>. (#133150)
Part of https://github.com/llvm/llvm-project/issues/131642.
2025-04-01 10:57:32 -04:00
Tejas Vipin
8078665bca [libc][math][c23] Add hypotf16 function (#131991)
Implement hypot for Float16 along with tests.
2025-03-31 10:06:28 -04:00
Tejas Vipin
d22e35be17 [libc][math][c23] Add asinhf16 function (#131351)
Implement asinh for Float16 along with tests. Closes #131001
2025-03-29 13:54:52 +01: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
Joseph Huber
9243f99d17 [libc] Add support for C++20 'atomic_ref' type (#132302)
Summary:
C++20 introduced an atomic reference type, which more easily wraps
around the standard way of dealing with atomics. Instead of a dedicated
type, it allows you to treat an existing allocation as atomic.

This has no users yet, but I'm hoping to use it when I start finalizing
my GPU allocation interface, as it will need to handle atomic values
in-place that can't be done with placement new. Hopefully this is small
enough that we can just keep it in-tree until it's needed, but I'll
accept holding it here until it has a user.

I added one extension to allow implicit conversion and CTAD.
2025-03-25 13:28:49 -05:00
Joseph Huber
6aed161cb9 [libc][NFC] Remove incorrect file level dependency in CMake (#132937)
Summary:
CMake doesn't support this type of dependency so it keeps emitting a
warning. Just remove it, because it's not doing anything currently
anyway. If we really wanted this to work you'd need to add a custom
target that has a dependency on the output of a custom command, but that
would only be worhwhile if we ever expected this file to change.
2025-03-25 09:33:25 -05:00
Alexey Samsonov
5a668bdb98 [libc] Migrate sys/epoll tests to use ErrnoCheckingTest. (#132823)
This is similar to PR #132107 but for tests for sys/epoll.h functions.

ErrnoCheckingTest ensures that errno is properly reset at the beginning
of the test case, and is validated at the end of it, so that the manual
code such as the one proposed in PR #131650 would not be necessary.
2025-03-24 13:54:46 -07:00
Roland McGrath
6f4ddefe5b [libc] Remove extraneous ASSERT_ERRNO_* macro definitions (#132812)
These are no longer meant to be defined in each
framework-specific header, but ZxTest.h wasn't updated.
2025-03-24 12:25:43 -07:00
Tejas Vipin
1f96788701 [libc][math] Fix range and comments in exhaustive hypotf_test (#131769)
`((23U + 127U) << 23) + 1` evaluates to `(2^23)+1` as opposed to `2^24`,
so should instead be `(24U + 127U) << 23`. Additionally, range for both
inputs is inclusive of STOP. The comments have been updated reflecting
these changes.
2025-03-24 12:32:11 -04: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
Harrison Hao
ee3e17d67f [libc][math][c23] Add acoshf16 C23 math function. (#130588)
Implementation of acoshf16 function for 16-bit inputs.
2025-03-22 22:08:34 -04:00