Commit Graph

258 Commits

Author SHA1 Message Date
Fabian Keßler
cd7a7a56fc Add basic char*_t support for libc (partial WG14 N2653) (#90360)
This PR implements a part of WG14 N2653:
 - Define C23 char8_t
 - Define C11 char16_t
 - Define C11 char32_t
 
 Missing goals are:
- The type of UTF-8 character literals is changed from unsigned char to
char8_t. (Since UTF-8 character literals already have type unsigned
char, this is not a semantic change).
- New mbrtoc8() and c8rtomb() functions declared in <uchar.h> enable
conversions between multibyte characters and UTF-8.
    - A new ATOMIC_CHAR8_T_LOCK_FREE macro.
    - A new atomic_char8_t typedef name.
2024-04-30 15:08:38 -07:00
Michael Flanders
5e9937d1b3 [libc][math] Adds entrypoint and tests for nearbyintf128,scalbnf128 (#88443)
Closes #84689.

Adding @lntue for review.

I was curious about the implementation of
`round_using_current_rounding_mode` used for the `nearbyint` functions.
It has one of the rounding modes as unreachable
([here](https://github.com/llvm/llvm-project/blob/main/libc/src/__support/FPUtil/NearestIntegerOperations.h#L243)),
and I was wondering if this was okay for the `nearbyint` functions.

---------

Co-authored-by: Michael Flanders <mkf727@cs.washington.edu>
2024-04-29 19:25:45 -04:00
Rajveer Singh Bharadwaj
3ae10fde39 [libc] Generate docs for setjmp.h (#89542)
Resolves #88065

Added macros and functions.
2024-04-23 11:28:09 -07:00
Nick Desaulniers
0336116ed4 [libc][docs] codify Policy on Assembler Sources (#88185)
It would be helpful in future code reviews to document a policy with
regards to
where and when Assembler sources are appropriate. That way when
reviewers point
out infractions, they can point to this written policy, which may help
contributors understand that it's not solely the personal preferences of
individual reviewers but instead rather a previously agreed upon rule by
maintainers.

Link: https://github.com/llvm/llvm-project/pull/87837
Link: https://github.com/llvm/llvm-project/pull/88157
Link:
https://discourse.llvm.org/t/hand-written-in-assembly-in-libc-setjmp-longjmp/73249/12
2024-04-22 11:57:28 -07:00
Nick Desaulniers
7aad1ee70f [libc][docs] link to good beginner bugs (#89297)
Tagging bugs as "good first issue" and taking the time to work with new
contributors pays dividends.
2024-04-18 13:38:00 -07:00
Michael Flanders
bd0f818d63 [libc][docs] adds threads.h impl status docs (#89275)
Closes #88067.

Adding @nickdesaulniers for review.
2024-04-18 12:26:41 -07:00
Michael Flanders
2a2e21cd2b [libc][docs] adds highlighting languages to docs/dev/config_options.rst (#89136)
Fixes #89135.
2024-04-18 12:26:14 -07:00
Robin Caloudis
b854a23233 [libc][c23][fenv] Implement fetestexceptflag (#87828)
Provide C23 `fetestexceptflag` function according to 7.6.4.6 in the
latest [revision of the C
standard](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3096.pdf)
from 2023-04-02.

Closes https://github.com/llvm/llvm-project/issues/87565.
2024-04-17 08:38:47 -07:00
Michael Flanders
2996cb7970 [libc][docs] use docgen to generate stdbit rst docs (#88540)
Closes #88066.

Compared to before, the function names in the stdbit table are sorted by
function name, not order-of-appearance in the standard. Since macros
aren't printed by docgen.py and are still a TODO in the code, they are
also not printed in the new stdbit.h docs.

Adds some checks to docgen.py for conditions that tripped me up.

Add code to docgen.py to add the include of the `|check|` rewriter,
since all other generated files need it.
2024-04-12 14:35:10 -07:00
Nick Desaulniers
f626a35086 [libc] Codify header inclusion policy (#87017)
When supporting "overlay" vs "fullbuild" modes, "what ABI are you
using?" becomes a fundamental question to have concrete answers for.
Overlay mode MUST match the ABI of the system being overlayed onto;
fullbuild more flexible (the only system ABI relevant is the OS kernel).

When implementing llvm-libc we generally prefer the include-what-you use
style of avoiding transitive dependencies (since that makes refactoring
headers more painful, and slows down build times). So what header do you
include for any given type or function declaration? For any given
userspace program, the answer is straightforward. But for llvm-libc
which is trying to support multiple ABIs (at least one per
configuration), the answer is perhaps less clear.

This proposal seeks to add one layer of indirection relative to what's
being done today.

It then converts users of sigset_t and struct epoll_event and the epoll
implemenations over to this convention as an example.
2024-04-11 10:11:58 -07:00
Xu Zhang
7ab7e7a55f [libc][docs] Generate docs for signal.h & optimized is_implemented func (#88028)
Fixes #87835

This patch added the documentation for the POSIX functions according to
[n3096](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3096.pdf)
Section 7.14, and gives the *docgen.py* script a more elegant *is_implemented*
function.
2024-04-11 08:49:59 -07:00
Joseph Huber
fad14707b7 [libc] Add note to use LIBC_GPU_BUILD=ON as another form
Summary:
This is a shorthand to enable GPU support so it should be listed in the
docs.
2024-04-10 14:07:57 -05:00
Nick Desaulniers
e127997155 [libc][docs] fix missing include
Fixes #87946
2024-04-08 15:58:36 -07:00
Zander Dumont-Strom
279c758b5d [libc][docs] generate docs for ctype.h (#87946)
Fixes #87833
2024-04-08 15:51:31 -07:00
Nick Desaulniers
af34a5d382 [libc][docs] Introduce docgen (#87682)
This script+config should help us generate more consistent documentation wrt.
what we currently support or not.

As an example usage:

    $ ./libc/utils/docgen/docgen.py fenv.h

Will spit out an RST formatted table that can be copy+pasted into our docs.

The config is not filled out entirely, but doing so and then updating our docs
would be great beginner bugs for new contributors.

Having python+json generate things like docs, or headers (as imagined in
https://github.com/nickdesaulniers/llvm-project/tree/hdr-gen2) is perhaps
easier to work with than tablegen, and doesn't introduce a dependency on a host
tool that needs to be compiled from llvm sources before building the rest of
the libc. This can probably be merged with whatever we end up doing to replace
libc-hdrgen.

Please use

https://llvm.org/docs/CodingStandards.html#python-version-and-source-code-formatting
for keeping this file formatted.
2024-04-05 14:50:45 -07: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
Vinayak Dev
986435c765 [libc] Move {f,d}sqrt to higher functions in docs (#87445)
Moves the functions `fsqrt()` and `dsqrt()` from basic functions to
higher math functions in math docs
2024-04-02 22:39:48 -04:00
Vinayak Dev
2fb5440e76 [libc] Re-organize the math function tables in docs (#87412)
Re-organizes the tables that listed libc's support for math functions,
and adds two new columns to the tables indicating where the respective
function definitions and error handling methods are located in the C23
standard draft WG14-N3096.
2024-04-02 22:23:35 -04: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
Schrodinger ZHU Yifan
a8b0ecd260 [libc] enable stack protectors and frame pointers on default (#86288) 2024-03-29 20:17:11 -04:00
Joseph Huber
99379522d0 [libc][Docs] Update RPC server example using CUDA after changes
Summary:
This has changed, so update it to match the new interface.
2024-03-29 13:13:20 -05: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
Nick Desaulniers
8a071678a9 Revert "[libc][math][c23] Add remaining linux/* entrypoints for {,u}fromfp{,x}* (#86692)"
This reverts commit cd17082b24 because the newly
added tests fail on 32b ARM.

Link: #86692
Link: https://lab.llvm.org/buildbot/#/builders/229/builds/24458
2024-03-27 13:28:26 -07:00
OverMighty
cd17082b24 [libc][math][c23] Add remaining linux/* entrypoints for {,u}fromfp{,x}* (#86692) 2024-03-27 12:28:27 -07:00
Marc Auberer
77118536b5 [libc] Remove obsolete LIBC_HAS_BUILTIN macro (#86554)
Fixes #86546 and removes the macro `LIBC_HAS_BUILTIN`. This was
necessary to support older compilers that did not support
`__has_builtin`. All of the compilers we support already have this
builtin.
See: https://libc.llvm.org/compiler_support.html
All uses now use `__has_builtin` directly

cc @nickdesaulniers
2024-03-27 17:22:41 +01:00
Shourya Goel
19ca79e867 [libc][math][c23] Implement canonicalize functions (#85940)
Fixes: #85286
2024-03-26 08:28:22 -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
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
OverMighty
85b6af198f [libc][math][c23] Add linux/* entrypoints for nextup* and nextdown* (#85803)
See
https://github.com/llvm/llvm-project/pull/85484#discussion_r1526971653.

There already were entrypoints for linux/x86_64. I haven't tested on the other
targets and will rely on the buildbots.
2024-03-19 12:47:01 -07: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
Schrodinger ZHU Yifan
f6f42af06f [libc] Add shm_open/shm_unlink (#84974) 2024-03-18 11:40:07 -04:00
OverMighty
a2bad75879 [libc][math][c23] Add nextupl and nextdownl functions (#85484)
Fixes #85283.

cc @lntue
2024-03-16 17:21:07 -04:00
Joseph Huber
6818c7b8ef [libc] Update GPU testing documentation (#85459)
Summary:
This documentation was lagging reality and didn't contain much. Update
it with some more information now that it's more mature.
2024-03-15 17:49:44 -05:00
Michael Flanders
b43965adac [libc][math][c23] adds nanf128 (#85201)
Continuing #84689, this one required more changes than the others, so I
am making it a separate PR.

Extends some stuff in `str_to_float.h`, `str_to_integer.h` to work on
types wider than `unsigned long long` and `uint64_t`.

cc @lntue for review.
2024-03-15 13:31:50 -04:00
FantasqueX
a4ca07f13b [libc] Fix typo in libc fullbuild mode doc (#85204)
"In order to" is more appropriate.
2024-03-15 11:48:09 -04:00
Nick Desaulniers
5facb406e6 [libc][docs] document gpu support for stdbit.h (#85103)
Via:
https://github.com/llvm/llvm-project/pull/84938#issuecomment-1992120095

---------

Co-authored-by: Joseph Huber <huberjn@outlook.com>
2024-03-13 09:26:36 -07:00
Michael Flanders
15a55486a5 [libc][math] Adds entrypoint and test for nextafterf128 (#84882) 2024-03-12 23:25:05 -04:00
Nick Desaulniers
f0c0ddae45 [libc] implement the final macros for stdbit.h support (#84798)
Relevant sections of n3096:
- 7.18.1p1
- 7.18.2
2024-03-12 08:39:17 -07:00
lntue
4d21e75210 [libc][math][c23] Add fmodl and fmodf128 math functions. (#84600)
- Allow `FMod` template to have different computational types and make
it work for 80-bit long double.
- Switch to use `uint64_t` as the intermediate computational types for
`float`, significantly reduce the latency of `fmodf` when the exponent
difference is large.
2024-03-11 16:27:42 -04:00
lntue
d99bb01422 [libc][NFC] Clean up test/src/math/differential_testing folder, renaming it to performance_testing. (#84646)
Removing all the diff tests.
2024-03-11 11:38:39 -04:00
Michael Flanders
75b0d384fb [libc][stdbit][c23] adds implementation of stdc_bit_ceil functions (#84657)
Closes #84652.

Based on #84233.
2024-03-10 12:53:28 -04:00
lntue
99f5e9634b [libc][math][c23] Add modff128 C23 math function. (#84532) 2024-03-09 11:47:22 -05:00
lntue
60d7bf3dbe [libc][math][c23] Add (l|ll)rintf128 and (l|ll)roundf128 math functions. (#84504) 2024-03-08 12:15:02 -05:00
Nick Desaulniers
37f3661f4e [libc][docs] add slides link for Tue's 2023 talk (#84516) 2024-03-08 08:50:41 -08:00
Nick Desaulniers
3712edbdbb [libc] finish documenting c23 additions (#84383)
- [libc] finish documenting c23 additions
- sort according to appearance in Annex B and section 7
2024-03-07 15:37:45 -08:00
Nick Desaulniers
1c01651bda [libc][docs] add page linking to talks (#84393) 2024-03-07 15:09:17 -08:00
lntue
14171b87a3 [libc][stdfix] Add exp function for short _Accum and _Accum types. (#84391) 2024-03-07 17:58:28 -05:00
Nick Desaulniers
101a13df71 [libc][stdbit] implement stdc_bit_floor (C23) (#84233) 2024-03-07 08:38:04 -08:00