lib/std/bits.rad 1.6 KiB raw
1
//! Fixed-width bit operations. Rotation counts wrap modulo the value width.
2
3
@test mod tests;
4
5
/// Rotate a 32-bit value to the left. The count is reduced modulo 32.
6
@intrinsic export fn rotateLeft32(value: u32, count: u32) -> u32;
7
8
/// Rotate a 32-bit value to the right. The count is reduced modulo 32.
9
@intrinsic export fn rotateRight32(value: u32, count: u32) -> u32;
10
11
/// Count high zero bits in a 32-bit value. Return 32 for zero.
12
@intrinsic export fn leadingZeros32(value: u32) -> u32;
13
14
/// Count low zero bits in a 32-bit value. Return 32 for zero.
15
@intrinsic export fn trailingZeros32(value: u32) -> u32;
16
17
/// Count the set bits in a 32-bit value.
18
@intrinsic export fn popCount32(value: u32) -> u32;
19
20
/// Reverse the byte order of a 32-bit value.
21
@intrinsic export fn byteSwap32(value: u32) -> u32;
22
23
/// Rotate a 64-bit value to the left. The count is reduced modulo 64.
24
@intrinsic export fn rotateLeft64(value: u64, count: u32) -> u64;
25
26
/// Rotate a 64-bit value to the right. The count is reduced modulo 64.
27
@intrinsic export fn rotateRight64(value: u64, count: u32) -> u64;
28
29
/// Count high zero bits in a 64-bit value. Return 64 for zero.
30
@intrinsic export fn leadingZeros64(value: u64) -> u32;
31
32
/// Count low zero bits in a 64-bit value. Return 64 for zero.
33
@intrinsic export fn trailingZeros64(value: u64) -> u32;
34
35
/// Count the set bits in a 64-bit value.
36
@intrinsic export fn popCount64(value: u64) -> u32;
37
38
/// Reverse the byte order of a 64-bit value.
39
@intrinsic export fn byteSwap64(value: u64) -> u64;
40
41
/// Reverse the byte order of a 16-bit value.
42
@intrinsic export fn byteSwap16(value: u16) -> u16;