This repository has been archived by the owner on Feb 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved performance of comparison with SIMD feature flag (2x-3.5x) (#…
…305)
- Loading branch information
1 parent
4f20537
commit 2873e1a
Showing
8 changed files
with
236 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
use crate::types::NativeType; | ||
|
||
/// [`NativeType`] that supports a representation of 8 lanes | ||
pub trait Simd8: NativeType { | ||
type Simd: Simd8Lanes<Self>; | ||
} | ||
|
||
pub trait Simd8Lanes<T>: Copy { | ||
fn from_chunk(v: &[T]) -> Self; | ||
fn from_incomplete_chunk(v: &[T], remaining: T) -> Self; | ||
fn eq(self, other: Self) -> u8; | ||
fn neq(self, other: Self) -> u8; | ||
fn lt_eq(self, other: Self) -> u8; | ||
fn lt(self, other: Self) -> u8; | ||
fn gt(self, other: Self) -> u8; | ||
fn gt_eq(self, other: Self) -> u8; | ||
} | ||
|
||
#[inline] | ||
pub(super) fn set<T: Copy, F: Fn(T, T) -> bool>(lhs: [T; 8], rhs: [T; 8], op: F) -> u8 { | ||
let mut byte = 0u8; | ||
lhs.iter() | ||
.zip(rhs.iter()) | ||
.enumerate() | ||
.for_each(|(i, (lhs, rhs))| { | ||
byte |= if op(*lhs, *rhs) { 1 << i } else { 0 }; | ||
}); | ||
byte | ||
} | ||
|
||
macro_rules! simd8_native { | ||
($type:ty) => { | ||
impl Simd8 for $type { | ||
type Simd = [$type; 8]; | ||
} | ||
|
||
impl Simd8Lanes<$type> for [$type; 8] { | ||
#[inline] | ||
fn from_chunk(v: &[$type]) -> Self { | ||
v.try_into().unwrap() | ||
} | ||
|
||
#[inline] | ||
fn from_incomplete_chunk(v: &[$type], remaining: $type) -> Self { | ||
let mut a = [remaining; 8]; | ||
a.iter_mut().zip(v.iter()).for_each(|(a, b)| *a = *b); | ||
a | ||
} | ||
|
||
#[inline] | ||
fn eq(self, other: Self) -> u8 { | ||
set(self, other, |x, y| x == y) | ||
} | ||
|
||
#[inline] | ||
fn neq(self, other: Self) -> u8 { | ||
#[allow(clippy::float_cmp)] | ||
set(self, other, |x, y| x != y) | ||
} | ||
|
||
#[inline] | ||
fn lt_eq(self, other: Self) -> u8 { | ||
set(self, other, |x, y| x <= y) | ||
} | ||
|
||
#[inline] | ||
fn lt(self, other: Self) -> u8 { | ||
set(self, other, |x, y| x < y) | ||
} | ||
|
||
#[inline] | ||
fn gt_eq(self, other: Self) -> u8 { | ||
set(self, other, |x, y| x >= y) | ||
} | ||
|
||
#[inline] | ||
fn gt(self, other: Self) -> u8 { | ||
set(self, other, |x, y| x > y) | ||
} | ||
} | ||
}; | ||
} | ||
|
||
#[cfg(not(feature = "simd"))] | ||
mod native; | ||
#[cfg(not(feature = "simd"))] | ||
pub use native::*; | ||
#[cfg(feature = "simd")] | ||
mod packed; | ||
#[cfg(feature = "simd")] | ||
pub use packed::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use std::convert::TryInto; | ||
|
||
use super::{set, Simd8, Simd8Lanes}; | ||
|
||
simd8_native!(u8); | ||
simd8_native!(u16); | ||
simd8_native!(u32); | ||
simd8_native!(u64); | ||
simd8_native!(i8); | ||
simd8_native!(i16); | ||
simd8_native!(i32); | ||
simd8_native!(i128); | ||
simd8_native!(i64); | ||
simd8_native!(f32); | ||
simd8_native!(f64); |
Oops, something went wrong.