|
| 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 | +// ignore-emscripten |
| 12 | + |
| 13 | +// Test that the simd_select intrinsics produces correct results. |
| 14 | + |
| 15 | +#![feature(repr_simd, platform_intrinsics)] |
| 16 | +#[allow(non_camel_case_types)] |
| 17 | + |
| 18 | +#[repr(simd)] |
| 19 | +#[derive(Copy, Clone, PartialEq, Debug)] |
| 20 | +struct i32x4(pub i32, pub i32, pub i32, pub i32); |
| 21 | + |
| 22 | +#[repr(simd)] |
| 23 | +#[derive(Copy, Clone, PartialEq, Debug)] |
| 24 | +struct u32x4(pub u32, pub u32, pub u32, pub u32); |
| 25 | + |
| 26 | +#[repr(simd)] |
| 27 | +#[derive(Copy, Clone, PartialEq, Debug)] |
| 28 | +struct f32x4(pub f32, pub f32, pub f32, pub f32); |
| 29 | + |
| 30 | +#[repr(simd)] |
| 31 | +#[derive(Copy, Clone, PartialEq, Debug)] |
| 32 | +struct b8x4(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 | +} |
| 37 | + |
| 38 | +fn main() { |
| 39 | + let m0 = b8x4(!0, !0, !0, !0); |
| 40 | + let m1 = b8x4(0, 0, 0, 0); |
| 41 | + let m2 = b8x4(!0, !0, 0, 0); |
| 42 | + let m3 = b8x4(0, 0, !0, !0); |
| 43 | + let m4 = b8x4(!0, 0, !0, 0); |
| 44 | + |
| 45 | + unsafe { |
| 46 | + let a = i32x4(1, -2, 3, 4); |
| 47 | + let b = i32x4(5, 6, -7, 8); |
| 48 | + |
| 49 | + let r: i32x4 = simd_select(m0, a, b); |
| 50 | + let e = a; |
| 51 | + assert_eq!(r, e); |
| 52 | + |
| 53 | + let r: i32x4 = simd_select(m1, a, b); |
| 54 | + let e = b; |
| 55 | + assert_eq!(r, e); |
| 56 | + |
| 57 | + let r: i32x4 = simd_select(m2, a, b); |
| 58 | + let e = i32x4(1, -2, -7, 8); |
| 59 | + assert_eq!(r, e); |
| 60 | + |
| 61 | + let r: i32x4 = simd_select(m3, a, b); |
| 62 | + let e = i32x4(5, 6, 3, 4); |
| 63 | + assert_eq!(r, e); |
| 64 | + |
| 65 | + let r: i32x4 = simd_select(m4, a, b); |
| 66 | + let e = i32x4(1, 6, 3, 8); |
| 67 | + assert_eq!(r, e); |
| 68 | + } |
| 69 | + |
| 70 | + unsafe { |
| 71 | + let a = u32x4(1, 2, 3, 4); |
| 72 | + let b = u32x4(5, 6, 7, 8); |
| 73 | + |
| 74 | + let r: u32x4 = simd_select(m0, a, b); |
| 75 | + let e = a; |
| 76 | + assert_eq!(r, e); |
| 77 | + |
| 78 | + let r: u32x4 = simd_select(m1, a, b); |
| 79 | + let e = b; |
| 80 | + assert_eq!(r, e); |
| 81 | + |
| 82 | + let r: u32x4 = simd_select(m2, a, b); |
| 83 | + let e = u32x4(1, 2, 7, 8); |
| 84 | + assert_eq!(r, e); |
| 85 | + |
| 86 | + let r: u32x4 = simd_select(m3, a, b); |
| 87 | + let e = u32x4(5, 6, 3, 4); |
| 88 | + assert_eq!(r, e); |
| 89 | + |
| 90 | + let r: u32x4 = simd_select(m4, a, b); |
| 91 | + let e = u32x4(1, 6, 3, 8); |
| 92 | + assert_eq!(r, e); |
| 93 | + } |
| 94 | + |
| 95 | + unsafe { |
| 96 | + let a = f32x4(1., 2., 3., 4.); |
| 97 | + let b = f32x4(5., 6., 7., 8.); |
| 98 | + |
| 99 | + let r: f32x4 = simd_select(m0, a, b); |
| 100 | + let e = a; |
| 101 | + assert_eq!(r, e); |
| 102 | + |
| 103 | + let r: f32x4 = simd_select(m1, a, b); |
| 104 | + let e = b; |
| 105 | + assert_eq!(r, e); |
| 106 | + |
| 107 | + let r: f32x4 = simd_select(m2, a, b); |
| 108 | + let e = f32x4(1., 2., 7., 8.); |
| 109 | + assert_eq!(r, e); |
| 110 | + |
| 111 | + let r: f32x4 = simd_select(m3, a, b); |
| 112 | + let e = f32x4(5., 6., 3., 4.); |
| 113 | + assert_eq!(r, e); |
| 114 | + |
| 115 | + let r: f32x4 = simd_select(m4, a, b); |
| 116 | + let e = f32x4(1., 6., 3., 8.); |
| 117 | + assert_eq!(r, e); |
| 118 | + } |
| 119 | + |
| 120 | + unsafe { |
| 121 | + let t = !0 as i8; |
| 122 | + let f = 0 as i8; |
| 123 | + let a = b8x4(t, f, t, f); |
| 124 | + let b = b8x4(f, f, f, t); |
| 125 | + |
| 126 | + let r: b8x4 = simd_select(m0, a, b); |
| 127 | + let e = a; |
| 128 | + assert_eq!(r, e); |
| 129 | + |
| 130 | + let r: b8x4 = simd_select(m1, a, b); |
| 131 | + let e = b; |
| 132 | + assert_eq!(r, e); |
| 133 | + |
| 134 | + let r: b8x4 = simd_select(m2, a, b); |
| 135 | + let e = b8x4(t, f, f, t); |
| 136 | + assert_eq!(r, e); |
| 137 | + |
| 138 | + let r: b8x4 = simd_select(m3, a, b); |
| 139 | + let e = b8x4(f, f, t, f); |
| 140 | + assert_eq!(r, e); |
| 141 | + |
| 142 | + let r: b8x4 = simd_select(m4, a, b); |
| 143 | + let e = b8x4(t, f, t, t); |
| 144 | + assert_eq!(r, e); |
| 145 | + } |
| 146 | +} |
0 commit comments