Hi,

This is a proposition of a _BitInt(N) implementation for LoongArch,
with the following psABI description:

```
=== Fundamental types of N-bit integers

`_BitInt(N)` (as proposed in ISO/IEC WG14 N2763) is a family of integer types
where `N` specifies the exact number of bits used for its representation.

* `_BitInt(N)` objects are stored in little-endian order in memory
and are signed by default.

* For N <= 64, `_BitInt(N)` objects have the same size and alignment of the
smallest fundamental integral type that can contain them, and are always
sign-extended or zero-extended to this size according its signedness.
For instance, `_BitInt(8)`, `_BitInt(16)`, `_BitInt(32)` and `_BitInt(64)`
behave exactly the same as the fundamental types of signed byte,
half-word, word and double-word, respectively.

* For N > 64, `_BitInt(N)` objects are implemented as structs of 64-bit
integer chunks. The number of chunks is the smallest even integer `M` so
that M * 64 >= N. These objects are of the same size of the struct containing
the chunks, but always have 16-byte alignment. If there are unused bits in the
highest-ordered chunk that contains used bits, they are defined as the sign- or
zero- extension of the used bits. If an entire chunk is unused, its bits
are undefined.
```

The main differences from the existing implementations (x86_64 and aarch64)
is that all partial limbs are extended for both small/middle and large/huge
_BitInts. For this purpose, some changes needs to be made to gimple lowering
and expand.

This series has been bootstrapped and regtested with x86_64-linux-gnu and
loongarch64-linux-gnu (against a version that leaves the partial limbs
undefined).

Please help us find if there's something we've missed.

Thanks,
Yujie


Yang Yujie (3):
  bitint: Support ABI-extended _BitInt(N)
  bitint: Allow wider abi_limb_mode than limb_mode during layout
  LoongArch: Add support for _BitInt [PR117599]

 gcc/c-family/c-common.cc                      |  65 +++-
 gcc/config/loongarch/loongarch.cc             |  31 +-
 gcc/config/loongarch/loongarch.h              |   4 +-
 gcc/explow.cc                                 |  32 +-
 gcc/expr.cc                                   |  23 +-
 gcc/gimple-lower-bitint.cc                    | 365 ++++++++++++++++--
 gcc/stor-layout.cc                            |   3 +-
 .../gcc.target/loongarch/bitint-alignments.c  |  58 +++
 .../gcc.target/loongarch/bitint-args.c        |  93 +++++
 .../gcc.target/loongarch/bitint-sizes.c       |  60 +++
 libgcc/config/loongarch/t-softfp-tf           |   1 +
 11 files changed, 690 insertions(+), 45 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/loongarch/bitint-alignments.c
 create mode 100644 gcc/testsuite/gcc.target/loongarch/bitint-args.c
 create mode 100644 gcc/testsuite/gcc.target/loongarch/bitint-sizes.c

-- 
2.34.1

Reply via email to