RISC-V: Improvements of inline assembly uses #1921
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit performs various improvements (better register allocation, less register clobbering on the worst case and better readability) of RISC-V inline assembly use cases.
Note that it does not change the
p
module (which defines the "P" extension draft instructions but very likely to change).lateout
as possible.Unlike
out(reg)
andin(reg)
pair,lateout(reg)
andin(reg)
can share the same register because they state that the late-output register is written after all the reads are performed. It can improve register allocation.preserves_flags
option as possible.While RISC-V doesn't have regular condition codes, RISC-V inline assembly in the Rust language assumes that some registers (mainly vector state registers) may be overwritten by default. By adding
preserves_flags
to the intrinsics corresponding instructions without overwriting them, it can minimize register clobbering on the worst case.As
asm!
declares an action and it doesn't return a value by itself, it would be better to have trailing semicolon to denote that anasm!
call is effectively a statement.asm!
calls multi-lined.rustfmt
makes some simple (yet long)asm!
calls multi-lined but it does not perform formatting of complexasm!
calls with inputs and/or outputs. To keep consistency, it makes most of theasm!
calls multi-lined.