-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add run-time test and missing codegen test
- Loading branch information
Showing
2 changed files
with
194 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// ignore-emscripten | ||
|
||
// compile-flags: -C no-prepopulate-passes | ||
|
||
#![crate_type = "lib"] | ||
|
||
#![feature(repr_simd, platform_intrinsics)] | ||
#![allow(non_camel_case_types)] | ||
|
||
#[repr(simd)] | ||
#[derive(Copy, Clone, PartialEq, Debug)] | ||
pub struct f32x2(pub f32, pub f32); | ||
|
||
#[repr(simd)] | ||
#[derive(Copy, Clone, PartialEq, Debug)] | ||
pub struct f32x4(pub f32, pub f32, pub f32, pub f32); | ||
|
||
#[repr(simd)] | ||
#[derive(Copy, Clone, PartialEq, Debug)] | ||
pub struct f32x8(pub f32, pub f32, pub f32, pub f32, | ||
pub f32, pub f32, pub f32, pub f32); | ||
|
||
#[repr(simd)] | ||
#[derive(Copy, Clone, PartialEq, Debug)] | ||
pub struct f32x16(pub f32, pub f32, pub f32, pub f32, | ||
pub f32, pub f32, pub f32, pub f32, | ||
pub f32, pub f32, pub f32, pub f32, | ||
pub f32, pub f32, pub f32, pub f32); | ||
|
||
extern "platform-intrinsic" { | ||
fn simd_flog<T>(x: T) -> T; | ||
} | ||
|
||
// CHECK-LABEL: @log_32x2 | ||
#[no_mangle] | ||
pub unsafe fn log_32x2(a: f32x2) -> f32x2 { | ||
// CHECK: call <2 x float> @llvm.log.v2f32 | ||
simd_flog(a) | ||
} | ||
|
||
// CHECK-LABEL: @log_32x4 | ||
#[no_mangle] | ||
pub unsafe fn log_32x4(a: f32x4) -> f32x4 { | ||
// CHECK: call <4 x float> @llvm.log.v4f32 | ||
simd_flog(a) | ||
} | ||
|
||
// CHECK-LABEL: @log_32x8 | ||
#[no_mangle] | ||
pub unsafe fn log_32x8(a: f32x8) -> f32x8 { | ||
// CHECK: call <8 x float> @llvm.log.v8f32 | ||
simd_flog(a) | ||
} | ||
|
||
// CHECK-LABEL: @log_32x16 | ||
#[no_mangle] | ||
pub unsafe fn log_32x16(a: f32x16) -> f32x16 { | ||
// CHECK: call <16 x float> @llvm.log.v16f32 | ||
simd_flog(a) | ||
} | ||
|
||
#[repr(simd)] | ||
#[derive(Copy, Clone, PartialEq, Debug)] | ||
pub struct f64x2(pub f64, pub f64); | ||
|
||
#[repr(simd)] | ||
#[derive(Copy, Clone, PartialEq, Debug)] | ||
pub struct f64x4(pub f64, pub f64, pub f64, pub f64); | ||
|
||
#[repr(simd)] | ||
#[derive(Copy, Clone, PartialEq, Debug)] | ||
pub struct f64x8(pub f64, pub f64, pub f64, pub f64, | ||
pub f64, pub f64, pub f64, pub f64); | ||
|
||
// CHECK-LABEL: @log_64x4 | ||
#[no_mangle] | ||
pub unsafe fn log_64x4(a: f64x4) -> f64x4 { | ||
// CHECK: call <4 x double> @llvm.log.v4f64 | ||
simd_flog(a) | ||
} | ||
|
||
// CHECK-LABEL: @log_64x2 | ||
#[no_mangle] | ||
pub unsafe fn log_64x2(a: f64x2) -> f64x2 { | ||
// CHECK: call <2 x double> @llvm.log.v2f64 | ||
simd_flog(a) | ||
} | ||
|
||
// CHECK-LABEL: @log_64x8 | ||
#[no_mangle] | ||
pub unsafe fn log_64x8(a: f64x8) -> f64x8 { | ||
// CHECK: call <8 x double> @llvm.log.v8f64 | ||
simd_flog(a) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// ignore-emscripten | ||
// error-pattern: panicked | ||
|
||
// 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_ceil<T>(x: T) -> T; | ||
fn simd_fexp<T>(x: T) -> T; | ||
fn simd_fexp2<T>(x: T) -> T; | ||
fn simd_floor<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; | ||
} | ||
|
||
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); | ||
assert_eq!(x, r); | ||
|
||
let r = simd_fcos(z); | ||
assert_eq!(x, r); | ||
|
||
let r = simd_ceil(h); | ||
assert_eq!(x, r); | ||
|
||
let r = simd_fexp(z); | ||
assert_eq!(x, r); | ||
|
||
let r = simd_fexp2(z); | ||
assert_eq!(x, r); | ||
|
||
let r = simd_floor(h); | ||
assert_eq!(z, r); | ||
|
||
let r = simd_fma(x, h, h); | ||
assert_eq!(x, r); | ||
|
||
let r = simd_fsqrt(x); | ||
assert_eq!(x, r); | ||
|
||
let r = simd_flog(x); | ||
assert_eq!(z, r); | ||
|
||
let r = simd_flog2(x); | ||
assert_eq!(z, r); | ||
|
||
let r = simd_flog10(x); | ||
assert_eq!(z, r); | ||
|
||
let r = simd_fpow(h, x); | ||
assert_eq!(h, r); | ||
|
||
let r = simd_fpowi(h, 1); | ||
assert_eq!(h, r); | ||
|
||
let r = simd_fsin(z); | ||
assert_eq!(z, r); | ||
} | ||
} |