File: bmi1_tests.rs

package info (click to toggle)
rust-safe-arch 0.9.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 940 kB
  • sloc: python: 66; makefile: 2; sh: 1
file content (130 lines) | stat: -rw-r--r-- 3,893 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
use super::*;

#[test]
fn test_bitandnot_u32() {
  let a = [1, 0, 1, 0];
  let b = [1, 1, 0, 0];
  let mut c = [0_u32; 4];
  for i in 0..4 {
    c[i] = bitandnot_u32(a[i], b[i]);
  }
  assert_eq!(c, [0, 1, 0, 0]);
}

#[test]
#[cfg(target_arch = "x86_64")]
fn test_bitandnot_u64() {
  let a = [1_u64, 0, 1, 0];
  let b = [1_u64, 1, 0, 0];
  let mut c = [0_u64; 4];
  for i in 0..4 {
    c[i] = bitandnot_u64(a[i], b[i]);
  }
  assert_eq!(c, [0_u64, 1, 0, 0]);
}

#[test]
fn test_bit_extract_u32() {
  assert_eq!(bit_extract_u32(0b0110, 0, 3), 0b110);
  assert_eq!(bit_extract_u32(0b0110, 0, 2), 0b10);
  assert_eq!(bit_extract_u32(0b0110, 1, 2), 0b11);
}

#[test]
#[cfg(target_arch = "x86_64")]
fn test_bit_extract_u64() {
  assert_eq!(bit_extract_u64(0b0110, 0, 3), 0b110);
  assert_eq!(bit_extract_u64(0b0110, 0, 2), 0b10);
  assert_eq!(bit_extract_u64(0b0110, 1, 2), 0b11);
}

#[test]
fn test_bit_extract2_u32() {
  assert_eq!(bit_extract2_u32(0b0110, (3 << 8) | 0), 0b110);
  assert_eq!(bit_extract2_u32(0b0110, (2 << 8) | 0), 0b10);
  assert_eq!(bit_extract2_u32(0b0110, (2 << 8) | 1), 0b11);
}

#[test]
#[cfg(target_arch = "x86_64")]
fn test_bit_extract2_u64() {
  assert_eq!(bit_extract2_u64(0b0110, (3 << 8) | 0), 0b110);
  assert_eq!(bit_extract2_u64(0b0110, (2 << 8) | 0), 0b10);
  assert_eq!(bit_extract2_u64(0b0110, (2 << 8) | 1), 0b11);
}

#[test]
fn test_bit_lowest_set_value_u32() {
  assert_eq!(bit_lowest_set_value_u32(0b0), 0);
  assert_eq!(bit_lowest_set_value_u32(0b1), 1);
  assert_eq!(bit_lowest_set_value_u32(0b10), 2);
  assert_eq!(bit_lowest_set_value_u32(0b100), 4);
  assert_eq!(bit_lowest_set_value_u32(0b111100), 4);
}

#[test]
#[cfg(target_arch = "x86_64")]
fn test_bit_lowest_set_value_u64() {
  assert_eq!(bit_lowest_set_value_u64(0b0), 0);
  assert_eq!(bit_lowest_set_value_u64(0b1), 1);
  assert_eq!(bit_lowest_set_value_u64(0b10), 2);
  assert_eq!(bit_lowest_set_value_u64(0b100), 4);
  assert_eq!(bit_lowest_set_value_u64(0b111100), 4);
}

#[test]
fn test_bit_lowest_set_mask_u32() {
  assert_eq!(bit_lowest_set_mask_u32(0b0), u32::MAX);
  assert_eq!(bit_lowest_set_mask_u32(0b1), 0b1);
  assert_eq!(bit_lowest_set_mask_u32(0b10), 0b11);
  assert_eq!(bit_lowest_set_mask_u32(0b100), 0b111);
  assert_eq!(bit_lowest_set_mask_u32(0b111100), 0b111);
}

#[test]
#[cfg(target_arch = "x86_64")]
fn test_bit_lowest_set_mask_u64() {
  assert_eq!(bit_lowest_set_mask_u64(0b0), u64::MAX);
  assert_eq!(bit_lowest_set_mask_u64(0b1), 0b1);
  assert_eq!(bit_lowest_set_mask_u64(0b10), 0b11);
  assert_eq!(bit_lowest_set_mask_u64(0b100), 0b111);
  assert_eq!(bit_lowest_set_mask_u64(0b111100), 0b111);
}

#[test]
fn test_bit_lowest_set_reset_u32() {
  assert_eq!(bit_lowest_set_reset_u32(0b0), 0);
  assert_eq!(bit_lowest_set_reset_u32(0b1), 0b0);
  assert_eq!(bit_lowest_set_reset_u32(0b10), 0b00);
  assert_eq!(bit_lowest_set_reset_u32(0b100), 0b000);
  assert_eq!(bit_lowest_set_reset_u32(0b111100), 0b111000);
}

#[test]
#[cfg(target_arch = "x86_64")]
fn test_bit_lowest_set_reset_u64() {
  assert_eq!(bit_lowest_set_reset_u64(0b0), 0);
  assert_eq!(bit_lowest_set_reset_u64(0b1), 0b0);
  assert_eq!(bit_lowest_set_reset_u64(0b10), 0b00);
  assert_eq!(bit_lowest_set_reset_u64(0b100), 0b000);
  assert_eq!(bit_lowest_set_reset_u64(0b111100), 0b111000);
}

#[test]
fn test_trailing_zero_count_u32() {
  assert_eq!(trailing_zero_count_u32(0b0), 32);
  assert_eq!(trailing_zero_count_u32(0b1), 0);
  assert_eq!(trailing_zero_count_u32(0b10), 1);
  assert_eq!(trailing_zero_count_u32(0b100), 2);
  assert_eq!(trailing_zero_count_u32(0b111100), 2);
}

#[test]
#[cfg(target_arch = "x86_64")]
fn test_trailing_zero_count_u64() {
  assert_eq!(trailing_zero_count_u64(0b0), 64);
  assert_eq!(trailing_zero_count_u64(0b1), 0);
  assert_eq!(trailing_zero_count_u64(0b10), 1);
  assert_eq!(trailing_zero_count_u64(0b100), 2);
  assert_eq!(trailing_zero_count_u64(0b111100), 2);
}