compiler-rt: Add udivmodei5 to builtins and add bitint library
authorMatthias Gehre <matthias.gehre@xilinx.com>
Tue, 22 Feb 2022 15:09:54 +0000 (15:09 +0000)
committerMatthias Gehre <matthias.gehre@xilinx.com>
Fri, 8 Apr 2022 06:43:15 +0000 (07:43 +0100)
commitbf2dc4b37623e1b4f7d39570e1b5a6f3ef5db107
treedaa968956f6c9e26ea46e687cac2997991e9dce9
parent36d3efea15e6202edd64b05de38d8379e2baddb2
compiler-rt: Add udivmodei5 to builtins and add bitint library

According to the RFC [0], this review contains the compiler-rt parts of large integer divison for _BitInt.

It adds the functions
```
/// Computes the unsigned division of a / b for two large integers
/// composed of n significant words.
/// Writes the quotient to quo and the remainder to rem.
///
/// \param quo The quotient represented by n words. Must be non-null.
/// \param rem The remainder represented by n words. Must be non-null.
/// \param a The dividend represented by n + 1 words. Must be non-null.
/// \param b The divisor represented by n words. Must be non-null.

/// \note The word order is in host endianness.
/// \note Might modify a and b.
/// \note The storage of 'a' needs to hold n + 1 elements because some
///       implementations need extra scratch space in the most significant word.
///       The value of that word is ignored.
COMPILER_RT_ABI void __udivmodei5(su_int *quo, su_int *rem, su_int *a,
                                  su_int *b, unsigned int n);

/// Computes the signed division of a / b.
/// See __udivmodei5 for details.
COMPILER_RT_ABI void __divmodei5(su_int *quo, su_int *rem, su_int *a, su_int *b,
                                 unsigned int words);
```
into builtins.
In addition it introduces a new "bitint" library containing only those new functions,
which is meant as a way to provide those when using libgcc as runtime.

[0] https://discourse.llvm.org/t/rfc-add-support-for-division-of-large-bitint-builtins-selectiondag-globalisel-clang/60329

Differential Revision: https://reviews.llvm.org/D120327
14 files changed:
compiler-rt/CMakeLists.txt
compiler-rt/cmake/builtin-config-ix.cmake
compiler-rt/lib/CMakeLists.txt
compiler-rt/lib/bitint/CMakeLists.txt [new file with mode: 0644]
compiler-rt/lib/builtins/CMakeLists.txt
compiler-rt/lib/builtins/int_lib.h
compiler-rt/lib/builtins/udivmodei5.c [new file with mode: 0644]
compiler-rt/test/CMakeLists.txt
compiler-rt/test/bitint/CMakeLists.txt [new file with mode: 0644]
compiler-rt/test/bitint/Unit/bitint_test.c [new file with mode: 0644]
compiler-rt/test/bitint/Unit/lit.cfg.py [new file with mode: 0644]
compiler-rt/test/bitint/Unit/lit.site.cfg.py.in [new file with mode: 0644]
compiler-rt/test/builtins/Unit/divmodei5_test.c [new file with mode: 0644]
compiler-rt/test/builtins/Unit/udivmodei5_test.c [new file with mode: 0644]