Skip to content

Commit 4126bdc

Browse files
gnzlbgalexcrichton
authored andcommitted
add tests for endian-dependent behavior (rust-lang#394)
* add tests for endian-dependent behavior * format
1 parent a063a59 commit 4126bdc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1883
-832
lines changed

coresimd/mips/msa.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ extern "C" {
1717

1818
/// Vector Add Absolute Values.
1919
///
20-
/// Adds the absolute values of the elements in `a` and `b` into the result vector.
20+
/// Adds the absolute values of the elements in `a` and `b` into the result
21+
/// vector.
2122
#[inline]
2223
#[target_feature(enable = "msa")]
2324
#[cfg_attr(test, assert_instr(add_a.b))]

coresimd/ppsv/api/arithmetic_ops.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#![allow(unused)]
33

44
macro_rules! impl_arithmetic_ops {
5-
($id:ident) => {
5+
($id: ident) => {
66
impl ::ops::Add for $id {
77
type Output = Self;
88
#[inline]
@@ -82,15 +82,15 @@ macro_rules! impl_arithmetic_ops {
8282
*self = *self % other;
8383
}
8484
}
85-
}
85+
};
8686
}
8787

8888
#[cfg(test)]
8989
macro_rules! test_arithmetic_ops {
90-
($id:ident, $elem_ty:ident) => {
90+
($id: ident, $elem_ty: ident) => {
9191
#[test]
9292
fn arithmetic() {
93-
use ::coresimd::simd::$id;
93+
use coresimd::simd::$id;
9494
let z = $id::splat(0 as $elem_ty);
9595
let o = $id::splat(1 as $elem_ty);
9696
let t = $id::splat(2 as $elem_ty);
@@ -126,7 +126,7 @@ macro_rules! test_arithmetic_ops {
126126
{
127127
let mut v = z;
128128
assert_eq!(v, z);
129-
v += o; // add_assign
129+
v += o; // add_assign
130130
assert_eq!(v, o);
131131
v -= o; // sub_assign
132132
assert_eq!(v, z);

coresimd/ppsv/api/arithmetic_reductions.rs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#![allow(unused)]
33

44
macro_rules! impl_arithmetic_reductions {
5-
($id:ident, $elem_ty:ident) => {
5+
($id: ident, $elem_ty: ident) => {
66
impl $id {
77
/// Lane-wise addition of the vector elements.
88
///
@@ -12,10 +12,8 @@ macro_rules! impl_arithmetic_reductions {
1212
#[cfg(not(target_arch = "aarch64"))]
1313
#[inline]
1414
pub fn sum(self) -> $elem_ty {
15-
use ::coresimd::simd_llvm::simd_reduce_add_ordered;
16-
unsafe {
17-
simd_reduce_add_ordered(self, 0 as $elem_ty)
18-
}
15+
use coresimd::simd_llvm::simd_reduce_add_ordered;
16+
unsafe { simd_reduce_add_ordered(self, 0 as $elem_ty) }
1917
}
2018
/// Lane-wise addition of the vector elements.
2119
///
@@ -42,10 +40,8 @@ macro_rules! impl_arithmetic_reductions {
4240
#[cfg(not(target_arch = "aarch64"))]
4341
#[inline]
4442
pub fn product(self) -> $elem_ty {
45-
use ::coresimd::simd_llvm::simd_reduce_mul_ordered;
46-
unsafe {
47-
simd_reduce_mul_ordered(self, 1 as $elem_ty)
48-
}
43+
use coresimd::simd_llvm::simd_reduce_mul_ordered;
44+
unsafe { simd_reduce_mul_ordered(self, 1 as $elem_ty) }
4945
}
5046
/// Lane-wise multiplication of the vector elements.
5147
///
@@ -64,15 +60,14 @@ macro_rules! impl_arithmetic_reductions {
6460
x
6561
}
6662
}
67-
}
63+
};
6864
}
6965

7066
#[cfg(test)]
7167
macro_rules! test_arithmetic_reductions {
72-
($id:ident, $elem_ty:ident) => {
73-
68+
($id: ident, $elem_ty: ident) => {
7469
fn alternating(x: usize) -> ::coresimd::simd::$id {
75-
use ::coresimd::simd::$id;
70+
use coresimd::simd::$id;
7671
let mut v = $id::splat(1 as $elem_ty);
7772
for i in 0..$id::lanes() {
7873
if i % x == 0 {
@@ -84,17 +79,20 @@ macro_rules! test_arithmetic_reductions {
8479

8580
#[test]
8681
fn sum() {
87-
use ::coresimd::simd::$id;
82+
use coresimd::simd::$id;
8883
let v = $id::splat(0 as $elem_ty);
8984
assert_eq!(v.sum(), 0 as $elem_ty);
9085
let v = $id::splat(1 as $elem_ty);
9186
assert_eq!(v.sum(), $id::lanes() as $elem_ty);
9287
let v = alternating(2);
93-
assert_eq!(v.sum(), ($id::lanes() / 2 + $id::lanes()) as $elem_ty);
88+
assert_eq!(
89+
v.sum(),
90+
($id::lanes() / 2 + $id::lanes()) as $elem_ty
91+
);
9492
}
9593
#[test]
9694
fn product() {
97-
use ::coresimd::simd::$id;
95+
use coresimd::simd::$id;
9896
let v = $id::splat(0 as $elem_ty);
9997
assert_eq!(v.product(), 0 as $elem_ty);
10098
let v = $id::splat(1 as $elem_ty);
@@ -106,7 +104,10 @@ macro_rules! test_arithmetic_reductions {
106104
_ => 2,
107105
};
108106
let v = alternating(f);
109-
assert_eq!(v.product(), (2_usize.pow(($id::lanes() / f) as u32) as $elem_ty));
107+
assert_eq!(
108+
v.product(),
109+
(2_usize.pow(($id::lanes() / f) as u32) as $elem_ty)
110+
);
110111
}
111-
}
112+
};
112113
}

coresimd/ppsv/api/arithmetic_scalar_ops.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#![allow(unused)]
33

44
macro_rules! impl_arithmetic_scalar_ops {
5-
($id:ident, $elem_ty:ident) => {
5+
($id: ident, $elem_ty: ident) => {
66
impl ::ops::Add<$elem_ty> for $id {
77
type Output = Self;
88
#[inline]
@@ -112,15 +112,15 @@ macro_rules! impl_arithmetic_scalar_ops {
112112
*self = *self % other;
113113
}
114114
}
115-
}
115+
};
116116
}
117117

118118
#[cfg(test)]
119119
macro_rules! test_arithmetic_scalar_ops {
120-
($id:ident, $elem_ty:ident) => {
120+
($id: ident, $elem_ty: ident) => {
121121
#[test]
122122
fn arithmetic_scalar() {
123-
use ::coresimd::simd::$id;
123+
use coresimd::simd::$id;
124124
let zi = 0 as $elem_ty;
125125
let oi = 1 as $elem_ty;
126126
let ti = 2 as $elem_ty;
@@ -181,7 +181,7 @@ macro_rules! test_arithmetic_scalar_ops {
181181
{
182182
let mut v = z;
183183
assert_eq!(v, z);
184-
v += oi; // add_assign
184+
v += oi; // add_assign
185185
assert_eq!(v, o);
186186
v -= oi; // sub_assign
187187
assert_eq!(v, z);

coresimd/ppsv/api/bitwise_ops.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#![allow(unused)]
33

44
macro_rules! impl_bitwise_ops {
5-
($id:ident, $true_val:expr) => {
5+
($id: ident, $true_val: expr) => {
66
impl ::ops::Not for $id {
77
type Output = Self;
88
#[inline]
@@ -57,10 +57,10 @@ macro_rules! impl_bitwise_ops {
5757

5858
#[cfg(test)]
5959
macro_rules! test_int_bitwise_ops {
60-
($id:ident, $elem_ty:ident) => {
60+
($id: ident, $elem_ty: ident) => {
6161
#[test]
6262
fn bitwise_ops() {
63-
use ::coresimd::simd::$id;
63+
use coresimd::simd::$id;
6464
let z = $id::splat(0 as $elem_ty);
6565
let o = $id::splat(1 as $elem_ty);
6666
let t = $id::splat(2 as $elem_ty);
@@ -100,31 +100,34 @@ macro_rules! test_int_bitwise_ops {
100100
assert_eq!(t ^ z, t);
101101
assert_eq!(z ^ t, t);
102102

103-
{ // AndAssign:
103+
{
104+
// AndAssign:
104105
let mut v = o;
105106
v &= t;
106107
assert_eq!(v, z);
107108
}
108-
{ // OrAssign:
109+
{
110+
// OrAssign:
109111
let mut v = z;
110112
v |= o;
111113
assert_eq!(v, o);
112114
}
113-
{ // XORAssign:
115+
{
116+
// XORAssign:
114117
let mut v = z;
115118
v ^= o;
116119
assert_eq!(v, o);
117120
}
118121
}
119-
}
122+
};
120123
}
121124

122125
#[cfg(test)]
123126
macro_rules! test_bool_bitwise_ops {
124-
($id:ident) => {
127+
($id: ident) => {
125128
#[test]
126129
fn bool_arithmetic() {
127-
use ::coresimd::simd::*;
130+
use coresimd::simd::*;
128131

129132
let t = $id::splat(true);
130133
let f = $id::splat(false);
@@ -153,21 +156,24 @@ macro_rules! test_bool_bitwise_ops {
153156
assert_eq!(t ^ t, f);
154157
assert_eq!(f ^ f, f);
155158

156-
{ // AndAssign:
159+
{
160+
// AndAssign:
157161
let mut v = f;
158162
v &= t;
159163
assert_eq!(v, f);
160164
}
161-
{ // OrAssign:
165+
{
166+
// OrAssign:
162167
let mut v = f;
163168
v |= t;
164169
assert_eq!(v, t);
165170
}
166-
{ // XORAssign:
171+
{
172+
// XORAssign:
167173
let mut v = f;
168174
v ^= t;
169175
assert_eq!(v, t);
170176
}
171177
}
172-
}
178+
};
173179
}

coresimd/ppsv/api/bitwise_reductions.rs

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22
#![allow(unused)]
33

44
macro_rules! impl_bitwise_reductions {
5-
($id:ident, $elem_ty:ident) => {
5+
($id: ident, $elem_ty: ident) => {
66
impl $id {
77
/// Lane-wise bitwise `and` of the vector elements.
88
#[cfg(not(target_arch = "aarch64"))]
99
#[inline]
1010
pub fn and(self) -> $elem_ty {
11-
use ::coresimd::simd_llvm::simd_reduce_and;
12-
unsafe {
13-
simd_reduce_and(self)
14-
}
11+
use coresimd::simd_llvm::simd_reduce_and;
12+
unsafe { simd_reduce_and(self) }
1513
}
1614
/// Lane-wise bitwise `and` of the vector elements.
1715
#[cfg(target_arch = "aarch64")]
@@ -30,10 +28,8 @@ macro_rules! impl_bitwise_reductions {
3028
#[cfg(not(target_arch = "aarch64"))]
3129
#[inline]
3230
pub fn or(self) -> $elem_ty {
33-
use ::coresimd::simd_llvm::simd_reduce_or;
34-
unsafe {
35-
simd_reduce_or(self)
36-
}
31+
use coresimd::simd_llvm::simd_reduce_or;
32+
unsafe { simd_reduce_or(self) }
3733
}
3834
/// Lane-wise bitwise `or` of the vector elements.
3935
#[cfg(target_arch = "aarch64")]
@@ -52,10 +48,8 @@ macro_rules! impl_bitwise_reductions {
5248
#[cfg(not(target_arch = "aarch64"))]
5349
#[inline]
5450
pub fn xor(self) -> $elem_ty {
55-
use ::coresimd::simd_llvm::simd_reduce_xor;
56-
unsafe {
57-
simd_reduce_xor(self)
58-
}
51+
use coresimd::simd_llvm::simd_reduce_xor;
52+
unsafe { simd_reduce_xor(self) }
5953
}
6054
/// Lane-wise bitwise `xor` of the vector elements.
6155
#[cfg(target_arch = "aarch64")]
@@ -70,17 +64,17 @@ macro_rules! impl_bitwise_reductions {
7064
x
7165
}
7266
}
73-
}
67+
};
7468
}
7569

7670
macro_rules! impl_bool_bitwise_reductions {
77-
($id:ident, $elem_ty:ident, $internal_ty:ident) => {
71+
($id: ident, $elem_ty: ident, $internal_ty: ident) => {
7872
impl $id {
7973
/// Lane-wise bitwise `and` of the vector elements.
8074
#[cfg(not(target_arch = "aarch64"))]
8175
#[inline]
8276
pub fn and(self) -> $elem_ty {
83-
use ::coresimd::simd_llvm::simd_reduce_and;
77+
use coresimd::simd_llvm::simd_reduce_and;
8478
unsafe {
8579
let r: $internal_ty = simd_reduce_and(self);
8680
r != 0
@@ -103,7 +97,7 @@ macro_rules! impl_bool_bitwise_reductions {
10397
#[cfg(not(target_arch = "aarch64"))]
10498
#[inline]
10599
pub fn or(self) -> $elem_ty {
106-
use ::coresimd::simd_llvm::simd_reduce_or;
100+
use coresimd::simd_llvm::simd_reduce_or;
107101
unsafe {
108102
let r: $internal_ty = simd_reduce_or(self);
109103
r != 0
@@ -126,7 +120,7 @@ macro_rules! impl_bool_bitwise_reductions {
126120
#[cfg(not(target_arch = "aarch64"))]
127121
#[inline]
128122
pub fn xor(self) -> $elem_ty {
129-
use ::coresimd::simd_llvm::simd_reduce_xor;
123+
use coresimd::simd_llvm::simd_reduce_xor;
130124
unsafe {
131125
let r: $internal_ty = simd_reduce_xor(self);
132126
r != 0
@@ -145,16 +139,16 @@ macro_rules! impl_bool_bitwise_reductions {
145139
x
146140
}
147141
}
148-
}
142+
};
149143
}
150144

151145
#[cfg(test)]
152146
macro_rules! test_bitwise_reductions {
153-
($id:ident, $true:expr) => {
147+
($id: ident, $true: expr) => {
154148
#[test]
155149
fn and() {
156150
let false_ = !$true;
157-
use ::coresimd::simd::$id;
151+
use coresimd::simd::$id;
158152
let v = $id::splat(false_);
159153
assert_eq!(v.and(), false_);
160154
let v = $id::splat($true);
@@ -169,7 +163,7 @@ macro_rules! test_bitwise_reductions {
169163
#[test]
170164
fn or() {
171165
let false_ = !$true;
172-
use ::coresimd::simd::$id;
166+
use coresimd::simd::$id;
173167
let v = $id::splat(false_);
174168
assert_eq!(v.or(), false_);
175169
let v = $id::splat($true);
@@ -184,7 +178,7 @@ macro_rules! test_bitwise_reductions {
184178
#[test]
185179
fn xor() {
186180
let false_ = !$true;
187-
use ::coresimd::simd::$id;
181+
use coresimd::simd::$id;
188182
let v = $id::splat(false_);
189183
assert_eq!(v.xor(), false_);
190184
let v = $id::splat($true);
@@ -196,5 +190,5 @@ macro_rules! test_bitwise_reductions {
196190
let v = v.replace(0, false_);
197191
assert_eq!(v.xor(), $true);
198192
}
199-
}
193+
};
200194
}

0 commit comments

Comments
 (0)