Skip to content

Commit

Permalink
Remove aliases from most tests
Browse files Browse the repository at this point in the history
  • Loading branch information
calebzulawski committed Aug 7, 2021
1 parent 88f79d4 commit f7f2968
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 62 deletions.
2 changes: 1 addition & 1 deletion crates/core_simd/tests/f32_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

#[macro_use]
mod ops_macros;
impl_float_tests! { SimdF32, f32, i32 }
impl_float_tests! { f32, i32 }
2 changes: 1 addition & 1 deletion crates/core_simd/tests/f64_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

#[macro_use]
mod ops_macros;
impl_float_tests! { SimdF64, f64, i64 }
impl_float_tests! { f64, i64 }
2 changes: 1 addition & 1 deletion crates/core_simd/tests/i16_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

#[macro_use]
mod ops_macros;
impl_signed_tests! { SimdI16, i16 }
impl_signed_tests! { i16 }
2 changes: 1 addition & 1 deletion crates/core_simd/tests/i32_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

#[macro_use]
mod ops_macros;
impl_signed_tests! { SimdI32, i32 }
impl_signed_tests! { i32 }
2 changes: 1 addition & 1 deletion crates/core_simd/tests/i64_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

#[macro_use]
mod ops_macros;
impl_signed_tests! { SimdI64, i64 }
impl_signed_tests! { i64 }
2 changes: 1 addition & 1 deletion crates/core_simd/tests/i8_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

#[macro_use]
mod ops_macros;
impl_signed_tests! { SimdI8, i8 }
impl_signed_tests! { i8 }
2 changes: 1 addition & 1 deletion crates/core_simd/tests/isize_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

