Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use core::arch::x86_64 as simd;
- #[no_mangle]
- fn stuff(bytes: &[u8]) -> u16 {
- unsafe {
- let bytes: [i32; 4] = *(bytes.as_ptr() as *const [i32; 4]);
- let vec = simd::_mm_set_epi32(
- bytes[3], bytes[2], bytes[1], bytes[0],
- );
- simd::_mm_movemask_epi8(vec) as u16
- }
- }
- static BYTES: &[u8] = &[
- // We ignore this byte, it's only here to screw with alignment
- 0x00,
- 0xFF,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,
- 0xFF,0xFF,0xFF,0xFF,
- 0xFF,0xFF,0xFF,0x00,
- ];
- fn main() {
- let bits = stuff(&BYTES[1..]);
- // Bits are in reverse order due to LE architecture
- assert_eq!(bits, 0b0111_1111_0000_0001);
- println!("{:016b}", bits);
- }
Add Comment
Please, Sign In to add comment