2018-08-30 07:18:55 -05:00
|
|
|
// run-pass
|
2018-05-09 09:01:52 -05:00
|
|
|
// ignore-emscripten
|
2018-05-18 06:04:07 -05:00
|
|
|
// ignore-android
|
2018-05-09 09:01:52 -05:00
|
|
|
|
2018-05-18 06:06:50 -05:00
|
|
|
// FIXME: this test fails on arm-android because the NDK version 14 is too old.
|
|
|
|
// It needs at least version 18. We disable it on all android build bots because
|
|
|
|
// there is no way in compile-test to disable it for an (arch,os) pair.
|
|
|
|
|
2018-05-09 09:01:52 -05:00
|
|
|
// Test that the simd floating-point math intrinsics produce correct results.
|
|
|
|
|
|
|
|
#![feature(repr_simd, platform_intrinsics)]
|
|
|
|
#![allow(non_camel_case_types)]
|
|
|
|
|
|
|
|
#[repr(simd)]
|
|
|
|
#[derive(Copy, Clone, PartialEq, Debug)]
|
|
|
|
struct f32x4(pub f32, pub f32, pub f32, pub f32);
|
|
|
|
|
|
|
|
extern "platform-intrinsic" {
|
|
|
|
fn simd_fsqrt<T>(x: T) -> T;
|
|
|
|
fn simd_fabs<T>(x: T) -> T;
|
|
|
|
fn simd_fsin<T>(x: T) -> T;
|
|
|
|
fn simd_fcos<T>(x: T) -> T;
|
|
|
|
fn simd_fexp<T>(x: T) -> T;
|
|
|
|
fn simd_fexp2<T>(x: T) -> T;
|
|
|
|
fn simd_fma<T>(x: T, y: T, z: T) -> T;
|
|
|
|
fn simd_flog<T>(x: T) -> T;
|
|
|
|
fn simd_flog10<T>(x: T) -> T;
|
|
|
|
fn simd_flog2<T>(x: T) -> T;
|
|
|
|
fn simd_fpow<T>(x: T, y: T) -> T;
|
|
|
|
fn simd_fpowi<T>(x: T, y: i32) -> T;
|
2021-04-14 17:07:36 -05:00
|
|
|
|
|
|
|
// rounding functions
|
|
|
|
fn simd_ceil<T>(x: T) -> T;
|
|
|
|
fn simd_floor<T>(x: T) -> T;
|
|
|
|
fn simd_round<T>(x: T) -> T;
|
|
|
|
fn simd_trunc<T>(x: T) -> T;
|
2018-05-09 09:01:52 -05:00
|
|
|
}
|
|
|
|
|
2018-06-01 12:20:00 -05:00
|
|
|
macro_rules! assert_approx_eq_f32 {
|
|
|
|
($a:expr, $b:expr) => ({
|
|
|
|
let (a, b) = (&$a, &$b);
|
|
|
|
assert!((*a - *b).abs() < 1.0e-6,
|
|
|
|
"{} is not approximately equal to {}", *a, *b);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
macro_rules! assert_approx_eq {
|
|
|
|
($a:expr, $b:expr) => ({
|
|
|
|
let a = $a;
|
|
|
|
let b = $b;
|
|
|
|
assert_approx_eq_f32!(a.0, b.0);
|
|
|
|
assert_approx_eq_f32!(a.1, b.1);
|
|
|
|
assert_approx_eq_f32!(a.2, b.2);
|
|
|
|
assert_approx_eq_f32!(a.3, b.3);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-05-09 09:01:52 -05:00
|
|
|
fn main() {
|
|
|
|
let x = f32x4(1.0, 1.0, 1.0, 1.0);
|
|
|
|
let y = f32x4(-1.0, -1.0, -1.0, -1.0);
|
|
|
|
let z = f32x4(0.0, 0.0, 0.0, 0.0);
|
|
|
|
|
|
|
|
let h = f32x4(0.5, 0.5, 0.5, 0.5);
|
|
|
|
|
|
|
|
unsafe {
|
|
|
|
let r = simd_fabs(y);
|
2018-06-01 12:20:00 -05:00
|
|
|
assert_approx_eq!(x, r);
|
2018-05-09 09:01:52 -05:00
|
|
|
|
|
|
|
let r = simd_fcos(z);
|
2018-06-01 12:20:00 -05:00
|
|
|
assert_approx_eq!(x, r);
|
2018-05-09 09:01:52 -05:00
|
|
|
|
|
|
|
let r = simd_fexp(z);
|
2018-06-01 12:20:00 -05:00
|
|
|
assert_approx_eq!(x, r);
|
2018-05-09 09:01:52 -05:00
|
|
|
|
|
|
|
let r = simd_fexp2(z);
|
2018-06-01 12:20:00 -05:00
|
|
|
assert_approx_eq!(x, r);
|
2018-05-09 09:01:52 -05:00
|
|
|
|
|
|
|
let r = simd_fma(x, h, h);
|
2018-06-01 12:20:00 -05:00
|
|
|
assert_approx_eq!(x, r);
|
2018-05-09 09:01:52 -05:00
|
|
|
|
|
|
|
let r = simd_fsqrt(x);
|
2018-06-01 12:20:00 -05:00
|
|
|
assert_approx_eq!(x, r);
|
2018-05-09 09:01:52 -05:00
|
|
|
|
|
|
|
let r = simd_flog(x);
|
2018-06-01 12:20:00 -05:00
|
|
|
assert_approx_eq!(z, r);
|
2018-05-09 09:01:52 -05:00
|
|
|
|
|
|
|
let r = simd_flog2(x);
|
2018-06-01 12:20:00 -05:00
|
|
|
assert_approx_eq!(z, r);
|
2018-05-09 09:01:52 -05:00
|
|
|
|
|
|
|
let r = simd_flog10(x);
|
2018-06-01 12:20:00 -05:00
|
|
|
assert_approx_eq!(z, r);
|
2018-05-09 09:01:52 -05:00
|
|
|
|
|
|
|
let r = simd_fpow(h, x);
|
2018-06-01 12:20:00 -05:00
|
|
|
assert_approx_eq!(h, r);
|
2018-05-09 09:01:52 -05:00
|
|
|
|
|
|
|
let r = simd_fpowi(h, 1);
|
2018-06-01 12:20:00 -05:00
|
|
|
assert_approx_eq!(h, r);
|
2018-05-09 09:01:52 -05:00
|
|
|
|
|
|
|
let r = simd_fsin(z);
|
2018-06-01 12:20:00 -05:00
|
|
|
assert_approx_eq!(z, r);
|
2021-04-14 17:07:36 -05:00
|
|
|
|
|
|
|
// rounding functions
|
|
|
|
let r = simd_floor(h);
|
|
|
|
assert_eq!(z, r);
|
|
|
|
|
|
|
|
let r = simd_ceil(h);
|
|
|
|
assert_eq!(x, r);
|
|
|
|
|
|
|
|
let r = simd_round(h);
|
|
|
|
assert_eq!(x, r);
|
|
|
|
|
|
|
|
let r = simd_trunc(h);
|
|
|
|
assert_eq!(z, r);
|
2018-05-09 09:01:52 -05:00
|
|
|
}
|
|
|
|
}
|