Skip to content
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

RISC-V feature and detect macro #1263

Merged
merged 1 commit into from
Dec 8, 2021
Merged

Conversation

luojia65
Copy link
Contributor

@luojia65 luojia65 commented Dec 7, 2021

This pull request includes:

  • RISC-V platform feature and its detect maro
  • Detect RISC-V instruction set features in Linux, using Auxvec and /proc/cpuinfo. (edit: does not read from /proc/cpuinfo)

Marked as draft: these functions are yet to be verified on real Linux RISC-V machines. edit: these function passed tests on RISC-V Linux machines

@rust-highfive
Copy link

r? @Amanieu

(rust-highfive has picked a reviewer for you, use r? to override)

Copy link
Member

@Amanieu Amanieu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! However make sure the feature names match the ones used by Rust for cfg(target_feature) and #[target_feature(enable = "...")]. I much prefer the names that you chose, so the next step would be to update the feature names in rustc to match these. This can be done via the renaming layer in compiler/rustc_codegen_ssa/src/target_features.rs which maps rustc feature names to LLVM features.

crates/std_detect/src/detect/os/linux/riscv.rs Outdated Show resolved Hide resolved
@luojia65 luojia65 force-pushed the riscv-detect branch 2 times, most recently from 19949fa to 8ebc3a3 Compare December 8, 2021 04:51
@luojia65
Copy link
Contributor Author

luojia65 commented Dec 8, 2021

Cargo test has passed on RISC-V real machine:

