395 Commits

Author SHA1 Message Date
lntue
c342d11375
[libc][doc] Add links to slides and video from Siva's CppNow 2023 talk. (#116038) 2024-11-13 11:35:45 -05:00
Duncan
396ed9c2a1
[libc][search] implement posix lfind function (#114692)
# Changes
- Implement the POSIX
[`lfind`](https://man7.org/linux/man-pages/man3/lsearch.3.html)
function.

- Put a checkmark in the [posix support table
docs](https://libc.llvm.org/libc_search.html) next to `lfind`.
2024-11-11 09:53:20 -08:00
wldfngrs
f7bb12901e
[libc][math][c23] Add tanpif16 function (#115183)
- Implementation of `tan` for 16-bit floating point inputs scaled by pi.
i.e,. `tanpif16()`
- Implementation of Tanpi in MPFRWrapper for MPFR versions < 4.2
- Exhaustive tests for `tanpif16()`
2024-11-08 09:56:31 -05:00
OverMighty
faefedf7f8
[libc][math][c23] Add exp10m1f C23 math function (#87992)
Fixes #86503.
2024-11-07 23:56:00 +01:00
Shourya Goel
ffe04e0351
[libc][complex] implement different flavors of creal and cimag functions (#113300)
I have commented out the test for `neg_zero`(creal) because : 

1. real(neg_zero + 0.0i) equals zero. 
2. real(neg_zero - 0.0i) equals neg_zero.

I am not sure if this is the intended behaviour. 

[EDIT]
I have updated tests for `neg_zero` (creal) to be : 

```
    EXPECT_FP_EQ(func(CFPT(neg_zero - zero * 1.0i)), neg_zero);
    EXPECT_FP_EQ(func(CFPT(neg_zero + zero * 1.0i)), zero);
```

because all three [gcc, clang and GNU MPC] also give the same result. 
https://godbolt.org/z/hxhcn6aof
and it seems that it is indeed the correct behaviour since Imaginary
types are not supported yet, refer #113671
2024-11-03 09:38:09 +05:30
c8ef
b57b3f6425
[NFC] Simple typo correction. (#114548) 2024-11-02 00:40:57 +08:00
wldfngrs
7395ef5419
[libc][math][c23] Add cospif16 function (#113001)
Implementation of `cos` for half precision floating point inputs scaled
by pi (i.e., `cospi`), correctly rounded for all rounding modes.

---------

Co-authored-by: OverMighty <its.overmighty@gmail.com>
2024-10-29 03:39:57 -07:00
OverMighty
d97f6d1ae9
[libc][math][c23] Add sqrtf16 C23 math function (#112406)
Part of #95250.
2024-10-19 01:41:52 +02:00
OverMighty
69d3a44ede
[libc][math][c23] Add log10f16 C23 math function (#106091)
Part of #95250.
2024-10-19 01:40:40 +02:00
OverMighty
6d347fdfbd
[libc][math][c23] Add log2f16 C23 math function (#106084)
Part of #95250.
2024-10-19 01:10:32 +02:00
OverMighty
65cf7afb6d
[libc][math][c23] Add logf16 C23 math function (#106072)
Part of #95250.
2024-10-18 22:35:12 +02:00
Joseph Huber
00d30bd61e [libc] Commit document formatting change someone left 2024-10-18 10:09:28 -05:00
lntue
b0dbd2ca5b
[libc][math] Add option to set a specific exponent for frexp with Inf/NaN inputs. (#112387)
In IEEE 754 and C standards, when calling `frexp` with Inf/Nan inputs,
the exponent result is unspecified. In this case, FreeBSD libc and musl
just passthrough `exp`, while glibc, FreeBSD libm set exp = 0, and MSVC
set exp = -1.

By default, LLVM libc will passthrough `exp` just as FreeBSD libc and
musl, but we also allow users to explicitly choose the return exp value
in this case for compatibility with other libc.

Notice that, gcc did generate passthrough `exp` for `frexp(NaN/Inf,
exp)`: https://godbolt.org/z/sM8fEej4E
2024-10-18 09:58:15 -04:00
OverMighty
fdd7c0353f
[libc][math][c23] Add tanhf16 C23 math function (#106006)
Part of #95250.
2024-10-18 14:22:45 +02:00
OverMighty
ed3d051782
[libc][math][c23] Add sinhf16 and coshf16 C23 math functions (#105947)
Part of #95250.
2024-10-17 20:44:23 +02:00
OverMighty
95c24cb9de
[libc][math][c23] Add exp10m1f16 C23 math function (#105706)
Part of #95250.
2024-10-16 16:33:13 +02:00
wldfngrs
ddc3f2dd26
[libc] Add sinpif16 function (#110994)
Half-precision floating point (16-bit) implementation of the
trigonometric function Sin for inputs scaled by pi
2024-10-15 18:40:08 -04:00
Shourya Goel
f4ba6a654d
[libc][complex] Set up headers and add documentation for complex.h. (#111659)
Refer: 7.3.1 from [ISO
SPEC](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3220.pdf)

I have added complex variants of F16 and F128 in libc doc but have
omitted support for them since we will have to first investigate how
their support matrix for clang and gcc looks like, and then add header
guards for them accordingly. Planning to add them in follow up PRs once
this gets landed.
2024-10-14 13:35:04 -04:00
OverMighty
ce65d4e974
[libc][math][c23] Add exp2m1f16 C23 math function (#105690)
Part of #95250.
2024-10-12 19:31:12 +02:00
Joseph Huber
50838851e8 [libc][docs] Update NVPTX using documentation now that linking works
Summary:
I added a wrapper linker awhile back but this still says it doesn't
work.
2024-10-04 18:09:28 -05:00
Michael Jones
e1d64b7662
[libc] Enable dyadic float for float printf (#110765)
Dyadic floats were an existing option for float to string conversion,
but it had become stale. This patch fixes it up as well as adding proper
config options and test support. Due to the test changes this is a
followup to #110759
2024-10-02 09:42:34 -07:00
Shourya Goel
2d784b1946
[libc][math] Implement iscanonical[f|l] as a libc math function (#110565)
This PR implements the iscanonical function as part of the libc math
library.

The addition of this function is crucial for completing the
implementation of remaining math macros, as referenced in #109201
2024-10-02 10:14:04 -04:00
Shourya Goel
47e3d8dc7e
[libc][math] Implement issignaling[f|l] as a libc math function (#110556)
This PR implements the issignaling function as part of the libc math
library, addressing the TODO items mentioned in #110011

The addition of this function is crucial for completing the
implementation of remaining math macros, as referenced in #109201
2024-10-01 13:49:28 -04:00
Joseph Huber
fe6a3d46aa
[libc] Implement the 'rename' function on the GPU (#109814)
Summary:
Straightforward implementation like the other `stdio.h` functions.
2024-09-24 09:32:42 -07:00
Joseph Huber
3bbe0f90f3
[libc] Add 'strings.h' header on the GPU (#109661)
Summary:
These are GNU extensions but still show up, the entrypoints were enabled
but we weren't emitting the header so they couldn't be used.
2024-09-23 14:19:33 -07:00
Joseph Huber
16d11e26f3
[libc] Add GPU support for the 'system' function (#109687)
Summary:
This function can easily be implemented by forwarding it to the host
process. This shows up in a few places that we might want to test the
GPU so it should be provided. Also, I find the idea of the GPU
offloading work to the CPU via `system` very funny.
2024-09-23 14:04:28 -07:00
Michael Jones
f009f72df5
[libc] Add printf strerror conversion (%m) (#105891)
This patch adds the %m conversion to printf, which prints the
strerror(errno). Explanation of why is below, this patch also updates
the docs, tests, and build system to accomodate this.

The standard for syslog in posix specifies it uses the same format as
printf, but adds %m which prints the error message string for the
current value of errno. For ease of implementation, it's standard
practice for libc implementers to just add %m to printf instead of
creating a separate parser for syslog.
2024-09-19 10:48:08 -07:00
Зишан Мирза
b9e13045ab
[libc] add ctime and ctime_r to date_and_time documentation (#108665)
closes #108664
2024-09-17 09:50:07 -07:00
lntue
1896ee3889
[libc] Fix undefined behavior for nan functions. (#106468)
Currently the nan* functions use nullptr dereferencing to crash with
SIGSEGV if the input is nullptr. Both `nan(nullptr)` and `nullptr`
dereferencing are undefined behaviors according to the C standard.
Employing `nullptr` dereference in the `nan` function implementation is
ok if users only linked against the pre-built library, but it might be
completely removed by the compilers' optimizations if it is built from
source together with the users' code.

See for instance:  https://godbolt.org/z/fd8KcM9bx

This PR uses volatile load to prevent the undefined behavior if libc is
built without sanitizers, and leave the current undefined behavior if
libc is built with sanitizers, so that the undefined behavior can be
caught for users' codes.
2024-09-11 14:13:31 -04:00
Joseph Huber
6b98a72365
[libc] Add scanf support to the GPU build (#104812)
Summary:
The `scanf` function has a "system file" configuration, which is pretty
much what the GPU implementation does at this point. So we should be
able to use it in much the same way.
2024-08-21 18:02:04 -05:00
Michael Jones
b89fef8f67
[libc][docs] Update docs to reflect new headergen (#102381)
Since new headergen is now the default for building LLVM-libc, the docs
need to be updated to reflect that. While I was editing those docs, I
took a quick pass at updating other out-of-date pages.
2024-08-21 10:50:39 -07:00
OverMighty
560ed8ce3d
[libc][math][c23] Add expm1f16 C23 math function (#102387)
Part of #95250.
2024-08-13 16:48:28 +02:00
aaryanshukla
b6cbd014b9
[libc][newhdrgen]sorted function names in yaml (#102544) 2024-08-09 11:27:36 -07:00
Job Henandez Lara
ff1cc5b97c
[libc][math][c23] Add totalorderl function. (#102564) 2024-08-09 10:18:00 -04:00
aaryanshukla
d0fe470fd2
[libc][math] Add scalbln{,f,l,f128} math functions (#102219)
Co-authored-by: OverMighty <its.overmighty@gmail.com>
2024-08-08 14:33:50 -07:00
lntue
eddfd504f8
[libc][math][c23] Add ddivl C23 math function. (#102468) 2024-08-08 11:41:17 -04:00
Simon Tatham
722c066c59
[libc] Make use of 32-bit time_t a config option (#102012)
The 32-bit Arm builds of libc define time_t to be `__INTPTR_TYPE__`,
i.e. a 32-bit integer. This is commented in the commit introducing it
(75398f28ebdb600) as being for compatibility with glibc. But in the near
future not even every AArch32 build of glibc will have a 32-bit time_t:
Debian is planning that their next release (trixie) will have switched
to 64-bit. And non-Linux builds of this libc (e.g. baremetal) have no
reason to need glibc compatibility in the first place – and every reason
_not_ to want to start using a 32-bit time_t in 2024 or later.

So I've replaced the `#ifdef` in `llvm-libc-types/time_t.h` with two
versions of the header file, chosen in `CMakeLists.txt` via a new
configuration option. This involved adding an extra parameter to the
cmake `add_header` function to specify different names for the header
file in the source and destination directories.
2024-08-08 16:36:05 +01:00
Job Henandez Lara
aae7c38827
[libc][math][c23] Add entrypoints and tests for setpayloadsig{,f,l,f128} and setpayloadl. (#102413) 2024-08-08 00:17:20 -04:00
aaryanshukla
2c74237c0f
[libc][math][c23] Add fsub{,l,f128} and remainderf128 C23 math functions (#101576)
Co-authored-by: OverMighty <its.overmighty@gmail.com>
2024-08-07 13:03:58 -07:00
OverMighty
59338ad8c5
[libc][math][c23] Add exp10f16 C23 math function (#101588)
Part of #95250.
2024-08-07 15:54:06 +02:00
Job Henandez Lara
e3778a5d0e
[libc][math] Add getpayloadl function. (#102214) 2024-08-07 08:27:45 -04:00
Schrodinger ZHU Yifan
03841e7ab8
[libc] add spin lock family functions (#100509)
This PR:
- add entrypoints for `pthread_spin_*`
- additionally, the fixes a typo that has been disabling lock related
tests
2024-08-06 21:02:54 -07:00
aaryanshukla
0395bf7636
[libc][math][c23] Add ffma{,l,f128} and fdiv{,l,f128} C23 math functions #101089 (#101253)
- added all variations of ffma and fdiv 
- will add all new headers into yaml  for next patch 
- only fsub is left then all basic operations for float is complete

---------

Co-authored-by: OverMighty <its.overmighty@gmail.com>
2024-08-06 10:19:54 -07:00
Sirui Mu
2f28378317
[libc] Fix builds on Windows (#102162)
This PR changes several places in the CMake scripts to make libc build
on Windows. It adds the `errno` entrypoint to the Windows target.

A mistake in the overlay build doc is also fixed.

Tests still cannot be built on Windows because of the lack of osutils.
2024-08-06 08:38:05 -07:00
OverMighty
936515c7a5
[libc][math][c23] Add exp2f16 C23 math function (#101217)
Part of #95250.
2024-08-06 14:44:01 +02:00
lntue
9f6b440adf
[libc][math] Implement fast pass for double precision pow function with up to 1ULP error. (#101926) 2024-08-05 13:08:59 -04:00
Michael Jones
a21fc4c0a6
[libc] Fix printf handling of INT_MIN width (#101729)
Prevously, if INT_MIN was passed as a wildcard width to a printf
conversion the parser would attempt to negate it to get the positive
width (and set the left justify flag), but it would underflow and the
width would be treated as 0. This patch corrects the issue by instead
treating a width of INT_MIN as identical to -INT_MAX.

Also includes docs changes to explain this behavior and adding b to the
list of int conversions.
2024-08-02 13:45:54 -07:00
aaryanshukla
8f33f1d829
[libc][math][c23] Add dadd{l,f128} and ddiv{l,f128} C23 math functions (#100456)
- fadd removed because I need to add for different input types
- finishing rest of basic operations
- noticed duplicates will remove

---------

Co-authored-by: OverMighty <its.overmighty@gmail.com>
2024-08-01 13:36:50 -07:00
Job Henandez Lara
ed12f80ff0
[libc][math][c23] add entrypoints and tests for getpayload{,f,f128} (#101285) 2024-07-31 23:16:42 -04:00
aaryanshukla
30b5d4a763
[libc][math][c23] Add dfma{l,f128} and dsub{l,f128} C23 math functions (#101089)
Co-authored-by: OverMighty <its.overmighty@gmail.com>
2024-07-31 13:07:03 -07:00