]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_codegen_cranelift/example/float-minmax-pass.rs
Merge commit 'e9d1a0a7b0b28dd422f1a790ccde532acafbf193' into sync_cg_clif-2022-08-24
[rust.git] / compiler / rustc_codegen_cranelift / example / float-minmax-pass.rs
1 // Copied from https://github.com/rust-lang/rust/blob/3fe3b89cd57229343eeca753fdd8c63d9b03c65c/src/test/ui/simd/intrinsic/float-minmax-pass.rs
2 // run-pass
3 // ignore-emscripten
4
5 // Test that the simd_f{min,max} intrinsics produce the correct results.
6
7 #![feature(repr_simd, platform_intrinsics)]
8 #![allow(non_camel_case_types)]
9
10 #[repr(simd)]
11 #[derive(Copy, Clone, PartialEq, Debug)]
12 struct f32x4(pub f32, pub f32, pub f32, pub f32);
13
14 extern "platform-intrinsic" {
15     fn simd_fmin<T>(x: T, y: T) -> T;
16     fn simd_fmax<T>(x: T, y: T) -> T;
17 }
18
19 fn main() {
20     let x = f32x4(1.0, 2.0, 3.0, 4.0);
21     let y = f32x4(2.0, 1.0, 4.0, 3.0);
22
23     #[cfg(not(any(target_arch = "mips", target_arch = "mips64")))]
24     let nan = f32::NAN;
25     // MIPS hardware treats f32::NAN as SNAN. Clear the signaling bit.
26     // See https://github.com/rust-lang/rust/issues/52746.
27     #[cfg(any(target_arch = "mips", target_arch = "mips64"))]
28     let nan = f32::from_bits(f32::NAN.to_bits() - 1);
29
30     let n = f32x4(nan, nan, nan, nan);
31
32     unsafe {
33         let min0 = simd_fmin(x, y);
34         let min1 = simd_fmin(y, x);
35         assert_eq!(min0, min1);
36         let e = f32x4(1.0, 1.0, 3.0, 3.0);
37         assert_eq!(min0, e);
38         let minn = simd_fmin(x, n);
39         assert_eq!(minn, x);
40         let minn = simd_fmin(y, n);
41         assert_eq!(minn, y);
42
43         let max0 = simd_fmax(x, y);
44         let max1 = simd_fmax(y, x);
45         assert_eq!(max0, max1);
46         let e = f32x4(2.0, 2.0, 4.0, 4.0);
47         assert_eq!(max0, e);
48         let maxn = simd_fmax(x, n);
49         assert_eq!(maxn, x);
50         let maxn = simd_fmax(y, n);
51         assert_eq!(maxn, y);
52     }
53 }