2 * PowerPC emulation for qemu: main translation routines.
4 * Copyright (c) 2003-2007 Jocelyn Mayer
5 * Copyright (C) 2011 Freescale Semiconductor, Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
22 #include "disas/disas.h"
24 #include "qemu/host-utils.h"
25 #include "exec/cpu_ldst.h"
27 #include "exec/helper-proto.h"
28 #include "exec/helper-gen.h"
30 #define CPU_SINGLE_STEP 0x1
31 #define CPU_BRANCH_STEP 0x2
32 #define GDBSTUB_SINGLE_STEP 0x4
34 /* Include definitions for instructions classes and implementations flags */
35 //#define PPC_DEBUG_DISAS
36 //#define DO_PPC_STATISTICS
38 #ifdef PPC_DEBUG_DISAS
39 # define LOG_DISAS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
41 # define LOG_DISAS(...) do { } while (0)
43 /*****************************************************************************/
44 /* Code translation helpers */
46 /* global register indexes */
47 static TCGv_ptr cpu_env;
48 static char cpu_reg_names[10*3 + 22*4 /* GPR */
49 #if !defined(TARGET_PPC64)
50 + 10*4 + 22*5 /* SPE GPRh */
52 + 10*4 + 22*5 /* FPR */
53 + 2*(10*6 + 22*7) /* AVRh, AVRl */
54 + 10*5 + 22*6 /* VSR */
56 static TCGv cpu_gpr[32];
57 #if !defined(TARGET_PPC64)
58 static TCGv cpu_gprh[32];
60 static TCGv_i64 cpu_fpr[32];
61 static TCGv_i64 cpu_avrh[32], cpu_avrl[32];
62 static TCGv_i64 cpu_vsr[32];
63 static TCGv_i32 cpu_crf[8];
68 #if defined(TARGET_PPC64)
71 static TCGv cpu_xer, cpu_so, cpu_ov, cpu_ca;
72 static TCGv cpu_reserve;
73 static TCGv cpu_fpscr;
74 static TCGv_i32 cpu_access_type;
76 #include "exec/gen-icount.h"
78 void ppc_translate_init(void)
82 size_t cpu_reg_names_size;
83 static int done_init = 0;
88 cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
91 cpu_reg_names_size = sizeof(cpu_reg_names);
93 for (i = 0; i < 8; i++) {
94 snprintf(p, cpu_reg_names_size, "crf%d", i);
95 cpu_crf[i] = tcg_global_mem_new_i32(TCG_AREG0,
96 offsetof(CPUPPCState, crf[i]), p);
98 cpu_reg_names_size -= 5;
101 for (i = 0; i < 32; i++) {
102 snprintf(p, cpu_reg_names_size, "r%d", i);
103 cpu_gpr[i] = tcg_global_mem_new(TCG_AREG0,
104 offsetof(CPUPPCState, gpr[i]), p);
105 p += (i < 10) ? 3 : 4;
106 cpu_reg_names_size -= (i < 10) ? 3 : 4;
107 #if !defined(TARGET_PPC64)
108 snprintf(p, cpu_reg_names_size, "r%dH", i);
109 cpu_gprh[i] = tcg_global_mem_new_i32(TCG_AREG0,
110 offsetof(CPUPPCState, gprh[i]), p);
111 p += (i < 10) ? 4 : 5;
112 cpu_reg_names_size -= (i < 10) ? 4 : 5;
115 snprintf(p, cpu_reg_names_size, "fp%d", i);
116 cpu_fpr[i] = tcg_global_mem_new_i64(TCG_AREG0,
117 offsetof(CPUPPCState, fpr[i]), p);
118 p += (i < 10) ? 4 : 5;
119 cpu_reg_names_size -= (i < 10) ? 4 : 5;
121 snprintf(p, cpu_reg_names_size, "avr%dH", i);
122 #ifdef HOST_WORDS_BIGENDIAN
123 cpu_avrh[i] = tcg_global_mem_new_i64(TCG_AREG0,
124 offsetof(CPUPPCState, avr[i].u64[0]), p);
126 cpu_avrh[i] = tcg_global_mem_new_i64(TCG_AREG0,
127 offsetof(CPUPPCState, avr[i].u64[1]), p);
129 p += (i < 10) ? 6 : 7;
130 cpu_reg_names_size -= (i < 10) ? 6 : 7;
132 snprintf(p, cpu_reg_names_size, "avr%dL", i);
133 #ifdef HOST_WORDS_BIGENDIAN
134 cpu_avrl[i] = tcg_global_mem_new_i64(TCG_AREG0,
135 offsetof(CPUPPCState, avr[i].u64[1]), p);
137 cpu_avrl[i] = tcg_global_mem_new_i64(TCG_AREG0,
138 offsetof(CPUPPCState, avr[i].u64[0]), p);
140 p += (i < 10) ? 6 : 7;
141 cpu_reg_names_size -= (i < 10) ? 6 : 7;
142 snprintf(p, cpu_reg_names_size, "vsr%d", i);
143 cpu_vsr[i] = tcg_global_mem_new_i64(TCG_AREG0,
144 offsetof(CPUPPCState, vsr[i]), p);
145 p += (i < 10) ? 5 : 6;
146 cpu_reg_names_size -= (i < 10) ? 5 : 6;
149 cpu_nip = tcg_global_mem_new(TCG_AREG0,
150 offsetof(CPUPPCState, nip), "nip");
152 cpu_msr = tcg_global_mem_new(TCG_AREG0,
153 offsetof(CPUPPCState, msr), "msr");
155 cpu_ctr = tcg_global_mem_new(TCG_AREG0,
156 offsetof(CPUPPCState, ctr), "ctr");
158 cpu_lr = tcg_global_mem_new(TCG_AREG0,
159 offsetof(CPUPPCState, lr), "lr");
161 #if defined(TARGET_PPC64)
162 cpu_cfar = tcg_global_mem_new(TCG_AREG0,
163 offsetof(CPUPPCState, cfar), "cfar");
166 cpu_xer = tcg_global_mem_new(TCG_AREG0,
167 offsetof(CPUPPCState, xer), "xer");
168 cpu_so = tcg_global_mem_new(TCG_AREG0,
169 offsetof(CPUPPCState, so), "SO");
170 cpu_ov = tcg_global_mem_new(TCG_AREG0,
171 offsetof(CPUPPCState, ov), "OV");
172 cpu_ca = tcg_global_mem_new(TCG_AREG0,
173 offsetof(CPUPPCState, ca), "CA");
175 cpu_reserve = tcg_global_mem_new(TCG_AREG0,
176 offsetof(CPUPPCState, reserve_addr),
179 cpu_fpscr = tcg_global_mem_new(TCG_AREG0,
180 offsetof(CPUPPCState, fpscr), "fpscr");
182 cpu_access_type = tcg_global_mem_new_i32(TCG_AREG0,
183 offsetof(CPUPPCState, access_type), "access_type");
188 /* internal defines */
189 typedef struct DisasContext {
190 struct TranslationBlock *tb;
194 /* Routine used to access memory */
197 /* Translation flags */
199 #if defined(TARGET_PPC64)
207 ppc_spr_t *spr_cb; /* Needed to check rights for mfspr/mtspr */
208 int singlestep_enabled;
209 uint64_t insns_flags;
210 uint64_t insns_flags2;
213 /* True when active word size < size of target_long. */
215 # define NARROW_MODE(C) (!(C)->sf_mode)
217 # define NARROW_MODE(C) 0
220 struct opc_handler_t {
221 /* invalid bits for instruction 1 (Rc(opcode) == 0) */
223 /* invalid bits for instruction 2 (Rc(opcode) == 1) */
225 /* instruction type */
227 /* extended instruction type */
230 void (*handler)(DisasContext *ctx);
231 #if defined(DO_PPC_STATISTICS) || defined(PPC_DUMP_CPU)
234 #if defined(DO_PPC_STATISTICS)
239 static inline void gen_reset_fpstatus(void)
241 gen_helper_reset_fpstatus(cpu_env);
244 static inline void gen_compute_fprf(TCGv_i64 arg, int set_fprf, int set_rc)
246 TCGv_i32 t0 = tcg_temp_new_i32();
249 /* This case might be optimized later */
250 tcg_gen_movi_i32(t0, 1);
251 gen_helper_compute_fprf(t0, cpu_env, arg, t0);
252 if (unlikely(set_rc)) {
253 tcg_gen_mov_i32(cpu_crf[1], t0);
255 gen_helper_float_check_status(cpu_env);
256 } else if (unlikely(set_rc)) {
257 /* We always need to compute fpcc */
258 tcg_gen_movi_i32(t0, 0);
259 gen_helper_compute_fprf(t0, cpu_env, arg, t0);
260 tcg_gen_mov_i32(cpu_crf[1], t0);
263 tcg_temp_free_i32(t0);
266 static inline void gen_set_access_type(DisasContext *ctx, int access_type)
268 if (ctx->access_type != access_type) {
269 tcg_gen_movi_i32(cpu_access_type, access_type);
270 ctx->access_type = access_type;
274 static inline void gen_update_nip(DisasContext *ctx, target_ulong nip)
276 if (NARROW_MODE(ctx)) {
279 tcg_gen_movi_tl(cpu_nip, nip);
282 static inline void gen_exception_err(DisasContext *ctx, uint32_t excp, uint32_t error)
285 if (ctx->exception == POWERPC_EXCP_NONE) {
286 gen_update_nip(ctx, ctx->nip);
288 t0 = tcg_const_i32(excp);
289 t1 = tcg_const_i32(error);
290 gen_helper_raise_exception_err(cpu_env, t0, t1);
291 tcg_temp_free_i32(t0);
292 tcg_temp_free_i32(t1);
293 ctx->exception = (excp);
296 static inline void gen_exception(DisasContext *ctx, uint32_t excp)
299 if (ctx->exception == POWERPC_EXCP_NONE) {
300 gen_update_nip(ctx, ctx->nip);
302 t0 = tcg_const_i32(excp);
303 gen_helper_raise_exception(cpu_env, t0);
304 tcg_temp_free_i32(t0);
305 ctx->exception = (excp);
308 static inline void gen_debug_exception(DisasContext *ctx)
312 if ((ctx->exception != POWERPC_EXCP_BRANCH) &&
313 (ctx->exception != POWERPC_EXCP_SYNC)) {
314 gen_update_nip(ctx, ctx->nip);
316 t0 = tcg_const_i32(EXCP_DEBUG);
317 gen_helper_raise_exception(cpu_env, t0);
318 tcg_temp_free_i32(t0);
321 static inline void gen_inval_exception(DisasContext *ctx, uint32_t error)
323 gen_exception_err(ctx, POWERPC_EXCP_PROGRAM, POWERPC_EXCP_INVAL | error);
326 /* Stop translation */
327 static inline void gen_stop_exception(DisasContext *ctx)
329 gen_update_nip(ctx, ctx->nip);
330 ctx->exception = POWERPC_EXCP_STOP;
333 /* No need to update nip here, as execution flow will change */
334 static inline void gen_sync_exception(DisasContext *ctx)
336 ctx->exception = POWERPC_EXCP_SYNC;
339 #define GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
340 GEN_OPCODE(name, opc1, opc2, opc3, inval, type, PPC_NONE)
342 #define GEN_HANDLER_E(name, opc1, opc2, opc3, inval, type, type2) \
343 GEN_OPCODE(name, opc1, opc2, opc3, inval, type, type2)
345 #define GEN_HANDLER2(name, onam, opc1, opc2, opc3, inval, type) \
346 GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, PPC_NONE)
348 #define GEN_HANDLER2_E(name, onam, opc1, opc2, opc3, inval, type, type2) \
349 GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, type2)
351 typedef struct opcode_t {
352 unsigned char opc1, opc2, opc3;
353 #if HOST_LONG_BITS == 64 /* Explicitly align to 64 bits */
354 unsigned char pad[5];
356 unsigned char pad[1];
358 opc_handler_t handler;
362 /*****************************************************************************/
363 /*** Instruction decoding ***/
364 #define EXTRACT_HELPER(name, shift, nb) \
365 static inline uint32_t name(uint32_t opcode) \
367 return (opcode >> (shift)) & ((1 << (nb)) - 1); \
370 #define EXTRACT_SHELPER(name, shift, nb) \
371 static inline int32_t name(uint32_t opcode) \
373 return (int16_t)((opcode >> (shift)) & ((1 << (nb)) - 1)); \
376 #define EXTRACT_HELPER_SPLIT(name, shift1, nb1, shift2, nb2) \
377 static inline uint32_t name(uint32_t opcode) \
379 return (((opcode >> (shift1)) & ((1 << (nb1)) - 1)) << nb2) | \
380 ((opcode >> (shift2)) & ((1 << (nb2)) - 1)); \
383 EXTRACT_HELPER(opc1, 26, 6);
385 EXTRACT_HELPER(opc2, 1, 5);
387 EXTRACT_HELPER(opc3, 6, 5);
388 /* Update Cr0 flags */
389 EXTRACT_HELPER(Rc, 0, 1);
390 /* Update Cr6 flags (Altivec) */
391 EXTRACT_HELPER(Rc21, 10, 1);
393 EXTRACT_HELPER(rD, 21, 5);
395 EXTRACT_HELPER(rS, 21, 5);
397 EXTRACT_HELPER(rA, 16, 5);
399 EXTRACT_HELPER(rB, 11, 5);
401 EXTRACT_HELPER(rC, 6, 5);
403 EXTRACT_HELPER(crfD, 23, 3);
404 EXTRACT_HELPER(crfS, 18, 3);
405 EXTRACT_HELPER(crbD, 21, 5);
406 EXTRACT_HELPER(crbA, 16, 5);
407 EXTRACT_HELPER(crbB, 11, 5);
409 EXTRACT_HELPER(_SPR, 11, 10);
410 static inline uint32_t SPR(uint32_t opcode)
412 uint32_t sprn = _SPR(opcode);
414 return ((sprn >> 5) & 0x1F) | ((sprn & 0x1F) << 5);
416 /*** Get constants ***/
417 EXTRACT_HELPER(IMM, 12, 8);
418 /* 16 bits signed immediate value */
419 EXTRACT_SHELPER(SIMM, 0, 16);
420 /* 16 bits unsigned immediate value */
421 EXTRACT_HELPER(UIMM, 0, 16);
422 /* 5 bits signed immediate value */
423 EXTRACT_HELPER(SIMM5, 16, 5);
424 /* 5 bits signed immediate value */
425 EXTRACT_HELPER(UIMM5, 16, 5);
427 EXTRACT_HELPER(NB, 11, 5);
429 EXTRACT_HELPER(SH, 11, 5);
430 /* Vector shift count */
431 EXTRACT_HELPER(VSH, 6, 4);
433 EXTRACT_HELPER(MB, 6, 5);
435 EXTRACT_HELPER(ME, 1, 5);
437 EXTRACT_HELPER(TO, 21, 5);
439 EXTRACT_HELPER(CRM, 12, 8);
440 EXTRACT_HELPER(SR, 16, 4);
443 EXTRACT_HELPER(FPBF, 23, 3);
444 EXTRACT_HELPER(FPIMM, 12, 4);
445 EXTRACT_HELPER(FPL, 25, 1);
446 EXTRACT_HELPER(FPFLM, 17, 8);
447 EXTRACT_HELPER(FPW, 16, 1);
449 /*** Jump target decoding ***/
451 EXTRACT_SHELPER(d, 0, 16);
452 /* Immediate address */
453 static inline target_ulong LI(uint32_t opcode)
455 return (opcode >> 0) & 0x03FFFFFC;
458 static inline uint32_t BD(uint32_t opcode)
460 return (opcode >> 0) & 0xFFFC;
463 EXTRACT_HELPER(BO, 21, 5);
464 EXTRACT_HELPER(BI, 16, 5);
465 /* Absolute/relative address */
466 EXTRACT_HELPER(AA, 1, 1);
468 EXTRACT_HELPER(LK, 0, 1);
471 EXTRACT_HELPER(DCM, 10, 6)
474 EXTRACT_HELPER(RMC, 9, 2)
476 /* Create a mask between <start> and <end> bits */
477 static inline target_ulong MASK(uint32_t start, uint32_t end)
481 #if defined(TARGET_PPC64)
482 if (likely(start == 0)) {
483 ret = UINT64_MAX << (63 - end);
484 } else if (likely(end == 63)) {
485 ret = UINT64_MAX >> start;
488 if (likely(start == 0)) {
489 ret = UINT32_MAX << (31 - end);
490 } else if (likely(end == 31)) {
491 ret = UINT32_MAX >> start;
495 ret = (((target_ulong)(-1ULL)) >> (start)) ^
496 (((target_ulong)(-1ULL) >> (end)) >> 1);
497 if (unlikely(start > end))
504 EXTRACT_HELPER_SPLIT(xT, 0, 1, 21, 5);
505 EXTRACT_HELPER_SPLIT(xS, 0, 1, 21, 5);
506 EXTRACT_HELPER_SPLIT(xA, 2, 1, 16, 5);
507 EXTRACT_HELPER_SPLIT(xB, 1, 1, 11, 5);
508 EXTRACT_HELPER_SPLIT(xC, 3, 1, 6, 5);
509 EXTRACT_HELPER(DM, 8, 2);
510 EXTRACT_HELPER(UIM, 16, 2);
511 EXTRACT_HELPER(SHW, 8, 2);
512 EXTRACT_HELPER(SP, 19, 2);
513 /*****************************************************************************/
514 /* PowerPC instructions table */
516 #if defined(DO_PPC_STATISTICS)
517 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \
527 .handler = &gen_##name, \
528 .oname = stringify(name), \
530 .oname = stringify(name), \
532 #define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \
543 .handler = &gen_##name, \
544 .oname = stringify(name), \
546 .oname = stringify(name), \
548 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \
558 .handler = &gen_##name, \
564 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \
574 .handler = &gen_##name, \
576 .oname = stringify(name), \
578 #define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \
589 .handler = &gen_##name, \
591 .oname = stringify(name), \
593 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \
603 .handler = &gen_##name, \
609 /* SPR load/store helpers */
610 static inline void gen_load_spr(TCGv t, int reg)
612 tcg_gen_ld_tl(t, cpu_env, offsetof(CPUPPCState, spr[reg]));
615 static inline void gen_store_spr(int reg, TCGv t)
617 tcg_gen_st_tl(t, cpu_env, offsetof(CPUPPCState, spr[reg]));
620 /* Invalid instruction */
621 static void gen_invalid(DisasContext *ctx)
623 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
626 static opc_handler_t invalid_handler = {
627 .inval1 = 0xFFFFFFFF,
628 .inval2 = 0xFFFFFFFF,
631 .handler = gen_invalid,
634 #if defined(TARGET_PPC64)
635 /* NOTE: as this time, the only use of is_user_mode() is in 64 bit code. And */
636 /* so the function is wrapped in the standard 64-bit ifdef in order to */
637 /* avoid compiler warnings in 32-bit implementations. */
638 static bool is_user_mode(DisasContext *ctx)
640 #if defined(CONFIG_USER_ONLY)
643 return ctx->mem_idx == 0;
648 /*** Integer comparison ***/
650 static inline void gen_op_cmp(TCGv arg0, TCGv arg1, int s, int crf)
652 TCGv t0 = tcg_temp_new();
653 TCGv_i32 t1 = tcg_temp_new_i32();
655 tcg_gen_trunc_tl_i32(cpu_crf[crf], cpu_so);
657 tcg_gen_setcond_tl((s ? TCG_COND_LT: TCG_COND_LTU), t0, arg0, arg1);
658 tcg_gen_trunc_tl_i32(t1, t0);
659 tcg_gen_shli_i32(t1, t1, CRF_LT);
660 tcg_gen_or_i32(cpu_crf[crf], cpu_crf[crf], t1);
662 tcg_gen_setcond_tl((s ? TCG_COND_GT: TCG_COND_GTU), t0, arg0, arg1);
663 tcg_gen_trunc_tl_i32(t1, t0);
664 tcg_gen_shli_i32(t1, t1, CRF_GT);
665 tcg_gen_or_i32(cpu_crf[crf], cpu_crf[crf], t1);
667 tcg_gen_setcond_tl(TCG_COND_EQ, t0, arg0, arg1);
668 tcg_gen_trunc_tl_i32(t1, t0);
669 tcg_gen_shli_i32(t1, t1, CRF_EQ);
670 tcg_gen_or_i32(cpu_crf[crf], cpu_crf[crf], t1);
673 tcg_temp_free_i32(t1);
676 static inline void gen_op_cmpi(TCGv arg0, target_ulong arg1, int s, int crf)
678 TCGv t0 = tcg_const_tl(arg1);
679 gen_op_cmp(arg0, t0, s, crf);
683 static inline void gen_op_cmp32(TCGv arg0, TCGv arg1, int s, int crf)
689 tcg_gen_ext32s_tl(t0, arg0);
690 tcg_gen_ext32s_tl(t1, arg1);
692 tcg_gen_ext32u_tl(t0, arg0);
693 tcg_gen_ext32u_tl(t1, arg1);
695 gen_op_cmp(t0, t1, s, crf);
700 static inline void gen_op_cmpi32(TCGv arg0, target_ulong arg1, int s, int crf)
702 TCGv t0 = tcg_const_tl(arg1);
703 gen_op_cmp32(arg0, t0, s, crf);
707 static inline void gen_set_Rc0(DisasContext *ctx, TCGv reg)
709 if (NARROW_MODE(ctx)) {
710 gen_op_cmpi32(reg, 0, 1, 0);
712 gen_op_cmpi(reg, 0, 1, 0);
717 static void gen_cmp(DisasContext *ctx)
719 if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) {
720 gen_op_cmp(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
721 1, crfD(ctx->opcode));
723 gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
724 1, crfD(ctx->opcode));
729 static void gen_cmpi(DisasContext *ctx)
731 if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) {
732 gen_op_cmpi(cpu_gpr[rA(ctx->opcode)], SIMM(ctx->opcode),
733 1, crfD(ctx->opcode));
735 gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], SIMM(ctx->opcode),
736 1, crfD(ctx->opcode));
741 static void gen_cmpl(DisasContext *ctx)
743 if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) {
744 gen_op_cmp(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
745 0, crfD(ctx->opcode));
747 gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
748 0, crfD(ctx->opcode));
753 static void gen_cmpli(DisasContext *ctx)
755 if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) {
756 gen_op_cmpi(cpu_gpr[rA(ctx->opcode)], UIMM(ctx->opcode),
757 0, crfD(ctx->opcode));
759 gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], UIMM(ctx->opcode),
760 0, crfD(ctx->opcode));
764 /* isel (PowerPC 2.03 specification) */
765 static void gen_isel(DisasContext *ctx)
768 uint32_t bi = rC(ctx->opcode);
772 l1 = gen_new_label();
773 l2 = gen_new_label();
775 mask = 1 << (3 - (bi & 0x03));
776 t0 = tcg_temp_new_i32();
777 tcg_gen_andi_i32(t0, cpu_crf[bi >> 2], mask);
778 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1);
779 if (rA(ctx->opcode) == 0)
780 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
782 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
785 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
787 tcg_temp_free_i32(t0);
790 /* cmpb: PowerPC 2.05 specification */
791 static void gen_cmpb(DisasContext *ctx)
793 gen_helper_cmpb(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)],
794 cpu_gpr[rB(ctx->opcode)]);
797 /*** Integer arithmetic ***/
799 static inline void gen_op_arith_compute_ov(DisasContext *ctx, TCGv arg0,
800 TCGv arg1, TCGv arg2, int sub)
802 TCGv t0 = tcg_temp_new();
804 tcg_gen_xor_tl(cpu_ov, arg0, arg2);
805 tcg_gen_xor_tl(t0, arg1, arg2);
807 tcg_gen_and_tl(cpu_ov, cpu_ov, t0);
809 tcg_gen_andc_tl(cpu_ov, cpu_ov, t0);
812 if (NARROW_MODE(ctx)) {
813 tcg_gen_ext32s_tl(cpu_ov, cpu_ov);
815 tcg_gen_shri_tl(cpu_ov, cpu_ov, TARGET_LONG_BITS - 1);
816 tcg_gen_or_tl(cpu_so, cpu_so, cpu_ov);
819 /* Common add function */
820 static inline void gen_op_arith_add(DisasContext *ctx, TCGv ret, TCGv arg1,
821 TCGv arg2, bool add_ca, bool compute_ca,
822 bool compute_ov, bool compute_rc0)
826 if (compute_ca || compute_ov) {
831 if (NARROW_MODE(ctx)) {
832 /* Caution: a non-obvious corner case of the spec is that we
833 must produce the *entire* 64-bit addition, but produce the
834 carry into bit 32. */
835 TCGv t1 = tcg_temp_new();
836 tcg_gen_xor_tl(t1, arg1, arg2); /* add without carry */
837 tcg_gen_add_tl(t0, arg1, arg2);
839 tcg_gen_add_tl(t0, t0, cpu_ca);
841 tcg_gen_xor_tl(cpu_ca, t0, t1); /* bits changed w/ carry */
843 tcg_gen_shri_tl(cpu_ca, cpu_ca, 32); /* extract bit 32 */
844 tcg_gen_andi_tl(cpu_ca, cpu_ca, 1);
846 TCGv zero = tcg_const_tl(0);
848 tcg_gen_add2_tl(t0, cpu_ca, arg1, zero, cpu_ca, zero);
849 tcg_gen_add2_tl(t0, cpu_ca, t0, cpu_ca, arg2, zero);
851 tcg_gen_add2_tl(t0, cpu_ca, arg1, zero, arg2, zero);
856 tcg_gen_add_tl(t0, arg1, arg2);
858 tcg_gen_add_tl(t0, t0, cpu_ca);
863 gen_op_arith_compute_ov(ctx, t0, arg1, arg2, 0);
865 if (unlikely(compute_rc0)) {
866 gen_set_Rc0(ctx, t0);
869 if (!TCGV_EQUAL(t0, ret)) {
870 tcg_gen_mov_tl(ret, t0);
874 /* Add functions with two operands */
875 #define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
876 static void glue(gen_, name)(DisasContext *ctx) \
878 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
879 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
880 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
882 /* Add functions with one operand and one immediate */
883 #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
884 add_ca, compute_ca, compute_ov) \
885 static void glue(gen_, name)(DisasContext *ctx) \
887 TCGv t0 = tcg_const_tl(const_val); \
888 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
889 cpu_gpr[rA(ctx->opcode)], t0, \
890 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
894 /* add add. addo addo. */
895 GEN_INT_ARITH_ADD(add, 0x08, 0, 0, 0)
896 GEN_INT_ARITH_ADD(addo, 0x18, 0, 0, 1)
897 /* addc addc. addco addco. */
898 GEN_INT_ARITH_ADD(addc, 0x00, 0, 1, 0)
899 GEN_INT_ARITH_ADD(addco, 0x10, 0, 1, 1)
900 /* adde adde. addeo addeo. */
901 GEN_INT_ARITH_ADD(adde, 0x04, 1, 1, 0)
902 GEN_INT_ARITH_ADD(addeo, 0x14, 1, 1, 1)
903 /* addme addme. addmeo addmeo. */
904 GEN_INT_ARITH_ADD_CONST(addme, 0x07, -1LL, 1, 1, 0)
905 GEN_INT_ARITH_ADD_CONST(addmeo, 0x17, -1LL, 1, 1, 1)
906 /* addze addze. addzeo addzeo.*/
907 GEN_INT_ARITH_ADD_CONST(addze, 0x06, 0, 1, 1, 0)
908 GEN_INT_ARITH_ADD_CONST(addzeo, 0x16, 0, 1, 1, 1)
910 static void gen_addi(DisasContext *ctx)
912 target_long simm = SIMM(ctx->opcode);
914 if (rA(ctx->opcode) == 0) {
916 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], simm);
918 tcg_gen_addi_tl(cpu_gpr[rD(ctx->opcode)],
919 cpu_gpr[rA(ctx->opcode)], simm);
923 static inline void gen_op_addic(DisasContext *ctx, bool compute_rc0)
925 TCGv c = tcg_const_tl(SIMM(ctx->opcode));
926 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
927 c, 0, 1, 0, compute_rc0);
931 static void gen_addic(DisasContext *ctx)
933 gen_op_addic(ctx, 0);
936 static void gen_addic_(DisasContext *ctx)
938 gen_op_addic(ctx, 1);
942 static void gen_addis(DisasContext *ctx)
944 target_long simm = SIMM(ctx->opcode);
946 if (rA(ctx->opcode) == 0) {
948 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], simm << 16);
950 tcg_gen_addi_tl(cpu_gpr[rD(ctx->opcode)],
951 cpu_gpr[rA(ctx->opcode)], simm << 16);
955 static inline void gen_op_arith_divw(DisasContext *ctx, TCGv ret, TCGv arg1,
956 TCGv arg2, int sign, int compute_ov)
958 int l1 = gen_new_label();
959 int l2 = gen_new_label();
960 TCGv_i32 t0 = tcg_temp_local_new_i32();
961 TCGv_i32 t1 = tcg_temp_local_new_i32();
963 tcg_gen_trunc_tl_i32(t0, arg1);
964 tcg_gen_trunc_tl_i32(t1, arg2);
965 tcg_gen_brcondi_i32(TCG_COND_EQ, t1, 0, l1);
967 int l3 = gen_new_label();
968 tcg_gen_brcondi_i32(TCG_COND_NE, t1, -1, l3);
969 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, INT32_MIN, l1);
971 tcg_gen_div_i32(t0, t0, t1);
973 tcg_gen_divu_i32(t0, t0, t1);
976 tcg_gen_movi_tl(cpu_ov, 0);
981 tcg_gen_sari_i32(t0, t0, 31);
983 tcg_gen_movi_i32(t0, 0);
986 tcg_gen_movi_tl(cpu_ov, 1);
987 tcg_gen_movi_tl(cpu_so, 1);
990 tcg_gen_extu_i32_tl(ret, t0);
991 tcg_temp_free_i32(t0);
992 tcg_temp_free_i32(t1);
993 if (unlikely(Rc(ctx->opcode) != 0))
994 gen_set_Rc0(ctx, ret);
997 #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
998 static void glue(gen_, name)(DisasContext *ctx) \
1000 gen_op_arith_divw(ctx, cpu_gpr[rD(ctx->opcode)], \
1001 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1002 sign, compute_ov); \
1004 /* divwu divwu. divwuo divwuo. */
1005 GEN_INT_ARITH_DIVW(divwu, 0x0E, 0, 0);
1006 GEN_INT_ARITH_DIVW(divwuo, 0x1E, 0, 1);
1007 /* divw divw. divwo divwo. */
1008 GEN_INT_ARITH_DIVW(divw, 0x0F, 1, 0);
1009 GEN_INT_ARITH_DIVW(divwo, 0x1F, 1, 1);
1011 /* div[wd]eu[o][.] */
1012 #define GEN_DIVE(name, hlpr, compute_ov) \
1013 static void gen_##name(DisasContext *ctx) \
1015 TCGv_i32 t0 = tcg_const_i32(compute_ov); \
1016 gen_helper_##hlpr(cpu_gpr[rD(ctx->opcode)], cpu_env, \
1017 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], t0); \
1018 tcg_temp_free_i32(t0); \
1019 if (unlikely(Rc(ctx->opcode) != 0)) { \
1020 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); \
1024 GEN_DIVE(divweu, divweu, 0);
1025 GEN_DIVE(divweuo, divweu, 1);
1026 GEN_DIVE(divwe, divwe, 0);
1027 GEN_DIVE(divweo, divwe, 1);
1029 #if defined(TARGET_PPC64)
1030 static inline void gen_op_arith_divd(DisasContext *ctx, TCGv ret, TCGv arg1,
1031 TCGv arg2, int sign, int compute_ov)
1033 int l1 = gen_new_label();
1034 int l2 = gen_new_label();
1036 tcg_gen_brcondi_i64(TCG_COND_EQ, arg2, 0, l1);
1038 int l3 = gen_new_label();
1039 tcg_gen_brcondi_i64(TCG_COND_NE, arg2, -1, l3);
1040 tcg_gen_brcondi_i64(TCG_COND_EQ, arg1, INT64_MIN, l1);
1042 tcg_gen_div_i64(ret, arg1, arg2);
1044 tcg_gen_divu_i64(ret, arg1, arg2);
1047 tcg_gen_movi_tl(cpu_ov, 0);
1052 tcg_gen_sari_i64(ret, arg1, 63);
1054 tcg_gen_movi_i64(ret, 0);
1057 tcg_gen_movi_tl(cpu_ov, 1);
1058 tcg_gen_movi_tl(cpu_so, 1);
1061 if (unlikely(Rc(ctx->opcode) != 0))
1062 gen_set_Rc0(ctx, ret);
1064 #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
1065 static void glue(gen_, name)(DisasContext *ctx) \
1067 gen_op_arith_divd(ctx, cpu_gpr[rD(ctx->opcode)], \
1068 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1069 sign, compute_ov); \
1071 /* divwu divwu. divwuo divwuo. */
1072 GEN_INT_ARITH_DIVD(divdu, 0x0E, 0, 0);
1073 GEN_INT_ARITH_DIVD(divduo, 0x1E, 0, 1);
1074 /* divw divw. divwo divwo. */
1075 GEN_INT_ARITH_DIVD(divd, 0x0F, 1, 0);
1076 GEN_INT_ARITH_DIVD(divdo, 0x1F, 1, 1);
1078 GEN_DIVE(divdeu, divdeu, 0);
1079 GEN_DIVE(divdeuo, divdeu, 1);
1080 GEN_DIVE(divde, divde, 0);
1081 GEN_DIVE(divdeo, divde, 1);
1085 static void gen_mulhw(DisasContext *ctx)
1087 TCGv_i32 t0 = tcg_temp_new_i32();
1088 TCGv_i32 t1 = tcg_temp_new_i32();
1090 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]);
1091 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]);
1092 tcg_gen_muls2_i32(t0, t1, t0, t1);
1093 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t1);
1094 tcg_temp_free_i32(t0);
1095 tcg_temp_free_i32(t1);
1096 if (unlikely(Rc(ctx->opcode) != 0))
1097 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1100 /* mulhwu mulhwu. */
1101 static void gen_mulhwu(DisasContext *ctx)
1103 TCGv_i32 t0 = tcg_temp_new_i32();
1104 TCGv_i32 t1 = tcg_temp_new_i32();
1106 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]);
1107 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]);
1108 tcg_gen_mulu2_i32(t0, t1, t0, t1);
1109 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t1);
1110 tcg_temp_free_i32(t0);
1111 tcg_temp_free_i32(t1);
1112 if (unlikely(Rc(ctx->opcode) != 0))
1113 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1117 static void gen_mullw(DisasContext *ctx)
1119 tcg_gen_mul_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1120 cpu_gpr[rB(ctx->opcode)]);
1121 tcg_gen_ext32s_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)]);
1122 if (unlikely(Rc(ctx->opcode) != 0))
1123 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1126 /* mullwo mullwo. */
1127 static void gen_mullwo(DisasContext *ctx)
1129 TCGv_i32 t0 = tcg_temp_new_i32();
1130 TCGv_i32 t1 = tcg_temp_new_i32();
1132 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]);
1133 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]);
1134 tcg_gen_muls2_i32(t0, t1, t0, t1);
1135 tcg_gen_ext_i32_tl(cpu_gpr[rD(ctx->opcode)], t0);
1137 tcg_gen_sari_i32(t0, t0, 31);
1138 tcg_gen_setcond_i32(TCG_COND_NE, t0, t0, t1);
1139 tcg_gen_extu_i32_tl(cpu_ov, t0);
1140 tcg_gen_or_tl(cpu_so, cpu_so, cpu_ov);
1142 tcg_temp_free_i32(t0);
1143 tcg_temp_free_i32(t1);
1144 if (unlikely(Rc(ctx->opcode) != 0))
1145 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1149 static void gen_mulli(DisasContext *ctx)
1151 tcg_gen_muli_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1155 #if defined(TARGET_PPC64)
1157 static void gen_mulhd(DisasContext *ctx)
1159 TCGv lo = tcg_temp_new();
1160 tcg_gen_muls2_tl(lo, cpu_gpr[rD(ctx->opcode)],
1161 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1163 if (unlikely(Rc(ctx->opcode) != 0)) {
1164 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1168 /* mulhdu mulhdu. */
1169 static void gen_mulhdu(DisasContext *ctx)
1171 TCGv lo = tcg_temp_new();
1172 tcg_gen_mulu2_tl(lo, cpu_gpr[rD(ctx->opcode)],
1173 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1175 if (unlikely(Rc(ctx->opcode) != 0)) {
1176 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1181 static void gen_mulld(DisasContext *ctx)
1183 tcg_gen_mul_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1184 cpu_gpr[rB(ctx->opcode)]);
1185 if (unlikely(Rc(ctx->opcode) != 0))
1186 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1189 /* mulldo mulldo. */
1190 static void gen_mulldo(DisasContext *ctx)
1192 gen_helper_mulldo(cpu_gpr[rD(ctx->opcode)], cpu_env,
1193 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1194 if (unlikely(Rc(ctx->opcode) != 0)) {
1195 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1200 /* Common subf function */
1201 static inline void gen_op_arith_subf(DisasContext *ctx, TCGv ret, TCGv arg1,
1202 TCGv arg2, bool add_ca, bool compute_ca,
1203 bool compute_ov, bool compute_rc0)
1207 if (compute_ca || compute_ov) {
1208 t0 = tcg_temp_new();
1212 /* dest = ~arg1 + arg2 [+ ca]. */
1213 if (NARROW_MODE(ctx)) {
1214 /* Caution: a non-obvious corner case of the spec is that we
1215 must produce the *entire* 64-bit addition, but produce the
1216 carry into bit 32. */
1217 TCGv inv1 = tcg_temp_new();
1218 TCGv t1 = tcg_temp_new();
1219 tcg_gen_not_tl(inv1, arg1);
1221 tcg_gen_add_tl(t0, arg2, cpu_ca);
1223 tcg_gen_addi_tl(t0, arg2, 1);
1225 tcg_gen_xor_tl(t1, arg2, inv1); /* add without carry */
1226 tcg_gen_add_tl(t0, t0, inv1);
1227 tcg_temp_free(inv1);
1228 tcg_gen_xor_tl(cpu_ca, t0, t1); /* bits changes w/ carry */
1230 tcg_gen_shri_tl(cpu_ca, cpu_ca, 32); /* extract bit 32 */
1231 tcg_gen_andi_tl(cpu_ca, cpu_ca, 1);
1232 } else if (add_ca) {
1233 TCGv zero, inv1 = tcg_temp_new();
1234 tcg_gen_not_tl(inv1, arg1);
1235 zero = tcg_const_tl(0);
1236 tcg_gen_add2_tl(t0, cpu_ca, arg2, zero, cpu_ca, zero);
1237 tcg_gen_add2_tl(t0, cpu_ca, t0, cpu_ca, inv1, zero);
1238 tcg_temp_free(zero);
1239 tcg_temp_free(inv1);
1241 tcg_gen_setcond_tl(TCG_COND_GEU, cpu_ca, arg2, arg1);
1242 tcg_gen_sub_tl(t0, arg2, arg1);
1244 } else if (add_ca) {
1245 /* Since we're ignoring carry-out, we can simplify the
1246 standard ~arg1 + arg2 + ca to arg2 - arg1 + ca - 1. */
1247 tcg_gen_sub_tl(t0, arg2, arg1);
1248 tcg_gen_add_tl(t0, t0, cpu_ca);
1249 tcg_gen_subi_tl(t0, t0, 1);
1251 tcg_gen_sub_tl(t0, arg2, arg1);
1255 gen_op_arith_compute_ov(ctx, t0, arg1, arg2, 1);
1257 if (unlikely(compute_rc0)) {
1258 gen_set_Rc0(ctx, t0);
1261 if (!TCGV_EQUAL(t0, ret)) {
1262 tcg_gen_mov_tl(ret, t0);
1266 /* Sub functions with Two operands functions */
1267 #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
1268 static void glue(gen_, name)(DisasContext *ctx) \
1270 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1271 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1272 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
1274 /* Sub functions with one operand and one immediate */
1275 #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
1276 add_ca, compute_ca, compute_ov) \
1277 static void glue(gen_, name)(DisasContext *ctx) \
1279 TCGv t0 = tcg_const_tl(const_val); \
1280 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1281 cpu_gpr[rA(ctx->opcode)], t0, \
1282 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
1283 tcg_temp_free(t0); \
1285 /* subf subf. subfo subfo. */
1286 GEN_INT_ARITH_SUBF(subf, 0x01, 0, 0, 0)
1287 GEN_INT_ARITH_SUBF(subfo, 0x11, 0, 0, 1)
1288 /* subfc subfc. subfco subfco. */
1289 GEN_INT_ARITH_SUBF(subfc, 0x00, 0, 1, 0)
1290 GEN_INT_ARITH_SUBF(subfco, 0x10, 0, 1, 1)
1291 /* subfe subfe. subfeo subfo. */
1292 GEN_INT_ARITH_SUBF(subfe, 0x04, 1, 1, 0)
1293 GEN_INT_ARITH_SUBF(subfeo, 0x14, 1, 1, 1)
1294 /* subfme subfme. subfmeo subfmeo. */
1295 GEN_INT_ARITH_SUBF_CONST(subfme, 0x07, -1LL, 1, 1, 0)
1296 GEN_INT_ARITH_SUBF_CONST(subfmeo, 0x17, -1LL, 1, 1, 1)
1297 /* subfze subfze. subfzeo subfzeo.*/
1298 GEN_INT_ARITH_SUBF_CONST(subfze, 0x06, 0, 1, 1, 0)
1299 GEN_INT_ARITH_SUBF_CONST(subfzeo, 0x16, 0, 1, 1, 1)
1302 static void gen_subfic(DisasContext *ctx)
1304 TCGv c = tcg_const_tl(SIMM(ctx->opcode));
1305 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1310 /* neg neg. nego nego. */
1311 static inline void gen_op_arith_neg(DisasContext *ctx, bool compute_ov)
1313 TCGv zero = tcg_const_tl(0);
1314 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1315 zero, 0, 0, compute_ov, Rc(ctx->opcode));
1316 tcg_temp_free(zero);
1319 static void gen_neg(DisasContext *ctx)
1321 gen_op_arith_neg(ctx, 0);
1324 static void gen_nego(DisasContext *ctx)
1326 gen_op_arith_neg(ctx, 1);
1329 /*** Integer logical ***/
1330 #define GEN_LOGICAL2(name, tcg_op, opc, type) \
1331 static void glue(gen_, name)(DisasContext *ctx) \
1333 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], \
1334 cpu_gpr[rB(ctx->opcode)]); \
1335 if (unlikely(Rc(ctx->opcode) != 0)) \
1336 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
1339 #define GEN_LOGICAL1(name, tcg_op, opc, type) \
1340 static void glue(gen_, name)(DisasContext *ctx) \
1342 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); \
1343 if (unlikely(Rc(ctx->opcode) != 0)) \
1344 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
1348 GEN_LOGICAL2(and, tcg_gen_and_tl, 0x00, PPC_INTEGER);
1350 GEN_LOGICAL2(andc, tcg_gen_andc_tl, 0x01, PPC_INTEGER);
1353 static void gen_andi_(DisasContext *ctx)
1355 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], UIMM(ctx->opcode));
1356 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1360 static void gen_andis_(DisasContext *ctx)
1362 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], UIMM(ctx->opcode) << 16);
1363 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1367 static void gen_cntlzw(DisasContext *ctx)
1369 gen_helper_cntlzw(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1370 if (unlikely(Rc(ctx->opcode) != 0))
1371 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1374 GEN_LOGICAL2(eqv, tcg_gen_eqv_tl, 0x08, PPC_INTEGER);
1375 /* extsb & extsb. */
1376 GEN_LOGICAL1(extsb, tcg_gen_ext8s_tl, 0x1D, PPC_INTEGER);
1377 /* extsh & extsh. */
1378 GEN_LOGICAL1(extsh, tcg_gen_ext16s_tl, 0x1C, PPC_INTEGER);
1380 GEN_LOGICAL2(nand, tcg_gen_nand_tl, 0x0E, PPC_INTEGER);
1382 GEN_LOGICAL2(nor, tcg_gen_nor_tl, 0x03, PPC_INTEGER);
1385 static void gen_or(DisasContext *ctx)
1389 rs = rS(ctx->opcode);
1390 ra = rA(ctx->opcode);
1391 rb = rB(ctx->opcode);
1392 /* Optimisation for mr. ri case */
1393 if (rs != ra || rs != rb) {
1395 tcg_gen_or_tl(cpu_gpr[ra], cpu_gpr[rs], cpu_gpr[rb]);
1397 tcg_gen_mov_tl(cpu_gpr[ra], cpu_gpr[rs]);
1398 if (unlikely(Rc(ctx->opcode) != 0))
1399 gen_set_Rc0(ctx, cpu_gpr[ra]);
1400 } else if (unlikely(Rc(ctx->opcode) != 0)) {
1401 gen_set_Rc0(ctx, cpu_gpr[rs]);
1402 #if defined(TARGET_PPC64)
1408 /* Set process priority to low */
1412 /* Set process priority to medium-low */
1416 /* Set process priority to normal */
1419 #if !defined(CONFIG_USER_ONLY)
1421 if (ctx->mem_idx > 0) {
1422 /* Set process priority to very low */
1427 if (ctx->mem_idx > 0) {
1428 /* Set process priority to medium-hight */
1433 if (ctx->mem_idx > 0) {
1434 /* Set process priority to high */
1439 if (ctx->mem_idx > 1) {
1440 /* Set process priority to very high */
1450 TCGv t0 = tcg_temp_new();
1451 gen_load_spr(t0, SPR_PPR);
1452 tcg_gen_andi_tl(t0, t0, ~0x001C000000000000ULL);
1453 tcg_gen_ori_tl(t0, t0, ((uint64_t)prio) << 50);
1454 gen_store_spr(SPR_PPR, t0);
1461 GEN_LOGICAL2(orc, tcg_gen_orc_tl, 0x0C, PPC_INTEGER);
1464 static void gen_xor(DisasContext *ctx)
1466 /* Optimisation for "set to zero" case */
1467 if (rS(ctx->opcode) != rB(ctx->opcode))
1468 tcg_gen_xor_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1470 tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
1471 if (unlikely(Rc(ctx->opcode) != 0))
1472 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1476 static void gen_ori(DisasContext *ctx)
1478 target_ulong uimm = UIMM(ctx->opcode);
1480 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1482 /* XXX: should handle special NOPs for POWER series */
1485 tcg_gen_ori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm);
1489 static void gen_oris(DisasContext *ctx)
1491 target_ulong uimm = UIMM(ctx->opcode);
1493 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1497 tcg_gen_ori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm << 16);
1501 static void gen_xori(DisasContext *ctx)
1503 target_ulong uimm = UIMM(ctx->opcode);
1505 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1509 tcg_gen_xori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm);
1513 static void gen_xoris(DisasContext *ctx)
1515 target_ulong uimm = UIMM(ctx->opcode);
1517 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1521 tcg_gen_xori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm << 16);
1524 /* popcntb : PowerPC 2.03 specification */
1525 static void gen_popcntb(DisasContext *ctx)
1527 gen_helper_popcntb(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1530 static void gen_popcntw(DisasContext *ctx)
1532 gen_helper_popcntw(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1535 #if defined(TARGET_PPC64)
1536 /* popcntd: PowerPC 2.06 specification */
1537 static void gen_popcntd(DisasContext *ctx)
1539 gen_helper_popcntd(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1543 /* prtyw: PowerPC 2.05 specification */
1544 static void gen_prtyw(DisasContext *ctx)
1546 TCGv ra = cpu_gpr[rA(ctx->opcode)];
1547 TCGv rs = cpu_gpr[rS(ctx->opcode)];
1548 TCGv t0 = tcg_temp_new();
1549 tcg_gen_shri_tl(t0, rs, 16);
1550 tcg_gen_xor_tl(ra, rs, t0);
1551 tcg_gen_shri_tl(t0, ra, 8);
1552 tcg_gen_xor_tl(ra, ra, t0);
1553 tcg_gen_andi_tl(ra, ra, (target_ulong)0x100000001ULL);
1557 #if defined(TARGET_PPC64)
1558 /* prtyd: PowerPC 2.05 specification */
1559 static void gen_prtyd(DisasContext *ctx)
1561 TCGv ra = cpu_gpr[rA(ctx->opcode)];
1562 TCGv rs = cpu_gpr[rS(ctx->opcode)];
1563 TCGv t0 = tcg_temp_new();
1564 tcg_gen_shri_tl(t0, rs, 32);
1565 tcg_gen_xor_tl(ra, rs, t0);
1566 tcg_gen_shri_tl(t0, ra, 16);
1567 tcg_gen_xor_tl(ra, ra, t0);
1568 tcg_gen_shri_tl(t0, ra, 8);
1569 tcg_gen_xor_tl(ra, ra, t0);
1570 tcg_gen_andi_tl(ra, ra, 1);
1575 #if defined(TARGET_PPC64)
1577 static void gen_bpermd(DisasContext *ctx)
1579 gen_helper_bpermd(cpu_gpr[rA(ctx->opcode)],
1580 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1584 #if defined(TARGET_PPC64)
1585 /* extsw & extsw. */
1586 GEN_LOGICAL1(extsw, tcg_gen_ext32s_tl, 0x1E, PPC_64B);
1589 static void gen_cntlzd(DisasContext *ctx)
1591 gen_helper_cntlzd(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1592 if (unlikely(Rc(ctx->opcode) != 0))
1593 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1597 /*** Integer rotate ***/
1599 /* rlwimi & rlwimi. */
1600 static void gen_rlwimi(DisasContext *ctx)
1602 uint32_t mb, me, sh;
1604 mb = MB(ctx->opcode);
1605 me = ME(ctx->opcode);
1606 sh = SH(ctx->opcode);
1607 if (likely(sh == 0 && mb == 0 && me == 31)) {
1608 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1612 TCGv t0 = tcg_temp_new();
1613 #if defined(TARGET_PPC64)
1614 TCGv_i32 t2 = tcg_temp_new_i32();
1615 tcg_gen_trunc_i64_i32(t2, cpu_gpr[rS(ctx->opcode)]);
1616 tcg_gen_rotli_i32(t2, t2, sh);
1617 tcg_gen_extu_i32_i64(t0, t2);
1618 tcg_temp_free_i32(t2);
1620 tcg_gen_rotli_i32(t0, cpu_gpr[rS(ctx->opcode)], sh);
1622 #if defined(TARGET_PPC64)
1626 mask = MASK(mb, me);
1627 t1 = tcg_temp_new();
1628 tcg_gen_andi_tl(t0, t0, mask);
1629 tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], ~mask);
1630 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1634 if (unlikely(Rc(ctx->opcode) != 0))
1635 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1638 /* rlwinm & rlwinm. */
1639 static void gen_rlwinm(DisasContext *ctx)
1641 uint32_t mb, me, sh;
1643 sh = SH(ctx->opcode);
1644 mb = MB(ctx->opcode);
1645 me = ME(ctx->opcode);
1647 if (likely(mb == 0 && me == (31 - sh))) {
1648 if (likely(sh == 0)) {
1649 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1651 TCGv t0 = tcg_temp_new();
1652 tcg_gen_ext32u_tl(t0, cpu_gpr[rS(ctx->opcode)]);
1653 tcg_gen_shli_tl(t0, t0, sh);
1654 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], t0);
1657 } else if (likely(sh != 0 && me == 31 && sh == (32 - mb))) {
1658 TCGv t0 = tcg_temp_new();
1659 tcg_gen_ext32u_tl(t0, cpu_gpr[rS(ctx->opcode)]);
1660 tcg_gen_shri_tl(t0, t0, mb);
1661 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], t0);
1664 TCGv t0 = tcg_temp_new();
1665 #if defined(TARGET_PPC64)
1666 TCGv_i32 t1 = tcg_temp_new_i32();
1667 tcg_gen_trunc_i64_i32(t1, cpu_gpr[rS(ctx->opcode)]);
1668 tcg_gen_rotli_i32(t1, t1, sh);
1669 tcg_gen_extu_i32_i64(t0, t1);
1670 tcg_temp_free_i32(t1);
1672 tcg_gen_rotli_i32(t0, cpu_gpr[rS(ctx->opcode)], sh);
1674 #if defined(TARGET_PPC64)
1678 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me));
1681 if (unlikely(Rc(ctx->opcode) != 0))
1682 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1685 /* rlwnm & rlwnm. */
1686 static void gen_rlwnm(DisasContext *ctx)
1690 #if defined(TARGET_PPC64)
1694 mb = MB(ctx->opcode);
1695 me = ME(ctx->opcode);
1696 t0 = tcg_temp_new();
1697 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1f);
1698 #if defined(TARGET_PPC64)
1699 t1 = tcg_temp_new_i32();
1700 t2 = tcg_temp_new_i32();
1701 tcg_gen_trunc_i64_i32(t1, cpu_gpr[rS(ctx->opcode)]);
1702 tcg_gen_trunc_i64_i32(t2, t0);
1703 tcg_gen_rotl_i32(t1, t1, t2);
1704 tcg_gen_extu_i32_i64(t0, t1);
1705 tcg_temp_free_i32(t1);
1706 tcg_temp_free_i32(t2);
1708 tcg_gen_rotl_i32(t0, cpu_gpr[rS(ctx->opcode)], t0);
1710 if (unlikely(mb != 0 || me != 31)) {
1711 #if defined(TARGET_PPC64)
1715 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me));
1717 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
1720 if (unlikely(Rc(ctx->opcode) != 0))
1721 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1724 #if defined(TARGET_PPC64)
1725 #define GEN_PPC64_R2(name, opc1, opc2) \
1726 static void glue(gen_, name##0)(DisasContext *ctx) \
1728 gen_##name(ctx, 0); \
1731 static void glue(gen_, name##1)(DisasContext *ctx) \
1733 gen_##name(ctx, 1); \
1735 #define GEN_PPC64_R4(name, opc1, opc2) \
1736 static void glue(gen_, name##0)(DisasContext *ctx) \
1738 gen_##name(ctx, 0, 0); \
1741 static void glue(gen_, name##1)(DisasContext *ctx) \
1743 gen_##name(ctx, 0, 1); \
1746 static void glue(gen_, name##2)(DisasContext *ctx) \
1748 gen_##name(ctx, 1, 0); \
1751 static void glue(gen_, name##3)(DisasContext *ctx) \
1753 gen_##name(ctx, 1, 1); \
1756 static inline void gen_rldinm(DisasContext *ctx, uint32_t mb, uint32_t me,
1759 if (likely(sh != 0 && mb == 0 && me == (63 - sh))) {
1760 tcg_gen_shli_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], sh);
1761 } else if (likely(sh != 0 && me == 63 && sh == (64 - mb))) {
1762 tcg_gen_shri_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], mb);
1764 TCGv t0 = tcg_temp_new();
1765 tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
1766 if (likely(mb == 0 && me == 63)) {
1767 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
1769 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me));
1773 if (unlikely(Rc(ctx->opcode) != 0))
1774 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1776 /* rldicl - rldicl. */
1777 static inline void gen_rldicl(DisasContext *ctx, int mbn, int shn)
1781 sh = SH(ctx->opcode) | (shn << 5);
1782 mb = MB(ctx->opcode) | (mbn << 5);
1783 gen_rldinm(ctx, mb, 63, sh);
1785 GEN_PPC64_R4(rldicl, 0x1E, 0x00);
1786 /* rldicr - rldicr. */
1787 static inline void gen_rldicr(DisasContext *ctx, int men, int shn)
1791 sh = SH(ctx->opcode) | (shn << 5);
1792 me = MB(ctx->opcode) | (men << 5);
1793 gen_rldinm(ctx, 0, me, sh);
1795 GEN_PPC64_R4(rldicr, 0x1E, 0x02);
1796 /* rldic - rldic. */
1797 static inline void gen_rldic(DisasContext *ctx, int mbn, int shn)
1801 sh = SH(ctx->opcode) | (shn << 5);
1802 mb = MB(ctx->opcode) | (mbn << 5);
1803 gen_rldinm(ctx, mb, 63 - sh, sh);
1805 GEN_PPC64_R4(rldic, 0x1E, 0x04);
1807 static inline void gen_rldnm(DisasContext *ctx, uint32_t mb, uint32_t me)
1811 t0 = tcg_temp_new();
1812 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3f);
1813 tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
1814 if (unlikely(mb != 0 || me != 63)) {
1815 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me));
1817 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
1820 if (unlikely(Rc(ctx->opcode) != 0))
1821 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1824 /* rldcl - rldcl. */
1825 static inline void gen_rldcl(DisasContext *ctx, int mbn)
1829 mb = MB(ctx->opcode) | (mbn << 5);
1830 gen_rldnm(ctx, mb, 63);
1832 GEN_PPC64_R2(rldcl, 0x1E, 0x08);
1833 /* rldcr - rldcr. */
1834 static inline void gen_rldcr(DisasContext *ctx, int men)
1838 me = MB(ctx->opcode) | (men << 5);
1839 gen_rldnm(ctx, 0, me);
1841 GEN_PPC64_R2(rldcr, 0x1E, 0x09);
1842 /* rldimi - rldimi. */
1843 static inline void gen_rldimi(DisasContext *ctx, int mbn, int shn)
1845 uint32_t sh, mb, me;
1847 sh = SH(ctx->opcode) | (shn << 5);
1848 mb = MB(ctx->opcode) | (mbn << 5);
1850 if (unlikely(sh == 0 && mb == 0)) {
1851 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1856 t0 = tcg_temp_new();
1857 tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
1858 t1 = tcg_temp_new();
1859 mask = MASK(mb, me);
1860 tcg_gen_andi_tl(t0, t0, mask);
1861 tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], ~mask);
1862 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1866 if (unlikely(Rc(ctx->opcode) != 0))
1867 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1869 GEN_PPC64_R4(rldimi, 0x1E, 0x06);
1872 /*** Integer shift ***/
1875 static void gen_slw(DisasContext *ctx)
1879 t0 = tcg_temp_new();
1880 /* AND rS with a mask that is 0 when rB >= 0x20 */
1881 #if defined(TARGET_PPC64)
1882 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3a);
1883 tcg_gen_sari_tl(t0, t0, 0x3f);
1885 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1a);
1886 tcg_gen_sari_tl(t0, t0, 0x1f);
1888 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
1889 t1 = tcg_temp_new();
1890 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1f);
1891 tcg_gen_shl_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1894 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
1895 if (unlikely(Rc(ctx->opcode) != 0))
1896 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1900 static void gen_sraw(DisasContext *ctx)
1902 gen_helper_sraw(cpu_gpr[rA(ctx->opcode)], cpu_env,
1903 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1904 if (unlikely(Rc(ctx->opcode) != 0))
1905 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1908 /* srawi & srawi. */
1909 static void gen_srawi(DisasContext *ctx)
1911 int sh = SH(ctx->opcode);
1912 TCGv dst = cpu_gpr[rA(ctx->opcode)];
1913 TCGv src = cpu_gpr[rS(ctx->opcode)];
1915 tcg_gen_mov_tl(dst, src);
1916 tcg_gen_movi_tl(cpu_ca, 0);
1919 tcg_gen_ext32s_tl(dst, src);
1920 tcg_gen_andi_tl(cpu_ca, dst, (1ULL << sh) - 1);
1921 t0 = tcg_temp_new();
1922 tcg_gen_sari_tl(t0, dst, TARGET_LONG_BITS - 1);
1923 tcg_gen_and_tl(cpu_ca, cpu_ca, t0);
1925 tcg_gen_setcondi_tl(TCG_COND_NE, cpu_ca, cpu_ca, 0);
1926 tcg_gen_sari_tl(dst, dst, sh);
1928 if (unlikely(Rc(ctx->opcode) != 0)) {
1929 gen_set_Rc0(ctx, dst);
1934 static void gen_srw(DisasContext *ctx)
1938 t0 = tcg_temp_new();
1939 /* AND rS with a mask that is 0 when rB >= 0x20 */
1940 #if defined(TARGET_PPC64)
1941 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3a);
1942 tcg_gen_sari_tl(t0, t0, 0x3f);
1944 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1a);
1945 tcg_gen_sari_tl(t0, t0, 0x1f);
1947 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
1948 tcg_gen_ext32u_tl(t0, t0);
1949 t1 = tcg_temp_new();
1950 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1f);
1951 tcg_gen_shr_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1954 if (unlikely(Rc(ctx->opcode) != 0))
1955 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1958 #if defined(TARGET_PPC64)
1960 static void gen_sld(DisasContext *ctx)
1964 t0 = tcg_temp_new();
1965 /* AND rS with a mask that is 0 when rB >= 0x40 */
1966 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x39);
1967 tcg_gen_sari_tl(t0, t0, 0x3f);
1968 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
1969 t1 = tcg_temp_new();
1970 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x3f);
1971 tcg_gen_shl_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1974 if (unlikely(Rc(ctx->opcode) != 0))
1975 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1979 static void gen_srad(DisasContext *ctx)
1981 gen_helper_srad(cpu_gpr[rA(ctx->opcode)], cpu_env,
1982 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1983 if (unlikely(Rc(ctx->opcode) != 0))
1984 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1986 /* sradi & sradi. */
1987 static inline void gen_sradi(DisasContext *ctx, int n)
1989 int sh = SH(ctx->opcode) + (n << 5);
1990 TCGv dst = cpu_gpr[rA(ctx->opcode)];
1991 TCGv src = cpu_gpr[rS(ctx->opcode)];
1993 tcg_gen_mov_tl(dst, src);
1994 tcg_gen_movi_tl(cpu_ca, 0);
1997 tcg_gen_andi_tl(cpu_ca, src, (1ULL << sh) - 1);
1998 t0 = tcg_temp_new();
1999 tcg_gen_sari_tl(t0, src, TARGET_LONG_BITS - 1);
2000 tcg_gen_and_tl(cpu_ca, cpu_ca, t0);
2002 tcg_gen_setcondi_tl(TCG_COND_NE, cpu_ca, cpu_ca, 0);
2003 tcg_gen_sari_tl(dst, src, sh);
2005 if (unlikely(Rc(ctx->opcode) != 0)) {
2006 gen_set_Rc0(ctx, dst);
2010 static void gen_sradi0(DisasContext *ctx)
2015 static void gen_sradi1(DisasContext *ctx)
2021 static void gen_srd(DisasContext *ctx)
2025 t0 = tcg_temp_new();
2026 /* AND rS with a mask that is 0 when rB >= 0x40 */
2027 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x39);
2028 tcg_gen_sari_tl(t0, t0, 0x3f);
2029 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
2030 t1 = tcg_temp_new();
2031 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x3f);
2032 tcg_gen_shr_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
2035 if (unlikely(Rc(ctx->opcode) != 0))
2036 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
2040 /*** Floating-Point arithmetic ***/
2041 #define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
2042 static void gen_f##name(DisasContext *ctx) \
2044 if (unlikely(!ctx->fpu_enabled)) { \
2045 gen_exception(ctx, POWERPC_EXCP_FPU); \
2048 /* NIP cannot be restored if the memory exception comes from an helper */ \
2049 gen_update_nip(ctx, ctx->nip - 4); \
2050 gen_reset_fpstatus(); \
2051 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2052 cpu_fpr[rA(ctx->opcode)], \
2053 cpu_fpr[rC(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]); \
2055 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2056 cpu_fpr[rD(ctx->opcode)]); \
2058 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], set_fprf, \
2059 Rc(ctx->opcode) != 0); \
2062 #define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
2063 _GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type); \
2064 _GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type);
2066 #define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
2067 static void gen_f##name(DisasContext *ctx) \
2069 if (unlikely(!ctx->fpu_enabled)) { \
2070 gen_exception(ctx, POWERPC_EXCP_FPU); \
2073 /* NIP cannot be restored if the memory exception comes from an helper */ \
2074 gen_update_nip(ctx, ctx->nip - 4); \
2075 gen_reset_fpstatus(); \
2076 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2077 cpu_fpr[rA(ctx->opcode)], \
2078 cpu_fpr[rB(ctx->opcode)]); \
2080 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2081 cpu_fpr[rD(ctx->opcode)]); \
2083 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2084 set_fprf, Rc(ctx->opcode) != 0); \
2086 #define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
2087 _GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2088 _GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
2090 #define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
2091 static void gen_f##name(DisasContext *ctx) \
2093 if (unlikely(!ctx->fpu_enabled)) { \
2094 gen_exception(ctx, POWERPC_EXCP_FPU); \
2097 /* NIP cannot be restored if the memory exception comes from an helper */ \
2098 gen_update_nip(ctx, ctx->nip - 4); \
2099 gen_reset_fpstatus(); \
2100 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2101 cpu_fpr[rA(ctx->opcode)], \
2102 cpu_fpr[rC(ctx->opcode)]); \
2104 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2105 cpu_fpr[rD(ctx->opcode)]); \
2107 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2108 set_fprf, Rc(ctx->opcode) != 0); \
2110 #define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
2111 _GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2112 _GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
2114 #define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
2115 static void gen_f##name(DisasContext *ctx) \
2117 if (unlikely(!ctx->fpu_enabled)) { \
2118 gen_exception(ctx, POWERPC_EXCP_FPU); \
2121 /* NIP cannot be restored if the memory exception comes from an helper */ \
2122 gen_update_nip(ctx, ctx->nip - 4); \
2123 gen_reset_fpstatus(); \
2124 gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2125 cpu_fpr[rB(ctx->opcode)]); \
2126 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2127 set_fprf, Rc(ctx->opcode) != 0); \
2130 #define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
2131 static void gen_f##name(DisasContext *ctx) \
2133 if (unlikely(!ctx->fpu_enabled)) { \
2134 gen_exception(ctx, POWERPC_EXCP_FPU); \
2137 /* NIP cannot be restored if the memory exception comes from an helper */ \
2138 gen_update_nip(ctx, ctx->nip - 4); \
2139 gen_reset_fpstatus(); \
2140 gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2141 cpu_fpr[rB(ctx->opcode)]); \
2142 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2143 set_fprf, Rc(ctx->opcode) != 0); \
2147 GEN_FLOAT_AB(add, 0x15, 0x000007C0, 1, PPC_FLOAT);
2149 GEN_FLOAT_AB(div, 0x12, 0x000007C0, 1, PPC_FLOAT);
2151 GEN_FLOAT_AC(mul, 0x19, 0x0000F800, 1, PPC_FLOAT);
2154 GEN_FLOAT_BS(re, 0x3F, 0x18, 1, PPC_FLOAT_EXT);
2157 GEN_FLOAT_BS(res, 0x3B, 0x18, 1, PPC_FLOAT_FRES);
2160 GEN_FLOAT_BS(rsqrte, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE);
2163 static void gen_frsqrtes(DisasContext *ctx)
2165 if (unlikely(!ctx->fpu_enabled)) {
2166 gen_exception(ctx, POWERPC_EXCP_FPU);
2169 /* NIP cannot be restored if the memory exception comes from an helper */
2170 gen_update_nip(ctx, ctx->nip - 4);
2171 gen_reset_fpstatus();
2172 gen_helper_frsqrte(cpu_fpr[rD(ctx->opcode)], cpu_env,
2173 cpu_fpr[rB(ctx->opcode)]);
2174 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env,
2175 cpu_fpr[rD(ctx->opcode)]);
2176 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 1, Rc(ctx->opcode) != 0);
2180 _GEN_FLOAT_ACB(sel, sel, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL);
2182 GEN_FLOAT_AB(sub, 0x14, 0x000007C0, 1, PPC_FLOAT);
2186 static void gen_fsqrt(DisasContext *ctx)
2188 if (unlikely(!ctx->fpu_enabled)) {
2189 gen_exception(ctx, POWERPC_EXCP_FPU);
2192 /* NIP cannot be restored if the memory exception comes from an helper */
2193 gen_update_nip(ctx, ctx->nip - 4);
2194 gen_reset_fpstatus();
2195 gen_helper_fsqrt(cpu_fpr[rD(ctx->opcode)], cpu_env,
2196 cpu_fpr[rB(ctx->opcode)]);
2197 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 1, Rc(ctx->opcode) != 0);
2200 static void gen_fsqrts(DisasContext *ctx)
2202 if (unlikely(!ctx->fpu_enabled)) {
2203 gen_exception(ctx, POWERPC_EXCP_FPU);
2206 /* NIP cannot be restored if the memory exception comes from an helper */
2207 gen_update_nip(ctx, ctx->nip - 4);
2208 gen_reset_fpstatus();
2209 gen_helper_fsqrt(cpu_fpr[rD(ctx->opcode)], cpu_env,
2210 cpu_fpr[rB(ctx->opcode)]);
2211 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env,
2212 cpu_fpr[rD(ctx->opcode)]);
2213 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 1, Rc(ctx->opcode) != 0);
2216 /*** Floating-Point multiply-and-add ***/
2217 /* fmadd - fmadds */
2218 GEN_FLOAT_ACB(madd, 0x1D, 1, PPC_FLOAT);
2219 /* fmsub - fmsubs */
2220 GEN_FLOAT_ACB(msub, 0x1C, 1, PPC_FLOAT);
2221 /* fnmadd - fnmadds */
2222 GEN_FLOAT_ACB(nmadd, 0x1F, 1, PPC_FLOAT);
2223 /* fnmsub - fnmsubs */
2224 GEN_FLOAT_ACB(nmsub, 0x1E, 1, PPC_FLOAT);
2226 /*** Floating-Point round & convert ***/
2228 GEN_FLOAT_B(ctiw, 0x0E, 0x00, 0, PPC_FLOAT);
2230 GEN_FLOAT_B(ctiwu, 0x0E, 0x04, 0, PPC2_FP_CVT_ISA206);
2232 GEN_FLOAT_B(ctiwz, 0x0F, 0x00, 0, PPC_FLOAT);
2234 GEN_FLOAT_B(ctiwuz, 0x0F, 0x04, 0, PPC2_FP_CVT_ISA206);
2236 GEN_FLOAT_B(rsp, 0x0C, 0x00, 1, PPC_FLOAT);
2237 #if defined(TARGET_PPC64)
2239 GEN_FLOAT_B(cfid, 0x0E, 0x1A, 1, PPC_64B);
2241 GEN_FLOAT_B(cfids, 0x0E, 0x1A, 0, PPC2_FP_CVT_ISA206);
2243 GEN_FLOAT_B(cfidu, 0x0E, 0x1E, 0, PPC2_FP_CVT_ISA206);
2245 GEN_FLOAT_B(cfidus, 0x0E, 0x1E, 0, PPC2_FP_CVT_ISA206);
2247 GEN_FLOAT_B(ctid, 0x0E, 0x19, 0, PPC_64B);
2249 GEN_FLOAT_B(ctidu, 0x0E, 0x1D, 0, PPC2_FP_CVT_ISA206);
2251 GEN_FLOAT_B(ctidz, 0x0F, 0x19, 0, PPC_64B);
2253 GEN_FLOAT_B(ctiduz, 0x0F, 0x1D, 0, PPC2_FP_CVT_ISA206);
2257 GEN_FLOAT_B(rin, 0x08, 0x0C, 1, PPC_FLOAT_EXT);
2259 GEN_FLOAT_B(riz, 0x08, 0x0D, 1, PPC_FLOAT_EXT);
2261 GEN_FLOAT_B(rip, 0x08, 0x0E, 1, PPC_FLOAT_EXT);
2263 GEN_FLOAT_B(rim, 0x08, 0x0F, 1, PPC_FLOAT_EXT);
2265 static void gen_ftdiv(DisasContext *ctx)
2267 if (unlikely(!ctx->fpu_enabled)) {
2268 gen_exception(ctx, POWERPC_EXCP_FPU);
2271 gen_helper_ftdiv(cpu_crf[crfD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)],
2272 cpu_fpr[rB(ctx->opcode)]);
2275 static void gen_ftsqrt(DisasContext *ctx)
2277 if (unlikely(!ctx->fpu_enabled)) {
2278 gen_exception(ctx, POWERPC_EXCP_FPU);
2281 gen_helper_ftsqrt(cpu_crf[crfD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]);
2286 /*** Floating-Point compare ***/
2289 static void gen_fcmpo(DisasContext *ctx)
2292 if (unlikely(!ctx->fpu_enabled)) {
2293 gen_exception(ctx, POWERPC_EXCP_FPU);
2296 /* NIP cannot be restored if the memory exception comes from an helper */
2297 gen_update_nip(ctx, ctx->nip - 4);
2298 gen_reset_fpstatus();
2299 crf = tcg_const_i32(crfD(ctx->opcode));
2300 gen_helper_fcmpo(cpu_env, cpu_fpr[rA(ctx->opcode)],
2301 cpu_fpr[rB(ctx->opcode)], crf);
2302 tcg_temp_free_i32(crf);
2303 gen_helper_float_check_status(cpu_env);
2307 static void gen_fcmpu(DisasContext *ctx)
2310 if (unlikely(!ctx->fpu_enabled)) {
2311 gen_exception(ctx, POWERPC_EXCP_FPU);
2314 /* NIP cannot be restored if the memory exception comes from an helper */
2315 gen_update_nip(ctx, ctx->nip - 4);
2316 gen_reset_fpstatus();
2317 crf = tcg_const_i32(crfD(ctx->opcode));
2318 gen_helper_fcmpu(cpu_env, cpu_fpr[rA(ctx->opcode)],
2319 cpu_fpr[rB(ctx->opcode)], crf);
2320 tcg_temp_free_i32(crf);
2321 gen_helper_float_check_status(cpu_env);
2324 /*** Floating-point move ***/
2326 /* XXX: beware that fabs never checks for NaNs nor update FPSCR */
2327 static void gen_fabs(DisasContext *ctx)
2329 if (unlikely(!ctx->fpu_enabled)) {
2330 gen_exception(ctx, POWERPC_EXCP_FPU);
2333 tcg_gen_andi_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)],
2335 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
2339 /* XXX: beware that fmr never checks for NaNs nor update FPSCR */
2340 static void gen_fmr(DisasContext *ctx)
2342 if (unlikely(!ctx->fpu_enabled)) {
2343 gen_exception(ctx, POWERPC_EXCP_FPU);
2346 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]);
2347 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
2351 /* XXX: beware that fnabs never checks for NaNs nor update FPSCR */
2352 static void gen_fnabs(DisasContext *ctx)
2354 if (unlikely(!ctx->fpu_enabled)) {
2355 gen_exception(ctx, POWERPC_EXCP_FPU);
2358 tcg_gen_ori_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)],
2360 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
2364 /* XXX: beware that fneg never checks for NaNs nor update FPSCR */
2365 static void gen_fneg(DisasContext *ctx)
2367 if (unlikely(!ctx->fpu_enabled)) {
2368 gen_exception(ctx, POWERPC_EXCP_FPU);
2371 tcg_gen_xori_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)],
2373 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
2376 /* fcpsgn: PowerPC 2.05 specification */
2377 /* XXX: beware that fcpsgn never checks for NaNs nor update FPSCR */
2378 static void gen_fcpsgn(DisasContext *ctx)
2380 if (unlikely(!ctx->fpu_enabled)) {
2381 gen_exception(ctx, POWERPC_EXCP_FPU);
2384 tcg_gen_deposit_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)],
2385 cpu_fpr[rB(ctx->opcode)], 0, 63);
2386 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
2389 static void gen_fmrgew(DisasContext *ctx)
2392 if (unlikely(!ctx->fpu_enabled)) {
2393 gen_exception(ctx, POWERPC_EXCP_FPU);
2396 b0 = tcg_temp_new_i64();
2397 tcg_gen_shri_i64(b0, cpu_fpr[rB(ctx->opcode)], 32);
2398 tcg_gen_deposit_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)],
2400 tcg_temp_free_i64(b0);
2403 static void gen_fmrgow(DisasContext *ctx)
2405 if (unlikely(!ctx->fpu_enabled)) {
2406 gen_exception(ctx, POWERPC_EXCP_FPU);
2409 tcg_gen_deposit_i64(cpu_fpr[rD(ctx->opcode)],
2410 cpu_fpr[rB(ctx->opcode)],
2411 cpu_fpr[rA(ctx->opcode)],
2415 /*** Floating-Point status & ctrl register ***/
2418 static void gen_mcrfs(DisasContext *ctx)
2420 TCGv tmp = tcg_temp_new();
2423 if (unlikely(!ctx->fpu_enabled)) {
2424 gen_exception(ctx, POWERPC_EXCP_FPU);
2427 bfa = 4 * (7 - crfS(ctx->opcode));
2428 tcg_gen_shri_tl(tmp, cpu_fpscr, bfa);
2429 tcg_gen_trunc_tl_i32(cpu_crf[crfD(ctx->opcode)], tmp);
2431 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], 0xf);
2432 tcg_gen_andi_tl(cpu_fpscr, cpu_fpscr, ~(0xF << bfa));
2436 static void gen_mffs(DisasContext *ctx)
2438 if (unlikely(!ctx->fpu_enabled)) {
2439 gen_exception(ctx, POWERPC_EXCP_FPU);
2442 gen_reset_fpstatus();
2443 tcg_gen_extu_tl_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpscr);
2444 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
2448 static void gen_mtfsb0(DisasContext *ctx)
2452 if (unlikely(!ctx->fpu_enabled)) {
2453 gen_exception(ctx, POWERPC_EXCP_FPU);
2456 crb = 31 - crbD(ctx->opcode);
2457 gen_reset_fpstatus();
2458 if (likely(crb != FPSCR_FEX && crb != FPSCR_VX)) {
2460 /* NIP cannot be restored if the memory exception comes from an helper */
2461 gen_update_nip(ctx, ctx->nip - 4);
2462 t0 = tcg_const_i32(crb);
2463 gen_helper_fpscr_clrbit(cpu_env, t0);
2464 tcg_temp_free_i32(t0);
2466 if (unlikely(Rc(ctx->opcode) != 0)) {
2467 tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr);
2468 tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX);
2473 static void gen_mtfsb1(DisasContext *ctx)
2477 if (unlikely(!ctx->fpu_enabled)) {
2478 gen_exception(ctx, POWERPC_EXCP_FPU);
2481 crb = 31 - crbD(ctx->opcode);
2482 gen_reset_fpstatus();
2483 /* XXX: we pretend we can only do IEEE floating-point computations */
2484 if (likely(crb != FPSCR_FEX && crb != FPSCR_VX && crb != FPSCR_NI)) {
2486 /* NIP cannot be restored if the memory exception comes from an helper */
2487 gen_update_nip(ctx, ctx->nip - 4);
2488 t0 = tcg_const_i32(crb);
2489 gen_helper_fpscr_setbit(cpu_env, t0);
2490 tcg_temp_free_i32(t0);
2492 if (unlikely(Rc(ctx->opcode) != 0)) {
2493 tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr);
2494 tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX);
2496 /* We can raise a differed exception */
2497 gen_helper_float_check_status(cpu_env);
2501 static void gen_mtfsf(DisasContext *ctx)
2506 if (unlikely(!ctx->fpu_enabled)) {
2507 gen_exception(ctx, POWERPC_EXCP_FPU);
2510 flm = FPFLM(ctx->opcode);
2511 l = FPL(ctx->opcode);
2512 w = FPW(ctx->opcode);
2513 if (unlikely(w & !(ctx->insns_flags2 & PPC2_ISA205))) {
2514 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
2517 /* NIP cannot be restored if the memory exception comes from an helper */
2518 gen_update_nip(ctx, ctx->nip - 4);
2519 gen_reset_fpstatus();
2521 t0 = tcg_const_i32((ctx->insns_flags2 & PPC2_ISA205) ? 0xffff : 0xff);
2523 t0 = tcg_const_i32(flm << (w * 8));
2525 gen_helper_store_fpscr(cpu_env, cpu_fpr[rB(ctx->opcode)], t0);
2526 tcg_temp_free_i32(t0);
2527 if (unlikely(Rc(ctx->opcode) != 0)) {
2528 tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr);
2529 tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX);
2531 /* We can raise a differed exception */
2532 gen_helper_float_check_status(cpu_env);
2536 static void gen_mtfsfi(DisasContext *ctx)
2542 if (unlikely(!ctx->fpu_enabled)) {
2543 gen_exception(ctx, POWERPC_EXCP_FPU);
2546 w = FPW(ctx->opcode);
2547 bf = FPBF(ctx->opcode);
2548 if (unlikely(w & !(ctx->insns_flags2 & PPC2_ISA205))) {
2549 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
2552 sh = (8 * w) + 7 - bf;
2553 /* NIP cannot be restored if the memory exception comes from an helper */
2554 gen_update_nip(ctx, ctx->nip - 4);
2555 gen_reset_fpstatus();
2556 t0 = tcg_const_i64(((uint64_t)FPIMM(ctx->opcode)) << (4 * sh));
2557 t1 = tcg_const_i32(1 << sh);
2558 gen_helper_store_fpscr(cpu_env, t0, t1);
2559 tcg_temp_free_i64(t0);
2560 tcg_temp_free_i32(t1);
2561 if (unlikely(Rc(ctx->opcode) != 0)) {
2562 tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr);
2563 tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX);
2565 /* We can raise a differed exception */
2566 gen_helper_float_check_status(cpu_env);
2569 /*** Addressing modes ***/
2570 /* Register indirect with immediate index : EA = (rA|0) + SIMM */
2571 static inline void gen_addr_imm_index(DisasContext *ctx, TCGv EA,
2574 target_long simm = SIMM(ctx->opcode);
2577 if (rA(ctx->opcode) == 0) {
2578 if (NARROW_MODE(ctx)) {
2579 simm = (uint32_t)simm;
2581 tcg_gen_movi_tl(EA, simm);
2582 } else if (likely(simm != 0)) {
2583 tcg_gen_addi_tl(EA, cpu_gpr[rA(ctx->opcode)], simm);
2584 if (NARROW_MODE(ctx)) {
2585 tcg_gen_ext32u_tl(EA, EA);
2588 if (NARROW_MODE(ctx)) {
2589 tcg_gen_ext32u_tl(EA, cpu_gpr[rA(ctx->opcode)]);
2591 tcg_gen_mov_tl(EA, cpu_gpr[rA(ctx->opcode)]);
2596 static inline void gen_addr_reg_index(DisasContext *ctx, TCGv EA)
2598 if (rA(ctx->opcode) == 0) {
2599 if (NARROW_MODE(ctx)) {
2600 tcg_gen_ext32u_tl(EA, cpu_gpr[rB(ctx->opcode)]);
2602 tcg_gen_mov_tl(EA, cpu_gpr[rB(ctx->opcode)]);
2605 tcg_gen_add_tl(EA, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
2606 if (NARROW_MODE(ctx)) {
2607 tcg_gen_ext32u_tl(EA, EA);
2612 static inline void gen_addr_register(DisasContext *ctx, TCGv EA)
2614 if (rA(ctx->opcode) == 0) {
2615 tcg_gen_movi_tl(EA, 0);
2616 } else if (NARROW_MODE(ctx)) {
2617 tcg_gen_ext32u_tl(EA, cpu_gpr[rA(ctx->opcode)]);
2619 tcg_gen_mov_tl(EA, cpu_gpr[rA(ctx->opcode)]);
2623 static inline void gen_addr_add(DisasContext *ctx, TCGv ret, TCGv arg1,
2626 tcg_gen_addi_tl(ret, arg1, val);
2627 if (NARROW_MODE(ctx)) {
2628 tcg_gen_ext32u_tl(ret, ret);
2632 static inline void gen_check_align(DisasContext *ctx, TCGv EA, int mask)
2634 int l1 = gen_new_label();
2635 TCGv t0 = tcg_temp_new();
2637 /* NIP cannot be restored if the memory exception comes from an helper */
2638 gen_update_nip(ctx, ctx->nip - 4);
2639 tcg_gen_andi_tl(t0, EA, mask);
2640 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
2641 t1 = tcg_const_i32(POWERPC_EXCP_ALIGN);
2642 t2 = tcg_const_i32(0);
2643 gen_helper_raise_exception_err(cpu_env, t1, t2);
2644 tcg_temp_free_i32(t1);
2645 tcg_temp_free_i32(t2);
2650 /*** Integer load ***/
2651 static inline void gen_qemu_ld8u(DisasContext *ctx, TCGv arg1, TCGv arg2)
2653 tcg_gen_qemu_ld8u(arg1, arg2, ctx->mem_idx);
2656 static inline void gen_qemu_ld8s(DisasContext *ctx, TCGv arg1, TCGv arg2)
2658 tcg_gen_qemu_ld8s(arg1, arg2, ctx->mem_idx);
2661 static inline void gen_qemu_ld16u(DisasContext *ctx, TCGv arg1, TCGv arg2)
2663 tcg_gen_qemu_ld16u(arg1, arg2, ctx->mem_idx);
2664 if (unlikely(ctx->le_mode)) {
2665 tcg_gen_bswap16_tl(arg1, arg1);
2669 static inline void gen_qemu_ld16s(DisasContext *ctx, TCGv arg1, TCGv arg2)
2671 if (unlikely(ctx->le_mode)) {
2672 tcg_gen_qemu_ld16u(arg1, arg2, ctx->mem_idx);
2673 tcg_gen_bswap16_tl(arg1, arg1);
2674 tcg_gen_ext16s_tl(arg1, arg1);
2676 tcg_gen_qemu_ld16s(arg1, arg2, ctx->mem_idx);
2680 static inline void gen_qemu_ld32u(DisasContext *ctx, TCGv arg1, TCGv arg2)
2682 tcg_gen_qemu_ld32u(arg1, arg2, ctx->mem_idx);
2683 if (unlikely(ctx->le_mode)) {
2684 tcg_gen_bswap32_tl(arg1, arg1);
2688 static void gen_qemu_ld32u_i64(DisasContext *ctx, TCGv_i64 val, TCGv addr)
2690 TCGv tmp = tcg_temp_new();
2691 gen_qemu_ld32u(ctx, tmp, addr);
2692 tcg_gen_extu_tl_i64(val, tmp);
2696 static inline void gen_qemu_ld32s(DisasContext *ctx, TCGv arg1, TCGv arg2)
2698 if (unlikely(ctx->le_mode)) {
2699 tcg_gen_qemu_ld32u(arg1, arg2, ctx->mem_idx);
2700 tcg_gen_bswap32_tl(arg1, arg1);
2701 tcg_gen_ext32s_tl(arg1, arg1);
2703 tcg_gen_qemu_ld32s(arg1, arg2, ctx->mem_idx);
2706 static void gen_qemu_ld32s_i64(DisasContext *ctx, TCGv_i64 val, TCGv addr)
2708 TCGv tmp = tcg_temp_new();
2709 gen_qemu_ld32s(ctx, tmp, addr);
2710 tcg_gen_ext_tl_i64(val, tmp);
2714 static inline void gen_qemu_ld64(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
2716 tcg_gen_qemu_ld64(arg1, arg2, ctx->mem_idx);
2717 if (unlikely(ctx->le_mode)) {
2718 tcg_gen_bswap64_i64(arg1, arg1);
2722 static inline void gen_qemu_st8(DisasContext *ctx, TCGv arg1, TCGv arg2)
2724 tcg_gen_qemu_st8(arg1, arg2, ctx->mem_idx);
2727 static inline void gen_qemu_st16(DisasContext *ctx, TCGv arg1, TCGv arg2)
2729 if (unlikely(ctx->le_mode)) {
2730 TCGv t0 = tcg_temp_new();
2731 tcg_gen_ext16u_tl(t0, arg1);
2732 tcg_gen_bswap16_tl(t0, t0);
2733 tcg_gen_qemu_st16(t0, arg2, ctx->mem_idx);
2736 tcg_gen_qemu_st16(arg1, arg2, ctx->mem_idx);
2740 static inline void gen_qemu_st32(DisasContext *ctx, TCGv arg1, TCGv arg2)
2742 if (unlikely(ctx->le_mode)) {
2743 TCGv t0 = tcg_temp_new();
2744 tcg_gen_ext32u_tl(t0, arg1);
2745 tcg_gen_bswap32_tl(t0, t0);
2746 tcg_gen_qemu_st32(t0, arg2, ctx->mem_idx);
2749 tcg_gen_qemu_st32(arg1, arg2, ctx->mem_idx);
2753 static void gen_qemu_st32_i64(DisasContext *ctx, TCGv_i64 val, TCGv addr)
2755 TCGv tmp = tcg_temp_new();
2756 tcg_gen_trunc_i64_tl(tmp, val);
2757 gen_qemu_st32(ctx, tmp, addr);
2761 static inline void gen_qemu_st64(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
2763 if (unlikely(ctx->le_mode)) {
2764 TCGv_i64 t0 = tcg_temp_new_i64();
2765 tcg_gen_bswap64_i64(t0, arg1);
2766 tcg_gen_qemu_st64(t0, arg2, ctx->mem_idx);
2767 tcg_temp_free_i64(t0);
2769 tcg_gen_qemu_st64(arg1, arg2, ctx->mem_idx);
2772 #define GEN_LD(name, ldop, opc, type) \
2773 static void glue(gen_, name)(DisasContext *ctx) \
2776 gen_set_access_type(ctx, ACCESS_INT); \
2777 EA = tcg_temp_new(); \
2778 gen_addr_imm_index(ctx, EA, 0); \
2779 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2780 tcg_temp_free(EA); \
2783 #define GEN_LDU(name, ldop, opc, type) \
2784 static void glue(gen_, name##u)(DisasContext *ctx) \
2787 if (unlikely(rA(ctx->opcode) == 0 || \
2788 rA(ctx->opcode) == rD(ctx->opcode))) { \
2789 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2792 gen_set_access_type(ctx, ACCESS_INT); \
2793 EA = tcg_temp_new(); \
2794 if (type == PPC_64B) \
2795 gen_addr_imm_index(ctx, EA, 0x03); \
2797 gen_addr_imm_index(ctx, EA, 0); \
2798 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2799 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2800 tcg_temp_free(EA); \
2803 #define GEN_LDUX(name, ldop, opc2, opc3, type) \
2804 static void glue(gen_, name##ux)(DisasContext *ctx) \
2807 if (unlikely(rA(ctx->opcode) == 0 || \
2808 rA(ctx->opcode) == rD(ctx->opcode))) { \
2809 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2812 gen_set_access_type(ctx, ACCESS_INT); \
2813 EA = tcg_temp_new(); \
2814 gen_addr_reg_index(ctx, EA); \
2815 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2816 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2817 tcg_temp_free(EA); \
2820 #define GEN_LDX_E(name, ldop, opc2, opc3, type, type2) \
2821 static void glue(gen_, name##x)(DisasContext *ctx) \
2824 gen_set_access_type(ctx, ACCESS_INT); \
2825 EA = tcg_temp_new(); \
2826 gen_addr_reg_index(ctx, EA); \
2827 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2828 tcg_temp_free(EA); \
2830 #define GEN_LDX(name, ldop, opc2, opc3, type) \
2831 GEN_LDX_E(name, ldop, opc2, opc3, type, PPC_NONE)
2833 #define GEN_LDS(name, ldop, op, type) \
2834 GEN_LD(name, ldop, op | 0x20, type); \
2835 GEN_LDU(name, ldop, op | 0x21, type); \
2836 GEN_LDUX(name, ldop, 0x17, op | 0x01, type); \
2837 GEN_LDX(name, ldop, 0x17, op | 0x00, type)
2839 /* lbz lbzu lbzux lbzx */
2840 GEN_LDS(lbz, ld8u, 0x02, PPC_INTEGER);
2841 /* lha lhau lhaux lhax */
2842 GEN_LDS(lha, ld16s, 0x0A, PPC_INTEGER);
2843 /* lhz lhzu lhzux lhzx */
2844 GEN_LDS(lhz, ld16u, 0x08, PPC_INTEGER);
2845 /* lwz lwzu lwzux lwzx */
2846 GEN_LDS(lwz, ld32u, 0x00, PPC_INTEGER);
2847 #if defined(TARGET_PPC64)
2849 GEN_LDUX(lwa, ld32s, 0x15, 0x0B, PPC_64B);
2851 GEN_LDX(lwa, ld32s, 0x15, 0x0A, PPC_64B);
2853 GEN_LDUX(ld, ld64, 0x15, 0x01, PPC_64B);
2855 GEN_LDX(ld, ld64, 0x15, 0x00, PPC_64B);
2857 static void gen_ld(DisasContext *ctx)
2860 if (Rc(ctx->opcode)) {
2861 if (unlikely(rA(ctx->opcode) == 0 ||
2862 rA(ctx->opcode) == rD(ctx->opcode))) {
2863 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
2867 gen_set_access_type(ctx, ACCESS_INT);
2868 EA = tcg_temp_new();
2869 gen_addr_imm_index(ctx, EA, 0x03);
2870 if (ctx->opcode & 0x02) {
2871 /* lwa (lwau is undefined) */
2872 gen_qemu_ld32s(ctx, cpu_gpr[rD(ctx->opcode)], EA);
2875 gen_qemu_ld64(ctx, cpu_gpr[rD(ctx->opcode)], EA);
2877 if (Rc(ctx->opcode))
2878 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA);
2883 static void gen_lq(DisasContext *ctx)
2888 /* lq is a legal user mode instruction starting in ISA 2.07 */
2889 bool legal_in_user_mode = (ctx->insns_flags2 & PPC2_LSQ_ISA207) != 0;
2890 bool le_is_supported = (ctx->insns_flags2 & PPC2_LSQ_ISA207) != 0;
2892 if (!legal_in_user_mode && is_user_mode(ctx)) {
2893 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
2897 if (!le_is_supported && ctx->le_mode) {
2898 gen_exception_err(ctx, POWERPC_EXCP_ALIGN, POWERPC_EXCP_ALIGN_LE);
2902 ra = rA(ctx->opcode);
2903 rd = rD(ctx->opcode);
2904 if (unlikely((rd & 1) || rd == ra)) {
2905 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
2909 gen_set_access_type(ctx, ACCESS_INT);
2910 EA = tcg_temp_new();
2911 gen_addr_imm_index(ctx, EA, 0x0F);
2913 if (unlikely(ctx->le_mode)) {
2914 gen_qemu_ld64(ctx, cpu_gpr[rd+1], EA);
2915 gen_addr_add(ctx, EA, EA, 8);
2916 gen_qemu_ld64(ctx, cpu_gpr[rd], EA);
2918 gen_qemu_ld64(ctx, cpu_gpr[rd], EA);
2919 gen_addr_add(ctx, EA, EA, 8);
2920 gen_qemu_ld64(ctx, cpu_gpr[rd+1], EA);
2926 /*** Integer store ***/
2927 #define GEN_ST(name, stop, opc, type) \
2928 static void glue(gen_, name)(DisasContext *ctx) \
2931 gen_set_access_type(ctx, ACCESS_INT); \
2932 EA = tcg_temp_new(); \
2933 gen_addr_imm_index(ctx, EA, 0); \
2934 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2935 tcg_temp_free(EA); \
2938 #define GEN_STU(name, stop, opc, type) \
2939 static void glue(gen_, stop##u)(DisasContext *ctx) \
2942 if (unlikely(rA(ctx->opcode) == 0)) { \
2943 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2946 gen_set_access_type(ctx, ACCESS_INT); \
2947 EA = tcg_temp_new(); \
2948 if (type == PPC_64B) \
2949 gen_addr_imm_index(ctx, EA, 0x03); \
2951 gen_addr_imm_index(ctx, EA, 0); \
2952 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2953 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2954 tcg_temp_free(EA); \
2957 #define GEN_STUX(name, stop, opc2, opc3, type) \
2958 static void glue(gen_, name##ux)(DisasContext *ctx) \
2961 if (unlikely(rA(ctx->opcode) == 0)) { \
2962 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2965 gen_set_access_type(ctx, ACCESS_INT); \
2966 EA = tcg_temp_new(); \
2967 gen_addr_reg_index(ctx, EA); \
2968 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2969 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2970 tcg_temp_free(EA); \
2973 #define GEN_STX_E(name, stop, opc2, opc3, type, type2) \
2974 static void glue(gen_, name##x)(DisasContext *ctx) \
2977 gen_set_access_type(ctx, ACCESS_INT); \
2978 EA = tcg_temp_new(); \
2979 gen_addr_reg_index(ctx, EA); \
2980 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2981 tcg_temp_free(EA); \
2983 #define GEN_STX(name, stop, opc2, opc3, type) \
2984 GEN_STX_E(name, stop, opc2, opc3, type, PPC_NONE)
2986 #define GEN_STS(name, stop, op, type) \
2987 GEN_ST(name, stop, op | 0x20, type); \
2988 GEN_STU(name, stop, op | 0x21, type); \
2989 GEN_STUX(name, stop, 0x17, op | 0x01, type); \
2990 GEN_STX(name, stop, 0x17, op | 0x00, type)
2992 /* stb stbu stbux stbx */
2993 GEN_STS(stb, st8, 0x06, PPC_INTEGER);
2994 /* sth sthu sthux sthx */
2995 GEN_STS(sth, st16, 0x0C, PPC_INTEGER);
2996 /* stw stwu stwux stwx */
2997 GEN_STS(stw, st32, 0x04, PPC_INTEGER);
2998 #if defined(TARGET_PPC64)
2999 GEN_STUX(std, st64, 0x15, 0x05, PPC_64B);
3000 GEN_STX(std, st64, 0x15, 0x04, PPC_64B);
3002 static void gen_std(DisasContext *ctx)
3007 rs = rS(ctx->opcode);
3008 if ((ctx->opcode & 0x3) == 0x2) { /* stq */
3010 bool legal_in_user_mode = (ctx->insns_flags2 & PPC2_LSQ_ISA207) != 0;
3011 bool le_is_supported = (ctx->insns_flags2 & PPC2_LSQ_ISA207) != 0;
3013 if (!legal_in_user_mode && is_user_mode(ctx)) {
3014 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
3018 if (!le_is_supported && ctx->le_mode) {
3019 gen_exception_err(ctx, POWERPC_EXCP_ALIGN, POWERPC_EXCP_ALIGN_LE);
3023 if (unlikely(rs & 1)) {
3024 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
3027 gen_set_access_type(ctx, ACCESS_INT);
3028 EA = tcg_temp_new();
3029 gen_addr_imm_index(ctx, EA, 0x03);
3031 if (unlikely(ctx->le_mode)) {
3032 gen_qemu_st64(ctx, cpu_gpr[rs+1], EA);
3033 gen_addr_add(ctx, EA, EA, 8);
3034 gen_qemu_st64(ctx, cpu_gpr[rs], EA);
3036 gen_qemu_st64(ctx, cpu_gpr[rs], EA);
3037 gen_addr_add(ctx, EA, EA, 8);
3038 gen_qemu_st64(ctx, cpu_gpr[rs+1], EA);
3043 if (Rc(ctx->opcode)) {
3044 if (unlikely(rA(ctx->opcode) == 0)) {
3045 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
3049 gen_set_access_type(ctx, ACCESS_INT);
3050 EA = tcg_temp_new();
3051 gen_addr_imm_index(ctx, EA, 0x03);
3052 gen_qemu_st64(ctx, cpu_gpr[rs], EA);
3053 if (Rc(ctx->opcode))
3054 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA);
3059 /*** Integer load and store with byte reverse ***/
3061 static inline void gen_qemu_ld16ur(DisasContext *ctx, TCGv arg1, TCGv arg2)
3063 tcg_gen_qemu_ld16u(arg1, arg2, ctx->mem_idx);
3064 if (likely(!ctx->le_mode)) {
3065 tcg_gen_bswap16_tl(arg1, arg1);
3068 GEN_LDX(lhbr, ld16ur, 0x16, 0x18, PPC_INTEGER);
3071 static inline void gen_qemu_ld32ur(DisasContext *ctx, TCGv arg1, TCGv arg2)
3073 tcg_gen_qemu_ld32u(arg1, arg2, ctx->mem_idx);
3074 if (likely(!ctx->le_mode)) {
3075 tcg_gen_bswap32_tl(arg1, arg1);
3078 GEN_LDX(lwbr, ld32ur, 0x16, 0x10, PPC_INTEGER);
3080 #if defined(TARGET_PPC64)
3082 static inline void gen_qemu_ld64ur(DisasContext *ctx, TCGv arg1, TCGv arg2)
3084 tcg_gen_qemu_ld64(arg1, arg2, ctx->mem_idx);
3085 if (likely(!ctx->le_mode)) {
3086 tcg_gen_bswap64_tl(arg1, arg1);
3089 GEN_LDX_E(ldbr, ld64ur, 0x14, 0x10, PPC_NONE, PPC2_DBRX);
3090 #endif /* TARGET_PPC64 */
3093 static inline void gen_qemu_st16r(DisasContext *ctx, TCGv arg1, TCGv arg2)
3095 if (likely(!ctx->le_mode)) {
3096 TCGv t0 = tcg_temp_new();
3097 tcg_gen_ext16u_tl(t0, arg1);
3098 tcg_gen_bswap16_tl(t0, t0);
3099 tcg_gen_qemu_st16(t0, arg2, ctx->mem_idx);
3102 tcg_gen_qemu_st16(arg1, arg2, ctx->mem_idx);
3105 GEN_STX(sthbr, st16r, 0x16, 0x1C, PPC_INTEGER);
3108 static inline void gen_qemu_st32r(DisasContext *ctx, TCGv arg1, TCGv arg2)
3110 if (likely(!ctx->le_mode)) {
3111 TCGv t0 = tcg_temp_new();
3112 tcg_gen_ext32u_tl(t0, arg1);
3113 tcg_gen_bswap32_tl(t0, t0);
3114 tcg_gen_qemu_st32(t0, arg2, ctx->mem_idx);
3117 tcg_gen_qemu_st32(arg1, arg2, ctx->mem_idx);
3120 GEN_STX(stwbr, st32r, 0x16, 0x14, PPC_INTEGER);
3122 #if defined(TARGET_PPC64)
3124 static inline void gen_qemu_st64r(DisasContext *ctx, TCGv arg1, TCGv arg2)
3126 if (likely(!ctx->le_mode)) {
3127 TCGv t0 = tcg_temp_new();
3128 tcg_gen_bswap64_tl(t0, arg1);
3129 tcg_gen_qemu_st64(t0, arg2, ctx->mem_idx);
3132 tcg_gen_qemu_st64(arg1, arg2, ctx->mem_idx);
3135 GEN_STX_E(stdbr, st64r, 0x14, 0x14, PPC_NONE, PPC2_DBRX);
3136 #endif /* TARGET_PPC64 */
3138 /*** Integer load and store multiple ***/
3141 static void gen_lmw(DisasContext *ctx)
3145 gen_set_access_type(ctx, ACCESS_INT);
3146 /* NIP cannot be restored if the memory exception comes from an helper */
3147 gen_update_nip(ctx, ctx->nip - 4);
3148 t0 = tcg_temp_new();
3149 t1 = tcg_const_i32(rD(ctx->opcode));
3150 gen_addr_imm_index(ctx, t0, 0);
3151 gen_helper_lmw(cpu_env, t0, t1);
3153 tcg_temp_free_i32(t1);
3157 static void gen_stmw(DisasContext *ctx)
3161 gen_set_access_type(ctx, ACCESS_INT);
3162 /* NIP cannot be restored if the memory exception comes from an helper */
3163 gen_update_nip(ctx, ctx->nip - 4);
3164 t0 = tcg_temp_new();
3165 t1 = tcg_const_i32(rS(ctx->opcode));
3166 gen_addr_imm_index(ctx, t0, 0);
3167 gen_helper_stmw(cpu_env, t0, t1);
3169 tcg_temp_free_i32(t1);
3172 /*** Integer load and store strings ***/
3175 /* PowerPC32 specification says we must generate an exception if
3176 * rA is in the range of registers to be loaded.
3177 * In an other hand, IBM says this is valid, but rA won't be loaded.
3178 * For now, I'll follow the spec...
3180 static void gen_lswi(DisasContext *ctx)
3184 int nb = NB(ctx->opcode);
3185 int start = rD(ctx->opcode);
3186 int ra = rA(ctx->opcode);
3192 if (unlikely(((start + nr) > 32 &&
3193 start <= ra && (start + nr - 32) > ra) ||
3194 ((start + nr) <= 32 && start <= ra && (start + nr) > ra))) {
3195 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX);
3198 gen_set_access_type(ctx, ACCESS_INT);
3199 /* NIP cannot be restored if the memory exception comes from an helper */
3200 gen_update_nip(ctx, ctx->nip - 4);
3201 t0 = tcg_temp_new();
3202 gen_addr_register(ctx, t0);
3203 t1 = tcg_const_i32(nb);
3204 t2 = tcg_const_i32(start);
3205 gen_helper_lsw(cpu_env, t0, t1, t2);
3207 tcg_temp_free_i32(t1);
3208 tcg_temp_free_i32(t2);
3212 static void gen_lswx(DisasContext *ctx)
3215 TCGv_i32 t1, t2, t3;
3216 gen_set_access_type(ctx, ACCESS_INT);
3217 /* NIP cannot be restored if the memory exception comes from an helper */
3218 gen_update_nip(ctx, ctx->nip - 4);
3219 t0 = tcg_temp_new();
3220 gen_addr_reg_index(ctx, t0);
3221 t1 = tcg_const_i32(rD(ctx->opcode));
3222 t2 = tcg_const_i32(rA(ctx->opcode));
3223 t3 = tcg_const_i32(rB(ctx->opcode));
3224 gen_helper_lswx(cpu_env, t0, t1, t2, t3);
3226 tcg_temp_free_i32(t1);
3227 tcg_temp_free_i32(t2);
3228 tcg_temp_free_i32(t3);
3232 static void gen_stswi(DisasContext *ctx)
3236 int nb = NB(ctx->opcode);
3237 gen_set_access_type(ctx, ACCESS_INT);
3238 /* NIP cannot be restored if the memory exception comes from an helper */
3239 gen_update_nip(ctx, ctx->nip - 4);
3240 t0 = tcg_temp_new();
3241 gen_addr_register(ctx, t0);
3244 t1 = tcg_const_i32(nb);
3245 t2 = tcg_const_i32(rS(ctx->opcode));
3246 gen_helper_stsw(cpu_env, t0, t1, t2);
3248 tcg_temp_free_i32(t1);
3249 tcg_temp_free_i32(t2);
3253 static void gen_stswx(DisasContext *ctx)
3257 gen_set_access_type(ctx, ACCESS_INT);
3258 /* NIP cannot be restored if the memory exception comes from an helper */
3259 gen_update_nip(ctx, ctx->nip - 4);
3260 t0 = tcg_temp_new();
3261 gen_addr_reg_index(ctx, t0);
3262 t1 = tcg_temp_new_i32();
3263 tcg_gen_trunc_tl_i32(t1, cpu_xer);
3264 tcg_gen_andi_i32(t1, t1, 0x7F);
3265 t2 = tcg_const_i32(rS(ctx->opcode));
3266 gen_helper_stsw(cpu_env, t0, t1, t2);
3268 tcg_temp_free_i32(t1);
3269 tcg_temp_free_i32(t2);
3272 /*** Memory synchronisation ***/
3274 static void gen_eieio(DisasContext *ctx)
3279 static void gen_isync(DisasContext *ctx)
3281 gen_stop_exception(ctx);
3284 #define LARX(name, len, loadop) \
3285 static void gen_##name(DisasContext *ctx) \
3288 TCGv gpr = cpu_gpr[rD(ctx->opcode)]; \
3289 gen_set_access_type(ctx, ACCESS_RES); \
3290 t0 = tcg_temp_local_new(); \
3291 gen_addr_reg_index(ctx, t0); \
3293 gen_check_align(ctx, t0, (len)-1); \
3295 gen_qemu_##loadop(ctx, gpr, t0); \
3296 tcg_gen_mov_tl(cpu_reserve, t0); \
3297 tcg_gen_st_tl(gpr, cpu_env, offsetof(CPUPPCState, reserve_val)); \
3298 tcg_temp_free(t0); \
3302 LARX(lbarx, 1, ld8u);
3303 LARX(lharx, 2, ld16u);
3304 LARX(lwarx, 4, ld32u);
3307 #if defined(CONFIG_USER_ONLY)
3308 static void gen_conditional_store(DisasContext *ctx, TCGv EA,
3311 TCGv t0 = tcg_temp_new();
3312 uint32_t save_exception = ctx->exception;
3314 tcg_gen_st_tl(EA, cpu_env, offsetof(CPUPPCState, reserve_ea));
3315 tcg_gen_movi_tl(t0, (size << 5) | reg);
3316 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUPPCState, reserve_info));
3318 gen_update_nip(ctx, ctx->nip-4);
3319 ctx->exception = POWERPC_EXCP_BRANCH;
3320 gen_exception(ctx, POWERPC_EXCP_STCX);
3321 ctx->exception = save_exception;
3324 static void gen_conditional_store(DisasContext *ctx, TCGv EA,
3329 tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so);
3330 l1 = gen_new_label();
3331 tcg_gen_brcond_tl(TCG_COND_NE, EA, cpu_reserve, l1);
3332 tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 1 << CRF_EQ);
3333 #if defined(TARGET_PPC64)
3335 gen_qemu_st64(ctx, cpu_gpr[reg], EA);
3339 gen_qemu_st32(ctx, cpu_gpr[reg], EA);
3340 } else if (size == 2) {
3341 gen_qemu_st16(ctx, cpu_gpr[reg], EA);
3342 #if defined(TARGET_PPC64)
3343 } else if (size == 16) {
3344 TCGv gpr1, gpr2 , EA8;
3345 if (unlikely(ctx->le_mode)) {
3346 gpr1 = cpu_gpr[reg+1];
3347 gpr2 = cpu_gpr[reg];
3349 gpr1 = cpu_gpr[reg];
3350 gpr2 = cpu_gpr[reg+1];
3352 gen_qemu_st64(ctx, gpr1, EA);
3353 EA8 = tcg_temp_local_new();
3354 gen_addr_add(ctx, EA8, EA, 8);
3355 gen_qemu_st64(ctx, gpr2, EA8);
3359 gen_qemu_st8(ctx, cpu_gpr[reg], EA);
3362 tcg_gen_movi_tl(cpu_reserve, -1);
3366 #define STCX(name, len) \
3367 static void gen_##name(DisasContext *ctx) \
3370 if (unlikely((len == 16) && (rD(ctx->opcode) & 1))) { \
3371 gen_inval_exception(ctx, \
3372 POWERPC_EXCP_INVAL_INVAL); \
3375 gen_set_access_type(ctx, ACCESS_RES); \
3376 t0 = tcg_temp_local_new(); \
3377 gen_addr_reg_index(ctx, t0); \
3379 gen_check_align(ctx, t0, (len)-1); \
3381 gen_conditional_store(ctx, t0, rS(ctx->opcode), len); \
3382 tcg_temp_free(t0); \
3389 #if defined(TARGET_PPC64)
3391 LARX(ldarx, 8, ld64);
3394 static void gen_lqarx(DisasContext *ctx)
3397 int rd = rD(ctx->opcode);
3400 if (unlikely((rd & 1) || (rd == rA(ctx->opcode)) ||
3401 (rd == rB(ctx->opcode)))) {
3402 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
3406 gen_set_access_type(ctx, ACCESS_RES);
3407 EA = tcg_temp_local_new();
3408 gen_addr_reg_index(ctx, EA);
3409 gen_check_align(ctx, EA, 15);
3410 if (unlikely(ctx->le_mode)) {
3411 gpr1 = cpu_gpr[rd+1];
3415 gpr2 = cpu_gpr[rd+1];
3417 gen_qemu_ld64(ctx, gpr1, EA);
3418 tcg_gen_mov_tl(cpu_reserve, EA);
3420 gen_addr_add(ctx, EA, EA, 8);
3421 gen_qemu_ld64(ctx, gpr2, EA);
3423 tcg_gen_st_tl(gpr1, cpu_env, offsetof(CPUPPCState, reserve_val));
3424 tcg_gen_st_tl(gpr2, cpu_env, offsetof(CPUPPCState, reserve_val2));
3432 #endif /* defined(TARGET_PPC64) */
3435 static void gen_sync(DisasContext *ctx)
3440 static void gen_wait(DisasContext *ctx)
3442 TCGv_i32 t0 = tcg_temp_new_i32();
3443 tcg_gen_st_i32(t0, cpu_env,
3444 -offsetof(PowerPCCPU, env) + offsetof(CPUState, halted));
3445 tcg_temp_free_i32(t0);
3446 /* Stop translation, as the CPU is supposed to sleep from now */
3447 gen_exception_err(ctx, EXCP_HLT, 1);
3450 /*** Floating-point load ***/
3451 #define GEN_LDF(name, ldop, opc, type) \
3452 static void glue(gen_, name)(DisasContext *ctx) \
3455 if (unlikely(!ctx->fpu_enabled)) { \
3456 gen_exception(ctx, POWERPC_EXCP_FPU); \
3459 gen_set_access_type(ctx, ACCESS_FLOAT); \
3460 EA = tcg_temp_new(); \
3461 gen_addr_imm_index(ctx, EA, 0); \
3462 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3463 tcg_temp_free(EA); \
3466 #define GEN_LDUF(name, ldop, opc, type) \
3467 static void glue(gen_, name##u)(DisasContext *ctx) \
3470 if (unlikely(!ctx->fpu_enabled)) { \
3471 gen_exception(ctx, POWERPC_EXCP_FPU); \
3474 if (unlikely(rA(ctx->opcode) == 0)) { \
3475 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3478 gen_set_access_type(ctx, ACCESS_FLOAT); \
3479 EA = tcg_temp_new(); \
3480 gen_addr_imm_index(ctx, EA, 0); \
3481 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3482 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3483 tcg_temp_free(EA); \
3486 #define GEN_LDUXF(name, ldop, opc, type) \
3487 static void glue(gen_, name##ux)(DisasContext *ctx) \
3490 if (unlikely(!ctx->fpu_enabled)) { \
3491 gen_exception(ctx, POWERPC_EXCP_FPU); \
3494 if (unlikely(rA(ctx->opcode) == 0)) { \
3495 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3498 gen_set_access_type(ctx, ACCESS_FLOAT); \
3499 EA = tcg_temp_new(); \
3500 gen_addr_reg_index(ctx, EA); \
3501 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3502 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3503 tcg_temp_free(EA); \
3506 #define GEN_LDXF(name, ldop, opc2, opc3, type) \
3507 static void glue(gen_, name##x)(DisasContext *ctx) \
3510 if (unlikely(!ctx->fpu_enabled)) { \
3511 gen_exception(ctx, POWERPC_EXCP_FPU); \
3514 gen_set_access_type(ctx, ACCESS_FLOAT); \
3515 EA = tcg_temp_new(); \
3516 gen_addr_reg_index(ctx, EA); \
3517 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3518 tcg_temp_free(EA); \
3521 #define GEN_LDFS(name, ldop, op, type) \
3522 GEN_LDF(name, ldop, op | 0x20, type); \
3523 GEN_LDUF(name, ldop, op | 0x21, type); \
3524 GEN_LDUXF(name, ldop, op | 0x01, type); \
3525 GEN_LDXF(name, ldop, 0x17, op | 0x00, type)
3527 static inline void gen_qemu_ld32fs(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
3529 TCGv t0 = tcg_temp_new();
3530 TCGv_i32 t1 = tcg_temp_new_i32();
3531 gen_qemu_ld32u(ctx, t0, arg2);
3532 tcg_gen_trunc_tl_i32(t1, t0);
3534 gen_helper_float32_to_float64(arg1, cpu_env, t1);
3535 tcg_temp_free_i32(t1);
3538 /* lfd lfdu lfdux lfdx */
3539 GEN_LDFS(lfd, ld64, 0x12, PPC_FLOAT);
3540 /* lfs lfsu lfsux lfsx */
3541 GEN_LDFS(lfs, ld32fs, 0x10, PPC_FLOAT);
3544 static void gen_lfdp(DisasContext *ctx)
3547 if (unlikely(!ctx->fpu_enabled)) {
3548 gen_exception(ctx, POWERPC_EXCP_FPU);
3551 gen_set_access_type(ctx, ACCESS_FLOAT);
3552 EA = tcg_temp_new();
3553 gen_addr_imm_index(ctx, EA, 0); \
3554 if (unlikely(ctx->le_mode)) {
3555 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3556 tcg_gen_addi_tl(EA, EA, 8);
3557 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3559 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3560 tcg_gen_addi_tl(EA, EA, 8);
3561 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3567 static void gen_lfdpx(DisasContext *ctx)
3570 if (unlikely(!ctx->fpu_enabled)) {
3571 gen_exception(ctx, POWERPC_EXCP_FPU);
3574 gen_set_access_type(ctx, ACCESS_FLOAT);
3575 EA = tcg_temp_new();
3576 gen_addr_reg_index(ctx, EA);
3577 if (unlikely(ctx->le_mode)) {
3578 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3579 tcg_gen_addi_tl(EA, EA, 8);
3580 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3582 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3583 tcg_gen_addi_tl(EA, EA, 8);
3584 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3590 static void gen_lfiwax(DisasContext *ctx)
3594 if (unlikely(!ctx->fpu_enabled)) {
3595 gen_exception(ctx, POWERPC_EXCP_FPU);
3598 gen_set_access_type(ctx, ACCESS_FLOAT);
3599 EA = tcg_temp_new();
3600 t0 = tcg_temp_new();
3601 gen_addr_reg_index(ctx, EA);
3602 gen_qemu_ld32s(ctx, t0, EA);
3603 tcg_gen_ext_tl_i64(cpu_fpr[rD(ctx->opcode)], t0);
3609 static void gen_lfiwzx(DisasContext *ctx)
3612 if (unlikely(!ctx->fpu_enabled)) {
3613 gen_exception(ctx, POWERPC_EXCP_FPU);
3616 gen_set_access_type(ctx, ACCESS_FLOAT);
3617 EA = tcg_temp_new();
3618 gen_addr_reg_index(ctx, EA);
3619 gen_qemu_ld32u_i64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3622 /*** Floating-point store ***/
3623 #define GEN_STF(name, stop, opc, type) \
3624 static void glue(gen_, name)(DisasContext *ctx) \
3627 if (unlikely(!ctx->fpu_enabled)) { \
3628 gen_exception(ctx, POWERPC_EXCP_FPU); \
3631 gen_set_access_type(ctx, ACCESS_FLOAT); \
3632 EA = tcg_temp_new(); \
3633 gen_addr_imm_index(ctx, EA, 0); \
3634 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3635 tcg_temp_free(EA); \
3638 #define GEN_STUF(name, stop, opc, type) \
3639 static void glue(gen_, name##u)(DisasContext *ctx) \
3642 if (unlikely(!ctx->fpu_enabled)) { \
3643 gen_exception(ctx, POWERPC_EXCP_FPU); \
3646 if (unlikely(rA(ctx->opcode) == 0)) { \
3647 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3650 gen_set_access_type(ctx, ACCESS_FLOAT); \
3651 EA = tcg_temp_new(); \
3652 gen_addr_imm_index(ctx, EA, 0); \
3653 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3654 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3655 tcg_temp_free(EA); \
3658 #define GEN_STUXF(name, stop, opc, type) \
3659 static void glue(gen_, name##ux)(DisasContext *ctx) \
3662 if (unlikely(!ctx->fpu_enabled)) { \
3663 gen_exception(ctx, POWERPC_EXCP_FPU); \
3666 if (unlikely(rA(ctx->opcode) == 0)) { \
3667 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3670 gen_set_access_type(ctx, ACCESS_FLOAT); \
3671 EA = tcg_temp_new(); \
3672 gen_addr_reg_index(ctx, EA); \
3673 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3674 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3675 tcg_temp_free(EA); \
3678 #define GEN_STXF(name, stop, opc2, opc3, type) \
3679 static void glue(gen_, name##x)(DisasContext *ctx) \
3682 if (unlikely(!ctx->fpu_enabled)) { \
3683 gen_exception(ctx, POWERPC_EXCP_FPU); \
3686 gen_set_access_type(ctx, ACCESS_FLOAT); \
3687 EA = tcg_temp_new(); \
3688 gen_addr_reg_index(ctx, EA); \
3689 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3690 tcg_temp_free(EA); \
3693 #define GEN_STFS(name, stop, op, type) \
3694 GEN_STF(name, stop, op | 0x20, type); \
3695 GEN_STUF(name, stop, op | 0x21, type); \
3696 GEN_STUXF(name, stop, op | 0x01, type); \
3697 GEN_STXF(name, stop, 0x17, op | 0x00, type)
3699 static inline void gen_qemu_st32fs(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
3701 TCGv_i32 t0 = tcg_temp_new_i32();
3702 TCGv t1 = tcg_temp_new();
3703 gen_helper_float64_to_float32(t0, cpu_env, arg1);
3704 tcg_gen_extu_i32_tl(t1, t0);
3705 tcg_temp_free_i32(t0);
3706 gen_qemu_st32(ctx, t1, arg2);
3710 /* stfd stfdu stfdux stfdx */
3711 GEN_STFS(stfd, st64, 0x16, PPC_FLOAT);
3712 /* stfs stfsu stfsux stfsx */
3713 GEN_STFS(stfs, st32fs, 0x14, PPC_FLOAT);
3716 static void gen_stfdp(DisasContext *ctx)
3719 if (unlikely(!ctx->fpu_enabled)) {
3720 gen_exception(ctx, POWERPC_EXCP_FPU);
3723 gen_set_access_type(ctx, ACCESS_FLOAT);
3724 EA = tcg_temp_new();
3725 gen_addr_imm_index(ctx, EA, 0); \
3726 if (unlikely(ctx->le_mode)) {
3727 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3728 tcg_gen_addi_tl(EA, EA, 8);
3729 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3731 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3732 tcg_gen_addi_tl(EA, EA, 8);
3733 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3739 static void gen_stfdpx(DisasContext *ctx)
3742 if (unlikely(!ctx->fpu_enabled)) {
3743 gen_exception(ctx, POWERPC_EXCP_FPU);
3746 gen_set_access_type(ctx, ACCESS_FLOAT);
3747 EA = tcg_temp_new();
3748 gen_addr_reg_index(ctx, EA);
3749 if (unlikely(ctx->le_mode)) {
3750 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3751 tcg_gen_addi_tl(EA, EA, 8);
3752 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3754 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3755 tcg_gen_addi_tl(EA, EA, 8);
3756 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3762 static inline void gen_qemu_st32fiw(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
3764 TCGv t0 = tcg_temp_new();
3765 tcg_gen_trunc_i64_tl(t0, arg1),
3766 gen_qemu_st32(ctx, t0, arg2);
3770 GEN_STXF(stfiw, st32fiw, 0x17, 0x1E, PPC_FLOAT_STFIWX);
3772 static inline void gen_update_cfar(DisasContext *ctx, target_ulong nip)
3774 #if defined(TARGET_PPC64)
3776 tcg_gen_movi_tl(cpu_cfar, nip);
3781 static inline void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest)
3783 TranslationBlock *tb;
3785 if (NARROW_MODE(ctx)) {
3786 dest = (uint32_t) dest;
3788 if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK) &&
3789 likely(!ctx->singlestep_enabled)) {
3791 tcg_gen_movi_tl(cpu_nip, dest & ~3);
3792 tcg_gen_exit_tb((uintptr_t)tb + n);
3794 tcg_gen_movi_tl(cpu_nip, dest & ~3);
3795 if (unlikely(ctx->singlestep_enabled)) {
3796 if ((ctx->singlestep_enabled &
3797 (CPU_BRANCH_STEP | CPU_SINGLE_STEP)) &&
3798 (ctx->exception == POWERPC_EXCP_BRANCH ||
3799 ctx->exception == POWERPC_EXCP_TRACE)) {
3800 target_ulong tmp = ctx->nip;
3802 gen_exception(ctx, POWERPC_EXCP_TRACE);
3805 if (ctx->singlestep_enabled & GDBSTUB_SINGLE_STEP) {
3806 gen_debug_exception(ctx);
3813 static inline void gen_setlr(DisasContext *ctx, target_ulong nip)
3815 if (NARROW_MODE(ctx)) {
3816 nip = (uint32_t)nip;
3818 tcg_gen_movi_tl(cpu_lr, nip);
3822 static void gen_b(DisasContext *ctx)
3824 target_ulong li, target;
3826 ctx->exception = POWERPC_EXCP_BRANCH;
3827 /* sign extend LI */
3828 li = LI(ctx->opcode);
3829 li = (li ^ 0x02000000) - 0x02000000;
3830 if (likely(AA(ctx->opcode) == 0)) {
3831 target = ctx->nip + li - 4;
3835 if (LK(ctx->opcode)) {
3836 gen_setlr(ctx, ctx->nip);
3838 gen_update_cfar(ctx, ctx->nip);
3839 gen_goto_tb(ctx, 0, target);
3847 static inline void gen_bcond(DisasContext *ctx, int type)
3849 uint32_t bo = BO(ctx->opcode);
3853 ctx->exception = POWERPC_EXCP_BRANCH;
3854 if (type == BCOND_LR || type == BCOND_CTR || type == BCOND_TAR) {
3855 target = tcg_temp_local_new();
3856 if (type == BCOND_CTR)
3857 tcg_gen_mov_tl(target, cpu_ctr);
3858 else if (type == BCOND_TAR)
3859 gen_load_spr(target, SPR_TAR);
3861 tcg_gen_mov_tl(target, cpu_lr);
3863 TCGV_UNUSED(target);
3865 if (LK(ctx->opcode))
3866 gen_setlr(ctx, ctx->nip);
3867 l1 = gen_new_label();
3868 if ((bo & 0x4) == 0) {
3869 /* Decrement and test CTR */
3870 TCGv temp = tcg_temp_new();
3871 if (unlikely(type == BCOND_CTR)) {
3872 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
3875 tcg_gen_subi_tl(cpu_ctr, cpu_ctr, 1);
3876 if (NARROW_MODE(ctx)) {
3877 tcg_gen_ext32u_tl(temp, cpu_ctr);
3879 tcg_gen_mov_tl(temp, cpu_ctr);
3882 tcg_gen_brcondi_tl(TCG_COND_NE, temp, 0, l1);
3884 tcg_gen_brcondi_tl(TCG_COND_EQ, temp, 0, l1);
3886 tcg_temp_free(temp);
3888 if ((bo & 0x10) == 0) {
3890 uint32_t bi = BI(ctx->opcode);
3891 uint32_t mask = 1 << (3 - (bi & 0x03));
3892 TCGv_i32 temp = tcg_temp_new_i32();
3895 tcg_gen_andi_i32(temp, cpu_crf[bi >> 2], mask);
3896 tcg_gen_brcondi_i32(TCG_COND_EQ, temp, 0, l1);
3898 tcg_gen_andi_i32(temp, cpu_crf[bi >> 2], mask);
3899 tcg_gen_brcondi_i32(TCG_COND_NE, temp, 0, l1);
3901 tcg_temp_free_i32(temp);
3903 gen_update_cfar(ctx, ctx->nip);
3904 if (type == BCOND_IM) {
3905 target_ulong li = (target_long)((int16_t)(BD(ctx->opcode)));
3906 if (likely(AA(ctx->opcode) == 0)) {
3907 gen_goto_tb(ctx, 0, ctx->nip + li - 4);
3909 gen_goto_tb(ctx, 0, li);
3912 gen_goto_tb(ctx, 1, ctx->nip);
3914 if (NARROW_MODE(ctx)) {
3915 tcg_gen_andi_tl(cpu_nip, target, (uint32_t)~3);
3917 tcg_gen_andi_tl(cpu_nip, target, ~3);
3921 gen_update_nip(ctx, ctx->nip);
3924 if (type == BCOND_LR || type == BCOND_CTR) {
3925 tcg_temp_free(target);
3929 static void gen_bc(DisasContext *ctx)
3931 gen_bcond(ctx, BCOND_IM);
3934 static void gen_bcctr(DisasContext *ctx)
3936 gen_bcond(ctx, BCOND_CTR);
3939 static void gen_bclr(DisasContext *ctx)
3941 gen_bcond(ctx, BCOND_LR);
3944 static void gen_bctar(DisasContext *ctx)
3946 gen_bcond(ctx, BCOND_TAR);
3949 /*** Condition register logical ***/
3950 #define GEN_CRLOGIC(name, tcg_op, opc) \
3951 static void glue(gen_, name)(DisasContext *ctx) \
3956 sh = (crbD(ctx->opcode) & 0x03) - (crbA(ctx->opcode) & 0x03); \
3957 t0 = tcg_temp_new_i32(); \
3959 tcg_gen_shri_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], sh); \
3961 tcg_gen_shli_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], -sh); \
3963 tcg_gen_mov_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2]); \
3964 t1 = tcg_temp_new_i32(); \
3965 sh = (crbD(ctx->opcode) & 0x03) - (crbB(ctx->opcode) & 0x03); \
3967 tcg_gen_shri_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], sh); \
3969 tcg_gen_shli_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], -sh); \
3971 tcg_gen_mov_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2]); \
3972 tcg_op(t0, t0, t1); \
3973 bitmask = 1 << (3 - (crbD(ctx->opcode) & 0x03)); \
3974 tcg_gen_andi_i32(t0, t0, bitmask); \
3975 tcg_gen_andi_i32(t1, cpu_crf[crbD(ctx->opcode) >> 2], ~bitmask); \
3976 tcg_gen_or_i32(cpu_crf[crbD(ctx->opcode) >> 2], t0, t1); \
3977 tcg_temp_free_i32(t0); \
3978 tcg_temp_free_i32(t1); \
3982 GEN_CRLOGIC(crand, tcg_gen_and_i32, 0x08);
3984 GEN_CRLOGIC(crandc, tcg_gen_andc_i32, 0x04);
3986 GEN_CRLOGIC(creqv, tcg_gen_eqv_i32, 0x09);
3988 GEN_CRLOGIC(crnand, tcg_gen_nand_i32, 0x07);
3990 GEN_CRLOGIC(crnor, tcg_gen_nor_i32, 0x01);
3992 GEN_CRLOGIC(cror, tcg_gen_or_i32, 0x0E);
3994 GEN_CRLOGIC(crorc, tcg_gen_orc_i32, 0x0D);
3996 GEN_CRLOGIC(crxor, tcg_gen_xor_i32, 0x06);
3999 static void gen_mcrf(DisasContext *ctx)
4001 tcg_gen_mov_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfS(ctx->opcode)]);
4004 /*** System linkage ***/
4006 /* rfi (mem_idx only) */
4007 static void gen_rfi(DisasContext *ctx)
4009 #if defined(CONFIG_USER_ONLY)
4010 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4012 /* Restore CPU state */
4013 if (unlikely(!ctx->mem_idx)) {
4014 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4017 gen_update_cfar(ctx, ctx->nip);
4018 gen_helper_rfi(cpu_env);
4019 gen_sync_exception(ctx);
4023 #if defined(TARGET_PPC64)
4024 static void gen_rfid(DisasContext *ctx)
4026 #if defined(CONFIG_USER_ONLY)
4027 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4029 /* Restore CPU state */
4030 if (unlikely(!ctx->mem_idx)) {
4031 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4034 gen_update_cfar(ctx, ctx->nip);
4035 gen_helper_rfid(cpu_env);
4036 gen_sync_exception(ctx);
4040 static void gen_hrfid(DisasContext *ctx)
4042 #if defined(CONFIG_USER_ONLY)
4043 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4045 /* Restore CPU state */
4046 if (unlikely(ctx->mem_idx <= 1)) {
4047 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4050 gen_helper_hrfid(cpu_env);
4051 gen_sync_exception(ctx);
4057 #if defined(CONFIG_USER_ONLY)
4058 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL_USER
4060 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL
4062 static void gen_sc(DisasContext *ctx)
4066 lev = (ctx->opcode >> 5) & 0x7F;
4067 gen_exception_err(ctx, POWERPC_SYSCALL, lev);
4073 static void gen_tw(DisasContext *ctx)
4075 TCGv_i32 t0 = tcg_const_i32(TO(ctx->opcode));
4076 /* Update the nip since this might generate a trap exception */
4077 gen_update_nip(ctx, ctx->nip);
4078 gen_helper_tw(cpu_env, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
4080 tcg_temp_free_i32(t0);
4084 static void gen_twi(DisasContext *ctx)
4086 TCGv t0 = tcg_const_tl(SIMM(ctx->opcode));
4087 TCGv_i32 t1 = tcg_const_i32(TO(ctx->opcode));
4088 /* Update the nip since this might generate a trap exception */
4089 gen_update_nip(ctx, ctx->nip);
4090 gen_helper_tw(cpu_env, cpu_gpr[rA(ctx->opcode)], t0, t1);
4092 tcg_temp_free_i32(t1);
4095 #if defined(TARGET_PPC64)
4097 static void gen_td(DisasContext *ctx)
4099 TCGv_i32 t0 = tcg_const_i32(TO(ctx->opcode));
4100 /* Update the nip since this might generate a trap exception */
4101 gen_update_nip(ctx, ctx->nip);
4102 gen_helper_td(cpu_env, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
4104 tcg_temp_free_i32(t0);
4108 static void gen_tdi(DisasContext *ctx)
4110 TCGv t0 = tcg_const_tl(SIMM(ctx->opcode));
4111 TCGv_i32 t1 = tcg_const_i32(TO(ctx->opcode));
4112 /* Update the nip since this might generate a trap exception */
4113 gen_update_nip(ctx, ctx->nip);
4114 gen_helper_td(cpu_env, cpu_gpr[rA(ctx->opcode)], t0, t1);
4116 tcg_temp_free_i32(t1);
4120 /*** Processor control ***/
4122 static void gen_read_xer(TCGv dst)
4124 TCGv t0 = tcg_temp_new();
4125 TCGv t1 = tcg_temp_new();
4126 TCGv t2 = tcg_temp_new();
4127 tcg_gen_mov_tl(dst, cpu_xer);
4128 tcg_gen_shli_tl(t0, cpu_so, XER_SO);
4129 tcg_gen_shli_tl(t1, cpu_ov, XER_OV);
4130 tcg_gen_shli_tl(t2, cpu_ca, XER_CA);
4131 tcg_gen_or_tl(t0, t0, t1);
4132 tcg_gen_or_tl(dst, dst, t2);
4133 tcg_gen_or_tl(dst, dst, t0);
4139 static void gen_write_xer(TCGv src)
4141 tcg_gen_andi_tl(cpu_xer, src,
4142 ~((1u << XER_SO) | (1u << XER_OV) | (1u << XER_CA)));
4143 tcg_gen_shri_tl(cpu_so, src, XER_SO);
4144 tcg_gen_shri_tl(cpu_ov, src, XER_OV);
4145 tcg_gen_shri_tl(cpu_ca, src, XER_CA);
4146 tcg_gen_andi_tl(cpu_so, cpu_so, 1);
4147 tcg_gen_andi_tl(cpu_ov, cpu_ov, 1);
4148 tcg_gen_andi_tl(cpu_ca, cpu_ca, 1);
4152 static void gen_mcrxr(DisasContext *ctx)
4154 TCGv_i32 t0 = tcg_temp_new_i32();
4155 TCGv_i32 t1 = tcg_temp_new_i32();
4156 TCGv_i32 dst = cpu_crf[crfD(ctx->opcode)];
4158 tcg_gen_trunc_tl_i32(t0, cpu_so);
4159 tcg_gen_trunc_tl_i32(t1, cpu_ov);
4160 tcg_gen_trunc_tl_i32(dst, cpu_ca);
4161 tcg_gen_shri_i32(t0, t0, 2);
4162 tcg_gen_shri_i32(t1, t1, 1);
4163 tcg_gen_or_i32(dst, dst, t0);
4164 tcg_gen_or_i32(dst, dst, t1);
4165 tcg_temp_free_i32(t0);
4166 tcg_temp_free_i32(t1);
4168 tcg_gen_movi_tl(cpu_so, 0);
4169 tcg_gen_movi_tl(cpu_ov, 0);
4170 tcg_gen_movi_tl(cpu_ca, 0);
4174 static void gen_mfcr(DisasContext *ctx)
4178 if (likely(ctx->opcode & 0x00100000)) {
4179 crm = CRM(ctx->opcode);
4180 if (likely(crm && ((crm & (crm - 1)) == 0))) {
4182 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], cpu_crf[7 - crn]);
4183 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)],
4184 cpu_gpr[rD(ctx->opcode)], crn * 4);
4187 TCGv_i32 t0 = tcg_temp_new_i32();
4188 tcg_gen_mov_i32(t0, cpu_crf[0]);
4189 tcg_gen_shli_i32(t0, t0, 4);
4190 tcg_gen_or_i32(t0, t0, cpu_crf[1]);
4191 tcg_gen_shli_i32(t0, t0, 4);
4192 tcg_gen_or_i32(t0, t0, cpu_crf[2]);
4193 tcg_gen_shli_i32(t0, t0, 4);
4194 tcg_gen_or_i32(t0, t0, cpu_crf[3]);
4195 tcg_gen_shli_i32(t0, t0, 4);
4196 tcg_gen_or_i32(t0, t0, cpu_crf[4]);
4197 tcg_gen_shli_i32(t0, t0, 4);
4198 tcg_gen_or_i32(t0, t0, cpu_crf[5]);
4199 tcg_gen_shli_i32(t0, t0, 4);
4200 tcg_gen_or_i32(t0, t0, cpu_crf[6]);
4201 tcg_gen_shli_i32(t0, t0, 4);
4202 tcg_gen_or_i32(t0, t0, cpu_crf[7]);
4203 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0);
4204 tcg_temp_free_i32(t0);
4209 static void gen_mfmsr(DisasContext *ctx)
4211 #if defined(CONFIG_USER_ONLY)
4212 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4214 if (unlikely(!ctx->mem_idx)) {
4215 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4218 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_msr);
4222 static void spr_noaccess(void *opaque, int gprn, int sprn)
4225 sprn = ((sprn >> 5) & 0x1F) | ((sprn & 0x1F) << 5);
4226 printf("ERROR: try to access SPR %d !\n", sprn);
4229 #define SPR_NOACCESS (&spr_noaccess)
4232 static inline void gen_op_mfspr(DisasContext *ctx)
4234 void (*read_cb)(void *opaque, int gprn, int sprn);
4235 uint32_t sprn = SPR(ctx->opcode);
4237 #if !defined(CONFIG_USER_ONLY)
4238 if (ctx->mem_idx == 2)
4239 read_cb = ctx->spr_cb[sprn].hea_read;
4240 else if (ctx->mem_idx)
4241 read_cb = ctx->spr_cb[sprn].oea_read;
4244 read_cb = ctx->spr_cb[sprn].uea_read;
4245 if (likely(read_cb != NULL)) {
4246 if (likely(read_cb != SPR_NOACCESS)) {
4247 (*read_cb)(ctx, rD(ctx->opcode), sprn);
4249 /* Privilege exception */
4250 /* This is a hack to avoid warnings when running Linux:
4251 * this OS breaks the PowerPC virtualisation model,
4252 * allowing userland application to read the PVR
4254 if (sprn != SPR_PVR) {
4255 qemu_log("Trying to read privileged spr %d (0x%03x) at "
4256 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4257 printf("Trying to read privileged spr %d (0x%03x) at "
4258 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4260 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4264 qemu_log("Trying to read invalid spr %d (0x%03x) at "
4265 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4266 printf("Trying to read invalid spr %d (0x%03x) at "
4267 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4268 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_SPR);
4272 static void gen_mfspr(DisasContext *ctx)
4278 static void gen_mftb(DisasContext *ctx)
4284 static void gen_mtcrf(DisasContext *ctx)
4288 crm = CRM(ctx->opcode);
4289 if (likely((ctx->opcode & 0x00100000))) {
4290 if (crm && ((crm & (crm - 1)) == 0)) {
4291 TCGv_i32 temp = tcg_temp_new_i32();
4293 tcg_gen_trunc_tl_i32(temp, cpu_gpr[rS(ctx->opcode)]);
4294 tcg_gen_shri_i32(temp, temp, crn * 4);
4295 tcg_gen_andi_i32(cpu_crf[7 - crn], temp, 0xf);
4296 tcg_temp_free_i32(temp);
4299 TCGv_i32 temp = tcg_temp_new_i32();
4300 tcg_gen_trunc_tl_i32(temp, cpu_gpr[rS(ctx->opcode)]);
4301 for (crn = 0 ; crn < 8 ; crn++) {
4302 if (crm & (1 << crn)) {
4303 tcg_gen_shri_i32(cpu_crf[7 - crn], temp, crn * 4);
4304 tcg_gen_andi_i32(cpu_crf[7 - crn], cpu_crf[7 - crn], 0xf);
4307 tcg_temp_free_i32(temp);
4312 #if defined(TARGET_PPC64)
4313 static void gen_mtmsrd(DisasContext *ctx)
4315 #if defined(CONFIG_USER_ONLY)
4316 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4318 if (unlikely(!ctx->mem_idx)) {
4319 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4322 if (ctx->opcode & 0x00010000) {
4323 /* Special form that does not need any synchronisation */
4324 TCGv t0 = tcg_temp_new();
4325 tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1 << MSR_RI) | (1 << MSR_EE));
4326 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~((1 << MSR_RI) | (1 << MSR_EE)));
4327 tcg_gen_or_tl(cpu_msr, cpu_msr, t0);
4330 /* XXX: we need to update nip before the store
4331 * if we enter power saving mode, we will exit the loop
4332 * directly from ppc_store_msr
4334 gen_update_nip(ctx, ctx->nip);
4335 gen_helper_store_msr(cpu_env, cpu_gpr[rS(ctx->opcode)]);
4336 /* Must stop the translation as machine state (may have) changed */
4337 /* Note that mtmsr is not always defined as context-synchronizing */
4338 gen_stop_exception(ctx);
4344 static void gen_mtmsr(DisasContext *ctx)
4346 #if defined(CONFIG_USER_ONLY)
4347 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4349 if (unlikely(!ctx->mem_idx)) {
4350 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4353 if (ctx->opcode & 0x00010000) {
4354 /* Special form that does not need any synchronisation */
4355 TCGv t0 = tcg_temp_new();
4356 tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1 << MSR_RI) | (1 << MSR_EE));
4357 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~((1 << MSR_RI) | (1 << MSR_EE)));
4358 tcg_gen_or_tl(cpu_msr, cpu_msr, t0);
4361 TCGv msr = tcg_temp_new();
4363 /* XXX: we need to update nip before the store
4364 * if we enter power saving mode, we will exit the loop
4365 * directly from ppc_store_msr
4367 gen_update_nip(ctx, ctx->nip);
4368 #if defined(TARGET_PPC64)
4369 tcg_gen_deposit_tl(msr, cpu_msr, cpu_gpr[rS(ctx->opcode)], 0, 32);
4371 tcg_gen_mov_tl(msr, cpu_gpr[rS(ctx->opcode)]);
4373 gen_helper_store_msr(cpu_env, msr);
4375 /* Must stop the translation as machine state (may have) changed */
4376 /* Note that mtmsr is not always defined as context-synchronizing */
4377 gen_stop_exception(ctx);
4383 static void gen_mtspr(DisasContext *ctx)
4385 void (*write_cb)(void *opaque, int sprn, int gprn);
4386 uint32_t sprn = SPR(ctx->opcode);
4388 #if !defined(CONFIG_USER_ONLY)
4389 if (ctx->mem_idx == 2)
4390 write_cb = ctx->spr_cb[sprn].hea_write;
4391 else if (ctx->mem_idx)
4392 write_cb = ctx->spr_cb[sprn].oea_write;
4395 write_cb = ctx->spr_cb[sprn].uea_write;
4396 if (likely(write_cb != NULL)) {
4397 if (likely(write_cb != SPR_NOACCESS)) {
4398 (*write_cb)(ctx, sprn, rS(ctx->opcode));
4400 /* Privilege exception */
4401 qemu_log("Trying to write privileged spr %d (0x%03x) at "
4402 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4403 printf("Trying to write privileged spr %d (0x%03x) at "
4404 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4405 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4409 qemu_log("Trying to write invalid spr %d (0x%03x) at "
4410 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4411 printf("Trying to write invalid spr %d (0x%03x) at "
4412 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4413 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_SPR);
4417 /*** Cache management ***/
4420 static void gen_dcbf(DisasContext *ctx)
4422 /* XXX: specification says this is treated as a load by the MMU */
4424 gen_set_access_type(ctx, ACCESS_CACHE);
4425 t0 = tcg_temp_new();
4426 gen_addr_reg_index(ctx, t0);
4427 gen_qemu_ld8u(ctx, t0, t0);
4431 /* dcbi (Supervisor only) */
4432 static void gen_dcbi(DisasContext *ctx)
4434 #if defined(CONFIG_USER_ONLY)
4435 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4438 if (unlikely(!ctx->mem_idx)) {
4439 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4442 EA = tcg_temp_new();
4443 gen_set_access_type(ctx, ACCESS_CACHE);
4444 gen_addr_reg_index(ctx, EA);
4445 val = tcg_temp_new();
4446 /* XXX: specification says this should be treated as a store by the MMU */
4447 gen_qemu_ld8u(ctx, val, EA);
4448 gen_qemu_st8(ctx, val, EA);
4455 static void gen_dcbst(DisasContext *ctx)
4457 /* XXX: specification say this is treated as a load by the MMU */
4459 gen_set_access_type(ctx, ACCESS_CACHE);
4460 t0 = tcg_temp_new();
4461 gen_addr_reg_index(ctx, t0);
4462 gen_qemu_ld8u(ctx, t0, t0);
4467 static void gen_dcbt(DisasContext *ctx)
4469 /* interpreted as no-op */
4470 /* XXX: specification say this is treated as a load by the MMU
4471 * but does not generate any exception
4476 static void gen_dcbtst(DisasContext *ctx)
4478 /* interpreted as no-op */
4479 /* XXX: specification say this is treated as a load by the MMU
4480 * but does not generate any exception
4485 static void gen_dcbz(DisasContext *ctx)
4488 TCGv_i32 tcgv_is_dcbzl;
4489 int is_dcbzl = ctx->opcode & 0x00200000 ? 1 : 0;
4491 gen_set_access_type(ctx, ACCESS_CACHE);
4492 /* NIP cannot be restored if the memory exception comes from an helper */
4493 gen_update_nip(ctx, ctx->nip - 4);
4494 tcgv_addr = tcg_temp_new();
4495 tcgv_is_dcbzl = tcg_const_i32(is_dcbzl);
4497 gen_addr_reg_index(ctx, tcgv_addr);
4498 gen_helper_dcbz(cpu_env, tcgv_addr, tcgv_is_dcbzl);
4500 tcg_temp_free(tcgv_addr);
4501 tcg_temp_free_i32(tcgv_is_dcbzl);
4505 static void gen_dst(DisasContext *ctx)
4507 if (rA(ctx->opcode) == 0) {
4508 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX);
4510 /* interpreted as no-op */
4515 static void gen_dstst(DisasContext *ctx)
4517 if (rA(ctx->opcode) == 0) {
4518 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX);
4520 /* interpreted as no-op */
4526 static void gen_dss(DisasContext *ctx)
4528 /* interpreted as no-op */
4532 static void gen_icbi(DisasContext *ctx)
4535 gen_set_access_type(ctx, ACCESS_CACHE);
4536 /* NIP cannot be restored if the memory exception comes from an helper */
4537 gen_update_nip(ctx, ctx->nip - 4);
4538 t0 = tcg_temp_new();
4539 gen_addr_reg_index(ctx, t0);
4540 gen_helper_icbi(cpu_env, t0);
4546 static void gen_dcba(DisasContext *ctx)
4548 /* interpreted as no-op */
4549 /* XXX: specification say this is treated as a store by the MMU
4550 * but does not generate any exception
4554 /*** Segment register manipulation ***/
4555 /* Supervisor only: */
4558 static void gen_mfsr(DisasContext *ctx)
4560 #if defined(CONFIG_USER_ONLY)
4561 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4564 if (unlikely(!ctx->mem_idx)) {
4565 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4568 t0 = tcg_const_tl(SR(ctx->opcode));
4569 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
4575 static void gen_mfsrin(DisasContext *ctx)
4577 #if defined(CONFIG_USER_ONLY)
4578 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4581 if (unlikely(!ctx->mem_idx)) {
4582 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4585 t0 = tcg_temp_new();
4586 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4587 tcg_gen_andi_tl(t0, t0, 0xF);
4588 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
4594 static void gen_mtsr(DisasContext *ctx)
4596 #if defined(CONFIG_USER_ONLY)
4597 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4600 if (unlikely(!ctx->mem_idx)) {
4601 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4604 t0 = tcg_const_tl(SR(ctx->opcode));
4605 gen_helper_store_sr(cpu_env, t0, cpu_gpr[rS(ctx->opcode)]);
4611 static void gen_mtsrin(DisasContext *ctx)
4613 #if defined(CONFIG_USER_ONLY)
4614 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4617 if (unlikely(!ctx->mem_idx)) {
4618 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4621 t0 = tcg_temp_new();
4622 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4623 tcg_gen_andi_tl(t0, t0, 0xF);
4624 gen_helper_store_sr(cpu_env, t0, cpu_gpr[rD(ctx->opcode)]);
4629 #if defined(TARGET_PPC64)
4630 /* Specific implementation for PowerPC 64 "bridge" emulation using SLB */
4633 static void gen_mfsr_64b(DisasContext *ctx)
4635 #if defined(CONFIG_USER_ONLY)
4636 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4639 if (unlikely(!ctx->mem_idx)) {
4640 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4643 t0 = tcg_const_tl(SR(ctx->opcode));
4644 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
4650 static void gen_mfsrin_64b(DisasContext *ctx)
4652 #if defined(CONFIG_USER_ONLY)
4653 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4656 if (unlikely(!ctx->mem_idx)) {
4657 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4660 t0 = tcg_temp_new();
4661 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4662 tcg_gen_andi_tl(t0, t0, 0xF);
4663 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
4669 static void gen_mtsr_64b(DisasContext *ctx)
4671 #if defined(CONFIG_USER_ONLY)
4672 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4675 if (unlikely(!ctx->mem_idx)) {
4676 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4679 t0 = tcg_const_tl(SR(ctx->opcode));
4680 gen_helper_store_sr(cpu_env, t0, cpu_gpr[rS(ctx->opcode)]);
4686 static void gen_mtsrin_64b(DisasContext *ctx)
4688 #if defined(CONFIG_USER_ONLY)
4689 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4692 if (unlikely(!ctx->mem_idx)) {
4693 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4696 t0 = tcg_temp_new();
4697 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4698 tcg_gen_andi_tl(t0, t0, 0xF);
4699 gen_helper_store_sr(cpu_env, t0, cpu_gpr[rS(ctx->opcode)]);
4705 static void gen_slbmte(DisasContext *ctx)
4707 #if defined(CONFIG_USER_ONLY)
4708 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4710 if (unlikely(!ctx->mem_idx)) {
4711 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4714 gen_helper_store_slb(cpu_env, cpu_gpr[rB(ctx->opcode)],
4715 cpu_gpr[rS(ctx->opcode)]);
4719 static void gen_slbmfee(DisasContext *ctx)
4721 #if defined(CONFIG_USER_ONLY)
4722 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4724 if (unlikely(!ctx->mem_idx)) {
4725 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4728 gen_helper_load_slb_esid(cpu_gpr[rS(ctx->opcode)], cpu_env,
4729 cpu_gpr[rB(ctx->opcode)]);
4733 static void gen_slbmfev(DisasContext *ctx)
4735 #if defined(CONFIG_USER_ONLY)
4736 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4738 if (unlikely(!ctx->mem_idx)) {
4739 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4742 gen_helper_load_slb_vsid(cpu_gpr[rS(ctx->opcode)], cpu_env,
4743 cpu_gpr[rB(ctx->opcode)]);
4746 #endif /* defined(TARGET_PPC64) */
4748 /*** Lookaside buffer management ***/
4749 /* Optional & mem_idx only: */
4752 static void gen_tlbia(DisasContext *ctx)
4754 #if defined(CONFIG_USER_ONLY)
4755 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4757 if (unlikely(!ctx->mem_idx)) {
4758 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4761 gen_helper_tlbia(cpu_env);
4766 static void gen_tlbiel(DisasContext *ctx)
4768 #if defined(CONFIG_USER_ONLY)
4769 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4771 if (unlikely(!ctx->mem_idx)) {
4772 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4775 gen_helper_tlbie(cpu_env, cpu_gpr[rB(ctx->opcode)]);
4780 static void gen_tlbie(DisasContext *ctx)
4782 #if defined(CONFIG_USER_ONLY)
4783 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4785 if (unlikely(!ctx->mem_idx)) {
4786 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4789 if (NARROW_MODE(ctx)) {
4790 TCGv t0 = tcg_temp_new();
4791 tcg_gen_ext32u_tl(t0, cpu_gpr[rB(ctx->opcode)]);
4792 gen_helper_tlbie(cpu_env, t0);
4795 gen_helper_tlbie(cpu_env, cpu_gpr[rB(ctx->opcode)]);
4801 static void gen_tlbsync(DisasContext *ctx)
4803 #if defined(CONFIG_USER_ONLY)
4804 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4806 if (unlikely(!ctx->mem_idx)) {
4807 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4810 /* This has no effect: it should ensure that all previous
4811 * tlbie have completed
4813 gen_stop_exception(ctx);
4817 #if defined(TARGET_PPC64)
4819 static void gen_slbia(DisasContext *ctx)
4821 #if defined(CONFIG_USER_ONLY)
4822 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4824 if (unlikely(!ctx->mem_idx)) {
4825 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4828 gen_helper_slbia(cpu_env);
4833 static void gen_slbie(DisasContext *ctx)
4835 #if defined(CONFIG_USER_ONLY)
4836 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4838 if (unlikely(!ctx->mem_idx)) {
4839 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4842 gen_helper_slbie(cpu_env, cpu_gpr[rB(ctx->opcode)]);
4847 /*** External control ***/
4851 static void gen_eciwx(DisasContext *ctx)
4854 /* Should check EAR[E] ! */
4855 gen_set_access_type(ctx, ACCESS_EXT);
4856 t0 = tcg_temp_new();
4857 gen_addr_reg_index(ctx, t0);
4858 gen_check_align(ctx, t0, 0x03);
4859 gen_qemu_ld32u(ctx, cpu_gpr[rD(ctx->opcode)], t0);
4864 static void gen_ecowx(DisasContext *ctx)
4867 /* Should check EAR[E] ! */
4868 gen_set_access_type(ctx, ACCESS_EXT);
4869 t0 = tcg_temp_new();
4870 gen_addr_reg_index(ctx, t0);
4871 gen_check_align(ctx, t0, 0x03);
4872 gen_qemu_st32(ctx, cpu_gpr[rD(ctx->opcode)], t0);
4876 /* PowerPC 601 specific instructions */
4879 static void gen_abs(DisasContext *ctx)
4881 int l1 = gen_new_label();
4882 int l2 = gen_new_label();
4883 tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rA(ctx->opcode)], 0, l1);
4884 tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4887 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4889 if (unlikely(Rc(ctx->opcode) != 0))
4890 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
4894 static void gen_abso(DisasContext *ctx)
4896 int l1 = gen_new_label();
4897 int l2 = gen_new_label();
4898 int l3 = gen_new_label();
4899 /* Start with XER OV disabled, the most likely case */
4900 tcg_gen_movi_tl(cpu_ov, 0);
4901 tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rA(ctx->opcode)], 0, l2);
4902 tcg_gen_brcondi_tl(TCG_COND_NE, cpu_gpr[rA(ctx->opcode)], 0x80000000, l1);
4903 tcg_gen_movi_tl(cpu_ov, 1);
4904 tcg_gen_movi_tl(cpu_so, 1);
4907 tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4910 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4912 if (unlikely(Rc(ctx->opcode) != 0))
4913 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
4917 static void gen_clcs(DisasContext *ctx)
4919 TCGv_i32 t0 = tcg_const_i32(rA(ctx->opcode));
4920 gen_helper_clcs(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
4921 tcg_temp_free_i32(t0);
4922 /* Rc=1 sets CR0 to an undefined state */
4926 static void gen_div(DisasContext *ctx)
4928 gen_helper_div(cpu_gpr[rD(ctx->opcode)], cpu_env, cpu_gpr[rA(ctx->opcode)],
4929 cpu_gpr[rB(ctx->opcode)]);
4930 if (unlikely(Rc(ctx->opcode) != 0))
4931 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
4935 static void gen_divo(DisasContext *ctx)
4937 gen_helper_divo(cpu_gpr[rD(ctx->opcode)], cpu_env, cpu_gpr[rA(ctx->opcode)],
4938 cpu_gpr[rB(ctx->opcode)]);
4939 if (unlikely(Rc(ctx->opcode) != 0))
4940 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
4944 static void gen_divs(DisasContext *ctx)
4946 gen_helper_divs(cpu_gpr[rD(ctx->opcode)], cpu_env, cpu_gpr[rA(ctx->opcode)],
4947 cpu_gpr[rB(ctx->opcode)]);
4948 if (unlikely(Rc(ctx->opcode) != 0))
4949 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
4952 /* divso - divso. */
4953 static void gen_divso(DisasContext *ctx)
4955 gen_helper_divso(cpu_gpr[rD(ctx->opcode)], cpu_env,
4956 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
4957 if (unlikely(Rc(ctx->opcode) != 0))
4958 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
4962 static void gen_doz(DisasContext *ctx)
4964 int l1 = gen_new_label();
4965 int l2 = gen_new_label();
4966 tcg_gen_brcond_tl(TCG_COND_GE, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], l1);
4967 tcg_gen_sub_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4970 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
4972 if (unlikely(Rc(ctx->opcode) != 0))
4973 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
4977 static void gen_dozo(DisasContext *ctx)
4979 int l1 = gen_new_label();
4980 int l2 = gen_new_label();
4981 TCGv t0 = tcg_temp_new();
4982 TCGv t1 = tcg_temp_new();
4983 TCGv t2 = tcg_temp_new();
4984 /* Start with XER OV disabled, the most likely case */
4985 tcg_gen_movi_tl(cpu_ov, 0);
4986 tcg_gen_brcond_tl(TCG_COND_GE, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], l1);
4987 tcg_gen_sub_tl(t0, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4988 tcg_gen_xor_tl(t1, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4989 tcg_gen_xor_tl(t2, cpu_gpr[rA(ctx->opcode)], t0);
4990 tcg_gen_andc_tl(t1, t1, t2);
4991 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
4992 tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l2);
4993 tcg_gen_movi_tl(cpu_ov, 1);
4994 tcg_gen_movi_tl(cpu_so, 1);
4997 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
5002 if (unlikely(Rc(ctx->opcode) != 0))
5003 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
5007 static void gen_dozi(DisasContext *ctx)
5009 target_long simm = SIMM(ctx->opcode);
5010 int l1 = gen_new_label();
5011 int l2 = gen_new_label();
5012 tcg_gen_brcondi_tl(TCG_COND_LT, cpu_gpr[rA(ctx->opcode)], simm, l1);
5013 tcg_gen_subfi_tl(cpu_gpr[rD(ctx->opcode)], simm, cpu_gpr[rA(ctx->opcode)]);
5016 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
5018 if (unlikely(Rc(ctx->opcode) != 0))
5019 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
5022 /* lscbx - lscbx. */
5023 static void gen_lscbx(DisasContext *ctx)
5025 TCGv t0 = tcg_temp_new();
5026 TCGv_i32 t1 = tcg_const_i32(rD(ctx->opcode));
5027 TCGv_i32 t2 = tcg_const_i32(rA(ctx->opcode));
5028 TCGv_i32 t3 = tcg_const_i32(rB(ctx->opcode));
5030 gen_addr_reg_index(ctx, t0);
5031 /* NIP cannot be restored if the memory exception comes from an helper */
5032 gen_update_nip(ctx, ctx->nip - 4);
5033 gen_helper_lscbx(t0, cpu_env, t0, t1, t2, t3);
5034 tcg_temp_free_i32(t1);
5035 tcg_temp_free_i32(t2);
5036 tcg_temp_free_i32(t3);
5037 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~0x7F);
5038 tcg_gen_or_tl(cpu_xer, cpu_xer, t0);
5039 if (unlikely(Rc(ctx->opcode) != 0))
5040 gen_set_Rc0(ctx, t0);
5044 /* maskg - maskg. */
5045 static void gen_maskg(DisasContext *ctx)
5047 int l1 = gen_new_label();
5048 TCGv t0 = tcg_temp_new();
5049 TCGv t1 = tcg_temp_new();
5050 TCGv t2 = tcg_temp_new();
5051 TCGv t3 = tcg_temp_new();
5052 tcg_gen_movi_tl(t3, 0xFFFFFFFF);
5053 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
5054 tcg_gen_andi_tl(t1, cpu_gpr[rS(ctx->opcode)], 0x1F);
5055 tcg_gen_addi_tl(t2, t0, 1);
5056 tcg_gen_shr_tl(t2, t3, t2);
5057 tcg_gen_shr_tl(t3, t3, t1);
5058 tcg_gen_xor_tl(cpu_gpr[rA(ctx->opcode)], t2, t3);
5059 tcg_gen_brcond_tl(TCG_COND_GE, t0, t1, l1);
5060 tcg_gen_neg_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5066 if (unlikely(Rc(ctx->opcode) != 0))
5067 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5070 /* maskir - maskir. */
5071 static void gen_maskir(DisasContext *ctx)
5073 TCGv t0 = tcg_temp_new();
5074 TCGv t1 = tcg_temp_new();
5075 tcg_gen_and_tl(t0, cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
5076 tcg_gen_andc_tl(t1, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
5077 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5080 if (unlikely(Rc(ctx->opcode) != 0))
5081 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5085 static void gen_mul(DisasContext *ctx)
5087 TCGv_i64 t0 = tcg_temp_new_i64();
5088 TCGv_i64 t1 = tcg_temp_new_i64();
5089 TCGv t2 = tcg_temp_new();
5090 tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
5091 tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
5092 tcg_gen_mul_i64(t0, t0, t1);
5093 tcg_gen_trunc_i64_tl(t2, t0);
5094 gen_store_spr(SPR_MQ, t2);
5095 tcg_gen_shri_i64(t1, t0, 32);
5096 tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t1);
5097 tcg_temp_free_i64(t0);
5098 tcg_temp_free_i64(t1);
5100 if (unlikely(Rc(ctx->opcode) != 0))
5101 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
5105 static void gen_mulo(DisasContext *ctx)
5107 int l1 = gen_new_label();
5108 TCGv_i64 t0 = tcg_temp_new_i64();
5109 TCGv_i64 t1 = tcg_temp_new_i64();
5110 TCGv t2 = tcg_temp_new();
5111 /* Start with XER OV disabled, the most likely case */
5112 tcg_gen_movi_tl(cpu_ov, 0);
5113 tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
5114 tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
5115 tcg_gen_mul_i64(t0, t0, t1);
5116 tcg_gen_trunc_i64_tl(t2, t0);
5117 gen_store_spr(SPR_MQ, t2);
5118 tcg_gen_shri_i64(t1, t0, 32);
5119 tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t1);
5120 tcg_gen_ext32s_i64(t1, t0);
5121 tcg_gen_brcond_i64(TCG_COND_EQ, t0, t1, l1);
5122 tcg_gen_movi_tl(cpu_ov, 1);
5123 tcg_gen_movi_tl(cpu_so, 1);
5125 tcg_temp_free_i64(t0);
5126 tcg_temp_free_i64(t1);
5128 if (unlikely(Rc(ctx->opcode) != 0))
5129 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
5133 static void gen_nabs(DisasContext *ctx)
5135 int l1 = gen_new_label();
5136 int l2 = gen_new_label();
5137 tcg_gen_brcondi_tl(TCG_COND_GT, cpu_gpr[rA(ctx->opcode)], 0, l1);
5138 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5141 tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5143 if (unlikely(Rc(ctx->opcode) != 0))
5144 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
5147 /* nabso - nabso. */
5148 static void gen_nabso(DisasContext *ctx)
5150 int l1 = gen_new_label();
5151 int l2 = gen_new_label();
5152 tcg_gen_brcondi_tl(TCG_COND_GT, cpu_gpr[rA(ctx->opcode)], 0, l1);
5153 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5156 tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5158 /* nabs never overflows */
5159 tcg_gen_movi_tl(cpu_ov, 0);
5160 if (unlikely(Rc(ctx->opcode) != 0))
5161 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
5165 static void gen_rlmi(DisasContext *ctx)
5167 uint32_t mb = MB(ctx->opcode);
5168 uint32_t me = ME(ctx->opcode);
5169 TCGv t0 = tcg_temp_new();
5170 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
5171 tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
5172 tcg_gen_andi_tl(t0, t0, MASK(mb, me));
5173 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~MASK(mb, me));
5174 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], t0);
5176 if (unlikely(Rc(ctx->opcode) != 0))
5177 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5181 static void gen_rrib(DisasContext *ctx)
5183 TCGv t0 = tcg_temp_new();
5184 TCGv t1 = tcg_temp_new();
5185 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
5186 tcg_gen_movi_tl(t1, 0x80000000);
5187 tcg_gen_shr_tl(t1, t1, t0);
5188 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
5189 tcg_gen_and_tl(t0, t0, t1);
5190 tcg_gen_andc_tl(t1, cpu_gpr[rA(ctx->opcode)], t1);
5191 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5194 if (unlikely(Rc(ctx->opcode) != 0))
5195 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5199 static void gen_sle(DisasContext *ctx)
5201 TCGv t0 = tcg_temp_new();
5202 TCGv t1 = tcg_temp_new();
5203 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5204 tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5205 tcg_gen_subfi_tl(t1, 32, t1);
5206 tcg_gen_shr_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
5207 tcg_gen_or_tl(t1, t0, t1);
5208 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5209 gen_store_spr(SPR_MQ, t1);
5212 if (unlikely(Rc(ctx->opcode) != 0))
5213 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5217 static void gen_sleq(DisasContext *ctx)
5219 TCGv t0 = tcg_temp_new();
5220 TCGv t1 = tcg_temp_new();
5221 TCGv t2 = tcg_temp_new();
5222 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
5223 tcg_gen_movi_tl(t2, 0xFFFFFFFF);
5224 tcg_gen_shl_tl(t2, t2, t0);
5225 tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
5226 gen_load_spr(t1, SPR_MQ);
5227 gen_store_spr(SPR_MQ, t0);
5228 tcg_gen_and_tl(t0, t0, t2);
5229 tcg_gen_andc_tl(t1, t1, t2);
5230 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5234 if (unlikely(Rc(ctx->opcode) != 0))
5235 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5239 static void gen_sliq(DisasContext *ctx)
5241 int sh = SH(ctx->opcode);
5242 TCGv t0 = tcg_temp_new();
5243 TCGv t1 = tcg_temp_new();
5244 tcg_gen_shli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5245 tcg_gen_shri_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh);
5246 tcg_gen_or_tl(t1, t0, t1);
5247 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5248 gen_store_spr(SPR_MQ, t1);
5251 if (unlikely(Rc(ctx->opcode) != 0))
5252 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5255 /* slliq - slliq. */
5256 static void gen_slliq(DisasContext *ctx)
5258 int sh = SH(ctx->opcode);
5259 TCGv t0 = tcg_temp_new();
5260 TCGv t1 = tcg_temp_new();
5261 tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5262 gen_load_spr(t1, SPR_MQ);
5263 gen_store_spr(SPR_MQ, t0);
5264 tcg_gen_andi_tl(t0, t0, (0xFFFFFFFFU << sh));
5265 tcg_gen_andi_tl(t1, t1, ~(0xFFFFFFFFU << sh));
5266 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5269 if (unlikely(Rc(ctx->opcode) != 0))
5270 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5274 static void gen_sllq(DisasContext *ctx)
5276 int l1 = gen_new_label();
5277 int l2 = gen_new_label();
5278 TCGv t0 = tcg_temp_local_new();
5279 TCGv t1 = tcg_temp_local_new();
5280 TCGv t2 = tcg_temp_local_new();
5281 tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F);
5282 tcg_gen_movi_tl(t1, 0xFFFFFFFF);
5283 tcg_gen_shl_tl(t1, t1, t2);
5284 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20);
5285 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
5286 gen_load_spr(t0, SPR_MQ);
5287 tcg_gen_and_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5290 tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t2);
5291 gen_load_spr(t2, SPR_MQ);
5292 tcg_gen_andc_tl(t1, t2, t1);
5293 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5298 if (unlikely(Rc(ctx->opcode) != 0))
5299 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5303 static void gen_slq(DisasContext *ctx)
5305 int l1 = gen_new_label();
5306 TCGv t0 = tcg_temp_new();
5307 TCGv t1 = tcg_temp_new();
5308 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5309 tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5310 tcg_gen_subfi_tl(t1, 32, t1);
5311 tcg_gen_shr_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
5312 tcg_gen_or_tl(t1, t0, t1);
5313 gen_store_spr(SPR_MQ, t1);
5314 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x20);
5315 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5316 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
5317 tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
5321 if (unlikely(Rc(ctx->opcode) != 0))
5322 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5325 /* sraiq - sraiq. */
5326 static void gen_sraiq(DisasContext *ctx)
5328 int sh = SH(ctx->opcode);
5329 int l1 = gen_new_label();
5330 TCGv t0 = tcg_temp_new();
5331 TCGv t1 = tcg_temp_new();
5332 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5333 tcg_gen_shli_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh);
5334 tcg_gen_or_tl(t0, t0, t1);
5335 gen_store_spr(SPR_MQ, t0);
5336 tcg_gen_movi_tl(cpu_ca, 0);
5337 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
5338 tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rS(ctx->opcode)], 0, l1);
5339 tcg_gen_movi_tl(cpu_ca, 1);
5341 tcg_gen_sari_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], sh);
5344 if (unlikely(Rc(ctx->opcode) != 0))
5345 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5349 static void gen_sraq(DisasContext *ctx)
5351 int l1 = gen_new_label();
5352 int l2 = gen_new_label();
5353 TCGv t0 = tcg_temp_new();
5354 TCGv t1 = tcg_temp_local_new();
5355 TCGv t2 = tcg_temp_local_new();
5356 tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F);
5357 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t2);
5358 tcg_gen_sar_tl(t1, cpu_gpr[rS(ctx->opcode)], t2);
5359 tcg_gen_subfi_tl(t2, 32, t2);
5360 tcg_gen_shl_tl(t2, cpu_gpr[rS(ctx->opcode)], t2);
5361 tcg_gen_or_tl(t0, t0, t2);
5362 gen_store_spr(SPR_MQ, t0);
5363 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20);
5364 tcg_gen_brcondi_tl(TCG_COND_EQ, t2, 0, l1);
5365 tcg_gen_mov_tl(t2, cpu_gpr[rS(ctx->opcode)]);
5366 tcg_gen_sari_tl(t1, cpu_gpr[rS(ctx->opcode)], 31);
5369 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t1);
5370 tcg_gen_movi_tl(cpu_ca, 0);
5371 tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l2);
5372 tcg_gen_brcondi_tl(TCG_COND_EQ, t2, 0, l2);
5373 tcg_gen_movi_tl(cpu_ca, 1);
5377 if (unlikely(Rc(ctx->opcode) != 0))
5378 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5382 static void gen_sre(DisasContext *ctx)
5384 TCGv t0 = tcg_temp_new();
5385 TCGv t1 = tcg_temp_new();
5386 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5387 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5388 tcg_gen_subfi_tl(t1, 32, t1);
5389 tcg_gen_shl_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
5390 tcg_gen_or_tl(t1, t0, t1);
5391 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5392 gen_store_spr(SPR_MQ, t1);
5395 if (unlikely(Rc(ctx->opcode) != 0))
5396 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5400 static void gen_srea(DisasContext *ctx)
5402 TCGv t0 = tcg_temp_new();
5403 TCGv t1 = tcg_temp_new();
5404 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5405 tcg_gen_rotr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5406 gen_store_spr(SPR_MQ, t0);
5407 tcg_gen_sar_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], t1);
5410 if (unlikely(Rc(ctx->opcode) != 0))
5411 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5415 static void gen_sreq(DisasContext *ctx)
5417 TCGv t0 = tcg_temp_new();
5418 TCGv t1 = tcg_temp_new();
5419 TCGv t2 = tcg_temp_new();
5420 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
5421 tcg_gen_movi_tl(t1, 0xFFFFFFFF);
5422 tcg_gen_shr_tl(t1, t1, t0);
5423 tcg_gen_rotr_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
5424 gen_load_spr(t2, SPR_MQ);
5425 gen_store_spr(SPR_MQ, t0);
5426 tcg_gen_and_tl(t0, t0, t1);
5427 tcg_gen_andc_tl(t2, t2, t1);
5428 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t2);
5432 if (unlikely(Rc(ctx->opcode) != 0))
5433 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5437 static void gen_sriq(DisasContext *ctx)
5439 int sh = SH(ctx->opcode);
5440 TCGv t0 = tcg_temp_new();
5441 TCGv t1 = tcg_temp_new();
5442 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5443 tcg_gen_shli_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh);
5444 tcg_gen_or_tl(t1, t0, t1);
5445 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5446 gen_store_spr(SPR_MQ, t1);
5449 if (unlikely(Rc(ctx->opcode) != 0))
5450 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5454 static void gen_srliq(DisasContext *ctx)
5456 int sh = SH(ctx->opcode);
5457 TCGv t0 = tcg_temp_new();
5458 TCGv t1 = tcg_temp_new();
5459 tcg_gen_rotri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5460 gen_load_spr(t1, SPR_MQ);
5461 gen_store_spr(SPR_MQ, t0);
5462 tcg_gen_andi_tl(t0, t0, (0xFFFFFFFFU >> sh));
5463 tcg_gen_andi_tl(t1, t1, ~(0xFFFFFFFFU >> sh));
5464 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5467 if (unlikely(Rc(ctx->opcode) != 0))
5468 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5472 static void gen_srlq(DisasContext *ctx)
5474 int l1 = gen_new_label();
5475 int l2 = gen_new_label();
5476 TCGv t0 = tcg_temp_local_new();
5477 TCGv t1 = tcg_temp_local_new();
5478 TCGv t2 = tcg_temp_local_new();
5479 tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F);
5480 tcg_gen_movi_tl(t1, 0xFFFFFFFF);
5481 tcg_gen_shr_tl(t2, t1, t2);
5482 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20);
5483 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
5484 gen_load_spr(t0, SPR_MQ);
5485 tcg_gen_and_tl(cpu_gpr[rA(ctx->opcode)], t0, t2);
5488 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t2);
5489 tcg_gen_and_tl(t0, t0, t2);
5490 gen_load_spr(t1, SPR_MQ);
5491 tcg_gen_andc_tl(t1, t1, t2);
5492 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5497 if (unlikely(Rc(ctx->opcode) != 0))
5498 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5502 static void gen_srq(DisasContext *ctx)
5504 int l1 = gen_new_label();
5505 TCGv t0 = tcg_temp_new();
5506 TCGv t1 = tcg_temp_new();
5507 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5508 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5509 tcg_gen_subfi_tl(t1, 32, t1);
5510 tcg_gen_shl_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
5511 tcg_gen_or_tl(t1, t0, t1);
5512 gen_store_spr(SPR_MQ, t1);
5513 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x20);
5514 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5515 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
5516 tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
5520 if (unlikely(Rc(ctx->opcode) != 0))
5521 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5524 /* PowerPC 602 specific instructions */
5527 static void gen_dsa(DisasContext *ctx)
5530 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
5534 static void gen_esa(DisasContext *ctx)
5537 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
5541 static void gen_mfrom(DisasContext *ctx)
5543 #if defined(CONFIG_USER_ONLY)
5544 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5546 if (unlikely(!ctx->mem_idx)) {
5547 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5550 gen_helper_602_mfrom(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5554 /* 602 - 603 - G2 TLB management */
5557 static void gen_tlbld_6xx(DisasContext *ctx)
5559 #if defined(CONFIG_USER_ONLY)
5560 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5562 if (unlikely(!ctx->mem_idx)) {
5563 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5566 gen_helper_6xx_tlbd(cpu_env, cpu_gpr[rB(ctx->opcode)]);
5571 static void gen_tlbli_6xx(DisasContext *ctx)
5573 #if defined(CONFIG_USER_ONLY)
5574 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5576 if (unlikely(!ctx->mem_idx)) {
5577 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5580 gen_helper_6xx_tlbi(cpu_env, cpu_gpr[rB(ctx->opcode)]);
5584 /* 74xx TLB management */
5587 static void gen_tlbld_74xx(DisasContext *ctx)
5589 #if defined(CONFIG_USER_ONLY)
5590 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5592 if (unlikely(!ctx->mem_idx)) {
5593 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5596 gen_helper_74xx_tlbd(cpu_env, cpu_gpr[rB(ctx->opcode)]);
5601 static void gen_tlbli_74xx(DisasContext *ctx)
5603 #if defined(CONFIG_USER_ONLY)
5604 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5606 if (unlikely(!ctx->mem_idx)) {
5607 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5610 gen_helper_74xx_tlbi(cpu_env, cpu_gpr[rB(ctx->opcode)]);
5614 /* POWER instructions not in PowerPC 601 */
5617 static void gen_clf(DisasContext *ctx)
5619 /* Cache line flush: implemented as no-op */
5623 static void gen_cli(DisasContext *ctx)
5625 /* Cache line invalidate: privileged and treated as no-op */
5626 #if defined(CONFIG_USER_ONLY)
5627 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5629 if (unlikely(!ctx->mem_idx)) {
5630 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5637 static void gen_dclst(DisasContext *ctx)
5639 /* Data cache line store: treated as no-op */
5642 static void gen_mfsri(DisasContext *ctx)
5644 #if defined(CONFIG_USER_ONLY)
5645 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5647 int ra = rA(ctx->opcode);
5648 int rd = rD(ctx->opcode);
5650 if (unlikely(!ctx->mem_idx)) {
5651 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5654 t0 = tcg_temp_new();
5655 gen_addr_reg_index(ctx, t0);
5656 tcg_gen_shri_tl(t0, t0, 28);
5657 tcg_gen_andi_tl(t0, t0, 0xF);
5658 gen_helper_load_sr(cpu_gpr[rd], cpu_env, t0);
5660 if (ra != 0 && ra != rd)
5661 tcg_gen_mov_tl(cpu_gpr[ra], cpu_gpr[rd]);
5665 static void gen_rac(DisasContext *ctx)
5667 #if defined(CONFIG_USER_ONLY)
5668 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5671 if (unlikely(!ctx->mem_idx)) {
5672 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5675 t0 = tcg_temp_new();
5676 gen_addr_reg_index(ctx, t0);
5677 gen_helper_rac(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
5682 static void gen_rfsvc(DisasContext *ctx)
5684 #if defined(CONFIG_USER_ONLY)
5685 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5687 if (unlikely(!ctx->mem_idx)) {
5688 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5691 gen_helper_rfsvc(cpu_env);
5692 gen_sync_exception(ctx);
5696 /* svc is not implemented for now */
5698 /* POWER2 specific instructions */
5699 /* Quad manipulation (load/store two floats at a time) */
5702 static void gen_lfq(DisasContext *ctx)
5704 int rd = rD(ctx->opcode);
5706 gen_set_access_type(ctx, ACCESS_FLOAT);
5707 t0 = tcg_temp_new();
5708 gen_addr_imm_index(ctx, t0, 0);
5709 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5710 gen_addr_add(ctx, t0, t0, 8);
5711 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t0);
5716 static void gen_lfqu(DisasContext *ctx)
5718 int ra = rA(ctx->opcode);
5719 int rd = rD(ctx->opcode);
5721 gen_set_access_type(ctx, ACCESS_FLOAT);
5722 t0 = tcg_temp_new();
5723 t1 = tcg_temp_new();
5724 gen_addr_imm_index(ctx, t0, 0);
5725 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5726 gen_addr_add(ctx, t1, t0, 8);
5727 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t1);
5729 tcg_gen_mov_tl(cpu_gpr[ra], t0);
5735 static void gen_lfqux(DisasContext *ctx)
5737 int ra = rA(ctx->opcode);
5738 int rd = rD(ctx->opcode);
5739 gen_set_access_type(ctx, ACCESS_FLOAT);
5741 t0 = tcg_temp_new();
5742 gen_addr_reg_index(ctx, t0);
5743 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5744 t1 = tcg_temp_new();
5745 gen_addr_add(ctx, t1, t0, 8);
5746 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t1);
5749 tcg_gen_mov_tl(cpu_gpr[ra], t0);
5754 static void gen_lfqx(DisasContext *ctx)
5756 int rd = rD(ctx->opcode);
5758 gen_set_access_type(ctx, ACCESS_FLOAT);
5759 t0 = tcg_temp_new();
5760 gen_addr_reg_index(ctx, t0);
5761 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5762 gen_addr_add(ctx, t0, t0, 8);
5763 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t0);
5768 static void gen_stfq(DisasContext *ctx)
5770 int rd = rD(ctx->opcode);
5772 gen_set_access_type(ctx, ACCESS_FLOAT);
5773 t0 = tcg_temp_new();
5774 gen_addr_imm_index(ctx, t0, 0);
5775 gen_qemu_st64(ctx, cpu_fpr[rd], t0);
5776 gen_addr_add(ctx, t0, t0, 8);
5777 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t0);
5782 static void gen_stfqu(DisasContext *ctx)
5784 int ra = rA(ctx->opcode);
5785 int rd = rD(ctx->opcode);
5787 gen_set_access_type(ctx, ACCESS_FLOAT);
5788 t0 = tcg_temp_new();
5789 gen_addr_imm_index(ctx, t0, 0);
5790 gen_qemu_st64(ctx, cpu_fpr[rd], t0);
5791 t1 = tcg_temp_new();
5792 gen_addr_add(ctx, t1, t0, 8);
5793 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t1);
5796 tcg_gen_mov_tl(cpu_gpr[ra], t0);
5801 static void gen_stfqux(DisasContext *ctx)
5803 int ra = rA(ctx->opcode);
5804 int rd = rD(ctx->opcode);
5806 gen_set_access_type(ctx, ACCESS_FLOAT);
5807 t0 = tcg_temp_new();
5808 gen_addr_reg_index(ctx, t0);
5809 gen_qemu_st64(ctx, cpu_fpr[rd], t0);
5810 t1 = tcg_temp_new();
5811 gen_addr_add(ctx, t1, t0, 8);
5812 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t1);
5815 tcg_gen_mov_tl(cpu_gpr[ra], t0);
5820 static void gen_stfqx(DisasContext *ctx)
5822 int rd = rD(ctx->opcode);
5824 gen_set_access_type(ctx, ACCESS_FLOAT);
5825 t0 = tcg_temp_new();
5826 gen_addr_reg_index(ctx, t0);
5827 gen_qemu_st64(ctx, cpu_fpr[rd], t0);
5828 gen_addr_add(ctx, t0, t0, 8);
5829 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t0);
5833 /* BookE specific instructions */
5835 /* XXX: not implemented on 440 ? */
5836 static void gen_mfapidi(DisasContext *ctx)
5839 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
5842 /* XXX: not implemented on 440 ? */
5843 static void gen_tlbiva(DisasContext *ctx)
5845 #if defined(CONFIG_USER_ONLY)
5846 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5849 if (unlikely(!ctx->mem_idx)) {
5850 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5853 t0 = tcg_temp_new();
5854 gen_addr_reg_index(ctx, t0);
5855 gen_helper_tlbie(cpu_env, cpu_gpr[rB(ctx->opcode)]);
5860 /* All 405 MAC instructions are translated here */
5861 static inline void gen_405_mulladd_insn(DisasContext *ctx, int opc2, int opc3,
5862 int ra, int rb, int rt, int Rc)
5866 t0 = tcg_temp_local_new();
5867 t1 = tcg_temp_local_new();
5869 switch (opc3 & 0x0D) {
5871 /* macchw - macchw. - macchwo - macchwo. */
5872 /* macchws - macchws. - macchwso - macchwso. */
5873 /* nmacchw - nmacchw. - nmacchwo - nmacchwo. */
5874 /* nmacchws - nmacchws. - nmacchwso - nmacchwso. */
5875 /* mulchw - mulchw. */
5876 tcg_gen_ext16s_tl(t0, cpu_gpr[ra]);
5877 tcg_gen_sari_tl(t1, cpu_gpr[rb], 16);
5878 tcg_gen_ext16s_tl(t1, t1);
5881 /* macchwu - macchwu. - macchwuo - macchwuo. */
5882 /* macchwsu - macchwsu. - macchwsuo - macchwsuo. */
5883 /* mulchwu - mulchwu. */
5884 tcg_gen_ext16u_tl(t0, cpu_gpr[ra]);
5885 tcg_gen_shri_tl(t1, cpu_gpr[rb], 16);
5886 tcg_gen_ext16u_tl(t1, t1);
5889 /* machhw - machhw. - machhwo - machhwo. */
5890 /* machhws - machhws. - machhwso - machhwso. */
5891 /* nmachhw - nmachhw. - nmachhwo - nmachhwo. */
5892 /* nmachhws - nmachhws. - nmachhwso - nmachhwso. */
5893 /* mulhhw - mulhhw. */
5894 tcg_gen_sari_tl(t0, cpu_gpr[ra], 16);
5895 tcg_gen_ext16s_tl(t0, t0);
5896 tcg_gen_sari_tl(t1, cpu_gpr[rb], 16);
5897 tcg_gen_ext16s_tl(t1, t1);
5900 /* machhwu - machhwu. - machhwuo - machhwuo. */
5901 /* machhwsu - machhwsu. - machhwsuo - machhwsuo. */
5902 /* mulhhwu - mulhhwu. */
5903 tcg_gen_shri_tl(t0, cpu_gpr[ra], 16);
5904 tcg_gen_ext16u_tl(t0, t0);
5905 tcg_gen_shri_tl(t1, cpu_gpr[rb], 16);
5906 tcg_gen_ext16u_tl(t1, t1);
5909 /* maclhw - maclhw. - maclhwo - maclhwo. */
5910 /* maclhws - maclhws. - maclhwso - maclhwso. */
5911 /* nmaclhw - nmaclhw. - nmaclhwo - nmaclhwo. */
5912 /* nmaclhws - nmaclhws. - nmaclhwso - nmaclhwso. */
5913 /* mullhw - mullhw. */
5914 tcg_gen_ext16s_tl(t0, cpu_gpr[ra]);
5915 tcg_gen_ext16s_tl(t1, cpu_gpr[rb]);
5918 /* maclhwu - maclhwu. - maclhwuo - maclhwuo. */
5919 /* maclhwsu - maclhwsu. - maclhwsuo - maclhwsuo. */
5920 /* mullhwu - mullhwu. */
5921 tcg_gen_ext16u_tl(t0, cpu_gpr[ra]);
5922 tcg_gen_ext16u_tl(t1, cpu_gpr[rb]);
5926 /* (n)multiply-and-accumulate (0x0C / 0x0E) */
5927 tcg_gen_mul_tl(t1, t0, t1);
5929 /* nmultiply-and-accumulate (0x0E) */
5930 tcg_gen_sub_tl(t0, cpu_gpr[rt], t1);
5932 /* multiply-and-accumulate (0x0C) */
5933 tcg_gen_add_tl(t0, cpu_gpr[rt], t1);
5937 /* Check overflow and/or saturate */
5938 int l1 = gen_new_label();
5941 /* Start with XER OV disabled, the most likely case */
5942 tcg_gen_movi_tl(cpu_ov, 0);
5946 tcg_gen_xor_tl(t1, cpu_gpr[rt], t1);
5947 tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l1);
5948 tcg_gen_xor_tl(t1, cpu_gpr[rt], t0);
5949 tcg_gen_brcondi_tl(TCG_COND_LT, t1, 0, l1);
5952 tcg_gen_sari_tl(t0, cpu_gpr[rt], 31);
5953 tcg_gen_xori_tl(t0, t0, 0x7fffffff);
5957 tcg_gen_brcond_tl(TCG_COND_GEU, t0, t1, l1);
5960 tcg_gen_movi_tl(t0, UINT32_MAX);
5964 /* Check overflow */
5965 tcg_gen_movi_tl(cpu_ov, 1);
5966 tcg_gen_movi_tl(cpu_so, 1);
5969 tcg_gen_mov_tl(cpu_gpr[rt], t0);
5972 tcg_gen_mul_tl(cpu_gpr[rt], t0, t1);
5976 if (unlikely(Rc) != 0) {
5978 gen_set_Rc0(ctx, cpu_gpr[rt]);
5982 #define GEN_MAC_HANDLER(name, opc2, opc3) \
5983 static void glue(gen_, name)(DisasContext *ctx) \
5985 gen_405_mulladd_insn(ctx, opc2, opc3, rA(ctx->opcode), rB(ctx->opcode), \
5986 rD(ctx->opcode), Rc(ctx->opcode)); \
5989 /* macchw - macchw. */
5990 GEN_MAC_HANDLER(macchw, 0x0C, 0x05);
5991 /* macchwo - macchwo. */
5992 GEN_MAC_HANDLER(macchwo, 0x0C, 0x15);
5993 /* macchws - macchws. */
5994 GEN_MAC_HANDLER(macchws, 0x0C, 0x07);
5995 /* macchwso - macchwso. */
5996 GEN_MAC_HANDLER(macchwso, 0x0C, 0x17);
5997 /* macchwsu - macchwsu. */
5998 GEN_MAC_HANDLER(macchwsu, 0x0C, 0x06);
5999 /* macchwsuo - macchwsuo. */
6000 GEN_MAC_HANDLER(macchwsuo, 0x0C, 0x16);
6001 /* macchwu - macchwu. */
6002 GEN_MAC_HANDLER(macchwu, 0x0C, 0x04);
6003 /* macchwuo - macchwuo. */
6004 GEN_MAC_HANDLER(macchwuo, 0x0C, 0x14);
6005 /* machhw - machhw. */
6006 GEN_MAC_HANDLER(machhw, 0x0C, 0x01);
6007 /* machhwo - machhwo. */
6008 GEN_MAC_HANDLER(machhwo, 0x0C, 0x11);
6009 /* machhws - machhws. */
6010 GEN_MAC_HANDLER(machhws, 0x0C, 0x03);
6011 /* machhwso - machhwso. */
6012 GEN_MAC_HANDLER(machhwso, 0x0C, 0x13);
6013 /* machhwsu - machhwsu. */
6014 GEN_MAC_HANDLER(machhwsu, 0x0C, 0x02);
6015 /* machhwsuo - machhwsuo. */
6016 GEN_MAC_HANDLER(machhwsuo, 0x0C, 0x12);
6017 /* machhwu - machhwu. */
6018 GEN_MAC_HANDLER(machhwu, 0x0C, 0x00);
6019 /* machhwuo - machhwuo. */
6020 GEN_MAC_HANDLER(machhwuo, 0x0C, 0x10);
6021 /* maclhw - maclhw. */
6022 GEN_MAC_HANDLER(maclhw, 0x0C, 0x0D);
6023 /* maclhwo - maclhwo. */
6024 GEN_MAC_HANDLER(maclhwo, 0x0C, 0x1D);
6025 /* maclhws - maclhws. */
6026 GEN_MAC_HANDLER(maclhws, 0x0C, 0x0F);
6027 /* maclhwso - maclhwso. */
6028 GEN_MAC_HANDLER(maclhwso, 0x0C, 0x1F);
6029 /* maclhwu - maclhwu. */
6030 GEN_MAC_HANDLER(maclhwu, 0x0C, 0x0C);
6031 /* maclhwuo - maclhwuo. */
6032 GEN_MAC_HANDLER(maclhwuo, 0x0C, 0x1C);
6033 /* maclhwsu - maclhwsu. */
6034 GEN_MAC_HANDLER(maclhwsu, 0x0C, 0x0E);
6035 /* maclhwsuo - maclhwsuo. */
6036 GEN_MAC_HANDLER(maclhwsuo, 0x0C, 0x1E);
6037 /* nmacchw - nmacchw. */
6038 GEN_MAC_HANDLER(nmacchw, 0x0E, 0x05);
6039 /* nmacchwo - nmacchwo. */
6040 GEN_MAC_HANDLER(nmacchwo, 0x0E, 0x15);
6041 /* nmacchws - nmacchws. */
6042 GEN_MAC_HANDLER(nmacchws, 0x0E, 0x07);
6043 /* nmacchwso - nmacchwso. */
6044 GEN_MAC_HANDLER(nmacchwso, 0x0E, 0x17);
6045 /* nmachhw - nmachhw. */
6046 GEN_MAC_HANDLER(nmachhw, 0x0E, 0x01);
6047 /* nmachhwo - nmachhwo. */
6048 GEN_MAC_HANDLER(nmachhwo, 0x0E, 0x11);
6049 /* nmachhws - nmachhws. */
6050 GEN_MAC_HANDLER(nmachhws, 0x0E, 0x03);
6051 /* nmachhwso - nmachhwso. */
6052 GEN_MAC_HANDLER(nmachhwso, 0x0E, 0x13);
6053 /* nmaclhw - nmaclhw. */
6054 GEN_MAC_HANDLER(nmaclhw, 0x0E, 0x0D);
6055 /* nmaclhwo - nmaclhwo. */
6056 GEN_MAC_HANDLER(nmaclhwo, 0x0E, 0x1D);
6057 /* nmaclhws - nmaclhws. */
6058 GEN_MAC_HANDLER(nmaclhws, 0x0E, 0x0F);
6059 /* nmaclhwso - nmaclhwso. */
6060 GEN_MAC_HANDLER(nmaclhwso, 0x0E, 0x1F);
6062 /* mulchw - mulchw. */
6063 GEN_MAC_HANDLER(mulchw, 0x08, 0x05);
6064 /* mulchwu - mulchwu. */
6065 GEN_MAC_HANDLER(mulchwu, 0x08, 0x04);
6066 /* mulhhw - mulhhw. */
6067 GEN_MAC_HANDLER(mulhhw, 0x08, 0x01);
6068 /* mulhhwu - mulhhwu. */
6069 GEN_MAC_HANDLER(mulhhwu, 0x08, 0x00);
6070 /* mullhw - mullhw. */
6071 GEN_MAC_HANDLER(mullhw, 0x08, 0x0D);
6072 /* mullhwu - mullhwu. */
6073 GEN_MAC_HANDLER(mullhwu, 0x08, 0x0C);
6076 static void gen_mfdcr(DisasContext *ctx)
6078 #if defined(CONFIG_USER_ONLY)
6079 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
6082 if (unlikely(!ctx->mem_idx)) {
6083 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
6086 /* NIP cannot be restored if the memory exception comes from an helper */
6087 gen_update_nip(ctx, ctx->nip - 4);
6088 dcrn = tcg_const_tl(SPR(ctx->opcode));
6089 gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_env, dcrn);
6090 tcg_temp_free(dcrn);
6095 static void gen_mtdcr(DisasContext *ctx)
6097 #if defined(CONFIG_USER_ONLY)
6098 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
6101 if (unlikely(!ctx->mem_idx)) {
6102 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
6105 /* NIP cannot be restored if the memory exception comes from an helper */
6106 gen_update_nip(ctx, ctx->nip - 4);
6107 dcrn = tcg_const_tl(SPR(ctx->opcode));
6108 gen_helper_store_dcr(cpu_env, dcrn, cpu_gpr[rS(ctx->opcode)]);
6109 tcg_temp_free(dcrn);
6114 /* XXX: not implemented on 440 ? */
6115 static void gen_mfdcrx(DisasContext *ctx)
6117 #if defined(CONFIG_USER_ONLY)
6118 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
6120 if (unlikely(!ctx->mem_idx)) {
6121 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
6124 /* NIP cannot be restored if the memory exception comes from an helper */
6125 gen_update_nip(ctx, ctx->nip - 4);
6126 gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_env,
6127 cpu_gpr[rA(ctx->opcode)]);
6128 /* Note: Rc update flag set leads to undefined state of Rc0 */
6133 /* XXX: not implemented on 440 ? */
6134 static void gen_mtdcrx(DisasContext *ctx)
6136 #if defined(CONFIG_USER_ONLY)
6137 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
6139 if (unlikely(!ctx->mem_idx)) {
6140 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
6143 /* NIP cannot be restored if the memory exception comes from an helper */
6144 gen_update_nip(ctx, ctx->nip - 4);
6145 gen_helper_store_dcr(cpu_env, cpu_gpr[rA(ctx->opcode)],
6146 cpu_gpr[rS(ctx->opcode)]);
6147 /* Note: Rc update flag set leads to undefined state of Rc0 */
6151 /* mfdcrux (PPC 460) : user-mode access to DCR */
6152 static void gen_mfdcrux(DisasContext *ctx)
6154 /* NIP cannot be restored if the memory exception comes from an helper */
6155 gen_update_nip(ctx, ctx->nip - 4);
6156 gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_env,
6157 cpu_gpr[rA(ctx->opcode)]);
6158 /* Note: Rc update flag set leads to undefined state of Rc0 */
6161 /* mtdcrux (PPC 460) : user-mode access to DCR */
6162 static void gen_mtdcrux(DisasContext *ctx)
6164 /* NIP cannot be restored if the memory exception comes from an helper */
6165 gen_update_nip(ctx, ctx->nip - 4);
6166 gen_helper_store_dcr(cpu_env, cpu_gpr[rA(ctx->opcode)],
6167 cpu_gpr[rS(ctx->opcode)]);
6168 /* Note: Rc update flag set leads to undefined state of Rc0 */
6172 static void gen_dccci(DisasContext *ctx)
6174 #if defined(CONFIG_USER_ONLY)
6175 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6177 if (unlikely(!ctx->mem_idx)) {
6178 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6181 /* interpreted as no-op */
6186 static void gen_dcread(DisasContext *ctx)
6188 #if defined(CONFIG_USER_ONLY)
6189 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6192 if (unlikely(!ctx->mem_idx)) {
6193 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6196 gen_set_access_type(ctx, ACCESS_CACHE);
6197 EA = tcg_temp_new();
6198 gen_addr_reg_index(ctx, EA);
6199 val = tcg_temp_new();
6200 gen_qemu_ld32u(ctx, val, EA);
6202 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], EA);
6208 static void gen_icbt_40x(DisasContext *ctx)
6210 /* interpreted as no-op */
6211 /* XXX: specification say this is treated as a load by the MMU
6212 * but does not generate any exception
6217 static void gen_iccci(DisasContext *ctx)
6219 #if defined(CONFIG_USER_ONLY)
6220 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6222 if (unlikely(!ctx->mem_idx)) {
6223 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6226 /* interpreted as no-op */
6231 static void gen_icread(DisasContext *ctx)
6233 #if defined(CONFIG_USER_ONLY)
6234 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6236 if (unlikely(!ctx->mem_idx)) {
6237 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6240 /* interpreted as no-op */
6244 /* rfci (mem_idx only) */
6245 static void gen_rfci_40x(DisasContext *ctx)
6247 #if defined(CONFIG_USER_ONLY)
6248 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6250 if (unlikely(!ctx->mem_idx)) {
6251 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6254 /* Restore CPU state */
6255 gen_helper_40x_rfci(cpu_env);
6256 gen_sync_exception(ctx);
6260 static void gen_rfci(DisasContext *ctx)
6262 #if defined(CONFIG_USER_ONLY)
6263 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6265 if (unlikely(!ctx->mem_idx)) {
6266 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6269 /* Restore CPU state */
6270 gen_helper_rfci(cpu_env);
6271 gen_sync_exception(ctx);
6275 /* BookE specific */
6277 /* XXX: not implemented on 440 ? */
6278 static void gen_rfdi(DisasContext *ctx)
6280 #if defined(CONFIG_USER_ONLY)
6281 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6283 if (unlikely(!ctx->mem_idx)) {
6284 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6287 /* Restore CPU state */
6288 gen_helper_rfdi(cpu_env);
6289 gen_sync_exception(ctx);
6293 /* XXX: not implemented on 440 ? */
6294 static void gen_rfmci(DisasContext *ctx)
6296 #if defined(CONFIG_USER_ONLY)
6297 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6299 if (unlikely(!ctx->mem_idx)) {
6300 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6303 /* Restore CPU state */
6304 gen_helper_rfmci(cpu_env);
6305 gen_sync_exception(ctx);
6309 /* TLB management - PowerPC 405 implementation */
6312 static void gen_tlbre_40x(DisasContext *ctx)
6314 #if defined(CONFIG_USER_ONLY)
6315 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6317 if (unlikely(!ctx->mem_idx)) {
6318 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6321 switch (rB(ctx->opcode)) {
6323 gen_helper_4xx_tlbre_hi(cpu_gpr[rD(ctx->opcode)], cpu_env,
6324 cpu_gpr[rA(ctx->opcode)]);
6327 gen_helper_4xx_tlbre_lo(cpu_gpr[rD(ctx->opcode)], cpu_env,
6328 cpu_gpr[rA(ctx->opcode)]);
6331 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
6337 /* tlbsx - tlbsx. */
6338 static void gen_tlbsx_40x(DisasContext *ctx)
6340 #if defined(CONFIG_USER_ONLY)
6341 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6344 if (unlikely(!ctx->mem_idx)) {
6345 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6348 t0 = tcg_temp_new();
6349 gen_addr_reg_index(ctx, t0);
6350 gen_helper_4xx_tlbsx(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
6352 if (Rc(ctx->opcode)) {
6353 int l1 = gen_new_label();
6354 tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so);
6355 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_gpr[rD(ctx->opcode)], -1, l1);
6356 tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 0x02);
6363 static void gen_tlbwe_40x(DisasContext *ctx)
6365 #if defined(CONFIG_USER_ONLY)
6366 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6368 if (unlikely(!ctx->mem_idx)) {
6369 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6372 switch (rB(ctx->opcode)) {
6374 gen_helper_4xx_tlbwe_hi(cpu_env, cpu_gpr[rA(ctx->opcode)],
6375 cpu_gpr[rS(ctx->opcode)]);
6378 gen_helper_4xx_tlbwe_lo(cpu_env, cpu_gpr[rA(ctx->opcode)],
6379 cpu_gpr[rS(ctx->opcode)]);
6382 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
6388 /* TLB management - PowerPC 440 implementation */
6391 static void gen_tlbre_440(DisasContext *ctx)
6393 #if defined(CONFIG_USER_ONLY)
6394 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6396 if (unlikely(!ctx->mem_idx)) {
6397 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6400 switch (rB(ctx->opcode)) {
6405 TCGv_i32 t0 = tcg_const_i32(rB(ctx->opcode));
6406 gen_helper_440_tlbre(cpu_gpr[rD(ctx->opcode)], cpu_env,
6407 t0, cpu_gpr[rA(ctx->opcode)]);
6408 tcg_temp_free_i32(t0);
6412 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
6418 /* tlbsx - tlbsx. */
6419 static void gen_tlbsx_440(DisasContext *ctx)
6421 #if defined(CONFIG_USER_ONLY)
6422 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6425 if (unlikely(!ctx->mem_idx)) {
6426 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6429 t0 = tcg_temp_new();
6430 gen_addr_reg_index(ctx, t0);
6431 gen_helper_440_tlbsx(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
6433 if (Rc(ctx->opcode)) {
6434 int l1 = gen_new_label();
6435 tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so);
6436 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_gpr[rD(ctx->opcode)], -1, l1);
6437 tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 0x02);
6444 static void gen_tlbwe_440(DisasContext *ctx)
6446 #if defined(CONFIG_USER_ONLY)
6447 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6449 if (unlikely(!ctx->mem_idx)) {
6450 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6453 switch (rB(ctx->opcode)) {
6458 TCGv_i32 t0 = tcg_const_i32(rB(ctx->opcode));
6459 gen_helper_440_tlbwe(cpu_env, t0, cpu_gpr[rA(ctx->opcode)],
6460 cpu_gpr[rS(ctx->opcode)]);
6461 tcg_temp_free_i32(t0);
6465 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
6471 /* TLB management - PowerPC BookE 2.06 implementation */
6474 static void gen_tlbre_booke206(DisasContext *ctx)
6476 #if defined(CONFIG_USER_ONLY)
6477 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6479 if (unlikely(!ctx->mem_idx)) {
6480 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6484 gen_helper_booke206_tlbre(cpu_env);
6488 /* tlbsx - tlbsx. */
6489 static void gen_tlbsx_booke206(DisasContext *ctx)
6491 #if defined(CONFIG_USER_ONLY)
6492 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6495 if (unlikely(!ctx->mem_idx)) {
6496 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6500 if (rA(ctx->opcode)) {
6501 t0 = tcg_temp_new();
6502 tcg_gen_mov_tl(t0, cpu_gpr[rD(ctx->opcode)]);
6504 t0 = tcg_const_tl(0);
6507 tcg_gen_add_tl(t0, t0, cpu_gpr[rB(ctx->opcode)]);
6508 gen_helper_booke206_tlbsx(cpu_env, t0);
6514 static void gen_tlbwe_booke206(DisasContext *ctx)
6516 #if defined(CONFIG_USER_ONLY)
6517 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6519 if (unlikely(!ctx->mem_idx)) {
6520 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6523 gen_update_nip(ctx, ctx->nip - 4);
6524 gen_helper_booke206_tlbwe(cpu_env);
6528 static void gen_tlbivax_booke206(DisasContext *ctx)
6530 #if defined(CONFIG_USER_ONLY)
6531 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6534 if (unlikely(!ctx->mem_idx)) {
6535 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6539 t0 = tcg_temp_new();
6540 gen_addr_reg_index(ctx, t0);
6542 gen_helper_booke206_tlbivax(cpu_env, t0);
6547 static void gen_tlbilx_booke206(DisasContext *ctx)
6549 #if defined(CONFIG_USER_ONLY)
6550 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6553 if (unlikely(!ctx->mem_idx)) {
6554 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6558 t0 = tcg_temp_new();
6559 gen_addr_reg_index(ctx, t0);
6561 switch((ctx->opcode >> 21) & 0x3) {
6563 gen_helper_booke206_tlbilx0(cpu_env, t0);
6566 gen_helper_booke206_tlbilx1(cpu_env, t0);
6569 gen_helper_booke206_tlbilx3(cpu_env, t0);
6572 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
6582 static void gen_wrtee(DisasContext *ctx)
6584 #if defined(CONFIG_USER_ONLY)
6585 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6588 if (unlikely(!ctx->mem_idx)) {
6589 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6592 t0 = tcg_temp_new();
6593 tcg_gen_andi_tl(t0, cpu_gpr[rD(ctx->opcode)], (1 << MSR_EE));
6594 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~(1 << MSR_EE));
6595 tcg_gen_or_tl(cpu_msr, cpu_msr, t0);
6597 /* Stop translation to have a chance to raise an exception
6598 * if we just set msr_ee to 1
6600 gen_stop_exception(ctx);
6605 static void gen_wrteei(DisasContext *ctx)
6607 #if defined(CONFIG_USER_ONLY)
6608 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6610 if (unlikely(!ctx->mem_idx)) {
6611 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6614 if (ctx->opcode & 0x00008000) {
6615 tcg_gen_ori_tl(cpu_msr, cpu_msr, (1 << MSR_EE));
6616 /* Stop translation to have a chance to raise an exception */
6617 gen_stop_exception(ctx);
6619 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~(1 << MSR_EE));
6624 /* PowerPC 440 specific instructions */
6627 static void gen_dlmzb(DisasContext *ctx)
6629 TCGv_i32 t0 = tcg_const_i32(Rc(ctx->opcode));
6630 gen_helper_dlmzb(cpu_gpr[rA(ctx->opcode)], cpu_env,
6631 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], t0);
6632 tcg_temp_free_i32(t0);
6635 /* mbar replaces eieio on 440 */
6636 static void gen_mbar(DisasContext *ctx)
6638 /* interpreted as no-op */
6641 /* msync replaces sync on 440 */
6642 static void gen_msync_4xx(DisasContext *ctx)
6644 /* interpreted as no-op */
6648 static void gen_icbt_440(DisasContext *ctx)
6650 /* interpreted as no-op */
6651 /* XXX: specification say this is treated as a load by the MMU
6652 * but does not generate any exception
6656 /* Embedded.Processor Control */
6658 static void gen_msgclr(DisasContext *ctx)
6660 #if defined(CONFIG_USER_ONLY)
6661 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6663 if (unlikely(ctx->mem_idx == 0)) {
6664 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6668 gen_helper_msgclr(cpu_env, cpu_gpr[rB(ctx->opcode)]);
6672 static void gen_msgsnd(DisasContext *ctx)
6674 #if defined(CONFIG_USER_ONLY)
6675 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6677 if (unlikely(ctx->mem_idx == 0)) {
6678 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6682 gen_helper_msgsnd(cpu_gpr[rB(ctx->opcode)]);
6686 /*** Altivec vector extension ***/
6687 /* Altivec registers moves */
6689 static inline TCGv_ptr gen_avr_ptr(int reg)
6691 TCGv_ptr r = tcg_temp_new_ptr();
6692 tcg_gen_addi_ptr(r, cpu_env, offsetof(CPUPPCState, avr[reg]));
6696 #define GEN_VR_LDX(name, opc2, opc3) \
6697 static void glue(gen_, name)(DisasContext *ctx) \
6700 if (unlikely(!ctx->altivec_enabled)) { \
6701 gen_exception(ctx, POWERPC_EXCP_VPU); \
6704 gen_set_access_type(ctx, ACCESS_INT); \
6705 EA = tcg_temp_new(); \
6706 gen_addr_reg_index(ctx, EA); \
6707 tcg_gen_andi_tl(EA, EA, ~0xf); \
6708 if (ctx->le_mode) { \
6709 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6710 tcg_gen_addi_tl(EA, EA, 8); \
6711 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6713 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6714 tcg_gen_addi_tl(EA, EA, 8); \
6715 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6717 tcg_temp_free(EA); \
6720 #define GEN_VR_STX(name, opc2, opc3) \
6721 static void gen_st##name(DisasContext *ctx) \
6724 if (unlikely(!ctx->altivec_enabled)) { \
6725 gen_exception(ctx, POWERPC_EXCP_VPU); \
6728 gen_set_access_type(ctx, ACCESS_INT); \
6729 EA = tcg_temp_new(); \
6730 gen_addr_reg_index(ctx, EA); \
6731 tcg_gen_andi_tl(EA, EA, ~0xf); \
6732 if (ctx->le_mode) { \
6733 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6734 tcg_gen_addi_tl(EA, EA, 8); \
6735 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6737 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6738 tcg_gen_addi_tl(EA, EA, 8); \
6739 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6741 tcg_temp_free(EA); \
6744 #define GEN_VR_LVE(name, opc2, opc3) \
6745 static void gen_lve##name(DisasContext *ctx) \
6749 if (unlikely(!ctx->altivec_enabled)) { \
6750 gen_exception(ctx, POWERPC_EXCP_VPU); \
6753 gen_set_access_type(ctx, ACCESS_INT); \
6754 EA = tcg_temp_new(); \
6755 gen_addr_reg_index(ctx, EA); \
6756 rs = gen_avr_ptr(rS(ctx->opcode)); \
6757 gen_helper_lve##name(cpu_env, rs, EA); \
6758 tcg_temp_free(EA); \
6759 tcg_temp_free_ptr(rs); \
6762 #define GEN_VR_STVE(name, opc2, opc3) \
6763 static void gen_stve##name(DisasContext *ctx) \
6767 if (unlikely(!ctx->altivec_enabled)) { \
6768 gen_exception(ctx, POWERPC_EXCP_VPU); \
6771 gen_set_access_type(ctx, ACCESS_INT); \
6772 EA = tcg_temp_new(); \
6773 gen_addr_reg_index(ctx, EA); \
6774 rs = gen_avr_ptr(rS(ctx->opcode)); \
6775 gen_helper_stve##name(cpu_env, rs, EA); \
6776 tcg_temp_free(EA); \
6777 tcg_temp_free_ptr(rs); \
6780 GEN_VR_LDX(lvx, 0x07, 0x03);
6781 /* As we don't emulate the cache, lvxl is stricly equivalent to lvx */
6782 GEN_VR_LDX(lvxl, 0x07, 0x0B);
6784 GEN_VR_LVE(bx, 0x07, 0x00);
6785 GEN_VR_LVE(hx, 0x07, 0x01);
6786 GEN_VR_LVE(wx, 0x07, 0x02);
6788 GEN_VR_STX(svx, 0x07, 0x07);
6789 /* As we don't emulate the cache, stvxl is stricly equivalent to stvx */
6790 GEN_VR_STX(svxl, 0x07, 0x0F);
6792 GEN_VR_STVE(bx, 0x07, 0x04);
6793 GEN_VR_STVE(hx, 0x07, 0x05);
6794 GEN_VR_STVE(wx, 0x07, 0x06);
6796 static void gen_lvsl(DisasContext *ctx)
6800 if (unlikely(!ctx->altivec_enabled)) {
6801 gen_exception(ctx, POWERPC_EXCP_VPU);
6804 EA = tcg_temp_new();
6805 gen_addr_reg_index(ctx, EA);
6806 rd = gen_avr_ptr(rD(ctx->opcode));
6807 gen_helper_lvsl(rd, EA);
6809 tcg_temp_free_ptr(rd);
6812 static void gen_lvsr(DisasContext *ctx)
6816 if (unlikely(!ctx->altivec_enabled)) {
6817 gen_exception(ctx, POWERPC_EXCP_VPU);
6820 EA = tcg_temp_new();
6821 gen_addr_reg_index(ctx, EA);
6822 rd = gen_avr_ptr(rD(ctx->opcode));
6823 gen_helper_lvsr(rd, EA);
6825 tcg_temp_free_ptr(rd);
6828 static void gen_mfvscr(DisasContext *ctx)
6831 if (unlikely(!ctx->altivec_enabled)) {
6832 gen_exception(ctx, POWERPC_EXCP_VPU);
6835 tcg_gen_movi_i64(cpu_avrh[rD(ctx->opcode)], 0);
6836 t = tcg_temp_new_i32();
6837 tcg_gen_ld_i32(t, cpu_env, offsetof(CPUPPCState, vscr));
6838 tcg_gen_extu_i32_i64(cpu_avrl[rD(ctx->opcode)], t);
6839 tcg_temp_free_i32(t);
6842 static void gen_mtvscr(DisasContext *ctx)
6845 if (unlikely(!ctx->altivec_enabled)) {
6846 gen_exception(ctx, POWERPC_EXCP_VPU);
6849 p = gen_avr_ptr(rD(ctx->opcode));
6850 gen_helper_mtvscr(cpu_env, p);
6851 tcg_temp_free_ptr(p);
6854 /* Logical operations */
6855 #define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \
6856 static void glue(gen_, name)(DisasContext *ctx) \
6858 if (unlikely(!ctx->altivec_enabled)) { \
6859 gen_exception(ctx, POWERPC_EXCP_VPU); \
6862 tcg_op(cpu_avrh[rD(ctx->opcode)], cpu_avrh[rA(ctx->opcode)], cpu_avrh[rB(ctx->opcode)]); \
6863 tcg_op(cpu_avrl[rD(ctx->opcode)], cpu_avrl[rA(ctx->opcode)], cpu_avrl[rB(ctx->opcode)]); \
6866 GEN_VX_LOGICAL(vand, tcg_gen_and_i64, 2, 16);
6867 GEN_VX_LOGICAL(vandc, tcg_gen_andc_i64, 2, 17);
6868 GEN_VX_LOGICAL(vor, tcg_gen_or_i64, 2, 18);
6869 GEN_VX_LOGICAL(vxor, tcg_gen_xor_i64, 2, 19);
6870 GEN_VX_LOGICAL(vnor, tcg_gen_nor_i64, 2, 20);
6871 GEN_VX_LOGICAL(veqv, tcg_gen_eqv_i64, 2, 26);
6872 GEN_VX_LOGICAL(vnand, tcg_gen_nand_i64, 2, 22);
6873 GEN_VX_LOGICAL(vorc, tcg_gen_orc_i64, 2, 21);
6875 #define GEN_VXFORM(name, opc2, opc3) \
6876 static void glue(gen_, name)(DisasContext *ctx) \
6878 TCGv_ptr ra, rb, rd; \
6879 if (unlikely(!ctx->altivec_enabled)) { \
6880 gen_exception(ctx, POWERPC_EXCP_VPU); \
6883 ra = gen_avr_ptr(rA(ctx->opcode)); \
6884 rb = gen_avr_ptr(rB(ctx->opcode)); \
6885 rd = gen_avr_ptr(rD(ctx->opcode)); \
6886 gen_helper_##name (rd, ra, rb); \
6887 tcg_temp_free_ptr(ra); \
6888 tcg_temp_free_ptr(rb); \
6889 tcg_temp_free_ptr(rd); \
6892 #define GEN_VXFORM_ENV(name, opc2, opc3) \
6893 static void glue(gen_, name)(DisasContext *ctx) \
6895 TCGv_ptr ra, rb, rd; \
6896 if (unlikely(!ctx->altivec_enabled)) { \
6897 gen_exception(ctx, POWERPC_EXCP_VPU); \
6900 ra = gen_avr_ptr(rA(ctx->opcode)); \
6901 rb = gen_avr_ptr(rB(ctx->opcode)); \
6902 rd = gen_avr_ptr(rD(ctx->opcode)); \
6903 gen_helper_##name(cpu_env, rd, ra, rb); \
6904 tcg_temp_free_ptr(ra); \
6905 tcg_temp_free_ptr(rb); \
6906 tcg_temp_free_ptr(rd); \
6909 #define GEN_VXFORM3(name, opc2, opc3) \
6910 static void glue(gen_, name)(DisasContext *ctx) \
6912 TCGv_ptr ra, rb, rc, rd; \
6913 if (unlikely(!ctx->altivec_enabled)) { \
6914 gen_exception(ctx, POWERPC_EXCP_VPU); \
6917 ra = gen_avr_ptr(rA(ctx->opcode)); \
6918 rb = gen_avr_ptr(rB(ctx->opcode)); \
6919 rc = gen_avr_ptr(rC(ctx->opcode)); \
6920 rd = gen_avr_ptr(rD(ctx->opcode)); \
6921 gen_helper_##name(rd, ra, rb, rc); \
6922 tcg_temp_free_ptr(ra); \
6923 tcg_temp_free_ptr(rb); \
6924 tcg_temp_free_ptr(rc); \
6925 tcg_temp_free_ptr(rd); \
6929 * Support for Altivec instruction pairs that use bit 31 (Rc) as
6930 * an opcode bit. In general, these pairs come from different
6931 * versions of the ISA, so we must also support a pair of flags for
6934 #define GEN_VXFORM_DUAL(name0, flg0, flg2_0, name1, flg1, flg2_1) \
6935 static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
6937 if ((Rc(ctx->opcode) == 0) && \
6938 ((ctx->insns_flags & flg0) || (ctx->insns_flags2 & flg2_0))) { \
6940 } else if ((Rc(ctx->opcode) == 1) && \
6941 ((ctx->insns_flags & flg1) || (ctx->insns_flags2 & flg2_1))) { \
6944 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
6948 GEN_VXFORM(vaddubm, 0, 0);
6949 GEN_VXFORM(vadduhm, 0, 1);
6950 GEN_VXFORM(vadduwm, 0, 2);
6951 GEN_VXFORM(vaddudm, 0, 3);
6952 GEN_VXFORM(vsububm, 0, 16);
6953 GEN_VXFORM(vsubuhm, 0, 17);
6954 GEN_VXFORM(vsubuwm, 0, 18);
6955 GEN_VXFORM(vsubudm, 0, 19);
6956 GEN_VXFORM(vmaxub, 1, 0);
6957 GEN_VXFORM(vmaxuh, 1, 1);
6958 GEN_VXFORM(vmaxuw, 1, 2);
6959 GEN_VXFORM(vmaxud, 1, 3);
6960 GEN_VXFORM(vmaxsb, 1, 4);
6961 GEN_VXFORM(vmaxsh, 1, 5);
6962 GEN_VXFORM(vmaxsw, 1, 6);
6963 GEN_VXFORM(vmaxsd, 1, 7);
6964 GEN_VXFORM(vminub, 1, 8);
6965 GEN_VXFORM(vminuh, 1, 9);
6966 GEN_VXFORM(vminuw, 1, 10);
6967 GEN_VXFORM(vminud, 1, 11);
6968 GEN_VXFORM(vminsb, 1, 12);
6969 GEN_VXFORM(vminsh, 1, 13);
6970 GEN_VXFORM(vminsw, 1, 14);
6971 GEN_VXFORM(vminsd, 1, 15);
6972 GEN_VXFORM(vavgub, 1, 16);
6973 GEN_VXFORM(vavguh, 1, 17);
6974 GEN_VXFORM(vavguw, 1, 18);
6975 GEN_VXFORM(vavgsb, 1, 20);
6976 GEN_VXFORM(vavgsh, 1, 21);
6977 GEN_VXFORM(vavgsw, 1, 22);
6978 GEN_VXFORM(vmrghb, 6, 0);
6979 GEN_VXFORM(vmrghh, 6, 1);
6980 GEN_VXFORM(vmrghw, 6, 2);
6981 GEN_VXFORM(vmrglb, 6, 4);
6982 GEN_VXFORM(vmrglh, 6, 5);
6983 GEN_VXFORM(vmrglw, 6, 6);
6985 static void gen_vmrgew(DisasContext *ctx)
6989 if (unlikely(!ctx->altivec_enabled)) {
6990 gen_exception(ctx, POWERPC_EXCP_VPU);
6993 VT = rD(ctx->opcode);
6994 VA = rA(ctx->opcode);
6995 VB = rB(ctx->opcode);
6996 tmp = tcg_temp_new_i64();
6997 tcg_gen_shri_i64(tmp, cpu_avrh[VB], 32);
6998 tcg_gen_deposit_i64(cpu_avrh[VT], cpu_avrh[VA], tmp, 0, 32);
6999 tcg_gen_shri_i64(tmp, cpu_avrl[VB], 32);
7000 tcg_gen_deposit_i64(cpu_avrl[VT], cpu_avrl[VA], tmp, 0, 32);
7001 tcg_temp_free_i64(tmp);
7004 static void gen_vmrgow(DisasContext *ctx)
7007 if (unlikely(!ctx->altivec_enabled)) {
7008 gen_exception(ctx, POWERPC_EXCP_VPU);
7011 VT = rD(ctx->opcode);
7012 VA = rA(ctx->opcode);
7013 VB = rB(ctx->opcode);
7015 tcg_gen_deposit_i64(cpu_avrh[VT], cpu_avrh[VB], cpu_avrh[VA], 32, 32);
7016 tcg_gen_deposit_i64(cpu_avrl[VT], cpu_avrl[VB], cpu_avrl[VA], 32, 32);
7019 GEN_VXFORM(vmuloub, 4, 0);
7020 GEN_VXFORM(vmulouh, 4, 1);
7021 GEN_VXFORM(vmulouw, 4, 2);
7022 GEN_VXFORM(vmuluwm, 4, 2);
7023 GEN_VXFORM_DUAL(vmulouw, PPC_ALTIVEC, PPC_NONE,
7024 vmuluwm, PPC_NONE, PPC2_ALTIVEC_207)
7025 GEN_VXFORM(vmulosb, 4, 4);
7026 GEN_VXFORM(vmulosh, 4, 5);
7027 GEN_VXFORM(vmulosw, 4, 6);
7028 GEN_VXFORM(vmuleub, 4, 8);
7029 GEN_VXFORM(vmuleuh, 4, 9);
7030 GEN_VXFORM(vmuleuw, 4, 10);
7031 GEN_VXFORM(vmulesb, 4, 12);
7032 GEN_VXFORM(vmulesh, 4, 13);
7033 GEN_VXFORM(vmulesw, 4, 14);
7034 GEN_VXFORM(vslb, 2, 4);
7035 GEN_VXFORM(vslh, 2, 5);
7036 GEN_VXFORM(vslw, 2, 6);
7037 GEN_VXFORM(vsld, 2, 23);
7038 GEN_VXFORM(vsrb, 2, 8);
7039 GEN_VXFORM(vsrh, 2, 9);
7040 GEN_VXFORM(vsrw, 2, 10);
7041 GEN_VXFORM(vsrd, 2, 27);
7042 GEN_VXFORM(vsrab, 2, 12);
7043 GEN_VXFORM(vsrah, 2, 13);
7044 GEN_VXFORM(vsraw, 2, 14);
7045 GEN_VXFORM(vsrad, 2, 15);
7046 GEN_VXFORM(vslo, 6, 16);
7047 GEN_VXFORM(vsro, 6, 17);
7048 GEN_VXFORM(vaddcuw, 0, 6);
7049 GEN_VXFORM(vsubcuw, 0, 22);
7050 GEN_VXFORM_ENV(vaddubs, 0, 8);
7051 GEN_VXFORM_ENV(vadduhs, 0, 9);
7052 GEN_VXFORM_ENV(vadduws, 0, 10);
7053 GEN_VXFORM_ENV(vaddsbs, 0, 12);
7054 GEN_VXFORM_ENV(vaddshs, 0, 13);
7055 GEN_VXFORM_ENV(vaddsws, 0, 14);
7056 GEN_VXFORM_ENV(vsububs, 0, 24);
7057 GEN_VXFORM_ENV(vsubuhs, 0, 25);
7058 GEN_VXFORM_ENV(vsubuws, 0, 26);
7059 GEN_VXFORM_ENV(vsubsbs, 0, 28);
7060 GEN_VXFORM_ENV(vsubshs, 0, 29);
7061 GEN_VXFORM_ENV(vsubsws, 0, 30);
7062 GEN_VXFORM(vadduqm, 0, 4);
7063 GEN_VXFORM(vaddcuq, 0, 5);
7064 GEN_VXFORM3(vaddeuqm, 30, 0);
7065 GEN_VXFORM3(vaddecuq, 30, 0);
7066 GEN_VXFORM_DUAL(vaddeuqm, PPC_NONE, PPC2_ALTIVEC_207, \
7067 vaddecuq, PPC_NONE, PPC2_ALTIVEC_207)
7068 GEN_VXFORM(vsubuqm, 0, 20);
7069 GEN_VXFORM(vsubcuq, 0, 21);
7070 GEN_VXFORM3(vsubeuqm, 31, 0);
7071 GEN_VXFORM3(vsubecuq, 31, 0);
7072 GEN_VXFORM_DUAL(vsubeuqm, PPC_NONE, PPC2_ALTIVEC_207, \
7073 vsubecuq, PPC_NONE, PPC2_ALTIVEC_207)
7074 GEN_VXFORM(vrlb, 2, 0);
7075 GEN_VXFORM(vrlh, 2, 1);
7076 GEN_VXFORM(vrlw, 2, 2);
7077 GEN_VXFORM(vrld, 2, 3);
7078 GEN_VXFORM(vsl, 2, 7);
7079 GEN_VXFORM(vsr, 2, 11);
7080 GEN_VXFORM_ENV(vpkuhum, 7, 0);
7081 GEN_VXFORM_ENV(vpkuwum, 7, 1);
7082 GEN_VXFORM_ENV(vpkudum, 7, 17);
7083 GEN_VXFORM_ENV(vpkuhus, 7, 2);
7084 GEN_VXFORM_ENV(vpkuwus, 7, 3);
7085 GEN_VXFORM_ENV(vpkudus, 7, 19);
7086 GEN_VXFORM_ENV(vpkshus, 7, 4);
7087 GEN_VXFORM_ENV(vpkswus, 7, 5);
7088 GEN_VXFORM_ENV(vpksdus, 7, 21);
7089 GEN_VXFORM_ENV(vpkshss, 7, 6);
7090 GEN_VXFORM_ENV(vpkswss, 7, 7);
7091 GEN_VXFORM_ENV(vpksdss, 7, 23);
7092 GEN_VXFORM(vpkpx, 7, 12);
7093 GEN_VXFORM_ENV(vsum4ubs, 4, 24);
7094 GEN_VXFORM_ENV(vsum4sbs, 4, 28);
7095 GEN_VXFORM_ENV(vsum4shs, 4, 25);
7096 GEN_VXFORM_ENV(vsum2sws, 4, 26);
7097 GEN_VXFORM_ENV(vsumsws, 4, 30);
7098 GEN_VXFORM_ENV(vaddfp, 5, 0);
7099 GEN_VXFORM_ENV(vsubfp, 5, 1);
7100 GEN_VXFORM_ENV(vmaxfp, 5, 16);
7101 GEN_VXFORM_ENV(vminfp, 5, 17);
7103 #define GEN_VXRFORM1(opname, name, str, opc2, opc3) \
7104 static void glue(gen_, name)(DisasContext *ctx) \
7106 TCGv_ptr ra, rb, rd; \
7107 if (unlikely(!ctx->altivec_enabled)) { \
7108 gen_exception(ctx, POWERPC_EXCP_VPU); \
7111 ra = gen_avr_ptr(rA(ctx->opcode)); \
7112 rb = gen_avr_ptr(rB(ctx->opcode)); \
7113 rd = gen_avr_ptr(rD(ctx->opcode)); \
7114 gen_helper_##opname(cpu_env, rd, ra, rb); \
7115 tcg_temp_free_ptr(ra); \
7116 tcg_temp_free_ptr(rb); \
7117 tcg_temp_free_ptr(rd); \
7120 #define GEN_VXRFORM(name, opc2, opc3) \
7121 GEN_VXRFORM1(name, name, #name, opc2, opc3) \
7122 GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4)))
7125 * Support for Altivec instructions that use bit 31 (Rc) as an opcode
7126 * bit but also use bit 21 as an actual Rc bit. In general, thse pairs
7127 * come from different versions of the ISA, so we must also support a
7128 * pair of flags for each instruction.
7130 #define GEN_VXRFORM_DUAL(name0, flg0, flg2_0, name1, flg1, flg2_1) \
7131 static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
7133 if ((Rc(ctx->opcode) == 0) && \
7134 ((ctx->insns_flags & flg0) || (ctx->insns_flags2 & flg2_0))) { \
7135 if (Rc21(ctx->opcode) == 0) { \
7138 gen_##name0##_(ctx); \
7140 } else if ((Rc(ctx->opcode) == 1) && \
7141 ((ctx->insns_flags & flg1) || (ctx->insns_flags2 & flg2_1))) { \
7142 if (Rc21(ctx->opcode) == 0) { \
7145 gen_##name1##_(ctx); \
7148 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
7152 GEN_VXRFORM(vcmpequb, 3, 0)
7153 GEN_VXRFORM(vcmpequh, 3, 1)
7154 GEN_VXRFORM(vcmpequw, 3, 2)
7155 GEN_VXRFORM(vcmpequd, 3, 3)
7156 GEN_VXRFORM(vcmpgtsb, 3, 12)
7157 GEN_VXRFORM(vcmpgtsh, 3, 13)
7158 GEN_VXRFORM(vcmpgtsw, 3, 14)
7159 GEN_VXRFORM(vcmpgtsd, 3, 15)
7160 GEN_VXRFORM(vcmpgtub, 3, 8)
7161 GEN_VXRFORM(vcmpgtuh, 3, 9)
7162 GEN_VXRFORM(vcmpgtuw, 3, 10)
7163 GEN_VXRFORM(vcmpgtud, 3, 11)
7164 GEN_VXRFORM(vcmpeqfp, 3, 3)
7165 GEN_VXRFORM(vcmpgefp, 3, 7)
7166 GEN_VXRFORM(vcmpgtfp, 3, 11)
7167 GEN_VXRFORM(vcmpbfp, 3, 15)
7169 GEN_VXRFORM_DUAL(vcmpeqfp, PPC_ALTIVEC, PPC_NONE, \
7170 vcmpequd, PPC_NONE, PPC2_ALTIVEC_207)
7171 GEN_VXRFORM_DUAL(vcmpbfp, PPC_ALTIVEC, PPC_NONE, \
7172 vcmpgtsd, PPC_NONE, PPC2_ALTIVEC_207)
7173 GEN_VXRFORM_DUAL(vcmpgtfp, PPC_ALTIVEC, PPC_NONE, \
7174 vcmpgtud, PPC_NONE, PPC2_ALTIVEC_207)
7176 #define GEN_VXFORM_SIMM(name, opc2, opc3) \
7177 static void glue(gen_, name)(DisasContext *ctx) \
7181 if (unlikely(!ctx->altivec_enabled)) { \
7182 gen_exception(ctx, POWERPC_EXCP_VPU); \
7185 simm = tcg_const_i32(SIMM5(ctx->opcode)); \
7186 rd = gen_avr_ptr(rD(ctx->opcode)); \
7187 gen_helper_##name (rd, simm); \
7188 tcg_temp_free_i32(simm); \
7189 tcg_temp_free_ptr(rd); \
7192 GEN_VXFORM_SIMM(vspltisb, 6, 12);
7193 GEN_VXFORM_SIMM(vspltish, 6, 13);
7194 GEN_VXFORM_SIMM(vspltisw, 6, 14);
7196 #define GEN_VXFORM_NOA(name, opc2, opc3) \
7197 static void glue(gen_, name)(DisasContext *ctx) \
7200 if (unlikely(!ctx->altivec_enabled)) { \
7201 gen_exception(ctx, POWERPC_EXCP_VPU); \
7204 rb = gen_avr_ptr(rB(ctx->opcode)); \
7205 rd = gen_avr_ptr(rD(ctx->opcode)); \
7206 gen_helper_##name (rd, rb); \
7207 tcg_temp_free_ptr(rb); \
7208 tcg_temp_free_ptr(rd); \
7211 #define GEN_VXFORM_NOA_ENV(name, opc2, opc3) \
7212 static void glue(gen_, name)(DisasContext *ctx) \
7216 if (unlikely(!ctx->altivec_enabled)) { \
7217 gen_exception(ctx, POWERPC_EXCP_VPU); \
7220 rb = gen_avr_ptr(rB(ctx->opcode)); \
7221 rd = gen_avr_ptr(rD(ctx->opcode)); \
7222 gen_helper_##name(cpu_env, rd, rb); \
7223 tcg_temp_free_ptr(rb); \
7224 tcg_temp_free_ptr(rd); \
7227 GEN_VXFORM_NOA(vupkhsb, 7, 8);
7228 GEN_VXFORM_NOA(vupkhsh, 7, 9);
7229 GEN_VXFORM_NOA(vupkhsw, 7, 25);
7230 GEN_VXFORM_NOA(vupklsb, 7, 10);
7231 GEN_VXFORM_NOA(vupklsh, 7, 11);
7232 GEN_VXFORM_NOA(vupklsw, 7, 27);
7233 GEN_VXFORM_NOA(vupkhpx, 7, 13);
7234 GEN_VXFORM_NOA(vupklpx, 7, 15);
7235 GEN_VXFORM_NOA_ENV(vrefp, 5, 4);
7236 GEN_VXFORM_NOA_ENV(vrsqrtefp, 5, 5);
7237 GEN_VXFORM_NOA_ENV(vexptefp, 5, 6);
7238 GEN_VXFORM_NOA_ENV(vlogefp, 5, 7);
7239 GEN_VXFORM_NOA_ENV(vrfim, 5, 8);
7240 GEN_VXFORM_NOA_ENV(vrfin, 5, 9);
7241 GEN_VXFORM_NOA_ENV(vrfip, 5, 10);
7242 GEN_VXFORM_NOA_ENV(vrfiz, 5, 11);
7244 #define GEN_VXFORM_SIMM(name, opc2, opc3) \
7245 static void glue(gen_, name)(DisasContext *ctx) \
7249 if (unlikely(!ctx->altivec_enabled)) { \
7250 gen_exception(ctx, POWERPC_EXCP_VPU); \
7253 simm = tcg_const_i32(SIMM5(ctx->opcode)); \
7254 rd = gen_avr_ptr(rD(ctx->opcode)); \
7255 gen_helper_##name (rd, simm); \
7256 tcg_temp_free_i32(simm); \
7257 tcg_temp_free_ptr(rd); \
7260 #define GEN_VXFORM_UIMM(name, opc2, opc3) \
7261 static void glue(gen_, name)(DisasContext *ctx) \
7265 if (unlikely(!ctx->altivec_enabled)) { \
7266 gen_exception(ctx, POWERPC_EXCP_VPU); \
7269 uimm = tcg_const_i32(UIMM5(ctx->opcode)); \
7270 rb = gen_avr_ptr(rB(ctx->opcode)); \
7271 rd = gen_avr_ptr(rD(ctx->opcode)); \
7272 gen_helper_##name (rd, rb, uimm); \
7273 tcg_temp_free_i32(uimm); \
7274 tcg_temp_free_ptr(rb); \
7275 tcg_temp_free_ptr(rd); \
7278 #define GEN_VXFORM_UIMM_ENV(name, opc2, opc3) \
7279 static void glue(gen_, name)(DisasContext *ctx) \
7284 if (unlikely(!ctx->altivec_enabled)) { \
7285 gen_exception(ctx, POWERPC_EXCP_VPU); \
7288 uimm = tcg_const_i32(UIMM5(ctx->opcode)); \
7289 rb = gen_avr_ptr(rB(ctx->opcode)); \
7290 rd = gen_avr_ptr(rD(ctx->opcode)); \
7291 gen_helper_##name(cpu_env, rd, rb, uimm); \
7292 tcg_temp_free_i32(uimm); \
7293 tcg_temp_free_ptr(rb); \
7294 tcg_temp_free_ptr(rd); \
7297 GEN_VXFORM_UIMM(vspltb, 6, 8);
7298 GEN_VXFORM_UIMM(vsplth, 6, 9);
7299 GEN_VXFORM_UIMM(vspltw, 6, 10);
7300 GEN_VXFORM_UIMM_ENV(vcfux, 5, 12);
7301 GEN_VXFORM_UIMM_ENV(vcfsx, 5, 13);
7302 GEN_VXFORM_UIMM_ENV(vctuxs, 5, 14);
7303 GEN_VXFORM_UIMM_ENV(vctsxs, 5, 15);
7305 static void gen_vsldoi(DisasContext *ctx)
7307 TCGv_ptr ra, rb, rd;
7309 if (unlikely(!ctx->altivec_enabled)) {
7310 gen_exception(ctx, POWERPC_EXCP_VPU);
7313 ra = gen_avr_ptr(rA(ctx->opcode));
7314 rb = gen_avr_ptr(rB(ctx->opcode));
7315 rd = gen_avr_ptr(rD(ctx->opcode));
7316 sh = tcg_const_i32(VSH(ctx->opcode));
7317 gen_helper_vsldoi (rd, ra, rb, sh);
7318 tcg_temp_free_ptr(ra);
7319 tcg_temp_free_ptr(rb);
7320 tcg_temp_free_ptr(rd);
7321 tcg_temp_free_i32(sh);
7324 #define GEN_VAFORM_PAIRED(name0, name1, opc2) \
7325 static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
7327 TCGv_ptr ra, rb, rc, rd; \
7328 if (unlikely(!ctx->altivec_enabled)) { \
7329 gen_exception(ctx, POWERPC_EXCP_VPU); \
7332 ra = gen_avr_ptr(rA(ctx->opcode)); \
7333 rb = gen_avr_ptr(rB(ctx->opcode)); \
7334 rc = gen_avr_ptr(rC(ctx->opcode)); \
7335 rd = gen_avr_ptr(rD(ctx->opcode)); \
7336 if (Rc(ctx->opcode)) { \
7337 gen_helper_##name1(cpu_env, rd, ra, rb, rc); \
7339 gen_helper_##name0(cpu_env, rd, ra, rb, rc); \
7341 tcg_temp_free_ptr(ra); \
7342 tcg_temp_free_ptr(rb); \
7343 tcg_temp_free_ptr(rc); \
7344 tcg_temp_free_ptr(rd); \
7347 GEN_VAFORM_PAIRED(vmhaddshs, vmhraddshs, 16)
7349 static void gen_vmladduhm(DisasContext *ctx)
7351 TCGv_ptr ra, rb, rc, rd;
7352 if (unlikely(!ctx->altivec_enabled)) {
7353 gen_exception(ctx, POWERPC_EXCP_VPU);
7356 ra = gen_avr_ptr(rA(ctx->opcode));
7357 rb = gen_avr_ptr(rB(ctx->opcode));
7358 rc = gen_avr_ptr(rC(ctx->opcode));
7359 rd = gen_avr_ptr(rD(ctx->opcode));
7360 gen_helper_vmladduhm(rd, ra, rb, rc);
7361 tcg_temp_free_ptr(ra);
7362 tcg_temp_free_ptr(rb);
7363 tcg_temp_free_ptr(rc);
7364 tcg_temp_free_ptr(rd);
7367 GEN_VAFORM_PAIRED(vmsumubm, vmsummbm, 18)
7368 GEN_VAFORM_PAIRED(vmsumuhm, vmsumuhs, 19)
7369 GEN_VAFORM_PAIRED(vmsumshm, vmsumshs, 20)
7370 GEN_VAFORM_PAIRED(vsel, vperm, 21)
7371 GEN_VAFORM_PAIRED(vmaddfp, vnmsubfp, 23)
7373 GEN_VXFORM_NOA(vclzb, 1, 28)
7374 GEN_VXFORM_NOA(vclzh, 1, 29)
7375 GEN_VXFORM_NOA(vclzw, 1, 30)
7376 GEN_VXFORM_NOA(vclzd, 1, 31)
7377 GEN_VXFORM_NOA(vpopcntb, 1, 28)
7378 GEN_VXFORM_NOA(vpopcnth, 1, 29)
7379 GEN_VXFORM_NOA(vpopcntw, 1, 30)
7380 GEN_VXFORM_NOA(vpopcntd, 1, 31)
7381 GEN_VXFORM_DUAL(vclzb, PPC_NONE, PPC2_ALTIVEC_207, \
7382 vpopcntb, PPC_NONE, PPC2_ALTIVEC_207)
7383 GEN_VXFORM_DUAL(vclzh, PPC_NONE, PPC2_ALTIVEC_207, \
7384 vpopcnth, PPC_NONE, PPC2_ALTIVEC_207)
7385 GEN_VXFORM_DUAL(vclzw, PPC_NONE, PPC2_ALTIVEC_207, \
7386 vpopcntw, PPC_NONE, PPC2_ALTIVEC_207)
7387 GEN_VXFORM_DUAL(vclzd, PPC_NONE, PPC2_ALTIVEC_207, \
7388 vpopcntd, PPC_NONE, PPC2_ALTIVEC_207)
7389 GEN_VXFORM(vbpermq, 6, 21);
7390 GEN_VXFORM_NOA(vgbbd, 6, 20);
7391 GEN_VXFORM(vpmsumb, 4, 16)
7392 GEN_VXFORM(vpmsumh, 4, 17)
7393 GEN_VXFORM(vpmsumw, 4, 18)
7394 GEN_VXFORM(vpmsumd, 4, 19)
7396 #define GEN_BCD(op) \
7397 static void gen_##op(DisasContext *ctx) \
7399 TCGv_ptr ra, rb, rd; \
7402 if (unlikely(!ctx->altivec_enabled)) { \
7403 gen_exception(ctx, POWERPC_EXCP_VPU); \
7407 ra = gen_avr_ptr(rA(ctx->opcode)); \
7408 rb = gen_avr_ptr(rB(ctx->opcode)); \
7409 rd = gen_avr_ptr(rD(ctx->opcode)); \
7411 ps = tcg_const_i32((ctx->opcode & 0x200) != 0); \
7413 gen_helper_##op(cpu_crf[6], rd, ra, rb, ps); \
7415 tcg_temp_free_ptr(ra); \
7416 tcg_temp_free_ptr(rb); \
7417 tcg_temp_free_ptr(rd); \
7418 tcg_temp_free_i32(ps); \
7424 GEN_VXFORM_DUAL(vsububm, PPC_ALTIVEC, PPC_NONE, \
7425 bcdadd, PPC_NONE, PPC2_ALTIVEC_207)
7426 GEN_VXFORM_DUAL(vsububs, PPC_ALTIVEC, PPC_NONE, \
7427 bcdadd, PPC_NONE, PPC2_ALTIVEC_207)
7428 GEN_VXFORM_DUAL(vsubuhm, PPC_ALTIVEC, PPC_NONE, \
7429 bcdsub, PPC_NONE, PPC2_ALTIVEC_207)
7430 GEN_VXFORM_DUAL(vsubuhs, PPC_ALTIVEC, PPC_NONE, \
7431 bcdsub, PPC_NONE, PPC2_ALTIVEC_207)
7433 static void gen_vsbox(DisasContext *ctx)
7436 if (unlikely(!ctx->altivec_enabled)) {
7437 gen_exception(ctx, POWERPC_EXCP_VPU);
7440 ra = gen_avr_ptr(rA(ctx->opcode));
7441 rd = gen_avr_ptr(rD(ctx->opcode));
7442 gen_helper_vsbox(rd, ra);
7443 tcg_temp_free_ptr(ra);
7444 tcg_temp_free_ptr(rd);
7447 GEN_VXFORM(vcipher, 4, 20)
7448 GEN_VXFORM(vcipherlast, 4, 20)
7449 GEN_VXFORM(vncipher, 4, 21)
7450 GEN_VXFORM(vncipherlast, 4, 21)
7452 GEN_VXFORM_DUAL(vcipher, PPC_NONE, PPC2_ALTIVEC_207,
7453 vcipherlast, PPC_NONE, PPC2_ALTIVEC_207)
7454 GEN_VXFORM_DUAL(vncipher, PPC_NONE, PPC2_ALTIVEC_207,
7455 vncipherlast, PPC_NONE, PPC2_ALTIVEC_207)
7457 #define VSHASIGMA(op) \
7458 static void gen_##op(DisasContext *ctx) \
7462 if (unlikely(!ctx->altivec_enabled)) { \
7463 gen_exception(ctx, POWERPC_EXCP_VPU); \
7466 ra = gen_avr_ptr(rA(ctx->opcode)); \
7467 rd = gen_avr_ptr(rD(ctx->opcode)); \
7468 st_six = tcg_const_i32(rB(ctx->opcode)); \
7469 gen_helper_##op(rd, ra, st_six); \
7470 tcg_temp_free_ptr(ra); \
7471 tcg_temp_free_ptr(rd); \
7472 tcg_temp_free_i32(st_six); \
7475 VSHASIGMA(vshasigmaw)
7476 VSHASIGMA(vshasigmad)
7478 GEN_VXFORM3(vpermxor, 22, 0xFF)
7479 GEN_VXFORM_DUAL(vsldoi, PPC_ALTIVEC, PPC_NONE,
7480 vpermxor, PPC_NONE, PPC2_ALTIVEC_207)
7482 /*** VSX extension ***/
7484 static inline TCGv_i64 cpu_vsrh(int n)
7489 return cpu_avrh[n-32];
7493 static inline TCGv_i64 cpu_vsrl(int n)
7498 return cpu_avrl[n-32];
7502 #define VSX_LOAD_SCALAR(name, operation) \
7503 static void gen_##name(DisasContext *ctx) \
7506 if (unlikely(!ctx->vsx_enabled)) { \
7507 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7510 gen_set_access_type(ctx, ACCESS_INT); \
7511 EA = tcg_temp_new(); \
7512 gen_addr_reg_index(ctx, EA); \
7513 gen_qemu_##operation(ctx, cpu_vsrh(xT(ctx->opcode)), EA); \
7514 /* NOTE: cpu_vsrl is undefined */ \
7515 tcg_temp_free(EA); \
7518 VSX_LOAD_SCALAR(lxsdx, ld64)
7519 VSX_LOAD_SCALAR(lxsiwax, ld32s_i64)
7520 VSX_LOAD_SCALAR(lxsiwzx, ld32u_i64)
7521 VSX_LOAD_SCALAR(lxsspx, ld32fs)
7523 static void gen_lxvd2x(DisasContext *ctx)
7526 if (unlikely(!ctx->vsx_enabled)) {
7527 gen_exception(ctx, POWERPC_EXCP_VSXU);
7530 gen_set_access_type(ctx, ACCESS_INT);
7531 EA = tcg_temp_new();
7532 gen_addr_reg_index(ctx, EA);
7533 gen_qemu_ld64(ctx, cpu_vsrh(xT(ctx->opcode)), EA);
7534 tcg_gen_addi_tl(EA, EA, 8);
7535 gen_qemu_ld64(ctx, cpu_vsrl(xT(ctx->opcode)), EA);
7539 static void gen_lxvdsx(DisasContext *ctx)
7542 if (unlikely(!ctx->vsx_enabled)) {
7543 gen_exception(ctx, POWERPC_EXCP_VSXU);
7546 gen_set_access_type(ctx, ACCESS_INT);
7547 EA = tcg_temp_new();
7548 gen_addr_reg_index(ctx, EA);
7549 gen_qemu_ld64(ctx, cpu_vsrh(xT(ctx->opcode)), EA);
7550 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), cpu_vsrh(xT(ctx->opcode)));
7554 static void gen_lxvw4x(DisasContext *ctx)
7558 TCGv_i64 xth = cpu_vsrh(xT(ctx->opcode));
7559 TCGv_i64 xtl = cpu_vsrl(xT(ctx->opcode));
7560 if (unlikely(!ctx->vsx_enabled)) {
7561 gen_exception(ctx, POWERPC_EXCP_VSXU);
7564 gen_set_access_type(ctx, ACCESS_INT);
7565 EA = tcg_temp_new();
7566 tmp = tcg_temp_new_i64();
7568 gen_addr_reg_index(ctx, EA);
7569 gen_qemu_ld32u_i64(ctx, tmp, EA);
7570 tcg_gen_addi_tl(EA, EA, 4);
7571 gen_qemu_ld32u_i64(ctx, xth, EA);
7572 tcg_gen_deposit_i64(xth, xth, tmp, 32, 32);
7574 tcg_gen_addi_tl(EA, EA, 4);
7575 gen_qemu_ld32u_i64(ctx, tmp, EA);
7576 tcg_gen_addi_tl(EA, EA, 4);
7577 gen_qemu_ld32u_i64(ctx, xtl, EA);
7578 tcg_gen_deposit_i64(xtl, xtl, tmp, 32, 32);
7581 tcg_temp_free_i64(tmp);
7584 #define VSX_STORE_SCALAR(name, operation) \
7585 static void gen_##name(DisasContext *ctx) \
7588 if (unlikely(!ctx->vsx_enabled)) { \
7589 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7592 gen_set_access_type(ctx, ACCESS_INT); \
7593 EA = tcg_temp_new(); \
7594 gen_addr_reg_index(ctx, EA); \
7595 gen_qemu_##operation(ctx, cpu_vsrh(xS(ctx->opcode)), EA); \
7596 tcg_temp_free(EA); \
7599 VSX_STORE_SCALAR(stxsdx, st64)
7600 VSX_STORE_SCALAR(stxsiwx, st32_i64)
7601 VSX_STORE_SCALAR(stxsspx, st32fs)
7603 static void gen_stxvd2x(DisasContext *ctx)
7606 if (unlikely(!ctx->vsx_enabled)) {
7607 gen_exception(ctx, POWERPC_EXCP_VSXU);
7610 gen_set_access_type(ctx, ACCESS_INT);
7611 EA = tcg_temp_new();
7612 gen_addr_reg_index(ctx, EA);
7613 gen_qemu_st64(ctx, cpu_vsrh(xS(ctx->opcode)), EA);
7614 tcg_gen_addi_tl(EA, EA, 8);
7615 gen_qemu_st64(ctx, cpu_vsrl(xS(ctx->opcode)), EA);
7619 static void gen_stxvw4x(DisasContext *ctx)
7623 if (unlikely(!ctx->vsx_enabled)) {
7624 gen_exception(ctx, POWERPC_EXCP_VSXU);
7627 gen_set_access_type(ctx, ACCESS_INT);
7628 EA = tcg_temp_new();
7629 gen_addr_reg_index(ctx, EA);
7630 tmp = tcg_temp_new_i64();
7632 tcg_gen_shri_i64(tmp, cpu_vsrh(xS(ctx->opcode)), 32);
7633 gen_qemu_st32_i64(ctx, tmp, EA);
7634 tcg_gen_addi_tl(EA, EA, 4);
7635 gen_qemu_st32_i64(ctx, cpu_vsrh(xS(ctx->opcode)), EA);
7637 tcg_gen_shri_i64(tmp, cpu_vsrl(xS(ctx->opcode)), 32);
7638 tcg_gen_addi_tl(EA, EA, 4);
7639 gen_qemu_st32_i64(ctx, tmp, EA);
7640 tcg_gen_addi_tl(EA, EA, 4);
7641 gen_qemu_st32_i64(ctx, cpu_vsrl(xS(ctx->opcode)), EA);
7644 tcg_temp_free_i64(tmp);
7647 #define MV_VSRW(name, tcgop1, tcgop2, target, source) \
7648 static void gen_##name(DisasContext *ctx) \
7650 if (xS(ctx->opcode) < 32) { \
7651 if (unlikely(!ctx->fpu_enabled)) { \
7652 gen_exception(ctx, POWERPC_EXCP_FPU); \
7656 if (unlikely(!ctx->altivec_enabled)) { \
7657 gen_exception(ctx, POWERPC_EXCP_VPU); \
7661 TCGv_i64 tmp = tcg_temp_new_i64(); \
7662 tcg_gen_##tcgop1(tmp, source); \
7663 tcg_gen_##tcgop2(target, tmp); \
7664 tcg_temp_free_i64(tmp); \
7668 MV_VSRW(mfvsrwz, ext32u_i64, trunc_i64_tl, cpu_gpr[rA(ctx->opcode)], \
7669 cpu_vsrh(xS(ctx->opcode)))
7670 MV_VSRW(mtvsrwa, extu_tl_i64, ext32s_i64, cpu_vsrh(xT(ctx->opcode)), \
7671 cpu_gpr[rA(ctx->opcode)])
7672 MV_VSRW(mtvsrwz, extu_tl_i64, ext32u_i64, cpu_vsrh(xT(ctx->opcode)), \
7673 cpu_gpr[rA(ctx->opcode)])
7675 #if defined(TARGET_PPC64)
7676 #define MV_VSRD(name, target, source) \
7677 static void gen_##name(DisasContext *ctx) \
7679 if (xS(ctx->opcode) < 32) { \
7680 if (unlikely(!ctx->fpu_enabled)) { \
7681 gen_exception(ctx, POWERPC_EXCP_FPU); \
7685 if (unlikely(!ctx->altivec_enabled)) { \
7686 gen_exception(ctx, POWERPC_EXCP_VPU); \
7690 tcg_gen_mov_i64(target, source); \
7693 MV_VSRD(mfvsrd, cpu_gpr[rA(ctx->opcode)], cpu_vsrh(xS(ctx->opcode)))
7694 MV_VSRD(mtvsrd, cpu_vsrh(xT(ctx->opcode)), cpu_gpr[rA(ctx->opcode)])
7698 static void gen_xxpermdi(DisasContext *ctx)
7700 if (unlikely(!ctx->vsx_enabled)) {
7701 gen_exception(ctx, POWERPC_EXCP_VSXU);
7705 if (unlikely((xT(ctx->opcode) == xA(ctx->opcode)) ||
7706 (xT(ctx->opcode) == xB(ctx->opcode)))) {
7709 xh = tcg_temp_new_i64();
7710 xl = tcg_temp_new_i64();
7712 if ((DM(ctx->opcode) & 2) == 0) {
7713 tcg_gen_mov_i64(xh, cpu_vsrh(xA(ctx->opcode)));
7715 tcg_gen_mov_i64(xh, cpu_vsrl(xA(ctx->opcode)));
7717 if ((DM(ctx->opcode) & 1) == 0) {
7718 tcg_gen_mov_i64(xl, cpu_vsrh(xB(ctx->opcode)));
7720 tcg_gen_mov_i64(xl, cpu_vsrl(xB(ctx->opcode)));
7723 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xh);
7724 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), xl);
7726 tcg_temp_free_i64(xh);
7727 tcg_temp_free_i64(xl);
7729 if ((DM(ctx->opcode) & 2) == 0) {
7730 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), cpu_vsrh(xA(ctx->opcode)));
7732 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), cpu_vsrl(xA(ctx->opcode)));
7734 if ((DM(ctx->opcode) & 1) == 0) {
7735 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), cpu_vsrh(xB(ctx->opcode)));
7737 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), cpu_vsrl(xB(ctx->opcode)));
7746 #define SGN_MASK_DP 0x8000000000000000ull
7747 #define SGN_MASK_SP 0x8000000080000000ull
7749 #define VSX_SCALAR_MOVE(name, op, sgn_mask) \
7750 static void glue(gen_, name)(DisasContext * ctx) \
7753 if (unlikely(!ctx->vsx_enabled)) { \
7754 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7757 xb = tcg_temp_new_i64(); \
7758 sgm = tcg_temp_new_i64(); \
7759 tcg_gen_mov_i64(xb, cpu_vsrh(xB(ctx->opcode))); \
7760 tcg_gen_movi_i64(sgm, sgn_mask); \
7763 tcg_gen_andc_i64(xb, xb, sgm); \
7767 tcg_gen_or_i64(xb, xb, sgm); \
7771 tcg_gen_xor_i64(xb, xb, sgm); \
7775 TCGv_i64 xa = tcg_temp_new_i64(); \
7776 tcg_gen_mov_i64(xa, cpu_vsrh(xA(ctx->opcode))); \
7777 tcg_gen_and_i64(xa, xa, sgm); \
7778 tcg_gen_andc_i64(xb, xb, sgm); \
7779 tcg_gen_or_i64(xb, xb, xa); \
7780 tcg_temp_free_i64(xa); \
7784 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xb); \
7785 tcg_temp_free_i64(xb); \
7786 tcg_temp_free_i64(sgm); \
7789 VSX_SCALAR_MOVE(xsabsdp, OP_ABS, SGN_MASK_DP)
7790 VSX_SCALAR_MOVE(xsnabsdp, OP_NABS, SGN_MASK_DP)
7791 VSX_SCALAR_MOVE(xsnegdp, OP_NEG, SGN_MASK_DP)
7792 VSX_SCALAR_MOVE(xscpsgndp, OP_CPSGN, SGN_MASK_DP)
7794 #define VSX_VECTOR_MOVE(name, op, sgn_mask) \
7795 static void glue(gen_, name)(DisasContext * ctx) \
7797 TCGv_i64 xbh, xbl, sgm; \
7798 if (unlikely(!ctx->vsx_enabled)) { \
7799 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7802 xbh = tcg_temp_new_i64(); \
7803 xbl = tcg_temp_new_i64(); \
7804 sgm = tcg_temp_new_i64(); \
7805 tcg_gen_mov_i64(xbh, cpu_vsrh(xB(ctx->opcode))); \
7806 tcg_gen_mov_i64(xbl, cpu_vsrl(xB(ctx->opcode))); \
7807 tcg_gen_movi_i64(sgm, sgn_mask); \
7810 tcg_gen_andc_i64(xbh, xbh, sgm); \
7811 tcg_gen_andc_i64(xbl, xbl, sgm); \
7815 tcg_gen_or_i64(xbh, xbh, sgm); \
7816 tcg_gen_or_i64(xbl, xbl, sgm); \
7820 tcg_gen_xor_i64(xbh, xbh, sgm); \
7821 tcg_gen_xor_i64(xbl, xbl, sgm); \
7825 TCGv_i64 xah = tcg_temp_new_i64(); \
7826 TCGv_i64 xal = tcg_temp_new_i64(); \
7827 tcg_gen_mov_i64(xah, cpu_vsrh(xA(ctx->opcode))); \
7828 tcg_gen_mov_i64(xal, cpu_vsrl(xA(ctx->opcode))); \
7829 tcg_gen_and_i64(xah, xah, sgm); \
7830 tcg_gen_and_i64(xal, xal, sgm); \
7831 tcg_gen_andc_i64(xbh, xbh, sgm); \
7832 tcg_gen_andc_i64(xbl, xbl, sgm); \
7833 tcg_gen_or_i64(xbh, xbh, xah); \
7834 tcg_gen_or_i64(xbl, xbl, xal); \
7835 tcg_temp_free_i64(xah); \
7836 tcg_temp_free_i64(xal); \
7840 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xbh); \
7841 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), xbl); \
7842 tcg_temp_free_i64(xbh); \
7843 tcg_temp_free_i64(xbl); \
7844 tcg_temp_free_i64(sgm); \
7847 VSX_VECTOR_MOVE(xvabsdp, OP_ABS, SGN_MASK_DP)
7848 VSX_VECTOR_MOVE(xvnabsdp, OP_NABS, SGN_MASK_DP)
7849 VSX_VECTOR_MOVE(xvnegdp, OP_NEG, SGN_MASK_DP)
7850 VSX_VECTOR_MOVE(xvcpsgndp, OP_CPSGN, SGN_MASK_DP)
7851 VSX_VECTOR_MOVE(xvabssp, OP_ABS, SGN_MASK_SP)
7852 VSX_VECTOR_MOVE(xvnabssp, OP_NABS, SGN_MASK_SP)
7853 VSX_VECTOR_MOVE(xvnegsp, OP_NEG, SGN_MASK_SP)
7854 VSX_VECTOR_MOVE(xvcpsgnsp, OP_CPSGN, SGN_MASK_SP)
7856 #define GEN_VSX_HELPER_2(name, op1, op2, inval, type) \
7857 static void gen_##name(DisasContext * ctx) \
7860 if (unlikely(!ctx->vsx_enabled)) { \
7861 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7864 /* NIP cannot be restored if the memory exception comes from an helper */ \
7865 gen_update_nip(ctx, ctx->nip - 4); \
7866 opc = tcg_const_i32(ctx->opcode); \
7867 gen_helper_##name(cpu_env, opc); \
7868 tcg_temp_free_i32(opc); \
7871 #define GEN_VSX_HELPER_XT_XB_ENV(name, op1, op2, inval, type) \
7872 static void gen_##name(DisasContext * ctx) \
7874 if (unlikely(!ctx->vsx_enabled)) { \
7875 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7878 /* NIP cannot be restored if the exception comes */ \
7879 /* from a helper. */ \
7880 gen_update_nip(ctx, ctx->nip - 4); \
7882 gen_helper_##name(cpu_vsrh(xT(ctx->opcode)), cpu_env, \
7883 cpu_vsrh(xB(ctx->opcode))); \
7886 GEN_VSX_HELPER_2(xsadddp, 0x00, 0x04, 0, PPC2_VSX)
7887 GEN_VSX_HELPER_2(xssubdp, 0x00, 0x05, 0, PPC2_VSX)
7888 GEN_VSX_HELPER_2(xsmuldp, 0x00, 0x06, 0, PPC2_VSX)
7889 GEN_VSX_HELPER_2(xsdivdp, 0x00, 0x07, 0, PPC2_VSX)
7890 GEN_VSX_HELPER_2(xsredp, 0x14, 0x05, 0, PPC2_VSX)
7891 GEN_VSX_HELPER_2(xssqrtdp, 0x16, 0x04, 0, PPC2_VSX)
7892 GEN_VSX_HELPER_2(xsrsqrtedp, 0x14, 0x04, 0, PPC2_VSX)
7893 GEN_VSX_HELPER_2(xstdivdp, 0x14, 0x07, 0, PPC2_VSX)
7894 GEN_VSX_HELPER_2(xstsqrtdp, 0x14, 0x06, 0, PPC2_VSX)
7895 GEN_VSX_HELPER_2(xsmaddadp, 0x04, 0x04, 0, PPC2_VSX)
7896 GEN_VSX_HELPER_2(xsmaddmdp, 0x04, 0x05, 0, PPC2_VSX)
7897 GEN_VSX_HELPER_2(xsmsubadp, 0x04, 0x06, 0, PPC2_VSX)
7898 GEN_VSX_HELPER_2(xsmsubmdp, 0x04, 0x07, 0, PPC2_VSX)
7899 GEN_VSX_HELPER_2(xsnmaddadp, 0x04, 0x14, 0, PPC2_VSX)
7900 GEN_VSX_HELPER_2(xsnmaddmdp, 0x04, 0x15, 0, PPC2_VSX)
7901 GEN_VSX_HELPER_2(xsnmsubadp, 0x04, 0x16, 0, PPC2_VSX)
7902 GEN_VSX_HELPER_2(xsnmsubmdp, 0x04, 0x17, 0, PPC2_VSX)
7903 GEN_VSX_HELPER_2(xscmpodp, 0x0C, 0x05, 0, PPC2_VSX)
7904 GEN_VSX_HELPER_2(xscmpudp, 0x0C, 0x04, 0, PPC2_VSX)
7905 GEN_VSX_HELPER_2(xsmaxdp, 0x00, 0x14, 0, PPC2_VSX)
7906 GEN_VSX_HELPER_2(xsmindp, 0x00, 0x15, 0, PPC2_VSX)
7907 GEN_VSX_HELPER_2(xscvdpsp, 0x12, 0x10, 0, PPC2_VSX)
7908 GEN_VSX_HELPER_XT_XB_ENV(xscvdpspn, 0x16, 0x10, 0, PPC2_VSX207)
7909 GEN_VSX_HELPER_2(xscvspdp, 0x12, 0x14, 0, PPC2_VSX)
7910 GEN_VSX_HELPER_XT_XB_ENV(xscvspdpn, 0x16, 0x14, 0, PPC2_VSX207)
7911 GEN_VSX_HELPER_2(xscvdpsxds, 0x10, 0x15, 0, PPC2_VSX)
7912 GEN_VSX_HELPER_2(xscvdpsxws, 0x10, 0x05, 0, PPC2_VSX)
7913 GEN_VSX_HELPER_2(xscvdpuxds, 0x10, 0x14, 0, PPC2_VSX)
7914 GEN_VSX_HELPER_2(xscvdpuxws, 0x10, 0x04, 0, PPC2_VSX)
7915 GEN_VSX_HELPER_2(xscvsxddp, 0x10, 0x17, 0, PPC2_VSX)
7916 GEN_VSX_HELPER_2(xscvuxddp, 0x10, 0x16, 0, PPC2_VSX)
7917 GEN_VSX_HELPER_2(xsrdpi, 0x12, 0x04, 0, PPC2_VSX)
7918 GEN_VSX_HELPER_2(xsrdpic, 0x16, 0x06, 0, PPC2_VSX)
7919 GEN_VSX_HELPER_2(xsrdpim, 0x12, 0x07, 0, PPC2_VSX)
7920 GEN_VSX_HELPER_2(xsrdpip, 0x12, 0x06, 0, PPC2_VSX)
7921 GEN_VSX_HELPER_2(xsrdpiz, 0x12, 0x05, 0, PPC2_VSX)
7922 GEN_VSX_HELPER_XT_XB_ENV(xsrsp, 0x12, 0x11, 0, PPC2_VSX207)
7924 GEN_VSX_HELPER_2(xsaddsp, 0x00, 0x00, 0, PPC2_VSX207)
7925 GEN_VSX_HELPER_2(xssubsp, 0x00, 0x01, 0, PPC2_VSX207)
7926 GEN_VSX_HELPER_2(xsmulsp, 0x00, 0x02, 0, PPC2_VSX207)
7927 GEN_VSX_HELPER_2(xsdivsp, 0x00, 0x03, 0, PPC2_VSX207)
7928 GEN_VSX_HELPER_2(xsresp, 0x14, 0x01, 0, PPC2_VSX207)
7929 GEN_VSX_HELPER_2(xssqrtsp, 0x16, 0x00, 0, PPC2_VSX207)
7930 GEN_VSX_HELPER_2(xsrsqrtesp, 0x14, 0x00, 0, PPC2_VSX207)
7931 GEN_VSX_HELPER_2(xsmaddasp, 0x04, 0x00, 0, PPC2_VSX207)
7932 GEN_VSX_HELPER_2(xsmaddmsp, 0x04, 0x01, 0, PPC2_VSX207)
7933 GEN_VSX_HELPER_2(xsmsubasp, 0x04, 0x02, 0, PPC2_VSX207)
7934 GEN_VSX_HELPER_2(xsmsubmsp, 0x04, 0x03, 0, PPC2_VSX207)
7935 GEN_VSX_HELPER_2(xsnmaddasp, 0x04, 0x10, 0, PPC2_VSX207)
7936 GEN_VSX_HELPER_2(xsnmaddmsp, 0x04, 0x11, 0, PPC2_VSX207)
7937 GEN_VSX_HELPER_2(xsnmsubasp, 0x04, 0x12, 0, PPC2_VSX207)
7938 GEN_VSX_HELPER_2(xsnmsubmsp, 0x04, 0x13, 0, PPC2_VSX207)
7939 GEN_VSX_HELPER_2(xscvsxdsp, 0x10, 0x13, 0, PPC2_VSX207)
7940 GEN_VSX_HELPER_2(xscvuxdsp, 0x10, 0x12, 0, PPC2_VSX207)
7942 GEN_VSX_HELPER_2(xvadddp, 0x00, 0x0C, 0, PPC2_VSX)
7943 GEN_VSX_HELPER_2(xvsubdp, 0x00, 0x0D, 0, PPC2_VSX)
7944 GEN_VSX_HELPER_2(xvmuldp, 0x00, 0x0E, 0, PPC2_VSX)
7945 GEN_VSX_HELPER_2(xvdivdp, 0x00, 0x0F, 0, PPC2_VSX)
7946 GEN_VSX_HELPER_2(xvredp, 0x14, 0x0D, 0, PPC2_VSX)
7947 GEN_VSX_HELPER_2(xvsqrtdp, 0x16, 0x0C, 0, PPC2_VSX)
7948 GEN_VSX_HELPER_2(xvrsqrtedp, 0x14, 0x0C, 0, PPC2_VSX)
7949 GEN_VSX_HELPER_2(xvtdivdp, 0x14, 0x0F, 0, PPC2_VSX)
7950 GEN_VSX_HELPER_2(xvtsqrtdp, 0x14, 0x0E, 0, PPC2_VSX)
7951 GEN_VSX_HELPER_2(xvmaddadp, 0x04, 0x0C, 0, PPC2_VSX)
7952 GEN_VSX_HELPER_2(xvmaddmdp, 0x04, 0x0D, 0, PPC2_VSX)
7953 GEN_VSX_HELPER_2(xvmsubadp, 0x04, 0x0E, 0, PPC2_VSX)
7954 GEN_VSX_HELPER_2(xvmsubmdp, 0x04, 0x0F, 0, PPC2_VSX)
7955 GEN_VSX_HELPER_2(xvnmaddadp, 0x04, 0x1C, 0, PPC2_VSX)
7956 GEN_VSX_HELPER_2(xvnmaddmdp, 0x04, 0x1D, 0, PPC2_VSX)
7957 GEN_VSX_HELPER_2(xvnmsubadp, 0x04, 0x1E, 0, PPC2_VSX)
7958 GEN_VSX_HELPER_2(xvnmsubmdp, 0x04, 0x1F, 0, PPC2_VSX)
7959 GEN_VSX_HELPER_2(xvmaxdp, 0x00, 0x1C, 0, PPC2_VSX)
7960 GEN_VSX_HELPER_2(xvmindp, 0x00, 0x1D, 0, PPC2_VSX)
7961 GEN_VSX_HELPER_2(xvcmpeqdp, 0x0C, 0x0C, 0, PPC2_VSX)
7962 GEN_VSX_HELPER_2(xvcmpgtdp, 0x0C, 0x0D, 0, PPC2_VSX)
7963 GEN_VSX_HELPER_2(xvcmpgedp, 0x0C, 0x0E, 0, PPC2_VSX)
7964 GEN_VSX_HELPER_2(xvcvdpsp, 0x12, 0x18, 0, PPC2_VSX)
7965 GEN_VSX_HELPER_2(xvcvdpsxds, 0x10, 0x1D, 0, PPC2_VSX)
7966 GEN_VSX_HELPER_2(xvcvdpsxws, 0x10, 0x0D, 0, PPC2_VSX)
7967 GEN_VSX_HELPER_2(xvcvdpuxds, 0x10, 0x1C, 0, PPC2_VSX)
7968 GEN_VSX_HELPER_2(xvcvdpuxws, 0x10, 0x0C, 0, PPC2_VSX)
7969 GEN_VSX_HELPER_2(xvcvsxddp, 0x10, 0x1F, 0, PPC2_VSX)
7970 GEN_VSX_HELPER_2(xvcvuxddp, 0x10, 0x1E, 0, PPC2_VSX)
7971 GEN_VSX_HELPER_2(xvcvsxwdp, 0x10, 0x0F, 0, PPC2_VSX)
7972 GEN_VSX_HELPER_2(xvcvuxwdp, 0x10, 0x0E, 0, PPC2_VSX)
7973 GEN_VSX_HELPER_2(xvrdpi, 0x12, 0x0C, 0, PPC2_VSX)
7974 GEN_VSX_HELPER_2(xvrdpic, 0x16, 0x0E, 0, PPC2_VSX)
7975 GEN_VSX_HELPER_2(xvrdpim, 0x12, 0x0F, 0, PPC2_VSX)
7976 GEN_VSX_HELPER_2(xvrdpip, 0x12, 0x0E, 0, PPC2_VSX)
7977 GEN_VSX_HELPER_2(xvrdpiz, 0x12, 0x0D, 0, PPC2_VSX)
7979 GEN_VSX_HELPER_2(xvaddsp, 0x00, 0x08, 0, PPC2_VSX)
7980 GEN_VSX_HELPER_2(xvsubsp, 0x00, 0x09, 0, PPC2_VSX)
7981 GEN_VSX_HELPER_2(xvmulsp, 0x00, 0x0A, 0, PPC2_VSX)
7982 GEN_VSX_HELPER_2(xvdivsp, 0x00, 0x0B, 0, PPC2_VSX)
7983 GEN_VSX_HELPER_2(xvresp, 0x14, 0x09, 0, PPC2_VSX)
7984 GEN_VSX_HELPER_2(xvsqrtsp, 0x16, 0x08, 0, PPC2_VSX)
7985 GEN_VSX_HELPER_2(xvrsqrtesp, 0x14, 0x08, 0, PPC2_VSX)
7986 GEN_VSX_HELPER_2(xvtdivsp, 0x14, 0x0B, 0, PPC2_VSX)
7987 GEN_VSX_HELPER_2(xvtsqrtsp, 0x14, 0x0A, 0, PPC2_VSX)
7988 GEN_VSX_HELPER_2(xvmaddasp, 0x04, 0x08, 0, PPC2_VSX)
7989 GEN_VSX_HELPER_2(xvmaddmsp, 0x04, 0x09, 0, PPC2_VSX)
7990 GEN_VSX_HELPER_2(xvmsubasp, 0x04, 0x0A, 0, PPC2_VSX)
7991 GEN_VSX_HELPER_2(xvmsubmsp, 0x04, 0x0B, 0, PPC2_VSX)
7992 GEN_VSX_HELPER_2(xvnmaddasp, 0x04, 0x18, 0, PPC2_VSX)
7993 GEN_VSX_HELPER_2(xvnmaddmsp, 0x04, 0x19, 0, PPC2_VSX)
7994 GEN_VSX_HELPER_2(xvnmsubasp, 0x04, 0x1A, 0, PPC2_VSX)
7995 GEN_VSX_HELPER_2(xvnmsubmsp, 0x04, 0x1B, 0, PPC2_VSX)
7996 GEN_VSX_HELPER_2(xvmaxsp, 0x00, 0x18, 0, PPC2_VSX)
7997 GEN_VSX_HELPER_2(xvminsp, 0x00, 0x19, 0, PPC2_VSX)
7998 GEN_VSX_HELPER_2(xvcmpeqsp, 0x0C, 0x08, 0, PPC2_VSX)
7999 GEN_VSX_HELPER_2(xvcmpgtsp, 0x0C, 0x09, 0, PPC2_VSX)
8000 GEN_VSX_HELPER_2(xvcmpgesp, 0x0C, 0x0A, 0, PPC2_VSX)
8001 GEN_VSX_HELPER_2(xvcvspdp, 0x12, 0x1C, 0, PPC2_VSX)
8002 GEN_VSX_HELPER_2(xvcvspsxds, 0x10, 0x19, 0, PPC2_VSX)
8003 GEN_VSX_HELPER_2(xvcvspsxws, 0x10, 0x09, 0, PPC2_VSX)
8004 GEN_VSX_HELPER_2(xvcvspuxds, 0x10, 0x18, 0, PPC2_VSX)
8005 GEN_VSX_HELPER_2(xvcvspuxws, 0x10, 0x08, 0, PPC2_VSX)
8006 GEN_VSX_HELPER_2(xvcvsxdsp, 0x10, 0x1B, 0, PPC2_VSX)
8007 GEN_VSX_HELPER_2(xvcvuxdsp, 0x10, 0x1A, 0, PPC2_VSX)
8008 GEN_VSX_HELPER_2(xvcvsxwsp, 0x10, 0x0B, 0, PPC2_VSX)
8009 GEN_VSX_HELPER_2(xvcvuxwsp, 0x10, 0x0A, 0, PPC2_VSX)
8010 GEN_VSX_HELPER_2(xvrspi, 0x12, 0x08, 0, PPC2_VSX)
8011 GEN_VSX_HELPER_2(xvrspic, 0x16, 0x0A, 0, PPC2_VSX)
8012 GEN_VSX_HELPER_2(xvrspim, 0x12, 0x0B, 0, PPC2_VSX)
8013 GEN_VSX_HELPER_2(xvrspip, 0x12, 0x0A, 0, PPC2_VSX)
8014 GEN_VSX_HELPER_2(xvrspiz, 0x12, 0x09, 0, PPC2_VSX)
8016 #define VSX_LOGICAL(name, tcg_op) \
8017 static void glue(gen_, name)(DisasContext * ctx) \
8019 if (unlikely(!ctx->vsx_enabled)) { \
8020 gen_exception(ctx, POWERPC_EXCP_VSXU); \
8023 tcg_op(cpu_vsrh(xT(ctx->opcode)), cpu_vsrh(xA(ctx->opcode)), \
8024 cpu_vsrh(xB(ctx->opcode))); \
8025 tcg_op(cpu_vsrl(xT(ctx->opcode)), cpu_vsrl(xA(ctx->opcode)), \
8026 cpu_vsrl(xB(ctx->opcode))); \
8029 VSX_LOGICAL(xxland, tcg_gen_and_i64)
8030 VSX_LOGICAL(xxlandc, tcg_gen_andc_i64)
8031 VSX_LOGICAL(xxlor, tcg_gen_or_i64)
8032 VSX_LOGICAL(xxlxor, tcg_gen_xor_i64)
8033 VSX_LOGICAL(xxlnor, tcg_gen_nor_i64)
8034 VSX_LOGICAL(xxleqv, tcg_gen_eqv_i64)
8035 VSX_LOGICAL(xxlnand, tcg_gen_nand_i64)
8036 VSX_LOGICAL(xxlorc, tcg_gen_orc_i64)
8038 #define VSX_XXMRG(name, high) \
8039 static void glue(gen_, name)(DisasContext * ctx) \
8041 TCGv_i64 a0, a1, b0, b1; \
8042 if (unlikely(!ctx->vsx_enabled)) { \
8043 gen_exception(ctx, POWERPC_EXCP_VSXU); \
8046 a0 = tcg_temp_new_i64(); \
8047 a1 = tcg_temp_new_i64(); \
8048 b0 = tcg_temp_new_i64(); \
8049 b1 = tcg_temp_new_i64(); \
8051 tcg_gen_mov_i64(a0, cpu_vsrh(xA(ctx->opcode))); \
8052 tcg_gen_mov_i64(a1, cpu_vsrh(xA(ctx->opcode))); \
8053 tcg_gen_mov_i64(b0, cpu_vsrh(xB(ctx->opcode))); \
8054 tcg_gen_mov_i64(b1, cpu_vsrh(xB(ctx->opcode))); \
8056 tcg_gen_mov_i64(a0, cpu_vsrl(xA(ctx->opcode))); \
8057 tcg_gen_mov_i64(a1, cpu_vsrl(xA(ctx->opcode))); \
8058 tcg_gen_mov_i64(b0, cpu_vsrl(xB(ctx->opcode))); \
8059 tcg_gen_mov_i64(b1, cpu_vsrl(xB(ctx->opcode))); \
8061 tcg_gen_shri_i64(a0, a0, 32); \
8062 tcg_gen_shri_i64(b0, b0, 32); \
8063 tcg_gen_deposit_i64(cpu_vsrh(xT(ctx->opcode)), \
8065 tcg_gen_deposit_i64(cpu_vsrl(xT(ctx->opcode)), \
8067 tcg_temp_free_i64(a0); \
8068 tcg_temp_free_i64(a1); \
8069 tcg_temp_free_i64(b0); \
8070 tcg_temp_free_i64(b1); \
8073 VSX_XXMRG(xxmrghw, 1)
8074 VSX_XXMRG(xxmrglw, 0)
8076 static void gen_xxsel(DisasContext * ctx)
8079 if (unlikely(!ctx->vsx_enabled)) {
8080 gen_exception(ctx, POWERPC_EXCP_VSXU);
8083 a = tcg_temp_new_i64();
8084 b = tcg_temp_new_i64();
8085 c = tcg_temp_new_i64();
8087 tcg_gen_mov_i64(a, cpu_vsrh(xA(ctx->opcode)));
8088 tcg_gen_mov_i64(b, cpu_vsrh(xB(ctx->opcode)));
8089 tcg_gen_mov_i64(c, cpu_vsrh(xC(ctx->opcode)));
8091 tcg_gen_and_i64(b, b, c);
8092 tcg_gen_andc_i64(a, a, c);
8093 tcg_gen_or_i64(cpu_vsrh(xT(ctx->opcode)), a, b);
8095 tcg_gen_mov_i64(a, cpu_vsrl(xA(ctx->opcode)));
8096 tcg_gen_mov_i64(b, cpu_vsrl(xB(ctx->opcode)));
8097 tcg_gen_mov_i64(c, cpu_vsrl(xC(ctx->opcode)));
8099 tcg_gen_and_i64(b, b, c);
8100 tcg_gen_andc_i64(a, a, c);
8101 tcg_gen_or_i64(cpu_vsrl(xT(ctx->opcode)), a, b);
8103 tcg_temp_free_i64(a);
8104 tcg_temp_free_i64(b);
8105 tcg_temp_free_i64(c);
8108 static void gen_xxspltw(DisasContext *ctx)
8111 TCGv_i64 vsr = (UIM(ctx->opcode) & 2) ?
8112 cpu_vsrl(xB(ctx->opcode)) :
8113 cpu_vsrh(xB(ctx->opcode));
8115 if (unlikely(!ctx->vsx_enabled)) {
8116 gen_exception(ctx, POWERPC_EXCP_VSXU);
8120 b = tcg_temp_new_i64();
8121 b2 = tcg_temp_new_i64();
8123 if (UIM(ctx->opcode) & 1) {
8124 tcg_gen_ext32u_i64(b, vsr);
8126 tcg_gen_shri_i64(b, vsr, 32);
8129 tcg_gen_shli_i64(b2, b, 32);
8130 tcg_gen_or_i64(cpu_vsrh(xT(ctx->opcode)), b, b2);
8131 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), cpu_vsrh(xT(ctx->opcode)));
8133 tcg_temp_free_i64(b);
8134 tcg_temp_free_i64(b2);
8137 static void gen_xxsldwi(DisasContext *ctx)
8140 if (unlikely(!ctx->vsx_enabled)) {
8141 gen_exception(ctx, POWERPC_EXCP_VSXU);
8144 xth = tcg_temp_new_i64();
8145 xtl = tcg_temp_new_i64();
8147 switch (SHW(ctx->opcode)) {
8149 tcg_gen_mov_i64(xth, cpu_vsrh(xA(ctx->opcode)));
8150 tcg_gen_mov_i64(xtl, cpu_vsrl(xA(ctx->opcode)));
8154 TCGv_i64 t0 = tcg_temp_new_i64();
8155 tcg_gen_mov_i64(xth, cpu_vsrh(xA(ctx->opcode)));
8156 tcg_gen_shli_i64(xth, xth, 32);
8157 tcg_gen_mov_i64(t0, cpu_vsrl(xA(ctx->opcode)));
8158 tcg_gen_shri_i64(t0, t0, 32);
8159 tcg_gen_or_i64(xth, xth, t0);
8160 tcg_gen_mov_i64(xtl, cpu_vsrl(xA(ctx->opcode)));
8161 tcg_gen_shli_i64(xtl, xtl, 32);
8162 tcg_gen_mov_i64(t0, cpu_vsrh(xB(ctx->opcode)));
8163 tcg_gen_shri_i64(t0, t0, 32);
8164 tcg_gen_or_i64(xtl, xtl, t0);
8165 tcg_temp_free_i64(t0);
8169 tcg_gen_mov_i64(xth, cpu_vsrl(xA(ctx->opcode)));
8170 tcg_gen_mov_i64(xtl, cpu_vsrh(xB(ctx->opcode)));
8174 TCGv_i64 t0 = tcg_temp_new_i64();
8175 tcg_gen_mov_i64(xth, cpu_vsrl(xA(ctx->opcode)));
8176 tcg_gen_shli_i64(xth, xth, 32);
8177 tcg_gen_mov_i64(t0, cpu_vsrh(xB(ctx->opcode)));
8178 tcg_gen_shri_i64(t0, t0, 32);
8179 tcg_gen_or_i64(xth, xth, t0);
8180 tcg_gen_mov_i64(xtl, cpu_vsrh(xB(ctx->opcode)));
8181 tcg_gen_shli_i64(xtl, xtl, 32);
8182 tcg_gen_mov_i64(t0, cpu_vsrl(xB(ctx->opcode)));
8183 tcg_gen_shri_i64(t0, t0, 32);
8184 tcg_gen_or_i64(xtl, xtl, t0);
8185 tcg_temp_free_i64(t0);
8190 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xth);
8191 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), xtl);
8193 tcg_temp_free_i64(xth);
8194 tcg_temp_free_i64(xtl);
8197 /*** Decimal Floating Point ***/
8199 static inline TCGv_ptr gen_fprp_ptr(int reg)
8201 TCGv_ptr r = tcg_temp_new_ptr();
8202 tcg_gen_addi_ptr(r, cpu_env, offsetof(CPUPPCState, fpr[reg]));
8206 #if defined(TARGET_PPC64)
8207 static void gen_set_cr6_from_fpscr(DisasContext *ctx)
8209 TCGv_i32 tmp = tcg_temp_new_i32();
8210 tcg_gen_trunc_tl_i32(tmp, cpu_fpscr);
8211 tcg_gen_shri_i32(cpu_crf[1], tmp, 28);
8212 tcg_temp_free_i32(tmp);
8215 static void gen_set_cr6_from_fpscr(DisasContext *ctx)
8217 tcg_gen_shri_tl(cpu_crf[1], cpu_fpscr, 28);
8221 #define GEN_DFP_T_A_B_Rc(name) \
8222 static void gen_##name(DisasContext *ctx) \
8224 TCGv_ptr rd, ra, rb; \
8225 if (unlikely(!ctx->fpu_enabled)) { \
8226 gen_exception(ctx, POWERPC_EXCP_FPU); \
8229 gen_update_nip(ctx, ctx->nip - 4); \
8230 rd = gen_fprp_ptr(rD(ctx->opcode)); \
8231 ra = gen_fprp_ptr(rA(ctx->opcode)); \
8232 rb = gen_fprp_ptr(rB(ctx->opcode)); \
8233 gen_helper_##name(cpu_env, rd, ra, rb); \
8234 if (unlikely(Rc(ctx->opcode) != 0)) { \
8235 gen_set_cr6_from_fpscr(ctx); \
8237 tcg_temp_free_ptr(rd); \
8238 tcg_temp_free_ptr(ra); \
8239 tcg_temp_free_ptr(rb); \
8242 #define GEN_DFP_BF_A_B(name) \
8243 static void gen_##name(DisasContext *ctx) \
8246 if (unlikely(!ctx->fpu_enabled)) { \
8247 gen_exception(ctx, POWERPC_EXCP_FPU); \
8250 gen_update_nip(ctx, ctx->nip - 4); \
8251 ra = gen_fprp_ptr(rA(ctx->opcode)); \
8252 rb = gen_fprp_ptr(rB(ctx->opcode)); \
8253 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], \
8255 tcg_temp_free_ptr(ra); \
8256 tcg_temp_free_ptr(rb); \
8259 #define GEN_DFP_BF_A_DCM(name) \
8260 static void gen_##name(DisasContext *ctx) \
8264 if (unlikely(!ctx->fpu_enabled)) { \
8265 gen_exception(ctx, POWERPC_EXCP_FPU); \
8268 gen_update_nip(ctx, ctx->nip - 4); \
8269 ra = gen_fprp_ptr(rA(ctx->opcode)); \
8270 dcm = tcg_const_i32(DCM(ctx->opcode)); \
8271 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], \
8272 cpu_env, ra, dcm); \
8273 tcg_temp_free_ptr(ra); \
8274 tcg_temp_free_i32(dcm); \
8277 #define GEN_DFP_T_B_U32_U32_Rc(name, u32f1, u32f2) \
8278 static void gen_##name(DisasContext *ctx) \
8281 TCGv_i32 u32_1, u32_2; \
8282 if (unlikely(!ctx->fpu_enabled)) { \
8283 gen_exception(ctx, POWERPC_EXCP_FPU); \
8286 gen_update_nip(ctx, ctx->nip - 4); \
8287 rt = gen_fprp_ptr(rD(ctx->opcode)); \
8288 rb = gen_fprp_ptr(rB(ctx->opcode)); \
8289 u32_1 = tcg_const_i32(u32f1(ctx->opcode)); \
8290 u32_2 = tcg_const_i32(u32f2(ctx->opcode)); \
8291 gen_helper_##name(cpu_env, rt, rb, u32_1, u32_2); \
8292 if (unlikely(Rc(ctx->opcode) != 0)) { \
8293 gen_set_cr6_from_fpscr(ctx); \
8295 tcg_temp_free_ptr(rt); \
8296 tcg_temp_free_ptr(rb); \
8297 tcg_temp_free_i32(u32_1); \
8298 tcg_temp_free_i32(u32_2); \
8301 #define GEN_DFP_T_A_B_I32_Rc(name, i32fld) \
8302 static void gen_##name(DisasContext *ctx) \
8304 TCGv_ptr rt, ra, rb; \
8306 if (unlikely(!ctx->fpu_enabled)) { \
8307 gen_exception(ctx, POWERPC_EXCP_FPU); \
8310 gen_update_nip(ctx, ctx->nip - 4); \
8311 rt = gen_fprp_ptr(rD(ctx->opcode)); \
8312 ra = gen_fprp_ptr(rA(ctx->opcode)); \
8313 rb = gen_fprp_ptr(rB(ctx->opcode)); \
8314 i32 = tcg_const_i32(i32fld(ctx->opcode)); \
8315 gen_helper_##name(cpu_env, rt, ra, rb, i32); \
8316 if (unlikely(Rc(ctx->opcode) != 0)) { \
8317 gen_set_cr6_from_fpscr(ctx); \
8319 tcg_temp_free_ptr(rt); \
8320 tcg_temp_free_ptr(rb); \
8321 tcg_temp_free_ptr(ra); \
8322 tcg_temp_free_i32(i32); \
8325 #define GEN_DFP_T_B_Rc(name) \
8326 static void gen_##name(DisasContext *ctx) \
8329 if (unlikely(!ctx->fpu_enabled)) { \
8330 gen_exception(ctx, POWERPC_EXCP_FPU); \
8333 gen_update_nip(ctx, ctx->nip - 4); \
8334 rt = gen_fprp_ptr(rD(ctx->opcode)); \
8335 rb = gen_fprp_ptr(rB(ctx->opcode)); \
8336 gen_helper_##name(cpu_env, rt, rb); \
8337 if (unlikely(Rc(ctx->opcode) != 0)) { \
8338 gen_set_cr6_from_fpscr(ctx); \
8340 tcg_temp_free_ptr(rt); \
8341 tcg_temp_free_ptr(rb); \
8344 #define GEN_DFP_T_FPR_I32_Rc(name, fprfld, i32fld) \
8345 static void gen_##name(DisasContext *ctx) \
8349 if (unlikely(!ctx->fpu_enabled)) { \
8350 gen_exception(ctx, POWERPC_EXCP_FPU); \
8353 gen_update_nip(ctx, ctx->nip - 4); \
8354 rt = gen_fprp_ptr(rD(ctx->opcode)); \
8355 rs = gen_fprp_ptr(fprfld(ctx->opcode)); \
8356 i32 = tcg_const_i32(i32fld(ctx->opcode)); \
8357 gen_helper_##name(cpu_env, rt, rs, i32); \
8358 if (unlikely(Rc(ctx->opcode) != 0)) { \
8359 gen_set_cr6_from_fpscr(ctx); \
8361 tcg_temp_free_ptr(rt); \
8362 tcg_temp_free_ptr(rs); \
8363 tcg_temp_free_i32(i32); \
8366 GEN_DFP_T_A_B_Rc(dadd)
8367 GEN_DFP_T_A_B_Rc(daddq)
8368 GEN_DFP_T_A_B_Rc(dsub)
8369 GEN_DFP_T_A_B_Rc(dsubq)
8370 GEN_DFP_T_A_B_Rc(dmul)
8371 GEN_DFP_T_A_B_Rc(dmulq)
8372 GEN_DFP_T_A_B_Rc(ddiv)
8373 GEN_DFP_T_A_B_Rc(ddivq)
8374 GEN_DFP_BF_A_B(dcmpu)
8375 GEN_DFP_BF_A_B(dcmpuq)
8376 GEN_DFP_BF_A_B(dcmpo)
8377 GEN_DFP_BF_A_B(dcmpoq)
8378 GEN_DFP_BF_A_DCM(dtstdc)
8379 GEN_DFP_BF_A_DCM(dtstdcq)
8380 GEN_DFP_BF_A_DCM(dtstdg)
8381 GEN_DFP_BF_A_DCM(dtstdgq)
8382 GEN_DFP_BF_A_B(dtstex)
8383 GEN_DFP_BF_A_B(dtstexq)
8384 GEN_DFP_BF_A_B(dtstsf)
8385 GEN_DFP_BF_A_B(dtstsfq)
8386 GEN_DFP_T_B_U32_U32_Rc(dquai, SIMM5, RMC)
8387 GEN_DFP_T_B_U32_U32_Rc(dquaiq, SIMM5, RMC)
8388 GEN_DFP_T_A_B_I32_Rc(dqua, RMC)
8389 GEN_DFP_T_A_B_I32_Rc(dquaq, RMC)
8390 GEN_DFP_T_A_B_I32_Rc(drrnd, RMC)
8391 GEN_DFP_T_A_B_I32_Rc(drrndq, RMC)
8392 GEN_DFP_T_B_U32_U32_Rc(drintx, FPW, RMC)
8393 GEN_DFP_T_B_U32_U32_Rc(drintxq, FPW, RMC)
8394 GEN_DFP_T_B_U32_U32_Rc(drintn, FPW, RMC)
8395 GEN_DFP_T_B_U32_U32_Rc(drintnq, FPW, RMC)
8396 GEN_DFP_T_B_Rc(dctdp)
8397 GEN_DFP_T_B_Rc(dctqpq)
8398 GEN_DFP_T_B_Rc(drsp)
8399 GEN_DFP_T_B_Rc(drdpq)
8400 GEN_DFP_T_B_Rc(dcffix)
8401 GEN_DFP_T_B_Rc(dcffixq)
8402 GEN_DFP_T_B_Rc(dctfix)
8403 GEN_DFP_T_B_Rc(dctfixq)
8404 GEN_DFP_T_FPR_I32_Rc(ddedpd, rB, SP)
8405 GEN_DFP_T_FPR_I32_Rc(ddedpdq, rB, SP)
8406 GEN_DFP_T_FPR_I32_Rc(denbcd, rB, SP)
8407 GEN_DFP_T_FPR_I32_Rc(denbcdq, rB, SP)
8408 GEN_DFP_T_B_Rc(dxex)
8409 GEN_DFP_T_B_Rc(dxexq)
8410 GEN_DFP_T_A_B_Rc(diex)
8411 GEN_DFP_T_A_B_Rc(diexq)
8412 GEN_DFP_T_FPR_I32_Rc(dscli, rA, DCM)
8413 GEN_DFP_T_FPR_I32_Rc(dscliq, rA, DCM)
8414 GEN_DFP_T_FPR_I32_Rc(dscri, rA, DCM)
8415 GEN_DFP_T_FPR_I32_Rc(dscriq, rA, DCM)
8417 /*** SPE extension ***/
8418 /* Register moves */
8420 static inline void gen_evmra(DisasContext *ctx)
8423 if (unlikely(!ctx->spe_enabled)) {
8424 gen_exception(ctx, POWERPC_EXCP_SPEU);
8428 #if defined(TARGET_PPC64)
8430 tcg_gen_mov_i64(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
8433 tcg_gen_st_i64(cpu_gpr[rA(ctx->opcode)],
8435 offsetof(CPUPPCState, spe_acc));
8437 TCGv_i64 tmp = tcg_temp_new_i64();
8439 /* tmp := rA_lo + rA_hi << 32 */
8440 tcg_gen_concat_i32_i64(tmp, cpu_gpr[rA(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
8442 /* spe_acc := tmp */
8443 tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUPPCState, spe_acc));
8444 tcg_temp_free_i64(tmp);
8447 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
8448 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
8452 static inline void gen_load_gpr64(TCGv_i64 t, int reg)
8454 #if defined(TARGET_PPC64)
8455 tcg_gen_mov_i64(t, cpu_gpr[reg]);
8457 tcg_gen_concat_i32_i64(t, cpu_gpr[reg], cpu_gprh[reg]);
8461 static inline void gen_store_gpr64(int reg, TCGv_i64 t)
8463 #if defined(TARGET_PPC64)
8464 tcg_gen_mov_i64(cpu_gpr[reg], t);
8466 TCGv_i64 tmp = tcg_temp_new_i64();
8467 tcg_gen_trunc_i64_i32(cpu_gpr[reg], t);
8468 tcg_gen_shri_i64(tmp, t, 32);
8469 tcg_gen_trunc_i64_i32(cpu_gprh[reg], tmp);
8470 tcg_temp_free_i64(tmp);
8474 #define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \
8475 static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
8477 if (Rc(ctx->opcode)) \
8483 /* Handler for undefined SPE opcodes */
8484 static inline void gen_speundef(DisasContext *ctx)
8486 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
8490 #if defined(TARGET_PPC64)
8491 #define GEN_SPEOP_LOGIC2(name, tcg_op) \
8492 static inline void gen_##name(DisasContext *ctx) \
8494 if (unlikely(!ctx->spe_enabled)) { \
8495 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8498 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
8499 cpu_gpr[rB(ctx->opcode)]); \
8502 #define GEN_SPEOP_LOGIC2(name, tcg_op) \
8503 static inline void gen_##name(DisasContext *ctx) \
8505 if (unlikely(!ctx->spe_enabled)) { \
8506 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8509 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
8510 cpu_gpr[rB(ctx->opcode)]); \
8511 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
8512 cpu_gprh[rB(ctx->opcode)]); \
8516 GEN_SPEOP_LOGIC2(evand, tcg_gen_and_tl);
8517 GEN_SPEOP_LOGIC2(evandc, tcg_gen_andc_tl);
8518 GEN_SPEOP_LOGIC2(evxor, tcg_gen_xor_tl);
8519 GEN_SPEOP_LOGIC2(evor, tcg_gen_or_tl);
8520 GEN_SPEOP_LOGIC2(evnor, tcg_gen_nor_tl);
8521 GEN_SPEOP_LOGIC2(eveqv, tcg_gen_eqv_tl);
8522 GEN_SPEOP_LOGIC2(evorc, tcg_gen_orc_tl);
8523 GEN_SPEOP_LOGIC2(evnand, tcg_gen_nand_tl);
8525 /* SPE logic immediate */
8526 #if defined(TARGET_PPC64)
8527 #define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \
8528 static inline void gen_##name(DisasContext *ctx) \
8530 if (unlikely(!ctx->spe_enabled)) { \
8531 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8534 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
8535 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
8536 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
8537 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8538 tcg_opi(t0, t0, rB(ctx->opcode)); \
8539 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
8540 tcg_gen_trunc_i64_i32(t1, t2); \
8541 tcg_temp_free_i64(t2); \
8542 tcg_opi(t1, t1, rB(ctx->opcode)); \
8543 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
8544 tcg_temp_free_i32(t0); \
8545 tcg_temp_free_i32(t1); \
8548 #define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \
8549 static inline void gen_##name(DisasContext *ctx) \
8551 if (unlikely(!ctx->spe_enabled)) { \
8552 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8555 tcg_opi(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
8557 tcg_opi(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
8561 GEN_SPEOP_TCG_LOGIC_IMM2(evslwi, tcg_gen_shli_i32);
8562 GEN_SPEOP_TCG_LOGIC_IMM2(evsrwiu, tcg_gen_shri_i32);
8563 GEN_SPEOP_TCG_LOGIC_IMM2(evsrwis, tcg_gen_sari_i32);
8564 GEN_SPEOP_TCG_LOGIC_IMM2(evrlwi, tcg_gen_rotli_i32);
8566 /* SPE arithmetic */
8567 #if defined(TARGET_PPC64)
8568 #define GEN_SPEOP_ARITH1(name, tcg_op) \
8569 static inline void gen_##name(DisasContext *ctx) \
8571 if (unlikely(!ctx->spe_enabled)) { \
8572 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8575 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
8576 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
8577 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
8578 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8580 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
8581 tcg_gen_trunc_i64_i32(t1, t2); \
8582 tcg_temp_free_i64(t2); \
8584 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
8585 tcg_temp_free_i32(t0); \
8586 tcg_temp_free_i32(t1); \
8589 #define GEN_SPEOP_ARITH1(name, tcg_op) \
8590 static inline void gen_##name(DisasContext *ctx) \
8592 if (unlikely(!ctx->spe_enabled)) { \
8593 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8596 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); \
8597 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); \
8601 static inline void gen_op_evabs(TCGv_i32 ret, TCGv_i32 arg1)
8603 int l1 = gen_new_label();
8604 int l2 = gen_new_label();
8606 tcg_gen_brcondi_i32(TCG_COND_GE, arg1, 0, l1);
8607 tcg_gen_neg_i32(ret, arg1);
8610 tcg_gen_mov_i32(ret, arg1);
8613 GEN_SPEOP_ARITH1(evabs, gen_op_evabs);
8614 GEN_SPEOP_ARITH1(evneg, tcg_gen_neg_i32);
8615 GEN_SPEOP_ARITH1(evextsb, tcg_gen_ext8s_i32);
8616 GEN_SPEOP_ARITH1(evextsh, tcg_gen_ext16s_i32);
8617 static inline void gen_op_evrndw(TCGv_i32 ret, TCGv_i32 arg1)
8619 tcg_gen_addi_i32(ret, arg1, 0x8000);
8620 tcg_gen_ext16u_i32(ret, ret);
8622 GEN_SPEOP_ARITH1(evrndw, gen_op_evrndw);
8623 GEN_SPEOP_ARITH1(evcntlsw, gen_helper_cntlsw32);
8624 GEN_SPEOP_ARITH1(evcntlzw, gen_helper_cntlzw32);
8626 #if defined(TARGET_PPC64)
8627 #define GEN_SPEOP_ARITH2(name, tcg_op) \
8628 static inline void gen_##name(DisasContext *ctx) \
8630 if (unlikely(!ctx->spe_enabled)) { \
8631 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8634 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
8635 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
8636 TCGv_i32 t2 = tcg_temp_local_new_i32(); \
8637 TCGv_i64 t3 = tcg_temp_local_new_i64(); \
8638 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8639 tcg_gen_trunc_i64_i32(t2, cpu_gpr[rB(ctx->opcode)]); \
8640 tcg_op(t0, t0, t2); \
8641 tcg_gen_shri_i64(t3, cpu_gpr[rA(ctx->opcode)], 32); \
8642 tcg_gen_trunc_i64_i32(t1, t3); \
8643 tcg_gen_shri_i64(t3, cpu_gpr[rB(ctx->opcode)], 32); \
8644 tcg_gen_trunc_i64_i32(t2, t3); \
8645 tcg_temp_free_i64(t3); \
8646 tcg_op(t1, t1, t2); \
8647 tcg_temp_free_i32(t2); \
8648 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
8649 tcg_temp_free_i32(t0); \
8650 tcg_temp_free_i32(t1); \
8653 #define GEN_SPEOP_ARITH2(name, tcg_op) \
8654 static inline void gen_##name(DisasContext *ctx) \
8656 if (unlikely(!ctx->spe_enabled)) { \
8657 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8660 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
8661 cpu_gpr[rB(ctx->opcode)]); \
8662 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
8663 cpu_gprh[rB(ctx->opcode)]); \
8667 static inline void gen_op_evsrwu(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
8672 l1 = gen_new_label();
8673 l2 = gen_new_label();
8674 t0 = tcg_temp_local_new_i32();
8675 /* No error here: 6 bits are used */
8676 tcg_gen_andi_i32(t0, arg2, 0x3F);
8677 tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1);
8678 tcg_gen_shr_i32(ret, arg1, t0);
8681 tcg_gen_movi_i32(ret, 0);
8683 tcg_temp_free_i32(t0);
8685 GEN_SPEOP_ARITH2(evsrwu, gen_op_evsrwu);
8686 static inline void gen_op_evsrws(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
8691 l1 = gen_new_label();
8692 l2 = gen_new_label();
8693 t0 = tcg_temp_local_new_i32();
8694 /* No error here: 6 bits are used */
8695 tcg_gen_andi_i32(t0, arg2, 0x3F);
8696 tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1);
8697 tcg_gen_sar_i32(ret, arg1, t0);
8700 tcg_gen_movi_i32(ret, 0);
8702 tcg_temp_free_i32(t0);
8704 GEN_SPEOP_ARITH2(evsrws, gen_op_evsrws);
8705 static inline void gen_op_evslw(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
8710 l1 = gen_new_label();
8711 l2 = gen_new_label();
8712 t0 = tcg_temp_local_new_i32();
8713 /* No error here: 6 bits are used */
8714 tcg_gen_andi_i32(t0, arg2, 0x3F);
8715 tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1);
8716 tcg_gen_shl_i32(ret, arg1, t0);
8719 tcg_gen_movi_i32(ret, 0);
8721 tcg_temp_free_i32(t0);
8723 GEN_SPEOP_ARITH2(evslw, gen_op_evslw);
8724 static inline void gen_op_evrlw(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
8726 TCGv_i32 t0 = tcg_temp_new_i32();
8727 tcg_gen_andi_i32(t0, arg2, 0x1F);
8728 tcg_gen_rotl_i32(ret, arg1, t0);
8729 tcg_temp_free_i32(t0);
8731 GEN_SPEOP_ARITH2(evrlw, gen_op_evrlw);
8732 static inline void gen_evmergehi(DisasContext *ctx)
8734 if (unlikely(!ctx->spe_enabled)) {
8735 gen_exception(ctx, POWERPC_EXCP_SPEU);
8738 #if defined(TARGET_PPC64)
8739 TCGv t0 = tcg_temp_new();
8740 TCGv t1 = tcg_temp_new();
8741 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 32);
8742 tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], 0xFFFFFFFF0000000ULL);
8743 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1);
8747 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
8748 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
8751 GEN_SPEOP_ARITH2(evaddw, tcg_gen_add_i32);
8752 static inline void gen_op_evsubf(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
8754 tcg_gen_sub_i32(ret, arg2, arg1);
8756 GEN_SPEOP_ARITH2(evsubfw, gen_op_evsubf);
8758 /* SPE arithmetic immediate */
8759 #if defined(TARGET_PPC64)
8760 #define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \
8761 static inline void gen_##name(DisasContext *ctx) \
8763 if (unlikely(!ctx->spe_enabled)) { \
8764 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8767 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
8768 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
8769 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
8770 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
8771 tcg_op(t0, t0, rA(ctx->opcode)); \
8772 tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32); \
8773 tcg_gen_trunc_i64_i32(t1, t2); \
8774 tcg_temp_free_i64(t2); \
8775 tcg_op(t1, t1, rA(ctx->opcode)); \
8776 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
8777 tcg_temp_free_i32(t0); \
8778 tcg_temp_free_i32(t1); \
8781 #define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \
8782 static inline void gen_##name(DisasContext *ctx) \
8784 if (unlikely(!ctx->spe_enabled)) { \
8785 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8788 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
8790 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)], \
8794 GEN_SPEOP_ARITH_IMM2(evaddiw, tcg_gen_addi_i32);
8795 GEN_SPEOP_ARITH_IMM2(evsubifw, tcg_gen_subi_i32);
8797 /* SPE comparison */
8798 #if defined(TARGET_PPC64)
8799 #define GEN_SPEOP_COMP(name, tcg_cond) \
8800 static inline void gen_##name(DisasContext *ctx) \
8802 if (unlikely(!ctx->spe_enabled)) { \
8803 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8806 int l1 = gen_new_label(); \
8807 int l2 = gen_new_label(); \
8808 int l3 = gen_new_label(); \
8809 int l4 = gen_new_label(); \
8810 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
8811 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
8812 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
8813 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8814 tcg_gen_trunc_i64_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
8815 tcg_gen_brcond_i32(tcg_cond, t0, t1, l1); \
8816 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], 0); \
8818 gen_set_label(l1); \
8819 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \
8820 CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \
8821 gen_set_label(l2); \
8822 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
8823 tcg_gen_trunc_i64_i32(t0, t2); \
8824 tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32); \
8825 tcg_gen_trunc_i64_i32(t1, t2); \
8826 tcg_temp_free_i64(t2); \
8827 tcg_gen_brcond_i32(tcg_cond, t0, t1, l3); \
8828 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
8829 ~(CRF_CH | CRF_CH_AND_CL)); \
8831 gen_set_label(l3); \
8832 tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
8833 CRF_CH | CRF_CH_OR_CL); \
8834 gen_set_label(l4); \
8835 tcg_temp_free_i32(t0); \
8836 tcg_temp_free_i32(t1); \
8839 #define GEN_SPEOP_COMP(name, tcg_cond) \
8840 static inline void gen_##name(DisasContext *ctx) \
8842 if (unlikely(!ctx->spe_enabled)) { \
8843 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8846 int l1 = gen_new_label(); \
8847 int l2 = gen_new_label(); \
8848 int l3 = gen_new_label(); \
8849 int l4 = gen_new_label(); \
8851 tcg_gen_brcond_i32(tcg_cond, cpu_gpr[rA(ctx->opcode)], \
8852 cpu_gpr[rB(ctx->opcode)], l1); \
8853 tcg_gen_movi_tl(cpu_crf[crfD(ctx->opcode)], 0); \
8855 gen_set_label(l1); \
8856 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \
8857 CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \
8858 gen_set_label(l2); \
8859 tcg_gen_brcond_i32(tcg_cond, cpu_gprh[rA(ctx->opcode)], \
8860 cpu_gprh[rB(ctx->opcode)], l3); \
8861 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
8862 ~(CRF_CH | CRF_CH_AND_CL)); \
8864 gen_set_label(l3); \
8865 tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
8866 CRF_CH | CRF_CH_OR_CL); \
8867 gen_set_label(l4); \
8870 GEN_SPEOP_COMP(evcmpgtu, TCG_COND_GTU);
8871 GEN_SPEOP_COMP(evcmpgts, TCG_COND_GT);
8872 GEN_SPEOP_COMP(evcmpltu, TCG_COND_LTU);
8873 GEN_SPEOP_COMP(evcmplts, TCG_COND_LT);
8874 GEN_SPEOP_COMP(evcmpeq, TCG_COND_EQ);
8877 static inline void gen_brinc(DisasContext *ctx)
8879 /* Note: brinc is usable even if SPE is disabled */
8880 gen_helper_brinc(cpu_gpr[rD(ctx->opcode)],
8881 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
8883 static inline void gen_evmergelo(DisasContext *ctx)
8885 if (unlikely(!ctx->spe_enabled)) {
8886 gen_exception(ctx, POWERPC_EXCP_SPEU);
8889 #if defined(TARGET_PPC64)
8890 TCGv t0 = tcg_temp_new();
8891 TCGv t1 = tcg_temp_new();
8892 tcg_gen_ext32u_tl(t0, cpu_gpr[rB(ctx->opcode)]);
8893 tcg_gen_shli_tl(t1, cpu_gpr[rA(ctx->opcode)], 32);
8894 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1);
8898 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
8899 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
8902 static inline void gen_evmergehilo(DisasContext *ctx)
8904 if (unlikely(!ctx->spe_enabled)) {
8905 gen_exception(ctx, POWERPC_EXCP_SPEU);
8908 #if defined(TARGET_PPC64)
8909 TCGv t0 = tcg_temp_new();
8910 TCGv t1 = tcg_temp_new();
8911 tcg_gen_ext32u_tl(t0, cpu_gpr[rB(ctx->opcode)]);
8912 tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], 0xFFFFFFFF0000000ULL);
8913 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1);
8917 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
8918 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
8921 static inline void gen_evmergelohi(DisasContext *ctx)
8923 if (unlikely(!ctx->spe_enabled)) {
8924 gen_exception(ctx, POWERPC_EXCP_SPEU);
8927 #if defined(TARGET_PPC64)
8928 TCGv t0 = tcg_temp_new();
8929 TCGv t1 = tcg_temp_new();
8930 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 32);
8931 tcg_gen_shli_tl(t1, cpu_gpr[rA(ctx->opcode)], 32);
8932 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1);
8936 if (rD(ctx->opcode) == rA(ctx->opcode)) {
8937 TCGv_i32 tmp = tcg_temp_new_i32();
8938 tcg_gen_mov_i32(tmp, cpu_gpr[rA(ctx->opcode)]);
8939 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
8940 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], tmp);
8941 tcg_temp_free_i32(tmp);
8943 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
8944 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
8948 static inline void gen_evsplati(DisasContext *ctx)
8950 uint64_t imm = ((int32_t)(rA(ctx->opcode) << 27)) >> 27;
8952 #if defined(TARGET_PPC64)
8953 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], (imm << 32) | imm);
8955 tcg_gen_movi_i32(cpu_gpr[rD(ctx->opcode)], imm);
8956 tcg_gen_movi_i32(cpu_gprh[rD(ctx->opcode)], imm);
8959 static inline void gen_evsplatfi(DisasContext *ctx)
8961 uint64_t imm = rA(ctx->opcode) << 27;
8963 #if defined(TARGET_PPC64)
8964 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], (imm << 32) | imm);
8966 tcg_gen_movi_i32(cpu_gpr[rD(ctx->opcode)], imm);
8967 tcg_gen_movi_i32(cpu_gprh[rD(ctx->opcode)], imm);
8971 static inline void gen_evsel(DisasContext *ctx)
8973 int l1 = gen_new_label();
8974 int l2 = gen_new_label();
8975 int l3 = gen_new_label();
8976 int l4 = gen_new_label();
8977 TCGv_i32 t0 = tcg_temp_local_new_i32();
8978 #if defined(TARGET_PPC64)
8979 TCGv t1 = tcg_temp_local_new();
8980 TCGv t2 = tcg_temp_local_new();
8982 tcg_gen_andi_i32(t0, cpu_crf[ctx->opcode & 0x07], 1 << 3);
8983 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1);
8984 #if defined(TARGET_PPC64)
8985 tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], 0xFFFFFFFF00000000ULL);
8987 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
8991 #if defined(TARGET_PPC64)
8992 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0xFFFFFFFF00000000ULL);
8994 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
8997 tcg_gen_andi_i32(t0, cpu_crf[ctx->opcode & 0x07], 1 << 2);
8998 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l3);
8999 #if defined(TARGET_PPC64)
9000 tcg_gen_ext32u_tl(t2, cpu_gpr[rA(ctx->opcode)]);
9002 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
9006 #if defined(TARGET_PPC64)
9007 tcg_gen_ext32u_tl(t2, cpu_gpr[rB(ctx->opcode)]);
9009 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
9012 tcg_temp_free_i32(t0);
9013 #if defined(TARGET_PPC64)
9014 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t1, t2);
9020 static void gen_evsel0(DisasContext *ctx)
9025 static void gen_evsel1(DisasContext *ctx)
9030 static void gen_evsel2(DisasContext *ctx)
9035 static void gen_evsel3(DisasContext *ctx)
9042 static inline void gen_evmwumi(DisasContext *ctx)
9046 if (unlikely(!ctx->spe_enabled)) {
9047 gen_exception(ctx, POWERPC_EXCP_SPEU);
9051 t0 = tcg_temp_new_i64();
9052 t1 = tcg_temp_new_i64();
9054 /* t0 := rA; t1 := rB */
9055 #if defined(TARGET_PPC64)
9056 tcg_gen_ext32u_tl(t0, cpu_gpr[rA(ctx->opcode)]);
9057 tcg_gen_ext32u_tl(t1, cpu_gpr[rB(ctx->opcode)]);
9059 tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
9060 tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
9063 tcg_gen_mul_i64(t0, t0, t1); /* t0 := rA * rB */
9065 gen_store_gpr64(rD(ctx->opcode), t0); /* rD := t0 */
9067 tcg_temp_free_i64(t0);
9068 tcg_temp_free_i64(t1);
9071 static inline void gen_evmwumia(DisasContext *ctx)
9075 if (unlikely(!ctx->spe_enabled)) {
9076 gen_exception(ctx, POWERPC_EXCP_SPEU);
9080 gen_evmwumi(ctx); /* rD := rA * rB */
9082 tmp = tcg_temp_new_i64();
9085 gen_load_gpr64(tmp, rD(ctx->opcode));
9086 tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUPPCState, spe_acc));
9087 tcg_temp_free_i64(tmp);
9090 static inline void gen_evmwumiaa(DisasContext *ctx)
9095 if (unlikely(!ctx->spe_enabled)) {
9096 gen_exception(ctx, POWERPC_EXCP_SPEU);
9100 gen_evmwumi(ctx); /* rD := rA * rB */
9102 acc = tcg_temp_new_i64();
9103 tmp = tcg_temp_new_i64();
9106 gen_load_gpr64(tmp, rD(ctx->opcode));
9109 tcg_gen_ld_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc));
9111 /* acc := tmp + acc */
9112 tcg_gen_add_i64(acc, acc, tmp);
9115 tcg_gen_st_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc));
9118 gen_store_gpr64(rD(ctx->opcode), acc);
9120 tcg_temp_free_i64(acc);
9121 tcg_temp_free_i64(tmp);
9124 static inline void gen_evmwsmi(DisasContext *ctx)
9128 if (unlikely(!ctx->spe_enabled)) {
9129 gen_exception(ctx, POWERPC_EXCP_SPEU);
9133 t0 = tcg_temp_new_i64();
9134 t1 = tcg_temp_new_i64();
9136 /* t0 := rA; t1 := rB */
9137 #if defined(TARGET_PPC64)
9138 tcg_gen_ext32s_tl(t0, cpu_gpr[rA(ctx->opcode)]);
9139 tcg_gen_ext32s_tl(t1, cpu_gpr[rB(ctx->opcode)]);
9141 tcg_gen_ext_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
9142 tcg_gen_ext_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
9145 tcg_gen_mul_i64(t0, t0, t1); /* t0 := rA * rB */
9147 gen_store_gpr64(rD(ctx->opcode), t0); /* rD := t0 */
9149 tcg_temp_free_i64(t0);
9150 tcg_temp_free_i64(t1);
9153 static inline void gen_evmwsmia(DisasContext *ctx)
9157 gen_evmwsmi(ctx); /* rD := rA * rB */
9159 tmp = tcg_temp_new_i64();
9162 gen_load_gpr64(tmp, rD(ctx->opcode));
9163 tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUPPCState, spe_acc));
9165 tcg_temp_free_i64(tmp);
9168 static inline void gen_evmwsmiaa(DisasContext *ctx)
9170 TCGv_i64 acc = tcg_temp_new_i64();
9171 TCGv_i64 tmp = tcg_temp_new_i64();
9173 gen_evmwsmi(ctx); /* rD := rA * rB */
9175 acc = tcg_temp_new_i64();
9176 tmp = tcg_temp_new_i64();
9179 gen_load_gpr64(tmp, rD(ctx->opcode));
9182 tcg_gen_ld_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc));
9184 /* acc := tmp + acc */
9185 tcg_gen_add_i64(acc, acc, tmp);
9188 tcg_gen_st_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc));
9191 gen_store_gpr64(rD(ctx->opcode), acc);
9193 tcg_temp_free_i64(acc);
9194 tcg_temp_free_i64(tmp);
9197 GEN_SPE(evaddw, speundef, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
9198 GEN_SPE(evaddiw, speundef, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE);
9199 GEN_SPE(evsubfw, speundef, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
9200 GEN_SPE(evsubifw, speundef, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE);
9201 GEN_SPE(evabs, evneg, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE); ////
9202 GEN_SPE(evextsb, evextsh, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE); ////
9203 GEN_SPE(evrndw, evcntlzw, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE); ////
9204 GEN_SPE(evcntlsw, brinc, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE); //
9205 GEN_SPE(evmra, speundef, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE);
9206 GEN_SPE(speundef, evand, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE); ////
9207 GEN_SPE(evandc, speundef, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
9208 GEN_SPE(evxor, evor, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
9209 GEN_SPE(evnor, eveqv, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
9210 GEN_SPE(evmwumi, evmwsmi, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE);
9211 GEN_SPE(evmwumia, evmwsmia, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE);
9212 GEN_SPE(evmwumiaa, evmwsmiaa, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE);
9213 GEN_SPE(speundef, evorc, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE); ////
9214 GEN_SPE(evnand, speundef, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
9215 GEN_SPE(evsrwu, evsrws, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
9216 GEN_SPE(evsrwiu, evsrwis, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE);
9217 GEN_SPE(evslw, speundef, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
9218 GEN_SPE(evslwi, speundef, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE);
9219 GEN_SPE(evrlw, evsplati, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE); //
9220 GEN_SPE(evrlwi, evsplatfi, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE);
9221 GEN_SPE(evmergehi, evmergelo, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
9222 GEN_SPE(evmergehilo, evmergelohi, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
9223 GEN_SPE(evcmpgtu, evcmpgts, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE); ////
9224 GEN_SPE(evcmpltu, evcmplts, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE); ////
9225 GEN_SPE(evcmpeq, speundef, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE); ////
9227 /* SPE load and stores */
9228 static inline void gen_addr_spe_imm_index(DisasContext *ctx, TCGv EA, int sh)
9230 target_ulong uimm = rB(ctx->opcode);
9232 if (rA(ctx->opcode) == 0) {
9233 tcg_gen_movi_tl(EA, uimm << sh);
9235 tcg_gen_addi_tl(EA, cpu_gpr[rA(ctx->opcode)], uimm << sh);
9236 if (NARROW_MODE(ctx)) {
9237 tcg_gen_ext32u_tl(EA, EA);
9242 static inline void gen_op_evldd(DisasContext *ctx, TCGv addr)
9244 #if defined(TARGET_PPC64)
9245 gen_qemu_ld64(ctx, cpu_gpr[rD(ctx->opcode)], addr);
9247 TCGv_i64 t0 = tcg_temp_new_i64();
9248 gen_qemu_ld64(ctx, t0, addr);
9249 tcg_gen_trunc_i64_i32(cpu_gpr[rD(ctx->opcode)], t0);
9250 tcg_gen_shri_i64(t0, t0, 32);
9251 tcg_gen_trunc_i64_i32(cpu_gprh[rD(ctx->opcode)], t0);
9252 tcg_temp_free_i64(t0);
9256 static inline void gen_op_evldw(DisasContext *ctx, TCGv addr)
9258 #if defined(TARGET_PPC64)
9259 TCGv t0 = tcg_temp_new();
9260 gen_qemu_ld32u(ctx, t0, addr);
9261 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32);
9262 gen_addr_add(ctx, addr, addr, 4);
9263 gen_qemu_ld32u(ctx, t0, addr);
9264 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
9267 gen_qemu_ld32u(ctx, cpu_gprh[rD(ctx->opcode)], addr);
9268 gen_addr_add(ctx, addr, addr, 4);
9269 gen_qemu_ld32u(ctx, cpu_gpr[rD(ctx->opcode)], addr);
9273 static inline void gen_op_evldh(DisasContext *ctx, TCGv addr)
9275 TCGv t0 = tcg_temp_new();
9276 #if defined(TARGET_PPC64)
9277 gen_qemu_ld16u(ctx, t0, addr);
9278 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48);
9279 gen_addr_add(ctx, addr, addr, 2);
9280 gen_qemu_ld16u(ctx, t0, addr);
9281 tcg_gen_shli_tl(t0, t0, 32);
9282 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
9283 gen_addr_add(ctx, addr, addr, 2);
9284 gen_qemu_ld16u(ctx, t0, addr);
9285 tcg_gen_shli_tl(t0, t0, 16);
9286 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
9287 gen_addr_add(ctx, addr, addr, 2);
9288 gen_qemu_ld16u(ctx, t0, addr);
9289 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
9291 gen_qemu_ld16u(ctx, t0, addr);
9292 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
9293 gen_addr_add(ctx, addr, addr, 2);
9294 gen_qemu_ld16u(ctx, t0, addr);
9295 tcg_gen_or_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0);
9296 gen_addr_add(ctx, addr, addr, 2);
9297 gen_qemu_ld16u(ctx, t0, addr);
9298 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
9299 gen_addr_add(ctx, addr, addr, 2);
9300 gen_qemu_ld16u(ctx, t0, addr);
9301 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
9306 static inline void gen_op_evlhhesplat(DisasContext *ctx, TCGv addr)
9308 TCGv t0 = tcg_temp_new();
9309 gen_qemu_ld16u(ctx, t0, addr);
9310 #if defined(TARGET_PPC64)
9311 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48);
9312 tcg_gen_shli_tl(t0, t0, 16);
9313 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
9315 tcg_gen_shli_tl(t0, t0, 16);
9316 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
9317 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
9322 static inline void gen_op_evlhhousplat(DisasContext *ctx, TCGv addr)
9324 TCGv t0 = tcg_temp_new();
9325 gen_qemu_ld16u(ctx, t0, addr);
9326 #if defined(TARGET_PPC64)
9327 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32);
9328 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
9330 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
9331 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
9336 static inline void gen_op_evlhhossplat(DisasContext *ctx, TCGv addr)
9338 TCGv t0 = tcg_temp_new();
9339 gen_qemu_ld16s(ctx, t0, addr);
9340 #if defined(TARGET_PPC64)
9341 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32);
9342 tcg_gen_ext32u_tl(t0, t0);
9343 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
9345 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
9346 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
9351 static inline void gen_op_evlwhe(DisasContext *ctx, TCGv addr)
9353 TCGv t0 = tcg_temp_new();
9354 #if defined(TARGET_PPC64)
9355 gen_qemu_ld16u(ctx, t0, addr);
9356 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48);
9357 gen_addr_add(ctx, addr, addr, 2);
9358 gen_qemu_ld16u(ctx, t0, addr);
9359 tcg_gen_shli_tl(t0, t0, 16);
9360 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
9362 gen_qemu_ld16u(ctx, t0, addr);
9363 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
9364 gen_addr_add(ctx, addr, addr, 2);
9365 gen_qemu_ld16u(ctx, t0, addr);
9366 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 16);
9371 static inline void gen_op_evlwhou(DisasContext *ctx, TCGv addr)
9373 #if defined(TARGET_PPC64)
9374 TCGv t0 = tcg_temp_new();
9375 gen_qemu_ld16u(ctx, cpu_gpr[rD(ctx->opcode)], addr);
9376 gen_addr_add(ctx, addr, addr, 2);
9377 gen_qemu_ld16u(ctx, t0, addr);
9378 tcg_gen_shli_tl(t0, t0, 32);
9379 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
9382 gen_qemu_ld16u(ctx, cpu_gprh[rD(ctx->opcode)], addr);
9383 gen_addr_add(ctx, addr, addr, 2);
9384 gen_qemu_ld16u(ctx, cpu_gpr[rD(ctx->opcode)], addr);
9388 static inline void gen_op_evlwhos(DisasContext *ctx, TCGv addr)
9390 #if defined(TARGET_PPC64)
9391 TCGv t0 = tcg_temp_new();
9392 gen_qemu_ld16s(ctx, t0, addr);
9393 tcg_gen_ext32u_tl(cpu_gpr[rD(ctx->opcode)], t0);
9394 gen_addr_add(ctx, addr, addr, 2);
9395 gen_qemu_ld16s(ctx, t0, addr);
9396 tcg_gen_shli_tl(t0, t0, 32);
9397 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
9400 gen_qemu_ld16s(ctx, cpu_gprh[rD(ctx->opcode)], addr);
9401 gen_addr_add(ctx, addr, addr, 2);
9402 gen_qemu_ld16s(ctx, cpu_gpr[rD(ctx->opcode)], addr);
9406 static inline void gen_op_evlwwsplat(DisasContext *ctx, TCGv addr)
9408 TCGv t0 = tcg_temp_new();
9409 gen_qemu_ld32u(ctx, t0, addr);
9410 #if defined(TARGET_PPC64)
9411 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32);
9412 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
9414 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
9415 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
9420 static inline void gen_op_evlwhsplat(DisasContext *ctx, TCGv addr)
9422 TCGv t0 = tcg_temp_new();
9423 #if defined(TARGET_PPC64)
9424 gen_qemu_ld16u(ctx, t0, addr);
9425 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48);
9426 tcg_gen_shli_tl(t0, t0, 32);
9427 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
9428 gen_addr_add(ctx, addr, addr, 2);
9429 gen_qemu_ld16u(ctx, t0, addr);
9430 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
9431 tcg_gen_shli_tl(t0, t0, 16);
9432 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
9434 gen_qemu_ld16u(ctx, t0, addr);
9435 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
9436 tcg_gen_or_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0);
9437 gen_addr_add(ctx, addr, addr, 2);
9438 gen_qemu_ld16u(ctx, t0, addr);
9439 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 16);
9440 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0);
9445 static inline void gen_op_evstdd(DisasContext *ctx, TCGv addr)
9447 #if defined(TARGET_PPC64)
9448 gen_qemu_st64(ctx, cpu_gpr[rS(ctx->opcode)], addr);
9450 TCGv_i64 t0 = tcg_temp_new_i64();
9451 tcg_gen_concat_i32_i64(t0, cpu_gpr[rS(ctx->opcode)], cpu_gprh[rS(ctx->opcode)]);
9452 gen_qemu_st64(ctx, t0, addr);
9453 tcg_temp_free_i64(t0);
9457 static inline void gen_op_evstdw(DisasContext *ctx, TCGv addr)
9459 #if defined(TARGET_PPC64)
9460 TCGv t0 = tcg_temp_new();
9461 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32);
9462 gen_qemu_st32(ctx, t0, addr);
9465 gen_qemu_st32(ctx, cpu_gprh[rS(ctx->opcode)], addr);
9467 gen_addr_add(ctx, addr, addr, 4);
9468 gen_qemu_st32(ctx, cpu_gpr[rS(ctx->opcode)], addr);
9471 static inline void gen_op_evstdh(DisasContext *ctx, TCGv addr)
9473 TCGv t0 = tcg_temp_new();
9474 #if defined(TARGET_PPC64)
9475 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 48);
9477 tcg_gen_shri_tl(t0, cpu_gprh[rS(ctx->opcode)], 16);
9479 gen_qemu_st16(ctx, t0, addr);
9480 gen_addr_add(ctx, addr, addr, 2);
9481 #if defined(TARGET_PPC64)
9482 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32);
9483 gen_qemu_st16(ctx, t0, addr);
9485 gen_qemu_st16(ctx, cpu_gprh[rS(ctx->opcode)], addr);
9487 gen_addr_add(ctx, addr, addr, 2);
9488 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 16);
9489 gen_qemu_st16(ctx, t0, addr);
9491 gen_addr_add(ctx, addr, addr, 2);
9492 gen_qemu_st16(ctx, cpu_gpr[rS(ctx->opcode)], addr);
9495 static inline void gen_op_evstwhe(DisasContext *ctx, TCGv addr)
9497 TCGv t0 = tcg_temp_new();
9498 #if defined(TARGET_PPC64)
9499 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 48);
9501 tcg_gen_shri_tl(t0, cpu_gprh[rS(ctx->opcode)], 16);
9503 gen_qemu_st16(ctx, t0, addr);
9504 gen_addr_add(ctx, addr, addr, 2);
9505 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 16);
9506 gen_qemu_st16(ctx, t0, addr);
9510 static inline void gen_op_evstwho(DisasContext *ctx, TCGv addr)
9512 #if defined(TARGET_PPC64)
9513 TCGv t0 = tcg_temp_new();
9514 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32);
9515 gen_qemu_st16(ctx, t0, addr);
9518 gen_qemu_st16(ctx, cpu_gprh[rS(ctx->opcode)], addr);
9520 gen_addr_add(ctx, addr, addr, 2);
9521 gen_qemu_st16(ctx, cpu_gpr[rS(ctx->opcode)], addr);
9524 static inline void gen_op_evstwwe(DisasContext *ctx, TCGv addr)
9526 #if defined(TARGET_PPC64)
9527 TCGv t0 = tcg_temp_new();
9528 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32);
9529 gen_qemu_st32(ctx, t0, addr);
9532 gen_qemu_st32(ctx, cpu_gprh[rS(ctx->opcode)], addr);
9536 static inline void gen_op_evstwwo(DisasContext *ctx, TCGv addr)
9538 gen_qemu_st32(ctx, cpu_gpr[rS(ctx->opcode)], addr);
9541 #define GEN_SPEOP_LDST(name, opc2, sh) \
9542 static void glue(gen_, name)(DisasContext *ctx) \
9545 if (unlikely(!ctx->spe_enabled)) { \
9546 gen_exception(ctx, POWERPC_EXCP_SPEU); \
9549 gen_set_access_type(ctx, ACCESS_INT); \
9550 t0 = tcg_temp_new(); \
9551 if (Rc(ctx->opcode)) { \
9552 gen_addr_spe_imm_index(ctx, t0, sh); \
9554 gen_addr_reg_index(ctx, t0); \
9556 gen_op_##name(ctx, t0); \
9557 tcg_temp_free(t0); \
9560 GEN_SPEOP_LDST(evldd, 0x00, 3);
9561 GEN_SPEOP_LDST(evldw, 0x01, 3);
9562 GEN_SPEOP_LDST(evldh, 0x02, 3);
9563 GEN_SPEOP_LDST(evlhhesplat, 0x04, 1);
9564 GEN_SPEOP_LDST(evlhhousplat, 0x06, 1);
9565 GEN_SPEOP_LDST(evlhhossplat, 0x07, 1);
9566 GEN_SPEOP_LDST(evlwhe, 0x08, 2);
9567 GEN_SPEOP_LDST(evlwhou, 0x0A, 2);
9568 GEN_SPEOP_LDST(evlwhos, 0x0B, 2);
9569 GEN_SPEOP_LDST(evlwwsplat, 0x0C, 2);
9570 GEN_SPEOP_LDST(evlwhsplat, 0x0E, 2);
9572 GEN_SPEOP_LDST(evstdd, 0x10, 3);
9573 GEN_SPEOP_LDST(evstdw, 0x11, 3);
9574 GEN_SPEOP_LDST(evstdh, 0x12, 3);
9575 GEN_SPEOP_LDST(evstwhe, 0x18, 2);
9576 GEN_SPEOP_LDST(evstwho, 0x1A, 2);
9577 GEN_SPEOP_LDST(evstwwe, 0x1C, 2);
9578 GEN_SPEOP_LDST(evstwwo, 0x1E, 2);
9580 /* Multiply and add - TODO */
9582 GEN_SPE(speundef, evmhessf, 0x01, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);//
9583 GEN_SPE(speundef, evmhossf, 0x03, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9584 GEN_SPE(evmheumi, evmhesmi, 0x04, 0x10, 0x00000000, 0x00000000, PPC_SPE);
9585 GEN_SPE(speundef, evmhesmf, 0x05, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9586 GEN_SPE(evmhoumi, evmhosmi, 0x06, 0x10, 0x00000000, 0x00000000, PPC_SPE);
9587 GEN_SPE(speundef, evmhosmf, 0x07, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9588 GEN_SPE(speundef, evmhessfa, 0x11, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9589 GEN_SPE(speundef, evmhossfa, 0x13, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9590 GEN_SPE(evmheumia, evmhesmia, 0x14, 0x10, 0x00000000, 0x00000000, PPC_SPE);
9591 GEN_SPE(speundef, evmhesmfa, 0x15, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9592 GEN_SPE(evmhoumia, evmhosmia, 0x16, 0x10, 0x00000000, 0x00000000, PPC_SPE);
9593 GEN_SPE(speundef, evmhosmfa, 0x17, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9595 GEN_SPE(speundef, evmwhssf, 0x03, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9596 GEN_SPE(evmwlumi, speundef, 0x04, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE);
9597 GEN_SPE(evmwhumi, evmwhsmi, 0x06, 0x11, 0x00000000, 0x00000000, PPC_SPE);
9598 GEN_SPE(speundef, evmwhsmf, 0x07, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9599 GEN_SPE(speundef, evmwssf, 0x09, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9600 GEN_SPE(speundef, evmwsmf, 0x0D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9601 GEN_SPE(speundef, evmwhssfa, 0x13, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9602 GEN_SPE(evmwlumia, speundef, 0x14, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE);
9603 GEN_SPE(evmwhumia, evmwhsmia, 0x16, 0x11, 0x00000000, 0x00000000, PPC_SPE);
9604 GEN_SPE(speundef, evmwhsmfa, 0x17, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9605 GEN_SPE(speundef, evmwssfa, 0x19, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9606 GEN_SPE(speundef, evmwsmfa, 0x1D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9608 GEN_SPE(evadduiaaw, evaddsiaaw, 0x00, 0x13, 0x0000F800, 0x0000F800, PPC_SPE);
9609 GEN_SPE(evsubfusiaaw, evsubfssiaaw, 0x01, 0x13, 0x0000F800, 0x0000F800, PPC_SPE);
9610 GEN_SPE(evaddumiaaw, evaddsmiaaw, 0x04, 0x13, 0x0000F800, 0x0000F800, PPC_SPE);
9611 GEN_SPE(evsubfumiaaw, evsubfsmiaaw, 0x05, 0x13, 0x0000F800, 0x0000F800, PPC_SPE);
9612 GEN_SPE(evdivws, evdivwu, 0x06, 0x13, 0x00000000, 0x00000000, PPC_SPE);
9614 GEN_SPE(evmheusiaaw, evmhessiaaw, 0x00, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9615 GEN_SPE(speundef, evmhessfaaw, 0x01, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9616 GEN_SPE(evmhousiaaw, evmhossiaaw, 0x02, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9617 GEN_SPE(speundef, evmhossfaaw, 0x03, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9618 GEN_SPE(evmheumiaaw, evmhesmiaaw, 0x04, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9619 GEN_SPE(speundef, evmhesmfaaw, 0x05, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9620 GEN_SPE(evmhoumiaaw, evmhosmiaaw, 0x06, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9621 GEN_SPE(speundef, evmhosmfaaw, 0x07, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9622 GEN_SPE(evmhegumiaa, evmhegsmiaa, 0x14, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9623 GEN_SPE(speundef, evmhegsmfaa, 0x15, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9624 GEN_SPE(evmhogumiaa, evmhogsmiaa, 0x16, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9625 GEN_SPE(speundef, evmhogsmfaa, 0x17, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9627 GEN_SPE(evmwlusiaaw, evmwlssiaaw, 0x00, 0x15, 0x00000000, 0x00000000, PPC_SPE);
9628 GEN_SPE(evmwlumiaaw, evmwlsmiaaw, 0x04, 0x15, 0x00000000, 0x00000000, PPC_SPE);
9629 GEN_SPE(speundef, evmwssfaa, 0x09, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9630 GEN_SPE(speundef, evmwsmfaa, 0x0D, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9632 GEN_SPE(evmheusianw, evmhessianw, 0x00, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9633 GEN_SPE(speundef, evmhessfanw, 0x01, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9634 GEN_SPE(evmhousianw, evmhossianw, 0x02, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9635 GEN_SPE(speundef, evmhossfanw, 0x03, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9636 GEN_SPE(evmheumianw, evmhesmianw, 0x04, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9637 GEN_SPE(speundef, evmhesmfanw, 0x05, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9638 GEN_SPE(evmhoumianw, evmhosmianw, 0x06, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9639 GEN_SPE(speundef, evmhosmfanw, 0x07, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9640 GEN_SPE(evmhegumian, evmhegsmian, 0x14, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9641 GEN_SPE(speundef, evmhegsmfan, 0x15, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9642 GEN_SPE(evmhigumian, evmhigsmian, 0x16, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9643 GEN_SPE(speundef, evmhogsmfan, 0x17, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9645 GEN_SPE(evmwlusianw, evmwlssianw, 0x00, 0x17, 0x00000000, 0x00000000, PPC_SPE);
9646 GEN_SPE(evmwlumianw, evmwlsmianw, 0x04, 0x17, 0x00000000, 0x00000000, PPC_SPE);
9647 GEN_SPE(speundef, evmwssfan, 0x09, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9648 GEN_SPE(evmwumian, evmwsmian, 0x0C, 0x17, 0x00000000, 0x00000000, PPC_SPE);
9649 GEN_SPE(speundef, evmwsmfan, 0x0D, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9652 /*** SPE floating-point extension ***/
9653 #if defined(TARGET_PPC64)
9654 #define GEN_SPEFPUOP_CONV_32_32(name) \
9655 static inline void gen_##name(DisasContext *ctx) \
9659 t0 = tcg_temp_new_i32(); \
9660 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
9661 gen_helper_##name(t0, cpu_env, t0); \
9662 t1 = tcg_temp_new(); \
9663 tcg_gen_extu_i32_tl(t1, t0); \
9664 tcg_temp_free_i32(t0); \
9665 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
9666 0xFFFFFFFF00000000ULL); \
9667 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t1); \
9668 tcg_temp_free(t1); \
9670 #define GEN_SPEFPUOP_CONV_32_64(name) \
9671 static inline void gen_##name(DisasContext *ctx) \
9675 t0 = tcg_temp_new_i32(); \
9676 gen_helper_##name(t0, cpu_env, cpu_gpr[rB(ctx->opcode)]); \
9677 t1 = tcg_temp_new(); \
9678 tcg_gen_extu_i32_tl(t1, t0); \
9679 tcg_temp_free_i32(t0); \
9680 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
9681 0xFFFFFFFF00000000ULL); \
9682 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t1); \
9683 tcg_temp_free(t1); \
9685 #define GEN_SPEFPUOP_CONV_64_32(name) \
9686 static inline void gen_##name(DisasContext *ctx) \
9688 TCGv_i32 t0 = tcg_temp_new_i32(); \
9689 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
9690 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); \
9691 tcg_temp_free_i32(t0); \
9693 #define GEN_SPEFPUOP_CONV_64_64(name) \
9694 static inline void gen_##name(DisasContext *ctx) \
9696 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
9697 cpu_gpr[rB(ctx->opcode)]); \
9699 #define GEN_SPEFPUOP_ARITH2_32_32(name) \
9700 static inline void gen_##name(DisasContext *ctx) \
9704 if (unlikely(!ctx->spe_enabled)) { \
9705 gen_exception(ctx, POWERPC_EXCP_SPEU); \
9708 t0 = tcg_temp_new_i32(); \
9709 t1 = tcg_temp_new_i32(); \
9710 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
9711 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
9712 gen_helper_##name(t0, cpu_env, t0, t1); \
9713 tcg_temp_free_i32(t1); \
9714 t2 = tcg_temp_new(); \
9715 tcg_gen_extu_i32_tl(t2, t0); \
9716 tcg_temp_free_i32(t0); \
9717 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
9718 0xFFFFFFFF00000000ULL); \
9719 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t2); \
9720 tcg_temp_free(t2); \
9722 #define GEN_SPEFPUOP_ARITH2_64_64(name) \
9723 static inline void gen_##name(DisasContext *ctx) \
9725 if (unlikely(!ctx->spe_enabled)) { \
9726 gen_exception(ctx, POWERPC_EXCP_SPEU); \
9729 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
9730 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
9732 #define GEN_SPEFPUOP_COMP_32(name) \
9733 static inline void gen_##name(DisasContext *ctx) \
9736 if (unlikely(!ctx->spe_enabled)) { \
9737 gen_exception(ctx, POWERPC_EXCP_SPEU); \
9740 t0 = tcg_temp_new_i32(); \
9741 t1 = tcg_temp_new_i32(); \
9742 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
9743 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
9744 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, t0, t1); \
9745 tcg_temp_free_i32(t0); \
9746 tcg_temp_free_i32(t1); \
9748 #define GEN_SPEFPUOP_COMP_64(name) \
9749 static inline void gen_##name(DisasContext *ctx) \
9751 if (unlikely(!ctx->spe_enabled)) { \
9752 gen_exception(ctx, POWERPC_EXCP_SPEU); \
9755 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, \
9756 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
9759 #define GEN_SPEFPUOP_CONV_32_32(name) \
9760 static inline void gen_##name(DisasContext *ctx) \
9762 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
9763 cpu_gpr[rB(ctx->opcode)]); \
9765 #define GEN_SPEFPUOP_CONV_32_64(name) \
9766 static inline void gen_##name(DisasContext *ctx) \
9768 TCGv_i64 t0 = tcg_temp_new_i64(); \
9769 gen_load_gpr64(t0, rB(ctx->opcode)); \
9770 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); \
9771 tcg_temp_free_i64(t0); \
9773 #define GEN_SPEFPUOP_CONV_64_32(name) \
9774 static inline void gen_##name(DisasContext *ctx) \
9776 TCGv_i64 t0 = tcg_temp_new_i64(); \
9777 gen_helper_##name(t0, cpu_env, cpu_gpr[rB(ctx->opcode)]); \
9778 gen_store_gpr64(rD(ctx->opcode), t0); \
9779 tcg_temp_free_i64(t0); \
9781 #define GEN_SPEFPUOP_CONV_64_64(name) \
9782 static inline void gen_##name(DisasContext *ctx) \
9784 TCGv_i64 t0 = tcg_temp_new_i64(); \
9785 gen_load_gpr64(t0, rB(ctx->opcode)); \
9786 gen_helper_##name(t0, cpu_env, t0); \
9787 gen_store_gpr64(rD(ctx->opcode), t0); \
9788 tcg_temp_free_i64(t0); \
9790 #define GEN_SPEFPUOP_ARITH2_32_32(name) \
9791 static inline void gen_##name(DisasContext *ctx) \
9793 if (unlikely(!ctx->spe_enabled)) { \
9794 gen_exception(ctx, POWERPC_EXCP_SPEU); \
9797 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
9798 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
9800 #define GEN_SPEFPUOP_ARITH2_64_64(name) \
9801 static inline void gen_##name(DisasContext *ctx) \
9804 if (unlikely(!ctx->spe_enabled)) { \
9805 gen_exception(ctx, POWERPC_EXCP_SPEU); \
9808 t0 = tcg_temp_new_i64(); \
9809 t1 = tcg_temp_new_i64(); \
9810 gen_load_gpr64(t0, rA(ctx->opcode)); \
9811 gen_load_gpr64(t1, rB(ctx->opcode)); \
9812 gen_helper_##name(t0, cpu_env, t0, t1); \
9813 gen_store_gpr64(rD(ctx->opcode), t0); \
9814 tcg_temp_free_i64(t0); \
9815 tcg_temp_free_i64(t1); \
9817 #define GEN_SPEFPUOP_COMP_32(name) \
9818 static inline void gen_##name(DisasContext *ctx) \
9820 if (unlikely(!ctx->spe_enabled)) { \
9821 gen_exception(ctx, POWERPC_EXCP_SPEU); \
9824 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, \
9825 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
9827 #define GEN_SPEFPUOP_COMP_64(name) \
9828 static inline void gen_##name(DisasContext *ctx) \
9831 if (unlikely(!ctx->spe_enabled)) { \
9832 gen_exception(ctx, POWERPC_EXCP_SPEU); \
9835 t0 = tcg_temp_new_i64(); \
9836 t1 = tcg_temp_new_i64(); \
9837 gen_load_gpr64(t0, rA(ctx->opcode)); \
9838 gen_load_gpr64(t1, rB(ctx->opcode)); \
9839 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, t0, t1); \
9840 tcg_temp_free_i64(t0); \
9841 tcg_temp_free_i64(t1); \
9845 /* Single precision floating-point vectors operations */
9847 GEN_SPEFPUOP_ARITH2_64_64(evfsadd);
9848 GEN_SPEFPUOP_ARITH2_64_64(evfssub);
9849 GEN_SPEFPUOP_ARITH2_64_64(evfsmul);
9850 GEN_SPEFPUOP_ARITH2_64_64(evfsdiv);
9851 static inline void gen_evfsabs(DisasContext *ctx)
9853 if (unlikely(!ctx->spe_enabled)) {
9854 gen_exception(ctx, POWERPC_EXCP_SPEU);
9857 #if defined(TARGET_PPC64)
9858 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~0x8000000080000000LL);
9860 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~0x80000000);
9861 tcg_gen_andi_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], ~0x80000000);
9864 static inline void gen_evfsnabs(DisasContext *ctx)
9866 if (unlikely(!ctx->spe_enabled)) {
9867 gen_exception(ctx, POWERPC_EXCP_SPEU);
9870 #if defined(TARGET_PPC64)
9871 tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000080000000LL);
9873 tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000);
9874 tcg_gen_ori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000);
9877 static inline void gen_evfsneg(DisasContext *ctx)
9879 if (unlikely(!ctx->spe_enabled)) {
9880 gen_exception(ctx, POWERPC_EXCP_SPEU);
9883 #if defined(TARGET_PPC64)
9884 tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000080000000LL);
9886 tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000);
9887 tcg_gen_xori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000);
9892 GEN_SPEFPUOP_CONV_64_64(evfscfui);
9893 GEN_SPEFPUOP_CONV_64_64(evfscfsi);
9894 GEN_SPEFPUOP_CONV_64_64(evfscfuf);
9895 GEN_SPEFPUOP_CONV_64_64(evfscfsf);
9896 GEN_SPEFPUOP_CONV_64_64(evfsctui);
9897 GEN_SPEFPUOP_CONV_64_64(evfsctsi);
9898 GEN_SPEFPUOP_CONV_64_64(evfsctuf);
9899 GEN_SPEFPUOP_CONV_64_64(evfsctsf);
9900 GEN_SPEFPUOP_CONV_64_64(evfsctuiz);
9901 GEN_SPEFPUOP_CONV_64_64(evfsctsiz);
9904 GEN_SPEFPUOP_COMP_64(evfscmpgt);
9905 GEN_SPEFPUOP_COMP_64(evfscmplt);
9906 GEN_SPEFPUOP_COMP_64(evfscmpeq);
9907 GEN_SPEFPUOP_COMP_64(evfststgt);
9908 GEN_SPEFPUOP_COMP_64(evfststlt);
9909 GEN_SPEFPUOP_COMP_64(evfststeq);
9911 /* Opcodes definitions */
9912 GEN_SPE(evfsadd, evfssub, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE); //
9913 GEN_SPE(evfsabs, evfsnabs, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE); //
9914 GEN_SPE(evfsneg, speundef, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9915 GEN_SPE(evfsmul, evfsdiv, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE); //
9916 GEN_SPE(evfscmpgt, evfscmplt, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE); //
9917 GEN_SPE(evfscmpeq, speundef, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9918 GEN_SPE(evfscfui, evfscfsi, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9919 GEN_SPE(evfscfuf, evfscfsf, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9920 GEN_SPE(evfsctui, evfsctsi, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9921 GEN_SPE(evfsctuf, evfsctsf, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9922 GEN_SPE(evfsctuiz, speundef, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9923 GEN_SPE(evfsctsiz, speundef, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9924 GEN_SPE(evfststgt, evfststlt, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE); //
9925 GEN_SPE(evfststeq, speundef, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9927 /* Single precision floating-point operations */
9929 GEN_SPEFPUOP_ARITH2_32_32(efsadd);
9930 GEN_SPEFPUOP_ARITH2_32_32(efssub);
9931 GEN_SPEFPUOP_ARITH2_32_32(efsmul);
9932 GEN_SPEFPUOP_ARITH2_32_32(efsdiv);
9933 static inline void gen_efsabs(DisasContext *ctx)
9935 if (unlikely(!ctx->spe_enabled)) {
9936 gen_exception(ctx, POWERPC_EXCP_SPEU);
9939 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], (target_long)~0x80000000LL);
9941 static inline void gen_efsnabs(DisasContext *ctx)
9943 if (unlikely(!ctx->spe_enabled)) {
9944 gen_exception(ctx, POWERPC_EXCP_SPEU);
9947 tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000);
9949 static inline void gen_efsneg(DisasContext *ctx)
9951 if (unlikely(!ctx->spe_enabled)) {
9952 gen_exception(ctx, POWERPC_EXCP_SPEU);
9955 tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000);
9959 GEN_SPEFPUOP_CONV_32_32(efscfui);
9960 GEN_SPEFPUOP_CONV_32_32(efscfsi);
9961 GEN_SPEFPUOP_CONV_32_32(efscfuf);
9962 GEN_SPEFPUOP_CONV_32_32(efscfsf);
9963 GEN_SPEFPUOP_CONV_32_32(efsctui);
9964 GEN_SPEFPUOP_CONV_32_32(efsctsi);
9965 GEN_SPEFPUOP_CONV_32_32(efsctuf);
9966 GEN_SPEFPUOP_CONV_32_32(efsctsf);
9967 GEN_SPEFPUOP_CONV_32_32(efsctuiz);
9968 GEN_SPEFPUOP_CONV_32_32(efsctsiz);
9969 GEN_SPEFPUOP_CONV_32_64(efscfd);
9972 GEN_SPEFPUOP_COMP_32(efscmpgt);
9973 GEN_SPEFPUOP_COMP_32(efscmplt);
9974 GEN_SPEFPUOP_COMP_32(efscmpeq);
9975 GEN_SPEFPUOP_COMP_32(efststgt);
9976 GEN_SPEFPUOP_COMP_32(efststlt);
9977 GEN_SPEFPUOP_COMP_32(efststeq);
9979 /* Opcodes definitions */
9980 GEN_SPE(efsadd, efssub, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE); //
9981 GEN_SPE(efsabs, efsnabs, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE); //
9982 GEN_SPE(efsneg, speundef, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9983 GEN_SPE(efsmul, efsdiv, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE); //
9984 GEN_SPE(efscmpgt, efscmplt, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE); //
9985 GEN_SPE(efscmpeq, efscfd, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE); //
9986 GEN_SPE(efscfui, efscfsi, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9987 GEN_SPE(efscfuf, efscfsf, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9988 GEN_SPE(efsctui, efsctsi, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9989 GEN_SPE(efsctuf, efsctsf, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9990 GEN_SPE(efsctuiz, speundef, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9991 GEN_SPE(efsctsiz, speundef, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9992 GEN_SPE(efststgt, efststlt, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE); //
9993 GEN_SPE(efststeq, speundef, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9995 /* Double precision floating-point operations */
9997 GEN_SPEFPUOP_ARITH2_64_64(efdadd);
9998 GEN_SPEFPUOP_ARITH2_64_64(efdsub);
9999 GEN_SPEFPUOP_ARITH2_64_64(efdmul);
10000 GEN_SPEFPUOP_ARITH2_64_64(efddiv);
10001 static inline void gen_efdabs(DisasContext *ctx)
10003 if (unlikely(!ctx->spe_enabled)) {
10004 gen_exception(ctx, POWERPC_EXCP_SPEU);
10007 #if defined(TARGET_PPC64)
10008 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~0x8000000000000000LL);
10010 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
10011 tcg_gen_andi_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], ~0x80000000);
10014 static inline void gen_efdnabs(DisasContext *ctx)
10016 if (unlikely(!ctx->spe_enabled)) {
10017 gen_exception(ctx, POWERPC_EXCP_SPEU);
10020 #if defined(TARGET_PPC64)
10021 tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000000000000LL);
10023 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
10024 tcg_gen_ori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000);
10027 static inline void gen_efdneg(DisasContext *ctx)
10029 if (unlikely(!ctx->spe_enabled)) {
10030 gen_exception(ctx, POWERPC_EXCP_SPEU);
10033 #if defined(TARGET_PPC64)
10034 tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000000000000LL);
10036 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
10037 tcg_gen_xori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000);
10042 GEN_SPEFPUOP_CONV_64_32(efdcfui);
10043 GEN_SPEFPUOP_CONV_64_32(efdcfsi);
10044 GEN_SPEFPUOP_CONV_64_32(efdcfuf);
10045 GEN_SPEFPUOP_CONV_64_32(efdcfsf);
10046 GEN_SPEFPUOP_CONV_32_64(efdctui);
10047 GEN_SPEFPUOP_CONV_32_64(efdctsi);
10048 GEN_SPEFPUOP_CONV_32_64(efdctuf);
10049 GEN_SPEFPUOP_CONV_32_64(efdctsf);
10050 GEN_SPEFPUOP_CONV_32_64(efdctuiz);
10051 GEN_SPEFPUOP_CONV_32_64(efdctsiz);
10052 GEN_SPEFPUOP_CONV_64_32(efdcfs);
10053 GEN_SPEFPUOP_CONV_64_64(efdcfuid);
10054 GEN_SPEFPUOP_CONV_64_64(efdcfsid);
10055 GEN_SPEFPUOP_CONV_64_64(efdctuidz);
10056 GEN_SPEFPUOP_CONV_64_64(efdctsidz);
10059 GEN_SPEFPUOP_COMP_64(efdcmpgt);
10060 GEN_SPEFPUOP_COMP_64(efdcmplt);
10061 GEN_SPEFPUOP_COMP_64(efdcmpeq);
10062 GEN_SPEFPUOP_COMP_64(efdtstgt);
10063 GEN_SPEFPUOP_COMP_64(efdtstlt);
10064 GEN_SPEFPUOP_COMP_64(efdtsteq);
10066 /* Opcodes definitions */
10067 GEN_SPE(efdadd, efdsub, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE); //
10068 GEN_SPE(efdcfuid, efdcfsid, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
10069 GEN_SPE(efdabs, efdnabs, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE); //
10070 GEN_SPE(efdneg, speundef, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE); //
10071 GEN_SPE(efdmul, efddiv, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE); //
10072 GEN_SPE(efdctuidz, efdctsidz, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
10073 GEN_SPE(efdcmpgt, efdcmplt, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE); //
10074 GEN_SPE(efdcmpeq, efdcfs, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE); //
10075 GEN_SPE(efdcfui, efdcfsi, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
10076 GEN_SPE(efdcfuf, efdcfsf, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
10077 GEN_SPE(efdctui, efdctsi, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
10078 GEN_SPE(efdctuf, efdctsf, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
10079 GEN_SPE(efdctuiz, speundef, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE); //
10080 GEN_SPE(efdctsiz, speundef, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE); //
10081 GEN_SPE(efdtstgt, efdtstlt, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE); //
10082 GEN_SPE(efdtsteq, speundef, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE); //
10084 static opcode_t opcodes[] = {
10085 GEN_HANDLER(invalid, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE),
10086 GEN_HANDLER(cmp, 0x1F, 0x00, 0x00, 0x00400000, PPC_INTEGER),
10087 GEN_HANDLER(cmpi, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER),
10088 GEN_HANDLER(cmpl, 0x1F, 0x00, 0x01, 0x00400000, PPC_INTEGER),
10089 GEN_HANDLER(cmpli, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER),
10090 GEN_HANDLER_E(cmpb, 0x1F, 0x1C, 0x0F, 0x00000001, PPC_NONE, PPC2_ISA205),
10091 GEN_HANDLER(isel, 0x1F, 0x0F, 0xFF, 0x00000001, PPC_ISEL),
10092 GEN_HANDLER(addi, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
10093 GEN_HANDLER(addic, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
10094 GEN_HANDLER2(addic_, "addic.", 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
10095 GEN_HANDLER(addis, 0x0F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
10096 GEN_HANDLER(mulhw, 0x1F, 0x0B, 0x02, 0x00000400, PPC_INTEGER),
10097 GEN_HANDLER(mulhwu, 0x1F, 0x0B, 0x00, 0x00000400, PPC_INTEGER),
10098 GEN_HANDLER(mullw, 0x1F, 0x0B, 0x07, 0x00000000, PPC_INTEGER),
10099 GEN_HANDLER(mullwo, 0x1F, 0x0B, 0x17, 0x00000000, PPC_INTEGER),
10100 GEN_HANDLER(mulli, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
10101 #if defined(TARGET_PPC64)
10102 GEN_HANDLER(mulld, 0x1F, 0x09, 0x07, 0x00000000, PPC_64B),
10104 GEN_HANDLER(neg, 0x1F, 0x08, 0x03, 0x0000F800, PPC_INTEGER),
10105 GEN_HANDLER(nego, 0x1F, 0x08, 0x13, 0x0000F800, PPC_INTEGER),
10106 GEN_HANDLER(subfic, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
10107 GEN_HANDLER2(andi_, "andi.", 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
10108 GEN_HANDLER2(andis_, "andis.", 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
10109 GEN_HANDLER(cntlzw, 0x1F, 0x1A, 0x00, 0x00000000, PPC_INTEGER),
10110 GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER),
10111 GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER),
10112 GEN_HANDLER(ori, 0x18, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
10113 GEN_HANDLER(oris, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
10114 GEN_HANDLER(xori, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
10115 GEN_HANDLER(xoris, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
10116 GEN_HANDLER(popcntb, 0x1F, 0x03, 0x03, 0x0000F801, PPC_POPCNTB),
10117 GEN_HANDLER(popcntw, 0x1F, 0x1A, 0x0b, 0x0000F801, PPC_POPCNTWD),
10118 GEN_HANDLER_E(prtyw, 0x1F, 0x1A, 0x04, 0x0000F801, PPC_NONE, PPC2_ISA205),
10119 #if defined(TARGET_PPC64)
10120 GEN_HANDLER(popcntd, 0x1F, 0x1A, 0x0F, 0x0000F801, PPC_POPCNTWD),
10121 GEN_HANDLER(cntlzd, 0x1F, 0x1A, 0x01, 0x00000000, PPC_64B),
10122 GEN_HANDLER_E(prtyd, 0x1F, 0x1A, 0x05, 0x0000F801, PPC_NONE, PPC2_ISA205),
10123 GEN_HANDLER_E(bpermd, 0x1F, 0x1C, 0x07, 0x00000001, PPC_NONE, PPC2_PERM_ISA206),
10125 GEN_HANDLER(rlwimi, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
10126 GEN_HANDLER(rlwinm, 0x15, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
10127 GEN_HANDLER(rlwnm, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
10128 GEN_HANDLER(slw, 0x1F, 0x18, 0x00, 0x00000000, PPC_INTEGER),
10129 GEN_HANDLER(sraw, 0x1F, 0x18, 0x18, 0x00000000, PPC_INTEGER),
10130 GEN_HANDLER(srawi, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER),
10131 GEN_HANDLER(srw, 0x1F, 0x18, 0x10, 0x00000000, PPC_INTEGER),
10132 #if defined(TARGET_PPC64)
10133 GEN_HANDLER(sld, 0x1F, 0x1B, 0x00, 0x00000000, PPC_64B),
10134 GEN_HANDLER(srad, 0x1F, 0x1A, 0x18, 0x00000000, PPC_64B),
10135 GEN_HANDLER2(sradi0, "sradi", 0x1F, 0x1A, 0x19, 0x00000000, PPC_64B),
10136 GEN_HANDLER2(sradi1, "sradi", 0x1F, 0x1B, 0x19, 0x00000000, PPC_64B),
10137 GEN_HANDLER(srd, 0x1F, 0x1B, 0x10, 0x00000000, PPC_64B),
10139 GEN_HANDLER(frsqrtes, 0x3B, 0x1A, 0xFF, 0x001F07C0, PPC_FLOAT_FRSQRTES),
10140 GEN_HANDLER(fsqrt, 0x3F, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT),
10141 GEN_HANDLER(fsqrts, 0x3B, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT),
10142 GEN_HANDLER(fcmpo, 0x3F, 0x00, 0x01, 0x00600001, PPC_FLOAT),
10143 GEN_HANDLER(fcmpu, 0x3F, 0x00, 0x00, 0x00600001, PPC_FLOAT),
10144 GEN_HANDLER(fabs, 0x3F, 0x08, 0x08, 0x001F0000, PPC_FLOAT),
10145 GEN_HANDLER(fmr, 0x3F, 0x08, 0x02, 0x001F0000, PPC_FLOAT),
10146 GEN_HANDLER(fnabs, 0x3F, 0x08, 0x04, 0x001F0000, PPC_FLOAT),
10147 GEN_HANDLER(fneg, 0x3F, 0x08, 0x01, 0x001F0000, PPC_FLOAT),
10148 GEN_HANDLER_E(fcpsgn, 0x3F, 0x08, 0x00, 0x00000000, PPC_NONE, PPC2_ISA205),
10149 GEN_HANDLER_E(fmrgew, 0x3F, 0x06, 0x1E, 0x00000001, PPC_NONE, PPC2_VSX207),
10150 GEN_HANDLER_E(fmrgow, 0x3F, 0x06, 0x1A, 0x00000001, PPC_NONE, PPC2_VSX207),
10151 GEN_HANDLER(mcrfs, 0x3F, 0x00, 0x02, 0x0063F801, PPC_FLOAT),
10152 GEN_HANDLER(mffs, 0x3F, 0x07, 0x12, 0x001FF800, PPC_FLOAT),
10153 GEN_HANDLER(mtfsb0, 0x3F, 0x06, 0x02, 0x001FF800, PPC_FLOAT),
10154 GEN_HANDLER(mtfsb1, 0x3F, 0x06, 0x01, 0x001FF800, PPC_FLOAT),
10155 GEN_HANDLER(mtfsf, 0x3F, 0x07, 0x16, 0x00000000, PPC_FLOAT),
10156 GEN_HANDLER(mtfsfi, 0x3F, 0x06, 0x04, 0x006e0800, PPC_FLOAT),
10157 #if defined(TARGET_PPC64)
10158 GEN_HANDLER(ld, 0x3A, 0xFF, 0xFF, 0x00000000, PPC_64B),
10159 GEN_HANDLER(lq, 0x38, 0xFF, 0xFF, 0x00000000, PPC_64BX),
10160 GEN_HANDLER(std, 0x3E, 0xFF, 0xFF, 0x00000000, PPC_64B),
10162 GEN_HANDLER(lmw, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
10163 GEN_HANDLER(stmw, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
10164 GEN_HANDLER(lswi, 0x1F, 0x15, 0x12, 0x00000001, PPC_STRING),
10165 GEN_HANDLER(lswx, 0x1F, 0x15, 0x10, 0x00000001, PPC_STRING),
10166 GEN_HANDLER(stswi, 0x1F, 0x15, 0x16, 0x00000001, PPC_STRING),
10167 GEN_HANDLER(stswx, 0x1F, 0x15, 0x14, 0x00000001, PPC_STRING),
10168 GEN_HANDLER(eieio, 0x1F, 0x16, 0x1A, 0x03FFF801, PPC_MEM_EIEIO),
10169 GEN_HANDLER(isync, 0x13, 0x16, 0x04, 0x03FFF801, PPC_MEM),
10170 GEN_HANDLER_E(lbarx, 0x1F, 0x14, 0x01, 0, PPC_NONE, PPC2_ATOMIC_ISA206),
10171 GEN_HANDLER_E(lharx, 0x1F, 0x14, 0x03, 0, PPC_NONE, PPC2_ATOMIC_ISA206),
10172 GEN_HANDLER(lwarx, 0x1F, 0x14, 0x00, 0x00000000, PPC_RES),
10173 GEN_HANDLER_E(stbcx_, 0x1F, 0x16, 0x15, 0, PPC_NONE, PPC2_ATOMIC_ISA206),
10174 GEN_HANDLER_E(sthcx_, 0x1F, 0x16, 0x16, 0, PPC_NONE, PPC2_ATOMIC_ISA206),
10175 GEN_HANDLER2(stwcx_, "stwcx.", 0x1F, 0x16, 0x04, 0x00000000, PPC_RES),
10176 #if defined(TARGET_PPC64)
10177 GEN_HANDLER(ldarx, 0x1F, 0x14, 0x02, 0x00000000, PPC_64B),
10178 GEN_HANDLER_E(lqarx, 0x1F, 0x14, 0x08, 0, PPC_NONE, PPC2_LSQ_ISA207),
10179 GEN_HANDLER2(stdcx_, "stdcx.", 0x1F, 0x16, 0x06, 0x00000000, PPC_64B),
10180 GEN_HANDLER_E(stqcx_, 0x1F, 0x16, 0x05, 0, PPC_NONE, PPC2_LSQ_ISA207),
10182 GEN_HANDLER(sync, 0x1F, 0x16, 0x12, 0x039FF801, PPC_MEM_SYNC),
10183 GEN_HANDLER(wait, 0x1F, 0x1E, 0x01, 0x03FFF801, PPC_WAIT),
10184 GEN_HANDLER(b, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW),
10185 GEN_HANDLER(bc, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW),
10186 GEN_HANDLER(bcctr, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW),
10187 GEN_HANDLER(bclr, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW),
10188 GEN_HANDLER_E(bctar, 0x13, 0x10, 0x11, 0, PPC_NONE, PPC2_BCTAR_ISA207),
10189 GEN_HANDLER(mcrf, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER),
10190 GEN_HANDLER(rfi, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW),
10191 #if defined(TARGET_PPC64)
10192 GEN_HANDLER(rfid, 0x13, 0x12, 0x00, 0x03FF8001, PPC_64B),
10193 GEN_HANDLER(hrfid, 0x13, 0x12, 0x08, 0x03FF8001, PPC_64H),
10195 GEN_HANDLER(sc, 0x11, 0xFF, 0xFF, 0x03FFF01D, PPC_FLOW),
10196 GEN_HANDLER(tw, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW),
10197 GEN_HANDLER(twi, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW),
10198 #if defined(TARGET_PPC64)
10199 GEN_HANDLER(td, 0x1F, 0x04, 0x02, 0x00000001, PPC_64B),
10200 GEN_HANDLER(tdi, 0x02, 0xFF, 0xFF, 0x00000000, PPC_64B),
10202 GEN_HANDLER(mcrxr, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC),
10203 GEN_HANDLER(mfcr, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC),
10204 GEN_HANDLER(mfmsr, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC),
10205 GEN_HANDLER(mfspr, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC),
10206 GEN_HANDLER(mftb, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MFTB),
10207 GEN_HANDLER(mtcrf, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC),
10208 #if defined(TARGET_PPC64)
10209 GEN_HANDLER(mtmsrd, 0x1F, 0x12, 0x05, 0x001EF801, PPC_64B),
10211 GEN_HANDLER(mtmsr, 0x1F, 0x12, 0x04, 0x001FF801, PPC_MISC),
10212 GEN_HANDLER(mtspr, 0x1F, 0x13, 0x0E, 0x00000001, PPC_MISC),
10213 GEN_HANDLER(dcbf, 0x1F, 0x16, 0x02, 0x03C00001, PPC_CACHE),
10214 GEN_HANDLER(dcbi, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE),
10215 GEN_HANDLER(dcbst, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE),
10216 GEN_HANDLER(dcbt, 0x1F, 0x16, 0x08, 0x00000001, PPC_CACHE),
10217 GEN_HANDLER(dcbtst, 0x1F, 0x16, 0x07, 0x00000001, PPC_CACHE),
10218 GEN_HANDLER(dcbz, 0x1F, 0x16, 0x1F, 0x03C00001, PPC_CACHE_DCBZ),
10219 GEN_HANDLER(dst, 0x1F, 0x16, 0x0A, 0x01800001, PPC_ALTIVEC),
10220 GEN_HANDLER(dstst, 0x1F, 0x16, 0x0B, 0x02000001, PPC_ALTIVEC),
10221 GEN_HANDLER(dss, 0x1F, 0x16, 0x19, 0x019FF801, PPC_ALTIVEC),
10222 GEN_HANDLER(icbi, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE_ICBI),
10223 GEN_HANDLER(dcba, 0x1F, 0x16, 0x17, 0x03E00001, PPC_CACHE_DCBA),
10224 GEN_HANDLER(mfsr, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT),
10225 GEN_HANDLER(mfsrin, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT),
10226 GEN_HANDLER(mtsr, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT),
10227 GEN_HANDLER(mtsrin, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT),
10228 #if defined(TARGET_PPC64)
10229 GEN_HANDLER2(mfsr_64b, "mfsr", 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT_64B),
10230 GEN_HANDLER2(mfsrin_64b, "mfsrin", 0x1F, 0x13, 0x14, 0x001F0001,
10232 GEN_HANDLER2(mtsr_64b, "mtsr", 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT_64B),
10233 GEN_HANDLER2(mtsrin_64b, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001,
10235 GEN_HANDLER2(slbmte, "slbmte", 0x1F, 0x12, 0x0C, 0x001F0001, PPC_SEGMENT_64B),
10236 GEN_HANDLER2(slbmfee, "slbmfee", 0x1F, 0x13, 0x1C, 0x001F0001, PPC_SEGMENT_64B),
10237 GEN_HANDLER2(slbmfev, "slbmfev", 0x1F, 0x13, 0x1A, 0x001F0001, PPC_SEGMENT_64B),
10239 GEN_HANDLER(tlbia, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA),
10240 GEN_HANDLER(tlbiel, 0x1F, 0x12, 0x08, 0x03FF0001, PPC_MEM_TLBIE),
10241 GEN_HANDLER(tlbie, 0x1F, 0x12, 0x09, 0x03FF0001, PPC_MEM_TLBIE),
10242 GEN_HANDLER(tlbsync, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC),
10243 #if defined(TARGET_PPC64)
10244 GEN_HANDLER(slbia, 0x1F, 0x12, 0x0F, 0x03FFFC01, PPC_SLBI),
10245 GEN_HANDLER(slbie, 0x1F, 0x12, 0x0D, 0x03FF0001, PPC_SLBI),
10247 GEN_HANDLER(eciwx, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN),
10248 GEN_HANDLER(ecowx, 0x1F, 0x16, 0x09, 0x00000001, PPC_EXTERN),
10249 GEN_HANDLER(abs, 0x1F, 0x08, 0x0B, 0x0000F800, PPC_POWER_BR),
10250 GEN_HANDLER(abso, 0x1F, 0x08, 0x1B, 0x0000F800, PPC_POWER_BR),
10251 GEN_HANDLER(clcs, 0x1F, 0x10, 0x13, 0x0000F800, PPC_POWER_BR),
10252 GEN_HANDLER(div, 0x1F, 0x0B, 0x0A, 0x00000000, PPC_POWER_BR),
10253 GEN_HANDLER(divo, 0x1F, 0x0B, 0x1A, 0x00000000, PPC_POWER_BR),
10254 GEN_HANDLER(divs, 0x1F, 0x0B, 0x0B, 0x00000000, PPC_POWER_BR),
10255 GEN_HANDLER(divso, 0x1F, 0x0B, 0x1B, 0x00000000, PPC_POWER_BR),
10256 GEN_HANDLER(doz, 0x1F, 0x08, 0x08, 0x00000000, PPC_POWER_BR),
10257 GEN_HANDLER(dozo, 0x1F, 0x08, 0x18, 0x00000000, PPC_POWER_BR),
10258 GEN_HANDLER(dozi, 0x09, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR),
10259 GEN_HANDLER(lscbx, 0x1F, 0x15, 0x08, 0x00000000, PPC_POWER_BR),
10260 GEN_HANDLER(maskg, 0x1F, 0x1D, 0x00, 0x00000000, PPC_POWER_BR),
10261 GEN_HANDLER(maskir, 0x1F, 0x1D, 0x10, 0x00000000, PPC_POWER_BR),
10262 GEN_HANDLER(mul, 0x1F, 0x0B, 0x03, 0x00000000, PPC_POWER_BR),
10263 GEN_HANDLER(mulo, 0x1F, 0x0B, 0x13, 0x00000000, PPC_POWER_BR),
10264 GEN_HANDLER(nabs, 0x1F, 0x08, 0x0F, 0x00000000, PPC_POWER_BR),
10265 GEN_HANDLER(nabso, 0x1F, 0x08, 0x1F, 0x00000000, PPC_POWER_BR),
10266 GEN_HANDLER(rlmi, 0x16, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR),
10267 GEN_HANDLER(rrib, 0x1F, 0x19, 0x10, 0x00000000, PPC_POWER_BR),
10268 GEN_HANDLER(sle, 0x1F, 0x19, 0x04, 0x00000000, PPC_POWER_BR),
10269 GEN_HANDLER(sleq, 0x1F, 0x19, 0x06, 0x00000000, PPC_POWER_BR),
10270 GEN_HANDLER(sliq, 0x1F, 0x18, 0x05, 0x00000000, PPC_POWER_BR),
10271 GEN_HANDLER(slliq, 0x1F, 0x18, 0x07, 0x00000000, PPC_POWER_BR),
10272 GEN_HANDLER(sllq, 0x1F, 0x18, 0x06, 0x00000000, PPC_POWER_BR),
10273 GEN_HANDLER(slq, 0x1F, 0x18, 0x04, 0x00000000, PPC_POWER_BR),
10274 GEN_HANDLER(sraiq, 0x1F, 0x18, 0x1D, 0x00000000, PPC_POWER_BR),
10275 GEN_HANDLER(sraq, 0x1F, 0x18, 0x1C, 0x00000000, PPC_POWER_BR),
10276 GEN_HANDLER(sre, 0x1F, 0x19, 0x14, 0x00000000, PPC_POWER_BR),
10277 GEN_HANDLER(srea, 0x1F, 0x19, 0x1C, 0x00000000, PPC_POWER_BR),
10278 GEN_HANDLER(sreq, 0x1F, 0x19, 0x16, 0x00000000, PPC_POWER_BR),
10279 GEN_HANDLER(sriq, 0x1F, 0x18, 0x15, 0x00000000, PPC_POWER_BR),
10280 GEN_HANDLER(srliq, 0x1F, 0x18, 0x17, 0x00000000, PPC_POWER_BR),
10281 GEN_HANDLER(srlq, 0x1F, 0x18, 0x16, 0x00000000, PPC_POWER_BR),
10282 GEN_HANDLER(srq, 0x1F, 0x18, 0x14, 0x00000000, PPC_POWER_BR),
10283 GEN_HANDLER(dsa, 0x1F, 0x14, 0x13, 0x03FFF801, PPC_602_SPEC),
10284 GEN_HANDLER(esa, 0x1F, 0x14, 0x12, 0x03FFF801, PPC_602_SPEC),
10285 GEN_HANDLER(mfrom, 0x1F, 0x09, 0x08, 0x03E0F801, PPC_602_SPEC),
10286 GEN_HANDLER2(tlbld_6xx, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB),
10287 GEN_HANDLER2(tlbli_6xx, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_6xx_TLB),
10288 GEN_HANDLER2(tlbld_74xx, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_74xx_TLB),
10289 GEN_HANDLER2(tlbli_74xx, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_74xx_TLB),
10290 GEN_HANDLER(clf, 0x1F, 0x16, 0x03, 0x03E00000, PPC_POWER),
10291 GEN_HANDLER(cli, 0x1F, 0x16, 0x0F, 0x03E00000, PPC_POWER),
10292 GEN_HANDLER(dclst, 0x1F, 0x16, 0x13, 0x03E00000, PPC_POWER),
10293 GEN_HANDLER(mfsri, 0x1F, 0x13, 0x13, 0x00000001, PPC_POWER),
10294 GEN_HANDLER(rac, 0x1F, 0x12, 0x19, 0x00000001, PPC_POWER),
10295 GEN_HANDLER(rfsvc, 0x13, 0x12, 0x02, 0x03FFF0001, PPC_POWER),
10296 GEN_HANDLER(lfq, 0x38, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
10297 GEN_HANDLER(lfqu, 0x39, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
10298 GEN_HANDLER(lfqux, 0x1F, 0x17, 0x19, 0x00000001, PPC_POWER2),
10299 GEN_HANDLER(lfqx, 0x1F, 0x17, 0x18, 0x00000001, PPC_POWER2),
10300 GEN_HANDLER(stfq, 0x3C, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
10301 GEN_HANDLER(stfqu, 0x3D, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
10302 GEN_HANDLER(stfqux, 0x1F, 0x17, 0x1D, 0x00000001, PPC_POWER2),
10303 GEN_HANDLER(stfqx, 0x1F, 0x17, 0x1C, 0x00000001, PPC_POWER2),
10304 GEN_HANDLER(mfapidi, 0x1F, 0x13, 0x08, 0x0000F801, PPC_MFAPIDI),
10305 GEN_HANDLER(tlbiva, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_TLBIVA),
10306 GEN_HANDLER(mfdcr, 0x1F, 0x03, 0x0A, 0x00000001, PPC_DCR),
10307 GEN_HANDLER(mtdcr, 0x1F, 0x03, 0x0E, 0x00000001, PPC_DCR),
10308 GEN_HANDLER(mfdcrx, 0x1F, 0x03, 0x08, 0x00000000, PPC_DCRX),
10309 GEN_HANDLER(mtdcrx, 0x1F, 0x03, 0x0C, 0x00000000, PPC_DCRX),
10310 GEN_HANDLER(mfdcrux, 0x1F, 0x03, 0x09, 0x00000000, PPC_DCRUX),
10311 GEN_HANDLER(mtdcrux, 0x1F, 0x03, 0x0D, 0x00000000, PPC_DCRUX),
10312 GEN_HANDLER(dccci, 0x1F, 0x06, 0x0E, 0x03E00001, PPC_4xx_COMMON),
10313 GEN_HANDLER(dcread, 0x1F, 0x06, 0x0F, 0x00000001, PPC_4xx_COMMON),
10314 GEN_HANDLER2(icbt_40x, "icbt", 0x1F, 0x06, 0x08, 0x03E00001, PPC_40x_ICBT),
10315 GEN_HANDLER(iccci, 0x1F, 0x06, 0x1E, 0x00000001, PPC_4xx_COMMON),
10316 GEN_HANDLER(icread, 0x1F, 0x06, 0x1F, 0x03E00001, PPC_4xx_COMMON),
10317 GEN_HANDLER2(rfci_40x, "rfci", 0x13, 0x13, 0x01, 0x03FF8001, PPC_40x_EXCP),
10318 GEN_HANDLER_E(rfci, 0x13, 0x13, 0x01, 0x03FF8001, PPC_BOOKE, PPC2_BOOKE206),
10319 GEN_HANDLER(rfdi, 0x13, 0x07, 0x01, 0x03FF8001, PPC_RFDI),
10320 GEN_HANDLER(rfmci, 0x13, 0x06, 0x01, 0x03FF8001, PPC_RFMCI),
10321 GEN_HANDLER2(tlbre_40x, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_40x_TLB),
10322 GEN_HANDLER2(tlbsx_40x, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_40x_TLB),
10323 GEN_HANDLER2(tlbwe_40x, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_TLB),
10324 GEN_HANDLER2(tlbre_440, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_BOOKE),
10325 GEN_HANDLER2(tlbsx_440, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_BOOKE),
10326 GEN_HANDLER2(tlbwe_440, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_BOOKE),
10327 GEN_HANDLER2_E(tlbre_booke206, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001,
10328 PPC_NONE, PPC2_BOOKE206),
10329 GEN_HANDLER2_E(tlbsx_booke206, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000,
10330 PPC_NONE, PPC2_BOOKE206),
10331 GEN_HANDLER2_E(tlbwe_booke206, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001,
10332 PPC_NONE, PPC2_BOOKE206),
10333 GEN_HANDLER2_E(tlbivax_booke206, "tlbivax", 0x1F, 0x12, 0x18, 0x00000001,
10334 PPC_NONE, PPC2_BOOKE206),
10335 GEN_HANDLER2_E(tlbilx_booke206, "tlbilx", 0x1F, 0x12, 0x00, 0x03800001,
10336 PPC_NONE, PPC2_BOOKE206),
10337 GEN_HANDLER2_E(msgsnd, "msgsnd", 0x1F, 0x0E, 0x06, 0x03ff0001,
10338 PPC_NONE, PPC2_PRCNTL),
10339 GEN_HANDLER2_E(msgclr, "msgclr", 0x1F, 0x0E, 0x07, 0x03ff0001,
10340 PPC_NONE, PPC2_PRCNTL),
10341 GEN_HANDLER(wrtee, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_WRTEE),
10342 GEN_HANDLER(wrteei, 0x1F, 0x03, 0x05, 0x000E7C01, PPC_WRTEE),
10343 GEN_HANDLER(dlmzb, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC),
10344 GEN_HANDLER_E(mbar, 0x1F, 0x16, 0x1a, 0x001FF801,
10345 PPC_BOOKE, PPC2_BOOKE206),
10346 GEN_HANDLER(msync_4xx, 0x1F, 0x16, 0x12, 0x03FFF801, PPC_BOOKE),
10347 GEN_HANDLER2_E(icbt_440, "icbt", 0x1F, 0x16, 0x00, 0x03E00001,
10348 PPC_BOOKE, PPC2_BOOKE206),
10349 GEN_HANDLER(lvsl, 0x1f, 0x06, 0x00, 0x00000001, PPC_ALTIVEC),
10350 GEN_HANDLER(lvsr, 0x1f, 0x06, 0x01, 0x00000001, PPC_ALTIVEC),
10351 GEN_HANDLER(mfvscr, 0x04, 0x2, 0x18, 0x001ff800, PPC_ALTIVEC),
10352 GEN_HANDLER(mtvscr, 0x04, 0x2, 0x19, 0x03ff0000, PPC_ALTIVEC),
10353 GEN_HANDLER(vmladduhm, 0x04, 0x11, 0xFF, 0x00000000, PPC_ALTIVEC),
10354 GEN_HANDLER2(evsel0, "evsel", 0x04, 0x1c, 0x09, 0x00000000, PPC_SPE),
10355 GEN_HANDLER2(evsel1, "evsel", 0x04, 0x1d, 0x09, 0x00000000, PPC_SPE),
10356 GEN_HANDLER2(evsel2, "evsel", 0x04, 0x1e, 0x09, 0x00000000, PPC_SPE),
10357 GEN_HANDLER2(evsel3, "evsel", 0x04, 0x1f, 0x09, 0x00000000, PPC_SPE),
10359 #undef GEN_INT_ARITH_ADD
10360 #undef GEN_INT_ARITH_ADD_CONST
10361 #define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
10362 GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x00000000, PPC_INTEGER),
10363 #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
10364 add_ca, compute_ca, compute_ov) \
10365 GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x0000F800, PPC_INTEGER),
10366 GEN_INT_ARITH_ADD(add, 0x08, 0, 0, 0)
10367 GEN_INT_ARITH_ADD(addo, 0x18, 0, 0, 1)
10368 GEN_INT_ARITH_ADD(addc, 0x00, 0, 1, 0)
10369 GEN_INT_ARITH_ADD(addco, 0x10, 0, 1, 1)
10370 GEN_INT_ARITH_ADD(adde, 0x04, 1, 1, 0)
10371 GEN_INT_ARITH_ADD(addeo, 0x14, 1, 1, 1)
10372 GEN_INT_ARITH_ADD_CONST(addme, 0x07, -1LL, 1, 1, 0)
10373 GEN_INT_ARITH_ADD_CONST(addmeo, 0x17, -1LL, 1, 1, 1)
10374 GEN_INT_ARITH_ADD_CONST(addze, 0x06, 0, 1, 1, 0)
10375 GEN_INT_ARITH_ADD_CONST(addzeo, 0x16, 0, 1, 1, 1)
10377 #undef GEN_INT_ARITH_DIVW
10378 #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
10379 GEN_HANDLER(name, 0x1F, 0x0B, opc3, 0x00000000, PPC_INTEGER)
10380 GEN_INT_ARITH_DIVW(divwu, 0x0E, 0, 0),
10381 GEN_INT_ARITH_DIVW(divwuo, 0x1E, 0, 1),
10382 GEN_INT_ARITH_DIVW(divw, 0x0F, 1, 0),
10383 GEN_INT_ARITH_DIVW(divwo, 0x1F, 1, 1),
10384 GEN_HANDLER_E(divwe, 0x1F, 0x0B, 0x0D, 0, PPC_NONE, PPC2_DIVE_ISA206),
10385 GEN_HANDLER_E(divweo, 0x1F, 0x0B, 0x1D, 0, PPC_NONE, PPC2_DIVE_ISA206),
10386 GEN_HANDLER_E(divweu, 0x1F, 0x0B, 0x0C, 0, PPC_NONE, PPC2_DIVE_ISA206),
10387 GEN_HANDLER_E(divweuo, 0x1F, 0x0B, 0x1C, 0, PPC_NONE, PPC2_DIVE_ISA206),
10389 #if defined(TARGET_PPC64)
10390 #undef GEN_INT_ARITH_DIVD
10391 #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
10392 GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
10393 GEN_INT_ARITH_DIVD(divdu, 0x0E, 0, 0),
10394 GEN_INT_ARITH_DIVD(divduo, 0x1E, 0, 1),
10395 GEN_INT_ARITH_DIVD(divd, 0x0F, 1, 0),
10396 GEN_INT_ARITH_DIVD(divdo, 0x1F, 1, 1),
10398 GEN_HANDLER_E(divdeu, 0x1F, 0x09, 0x0C, 0, PPC_NONE, PPC2_DIVE_ISA206),
10399 GEN_HANDLER_E(divdeuo, 0x1F, 0x09, 0x1C, 0, PPC_NONE, PPC2_DIVE_ISA206),
10400 GEN_HANDLER_E(divde, 0x1F, 0x09, 0x0D, 0, PPC_NONE, PPC2_DIVE_ISA206),
10401 GEN_HANDLER_E(divdeo, 0x1F, 0x09, 0x1D, 0, PPC_NONE, PPC2_DIVE_ISA206),
10403 #undef GEN_INT_ARITH_MUL_HELPER
10404 #define GEN_INT_ARITH_MUL_HELPER(name, opc3) \
10405 GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
10406 GEN_INT_ARITH_MUL_HELPER(mulhdu, 0x00),
10407 GEN_INT_ARITH_MUL_HELPER(mulhd, 0x02),
10408 GEN_INT_ARITH_MUL_HELPER(mulldo, 0x17),
10411 #undef GEN_INT_ARITH_SUBF
10412 #undef GEN_INT_ARITH_SUBF_CONST
10413 #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
10414 GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x00000000, PPC_INTEGER),
10415 #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
10416 add_ca, compute_ca, compute_ov) \
10417 GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x0000F800, PPC_INTEGER),
10418 GEN_INT_ARITH_SUBF(subf, 0x01, 0, 0, 0)
10419 GEN_INT_ARITH_SUBF(subfo, 0x11, 0, 0, 1)
10420 GEN_INT_ARITH_SUBF(subfc, 0x00, 0, 1, 0)
10421 GEN_INT_ARITH_SUBF(subfco, 0x10, 0, 1, 1)
10422 GEN_INT_ARITH_SUBF(subfe, 0x04, 1, 1, 0)
10423 GEN_INT_ARITH_SUBF(subfeo, 0x14, 1, 1, 1)
10424 GEN_INT_ARITH_SUBF_CONST(subfme, 0x07, -1LL, 1, 1, 0)
10425 GEN_INT_ARITH_SUBF_CONST(subfmeo, 0x17, -1LL, 1, 1, 1)
10426 GEN_INT_ARITH_SUBF_CONST(subfze, 0x06, 0, 1, 1, 0)
10427 GEN_INT_ARITH_SUBF_CONST(subfzeo, 0x16, 0, 1, 1, 1)
10429 #undef GEN_LOGICAL1
10430 #undef GEN_LOGICAL2
10431 #define GEN_LOGICAL2(name, tcg_op, opc, type) \
10432 GEN_HANDLER(name, 0x1F, 0x1C, opc, 0x00000000, type)
10433 #define GEN_LOGICAL1(name, tcg_op, opc, type) \
10434 GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, type)
10435 GEN_LOGICAL2(and, tcg_gen_and_tl, 0x00, PPC_INTEGER),
10436 GEN_LOGICAL2(andc, tcg_gen_andc_tl, 0x01, PPC_INTEGER),
10437 GEN_LOGICAL2(eqv, tcg_gen_eqv_tl, 0x08, PPC_INTEGER),
10438 GEN_LOGICAL1(extsb, tcg_gen_ext8s_tl, 0x1D, PPC_INTEGER),
10439 GEN_LOGICAL1(extsh, tcg_gen_ext16s_tl, 0x1C, PPC_INTEGER),
10440 GEN_LOGICAL2(nand, tcg_gen_nand_tl, 0x0E, PPC_INTEGER),
10441 GEN_LOGICAL2(nor, tcg_gen_nor_tl, 0x03, PPC_INTEGER),
10442 GEN_LOGICAL2(orc, tcg_gen_orc_tl, 0x0C, PPC_INTEGER),
10443 #if defined(TARGET_PPC64)
10444 GEN_LOGICAL1(extsw, tcg_gen_ext32s_tl, 0x1E, PPC_64B),
10447 #if defined(TARGET_PPC64)
10448 #undef GEN_PPC64_R2
10449 #undef GEN_PPC64_R4
10450 #define GEN_PPC64_R2(name, opc1, opc2) \
10451 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
10452 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
10454 #define GEN_PPC64_R4(name, opc1, opc2) \
10455 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
10456 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x01, 0xFF, 0x00000000, \
10458 GEN_HANDLER2(name##2, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
10460 GEN_HANDLER2(name##3, stringify(name), opc1, opc2 | 0x11, 0xFF, 0x00000000, \
10462 GEN_PPC64_R4(rldicl, 0x1E, 0x00),
10463 GEN_PPC64_R4(rldicr, 0x1E, 0x02),
10464 GEN_PPC64_R4(rldic, 0x1E, 0x04),
10465 GEN_PPC64_R2(rldcl, 0x1E, 0x08),
10466 GEN_PPC64_R2(rldcr, 0x1E, 0x09),
10467 GEN_PPC64_R4(rldimi, 0x1E, 0x06),
10470 #undef _GEN_FLOAT_ACB
10471 #undef GEN_FLOAT_ACB
10472 #undef _GEN_FLOAT_AB
10473 #undef GEN_FLOAT_AB
10474 #undef _GEN_FLOAT_AC
10475 #undef GEN_FLOAT_AC
10477 #undef GEN_FLOAT_BS
10478 #define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
10479 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x00000000, type)
10480 #define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
10481 _GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type), \
10482 _GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type)
10483 #define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
10484 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type)
10485 #define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
10486 _GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type), \
10487 _GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type)
10488 #define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
10489 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type)
10490 #define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
10491 _GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type), \
10492 _GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type)
10493 #define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
10494 GEN_HANDLER(f##name, 0x3F, op2, op3, 0x001F0000, type)
10495 #define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
10496 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x001F07C0, type)
10498 GEN_FLOAT_AB(add, 0x15, 0x000007C0, 1, PPC_FLOAT),
10499 GEN_FLOAT_AB(div, 0x12, 0x000007C0, 1, PPC_FLOAT),
10500 GEN_FLOAT_AC(mul, 0x19, 0x0000F800, 1, PPC_FLOAT),
10501 GEN_FLOAT_BS(re, 0x3F, 0x18, 1, PPC_FLOAT_EXT),
10502 GEN_FLOAT_BS(res, 0x3B, 0x18, 1, PPC_FLOAT_FRES),
10503 GEN_FLOAT_BS(rsqrte, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE),
10504 _GEN_FLOAT_ACB(sel, sel, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL),
10505 GEN_FLOAT_AB(sub, 0x14, 0x000007C0, 1, PPC_FLOAT),
10506 GEN_FLOAT_ACB(madd, 0x1D, 1, PPC_FLOAT),
10507 GEN_FLOAT_ACB(msub, 0x1C, 1, PPC_FLOAT),
10508 GEN_FLOAT_ACB(nmadd, 0x1F, 1, PPC_FLOAT),
10509 GEN_FLOAT_ACB(nmsub, 0x1E, 1, PPC_FLOAT),
10510 GEN_HANDLER_E(ftdiv, 0x3F, 0x00, 0x04, 1, PPC_NONE, PPC2_FP_TST_ISA206),
10511 GEN_HANDLER_E(ftsqrt, 0x3F, 0x00, 0x05, 1, PPC_NONE, PPC2_FP_TST_ISA206),
10512 GEN_FLOAT_B(ctiw, 0x0E, 0x00, 0, PPC_FLOAT),
10513 GEN_HANDLER_E(fctiwu, 0x3F, 0x0E, 0x04, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
10514 GEN_FLOAT_B(ctiwz, 0x0F, 0x00, 0, PPC_FLOAT),
10515 GEN_HANDLER_E(fctiwuz, 0x3F, 0x0F, 0x04, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
10516 GEN_FLOAT_B(rsp, 0x0C, 0x00, 1, PPC_FLOAT),
10517 #if defined(TARGET_PPC64)
10518 GEN_FLOAT_B(cfid, 0x0E, 0x1A, 1, PPC_64B),
10519 GEN_HANDLER_E(fcfids, 0x3B, 0x0E, 0x1A, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
10520 GEN_HANDLER_E(fcfidu, 0x3F, 0x0E, 0x1E, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
10521 GEN_HANDLER_E(fcfidus, 0x3B, 0x0E, 0x1E, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
10522 GEN_FLOAT_B(ctid, 0x0E, 0x19, 0, PPC_64B),
10523 GEN_HANDLER_E(fctidu, 0x3F, 0x0E, 0x1D, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
10524 GEN_FLOAT_B(ctidz, 0x0F, 0x19, 0, PPC_64B),
10525 GEN_HANDLER_E(fctiduz, 0x3F, 0x0F, 0x1D, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
10527 GEN_FLOAT_B(rin, 0x08, 0x0C, 1, PPC_FLOAT_EXT),
10528 GEN_FLOAT_B(riz, 0x08, 0x0D, 1, PPC_FLOAT_EXT),
10529 GEN_FLOAT_B(rip, 0x08, 0x0E, 1, PPC_FLOAT_EXT),
10530 GEN_FLOAT_B(rim, 0x08, 0x0F, 1, PPC_FLOAT_EXT),
10537 #define GEN_LD(name, ldop, opc, type) \
10538 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
10539 #define GEN_LDU(name, ldop, opc, type) \
10540 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
10541 #define GEN_LDUX(name, ldop, opc2, opc3, type) \
10542 GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
10543 #define GEN_LDX_E(name, ldop, opc2, opc3, type, type2) \
10544 GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2),
10545 #define GEN_LDS(name, ldop, op, type) \
10546 GEN_LD(name, ldop, op | 0x20, type) \
10547 GEN_LDU(name, ldop, op | 0x21, type) \
10548 GEN_LDUX(name, ldop, 0x17, op | 0x01, type) \
10549 GEN_LDX(name, ldop, 0x17, op | 0x00, type)
10551 GEN_LDS(lbz, ld8u, 0x02, PPC_INTEGER)
10552 GEN_LDS(lha, ld16s, 0x0A, PPC_INTEGER)
10553 GEN_LDS(lhz, ld16u, 0x08, PPC_INTEGER)
10554 GEN_LDS(lwz, ld32u, 0x00, PPC_INTEGER)
10555 #if defined(TARGET_PPC64)
10556 GEN_LDUX(lwa, ld32s, 0x15, 0x0B, PPC_64B)
10557 GEN_LDX(lwa, ld32s, 0x15, 0x0A, PPC_64B)
10558 GEN_LDUX(ld, ld64, 0x15, 0x01, PPC_64B)
10559 GEN_LDX(ld, ld64, 0x15, 0x00, PPC_64B)
10560 GEN_LDX_E(ldbr, ld64ur, 0x14, 0x10, PPC_NONE, PPC2_DBRX)
10562 GEN_LDX(lhbr, ld16ur, 0x16, 0x18, PPC_INTEGER)
10563 GEN_LDX(lwbr, ld32ur, 0x16, 0x10, PPC_INTEGER)
10570 #define GEN_ST(name, stop, opc, type) \
10571 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
10572 #define GEN_STU(name, stop, opc, type) \
10573 GEN_HANDLER(stop##u, opc, 0xFF, 0xFF, 0x00000000, type),
10574 #define GEN_STUX(name, stop, opc2, opc3, type) \
10575 GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
10576 #define GEN_STX_E(name, stop, opc2, opc3, type, type2) \
10577 GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2),
10578 #define GEN_STS(name, stop, op, type) \
10579 GEN_ST(name, stop, op | 0x20, type) \
10580 GEN_STU(name, stop, op | 0x21, type) \
10581 GEN_STUX(name, stop, 0x17, op | 0x01, type) \
10582 GEN_STX(name, stop, 0x17, op | 0x00, type)
10584 GEN_STS(stb, st8, 0x06, PPC_INTEGER)
10585 GEN_STS(sth, st16, 0x0C, PPC_INTEGER)
10586 GEN_STS(stw, st32, 0x04, PPC_INTEGER)
10587 #if defined(TARGET_PPC64)
10588 GEN_STUX(std, st64, 0x15, 0x05, PPC_64B)
10589 GEN_STX(std, st64, 0x15, 0x04, PPC_64B)
10590 GEN_STX_E(stdbr, st64r, 0x14, 0x14, PPC_NONE, PPC2_DBRX)
10592 GEN_STX(sthbr, st16r, 0x16, 0x1C, PPC_INTEGER)
10593 GEN_STX(stwbr, st32r, 0x16, 0x14, PPC_INTEGER)
10600 #define GEN_LDF(name, ldop, opc, type) \
10601 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
10602 #define GEN_LDUF(name, ldop, opc, type) \
10603 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
10604 #define GEN_LDUXF(name, ldop, opc, type) \
10605 GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type),
10606 #define GEN_LDXF(name, ldop, opc2, opc3, type) \
10607 GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
10608 #define GEN_LDFS(name, ldop, op, type) \
10609 GEN_LDF(name, ldop, op | 0x20, type) \
10610 GEN_LDUF(name, ldop, op | 0x21, type) \
10611 GEN_LDUXF(name, ldop, op | 0x01, type) \
10612 GEN_LDXF(name, ldop, 0x17, op | 0x00, type)
10614 GEN_LDFS(lfd, ld64, 0x12, PPC_FLOAT)
10615 GEN_LDFS(lfs, ld32fs, 0x10, PPC_FLOAT)
10616 GEN_HANDLER_E(lfiwax, 0x1f, 0x17, 0x1a, 0x00000001, PPC_NONE, PPC2_ISA205),
10617 GEN_HANDLER_E(lfiwzx, 0x1f, 0x17, 0x1b, 0x1, PPC_NONE, PPC2_FP_CVT_ISA206),
10618 GEN_HANDLER_E(lfdp, 0x39, 0xFF, 0xFF, 0x00200003, PPC_NONE, PPC2_ISA205),
10619 GEN_HANDLER_E(lfdpx, 0x1F, 0x17, 0x18, 0x00200001, PPC_NONE, PPC2_ISA205),
10626 #define GEN_STF(name, stop, opc, type) \
10627 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
10628 #define GEN_STUF(name, stop, opc, type) \
10629 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
10630 #define GEN_STUXF(name, stop, opc, type) \
10631 GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type),
10632 #define GEN_STXF(name, stop, opc2, opc3, type) \
10633 GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
10634 #define GEN_STFS(name, stop, op, type) \
10635 GEN_STF(name, stop, op | 0x20, type) \
10636 GEN_STUF(name, stop, op | 0x21, type) \
10637 GEN_STUXF(name, stop, op | 0x01, type) \
10638 GEN_STXF(name, stop, 0x17, op | 0x00, type)
10640 GEN_STFS(stfd, st64, 0x16, PPC_FLOAT)
10641 GEN_STFS(stfs, st32fs, 0x14, PPC_FLOAT)
10642 GEN_STXF(stfiw, st32fiw, 0x17, 0x1E, PPC_FLOAT_STFIWX)
10643 GEN_HANDLER_E(stfdp, 0x3D, 0xFF, 0xFF, 0x00200003, PPC_NONE, PPC2_ISA205),
10644 GEN_HANDLER_E(stfdpx, 0x1F, 0x17, 0x1C, 0x00200001, PPC_NONE, PPC2_ISA205),
10647 #define GEN_CRLOGIC(name, tcg_op, opc) \
10648 GEN_HANDLER(name, 0x13, 0x01, opc, 0x00000001, PPC_INTEGER)
10649 GEN_CRLOGIC(crand, tcg_gen_and_i32, 0x08),
10650 GEN_CRLOGIC(crandc, tcg_gen_andc_i32, 0x04),
10651 GEN_CRLOGIC(creqv, tcg_gen_eqv_i32, 0x09),
10652 GEN_CRLOGIC(crnand, tcg_gen_nand_i32, 0x07),
10653 GEN_CRLOGIC(crnor, tcg_gen_nor_i32, 0x01),
10654 GEN_CRLOGIC(cror, tcg_gen_or_i32, 0x0E),
10655 GEN_CRLOGIC(crorc, tcg_gen_orc_i32, 0x0D),
10656 GEN_CRLOGIC(crxor, tcg_gen_xor_i32, 0x06),
10658 #undef GEN_MAC_HANDLER
10659 #define GEN_MAC_HANDLER(name, opc2, opc3) \
10660 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_405_MAC)
10661 GEN_MAC_HANDLER(macchw, 0x0C, 0x05),
10662 GEN_MAC_HANDLER(macchwo, 0x0C, 0x15),
10663 GEN_MAC_HANDLER(macchws, 0x0C, 0x07),
10664 GEN_MAC_HANDLER(macchwso, 0x0C, 0x17),
10665 GEN_MAC_HANDLER(macchwsu, 0x0C, 0x06),
10666 GEN_MAC_HANDLER(macchwsuo, 0x0C, 0x16),
10667 GEN_MAC_HANDLER(macchwu, 0x0C, 0x04),
10668 GEN_MAC_HANDLER(macchwuo, 0x0C, 0x14),
10669 GEN_MAC_HANDLER(machhw, 0x0C, 0x01),
10670 GEN_MAC_HANDLER(machhwo, 0x0C, 0x11),
10671 GEN_MAC_HANDLER(machhws, 0x0C, 0x03),
10672 GEN_MAC_HANDLER(machhwso, 0x0C, 0x13),
10673 GEN_MAC_HANDLER(machhwsu, 0x0C, 0x02),
10674 GEN_MAC_HANDLER(machhwsuo, 0x0C, 0x12),
10675 GEN_MAC_HANDLER(machhwu, 0x0C, 0x00),
10676 GEN_MAC_HANDLER(machhwuo, 0x0C, 0x10),
10677 GEN_MAC_HANDLER(maclhw, 0x0C, 0x0D),
10678 GEN_MAC_HANDLER(maclhwo, 0x0C, 0x1D),
10679 GEN_MAC_HANDLER(maclhws, 0x0C, 0x0F),
10680 GEN_MAC_HANDLER(maclhwso, 0x0C, 0x1F),
10681 GEN_MAC_HANDLER(maclhwu, 0x0C, 0x0C),
10682 GEN_MAC_HANDLER(maclhwuo, 0x0C, 0x1C),
10683 GEN_MAC_HANDLER(maclhwsu, 0x0C, 0x0E),
10684 GEN_MAC_HANDLER(maclhwsuo, 0x0C, 0x1E),
10685 GEN_MAC_HANDLER(nmacchw, 0x0E, 0x05),
10686 GEN_MAC_HANDLER(nmacchwo, 0x0E, 0x15),
10687 GEN_MAC_HANDLER(nmacchws, 0x0E, 0x07),
10688 GEN_MAC_HANDLER(nmacchwso, 0x0E, 0x17),
10689 GEN_MAC_HANDLER(nmachhw, 0x0E, 0x01),
10690 GEN_MAC_HANDLER(nmachhwo, 0x0E, 0x11),
10691 GEN_MAC_HANDLER(nmachhws, 0x0E, 0x03),
10692 GEN_MAC_HANDLER(nmachhwso, 0x0E, 0x13),
10693 GEN_MAC_HANDLER(nmaclhw, 0x0E, 0x0D),
10694 GEN_MAC_HANDLER(nmaclhwo, 0x0E, 0x1D),
10695 GEN_MAC_HANDLER(nmaclhws, 0x0E, 0x0F),
10696 GEN_MAC_HANDLER(nmaclhwso, 0x0E, 0x1F),
10697 GEN_MAC_HANDLER(mulchw, 0x08, 0x05),
10698 GEN_MAC_HANDLER(mulchwu, 0x08, 0x04),
10699 GEN_MAC_HANDLER(mulhhw, 0x08, 0x01),
10700 GEN_MAC_HANDLER(mulhhwu, 0x08, 0x00),
10701 GEN_MAC_HANDLER(mullhw, 0x08, 0x0D),
10702 GEN_MAC_HANDLER(mullhwu, 0x08, 0x0C),
10708 #define GEN_VR_LDX(name, opc2, opc3) \
10709 GEN_HANDLER(name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10710 #define GEN_VR_STX(name, opc2, opc3) \
10711 GEN_HANDLER(st##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10712 #define GEN_VR_LVE(name, opc2, opc3) \
10713 GEN_HANDLER(lve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10714 #define GEN_VR_STVE(name, opc2, opc3) \
10715 GEN_HANDLER(stve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10716 GEN_VR_LDX(lvx, 0x07, 0x03),
10717 GEN_VR_LDX(lvxl, 0x07, 0x0B),
10718 GEN_VR_LVE(bx, 0x07, 0x00),
10719 GEN_VR_LVE(hx, 0x07, 0x01),
10720 GEN_VR_LVE(wx, 0x07, 0x02),
10721 GEN_VR_STX(svx, 0x07, 0x07),
10722 GEN_VR_STX(svxl, 0x07, 0x0F),
10723 GEN_VR_STVE(bx, 0x07, 0x04),
10724 GEN_VR_STVE(hx, 0x07, 0x05),
10725 GEN_VR_STVE(wx, 0x07, 0x06),
10727 #undef GEN_VX_LOGICAL
10728 #define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \
10729 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
10731 #undef GEN_VX_LOGICAL_207
10732 #define GEN_VX_LOGICAL_207(name, tcg_op, opc2, opc3) \
10733 GEN_HANDLER_E(name, 0x04, opc2, opc3, 0x00000000, PPC_NONE, PPC2_ALTIVEC_207)
10735 GEN_VX_LOGICAL(vand, tcg_gen_and_i64, 2, 16),
10736 GEN_VX_LOGICAL(vandc, tcg_gen_andc_i64, 2, 17),
10737 GEN_VX_LOGICAL(vor, tcg_gen_or_i64, 2, 18),
10738 GEN_VX_LOGICAL(vxor, tcg_gen_xor_i64, 2, 19),
10739 GEN_VX_LOGICAL(vnor, tcg_gen_nor_i64, 2, 20),
10740 GEN_VX_LOGICAL_207(veqv, tcg_gen_eqv_i64, 2, 26),
10741 GEN_VX_LOGICAL_207(vnand, tcg_gen_nand_i64, 2, 22),
10742 GEN_VX_LOGICAL_207(vorc, tcg_gen_orc_i64, 2, 21),
10745 #define GEN_VXFORM(name, opc2, opc3) \
10746 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
10748 #undef GEN_VXFORM_207
10749 #define GEN_VXFORM_207(name, opc2, opc3) \
10750 GEN_HANDLER_E(name, 0x04, opc2, opc3, 0x00000000, PPC_NONE, PPC2_ALTIVEC_207)
10752 #undef GEN_VXFORM_DUAL
10753 #define GEN_VXFORM_DUAL(name0, name1, opc2, opc3, type0, type1) \
10754 GEN_HANDLER_E(name0##_##name1, 0x4, opc2, opc3, 0x00000000, type0, type1)
10756 #undef GEN_VXRFORM_DUAL
10757 #define GEN_VXRFORM_DUAL(name0, name1, opc2, opc3, tp0, tp1) \
10758 GEN_HANDLER_E(name0##_##name1, 0x4, opc2, opc3, 0x00000000, tp0, tp1), \
10759 GEN_HANDLER_E(name0##_##name1, 0x4, opc2, (opc3 | 0x10), 0x00000000, tp0, tp1),
10761 GEN_VXFORM(vaddubm, 0, 0),
10762 GEN_VXFORM(vadduhm, 0, 1),
10763 GEN_VXFORM(vadduwm, 0, 2),
10764 GEN_VXFORM_207(vaddudm, 0, 3),
10765 GEN_VXFORM_DUAL(vsububm, bcdadd, 0, 16, PPC_ALTIVEC, PPC_NONE),
10766 GEN_VXFORM_DUAL(vsubuhm, bcdsub, 0, 17, PPC_ALTIVEC, PPC_NONE),
10767 GEN_VXFORM(vsubuwm, 0, 18),
10768 GEN_VXFORM_207(vsubudm, 0, 19),
10769 GEN_VXFORM(vmaxub, 1, 0),
10770 GEN_VXFORM(vmaxuh, 1, 1),
10771 GEN_VXFORM(vmaxuw, 1, 2),
10772 GEN_VXFORM_207(vmaxud, 1, 3),
10773 GEN_VXFORM(vmaxsb, 1, 4),
10774 GEN_VXFORM(vmaxsh, 1, 5),
10775 GEN_VXFORM(vmaxsw, 1, 6),
10776 GEN_VXFORM_207(vmaxsd, 1, 7),
10777 GEN_VXFORM(vminub, 1, 8),
10778 GEN_VXFORM(vminuh, 1, 9),
10779 GEN_VXFORM(vminuw, 1, 10),
10780 GEN_VXFORM_207(vminud, 1, 11),
10781 GEN_VXFORM(vminsb, 1, 12),
10782 GEN_VXFORM(vminsh, 1, 13),
10783 GEN_VXFORM(vminsw, 1, 14),
10784 GEN_VXFORM_207(vminsd, 1, 15),
10785 GEN_VXFORM(vavgub, 1, 16),
10786 GEN_VXFORM(vavguh, 1, 17),
10787 GEN_VXFORM(vavguw, 1, 18),
10788 GEN_VXFORM(vavgsb, 1, 20),
10789 GEN_VXFORM(vavgsh, 1, 21),
10790 GEN_VXFORM(vavgsw, 1, 22),
10791 GEN_VXFORM(vmrghb, 6, 0),
10792 GEN_VXFORM(vmrghh, 6, 1),
10793 GEN_VXFORM(vmrghw, 6, 2),
10794 GEN_VXFORM(vmrglb, 6, 4),
10795 GEN_VXFORM(vmrglh, 6, 5),
10796 GEN_VXFORM(vmrglw, 6, 6),
10797 GEN_VXFORM_207(vmrgew, 6, 30),
10798 GEN_VXFORM_207(vmrgow, 6, 26),
10799 GEN_VXFORM(vmuloub, 4, 0),
10800 GEN_VXFORM(vmulouh, 4, 1),
10801 GEN_VXFORM_DUAL(vmulouw, vmuluwm, 4, 2, PPC_ALTIVEC, PPC_NONE),
10802 GEN_VXFORM(vmulosb, 4, 4),
10803 GEN_VXFORM(vmulosh, 4, 5),
10804 GEN_VXFORM_207(vmulosw, 4, 6),
10805 GEN_VXFORM(vmuleub, 4, 8),
10806 GEN_VXFORM(vmuleuh, 4, 9),
10807 GEN_VXFORM_207(vmuleuw, 4, 10),
10808 GEN_VXFORM(vmulesb, 4, 12),
10809 GEN_VXFORM(vmulesh, 4, 13),
10810 GEN_VXFORM_207(vmulesw, 4, 14),
10811 GEN_VXFORM(vslb, 2, 4),
10812 GEN_VXFORM(vslh, 2, 5),
10813 GEN_VXFORM(vslw, 2, 6),
10814 GEN_VXFORM_207(vsld, 2, 23),
10815 GEN_VXFORM(vsrb, 2, 8),
10816 GEN_VXFORM(vsrh, 2, 9),
10817 GEN_VXFORM(vsrw, 2, 10),
10818 GEN_VXFORM_207(vsrd, 2, 27),
10819 GEN_VXFORM(vsrab, 2, 12),
10820 GEN_VXFORM(vsrah, 2, 13),
10821 GEN_VXFORM(vsraw, 2, 14),
10822 GEN_VXFORM_207(vsrad, 2, 15),
10823 GEN_VXFORM(vslo, 6, 16),
10824 GEN_VXFORM(vsro, 6, 17),
10825 GEN_VXFORM(vaddcuw, 0, 6),
10826 GEN_VXFORM(vsubcuw, 0, 22),
10827 GEN_VXFORM(vaddubs, 0, 8),
10828 GEN_VXFORM(vadduhs, 0, 9),
10829 GEN_VXFORM(vadduws, 0, 10),
10830 GEN_VXFORM(vaddsbs, 0, 12),
10831 GEN_VXFORM(vaddshs, 0, 13),
10832 GEN_VXFORM(vaddsws, 0, 14),
10833 GEN_VXFORM_DUAL(vsububs, bcdadd, 0, 24, PPC_ALTIVEC, PPC_NONE),
10834 GEN_VXFORM_DUAL(vsubuhs, bcdsub, 0, 25, PPC_ALTIVEC, PPC_NONE),
10835 GEN_VXFORM(vsubuws, 0, 26),
10836 GEN_VXFORM(vsubsbs, 0, 28),
10837 GEN_VXFORM(vsubshs, 0, 29),
10838 GEN_VXFORM(vsubsws, 0, 30),
10839 GEN_VXFORM_207(vadduqm, 0, 4),
10840 GEN_VXFORM_207(vaddcuq, 0, 5),
10841 GEN_VXFORM_DUAL(vaddeuqm, vaddecuq, 30, 0xFF, PPC_NONE, PPC2_ALTIVEC_207),
10842 GEN_VXFORM_207(vsubuqm, 0, 20),
10843 GEN_VXFORM_207(vsubcuq, 0, 21),
10844 GEN_VXFORM_DUAL(vsubeuqm, vsubecuq, 31, 0xFF, PPC_NONE, PPC2_ALTIVEC_207),
10845 GEN_VXFORM(vrlb, 2, 0),
10846 GEN_VXFORM(vrlh, 2, 1),
10847 GEN_VXFORM(vrlw, 2, 2),
10848 GEN_VXFORM_207(vrld, 2, 3),
10849 GEN_VXFORM(vsl, 2, 7),
10850 GEN_VXFORM(vsr, 2, 11),
10851 GEN_VXFORM(vpkuhum, 7, 0),
10852 GEN_VXFORM(vpkuwum, 7, 1),
10853 GEN_VXFORM_207(vpkudum, 7, 17),
10854 GEN_VXFORM(vpkuhus, 7, 2),
10855 GEN_VXFORM(vpkuwus, 7, 3),
10856 GEN_VXFORM_207(vpkudus, 7, 19),
10857 GEN_VXFORM(vpkshus, 7, 4),
10858 GEN_VXFORM(vpkswus, 7, 5),
10859 GEN_VXFORM_207(vpksdus, 7, 21),
10860 GEN_VXFORM(vpkshss, 7, 6),
10861 GEN_VXFORM(vpkswss, 7, 7),
10862 GEN_VXFORM_207(vpksdss, 7, 23),
10863 GEN_VXFORM(vpkpx, 7, 12),
10864 GEN_VXFORM(vsum4ubs, 4, 24),
10865 GEN_VXFORM(vsum4sbs, 4, 28),
10866 GEN_VXFORM(vsum4shs, 4, 25),
10867 GEN_VXFORM(vsum2sws, 4, 26),
10868 GEN_VXFORM(vsumsws, 4, 30),
10869 GEN_VXFORM(vaddfp, 5, 0),
10870 GEN_VXFORM(vsubfp, 5, 1),
10871 GEN_VXFORM(vmaxfp, 5, 16),
10872 GEN_VXFORM(vminfp, 5, 17),
10874 #undef GEN_VXRFORM1
10876 #define GEN_VXRFORM1(opname, name, str, opc2, opc3) \
10877 GEN_HANDLER2(name, str, 0x4, opc2, opc3, 0x00000000, PPC_ALTIVEC),
10878 #define GEN_VXRFORM(name, opc2, opc3) \
10879 GEN_VXRFORM1(name, name, #name, opc2, opc3) \
10880 GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4)))
10881 GEN_VXRFORM(vcmpequb, 3, 0)
10882 GEN_VXRFORM(vcmpequh, 3, 1)
10883 GEN_VXRFORM(vcmpequw, 3, 2)
10884 GEN_VXRFORM(vcmpgtsb, 3, 12)
10885 GEN_VXRFORM(vcmpgtsh, 3, 13)
10886 GEN_VXRFORM(vcmpgtsw, 3, 14)
10887 GEN_VXRFORM(vcmpgtub, 3, 8)
10888 GEN_VXRFORM(vcmpgtuh, 3, 9)
10889 GEN_VXRFORM(vcmpgtuw, 3, 10)
10890 GEN_VXRFORM_DUAL(vcmpeqfp, vcmpequd, 3, 3, PPC_ALTIVEC, PPC_NONE)
10891 GEN_VXRFORM(vcmpgefp, 3, 7)
10892 GEN_VXRFORM_DUAL(vcmpgtfp, vcmpgtud, 3, 11, PPC_ALTIVEC, PPC_NONE)
10893 GEN_VXRFORM_DUAL(vcmpbfp, vcmpgtsd, 3, 15, PPC_ALTIVEC, PPC_NONE)
10895 #undef GEN_VXFORM_SIMM
10896 #define GEN_VXFORM_SIMM(name, opc2, opc3) \
10897 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
10898 GEN_VXFORM_SIMM(vspltisb, 6, 12),
10899 GEN_VXFORM_SIMM(vspltish, 6, 13),
10900 GEN_VXFORM_SIMM(vspltisw, 6, 14),
10902 #undef GEN_VXFORM_NOA
10903 #define GEN_VXFORM_NOA(name, opc2, opc3) \
10904 GEN_HANDLER(name, 0x04, opc2, opc3, 0x001f0000, PPC_ALTIVEC)
10905 GEN_VXFORM_NOA(vupkhsb, 7, 8),
10906 GEN_VXFORM_NOA(vupkhsh, 7, 9),
10907 GEN_VXFORM_207(vupkhsw, 7, 25),
10908 GEN_VXFORM_NOA(vupklsb, 7, 10),
10909 GEN_VXFORM_NOA(vupklsh, 7, 11),
10910 GEN_VXFORM_207(vupklsw, 7, 27),
10911 GEN_VXFORM_NOA(vupkhpx, 7, 13),
10912 GEN_VXFORM_NOA(vupklpx, 7, 15),
10913 GEN_VXFORM_NOA(vrefp, 5, 4),
10914 GEN_VXFORM_NOA(vrsqrtefp, 5, 5),
10915 GEN_VXFORM_NOA(vexptefp, 5, 6),
10916 GEN_VXFORM_NOA(vlogefp, 5, 7),
10917 GEN_VXFORM_NOA(vrfim, 5, 8),
10918 GEN_VXFORM_NOA(vrfin, 5, 9),
10919 GEN_VXFORM_NOA(vrfip, 5, 10),
10920 GEN_VXFORM_NOA(vrfiz, 5, 11),
10922 #undef GEN_VXFORM_UIMM
10923 #define GEN_VXFORM_UIMM(name, opc2, opc3) \
10924 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
10925 GEN_VXFORM_UIMM(vspltb, 6, 8),
10926 GEN_VXFORM_UIMM(vsplth, 6, 9),
10927 GEN_VXFORM_UIMM(vspltw, 6, 10),
10928 GEN_VXFORM_UIMM(vcfux, 5, 12),
10929 GEN_VXFORM_UIMM(vcfsx, 5, 13),
10930 GEN_VXFORM_UIMM(vctuxs, 5, 14),
10931 GEN_VXFORM_UIMM(vctsxs, 5, 15),
10933 #undef GEN_VAFORM_PAIRED
10934 #define GEN_VAFORM_PAIRED(name0, name1, opc2) \
10935 GEN_HANDLER(name0##_##name1, 0x04, opc2, 0xFF, 0x00000000, PPC_ALTIVEC)
10936 GEN_VAFORM_PAIRED(vmhaddshs, vmhraddshs, 16),
10937 GEN_VAFORM_PAIRED(vmsumubm, vmsummbm, 18),
10938 GEN_VAFORM_PAIRED(vmsumuhm, vmsumuhs, 19),
10939 GEN_VAFORM_PAIRED(vmsumshm, vmsumshs, 20),
10940 GEN_VAFORM_PAIRED(vsel, vperm, 21),
10941 GEN_VAFORM_PAIRED(vmaddfp, vnmsubfp, 23),
10943 GEN_VXFORM_DUAL(vclzb, vpopcntb, 1, 28, PPC_NONE, PPC2_ALTIVEC_207),
10944 GEN_VXFORM_DUAL(vclzh, vpopcnth, 1, 29, PPC_NONE, PPC2_ALTIVEC_207),
10945 GEN_VXFORM_DUAL(vclzw, vpopcntw, 1, 30, PPC_NONE, PPC2_ALTIVEC_207),
10946 GEN_VXFORM_DUAL(vclzd, vpopcntd, 1, 31, PPC_NONE, PPC2_ALTIVEC_207),
10948 GEN_VXFORM_207(vbpermq, 6, 21),
10949 GEN_VXFORM_207(vgbbd, 6, 20),
10950 GEN_VXFORM_207(vpmsumb, 4, 16),
10951 GEN_VXFORM_207(vpmsumh, 4, 17),
10952 GEN_VXFORM_207(vpmsumw, 4, 18),
10953 GEN_VXFORM_207(vpmsumd, 4, 19),
10955 GEN_VXFORM_207(vsbox, 4, 23),
10957 GEN_VXFORM_DUAL(vcipher, vcipherlast, 4, 20, PPC_NONE, PPC2_ALTIVEC_207),
10958 GEN_VXFORM_DUAL(vncipher, vncipherlast, 4, 21, PPC_NONE, PPC2_ALTIVEC_207),
10960 GEN_VXFORM_207(vshasigmaw, 1, 26),
10961 GEN_VXFORM_207(vshasigmad, 1, 27),
10963 GEN_VXFORM_DUAL(vsldoi, vpermxor, 22, 0xFF, PPC_ALTIVEC, PPC_NONE),
10965 GEN_HANDLER_E(lxsdx, 0x1F, 0x0C, 0x12, 0, PPC_NONE, PPC2_VSX),
10966 GEN_HANDLER_E(lxsiwax, 0x1F, 0x0C, 0x02, 0, PPC_NONE, PPC2_VSX207),
10967 GEN_HANDLER_E(lxsiwzx, 0x1F, 0x0C, 0x00, 0, PPC_NONE, PPC2_VSX207),
10968 GEN_HANDLER_E(lxsspx, 0x1F, 0x0C, 0x10, 0, PPC_NONE, PPC2_VSX207),
10969 GEN_HANDLER_E(lxvd2x, 0x1F, 0x0C, 0x1A, 0, PPC_NONE, PPC2_VSX),
10970 GEN_HANDLER_E(lxvdsx, 0x1F, 0x0C, 0x0A, 0, PPC_NONE, PPC2_VSX),
10971 GEN_HANDLER_E(lxvw4x, 0x1F, 0x0C, 0x18, 0, PPC_NONE, PPC2_VSX),
10973 GEN_HANDLER_E(stxsdx, 0x1F, 0xC, 0x16, 0, PPC_NONE, PPC2_VSX),
10974 GEN_HANDLER_E(stxsiwx, 0x1F, 0xC, 0x04, 0, PPC_NONE, PPC2_VSX207),
10975 GEN_HANDLER_E(stxsspx, 0x1F, 0xC, 0x14, 0, PPC_NONE, PPC2_VSX207),
10976 GEN_HANDLER_E(stxvd2x, 0x1F, 0xC, 0x1E, 0, PPC_NONE, PPC2_VSX),
10977 GEN_HANDLER_E(stxvw4x, 0x1F, 0xC, 0x1C, 0, PPC_NONE, PPC2_VSX),
10979 GEN_HANDLER_E(mfvsrwz, 0x1F, 0x13, 0x03, 0x0000F800, PPC_NONE, PPC2_VSX207),
10980 GEN_HANDLER_E(mtvsrwa, 0x1F, 0x13, 0x06, 0x0000F800, PPC_NONE, PPC2_VSX207),
10981 GEN_HANDLER_E(mtvsrwz, 0x1F, 0x13, 0x07, 0x0000F800, PPC_NONE, PPC2_VSX207),
10982 #if defined(TARGET_PPC64)
10983 GEN_HANDLER_E(mfvsrd, 0x1F, 0x13, 0x01, 0x0000F800, PPC_NONE, PPC2_VSX207),
10984 GEN_HANDLER_E(mtvsrd, 0x1F, 0x13, 0x05, 0x0000F800, PPC_NONE, PPC2_VSX207),
10988 #define GEN_XX2FORM(name, opc2, opc3, fl2) \
10989 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0, opc3, 0, PPC_NONE, fl2), \
10990 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 1, opc3, 0, PPC_NONE, fl2)
10993 #define GEN_XX3FORM(name, opc2, opc3, fl2) \
10994 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0, opc3, 0, PPC_NONE, fl2), \
10995 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 1, opc3, 0, PPC_NONE, fl2), \
10996 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 2, opc3, 0, PPC_NONE, fl2), \
10997 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 3, opc3, 0, PPC_NONE, fl2)
10999 #undef GEN_XX3_RC_FORM
11000 #define GEN_XX3_RC_FORM(name, opc2, opc3, fl2) \
11001 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x00, opc3 | 0x00, 0, PPC_NONE, fl2), \
11002 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x01, opc3 | 0x00, 0, PPC_NONE, fl2), \
11003 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x02, opc3 | 0x00, 0, PPC_NONE, fl2), \
11004 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x03, opc3 | 0x00, 0, PPC_NONE, fl2), \
11005 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x00, opc3 | 0x10, 0, PPC_NONE, fl2), \
11006 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x01, opc3 | 0x10, 0, PPC_NONE, fl2), \
11007 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x02, opc3 | 0x10, 0, PPC_NONE, fl2), \
11008 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x03, opc3 | 0x10, 0, PPC_NONE, fl2)
11010 #undef GEN_XX3FORM_DM
11011 #define GEN_XX3FORM_DM(name, opc2, opc3) \
11012 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
11013 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
11014 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
11015 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
11016 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
11017 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
11018 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
11019 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
11020 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
11021 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
11022 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
11023 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
11024 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x0C, 0, PPC_NONE, PPC2_VSX),\
11025 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x0C, 0, PPC_NONE, PPC2_VSX),\
11026 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x0C, 0, PPC_NONE, PPC2_VSX),\
11027 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x0C, 0, PPC_NONE, PPC2_VSX)
11029 GEN_XX2FORM(xsabsdp, 0x12, 0x15, PPC2_VSX),
11030 GEN_XX2FORM(xsnabsdp, 0x12, 0x16, PPC2_VSX),
11031 GEN_XX2FORM(xsnegdp, 0x12, 0x17, PPC2_VSX),
11032 GEN_XX3FORM(xscpsgndp, 0x00, 0x16, PPC2_VSX),
11034 GEN_XX2FORM(xvabsdp, 0x12, 0x1D, PPC2_VSX),
11035 GEN_XX2FORM(xvnabsdp, 0x12, 0x1E, PPC2_VSX),
11036 GEN_XX2FORM(xvnegdp, 0x12, 0x1F, PPC2_VSX),
11037 GEN_XX3FORM(xvcpsgndp, 0x00, 0x1E, PPC2_VSX),
11038 GEN_XX2FORM(xvabssp, 0x12, 0x19, PPC2_VSX),
11039 GEN_XX2FORM(xvnabssp, 0x12, 0x1A, PPC2_VSX),
11040 GEN_XX2FORM(xvnegsp, 0x12, 0x1B, PPC2_VSX),
11041 GEN_XX3FORM(xvcpsgnsp, 0x00, 0x1A, PPC2_VSX),
11043 GEN_XX3FORM(xsadddp, 0x00, 0x04, PPC2_VSX),
11044 GEN_XX3FORM(xssubdp, 0x00, 0x05, PPC2_VSX),
11045 GEN_XX3FORM(xsmuldp, 0x00, 0x06, PPC2_VSX),
11046 GEN_XX3FORM(xsdivdp, 0x00, 0x07, PPC2_VSX),
11047 GEN_XX2FORM(xsredp, 0x14, 0x05, PPC2_VSX),
11048 GEN_XX2FORM(xssqrtdp, 0x16, 0x04, PPC2_VSX),
11049 GEN_XX2FORM(xsrsqrtedp, 0x14, 0x04, PPC2_VSX),
11050 GEN_XX3FORM(xstdivdp, 0x14, 0x07, PPC2_VSX),
11051 GEN_XX2FORM(xstsqrtdp, 0x14, 0x06, PPC2_VSX),
11052 GEN_XX3FORM(xsmaddadp, 0x04, 0x04, PPC2_VSX),
11053 GEN_XX3FORM(xsmaddmdp, 0x04, 0x05, PPC2_VSX),
11054 GEN_XX3FORM(xsmsubadp, 0x04, 0x06, PPC2_VSX),
11055 GEN_XX3FORM(xsmsubmdp, 0x04, 0x07, PPC2_VSX),
11056 GEN_XX3FORM(xsnmaddadp, 0x04, 0x14, PPC2_VSX),
11057 GEN_XX3FORM(xsnmaddmdp, 0x04, 0x15, PPC2_VSX),
11058 GEN_XX3FORM(xsnmsubadp, 0x04, 0x16, PPC2_VSX),
11059 GEN_XX3FORM(xsnmsubmdp, 0x04, 0x17, PPC2_VSX),
11060 GEN_XX2FORM(xscmpodp, 0x0C, 0x05, PPC2_VSX),
11061 GEN_XX2FORM(xscmpudp, 0x0C, 0x04, PPC2_VSX),
11062 GEN_XX3FORM(xsmaxdp, 0x00, 0x14, PPC2_VSX),
11063 GEN_XX3FORM(xsmindp, 0x00, 0x15, PPC2_VSX),
11064 GEN_XX2FORM(xscvdpsp, 0x12, 0x10, PPC2_VSX),
11065 GEN_XX2FORM(xscvdpspn, 0x16, 0x10, PPC2_VSX207),
11066 GEN_XX2FORM(xscvspdp, 0x12, 0x14, PPC2_VSX),
11067 GEN_XX2FORM(xscvspdpn, 0x16, 0x14, PPC2_VSX207),
11068 GEN_XX2FORM(xscvdpsxds, 0x10, 0x15, PPC2_VSX),
11069 GEN_XX2FORM(xscvdpsxws, 0x10, 0x05, PPC2_VSX),
11070 GEN_XX2FORM(xscvdpuxds, 0x10, 0x14, PPC2_VSX),
11071 GEN_XX2FORM(xscvdpuxws, 0x10, 0x04, PPC2_VSX),
11072 GEN_XX2FORM(xscvsxddp, 0x10, 0x17, PPC2_VSX),
11073 GEN_XX2FORM(xscvuxddp, 0x10, 0x16, PPC2_VSX),
11074 GEN_XX2FORM(xsrdpi, 0x12, 0x04, PPC2_VSX),
11075 GEN_XX2FORM(xsrdpic, 0x16, 0x06, PPC2_VSX),
11076 GEN_XX2FORM(xsrdpim, 0x12, 0x07, PPC2_VSX),
11077 GEN_XX2FORM(xsrdpip, 0x12, 0x06, PPC2_VSX),
11078 GEN_XX2FORM(xsrdpiz, 0x12, 0x05, PPC2_VSX),
11080 GEN_XX3FORM(xsaddsp, 0x00, 0x00, PPC2_VSX207),
11081 GEN_XX3FORM(xssubsp, 0x00, 0x01, PPC2_VSX207),
11082 GEN_XX3FORM(xsmulsp, 0x00, 0x02, PPC2_VSX207),
11083 GEN_XX3FORM(xsdivsp, 0x00, 0x03, PPC2_VSX207),
11084 GEN_XX2FORM(xsresp, 0x14, 0x01, PPC2_VSX207),
11085 GEN_XX2FORM(xsrsp, 0x12, 0x11, PPC2_VSX207),
11086 GEN_XX2FORM(xssqrtsp, 0x16, 0x00, PPC2_VSX207),
11087 GEN_XX2FORM(xsrsqrtesp, 0x14, 0x00, PPC2_VSX207),
11088 GEN_XX3FORM(xsmaddasp, 0x04, 0x00, PPC2_VSX207),
11089 GEN_XX3FORM(xsmaddmsp, 0x04, 0x01, PPC2_VSX207),
11090 GEN_XX3FORM(xsmsubasp, 0x04, 0x02, PPC2_VSX207),
11091 GEN_XX3FORM(xsmsubmsp, 0x04, 0x03, PPC2_VSX207),
11092 GEN_XX3FORM(xsnmaddasp, 0x04, 0x10, PPC2_VSX207),
11093 GEN_XX3FORM(xsnmaddmsp, 0x04, 0x11, PPC2_VSX207),
11094 GEN_XX3FORM(xsnmsubasp, 0x04, 0x12, PPC2_VSX207),
11095 GEN_XX3FORM(xsnmsubmsp, 0x04, 0x13, PPC2_VSX207),
11096 GEN_XX2FORM(xscvsxdsp, 0x10, 0x13, PPC2_VSX207),
11097 GEN_XX2FORM(xscvuxdsp, 0x10, 0x12, PPC2_VSX207),
11099 GEN_XX3FORM(xvadddp, 0x00, 0x0C, PPC2_VSX),
11100 GEN_XX3FORM(xvsubdp, 0x00, 0x0D, PPC2_VSX),
11101 GEN_XX3FORM(xvmuldp, 0x00, 0x0E, PPC2_VSX),
11102 GEN_XX3FORM(xvdivdp, 0x00, 0x0F, PPC2_VSX),
11103 GEN_XX2FORM(xvredp, 0x14, 0x0D, PPC2_VSX),
11104 GEN_XX2FORM(xvsqrtdp, 0x16, 0x0C, PPC2_VSX),
11105 GEN_XX2FORM(xvrsqrtedp, 0x14, 0x0C, PPC2_VSX),
11106 GEN_XX3FORM(xvtdivdp, 0x14, 0x0F, PPC2_VSX),
11107 GEN_XX2FORM(xvtsqrtdp, 0x14, 0x0E, PPC2_VSX),
11108 GEN_XX3FORM(xvmaddadp, 0x04, 0x0C, PPC2_VSX),
11109 GEN_XX3FORM(xvmaddmdp, 0x04, 0x0D, PPC2_VSX),
11110 GEN_XX3FORM(xvmsubadp, 0x04, 0x0E, PPC2_VSX),
11111 GEN_XX3FORM(xvmsubmdp, 0x04, 0x0F, PPC2_VSX),
11112 GEN_XX3FORM(xvnmaddadp, 0x04, 0x1C, PPC2_VSX),
11113 GEN_XX3FORM(xvnmaddmdp, 0x04, 0x1D, PPC2_VSX),
11114 GEN_XX3FORM(xvnmsubadp, 0x04, 0x1E, PPC2_VSX),
11115 GEN_XX3FORM(xvnmsubmdp, 0x04, 0x1F, PPC2_VSX),
11116 GEN_XX3FORM(xvmaxdp, 0x00, 0x1C, PPC2_VSX),
11117 GEN_XX3FORM(xvmindp, 0x00, 0x1D, PPC2_VSX),
11118 GEN_XX3_RC_FORM(xvcmpeqdp, 0x0C, 0x0C, PPC2_VSX),
11119 GEN_XX3_RC_FORM(xvcmpgtdp, 0x0C, 0x0D, PPC2_VSX),
11120 GEN_XX3_RC_FORM(xvcmpgedp, 0x0C, 0x0E, PPC2_VSX),
11121 GEN_XX2FORM(xvcvdpsp, 0x12, 0x18, PPC2_VSX),
11122 GEN_XX2FORM(xvcvdpsxds, 0x10, 0x1D, PPC2_VSX),
11123 GEN_XX2FORM(xvcvdpsxws, 0x10, 0x0D, PPC2_VSX),
11124 GEN_XX2FORM(xvcvdpuxds, 0x10, 0x1C, PPC2_VSX),
11125 GEN_XX2FORM(xvcvdpuxws, 0x10, 0x0C, PPC2_VSX),
11126 GEN_XX2FORM(xvcvsxddp, 0x10, 0x1F, PPC2_VSX),
11127 GEN_XX2FORM(xvcvuxddp, 0x10, 0x1E, PPC2_VSX),
11128 GEN_XX2FORM(xvcvsxwdp, 0x10, 0x0F, PPC2_VSX),
11129 GEN_XX2FORM(xvcvuxwdp, 0x10, 0x0E, PPC2_VSX),
11130 GEN_XX2FORM(xvrdpi, 0x12, 0x0C, PPC2_VSX),
11131 GEN_XX2FORM(xvrdpic, 0x16, 0x0E, PPC2_VSX),
11132 GEN_XX2FORM(xvrdpim, 0x12, 0x0F, PPC2_VSX),
11133 GEN_XX2FORM(xvrdpip, 0x12, 0x0E, PPC2_VSX),
11134 GEN_XX2FORM(xvrdpiz, 0x12, 0x0D, PPC2_VSX),
11136 GEN_XX3FORM(xvaddsp, 0x00, 0x08, PPC2_VSX),
11137 GEN_XX3FORM(xvsubsp, 0x00, 0x09, PPC2_VSX),
11138 GEN_XX3FORM(xvmulsp, 0x00, 0x0A, PPC2_VSX),
11139 GEN_XX3FORM(xvdivsp, 0x00, 0x0B, PPC2_VSX),
11140 GEN_XX2FORM(xvresp, 0x14, 0x09, PPC2_VSX),
11141 GEN_XX2FORM(xvsqrtsp, 0x16, 0x08, PPC2_VSX),
11142 GEN_XX2FORM(xvrsqrtesp, 0x14, 0x08, PPC2_VSX),
11143 GEN_XX3FORM(xvtdivsp, 0x14, 0x0B, PPC2_VSX),
11144 GEN_XX2FORM(xvtsqrtsp, 0x14, 0x0A, PPC2_VSX),
11145 GEN_XX3FORM(xvmaddasp, 0x04, 0x08, PPC2_VSX),
11146 GEN_XX3FORM(xvmaddmsp, 0x04, 0x09, PPC2_VSX),
11147 GEN_XX3FORM(xvmsubasp, 0x04, 0x0A, PPC2_VSX),
11148 GEN_XX3FORM(xvmsubmsp, 0x04, 0x0B, PPC2_VSX),
11149 GEN_XX3FORM(xvnmaddasp, 0x04, 0x18, PPC2_VSX),
11150 GEN_XX3FORM(xvnmaddmsp, 0x04, 0x19, PPC2_VSX),
11151 GEN_XX3FORM(xvnmsubasp, 0x04, 0x1A, PPC2_VSX),
11152 GEN_XX3FORM(xvnmsubmsp, 0x04, 0x1B, PPC2_VSX),
11153 GEN_XX3FORM(xvmaxsp, 0x00, 0x18, PPC2_VSX),
11154 GEN_XX3FORM(xvminsp, 0x00, 0x19, PPC2_VSX),
11155 GEN_XX3_RC_FORM(xvcmpeqsp, 0x0C, 0x08, PPC2_VSX),
11156 GEN_XX3_RC_FORM(xvcmpgtsp, 0x0C, 0x09, PPC2_VSX),
11157 GEN_XX3_RC_FORM(xvcmpgesp, 0x0C, 0x0A, PPC2_VSX),
11158 GEN_XX2FORM(xvcvspdp, 0x12, 0x1C, PPC2_VSX),
11159 GEN_XX2FORM(xvcvspsxds, 0x10, 0x19, PPC2_VSX),
11160 GEN_XX2FORM(xvcvspsxws, 0x10, 0x09, PPC2_VSX),
11161 GEN_XX2FORM(xvcvspuxds, 0x10, 0x18, PPC2_VSX),
11162 GEN_XX2FORM(xvcvspuxws, 0x10, 0x08, PPC2_VSX),
11163 GEN_XX2FORM(xvcvsxdsp, 0x10, 0x1B, PPC2_VSX),
11164 GEN_XX2FORM(xvcvuxdsp, 0x10, 0x1A, PPC2_VSX),
11165 GEN_XX2FORM(xvcvsxwsp, 0x10, 0x0B, PPC2_VSX),
11166 GEN_XX2FORM(xvcvuxwsp, 0x10, 0x0A, PPC2_VSX),
11167 GEN_XX2FORM(xvrspi, 0x12, 0x08, PPC2_VSX),
11168 GEN_XX2FORM(xvrspic, 0x16, 0x0A, PPC2_VSX),
11169 GEN_XX2FORM(xvrspim, 0x12, 0x0B, PPC2_VSX),
11170 GEN_XX2FORM(xvrspip, 0x12, 0x0A, PPC2_VSX),
11171 GEN_XX2FORM(xvrspiz, 0x12, 0x09, PPC2_VSX),
11174 #define VSX_LOGICAL(name, opc2, opc3, fl2) \
11175 GEN_XX3FORM(name, opc2, opc3, fl2)
11177 VSX_LOGICAL(xxland, 0x8, 0x10, PPC2_VSX),
11178 VSX_LOGICAL(xxlandc, 0x8, 0x11, PPC2_VSX),
11179 VSX_LOGICAL(xxlor, 0x8, 0x12, PPC2_VSX),
11180 VSX_LOGICAL(xxlxor, 0x8, 0x13, PPC2_VSX),
11181 VSX_LOGICAL(xxlnor, 0x8, 0x14, PPC2_VSX),
11182 VSX_LOGICAL(xxleqv, 0x8, 0x17, PPC2_VSX207),
11183 VSX_LOGICAL(xxlnand, 0x8, 0x16, PPC2_VSX207),
11184 VSX_LOGICAL(xxlorc, 0x8, 0x15, PPC2_VSX207),
11185 GEN_XX3FORM(xxmrghw, 0x08, 0x02, PPC2_VSX),
11186 GEN_XX3FORM(xxmrglw, 0x08, 0x06, PPC2_VSX),
11187 GEN_XX2FORM(xxspltw, 0x08, 0x0A, PPC2_VSX),
11188 GEN_XX3FORM_DM(xxsldwi, 0x08, 0x00),
11190 #define GEN_XXSEL_ROW(opc3) \
11191 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x18, opc3, 0, PPC_NONE, PPC2_VSX), \
11192 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x19, opc3, 0, PPC_NONE, PPC2_VSX), \
11193 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1A, opc3, 0, PPC_NONE, PPC2_VSX), \
11194 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1B, opc3, 0, PPC_NONE, PPC2_VSX), \
11195 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1C, opc3, 0, PPC_NONE, PPC2_VSX), \
11196 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1D, opc3, 0, PPC_NONE, PPC2_VSX), \
11197 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1E, opc3, 0, PPC_NONE, PPC2_VSX), \
11198 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1F, opc3, 0, PPC_NONE, PPC2_VSX), \
11200 GEN_XXSEL_ROW(0x00)
11201 GEN_XXSEL_ROW(0x01)
11202 GEN_XXSEL_ROW(0x02)
11203 GEN_XXSEL_ROW(0x03)
11204 GEN_XXSEL_ROW(0x04)
11205 GEN_XXSEL_ROW(0x05)
11206 GEN_XXSEL_ROW(0x06)
11207 GEN_XXSEL_ROW(0x07)
11208 GEN_XXSEL_ROW(0x08)
11209 GEN_XXSEL_ROW(0x09)
11210 GEN_XXSEL_ROW(0x0A)
11211 GEN_XXSEL_ROW(0x0B)
11212 GEN_XXSEL_ROW(0x0C)
11213 GEN_XXSEL_ROW(0x0D)
11214 GEN_XXSEL_ROW(0x0E)
11215 GEN_XXSEL_ROW(0x0F)
11216 GEN_XXSEL_ROW(0x10)
11217 GEN_XXSEL_ROW(0x11)
11218 GEN_XXSEL_ROW(0x12)
11219 GEN_XXSEL_ROW(0x13)
11220 GEN_XXSEL_ROW(0x14)
11221 GEN_XXSEL_ROW(0x15)
11222 GEN_XXSEL_ROW(0x16)
11223 GEN_XXSEL_ROW(0x17)
11224 GEN_XXSEL_ROW(0x18)
11225 GEN_XXSEL_ROW(0x19)
11226 GEN_XXSEL_ROW(0x1A)
11227 GEN_XXSEL_ROW(0x1B)
11228 GEN_XXSEL_ROW(0x1C)
11229 GEN_XXSEL_ROW(0x1D)
11230 GEN_XXSEL_ROW(0x1E)
11231 GEN_XXSEL_ROW(0x1F)
11233 GEN_XX3FORM_DM(xxpermdi, 0x08, 0x01),
11235 #undef GEN_DFP_T_A_B_Rc
11236 #undef GEN_DFP_BF_A_B
11237 #undef GEN_DFP_BF_A_DCM
11238 #undef GEN_DFP_T_B_U32_U32_Rc
11239 #undef GEN_DFP_T_A_B_I32_Rc
11240 #undef GEN_DFP_T_B_Rc
11241 #undef GEN_DFP_T_FPR_I32_Rc
11243 #define _GEN_DFP_LONG(name, op1, op2, mask) \
11244 GEN_HANDLER_E(name, 0x3B, op1, op2, mask, PPC_NONE, PPC2_DFP)
11246 #define _GEN_DFP_LONGx2(name, op1, op2, mask) \
11247 GEN_HANDLER_E(name, 0x3B, op1, 0x00 | op2, mask, PPC_NONE, PPC2_DFP), \
11248 GEN_HANDLER_E(name, 0x3B, op1, 0x10 | op2, mask, PPC_NONE, PPC2_DFP)
11250 #define _GEN_DFP_LONGx4(name, op1, op2, mask) \
11251 GEN_HANDLER_E(name, 0x3B, op1, 0x00 | op2, mask, PPC_NONE, PPC2_DFP), \
11252 GEN_HANDLER_E(name, 0x3B, op1, 0x08 | op2, mask, PPC_NONE, PPC2_DFP), \
11253 GEN_HANDLER_E(name, 0x3B, op1, 0x10 | op2, mask, PPC_NONE, PPC2_DFP), \
11254 GEN_HANDLER_E(name, 0x3B, op1, 0x18 | op2, mask, PPC_NONE, PPC2_DFP)
11256 #define _GEN_DFP_QUAD(name, op1, op2, mask) \
11257 GEN_HANDLER_E(name, 0x3F, op1, op2, mask, PPC_NONE, PPC2_DFP)
11259 #define _GEN_DFP_QUADx2(name, op1, op2, mask) \
11260 GEN_HANDLER_E(name, 0x3F, op1, 0x00 | op2, mask, PPC_NONE, PPC2_DFP), \
11261 GEN_HANDLER_E(name, 0x3F, op1, 0x10 | op2, mask, PPC_NONE, PPC2_DFP)
11263 #define _GEN_DFP_QUADx4(name, op1, op2, mask) \
11264 GEN_HANDLER_E(name, 0x3F, op1, 0x00 | op2, mask, PPC_NONE, PPC2_DFP), \
11265 GEN_HANDLER_E(name, 0x3F, op1, 0x08 | op2, mask, PPC_NONE, PPC2_DFP), \
11266 GEN_HANDLER_E(name, 0x3F, op1, 0x10 | op2, mask, PPC_NONE, PPC2_DFP), \
11267 GEN_HANDLER_E(name, 0x3F, op1, 0x18 | op2, mask, PPC_NONE, PPC2_DFP)
11269 #define GEN_DFP_T_A_B_Rc(name, op1, op2) \
11270 _GEN_DFP_LONG(name, op1, op2, 0x00000000)
11272 #define GEN_DFP_Tp_Ap_Bp_Rc(name, op1, op2) \
11273 _GEN_DFP_QUAD(name, op1, op2, 0x00210800)
11275 #define GEN_DFP_Tp_A_Bp_Rc(name, op1, op2) \
11276 _GEN_DFP_QUAD(name, op1, op2, 0x00200800)
11278 #define GEN_DFP_T_B_Rc(name, op1, op2) \
11279 _GEN_DFP_LONG(name, op1, op2, 0x001F0000)
11281 #define GEN_DFP_Tp_Bp_Rc(name, op1, op2) \
11282 _GEN_DFP_QUAD(name, op1, op2, 0x003F0800)
11284 #define GEN_DFP_Tp_B_Rc(name, op1, op2) \
11285 _GEN_DFP_QUAD(name, op1, op2, 0x003F0000)
11287 #define GEN_DFP_T_Bp_Rc(name, op1, op2) \
11288 _GEN_DFP_QUAD(name, op1, op2, 0x001F0800)
11290 #define GEN_DFP_BF_A_B(name, op1, op2) \
11291 _GEN_DFP_LONG(name, op1, op2, 0x00000001)
11293 #define GEN_DFP_BF_Ap_Bp(name, op1, op2) \
11294 _GEN_DFP_QUAD(name, op1, op2, 0x00610801)
11296 #define GEN_DFP_BF_A_Bp(name, op1, op2) \
11297 _GEN_DFP_QUAD(name, op1, op2, 0x00600801)
11299 #define GEN_DFP_BF_A_DCM(name, op1, op2) \
11300 _GEN_DFP_LONGx2(name, op1, op2, 0x00600001)
11302 #define GEN_DFP_BF_Ap_DCM(name, op1, op2) \
11303 _GEN_DFP_QUADx2(name, op1, op2, 0x00610001)
11305 #define GEN_DFP_T_A_B_RMC_Rc(name, op1, op2) \
11306 _GEN_DFP_LONGx4(name, op1, op2, 0x00000000)
11308 #define GEN_DFP_Tp_Ap_Bp_RMC_Rc(name, op1, op2) \
11309 _GEN_DFP_QUADx4(name, op1, op2, 0x02010800)
11311 #define GEN_DFP_Tp_A_Bp_RMC_Rc(name, op1, op2) \
11312 _GEN_DFP_QUADx4(name, op1, op2, 0x02000800)
11314 #define GEN_DFP_TE_T_B_RMC_Rc(name, op1, op2) \
11315 _GEN_DFP_LONGx4(name, op1, op2, 0x00000000)
11317 #define GEN_DFP_TE_Tp_Bp_RMC_Rc(name, op1, op2) \
11318 _GEN_DFP_QUADx4(name, op1, op2, 0x00200800)
11320 #define GEN_DFP_R_T_B_RMC_Rc(name, op1, op2) \
11321 _GEN_DFP_LONGx4(name, op1, op2, 0x001E0000)
11323 #define GEN_DFP_R_Tp_Bp_RMC_Rc(name, op1, op2) \
11324 _GEN_DFP_QUADx4(name, op1, op2, 0x003E0800)
11326 #define GEN_DFP_SP_T_B_Rc(name, op1, op2) \
11327 _GEN_DFP_LONG(name, op1, op2, 0x00070000)
11329 #define GEN_DFP_SP_Tp_Bp_Rc(name, op1, op2) \
11330 _GEN_DFP_QUAD(name, op1, op2, 0x00270800)
11332 #define GEN_DFP_S_T_B_Rc(name, op1, op2) \
11333 _GEN_DFP_LONG(name, op1, op2, 0x000F0000)
11335 #define GEN_DFP_S_Tp_Bp_Rc(name, op1, op2) \
11336 _GEN_DFP_QUAD(name, op1, op2, 0x002F0800)
11338 #define GEN_DFP_T_A_SH_Rc(name, op1, op2) \
11339 _GEN_DFP_LONGx2(name, op1, op2, 0x00000000)
11341 #define GEN_DFP_Tp_Ap_SH_Rc(name, op1, op2) \
11342 _GEN_DFP_QUADx2(name, op1, op2, 0x00210000)
11344 GEN_DFP_T_A_B_Rc(dadd, 0x02, 0x00),
11345 GEN_DFP_Tp_Ap_Bp_Rc(daddq, 0x02, 0x00),
11346 GEN_DFP_T_A_B_Rc(dsub, 0x02, 0x10),
11347 GEN_DFP_Tp_Ap_Bp_Rc(dsubq, 0x02, 0x10),
11348 GEN_DFP_T_A_B_Rc(dmul, 0x02, 0x01),
11349 GEN_DFP_Tp_Ap_Bp_Rc(dmulq, 0x02, 0x01),
11350 GEN_DFP_T_A_B_Rc(ddiv, 0x02, 0x11),
11351 GEN_DFP_Tp_Ap_Bp_Rc(ddivq, 0x02, 0x11),
11352 GEN_DFP_BF_A_B(dcmpu, 0x02, 0x14),
11353 GEN_DFP_BF_Ap_Bp(dcmpuq, 0x02, 0x14),
11354 GEN_DFP_BF_A_B(dcmpo, 0x02, 0x04),
11355 GEN_DFP_BF_Ap_Bp(dcmpoq, 0x02, 0x04),
11356 GEN_DFP_BF_A_DCM(dtstdc, 0x02, 0x06),
11357 GEN_DFP_BF_Ap_DCM(dtstdcq, 0x02, 0x06),
11358 GEN_DFP_BF_A_DCM(dtstdg, 0x02, 0x07),
11359 GEN_DFP_BF_Ap_DCM(dtstdgq, 0x02, 0x07),
11360 GEN_DFP_BF_A_B(dtstex, 0x02, 0x05),
11361 GEN_DFP_BF_Ap_Bp(dtstexq, 0x02, 0x05),
11362 GEN_DFP_BF_A_B(dtstsf, 0x02, 0x15),
11363 GEN_DFP_BF_A_Bp(dtstsfq, 0x02, 0x15),
11364 GEN_DFP_TE_T_B_RMC_Rc(dquai, 0x03, 0x02),
11365 GEN_DFP_TE_Tp_Bp_RMC_Rc(dquaiq, 0x03, 0x02),
11366 GEN_DFP_T_A_B_RMC_Rc(dqua, 0x03, 0x00),
11367 GEN_DFP_Tp_Ap_Bp_RMC_Rc(dquaq, 0x03, 0x00),
11368 GEN_DFP_T_A_B_RMC_Rc(drrnd, 0x03, 0x01),
11369 GEN_DFP_Tp_A_Bp_RMC_Rc(drrndq, 0x03, 0x01),
11370 GEN_DFP_R_T_B_RMC_Rc(drintx, 0x03, 0x03),
11371 GEN_DFP_R_Tp_Bp_RMC_Rc(drintxq, 0x03, 0x03),
11372 GEN_DFP_R_T_B_RMC_Rc(drintn, 0x03, 0x07),
11373 GEN_DFP_R_Tp_Bp_RMC_Rc(drintnq, 0x03, 0x07),
11374 GEN_DFP_T_B_Rc(dctdp, 0x02, 0x08),
11375 GEN_DFP_Tp_B_Rc(dctqpq, 0x02, 0x08),
11376 GEN_DFP_T_B_Rc(drsp, 0x02, 0x18),
11377 GEN_DFP_Tp_Bp_Rc(drdpq, 0x02, 0x18),
11378 GEN_DFP_T_B_Rc(dcffix, 0x02, 0x19),
11379 GEN_DFP_Tp_B_Rc(dcffixq, 0x02, 0x19),
11380 GEN_DFP_T_B_Rc(dctfix, 0x02, 0x09),
11381 GEN_DFP_T_Bp_Rc(dctfixq, 0x02, 0x09),
11382 GEN_DFP_SP_T_B_Rc(ddedpd, 0x02, 0x0a),
11383 GEN_DFP_SP_Tp_Bp_Rc(ddedpdq, 0x02, 0x0a),
11384 GEN_DFP_S_T_B_Rc(denbcd, 0x02, 0x1a),
11385 GEN_DFP_S_Tp_Bp_Rc(denbcdq, 0x02, 0x1a),
11386 GEN_DFP_T_B_Rc(dxex, 0x02, 0x0b),
11387 GEN_DFP_T_Bp_Rc(dxexq, 0x02, 0x0b),
11388 GEN_DFP_T_A_B_Rc(diex, 0x02, 0x1b),
11389 GEN_DFP_Tp_A_Bp_Rc(diexq, 0x02, 0x1b),
11390 GEN_DFP_T_A_SH_Rc(dscli, 0x02, 0x02),
11391 GEN_DFP_Tp_Ap_SH_Rc(dscliq, 0x02, 0x02),
11392 GEN_DFP_T_A_SH_Rc(dscri, 0x02, 0x03),
11393 GEN_DFP_Tp_Ap_SH_Rc(dscriq, 0x02, 0x03),
11396 #define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \
11397 GEN_OPCODE_DUAL(name0##_##name1, 0x04, opc2, opc3, inval0, inval1, type, PPC_NONE)
11398 GEN_SPE(evaddw, speundef, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11399 GEN_SPE(evaddiw, speundef, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11400 GEN_SPE(evsubfw, speundef, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11401 GEN_SPE(evsubifw, speundef, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11402 GEN_SPE(evabs, evneg, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE),
11403 GEN_SPE(evextsb, evextsh, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE),
11404 GEN_SPE(evrndw, evcntlzw, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE),
11405 GEN_SPE(evcntlsw, brinc, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE),
11406 GEN_SPE(evmra, speundef, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE),
11407 GEN_SPE(speundef, evand, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE),
11408 GEN_SPE(evandc, speundef, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11409 GEN_SPE(evxor, evor, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE),
11410 GEN_SPE(evnor, eveqv, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE),
11411 GEN_SPE(evmwumi, evmwsmi, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE),
11412 GEN_SPE(evmwumia, evmwsmia, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE),
11413 GEN_SPE(evmwumiaa, evmwsmiaa, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE),
11414 GEN_SPE(speundef, evorc, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE),
11415 GEN_SPE(evnand, speundef, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11416 GEN_SPE(evsrwu, evsrws, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE),
11417 GEN_SPE(evsrwiu, evsrwis, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE),
11418 GEN_SPE(evslw, speundef, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11419 GEN_SPE(evslwi, speundef, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11420 GEN_SPE(evrlw, evsplati, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE),
11421 GEN_SPE(evrlwi, evsplatfi, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE),
11422 GEN_SPE(evmergehi, evmergelo, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE),
11423 GEN_SPE(evmergehilo, evmergelohi, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE),
11424 GEN_SPE(evcmpgtu, evcmpgts, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE),
11425 GEN_SPE(evcmpltu, evcmplts, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE),
11426 GEN_SPE(evcmpeq, speundef, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE),
11428 GEN_SPE(evfsadd, evfssub, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE),
11429 GEN_SPE(evfsabs, evfsnabs, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE),
11430 GEN_SPE(evfsneg, speundef, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE),
11431 GEN_SPE(evfsmul, evfsdiv, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE),
11432 GEN_SPE(evfscmpgt, evfscmplt, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE),
11433 GEN_SPE(evfscmpeq, speundef, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11434 GEN_SPE(evfscfui, evfscfsi, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11435 GEN_SPE(evfscfuf, evfscfsf, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11436 GEN_SPE(evfsctui, evfsctsi, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11437 GEN_SPE(evfsctuf, evfsctsf, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11438 GEN_SPE(evfsctuiz, speundef, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11439 GEN_SPE(evfsctsiz, speundef, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11440 GEN_SPE(evfststgt, evfststlt, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE),
11441 GEN_SPE(evfststeq, speundef, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11443 GEN_SPE(efsadd, efssub, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE),
11444 GEN_SPE(efsabs, efsnabs, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE),
11445 GEN_SPE(efsneg, speundef, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE),
11446 GEN_SPE(efsmul, efsdiv, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE),
11447 GEN_SPE(efscmpgt, efscmplt, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE),
11448 GEN_SPE(efscmpeq, efscfd, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE),
11449 GEN_SPE(efscfui, efscfsi, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11450 GEN_SPE(efscfuf, efscfsf, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11451 GEN_SPE(efsctui, efsctsi, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11452 GEN_SPE(efsctuf, efsctsf, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11453 GEN_SPE(efsctuiz, speundef, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11454 GEN_SPE(efsctsiz, speundef, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11455 GEN_SPE(efststgt, efststlt, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE),
11456 GEN_SPE(efststeq, speundef, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11458 GEN_SPE(efdadd, efdsub, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE),
11459 GEN_SPE(efdcfuid, efdcfsid, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
11460 GEN_SPE(efdabs, efdnabs, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE),
11461 GEN_SPE(efdneg, speundef, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE),
11462 GEN_SPE(efdmul, efddiv, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE),
11463 GEN_SPE(efdctuidz, efdctsidz, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
11464 GEN_SPE(efdcmpgt, efdcmplt, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE),
11465 GEN_SPE(efdcmpeq, efdcfs, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE),
11466 GEN_SPE(efdcfui, efdcfsi, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
11467 GEN_SPE(efdcfuf, efdcfsf, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
11468 GEN_SPE(efdctui, efdctsi, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
11469 GEN_SPE(efdctuf, efdctsf, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
11470 GEN_SPE(efdctuiz, speundef, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE),
11471 GEN_SPE(efdctsiz, speundef, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE),
11472 GEN_SPE(efdtstgt, efdtstlt, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE),
11473 GEN_SPE(efdtsteq, speundef, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE),
11475 #undef GEN_SPEOP_LDST
11476 #define GEN_SPEOP_LDST(name, opc2, sh) \
11477 GEN_HANDLER(name, 0x04, opc2, 0x0C, 0x00000000, PPC_SPE)
11478 GEN_SPEOP_LDST(evldd, 0x00, 3),
11479 GEN_SPEOP_LDST(evldw, 0x01, 3),
11480 GEN_SPEOP_LDST(evldh, 0x02, 3),
11481 GEN_SPEOP_LDST(evlhhesplat, 0x04, 1),
11482 GEN_SPEOP_LDST(evlhhousplat, 0x06, 1),
11483 GEN_SPEOP_LDST(evlhhossplat, 0x07, 1),
11484 GEN_SPEOP_LDST(evlwhe, 0x08, 2),
11485 GEN_SPEOP_LDST(evlwhou, 0x0A, 2),
11486 GEN_SPEOP_LDST(evlwhos, 0x0B, 2),
11487 GEN_SPEOP_LDST(evlwwsplat, 0x0C, 2),
11488 GEN_SPEOP_LDST(evlwhsplat, 0x0E, 2),
11490 GEN_SPEOP_LDST(evstdd, 0x10, 3),
11491 GEN_SPEOP_LDST(evstdw, 0x11, 3),
11492 GEN_SPEOP_LDST(evstdh, 0x12, 3),
11493 GEN_SPEOP_LDST(evstwhe, 0x18, 2),
11494 GEN_SPEOP_LDST(evstwho, 0x1A, 2),
11495 GEN_SPEOP_LDST(evstwwe, 0x1C, 2),
11496 GEN_SPEOP_LDST(evstwwo, 0x1E, 2),
11499 #include "helper_regs.h"
11500 #include "translate_init.c"
11502 /*****************************************************************************/
11503 /* Misc PowerPC helpers */
11504 void ppc_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf,
11510 PowerPCCPU *cpu = POWERPC_CPU(cs);
11511 CPUPPCState *env = &cpu->env;
11514 cpu_fprintf(f, "NIP " TARGET_FMT_lx " LR " TARGET_FMT_lx " CTR "
11515 TARGET_FMT_lx " XER " TARGET_FMT_lx "\n",
11516 env->nip, env->lr, env->ctr, cpu_read_xer(env));
11517 cpu_fprintf(f, "MSR " TARGET_FMT_lx " HID0 " TARGET_FMT_lx " HF "
11518 TARGET_FMT_lx " idx %d\n", env->msr, env->spr[SPR_HID0],
11519 env->hflags, env->mmu_idx);
11520 #if !defined(NO_TIMER_DUMP)
11521 cpu_fprintf(f, "TB %08" PRIu32 " %08" PRIu64
11522 #if !defined(CONFIG_USER_ONLY)
11526 cpu_ppc_load_tbu(env), cpu_ppc_load_tbl(env)
11527 #if !defined(CONFIG_USER_ONLY)
11528 , cpu_ppc_load_decr(env)
11532 for (i = 0; i < 32; i++) {
11533 if ((i & (RGPL - 1)) == 0)
11534 cpu_fprintf(f, "GPR%02d", i);
11535 cpu_fprintf(f, " %016" PRIx64, ppc_dump_gpr(env, i));
11536 if ((i & (RGPL - 1)) == (RGPL - 1))
11537 cpu_fprintf(f, "\n");
11539 cpu_fprintf(f, "CR ");
11540 for (i = 0; i < 8; i++)
11541 cpu_fprintf(f, "%01x", env->crf[i]);
11542 cpu_fprintf(f, " [");
11543 for (i = 0; i < 8; i++) {
11545 if (env->crf[i] & 0x08)
11547 else if (env->crf[i] & 0x04)
11549 else if (env->crf[i] & 0x02)
11551 cpu_fprintf(f, " %c%c", a, env->crf[i] & 0x01 ? 'O' : ' ');
11553 cpu_fprintf(f, " ] RES " TARGET_FMT_lx "\n",
11554 env->reserve_addr);
11555 for (i = 0; i < 32; i++) {
11556 if ((i & (RFPL - 1)) == 0)
11557 cpu_fprintf(f, "FPR%02d", i);
11558 cpu_fprintf(f, " %016" PRIx64, *((uint64_t *)&env->fpr[i]));
11559 if ((i & (RFPL - 1)) == (RFPL - 1))
11560 cpu_fprintf(f, "\n");
11562 cpu_fprintf(f, "FPSCR " TARGET_FMT_lx "\n", env->fpscr);
11563 #if !defined(CONFIG_USER_ONLY)
11564 cpu_fprintf(f, " SRR0 " TARGET_FMT_lx " SRR1 " TARGET_FMT_lx
11565 " PVR " TARGET_FMT_lx " VRSAVE " TARGET_FMT_lx "\n",
11566 env->spr[SPR_SRR0], env->spr[SPR_SRR1],
11567 env->spr[SPR_PVR], env->spr[SPR_VRSAVE]);
11569 cpu_fprintf(f, "SPRG0 " TARGET_FMT_lx " SPRG1 " TARGET_FMT_lx
11570 " SPRG2 " TARGET_FMT_lx " SPRG3 " TARGET_FMT_lx "\n",
11571 env->spr[SPR_SPRG0], env->spr[SPR_SPRG1],
11572 env->spr[SPR_SPRG2], env->spr[SPR_SPRG3]);
11574 cpu_fprintf(f, "SPRG4 " TARGET_FMT_lx " SPRG5 " TARGET_FMT_lx
11575 " SPRG6 " TARGET_FMT_lx " SPRG7 " TARGET_FMT_lx "\n",
11576 env->spr[SPR_SPRG4], env->spr[SPR_SPRG5],
11577 env->spr[SPR_SPRG6], env->spr[SPR_SPRG7]);
11579 if (env->excp_model == POWERPC_EXCP_BOOKE) {
11580 cpu_fprintf(f, "CSRR0 " TARGET_FMT_lx " CSRR1 " TARGET_FMT_lx
11581 " MCSRR0 " TARGET_FMT_lx " MCSRR1 " TARGET_FMT_lx "\n",
11582 env->spr[SPR_BOOKE_CSRR0], env->spr[SPR_BOOKE_CSRR1],
11583 env->spr[SPR_BOOKE_MCSRR0], env->spr[SPR_BOOKE_MCSRR1]);
11585 cpu_fprintf(f, " TCR " TARGET_FMT_lx " TSR " TARGET_FMT_lx
11586 " ESR " TARGET_FMT_lx " DEAR " TARGET_FMT_lx "\n",
11587 env->spr[SPR_BOOKE_TCR], env->spr[SPR_BOOKE_TSR],
11588 env->spr[SPR_BOOKE_ESR], env->spr[SPR_BOOKE_DEAR]);
11590 cpu_fprintf(f, " PIR " TARGET_FMT_lx " DECAR " TARGET_FMT_lx
11591 " IVPR " TARGET_FMT_lx " EPCR " TARGET_FMT_lx "\n",
11592 env->spr[SPR_BOOKE_PIR], env->spr[SPR_BOOKE_DECAR],
11593 env->spr[SPR_BOOKE_IVPR], env->spr[SPR_BOOKE_EPCR]);
11595 cpu_fprintf(f, " MCSR " TARGET_FMT_lx " SPRG8 " TARGET_FMT_lx
11596 " EPR " TARGET_FMT_lx "\n",
11597 env->spr[SPR_BOOKE_MCSR], env->spr[SPR_BOOKE_SPRG8],
11598 env->spr[SPR_BOOKE_EPR]);
11601 cpu_fprintf(f, " MCAR " TARGET_FMT_lx " PID1 " TARGET_FMT_lx
11602 " PID2 " TARGET_FMT_lx " SVR " TARGET_FMT_lx "\n",
11603 env->spr[SPR_Exxx_MCAR], env->spr[SPR_BOOKE_PID1],
11604 env->spr[SPR_BOOKE_PID2], env->spr[SPR_E500_SVR]);
11607 * IVORs are left out as they are large and do not change often --
11608 * they can be read with "p $ivor0", "p $ivor1", etc.
11612 #if defined(TARGET_PPC64)
11613 if (env->flags & POWERPC_FLAG_CFAR) {
11614 cpu_fprintf(f, " CFAR " TARGET_FMT_lx"\n", env->cfar);
11618 switch (env->mmu_model) {
11619 case POWERPC_MMU_32B:
11620 case POWERPC_MMU_601:
11621 case POWERPC_MMU_SOFT_6xx:
11622 case POWERPC_MMU_SOFT_74xx:
11623 #if defined(TARGET_PPC64)
11624 case POWERPC_MMU_64B:
11625 case POWERPC_MMU_2_06:
11626 case POWERPC_MMU_2_06a:
11627 case POWERPC_MMU_2_06d:
11629 cpu_fprintf(f, " SDR1 " TARGET_FMT_lx " DAR " TARGET_FMT_lx
11630 " DSISR " TARGET_FMT_lx "\n", env->spr[SPR_SDR1],
11631 env->spr[SPR_DAR], env->spr[SPR_DSISR]);
11633 case POWERPC_MMU_BOOKE206:
11634 cpu_fprintf(f, " MAS0 " TARGET_FMT_lx " MAS1 " TARGET_FMT_lx
11635 " MAS2 " TARGET_FMT_lx " MAS3 " TARGET_FMT_lx "\n",
11636 env->spr[SPR_BOOKE_MAS0], env->spr[SPR_BOOKE_MAS1],
11637 env->spr[SPR_BOOKE_MAS2], env->spr[SPR_BOOKE_MAS3]);
11639 cpu_fprintf(f, " MAS4 " TARGET_FMT_lx " MAS6 " TARGET_FMT_lx
11640 " MAS7 " TARGET_FMT_lx " PID " TARGET_FMT_lx "\n",
11641 env->spr[SPR_BOOKE_MAS4], env->spr[SPR_BOOKE_MAS6],
11642 env->spr[SPR_BOOKE_MAS7], env->spr[SPR_BOOKE_PID]);
11644 cpu_fprintf(f, "MMUCFG " TARGET_FMT_lx " TLB0CFG " TARGET_FMT_lx
11645 " TLB1CFG " TARGET_FMT_lx "\n",
11646 env->spr[SPR_MMUCFG], env->spr[SPR_BOOKE_TLB0CFG],
11647 env->spr[SPR_BOOKE_TLB1CFG]);
11658 void ppc_cpu_dump_statistics(CPUState *cs, FILE*f,
11659 fprintf_function cpu_fprintf, int flags)
11661 #if defined(DO_PPC_STATISTICS)
11662 PowerPCCPU *cpu = POWERPC_CPU(cs);
11663 opc_handler_t **t1, **t2, **t3, *handler;
11666 t1 = cpu->env.opcodes;
11667 for (op1 = 0; op1 < 64; op1++) {
11669 if (is_indirect_opcode(handler)) {
11670 t2 = ind_table(handler);
11671 for (op2 = 0; op2 < 32; op2++) {
11673 if (is_indirect_opcode(handler)) {
11674 t3 = ind_table(handler);
11675 for (op3 = 0; op3 < 32; op3++) {
11677 if (handler->count == 0)
11679 cpu_fprintf(f, "%02x %02x %02x (%02x %04d) %16s: "
11680 "%016" PRIx64 " %" PRId64 "\n",
11681 op1, op2, op3, op1, (op3 << 5) | op2,
11683 handler->count, handler->count);
11686 if (handler->count == 0)
11688 cpu_fprintf(f, "%02x %02x (%02x %04d) %16s: "
11689 "%016" PRIx64 " %" PRId64 "\n",
11690 op1, op2, op1, op2, handler->oname,
11691 handler->count, handler->count);
11695 if (handler->count == 0)
11697 cpu_fprintf(f, "%02x (%02x ) %16s: %016" PRIx64
11699 op1, op1, handler->oname,
11700 handler->count, handler->count);
11706 /*****************************************************************************/
11707 static inline void gen_intermediate_code_internal(PowerPCCPU *cpu,
11708 TranslationBlock *tb,
11711 CPUState *cs = CPU(cpu);
11712 CPUPPCState *env = &cpu->env;
11713 DisasContext ctx, *ctxp = &ctx;
11714 opc_handler_t **table, *handler;
11715 target_ulong pc_start;
11716 uint16_t *gen_opc_end;
11723 gen_opc_end = tcg_ctx.gen_opc_buf + OPC_MAX_SIZE;
11724 ctx.nip = pc_start;
11726 ctx.exception = POWERPC_EXCP_NONE;
11727 ctx.spr_cb = env->spr_cb;
11728 ctx.mem_idx = env->mmu_idx;
11729 ctx.insns_flags = env->insns_flags;
11730 ctx.insns_flags2 = env->insns_flags2;
11731 ctx.access_type = -1;
11732 ctx.le_mode = env->hflags & (1 << MSR_LE) ? 1 : 0;
11733 #if defined(TARGET_PPC64)
11734 ctx.sf_mode = msr_is_64bit(env, env->msr);
11735 ctx.has_cfar = !!(env->flags & POWERPC_FLAG_CFAR);
11737 ctx.fpu_enabled = msr_fp;
11738 if ((env->flags & POWERPC_FLAG_SPE) && msr_spe)
11739 ctx.spe_enabled = msr_spe;
11741 ctx.spe_enabled = 0;
11742 if ((env->flags & POWERPC_FLAG_VRE) && msr_vr)
11743 ctx.altivec_enabled = msr_vr;
11745 ctx.altivec_enabled = 0;
11746 if ((env->flags & POWERPC_FLAG_VSX) && msr_vsx) {
11747 ctx.vsx_enabled = msr_vsx;
11749 ctx.vsx_enabled = 0;
11751 if ((env->flags & POWERPC_FLAG_SE) && msr_se)
11752 ctx.singlestep_enabled = CPU_SINGLE_STEP;
11754 ctx.singlestep_enabled = 0;
11755 if ((env->flags & POWERPC_FLAG_BE) && msr_be)
11756 ctx.singlestep_enabled |= CPU_BRANCH_STEP;
11757 if (unlikely(cs->singlestep_enabled)) {
11758 ctx.singlestep_enabled |= GDBSTUB_SINGLE_STEP;
11760 #if defined (DO_SINGLE_STEP) && 0
11761 /* Single step trace mode */
11765 max_insns = tb->cflags & CF_COUNT_MASK;
11766 if (max_insns == 0)
11767 max_insns = CF_COUNT_MASK;
11770 tcg_clear_temp_count();
11771 /* Set env in case of segfault during code fetch */
11772 while (ctx.exception == POWERPC_EXCP_NONE
11773 && tcg_ctx.gen_opc_ptr < gen_opc_end) {
11774 if (unlikely(!QTAILQ_EMPTY(&cs->breakpoints))) {
11775 QTAILQ_FOREACH(bp, &cs->breakpoints, entry) {
11776 if (bp->pc == ctx.nip) {
11777 gen_debug_exception(ctxp);
11782 if (unlikely(search_pc)) {
11783 j = tcg_ctx.gen_opc_ptr - tcg_ctx.gen_opc_buf;
11787 tcg_ctx.gen_opc_instr_start[lj++] = 0;
11789 tcg_ctx.gen_opc_pc[lj] = ctx.nip;
11790 tcg_ctx.gen_opc_instr_start[lj] = 1;
11791 tcg_ctx.gen_opc_icount[lj] = num_insns;
11793 LOG_DISAS("----------------\n");
11794 LOG_DISAS("nip=" TARGET_FMT_lx " super=%d ir=%d\n",
11795 ctx.nip, ctx.mem_idx, (int)msr_ir);
11796 if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO))
11798 if (unlikely(ctx.le_mode)) {
11799 ctx.opcode = bswap32(cpu_ldl_code(env, ctx.nip));
11801 ctx.opcode = cpu_ldl_code(env, ctx.nip);
11803 LOG_DISAS("translate opcode %08x (%02x %02x %02x) (%s)\n",
11804 ctx.opcode, opc1(ctx.opcode), opc2(ctx.opcode),
11805 opc3(ctx.opcode), ctx.le_mode ? "little" : "big");
11806 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP | CPU_LOG_TB_OP_OPT))) {
11807 tcg_gen_debug_insn_start(ctx.nip);
11810 table = env->opcodes;
11812 handler = table[opc1(ctx.opcode)];
11813 if (is_indirect_opcode(handler)) {
11814 table = ind_table(handler);
11815 handler = table[opc2(ctx.opcode)];
11816 if (is_indirect_opcode(handler)) {
11817 table = ind_table(handler);
11818 handler = table[opc3(ctx.opcode)];
11821 /* Is opcode *REALLY* valid ? */
11822 if (unlikely(handler->handler == &gen_invalid)) {
11823 if (qemu_log_enabled()) {
11824 qemu_log("invalid/unsupported opcode: "
11825 "%02x - %02x - %02x (%08x) " TARGET_FMT_lx " %d\n",
11826 opc1(ctx.opcode), opc2(ctx.opcode),
11827 opc3(ctx.opcode), ctx.opcode, ctx.nip - 4, (int)msr_ir);
11832 if (unlikely(handler->type & (PPC_SPE | PPC_SPE_SINGLE | PPC_SPE_DOUBLE) && Rc(ctx.opcode))) {
11833 inval = handler->inval2;
11835 inval = handler->inval1;
11838 if (unlikely((ctx.opcode & inval) != 0)) {
11839 if (qemu_log_enabled()) {
11840 qemu_log("invalid bits: %08x for opcode: "
11841 "%02x - %02x - %02x (%08x) " TARGET_FMT_lx "\n",
11842 ctx.opcode & inval, opc1(ctx.opcode),
11843 opc2(ctx.opcode), opc3(ctx.opcode),
11844 ctx.opcode, ctx.nip - 4);
11846 gen_inval_exception(ctxp, POWERPC_EXCP_INVAL_INVAL);
11850 (*(handler->handler))(&ctx);
11851 #if defined(DO_PPC_STATISTICS)
11854 /* Check trace mode exceptions */
11855 if (unlikely(ctx.singlestep_enabled & CPU_SINGLE_STEP &&
11856 (ctx.nip <= 0x100 || ctx.nip > 0xF00) &&
11857 ctx.exception != POWERPC_SYSCALL &&
11858 ctx.exception != POWERPC_EXCP_TRAP &&
11859 ctx.exception != POWERPC_EXCP_BRANCH)) {
11860 gen_exception(ctxp, POWERPC_EXCP_TRACE);
11861 } else if (unlikely(((ctx.nip & (TARGET_PAGE_SIZE - 1)) == 0) ||
11862 (cs->singlestep_enabled) ||
11864 num_insns >= max_insns)) {
11865 /* if we reach a page boundary or are single stepping, stop
11870 if (tcg_check_temp_count()) {
11871 fprintf(stderr, "Opcode %02x %02x %02x (%08x) leaked temporaries\n",
11872 opc1(ctx.opcode), opc2(ctx.opcode), opc3(ctx.opcode),
11877 if (tb->cflags & CF_LAST_IO)
11879 if (ctx.exception == POWERPC_EXCP_NONE) {
11880 gen_goto_tb(&ctx, 0, ctx.nip);
11881 } else if (ctx.exception != POWERPC_EXCP_BRANCH) {
11882 if (unlikely(cs->singlestep_enabled)) {
11883 gen_debug_exception(ctxp);
11885 /* Generate the return instruction */
11886 tcg_gen_exit_tb(0);
11888 gen_tb_end(tb, num_insns);
11889 *tcg_ctx.gen_opc_ptr = INDEX_op_end;
11890 if (unlikely(search_pc)) {
11891 j = tcg_ctx.gen_opc_ptr - tcg_ctx.gen_opc_buf;
11894 tcg_ctx.gen_opc_instr_start[lj++] = 0;
11896 tb->size = ctx.nip - pc_start;
11897 tb->icount = num_insns;
11899 #if defined(DEBUG_DISAS)
11900 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
11902 flags = env->bfd_mach;
11903 flags |= ctx.le_mode << 16;
11904 qemu_log("IN: %s\n", lookup_symbol(pc_start));
11905 log_target_disas(env, pc_start, ctx.nip - pc_start, flags);
11911 void gen_intermediate_code (CPUPPCState *env, struct TranslationBlock *tb)
11913 gen_intermediate_code_internal(ppc_env_get_cpu(env), tb, false);
11916 void gen_intermediate_code_pc (CPUPPCState *env, struct TranslationBlock *tb)
11918 gen_intermediate_code_internal(ppc_env_get_cpu(env), tb, true);
11921 void restore_state_to_opc(CPUPPCState *env, TranslationBlock *tb, int pc_pos)
11923 env->nip = tcg_ctx.gen_opc_pc[pc_pos];