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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
//! `FromBits` and `IntoBits` between portable vector types and the
//! architecture-specific vector types.
#[rustfmt::skip]

// FIXME: MIPS FromBits/IntoBits

#[allow(unused)]
use crate::*;

/// This macro implements FromBits for the portable and the architecture
/// specific vector types.
///
/// The "leaf" case is at the bottom, and the most generic case is at the top.
/// The generic case is split into smaller cases recursively.
macro_rules! impl_arch {
    ([$arch_head_i:ident[$arch_head_tt:tt]: $($arch_head_ty:ident),*],
     $([$arch_tail_i:ident[$arch_tail_tt:tt]: $($arch_tail_ty:ident),*]),* |
     from: $($from_ty:ident),* | into: $($into_ty:ident),* |
     test: $test_tt:tt) => {
        impl_arch!(
            [$arch_head_i[$arch_head_tt]: $($arch_head_ty),*] |
            from: $($from_ty),* |
            into: $($into_ty),* |
            test: $test_tt
        );
        impl_arch!(
            $([$arch_tail_i[$arch_tail_tt]: $($arch_tail_ty),*]),* |
            from: $($from_ty),* |
            into: $($into_ty),* |
            test: $test_tt
        );
    };
    ([$arch:ident[$arch_tt:tt]: $($arch_ty:ident),*] |
     from: $($from_ty:ident),* | into: $($into_ty:ident),* |
     test: $test_tt:tt) => {
        // note: if target is "arm", "+v7,+neon" must be enabled
        // and the std library must be recompiled with them
        #[cfg(any(
            not(target_arch = "arm"),
            all(target_feature = "v7", target_feature = "neon",
                any(feature = "core_arch", libcore_neon)))
        )]
        // note: if target is "powerpc", "altivec" must be enabled
        // and the std library must be recompiled with it
        #[cfg(any(
            not(target_arch = "powerpc"),
            all(target_feature = "altivec", feature = "core_arch"),
        ))]
        #[cfg(target_arch = $arch_tt)]
        use crate::arch::$arch::{
            $($arch_ty),*
        };

        #[cfg(any(
            not(target_arch = "arm"),
            all(target_feature = "v7", target_feature = "neon",
                any(feature = "core_arch", libcore_neon)))
        )]
        #[cfg(any(
            not(target_arch = "powerpc"),
            all(target_feature = "altivec", feature = "core_arch"),
        ))]
        #[cfg(target_arch = $arch_tt)]
        impl_arch!($($arch_ty),* | $($from_ty),* | $($into_ty),* |
                   test: $test_tt);
    };
    ($arch_head:ident, $($arch_tail:ident),* | $($from_ty:ident),*
     | $($into_ty:ident),* | test: $test_tt:tt) => {
        impl_arch!($arch_head | $($from_ty),* | $($into_ty),* |
                   test: $test_tt);
        impl_arch!($($arch_tail),* | $($from_ty),* | $($into_ty),* |
                   test: $test_tt);
    };
    ($arch_head:ident | $($from_ty:ident),* | $($into_ty:ident),* |
     test: $test_tt:tt) => {
        impl_from_bits!($arch_head[$test_tt]: $($from_ty),*);
        impl_into_bits!($arch_head[$test_tt]: $($into_ty),*);
    };
}

////////////////////////////////////////////////////////////////////////////////
// Implementations for the 64-bit wide vector types:

// FIXME: 64-bit single element types
// FIXME: arm/aarch float16x4_t missing
impl_arch!(
    [
        arm["arm"]: int8x8_t,
        uint8x8_t,
        poly8x8_t,
        int16x4_t,
        uint16x4_t,
        poly16x4_t,
        int32x2_t,
        uint32x2_t,
        float32x2_t,
        int64x1_t,
        uint64x1_t
    ],
    [
        aarch64["aarch64"]: int8x8_t,
        uint8x8_t,
        poly8x8_t,
        int16x4_t,
        uint16x4_t,
        poly16x4_t,
        int32x2_t,
        uint32x2_t,
        float32x2_t,
        int64x1_t,
        uint64x1_t,
        float64x1_t
    ] | from: i8x8,
    u8x8,
    m8x8,
    i16x4,
    u16x4,
    m16x4,
    i32x2,
    u32x2,
    f32x2,
    m32x2 | into: i8x8,
    u8x8,
    i16x4,
    u16x4,
    i32x2,
    u32x2,
    f32x2 | test: test_v64
);

////////////////////////////////////////////////////////////////////////////////
// Implementations for the 128-bit wide vector types:

