1381 Commits

Author SHA1 Message Date
OverMighty
12a1e6dd12
[libc][math][c23] Add f16{add,sub}f C23 math functions (#96787)
Part of #93566.
2024-07-02 09:16:12 -04:00
Job Henandez Lara
6f60d2b807
[libc] Add mpfr tests for fmul. (#97376)
Fixes https://github.com/llvm/llvm-project/issues/94834
2024-07-02 00:38:15 -04:00
Hendrik Hübner
ea93c538c7
[libc][math][c23] Implemented sinpif function correctly rounded for all rounding modes. (#97149)
This implements the sinpif function. An exhaustive test shows it's
correct for all rounding modes.

Issue:  #94895
2024-07-01 16:38:03 -04:00
OverMighty
a3f700a3d6
[libc][math][c23] Add MPFR unit test for f16sqrtf (#97062) 2024-07-01 08:46:29 -04:00
OverMighty
44a2589cfc
[libc][math] Add MPFR unit tests for nearbyint{,f,l,f16} (#94479) 2024-07-01 08:45:36 -04:00
OverMighty
6c1c451b86
[libc][math][c23] Add f16sqrt{,l,f128} C23 math functions (#96642)
Part of #95250.
2024-06-30 19:20:39 -04:00
OverMighty
56ef6a2eb2
[libc][math][c23] Add f16div{,l,f128} C23 math functions (#97054)
Part of #93566.
2024-06-29 18:48:12 -04:00
lntue
b8450d4ec8
[libc] Fix incomplete sincos_test. (#97174) 2024-06-29 17:21:00 -04:00
OverMighty
7f68675f64
[libc] Fix compilation error on targets without 128-bit int types (#97039)
See Buildbot failures:

- https://lab.llvm.org/buildbot/#/builders/11/builds/743
- https://lab.llvm.org/buildbot/#/builders/182/builds/362
2024-06-28 07:35:31 -04:00
OverMighty
e34dbb127a
[libc][math][c23] Add f16fma{,l,f128} C23 math function (#96711)
Part of #93566.
2024-06-27 14:44:19 -04:00
lntue
4080f174ab
[libc][math] Implement double precision sincos correctly rounded to all rounding modes. (#96719)
Sharing the same algorithm as double precision sin:
https://github.com/llvm/llvm-project/pull/95736 and cos:
https://github.com/llvm/llvm-project/pull/96591
2024-06-27 10:15:22 -04:00
Schrodinger ZHU Yifan
133492fe18
[libc] add proxy header for struct_sigaction (#96224) 2024-06-26 12:46:15 -07:00
Xu Zhang
7c4fc9ccc0
[libc][fcntl] Simplify the handling of the return value from syscall … (#96325)
Fixes #95570
2024-06-26 09:53:20 -07:00
Joseph Huber
86860be288
[libc] Make 'rand()' thread-safe using atomics instead of TLS (#96692)
Summary:
Currently, we implement the `rand` function using thread-local storage.
This is somewhat problematic because not every target supports TLS, and
even more do not support non-zero initializers on TLS.

The C standard states that the `rand()` function need not be thread,
safe. However, many implementations provide thread-safety anyway.
There's some confusing language in the 'rationale' section of
https://pubs.opengroup.org/onlinepubs/9699919799/functions/rand.html,
but given that `glibc` uses a lock, I think we should make this thread
safe as well. it mentions that threaded behavior is desirable and can be
done in the two ways:

1. A single per-process sequence of pseudo-random numbers that is shared
by all threads that call rand()
2. A different sequence of pseudo-random numbers for each thread that
calls rand()

The current implementation is (2.) and this patch moves it to (1.). This
is beneficial for the GPU case and more generic support. The downside is
that it's slightly slower to do these atomic operations, the fast path
will be two atomic reads and an atomic write.
2024-06-26 07:03:28 -05:00
PiJoules
54ca5a800d
[libc][fixedvector] Add const_iterator begin/end (#96714) 2024-06-25 16:33:36 -07:00
lntue
88f80aeb0c
[libc][math] Implement double precision cos correctly rounded to all rounding modes. (#96591)
Sharing the same algorithm as double precision sin:
https://github.com/llvm/llvm-project/pull/95736
2024-06-25 16:51:31 -04:00
OverMighty
ef05b03223
[libc][math][c23] Add MPFR exhaustive test for fmodf16 (#94656) 2024-06-25 16:44:47 -04:00
OverMighty
edbe698ead
[libc][math][c23] Add f16divf C23 math function (#96131)
Part of #93566.
2024-06-25 08:48:28 -04:00
Joseph Huber
dc27ff1049 [libc] Disable freelist test on NVPTX temporarily
Summary:
This test fails due to alignment issues, it's likely that it's
misaligned on other targets too and they just don't crash on it.
@PiJoules maybe we should run this with ubsan?
2024-06-24 18:05:00 -05:00
lntue
16903ace18
[libc][math] Implement double precision sin correctly rounded to all rounding modes. (#95736)
- Algorithm:
- Step 1 - Range reduction: for a double precision input `x`, return `k`
and `u` such that
    - k is an integer
    - u = x - k * pi / 128, and |u| < pi/256
- Step 2 - Calculate `sin(u)` and `cos(u)` in double-double using Taylor
polynomials with errors < 2^-70 with FMA or < 2^-66 w/o FMA.
- Step 3 - Calculate `sin(x) = sin(k*pi/128) * cos(u) + cos(k*pi/128) *
sin(u)` using look-up table for `sin(k*pi/128)` and `cos(k*pi/128)`.
- Step 4 - Use Ziv's rounding test to decide if the result is correctly
rounded.
- Step 4' - If the Ziv's rounding test failed, redo step 1-3 using
128-bit precision.
- Currently, without FMA instructions, the large range reduction only
works correctly for the default rounding mode (FE_TONEAREST).
- Provide `LIBC_MATH` flag so that users can set `LIBC_MATH =
LIBC_MATH_SKIP_ACCURATE_PASS` to build the `sin` function without step 4
and 4'.
2024-06-24 17:57:08 -04:00
lntue
09bc1e8250
[libc][stdlib] Only use freelist_malloc for baremetal targets. (#96355) 2024-06-21 16:38:25 -04:00
OverMighty
b5efd21429
[libc][math][c23] Add {ldexp,scalbn,scalbln}f16 C23 math functions (#94797)
Part of #93566.
2024-06-21 09:01:47 -04:00
PiJoules
f77ade0aed
[libc] Move freelist + block to __support (#96231) 2024-06-20 13:13:52 -07:00
OverMighty
1107575c95
[libc][math][c23] Add {getpayload,setpayload,setpayloadsig}f16 C23 math functions (#95159)
Part of #93566.
2024-06-20 13:33:34 -04:00
OverMighty
57778ec36c
[libc] Fix scheduler test incorrectly guessing user privileges (#95562)
Non-root users may be able to set real-time scheduling policies. Don't
expect failure to set real-time scheduling policies based on UID.
Instead, check that if it fails, it is either due to missing privileges,
or unsupported parameters if the scheduling policy is not mandated by
POSIX.

Fixes #95564.
2024-06-19 20:16:02 -05:00
Joseph Huber
ffed34e025 [libc] Fix getauxval being defined in a namespace 2024-06-17 19:52:06 -05:00
lntue
ca22469a10
[libc][stdlib] Run freelist_heap_test only in full build mode. (#95850) 2024-06-17 17:56:45 -04:00
Joseph Huber
44ca65661e
[libc] Only include getauxval on AARCH64 targets (#95844)
Summary:
Not all platforms support this function or header, but it was being
included by every test. Move it inside of the `ifdef` for the only user,
which is aarch64.
2024-06-17 15:51:26 -05:00
Xu Zhang
0b24b47069
[libc] Add the implementation of the fdopen function (#94186)
Fixes #93711 .
This patch implements the ``fdopen`` function. Given that ``fdopen`` 
internally calls ``fcntl``, the implementation of ``fcntl`` has been
moved to the ``__support/OSUtil``, where it serves as an internal public
function.
2024-06-14 16:17:44 -07:00
Schrodinger ZHU Yifan
c091dd4800
[libc] fix build errors (#95613) 2024-06-14 15:59:42 -07:00
Schrodinger ZHU Yifan
f00f11bf86
[libc] fix build errors (#95600)
Bitfield conversion problem tested at: https://godbolt.org/z/dxjhs5Ghr
2024-06-14 14:50:12 -07:00
Schrodinger ZHU Yifan
41fecca97b
[libc] add rwlock (#94156) 2024-06-14 13:34:28 -07:00
PiJoules
005758eb6b
[libc][stdlib] Make the FreeListHeap constant-initializable (#95453)
This refactors some of the FreeListHeap, FreeList, and Block classes to
have constexpr ctors so we can constinit a global allocator that does
not require running some global function or global ctor to initialize.
This is needed to prevent worrying about initialization order and any
other module-ctor can invoke malloc without worry.
2024-06-14 12:11:49 -07:00
OverMighty
f3aceeee8a
[libc][math][c23] Add f16fmaf C23 math function (#95483)
Part of #93566.
2024-06-14 12:31:32 -04:00
Schrodinger ZHU Yifan
2efe3d7fc0
Reland "[libc] fix aarch64 linux full build (#95358)" (#95423)
Reverts llvm/llvm-project#95419 and Reland #95358.

This PR is full of temporal fixes. After a discussion with @lntue, it is
better to avoid further changes to the cmake infrastructure for now as a
rework to the cmake utilities will be landed in the future.
2024-06-13 20:34:32 -07:00
OverMighty
ba7d5ebe4b
[libc] Fix build breaks caused by f16sqrtf changes (#95459)
See Buildbot failures:

- https://lab.llvm.org/buildbot/#/builders/78/builds/13
- https://lab.llvm.org/buildbot/#/builders/182/builds/7
2024-06-13 15:48:36 -04:00
Jay Foad
d4a0154902
[llvm-project] Fix typo "seperate" (#95373) 2024-06-13 20:20:27 +01:00
OverMighty
a239343521
[libc][math][c23] Add f16sqrtf C23 math function (#95251)
Part of #95250.
2024-06-13 12:57:24 -04:00
Schrodinger ZHU Yifan
9e5428e6b0
Revert "[libc] fix aarch64 linux full build (#95358)" (#95419) 2024-06-13 08:37:20 -07:00
Schrodinger ZHU Yifan
ca05204f9a
[libc] fix aarch64 linux full build (#95358) 2024-06-13 07:45:25 -07:00
PiJoules
3bcd80acba
[libc][stdlib] Add the FreelistHeap (#95066)
This is the actual freelist allocator which utilizes the generic
FreeList and the Block classes. We will eventually wrap the malloc
interface around this.

This is a part of #94270 to land in smaller patches.
2024-06-12 22:47:47 -07:00
OverMighty
f5dcfb9968
[libc][math][c23] Add {totalorder,totalordermag}f16 C23 math functions (#95014)
Part of #93566.
2024-06-11 11:04:48 -04:00
PiJoules
1737814e57
[libc][stdlib] Add freelist class (#95041)
This implements a traditional freelist to be used by the freelist
allocator. It operates on spans of bytes which can be anything. The
freelist allocator will store Blocks inside them.

This is a part of #94270 to land in smaller patches.
2024-06-10 17:22:58 -07:00
OverMighty
f50656c509
[libc][math][c23] Add MPFR unit tests for {rint,lrint,llrint,lround,llround}f16 (#94473) 2024-06-10 17:30:18 -04:00
PiJoules
85c78d4507
[libc][stdlib] Add Block class (#94407)
A block represents a chunk of memory used by the freelist allocator. It
contains header information denoting the usable space and pointers as
offsets to the next and previous block.

On it's own, this doesn't do much. This is a part of
https://github.com/llvm/llvm-project/pull/94270 to land in smaller
patches.

This is a subset of pigweed's freelist allocator implementation.
2024-06-10 13:26:35 -07:00
OverMighty
65310f34d7
Reapply "[libc][math][c23] Add MPFR unit tests for {ceil,floor,round,roundeven,trunc}f16 (#94383)" (#94807)
This reverts commit cbe97e959dc67503d7cc44a3810e3124b6d3340e.
2024-06-10 15:48:19 -04:00
OverMighty
7683a16dbf
[libc][math][c23] Add {remainder,remquo}f16 C23 math functions (#94773)
Part of #93566.
2024-06-10 11:02:09 -04:00
OverMighty
6b21e17049
[libc] Add WordTypeSelector<16> specialization (#94979) 2024-06-10 09:56:02 -04:00
OverMighty
10cd96dd33
[libc][math][c23] Add {frexp,ilogb,llogb,logb,modf}f16 C23 math functions (#94758)
Part of #93566.
2024-06-10 08:38:47 -04:00
OverMighty
cb1a727dea
[libc][math][c23] Add nanf16 C23 math function (#94767)
Part of #93566.
2024-06-10 00:19:22 -04:00