503 Commits

Author SHA1 Message Date
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
6602d6c7a7
[libc][math][docs] Add documentation for BFloat16 type (#153475)
Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-08-15 20:07:33 +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
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
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
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
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
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
Shubh Pachchigar
98e8ef2273
[libc] Fix broken links in libc (#145199)
This PR fixes broken links in all files describing libc usage modes.
Please let me know if there are any other places that need updating.

---------

Co-authored-by: shubhp@perlmutter <shubhp@perlmutter.com>
2025-06-23 15:51:43 -07:00
Michael Jones
70f44ec6fe
[libc][NFC] Accept doc fix (#143996)
Docgen updates the docs when the config options are changed. This update
has been waiting since https://github.com/llvm/llvm-project/pull/143187.
2025-06-12 16:49:25 -07:00
Kewen12
a71210e5ab
Revert "[libc] Fix stdio tests after #143802" (#143824)
Reverts llvm/llvm-project#143810 

This PR breaks our buildbot:
https://lab.llvm.org/buildbot/#/builders/10/builds/7159 revert to
unblock downstream merge.
2025-06-11 23:24:56 -04:00
Michael Jones
3c7af175e5
[libc] Fix stdio tests after #143802 (#143810)
In #143802 the stdio test cleanup missed a few places where errno was
being set to a failing value, and one where the framework needed to
included.
2025-06-11 16:52:21 -07:00
lntue
d87eea35fa
[libc] Move libc_errno.h to libc/src/__support and make LIBC_ERRNO_MODE_SYSTEM to be header-only. (#143187)
This is the first step 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-06-11 16:25:27 -04: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
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
Kazu Hirata
c5229e92ce
[libc] Fix typos in documentation (#139852) 2025-05-14 07:14:43 -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
Howard Chu
c275fdc0bc
[libc][gpu][docs] Fix typos in GPU libc's documentation (#138565)
Fix typos in GPU libc's documentation about the rpc implementation.
2025-05-05 14:06:45 -05:00
lntue
ade502a8c4
[libc][math] Implement double precision asin correctly rounded for all rounding modes. (#134401)
Main algorithm:

The Taylor series expansion of `asin(x)` is:
```math
\begin{align*}
  asin(x) &= x + x^3 / 6 + 3x^5 / 40 + ... \\
       &= x \cdot P(x^2) \\
       &= x \cdot P(u) &\text{, where } u = x^2.
\end{align*}
```
For the fast path, we perform range reduction mod 1/64 and use degree-7
(minimax + Taylor) polynomials to approximate `P(x^2)`.

When `|x| >= 0.5`, we use the transformation:
```math
  u = \frac{1 + x}{2}
```
and apply half-angle formula to reduce `asin(x)` to:
```math
\begin{align*}
  asin(x) &= sign(x) \cdot \left( \frac{\pi}{2} - 2 \cdot asin(\sqrt{u}) \right) \\
       &= sign(x) \cdot \left( \frac{\pi}{2} - 2 \cdot \sqrt{u} \cdot P(u) \right).
\end{align*}
```
Since `0.5 <= |x| <= 1`, `|u| <= 0.5`. So we can reuse the polynomial
evaluation of `P(u)` when `|x| < 0.5`.

For the accurate path, we redo the computations in 128-bit precision
with degree-15 (minimax + Taylor) polynomials to approximate `P(u)`.
2025-04-25 09:55:21 -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
Joseph Huber
a5cdbef5f0 Revert "[LLVM] Replace use of LLVM_RUNTIMES_TARGET with LLVM_DEFAULT_TARGET_TRIPLE (#136208)"
This reverts commit 2e145f11c0bcfa2052416d96d682c75f33971a8c.

Somehow causes some static assertions to fail?
2025-04-22 08:08:51 -05:00
Joseph Huber
2e145f11c0
[LLVM] Replace use of LLVM_RUNTIMES_TARGET with LLVM_DEFAULT_TARGET_TRIPLE (#136208)
Summary:
For purposes of determining the triple, it's more correct to use
`LLVM_DEFAULT_TARGET_TRIPLE`.
2025-04-22 07:59:54 -05:00
amansharma612
3382aef944
[libc] Fixed typo in porting.rst (#134488)
Co-authored-by: Aman Sharma <210100011@iitb.ac.in>
2025-04-07 21:59:41 +01:00
lntue
8741412bdf
[libc][math] Implement a fast pass for atan2f128 with 1ULP error using DyadicFloat<128>. (#133150)
Part of https://github.com/llvm/llvm-project/issues/131642.
2025-04-01 10:57:32 -04:00
Tejas Vipin
8078665bca
[libc][math][c23] Add hypotf16 function (#131991)
Implement hypot for Float16 along with tests.
2025-03-31 10:06:28 -04:00
Tejas Vipin
d22e35be17
[libc][math][c23] Add asinhf16 function (#131351)
Implement asinh for Float16 along with tests. Closes #131001
2025-03-29 13:54:52 +01:00
Michael Jones
6cc208cd3c
[libc] Add maintainers file (#133471)
Based on #133297 by jhuber.

LLVM-libc needs a maintainers file, this patch adds an initial set.
The file is based on `clang/maintainers.rst` and
https://llvm.org/docs/DeveloperPolicy.html#maintainers.
2025-03-28 16:50:19 -07:00
Harrison Hao
445837a363
[libc][math][c23] Add fmaf16 C23 math function. (#130757)
Implementation of fmaf16 function for 16-bit inputs.
2025-03-23 10:48:56 +08:00
Harrison Hao
ee3e17d67f
[libc][math][c23] Add acoshf16 C23 math function. (#130588)
Implementation of acoshf16 function for 16-bit inputs.
2025-03-22 22:08:34 -04:00
Mohamed Emad
adcaf1769d
[libc] [NFC] fix type in docs/uefi/index.rst (#132553)
Closes #132537
2025-03-22 12:16:15 -07:00
lntue
a17b03f0e4
[libc][math] Implement fast pass for double precision atan function. (#132333)
Implement fast pass for double precision `atan` using range reduction
modulo 1/64 and degree-9 Taylor polynomial.
Relative error is bounded by 2^-66.
2025-03-21 14:12:06 -04:00
Prashanth
7063419460
[libc][docs] Add dirent implementation status doc and include in CMakeLists (#132151)
These changes tracks `dirent.h` for the implementation status of
functions and macros, with respect to the issue (
https://github.com/llvm/llvm-project/issues/122006 ).
2025-03-20 11:08:44 -04:00
Prashanth
592a3ba125
[libc][docs] Add sys/utsname header and documentation for uname function (#131817)
These changes tracks `utsname.h` for the implementation status of
functions and macros, with respect to the issue (
https://github.com/llvm/llvm-project/issues/122006 ).
2025-03-18 16:22:01 -04:00
Prashanth
47f7daab06
[libc][docs] Add glob implementation status doc and include in CMakeLists (#126923)
These changes tracks `glob.h` for the implementation status of functions
and macros, with respect to the issue ( #122006 ) .

cc @nickdesaulniers
2025-03-17 13:05:50 -04:00
Tristan Ross
4e841d7d63
[libc] add uefi docs (#131426)
Adds documentation for the UEFI target since #131246 was merged.
2025-03-16 10:21:19 -07:00
Joseph Huber
8437b7f558
[libc] Make RPC server handling header only (#131205)
Summary:
This patch moves the RPC server handling to be a header only utility
stored in the `shared/` directory. This is intended to be shared within
LLVM for the loaders and `offload/` handling.

Generally, this makes it easier to share code without weird
cross-project binaries being plucked out of the build system. It also
allows us to soon move the loader interface out of the `libc` project so
that we don't need to bootstrap those and can build them in LLVM.
2025-03-13 19:23:21 -05:00
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
PiJoules
313e2ef93e
[libc] Mark fixed point type generic macros as complete (#130805)
These were added in https://github.com/llvm/llvm-project/pull/129371.
2025-03-11 11:03:51 -07:00
Aiden Grossman
eac734aab6
[libc][docs] Fix libc docs build post #129138 (#130184)
The docs build action was failing with libc due to checks.rst not
existing in the expected path. This patch adjusts the path to the actual
path which seems to make everything happy. It seems like this did not
show up before as stdfix.rst was not included in a place that actually
caused it to get picked up by sphinx.
2025-03-06 14:07:44 -08:00
PiJoules
1a09adae9f
[libc] Add link to stdfix.h on headers page (#129138)
Co-authored-by: Petr Hosek <phosek@google.com>
2025-03-06 10:31:26 -08:00
OverMighty
d9ac5d0be6
[libc][docs] Add links to Peter Smith's FOSDEM 2025 talk (#129555) 2025-03-03 19:15:21 +01:00
PiJoules
7842954b9d
[stdfix] Update function names (#129129)
The remaining math functions are `mulifx` (int * fx = int), `divifx`
(int / fx = int), `fxdivi` (int / int = fx), and `idivfx` (fx / fx =
int).
2025-02-27 13:51:37 -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
PiJoules
9a32af25b4
[stdfix] Check fxbits as complete (#129107)
These were added in https://github.com/llvm/llvm-project/pull/114912 by
@smallp-o-p.
2025-02-27 12:04:06 -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
Alexey Samsonov
829e2a5526
[libc][hdrgen] Allow to treat hdrgen Python code as a Python module. (#128955)
Move the hdrgen code under a subdirectory to treat it as a Python
module.

This mimics the structure used by llvm/utils/lit and
llvm/utils/mlgo-utils and simplifies integration of hdrgen to the build
system which rely on Python modules. In addition to that, it clarifies
which imports are coming from the hdrgen-specific helpers (e.g. "from
type import ..." becomes "from hdrgen.type import ...".

Leave the entrypoints (top-level main.py and yaml_to_classes.py) as-is:
they can keep being referred by the CMake build system w/o any changes.
2025-02-26 15:41:30 -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