Source file
test/codegen/known_bits.go
1
2
3
4
5
6
7 package codegen
8
9 func knownBitsPhiAnd(cond bool) int {
10 x := 1
11 if cond {
12 x = 3
13 }
14
15
16 return x & 1
17 }
18
19 func knownBitsDeferPattern(a, b bool) int {
20 bits := 0
21 bits |= 1 << 0
22 if a {
23 bits |= 1 << 1
24 }
25 bits |= 1 << 2
26 if b {
27 bits |= 1 << 3
28 }
29
30
31 return bits & (1<<2 | 1<<0)
32 }
33
34 func knownBitsXorToggle(a, b, c bool) int {
35 bits := 0
36 bits ^= 1 << 0
37 if a {
38 bits ^= 1 << 1
39 }
40 bits ^= 1 << 2
41 if b {
42 bits ^= 1 << 3
43 }
44 bits ^= 1 << 2
45 if c {
46 bits ^= 1 << 4
47 }
48
49
50 return bits & (1<<2 | 1<<0)
51 }
52
View as plain text