root@unmatched:~/stdarch# root@unmatched:~/stdarch# cargo test
    Updating crates.io index
  Downloaded rand_core v0.5.1
  Downloaded memoffset v0.6.5
  Downloaded addr2line v0.17.0
  Downloaded rand_hc v0.1.0
  Downloaded quote v0.6.13
  Downloaded scopeguard v1.1.0
  Downloaded rustc_version v0.2.3
  Downloaded rustc-demangle v0.1.21
  Downloaded rayon v1.5.1
  Downloaded semver-parser v0.7.0
  Downloaded termcolor v1.1.2
  Downloaded tendril v0.4.2
  Downloaded xml-rs v0.8.4
  Downloaded strsim v0.8.0
  Downloaded utf-8 v0.7.6
  Downloaded vec_map v0.8.2
  Downloaded unicode-xid v0.1.0
  Downloaded bitflags v1.3.2
  Downloaded cc v1.0.72
  Downloaded diff v0.1.12
  Downloaded crossbeam-utils v0.8.5
  Downloaded crossbeam-epoch v0.9.5
  Downloaded clap v2.34.0
  Downloaded crossbeam-channel v0.5.1
  Downloaded env_logger v0.7.1
  Downloaded getrandom v0.1.16
  Downloaded gcc v0.3.55
  Downloaded string_cache_shared v0.3.0
  Downloaded rand v0.6.5
  Downloaded siphasher v0.2.3
  Downloaded serde-xml-rs v0.3.1
  Downloaded lazy_static v1.4.0
  Downloaded ppv-lite86 v0.2.15
  Downloaded quote v1.0.10
  Downloaded proc-macro2 v1.0.33
  Downloaded serde_json v1.0.72
  Downloaded regex v1.5.4
  Downloaded miniz_oxide v0.4.4
  Downloaded regex-automata v0.1.10
  Downloaded quick-error v1.2.3
  Downloaded serde_derive v1.0.130
  Downloaded string_cache_codegen v0.4.4
  Downloaded pretty_env_logger v0.4.0
  Downloaded syn v0.15.44
  Downloaded unicode-width v0.1.9
  Downloaded regex-syntax v0.6.25
  Downloaded phf_shared v0.7.24
  Downloaded object v0.27.1
  Downloaded syn v1.0.82
  Downloaded phf_generator v0.7.24
  Downloaded string_cache v0.7.5
  Downloaded html5ever v0.23.0
  Downloaded cupid v0.6.1
  Downloaded backtrace v0.3.63
  Downloaded autocfg v0.1.7
  Downloaded auxv v0.3.3
  Downloaded csv v1.1.6
  Downloaded aho-corasick v0.7.18
  Downloaded gimli v0.26.1
  Downloaded phf v0.7.24
  Downloaded libc v0.2.109
  Downloaded phf_codegen v0.7.24
  Downloaded markup5ever v0.8.1
  Downloaded error-chain v0.10.0
  Downloaded rand_core v0.3.1
  Downloaded num_cpus v1.13.0
  Downloaded mac v0.1.1
  Downloaded serde v1.0.130
  Downloaded ryu v1.0.6
  Downloaded rand_xorshift v0.1.1
  Downloaded rand_pcg v0.1.2
  Downloaded rand_chacha v0.2.2
  Downloaded rand_chacha v0.1.1
  Downloaded rand v0.7.3
  Downloaded proc-macro2 v0.4.30
  Downloaded rayon-core v1.9.1
  Downloaded memchr v2.4.1
  Downloaded itertools v0.10.3
  Downloaded log v0.4.14
  Downloaded itoa v0.4.8
  Downloaded rand_os v0.1.3
  Downloaded rand_jitter v0.1.4
  Downloaded rand_isaac v0.1.1
  Downloaded rand_core v0.4.2
  Downloaded quickcheck v0.9.2
  Downloaded precomputed-hash v0.1.1
  Downloaded new_debug_unreachable v1.0.4
  Downloaded humantime v1.3.0
  Downloaded futf v0.1.4
  Downloaded either v1.6.1
  Downloaded crossbeam-deque v0.8.1
  Downloaded cfg-if v1.0.0
  Downloaded cfg-if v0.1.10
  Downloaded csv-core v0.1.10
  Downloaded bstr v0.2.17
  Downloaded adler v1.0.2
  Downloaded autocfg v1.0.1
  Downloaded textwrap v0.11.0
  Downloaded unicode-xid v0.2.2
  Downloaded atty v0.2.14
  Downloaded ansi_term v0.12.1
  Downloaded byteorder v1.4.3
  Downloaded semver v0.9.0
  Downloaded 103 crates (6.8 MB) in 5.85s
   Compiling libc v0.2.109
   Compiling proc-macro2 v1.0.33
   Compiling unicode-xid v0.2.2
   Compiling syn v1.0.82
   Compiling cfg-if v1.0.0
   Compiling rand_core v0.4.2
   Compiling autocfg v0.1.7
   Compiling lazy_static v1.4.0
   Compiling memchr v2.4.1
   Compiling autocfg v1.0.1
   Compiling serde_derive v1.0.130
   Compiling log v0.4.14
   Compiling serde v1.0.130
   Compiling siphasher v0.2.3
   Compiling cc v1.0.72
   Compiling cfg-if v0.1.10
   Compiling ryu v1.0.6
   Compiling rustc-demangle v0.1.21
   Compiling string_cache_shared v0.3.0
   Compiling itoa v0.4.8
   Compiling gcc v0.3.55
   Compiling proc-macro2 v0.4.30
   Compiling semver-parser v0.7.0
   Compiling serde_json v1.0.72
   Compiling unicode-xid v0.1.0
   Compiling getrandom v0.1.16
   Compiling new_debug_unreachable v1.0.4
   Compiling syn v0.15.44
   Compiling assert-instr-macro v0.1.0 (/home/root/stdarch/crates/assert-instr-macro)
   Compiling core_arch v0.1.5 (/home/root/stdarch/crates/core_arch)
   Compiling quick-error v1.2.3
   Compiling mac v0.1.1
   Compiling adler v1.0.2
   Compiling regex-syntax v0.6.25
   Compiling crossbeam-utils v0.8.5
   Compiling gimli v0.26.1
   Compiling precomputed-hash v0.1.1
   Compiling termcolor v1.1.2
   Compiling utf-8 v0.7.6
   Compiling ppv-lite86 v0.2.15
   Compiling stdarch-verify v0.1.0 (/home/root/stdarch/crates/stdarch-verify)
   Compiling byteorder v1.4.3
   Compiling crossbeam-epoch v0.9.5
   Compiling scopeguard v1.1.0
   Compiling rayon-core v1.9.1
   Compiling xml-rs v0.8.4
   Compiling regex-automata v0.1.10
   Compiling unicode-width v0.1.9
   Compiling either v1.6.1
   Compiling bitflags v1.3.2
   Compiling strsim v0.8.0
   Compiling vec_map v0.8.2
   Compiling ansi_term v0.12.1
   Compiling diff v0.1.12
   Compiling stdarch-gen v0.1.0 (/home/root/stdarch/crates/stdarch-gen)
   Compiling rand_core v0.3.1
   Compiling rand_jitter v0.1.4
   Compiling rand_pcg v0.1.2
   Compiling rand_chacha v0.1.1
   Compiling rand v0.6.5
   Compiling miniz_oxide v0.4.4
   Compiling memoffset v0.6.5
   Compiling rayon v1.5.1
   Compiling phf_shared v0.7.24
   Compiling semver v0.9.0
   Compiling auxv v0.3.3
   Compiling humantime v1.3.0
   Compiling futf v0.1.4
   Compiling backtrace v0.3.63
   Compiling addr2line v0.17.0
   Compiling textwrap v0.11.0
   Compiling itertools v0.10.3
   Compiling rand_isaac v0.1.1
   Compiling rand_xorshift v0.1.1
   Compiling rand_hc v0.1.0
   Compiling phf v0.7.24
   Compiling rustc_version v0.2.3
   Compiling tendril v0.4.2
   Compiling rand_os v0.1.3
   Compiling std_detect v0.1.5 (/home/root/stdarch/crates/std_detect)
   Compiling atty v0.2.14
   Compiling num_cpus v1.13.0
   Compiling quote v1.0.10
   Compiling aho-corasick v0.7.18
   Compiling object v0.27.1
   Compiling csv-core v0.1.10
   Compiling quote v0.6.13
   Compiling cupid v0.6.1
   Compiling crossbeam-channel v0.5.1
   Compiling clap v2.34.0
   Compiling rand_core v0.5.1
   Compiling simd-test-macro v0.1.0 (/home/root/stdarch/crates/simd-test-macro)
   Compiling regex v1.5.4
   Compiling rand_chacha v0.2.2
   Compiling phf_generator v0.7.24
   Compiling crossbeam-deque v0.8.1
   Compiling env_logger v0.7.1
   Compiling rand v0.7.3
   Compiling string_cache_codegen v0.4.4
   Compiling phf_codegen v0.7.24
   Compiling error-chain v0.10.0
   Compiling pretty_env_logger v0.4.0
   Compiling quickcheck v0.9.2
   Compiling string_cache v0.7.5
   Compiling html5ever v0.23.0
   Compiling stdarch-test v0.1.0 (/home/root/stdarch/crates/stdarch-test)
   Compiling stdarch_examples v0.0.0 (/home/root/stdarch/examples)
   Compiling serde-xml-rs v0.3.1
   Compiling bstr v0.2.17
   Compiling csv v1.1.6
   Compiling intrinsic-test v0.1.0 (/home/root/stdarch/crates/intrinsic-test)
   Compiling markup5ever v0.8.1
    Finished test [unoptimized + debuginfo] target(s) in 26m 04s
     Running unittests (target/debug/deps/core_arch-280a01df54287274)

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running tests/cpu-detection.rs (target/debug/deps/cpu_detection-43cac81c3cd6e35b)

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running unittests (target/debug/deps/intrinsic_test-2f96af79bef4e56a)

