From 874b07df0298dcc5abdcc60bb5e5fb3e89cec374 Mon Sep 17 00:00:00 2001 From: Nathan Vegdahl Date: Sat, 29 Jun 2019 07:48:33 +0900 Subject: [PATCH] Filled in missing methods on the fall-back non-SIMD code. --- sub_crates/float4/src/lib.rs | 41 ++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/sub_crates/float4/src/lib.rs b/sub_crates/float4/src/lib.rs index 327fbf9..0f081b3 100644 --- a/sub_crates/float4/src/lib.rs +++ b/sub_crates/float4/src/lib.rs @@ -680,8 +680,8 @@ mod x86_64_sse { /// Returns whether all four bools are false. /// - /// This is the `OR` operation on all the contained bools. If even - /// one bool is true, this returns true. + /// 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 { let a = unsafe { *(&self.data as *const __m128 as *const u128) }; @@ -1269,21 +1269,25 @@ mod fallback { det } - /// Essentially a tuple of four bools, which will use SIMD operations - /// where possible on a platform. - #[cfg(feature = "simd_perf")] - #[derive(Debug, Copy, Clone)] - pub struct Bool4 { - data: bool32fx4, - } - - #[cfg(not(feature = "simd_perf"))] + /// Essentially a tuple of four bools. #[derive(Debug, Copy, Clone)] pub struct Bool4 { data: [bool; 4], } 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. #[inline(always)] pub fn get_n(self, n: usize) -> bool { @@ -1318,6 +1322,15 @@ mod fallback { 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] pub fn to_bitmask(self) -> u8 { (self.get_0() as u8) @@ -1598,4 +1611,10 @@ mod tests { 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()); + } }