Skip to content

Commit

Permalink
Merge pull request rust-lang#46 from alexcrichton/always-test
Browse files Browse the repository at this point in the history
Always test intrinsics unconditionally
  • Loading branch information
alexcrichton authored Sep 26, 2017
2 parents 411e125 + 338a9df commit 8dba149
Show file tree
Hide file tree
Showing 25 changed files with 519 additions and 563 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ debug = true
opt-level = 3

[dev-dependencies]
assert-instr = { path = "assert-instr" }
stdsimd-test = { path = "stdsimd-test" }
2 changes: 1 addition & 1 deletion src/arm/v6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//! Manual](http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0419c/index.html).

#[cfg(test)]
use assert_instr::assert_instr;
use stdsimd_test::assert_instr;

/// Reverse the order of the bytes.
#[inline(always)]
Expand Down
2 changes: 1 addition & 1 deletion src/arm/v7.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
pub use super::v6::*;

#[cfg(test)]
use assert_instr::assert_instr;
use stdsimd_test::assert_instr;

/// Count Leading Zeros.
#[inline(always)]
Expand Down
2 changes: 1 addition & 1 deletion src/arm/v8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
pub use super::v7::*;

#[cfg(test)]
use assert_instr::assert_instr;
use stdsimd_test::assert_instr;

/// Reverse the order of the bytes.
#[inline(always)]
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
#![cfg_attr(test, feature(proc_macro))]

#[cfg(test)]
extern crate assert_instr;
extern crate stdsimd_test;

