95 Commits

Author SHA1 Message Date
Zorojuro
15a7c45163
[libc][math][c23] Add asinbf16 math function (#184170)
Co-authored-by: bassiounix <muhammad.m.bassiouni@gmail.com>
2026-03-30 21:29:55 +02:00
Mohamed Emad
1bb03026b6
[libc][math][c23] implement double-precision asinpi (#188158)
Implement the double precision version of the asinpi c23 math function
2026-03-29 10:18:07 -04:00
Shikhar Soni
f0ce26d06d
[libc][math][c23] Add log2p1f16 C23 math function (#186754)
Signed-off-by: Shikhar Soni <shikharish05@gmail.com>
2026-03-28 11:34:42 -04:00
Petter Berntsson
da439d5426
[libc][docs] Avoid docgen target collisions and restore pthread docs (#188221)
Fixes llvm/llvm-project#123821.

Re-enabling pthread docs created a global CMake utility target named
`pthread`, which collides in combined runtime builds where `pthread` is
expected to be a library name. Namespace the internal libc docgen helper
targets under `libc-docgen-*` and restore the generated pthread docs
page. `docs-libc-html` is unchanged.
2026-03-24 14:33:34 +00:00
Zorojuro
7d7cd745af
[libc][math][c23] Add atanbf16 function (#184019)
This PR intends to add atanbf16 higher math function for BFloat16 type
along with the tests.
2026-03-21 11:09:11 -04:00
Xinlong Chen
458096d5f8
[libc][math][c23] Add atan2f16 function (#183531)
Add atan2f16 function

closes https://github.com/llvm/llvm-project/issues/180969
Part of https://github.com/llvm/llvm-project/issues/95250.

also refactor to header only, it's a part of
https://github.com/llvm/llvm-project/issues/147386
2026-03-13 22:12:44 +02:00
Zorojuro
ad054822eb
[libc][math][c23] Add hypotbf16 function (#183460)
This PR intends to add hypotbf16 higher math function for BFloat16 type
along with the tests.
2026-03-13 10:11:33 -04:00
Shikhar Soni
a7d1a87b30
[libc][math][c23] Add log10p1f16 C23 math function (#184739)
Closes #133202

---------

Signed-off-by: Shikhar Soni <shikharish05@gmail.com>
2026-03-13 09:59:26 -04:00
Zorojuro
0bebee6782
[libc][math][c++23] Add Fmabf16 math function (#182836)
closes #180171 
part of #177259 

Here are some extra changes apart from the usual which were needed
1. `libc/src/__support/FPUtil/generic/add_sub.h` → +0 -0 error
2. `libc/src/__support/FPUtil/generic/FMA.h` → implemented to handle
fmabf16(Normal,Normal,+/-INF)

```jsx
/home/runner/work/llvm-project/llvm-project/libc/test/src/math/fmabf16_test.cpp:62: FAILURE
Failed to match __llvm_libc_23_0_0_git::fmabf16(x, y, z) against LIBC_NAMESPACE::testing::mpfr::get_mpfr_matcher<mpfr::Operation::Fma>( input, __llvm_libc_23_0_0_git::fmabf16(x, y, z), 0.5, mpfr::RoundingMode::Nearest).
Input decimal: x: 338953138925153547590470800371487866880.00000000000000000000000000000000000000000000000000 y: 338953138925153547590470800371487866880.00000000000000000000000000000000000000000000000000 z: -inf
 First input bits: 0x7F7F = (S: 0, E: 0x00FE, M: 0x007F)
Second input bits: 0x7F7F = (S: 0, E: 0x00FE, M: 0x007F)
 Third input bits: (-Infinity)
Libc result: nan
MPFR result: -inf
Libc floating point result bits: (NaN)
              MPFR rounded bits: (-Infinity)
```

1. ~~`libc/src/__support/FPUtil/bfloat16.h` → to handle *= operator for
Bfloat16 ( uses the already available mult operator)~~
moved to  #182882 

The exhaustive test currently includes subnormal range and for checking
for specific edge cases . This is due to the repeated failure at <2^32
input space specifically only for ubuntu 24.04 and 24.04-arm
The removed tests included -> PositiveRange and NegativeRange for
Normals and an extra positive test for subnormals/Denormals

Let me know if there are any changes expected or anything I missed in
this .
 cc: @lntue @krishna2803 @overmighty
2026-03-13 05:33:52 +00:00
sohail
cd7e200e42
[libc][math] Add cbrtbf16 math function (#180327)
Add a bfloat16 implementation of cbrt along with corresponding smoke
tests and an MPFR-based exhaustive unit test.

Fixes #179729
2026-03-10 12:59:26 -04:00
Jeff Bailey
7030a34403
[libc][docs] Furo theme, new landing page, cleanups (#184303)
Switch the libc documentation site from the alabaster theme to Furo,
which provides mobile-friendly layout, a collapsible sidebar with
caption-based section grouping, and built-in "Edit this page" links.

Changes by area:

conf.py
- Switch html_theme to "furo"
- Add myst_parser extension (already in llvm/docs/requirements.txt, used
by LLDB/Clang/LLVM docs) to allow Markdown alongside RST
- Accept both .rst and .md source suffixes
- Configure Furo source_repository/source_branch/source_directory for
"Edit this page" links pointing to GitHub
- Wire _static/copybutton.{js,css} for copy-to-clipboard buttons on code
blocks (no new pip dependency; can migrate to sphinx-copybutton later
once it's in requirements-hashed.txt)
- Exclude plan-docs.md and Helpers/ from Sphinx processing

index.rst
- Rewrite landing page: remove apologetic "not fully complete" note, add
"What Works Today" section with concrete supported use cases, honest
caveat that full C stdlib coverage is still in progress
- Restructure hidden toctrees into five captioned sidebar groups: "Using
LLVM-libc", "Platforms" (GPU/UEFI promoted to top-level),
"Implementation Status", "Development", "Links"

New files
- docs/_static/copybutton.{js,css}: lightweight copy button for code
blocks
- docs/_static/custom.css: add status badge styles (.badge-complete
etc.) for use with Helpers/Styles.rst substitutions in later phases

Prepare for future status badges:
- docs/Helpers/Styles.rst: RST substitution definitions for status
badges (|Complete|, |Partial|, |InProgress|, |NotStarted|, |GPUOnly|,
|LinuxOnly|) — excluded from toctree, available for Phase 5+ pages
- docs/dev/building_docs.rst: new page covering prerequisites (with
Debian apt-first instructions), CMake flags, ninja docs-libc-html, the
docgen auto-generation pipeline, and troubleshooting

Removed
- docs/README.txt: stale file claiming Sphinx 1.1.3, not in any toctree;
superseded by docs/dev/building_docs.rst

Cleanups
- Remove redundant ".. contents:: Table of Contents" directives from 16
RST files (Furo renders its own per-page TOC in the sidebar)
- Remove same directive from libc/Maintainers.rst (pulled into docs via
include)
2026-03-09 20:48:42 +00:00
Mohamed Emad
8f3dd82a0a
[libc][math][c23] implement asinpif function (#181511)
Implementing `asinpi` for single-precision. it continues what is done in
#152690 that implemented `asinpif16` with header-only approach that is
followed since #147386
2026-02-26 05:05:49 +02:00
Petter Berntsson
19d6950739
[libc][docs] Fix stale entrypoints links and time.h table duplication (#180347)
Update stale links and remove duplication in table.
2026-02-10 00:02:28 +00:00
Anton Shepelev
79601cec33
[libc][POSIX] Add clock_settime() function for Linux (#161729)
Closes #161461
- This is my first time contributing to libc's POSIX, so for reference I
used `clock_gettime` implementation for Linux. For convenience, here is
the description of `clock_settime` function
[behavior](https://www.man7.org/linux/man-pages/man3/clock_settime.3.html)
2025-11-11 09:54:34 -08:00
Anton Shepelev
1244fd24d9
[libc][math][c23] Add rsqrtf() function (#159615)
Closes #159614

**Changes:**
- Initial implementation of rsqrt for single precision float

**Some small unrelated style changes to this PR (that I missed in my
rsqrtf16 PR):**
- Added extra - to the top comments to make it look nicer in
libc/shared/math/rsqrtf16.h
- Put rsqrtf16 inside of libc/src/__support/math/CMakeLists.txt in
sorted order
- Rearanged libc_math_function rsqrtf16 in Bazel to match alphabetical
order
2025-10-08 23:37:01 -04:00
Shreeyash Pandey
c57796dcb2
[libc][stdfix] Implement fxdivi functions (rdivi) (#154914)
This PR includes only one of the fxdivi functions (rdivi). It uses a
polynomial function for initial approximation followed by 4
newton-raphson iterations to calculate the reciprocal and finally
multiplies the numerator with it to get the result.


---------

Signed-off-by: Shreeyash Pandey <shreeyash335@gmail.com>
2025-10-08 15:17:31 -04:00
Krishna Pandey
1fda257728
[libc][math][c++23] Add log_bf16 math function (#157811)
This PR adds log_bf16 higher math function for BFloat16 type along with
the tests.

---------

Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-09-24 20:47:10 +05:30
Anton Shepelev
80f9c72a1e
[libc][math][c23] Add rsqrtf16() function (#137545)
Addresses #132818 
Part of #95250
2025-09-17 10:19:20 -04:00
Krishna Pandey
8dda18f836
[libc][math][c++23] Add sqrtbf16 math function (#156654)
This PR adds sqrtbf16 higher math function for BFloat16 type along with
the tests.

---------

Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-09-06 14:36:02 +05:30
Zishan Mirza
b946b2b4c9
[libc] add ctime and ctime_r to docs (#156216)
I noticed that I forgot to add `ctime` and `ctime_r` to docs in
https://github.com/llvm/llvm-project/pull/107285. This is a simple patch
to add it.
2025-09-05 10:21:18 -07:00
Connector Switch
78579b9157
[libc] Implement CMPLX related macros (#156344) 2025-09-05 10:08:04 +08:00
Leandro Lacerda
4e607599e6
[libc][docs] Add GPU math conformance test results to support page (#156263)
This patch enhances the GPU support documentation page (`support.html`)
by adding a new, detailed section for `math.h`. This new section
presents the results of the GPU math conformance tests, providing
quantitative data on the accuracy of the supported higher math
functions.
2025-09-04 16:01:04 -05:00
Zishan Mirza
17bddd1224
[libc] implement template functions for localtime (#110363)
This is an implementation for template functions of localtime.

Update for this pull request: Implementation as been removed from this
pull request and will be added to a new one. This is because this pull
request is getting big. This pull request will only contain template
functions in order to implement localtime.

Update: The implementation is available in
https://github.com/zimirza/llvm-project/tree/localtime_implementation.

---------

Co-authored-by: Зишан Мирза <zmirza@tutanota.de>
Co-authored-by: Zishan Mirza <zmirza@posteo.de>
2025-09-03 14:55:02 -07:00
Krishna Pandey
96b1dfb57f
[libc][math][c++23] Add fmodbf16 math function (#155575)
This PR adds fmodbf16 basic math function for BFloat16 type along with
the tests.

---------

Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-09-03 22:20:07 +05:30
Mohamed Emad
c1d1e0e32f
[libc][math][c23] Implement C23 math function atanpif16 (#150400)
This PR implements `atanpif16(x)` which computes
$\frac{\arctan(x)}{\pi}$ for half-precision floating-point numbers using
polynomial approximation with domain reduction.

## Mathematical Implementation

The implementation uses a 15th-degree Taylor polynomial expansion of
$\frac{\arctan(x)}{\pi}$ that's computed using
[`python-sympy`](https://www.sympy.org/en/index.html) and it's accurate
in $|x| \in [0, 0.5)$:

$$
g(x) = \frac{\arctan(x)}{\pi} \approx 
\begin{aligned}[t]
    & 0.318309886183791x \\
    & - 0.106103295394597x^3 \\
    & + 0.0636619772367581x^5 \\
    & - 0.0454728408833987x^7 \\
    & + 0.0353677651315323x^9 \\
    & - 0.0289372623803446x^{11} \\
    & + 0.0244853758602916x^{13} \\
    & - 0.0212206590789194x^{15} + O(x^{17})
\end{aligned}
$$


--- 

To ensure accuracy across all real inputs, the domain is divided into
three cases with appropriate transformations:

**Case 1: $|x| \leq 0.5$**  
Direct polynomial evaluation: 

$$\text{atanpi}(x) = \text{sign}(x) \cdot g(|x|)$$

**Case 2: $0.5 < |x| \leq 1$**  
Double-angle reduction using:

$$\arctan(x) = 2\arctan\left(\frac{x}{1 + \sqrt{1 + x^2}}\right)$$

$$\text{atanpi}(x) = \text{sign}(x) \cdot 2g\left(\frac{|x|}{1 + \sqrt{1
+ x^2}}\right)$$

**Case 3: $|x| > 1$**  
Reciprocal transformation using 

$$\arctan(x) = \frac{\pi}{2} - \arctan\left(\frac{1}{x}\right) \
\text{for} \ x \gt 0$$

$$\text{atanpi}(x) = \text{sign}(x) \cdot \left(\frac{1}{2} -
g\left(\frac{1}{|x|}\right)\right)$$


Closes #132212
2025-09-02 22:50:50 +03:00
Krishna Pandey
a985be6fdf
[libc][math][c++23] Add scalb{,l}nbf16 math functions (#155569)
This PR adds the following basic math functions for BFloat16 type along
with the tests:
- scalbnbf16
- scalblnbf16

---------

Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-08-28 20:29:03 +05:30
Krishna Pandey
691f231579
[libc][math][c++23] Add totalorder{,mag}bf16 math functions (#155568)
This PR adds the following basic math functions for BFloat16 type along
with the tests:
- totalorderbf16
- totalordermagbf16

---------

Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-08-28 19:37:07 +05:30
Krishna Pandey
3d2b282044
[libc][math][c++23] Add {canonicalize,iscanonical,fdim,copysign,issignaling}bf16 math functions (#155567)
This PR adds the following basic math functions for BFloat16 type along
with the tests:
- canonicalizebf16
- iscanonicalbf16
- fdimbf16
- copysignbf16
- issignalingbf16

---------

Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-08-27 22:31:17 +05:30
Krishna Pandey
f005e2cb7a
[libc][math][c++23] Add {modf,remainder,remquo}bf16 math functions (#154652)
This PR adds the following basic math functions for BFloat16 type along
with the tests:
- modfbf16
- remainderbf16
- remquobf16

---------

Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
Co-authored-by: OverMighty <its.overmighty@gmail.com>
2025-08-27 11:42:09 +05:30
Krishna Pandey
c11acac4dc
[libc][math][c++23] Add {frexp,ilogb,ldexp,llogb,logb}bf16 math functions (#154427)
This PR adds the following basic math functions for BFloat16 type along
with the tests:
- frexpbf16
- ilobbf16
- ldexpbf16
- llogbbf16
- logbbf16

---------

Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-08-25 11:46:25 +05:30
Krishna Pandey
60743358d1
[libc][math][c++23] Add {nearbyint,rint,lrint,llrint,lround,llround}bf16 math functions (#153882)
This PR adds the following basic math functions for BFloat16 type along
with the tests:
- nearbyintbf16
- rintbf16
- lrintbf16
- llrintbf16
- lroundbf16
- llroundbf16

---------

Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-08-24 20:51:02 +05:30
Krishna Pandey
699f15426f
[libc][math][c++23] Add nanbf16 math function (#153995)
This PR adds the nanbf16 basic math function for BFloat16 type along
with the tests.

---------

Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-08-23 14:45:53 +05:30
Krishna Pandey
de6bd152b9
[libc][math][c++23] Add {get,set}payloadbf16 and setpayloadsigbf16 math functions (#153994)
This PR adds the following basic math functions for BFloat16 type along
with the tests:
- getpayloadbf16
- setpayloadbf16
- setpayloadsigbf16

---------

Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-08-23 01:02:02 +05:30
Krishna Pandey
eac19d46d8
[libc][math][c++23] Add next{after,down,toward,up}bf16 math functions (#153993)
This PR adds the following basic math functions for BFloat16 type along
with the tests:
- nextafterbf16
- nextdownbf16
- nexttowardbf16
- nextupbf16

---------

Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
Co-authored-by: OverMighty <its.overmighty@gmail.com>
2025-08-22 22:01:49 +05:30
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
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
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
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
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
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
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