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
Rework riscv -march and -mabi detection #796
base: main
Are you sure you want to change the base?
Conversation
src/lib.rs
Outdated
|
||
// If riscv32gc-* or riscv64gc-* then double-float ABI, | ||
// otherwise use soft-float ABI. | ||
let float_abi = if arch.contains("g") { "d" } else { "" }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks fragile to me, maybe we could use arch.ends_with("gc")
or contains("gc")
at least.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My reasoning is that g
means imafd_zifencei_zicsr
, so it implies d
for double
, which is required for double float ABI. Currently it seems (see table in top post) that rustc does use lp64d
/ilp32d
for all targets with d
ouble. Maybe I can change the code to detect d
or g
and/or change the comment to reflect this reasoning better?
I guess I'll also change it so that it handles e.g. riscv64imac_zsomething
with a multi-letter extension tha happens to contain g
. Not sure if something other than an ISA/-march
string appears here though tbh.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the RISC-V Unprivileged Specification RISC-V ISA can be decided from ISA string, which indicates that if it has D inside, the target must support double length floating points; and G means that it has IMAFD and Zifencei (F indicates Zicsr). Using C here would not cover this case correctly, as that C doesn't imply G or D.
It is possible to have an RVD implementation without RVC, for example disabling C instruction set on RV64GC platform (which is sometimes common on embedded SoC or developing new SoCs); detecting GC for D will not be correct in those cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a bunch of comments explaining the logic, and also updated the detection logic to handle the possible future existence of multi-letter extensions, so it won't get confused by e.g. riscv64imac_zsomething
containing a g
.
989026d
to
23303fc
Compare
Instead of adding cases for all the operating systems, Use target architecture directly as ISA string, replacing "riscv" with "rv", and detect floating point ABI based on support for the D and F extensions. Fixes rust-lang#795
23303fc
to
6a1aff2
Compare
Additional justification for inferring the ABI: https://github.com/riscv-non-isa/riscv-toolchain-conventions#specifying-the-target-isa-with--march
Since the Rust target implies I can add a comment linking to it, if the maintainers are okay with this logic in general. |
Currently all the riscv*gc targets use the 'd' double-float ABI, and
soft-float otherwise. There's no need to detect the operating system
type. Fixes #795.
I'm not sure how correct this is. I've checked all the targets on version
1.69.0-nightly (ef934d9b6 2023-02-08)
with this script:Which gives:
Also I'm not sure whether to add tests or not. Please advise on this.