Skip to content

Commit 4abbf01

Browse files
committed
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.
1 parent bedbad6 commit 4abbf01

File tree

5 files changed

+64
-4
lines changed

5 files changed

+64
-4
lines changed

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,6 @@
5050
[submodule "src/llvm-emscripten"]
5151
path = src/llvm-emscripten
5252
url = https://github.com/rust-lang/llvm
53+
[submodule "src/stdsimd"]
54+
path = src/stdsimd
55+
url = https://github.com/rust-lang-nursery/stdsimd

src/libcore/lib.rs

+29-4
Original file line numberDiff line numberDiff line change
@@ -68,32 +68,39 @@
6868
#![feature(allow_internal_unstable)]
6969
#![feature(asm)]
7070
#![feature(associated_type_defaults)]
71+
#![feature(attr_literals)]
7172
#![feature(cfg_target_feature)]
7273
#![feature(cfg_target_has_atomic)]
7374
#![feature(concat_idents)]
7475
#![feature(const_fn)]
7576
#![feature(custom_attribute)]
77+
#![feature(doc_spotlight)]
7678
#![feature(fundamental)]
7779
#![feature(i128_type)]
7880
#![feature(inclusive_range_syntax)]
7981
#![feature(intrinsics)]
82+
#![feature(iterator_flatten)]
83+
#![feature(iterator_repeat_with)]
8084
#![feature(lang_items)]
85+
#![feature(link_llvm_intrinsics)]
8186
#![feature(never_type)]
8287
#![feature(no_core)]
8388
#![feature(on_unimplemented)]
8489
#![feature(optin_builtin_traits)]
8590
#![feature(prelude_import)]
8691
#![feature(repr_simd, platform_intrinsics)]
8792
#![feature(rustc_attrs)]
93+
#![feature(rustc_const_unstable)]
94+
#![feature(simd_ffi)]
8895
#![feature(specialization)]
8996
#![feature(staged_api)]
97+
#![feature(stmt_expr_attributes)]
98+
#![feature(target_feature)]
9099
#![feature(unboxed_closures)]
91100
#![feature(untagged_unions)]
92101
#![feature(unwind_attributes)]
93-
#![feature(doc_spotlight)]
94-
#![feature(rustc_const_unstable)]
95-
#![feature(iterator_repeat_with)]
96-
#![feature(iterator_flatten)]
102+
103+
#![cfg_attr(stage0, allow(unused_attributes))]
97104

98105
#[prelude_import]
99106
#[allow(unused)]
@@ -179,3 +186,21 @@ mod char_private;
179186
mod iter_private;
180187
mod tuple;
181188
mod unit;
189+
190+
// Pull in the the `coresimd` crate directly into libcore. This is where all the
191+
// architecture-specific (and vendor-specific) intrinsics are defined. AKA
192+
// things like SIMD and such. Note that the actual source for all this lies in a
193+
// different repository, rust-lang-nursery/stdsimd. That's why the setup here is
194+
// a bit wonky.
195+
#[path = "../stdsimd/coresimd/mod.rs"]
196+
#[allow(missing_docs, missing_debug_implementations, dead_code)]
197+
#[unstable(feature = "stdsimd", issue = "48556")]
198+
#[cfg(not(stage0))] // allow changes to how stdsimd works in stage0
199+
mod coresimd;
200+
201+
#[unstable(feature = "stdsimd", issue = "48556")]
202+
#[cfg(not(stage0))]
203+
pub use coresimd::simd;
204+
#[unstable(feature = "stdsimd", issue = "48556")]
205+
#[cfg(not(stage0))]
206+
pub use coresimd::arch;

src/libstd/lib.rs

+30
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@
299299
#![feature(rand)]
300300
#![feature(raw)]
301301
#![feature(rustc_attrs)]
302+
#![feature(stdsimd)]
302303
#![feature(sip_hash_13)]
303304
#![feature(slice_bytes)]
304305
#![feature(slice_concat_ext)]
@@ -501,6 +502,35 @@ mod memchr;
501502
// compiler
502503
pub mod rt;
503504

505+
// Pull in the the `stdsimd` crate directly into libstd. This is the same as
506+
// libcore's arch/simd modules where the source of truth here is in a different
507+
// repository, but we pull things in here manually to get it into libstd.
508+
//
509+
// Note that the #[cfg] here is intended to do two things. First it allows us to
510+
// change the rustc implementation of intrinsics in stage0 by not compiling simd
511+
// intrinsics in stage0. Next it doesn't compile anything in test mode as
512+
// stdsimd has tons of its own tests which we don't want to run.
513+
#[path = "../stdsimd/stdsimd/mod.rs"]
514+
#[allow(missing_debug_implementations, missing_docs)]
515+
#[unstable(feature = "stdsimd", issue = "48556")]
516+
#[cfg(all(not(stage0), not(test)))]
517+
mod stdsimd;
518+
519+
// A "fake" module needed by the `stdsimd` module to compile, not actually
520+
// exported though.
521+
#[cfg(not(stage0))]
522+
mod coresimd {
523+
pub use core::arch;
524+
pub use core::simd;
525+
}
526+
527+
#[unstable(feature = "stdsimd", issue = "48556")]
528+
#[cfg(all(not(stage0), not(test)))]
529+
pub use stdsimd::simd;
530+
#[unstable(feature = "stdsimd", issue = "48556")]
531+
#[cfg(all(not(stage0), not(test)))]
532+
pub use stdsimd::arch;
533+
504534
// Include a number of private modules that exist solely to provide
505535
// the rustdoc documentation for primitive types. Using `include!`
506536
// because rustdoc only looks for these modules at the crate level.

src/stdsimd

Submodule stdsimd added at 78dd56a

src/tools/tidy/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ fn filter_dirs(path: &Path) -> bool {
7171
"src/librustc/mir/interpret",
7272
"src/librustc_mir/interpret",
7373
"src/target",
74+
"src/stdsimd",
7475
];
7576
skip.iter().any(|p| path.ends_with(p))
7677
}

0 commit comments

Comments
 (0)