Commit Graph

1273 Commits

Author SHA1 Message Date
lntue
3c2feab7d1 Revert "[libc] implement ioctl" (#88226)
Reverts llvm/llvm-project#85890

This fails in full build mode:

https://lab.llvm.org/buildbot/#/builders/163/builds/54478/steps/4/logs/stdio
2024-04-09 23:48:09 -04:00
Nhat Nguyen
289a2c380e [libc] implement ioctl (#85890)
This PR is to work on the issue #85275
2024-04-09 23:38:23 -04:00
Job Henandez Lara
49561181bd [libc] Add proxy header for fenv.h macro constants. #87863 (#87896)
Hello, this addresses #87863.
2024-04-09 12:55:10 -04:00
Joseph Huber
71ffc1f0ea [libc] Initialize rand for fma tests (#88055)
Summary:
The GPU build will have some random garbage here since we do not support
initializers for the underlying implementation. Manually set the seed to
1.
2024-04-09 11:07:36 -05:00
lntue
ac8ed7f16e [libc] Remove RandUtils.(h|cpp). (#88044) 2024-04-08 17:25:32 -04:00
lntue
312b9297bb [libc] Increase timeout for death tests. (#87959)
Fix test timeout on RISCV bots.
Fixes https://github.com/llvm/llvm-project/issues/87096
2024-04-08 11:31:07 -04:00
lntue
5f7b133e32 [libc][math] Update error bound for log1p to compensate for directional rounding. (#87893) 2024-04-06 17:38:20 -04:00
Guillaume Chatelet
b88a1dd6c7 [libc] Make BigInt bitwise shift consistent with regular integral semantics. (#87874)
This patch removes the test for cases where the shift operand is greater
or equal to the bit width of the number. This is done for two reasons,
first it makes `BigInt` consistent with regular integral bitwise shift
semantics, and second it makes the shift operation faster. The shift
operation is on the critical path for `exp` and `log` operations, see
https://github.com/llvm/llvm-project/pull/86137#issuecomment-2034133868.
2024-04-06 19:30:16 +02:00
Guillaume Chatelet
fc7087b7b7 [libc][NFC] Rename uint_test into big_int_test for consistency (#87875) 2024-04-06 19:10:25 +02:00
Guillaume Chatelet
09efe848cf [libc][NFC] Rename UInt.h to big_int.h and UInt128.h to uint128.h for consistency (#87808) 2024-04-06 10:39:55 +02:00
lntue
5748ad84e5 [libc] Add proxy header math_macros.h. (#87598)
Context: https://github.com/llvm/llvm-project/pull/87017

- Add proxy header `libc/hdr/math_macros.h` that will:
  - include `<math.h>` in overlay mode,
- include `"include/llvm-libc-macros/math-macros.h"` in full build mode.
- Its corresponding CMake target `libc.hdr.math_macros` will only depend
on `libc.include.math` and `libc.include.llvm-libc-macros.math_macros`
in full build mode.
- Replace all `#include "include/llvm-libc-macros/math-macros.h"` with
`#include "hdr/math_macros.h"`.
- Add dependency to `libc.hdr.math_macros` CMake target when using
`add_fp_unittest`.
- Update the remaining dependency.
- Update bazel overlay: add `libc:hdr_math_macros` target, and replacing
all dependency on `libc:llvm_libc_macros_math_macros` with
`libc:hdr_math_macros`.
2024-04-05 18:21:16 -04:00
aniplcc
8ee6ab7f69 [libc][c23][fenv] implement fesetexcept (#87603)
Closes #87564
2024-04-05 13:52:57 -07:00
Vinayak Dev
3b961d113e [libc] Implement roundeven C23 math functions (#87678)
Implements the functions `roundeven()`, `roundevenf()`, `roundevenl()`
from the roundeven family of functions introduced in C23. Also
implements `roundevenf128()`.
2024-04-05 08:36:12 -04:00
OverMighty
a8c59750d9 [libc][math][c23] Add exp2m1f C23 math function (#86996)
Fixes #86502.

cc @lntue
2024-04-04 08:22:45 -04:00
Guillaume Chatelet
71c3f5d617 [reland][libc] Refactor BigInt (#87613)
This is a reland of #86137 with a fix for platforms / compiler that do
not support trivially constructible int128 types.
2024-04-04 11:41:27 +02:00
Guillaume Chatelet
12735916bd Revert "[libc] Refactor BigInt" (#87612)
Reverts llvm/llvm-project#86137

Some aarch64 compilers seem to consider that `uint128_t` is not
`is_trivially_constructible` which prevents `bit_cast`-ing.
2024-04-04 11:10:30 +02:00
Guillaume Chatelet
a2306b65d2 [libc] Refactor BigInt (#86137)
This patch moves most of the multiprecision logic to the `multiword`
namespace and simplifies some logic in `BigInt`. It also fully
implements the mask and count functions and increases test coverage.

`math_extras.h` is also reworked to make it more concise.
2024-04-04 10:27:08 +02:00
Joseph Huber
7327014b49 [libc] Implement temporary printf on the GPU (#85331)
Summary:
This patch adds a temporary implementation that uses a struct-based
interface in lieu of varargs support. Once varargs support exists we
will move this implementation to the "real" printf implementation.

Conceptually, this patch has the client copy over its format string and
arguments to the server. The server will then scan the format string
searching for any specifiers that are actually a string. If it is a
string then we will send the pointer back to the server to tell it to
copy it back. This copied value will then replace the pointer when the
final formatting is done.

This will require a built-in extension to the varargs support to get
access to the underlying struct. The varargs used on the GPU will simply
be a struct wrapped in a varargs ABI.
2024-04-02 16:25:18 -05:00
aniplcc
82be6e186b [libc][posix] implement _exit (#87185)
Fixes  #87126.
2024-04-02 10:37:42 -07:00
Nick Desaulniers
70e189fbc9 [libc] fixup ftello test (#87282)
Use a seek offset that fits within the file size.

This was missed in presubmit because the FILE based stdio tests aren't
run in
overlay mode; fullbuild is not tested in presubmit.

WRITE_SIZE == 11, so using a value of 42 for offseto would cause the
expression
`WRITE_SIZE - offseto` to evaluate to -31 as an unsigned 64b integer
(18446744073709551585ULL).

Fixes #86928
2024-04-01 14:13:56 -07:00
lntue
2be722587f [libc][math] Implement atan2f correctly rounded to all rounding modes. (#86716)
We compute atan2f(y, x) in 2 stages:
- Fast step: perform computations in double precision , with relative
errors < 2^-50
- Accurate step: if the result from the Fast step fails Ziv's rounding
test, then we perform computations in double-double precision, with
relative errors < 2^-100.

On Ryzen 5900X, worst-case latency is ~ 200 clocks, compared to average
latency ~ 60 clocks, and average reciprocal throughput ~ 20 clocks.
2024-04-01 13:31:07 -04:00
Shourya Goel
55b74030a4 [libc][POSIX] implement fseeko, ftello (#86928)
Fixes: #85287
2024-04-01 10:09:28 -07:00
Shourya Goel
bbb8a6c836 [libc][math][c23] Fix impl and tests for X86_80 canonicalize function. (#87103)
In continuation to: #87097
2024-03-29 17:03:35 -04:00
Michael Jones
838b118d39 [libc] Fix missing UINTMAX_WIDTH (#87092)
In patch #82461 the sprintf tests were made to use UINTMAX_WIDTH which
isn't defined on all systems. This patch changes it to
sizeof(uintmax_t)*CHAR_BIT which is more portable.
2024-03-29 10:32:33 -07:00
Om Prakaash
fdef5c4f45 Add bit width length modifier to printf (#82461)
Resolves #81685. This adds support for wN and wfN length modifiers in
fprintf.
2024-03-29 10:15:22 -07:00
Vinayak Dev
6373577a2c [libc] Add inf/nan tests for strfrom*() functions (#86663)
Adds tests for `inf` and `nan` values to the tests for `strfrom*()`
functions.

Also marks some variables as `[[maybe_unused]]` to silence unused
variable warnings.
2024-03-28 15:18:28 -07:00
Nick Desaulniers
d357324f77 Revert "[libc][math][c23] Fix X86_Binary80 special cases for canonicalize functions. (#86924)"
This reverts commit 7c1c07c920.

Fails in presubmit.

Link: https://lab.llvm.org/buildbot/#/builders/90/builds/67461
Link: https://lab.llvm.org/buildbot/#/builders/225/builds/33519
Link: https://lab.llvm.org/buildbot/#/builders/163/builds/53858
Link: https://lab.llvm.org/buildbot/#/builders/250/builds/20983
Link: #86924
2024-03-28 14:33:23 -07:00
Shourya Goel
7c1c07c920 [libc][math][c23] Fix X86_Binary80 special cases for canonicalize functions. (#86924)
Updates the special case of pseudo infinty as pointed in #85940
2024-03-28 16:36:49 -04:00
OverMighty
6aee1f9d18 [libc][math][c23] Fix bounds checking and add FE_INVALID raising in {,u}fromfp{,x}* (#86892)
See
https://github.com/llvm/llvm-project/pull/86692#issuecomment-2024044889
and
https://github.com/llvm/llvm-project/pull/86892#discussion_r1542276037.

cc @lntue @nickdesaulniers
2024-03-28 13:08:14 -04:00
Nick Desaulniers
ad97ee2531 [libc][support][FixedVector] add reverse iterator (#86732)
Critically, we don't want to return an iterator to the end of the underlying
cpp::array "store." Add a test to catch this issue.

This will be used by __cxa_finalize to iterate backwards through a FixedVector.

Link: #85651
2024-03-28 09:53:44 -07:00
Nick Desaulniers
51f7b26242 [libc][support][UInt] implement 128b math helpers (#86531)
Flush out the remaining UInt<128> support and add test coverage.

We could have used cpp::popcount in the implementation of
UInt::has_single_bit, but
has_single_bit has a perhaps useful early return.
2024-03-27 08:22:51 -07:00
Vinayak Dev
a3f21a3249 [libc] Remove LIBC_HAS_ATTRIBUTE macro (#86656)
Resolves #86547

Replace occurrences of the macro `LIBC_HAS_ATTRIBUTE` with `__has_attribute`.
2024-03-26 13:22:14 -07:00
Michael Jones
4c72cfa317 [libc] Remove definition of LIBC_NAMESPACE in test (#86704)
The canonicalize test added in #85940 defined the LIBC_NAMESPACE macro.
this macro is intended to be set only by the build system and never in
the code.
2024-03-26 12:51:40 -07:00
Shourya Goel
19ca79e867 [libc][math][c23] Implement canonicalize functions (#85940)
Fixes: #85286
2024-03-26 08:28:22 -04:00
Job Henandez Lara
3e3f0c3175 [libc][math][c23] add c23 floating point fmaximum and fminimum functions. (#86016)
Fixes https://github.com/llvm/llvm-project/issues/85496.

---------

Co-authored-by: Job Hernandez <h93@protonmail.com>
2024-03-25 15:19:10 -04:00
Schrodinger ZHU Yifan
05dc5d927b [libc] add statvfs/fstatvfs (#86169)
fixes #86449
2024-03-25 13:37:50 -04:00
OverMighty
b282259711 [libc][math][c23] Add {,u}fromfp{,x}{,f,l,f128} functions (#86003)
Fixes #85279.

cc @lntue
2024-03-25 10:26:22 -04:00
Vinayak Dev
83e96977cd [libc] Implement strfromd() and strfroml() (#86113)
Follow up to #85438.

Implements the functions `strfromd()` and `strfroml()` introduced in
C23, and unifies the testing framework for `strfrom*()` functions.
2024-03-22 11:39:53 -07:00
Nick Desaulniers
6eff53b4f0 [libc][stdio] implement rename via SYS_renameat2 (#86140)
SYS_rename may be unavailable on architectures such as aarch64 and
riscv.
rename can be implemented in terms of SYS_rename, SYS_renameat, or
SYS_renameat2. I don't have a full picture of the history here, but it
seems
that SYS_renameat might also be unavailable on some platforms.

`man 2 rename` mentions that SYS_renameat2 was added in Linux 3.15. We
don't
need to support such ancient kernel versions prior.

Link: #84980
Link: #85068
2024-03-21 09:35:18 -07:00
Nick Desaulniers
0c8dfc85c3 [libc][stdio][test] fixup rename test (#86136)
Link: #84980
Link: #85068
2024-03-21 08:36:47 -07:00
aniplcc
c04807c84e [libc][c11] Add stdio.h's rename() function (#85068)
Adds stdio.h's rename() function as defined in n3096. Fixes  #84980.
2024-03-21 08:21:06 -07:00
Vinayak Dev
5ea152033e [libc]: Implement strfromf() and shared utilities (#85438)
Fixes #84244.

Implements the function `strfromf()` introduced in C23, and adds shared
utilities for implementation of other `strfrom*()` functions, including
`strfromd()` and `strfroml()`.
2024-03-20 10:47:35 -07:00
Job Henandez Lara
b754e6f690 Fix typo (#85869) 2024-03-20 10:13:45 -07:00
Guillaume Chatelet
2137894a6f [libc][NFC] Move Sign type to separate header (#85930) 2024-03-20 15:10:19 +01:00
Joseph Huber
3dc1b5044e [libc] Make 'printf' converter output "(null)" instead of "null" (#85845)
Summary:
Currently we print `null` for the null pointer in a `%s` expression.
Although it's not defined by the standard, other implementations choose
to use `(null)` to indicate this. We also currently print `(nullptr)` so
I think it's more consistent to use parens in both cases.
2024-03-19 14:44:59 -05:00
Nick Desaulniers
c63a291c64 [libc][cpp] reverse_iterator support (#85702)
Towards the goal of implementing __cxa_finalize (#85651) I'd like to be able to
reverse iterate over cpp::arrays such as the one used in FixedVector.

Implement the enough iterator support to be able to iterate a cpp::array in
reverse, and add tests.

Of note, reverse iterator's begin() refers to forward iterator's end() (and
vice versa). When dereferenced (operator*), the reverse iterator returns a copy
that's been pre-decremented (the underlying forward iterator is advanced).
2024-03-19 09:25:57 -07:00
lntue
a629621454 [libc][math] Improve atanf performance. (#85463)
Simplify the range reduction logic and computations. Performance test
using `perf.sh` from CORE-MATH project on Ryzen 5900X:

Before:
```
$ ./perf.sh atanf --rdtsc --path1
LIBC-location: /home/lnt/experiment/llvm-project/build/projects/libc/lib/libllvmlibc.a
GNU libc version: 2.35
GNU libc release: stable
-- CORE-MATH reciprocal throughput --
[####################] 100 %
Ntrial = 20 ; Min = 14.369 + 0.556 clc/call; Median-Min = 0.613 clc/call; Max = 15.061 clc/call;
-- System LIBC reciprocal throughput --
[####################] 100 %
Ntrial = 20 ; Min = 26.180 + 0.015 clc/call; Median-Min = 0.014 clc/call; Max = 26.260 clc/call;
-- LIBC reciprocal throughput --
[####################] 100 %
Ntrial = 20 ; Min = 21.237 + 0.022 clc/call; Median-Min = 0.020 clc/call; Max = 21.272 clc/call;

$ ./perf.sh atanf --rdtsc --path1 --latency
LIBC-location: /home/lnt/experiment/llvm-project/build/projects/libc/lib/libllvmlibc.a
GNU libc version: 2.35
GNU libc release: stable
-- CORE-MATH latency --
[####################] 100 %
Ntrial = 20 ; Min = 50.505 + 0.045 clc/call; Median-Min = 0.037 clc/call; Max = 50.579 clc/call;
-- System LIBC latency --
[####################] 100 %
Ntrial = 20 ; Min = 62.438 + 0.836 clc/call; Median-Min = 0.049 clc/call; Max = 64.498 clc/call;
-- LIBC latency --
[####################] 100 %
Ntrial = 20 ; Min = 67.781 + 0.546 clc/call; Median-Min = 0.028 clc/call; Max = 68.844 clc/call;
```

After:
```
$ ./perf.sh atanf --rdtsc --path2
LIBC-location: /home/lnt/experiment/llvm/llvm-project/build/projects/libc/lib/libllvmlibc.a
GNU libc version: 2.35
GNU libc release: stable
-- CORE-MATH reciprocal throughput --
[####################] 100 %
Ntrial = 20 ; Min = 14.400 + 0.353 clc/call; Median-Min = 0.404 clc/call; Max = 14.863 clc/call;
-- System LIBC reciprocal throughput --
[####################] 100 %
Ntrial = 20 ; Min = 25.247 + 0.783 clc/call; Median-Min = 0.714 clc/call; Max = 26.238 clc/call;
-- LIBC reciprocal throughput --
[####################] 100 %
Ntrial = 20 ; Min = 13.751 + 0.158 clc/call; Median-Min = 0.140 clc/call; Max = 14.006 clc/call;

$ ./perf.sh atanf --rdtsc --path2 --latency
LIBC-location: /home/lnt/experiment/llvm/llvm-project/build/projects/libc/lib/libllvmlibc.a
GNU libc version: 2.35
GNU libc release: stable
-- CORE-MATH latency --
[####################] 100 %
Ntrial = 20 ; Min = 51.837 + 0.073 clc/call; Median-Min = 0.058 clc/call; Max = 52.000 clc/call;
-- System LIBC latency --
[####################] 100 %
Ntrial = 20 ; Min = 62.487 + 1.878 clc/call; Median-Min = 1.965 clc/call; Max = 64.569 clc/call;
OK
-- LIBC latency --
[####################] 100 %
Ntrial = 20 ; Min = 55.414 + 1.312 clc/call; Median-Min = 0.345 clc/call; Max = 58.362 clc/call;
```
2024-03-18 21:10:50 -04:00
Michael Jones
5d56b34807 [libc] Remove direct math.h includes (#85324)
Reland of #84991

A downstream overlay mode user ran into issues with the isnan macro not
working in our sources with a specific libc configuration. This patch
replaces the last direct includes of math.h with our internal
math_macros.h, along with the necessary build system changes.
2024-03-18 14:19:33 -07:00
Nick Desaulniers
27d7bb8616 [libc] fix up fileno tests (#85660)
Fixes #85628
2024-03-18 13:35:44 -04:00
Shourya Goel
ca04b56a8b [libc] Implement fileno (#85628)
fixes: #85150
2024-03-18 09:26:30 -07:00