4347 Commits

Author SHA1 Message Date
William Huynh
0425a5df4d
[libc] Add hooks for extra options in running hermetic tests (#147931)
Part of #145349. These hooks are required downstream in order to run
hermetic tests. See https://github.com/arm/arm-toolchain/pull/420 for
more context on how this PR will be used.
2025-07-15 11:43:51 +01:00
Connector Switch
91b3dbe273
[libc] Update some implementation status for search.h (#148414)
- `VISIT` was implemented in
https://github.com/llvm/llvm-project/pull/132746.
- `lsearch` was implemented in
https://github.com/llvm/llvm-project/pull/131431.

At first, I thought this would be updated automatically, but it seems
that the header status needs to be added manually.
2025-07-15 10:34:30 +08:00
Uzair Nawaz
56a4f8d8c1
[libc] Wchar Stringconverter (#146388)
Implemented a string converter class to encapsulate the logic of
converting between utf8 <-> utf32
2025-07-14 15:45:46 -07:00
Uzair Nawaz
711132dfa4
[libc] Implement widechar to integer public functions (#148683)
Implement public wchar -> integer public functions using templated
internal wcs_to_integer function
2025-07-14 13:33:12 -07:00
lntue
f4630baaa2
Revert "[libc][math] Refactor exp implementation to header-only in src/__support/math folder." (#148668)
Reverts llvm/llvm-project#148091
Full build bots are failing.
2025-07-14 12:46:26 -04:00
sribee8
1f97c9432d
[libc] exp fuzz tests (#148086)
Created fuzz tests for exp functions

---------

Co-authored-by: Sriya Pratipati <sriyap@google.com>
2025-07-14 16:36:24 +00:00
Muhammad Bassiouni
a76dfde936
[libc][math] Refactor exp implementation to header-only in src/__support/math folder. (#148091)
Part of #147386

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-07-14 12:21:27 -04:00
Muhammad Bassiouni
cfcda5d0ff
[libc][math] Refactor ldexpf implementation to header-only in src/__support/math folder (#147906)
Part of #147386

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

Please merge #147901 first

@lntue
2025-07-14 11:35:53 -04:00
Muhammad Bassiouni
074218dd10
[libc][math] Refactor ldexpf16 implementation to header-only in src/__support/math folder. (#147901)
Part of #147386

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

Please merge #147895 first
2025-07-14 11:00:01 -04:00
Muhammad Bassiouni
0ad2574de7
[libc][math] Refactor ldexpf128 implementation to header-only in src/__support/math folder. (#147895)
Part of #147386

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-07-14 10:10:49 -04:00
Amy Huang
bc2cc8b56e
Change binary path in libc test cmake file from relative to absolute (#148315)
For some reason cmake usually turns this path into an absolute path, but
sometimes
it doesn't do it and stays as a relative path, which means the command
will fail.
Specify it as an absolute path always so this doesn't happen any more.
2025-07-12 14:43:52 -07:00
Petr Hosek
bce3cbc74e
[libc] Baremetal version of clock (#146417)
This is analogous to the baremetal version of timespec_get using the
__llvm_libc_timespec_get_active embedding interface.
2025-07-12 10:26:51 -07:00
Connector Switch
490e500904
[libc][NFC] Revise file header for tanf exhaustive test. (#148348) 2025-07-13 01:05:23 +08:00
Muhammad Bassiouni
d06e9ce1dd
[libc][math] Refactor frexpf implementation to header-only in src/__support/math folder. (#147893)
Part of #147386

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-07-12 11:08:58 -04:00
Muhammad Bassiouni
395643e60b
[libc][math] Refactor frexpf16 implementation to header-only in src/__support/math folder. (#147889)
Part of #147386

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-07-12 00:48:01 -04:00
Connector Switch
c3abe3ff22
[libc][math][c23] implement C23 math function tanpif (#147192)
The smoke test and exhaustive test pass on x86_64 Linux.

Closes #94895.
2025-07-12 12:39:33 +08:00
Muhammad Bassiouni
d02c85a29b
[libc] Fix frexpf128 build failure. (#148332) 2025-07-11 23:55:09 -04:00
Muhammad Bassiouni
af6500d14c
[libc][math] Refactor frexpf128 implementation to header-only in src/… (#147822)
Part of #147386 

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-07-11 22:59:09 -04:00
William Huynh
e908f6131e
[libc] Fix WEOF and fix 1'000'000 error messages on test failure (#147928)
1. WEOF is defined as a `wint_t` by the C standard. On certain
architectures, the test won't compile on `-Wall`. This fixes it.
2. If `testSubnormalRange` fails, it will spit out way too many error
messages, which overwhelms my test environment. I reduce this to 1k for
now.

This is required for #145349
2025-07-11 09:35:04 +01:00
Muhammad Bassiouni
c25a5e08ba
[libc][math] Refactor expf16 implementation to header-only in src/__support/math folder. (#147428)
Part of #147386

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-07-10 22:21:48 -04:00
Uzair Nawaz
88ba06d6fc
[libc] Addressed todo to make first_non_whitespace to return an idx instead of ptr (#148004)
Addressed todo to make first_non_whitespace to return an idx instead of
ptr
2025-07-10 13:55:14 -07:00
Uzair Nawaz
d93cc7aabf
[libc] WCS to integer internal function (#147857)
Duplicated str_to_integer.h and modified it to work with widechars.
A future patch will implement the public functions (wcstol, wcstoll,
etc) by calling this internal function.
2025-07-10 10:22:39 -07:00
sribee8
425ed22b2e
[libc] asin fuzz testing (#147786)
Added fuzz test for asin

---------

Co-authored-by: Sriya Pratipati <sriyap@google.com>
2025-07-10 16:28:57 +00:00
sribee8
a9d8843d71
[libc] Fuzz tests for acos and atan (#147843)
created fuzz tests for acos and atan

---------

Co-authored-by: Sriya Pratipati <sriyap@google.com>
2025-07-10 16:28:29 +00:00
sribee8
81614e5b90
[libc] sincos fuzz test (#147855)
Created fuzz test for sincos

---------

Co-authored-by: Sriya Pratipati <sriyap@google.com>
2025-07-10 16:26:26 +00:00
sribee8
d5436b0b95
[libc] wcslcat implementation (#146588)
implemented wcslcat and tests.

---------

Co-authored-by: Sriya Pratipati <sriyap@google.com>
2025-07-09 23:54:03 +00:00
Bogdan Vetrenko
071e30220d
[libc][NFC] fix comment typo ("documentation") (#147836) 2025-07-09 15:44:10 -07:00
sribee8
f1acd69bfe
[libc] Added internal wctype functions (#147798)
Copy pasted the ctype equivalents

---------

Co-authored-by: Sriya Pratipati <sriyap@google.com>
2025-07-09 21:58:55 +00:00
sribee8
16f046281b
[libc] wcslcpy implementation (#146571)
Implemented wcslcpy and tests.

---------

Co-authored-by: Sriya Pratipati <sriyap@google.com>
2025-07-09 21:17:16 +00:00
OverMighty
44582c9f08
[libc] Fix DyadicFloat::generic_as() requiring LIBC_TYPES_HAS_FLOAT16 (#147811)
See https://lab.llvm.org/buildbot/#/builders/215/builds/710.
2025-07-09 21:47:14 +02:00
Krishna Pandey
bb7cea0637
[libc][math][c++23] Add bfloat16 support in LLVM libc (#144463)
This PR enables support for BFloat16 type in LLVM libc along with
support for testing BFloat16 functions via MPFR.

---------

Signed-off-by: krishna2803 <kpandey81930@gmail.com>
Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
Co-authored-by: OverMighty <its.overmighty@gmail.com>
2025-07-09 21:26:29 +02:00
enh-google
ff365ce1d7
Reland "Fix wcpncpy() return value; add test." (#146753)
Reverts llvm/llvm-project#146752, which was a revert of my accidental
push, so we can actually review and presubmit this time.
2025-07-09 15:25:49 -04:00
Connector Switch
708c0fe3df
[libc] Simplify the version guard for mpfr. (#146354)
Instead of manually calculating the major and minor version numbers, we
can directly use `MPFR_VERSION_NUM` to simplify this.
2025-07-09 00:22:18 +08:00
Connector Switch
ab92c68c5c
[libc][NFC] Fix func name in comment. (#147183) 2025-07-06 19:30:39 +08:00
Michael Jones
77d95911a3
Revert "Fix wcpncpy() return value; add test." (#146752)
This reverts commit 988876cdd918d5b945a072a3d643b5fa22ae2917.
Was intended to be a PR
2025-07-02 11:08:21 -07:00
enh-google
988876cdd9
Fix wcpncpy() return value; add test. 2025-07-02 14:00:02 -04:00
Joseph Huber
50f40a5327
[libc] Fix internal alignment in allcoator (#146738)
Summary:
The allocator interface is supposed to have 16 byte alignment (to keep
it consistent with the CPU allocator. We could probably drop this to 8
if desires.) But this was not enforced because the number of bytes used
for the bitfield sometimes resulted in alignment of 8 instead of 16.
Explicitly align the number of bytes to be a multiple of 16 even if
unused.
2025-07-02 12:29:01 -05:00
Joseph Huber
24828c8c45
[libc] Efficiently implement aligned_alloc for AMDGPU (#146585)
Summary:
This patch uses the actual allocator interface to implement
`aligned_alloc`. We do this by simply rounding up the amount allocated.
Because of how index calculation works, any offset within an allocated
pointer will still map to the same chunk, so we can just adjust
internally and it will free all the same.
2025-07-02 09:25:57 -05:00
Joseph Huber
dea4f3213d
[libc] Use is aligned builtin instead of ptrtoint (#146402)
Summary:
This avoids a ptrtoint by just using the clang builtin. This is clang
specific but only clang can compile GPU code anyway so I do not bother
with a fallback.
2025-07-02 07:03:11 -05:00
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
sribee8
81c9a1a4e5
[libc][obvious] Fixed typos in some wchar headers (#146413)
Some of the wchar headers had typos in them.

Co-authored-by: Sriya Pratipati <sriyap@google.com>
2025-06-30 20:22:05 +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
Joseph Huber
10445acfa6
[libc] Efficiently implement 'realloc' for AMDGPU devices (#145960)
Summary:
Now that we have `malloc` we can implement `realloc` efficiently. This
uses the known chunk sizes to avoid unnecessary allocations. We just
return nullptr for NVPTX. I'd remove the list for the entrypoint but
then the libc++ code would stop working. When someone writes the NVPTX
support this will be trivial.
2025-06-30 08:39:40 -05:00
sribee8
f58caed1bc
[libc] Changed CharacterConverter returns (#146130)
changed internal CharacterConverter returns to return errno macro when
necessary for consistency.

---------

Co-authored-by: Sriya Pratipati <sriyap@google.com>
2025-06-27 21:50:09 +00:00
Joseph Huber
d34214a85e
[libc] Add and use 'cpp::launder' to guard placement new (#146123)
Summary:
In the GPU allocator we reinterpret cast from a void pointer. We know
that an actual object was constructed there according to the C++ object
model, but to make it fully standards compliant we need to 'launder' it
to forward that information to the compiler. Add this function and call
it as appropriate.
2025-06-27 14:34:33 -05: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
Hans Wennborg
58b7d200aa
[libc] Fix the risc-v half precison float feature check (#145894)
This is a follow-up to #145169, which would break compiles when
__riscv_zfhmin is not defined.
2025-06-26 16:32:21 +02:00
Guillaume Chatelet
7289b6789e
[libc] Improve memcpy for ARM Cortex-M supporting unaligned accesses. (#144872)
This implementation has been compiled with the [pigweed toolchain](https://pigweed.dev/toolchain.html) and tested on:
 - Raspberry Pi Pico 2 with the following options\
`--target=armv8m.main-none-eabi`
`-march=armv8m.main+fp+dsp`
`-mcpu=cortex-m33` 
 - Raspberry Pi Pico with the following options\
`--target=armv6m-none-eabi`
`-march=armv6m`
`-mcpu=cortex-m0+` 

They both compile down to a little bit more than 200 bytes and are between 2 and 10 times faster than byte per byte copies.

For best performance the following options can be set in the `libc/config/baremetal/arm/config.json`
```
{
  "codegen": {
    "LIBC_CONF_KEEP_FRAME_POINTER": {
      "value": false
    }
  },
  "general": {
    "LIBC_ADD_NULL_CHECKS": {
      "value": false
    }
  }
}
```
2025-06-26 10:18:02 +02: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