Skip to content

Commit e0fd4e1

Browse files
committed
add run-time test and missing codegen test
1 parent 0068f40 commit e0fd4e1

File tree

2 files changed

+194
-0
lines changed

2 files changed

+194
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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+
// ignore-emscripten
12+
13+
// compile-flags: -C no-prepopulate-passes
14+
15+
#![crate_type = "lib"]
16+
17+
#![feature(repr_simd, platform_intrinsics)]
18+
#![allow(non_camel_case_types)]
19+
20+
#[repr(simd)]
21+
#[derive(Copy, Clone, PartialEq, Debug)]
22+
pub struct f32x2(pub f32, pub f32);
23+
24+
#[repr(simd)]
25+
#[derive(Copy, Clone, PartialEq, Debug)]
26+
pub struct f32x4(pub f32, pub f32, pub f32, pub f32);
27+
28+
#[repr(simd)]
29+
#[derive(Copy, Clone, PartialEq, Debug)]
30+
pub struct f32x8(pub f32, pub f32, pub f32, pub f32,
31+
pub f32, pub f32, pub f32, pub f32);
32+
33+
#[repr(simd)]
34+
#[derive(Copy, Clone, PartialEq, Debug)]
35+
pub struct f32x16(pub f32, pub f32, pub f32, pub f32,
36+
pub f32, pub f32, pub f32, pub f32,
37+
pub f32, pub f32, pub f32, pub f32,
38+
pub f32, pub f32, pub f32, pub f32);
39+
40+
extern "platform-intrinsic" {
41+
fn simd_flog<T>(x: T) -> T;
42+
}
43+
44+
// CHECK-LABEL: @log_32x2
45+
#[no_mangle]
46+
pub unsafe fn log_32x2(a: f32x2) -> f32x2 {
47+
// CHECK: call <2 x float> @llvm.log.v2f32
48+
simd_flog(a)
49+
}
50+
51+
// CHECK-LABEL: @log_32x4
52+
#[no_mangle]
53+
pub unsafe fn log_32x4(a: f32x4) -> f32x4 {
54+
// CHECK: call <4 x float> @llvm.log.v4f32
55+
simd_flog(a)
56+
}
57+
58+
// CHECK-LABEL: @log_32x8
59+
#[no_mangle]
60+
pub unsafe fn log_32x8(a: f32x8) -> f32x8 {
61+
// CHECK: call <8 x float> @llvm.log.v8f32
62+
simd_flog(a)
63+
}
64+
65+
// CHECK-LABEL: @log_32x16
66+
#[no_mangle]
67+
pub unsafe fn log_32x16(a: f32x16) -> f32x16 {
68+
// CHECK: call <16 x float> @llvm.log.v16f32
69+
simd_flog(a)
70+
}
71+
72+
#[repr(simd)]
73+
#[derive(Copy, Clone, PartialEq, Debug)]
74+
pub struct f64x2(pub f64, pub f64);
75+
76+
#[repr(simd)]
77+
#[derive(Copy, Clone, PartialEq, Debug)]
78+
pub struct f64x4(pub f64, pub f64, pub f64, pub f64);
79+
80+
#[repr(simd)]
81+
#[derive(Copy, Clone, PartialEq, Debug)]
82+
pub struct f64x8(pub f64, pub f64, pub f64, pub f64,
83+
pub f64, pub f64, pub f64, pub f64);
84+
85+
// CHECK-LABEL: @log_64x4
86+
#[no_mangle]
87+
pub unsafe fn log_64x4(a: f64x4) -> f64x4 {
88+
// CHECK: call <4 x double> @llvm.log.v4f64
89+
simd_flog(a)
90+
}
91+
92+
// CHECK-LABEL: @log_64x2
93+
#[no_mangle]
94+
pub unsafe fn log_64x2(a: f64x2) -> f64x2 {
95+
// CHECK: call <2 x double> @llvm.log.v2f64
96+
simd_flog(a)
97+
}
98+
99+
// CHECK-LABEL: @log_64x8
100+
#[no_mangle]
101+
pub unsafe fn log_64x8(a: f64x8) -> f64x8 {
102+
// CHECK: call <8 x double> @llvm.log.v8f64
103+
simd_flog(a)
104+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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+
// error-pattern: panicked
13+
14+
// Test that the simd floating-point math intrinsics produce correct results.
15+
16+
#![feature(repr_simd, platform_intrinsics)]
17+
#![allow(non_camel_case_types)]
18+
19+
#[repr(simd)]
20+
#[derive(Copy, Clone, PartialEq, Debug)]
21+
struct f32x4(pub f32, pub f32, pub f32, pub f32);
22+
23+
extern "platform-intrinsic" {
24+
fn simd_fsqrt<T>(x: T) -> T;
25+
fn simd_fabs<T>(x: T) -> T;
26+
fn simd_fsin<T>(x: T) -> T;
27+
fn simd_fcos<T>(x: T) -> T;
28+
fn simd_ceil<T>(x: T) -> T;
29+
fn simd_fexp<T>(x: T) -> T;
30+
fn simd_fexp2<T>(x: T) -> T;
31+
fn simd_floor<T>(x: T) -> T;
32+
fn simd_fma<T>(x: T, y: T, z: T) -> T;
33+
fn simd_flog<T>(x: T) -> T;
34+
fn simd_flog10<T>(x: T) -> T;
35+
fn simd_flog2<T>(x: T) -> T;
36+
fn simd_fpow<T>(x: T, y: T) -> T;
37+
fn simd_fpowi<T>(x: T, y: i32) -> T;
38+
}
39+
40+
fn main() {
41+
let x = f32x4(1.0, 1.0, 1.0, 1.0);
42+
let y = f32x4(-1.0, -1.0, -1.0, -1.0);
43+
let z = f32x4(0.0, 0.0, 0.0, 0.0);
44+
45+
let h = f32x4(0.5, 0.5, 0.5, 0.5);
46+
47+
unsafe {
48+
let r = simd_fabs(y);
49+
assert_eq!(x, r);
50+
51+
let r = simd_fcos(z);
52+
assert_eq!(x, r);
53+
54+
let r = simd_ceil(h);
55+
assert_eq!(x, r);
56+
57+
let r = simd_fexp(z);
58+
assert_eq!(x, r);
59+
60+
let r = simd_fexp2(z);
61+
assert_eq!(x, r);
62+
63+
let r = simd_floor(h);
64+
assert_eq!(z, r);
65+
66+
let r = simd_fma(x, h, h);
67+
assert_eq!(x, r);
68+
69+
let r = simd_fsqrt(x);
70+
assert_eq!(x, r);
71+
72+
let r = simd_flog(x);
73+
assert_eq!(z, r);
74+
75+
let r = simd_flog2(x);
76+
assert_eq!(z, r);
77+
78+
let r = simd_flog10(x);
79+
assert_eq!(z, r);
80+
81+
let r = simd_fpow(h, x);
82+
assert_eq!(h, r);
83+
84+
let r = simd_fpowi(h, 1);
85+
assert_eq!(h, r);
86+
87+
let r = simd_fsin(z);
88+
assert_eq!(z, r);
89+
}
90+
}

0 commit comments

Comments
 (0)