@@ -45,11 +45,13 @@ pub fn leading_zeros_64(x u64) int {
45
45
46
46
// --- TrailingZeros ---
47
47
// trailing_zeros_8 returns the number of trailing zero bits in x; the result is 8 for x == 0.
48
+ @[direct_array_access]
48
49
pub fn trailing_zeros_8 (x u8 ) int {
49
50
return int (ntz_8_ tab[x])
50
51
}
51
52
52
53
// trailing_zeros_16 returns the number of trailing zero bits in x; the result is 16 for x == 0.
54
+ @[direct_array_access]
53
55
pub fn trailing_zeros_16 (x u16 ) int {
54
56
if x == 0 {
55
57
return 16
@@ -59,6 +61,7 @@ pub fn trailing_zeros_16(x u16) int {
59
61
}
60
62
61
63
// trailing_zeros_32 returns the number of trailing zero bits in x; the result is 32 for x == 0.
64
+ @[direct_array_access]
62
65
pub fn trailing_zeros_32 (x u32 ) int {
63
66
if x == 0 {
64
67
return 32
@@ -68,6 +71,7 @@ pub fn trailing_zeros_32(x u32) int {
68
71
}
69
72
70
73
// trailing_zeros_64 returns the number of trailing zero bits in x; the result is 64 for x == 0.
74
+ @[direct_array_access]
71
75
pub fn trailing_zeros_64 (x u64 ) int {
72
76
if x == 0 {
73
77
return 64
@@ -88,16 +92,19 @@ pub fn trailing_zeros_64(x u64) int {
88
92
89
93
// --- OnesCount ---
90
94
// ones_count_8 returns the number of one bits ("population count") in x.
95
+ @[direct_array_access]
91
96
pub fn ones_count_8 (x u8 ) int {
92
97
return int (pop_8_ tab[x])
93
98
}
94
99
95
100
// ones_count_16 returns the number of one bits ("population count") in x.
101
+ @[direct_array_access]
96
102
pub fn ones_count_16 (x u16 ) int {
97
103
return int (pop_8_ tab[x >> 8 ] + pop_8_ tab[x & u16 (0xff )])
98
104
}
99
105
100
106
// ones_count_32 returns the number of one bits ("population count") in x.
107
+ @[direct_array_access]
101
108
pub fn ones_count_32 (x u32 ) int {
102
109
return int (pop_8_ tab[x >> 24 ] + pop_8_ tab[x >> 16 & 0xff ] + pop_8_ tab[x >> 8 & 0xff ] +
103
110
pop_8_ tab[x & u32 (0xff )])
@@ -181,13 +188,13 @@ pub fn rotate_left_64(x u64, k int) u64 {
181
188
182
189
// --- Reverse ---
183
190
// reverse_8 returns the value of x with its bits in reversed order.
184
- @[inline]
191
+ @[direct_array_access; inline]
185
192
pub fn reverse_8 (x u8 ) u8 {
186
193
return rev_8_ tab[x]
187
194
}
188
195
189
196
// reverse_16 returns the value of x with its bits in reversed order.
190
- @[inline]
197
+ @[direct_array_access; inline]
191
198
pub fn reverse_16 (x u16 ) u16 {
192
199
return u16 (rev_8_ tab[x >> 8 ]) | (u16 (rev_8_ tab[x & u16 (0xff )]) << 8 )
193
200
}
@@ -240,11 +247,13 @@ pub fn reverse_bytes_64(x u64) u64 {
240
247
241
248
// --- Len ---
242
249
// len_8 returns the minimum number of bits required to represent x; the result is 0 for x == 0.
250
+ @[direct_array_access]
243
251
pub fn len_8 (x u8 ) int {
244
252
return int (len_8_ tab[x])
245
253
}
246
254
247
255
// len_16 returns the minimum number of bits required to represent x; the result is 0 for x == 0.
256
+ @[direct_array_access]
248
257
pub fn len_16 (x u16 ) int {
249
258
mut y := x
250
259
mut n := 0
@@ -256,6 +265,7 @@ pub fn len_16(x u16) int {
256
265
}
257
266
258
267
// len_32 returns the minimum number of bits required to represent x; the result is 0 for x == 0.
268
+ @[direct_array_access]
259
269
pub fn len_32 (x u32 ) int {
260
270
mut y := x
261
271
mut n := 0
@@ -271,6 +281,7 @@ pub fn len_32(x u32) int {
271
281
}
272
282
273
283
// len_64 returns the minimum number of bits required to represent x; the result is 0 for x == 0.
284
+ @[direct_array_access]
274
285
pub fn len_64 (x u64 ) int {
275
286
mut y := x
276
287
mut n := 0
0 commit comments