]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/simd-intrinsic-generic-arithmetic.rs
Add #[rustc_no_mir] to make tests pass with -Z orbit.
[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, rustc_attrs)]
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 #[rustc_no_mir] // FIXME #27840 MIR doesn't provide precise spans for calls.
38 fn main() {
39     let x = i32x4(0, 0, 0, 0);
40     let y = u32x4(0, 0, 0, 0);
41     let z = f32x4(0.0, 0.0, 0.0, 0.0);
42
43     unsafe {
44         simd_add(x, x);
45         simd_add(y, y);
46         simd_add(z, z);
47         simd_sub(x, x);
48         simd_sub(y, y);
49         simd_sub(z, z);
50         simd_mul(x, x);
51         simd_mul(y, y);
52         simd_mul(z, z);
53
54         simd_div(z, z);
55
56         simd_shl(x, x);
57         simd_shl(y, y);
58         simd_shr(x, x);
59         simd_shr(y, y);
60         simd_and(x, x);
61         simd_and(y, y);
62         simd_or(x, x);
63         simd_or(y, y);
64         simd_xor(x, x);
65         simd_xor(y, y);
66
67
68         simd_add(0, 0);
69         //~^ ERROR expected SIMD input type, found non-SIMD `i32`
70         simd_sub(0, 0);
71         //~^ ERROR expected SIMD input type, found non-SIMD `i32`
72         simd_mul(0, 0);
73         //~^ ERROR expected SIMD input type, found non-SIMD `i32`
74         simd_div(0, 0);
75         //~^ ERROR expected SIMD input type, found non-SIMD `i32`
76         simd_shl(0, 0);
77         //~^ ERROR expected SIMD input type, found non-SIMD `i32`
78         simd_shr(0, 0);
79         //~^ ERROR expected SIMD input type, found non-SIMD `i32`
80         simd_and(0, 0);
81         //~^ ERROR expected SIMD input type, found non-SIMD `i32`
82         simd_or(0, 0);
83         //~^ ERROR expected SIMD input type, found non-SIMD `i32`
84         simd_xor(0, 0);
85         //~^ ERROR expected SIMD input type, found non-SIMD `i32`
86
87
88         simd_div(x, x);
89 //~^ ERROR unsupported operation on `i32x4` with element `i32`
90         simd_div(y, y);
91 //~^ ERROR unsupported operation on `u32x4` with element `u32`
92         simd_shl(z, z);
93 //~^ ERROR unsupported operation on `f32x4` with element `f32`
94         simd_shr(z, z);
95 //~^ ERROR unsupported operation on `f32x4` with element `f32`
96         simd_and(z, z);
97 //~^ ERROR unsupported operation on `f32x4` with element `f32`
98         simd_or(z, z);
99 //~^ ERROR unsupported operation on `f32x4` with element `f32`
100         simd_xor(z, z);
101 //~^ ERROR unsupported operation on `f32x4` with element `f32`
102     }
103 }