mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-29 20:46:07 +03:00
Touch up some recently added intrinsics
* Mark them as `unsafe` * Mark the tests as `unsafe` * Leverage the new features of the `#[assert_instr]` macro
This commit is contained in:
@@ -120,33 +120,23 @@ pub unsafe fn _mm256_floor_pd(a: f64x4) -> f64x4 {
|
||||
/// https://github.com/llvm-mirror/clang/blob/dcd8d797b20291f1a6b3e0ddda085aa2bbb382a8/lib/Headers/avxintrin.h#L382
|
||||
#[inline(always)]
|
||||
#[target_feature = "+avx"]
|
||||
// #[cfg_attr(test, assert_instr(vroundps))]
|
||||
// TODO: Replace with assert_expanded_instr https://github.com/rust-lang-nursery/stdsimd/issues/49
|
||||
pub fn _mm256_round_ps(a: f32x8, b: i32) -> f32x8 {
|
||||
#[cfg_attr(test, assert_instr(vroundps, b = 0x00))]
|
||||
pub unsafe fn _mm256_round_ps(a: f32x8, b: i32) -> f32x8 {
|
||||
macro_rules! call {
|
||||
($imm8:expr) => {
|
||||
unsafe { roundps256(a, $imm8) }
|
||||
roundps256(a, $imm8)
|
||||
}
|
||||
}
|
||||
constify_imm8!(b, call)
|
||||
}
|
||||
|
||||
// TODO: Remove once a macro is ipmlemented to automate these tests
|
||||
// https://github.com/rust-lang-nursery/stdsimd/issues/49
|
||||
#[cfg(test)]
|
||||
#[target_feature = "+avx"]
|
||||
#[cfg_attr(test, assert_instr(vroundps))]
|
||||
fn test_mm256_round_ps(a: f32x8) -> f32x8 {
|
||||
_mm256_round_ps(a, 0x00)
|
||||
}
|
||||
|
||||
/// Round packed single-precision (32-bit) floating point elements in `a` toward
|
||||
/// positive infinity.
|
||||
#[inline(always)]
|
||||
#[target_feature = "+avx"]
|
||||
#[cfg_attr(test, assert_instr(vroundps))]
|
||||
pub fn _mm256_ceil_ps(a: f32x8) -> f32x8 {
|
||||
unsafe { roundps256(a, 0x02) }
|
||||
pub unsafe fn _mm256_ceil_ps(a: f32x8) -> f32x8 {
|
||||
roundps256(a, 0x02)
|
||||
}
|
||||
|
||||
/// Round packed single-precision (32-bit) floating point elements in `a` toward
|
||||
@@ -154,8 +144,8 @@ pub fn _mm256_ceil_ps(a: f32x8) -> f32x8 {
|
||||
#[inline(always)]
|
||||
#[target_feature = "+avx"]
|
||||
#[cfg_attr(test, assert_instr(vroundps))]
|
||||
pub fn _mm256_floor_ps(a: f32x8) -> f32x8 {
|
||||
unsafe { roundps256(a, 0x01) }
|
||||
pub unsafe fn _mm256_floor_ps(a: f32x8) -> f32x8 {
|
||||
roundps256(a, 0x01)
|
||||
}
|
||||
|
||||
/// Return the square root of packed single-precision (32-bit) floating point
|
||||
@@ -163,8 +153,8 @@ pub fn _mm256_floor_ps(a: f32x8) -> f32x8 {
|
||||
#[inline(always)]
|
||||
#[target_feature = "+avx"]
|
||||
#[cfg_attr(test, assert_instr(vsqrtps))]
|
||||
pub fn _mm256_sqrt_ps(a: f32x8) -> f32x8 {
|
||||
unsafe { sqrtps256(a) }
|
||||
pub unsafe fn _mm256_sqrt_ps(a: f32x8) -> f32x8 {
|
||||
sqrtps256(a)
|
||||
}
|
||||
|
||||
/// Return the square root of packed double-precision (64-bit) floating point
|
||||
@@ -172,8 +162,8 @@ pub fn _mm256_sqrt_ps(a: f32x8) -> f32x8 {
|
||||
#[inline(always)]
|
||||
#[target_feature = "+avx"]
|
||||
#[cfg_attr(test, assert_instr(vsqrtpd))]
|
||||
pub fn _mm256_sqrt_pd(a: f64x4) -> f64x4 {
|
||||
unsafe { sqrtpd256(a) }
|
||||
pub unsafe fn _mm256_sqrt_pd(a: f64x4) -> f64x4 {
|
||||
sqrtpd256(a)
|
||||
}
|
||||
|
||||
/// LLVM intrinsics used in the above functions
|
||||
@@ -193,7 +183,7 @@ pub fn _mm256_sqrt_pd(a: f64x4) -> f64x4 {
|
||||
fn sqrtps256(a: f32x8) -> f32x8;
|
||||
}
|
||||
|
||||
#[cfg(all(test, target_feature = "avx", any(target_arch = "x86", target_arch = "x86_64")))]
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use stdsimd_test::simd_test;
|
||||
|
||||
@@ -303,7 +293,7 @@ unsafe fn _mm256_ceil_pd() {
|
||||
}
|
||||
|
||||
#[simd_test = "avx"]
|
||||
fn _mm256_round_ps() {
|
||||
unsafe fn _mm256_round_ps() {
|
||||
let a = f32x8::new(1.55, 2.2, 3.99, -1.2, 1.55, 2.2, 3.99, -1.2);
|
||||
let result_closest = avx::_mm256_round_ps(a, 0b00000000);
|
||||
let result_down = avx::_mm256_round_ps(a, 0b00000001);
|
||||
@@ -317,7 +307,7 @@ fn _mm256_round_ps() {
|
||||
}
|
||||
|
||||
#[simd_test = "avx"]
|
||||
fn _mm256_floor_ps() {
|
||||
unsafe fn _mm256_floor_ps() {
|
||||
let a = f32x8::new(1.55, 2.2, 3.99, -1.2, 1.55, 2.2, 3.99, -1.2);
|
||||
let result_down = avx::_mm256_floor_ps(a);
|
||||
let expected_down = f32x8::new(1.0, 2.0, 3.0, -2.0, 1.0, 2.0, 3.0, -2.0);
|
||||
@@ -325,7 +315,7 @@ fn _mm256_floor_ps() {
|
||||
}
|
||||
|
||||
#[simd_test = "avx"]
|
||||
fn _mm256_ceil_ps() {
|
||||
unsafe fn _mm256_ceil_ps() {
|
||||
let a = f32x8::new(1.55, 2.2, 3.99, -1.2, 1.55, 2.2, 3.99, -1.2);
|
||||
let result_up = avx::_mm256_ceil_ps(a);
|
||||
let expected_up = f32x8::new(2.0, 3.0, 4.0, -1.0, 2.0, 3.0, 4.0, -1.0);
|
||||
@@ -333,7 +323,7 @@ fn _mm256_ceil_ps() {
|
||||
}
|
||||
|
||||
#[simd_test = "avx"]
|
||||
fn _mm256_sqrt_pd() {
|
||||
unsafe fn _mm256_sqrt_pd() {
|
||||
let a = f64x4::new(4.0, 9.0, 16.0, 25.0);
|
||||
let r = avx::_mm256_sqrt_pd(a, );
|
||||
let e = f64x4::new(2.0, 3.0, 4.0, 5.0);
|
||||
@@ -341,11 +331,10 @@ fn _mm256_sqrt_pd() {
|
||||
}
|
||||
|
||||
#[simd_test = "avx"]
|
||||
fn _mm256_sqrt_ps() {
|
||||
unsafe fn _mm256_sqrt_ps() {
|
||||
let a = f32x8::new(4.0, 9.0, 16.0, 25.0, 4.0, 9.0, 16.0, 25.0);
|
||||
let r = avx::_mm256_sqrt_ps(a);
|
||||
let e = f32x8::new(2.0, 3.0, 4.0, 5.0, 2.0, 3.0, 4.0, 5.0);
|
||||
assert_eq!(r, e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user