summaryrefslogtreecommitdiffstats
path: root/library/portable-simd/crates/core_simd/tests/to_bytes.rs
blob: 66a7981cdc3dd78348b43432d7ca41d9f991b979 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#![feature(portable_simd)]

use core_simd::simd::{Simd, ToBytes};

#[test]
fn byte_convert() {
    let int = Simd::<u32, 2>::from_array([0xdeadbeef, 0x8badf00d]);
    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);
}