rust/crates/core_simd/tests/to_bytes.rs

15 lines
459 B
Rust
Raw Normal View History

#![feature(portable_simd, generic_const_exprs, adt_const_params)]
#![allow(incomplete_features)]
#![cfg(feature = "generic_const_exprs")]
2022-11-27 22:44:20 -06:00
use core_simd::simd::Simd;
2021-05-24 07:37:15 -05:00
#[test]
fn byte_convert() {
2021-08-07 16:06:40 -05:00
let int = Simd::<u32, 2>::from_array([0xdeadbeef, 0x8badf00d]);
2021-05-24 07:37:15 -05:00
let bytes = int.to_ne_bytes();
assert_eq!(int[0].to_ne_bytes(), bytes[..4]);
2021-05-24 07:37:15 -05:00
assert_eq!(int[1].to_ne_bytes(), bytes[4..]);
2021-08-07 16:06:40 -05:00
assert_eq!(Simd::<u32, 2>::from_ne_bytes(bytes), int);
2021-05-24 07:37:15 -05:00
}