Skip to content

Commit 6001333

Browse files
committed
[Vector ABI] Type size and alignment for vector types.
The issue of Vector alignment is discussed in #347. It is mentioned that aligning to 128 bytes might deliver better performance on some RISC-V cores, but this behavior could lead to considerable stack wastage on zve32 and zve64 cores. For instance, in order to ensure a vector value in the stack conforms to the ABI specification, we could potentially waste up to 96 bits per vector object in stack for zve32, and the performance difference isn't always evident across all core implementations. Therefore, this proposal sets the alignment of vector types to element alignment, to avoid wasting a significant amount of stack space in zve32 and zve64 configurations. Also, since the ABI only specify the minimum alignment and doesn't limit the compiler from adopting higher alignment for specific CPUs. Fix #347.
1 parent 9401f64 commit 6001333

File tree

2 files changed

+118
-1
lines changed

2 files changed

+118
-1
lines changed

riscv-cc.adoc

+91
Original file line numberDiff line numberDiff line change
@@ -555,3 +555,94 @@ The following definitions apply for all ABIs defined in this document. Here
555555
there is no differentiation between ILP32 and LP64 ABIs.
556556

557557
`wchar_t` is signed. `wint_t` is unsigned.
558+
559+
=== Vector type sizes and alignments
560+
561+
This section defines the sizes and alignments for the vector types defined in
562+
the _RISC-V Vector Extension Intrinsic Document_<<rvv-intrinsic-doc>>.
563+
The actual size of each type is determined by the hardware configuration, which
564+
is based on the content of the `vlenb` register.
565+
566+
There are two classes of vector types: the vector mask types and the vector
567+
data types.
568+
569+
+
570+
.Type sizes and alignments for vector mask types
571+
[cols="4,>2,>3"]
572+
[width=60%]
573+
|===
574+
| Type | Size (Bytes) | Alignment (Bytes)
575+
576+
| vbool1_t | VLENB | 1
577+
| vbool2_t | VLENB | 1
578+
| vbool4_t | VLENB | 1
579+
| vbool8_t | VLENB | 1
580+
| vbool16_t | VLENB | 1
581+
| vbool32_t | VLENB | 1
582+
| vbool64_t | VLENB | 1
583+
|===
584+
585+
+
586+
.Type sizes and alignments for vector data types
587+
[cols="4,>2,>3"]
588+
[width=60%]
589+
|===
590+
| Type | Size (Bytes) | Alignment (Bytes)
591+
592+
| vint8mf8_t | VLENB / 8 | 1
593+
| vuint8mf8_t | VLENB / 8 | 1
594+
| vint8mf4_t | VLENB / 4 | 1
595+
| vuint8mf4_t | VLENB / 4 | 1
596+
| vint8mf2_t | VLENB / 2 | 1
597+
| vuint8mf2_t | VLENB / 2 | 1
598+
| vint8m1_t | VLENB | 1
599+
| vuint8m1_t | VLENB | 1
600+
| vint8m2_t | VLENB * 2 | 1
601+
| vuint8m2_t | VLENB * 2 | 1
602+
| vint8m4_t | VLENB * 4 | 1
603+
| vuint8m4_t | VLENB * 4 | 1
604+
| vint8m8_t | VLENB * 8 | 1
605+
| vuint8m8_t | VLENB * 8 | 1
606+
| vint16mf4_t | VLENB / 4 | 2
607+
| vuint16mf4_t | VLENB / 4 | 2
608+
| vint16mf2_t | VLENB / 2 | 2
609+
| vuint16mf2_t | VLENB / 2 | 2
610+
| vint16m1_t | VLENB | 2
611+
| vuint16m1_t | VLENB | 2
612+
| vint16m2_t | VLENB * 2 | 2
613+
| vuint16m2_t | VLENB * 2 | 2
614+
| vint16m4_t | VLENB * 4 | 2
615+
| vuint16m4_t | VLENB * 4 | 2
616+
| vint16m8_t | VLENB * 8 | 2
617+
| vuint16m8_t | VLENB * 8 | 2
618+
| vint32mf2_t | VLENB / 2 | 4
619+
| vuint32mf2_t | VLENB / 2 | 4
620+
| vfloat32mf2_t | VLENB / 2 | 4
621+
| vint32m1_t | VLENB | 4
622+
| vuint32m1_t | VLENB | 4
623+
| vfloat32m1_t | VLENB | 4
624+
| vint32m2_t | VLENB * 2 | 4
625+
| vuint32m2_t | VLENB * 2 | 4
626+
| vfloat32m2_t | VLENB * 2 | 4
627+
| vint32m4_t | VLENB * 4 | 4
628+
| vuint32m4_t | VLENB * 4 | 4
629+
| vfloat32m4_t | VLENB * 4 | 4
630+
| vint32m8_t | VLENB * 8 | 4
631+
| vuint32m8_t | VLENB * 8 | 4
632+
| vfloat32m8_t | VLENB * 8 | 4
633+
| vint64m1_t | VLENB | 8
634+
| vuint64m1_t | VLENB | 8
635+
| vfloat64m1_t | VLENB | 8
636+
| vint64m2_t | VLENB * 2 | 8
637+
| vuint64m2_t | VLENB * 2 | 8
638+
| vfloat64m2_t | VLENB * 2 | 8
639+
| vint64m4_t | VLENB * 4 | 8
640+
| vuint64m4_t | VLENB * 4 | 8
641+
| vfloat64m4_t | VLENB * 4 | 8
642+
| vint64m8_t | VLENB * 8 | 8
643+
| vuint64m8_t | VLENB * 8 | 8
644+
| vfloat64m8_t | VLENB * 8 | 8
645+
|===
646+
647+
NOTE: The vector mask types utilize a portion of the space, while the remaining
648+
content may be undefined, both in the register and in memory.

riscv-elf.adoc

+27-1
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,35 @@ any vector registers.
142142

143143
{Cpp} name mangling for RISC-V follows
144144
the _Itanium {Cpp} ABI_ <<itanium-cxx-abi>>;
145-
there are no RISC-V specific mangling rules.
145+
there are no RISC-V specific mangling rules,
146+
except for the vector data types and vector masking types, which are defined in
147+
the following section.
146148

147149
See the "Type encodings" section in _Itanium {Cpp} ABI_
148150
for more detail on how to mangle types. Note that `__bf16` is mangled in the
149151
same way as `std::bfloat16_t`.
150152

153+
=== Name Mangling for Vector Data Types and Vector Masking Types
154+
155+
The vector data types and vector masking types, as defined in the section
156+
<<Vector type sizes and alignments>>, are treated as vendor-extended types in
157+
the _Itanium {Cpp} ABI_ <<itanium-cxx-abi>>. The mangled name for these types
158+
employs the internal name, which is prefixed by `u`, and then followed by the
159+
length of the type name."
160+
161+
For example:
162+
163+
[,c]
164+
----
165+
void foo(vint8m1_t x);
166+
----
167+
168+
is mangled as
169+
[,c]
170+
----
171+
_Z3foou14__rvv_int8m1_t
172+
----
173+
151174
== ELF Object Files
152175

153176
The ELF object file format for RISC-V follows the
@@ -1637,3 +1660,6 @@ RISC-V International.
16371660

16381661
* [[[riscv-zc-extension-group]]] "ZC* extension specification"
16391662
https://github.com/riscv/riscv-code-size-reduction
1663+
1664+
* [[[rvv-intrinsic-doc]]] "RISC-V Vector Extension Intrinsic Document"
1665+
https://github.com/riscv-non-isa/rvv-intrinsic-doc

0 commit comments

Comments
 (0)