]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/simd-size-align.rs
Rollup merge of #45171 - rust-lang:petrochenkov-patch-2, r=steveklabnik
[rust.git] / src / test / run-pass / simd-size-align.rs
1 // Copyright 2015 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.
4 //
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.
10
11
12 #![feature(repr_simd)]
13 #![allow(non_camel_case_types)]
14
15 use std::mem;
16
17 /// `T` should satisfy `size_of T (mod min_align_of T) === 0` to be stored at `Vec<T>` properly
18 /// Please consult the issue #20460
19 fn check<T>() {
20     assert_eq!(mem::size_of::<T>() % mem::min_align_of::<T>(), 0)
21 }
22
23 fn main() {
24     check::<u8x2>();
25     check::<u8x3>();
26     check::<u8x4>();
27     check::<u8x5>();
28     check::<u8x6>();
29     check::<u8x7>();
30     check::<u8x8>();
31
32     check::<i16x2>();
33     check::<i16x3>();
34     check::<i16x4>();
35     check::<i16x5>();
36     check::<i16x6>();
37     check::<i16x7>();
38     check::<i16x8>();
39
40     check::<f32x2>();
41     check::<f32x3>();
42     check::<f32x4>();
43     check::<f32x5>();
44     check::<f32x6>();
45     check::<f32x7>();
46     check::<f32x8>();
47 }
48
49 #[repr(simd)] struct u8x2(u8, u8);
50 #[repr(simd)] struct u8x3(u8, u8, u8);
51 #[repr(simd)] struct u8x4(u8, u8, u8, u8);
52 #[repr(simd)] struct u8x5(u8, u8, u8, u8, u8);
53 #[repr(simd)] struct u8x6(u8, u8, u8, u8, u8, u8);
54 #[repr(simd)] struct u8x7(u8, u8, u8, u8, u8, u8, u8);
55 #[repr(simd)] struct u8x8(u8, u8, u8, u8, u8, u8, u8, u8);
56
57 #[repr(simd)] struct i16x2(i16, i16);
58 #[repr(simd)] struct i16x3(i16, i16, i16);
59 #[repr(simd)] struct i16x4(i16, i16, i16, i16);
60 #[repr(simd)] struct i16x5(i16, i16, i16, i16, i16);
61 #[repr(simd)] struct i16x6(i16, i16, i16, i16, i16, i16);
62 #[repr(simd)] struct i16x7(i16, i16, i16, i16, i16, i16, i16);
63 #[repr(simd)] struct i16x8(i16, i16, i16, i16, i16, i16, i16, i16);
64
65 #[repr(simd)] struct f32x2(f32, f32);
66 #[repr(simd)] struct f32x3(f32, f32, f32);
67 #[repr(simd)] struct f32x4(f32, f32, f32, f32);
68 #[repr(simd)] struct f32x5(f32, f32, f32, f32, f32);
69 #[repr(simd)] struct f32x6(f32, f32, f32, f32, f32, f32);
70 #[repr(simd)] struct f32x7(f32, f32, f32, f32, f32, f32, f32);
71 #[repr(simd)] struct f32x8(f32, f32, f32, f32, f32, f32, f32, f32);