/// Platform independent SIMD vector types and operations.
pub mod simd {
Expand Down
31 changes: 16 additions & 15 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ macro_rules! define_impl {
$($elname:ident),+
) => {
impl $name {
#[inline]
#[inline(always)]
pub fn new($($elname: $elemty),*) -> $name {
$name($($elname),*)
}

#[inline]
#[inline(always)]
pub fn splat(value: $elemty) -> $name {
$name($({
#[allow(non_camel_case_types, dead_code)]
Expand All @@ -37,25 +37,25 @@ macro_rules! define_impl {
}),*)
}

#[inline]
#[inline(always)]
pub fn extract(self, idx: u32) -> $elemty {
assert!(idx < $nelems);
unsafe { simd_extract(self, idx) }
}

#[inline]
#[inline(always)]
pub fn replace(self, idx: u32, val: $elemty) -> $name {
assert!(idx < $nelems);
unsafe { simd_insert(self, idx, val) }
}

#[inline]
#[inline(always)]
pub fn store(self, slice: &mut [$elemty], offset: usize) {
assert!(slice[offset..].len() >= $nelems);
unsafe { self.store_unchecked(slice, offset) }
}

#[inline]
#[inline(always)]
pub unsafe fn store_unchecked(
self,
slice: &mut [$elemty],
Expand All @@ -70,13 +70,13 @@ macro_rules! define_impl {
size_of::<$name>());
}

#[inline]
#[inline(always)]
pub fn load(slice: &[$elemty], offset: usize) -> $name {
assert!(slice[offset..].len() >= $nelems);
unsafe { $name::load_unchecked(slice, offset) }
}

#[inline]
#[inline(always)]
pub unsafe fn load_unchecked(
slice: &[$elemty],
offset: usize,
Expand All @@ -92,32 +92,32 @@ macro_rules! define_impl {
x
}

#[inline]
#[inline(always)]
pub fn eq(self, other: $name) -> $boolname {
unsafe { simd_eq(self, other) }
}

#[inline]
#[inline(always)]
pub fn ne(self, other: $name) -> $boolname {
unsafe { simd_ne(self, other) }
}

#[inline]
#[inline(always)]
pub fn lt(self, other: $name) -> $boolname {
unsafe { simd_lt(self, other) }
}

#[inline]
#[inline(always)]
pub fn le(self, other: $name) -> $boolname {
unsafe { simd_le(self, other) }
}

#[inline]
#[inline(always)]
pub fn gt(self, other: $name) -> $boolname {
unsafe { simd_gt(self, other) }
}

#[inline]
#[inline(always)]
pub fn ge(self, other: $name) -> $boolname {
unsafe { simd_ge(self, other) }
}
Expand All @@ -129,6 +129,7 @@ macro_rules! define_from {
($to:ident, $($from:ident),+) => {
$(
impl From<$from> for $to {
#[inline(always)]
fn from(f: $from) -> $to {
unsafe { ::std::mem::transmute(f) }
}
Expand Down Expand Up @@ -259,7 +260,7 @@ macro_rules! define_casts {
($(($fromty:ident, $toty:ident, $cast:ident)),+) => {
$(
impl $fromty {
#[inline]
#[inline(always)]
pub fn $cast(self) -> ::simd::$toty {
unsafe { simd_cast(self) }
}
Expand Down
18 changes: 8 additions & 10 deletions src/x86/abm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//! provides a quick overview of the instructions available.

#[cfg(test)]
use assert_instr::assert_instr;
use stdsimd_test::assert_instr;

/// Counts the leading most significant zero bits.
///
Expand Down Expand Up @@ -41,30 +41,28 @@ pub fn _popcnt32(x: u32) -> u32 { x.count_ones() }
#[cfg_attr(test, assert_instr(popcnt))]
pub fn _popcnt64(x: u64) -> u64 { x.count_ones() as u64 }

#[cfg(all(test, target_feature = "bmi", any(target_arch = "x86", target_arch = "x86_64")))]
#[cfg(test)]
mod tests {
use stdsimd_test::simd_test;

use x86::abm;

#[test]
#[target_feature = "+lzcnt"]
#[simd_test = "lzcnt"]
fn _lzcnt_u32() {
assert_eq!(abm::_lzcnt_u32(0b0101_1010u32), 25u32);
}

#[test]
#[target_feature = "+lzcnt"]
#[simd_test = "lzcnt"]
fn _lzcnt_u64() {
assert_eq!(abm::_lzcnt_u64(0b0101_1010u64), 57u64);
}

#[test]
#[target_feature = "+popcnt"]
#[simd_test = "popcnt"]
fn _popcnt32() {
assert_eq!(abm::_popcnt32(0b0101_1010u32), 4);
}

#[test]
#[target_feature = "+popcnt"]
#[simd_test = "popcnt"]
fn _popcnt64() {
assert_eq!(abm::_popcnt64(0b0101_1010u64), 4);
}
Expand Down
14 changes: 6 additions & 8 deletions src/x86/avx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ extern "C" {
fn addsubpd256(a: f64x4, b:f64x4) -> f64x4;
}


#[cfg(all(test, target_feature = "avx", any(target_arch = "x86", target_arch = "x86_64")))]
#[cfg(test)]
mod tests {
use stdsimd_test::simd_test;

use v256::*;
use x86::avx;

#[test]
#[target_feature = "+avx"]
#[simd_test = "avx"]
fn _mm256_add_pd() {
let a = f64x4::new(1.0, 2.0, 3.0, 4.0);
let b = f64x4::new(5.0, 6.0, 7.0, 8.0);
Expand All @@ -46,8 +46,7 @@ mod tests {
assert_eq!(r, e);
}

#[test]
#[target_feature = "+avx"]
#[simd_test = "avx"]
fn _mm256_add_ps() {
let a = f32x8::new(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0);
let b = f32x8::new(9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0);
Expand All @@ -56,8 +55,7 @@ mod tests {
assert_eq!(r, e);
}

#[test]
#[target_feature = "+avx"]
#[simd_test = "avx"]
fn _mm256_addsub_pd() {
let a = f64x4::new(1.0, 2.0, 3.0, 4.0);
let b = f64x4::new(5.0, 6.0, 7.0, 8.0);
Expand Down
Loading

0 comments on commit 8dba149

Please sign in to comment.