summaryrefslogtreecommitdiff
path: root/libc/utils
AgeCommit message (Collapse)Author
2025-11-19[Clang] Gut the libc wrapper headers and simplify (#168438)Joseph Huber
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-10-30[libc][hdrgen] Sort identifiers with leading underscores specially (#165745)Roland McGrath
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[libc][hdrgen] Add extra_standards and license_text (#165459)Roland McGrath
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-28[libc][hdrgen] Fix `includes` sorting in JSON emission (#165460)Roland McGrath
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-08[NFC][CI] Use Fully Qualified Names for All ContainersAiden Grossman
Fix the rest of the containers sitting around in the monorepo.
2025-09-22[libc] Add -Wextra for libc tests (#153321)Vinay Deshmukh
RE apply https://github.com/llvm/llvm-project/pull/133643/commits#top
2025-09-17[libc][math][c23] Add rsqrtf16() function (#137545)Anton Shepelev
Addresses #132818 Part of #95250
2025-09-06[libc][math][c++23] Add sqrtbf16 math function (#156654)Krishna Pandey
This PR adds sqrtbf16 higher math function for BFloat16 type along with the tests. --------- Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-09-02[libc][math][c23] Implement C23 math function atanpif16 (#150400)Mohamed Emad
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-08-24[libc][math][c++23] Add {nearbyint,rint,lrint,llrint,lround,llround}bf16 ↵Krishna Pandey
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-18Reland "[libc][math][c23] Implement C23 math function asinpif16" (#152690)Mohamed Emad
#146226 with fixing asinpi MPFR number function and make it work when mpfr < `4.2.0`
2025-08-13[libc][math][c++23] Add bf16fma{,f,l,f128} math functions (#153231)Krishna Pandey
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-12Revert "[libc] Add -Wextra for libc tests" (#153169)William Huynh
Reverts llvm/llvm-project#133643
2025-08-12[libc] Add -Wextra for libc tests (#133643)Vinay Deshmukh
* Relates to: https://github.com/llvm/llvm-project/issues/119281
2025-08-08[libc][math][c++23] Add bf16{add,sub}{,f,l,f128} math functions (#152774)Krishna Pandey
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[libc][hdrgen] Fix hdrgen when using macros as guards in stdlib.yaml. (#152732)Muhammad Bassiouni
2025-08-06[libc][math][c++23] Implement basic arithmetic operations for BFloat16 (#151228)Krishna Pandey
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-07-26Revert "[libc][math][c23] Implement C23 math function asinpif16" (#150756)OverMighty
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[libc][math][c23] Implement C23 math function asinpif16 (#146226)Mohamed Emad
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-23[libc][NFC] Add stdint.h proxy header to fix dependency issue with ↵lntue
<stdint.h> includes. (#150303) https://github.com/llvm/llvm-project/issues/149993
2025-07-09[libc][math][c++23] Add bfloat16 support in LLVM libc (#144463)Krishna Pandey
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[libc] Simplify the version guard for mpfr. (#146354)Connector Switch
Instead of manually calculating the major and minor version numbers, we can directly use `MPFR_VERSION_NUM` to simplify this.
2025-04-24[libc][math][c23] Add acospif16() function (#134664)Anton
Addresses #132211 #132754 Part of #95250
2025-03-23[libc][math][c23] Add fmaf16 C23 math function. (#130757)Harrison Hao
Implementation of fmaf16 function for 16-bit inputs.
2025-03-21Reapply "[LLVM] Make the GPU loader utilities an LLVM tool (#132096)" (#132277)Joseph Huber
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-20Revert "[LLVM] Make the GPU loader utilities an LLVM tool (#132096)"Joseph Huber
This reverts commit 221b0117fd21d45098ead779a040a4b939a5c84f. Some build failures requiring TargetParser and some warnings to clean up.
2025-03-20[LLVM] Make the GPU loader utilities an LLVM tool (#132096)Joseph Huber
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[libc][docs] Add dirent implementation status doc and include in CMakeLists ↵Prashanth
(#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-18[libc][docs] Add sys/utsname header and documentation for uname function ↵Prashanth
(#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[libc] Define (stub) dl_iterate_phdr (#131436)Roland McGrath
This fleshes out the <link.h> a little more, including the `struct dl_phdr_info` type and declaring the dl_iterate_phdr function. There is only a no-op implementation without tests, as for the existing dlfcn functions.
2025-03-18[libc] Fix compile error in MPFRWrapper when float128 is long double (#131821)OverMighty
See https://lab.llvm.org/buildbot/#/builders/104/builds/18422.
2025-03-18[libc][math] Fix incorrect logic in fputil::generic::add_or_sub (#116129)OverMighty
Fixes incorrect logic that went unnoticed until the function was tested with output and input types that have the same underlying floating-point format.
2025-03-17[libc][docs] Add glob implementation status doc and include in CMakeLists ↵Prashanth
(#126923) These changes tracks `glob.h` for the implementation status of functions and macros, with respect to the issue ( #122006 ) . cc @nickdesaulniers
2025-03-14[libc] init uefi (#131246)Tristan Ross
Initial UEFI OS target support after the headers. This just defines enough that stuff might try and compile. Test with: ``` $ cmake -S llvm -B build -G Ninja -DLLVM_RUNTIME_TARGETS=x86_64-unknown-uefi-llvm -DRUNTIMES_x86_64-unknown-uefi-llvm_LLVM_ENABLE_RUNTIMES=libc -DRUNTIMES_x86_64-unknown-uefi-llvm_LLVM_LIBC_FULL_BUILD=true -DCMAKE_C_COMPILER_WORKS=true -DCMAKE_CXX_COMPILER_WORKS=true -DLLVM_ENABLE_PROJECTS="clang;lld" -DCMAKE_BUILD_TYPE=Debug -DLLVM_ENABLE_LIBCXX=true -DLLVM_HOST_TRIPLE=aarch64-unknown-linux-gnu -DLLVM_DEFAULT_TARGET_TRIPLE=x86_64-unknown-uefi-llvm -DCMAKE_INSTALL_LIBDIR=build/target/lib $ ninja -C build ```
2025-03-14[libc] Fix implicit conversion warnings in tests. (#131362)lntue
2025-03-13[libc] Make RPC server handling header only (#131205)Joseph Huber
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[libc] Remove use of C++ STL features from `rpc_server.cpp` (#131169)Joseph Huber
Summary: This is done in preparation for making this header only so we can use it without an object library. This will be a transient interface that internal LLVM stuff with use. External people can use it too if they go through the LLVM libc interface for shared stuff but there's no backward compatibility guarantees. Patch just cleans it up prior to the move.
2025-03-12[libc] Template the writing mode for the writer class (#111559)Joseph Huber
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-04[libc][bazel] Add BUILD targets for complex functions and tests. (#129618)Jorge Gorbe Moya
This involved a little bit of yak shaving because one of the new tests depends on MPC, and we didn't have targets for it yet, so I ended up needing to add a similar setup to what we have for MPFR.
2025-02-28[libc] Fix warning in libc/utils/MPCWrapper/MPCUtils.h (#129349)Jorge Gorbe Moya
`cpp::is_complex_type_same<T1, T2>` is a function, so we need parentheses in order to call it. Otherwise the expression is treated like a function pointer which is always true in this boolean context.
2025-02-26[libc][hdrgen] Allow to treat hdrgen Python code as a Python module. (#128955)Alexey Samsonov
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-19[libc] Add --json mode for hdrgen (#127847)Roland McGrath
This adds a feature to hdrgen to emit JSON summaries of header files for build system integration. For now the summaries have only the basic information about each header that is relevant for build and testing purposes: the standards and includes lists.
2025-02-15[libc] Produce standard-compliant header guard macros in hdrgen (#127356)Roland McGrath
Macros starting with alphabetic characters such as "LLVM" are in the application name space and cannot be defined or used by a conforming implementation's headers. This fixes the headers that are entirely generated, and the __llvm-libc-common.h header to use a conforming macro name for the header guard. That is, it starts with "_LLVM_LIBC_" instead of "LLVM_LIBC_", as identifiers starting with an underscore followed by a capital letter are in the name space reserved for the implementation. The remaining headers either will be fixed implicitly by removal of their custom template files, or will need to be fixed by hand.
2025-02-14[libc] Elide extra space in hdrgen function declarations (#127287)Roland McGrath
When the return type's rendering already doesn't end with an identifier character, such as when it's `T *`, then idiomatic syntax does not include a space before the `(` and arguments.
2025-02-14[libc] Add merge_yaml_files feature to hdrgen (#127269)Roland McGrath
This allows a sort of "include" mechanism in the YAML files. A file can have a "merge_yaml_files" list of paths (relative to the containing file's location). These are YAML files in the same syntax, except they cannot have their own "header" entry. Only the lists (types, enums, macros, functions, objects) can appear. The main YAML file is then processed just as if each of its lists were the (sorted) union of each YAML file's corresponding list. This will enable maintaining a single source of truth for each function signature and other such details, where it is necessary to generate the same declaration in more than one header.
2025-02-14[libc] Make template_header optional for hdrgen (#127259)Roland McGrath
This allows a YAML file to omit `template_header` and have no `.h.def` file. A default template is generated based purely on the information in the YAML file. This should handle most of the cases. For now, it's exercised (aside from the hdrgen tests) only for one of the simplest cases: <ctype.h>. This includes making the parser notice the "standards" YAML field at the top (header) level, not just in "functions" lists. The standards listed for the header overall and for the individual functions both feed into how a fully-generated header describes itself in comments. To go with this, files using the default generated template must stick to a new uniform set of spellings for the "standards" lists. As more custom template files are retired, the corresponding YAML files will need all their standards lists normalized. For now, ctype.yaml is updated with correct attribution for the POSIX `_l` extensions.
2025-02-14[libc] Fix hdrgen to be compatible with Python 3.8 (#127265)Roland McGrath
2025-02-14[libc] Make hdrgen deduce header type lists from function signatures (#127251)Roland McGrath
With this, the `types` list in YAML files should only be used to list the types that a standard specifies should be in that header per se. All the types referenced in function signatures will be collected automatically.
2025-02-14[libc] Make hdrgen emit correct relative paths for llvm-libc-types (#127150)Roland McGrath
This makes hdrgen emit `#include "..."` lines using the correct relative path (number of `../` steps, if any) for the containing header, and includes this in the sorted block of `#include` lines also used for the macro headers.
2025-02-13[libc] Make hdrgen support macro_header YAML field. (#123265)Roland McGrath
A macro can specify macro_header instead of macro_value to indicate that an llvm-libc-macros/ header file is supposed to define this macro. This is used for dlfcn.h, which previously bogusly redefined the RTLD_* macros to empty.