Skip to content

Commit 9e2e1d9

Browse files
committed
ABI for _BitInt
`_BitInt (N)` is the type defined in C23, allow user to define an arbitrary-sized integer type, where N is a postive integer larger than zero. This proposal defined the size and alignment of _BitInt, and define the unused bits as unspecified which is same as x86-64 and AArch64. For the calling convention part, we keep unused bits as unspecified. Ref: - ISO/IEC WG14 N2763: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2763.pdf - [AArch64] Rationale Document for ABI related to the C23 _BitInt type. https://github.com/ARM-software/abi-aa/tree/main/design-documents/bit-precise-types.rst - AAPCS64 for _BitInt(N) ARM-software/abi-aa@d621417 - x86-64 ABI for _BitInt(N) https://gitlab.com/x86-psABIs/x86-64-ABI/-/commit/8ca45392570e96920f8a15d903d6122f6d263cd0 Fix #300
1 parent 52a6631 commit 9e2e1d9

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

riscv-cc.adoc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ sign-extended to XLEN bits.
156156
When passed in registers or on the stack, floating-point types narrower than
157157
XLEN bits are widened to XLEN bits, with the upper bits undefined.
158158

159+
When passed in registers or on the stack, `__BitInt(N)`, unused bits are
160+
undefined, types narrower than XLEN bits are widened to XLEN bits, with the
161+
upper bits undefined.
162+
159163
Scalars that are 2×XLEN bits wide are passed in a pair of argument registers,
160164
with the low-order XLEN bits in the lower-numbered register and the high-order
161165
XLEN bits in the higher-numbered register. If no argument registers are
@@ -457,6 +461,12 @@ alignments (based on the ILP32 convention):
457461
| float _Complex | 8 | 4
458462
| double _Complex | 16 | 8
459463
| long double _Complex | 32 | 16
464+
| _BitInt(1 ≤ N ≤ 8) | 1 | 1
465+
| _BitInt(9 ≤ N ≤ 16) | 2 | 2
466+
| _BitInt(17 ≤ N ≤ 32) | 4 | 4
467+
| _BitInt(33 ≤ N ≤ 64) | 8 | 8
468+
| _BitInt(65 ≤ N ≤ 128)| 16 | 16
469+
| _BitInt(N > 128) | RoundUp(N / 128) * 16 | 16
460470
|===
461471

462472
LP64, LP64F, LP64D, and LP64Q:: Use the following type sizes and
@@ -484,6 +494,12 @@ alignments (based on the LP64 convention):
484494
| float _Complex | 8 | 4
485495
| double _Complex | 16 | 8
486496
| long double _Complex | 32 | 16
497+
| _BitInt(1 ≤ N ≤ 8) | 1 | 1
498+
| _BitInt(9 ≤ N ≤ 16) | 2 | 2
499+
| _BitInt(17 ≤ N ≤ 32) | 4 | 4
500+
| _BitInt(33 ≤ N ≤ 64) | 8 | 8
501+
| _BitInt(65 ≤ N ≤ 128)| 16 | 16
502+
| _BitInt(N > 128) | RoundUp(N / 128) * 16 | 16
487503
|===
488504

489505
The alignment of `max_align_t` is 16.
@@ -493,6 +509,17 @@ The alignment of `max_align_t` is 16.
493509
Structs and unions are aligned to the alignment of their most strictly aligned
494510
member. The size of any object is a multiple of its alignment.
495511

512+
==== _BitInt (N)
513+
514+
`_BitInt (N)` is the type defined in C23, allow user to define an
515+
arbitrary-sized integer type, where N is a postive integer larger than zero.
516+
517+
`_BitInt(N)` types are stored in little-endian order in memory. Bits in each
518+
byte are allocated from low to high.
519+
520+
Unused bits of the `_BitInt (N)` are unspecified when stored in memory or
521+
register.
522+
496523
=== C/{Cpp} type representations
497524

498525
`char` is unsigned.

0 commit comments

Comments
 (0)