Skip to content

Commit c1c3c4e

Browse files
committedJan 29, 2019
Auto merge of #57808 - gnzlbg:ustdsimd, r=gnzlbg
Update stdsimd This is the companion PR to rust-lang/stdarch#640 r? @alexcrichton
2 parents 7425663 + 938a814 commit c1c3c4e

File tree

5 files changed

+125
-26
lines changed

5 files changed

+125
-26
lines changed
 

‎src/libcore/lib.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -221,11 +221,12 @@ pub mod alloc;
221221
mod tuple;
222222
mod unit;
223223

224-
// Pull in the `coresimd` crate directly into libcore. This is where all the
225-
// architecture-specific (and vendor-specific) intrinsics are defined. AKA
226-
// things like SIMD and such. Note that the actual source for all this lies in a
227-
// different repository, rust-lang-nursery/stdsimd. That's why the setup here is
228-
// a bit wonky.
224+
// Pull in the `core_arch` crate directly into libcore. The contents of
225+
// `core_arch` are in a different repository: rust-lang-nursery/stdsimd.
226+
//
227+
// `core_arch` depends on libcore, but the contents of this module are
228+
// set up in such a way that directly pulling it here works such that the
229+
// crate uses the this crate as its libcore.
229230
#[allow(unused_macros)]
230231
macro_rules! test_v16 { ($item:item) => {}; }
231232
#[allow(unused_macros)]
@@ -240,10 +241,10 @@ macro_rules! test_v256 { ($item:item) => {}; }
240241
macro_rules! test_v512 { ($item:item) => {}; }
241242
#[allow(unused_macros)]
242243
macro_rules! vector_impl { ($([$f:ident, $($args:tt)*]),*) => { $($f!($($args)*);)* } }
243-
#[path = "../stdsimd/coresimd/mod.rs"]
244+
#[path = "../stdsimd/crates/core_arch/src/mod.rs"]
244245
#[allow(missing_docs, missing_debug_implementations, dead_code, unused_imports)]
245246
#[unstable(feature = "stdsimd", issue = "48556")]
246-
mod coresimd;
247+
mod core_arch;
247248

248249
#[stable(feature = "simd_arch", since = "1.27.0")]
249-
pub use coresimd::arch;
250+
pub use core_arch::arch;

‎src/libstd/lib.rs

+13-17
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,9 @@ pub mod prelude;
358358
// Public module declarations and re-exports
359359
#[stable(feature = "rust1", since = "1.0.0")]
360360
pub use core::any;
361+
#[stable(feature = "simd_arch", since = "1.27.0")]
362+
#[doc(no_inline)]
363+
pub use core::arch;
361364
#[stable(feature = "rust1", since = "1.0.0")]
362365
pub use core::cell;
363366
#[stable(feature = "rust1", since = "1.0.0")]
@@ -489,29 +492,22 @@ mod memchr;
489492
// compiler
490493
pub mod rt;
491494

492-
// Pull in the `stdsimd` crate directly into libstd. This is the same as
493-
// libcore's arch/simd modules where the source of truth here is in a different
494-
// repository, but we pull things in here manually to get it into libstd.
495+
// Pull in the `std_detect` crate directly into libstd. The contents of
496+
// `std_detect` are in a different repository: rust-lang-nursery/stdsimd.
495497
//
496-
// Note that the #[cfg] here is intended to do two things. First it allows us to
497-
// change the rustc implementation of intrinsics in stage0 by not compiling simd
498-
// intrinsics in stage0. Next it doesn't compile anything in test mode as
499-
// stdsimd has tons of its own tests which we don't want to run.
500-
#[path = "../stdsimd/stdsimd/mod.rs"]
498+
// `std_detect` depends on libstd, but the contents of this module are
499+
// set up in such a way that directly pulling it here works such that the
500+
// crate uses the this crate as its libstd.
501+
#[path = "../stdsimd/crates/std_detect/src/mod.rs"]
501502
#[allow(missing_debug_implementations, missing_docs, dead_code)]
502503
#[unstable(feature = "stdsimd", issue = "48556")]
503504
#[cfg(not(test))]
504-
mod stdsimd;
505-
506-
// A "fake" module needed by the `stdsimd` module to compile, not actually
507-
// exported though.
508-
mod coresimd {
509-
pub use core::arch;
510-
}
505+
mod std_detect;
511506

