Skip to content

Commit ecafa7b

Browse files
committed
add tests
1 parent f6a35aa commit ecafa7b

File tree

2 files changed

+95
-0
lines changed

2 files changed

+95
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright 2016 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+
// compile-flags: -C no-prepopulate-passes
12+
13+
#![crate_type = "lib"]
14+
15+
#![feature(repr_simd, platform_intrinsics)]
16+
#[allow(non_camel_case_types)]
17+
18+
#[repr(simd)]
19+
#[derive(Copy, Clone, PartialEq, Debug)]
20+
pub struct f32x4(pub f32, pub f32, pub f32, pub f32);
21+
22+
extern "platform-intrinsic" {
23+
fn simd_fmin<T>(x: T, y: T) -> T;
24+
fn simd_fmax<T>(x: T, y: T) -> T;
25+
}
26+
27+
// CHECK-LABEL: @fmin
28+
#[no_mangle]
29+
pub unsafe fn fmin(a: f32x4, b: f32x4) -> f32x4 {
30+
// CHECK: call <4 x float> @llvm.minnum.v4f32
31+
simd_fmin(a, b)
32+
}
33+
34+
// FIXME(49261)
35+
// // CHECK-LABEL: @fmax
36+
// #[no_mangle]
37+
// pub unsafe fn fmax(a: f32x4, b: f32x4) -> f32x4 {
38+
// // CHECK: call <4 x float> @llvm.maxnum.v4f32
39+
// simd_fmax(a, b)
40+
// }
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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_f{min,max} intrinsics produce the 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 f32x4(pub f32, pub f32, pub f32, pub f32);
21+
22+
extern "platform-intrinsic" {
23+
fn simd_fmin<T>(x: T, y: T) -> T;
24+
fn simd_fmax<T>(x: T, y: T) -> T;
25+
}
26+
27+
fn main() {
28+
let x = f32x4(1.0, 2.0, 3.0, 4.0);
29+
let y = f32x4(2.0, 1.0, 4.0, 3.0);
30+
let nan = ::std::f32::NAN;
31+
let n = f32x4(nan, nan, nan, nan);
32+
33+
unsafe {
34+
let min0 = simd_fmin(x, y);
35+
let min1 = simd_fmin(y, x);
36+
assert_eq!(min0, min1);
37+
let e = f32x4(1.0, 1.0, 3.0, 3.0);
38+
assert_eq!(min0, e);
39+
let minn = simd_fmin(x, n);
40+
assert_eq!(minn, x);
41+
let minn = simd_fmin(y, n);
42+
assert_eq!(minn, y);
43+
44+
// FIXME(49261)
45+
let max0 = simd_fmax(x, y);
46+
let max1 = simd_fmax(y, x);
47+
assert_eq!(max0, max1);
48+
let e = f32x4(2.0, 2.0, 4.0, 4.0);
49+
assert_eq!(max0, e);
50+
let maxn = simd_fmax(x, n);
51+
assert_eq!(maxn, x);
52+
let maxn = simd_fmax(y, n);
53+
assert_eq!(maxn, y);
54+
}
55+
}

0 commit comments

Comments
 (0)