Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions src/c-api.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,64 @@ 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. These feature macros are optional, and compilers
that support them provide a `+__riscv_profile_test+` macro (with the value `1`).

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+`.

All profile test macros are defined with the value `1`:

[source, C]
----
#define __riscv_rva23u64 1
----

When a specific profile is targeted, the compiler defines not only the exact profile macro,
but also all compatible profile macros. This includes:

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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The 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+`
Copy link
Copy Markdown
Contributor

@topperc topperc Nov 21, 2025

Choose a reason for hiding this comment

The 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?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The 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.

- `+__riscv_rvi20u64+`
- ... (and any other profiles whose extension set is a subset)

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
Expand Down
Loading