Commit Graph

3643 Commits

Author SHA1 Message Date
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
Job Henandez Lara
e873b415a2 [libc] add the rest of the hdr/fcntl_macro.h headers (#113972) 2024-10-28 18:32:45 -04:00
Job Henandez Lara
7b663bd917 [libc] Fix the remaining fcntl.h proxy header includes. (#113961) 2024-10-28 17:49:36 -04:00
Joseph Huber
03dcefe08e [libc] Fix leftover LIBC_NAMESPACE after porting it (#113960)
Summary:
There are a few of these leftover, they should all use the
`LIBC_NAMESPACE_DECL` version because that implies visibility.
2024-10-28 13:47:31 -07:00
Job Henandez Lara
abc49cc194 [libc] remove #include <fcntl.h> and add proxy or type (#113836) 2024-10-28 13:29:16 -07:00
goldsteinn
45c84d59c4 [libc] Add __builtin_expect tag on assert conditions; NFC (#99498) 2024-10-27 08:49:20 -05:00
lntue
0f4b3c409f [libc][math] Add tests and fix some issues with FTZ/DAZ modes. (#113744) 2024-10-26 10:55:20 -04:00
lntue
a879073494 [libc][math] Fix a bug in cbrt when the result is rounded to the next exponent. (#113749) 2024-10-25 22:11:07 -04:00
Roland McGrath
2e6d451d15 [libc] Use idiomatic main() function in newhdrgen/yaml_to_classes.py (#113419)
This changes the entry-point Python script of newhdrgen to use
the idiomatic main() function of no arguments that does the whole
job of the script.  This replaces the unusual pattern of having
an idiosyncratic main(...) signature and having the script's
direct code do argument parsing outside the main function.  The
idiomatic pattern makes it possible to usefully wrap the script
in Python and still use its full command-line functionality.
2024-10-24 22:17:57 -07:00
Simon Tatham
c7aff2ab4c [libc] Pass through LIBC_CONF_MATH_OPTIMIZATIONS correctly (#113540)
It's checked in a cmake function that builds up a list called
`config_options`. But the check was appending to a list called
`compile_options`, so the intended `-DLIBC_MATH=whatever` didn't end up
on the actual compile command lines.
2024-10-24 14:51:38 +01:00
Roland McGrath
100720cc4b [libc] Use if constexpr for compile-time conditionals (#113417)
Don't use plain `if` for things that are compile-time constants.
Instead, use `if constexpr`.  This both ensures that these are
properly wired up constant expressions as intended, and prevents
warnings from the compiler about useless `if` checks that look in
the source like they're meant to do something at runtime but will
just be compiled away.
2024-10-22 22:43:32 -07:00
Michael Jones
4275a73124 [libc] Fix long double is double double const (#113258)
Turns out for double double LDBL_MANT_DIG == 106. This patch fixes the
constant. Should fix the ppc buildbot.

Previously:
https://github.com/llvm/llvm-project/pull/113235
https://github.com/llvm/llvm-project/issues/113237
https://github.com/llvm/llvm-project/pull/91651
2024-10-22 07:31:57 -07:00
Guillaume Chatelet
2f58ac4a22 [libc][x86] copy one cache line at a time to prevent the use of rep;movsb (#113161)
When using `-mprefer-vector-width=128` with `-march=sandybridge` copying
3 cache lines in one go (192B) gets converted into `rep;movsb` which
translate into a 60% hit in performance.

Consecutive calls to `__builtin_memcpy_inline` (implementation behind
`builtin::Memcpy::block_offset`) are not coalesced by the compiler and
so calling it three times in a row generates the desired assembly. It
only differs in the interleaving of the loads and stores and does not
affect performance.

This is needed to reland
https://github.com/llvm/llvm-project/pull/108939.
2024-10-22 10:48:43 +02:00
Michael Jones
7eb3264413 [libc] Add handling for long double=double double (#113235)
For Hand-In-Hand we need float to string to support a wider set of
architectures, specifically the ones that libc++ supports. This includes
powerpc, which apparently uses "double double" as its long double type.
Since Hand-In-Hand isn't currently using long double, this just opts
them out.
2024-10-21 17:07:58 -07:00
Michael Jones
6c4267fb17 [libcxx][libc] Hand in Hand PoC with from_chars (#91651)
Implements std::from_chars for float and double.

The implementation uses LLVM-libc to do the real parsing. Since this is
the first time libc++
uses LLVM-libc there is a bit of additional infrastructure code. The
patch is based on the
[RFC] Project Hand In Hand (LLVM-libc/libc++ code sharing)

https://discourse.llvm.org/t/rfc-project-hand-in-hand-llvm-libc-libc-code-sharing/77701
2024-10-21 15:04:06 -07:00
Job Henandez Lara
2ce10f0491 [libc] Remove the <string.h> header in libc/src and libc/test (#113076) 2024-10-20 09:05:41 -07:00
OverMighty
e6c01432b6 [libc][math][c23] Update newhdrgen for new _Float16 math functions (#113005) 2024-10-20 09:49:19 +02:00
Job Henandez Lara
cf4442e6b1 [libc] temporaliy disable __USE_EXTERN_INLINES and set __USE_FORITFY_LEVEL to 1 before including in overlay mode (#113012) 2024-10-18 19:41:22 -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
Michael Jones
0afe6e42fb [libc] Scanf shouldn't match just "0x" for hex int (#112440)
Scanf parsing reads the longest possibly valid prefix for a given
conversion. Then, it performs the conversion on that string. In the case
of "0xZ" with a hex conversion (either "%x" or "%i") the longest
possibly valid prefix is "0x", which makes it the "input item" (per the
standard). The sequence "0x" is not a "matching sequence" for a hex
conversion, meaning it results in a matching failure, and parsing ends.
This is because to know that there's no valid digit after "0x" it reads
the 'Z', but it can only put back one character (the 'Z') leaving it
with consuming an invalid sequence.

(inspired by a thread on the libc-coord mailing list: 
https://www.openwall.com/lists/libc-coord/2024/10/15/1, see 7.32.6.2 in
the standard for more details.)
2024-10-18 15:48:15 -07:00
OverMighty
65cf7afb6d [libc][math][c23] Add logf16 C23 math function (#106072)
Part of #95250.
2024-10-18 22:35:12 +02:00
lntue
952dafb08e [libc][math] Add test and fix atan2f crashing when flush-denorm-to-zero (FTZ) and denorm-as-zero (DAZ) modes are set. (#112828) 2024-10-18 14:56:23 -04:00
lntue
170dab9972 [libc][math] Fix signed zeros for powf when underflow happens. (#112601) 2024-10-18 14:26:05 -04:00
Joseph Huber
00d30bd61e [libc] Commit document formatting change someone left 2024-10-18 10:09:28 -05:00
wldfngrs
803220db43 [libc] changed the return cast from static_cast<float16> to fputil::cast<float16> in exp10f16.cpp. (#112889)
switch to fputil::cast to fix rounding with compiler-rt
2024-10-18 10:24:19 -04: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
Shourya Goel
d508701249 [libc][complex] add additonal header guards for CFP16 and CFP128 (#112879)
Fixes build errors due to #112594
2024-10-18 16:29:07 +05:30
Shourya Goel
7be4ab0a86 [libc][complex] Added support for CFP16 and CFP128 (#112594)
Fixes: #112217
2024-10-18 11:55:57 +05:30
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
87645e9205 [libc][math][c23] Fix undefined behavior in expxf16.h (#112734)
Fixes the left-shifting of potentially negative signed integers.
2024-10-17 18:37:58 +02:00
Nick Desaulniers
3764d0ff15 [libc][setjmp] make x86_64 longjmp naked (#112581)
The generated asm for x86_64's longjmp has a function prolog and epilog.
The
epilog in particular is unreachable. Convert longjmp to a naked function
to
avoid these spurious instructions in longjmp.

Link: https://github.com/llvm/llvm-project/pull/112437/files#r1802085511
2024-10-17 10:08:54 -04:00
OverMighty
95c24cb9de [libc][math][c23] Add exp10m1f16 C23 math function (#105706)
Part of #95250.
2024-10-16 16:33:13 +02:00
westtide
4cc6a08142 Update LLVMLibCArchitectures.cmake (#112464)
Hi there,

When building llvm-libc on the openEuler system, I encountered an issue
as shown in the image below:

![image](https://github.com/user-attachments/assets/75667de4-5bea-4a95-be28-ed34db0e05b9)

This issue happens because the regular expression used in
`libc/cmake/modules/LLVMLibCArchitectures.cmake`: `string(REGEX MATCH
"Target: [-_a-z0-9.]+[ \r\n]+")` does not handle capital letters
properly in `openEuler`.

To fix this, I modified the regular expression to: `string(REGEX MATCH
"Target: [-_a-zA-Z0-9.]+[ \r\n]+")`. This change makes it compatible
with capital letters.
2024-10-15 22:22:44 -05:00
Joseph Huber
08ed19994b [libc] Fix incorrect RPC usage in tests 2024-10-15 18:02:26 -05: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
Nick Desaulniers
46200fcf94 [libc] fix -Wmissing-attributes in setjmp (#112415)
Fixes:

    llvm-project/libc/src/setjmp/x86_64/setjmp.cpp:21:25: error: ‘int
    __llvm_libc_19_0_0_git::setjmp(__jmp_buf*)’ specifies less restrictive
    attribute than its target ‘int
    __llvm_libc_19_0_0_git::__setjmp_impl__(__jmp_buf*)’: ‘nothrow’
    [-Werror=missing-attributes]
       21 | LLVM_LIBC_FUNCTION(int, setjmp, (__jmp_buf * buf)) {
          |                         ^~~~~~

observed in the GCC build by manually expanding LLVM_LIBC_FUNCTION to add
`gnu::nothrow` to the alias.

We probably need to revisit adding nothrow throughout our declarations, so
there is probably a better way to clean this up in the future.

Link: #88054
2024-10-15 13:07:20 -07:00
Joseph Huber
be0c67c90e [libc] Remove dependency on cpp::function in rpc.h (#112422)
Summary:
I'm going to attempt to move the `rpc.h` header to a separate folder
that we can install and include outside of `libc`. Before doing this I'm
going to try to trim up the file so there's not as many things I need to
copy to make it work. This dependency on `cpp::functional` is a low
hanging fruit. I only did it so that I could overload the argument of
the work function so that passing the id was optional in the lambda,
that's not a *huge* deal and it makes it more explicit I suppose.
2024-10-15 12:31:06 -07:00
Michael Jones
87db0c0601 [libc] Add bigint casting between word types (#111914)
Previously you could cast between bigints with different numbers of
bits, but only if they had the same underlying type. This patch adds the
ability to cast between bigints with different underlying types, which
is needed for #110894
2024-10-15 11:18:38 -07:00
Nick Desaulniers
66f968cf37 [libc][setjmp] fix setjmp test via naked fn attr (#88054)
This would consistently fail for me locally, to the point where I could not run
ninja libc-unit-tests without ninja libc_setjmp_unittests failing.

Turns out that since I enabled -ftrivial-auto-var-init=pattern in
commit 1d5c16d ("[libc] default enable -ftrivial-auto-var-init=pattern
(#78776)")
this has been a problem. Our x86_64 setjmp definition disabled -Wuninitialized,
so we wound up clobbering these registers and instead backing up
0xAAAAAAAAAAAAAAAA rather than the actual register value.

Use `naked` function attribute to avoid function prolog/epilog.
2024-10-15 10:39:39 -07:00
OverMighty
aabdd8f818 [libc] Fix compilation errors thrown by GCC (#112351) 2024-10-15 14:44:35 +02:00
lntue
cadfd0b4ca [libc] Also add -Wno-pedantic when building with clang. (#112286) 2024-10-14 19:55:33 -04:00
lntue
9b8dbe2c8d [libc][complex] Fix compiler warnings for usage of complex.h header. (#112282) 2024-10-14 19:33:22 -04:00
lntue
d0b6709965 [libc][math] Fix issignaling macro usage in the implementation. (#112235) 2024-10-14 17:30:07 -04:00
Aly ElAshram
76173b1b67 [libc] Add Linux mman extension remap_file_pages. (#110307)
Fixes https://github.com/llvm/llvm-project/issues/110122
- Create remap_file_pages.h/.cpp wrapper for the linux sys call.
- Add UnitTests for remap_file_pages
- Add function to libc/spec/linux.td
- Add Function spec to mman.yaml
2024-10-14 14:04:32 -07:00
Shourya Goel
8906bff5ab [libc][complex] Silence pedantic warning (#112239)
Fix buildbot errors due to #111659
2024-10-14 14:11:01 -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