]>
git.proxmox.com Git - rustc.git/blob - src/test/run-pass/simd-intrinsic-generic-comparison.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.
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.
11 #![feature(repr_simd, platform_intrinsics, concat_idents)]
12 #![allow(non_camel_case_types)]
17 #[derive(Copy, Clone)]
18 struct i32x4(i32, i32, i32, i32);
20 #[derive(Copy, Clone)]
21 struct u32x4(pub u32, pub u32, pub u32, pub u32);
23 #[derive(Copy, Clone)]
24 struct f32x4(pub f32, pub f32, pub f32, pub f32);
26 extern "platform-intrinsic" {
27 fn simd_eq
<T
, U
>(x
: T
, y
: T
) -> U
;
28 fn simd_ne
<T
, U
>(x
: T
, y
: T
) -> U
;
29 fn simd_lt
<T
, U
>(x
: T
, y
: T
) -> U
;
30 fn simd_le
<T
, U
>(x
: T
, y
: T
) -> U
;
31 fn simd_gt
<T
, U
>(x
: T
, y
: T
) -> U
;
32 fn simd_ge
<T
, U
>(x
: T
, y
: T
) -> U
;
36 ($method
: ident($lhs
: expr
, $rhs
: expr
)) => {{
39 let e
: u32x4
= concat_idents
!(simd_
, $method
)($lhs
, $rhs
);
40 // assume the scalar version is correct/the behaviour we want.
41 assert
!((e
.0 != 0) == lhs
.0 .$
method(&rhs
.0));
42 assert
!((e
.1 != 0) == lhs
.1 .$
method(&rhs
.1));
43 assert
!((e
.2 != 0) == lhs
.2 .$
method(&rhs
.2));
44 assert
!((e
.3 != 0) == lhs
.3 .$
method(&rhs
.3));
48 ($
($lhs
: ident
, $rhs
: ident
;)*) => {{
54 // test both directions
71 // 13 vs. -100 tests that we get signed vs. unsigned comparisons
72 // correct (i32: 13 > -100, u32: 13 < -100). let i1 = i32x4(10, -11, 12, 13);
73 let i1
= i32x4(10, -11, 12, 13);
74 let i2
= i32x4(5, -5, 20, -100);
75 let i3
= i32x4(10, -11, 20, -100);
77 let u1
= u32x4(10, !11+1, 12, 13);
78 let u2
= u32x4(5, !5+1, 20, !100+1);
79 let u3
= u32x4(10, !11+1, 20, !100+1);
81 let f1
= f32x4(10.0, -11.0, 12.0, 13.0);
82 let f2
= f32x4(5.0, -5.0, 20.0, -100.0);
83 let f3
= f32x4(10.0, -11.0, 20.0, -100.0);
101 // NAN comparisons are special:
104 let f4
= f32x4(NAN
, f1
.1
, NAN
, f2
.3
);