target-ppc: add vabsdu[b,h,w] instructions
[qemu/ar7.git] / target-ppc / translate / vmx-impl.c
blobad0345f1ac9f9a89460202468ef396067e127411
1 /*
2 * translate/vmx-impl.c
4 * Altivec/VMX translation
5 */
7 /*** Altivec vector extension ***/
8 /* Altivec registers moves */
10 static inline TCGv_ptr gen_avr_ptr(int reg)
12 TCGv_ptr r = tcg_temp_new_ptr();
13 tcg_gen_addi_ptr(r, cpu_env, offsetof(CPUPPCState, avr[reg]));
14 return r;
17 #define GEN_VR_LDX(name, opc2, opc3) \
18 static void glue(gen_, name)(DisasContext *ctx) \
19 { \
20 TCGv EA; \
21 if (unlikely(!ctx->altivec_enabled)) { \
22 gen_exception(ctx, POWERPC_EXCP_VPU); \
23 return; \
24 } \
25 gen_set_access_type(ctx, ACCESS_INT); \
26 EA = tcg_temp_new(); \
27 gen_addr_reg_index(ctx, EA); \
28 tcg_gen_andi_tl(EA, EA, ~0xf); \
29 /* We only need to swap high and low halves. gen_qemu_ld64 does necessary \
30 64-bit byteswap already. */ \
31 if (ctx->le_mode) { \
32 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
33 tcg_gen_addi_tl(EA, EA, 8); \
34 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
35 } else { \
36 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
37 tcg_gen_addi_tl(EA, EA, 8); \
38 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
39 } \
40 tcg_temp_free(EA); \
43 #define GEN_VR_STX(name, opc2, opc3) \
44 static void gen_st##name(DisasContext *ctx) \
45 { \
46 TCGv EA; \
47 if (unlikely(!ctx->altivec_enabled)) { \
48 gen_exception(ctx, POWERPC_EXCP_VPU); \
49 return; \
50 } \
51 gen_set_access_type(ctx, ACCESS_INT); \
52 EA = tcg_temp_new(); \
53 gen_addr_reg_index(ctx, EA); \
54 tcg_gen_andi_tl(EA, EA, ~0xf); \
55 /* We only need to swap high and low halves. gen_qemu_st64 does necessary \
56 64-bit byteswap already. */ \
57 if (ctx->le_mode) { \
58 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
59 tcg_gen_addi_tl(EA, EA, 8); \
60 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
61 } else { \
62 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
63 tcg_gen_addi_tl(EA, EA, 8); \
64 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
65 } \
66 tcg_temp_free(EA); \
69 #define GEN_VR_LVE(name, opc2, opc3, size) \
70 static void gen_lve##name(DisasContext *ctx) \
71 { \
72 TCGv EA; \
73 TCGv_ptr rs; \
74 if (unlikely(!ctx->altivec_enabled)) { \
75 gen_exception(ctx, POWERPC_EXCP_VPU); \
76 return; \
77 } \
78 gen_set_access_type(ctx, ACCESS_INT); \
79 EA = tcg_temp_new(); \
80 gen_addr_reg_index(ctx, EA); \
81 if (size > 1) { \
82 tcg_gen_andi_tl(EA, EA, ~(size - 1)); \
83 } \
84 rs = gen_avr_ptr(rS(ctx->opcode)); \
85 gen_helper_lve##name(cpu_env, rs, EA); \
86 tcg_temp_free(EA); \
87 tcg_temp_free_ptr(rs); \
90 #define GEN_VR_STVE(name, opc2, opc3, size) \
91 static void gen_stve##name(DisasContext *ctx) \
92 { \
93 TCGv EA; \
94 TCGv_ptr rs; \
95 if (unlikely(!ctx->altivec_enabled)) { \
96 gen_exception(ctx, POWERPC_EXCP_VPU); \
97 return; \
98 } \
99 gen_set_access_type(ctx, ACCESS_INT); \
100 EA = tcg_temp_new(); \
101 gen_addr_reg_index(ctx, EA); \
102 if (size > 1) { \
103 tcg_gen_andi_tl(EA, EA, ~(size - 1)); \
105 rs = gen_avr_ptr(rS(ctx->opcode)); \
106 gen_helper_stve##name(cpu_env, rs, EA); \
107 tcg_temp_free(EA); \
108 tcg_temp_free_ptr(rs); \
111 GEN_VR_LDX(lvx, 0x07, 0x03);
112 /* As we don't emulate the cache, lvxl is stricly equivalent to lvx */
113 GEN_VR_LDX(lvxl, 0x07, 0x0B);
115 GEN_VR_LVE(bx, 0x07, 0x00, 1);
116 GEN_VR_LVE(hx, 0x07, 0x01, 2);
117 GEN_VR_LVE(wx, 0x07, 0x02, 4);
119 GEN_VR_STX(svx, 0x07, 0x07);
120 /* As we don't emulate the cache, stvxl is stricly equivalent to stvx */
121 GEN_VR_STX(svxl, 0x07, 0x0F);
123 GEN_VR_STVE(bx, 0x07, 0x04, 1);
124 GEN_VR_STVE(hx, 0x07, 0x05, 2);
125 GEN_VR_STVE(wx, 0x07, 0x06, 4);
127 static void gen_lvsl(DisasContext *ctx)
129 TCGv_ptr rd;
130 TCGv EA;
131 if (unlikely(!ctx->altivec_enabled)) {
132 gen_exception(ctx, POWERPC_EXCP_VPU);
133 return;
135 EA = tcg_temp_new();
136 gen_addr_reg_index(ctx, EA);
137 rd = gen_avr_ptr(rD(ctx->opcode));
138 gen_helper_lvsl(rd, EA);
139 tcg_temp_free(EA);
140 tcg_temp_free_ptr(rd);
143 static void gen_lvsr(DisasContext *ctx)
145 TCGv_ptr rd;
146 TCGv EA;
147 if (unlikely(!ctx->altivec_enabled)) {
148 gen_exception(ctx, POWERPC_EXCP_VPU);
149 return;
151 EA = tcg_temp_new();
152 gen_addr_reg_index(ctx, EA);
153 rd = gen_avr_ptr(rD(ctx->opcode));
154 gen_helper_lvsr(rd, EA);
155 tcg_temp_free(EA);
156 tcg_temp_free_ptr(rd);
159 static void gen_mfvscr(DisasContext *ctx)
161 TCGv_i32 t;
162 if (unlikely(!ctx->altivec_enabled)) {
163 gen_exception(ctx, POWERPC_EXCP_VPU);
164 return;
166 tcg_gen_movi_i64(cpu_avrh[rD(ctx->opcode)], 0);
167 t = tcg_temp_new_i32();
168 tcg_gen_ld_i32(t, cpu_env, offsetof(CPUPPCState, vscr));
169 tcg_gen_extu_i32_i64(cpu_avrl[rD(ctx->opcode)], t);
170 tcg_temp_free_i32(t);
173 static void gen_mtvscr(DisasContext *ctx)
175 TCGv_ptr p;
176 if (unlikely(!ctx->altivec_enabled)) {
177 gen_exception(ctx, POWERPC_EXCP_VPU);
178 return;
180 p = gen_avr_ptr(rB(ctx->opcode));
181 gen_helper_mtvscr(cpu_env, p);
182 tcg_temp_free_ptr(p);
185 /* Logical operations */
186 #define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \
187 static void glue(gen_, name)(DisasContext *ctx) \
189 if (unlikely(!ctx->altivec_enabled)) { \
190 gen_exception(ctx, POWERPC_EXCP_VPU); \
191 return; \
193 tcg_op(cpu_avrh[rD(ctx->opcode)], cpu_avrh[rA(ctx->opcode)], cpu_avrh[rB(ctx->opcode)]); \
194 tcg_op(cpu_avrl[rD(ctx->opcode)], cpu_avrl[rA(ctx->opcode)], cpu_avrl[rB(ctx->opcode)]); \
197 GEN_VX_LOGICAL(vand, tcg_gen_and_i64, 2, 16);
198 GEN_VX_LOGICAL(vandc, tcg_gen_andc_i64, 2, 17);
199 GEN_VX_LOGICAL(vor, tcg_gen_or_i64, 2, 18);
200 GEN_VX_LOGICAL(vxor, tcg_gen_xor_i64, 2, 19);
201 GEN_VX_LOGICAL(vnor, tcg_gen_nor_i64, 2, 20);
202 GEN_VX_LOGICAL(veqv, tcg_gen_eqv_i64, 2, 26);
203 GEN_VX_LOGICAL(vnand, tcg_gen_nand_i64, 2, 22);
204 GEN_VX_LOGICAL(vorc, tcg_gen_orc_i64, 2, 21);
206 #define GEN_VXFORM(name, opc2, opc3) \
207 static void glue(gen_, name)(DisasContext *ctx) \
209 TCGv_ptr ra, rb, rd; \
210 if (unlikely(!ctx->altivec_enabled)) { \
211 gen_exception(ctx, POWERPC_EXCP_VPU); \
212 return; \
214 ra = gen_avr_ptr(rA(ctx->opcode)); \
215 rb = gen_avr_ptr(rB(ctx->opcode)); \
216 rd = gen_avr_ptr(rD(ctx->opcode)); \
217 gen_helper_##name (rd, ra, rb); \
218 tcg_temp_free_ptr(ra); \
219 tcg_temp_free_ptr(rb); \
220 tcg_temp_free_ptr(rd); \
223 #define GEN_VXFORM_ENV(name, opc2, opc3) \
224 static void glue(gen_, name)(DisasContext *ctx) \
226 TCGv_ptr ra, rb, rd; \
227 if (unlikely(!ctx->altivec_enabled)) { \
228 gen_exception(ctx, POWERPC_EXCP_VPU); \
229 return; \
231 ra = gen_avr_ptr(rA(ctx->opcode)); \
232 rb = gen_avr_ptr(rB(ctx->opcode)); \
233 rd = gen_avr_ptr(rD(ctx->opcode)); \
234 gen_helper_##name(cpu_env, rd, ra, rb); \
235 tcg_temp_free_ptr(ra); \
236 tcg_temp_free_ptr(rb); \
237 tcg_temp_free_ptr(rd); \
240 #define GEN_VXFORM3(name, opc2, opc3) \
241 static void glue(gen_, name)(DisasContext *ctx) \
243 TCGv_ptr ra, rb, rc, rd; \
244 if (unlikely(!ctx->altivec_enabled)) { \
245 gen_exception(ctx, POWERPC_EXCP_VPU); \
246 return; \
248 ra = gen_avr_ptr(rA(ctx->opcode)); \
249 rb = gen_avr_ptr(rB(ctx->opcode)); \
250 rc = gen_avr_ptr(rC(ctx->opcode)); \
251 rd = gen_avr_ptr(rD(ctx->opcode)); \
252 gen_helper_##name(rd, ra, rb, rc); \
253 tcg_temp_free_ptr(ra); \
254 tcg_temp_free_ptr(rb); \
255 tcg_temp_free_ptr(rc); \
256 tcg_temp_free_ptr(rd); \
260 * Support for Altivec instruction pairs that use bit 31 (Rc) as
261 * an opcode bit. In general, these pairs come from different
262 * versions of the ISA, so we must also support a pair of flags for
263 * each instruction.
265 #define GEN_VXFORM_DUAL(name0, flg0, flg2_0, name1, flg1, flg2_1) \
266 static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
268 if ((Rc(ctx->opcode) == 0) && \
269 ((ctx->insns_flags & flg0) || (ctx->insns_flags2 & flg2_0))) { \
270 gen_##name0(ctx); \
271 } else if ((Rc(ctx->opcode) == 1) && \
272 ((ctx->insns_flags & flg1) || (ctx->insns_flags2 & flg2_1))) { \
273 gen_##name1(ctx); \
274 } else { \
275 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
279 GEN_VXFORM(vaddubm, 0, 0);
280 GEN_VXFORM(vadduhm, 0, 1);
281 GEN_VXFORM(vadduwm, 0, 2);
282 GEN_VXFORM(vaddudm, 0, 3);
283 GEN_VXFORM(vsububm, 0, 16);
284 GEN_VXFORM(vsubuhm, 0, 17);
285 GEN_VXFORM(vsubuwm, 0, 18);
286 GEN_VXFORM(vsubudm, 0, 19);
287 GEN_VXFORM(vmaxub, 1, 0);
288 GEN_VXFORM(vmaxuh, 1, 1);
289 GEN_VXFORM(vmaxuw, 1, 2);
290 GEN_VXFORM(vmaxud, 1, 3);
291 GEN_VXFORM(vmaxsb, 1, 4);
292 GEN_VXFORM(vmaxsh, 1, 5);
293 GEN_VXFORM(vmaxsw, 1, 6);
294 GEN_VXFORM(vmaxsd, 1, 7);
295 GEN_VXFORM(vminub, 1, 8);
296 GEN_VXFORM(vminuh, 1, 9);
297 GEN_VXFORM(vminuw, 1, 10);
298 GEN_VXFORM(vminud, 1, 11);
299 GEN_VXFORM(vminsb, 1, 12);
300 GEN_VXFORM(vminsh, 1, 13);
301 GEN_VXFORM(vminsw, 1, 14);
302 GEN_VXFORM(vminsd, 1, 15);
303 GEN_VXFORM(vavgub, 1, 16);
304 GEN_VXFORM(vabsdub, 1, 16);
305 GEN_VXFORM_DUAL(vavgub, PPC_ALTIVEC, PPC_NONE, \
306 vabsdub, PPC_NONE, PPC2_ISA300)
307 GEN_VXFORM(vavguh, 1, 17);
308 GEN_VXFORM(vabsduh, 1, 17);
309 GEN_VXFORM_DUAL(vavguh, PPC_ALTIVEC, PPC_NONE, \
310 vabsduh, PPC_NONE, PPC2_ISA300)
311 GEN_VXFORM(vavguw, 1, 18);
312 GEN_VXFORM(vabsduw, 1, 18);
313 GEN_VXFORM_DUAL(vavguw, PPC_ALTIVEC, PPC_NONE, \
314 vabsduw, PPC_NONE, PPC2_ISA300)
315 GEN_VXFORM(vavgsb, 1, 20);
316 GEN_VXFORM(vavgsh, 1, 21);
317 GEN_VXFORM(vavgsw, 1, 22);
318 GEN_VXFORM(vmrghb, 6, 0);
319 GEN_VXFORM(vmrghh, 6, 1);
320 GEN_VXFORM(vmrghw, 6, 2);
321 GEN_VXFORM(vmrglb, 6, 4);
322 GEN_VXFORM(vmrglh, 6, 5);
323 GEN_VXFORM(vmrglw, 6, 6);
325 static void gen_vmrgew(DisasContext *ctx)
327 TCGv_i64 tmp;
328 int VT, VA, VB;
329 if (unlikely(!ctx->altivec_enabled)) {
330 gen_exception(ctx, POWERPC_EXCP_VPU);
331 return;
333 VT = rD(ctx->opcode);
334 VA = rA(ctx->opcode);
335 VB = rB(ctx->opcode);
336 tmp = tcg_temp_new_i64();
337 tcg_gen_shri_i64(tmp, cpu_avrh[VB], 32);
338 tcg_gen_deposit_i64(cpu_avrh[VT], cpu_avrh[VA], tmp, 0, 32);
339 tcg_gen_shri_i64(tmp, cpu_avrl[VB], 32);
340 tcg_gen_deposit_i64(cpu_avrl[VT], cpu_avrl[VA], tmp, 0, 32);
341 tcg_temp_free_i64(tmp);
344 static void gen_vmrgow(DisasContext *ctx)
346 int VT, VA, VB;
347 if (unlikely(!ctx->altivec_enabled)) {
348 gen_exception(ctx, POWERPC_EXCP_VPU);
349 return;
351 VT = rD(ctx->opcode);
352 VA = rA(ctx->opcode);
353 VB = rB(ctx->opcode);
355 tcg_gen_deposit_i64(cpu_avrh[VT], cpu_avrh[VB], cpu_avrh[VA], 32, 32);
356 tcg_gen_deposit_i64(cpu_avrl[VT], cpu_avrl[VB], cpu_avrl[VA], 32, 32);
359 GEN_VXFORM(vmuloub, 4, 0);
360 GEN_VXFORM(vmulouh, 4, 1);
361 GEN_VXFORM(vmulouw, 4, 2);
362 GEN_VXFORM(vmuluwm, 4, 2);
363 GEN_VXFORM_DUAL(vmulouw, PPC_ALTIVEC, PPC_NONE,
364 vmuluwm, PPC_NONE, PPC2_ALTIVEC_207)
365 GEN_VXFORM(vmulosb, 4, 4);
366 GEN_VXFORM(vmulosh, 4, 5);
367 GEN_VXFORM(vmulosw, 4, 6);
368 GEN_VXFORM(vmuleub, 4, 8);
369 GEN_VXFORM(vmuleuh, 4, 9);
370 GEN_VXFORM(vmuleuw, 4, 10);
371 GEN_VXFORM(vmulesb, 4, 12);
372 GEN_VXFORM(vmulesh, 4, 13);
373 GEN_VXFORM(vmulesw, 4, 14);
374 GEN_VXFORM(vslb, 2, 4);
375 GEN_VXFORM(vslh, 2, 5);
376 GEN_VXFORM(vslw, 2, 6);
377 GEN_VXFORM(vsld, 2, 23);
378 GEN_VXFORM(vsrb, 2, 8);
379 GEN_VXFORM(vsrh, 2, 9);
380 GEN_VXFORM(vsrw, 2, 10);
381 GEN_VXFORM(vsrd, 2, 27);
382 GEN_VXFORM(vsrab, 2, 12);
383 GEN_VXFORM(vsrah, 2, 13);
384 GEN_VXFORM(vsraw, 2, 14);
385 GEN_VXFORM(vsrad, 2, 15);
386 GEN_VXFORM(vslo, 6, 16);
387 GEN_VXFORM(vsro, 6, 17);
388 GEN_VXFORM(vaddcuw, 0, 6);
389 GEN_VXFORM(vsubcuw, 0, 22);
390 GEN_VXFORM_ENV(vaddubs, 0, 8);
391 GEN_VXFORM_ENV(vadduhs, 0, 9);
392 GEN_VXFORM_ENV(vadduws, 0, 10);
393 GEN_VXFORM_ENV(vaddsbs, 0, 12);
394 GEN_VXFORM_ENV(vaddshs, 0, 13);
395 GEN_VXFORM_ENV(vaddsws, 0, 14);
396 GEN_VXFORM_ENV(vsububs, 0, 24);
397 GEN_VXFORM_ENV(vsubuhs, 0, 25);
398 GEN_VXFORM_ENV(vsubuws, 0, 26);
399 GEN_VXFORM_ENV(vsubsbs, 0, 28);
400 GEN_VXFORM_ENV(vsubshs, 0, 29);
401 GEN_VXFORM_ENV(vsubsws, 0, 30);
402 GEN_VXFORM(vadduqm, 0, 4);
403 GEN_VXFORM(vaddcuq, 0, 5);
404 GEN_VXFORM3(vaddeuqm, 30, 0);
405 GEN_VXFORM3(vaddecuq, 30, 0);
406 GEN_VXFORM_DUAL(vaddeuqm, PPC_NONE, PPC2_ALTIVEC_207, \
407 vaddecuq, PPC_NONE, PPC2_ALTIVEC_207)
408 GEN_VXFORM(vsubuqm, 0, 20);
409 GEN_VXFORM(vsubcuq, 0, 21);
410 GEN_VXFORM3(vsubeuqm, 31, 0);
411 GEN_VXFORM3(vsubecuq, 31, 0);
412 GEN_VXFORM_DUAL(vsubeuqm, PPC_NONE, PPC2_ALTIVEC_207, \
413 vsubecuq, PPC_NONE, PPC2_ALTIVEC_207)
414 GEN_VXFORM(vrlb, 2, 0);
415 GEN_VXFORM(vrlh, 2, 1);
416 GEN_VXFORM(vrlw, 2, 2);
417 GEN_VXFORM(vrld, 2, 3);
418 GEN_VXFORM(vsl, 2, 7);
419 GEN_VXFORM(vsr, 2, 11);
420 GEN_VXFORM_ENV(vpkuhum, 7, 0);
421 GEN_VXFORM_ENV(vpkuwum, 7, 1);
422 GEN_VXFORM_ENV(vpkudum, 7, 17);
423 GEN_VXFORM_ENV(vpkuhus, 7, 2);
424 GEN_VXFORM_ENV(vpkuwus, 7, 3);
425 GEN_VXFORM_ENV(vpkudus, 7, 19);
426 GEN_VXFORM_ENV(vpkshus, 7, 4);
427 GEN_VXFORM_ENV(vpkswus, 7, 5);
428 GEN_VXFORM_ENV(vpksdus, 7, 21);
429 GEN_VXFORM_ENV(vpkshss, 7, 6);
430 GEN_VXFORM_ENV(vpkswss, 7, 7);
431 GEN_VXFORM_ENV(vpksdss, 7, 23);
432 GEN_VXFORM(vpkpx, 7, 12);
433 GEN_VXFORM_ENV(vsum4ubs, 4, 24);
434 GEN_VXFORM_ENV(vsum4sbs, 4, 28);
435 GEN_VXFORM_ENV(vsum4shs, 4, 25);
436 GEN_VXFORM_ENV(vsum2sws, 4, 26);
437 GEN_VXFORM_ENV(vsumsws, 4, 30);
438 GEN_VXFORM_ENV(vaddfp, 5, 0);
439 GEN_VXFORM_ENV(vsubfp, 5, 1);
440 GEN_VXFORM_ENV(vmaxfp, 5, 16);
441 GEN_VXFORM_ENV(vminfp, 5, 17);
443 #define GEN_VXRFORM1(opname, name, str, opc2, opc3) \
444 static void glue(gen_, name)(DisasContext *ctx) \
446 TCGv_ptr ra, rb, rd; \
447 if (unlikely(!ctx->altivec_enabled)) { \
448 gen_exception(ctx, POWERPC_EXCP_VPU); \
449 return; \
451 ra = gen_avr_ptr(rA(ctx->opcode)); \
452 rb = gen_avr_ptr(rB(ctx->opcode)); \
453 rd = gen_avr_ptr(rD(ctx->opcode)); \
454 gen_helper_##opname(cpu_env, rd, ra, rb); \
455 tcg_temp_free_ptr(ra); \
456 tcg_temp_free_ptr(rb); \
457 tcg_temp_free_ptr(rd); \
460 #define GEN_VXRFORM(name, opc2, opc3) \
461 GEN_VXRFORM1(name, name, #name, opc2, opc3) \
462 GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4)))
465 * Support for Altivec instructions that use bit 31 (Rc) as an opcode
466 * bit but also use bit 21 as an actual Rc bit. In general, thse pairs
467 * come from different versions of the ISA, so we must also support a
468 * pair of flags for each instruction.
470 #define GEN_VXRFORM_DUAL(name0, flg0, flg2_0, name1, flg1, flg2_1) \
471 static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
473 if ((Rc(ctx->opcode) == 0) && \
474 ((ctx->insns_flags & flg0) || (ctx->insns_flags2 & flg2_0))) { \
475 if (Rc21(ctx->opcode) == 0) { \
476 gen_##name0(ctx); \
477 } else { \
478 gen_##name0##_(ctx); \
480 } else if ((Rc(ctx->opcode) == 1) && \
481 ((ctx->insns_flags & flg1) || (ctx->insns_flags2 & flg2_1))) { \
482 if (Rc21(ctx->opcode) == 0) { \
483 gen_##name1(ctx); \
484 } else { \
485 gen_##name1##_(ctx); \
487 } else { \
488 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
492 GEN_VXRFORM(vcmpequb, 3, 0)
493 GEN_VXRFORM(vcmpequh, 3, 1)
494 GEN_VXRFORM(vcmpequw, 3, 2)
495 GEN_VXRFORM(vcmpequd, 3, 3)
496 GEN_VXRFORM(vcmpgtsb, 3, 12)
497 GEN_VXRFORM(vcmpgtsh, 3, 13)
498 GEN_VXRFORM(vcmpgtsw, 3, 14)
499 GEN_VXRFORM(vcmpgtsd, 3, 15)
500 GEN_VXRFORM(vcmpgtub, 3, 8)
501 GEN_VXRFORM(vcmpgtuh, 3, 9)
502 GEN_VXRFORM(vcmpgtuw, 3, 10)
503 GEN_VXRFORM(vcmpgtud, 3, 11)
504 GEN_VXRFORM(vcmpeqfp, 3, 3)
505 GEN_VXRFORM(vcmpgefp, 3, 7)
506 GEN_VXRFORM(vcmpgtfp, 3, 11)
507 GEN_VXRFORM(vcmpbfp, 3, 15)
509 GEN_VXRFORM_DUAL(vcmpeqfp, PPC_ALTIVEC, PPC_NONE, \
510 vcmpequd, PPC_NONE, PPC2_ALTIVEC_207)
511 GEN_VXRFORM_DUAL(vcmpbfp, PPC_ALTIVEC, PPC_NONE, \
512 vcmpgtsd, PPC_NONE, PPC2_ALTIVEC_207)
513 GEN_VXRFORM_DUAL(vcmpgtfp, PPC_ALTIVEC, PPC_NONE, \
514 vcmpgtud, PPC_NONE, PPC2_ALTIVEC_207)
516 #define GEN_VXFORM_SIMM(name, opc2, opc3) \
517 static void glue(gen_, name)(DisasContext *ctx) \
519 TCGv_ptr rd; \
520 TCGv_i32 simm; \
521 if (unlikely(!ctx->altivec_enabled)) { \
522 gen_exception(ctx, POWERPC_EXCP_VPU); \
523 return; \
525 simm = tcg_const_i32(SIMM5(ctx->opcode)); \
526 rd = gen_avr_ptr(rD(ctx->opcode)); \
527 gen_helper_##name (rd, simm); \
528 tcg_temp_free_i32(simm); \
529 tcg_temp_free_ptr(rd); \
532 GEN_VXFORM_SIMM(vspltisb, 6, 12);
533 GEN_VXFORM_SIMM(vspltish, 6, 13);
534 GEN_VXFORM_SIMM(vspltisw, 6, 14);
536 #define GEN_VXFORM_NOA(name, opc2, opc3) \
537 static void glue(gen_, name)(DisasContext *ctx) \
539 TCGv_ptr rb, rd; \
540 if (unlikely(!ctx->altivec_enabled)) { \
541 gen_exception(ctx, POWERPC_EXCP_VPU); \
542 return; \
544 rb = gen_avr_ptr(rB(ctx->opcode)); \
545 rd = gen_avr_ptr(rD(ctx->opcode)); \
546 gen_helper_##name (rd, rb); \
547 tcg_temp_free_ptr(rb); \
548 tcg_temp_free_ptr(rd); \
551 #define GEN_VXFORM_NOA_ENV(name, opc2, opc3) \
552 static void glue(gen_, name)(DisasContext *ctx) \
554 TCGv_ptr rb, rd; \
556 if (unlikely(!ctx->altivec_enabled)) { \
557 gen_exception(ctx, POWERPC_EXCP_VPU); \
558 return; \
560 rb = gen_avr_ptr(rB(ctx->opcode)); \
561 rd = gen_avr_ptr(rD(ctx->opcode)); \
562 gen_helper_##name(cpu_env, rd, rb); \
563 tcg_temp_free_ptr(rb); \
564 tcg_temp_free_ptr(rd); \
567 GEN_VXFORM_NOA(vupkhsb, 7, 8);
568 GEN_VXFORM_NOA(vupkhsh, 7, 9);
569 GEN_VXFORM_NOA(vupkhsw, 7, 25);
570 GEN_VXFORM_NOA(vupklsb, 7, 10);
571 GEN_VXFORM_NOA(vupklsh, 7, 11);
572 GEN_VXFORM_NOA(vupklsw, 7, 27);
573 GEN_VXFORM_NOA(vupkhpx, 7, 13);
574 GEN_VXFORM_NOA(vupklpx, 7, 15);
575 GEN_VXFORM_NOA_ENV(vrefp, 5, 4);
576 GEN_VXFORM_NOA_ENV(vrsqrtefp, 5, 5);
577 GEN_VXFORM_NOA_ENV(vexptefp, 5, 6);
578 GEN_VXFORM_NOA_ENV(vlogefp, 5, 7);
579 GEN_VXFORM_NOA_ENV(vrfim, 5, 11);
580 GEN_VXFORM_NOA_ENV(vrfin, 5, 8);
581 GEN_VXFORM_NOA_ENV(vrfip, 5, 10);
582 GEN_VXFORM_NOA_ENV(vrfiz, 5, 9);
584 #define GEN_VXFORM_SIMM(name, opc2, opc3) \
585 static void glue(gen_, name)(DisasContext *ctx) \
587 TCGv_ptr rd; \
588 TCGv_i32 simm; \
589 if (unlikely(!ctx->altivec_enabled)) { \
590 gen_exception(ctx, POWERPC_EXCP_VPU); \
591 return; \
593 simm = tcg_const_i32(SIMM5(ctx->opcode)); \
594 rd = gen_avr_ptr(rD(ctx->opcode)); \
595 gen_helper_##name (rd, simm); \
596 tcg_temp_free_i32(simm); \
597 tcg_temp_free_ptr(rd); \
600 #define GEN_VXFORM_UIMM(name, opc2, opc3) \
601 static void glue(gen_, name)(DisasContext *ctx) \
603 TCGv_ptr rb, rd; \
604 TCGv_i32 uimm; \
605 if (unlikely(!ctx->altivec_enabled)) { \
606 gen_exception(ctx, POWERPC_EXCP_VPU); \
607 return; \
609 uimm = tcg_const_i32(UIMM5(ctx->opcode)); \
610 rb = gen_avr_ptr(rB(ctx->opcode)); \
611 rd = gen_avr_ptr(rD(ctx->opcode)); \
612 gen_helper_##name (rd, rb, uimm); \
613 tcg_temp_free_i32(uimm); \
614 tcg_temp_free_ptr(rb); \
615 tcg_temp_free_ptr(rd); \
618 #define GEN_VXFORM_UIMM_ENV(name, opc2, opc3) \
619 static void glue(gen_, name)(DisasContext *ctx) \
621 TCGv_ptr rb, rd; \
622 TCGv_i32 uimm; \
624 if (unlikely(!ctx->altivec_enabled)) { \
625 gen_exception(ctx, POWERPC_EXCP_VPU); \
626 return; \
628 uimm = tcg_const_i32(UIMM5(ctx->opcode)); \
629 rb = gen_avr_ptr(rB(ctx->opcode)); \
630 rd = gen_avr_ptr(rD(ctx->opcode)); \
631 gen_helper_##name(cpu_env, rd, rb, uimm); \
632 tcg_temp_free_i32(uimm); \
633 tcg_temp_free_ptr(rb); \
634 tcg_temp_free_ptr(rd); \
637 GEN_VXFORM_UIMM(vspltb, 6, 8);
638 GEN_VXFORM_UIMM(vsplth, 6, 9);
639 GEN_VXFORM_UIMM(vspltw, 6, 10);
640 GEN_VXFORM_UIMM_ENV(vcfux, 5, 12);
641 GEN_VXFORM_UIMM_ENV(vcfsx, 5, 13);
642 GEN_VXFORM_UIMM_ENV(vctuxs, 5, 14);
643 GEN_VXFORM_UIMM_ENV(vctsxs, 5, 15);
645 static void gen_vsldoi(DisasContext *ctx)
647 TCGv_ptr ra, rb, rd;
648 TCGv_i32 sh;
649 if (unlikely(!ctx->altivec_enabled)) {
650 gen_exception(ctx, POWERPC_EXCP_VPU);
651 return;
653 ra = gen_avr_ptr(rA(ctx->opcode));
654 rb = gen_avr_ptr(rB(ctx->opcode));
655 rd = gen_avr_ptr(rD(ctx->opcode));
656 sh = tcg_const_i32(VSH(ctx->opcode));
657 gen_helper_vsldoi (rd, ra, rb, sh);
658 tcg_temp_free_ptr(ra);
659 tcg_temp_free_ptr(rb);
660 tcg_temp_free_ptr(rd);
661 tcg_temp_free_i32(sh);
664 #define GEN_VAFORM_PAIRED(name0, name1, opc2) \
665 static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
667 TCGv_ptr ra, rb, rc, rd; \
668 if (unlikely(!ctx->altivec_enabled)) { \
669 gen_exception(ctx, POWERPC_EXCP_VPU); \
670 return; \
672 ra = gen_avr_ptr(rA(ctx->opcode)); \
673 rb = gen_avr_ptr(rB(ctx->opcode)); \
674 rc = gen_avr_ptr(rC(ctx->opcode)); \
675 rd = gen_avr_ptr(rD(ctx->opcode)); \
676 if (Rc(ctx->opcode)) { \
677 gen_helper_##name1(cpu_env, rd, ra, rb, rc); \
678 } else { \
679 gen_helper_##name0(cpu_env, rd, ra, rb, rc); \
681 tcg_temp_free_ptr(ra); \
682 tcg_temp_free_ptr(rb); \
683 tcg_temp_free_ptr(rc); \
684 tcg_temp_free_ptr(rd); \
687 GEN_VAFORM_PAIRED(vmhaddshs, vmhraddshs, 16)
689 static void gen_vmladduhm(DisasContext *ctx)
691 TCGv_ptr ra, rb, rc, rd;
692 if (unlikely(!ctx->altivec_enabled)) {
693 gen_exception(ctx, POWERPC_EXCP_VPU);
694 return;
696 ra = gen_avr_ptr(rA(ctx->opcode));
697 rb = gen_avr_ptr(rB(ctx->opcode));
698 rc = gen_avr_ptr(rC(ctx->opcode));
699 rd = gen_avr_ptr(rD(ctx->opcode));
700 gen_helper_vmladduhm(rd, ra, rb, rc);
701 tcg_temp_free_ptr(ra);
702 tcg_temp_free_ptr(rb);
703 tcg_temp_free_ptr(rc);
704 tcg_temp_free_ptr(rd);
707 GEN_VAFORM_PAIRED(vmsumubm, vmsummbm, 18)
708 GEN_VAFORM_PAIRED(vmsumuhm, vmsumuhs, 19)
709 GEN_VAFORM_PAIRED(vmsumshm, vmsumshs, 20)
710 GEN_VAFORM_PAIRED(vsel, vperm, 21)
711 GEN_VAFORM_PAIRED(vmaddfp, vnmsubfp, 23)
713 GEN_VXFORM_NOA(vclzb, 1, 28)
714 GEN_VXFORM_NOA(vclzh, 1, 29)
715 GEN_VXFORM_NOA(vclzw, 1, 30)
716 GEN_VXFORM_NOA(vclzd, 1, 31)
717 GEN_VXFORM_NOA(vpopcntb, 1, 28)
718 GEN_VXFORM_NOA(vpopcnth, 1, 29)
719 GEN_VXFORM_NOA(vpopcntw, 1, 30)
720 GEN_VXFORM_NOA(vpopcntd, 1, 31)
721 GEN_VXFORM_DUAL(vclzb, PPC_NONE, PPC2_ALTIVEC_207, \
722 vpopcntb, PPC_NONE, PPC2_ALTIVEC_207)
723 GEN_VXFORM_DUAL(vclzh, PPC_NONE, PPC2_ALTIVEC_207, \
724 vpopcnth, PPC_NONE, PPC2_ALTIVEC_207)
725 GEN_VXFORM_DUAL(vclzw, PPC_NONE, PPC2_ALTIVEC_207, \
726 vpopcntw, PPC_NONE, PPC2_ALTIVEC_207)
727 GEN_VXFORM_DUAL(vclzd, PPC_NONE, PPC2_ALTIVEC_207, \
728 vpopcntd, PPC_NONE, PPC2_ALTIVEC_207)
729 GEN_VXFORM(vbpermq, 6, 21);
730 GEN_VXFORM_NOA(vgbbd, 6, 20);
731 GEN_VXFORM(vpmsumb, 4, 16)
732 GEN_VXFORM(vpmsumh, 4, 17)
733 GEN_VXFORM(vpmsumw, 4, 18)
734 GEN_VXFORM(vpmsumd, 4, 19)
736 #define GEN_BCD(op) \
737 static void gen_##op(DisasContext *ctx) \
739 TCGv_ptr ra, rb, rd; \
740 TCGv_i32 ps; \
742 if (unlikely(!ctx->altivec_enabled)) { \
743 gen_exception(ctx, POWERPC_EXCP_VPU); \
744 return; \
747 ra = gen_avr_ptr(rA(ctx->opcode)); \
748 rb = gen_avr_ptr(rB(ctx->opcode)); \
749 rd = gen_avr_ptr(rD(ctx->opcode)); \
751 ps = tcg_const_i32((ctx->opcode & 0x200) != 0); \
753 gen_helper_##op(cpu_crf[6], rd, ra, rb, ps); \
755 tcg_temp_free_ptr(ra); \
756 tcg_temp_free_ptr(rb); \
757 tcg_temp_free_ptr(rd); \
758 tcg_temp_free_i32(ps); \
761 GEN_BCD(bcdadd)
762 GEN_BCD(bcdsub)
764 GEN_VXFORM_DUAL(vsububm, PPC_ALTIVEC, PPC_NONE, \
765 bcdadd, PPC_NONE, PPC2_ALTIVEC_207)
766 GEN_VXFORM_DUAL(vsububs, PPC_ALTIVEC, PPC_NONE, \
767 bcdadd, PPC_NONE, PPC2_ALTIVEC_207)
768 GEN_VXFORM_DUAL(vsubuhm, PPC_ALTIVEC, PPC_NONE, \
769 bcdsub, PPC_NONE, PPC2_ALTIVEC_207)
770 GEN_VXFORM_DUAL(vsubuhs, PPC_ALTIVEC, PPC_NONE, \
771 bcdsub, PPC_NONE, PPC2_ALTIVEC_207)
773 static void gen_vsbox(DisasContext *ctx)
775 TCGv_ptr ra, rd;
776 if (unlikely(!ctx->altivec_enabled)) {
777 gen_exception(ctx, POWERPC_EXCP_VPU);
778 return;
780 ra = gen_avr_ptr(rA(ctx->opcode));
781 rd = gen_avr_ptr(rD(ctx->opcode));
782 gen_helper_vsbox(rd, ra);
783 tcg_temp_free_ptr(ra);
784 tcg_temp_free_ptr(rd);
787 GEN_VXFORM(vcipher, 4, 20)
788 GEN_VXFORM(vcipherlast, 4, 20)
789 GEN_VXFORM(vncipher, 4, 21)
790 GEN_VXFORM(vncipherlast, 4, 21)
792 GEN_VXFORM_DUAL(vcipher, PPC_NONE, PPC2_ALTIVEC_207,
793 vcipherlast, PPC_NONE, PPC2_ALTIVEC_207)
794 GEN_VXFORM_DUAL(vncipher, PPC_NONE, PPC2_ALTIVEC_207,
795 vncipherlast, PPC_NONE, PPC2_ALTIVEC_207)
797 #define VSHASIGMA(op) \
798 static void gen_##op(DisasContext *ctx) \
800 TCGv_ptr ra, rd; \
801 TCGv_i32 st_six; \
802 if (unlikely(!ctx->altivec_enabled)) { \
803 gen_exception(ctx, POWERPC_EXCP_VPU); \
804 return; \
806 ra = gen_avr_ptr(rA(ctx->opcode)); \
807 rd = gen_avr_ptr(rD(ctx->opcode)); \
808 st_six = tcg_const_i32(rB(ctx->opcode)); \
809 gen_helper_##op(rd, ra, st_six); \
810 tcg_temp_free_ptr(ra); \
811 tcg_temp_free_ptr(rd); \
812 tcg_temp_free_i32(st_six); \
815 VSHASIGMA(vshasigmaw)
816 VSHASIGMA(vshasigmad)
818 GEN_VXFORM3(vpermxor, 22, 0xFF)
819 GEN_VXFORM_DUAL(vsldoi, PPC_ALTIVEC, PPC_NONE,
820 vpermxor, PPC_NONE, PPC2_ALTIVEC_207)
822 #undef GEN_VR_LDX
823 #undef GEN_VR_STX
824 #undef GEN_VR_LVE
825 #undef GEN_VR_STVE
827 #undef GEN_VX_LOGICAL
828 #undef GEN_VX_LOGICAL_207
829 #undef GEN_VXFORM
830 #undef GEN_VXFORM_207
831 #undef GEN_VXFORM_DUAL
832 #undef GEN_VXRFORM_DUAL
833 #undef GEN_VXRFORM1
834 #undef GEN_VXRFORM
835 #undef GEN_VXFORM_SIMM
836 #undef GEN_VXFORM_NOA
837 #undef GEN_VXFORM_UIMM
838 #undef GEN_VAFORM_PAIRED