1 // Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
13 //! These types can be used for accessing basic SIMD operations. Currently
14 //! comparison operators are not implemented. To use SSE3+, you must enable
15 //! the features, like `-C target-feature=sse3,sse4.1,sse4.2`, or a more
16 //! specific `target-cpu`. No other SIMD intrinsics or high-level wrappers are
17 //! provided beyond this module.
21 //! These are all experimental. The interface may change entirely, without
24 #![unstable(feature = "core_simd",
25 reason = "needs an RFC to flesh out the design",
27 #![deprecated(since = "1.3.0",
28 reason = "use the external `simd` crate instead")]
30 #![allow(non_camel_case_types)]
31 #![allow(missing_docs)]
34 use ops::{Add, Sub, Mul, Div, Shl, Shr, BitAnd, BitOr, BitXor};
36 // FIXME(stage0): the contents of macro can be inlined.
37 // ABIs are verified as valid as soon as they are parsed, i.e. before
38 // `cfg` stripping. The `platform-intrinsic` ABI is new, so stage0
39 // doesn't know about it, but it still errors out when it hits it
40 // (despite this being in a `cfg(not(stage0))` module).
43 extern "platform-intrinsic" {
44 fn simd_add<T>(x: T, y: T) -> T;
45 fn simd_sub<T>(x: T, y: T) -> T;
46 fn simd_mul<T>(x: T, y: T) -> T;
47 fn simd_div<T>(x: T, y: T) -> T;
48 fn simd_shl<T>(x: T, y: T) -> T;
49 fn simd_shr<T>(x: T, y: T) -> T;
50 fn simd_and<T>(x: T, y: T) -> T;
51 fn simd_or<T>(x: T, y: T) -> T;
52 fn simd_xor<T>(x: T, y: T) -> T;
59 #[derive(Copy, Clone, Debug)]
61 pub struct i8x16(pub i8, pub i8, pub i8, pub i8,
62 pub i8, pub i8, pub i8, pub i8,
63 pub i8, pub i8, pub i8, pub i8,
64 pub i8, pub i8, pub i8, pub i8);
67 #[derive(Copy, Clone, Debug)]
69 pub struct i16x8(pub i16, pub i16, pub i16, pub i16,
70 pub i16, pub i16, pub i16, pub i16);
73 #[derive(Copy, Clone, Debug)]
75 pub struct i32x4(pub i32, pub i32, pub i32, pub i32);
78 #[derive(Copy, Clone, Debug)]
80 pub struct i64x2(pub i64, pub i64);
83 #[derive(Copy, Clone, Debug)]
85 pub struct u8x16(pub u8, pub u8, pub u8, pub u8,
86 pub u8, pub u8, pub u8, pub u8,
87 pub u8, pub u8, pub u8, pub u8,
88 pub u8, pub u8, pub u8, pub u8);
91 #[derive(Copy, Clone, Debug)]
93 pub struct u16x8(pub u16, pub u16, pub u16, pub u16,
94 pub u16, pub u16, pub u16, pub u16);
97 #[derive(Copy, Clone, Debug)]
99 pub struct u32x4(pub u32, pub u32, pub u32, pub u32);
102 #[derive(Copy, Clone, Debug)]
104 pub struct u64x2(pub u64, pub u64);
107 #[derive(Copy, Clone, Debug)]
109 pub struct f32x4(pub f32, pub f32, pub f32, pub f32);
112 #[derive(Copy, Clone, Debug)]
114 pub struct f64x2(pub f64, pub f64);
116 macro_rules! impl_traits {
117 ($($trayt: ident, $method: ident, $func: ident: $($ty: ty),*;)*) => {
119 impl $trayt<$ty> for $ty {
121 fn $method(self, other: Self) -> Self {
132 Add, add, simd_add: u8x16, u16x8, u32x4, u64x2, i8x16, i16x8, i32x4, i64x2, f32x4, f64x2;
133 Sub, sub, simd_sub: u8x16, u16x8, u32x4, u64x2, i8x16, i16x8, i32x4, i64x2, f32x4, f64x2;
134 Mul, mul, simd_mul: u8x16, u16x8, u32x4, u64x2, i8x16, i16x8, i32x4, i64x2, f32x4, f64x2;
136 Div, div, simd_div: f32x4, f64x2;
138 Shl, shl, simd_shl: u8x16, u16x8, u32x4, u64x2, i8x16, i16x8, i32x4, i64x2;
139 Shr, shr, simd_shr: u8x16, u16x8, u32x4, u64x2, i8x16, i16x8, i32x4, i64x2;
140 BitAnd, bitand, simd_and: u8x16, u16x8, u32x4, u64x2, i8x16, i16x8, i32x4, i64x2;
141 BitOr, bitor, simd_or: u8x16, u16x8, u32x4, u64x2, i8x16, i16x8, i32x4, i64x2;
142 BitXor, bitxor, simd_xor: u8x16, u16x8, u32x4, u64x2, i8x16, i16x8, i32x4, i64x2;