-
Notifications
You must be signed in to change notification settings - Fork 48
Document Architecture Profile Test Macros #128
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
base: main
Are you sure you want to change the base?
Conversation
Add documentation for RISC-V profile test macros that enable compile-time profile detection (e.g., __riscv_rva23u64).
- The test macro for the RVA23U64 profile is `+__riscv_rva23u64+`. | ||
- The test macro for the RVI20U32 profile is `+__riscv_rvi20u32+`. | ||
|
||
The profile macro is defined (with value 1) when the compiler detects that the enabled extensions match a specific RISC-V profile. |
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.
The word "match" leaves some room for interpretation:
- Are the S* and H* extensions of a profile considered in the match?
- What if additional extensions beyond those in the profile are enabled?
- What if vendor extensions are enabled?
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.
Are the S* and H* extensions of a profile considered in the match?
Yes, if they are part of the profile definition.
What if additional extensions beyond those in the profile are enabled?
Additional extensions do not prevent a profile match. as long as all extensions required by the profile are present, this matched profile macro will be defined.
What if vendor extensions are enabled?
don't affect profile matching.
Thanks for the PR! I guess the use case for this is to test for profiles instead of several individual extensions at compile time. Do you know if these macros exist in LLVM? |
Exactly! That's precisely the intention.
AFAIK, they don't exist in LLVM yet. However, I have prepared a patch for LLVM as well and plan to submit it later. |
#endif | ||
---- | ||
|
||
NOTE: The compiler selects the best matching profile based on the maximum number of matching extensions when multiple profiles could apply. |
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.
Doesn't this create a compatibility issue.
Developer writes code for RVA23U64 today.
In the future the code is compiled with RVA30U64 that is superset of RVA23U64. __riscv_rva23u64 macro is not defined because __riscv_rva30u64. Code no longer does the correct thing and must be updated to check for __riscv_rva30u64 OR __riscv_rva23u64.
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.
Thanks for the review, I do miss the compatibility issue.
maybe this better ? anyway, need reconsider the macro definitions.
#define __riscv_profile_number 23
#define __riscv_profile_class 'A'
#define __riscv_xlen 64
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.
#define __riscv_profile_class 'A'
https://github.com/riscv/riscv-profiles/blob/main/src/profiles.adoc#34-profile-naming-convention
Single letter might not work because spec say:
"A specific profile family name string. Initially a single letter (I, M, or A), but later profiles may have longer family name strings."
Also rvX30u64 might also a super-set of rva23u64...so I would prefer to define every profile macro if the extension meet the requirement of that profile.
That means -march=rva23s64 will define __riscv_rva23s64
, __riscv_rva23u64
, __riscv_rvi20u64
, __riscv_rva20u64
, __riscv_rva20s64
, __riscv_rva22u64
and __riscv_rva22s64
.
This seems little bit mess, but that could guarantee the code guarded with __riscv_rva23u64
could work on any future version which compatible with that.
Do you have an example use case for this? I wouldn't expect one piece of code to be dependent on everything in a profile. It's effectively listing a bunch of requirements that probably don't apply. This may make it hard to understand the true requirements in the future if the code needs to be updated for a new profile with fewer extensions. We've already seen something similar with Zmmul and Zca. Code that used |
have no realworld example.
Agree.
You’re right, but some developers may prefer the profile macro for convenience. maybe leave the implementation up to them ? |
Add documentation for RISC-V profile test macros that enable compile-time profile detection (e.g., __riscv_rva23u64).
This aligns with the GCC patch that implements RISC-V profile macro support in the compiler.