Guest User

Untitled

a guest
Dec 13th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. use core::arch::x86_64 as simd;
  2.  
  3. #[no_mangle]
  4. fn stuff(bytes: &[u8]) -> u16 {
  5. unsafe {
  6. let bytes: [i32; 4] = *(bytes.as_ptr() as *const [i32; 4]);
  7.  
  8. let vec = simd::_mm_set_epi32(
  9. bytes[3], bytes[2], bytes[1], bytes[0],
  10. );
  11.  
  12. simd::_mm_movemask_epi8(vec) as u16
  13. }
  14. }
  15.  
  16. static BYTES: &[u8] = &[
  17. // We ignore this byte, it's only here to screw with alignment
  18. 0x00,
  19.  
  20. 0xFF,0x00,0x00,0x00,
  21. 0x00,0x00,0x00,0x00,
  22. 0xFF,0xFF,0xFF,0xFF,
  23. 0xFF,0xFF,0xFF,0x00,
  24. ];
  25.  
  26. fn main() {
  27. let bits = stuff(&BYTES[1..]);
  28.  
  29. // Bits are in reverse order due to LE architecture
  30. assert_eq!(bits, 0b0111_1111_0000_0001);
  31.  
  32. println!("{:016b}", bits);
  33. }
Add Comment
Please, Sign In to add comment