Commit Graph

3027 Commits

Author SHA1 Message Date
PiJoules
39cf880339 [libc][stdlib] Change old unsigned short variables to size_t (#95065)
They were assigned from calls to find_chunk_ptr_for_size which return
size_t now.
2024-06-10 20:19:24 -07: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
PiJoules
fd4a740128 [libc][stdlib] Move LIBC_INLINE after template and before constexpr (#95037) 2024-06-10 15:01:01 -07:00
PiJoules
076a50ad17 [NFC][libc][stdlib] LLVM_LIBC_SRC_STDLIB_LDIV_H -> LLVM_LIBC_SRC_STDL… (#95038)
…IB_FREE_H
2024-06-10 15:00:50 -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 cbe97e959d.
2024-06-10 15:48:19 -04:00
OverMighty
a9e5f42e2a [libc][math][c23] Temporarily disable float16 on 32-bit Arm (#95027)
See Buildbot failure:
https://lab.llvm.org/buildbot/#/builders/229/builds/27009.
2024-06-10 15:30:18 -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
c5b68a9dce [libc][math][c23] Temporarily disable float16 on RISC-V (#94984)
See Buildbot failures:

- https://lab.llvm.org/buildbot/#/builders/257/builds/13450
- https://lab.llvm.org/buildbot/#/builders/256/builds/14531
2024-06-10 10:18:53 -04:00
OverMighty
6b21e17049 [libc] Add WordTypeSelector<16> specialization (#94979) 2024-06-10 09:56:02 -04:00
OverMighty
dcd9a503dc [libc][math][c23] Temporarily disable modff16 on AArch64 (#94972)
See Buildbot failure:
https://lab.llvm.org/buildbot/#/builders/138/builds/67428.
2024-06-10 08:48: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
Hendrik Hübner
44aecca020 [libc][math][C23] Implemented remquof128 function (#94809)
Added remquof128 function. Closes #94312
2024-06-08 15:08:45 -04:00
Job Henandez Lara
263be9fb00 [libc][math][c23] fmul correcly rounded to all rounding modes (#91537)
This is an implementation of floating point multiplication:

It will consist of 
   - `double x double -> float`
2024-06-08 15:07:27 -04:00
OverMighty
4346c3859c [libc][math][c23] Temporarily disable fmodf16 on AArch64 (#94813)
See Buildbot failure:
https://lab.llvm.org/buildbot/#/builders/138/builds/67337.
2024-06-07 18:49:44 -04:00
OverMighty
0cdb0b7473 [libc][math][c23] Add fmodf16 C23 math function (#94629)
Part of #93566.
2024-06-07 18:26:58 -04:00
Michael Jones
11d643f0b1 [libc] Add baremetal printf (#94078)
For baremetal targets that don't support FILE, this version of printf
just writes directly to a function provided by a vendor. To do this both
printf and vprintf were moved to /generic (vprintf since they need the
same flags and cmake gets funky about setting variables in one file and
reading them in another).
2024-06-07 11:37:12 -07:00
Joseph Huber
2c3723d321 [libc] Correctly pass the C++ standard to NVPTX internal builds
Summary:
The NVPTX build wasn't getting the `C++20` standard necessary for a few
files.
2024-06-07 07:55:06 -05:00
aaryanshukla
855af13e8a [libc] fixed target issue with exit_handler (#94678)
- addressed
https://github.com/llvm/llvm-project/pull/94317#issuecomment-2153103129
- added conditional in cmake file for exit_handler object library

Co-authored-by: Aaryan Shukla <aaryanshukla@google.com>
2024-06-06 21:35:59 +00:00
PiJoules
649edb8eb2 [libc][FixedVector] Add more helper methods (#94278)
This adds:
- A ctor accepting a start and end iterator
- A ctor accepting a count and const T&
- size()
- subscript operators
- begin() and end() iterators
2024-06-06 11:25:16 -07:00
aaryanshukla
39d38d66ec [libc] at_quick_exit function implemented (#94317)
- added at_quick_exit function 
- used helper file exit_handler which reuses code from atexit
- atexit now calls helper functions from exit_handler
- test cases and dependencies are added

---------

Co-authored-by: Aaryan Shukla <aaryanshukla@google.com>
2024-06-06 17:21:44 +00:00
OverMighty
dd1cd02a43 [libc][math][c23] Add {fmaximum,fminimum}{,_mag,_mag_num,_num} C23 math functions (#94510)
#93566
2024-06-06 11:20:29 -04:00
OverMighty
3c6d004068 [libc][math][c23] Fix implicit conversion in smoke tests for {fmax,fmin}f16 (#94624) 2024-06-06 11:16:59 -04:00
Joseph Huber
31442c9669 [libc] Enable varargs tests for AMDGPU targets
Summary:
This reverts commit 574ab7e7b7.
2024-06-06 08:39:40 -05:00
lntue
e040474f49 [libc][math] Temporarily disable nexttowardf16 on aarch64 due to clang-11 bug. (#94569)
The conversion between _Float16 and long double will crash clang-11 on
aarch64. This is fixed in clang-12: https://godbolt.org/z/8ceT9454c
2024-06-06 07:59:02 -04:00
Jon Chesterfield
574ab7e7b7 [libc] Disable varargs tests on gpu, nvptx can't build them yet 2024-06-06 11:33:36 +01:00
Jon Chesterfield
8516f54e6a [AMDGPU] Implement variadic functions by IR lowering (#93362)
This is a mostly-target-independent variadic function optimisation and
lowering pass. It is only enabled for AMDGPU in this initial commit.

The purpose is to make C style variadic functions a zero cost
abstraction. They are lowered to equivalent IR which is then amenable to
other optimisations. This is inherently slightly target specific but
much less so than one might expect - the C varargs interface heavily
constrains the ABI design divergence.

The pass is primarily tested from webassembly. This is because wasm has
a straightforward variadic lowering strategy which coincides exactly
with what this pass transforms code into and a struct passing convention
with few cases to check. Adding further targets conventions is
straightforward and elided from this patch primarily to simplify the
review. Implemented in other branches are Linux X86, AMD64, AArch64 and
NVPTX.

Testing for targets that have existing lowering for va_arg from clang is
most efficiently done by checking that clang | opt completely elides the
variadic syntax from test cases. The lowering produces a struct for each
call site which can be inspected to check the various alignment and
indirections are correct.

AMDGPU presently has no variadic support other than some ad hoc printf
handling. Combined with the pass being inactive on all other targets
landing this represents strict increase in capability with zero risk.
Testing and refining will continue post commit.

In addition to the compiler tests included here, a self contained x64
clang/musl toolchain was constructed using the "lowering" instead of the
systemv ABI and used to build various C programs like lua and libxml2.
2024-06-06 10:44:53 +01:00
OverMighty
63cda2d19c [libc][math][c23] Add {nextafter,nexttoward,nextup,nextdown}f16 C23 math functions (#94535)
#93566
2024-06-05 23:06:48 -04:00
Hendrik Hübner
8e67495326 [libc][math][c23] Implement fmaxf16 and fminf16 function (#94131)
Implements fmaxf16 and fminf16, which are two missing functions listed
here: #93566
2024-06-05 22:44:44 -04:00
Joseph Huber
dbc3e26c25 [libc][NFC] More verbose warning message on missing utilities
Summary:
The GPU needs both the loader utility and the architecture to be present
to run tests. This simply makes it easier to detect which is missing in
case of problems.
2024-06-05 18:09:06 -05:00
Michael Jones
20483edd27 [libc] Unpoison epoll structs (#94536)
The epoll wait functions return structs via pointer, but those structs
need to be unpoisoned before return. This patch adds that unpoisoning.
2024-06-05 15:02:28 -07:00
PiJoules
b477d1de6e [libc][type_traits] Add aligned_storage (#94074) 2024-06-05 12:59:39 -07:00
OverMighty
cbe97e959d Revert "[libc][math][c23] Add MPFR unit tests for {ceil,floor,round,roundeven,trunc}f16 (#94383)" (#94505)
This reverts commit fda1e4b01f.

The commit caused Buildbot failures:
- https://lab.llvm.org/buildbot/#/builders/256/builds/14331
- https://lab.llvm.org/buildbot/#/builders/229/builds/27009
2024-06-05 13:16:09 -04:00
OverMighty
fda1e4b01f [libc][math][c23] Add MPFR unit tests for {ceil,floor,round,roundeven,trunc}f16 (#94383) 2024-06-05 12:38:15 -04:00
Joseph Huber
7578c31823 [libc] Disable fpexcept testing on the GPU
Summary:
These new tests fails on the GPU due to the exception testing. Disable
it for now because these aren't supported and can't be supported on
NVPTX.
2024-06-05 09:54:34 -05:00
OverMighty
c537f35646 [libc][math][c23] Add fdimf16 C23 math function (#94354)
#93566
2024-06-05 10:37:55 -04:00
jameshu15869
ce8bb9b5ac [libc] Implement forward iterators for libc fixed_vector (#93916)
- Implements forward iterators for `cpp::fixed_vector` to use in
https://github.com/llvm/llvm-project/pull/92009
2024-06-05 09:04:24 -05:00
OverMighty
6c97303681 [libc][math][c23] Add copysignf16 C23 math function (#94351)
#93566
2024-06-05 09:46:36 -04:00
OverMighty
3614beede1 [libc][math][c23] Add canonicalizef16 C23 math function (#94341)
#93566
2024-06-05 08:24:23 -04:00
PiJoules
330e8a7619 [libc][stdlib] Add calloc header (#94403) 2024-06-04 15:51:53 -07:00
Joachim Meyer
8896f21ca9 [NFC] Fix typo in libc/docs/gpu/using.rst 2024-06-04 15:40:45 -07:00
OverMighty
6b5ae148e5 [libc][math][c23] Add {fromfp,fromfpx,ufromfp,ufromfpx}f16 C23 math functions (#94254)
https://github.com/llvm/llvm-project/issues/93566
2024-06-04 18:29:53 -04:00
PiJoules
534590144f [libc][new] Add placement new functions (#94290) 2024-06-04 12:10:08 -07:00
c8ef
fb300eb44d [libc] add LIBC_INLINE for expected, use CTAD in abs_timeout (#94348) 2024-06-04 07:49:48 -07:00
OverMighty
2635d0419e [libc][math][c23] Add {nearbyint,rint,lrint,llrint,lround,llround}f16 C23 math functions (#94218)
https://github.com/llvm/llvm-project/issues/93566
2024-06-04 10:03:31 -04:00
Jordan Rupprecht
392ca64893 [libc][test] Fix TEST->TEST_F typo in getenv_and_setenv_test.cpp (#94304)
This manifests as `AddressSanitizer: stack-use-after-return` w/o this
change. The `~CheckFEnv()` method of checking fenv seems to only work
for test fixtures.
2024-06-03 21:48:33 -05:00
Joseph Huber
cf3b37c92f [libc] Add GPU utility dependencies if present
Summary:
These tools need to be built before we can do the library creation
stage. If they are generated in the same build then this is not
guaranteed so we should add explicit dependencies.
2024-06-03 14:37:39 -05:00
PiJoules
e44cea597c [libc][CPP] Add all_of and find_if_not to algorithm.h (#94058)
This is needed for the allocator implementation for malloc.
2024-06-03 11:44:44 -07:00