]> git.lizzy.rs Git - rust.git/blob - src/test/ui/simd-intrinsic/simd-intrinsic-generic-select.rs
2a2d35e7bd9228a11d251881520e44d530c4a566
[rust.git] / src / test / ui / simd-intrinsic / simd-intrinsic-generic-select.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 // Test that the simd_select intrinsic produces ok-ish error
12 // messages when misused.
13
14 #![feature(repr_simd, platform_intrinsics)]
15 #![allow(non_camel_case_types)]
16
17 #[repr(simd)]
18 #[derive(Copy, Clone)]
19 pub struct f32x4(pub f32, pub f32, pub f32, pub f32);
20
21 #[repr(simd)]
22 #[derive(Copy, Clone)]
23 pub struct u32x4(pub u32, pub u32, pub u32, pub u32);
24
25 #[repr(simd)]
26 #[derive(Copy, Clone, PartialEq)]
27 struct b8x4(pub i8, pub i8, pub i8, pub i8);
28
29 #[repr(simd)]
30 #[derive(Copy, Clone, PartialEq)]
31 struct b8x8(pub i8, pub i8, pub i8, pub i8,
32             pub i8, pub i8, pub i8, pub i8);
33
34 extern "platform-intrinsic" {
35     fn simd_select<T, U>(x: T, a: U, b: U) -> U;
36     fn simd_select_bitmask<T, U>(x: T, a: U, b: U) -> U;
37 }
38
39 fn main() {
40     let m4 = b8x4(0, 0, 0, 0);
41     let m8 = b8x8(0, 0, 0, 0, 0, 0, 0, 0);
42     let x = u32x4(0, 0, 0, 0);
43     let z = f32x4(0.0, 0.0, 0.0, 0.0);
44
45     unsafe {
46         simd_select(m4, x, x);
47
48         simd_select(m8, x, x);
49         //~^ ERROR mismatched lengths: mask length `8` != other vector length `4`
50
51         simd_select(x, x, x);
52         //~^ ERROR mask element type is `u32`, expected `i_`
53
54         simd_select(z, z, z);
55         //~^ ERROR mask element type is `f32`, expected `i_`
56
57         simd_select_bitmask(0u8, x, x);
58         //~^ ERROR mask length `8` != other vector length `4`
59
60         simd_select_bitmask(0.0f32, x, x);
61         //~^ ERROR `f32` is not an integral type
62
63         simd_select_bitmask("x", x, x);
64         //~^ ERROR `&str` is not an integral type
65     }
66 }