This commit is contained in:
Caleb Zulawski 2020-09-22 20:26:25 -04:00
parent 011aafea16
commit 0f837a9147
54 changed files with 232 additions and 70 deletions

View file

@ -28,8 +28,8 @@ macro_rules! from_unaligned {
}
macro_rules! define_type {
{ struct $name:ident([$type:ty; $lanes:tt]); } => {
define_type! { @impl $name [$type; $lanes] }
{ $(#[$attr:meta])* struct $name:ident([$type:ty; $lanes:tt]); } => {
define_type! { @impl $(#[$attr])* | $name [$type; $lanes] }
// array references
impl AsRef<[$type; $lanes]> for $name {
@ -74,40 +74,40 @@ macro_rules! define_type {
}
}
};
{ @impl $name:ident [$type:ty; 1] } => {
define_type! { @impl $name | $type | $type, | v0, }
{ @impl $(#[$attr:meta])* | $name:ident [$type:ty; 1] } => {
define_type! { @def $(#[$attr])* | $name | $type | $type, | v0, }
};
{ @impl $name:ident [$type:ty; 2] } => {
define_type! { @impl $name | $type | $type, $type, | v0, v1, }
{ @impl $(#[$attr:meta])* | $name:ident [$type:ty; 2] } => {
define_type! { @def $(#[$attr])* | $name | $type | $type, $type, | v0, v1, }
};
{ @impl $name:ident [$type:ty; 4] } => {
define_type! { @impl $name | $type |
{ @impl $(#[$attr:meta])* | $name:ident [$type:ty; 4] } => {
define_type! { @def $(#[$attr])* | $name | $type |
$type, $type, $type, $type, |
v0, v1, v2, v3,
}
};
{ @impl $name:ident [$type:ty; 8] } => {
define_type! { @impl $name | $type |
{ @impl $(#[$attr:meta])* | $name:ident [$type:ty; 8] } => {
define_type! { @def $(#[$attr])* | $name | $type |
$type, $type, $type, $type, $type, $type, $type, $type, |
v0, v1, v2, v3, v4, v5, v6, v7,
}
};
{ @impl $name:ident [$type:ty; 16] } => {
define_type! { @impl $name | $type |
{ @impl $(#[$attr:meta])* | $name:ident [$type:ty; 16] } => {
define_type! { @def $(#[$attr])* | $name | $type |
$type, $type, $type, $type, $type, $type, $type, $type, $type, $type, $type, $type, $type, $type, $type, $type, |
v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15,
}
};
{ @impl $name:ident [$type:ty; 32] } => {
define_type! { @impl $name | $type |
{ @impl $(#[$attr:meta])* | $name:ident [$type:ty; 32] } => {
define_type! { @def $(#[$attr])* | $name | $type |
$type, $type, $type, $type, $type, $type, $type, $type, $type, $type, $type, $type, $type, $type, $type, $type,
$type, $type, $type, $type, $type, $type, $type, $type, $type, $type, $type, $type, $type, $type, $type, $type, |
v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15,
v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31,
}
};
{ @impl $name:ident [$type:ty; 64] } => {
define_type! { @impl $name | $type |
{ @impl $(#[$attr:meta])* | $name:ident [$type:ty; 64] } => {
define_type! { @def $(#[$attr])* | $name | $type |
$type, $type, $type, $type, $type, $type, $type, $type, $type, $type, $type, $type, $type, $type, $type, $type,
$type, $type, $type, $type, $type, $type, $type, $type, $type, $type, $type, $type, $type, $type, $type, $type,
$type, $type, $type, $type, $type, $type, $type, $type, $type, $type, $type, $type, $type, $type, $type, $type,
@ -118,18 +118,21 @@ macro_rules! define_type {
v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61, v62, v63,
}
};
{ @impl $name:ident | $type:ty | $($itype:ty,)* | $($ivar:ident,)* } => {
{ @def $(#[$attr:meta])* | $name:ident | $type:ty | $($itype:ty,)* | $($ivar:ident,)* } => {
$(#[$attr])*
#[allow(non_camel_case_types)]
#[derive(Copy, Clone, Debug, Default, PartialEq, PartialOrd)]
#[repr(simd)]
pub struct $name($($itype),*);
impl $name {
/// Construct a vector by setting each lane to a single value.
#[inline]
pub fn splat(value: $type) -> Self {
Self($(value as $itype),*)
}
/// Construct a vector by setting each lane.
#[allow(clippy::too_many_arguments)]
#[inline]
pub fn new($($ivar: $itype),*) -> Self {

View file

@ -1,4 +1,7 @@
define_type! { struct f32x16([f32; 16]); }
define_type! {
#[doc = "Vector of 16 `f32` types"]
struct f32x16([f32; 16]);
}
/*
#[cfg(target_arch = "x86")]

View file

@ -1 +1,4 @@
define_type! { struct f32x2([f32; 2]); }
define_type! {
#[doc = "Vector of two `f32` types"]
struct f32x2([f32; 2]);
}

View file

@ -1,4 +1,7 @@
define_type! { struct f32x4([f32; 4]); }
define_type! {
#[doc = "Vector of four `f32` types"]
struct f32x4([f32; 4]);
}
#[cfg(target_arch = "x86")]
from_aligned! { unsafe f32x4 |bidirectional| core::arch::x86::__m128 }

View file

@ -1,4 +1,7 @@
define_type! { struct f32x8([f32; 8]); }
define_type! {
#[doc = "Vector of eight `f32` types"]
struct f32x8([f32; 8]);
}
#[cfg(target_arch = "x86")]
from_aligned! { unsafe f32x8 |bidirectional| core::arch::x86::__m256 }

View file

@ -1,4 +1,7 @@
define_type! { struct f64x2([f64; 2]); }
define_type! {
#[doc = "Vector of two `f64` types"]
struct f64x2([f64; 2]);
}
#[cfg(target_arch = "x86")]
from_aligned! { unsafe f64x2 |bidirectional| core::arch::x86::__m128d }

View file

@ -1,4 +1,7 @@
define_type! { struct f64x4([f64; 4]); }
define_type! {
#[doc = "Vector of four `f64` types"]
struct f64x4([f64; 4]);
}
#[cfg(target_arch = "x86")]
from_aligned! { unsafe f64x4 |bidirectional| core::arch::x86::__m256d }

View file

@ -1,4 +1,7 @@
define_type! { struct f64x8([f64; 8]); }
define_type! {
#[doc = "Vector of eight `f64` types"]
struct f64x8([f64; 8]);
}
/*
#[cfg(target_arch = "x86")]

View file

@ -1,4 +1,7 @@
define_type! { struct i128x2([i128; 2]); }
define_type! {
#[doc = "Vector of two `i128` types"]
struct i128x2([i128; 2]);
}
#[cfg(target_arch = "x86")]
from_aligned! { unsafe i128x2 |bidirectional| core::arch::x86::__m256i }

View file

@ -1,4 +1,7 @@
define_type! { struct i128x4([i128; 4]); }
define_type! {
#[doc = "Vector of four `i128` types"]
struct i128x4([i128; 4]);
}
/*
#[cfg(target_arch = "x86")]

View file

@ -1,4 +1,7 @@
define_type! { struct i16x16([i16; 16]); }
define_type! {
#[doc = "Vector of 16 `i16` types"]
struct i16x16([i16; 16]);
}
#[cfg(target_arch = "x86")]
from_aligned! { unsafe i16x16 |bidirectional| core::arch::x86::__m256i }

View file

@ -1 +1,4 @@
define_type! { struct i16x2([i16; 2]); }
define_type! {
#[doc = "Vector of two `i16` types"]
struct i16x2([i16; 2]);
}

View file

@ -1,4 +1,7 @@
define_type! { struct i16x32([i16; 32]); }
define_type! {
#[doc = "Vector of 32 `i16` types"]
struct i16x32([i16; 32]);
}
/*
#[cfg(target_arch = "x86")]

View file

@ -1 +1,4 @@
define_type! { struct i16x4([i16; 4]); }
define_type! {
#[doc = "Vector of four `i16` types"]
struct i16x4([i16; 4]);
}

View file

@ -1,4 +1,7 @@
define_type! { struct i16x8([i16; 8]); }
define_type! {
#[doc = "Vector of eight `i16` types"]
struct i16x8([i16; 8]);
}
#[cfg(target_arch = "x86")]
from_aligned! { unsafe i16x8 |bidirectional| core::arch::x86::__m128i }

View file

@ -1,4 +1,7 @@
define_type! { struct i32x16([i32; 16]); }
define_type! {
#[doc = "Vector of 16 `i32` types"]
struct i32x16([i32; 16]);
}
/*
#[cfg(target_arch = "x86")]

View file

@ -1 +1,4 @@
define_type! { struct i32x2([i32; 2]); }
define_type! {
#[doc = "Vector of two `i32` types"]
struct i32x2([i32; 2]);
}

View file

@ -1,4 +1,7 @@
define_type! { struct i32x4([i32; 4]); }
define_type! {
#[doc = "Vector of four `i32` types"]
struct i32x4([i32; 4]);
}
#[cfg(target_arch = "x86")]
from_aligned! { unsafe i32x4 |bidirectional| core::arch::x86::__m128i }

View file

@ -1,4 +1,7 @@
define_type! { struct i32x8([i32; 8]); }
define_type! {
#[doc = "Vector of eight `i32` types"]
struct i32x8([i32; 8]);
}
#[cfg(target_arch = "x86")]
from_aligned! { unsafe i32x8 |bidirectional| core::arch::x86::__m256i }

View file

@ -1,4 +1,7 @@
define_type! { struct i64x2([i64; 2]); }
define_type! {
#[doc = "Vector of two `i64` types"]
struct i64x2([i64; 2]);
}
#[cfg(target_arch = "x86")]
from_aligned! { unsafe i64x2 |bidirectional| core::arch::x86::__m128i }

View file

@ -1,4 +1,7 @@
define_type! { struct i64x4([i64; 4]); }
define_type! {
#[doc = "Vector of four `i64` types"]
struct i64x4([i64; 4]);
}
#[cfg(target_arch = "x86")]
from_aligned! { unsafe i64x4 |bidirectional| core::arch::x86::__m256i }

View file

@ -1,4 +1,7 @@
define_type! { struct i64x8([i64; 8]); }
define_type! {
#[doc = "Vector of eight `i64` types"]
struct i64x8([i64; 8]);
}
/*
#[cfg(target_arch = "x86")]

View file

@ -1,4 +1,7 @@
define_type! { struct i8x16([i8; 16]); }
define_type! {
#[doc = "Vector of 16 `i8` types"]
struct i8x16([i8; 16]);
}
#[cfg(target_arch = "x86")]
from_aligned! { unsafe i8x16 |bidirectional| core::arch::x86::__m128i }

View file

@ -1 +1,4 @@
define_type! { struct i8x2([i8; 2]); }
define_type! {
#[doc = "Vector of two `i8` types"]
struct i8x2([i8; 2]);
}

View file

@ -1,4 +1,7 @@
define_type! { struct i8x32([i8; 32]); }
define_type! {
#[doc = "Vector of 32 `i8` types"]
struct i8x32([i8; 32]);
}
#[cfg(target_arch = "x86")]
from_aligned! { unsafe i8x32 |bidirectional| core::arch::x86::__m256i }

View file

@ -1 +1,4 @@
define_type! { struct i8x4([i8; 4]); }
define_type! {
#[doc = "Vector of four `i8` types"]
struct i8x4([i8; 4]);
}

View file

@ -1,4 +1,7 @@
define_type! { struct i8x64([i8; 64]); }
define_type! {
#[doc = "Vector of 64 `i8` types"]
struct i8x64([i8; 64]);
}
/*
#[cfg(target_arch = "x86")]

View file

@ -1 +1,4 @@
define_type! { struct i8x8([i8; 8]); }
define_type! {
#[doc = "Vector of eight `i8` types"]
struct i8x8([i8; 8]);
}

View file

@ -1,4 +1,7 @@
define_type! { struct isizex2([isize; 2]); }
define_type! {
#[doc = "Vector of two `isize` types"]
struct isizex2([isize; 2]);
}
#[cfg(all(target_arch = "x86", target_pointer_width = "64"))]
from_aligned! { unsafe isizex2 |bidirectional| core::arch::x86::__m128i }

View file

@ -1,4 +1,7 @@
define_type! { struct isizex4([isize; 4]); }
define_type! {
#[doc = "Vector of four `isize` types"]
struct isizex4([isize; 4]);
}
#[cfg(all(target_arch = "x86", target_pointer_width = "32"))]
from_aligned! { unsafe isizex4 |bidirectional| core::arch::x86::__m128i }

View file

@ -1,4 +1,7 @@
define_type! { struct isizex8([isize; 8]); }
define_type! {
#[doc = "Vector of eight `isize` types"]
struct isizex8([isize; 8]);
}
#[cfg(all(target_arch = "x86", target_pointer_width = "32"))]
from_aligned! { unsafe isizex8 |bidirectional| core::arch::x86::__m256i }

View file

@ -1,4 +1,7 @@
define_type! { struct u128x2([u128; 2]); }
define_type! {
#[doc = "Vector of two `u128` types"]
struct u128x2([u128; 2]);
}
#[cfg(target_arch = "x86")]
from_aligned! { unsafe u128x2 |bidirectional| core::arch::x86::__m256i }

View file

@ -1,4 +1,7 @@
define_type! { struct u128x4([u128; 4]); }
define_type! {
#[doc = "Vector of four `u128` types"]
struct u128x4([u128; 4]);
}
/*
#[cfg(target_arch = "x86")]

View file

@ -1,4 +1,7 @@
define_type! { struct u16x16([u16; 16]); }
define_type! {
#[doc = "Vector of 16 `u16` types"]
struct u16x16([u16; 16]);
}
#[cfg(target_arch = "x86")]
from_aligned! { unsafe u16x16 |bidirectional| core::arch::x86::__m256i }

View file

@ -1 +1,4 @@
define_type! { struct u16x2([u16; 2]); }
define_type! {
#[doc = "Vector of two `u16` types"]
struct u16x2([u16; 2]);
}

View file

@ -1,4 +1,7 @@
define_type! { struct u16x32([u16; 32]); }
define_type! {
#[doc = "Vector of 32 `u16` types"]
struct u16x32([u16; 32]);
}
/*
#[cfg(target_arch = "x86")]

View file

@ -1 +1,4 @@
define_type! { struct u16x4([u16; 4]); }
define_type! {
#[doc = "Vector of four `u16` types"]
struct u16x4([u16; 4]);
}

View file

@ -1,4 +1,7 @@
define_type! { struct u16x8([u16; 8]); }
define_type! {
#[doc = "Vector of eight `u16` types"]
struct u16x8([u16; 8]);
}
#[cfg(target_arch = "x86")]
from_aligned! { unsafe u16x8 |bidirectional| core::arch::x86::__m128i }

View file

@ -1,4 +1,7 @@
define_type! { struct u32x16([u32; 16]); }
define_type! {
#[doc = "Vector of 16 `u32` types"]
struct u32x16([u32; 16]);
}
/*
#[cfg(target_arch = "x86")]

View file

@ -1 +1,4 @@
define_type! { struct u32x2([u32; 2]); }
define_type! {
#[doc = "Vector of two `u32` types"]
struct u32x2([u32; 2]);
}

View file

@ -1,4 +1,7 @@
define_type! { struct u32x4([u32; 4]); }
define_type! {
#[doc = "Vector of four `u32` types"]
struct u32x4([u32; 4]);
}
#[cfg(target_arch = "x86")]
from_aligned! { unsafe u32x4 |bidirectional| core::arch::x86::__m128i }

View file

@ -1,4 +1,7 @@
define_type! { struct u32x8([u32; 8]); }
define_type! {
#[doc = "Vector of eight `u32` types"]
struct u32x8([u32; 8]);
}
#[cfg(target_arch = "x86")]
from_aligned! { unsafe u32x8 |bidirectional| core::arch::x86::__m256i }

View file

@ -1,4 +1,7 @@
define_type! { struct u64x2([u64; 2]); }
define_type! {
#[doc = "Vector of two `u64` types"]
struct u64x2([u64; 2]);
}
#[cfg(target_arch = "x86")]
from_aligned! { unsafe u64x2 |bidirectional| core::arch::x86::__m128i }

View file

@ -1,4 +1,7 @@
define_type! { struct u64x4([u64; 4]); }
define_type! {
#[doc = "Vector of four `u64` types"]
struct u64x4([u64; 4]);
}
#[cfg(target_arch = "x86")]
from_aligned! { unsafe u64x4 |bidirectional| core::arch::x86::__m256i }

View file

@ -1,4 +1,7 @@
define_type! { struct u64x8([u64; 8]); }
define_type! {
#[doc = "Vector of eight `u64` types"]
struct u64x8([u64; 8]);
}
/*
#[cfg(target_arch = "x86")]

View file

@ -1,4 +1,7 @@
define_type! { struct u8x16([u8; 16]); }
define_type! {
#[doc = "Vector of 16 `u8` types"]
struct u8x16([u8; 16]);
}
#[cfg(target_arch = "x86")]
from_aligned! { unsafe u8x16 |bidirectional| core::arch::x86::__m128i }

View file

@ -1 +1,4 @@
define_type! { struct u8x2([u8; 2]); }
define_type! {
#[doc = "Vector of two `u8` types"]
struct u8x2([u8; 2]);
}

View file

@ -1,4 +1,7 @@
define_type! { struct u8x32([u8; 32]); }
define_type! {
#[doc = "Vector of 32 `u8` types"]
struct u8x32([u8; 32]);
}
#[cfg(target_arch = "x86")]
from_aligned! { unsafe u8x32 |bidirectional| core::arch::x86::__m256i }

View file

@ -1 +1,4 @@
define_type! { struct u8x4([u8; 4]); }
define_type! {
#[doc = "Vector of four `u8` types"]
struct u8x4([u8; 4]);
}

View file

@ -1,4 +1,7 @@
define_type! { struct u8x64([u8; 64]); }
define_type! {
#[doc = "Vector of 64 `u8` types"]
struct u8x64([u8; 64]);
}
/*
#[cfg(target_arch = "x86")]

View file

@ -1 +1,4 @@
define_type! { struct u8x8([u8; 8]); }
define_type! {
#[doc = "Vector of eight `u8` types"]
struct u8x8([u8; 8]);
}

View file

@ -1,4 +1,7 @@
define_type! { struct usizex2([usize; 2]); }
define_type! {
#[doc = "Vector of two `usize` types"]
struct usizex2([usize; 2]);
}
#[cfg(all(target_arch = "x86", target_pointer_width = "64"))]
from_aligned! { unsafe usizex2 |bidirectional| core::arch::x86::__m128i }

View file

@ -1,4 +1,7 @@
define_type! { struct usizex4([usize; 4]); }
define_type! {
#[doc = "Vector of four `usize` types"]
struct usizex4([usize; 4]);
}
#[cfg(all(target_arch = "x86", target_pointer_width = "32"))]
from_aligned! { unsafe usizex4 |bidirectional| core::arch::x86::__m128i }

View file

@ -1,4 +1,7 @@
define_type! { struct usizex8([usize; 8]); }
define_type! {
#[doc = "Vector of eight `usize` types"]
struct usizex8([usize; 8]);
}
#[cfg(all(target_arch = "x86", target_pointer_width = "32"))]
from_aligned! { unsafe usizex8 |bidirectional| core::arch::x86::__m256i }