| 1 | //! Run-time feature detection on RISC-V. |
| 2 | |
| 3 | features! { |
| 4 | @TARGET: riscv; |
| 5 | @CFG: any(target_arch = "riscv32" , target_arch = "riscv64" ); |
| 6 | @MACRO_NAME: is_riscv_feature_detected; |
| 7 | @MACRO_ATTRS: |
| 8 | /// A macro to test at *runtime* whether instruction sets are available on |
| 9 | /// RISC-V platforms. |
| 10 | /// |
| 11 | /// RISC-V standard defined the base sets and the extension sets. |
| 12 | /// The base sets are RV32I, RV64I, RV32E or RV128I. Any RISC-V platform |
| 13 | /// must support one base set and/or multiple extension sets. |
| 14 | /// |
| 15 | /// Any RISC-V standard instruction sets can be in state of either ratified, |
| 16 | /// frozen or draft. The version and status of current standard instruction |
| 17 | /// sets can be checked out from preface section of the [ISA manual]. |
| 18 | /// |
| 19 | /// Platform may define and support their own custom instruction sets with |
| 20 | /// ISA prefix X. These sets are highly platform specific and should be |
| 21 | /// detected with their own platform support crates. |
| 22 | /// |
| 23 | /// # Unprivileged Specification |
| 24 | /// |
| 25 | /// The supported ratified RISC-V instruction sets are as follows: |
| 26 | /// |
| 27 | /// * RV32E: `"rv32e"` |
| 28 | /// * RV32I: `"rv32i"` |
| 29 | /// * RV64I: `"rv64i"` |
| 30 | /// * A: `"a"` |
| 31 | /// * B: `"b"` |
| 32 | /// * Zba: `"zba"` |
| 33 | /// * Zbb: `"zbb"` |
| 34 | /// * Zbc: `"zbc"` |
| 35 | /// * Zbs: `"zbs"` |
| 36 | /// * C: `"c"` |
| 37 | /// * D: `"d"` |
| 38 | /// * F: `"f"` |
| 39 | /// * M: `"m"` |
| 40 | /// * Q: `"q"` |
| 41 | /// * V: `"v"` |
| 42 | /// * Zicntr: `"zicntr"` |
| 43 | /// * Zicsr: `"zicsr"` |
| 44 | /// * Zifencei: `"zifencei"` |
| 45 | /// * Zihintpause: `"zihintpause"` |
| 46 | /// * Zihpm: `"zihpm"` |
| 47 | /// * Zk: `"zk"` |
| 48 | /// * Zbkb: `"zbkb"` |
| 49 | /// * Zbkc: `"zbkc"` |
| 50 | /// * Zbkx: `"zbkx"` |
| 51 | /// * Zkn: `"zkn"` |
| 52 | /// * Zknd: `"zknd"` |
| 53 | /// * Zkne: `"zkne"` |
| 54 | /// * Zknh: `"zknh"` |
| 55 | /// * Zkr: `"zkr"` |
| 56 | /// * Zks: `"zks"` |
| 57 | /// * Zksed: `"zksed"` |
| 58 | /// * Zksh: `"zksh"` |
| 59 | /// * Zkt: `"zkt"` |
| 60 | /// |
| 61 | /// There's also bases and extensions marked as standard instruction set, |
| 62 | /// but they are in frozen or draft state. These instruction sets are also |
| 63 | /// reserved by this macro and can be detected in the future platforms. |
| 64 | /// |
| 65 | /// Frozen RISC-V instruction sets: |
| 66 | /// |
| 67 | /// * Zfh: `"zfh"` |
| 68 | /// * Zfhmin: `"zfhmin"` |
| 69 | /// * Zfinx: `"zfinx"` |
| 70 | /// * Zdinx: `"zdinx"` |
| 71 | /// * Zhinx: `"zhinx"` |
| 72 | /// * Zhinxmin: `"zhinxmin"` |
| 73 | /// * Ztso: `"ztso"` |
| 74 | /// |
| 75 | /// Draft RISC-V instruction sets: |
| 76 | /// |
| 77 | /// * RV128I: `"rv128i"` |
| 78 | /// * J: `"j"` |
| 79 | /// * P: `"p"` |
| 80 | /// * Zam: `"zam"` |
| 81 | /// |
| 82 | /// Defined by Privileged Specification: |
| 83 | /// |
| 84 | /// * Supervisor: `"s"` |
| 85 | /// * Svnapot: `"svnapot"` |
| 86 | /// * Svpbmt: `"svpbmt"` |
| 87 | /// * Svinval: `"svinval"` |
| 88 | /// * Hypervisor: `"h"` |
| 89 | /// |
| 90 | /// [ISA manual]: https://github.com/riscv/riscv-isa-manual/ |
| 91 | #[stable (feature = "riscv_ratified" , since = "1.76.0" )] |
| 92 | @FEATURE: #[unstable (feature = "stdarch_riscv_feature_detection" , issue = "111192" )] rv32i: "rv32i" ; |
| 93 | without cfg check: true; |
| 94 | /// RV32I Base Integer Instruction Set |
| 95 | @FEATURE: #[unstable (feature = "stdarch_riscv_feature_detection" , issue = "111192" )] zifencei: "zifencei" ; |
| 96 | without cfg check: true; |
| 97 | /// "Zifencei" Instruction-Fetch Fence |
| 98 | @FEATURE: #[unstable (feature = "stdarch_riscv_feature_detection" , issue = "111192" )] zihintpause: "zihintpause" ; |
| 99 | without cfg check: true; |
| 100 | /// "Zihintpause" Pause Hint |
| 101 | @FEATURE: #[unstable (feature = "stdarch_riscv_feature_detection" , issue = "111192" )] rv64i: "rv64i" ; |
| 102 | without cfg check: true; |
| 103 | /// RV64I Base Integer Instruction Set |
| 104 | @FEATURE: #[stable (feature = "riscv_ratified" , since = "1.76.0" )] m: "m" ; |
| 105 | /// "M" Standard Extension for Integer Multiplication and Division |
| 106 | @FEATURE: #[stable (feature = "riscv_ratified" , since = "1.76.0" )] a: "a" ; |
| 107 | /// "A" Standard Extension for Atomic Instructions |
| 108 | @FEATURE: #[unstable (feature = "stdarch_riscv_feature_detection" , issue = "111192" )] zicsr: "zicsr" ; |
| 109 | without cfg check: true; |
| 110 | /// "Zicsr", Control and Status Register (CSR) Instructions |
| 111 | @FEATURE: #[unstable (feature = "stdarch_riscv_feature_detection" , issue = "111192" )] zicntr: "zicntr" ; |
| 112 | without cfg check: true; |
| 113 | /// "Zicntr", Standard Extension for Base Counters and Timers |
| 114 | @FEATURE: #[unstable (feature = "stdarch_riscv_feature_detection" , issue = "111192" )] zihpm: "zihpm" ; |
| 115 | without cfg check: true; |
| 116 | /// "Zihpm", Standard Extension for Hardware Performance Counters |
| 117 | @FEATURE: #[unstable (feature = "stdarch_riscv_feature_detection" , issue = "111192" )] f: "f" ; |
| 118 | /// "F" Standard Extension for Single-Precision Floating-Point |
| 119 | @FEATURE: #[unstable (feature = "stdarch_riscv_feature_detection" , issue = "111192" )] d: "d" ; |
| 120 | /// "D" Standard Extension for Double-Precision Floating-Point |
| 121 | @FEATURE: #[unstable (feature = "stdarch_riscv_feature_detection" , issue = "111192" )] q: "q" ; |
| 122 | without cfg check: true; |
| 123 | /// "Q" Standard Extension for Quad-Precision Floating-Point |
| 124 | @FEATURE: #[stable (feature = "riscv_ratified" , since = "1.76.0" )] c: "c" ; |
| 125 | /// "C" Standard Extension for Compressed Instructions |
| 126 | |
| 127 | @FEATURE: #[unstable (feature = "stdarch_riscv_feature_detection" , issue = "111192" )] zfinx: "zfinx" ; |
| 128 | /// "Zfinx" Standard Extension for Single-Precision Floating-Point in Integer Registers |
| 129 | @FEATURE: #[unstable (feature = "stdarch_riscv_feature_detection" , issue = "111192" )] zdinx: "zdinx" ; |
| 130 | /// "Zdinx" Standard Extension for Double-Precision Floating-Point in Integer Registers |
| 131 | @FEATURE: #[unstable (feature = "stdarch_riscv_feature_detection" , issue = "111192" )] zhinx: "zhinx" ; |
| 132 | /// "Zhinx" Standard Extension for Half-Precision Floating-Point in Integer Registers |
| 133 | @FEATURE: #[unstable (feature = "stdarch_riscv_feature_detection" , issue = "111192" )] zhinxmin: "zhinxmin" ; |
| 134 | /// "Zhinxmin" Standard Extension for Minimal Half-Precision Floating-Point in Integer Registers |
| 135 | @FEATURE: #[unstable (feature = "stdarch_riscv_feature_detection" , issue = "111192" )] ztso: "ztso" ; |
| 136 | without cfg check: true; |
| 137 | /// "Ztso" Standard Extension for Total Store Ordering |
| 138 | |
| 139 | @FEATURE: #[unstable (feature = "stdarch_riscv_feature_detection" , issue = "111192" )] rv32e: "rv32e" ; |
| 140 | without cfg check: true; |
| 141 | /// RV32E Base Integer Instruction Set |
| 142 | @FEATURE: #[unstable (feature = "stdarch_riscv_feature_detection" , issue = "111192" )] rv128i: "rv128i" ; |
| 143 | without cfg check: true; |
| 144 | /// RV128I Base Integer Instruction Set |
| 145 | @FEATURE: #[unstable (feature = "stdarch_riscv_feature_detection" , issue = "111192" )] zfh: "zfh" ; |
| 146 | /// "Zfh" Standard Extension for 16-Bit Half-Precision Floating-Point |
| 147 | @FEATURE: #[unstable (feature = "stdarch_riscv_feature_detection" , issue = "111192" )] zfhmin: "zfhmin" ; |
| 148 | /// "Zfhmin" Standard Extension for Minimal Half-Precision Floating-Point Support |
| 149 | @FEATURE: #[unstable (feature = "stdarch_riscv_feature_detection" , issue = "111192" )] j: "j" ; |
| 150 | without cfg check: true; |
| 151 | /// "J" Standard Extension for Dynamically Translated Languages |
| 152 | @FEATURE: #[unstable (feature = "stdarch_riscv_feature_detection" , issue = "111192" )] p: "p" ; |
| 153 | without cfg check: true; |
| 154 | /// "P" Standard Extension for Packed-SIMD Instructions |
| 155 | @FEATURE: #[unstable (feature = "stdarch_riscv_feature_detection" , issue = "111192" )] v: "v" ; |
| 156 | /// "V" Standard Extension for Vector Operations |
| 157 | @FEATURE: #[unstable (feature = "stdarch_riscv_feature_detection" , issue = "111192" )] zam: "zam" ; |
| 158 | without cfg check: true; |
| 159 | /// "Zam" Standard Extension for Misaligned Atomics |
| 160 | |
| 161 | @FEATURE: #[unstable (feature = "stdarch_riscv_feature_detection" , issue = "111192" )] s: "s" ; |
| 162 | without cfg check: true; |
| 163 | /// Supervisor-Level ISA |
| 164 | @FEATURE: #[unstable (feature = "stdarch_riscv_feature_detection" , issue = "111192" )] svnapot: "svnapot" ; |
| 165 | without cfg check: true; |
| 166 | /// "Svnapot" Standard Extension for NAPOT Translation Contiguity |
| 167 | @FEATURE: #[unstable (feature = "stdarch_riscv_feature_detection" , issue = "111192" )] svpbmt: "svpbmt" ; |
| 168 | without cfg check: true; |
| 169 | /// "Svpbmt" Standard Extension for Page-Based Memory Types |
| 170 | @FEATURE: #[unstable (feature = "stdarch_riscv_feature_detection" , issue = "111192" )] svinval: "svinval" ; |
| 171 | without cfg check: true; |
| 172 | /// "Svinval" Standard Extension for Fine-Grained Address-Translation Cache Invalidation |
| 173 | @FEATURE: #[unstable (feature = "stdarch_riscv_feature_detection" , issue = "111192" )] h: "h" ; |
| 174 | without cfg check: true; |
| 175 | /// Hypervisor Extension |
| 176 | |
| 177 | @FEATURE: #[stable (feature = "riscv_ratified" , since = "1.76.0" )] zba: "zba" ; |
| 178 | /// "Zba" Standard Extension for Address Generation Instructions |
| 179 | @FEATURE: #[stable (feature = "riscv_ratified" , since = "1.76.0" )] zbb: "zbb" ; |
| 180 | /// "Zbb" Standard Extension for Basic Bit-Manipulation |
| 181 | @FEATURE: #[stable (feature = "riscv_ratified" , since = "1.76.0" )] zbc: "zbc" ; |
| 182 | /// "Zbc" Standard Extension for Carry-less Multiplication |
| 183 | @FEATURE: #[stable (feature = "riscv_ratified" , since = "1.76.0" )] zbs: "zbs" ; |
| 184 | /// "Zbs" Standard Extension for Single-Bit instructions |
| 185 | |
| 186 | @FEATURE: #[stable (feature = "riscv_ratified" , since = "1.76.0" )] zbkb: "zbkb" ; |
| 187 | /// "Zbkb" Standard Extension for Bitmanip instructions for Cryptography |
| 188 | @FEATURE: #[stable (feature = "riscv_ratified" , since = "1.76.0" )] zbkc: "zbkc" ; |
| 189 | /// "Zbkc" Standard Extension for Carry-less multiply instructions |
| 190 | @FEATURE: #[stable (feature = "riscv_ratified" , since = "1.76.0" )] zbkx: "zbkx" ; |
| 191 | /// "Zbkx" Standard Extension for Crossbar permutation instructions |
| 192 | @FEATURE: #[stable (feature = "riscv_ratified" , since = "1.76.0" )] zknd: "zknd" ; |
| 193 | /// "Zknd" Standard Extension for NIST Suite: AES Decryption |
| 194 | @FEATURE: #[stable (feature = "riscv_ratified" , since = "1.76.0" )] zkne: "zkne" ; |
| 195 | /// "Zkne" Standard Extension for NIST Suite: AES Encryption |
| 196 | @FEATURE: #[stable (feature = "riscv_ratified" , since = "1.76.0" )] zknh: "zknh" ; |
| 197 | /// "Zknh" Standard Extension for NIST Suite: Hash Function Instructions |
| 198 | @FEATURE: #[stable (feature = "riscv_ratified" , since = "1.76.0" )] zksed: "zksed" ; |
| 199 | /// "Zksed" Standard Extension for ShangMi Suite: SM4 Block Cipher Instructions |
| 200 | @FEATURE: #[stable (feature = "riscv_ratified" , since = "1.76.0" )] zksh: "zksh" ; |
| 201 | /// "Zksh" Standard Extension for ShangMi Suite: SM3 Hash Function Instructions |
| 202 | @FEATURE: #[stable (feature = "riscv_ratified" , since = "1.76.0" )] zkr: "zkr" ; |
| 203 | /// "Zkr" Standard Extension for Entropy Source Extension |
| 204 | @FEATURE: #[stable (feature = "riscv_ratified" , since = "1.76.0" )] zkn: "zkn" ; |
| 205 | /// "Zkn" Standard Extension for NIST Algorithm Suite |
| 206 | @FEATURE: #[stable (feature = "riscv_ratified" , since = "1.76.0" )] zks: "zks" ; |
| 207 | /// "Zks" Standard Extension for ShangMi Algorithm Suite |
| 208 | @FEATURE: #[stable (feature = "riscv_ratified" , since = "1.76.0" )] zk: "zk" ; |
| 209 | /// "Zk" Standard Extension for Standard scalar cryptography extension |
| 210 | @FEATURE: #[stable (feature = "riscv_ratified" , since = "1.76.0" )] zkt: "zkt" ; |
| 211 | /// "Zkt" Standard Extension for Data Independent Execution Latency |
| 212 | } |
| 213 | |