running 3 tests
test acle_csv_parser::test::parse_simd ... ok
test acle_csv_parser::test::test_ptr ... ok
test acle_csv_parser::test::parse_simd_with_vec ... ok

test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running unittests (target/debug/deps/std_detect-35b4f4fe95136d3a)

running 9 tests
test detect::os::auxvec::tests::auxv_dump ... ok
test detect::os::auxvec::tests::auxv_dump_procfs ... ok
test detect::os::cpuinfo::tests::arm_cortex_a57 ... ok
test detect::os::cpuinfo::tests::arm_cortex_a53 ... ok
test detect::os::cpuinfo::tests::power5p ... ok
test detect::os::cpuinfo::tests::raw_dump ... ok
test detect::os::cpuinfo::tests::riscv_rv64gc ... ok
test detect::os::cpuinfo::tests::core_duo_t6500 ... ok
test detect::os::cpuinfo::tests::power8_powerkvm ... ok

test result: ok. 9 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running tests/cpu-detection.rs (target/debug/deps/cpu_detection-9146670384d8b036)

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running tests/macro_trailing_commas.rs (target/debug/deps/macro_trailing_commas-3cb36e41db79a5dd)

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running tests/x86-specific.rs (target/debug/deps/x86_specific-ac4e7264b40602a0)

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running unittests (target/debug/deps/stdarch_gen-da8c258580987643)

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running unittests (target/debug/deps/stdarch_test-8ec8368ea9ac6223)

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running tests/arm.rs (target/debug/deps/arm-8f4632b1e7077281)

