memx/arch/x86/needles/
sgl.rs

1use super::{__m128i, __m256i};
2use super::{_b16_eq, _b16_from_b32, _b16_value, _b32_eq, _b32_value};
3use crate::utils::B1Sgl;
4
5#[derive(Debug, Copy, Clone)]
6pub(crate) struct MMB16Sgl {
7    pub v1: __m128i,
8}
9impl MMB16Sgl {
10    #[inline(always)]
11    pub fn new(b1: u8) -> Self {
12        Self {
13            v1: unsafe { _b16_value(b1) },
14        }
15    }
16}
17impl PartialEq for MMB16Sgl {
18    fn eq(&self, other: &Self) -> bool {
19        unsafe { _b16_eq(self.v1, other.v1) }
20    }
21}
22
23impl From<B1Sgl> for MMB16Sgl {
24    fn from(cc: B1Sgl) -> Self {
25        Self::new(cc.v1)
26    }
27}
28
29#[derive(Debug, Copy, Clone)]
30pub(crate) struct MMB32Sgl {
31    pub v1: __m256i,
32}
33impl MMB32Sgl {
34    #[inline(always)]
35    pub fn new(b1: u8) -> Self {
36        Self {
37            v1: unsafe { _b32_value(b1) },
38        }
39    }
40}
41impl PartialEq for MMB32Sgl {
42    fn eq(&self, other: &Self) -> bool {
43        unsafe { _b32_eq(self.v1, other.v1) }
44    }
45}
46
47impl From<B1Sgl> for MMB32Sgl {
48    fn from(cc: B1Sgl) -> Self {
49        Self::new(cc.v1)
50    }
51}
52
53impl From<MMB32Sgl> for MMB16Sgl {
54    fn from(cc: MMB32Sgl) -> Self {
55        Self {
56            v1: unsafe { _b16_from_b32(cc.v1) },
57        }
58    }
59}
60
61#[cfg(test)]
62mod mini {
63    #![allow(clippy::clone_on_copy)]
64    use super::super::super::cpuid;
65    use super::*;
66    //
67    #[test]
68    fn t_b32() {
69        if !cpuid::has_avx2() {
70            return;
71        }
72        let a = MMB32Sgl::new(b'A');
73        let b = a.clone();
74        let c = a;
75        assert_eq!(a, b);
76        assert_eq!(a, c);
77        assert_eq!(
78            format!("{a:?}"),
79            "MMB32Sgl { v1: __m256i(4702111234474983745, 4702111234474983745, 4702111234474983745, 4702111234474983745) }"
80        );
81    }
82    #[test]
83    fn t_b16() {
84        let a = MMB16Sgl::new(b'A');
85        let b = a.clone();
86        let c = a;
87        assert_eq!(a, b);
88        assert_eq!(a, c);
89        assert_eq!(
90            format!("{a:?}"),
91            "MMB16Sgl { v1: __m128i(4702111234474983745, 4702111234474983745) }"
92        );
93    }
94    #[test]
95    fn t_into() {
96        if !cpuid::has_avx2() {
97            return;
98        }
99        let a_b32 = MMB32Sgl::new(b'A');
100        let a_b16: MMB16Sgl = a_b32.into();
101        assert_eq!(a_b32, MMB32Sgl::new(b'A'));
102        assert_eq!(a_b16, MMB16Sgl::new(b'A'));
103    }
104}