845 Commits

Author SHA1 Message Date
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
Nick Desaulniers
431ea2d076
[libc] move bcmp, bzero, bcopy, index, rindex, strcasecmp, strncasecmp to strings.h (#118899)
docgen relies on the convention that we have a file foo.cpp in
libc/src/\<header\>/. Because the above functions weren't in libc/src/strings/
but rather libc/src/string/, docgen could not find that we had implemented
these.

Rather than add special carve outs to docgen, let's fix up our sources for
these 7 functions to stick with the existing conventions the rest of the
codebase follows.

Link: #118860
Fixes: #118875
2024-12-10 08:58:45 -08:00
Shourya Goel
78c2b6d483
[libc][complex] Implement different flavors of the conj function (#118671)
Refer section 7.3.9.4 of ISO/IEC 9899:2023
2024-12-10 10:05:11 +05:30
Schrodinger ZHU Yifan
9a06fb7e5c
[libc][time][windows] implement clock_getres (#118931) 2024-12-09 22:00:01 -05:00
Petr Hosek
2e8ce30423
[libc] Support baremetal libc on aarch64 (#118691)
We have users that target baremetal aarch64.
2024-12-09 15:34:51 -08:00
Schrodinger ZHU Yifan
e6cf5d2863
Reapply "[libc][windows] start time API implementation (#117775)" (#118886) 2024-12-05 18:21:03 -05:00
Joseph Huber
9fd052a122 Revert "[libc][windows] start time API implementation (#117775)"
This reverts commit 0adff0af20c7d9bae8bd8bdf402506c10369ead1.

Breaks the GPU build
2024-12-05 14:43:06 -06:00
Schrodinger ZHU Yifan
0adff0af20
[libc][windows] start time API implementation (#117775)
Add a `clock_gettime` emulation layer and use it to implement the `time`
entrypoint.

For windows, the monotonic clock is emulated using `QPC`.
The realtime clock is emulated using `GetSystemTimePreciseAsFileTime`.
2024-12-05 14:08:27 -05:00
Schrodinger ZHU Yifan
245f26a3d3
[libc] revert all process_mrelease changes (#118650)
Revert as its test is unstable.
https://github.com/llvm/llvm-project/issues/118057
2024-12-05 11:58:37 -05:00
Nick Desaulniers
5e769fb234
[libc] add headers.txt for windows (#118675)
Link:
https://github.com/llvm/llvm-project/pull/117220#issuecomment-2518126598

---------

Co-authored-by: Michael Jones <michaelrj@google.com>
2024-12-04 12:38:21 -08:00
Nick Desaulniers
e0ae7793fc
[libc] delete hdrgen (#117220)
Thanks to the effort of @RoseZhang03 and @aaryanshukla under the
guidance of
@michaelrj-google and @amykhuang, we now have newhdrgen and no longer
have a
dependency on TableGen and thus LLVM in order to start bootstrapping a
full
build.

This PR removes:
- LIBC_HDRGEN_EXE; the in tree newhdrgen is the only hdrgen that can be
used.
- LIBC_USE_NEW_HEADER_GEN; newhdrgen is the default and only option.
- LIBC_HDRGEN_ONLY; there is no need to have a distinct build step for
old
  hdrgen.
- libc-api-test and libc-api-test-tidy build targets.
- Deletes all .td files.

It does not rename newhdrgen to just hdrgen. Will follow up with a
distinct PR
for that.

Link: #117209
Link: #117254
Fixes: #117208
2024-12-03 12:34:26 -08:00
wldfngrs
cd04653c4e
[libc][math][c23] Add sinf16 C23 math function (#116674)
Co-authored-by: OverMighty <its.overmighty@gmail.com>
2024-12-03 21:08:46 +01:00
Petr Hosek
b8daa45a56
[libc] Implement timespec_get (#116102)
`timespec_get` is C standard counterpart to POSIX `clock_gettime`. On
Linux we simply use `clock_gettime`. On baremetal we introduce a new
external API `__llvm_libc_timespec_get_utc` that should be implemented
by the vendor.
2024-12-02 14:29:49 -08:00
Schrodinger ZHU Yifan
700d9ac9ef
[libc] disable process_mrelease for riscv (#117956)
`process_mrelease` upsets the RV32 build bot. Disable it for now.
2024-11-27 21:17:38 -05:00
Omar Hossam
d2b482b0ef
[libc] (reland #117503) Implement process_mrelease (#117851)
This PR implements process_mrelease.
A previous PR was merged #117503, but failed on merge due to an issue in
the tests. Namely the failing tests were comparing against return type
as opposed to errno. This is fixed in this PR.
2024-11-27 20:15:17 -05:00
lntue
3372303188
Revert "[libc] Implement process_mrelease." (#117807)
Reverts llvm/llvm-project#117503
2024-11-26 18:07:30 -05:00
Omar Hossam
36a46d85e7
[libc] Implement process_mrelease. (#117503)
This PR addresses #110124.
2024-11-26 17:40:06 -05:00
Petr Hosek
a4f3a10c0e
[libc] Include features.h in baremetal targets (#109444)
This is used by other libraries like libc++.
2024-11-12 23:46:20 -08:00
William Tran-Viet
13ced90b00
[libc] {u}lkbits broken on riscv32 (#115799)
- Re-enabled ulkbits and lkbits for Risc-V
- Bumped `int_lk_t` to a `signed long long` and a `uint_ulk_t` to an
`unsigned long long` to guarantee they both fit in 8 bytes, which `long
_Accum` and `unsigned long _Accum` are defaulted to on 32bit
architectures.

This is probably inconvenient on systems that have a word size larger
than 64 bits?

#115778
2024-11-12 10:38:08 -08:00
Nick Desaulniers
28cdebf7ba
[libc][stdfix] disable ulkbits on riscv (#115781) (#115792)
I should have disabled this in #115781. Mea culpa.

Link: #114912
Link: #115778
Link: #115781
2024-11-11 16:18:55 -08:00