864 Commits

Author SHA1 Message Date
Joseph Huber
598e882ee8
[libc] Template the writing mode for the writer class (#111559)
Summary:
Currently we dispatch the writing mode off of a runtime enum passed in
by the constructor. This causes very unfortunate codegen for the GPU
targets where we get worst-case codegen because of the unused function
pointer for `sprintf`. Instead, this patch moves all of this to a
template so it can be masked out. This results in no dynamic stack and
uses 60 VGPRs instead of 117. It also compiles about 5x as fast.
2025-03-12 13:51:44 -05: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
Joseph Huber
6b3e7657cf
[libc] Enable 'strftime' for the GPU targets (#128220)
Summary:
These should allow us to build with locale support for libcxx.
2025-02-21 16:29:15 -06: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
Petr Hosek
ea77dd8715
[libc] Include locale support in baremetal configuration (#127103)
Having locale is a requirement for C++ streams.
2025-02-13 10:26:33 -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
PiJoules
ec7167bac7
[libc] Disable fixed point printing for baremetal (#126115)
This follows suite with disabling float printing.
2025-02-06 11:31:05 -08:00
c8ef
e1c63bbde5
[libc] implement sys/uio/readv (#124718)
Closes #124694.

This patch adds the `sys/uio/readv` function.
ref:
https://pubs.opengroup.org/onlinepubs/009696699/functions/readv.html
2025-02-06 09:28:20 +08:00
Nick Desaulniers
72aa3889fb
[libc][poll] remove entrypoint for riscv (#125941)
riscv32 specifically doesn't provide EITHER SYS_poll or SYS_ppoll. We may be
able to reimplement poll in terms of syscalls to SYS_ppoll_time64, but will
leave that as a TODO for the future. (Such as when we want to be able to cross
compile for riscv32).

Link: #125940
Fixes: #125118
2025-02-05 13:56:30 -08:00
Nick Desaulniers
8e35b3d29b
[libc][POSIX][poll.h] implement poll (#125118)
Simple syscall.

Fixes: #124647
2025-02-05 13:24:39 -08:00
Krishna Pandey
6f750cfb96
[libc][unistd] Implement setsid (#125704)
https://man7.org/linux/man-pages/man2/setsid.2.html

closes #124632
2025-02-05 10:08:16 -08:00
Simon Tatham
b53da77c50
[libc] Alternative algorithm for decimal FP printf (#123643)
The existing options for bin→dec float conversion are all based on the
Ryū algorithm, which generates 9 output digits at a time using a table
lookup. For users who can't afford the space cost of the table, the
table-lookup subroutine is replaced with one that computes the needed
table entry on demand, but the algorithm is otherwise unmodified.

The performance problem with computing table entries on demand is that
now you need to calculate a power of 10 for each 9 digits you output.
But if you're calculating a custom power of 10 anyway, it's easier to
just compute one, and multiply the _whole_ mantissa by it.

This patch adds a header file alongside `float_dec_converter.h`, which
replaces the whole Ryū system instead of just the table-lookup routine,
implementing this alternative simpler algorithm. The result is accurate
enough to satisfy (minimally) the accuracy demands of IEEE 754-2019 even
in 128-bit long double. The new float128 test cases demonstrate this by
testing the cases closest to the 39-digit rounding boundary.

In my tests of generating 39 output digits (the maximum number supported
by this algorithm) this code is also both faster and smaller than the
USE_DYADIC_FLOAT version of the existing Ryū code.
2025-02-04 08:57:54 +00:00
Nick Desaulniers
631a6e0004
[libc][wchar] implement wcslen (#124150)
Update string_utils' string_length to work with char* or wchar_t*, so that it
may be reusable when implementing wmemchr, wcspbrk, wcsrchr, wcsstr.

Link: #121183
Link: #124027

Co-authored-by: Nick Desaulniers <ndesaulniers@google.com>

---------

Co-authored-by: Tristan Ross <tristan.ross@midstall.com>
2025-01-23 13:33:04 -08:00
Joseph Huber
db6b7a84e6
[libc][NFC] Strip all training whitespace and missing newlines (#124163) 2025-01-23 12:02:54 -06:00
Schrodinger ZHU Yifan
defd0d966d
[libc] implement unistd/getentropy (#122692)
Implement GNU extension getentropy. This function is used by many
programs to acquire entropy without handling the loop of getrandom.
2025-01-15 18:27:05 +08:00
wldfngrs
ecf4f95c4f
[libc][math][c23] Add tanf16 function (#121018)
- Implementation of tan for 16-bit floating point inputs.
- Exhaustive tests across the 16-bit input range
2025-01-12 23:46:53 -05:00
Schrodinger ZHU Yifan
73dd730fb9
[libc] implement sys/uio/writev (#122233)
implement sys/uio/writev according to POSIX standard. This vectorized IO
API is needed by many logging libraries to achieve atomic logging
multiple strings.
2025-01-10 12:49:00 +08:00
Prabhuk
3b19e787fc
[libc] Keep framepointers for baremetal (#121836)
Keep framepointers enabled by default for the default baremetal libc
builds.

Frame pointers help unwind the stack and unwinding without frame pointer
is complex and increaseis the code size. This code size increase is
potentially larger than the savings achieved by disabling frame
pointers. Retaining the original behavior of retaining frame pointers as
the default behavior.
2025-01-07 13:22:14 -08:00
Joseph Huber
f4bab06c97
[libc] Split AMDGPU and NVPTX configs into separate folders (#120153)
Summary:
This is a holdover from when these targets were merged. They're
basically the same but there's no reason they should be treated as
identical. I think we will live with a little duplication.
2025-01-06 13:49:19 -06:00
Prabhuk
7deaed975e
[libc] Reduce binary size for baremetal targets (#121164)
For `math` functions we must choose size optimized implementations.
Removing framepointers will also help with binary size savings.
2024-12-26 15:55:39 -08:00
Shourya Goel
9f75b6664f
[libc][complex] fix buildbot errors (#121141)
Fix buildbot errors due to #121140
2024-12-26 12:57:48 +05:30
Shourya Goel
abd9102344
[libc][complex] add cfloat16 and cfloat128 compiler flags (#121140)
Proper fix for the temporary fix in #114696
2024-12-26 12:50:07 +05:30
Shourya Goel
ff97daadcd
Revert "[libc][complex] enable CFP128 entrypoints on X86_64 (#121111)" (#121113)
This reverts commit dd9c5c118230fc9adde668f2c96323b73a677400.
2024-12-25 20:56:13 +05:30
Shourya Goel
dd9c5c1182
[libc][complex] enable CFP128 entrypoints on X86_64 (#121111) 2024-12-25 20:45:32 +05:30
Joseph Huber
3bbd53ce97
[libc] Remove old RPC host call extension for GPU (#120800)
Summary:
This was originally a hacked together function that served to just
implement some features for OpenMP. That has been moved into OpenMP
itself now that we have exported RPC properly. This can now be deleted.
2024-12-20 19:34:05 -06:00
Joseph Huber
958de20b30
[libc] Enable 'timespec_get' for the GPU build (#120304)
Summary:
Currently fails to build libc++ because this is missing.
2024-12-17 15:31:07 -06:00
Shourya Goel
c98e79d856
[libc][complex] Implement different flavors of the cproj function (#119722)
Refer section 7.3.9.5 of ISO/IEC 9899:2023
2024-12-18 02:04:50 +05:30
Petr Hosek
7bf3137c39
[libc] Breakup freelist_malloc into separate files (#119806)
This better matches the structure we use for the rest of libc.
2024-12-16 10:30:27 -08:00
wldfngrs
6a865b6d3d
[libc][math][c23] Add cosf16 function (#118785) 2024-12-15 18:58:54 +01:00
Petr Hosek
379cc44f56
Revert "[libc] Breakup freelist_malloc into separate files" (#119749)
Reverts llvm/llvm-project#98784 which broke libc builders.
2024-12-12 13:28:30 -08:00
Petr Hosek
4e2a9e50f6
[libc] Breakup freelist_malloc into separate files (#98784)
This better matches the structure we use for the rest of libc.
2024-12-12 11:24:36 -08:00
Shourya Goel
d5b7b97034
[libc][complex] Add complex.yaml in hdrgen. (#119609) 2024-12-12 03:12:09 +05:30
Nick Desaulniers
d1d5fc381f
[libc] fix up strings.h entrypoints (#119417)
I typo'd riscv, and the newly added baremetal aarch64 entrypoints had a mid air
collision.

Link: #118691
Link: #118899
2024-12-10 10:14:01 -08:00
Nick Desaulniers
1d7d0051f9
[libc] move src/network to src/arpa/inet (#119273)
So that docgen can find our implementations.

Fixes: #119272
2024-12-10 08:59:39 -08:00