Add support for the `BitAnd` and `BitAndAssign` traits
@@ -28,7 +28,7 @@ union __U128 {
const ONE: __m128i = unsafe { (__U128 { bytes: 1 }).vector };
const ONES: __m128i = unsafe {
(__U128 {
- bytes: 0xFFFF_FFFF_FFFF_FFFF,
+ bytes: 0xFFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF,
})
.vector
};
@@ -164,6 +164,21 @@ impl AsMut<[u8]> for Block {
}
}
+impl std::ops::BitAnd for Block {
+ type Output = Block;
+ #[inline]
+ fn bitand(self, rhs: Self) -> Self {
+ unsafe { Block(_mm_and_si128(self.0, rhs.0)) }
+ }
+}
+
+impl std::ops::BitAndAssign for Block {
+ #[inline]
+ fn bitand_assign(&mut self, rhs: Self) {
+ unsafe { self.0 = _mm_and_si128(self.0, rhs.0) }
+ }
+}
+
impl std::ops::BitXor for Block {
type Output = Block;
#[inline]
@@ -319,6 +334,13 @@ mod tests {
assert_eq!(x, z);
}
+ #[test]
+ fn test_and() {
+ let x = rand::random::<Block>();
+ let y = x & Block(ONES);
+ assert_eq!(x, y);
+ }
+
#[test]
fn test_color_bit() {
let x = rand::random::<Block>();
