riscv-non-isa / riscv-c-api-doc

Documentation of the RISC-V C API
https://jira.riscv.org/browse/RVG-4
Creative Commons Attribution 4.0 International
68 stars 38 forks source link

Function attribute for standard vector calling convention variant: riscv_vector_cc #67

Closed kito-cheng closed 4 months ago

kito-cheng commented 7 months ago

Standard vector calling convention variant has landed in psABI now, and the implementation also merged into GCC trunk, LLVM part are also under reviewing, and this attribute has mentioned during the discussion, but seems like we don't document that yet.


Standard vector calling convention variant will only enabled when function has vector argument or returing value by default, however user may also want to invoke function without that during a vectorized loop at some situation, but it will cause a huge performance penalty due to vector register store/restore.

So user can declare function with this riscv_vector_cc attribute like below, that could enforce function will use standard vector calling convention variant.

void foo() __attribute__((riscv_vector_cc));
[[riscv::vector_cc]] void foo(); // For C++11 and C23
kito-cheng commented 7 months ago

ChangeLog:

sorear commented 7 months ago

(copying my comment from #68 since it applies to both)

Stylistically, since this is a well-defined RISC-V specific ABI attribute independent of any GNU extensions, I wonder if it should be [[riscv:vector_cc]] instead of [[gnu:riscv_vector_cc]]. Probably not since other architectures still seem to be using attributes in the compiler-specific namespace?

I believe that this needs to be included in C++ function pointer mangling to support natural uses (although this doesn't work on aarch64). Do the rules for that need to be specified here?

LGTM otherwise.

kito-cheng commented 7 months ago

Update:

kito-cheng commented 7 months ago

Added C++11 and C23 style syntax.

Let me ask our folks to implement that in LLVM and GCC.

kito-cheng commented 4 months ago

GCC and clang/LLVM implementation has merged into trunk[1][2]

[1] https://github.com/gcc-mirror/gcc/commit/4547628c78618616595f4b5e1bef2b582c77793d [2] https://github.com/llvm/llvm-project/pull/77560