Commit Graph

486 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
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
William Huynh
fd432151a6 [libc] Fix bugs found when testing with all headers (#144049)
Fixes a couple of bugs found when building. The PR to enable the headers
can be found here: #144114.

- math.yaml: float128 guard
- wchar.yaml: __restrict keyword order
2025-06-13 10:26:40 -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
Uzair Nawaz
6311f039b2 [libc] Build fixes for widechar characterconverter (#143805)
Build fixes for wchar CharacterConverter class
2025-06-12 17:34:45 +00:00
lntue
82f19674bf [libc] Update size_t and ssize_t definitions to use __SIZE_TYPE__ and __PTRDIFF_TYPE__ respectively. (#143921)
The current definition of `ssize_t` does not have the same bit width as
`size_t` on 32-bit platforms.
2025-06-12 13:11:42 -04: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
William
117e78fe50 [libc] Add NULL macro definitions to header files (#142764)
By the C standard, <locale.h>, <stddef.h> <stdio.h>, <stdlib.h>,
<string.h>, <time.h>, and <wchar.h> require NULL to be defined.
2025-06-11 09:51:34 -07:00
William
a75fc765d3 [libc] Add definitions to embedded AArch32/AArch64 (#142597)
Add `CLOCKS_PER_SEC` and the older `CLK_TCK`. Allows the user to define
a `__CLK_TCK` to override if necessary.

Also add an extra column for embedded AArch64 in `time.rst`
2025-06-06 16:05:14 -04: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
Michael Jones
cc68367bb9 [libc][obvious] fix wchar yaml formatting (#142506)
The yaml ended up with a typo, possibly due to merge issues. This patch
fixes it.
2025-06-02 17:00:23 -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
339851e140 [libc][obvious] Fixed wchar.yaml (#142238)
Changed __restricted to __restrict for wmemcpy.

Co-authored-by: Sriya Pratipati <sriyap@google.com>
2025-05-30 16:41:11 -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
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
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
3b62a3369a [libc] Add struct entry definition in addition to ENTRY according to POSIX. (#139773) 2025-05-13 15:48:30 -04: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
enh-google
e79dc76b5f stdlib.yaml: qsort_r() is in POSIX 2024 (aka issue 8). (#138572) 2025-05-06 09:36:10 -04: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
Michael Jones
9124e963a3 [libc] Update assert for C23 (#137402)
Previously the assert macro took one argument named "e", but this led to
possible errors if the caller had commas in their input. C23 changed the
definition of assert to use `__VA_ARGS__` to ensure comma cases are
handled properly. This patch doesn't introduce the enforcement function
mentioned in the standard update, though that may be done in a followup.

Fixes #136184
2025-04-28 15:06:52 -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