Skip to main content

parse_binary_avx512

Function parse_binary_avx512 

Source
pub unsafe fn parse_binary_avx512(bytes: &[u8], words: &mut [u64]) -> bool
Examples found in repository?
crates/competitive/src/data_structure/bitset.rs (line 52)
45    pub fn from_binary(s: &str) -> Option<Self> {
46        let bytes = s.as_bytes();
47        let mut bits = Self::new(bytes.len());
48        let end = bytes.len() / 64 * 64;
49        #[cfg(target_arch = "x86_64")]
50        let parsed = if avx512_enabled() && is_x86_feature_detected!("avx512bw") {
51            // SAFETY: AVX-512BW is available; each complete chunk contains 64 bytes.
52            unsafe { simd::parse_binary_avx512(&bytes[..end], bits.words_mut()) }
53        } else if is_x86_feature_detected!("avx2") {
54            // SAFETY: AVX2 is available; each complete chunk contains 64 bytes.
55            unsafe { simd::parse_binary_avx2(&bytes[..end], bits.words_mut()) }
56        } else {
57            Self::parse_binary_scalar(&bytes[..end], bits.words_mut())
58        };
59        #[cfg(not(target_arch = "x86_64"))]
60        let parsed = Self::parse_binary_scalar(&bytes[..end], bits.words_mut());
61        if !parsed {
62            return None;
63        }
64        if end != bytes.len() {
65            let mut word = 0;
66            for (i, &b) in bytes[end..].iter().enumerate() {
67                if b != b'0' && b != b'1' {
68                    return None;
69                }
70                word |= u64::from(b & 1) << i;
71            }
72            bits.words_mut()[end / 64] = word;
73        }
74        Some(bits)
75    }