Remove remaining derived traits

This commit is contained in:
Caleb Zulawski 2020-09-26 14:30:00 -04:00
parent d817b56f1d
commit b9bf9ef3c2
13 changed files with 81 additions and 93 deletions

View File

@ -207,6 +207,28 @@ macro_rules! base_vector_traits {
}
}
/// Implements additional integer traits (Eq, Ord, Hash) on the specified vector `$name`, holding multiple `$lanes` of `$type`.
macro_rules! integer_vector_traits {
{ $name:path => [$type:ty; $lanes:literal] } => {
impl Eq for $name {}
impl Ord for $name {
fn cmp(&self, other: &Self) -> core::cmp::Ordering {
AsRef::<[$type]>::as_ref(self).cmp(AsRef::<[$type]>::as_ref(other))
}
}
impl core::hash::Hash for $name {
fn hash<H>(&self, state: &mut H)
where
H: core::hash::Hasher
{
AsRef::<[$type]>::as_ref(self).hash(state)
}
}
}
}
/// Defines a vector `$name` containing multiple `$lanes` of `$type`.
macro_rules! define_vector {
{ $(#[$attr:meta])* struct $name:ident([$type:ty; $lanes:tt]); } => {
@ -242,6 +264,18 @@ macro_rules! define_vector {
}
}
/// Defines an integer vector `$name` containing multiple `$lanes` of integer `$type`.
macro_rules! define_integer_vector {
{ $(#[$attr:meta])* struct $name:ident([$type:ty; $lanes:tt]); } => {
define_vector! {
$(#[$attr])*
struct $name([$type; $lanes]);
}
integer_vector_traits! { $name => [$type; $lanes] }
}
}
/// Defines a mask vector `$name` containing multiple `$lanes` of `$type`, represented by the
/// underlying type `$impl_type`.
macro_rules! define_mask_vector {
@ -254,11 +288,11 @@ macro_rules! define_mask_vector {
}
base_vector_traits! { $name => [$type; $lanes] }
integer_vector_traits! { $name => [$type; $lanes] }
};
{ def $(#[$attr:meta])* | $name:ident | $($itype:ty)* } => {
$(#[$attr])*
#[allow(non_camel_case_types)]
#[derive(Eq, Ord)]
#[repr(simd)]
pub struct $name($($itype),*);
};

View File

@ -1,12 +1,10 @@
define_vector! {
define_integer_vector! {
/// Vector of two `i128` values
#[derive(Eq, Ord, Hash)]
struct i128x2([i128; 2]);
}
define_vector! {
define_integer_vector! {
/// Vector of four `i128` values
#[derive(Eq, Ord, Hash)]
struct i128x4([i128; 4]);
}

View File

@ -1,30 +1,25 @@
define_vector! {
define_integer_vector! {
/// Vector of two `i16` values
#[derive(Eq, Ord, Hash)]
struct i16x2([i16; 2]);
}
define_vector! {
define_integer_vector! {
/// Vector of four `i16` values
#[derive(Eq, Ord, Hash)]
struct i16x4([i16; 4]);
}
define_vector! {
define_integer_vector! {
/// Vector of eight `i16` values
#[derive(Eq, Ord, Hash)]
struct i16x8([i16; 8]);
}
define_vector! {
define_integer_vector! {
/// Vector of 16 `i16` values
#[derive(Eq, Ord, Hash)]
struct i16x16([i16; 16]);
}
define_vector! {
define_integer_vector! {
/// Vector of 32 `i16` values
#[derive(Eq, Ord, Hash)]
struct i16x32([i16; 32]);
}

View File

@ -1,24 +1,20 @@
define_vector! {
define_integer_vector! {
/// Vector of two `i32` values
#[derive(Eq, Ord, Hash)]
struct i32x2([i32; 2]);
}
define_vector! {
define_integer_vector! {
/// Vector of four `i32` values
#[derive(Eq, Ord, Hash)]
struct i32x4([i32; 4]);
}
define_vector! {
define_integer_vector! {
/// Vector of eight `i32` values
#[derive(Eq, Ord, Hash)]
struct i32x8([i32; 8]);
}
define_vector! {
define_integer_vector! {
/// Vector of 16 `i32` values
#[derive(Eq, Ord, Hash)]
struct i32x16([i32; 16]);
}

View File

@ -1,18 +1,15 @@
define_vector! {
define_integer_vector! {
/// Vector of two `i64` values
#[derive(Eq, Ord, Hash)]
struct i64x2([i64; 2]);
}
define_vector! {
define_integer_vector! {
/// Vector of four `i64` values
#[derive(Eq, Ord, Hash)]
struct i64x4([i64; 4]);
}
define_vector! {
define_integer_vector! {
/// Vector of eight `i64` values
#[derive(Eq, Ord, Hash)]
struct i64x8([i64; 8]);
}

View File

@ -1,36 +1,30 @@
define_vector! {
define_integer_vector! {
/// Vector of two `i8` values
#[derive(Eq, Ord, Hash)]
struct i8x2([i8; 2]);
}
define_vector! {
define_integer_vector! {
/// Vector of four `i8` values
#[derive(Eq, Ord, Hash)]
struct i8x4([i8; 4]);
}
define_vector! {
define_integer_vector! {
/// Vector of eight `i8` values
#[derive(Eq, Ord, Hash)]
struct i8x8([i8; 8]);
}
define_vector! {
define_integer_vector! {
/// Vector of 16 `i8` values
#[derive(Eq, Ord, Hash)]
struct i8x16([i8; 16]);
}
define_vector! {
define_integer_vector! {
/// Vector of 32 `i8` values
#[derive(Eq, Ord, Hash)]
struct i8x32([i8; 32]);
}
define_vector! {
define_integer_vector! {
/// Vector of 64 `i8` values
#[derive(Eq, Ord, Hash)]
struct i8x64([i8; 64]);
}

View File

@ -1,18 +1,15 @@
define_vector! {
define_integer_vector! {
/// Vector of two `isize` values
#[derive(Eq, Ord, Hash)]
struct isizex2([isize; 2]);
}
define_vector! {
define_integer_vector! {
/// Vector of four `isize` values
#[derive(Eq, Ord, Hash)]
struct isizex4([isize; 4]);
}
define_vector! {
define_integer_vector! {
/// Vector of eight `isize` values
#[derive(Eq, Ord, Hash)]
struct isizex8([isize; 8]);
}

View File

@ -1,12 +1,10 @@
define_vector! {
define_integer_vector! {
/// Vector of two `u128` values
#[derive(Eq, Ord, Hash)]
struct u128x2([u128; 2]);
}
define_vector! {
define_integer_vector! {
/// Vector of four `u128` values
#[derive(Eq, Ord, Hash)]
struct u128x4([u128; 4]);
}

View File

@ -1,30 +1,25 @@
define_vector! {
define_integer_vector! {
/// Vector of two `u16` values
#[derive(Eq, Ord, Hash)]
struct u16x2([u16; 2]);
}
define_vector! {
define_integer_vector! {
/// Vector of four `u16` values
#[derive(Eq, Ord, Hash)]
struct u16x4([u16; 4]);
}
define_vector! {
define_integer_vector! {
/// Vector of eight `u16` values
#[derive(Eq, Ord, Hash)]
struct u16x8([u16; 8]);
}
define_vector! {
define_integer_vector! {
/// Vector of 16 `u16` values
#[derive(Eq, Ord, Hash)]
struct u16x16([u16; 16]);
}
define_vector! {
define_integer_vector! {
/// Vector of 32 `u16` values
#[derive(Eq, Ord, Hash)]
struct u16x32([u16; 32]);
}

View File

@ -1,24 +1,20 @@
define_vector! {
define_integer_vector! {
/// Vector of two `u32` values
#[derive(Eq, Ord, Hash)]
struct u32x2([u32; 2]);
}
define_vector! {
define_integer_vector! {
/// Vector of four `u32` values
#[derive(Eq, Ord, Hash)]
struct u32x4([u32; 4]);
}
define_vector! {
define_integer_vector! {
/// Vector of eight `u32` values
#[derive(Eq, Ord, Hash)]
struct u32x8([u32; 8]);
}
define_vector! {
define_integer_vector! {
/// Vector of 16 `u32` values
#[derive(Eq, Ord, Hash)]
struct u32x16([u32; 16]);
}

View File

@ -1,18 +1,15 @@
define_vector! {
define_integer_vector! {
/// Vector of two `u64` values
#[derive(Eq, Ord, Hash)]
struct u64x2([u64; 2]);
}
define_vector! {
define_integer_vector! {
/// Vector of four `u64` values
#[derive(Eq, Ord, Hash)]
struct u64x4([u64; 4]);
}
define_vector! {
define_integer_vector! {
/// Vector of eight `u64` values
#[derive(Eq, Ord, Hash)]
struct u64x8([u64; 8]);
}

View File

@ -1,36 +1,30 @@
define_vector! {
define_integer_vector! {
/// Vector of two `u8` values
#[derive(Eq, Ord, Hash)]
struct u8x2([u8; 2]);
}
define_vector! {
define_integer_vector! {
/// Vector of four `u8` values
#[derive(Eq, Ord, Hash)]
struct u8x4([u8; 4]);
}
define_vector! {
define_integer_vector! {
/// Vector of eight `u8` values
#[derive(Eq, Ord, Hash)]
struct u8x8([u8; 8]);
}
define_vector! {
define_integer_vector! {
/// Vector of 16 `u8` values
#[derive(Eq, Ord, Hash)]
struct u8x16([u8; 16]);
}
define_vector! {
define_integer_vector! {
/// Vector of 32 `u8` values
#[derive(Eq, Ord, Hash)]
struct u8x32([u8; 32]);
}
define_vector! {
define_integer_vector! {
/// Vector of 64 `u8` values
#[derive(Eq, Ord, Hash)]
struct u8x64([u8; 64]);
}

View File

@ -1,18 +1,15 @@
define_vector! {
define_integer_vector! {
/// Vector of two `usize` values
#[derive(Eq, Ord, Hash)]
struct usizex2([usize; 2]);
}
define_vector! {
define_integer_vector! {
/// Vector of four `usize` values
#[derive(Eq, Ord, Hash)]
struct usizex4([usize; 4]);
}
define_vector! {
define_integer_vector! {
/// Vector of eight `usize` values
#[derive(Eq, Ord, Hash)]
struct usizex8([usize; 8]);
}