Skip to content

Commit 9ba3dc9

Browse files
committed
add ctlz and cttz tests
1 parent 379cf5a commit 9ba3dc9

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

tests/run/int_intrinsics.rs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Compiler:
2+
//
3+
// Run-time:
4+
5+
#![feature(no_core, intrinsics)]
6+
#![no_std]
7+
#![no_core]
8+
#![no_main]
9+
10+
extern crate mini_core;
11+
use intrinsics::black_box;
12+
use mini_core::*;
13+
14+
#[rustc_intrinsic]
15+
pub const fn ctlz<T: Copy>(_x: T) -> u32;
16+
17+
#[rustc_intrinsic]
18+
pub const fn cttz<T: Copy>(_x: T) -> u32;
19+
20+
#[no_mangle]
21+
extern "C" fn main(argc: i32, _argv: *const *const u8) -> i32 {
22+
macro_rules! check {
23+
($func_name:ident, $input:expr, $expected:expr, $res:expr) => {{
24+
if $func_name(black_box($input)) != $expected {
25+
return $res;
26+
}
27+
}};
28+
}
29+
30+
check!(ctlz, 0_u128, 128_u32, 1);
31+
check!(ctlz, 1_u128, 127_u32, 2);
32+
check!(ctlz, 0x8000_0000_0000_0000_0000_0000_0000_0000_u128, 0_u32, 3);
33+
check!(cttz, 0_u128, 128_u32, 4);
34+
check!(cttz, 1_u128, 0_u32, 5);
35+
check!(cttz, 2_u128, 1_u32, 6);
36+
check!(cttz, 0x8000_0000_0000_0000_0000_0000_0000_0000_u128, 127_u32, 7);
37+
38+
check!(ctlz, 0_u64, 64_u32, 8);
39+
check!(ctlz, 1_u64, 63_u32, 9);
40+
check!(ctlz, 0x8000_0000_0000_0000_u64, 0_u32, 10);
41+
check!(cttz, 0_u64, 64_u32, 11);
42+
check!(cttz, 1_u64, 0_u32, 12);
43+
check!(cttz, 2_u64, 1_u32, 13);
44+
check!(cttz, 0x8000_0000_0000_0000_u64, 63_u32, 14);
45+
46+
check!(ctlz, 0_u32, 32_u32, 15);
47+
check!(ctlz, 1_u32, 31_u32, 16);
48+
check!(ctlz, 0x8000_0000_u32, 0_u32, 17);
49+
check!(cttz, 0_u32, 32_u32, 18);
50+
check!(cttz, 1_u32, 0_u32, 19);
51+
check!(cttz, 2_u32, 1_u32, 20);
52+
check!(cttz, 0x8000_0000_u32, 31_u32, 21);
53+
54+
check!(ctlz, 0_u16, 16_u32, 22);
55+
check!(ctlz, 1_u16, 15_u32, 23);
56+
check!(ctlz, 0x8000_u16, 0_u32, 24);
57+
check!(cttz, 0_u16, 16_u32, 25);
58+
check!(cttz, 1_u16, 0_u32, 26);
59+
check!(cttz, 2_u16, 1_u32, 27);
60+
check!(cttz, 0x8000_u16, 15_u32, 28);
61+
62+
check!(ctlz, 0_u8, 8_u32, 29);
63+
check!(ctlz, 1_u8, 7_u32, 30);
64+
check!(ctlz, 0x80_u8, 0_u32, 31);
65+
check!(cttz, 0_u8, 8_u32, 32);
66+
check!(cttz, 1_u8, 0_u32, 33);
67+
check!(cttz, 2_u8, 1_u32, 34);
68+
check!(cttz, 0x80_u8, 7_u32, 35);
69+
70+
0
71+
}

0 commit comments

Comments
 (0)