Commit Graph

1566 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
7b663bd917 [libc] Fix the remaining fcntl.h proxy header includes. (#113961) 2024-10-28 17:49:36 -04:00
Job Henandez Lara
abc49cc194 [libc] remove #include <fcntl.h> and add proxy or type (#113836) 2024-10-28 13:29:16 -07: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
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
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
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
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
95c24cb9de [libc][math][c23] Add exp10m1f16 C23 math function (#105706)
Part of #95250.
2024-10-16 16:33:13 +02: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
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
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
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
Shourya Goel
111b062f63 [libc] Fix for adding macro I (#111872)
We have two (EDIT: 4) files in which we are using `I`. This PR replaces
them with alternatives like `i` and `IDX` etc.
2024-10-11 16:35:01 -04:00
lntue
51e9430a0c [libc][math] Improve performance of double precision trig functions. (#111793)
- Improve the accuracy of fast pass' range reduction.
- Provide tighter error estimations.
- Reduce the table size when `LIBC_MATH_SMALL_TABLES` flag is set.
2024-10-10 23:33:02 -04:00
Joseph Huber
cbfcea1fc2 [libc] Temporarily disable strerror test on NVPTX
Summary:
This is failing on the NVPTX buildbot,
https://lab.llvm.org/buildbot/#/builders/69/builds/6997/. I cannot
reproduce it locally so I'm disabling it temporarily so the bot is
green.
2024-10-10 20:20:05 -05:00
Shourya Goel
4e33afee5a [libc][math] Implement issignaling and iscanonical macro. (#111403)
#109201
2024-10-09 10:25:49 -07:00
Job Henandez Lara
46944b0cbc [libc] remove errno.h includes (#110934) 2024-10-05 19:31:36 -04:00
lntue
7a0a524653 [libc] Fix iscanonical test on aarch64 and riscv64. (#110907) 2024-10-02 14:29:56 -04: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
Michael Jones
9c868195da [libc] clean up sprintf macros and float tests (#110759)
The sprintf tests have a macro named "ASSERT_STREQ_LEN" which was used
in about half of the tests. This patch moves all of the tests which can
to using that macro. This patch also enables long double tests for %e
and %g, since those never got finished. There's still some work to do
enabling long double testing for long doubles other than the intel 80
bit format, but that can land in a followup.

The `#ifdef LIBC_COPT_FLOAT_TO_STR_REDUCED_PRECISION` lines are for a
followup patch.
2024-10-01 16:28:41 -07:00
Michael Jones
f6b2a222be [libc] Move struct Sign into LIBC_NAMESPACE (#110709)
The struct Sign should be in the correct namespace. Also update the
various tests that use it.
2024-10-01 10:55:57 -07: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
lntue
c63112a911 [libc][stdio] Use proxy headers of stdio.h in src and test folders. (#110067)
https://github.com/llvm/llvm-project/issues/60481
2024-10-01 11:48:07 -04:00
lntue
cab8c87692 [libc] Fix race conditions in sprintf_test. (#110624) 2024-10-01 08:42:32 -04:00
lntue
79ecb814d0 [libc][math] Fix exceptional cases pow(-0, 1/2) and pow(-inf, 1/2). (#110566) 2024-10-01 06:37:47 -04:00
Joseph Huber
95c0e03376 [libc] Fix 'fgets' test on the GPU for some C libraries (#110118)
Summary:
The GPU handling for a lot of `FILE *` functions pretty much just
forwards it to the host via RPC. This test checks for implementation
defined behavior, which sometimes passes and sometimes doesn't. We just
disable it here so it works on the standard semantics.

We do this forwarding primarily for interopt w/ the host if the user is
compiling from an offloading language (e.g. CUDA).
2024-09-26 07:23:07 -07:00
Shourya Goel
b935d312f1 [libc][math] Reapply and fix issignaling macro. (#110011)
reapply #109615
2024-09-25 15:39:55 -04:00
lntue
808c498f52 Revert "[libc][math] Implement issignaling macro." (#109992)
Reverts llvm/llvm-project#109615
2024-09-25 10:58:08 -04:00
Shourya Goel
ac802a3148 [libc][math] Implement issignaling macro. (#109615)
#109201
2024-09-25 10:35:20 -04:00
OverMighty
127349fcba [libc][math] Add floating-point cast independent of compiler runtime (#105152)
Fixes build and tests with compiler-rt on x86.
2024-09-23 19:35:39 +02:00
Shourya Goel
ba5e195809 [libc][math] Implement issubnormal macro. (#109572)
#109201
2024-09-23 00:50:46 -04:00
Shourya Goel
aaa637d8d0 [libc][math] Implement isnormal macro. (#109547)
#109201
2024-09-21 22:26:56 -04:00
Shourya Goel
56124feeb8 [libc][math] Implement fpclassify macro. (#109519)
#109201
2024-09-21 11:49:23 -04:00
Shourya Goel
739ede400b [libc][[math] Implement IsZero Macro (#109336)
#109201
2024-09-20 13:00:01 -04:00
lntue
95d4c97a20 [libc][wchar] Move wchar's types to proxy headers. (#109334)
Also protect against extern inline function definitions added when
building with gcc: https://github.com/llvm/llvm-project/issues/60481.
2024-09-19 22:23:51 -04:00
Michael Jones
13dd2fd1e0 [libc] Put bind back, fix gcc build (#109341)
Fixes #106467.
Bind was accidentally removed while trying to clean up functions that
didn't end up being needed. The GCC issue was just a warning treated as
an error.
2024-09-19 15:10:56 -07:00
Michael Jones
f6b4c34d4f [libc] Add functions to send/recv messages (#106467)
This patch adds the necessary functions to send and receive messages
over a socket. Those functions are: recv, recvfrom, recvmsg, send,
sendto, sendmsg, and socketpair for testing.
2024-09-19 14:43:00 -07:00