1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#include "qemu/osdep.h"
21#include "cpu.h"
22#include "exec/exec-all.h"
23#include "exec/helper-proto.h"
24#include "qemu/host-utils.h"
25
26
27uint64_t helper_ctpop(uint64_t arg)
28{
29 return ctpop64(arg);
30}
31
32uint64_t helper_ctlz(uint64_t arg)
33{
34 return clz64(arg);
35}
36
37uint64_t helper_cttz(uint64_t arg)
38{
39 return ctz64(arg);
40}
41
42uint64_t helper_zapnot(uint64_t val, uint64_t mskb)
43{
44 uint64_t mask;
45
46 mask = -(mskb & 0x01) & 0x00000000000000ffull;
47 mask |= -(mskb & 0x02) & 0x000000000000ff00ull;
48 mask |= -(mskb & 0x04) & 0x0000000000ff0000ull;
49 mask |= -(mskb & 0x08) & 0x00000000ff000000ull;
50 mask |= -(mskb & 0x10) & 0x000000ff00000000ull;
51 mask |= -(mskb & 0x20) & 0x0000ff0000000000ull;
52 mask |= -(mskb & 0x40) & 0x00ff000000000000ull;
53 mask |= -(mskb & 0x80) & 0xff00000000000000ull;
54
55 return val & mask;
56}
57
58uint64_t helper_zap(uint64_t val, uint64_t mask)
59{
60 return helper_zapnot(val, ~mask);
61}
62
63uint64_t helper_cmpbe0(uint64_t a)
64{
65 uint64_t m = 0x7f7f7f7f7f7f7f7fULL;
66 uint64_t c = ~(((a & m) + m) | a | m);
67
68 c |= c << 7;
69
70 c |= c << 14;
71
72 c |= c << 28;
73
74 return c >> 56;
75}
76
77uint64_t helper_cmpbge(uint64_t a, uint64_t b)
78{
79 uint64_t mask = 0x00ff00ff00ff00ffULL;
80 uint64_t test = 0x0100010001000100ULL;
81 uint64_t al, ah, bl, bh, cl, ch;
82
83
84 al = a & mask;
85 bl = b & mask;
86 ah = (a >> 8) & mask;
87 bh = (b >> 8) & mask;
88
89
90
91 cl = ((al | test) - bl) & test;
92 ch = ((ah | test) - bh) & test;
93
94
95
96
97 cl += ch << 1;
98
99 cl |= cl << 14;
100
101 cl |= cl << 28;
102
103 return cl >> 50;
104}
105
106uint64_t helper_minub8(uint64_t op1, uint64_t op2)
107{
108 uint64_t res = 0;
109 uint8_t opa, opb, opr;
110 int i;
111
112 for (i = 0; i < 8; ++i) {
113 opa = op1 >> (i * 8);
114 opb = op2 >> (i * 8);
115 opr = opa < opb ? opa : opb;
116 res |= (uint64_t)opr << (i * 8);
117 }
118 return res;
119}
120
121uint64_t helper_minsb8(uint64_t op1, uint64_t op2)
122{
123 uint64_t res = 0;
124 int8_t opa, opb;
125 uint8_t opr;
126 int i;
127
128 for (i = 0; i < 8; ++i) {
129 opa = op1 >> (i * 8);
130 opb = op2 >> (i * 8);
131 opr = opa < opb ? opa : opb;
132 res |= (uint64_t)opr << (i * 8);
133 }
134 return res;
135}
136
137uint64_t helper_minuw4(uint64_t op1, uint64_t op2)
138{
139 uint64_t res = 0;
140 uint16_t opa, opb, opr;
141 int i;
142
143 for (i = 0; i < 4; ++i) {
144 opa = op1 >> (i * 16);
145 opb = op2 >> (i * 16);
146 opr = opa < opb ? opa : opb;
147 res |= (uint64_t)opr << (i * 16);
148 }
149 return res;
150}
151
152uint64_t helper_minsw4(uint64_t op1, uint64_t op2)
153{
154 uint64_t res = 0;
155 int16_t opa, opb;
156 uint16_t opr;
157 int i;
158
159 for (i = 0; i < 4; ++i) {
160 opa = op1 >> (i * 16);
161 opb = op2 >> (i * 16);
162 opr = opa < opb ? opa : opb;
163 res |= (uint64_t)opr << (i * 16);
164 }
165 return res;
166}
167
168uint64_t helper_maxub8(uint64_t op1, uint64_t op2)
169{
170 uint64_t res = 0;
171 uint8_t opa, opb, opr;
172 int i;
173
174 for (i = 0; i < 8; ++i) {
175 opa = op1 >> (i * 8);
176 opb = op2 >> (i * 8);
177 opr = opa > opb ? opa : opb;
178 res |= (uint64_t)opr << (i * 8);
179 }
180 return res;
181}
182
183uint64_t helper_maxsb8(uint64_t op1, uint64_t op2)
184{
185 uint64_t res = 0;
186 int8_t opa, opb;
187 uint8_t opr;
188 int i;
189
190 for (i = 0; i < 8; ++i) {
191 opa = op1 >> (i * 8);
192 opb = op2 >> (i * 8);
193 opr = opa > opb ? opa : opb;
194 res |= (uint64_t)opr << (i * 8);
195 }
196 return res;
197}
198
199uint64_t helper_maxuw4(uint64_t op1, uint64_t op2)
200{
201 uint64_t res = 0;
202 uint16_t opa, opb, opr;
203 int i;
204
205 for (i = 0; i < 4; ++i) {
206 opa = op1 >> (i * 16);
207 opb = op2 >> (i * 16);
208 opr = opa > opb ? opa : opb;
209 res |= (uint64_t)opr << (i * 16);
210 }
211 return res;
212}
213
214uint64_t helper_maxsw4(uint64_t op1, uint64_t op2)
215{
216 uint64_t res = 0;
217 int16_t opa, opb;
218 uint16_t opr;
219 int i;
220
221 for (i = 0; i < 4; ++i) {
222 opa = op1 >> (i * 16);
223 opb = op2 >> (i * 16);
224 opr = opa > opb ? opa : opb;
225 res |= (uint64_t)opr << (i * 16);
226 }
227 return res;
228}
229
230uint64_t helper_perr(uint64_t op1, uint64_t op2)
231{
232 uint64_t res = 0;
233 uint8_t opa, opb, opr;
234 int i;
235
236 for (i = 0; i < 8; ++i) {
237 opa = op1 >> (i * 8);
238 opb = op2 >> (i * 8);
239 if (opa >= opb) {
240 opr = opa - opb;
241 } else {
242 opr = opb - opa;
243 }
244 res += opr;
245 }
246 return res;
247}
248
249uint64_t helper_pklb(uint64_t op1)
250{
251 return (op1 & 0xff) | ((op1 >> 24) & 0xff00);
252}
253
254uint64_t helper_pkwb(uint64_t op1)
255{
256 return ((op1 & 0xff)
257 | ((op1 >> 8) & 0xff00)
258 | ((op1 >> 16) & 0xff0000)
259 | ((op1 >> 24) & 0xff000000));
260}
261
262uint64_t helper_unpkbl(uint64_t op1)
263{
264 return (op1 & 0xff) | ((op1 & 0xff00) << 24);
265}
266
267uint64_t helper_unpkbw(uint64_t op1)
268{
269 return ((op1 & 0xff)
270 | ((op1 & 0xff00) << 8)
271 | ((op1 & 0xff0000) << 16)
272 | ((op1 & 0xff000000) << 24));
273}
274
275void helper_check_overflow(CPUAlphaState *env, uint64_t op1, uint64_t op2)
276{
277 if (unlikely(op1 != op2)) {
278 arith_excp(env, GETPC(), EXC_M_IOV, 0);
279 }
280}
281