2023-10-01 21:28:03 -04:00
|
|
|
#![feature(portable_simd)]
|
2021-07-19 19:13:24 -04:00
|
|
|
|
2023-10-01 21:28:03 -04:00
|
|
|
use core_simd::simd::{Simd, ToBytes};
|
2021-05-24 08:37:15 -04:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn byte_convert() {
|
2021-08-07 21:06:40 +00:00
|
|
|
let int = Simd::<u32, 2>::from_array([0xdeadbeef, 0x8badf00d]);
|
2023-07-30 15:53:32 -04:00
|
|
|
let ne_bytes = int.to_ne_bytes();
|
|
|
|
let be_bytes = int.to_be_bytes();
|
|
|
|
let le_bytes = int.to_le_bytes();
|
|
|
|
assert_eq!(int[0].to_ne_bytes(), ne_bytes[..4]);
|
|
|
|
assert_eq!(int[1].to_ne_bytes(), ne_bytes[4..]);
|
|
|
|
assert_eq!(int[0].to_be_bytes(), be_bytes[..4]);
|
|
|
|
assert_eq!(int[1].to_be_bytes(), be_bytes[4..]);
|
|
|
|
assert_eq!(int[0].to_le_bytes(), le_bytes[..4]);
|
|
|
|
assert_eq!(int[1].to_le_bytes(), le_bytes[4..]);
|
|
|
|
assert_eq!(Simd::<u32, 2>::from_ne_bytes(ne_bytes), int);
|
|
|
|
assert_eq!(Simd::<u32, 2>::from_be_bytes(be_bytes), int);
|
|
|
|
assert_eq!(Simd::<u32, 2>::from_le_bytes(le_bytes), int);
|
2021-05-24 08:37:15 -04:00
|
|
|
}
|