#[macro_use]
mod ops_macros;
impl_signed_tests! { SimdIsize, isize }
impl_signed_tests! { isize }
102 changes: 52 additions & 50 deletions crates/core_simd/tests/ops_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
/// Compares the vector operation to the equivalent scalar operation.
#[macro_export]
macro_rules! impl_unary_op_test {
{ $vector:ty, $scalar:ty, $trait:ident :: $fn:ident, $scalar_fn:expr } => {
{ $scalar:ty, $trait:ident :: $fn:ident, $scalar_fn:expr } => {
test_helpers::test_lanes! {
fn $fn<const LANES: usize>() {
test_helpers::test_unary_elementwise(
&<$vector as core::ops::$trait>::$fn,
&<core_simd::Simd<$scalar, LANES> as core::ops::$trait>::$fn,
&$scalar_fn,
&|_| true,
);
}
}
};
{ $vector:ty, $scalar:ty, $trait:ident :: $fn:ident } => {
impl_unary_op_test! { $vector, $scalar, $trait::$fn, <$scalar as core::ops::$trait>::$fn }
{ $scalar:ty, $trait:ident :: $fn:ident } => {
impl_unary_op_test! { $scalar, $trait::$fn, <$scalar as core::ops::$trait>::$fn }
};
}

Expand All @@ -24,55 +24,56 @@ macro_rules! impl_unary_op_test {
/// Compares the vector operation to the equivalent scalar operation.
#[macro_export]
macro_rules! impl_binary_op_test {
{ $vector:ty, $scalar:ty, $trait:ident :: $fn:ident, $trait_assign:ident :: $fn_assign:ident, $scalar_fn:expr } => {
{ $scalar:ty, $trait:ident :: $fn:ident, $trait_assign:ident :: $fn_assign:ident, $scalar_fn:expr } => {
mod $fn {
use super::*;
use core_simd::Simd;

test_helpers::test_lanes! {
fn normal<const LANES: usize>() {
test_helpers::test_binary_elementwise(
&<$vector as core::ops::$trait>::$fn,
&<Simd<$scalar, LANES> as core::ops::$trait>::$fn,
&$scalar_fn,
&|_, _| true,
);
}

fn scalar_rhs<const LANES: usize>() {
test_helpers::test_binary_scalar_rhs_elementwise(
&<$vector as core::ops::$trait<$scalar>>::$fn,
&<Simd<$scalar, LANES> as core::ops::$trait<$scalar>>::$fn,
&$scalar_fn,
&|_, _| true,
);
}

fn scalar_lhs<const LANES: usize>() {
test_helpers::test_binary_scalar_lhs_elementwise(
&<$scalar as core::ops::$trait<$vector>>::$fn,
&<$scalar as core::ops::$trait<Simd<$scalar, LANES>>>::$fn,
&$scalar_fn,
&|_, _| true,
);
}

fn assign<const LANES: usize>() {
test_helpers::test_binary_elementwise(
&|mut a, b| { <$vector as core::ops::$trait_assign>::$fn_assign(&mut a, b); a },
&|mut a, b| { <Simd<$scalar, LANES> as core::ops::$trait_assign>::$fn_assign(&mut a, b); a },
&$scalar_fn,
&|_, _| true,
);
}

fn assign_scalar_rhs<const LANES: usize>() {
test_helpers::test_binary_scalar_rhs_elementwise(
&|mut a, b| { <$vector as core::ops::$trait_assign<$scalar>>::$fn_assign(&mut a, b); a },
&|mut a, b| { <Simd<$scalar, LANES> as core::ops::$trait_assign<$scalar>>::$fn_assign(&mut a, b); a },
&$scalar_fn,
&|_, _| true,
);
}
}
}
};
{ $vector:ty, $scalar:ty, $trait:ident :: $fn:ident, $trait_assign:ident :: $fn_assign:ident } => {
impl_binary_op_test! { $vector, $scalar, $trait::$fn, $trait_assign::$fn_assign, <$scalar as core::ops::$trait>::$fn }
{ $scalar:ty, $trait:ident :: $fn:ident, $trait_assign:ident :: $fn_assign:ident } => {
impl_binary_op_test! { $scalar, $trait::$fn, $trait_assign::$fn_assign, <$scalar as core::ops::$trait>::$fn }
};
}

Expand All @@ -84,55 +85,56 @@ macro_rules! impl_binary_op_test {
/// Compares the vector operation to the equivalent scalar operation.
#[macro_export]
macro_rules! impl_binary_checked_op_test {
{ $vector:ty, $scalar:ty, $trait:ident :: $fn:ident, $trait_assign:ident :: $fn_assign:ident, $scalar_fn:expr, $check_fn:expr } => {
{ $scalar:ty, $trait:ident :: $fn:ident, $trait_assign:ident :: $fn_assign:ident, $scalar_fn:expr, $check_fn:expr } => {
mod $fn {
use super::*;
use core_simd::Simd;

test_helpers::test_lanes! {
fn normal<const LANES: usize>() {
test_helpers::test_binary_elementwise(
&<$vector as core::ops::$trait>::$fn,
&<Simd<$scalar, LANES> as core::ops::$trait>::$fn,
&$scalar_fn,
&|x, y| x.iter().zip(y.iter()).all(|(x, y)| $check_fn(*x, *y)),
);
}

fn scalar_rhs<const LANES: usize>() {
test_helpers::test_binary_scalar_rhs_elementwise(
&<$vector as core::ops::$trait<$scalar>>::$fn,
&<Simd<$scalar, LANES> as core::ops::$trait<$scalar>>::$fn,
&$scalar_fn,
&|x, y| x.iter().all(|x| $check_fn(*x, y)),
);
}

fn scalar_lhs<const LANES: usize>() {
test_helpers::test_binary_scalar_lhs_elementwise(
&<$scalar as core::ops::$trait<$vector>>::$fn,
&<$scalar as core::ops::$trait<Simd<$scalar, LANES>>>::$fn,
&$scalar_fn,
&|x, y| y.iter().all(|y| $check_fn(x, *y)),
);
}

fn assign<const LANES: usize>() {
test_helpers::test_binary_elementwise(
&|mut a, b| { <$vector as core::ops::$trait_assign>::$fn_assign(&mut a, b); a },
&|mut a, b| { <Simd<$scalar, LANES> as core::ops::$trait_assign>::$fn_assign(&mut a, b); a },
&$scalar_fn,
&|x, y| x.iter().zip(y.iter()).all(|(x, y)| $check_fn(*x, *y)),
)
}

fn assign_scalar_rhs<const LANES: usize>() {
test_helpers::test_binary_scalar_rhs_elementwise(
&|mut a, b| { <$vector as core::ops::$trait_assign<$scalar>>::$fn_assign(&mut a, b); a },
&|mut a, b| { <Simd<$scalar, LANES> as core::ops::$trait_assign<$scalar>>::$fn_assign(&mut a, b); a },
&$scalar_fn,
&|x, y| x.iter().all(|x| $check_fn(*x, y)),
)
}
}
}
};
{ $vector:ty, $scalar:ty, $trait:ident :: $fn:ident, $trait_assign:ident :: $fn_assign:ident, $check_fn:expr } => {
impl_binary_nonzero_rhs_op_test! { $vector, $scalar, $trait::$fn, $trait_assign::$fn_assign, <$scalar as core::ops::$trait>::$fn, $check_fn }
{ $scalar:ty, $trait:ident :: $fn:ident, $trait_assign:ident :: $fn_assign:ident, $check_fn:expr } => {
impl_binary_checked_op_test! { $scalar, $trait::$fn, $trait_assign::$fn_assign, <$scalar as core::ops::$trait>::$fn, $check_fn }
};
}

Expand Down Expand Up @@ -216,9 +218,9 @@ macro_rules! impl_common_integer_tests {
/// Implement tests for signed integers.
#[macro_export]
macro_rules! impl_signed_tests {
{ $vector:ident, $scalar:tt } => {
{ $scalar:tt } => {
mod $scalar {
type Vector<const LANES: usize> = core_simd::$vector<LANES>;
type Vector<const LANES: usize> = core_simd::Simd<Scalar, LANES>;
type Scalar = $scalar;

impl_common_integer_tests! { Vector, Scalar }
Expand Down Expand Up @@ -305,28 +307,28 @@ macro_rules! impl_signed_tests {
}
}

impl_binary_op_test!(Vector<LANES>, Scalar, Add::add, AddAssign::add_assign, Scalar::wrapping_add);
impl_binary_op_test!(Vector<LANES>, Scalar, Sub::sub, SubAssign::sub_assign, Scalar::wrapping_sub);
impl_binary_op_test!(Vector<LANES>, Scalar, Mul::mul, MulAssign::mul_assign, Scalar::wrapping_mul);
impl_binary_op_test!(Scalar, Add::add, AddAssign::add_assign, Scalar::wrapping_add);
impl_binary_op_test!(Scalar, Sub::sub, SubAssign::sub_assign, Scalar::wrapping_sub);
impl_binary_op_test!(Scalar, Mul::mul, MulAssign::mul_assign, Scalar::wrapping_mul);

// Exclude Div and Rem panicking cases
impl_binary_checked_op_test!(Vector<LANES>, Scalar, Div::div, DivAssign::div_assign, Scalar::wrapping_div, |x, y| y != 0 && !(x == Scalar::MIN && y == -1));
impl_binary_checked_op_test!(Vector<LANES>, Scalar, Rem::rem, RemAssign::rem_assign, Scalar::wrapping_rem, |x, y| y != 0 && !(x == Scalar::MIN && y == -1));
impl_binary_checked_op_test!(Scalar, Div::div, DivAssign::div_assign, Scalar::wrapping_div, |x, y| y != 0 && !(x == Scalar::MIN && y == -1));
impl_binary_checked_op_test!(Scalar, Rem::rem, RemAssign::rem_assign, Scalar::wrapping_rem, |x, y| y != 0 && !(x == Scalar::MIN && y == -1));

impl_unary_op_test!(Vector<LANES>, Scalar, Not::not);
impl_binary_op_test!(Vector<LANES>, Scalar, BitAnd::bitand, BitAndAssign::bitand_assign);
impl_binary_op_test!(Vector<LANES>, Scalar, BitOr::bitor, BitOrAssign::bitor_assign);
impl_binary_op_test!(Vector<LANES>, Scalar, BitXor::bitxor, BitXorAssign::bitxor_assign);
impl_unary_op_test!(Scalar, Not::not);
impl_binary_op_test!(Scalar, BitAnd::bitand, BitAndAssign::bitand_assign);
impl_binary_op_test!(Scalar, BitOr::bitor, BitOrAssign::bitor_assign);
impl_binary_op_test!(Scalar, BitXor::bitxor, BitXorAssign::bitxor_assign);
}
}
}

/// Implement tests for unsigned integers.
#[macro_export]
macro_rules! impl_unsigned_tests {
{ $vector:ident, $scalar:tt } => {
{ $scalar:tt } => {
mod $scalar {
type Vector<const LANES: usize> = core_simd::$vector<LANES>;
type Vector<const LANES: usize> = core_simd::Simd<Scalar, LANES>;
type Scalar = $scalar;

impl_common_integer_tests! { Vector, Scalar }
Expand All @@ -339,36 +341,36 @@ macro_rules! impl_unsigned_tests {
}
}

impl_binary_op_test!(Vector<LANES>, Scalar, Add::add, AddAssign::add_assign, Scalar::wrapping_add);
impl_binary_op_test!(Vector<LANES>, Scalar, Sub::sub, SubAssign::sub_assign, Scalar::wrapping_sub);
impl_binary_op_test!(Vector<LANES>, Scalar, Mul::mul, MulAssign::mul_assign, Scalar::wrapping_mul);
impl_binary_op_test!(Scalar, Add::add, AddAssign::add_assign, Scalar::wrapping_add);
impl_binary_op_test!(Scalar, Sub::sub, SubAssign::sub_assign, Scalar::wrapping_sub);
impl_binary_op_test!(Scalar, Mul::mul, MulAssign::mul_assign, Scalar::wrapping_mul);

// Exclude Div and Rem panicking cases
impl_binary_checked_op_test!(Vector<LANES>, Scalar, Div::div, DivAssign::div_assign, Scalar::wrapping_div, |_, y| y != 0);
impl_binary_checked_op_test!(Vector<LANES>, Scalar, Rem::rem, RemAssign::rem_assign, Scalar::wrapping_rem, |_, y| y != 0);
impl_binary_checked_op_test!(Scalar, Div::div, DivAssign::div_assign, Scalar::wrapping_div, |_, y| y != 0);
impl_binary_checked_op_test!(Scalar, Rem::rem, RemAssign::rem_assign, Scalar::wrapping_rem, |_, y| y != 0);

impl_unary_op_test!(Vector<LANES>, Scalar, Not::not);
impl_binary_op_test!(Vector<LANES>, Scalar, BitAnd::bitand, BitAndAssign::bitand_assign);
impl_binary_op_test!(Vector<LANES>, Scalar, BitOr::bitor, BitOrAssign::bitor_assign);
impl_binary_op_test!(Vector<LANES>, Scalar, BitXor::bitxor, BitXorAssign::bitxor_assign);
impl_unary_op_test!(Scalar, Not::not);
impl_binary_op_test!(Scalar, BitAnd::bitand, BitAndAssign::bitand_assign);
impl_binary_op_test!(Scalar, BitOr::bitor, BitOrAssign::bitor_assign);
impl_binary_op_test!(Scalar, BitXor::bitxor, BitXorAssign::bitxor_assign);
}
}
}

/// Implement tests for floating point numbers.
#[macro_export]
macro_rules! impl_float_tests {
{ $vector:ident, $scalar:tt, $int_scalar:tt } => {
{ $scalar:tt, $int_scalar:tt } => {
mod $scalar {
type Vector<const LANES: usize> = core_simd::$vector<LANES>;
type Vector<const LANES: usize> = core_simd::Simd<Scalar, LANES>;
type Scalar = $scalar;

impl_unary_op_test!(Vector<LANES>, Scalar, Neg::neg);
impl_binary_op_test!(Vector<LANES>, Scalar, Add::add, AddAssign::add_assign);
impl_binary_op_test!(Vector<LANES>, Scalar, Sub::sub, SubAssign::sub_assign);
impl_binary_op_test!(Vector<LANES>, Scalar, Mul::mul, MulAssign::mul_assign);
impl_binary_op_test!(Vector<LANES>, Scalar, Div::div, DivAssign::div_assign);
impl_binary_op_test!(Vector<LANES>, Scalar, Rem::rem, RemAssign::rem_assign);
impl_unary_op_test!(Scalar, Neg::neg);
impl_binary_op_test!(Scalar, Add::add, AddAssign::add_assign);
impl_binary_op_test!(Scalar, Sub::sub, SubAssign::sub_assign);
impl_binary_op_test!(Scalar, Mul::mul, MulAssign::mul_assign);
impl_binary_op_test!(Scalar, Div::div, DivAssign::div_assign);
impl_binary_op_test!(Scalar, Rem::rem, RemAssign::rem_assign);

test_helpers::test_lanes! {
fn is_sign_positive<const LANES: usize>() {
Expand Down
2 changes: 1 addition & 1 deletion crates/core_simd/tests/u16_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

#[macro_use]
mod ops_macros;
impl_unsigned_tests! { SimdU16, u16 }
impl_unsigned_tests! { u16 }
2 changes: 1 addition & 1 deletion crates/core_simd/tests/u32_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

#[macro_use]
mod ops_macros;
impl_unsigned_tests! { SimdU32, u32 }
impl_unsigned_tests! { u32 }
2 changes: 1 addition & 1 deletion crates/core_simd/tests/u64_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

#[macro_use]
mod ops_macros;
impl_unsigned_tests! { SimdU64, u64 }
impl_unsigned_tests! { u64 }
2 changes: 1 addition & 1 deletion crates/core_simd/tests/u8_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

#[macro_use]
mod ops_macros;
impl_unsigned_tests! { SimdU8, u8 }
impl_unsigned_tests! { u8 }
2 changes: 1 addition & 1 deletion crates/core_simd/tests/usize_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

#[macro_use]
mod ops_macros;
impl_unsigned_tests! { SimdUsize, usize }
impl_unsigned_tests! { usize }

0 comments on commit f7f2968

Please sign in to comment.