-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -128,6 +128,37 @@ For example: | |
|
|
||
| - F-extension v2.2 will define `+__riscv_f+` as `2002000`. | ||
|
|
||
| === Architecture Profile Test Macros | ||
|
|
||
| Architecture profile test macros allow checking whether a specific RISC-V profile | ||
| is in effect at compile-time. These macros enable developers to conditionally compile code | ||
| based on the target profile. | ||
|
|
||
| The naming rule for profile test macros is `+__riscv_<profile_name>+`, | ||
| where `<profile_name>` is the lowercase profile identifier. | ||
|
|
||
| Examples: | ||
|
|
||
| - 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. | ||
|
|
||
| Example usage: | ||
|
|
||
| [source, C] | ||
| ---- | ||
| #ifdef __riscv_rva23u64 | ||
| // Code specific to the RVA23U64 profile | ||
| #endif | ||
|
|
||
| #ifdef __riscv_rvi20u32 | ||
| // Code specific to the RVI20U32 profile | ||
| #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 commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the review, I do miss the compatibility issue. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
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 This seems little bit mess, but that could guarantee the code guarded with |
||
|
|
||
| === ABI Related Preprocessor Definitions | ||
|
|
||
| .ABI Related Preprocessor Definitions | ||
|
|
||
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:
Uh oh!
There was an error while loading. Please reload this page.
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.
Yes, if they are part of the profile definition.
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.
don't affect profile matching.