Mikhail R. Gadelha
36b4ffeb7e
[libc] Enable utimes function for riscv ( #139181 )
...
RV32 uses SYS_utimensat_time64 instead of SYS_utimensat but the call is
the same.
2025-05-13 18:59:49 -03:00
Mikhail R. Gadelha
66bb445d5c
[libc] Enable poll function for riscv ( #139180 )
...
RV32 uses SYS_ppoll_time64 instead of SYS_ppoll, but the call is the
same.
2025-05-13 18:59:28 -03: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
Mikhail R. Gadelha
ca0c9bcf10
[libc] Update riscv entrypoints to be on par with x86 ( #138597 )
...
This patch updates the riscv entrypoints with almost all functions that
are currently supported on x86. I left six functions commented, as I'll
send separate PRs to enable them:
* poll: needs a new syscall implementation
* utimes: needs a new syscall implementation
* setitimer: test never finished in rv32
* getitimer: test fails in rv32
* exp10m1f: test case doesn't build but it's an easy fix
* sqrtulk: needs to be implemented
I also added the 16-bit fp functions, however, they are not enabled due
to a cmake check in float16-macros.h. To enable 16-bit fp in riscv, we
need to update the buildbots with a clang version that includes the fix
from commit PR #119481
2025-05-06 13:56:58 -03:00
Schrodinger ZHU Yifan
a1803ea063
[libc] implement sigsetjmp/siglongjmp for riscv ( #137992 )
...
See https://godbolt.org/z/jo7s6j7sq for compiled code.
```c++
#if __riscv_xlen == 64
#define STORE(A, B, C) "sd " #A ", %c[" #B "](" #C ")\n\t"
#define LOAD(A, B, C) "ld " #A ", %c[" #B "](" #C ")\n\t"
#elif __riscv_xlen == 32
#define STORE(A, B, C) "sw " #A ", %c[" #B "](" #C ")\n\t"
#define LOAD(A, B, C) "lw " #A ", %c[" #B "](" #C ")\n\t"
#else
#error "Unsupported RISC-V architecture"
#endif
namespace LIBC_NAMESPACE_DECL {
[[gnu::naked]]
LLVM_LIBC_FUNCTION(int, sigsetjmp, (sigjmp_buf, int)) {
// clang-format off
asm("beqz a1, .Lnosave\n\t"
STORE(ra, retaddr, a0)
STORE(s0, extra, a0)
"mv s0, a0\n\t"
"call %c[setjmp]\n\t"
"mv a1, a0\n\t"
"mv a0, s0\n\t"
LOAD(s0, extra, a0)
LOAD(ra, retaddr, a0)
"tail %c[epilogue]\n"
".Lnosave:\n\t"
"tail %c[setjmp]"
// clang-format on
::[retaddr] "i"(offsetof(__jmp_buf, sig_retaddr)),
[extra] "i"(offsetof(__jmp_buf, sig_extra)), [setjmp] "i"(setjmp),
[epilogue] "i"(sigsetjmp_epilogue)
: "a0", "a1", "s0");
}
```
2025-05-04 16:21:48 -04:00
Schrodinger ZHU Yifan
9ebaa9d483
[libc] implement aarch64 sigsetjmp ( #136706 )
...
- **[libc][aarch64] implement sigsetjmp**
On top of https://github.com/llvm/llvm-project/pull/136072
See also https://github.com/llvm/llvm-project/issues/137055 for remarks
on naked attributes.
```c++
//===-- Implementation of setjmp ------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "src/setjmp/sigsetjmp.h"
#include "hdr/offsetof_macros.h"
#include "src/__support/common.h"
#include "src/__support/macros/config.h"
#include "src/setjmp/setjmp_impl.h"
#include "src/setjmp/sigsetjmp_epilogue.h"
namespace LIBC_NAMESPACE_DECL {
[[gnu::naked]]
LLVM_LIBC_FUNCTION(int, sigsetjmp, (sigjmp_buf, int)) {
asm(R"(
cbz w1, %c[setjmp]
str x30, [x0, %c[retaddr]]
str x19, [x0, %c[extra]]
mov x19, x0
bl %c[setjmp]
mov w1, w0
mov x0, x19
ldr x30, [x0, %c[retaddr]]
ldr x19, [x0, %c[extra]]
b %c[epilogue])" ::[retaddr] "i"(offsetof(__jmp_buf, sig_retaddr)),
[extra] "i"(offsetof(__jmp_buf, sig_extra)), [setjmp] "i"(setjmp),
[epilogue] "i"(sigsetjmp_epilogue)
: "x0", "x1", "x19", "x30");
}
} // namespace LIBC_NAMESPACE_DECL
```
2025-04-29 16:37:25 -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
Krishna Pandey
d8e81756b3
[libc][stdfix] Fix riscv entrypoints for idivfx ( #137499 )
...
Fixes a typo in riscv entrypoints that caused buildbot failures.
https://lab.llvm.org/buildbot/#/builders/196/builds/7352
Signed-off-by: krishna2803 <kpandey81930@gmail.com>
2025-04-27 06:54:01 -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
gulfemsavrun
0d00b6bc3b
Revert "[libc] build fix for sigsetjmp ( #137047 )" ( #137077 )
...
This reverts commit f07511a0e0d2ac9bee9ae12a9ad68e279e352634.
This reverts commit 5bb4cf9d9189c41de50adffd960eb2188140eb9c.
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
Tsz Chan
f5c5f9f926
[libc] Implement getitimer and setitimer, add proxy headers for itimerval ( #134773 )
...
#133983
2025-04-14 13:39:42 -07:00
Michael Jones
556fb4c9af
[libc] Disable sin/cospif16 on aarch64 ( #134918 )
...
The tests are failing and it's unclear why. Disabling for now until a
fix can be implemented. See
https://github.com/llvm/llvm-project/issues/134917 for details.
2025-04-08 12:42:44 -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
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
Michael Jones
3a5d77608b
[libc] Update headers on aarch64 ( #133180 )
...
The entrypoints for aarch64 are mostly up to date, but the headers are
not. This patch fixes that, and also makes explicit the dependency from
OSUtils/linux on sys/syscalls.h
2025-03-27 09:05:24 -07:00
Harrison Hao
ebcf1de065
[libc][math] Disable acoshf16 Test on AArch64 to resolve test failures. ( #132580 )
2025-03-23 11:19:20 +08: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
lntue
a17b03f0e4
[libc][math] Implement fast pass for double precision atan function. ( #132333 )
...
Implement fast pass for double precision `atan` using range reduction
modulo 1/64 and degree-9 Taylor polynomial.
Relative error is bounded by 2^-66.
2025-03-21 14:12:06 -04:00
Krishna Pandey
bda87e0a09
[libc][sched] Implement CPU_ZERO, CPU_ISSET, CPU_SET macros ( #131524 )
...
This PR implements the following macros for `sched.h`:
- `CPU_ZERO`
- `CPU_ISSET`
- `CPU_SET`
Fixes #124642
---------
Signed-off-by: krishna2803 <kpandey81930@gmail.com>
2025-03-19 13:44:41 -04:00
Connector Switch
af7c8c475a
[libc] Implement search/lsearch ( #131431 )
...
ref:
- https://man7.org/linux/man-pages/man3/lsearch.3.html
- https://pubs.opengroup.org/onlinepubs/009696699/functions/lsearch.html
2025-03-19 08:40:59 +08:00
Roland McGrath
460b9cda81
[libc] Disable dl_iterate_phdr entrypoint for linux fullbuild ( #131893 )
...
There are some issues with typedef conflicts between libc headers
and Linux kernel headers arising. Disable building the new code
for Linux for now.
2025-03-18 12:26:22 -07:00
Roland McGrath
123c0040d4
[libc] Define (stub) dl_iterate_phdr ( #131436 )
...
This fleshes out the <link.h> a little more, including the
`struct dl_phdr_info` type and declaring the dl_iterate_phdr
function. There is only a no-op implementation without tests, as
for the existing dlfcn functions.
2025-03-18 11:38:33 -07:00
Connector Switch
ab22f652a4
[libc] implement strings/str{n}casecmp_l ( #130407 )
...
ref:
https://pubs.opengroup.org/onlinepubs/9799919799/functions/strcasecmp_l.html
This patch introduces the `strcasecmp_l` function. At present, the
locale parameter is ignored, making it a stub implementation. This is
consistent with how other locale-related functions, such as `islower_l`,
are treated in our codebase as well as in
[musl](https://github.com/bminor/musl/blob/master/src/string/strcasecmp.c )
and
[bionic](https://cs.android.com/android/platform/superproject/main/+/main:bionic/libc/bionic/strings_l.cpp ).
---------
Co-authored-by: Michael Jones <michaelrj@google.com>
2025-03-12 10:49:04 +08:00
Connector Switch
a5588b6d20
[libc] implement strings/ffs ( #129892 )
...
This patch adds the `strings/ffs` function.
ref: https://pubs.opengroup.org/onlinepubs/9799919799/functions/ffs.html
Closes : #122054 .
2025-03-08 09:31:18 +08:00
Ajay Raj
9a65dc9513
Add sysexits.h header with BSD exit codes (total-18) ( #126112 )
...
This pull request adds a new header file, SysExits.h, to the LLVM
project. The header includes 18 BSD exit code.
2025-03-06 16:25:14 -08:00
Michael Jones
64ae0a102f
[libc] implement l64a ( #129099 )
...
Adds l64a, which generates the base 64 string expected by a64l.
2025-02-27 12:48:39 -08:00
Krishna Pandey
f6bfa33cdb
[libc][stdfix] Implement fixed point bitsfx functions in llvm libc ( #128413 )
...
Fixes #113359
---------
Signed-off-by: krishna2803 <kpandey81930@gmail.com>
2025-02-27 13:05:27 -05:00
Michael Jones
8beec9fc48
[libc] implement a64l ( #128758 )
...
Implement the posix function a64l.
Standard:
https://pubs.opengroup.org/onlinepubs/9799919799/functions/a64l.html
2025-02-25 13:57:13 -08:00
Michael Jones
f4a80180f1
[libc] Move fileno and fdopen to fullbuild only ( #128762 )
...
Both fileno and fdopen require interfacing with the opaque FILE struct,
so they shouldn't be enabled in overlay mode. This patch moves both into
fullbuild only on all platforms.
Fixes #128643
2025-02-25 13:56:20 -08:00
wldfngrs
3e284554a8
[libc][math][c23] Add acosf16() function ( #127731 )
...
- Implementation of acosf16 (inverse cosine) function for 16-bit inputs.
- Exhaustive tests across the 16-bit input range.
2025-02-23 19:46:46 +01:00
Petr Hosek
00637b7dfb
[libc] Add strftime_l ( #127767 )
...
This is a (no-op) locale version of strftime.
Fixes: https://github.com/llvm/llvm-project/issues/106630
2025-02-21 10:50:32 -08:00
Zaky Hermawan
ef49760fa9
[libc][POSIX][unistd] implement getsid ( #127341 )
...
Fixes https://github.com/llvm/llvm-project/issues/126603
---------
Signed-off-by: ZakyHermawan <zaky.hermawan9615@gmail.com>
2025-02-19 14:26:18 -08:00
Petr Hosek
a2b4d4e756
Revert "[libc] Add strftime_l" ( #127766 )
...
Reverts llvm/llvm-project#127708
2025-02-19 00:39:33 -08:00
Petr Hosek
9072ba71ca
[libc] Add strftime_l ( #127708 )
...
This is a (no-op) locale version of strftime.
2025-02-18 23:54:45 -08:00
Michael Jones
398f865499
[libc] Implement strftime ( #122556 )
...
Implements the posix-specified strftime conversions for the default
locale, along with comprehensive unit tests. This reuses a lot of design
from printf, as well as the printf writer.
Roughly based on #111305 , but with major rewrites.
2025-02-14 15:56:55 -08:00
Krishna Pandey
1f51038036
[libc][stdfix] Implement countlsfx functions in libc. ( #126597 )
...
fixes #113357
---------
Signed-off-by: krishna2803 <kpandey81930@gmail.com>
2025-02-12 14:12:44 -05:00
wldfngrs
7ee56b9afc
[libc][math][c23] Add asinf16() function ( #124212 )
...
Co-authored-by: OverMighty <its.overmighty@gmail.com>
2025-02-10 12:38:55 +01:00
Joseph Huber
7623d91784
Revert "[libc][stdfix] Fix buildbot failure because of a typo. ( #126291 )"
...
This reverts commit bada9220b87e73c0f4a498b82f883e17eda928d1.
Revert "[libc][stdfix] Implement fixed point `countlsfx` functions in llvm-libc (#125356 )"
This reverts commit f2a1103b323492160d7d27a1575fbda709b49036.
2025-02-07 14:34:40 -06:00
Krishna Pandey
f2a1103b32
[libc][stdfix] Implement fixed point countlsfx functions in llvm-libc ( #125356 )
...
fixes #113357
2025-02-07 13:53:17 -05:00
c8ef
6807164500
[libc] Add the <endian.h> header. ( #125168 )
...
Closes [#124631 ](https://github.com/llvm/llvm-project/issues/124631 ).
ref:
https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/endian.h.html
This patch adds the implementation of `endian.h`, which includes the
header itself and three related macros. These macros in the header rely
on the compiler preprocessor, similar to how
https://github.com/llvm/llvm-project/blob/main/libc/src/__support/endian_internal.h
does. Hopefully this will meet the requirements for compiling llvm with
llvm-libc.
2025-02-07 09:20:18 +08:00
Alex Prabhat Bara
74c2e9a82a
[libc] generate sys/wait.h for aarch64 ( #125171 )
...
Fixes : #125102
2025-02-06 13:15:45 -08:00