Skip to content

Commit

Permalink
Rollup merge of rust-lang#48513 - alexcrichton:simd, r=JoshTriplett
Browse files Browse the repository at this point in the history
std: Add `arch` and `simd` modules

This commit imports the `stdsimd` crate into the standard library,
creating an `arch` and `simd` module inside of both libcore and libstd.
Both of these modules are **unstable** and will continue to be so until
RFC 2335 is stabilized.

As a brief recap, the modules are organized as so:

* `arch` contains all current architectures with intrinsics, for example
  `std::arch::x86`, `std::arch::x86_64`, `std::arch::arm`, etc. These
  modules contain all of the intrinsics defined for the platform, like
  `_mm_set1_epi8`.
* In the standard library, the `arch` module also exports a
  `is_target_feature_detected` macro which performs runtime detection to
  determine whether a target feature is available at runtime.
* The `simd` module contains experimental versions of strongly-typed
  lane-aware SIMD primitives, to be fully fleshed out in a future RFC.

The main purpose of this commit is to start pulling in all these
intrinsics and such into the standard library on nightly and allow
testing and such. This'll help allow users to easily kick the tires and
see if intrinsics work as well as allow us to test out all the
infrastructure for moving the intrinsics into the standard library.
  • Loading branch information
kennytm committed Mar 3, 2018
2 parents e71c96f + c72537f commit 6f07aaa
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,6 @@
[submodule "src/llvm-emscripten"]
path = src/llvm-emscripten
url = https://github.com/rust-lang/llvm
[submodule "src/stdsimd"]
path = src/stdsimd
url = https://github.com/rust-lang-nursery/stdsimd
33 changes: 29 additions & 4 deletions src/libcore/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,32 +68,39 @@
#![feature(allow_internal_unstable)]
#![feature(asm)]
#![feature(associated_type_defaults)]
#![feature(attr_literals)]
#![feature(cfg_target_feature)]
#![feature(cfg_target_has_atomic)]
#![feature(concat_idents)]
#![feature(const_fn)]
#![feature(custom_attribute)]
#![feature(doc_spotlight)]
#![feature(fundamental)]
#![feature(i128_type)]
#![feature(inclusive_range_syntax)]
#![feature(intrinsics)]
#![feature(iterator_flatten)]
#![feature(iterator_repeat_with)]
#![feature(lang_items)]
#![feature(link_llvm_intrinsics)]
#![feature(never_type)]
#![feature(no_core)]
#![feature(on_unimplemented)]
#![feature(optin_builtin_traits)]
#![feature(prelude_import)]
#![feature(repr_simd, platform_intrinsics)]
#![feature(rustc_attrs)]
#![feature(rustc_const_unstable)]
#![feature(simd_ffi)]
#![feature(specialization)]
#![feature(staged_api)]
#![feature(stmt_expr_attributes)]
#![feature(target_feature)]
#![feature(unboxed_closures)]
#![feature(untagged_unions)]
#![feature(unwind_attributes)]
#![feature(doc_spotlight)]
#![feature(rustc_const_unstable)]
#![feature(iterator_repeat_with)]
#![feature(iterator_flatten)]

#![cfg_attr(stage0, allow(unused_attributes))]

#[prelude_import]
#[allow(unused)]
Expand Down Expand Up @@ -179,3 +186,21 @@ mod char_private;
mod iter_private;
mod tuple;
mod unit;

// Pull in the the `coresimd` crate directly into libcore. This is where all the
// architecture-specific (and vendor-specific) intrinsics are defined. AKA
// things like SIMD and such. Note that the actual source for all this lies in a
// different repository, rust-lang-nursery/stdsimd. That's why the setup here is
// a bit wonky.
#[path = "../stdsimd/coresimd/mod.rs"]
#[allow(missing_docs, missing_debug_implementations, dead_code)]
#[unstable(feature = "stdsimd", issue = "48556")]
#[cfg(not(stage0))] // allow changes to how stdsimd works in stage0
mod coresimd;

#[unstable(feature = "stdsimd", issue = "48556")]
#[cfg(not(stage0))]
pub use coresimd::simd;
#[unstable(feature = "stdsimd", issue = "48556")]
#[cfg(not(stage0))]
pub use coresimd::arch;
30 changes: 30 additions & 0 deletions src/libstd/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@
#![feature(rand)]
#![feature(raw)]
#![feature(rustc_attrs)]
#![feature(stdsimd)]
#![feature(sip_hash_13)]
#![feature(slice_bytes)]
#![feature(slice_concat_ext)]
Expand Down Expand Up @@ -501,6 +502,35 @@ mod memchr;
// compiler
pub mod rt;

// Pull in the the `stdsimd` crate directly into libstd. This is the same as
// libcore's arch/simd modules where the source of truth here is in a different
// repository, but we pull things in here manually to get it into libstd.
//
// Note that the #[cfg] here is intended to do two things. First it allows us to
// change the rustc implementation of intrinsics in stage0 by not compiling simd
// intrinsics in stage0. Next it doesn't compile anything in test mode as
// stdsimd has tons of its own tests which we don't want to run.
#[path = "../stdsimd/stdsimd/mod.rs"]
#[allow(missing_debug_implementations, missing_docs, dead_code)]
#[unstable(feature = "stdsimd", issue = "48556")]
#[cfg(all(not(stage0), not(test)))]
mod stdsimd;

// A "fake" module needed by the `stdsimd` module to compile, not actually
// exported though.
#[cfg(not(stage0))]
mod coresimd {
pub use core::arch;
pub use core::simd;
}

#[unstable(feature = "stdsimd", issue = "48556")]
#[cfg(all(not(stage0), not(test)))]
pub use stdsimd::simd;
#[unstable(feature = "stdsimd", issue = "48556")]
#[cfg(all(not(stage0), not(test)))]
pub use stdsimd::arch;

// Include a number of private modules that exist solely to provide
// the rustdoc documentation for primitive types. Using `include!`
// because rustdoc only looks for these modules at the crate level.
Expand Down
1 change: 1 addition & 0 deletions src/stdsimd
Submodule stdsimd added at 678cbd
1 change: 1 addition & 0 deletions src/tools/tidy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ fn filter_dirs(path: &Path) -> bool {
"src/librustc/mir/interpret",
"src/librustc_mir/interpret",
"src/target",
"src/stdsimd",
];
skip.iter().any(|p| path.ends_with(p))
}
Expand Down

0 comments on commit 6f07aaa

Please sign in to comment.