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