Commit Graph

4310 Commits

Author SHA1 Message Date
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
Tejas Vipin
dde00f5e22 [libc][math] Improve performance test framework (#134501)
- Merges `BinaryOpSingleOutputPerf.h` and
`SingleInputSingleOutputPerf.h` files into a unified `PerfTest.h` and
update all performance tests to use this.
- Improve the output printed to log file for tests.
- Removes unused `run_diff` method and redundant `run_perf` call in
`BINARY_INPUT_SINGLE_OUTPUT_PERF_EX` (previously
`BINARY_OP_SINGLE_OUTPUT_PERF_EX`)
- Change `BINARY_INPUT_SINGLE_OUTPUT_PERF_EX` and
`SINGLE_INPUT_SINGLE_OUTPUT_PERF` to not define `main`
2025-04-24 07:22:21 -04:00
gulfemsavrun
0d00b6bc3b Revert "[libc] build fix for sigsetjmp (#137047)" (#137077)
This reverts commit f07511a0e0.

This reverts commit 5bb4cf9d91.

It caused a CMake configuration issue.
2025-04-23 15:49:55 -07:00
Schrodinger ZHU Yifan
f07511a0e0 [libc] build fix for sigsetjmp (#137047)
This PR fixes the build failure due to the `sigsetjmp` implementation.

1. Use a most relaxed input constraint to fix `clang` build.
2. Avoid create alias target if os directory for `sigsetjmp_epilogue`
does not exist.
2025-04-23 15:50:55 -04:00
Schrodinger ZHU Yifan
5bb4cf9d91 [libc] implement sigsetjmp/siglongjmp for x86-64 (#136072) 2025-04-23 14:19:47 -04:00
Joseph Huber
cc6def4b75 [libc] Special case PPC double double for print (#136614)
Summary:
We use the storage class for `long double` in the printing
implementations. We don't fully support the PPC double double type,
which that maps to, but we can stub out just the support needed for the
print interface to works. This required using the internal interface for
storage type, but it should be good enough.

Fixes: https://github.com/llvm/llvm-project/issues/136596
2025-04-23 10:36:14 -05:00
lntue
7547ad3a7b [libc][math] Skip checking for exceptional values in expm1f when LIBC_MATH_SKIP_ACCURATE_PASS is set. (#130968) 2025-04-23 12:04:21 +07:00
Daniel Thornburgh
710ffb69bf [libc] Fix warnings for freelist_heap_test/fuzz (#136634)
Fixes #122367
2025-04-22 11:11:31 -07:00
Joseph Huber
a5cdbef5f0 Revert "[LLVM] Replace use of LLVM_RUNTIMES_TARGET with LLVM_DEFAULT_TARGET_TRIPLE (#136208)"
This reverts commit 2e145f11c0.

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
lntue
f351172d4a [libc] Export standard C symbols in the public packages for MacOS instead of namespaced C++ symbols. (#136100) 2025-04-17 16:02:44 +08:00
Wu Yingcong
6b8d072cfd [libc] Fix incorrect unsigned comparison (#135595)
There is a problem with such unsigned comparison pattern:
```
if(unsigned_a - unsigned_b > 0) { /* only NOT go here when unsigned_a==unsigned_b */ }
```
When `unsigned_a` < `unsigned_b`, the result will still be `>0` due to
underflow.
This patch fixes two of the occurrences I found.
Also remove two redundant `if` where its condition is guaranteed by
outer `if`.
2025-04-17 09:33:48 +08:00
Vinay Deshmukh
77f0708b9d [libc]: Remove -Wglobal-constructors for libc tests (#131485)
* Relates to: https://github.com/llvm/llvm-project/issues/119281
* Removes `-Wglobal-constructors` as per:
https://github.com/llvm/llvm-project/pull/131485#pullrequestreview-2728020622
2025-04-15 19:24:07 -05:00
Tsz Chan
f5c5f9f926 [libc] Implement getitimer and setitimer, add proxy headers for itimerval (#134773)
#133983
2025-04-14 13:39:42 -07:00
Petr Hosek
a43ff0ec8a [libc] Include extra baremetal headers and entrypoints (#135462)
These are all usable in baremetal environments.
2025-04-14 12:26:03 -07:00
Roland McGrath
db4ad4686f [libc] Add myself as maintainer for Public Headers / hdrgen (#135209) 2025-04-11 11:33:52 -07:00
Daniel Thornburgh
1e54bca669 [libc] Add dthorn as maintainer for allocator on baremetal (#135203)
This was on request from other maintainers, given that I've been
de-facto acting as maintainer of the baremetal allocator stuff.
2025-04-11 11:19:43 -07:00
Drew Lewis
d07a2164e7 Add generic sqrt root headers to libc sqrt specializations (#135237)
This header is needed to provide the declaration for the sqrt template.
You can build without these in the CMake build, but not having this
include in the architecture specific headers makes them not self
contained.
2025-04-10 12:04:41 -07:00
Joseph Huber
2f41fa387d [AMDGPU] Fix code object version not being set to 'none' (#135036)
Summary:
Previously, we removed the special handling for the code object version
global. I erroneously thought that this meant we cold get rid of this
weird `-Xclang` option. However, this also emits an LLVM IR module flag,
which will then cause linking issues.
2025-04-10 11:31:21 -05:00
Muhammad Bassiouni
785d69e317 [libc][test] make str_to_float_comparison_test independent of C++ headers. (#133978)
This is an attempt to move away from C++ headers to be able to run the
test without `libcxx`.
closes #129838

cc @lntue @RossComputerGuy
2025-04-09 14:11:02 -07:00
lntue
c5e07fb861 [libc] Use correct instruction for arm32 sqrt inline asm. (#134968)
https://godbolt.org/z/3jT7jdrs9
2025-04-09 00:01:45 -04:00
lntue
438ade1dfc [libc] Fix wrong #ifdef for riscv's sqrt. (#134964) 2025-04-08 22:40:20 -04:00
lntue
cf7d34a54d [libc] Extend fputil::sqrt to use floating point instructions for arm32. (#134499) 2025-04-08 22:14:38 -04:00
lntue
dbcde15aba [libc] Add remaining math function entrypoints to darwin/arm. (#134920)
To match with what are currently available on linux/x86_64.
2025-04-08 16:20:09 -04:00
Michael Jones
556fb4c9af [libc] Disable sin/cospif16 on aarch64 (#134918)
The tests are failing and it's unclear why. Disabling for now until a
fix can be implemented. See
https://github.com/llvm/llvm-project/issues/134917 for details.
2025-04-08 12:42:44 -07:00
wldfngrs
fdf20941a8 [libc][math] Fix signaling NaN handling for math functions. (#133347)
Add tests for signaling NaNs, and fix function behavior for handling
signaling NaN input.

Fixes https://github.com/llvm/llvm-project/issues/124812
2025-04-08 15:23:38 +02: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
jobhdez
1d7bd3bc5c [libc] Remove extra parenthesis in sin.cpp comments (#134477) 2025-04-04 23:51:56 -04:00
Michael Jones
e8b52acca2 [libc][NFC] replace NULL with nullptr (#134464)
Simple cleanup
2025-04-04 16:55:43 -07:00
Michael Jones
4c182df633 [libc] Fix suseconds_t definition and utimes_test (#134326)
The main issue was that the kernel expected `suseconds_t` to be 64 bits
but ours was 32. This caused inconsistent failures since all valid
`suseconds_t` values are less than 1000000 (1 million), and some
configurations caused `struct timeval` to be padded to 128 bits.

Also: forgot to use TEST_FILE instead of FILE_PATH in some places.
2025-04-04 12:53:46 -07:00
Michael Jones
c0079ba3dd [libc] Make utimes_test more stable (#134321)
The test for utimes added in #134167 might fail if the file for one test
hasn't been cleaned up by the OS before the second test starts. This
patch makes the tests use different files.
2025-04-03 16:53:55 -07:00
Aditya Tejpaul
d33ae41c62 [libc] Implemented utimes (Issue #133953) (#134167)
This pull request implements the `utimes` command in libc ([Issue
#133953](https://github.com/llvm/llvm-project/issues/133953)).

- [x] Add the implementation of `utimes` in `/src/sys/time`.
- [x] Add tests for `utimes` in `/test/src/sys/time`. 
- [x] Add `utimes` to
[entrypoints.txt](https://github.com/llvm/llvm-project/blob/main/libc/config/linux/x86_64/entrypoints.txt)
for at least x86_64 and whatever you're building on
- [x] Add `utimes` to
[include/sys/time.yaml](https://github.com/llvm/llvm-project/blob/main/libc/include/sys/time.yaml)
2025-04-03 16:19:12 -07:00
Connector Switch
b738b82699 [libc] Combine the function prototype int (*compar)(const void *, const void *) (#134238)
Closes #134118.
2025-04-04 00:36:23 +08:00
Abhinav Kumar
51d1c72886 [libc] Added support for fixed-points in `is_signed and is_unsigned`. (#133371)
Fixes #133365

## Changes Done
- Changed the signed checking to 
```cpp
struct is_signed : bool_constant<((is_fixed_point<T> || is_arithmetic_v<T>) && (T(-1) < T(0)))>
```
in ``/libc/src/__support/CPP/type_traits/is_signed.h``. Added check for
fixed-points.
- But, got to know that this will fail for ``unsigned _Fract`` or any
unsigned fixed-point because ``unsigned _Fract`` can’t represent -1 in
T(-1), while ``unsigned int`` can handle it via wrapping.
- That's why I explicity added ``is_signed`` check for ``unsigned``
fixed-points.
- Same changes to ``/libc/src/__support/CPP/type_traits/is_unsigned.h``.
- Added tests for ``is_signed`` and ``is_unsigned``.
2025-04-02 16:41:47 -04:00
Alexey Samsonov
07504afc42 [libc] Stop depending on .cpp files in libcxx_shared_headers library. (#133999)
Fix two instances of libcxx_shared_headers depending on .cpp files (in
Bazel build):

* Don't depend on exit syscall in LIBC_ASSERT implementation. This
dependency is not used, since LIBC_ASSERT always uses system <assert.h>
in the overlay mode, which is the only mode supported by Bazel.
* Don't depend on libc_errno in str-to-float and str-to-integer
conversions. We only need the ERANGE value, which can be obtained from
the proxy header instead.
2025-04-01 16:23:19 -07:00
lntue
44b87e4206 [libc] Reduce the range of hypotf exhaustive test to be run automatically. (#133944)
The current setup of `hypotf` exhaustive tests might take days to
finish.
2025-04-01 13:29:28 -04:00
lntue
65ad6267e8 [libc] Fix atan2f128 test for aarch64. (#133924) 2025-04-01 11:37:57 -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
Mikhail R. Gadelha
091051fb7f [libc] Add myself as maintainer of the riscv port (#133757)
Co-authored-by: Joseph Huber <huberjn@outlook.com>
2025-03-31 20:13:44 -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
Mohamed Emad
4840895467 [libc] implement memalignment (#132493)
This patch adds the `memalignment` function to LLVM-libc, following its
description in [WG14 N3220,
§7.24.2.1](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3220.pdf#page=387).

- [x] Add the implementation of `memalignment` in
[`/src/stdlib`](https://github.com/llvm/llvm-project/tree/main/libc/src/stdlib)
- [x] Add tests for `memalignment` in
[`/test/src/stdlib`](https://github.com/llvm/llvm-project/tree/main/libc/test/src/stdlib)
- [x] Add `memalignment` to
[`entrypoints.txt`](https://github.com/llvm/llvm-project/blob/main/libc/config/linux/x86_64/entrypoints.txt)
for at least x86_64 and whatever you're building on
- [x] Add `memalignment` to
[`include/stdlib.yaml`](https://github.com/llvm/llvm-project/blob/main/libc/include/stdlib.yaml)




Closes #132300

---------

Co-authored-by: Joseph Huber <huberjn@outlook.com>
2025-03-28 16:07:57 -07:00
Qinkun Bao
91d2ecf0d5 [NFC] Fix some typos in libc and mlir comments (#133374) 2025-03-28 15:52:37 -04:00
Joseph Huber
4abe47c6fc [libc] Enable 'mktime' for the GPU (#133437)
Summary:
This is a dependency on `strftime` which we provide, so we should have
this.
2025-03-28 11:14:51 -05:00
Joseph Huber
772173f548 [Clang][AMDGPU] Remove special handling for COV4 libraries (#132870)
Summary:
When we were first porting to COV5, this lead to some ABI issues due to
a change in how we looked up the work group size. Bitcode libraries
relied on the builtins to emit code, but this was changed between
versions. This prevented the bitcode libraries, like OpenMP or libc,
from being used for both COV4 and COV5. The solution was to have this
'none' functionality which effectively emitted code that branched off of
a global to resolve to either version.

This isn't a great solution because it forced every TU to have this
variable in it. The patch in
https://github.com/llvm/llvm-project/pull/131033 removed support for
COV4 from OpenMP, which was the only consumer of this functionality.
Other users like HIP and OpenCL did not use this because they linked the
ROCm Device Library directly which has its own handling (The name was
borrowed from it after all).

So, now that we don't need to worry about backward compatibility with
COV4, we can remove this special handling. Users can still emit COV4
code, this simply removes the special handling used to make the OpenMP
device runtime bitcode version agnostic.
2025-03-28 07:35:16 -05:00
Jesse D
f76254d9b2 [libc] Fix implicit conversion error in DyadicFloat::as_mantissa_type(). (#133383)
This is the same fix that was recently applied to
as_mantissa_type_rounded(), but for as_mantissa_type().
2025-03-28 08:31:17 -04:00