|
| 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 | +// min-llvm-version 6.0 |
| 13 | +// error-pattern: panicked |
| 14 | + |
| 15 | +// Test that the simd_f{min,max} intrinsics produce the correct results. |
| 16 | + |
| 17 | +#![feature(repr_simd, platform_intrinsics)] |
| 18 | +#[allow(non_camel_case_types)] |
| 19 | + |
| 20 | +#[repr(simd)] |
| 21 | +#[derive(Copy, Clone, PartialEq, Debug)] |
| 22 | +struct f32x4(pub f32, pub f32, pub f32, pub f32); |
| 23 | + |
| 24 | +extern "platform-intrinsic" { |
| 25 | + fn simd_fmin<T>(x: T, y: T) -> T; |
| 26 | + fn simd_fmax<T>(x: T, y: T) -> T; |
| 27 | +} |
| 28 | + |
| 29 | +fn main() { |
| 30 | + let x = f32x4(1.0, 2.0, 3.0, 4.0); |
| 31 | + let y = f32x4(2.0, 1.0, 4.0, 3.0); |
| 32 | + let nan = ::std::f32::NAN; |
| 33 | + let n = f32x4(nan, nan, nan, nan); |
| 34 | + |
| 35 | + unsafe { |
| 36 | + let min0 = simd_fmin(x, y); |
| 37 | + let min1 = simd_fmin(y, x); |
| 38 | + assert_eq!(min0, min1); |
| 39 | + let e = f32x4(1.0, 1.0, 3.0, 3.0); |
| 40 | + assert_eq!(min0, e); |
| 41 | + let minn = simd_fmin(x, n); |
| 42 | + assert_eq!(minn, x); |
| 43 | + let minn = simd_fmin(y, n); |
| 44 | + assert_eq!(minn, y); |
| 45 | + |
| 46 | + // FIXME(49261) |
| 47 | + let max0 = simd_fmax(x, y); |
| 48 | + let max1 = simd_fmax(y, x); |
| 49 | + assert_eq!(max0, max1); |
| 50 | + let e = f32x4(2.0, 2.0, 4.0, 4.0); |
| 51 | + assert_eq!(max0, e); |
| 52 | + let maxn = simd_fmax(x, n); |
| 53 | + assert_eq!(maxn, x); |
| 54 | + let maxn = simd_fmax(y, n); |
| 55 | + assert_eq!(maxn, y); |
| 56 | + } |
| 57 | +} |
0 commit comments