_nx_bits_rotate_oracle.nx source
↩ module page · 33 lines · 1555 B
1// _nx_bits_rotate_oracle.nx -- correctness paired oracle for
2// nx_bits_rotl64 / nx_bits_rotr64 (intrinsic) vs SOFT shift+or.
3
4import "syscalls.nx"
5import "nx_bits.nx"
6
7func main() -> i64 {
8 let x1: i64 = 0xCAFEBABE12345678
9
10 // rotl by representative counts
11 if nx_bits_rotl64(x1, 0) != nx_bits_rotl64_soft(x1, 0) { return 1 }
12 if nx_bits_rotl64(x1, 1) != nx_bits_rotl64_soft(x1, 1) { return 2 }
13 if nx_bits_rotl64(x1, 7) != nx_bits_rotl64_soft(x1, 7) { return 3 }
14 if nx_bits_rotl64(x1, 16) != nx_bits_rotl64_soft(x1, 16) { return 4 }
15 if nx_bits_rotl64(x1, 32) != nx_bits_rotl64_soft(x1, 32) { return 5 }
16 if nx_bits_rotl64(x1, 47) != nx_bits_rotl64_soft(x1, 47) { return 6 }
17 if nx_bits_rotl64(x1, 63) != nx_bits_rotl64_soft(x1, 63) { return 7 }
18
19 // rotr by representative counts
20 if nx_bits_rotr64(x1, 0) != nx_bits_rotr64_soft(x1, 0) { return 8 }
21 if nx_bits_rotr64(x1, 1) != nx_bits_rotr64_soft(x1, 1) { return 9 }
22 if nx_bits_rotr64(x1, 7) != nx_bits_rotr64_soft(x1, 7) { return 10 }
23 if nx_bits_rotr64(x1, 16) != nx_bits_rotr64_soft(x1, 16) { return 11 }
24 if nx_bits_rotr64(x1, 32) != nx_bits_rotr64_soft(x1, 32) { return 12 }
25 if nx_bits_rotr64(x1, 47) != nx_bits_rotr64_soft(x1, 47) { return 13 }
26 if nx_bits_rotr64(x1, 63) != nx_bits_rotr64_soft(x1, 63) { return 14 }
27
28 // round-trip identity: rotr(rotl(x, n), n) == x
29 if nx_bits_rotr64(nx_bits_rotl64(x1, 13), 13) != x1 { return 15 }
30 if nx_bits_rotl64(nx_bits_rotr64(x1, 29), 29) != x1 { return 16 }
31
32 return 0
33}