Skip to content

Commit 3fc4c61

Browse files
committed
refactor no_std components into the coresimd crate
1 parent 14cec94 commit 3fc4c61

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+470
-191
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@ Cargo.lock
22
.*.swp
33
/target
44
tags
5+
/coresimd/target
6+
/stdsimd-test/target
7+
/stdsimd-test/assert-instr-macro/target
8+
/stdsimd-test/simd-test-macro/target

.travis.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,15 @@ matrix:
2525
script: |
2626
cargo install clippy
2727
cargo clippy --all -- -D clippy-pedantic
28+
cd coresimd
29+
cargo clippy --all -- -D clippy-pedantic
2830
allow_failures:
2931
- env: RUSTFMT=On TARGET=x86_64-unknown-linux-gnu NO_ADD=1
3032
- env: CLIPPY=On TARGET=x86_64-unknown-linux-gnu NO_ADD=1
3133
install:
3234
- if [ "$NO_ADD" == "" ]; then rustup target add $TARGET; fi
3335

3436
script:
35-
- cargo generate-lockfile
3637
- ci/run-docker.sh $TARGET $FEATURES
3738

3839
notifications:

Cargo.toml

+9-8
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
name = "stdsimd"
33
version = "0.0.3"
44
authors = ["Andrew Gallant <[email protected]>"]
5-
description = "Experiments for adding SIMD support to Rust's standard library."
5+
description = "SIMD support in Rust's standard library."
66
documentation = "https://docs.rs/stdsimd"
77
homepage = "https://github.com/BurntSushi/stdsimd"
88
repository = "https://github.com/BurntSushi/stdsimd"
99
readme = "README.md"
1010
keywords = ["std", "simd", "intrinsics"]
11-
categories = ["hardware-support", "no-std"]
11+
categories = ["hardware-support"]
1212
license = "MIT/Apache-2.0"
1313

1414
[badges]
@@ -18,6 +18,9 @@ is-it-maintained-issue-resolution = { repository = "BurntSushi/stdsimd" }
1818
is-it-maintained-open-issues = { repository = "BurntSushi/stdsimd" }
1919
maintenance = { status = "experimental" }
2020

21+
[dependencies]
22+
coresimd = { version = "0.0.3", path = "coresimd/" }
23+
2124
[profile.release]
2225
debug = true
2326
opt-level = 3
@@ -31,10 +34,8 @@ stdsimd-test = { version = "0.*", path = "stdsimd-test" }
3134
cupid = "0.5.0"
3235

3336
[features]
34-
std = []
35-
36-
# Internal-only: denies all warnings.
37-
strict = []
38-
# Internal-only: enables only those intrinsics supported by Intel's
37+
# Internal-usage only: denies all warnings.
38+
strict = [ "coresimd/strict" ]
39+
# Internal-usage only: enables only those intrinsics supported by Intel's
3940
# Software Development Environment (SDE).
40-
intel_sde = []
41+
intel_sde = [ "coresimd/intel_sde" ]

