Skip to content

Commit 338a9df

Browse files
committed
Always test intrinsics unconditionally
This commit alters the test suite to unconditionally compile and run all tests, regardless of the ambient target features enabled. This then uses a new convenience macro, `#[simd_test]`, to guard all tests with the appropriate `cfg_feature_enabled!` and also enable the `#[target_feature]` appropriately.
1 parent 411e125 commit 338a9df

File tree

25 files changed

+519
-563
lines changed

25 files changed

+519
-563
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ debug = true
1919
opt-level = 3
2020

2121
[dev-dependencies]
22-
assert-instr = { path = "assert-instr" }
22+
stdsimd-test = { path = "stdsimd-test" }

src/arm/v6.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//! Manual](http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0419c/index.html).
55
66
#[cfg(test)]
7-
use assert_instr::assert_instr;
7+
use stdsimd_test::assert_instr;
88

99
/// Reverse the order of the bytes.
1010
#[inline(always)]

src/arm/v7.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
pub use super::v6::*;
77

88
#[cfg(test)]
9-
use assert_instr::assert_instr;
9+
use stdsimd_test::assert_instr;
1010

1111
/// Count Leading Zeros.
1212
#[inline(always)]

src/arm/v8.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
pub use super::v7::*;
66

77
#[cfg(test)]
8-
use assert_instr::assert_instr;
8+
use stdsimd_test::assert_instr;
99

1010
/// Reverse the order of the bytes.
1111
#[inline(always)]

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
#![cfg_attr(test, feature(proc_macro))]
9090

9191
#[cfg(test)]
92-
extern crate assert_instr;
92+
extern crate stdsimd_test;
9393

9494
/// Platform independent SIMD vector types and operations.
9595
pub mod simd {

src/macros.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ macro_rules! define_impl {
2323
$($elname:ident),+
2424
) => {
2525
impl $name {
26-
#[inline]
26+
#[inline(always)]
2727
pub fn new($($elname: $elemty),*) -> $name {
2828
$name($($elname),*)
2929
}
3030

31-
#[inline]
31+
#[inline(always)]
3232
pub fn splat(value: $elemty) -> $name {
3333
$name($({
3434
#[allow(non_camel_case_types, dead_code)]
@@ -37,25 +37,25 @@ macro_rules! define_impl {
3737
}),*)
3838
}
3939

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

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

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

58-
#[inline]
58+
#[inline(always)]
5959
pub unsafe fn store_unchecked(
6060
self,
6161
slice: &mut [$elemty],
@@ -70,13 +70,13 @@ macro_rules! define_impl {
7070
size_of::<$name>());
7171
}
7272

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

79-
#[inline]
79+
#[inline(always)]
8080
pub unsafe fn load_unchecked(
8181
slice: &[$elemty],
8282
offset: usize,
@@ -92,32 +92,32 @@ macro_rules! define_impl {
9292
x
9393
}
9494

95-
#[inline]
95+
#[inline(always)]
9696
pub fn eq(self, other: $name) -> $boolname {
9797
unsafe { simd_eq(self, other) }
9898
}
9999

100-
#[inline]
100+
#[inline(always)]
101101
pub fn ne(self, other: $name) -> $boolname {
102102
unsafe { simd_ne(self, other) }
103103
}
104104

105-
#[inline]
105+
#[inline(always)]
106106
pub fn lt(self, other: $name) -> $boolname {
107107
unsafe { simd_lt(self, other) }
108108
}
109109

110-
#[inline]
110+
#[inline(always)]
111111
pub fn le(self, other: $name) -> $boolname {
112112
unsafe { simd_le(self, other) }
113113
}
114114

115-
#[inline]
115+
#[inline(always)]
116116
pub fn gt(self, other: $name) -> $boolname {
117117
unsafe { simd_gt(self, other) }
118118
}
119119

120-
#[inline]
120+
#[inline(always)]
121121
pub fn ge(self, other: $name) -> $boolname {
122122
unsafe { simd_ge(self, other) }
123123
}
@@ -129,6 +129,7 @@ macro_rules! define_from {
129129
($to:ident, $($from:ident),+) => {
130130
$(
131131
impl From<$from> for $to {
132+
#[inline(always)]
132133
fn from(f: $from) -> $to {
133134
unsafe { ::std::mem::transmute(f) }
134135
}
@@ -259,7 +260,7 @@ macro_rules! define_casts {
259260
($(($fromty:ident, $toty:ident, $cast:ident)),+) => {
260261
$(
261262
impl $fromty {
262-
#[inline]
263+
#[inline(always)]
263264
pub fn $cast(self) -> ::simd::$toty {
264265
unsafe { simd_cast(self) }
265266
}

src/x86/abm.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//! provides a quick overview of the instructions available.
1212
1313
#[cfg(test)]
14-
use assert_instr::assert_instr;
14+
use stdsimd_test::assert_instr;
1515

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

44-
#[cfg(all(test, target_feature = "bmi", any(target_arch = "x86", target_arch = "x86_64")))]
44+
#[cfg(test)]
4545
mod tests {
46+
use stdsimd_test::simd_test;
47+
4648
use x86::abm;
4749

48-
#[test]
49-
#[target_feature = "+lzcnt"]
50+
#[simd_test = "lzcnt"]
5051
fn _lzcnt_u32() {
5152
assert_eq!(abm::_lzcnt_u32(0b0101_1010u32), 25u32);
5253
}
5354

54-
#[test]
55-
#[target_feature = "+lzcnt"]
55+
#[simd_test = "lzcnt"]
5656
fn _lzcnt_u64() {
5757
assert_eq!(abm::_lzcnt_u64(0b0101_1010u64), 57u64);
5858
}
5959

60-
#[test]
61-
#[target_feature = "+popcnt"]
60+
#[simd_test = "popcnt"]
6261
fn _popcnt32() {
6362
assert_eq!(abm::_popcnt32(0b0101_1010u32), 4);
6463
}
6564

66-
#[test]
67-
#[target_feature = "+popcnt"]
65+
#[simd_test = "popcnt"]
6866
fn _popcnt64() {
6967
assert_eq!(abm::_popcnt64(0b0101_1010u64), 4);
7068
}

src/x86/avx.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ extern "C" {
3030
fn addsubpd256(a: f64x4, b:f64x4) -> f64x4;
3131
}
3232

33-
34-
#[cfg(all(test, target_feature = "avx", any(target_arch = "x86", target_arch = "x86_64")))]
33+
#[cfg(test)]
3534
mod tests {
35+
use stdsimd_test::simd_test;
36+
3637
use v256::*;
3738
use x86::avx;
3839

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

49-
#[test]
50-
#[target_feature = "+avx"]
49+
#[simd_test = "avx"]
5150
fn _mm256_add_ps() {
5251
let a = f32x8::new(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0);
5352
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 {
5655
assert_eq!(r, e);
5756
}
5857

59-
#[test]
60-
#[target_feature = "+avx"]
58+
#[simd_test = "avx"]
6159
fn _mm256_addsub_pd() {
6260
let a = f64x4::new(1.0, 2.0, 3.0, 4.0);
6361
let b = f64x4::new(5.0, 6.0, 7.0, 8.0);

0 commit comments

Comments
 (0)