-
Notifications
You must be signed in to change notification settings - Fork 289
[coresimd] extracts the no_std components into the coresimd crate #197
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
Changes from all commits
3fc4c61
1fabed5
31c2291
8597062
5a8322c
a8d45e4
926874d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
Cargo.lock | ||
.*.swp | ||
/target | ||
tags | ||
target | ||
tags |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,22 +2,27 @@ | |
name = "stdsimd" | ||
version = "0.0.3" | ||
authors = ["Andrew Gallant <[email protected]>"] | ||
description = "Experiments for adding SIMD support to Rust's standard library." | ||
description = "SIMD support in Rust's standard library." | ||
documentation = "https://docs.rs/stdsimd" | ||
homepage = "https://github.com/BurntSushi/stdsimd" | ||
repository = "https://github.com/BurntSushi/stdsimd" | ||
readme = "README.md" | ||
keywords = ["std", "simd", "intrinsics"] | ||
categories = ["hardware-support", "no-std"] | ||
categories = ["hardware-support"] | ||
license = "MIT/Apache-2.0" | ||
|
||
[workspace] | ||
|
||
[badges] | ||
travis-ci = { repository = "BurntSushi/stdsimd" } | ||
appveyor = { repository = "BurntSushi/stdsimd" } | ||
is-it-maintained-issue-resolution = { repository = "BurntSushi/stdsimd" } | ||
is-it-maintained-open-issues = { repository = "BurntSushi/stdsimd" } | ||
maintenance = { status = "experimental" } | ||
|
||
[dependencies] | ||
coresimd = { version = "0.0.3", path = "coresimd/" } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've set the first version of |
||
|
||
[profile.release] | ||
debug = true | ||
opt-level = 3 | ||
|
@@ -26,15 +31,9 @@ opt-level = 3 | |
debug = true | ||
opt-level = 3 | ||
|
||
[dev-dependencies] | ||
stdsimd-test = { version = "0.*", path = "stdsimd-test" } | ||
cupid = "0.5.0" | ||
|
||
[features] | ||
std = [] | ||
|
||
# Internal-only: denies all warnings. | ||
strict = [] | ||
# Internal-only: enables only those intrinsics supported by Intel's | ||
# Internal-usage only: denies all warnings. | ||
strict = [ "coresimd/strict" ] | ||
# Internal-usage only: enables only those intrinsics supported by Intel's | ||
# Software Development Environment (SDE). | ||
intel_sde = [] | ||
intel_sde = [ "coresimd/intel_sde" ] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,10 @@ dox() { | |
rm -rf target/doc/$arch | ||
mkdir target/doc/$arch | ||
|
||
rustdoc --target $target -o target/doc/$arch src/lib.rs --crate-name stdsimd | ||
cargo clean | ||
cargo build --target $target | ||
|
||
rustdoc --target $target -o target/doc/$arch src/lib.rs --crate-name stdsimd --library-path target/$target/debug/deps | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now |
||
} | ||
|
||
dox i686 i686-unknown-linux-gnu | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
[package] | ||
name = "coresimd" | ||
version = "0.0.3" | ||
authors = ["Andrew Gallant <[email protected]>"] | ||
description = "SIMD support in Rust's core library." | ||
documentation = "https://docs.rs/stdsimd" | ||
homepage = "https://github.com/BurntSushi/stdsimd" | ||
repository = "https://github.com/BurntSushi/stdsimd" | ||
readme = "README.md" | ||
keywords = ["core", "simd", "intrinsics"] | ||
categories = ["hardware-support", "no-std"] | ||
license = "MIT/Apache-2.0" | ||
|
||
[badges] | ||
travis-ci = { repository = "BurntSushi/stdsimd" } | ||
appveyor = { repository = "BurntSushi/stdsimd" } | ||
is-it-maintained-issue-resolution = { repository = "BurntSushi/stdsimd" } | ||
is-it-maintained-open-issues = { repository = "BurntSushi/stdsimd" } | ||
maintenance = { status = "experimental" } | ||
|
||
[dev-dependencies] | ||
cupid = "0.5.0" | ||
stdsimd-test = { version = "0.*", path = "../stdsimd-test" } | ||
|
||
[features] | ||
# Internal-usage only: denies all warnings. | ||
strict = [] | ||
# Internal-usage only: enables only those intrinsics supported by Intel's | ||
# Software Development Environment (SDE). | ||
intel_sde = [] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../LICENSE-APACHE |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../LICENSE-MIT |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../README.md |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../rustfmt.toml |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,231 @@ | ||
//! SIMD support | ||
//! | ||
//! This crate provides the fundamentals of supporting SIMD in Rust. This crate | ||
//! should compile on all platforms and provide `simd` and `vendor` modules at | ||
//! the top-level. The `simd` module contains *portable vector types* which | ||
//! should work across all platforms and be implemented in the most efficient | ||
//! manner possible for the platform at hand. The `vendor` module contains | ||
//! vendor intrinsics that operate over these SIMD types, typically | ||
//! corresponding to a particular CPU instruction | ||
//! | ||
//! ```rust | ||
//! extern crate coresimd as stdsimd; | ||
//! use stdsimd::simd::u32x4; | ||
//! | ||
//! fn main() { | ||
//! let a = u32x4::new(1, 2, 3, 4); | ||
//! let b = u32x4::splat(10); | ||
//! assert_eq!(a + b, u32x4::new(11, 12, 13, 14)); | ||
//! } | ||
//! ``` | ||
//! | ||
//! > **Note**: This crate is *nightly only* at the moment, and requires a | ||
//! > nightly rust toolchain to compile. | ||
//! | ||
//! This documentation is only for one particular architecture, you can find | ||
//! others at: | ||
//! | ||
//! * [i686](https://rust-lang-nursery.github.io/stdsimd/i686/stdsimd/) | ||
//! * [`x86_64`](https://rust-lang-nursery.github.io/stdsimd/x86_64/stdsimd/) | ||
//! * [arm](https://rust-lang-nursery.github.io/stdsimd/arm/stdsimd/) | ||
//! * [aarch64](https://rust-lang-nursery.github.io/stdsimd/aarch64/stdsimd/) | ||
//! | ||
//! ## Portability | ||
//! | ||
//! The `simd` module and its types should be portable to all platforms. The | ||
//! runtime characteristics of these types may vary per platform and per CPU | ||
//! feature enabled, but they should always have the most optimized | ||
//! implementation for the target at hand. | ||
//! | ||
//! The `vendor` module provides no portability guarantees. The `vendor` module | ||
//! is per CPU architecture currently and provides intrinsics corresponding to | ||
//! functions for that particular CPU architecture. Note that the functions | ||
//! provided in this module are intended to correspond to CPU instructions and | ||
//! have no runtime support for whether you CPU actually supports the | ||
//! instruction. | ||
//! | ||
//! CPU target feature detection is done via the `cfg_feature_enabled!` macro | ||
//! at runtime. This macro will detect at runtime whether the specified feature | ||
//! is available or not, returning true or false depending on the current CPU. | ||
//! | ||
//! ``` | ||
//! #![feature(cfg_target_feature)] | ||
//! | ||
//! #[macro_use] | ||
//! extern crate coresimd as stdsimd; | ||
//! | ||
//! fn main() { | ||
//! if cfg_feature_enabled!("avx2") { | ||
//! println!("avx2 intrinsics will work"); | ||
//! } else { | ||
//! println!("avx2 intrinsics will not work"); | ||
//! // undefined behavior: may generate a `SIGILL`. | ||
//! } | ||
//! } | ||
//! ``` | ||
//! | ||
//! After verifying that a specified feature is available, use `target_feature` | ||
//! to enable a given feature and use the desired intrinsic. | ||
//! | ||
//! ```ignore | ||
//! # #![feature(cfg_target_feature)] | ||
//! # #![feature(target_feature)] | ||
//! # #[macro_use] | ||
//! # extern crate coresimd as stdsimd; | ||
//! # fn main() { | ||
//! # if cfg_feature_enabled!("avx2") { | ||
//! // avx2 specific code may be used in this function | ||
//! #[target_feature = "+avx2"] | ||
//! fn and_256() { | ||
//! // avx2 feature specific intrinsics will work here! | ||
//! use stdsimd::vendor::{__m256i, _mm256_and_si256}; | ||
//! | ||
//! let a = __m256i::splat(5); | ||
//! let b = __m256i::splat(3); | ||
//! | ||
//! let got = unsafe { _mm256_and_si256(a, b) }; | ||
//! | ||
//! assert_eq!(got, __m256i::splat(1)); | ||
//! } | ||
//! # and_256(); | ||
//! # } | ||
//! # } | ||
//! ``` | ||
//! | ||
//! # Status | ||
//! | ||
//! This crate is intended for eventual inclusion into the standard library, | ||
//! but some work and experimentation is needed to get there! First and | ||
//! foremost you can help out by kicking the tires on this crate and seeing if | ||
//! it works for your use case! Next up you can help us fill out the [vendor | ||
//! intrinsics][vendor] to ensure that we've got all the SIMD support | ||
//! necessary. | ||
//! | ||
//! The language support and status of SIMD is also still a little up in the | ||
//! air right now, you may be interested in a few issues along these lines: | ||
//! | ||
//! * [Overal tracking issue for SIMD support][simd_tracking_issue] | ||
//! * [`cfg_target_feature` tracking issue][cfg_target_feature_issue] | ||
//! * [SIMD types currently not sound][simd_soundness_bug] | ||
//! * [`#[target_feature]` improvements][target_feature_impr] | ||
//! | ||
//! [vendor]: https://github.com/rust-lang-nursery/stdsimd/issues/40 | ||
//! [simd_tracking_issue]: https://github.com/rust-lang/rust/issues/27731 | ||
//! [cfg_target_feature_issue]: https://github.com/rust-lang/rust/issues/29717 | ||
//! [simd_soundness_bug]: https://github.com/rust-lang/rust/issues/44367 | ||
//! [target_feature_impr]: https://github.com/rust-lang/rust/issues/44839 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These docs still need to be updated to reflect |
||
|
||
#![cfg_attr(feature = "strict", deny(warnings))] | ||
#![allow(dead_code)] | ||
#![allow(unused_features)] | ||
#![feature(const_fn, link_llvm_intrinsics, platform_intrinsics, repr_simd, | ||
simd_ffi, target_feature, cfg_target_feature, i128_type, asm, | ||
const_atomic_usize_new, stmt_expr_attributes)] | ||
#![cfg_attr(test, feature(proc_macro, test, repr_align, attr_literals))] | ||
#![cfg_attr(feature = "cargo-clippy", | ||
allow(inline_always, too_many_arguments, cast_sign_loss, | ||
cast_lossless, cast_possible_wrap, | ||
cast_possible_truncation, cast_precision_loss, | ||
shadow_reuse, cyclomatic_complexity, similar_names, | ||
many_single_char_names))] | ||
#![no_std] | ||
|
||
#[cfg(test)] | ||
#[macro_use] | ||
extern crate std; | ||
|
||
#[cfg(test)] | ||
extern crate stdsimd_test; | ||
|
||
#[cfg(test)] | ||
extern crate test; | ||
|
||
/// Platform independent SIMD vector types and operations. | ||
pub mod simd { | ||
pub use v128::*; | ||
pub use v256::*; | ||
pub use v512::*; | ||
pub use v64::*; | ||
} | ||
|
||
/// Platform dependent vendor intrinsics. | ||
pub mod vendor { | ||
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] | ||
pub use x86::*; | ||
|
||
#[cfg(any(target_arch = "arm", target_arch = "aarch64"))] | ||
pub use arm::*; | ||
|
||
#[cfg(target_arch = "aarch64")] | ||
pub use aarch64::*; | ||
|
||
// FIXME: rust does not expose the nvptx and nvptx64 targets yet | ||
#[cfg(not(any(target_arch = "x86", target_arch = "x86_64", | ||
target_arch = "arm", target_arch = "aarch64")))] | ||
pub use nvptx::*; | ||
|
||
#[cfg( | ||
// x86/x86_64: | ||
any(target_arch = "x86", target_arch = "x86_64") | ||
)] | ||
pub use runtime::{__unstable_detect_feature, __Feature}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In |
||
} | ||
|
||
#[cfg( | ||
// x86/x86_64: | ||
any(target_arch = "x86", target_arch = "x86_64") | ||
)] | ||
#[macro_use] | ||
mod runtime; | ||
|
||
#[macro_use] | ||
mod macros; | ||
mod simd_llvm; | ||
mod v128; | ||
mod v256; | ||
mod v512; | ||
mod v64; | ||
|
||
/// 32-bit wide vector tpyes | ||
mod v32 { | ||
use simd_llvm::*; | ||
|
||
define_ty! { i16x2, i16, i16 } | ||
define_impl! { i16x2, i16, 2, i16x2, x0, x1 } | ||
define_ty! { u16x2, u16, u16 } | ||
define_impl! { u16x2, u16, 2, i16x2, x0, x1 } | ||
|
||
define_ty! { i8x4, i8, i8, i8, i8 } | ||
define_impl! { i8x4, i8, 4, i8x4, x0, x1, x2, x3 } | ||
define_ty! { u8x4, u8, u8, u8, u8 } | ||
define_impl! { u8x4, u8, 4, i8x4, x0, x1, x2, x3 } | ||
|
||
define_casts!( | ||
(i16x2, i64x2, as_i64x2), | ||
(u16x2, i64x2, as_i64x2), | ||
(i8x4, i32x4, as_i32x4), | ||
(u8x4, i32x4, as_i32x4) | ||
); | ||
} | ||
|
||
/// 16-bit wide vector tpyes | ||
mod v16 { | ||
use simd_llvm::*; | ||
|
||
define_ty! { i8x2, i8, i8 } | ||
define_impl! { i8x2, i8, 2, i8x2, x0, x1 } | ||
define_ty! { u8x2, u8, u8 } | ||
define_impl! { u8x2, u8, 2, i8x2, x0, x1 } | ||
|
||
define_casts!((i8x2, i64x2, as_i64x2), (u8x2, i64x2, as_i64x2)); | ||
} | ||
|
||
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] | ||
mod x86; | ||
|
||
#[cfg(any(target_arch = "arm", target_arch = "aarch64"))] | ||
mod arm; | ||
#[cfg(target_arch = "aarch64")] | ||
mod aarch64; | ||
|
||
mod nvptx; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
//! Bit manipulation utilities | ||
|
||
/// Sets the `bit` of `x`. | ||
pub const fn set(x: usize, bit: u32) -> usize { | ||
x | 1 << bit | ||
} | ||
|
||
/// Tests the `bit` of `x`. | ||
pub const fn test(x: usize, bit: u32) -> bool { | ||
x & (1 << bit) != 0 | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file is duplicated in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stdsimd
always requiresstd
now