running 1 test
test verify_all_signatures ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 52.18s

     Running tests/mips.rs (target/debug/deps/mips-53652991cc5a6db9)

running 1 test
test verify_all_signatures ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.06s

     Running tests/x86-intel.rs (target/debug/deps/x86_intel-45241d9139e0bd87)

running 1 test
test verify_all_signatures ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 36.55s

     Running unittests (target/debug/deps/connect5-5c84dbfb5d305770)

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running unittests (target/debug/deps/hex-470e6041bf8f02ae)

running 9 tests
test benches::small_default ... ok
test benches::small_fallback ... ok
test tests::avx_works ... ok
test tests::empty ... ok
test tests::big ... ok
test tests::odd ... ok
test tests::encode_equals_fallback ... ok
test benches::large_fallback ... ok
test benches::large_default ... ok

test result: ok. 9 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 15.71s

   Doc-tests assert-instr-macro

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

   Doc-tests core_arch

running 8 tests
test src/lib.rs - (line 114) ... ignored
test src/lib.rs - (line 58) ... ignored
test src/mod.rs - core_arch::arch (line 124) ... ignored
test src/lib.rs - (line 214) ... ok
test src/mod.rs - core_arch::arch (line 68) ... ignored
test src/mod.rs - core_arch::arch (line 224) ... ok
test src/lib.rs - (line 250) ... ok
test src/mod.rs - core_arch::arch (line 260) ... ok

test result: ok. 4 passed; 0 failed; 4 ignored; 0 measured; 0 filtered out; finished in 3.59s

   Doc-tests simd-test-macro

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

   Doc-tests std_detect

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

   Doc-tests stdarch-test

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

   Doc-tests stdarch-verify

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

root@unmatched:~/stdarch#

Dump auxv value:

root@unmatched:~/stdarch# cargo test --package std_detect --lib -- detect::os::auxvec::tests::auxv_dump --exact --nocapture
   Compiling libc v0.2.109
   Compiling std_detect v0.1.5 (/home/root/stdarch/crates/std_detect)
    Finished test [unoptimized + debuginfo] target(s) in 23.82s
     Running unittests (target/debug/deps/std_detect-584ae2c45d18a130)

running 1 test
AuxVec { hwcap: 4397 }
test detect::os::auxvec::tests::auxv_dump ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 8 filtered out; finished in 0.00s

