|
10 | 10 |
|
11 | 11 | //! SIMD vectors.
|
12 | 12 | //!
|
13 |
| -//! These types can be used for accessing basic SIMD operations. Each of them |
14 |
| -//! implements the standard arithmetic operator traits (Add, Sub, Mul, Div, |
15 |
| -//! Rem, Shl, Shr) through compiler magic, rather than explicitly. Currently |
| 13 | +//! These types can be used for accessing basic SIMD operations. Currently |
16 | 14 | //! comparison operators are not implemented. To use SSE3+, you must enable
|
17 | 15 | //! the features, like `-C target-feature=sse3,sse4.1,sse4.2`, or a more
|
18 | 16 | //! specific `target-cpu`. No other SIMD intrinsics or high-level wrappers are
|
19 | 17 | //! provided beyond this module.
|
20 | 18 | //!
|
21 |
| -//! ```rust |
22 |
| -//! #![feature(core_simd)] |
23 |
| -//! |
24 |
| -//! fn main() { |
25 |
| -//! use std::simd::f32x4; |
26 |
| -//! let a = f32x4(40.0, 41.0, 42.0, 43.0); |
27 |
| -//! let b = f32x4(1.0, 1.1, 3.4, 9.8); |
28 |
| -//! println!("{:?}", a + b); |
29 |
| -//! } |
30 |
| -//! ``` |
31 |
| -//! |
32 | 19 | //! # Stability Note
|
33 | 20 | //!
|
34 | 21 | //! These are all experimental. The interface may change entirely, without
|
|
37 | 24 | #![unstable(feature = "core_simd",
|
38 | 25 | reason = "needs an RFC to flesh out the design",
|
39 | 26 | issue = "27731")]
|
| 27 | +#![deprecated(since = "1.3.0", |
| 28 | + reason = "use the external `simd` crate instead")] |
40 | 29 |
|
41 | 30 | #![allow(non_camel_case_types)]
|
42 | 31 | #![allow(missing_docs)]
|
| 32 | +#![allow(deprecated)] |
| 33 | + |
| 34 | +use ops::{Add, Sub, Mul, Div, Shl, Shr, BitAnd, BitOr, BitXor}; |
| 35 | + |
| 36 | +macro_rules! argh { |
| 37 | + () => { |
| 38 | + extern "platform-intrinsic" { |
| 39 | + fn simd_add<T>(x: T, y: T) -> T; |
| 40 | + fn simd_sub<T>(x: T, y: T) -> T; |
| 41 | + fn simd_mul<T>(x: T, y: T) -> T; |
| 42 | + fn simd_div<T>(x: T, y: T) -> T; |
| 43 | + fn simd_shl<T>(x: T, y: T) -> T; |
| 44 | + fn simd_shr<T>(x: T, y: T) -> T; |
| 45 | + fn simd_and<T>(x: T, y: T) -> T; |
| 46 | + fn simd_or<T>(x: T, y: T) -> T; |
| 47 | + fn simd_xor<T>(x: T, y: T) -> T; |
| 48 | + } |
| 49 | + } |
| 50 | +} |
| 51 | +argh!(); |
43 | 52 |
|
44 |
| -#[simd] |
| 53 | +#[repr(simd)] |
45 | 54 | #[derive(Copy, Clone, Debug)]
|
46 | 55 | #[repr(C)]
|
47 | 56 | pub struct i8x16(pub i8, pub i8, pub i8, pub i8,
|
48 | 57 | pub i8, pub i8, pub i8, pub i8,
|
49 | 58 | pub i8, pub i8, pub i8, pub i8,
|
50 | 59 | pub i8, pub i8, pub i8, pub i8);
|
51 | 60 |
|
52 |
| -#[simd] |
| 61 | +#[repr(simd)] |
53 | 62 | #[derive(Copy, Clone, Debug)]
|
54 | 63 | #[repr(C)]
|
55 | 64 | pub struct i16x8(pub i16, pub i16, pub i16, pub i16,
|
56 | 65 | pub i16, pub i16, pub i16, pub i16);
|
57 | 66 |
|
58 |
| -#[simd] |
| 67 | +#[repr(simd)] |
59 | 68 | #[derive(Copy, Clone, Debug)]
|
60 | 69 | #[repr(C)]
|
61 | 70 | pub struct i32x4(pub i32, pub i32, pub i32, pub i32);
|
62 | 71 |
|
63 |
| -#[simd] |
| 72 | +#[repr(simd)] |
64 | 73 | #[derive(Copy, Clone, Debug)]
|
65 | 74 | #[repr(C)]
|
66 | 75 | pub struct i64x2(pub i64, pub i64);
|
67 | 76 |
|
68 |
| -#[simd] |
| 77 | +#[repr(simd)] |
69 | 78 | #[derive(Copy, Clone, Debug)]
|
70 | 79 | #[repr(C)]
|
71 | 80 | pub struct u8x16(pub u8, pub u8, pub u8, pub u8,
|
72 | 81 | pub u8, pub u8, pub u8, pub u8,
|
73 | 82 | pub u8, pub u8, pub u8, pub u8,
|
74 | 83 | pub u8, pub u8, pub u8, pub u8);
|
75 | 84 |
|
76 |
| -#[simd] |
| 85 | +#[repr(simd)] |
77 | 86 | #[derive(Copy, Clone, Debug)]
|
78 | 87 | #[repr(C)]
|
79 | 88 | pub struct u16x8(pub u16, pub u16, pub u16, pub u16,
|
80 | 89 | pub u16, pub u16, pub u16, pub u16);
|
81 | 90 |
|
82 |
| -#[simd] |
| 91 | +#[repr(simd)] |
83 | 92 | #[derive(Copy, Clone, Debug)]
|
84 | 93 | #[repr(C)]
|
85 | 94 | pub struct u32x4(pub u32, pub u32, pub u32, pub u32);
|
86 | 95 |
|
87 |
| -#[simd] |
| 96 | +#[repr(simd)] |
88 | 97 | #[derive(Copy, Clone, Debug)]
|
89 | 98 | #[repr(C)]
|
90 | 99 | pub struct u64x2(pub u64, pub u64);
|
91 | 100 |
|
92 |
| -#[simd] |
| 101 | +#[repr(simd)] |
93 | 102 | #[derive(Copy, Clone, Debug)]
|
94 | 103 | #[repr(C)]
|
95 | 104 | pub struct f32x4(pub f32, pub f32, pub f32, pub f32);
|
96 | 105 |
|
97 |
| -#[simd] |
| 106 | +#[repr(simd)] |
98 | 107 | #[derive(Copy, Clone, Debug)]
|
99 | 108 | #[repr(C)]
|
100 | 109 | pub struct f64x2(pub f64, pub f64);
|
| 110 | + |
| 111 | +macro_rules! impl_traits { |
| 112 | + ($($trayt: ident, $method: ident, $func: ident: $($ty: ty),*;)*) => { |
| 113 | + $($( |
| 114 | + impl $trayt<$ty> for $ty { |
| 115 | + type Output = Self; |
| 116 | + fn $method(self, other: Self) -> Self { |
| 117 | + unsafe { |
| 118 | + $func(self, other) |
| 119 | + } |
| 120 | + } |
| 121 | + } |
| 122 | + )*)* |
| 123 | + } |
| 124 | +} |
| 125 | + |
| 126 | +impl_traits! { |
| 127 | + Add, add, simd_add: u8x16, u16x8, u32x4, u64x2, i8x16, i16x8, i32x4, i64x2, f32x4, f64x2; |
| 128 | + Sub, sub, simd_sub: u8x16, u16x8, u32x4, u64x2, i8x16, i16x8, i32x4, i64x2, f32x4, f64x2; |
| 129 | + Mul, mul, simd_mul: u8x16, u16x8, u32x4, u64x2, i8x16, i16x8, i32x4, i64x2, f32x4, f64x2; |
| 130 | + |
| 131 | + Div, div, simd_div: f32x4, f64x2; |
| 132 | + |
| 133 | + Shl, shl, simd_shl: u8x16, u16x8, u32x4, u64x2, i8x16, i16x8, i32x4, i64x2; |
| 134 | + Shr, shr, simd_shr: u8x16, u16x8, u32x4, u64x2, i8x16, i16x8, i32x4, i64x2; |
| 135 | + BitAnd, bitand, simd_and: u8x16, u16x8, u32x4, u64x2, i8x16, i16x8, i32x4, i64x2; |
| 136 | + BitOr, bitor, simd_or: u8x16, u16x8, u32x4, u64x2, i8x16, i16x8, i32x4, i64x2; |
| 137 | + BitXor, bitxor, simd_xor: u8x16, u16x8, u32x4, u64x2, i8x16, i16x8, i32x4, i64x2; |
| 138 | +} |
0 commit comments