Merge pull request #46 from alexcrichton/always-test

Always test intrinsics unconditionally
This commit is contained in:
Alex Crichton 2017-09-26 16:45:05 -05:00 committed by GitHub
commit 374ece6818
25 changed files with 519 additions and 563 deletions

View file

@ -19,4 +19,4 @@ debug = true
opt-level = 3
[dev-dependencies]
assert-instr = { path = "assert-instr" }
stdsimd-test = { path = "stdsimd-test" }

View file

@ -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)]

View file

@ -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)]

View file

@ -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)]

View file

@ -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 {

View file

@ -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)]
@ -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],
@ -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,
@ -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) }
}
@ -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) }
}
@ -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) }
}

View file

@ -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.
///
@ -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);
}

View file

@ -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);
@ -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);
@ -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);

View file

@ -1044,16 +1044,17 @@ extern "C" {
}
#[cfg(all(test, target_feature = "avx2", any(target_arch = "x86", target_arch = "x86_64")))]
#[cfg(test)]
mod tests {
use stdsimd_test::simd_test;
use v256::*;
use v128::*;
use x86::avx2;
use x86::__m256i;
use std;
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_abs_epi32() {
let a = i32x8::new(
0, 1, -1, std::i32::MAX,
@ -1065,8 +1066,7 @@ mod tests {
assert_eq!(r, e);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_abs_epi16() {
let a = i16x16::new(
0, 1, -1, 2,
@ -1082,8 +1082,7 @@ mod tests {
assert_eq!(r, e);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_abs_epi8() {
let a = i8x32::new(
0, 1, -1, 2,
@ -1103,8 +1102,7 @@ mod tests {
assert_eq!(r, e);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_add_epi64() {
let a = i64x4::new(-10, 0, 100, 1_000_000_000);
let b = i64x4::new(-1, 0, 1, 2);
@ -1113,8 +1111,7 @@ mod tests {
assert_eq!(r, e);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_add_epi32() {
let a = i32x8::new(-1, 0, 1, 2, 3, 4, 5, 6);
let b = i32x8::new(1, 2, 3, 4, 5, 6, 7, 8);
@ -1123,8 +1120,7 @@ mod tests {
assert_eq!(r, e);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_add_epi16() {
let a = i16x16::new(
0, 1, 2, 3, 4, 5, 6, 7,
@ -1139,8 +1135,7 @@ mod tests {
assert_eq!(r, e);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_add_epi8() {
let a = i8x32::new(
0, 1, 2, 3, 4, 5, 6, 7,
@ -1161,8 +1156,7 @@ mod tests {
assert_eq!(r, e);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_adds_epi8() {
let a = i8x32::new(
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
@ -1177,8 +1171,7 @@ mod tests {
assert_eq!(r, e);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_adds_epi8_saturate_positive() {
let a = i8x32::splat(0x7F);
let b = i8x32::splat(1);
@ -1186,8 +1179,7 @@ mod tests {
assert_eq!(r, a);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_adds_epi8_saturate_negative() {
let a = i8x32::splat(-0x80);
let b = i8x32::splat(-1);
@ -1195,8 +1187,7 @@ mod tests {
assert_eq!(r, a);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_adds_epi16() {
let a = i16x16::new(
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
@ -1209,8 +1200,7 @@ mod tests {
assert_eq!(r, e);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_adds_epi16_saturate_positive() {
let a = i16x16::splat(0x7FFF);
let b = i16x16::splat(1);
@ -1218,8 +1208,7 @@ mod tests {
assert_eq!(r, a);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_adds_epi16_saturate_negative() {
let a = i16x16::splat(-0x8000);
let b = i16x16::splat(-1);
@ -1227,8 +1216,7 @@ mod tests {
assert_eq!(r, a);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_adds_epu8() {
let a = u8x32::new(
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
@ -1243,8 +1231,7 @@ mod tests {
assert_eq!(r, e);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_adds_epu8_saturate() {
let a = u8x32::splat(0xFF);
let b = u8x32::splat(1);
@ -1253,8 +1240,7 @@ mod tests {
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_adds_epu16() {
let a = u16x16::new(
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
@ -1267,8 +1253,7 @@ mod tests {
assert_eq!(r, e);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_adds_epu16_saturate() {
let a = u16x16::splat(0xFFFF);
let b = u16x16::splat(1);
@ -1276,40 +1261,35 @@ mod tests {
assert_eq!(r, a);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_and_si256() {
assert_eq!(
avx2::_mm256_and_si256(
__m256i::splat(5), __m256i::splat(3)),__m256i::splat(1));
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_andnot_si256() {
assert_eq!(
avx2::_mm256_andnot_si256(__m256i::splat(5), __m256i::splat(3)),
__m256i::splat(2));
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_avg_epu8() {
let (a, b) = (u8x32::splat(3), u8x32::splat(9));
let r = avx2::_mm256_avg_epu8(a, b);
assert_eq!(r, u8x32::splat(6));
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_avg_epu16() {
let (a, b) = (u16x16::splat(3), u16x16::splat(9));
let r = avx2::_mm256_avg_epu16(a, b);
assert_eq!(r, u16x16::splat(6));
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_blendv_epi8() {
let (a,b) = (i8x32::splat(4),i8x32::splat(2));
let mask = i8x32::splat(0).replace(2,-1);
@ -1318,7 +1298,7 @@ mod tests {
assert_eq!(r,e);
}
#[test]
#[simd_test = "avx2"]
fn _mm256_cmpeq_epi8() {
let a = i8x32::new(
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
@ -1330,7 +1310,7 @@ mod tests {
assert_eq!(r, i8x32::splat(0).replace(2,0xFFu8 as i8));
}
#[test]
#[simd_test = "avx2"]
fn _mm256_cmpeq_epi16() {
let a = i16x16::new(
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
@ -1340,7 +1320,7 @@ mod tests {
assert_eq!(r, i16x16::splat(0).replace(2, 0xFFFFu16 as i16));
}
#[test]
#[simd_test = "avx2"]
fn _mm256_cmpeq_epi32() {
let a = i32x8::new(0, 1, 2, 3,4,5,6,7);
let b = i32x8::new(7,6,2,4,3, 2, 1, 0);
@ -1348,7 +1328,7 @@ mod tests {
assert_eq!(r, i32x8::splat(0).replace(2, 0xFFFFFFFFu32 as i32));
}
#[test]
#[simd_test = "avx2"]
fn _mm256_cmpeq_epi64() {
let a = i64x4::new(0, 1, 2, 3);
let b = i64x4::new(3, 2, 2, 0);
@ -1357,7 +1337,7 @@ mod tests {
2, 0xFFFFFFFFFFFFFFFFu64 as i64));
}
#[test]
#[simd_test = "avx2"]
fn _mm256_cmpgt_epi8() {
let a = i8x32::splat(0).replace(0, 5);
let b = i8x32::splat(0);
@ -1365,7 +1345,7 @@ mod tests {
assert_eq!(r, i8x32::splat(0).replace(0, 0xFFu8 as i8));
}
#[test]
#[simd_test = "avx2"]
fn _mm256_cmpgt_epi16() {
let a = i16x16::splat(0).replace(0, 5);
let b = i16x16::splat(0);
@ -1373,7 +1353,7 @@ mod tests {
assert_eq!(r, i16x16::splat(0).replace(0, 0xFFFFu16 as i16));
}
#[test]
#[simd_test = "avx2"]
fn _mm256_cmpgt_epi32() {
let a = i32x8::splat(0).replace(0, 5);
let b = i32x8::splat(0);
@ -1381,7 +1361,7 @@ mod tests {
assert_eq!(r, i32x8::splat(0).replace(0, 0xFFFFFFFFu32 as i32));
}
#[test]
#[simd_test = "avx2"]
fn _mm256_cmpgt_epi64() {
let a = i64x4::splat(0).replace(0, 5);
let b = i64x4::splat(0);
@ -1390,8 +1370,7 @@ mod tests {
0, 0xFFFFFFFFFFFFFFFFu64 as i64));
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_hadd_epi16() {
let a = i16x16::splat(2);
let b = i16x16::splat(4);
@ -1400,8 +1379,7 @@ mod tests {
assert_eq!(r, e);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_hadd_epi32() {
let a = i32x8::splat(2);
let b = i32x8::splat(4);
@ -1410,8 +1388,7 @@ mod tests {
assert_eq!(r, e);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_hadds_epi16() {
let a = i16x16::splat(2).replace(0,0x7FFF).replace(1,1);
let b = i16x16::splat(4);
@ -1421,8 +1398,7 @@ mod tests {
assert_eq!(r, e);
}
#[test]
#[target_feature ="+avx2"]
#[simd_test = "avx2"]
fn _mm256_hsub_epi16() {
let a = i16x16::splat(2);
let b = i16x16::splat(4);
@ -1431,8 +1407,7 @@ mod tests {
assert_eq!(r, e);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_hsub_epi32() {
let a = i32x8::splat(2);
let b = i32x8::splat(4);
@ -1441,8 +1416,7 @@ mod tests {
assert_eq!(r, e);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_hsubs_epi16() {
let a = i16x16::splat(2).replace(0,0x7FFF).replace(1,-1);
let b = i16x16::splat(4);
@ -1451,8 +1425,7 @@ mod tests {
assert_eq!(r, e);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_madd_epi16() {
let a = i16x16::splat(2);
let b = i16x16::splat(4);
@ -1461,8 +1434,7 @@ mod tests {
assert_eq!(r, e);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_maddubs_epi16() {
let a = u8x32::splat(2);
let b = u8x32::splat(4);
@ -1471,8 +1443,7 @@ mod tests {
assert_eq!(r, e);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_max_epi16() {
let a = i16x16::splat(2);
let b = i16x16::splat(4);
@ -1480,8 +1451,7 @@ mod tests {
assert_eq!(r, b);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_max_epi32() {
let a = i32x8::splat(2);
let b = i32x8::splat(4);
@ -1489,8 +1459,7 @@ mod tests {
assert_eq!(r, b);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_max_epi8() {
let a = i8x32::splat(2);
let b = i8x32::splat(4);
@ -1498,8 +1467,7 @@ mod tests {
assert_eq!(r, b);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_max_epu16() {
let a = u16x16::splat(2);
let b = u16x16::splat(4);
@ -1507,8 +1475,7 @@ mod tests {
assert_eq!(r, b);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_max_epu32() {
let a = u32x8::splat(2);
let b = u32x8::splat(4);
@ -1516,8 +1483,7 @@ mod tests {
assert_eq!(r, b);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_max_epu8() {
let a = u8x32::splat(2);
let b = u8x32::splat(4);
@ -1525,8 +1491,7 @@ mod tests {
assert_eq!(r, b);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_min_epi16() {
let a = i16x16::splat(2);
let b = i16x16::splat(4);
@ -1534,8 +1499,7 @@ mod tests {
assert_eq!(r, a);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_min_epi32() {
let a = i32x8::splat(2);
let b = i32x8::splat(4);
@ -1543,8 +1507,7 @@ mod tests {
assert_eq!(r, a);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_min_epi8() {
let a = i8x32::splat(2);
let b = i8x32::splat(4);
@ -1552,8 +1515,7 @@ mod tests {
assert_eq!(r, a);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_min_epu16() {
let a = u16x16::splat(2);
let b = u16x16::splat(4);
@ -1561,8 +1523,7 @@ mod tests {
assert_eq!(r, a);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_min_epu32() {
let a = u32x8::splat(2);
let b = u32x8::splat(4);
@ -1570,8 +1531,7 @@ mod tests {
assert_eq!(r, a);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_min_epu8() {
let a = u8x32::splat(2);
let b = u8x32::splat(4);
@ -1603,8 +1563,7 @@ mod tests {
}
**/
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_mul_epi32() {
let a = i32x8::new(0, 0, 0, 0, 2, 2, 2, 2);
let b = i32x8::new(1, 2, 3, 4, 5, 6, 7, 8);
@ -1613,8 +1572,7 @@ mod tests {
assert_eq!(r, e);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_mul_epu32() {
let a = u32x8::new(0, 0, 0, 0, 2, 2, 2, 2);
let b = u32x8::new(1, 2, 3, 4, 5, 6, 7, 8);
@ -1623,8 +1581,7 @@ mod tests {
assert_eq!(r, e);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_mulhi_epi16() {
let a = i16x16::splat(6535);
let b = i16x16::splat(6535);
@ -1633,8 +1590,7 @@ mod tests {
assert_eq!(r, e);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_mulhi_epu16() {
let a = u16x16::splat(6535);
let b = u16x16::splat(6535);
@ -1643,8 +1599,7 @@ mod tests {
assert_eq!(r, e);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_mullo_epi16() {
let a = i16x16::splat(2);
let b = i16x16::splat(4);
@ -1653,8 +1608,7 @@ mod tests {
assert_eq!(r, e);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_mullo_epi32() {
let a = i32x8::splat(2);
let b = i32x8::splat(4);
@ -1663,8 +1617,7 @@ mod tests {
assert_eq!(r, e);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_mulhrs_epi16() {
let a = i16x16::splat(2);
let b = i16x16::splat(4);
@ -1673,8 +1626,7 @@ mod tests {
assert_eq!(r, e);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_or_si256() {
let a = __m256i::splat(-1);
let b = __m256i::splat(0);
@ -1682,8 +1634,7 @@ mod tests {
assert_eq!(r, a);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_packs_epi16() {
let a = i16x16::splat(2);
let b = i16x16::splat(4);
@ -1697,8 +1648,7 @@ mod tests {
assert_eq!(r, e);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_packs_epi32() {
let a = i32x8::splat(2);
let b = i32x8::splat(4);
@ -1712,8 +1662,7 @@ mod tests {
assert_eq!(r, e);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_packus_epi16() {
let a = i16x16::splat(2);
let b = i16x16::splat(4);
@ -1727,8 +1676,7 @@ mod tests {
assert_eq!(r, e);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_packus_epi32() {
let a = i32x8::splat(2);
let b = i32x8::splat(4);
@ -1742,8 +1690,7 @@ mod tests {
assert_eq!(r, e);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_sad_epu8() {
let a = u8x32::splat(2);
let b = u8x32::splat(4);
@ -1752,8 +1699,7 @@ mod tests {
assert_eq!(r, e);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_sign_epi16() {
let a = i16x16::splat(2);
let b = i16x16::splat(-1);
@ -1762,8 +1708,7 @@ mod tests {
assert_eq!(r, e);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_sign_epi32() {
let a = i32x8::splat(2);
let b = i32x8::splat(-1);
@ -1772,8 +1717,7 @@ mod tests {
assert_eq!(r, e);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_sign_epi8() {
let a = i8x32::splat(2);
let b = i8x32::splat(-1);
@ -1782,8 +1726,7 @@ mod tests {
assert_eq!(r, e);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_sll_epi16() {
assert_eq!(
avx2::_mm256_sll_epi16(i16x16::splat(0xFF), i16x8::splat(0).replace(0,4)),
@ -1791,8 +1734,7 @@ mod tests {
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_sll_epi32() {
assert_eq!(
avx2::_mm256_sll_epi32(i32x8::splat(0xFFFF), i32x4::splat(0).replace(0,4)),
@ -1800,8 +1742,7 @@ mod tests {
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_sll_epi64() {
assert_eq!(
avx2::_mm256_sll_epi64(i64x4::splat(0xFFFFFFFF), i64x2::splat(0).replace(0,4)),
@ -1809,32 +1750,28 @@ mod tests {
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_slli_epi16() {
assert_eq!(
avx2::_mm256_slli_epi16(i16x16::splat(0xFF), 4),
i16x16::splat(0xFF0));
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_slli_epi32() {
assert_eq!(
avx2::_mm256_slli_epi32(i32x8::splat(0xFFFF), 4),
i32x8::splat(0xFFFF0));
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_slli_epi64() {
assert_eq!(
avx2::_mm256_slli_epi64(i64x4::splat(0xFFFFFFFF), 4),
i64x4::splat(0xFFFFFFFF0));
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm_sllv_epi32() {
let a = i32x4::splat(2);
let b = i32x4::splat(1);
@ -1843,8 +1780,7 @@ mod tests {
assert_eq!(r, e);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_sllv_epi32() {
let a = i32x8::splat(2);
let b = i32x8::splat(1);
@ -1852,8 +1788,8 @@ mod tests {
let e = i32x8::splat(4);
assert_eq!(r, e);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm_sllv_epi64() {
let a = i64x2::splat(2);
let b = i64x2::splat(1);
@ -1861,8 +1797,8 @@ mod tests {
let e = i64x2::splat(4);
assert_eq!(r, e);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_sllv_epi64() {
let a = i64x4::splat(2);
let b = i64x4::splat(1);
@ -1871,8 +1807,7 @@ mod tests {
assert_eq!(r, e);
}
#[test]
#[target_feature ="+avx2"]
#[simd_test = "avx2"]
fn _mm256_sra_epi16() {
assert_eq!(
avx2::_mm256_sra_epi16(
@ -1880,8 +1815,7 @@ mod tests {
i16x16::splat(-1));
}
#[test]
#[target_feature ="+avx2"]
#[simd_test = "avx2"]
fn _mm256_sra_epi32() {
assert_eq!(
avx2::_mm256_sra_epi32(
@ -1889,24 +1823,21 @@ mod tests {
i32x8::splat(-1));
}
#[test]
#[target_feature ="+avx2"]
#[simd_test = "avx2"]
fn _mm256_srai_epi16() {
assert_eq!(
avx2::_mm256_srai_epi16(
i16x16::splat(-1), 1), i16x16::splat(-1));
}
#[test]
#[target_feature ="+avx2"]
#[simd_test = "avx2"]
fn _mm256_srai_epi32() {
assert_eq!(
avx2::_mm256_srai_epi32(
i32x8::splat(-1), 1), i32x8::splat(-1));
}
#[test]
#[target_feature ="+avx2"]
#[simd_test = "avx2"]
fn _mm_srav_epi32() {
let a = i32x4::splat(4);
let count = i32x4::splat(1);
@ -1915,8 +1846,7 @@ mod tests {
assert_eq!(r, e );
}
#[test]
#[target_feature ="+avx2"]
#[simd_test = "avx2"]
fn _mm256_srav_epi32() {
let a = i32x8::splat(4);
let count = i32x8::splat(1);
@ -1925,8 +1855,7 @@ mod tests {
assert_eq!(r, e );
}
#[test]
#[target_feature ="+avx2"]
#[simd_test = "avx2"]
fn _mm256_srl_epi16() {
assert_eq!(
avx2::_mm256_srl_epi16(
@ -1934,8 +1863,7 @@ mod tests {
i16x16::splat(0xF));
}
#[test]
#[target_feature ="+avx2"]
#[simd_test = "avx2"]
fn _mm256_srl_epi32() {
assert_eq!(
avx2::_mm256_srl_epi32(
@ -1943,8 +1871,7 @@ mod tests {
i32x8::splat(0xFFF));
}
#[test]
#[target_feature ="+avx2"]
#[simd_test = "avx2"]
fn _mm256_srl_epi64() {
assert_eq!(
avx2::_mm256_srl_epi64(
@ -1952,32 +1879,28 @@ mod tests {
i64x4::splat(0xFFFFFFF));
}
#[test]
#[target_feature ="+avx2"]
#[simd_test = "avx2"]
fn _mm256_srli_epi16() {
assert_eq!(
avx2::_mm256_srli_epi16(i16x16::splat(0xFF), 4),
i16x16::splat(0xF));
}
#[test]
#[target_feature ="+avx2"]
#[simd_test = "avx2"]
fn _mm256_srli_epi32() {
assert_eq!(
avx2::_mm256_srli_epi32(i32x8::splat(0xFFFF), 4),
i32x8::splat(0xFFF));
}
#[test]
#[target_feature ="+avx2"]
#[simd_test = "avx2"]
fn _mm256_srli_epi64() {
assert_eq!(
avx2::_mm256_srli_epi64(i64x4::splat(0xFFFFFFFF), 4),
i64x4::splat(0xFFFFFFF));
}
#[test]
#[target_feature ="+avx2"]
#[simd_test = "avx2"]
fn _mm_srlv_epi32() {
let a = i32x4::splat(2);
let count = i32x4::splat(1);
@ -1986,8 +1909,7 @@ mod tests {
assert_eq!(r, e);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_srlv_epi32() {
let a = i32x8::splat(2);
let count = i32x8::splat(1);
@ -1996,8 +1918,7 @@ mod tests {
assert_eq!(r, e);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm_srlv_epi64() {
let a = i64x2::splat(2);
let count = i64x2::splat(1);
@ -2007,8 +1928,7 @@ mod tests {
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_srlv_epi64() {
let a = i64x4::splat(2);
let count = i64x4::splat(1);
@ -2017,8 +1937,7 @@ mod tests {
assert_eq!(r, e);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_sub_epi16() {
let a = i16x16::splat(4);
let b = i16x16::splat(2);
@ -2026,8 +1945,7 @@ mod tests {
assert_eq!(r, b);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_sub_epi32() {
let a = i32x8::splat(4);
let b = i32x8::splat(2);
@ -2035,8 +1953,7 @@ mod tests {
assert_eq!(r, b);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_sub_epi64() {
let a = i64x4::splat(4);
let b = i64x4::splat(2);
@ -2044,8 +1961,7 @@ mod tests {
assert_eq!(r, b);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_sub_epi8() {
let a = i8x32::splat(4);
let b = i8x32::splat(2);
@ -2053,8 +1969,7 @@ mod tests {
assert_eq!(r, b);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_subs_epi16() {
let a = i16x16::splat(4);
let b = i16x16::splat(2);
@ -2062,8 +1977,7 @@ mod tests {
assert_eq!(r, b);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_subs_epi8() {
let a = i8x32::splat(4);
let b = i8x32::splat(2);
@ -2071,8 +1985,7 @@ mod tests {
assert_eq!(r, b);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_subs_epu16() {
let a = u16x16::splat(4);
let b = u16x16::splat(2);
@ -2080,8 +1993,7 @@ mod tests {
assert_eq!(r, b);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_subs_epu8() {
let a = u8x32::splat(4);
let b = u8x32::splat(2);
@ -2089,13 +2001,10 @@ mod tests {
assert_eq!(r, b);
}
#[test]
#[target_feature = "+avx2"]
#[simd_test = "avx2"]
fn _mm256_xor_si256() {
assert_eq!(
avx2::_mm256_xor_si256(__m256i::splat(5), __m256i::splat(3)),
__m256i::splat(6));
}
}

View file

@ -8,7 +8,7 @@
//! provides a quick overview of the available instructions.
#[cfg(test)]
use assert_instr::assert_instr;
use stdsimd_test::assert_instr;
#[allow(dead_code)]
extern "C" {
@ -185,22 +185,21 @@ pub fn _mm_tzcnt_u64(x: u64) -> u64 {
#[cfg(all(test, target_feature = "bmi", any(target_arch = "x86", target_arch = "x86_64")))]
mod tests {
use stdsimd_test::simd_test;
use x86::bmi;
#[test]
#[target_feature = "+bmi"]
#[simd_test = "bmi"]
fn _bextr_u32() {
assert_eq!(bmi::_bextr_u32(0b0101_0000u32, 4, 4), 0b0000_0101u32);
}
#[test]
#[target_feature = "+bmi"]
#[simd_test = "bmi"]
fn _bextr_u64() {
assert_eq!(bmi::_bextr_u64(0b0101_0000u64, 4, 4), 0b0000_0101u64);
}
#[test]
#[target_feature = "+bmi"]
#[simd_test = "bmi"]
fn _andn_u32() {
assert_eq!(bmi::_andn_u32(0, 0), 0);
assert_eq!(bmi::_andn_u32(0, 1), 1);
@ -214,8 +213,7 @@ mod tests {
assert_eq!(bmi::_andn_u32(0b0100_0000u32, 0b0101_1101u32), 0b0001_1101u32);
}
#[test]
#[target_feature = "+bmi"]
#[simd_test = "bmi"]
fn _andn_u64() {
assert_eq!(bmi::_andn_u64(0, 0), 0);
assert_eq!(bmi::_andn_u64(0, 1), 1);
@ -229,62 +227,53 @@ mod tests {
assert_eq!(bmi::_andn_u64(0b0100_0000u64, 0b0101_1101u64), 0b0001_1101u64);
}
#[test]
#[target_feature = "+bmi"]
#[simd_test = "bmi"]
fn _blsi_u32() {
assert_eq!(bmi::_blsi_u32(0b1101_0000u32), 0b0001_0000u32);
}
#[test]
#[target_feature = "+bmi"]
#[simd_test = "bmi"]
fn _blsi_u64() {
assert_eq!(bmi::_blsi_u64(0b1101_0000u64), 0b0001_0000u64);
}
#[test]
#[target_feature = "+bmi"]
#[simd_test = "bmi"]
fn _blsmsk_u32() {
assert_eq!(bmi::_blsmsk_u32(0b0011_0000u32), 0b0001_1111u32);
}
#[test]
#[target_feature = "+bmi"]
#[simd_test = "bmi"]
fn _blsmsk_u64() {
assert_eq!(bmi::_blsmsk_u64(0b0011_0000u64), 0b0001_1111u64);
}
#[test]
#[target_feature = "+bmi"]
#[simd_test = "bmi"]
fn _blsr_u32() {
/// TODO: test the behavior when the input is 0
assert_eq!(bmi::_blsr_u32(0b0011_0000u32), 0b0010_0000u32);
}
#[test]
#[target_feature = "+bmi"]
#[simd_test = "bmi"]
fn _blsr_u64() {
/// TODO: test the behavior when the input is 0
assert_eq!(bmi::_blsr_u64(0b0011_0000u64), 0b0010_0000u64);
}
#[test]
#[target_feature = "+bmi"]
#[simd_test = "bmi"]
fn _tzcnt_u16() {
assert_eq!(bmi::_tzcnt_u16(0b0000_0001u16), 0u16);
assert_eq!(bmi::_tzcnt_u16(0b0000_0000u16), 16u16);
assert_eq!(bmi::_tzcnt_u16(0b1001_0000u16), 4u16);
}
#[test]
#[target_feature = "+bmi"]
#[simd_test = "bmi"]
fn _tzcnt_u32() {
assert_eq!(bmi::_tzcnt_u32(0b0000_0001u32), 0u32);
assert_eq!(bmi::_tzcnt_u32(0b0000_0000u32), 32u32);
assert_eq!(bmi::_tzcnt_u32(0b1001_0000u32), 4u32);
}
#[test]
#[target_feature = "+bmi"]
#[simd_test = "bmi"]
fn _tzcnt_u64() {
assert_eq!(bmi::_tzcnt_u64(0b0000_0001u64), 0u64);
assert_eq!(bmi::_tzcnt_u64(0b0000_0000u64), 64u64);

View file

@ -8,7 +8,7 @@
//! provides a quick overview of the available instructions.
#[cfg(test)]
use assert_instr::assert_instr;
use stdsimd_test::assert_instr;
/// Unsigned multiply without affecting flags.
///
@ -112,12 +112,13 @@ pub fn _pext_u64(a: u64, mask: u64) -> u64 {
unsafe { x86_bmi2_pext_64(a, mask) }
}
#[cfg(all(test, target_feature = "bmi2", any(target_arch = "x86", target_arch = "x86_64")))]
#[cfg(test)]
mod tests {
use stdsimd_test::simd_test;
use x86::bmi2;
#[test]
#[target_feature = "+bmi2"]
#[simd_test = "bmi2"]
fn _pext_u32() {
let n = 0b1011_1110_1001_0011u32;
@ -131,8 +132,8 @@ mod tests {
assert_eq!(bmi2::_pext_u32(n, m1), s1);
}
#[test]
#[target_feature = "+bmi2"]
#[simd_test = "bmi2"]
#[cfg(not(target_arch = "x86"))]
fn _pext_u64() {
let n = 0b1011_1110_1001_0011u64;
@ -146,8 +147,7 @@ mod tests {
assert_eq!(bmi2::_pext_u64(n, m1), s1);
}
#[test]
#[target_feature = "+bmi2"]
#[simd_test = "bmi2"]
fn _pdep_u32() {
let n = 0b1011_1110_1001_0011u32;
@ -161,8 +161,8 @@ mod tests {
assert_eq!(bmi2::_pdep_u32(n, m1), s1);
}
#[test]
#[target_feature = "+bmi2"]
#[simd_test = "bmi2"]
#[cfg(not(target_arch = "x86"))]
fn _pdep_u64() {
let n = 0b1011_1110_1001_0011u64;
@ -176,24 +176,22 @@ mod tests {
assert_eq!(bmi2::_pdep_u64(n, m1), s1);
}
#[test]
#[target_feature = "+bmi2"]
#[simd_test = "bmi2"]
fn _bzhi_u32() {
let n = 0b1111_0010u32;
let s = 0b0001_0010u32;
assert_eq!(bmi2::_bzhi_u32(n, 5), s);
}
#[test]
#[target_feature = "+bmi2"]
#[simd_test = "bmi2"]
#[cfg(not(target_arch = "x86"))]
fn _bzhi_u64() {
let n = 0b1111_0010u64;
let s = 0b0001_0010u64;
assert_eq!(bmi2::_bzhi_u64(n, 5), s);
}
#[test]
#[target_feature = "+bmi2"]
#[simd_test = "bmi2"]
fn _mulx_u32() {
let a: u32 = 4_294_967_200;
let b: u32 = 2;
@ -205,8 +203,8 @@ mod tests {
assert_eq!(hi, 0b0001u32);
}
#[test]
#[target_feature = "+bmi2"]
#[simd_test = "bmi2"]
#[cfg(not(target_arch = "x86"))]
fn _mulx_u64() {
let a: u64 = 9_223_372_036_854_775_800;
let b: u64 = 100;

View file

@ -20,6 +20,9 @@ pub type __m256i = ::v256::i8x32;
#[macro_use]
mod macros;
#[macro_use]
mod runtime;
mod sse;
mod sse2;
mod ssse3;
@ -32,6 +35,3 @@ mod abm;
mod bmi;
mod bmi2;
mod tbm;
#[macro_use]
mod runtime;

View file

@ -2,7 +2,7 @@ use simd_llvm::simd_shuffle4;
use v128::*;
#[cfg(test)]
use assert_instr::assert_instr;
use stdsimd_test::assert_instr;
/// Adds the first component of `a` and `b`, the other components are copied
/// from `a`.
@ -217,13 +217,13 @@ extern {
fn movmskps(a: f32x4) -> i32;
}
#[cfg(all(test, target_feature = "sse", any(target_arch = "x86", target_arch = "x86_64")))]
#[cfg(test)]
mod tests {
use v128::*;
use x86::sse;
use stdsimd_test::simd_test;
#[test]
#[target_feature = "+sse"]
#[simd_test = "sse"]
fn _mm_add_ps() {
let a = f32x4::new(-1.0, 5.0, 0.0, -10.0);
let b = f32x4::new(-100.0, 20.0, 0.0, -5.0);
@ -231,8 +231,7 @@ mod tests {
assert_eq!(r, f32x4::new(-101.0, 25.0, 0.0, -15.0));
}
#[test]
#[target_feature = "+sse"]
#[simd_test = "sse"]
fn _mm_add_ss() {
let a = f32x4::new(-1.0, 5.0, 0.0, -10.0);
let b = f32x4::new(-100.0, 20.0, 0.0, -5.0);
@ -240,8 +239,7 @@ mod tests {
assert_eq!(r, f32x4::new(-101.0, 5.0, 0.0, -10.0));
}
#[test]
#[target_feature = "+sse"]
#[simd_test = "sse"]
fn _mm_sub_ps() {
let a = f32x4::new(-1.0, 5.0, 0.0, -10.0);
let b = f32x4::new(-100.0, 20.0, 0.0, -5.0);
@ -249,8 +247,7 @@ mod tests {
assert_eq!(r, f32x4::new(99.0, -15.0, 0.0, -5.0));
}
#[test]
#[target_feature = "+sse"]
#[simd_test = "sse"]
fn _mm_sub_ss() {
let a = f32x4::new(-1.0, 5.0, 0.0, -10.0);
let b = f32x4::new(-100.0, 20.0, 0.0, -5.0);
@ -258,8 +255,7 @@ mod tests {
assert_eq!(r, f32x4::new(99.0, 5.0, 0.0, -10.0));
}
#[test]
#[target_feature = "+sse"]
#[simd_test = "sse"]
fn _mm_mul_ps() {
let a = f32x4::new(-1.0, 5.0, 0.0, -10.0);
let b = f32x4::new(-100.0, 20.0, 0.0, -5.0);
@ -267,8 +263,7 @@ mod tests {
assert_eq!(r, f32x4::new(100.0, 100.0, 0.0, 50.0));
}
#[test]
#[target_feature = "+sse"]
#[simd_test = "sse"]
fn _mm_mul_ss() {
let a = f32x4::new(-1.0, 5.0, 0.0, -10.0);
let b = f32x4::new(-100.0, 20.0, 0.0, -5.0);
@ -276,8 +271,7 @@ mod tests {
assert_eq!(r, f32x4::new(100.0, 5.0, 0.0, -10.0));
}
#[test]
#[target_feature = "+sse"]
#[simd_test = "sse"]
fn _mm_div_ps() {
let a = f32x4::new(-1.0, 5.0, 2.0, -10.0);
let b = f32x4::new(-100.0, 20.0, 0.2, -5.0);
@ -285,8 +279,7 @@ mod tests {
assert_eq!(r, f32x4::new(0.01, 0.25, 10.0, 2.0));
}
#[test]
#[target_feature = "+sse"]
#[simd_test = "sse"]
fn _mm_div_ss() {
let a = f32x4::new(-1.0, 5.0, 0.0, -10.0);
let b = f32x4::new(-100.0, 20.0, 0.0, -5.0);
@ -294,8 +287,7 @@ mod tests {
assert_eq!(r, f32x4::new(0.01, 5.0, 0.0, -10.0));
}
#[test]
#[target_feature = "+sse"]
#[simd_test = "sse"]
fn _mm_sqrt_ss() {
let a = f32x4::new(4.0, 13.0, 16.0, 100.0);
let r = sse::_mm_sqrt_ss(a);
@ -303,8 +295,7 @@ mod tests {
assert_eq!(r, e);
}
#[test]
#[target_feature = "+sse"]
#[simd_test = "sse"]
fn _mm_sqrt_ps() {
let a = f32x4::new(4.0, 13.0, 16.0, 100.0);
let r = sse::_mm_sqrt_ps(a);
@ -312,8 +303,7 @@ mod tests {
assert_eq!(r, e);
}
#[test]
#[target_feature = "+sse"]
#[simd_test = "sse"]
fn _mm_rcp_ss() {
let a = f32x4::new(4.0, 13.0, 16.0, 100.0);
let r = sse::_mm_rcp_ss(a);
@ -321,8 +311,7 @@ mod tests {
assert_eq!(r, e);
}
#[test]
#[target_feature = "+sse"]
#[simd_test = "sse"]
fn _mm_rcp_ps() {
let a = f32x4::new(4.0, 13.0, 16.0, 100.0);
let r = sse::_mm_rcp_ps(a);
@ -330,8 +319,7 @@ mod tests {
assert_eq!(r, e);
}
#[test]
#[target_feature = "+sse"]
#[simd_test = "sse"]
fn _mm_rsqrt_ss() {
let a = f32x4::new(4.0, 13.0, 16.0, 100.0);
let r = sse::_mm_rsqrt_ss(a);
@ -339,8 +327,7 @@ mod tests {
assert_eq!(r, e);
}
#[test]
#[target_feature = "+sse"]
#[simd_test = "sse"]
fn _mm_rsqrt_ps() {
let a = f32x4::new(4.0, 13.0, 16.0, 100.0);
let r = sse::_mm_rsqrt_ps(a);
@ -348,8 +335,7 @@ mod tests {
assert_eq!(r, e);
}
#[test]
#[target_feature = "+sse"]
#[simd_test = "sse"]
fn _mm_min_ss() {
let a = f32x4::new(-1.0, 5.0, 0.0, -10.0);
let b = f32x4::new(-100.0, 20.0, 0.0, -5.0);
@ -357,8 +343,7 @@ mod tests {
assert_eq!(r, f32x4::new(-100.0, 5.0, 0.0, -10.0));
}
#[test]
#[target_feature = "+sse"]
#[simd_test = "sse"]
fn _mm_min_ps() {
let a = f32x4::new(-1.0, 5.0, 0.0, -10.0);
let b = f32x4::new(-100.0, 20.0, 0.0, -5.0);
@ -366,8 +351,7 @@ mod tests {
assert_eq!(r, f32x4::new(-100.0, 5.0, 0.0, -10.0));
}
#[test]
#[target_feature = "+sse"]
#[simd_test = "sse"]
fn _mm_max_ss() {
let a = f32x4::new(-1.0, 5.0, 0.0, -10.0);
let b = f32x4::new(-100.0, 20.0, 0.0, -5.0);
@ -375,8 +359,7 @@ mod tests {
assert_eq!(r, f32x4::new(-1.0, 5.0, 0.0, -10.0));
}
#[test]
#[target_feature = "+sse"]
#[simd_test = "sse"]
fn _mm_max_ps() {
let a = f32x4::new(-1.0, 5.0, 0.0, -10.0);
let b = f32x4::new(-100.0, 20.0, 0.0, -5.0);
@ -384,8 +367,7 @@ mod tests {
assert_eq!(r, f32x4::new(-1.0, 20.0, 0.0, -5.0));
}
#[test]
#[target_feature = "+sse"]
#[simd_test = "sse"]
fn _mm_unpackhi_ps() {
let a = f32x4::new(1.0, 2.0, 3.0, 4.0);
let b = f32x4::new(5.0, 6.0, 7.0, 8.0);
@ -393,8 +375,7 @@ mod tests {
assert_eq!(r, f32x4::new(3.0, 7.0, 4.0, 8.0));
}
#[test]
#[target_feature = "+sse"]
#[simd_test = "sse"]
fn _mm_movemask_ps() {
let r = sse::_mm_movemask_ps(f32x4::new(-1.0, 5.0, -5.0, 0.0));
assert_eq!(r, 0b0101);

File diff suppressed because it is too large Load diff

View file

@ -57,13 +57,14 @@ extern {
fn dpps(a: f32x4, b: f32x4, imm8: u8) -> f32x4;
}
#[cfg(all(test, target_feature = "sse4.1", any(target_arch = "x86", target_arch = "x86_64")))]
#[cfg(test)]
mod tests {
use stdsimd_test::simd_test;
use v128::*;
use x86::sse41;
#[test]
#[target_feature = "+sse4.1"]
#[simd_test = "sse4.1"]
fn _mm_blendv_epi8() {
let a = i8x16::new(
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
@ -76,8 +77,7 @@ mod tests {
assert_eq!(sse41::_mm_blendv_epi8(a, b, mask), e);
}
#[test]
#[target_feature = "+sse4.1"]
#[simd_test = "sse4.1"]
fn _mm_dp_pd() {
let a = f64x2::new(2.0, 3.0);
let b = f64x2::new(1.0, 4.0);
@ -85,8 +85,7 @@ mod tests {
assert_eq!(sse41::_mm_dp_pd(a, b, 0b00110001), e);
}
#[test]
#[target_feature = "+sse4.1"]
#[simd_test = "sse4.1"]
fn _mm_dp_ps() {
let a = f32x4::new(2.0, 3.0, 1.0, 10.0);
let b = f32x4::new(1.0, 4.0, 0.5, 10.0);

View file

@ -40,13 +40,14 @@ extern {
fn pcmpestri128(a: __m128i, la: i32, b: __m128i, lb: i32, imm8: i8) -> i32;
}
#[cfg(all(test, target_feature = "sse4.2", any(target_arch = "x86", target_arch = "x86_64")))]
#[cfg(test)]
mod tests {
use stdsimd_test::simd_test;
use v128::*;
use x86::{__m128i, sse42};
#[test]
#[target_feature = "+sse4.2"]
#[simd_test = "sse4.2"]
fn _mm_cmpestri() {
let a = &b"bar "[..];
let b = &b"foobar "[..];

View file

@ -50,20 +50,20 @@ extern {
fn pshufb128(a: u8x16, b: u8x16) -> u8x16;
}
#[cfg(all(test, target_feature = "ssse3", any(target_arch = "x86", target_arch = "x86_64")))]
#[cfg(test)]
mod tests {
use stdsimd_test::simd_test;
use v128::*;
use x86::ssse3 as ssse3;
#[test]
#[target_feature = "+ssse3"]
#[simd_test = "ssse3"]
fn _mm_abs_epi8() {
let r = ssse3::_mm_abs_epi8(i8x16::splat(-5));
assert_eq!(r, u8x16::splat(5));
}
#[test]
#[target_feature = "+ssse3"]
#[simd_test = "ssse3"]
fn _mm_shuffle_epi8() {
let a = u8x16::new(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
let b = u8x16::new(4, 128, 4, 3, 24, 12, 6, 19, 12, 5, 5, 10, 4, 1, 8, 0);

View file

@ -8,7 +8,7 @@
//! provides a quick overview of the available instructions.
#[cfg(test)]
use assert_instr::assert_instr;
use stdsimd_test::assert_instr;
// TODO: LLVM-CODEGEN ERROR: LLVM ERROR: Cannot select: intrinsic %llvm.x86.tbm.bextri.u32
/*
@ -252,40 +252,38 @@ pub fn _tzmsk_u64(x: u64) -> u64 {
!x & (x.wrapping_sub(1))
}
#[cfg(all(test, target_feature = "tbm", any(target_arch = "x86", target_arch = "x86_64")))]
#[cfg(test)]
mod tests {
use stdsimd_test::simd_test;
use x86::tbm;
/*
#[test]
#[target_feature = "+tbm"]
#[simd_test = "tbm"]
fn _bextr_u32() {
assert_eq!(tbm::_bextr_u32(0b0101_0000u32, 4, 4), 0b0000_0101u32);
}
#[test]
#[target_feature = "+tbm"]
#[simd_test = "tbm"]
fn _bextr_u64() {
assert_eq!(tbm::_bextr_u64(0b0101_0000u64, 4, 4), 0b0000_0101u64);
}
*/
#[test]
#[target_feature = "+tbm"]
#[simd_test = "tbm"]
fn _blcfill_u32() {
assert_eq!(tbm::_blcfill_u32(0b0101_0111u32), 0b0101_0000u32);
assert_eq!(tbm::_blcfill_u32(0b1111_1111u32), 0u32);
}
#[test]
#[target_feature = "+tbm"]
#[simd_test = "tbm"]
#[cfg(not(target_arch = "x86"))]
fn _blcfill_u64() {
assert_eq!(tbm::_blcfill_u64(0b0101_0111u64), 0b0101_0000u64);
assert_eq!(tbm::_blcfill_u64(0b1111_1111u64), 0u64);
}
#[test]
#[target_feature = "+tbm"]
#[simd_test = "tbm"]
fn _blci_u32() {
assert_eq!(tbm::_blci_u32(0b0101_0000u32),
0b1111_1111_1111_1111_1111_1111_1111_1110u32);
@ -293,8 +291,8 @@ mod tests {
0b1111_1111_1111_1111_1111_1110_1111_1111u32);
}
#[test]
#[target_feature = "+tbm"]
#[simd_test = "tbm"]
#[cfg(not(target_arch = "x86"))]
fn _blci_u64() {
assert_eq!(tbm::_blci_u64(0b0101_0000u64),
0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1110u64);
@ -302,99 +300,92 @@ mod tests {
0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1110_1111_1111u64);
}
#[test]
#[target_feature = "+tbm"]
#[simd_test = "tbm"]
fn _blcic_u32() {
assert_eq!(tbm::_blcic_u32(0b0101_0001u32), 0b0000_0010u32);
assert_eq!(tbm::_blcic_u32(0b1111_1111u32), 0b1_0000_0000u32);
}
#[test]
#[target_feature = "+tbm"]
#[simd_test = "tbm"]
#[cfg(not(target_arch = "x86"))]
fn _blcic_u64() {
assert_eq!(tbm::_blcic_u64(0b0101_0001u64), 0b0000_0010u64);
assert_eq!(tbm::_blcic_u64(0b1111_1111u64), 0b1_0000_0000u64);
}
#[test]
#[target_feature = "+tbm"]
#[simd_test = "tbm"]
fn _blcmsk_u32() {
assert_eq!(tbm::_blcmsk_u32(0b0101_0001u32), 0b0000_0011u32);
assert_eq!(tbm::_blcmsk_u32(0b1111_1111u32), 0b1_1111_1111u32);
}
#[test]
#[target_feature = "+tbm"]
#[simd_test = "tbm"]
#[cfg(not(target_arch = "x86"))]
fn _blcmsk_u64() {
assert_eq!(tbm::_blcmsk_u64(0b0101_0001u64), 0b0000_0011u64);
assert_eq!(tbm::_blcmsk_u64(0b1111_1111u64), 0b1_1111_1111u64);
}
#[test]
#[target_feature = "+tbm"]
#[simd_test = "tbm"]
fn _blcs_u32() {
assert_eq!(tbm::_blcs_u32(0b0101_0001u32), 0b0101_0011u32);
assert_eq!(tbm::_blcs_u32(0b1111_1111u32), 0b1_1111_1111u32);
}
#[test]
#[target_feature = "+tbm"]
#[simd_test = "tbm"]
#[cfg(not(target_arch = "x86"))]
fn _blcs_u64() {
assert_eq!(tbm::_blcs_u64(0b0101_0001u64), 0b0101_0011u64);
assert_eq!(tbm::_blcs_u64(0b1111_1111u64), 0b1_1111_1111u64);
}
#[test]
#[target_feature = "+tbm"]
#[simd_test = "tbm"]
fn _blsfill_u32() {
assert_eq!(tbm::_blsfill_u32(0b0101_0100u32), 0b0101_0111u32);
assert_eq!(tbm::_blsfill_u32(0u32), 0b1111_1111_1111_1111_1111_1111_1111_1111u32);
}
#[test]
#[target_feature = "+tbm"]
#[simd_test = "tbm"]
#[cfg(not(target_arch = "x86"))]
fn _blsfill_u64() {
assert_eq!(tbm::_blsfill_u64(0b0101_0100u64), 0b0101_0111u64);
assert_eq!(tbm::_blsfill_u64(0u64), 0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111u64);
}
#[test]
#[target_feature = "+tbm"]
#[simd_test = "tbm"]
fn _blsic_u32() {
assert_eq!(tbm::_blsic_u32(0b0101_0100u32), 0b1111_1111_1111_1111_1111_1111_1111_1011u32);
assert_eq!(tbm::_blsic_u32(0u32), 0b1111_1111_1111_1111_1111_1111_1111_1111u32);
}
#[test]
#[target_feature = "+tbm"]
#[simd_test = "tbm"]
#[cfg(not(target_arch = "x86"))]
fn _blsic_u64() {
assert_eq!(tbm::_blsic_u64(0b0101_0100u64), 0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1011u64);
assert_eq!(tbm::_blsic_u64(0u64), 0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111u64);
}
#[test]
#[target_feature = "+tbm"]
#[simd_test = "tbm"]
fn _t1mskc_u32() {
assert_eq!(tbm::_t1mskc_u32(0b0101_0111u32), 0b1111_1111_1111_1111_1111_1111_1111_1000u32);
assert_eq!(tbm::_t1mskc_u32(0u32), 0b1111_1111_1111_1111_1111_1111_1111_1111u32);
}
#[test]
#[target_feature = "+tbm"]
#[simd_test = "tbm"]
#[cfg(not(target_arch = "x86"))]
fn _t1mksc_u64() {
assert_eq!(tbm::_t1mskc_u64(0b0101_0111u64), 0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1000u64);
assert_eq!(tbm::_t1mskc_u64(0u64), 0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111u64);
}
#[test]
#[target_feature = "+tbm"]
#[simd_test = "tbm"]
fn _tzmsk_u32() {
assert_eq!(tbm::_tzmsk_u32(0b0101_1000u32), 0b0000_0111u32);
assert_eq!(tbm::_tzmsk_u32(0b0101_1001u32), 0b0000_0000u32);
}
#[test]
#[target_feature = "+tbm"]
#[simd_test = "tbm"]
#[cfg(not(target_arch = "x86"))]
fn _tzmsk_u64() {
assert_eq!(tbm::_tzmsk_u64(0b0101_1000u64), 0b0000_0111u64);
assert_eq!(tbm::_tzmsk_u64(0b0101_1001u64), 0b0000_0000u64);

View file

@ -1,10 +1,11 @@
[package]
name = "assert-instr"
name = "stdsimd-test"
version = "0.1.0"
authors = ["Alex Crichton <alex@alexcrichton.com>"]
[dependencies]
assert-instr-macro = { path = "assert-instr-macro" }
simd-test-macro = { path = "simd-test-macro" }
backtrace = "0.3"
cc = "1.0"
lazy_static = "0.2"

View file

@ -44,7 +44,7 @@ pub fn assert_instr(attr: TokenStream, item: TokenStream) -> TokenStream {
#[allow(non_snake_case)]
{ignore}
fn assert_instr_{name}() {{
::assert_instr::assert({name} as usize,
::stdsimd_test::assert({name} as usize,
\"{name}\",
\"{instr}\");
}}

View file

@ -0,0 +1,11 @@
[package]
name = "simd-test-macro"
version = "0.1.0"
authors = ["Alex Crichton <alex@alexcrichton.com>"]
[lib]
proc-macro = true
[dependencies]
proc-macro2 = { version = "0.1", features = ["unstable"] }
quote = { git = 'https://github.com/dtolnay/quote' }

View file

@ -0,0 +1,76 @@
//! Implementation of the `#[simd_test]` macro
//!
//! This macro expands to a `#[test]` function which tests the local machine for
//! the appropriate cfg before calling the inner test function.
#![feature(proc_macro)]
#[macro_use]
extern crate quote;
extern crate proc_macro;
extern crate proc_macro2;
use proc_macro2::{TokenStream, Term, TokenNode, TokenTree};
use proc_macro2::Literal;
fn string(s: &str) -> TokenTree {
TokenTree {
kind: TokenNode::Literal(Literal::string(s)),
span: Default::default(),
}
}
#[proc_macro_attribute]
pub fn simd_test(attr: proc_macro::TokenStream,
item: proc_macro::TokenStream) -> proc_macro::TokenStream {
let tokens = TokenStream::from(attr).into_iter().collect::<Vec<_>>();
if tokens.len() != 2 {
panic!("expected #[simd_test = \"feature\"]");
}
match tokens[0].kind {
TokenNode::Op('=', _) => {}
_ => panic!("expected #[simd_test = \"feature\"]"),
}
let target_feature = &tokens[1];
let enable_feature = match tokens[1].kind {
TokenNode::Literal(ref l) => l.to_string(),
_ => panic!("expected #[simd_test = \"feature\"]"),
};
let enable_feature = enable_feature.trim_left_matches('"')
.trim_right_matches('"');
let enable_feature = string(&format!("+{}", enable_feature));
let item = TokenStream::from(item);
let name = find_name(item.clone());
let name: TokenStream = name.as_str().parse().unwrap();
let ret: TokenStream = quote! {
#[test]
fn #name() {
if cfg_feature_enabled!(#target_feature) {
return #name();
}
#[target_feature = #enable_feature]
#item
}
}.into();
ret.into()
}
fn find_name(item: TokenStream) -> Term {
let mut tokens = item.into_iter();
while let Some(tok) = tokens.next() {
if let TokenNode::Term(word) = tok.kind {
if word.as_str() == "fn" {
break
}
}
}
match tokens.next().map(|t| t.kind) {
Some(TokenNode::Term(word)) => word,
_ => panic!("failed to find function name"),
}
}

View file

@ -1,4 +1,4 @@
//! Runtime support needed for the `#![assert_instr]` macro
//! Runtime support needed for testing the stdsimd crate.
//!
//! This basically just disassembles the current executable and then parses the
//! output once globally and then provides the `assert` function which makes
@ -7,6 +7,7 @@
#![feature(proc_macro)]
extern crate assert_instr_macro;
extern crate simd_test_macro;
extern crate backtrace;
extern crate cc;
extern crate rustc_demangle;
@ -19,6 +20,7 @@ use std::process::Command;
use std::str;
pub use assert_instr_macro::*;
pub use simd_test_macro::*;
lazy_static! {
static ref DISASSEMBLY: HashMap<String, Vec<Function>> = disassemble_myself();