ci/run-docker.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ run() {
1919
--env TARGET=$target \
2020
--env FEATURES=$2 \
2121
--env STDSIMD_TEST_EVERYTHING \
22-
--volume `pwd`:/checkout:ro \
22+
--volume `pwd`:/checkout \
2323
--volume `pwd`/target:/checkout/target \
2424
--workdir /checkout \
2525
--privileged \

ci/run.sh

+6-6
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ case ${TARGET} in
1616
esac
1717

1818
FEATURES="strict,$FEATURES"
19-
FEATURES_STD="$std,${FEATURES}"
2019

2120
echo "RUSTFLAGS=${RUSTFLAGS}"
2221
echo "FEATURES=${FEATURES}"
2322
echo "OBJDUMP=${OBJDUMP}"
2423

25-
cargo test --target $TARGET --features $FEATURES --verbose -- --nocapture
26-
cargo test --release --target $TARGET --features $FEATURES --verbose -- --nocapture
27-
28-
cargo test --target $TARGET --features $FEATURES_STD --verbose -- --nocapture
29-
cargo test --release --target $TARGET --features $FEATURES_STD --verbose -- --nocapture
24+
cd coresimd
25+
cargo test --all --target $TARGET --features $FEATURES --verbose -- --nocapture
26+
cargo test --all --release --target $TARGET --features $FEATURES --verbose -- --nocapture
27+
cd ..
28+
cargo test --all --target $TARGET --features $FEATURES --verbose -- --nocapture
29+
cargo test --all --release --target $TARGET --features $FEATURES --verbose -- --nocapture

coresimd/Cargo.toml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
[package]
2+
name = "coresimd"
3+
version = "0.0.3"
4+
authors = ["Andrew Gallant <[email protected]>"]
5+
description = "SIMD support in Rust's core library."
6+
documentation = "https://docs.rs/stdsimd"
7+
homepage = "https://github.com/BurntSushi/stdsimd"
8+
repository = "https://github.com/BurntSushi/stdsimd"
9+
readme = "README.md"
10+
keywords = ["core", "simd", "intrinsics"]
11+
categories = ["hardware-support", "no-std"]
12+
license = "MIT/Apache-2.0"
13+
14+
[badges]
15+
travis-ci = { repository = "BurntSushi/stdsimd" }
16+
appveyor = { repository = "BurntSushi/stdsimd" }
17+
is-it-maintained-issue-resolution = { repository = "BurntSushi/stdsimd" }
18+
is-it-maintained-open-issues = { repository = "BurntSushi/stdsimd" }
19+
maintenance = { status = "experimental" }
20+
21+
[dev-dependencies]
22+
stdsimd-test = { version = "0.*", path = "../stdsimd-test" }
23+
24+
[features]
25+
# Internal-usage only: denies all warnings.
26+
strict = []
27+
# Internal-usage only: enables only those intrinsics supported by Intel's
28+
# Software Development Environment (SDE).
29+
intel_sde = []

coresimd/LICENSE-APACHE

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../LICENSE-APACHE

coresimd/LICENSE-MIT

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../LICENSE-MIT

coresimd/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../README.md

coresimd/rustfmt.toml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../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.

coresimd/src/lib.rs

+231
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
//! SIMD support
2+
//!
3+
//! This crate provides the fundamentals of supporting SIMD in Rust. This crate
4+
//! should compile on all platforms and provide `simd` and `vendor` modules at
5+
//! the top-level. The `simd` module contains *portable vector types* which
6+
//! should work across all platforms and be implemented in the most efficient
7+
//! manner possible for the platform at hand. The `vendor` module contains
8+
//! vendor intrinsics that operate over these SIMD types, typically
9+
//! corresponding to a particular CPU instruction
10+
//!
11+
//! ```rust
12+
//! extern crate coresimd as stdsimd;
13+
//! use stdsimd::simd::u32x4;
14+
//!
15+
//! fn main() {
16+
//! let a = u32x4::new(1, 2, 3, 4);
17+
//! let b = u32x4::splat(10);
18+
//! assert_eq!(a + b, u32x4::new(11, 12, 13, 14));
19+
//! }
20+
//! ```
21+
//!
22+
//! > **Note**: This crate is *nightly only* at the moment, and requires a
23+
//! > nightly rust toolchain to compile.
24+
//!
25+
//! This documentation is only for one particular architecture, you can find
26+
//! others at:
27+
//!
28+
//! * [i686](https://rust-lang-nursery.github.io/stdsimd/i686/stdsimd/)
29+
//! * [`x86_64`](https://rust-lang-nursery.github.io/stdsimd/x86_64/stdsimd/)
30+
//! * [arm](https://rust-lang-nursery.github.io/stdsimd/arm/stdsimd/)
31+
//! * [aarch64](https://rust-lang-nursery.github.io/stdsimd/aarch64/stdsimd/)
32+
//!
33+
//! ## Portability
34+
//!
35+
//! The `simd` module and its types should be portable to all platforms. The
36+
//! runtime characteristics of these types may vary per platform and per CPU
37+
//! feature enabled, but they should always have the most optimized
38+
//! implementation for the target at hand.
39+
//!
40+
//! The `vendor` module provides no portability guarantees. The `vendor` module
41+
//! is per CPU architecture currently and provides intrinsics corresponding to
42+
//! functions for that particular CPU architecture. Note that the functions
43+
//! provided in this module are intended to correspond to CPU instructions and
44+
//! have no runtime support for whether you CPU actually supports the
45+
//! instruction.
46+
//!
47+
//! CPU target feature detection is done via the `cfg_feature_enabled!` macro
48+
//! at runtime. This macro will detect at runtime whether the specified feature
49+
//! is available or not, returning true or false depending on the current CPU.
50+
//!
51+
//! ```
52+
//! #![feature(cfg_target_feature)]
53+
//!
54+
//! #[macro_use]
55+
//! extern crate coresimd as stdsimd;
56+
//!
57+
//! fn main() {
58+
//! if cfg_feature_enabled!("avx2") {
59+
//! println!("avx2 intrinsics will work");
60+
//! } else {
61+
//! println!("avx2 intrinsics will not work");
62+
//! // undefined behavior: may generate a `SIGILL`.
63+
//! }
64+
//! }
65+
//! ```
66+
//!
67+
//! After verifying that a specified feature is available, use `target_feature`
68+
//! to enable a given feature and use the desired intrinsic.
69+
//!
70+
//! ```ignore
71+
//! # #![feature(cfg_target_feature)]
72+
//! # #![feature(target_feature)]
73+
//! # #[macro_use]
74+
//! # extern crate coresimd as stdsimd;
75+
//! # fn main() {
76+
//! # if cfg_feature_enabled!("avx2") {
77+
//! // avx2 specific code may be used in this function
78+
//! #[target_feature = "+avx2"]
79+
//! fn and_256() {
80+
//! // avx2 feature specific intrinsics will work here!
81+
//! use stdsimd::vendor::{__m256i, _mm256_and_si256};
82+
//!
83+
//! let a = __m256i::splat(5);
84+
//! let b = __m256i::splat(3);
85+
//!
86+
//! let got = unsafe { _mm256_and_si256(a, b) };
87+
//!
88+
//! assert_eq!(got, __m256i::splat(1));
89+
//! }
90+
//! # and_256();
91+
//! # }
92+
//! # }
93+
//! ```
94+
//!
95+
//! # Status
96+
//!
97+
//! This crate is intended for eventual inclusion into the standard library,
98+
//! but some work and experimentation is needed to get there! First and
99+
//! foremost you can help out by kicking the tires on this crate and seeing if
100+
//! it works for your use case! Next up you can help us fill out the [vendor
101+
//! intrinsics][vendor] to ensure that we've got all the SIMD support
102+
//! necessary.
103+
//!
104+
//! The language support and status of SIMD is also still a little up in the
105+
//! air right now, you may be interested in a few issues along these lines:
106+
//!
107+
//! * [Overal tracking issue for SIMD support][simd_tracking_issue]
108+
//! * [`cfg_target_feature` tracking issue][cfg_target_feature_issue]
109+
//! * [SIMD types currently not sound][simd_soundness_bug]
110+
//! * [`#[target_feature]` improvements][target_feature_impr]
111+
//!
112+
//! [vendor]: https://github.com/rust-lang-nursery/stdsimd/issues/40
113+
//! [simd_tracking_issue]: https://github.com/rust-lang/rust/issues/27731
114+
//! [cfg_target_feature_issue]: https://github.com/rust-lang/rust/issues/29717
115+
//! [simd_soundness_bug]: https://github.com/rust-lang/rust/issues/44367
116+
//! [target_feature_impr]: https://github.com/rust-lang/rust/issues/44839
117+
118+
#![cfg_attr(feature = "strict", deny(warnings))]
119+
#![allow(dead_code)]
120+
#![allow(unused_features)]
121+
#![feature(const_fn, link_llvm_intrinsics, platform_intrinsics, repr_simd,
122+
simd_ffi, target_feature, cfg_target_feature, i128_type, asm,
123+
const_atomic_usize_new, stmt_expr_attributes)]
124+
#![cfg_attr(test, feature(proc_macro, test, repr_align, attr_literals))]
125+
#![cfg_attr(feature = "cargo-clippy",
126+
allow(inline_always, too_many_arguments, cast_sign_loss,
127+
cast_lossless, cast_possible_wrap,
128+
cast_possible_truncation, cast_precision_loss,
129+
shadow_reuse, cyclomatic_complexity, similar_names,
130+
many_single_char_names))]
131+
#![no_std]
132+
133+
#[cfg(test)]
134+
#[macro_use]
135+
extern crate std;
136+
137+
#[cfg(test)]
138+
extern crate stdsimd_test;
139+
140+
#[cfg(test)]
141+
extern crate test;
142+
143+
/// Platform independent SIMD vector types and operations.
144+
pub mod simd {
145+
pub use v128::*;
146+
pub use v256::*;
147+
pub use v512::*;
148+
pub use v64::*;
149+
}
150+
151+
/// Platform dependent vendor intrinsics.
152+
pub mod vendor {
153+
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
154+
pub use x86::*;
155+
156+
#[cfg(any(target_arch = "arm", target_arch = "aarch64"))]
157+
pub use arm::*;
158+
159+
#[cfg(target_arch = "aarch64")]
160+
pub use aarch64::*;
161+
162+
// FIXME: rust does not expose the nvptx and nvptx64 targets yet
163+
#[cfg(not(any(target_arch = "x86", target_arch = "x86_64",
164+
target_arch = "arm", target_arch = "aarch64")))]
165+
pub use nvptx::*;
166+
167+
#[cfg(
168+
// x86/x86_64:
169+
any(target_arch = "x86", target_arch = "x86_64")
170+
)]
171+
pub use runtime::{__unstable_detect_feature, __Feature};
172+
}
173+
174+
#[cfg(
175+
// x86/x86_64:
176+
any(target_arch = "x86", target_arch = "x86_64")
177+
)]
178+
#[macro_use]
179+
mod runtime;
180+
181+
#[macro_use]
182+
mod macros;
183+
mod simd_llvm;
184+
mod v128;
185+
mod v256;
186+
mod v512;
187+
mod v64;
188+
189+
/// 32-bit wide vector tpyes
190+
mod v32 {
191+
use simd_llvm::*;
192+
193+
define_ty! { i16x2, i16, i16 }
194+
define_impl! { i16x2, i16, 2, i16x2, x0, x1 }
195+
define_ty! { u16x2, u16, u16 }
196+
define_impl! { u16x2, u16, 2, i16x2, x0, x1 }
197+
198+
define_ty! { i8x4, i8, i8, i8, i8 }
199+
define_impl! { i8x4, i8, 4, i8x4, x0, x1, x2, x3 }
200+
define_ty! { u8x4, u8, u8, u8, u8 }
201+
define_impl! { u8x4, u8, 4, i8x4, x0, x1, x2, x3 }
202+
203+
define_casts!(
204+
(i16x2, i64x2, as_i64x2),
205+
(u16x2, i64x2, as_i64x2),
206+
(i8x4, i32x4, as_i32x4),
207+
(u8x4, i32x4, as_i32x4)
208+
);
209+
}
210+
211+
/// 16-bit wide vector tpyes
212+
mod v16 {
213+
use simd_llvm::*;
214+
215+
define_ty! { i8x2, i8, i8 }
216+
define_impl! { i8x2, i8, 2, i8x2, x0, x1 }
217+
define_ty! { u8x2, u8, u8 }
218+
define_impl! { u8x2, u8, 2, i8x2, x0, x1 }
219+
220+
define_casts!((i8x2, i64x2, as_i64x2), (u8x2, i64x2, as_i64x2));
221+
}
222+
223+
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
224+
mod x86;
225+
226+
#[cfg(any(target_arch = "arm", target_arch = "aarch64"))]
227+
mod arm;
228+
#[cfg(target_arch = "aarch64")]
229+
mod aarch64;
230+
231+
mod nvptx;
File renamed without changes.
File renamed without changes.

coresimd/src/runtime/bit.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//! Bit manipulation utilities
2+
3+
/// Sets the `bit` of `x`.
4+
pub const fn set(x: usize, bit: u32) -> usize {
5+
x | 1 << bit
6+
}
7+
8+
/// Tests the `bit` of `x`.
9+
pub const fn test(x: usize, bit: u32) -> bool {
10+
x & (1 << bit) != 0
11+
}

0 commit comments

Comments
 (0)