Skip to content

Instantly share code, notes, and snippets.

@ayosec
Created March 21, 2021 19:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ayosec/19c620d5808efa0273cf3cbba2b9951f to your computer and use it in GitHub Desktop.
Save ayosec/19c620d5808efa0273cf3cbba2b9951f to your computer and use it in GitHub Desktop.
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