984 Commits

Author SHA1 Message Date
Joseph Huber
27fc9671f9 Revert "[libc] Enable wide-read memory operations by default on Linux (#154602)"
This reverts commit c80d1483c6d787edf62ff9e86b1e97af5eb5abf9.
2025-08-20 17:27:13 -05:00
Joseph Huber
c80d1483c6
[libc] Enable wide-read memory operations by default on Linux (#154602)
Summary:
This patch changes the linux build to use the wide reads on the memory
operations by default. These memory functions will now potentially read
outside of the bounds explicitly allowed by the current function. While
technically undefined behavior in the standard, plenty of C library
implementations do this. it will not cause a segmentation fault on linux
as long as you do not cross a page boundary, and because we are only
*reading* memory it should not have atomic effects.
2025-08-20 17:17:12 -05:00
Krishna Pandey
550dbec03a
[libc][math][c++23] Add {,u}fromfp{,x}bf16 math functions (#153992)
This PR adds the following basic math functions for BFloat16 type along
with the tests:
- fromfpbf16
- fromfpxbf16
- ufromfpbf16
- ufromfpxbf16

---------

Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-08-19 22:19:03 +05:30
Mohamed Emad
40833eea21
Reland "[libc][math][c23] Implement C23 math function asinpif16" (#152690)
#146226 with fixing asinpi MPFR number function and make it work when
mpfr < `4.2.0`
2025-08-18 00:04:47 +03:00
Krishna Pandey
41c9510d72
[libc][math][c++23] Add bf16fma{,f,l,f128} math functions (#153231)
This PR adds the following basic math functions for BFloat16 type along
with the tests:
- bf16fma
- bf16fmaf
- bf16fmal
- bf16fmaf128

---------

Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-08-13 23:26:15 +05:30
Alexey Samsonov
04081caa09
[libc] Remove LIBC_ERRNO_MODE_SYSTEM mode. (#153077)
Use LIBC_ERRNO_MODE_SYSTEM_INLINE instead as the default for the "public
packaging" (i.e. release mode) of an overlay build. The Bazel build has
already switched to use it by default in
5ccc734fa0355f971f8f515457a0bece33ab6642. This should be a safe change,
as LIBC_ERRNO_MODE_SYSTEM_INLINE works a drop-in (but simpler)
LIBC_ERRNO_MODE_SYSTEM replacement. Remove the associated code paths and
config settings.

Fixes issue #143454.
2025-08-12 19:52:40 -07:00
Krishna Pandey
c819c246f3
[libc][math][c++23] Add bf16div{,f,l,f128} math functions (#153191)
This PR adds the following basic math functions for BFloat16 type along
with the tests:
- bf16div
- bf16divf
- bf16divl
- bf16divf128

---------

Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-08-12 21:46:22 +05:30
Krishna Pandey
8c5e9399f6
[libc][math][c++23] Add f{max,min}imum{,_mag,_mag_num,_num}bf16 math functions (#152881)
This PR adds the following basic math functions for BFloat16 type along
with the tests:
- fmaximumbf16
- fmaximum_magbf16
- fmaximum_mag_numbf16
- fmaximum_numbf16
- fminimumbf16
- fminimum_magbf16
- fminimum_mag_numbf16
- fminimum_numbf16

---------

Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-08-12 20:37:31 +05:30
Krishna Pandey
628c0e33e4
[libc][math][c++23] Add bf16mul{,f,l,f128} math functions (#152847)
This PR adds the following basic math functions for BFloat16 type along
with the tests:
- bf16mul
- bf16mulf
- bf16mull
- bf16mulf128

---------

Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-08-10 21:38:27 -04:00
Krishna Pandey
246f92324f
[libc][math][c++23] Add f{max,min}bf16 math functions (#152782)
Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-08-08 17:54:02 -04:00
Krishna Pandey
10088b64ef
[libc][math] Update entrypoints for bf16{add,sub}{,f,l,f128} math functions (#152784)
Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-08-08 17:06:48 -04:00
Krishna Pandey
1ffb99520d
[libc][math][c++23] Add bf16{add,sub}{,f,l,f128} math functions (#152774)
This PR adds implements following basic math functions for BFloat16 type
along with the tests:
- bf16add
- bf16addf
- bf16addl
- bf16addf128
- bf16sub
- bf16subf
- bf16subl
- bf16subf128

---------

Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-08-08 15:20:24 -04:00
Krishna Pandey
15a705dc93
[libc][math][c++23] Add {ceil,floor,round,roundeven,trunc}bf16 math functions (#152352)
This PR implements the following basic math functions for BFloat16 type
along with the tests:
- ceilbf16
- floorbf16
- roundbf16
- roundevenbf16
- truncbf16

---------

Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-08-08 00:15:22 -04:00
Amy Huang
9e9bf7ac5b
Update the cmake options in libc windows build docs (#152205)
Add the LLVM_ENABLE_RUNTIMES option and remove some that are out of date
or already the default setting.
2025-08-05 16:57:16 -07:00
Leandro Lacerda
448c88478d
[libc] Enable the acoshf math function on AMD GPUs (#152157)
This patch adds the `acoshf` math function to the AMDGPU build.
2025-08-05 13:33:11 -05:00
Leandro Lacerda
cd19fbad09
[libc] Enable float math functions on the GPU (#151841)
This patch adds the `tanpif` math functions to the GPU build. It also
adds the `cospif` and `sinpif` math functions to the `math.h` header.
2025-08-02 22:13:04 -05:00
William Huynh
35a4d8206b
[libc] Add atexit to baremetal entrypoints (#147290)
Part of #145349. Requires #145358. Required by #146863. Once the mutex
has been implemented, we can register functions to be called for exit
with `atexit`.
2025-07-31 12:16:58 +01:00
William Huynh
82bddc3e64
[libc] Mutex implementation for single-threaded baremetal (#145358)
Part of https://github.com/llvm/llvm-project/issues/145349. Required to
allow `atexit` to work. As part of `HermeticTestUtils.cpp`, there is a
reference to `atexit()`, which eventually instantiates an instance of a
Mutex.

Instead of copying the implementation from
`libc/src/__support/threads/gpu/mutex.h`, we allow platforms to select
an implementation based on configurations, allowing the GPU and
single-threaded baremetal platforms to share an implementation. This can
be configured or overridden.

Later, when the threading API is more complete, we can add an option to
support multithreading (or set it as the default), but having
single-threading (in tandem) is in line with other libraries for
embedded devices.
2025-07-31 12:16:44 +01:00
Aiden Grossman
fc5976118d
[libc] Add implementation of getcpu syscall wrapper (#150871)
This patch adds the getcpu syscall wrapper. This has been supported in
glibc since v2.29.
2025-07-30 09:45:19 -07:00
Uzair Nawaz
a1aba84c2b
[libc] Reland #148948 "Implement barriers for pthreads" (#151021)
Fixed build dependencies for pthread_barrier_t (add __barrier_type to
cmake dependencies)
2025-07-29 16:39:40 +00:00
sribee8
a653934b58
[libc] Reland wchar string conversion mb to wc (#151048)
Added crash on nullptr to mbstowcs

---------

Co-authored-by: Sriya Pratipati <sriyap@google.com>
2025-07-29 16:34:10 +00:00
Krishna Pandey
111edfcab8
[libc][math][c++23] Add fabsbf16 math function (#148398)
This PR implements fabsbf16 math function for BFloat16 type along with
the tests.

---------

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-29 12:19:21 -04:00
sribee8
1381ad497b
Revert "[libc] Reland #149423 "wchar string conversion functions mb to wc"" (#151016)
Reverts llvm/llvm-project#150667
2025-07-28 18:39:41 +00:00
Uzair Nawaz
a4a0832899
Revert "[libc] Implement barriers for pthreads" (#151014)
Reverts llvm/llvm-project#148948
2025-07-28 11:37:23 -07:00
Uzair Nawaz
7ca23754c4
[libc] Implement barriers for pthreads (#148948)
Implemented barrier synchronization for pthreads
- Uses condition variables internally for platform independence
(platform-specific work is handled by the condition variable
implementation)
- Does NOT currently handle barrierattr pshared, this is a goal for a
future patch
2025-07-28 11:22:38 -07:00
sribee8
741df45bc3
[libc] Reland #149423 "wchar string conversion functions mb to wc" (#150667)
Added missing includes in the test files for null check

---------

Co-authored-by: Sriya Pratipati <sriyap@google.com>
2025-07-28 17:40:10 +00:00
OverMighty
6a85f7cef3
Revert "[libc][math][c23] Implement C23 math function asinpif16" (#150756)
Reverts llvm/llvm-project#146226

The MPFR test uses `mpfr_asinpi` which requires MPFR 4.2.0 or later, but
the Buildbots are running an older version of MPFR.

See https://lab.llvm.org/buildbot/#/builders/104/builds/27743 for
example.

I said I was going to revert the PR until we have a workaround for older
versions of MPFR, but then I forgot and I just disabled the entrypoints
which doesn't fix the Buildbot builds.
2025-07-26 15:39:43 +03:00
OverMighty
3ea99a9c7c
Revert "[libc][math][c23] Temporarily disable asinpif16 C23 math function" (#150755)
Reverts llvm/llvm-project#150754

I should have reverted the asinpif16 PR instead of just disabling the
entrypoints.
2025-07-26 15:32:56 +03:00
OverMighty
7ba62551db
[libc][math][c23] Temporarily disable asinpif16 C23 math function (#150754)
The MPFR test uses `mpfr_asinpi` which requires MPFR 4.2.0 or later, but
the Buildbots are running an older version of MPFR.

See https://lab.llvm.org/buildbot/#/builders/104/builds/27743 for
example.
2025-07-26 15:10:10 +03:00
Mohamed Emad
eed9b4e058
[libc][math][c23] Implement C23 math function asinpif16 (#146226)
The function is implemented using the following Taylor series that's
generated using [python-sympy](https://www.sympy.org/en/index.html), and
it is very accurate for |x| $$\in [0, 0.5]$$ and has been verified using
Geogebra. The range reduction is used for the rest range (0.5, 1].

$$
\frac{\arcsin(x)}{\pi} \approx 
\begin{aligned}[t]
    &  0.318309886183791x  \\
    & + 0.0530516476972984x^3 \\
    & + 0.0238732414637843x^5 \\
    & + 0.0142102627760621x^7 \\
    & + 0.00967087327815336x^9 \\
    & + 0.00712127941391293x^{11} \\
    & + 0.00552355646848375x^{13} \\
    & + 0.00444514782463692x^{15} \\
    & + 0.00367705242846804x^{17} \\
    & + 0.00310721681820837x^{19} + O(x^{21})
\end{aligned}
$$

## Geogebra graph

![28-06-2025-1913-eDP-1](https://github.com/user-attachments/assets/f70818e1-1b34-406e-962a-a30fdc909f18)

Closes #132210
2025-07-26 14:02:18 +03:00
Uzair Nawaz
3f3d779ff8
[libc] Implement mbsinit (#150654)
Implemented public libc function to check if an mbstate describes an
empty state
2025-07-25 12:45:24 -07:00
sribee8
42b101d844
Revert "[libc] wchar string conversion functions mb to wc" (#150549)
Reverts llvm/llvm-project#149423

Failing nullptr crash when using sanitizer
2025-07-24 23:39:16 +00:00
sribee8
af98a245f8
[libc] wchar string conversion functions mb to wc (#149423)
Implemented an internal multi-byte to wide character string conversion
function, public functions, and tests

---------

Co-authored-by: Sriya Pratipati <sriyap@google.com>
2025-07-24 23:10:32 +00:00
Uzair Nawaz
7884c077ff
[libc] Implement wcs to mbs family of functions (#149421)
Implemented internal wcs to mbs internal function + tests
Impelemented wcs to mbs public functions
2025-07-24 13:15:52 -07:00
Uzair Nawaz
f26c0d00df
[libc] Implemented wcsdup libc function (#150453)
Implemented wcsdup by templating internal strdup function
2025-07-24 11:29:40 -07:00
sribee8
4f2686e5a1
[libc] Implemented mblen functions (#150141)
Implemented mblen and mbrlen as well as tests

---------

Co-authored-by: Sriya Pratipati <sriyap@google.com>
2025-07-24 18:28:25 +00:00
lntue
66603dd1f1
[libc][NFC] Add stdint.h proxy header to fix dependency issue with <stdint.h> includes. (#150303)
https://github.com/llvm/llvm-project/issues/149993
2025-07-23 20:19:52 -04:00
Prabhu Rajasekaran
e8182fb501
[libc] add wctype.h header (#149202)
Add basic configurations to generate wctype.h header file. To begin with
this header file just exposes one function iswalpha.
2025-07-17 13:06:04 -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
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
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
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
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
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