]> git.proxmox.com Git - rustc.git/blame - src/test/run-pass/simd-intrinsic-generic-elements.rs
Imported Upstream version 1.9.0+dfsg1
[rustc.git] / src / test / run-pass / simd-intrinsic-generic-elements.rs
CommitLineData
e9174d1e
SL
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
54a0048b
SL
11#![feature(repr_simd, rustc_attrs, platform_intrinsics)]
12
13// ignore-pretty : (#23623) problems when ending with // comments
e9174d1e
SL
14
15#[repr(simd)]
16#[derive(Copy, Clone, Debug, PartialEq)]
17#[allow(non_camel_case_types)]
18struct i32x2(i32, i32);
19#[repr(simd)]
20#[derive(Copy, Clone, Debug, PartialEq)]
21#[allow(non_camel_case_types)]
22struct i32x3(i32, i32, i32);
23#[repr(simd)]
24#[derive(Copy, Clone, Debug, PartialEq)]
25#[allow(non_camel_case_types)]
26struct i32x4(i32, i32, i32, i32);
27#[repr(simd)]
28#[derive(Copy, Clone, Debug, PartialEq)]
29#[allow(non_camel_case_types)]
30struct i32x8(i32, i32, i32, i32,
31 i32, i32, i32, i32);
32
33extern "platform-intrinsic" {
34 fn simd_insert<T, E>(x: T, idx: u32, y: E) -> T;
35 fn simd_extract<T, E>(x: T, idx: u32) -> E;
36
37 fn simd_shuffle2<T, U>(x: T, y: T, idx: [u32; 2]) -> U;
38 fn simd_shuffle3<T, U>(x: T, y: T, idx: [u32; 3]) -> U;
39 fn simd_shuffle4<T, U>(x: T, y: T, idx: [u32; 4]) -> U;
40 fn simd_shuffle8<T, U>(x: T, y: T, idx: [u32; 8]) -> U;
41}
42
43macro_rules! all_eq {
44 ($a: expr, $b: expr) => {{
45 let a = $a;
46 let b = $b;
47 // type inference works better with the concrete type on the
48 // left, but humans work better with the expected on the
49 // right.
50 assert!(b == a,
51 "{:?} != {:?}", a, b);
52 }}
53}
54
54a0048b 55#[rustc_no_mir] // FIXME #27840 MIR doesn't handle shuffle constants.
e9174d1e
SL
56fn main() {
57 let x2 = i32x2(20, 21);
58 let x3 = i32x3(30, 31, 32);
59 let x4 = i32x4(40, 41, 42, 43);
60 let x8 = i32x8(80, 81, 82, 83, 84, 85, 86, 87);
61 unsafe {
62 all_eq!(simd_insert(x2, 0, 100), i32x2(100, 21));
63 all_eq!(simd_insert(x2, 1, 100), i32x2(20, 100));
64
65 all_eq!(simd_insert(x3, 0, 100), i32x3(100, 31, 32));
66 all_eq!(simd_insert(x3, 1, 100), i32x3(30, 100, 32));
67 all_eq!(simd_insert(x3, 2, 100), i32x3(30, 31, 100));
68
69 all_eq!(simd_insert(x4, 0, 100), i32x4(100, 41, 42, 43));
70 all_eq!(simd_insert(x4, 1, 100), i32x4(40, 100, 42, 43));
71 all_eq!(simd_insert(x4, 2, 100), i32x4(40, 41, 100, 43));
72 all_eq!(simd_insert(x4, 3, 100), i32x4(40, 41, 42, 100));
73
74 all_eq!(simd_insert(x8, 0, 100), i32x8(100, 81, 82, 83, 84, 85, 86, 87));
75 all_eq!(simd_insert(x8, 1, 100), i32x8(80, 100, 82, 83, 84, 85, 86, 87));
76 all_eq!(simd_insert(x8, 2, 100), i32x8(80, 81, 100, 83, 84, 85, 86, 87));
77 all_eq!(simd_insert(x8, 3, 100), i32x8(80, 81, 82, 100, 84, 85, 86, 87));
78 all_eq!(simd_insert(x8, 4, 100), i32x8(80, 81, 82, 83, 100, 85, 86, 87));
79 all_eq!(simd_insert(x8, 5, 100), i32x8(80, 81, 82, 83, 84, 100, 86, 87));
80 all_eq!(simd_insert(x8, 6, 100), i32x8(80, 81, 82, 83, 84, 85, 100, 87));
81 all_eq!(simd_insert(x8, 7, 100), i32x8(80, 81, 82, 83, 84, 85, 86, 100));
82
83 all_eq!(simd_extract(x2, 0), 20);
84 all_eq!(simd_extract(x2, 1), 21);
85
86 all_eq!(simd_extract(x3, 0), 30);
87 all_eq!(simd_extract(x3, 1), 31);
88 all_eq!(simd_extract(x3, 2), 32);
89
90 all_eq!(simd_extract(x4, 0), 40);
91 all_eq!(simd_extract(x4, 1), 41);
92 all_eq!(simd_extract(x4, 2), 42);
93 all_eq!(simd_extract(x4, 3), 43);
94
95 all_eq!(simd_extract(x8, 0), 80);
96 all_eq!(simd_extract(x8, 1), 81);
97 all_eq!(simd_extract(x8, 2), 82);
98 all_eq!(simd_extract(x8, 3), 83);
99 all_eq!(simd_extract(x8, 4), 84);
100 all_eq!(simd_extract(x8, 5), 85);
101 all_eq!(simd_extract(x8, 6), 86);
102 all_eq!(simd_extract(x8, 7), 87);
103 }
104
105 let y2 = i32x2(120, 121);
106 let y3 = i32x3(130, 131, 132);
107 let y4 = i32x4(140, 141, 142, 143);
108 let y8 = i32x8(180, 181, 182, 183, 184, 185, 186, 187);
109 unsafe {
110 all_eq!(simd_shuffle2(x2, y2, [3, 0]), i32x2(121, 20));
111 all_eq!(simd_shuffle3(x2, y2, [3, 0, 1]), i32x3(121, 20, 21));
112 all_eq!(simd_shuffle4(x2, y2, [3, 0, 1, 2]), i32x4(121, 20, 21, 120));
113 all_eq!(simd_shuffle8(x2, y2, [3, 0, 1, 2, 1, 2, 3, 0]),
114 i32x8(121, 20, 21, 120, 21, 120, 121, 20));
115
116 all_eq!(simd_shuffle2(x3, y3, [4, 2]), i32x2(131, 32));
117 all_eq!(simd_shuffle3(x3, y3, [4, 2, 3]), i32x3(131, 32, 130));
118 all_eq!(simd_shuffle4(x3, y3, [4, 2, 3, 0]), i32x4(131, 32, 130, 30));
119 all_eq!(simd_shuffle8(x3, y3, [4, 2, 3, 0, 1, 5, 5, 1]),
120 i32x8(131, 32, 130, 30, 31, 132, 132, 31));
121
122 all_eq!(simd_shuffle2(x4, y4, [7, 2]), i32x2(143, 42));
123 all_eq!(simd_shuffle3(x4, y4, [7, 2, 5]), i32x3(143, 42, 141));
124 all_eq!(simd_shuffle4(x4, y4, [7, 2, 5, 0]), i32x4(143, 42, 141, 40));
125 all_eq!(simd_shuffle8(x4, y4, [7, 2, 5, 0, 3, 6, 4, 1]),
126 i32x8(143, 42, 141, 40, 43, 142, 140, 41));
127
128 all_eq!(simd_shuffle2(x8, y8, [11, 5]), i32x2(183, 85));
129 all_eq!(simd_shuffle3(x8, y8, [11, 5, 15]), i32x3(183, 85, 187));
130 all_eq!(simd_shuffle4(x8, y8, [11, 5, 15, 0]), i32x4(183, 85, 187, 80));
131 all_eq!(simd_shuffle8(x8, y8, [11, 5, 15, 0, 3, 8, 12, 1]),
132 i32x8(183, 85, 187, 80, 83, 180, 184, 81));
133 }
134
135}