]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/simd-intrinsic-generic-arithmetic.rs
35c368f4cbedb5bb399156b590bbc7ad1f43dfdd
[rust.git] / src / test / compile-fail / simd-intrinsic-generic-arithmetic.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 #![feature(repr_simd, platform_intrinsics)]
12 #![allow(non_camel_case_types)]
13 #[repr(simd)]
14 #[derive(Copy, Clone)]
15 pub struct i32x4(pub i32, pub i32, pub i32, pub i32);
16
17 #[repr(simd)]
18 #[derive(Copy, Clone)]
19 pub struct u32x4(pub u32, pub u32, pub u32, pub u32);
20
21 #[repr(simd)]
22 #[derive(Copy, Clone)]
23 pub struct f32x4(pub f32, pub f32, pub f32, pub f32);
24
25 extern "platform-intrinsic" {
26     fn simd_add<T>(x: T, y: T) -> T;
27     fn simd_sub<T>(x: T, y: T) -> T;
28     fn simd_mul<T>(x: T, y: T) -> T;
29     fn simd_div<T>(x: T, y: T) -> T;
30     fn simd_shl<T>(x: T, y: T) -> T;
31     fn simd_shr<T>(x: T, y: T) -> T;
32     fn simd_and<T>(x: T, y: T) -> T;
33     fn simd_or<T>(x: T, y: T) -> T;
34     fn simd_xor<T>(x: T, y: T) -> T;
35 }
36
37 fn main() {
38     let x = i32x4(0, 0, 0, 0);
39     let y = u32x4(0, 0, 0, 0);
40     let z = f32x4(0.0, 0.0, 0.0, 0.0);
41
42     unsafe {
43         simd_add(x, x);
44         simd_add(y, y);
45         simd_add(z, z);
46         simd_sub(x, x);
47         simd_sub(y, y);
48         simd_sub(z, z);
49         simd_mul(x, x);
50         simd_mul(y, y);
51         simd_mul(z, z);
52
53         simd_div(z, z);
54
55         simd_shl(x, x);
56         simd_shl(y, y);
57         simd_shr(x, x);
58         simd_shr(y, y);
59         simd_and(x, x);
60         simd_and(y, y);
61         simd_or(x, x);
62         simd_or(y, y);
63         simd_xor(x, x);
64         simd_xor(y, y);
65
66
67         simd_add(0, 0);
68         //~^ ERROR expected SIMD input type, found non-SIMD `i32`
69         simd_sub(0, 0);
70         //~^ ERROR expected SIMD input type, found non-SIMD `i32`
71         simd_mul(0, 0);
72         //~^ ERROR expected SIMD input type, found non-SIMD `i32`
73         simd_div(0, 0);
74         //~^ ERROR expected SIMD input type, found non-SIMD `i32`
75         simd_shl(0, 0);
76         //~^ ERROR expected SIMD input type, found non-SIMD `i32`
77         simd_shr(0, 0);
78         //~^ ERROR expected SIMD input type, found non-SIMD `i32`
79         simd_and(0, 0);
80         //~^ ERROR expected SIMD input type, found non-SIMD `i32`
81         simd_or(0, 0);
82         //~^ ERROR expected SIMD input type, found non-SIMD `i32`
83         simd_xor(0, 0);
84         //~^ ERROR expected SIMD input type, found non-SIMD `i32`
85
86
87         simd_div(x, x);
88 //~^ ERROR unsupported operation on `i32x4` with element `i32`
89         simd_div(y, y);
90 //~^ ERROR unsupported operation on `u32x4` with element `u32`
91         simd_shl(z, z);
92 //~^ ERROR unsupported operation on `f32x4` with element `f32`
93         simd_shr(z, z);
94 //~^ ERROR unsupported operation on `f32x4` with element `f32`
95         simd_and(z, z);
96 //~^ ERROR unsupported operation on `f32x4` with element `f32`
97         simd_or(z, z);
98 //~^ ERROR unsupported operation on `f32x4` with element `f32`
99         simd_xor(z, z);
100 //~^ ERROR unsupported operation on `f32x4` with element `f32`
101     }
102 }