Commit Graph

941 Commits

Author SHA1 Message Date
sribee8
47e28d9cd1 [libc] wcscspn implementation (#146158)
Implemented wcscspn and tests.

---------

Co-authored-by: Sriya Pratipati <sriyap@google.com>
2025-07-01 15:56:09 +00:00
Uzair Nawaz
7a33b709b1 [libc] wcstok implementation (#145989)
Implemented wcstok and added tests
2025-06-30 10:41:00 -07:00
Schrodinger ZHU Yifan
a8f460d1dc [libc] implement sigsetjmp for thumb/thumb2/armv7-a (#138147) 2025-06-30 12:32:14 -04:00
sribee8
ac7e391035 [libc] Implemented wcsnlen (#145610)
Implemented wcsnlen and tests for the function.

---------

Co-authored-by: Sriya Pratipati <sriyap@google.com>
2025-06-27 16:51:37 +00: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
Uzair Nawaz
2db0289abe [libc] Implemented wctomb (#145554)
Implemented wctomb by calling internal wcrtomb function
Added tests
2025-06-25 13:23:47 -07:00
sribee8
bc5e5c0114 [libc] wcpncpy implementation (#145430)
Implemented wcpncpy and tests.

---------

Co-authored-by: Sriya Pratipati <sriyap@google.com>
2025-06-23 23:35:28 +00:00
sribee8
10d46cf0d5 [libc] mbtowc implementation (#145405)
Implemented mbtowcs and tests for the function.

---------

Co-authored-by: Sriya Pratipati <sriyap@google.com>
2025-06-23 23:25:13 +00:00
sribee8
b215c8e18f [libc] wcpcpy implementation (#144802)
Implemented wcpcpy and tests.

---------

Co-authored-by: Sriya Pratipati <sriyap@google.com>
2025-06-23 18:31:13 +00:00
Uzair Nawaz
a911543437 [libc] Implemented wcrtomb internal function and public libc function (#144596)
Implemented internal wcrtomb function using the CharacterConverter class
public libc function calls this internal function to perform the
conversion
2025-06-20 14:43:00 -07:00
sribee8
d078ce7c98 [libc] mbrtowc implementation (#144760)
implemented the internal and public mbrtowc as well as tests for the
public function.

---------

Co-authored-by: Sriya Pratipati <sriyap@google.com>
2025-06-20 20:00:59 +00:00
Aly ElAshram
5645d67109 Implement sigsetjmp and siglongjmp for darwin/aarch64 (#139555) 2025-06-19 09:15:59 -04:00
Amy Huang
ca38027c03 Revert "Turn LIBC_COPT_STRING_UNSAFE_WIDE_READ on by default" (#144167)
Reverts llvm/llvm-project#144163 because for some reason I didn't
realize there are ASan tests.
2025-06-13 15:30:28 -07:00
Amy Huang
a591bd222b Turn LIBC_COPT_STRING_UNSAFE_WIDE_READ on by default (#144163)
Configure strlen to use unsafe implementation because it is faster.

Because this is undefined behavior it could cause sanitizers to fail.
2025-06-13 15:09:57 -07:00
Uzair Nawaz
b184672ec7 [libc] Implemented wmemmove (#142245)
Implemented wmemmove and added tests
2025-06-13 16:48:24 +00:00
Michael Jones
5a6a4b6ba6 [libc] Implement perror (#143624)
The perror function writes an error message directly to stderr. This
patch adds an implementation, tests, and header generation details.
2025-06-12 10:45:47 -07:00
W. Turner Abney
4039fdb7ba [libc] add ioctl (#141393)
Closes #85275
Closes #90317
Updates #97191

---------

Co-authored-by: Joseph Huber <huberjn@outlook.com>
Co-authored-by: Michael Jones <michaelrj@google.com>
2025-06-12 09:20:32 -07:00
lntue
d87eea35fa [libc] Move libc_errno.h to libc/src/__support and make LIBC_ERRNO_MODE_SYSTEM to be header-only. (#143187)
This is the first step 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
2025-06-11 16:25:27 -04: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
sribee8
22dd9a2483 [libc] wmemchr implementation (#142640)
Implemented wmemchr and tests.
Fixes: #121183

---------

Co-authored-by: Sriya Pratipati <sriyap@google.com>
2025-06-03 17:05:14 -07:00
sribee8
2ff2a076cc [libc] wcsncpy implementation (#142237)
Implemented wcsncpy and tests for the function.

---------

Co-authored-by: Sriya Pratipati <sriyap@google.com>
2025-06-03 16:37:14 -07:00
sribee8
3887c23059 [libc] wcscat implementation (#142243)
Implemented wcscat and tests.

---------

Co-authored-by: Sriya Pratipati <sriyap@google.com>
2025-06-03 09:58:08 -07:00
Uzair Nawaz
c8741851d1 [libc] Implemented wcsncmp (#142429)
Implemented wcsncmp and added tests
2025-06-02 16:05:47 -07:00
sribee8
e3d1a33b7e [libc] wcsstr implementation (#142440)
Implemented wcsstr and tests.
fixes #124348

---------

Co-authored-by: Sriya Pratipati <sriyap@google.com>
2025-06-02 16:05:12 -07:00
sribee8
9422abf9eb [libc] wcsncat implementation (#142431)
Implemented wcsncat and tests.

---------

Co-authored-by: Sriya Pratipati <sriyap@google.com>
2025-06-02 15:20:10 -07:00
Uzair Nawaz
dabe983e7e [libc] Implemented wcsrchr (#142436)
fixes #124347 
Implemented wcsrchr and added tests
2025-06-02 15:18:44 -07:00
Uzair Nawaz
62af2a5ae2 [libc] Implemented wcscmp (#142423)
Implemented wcscmp and added tests
2025-06-02 15:16:14 -07:00
Uzair Nawaz
c80c452525 [libc] Implemented wmempcpy (#142067)
Implemented wmempcpy and added tests
2025-06-02 15:00:46 -07:00
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
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
Aly ElAshram
bfd7024b0d [LibC] Refactor arm64 to aarch64 for darwin. (#141509)
Fixes [#141505](https://github.com/llvm/llvm-project/issues/141505)

The main intention behind this PR is to update the
LibCTargetArchitecture for arm64 to use the implementation of aarch64
architecture and not arm32.

This is a historical issue , and is a blocker to issue #138407. 

The intended fix is to set the `LibCTargetArchitecture` to aarch64 when
it matches arm64 , this in turn would help us run darwin/aarch64
specific code on our MacOs pipeline in the git actions.

Methods used to search and find "darwin/arm" directories was  

1. "find . -type d -path "*/libc/*/darwin/arm" in a linux terminal to
check for arm specifically
2. "find . -type d -path "*/libc/*/darwin/*" to ensure there are no
directories that are named "*arm*" where star is a wildcard for any
character.
2025-05-29 23:41:34 -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
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
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
Mikhail R. Gadelha
ba38e56c98 [libc] Enable setitimer and getitimer functions on riscv (#139182)
These functions don't have a _time64 variant, so we can't use time_t
directly (since our time_t is a uint64_t). The workaround is to use
longs when doing the syscall and write back when necessary.
2025-05-16 18:55:32 -03:00
Bill Wendling
00c5cd8a7a [libc] Fix typo: Configue -> Configure (#140166) 2025-05-16 11:48:36 -07:00
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
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
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