pub trait Select<T> {
// Required method
fn select(self, if_true: T, if_false: T) -> T;
}Expand description
A trait for lanewise SIMD selection.
The method select is used to select lanes from two SIMD values based on
the elements of a SIMD mask.
The type of values to select from could be a SIMD vector (e.g.,
f32x4), or it could be a composite type over SIMD vectors (e.g., a
Vec3<f32x4> structure).
This trait is meant to be implemented for such downstream types. If you
simply want to call select, you do not need to import this trait as SIMD
vectors have an inherent method for this.
§Example
#[derive(Debug, PartialEq)]
struct Point {
x: u32x4,
y: u32x4,
}
impl Select<Point> for u32x4 {
fn select(self, if_true: Point, if_false: Point) -> Point {
Point {
x: self.select(if_true.x, if_false.x),
y: self.select(if_true.y, if_false.y),
}
}
}
let mask = u32x4::new([0, !0, !0, 0]);
let if_true = Point { x: u32x4::splat(2), y: u32x4::ZERO };
let if_false = Point { x: u32x4::ZERO, y: u32x4::splat(5) };
assert_eq!(
mask.select(if_true, if_false),
Point {
x: u32x4::new([0, 2, 2, 0]),
y: u32x4::new([5, 0, 0, 5]),
},
);Required Methods§
Sourcefn select(self, if_true: T, if_false: T) -> T
fn select(self, if_true: T, if_false: T) -> T
Lanewise SIMD selection.
If self is a SIMD vector, it is treated as a mask, where
each lane is considered true if all bits are one, or false if all bits are
zero.
For each lane:
- If
selfis true, return the corresponding lane ofif_true - If
selfis false, return the corresponding lane ofif_false
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".