Run example code:

root@unmatched:~/riscv-stdarch-test# cat src/main.rs
#![feature(stdsimd)]
#[macro_use]
extern crate std_detect;
use std_detect::detect;

fn main() {
    if is_riscv_feature_detected!("a") {
        println!("Macro: this platform supports RISC-V atomic instructions");
    }
    for (feature, supported) in detect::features() {
        let supported = if supported { "supported" } else { "unsupported" };
        println!("Enumerate: {} feature {}", supported, feature);
    }
}

root@unmatched:~/riscv-stdarch-test# cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.06s
     Running `target/debug/riscv-stdarch-test`
Macro: this platform supports RISC-V atomic instructions
Enumerate: unsupported feature rv32i
Enumerate: unsupported feature zifencei
Enumerate: unsupported feature zihintpause
Enumerate: supported feature rv64i
Enumerate: supported feature m
Enumerate: supported feature a
Enumerate: supported feature zicsr
Enumerate: unsupported feature zicntr
Enumerate: unsupported feature zihpm
Enumerate: supported feature f
Enumerate: supported feature d
Enumerate: unsupported feature q
Enumerate: supported feature c
Enumerate: unsupported feature zfinx
Enumerate: unsupported feature zdinx
Enumerate: unsupported feature zhinx
Enumerate: unsupported feature zhinxmin
Enumerate: unsupported feature ztso
Enumerate: unsupported feature rv32e
Enumerate: unsupported feature rv128i
Enumerate: unsupported feature zfh
Enumerate: unsupported feature zfhmin
Enumerate: unsupported feature b
Enumerate: unsupported feature j
Enumerate: unsupported feature p
Enumerate: unsupported feature v
Enumerate: unsupported feature zam
Enumerate: unsupported feature s
Enumerate: unsupported feature svnapot
Enumerate: unsupported feature svpbmt
Enumerate: unsupported feature svinval
Enumerate: unsupported feature h
Enumerate: unsupported feature zba
Enumerate: unsupported feature zbb
Enumerate: unsupported feature zbc
Enumerate: unsupported feature zbs
Enumerate: unsupported feature zbkb
Enumerate: unsupported feature zbkc
Enumerate: unsupported feature zbkx
Enumerate: unsupported feature zknd
Enumerate: unsupported feature zkne
Enumerate: unsupported feature zknh
Enumerate: unsupported feature zksed
Enumerate: unsupported feature zksh
Enumerate: unsupported feature zkr
Enumerate: unsupported feature zkn
Enumerate: unsupported feature zks
Enumerate: unsupported feature zk
Enumerate: unsupported feature zkt

@luojia65 luojia65 marked this pull request as ready for review December 8, 2021 09:10
This patch includes:

- RISC-V platform feature and its detect macro
- Detect RISC-V instruction set features in Linux using Auxvec
Copy link
Contributor

@lu-zero lu-zero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good to me, the amount of extension is a bit large, we should consider how to support shorthands, if they exist.

@Amanieu Amanieu merged commit f4513d5 into rust-lang:master Dec 8, 2021
@luojia65 luojia65 deleted the riscv-detect branch December 9, 2021 04:06
luojia65 added a commit to luojia65/rust that referenced this pull request Feb 6, 2022
Based on discussion at: rust-lang/stdarch#1263 (review)

Extension 'e' is renamed to 'rv32e'.
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 16, 2022
Support more RISC-V backend features on rustc compiler

This pull request adds the following RISC-V compiler features:

- V for vector extension
- Zfinx, Zdinx, Zhinx and Zhinxmin float in integer register extensions
- Zfh, Zfhmin 16-bit float pointer extensions
- Zbkb, Zkbc, Zbkc, Zk* cryptography extensions

It matches name in LLVM feature and is_riscv_feature_detected!. In this case we can use `#[target_feature]` on new RISC-V features. Ref: rust-lang/stdarch#1263 (review)

