On 1/4/2026 7:55 PM, Kito Cheng wrote:
This patch implements _BitInt support for RISC-V target by defining the
type layout and ABI requirements.  The limb mode selection is based on
the bit width, using appropriate integer modes from QImode to TImode.
The implementation also adds the necessary libgcc version symbols for
_BitInt runtime support functions.

Changes in v2:
- limb_mode use up to XLEN when N > XLEN, which is different setting from
   the abi_limb_mode.
- Adding missing floatbitinthf in libgcc.

gcc/ChangeLog:

        PR target/117581
        * config/riscv/riscv.cc (riscv_bitint_type_info): New function.
        (TARGET_C_BITINT_TYPE_INFO): Define.

gcc/testsuite/ChangeLog:

        PR target/117581
        * gcc.target/riscv/bitint-32-on-rv64.c: New test.
        * gcc.target/riscv/bitint-alignments.c: New test.
        * gcc.target/riscv/bitint-args.c: New test.
        * gcc.target/riscv/bitint-sizes.c: New test.

libgcc/ChangeLog:

        PR target/117581
        * config/riscv/libgcc-riscv.ver: New file.
        * config/riscv/t-elf (SHLIB_MAPFILES): Add libgcc-riscv.ver.
        * config/riscv/t-softfp32 (softfp_extras): Add floatbitinttf and
        fixtfbitint.
So this turned out to be much less intrusive than I expected.

+bool
+riscv_bitint_type_info (int n, struct bitint_info *info)
+{
+  if (n <= 8)
+    info->limb_mode = QImode;
+  else if (n <= 16)
+    info->limb_mode = HImode;
+  else if (n <= 32)
+    info->limb_mode = SImode;
+  else if (n <= 64)
+    info->limb_mode = DImode;
+  else if (n <= 128 && TARGET_64BIT)
+    info->limb_mode = TImode;
+  else
+    info->limb_mode = TARGET_64BIT ? DImode : SImode;
So I've never looked at how BitInt works, so if this is totally off-base just say so ;-)

It seems a bit odd to have the limb_mode by DImode for rv32 when we don't have any DImode operations in rv32.  Though we allow TImode for rv64, so perhaps we're just relying on widening capabilities in the expander interfaces under the hood?

It also seems a bit odd that for n > 128 and TARGET_64BIT that we select DImode when we use TImode for sizes > 64, but <= 128.   Similarly for !TARGET_64BIT we have SImode and DImode respectively.

Jeff



Reply via email to