On Fri, Jul 25, 2025 at 10:55:36AM +0800, Yang Yujie wrote:
> This patch adds support for C23's _BitInt for LoongArch.
> 
> >From the LoongArch psABI[1]:
> 
> > _BitInt(N) objects are stored in little-endian order in memory
> > and are signed by default.
> >
> > For N ≤ 64, a _BitInt(N) object have the same size and alignment
> > of the smallest fundamental integral type that can contain it.
> > The unused high-order bits within this containing type are filled
> > with sign or zero extension of the N-bit value, depending on whether
> > the _BitInt(N) object is signed or unsigned. The _BitInt(N) object
> > propagates its signedness to the containing type and is laid out
> > in a register or memory as an object of this type.
> >
> > 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 depending on whether the _BitInt(N) object is signed or
> > unsigned. If an entire chunk is unused, its bits are undefined.
> 
> [1] https://github.com/loongson/la-abi-specs
> 
>       PR target/117599
> 
> gcc/ChangeLog:
> 
>       * config/loongarch/loongarch.h: Define a PROMOTE_MODE case for
>       small _BitInts.
>       * config/loongarch/loongarch.cc (loongarch_promote_function_mode):
>       Same.
>       (loongarch_bitint_type_info): New function.
>       (TARGET_C_BITINT_TYPE_INFO): Declare.
> 
> libgcc/ChangeLog:
> 
>       * config/loongarch/t-softfp-tf: Enable _BitInt helper functions.
>       * config/loongarch/t-loongarch: Same.
>       * config/loongarch/libgcc-loongarch.ver: New file.
> 
> gcc/testsuite/ChangeLog:
> 
>       * gcc.target/loongarch/bitint-alignments.c: New test.
>       * gcc.target/loongarch/bitint-args.c: New test.
>       * gcc.target/loongarch/bitint-sizes.c: New test.

This needs to be reviewed by loongarch maintainer, it is OK from my side.

        Jakub

Reply via email to