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
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
//! Portable Packed-SIMD Vectors.
//!
//! These types are:
//!
//! * portable: work correctly on all architectures,
//! * packed: have a size fixed at compile-time.
//!
//! These two terms are the opposites of:
//!
//! * architecture-specific: only available in a particular architecture,
//! * scalable: the vector's size is dynamic.
//!
//! This module is structured as follows:
//!
//! * `api`: defines the API of the portable packed vector types.
//! * `v{width}`: defines the portable vector types for a particular `width`.
//!
//! The portable packed vector types are named using the following schema:
//! `{t}{l_w}x{l_n}`:
//!
//! * `t`: type - single letter corresponding to the following Rust literal
//! types:
//!   * `i`: signed integer
//!   * `u`: unsigned integer
//!   * `f`: floating point
//!   * `m`: vector mask
//! * `l_w`: lane width in bits
//! * `l_n`: number of lanes
//!
//! For example, `f32x4` is a vector type containing four 32-bit wide
//! floating-point numbers. The total width of this type is 32 bit times 4
//! lanes, that is, 128 bits, and is thus defined in the `v128` module.

#[macro_use]
mod api;

mod v128;
mod v16;
mod v256;
mod v32;
mod v512;
mod v64;

pub use self::v128::*;
pub use self::v16::*;
pub use self::v256::*;
pub use self::v32::*;
pub use self::v512::*;
pub use self::v64::*;

/// Safe lossless bitwise conversion from `T` to `Self`.
pub trait FromBits<T>: ::marker::Sized {
    /// Safe lossless bitwise from `T` to `Self`.
    fn from_bits(T) -> Self;
}

/// Safe lossless bitwise conversion from `Self` to `T`.
pub trait IntoBits<T>: ::marker::Sized {
    /// Safe lossless bitwise transmute from `self` to `T`.
    fn into_bits(self) -> T;
}

// FromBits implies IntoBits.
impl<T, U> IntoBits<U> for T
where
    U: FromBits<T>,
{
    #[inline]
    fn into_bits(self) -> U {
        debug_assert!(::mem::size_of::<Self>() == ::mem::size_of::<U>());
        U::from_bits(self)
    }
}

// FromBits (and thus IntoBits) is reflexive.
impl<T> FromBits<T> for T {
    #[inline]
    fn from_bits(t: Self) -> Self {
        t
    }
}

/// Workarounds code generation issues.
#[cfg(target_arch = "aarch64")]
mod codegen {
    #[cfg(target_arch = "aarch64")]
    pub mod wrapping {
        pub trait Wrapping {
            fn add(self, other: Self) -> Self;
            fn mul(self, other: Self) -> Self;
        }

        macro_rules! int_impl {
            ($id:ident) => {
                impl Wrapping for $id {
                    fn add(self, other: Self) -> Self {
                        self.wrapping_add(other)
                    }
                    fn mul(self, other: Self) -> Self {
                        self.wrapping_mul(other)
                    }
                }
            };
        }
        int_impl!(i8);
        int_impl!(i16);
        int_impl!(i32);
        int_impl!(i64);
        int_impl!(u8);
        int_impl!(u16);
        int_impl!(u32);
        int_impl!(u64);

        macro_rules! float_impl {
            ($id:ident) => {
                impl Wrapping for $id {
                    fn add(self, other: Self) -> Self {
                        self + other
                    }
                    fn mul(self, other: Self) -> Self {
                        self * other
                    }
                }
            };
        }
        float_impl!(f32);
        float_impl!(f64);
    }

}