639 Commits

Author SHA1 Message Date
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
Jeff Bailey
d6ff5e7778
[libc][docs] Parse inline macro_value from YAML in docgen (#189118)
The docgen script was previously hardcoded to assume all implemented
macros must be placed in a *-macros.h header. This updates docgen to
read inline macro_value properties directly from the source YAML files,
correctly recognizing them as implemented.
2026-03-27 22:19:29 +00:00
Petter Berntsson
2af95b2fa2
[libc][docs] Fix POSIX basedefs links for nested headers (#188738)
Fix broken POSIX basedefs links for nested headers in llvm-libc docs.

The docgen script currently emits paths like `sys/wait.h.html`, but the
Open Group uses `sys_wait.h.html`, for example:
-
https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/sys_wait.h.html

This updates nested-header link generation while leaving flat headers
unchanged.
2026-03-27 17:30:43 +00:00
Anonmiraj
e06b5e53a2
[libc][math] Implement C23 half precision erfc function (#180930)
Add support for the half-precision complementary error function
`erfcf16``, using a Sollya generated polynomial implementation with
proper handling of special cases.

Extend the MPFR utilities with erfc support to allow tests.

closes: #180927
2026-03-27 10:42:03 -04:00
Alexey Samsonov
968b6aaef1
[libc][hdrgen] Print __BEGIN_C_DECLS / __END_C_DECLS conditionally. (#188830)
Clean up the `%public_api` printer code slightly - get rid of explicit
`\n` and ensure we only print `__BEGIN_C_DECLS` and `__END_C_DECLS` if
the generated header actually contains functions or objects to declare.

I've noticed that after 27ba9e2a44c11f8123528c350227db2c9a707c8f landed,
generated errno.h header has two blocks of `__BEGIN_C_DECLS` /
`__END_C_DECLS`: an empty one was generated automatically from
`%public_api` section that was intended to only add the `errno_t` type
declaration.
2026-03-26 20:02:34 +00:00
Jeff Bailey
079be4e739
[libc] Support Windows test executables in LibcTest lit format (#188057)
Updated LibcTest to handle Windows test executables:

* Added support for .exe extensions when identifying test executables.
* Skipped the executable bit check on Windows as it is not applicable.
* Updated .params file discovery to look for both <test>.exe.params and
<test>.params.

This allows running libc tests on Windows hosts.
2026-03-23 16:39:40 +00:00
Daniel Thornburgh
7efcd6198c
[libc] Modular printf option (float only) (#147426)
This adds LIBC_CONF_PRINTF_MODULAR, which causes floating point support
(later, others) to be weakly linked into the implementation.
__printf_modular becomes the main entry point of the implementaiton, an
printf itself wraps __printf_modular. printf it also contains a
BFD_RELOC_NONE relocation to bring in the float aspect.

See issue #146159 for context.
2026-03-19 14:22:03 -07: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
DylanFleming-arm
d682325961
[libc] Remove unused AOR_v20.02 directory (#185951)
As far as I am aware, AOR is no longer used anywhere within LLVM, as
most of the required code has since been ported to elsewhere within the
project.

Removes the entire directory, and updates some now outdated comments.
2026-03-12 10:14:04 -04:00
Victor Campos
753db4b457
[libc] Fix hdrgen test test_small_proxy.h (#185890)
The expected output was outdated as it did not contain the macro
definitions.

This patch fixes the issue.
2026-03-12 11:00:52 +00:00
Jeff Bailey
31f69d333e
[libc] Fix integration test args/env in LibcTest lit format (#184438)
Integration tests with ARGS or ENV in their add_integration_test() call
were being run with no arguments or environment variables by the
LibcTest lit format, causing failures in startup_args_test,
sprintf_size_test, getenv_test, execv_test, execve_test, and
getcwd_test.

Fix this by having add_integration_test() emit a sidecar
<executable>.params JSON file (via file(GENERATE)) whenever ARGS or ENV
are specified. LibcTest.execute() reads this file at test time and
passes the args and environment to the test executable.

Also always set PWD=exec_dir in the test environment so that
getenv("PWD") matches getcwd() for tests that compare them.
2026-03-04 09:47:40 +00:00
Jeff Bailey
7b7c8b2eb3
[libc] Extend check-libc-lit to cover include, integration, and all src tests (#184366)
The lit-based test runner introduced in c776a52f only discovered
libc.test.src tests with a strict __unit__.__build__ or
__hermetic__.__build__ suffix. This missed four categories of tests:

1. libc.test.include.* tests (e.g. isnan_test, signbit_test)
2. libc.test.integration.* tests (e.g. pthread, unistd, startup)
3. libc.test.src.* tests that have no __unit__/__hermetic__ marker (e.g.
errno_test, dirent_test, htonl)
4. libc.test.src.* tests with extra option suffixes between the type
marker and .__build__ (e.g. __unit__.__NO_FMA_OPT.__build__)

Wire up the two missing build dependencies so that check-libc-lit builds
include and integration tests before running them, and update
_isTestExecutable() to recognise all four patterns.

The pattern documentation was consolidated into the _isTestExecutable()
docstring, where it is next to the code it describes, to avoid the two
diverging in future.

Tested:
Compared the test count from a full `ninja check-libc` run (2765 tests)
against `llvm-lit --show-tests libc/test` after this change and
confirmed the counts match exactly.
2026-03-03 17:42:48 +00:00
Petr Hosek
c5339b7025
[libc] Use response files for hdrgen entry points (#183267)
This avoids the build failure when the command line ends up being too
long which can be especially problematic on Windows.

Fixes #182374
2026-02-26 00:42:17 -08:00
Marcell Leleszi
e316ea188a
[libc][wctype] Add missing functions to wctype docs (#181478)
#170525

Adds missing wctype.h functions to docs.
2026-02-16 10:15:53 +01:00
Jeff Bailey
c776a52fa2
[libc] Implement lit-based test execution for Libc (#178746)
This provides optional lit-based test execution for the LLVM Libc tests,
alongside the existing CMake-based test execution.

Usage:
  ninja -C build check-libc-lit
  cd build && bin/llvm-lit libc/test/src/

Partially addresses
[#118694](https://github.com/llvm/llvm-project/issues/118694). A future
PR once this lands will flip the default (per suggestion in the RFC)
2026-02-13 18:39:54 +00:00
Marcell Leleszi
d31dbb9555
[libc][wctype] Move classification lookup tables to a cpp file (#174993)
#170525

Previously, lookup tables were defined in a header so that they can be
constexpr, but this lead to each translation unit having it's own copy,
bloating the library size. Looking at current usages of wctype
functions, they are always used at runtime, so there's no benefit of
having them constexpr, so I'm moving them to a cpp file, so that there's
only a single copy in the library.
2026-02-05 17:58:50 +01:00
Petr Hosek
9a02a3c7f4
[libc] Support for generating proxy headers (#175279)
This is a follow up to #174823 which adds build system integration.
2026-01-09 23:21:16 -08:00
Roland McGrath
4040f6c6f8
[libc] Add hdrgen --proxy mode (#174823)
This adds the --proxy switch to generate headers like go
into libc/src/hdr/foo-proxy.h instead of public headers.
2026-01-07 11:17:12 -08:00
Marcell Leleszi
9373dbdc00
[libc][wctype] Create generation script for classification lookup tables (#172042)
[#172040](https://github.com/llvm/llvm-project/issues/172040)

This patch implements the scripts for generating the lookup tables and
associated utils for wctype classification functions. Not all Unicode
properties are covered as not all need a lookup table, the rest will be
hardcoded. The size of the generated tables is 47,8KB.
2026-01-06 12:13:28 +01:00
Muhammad Bassiouni
3a04e01f34
[libc][wctype][codegen] Add generation script for conversion data (#170868)
Closes #170871
2025-12-12 16:47:51 +02:00
Sterling-Augustine
a50a7ea2e2
[libc] Add support for getpagesize. (#171713)
As in the description.
2025-12-11 14:27:50 -08:00
Michael Jones
2797688887
[libc][docs] Add a sunset policy to porting docs (#168936)
As discussed in the monthly meeting, update the porting docs to clarify
what's needed for a target and add a policy for sunsetting targets.
2025-12-11 09:29:26 -08:00
Joseph Huber
7fe3564167
[Clang] Gut the libc wrapper headers and simplify (#168438)
Summary:
These were originally intended to represent the functions that are
present on the GPU as to be provided by the LLVM libc implementation.
The original plan was that LLVM libc would report which functions were
supported and then the offload interface would mark those as supported.
The problem is that these wrapper headers are very difficult to make
work given the various libc extensions everyone does so they were
extremely fragile.

OpenMP already declares all functions used inside of a target region as
implicitly host / device, while these headers weren't even used for CUDA
/ HIP yet anyway. The only things we need to define right now are the
stdio FILE types. If we want to make this work for CUDA we'd need to
define these manually, but we're a ways off and that's way easier
because they do proper overloading.
2025-11-19 07:18:13 -06:00
Roland McGrath
a24a7548b8
[libc][hdrgen] Sort identifiers with leading underscores specially (#165745)
This makes the sorting behavior more uniform: functions and
macros are always sorted (separately), not only when merging.

This changes the sort order used for functions and other things
sorted by their symbol names.  Symbols are sorted alphabetically
without regard to leading underscores, and then for identifiers
that differ only in the number of leading underscores, the fewer
underscores the earlier in the sort order.  For the functions
declared in a generated header, adjacent names with and without
underscores will be grouped together without blank lines.

This is implemented by factoring the name field, equality, and
sorting support out of the various entity classes into a new
common superclass (hdrgen.Symbol).

This uncovered YAML's requirement to quote the string "NULL" to
avoid pyyaml parsing it as None (equivalent to Javascript null)
rather than a string.
2025-10-30 11:49:22 -07:00
Roland McGrath
22079e3f36
[libc][hdrgen] Add extra_standards and license_text (#165459)
This adds a few new features to hdrgen, all meant to facilitate
using it with inputs and outputs that are outside the llvm-libc
source tree.

The new `extra_standards` field is a dictionary to augment the
set of names that can be used in `standards` lists.  The keys are
the identifiers used in YAML ("stdc") and the values are the
pretty names generated in the header comments ("Standard C").
This lets a libc project that's leveraging the llvm-libc sources
along with its own code define new APIs outside the formal and de
facto standards that llvm-libc draws its supported APIs from.

The new `license_text` field is a list of lines of license text
that replaces the standard LLVM license text used at the top of
each generated header.  This lets other projects use hdrgen with
their own inputs to produce generated headers that are not tied
to the LLVM project.

Finally, for any function attributes that are not in a canonical
list known to be provided by __llvm-libc-common.h, an include
will be generated for "llvm-libc-macros/{attribute name}.h",
expecting that file to define the "attribute" name as a macro.

All this can be used immediately by builds that drive hdrgen and
build libc code outside the LLVM CMake build.  Future changes
could add CMake plumbing to facilitate augmenting the LLVM CMake
build of libc with outside sources via overlays and cache files.
2025-10-30 10:00:51 -07:00
Roland McGrath
10afda0796
[libc][hdrgen] Fix includes sorting in JSON emission (#165460)
The JSON output support in hdrgen had a bug that tripped when
used with headers that use special-case headers like <stdint.h>
to supply some times, as well as llvm-libc-types/*.h headers.
2025-10-28 13:16:20 -07:00
Aiden Grossman
4d2d21331b [NFC][CI] Use Fully Qualified Names for All Containers
Fix the rest of the containers sitting around in the monorepo.
2025-10-08 22:08:46 +00:00
Vinay Deshmukh
beb743b982
[libc] Add -Wextra for libc tests (#153321)
RE apply https://github.com/llvm/llvm-project/pull/133643/commits#top
2025-09-22 12:56:38 -04:00
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
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
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
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
William Huynh
33fe6353ef
Revert "[libc] Add -Wextra for libc tests" (#153169)
Reverts llvm/llvm-project#133643
2025-08-12 11:40:14 +00:00
Vinay Deshmukh
e617dc80bf
[libc] Add -Wextra for libc tests (#133643)
* Relates to: https://github.com/llvm/llvm-project/issues/119281
2025-08-12 12:27:13 +01: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
Muhammad Bassiouni
45b15946b1
[libc][hdrgen] Fix hdrgen when using macros as guards in stdlib.yaml. (#152732) 2025-08-08 18:39:47 +03:00
Krishna Pandey
a4ff76e819
[libc][math][c++23] Implement basic arithmetic operations for BFloat16 (#151228)
This PR implements addition, subtraction, multiplication and division
operations for BFloat16.

---------

Signed-off-by: krishna2803 <kpandey81930@gmail.com>
Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
Co-authored-by: OverMighty <its.overmighty@gmail.com>
2025-08-06 10:42:55 -04: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
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
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
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
Anton
851f7c7421
[libc][math][c23] Add acospif16() function (#134664)
Addresses #132211  #132754
Part of #95250
2025-04-24 18:03:24 -04: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
Joseph Huber
bd6df0fe21
Reapply "[LLVM] Make the GPU loader utilities an LLVM tool (#132096)" (#132277)
Summary:
There were a few issues with the first one, leading to some errors and
warnings. Most importantly, this was building on MSVC which isn't
supported.
2025-03-21 11:05:32 -05:00
Joseph Huber
df2a56767d Revert "[LLVM] Make the GPU loader utilities an LLVM tool (#132096)"
This reverts commit 221b0117fd21d45098ead779a040a4b939a5c84f.

Some build failures requiring TargetParser and some warnings to clean
up.
2025-03-20 14:26:59 -05:00
Joseph Huber
221b0117fd
[LLVM] Make the GPU loader utilities an LLVM tool (#132096)
Summary:
These tools `amdhsa-loader` and `nvptx-loader` are used to execute unit
tests directly on the GPU. We use this for `libc` and `libcxx` unit
tests as well as general GPU experimentation. It looks like this.

```console
> clang++ main.cpp --target=amdgcn-amd-amdhsa -mcpu=native -flto -lc ./lib/amdgcn-amd-amdhsa/crt1.o
> llvm-gpu-loader a.out
Hello World!
```

Currently these are a part of the `libc` project, but this creates
issues as `libc` itself depends on them to run tests. Right now we get
around this by force-including the `libc` project prior to running the
runtimes build so that this dependency can be built first. We should
instead just make this a simple LLVM tool so it's always available.

This has the effect of installing these by default now instead of just
when `libc` was enabled, but they should be relatively small. Right now
this only supports a 'static' configuration. That is, we locate the CUDA
and HSA dependencies at LLVM compile time. In the future we should be
able to provide this by default using `dlopen` and some API.

I don't know if it's required to reformat all of these names since they
used the `libc` naming convention so I just left it for now.
2025-03-20 14:17:41 -05:00