_nx_bits_bswap_oracle.nx source
↩ module page · 32 lines · 1558 B
1// _nx_bits_bswap_oracle.nx -- correctness paired oracle for
2// nx_bits_bswap64 / nx_bits_bswap32 (intrinsic) vs SOFT SWAR.
3
4import "syscalls.nx"
5import "nx_bits.nx"
6
7func main() -> i64 {
8 // bswap64 oracles -- known fixed-point + characteristic patterns
9 if nx_bits_bswap64(0) != nx_bits_bswap64_soft(0) { return 1 }
10 if nx_bits_bswap64(0x0123456789ABCDEF) != nx_bits_bswap64_soft(0x0123456789ABCDEF) { return 2 }
11 if nx_bits_bswap64(-1) != nx_bits_bswap64_soft(-1) { return 3 }
12 if nx_bits_bswap64(0xFF) != nx_bits_bswap64_soft(0xFF) { return 4 }
13 if nx_bits_bswap64(0xCAFEBABE12345678) != nx_bits_bswap64_soft(0xCAFEBABE12345678) { return 5 }
14 if nx_bits_bswap64(0x1100000000000000) != nx_bits_bswap64_soft(0x1100000000000000) { return 6 }
15
16 // Known fixed values: bswap of 0x0123456789ABCDEF = 0xEFCDAB8967452301
17 if nx_bits_bswap64(0x0123456789ABCDEF) != 0xEFCDAB8967452301 as i64 { return 7 }
18 if nx_bits_bswap64(0xFF) != 0xFF00000000000000 as i64 { return 8 }
19
20 // Involution: bswap(bswap(x)) == x
21 let x1: i64 = 0xCAFEBABE12345678
22 if nx_bits_bswap64(nx_bits_bswap64(x1)) != x1 { return 9 }
23
24 // bswap32 oracles
25 if nx_bits_bswap32(0) != nx_bits_bswap32_soft(0) { return 10 }
26 if nx_bits_bswap32(0x12345678) != nx_bits_bswap32_soft(0x12345678) { return 11 }
27 if nx_bits_bswap32(0xFFFFFFFF) != nx_bits_bswap32_soft(0xFFFFFFFF) { return 12 }
28 if nx_bits_bswap32(0x12345678) != 0x78563412 { return 13 }
29 if nx_bits_bswap32(nx_bits_bswap32(0xCAFEBABE)) != 0xCAFEBABE { return 14 }
30
31 return 0
32}