Filled in missing methods on the fall-back non-SIMD code.

This commit is contained in:
Nathan Vegdahl 2019-06-29 07:48:33 +09:00
parent b09f9684d1
commit 874b07df02

View File

@ -680,8 +680,8 @@ mod x86_64_sse {
/// Returns whether all four bools are false. /// Returns whether all four bools are false.
/// ///
/// This is the `OR` operation on all the contained bools. If even /// This is the `NOT` operation on the result of `OR`ing all the
/// one bool is true, this returns true. /// contained bools. If even one bool is true, this returns false.
#[inline(always)] #[inline(always)]
pub fn is_all_false(&self) -> bool { pub fn is_all_false(&self) -> bool {
let a = unsafe { *(&self.data as *const __m128 as *const u128) }; let a = unsafe { *(&self.data as *const __m128 as *const u128) };
@ -1269,21 +1269,25 @@ mod fallback {
det det
} }
/// Essentially a tuple of four bools, which will use SIMD operations /// Essentially a tuple of four bools.
/// where possible on a platform.
#[cfg(feature = "simd_perf")]
#[derive(Debug, Copy, Clone)]
pub struct Bool4 {
data: bool32fx4,
}
#[cfg(not(feature = "simd_perf"))]
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
pub struct Bool4 { pub struct Bool4 {
data: [bool; 4], data: [bool; 4],
} }
impl Bool4 { impl Bool4 {
#[inline(always)]
pub fn new(a: bool, b: bool, c: bool, d: bool) -> Bool4 {
Bool4 { data: [a, b, c, d] }
}
#[inline(always)]
pub fn new_false() -> Bool4 {
Bool4 {
data: [false, false, false, false],
}
}
/// Returns the value of the nth element. /// Returns the value of the nth element.
#[inline(always)] #[inline(always)]
pub fn get_n(self, n: usize) -> bool { pub fn get_n(self, n: usize) -> bool {
@ -1318,6 +1322,15 @@ mod fallback {
self.get_n(3) self.get_n(3)
} }
/// Returns whether all four bools are false.
///
/// This is the `NOT` operation on the result of `OR`ing all the
/// contained bools. If even one bool is true, this returns false.
#[inline(always)]
pub fn is_all_false(&self) -> bool {
!(self.data[0] | self.data[1] | self.data[2] | self.data[3])
}
#[inline] #[inline]
pub fn to_bitmask(self) -> u8 { pub fn to_bitmask(self) -> u8 {
(self.get_0() as u8) (self.get_0() as u8)
@ -1598,4 +1611,10 @@ mod tests {
assert_eq!(r, 0b00001010); assert_eq!(r, 0b00001010);
} }
#[test]
fn bool4_is_all_false() {
assert_eq!(true, Bool4::new(false, false, false, false).is_all_false());
assert_eq!(false, Bool4::new(false, false, true, false).is_all_false());
}
} }