512-
#[stable(feature = "simd_arch", since = "1.27.0")]
507+
#[doc(hidden)]
508+
#[unstable(feature = "stdsimd", issue = "48556")]
513509
#[cfg(not(test))]
514-
pub use stdsimd::arch;
510+
pub use std_detect::detect;
515511

516512
// Include a number of private modules that exist solely to provide
517513
// the rustdoc documentation for primitive types. Using `include!`

‎src/libstd/tests/run-time-detect.rs

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
//! These tests just check that the macros are available in libstd.
2+
3+
#![cfg_attr(
4+
any(
5+
all(target_arch = "arm", any(target_os = "linux", target_os = "android")),
6+
all(target_arch = "aarch64", any(target_os = "linux", target_os = "android")),
7+
all(target_arch = "powerpc", target_os = "linux"),
8+
all(target_arch = "powerpc64", target_os = "linux"),
9+
),
10+
feature(stdsimd)
11+
)]
12+
13+
#[test]
14+
#[cfg(all(target_arch = "arm",
15+
any(target_os = "linux", target_os = "android")))]
16+
fn arm_linux() {
17+
println!("neon: {}", is_arm_feature_detected!("neon"));
18+
println!("pmull: {}", is_arm_feature_detected!("pmull"));
19+
}
20+
21+
#[test]
22+
#[cfg(all(
23+
target_arch = "aarch64",
24+
any(target_os = "linux", target_os = "android")
25+
))]
26+
fn aarch64_linux() {
27+
println!("fp: {}", is_aarch64_feature_detected!("fp"));
28+
println!("fp16: {}", is_aarch64_feature_detected!("fp16"));
29+
println!("neon: {}", is_aarch64_feature_detected!("neon"));
30+
println!("asimd: {}", is_aarch64_feature_detected!("asimd"));
31+
println!("sve: {}", is_aarch64_feature_detected!("sve"));
32+
println!("crc: {}", is_aarch64_feature_detected!("crc"));
33+
println!("crypto: {}", is_aarch64_feature_detected!("crypto"));
34+
println!("lse: {}", is_aarch64_feature_detected!("lse"));
35+
println!("rdm: {}", is_aarch64_feature_detected!("rdm"));
36+
println!("rcpc: {}", is_aarch64_feature_detected!("rcpc"));
37+
println!("dotprod: {}", is_aarch64_feature_detected!("dotprod"));
38+
}
39+
40+
#[test]
41+
#[cfg(all(target_arch = "powerpc", target_os = "linux"))]
42+
fn powerpc_linux() {
43+
println!("altivec: {}", is_powerpc_feature_detected!("altivec"));
44+
println!("vsx: {}", is_powerpc_feature_detected!("vsx"));
45+
println!("power8: {}", is_powerpc_feature_detected!("power8"));
46+
}
47+
48+
#[test]
49+
#[cfg(all(target_arch = "powerpc64", target_os = "linux"))]
50+
fn powerpc64_linux() {
51+
println!("altivec: {}", is_powerpc64_feature_detected!("altivec"));
52+
println!("vsx: {}", is_powerpc64_feature_detected!("vsx"));
53+
println!("power8: {}", is_powerpc64_feature_detected!("power8"));
54+
}
55+
56+
#[test]
57+
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
58+
fn x86_all() {
59+
println!("aes: {:?}", is_x86_feature_detected!("aes"));
60+
println!("pcmulqdq: {:?}", is_x86_feature_detected!("pclmulqdq"));
61+
println!("rdrand: {:?}", is_x86_feature_detected!("rdrand"));
62+
println!("rdseed: {:?}", is_x86_feature_detected!("rdseed"));
63+
println!("tsc: {:?}", is_x86_feature_detected!("tsc"));
64+
println!("mmx: {:?}", is_x86_feature_detected!("mmx"));
65+
println!("sse: {:?}", is_x86_feature_detected!("sse"));
66+
println!("sse2: {:?}", is_x86_feature_detected!("sse2"));
67+
println!("sse3: {:?}", is_x86_feature_detected!("sse3"));
68+
println!("ssse3: {:?}", is_x86_feature_detected!("ssse3"));
69+
println!("sse4.1: {:?}", is_x86_feature_detected!("sse4.1"));
70+
println!("sse4.2: {:?}", is_x86_feature_detected!("sse4.2"));
71+
println!("sse4a: {:?}", is_x86_feature_detected!("sse4a"));
72+
println!("sha: {:?}", is_x86_feature_detected!("sha"));
73+
println!("avx: {:?}", is_x86_feature_detected!("avx"));
74+
println!("avx2: {:?}", is_x86_feature_detected!("avx2"));
75+
println!("avx512f {:?}", is_x86_feature_detected!("avx512f"));
76+
println!("avx512cd {:?}", is_x86_feature_detected!("avx512cd"));
77+
println!("avx512er {:?}", is_x86_feature_detected!("avx512er"));
78+
println!("avx512pf {:?}", is_x86_feature_detected!("avx512pf"));
79+
println!("avx512bw {:?}", is_x86_feature_detected!("avx512bw"));
80+
println!("avx512dq {:?}", is_x86_feature_detected!("avx512dq"));
81+
println!("avx512vl {:?}", is_x86_feature_detected!("avx512vl"));
82+
println!("avx512_ifma {:?}", is_x86_feature_detected!("avx512ifma"));
83+
println!("avx512_vbmi {:?}", is_x86_feature_detected!("avx512vbmi"));
84+
println!(
85+
"avx512_vpopcntdq {:?}",
86+
is_x86_feature_detected!("avx512vpopcntdq")
87+
);
88+
println!("fma: {:?}", is_x86_feature_detected!("fma"));
89+
println!("bmi1: {:?}", is_x86_feature_detected!("bmi1"));
90+
println!("bmi2: {:?}", is_x86_feature_detected!("bmi2"));
91+
println!("abm: {:?}", is_x86_feature_detected!("abm"));
92+
println!("lzcnt: {:?}", is_x86_feature_detected!("lzcnt"));
93+
println!("tbm: {:?}", is_x86_feature_detected!("tbm"));
94+
println!("popcnt: {:?}", is_x86_feature_detected!("popcnt"));
95+
println!("fxsr: {:?}", is_x86_feature_detected!("fxsr"));
96+
println!("xsave: {:?}", is_x86_feature_detected!("xsave"));
97+
println!("xsaveopt: {:?}", is_x86_feature_detected!("xsaveopt"));
98+
println!("xsaves: {:?}", is_x86_feature_detected!("xsaves"));
99+
println!("xsavec: {:?}", is_x86_feature_detected!("xsavec"));
100+
}

‎src/stdsimd

‎src/tools/tidy/src/pal.rs

+2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ const EXCEPTION_PATHS: &[&str] = &[
5252
"src/libstd/path.rs",
5353
"src/libstd/f32.rs",
5454
"src/libstd/f64.rs",
55+
// Integration test for platform-specific run-time feature detection:
56+
"src/libstd/tests/run-time-detect.rs" ,
5557
"src/libstd/sys_common/mod.rs",
5658
"src/libstd/sys_common/net.rs",
5759
"src/libterm", // Not sure how to make this crate portable, but test crate needs it.

0 commit comments

Comments
 (0)
Please sign in to comment.