-
Notifications
You must be signed in to change notification settings - Fork 50
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 2 commits
c0f6270
febba92
4dbcbee
6db8eeb
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,54 @@ 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+`. | ||
|
|
||
| When a specific profile is targeted, the compiler defines (with value 1) not only the exact profile macro, | ||
| but also all compatible profile macros. This includes: | ||
|
|
||
cmuellner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 1. The exact profile macro for the targeted profile | ||
| 2. Lower privilege mode variants (e.g., when targeting an S-mode profile, the corresponding U-mode profile macro is also defined, since S-mode is a superset of U-mode) | ||
| 3. All previous compatible profile versions | ||
|
Contributor
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. Does this include profiles that are compatible but not from the same profile family. Like RVI20 is subset of all defined RVA profiles.
Author
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. Yes |
||
|
|
||
| For example, when compiling with `-march=rva23s64`, the following macros are defined: | ||
|
|
||
| - `+__riscv_rva23s64+` | ||
| - `+__riscv_rva23u64+` | ||
| - `+__riscv_rva22s64+` | ||
| - `+__riscv_rva22u64+` | ||
| - `+__riscv_rva20s64+` | ||
| - `+__riscv_rva20u64+` | ||
|
Contributor
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. So __rvi20u64 should be listed here? Is rvb23s64/u64 also a subset of rva23s64?
Author
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. Yeah, __rvi20u64 should be there. Haven't checked rvb23, but I should add an ellipsis to show any profile with a subset of extensions should define its macro too. |
||
|
|
||
| This behavior ensures that code guarded with a profile macro will work correctly on any future | ||
| profile that is compatible with it, providing better forward compatibility and code portability. | ||
|
|
||
| Example usage: | ||
|
|
||
| [source, C] | ||
| ---- | ||
| #ifdef __riscv_rva23u64 | ||
| // This code will execute on RVA23U64, RVA23S64, and any future | ||
| // profiles compatible with RVA23U64 | ||
| #endif | ||
|
|
||
| #ifdef __riscv_rvi20u32 | ||
| // This code will execute on RVI20U32 and any future | ||
| // profiles compatible with RVI20U32 | ||
| #endif | ||
| ---- | ||
|
|
||
| === ABI Related Preprocessor Definitions | ||
|
|
||
| .ABI Related Preprocessor Definitions | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.