Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question on vector register convention #264

Open
kito-cheng opened this issue Apr 21, 2022 · 9 comments
Open

Question on vector register convention #264

kito-cheng opened this issue Apr 21, 2022 · 9 comments

Comments

@kito-cheng
Copy link
Collaborator

Review comment come from @anderslindgren-iar and Anders Berg(IAR) https://lists.riscv.org/g/tech-toolchain-runtime/message/344

Vector Register Convention

Anders: The vector register convention is not settled yet as far as I know, so this is only preliminary and can be changed later on. Should therefore be marked as such.

@kito-cheng kito-cheng added this to the Public Review for 1.0 milestone Apr 21, 2022
@jrtc27
Copy link
Collaborator

jrtc27 commented Apr 21, 2022

I don't think this is true? There may be some __attribute__((vectorcall)) equivalent, but this isn't changing for the standard default calling convention?

@kito-cheng
Copy link
Collaborator Author

My thought is the vector register convention IS settle down and we really need this to settle down right now, since we might use vector instructions with existing calling conventions without backward incompatibility. e.g. Using lp64d ABI but using vector instruction, and make this workable is important since current linux distro are using either rv64g/lp64d or rv64gc/lp64d, and we definitely don't want make vector instructions incompatible with that, that would be a disaster for the RISC-V ecosystem IMO.

But we DO need a better vector register convention for optimizing the vector code, and that will be a separate calling convention, and might require users to mark something like __attribute__((vectorcall)) or __attribute__((vectorcc)) like Jessica mentioned, and that is a high priority task of this year for psABI group.

And actually we have some preparation for the alternative vector calling convention in future: STO_RISCV_VARIANT_CC, that what we referenced the design from AArch64 SVE :P

@anderslindgren-iar
Copy link

anderslindgren-iar commented Apr 26, 2022 via email

@jrtc27
Copy link
Collaborator

jrtc27 commented Apr 26, 2022

This does not work with dynamic linking; you can have the attributes but they're totally useless.

@ptomsich
Copy link
Collaborator

My thought is the vector register convention IS settle down and we really need this to settle down right now, since we might use vector instructions with existing calling conventions without backward incompatibility. e.g. Using lp64d ABI but using vector instruction, and make this workable is important since current linux distro are using either rv64g/lp64d or rv64gc/lp64d, and we definitely don't want make vector instructions incompatible with that, that would be a disaster for the RISC-V ecosystem IMO.

Given that vectors has only been ratified in December (and the current psABI release should have been released before that), it is not surprising that the vector calling convention is not included.

Please punt this down the road and we'll keep this as a high-priority project for after this psABI release.
We can then aim to have a vector calling-convention addendum to psABI in Q4 (please note that the vector calling convention will have to go through the full DoD/Acceptance flow incl. a PoC).

@kito-cheng
Copy link
Collaborator Author

@anderslindgren-iar I can imagine that would be very useful under static linking model, and might not work well on dynamic linking model (PLT stuffs will silently clobber t1 and t3 even no lazy binding), but that's always free to use non-standard calling convention IF compiler* or user guarantee that will work correctly, however such flexible scheme is not needed to be included in psABI spec, psABI has provide STO_RISCV_VARIANT_CC let you mark this function/symbol is using non standard calling convention variant, and that's all what psABI need to provide.

Generally I feel that’s not a bad idea, but that’s just not need to be part of psABI spec unless we identify some variant is really useful and should be standardized, riscv-c-api-doc should be a better place for that, there is already few attribute has similar effect like __attribute__((naked)), __attribute__((interrupt)) to tell compiler use a non-standard calling convention.

So why vector calling convention variant is special and must become a standard calling convention variant, that because we need a standard variant for passing vector arguments, that's default one, and will used to optimize libm and some other libraries;

Of course toolchain vendors could provide other vector calling conventions to optimize code gen or library, but again, the responsibility is back to the user, user guarantee that will work correctly IF using non standard calling conventions (including std. c.c. variants).

Refs:

@AndersBerg-IAR
Copy link

AndersBerg-IAR commented Jun 27, 2022

I have a somewhat radical proposal for the vector calling convention.

  • All vector registers/properties should be callee saved.
  • All vector registers can be used as function arguments (including returned result). In such cases the caller is responsible for saving the used argument registers.

By using such a calling convention, one do not need to know if a function (tree) is using vector extensions or not.
The number of vector registers used for passing arguments, is however debatable.

@jrtc27
Copy link
Collaborator

jrtc27 commented Jun 27, 2022

I have a somewhat radical proposal for the vector calling convention.

  • All vector registers/properties should be callee saved.
  • All vector registers can be used as function arguments (including returned result). In such cases the caller is responsible for saving the used argument registers.

This is what is already there today (other than the VXRM/VXSAT debate).

By using such a calling convention, one do not need to know if a function (tree) is using vector extensions or not.

This is not true when dynamic linking is involved, and is why STO_RISCV_VARIANT_CC. Please see the many past discussions about that.

The number of vector registers used for passing arguments, is however debatable.

@kito-cheng
Copy link
Collaborator Author

I have a somewhat radical proposal for the vector calling convention.

  • All vector registers/properties should be callee saved.

All callee save will increasing the initial cost for using vector operations, and in most case vector operation are happened on leaf function, so callee save might be a potential issue.

e.g. memcpy use 2 m8 register to load and store values, then we MUST store/restore 16 vector resister at prologue/epilogue.

  • All vector registers can be used as function arguments (including returned result). In such cases the caller is responsible for saving the used argument registers.

That's a radical but interesting idea, that sounds like kind of dynamic scheme, should be suitable for IPO/LTO, but I guess need more investigation if we consider treat it as a generic vector calling conventions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants