Skip to content

Commit b1c9cd0

Browse files
committed
Function attribute for standard fixed-length vector calling convention variant
Fixed-length vector are passed via general purposed register or memory within current ABI design, we proposed a standard fixed-length vector calling convention variant for passing the fixed-length vector via vector register. This is the syntax part in the proposal, further detail for that calling convention variant see riscv-non-isa/riscv-elf-psabi-doc#418
1 parent 84f4288 commit b1c9cd0

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

riscv-c-api.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,48 @@ __attribute__((target("arch=+v"))) int foo(void) { return 0; }
318318
__attribute__((target("arch=+zbb"))) int foo(void) { return 1; }
319319
```
320320
321+
### `__attribute__((riscv_vls_cc))`
322+
323+
Functions declared with this attribute will utilize the standard fixed-length
324+
vector calling convention variant instead of the default calling convention
325+
defined by the ABI. This variant aims to pass fixed-length vectors via vector
326+
registers, if possible, rather than through general-purpose registers.
327+
328+
The attribute can accept an optional unsigned integer argument within the value
329+
range of `[32, 65536]`, which must be a power of two. This argument specifies
330+
the ABI_VLEN. If not provided, the default value is set to 128. However, this
331+
default value can be changed via command-line options or pragma directives.
332+
333+
```c
334+
// foo uses the standard fixed-length vector calling convention variant with the
335+
// default ABI_VLEN, which is 128.
336+
void foo __attribute__((riscv_vls_cc));
337+
// bar uses the standard fixed-length vector calling convention variant with
338+
// ABI_VLEN=256.
339+
void bar __attribute__((riscv_vls_cc(256)));
340+
```
341+
342+
One constraint on ABI_VLEN is that it must be larger than or equal to the
343+
minimal VLEN, as specified by the `-march` option through the `zvl*b` extension,
344+
pragma directives, or the target attribute.
345+
346+
```c
347+
// foo is declared to use the standard fixed-length vector calling convention variant
348+
// with ABI_VLEN=256. Compilation will succeed with -march=rv64gcv_zvl256b, as it
349+
// supports VLEN of 256. However, compiling with -march=rv64gcv will result in an error,
350+
// because rv64gcv's VLEN is 128, which is less than the specified ABI_VLEN of 256.
351+
void foo __attribute__((riscv_vls_cc(256)));
352+
353+
// bar uses the standard fixed-length vector calling convention variant with
354+
// ABI_VLEN=256 and also specifies the minimal VLEN as 256 using the target
355+
// attribute.
356+
void bar __attribute__((riscv_vls_cc(256))) __attribute__((target("arch=+zvl256b")));
357+
```
358+
359+
NOTE: Invoking a function with an incorrect `ABI_VLEN` will cause parameters to
360+
be passed incorrectly. Users should ensure the consistency of `ABI_VLEN`,
361+
especially when using a non-default `ABI_VLEN`.
362+
321363
## Intrinsic Functions
322364
323365
Intrinsic functions (or intrinsics or built-ins) are expanded into instruction sequences by compilers.

0 commit comments

Comments
 (0)