Closed kito-cheng closed 10 months ago
cc. @palmer-dabbelt @JeffreyALaw @preames @topperc @rofirrim
I think @lhtin should be aware of this
Therefore, this PR proposes that fixed-length vectors should always be passed by reference.
We also plan to submit another proposal to address the issue of passing fixed-length vectors via vector registers.
Why are there two proposals for fixed-length vectors? My suggestion is to explicitly forbid the passing of fixed-length vectors first, thus, it will be compatible with the proposal that passes fixed-length vectors via vector registers. Thus, it is guaranteed that there will be no compatibility problems when a new proposal is put forward later.
For example, one part of the program is compiled before the new proposal is made, and the other part is compiled by the compiler that used the new proposal. If fixed-length vector was allowed to pass through pointers before, and now it is passed through vector registers, then there will be a problem that callers and callees maybe not aligned if they are not compiled at the same time.
Why are there two proposals for fixed-length vectors? My suggestion is to explicitly forbid the passing of fixed-length vectors first
The problem is that will become a hard ABI breakage and also make fixed length vector not able used without vector extension - some project will be broken immediately since rv64gc still default for most RISC-V Linux distribution.
it will be compatible with the proposal that passes fixed-length vectors via vector registers. Thus, it is guaranteed that there will be no compatibility problems when a new proposal is put forward later.
My thought to made it require explicitly function attribute to make it passed via vector register - not ideal, but compatible with existing ABI.
Few more description why we did kind of hard break to scalable vector but not doing same approach for fixed-length vectors: scalable is only a available when vector extension is present, but fixed-length vector can be used even vector extension is not available, it would cause much more problem to make it incompatible.
Quick note from LLVM sync up meeting: it's GCC bug, we should fix on GCC land, it will passing in ref when vector enabled.
Drop this PR, will create another PR to clarify fixed length vector should follow aggregate's rule
Previously, there was no mention of fixed-length vectors in the psABI. Unfortunately, GCC and Clang have implemented support for fixed-length vectors differently for a long time. We should address this soon, as the RISC-V ecosystem is expanding and optimizing programs with fixed-length vectors, especially with the upcoming vector extension, is becoming more common.
There are two options for passing arguments with fixed-length vectors:
GCC uses the first method, while Clang uses the second.
The drawback of the second option is the extra overhead required when generating code with vector instructions.
Consider the following code as an example. GCC passes
a
andb
by reference, using thea0
anda1
registers to pass their addresses. Clang, however, passesa
andb
through integer registers: usinga0
anda1
to passa
;a2
anda3
to passb
.The code generation with vector extension for pass-by-reference is straightforward: load the value from the pointer, perform the operation, and then store the result.
However, the code generation with the vector extension for the struct approach is quite complicated. It might use
vslide1down.vx
orvmv.v.s
to move data between integer and vector registers, which can generally result in poor performance.Therefore, this PR proposes that fixed-length vectors should always be passed by reference.
We also plan to submit another proposal to address the issue of passing fixed-length vectors via vector registers.