Use `rustc --print target-features` under any RISC-V target (or with `--target`) to check the features the rustc compiler support.

<details>

```
luojia@luojia-virtual-machine:~/IntrinRiscv/stdarch-riscv-crypto$ cargo rustc -- --print target-features
   Compiling stdarch-riscv-crypto v0.1.0 (/home/luojia/IntrinRiscv/stdarch-riscv-crypto)
Features supported by rustc for this target:
    m                - 'M' (Integer Multiplication and Division).
    a                - 'A' (Atomic Instructions).
    c                - 'C' (Compressed Instructions).
    f                - 'F' (Single-Precision Floating-Point).
    d                - 'D' (Double-Precision Floating-Point).
    e                - Implements RV32E (provides 16 rather than 32 GPRs).
    v                - 'V' (Vector Extension for Application Processors).
    zfinx            - 'Zfinx' (Float in Integer).
    zdinx            - 'Zdinx' (Double in Integer).
    zhinx            - 'Zhinx' (Half Float in Integer).
    zhinxmin         - 'Zhinxmin' (Half Float in Integer Minimal).
    zfh              - 'Zfh' (Half-Precision Floating-Point).
    zfhmin           - 'Zfhmin' (Half-Precision Floating-Point Minimal).
    zbkb             - 'Zbkb' (Bitmanip instructions for Cryptography).
    zbkc             - 'Zbkc' (Carry-less multiply instructions for Cryptography).
    zbkx             - 'Zbkx' (Crossbar permutation instructions).
    zknd             - 'Zknd' (NIST Suite: AES Decryption).
    zkne             - 'Zkne' (NIST Suite: AES Encryption).
    zknh             - 'Zknh' (NIST Suite: Hash Function Instructions).
    zksed            - 'Zksed' (ShangMi Suite: SM4 Block Cipher Instructions).
    zksh             - 'Zksh' (ShangMi Suite: SM3 Hash Function Instructions).
    zkr              - 'Zkr' (Entropy Source Extension).
    zkn              - 'Zkn' (NIST Algorithm Suite).
    zks              - 'Zks' (ShangMi Algorithm Suite).
    zk               - 'Zk' (Standard scalar cryptography extension).
    zkt              - 'Zkt' (Data Independent Execution Latency).
    crt-static       - Enables C Run-time Libraries to be statically linked.

Code-generation features supported by LLVM for this target:
    64bit            - Implements RV64.
    experimental-zbe - 'Zbe' (Extract-Deposit 'Zb' Instructions).
    experimental-zbf - 'Zbf' (Bit-Field 'Zb' Instructions).
    experimental-zbm - 'Zbm' (Matrix 'Zb' Instructions).
    experimental-zbp - 'Zbp' (Permutation 'Zb' Instructions).
    experimental-zbr - 'Zbr' (Polynomial Reduction 'Zb' Instructions).
    experimental-zbt - 'Zbt' (Ternary 'Zb' Instructions).
    no-rvc-hints     - Disable RVC Hint Instructions..
    relax            - Enable Linker relaxation..
    reserve-x1       - Reserve X1.
    reserve-x10      - Reserve X10.
    reserve-x11      - Reserve X11.
    reserve-x12      - Reserve X12.
    reserve-x13      - Reserve X13.
    reserve-x14      - Reserve X14.
    reserve-x15      - Reserve X15.
    reserve-x16      - Reserve X16.
    reserve-x17      - Reserve X17.
    reserve-x18      - Reserve X18.
    reserve-x19      - Reserve X19.
    reserve-x2       - Reserve X2.
    reserve-x20      - Reserve X20.
    reserve-x21      - Reserve X21.
    reserve-x22      - Reserve X22.
    reserve-x23      - Reserve X23.
    reserve-x24      - Reserve X24.
    reserve-x25      - Reserve X25.
    reserve-x26      - Reserve X26.
    reserve-x27      - Reserve X27.
    reserve-x28      - Reserve X28.
    reserve-x29      - Reserve X29.
    reserve-x3       - Reserve X3.
    reserve-x30      - Reserve X30.
    reserve-x31      - Reserve X31.
    reserve-x4       - Reserve X4.
    reserve-x5       - Reserve X5.
    reserve-x6       - Reserve X6.
    reserve-x7       - Reserve X7.
    reserve-x8       - Reserve X8.
    reserve-x9       - Reserve X9.
    save-restore     - Enable save/restore..
    sifive7          - SiFive 7-Series processors.
    zba              - 'Zba' (Address Generation Instructions).
    zbb              - 'Zbb' (Basic Bit-Manipulation).
    zbc              - 'Zbc' (Carry-Less Multiplication).
    zbs              - 'Zbs' (Single-Bit Instructions).
    zve32f           - 'Zve32f' (Vector Extensions for Embedded Processors with maximal 32 EEW and F extension).
    zve32x           - 'Zve32x' (Vector Extensions for Embedded Processors with maximal 32 EEW).
    zve64d           - 'Zve64d' (Vector Extensions for Embedded Processors with maximal 64 EEW, F and D extension).
    zve64f           - 'Zve64f' (Vector Extensions for Embedded Processors with maximal 64 EEW and F extension).
    zve64x           - 'Zve64x' (Vector Extensions for Embedded Processors with maximal 64 EEW).
    zvl1024b         - 'Zvl' (Minimum Vector Length) 1024.
    zvl128b          - 'Zvl' (Minimum Vector Length) 128.
    zvl16384b        - 'Zvl' (Minimum Vector Length) 16384.
    zvl2048b         - 'Zvl' (Minimum Vector Length) 2048.
    zvl256b          - 'Zvl' (Minimum Vector Length) 256.
    zvl32768b        - 'Zvl' (Minimum Vector Length) 32768.
    zvl32b           - 'Zvl' (Minimum Vector Length) 32.
    zvl4096b         - 'Zvl' (Minimum Vector Length) 4096.
    zvl512b          - 'Zvl' (Minimum Vector Length) 512.
    zvl64b           - 'Zvl' (Minimum Vector Length) 64.
    zvl8192b         - 'Zvl' (Minimum Vector Length) 8192.

Use +feature to enable a feature, or -feature to disable it.
For example, rustc -C target-cpu=mycpu -C target-feature=+feature1,-feature2

Code-generation features cannot be used in cfg or #[target_feature],
and may be renamed or removed in a future version of LLVM or rustc.

    Finished dev [unoptimized + debuginfo] target(s) in 0.03s
```
</details>

Proof of concept:

<details>

```rust
#![feature(link_llvm_intrinsics)]
#![feature(target_feature_11)]
#![feature(riscv_target_feature)]

extern "C" {
    #[link_name = "llvm.riscv.sm3p0"]
    fn llvm_sm3p0(x: u32) -> u32;
    #[link_name = "llvm.riscv.sm3p1"]
    fn llvm_sm3p1(x: u32) -> u32;
}

#[target_feature(enable = "zksh")]
pub unsafe fn sm3p0(x: u32) -> u32 {
    unsafe { llvm_sm3p0(x) }
}

extern "C" {
    #[link_name = "llvm.riscv.vsetvli"]
    fn llvm_vsetvli(avl: usize, sew: usize, lmul: usize) -> usize;
    #[link_name = "llvm.riscv.vsetvlimax"]
    fn llvm_vsetvlimax(sew: usize, lmul: usize) -> usize;
}

#[target_feature(enable = "v")]
pub unsafe fn vsetvli<const SEW: usize, const LMUL: usize>(avl: usize) -> usize {
    unsafe { llvm_vsetvli(avl, SEW, LMUL) }
}
```
</details>

r? `@Amanieu`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants