Skip to content

Commit 84de8ca

Browse files
committed
Add tests for various intrinsic behaviours.
1 parent 926b835 commit 84de8ca

11 files changed

+911
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
13+
#[repr(simd)]
14+
struct i16x8(i16, i16, i16, i16, i16, i16, i16, i16);
15+
#[repr(simd)]
16+
struct u16x8(u16, u16, u16, u16, u16, u16, u16, u16);
17+
18+
#[repr(simd)]
19+
struct i8x16(i8, i8, i8, i8, i8, i8, i8, i8,
20+
i8, i8, i8, i8, i8, i8, i8, i8);
21+
#[repr(simd)]
22+
struct i32x4(i32, i32, i32, i32);
23+
#[repr(simd)]
24+
struct f32x4(f32, f32, f32, f32);
25+
#[repr(simd)]
26+
struct i64x2(i64, i64);
27+
28+
// signed vs. unsigned doesn't matter
29+
mod i {
30+
use i16x8;
31+
extern "platform-intrinsic" {
32+
fn x86_mm_adds_epi16(x: i16x8, y: i16x8) -> i16x8;
33+
}
34+
}
35+
mod u {
36+
use u16x8;
37+
extern "platform-intrinsic" {
38+
fn x86_mm_adds_epi16(x: u16x8, y: u16x8) -> u16x8;
39+
}
40+
}
41+
// but lengths do
42+
extern "platform-intrinsic" {
43+
fn x86_mm_adds_epi16(x: i8x16, y: i32x4) -> i64x2;
44+
//~^ ERROR intrinsic argument 1 has wrong type
45+
//~^^ ERROR intrinsic argument 2 has wrong type
46+
//~^^^ ERROR intrinsic return value has wrong type
47+
}
48+
// and so does int vs. float
49+
extern "platform-intrinsic" {
50+
fn x86_mm_max_ps(x: i32x4, y: i32x4) -> i32x4;
51+
//~^ ERROR intrinsic argument 1 has wrong type
52+
//~^^ ERROR intrinsic argument 2 has wrong type
53+
//~^^^ ERROR intrinsic return value has wrong type
54+
}
55+
56+
57+
fn main() {}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
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 `simd_add` intrinsic monomorphized with non-SIMD type
69+
simd_sub(0, 0);
70+
//~^ ERROR `simd_sub` intrinsic monomorphized with non-SIMD type
71+
simd_mul(0, 0);
72+
//~^ ERROR `simd_mul` intrinsic monomorphized with non-SIMD type
73+
simd_div(0, 0);
74+
//~^ ERROR `simd_div` intrinsic monomorphized with non-SIMD type
75+
simd_shl(0, 0);
76+
//~^ ERROR `simd_shl` intrinsic monomorphized with non-SIMD type
77+
simd_shr(0, 0);
78+
//~^ ERROR `simd_shr` intrinsic monomorphized with non-SIMD type
79+
simd_and(0, 0);
80+
//~^ ERROR `simd_and` intrinsic monomorphized with non-SIMD type
81+
simd_or(0, 0);
82+
//~^ ERROR `simd_or` intrinsic monomorphized with non-SIMD type
83+
simd_xor(0, 0);
84+
//~^ ERROR `simd_xor` intrinsic monomorphized with non-SIMD type
85+
86+
87+
simd_div(x, x);
88+
//~^ ERROR `simd_div` intrinsic monomorphized with SIMD vector `i32x4` with unsupported element type
89+
simd_div(y, y);
90+
//~^ ERROR `simd_div` intrinsic monomorphized with SIMD vector `u32x4` with unsupported element type
91+
simd_shl(z, z);
92+
//~^ ERROR `simd_shl` intrinsic monomorphized with SIMD vector `f32x4` with unsupported element type
93+
simd_shr(z, z);
94+
//~^ ERROR `simd_shr` intrinsic monomorphized with SIMD vector `f32x4` with unsupported element type
95+
simd_and(z, z);
96+
//~^ ERROR `simd_and` intrinsic monomorphized with SIMD vector `f32x4` with unsupported element type
97+
simd_or(z, z);
98+
//~^ ERROR `simd_or` intrinsic monomorphized with SIMD vector `f32x4` with unsupported element type
99+
simd_xor(z, z);
100+
//~^ ERROR `simd_xor` intrinsic monomorphized with SIMD vector `f32x4` with unsupported element type
101+
}
102+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
13+
#[repr(simd)]
14+
#[derive(Copy, Clone)]
15+
#[allow(non_camel_case_types)]
16+
struct i32x4(i32, i32, i32, i32);
17+
#[repr(simd)]
18+
#[derive(Copy, Clone)]
19+
#[allow(non_camel_case_types)]
20+
struct i32x8(i32, i32, i32, i32,
21+
i32, i32, i32, i32);
22+
23+
#[repr(simd)]
24+
#[derive(Copy, Clone)]
25+
#[allow(non_camel_case_types)]
26+
struct f32x4(f32, f32, f32, f32);
27+
#[repr(simd)]
28+
#[derive(Copy, Clone)]
29+
#[allow(non_camel_case_types)]
30+
struct f32x8(f32, f32, f32, f32,
31+
f32, f32, f32, f32);
32+
33+
34+
extern "platform-intrinsic" {
35+
fn simd_cast<T, U>(x: T) -> U;
36+
}
37+
38+
fn main() {
39+
let x = i32x4(0, 0, 0, 0);
40+
41+
unsafe {
42+
simd_cast::<i32, i32>(0);
43+
//~^ ERROR SIMD cast intrinsic monomorphized with non-SIMD input type `i32`
44+
simd_cast::<i32, i32x4>(0);
45+
//~^ ERROR SIMD cast intrinsic monomorphized with non-SIMD input type `i32`
46+
simd_cast::<i32x4, i32>(x);
47+
//~^ ERROR SIMD cast intrinsic monomorphized with non-SIMD return type `i32`
48+
simd_cast::<_, i32x8>(x);
49+
//~^ ERROR monomorphized with input type `i32x4` and return type `i32x8` with different lengths
50+
}
51+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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+
13+
#[repr(simd)]
14+
#[derive(Copy, Clone)]
15+
#[allow(non_camel_case_types)]
16+
struct i32x4(i32, i32, i32, i32);
17+
#[repr(simd)]
18+
#[derive(Copy, Clone)]
19+
#[allow(non_camel_case_types)]
20+
struct i16x8(i16, i16, i16, i16,
21+
i16, i16, i16, i16);
22+
23+
extern "platform-intrinsic" {
24+
fn simd_eq<T, U>(x: T, y: T) -> U;
25+
fn simd_ne<T, U>(x: T, y: T) -> U;
26+
fn simd_lt<T, U>(x: T, y: T) -> U;
27+
fn simd_le<T, U>(x: T, y: T) -> U;
28+
fn simd_gt<T, U>(x: T, y: T) -> U;
29+
fn simd_ge<T, U>(x: T, y: T) -> U;
30+
}
31+
32+
fn main() {
33+
let x = i32x4(0, 0, 0, 0);
34+
35+
unsafe {
36+
simd_eq::<i32, i32>(0, 0);
37+
//~^ ERROR SIMD comparison intrinsic monomorphized for non-SIMD argument type
38+
simd_ne::<i32, i32>(0, 0);
39+
//~^ ERROR SIMD comparison intrinsic monomorphized for non-SIMD argument type
40+
simd_lt::<i32, i32>(0, 0);
41+
//~^ ERROR SIMD comparison intrinsic monomorphized for non-SIMD argument type
42+
simd_le::<i32, i32>(0, 0);
43+
//~^ ERROR SIMD comparison intrinsic monomorphized for non-SIMD argument type
44+
simd_gt::<i32, i32>(0, 0);
45+
//~^ ERROR SIMD comparison intrinsic monomorphized for non-SIMD argument type
46+
simd_ge::<i32, i32>(0, 0);
47+
//~^ ERROR SIMD comparison intrinsic monomorphized for non-SIMD argument type
48+
49+
simd_eq::<_, i32>(x, x);
50+
//~^ ERROR SIMD comparison intrinsic monomorphized for non-SIMD return type
51+
simd_ne::<_, i32>(x, x);
52+
//~^ ERROR SIMD comparison intrinsic monomorphized for non-SIMD return type
53+
simd_lt::<_, i32>(x, x);
54+
//~^ ERROR SIMD comparison intrinsic monomorphized for non-SIMD return type
55+
simd_le::<_, i32>(x, x);
56+
//~^ ERROR SIMD comparison intrinsic monomorphized for non-SIMD return type
57+
simd_gt::<_, i32>(x, x);
58+
//~^ ERROR SIMD comparison intrinsic monomorphized for non-SIMD return type
59+
simd_ge::<_, i32>(x, x);
60+
//~^ ERROR SIMD comparison intrinsic monomorphized for non-SIMD return type
61+
62+
simd_eq::<_, i16x8>(x, x);
63+
//~^ ERROR monomorphized with input type `i32x4` and return type `i16x8` with different lengths
64+
simd_ne::<_, i16x8>(x, x);
65+
//~^ ERROR monomorphized with input type `i32x4` and return type `i16x8` with different lengths
66+
simd_lt::<_, i16x8>(x, x);
67+
//~^ ERROR monomorphized with input type `i32x4` and return type `i16x8` with different lengths
68+
simd_le::<_, i16x8>(x, x);
69+
//~^ ERROR monomorphized with input type `i32x4` and return type `i16x8` with different lengths
70+
simd_gt::<_, i16x8>(x, x);
71+
//~^ ERROR monomorphized with input type `i32x4` and return type `i16x8` with different lengths
72+
simd_ge::<_, i16x8>(x, x);
73+
//~^ ERROR monomorphized with input type `i32x4` and return type `i16x8` with different lengths
74+
}
75+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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+
13+
#[repr(simd)]
14+
#[derive(Copy, Clone)]
15+
#[allow(non_camel_case_types)]
16+
struct i32x2(i32, i32);
17+
#[repr(simd)]
18+
#[derive(Copy, Clone)]
19+
#[allow(non_camel_case_types)]
20+
struct i32x3(i32, i32, i32);
21+
#[repr(simd)]
22+
#[derive(Copy, Clone)]
23+
#[allow(non_camel_case_types)]
24+
struct i32x4(i32, i32, i32, i32);
25+
#[repr(simd)]
26+
#[derive(Copy, Clone)]
27+
#[allow(non_camel_case_types)]
28+
struct i32x8(i32, i32, i32, i32,
29+
i32, i32, i32, i32);
30+
31+
#[repr(simd)]
32+
#[derive(Copy, Clone)]
33+
#[allow(non_camel_case_types)]
34+
struct f32x2(f32, f32);
35+
#[repr(simd)]
36+
#[derive(Copy, Clone)]
37+
#[allow(non_camel_case_types)]
38+
struct f32x3(f32, f32, f32);
39+
#[repr(simd)]
40+
#[derive(Copy, Clone)]
41+
#[allow(non_camel_case_types)]
42+
struct f32x4(f32, f32, f32, f32);
43+
#[repr(simd)]
44+
#[derive(Copy, Clone)]
45+
#[allow(non_camel_case_types)]
46+
struct f32x8(f32, f32, f32, f32,
47+
f32, f32, f32, f32);
48+
49+
extern "platform-intrinsic" {
50+
fn simd_insert<T, E>(x: T, idx: u32, y: E) -> T;
51+
fn simd_extract<T, E>(x: T, idx: u32) -> E;
52+
53+
fn simd_shuffle2<T, U>(x: T, y: T, idx: [u32; 2]) -> U;
54+
fn simd_shuffle3<T, U>(x: T, y: T, idx: [u32; 3]) -> U;
55+
fn simd_shuffle4<T, U>(x: T, y: T, idx: [u32; 4]) -> U;
56+
fn simd_shuffle8<T, U>(x: T, y: T, idx: [u32; 8]) -> U;
57+
}
58+
59+
fn main() {
60+
let x = i32x4(0, 0, 0, 0);
61+
62+
unsafe {
63+
simd_insert(0, 0, 0);
64+
//~^ ERROR SIMD insert intrinsic monomorphized for non-SIMD input type
65+
simd_insert(x, 0, 1.0);
66+
//~^ ERROR SIMD insert intrinsic monomorphized with inserted type not SIMD element type
67+
simd_extract::<_, f32>(x, 0);
68+
//~^ ERROR SIMD insert intrinsic monomorphized with returned type not SIMD element type
69+
70+
simd_shuffle2::<i32, i32>(0, 0, [0; 2]);
71+
//~^ ERROR SIMD shuffle intrinsic monomorphized with non-SIMD input type
72+
simd_shuffle3::<i32, i32>(0, 0, [0; 3]);
73+
//~^ ERROR SIMD shuffle intrinsic monomorphized with non-SIMD input type
74+
simd_shuffle4::<i32, i32>(0, 0, [0; 4]);
75+
//~^ ERROR SIMD shuffle intrinsic monomorphized with non-SIMD input type
76+
simd_shuffle8::<i32, i32>(0, 0, [0; 8]);
77+
//~^ ERROR SIMD shuffle intrinsic monomorphized with non-SIMD input type
78+
79+
simd_shuffle2::<_, f32x2>(x, x, [0; 2]);
80+
//~^ ERROR SIMD shuffle intrinsic monomorphized with different input and return element
81+
simd_shuffle3::<_, f32x3>(x, x, [0; 3]);
82+
//~^ ERROR SIMD shuffle intrinsic monomorphized with different input and return element
83+
simd_shuffle4::<_, f32x4>(x, x, [0; 4]);
84+
//~^ ERROR SIMD shuffle intrinsic monomorphized with different input and return element
85+
simd_shuffle8::<_, f32x8>(x, x, [0; 8]);
86+
//~^ ERROR SIMD shuffle intrinsic monomorphized with different input and return element
87+
}
88+
}

0 commit comments

Comments
 (0)