From b1c9cd069a683c20758bcaad0e5c98ccc26bbf8d Mon Sep 17 00:00:00 2001 From: Kito Cheng Date: Fri, 2 Feb 2024 17:15:30 +0800 Subject: [PATCH 1/3] 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 https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/418 --- riscv-c-api.md | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/riscv-c-api.md b/riscv-c-api.md index c2300f6..c9f9b84 100644 --- a/riscv-c-api.md +++ b/riscv-c-api.md @@ -318,6 +318,48 @@ __attribute__((target("arch=+v"))) int foo(void) { return 0; } __attribute__((target("arch=+zbb"))) int foo(void) { return 1; } ``` +### `__attribute__((riscv_vls_cc))` + +Functions declared with this attribute will utilize the standard fixed-length +vector calling convention variant instead of the default calling convention +defined by the ABI. This variant aims to pass fixed-length vectors via vector +registers, if possible, rather than through general-purpose registers. + +The attribute can accept an optional unsigned integer argument within the value +range of `[32, 65536]`, which must be a power of two. This argument specifies +the ABI_VLEN. If not provided, the default value is set to 128. However, this +default value can be changed via command-line options or pragma directives. + +```c +// foo uses the standard fixed-length vector calling convention variant with the +// default ABI_VLEN, which is 128. +void foo __attribute__((riscv_vls_cc)); +// bar uses the standard fixed-length vector calling convention variant with +// ABI_VLEN=256. +void bar __attribute__((riscv_vls_cc(256))); +``` + +One constraint on ABI_VLEN is that it must be larger than or equal to the +minimal VLEN, as specified by the `-march` option through the `zvl*b` extension, +pragma directives, or the target attribute. + +```c +// foo is declared to use the standard fixed-length vector calling convention variant +// with ABI_VLEN=256. Compilation will succeed with -march=rv64gcv_zvl256b, as it +// supports VLEN of 256. However, compiling with -march=rv64gcv will result in an error, +// because rv64gcv's VLEN is 128, which is less than the specified ABI_VLEN of 256. +void foo __attribute__((riscv_vls_cc(256))); + +// bar uses the standard fixed-length vector calling convention variant with +// ABI_VLEN=256 and also specifies the minimal VLEN as 256 using the target +// attribute. +void bar __attribute__((riscv_vls_cc(256))) __attribute__((target("arch=+zvl256b"))); +``` + +NOTE: Invoking a function with an incorrect `ABI_VLEN` will cause parameters to +be passed incorrectly. Users should ensure the consistency of `ABI_VLEN`, +especially when using a non-default `ABI_VLEN`. + ## Intrinsic Functions Intrinsic functions (or intrinsics or built-ins) are expanded into instruction sequences by compilers. From 9c2a62466d440d0ced5f8e0a13bc92b75c9b6f68 Mon Sep 17 00:00:00 2001 From: Kito Cheng Date: Fri, 2 Feb 2024 21:19:26 +0800 Subject: [PATCH 2/3] Make the format consistent --- riscv-c-api.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/riscv-c-api.md b/riscv-c-api.md index c9f9b84..4e94c72 100644 --- a/riscv-c-api.md +++ b/riscv-c-api.md @@ -327,7 +327,7 @@ registers, if possible, rather than through general-purpose registers. The attribute can accept an optional unsigned integer argument within the value range of `[32, 65536]`, which must be a power of two. This argument specifies -the ABI_VLEN. If not provided, the default value is set to 128. However, this +the `ABI_VLEN`. If not provided, the default value is set to 128. However, this default value can be changed via command-line options or pragma directives. ```c @@ -339,8 +339,8 @@ void foo __attribute__((riscv_vls_cc)); void bar __attribute__((riscv_vls_cc(256))); ``` -One constraint on ABI_VLEN is that it must be larger than or equal to the -minimal VLEN, as specified by the `-march` option through the `zvl*b` extension, +One constraint on `ABI_VLEN` is that it must be larger than or equal to the +minimal `VLEN`, as specified by the `-march` option through the `zvl*b` extension, pragma directives, or the target attribute. ```c From e83c8c741db2a695fe364b466781dd5e569e0f9e Mon Sep 17 00:00:00 2001 From: Kito Cheng Date: Fri, 2 Feb 2024 21:19:35 +0800 Subject: [PATCH 3/3] Add C++11 and C23 style syntax for riscv_vls_cc --- riscv-c-api.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/riscv-c-api.md b/riscv-c-api.md index 4e94c72..e1c4c1d 100644 --- a/riscv-c-api.md +++ b/riscv-c-api.md @@ -320,6 +320,15 @@ __attribute__((target("arch=+zbb"))) int foo(void) { return 1; } ### `__attribute__((riscv_vls_cc))` +Supported Syntaxes: +| Style | Syntax | +| ------ | --------------------------------------------------------------------- | +| GNU | `__attribute__((riscv_vls_cc)))`, `__attribute__((riscv_vls_cc(N))))``*` | +| C++11 | `[[riscv::vls_cc]]`, `[[riscv::vls_cc(N)]]``*` | +| C23 | `[[riscv::vls_cc]]`, `[[riscv::vls_cc(N)]]``*` | + +`*` N is the the `ABI_LEN`. + Functions declared with this attribute will utilize the standard fixed-length vector calling convention variant instead of the default calling convention defined by the ABI. This variant aims to pass fixed-length vectors via vector