Skip to content

Commit 5bd2b16

Browse files
gnzlbgalexcrichton
authored andcommitted
[arm] v6/v7/v8 run-time tests (rust-lang#119)
1 parent 9679514 commit 5bd2b16

File tree

3 files changed

+110
-0
lines changed

3 files changed

+110
-0
lines changed

src/arm/v6.rs

+23
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,26 @@ pub unsafe fn _rev_u16(x: u16) -> u16 {
1919
pub unsafe fn _rev_u32(x: u32) -> u32 {
2020
x.swap_bytes() as u32
2121
}
22+
23+
#[cfg(test)]
24+
mod tests {
25+
use stdsimd_test::simd_test;
26+
27+
use arm::v6;
28+
29+
#[test]
30+
fn _rev_u16() {
31+
unsafe {
32+
assert_eq!(v6::_rev_u16(0b0000_0000_1111_1111_u16), 0b1111_1111_0000_0000_u16);
33+
}
34+
}
35+
36+
#[test]
37+
fn _rev_u32() {
38+
unsafe {
39+
assert_eq!(v6::_rev_u32(
40+
0b0000_0000_1111_1111_0000_0000_1111_1111_u32
41+
), 0b1111_1111_0000_0000_1111_1111_0000_0000_u32);
42+
}
43+
}
44+
}

src/arm/v7.rs

+37
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,40 @@ extern "C" {
4242
#[link_name="llvm.bitreverse.i32"]
4343
fn rbit_u32(i: i32) -> i32;
4444
}
45+
46+
47+
#[cfg(test)]
48+
mod tests {
49+
use stdsimd_test::simd_test;
50+
51+
use arm::v7;
52+
53+
#[test]
54+
fn _clz_u8() {
55+
unsafe {
56+
assert_eq!(v7::_clz_u8(0b0000_1010u8), 4u8);
57+
}
58+
}
59+
60+
#[test]
61+
fn _clz_u16() {
62+
unsafe {
63+
assert_eq!(v7::_clz_u16(0b0000_1010u16), 12u16);
64+
}
65+
}
66+
67+
#[test]
68+
fn _clz_u32() {
69+
unsafe {
70+
assert_eq!(v7::_clz_u32(0b0000_1010u32), 28u32);
71+
}
72+
}
73+
74+
#[test]
75+
fn _rbit_u32() {
76+
unsafe {
77+
assert_eq!(v7::_rbit_u32(0b0000_1010u32),
78+
0b0101_0000_0000_0000_0000_0000_0000_0000u32);
79+
}
80+
}
81+
}

src/arm/v8.rs

+50
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,53 @@ pub unsafe fn _cls_u32(x: u32) -> u32 {
5353
pub unsafe fn _cls_u64(x: u64) -> u64 {
5454
u64::leading_zeros(((((((x as i64) >> 63) as u64) ^ x) << 1) | 1)) as u64
5555
}
56+
57+
#[cfg(test)]
58+
mod tests {
59+
use stdsimd_test::simd_test;
60+
61+
use arm::v8;
62+
63+
#[test]
64+
fn _rev_u64() {
65+
unsafe {
66+
assert_eq!(v8::_rev_u64(
67+
0b0000_0000_1111_1111_0000_0000_1111_1111_u64
68+
), 0b1111_1111_0000_0000_1111_1111_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_u64);
69+
}
70+
}
71+
72+
#[test]
73+
fn _clz_u64() {
74+
unsafe {
75+
assert_eq!(v8::_clz_u64(0b0000_1010u64), 60u64);
76+
}
77+
}
78+
79+
#[test]
80+
fn _rbit_u64() {
81+
unsafe {
82+
assert_eq!(v8::_rbit_u64(
83+
0b0000_0000_1111_1101_0000_0000_1111_1111_u64
84+
), 0b1111_1111_0000_0000_1011_1111_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_u64);
85+
}
86+
}
87+
88+
#[test]
89+
fn _cls_u32() {
90+
unsafe {
91+
assert_eq!(v8::_cls_u32(
92+
0b1111_1111_1111_1111_0000_0000_1111_1111_u32
93+
), 15_u32);
94+
}
95+
}
96+
97+
#[test]
98+
fn _cls_u64() {
99+
unsafe {
100+
assert_eq!(v8::_cls_u64(
101+
0b1111_1111_1111_1111_0000_0000_1111_1111_0000_0000_0000_0000_0000_0000_0000_0000_u64
102+
), 15_u64);
103+
}
104+
}
105+
}

0 commit comments

Comments
 (0)