1
2
3
4
5
6
7 package codegen
8
9 func andn64(x, y int64) int64 {
10
11 return x &^ y
12 }
13
14 func andn32(x, y int32) int32 {
15
16 return x &^ y
17 }
18
19 func blsi64(x int64) int64 {
20
21 return x & -x
22 }
23
24 func blsi32(x int32) int32 {
25
26 return x & -x
27 }
28
29 func blsmsk64(x int64) int64 {
30
31 return x ^ (x - 1)
32 }
33
34 func blsmsk32(x int32) int32 {
35
36 return x ^ (x - 1)
37 }
38
39 func blsr64(x int64) int64 {
40
41 return x & (x - 1)
42 }
43
44 func blsr32(x int32) int32 {
45
46 return x & (x - 1)
47 }
48
49 func isPowerOfTwo64(x int64) bool {
50
51 return blsr64(x) == 0
52 }
53
54 func isPowerOfTwo32(x int32) bool {
55
56 return blsr32(x) == 0
57 }
58
59 func isPowerOfTwoSelect64(x, a, b int64) int64 {
60 var r int64
61
62 if isPowerOfTwo64(x) {
63 r = a
64 } else {
65 r = b
66 }
67
68 return r * 2
69 }
70
71 func isPowerOfTwoSelect32(x, a, b int32) int32 {
72 var r int32
73
74 if isPowerOfTwo32(x) {
75 r = a
76 } else {
77 r = b
78 }
79
80 return r * 2
81 }
82
83 func isPowerOfTwoBranch64(x int64, a func(bool), b func(string)) {
84
85 if isPowerOfTwo64(x) {
86 a(true)
87 } else {
88 b("false")
89 }
90 }
91
92 func isPowerOfTwoBranch32(x int32, a func(bool), b func(string)) {
93
94 if isPowerOfTwo32(x) {
95 a(true)
96 } else {
97 b("false")
98 }
99 }
100
101 func isNotPowerOfTwo64(x int64) bool {
102
103 return blsr64(x) != 0
104 }
105
106 func isNotPowerOfTwo32(x int32) bool {
107
108 return blsr32(x) != 0
109 }
110
111 func isNotPowerOfTwoSelect64(x, a, b int64) int64 {
112 var r int64
113
114 if isNotPowerOfTwo64(x) {
115 r = a
116 } else {
117 r = b
118 }
119
120 return r * 2
121 }
122
123 func isNotPowerOfTwoSelect32(x, a, b int32) int32 {
124 var r int32
125
126 if isNotPowerOfTwo32(x) {
127 r = a
128 } else {
129 r = b
130 }
131
132 return r * 2
133 }
134
135 func isNotPowerOfTwoBranch64(x int64, a func(bool), b func(string)) {
136
137 if isNotPowerOfTwo64(x) {
138 a(true)
139 } else {
140 b("false")
141 }
142 }
143
144 func isNotPowerOfTwoBranch32(x int32, a func(bool), b func(string)) {
145
146 if isNotPowerOfTwo32(x) {
147 a(true)
148 } else {
149 b("false")
150 }
151 }
152
153 func sarx64(x, y int64) int64 {
154
155 return x >> y
156 }
157
158 func sarx32(x, y int32) int32 {
159
160 return x >> y
161 }
162
163 func sarx64_load(x []int64, i int) int64 {
164
165 s := x[i] >> (i & 63)
166
167 s = x[i+1] >> (s & 63)
168 return s
169 }
170
171 func sarx32_load(x []int32, i int) int32 {
172
173 s := x[i] >> (i & 63)
174
175 s = x[i+1] >> (s & 63)
176 return s
177 }
178
179 func shlrx64(x, y uint64) uint64 {
180
181 s := x >> y
182
183 s = s << y
184 return s
185 }
186
187 func shlrx32(x, y uint32) uint32 {
188
189 s := x >> y
190
191 s = s << y
192 return s
193 }
194
195 func shlrx64_load(x []uint64, i int, s uint64) uint64 {
196
197 s = x[i] >> i
198
199 s = x[i+1] << s
200 return s
201 }
202
203 func shlrx32_load(x []uint32, i int, s uint32) uint32 {
204
205 s = x[i] >> i
206
207 s = x[i+1] << s
208 return s
209 }
210
View as plain text