Created
March 21, 2021 19:36
-
-
Save ayosec/19c620d5808efa0273cf3cbba2b9951f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::arch::x86_64 as S; | |
fn main() { | |
let data: &[u8; 16] = b"1e0b98cfa67ebe20"; | |
let pattern: &[u8; 16] = b"b98............."; | |
let mask; | |
unsafe { | |
let v0 = S::_mm_loadu_si128(data.as_ptr().cast()); | |
let v1 = S::_mm_loadu_si128(pattern.as_ptr().cast()); | |
let m1 = S::_mm_cmpestrm(v1, 3, v0, 16, S::_SIDD_CMP_EQUAL_ORDERED); | |
mask = S::_mm_extract_epi16(m1, 0) as u16; | |
} | |
let trailing_zeros = mask.trailing_zeros() as usize; | |
println!("m = {:016b}", mask); | |
println!("match = {:?}", std::str::from_utf8(&data[trailing_zeros..])); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment