2018-08-30 07:18:55 -05:00
|
|
|
// run-pass
|
2018-08-31 08:02:01 -05:00
|
|
|
#![allow(non_camel_case_types)]
|
|
|
|
|
2018-03-16 03:39:41 -05:00
|
|
|
// ignore-emscripten
|
2018-03-15 04:10:16 -05:00
|
|
|
|
2018-03-13 10:46:55 -05:00
|
|
|
// Test that the simd_reduce_{op} intrinsics produce the correct results.
|
|
|
|
|
|
|
|
#![feature(repr_simd, platform_intrinsics)]
|
|
|
|
#[allow(non_camel_case_types)]
|
|
|
|
|
|
|
|
#[repr(simd)]
|
|
|
|
#[derive(Copy, Clone)]
|
|
|
|
struct i32x4(pub i32, pub i32, pub i32, pub i32);
|
|
|
|
|
|
|
|
#[repr(simd)]
|
|
|
|
#[derive(Copy, Clone)]
|
|
|
|
struct u32x4(pub u32, pub u32, pub u32, pub u32);
|
|
|
|
|
|
|
|
#[repr(simd)]
|
|
|
|
#[derive(Copy, Clone)]
|
|
|
|
struct f32x4(pub f32, pub f32, pub f32, pub f32);
|
|
|
|
|
|
|
|
#[repr(simd)]
|
|
|
|
#[derive(Copy, Clone)]
|
|
|
|
struct b8x4(pub i8, pub i8, pub i8, pub i8);
|
|
|
|
|
|
|
|
extern "platform-intrinsic" {
|
2018-03-14 11:22:40 -05:00
|
|
|
fn simd_reduce_add_unordered<T, U>(x: T) -> U;
|
|
|
|
fn simd_reduce_mul_unordered<T, U>(x: T) -> U;
|
|
|
|
fn simd_reduce_add_ordered<T, U>(x: T, acc: U) -> U;
|
|
|
|
fn simd_reduce_mul_ordered<T, U>(x: T, acc: U) -> U;
|
2018-03-13 10:46:55 -05:00
|
|
|
fn simd_reduce_min<T, U>(x: T) -> U;
|
|
|
|
fn simd_reduce_max<T, U>(x: T) -> U;
|
2018-03-14 11:22:40 -05:00
|
|
|
fn simd_reduce_min_nanless<T, U>(x: T) -> U;
|
|
|
|
fn simd_reduce_max_nanless<T, U>(x: T) -> U;
|
2018-03-13 10:46:55 -05:00
|
|
|
fn simd_reduce_and<T, U>(x: T) -> U;
|
|
|
|
fn simd_reduce_or<T, U>(x: T) -> U;
|
|
|
|
fn simd_reduce_xor<T, U>(x: T) -> U;
|
|
|
|
fn simd_reduce_all<T>(x: T) -> bool;
|
|
|
|
fn simd_reduce_any<T>(x: T) -> bool;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
unsafe {
|
|
|
|
let x = i32x4(1, -2, 3, 4);
|
2018-03-14 11:22:40 -05:00
|
|
|
let r: i32 = simd_reduce_add_unordered(x);
|
|
|
|
assert_eq!(r, 6_i32);
|
|
|
|
let r: i32 = simd_reduce_mul_unordered(x);
|
|
|
|
assert_eq!(r, -24_i32);
|
|
|
|
let r: i32 = simd_reduce_add_ordered(x, -1);
|
|
|
|
assert_eq!(r, 5_i32);
|
|
|
|
let r: i32 = simd_reduce_mul_ordered(x, -1);
|
|
|
|
assert_eq!(r, 24_i32);
|
|
|
|
|
2018-03-13 10:46:55 -05:00
|
|
|
let r: i32 = simd_reduce_min(x);
|
2018-03-14 11:22:40 -05:00
|
|
|
assert_eq!(r, -2_i32);
|
2018-03-13 10:46:55 -05:00
|
|
|
let r: i32 = simd_reduce_max(x);
|
2018-03-14 11:22:40 -05:00
|
|
|
assert_eq!(r, 4_i32);
|
2018-03-13 10:46:55 -05:00
|
|
|
|
|
|
|
let x = i32x4(-1, -1, -1, -1);
|
|
|
|
let r: i32 = simd_reduce_and(x);
|
2018-03-14 11:22:40 -05:00
|
|
|
assert_eq!(r, -1_i32);
|
2018-03-13 10:46:55 -05:00
|
|
|
let r: i32 = simd_reduce_or(x);
|
2018-03-14 11:22:40 -05:00
|
|
|
assert_eq!(r, -1_i32);
|
2018-03-13 10:46:55 -05:00
|
|
|
let r: i32 = simd_reduce_xor(x);
|
2018-03-14 11:22:40 -05:00
|
|
|
assert_eq!(r, 0_i32);
|
2018-03-13 10:46:55 -05:00
|
|
|
|
|
|
|
let x = i32x4(-1, -1, 0, -1);
|
|
|
|
let r: i32 = simd_reduce_and(x);
|
2018-03-14 11:22:40 -05:00
|
|
|
assert_eq!(r, 0_i32);
|
2018-03-13 10:46:55 -05:00
|
|
|
let r: i32 = simd_reduce_or(x);
|
2018-03-14 11:22:40 -05:00
|
|
|
assert_eq!(r, -1_i32);
|
2018-03-13 10:46:55 -05:00
|
|
|
let r: i32 = simd_reduce_xor(x);
|
2018-03-14 11:22:40 -05:00
|
|
|
assert_eq!(r, -1_i32);
|
2018-03-13 10:46:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
unsafe {
|
|
|
|
let x = u32x4(1, 2, 3, 4);
|
2018-03-14 11:22:40 -05:00
|
|
|
let r: u32 = simd_reduce_add_unordered(x);
|
|
|
|
assert_eq!(r, 10_u32);
|
|
|
|
let r: u32 = simd_reduce_mul_unordered(x);
|
|
|
|
assert_eq!(r, 24_u32);
|
|
|
|
let r: u32 = simd_reduce_add_ordered(x, 1);
|
|
|
|
assert_eq!(r, 11_u32);
|
|
|
|
let r: u32 = simd_reduce_mul_ordered(x, 2);
|
|
|
|
assert_eq!(r, 48_u32);
|
|
|
|
|
2018-03-13 10:46:55 -05:00
|
|
|
let r: u32 = simd_reduce_min(x);
|
2018-03-14 11:22:40 -05:00
|
|
|
assert_eq!(r, 1_u32);
|
2018-03-13 10:46:55 -05:00
|
|
|
let r: u32 = simd_reduce_max(x);
|
2018-03-14 11:22:40 -05:00
|
|
|
assert_eq!(r, 4_u32);
|
2018-03-13 10:46:55 -05:00
|
|
|
|
2020-06-02 02:59:11 -05:00
|
|
|
let t = u32::MAX;
|
2018-03-13 10:46:55 -05:00
|
|
|
let x = u32x4(t, t, t, t);
|
|
|
|
let r: u32 = simd_reduce_and(x);
|
2018-03-14 11:22:40 -05:00
|
|
|
assert_eq!(r, t);
|
2018-03-13 10:46:55 -05:00
|
|
|
let r: u32 = simd_reduce_or(x);
|
2018-03-14 11:22:40 -05:00
|
|
|
assert_eq!(r, t);
|
2018-03-13 10:46:55 -05:00
|
|
|
let r: u32 = simd_reduce_xor(x);
|
2018-03-14 11:22:40 -05:00
|
|
|
assert_eq!(r, 0_u32);
|
2018-03-13 10:46:55 -05:00
|
|
|
|
|
|
|
let x = u32x4(t, t, 0, t);
|
|
|
|
let r: u32 = simd_reduce_and(x);
|
2018-03-14 11:22:40 -05:00
|
|
|
assert_eq!(r, 0_u32);
|
2018-03-13 10:46:55 -05:00
|
|
|
let r: u32 = simd_reduce_or(x);
|
2018-03-14 11:22:40 -05:00
|
|
|
assert_eq!(r, t);
|
2018-03-13 10:46:55 -05:00
|
|
|
let r: u32 = simd_reduce_xor(x);
|
2018-03-14 11:22:40 -05:00
|
|
|
assert_eq!(r, t);
|
2018-03-13 10:46:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
unsafe {
|
|
|
|
let x = f32x4(1., -2., 3., 4.);
|
2018-03-14 11:22:40 -05:00
|
|
|
let r: f32 = simd_reduce_add_unordered(x);
|
|
|
|
assert_eq!(r, 6_f32);
|
|
|
|
let r: f32 = simd_reduce_mul_unordered(x);
|
|
|
|
assert_eq!(r, -24_f32);
|
|
|
|
let r: f32 = simd_reduce_add_ordered(x, 0.);
|
|
|
|
assert_eq!(r, 6_f32);
|
|
|
|
let r: f32 = simd_reduce_mul_ordered(x, 1.);
|
|
|
|
assert_eq!(r, -24_f32);
|
2019-07-20 06:05:37 -05:00
|
|
|
let r: f32 = simd_reduce_add_ordered(x, 1.);
|
|
|
|
assert_eq!(r, 7_f32);
|
|
|
|
let r: f32 = simd_reduce_mul_ordered(x, 2.);
|
|
|
|
assert_eq!(r, -48_f32);
|
2018-03-14 11:22:40 -05:00
|
|
|
|
2018-03-13 10:46:55 -05:00
|
|
|
let r: f32 = simd_reduce_min(x);
|
2018-03-14 11:22:40 -05:00
|
|
|
assert_eq!(r, -2_f32);
|
2018-03-13 10:46:55 -05:00
|
|
|
let r: f32 = simd_reduce_max(x);
|
2018-03-14 11:22:40 -05:00
|
|
|
assert_eq!(r, 4_f32);
|
|
|
|
let r: f32 = simd_reduce_min_nanless(x);
|
|
|
|
assert_eq!(r, -2_f32);
|
|
|
|
let r: f32 = simd_reduce_max_nanless(x);
|
|
|
|
assert_eq!(r, 4_f32);
|
2018-03-13 10:46:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
unsafe {
|
|
|
|
let x = b8x4(!0, !0, !0, !0);
|
|
|
|
let r: bool = simd_reduce_all(x);
|
2018-03-14 11:22:40 -05:00
|
|
|
assert_eq!(r, true);
|
2018-03-13 10:46:55 -05:00
|
|
|
let r: bool = simd_reduce_any(x);
|
2018-03-14 11:22:40 -05:00
|
|
|
assert_eq!(r, true);
|
2018-03-13 10:46:55 -05:00
|
|
|
|
|
|
|
let x = b8x4(!0, !0, 0, !0);
|
|
|
|
let r: bool = simd_reduce_all(x);
|
2018-03-14 11:22:40 -05:00
|
|
|
assert_eq!(r, false);
|
2018-03-13 10:46:55 -05:00
|
|
|
let r: bool = simd_reduce_any(x);
|
2018-03-14 11:22:40 -05:00
|
|
|
assert_eq!(r, true);
|
2018-03-13 10:46:55 -05:00
|
|
|
|
|
|
|
let x = b8x4(0, 0, 0, 0);
|
|
|
|
let r: bool = simd_reduce_all(x);
|
2018-03-14 11:22:40 -05:00
|
|
|
assert_eq!(r, false);
|
2018-03-13 10:46:55 -05:00
|
|
|
let r: bool = simd_reduce_any(x);
|
2018-03-14 11:22:40 -05:00
|
|
|
assert_eq!(r, false);
|
2018-03-13 10:46:55 -05:00
|
|
|
}
|
|
|
|
}
|