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