Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/comparisons #44

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions crates/core_simd/src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ macro_rules! impl_fmt_trait {

impl_fmt_trait! {
integers:
crate::u8x8, crate::u8x16, crate::u8x32, crate::u8x64,
crate::i8x8, crate::i8x16, crate::i8x32, crate::i8x64,
crate::u16x4, crate::u16x8, crate::u16x16, crate::u16x32,
crate::i16x4, crate::i16x8, crate::i16x16, crate::i16x32,
crate::u8x8, crate::u8x16, crate::u8x32, crate::u8x64,
crate::i8x8, crate::i8x16, crate::i8x32, crate::i8x64,
crate::u16x4, crate::u16x8, crate::u16x16, crate::u16x32,
crate::i16x4, crate::i16x8, crate::i16x16, crate::i16x32,
crate::u32x2, crate::u32x4, crate::u32x8, crate::u32x16,
crate::i32x2, crate::i32x4, crate::i32x8, crate::i32x16,
crate::u64x2, crate::u64x4, crate::u64x8,
Expand All @@ -96,10 +96,10 @@ impl_fmt_trait! {

impl_fmt_trait! {
masks:
crate::mask8x8, crate::mask8x16, crate::mask8x32, crate::mask8x64,
crate::mask16x4, crate::mask16x8, crate::mask16x16, crate::mask16x32,
crate::mask32x2, crate::mask32x4, crate::mask32x8, crate::mask32x16,
crate::mask64x2, crate::mask64x4, crate::mask64x8,
crate::mask128x2, crate::mask128x4,
crate::masksizex2, crate::masksizex4, crate::masksizex8,
crate::masks::wide::m8x8, crate::masks::wide::m8x16, crate::masks::wide::m8x32, crate::masks::wide::m8x64,
crate::masks::wide::m16x4, crate::masks::wide::m16x8, crate::masks::wide::m16x16, crate::masks::wide::m16x32,
crate::masks::wide::m32x2, crate::masks::wide::m32x4, crate::masks::wide::m32x8, crate::masks::wide::m32x16,
crate::masks::wide::m64x2, crate::masks::wide::m64x4, crate::masks::wide::m64x8,
crate::masks::wide::m128x2, crate::masks::wide::m128x4,
crate::masks::wide::msizex2, crate::masks::wide::msizex4, crate::masks::wide::msizex8,
}
7 changes: 7 additions & 0 deletions crates/core_simd/src/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,11 @@ extern "platform-intrinsic" {

/// fptoui/fptosi/uitofp/sitofp
pub(crate) fn simd_cast<T, U>(x: T) -> U;

pub(crate) fn simd_eq<T, U>(x: T, y: T) -> U;
pub(crate) fn simd_ne<T, U>(x: T, y: T) -> U;
pub(crate) fn simd_lt<T, U>(x: T, y: T) -> U;
pub(crate) fn simd_le<T, U>(x: T, y: T) -> U;
pub(crate) fn simd_gt<T, U>(x: T, y: T) -> U;
pub(crate) fn simd_ge<T, U>(x: T, y: T) -> U;
}
17 changes: 2 additions & 15 deletions crates/core_simd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ mod fmt;
mod intrinsics;
mod ops;

mod masks;
pub use masks::*;
pub mod masks;
pub use masks::opaque::*;

mod vectors_u8;
pub use vectors_u8::*;
Expand Down Expand Up @@ -44,17 +44,4 @@ pub use vectors_f32::*;
mod vectors_f64;
pub use vectors_f64::*;

mod vectors_mask8;
pub use vectors_mask8::*;
mod vectors_mask16;
pub use vectors_mask16::*;
mod vectors_mask32;
pub use vectors_mask32::*;
mod vectors_mask64;
pub use vectors_mask64::*;
mod vectors_mask128;
pub use vectors_mask128::*;
mod vectors_masksize;
pub use vectors_masksize::*;

mod round;
29 changes: 28 additions & 1 deletion crates/core_simd/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,6 @@ macro_rules! define_float_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]); } => {
Expand All @@ -336,6 +335,25 @@ macro_rules! define_mask_vector {
impl $name {
call_repeat! { $lanes => define_mask_vector [$impl_type] splat $type | }
call_counting_args! { $lanes => define_mask_vector => new $type | }
call_counting_args! { $lanes => define_mask_vector => new_from_bool $type | }

/// Tests the value of the specified lane.
///
/// # Panics
/// Panics if `lane` is greater than or equal to the number of lanes in the vector.
#[inline]
pub fn test(&self, lane: usize) -> bool {
self[lane].test()
}

/// Sets the value of the specified lane.
///
/// # Panics
/// Panics if `lane` is greater than or equal to the number of lanes in the vector.
#[inline]
pub fn set(&mut self, lane: usize, value: bool) {
self[lane] = value.into();
}
}

base_vector_traits! { $name => [$type; $lanes] }
Expand All @@ -361,5 +379,14 @@ macro_rules! define_mask_vector {
pub const fn new($($var: $type),*) -> Self {
Self($($var.0),*)
}
};
{ new_from_bool $type:ty | $($var:ident)* } => {
/// Used internally (since we can't use the Into trait in `const fn`s)
#[allow(clippy::too_many_arguments)]
#[allow(unused)]
#[inline]
pub(crate) const fn new_from_bool($($var: bool),*) -> Self {
Self($(<$type>::new($var).0),*)
}
}
}
Loading