// FIXME: arm/aarch float16x8_t missing
// FIXME: ppc vector_pixel missing
// FIXME: ppc64 vector_Float16 missing
// FIXME: ppc64 vector_signed_long_long missing
// FIXME: ppc64 vector_unsigned_long_long missing
// FIXME: ppc64 vector_bool_long_long missing
// FIXME: ppc64 vector_signed___int128 missing
// FIXME: ppc64 vector_unsigned___int128 missing
impl_arch!(
    [x86["x86"]: __m128, __m128i, __m128d],
    [x86_64["x86_64"]: __m128, __m128i, __m128d],
    [
        arm["arm"]: int8x16_t,
        uint8x16_t,
        poly8x16_t,
        int16x8_t,
        uint16x8_t,
        poly16x8_t,
        int32x4_t,
        uint32x4_t,
        float32x4_t,
        int64x2_t,
        uint64x2_t
    ],
    [
        aarch64["aarch64"]: int8x16_t,
        uint8x16_t,
        poly8x16_t,
        int16x8_t,
        uint16x8_t,
        poly16x8_t,
        int32x4_t,
        uint32x4_t,
        float32x4_t,
        int64x2_t,
        uint64x2_t,
        float64x2_t
    ],
    [
        powerpc["powerpc"]: vector_signed_char,
        vector_unsigned_char,
        vector_signed_short,
        vector_unsigned_short,
        vector_signed_int,
        vector_unsigned_int,
        vector_float
    ],
    [
        powerpc64["powerpc64"]: vector_signed_char,
        vector_unsigned_char,
        vector_signed_short,
        vector_unsigned_short,
        vector_signed_int,
        vector_unsigned_int,
        vector_float,
        vector_signed_long,
        vector_unsigned_long,
        vector_double
    ] | from: i8x16,
    u8x16,
    m8x16,
    i16x8,
    u16x8,
    m16x8,
    i32x4,
    u32x4,
    f32x4,
    m32x4,
    i64x2,
    u64x2,
    f64x2,
    m64x2,
    i128x1,
    u128x1,
    m128x1 | into: i8x16,
    u8x16,
    i16x8,
    u16x8,
    i32x4,
    u32x4,
    f32x4,
    i64x2,
    u64x2,
    f64x2,
    i128x1,
    u128x1 | test: test_v128
);

impl_arch!(
    [powerpc["powerpc"]: vector_bool_char],
    [powerpc64["powerpc64"]: vector_bool_char] | from: m8x16,
    m16x8,
    m32x4,
    m64x2,
    m128x1 | into: i8x16,
    u8x16,
    i16x8,
    u16x8,
    i32x4,
    u32x4,
    f32x4,
    i64x2,
    u64x2,
    f64x2,
    i128x1,
    u128x1,
    // Masks:
    m8x16 | test: test_v128
);

impl_arch!(
    [powerpc["powerpc"]: vector_bool_short],
    [powerpc64["powerpc64"]: vector_bool_short] | from: m16x8,
    m32x4,
    m64x2,
    m128x1 | into: i8x16,
    u8x16,
    i16x8,
    u16x8,
    i32x4,
    u32x4,
    f32x4,
    i64x2,
    u64x2,
    f64x2,
    i128x1,
    u128x1,
    // Masks:
    m8x16,
    m16x8 | test: test_v128
);

impl_arch!(
    [powerpc["powerpc"]: vector_bool_int],
    [powerpc64["powerpc64"]: vector_bool_int] | from: m32x4,
    m64x2,
    m128x1 | into: i8x16,
    u8x16,
    i16x8,
    u16x8,
    i32x4,
    u32x4,
    f32x4,
    i64x2,
    u64x2,
    f64x2,
    i128x1,
    u128x1,
    // Masks:
    m8x16,
    m16x8,
    m32x4 | test: test_v128
);

impl_arch!(
    [powerpc64["powerpc64"]: vector_bool_long] | from: m64x2,
    m128x1 | into: i8x16,
    u8x16,
    i16x8,
    u16x8,
    i32x4,
    u32x4,
    f32x4,
    i64x2,
    u64x2,
    f64x2,
    i128x1,
    u128x1,
    // Masks:
    m8x16,
    m16x8,
    m32x4,
    m64x2 | test: test_v128
);

////////////////////////////////////////////////////////////////////////////////
// Implementations for the 256-bit wide vector types

impl_arch!(
    [x86["x86"]: __m256, __m256i, __m256d],
    [x86_64["x86_64"]: __m256, __m256i, __m256d] | from: i8x32,
    u8x32,
    m8x32,
    i16x16,
    u16x16,
    m16x16,
    i32x8,
    u32x8,
    f32x8,
    m32x8,
    i64x4,
    u64x4,
    f64x4,
    m64x4,
    i128x2,
    u128x2,
    m128x2 | into: i8x32,
    u8x32,
    i16x16,
    u16x16,
    i32x8,
    u32x8,
    f32x8,
    i64x4,
    u64x4,
    f64x4,
    i128x2,
    u128x2 | test: test_v256
);

////////////////////////////////////////////////////////////////////////////////
// FIXME: Implementations for the 512-bit wide vector types