rust/library/stdarch/crates/stdsimd/tests/cpu-detection.rs
Alex Crichton 39b5ec91ae
Reorganize and refactor source tree (#324)
With RFC 2325 looking close to being accepted, I took a crack at
reorganizing this repository to being more amenable for inclusion in
libstd/libcore. My current plan is to add stdsimd as a submodule in
rust-lang/rust and then use `#[path]` to include the modules directly
into libstd/libcore.

Before this commit, however, the source code of coresimd/stdsimd
themselves were not quite ready for this. Imports wouldn't compile for
one reason or another, and the organization was also different than the
RFC itself!

In addition to moving a lot of files around, this commit has the
following major changes:

* The `cfg_feature_enabled!` macro is now renamed to
  `is_target_feature_detected!`
* The `vendor` module is now called `arch`.
* Under the `arch` module is a suite of modules like `x86`, `x86_64`,
  etc. One per `cfg!(target_arch)`.
* The `is_target_feature_detected!` macro was removed from coresimd.
  Unfortunately libcore has no ability to export unstable macros, so for
  now all feature detection is canonicalized in stdsimd.

The `coresimd` and `stdsimd` crates have been updated to the planned
organization in RFC 2325 as well. The runtime bits saw the largest
amount of refactoring, seeing a good deal of simplification without the
core/std split.
2018-02-18 10:07:35 +09:00

73 lines
3.3 KiB
Rust

#![feature(cfg_target_feature)]
#![cfg_attr(feature = "strict", deny(warnings))]
#![cfg_attr(feature = "cargo-clippy",
allow(option_unwrap_used, use_debug, print_stdout))]
#[cfg(any(target_arch = "arm", target_arch = "aarch64",
target_arch = "x86", target_arch = "x86_64",
target_arch = "powerpc64"))]
#[macro_use]
extern crate stdsimd;
#[test]
#[cfg(all(target_arch = "arm", target_os = "linux"))]
fn arm_linux() {
println!("neon: {}", is_target_feature_detected!("neon"));
println!("pmull: {}", is_target_feature_detected!("pmull"));
}
#[test]
#[cfg(all(target_arch = "aarch64", target_os = "linux"))]
fn aarch64_linux() {
println!("neon: {}", is_target_feature_detected!("neon"));
println!("asimd: {}", is_target_feature_detected!("asimd"));
println!("pmull: {}", is_target_feature_detected!("pmull"));
}
#[test]
#[cfg(all(target_arch = "powerpc64", target_os = "linux"))]
fn powerpc64_linux() {
println!("altivec: {}", is_target_feature_detected!("altivec"));
println!("vsx: {}", is_target_feature_detected!("vsx"));
println!("power8: {}", is_target_feature_detected!("power8"));
}
#[test]
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
fn x86_all() {
println!("sse: {:?}", is_target_feature_detected!("sse"));
println!("sse2: {:?}", is_target_feature_detected!("sse2"));
println!("sse3: {:?}", is_target_feature_detected!("sse3"));
println!("ssse3: {:?}", is_target_feature_detected!("ssse3"));
println!("sse4.1: {:?}", is_target_feature_detected!("sse4.1"));
println!("sse4.2: {:?}", is_target_feature_detected!("sse4.2"));
println!("sse4a: {:?}", is_target_feature_detected!("sse4a"));
println!("avx: {:?}", is_target_feature_detected!("avx"));
println!("avx2: {:?}", is_target_feature_detected!("avx2"));
println!("avx512f {:?}", is_target_feature_detected!("avx512f"));
println!("avx512cd {:?}", is_target_feature_detected!("avx512cd"));
println!("avx512er {:?}", is_target_feature_detected!("avx512er"));
println!("avx512pf {:?}", is_target_feature_detected!("avx512pf"));
println!("avx512bw {:?}", is_target_feature_detected!("avx512bw"));
println!("avx512dq {:?}", is_target_feature_detected!("avx512dq"));
println!("avx512vl {:?}", is_target_feature_detected!("avx512vl"));
println!("avx512_ifma {:?}", is_target_feature_detected!("avx512ifma"));
println!("avx512_vbmi {:?}", is_target_feature_detected!("avx512vbmi"));
println!(
"avx512_vpopcntdq {:?}",
is_target_feature_detected!("avx512vpopcntdq")
);
println!("fma: {:?}", is_target_feature_detected!("fma"));
println!("abm: {:?}", is_target_feature_detected!("abm"));
println!("bmi: {:?}", is_target_feature_detected!("bmi"));
println!("bmi2: {:?}", is_target_feature_detected!("bmi2"));
println!("tbm: {:?}", is_target_feature_detected!("tbm"));
println!("popcnt: {:?}", is_target_feature_detected!("popcnt"));
println!("lzcnt: {:?}", is_target_feature_detected!("lzcnt"));
println!("fxsr: {:?}", is_target_feature_detected!("fxsr"));
println!("xsave: {:?}", is_target_feature_detected!("xsave"));
println!("xsaveopt: {:?}", is_target_feature_detected!("xsaveopt"));
println!("xsaves: {:?}", is_target_feature_detected!("xsaves"));
println!("xsavec: {:?}", is_target_feature_detected!("xsavec"));
}