Skip to content

Commit 9261fcf

Browse files
authored
Rollup merge of #145417 - a4lg:riscv-arch-platform-guide-ch2, r=Amanieu
std_detect: RISC-V platform guide documentation This is practically a revert of a revert, making the commit e907456b2e10622ccd854a3bba8d02ce170b5dbb on `stdarch` come around again with minor fixes, enhancements and adjustments. An excerpt from the original commit message follows: Since there's no architectural feature detection on RISC-V (unlike `CPUID` on x86 architectures and some system registers on Arm/AArch64), runtime feature detection entirely depends on the platform-specific facility. As a result, availability of each feature heavily depends on the platform and its version. To help users make a decision for feature checking on a RISC-V system, this commit adds a platform guide with minimum supported platform versions.
2 parents 5a0c938 + bec399e commit 9261fcf

File tree

1 file changed

+114
-83
lines changed
  • library/std_detect/src/detect/arch

1 file changed

+114
-83
lines changed

library/std_detect/src/detect/arch/riscv.rs

Lines changed: 114 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -37,90 +37,121 @@ features! {
3737
///
3838
/// # Unprivileged Specification
3939
///
40-
/// The supported ratified RISC-V instruction sets are as follows:
40+
/// The supported ratified RISC-V instruction sets are as follows (OS
41+
/// columns denote runtime feature detection support with or without the
42+
/// minimum supported version):
4143
///
42-
/// * RV32E: `"rv32e"`
43-
/// * RV32I: `"rv32i"`
44-
/// * RV64I: `"rv64i"`
45-
/// * A: `"a"`
46-
/// * Zaamo: `"zaamo"`
47-
/// * Zalrsc: `"zalrsc"`
48-
/// * B: `"b"`
49-
/// * Zba: `"zba"`
50-
/// * Zbb: `"zbb"`
51-
/// * Zbs: `"zbs"`
52-
/// * C: `"c"`
53-
/// * Zca: `"zca"`
54-
/// * Zcd: `"zcd"` (if D is enabled)
55-
/// * Zcf: `"zcf"` (if F is enabled on RV32)
56-
/// * D: `"d"`
57-
/// * F: `"f"`
58-
/// * M: `"m"`
59-
/// * Q: `"q"`
60-
/// * V: `"v"`
61-
/// * Zve32x: `"zve32x"`
62-
/// * Zve32f: `"zve32f"`
63-
/// * Zve64x: `"zve64x"`
64-
/// * Zve64f: `"zve64f"`
65-
/// * Zve64d: `"zve64d"`
66-
/// * Zicbom: `"zicbom"`
67-
/// * Zicboz: `"zicboz"`
68-
/// * Zicntr: `"zicntr"`
69-
/// * Zicond: `"zicond"`
70-
/// * Zicsr: `"zicsr"`
71-
/// * Zifencei: `"zifencei"`
72-
/// * Zihintntl: `"zihintntl"`
73-
/// * Zihintpause: `"zihintpause"`
74-
/// * Zihpm: `"zihpm"`
75-
/// * Zimop: `"zimop"`
76-
/// * Zabha: `"zabha"`
77-
/// * Zacas: `"zacas"`
78-
/// * Zawrs: `"zawrs"`
79-
/// * Zfa: `"zfa"`
80-
/// * Zfbfmin: `"zfbfmin"`
81-
/// * Zfh: `"zfh"`
82-
/// * Zfhmin: `"zfhmin"`
83-
/// * Zfinx: `"zfinx"`
84-
/// * Zdinx: `"zdinx"`
85-
/// * Zhinx: `"zhinx"`
86-
/// * Zhinxmin: `"zhinxmin"`
87-
/// * Zcb: `"zcb"`
88-
/// * Zcmop: `"zcmop"`
89-
/// * Zbc: `"zbc"`
90-
/// * Zbkb: `"zbkb"`
91-
/// * Zbkc: `"zbkc"`
92-
/// * Zbkx: `"zbkx"`
93-
/// * Zk: `"zk"`
94-
/// * Zkn: `"zkn"`
95-
/// * Zknd: `"zknd"`
96-
/// * Zkne: `"zkne"`
97-
/// * Zknh: `"zknh"`
98-
/// * Zkr: `"zkr"`
99-
/// * Zks: `"zks"`
100-
/// * Zksed: `"zksed"`
101-
/// * Zksh: `"zksh"`
102-
/// * Zkt: `"zkt"`
103-
/// * Zvbb: `"zvbb"`
104-
/// * Zvbc: `"zvbc"`
105-
/// * Zvfbfmin: `"zvfbfmin"`
106-
/// * Zvfbfwma: `"zvfbfwma"`
107-
/// * Zvfh: `"zvfh"`
108-
/// * Zvfhmin: `"zvfhmin"`
109-
/// * Zvkb: `"zvkb"`
110-
/// * Zvkg: `"zvkg"`
111-
/// * Zvkn: `"zvkn"`
112-
/// * Zvkned: `"zvkned"`
113-
/// * Zvknha: `"zvknha"`
114-
/// * Zvknhb: `"zvknhb"`
115-
/// * Zvknc: `"zvknc"`
116-
/// * Zvkng: `"zvkng"`
117-
/// * Zvks: `"zvks"`
118-
/// * Zvksed: `"zvksed"`
119-
/// * Zvksh: `"zvksh"`
120-
/// * Zvksc: `"zvksc"`
121-
/// * Zvksg: `"zvksg"`
122-
/// * Zvkt: `"zvkt"`
123-
/// * Ztso: `"ztso"`
44+
/// | Literal | Base | Linux |
45+
/// |:---------- |:------- |:---------- |
46+
/// | `"rv32e"` | RV32E | No |
47+
/// | `"rv32i"` | RV32I | Yes [^ima] |
48+
/// | `"rv64i"` | RV64I | Yes [^ima] |
49+
///
50+
/// | Literal | Extension | Linux |
51+
/// |:--------------- |:----------- |:------------------- |
52+
/// | `"a"` | A | Yes [^ima] |
53+
/// | `"b"` | B | 6.5 |
54+
/// | `"c"` | C | Yes |
55+
/// | `"d"` | D | Yes |
56+
/// | `"f"` | F | Yes |
57+
/// | `"m"` | M | Yes [^ima] |
58+
/// | `"q"` | Q | No |
59+
/// | `"v"` | V | 6.5 |
60+
/// | `"zaamo"` | Zaamo | 6.15 [^ima] [^dep] |
61+
/// | `"zabha"` | Zabha | 6.16 |
62+
/// | `"zacas"` | Zacas | 6.8 |
63+
/// | `"zalrsc"` | Zalrsc | 6.15 [^ima] [^dep] |
64+
/// | `"zawrs"` | Zawrs | 6.11 |
65+
/// | `"zba"` | Zba | 6.5 |
66+
/// | `"zbb"` | Zbb | 6.5 |
67+
/// | `"zbc"` | Zbc | 6.8 |
68+
/// | `"zbkb"` | Zbkb | 6.8 |
69+
/// | `"zbkc"` | Zbkc | 6.8 |
70+
/// | `"zbkx"` | Zbkx | 6.8 |
71+
/// | `"zbs"` | Zbs | 6.5 |
72+
/// | `"zca"` | Zca | 6.11 [^dep] |
73+
/// | `"zcb"` | Zcb | 6.11 |
74+
/// | `"zcd"` | Zcd | 6.11 [^dep] |
75+
/// | `"zcf"` | Zcf | 6.11 [^dep] |
76+
/// | `"zcmop"` | Zcmop | 6.11 |
77+
/// | `"zdinx"` | Zdinx | No |
78+
/// | `"zfa"` | Zfa | 6.8 |
79+
/// | `"zfbfmin"` | Zfbfmin | 6.15 |
80+
/// | `"zfh"` | Zfh | 6.8 |
81+
/// | `"zfhmin"` | Zfhmin | 6.8 |
82+
/// | `"zfinx"` | Zfinx | No |
83+
/// | `"zhinx"` | Zhinx | No |
84+
/// | `"zhinxmin"` | Zhinxmin | No |
85+
/// | `"zicbom"` | Zicbom | 6.15 |
86+
/// | `"zicboz"` | Zicboz | 6.7 |
87+
/// | `"zicntr"` | Zicntr | 6.15 [^ima] [^cntr] |
88+
/// | `"zicond"` | Zicond | 6.8 |
89+
/// | `"zicsr"` | Zicsr | No [^ima] [^dep] |
90+
/// | `"zifencei"` | Zifencei | No [^ima] |
91+
/// | `"zihintntl"` | Zihintntl | 6.8 |
92+
/// | `"zihintpause"` | Zihintpause | 6.10 |
93+
/// | `"zihpm"` | Zihpm | 6.15 [^cntr] |
94+
/// | `"zimop"` | Zimop | 6.11 |
95+
/// | `"zk"` | Zk | No [^zkr] |
96+
/// | `"zkn"` | Zkn | 6.8 |
97+
/// | `"zknd"` | Zknd | 6.8 |
98+
/// | `"zkne"` | Zkne | 6.8 |
99+
/// | `"zknh"` | Zknh | 6.8 |
100+
/// | `"zkr"` | Zkr | No [^zkr] |
101+
/// | `"zks"` | Zks | 6.8 |
102+
/// | `"zksed"` | Zksed | 6.8 |
103+
/// | `"zksh"` | Zksh | 6.8 |
104+
/// | `"zkt"` | Zkt | 6.8 |
105+
/// | `"ztso"` | Ztso | 6.8 |
106+
/// | `"zvbb"` | Zvbb | 6.8 |
107+
/// | `"zvbc"` | Zvbc | 6.8 |
108+
/// | `"zve32f"` | Zve32f | 6.11 [^dep] |
109+
/// | `"zve32x"` | Zve32x | 6.11 [^dep] |
110+
/// | `"zve64d"` | Zve64d | 6.11 [^dep] |
111+
/// | `"zve64f"` | Zve64f | 6.11 [^dep] |
112+
/// | `"zve64x"` | Zve64x | 6.11 [^dep] |
113+
/// | `"zvfbfmin"` | Zvfbfmin | 6.15 |
114+
/// | `"zvfbfwma"` | Zvfbfwma | 6.15 |
115+
/// | `"zvfh"` | Zvfh | 6.8 |
116+
/// | `"zvfhmin"` | Zvfhmin | 6.8 |
117+
/// | `"zvkb"` | Zvkb | 6.8 |
118+
/// | `"zvkg"` | Zvkg | 6.8 |
119+
/// | `"zvkn"` | Zvkn | 6.8 |
120+
/// | `"zvknc"` | Zvknc | 6.8 |
121+
/// | `"zvkned"` | Zvkned | 6.8 |
122+
/// | `"zvkng"` | Zvkng | 6.8 |
123+
/// | `"zvknha"` | Zvknha | 6.8 |
124+
/// | `"zvknhb"` | Zvknhb | 6.8 |
125+
/// | `"zvks"` | Zvks | 6.8 |
126+
/// | `"zvksc"` | Zvksc | 6.8 |
127+
/// | `"zvksed"` | Zvksed | 6.8 |
128+
/// | `"zvksg"` | Zvksg | 6.8 |
129+
/// | `"zvksh"` | Zvksh | 6.8 |
130+
/// | `"zvkt"` | Zvkt | 6.8 |
131+
///
132+
/// [^ima]: Or enabled when the IMA base behavior is detected on the Linux
133+
/// kernel version 6.4 or later (for bases, the only matching one -- either
134+
/// `"rv32i"` or `"rv64i"` -- is enabled).
135+
///
136+
/// [^cntr]: Even if this extension is available, it does not necessarily
137+
/// mean all performance counters are accessible.
138+
/// For example, accesses to all performance counters except `time`
139+
/// (wall-clock) are blocked by default on the Linux kernel
140+
/// version 6.6 or later.
141+
/// Also beware that, even if performance counters like `cycle` and
142+
/// `instret` are accessible, their value can be unreliable (e.g. returning
143+
/// the constant value) under certain circumstances.
144+
///
145+
/// [^dep]: Or enabled as a dependency of another extension (a superset)
146+
/// even if runtime detection of this feature itself is not supported (as
147+
/// long as the runtime detection of the superset is supported).
148+
///
149+
/// [^zkr]: Linux does not report existence of this extension even if
150+
/// supported by the hardware mainly because the `seed` CSR on the Zkr
151+
/// extension (which provides hardware-based randomness) is normally
152+
/// inaccessible from the user mode.
153+
/// For the Zk extension features except this CSR, check existence of both
154+
/// `"zkn"` and `"zkt"` features instead.
124155
///
125156
/// There's also bases and extensions marked as standard instruction set,
126157
/// but they are in frozen or draft state. These instruction sets are also

0 commit comments

Comments
 (0)