Skip to content

Commit

Permalink
Merge pull request rust-lang#81 from rust-lang/feature/std-cargo-feature
Browse files Browse the repository at this point in the history
Add std cargo feature
  • Loading branch information
workingjubilee authored Mar 22, 2021
2 parents d95433d + fa77b19 commit 65c3ce9
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
4 changes: 4 additions & 0 deletions crates/core_simd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ keywords = ["core", "simd", "intrinsics"]
categories = ["hardware-support", "no-std"]
license = "MIT OR Apache-2.0"

[features]
default = ["std"]
std = []

[target.'cfg(target_arch = "wasm32")'.dev-dependencies.wasm-bindgen]
version = "0.2"

Expand Down
2 changes: 2 additions & 0 deletions crates/core_simd/src/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ extern "platform-intrinsic" {
pub(crate) fn simd_cast<T, U>(x: T) -> U;

// floor
#[cfg(feature = "std")]
pub(crate) fn simd_floor<T>(x: T) -> T;

// ceil
#[cfg(feature = "std")]
pub(crate) fn simd_ceil<T>(x: T) -> T;

pub(crate) fn simd_eq<T, U>(x: T, y: T) -> U;
Expand Down
2 changes: 2 additions & 0 deletions crates/core_simd/src/round.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ macro_rules! implement {
Self: crate::LanesAtMost64,
{
/// Returns the largest integer less than or equal to each lane.
#[cfg(feature = "std")]
#[must_use = "method returns a new vector and does not mutate the original value"]
#[inline]
pub fn floor(self) -> Self {
unsafe { crate::intrinsics::simd_floor(self) }
}

/// Returns the smallest integer greater than or equal to each lane.
#[cfg(feature = "std")]
#[must_use = "method returns a new vector and does not mutate the original value"]
#[inline]
pub fn ceil(self) -> Self {
Expand Down
19 changes: 11 additions & 8 deletions crates/core_simd/tests/ops_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,15 +265,8 @@ macro_rules! impl_float_tests {
impl_binary_op_test!(Vector<LANES>, Scalar, Div::div, DivAssign::div_assign);
impl_binary_op_test!(Vector<LANES>, Scalar, Rem::rem, RemAssign::rem_assign);

#[cfg(feature = "std")]
test_helpers::test_lanes! {
fn abs<const LANES: usize>() {
test_helpers::test_unary_elementwise(
&Vector::<LANES>::abs,
&Scalar::abs,
&|_| true,
)
}

fn ceil<const LANES: usize>() {
test_helpers::test_unary_elementwise(
&Vector::<LANES>::ceil,
Expand All @@ -289,6 +282,16 @@ macro_rules! impl_float_tests {
&|_| true,
)
}
}

test_helpers::test_lanes! {
fn abs<const LANES: usize>() {
test_helpers::test_unary_elementwise(
&Vector::<LANES>::abs,
&Scalar::abs,
&|_| true,
)
}

fn round_from_int<const LANES: usize>() {
test_helpers::test_unary_elementwise(
Expand Down

0 comments on commit 65c3ce9

Please sign in to comment.