1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//! Implements the `FromBits` trait for vector types, which performs bitwise
//! lossless transmutes between equally-sized vector types.
#![allow(unused)]

macro_rules! impl_from_bits__ {
    ($to:ident: $($from:ident),+) => {
        $(
            impl ::simd::FromBits<$from> for $to {
                #[inline]
                fn from_bits(f: $from) -> $to {
                    unsafe { ::mem::transmute(f) }
                }
            }
        )+
    }
}

macro_rules! impl_from_bits_ {
    ($to:ident: $($from:ident),+) => {
        vector_impl!([impl_from_bits__, $to: $($from),+]);
    }
}

macro_rules! impl_from_bits {
    ($to:ident: $elem_ty:ident, $test_mod:ident, $test_macro:ident | $($from:ident),+) => {
        impl_from_bits_!($to: $($from),+);

        $test_macro!(
            #[cfg(test)]
            mod $test_mod {
                $(
                    #[test]
                    fn $from() {
                        use ::coresimd::simd::*;
                        use ::std::mem;
                        assert_eq!(mem::size_of::<$from>(),
                                   mem::size_of::<$to>());
                        let a: $from = $from::default();
                        let b_0: $to = FromBits::from_bits(a);
                        let b_1: $to = a.into_bits();
                        assert_eq!(b_0, b_1);
                    }
                )+
            }
        );
    }
}