]>
Commit | Line | Data |
---|---|---|
0be034bc RH |
1 | /* |
2 | * Helpers for integer and multimedia instructions. | |
3 | * | |
4 | * Copyright (c) 2007 Jocelyn Mayer | |
5 | * | |
6 | * This library is free software; you can redistribute it and/or | |
7 | * modify it under the terms of the GNU Lesser General Public | |
8 | * License as published by the Free Software Foundation; either | |
9 | * version 2 of the License, or (at your option) any later version. | |
10 | * | |
11 | * This library is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | * Lesser General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU Lesser General Public | |
17 | * License along with this library; if not, see <http://www.gnu.org/licenses/>. | |
18 | */ | |
19 | ||
20 | #include "cpu.h" | |
2ef6175a | 21 | #include "exec/helper-proto.h" |
1de7afc9 | 22 | #include "qemu/host-utils.h" |
0be034bc RH |
23 | |
24 | ||
0be034bc RH |
25 | uint64_t helper_ctpop(uint64_t arg) |
26 | { | |
27 | return ctpop64(arg); | |
28 | } | |
29 | ||
30 | uint64_t helper_ctlz(uint64_t arg) | |
31 | { | |
32 | return clz64(arg); | |
33 | } | |
34 | ||
35 | uint64_t helper_cttz(uint64_t arg) | |
36 | { | |
37 | return ctz64(arg); | |
38 | } | |
39 | ||
8d8d324e | 40 | uint64_t helper_zapnot(uint64_t val, uint64_t mskb) |
0be034bc RH |
41 | { |
42 | uint64_t mask; | |
43 | ||
8d8d324e RH |
44 | mask = -(mskb & 0x01) & 0x00000000000000ffull; |
45 | mask |= -(mskb & 0x02) & 0x000000000000ff00ull; | |
46 | mask |= -(mskb & 0x04) & 0x0000000000ff0000ull; | |
47 | mask |= -(mskb & 0x08) & 0x00000000ff000000ull; | |
48 | mask |= -(mskb & 0x10) & 0x000000ff00000000ull; | |
49 | mask |= -(mskb & 0x20) & 0x0000ff0000000000ull; | |
50 | mask |= -(mskb & 0x40) & 0x00ff000000000000ull; | |
51 | mask |= -(mskb & 0x80) & 0xff00000000000000ull; | |
0be034bc | 52 | |
8d8d324e | 53 | return val & mask; |
0be034bc RH |
54 | } |
55 | ||
56 | uint64_t helper_zap(uint64_t val, uint64_t mask) | |
57 | { | |
8d8d324e | 58 | return helper_zapnot(val, ~mask); |
0be034bc RH |
59 | } |
60 | ||
112e4518 RH |
61 | uint64_t helper_cmpbe0(uint64_t a) |
62 | { | |
63 | uint64_t m = 0x7f7f7f7f7f7f7f7fULL; | |
64 | uint64_t c = ~(((a & m) + m) | a | m); | |
65 | /* a.......b.......c.......d.......e.......f.......g.......h....... */ | |
66 | c |= c << 7; | |
67 | /* ab......bc......cd......de......ef......fg......gh......h....... */ | |
68 | c |= c << 14; | |
69 | /* abcd....bcde....cdef....defg....efgh....fgh.....gh......h....... */ | |
70 | c |= c << 28; | |
71 | /* abcdefghbcdefgh.cdefgh..defgh...efgh....fgh.....gh......h....... */ | |
72 | return c >> 56; | |
73 | } | |
74 | ||
5f2a80ad | 75 | uint64_t helper_cmpbge(uint64_t a, uint64_t b) |
0be034bc | 76 | { |
5f2a80ad RH |
77 | uint64_t mask = 0x00ff00ff00ff00ffULL; |
78 | uint64_t test = 0x0100010001000100ULL; | |
79 | uint64_t al, ah, bl, bh, cl, ch; | |
0be034bc | 80 | |
5f2a80ad RH |
81 | /* Separate the bytes to avoid false positives. */ |
82 | al = a & mask; | |
83 | bl = b & mask; | |
84 | ah = (a >> 8) & mask; | |
85 | bh = (b >> 8) & mask; | |
86 | ||
87 | /* "Compare". If a byte in B is greater than a byte in A, | |
88 | it will clear the test bit. */ | |
89 | cl = ((al | test) - bl) & test; | |
90 | ch = ((ah | test) - bh) & test; | |
91 | ||
92 | /* Fold all of the test bits into a contiguous set. */ | |
93 | /* ch=.......a...............c...............e...............g........ */ | |
94 | /* cl=.......b...............d...............f...............h........ */ | |
95 | cl += ch << 1; | |
96 | /* cl=......ab..............cd..............ef..............gh........ */ | |
97 | cl |= cl << 14; | |
98 | /* cl=......abcd............cdef............efgh............gh........ */ | |
99 | cl |= cl << 28; | |
100 | /* cl=......abcdefgh........cdefgh..........efgh............gh........ */ | |
101 | return cl >> 50; | |
0be034bc RH |
102 | } |
103 | ||
104 | uint64_t helper_minub8(uint64_t op1, uint64_t op2) | |
105 | { | |
106 | uint64_t res = 0; | |
107 | uint8_t opa, opb, opr; | |
108 | int i; | |
109 | ||
110 | for (i = 0; i < 8; ++i) { | |
111 | opa = op1 >> (i * 8); | |
112 | opb = op2 >> (i * 8); | |
113 | opr = opa < opb ? opa : opb; | |
114 | res |= (uint64_t)opr << (i * 8); | |
115 | } | |
116 | return res; | |
117 | } | |
118 | ||
119 | uint64_t helper_minsb8(uint64_t op1, uint64_t op2) | |
120 | { | |
121 | uint64_t res = 0; | |
122 | int8_t opa, opb; | |
123 | uint8_t opr; | |
124 | int i; | |
125 | ||
126 | for (i = 0; i < 8; ++i) { | |
127 | opa = op1 >> (i * 8); | |
128 | opb = op2 >> (i * 8); | |
129 | opr = opa < opb ? opa : opb; | |
130 | res |= (uint64_t)opr << (i * 8); | |
131 | } | |
132 | return res; | |
133 | } | |
134 | ||
135 | uint64_t helper_minuw4(uint64_t op1, uint64_t op2) | |
136 | { | |
137 | uint64_t res = 0; | |
138 | uint16_t opa, opb, opr; | |
139 | int i; | |
140 | ||
141 | for (i = 0; i < 4; ++i) { | |
142 | opa = op1 >> (i * 16); | |
143 | opb = op2 >> (i * 16); | |
144 | opr = opa < opb ? opa : opb; | |
145 | res |= (uint64_t)opr << (i * 16); | |
146 | } | |
147 | return res; | |
148 | } | |
149 | ||
150 | uint64_t helper_minsw4(uint64_t op1, uint64_t op2) | |
151 | { | |
152 | uint64_t res = 0; | |
153 | int16_t opa, opb; | |
154 | uint16_t opr; | |
155 | int i; | |
156 | ||
157 | for (i = 0; i < 4; ++i) { | |
158 | opa = op1 >> (i * 16); | |
159 | opb = op2 >> (i * 16); | |
160 | opr = opa < opb ? opa : opb; | |
161 | res |= (uint64_t)opr << (i * 16); | |
162 | } | |
163 | return res; | |
164 | } | |
165 | ||
166 | uint64_t helper_maxub8(uint64_t op1, uint64_t op2) | |
167 | { | |
168 | uint64_t res = 0; | |
169 | uint8_t opa, opb, opr; | |
170 | int i; | |
171 | ||
172 | for (i = 0; i < 8; ++i) { | |
173 | opa = op1 >> (i * 8); | |
174 | opb = op2 >> (i * 8); | |
175 | opr = opa > opb ? opa : opb; | |
176 | res |= (uint64_t)opr << (i * 8); | |
177 | } | |
178 | return res; | |
179 | } | |
180 | ||
181 | uint64_t helper_maxsb8(uint64_t op1, uint64_t op2) | |
182 | { | |
183 | uint64_t res = 0; | |
184 | int8_t opa, opb; | |
185 | uint8_t opr; | |
186 | int i; | |
187 | ||
188 | for (i = 0; i < 8; ++i) { | |
189 | opa = op1 >> (i * 8); | |
190 | opb = op2 >> (i * 8); | |
191 | opr = opa > opb ? opa : opb; | |
192 | res |= (uint64_t)opr << (i * 8); | |
193 | } | |
194 | return res; | |
195 | } | |
196 | ||
197 | uint64_t helper_maxuw4(uint64_t op1, uint64_t op2) | |
198 | { | |
199 | uint64_t res = 0; | |
200 | uint16_t opa, opb, opr; | |
201 | int i; | |
202 | ||
203 | for (i = 0; i < 4; ++i) { | |
204 | opa = op1 >> (i * 16); | |
205 | opb = op2 >> (i * 16); | |
206 | opr = opa > opb ? opa : opb; | |
207 | res |= (uint64_t)opr << (i * 16); | |
208 | } | |
209 | return res; | |
210 | } | |
211 | ||
212 | uint64_t helper_maxsw4(uint64_t op1, uint64_t op2) | |
213 | { | |
214 | uint64_t res = 0; | |
215 | int16_t opa, opb; | |
216 | uint16_t opr; | |
217 | int i; | |
218 | ||
219 | for (i = 0; i < 4; ++i) { | |
220 | opa = op1 >> (i * 16); | |
221 | opb = op2 >> (i * 16); | |
222 | opr = opa > opb ? opa : opb; | |
223 | res |= (uint64_t)opr << (i * 16); | |
224 | } | |
225 | return res; | |
226 | } | |
227 | ||
228 | uint64_t helper_perr(uint64_t op1, uint64_t op2) | |
229 | { | |
230 | uint64_t res = 0; | |
231 | uint8_t opa, opb, opr; | |
232 | int i; | |
233 | ||
234 | for (i = 0; i < 8; ++i) { | |
235 | opa = op1 >> (i * 8); | |
236 | opb = op2 >> (i * 8); | |
237 | if (opa >= opb) { | |
238 | opr = opa - opb; | |
239 | } else { | |
240 | opr = opb - opa; | |
241 | } | |
242 | res += opr; | |
243 | } | |
244 | return res; | |
245 | } | |
246 | ||
247 | uint64_t helper_pklb(uint64_t op1) | |
248 | { | |
249 | return (op1 & 0xff) | ((op1 >> 24) & 0xff00); | |
250 | } | |
251 | ||
252 | uint64_t helper_pkwb(uint64_t op1) | |
253 | { | |
254 | return ((op1 & 0xff) | |
255 | | ((op1 >> 8) & 0xff00) | |
256 | | ((op1 >> 16) & 0xff0000) | |
257 | | ((op1 >> 24) & 0xff000000)); | |
258 | } | |
259 | ||
260 | uint64_t helper_unpkbl(uint64_t op1) | |
261 | { | |
262 | return (op1 & 0xff) | ((op1 & 0xff00) << 24); | |
263 | } | |
264 | ||
265 | uint64_t helper_unpkbw(uint64_t op1) | |
266 | { | |
267 | return ((op1 & 0xff) | |
268 | | ((op1 & 0xff00) << 8) | |
269 | | ((op1 & 0xff0000) << 16) | |
270 | | ((op1 & 0xff000000) << 24)); | |
271 | } | |
2958620f | 272 | |
4d1628e8 | 273 | void helper_check_overflow(CPUAlphaState *env, uint64_t op1, uint64_t op2) |
2958620f | 274 | { |
4d1628e8 | 275 | if (unlikely(op1 != op2)) { |
2958620f RH |
276 | arith_excp(env, GETPC(), EXC_M_IOV, 0); |
277 | } | |
2958620f | 278 | } |