Skip to content

[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

Merged
merged 7 commits into from
Nov 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Cargo.lock
.*.swp
/target
tags
target
tags
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ matrix:
- os: osx
env: TARGET=x86_64-apple-darwin NO_ADD=1
script: ci/run.sh
- install: true
- env: DOCUMENTATION
install: true
script: ci/dox.sh
- env: RUSTFMT=On TARGET=x86_64-unknown-linux-gnu NO_ADD=1
script: |
Expand Down
23 changes: 11 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stdsimd always requires std now

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/" }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've set the first version of coresimd to 0.0.3 to match that of stdsimd, we should release these together.


[profile.release]
debug = true
opt-level = 3
Expand All @@ -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" ]
5 changes: 4 additions & 1 deletion ci/dox.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now rustdoc needs a build of the coresimd to generate the docs for stdsimd. I haven't taken a detailed look at the docs, and haven't looked at the output of this at all. cargo doc seems to work just fine for stdsimd, wrapping the docs of both crates nicely, although some links on coresimd are still pointing to stdsimd.

}

dox i686 i686-unknown-linux-gnu
Expand Down
11 changes: 6 additions & 5 deletions ci/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ case ${TARGET} in
esac

FEATURES="strict,$FEATURES"
FEATURES_STD="$std,${FEATURES}"

echo "RUSTFLAGS=${RUSTFLAGS}"
echo "FEATURES=${FEATURES}"
echo "OBJDUMP=${OBJDUMP}"

cargo test --target $TARGET --features $FEATURES --verbose -- --nocapture
cargo test --release --target $TARGET --features $FEATURES --verbose -- --nocapture
cargo_test() {
cmd="cargo test --all --target=$TARGET --features $FEATURES --verbose $1 -- --nocapture $2"
$cmd
}

cargo test --target $TARGET --features $FEATURES_STD --verbose -- --nocapture
cargo test --release --target $TARGET --features $FEATURES_STD --verbose -- --nocapture
cargo_test
cargo_test "--release"
30 changes: 30 additions & 0 deletions coresimd/Cargo.toml
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 = []
1 change: 1 addition & 0 deletions coresimd/LICENSE-APACHE
1 change: 1 addition & 0 deletions coresimd/LICENSE-MIT
1 change: 1 addition & 0 deletions coresimd/README.md
1 change: 1 addition & 0 deletions coresimd/rustfmt.toml
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
231 changes: 231 additions & 0 deletions coresimd/src/lib.rs
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These docs still need to be updated to reflect coresimd instead of stdsimd.


#![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};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In coresimd only x86's run-time is available, stdsimd just re-exports it.

}

#[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;
File renamed without changes.
File renamed without changes.
11 changes: 11 additions & 0 deletions coresimd/src/runtime/bit.rs
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
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is duplicated in coresimd and stdsimd...

Loading