]> git.proxmox.com Git - mirror_qemu.git/blame - target-ppc/translate.c
tcg: Invert the inclusion of helper.h
[mirror_qemu.git] / target-ppc / translate.c
CommitLineData
79aceca5 1/*
3fc6c082 2 * PowerPC emulation for qemu: main translation routines.
5fafdf24 3 *
76a66253 4 * Copyright (c) 2003-2007 Jocelyn Mayer
90dc8812 5 * Copyright (C) 2011 Freescale Semiconductor, Inc.
79aceca5
FB
6 *
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.
11 *
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.
16 *
17 * You should have received a copy of the GNU Lesser General Public
8167ee88 18 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
79aceca5 19 */
c6a1c22b 20
79aceca5 21#include "cpu.h"
76cad711 22#include "disas/disas.h"
57fec1fe 23#include "tcg-op.h"
1de7afc9 24#include "qemu/host-utils.h"
79aceca5 25
2ef6175a
RH
26#include "exec/helper-proto.h"
27#include "exec/helper-gen.h"
a7812ae4 28
8cbcb4fa
AJ
29#define CPU_SINGLE_STEP 0x1
30#define CPU_BRANCH_STEP 0x2
31#define GDBSTUB_SINGLE_STEP 0x4
32
a750fc0b 33/* Include definitions for instructions classes and implementations flags */
9fddaa0c 34//#define PPC_DEBUG_DISAS
76a66253 35//#define DO_PPC_STATISTICS
79aceca5 36
d12d51d5 37#ifdef PPC_DEBUG_DISAS
93fcfe39 38# define LOG_DISAS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
d12d51d5
AL
39#else
40# define LOG_DISAS(...) do { } while (0)
41#endif
a750fc0b
JM
42/*****************************************************************************/
43/* Code translation helpers */
c53be334 44
f78fb44e 45/* global register indexes */
a7812ae4 46static TCGv_ptr cpu_env;
1d542695 47static char cpu_reg_names[10*3 + 22*4 /* GPR */
f78fb44e 48#if !defined(TARGET_PPC64)
1d542695 49 + 10*4 + 22*5 /* SPE GPRh */
f78fb44e 50#endif
a5e26afa 51 + 10*4 + 22*5 /* FPR */
47e4661c 52 + 2*(10*6 + 22*7) /* AVRh, AVRl */
472b24ce 53 + 10*5 + 22*6 /* VSR */
47e4661c 54 + 8*5 /* CRF */];
f78fb44e
AJ
55static TCGv cpu_gpr[32];
56#if !defined(TARGET_PPC64)
57static TCGv cpu_gprh[32];
58#endif
a7812ae4
PB
59static TCGv_i64 cpu_fpr[32];
60static TCGv_i64 cpu_avrh[32], cpu_avrl[32];
472b24ce 61static TCGv_i64 cpu_vsr[32];
a7812ae4 62static TCGv_i32 cpu_crf[8];
bd568f18 63static TCGv cpu_nip;
6527f6ea 64static TCGv cpu_msr;
cfdcd37a
AJ
65static TCGv cpu_ctr;
66static TCGv cpu_lr;
697ab892
DG
67#if defined(TARGET_PPC64)
68static TCGv cpu_cfar;
69#endif
da91a00f 70static TCGv cpu_xer, cpu_so, cpu_ov, cpu_ca;
cf360a32 71static TCGv cpu_reserve;
30304420 72static TCGv cpu_fpscr;
a7859e89 73static TCGv_i32 cpu_access_type;
f78fb44e 74
022c62cb 75#include "exec/gen-icount.h"
2e70f6ef
PB
76
77void ppc_translate_init(void)
78{
f78fb44e
AJ
79 int i;
80 char* p;
2dc766da 81 size_t cpu_reg_names_size;
b2437bf2 82 static int done_init = 0;
f78fb44e 83
2e70f6ef
PB
84 if (done_init)
85 return;
f78fb44e 86
a7812ae4 87 cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
a7812ae4 88
f78fb44e 89 p = cpu_reg_names;
2dc766da 90 cpu_reg_names_size = sizeof(cpu_reg_names);
47e4661c
AJ
91
92 for (i = 0; i < 8; i++) {
2dc766da 93 snprintf(p, cpu_reg_names_size, "crf%d", i);
a7812ae4 94 cpu_crf[i] = tcg_global_mem_new_i32(TCG_AREG0,
1328c2bf 95 offsetof(CPUPPCState, crf[i]), p);
47e4661c 96 p += 5;
2dc766da 97 cpu_reg_names_size -= 5;
47e4661c
AJ
98 }
99
f78fb44e 100 for (i = 0; i < 32; i++) {
2dc766da 101 snprintf(p, cpu_reg_names_size, "r%d", i);
a7812ae4 102 cpu_gpr[i] = tcg_global_mem_new(TCG_AREG0,
1328c2bf 103 offsetof(CPUPPCState, gpr[i]), p);
f78fb44e 104 p += (i < 10) ? 3 : 4;
2dc766da 105 cpu_reg_names_size -= (i < 10) ? 3 : 4;
f78fb44e 106#if !defined(TARGET_PPC64)
2dc766da 107 snprintf(p, cpu_reg_names_size, "r%dH", i);
a7812ae4 108 cpu_gprh[i] = tcg_global_mem_new_i32(TCG_AREG0,
1328c2bf 109 offsetof(CPUPPCState, gprh[i]), p);
f78fb44e 110 p += (i < 10) ? 4 : 5;
2dc766da 111 cpu_reg_names_size -= (i < 10) ? 4 : 5;
f78fb44e 112#endif
1d542695 113
2dc766da 114 snprintf(p, cpu_reg_names_size, "fp%d", i);
a7812ae4 115 cpu_fpr[i] = tcg_global_mem_new_i64(TCG_AREG0,
1328c2bf 116 offsetof(CPUPPCState, fpr[i]), p);
ec1ac72d 117 p += (i < 10) ? 4 : 5;
2dc766da 118 cpu_reg_names_size -= (i < 10) ? 4 : 5;
a5e26afa 119
2dc766da 120 snprintf(p, cpu_reg_names_size, "avr%dH", i);
e2542fe2 121#ifdef HOST_WORDS_BIGENDIAN
fe1e5c53 122 cpu_avrh[i] = tcg_global_mem_new_i64(TCG_AREG0,
1328c2bf 123 offsetof(CPUPPCState, avr[i].u64[0]), p);
fe1e5c53 124#else
a7812ae4 125 cpu_avrh[i] = tcg_global_mem_new_i64(TCG_AREG0,
1328c2bf 126 offsetof(CPUPPCState, avr[i].u64[1]), p);
fe1e5c53 127#endif
1d542695 128 p += (i < 10) ? 6 : 7;
2dc766da 129 cpu_reg_names_size -= (i < 10) ? 6 : 7;
ec1ac72d 130
2dc766da 131 snprintf(p, cpu_reg_names_size, "avr%dL", i);
e2542fe2 132#ifdef HOST_WORDS_BIGENDIAN
fe1e5c53 133 cpu_avrl[i] = tcg_global_mem_new_i64(TCG_AREG0,
1328c2bf 134 offsetof(CPUPPCState, avr[i].u64[1]), p);
fe1e5c53 135#else
a7812ae4 136 cpu_avrl[i] = tcg_global_mem_new_i64(TCG_AREG0,
1328c2bf 137 offsetof(CPUPPCState, avr[i].u64[0]), p);
fe1e5c53 138#endif
1d542695 139 p += (i < 10) ? 6 : 7;
2dc766da 140 cpu_reg_names_size -= (i < 10) ? 6 : 7;
472b24ce
TM
141 snprintf(p, cpu_reg_names_size, "vsr%d", i);
142 cpu_vsr[i] = tcg_global_mem_new_i64(TCG_AREG0,
143 offsetof(CPUPPCState, vsr[i]), p);
144 p += (i < 10) ? 5 : 6;
145 cpu_reg_names_size -= (i < 10) ? 5 : 6;
f78fb44e 146 }
f10dc08e 147
a7812ae4 148 cpu_nip = tcg_global_mem_new(TCG_AREG0,
1328c2bf 149 offsetof(CPUPPCState, nip), "nip");
bd568f18 150
6527f6ea 151 cpu_msr = tcg_global_mem_new(TCG_AREG0,
1328c2bf 152 offsetof(CPUPPCState, msr), "msr");
6527f6ea 153
a7812ae4 154 cpu_ctr = tcg_global_mem_new(TCG_AREG0,
1328c2bf 155 offsetof(CPUPPCState, ctr), "ctr");
cfdcd37a 156
a7812ae4 157 cpu_lr = tcg_global_mem_new(TCG_AREG0,
1328c2bf 158 offsetof(CPUPPCState, lr), "lr");
cfdcd37a 159
697ab892
DG
160#if defined(TARGET_PPC64)
161 cpu_cfar = tcg_global_mem_new(TCG_AREG0,
1328c2bf 162 offsetof(CPUPPCState, cfar), "cfar");
697ab892
DG
163#endif
164
a7812ae4 165 cpu_xer = tcg_global_mem_new(TCG_AREG0,
1328c2bf 166 offsetof(CPUPPCState, xer), "xer");
da91a00f
RH
167 cpu_so = tcg_global_mem_new(TCG_AREG0,
168 offsetof(CPUPPCState, so), "SO");
169 cpu_ov = tcg_global_mem_new(TCG_AREG0,
170 offsetof(CPUPPCState, ov), "OV");
171 cpu_ca = tcg_global_mem_new(TCG_AREG0,
172 offsetof(CPUPPCState, ca), "CA");
3d7b417e 173
cf360a32 174 cpu_reserve = tcg_global_mem_new(TCG_AREG0,
1328c2bf 175 offsetof(CPUPPCState, reserve_addr),
18b21a2f 176 "reserve_addr");
cf360a32 177
30304420
DG
178 cpu_fpscr = tcg_global_mem_new(TCG_AREG0,
179 offsetof(CPUPPCState, fpscr), "fpscr");
e1571908 180
a7859e89 181 cpu_access_type = tcg_global_mem_new_i32(TCG_AREG0,
1328c2bf 182 offsetof(CPUPPCState, access_type), "access_type");
a7859e89 183
2e70f6ef
PB
184 done_init = 1;
185}
186
79aceca5
FB
187/* internal defines */
188typedef struct DisasContext {
189 struct TranslationBlock *tb;
0fa85d43 190 target_ulong nip;
79aceca5 191 uint32_t opcode;
9a64fbe4 192 uint32_t exception;
3cc62370
FB
193 /* Routine used to access memory */
194 int mem_idx;
76db3ba4 195 int access_type;
3cc62370 196 /* Translation flags */
76db3ba4 197 int le_mode;
d9bce9d9
JM
198#if defined(TARGET_PPC64)
199 int sf_mode;
697ab892 200 int has_cfar;
9a64fbe4 201#endif
3cc62370 202 int fpu_enabled;
a9d9eb8f 203 int altivec_enabled;
1f29871c 204 int vsx_enabled;
0487d6a8 205 int spe_enabled;
c227f099 206 ppc_spr_t *spr_cb; /* Needed to check rights for mfspr/mtspr */
ea4e754f 207 int singlestep_enabled;
7d08d856
AJ
208 uint64_t insns_flags;
209 uint64_t insns_flags2;
79aceca5
FB
210} DisasContext;
211
79482e5a
RH
212/* True when active word size < size of target_long. */
213#ifdef TARGET_PPC64
214# define NARROW_MODE(C) (!(C)->sf_mode)
215#else
216# define NARROW_MODE(C) 0
217#endif
218
c227f099 219struct opc_handler_t {
70560da7
FC
220 /* invalid bits for instruction 1 (Rc(opcode) == 0) */
221 uint32_t inval1;
222 /* invalid bits for instruction 2 (Rc(opcode) == 1) */
223 uint32_t inval2;
9a64fbe4 224 /* instruction type */
0487d6a8 225 uint64_t type;
a5858d7a
AG
226 /* extended instruction type */
227 uint64_t type2;
79aceca5
FB
228 /* handler */
229 void (*handler)(DisasContext *ctx);
a750fc0b 230#if defined(DO_PPC_STATISTICS) || defined(PPC_DUMP_CPU)
b55266b5 231 const char *oname;
a750fc0b
JM
232#endif
233#if defined(DO_PPC_STATISTICS)
76a66253
JM
234 uint64_t count;
235#endif
3fc6c082 236};
79aceca5 237
636aa200 238static inline void gen_reset_fpstatus(void)
7c58044c 239{
8e703949 240 gen_helper_reset_fpstatus(cpu_env);
7c58044c
JM
241}
242
636aa200 243static inline void gen_compute_fprf(TCGv_i64 arg, int set_fprf, int set_rc)
7c58044c 244{
0f2f39c2 245 TCGv_i32 t0 = tcg_temp_new_i32();
af12906f 246
7c58044c
JM
247 if (set_fprf != 0) {
248 /* This case might be optimized later */
0f2f39c2 249 tcg_gen_movi_i32(t0, 1);
8e703949 250 gen_helper_compute_fprf(t0, cpu_env, arg, t0);
a7812ae4 251 if (unlikely(set_rc)) {
0f2f39c2 252 tcg_gen_mov_i32(cpu_crf[1], t0);
a7812ae4 253 }
8e703949 254 gen_helper_float_check_status(cpu_env);
7c58044c
JM
255 } else if (unlikely(set_rc)) {
256 /* We always need to compute fpcc */
0f2f39c2 257 tcg_gen_movi_i32(t0, 0);
8e703949 258 gen_helper_compute_fprf(t0, cpu_env, arg, t0);
0f2f39c2 259 tcg_gen_mov_i32(cpu_crf[1], t0);
7c58044c 260 }
af12906f 261
0f2f39c2 262 tcg_temp_free_i32(t0);
7c58044c
JM
263}
264
636aa200 265static inline void gen_set_access_type(DisasContext *ctx, int access_type)
a7859e89 266{
76db3ba4
AJ
267 if (ctx->access_type != access_type) {
268 tcg_gen_movi_i32(cpu_access_type, access_type);
269 ctx->access_type = access_type;
270 }
a7859e89
AJ
271}
272
636aa200 273static inline void gen_update_nip(DisasContext *ctx, target_ulong nip)
d9bce9d9 274{
e0c8f9ce
RH
275 if (NARROW_MODE(ctx)) {
276 nip = (uint32_t)nip;
277 }
278 tcg_gen_movi_tl(cpu_nip, nip);
d9bce9d9
JM
279}
280
636aa200 281static inline void gen_exception_err(DisasContext *ctx, uint32_t excp, uint32_t error)
e06fcd75
AJ
282{
283 TCGv_i32 t0, t1;
284 if (ctx->exception == POWERPC_EXCP_NONE) {
285 gen_update_nip(ctx, ctx->nip);
286 }
287 t0 = tcg_const_i32(excp);
288 t1 = tcg_const_i32(error);
e5f17ac6 289 gen_helper_raise_exception_err(cpu_env, t0, t1);
e06fcd75
AJ
290 tcg_temp_free_i32(t0);
291 tcg_temp_free_i32(t1);
292 ctx->exception = (excp);
293}
e1833e1f 294
636aa200 295static inline void gen_exception(DisasContext *ctx, uint32_t excp)
e06fcd75
AJ
296{
297 TCGv_i32 t0;
298 if (ctx->exception == POWERPC_EXCP_NONE) {
299 gen_update_nip(ctx, ctx->nip);
300 }
301 t0 = tcg_const_i32(excp);
e5f17ac6 302 gen_helper_raise_exception(cpu_env, t0);
e06fcd75
AJ
303 tcg_temp_free_i32(t0);
304 ctx->exception = (excp);
305}
e1833e1f 306
636aa200 307static inline void gen_debug_exception(DisasContext *ctx)
e06fcd75
AJ
308{
309 TCGv_i32 t0;
5518f3a6 310
ee2b3994
SB
311 if ((ctx->exception != POWERPC_EXCP_BRANCH) &&
312 (ctx->exception != POWERPC_EXCP_SYNC)) {
5518f3a6 313 gen_update_nip(ctx, ctx->nip);
ee2b3994 314 }
e06fcd75 315 t0 = tcg_const_i32(EXCP_DEBUG);
e5f17ac6 316 gen_helper_raise_exception(cpu_env, t0);
e06fcd75
AJ
317 tcg_temp_free_i32(t0);
318}
9a64fbe4 319
636aa200 320static inline void gen_inval_exception(DisasContext *ctx, uint32_t error)
e06fcd75
AJ
321{
322 gen_exception_err(ctx, POWERPC_EXCP_PROGRAM, POWERPC_EXCP_INVAL | error);
323}
a9d9eb8f 324
f24e5695 325/* Stop translation */
636aa200 326static inline void gen_stop_exception(DisasContext *ctx)
3fc6c082 327{
d9bce9d9 328 gen_update_nip(ctx, ctx->nip);
e1833e1f 329 ctx->exception = POWERPC_EXCP_STOP;
3fc6c082
FB
330}
331
f24e5695 332/* No need to update nip here, as execution flow will change */
636aa200 333static inline void gen_sync_exception(DisasContext *ctx)
2be0071f 334{
e1833e1f 335 ctx->exception = POWERPC_EXCP_SYNC;
2be0071f
FB
336}
337
79aceca5 338#define GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
a5858d7a
AG
339GEN_OPCODE(name, opc1, opc2, opc3, inval, type, PPC_NONE)
340
341#define GEN_HANDLER_E(name, opc1, opc2, opc3, inval, type, type2) \
342GEN_OPCODE(name, opc1, opc2, opc3, inval, type, type2)
79aceca5 343
c7697e1f 344#define GEN_HANDLER2(name, onam, opc1, opc2, opc3, inval, type) \
a5858d7a
AG
345GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, PPC_NONE)
346
347#define GEN_HANDLER2_E(name, onam, opc1, opc2, opc3, inval, type, type2) \
348GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, type2)
c7697e1f 349
c227f099 350typedef struct opcode_t {
79aceca5 351 unsigned char opc1, opc2, opc3;
1235fc06 352#if HOST_LONG_BITS == 64 /* Explicitly align to 64 bits */
18fba28c
FB
353 unsigned char pad[5];
354#else
355 unsigned char pad[1];
356#endif
c227f099 357 opc_handler_t handler;
b55266b5 358 const char *oname;
c227f099 359} opcode_t;
79aceca5 360
a750fc0b 361/*****************************************************************************/
79aceca5
FB
362/*** Instruction decoding ***/
363#define EXTRACT_HELPER(name, shift, nb) \
636aa200 364static inline uint32_t name(uint32_t opcode) \
79aceca5
FB
365{ \
366 return (opcode >> (shift)) & ((1 << (nb)) - 1); \
367}
368
369#define EXTRACT_SHELPER(name, shift, nb) \
636aa200 370static inline int32_t name(uint32_t opcode) \
79aceca5 371{ \
18fba28c 372 return (int16_t)((opcode >> (shift)) & ((1 << (nb)) - 1)); \
79aceca5
FB
373}
374
f9fc6d81
TM
375#define EXTRACT_HELPER_SPLIT(name, shift1, nb1, shift2, nb2) \
376static inline uint32_t name(uint32_t opcode) \
377{ \
378 return (((opcode >> (shift1)) & ((1 << (nb1)) - 1)) << nb2) | \
379 ((opcode >> (shift2)) & ((1 << (nb2)) - 1)); \
380}
79aceca5
FB
381/* Opcode part 1 */
382EXTRACT_HELPER(opc1, 26, 6);
383/* Opcode part 2 */
384EXTRACT_HELPER(opc2, 1, 5);
385/* Opcode part 3 */
386EXTRACT_HELPER(opc3, 6, 5);
387/* Update Cr0 flags */
388EXTRACT_HELPER(Rc, 0, 1);
a737d3eb
TM
389/* Update Cr6 flags (Altivec) */
390EXTRACT_HELPER(Rc21, 10, 1);
79aceca5
FB
391/* Destination */
392EXTRACT_HELPER(rD, 21, 5);
393/* Source */
394EXTRACT_HELPER(rS, 21, 5);
395/* First operand */
396EXTRACT_HELPER(rA, 16, 5);
397/* Second operand */
398EXTRACT_HELPER(rB, 11, 5);
399/* Third operand */
400EXTRACT_HELPER(rC, 6, 5);
401/*** Get CRn ***/
402EXTRACT_HELPER(crfD, 23, 3);
403EXTRACT_HELPER(crfS, 18, 3);
404EXTRACT_HELPER(crbD, 21, 5);
405EXTRACT_HELPER(crbA, 16, 5);
406EXTRACT_HELPER(crbB, 11, 5);
407/* SPR / TBL */
3fc6c082 408EXTRACT_HELPER(_SPR, 11, 10);
636aa200 409static inline uint32_t SPR(uint32_t opcode)
3fc6c082
FB
410{
411 uint32_t sprn = _SPR(opcode);
412
413 return ((sprn >> 5) & 0x1F) | ((sprn & 0x1F) << 5);
414}
79aceca5
FB
415/*** Get constants ***/
416EXTRACT_HELPER(IMM, 12, 8);
417/* 16 bits signed immediate value */
418EXTRACT_SHELPER(SIMM, 0, 16);
419/* 16 bits unsigned immediate value */
420EXTRACT_HELPER(UIMM, 0, 16);
21d21583
AJ
421/* 5 bits signed immediate value */
422EXTRACT_HELPER(SIMM5, 16, 5);
27a4edb3
AJ
423/* 5 bits signed immediate value */
424EXTRACT_HELPER(UIMM5, 16, 5);
79aceca5
FB
425/* Bit count */
426EXTRACT_HELPER(NB, 11, 5);
427/* Shift count */
428EXTRACT_HELPER(SH, 11, 5);
cd633b10
AJ
429/* Vector shift count */
430EXTRACT_HELPER(VSH, 6, 4);
79aceca5
FB
431/* Mask start */
432EXTRACT_HELPER(MB, 6, 5);
433/* Mask end */
434EXTRACT_HELPER(ME, 1, 5);
fb0eaffc
FB
435/* Trap operand */
436EXTRACT_HELPER(TO, 21, 5);
79aceca5
FB
437
438EXTRACT_HELPER(CRM, 12, 8);
79aceca5 439EXTRACT_HELPER(SR, 16, 4);
7d08d856
AJ
440
441/* mtfsf/mtfsfi */
779f6590 442EXTRACT_HELPER(FPBF, 23, 3);
e4bb997e 443EXTRACT_HELPER(FPIMM, 12, 4);
779f6590 444EXTRACT_HELPER(FPL, 25, 1);
7d08d856
AJ
445EXTRACT_HELPER(FPFLM, 17, 8);
446EXTRACT_HELPER(FPW, 16, 1);
fb0eaffc 447
79aceca5
FB
448/*** Jump target decoding ***/
449/* Displacement */
450EXTRACT_SHELPER(d, 0, 16);
451/* Immediate address */
636aa200 452static inline target_ulong LI(uint32_t opcode)
79aceca5
FB
453{
454 return (opcode >> 0) & 0x03FFFFFC;
455}
456
636aa200 457static inline uint32_t BD(uint32_t opcode)
79aceca5
FB
458{
459 return (opcode >> 0) & 0xFFFC;
460}
461
462EXTRACT_HELPER(BO, 21, 5);
463EXTRACT_HELPER(BI, 16, 5);
464/* Absolute/relative address */
465EXTRACT_HELPER(AA, 1, 1);
466/* Link */
467EXTRACT_HELPER(LK, 0, 1);
468
469/* Create a mask between <start> and <end> bits */
636aa200 470static inline target_ulong MASK(uint32_t start, uint32_t end)
79aceca5 471{
76a66253 472 target_ulong ret;
79aceca5 473
76a66253
JM
474#if defined(TARGET_PPC64)
475 if (likely(start == 0)) {
6f2d8978 476 ret = UINT64_MAX << (63 - end);
76a66253 477 } else if (likely(end == 63)) {
6f2d8978 478 ret = UINT64_MAX >> start;
76a66253
JM
479 }
480#else
481 if (likely(start == 0)) {
6f2d8978 482 ret = UINT32_MAX << (31 - end);
76a66253 483 } else if (likely(end == 31)) {
6f2d8978 484 ret = UINT32_MAX >> start;
76a66253
JM
485 }
486#endif
487 else {
488 ret = (((target_ulong)(-1ULL)) >> (start)) ^
489 (((target_ulong)(-1ULL) >> (end)) >> 1);
490 if (unlikely(start > end))
491 return ~ret;
492 }
79aceca5
FB
493
494 return ret;
495}
496
f9fc6d81
TM
497EXTRACT_HELPER_SPLIT(xT, 0, 1, 21, 5);
498EXTRACT_HELPER_SPLIT(xS, 0, 1, 21, 5);
499EXTRACT_HELPER_SPLIT(xA, 2, 1, 16, 5);
500EXTRACT_HELPER_SPLIT(xB, 1, 1, 11, 5);
551e3ef7 501EXTRACT_HELPER_SPLIT(xC, 3, 1, 6, 5);
f9fc6d81 502EXTRACT_HELPER(DM, 8, 2);
76c15fe0 503EXTRACT_HELPER(UIM, 16, 2);
acc42968 504EXTRACT_HELPER(SHW, 8, 2);
a750fc0b 505/*****************************************************************************/
a750fc0b 506/* PowerPC instructions table */
933dc6eb 507
76a66253 508#if defined(DO_PPC_STATISTICS)
a5858d7a 509#define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \
5c55ff99 510{ \
79aceca5
FB
511 .opc1 = op1, \
512 .opc2 = op2, \
513 .opc3 = op3, \
18fba28c 514 .pad = { 0, }, \
79aceca5 515 .handler = { \
70560da7
FC
516 .inval1 = invl, \
517 .type = _typ, \
518 .type2 = _typ2, \
519 .handler = &gen_##name, \
520 .oname = stringify(name), \
521 }, \
522 .oname = stringify(name), \
523}
524#define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \
525{ \
526 .opc1 = op1, \
527 .opc2 = op2, \
528 .opc3 = op3, \
529 .pad = { 0, }, \
530 .handler = { \
531 .inval1 = invl1, \
532 .inval2 = invl2, \
9a64fbe4 533 .type = _typ, \
a5858d7a 534 .type2 = _typ2, \
79aceca5 535 .handler = &gen_##name, \
76a66253 536 .oname = stringify(name), \
79aceca5 537 }, \
3fc6c082 538 .oname = stringify(name), \
79aceca5 539}
a5858d7a 540#define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \
5c55ff99 541{ \
c7697e1f
JM
542 .opc1 = op1, \
543 .opc2 = op2, \
544 .opc3 = op3, \
545 .pad = { 0, }, \
546 .handler = { \
70560da7 547 .inval1 = invl, \
c7697e1f 548 .type = _typ, \
a5858d7a 549 .type2 = _typ2, \
c7697e1f
JM
550 .handler = &gen_##name, \
551 .oname = onam, \
552 }, \
553 .oname = onam, \
554}
76a66253 555#else
a5858d7a 556#define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \
5c55ff99 557{ \
c7697e1f
JM
558 .opc1 = op1, \
559 .opc2 = op2, \
560 .opc3 = op3, \
561 .pad = { 0, }, \
562 .handler = { \
70560da7
FC
563 .inval1 = invl, \
564 .type = _typ, \
565 .type2 = _typ2, \
566 .handler = &gen_##name, \
567 }, \
568 .oname = stringify(name), \
569}
570#define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \
571{ \
572 .opc1 = op1, \
573 .opc2 = op2, \
574 .opc3 = op3, \
575 .pad = { 0, }, \
576 .handler = { \
577 .inval1 = invl1, \
578 .inval2 = invl2, \
c7697e1f 579 .type = _typ, \
a5858d7a 580 .type2 = _typ2, \
c7697e1f 581 .handler = &gen_##name, \
5c55ff99
BS
582 }, \
583 .oname = stringify(name), \
584}
a5858d7a 585#define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \
5c55ff99
BS
586{ \
587 .opc1 = op1, \
588 .opc2 = op2, \
589 .opc3 = op3, \
590 .pad = { 0, }, \
591 .handler = { \
70560da7 592 .inval1 = invl, \
5c55ff99 593 .type = _typ, \
a5858d7a 594 .type2 = _typ2, \
5c55ff99
BS
595 .handler = &gen_##name, \
596 }, \
597 .oname = onam, \
598}
599#endif
2e610050 600
5c55ff99 601/* SPR load/store helpers */
636aa200 602static inline void gen_load_spr(TCGv t, int reg)
5c55ff99 603{
1328c2bf 604 tcg_gen_ld_tl(t, cpu_env, offsetof(CPUPPCState, spr[reg]));
5c55ff99 605}
2e610050 606
636aa200 607static inline void gen_store_spr(int reg, TCGv t)
5c55ff99 608{
1328c2bf 609 tcg_gen_st_tl(t, cpu_env, offsetof(CPUPPCState, spr[reg]));
5c55ff99 610}
2e610050 611
54623277 612/* Invalid instruction */
99e300ef 613static void gen_invalid(DisasContext *ctx)
9a64fbe4 614{
e06fcd75 615 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
9a64fbe4
FB
616}
617
c227f099 618static opc_handler_t invalid_handler = {
70560da7
FC
619 .inval1 = 0xFFFFFFFF,
620 .inval2 = 0xFFFFFFFF,
9a64fbe4 621 .type = PPC_NONE,
a5858d7a 622 .type2 = PPC_NONE,
79aceca5
FB
623 .handler = gen_invalid,
624};
625
71a8c019
TM
626#if defined(TARGET_PPC64)
627/* NOTE: as this time, the only use of is_user_mode() is in 64 bit code. And */
628/* so the function is wrapped in the standard 64-bit ifdef in order to */
629/* avoid compiler warnings in 32-bit implementations. */
630static bool is_user_mode(DisasContext *ctx)
631{
632#if defined(CONFIG_USER_ONLY)
633 return true;
634#else
635 return ctx->mem_idx == 0;
636#endif
637}
638#endif
639
e1571908
AJ
640/*** Integer comparison ***/
641
636aa200 642static inline void gen_op_cmp(TCGv arg0, TCGv arg1, int s, int crf)
e1571908 643{
2fdcb629
RH
644 TCGv t0 = tcg_temp_new();
645 TCGv_i32 t1 = tcg_temp_new_i32();
e1571908 646
da91a00f 647 tcg_gen_trunc_tl_i32(cpu_crf[crf], cpu_so);
e1571908 648
2fdcb629
RH
649 tcg_gen_setcond_tl((s ? TCG_COND_LT: TCG_COND_LTU), t0, arg0, arg1);
650 tcg_gen_trunc_tl_i32(t1, t0);
651 tcg_gen_shli_i32(t1, t1, CRF_LT);
652 tcg_gen_or_i32(cpu_crf[crf], cpu_crf[crf], t1);
653
654 tcg_gen_setcond_tl((s ? TCG_COND_GT: TCG_COND_GTU), t0, arg0, arg1);
655 tcg_gen_trunc_tl_i32(t1, t0);
656 tcg_gen_shli_i32(t1, t1, CRF_GT);
657 tcg_gen_or_i32(cpu_crf[crf], cpu_crf[crf], t1);
658
659 tcg_gen_setcond_tl(TCG_COND_EQ, t0, arg0, arg1);
660 tcg_gen_trunc_tl_i32(t1, t0);
661 tcg_gen_shli_i32(t1, t1, CRF_EQ);
662 tcg_gen_or_i32(cpu_crf[crf], cpu_crf[crf], t1);
663
664 tcg_temp_free(t0);
665 tcg_temp_free_i32(t1);
e1571908
AJ
666}
667
636aa200 668static inline void gen_op_cmpi(TCGv arg0, target_ulong arg1, int s, int crf)
e1571908 669{
2fdcb629 670 TCGv t0 = tcg_const_tl(arg1);
ea363694
AJ
671 gen_op_cmp(arg0, t0, s, crf);
672 tcg_temp_free(t0);
e1571908
AJ
673}
674
636aa200 675static inline void gen_op_cmp32(TCGv arg0, TCGv arg1, int s, int crf)
e1571908 676{
ea363694 677 TCGv t0, t1;
2fdcb629
RH
678 t0 = tcg_temp_new();
679 t1 = tcg_temp_new();
e1571908 680 if (s) {
ea363694
AJ
681 tcg_gen_ext32s_tl(t0, arg0);
682 tcg_gen_ext32s_tl(t1, arg1);
e1571908 683 } else {
ea363694
AJ
684 tcg_gen_ext32u_tl(t0, arg0);
685 tcg_gen_ext32u_tl(t1, arg1);
e1571908 686 }
ea363694
AJ
687 gen_op_cmp(t0, t1, s, crf);
688 tcg_temp_free(t1);
689 tcg_temp_free(t0);
e1571908
AJ
690}
691
636aa200 692static inline void gen_op_cmpi32(TCGv arg0, target_ulong arg1, int s, int crf)
e1571908 693{
2fdcb629 694 TCGv t0 = tcg_const_tl(arg1);
ea363694
AJ
695 gen_op_cmp32(arg0, t0, s, crf);
696 tcg_temp_free(t0);
e1571908 697}
e1571908 698
636aa200 699static inline void gen_set_Rc0(DisasContext *ctx, TCGv reg)
e1571908 700{
02765534 701 if (NARROW_MODE(ctx)) {
e1571908 702 gen_op_cmpi32(reg, 0, 1, 0);
02765534 703 } else {
e1571908 704 gen_op_cmpi(reg, 0, 1, 0);
02765534 705 }
e1571908
AJ
706}
707
708/* cmp */
99e300ef 709static void gen_cmp(DisasContext *ctx)
e1571908 710{
36f48d9c 711 if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) {
e1571908
AJ
712 gen_op_cmp(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
713 1, crfD(ctx->opcode));
36f48d9c
AG
714 } else {
715 gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
716 1, crfD(ctx->opcode));
02765534 717 }
e1571908
AJ
718}
719
720/* cmpi */
99e300ef 721static void gen_cmpi(DisasContext *ctx)
e1571908 722{
36f48d9c 723 if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) {
e1571908
AJ
724 gen_op_cmpi(cpu_gpr[rA(ctx->opcode)], SIMM(ctx->opcode),
725 1, crfD(ctx->opcode));
36f48d9c
AG
726 } else {
727 gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], SIMM(ctx->opcode),
728 1, crfD(ctx->opcode));
02765534 729 }
e1571908
AJ
730}
731
732/* cmpl */
99e300ef 733static void gen_cmpl(DisasContext *ctx)
e1571908 734{
36f48d9c 735 if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) {
e1571908
AJ
736 gen_op_cmp(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
737 0, crfD(ctx->opcode));
36f48d9c
AG
738 } else {
739 gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
740 0, crfD(ctx->opcode));
02765534 741 }
e1571908
AJ
742}
743
744/* cmpli */
99e300ef 745static void gen_cmpli(DisasContext *ctx)
e1571908 746{
36f48d9c 747 if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) {
e1571908
AJ
748 gen_op_cmpi(cpu_gpr[rA(ctx->opcode)], UIMM(ctx->opcode),
749 0, crfD(ctx->opcode));
36f48d9c
AG
750 } else {
751 gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], UIMM(ctx->opcode),
752 0, crfD(ctx->opcode));
02765534 753 }
e1571908
AJ
754}
755
756/* isel (PowerPC 2.03 specification) */
99e300ef 757static void gen_isel(DisasContext *ctx)
e1571908
AJ
758{
759 int l1, l2;
760 uint32_t bi = rC(ctx->opcode);
761 uint32_t mask;
a7812ae4 762 TCGv_i32 t0;
e1571908
AJ
763
764 l1 = gen_new_label();
765 l2 = gen_new_label();
766
767 mask = 1 << (3 - (bi & 0x03));
a7812ae4 768 t0 = tcg_temp_new_i32();
fea0c503
AJ
769 tcg_gen_andi_i32(t0, cpu_crf[bi >> 2], mask);
770 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1);
e1571908
AJ
771 if (rA(ctx->opcode) == 0)
772 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
773 else
774 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
775 tcg_gen_br(l2);
776 gen_set_label(l1);
777 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
778 gen_set_label(l2);
a7812ae4 779 tcg_temp_free_i32(t0);
e1571908
AJ
780}
781
fcfda20f
AJ
782/* cmpb: PowerPC 2.05 specification */
783static void gen_cmpb(DisasContext *ctx)
784{
785 gen_helper_cmpb(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)],
786 cpu_gpr[rB(ctx->opcode)]);
787}
788
79aceca5 789/*** Integer arithmetic ***/
79aceca5 790
636aa200
BS
791static inline void gen_op_arith_compute_ov(DisasContext *ctx, TCGv arg0,
792 TCGv arg1, TCGv arg2, int sub)
74637406 793{
ffe30937 794 TCGv t0 = tcg_temp_new();
79aceca5 795
8e7a6db9 796 tcg_gen_xor_tl(cpu_ov, arg0, arg2);
74637406 797 tcg_gen_xor_tl(t0, arg1, arg2);
ffe30937
RH
798 if (sub) {
799 tcg_gen_and_tl(cpu_ov, cpu_ov, t0);
800 } else {
801 tcg_gen_andc_tl(cpu_ov, cpu_ov, t0);
802 }
803 tcg_temp_free(t0);
02765534 804 if (NARROW_MODE(ctx)) {
ffe30937
RH
805 tcg_gen_ext32s_tl(cpu_ov, cpu_ov);
806 }
ffe30937
RH
807 tcg_gen_shri_tl(cpu_ov, cpu_ov, TARGET_LONG_BITS - 1);
808 tcg_gen_or_tl(cpu_so, cpu_so, cpu_ov);
79aceca5
FB
809}
810
74637406 811/* Common add function */
636aa200 812static inline void gen_op_arith_add(DisasContext *ctx, TCGv ret, TCGv arg1,
b5a73f8d
RH
813 TCGv arg2, bool add_ca, bool compute_ca,
814 bool compute_ov, bool compute_rc0)
74637406 815{
b5a73f8d 816 TCGv t0 = ret;
d9bce9d9 817
752d634e 818 if (compute_ca || compute_ov) {
146de60d 819 t0 = tcg_temp_new();
74637406 820 }
79aceca5 821
da91a00f 822 if (compute_ca) {
79482e5a 823 if (NARROW_MODE(ctx)) {
752d634e
RH
824 /* Caution: a non-obvious corner case of the spec is that we
825 must produce the *entire* 64-bit addition, but produce the
826 carry into bit 32. */
79482e5a 827 TCGv t1 = tcg_temp_new();
752d634e
RH
828 tcg_gen_xor_tl(t1, arg1, arg2); /* add without carry */
829 tcg_gen_add_tl(t0, arg1, arg2);
79482e5a
RH
830 if (add_ca) {
831 tcg_gen_add_tl(t0, t0, cpu_ca);
832 }
752d634e
RH
833 tcg_gen_xor_tl(cpu_ca, t0, t1); /* bits changed w/ carry */
834 tcg_temp_free(t1);
835 tcg_gen_shri_tl(cpu_ca, cpu_ca, 32); /* extract bit 32 */
836 tcg_gen_andi_tl(cpu_ca, cpu_ca, 1);
b5a73f8d 837 } else {
79482e5a
RH
838 TCGv zero = tcg_const_tl(0);
839 if (add_ca) {
840 tcg_gen_add2_tl(t0, cpu_ca, arg1, zero, cpu_ca, zero);
841 tcg_gen_add2_tl(t0, cpu_ca, t0, cpu_ca, arg2, zero);
842 } else {
843 tcg_gen_add2_tl(t0, cpu_ca, arg1, zero, arg2, zero);
844 }
845 tcg_temp_free(zero);
b5a73f8d 846 }
b5a73f8d
RH
847 } else {
848 tcg_gen_add_tl(t0, arg1, arg2);
849 if (add_ca) {
850 tcg_gen_add_tl(t0, t0, cpu_ca);
851 }
da91a00f 852 }
79aceca5 853
74637406
AJ
854 if (compute_ov) {
855 gen_op_arith_compute_ov(ctx, t0, arg1, arg2, 0);
856 }
b5a73f8d 857 if (unlikely(compute_rc0)) {
74637406 858 gen_set_Rc0(ctx, t0);
b5a73f8d 859 }
74637406 860
a7812ae4 861 if (!TCGV_EQUAL(t0, ret)) {
74637406
AJ
862 tcg_gen_mov_tl(ret, t0);
863 tcg_temp_free(t0);
864 }
39dd32ee 865}
74637406
AJ
866/* Add functions with two operands */
867#define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
b5a73f8d 868static void glue(gen_, name)(DisasContext *ctx) \
74637406
AJ
869{ \
870 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
871 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
b5a73f8d 872 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
74637406
AJ
873}
874/* Add functions with one operand and one immediate */
875#define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
876 add_ca, compute_ca, compute_ov) \
b5a73f8d 877static void glue(gen_, name)(DisasContext *ctx) \
74637406 878{ \
b5a73f8d 879 TCGv t0 = tcg_const_tl(const_val); \
74637406
AJ
880 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
881 cpu_gpr[rA(ctx->opcode)], t0, \
b5a73f8d 882 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
74637406
AJ
883 tcg_temp_free(t0); \
884}
885
886/* add add. addo addo. */
887GEN_INT_ARITH_ADD(add, 0x08, 0, 0, 0)
888GEN_INT_ARITH_ADD(addo, 0x18, 0, 0, 1)
889/* addc addc. addco addco. */
890GEN_INT_ARITH_ADD(addc, 0x00, 0, 1, 0)
891GEN_INT_ARITH_ADD(addco, 0x10, 0, 1, 1)
892/* adde adde. addeo addeo. */
893GEN_INT_ARITH_ADD(adde, 0x04, 1, 1, 0)
894GEN_INT_ARITH_ADD(addeo, 0x14, 1, 1, 1)
895/* addme addme. addmeo addmeo. */
896GEN_INT_ARITH_ADD_CONST(addme, 0x07, -1LL, 1, 1, 0)
897GEN_INT_ARITH_ADD_CONST(addmeo, 0x17, -1LL, 1, 1, 1)
898/* addze addze. addzeo addzeo.*/
899GEN_INT_ARITH_ADD_CONST(addze, 0x06, 0, 1, 1, 0)
900GEN_INT_ARITH_ADD_CONST(addzeo, 0x16, 0, 1, 1, 1)
901/* addi */
99e300ef 902static void gen_addi(DisasContext *ctx)
d9bce9d9 903{
74637406
AJ
904 target_long simm = SIMM(ctx->opcode);
905
906 if (rA(ctx->opcode) == 0) {
907 /* li case */
908 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], simm);
909 } else {
b5a73f8d
RH
910 tcg_gen_addi_tl(cpu_gpr[rD(ctx->opcode)],
911 cpu_gpr[rA(ctx->opcode)], simm);
74637406 912 }
d9bce9d9 913}
74637406 914/* addic addic.*/
b5a73f8d 915static inline void gen_op_addic(DisasContext *ctx, bool compute_rc0)
d9bce9d9 916{
b5a73f8d
RH
917 TCGv c = tcg_const_tl(SIMM(ctx->opcode));
918 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
919 c, 0, 1, 0, compute_rc0);
920 tcg_temp_free(c);
d9bce9d9 921}
99e300ef
BS
922
923static void gen_addic(DisasContext *ctx)
d9bce9d9 924{
b5a73f8d 925 gen_op_addic(ctx, 0);
d9bce9d9 926}
e8eaa2c0
BS
927
928static void gen_addic_(DisasContext *ctx)
d9bce9d9 929{
b5a73f8d 930 gen_op_addic(ctx, 1);
d9bce9d9 931}
99e300ef 932
54623277 933/* addis */
99e300ef 934static void gen_addis(DisasContext *ctx)
d9bce9d9 935{
74637406
AJ
936 target_long simm = SIMM(ctx->opcode);
937
938 if (rA(ctx->opcode) == 0) {
939 /* lis case */
940 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], simm << 16);
941 } else {
b5a73f8d
RH
942 tcg_gen_addi_tl(cpu_gpr[rD(ctx->opcode)],
943 cpu_gpr[rA(ctx->opcode)], simm << 16);
74637406 944 }
d9bce9d9 945}
74637406 946
636aa200
BS
947static inline void gen_op_arith_divw(DisasContext *ctx, TCGv ret, TCGv arg1,
948 TCGv arg2, int sign, int compute_ov)
d9bce9d9 949{
2ef1b120
AJ
950 int l1 = gen_new_label();
951 int l2 = gen_new_label();
a7812ae4
PB
952 TCGv_i32 t0 = tcg_temp_local_new_i32();
953 TCGv_i32 t1 = tcg_temp_local_new_i32();
74637406 954
2ef1b120
AJ
955 tcg_gen_trunc_tl_i32(t0, arg1);
956 tcg_gen_trunc_tl_i32(t1, arg2);
957 tcg_gen_brcondi_i32(TCG_COND_EQ, t1, 0, l1);
74637406 958 if (sign) {
2ef1b120
AJ
959 int l3 = gen_new_label();
960 tcg_gen_brcondi_i32(TCG_COND_NE, t1, -1, l3);
961 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, INT32_MIN, l1);
74637406 962 gen_set_label(l3);
2ef1b120 963 tcg_gen_div_i32(t0, t0, t1);
74637406 964 } else {
2ef1b120 965 tcg_gen_divu_i32(t0, t0, t1);
74637406
AJ
966 }
967 if (compute_ov) {
da91a00f 968 tcg_gen_movi_tl(cpu_ov, 0);
74637406
AJ
969 }
970 tcg_gen_br(l2);
971 gen_set_label(l1);
972 if (sign) {
2ef1b120 973 tcg_gen_sari_i32(t0, t0, 31);
74637406
AJ
974 } else {
975 tcg_gen_movi_i32(t0, 0);
976 }
977 if (compute_ov) {
da91a00f
RH
978 tcg_gen_movi_tl(cpu_ov, 1);
979 tcg_gen_movi_tl(cpu_so, 1);
74637406
AJ
980 }
981 gen_set_label(l2);
2ef1b120 982 tcg_gen_extu_i32_tl(ret, t0);
a7812ae4
PB
983 tcg_temp_free_i32(t0);
984 tcg_temp_free_i32(t1);
74637406
AJ
985 if (unlikely(Rc(ctx->opcode) != 0))
986 gen_set_Rc0(ctx, ret);
d9bce9d9 987}
74637406
AJ
988/* Div functions */
989#define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
99e300ef 990static void glue(gen_, name)(DisasContext *ctx) \
74637406
AJ
991{ \
992 gen_op_arith_divw(ctx, cpu_gpr[rD(ctx->opcode)], \
993 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
994 sign, compute_ov); \
995}
996/* divwu divwu. divwuo divwuo. */
997GEN_INT_ARITH_DIVW(divwu, 0x0E, 0, 0);
998GEN_INT_ARITH_DIVW(divwuo, 0x1E, 0, 1);
999/* divw divw. divwo divwo. */
1000GEN_INT_ARITH_DIVW(divw, 0x0F, 1, 0);
1001GEN_INT_ARITH_DIVW(divwo, 0x1F, 1, 1);
98d1eb27
TM
1002
1003/* div[wd]eu[o][.] */
1004#define GEN_DIVE(name, hlpr, compute_ov) \
1005static void gen_##name(DisasContext *ctx) \
1006{ \
1007 TCGv_i32 t0 = tcg_const_i32(compute_ov); \
1008 gen_helper_##hlpr(cpu_gpr[rD(ctx->opcode)], cpu_env, \
1009 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], t0); \
1010 tcg_temp_free_i32(t0); \
1011 if (unlikely(Rc(ctx->opcode) != 0)) { \
1012 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); \
1013 } \
1014}
1015
6a4fda33
TM
1016GEN_DIVE(divweu, divweu, 0);
1017GEN_DIVE(divweuo, divweu, 1);
a98eb9e9
TM
1018GEN_DIVE(divwe, divwe, 0);
1019GEN_DIVE(divweo, divwe, 1);
6a4fda33 1020
d9bce9d9 1021#if defined(TARGET_PPC64)
636aa200
BS
1022static inline void gen_op_arith_divd(DisasContext *ctx, TCGv ret, TCGv arg1,
1023 TCGv arg2, int sign, int compute_ov)
d9bce9d9 1024{
2ef1b120
AJ
1025 int l1 = gen_new_label();
1026 int l2 = gen_new_label();
74637406
AJ
1027
1028 tcg_gen_brcondi_i64(TCG_COND_EQ, arg2, 0, l1);
1029 if (sign) {
2ef1b120 1030 int l3 = gen_new_label();
74637406
AJ
1031 tcg_gen_brcondi_i64(TCG_COND_NE, arg2, -1, l3);
1032 tcg_gen_brcondi_i64(TCG_COND_EQ, arg1, INT64_MIN, l1);
1033 gen_set_label(l3);
74637406
AJ
1034 tcg_gen_div_i64(ret, arg1, arg2);
1035 } else {
1036 tcg_gen_divu_i64(ret, arg1, arg2);
1037 }
1038 if (compute_ov) {
da91a00f 1039 tcg_gen_movi_tl(cpu_ov, 0);
74637406
AJ
1040 }
1041 tcg_gen_br(l2);
1042 gen_set_label(l1);
1043 if (sign) {
1044 tcg_gen_sari_i64(ret, arg1, 63);
1045 } else {
1046 tcg_gen_movi_i64(ret, 0);
1047 }
1048 if (compute_ov) {
da91a00f
RH
1049 tcg_gen_movi_tl(cpu_ov, 1);
1050 tcg_gen_movi_tl(cpu_so, 1);
74637406
AJ
1051 }
1052 gen_set_label(l2);
1053 if (unlikely(Rc(ctx->opcode) != 0))
1054 gen_set_Rc0(ctx, ret);
d9bce9d9 1055}
74637406 1056#define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
99e300ef 1057static void glue(gen_, name)(DisasContext *ctx) \
74637406 1058{ \
2ef1b120
AJ
1059 gen_op_arith_divd(ctx, cpu_gpr[rD(ctx->opcode)], \
1060 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1061 sign, compute_ov); \
74637406
AJ
1062}
1063/* divwu divwu. divwuo divwuo. */
1064GEN_INT_ARITH_DIVD(divdu, 0x0E, 0, 0);
1065GEN_INT_ARITH_DIVD(divduo, 0x1E, 0, 1);
1066/* divw divw. divwo divwo. */
1067GEN_INT_ARITH_DIVD(divd, 0x0F, 1, 0);
1068GEN_INT_ARITH_DIVD(divdo, 0x1F, 1, 1);
98d1eb27
TM
1069
1070GEN_DIVE(divdeu, divdeu, 0);
1071GEN_DIVE(divdeuo, divdeu, 1);
e44259b6
TM
1072GEN_DIVE(divde, divde, 0);
1073GEN_DIVE(divdeo, divde, 1);
d9bce9d9 1074#endif
74637406
AJ
1075
1076/* mulhw mulhw. */
99e300ef 1077static void gen_mulhw(DisasContext *ctx)
d9bce9d9 1078{
23ad1d5d
RH
1079 TCGv_i32 t0 = tcg_temp_new_i32();
1080 TCGv_i32 t1 = tcg_temp_new_i32();
74637406 1081
23ad1d5d
RH
1082 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]);
1083 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]);
1084 tcg_gen_muls2_i32(t0, t1, t0, t1);
1085 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t1);
1086 tcg_temp_free_i32(t0);
1087 tcg_temp_free_i32(t1);
74637406
AJ
1088 if (unlikely(Rc(ctx->opcode) != 0))
1089 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
d9bce9d9 1090}
99e300ef 1091
54623277 1092/* mulhwu mulhwu. */
99e300ef 1093static void gen_mulhwu(DisasContext *ctx)
d9bce9d9 1094{
23ad1d5d
RH
1095 TCGv_i32 t0 = tcg_temp_new_i32();
1096 TCGv_i32 t1 = tcg_temp_new_i32();
74637406 1097
23ad1d5d
RH
1098 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]);
1099 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]);
1100 tcg_gen_mulu2_i32(t0, t1, t0, t1);
1101 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t1);
1102 tcg_temp_free_i32(t0);
1103 tcg_temp_free_i32(t1);
74637406
AJ
1104 if (unlikely(Rc(ctx->opcode) != 0))
1105 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
d9bce9d9 1106}
99e300ef 1107
54623277 1108/* mullw mullw. */
99e300ef 1109static void gen_mullw(DisasContext *ctx)
d9bce9d9 1110{
74637406
AJ
1111 tcg_gen_mul_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1112 cpu_gpr[rB(ctx->opcode)]);
1e4c090f 1113 tcg_gen_ext32s_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)]);
74637406
AJ
1114 if (unlikely(Rc(ctx->opcode) != 0))
1115 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
d9bce9d9 1116}
99e300ef 1117
54623277 1118/* mullwo mullwo. */
99e300ef 1119static void gen_mullwo(DisasContext *ctx)
d9bce9d9 1120{
e4a2c846
RH
1121 TCGv_i32 t0 = tcg_temp_new_i32();
1122 TCGv_i32 t1 = tcg_temp_new_i32();
74637406 1123
e4a2c846
RH
1124 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]);
1125 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]);
1126 tcg_gen_muls2_i32(t0, t1, t0, t1);
1127 tcg_gen_ext_i32_tl(cpu_gpr[rD(ctx->opcode)], t0);
1128
1129 tcg_gen_sari_i32(t0, t0, 31);
1130 tcg_gen_setcond_i32(TCG_COND_NE, t0, t0, t1);
1131 tcg_gen_extu_i32_tl(cpu_ov, t0);
1132 tcg_gen_or_tl(cpu_so, cpu_so, cpu_ov);
1133
1134 tcg_temp_free_i32(t0);
1135 tcg_temp_free_i32(t1);
74637406
AJ
1136 if (unlikely(Rc(ctx->opcode) != 0))
1137 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
d9bce9d9 1138}
99e300ef 1139
54623277 1140/* mulli */
99e300ef 1141static void gen_mulli(DisasContext *ctx)
d9bce9d9 1142{
74637406
AJ
1143 tcg_gen_muli_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1144 SIMM(ctx->opcode));
d9bce9d9 1145}
23ad1d5d 1146
d9bce9d9 1147#if defined(TARGET_PPC64)
74637406 1148/* mulhd mulhd. */
23ad1d5d
RH
1149static void gen_mulhd(DisasContext *ctx)
1150{
1151 TCGv lo = tcg_temp_new();
1152 tcg_gen_muls2_tl(lo, cpu_gpr[rD(ctx->opcode)],
1153 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1154 tcg_temp_free(lo);
1155 if (unlikely(Rc(ctx->opcode) != 0)) {
1156 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1157 }
1158}
1159
74637406 1160/* mulhdu mulhdu. */
23ad1d5d
RH
1161static void gen_mulhdu(DisasContext *ctx)
1162{
1163 TCGv lo = tcg_temp_new();
1164 tcg_gen_mulu2_tl(lo, cpu_gpr[rD(ctx->opcode)],
1165 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1166 tcg_temp_free(lo);
1167 if (unlikely(Rc(ctx->opcode) != 0)) {
1168 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1169 }
1170}
99e300ef 1171
54623277 1172/* mulld mulld. */
99e300ef 1173static void gen_mulld(DisasContext *ctx)
d9bce9d9 1174{
74637406
AJ
1175 tcg_gen_mul_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1176 cpu_gpr[rB(ctx->opcode)]);
1177 if (unlikely(Rc(ctx->opcode) != 0))
1178 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
d9bce9d9 1179}
d15f74fb 1180
74637406 1181/* mulldo mulldo. */
d15f74fb
BS
1182static void gen_mulldo(DisasContext *ctx)
1183{
1184 gen_helper_mulldo(cpu_gpr[rD(ctx->opcode)], cpu_env,
1185 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1186 if (unlikely(Rc(ctx->opcode) != 0)) {
1187 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1188 }
1189}
d9bce9d9 1190#endif
74637406 1191
74637406 1192/* Common subf function */
636aa200 1193static inline void gen_op_arith_subf(DisasContext *ctx, TCGv ret, TCGv arg1,
b5a73f8d
RH
1194 TCGv arg2, bool add_ca, bool compute_ca,
1195 bool compute_ov, bool compute_rc0)
79aceca5 1196{
b5a73f8d 1197 TCGv t0 = ret;
79aceca5 1198
752d634e 1199 if (compute_ca || compute_ov) {
b5a73f8d 1200 t0 = tcg_temp_new();
da91a00f 1201 }
74637406 1202
79482e5a
RH
1203 if (compute_ca) {
1204 /* dest = ~arg1 + arg2 [+ ca]. */
1205 if (NARROW_MODE(ctx)) {
752d634e
RH
1206 /* Caution: a non-obvious corner case of the spec is that we
1207 must produce the *entire* 64-bit addition, but produce the
1208 carry into bit 32. */
79482e5a 1209 TCGv inv1 = tcg_temp_new();
752d634e 1210 TCGv t1 = tcg_temp_new();
79482e5a 1211 tcg_gen_not_tl(inv1, arg1);
79482e5a 1212 if (add_ca) {
752d634e 1213 tcg_gen_add_tl(t0, arg2, cpu_ca);
79482e5a 1214 } else {
752d634e 1215 tcg_gen_addi_tl(t0, arg2, 1);
79482e5a 1216 }
752d634e 1217 tcg_gen_xor_tl(t1, arg2, inv1); /* add without carry */
79482e5a 1218 tcg_gen_add_tl(t0, t0, inv1);
752d634e
RH
1219 tcg_gen_xor_tl(cpu_ca, t0, t1); /* bits changes w/ carry */
1220 tcg_temp_free(t1);
1221 tcg_gen_shri_tl(cpu_ca, cpu_ca, 32); /* extract bit 32 */
1222 tcg_gen_andi_tl(cpu_ca, cpu_ca, 1);
79482e5a 1223 } else if (add_ca) {
08f4a0f7
RH
1224 TCGv zero, inv1 = tcg_temp_new();
1225 tcg_gen_not_tl(inv1, arg1);
b5a73f8d
RH
1226 zero = tcg_const_tl(0);
1227 tcg_gen_add2_tl(t0, cpu_ca, arg2, zero, cpu_ca, zero);
08f4a0f7 1228 tcg_gen_add2_tl(t0, cpu_ca, t0, cpu_ca, inv1, zero);
b5a73f8d 1229 tcg_temp_free(zero);
08f4a0f7 1230 tcg_temp_free(inv1);
b5a73f8d 1231 } else {
79482e5a 1232 tcg_gen_setcond_tl(TCG_COND_GEU, cpu_ca, arg2, arg1);
b5a73f8d 1233 tcg_gen_sub_tl(t0, arg2, arg1);
b5a73f8d 1234 }
79482e5a
RH
1235 } else if (add_ca) {
1236 /* Since we're ignoring carry-out, we can simplify the
1237 standard ~arg1 + arg2 + ca to arg2 - arg1 + ca - 1. */
1238 tcg_gen_sub_tl(t0, arg2, arg1);
1239 tcg_gen_add_tl(t0, t0, cpu_ca);
1240 tcg_gen_subi_tl(t0, t0, 1);
79aceca5 1241 } else {
b5a73f8d 1242 tcg_gen_sub_tl(t0, arg2, arg1);
74637406 1243 }
b5a73f8d 1244
74637406
AJ
1245 if (compute_ov) {
1246 gen_op_arith_compute_ov(ctx, t0, arg1, arg2, 1);
1247 }
b5a73f8d 1248 if (unlikely(compute_rc0)) {
74637406 1249 gen_set_Rc0(ctx, t0);
b5a73f8d 1250 }
74637406 1251
a7812ae4 1252 if (!TCGV_EQUAL(t0, ret)) {
74637406
AJ
1253 tcg_gen_mov_tl(ret, t0);
1254 tcg_temp_free(t0);
79aceca5 1255 }
79aceca5 1256}
74637406
AJ
1257/* Sub functions with Two operands functions */
1258#define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
b5a73f8d 1259static void glue(gen_, name)(DisasContext *ctx) \
74637406
AJ
1260{ \
1261 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1262 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
b5a73f8d 1263 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
74637406
AJ
1264}
1265/* Sub functions with one operand and one immediate */
1266#define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
1267 add_ca, compute_ca, compute_ov) \
b5a73f8d 1268static void glue(gen_, name)(DisasContext *ctx) \
74637406 1269{ \
b5a73f8d 1270 TCGv t0 = tcg_const_tl(const_val); \
74637406
AJ
1271 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1272 cpu_gpr[rA(ctx->opcode)], t0, \
b5a73f8d 1273 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
74637406
AJ
1274 tcg_temp_free(t0); \
1275}
1276/* subf subf. subfo subfo. */
1277GEN_INT_ARITH_SUBF(subf, 0x01, 0, 0, 0)
1278GEN_INT_ARITH_SUBF(subfo, 0x11, 0, 0, 1)
1279/* subfc subfc. subfco subfco. */
1280GEN_INT_ARITH_SUBF(subfc, 0x00, 0, 1, 0)
1281GEN_INT_ARITH_SUBF(subfco, 0x10, 0, 1, 1)
1282/* subfe subfe. subfeo subfo. */
1283GEN_INT_ARITH_SUBF(subfe, 0x04, 1, 1, 0)
1284GEN_INT_ARITH_SUBF(subfeo, 0x14, 1, 1, 1)
1285/* subfme subfme. subfmeo subfmeo. */
1286GEN_INT_ARITH_SUBF_CONST(subfme, 0x07, -1LL, 1, 1, 0)
1287GEN_INT_ARITH_SUBF_CONST(subfmeo, 0x17, -1LL, 1, 1, 1)
1288/* subfze subfze. subfzeo subfzeo.*/
1289GEN_INT_ARITH_SUBF_CONST(subfze, 0x06, 0, 1, 1, 0)
1290GEN_INT_ARITH_SUBF_CONST(subfzeo, 0x16, 0, 1, 1, 1)
99e300ef 1291
54623277 1292/* subfic */
99e300ef 1293static void gen_subfic(DisasContext *ctx)
79aceca5 1294{
b5a73f8d
RH
1295 TCGv c = tcg_const_tl(SIMM(ctx->opcode));
1296 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1297 c, 0, 1, 0, 0);
1298 tcg_temp_free(c);
79aceca5
FB
1299}
1300
fd3f0081
RH
1301/* neg neg. nego nego. */
1302static inline void gen_op_arith_neg(DisasContext *ctx, bool compute_ov)
1303{
1304 TCGv zero = tcg_const_tl(0);
1305 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1306 zero, 0, 0, compute_ov, Rc(ctx->opcode));
1307 tcg_temp_free(zero);
1308}
1309
1310static void gen_neg(DisasContext *ctx)
1311{
1312 gen_op_arith_neg(ctx, 0);
1313}
1314
1315static void gen_nego(DisasContext *ctx)
1316{
1317 gen_op_arith_neg(ctx, 1);
1318}
1319
79aceca5 1320/*** Integer logical ***/
26d67362 1321#define GEN_LOGICAL2(name, tcg_op, opc, type) \
99e300ef 1322static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 1323{ \
26d67362
AJ
1324 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], \
1325 cpu_gpr[rB(ctx->opcode)]); \
76a66253 1326 if (unlikely(Rc(ctx->opcode) != 0)) \
26d67362 1327 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
79aceca5 1328}
79aceca5 1329
26d67362 1330#define GEN_LOGICAL1(name, tcg_op, opc, type) \
99e300ef 1331static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 1332{ \
26d67362 1333 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); \
76a66253 1334 if (unlikely(Rc(ctx->opcode) != 0)) \
26d67362 1335 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
79aceca5
FB
1336}
1337
1338/* and & and. */
26d67362 1339GEN_LOGICAL2(and, tcg_gen_and_tl, 0x00, PPC_INTEGER);
79aceca5 1340/* andc & andc. */
26d67362 1341GEN_LOGICAL2(andc, tcg_gen_andc_tl, 0x01, PPC_INTEGER);
e8eaa2c0 1342
54623277 1343/* andi. */
e8eaa2c0 1344static void gen_andi_(DisasContext *ctx)
79aceca5 1345{
26d67362
AJ
1346 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], UIMM(ctx->opcode));
1347 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
79aceca5 1348}
e8eaa2c0 1349
54623277 1350/* andis. */
e8eaa2c0 1351static void gen_andis_(DisasContext *ctx)
79aceca5 1352{
26d67362
AJ
1353 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], UIMM(ctx->opcode) << 16);
1354 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
79aceca5 1355}
99e300ef 1356
54623277 1357/* cntlzw */
99e300ef 1358static void gen_cntlzw(DisasContext *ctx)
26d67362 1359{
a7812ae4 1360 gen_helper_cntlzw(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
26d67362 1361 if (unlikely(Rc(ctx->opcode) != 0))
2e31f5d3 1362 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
26d67362 1363}
79aceca5 1364/* eqv & eqv. */
26d67362 1365GEN_LOGICAL2(eqv, tcg_gen_eqv_tl, 0x08, PPC_INTEGER);
79aceca5 1366/* extsb & extsb. */
26d67362 1367GEN_LOGICAL1(extsb, tcg_gen_ext8s_tl, 0x1D, PPC_INTEGER);
79aceca5 1368/* extsh & extsh. */
26d67362 1369GEN_LOGICAL1(extsh, tcg_gen_ext16s_tl, 0x1C, PPC_INTEGER);
79aceca5 1370/* nand & nand. */
26d67362 1371GEN_LOGICAL2(nand, tcg_gen_nand_tl, 0x0E, PPC_INTEGER);
79aceca5 1372/* nor & nor. */
26d67362 1373GEN_LOGICAL2(nor, tcg_gen_nor_tl, 0x03, PPC_INTEGER);
99e300ef 1374
54623277 1375/* or & or. */
99e300ef 1376static void gen_or(DisasContext *ctx)
9a64fbe4 1377{
76a66253
JM
1378 int rs, ra, rb;
1379
1380 rs = rS(ctx->opcode);
1381 ra = rA(ctx->opcode);
1382 rb = rB(ctx->opcode);
1383 /* Optimisation for mr. ri case */
1384 if (rs != ra || rs != rb) {
26d67362
AJ
1385 if (rs != rb)
1386 tcg_gen_or_tl(cpu_gpr[ra], cpu_gpr[rs], cpu_gpr[rb]);
1387 else
1388 tcg_gen_mov_tl(cpu_gpr[ra], cpu_gpr[rs]);
76a66253 1389 if (unlikely(Rc(ctx->opcode) != 0))
26d67362 1390 gen_set_Rc0(ctx, cpu_gpr[ra]);
76a66253 1391 } else if (unlikely(Rc(ctx->opcode) != 0)) {
26d67362 1392 gen_set_Rc0(ctx, cpu_gpr[rs]);
c80f84e3
JM
1393#if defined(TARGET_PPC64)
1394 } else {
26d67362
AJ
1395 int prio = 0;
1396
c80f84e3
JM
1397 switch (rs) {
1398 case 1:
1399 /* Set process priority to low */
26d67362 1400 prio = 2;
c80f84e3
JM
1401 break;
1402 case 6:
1403 /* Set process priority to medium-low */
26d67362 1404 prio = 3;
c80f84e3
JM
1405 break;
1406 case 2:
1407 /* Set process priority to normal */
26d67362 1408 prio = 4;
c80f84e3 1409 break;
be147d08
JM
1410#if !defined(CONFIG_USER_ONLY)
1411 case 31:
76db3ba4 1412 if (ctx->mem_idx > 0) {
be147d08 1413 /* Set process priority to very low */
26d67362 1414 prio = 1;
be147d08
JM
1415 }
1416 break;
1417 case 5:
76db3ba4 1418 if (ctx->mem_idx > 0) {
be147d08 1419 /* Set process priority to medium-hight */
26d67362 1420 prio = 5;
be147d08
JM
1421 }
1422 break;
1423 case 3:
76db3ba4 1424 if (ctx->mem_idx > 0) {
be147d08 1425 /* Set process priority to high */
26d67362 1426 prio = 6;
be147d08
JM
1427 }
1428 break;
be147d08 1429 case 7:
76db3ba4 1430 if (ctx->mem_idx > 1) {
be147d08 1431 /* Set process priority to very high */
26d67362 1432 prio = 7;
be147d08
JM
1433 }
1434 break;
be147d08 1435#endif
c80f84e3
JM
1436 default:
1437 /* nop */
1438 break;
1439 }
26d67362 1440 if (prio) {
a7812ae4 1441 TCGv t0 = tcg_temp_new();
54cdcae6 1442 gen_load_spr(t0, SPR_PPR);
ea363694
AJ
1443 tcg_gen_andi_tl(t0, t0, ~0x001C000000000000ULL);
1444 tcg_gen_ori_tl(t0, t0, ((uint64_t)prio) << 50);
54cdcae6 1445 gen_store_spr(SPR_PPR, t0);
ea363694 1446 tcg_temp_free(t0);
26d67362 1447 }
c80f84e3 1448#endif
9a64fbe4 1449 }
9a64fbe4 1450}
79aceca5 1451/* orc & orc. */
26d67362 1452GEN_LOGICAL2(orc, tcg_gen_orc_tl, 0x0C, PPC_INTEGER);
99e300ef 1453
54623277 1454/* xor & xor. */
99e300ef 1455static void gen_xor(DisasContext *ctx)
9a64fbe4 1456{
9a64fbe4 1457 /* Optimisation for "set to zero" case */
26d67362 1458 if (rS(ctx->opcode) != rB(ctx->opcode))
312179c4 1459 tcg_gen_xor_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
26d67362
AJ
1460 else
1461 tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
76a66253 1462 if (unlikely(Rc(ctx->opcode) != 0))
26d67362 1463 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
9a64fbe4 1464}
99e300ef 1465
54623277 1466/* ori */
99e300ef 1467static void gen_ori(DisasContext *ctx)
79aceca5 1468{
76a66253 1469 target_ulong uimm = UIMM(ctx->opcode);
79aceca5 1470
9a64fbe4
FB
1471 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1472 /* NOP */
76a66253 1473 /* XXX: should handle special NOPs for POWER series */
9a64fbe4 1474 return;
76a66253 1475 }
26d67362 1476 tcg_gen_ori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm);
79aceca5 1477}
99e300ef 1478
54623277 1479/* oris */
99e300ef 1480static void gen_oris(DisasContext *ctx)
79aceca5 1481{
76a66253 1482 target_ulong uimm = UIMM(ctx->opcode);
79aceca5 1483
9a64fbe4
FB
1484 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1485 /* NOP */
1486 return;
76a66253 1487 }
26d67362 1488 tcg_gen_ori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm << 16);
79aceca5 1489}
99e300ef 1490
54623277 1491/* xori */
99e300ef 1492static void gen_xori(DisasContext *ctx)
79aceca5 1493{
76a66253 1494 target_ulong uimm = UIMM(ctx->opcode);
9a64fbe4
FB
1495
1496 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1497 /* NOP */
1498 return;
1499 }
26d67362 1500 tcg_gen_xori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm);
79aceca5 1501}
99e300ef 1502
54623277 1503/* xoris */
99e300ef 1504static void gen_xoris(DisasContext *ctx)
79aceca5 1505{
76a66253 1506 target_ulong uimm = UIMM(ctx->opcode);
9a64fbe4
FB
1507
1508 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1509 /* NOP */
1510 return;
1511 }
26d67362 1512 tcg_gen_xori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm << 16);
79aceca5 1513}
99e300ef 1514
54623277 1515/* popcntb : PowerPC 2.03 specification */
99e300ef 1516static void gen_popcntb(DisasContext *ctx)
d9bce9d9 1517{
eaabeef2
DG
1518 gen_helper_popcntb(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1519}
1520
1521static void gen_popcntw(DisasContext *ctx)
1522{
1523 gen_helper_popcntw(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1524}
1525
d9bce9d9 1526#if defined(TARGET_PPC64)
eaabeef2
DG
1527/* popcntd: PowerPC 2.06 specification */
1528static void gen_popcntd(DisasContext *ctx)
1529{
1530 gen_helper_popcntd(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
d9bce9d9 1531}
eaabeef2 1532#endif
d9bce9d9 1533
725bcec2
AJ
1534/* prtyw: PowerPC 2.05 specification */
1535static void gen_prtyw(DisasContext *ctx)
1536{
1537 TCGv ra = cpu_gpr[rA(ctx->opcode)];
1538 TCGv rs = cpu_gpr[rS(ctx->opcode)];
1539 TCGv t0 = tcg_temp_new();
1540 tcg_gen_shri_tl(t0, rs, 16);
1541 tcg_gen_xor_tl(ra, rs, t0);
1542 tcg_gen_shri_tl(t0, ra, 8);
1543 tcg_gen_xor_tl(ra, ra, t0);
1544 tcg_gen_andi_tl(ra, ra, (target_ulong)0x100000001ULL);
1545 tcg_temp_free(t0);
1546}
1547
1548#if defined(TARGET_PPC64)
1549/* prtyd: PowerPC 2.05 specification */
1550static void gen_prtyd(DisasContext *ctx)
1551{
1552 TCGv ra = cpu_gpr[rA(ctx->opcode)];
1553 TCGv rs = cpu_gpr[rS(ctx->opcode)];
1554 TCGv t0 = tcg_temp_new();
1555 tcg_gen_shri_tl(t0, rs, 32);
1556 tcg_gen_xor_tl(ra, rs, t0);
1557 tcg_gen_shri_tl(t0, ra, 16);
1558 tcg_gen_xor_tl(ra, ra, t0);
1559 tcg_gen_shri_tl(t0, ra, 8);
1560 tcg_gen_xor_tl(ra, ra, t0);
1561 tcg_gen_andi_tl(ra, ra, 1);
1562 tcg_temp_free(t0);
1563}
1564#endif
1565
86ba37ed
TM
1566#if defined(TARGET_PPC64)
1567/* bpermd */
1568static void gen_bpermd(DisasContext *ctx)
1569{
1570 gen_helper_bpermd(cpu_gpr[rA(ctx->opcode)],
1571 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1572}
1573#endif
1574
d9bce9d9
JM
1575#if defined(TARGET_PPC64)
1576/* extsw & extsw. */
26d67362 1577GEN_LOGICAL1(extsw, tcg_gen_ext32s_tl, 0x1E, PPC_64B);
99e300ef 1578
54623277 1579/* cntlzd */
99e300ef 1580static void gen_cntlzd(DisasContext *ctx)
26d67362 1581{
a7812ae4 1582 gen_helper_cntlzd(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
26d67362
AJ
1583 if (unlikely(Rc(ctx->opcode) != 0))
1584 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1585}
d9bce9d9
JM
1586#endif
1587
79aceca5 1588/*** Integer rotate ***/
99e300ef 1589
54623277 1590/* rlwimi & rlwimi. */
99e300ef 1591static void gen_rlwimi(DisasContext *ctx)
79aceca5 1592{
76a66253 1593 uint32_t mb, me, sh;
79aceca5
FB
1594
1595 mb = MB(ctx->opcode);
1596 me = ME(ctx->opcode);
76a66253 1597 sh = SH(ctx->opcode);
d03ef511
AJ
1598 if (likely(sh == 0 && mb == 0 && me == 31)) {
1599 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1600 } else {
d03ef511 1601 target_ulong mask;
a7812ae4
PB
1602 TCGv t1;
1603 TCGv t0 = tcg_temp_new();
54843a58 1604#if defined(TARGET_PPC64)
a7812ae4
PB
1605 TCGv_i32 t2 = tcg_temp_new_i32();
1606 tcg_gen_trunc_i64_i32(t2, cpu_gpr[rS(ctx->opcode)]);
1607 tcg_gen_rotli_i32(t2, t2, sh);
1608 tcg_gen_extu_i32_i64(t0, t2);
1609 tcg_temp_free_i32(t2);
54843a58
AJ
1610#else
1611 tcg_gen_rotli_i32(t0, cpu_gpr[rS(ctx->opcode)], sh);
1612#endif
76a66253 1613#if defined(TARGET_PPC64)
d03ef511
AJ
1614 mb += 32;
1615 me += 32;
76a66253 1616#endif
d03ef511 1617 mask = MASK(mb, me);
a7812ae4 1618 t1 = tcg_temp_new();
d03ef511
AJ
1619 tcg_gen_andi_tl(t0, t0, mask);
1620 tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], ~mask);
1621 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1622 tcg_temp_free(t0);
1623 tcg_temp_free(t1);
1624 }
76a66253 1625 if (unlikely(Rc(ctx->opcode) != 0))
d03ef511 1626 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
79aceca5 1627}
99e300ef 1628
54623277 1629/* rlwinm & rlwinm. */
99e300ef 1630static void gen_rlwinm(DisasContext *ctx)
79aceca5
FB
1631{
1632 uint32_t mb, me, sh;
3b46e624 1633
79aceca5
FB
1634 sh = SH(ctx->opcode);
1635 mb = MB(ctx->opcode);
1636 me = ME(ctx->opcode);
d03ef511
AJ
1637
1638 if (likely(mb == 0 && me == (31 - sh))) {
1639 if (likely(sh == 0)) {
1640 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1641 } else {
a7812ae4 1642 TCGv t0 = tcg_temp_new();
d03ef511
AJ
1643 tcg_gen_ext32u_tl(t0, cpu_gpr[rS(ctx->opcode)]);
1644 tcg_gen_shli_tl(t0, t0, sh);
1645 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], t0);
1646 tcg_temp_free(t0);
79aceca5 1647 }
d03ef511 1648 } else if (likely(sh != 0 && me == 31 && sh == (32 - mb))) {
a7812ae4 1649 TCGv t0 = tcg_temp_new();
d03ef511
AJ
1650 tcg_gen_ext32u_tl(t0, cpu_gpr[rS(ctx->opcode)]);
1651 tcg_gen_shri_tl(t0, t0, mb);
1652 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], t0);
1653 tcg_temp_free(t0);
1654 } else {
a7812ae4 1655 TCGv t0 = tcg_temp_new();
54843a58 1656#if defined(TARGET_PPC64)
a7812ae4 1657 TCGv_i32 t1 = tcg_temp_new_i32();
54843a58
AJ
1658 tcg_gen_trunc_i64_i32(t1, cpu_gpr[rS(ctx->opcode)]);
1659 tcg_gen_rotli_i32(t1, t1, sh);
1660 tcg_gen_extu_i32_i64(t0, t1);
a7812ae4 1661 tcg_temp_free_i32(t1);
54843a58
AJ
1662#else
1663 tcg_gen_rotli_i32(t0, cpu_gpr[rS(ctx->opcode)], sh);
1664#endif
76a66253 1665#if defined(TARGET_PPC64)
d03ef511
AJ
1666 mb += 32;
1667 me += 32;
76a66253 1668#endif
d03ef511
AJ
1669 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me));
1670 tcg_temp_free(t0);
1671 }
76a66253 1672 if (unlikely(Rc(ctx->opcode) != 0))
d03ef511 1673 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
79aceca5 1674}
99e300ef 1675
54623277 1676/* rlwnm & rlwnm. */
99e300ef 1677static void gen_rlwnm(DisasContext *ctx)
79aceca5
FB
1678{
1679 uint32_t mb, me;
54843a58
AJ
1680 TCGv t0;
1681#if defined(TARGET_PPC64)
a7812ae4 1682 TCGv_i32 t1, t2;
54843a58 1683#endif
79aceca5
FB
1684
1685 mb = MB(ctx->opcode);
1686 me = ME(ctx->opcode);
a7812ae4 1687 t0 = tcg_temp_new();
d03ef511 1688 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1f);
54843a58 1689#if defined(TARGET_PPC64)
a7812ae4
PB
1690 t1 = tcg_temp_new_i32();
1691 t2 = tcg_temp_new_i32();
54843a58
AJ
1692 tcg_gen_trunc_i64_i32(t1, cpu_gpr[rS(ctx->opcode)]);
1693 tcg_gen_trunc_i64_i32(t2, t0);
1694 tcg_gen_rotl_i32(t1, t1, t2);
1695 tcg_gen_extu_i32_i64(t0, t1);
a7812ae4
PB
1696 tcg_temp_free_i32(t1);
1697 tcg_temp_free_i32(t2);
54843a58
AJ
1698#else
1699 tcg_gen_rotl_i32(t0, cpu_gpr[rS(ctx->opcode)], t0);
1700#endif
76a66253
JM
1701 if (unlikely(mb != 0 || me != 31)) {
1702#if defined(TARGET_PPC64)
1703 mb += 32;
1704 me += 32;
1705#endif
54843a58 1706 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me));
d03ef511 1707 } else {
54843a58 1708 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
79aceca5 1709 }
54843a58 1710 tcg_temp_free(t0);
76a66253 1711 if (unlikely(Rc(ctx->opcode) != 0))
d03ef511 1712 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
79aceca5
FB
1713}
1714
d9bce9d9
JM
1715#if defined(TARGET_PPC64)
1716#define GEN_PPC64_R2(name, opc1, opc2) \
e8eaa2c0 1717static void glue(gen_, name##0)(DisasContext *ctx) \
d9bce9d9
JM
1718{ \
1719 gen_##name(ctx, 0); \
1720} \
e8eaa2c0
BS
1721 \
1722static void glue(gen_, name##1)(DisasContext *ctx) \
d9bce9d9
JM
1723{ \
1724 gen_##name(ctx, 1); \
1725}
1726#define GEN_PPC64_R4(name, opc1, opc2) \
e8eaa2c0 1727static void glue(gen_, name##0)(DisasContext *ctx) \
d9bce9d9
JM
1728{ \
1729 gen_##name(ctx, 0, 0); \
1730} \
e8eaa2c0
BS
1731 \
1732static void glue(gen_, name##1)(DisasContext *ctx) \
d9bce9d9
JM
1733{ \
1734 gen_##name(ctx, 0, 1); \
1735} \
e8eaa2c0
BS
1736 \
1737static void glue(gen_, name##2)(DisasContext *ctx) \
d9bce9d9
JM
1738{ \
1739 gen_##name(ctx, 1, 0); \
1740} \
e8eaa2c0
BS
1741 \
1742static void glue(gen_, name##3)(DisasContext *ctx) \
d9bce9d9
JM
1743{ \
1744 gen_##name(ctx, 1, 1); \
1745}
51789c41 1746
636aa200
BS
1747static inline void gen_rldinm(DisasContext *ctx, uint32_t mb, uint32_t me,
1748 uint32_t sh)
51789c41 1749{
d03ef511
AJ
1750 if (likely(sh != 0 && mb == 0 && me == (63 - sh))) {
1751 tcg_gen_shli_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], sh);
1752 } else if (likely(sh != 0 && me == 63 && sh == (64 - mb))) {
1753 tcg_gen_shri_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], mb);
1754 } else {
a7812ae4 1755 TCGv t0 = tcg_temp_new();
54843a58 1756 tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
d03ef511 1757 if (likely(mb == 0 && me == 63)) {
54843a58 1758 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
d03ef511
AJ
1759 } else {
1760 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me));
51789c41 1761 }
d03ef511 1762 tcg_temp_free(t0);
51789c41 1763 }
51789c41 1764 if (unlikely(Rc(ctx->opcode) != 0))
d03ef511 1765 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
51789c41 1766}
d9bce9d9 1767/* rldicl - rldicl. */
636aa200 1768static inline void gen_rldicl(DisasContext *ctx, int mbn, int shn)
d9bce9d9 1769{
51789c41 1770 uint32_t sh, mb;
d9bce9d9 1771
9d53c753
JM
1772 sh = SH(ctx->opcode) | (shn << 5);
1773 mb = MB(ctx->opcode) | (mbn << 5);
51789c41 1774 gen_rldinm(ctx, mb, 63, sh);
d9bce9d9 1775}
51789c41 1776GEN_PPC64_R4(rldicl, 0x1E, 0x00);
d9bce9d9 1777/* rldicr - rldicr. */
636aa200 1778static inline void gen_rldicr(DisasContext *ctx, int men, int shn)
d9bce9d9 1779{
51789c41 1780 uint32_t sh, me;
d9bce9d9 1781
9d53c753
JM
1782 sh = SH(ctx->opcode) | (shn << 5);
1783 me = MB(ctx->opcode) | (men << 5);
51789c41 1784 gen_rldinm(ctx, 0, me, sh);
d9bce9d9 1785}
51789c41 1786GEN_PPC64_R4(rldicr, 0x1E, 0x02);
d9bce9d9 1787/* rldic - rldic. */
636aa200 1788static inline void gen_rldic(DisasContext *ctx, int mbn, int shn)
d9bce9d9 1789{
51789c41 1790 uint32_t sh, mb;
d9bce9d9 1791
9d53c753
JM
1792 sh = SH(ctx->opcode) | (shn << 5);
1793 mb = MB(ctx->opcode) | (mbn << 5);
51789c41
JM
1794 gen_rldinm(ctx, mb, 63 - sh, sh);
1795}
1796GEN_PPC64_R4(rldic, 0x1E, 0x04);
1797
636aa200 1798static inline void gen_rldnm(DisasContext *ctx, uint32_t mb, uint32_t me)
51789c41 1799{
54843a58 1800 TCGv t0;
d03ef511 1801
a7812ae4 1802 t0 = tcg_temp_new();
d03ef511 1803 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3f);
54843a58 1804 tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
51789c41 1805 if (unlikely(mb != 0 || me != 63)) {
54843a58
AJ
1806 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me));
1807 } else {
1808 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
1809 }
1810 tcg_temp_free(t0);
51789c41 1811 if (unlikely(Rc(ctx->opcode) != 0))
d03ef511 1812 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
d9bce9d9 1813}
51789c41 1814
d9bce9d9 1815/* rldcl - rldcl. */
636aa200 1816static inline void gen_rldcl(DisasContext *ctx, int mbn)
d9bce9d9 1817{
51789c41 1818 uint32_t mb;
d9bce9d9 1819
9d53c753 1820 mb = MB(ctx->opcode) | (mbn << 5);
51789c41 1821 gen_rldnm(ctx, mb, 63);
d9bce9d9 1822}
36081602 1823GEN_PPC64_R2(rldcl, 0x1E, 0x08);
d9bce9d9 1824/* rldcr - rldcr. */
636aa200 1825static inline void gen_rldcr(DisasContext *ctx, int men)
d9bce9d9 1826{
51789c41 1827 uint32_t me;
d9bce9d9 1828
9d53c753 1829 me = MB(ctx->opcode) | (men << 5);
51789c41 1830 gen_rldnm(ctx, 0, me);
d9bce9d9 1831}
36081602 1832GEN_PPC64_R2(rldcr, 0x1E, 0x09);
d9bce9d9 1833/* rldimi - rldimi. */
636aa200 1834static inline void gen_rldimi(DisasContext *ctx, int mbn, int shn)
d9bce9d9 1835{
271a916e 1836 uint32_t sh, mb, me;
d9bce9d9 1837
9d53c753
JM
1838 sh = SH(ctx->opcode) | (shn << 5);
1839 mb = MB(ctx->opcode) | (mbn << 5);
271a916e 1840 me = 63 - sh;
d03ef511
AJ
1841 if (unlikely(sh == 0 && mb == 0)) {
1842 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1843 } else {
1844 TCGv t0, t1;
1845 target_ulong mask;
1846
a7812ae4 1847 t0 = tcg_temp_new();
54843a58 1848 tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
a7812ae4 1849 t1 = tcg_temp_new();
d03ef511
AJ
1850 mask = MASK(mb, me);
1851 tcg_gen_andi_tl(t0, t0, mask);
1852 tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], ~mask);
1853 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1854 tcg_temp_free(t0);
1855 tcg_temp_free(t1);
51789c41 1856 }
51789c41 1857 if (unlikely(Rc(ctx->opcode) != 0))
d03ef511 1858 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
d9bce9d9 1859}
36081602 1860GEN_PPC64_R4(rldimi, 0x1E, 0x06);
d9bce9d9
JM
1861#endif
1862
79aceca5 1863/*** Integer shift ***/
99e300ef 1864
54623277 1865/* slw & slw. */
99e300ef 1866static void gen_slw(DisasContext *ctx)
26d67362 1867{
7fd6bf7d 1868 TCGv t0, t1;
26d67362 1869
7fd6bf7d
AJ
1870 t0 = tcg_temp_new();
1871 /* AND rS with a mask that is 0 when rB >= 0x20 */
1872#if defined(TARGET_PPC64)
1873 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3a);
1874 tcg_gen_sari_tl(t0, t0, 0x3f);
1875#else
1876 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1a);
1877 tcg_gen_sari_tl(t0, t0, 0x1f);
1878#endif
1879 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
1880 t1 = tcg_temp_new();
1881 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1f);
1882 tcg_gen_shl_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1883 tcg_temp_free(t1);
fea0c503 1884 tcg_temp_free(t0);
7fd6bf7d 1885 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
26d67362
AJ
1886 if (unlikely(Rc(ctx->opcode) != 0))
1887 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1888}
99e300ef 1889
54623277 1890/* sraw & sraw. */
99e300ef 1891static void gen_sraw(DisasContext *ctx)
26d67362 1892{
d15f74fb 1893 gen_helper_sraw(cpu_gpr[rA(ctx->opcode)], cpu_env,
a7812ae4 1894 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
26d67362
AJ
1895 if (unlikely(Rc(ctx->opcode) != 0))
1896 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1897}
99e300ef 1898
54623277 1899/* srawi & srawi. */
99e300ef 1900static void gen_srawi(DisasContext *ctx)
79aceca5 1901{
26d67362 1902 int sh = SH(ctx->opcode);
ba4af3e4
RH
1903 TCGv dst = cpu_gpr[rA(ctx->opcode)];
1904 TCGv src = cpu_gpr[rS(ctx->opcode)];
1905 if (sh == 0) {
1906 tcg_gen_mov_tl(dst, src);
da91a00f 1907 tcg_gen_movi_tl(cpu_ca, 0);
26d67362 1908 } else {
ba4af3e4
RH
1909 TCGv t0;
1910 tcg_gen_ext32s_tl(dst, src);
1911 tcg_gen_andi_tl(cpu_ca, dst, (1ULL << sh) - 1);
1912 t0 = tcg_temp_new();
1913 tcg_gen_sari_tl(t0, dst, TARGET_LONG_BITS - 1);
1914 tcg_gen_and_tl(cpu_ca, cpu_ca, t0);
1915 tcg_temp_free(t0);
1916 tcg_gen_setcondi_tl(TCG_COND_NE, cpu_ca, cpu_ca, 0);
1917 tcg_gen_sari_tl(dst, dst, sh);
1918 }
1919 if (unlikely(Rc(ctx->opcode) != 0)) {
1920 gen_set_Rc0(ctx, dst);
d9bce9d9 1921 }
79aceca5 1922}
99e300ef 1923
54623277 1924/* srw & srw. */
99e300ef 1925static void gen_srw(DisasContext *ctx)
26d67362 1926{
fea0c503 1927 TCGv t0, t1;
d9bce9d9 1928
7fd6bf7d
AJ
1929 t0 = tcg_temp_new();
1930 /* AND rS with a mask that is 0 when rB >= 0x20 */
1931#if defined(TARGET_PPC64)
1932 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3a);
1933 tcg_gen_sari_tl(t0, t0, 0x3f);
1934#else
1935 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1a);
1936 tcg_gen_sari_tl(t0, t0, 0x1f);
1937#endif
1938 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
1939 tcg_gen_ext32u_tl(t0, t0);
a7812ae4 1940 t1 = tcg_temp_new();
7fd6bf7d
AJ
1941 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1f);
1942 tcg_gen_shr_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
fea0c503 1943 tcg_temp_free(t1);
fea0c503 1944 tcg_temp_free(t0);
26d67362
AJ
1945 if (unlikely(Rc(ctx->opcode) != 0))
1946 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1947}
54623277 1948
d9bce9d9
JM
1949#if defined(TARGET_PPC64)
1950/* sld & sld. */
99e300ef 1951static void gen_sld(DisasContext *ctx)
26d67362 1952{
7fd6bf7d 1953 TCGv t0, t1;
26d67362 1954
7fd6bf7d
AJ
1955 t0 = tcg_temp_new();
1956 /* AND rS with a mask that is 0 when rB >= 0x40 */
1957 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x39);
1958 tcg_gen_sari_tl(t0, t0, 0x3f);
1959 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
1960 t1 = tcg_temp_new();
1961 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x3f);
1962 tcg_gen_shl_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1963 tcg_temp_free(t1);
fea0c503 1964 tcg_temp_free(t0);
26d67362
AJ
1965 if (unlikely(Rc(ctx->opcode) != 0))
1966 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1967}
99e300ef 1968
54623277 1969/* srad & srad. */
99e300ef 1970static void gen_srad(DisasContext *ctx)
26d67362 1971{
d15f74fb 1972 gen_helper_srad(cpu_gpr[rA(ctx->opcode)], cpu_env,
a7812ae4 1973 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
26d67362
AJ
1974 if (unlikely(Rc(ctx->opcode) != 0))
1975 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1976}
d9bce9d9 1977/* sradi & sradi. */
636aa200 1978static inline void gen_sradi(DisasContext *ctx, int n)
d9bce9d9 1979{
26d67362 1980 int sh = SH(ctx->opcode) + (n << 5);
ba4af3e4
RH
1981 TCGv dst = cpu_gpr[rA(ctx->opcode)];
1982 TCGv src = cpu_gpr[rS(ctx->opcode)];
1983 if (sh == 0) {
1984 tcg_gen_mov_tl(dst, src);
da91a00f 1985 tcg_gen_movi_tl(cpu_ca, 0);
26d67362 1986 } else {
ba4af3e4
RH
1987 TCGv t0;
1988 tcg_gen_andi_tl(cpu_ca, src, (1ULL << sh) - 1);
1989 t0 = tcg_temp_new();
1990 tcg_gen_sari_tl(t0, src, TARGET_LONG_BITS - 1);
1991 tcg_gen_and_tl(cpu_ca, cpu_ca, t0);
1992 tcg_temp_free(t0);
1993 tcg_gen_setcondi_tl(TCG_COND_NE, cpu_ca, cpu_ca, 0);
1994 tcg_gen_sari_tl(dst, src, sh);
1995 }
1996 if (unlikely(Rc(ctx->opcode) != 0)) {
1997 gen_set_Rc0(ctx, dst);
d9bce9d9 1998 }
d9bce9d9 1999}
e8eaa2c0
BS
2000
2001static void gen_sradi0(DisasContext *ctx)
d9bce9d9
JM
2002{
2003 gen_sradi(ctx, 0);
2004}
e8eaa2c0
BS
2005
2006static void gen_sradi1(DisasContext *ctx)
d9bce9d9
JM
2007{
2008 gen_sradi(ctx, 1);
2009}
99e300ef 2010
54623277 2011/* srd & srd. */
99e300ef 2012static void gen_srd(DisasContext *ctx)
26d67362 2013{
7fd6bf7d 2014 TCGv t0, t1;
26d67362 2015
7fd6bf7d
AJ
2016 t0 = tcg_temp_new();
2017 /* AND rS with a mask that is 0 when rB >= 0x40 */
2018 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x39);
2019 tcg_gen_sari_tl(t0, t0, 0x3f);
2020 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
2021 t1 = tcg_temp_new();
2022 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x3f);
2023 tcg_gen_shr_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
2024 tcg_temp_free(t1);
fea0c503 2025 tcg_temp_free(t0);
26d67362
AJ
2026 if (unlikely(Rc(ctx->opcode) != 0))
2027 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
2028}
d9bce9d9 2029#endif
79aceca5
FB
2030
2031/*** Floating-Point arithmetic ***/
7c58044c 2032#define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
99e300ef 2033static void gen_f##name(DisasContext *ctx) \
9a64fbe4 2034{ \
76a66253 2035 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 2036 gen_exception(ctx, POWERPC_EXCP_FPU); \
3cc62370
FB
2037 return; \
2038 } \
eb44b959
AJ
2039 /* NIP cannot be restored if the memory exception comes from an helper */ \
2040 gen_update_nip(ctx, ctx->nip - 4); \
7c58044c 2041 gen_reset_fpstatus(); \
8e703949
BS
2042 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2043 cpu_fpr[rA(ctx->opcode)], \
af12906f 2044 cpu_fpr[rC(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]); \
4ecc3190 2045 if (isfloat) { \
8e703949
BS
2046 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2047 cpu_fpr[rD(ctx->opcode)]); \
4ecc3190 2048 } \
af12906f
AJ
2049 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], set_fprf, \
2050 Rc(ctx->opcode) != 0); \
9a64fbe4
FB
2051}
2052
7c58044c
JM
2053#define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
2054_GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type); \
2055_GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type);
9a64fbe4 2056
7c58044c 2057#define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
99e300ef 2058static void gen_f##name(DisasContext *ctx) \
9a64fbe4 2059{ \
76a66253 2060 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 2061 gen_exception(ctx, POWERPC_EXCP_FPU); \
3cc62370
FB
2062 return; \
2063 } \
eb44b959
AJ
2064 /* NIP cannot be restored if the memory exception comes from an helper */ \
2065 gen_update_nip(ctx, ctx->nip - 4); \
7c58044c 2066 gen_reset_fpstatus(); \
8e703949
BS
2067 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2068 cpu_fpr[rA(ctx->opcode)], \
af12906f 2069 cpu_fpr[rB(ctx->opcode)]); \
4ecc3190 2070 if (isfloat) { \
8e703949
BS
2071 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2072 cpu_fpr[rD(ctx->opcode)]); \
4ecc3190 2073 } \
af12906f
AJ
2074 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2075 set_fprf, Rc(ctx->opcode) != 0); \
9a64fbe4 2076}
7c58044c
JM
2077#define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
2078_GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2079_GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
9a64fbe4 2080
7c58044c 2081#define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
99e300ef 2082static void gen_f##name(DisasContext *ctx) \
9a64fbe4 2083{ \
76a66253 2084 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 2085 gen_exception(ctx, POWERPC_EXCP_FPU); \
3cc62370
FB
2086 return; \
2087 } \
eb44b959
AJ
2088 /* NIP cannot be restored if the memory exception comes from an helper */ \
2089 gen_update_nip(ctx, ctx->nip - 4); \
7c58044c 2090 gen_reset_fpstatus(); \
8e703949
BS
2091 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2092 cpu_fpr[rA(ctx->opcode)], \
2093 cpu_fpr[rC(ctx->opcode)]); \
4ecc3190 2094 if (isfloat) { \
8e703949
BS
2095 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2096 cpu_fpr[rD(ctx->opcode)]); \
4ecc3190 2097 } \
af12906f
AJ
2098 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2099 set_fprf, Rc(ctx->opcode) != 0); \
9a64fbe4 2100}
7c58044c
JM
2101#define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
2102_GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2103_GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
9a64fbe4 2104
7c58044c 2105#define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
99e300ef 2106static void gen_f##name(DisasContext *ctx) \
9a64fbe4 2107{ \
76a66253 2108 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 2109 gen_exception(ctx, POWERPC_EXCP_FPU); \
3cc62370
FB
2110 return; \
2111 } \
eb44b959
AJ
2112 /* NIP cannot be restored if the memory exception comes from an helper */ \
2113 gen_update_nip(ctx, ctx->nip - 4); \
7c58044c 2114 gen_reset_fpstatus(); \
8e703949
BS
2115 gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2116 cpu_fpr[rB(ctx->opcode)]); \
af12906f
AJ
2117 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2118 set_fprf, Rc(ctx->opcode) != 0); \
79aceca5
FB
2119}
2120
7c58044c 2121#define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
99e300ef 2122static void gen_f##name(DisasContext *ctx) \
9a64fbe4 2123{ \
76a66253 2124 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 2125 gen_exception(ctx, POWERPC_EXCP_FPU); \
3cc62370
FB
2126 return; \
2127 } \
eb44b959
AJ
2128 /* NIP cannot be restored if the memory exception comes from an helper */ \
2129 gen_update_nip(ctx, ctx->nip - 4); \
7c58044c 2130 gen_reset_fpstatus(); \
8e703949
BS
2131 gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2132 cpu_fpr[rB(ctx->opcode)]); \
af12906f
AJ
2133 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2134 set_fprf, Rc(ctx->opcode) != 0); \
79aceca5
FB
2135}
2136
9a64fbe4 2137/* fadd - fadds */
7c58044c 2138GEN_FLOAT_AB(add, 0x15, 0x000007C0, 1, PPC_FLOAT);
4ecc3190 2139/* fdiv - fdivs */
7c58044c 2140GEN_FLOAT_AB(div, 0x12, 0x000007C0, 1, PPC_FLOAT);
4ecc3190 2141/* fmul - fmuls */
7c58044c 2142GEN_FLOAT_AC(mul, 0x19, 0x0000F800, 1, PPC_FLOAT);
79aceca5 2143
d7e4b87e 2144/* fre */
7c58044c 2145GEN_FLOAT_BS(re, 0x3F, 0x18, 1, PPC_FLOAT_EXT);
d7e4b87e 2146
a750fc0b 2147/* fres */
7c58044c 2148GEN_FLOAT_BS(res, 0x3B, 0x18, 1, PPC_FLOAT_FRES);
79aceca5 2149
a750fc0b 2150/* frsqrte */
7c58044c
JM
2151GEN_FLOAT_BS(rsqrte, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE);
2152
2153/* frsqrtes */
99e300ef 2154static void gen_frsqrtes(DisasContext *ctx)
7c58044c 2155{
af12906f 2156 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2157 gen_exception(ctx, POWERPC_EXCP_FPU);
af12906f
AJ
2158 return;
2159 }
eb44b959
AJ
2160 /* NIP cannot be restored if the memory exception comes from an helper */
2161 gen_update_nip(ctx, ctx->nip - 4);
af12906f 2162 gen_reset_fpstatus();
8e703949
BS
2163 gen_helper_frsqrte(cpu_fpr[rD(ctx->opcode)], cpu_env,
2164 cpu_fpr[rB(ctx->opcode)]);
2165 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env,
2166 cpu_fpr[rD(ctx->opcode)]);
af12906f 2167 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 1, Rc(ctx->opcode) != 0);
7c58044c 2168}
79aceca5 2169
a750fc0b 2170/* fsel */
7c58044c 2171_GEN_FLOAT_ACB(sel, sel, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL);
4ecc3190 2172/* fsub - fsubs */
7c58044c 2173GEN_FLOAT_AB(sub, 0x14, 0x000007C0, 1, PPC_FLOAT);
79aceca5 2174/* Optional: */
99e300ef 2175
54623277 2176/* fsqrt */
99e300ef 2177static void gen_fsqrt(DisasContext *ctx)
c7d344af 2178{
76a66253 2179 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2180 gen_exception(ctx, POWERPC_EXCP_FPU);
c7d344af
FB
2181 return;
2182 }
eb44b959
AJ
2183 /* NIP cannot be restored if the memory exception comes from an helper */
2184 gen_update_nip(ctx, ctx->nip - 4);
7c58044c 2185 gen_reset_fpstatus();
8e703949
BS
2186 gen_helper_fsqrt(cpu_fpr[rD(ctx->opcode)], cpu_env,
2187 cpu_fpr[rB(ctx->opcode)]);
af12906f 2188 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 1, Rc(ctx->opcode) != 0);
c7d344af 2189}
79aceca5 2190
99e300ef 2191static void gen_fsqrts(DisasContext *ctx)
79aceca5 2192{
76a66253 2193 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2194 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2195 return;
2196 }
eb44b959
AJ
2197 /* NIP cannot be restored if the memory exception comes from an helper */
2198 gen_update_nip(ctx, ctx->nip - 4);
7c58044c 2199 gen_reset_fpstatus();
8e703949
BS
2200 gen_helper_fsqrt(cpu_fpr[rD(ctx->opcode)], cpu_env,
2201 cpu_fpr[rB(ctx->opcode)]);
2202 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env,
2203 cpu_fpr[rD(ctx->opcode)]);
af12906f 2204 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 1, Rc(ctx->opcode) != 0);
79aceca5
FB
2205}
2206
2207/*** Floating-Point multiply-and-add ***/
4ecc3190 2208/* fmadd - fmadds */
7c58044c 2209GEN_FLOAT_ACB(madd, 0x1D, 1, PPC_FLOAT);
4ecc3190 2210/* fmsub - fmsubs */
7c58044c 2211GEN_FLOAT_ACB(msub, 0x1C, 1, PPC_FLOAT);
4ecc3190 2212/* fnmadd - fnmadds */
7c58044c 2213GEN_FLOAT_ACB(nmadd, 0x1F, 1, PPC_FLOAT);
4ecc3190 2214/* fnmsub - fnmsubs */
7c58044c 2215GEN_FLOAT_ACB(nmsub, 0x1E, 1, PPC_FLOAT);
79aceca5
FB
2216
2217/*** Floating-Point round & convert ***/
2218/* fctiw */
7c58044c 2219GEN_FLOAT_B(ctiw, 0x0E, 0x00, 0, PPC_FLOAT);
fab7fe42
TM
2220/* fctiwu */
2221GEN_FLOAT_B(ctiwu, 0x0E, 0x04, 0, PPC2_FP_CVT_ISA206);
79aceca5 2222/* fctiwz */
7c58044c 2223GEN_FLOAT_B(ctiwz, 0x0F, 0x00, 0, PPC_FLOAT);
fab7fe42
TM
2224/* fctiwuz */
2225GEN_FLOAT_B(ctiwuz, 0x0F, 0x04, 0, PPC2_FP_CVT_ISA206);
79aceca5 2226/* frsp */
7c58044c 2227GEN_FLOAT_B(rsp, 0x0C, 0x00, 1, PPC_FLOAT);
426613db
JM
2228#if defined(TARGET_PPC64)
2229/* fcfid */
7c58044c 2230GEN_FLOAT_B(cfid, 0x0E, 0x1A, 1, PPC_64B);
28288b48
TM
2231/* fcfids */
2232GEN_FLOAT_B(cfids, 0x0E, 0x1A, 0, PPC2_FP_CVT_ISA206);
2233/* fcfidu */
2234GEN_FLOAT_B(cfidu, 0x0E, 0x1E, 0, PPC2_FP_CVT_ISA206);
2235/* fcfidus */
2236GEN_FLOAT_B(cfidus, 0x0E, 0x1E, 0, PPC2_FP_CVT_ISA206);
426613db 2237/* fctid */
7c58044c 2238GEN_FLOAT_B(ctid, 0x0E, 0x19, 0, PPC_64B);
fab7fe42
TM
2239/* fctidu */
2240GEN_FLOAT_B(ctidu, 0x0E, 0x1D, 0, PPC2_FP_CVT_ISA206);
426613db 2241/* fctidz */
7c58044c 2242GEN_FLOAT_B(ctidz, 0x0F, 0x19, 0, PPC_64B);
fab7fe42
TM
2243/* fctidu */
2244GEN_FLOAT_B(ctiduz, 0x0F, 0x1D, 0, PPC2_FP_CVT_ISA206);
426613db 2245#endif
79aceca5 2246
d7e4b87e 2247/* frin */
7c58044c 2248GEN_FLOAT_B(rin, 0x08, 0x0C, 1, PPC_FLOAT_EXT);
d7e4b87e 2249/* friz */
7c58044c 2250GEN_FLOAT_B(riz, 0x08, 0x0D, 1, PPC_FLOAT_EXT);
d7e4b87e 2251/* frip */
7c58044c 2252GEN_FLOAT_B(rip, 0x08, 0x0E, 1, PPC_FLOAT_EXT);
d7e4b87e 2253/* frim */
7c58044c 2254GEN_FLOAT_B(rim, 0x08, 0x0F, 1, PPC_FLOAT_EXT);
d7e4b87e 2255
da29cb7b
TM
2256static void gen_ftdiv(DisasContext *ctx)
2257{
2258 if (unlikely(!ctx->fpu_enabled)) {
2259 gen_exception(ctx, POWERPC_EXCP_FPU);
2260 return;
2261 }
2262 gen_helper_ftdiv(cpu_crf[crfD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)],
2263 cpu_fpr[rB(ctx->opcode)]);
2264}
2265
6d41d146
TM
2266static void gen_ftsqrt(DisasContext *ctx)
2267{
2268 if (unlikely(!ctx->fpu_enabled)) {
2269 gen_exception(ctx, POWERPC_EXCP_FPU);
2270 return;
2271 }
2272 gen_helper_ftsqrt(cpu_crf[crfD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]);
2273}
2274
da29cb7b
TM
2275
2276
79aceca5 2277/*** Floating-Point compare ***/
99e300ef 2278
54623277 2279/* fcmpo */
99e300ef 2280static void gen_fcmpo(DisasContext *ctx)
79aceca5 2281{
330c483b 2282 TCGv_i32 crf;
76a66253 2283 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2284 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2285 return;
2286 }
eb44b959
AJ
2287 /* NIP cannot be restored if the memory exception comes from an helper */
2288 gen_update_nip(ctx, ctx->nip - 4);
7c58044c 2289 gen_reset_fpstatus();
9a819377 2290 crf = tcg_const_i32(crfD(ctx->opcode));
8e703949
BS
2291 gen_helper_fcmpo(cpu_env, cpu_fpr[rA(ctx->opcode)],
2292 cpu_fpr[rB(ctx->opcode)], crf);
330c483b 2293 tcg_temp_free_i32(crf);
8e703949 2294 gen_helper_float_check_status(cpu_env);
79aceca5
FB
2295}
2296
2297/* fcmpu */
99e300ef 2298static void gen_fcmpu(DisasContext *ctx)
79aceca5 2299{
330c483b 2300 TCGv_i32 crf;
76a66253 2301 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2302 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2303 return;
2304 }
eb44b959
AJ
2305 /* NIP cannot be restored if the memory exception comes from an helper */
2306 gen_update_nip(ctx, ctx->nip - 4);
7c58044c 2307 gen_reset_fpstatus();
9a819377 2308 crf = tcg_const_i32(crfD(ctx->opcode));
8e703949
BS
2309 gen_helper_fcmpu(cpu_env, cpu_fpr[rA(ctx->opcode)],
2310 cpu_fpr[rB(ctx->opcode)], crf);
330c483b 2311 tcg_temp_free_i32(crf);
8e703949 2312 gen_helper_float_check_status(cpu_env);
79aceca5
FB
2313}
2314
9a64fbe4
FB
2315/*** Floating-point move ***/
2316/* fabs */
7c58044c 2317/* XXX: beware that fabs never checks for NaNs nor update FPSCR */
bf45a2e6
AJ
2318static void gen_fabs(DisasContext *ctx)
2319{
2320 if (unlikely(!ctx->fpu_enabled)) {
2321 gen_exception(ctx, POWERPC_EXCP_FPU);
2322 return;
2323 }
2324 tcg_gen_andi_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)],
2325 ~(1ULL << 63));
2326 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
2327}
9a64fbe4
FB
2328
2329/* fmr - fmr. */
7c58044c 2330/* XXX: beware that fmr never checks for NaNs nor update FPSCR */
99e300ef 2331static void gen_fmr(DisasContext *ctx)
9a64fbe4 2332{
76a66253 2333 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2334 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2335 return;
2336 }
af12906f
AJ
2337 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]);
2338 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
9a64fbe4
FB
2339}
2340
2341/* fnabs */
7c58044c 2342/* XXX: beware that fnabs never checks for NaNs nor update FPSCR */
bf45a2e6
AJ
2343static void gen_fnabs(DisasContext *ctx)
2344{
2345 if (unlikely(!ctx->fpu_enabled)) {
2346 gen_exception(ctx, POWERPC_EXCP_FPU);
2347 return;
2348 }
2349 tcg_gen_ori_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)],
2350 1ULL << 63);
2351 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
2352}
2353
9a64fbe4 2354/* fneg */
7c58044c 2355/* XXX: beware that fneg never checks for NaNs nor update FPSCR */
bf45a2e6
AJ
2356static void gen_fneg(DisasContext *ctx)
2357{
2358 if (unlikely(!ctx->fpu_enabled)) {
2359 gen_exception(ctx, POWERPC_EXCP_FPU);
2360 return;
2361 }
2362 tcg_gen_xori_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)],
2363 1ULL << 63);
2364 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
2365}
9a64fbe4 2366
f0332888
AJ
2367/* fcpsgn: PowerPC 2.05 specification */
2368/* XXX: beware that fcpsgn never checks for NaNs nor update FPSCR */
2369static void gen_fcpsgn(DisasContext *ctx)
2370{
2371 if (unlikely(!ctx->fpu_enabled)) {
2372 gen_exception(ctx, POWERPC_EXCP_FPU);
2373 return;
2374 }
2375 tcg_gen_deposit_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)],
2376 cpu_fpr[rB(ctx->opcode)], 0, 63);
2377 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
2378}
2379
097ec5d8
TM
2380static void gen_fmrgew(DisasContext *ctx)
2381{
2382 TCGv_i64 b0;
2383 if (unlikely(!ctx->fpu_enabled)) {
2384 gen_exception(ctx, POWERPC_EXCP_FPU);
2385 return;
2386 }
2387 b0 = tcg_temp_new_i64();
2388 tcg_gen_shri_i64(b0, cpu_fpr[rB(ctx->opcode)], 32);
2389 tcg_gen_deposit_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)],
2390 b0, 0, 32);
2391 tcg_temp_free_i64(b0);
2392}
2393
2394static void gen_fmrgow(DisasContext *ctx)
2395{
2396 if (unlikely(!ctx->fpu_enabled)) {
2397 gen_exception(ctx, POWERPC_EXCP_FPU);
2398 return;
2399 }
2400 tcg_gen_deposit_i64(cpu_fpr[rD(ctx->opcode)],
2401 cpu_fpr[rB(ctx->opcode)],
2402 cpu_fpr[rA(ctx->opcode)],
2403 32, 32);
2404}
2405
79aceca5 2406/*** Floating-Point status & ctrl register ***/
99e300ef 2407
54623277 2408/* mcrfs */
99e300ef 2409static void gen_mcrfs(DisasContext *ctx)
79aceca5 2410{
30304420 2411 TCGv tmp = tcg_temp_new();
7c58044c
JM
2412 int bfa;
2413
76a66253 2414 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2415 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2416 return;
2417 }
7c58044c 2418 bfa = 4 * (7 - crfS(ctx->opcode));
30304420
DG
2419 tcg_gen_shri_tl(tmp, cpu_fpscr, bfa);
2420 tcg_gen_trunc_tl_i32(cpu_crf[crfD(ctx->opcode)], tmp);
2421 tcg_temp_free(tmp);
e1571908 2422 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], 0xf);
30304420 2423 tcg_gen_andi_tl(cpu_fpscr, cpu_fpscr, ~(0xF << bfa));
79aceca5
FB
2424}
2425
2426/* mffs */
99e300ef 2427static void gen_mffs(DisasContext *ctx)
79aceca5 2428{
76a66253 2429 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2430 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2431 return;
2432 }
7c58044c 2433 gen_reset_fpstatus();
30304420 2434 tcg_gen_extu_tl_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpscr);
af12906f 2435 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
79aceca5
FB
2436}
2437
2438/* mtfsb0 */
99e300ef 2439static void gen_mtfsb0(DisasContext *ctx)
79aceca5 2440{
fb0eaffc 2441 uint8_t crb;
3b46e624 2442
76a66253 2443 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2444 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2445 return;
2446 }
6e35d524 2447 crb = 31 - crbD(ctx->opcode);
7c58044c 2448 gen_reset_fpstatus();
6e35d524 2449 if (likely(crb != FPSCR_FEX && crb != FPSCR_VX)) {
eb44b959
AJ
2450 TCGv_i32 t0;
2451 /* NIP cannot be restored if the memory exception comes from an helper */
2452 gen_update_nip(ctx, ctx->nip - 4);
2453 t0 = tcg_const_i32(crb);
8e703949 2454 gen_helper_fpscr_clrbit(cpu_env, t0);
6e35d524
AJ
2455 tcg_temp_free_i32(t0);
2456 }
7c58044c 2457 if (unlikely(Rc(ctx->opcode) != 0)) {
30304420
DG
2458 tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr);
2459 tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX);
7c58044c 2460 }
79aceca5
FB
2461}
2462
2463/* mtfsb1 */
99e300ef 2464static void gen_mtfsb1(DisasContext *ctx)
79aceca5 2465{
fb0eaffc 2466 uint8_t crb;
3b46e624 2467
76a66253 2468 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2469 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2470 return;
2471 }
6e35d524 2472 crb = 31 - crbD(ctx->opcode);
7c58044c
JM
2473 gen_reset_fpstatus();
2474 /* XXX: we pretend we can only do IEEE floating-point computations */
af12906f 2475 if (likely(crb != FPSCR_FEX && crb != FPSCR_VX && crb != FPSCR_NI)) {
eb44b959
AJ
2476 TCGv_i32 t0;
2477 /* NIP cannot be restored if the memory exception comes from an helper */
2478 gen_update_nip(ctx, ctx->nip - 4);
2479 t0 = tcg_const_i32(crb);
8e703949 2480 gen_helper_fpscr_setbit(cpu_env, t0);
0f2f39c2 2481 tcg_temp_free_i32(t0);
af12906f 2482 }
7c58044c 2483 if (unlikely(Rc(ctx->opcode) != 0)) {
30304420
DG
2484 tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr);
2485 tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX);
7c58044c
JM
2486 }
2487 /* We can raise a differed exception */
8e703949 2488 gen_helper_float_check_status(cpu_env);
79aceca5
FB
2489}
2490
2491/* mtfsf */
99e300ef 2492static void gen_mtfsf(DisasContext *ctx)
79aceca5 2493{
0f2f39c2 2494 TCGv_i32 t0;
7d08d856 2495 int flm, l, w;
af12906f 2496
76a66253 2497 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2498 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2499 return;
2500 }
7d08d856
AJ
2501 flm = FPFLM(ctx->opcode);
2502 l = FPL(ctx->opcode);
2503 w = FPW(ctx->opcode);
2504 if (unlikely(w & !(ctx->insns_flags2 & PPC2_ISA205))) {
2505 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
2506 return;
2507 }
eb44b959
AJ
2508 /* NIP cannot be restored if the memory exception comes from an helper */
2509 gen_update_nip(ctx, ctx->nip - 4);
7c58044c 2510 gen_reset_fpstatus();
7d08d856
AJ
2511 if (l) {
2512 t0 = tcg_const_i32((ctx->insns_flags2 & PPC2_ISA205) ? 0xffff : 0xff);
2513 } else {
2514 t0 = tcg_const_i32(flm << (w * 8));
2515 }
8e703949 2516 gen_helper_store_fpscr(cpu_env, cpu_fpr[rB(ctx->opcode)], t0);
0f2f39c2 2517 tcg_temp_free_i32(t0);
7c58044c 2518 if (unlikely(Rc(ctx->opcode) != 0)) {
30304420
DG
2519 tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr);
2520 tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX);
7c58044c
JM
2521 }
2522 /* We can raise a differed exception */
8e703949 2523 gen_helper_float_check_status(cpu_env);
79aceca5
FB
2524}
2525
2526/* mtfsfi */
99e300ef 2527static void gen_mtfsfi(DisasContext *ctx)
79aceca5 2528{
7d08d856 2529 int bf, sh, w;
0f2f39c2
AJ
2530 TCGv_i64 t0;
2531 TCGv_i32 t1;
7c58044c 2532
76a66253 2533 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2534 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2535 return;
2536 }
7d08d856
AJ
2537 w = FPW(ctx->opcode);
2538 bf = FPBF(ctx->opcode);
2539 if (unlikely(w & !(ctx->insns_flags2 & PPC2_ISA205))) {
2540 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
2541 return;
2542 }
2543 sh = (8 * w) + 7 - bf;
eb44b959
AJ
2544 /* NIP cannot be restored if the memory exception comes from an helper */
2545 gen_update_nip(ctx, ctx->nip - 4);
7c58044c 2546 gen_reset_fpstatus();
7d08d856 2547 t0 = tcg_const_i64(((uint64_t)FPIMM(ctx->opcode)) << (4 * sh));
af12906f 2548 t1 = tcg_const_i32(1 << sh);
8e703949 2549 gen_helper_store_fpscr(cpu_env, t0, t1);
0f2f39c2
AJ
2550 tcg_temp_free_i64(t0);
2551 tcg_temp_free_i32(t1);
7c58044c 2552 if (unlikely(Rc(ctx->opcode) != 0)) {
30304420
DG
2553 tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr);
2554 tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX);
7c58044c
JM
2555 }
2556 /* We can raise a differed exception */
8e703949 2557 gen_helper_float_check_status(cpu_env);
79aceca5
FB
2558}
2559
76a66253
JM
2560/*** Addressing modes ***/
2561/* Register indirect with immediate index : EA = (rA|0) + SIMM */
636aa200
BS
2562static inline void gen_addr_imm_index(DisasContext *ctx, TCGv EA,
2563 target_long maskl)
76a66253
JM
2564{
2565 target_long simm = SIMM(ctx->opcode);
2566
be147d08 2567 simm &= ~maskl;
76db3ba4 2568 if (rA(ctx->opcode) == 0) {
c791fe84
RH
2569 if (NARROW_MODE(ctx)) {
2570 simm = (uint32_t)simm;
2571 }
e2be8d8d 2572 tcg_gen_movi_tl(EA, simm);
76db3ba4 2573 } else if (likely(simm != 0)) {
e2be8d8d 2574 tcg_gen_addi_tl(EA, cpu_gpr[rA(ctx->opcode)], simm);
c791fe84 2575 if (NARROW_MODE(ctx)) {
76db3ba4
AJ
2576 tcg_gen_ext32u_tl(EA, EA);
2577 }
76db3ba4 2578 } else {
c791fe84 2579 if (NARROW_MODE(ctx)) {
76db3ba4 2580 tcg_gen_ext32u_tl(EA, cpu_gpr[rA(ctx->opcode)]);
c791fe84
RH
2581 } else {
2582 tcg_gen_mov_tl(EA, cpu_gpr[rA(ctx->opcode)]);
2583 }
76db3ba4 2584 }
76a66253
JM
2585}
2586
636aa200 2587static inline void gen_addr_reg_index(DisasContext *ctx, TCGv EA)
76a66253 2588{
76db3ba4 2589 if (rA(ctx->opcode) == 0) {
c791fe84 2590 if (NARROW_MODE(ctx)) {
76db3ba4 2591 tcg_gen_ext32u_tl(EA, cpu_gpr[rB(ctx->opcode)]);
c791fe84
RH
2592 } else {
2593 tcg_gen_mov_tl(EA, cpu_gpr[rB(ctx->opcode)]);
2594 }
76db3ba4 2595 } else {
e2be8d8d 2596 tcg_gen_add_tl(EA, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
c791fe84 2597 if (NARROW_MODE(ctx)) {
76db3ba4
AJ
2598 tcg_gen_ext32u_tl(EA, EA);
2599 }
76db3ba4 2600 }
76a66253
JM
2601}
2602
636aa200 2603static inline void gen_addr_register(DisasContext *ctx, TCGv EA)
76a66253 2604{
76db3ba4 2605 if (rA(ctx->opcode) == 0) {
e2be8d8d 2606 tcg_gen_movi_tl(EA, 0);
c791fe84
RH
2607 } else if (NARROW_MODE(ctx)) {
2608 tcg_gen_ext32u_tl(EA, cpu_gpr[rA(ctx->opcode)]);
76db3ba4 2609 } else {
c791fe84 2610 tcg_gen_mov_tl(EA, cpu_gpr[rA(ctx->opcode)]);
76db3ba4
AJ
2611 }
2612}
2613
636aa200
BS
2614static inline void gen_addr_add(DisasContext *ctx, TCGv ret, TCGv arg1,
2615 target_long val)
76db3ba4
AJ
2616{
2617 tcg_gen_addi_tl(ret, arg1, val);
c791fe84 2618 if (NARROW_MODE(ctx)) {
76db3ba4
AJ
2619 tcg_gen_ext32u_tl(ret, ret);
2620 }
76a66253
JM
2621}
2622
636aa200 2623static inline void gen_check_align(DisasContext *ctx, TCGv EA, int mask)
cf360a32
AJ
2624{
2625 int l1 = gen_new_label();
2626 TCGv t0 = tcg_temp_new();
2627 TCGv_i32 t1, t2;
2628 /* NIP cannot be restored if the memory exception comes from an helper */
2629 gen_update_nip(ctx, ctx->nip - 4);
2630 tcg_gen_andi_tl(t0, EA, mask);
2631 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
2632 t1 = tcg_const_i32(POWERPC_EXCP_ALIGN);
2633 t2 = tcg_const_i32(0);
e5f17ac6 2634 gen_helper_raise_exception_err(cpu_env, t1, t2);
cf360a32
AJ
2635 tcg_temp_free_i32(t1);
2636 tcg_temp_free_i32(t2);
2637 gen_set_label(l1);
2638 tcg_temp_free(t0);
2639}
2640
7863667f 2641/*** Integer load ***/
636aa200 2642static inline void gen_qemu_ld8u(DisasContext *ctx, TCGv arg1, TCGv arg2)
76db3ba4
AJ
2643{
2644 tcg_gen_qemu_ld8u(arg1, arg2, ctx->mem_idx);
2645}
2646
636aa200 2647static inline void gen_qemu_ld8s(DisasContext *ctx, TCGv arg1, TCGv arg2)
76db3ba4
AJ
2648{
2649 tcg_gen_qemu_ld8s(arg1, arg2, ctx->mem_idx);
2650}
2651
636aa200 2652static inline void gen_qemu_ld16u(DisasContext *ctx, TCGv arg1, TCGv arg2)
76db3ba4
AJ
2653{
2654 tcg_gen_qemu_ld16u(arg1, arg2, ctx->mem_idx);
2655 if (unlikely(ctx->le_mode)) {
fa3966a3 2656 tcg_gen_bswap16_tl(arg1, arg1);
76db3ba4 2657 }
b61f2753
AJ
2658}
2659
636aa200 2660static inline void gen_qemu_ld16s(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2661{
76db3ba4 2662 if (unlikely(ctx->le_mode)) {
76db3ba4 2663 tcg_gen_qemu_ld16u(arg1, arg2, ctx->mem_idx);
fa3966a3 2664 tcg_gen_bswap16_tl(arg1, arg1);
76db3ba4 2665 tcg_gen_ext16s_tl(arg1, arg1);
76db3ba4
AJ
2666 } else {
2667 tcg_gen_qemu_ld16s(arg1, arg2, ctx->mem_idx);
2668 }
b61f2753
AJ
2669}
2670
636aa200 2671static inline void gen_qemu_ld32u(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2672{
76db3ba4
AJ
2673 tcg_gen_qemu_ld32u(arg1, arg2, ctx->mem_idx);
2674 if (unlikely(ctx->le_mode)) {
fa3966a3 2675 tcg_gen_bswap32_tl(arg1, arg1);
76db3ba4 2676 }
b61f2753
AJ
2677}
2678
f976b09e
AG
2679static void gen_qemu_ld32u_i64(DisasContext *ctx, TCGv_i64 val, TCGv addr)
2680{
2681 TCGv tmp = tcg_temp_new();
2682 gen_qemu_ld32u(ctx, tmp, addr);
2683 tcg_gen_extu_tl_i64(val, tmp);
2684 tcg_temp_free(tmp);
2685}
2686
636aa200 2687static inline void gen_qemu_ld32s(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2688{
a457e7ee 2689 if (unlikely(ctx->le_mode)) {
76db3ba4 2690 tcg_gen_qemu_ld32u(arg1, arg2, ctx->mem_idx);
fa3966a3
AJ
2691 tcg_gen_bswap32_tl(arg1, arg1);
2692 tcg_gen_ext32s_tl(arg1, arg1);
b61f2753 2693 } else
76db3ba4 2694 tcg_gen_qemu_ld32s(arg1, arg2, ctx->mem_idx);
b61f2753
AJ
2695}
2696
cac7f0ba
TM
2697static void gen_qemu_ld32s_i64(DisasContext *ctx, TCGv_i64 val, TCGv addr)
2698{
2699 TCGv tmp = tcg_temp_new();
2700 gen_qemu_ld32s(ctx, tmp, addr);
2701 tcg_gen_ext_tl_i64(val, tmp);
2702 tcg_temp_free(tmp);
2703}
2704
636aa200 2705static inline void gen_qemu_ld64(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
b61f2753 2706{
76db3ba4
AJ
2707 tcg_gen_qemu_ld64(arg1, arg2, ctx->mem_idx);
2708 if (unlikely(ctx->le_mode)) {
66896cb8 2709 tcg_gen_bswap64_i64(arg1, arg1);
76db3ba4 2710 }
b61f2753
AJ
2711}
2712
636aa200 2713static inline void gen_qemu_st8(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2714{
76db3ba4 2715 tcg_gen_qemu_st8(arg1, arg2, ctx->mem_idx);
b61f2753
AJ
2716}
2717
636aa200 2718static inline void gen_qemu_st16(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2719{
76db3ba4 2720 if (unlikely(ctx->le_mode)) {
76db3ba4
AJ
2721 TCGv t0 = tcg_temp_new();
2722 tcg_gen_ext16u_tl(t0, arg1);
fa3966a3 2723 tcg_gen_bswap16_tl(t0, t0);
76db3ba4
AJ
2724 tcg_gen_qemu_st16(t0, arg2, ctx->mem_idx);
2725 tcg_temp_free(t0);
76db3ba4
AJ
2726 } else {
2727 tcg_gen_qemu_st16(arg1, arg2, ctx->mem_idx);
2728 }
b61f2753
AJ
2729}
2730
636aa200 2731static inline void gen_qemu_st32(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2732{
76db3ba4 2733 if (unlikely(ctx->le_mode)) {
fa3966a3
AJ
2734 TCGv t0 = tcg_temp_new();
2735 tcg_gen_ext32u_tl(t0, arg1);
2736 tcg_gen_bswap32_tl(t0, t0);
76db3ba4
AJ
2737 tcg_gen_qemu_st32(t0, arg2, ctx->mem_idx);
2738 tcg_temp_free(t0);
76db3ba4
AJ
2739 } else {
2740 tcg_gen_qemu_st32(arg1, arg2, ctx->mem_idx);
2741 }
b61f2753
AJ
2742}
2743
f976b09e
AG
2744static void gen_qemu_st32_i64(DisasContext *ctx, TCGv_i64 val, TCGv addr)
2745{
2746 TCGv tmp = tcg_temp_new();
2747 tcg_gen_trunc_i64_tl(tmp, val);
2748 gen_qemu_st32(ctx, tmp, addr);
2749 tcg_temp_free(tmp);
2750}
2751
636aa200 2752static inline void gen_qemu_st64(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
b61f2753 2753{
76db3ba4 2754 if (unlikely(ctx->le_mode)) {
a7812ae4 2755 TCGv_i64 t0 = tcg_temp_new_i64();
66896cb8 2756 tcg_gen_bswap64_i64(t0, arg1);
76db3ba4 2757 tcg_gen_qemu_st64(t0, arg2, ctx->mem_idx);
a7812ae4 2758 tcg_temp_free_i64(t0);
b61f2753 2759 } else
76db3ba4 2760 tcg_gen_qemu_st64(arg1, arg2, ctx->mem_idx);
b61f2753
AJ
2761}
2762
0c8aacd4 2763#define GEN_LD(name, ldop, opc, type) \
99e300ef 2764static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 2765{ \
76db3ba4
AJ
2766 TCGv EA; \
2767 gen_set_access_type(ctx, ACCESS_INT); \
2768 EA = tcg_temp_new(); \
2769 gen_addr_imm_index(ctx, EA, 0); \
2770 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
b61f2753 2771 tcg_temp_free(EA); \
79aceca5
FB
2772}
2773
0c8aacd4 2774#define GEN_LDU(name, ldop, opc, type) \
99e300ef 2775static void glue(gen_, name##u)(DisasContext *ctx) \
79aceca5 2776{ \
b61f2753 2777 TCGv EA; \
76a66253
JM
2778 if (unlikely(rA(ctx->opcode) == 0 || \
2779 rA(ctx->opcode) == rD(ctx->opcode))) { \
e06fcd75 2780 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 2781 return; \
9a64fbe4 2782 } \
76db3ba4 2783 gen_set_access_type(ctx, ACCESS_INT); \
0c8aacd4 2784 EA = tcg_temp_new(); \
9d53c753 2785 if (type == PPC_64B) \
76db3ba4 2786 gen_addr_imm_index(ctx, EA, 0x03); \
9d53c753 2787 else \
76db3ba4
AJ
2788 gen_addr_imm_index(ctx, EA, 0); \
2789 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
b61f2753
AJ
2790 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2791 tcg_temp_free(EA); \
79aceca5
FB
2792}
2793
0c8aacd4 2794#define GEN_LDUX(name, ldop, opc2, opc3, type) \
99e300ef 2795static void glue(gen_, name##ux)(DisasContext *ctx) \
79aceca5 2796{ \
b61f2753 2797 TCGv EA; \
76a66253
JM
2798 if (unlikely(rA(ctx->opcode) == 0 || \
2799 rA(ctx->opcode) == rD(ctx->opcode))) { \
e06fcd75 2800 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 2801 return; \
9a64fbe4 2802 } \
76db3ba4 2803 gen_set_access_type(ctx, ACCESS_INT); \
0c8aacd4 2804 EA = tcg_temp_new(); \
76db3ba4
AJ
2805 gen_addr_reg_index(ctx, EA); \
2806 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
b61f2753
AJ
2807 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2808 tcg_temp_free(EA); \
79aceca5
FB
2809}
2810
cd6e9320 2811#define GEN_LDX_E(name, ldop, opc2, opc3, type, type2) \
99e300ef 2812static void glue(gen_, name##x)(DisasContext *ctx) \
79aceca5 2813{ \
76db3ba4
AJ
2814 TCGv EA; \
2815 gen_set_access_type(ctx, ACCESS_INT); \
2816 EA = tcg_temp_new(); \
2817 gen_addr_reg_index(ctx, EA); \
2818 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
b61f2753 2819 tcg_temp_free(EA); \
79aceca5 2820}
cd6e9320
TH
2821#define GEN_LDX(name, ldop, opc2, opc3, type) \
2822 GEN_LDX_E(name, ldop, opc2, opc3, type, PPC_NONE)
79aceca5 2823
0c8aacd4
AJ
2824#define GEN_LDS(name, ldop, op, type) \
2825GEN_LD(name, ldop, op | 0x20, type); \
2826GEN_LDU(name, ldop, op | 0x21, type); \
2827GEN_LDUX(name, ldop, 0x17, op | 0x01, type); \
2828GEN_LDX(name, ldop, 0x17, op | 0x00, type)
79aceca5
FB
2829
2830/* lbz lbzu lbzux lbzx */
0c8aacd4 2831GEN_LDS(lbz, ld8u, 0x02, PPC_INTEGER);
79aceca5 2832/* lha lhau lhaux lhax */
0c8aacd4 2833GEN_LDS(lha, ld16s, 0x0A, PPC_INTEGER);
79aceca5 2834/* lhz lhzu lhzux lhzx */
0c8aacd4 2835GEN_LDS(lhz, ld16u, 0x08, PPC_INTEGER);
79aceca5 2836/* lwz lwzu lwzux lwzx */
0c8aacd4 2837GEN_LDS(lwz, ld32u, 0x00, PPC_INTEGER);
d9bce9d9 2838#if defined(TARGET_PPC64)
d9bce9d9 2839/* lwaux */
0c8aacd4 2840GEN_LDUX(lwa, ld32s, 0x15, 0x0B, PPC_64B);
d9bce9d9 2841/* lwax */
0c8aacd4 2842GEN_LDX(lwa, ld32s, 0x15, 0x0A, PPC_64B);
d9bce9d9 2843/* ldux */
0c8aacd4 2844GEN_LDUX(ld, ld64, 0x15, 0x01, PPC_64B);
d9bce9d9 2845/* ldx */
0c8aacd4 2846GEN_LDX(ld, ld64, 0x15, 0x00, PPC_64B);
99e300ef
BS
2847
2848static void gen_ld(DisasContext *ctx)
d9bce9d9 2849{
b61f2753 2850 TCGv EA;
d9bce9d9
JM
2851 if (Rc(ctx->opcode)) {
2852 if (unlikely(rA(ctx->opcode) == 0 ||
2853 rA(ctx->opcode) == rD(ctx->opcode))) {
e06fcd75 2854 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
d9bce9d9
JM
2855 return;
2856 }
2857 }
76db3ba4 2858 gen_set_access_type(ctx, ACCESS_INT);
a7812ae4 2859 EA = tcg_temp_new();
76db3ba4 2860 gen_addr_imm_index(ctx, EA, 0x03);
d9bce9d9
JM
2861 if (ctx->opcode & 0x02) {
2862 /* lwa (lwau is undefined) */
76db3ba4 2863 gen_qemu_ld32s(ctx, cpu_gpr[rD(ctx->opcode)], EA);
d9bce9d9
JM
2864 } else {
2865 /* ld - ldu */
76db3ba4 2866 gen_qemu_ld64(ctx, cpu_gpr[rD(ctx->opcode)], EA);
d9bce9d9 2867 }
d9bce9d9 2868 if (Rc(ctx->opcode))
b61f2753
AJ
2869 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA);
2870 tcg_temp_free(EA);
d9bce9d9 2871}
99e300ef 2872
54623277 2873/* lq */
99e300ef 2874static void gen_lq(DisasContext *ctx)
be147d08 2875{
be147d08 2876 int ra, rd;
b61f2753 2877 TCGv EA;
be147d08 2878
e0498daa
TM
2879 /* lq is a legal user mode instruction starting in ISA 2.07 */
2880 bool legal_in_user_mode = (ctx->insns_flags2 & PPC2_LSQ_ISA207) != 0;
2881 bool le_is_supported = (ctx->insns_flags2 & PPC2_LSQ_ISA207) != 0;
2882
2883 if (!legal_in_user_mode && is_user_mode(ctx)) {
e06fcd75 2884 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
be147d08
JM
2885 return;
2886 }
e0498daa
TM
2887
2888 if (!le_is_supported && ctx->le_mode) {
2889 gen_exception_err(ctx, POWERPC_EXCP_ALIGN, POWERPC_EXCP_ALIGN_LE);
2890 return;
2891 }
2892
be147d08
JM
2893 ra = rA(ctx->opcode);
2894 rd = rD(ctx->opcode);
2895 if (unlikely((rd & 1) || rd == ra)) {
e06fcd75 2896 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
be147d08
JM
2897 return;
2898 }
e0498daa 2899
76db3ba4 2900 gen_set_access_type(ctx, ACCESS_INT);
a7812ae4 2901 EA = tcg_temp_new();
76db3ba4 2902 gen_addr_imm_index(ctx, EA, 0x0F);
e0498daa
TM
2903
2904 if (unlikely(ctx->le_mode)) {
2905 gen_qemu_ld64(ctx, cpu_gpr[rd+1], EA);
2906 gen_addr_add(ctx, EA, EA, 8);
2907 gen_qemu_ld64(ctx, cpu_gpr[rd], EA);
2908 } else {
2909 gen_qemu_ld64(ctx, cpu_gpr[rd], EA);
2910 gen_addr_add(ctx, EA, EA, 8);
2911 gen_qemu_ld64(ctx, cpu_gpr[rd+1], EA);
2912 }
b61f2753 2913 tcg_temp_free(EA);
be147d08 2914}
d9bce9d9 2915#endif
79aceca5
FB
2916
2917/*** Integer store ***/
0c8aacd4 2918#define GEN_ST(name, stop, opc, type) \
99e300ef 2919static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 2920{ \
76db3ba4
AJ
2921 TCGv EA; \
2922 gen_set_access_type(ctx, ACCESS_INT); \
2923 EA = tcg_temp_new(); \
2924 gen_addr_imm_index(ctx, EA, 0); \
2925 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
b61f2753 2926 tcg_temp_free(EA); \
79aceca5
FB
2927}
2928
0c8aacd4 2929#define GEN_STU(name, stop, opc, type) \
99e300ef 2930static void glue(gen_, stop##u)(DisasContext *ctx) \
79aceca5 2931{ \
b61f2753 2932 TCGv EA; \
76a66253 2933 if (unlikely(rA(ctx->opcode) == 0)) { \
e06fcd75 2934 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 2935 return; \
9a64fbe4 2936 } \
76db3ba4 2937 gen_set_access_type(ctx, ACCESS_INT); \
0c8aacd4 2938 EA = tcg_temp_new(); \
9d53c753 2939 if (type == PPC_64B) \
76db3ba4 2940 gen_addr_imm_index(ctx, EA, 0x03); \
9d53c753 2941 else \
76db3ba4
AJ
2942 gen_addr_imm_index(ctx, EA, 0); \
2943 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
b61f2753
AJ
2944 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2945 tcg_temp_free(EA); \
79aceca5
FB
2946}
2947
0c8aacd4 2948#define GEN_STUX(name, stop, opc2, opc3, type) \
99e300ef 2949static void glue(gen_, name##ux)(DisasContext *ctx) \
79aceca5 2950{ \
b61f2753 2951 TCGv EA; \
76a66253 2952 if (unlikely(rA(ctx->opcode) == 0)) { \
e06fcd75 2953 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 2954 return; \
9a64fbe4 2955 } \
76db3ba4 2956 gen_set_access_type(ctx, ACCESS_INT); \
0c8aacd4 2957 EA = tcg_temp_new(); \
76db3ba4
AJ
2958 gen_addr_reg_index(ctx, EA); \
2959 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
b61f2753
AJ
2960 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2961 tcg_temp_free(EA); \
79aceca5
FB
2962}
2963
cd6e9320
TH
2964#define GEN_STX_E(name, stop, opc2, opc3, type, type2) \
2965static void glue(gen_, name##x)(DisasContext *ctx) \
79aceca5 2966{ \
76db3ba4
AJ
2967 TCGv EA; \
2968 gen_set_access_type(ctx, ACCESS_INT); \
2969 EA = tcg_temp_new(); \
2970 gen_addr_reg_index(ctx, EA); \
2971 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
b61f2753 2972 tcg_temp_free(EA); \
79aceca5 2973}
cd6e9320
TH
2974#define GEN_STX(name, stop, opc2, opc3, type) \
2975 GEN_STX_E(name, stop, opc2, opc3, type, PPC_NONE)
79aceca5 2976
0c8aacd4
AJ
2977#define GEN_STS(name, stop, op, type) \
2978GEN_ST(name, stop, op | 0x20, type); \
2979GEN_STU(name, stop, op | 0x21, type); \
2980GEN_STUX(name, stop, 0x17, op | 0x01, type); \
2981GEN_STX(name, stop, 0x17, op | 0x00, type)
79aceca5
FB
2982
2983/* stb stbu stbux stbx */
0c8aacd4 2984GEN_STS(stb, st8, 0x06, PPC_INTEGER);
79aceca5 2985/* sth sthu sthux sthx */
0c8aacd4 2986GEN_STS(sth, st16, 0x0C, PPC_INTEGER);
79aceca5 2987/* stw stwu stwux stwx */
0c8aacd4 2988GEN_STS(stw, st32, 0x04, PPC_INTEGER);
d9bce9d9 2989#if defined(TARGET_PPC64)
0c8aacd4
AJ
2990GEN_STUX(std, st64, 0x15, 0x05, PPC_64B);
2991GEN_STX(std, st64, 0x15, 0x04, PPC_64B);
99e300ef
BS
2992
2993static void gen_std(DisasContext *ctx)
d9bce9d9 2994{
be147d08 2995 int rs;
b61f2753 2996 TCGv EA;
be147d08
JM
2997
2998 rs = rS(ctx->opcode);
84cab1e2
TM
2999 if ((ctx->opcode & 0x3) == 0x2) { /* stq */
3000
3001 bool legal_in_user_mode = (ctx->insns_flags2 & PPC2_LSQ_ISA207) != 0;
3002 bool le_is_supported = (ctx->insns_flags2 & PPC2_LSQ_ISA207) != 0;
3003
3004 if (!legal_in_user_mode && is_user_mode(ctx)) {
e06fcd75 3005 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
be147d08
JM
3006 return;
3007 }
84cab1e2
TM
3008
3009 if (!le_is_supported && ctx->le_mode) {
3010 gen_exception_err(ctx, POWERPC_EXCP_ALIGN, POWERPC_EXCP_ALIGN_LE);
d9bce9d9
JM
3011 return;
3012 }
84cab1e2
TM
3013
3014 if (unlikely(rs & 1)) {
3015 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
be147d08
JM
3016 return;
3017 }
76db3ba4 3018 gen_set_access_type(ctx, ACCESS_INT);
a7812ae4 3019 EA = tcg_temp_new();
76db3ba4 3020 gen_addr_imm_index(ctx, EA, 0x03);
84cab1e2
TM
3021
3022 if (unlikely(ctx->le_mode)) {
3023 gen_qemu_st64(ctx, cpu_gpr[rs+1], EA);
3024 gen_addr_add(ctx, EA, EA, 8);
3025 gen_qemu_st64(ctx, cpu_gpr[rs], EA);
3026 } else {
3027 gen_qemu_st64(ctx, cpu_gpr[rs], EA);
3028 gen_addr_add(ctx, EA, EA, 8);
3029 gen_qemu_st64(ctx, cpu_gpr[rs+1], EA);
3030 }
b61f2753 3031 tcg_temp_free(EA);
be147d08 3032 } else {
84cab1e2 3033 /* std / stdu*/
be147d08
JM
3034 if (Rc(ctx->opcode)) {
3035 if (unlikely(rA(ctx->opcode) == 0)) {
e06fcd75 3036 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
be147d08
JM
3037 return;
3038 }
3039 }
76db3ba4 3040 gen_set_access_type(ctx, ACCESS_INT);
a7812ae4 3041 EA = tcg_temp_new();
76db3ba4
AJ
3042 gen_addr_imm_index(ctx, EA, 0x03);
3043 gen_qemu_st64(ctx, cpu_gpr[rs], EA);
be147d08 3044 if (Rc(ctx->opcode))
b61f2753
AJ
3045 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA);
3046 tcg_temp_free(EA);
d9bce9d9 3047 }
d9bce9d9
JM
3048}
3049#endif
79aceca5
FB
3050/*** Integer load and store with byte reverse ***/
3051/* lhbrx */
86178a57 3052static inline void gen_qemu_ld16ur(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 3053{
76db3ba4
AJ
3054 tcg_gen_qemu_ld16u(arg1, arg2, ctx->mem_idx);
3055 if (likely(!ctx->le_mode)) {
fa3966a3 3056 tcg_gen_bswap16_tl(arg1, arg1);
76db3ba4 3057 }
b61f2753 3058}
0c8aacd4 3059GEN_LDX(lhbr, ld16ur, 0x16, 0x18, PPC_INTEGER);
b61f2753 3060
79aceca5 3061/* lwbrx */
86178a57 3062static inline void gen_qemu_ld32ur(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 3063{
76db3ba4
AJ
3064 tcg_gen_qemu_ld32u(arg1, arg2, ctx->mem_idx);
3065 if (likely(!ctx->le_mode)) {
fa3966a3 3066 tcg_gen_bswap32_tl(arg1, arg1);
76db3ba4 3067 }
b61f2753 3068}
0c8aacd4 3069GEN_LDX(lwbr, ld32ur, 0x16, 0x10, PPC_INTEGER);
b61f2753 3070
cd6e9320
TH
3071#if defined(TARGET_PPC64)
3072/* ldbrx */
3073static inline void gen_qemu_ld64ur(DisasContext *ctx, TCGv arg1, TCGv arg2)
3074{
3075 tcg_gen_qemu_ld64(arg1, arg2, ctx->mem_idx);
3076 if (likely(!ctx->le_mode)) {
3077 tcg_gen_bswap64_tl(arg1, arg1);
3078 }
3079}
3080GEN_LDX_E(ldbr, ld64ur, 0x14, 0x10, PPC_NONE, PPC2_DBRX);
3081#endif /* TARGET_PPC64 */
3082
79aceca5 3083/* sthbrx */
86178a57 3084static inline void gen_qemu_st16r(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 3085{
76db3ba4 3086 if (likely(!ctx->le_mode)) {
76db3ba4
AJ
3087 TCGv t0 = tcg_temp_new();
3088 tcg_gen_ext16u_tl(t0, arg1);
fa3966a3 3089 tcg_gen_bswap16_tl(t0, t0);
76db3ba4
AJ
3090 tcg_gen_qemu_st16(t0, arg2, ctx->mem_idx);
3091 tcg_temp_free(t0);
76db3ba4
AJ
3092 } else {
3093 tcg_gen_qemu_st16(arg1, arg2, ctx->mem_idx);
3094 }
b61f2753 3095}
0c8aacd4 3096GEN_STX(sthbr, st16r, 0x16, 0x1C, PPC_INTEGER);
b61f2753 3097
79aceca5 3098/* stwbrx */
86178a57 3099static inline void gen_qemu_st32r(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 3100{
76db3ba4 3101 if (likely(!ctx->le_mode)) {
fa3966a3
AJ
3102 TCGv t0 = tcg_temp_new();
3103 tcg_gen_ext32u_tl(t0, arg1);
3104 tcg_gen_bswap32_tl(t0, t0);
76db3ba4
AJ
3105 tcg_gen_qemu_st32(t0, arg2, ctx->mem_idx);
3106 tcg_temp_free(t0);
76db3ba4
AJ
3107 } else {
3108 tcg_gen_qemu_st32(arg1, arg2, ctx->mem_idx);
3109 }
b61f2753 3110}
0c8aacd4 3111GEN_STX(stwbr, st32r, 0x16, 0x14, PPC_INTEGER);
79aceca5 3112
cd6e9320
TH
3113#if defined(TARGET_PPC64)
3114/* stdbrx */
3115static inline void gen_qemu_st64r(DisasContext *ctx, TCGv arg1, TCGv arg2)
3116{
3117 if (likely(!ctx->le_mode)) {
3118 TCGv t0 = tcg_temp_new();
3119 tcg_gen_bswap64_tl(t0, arg1);
3120 tcg_gen_qemu_st64(t0, arg2, ctx->mem_idx);
3121 tcg_temp_free(t0);
3122 } else {
3123 tcg_gen_qemu_st64(arg1, arg2, ctx->mem_idx);
3124 }
3125}
3126GEN_STX_E(stdbr, st64r, 0x14, 0x14, PPC_NONE, PPC2_DBRX);
3127#endif /* TARGET_PPC64 */
3128
79aceca5 3129/*** Integer load and store multiple ***/
99e300ef 3130
54623277 3131/* lmw */
99e300ef 3132static void gen_lmw(DisasContext *ctx)
79aceca5 3133{
76db3ba4
AJ
3134 TCGv t0;
3135 TCGv_i32 t1;
3136 gen_set_access_type(ctx, ACCESS_INT);
76a66253 3137 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 3138 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
3139 t0 = tcg_temp_new();
3140 t1 = tcg_const_i32(rD(ctx->opcode));
3141 gen_addr_imm_index(ctx, t0, 0);
2f5a189c 3142 gen_helper_lmw(cpu_env, t0, t1);
ff4a62cd
AJ
3143 tcg_temp_free(t0);
3144 tcg_temp_free_i32(t1);
79aceca5
FB
3145}
3146
3147/* stmw */
99e300ef 3148static void gen_stmw(DisasContext *ctx)
79aceca5 3149{
76db3ba4
AJ
3150 TCGv t0;
3151 TCGv_i32 t1;
3152 gen_set_access_type(ctx, ACCESS_INT);
76a66253 3153 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 3154 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
3155 t0 = tcg_temp_new();
3156 t1 = tcg_const_i32(rS(ctx->opcode));
3157 gen_addr_imm_index(ctx, t0, 0);
2f5a189c 3158 gen_helper_stmw(cpu_env, t0, t1);
ff4a62cd
AJ
3159 tcg_temp_free(t0);
3160 tcg_temp_free_i32(t1);
79aceca5
FB
3161}
3162
3163/*** Integer load and store strings ***/
54623277 3164
79aceca5 3165/* lswi */
3fc6c082 3166/* PowerPC32 specification says we must generate an exception if
9a64fbe4
FB
3167 * rA is in the range of registers to be loaded.
3168 * In an other hand, IBM says this is valid, but rA won't be loaded.
3169 * For now, I'll follow the spec...
3170 */
99e300ef 3171static void gen_lswi(DisasContext *ctx)
79aceca5 3172{
dfbc799d
AJ
3173 TCGv t0;
3174 TCGv_i32 t1, t2;
79aceca5
FB
3175 int nb = NB(ctx->opcode);
3176 int start = rD(ctx->opcode);
9a64fbe4 3177 int ra = rA(ctx->opcode);
79aceca5
FB
3178 int nr;
3179
3180 if (nb == 0)
3181 nb = 32;
3182 nr = nb / 4;
76a66253
JM
3183 if (unlikely(((start + nr) > 32 &&
3184 start <= ra && (start + nr - 32) > ra) ||
3185 ((start + nr) <= 32 && start <= ra && (start + nr) > ra))) {
e06fcd75 3186 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX);
9fddaa0c 3187 return;
297d8e62 3188 }
76db3ba4 3189 gen_set_access_type(ctx, ACCESS_INT);
8dd4983c 3190 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 3191 gen_update_nip(ctx, ctx->nip - 4);
dfbc799d 3192 t0 = tcg_temp_new();
76db3ba4 3193 gen_addr_register(ctx, t0);
dfbc799d
AJ
3194 t1 = tcg_const_i32(nb);
3195 t2 = tcg_const_i32(start);
2f5a189c 3196 gen_helper_lsw(cpu_env, t0, t1, t2);
dfbc799d
AJ
3197 tcg_temp_free(t0);
3198 tcg_temp_free_i32(t1);
3199 tcg_temp_free_i32(t2);
79aceca5
FB
3200}
3201
3202/* lswx */
99e300ef 3203static void gen_lswx(DisasContext *ctx)
79aceca5 3204{
76db3ba4
AJ
3205 TCGv t0;
3206 TCGv_i32 t1, t2, t3;
3207 gen_set_access_type(ctx, ACCESS_INT);
76a66253 3208 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 3209 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
3210 t0 = tcg_temp_new();
3211 gen_addr_reg_index(ctx, t0);
3212 t1 = tcg_const_i32(rD(ctx->opcode));
3213 t2 = tcg_const_i32(rA(ctx->opcode));
3214 t3 = tcg_const_i32(rB(ctx->opcode));
2f5a189c 3215 gen_helper_lswx(cpu_env, t0, t1, t2, t3);
dfbc799d
AJ
3216 tcg_temp_free(t0);
3217 tcg_temp_free_i32(t1);
3218 tcg_temp_free_i32(t2);
3219 tcg_temp_free_i32(t3);
79aceca5
FB
3220}
3221
3222/* stswi */
99e300ef 3223static void gen_stswi(DisasContext *ctx)
79aceca5 3224{
76db3ba4
AJ
3225 TCGv t0;
3226 TCGv_i32 t1, t2;
4b3686fa 3227 int nb = NB(ctx->opcode);
76db3ba4 3228 gen_set_access_type(ctx, ACCESS_INT);
76a66253 3229 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 3230 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
3231 t0 = tcg_temp_new();
3232 gen_addr_register(ctx, t0);
4b3686fa
FB
3233 if (nb == 0)
3234 nb = 32;
dfbc799d 3235 t1 = tcg_const_i32(nb);
76db3ba4 3236 t2 = tcg_const_i32(rS(ctx->opcode));
2f5a189c 3237 gen_helper_stsw(cpu_env, t0, t1, t2);
dfbc799d
AJ
3238 tcg_temp_free(t0);
3239 tcg_temp_free_i32(t1);
3240 tcg_temp_free_i32(t2);
79aceca5
FB
3241}
3242
3243/* stswx */
99e300ef 3244static void gen_stswx(DisasContext *ctx)
79aceca5 3245{
76db3ba4
AJ
3246 TCGv t0;
3247 TCGv_i32 t1, t2;
3248 gen_set_access_type(ctx, ACCESS_INT);
8dd4983c 3249 /* NIP cannot be restored if the memory exception comes from an helper */
5fafdf24 3250 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
3251 t0 = tcg_temp_new();
3252 gen_addr_reg_index(ctx, t0);
3253 t1 = tcg_temp_new_i32();
dfbc799d
AJ
3254 tcg_gen_trunc_tl_i32(t1, cpu_xer);
3255 tcg_gen_andi_i32(t1, t1, 0x7F);
76db3ba4 3256 t2 = tcg_const_i32(rS(ctx->opcode));
2f5a189c 3257 gen_helper_stsw(cpu_env, t0, t1, t2);
dfbc799d
AJ
3258 tcg_temp_free(t0);
3259 tcg_temp_free_i32(t1);
3260 tcg_temp_free_i32(t2);
79aceca5
FB
3261}
3262
3263/*** Memory synchronisation ***/
3264/* eieio */
99e300ef 3265static void gen_eieio(DisasContext *ctx)
79aceca5 3266{
79aceca5
FB
3267}
3268
3269/* isync */
99e300ef 3270static void gen_isync(DisasContext *ctx)
79aceca5 3271{
e06fcd75 3272 gen_stop_exception(ctx);
79aceca5
FB
3273}
3274
5c77a786
TM
3275#define LARX(name, len, loadop) \
3276static void gen_##name(DisasContext *ctx) \
3277{ \
3278 TCGv t0; \
3279 TCGv gpr = cpu_gpr[rD(ctx->opcode)]; \
3280 gen_set_access_type(ctx, ACCESS_RES); \
3281 t0 = tcg_temp_local_new(); \
3282 gen_addr_reg_index(ctx, t0); \
3283 if ((len) > 1) { \
3284 gen_check_align(ctx, t0, (len)-1); \
3285 } \
3286 gen_qemu_##loadop(ctx, gpr, t0); \
3287 tcg_gen_mov_tl(cpu_reserve, t0); \
3288 tcg_gen_st_tl(gpr, cpu_env, offsetof(CPUPPCState, reserve_val)); \
3289 tcg_temp_free(t0); \
79aceca5
FB
3290}
3291
5c77a786
TM
3292/* lwarx */
3293LARX(lbarx, 1, ld8u);
3294LARX(lharx, 2, ld16u);
3295LARX(lwarx, 4, ld32u);
3296
3297
4425265b 3298#if defined(CONFIG_USER_ONLY)
587c51f7
TM
3299static void gen_conditional_store(DisasContext *ctx, TCGv EA,
3300 int reg, int size)
4425265b
NF
3301{
3302 TCGv t0 = tcg_temp_new();
3303 uint32_t save_exception = ctx->exception;
3304
1328c2bf 3305 tcg_gen_st_tl(EA, cpu_env, offsetof(CPUPPCState, reserve_ea));
4425265b 3306 tcg_gen_movi_tl(t0, (size << 5) | reg);
1328c2bf 3307 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUPPCState, reserve_info));
4425265b
NF
3308 tcg_temp_free(t0);
3309 gen_update_nip(ctx, ctx->nip-4);
3310 ctx->exception = POWERPC_EXCP_BRANCH;
3311 gen_exception(ctx, POWERPC_EXCP_STCX);
3312 ctx->exception = save_exception;
3313}
4425265b 3314#else
587c51f7
TM
3315static void gen_conditional_store(DisasContext *ctx, TCGv EA,
3316 int reg, int size)
3317{
3318 int l1;
4425265b 3319
587c51f7
TM
3320 tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so);
3321 l1 = gen_new_label();
3322 tcg_gen_brcond_tl(TCG_COND_NE, EA, cpu_reserve, l1);
3323 tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 1 << CRF_EQ);
3324#if defined(TARGET_PPC64)
3325 if (size == 8) {
3326 gen_qemu_st64(ctx, cpu_gpr[reg], EA);
3327 } else
3328#endif
3329 if (size == 4) {
3330 gen_qemu_st32(ctx, cpu_gpr[reg], EA);
3331 } else if (size == 2) {
3332 gen_qemu_st16(ctx, cpu_gpr[reg], EA);
27b95bfe
TM
3333#if defined(TARGET_PPC64)
3334 } else if (size == 16) {
3707cd62 3335 TCGv gpr1, gpr2 , EA8;
27b95bfe
TM
3336 if (unlikely(ctx->le_mode)) {
3337 gpr1 = cpu_gpr[reg+1];
3338 gpr2 = cpu_gpr[reg];
3339 } else {
3340 gpr1 = cpu_gpr[reg];
3341 gpr2 = cpu_gpr[reg+1];
3342 }
3343 gen_qemu_st64(ctx, gpr1, EA);
3707cd62
TM
3344 EA8 = tcg_temp_local_new();
3345 gen_addr_add(ctx, EA8, EA, 8);
3346 gen_qemu_st64(ctx, gpr2, EA8);
3347 tcg_temp_free(EA8);
27b95bfe 3348#endif
587c51f7
TM
3349 } else {
3350 gen_qemu_st8(ctx, cpu_gpr[reg], EA);
4425265b 3351 }
587c51f7
TM
3352 gen_set_label(l1);
3353 tcg_gen_movi_tl(cpu_reserve, -1);
3354}
4425265b 3355#endif
587c51f7
TM
3356
3357#define STCX(name, len) \
3358static void gen_##name(DisasContext *ctx) \
3359{ \
3360 TCGv t0; \
27b95bfe
TM
3361 if (unlikely((len == 16) && (rD(ctx->opcode) & 1))) { \
3362 gen_inval_exception(ctx, \
3363 POWERPC_EXCP_INVAL_INVAL); \
3364 return; \
3365 } \
587c51f7
TM
3366 gen_set_access_type(ctx, ACCESS_RES); \
3367 t0 = tcg_temp_local_new(); \
3368 gen_addr_reg_index(ctx, t0); \
3369 if (len > 1) { \
3370 gen_check_align(ctx, t0, (len)-1); \
3371 } \
3372 gen_conditional_store(ctx, t0, rS(ctx->opcode), len); \
3373 tcg_temp_free(t0); \
79aceca5
FB
3374}
3375
587c51f7
TM
3376STCX(stbcx_, 1);
3377STCX(sthcx_, 2);
3378STCX(stwcx_, 4);
3379
426613db 3380#if defined(TARGET_PPC64)
426613db 3381/* ldarx */
5c77a786 3382LARX(ldarx, 8, ld64);
426613db 3383
9c294d5a
TM
3384/* lqarx */
3385static void gen_lqarx(DisasContext *ctx)
3386{
3387 TCGv EA;
3388 int rd = rD(ctx->opcode);
3389 TCGv gpr1, gpr2;
3390
3391 if (unlikely((rd & 1) || (rd == rA(ctx->opcode)) ||
3392 (rd == rB(ctx->opcode)))) {
3393 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
3394 return;
3395 }
3396
3397 gen_set_access_type(ctx, ACCESS_RES);
3398 EA = tcg_temp_local_new();
3399 gen_addr_reg_index(ctx, EA);
3400 gen_check_align(ctx, EA, 15);
3401 if (unlikely(ctx->le_mode)) {
3402 gpr1 = cpu_gpr[rd+1];
3403 gpr2 = cpu_gpr[rd];
3404 } else {
3405 gpr1 = cpu_gpr[rd];
3406 gpr2 = cpu_gpr[rd+1];
3407 }
3408 gen_qemu_ld64(ctx, gpr1, EA);
3409 tcg_gen_mov_tl(cpu_reserve, EA);
3410
3411 gen_addr_add(ctx, EA, EA, 8);
3412 gen_qemu_ld64(ctx, gpr2, EA);
3413
3414 tcg_gen_st_tl(gpr1, cpu_env, offsetof(CPUPPCState, reserve_val));
3415 tcg_gen_st_tl(gpr2, cpu_env, offsetof(CPUPPCState, reserve_val2));
3416
3417 tcg_temp_free(EA);
3418}
3419
426613db 3420/* stdcx. */
587c51f7 3421STCX(stdcx_, 8);
27b95bfe 3422STCX(stqcx_, 16);
426613db
JM
3423#endif /* defined(TARGET_PPC64) */
3424
79aceca5 3425/* sync */
99e300ef 3426static void gen_sync(DisasContext *ctx)
79aceca5 3427{
79aceca5
FB
3428}
3429
0db1b20e 3430/* wait */
99e300ef 3431static void gen_wait(DisasContext *ctx)
0db1b20e 3432{
931ff272 3433 TCGv_i32 t0 = tcg_temp_new_i32();
259186a7
AF
3434 tcg_gen_st_i32(t0, cpu_env,
3435 -offsetof(PowerPCCPU, env) + offsetof(CPUState, halted));
931ff272 3436 tcg_temp_free_i32(t0);
0db1b20e 3437 /* Stop translation, as the CPU is supposed to sleep from now */
e06fcd75 3438 gen_exception_err(ctx, EXCP_HLT, 1);
0db1b20e
JM
3439}
3440
79aceca5 3441/*** Floating-point load ***/
a0d7d5a7 3442#define GEN_LDF(name, ldop, opc, type) \
99e300ef 3443static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 3444{ \
a0d7d5a7 3445 TCGv EA; \
76a66253 3446 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3447 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3448 return; \
3449 } \
76db3ba4 3450 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3451 EA = tcg_temp_new(); \
76db3ba4
AJ
3452 gen_addr_imm_index(ctx, EA, 0); \
3453 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
a0d7d5a7 3454 tcg_temp_free(EA); \
79aceca5
FB
3455}
3456
a0d7d5a7 3457#define GEN_LDUF(name, ldop, opc, type) \
99e300ef 3458static void glue(gen_, name##u)(DisasContext *ctx) \
79aceca5 3459{ \
a0d7d5a7 3460 TCGv EA; \
76a66253 3461 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3462 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3463 return; \
3464 } \
76a66253 3465 if (unlikely(rA(ctx->opcode) == 0)) { \
e06fcd75 3466 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 3467 return; \
9a64fbe4 3468 } \
76db3ba4 3469 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3470 EA = tcg_temp_new(); \
76db3ba4
AJ
3471 gen_addr_imm_index(ctx, EA, 0); \
3472 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
a0d7d5a7
AJ
3473 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3474 tcg_temp_free(EA); \
79aceca5
FB
3475}
3476
a0d7d5a7 3477#define GEN_LDUXF(name, ldop, opc, type) \
99e300ef 3478static void glue(gen_, name##ux)(DisasContext *ctx) \
79aceca5 3479{ \
a0d7d5a7 3480 TCGv EA; \
76a66253 3481 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3482 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3483 return; \
3484 } \
76a66253 3485 if (unlikely(rA(ctx->opcode) == 0)) { \
e06fcd75 3486 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 3487 return; \
9a64fbe4 3488 } \
76db3ba4 3489 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3490 EA = tcg_temp_new(); \
76db3ba4
AJ
3491 gen_addr_reg_index(ctx, EA); \
3492 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
a0d7d5a7
AJ
3493 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3494 tcg_temp_free(EA); \
79aceca5
FB
3495}
3496
a0d7d5a7 3497#define GEN_LDXF(name, ldop, opc2, opc3, type) \
99e300ef 3498static void glue(gen_, name##x)(DisasContext *ctx) \
79aceca5 3499{ \
a0d7d5a7 3500 TCGv EA; \
76a66253 3501 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3502 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3503 return; \
3504 } \
76db3ba4 3505 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3506 EA = tcg_temp_new(); \
76db3ba4
AJ
3507 gen_addr_reg_index(ctx, EA); \
3508 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
a0d7d5a7 3509 tcg_temp_free(EA); \
79aceca5
FB
3510}
3511
a0d7d5a7
AJ
3512#define GEN_LDFS(name, ldop, op, type) \
3513GEN_LDF(name, ldop, op | 0x20, type); \
3514GEN_LDUF(name, ldop, op | 0x21, type); \
3515GEN_LDUXF(name, ldop, op | 0x01, type); \
3516GEN_LDXF(name, ldop, 0x17, op | 0x00, type)
3517
636aa200 3518static inline void gen_qemu_ld32fs(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
a0d7d5a7
AJ
3519{
3520 TCGv t0 = tcg_temp_new();
3521 TCGv_i32 t1 = tcg_temp_new_i32();
76db3ba4 3522 gen_qemu_ld32u(ctx, t0, arg2);
a0d7d5a7
AJ
3523 tcg_gen_trunc_tl_i32(t1, t0);
3524 tcg_temp_free(t0);
8e703949 3525 gen_helper_float32_to_float64(arg1, cpu_env, t1);
a0d7d5a7
AJ
3526 tcg_temp_free_i32(t1);
3527}
79aceca5 3528
a0d7d5a7
AJ
3529 /* lfd lfdu lfdux lfdx */
3530GEN_LDFS(lfd, ld64, 0x12, PPC_FLOAT);
3531 /* lfs lfsu lfsux lfsx */
3532GEN_LDFS(lfs, ld32fs, 0x10, PPC_FLOAT);
79aceca5 3533
05050ee8
AJ
3534/* lfdp */
3535static void gen_lfdp(DisasContext *ctx)
3536{
3537 TCGv EA;
3538 if (unlikely(!ctx->fpu_enabled)) {
3539 gen_exception(ctx, POWERPC_EXCP_FPU);
3540 return;
3541 }
3542 gen_set_access_type(ctx, ACCESS_FLOAT);
3543 EA = tcg_temp_new();
3544 gen_addr_imm_index(ctx, EA, 0); \
3545 if (unlikely(ctx->le_mode)) {
3546 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3547 tcg_gen_addi_tl(EA, EA, 8);
3548 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3549 } else {
3550 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3551 tcg_gen_addi_tl(EA, EA, 8);
3552 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3553 }
3554 tcg_temp_free(EA);
3555}
3556
3557/* lfdpx */
3558static void gen_lfdpx(DisasContext *ctx)
3559{
3560 TCGv EA;
3561 if (unlikely(!ctx->fpu_enabled)) {
3562 gen_exception(ctx, POWERPC_EXCP_FPU);
3563 return;
3564 }
3565 gen_set_access_type(ctx, ACCESS_FLOAT);
3566 EA = tcg_temp_new();
3567 gen_addr_reg_index(ctx, EA);
3568 if (unlikely(ctx->le_mode)) {
3569 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3570 tcg_gen_addi_tl(EA, EA, 8);
3571 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3572 } else {
3573 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3574 tcg_gen_addi_tl(EA, EA, 8);
3575 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3576 }
3577 tcg_temp_free(EA);
3578}
3579
199f830d
AJ
3580/* lfiwax */
3581static void gen_lfiwax(DisasContext *ctx)
3582{
3583 TCGv EA;
3584 TCGv t0;
3585 if (unlikely(!ctx->fpu_enabled)) {
3586 gen_exception(ctx, POWERPC_EXCP_FPU);
3587 return;
3588 }
3589 gen_set_access_type(ctx, ACCESS_FLOAT);
3590 EA = tcg_temp_new();
3591 t0 = tcg_temp_new();
3592 gen_addr_reg_index(ctx, EA);
909eedb7 3593 gen_qemu_ld32s(ctx, t0, EA);
199f830d 3594 tcg_gen_ext_tl_i64(cpu_fpr[rD(ctx->opcode)], t0);
199f830d
AJ
3595 tcg_temp_free(EA);
3596 tcg_temp_free(t0);
3597}
3598
66c3e328
TM
3599/* lfiwzx */
3600static void gen_lfiwzx(DisasContext *ctx)
3601{
3602 TCGv EA;
3603 if (unlikely(!ctx->fpu_enabled)) {
3604 gen_exception(ctx, POWERPC_EXCP_FPU);
3605 return;
3606 }
3607 gen_set_access_type(ctx, ACCESS_FLOAT);
3608 EA = tcg_temp_new();
3609 gen_addr_reg_index(ctx, EA);
3610 gen_qemu_ld32u_i64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3611 tcg_temp_free(EA);
3612}
79aceca5 3613/*** Floating-point store ***/
a0d7d5a7 3614#define GEN_STF(name, stop, opc, type) \
99e300ef 3615static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 3616{ \
a0d7d5a7 3617 TCGv EA; \
76a66253 3618 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3619 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3620 return; \
3621 } \
76db3ba4 3622 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3623 EA = tcg_temp_new(); \
76db3ba4
AJ
3624 gen_addr_imm_index(ctx, EA, 0); \
3625 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
a0d7d5a7 3626 tcg_temp_free(EA); \
79aceca5
FB
3627}
3628
a0d7d5a7 3629#define GEN_STUF(name, stop, opc, type) \
99e300ef 3630static void glue(gen_, name##u)(DisasContext *ctx) \
79aceca5 3631{ \
a0d7d5a7 3632 TCGv EA; \
76a66253 3633 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3634 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3635 return; \
3636 } \
76a66253 3637 if (unlikely(rA(ctx->opcode) == 0)) { \
e06fcd75 3638 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 3639 return; \
9a64fbe4 3640 } \
76db3ba4 3641 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3642 EA = tcg_temp_new(); \
76db3ba4
AJ
3643 gen_addr_imm_index(ctx, EA, 0); \
3644 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
a0d7d5a7
AJ
3645 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3646 tcg_temp_free(EA); \
79aceca5
FB
3647}
3648
a0d7d5a7 3649#define GEN_STUXF(name, stop, opc, type) \
99e300ef 3650static void glue(gen_, name##ux)(DisasContext *ctx) \
79aceca5 3651{ \
a0d7d5a7 3652 TCGv EA; \
76a66253 3653 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3654 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3655 return; \
3656 } \
76a66253 3657 if (unlikely(rA(ctx->opcode) == 0)) { \
e06fcd75 3658 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 3659 return; \
9a64fbe4 3660 } \
76db3ba4 3661 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3662 EA = tcg_temp_new(); \
76db3ba4
AJ
3663 gen_addr_reg_index(ctx, EA); \
3664 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
a0d7d5a7
AJ
3665 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3666 tcg_temp_free(EA); \
79aceca5
FB
3667}
3668
a0d7d5a7 3669#define GEN_STXF(name, stop, opc2, opc3, type) \
99e300ef 3670static void glue(gen_, name##x)(DisasContext *ctx) \
79aceca5 3671{ \
a0d7d5a7 3672 TCGv EA; \
76a66253 3673 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3674 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3675 return; \
3676 } \
76db3ba4 3677 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3678 EA = tcg_temp_new(); \
76db3ba4
AJ
3679 gen_addr_reg_index(ctx, EA); \
3680 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
a0d7d5a7 3681 tcg_temp_free(EA); \
79aceca5
FB
3682}
3683
a0d7d5a7
AJ
3684#define GEN_STFS(name, stop, op, type) \
3685GEN_STF(name, stop, op | 0x20, type); \
3686GEN_STUF(name, stop, op | 0x21, type); \
3687GEN_STUXF(name, stop, op | 0x01, type); \
3688GEN_STXF(name, stop, 0x17, op | 0x00, type)
3689
636aa200 3690static inline void gen_qemu_st32fs(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
a0d7d5a7
AJ
3691{
3692 TCGv_i32 t0 = tcg_temp_new_i32();
3693 TCGv t1 = tcg_temp_new();
8e703949 3694 gen_helper_float64_to_float32(t0, cpu_env, arg1);
a0d7d5a7
AJ
3695 tcg_gen_extu_i32_tl(t1, t0);
3696 tcg_temp_free_i32(t0);
76db3ba4 3697 gen_qemu_st32(ctx, t1, arg2);
a0d7d5a7
AJ
3698 tcg_temp_free(t1);
3699}
79aceca5
FB
3700
3701/* stfd stfdu stfdux stfdx */
a0d7d5a7 3702GEN_STFS(stfd, st64, 0x16, PPC_FLOAT);
79aceca5 3703/* stfs stfsu stfsux stfsx */
a0d7d5a7 3704GEN_STFS(stfs, st32fs, 0x14, PPC_FLOAT);
79aceca5 3705
44bc0c4d
AJ
3706/* stfdp */
3707static void gen_stfdp(DisasContext *ctx)
3708{
3709 TCGv EA;
3710 if (unlikely(!ctx->fpu_enabled)) {
3711 gen_exception(ctx, POWERPC_EXCP_FPU);
3712 return;
3713 }
3714 gen_set_access_type(ctx, ACCESS_FLOAT);
3715 EA = tcg_temp_new();
3716 gen_addr_imm_index(ctx, EA, 0); \
3717 if (unlikely(ctx->le_mode)) {
3718 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3719 tcg_gen_addi_tl(EA, EA, 8);
3720 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3721 } else {
3722 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3723 tcg_gen_addi_tl(EA, EA, 8);
3724 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3725 }
3726 tcg_temp_free(EA);
3727}
3728
3729/* stfdpx */
3730static void gen_stfdpx(DisasContext *ctx)
3731{
3732 TCGv EA;
3733 if (unlikely(!ctx->fpu_enabled)) {
3734 gen_exception(ctx, POWERPC_EXCP_FPU);
3735 return;
3736 }
3737 gen_set_access_type(ctx, ACCESS_FLOAT);
3738 EA = tcg_temp_new();
3739 gen_addr_reg_index(ctx, EA);
3740 if (unlikely(ctx->le_mode)) {
3741 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3742 tcg_gen_addi_tl(EA, EA, 8);
3743 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3744 } else {
3745 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3746 tcg_gen_addi_tl(EA, EA, 8);
3747 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3748 }
3749 tcg_temp_free(EA);
3750}
3751
79aceca5 3752/* Optional: */
636aa200 3753static inline void gen_qemu_st32fiw(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
a0d7d5a7
AJ
3754{
3755 TCGv t0 = tcg_temp_new();
3756 tcg_gen_trunc_i64_tl(t0, arg1),
76db3ba4 3757 gen_qemu_st32(ctx, t0, arg2);
a0d7d5a7
AJ
3758 tcg_temp_free(t0);
3759}
79aceca5 3760/* stfiwx */
a0d7d5a7 3761GEN_STXF(stfiw, st32fiw, 0x17, 0x1E, PPC_FLOAT_STFIWX);
79aceca5 3762
697ab892
DG
3763static inline void gen_update_cfar(DisasContext *ctx, target_ulong nip)
3764{
3765#if defined(TARGET_PPC64)
3766 if (ctx->has_cfar)
3767 tcg_gen_movi_tl(cpu_cfar, nip);
3768#endif
3769}
3770
79aceca5 3771/*** Branch ***/
636aa200 3772static inline void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest)
c1942362
FB
3773{
3774 TranslationBlock *tb;
3775 tb = ctx->tb;
e0c8f9ce 3776 if (NARROW_MODE(ctx)) {
a2ffb812 3777 dest = (uint32_t) dest;
e0c8f9ce 3778 }
57fec1fe 3779 if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK) &&
8cbcb4fa 3780 likely(!ctx->singlestep_enabled)) {
57fec1fe 3781 tcg_gen_goto_tb(n);
a2ffb812 3782 tcg_gen_movi_tl(cpu_nip, dest & ~3);
8cfd0495 3783 tcg_gen_exit_tb((uintptr_t)tb + n);
c1942362 3784 } else {
a2ffb812 3785 tcg_gen_movi_tl(cpu_nip, dest & ~3);
8cbcb4fa
AJ
3786 if (unlikely(ctx->singlestep_enabled)) {
3787 if ((ctx->singlestep_enabled &
bdc4e053 3788 (CPU_BRANCH_STEP | CPU_SINGLE_STEP)) &&
f0cc4aa8
JG
3789 (ctx->exception == POWERPC_EXCP_BRANCH ||
3790 ctx->exception == POWERPC_EXCP_TRACE)) {
8cbcb4fa
AJ
3791 target_ulong tmp = ctx->nip;
3792 ctx->nip = dest;
e06fcd75 3793 gen_exception(ctx, POWERPC_EXCP_TRACE);
8cbcb4fa
AJ
3794 ctx->nip = tmp;
3795 }
3796 if (ctx->singlestep_enabled & GDBSTUB_SINGLE_STEP) {
e06fcd75 3797 gen_debug_exception(ctx);
8cbcb4fa
AJ
3798 }
3799 }
57fec1fe 3800 tcg_gen_exit_tb(0);
c1942362 3801 }
c53be334
FB
3802}
3803
636aa200 3804static inline void gen_setlr(DisasContext *ctx, target_ulong nip)
e1833e1f 3805{
e0c8f9ce
RH
3806 if (NARROW_MODE(ctx)) {
3807 nip = (uint32_t)nip;
3808 }
3809 tcg_gen_movi_tl(cpu_lr, nip);
e1833e1f
JM
3810}
3811
79aceca5 3812/* b ba bl bla */
99e300ef 3813static void gen_b(DisasContext *ctx)
79aceca5 3814{
76a66253 3815 target_ulong li, target;
38a64f9d 3816
8cbcb4fa 3817 ctx->exception = POWERPC_EXCP_BRANCH;
38a64f9d 3818 /* sign extend LI */
e0c8f9ce
RH
3819 li = LI(ctx->opcode);
3820 li = (li ^ 0x02000000) - 0x02000000;
3821 if (likely(AA(ctx->opcode) == 0)) {
046d6672 3822 target = ctx->nip + li - 4;
e0c8f9ce 3823 } else {
9a64fbe4 3824 target = li;
e0c8f9ce
RH
3825 }
3826 if (LK(ctx->opcode)) {
e1833e1f 3827 gen_setlr(ctx, ctx->nip);
e0c8f9ce 3828 }
697ab892 3829 gen_update_cfar(ctx, ctx->nip);
c1942362 3830 gen_goto_tb(ctx, 0, target);
79aceca5
FB
3831}
3832
e98a6e40
FB
3833#define BCOND_IM 0
3834#define BCOND_LR 1
3835#define BCOND_CTR 2
52a4984d 3836#define BCOND_TAR 3
e98a6e40 3837
636aa200 3838static inline void gen_bcond(DisasContext *ctx, int type)
d9bce9d9 3839{
d9bce9d9 3840 uint32_t bo = BO(ctx->opcode);
05f92404 3841 int l1;
a2ffb812 3842 TCGv target;
e98a6e40 3843
8cbcb4fa 3844 ctx->exception = POWERPC_EXCP_BRANCH;
52a4984d 3845 if (type == BCOND_LR || type == BCOND_CTR || type == BCOND_TAR) {
a7812ae4 3846 target = tcg_temp_local_new();
a2ffb812
AJ
3847 if (type == BCOND_CTR)
3848 tcg_gen_mov_tl(target, cpu_ctr);
52a4984d
TM
3849 else if (type == BCOND_TAR)
3850 gen_load_spr(target, SPR_TAR);
a2ffb812
AJ
3851 else
3852 tcg_gen_mov_tl(target, cpu_lr);
d2e9fd8f 3853 } else {
3854 TCGV_UNUSED(target);
e98a6e40 3855 }
e1833e1f
JM
3856 if (LK(ctx->opcode))
3857 gen_setlr(ctx, ctx->nip);
a2ffb812
AJ
3858 l1 = gen_new_label();
3859 if ((bo & 0x4) == 0) {
3860 /* Decrement and test CTR */
a7812ae4 3861 TCGv temp = tcg_temp_new();
a2ffb812 3862 if (unlikely(type == BCOND_CTR)) {
e06fcd75 3863 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
a2ffb812
AJ
3864 return;
3865 }
3866 tcg_gen_subi_tl(cpu_ctr, cpu_ctr, 1);
e0c8f9ce 3867 if (NARROW_MODE(ctx)) {
a2ffb812 3868 tcg_gen_ext32u_tl(temp, cpu_ctr);
e0c8f9ce 3869 } else {
a2ffb812 3870 tcg_gen_mov_tl(temp, cpu_ctr);
e0c8f9ce 3871 }
a2ffb812
AJ
3872 if (bo & 0x2) {
3873 tcg_gen_brcondi_tl(TCG_COND_NE, temp, 0, l1);
3874 } else {
3875 tcg_gen_brcondi_tl(TCG_COND_EQ, temp, 0, l1);
e98a6e40 3876 }
a7812ae4 3877 tcg_temp_free(temp);
a2ffb812
AJ
3878 }
3879 if ((bo & 0x10) == 0) {
3880 /* Test CR */
3881 uint32_t bi = BI(ctx->opcode);
3882 uint32_t mask = 1 << (3 - (bi & 0x03));
a7812ae4 3883 TCGv_i32 temp = tcg_temp_new_i32();
a2ffb812 3884
d9bce9d9 3885 if (bo & 0x8) {
a2ffb812
AJ
3886 tcg_gen_andi_i32(temp, cpu_crf[bi >> 2], mask);
3887 tcg_gen_brcondi_i32(TCG_COND_EQ, temp, 0, l1);
d9bce9d9 3888 } else {
a2ffb812
AJ
3889 tcg_gen_andi_i32(temp, cpu_crf[bi >> 2], mask);
3890 tcg_gen_brcondi_i32(TCG_COND_NE, temp, 0, l1);
d9bce9d9 3891 }
a7812ae4 3892 tcg_temp_free_i32(temp);
d9bce9d9 3893 }
697ab892 3894 gen_update_cfar(ctx, ctx->nip);
e98a6e40 3895 if (type == BCOND_IM) {
a2ffb812
AJ
3896 target_ulong li = (target_long)((int16_t)(BD(ctx->opcode)));
3897 if (likely(AA(ctx->opcode) == 0)) {
3898 gen_goto_tb(ctx, 0, ctx->nip + li - 4);
3899 } else {
3900 gen_goto_tb(ctx, 0, li);
3901 }
c53be334 3902 gen_set_label(l1);
c1942362 3903 gen_goto_tb(ctx, 1, ctx->nip);
e98a6e40 3904 } else {
e0c8f9ce 3905 if (NARROW_MODE(ctx)) {
a2ffb812 3906 tcg_gen_andi_tl(cpu_nip, target, (uint32_t)~3);
e0c8f9ce 3907 } else {
a2ffb812 3908 tcg_gen_andi_tl(cpu_nip, target, ~3);
e0c8f9ce 3909 }
a2ffb812
AJ
3910 tcg_gen_exit_tb(0);
3911 gen_set_label(l1);
e0c8f9ce 3912 gen_update_nip(ctx, ctx->nip);
57fec1fe 3913 tcg_gen_exit_tb(0);
08e46e54 3914 }
e98a6e40
FB
3915}
3916
99e300ef 3917static void gen_bc(DisasContext *ctx)
3b46e624 3918{
e98a6e40
FB
3919 gen_bcond(ctx, BCOND_IM);
3920}
3921
99e300ef 3922static void gen_bcctr(DisasContext *ctx)
3b46e624 3923{
e98a6e40
FB
3924 gen_bcond(ctx, BCOND_CTR);
3925}
3926
99e300ef 3927static void gen_bclr(DisasContext *ctx)
3b46e624 3928{
e98a6e40
FB
3929 gen_bcond(ctx, BCOND_LR);
3930}
79aceca5 3931
52a4984d
TM
3932static void gen_bctar(DisasContext *ctx)
3933{
3934 gen_bcond(ctx, BCOND_TAR);
3935}
3936
79aceca5 3937/*** Condition register logical ***/
e1571908 3938#define GEN_CRLOGIC(name, tcg_op, opc) \
99e300ef 3939static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 3940{ \
fc0d441e
JM
3941 uint8_t bitmask; \
3942 int sh; \
a7812ae4 3943 TCGv_i32 t0, t1; \
fc0d441e 3944 sh = (crbD(ctx->opcode) & 0x03) - (crbA(ctx->opcode) & 0x03); \
a7812ae4 3945 t0 = tcg_temp_new_i32(); \
fc0d441e 3946 if (sh > 0) \
fea0c503 3947 tcg_gen_shri_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], sh); \
fc0d441e 3948 else if (sh < 0) \
fea0c503 3949 tcg_gen_shli_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], -sh); \
e1571908 3950 else \
fea0c503 3951 tcg_gen_mov_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2]); \
a7812ae4 3952 t1 = tcg_temp_new_i32(); \
fc0d441e
JM
3953 sh = (crbD(ctx->opcode) & 0x03) - (crbB(ctx->opcode) & 0x03); \
3954 if (sh > 0) \
fea0c503 3955 tcg_gen_shri_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], sh); \
fc0d441e 3956 else if (sh < 0) \
fea0c503 3957 tcg_gen_shli_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], -sh); \
e1571908 3958 else \
fea0c503
AJ
3959 tcg_gen_mov_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2]); \
3960 tcg_op(t0, t0, t1); \
fc0d441e 3961 bitmask = 1 << (3 - (crbD(ctx->opcode) & 0x03)); \
fea0c503
AJ
3962 tcg_gen_andi_i32(t0, t0, bitmask); \
3963 tcg_gen_andi_i32(t1, cpu_crf[crbD(ctx->opcode) >> 2], ~bitmask); \
3964 tcg_gen_or_i32(cpu_crf[crbD(ctx->opcode) >> 2], t0, t1); \
a7812ae4
PB
3965 tcg_temp_free_i32(t0); \
3966 tcg_temp_free_i32(t1); \
79aceca5
FB
3967}
3968
3969/* crand */
e1571908 3970GEN_CRLOGIC(crand, tcg_gen_and_i32, 0x08);
79aceca5 3971/* crandc */
e1571908 3972GEN_CRLOGIC(crandc, tcg_gen_andc_i32, 0x04);
79aceca5 3973/* creqv */
e1571908 3974GEN_CRLOGIC(creqv, tcg_gen_eqv_i32, 0x09);
79aceca5 3975/* crnand */
e1571908 3976GEN_CRLOGIC(crnand, tcg_gen_nand_i32, 0x07);
79aceca5 3977/* crnor */
e1571908 3978GEN_CRLOGIC(crnor, tcg_gen_nor_i32, 0x01);
79aceca5 3979/* cror */
e1571908 3980GEN_CRLOGIC(cror, tcg_gen_or_i32, 0x0E);
79aceca5 3981/* crorc */
e1571908 3982GEN_CRLOGIC(crorc, tcg_gen_orc_i32, 0x0D);
79aceca5 3983/* crxor */
e1571908 3984GEN_CRLOGIC(crxor, tcg_gen_xor_i32, 0x06);
99e300ef 3985
54623277 3986/* mcrf */
99e300ef 3987static void gen_mcrf(DisasContext *ctx)
79aceca5 3988{
47e4661c 3989 tcg_gen_mov_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfS(ctx->opcode)]);
79aceca5
FB
3990}
3991
3992/*** System linkage ***/
99e300ef 3993
54623277 3994/* rfi (mem_idx only) */
99e300ef 3995static void gen_rfi(DisasContext *ctx)
79aceca5 3996{
9a64fbe4 3997#if defined(CONFIG_USER_ONLY)
e06fcd75 3998 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9a64fbe4
FB
3999#else
4000 /* Restore CPU state */
76db3ba4 4001 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4002 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9fddaa0c 4003 return;
9a64fbe4 4004 }
697ab892 4005 gen_update_cfar(ctx, ctx->nip);
e5f17ac6 4006 gen_helper_rfi(cpu_env);
e06fcd75 4007 gen_sync_exception(ctx);
9a64fbe4 4008#endif
79aceca5
FB
4009}
4010
426613db 4011#if defined(TARGET_PPC64)
99e300ef 4012static void gen_rfid(DisasContext *ctx)
426613db
JM
4013{
4014#if defined(CONFIG_USER_ONLY)
e06fcd75 4015 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db
JM
4016#else
4017 /* Restore CPU state */
76db3ba4 4018 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4019 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db
JM
4020 return;
4021 }
697ab892 4022 gen_update_cfar(ctx, ctx->nip);
e5f17ac6 4023 gen_helper_rfid(cpu_env);
e06fcd75 4024 gen_sync_exception(ctx);
426613db
JM
4025#endif
4026}
426613db 4027
99e300ef 4028static void gen_hrfid(DisasContext *ctx)
be147d08
JM
4029{
4030#if defined(CONFIG_USER_ONLY)
e06fcd75 4031 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
be147d08
JM
4032#else
4033 /* Restore CPU state */
76db3ba4 4034 if (unlikely(ctx->mem_idx <= 1)) {
e06fcd75 4035 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
be147d08
JM
4036 return;
4037 }
e5f17ac6 4038 gen_helper_hrfid(cpu_env);
e06fcd75 4039 gen_sync_exception(ctx);
be147d08
JM
4040#endif
4041}
4042#endif
4043
79aceca5 4044/* sc */
417bf010
JM
4045#if defined(CONFIG_USER_ONLY)
4046#define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL_USER
4047#else
4048#define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL
4049#endif
99e300ef 4050static void gen_sc(DisasContext *ctx)
79aceca5 4051{
e1833e1f
JM
4052 uint32_t lev;
4053
4054 lev = (ctx->opcode >> 5) & 0x7F;
e06fcd75 4055 gen_exception_err(ctx, POWERPC_SYSCALL, lev);
79aceca5
FB
4056}
4057
4058/*** Trap ***/
99e300ef 4059
54623277 4060/* tw */
99e300ef 4061static void gen_tw(DisasContext *ctx)
79aceca5 4062{
cab3bee2 4063 TCGv_i32 t0 = tcg_const_i32(TO(ctx->opcode));
db9a231d
AJ
4064 /* Update the nip since this might generate a trap exception */
4065 gen_update_nip(ctx, ctx->nip);
e5f17ac6
BS
4066 gen_helper_tw(cpu_env, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
4067 t0);
cab3bee2 4068 tcg_temp_free_i32(t0);
79aceca5
FB
4069}
4070
4071/* twi */
99e300ef 4072static void gen_twi(DisasContext *ctx)
79aceca5 4073{
cab3bee2
AJ
4074 TCGv t0 = tcg_const_tl(SIMM(ctx->opcode));
4075 TCGv_i32 t1 = tcg_const_i32(TO(ctx->opcode));
db9a231d
AJ
4076 /* Update the nip since this might generate a trap exception */
4077 gen_update_nip(ctx, ctx->nip);
e5f17ac6 4078 gen_helper_tw(cpu_env, cpu_gpr[rA(ctx->opcode)], t0, t1);
cab3bee2
AJ
4079 tcg_temp_free(t0);
4080 tcg_temp_free_i32(t1);
79aceca5
FB
4081}
4082
d9bce9d9
JM
4083#if defined(TARGET_PPC64)
4084/* td */
99e300ef 4085static void gen_td(DisasContext *ctx)
d9bce9d9 4086{
cab3bee2 4087 TCGv_i32 t0 = tcg_const_i32(TO(ctx->opcode));
db9a231d
AJ
4088 /* Update the nip since this might generate a trap exception */
4089 gen_update_nip(ctx, ctx->nip);
e5f17ac6
BS
4090 gen_helper_td(cpu_env, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
4091 t0);
cab3bee2 4092 tcg_temp_free_i32(t0);
d9bce9d9
JM
4093}
4094
4095/* tdi */
99e300ef 4096static void gen_tdi(DisasContext *ctx)
d9bce9d9 4097{
cab3bee2
AJ
4098 TCGv t0 = tcg_const_tl(SIMM(ctx->opcode));
4099 TCGv_i32 t1 = tcg_const_i32(TO(ctx->opcode));
db9a231d
AJ
4100 /* Update the nip since this might generate a trap exception */
4101 gen_update_nip(ctx, ctx->nip);
e5f17ac6 4102 gen_helper_td(cpu_env, cpu_gpr[rA(ctx->opcode)], t0, t1);
cab3bee2
AJ
4103 tcg_temp_free(t0);
4104 tcg_temp_free_i32(t1);
d9bce9d9
JM
4105}
4106#endif
4107
79aceca5 4108/*** Processor control ***/
99e300ef 4109
da91a00f
RH
4110static void gen_read_xer(TCGv dst)
4111{
4112 TCGv t0 = tcg_temp_new();
4113 TCGv t1 = tcg_temp_new();
4114 TCGv t2 = tcg_temp_new();
4115 tcg_gen_mov_tl(dst, cpu_xer);
4116 tcg_gen_shli_tl(t0, cpu_so, XER_SO);
4117 tcg_gen_shli_tl(t1, cpu_ov, XER_OV);
4118 tcg_gen_shli_tl(t2, cpu_ca, XER_CA);
4119 tcg_gen_or_tl(t0, t0, t1);
4120 tcg_gen_or_tl(dst, dst, t2);
4121 tcg_gen_or_tl(dst, dst, t0);
4122 tcg_temp_free(t0);
4123 tcg_temp_free(t1);
4124 tcg_temp_free(t2);
4125}
4126
4127static void gen_write_xer(TCGv src)
4128{
4129 tcg_gen_andi_tl(cpu_xer, src,
4130 ~((1u << XER_SO) | (1u << XER_OV) | (1u << XER_CA)));
4131 tcg_gen_shri_tl(cpu_so, src, XER_SO);
4132 tcg_gen_shri_tl(cpu_ov, src, XER_OV);
4133 tcg_gen_shri_tl(cpu_ca, src, XER_CA);
4134 tcg_gen_andi_tl(cpu_so, cpu_so, 1);
4135 tcg_gen_andi_tl(cpu_ov, cpu_ov, 1);
4136 tcg_gen_andi_tl(cpu_ca, cpu_ca, 1);
4137}
4138
54623277 4139/* mcrxr */
99e300ef 4140static void gen_mcrxr(DisasContext *ctx)
79aceca5 4141{
da91a00f
RH
4142 TCGv_i32 t0 = tcg_temp_new_i32();
4143 TCGv_i32 t1 = tcg_temp_new_i32();
4144 TCGv_i32 dst = cpu_crf[crfD(ctx->opcode)];
4145
4146 tcg_gen_trunc_tl_i32(t0, cpu_so);
4147 tcg_gen_trunc_tl_i32(t1, cpu_ov);
4148 tcg_gen_trunc_tl_i32(dst, cpu_ca);
4149 tcg_gen_shri_i32(t0, t0, 2);
4150 tcg_gen_shri_i32(t1, t1, 1);
4151 tcg_gen_or_i32(dst, dst, t0);
4152 tcg_gen_or_i32(dst, dst, t1);
4153 tcg_temp_free_i32(t0);
4154 tcg_temp_free_i32(t1);
4155
4156 tcg_gen_movi_tl(cpu_so, 0);
4157 tcg_gen_movi_tl(cpu_ov, 0);
4158 tcg_gen_movi_tl(cpu_ca, 0);
79aceca5
FB
4159}
4160
0cfe11ea 4161/* mfcr mfocrf */
99e300ef 4162static void gen_mfcr(DisasContext *ctx)
79aceca5 4163{
76a66253 4164 uint32_t crm, crn;
3b46e624 4165
76a66253
JM
4166 if (likely(ctx->opcode & 0x00100000)) {
4167 crm = CRM(ctx->opcode);
8dd640e4 4168 if (likely(crm && ((crm & (crm - 1)) == 0))) {
0cfe11ea 4169 crn = ctz32 (crm);
e1571908 4170 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], cpu_crf[7 - crn]);
0497d2f4
AJ
4171 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)],
4172 cpu_gpr[rD(ctx->opcode)], crn * 4);
76a66253 4173 }
d9bce9d9 4174 } else {
651721b2
AJ
4175 TCGv_i32 t0 = tcg_temp_new_i32();
4176 tcg_gen_mov_i32(t0, cpu_crf[0]);
4177 tcg_gen_shli_i32(t0, t0, 4);
4178 tcg_gen_or_i32(t0, t0, cpu_crf[1]);
4179 tcg_gen_shli_i32(t0, t0, 4);
4180 tcg_gen_or_i32(t0, t0, cpu_crf[2]);
4181 tcg_gen_shli_i32(t0, t0, 4);
4182 tcg_gen_or_i32(t0, t0, cpu_crf[3]);
4183 tcg_gen_shli_i32(t0, t0, 4);
4184 tcg_gen_or_i32(t0, t0, cpu_crf[4]);
4185 tcg_gen_shli_i32(t0, t0, 4);
4186 tcg_gen_or_i32(t0, t0, cpu_crf[5]);
4187 tcg_gen_shli_i32(t0, t0, 4);
4188 tcg_gen_or_i32(t0, t0, cpu_crf[6]);
4189 tcg_gen_shli_i32(t0, t0, 4);
4190 tcg_gen_or_i32(t0, t0, cpu_crf[7]);
4191 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0);
4192 tcg_temp_free_i32(t0);
d9bce9d9 4193 }
79aceca5
FB
4194}
4195
4196/* mfmsr */
99e300ef 4197static void gen_mfmsr(DisasContext *ctx)
79aceca5 4198{
9a64fbe4 4199#if defined(CONFIG_USER_ONLY)
e06fcd75 4200 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9a64fbe4 4201#else
76db3ba4 4202 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4203 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9fddaa0c 4204 return;
9a64fbe4 4205 }
6527f6ea 4206 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_msr);
9a64fbe4 4207#endif
79aceca5
FB
4208}
4209
7b13448f 4210static void spr_noaccess(void *opaque, int gprn, int sprn)
3fc6c082 4211{
7b13448f 4212#if 0
3fc6c082
FB
4213 sprn = ((sprn >> 5) & 0x1F) | ((sprn & 0x1F) << 5);
4214 printf("ERROR: try to access SPR %d !\n", sprn);
7b13448f 4215#endif
3fc6c082
FB
4216}
4217#define SPR_NOACCESS (&spr_noaccess)
3fc6c082 4218
79aceca5 4219/* mfspr */
636aa200 4220static inline void gen_op_mfspr(DisasContext *ctx)
79aceca5 4221{
45d827d2 4222 void (*read_cb)(void *opaque, int gprn, int sprn);
79aceca5
FB
4223 uint32_t sprn = SPR(ctx->opcode);
4224
3fc6c082 4225#if !defined(CONFIG_USER_ONLY)
76db3ba4 4226 if (ctx->mem_idx == 2)
be147d08 4227 read_cb = ctx->spr_cb[sprn].hea_read;
76db3ba4 4228 else if (ctx->mem_idx)
3fc6c082
FB
4229 read_cb = ctx->spr_cb[sprn].oea_read;
4230 else
9a64fbe4 4231#endif
3fc6c082 4232 read_cb = ctx->spr_cb[sprn].uea_read;
76a66253
JM
4233 if (likely(read_cb != NULL)) {
4234 if (likely(read_cb != SPR_NOACCESS)) {
45d827d2 4235 (*read_cb)(ctx, rD(ctx->opcode), sprn);
3fc6c082
FB
4236 } else {
4237 /* Privilege exception */
9fceefa7
JM
4238 /* This is a hack to avoid warnings when running Linux:
4239 * this OS breaks the PowerPC virtualisation model,
4240 * allowing userland application to read the PVR
4241 */
4242 if (sprn != SPR_PVR) {
c05541ee
AB
4243 qemu_log("Trying to read privileged spr %d (0x%03x) at "
4244 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4245 printf("Trying to read privileged spr %d (0x%03x) at "
4246 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
f24e5695 4247 }
e06fcd75 4248 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
79aceca5 4249 }
3fc6c082
FB
4250 } else {
4251 /* Not defined */
c05541ee
AB
4252 qemu_log("Trying to read invalid spr %d (0x%03x) at "
4253 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4254 printf("Trying to read invalid spr %d (0x%03x) at "
4255 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
e06fcd75 4256 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_SPR);
79aceca5 4257 }
79aceca5
FB
4258}
4259
99e300ef 4260static void gen_mfspr(DisasContext *ctx)
79aceca5 4261{
3fc6c082 4262 gen_op_mfspr(ctx);
76a66253 4263}
3fc6c082
FB
4264
4265/* mftb */
99e300ef 4266static void gen_mftb(DisasContext *ctx)
3fc6c082
FB
4267{
4268 gen_op_mfspr(ctx);
79aceca5
FB
4269}
4270
0cfe11ea 4271/* mtcrf mtocrf*/
99e300ef 4272static void gen_mtcrf(DisasContext *ctx)
79aceca5 4273{
76a66253 4274 uint32_t crm, crn;
3b46e624 4275
76a66253 4276 crm = CRM(ctx->opcode);
8dd640e4 4277 if (likely((ctx->opcode & 0x00100000))) {
4278 if (crm && ((crm & (crm - 1)) == 0)) {
4279 TCGv_i32 temp = tcg_temp_new_i32();
0cfe11ea 4280 crn = ctz32 (crm);
8dd640e4 4281 tcg_gen_trunc_tl_i32(temp, cpu_gpr[rS(ctx->opcode)]);
0cfe11ea
AJ
4282 tcg_gen_shri_i32(temp, temp, crn * 4);
4283 tcg_gen_andi_i32(cpu_crf[7 - crn], temp, 0xf);
8dd640e4 4284 tcg_temp_free_i32(temp);
4285 }
76a66253 4286 } else {
651721b2
AJ
4287 TCGv_i32 temp = tcg_temp_new_i32();
4288 tcg_gen_trunc_tl_i32(temp, cpu_gpr[rS(ctx->opcode)]);
4289 for (crn = 0 ; crn < 8 ; crn++) {
4290 if (crm & (1 << crn)) {
4291 tcg_gen_shri_i32(cpu_crf[7 - crn], temp, crn * 4);
4292 tcg_gen_andi_i32(cpu_crf[7 - crn], cpu_crf[7 - crn], 0xf);
4293 }
4294 }
a7812ae4 4295 tcg_temp_free_i32(temp);
76a66253 4296 }
79aceca5
FB
4297}
4298
4299/* mtmsr */
426613db 4300#if defined(TARGET_PPC64)
99e300ef 4301static void gen_mtmsrd(DisasContext *ctx)
426613db
JM
4302{
4303#if defined(CONFIG_USER_ONLY)
e06fcd75 4304 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
426613db 4305#else
76db3ba4 4306 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4307 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
426613db
JM
4308 return;
4309 }
be147d08
JM
4310 if (ctx->opcode & 0x00010000) {
4311 /* Special form that does not need any synchronisation */
6527f6ea
AJ
4312 TCGv t0 = tcg_temp_new();
4313 tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1 << MSR_RI) | (1 << MSR_EE));
4314 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~((1 << MSR_RI) | (1 << MSR_EE)));
4315 tcg_gen_or_tl(cpu_msr, cpu_msr, t0);
4316 tcg_temp_free(t0);
be147d08 4317 } else {
056b05f8
JM
4318 /* XXX: we need to update nip before the store
4319 * if we enter power saving mode, we will exit the loop
4320 * directly from ppc_store_msr
4321 */
be147d08 4322 gen_update_nip(ctx, ctx->nip);
e5f17ac6 4323 gen_helper_store_msr(cpu_env, cpu_gpr[rS(ctx->opcode)]);
be147d08
JM
4324 /* Must stop the translation as machine state (may have) changed */
4325 /* Note that mtmsr is not always defined as context-synchronizing */
e06fcd75 4326 gen_stop_exception(ctx);
be147d08 4327 }
426613db
JM
4328#endif
4329}
4330#endif
4331
99e300ef 4332static void gen_mtmsr(DisasContext *ctx)
79aceca5 4333{
9a64fbe4 4334#if defined(CONFIG_USER_ONLY)
e06fcd75 4335 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9a64fbe4 4336#else
76db3ba4 4337 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4338 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9fddaa0c 4339 return;
9a64fbe4 4340 }
be147d08
JM
4341 if (ctx->opcode & 0x00010000) {
4342 /* Special form that does not need any synchronisation */
6527f6ea
AJ
4343 TCGv t0 = tcg_temp_new();
4344 tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1 << MSR_RI) | (1 << MSR_EE));
4345 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~((1 << MSR_RI) | (1 << MSR_EE)));
4346 tcg_gen_or_tl(cpu_msr, cpu_msr, t0);
4347 tcg_temp_free(t0);
be147d08 4348 } else {
8018dc63
AG
4349 TCGv msr = tcg_temp_new();
4350
056b05f8
JM
4351 /* XXX: we need to update nip before the store
4352 * if we enter power saving mode, we will exit the loop
4353 * directly from ppc_store_msr
4354 */
be147d08 4355 gen_update_nip(ctx, ctx->nip);
d9bce9d9 4356#if defined(TARGET_PPC64)
8018dc63
AG
4357 tcg_gen_deposit_tl(msr, cpu_msr, cpu_gpr[rS(ctx->opcode)], 0, 32);
4358#else
4359 tcg_gen_mov_tl(msr, cpu_gpr[rS(ctx->opcode)]);
d9bce9d9 4360#endif
e5f17ac6 4361 gen_helper_store_msr(cpu_env, msr);
be147d08 4362 /* Must stop the translation as machine state (may have) changed */
6527f6ea 4363 /* Note that mtmsr is not always defined as context-synchronizing */
e06fcd75 4364 gen_stop_exception(ctx);
be147d08 4365 }
9a64fbe4 4366#endif
79aceca5
FB
4367}
4368
4369/* mtspr */
99e300ef 4370static void gen_mtspr(DisasContext *ctx)
79aceca5 4371{
45d827d2 4372 void (*write_cb)(void *opaque, int sprn, int gprn);
79aceca5
FB
4373 uint32_t sprn = SPR(ctx->opcode);
4374
3fc6c082 4375#if !defined(CONFIG_USER_ONLY)
76db3ba4 4376 if (ctx->mem_idx == 2)
be147d08 4377 write_cb = ctx->spr_cb[sprn].hea_write;
76db3ba4 4378 else if (ctx->mem_idx)
3fc6c082
FB
4379 write_cb = ctx->spr_cb[sprn].oea_write;
4380 else
9a64fbe4 4381#endif
3fc6c082 4382 write_cb = ctx->spr_cb[sprn].uea_write;
76a66253
JM
4383 if (likely(write_cb != NULL)) {
4384 if (likely(write_cb != SPR_NOACCESS)) {
45d827d2 4385 (*write_cb)(ctx, sprn, rS(ctx->opcode));
3fc6c082
FB
4386 } else {
4387 /* Privilege exception */
c05541ee
AB
4388 qemu_log("Trying to write privileged spr %d (0x%03x) at "
4389 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4390 printf("Trying to write privileged spr %d (0x%03x) at "
4391 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
e06fcd75 4392 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
76a66253 4393 }
3fc6c082
FB
4394 } else {
4395 /* Not defined */
c05541ee
AB
4396 qemu_log("Trying to write invalid spr %d (0x%03x) at "
4397 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4398 printf("Trying to write invalid spr %d (0x%03x) at "
4399 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
e06fcd75 4400 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_SPR);
79aceca5 4401 }
79aceca5
FB
4402}
4403
4404/*** Cache management ***/
99e300ef 4405
54623277 4406/* dcbf */
99e300ef 4407static void gen_dcbf(DisasContext *ctx)
79aceca5 4408{
dac454af 4409 /* XXX: specification says this is treated as a load by the MMU */
76db3ba4
AJ
4410 TCGv t0;
4411 gen_set_access_type(ctx, ACCESS_CACHE);
4412 t0 = tcg_temp_new();
4413 gen_addr_reg_index(ctx, t0);
4414 gen_qemu_ld8u(ctx, t0, t0);
fea0c503 4415 tcg_temp_free(t0);
79aceca5
FB
4416}
4417
4418/* dcbi (Supervisor only) */
99e300ef 4419static void gen_dcbi(DisasContext *ctx)
79aceca5 4420{
a541f297 4421#if defined(CONFIG_USER_ONLY)
e06fcd75 4422 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a541f297 4423#else
b61f2753 4424 TCGv EA, val;
76db3ba4 4425 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4426 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9fddaa0c 4427 return;
9a64fbe4 4428 }
a7812ae4 4429 EA = tcg_temp_new();
76db3ba4
AJ
4430 gen_set_access_type(ctx, ACCESS_CACHE);
4431 gen_addr_reg_index(ctx, EA);
a7812ae4 4432 val = tcg_temp_new();
76a66253 4433 /* XXX: specification says this should be treated as a store by the MMU */
76db3ba4
AJ
4434 gen_qemu_ld8u(ctx, val, EA);
4435 gen_qemu_st8(ctx, val, EA);
b61f2753
AJ
4436 tcg_temp_free(val);
4437 tcg_temp_free(EA);
a541f297 4438#endif
79aceca5
FB
4439}
4440
4441/* dcdst */
99e300ef 4442static void gen_dcbst(DisasContext *ctx)
79aceca5 4443{
76a66253 4444 /* XXX: specification say this is treated as a load by the MMU */
76db3ba4
AJ
4445 TCGv t0;
4446 gen_set_access_type(ctx, ACCESS_CACHE);
4447 t0 = tcg_temp_new();
4448 gen_addr_reg_index(ctx, t0);
4449 gen_qemu_ld8u(ctx, t0, t0);
fea0c503 4450 tcg_temp_free(t0);
79aceca5
FB
4451}
4452
4453/* dcbt */
99e300ef 4454static void gen_dcbt(DisasContext *ctx)
79aceca5 4455{
0db1b20e 4456 /* interpreted as no-op */
76a66253
JM
4457 /* XXX: specification say this is treated as a load by the MMU
4458 * but does not generate any exception
4459 */
79aceca5
FB
4460}
4461
4462/* dcbtst */
99e300ef 4463static void gen_dcbtst(DisasContext *ctx)
79aceca5 4464{
0db1b20e 4465 /* interpreted as no-op */
76a66253
JM
4466 /* XXX: specification say this is treated as a load by the MMU
4467 * but does not generate any exception
4468 */
79aceca5
FB
4469}
4470
4471/* dcbz */
99e300ef 4472static void gen_dcbz(DisasContext *ctx)
79aceca5 4473{
8e33944f
AG
4474 TCGv tcgv_addr;
4475 TCGv_i32 tcgv_is_dcbzl;
4476 int is_dcbzl = ctx->opcode & 0x00200000 ? 1 : 0;
d63001d1 4477
76db3ba4 4478 gen_set_access_type(ctx, ACCESS_CACHE);
799a8c8d
AJ
4479 /* NIP cannot be restored if the memory exception comes from an helper */
4480 gen_update_nip(ctx, ctx->nip - 4);
8e33944f
AG
4481 tcgv_addr = tcg_temp_new();
4482 tcgv_is_dcbzl = tcg_const_i32(is_dcbzl);
4483
4484 gen_addr_reg_index(ctx, tcgv_addr);
4485 gen_helper_dcbz(cpu_env, tcgv_addr, tcgv_is_dcbzl);
4486
4487 tcg_temp_free(tcgv_addr);
4488 tcg_temp_free_i32(tcgv_is_dcbzl);
79aceca5
FB
4489}
4490
ae1c1a3d 4491/* dst / dstt */
99e300ef 4492static void gen_dst(DisasContext *ctx)
ae1c1a3d
AJ
4493{
4494 if (rA(ctx->opcode) == 0) {
4495 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX);
4496 } else {
4497 /* interpreted as no-op */
4498 }
4499}
4500
4501/* dstst /dststt */
99e300ef 4502static void gen_dstst(DisasContext *ctx)
ae1c1a3d
AJ
4503{
4504 if (rA(ctx->opcode) == 0) {
4505 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX);
4506 } else {
4507 /* interpreted as no-op */
4508 }
4509
4510}
4511
4512/* dss / dssall */
99e300ef 4513static void gen_dss(DisasContext *ctx)
ae1c1a3d
AJ
4514{
4515 /* interpreted as no-op */
4516}
4517
79aceca5 4518/* icbi */
99e300ef 4519static void gen_icbi(DisasContext *ctx)
79aceca5 4520{
76db3ba4
AJ
4521 TCGv t0;
4522 gen_set_access_type(ctx, ACCESS_CACHE);
30032c94
JM
4523 /* NIP cannot be restored if the memory exception comes from an helper */
4524 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
4525 t0 = tcg_temp_new();
4526 gen_addr_reg_index(ctx, t0);
2f5a189c 4527 gen_helper_icbi(cpu_env, t0);
37d269df 4528 tcg_temp_free(t0);
79aceca5
FB
4529}
4530
4531/* Optional: */
4532/* dcba */
99e300ef 4533static void gen_dcba(DisasContext *ctx)
79aceca5 4534{
0db1b20e
JM
4535 /* interpreted as no-op */
4536 /* XXX: specification say this is treated as a store by the MMU
4537 * but does not generate any exception
4538 */
79aceca5
FB
4539}
4540
4541/*** Segment register manipulation ***/
4542/* Supervisor only: */
99e300ef 4543
54623277 4544/* mfsr */
99e300ef 4545static void gen_mfsr(DisasContext *ctx)
79aceca5 4546{
9a64fbe4 4547#if defined(CONFIG_USER_ONLY)
e06fcd75 4548 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9a64fbe4 4549#else
74d37793 4550 TCGv t0;
76db3ba4 4551 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4552 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9fddaa0c 4553 return;
9a64fbe4 4554 }
74d37793 4555 t0 = tcg_const_tl(SR(ctx->opcode));
c6c7cf05 4556 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793 4557 tcg_temp_free(t0);
9a64fbe4 4558#endif
79aceca5
FB
4559}
4560
4561/* mfsrin */
99e300ef 4562static void gen_mfsrin(DisasContext *ctx)
79aceca5 4563{
9a64fbe4 4564#if defined(CONFIG_USER_ONLY)
e06fcd75 4565 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9a64fbe4 4566#else
74d37793 4567 TCGv t0;
76db3ba4 4568 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4569 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9fddaa0c 4570 return;
9a64fbe4 4571 }
74d37793
AJ
4572 t0 = tcg_temp_new();
4573 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4574 tcg_gen_andi_tl(t0, t0, 0xF);
c6c7cf05 4575 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793 4576 tcg_temp_free(t0);
9a64fbe4 4577#endif
79aceca5
FB
4578}
4579
4580/* mtsr */
99e300ef 4581static void gen_mtsr(DisasContext *ctx)
79aceca5 4582{
9a64fbe4 4583#if defined(CONFIG_USER_ONLY)
e06fcd75 4584 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9a64fbe4 4585#else
74d37793 4586 TCGv t0;
76db3ba4 4587 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4588 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9fddaa0c 4589 return;
9a64fbe4 4590 }
74d37793 4591 t0 = tcg_const_tl(SR(ctx->opcode));
c6c7cf05 4592 gen_helper_store_sr(cpu_env, t0, cpu_gpr[rS(ctx->opcode)]);
74d37793 4593 tcg_temp_free(t0);
9a64fbe4 4594#endif
79aceca5
FB
4595}
4596
4597/* mtsrin */
99e300ef 4598static void gen_mtsrin(DisasContext *ctx)
79aceca5 4599{
9a64fbe4 4600#if defined(CONFIG_USER_ONLY)
e06fcd75 4601 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9a64fbe4 4602#else
74d37793 4603 TCGv t0;
76db3ba4 4604 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4605 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9fddaa0c 4606 return;
9a64fbe4 4607 }
74d37793
AJ
4608 t0 = tcg_temp_new();
4609 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4610 tcg_gen_andi_tl(t0, t0, 0xF);
c6c7cf05 4611 gen_helper_store_sr(cpu_env, t0, cpu_gpr[rD(ctx->opcode)]);
74d37793 4612 tcg_temp_free(t0);
9a64fbe4 4613#endif
79aceca5
FB
4614}
4615
12de9a39
JM
4616#if defined(TARGET_PPC64)
4617/* Specific implementation for PowerPC 64 "bridge" emulation using SLB */
e8eaa2c0 4618
54623277 4619/* mfsr */
e8eaa2c0 4620static void gen_mfsr_64b(DisasContext *ctx)
12de9a39
JM
4621{
4622#if defined(CONFIG_USER_ONLY)
e06fcd75 4623 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39 4624#else
74d37793 4625 TCGv t0;
76db3ba4 4626 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4627 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39
JM
4628 return;
4629 }
74d37793 4630 t0 = tcg_const_tl(SR(ctx->opcode));
c6c7cf05 4631 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793 4632 tcg_temp_free(t0);
12de9a39
JM
4633#endif
4634}
4635
4636/* mfsrin */
e8eaa2c0 4637static void gen_mfsrin_64b(DisasContext *ctx)
12de9a39
JM
4638{
4639#if defined(CONFIG_USER_ONLY)
e06fcd75 4640 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39 4641#else
74d37793 4642 TCGv t0;
76db3ba4 4643 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4644 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39
JM
4645 return;
4646 }
74d37793
AJ
4647 t0 = tcg_temp_new();
4648 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4649 tcg_gen_andi_tl(t0, t0, 0xF);
c6c7cf05 4650 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793 4651 tcg_temp_free(t0);
12de9a39
JM
4652#endif
4653}
4654
4655/* mtsr */
e8eaa2c0 4656static void gen_mtsr_64b(DisasContext *ctx)
12de9a39
JM
4657{
4658#if defined(CONFIG_USER_ONLY)
e06fcd75 4659 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39 4660#else
74d37793 4661 TCGv t0;
76db3ba4 4662 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4663 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39
JM
4664 return;
4665 }
74d37793 4666 t0 = tcg_const_tl(SR(ctx->opcode));
c6c7cf05 4667 gen_helper_store_sr(cpu_env, t0, cpu_gpr[rS(ctx->opcode)]);
74d37793 4668 tcg_temp_free(t0);
12de9a39
JM
4669#endif
4670}
4671
4672/* mtsrin */
e8eaa2c0 4673static void gen_mtsrin_64b(DisasContext *ctx)
12de9a39
JM
4674{
4675#if defined(CONFIG_USER_ONLY)
e06fcd75 4676 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39 4677#else
74d37793 4678 TCGv t0;
76db3ba4 4679 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4680 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39
JM
4681 return;
4682 }
74d37793
AJ
4683 t0 = tcg_temp_new();
4684 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4685 tcg_gen_andi_tl(t0, t0, 0xF);
c6c7cf05 4686 gen_helper_store_sr(cpu_env, t0, cpu_gpr[rS(ctx->opcode)]);
74d37793 4687 tcg_temp_free(t0);
12de9a39
JM
4688#endif
4689}
f6b868fc
BS
4690
4691/* slbmte */
e8eaa2c0 4692static void gen_slbmte(DisasContext *ctx)
f6b868fc
BS
4693{
4694#if defined(CONFIG_USER_ONLY)
4695 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4696#else
4697 if (unlikely(!ctx->mem_idx)) {
4698 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4699 return;
4700 }
c6c7cf05
BS
4701 gen_helper_store_slb(cpu_env, cpu_gpr[rB(ctx->opcode)],
4702 cpu_gpr[rS(ctx->opcode)]);
f6b868fc
BS
4703#endif
4704}
4705
efdef95f
DG
4706static void gen_slbmfee(DisasContext *ctx)
4707{
4708#if defined(CONFIG_USER_ONLY)
4709 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4710#else
4711 if (unlikely(!ctx->mem_idx)) {
4712 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4713 return;
4714 }
c6c7cf05 4715 gen_helper_load_slb_esid(cpu_gpr[rS(ctx->opcode)], cpu_env,
efdef95f
DG
4716 cpu_gpr[rB(ctx->opcode)]);
4717#endif
4718}
4719
4720static void gen_slbmfev(DisasContext *ctx)
4721{
4722#if defined(CONFIG_USER_ONLY)
4723 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4724#else
4725 if (unlikely(!ctx->mem_idx)) {
4726 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4727 return;
4728 }
c6c7cf05 4729 gen_helper_load_slb_vsid(cpu_gpr[rS(ctx->opcode)], cpu_env,
efdef95f
DG
4730 cpu_gpr[rB(ctx->opcode)]);
4731#endif
4732}
12de9a39
JM
4733#endif /* defined(TARGET_PPC64) */
4734
79aceca5 4735/*** Lookaside buffer management ***/
76db3ba4 4736/* Optional & mem_idx only: */
99e300ef 4737
54623277 4738/* tlbia */
99e300ef 4739static void gen_tlbia(DisasContext *ctx)
79aceca5 4740{
9a64fbe4 4741#if defined(CONFIG_USER_ONLY)
e06fcd75 4742 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9a64fbe4 4743#else
76db3ba4 4744 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4745 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9fddaa0c 4746 return;
9a64fbe4 4747 }
c6c7cf05 4748 gen_helper_tlbia(cpu_env);
9a64fbe4 4749#endif
79aceca5
FB
4750}
4751
bf14b1ce 4752/* tlbiel */
99e300ef 4753static void gen_tlbiel(DisasContext *ctx)
bf14b1ce
BS
4754{
4755#if defined(CONFIG_USER_ONLY)
4756 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4757#else
4758 if (unlikely(!ctx->mem_idx)) {
4759 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4760 return;
4761 }
c6c7cf05 4762 gen_helper_tlbie(cpu_env, cpu_gpr[rB(ctx->opcode)]);
bf14b1ce
BS
4763#endif
4764}
4765
79aceca5 4766/* tlbie */
99e300ef 4767static void gen_tlbie(DisasContext *ctx)
79aceca5 4768{
9a64fbe4 4769#if defined(CONFIG_USER_ONLY)
e06fcd75 4770 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9a64fbe4 4771#else
76db3ba4 4772 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4773 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9fddaa0c 4774 return;
9a64fbe4 4775 }
9ca3f7f3 4776 if (NARROW_MODE(ctx)) {
74d37793
AJ
4777 TCGv t0 = tcg_temp_new();
4778 tcg_gen_ext32u_tl(t0, cpu_gpr[rB(ctx->opcode)]);
c6c7cf05 4779 gen_helper_tlbie(cpu_env, t0);
74d37793 4780 tcg_temp_free(t0);
9ca3f7f3 4781 } else {
c6c7cf05 4782 gen_helper_tlbie(cpu_env, cpu_gpr[rB(ctx->opcode)]);
9ca3f7f3 4783 }
9a64fbe4 4784#endif
79aceca5
FB
4785}
4786
4787/* tlbsync */
99e300ef 4788static void gen_tlbsync(DisasContext *ctx)
79aceca5 4789{
9a64fbe4 4790#if defined(CONFIG_USER_ONLY)
e06fcd75 4791 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9a64fbe4 4792#else
76db3ba4 4793 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4794 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9fddaa0c 4795 return;
9a64fbe4
FB
4796 }
4797 /* This has no effect: it should ensure that all previous
4798 * tlbie have completed
4799 */
e06fcd75 4800 gen_stop_exception(ctx);
9a64fbe4 4801#endif
79aceca5
FB
4802}
4803
426613db
JM
4804#if defined(TARGET_PPC64)
4805/* slbia */
99e300ef 4806static void gen_slbia(DisasContext *ctx)
426613db
JM
4807{
4808#if defined(CONFIG_USER_ONLY)
e06fcd75 4809 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db 4810#else
76db3ba4 4811 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4812 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db
JM
4813 return;
4814 }
c6c7cf05 4815 gen_helper_slbia(cpu_env);
426613db
JM
4816#endif
4817}
4818
4819/* slbie */
99e300ef 4820static void gen_slbie(DisasContext *ctx)
426613db
JM
4821{
4822#if defined(CONFIG_USER_ONLY)
e06fcd75 4823 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db 4824#else
76db3ba4 4825 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4826 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db
JM
4827 return;
4828 }
c6c7cf05 4829 gen_helper_slbie(cpu_env, cpu_gpr[rB(ctx->opcode)]);
426613db
JM
4830#endif
4831}
4832#endif
4833
79aceca5
FB
4834/*** External control ***/
4835/* Optional: */
99e300ef 4836
54623277 4837/* eciwx */
99e300ef 4838static void gen_eciwx(DisasContext *ctx)
79aceca5 4839{
76db3ba4 4840 TCGv t0;
fa407c03 4841 /* Should check EAR[E] ! */
76db3ba4
AJ
4842 gen_set_access_type(ctx, ACCESS_EXT);
4843 t0 = tcg_temp_new();
4844 gen_addr_reg_index(ctx, t0);
fa407c03 4845 gen_check_align(ctx, t0, 0x03);
76db3ba4 4846 gen_qemu_ld32u(ctx, cpu_gpr[rD(ctx->opcode)], t0);
fa407c03 4847 tcg_temp_free(t0);
76a66253
JM
4848}
4849
4850/* ecowx */
99e300ef 4851static void gen_ecowx(DisasContext *ctx)
76a66253 4852{
76db3ba4 4853 TCGv t0;
fa407c03 4854 /* Should check EAR[E] ! */
76db3ba4
AJ
4855 gen_set_access_type(ctx, ACCESS_EXT);
4856 t0 = tcg_temp_new();
4857 gen_addr_reg_index(ctx, t0);
fa407c03 4858 gen_check_align(ctx, t0, 0x03);
76db3ba4 4859 gen_qemu_st32(ctx, cpu_gpr[rD(ctx->opcode)], t0);
fa407c03 4860 tcg_temp_free(t0);
76a66253
JM
4861}
4862
4863/* PowerPC 601 specific instructions */
99e300ef 4864
54623277 4865/* abs - abs. */
99e300ef 4866static void gen_abs(DisasContext *ctx)
76a66253 4867{
22e0e173
AJ
4868 int l1 = gen_new_label();
4869 int l2 = gen_new_label();
4870 tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rA(ctx->opcode)], 0, l1);
4871 tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4872 tcg_gen_br(l2);
4873 gen_set_label(l1);
4874 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4875 gen_set_label(l2);
76a66253 4876 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4877 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4878}
4879
4880/* abso - abso. */
99e300ef 4881static void gen_abso(DisasContext *ctx)
76a66253 4882{
22e0e173
AJ
4883 int l1 = gen_new_label();
4884 int l2 = gen_new_label();
4885 int l3 = gen_new_label();
4886 /* Start with XER OV disabled, the most likely case */
da91a00f 4887 tcg_gen_movi_tl(cpu_ov, 0);
22e0e173
AJ
4888 tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rA(ctx->opcode)], 0, l2);
4889 tcg_gen_brcondi_tl(TCG_COND_NE, cpu_gpr[rA(ctx->opcode)], 0x80000000, l1);
da91a00f
RH
4890 tcg_gen_movi_tl(cpu_ov, 1);
4891 tcg_gen_movi_tl(cpu_so, 1);
22e0e173
AJ
4892 tcg_gen_br(l2);
4893 gen_set_label(l1);
4894 tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4895 tcg_gen_br(l3);
4896 gen_set_label(l2);
4897 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4898 gen_set_label(l3);
76a66253 4899 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4900 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4901}
4902
4903/* clcs */
99e300ef 4904static void gen_clcs(DisasContext *ctx)
76a66253 4905{
22e0e173 4906 TCGv_i32 t0 = tcg_const_i32(rA(ctx->opcode));
d523dd00 4907 gen_helper_clcs(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
22e0e173 4908 tcg_temp_free_i32(t0);
c7697e1f 4909 /* Rc=1 sets CR0 to an undefined state */
76a66253
JM
4910}
4911
4912/* div - div. */
99e300ef 4913static void gen_div(DisasContext *ctx)
76a66253 4914{
d15f74fb
BS
4915 gen_helper_div(cpu_gpr[rD(ctx->opcode)], cpu_env, cpu_gpr[rA(ctx->opcode)],
4916 cpu_gpr[rB(ctx->opcode)]);
76a66253 4917 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4918 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4919}
4920
4921/* divo - divo. */
99e300ef 4922static void gen_divo(DisasContext *ctx)
76a66253 4923{
d15f74fb
BS
4924 gen_helper_divo(cpu_gpr[rD(ctx->opcode)], cpu_env, cpu_gpr[rA(ctx->opcode)],
4925 cpu_gpr[rB(ctx->opcode)]);
76a66253 4926 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4927 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4928}
4929
4930/* divs - divs. */
99e300ef 4931static void gen_divs(DisasContext *ctx)
76a66253 4932{
d15f74fb
BS
4933 gen_helper_divs(cpu_gpr[rD(ctx->opcode)], cpu_env, cpu_gpr[rA(ctx->opcode)],
4934 cpu_gpr[rB(ctx->opcode)]);
76a66253 4935 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4936 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4937}
4938
4939/* divso - divso. */
99e300ef 4940static void gen_divso(DisasContext *ctx)
76a66253 4941{
d15f74fb
BS
4942 gen_helper_divso(cpu_gpr[rD(ctx->opcode)], cpu_env,
4943 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
76a66253 4944 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4945 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4946}
4947
4948/* doz - doz. */
99e300ef 4949static void gen_doz(DisasContext *ctx)
76a66253 4950{
22e0e173
AJ
4951 int l1 = gen_new_label();
4952 int l2 = gen_new_label();
4953 tcg_gen_brcond_tl(TCG_COND_GE, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], l1);
4954 tcg_gen_sub_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4955 tcg_gen_br(l2);
4956 gen_set_label(l1);
4957 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
4958 gen_set_label(l2);
76a66253 4959 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4960 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4961}
4962
4963/* dozo - dozo. */
99e300ef 4964static void gen_dozo(DisasContext *ctx)
76a66253 4965{
22e0e173
AJ
4966 int l1 = gen_new_label();
4967 int l2 = gen_new_label();
4968 TCGv t0 = tcg_temp_new();
4969 TCGv t1 = tcg_temp_new();
4970 TCGv t2 = tcg_temp_new();
4971 /* Start with XER OV disabled, the most likely case */
da91a00f 4972 tcg_gen_movi_tl(cpu_ov, 0);
22e0e173
AJ
4973 tcg_gen_brcond_tl(TCG_COND_GE, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], l1);
4974 tcg_gen_sub_tl(t0, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4975 tcg_gen_xor_tl(t1, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4976 tcg_gen_xor_tl(t2, cpu_gpr[rA(ctx->opcode)], t0);
4977 tcg_gen_andc_tl(t1, t1, t2);
4978 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
4979 tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l2);
da91a00f
RH
4980 tcg_gen_movi_tl(cpu_ov, 1);
4981 tcg_gen_movi_tl(cpu_so, 1);
22e0e173
AJ
4982 tcg_gen_br(l2);
4983 gen_set_label(l1);
4984 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
4985 gen_set_label(l2);
4986 tcg_temp_free(t0);
4987 tcg_temp_free(t1);
4988 tcg_temp_free(t2);
76a66253 4989 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4990 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4991}
4992
4993/* dozi */
99e300ef 4994static void gen_dozi(DisasContext *ctx)
76a66253 4995{
22e0e173
AJ
4996 target_long simm = SIMM(ctx->opcode);
4997 int l1 = gen_new_label();
4998 int l2 = gen_new_label();
4999 tcg_gen_brcondi_tl(TCG_COND_LT, cpu_gpr[rA(ctx->opcode)], simm, l1);
5000 tcg_gen_subfi_tl(cpu_gpr[rD(ctx->opcode)], simm, cpu_gpr[rA(ctx->opcode)]);
5001 tcg_gen_br(l2);
5002 gen_set_label(l1);
5003 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
5004 gen_set_label(l2);
5005 if (unlikely(Rc(ctx->opcode) != 0))
5006 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
5007}
5008
76a66253 5009/* lscbx - lscbx. */
99e300ef 5010static void gen_lscbx(DisasContext *ctx)
76a66253 5011{
bdb4b689
AJ
5012 TCGv t0 = tcg_temp_new();
5013 TCGv_i32 t1 = tcg_const_i32(rD(ctx->opcode));
5014 TCGv_i32 t2 = tcg_const_i32(rA(ctx->opcode));
5015 TCGv_i32 t3 = tcg_const_i32(rB(ctx->opcode));
76a66253 5016
76db3ba4 5017 gen_addr_reg_index(ctx, t0);
76a66253 5018 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 5019 gen_update_nip(ctx, ctx->nip - 4);
2f5a189c 5020 gen_helper_lscbx(t0, cpu_env, t0, t1, t2, t3);
bdb4b689
AJ
5021 tcg_temp_free_i32(t1);
5022 tcg_temp_free_i32(t2);
5023 tcg_temp_free_i32(t3);
3d7b417e 5024 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~0x7F);
bdb4b689 5025 tcg_gen_or_tl(cpu_xer, cpu_xer, t0);
76a66253 5026 if (unlikely(Rc(ctx->opcode) != 0))
bdb4b689
AJ
5027 gen_set_Rc0(ctx, t0);
5028 tcg_temp_free(t0);
76a66253
JM
5029}
5030
5031/* maskg - maskg. */
99e300ef 5032static void gen_maskg(DisasContext *ctx)
76a66253 5033{
22e0e173
AJ
5034 int l1 = gen_new_label();
5035 TCGv t0 = tcg_temp_new();
5036 TCGv t1 = tcg_temp_new();
5037 TCGv t2 = tcg_temp_new();
5038 TCGv t3 = tcg_temp_new();
5039 tcg_gen_movi_tl(t3, 0xFFFFFFFF);
5040 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
5041 tcg_gen_andi_tl(t1, cpu_gpr[rS(ctx->opcode)], 0x1F);
5042 tcg_gen_addi_tl(t2, t0, 1);
5043 tcg_gen_shr_tl(t2, t3, t2);
5044 tcg_gen_shr_tl(t3, t3, t1);
5045 tcg_gen_xor_tl(cpu_gpr[rA(ctx->opcode)], t2, t3);
5046 tcg_gen_brcond_tl(TCG_COND_GE, t0, t1, l1);
5047 tcg_gen_neg_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5048 gen_set_label(l1);
5049 tcg_temp_free(t0);
5050 tcg_temp_free(t1);
5051 tcg_temp_free(t2);
5052 tcg_temp_free(t3);
76a66253 5053 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 5054 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5055}
5056
5057/* maskir - maskir. */
99e300ef 5058static void gen_maskir(DisasContext *ctx)
76a66253 5059{
22e0e173
AJ
5060 TCGv t0 = tcg_temp_new();
5061 TCGv t1 = tcg_temp_new();
5062 tcg_gen_and_tl(t0, cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
5063 tcg_gen_andc_tl(t1, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
5064 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5065 tcg_temp_free(t0);
5066 tcg_temp_free(t1);
76a66253 5067 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 5068 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5069}
5070
5071/* mul - mul. */
99e300ef 5072static void gen_mul(DisasContext *ctx)
76a66253 5073{
22e0e173
AJ
5074 TCGv_i64 t0 = tcg_temp_new_i64();
5075 TCGv_i64 t1 = tcg_temp_new_i64();
5076 TCGv t2 = tcg_temp_new();
5077 tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
5078 tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
5079 tcg_gen_mul_i64(t0, t0, t1);
5080 tcg_gen_trunc_i64_tl(t2, t0);
5081 gen_store_spr(SPR_MQ, t2);
5082 tcg_gen_shri_i64(t1, t0, 32);
5083 tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t1);
5084 tcg_temp_free_i64(t0);
5085 tcg_temp_free_i64(t1);
5086 tcg_temp_free(t2);
76a66253 5087 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 5088 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
5089}
5090
5091/* mulo - mulo. */
99e300ef 5092static void gen_mulo(DisasContext *ctx)
76a66253 5093{
22e0e173
AJ
5094 int l1 = gen_new_label();
5095 TCGv_i64 t0 = tcg_temp_new_i64();
5096 TCGv_i64 t1 = tcg_temp_new_i64();
5097 TCGv t2 = tcg_temp_new();
5098 /* Start with XER OV disabled, the most likely case */
da91a00f 5099 tcg_gen_movi_tl(cpu_ov, 0);
22e0e173
AJ
5100 tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
5101 tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
5102 tcg_gen_mul_i64(t0, t0, t1);
5103 tcg_gen_trunc_i64_tl(t2, t0);
5104 gen_store_spr(SPR_MQ, t2);
5105 tcg_gen_shri_i64(t1, t0, 32);
5106 tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t1);
5107 tcg_gen_ext32s_i64(t1, t0);
5108 tcg_gen_brcond_i64(TCG_COND_EQ, t0, t1, l1);
da91a00f
RH
5109 tcg_gen_movi_tl(cpu_ov, 1);
5110 tcg_gen_movi_tl(cpu_so, 1);
22e0e173
AJ
5111 gen_set_label(l1);
5112 tcg_temp_free_i64(t0);
5113 tcg_temp_free_i64(t1);
5114 tcg_temp_free(t2);
76a66253 5115 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 5116 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
5117}
5118
5119/* nabs - nabs. */
99e300ef 5120static void gen_nabs(DisasContext *ctx)
76a66253 5121{
22e0e173
AJ
5122 int l1 = gen_new_label();
5123 int l2 = gen_new_label();
5124 tcg_gen_brcondi_tl(TCG_COND_GT, cpu_gpr[rA(ctx->opcode)], 0, l1);
5125 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5126 tcg_gen_br(l2);
5127 gen_set_label(l1);
5128 tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5129 gen_set_label(l2);
76a66253 5130 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 5131 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
5132}
5133
5134/* nabso - nabso. */
99e300ef 5135static void gen_nabso(DisasContext *ctx)
76a66253 5136{
22e0e173
AJ
5137 int l1 = gen_new_label();
5138 int l2 = gen_new_label();
5139 tcg_gen_brcondi_tl(TCG_COND_GT, cpu_gpr[rA(ctx->opcode)], 0, l1);
5140 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5141 tcg_gen_br(l2);
5142 gen_set_label(l1);
5143 tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5144 gen_set_label(l2);
5145 /* nabs never overflows */
da91a00f 5146 tcg_gen_movi_tl(cpu_ov, 0);
76a66253 5147 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 5148 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
5149}
5150
5151/* rlmi - rlmi. */
99e300ef 5152static void gen_rlmi(DisasContext *ctx)
76a66253 5153{
7487953d
AJ
5154 uint32_t mb = MB(ctx->opcode);
5155 uint32_t me = ME(ctx->opcode);
5156 TCGv t0 = tcg_temp_new();
5157 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
5158 tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
5159 tcg_gen_andi_tl(t0, t0, MASK(mb, me));
5160 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~MASK(mb, me));
5161 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], t0);
5162 tcg_temp_free(t0);
76a66253 5163 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5164 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5165}
5166
5167/* rrib - rrib. */
99e300ef 5168static void gen_rrib(DisasContext *ctx)
76a66253 5169{
7487953d
AJ
5170 TCGv t0 = tcg_temp_new();
5171 TCGv t1 = tcg_temp_new();
5172 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
5173 tcg_gen_movi_tl(t1, 0x80000000);
5174 tcg_gen_shr_tl(t1, t1, t0);
5175 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
5176 tcg_gen_and_tl(t0, t0, t1);
5177 tcg_gen_andc_tl(t1, cpu_gpr[rA(ctx->opcode)], t1);
5178 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5179 tcg_temp_free(t0);
5180 tcg_temp_free(t1);
76a66253 5181 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5182 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5183}
5184
5185/* sle - sle. */
99e300ef 5186static void gen_sle(DisasContext *ctx)
76a66253 5187{
7487953d
AJ
5188 TCGv t0 = tcg_temp_new();
5189 TCGv t1 = tcg_temp_new();
5190 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5191 tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5192 tcg_gen_subfi_tl(t1, 32, t1);
5193 tcg_gen_shr_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
5194 tcg_gen_or_tl(t1, t0, t1);
5195 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5196 gen_store_spr(SPR_MQ, t1);
5197 tcg_temp_free(t0);
5198 tcg_temp_free(t1);
76a66253 5199 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5200 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5201}
5202
5203/* sleq - sleq. */
99e300ef 5204static void gen_sleq(DisasContext *ctx)
76a66253 5205{
7487953d
AJ
5206 TCGv t0 = tcg_temp_new();
5207 TCGv t1 = tcg_temp_new();
5208 TCGv t2 = tcg_temp_new();
5209 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
5210 tcg_gen_movi_tl(t2, 0xFFFFFFFF);
5211 tcg_gen_shl_tl(t2, t2, t0);
5212 tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
5213 gen_load_spr(t1, SPR_MQ);
5214 gen_store_spr(SPR_MQ, t0);
5215 tcg_gen_and_tl(t0, t0, t2);
5216 tcg_gen_andc_tl(t1, t1, t2);
5217 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5218 tcg_temp_free(t0);
5219 tcg_temp_free(t1);
5220 tcg_temp_free(t2);
76a66253 5221 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5222 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5223}
5224
5225/* sliq - sliq. */
99e300ef 5226static void gen_sliq(DisasContext *ctx)
76a66253 5227{
7487953d
AJ
5228 int sh = SH(ctx->opcode);
5229 TCGv t0 = tcg_temp_new();
5230 TCGv t1 = tcg_temp_new();
5231 tcg_gen_shli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5232 tcg_gen_shri_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh);
5233 tcg_gen_or_tl(t1, t0, t1);
5234 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5235 gen_store_spr(SPR_MQ, t1);
5236 tcg_temp_free(t0);
5237 tcg_temp_free(t1);
76a66253 5238 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5239 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5240}
5241
5242/* slliq - slliq. */
99e300ef 5243static void gen_slliq(DisasContext *ctx)
76a66253 5244{
7487953d
AJ
5245 int sh = SH(ctx->opcode);
5246 TCGv t0 = tcg_temp_new();
5247 TCGv t1 = tcg_temp_new();
5248 tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5249 gen_load_spr(t1, SPR_MQ);
5250 gen_store_spr(SPR_MQ, t0);
5251 tcg_gen_andi_tl(t0, t0, (0xFFFFFFFFU << sh));
5252 tcg_gen_andi_tl(t1, t1, ~(0xFFFFFFFFU << sh));
5253 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5254 tcg_temp_free(t0);
5255 tcg_temp_free(t1);
76a66253 5256 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5257 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5258}
5259
5260/* sllq - sllq. */
99e300ef 5261static void gen_sllq(DisasContext *ctx)
76a66253 5262{
7487953d
AJ
5263 int l1 = gen_new_label();
5264 int l2 = gen_new_label();
5265 TCGv t0 = tcg_temp_local_new();
5266 TCGv t1 = tcg_temp_local_new();
5267 TCGv t2 = tcg_temp_local_new();
5268 tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F);
5269 tcg_gen_movi_tl(t1, 0xFFFFFFFF);
5270 tcg_gen_shl_tl(t1, t1, t2);
5271 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20);
5272 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
5273 gen_load_spr(t0, SPR_MQ);
5274 tcg_gen_and_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5275 tcg_gen_br(l2);
5276 gen_set_label(l1);
5277 tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t2);
5278 gen_load_spr(t2, SPR_MQ);
5279 tcg_gen_andc_tl(t1, t2, t1);
5280 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5281 gen_set_label(l2);
5282 tcg_temp_free(t0);
5283 tcg_temp_free(t1);
5284 tcg_temp_free(t2);
76a66253 5285 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5286 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5287}
5288
5289/* slq - slq. */
99e300ef 5290static void gen_slq(DisasContext *ctx)
76a66253 5291{
7487953d
AJ
5292 int l1 = gen_new_label();
5293 TCGv t0 = tcg_temp_new();
5294 TCGv t1 = tcg_temp_new();
5295 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5296 tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5297 tcg_gen_subfi_tl(t1, 32, t1);
5298 tcg_gen_shr_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
5299 tcg_gen_or_tl(t1, t0, t1);
5300 gen_store_spr(SPR_MQ, t1);
5301 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x20);
5302 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5303 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
5304 tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
5305 gen_set_label(l1);
5306 tcg_temp_free(t0);
5307 tcg_temp_free(t1);
76a66253 5308 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5309 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5310}
5311
d9bce9d9 5312/* sraiq - sraiq. */
99e300ef 5313static void gen_sraiq(DisasContext *ctx)
76a66253 5314{
7487953d
AJ
5315 int sh = SH(ctx->opcode);
5316 int l1 = gen_new_label();
5317 TCGv t0 = tcg_temp_new();
5318 TCGv t1 = tcg_temp_new();
5319 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5320 tcg_gen_shli_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh);
5321 tcg_gen_or_tl(t0, t0, t1);
5322 gen_store_spr(SPR_MQ, t0);
da91a00f 5323 tcg_gen_movi_tl(cpu_ca, 0);
7487953d
AJ
5324 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
5325 tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rS(ctx->opcode)], 0, l1);
da91a00f 5326 tcg_gen_movi_tl(cpu_ca, 1);
7487953d
AJ
5327 gen_set_label(l1);
5328 tcg_gen_sari_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], sh);
5329 tcg_temp_free(t0);
5330 tcg_temp_free(t1);
76a66253 5331 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5332 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5333}
5334
5335/* sraq - sraq. */
99e300ef 5336static void gen_sraq(DisasContext *ctx)
76a66253 5337{
7487953d
AJ
5338 int l1 = gen_new_label();
5339 int l2 = gen_new_label();
5340 TCGv t0 = tcg_temp_new();
5341 TCGv t1 = tcg_temp_local_new();
5342 TCGv t2 = tcg_temp_local_new();
5343 tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F);
5344 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t2);
5345 tcg_gen_sar_tl(t1, cpu_gpr[rS(ctx->opcode)], t2);
5346 tcg_gen_subfi_tl(t2, 32, t2);
5347 tcg_gen_shl_tl(t2, cpu_gpr[rS(ctx->opcode)], t2);
5348 tcg_gen_or_tl(t0, t0, t2);
5349 gen_store_spr(SPR_MQ, t0);
5350 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20);
5351 tcg_gen_brcondi_tl(TCG_COND_EQ, t2, 0, l1);
5352 tcg_gen_mov_tl(t2, cpu_gpr[rS(ctx->opcode)]);
5353 tcg_gen_sari_tl(t1, cpu_gpr[rS(ctx->opcode)], 31);
5354 gen_set_label(l1);
5355 tcg_temp_free(t0);
5356 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t1);
da91a00f 5357 tcg_gen_movi_tl(cpu_ca, 0);
7487953d
AJ
5358 tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l2);
5359 tcg_gen_brcondi_tl(TCG_COND_EQ, t2, 0, l2);
da91a00f 5360 tcg_gen_movi_tl(cpu_ca, 1);
7487953d
AJ
5361 gen_set_label(l2);
5362 tcg_temp_free(t1);
5363 tcg_temp_free(t2);
76a66253 5364 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5365 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5366}
5367
5368/* sre - sre. */
99e300ef 5369static void gen_sre(DisasContext *ctx)
76a66253 5370{
7487953d
AJ
5371 TCGv t0 = tcg_temp_new();
5372 TCGv t1 = tcg_temp_new();
5373 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5374 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5375 tcg_gen_subfi_tl(t1, 32, t1);
5376 tcg_gen_shl_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
5377 tcg_gen_or_tl(t1, t0, t1);
5378 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5379 gen_store_spr(SPR_MQ, t1);
5380 tcg_temp_free(t0);
5381 tcg_temp_free(t1);
76a66253 5382 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5383 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5384}
5385
5386/* srea - srea. */
99e300ef 5387static void gen_srea(DisasContext *ctx)
76a66253 5388{
7487953d
AJ
5389 TCGv t0 = tcg_temp_new();
5390 TCGv t1 = tcg_temp_new();
5391 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5392 tcg_gen_rotr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5393 gen_store_spr(SPR_MQ, t0);
5394 tcg_gen_sar_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], t1);
5395 tcg_temp_free(t0);
5396 tcg_temp_free(t1);
76a66253 5397 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5398 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5399}
5400
5401/* sreq */
99e300ef 5402static void gen_sreq(DisasContext *ctx)
76a66253 5403{
7487953d
AJ
5404 TCGv t0 = tcg_temp_new();
5405 TCGv t1 = tcg_temp_new();
5406 TCGv t2 = tcg_temp_new();
5407 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
5408 tcg_gen_movi_tl(t1, 0xFFFFFFFF);
5409 tcg_gen_shr_tl(t1, t1, t0);
5410 tcg_gen_rotr_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
5411 gen_load_spr(t2, SPR_MQ);
5412 gen_store_spr(SPR_MQ, t0);
5413 tcg_gen_and_tl(t0, t0, t1);
5414 tcg_gen_andc_tl(t2, t2, t1);
5415 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t2);
5416 tcg_temp_free(t0);
5417 tcg_temp_free(t1);
5418 tcg_temp_free(t2);
76a66253 5419 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5420 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5421}
5422
5423/* sriq */
99e300ef 5424static void gen_sriq(DisasContext *ctx)
76a66253 5425{
7487953d
AJ
5426 int sh = SH(ctx->opcode);
5427 TCGv t0 = tcg_temp_new();
5428 TCGv t1 = tcg_temp_new();
5429 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5430 tcg_gen_shli_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh);
5431 tcg_gen_or_tl(t1, t0, t1);
5432 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5433 gen_store_spr(SPR_MQ, t1);
5434 tcg_temp_free(t0);
5435 tcg_temp_free(t1);
76a66253 5436 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5437 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5438}
5439
5440/* srliq */
99e300ef 5441static void gen_srliq(DisasContext *ctx)
76a66253 5442{
7487953d
AJ
5443 int sh = SH(ctx->opcode);
5444 TCGv t0 = tcg_temp_new();
5445 TCGv t1 = tcg_temp_new();
5446 tcg_gen_rotri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5447 gen_load_spr(t1, SPR_MQ);
5448 gen_store_spr(SPR_MQ, t0);
5449 tcg_gen_andi_tl(t0, t0, (0xFFFFFFFFU >> sh));
5450 tcg_gen_andi_tl(t1, t1, ~(0xFFFFFFFFU >> sh));
5451 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5452 tcg_temp_free(t0);
5453 tcg_temp_free(t1);
76a66253 5454 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5455 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5456}
5457
5458/* srlq */
99e300ef 5459static void gen_srlq(DisasContext *ctx)
76a66253 5460{
7487953d
AJ
5461 int l1 = gen_new_label();
5462 int l2 = gen_new_label();
5463 TCGv t0 = tcg_temp_local_new();
5464 TCGv t1 = tcg_temp_local_new();
5465 TCGv t2 = tcg_temp_local_new();
5466 tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F);
5467 tcg_gen_movi_tl(t1, 0xFFFFFFFF);
5468 tcg_gen_shr_tl(t2, t1, t2);
5469 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20);
5470 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
5471 gen_load_spr(t0, SPR_MQ);
5472 tcg_gen_and_tl(cpu_gpr[rA(ctx->opcode)], t0, t2);
5473 tcg_gen_br(l2);
5474 gen_set_label(l1);
5475 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t2);
5476 tcg_gen_and_tl(t0, t0, t2);
5477 gen_load_spr(t1, SPR_MQ);
5478 tcg_gen_andc_tl(t1, t1, t2);
5479 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5480 gen_set_label(l2);
5481 tcg_temp_free(t0);
5482 tcg_temp_free(t1);
5483 tcg_temp_free(t2);
76a66253 5484 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5485 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5486}
5487
5488/* srq */
99e300ef 5489static void gen_srq(DisasContext *ctx)
76a66253 5490{
7487953d
AJ
5491 int l1 = gen_new_label();
5492 TCGv t0 = tcg_temp_new();
5493 TCGv t1 = tcg_temp_new();
5494 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5495 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5496 tcg_gen_subfi_tl(t1, 32, t1);
5497 tcg_gen_shl_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
5498 tcg_gen_or_tl(t1, t0, t1);
5499 gen_store_spr(SPR_MQ, t1);
5500 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x20);
5501 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5502 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
5503 tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
5504 gen_set_label(l1);
5505 tcg_temp_free(t0);
5506 tcg_temp_free(t1);
76a66253 5507 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5508 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5509}
5510
5511/* PowerPC 602 specific instructions */
99e300ef 5512
54623277 5513/* dsa */
99e300ef 5514static void gen_dsa(DisasContext *ctx)
76a66253
JM
5515{
5516 /* XXX: TODO */
e06fcd75 5517 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
76a66253
JM
5518}
5519
5520/* esa */
99e300ef 5521static void gen_esa(DisasContext *ctx)
76a66253
JM
5522{
5523 /* XXX: TODO */
e06fcd75 5524 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
76a66253
JM
5525}
5526
5527/* mfrom */
99e300ef 5528static void gen_mfrom(DisasContext *ctx)
76a66253
JM
5529{
5530#if defined(CONFIG_USER_ONLY)
e06fcd75 5531 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5532#else
76db3ba4 5533 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5534 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5535 return;
5536 }
cf02a65c 5537 gen_helper_602_mfrom(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5538#endif
5539}
5540
5541/* 602 - 603 - G2 TLB management */
e8eaa2c0 5542
54623277 5543/* tlbld */
e8eaa2c0 5544static void gen_tlbld_6xx(DisasContext *ctx)
76a66253
JM
5545{
5546#if defined(CONFIG_USER_ONLY)
e06fcd75 5547 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5548#else
76db3ba4 5549 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5550 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5551 return;
5552 }
c6c7cf05 5553 gen_helper_6xx_tlbd(cpu_env, cpu_gpr[rB(ctx->opcode)]);
76a66253
JM
5554#endif
5555}
5556
5557/* tlbli */
e8eaa2c0 5558static void gen_tlbli_6xx(DisasContext *ctx)
76a66253
JM
5559{
5560#if defined(CONFIG_USER_ONLY)
e06fcd75 5561 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5562#else
76db3ba4 5563 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5564 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5565 return;
5566 }
c6c7cf05 5567 gen_helper_6xx_tlbi(cpu_env, cpu_gpr[rB(ctx->opcode)]);
76a66253
JM
5568#endif
5569}
5570
7dbe11ac 5571/* 74xx TLB management */
e8eaa2c0 5572
54623277 5573/* tlbld */
e8eaa2c0 5574static void gen_tlbld_74xx(DisasContext *ctx)
7dbe11ac
JM
5575{
5576#if defined(CONFIG_USER_ONLY)
e06fcd75 5577 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
7dbe11ac 5578#else
76db3ba4 5579 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5580 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
7dbe11ac
JM
5581 return;
5582 }
c6c7cf05 5583 gen_helper_74xx_tlbd(cpu_env, cpu_gpr[rB(ctx->opcode)]);
7dbe11ac
JM
5584#endif
5585}
5586
5587/* tlbli */
e8eaa2c0 5588static void gen_tlbli_74xx(DisasContext *ctx)
7dbe11ac
JM
5589{
5590#if defined(CONFIG_USER_ONLY)
e06fcd75 5591 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
7dbe11ac 5592#else
76db3ba4 5593 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5594 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
7dbe11ac
JM
5595 return;
5596 }
c6c7cf05 5597 gen_helper_74xx_tlbi(cpu_env, cpu_gpr[rB(ctx->opcode)]);
7dbe11ac
JM
5598#endif
5599}
5600
76a66253 5601/* POWER instructions not in PowerPC 601 */
99e300ef 5602
54623277 5603/* clf */
99e300ef 5604static void gen_clf(DisasContext *ctx)
76a66253
JM
5605{
5606 /* Cache line flush: implemented as no-op */
5607}
5608
5609/* cli */
99e300ef 5610static void gen_cli(DisasContext *ctx)
76a66253 5611{
7f75ffd3 5612 /* Cache line invalidate: privileged and treated as no-op */
76a66253 5613#if defined(CONFIG_USER_ONLY)
e06fcd75 5614 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5615#else
76db3ba4 5616 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5617 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5618 return;
5619 }
5620#endif
5621}
5622
5623/* dclst */
99e300ef 5624static void gen_dclst(DisasContext *ctx)
76a66253
JM
5625{
5626 /* Data cache line store: treated as no-op */
5627}
5628
99e300ef 5629static void gen_mfsri(DisasContext *ctx)
76a66253
JM
5630{
5631#if defined(CONFIG_USER_ONLY)
e06fcd75 5632 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5633#else
74d37793
AJ
5634 int ra = rA(ctx->opcode);
5635 int rd = rD(ctx->opcode);
5636 TCGv t0;
76db3ba4 5637 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5638 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5639 return;
5640 }
74d37793 5641 t0 = tcg_temp_new();
76db3ba4 5642 gen_addr_reg_index(ctx, t0);
74d37793
AJ
5643 tcg_gen_shri_tl(t0, t0, 28);
5644 tcg_gen_andi_tl(t0, t0, 0xF);
c6c7cf05 5645 gen_helper_load_sr(cpu_gpr[rd], cpu_env, t0);
74d37793 5646 tcg_temp_free(t0);
76a66253 5647 if (ra != 0 && ra != rd)
74d37793 5648 tcg_gen_mov_tl(cpu_gpr[ra], cpu_gpr[rd]);
76a66253
JM
5649#endif
5650}
5651
99e300ef 5652static void gen_rac(DisasContext *ctx)
76a66253
JM
5653{
5654#if defined(CONFIG_USER_ONLY)
e06fcd75 5655 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5656#else
22e0e173 5657 TCGv t0;
76db3ba4 5658 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5659 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5660 return;
5661 }
22e0e173 5662 t0 = tcg_temp_new();
76db3ba4 5663 gen_addr_reg_index(ctx, t0);
c6c7cf05 5664 gen_helper_rac(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
22e0e173 5665 tcg_temp_free(t0);
76a66253
JM
5666#endif
5667}
5668
99e300ef 5669static void gen_rfsvc(DisasContext *ctx)
76a66253
JM
5670{
5671#if defined(CONFIG_USER_ONLY)
e06fcd75 5672 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5673#else
76db3ba4 5674 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5675 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5676 return;
5677 }
e5f17ac6 5678 gen_helper_rfsvc(cpu_env);
e06fcd75 5679 gen_sync_exception(ctx);
76a66253
JM
5680#endif
5681}
5682
5683/* svc is not implemented for now */
5684
5685/* POWER2 specific instructions */
5686/* Quad manipulation (load/store two floats at a time) */
76a66253
JM
5687
5688/* lfq */
99e300ef 5689static void gen_lfq(DisasContext *ctx)
76a66253 5690{
01a4afeb 5691 int rd = rD(ctx->opcode);
76db3ba4
AJ
5692 TCGv t0;
5693 gen_set_access_type(ctx, ACCESS_FLOAT);
5694 t0 = tcg_temp_new();
5695 gen_addr_imm_index(ctx, t0, 0);
5696 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5697 gen_addr_add(ctx, t0, t0, 8);
5698 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t0);
01a4afeb 5699 tcg_temp_free(t0);
76a66253
JM
5700}
5701
5702/* lfqu */
99e300ef 5703static void gen_lfqu(DisasContext *ctx)
76a66253
JM
5704{
5705 int ra = rA(ctx->opcode);
01a4afeb 5706 int rd = rD(ctx->opcode);
76db3ba4
AJ
5707 TCGv t0, t1;
5708 gen_set_access_type(ctx, ACCESS_FLOAT);
5709 t0 = tcg_temp_new();
5710 t1 = tcg_temp_new();
5711 gen_addr_imm_index(ctx, t0, 0);
5712 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5713 gen_addr_add(ctx, t1, t0, 8);
5714 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t1);
76a66253 5715 if (ra != 0)
01a4afeb
AJ
5716 tcg_gen_mov_tl(cpu_gpr[ra], t0);
5717 tcg_temp_free(t0);
5718 tcg_temp_free(t1);
76a66253
JM
5719}
5720
5721/* lfqux */
99e300ef 5722static void gen_lfqux(DisasContext *ctx)
76a66253
JM
5723{
5724 int ra = rA(ctx->opcode);
01a4afeb 5725 int rd = rD(ctx->opcode);
76db3ba4
AJ
5726 gen_set_access_type(ctx, ACCESS_FLOAT);
5727 TCGv t0, t1;
5728 t0 = tcg_temp_new();
5729 gen_addr_reg_index(ctx, t0);
5730 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5731 t1 = tcg_temp_new();
5732 gen_addr_add(ctx, t1, t0, 8);
5733 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t1);
5734 tcg_temp_free(t1);
76a66253 5735 if (ra != 0)
01a4afeb
AJ
5736 tcg_gen_mov_tl(cpu_gpr[ra], t0);
5737 tcg_temp_free(t0);
76a66253
JM
5738}
5739
5740/* lfqx */
99e300ef 5741static void gen_lfqx(DisasContext *ctx)
76a66253 5742{
01a4afeb 5743 int rd = rD(ctx->opcode);
76db3ba4
AJ
5744 TCGv t0;
5745 gen_set_access_type(ctx, ACCESS_FLOAT);
5746 t0 = tcg_temp_new();
5747 gen_addr_reg_index(ctx, t0);
5748 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5749 gen_addr_add(ctx, t0, t0, 8);
5750 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t0);
01a4afeb 5751 tcg_temp_free(t0);
76a66253
JM
5752}
5753
5754/* stfq */
99e300ef 5755static void gen_stfq(DisasContext *ctx)
76a66253 5756{
01a4afeb 5757 int rd = rD(ctx->opcode);
76db3ba4
AJ
5758 TCGv t0;
5759 gen_set_access_type(ctx, ACCESS_FLOAT);
5760 t0 = tcg_temp_new();
5761 gen_addr_imm_index(ctx, t0, 0);
5762 gen_qemu_st64(ctx, cpu_fpr[rd], t0);
5763 gen_addr_add(ctx, t0, t0, 8);
5764 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t0);
01a4afeb 5765 tcg_temp_free(t0);
76a66253
JM
5766}
5767
5768/* stfqu */
99e300ef 5769static void gen_stfqu(DisasContext *ctx)
76a66253
JM
5770{
5771 int ra = rA(ctx->opcode);
01a4afeb 5772 int rd = rD(ctx->opcode);
76db3ba4
AJ
5773 TCGv t0, t1;
5774 gen_set_access_type(ctx, ACCESS_FLOAT);
5775 t0 = tcg_temp_new();
5776 gen_addr_imm_index(ctx, t0, 0);
5777 gen_qemu_st64(ctx, cpu_fpr[rd], t0);
5778 t1 = tcg_temp_new();
5779 gen_addr_add(ctx, t1, t0, 8);
5780 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t1);
5781 tcg_temp_free(t1);
76a66253 5782 if (ra != 0)
01a4afeb
AJ
5783 tcg_gen_mov_tl(cpu_gpr[ra], t0);
5784 tcg_temp_free(t0);
76a66253
JM
5785}
5786
5787/* stfqux */
99e300ef 5788static void gen_stfqux(DisasContext *ctx)
76a66253
JM
5789{
5790 int ra = rA(ctx->opcode);
01a4afeb 5791 int rd = rD(ctx->opcode);
76db3ba4
AJ
5792 TCGv t0, t1;
5793 gen_set_access_type(ctx, ACCESS_FLOAT);
5794 t0 = tcg_temp_new();
5795 gen_addr_reg_index(ctx, t0);
5796 gen_qemu_st64(ctx, cpu_fpr[rd], t0);
5797 t1 = tcg_temp_new();
5798 gen_addr_add(ctx, t1, t0, 8);
5799 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t1);
5800 tcg_temp_free(t1);
76a66253 5801 if (ra != 0)
01a4afeb
AJ
5802 tcg_gen_mov_tl(cpu_gpr[ra], t0);
5803 tcg_temp_free(t0);
76a66253
JM
5804}
5805
5806/* stfqx */
99e300ef 5807static void gen_stfqx(DisasContext *ctx)
76a66253 5808{
01a4afeb 5809 int rd = rD(ctx->opcode);
76db3ba4
AJ
5810 TCGv t0;
5811 gen_set_access_type(ctx, ACCESS_FLOAT);
5812 t0 = tcg_temp_new();
5813 gen_addr_reg_index(ctx, t0);
5814 gen_qemu_st64(ctx, cpu_fpr[rd], t0);
5815 gen_addr_add(ctx, t0, t0, 8);
5816 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t0);
01a4afeb 5817 tcg_temp_free(t0);
76a66253
JM
5818}
5819
5820/* BookE specific instructions */
99e300ef 5821
54623277 5822/* XXX: not implemented on 440 ? */
99e300ef 5823static void gen_mfapidi(DisasContext *ctx)
76a66253
JM
5824{
5825 /* XXX: TODO */
e06fcd75 5826 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
76a66253
JM
5827}
5828
2662a059 5829/* XXX: not implemented on 440 ? */
99e300ef 5830static void gen_tlbiva(DisasContext *ctx)
76a66253
JM
5831{
5832#if defined(CONFIG_USER_ONLY)
e06fcd75 5833 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5834#else
74d37793 5835 TCGv t0;
76db3ba4 5836 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5837 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5838 return;
5839 }
ec72e276 5840 t0 = tcg_temp_new();
76db3ba4 5841 gen_addr_reg_index(ctx, t0);
c6c7cf05 5842 gen_helper_tlbie(cpu_env, cpu_gpr[rB(ctx->opcode)]);
74d37793 5843 tcg_temp_free(t0);
76a66253
JM
5844#endif
5845}
5846
5847/* All 405 MAC instructions are translated here */
636aa200
BS
5848static inline void gen_405_mulladd_insn(DisasContext *ctx, int opc2, int opc3,
5849 int ra, int rb, int rt, int Rc)
76a66253 5850{
182608d4
AJ
5851 TCGv t0, t1;
5852
a7812ae4
PB
5853 t0 = tcg_temp_local_new();
5854 t1 = tcg_temp_local_new();
182608d4 5855
76a66253
JM
5856 switch (opc3 & 0x0D) {
5857 case 0x05:
5858 /* macchw - macchw. - macchwo - macchwo. */
5859 /* macchws - macchws. - macchwso - macchwso. */
5860 /* nmacchw - nmacchw. - nmacchwo - nmacchwo. */
5861 /* nmacchws - nmacchws. - nmacchwso - nmacchwso. */
5862 /* mulchw - mulchw. */
182608d4
AJ
5863 tcg_gen_ext16s_tl(t0, cpu_gpr[ra]);
5864 tcg_gen_sari_tl(t1, cpu_gpr[rb], 16);
5865 tcg_gen_ext16s_tl(t1, t1);
76a66253
JM
5866 break;
5867 case 0x04:
5868 /* macchwu - macchwu. - macchwuo - macchwuo. */
5869 /* macchwsu - macchwsu. - macchwsuo - macchwsuo. */
5870 /* mulchwu - mulchwu. */
182608d4
AJ
5871 tcg_gen_ext16u_tl(t0, cpu_gpr[ra]);
5872 tcg_gen_shri_tl(t1, cpu_gpr[rb], 16);
5873 tcg_gen_ext16u_tl(t1, t1);
76a66253
JM
5874 break;
5875 case 0x01:
5876 /* machhw - machhw. - machhwo - machhwo. */
5877 /* machhws - machhws. - machhwso - machhwso. */
5878 /* nmachhw - nmachhw. - nmachhwo - nmachhwo. */
5879 /* nmachhws - nmachhws. - nmachhwso - nmachhwso. */
5880 /* mulhhw - mulhhw. */
182608d4
AJ
5881 tcg_gen_sari_tl(t0, cpu_gpr[ra], 16);
5882 tcg_gen_ext16s_tl(t0, t0);
5883 tcg_gen_sari_tl(t1, cpu_gpr[rb], 16);
5884 tcg_gen_ext16s_tl(t1, t1);
76a66253
JM
5885 break;
5886 case 0x00:
5887 /* machhwu - machhwu. - machhwuo - machhwuo. */
5888 /* machhwsu - machhwsu. - machhwsuo - machhwsuo. */
5889 /* mulhhwu - mulhhwu. */
182608d4
AJ
5890 tcg_gen_shri_tl(t0, cpu_gpr[ra], 16);
5891 tcg_gen_ext16u_tl(t0, t0);
5892 tcg_gen_shri_tl(t1, cpu_gpr[rb], 16);
5893 tcg_gen_ext16u_tl(t1, t1);
76a66253
JM
5894 break;
5895 case 0x0D:
5896 /* maclhw - maclhw. - maclhwo - maclhwo. */
5897 /* maclhws - maclhws. - maclhwso - maclhwso. */
5898 /* nmaclhw - nmaclhw. - nmaclhwo - nmaclhwo. */
5899 /* nmaclhws - nmaclhws. - nmaclhwso - nmaclhwso. */
5900 /* mullhw - mullhw. */
182608d4
AJ
5901 tcg_gen_ext16s_tl(t0, cpu_gpr[ra]);
5902 tcg_gen_ext16s_tl(t1, cpu_gpr[rb]);
76a66253
JM
5903 break;
5904 case 0x0C:
5905 /* maclhwu - maclhwu. - maclhwuo - maclhwuo. */
5906 /* maclhwsu - maclhwsu. - maclhwsuo - maclhwsuo. */
5907 /* mullhwu - mullhwu. */
182608d4
AJ
5908 tcg_gen_ext16u_tl(t0, cpu_gpr[ra]);
5909 tcg_gen_ext16u_tl(t1, cpu_gpr[rb]);
76a66253
JM
5910 break;
5911 }
76a66253 5912 if (opc2 & 0x04) {
182608d4
AJ
5913 /* (n)multiply-and-accumulate (0x0C / 0x0E) */
5914 tcg_gen_mul_tl(t1, t0, t1);
5915 if (opc2 & 0x02) {
5916 /* nmultiply-and-accumulate (0x0E) */
5917 tcg_gen_sub_tl(t0, cpu_gpr[rt], t1);
5918 } else {
5919 /* multiply-and-accumulate (0x0C) */
5920 tcg_gen_add_tl(t0, cpu_gpr[rt], t1);
5921 }
5922
5923 if (opc3 & 0x12) {
5924 /* Check overflow and/or saturate */
5925 int l1 = gen_new_label();
5926
5927 if (opc3 & 0x10) {
5928 /* Start with XER OV disabled, the most likely case */
da91a00f 5929 tcg_gen_movi_tl(cpu_ov, 0);
182608d4
AJ
5930 }
5931 if (opc3 & 0x01) {
5932 /* Signed */
5933 tcg_gen_xor_tl(t1, cpu_gpr[rt], t1);
5934 tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l1);
5935 tcg_gen_xor_tl(t1, cpu_gpr[rt], t0);
5936 tcg_gen_brcondi_tl(TCG_COND_LT, t1, 0, l1);
bdc4e053 5937 if (opc3 & 0x02) {
182608d4
AJ
5938 /* Saturate */
5939 tcg_gen_sari_tl(t0, cpu_gpr[rt], 31);
5940 tcg_gen_xori_tl(t0, t0, 0x7fffffff);
5941 }
5942 } else {
5943 /* Unsigned */
5944 tcg_gen_brcond_tl(TCG_COND_GEU, t0, t1, l1);
bdc4e053 5945 if (opc3 & 0x02) {
182608d4
AJ
5946 /* Saturate */
5947 tcg_gen_movi_tl(t0, UINT32_MAX);
5948 }
5949 }
5950 if (opc3 & 0x10) {
5951 /* Check overflow */
da91a00f
RH
5952 tcg_gen_movi_tl(cpu_ov, 1);
5953 tcg_gen_movi_tl(cpu_so, 1);
182608d4
AJ
5954 }
5955 gen_set_label(l1);
5956 tcg_gen_mov_tl(cpu_gpr[rt], t0);
5957 }
5958 } else {
5959 tcg_gen_mul_tl(cpu_gpr[rt], t0, t1);
76a66253 5960 }
182608d4
AJ
5961 tcg_temp_free(t0);
5962 tcg_temp_free(t1);
76a66253
JM
5963 if (unlikely(Rc) != 0) {
5964 /* Update Rc0 */
182608d4 5965 gen_set_Rc0(ctx, cpu_gpr[rt]);
76a66253
JM
5966 }
5967}
5968
a750fc0b 5969#define GEN_MAC_HANDLER(name, opc2, opc3) \
99e300ef 5970static void glue(gen_, name)(DisasContext *ctx) \
76a66253
JM
5971{ \
5972 gen_405_mulladd_insn(ctx, opc2, opc3, rA(ctx->opcode), rB(ctx->opcode), \
5973 rD(ctx->opcode), Rc(ctx->opcode)); \
5974}
5975
5976/* macchw - macchw. */
a750fc0b 5977GEN_MAC_HANDLER(macchw, 0x0C, 0x05);
76a66253 5978/* macchwo - macchwo. */
a750fc0b 5979GEN_MAC_HANDLER(macchwo, 0x0C, 0x15);
76a66253 5980/* macchws - macchws. */
a750fc0b 5981GEN_MAC_HANDLER(macchws, 0x0C, 0x07);
76a66253 5982/* macchwso - macchwso. */
a750fc0b 5983GEN_MAC_HANDLER(macchwso, 0x0C, 0x17);
76a66253 5984/* macchwsu - macchwsu. */
a750fc0b 5985GEN_MAC_HANDLER(macchwsu, 0x0C, 0x06);
76a66253 5986/* macchwsuo - macchwsuo. */
a750fc0b 5987GEN_MAC_HANDLER(macchwsuo, 0x0C, 0x16);
76a66253 5988/* macchwu - macchwu. */
a750fc0b 5989GEN_MAC_HANDLER(macchwu, 0x0C, 0x04);
76a66253 5990/* macchwuo - macchwuo. */
a750fc0b 5991GEN_MAC_HANDLER(macchwuo, 0x0C, 0x14);
76a66253 5992/* machhw - machhw. */
a750fc0b 5993GEN_MAC_HANDLER(machhw, 0x0C, 0x01);
76a66253 5994/* machhwo - machhwo. */
a750fc0b 5995GEN_MAC_HANDLER(machhwo, 0x0C, 0x11);
76a66253 5996/* machhws - machhws. */
a750fc0b 5997GEN_MAC_HANDLER(machhws, 0x0C, 0x03);
76a66253 5998/* machhwso - machhwso. */
a750fc0b 5999GEN_MAC_HANDLER(machhwso, 0x0C, 0x13);
76a66253 6000/* machhwsu - machhwsu. */
a750fc0b 6001GEN_MAC_HANDLER(machhwsu, 0x0C, 0x02);
76a66253 6002/* machhwsuo - machhwsuo. */
a750fc0b 6003GEN_MAC_HANDLER(machhwsuo, 0x0C, 0x12);
76a66253 6004/* machhwu - machhwu. */
a750fc0b 6005GEN_MAC_HANDLER(machhwu, 0x0C, 0x00);
76a66253 6006/* machhwuo - machhwuo. */
a750fc0b 6007GEN_MAC_HANDLER(machhwuo, 0x0C, 0x10);
76a66253 6008/* maclhw - maclhw. */
a750fc0b 6009GEN_MAC_HANDLER(maclhw, 0x0C, 0x0D);
76a66253 6010/* maclhwo - maclhwo. */
a750fc0b 6011GEN_MAC_HANDLER(maclhwo, 0x0C, 0x1D);
76a66253 6012/* maclhws - maclhws. */
a750fc0b 6013GEN_MAC_HANDLER(maclhws, 0x0C, 0x0F);
76a66253 6014/* maclhwso - maclhwso. */
a750fc0b 6015GEN_MAC_HANDLER(maclhwso, 0x0C, 0x1F);
76a66253 6016/* maclhwu - maclhwu. */
a750fc0b 6017GEN_MAC_HANDLER(maclhwu, 0x0C, 0x0C);
76a66253 6018/* maclhwuo - maclhwuo. */
a750fc0b 6019GEN_MAC_HANDLER(maclhwuo, 0x0C, 0x1C);
76a66253 6020/* maclhwsu - maclhwsu. */
a750fc0b 6021GEN_MAC_HANDLER(maclhwsu, 0x0C, 0x0E);
76a66253 6022/* maclhwsuo - maclhwsuo. */
a750fc0b 6023GEN_MAC_HANDLER(maclhwsuo, 0x0C, 0x1E);
76a66253 6024/* nmacchw - nmacchw. */
a750fc0b 6025GEN_MAC_HANDLER(nmacchw, 0x0E, 0x05);
76a66253 6026/* nmacchwo - nmacchwo. */
a750fc0b 6027GEN_MAC_HANDLER(nmacchwo, 0x0E, 0x15);
76a66253 6028/* nmacchws - nmacchws. */
a750fc0b 6029GEN_MAC_HANDLER(nmacchws, 0x0E, 0x07);
76a66253 6030/* nmacchwso - nmacchwso. */
a750fc0b 6031GEN_MAC_HANDLER(nmacchwso, 0x0E, 0x17);
76a66253 6032/* nmachhw - nmachhw. */
a750fc0b 6033GEN_MAC_HANDLER(nmachhw, 0x0E, 0x01);
76a66253 6034/* nmachhwo - nmachhwo. */
a750fc0b 6035GEN_MAC_HANDLER(nmachhwo, 0x0E, 0x11);
76a66253 6036/* nmachhws - nmachhws. */
a750fc0b 6037GEN_MAC_HANDLER(nmachhws, 0x0E, 0x03);
76a66253 6038/* nmachhwso - nmachhwso. */
a750fc0b 6039GEN_MAC_HANDLER(nmachhwso, 0x0E, 0x13);
76a66253 6040/* nmaclhw - nmaclhw. */
a750fc0b 6041GEN_MAC_HANDLER(nmaclhw, 0x0E, 0x0D);
76a66253 6042/* nmaclhwo - nmaclhwo. */
a750fc0b 6043GEN_MAC_HANDLER(nmaclhwo, 0x0E, 0x1D);
76a66253 6044/* nmaclhws - nmaclhws. */
a750fc0b 6045GEN_MAC_HANDLER(nmaclhws, 0x0E, 0x0F);
76a66253 6046/* nmaclhwso - nmaclhwso. */
a750fc0b 6047GEN_MAC_HANDLER(nmaclhwso, 0x0E, 0x1F);
76a66253
JM
6048
6049/* mulchw - mulchw. */
a750fc0b 6050GEN_MAC_HANDLER(mulchw, 0x08, 0x05);
76a66253 6051/* mulchwu - mulchwu. */
a750fc0b 6052GEN_MAC_HANDLER(mulchwu, 0x08, 0x04);
76a66253 6053/* mulhhw - mulhhw. */
a750fc0b 6054GEN_MAC_HANDLER(mulhhw, 0x08, 0x01);
76a66253 6055/* mulhhwu - mulhhwu. */
a750fc0b 6056GEN_MAC_HANDLER(mulhhwu, 0x08, 0x00);
76a66253 6057/* mullhw - mullhw. */
a750fc0b 6058GEN_MAC_HANDLER(mullhw, 0x08, 0x0D);
76a66253 6059/* mullhwu - mullhwu. */
a750fc0b 6060GEN_MAC_HANDLER(mullhwu, 0x08, 0x0C);
76a66253
JM
6061
6062/* mfdcr */
99e300ef 6063static void gen_mfdcr(DisasContext *ctx)
76a66253
JM
6064{
6065#if defined(CONFIG_USER_ONLY)
e06fcd75 6066 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
76a66253 6067#else
06dca6a7 6068 TCGv dcrn;
76db3ba4 6069 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6070 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
76a66253
JM
6071 return;
6072 }
06dca6a7
AJ
6073 /* NIP cannot be restored if the memory exception comes from an helper */
6074 gen_update_nip(ctx, ctx->nip - 4);
6075 dcrn = tcg_const_tl(SPR(ctx->opcode));
d0f1562d 6076 gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_env, dcrn);
06dca6a7 6077 tcg_temp_free(dcrn);
76a66253
JM
6078#endif
6079}
6080
6081/* mtdcr */
99e300ef 6082static void gen_mtdcr(DisasContext *ctx)
76a66253
JM
6083{
6084#if defined(CONFIG_USER_ONLY)
e06fcd75 6085 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
76a66253 6086#else
06dca6a7 6087 TCGv dcrn;
76db3ba4 6088 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6089 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
76a66253
JM
6090 return;
6091 }
06dca6a7
AJ
6092 /* NIP cannot be restored if the memory exception comes from an helper */
6093 gen_update_nip(ctx, ctx->nip - 4);
6094 dcrn = tcg_const_tl(SPR(ctx->opcode));
d0f1562d 6095 gen_helper_store_dcr(cpu_env, dcrn, cpu_gpr[rS(ctx->opcode)]);
06dca6a7 6096 tcg_temp_free(dcrn);
a42bd6cc
JM
6097#endif
6098}
6099
6100/* mfdcrx */
2662a059 6101/* XXX: not implemented on 440 ? */
99e300ef 6102static void gen_mfdcrx(DisasContext *ctx)
a42bd6cc
JM
6103{
6104#if defined(CONFIG_USER_ONLY)
e06fcd75 6105 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
a42bd6cc 6106#else
76db3ba4 6107 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6108 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
a42bd6cc
JM
6109 return;
6110 }
06dca6a7
AJ
6111 /* NIP cannot be restored if the memory exception comes from an helper */
6112 gen_update_nip(ctx, ctx->nip - 4);
d0f1562d
BS
6113 gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_env,
6114 cpu_gpr[rA(ctx->opcode)]);
a750fc0b 6115 /* Note: Rc update flag set leads to undefined state of Rc0 */
a42bd6cc
JM
6116#endif
6117}
6118
6119/* mtdcrx */
2662a059 6120/* XXX: not implemented on 440 ? */
99e300ef 6121static void gen_mtdcrx(DisasContext *ctx)
a42bd6cc
JM
6122{
6123#if defined(CONFIG_USER_ONLY)
e06fcd75 6124 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
a42bd6cc 6125#else
76db3ba4 6126 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6127 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
a42bd6cc
JM
6128 return;
6129 }
06dca6a7
AJ
6130 /* NIP cannot be restored if the memory exception comes from an helper */
6131 gen_update_nip(ctx, ctx->nip - 4);
d0f1562d
BS
6132 gen_helper_store_dcr(cpu_env, cpu_gpr[rA(ctx->opcode)],
6133 cpu_gpr[rS(ctx->opcode)]);
a750fc0b 6134 /* Note: Rc update flag set leads to undefined state of Rc0 */
76a66253
JM
6135#endif
6136}
6137
a750fc0b 6138/* mfdcrux (PPC 460) : user-mode access to DCR */
99e300ef 6139static void gen_mfdcrux(DisasContext *ctx)
a750fc0b 6140{
06dca6a7
AJ
6141 /* NIP cannot be restored if the memory exception comes from an helper */
6142 gen_update_nip(ctx, ctx->nip - 4);
d0f1562d
BS
6143 gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_env,
6144 cpu_gpr[rA(ctx->opcode)]);
a750fc0b
JM
6145 /* Note: Rc update flag set leads to undefined state of Rc0 */
6146}
6147
6148/* mtdcrux (PPC 460) : user-mode access to DCR */
99e300ef 6149static void gen_mtdcrux(DisasContext *ctx)
a750fc0b 6150{
06dca6a7
AJ
6151 /* NIP cannot be restored if the memory exception comes from an helper */
6152 gen_update_nip(ctx, ctx->nip - 4);
975e5463 6153 gen_helper_store_dcr(cpu_env, cpu_gpr[rA(ctx->opcode)],
d0f1562d 6154 cpu_gpr[rS(ctx->opcode)]);
a750fc0b
JM
6155 /* Note: Rc update flag set leads to undefined state of Rc0 */
6156}
6157
76a66253 6158/* dccci */
99e300ef 6159static void gen_dccci(DisasContext *ctx)
76a66253
JM
6160{
6161#if defined(CONFIG_USER_ONLY)
e06fcd75 6162 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6163#else
76db3ba4 6164 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6165 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6166 return;
6167 }
6168 /* interpreted as no-op */
6169#endif
6170}
6171
6172/* dcread */
99e300ef 6173static void gen_dcread(DisasContext *ctx)
76a66253
JM
6174{
6175#if defined(CONFIG_USER_ONLY)
e06fcd75 6176 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6177#else
b61f2753 6178 TCGv EA, val;
76db3ba4 6179 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6180 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6181 return;
6182 }
76db3ba4 6183 gen_set_access_type(ctx, ACCESS_CACHE);
a7812ae4 6184 EA = tcg_temp_new();
76db3ba4 6185 gen_addr_reg_index(ctx, EA);
a7812ae4 6186 val = tcg_temp_new();
76db3ba4 6187 gen_qemu_ld32u(ctx, val, EA);
b61f2753
AJ
6188 tcg_temp_free(val);
6189 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], EA);
6190 tcg_temp_free(EA);
76a66253
JM
6191#endif
6192}
6193
6194/* icbt */
e8eaa2c0 6195static void gen_icbt_40x(DisasContext *ctx)
76a66253
JM
6196{
6197 /* interpreted as no-op */
6198 /* XXX: specification say this is treated as a load by the MMU
6199 * but does not generate any exception
6200 */
6201}
6202
6203/* iccci */
99e300ef 6204static void gen_iccci(DisasContext *ctx)
76a66253
JM
6205{
6206#if defined(CONFIG_USER_ONLY)
e06fcd75 6207 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6208#else
76db3ba4 6209 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6210 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6211 return;
6212 }
6213 /* interpreted as no-op */
6214#endif
6215}
6216
6217/* icread */
99e300ef 6218static void gen_icread(DisasContext *ctx)
76a66253
JM
6219{
6220#if defined(CONFIG_USER_ONLY)
e06fcd75 6221 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6222#else
76db3ba4 6223 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6224 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6225 return;
6226 }
6227 /* interpreted as no-op */
6228#endif
6229}
6230
76db3ba4 6231/* rfci (mem_idx only) */
e8eaa2c0 6232static void gen_rfci_40x(DisasContext *ctx)
a42bd6cc
JM
6233{
6234#if defined(CONFIG_USER_ONLY)
e06fcd75 6235 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a42bd6cc 6236#else
76db3ba4 6237 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6238 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a42bd6cc
JM
6239 return;
6240 }
6241 /* Restore CPU state */
e5f17ac6 6242 gen_helper_40x_rfci(cpu_env);
e06fcd75 6243 gen_sync_exception(ctx);
a42bd6cc
JM
6244#endif
6245}
6246
99e300ef 6247static void gen_rfci(DisasContext *ctx)
a42bd6cc
JM
6248{
6249#if defined(CONFIG_USER_ONLY)
e06fcd75 6250 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a42bd6cc 6251#else
76db3ba4 6252 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6253 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a42bd6cc
JM
6254 return;
6255 }
6256 /* Restore CPU state */
e5f17ac6 6257 gen_helper_rfci(cpu_env);
e06fcd75 6258 gen_sync_exception(ctx);
a42bd6cc
JM
6259#endif
6260}
6261
6262/* BookE specific */
99e300ef 6263
54623277 6264/* XXX: not implemented on 440 ? */
99e300ef 6265static void gen_rfdi(DisasContext *ctx)
76a66253
JM
6266{
6267#if defined(CONFIG_USER_ONLY)
e06fcd75 6268 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6269#else
76db3ba4 6270 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6271 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6272 return;
6273 }
6274 /* Restore CPU state */
e5f17ac6 6275 gen_helper_rfdi(cpu_env);
e06fcd75 6276 gen_sync_exception(ctx);
76a66253
JM
6277#endif
6278}
6279
2662a059 6280/* XXX: not implemented on 440 ? */
99e300ef 6281static void gen_rfmci(DisasContext *ctx)
a42bd6cc
JM
6282{
6283#if defined(CONFIG_USER_ONLY)
e06fcd75 6284 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a42bd6cc 6285#else
76db3ba4 6286 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6287 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a42bd6cc
JM
6288 return;
6289 }
6290 /* Restore CPU state */
e5f17ac6 6291 gen_helper_rfmci(cpu_env);
e06fcd75 6292 gen_sync_exception(ctx);
a42bd6cc
JM
6293#endif
6294}
5eb7995e 6295
d9bce9d9 6296/* TLB management - PowerPC 405 implementation */
e8eaa2c0 6297
54623277 6298/* tlbre */
e8eaa2c0 6299static void gen_tlbre_40x(DisasContext *ctx)
76a66253
JM
6300{
6301#if defined(CONFIG_USER_ONLY)
e06fcd75 6302 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6303#else
76db3ba4 6304 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6305 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6306 return;
6307 }
6308 switch (rB(ctx->opcode)) {
6309 case 0:
c6c7cf05
BS
6310 gen_helper_4xx_tlbre_hi(cpu_gpr[rD(ctx->opcode)], cpu_env,
6311 cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
6312 break;
6313 case 1:
c6c7cf05
BS
6314 gen_helper_4xx_tlbre_lo(cpu_gpr[rD(ctx->opcode)], cpu_env,
6315 cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
6316 break;
6317 default:
e06fcd75 6318 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
76a66253 6319 break;
9a64fbe4 6320 }
76a66253
JM
6321#endif
6322}
6323
d9bce9d9 6324/* tlbsx - tlbsx. */
e8eaa2c0 6325static void gen_tlbsx_40x(DisasContext *ctx)
76a66253
JM
6326{
6327#if defined(CONFIG_USER_ONLY)
e06fcd75 6328 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6329#else
74d37793 6330 TCGv t0;
76db3ba4 6331 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6332 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6333 return;
6334 }
74d37793 6335 t0 = tcg_temp_new();
76db3ba4 6336 gen_addr_reg_index(ctx, t0);
c6c7cf05 6337 gen_helper_4xx_tlbsx(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793
AJ
6338 tcg_temp_free(t0);
6339 if (Rc(ctx->opcode)) {
6340 int l1 = gen_new_label();
da91a00f 6341 tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so);
74d37793
AJ
6342 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_gpr[rD(ctx->opcode)], -1, l1);
6343 tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 0x02);
6344 gen_set_label(l1);
6345 }
76a66253 6346#endif
79aceca5
FB
6347}
6348
76a66253 6349/* tlbwe */
e8eaa2c0 6350static void gen_tlbwe_40x(DisasContext *ctx)
79aceca5 6351{
76a66253 6352#if defined(CONFIG_USER_ONLY)
e06fcd75 6353 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6354#else
76db3ba4 6355 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6356 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6357 return;
6358 }
6359 switch (rB(ctx->opcode)) {
6360 case 0:
c6c7cf05
BS
6361 gen_helper_4xx_tlbwe_hi(cpu_env, cpu_gpr[rA(ctx->opcode)],
6362 cpu_gpr[rS(ctx->opcode)]);
76a66253
JM
6363 break;
6364 case 1:
c6c7cf05
BS
6365 gen_helper_4xx_tlbwe_lo(cpu_env, cpu_gpr[rA(ctx->opcode)],
6366 cpu_gpr[rS(ctx->opcode)]);
76a66253
JM
6367 break;
6368 default:
e06fcd75 6369 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
76a66253 6370 break;
9a64fbe4 6371 }
76a66253
JM
6372#endif
6373}
6374
a4bb6c3e 6375/* TLB management - PowerPC 440 implementation */
e8eaa2c0 6376
54623277 6377/* tlbre */
e8eaa2c0 6378static void gen_tlbre_440(DisasContext *ctx)
5eb7995e
JM
6379{
6380#if defined(CONFIG_USER_ONLY)
e06fcd75 6381 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5eb7995e 6382#else
76db3ba4 6383 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6384 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5eb7995e
JM
6385 return;
6386 }
6387 switch (rB(ctx->opcode)) {
6388 case 0:
5eb7995e 6389 case 1:
5eb7995e 6390 case 2:
74d37793
AJ
6391 {
6392 TCGv_i32 t0 = tcg_const_i32(rB(ctx->opcode));
c6c7cf05
BS
6393 gen_helper_440_tlbre(cpu_gpr[rD(ctx->opcode)], cpu_env,
6394 t0, cpu_gpr[rA(ctx->opcode)]);
74d37793
AJ
6395 tcg_temp_free_i32(t0);
6396 }
5eb7995e
JM
6397 break;
6398 default:
e06fcd75 6399 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
5eb7995e
JM
6400 break;
6401 }
6402#endif
6403}
6404
6405/* tlbsx - tlbsx. */
e8eaa2c0 6406static void gen_tlbsx_440(DisasContext *ctx)
5eb7995e
JM
6407{
6408#if defined(CONFIG_USER_ONLY)
e06fcd75 6409 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5eb7995e 6410#else
74d37793 6411 TCGv t0;
76db3ba4 6412 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6413 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5eb7995e
JM
6414 return;
6415 }
74d37793 6416 t0 = tcg_temp_new();
76db3ba4 6417 gen_addr_reg_index(ctx, t0);
c6c7cf05 6418 gen_helper_440_tlbsx(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793
AJ
6419 tcg_temp_free(t0);
6420 if (Rc(ctx->opcode)) {
6421 int l1 = gen_new_label();
da91a00f 6422 tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so);
74d37793
AJ
6423 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_gpr[rD(ctx->opcode)], -1, l1);
6424 tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 0x02);
6425 gen_set_label(l1);
6426 }
5eb7995e
JM
6427#endif
6428}
6429
6430/* tlbwe */
e8eaa2c0 6431static void gen_tlbwe_440(DisasContext *ctx)
5eb7995e
JM
6432{
6433#if defined(CONFIG_USER_ONLY)
e06fcd75 6434 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5eb7995e 6435#else
76db3ba4 6436 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6437 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5eb7995e
JM
6438 return;
6439 }
6440 switch (rB(ctx->opcode)) {
6441 case 0:
5eb7995e 6442 case 1:
5eb7995e 6443 case 2:
74d37793
AJ
6444 {
6445 TCGv_i32 t0 = tcg_const_i32(rB(ctx->opcode));
c6c7cf05
BS
6446 gen_helper_440_tlbwe(cpu_env, t0, cpu_gpr[rA(ctx->opcode)],
6447 cpu_gpr[rS(ctx->opcode)]);
74d37793
AJ
6448 tcg_temp_free_i32(t0);
6449 }
5eb7995e
JM
6450 break;
6451 default:
e06fcd75 6452 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
5eb7995e
JM
6453 break;
6454 }
6455#endif
6456}
6457
01662f3e
AG
6458/* TLB management - PowerPC BookE 2.06 implementation */
6459
6460/* tlbre */
6461static void gen_tlbre_booke206(DisasContext *ctx)
6462{
6463#if defined(CONFIG_USER_ONLY)
6464 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6465#else
6466 if (unlikely(!ctx->mem_idx)) {
6467 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6468 return;
6469 }
6470
c6c7cf05 6471 gen_helper_booke206_tlbre(cpu_env);
01662f3e
AG
6472#endif
6473}
6474
6475/* tlbsx - tlbsx. */
6476static void gen_tlbsx_booke206(DisasContext *ctx)
6477{
6478#if defined(CONFIG_USER_ONLY)
6479 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6480#else
6481 TCGv t0;
6482 if (unlikely(!ctx->mem_idx)) {
6483 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6484 return;
6485 }
6486
6487 if (rA(ctx->opcode)) {
6488 t0 = tcg_temp_new();
6489 tcg_gen_mov_tl(t0, cpu_gpr[rD(ctx->opcode)]);
6490 } else {
6491 t0 = tcg_const_tl(0);
6492 }
6493
6494 tcg_gen_add_tl(t0, t0, cpu_gpr[rB(ctx->opcode)]);
c6c7cf05 6495 gen_helper_booke206_tlbsx(cpu_env, t0);
01662f3e
AG
6496#endif
6497}
6498
6499/* tlbwe */
6500static void gen_tlbwe_booke206(DisasContext *ctx)
6501{
6502#if defined(CONFIG_USER_ONLY)
6503 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6504#else
6505 if (unlikely(!ctx->mem_idx)) {
6506 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6507 return;
6508 }
3f162d11 6509 gen_update_nip(ctx, ctx->nip - 4);
c6c7cf05 6510 gen_helper_booke206_tlbwe(cpu_env);
01662f3e
AG
6511#endif
6512}
6513
6514static void gen_tlbivax_booke206(DisasContext *ctx)
6515{
6516#if defined(CONFIG_USER_ONLY)
6517 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6518#else
6519 TCGv t0;
6520 if (unlikely(!ctx->mem_idx)) {
6521 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6522 return;
6523 }
6524
6525 t0 = tcg_temp_new();
6526 gen_addr_reg_index(ctx, t0);
6527
c6c7cf05 6528 gen_helper_booke206_tlbivax(cpu_env, t0);
01662f3e
AG
6529#endif
6530}
6531
6d3db821
AG
6532static void gen_tlbilx_booke206(DisasContext *ctx)
6533{
6534#if defined(CONFIG_USER_ONLY)
6535 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6536#else
6537 TCGv t0;
6538 if (unlikely(!ctx->mem_idx)) {
6539 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6540 return;
6541 }
6542
6543 t0 = tcg_temp_new();
6544 gen_addr_reg_index(ctx, t0);
6545
6546 switch((ctx->opcode >> 21) & 0x3) {
6547 case 0:
c6c7cf05 6548 gen_helper_booke206_tlbilx0(cpu_env, t0);
6d3db821
AG
6549 break;
6550 case 1:
c6c7cf05 6551 gen_helper_booke206_tlbilx1(cpu_env, t0);
6d3db821
AG
6552 break;
6553 case 3:
c6c7cf05 6554 gen_helper_booke206_tlbilx3(cpu_env, t0);
6d3db821
AG
6555 break;
6556 default:
6557 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
6558 break;
6559 }
6560
6561 tcg_temp_free(t0);
6562#endif
6563}
6564
01662f3e 6565
76a66253 6566/* wrtee */
99e300ef 6567static void gen_wrtee(DisasContext *ctx)
76a66253
JM
6568{
6569#if defined(CONFIG_USER_ONLY)
e06fcd75 6570 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6571#else
6527f6ea 6572 TCGv t0;
76db3ba4 6573 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6574 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6575 return;
6576 }
6527f6ea
AJ
6577 t0 = tcg_temp_new();
6578 tcg_gen_andi_tl(t0, cpu_gpr[rD(ctx->opcode)], (1 << MSR_EE));
6579 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~(1 << MSR_EE));
6580 tcg_gen_or_tl(cpu_msr, cpu_msr, t0);
6581 tcg_temp_free(t0);
dee96f6c
JM
6582 /* Stop translation to have a chance to raise an exception
6583 * if we just set msr_ee to 1
6584 */
e06fcd75 6585 gen_stop_exception(ctx);
76a66253
JM
6586#endif
6587}
6588
6589/* wrteei */
99e300ef 6590static void gen_wrteei(DisasContext *ctx)
76a66253
JM
6591{
6592#if defined(CONFIG_USER_ONLY)
e06fcd75 6593 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6594#else
76db3ba4 6595 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6596 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6597 return;
6598 }
fbe73008 6599 if (ctx->opcode & 0x00008000) {
6527f6ea
AJ
6600 tcg_gen_ori_tl(cpu_msr, cpu_msr, (1 << MSR_EE));
6601 /* Stop translation to have a chance to raise an exception */
e06fcd75 6602 gen_stop_exception(ctx);
6527f6ea 6603 } else {
1b6e5f99 6604 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~(1 << MSR_EE));
6527f6ea 6605 }
76a66253
JM
6606#endif
6607}
6608
08e46e54 6609/* PowerPC 440 specific instructions */
99e300ef 6610
54623277 6611/* dlmzb */
99e300ef 6612static void gen_dlmzb(DisasContext *ctx)
76a66253 6613{
ef0d51af 6614 TCGv_i32 t0 = tcg_const_i32(Rc(ctx->opcode));
d15f74fb
BS
6615 gen_helper_dlmzb(cpu_gpr[rA(ctx->opcode)], cpu_env,
6616 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], t0);
ef0d51af 6617 tcg_temp_free_i32(t0);
76a66253
JM
6618}
6619
6620/* mbar replaces eieio on 440 */
99e300ef 6621static void gen_mbar(DisasContext *ctx)
76a66253
JM
6622{
6623 /* interpreted as no-op */
6624}
6625
6626/* msync replaces sync on 440 */
dcb2b9e1 6627static void gen_msync_4xx(DisasContext *ctx)
76a66253
JM
6628{
6629 /* interpreted as no-op */
6630}
6631
6632/* icbt */
e8eaa2c0 6633static void gen_icbt_440(DisasContext *ctx)
76a66253
JM
6634{
6635 /* interpreted as no-op */
6636 /* XXX: specification say this is treated as a load by the MMU
6637 * but does not generate any exception
6638 */
79aceca5
FB
6639}
6640
9e0b5cb1
AG
6641/* Embedded.Processor Control */
6642
6643static void gen_msgclr(DisasContext *ctx)
6644{
6645#if defined(CONFIG_USER_ONLY)
6646 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6647#else
6648 if (unlikely(ctx->mem_idx == 0)) {
6649 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6650 return;
6651 }
6652
e5f17ac6 6653 gen_helper_msgclr(cpu_env, cpu_gpr[rB(ctx->opcode)]);
9e0b5cb1
AG
6654#endif
6655}
6656
d5d11a39
AG
6657static void gen_msgsnd(DisasContext *ctx)
6658{
6659#if defined(CONFIG_USER_ONLY)
6660 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6661#else
6662 if (unlikely(ctx->mem_idx == 0)) {
6663 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6664 return;
6665 }
6666
6667 gen_helper_msgsnd(cpu_gpr[rB(ctx->opcode)]);
6668#endif
6669}
6670
a9d9eb8f
JM
6671/*** Altivec vector extension ***/
6672/* Altivec registers moves */
a9d9eb8f 6673
636aa200 6674static inline TCGv_ptr gen_avr_ptr(int reg)
564e571a 6675{
e4704b3b 6676 TCGv_ptr r = tcg_temp_new_ptr();
564e571a
AJ
6677 tcg_gen_addi_ptr(r, cpu_env, offsetof(CPUPPCState, avr[reg]));
6678 return r;
6679}
6680
a9d9eb8f 6681#define GEN_VR_LDX(name, opc2, opc3) \
99e300ef 6682static void glue(gen_, name)(DisasContext *ctx) \
a9d9eb8f 6683{ \
fe1e5c53 6684 TCGv EA; \
a9d9eb8f 6685 if (unlikely(!ctx->altivec_enabled)) { \
e06fcd75 6686 gen_exception(ctx, POWERPC_EXCP_VPU); \
a9d9eb8f
JM
6687 return; \
6688 } \
76db3ba4 6689 gen_set_access_type(ctx, ACCESS_INT); \
fe1e5c53 6690 EA = tcg_temp_new(); \
76db3ba4 6691 gen_addr_reg_index(ctx, EA); \
fe1e5c53 6692 tcg_gen_andi_tl(EA, EA, ~0xf); \
76db3ba4
AJ
6693 if (ctx->le_mode) { \
6694 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
fe1e5c53 6695 tcg_gen_addi_tl(EA, EA, 8); \
76db3ba4 6696 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
fe1e5c53 6697 } else { \
76db3ba4 6698 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
fe1e5c53 6699 tcg_gen_addi_tl(EA, EA, 8); \
76db3ba4 6700 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
fe1e5c53
AJ
6701 } \
6702 tcg_temp_free(EA); \
a9d9eb8f
JM
6703}
6704
6705#define GEN_VR_STX(name, opc2, opc3) \
99e300ef 6706static void gen_st##name(DisasContext *ctx) \
a9d9eb8f 6707{ \
fe1e5c53 6708 TCGv EA; \
a9d9eb8f 6709 if (unlikely(!ctx->altivec_enabled)) { \
e06fcd75 6710 gen_exception(ctx, POWERPC_EXCP_VPU); \
a9d9eb8f
JM
6711 return; \
6712 } \
76db3ba4 6713 gen_set_access_type(ctx, ACCESS_INT); \
fe1e5c53 6714 EA = tcg_temp_new(); \
76db3ba4 6715 gen_addr_reg_index(ctx, EA); \
fe1e5c53 6716 tcg_gen_andi_tl(EA, EA, ~0xf); \
76db3ba4
AJ
6717 if (ctx->le_mode) { \
6718 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
fe1e5c53 6719 tcg_gen_addi_tl(EA, EA, 8); \
76db3ba4 6720 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
fe1e5c53 6721 } else { \
76db3ba4 6722 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
fe1e5c53 6723 tcg_gen_addi_tl(EA, EA, 8); \
76db3ba4 6724 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
fe1e5c53
AJ
6725 } \
6726 tcg_temp_free(EA); \
a9d9eb8f
JM
6727}
6728
cbfb6ae9 6729#define GEN_VR_LVE(name, opc2, opc3) \
99e300ef 6730static void gen_lve##name(DisasContext *ctx) \
cbfb6ae9
AJ
6731 { \
6732 TCGv EA; \
6733 TCGv_ptr rs; \
6734 if (unlikely(!ctx->altivec_enabled)) { \
6735 gen_exception(ctx, POWERPC_EXCP_VPU); \
6736 return; \
6737 } \
6738 gen_set_access_type(ctx, ACCESS_INT); \
6739 EA = tcg_temp_new(); \
6740 gen_addr_reg_index(ctx, EA); \
6741 rs = gen_avr_ptr(rS(ctx->opcode)); \
2f5a189c 6742 gen_helper_lve##name(cpu_env, rs, EA); \
cbfb6ae9
AJ
6743 tcg_temp_free(EA); \
6744 tcg_temp_free_ptr(rs); \
6745 }
6746
6747#define GEN_VR_STVE(name, opc2, opc3) \
99e300ef 6748static void gen_stve##name(DisasContext *ctx) \
cbfb6ae9
AJ
6749 { \
6750 TCGv EA; \
6751 TCGv_ptr rs; \
6752 if (unlikely(!ctx->altivec_enabled)) { \
6753 gen_exception(ctx, POWERPC_EXCP_VPU); \
6754 return; \
6755 } \
6756 gen_set_access_type(ctx, ACCESS_INT); \
6757 EA = tcg_temp_new(); \
6758 gen_addr_reg_index(ctx, EA); \
6759 rs = gen_avr_ptr(rS(ctx->opcode)); \
2f5a189c 6760 gen_helper_stve##name(cpu_env, rs, EA); \
cbfb6ae9
AJ
6761 tcg_temp_free(EA); \
6762 tcg_temp_free_ptr(rs); \
6763 }
6764
fe1e5c53 6765GEN_VR_LDX(lvx, 0x07, 0x03);
a9d9eb8f 6766/* As we don't emulate the cache, lvxl is stricly equivalent to lvx */
fe1e5c53 6767GEN_VR_LDX(lvxl, 0x07, 0x0B);
a9d9eb8f 6768
cbfb6ae9
AJ
6769GEN_VR_LVE(bx, 0x07, 0x00);
6770GEN_VR_LVE(hx, 0x07, 0x01);
6771GEN_VR_LVE(wx, 0x07, 0x02);
6772
fe1e5c53 6773GEN_VR_STX(svx, 0x07, 0x07);
a9d9eb8f 6774/* As we don't emulate the cache, stvxl is stricly equivalent to stvx */
fe1e5c53 6775GEN_VR_STX(svxl, 0x07, 0x0F);
a9d9eb8f 6776
cbfb6ae9
AJ
6777GEN_VR_STVE(bx, 0x07, 0x04);
6778GEN_VR_STVE(hx, 0x07, 0x05);
6779GEN_VR_STVE(wx, 0x07, 0x06);
6780
99e300ef 6781static void gen_lvsl(DisasContext *ctx)
bf8d8ded
AJ
6782{
6783 TCGv_ptr rd;
6784 TCGv EA;
6785 if (unlikely(!ctx->altivec_enabled)) {
6786 gen_exception(ctx, POWERPC_EXCP_VPU);
6787 return;
6788 }
6789 EA = tcg_temp_new();
6790 gen_addr_reg_index(ctx, EA);
6791 rd = gen_avr_ptr(rD(ctx->opcode));
6792 gen_helper_lvsl(rd, EA);
6793 tcg_temp_free(EA);
6794 tcg_temp_free_ptr(rd);
6795}
6796
99e300ef 6797static void gen_lvsr(DisasContext *ctx)
bf8d8ded
AJ
6798{
6799 TCGv_ptr rd;
6800 TCGv EA;
6801 if (unlikely(!ctx->altivec_enabled)) {
6802 gen_exception(ctx, POWERPC_EXCP_VPU);
6803 return;
6804 }
6805 EA = tcg_temp_new();
6806 gen_addr_reg_index(ctx, EA);
6807 rd = gen_avr_ptr(rD(ctx->opcode));
6808 gen_helper_lvsr(rd, EA);
6809 tcg_temp_free(EA);
6810 tcg_temp_free_ptr(rd);
6811}
6812
99e300ef 6813static void gen_mfvscr(DisasContext *ctx)
785f451b
AJ
6814{
6815 TCGv_i32 t;
6816 if (unlikely(!ctx->altivec_enabled)) {
6817 gen_exception(ctx, POWERPC_EXCP_VPU);
6818 return;
6819 }
6820 tcg_gen_movi_i64(cpu_avrh[rD(ctx->opcode)], 0);
6821 t = tcg_temp_new_i32();
1328c2bf 6822 tcg_gen_ld_i32(t, cpu_env, offsetof(CPUPPCState, vscr));
785f451b 6823 tcg_gen_extu_i32_i64(cpu_avrl[rD(ctx->opcode)], t);
fce5ecb7 6824 tcg_temp_free_i32(t);
785f451b
AJ
6825}
6826
99e300ef 6827static void gen_mtvscr(DisasContext *ctx)
785f451b 6828{
6e87b7c7 6829 TCGv_ptr p;
785f451b
AJ
6830 if (unlikely(!ctx->altivec_enabled)) {
6831 gen_exception(ctx, POWERPC_EXCP_VPU);
6832 return;
6833 }
6e87b7c7 6834 p = gen_avr_ptr(rD(ctx->opcode));
d15f74fb 6835 gen_helper_mtvscr(cpu_env, p);
6e87b7c7 6836 tcg_temp_free_ptr(p);
785f451b
AJ
6837}
6838
7a9b96cf
AJ
6839/* Logical operations */
6840#define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \
99e300ef 6841static void glue(gen_, name)(DisasContext *ctx) \
7a9b96cf
AJ
6842{ \
6843 if (unlikely(!ctx->altivec_enabled)) { \
6844 gen_exception(ctx, POWERPC_EXCP_VPU); \
6845 return; \
6846 } \
6847 tcg_op(cpu_avrh[rD(ctx->opcode)], cpu_avrh[rA(ctx->opcode)], cpu_avrh[rB(ctx->opcode)]); \
6848 tcg_op(cpu_avrl[rD(ctx->opcode)], cpu_avrl[rA(ctx->opcode)], cpu_avrl[rB(ctx->opcode)]); \
6849}
6850
6851GEN_VX_LOGICAL(vand, tcg_gen_and_i64, 2, 16);
6852GEN_VX_LOGICAL(vandc, tcg_gen_andc_i64, 2, 17);
6853GEN_VX_LOGICAL(vor, tcg_gen_or_i64, 2, 18);
6854GEN_VX_LOGICAL(vxor, tcg_gen_xor_i64, 2, 19);
6855GEN_VX_LOGICAL(vnor, tcg_gen_nor_i64, 2, 20);
111c5f54
TM
6856GEN_VX_LOGICAL(veqv, tcg_gen_eqv_i64, 2, 26);
6857GEN_VX_LOGICAL(vnand, tcg_gen_nand_i64, 2, 22);
6858GEN_VX_LOGICAL(vorc, tcg_gen_orc_i64, 2, 21);
7a9b96cf 6859
8e27dd6f 6860#define GEN_VXFORM(name, opc2, opc3) \
99e300ef 6861static void glue(gen_, name)(DisasContext *ctx) \
8e27dd6f
AJ
6862{ \
6863 TCGv_ptr ra, rb, rd; \
6864 if (unlikely(!ctx->altivec_enabled)) { \
6865 gen_exception(ctx, POWERPC_EXCP_VPU); \
6866 return; \
6867 } \
6868 ra = gen_avr_ptr(rA(ctx->opcode)); \
6869 rb = gen_avr_ptr(rB(ctx->opcode)); \
6870 rd = gen_avr_ptr(rD(ctx->opcode)); \
6871 gen_helper_##name (rd, ra, rb); \
6872 tcg_temp_free_ptr(ra); \
6873 tcg_temp_free_ptr(rb); \
6874 tcg_temp_free_ptr(rd); \
6875}
6876
d15f74fb
BS
6877#define GEN_VXFORM_ENV(name, opc2, opc3) \
6878static void glue(gen_, name)(DisasContext *ctx) \
6879{ \
6880 TCGv_ptr ra, rb, rd; \
6881 if (unlikely(!ctx->altivec_enabled)) { \
6882 gen_exception(ctx, POWERPC_EXCP_VPU); \
6883 return; \
6884 } \
6885 ra = gen_avr_ptr(rA(ctx->opcode)); \
6886 rb = gen_avr_ptr(rB(ctx->opcode)); \
6887 rd = gen_avr_ptr(rD(ctx->opcode)); \
54cddd21 6888 gen_helper_##name(cpu_env, rd, ra, rb); \
d15f74fb
BS
6889 tcg_temp_free_ptr(ra); \
6890 tcg_temp_free_ptr(rb); \
6891 tcg_temp_free_ptr(rd); \
9b47bb49
TM
6892}
6893
6894#define GEN_VXFORM3(name, opc2, opc3) \
6895static void glue(gen_, name)(DisasContext *ctx) \
6896{ \
6897 TCGv_ptr ra, rb, rc, rd; \
6898 if (unlikely(!ctx->altivec_enabled)) { \
6899 gen_exception(ctx, POWERPC_EXCP_VPU); \
6900 return; \
6901 } \
6902 ra = gen_avr_ptr(rA(ctx->opcode)); \
6903 rb = gen_avr_ptr(rB(ctx->opcode)); \
6904 rc = gen_avr_ptr(rC(ctx->opcode)); \
6905 rd = gen_avr_ptr(rD(ctx->opcode)); \
6906 gen_helper_##name(rd, ra, rb, rc); \
6907 tcg_temp_free_ptr(ra); \
6908 tcg_temp_free_ptr(rb); \
6909 tcg_temp_free_ptr(rc); \
6910 tcg_temp_free_ptr(rd); \
d15f74fb
BS
6911}
6912
5dffff5a
TM
6913/*
6914 * Support for Altivec instruction pairs that use bit 31 (Rc) as
6915 * an opcode bit. In general, these pairs come from different
6916 * versions of the ISA, so we must also support a pair of flags for
6917 * each instruction.
6918 */
6919#define GEN_VXFORM_DUAL(name0, flg0, flg2_0, name1, flg1, flg2_1) \
6920static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
6921{ \
6922 if ((Rc(ctx->opcode) == 0) && \
6923 ((ctx->insns_flags & flg0) || (ctx->insns_flags2 & flg2_0))) { \
6924 gen_##name0(ctx); \
6925 } else if ((Rc(ctx->opcode) == 1) && \
6926 ((ctx->insns_flags & flg1) || (ctx->insns_flags2 & flg2_1))) { \
6927 gen_##name1(ctx); \
6928 } else { \
6929 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
6930 } \
6931}
6932
7872c51c
AJ
6933GEN_VXFORM(vaddubm, 0, 0);
6934GEN_VXFORM(vadduhm, 0, 1);
6935GEN_VXFORM(vadduwm, 0, 2);
56eabc75 6936GEN_VXFORM(vaddudm, 0, 3);
7872c51c
AJ
6937GEN_VXFORM(vsububm, 0, 16);
6938GEN_VXFORM(vsubuhm, 0, 17);
6939GEN_VXFORM(vsubuwm, 0, 18);
56eabc75 6940GEN_VXFORM(vsubudm, 0, 19);
e4039339
AJ
6941GEN_VXFORM(vmaxub, 1, 0);
6942GEN_VXFORM(vmaxuh, 1, 1);
6943GEN_VXFORM(vmaxuw, 1, 2);
8203e31b 6944GEN_VXFORM(vmaxud, 1, 3);
e4039339
AJ
6945GEN_VXFORM(vmaxsb, 1, 4);
6946GEN_VXFORM(vmaxsh, 1, 5);
6947GEN_VXFORM(vmaxsw, 1, 6);
8203e31b 6948GEN_VXFORM(vmaxsd, 1, 7);
e4039339
AJ
6949GEN_VXFORM(vminub, 1, 8);
6950GEN_VXFORM(vminuh, 1, 9);
6951GEN_VXFORM(vminuw, 1, 10);
8203e31b 6952GEN_VXFORM(vminud, 1, 11);
e4039339
AJ
6953GEN_VXFORM(vminsb, 1, 12);
6954GEN_VXFORM(vminsh, 1, 13);
6955GEN_VXFORM(vminsw, 1, 14);
8203e31b 6956GEN_VXFORM(vminsd, 1, 15);
fab3cbe9
AJ
6957GEN_VXFORM(vavgub, 1, 16);
6958GEN_VXFORM(vavguh, 1, 17);
6959GEN_VXFORM(vavguw, 1, 18);
6960GEN_VXFORM(vavgsb, 1, 20);
6961GEN_VXFORM(vavgsh, 1, 21);
6962GEN_VXFORM(vavgsw, 1, 22);
3b430048
AJ
6963GEN_VXFORM(vmrghb, 6, 0);
6964GEN_VXFORM(vmrghh, 6, 1);
6965GEN_VXFORM(vmrghw, 6, 2);
6966GEN_VXFORM(vmrglb, 6, 4);
6967GEN_VXFORM(vmrglh, 6, 5);
6968GEN_VXFORM(vmrglw, 6, 6);
e0ffe77f
TM
6969
6970static void gen_vmrgew(DisasContext *ctx)
6971{
6972 TCGv_i64 tmp;
6973 int VT, VA, VB;
6974 if (unlikely(!ctx->altivec_enabled)) {
6975 gen_exception(ctx, POWERPC_EXCP_VPU);
6976 return;
6977 }
6978 VT = rD(ctx->opcode);
6979 VA = rA(ctx->opcode);
6980 VB = rB(ctx->opcode);
6981 tmp = tcg_temp_new_i64();
6982 tcg_gen_shri_i64(tmp, cpu_avrh[VB], 32);
6983 tcg_gen_deposit_i64(cpu_avrh[VT], cpu_avrh[VA], tmp, 0, 32);
6984 tcg_gen_shri_i64(tmp, cpu_avrl[VB], 32);
6985 tcg_gen_deposit_i64(cpu_avrl[VT], cpu_avrl[VA], tmp, 0, 32);
6986 tcg_temp_free_i64(tmp);
6987}
6988
6989static void gen_vmrgow(DisasContext *ctx)
6990{
6991 int VT, VA, VB;
6992 if (unlikely(!ctx->altivec_enabled)) {
6993 gen_exception(ctx, POWERPC_EXCP_VPU);
6994 return;
6995 }
6996 VT = rD(ctx->opcode);
6997 VA = rA(ctx->opcode);
6998 VB = rB(ctx->opcode);
6999
7000 tcg_gen_deposit_i64(cpu_avrh[VT], cpu_avrh[VB], cpu_avrh[VA], 32, 32);
7001 tcg_gen_deposit_i64(cpu_avrl[VT], cpu_avrl[VB], cpu_avrl[VA], 32, 32);
7002}
7003
2c277908
AJ
7004GEN_VXFORM(vmuloub, 4, 0);
7005GEN_VXFORM(vmulouh, 4, 1);
63be0936 7006GEN_VXFORM(vmulouw, 4, 2);
953f0f58
TM
7007GEN_VXFORM(vmuluwm, 4, 2);
7008GEN_VXFORM_DUAL(vmulouw, PPC_ALTIVEC, PPC_NONE,
7009 vmuluwm, PPC_NONE, PPC2_ALTIVEC_207)
2c277908
AJ
7010GEN_VXFORM(vmulosb, 4, 4);
7011GEN_VXFORM(vmulosh, 4, 5);
63be0936 7012GEN_VXFORM(vmulosw, 4, 6);
2c277908
AJ
7013GEN_VXFORM(vmuleub, 4, 8);
7014GEN_VXFORM(vmuleuh, 4, 9);
63be0936 7015GEN_VXFORM(vmuleuw, 4, 10);
2c277908
AJ
7016GEN_VXFORM(vmulesb, 4, 12);
7017GEN_VXFORM(vmulesh, 4, 13);
63be0936 7018GEN_VXFORM(vmulesw, 4, 14);
d79f0809
AJ
7019GEN_VXFORM(vslb, 2, 4);
7020GEN_VXFORM(vslh, 2, 5);
7021GEN_VXFORM(vslw, 2, 6);
2fdf78e6 7022GEN_VXFORM(vsld, 2, 23);
07ef34c3
AJ
7023GEN_VXFORM(vsrb, 2, 8);
7024GEN_VXFORM(vsrh, 2, 9);
7025GEN_VXFORM(vsrw, 2, 10);
2fdf78e6 7026GEN_VXFORM(vsrd, 2, 27);
07ef34c3
AJ
7027GEN_VXFORM(vsrab, 2, 12);
7028GEN_VXFORM(vsrah, 2, 13);
7029GEN_VXFORM(vsraw, 2, 14);
2fdf78e6 7030GEN_VXFORM(vsrad, 2, 15);
7b239bec
AJ
7031GEN_VXFORM(vslo, 6, 16);
7032GEN_VXFORM(vsro, 6, 17);
e343da72
AJ
7033GEN_VXFORM(vaddcuw, 0, 6);
7034GEN_VXFORM(vsubcuw, 0, 22);
d15f74fb
BS
7035GEN_VXFORM_ENV(vaddubs, 0, 8);
7036GEN_VXFORM_ENV(vadduhs, 0, 9);
7037GEN_VXFORM_ENV(vadduws, 0, 10);
7038GEN_VXFORM_ENV(vaddsbs, 0, 12);
7039GEN_VXFORM_ENV(vaddshs, 0, 13);
7040GEN_VXFORM_ENV(vaddsws, 0, 14);
7041GEN_VXFORM_ENV(vsububs, 0, 24);
7042GEN_VXFORM_ENV(vsubuhs, 0, 25);
7043GEN_VXFORM_ENV(vsubuws, 0, 26);
7044GEN_VXFORM_ENV(vsubsbs, 0, 28);
7045GEN_VXFORM_ENV(vsubshs, 0, 29);
7046GEN_VXFORM_ENV(vsubsws, 0, 30);
b41da4eb
TM
7047GEN_VXFORM(vadduqm, 0, 4);
7048GEN_VXFORM(vaddcuq, 0, 5);
7049GEN_VXFORM3(vaddeuqm, 30, 0);
7050GEN_VXFORM3(vaddecuq, 30, 0);
7051GEN_VXFORM_DUAL(vaddeuqm, PPC_NONE, PPC2_ALTIVEC_207, \
7052 vaddecuq, PPC_NONE, PPC2_ALTIVEC_207)
7053GEN_VXFORM(vsubuqm, 0, 20);
7054GEN_VXFORM(vsubcuq, 0, 21);
7055GEN_VXFORM3(vsubeuqm, 31, 0);
7056GEN_VXFORM3(vsubecuq, 31, 0);
7057GEN_VXFORM_DUAL(vsubeuqm, PPC_NONE, PPC2_ALTIVEC_207, \
7058 vsubecuq, PPC_NONE, PPC2_ALTIVEC_207)
5e1d0985
AJ
7059GEN_VXFORM(vrlb, 2, 0);
7060GEN_VXFORM(vrlh, 2, 1);
7061GEN_VXFORM(vrlw, 2, 2);
2fdf78e6 7062GEN_VXFORM(vrld, 2, 3);
d9430add
AJ
7063GEN_VXFORM(vsl, 2, 7);
7064GEN_VXFORM(vsr, 2, 11);
d15f74fb
BS
7065GEN_VXFORM_ENV(vpkuhum, 7, 0);
7066GEN_VXFORM_ENV(vpkuwum, 7, 1);
024215b2 7067GEN_VXFORM_ENV(vpkudum, 7, 17);
d15f74fb
BS
7068GEN_VXFORM_ENV(vpkuhus, 7, 2);
7069GEN_VXFORM_ENV(vpkuwus, 7, 3);
024215b2 7070GEN_VXFORM_ENV(vpkudus, 7, 19);
d15f74fb
BS
7071GEN_VXFORM_ENV(vpkshus, 7, 4);
7072GEN_VXFORM_ENV(vpkswus, 7, 5);
024215b2 7073GEN_VXFORM_ENV(vpksdus, 7, 21);
d15f74fb
BS
7074GEN_VXFORM_ENV(vpkshss, 7, 6);
7075GEN_VXFORM_ENV(vpkswss, 7, 7);
024215b2 7076GEN_VXFORM_ENV(vpksdss, 7, 23);
1dd9ffb9 7077GEN_VXFORM(vpkpx, 7, 12);
d15f74fb
BS
7078GEN_VXFORM_ENV(vsum4ubs, 4, 24);
7079GEN_VXFORM_ENV(vsum4sbs, 4, 28);
7080GEN_VXFORM_ENV(vsum4shs, 4, 25);
7081GEN_VXFORM_ENV(vsum2sws, 4, 26);
7082GEN_VXFORM_ENV(vsumsws, 4, 30);
7083GEN_VXFORM_ENV(vaddfp, 5, 0);
7084GEN_VXFORM_ENV(vsubfp, 5, 1);
7085GEN_VXFORM_ENV(vmaxfp, 5, 16);
7086GEN_VXFORM_ENV(vminfp, 5, 17);
fab3cbe9 7087
0cbcd906 7088#define GEN_VXRFORM1(opname, name, str, opc2, opc3) \
e8eaa2c0 7089static void glue(gen_, name)(DisasContext *ctx) \
0cbcd906
AJ
7090 { \
7091 TCGv_ptr ra, rb, rd; \
7092 if (unlikely(!ctx->altivec_enabled)) { \
7093 gen_exception(ctx, POWERPC_EXCP_VPU); \
7094 return; \
7095 } \
7096 ra = gen_avr_ptr(rA(ctx->opcode)); \
7097 rb = gen_avr_ptr(rB(ctx->opcode)); \
7098 rd = gen_avr_ptr(rD(ctx->opcode)); \
d15f74fb 7099 gen_helper_##opname(cpu_env, rd, ra, rb); \
0cbcd906
AJ
7100 tcg_temp_free_ptr(ra); \
7101 tcg_temp_free_ptr(rb); \
7102 tcg_temp_free_ptr(rd); \
7103 }
7104
7105#define GEN_VXRFORM(name, opc2, opc3) \
7106 GEN_VXRFORM1(name, name, #name, opc2, opc3) \
7107 GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4)))
7108
a737d3eb
TM
7109/*
7110 * Support for Altivec instructions that use bit 31 (Rc) as an opcode
7111 * bit but also use bit 21 as an actual Rc bit. In general, thse pairs
7112 * come from different versions of the ISA, so we must also support a
7113 * pair of flags for each instruction.
7114 */
7115#define GEN_VXRFORM_DUAL(name0, flg0, flg2_0, name1, flg1, flg2_1) \
7116static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
7117{ \
7118 if ((Rc(ctx->opcode) == 0) && \
7119 ((ctx->insns_flags & flg0) || (ctx->insns_flags2 & flg2_0))) { \
7120 if (Rc21(ctx->opcode) == 0) { \
7121 gen_##name0(ctx); \
7122 } else { \
7123 gen_##name0##_(ctx); \
7124 } \
7125 } else if ((Rc(ctx->opcode) == 1) && \
7126 ((ctx->insns_flags & flg1) || (ctx->insns_flags2 & flg2_1))) { \
7127 if (Rc21(ctx->opcode) == 0) { \
7128 gen_##name1(ctx); \
7129 } else { \
7130 gen_##name1##_(ctx); \
7131 } \
7132 } else { \
7133 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
7134 } \
7135}
7136
1add6e23
AJ
7137GEN_VXRFORM(vcmpequb, 3, 0)
7138GEN_VXRFORM(vcmpequh, 3, 1)
7139GEN_VXRFORM(vcmpequw, 3, 2)
6f3dab41 7140GEN_VXRFORM(vcmpequd, 3, 3)
1add6e23
AJ
7141GEN_VXRFORM(vcmpgtsb, 3, 12)
7142GEN_VXRFORM(vcmpgtsh, 3, 13)
7143GEN_VXRFORM(vcmpgtsw, 3, 14)
6f3dab41 7144GEN_VXRFORM(vcmpgtsd, 3, 15)
1add6e23
AJ
7145GEN_VXRFORM(vcmpgtub, 3, 8)
7146GEN_VXRFORM(vcmpgtuh, 3, 9)
7147GEN_VXRFORM(vcmpgtuw, 3, 10)
6f3dab41 7148GEN_VXRFORM(vcmpgtud, 3, 11)
819ca121
AJ
7149GEN_VXRFORM(vcmpeqfp, 3, 3)
7150GEN_VXRFORM(vcmpgefp, 3, 7)
7151GEN_VXRFORM(vcmpgtfp, 3, 11)
7152GEN_VXRFORM(vcmpbfp, 3, 15)
1add6e23 7153
6f3dab41
TM
7154GEN_VXRFORM_DUAL(vcmpeqfp, PPC_ALTIVEC, PPC_NONE, \
7155 vcmpequd, PPC_NONE, PPC2_ALTIVEC_207)
7156GEN_VXRFORM_DUAL(vcmpbfp, PPC_ALTIVEC, PPC_NONE, \
7157 vcmpgtsd, PPC_NONE, PPC2_ALTIVEC_207)
7158GEN_VXRFORM_DUAL(vcmpgtfp, PPC_ALTIVEC, PPC_NONE, \
7159 vcmpgtud, PPC_NONE, PPC2_ALTIVEC_207)
7160
c026766b 7161#define GEN_VXFORM_SIMM(name, opc2, opc3) \
99e300ef 7162static void glue(gen_, name)(DisasContext *ctx) \
c026766b
AJ
7163 { \
7164 TCGv_ptr rd; \
7165 TCGv_i32 simm; \
7166 if (unlikely(!ctx->altivec_enabled)) { \
7167 gen_exception(ctx, POWERPC_EXCP_VPU); \
7168 return; \
7169 } \
7170 simm = tcg_const_i32(SIMM5(ctx->opcode)); \
7171 rd = gen_avr_ptr(rD(ctx->opcode)); \
7172 gen_helper_##name (rd, simm); \
7173 tcg_temp_free_i32(simm); \
7174 tcg_temp_free_ptr(rd); \
7175 }
7176
7177GEN_VXFORM_SIMM(vspltisb, 6, 12);
7178GEN_VXFORM_SIMM(vspltish, 6, 13);
7179GEN_VXFORM_SIMM(vspltisw, 6, 14);
7180
de5f2484 7181#define GEN_VXFORM_NOA(name, opc2, opc3) \
99e300ef 7182static void glue(gen_, name)(DisasContext *ctx) \
de5f2484
AJ
7183 { \
7184 TCGv_ptr rb, rd; \
7185 if (unlikely(!ctx->altivec_enabled)) { \
7186 gen_exception(ctx, POWERPC_EXCP_VPU); \
7187 return; \
7188 } \
7189 rb = gen_avr_ptr(rB(ctx->opcode)); \
7190 rd = gen_avr_ptr(rD(ctx->opcode)); \
7191 gen_helper_##name (rd, rb); \
7192 tcg_temp_free_ptr(rb); \
7193 tcg_temp_free_ptr(rd); \
7194 }
7195
d15f74fb
BS
7196#define GEN_VXFORM_NOA_ENV(name, opc2, opc3) \
7197static void glue(gen_, name)(DisasContext *ctx) \
7198 { \
7199 TCGv_ptr rb, rd; \
7200 \
7201 if (unlikely(!ctx->altivec_enabled)) { \
7202 gen_exception(ctx, POWERPC_EXCP_VPU); \
7203 return; \
7204 } \
7205 rb = gen_avr_ptr(rB(ctx->opcode)); \
7206 rd = gen_avr_ptr(rD(ctx->opcode)); \
7207 gen_helper_##name(cpu_env, rd, rb); \
7208 tcg_temp_free_ptr(rb); \
7209 tcg_temp_free_ptr(rd); \
7210 }
7211
6cf1c6e5
AJ
7212GEN_VXFORM_NOA(vupkhsb, 7, 8);
7213GEN_VXFORM_NOA(vupkhsh, 7, 9);
4430e076 7214GEN_VXFORM_NOA(vupkhsw, 7, 25);
6cf1c6e5
AJ
7215GEN_VXFORM_NOA(vupklsb, 7, 10);
7216GEN_VXFORM_NOA(vupklsh, 7, 11);
4430e076 7217GEN_VXFORM_NOA(vupklsw, 7, 27);
79f85c3a
AJ
7218GEN_VXFORM_NOA(vupkhpx, 7, 13);
7219GEN_VXFORM_NOA(vupklpx, 7, 15);
d15f74fb
BS
7220GEN_VXFORM_NOA_ENV(vrefp, 5, 4);
7221GEN_VXFORM_NOA_ENV(vrsqrtefp, 5, 5);
7222GEN_VXFORM_NOA_ENV(vexptefp, 5, 6);
7223GEN_VXFORM_NOA_ENV(vlogefp, 5, 7);
7224GEN_VXFORM_NOA_ENV(vrfim, 5, 8);
7225GEN_VXFORM_NOA_ENV(vrfin, 5, 9);
7226GEN_VXFORM_NOA_ENV(vrfip, 5, 10);
7227GEN_VXFORM_NOA_ENV(vrfiz, 5, 11);
79f85c3a 7228
21d21583 7229#define GEN_VXFORM_SIMM(name, opc2, opc3) \
99e300ef 7230static void glue(gen_, name)(DisasContext *ctx) \
21d21583
AJ
7231 { \
7232 TCGv_ptr rd; \
7233 TCGv_i32 simm; \
7234 if (unlikely(!ctx->altivec_enabled)) { \
7235 gen_exception(ctx, POWERPC_EXCP_VPU); \
7236 return; \
7237 } \
7238 simm = tcg_const_i32(SIMM5(ctx->opcode)); \
7239 rd = gen_avr_ptr(rD(ctx->opcode)); \
7240 gen_helper_##name (rd, simm); \
7241 tcg_temp_free_i32(simm); \
7242 tcg_temp_free_ptr(rd); \
7243 }
7244
27a4edb3 7245#define GEN_VXFORM_UIMM(name, opc2, opc3) \
99e300ef 7246static void glue(gen_, name)(DisasContext *ctx) \
27a4edb3
AJ
7247 { \
7248 TCGv_ptr rb, rd; \
7249 TCGv_i32 uimm; \
7250 if (unlikely(!ctx->altivec_enabled)) { \
7251 gen_exception(ctx, POWERPC_EXCP_VPU); \
7252 return; \
7253 } \
7254 uimm = tcg_const_i32(UIMM5(ctx->opcode)); \
7255 rb = gen_avr_ptr(rB(ctx->opcode)); \
7256 rd = gen_avr_ptr(rD(ctx->opcode)); \
7257 gen_helper_##name (rd, rb, uimm); \
7258 tcg_temp_free_i32(uimm); \
7259 tcg_temp_free_ptr(rb); \
7260 tcg_temp_free_ptr(rd); \
7261 }
7262
d15f74fb
BS
7263#define GEN_VXFORM_UIMM_ENV(name, opc2, opc3) \
7264static void glue(gen_, name)(DisasContext *ctx) \
7265 { \
7266 TCGv_ptr rb, rd; \
7267 TCGv_i32 uimm; \
7268 \
7269 if (unlikely(!ctx->altivec_enabled)) { \
7270 gen_exception(ctx, POWERPC_EXCP_VPU); \
7271 return; \
7272 } \
7273 uimm = tcg_const_i32(UIMM5(ctx->opcode)); \
7274 rb = gen_avr_ptr(rB(ctx->opcode)); \
7275 rd = gen_avr_ptr(rD(ctx->opcode)); \
7276 gen_helper_##name(cpu_env, rd, rb, uimm); \
7277 tcg_temp_free_i32(uimm); \
7278 tcg_temp_free_ptr(rb); \
7279 tcg_temp_free_ptr(rd); \
7280 }
7281
e4e6bee7
AJ
7282GEN_VXFORM_UIMM(vspltb, 6, 8);
7283GEN_VXFORM_UIMM(vsplth, 6, 9);
7284GEN_VXFORM_UIMM(vspltw, 6, 10);
d15f74fb
BS
7285GEN_VXFORM_UIMM_ENV(vcfux, 5, 12);
7286GEN_VXFORM_UIMM_ENV(vcfsx, 5, 13);
7287GEN_VXFORM_UIMM_ENV(vctuxs, 5, 14);
7288GEN_VXFORM_UIMM_ENV(vctsxs, 5, 15);
e4e6bee7 7289
99e300ef 7290static void gen_vsldoi(DisasContext *ctx)
cd633b10
AJ
7291{
7292 TCGv_ptr ra, rb, rd;
fce5ecb7 7293 TCGv_i32 sh;
cd633b10
AJ
7294 if (unlikely(!ctx->altivec_enabled)) {
7295 gen_exception(ctx, POWERPC_EXCP_VPU);
7296 return;
7297 }
7298 ra = gen_avr_ptr(rA(ctx->opcode));
7299 rb = gen_avr_ptr(rB(ctx->opcode));
7300 rd = gen_avr_ptr(rD(ctx->opcode));
7301 sh = tcg_const_i32(VSH(ctx->opcode));
7302 gen_helper_vsldoi (rd, ra, rb, sh);
7303 tcg_temp_free_ptr(ra);
7304 tcg_temp_free_ptr(rb);
7305 tcg_temp_free_ptr(rd);
fce5ecb7 7306 tcg_temp_free_i32(sh);
cd633b10
AJ
7307}
7308
707cec33 7309#define GEN_VAFORM_PAIRED(name0, name1, opc2) \
d15f74fb 7310static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
707cec33
AJ
7311 { \
7312 TCGv_ptr ra, rb, rc, rd; \
7313 if (unlikely(!ctx->altivec_enabled)) { \
7314 gen_exception(ctx, POWERPC_EXCP_VPU); \
7315 return; \
7316 } \
7317 ra = gen_avr_ptr(rA(ctx->opcode)); \
7318 rb = gen_avr_ptr(rB(ctx->opcode)); \
7319 rc = gen_avr_ptr(rC(ctx->opcode)); \
7320 rd = gen_avr_ptr(rD(ctx->opcode)); \
7321 if (Rc(ctx->opcode)) { \
d15f74fb 7322 gen_helper_##name1(cpu_env, rd, ra, rb, rc); \
707cec33 7323 } else { \
d15f74fb 7324 gen_helper_##name0(cpu_env, rd, ra, rb, rc); \
707cec33
AJ
7325 } \
7326 tcg_temp_free_ptr(ra); \
7327 tcg_temp_free_ptr(rb); \
7328 tcg_temp_free_ptr(rc); \
7329 tcg_temp_free_ptr(rd); \
7330 }
7331
b161ae27
AJ
7332GEN_VAFORM_PAIRED(vmhaddshs, vmhraddshs, 16)
7333
99e300ef 7334static void gen_vmladduhm(DisasContext *ctx)
bcd2ee23
AJ
7335{
7336 TCGv_ptr ra, rb, rc, rd;
7337 if (unlikely(!ctx->altivec_enabled)) {
7338 gen_exception(ctx, POWERPC_EXCP_VPU);
7339 return;
7340 }
7341 ra = gen_avr_ptr(rA(ctx->opcode));
7342 rb = gen_avr_ptr(rB(ctx->opcode));
7343 rc = gen_avr_ptr(rC(ctx->opcode));
7344 rd = gen_avr_ptr(rD(ctx->opcode));
7345 gen_helper_vmladduhm(rd, ra, rb, rc);
7346 tcg_temp_free_ptr(ra);
7347 tcg_temp_free_ptr(rb);
7348 tcg_temp_free_ptr(rc);
7349 tcg_temp_free_ptr(rd);
7350}
7351
b04ae981 7352GEN_VAFORM_PAIRED(vmsumubm, vmsummbm, 18)
4d9903b6 7353GEN_VAFORM_PAIRED(vmsumuhm, vmsumuhs, 19)
eae07261 7354GEN_VAFORM_PAIRED(vmsumshm, vmsumshs, 20)
d1258698 7355GEN_VAFORM_PAIRED(vsel, vperm, 21)
35cf7c7e 7356GEN_VAFORM_PAIRED(vmaddfp, vnmsubfp, 23)
b04ae981 7357
f293f04a
TM
7358GEN_VXFORM_NOA(vclzb, 1, 28)
7359GEN_VXFORM_NOA(vclzh, 1, 29)
7360GEN_VXFORM_NOA(vclzw, 1, 30)
7361GEN_VXFORM_NOA(vclzd, 1, 31)
e13500b3
TM
7362GEN_VXFORM_NOA(vpopcntb, 1, 28)
7363GEN_VXFORM_NOA(vpopcnth, 1, 29)
7364GEN_VXFORM_NOA(vpopcntw, 1, 30)
7365GEN_VXFORM_NOA(vpopcntd, 1, 31)
7366GEN_VXFORM_DUAL(vclzb, PPC_NONE, PPC2_ALTIVEC_207, \
7367 vpopcntb, PPC_NONE, PPC2_ALTIVEC_207)
7368GEN_VXFORM_DUAL(vclzh, PPC_NONE, PPC2_ALTIVEC_207, \
7369 vpopcnth, PPC_NONE, PPC2_ALTIVEC_207)
7370GEN_VXFORM_DUAL(vclzw, PPC_NONE, PPC2_ALTIVEC_207, \
7371 vpopcntw, PPC_NONE, PPC2_ALTIVEC_207)
7372GEN_VXFORM_DUAL(vclzd, PPC_NONE, PPC2_ALTIVEC_207, \
7373 vpopcntd, PPC_NONE, PPC2_ALTIVEC_207)
4d82038e 7374GEN_VXFORM(vbpermq, 6, 21);
f1064f61 7375GEN_VXFORM_NOA(vgbbd, 6, 20);
b8476fc7
TM
7376GEN_VXFORM(vpmsumb, 4, 16)
7377GEN_VXFORM(vpmsumh, 4, 17)
7378GEN_VXFORM(vpmsumw, 4, 18)
7379GEN_VXFORM(vpmsumd, 4, 19)
e13500b3 7380
e8f7b27b
TM
7381#define GEN_BCD(op) \
7382static void gen_##op(DisasContext *ctx) \
7383{ \
7384 TCGv_ptr ra, rb, rd; \
7385 TCGv_i32 ps; \
7386 \
7387 if (unlikely(!ctx->altivec_enabled)) { \
7388 gen_exception(ctx, POWERPC_EXCP_VPU); \
7389 return; \
7390 } \
7391 \
7392 ra = gen_avr_ptr(rA(ctx->opcode)); \
7393 rb = gen_avr_ptr(rB(ctx->opcode)); \
7394 rd = gen_avr_ptr(rD(ctx->opcode)); \
7395 \
7396 ps = tcg_const_i32((ctx->opcode & 0x200) != 0); \
7397 \
7398 gen_helper_##op(cpu_crf[6], rd, ra, rb, ps); \
7399 \
7400 tcg_temp_free_ptr(ra); \
7401 tcg_temp_free_ptr(rb); \
7402 tcg_temp_free_ptr(rd); \
7403 tcg_temp_free_i32(ps); \
7404}
7405
7406GEN_BCD(bcdadd)
7407GEN_BCD(bcdsub)
7408
7409GEN_VXFORM_DUAL(vsububm, PPC_ALTIVEC, PPC_NONE, \
7410 bcdadd, PPC_NONE, PPC2_ALTIVEC_207)
7411GEN_VXFORM_DUAL(vsububs, PPC_ALTIVEC, PPC_NONE, \
7412 bcdadd, PPC_NONE, PPC2_ALTIVEC_207)
7413GEN_VXFORM_DUAL(vsubuhm, PPC_ALTIVEC, PPC_NONE, \
7414 bcdsub, PPC_NONE, PPC2_ALTIVEC_207)
7415GEN_VXFORM_DUAL(vsubuhs, PPC_ALTIVEC, PPC_NONE, \
7416 bcdsub, PPC_NONE, PPC2_ALTIVEC_207)
7417
557d52fa
TM
7418static void gen_vsbox(DisasContext *ctx)
7419{
7420 TCGv_ptr ra, rd;
7421 if (unlikely(!ctx->altivec_enabled)) {
7422 gen_exception(ctx, POWERPC_EXCP_VPU);
7423 return;
7424 }
7425 ra = gen_avr_ptr(rA(ctx->opcode));
7426 rd = gen_avr_ptr(rD(ctx->opcode));
7427 gen_helper_vsbox(rd, ra);
7428 tcg_temp_free_ptr(ra);
7429 tcg_temp_free_ptr(rd);
7430}
7431
7432GEN_VXFORM(vcipher, 4, 20)
7433GEN_VXFORM(vcipherlast, 4, 20)
7434GEN_VXFORM(vncipher, 4, 21)
7435GEN_VXFORM(vncipherlast, 4, 21)
7436
7437GEN_VXFORM_DUAL(vcipher, PPC_NONE, PPC2_ALTIVEC_207,
7438 vcipherlast, PPC_NONE, PPC2_ALTIVEC_207)
7439GEN_VXFORM_DUAL(vncipher, PPC_NONE, PPC2_ALTIVEC_207,
7440 vncipherlast, PPC_NONE, PPC2_ALTIVEC_207)
7441
57354f8f
TM
7442#define VSHASIGMA(op) \
7443static void gen_##op(DisasContext *ctx) \
7444{ \
7445 TCGv_ptr ra, rd; \
7446 TCGv_i32 st_six; \
7447 if (unlikely(!ctx->altivec_enabled)) { \
7448 gen_exception(ctx, POWERPC_EXCP_VPU); \
7449 return; \
7450 } \
7451 ra = gen_avr_ptr(rA(ctx->opcode)); \
7452 rd = gen_avr_ptr(rD(ctx->opcode)); \
7453 st_six = tcg_const_i32(rB(ctx->opcode)); \
7454 gen_helper_##op(rd, ra, st_six); \
7455 tcg_temp_free_ptr(ra); \
7456 tcg_temp_free_ptr(rd); \
7457 tcg_temp_free_i32(st_six); \
7458}
7459
7460VSHASIGMA(vshasigmaw)
7461VSHASIGMA(vshasigmad)
7462
ac174549
TM
7463GEN_VXFORM3(vpermxor, 22, 0xFF)
7464GEN_VXFORM_DUAL(vsldoi, PPC_ALTIVEC, PPC_NONE,
7465 vpermxor, PPC_NONE, PPC2_ALTIVEC_207)
7466
472b24ce
TM
7467/*** VSX extension ***/
7468
7469static inline TCGv_i64 cpu_vsrh(int n)
7470{
7471 if (n < 32) {
7472 return cpu_fpr[n];
7473 } else {
7474 return cpu_avrh[n-32];
7475 }
7476}
7477
7478static inline TCGv_i64 cpu_vsrl(int n)
7479{
7480 if (n < 32) {
7481 return cpu_vsr[n];
7482 } else {
7483 return cpu_avrl[n-32];
7484 }
7485}
7486
e072fe79
TM
7487#define VSX_LOAD_SCALAR(name, operation) \
7488static void gen_##name(DisasContext *ctx) \
7489{ \
7490 TCGv EA; \
7491 if (unlikely(!ctx->vsx_enabled)) { \
7492 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7493 return; \
7494 } \
7495 gen_set_access_type(ctx, ACCESS_INT); \
7496 EA = tcg_temp_new(); \
7497 gen_addr_reg_index(ctx, EA); \
7498 gen_qemu_##operation(ctx, cpu_vsrh(xT(ctx->opcode)), EA); \
7499 /* NOTE: cpu_vsrl is undefined */ \
7500 tcg_temp_free(EA); \
7501}
7502
7503VSX_LOAD_SCALAR(lxsdx, ld64)
cac7f0ba
TM
7504VSX_LOAD_SCALAR(lxsiwax, ld32s_i64)
7505VSX_LOAD_SCALAR(lxsiwzx, ld32u_i64)
7506VSX_LOAD_SCALAR(lxsspx, ld32fs)
fa1832d7 7507
304af367
TM
7508static void gen_lxvd2x(DisasContext *ctx)
7509{
7510 TCGv EA;
7511 if (unlikely(!ctx->vsx_enabled)) {
7512 gen_exception(ctx, POWERPC_EXCP_VSXU);
7513 return;
7514 }
7515 gen_set_access_type(ctx, ACCESS_INT);
7516 EA = tcg_temp_new();
7517 gen_addr_reg_index(ctx, EA);
7518 gen_qemu_ld64(ctx, cpu_vsrh(xT(ctx->opcode)), EA);
7519 tcg_gen_addi_tl(EA, EA, 8);
7520 gen_qemu_ld64(ctx, cpu_vsrl(xT(ctx->opcode)), EA);
7521 tcg_temp_free(EA);
7522}
7523
ca03b467
TM
7524static void gen_lxvdsx(DisasContext *ctx)
7525{
7526 TCGv EA;
7527 if (unlikely(!ctx->vsx_enabled)) {
7528 gen_exception(ctx, POWERPC_EXCP_VSXU);
7529 return;
7530 }
7531 gen_set_access_type(ctx, ACCESS_INT);
7532 EA = tcg_temp_new();
7533 gen_addr_reg_index(ctx, EA);
7534 gen_qemu_ld64(ctx, cpu_vsrh(xT(ctx->opcode)), EA);
f976b09e 7535 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), cpu_vsrh(xT(ctx->opcode)));
ca03b467
TM
7536 tcg_temp_free(EA);
7537}
7538
897e61d1
TM
7539static void gen_lxvw4x(DisasContext *ctx)
7540{
f976b09e
AG
7541 TCGv EA;
7542 TCGv_i64 tmp;
897e61d1
TM
7543 TCGv_i64 xth = cpu_vsrh(xT(ctx->opcode));
7544 TCGv_i64 xtl = cpu_vsrl(xT(ctx->opcode));
7545 if (unlikely(!ctx->vsx_enabled)) {
7546 gen_exception(ctx, POWERPC_EXCP_VSXU);
7547 return;
7548 }
7549 gen_set_access_type(ctx, ACCESS_INT);
7550 EA = tcg_temp_new();
f976b09e
AG
7551 tmp = tcg_temp_new_i64();
7552
897e61d1 7553 gen_addr_reg_index(ctx, EA);
f976b09e 7554 gen_qemu_ld32u_i64(ctx, tmp, EA);
897e61d1 7555 tcg_gen_addi_tl(EA, EA, 4);
f976b09e 7556 gen_qemu_ld32u_i64(ctx, xth, EA);
897e61d1
TM
7557 tcg_gen_deposit_i64(xth, xth, tmp, 32, 32);
7558
7559 tcg_gen_addi_tl(EA, EA, 4);
f976b09e 7560 gen_qemu_ld32u_i64(ctx, tmp, EA);
897e61d1 7561 tcg_gen_addi_tl(EA, EA, 4);
f976b09e 7562 gen_qemu_ld32u_i64(ctx, xtl, EA);
897e61d1
TM
7563 tcg_gen_deposit_i64(xtl, xtl, tmp, 32, 32);
7564
7565 tcg_temp_free(EA);
f976b09e 7566 tcg_temp_free_i64(tmp);
897e61d1
TM
7567}
7568
f026da78
TM
7569#define VSX_STORE_SCALAR(name, operation) \
7570static void gen_##name(DisasContext *ctx) \
7571{ \
7572 TCGv EA; \
7573 if (unlikely(!ctx->vsx_enabled)) { \
7574 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7575 return; \
7576 } \
7577 gen_set_access_type(ctx, ACCESS_INT); \
7578 EA = tcg_temp_new(); \
7579 gen_addr_reg_index(ctx, EA); \
7580 gen_qemu_##operation(ctx, cpu_vsrh(xS(ctx->opcode)), EA); \
7581 tcg_temp_free(EA); \
9231ba9e
TM
7582}
7583
f026da78 7584VSX_STORE_SCALAR(stxsdx, st64)
e16a626b
TM
7585VSX_STORE_SCALAR(stxsiwx, st32_i64)
7586VSX_STORE_SCALAR(stxsspx, st32fs)
f026da78 7587
fbed2478
TM
7588static void gen_stxvd2x(DisasContext *ctx)
7589{
7590 TCGv EA;
7591 if (unlikely(!ctx->vsx_enabled)) {
7592 gen_exception(ctx, POWERPC_EXCP_VSXU);
7593 return;
7594 }
7595 gen_set_access_type(ctx, ACCESS_INT);
7596 EA = tcg_temp_new();
7597 gen_addr_reg_index(ctx, EA);
7598 gen_qemu_st64(ctx, cpu_vsrh(xS(ctx->opcode)), EA);
7599 tcg_gen_addi_tl(EA, EA, 8);
7600 gen_qemu_st64(ctx, cpu_vsrl(xS(ctx->opcode)), EA);
7601 tcg_temp_free(EA);
7602}
7603
86e61ce3
TM
7604static void gen_stxvw4x(DisasContext *ctx)
7605{
f976b09e
AG
7606 TCGv_i64 tmp;
7607 TCGv EA;
86e61ce3
TM
7608 if (unlikely(!ctx->vsx_enabled)) {
7609 gen_exception(ctx, POWERPC_EXCP_VSXU);
7610 return;
7611 }
7612 gen_set_access_type(ctx, ACCESS_INT);
7613 EA = tcg_temp_new();
7614 gen_addr_reg_index(ctx, EA);
f976b09e 7615 tmp = tcg_temp_new_i64();
86e61ce3
TM
7616
7617 tcg_gen_shri_i64(tmp, cpu_vsrh(xS(ctx->opcode)), 32);
f976b09e 7618 gen_qemu_st32_i64(ctx, tmp, EA);
86e61ce3 7619 tcg_gen_addi_tl(EA, EA, 4);
f976b09e 7620 gen_qemu_st32_i64(ctx, cpu_vsrh(xS(ctx->opcode)), EA);
86e61ce3
TM
7621
7622 tcg_gen_shri_i64(tmp, cpu_vsrl(xS(ctx->opcode)), 32);
7623 tcg_gen_addi_tl(EA, EA, 4);
f976b09e 7624 gen_qemu_st32_i64(ctx, tmp, EA);
86e61ce3 7625 tcg_gen_addi_tl(EA, EA, 4);
f976b09e 7626 gen_qemu_st32_i64(ctx, cpu_vsrl(xS(ctx->opcode)), EA);
86e61ce3
TM
7627
7628 tcg_temp_free(EA);
f976b09e 7629 tcg_temp_free_i64(tmp);
86e61ce3
TM
7630}
7631
f5c0f7f9
TM
7632#define MV_VSRW(name, tcgop1, tcgop2, target, source) \
7633static void gen_##name(DisasContext *ctx) \
7634{ \
7635 if (xS(ctx->opcode) < 32) { \
7636 if (unlikely(!ctx->fpu_enabled)) { \
7637 gen_exception(ctx, POWERPC_EXCP_FPU); \
7638 return; \
7639 } \
7640 } else { \
7641 if (unlikely(!ctx->altivec_enabled)) { \
7642 gen_exception(ctx, POWERPC_EXCP_VPU); \
7643 return; \
7644 } \
7645 } \
7646 TCGv_i64 tmp = tcg_temp_new_i64(); \
7647 tcg_gen_##tcgop1(tmp, source); \
7648 tcg_gen_##tcgop2(target, tmp); \
7649 tcg_temp_free_i64(tmp); \
7650}
7651
7652
7653MV_VSRW(mfvsrwz, ext32u_i64, trunc_i64_tl, cpu_gpr[rA(ctx->opcode)], \
7654 cpu_vsrh(xS(ctx->opcode)))
7655MV_VSRW(mtvsrwa, extu_tl_i64, ext32s_i64, cpu_vsrh(xT(ctx->opcode)), \
7656 cpu_gpr[rA(ctx->opcode)])
7657MV_VSRW(mtvsrwz, extu_tl_i64, ext32u_i64, cpu_vsrh(xT(ctx->opcode)), \
7658 cpu_gpr[rA(ctx->opcode)])
7659
7660#if defined(TARGET_PPC64)
7661#define MV_VSRD(name, target, source) \
7662static void gen_##name(DisasContext *ctx) \
7663{ \
7664 if (xS(ctx->opcode) < 32) { \
7665 if (unlikely(!ctx->fpu_enabled)) { \
7666 gen_exception(ctx, POWERPC_EXCP_FPU); \
7667 return; \
7668 } \
7669 } else { \
7670 if (unlikely(!ctx->altivec_enabled)) { \
7671 gen_exception(ctx, POWERPC_EXCP_VPU); \
7672 return; \
7673 } \
7674 } \
7675 tcg_gen_mov_i64(target, source); \
7676}
7677
7678MV_VSRD(mfvsrd, cpu_gpr[rA(ctx->opcode)], cpu_vsrh(xS(ctx->opcode)))
7679MV_VSRD(mtvsrd, cpu_vsrh(xT(ctx->opcode)), cpu_gpr[rA(ctx->opcode)])
7680
7681#endif
7682
cd73f2c9
TM
7683static void gen_xxpermdi(DisasContext *ctx)
7684{
7685 if (unlikely(!ctx->vsx_enabled)) {
7686 gen_exception(ctx, POWERPC_EXCP_VSXU);
7687 return;
7688 }
7689
f5bc1bfa
TM
7690 if (unlikely((xT(ctx->opcode) == xA(ctx->opcode)) ||
7691 (xT(ctx->opcode) == xB(ctx->opcode)))) {
7692 TCGv_i64 xh, xl;
7693
7694 xh = tcg_temp_new_i64();
7695 xl = tcg_temp_new_i64();
7696
7697 if ((DM(ctx->opcode) & 2) == 0) {
7698 tcg_gen_mov_i64(xh, cpu_vsrh(xA(ctx->opcode)));
7699 } else {
7700 tcg_gen_mov_i64(xh, cpu_vsrl(xA(ctx->opcode)));
7701 }
7702 if ((DM(ctx->opcode) & 1) == 0) {
7703 tcg_gen_mov_i64(xl, cpu_vsrh(xB(ctx->opcode)));
7704 } else {
7705 tcg_gen_mov_i64(xl, cpu_vsrl(xB(ctx->opcode)));
7706 }
7707
7708 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xh);
7709 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), xl);
7710
7711 tcg_temp_free_i64(xh);
7712 tcg_temp_free_i64(xl);
cd73f2c9 7713 } else {
f5bc1bfa
TM
7714 if ((DM(ctx->opcode) & 2) == 0) {
7715 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), cpu_vsrh(xA(ctx->opcode)));
7716 } else {
7717 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), cpu_vsrl(xA(ctx->opcode)));
7718 }
7719 if ((DM(ctx->opcode) & 1) == 0) {
7720 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), cpu_vsrh(xB(ctx->opcode)));
7721 } else {
7722 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), cpu_vsrl(xB(ctx->opcode)));
7723 }
cd73f2c9
TM
7724 }
7725}
7726
df020ce0
TM
7727#define OP_ABS 1
7728#define OP_NABS 2
7729#define OP_NEG 3
7730#define OP_CPSGN 4
e5d7d2b0
PM
7731#define SGN_MASK_DP 0x8000000000000000ull
7732#define SGN_MASK_SP 0x8000000080000000ull
df020ce0
TM
7733
7734#define VSX_SCALAR_MOVE(name, op, sgn_mask) \
7735static void glue(gen_, name)(DisasContext * ctx) \
7736 { \
7737 TCGv_i64 xb, sgm; \
7738 if (unlikely(!ctx->vsx_enabled)) { \
7739 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7740 return; \
7741 } \
f976b09e
AG
7742 xb = tcg_temp_new_i64(); \
7743 sgm = tcg_temp_new_i64(); \
df020ce0
TM
7744 tcg_gen_mov_i64(xb, cpu_vsrh(xB(ctx->opcode))); \
7745 tcg_gen_movi_i64(sgm, sgn_mask); \
7746 switch (op) { \
7747 case OP_ABS: { \
7748 tcg_gen_andc_i64(xb, xb, sgm); \
7749 break; \
7750 } \
7751 case OP_NABS: { \
7752 tcg_gen_or_i64(xb, xb, sgm); \
7753 break; \
7754 } \
7755 case OP_NEG: { \
7756 tcg_gen_xor_i64(xb, xb, sgm); \
7757 break; \
7758 } \
7759 case OP_CPSGN: { \
f976b09e 7760 TCGv_i64 xa = tcg_temp_new_i64(); \
df020ce0
TM
7761 tcg_gen_mov_i64(xa, cpu_vsrh(xA(ctx->opcode))); \
7762 tcg_gen_and_i64(xa, xa, sgm); \
7763 tcg_gen_andc_i64(xb, xb, sgm); \
7764 tcg_gen_or_i64(xb, xb, xa); \
f976b09e 7765 tcg_temp_free_i64(xa); \
df020ce0
TM
7766 break; \
7767 } \
7768 } \
7769 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xb); \
f976b09e
AG
7770 tcg_temp_free_i64(xb); \
7771 tcg_temp_free_i64(sgm); \
df020ce0
TM
7772 }
7773
7774VSX_SCALAR_MOVE(xsabsdp, OP_ABS, SGN_MASK_DP)
7775VSX_SCALAR_MOVE(xsnabsdp, OP_NABS, SGN_MASK_DP)
7776VSX_SCALAR_MOVE(xsnegdp, OP_NEG, SGN_MASK_DP)
7777VSX_SCALAR_MOVE(xscpsgndp, OP_CPSGN, SGN_MASK_DP)
7778
be574920
TM
7779#define VSX_VECTOR_MOVE(name, op, sgn_mask) \
7780static void glue(gen_, name)(DisasContext * ctx) \
7781 { \
7782 TCGv_i64 xbh, xbl, sgm; \
7783 if (unlikely(!ctx->vsx_enabled)) { \
7784 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7785 return; \
7786 } \
f976b09e
AG
7787 xbh = tcg_temp_new_i64(); \
7788 xbl = tcg_temp_new_i64(); \
7789 sgm = tcg_temp_new_i64(); \
be574920
TM
7790 tcg_gen_mov_i64(xbh, cpu_vsrh(xB(ctx->opcode))); \
7791 tcg_gen_mov_i64(xbl, cpu_vsrl(xB(ctx->opcode))); \
7792 tcg_gen_movi_i64(sgm, sgn_mask); \
7793 switch (op) { \
7794 case OP_ABS: { \
7795 tcg_gen_andc_i64(xbh, xbh, sgm); \
7796 tcg_gen_andc_i64(xbl, xbl, sgm); \
7797 break; \
7798 } \
7799 case OP_NABS: { \
7800 tcg_gen_or_i64(xbh, xbh, sgm); \
7801 tcg_gen_or_i64(xbl, xbl, sgm); \
7802 break; \
7803 } \
7804 case OP_NEG: { \
7805 tcg_gen_xor_i64(xbh, xbh, sgm); \
7806 tcg_gen_xor_i64(xbl, xbl, sgm); \
7807 break; \
7808 } \
7809 case OP_CPSGN: { \
f976b09e
AG
7810 TCGv_i64 xah = tcg_temp_new_i64(); \
7811 TCGv_i64 xal = tcg_temp_new_i64(); \
be574920
TM
7812 tcg_gen_mov_i64(xah, cpu_vsrh(xA(ctx->opcode))); \
7813 tcg_gen_mov_i64(xal, cpu_vsrl(xA(ctx->opcode))); \
7814 tcg_gen_and_i64(xah, xah, sgm); \
7815 tcg_gen_and_i64(xal, xal, sgm); \
7816 tcg_gen_andc_i64(xbh, xbh, sgm); \
7817 tcg_gen_andc_i64(xbl, xbl, sgm); \
7818 tcg_gen_or_i64(xbh, xbh, xah); \
7819 tcg_gen_or_i64(xbl, xbl, xal); \
f976b09e
AG
7820 tcg_temp_free_i64(xah); \
7821 tcg_temp_free_i64(xal); \
be574920
TM
7822 break; \
7823 } \
7824 } \
7825 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xbh); \
7826 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), xbl); \
f976b09e
AG
7827 tcg_temp_free_i64(xbh); \
7828 tcg_temp_free_i64(xbl); \
7829 tcg_temp_free_i64(sgm); \
be574920
TM
7830 }
7831
7832VSX_VECTOR_MOVE(xvabsdp, OP_ABS, SGN_MASK_DP)
7833VSX_VECTOR_MOVE(xvnabsdp, OP_NABS, SGN_MASK_DP)
7834VSX_VECTOR_MOVE(xvnegdp, OP_NEG, SGN_MASK_DP)
7835VSX_VECTOR_MOVE(xvcpsgndp, OP_CPSGN, SGN_MASK_DP)
7836VSX_VECTOR_MOVE(xvabssp, OP_ABS, SGN_MASK_SP)
7837VSX_VECTOR_MOVE(xvnabssp, OP_NABS, SGN_MASK_SP)
7838VSX_VECTOR_MOVE(xvnegsp, OP_NEG, SGN_MASK_SP)
7839VSX_VECTOR_MOVE(xvcpsgnsp, OP_CPSGN, SGN_MASK_SP)
7840
3c3cbbdc
TM
7841#define GEN_VSX_HELPER_2(name, op1, op2, inval, type) \
7842static void gen_##name(DisasContext * ctx) \
7843{ \
7844 TCGv_i32 opc; \
7845 if (unlikely(!ctx->vsx_enabled)) { \
7846 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7847 return; \
7848 } \
7849 /* NIP cannot be restored if the memory exception comes from an helper */ \
7850 gen_update_nip(ctx, ctx->nip - 4); \
7851 opc = tcg_const_i32(ctx->opcode); \
7852 gen_helper_##name(cpu_env, opc); \
7853 tcg_temp_free_i32(opc); \
7854}
be574920 7855
3d1140bf
TM
7856#define GEN_VSX_HELPER_XT_XB_ENV(name, op1, op2, inval, type) \
7857static void gen_##name(DisasContext * ctx) \
7858{ \
7859 if (unlikely(!ctx->vsx_enabled)) { \
7860 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7861 return; \
7862 } \
7863 /* NIP cannot be restored if the exception comes */ \
7864 /* from a helper. */ \
7865 gen_update_nip(ctx, ctx->nip - 4); \
7866 \
7867 gen_helper_##name(cpu_vsrh(xT(ctx->opcode)), cpu_env, \
7868 cpu_vsrh(xB(ctx->opcode))); \
7869}
7870
ee6e02c0
TM
7871GEN_VSX_HELPER_2(xsadddp, 0x00, 0x04, 0, PPC2_VSX)
7872GEN_VSX_HELPER_2(xssubdp, 0x00, 0x05, 0, PPC2_VSX)
5e591d88 7873GEN_VSX_HELPER_2(xsmuldp, 0x00, 0x06, 0, PPC2_VSX)
4b98eeef 7874GEN_VSX_HELPER_2(xsdivdp, 0x00, 0x07, 0, PPC2_VSX)
2009227f 7875GEN_VSX_HELPER_2(xsredp, 0x14, 0x05, 0, PPC2_VSX)
d32404fe 7876GEN_VSX_HELPER_2(xssqrtdp, 0x16, 0x04, 0, PPC2_VSX)
d3f9df8f 7877GEN_VSX_HELPER_2(xsrsqrtedp, 0x14, 0x04, 0, PPC2_VSX)
bc80838f 7878GEN_VSX_HELPER_2(xstdivdp, 0x14, 0x07, 0, PPC2_VSX)
5cb151ac 7879GEN_VSX_HELPER_2(xstsqrtdp, 0x14, 0x06, 0, PPC2_VSX)
595c6eef
TM
7880GEN_VSX_HELPER_2(xsmaddadp, 0x04, 0x04, 0, PPC2_VSX)
7881GEN_VSX_HELPER_2(xsmaddmdp, 0x04, 0x05, 0, PPC2_VSX)
7882GEN_VSX_HELPER_2(xsmsubadp, 0x04, 0x06, 0, PPC2_VSX)
7883GEN_VSX_HELPER_2(xsmsubmdp, 0x04, 0x07, 0, PPC2_VSX)
7884GEN_VSX_HELPER_2(xsnmaddadp, 0x04, 0x14, 0, PPC2_VSX)
7885GEN_VSX_HELPER_2(xsnmaddmdp, 0x04, 0x15, 0, PPC2_VSX)
7886GEN_VSX_HELPER_2(xsnmsubadp, 0x04, 0x16, 0, PPC2_VSX)
7887GEN_VSX_HELPER_2(xsnmsubmdp, 0x04, 0x17, 0, PPC2_VSX)
4f17e9c7
TM
7888GEN_VSX_HELPER_2(xscmpodp, 0x0C, 0x05, 0, PPC2_VSX)
7889GEN_VSX_HELPER_2(xscmpudp, 0x0C, 0x04, 0, PPC2_VSX)
959e9c9d
TM
7890GEN_VSX_HELPER_2(xsmaxdp, 0x00, 0x14, 0, PPC2_VSX)
7891GEN_VSX_HELPER_2(xsmindp, 0x00, 0x15, 0, PPC2_VSX)
ed8ac568 7892GEN_VSX_HELPER_2(xscvdpsp, 0x12, 0x10, 0, PPC2_VSX)
7ee19fb9 7893GEN_VSX_HELPER_XT_XB_ENV(xscvdpspn, 0x16, 0x10, 0, PPC2_VSX207)
ed8ac568 7894GEN_VSX_HELPER_2(xscvspdp, 0x12, 0x14, 0, PPC2_VSX)
7ee19fb9 7895GEN_VSX_HELPER_XT_XB_ENV(xscvspdpn, 0x16, 0x14, 0, PPC2_VSX207)
5177d2ca
TM
7896GEN_VSX_HELPER_2(xscvdpsxds, 0x10, 0x15, 0, PPC2_VSX)
7897GEN_VSX_HELPER_2(xscvdpsxws, 0x10, 0x05, 0, PPC2_VSX)
7898GEN_VSX_HELPER_2(xscvdpuxds, 0x10, 0x14, 0, PPC2_VSX)
7899GEN_VSX_HELPER_2(xscvdpuxws, 0x10, 0x04, 0, PPC2_VSX)
7900GEN_VSX_HELPER_2(xscvsxddp, 0x10, 0x17, 0, PPC2_VSX)
7901GEN_VSX_HELPER_2(xscvuxddp, 0x10, 0x16, 0, PPC2_VSX)
88e33d08
TM
7902GEN_VSX_HELPER_2(xsrdpi, 0x12, 0x04, 0, PPC2_VSX)
7903GEN_VSX_HELPER_2(xsrdpic, 0x16, 0x06, 0, PPC2_VSX)
7904GEN_VSX_HELPER_2(xsrdpim, 0x12, 0x07, 0, PPC2_VSX)
7905GEN_VSX_HELPER_2(xsrdpip, 0x12, 0x06, 0, PPC2_VSX)
7906GEN_VSX_HELPER_2(xsrdpiz, 0x12, 0x05, 0, PPC2_VSX)
3d1140bf 7907GEN_VSX_HELPER_XT_XB_ENV(xsrsp, 0x12, 0x11, 0, PPC2_VSX207)
ee6e02c0 7908
3fd0aadf
TM
7909GEN_VSX_HELPER_2(xsaddsp, 0x00, 0x00, 0, PPC2_VSX207)
7910GEN_VSX_HELPER_2(xssubsp, 0x00, 0x01, 0, PPC2_VSX207)
ab9408a2 7911GEN_VSX_HELPER_2(xsmulsp, 0x00, 0x02, 0, PPC2_VSX207)
b24d0b47 7912GEN_VSX_HELPER_2(xsdivsp, 0x00, 0x03, 0, PPC2_VSX207)
2c0c52ae 7913GEN_VSX_HELPER_2(xsresp, 0x14, 0x01, 0, PPC2_VSX207)
cea4e574 7914GEN_VSX_HELPER_2(xssqrtsp, 0x16, 0x00, 0, PPC2_VSX207)
968e76bc 7915GEN_VSX_HELPER_2(xsrsqrtesp, 0x14, 0x00, 0, PPC2_VSX207)
f53f81e0
TM
7916GEN_VSX_HELPER_2(xsmaddasp, 0x04, 0x00, 0, PPC2_VSX207)
7917GEN_VSX_HELPER_2(xsmaddmsp, 0x04, 0x01, 0, PPC2_VSX207)
7918GEN_VSX_HELPER_2(xsmsubasp, 0x04, 0x02, 0, PPC2_VSX207)
7919GEN_VSX_HELPER_2(xsmsubmsp, 0x04, 0x03, 0, PPC2_VSX207)
7920GEN_VSX_HELPER_2(xsnmaddasp, 0x04, 0x10, 0, PPC2_VSX207)
7921GEN_VSX_HELPER_2(xsnmaddmsp, 0x04, 0x11, 0, PPC2_VSX207)
7922GEN_VSX_HELPER_2(xsnmsubasp, 0x04, 0x12, 0, PPC2_VSX207)
7923GEN_VSX_HELPER_2(xsnmsubmsp, 0x04, 0x13, 0, PPC2_VSX207)
74698350
TM
7924GEN_VSX_HELPER_2(xscvsxdsp, 0x10, 0x13, 0, PPC2_VSX207)
7925GEN_VSX_HELPER_2(xscvuxdsp, 0x10, 0x12, 0, PPC2_VSX207)
3fd0aadf 7926
ee6e02c0
TM
7927GEN_VSX_HELPER_2(xvadddp, 0x00, 0x0C, 0, PPC2_VSX)
7928GEN_VSX_HELPER_2(xvsubdp, 0x00, 0x0D, 0, PPC2_VSX)
5e591d88 7929GEN_VSX_HELPER_2(xvmuldp, 0x00, 0x0E, 0, PPC2_VSX)
4b98eeef 7930GEN_VSX_HELPER_2(xvdivdp, 0x00, 0x0F, 0, PPC2_VSX)
2009227f 7931GEN_VSX_HELPER_2(xvredp, 0x14, 0x0D, 0, PPC2_VSX)
d32404fe 7932GEN_VSX_HELPER_2(xvsqrtdp, 0x16, 0x0C, 0, PPC2_VSX)
d3f9df8f 7933GEN_VSX_HELPER_2(xvrsqrtedp, 0x14, 0x0C, 0, PPC2_VSX)
bc80838f 7934GEN_VSX_HELPER_2(xvtdivdp, 0x14, 0x0F, 0, PPC2_VSX)
5cb151ac 7935GEN_VSX_HELPER_2(xvtsqrtdp, 0x14, 0x0E, 0, PPC2_VSX)
595c6eef
TM
7936GEN_VSX_HELPER_2(xvmaddadp, 0x04, 0x0C, 0, PPC2_VSX)
7937GEN_VSX_HELPER_2(xvmaddmdp, 0x04, 0x0D, 0, PPC2_VSX)
7938GEN_VSX_HELPER_2(xvmsubadp, 0x04, 0x0E, 0, PPC2_VSX)
7939GEN_VSX_HELPER_2(xvmsubmdp, 0x04, 0x0F, 0, PPC2_VSX)
7940GEN_VSX_HELPER_2(xvnmaddadp, 0x04, 0x1C, 0, PPC2_VSX)
7941GEN_VSX_HELPER_2(xvnmaddmdp, 0x04, 0x1D, 0, PPC2_VSX)
7942GEN_VSX_HELPER_2(xvnmsubadp, 0x04, 0x1E, 0, PPC2_VSX)
7943GEN_VSX_HELPER_2(xvnmsubmdp, 0x04, 0x1F, 0, PPC2_VSX)
959e9c9d
TM
7944GEN_VSX_HELPER_2(xvmaxdp, 0x00, 0x1C, 0, PPC2_VSX)
7945GEN_VSX_HELPER_2(xvmindp, 0x00, 0x1D, 0, PPC2_VSX)
354a6dec
TM
7946GEN_VSX_HELPER_2(xvcmpeqdp, 0x0C, 0x0C, 0, PPC2_VSX)
7947GEN_VSX_HELPER_2(xvcmpgtdp, 0x0C, 0x0D, 0, PPC2_VSX)
7948GEN_VSX_HELPER_2(xvcmpgedp, 0x0C, 0x0E, 0, PPC2_VSX)
ed8ac568 7949GEN_VSX_HELPER_2(xvcvdpsp, 0x12, 0x18, 0, PPC2_VSX)
5177d2ca
TM
7950GEN_VSX_HELPER_2(xvcvdpsxds, 0x10, 0x1D, 0, PPC2_VSX)
7951GEN_VSX_HELPER_2(xvcvdpsxws, 0x10, 0x0D, 0, PPC2_VSX)
7952GEN_VSX_HELPER_2(xvcvdpuxds, 0x10, 0x1C, 0, PPC2_VSX)
7953GEN_VSX_HELPER_2(xvcvdpuxws, 0x10, 0x0C, 0, PPC2_VSX)
7954GEN_VSX_HELPER_2(xvcvsxddp, 0x10, 0x1F, 0, PPC2_VSX)
7955GEN_VSX_HELPER_2(xvcvuxddp, 0x10, 0x1E, 0, PPC2_VSX)
7956GEN_VSX_HELPER_2(xvcvsxwdp, 0x10, 0x0F, 0, PPC2_VSX)
7957GEN_VSX_HELPER_2(xvcvuxwdp, 0x10, 0x0E, 0, PPC2_VSX)
88e33d08
TM
7958GEN_VSX_HELPER_2(xvrdpi, 0x12, 0x0C, 0, PPC2_VSX)
7959GEN_VSX_HELPER_2(xvrdpic, 0x16, 0x0E, 0, PPC2_VSX)
7960GEN_VSX_HELPER_2(xvrdpim, 0x12, 0x0F, 0, PPC2_VSX)
7961GEN_VSX_HELPER_2(xvrdpip, 0x12, 0x0E, 0, PPC2_VSX)
7962GEN_VSX_HELPER_2(xvrdpiz, 0x12, 0x0D, 0, PPC2_VSX)
ee6e02c0
TM
7963
7964GEN_VSX_HELPER_2(xvaddsp, 0x00, 0x08, 0, PPC2_VSX)
7965GEN_VSX_HELPER_2(xvsubsp, 0x00, 0x09, 0, PPC2_VSX)
5e591d88 7966GEN_VSX_HELPER_2(xvmulsp, 0x00, 0x0A, 0, PPC2_VSX)
4b98eeef 7967GEN_VSX_HELPER_2(xvdivsp, 0x00, 0x0B, 0, PPC2_VSX)
2009227f 7968GEN_VSX_HELPER_2(xvresp, 0x14, 0x09, 0, PPC2_VSX)
d32404fe 7969GEN_VSX_HELPER_2(xvsqrtsp, 0x16, 0x08, 0, PPC2_VSX)
d3f9df8f 7970GEN_VSX_HELPER_2(xvrsqrtesp, 0x14, 0x08, 0, PPC2_VSX)
bc80838f 7971GEN_VSX_HELPER_2(xvtdivsp, 0x14, 0x0B, 0, PPC2_VSX)
5cb151ac 7972GEN_VSX_HELPER_2(xvtsqrtsp, 0x14, 0x0A, 0, PPC2_VSX)
595c6eef
TM
7973GEN_VSX_HELPER_2(xvmaddasp, 0x04, 0x08, 0, PPC2_VSX)
7974GEN_VSX_HELPER_2(xvmaddmsp, 0x04, 0x09, 0, PPC2_VSX)
7975GEN_VSX_HELPER_2(xvmsubasp, 0x04, 0x0A, 0, PPC2_VSX)
7976GEN_VSX_HELPER_2(xvmsubmsp, 0x04, 0x0B, 0, PPC2_VSX)
7977GEN_VSX_HELPER_2(xvnmaddasp, 0x04, 0x18, 0, PPC2_VSX)
7978GEN_VSX_HELPER_2(xvnmaddmsp, 0x04, 0x19, 0, PPC2_VSX)
7979GEN_VSX_HELPER_2(xvnmsubasp, 0x04, 0x1A, 0, PPC2_VSX)
7980GEN_VSX_HELPER_2(xvnmsubmsp, 0x04, 0x1B, 0, PPC2_VSX)
959e9c9d
TM
7981GEN_VSX_HELPER_2(xvmaxsp, 0x00, 0x18, 0, PPC2_VSX)
7982GEN_VSX_HELPER_2(xvminsp, 0x00, 0x19, 0, PPC2_VSX)
354a6dec
TM
7983GEN_VSX_HELPER_2(xvcmpeqsp, 0x0C, 0x08, 0, PPC2_VSX)
7984GEN_VSX_HELPER_2(xvcmpgtsp, 0x0C, 0x09, 0, PPC2_VSX)
7985GEN_VSX_HELPER_2(xvcmpgesp, 0x0C, 0x0A, 0, PPC2_VSX)
ed8ac568 7986GEN_VSX_HELPER_2(xvcvspdp, 0x12, 0x1C, 0, PPC2_VSX)
5177d2ca
TM
7987GEN_VSX_HELPER_2(xvcvspsxds, 0x10, 0x19, 0, PPC2_VSX)
7988GEN_VSX_HELPER_2(xvcvspsxws, 0x10, 0x09, 0, PPC2_VSX)
7989GEN_VSX_HELPER_2(xvcvspuxds, 0x10, 0x18, 0, PPC2_VSX)
7990GEN_VSX_HELPER_2(xvcvspuxws, 0x10, 0x08, 0, PPC2_VSX)
7991GEN_VSX_HELPER_2(xvcvsxdsp, 0x10, 0x1B, 0, PPC2_VSX)
7992GEN_VSX_HELPER_2(xvcvuxdsp, 0x10, 0x1A, 0, PPC2_VSX)
7993GEN_VSX_HELPER_2(xvcvsxwsp, 0x10, 0x0B, 0, PPC2_VSX)
7994GEN_VSX_HELPER_2(xvcvuxwsp, 0x10, 0x0A, 0, PPC2_VSX)
88e33d08
TM
7995GEN_VSX_HELPER_2(xvrspi, 0x12, 0x08, 0, PPC2_VSX)
7996GEN_VSX_HELPER_2(xvrspic, 0x16, 0x0A, 0, PPC2_VSX)
7997GEN_VSX_HELPER_2(xvrspim, 0x12, 0x0B, 0, PPC2_VSX)
7998GEN_VSX_HELPER_2(xvrspip, 0x12, 0x0A, 0, PPC2_VSX)
7999GEN_VSX_HELPER_2(xvrspiz, 0x12, 0x09, 0, PPC2_VSX)
ee6e02c0 8000
79ca8a6a
TM
8001#define VSX_LOGICAL(name, tcg_op) \
8002static void glue(gen_, name)(DisasContext * ctx) \
8003 { \
8004 if (unlikely(!ctx->vsx_enabled)) { \
8005 gen_exception(ctx, POWERPC_EXCP_VSXU); \
8006 return; \
8007 } \
8008 tcg_op(cpu_vsrh(xT(ctx->opcode)), cpu_vsrh(xA(ctx->opcode)), \
8009 cpu_vsrh(xB(ctx->opcode))); \
8010 tcg_op(cpu_vsrl(xT(ctx->opcode)), cpu_vsrl(xA(ctx->opcode)), \
8011 cpu_vsrl(xB(ctx->opcode))); \
8012 }
8013
f976b09e
AG
8014VSX_LOGICAL(xxland, tcg_gen_and_i64)
8015VSX_LOGICAL(xxlandc, tcg_gen_andc_i64)
8016VSX_LOGICAL(xxlor, tcg_gen_or_i64)
8017VSX_LOGICAL(xxlxor, tcg_gen_xor_i64)
8018VSX_LOGICAL(xxlnor, tcg_gen_nor_i64)
67a33f37
TM
8019VSX_LOGICAL(xxleqv, tcg_gen_eqv_i64)
8020VSX_LOGICAL(xxlnand, tcg_gen_nand_i64)
8021VSX_LOGICAL(xxlorc, tcg_gen_orc_i64)
df020ce0 8022
ce577d2e
TM
8023#define VSX_XXMRG(name, high) \
8024static void glue(gen_, name)(DisasContext * ctx) \
8025 { \
8026 TCGv_i64 a0, a1, b0, b1; \
8027 if (unlikely(!ctx->vsx_enabled)) { \
8028 gen_exception(ctx, POWERPC_EXCP_VSXU); \
8029 return; \
8030 } \
f976b09e
AG
8031 a0 = tcg_temp_new_i64(); \
8032 a1 = tcg_temp_new_i64(); \
8033 b0 = tcg_temp_new_i64(); \
8034 b1 = tcg_temp_new_i64(); \
ce577d2e
TM
8035 if (high) { \
8036 tcg_gen_mov_i64(a0, cpu_vsrh(xA(ctx->opcode))); \
8037 tcg_gen_mov_i64(a1, cpu_vsrh(xA(ctx->opcode))); \
8038 tcg_gen_mov_i64(b0, cpu_vsrh(xB(ctx->opcode))); \
8039 tcg_gen_mov_i64(b1, cpu_vsrh(xB(ctx->opcode))); \
8040 } else { \
8041 tcg_gen_mov_i64(a0, cpu_vsrl(xA(ctx->opcode))); \
8042 tcg_gen_mov_i64(a1, cpu_vsrl(xA(ctx->opcode))); \
8043 tcg_gen_mov_i64(b0, cpu_vsrl(xB(ctx->opcode))); \
8044 tcg_gen_mov_i64(b1, cpu_vsrl(xB(ctx->opcode))); \
8045 } \
8046 tcg_gen_shri_i64(a0, a0, 32); \
8047 tcg_gen_shri_i64(b0, b0, 32); \
8048 tcg_gen_deposit_i64(cpu_vsrh(xT(ctx->opcode)), \
8049 b0, a0, 32, 32); \
8050 tcg_gen_deposit_i64(cpu_vsrl(xT(ctx->opcode)), \
8051 b1, a1, 32, 32); \
f976b09e
AG
8052 tcg_temp_free_i64(a0); \
8053 tcg_temp_free_i64(a1); \
8054 tcg_temp_free_i64(b0); \
8055 tcg_temp_free_i64(b1); \
ce577d2e
TM
8056 }
8057
8058VSX_XXMRG(xxmrghw, 1)
8059VSX_XXMRG(xxmrglw, 0)
8060
551e3ef7
TM
8061static void gen_xxsel(DisasContext * ctx)
8062{
8063 TCGv_i64 a, b, c;
8064 if (unlikely(!ctx->vsx_enabled)) {
8065 gen_exception(ctx, POWERPC_EXCP_VSXU);
8066 return;
8067 }
f976b09e
AG
8068 a = tcg_temp_new_i64();
8069 b = tcg_temp_new_i64();
8070 c = tcg_temp_new_i64();
551e3ef7
TM
8071
8072 tcg_gen_mov_i64(a, cpu_vsrh(xA(ctx->opcode)));
8073 tcg_gen_mov_i64(b, cpu_vsrh(xB(ctx->opcode)));
8074 tcg_gen_mov_i64(c, cpu_vsrh(xC(ctx->opcode)));
8075
8076 tcg_gen_and_i64(b, b, c);
8077 tcg_gen_andc_i64(a, a, c);
8078 tcg_gen_or_i64(cpu_vsrh(xT(ctx->opcode)), a, b);
8079
8080 tcg_gen_mov_i64(a, cpu_vsrl(xA(ctx->opcode)));
8081 tcg_gen_mov_i64(b, cpu_vsrl(xB(ctx->opcode)));
8082 tcg_gen_mov_i64(c, cpu_vsrl(xC(ctx->opcode)));
8083
8084 tcg_gen_and_i64(b, b, c);
8085 tcg_gen_andc_i64(a, a, c);
8086 tcg_gen_or_i64(cpu_vsrl(xT(ctx->opcode)), a, b);
8087
f976b09e
AG
8088 tcg_temp_free_i64(a);
8089 tcg_temp_free_i64(b);
8090 tcg_temp_free_i64(c);
551e3ef7
TM
8091}
8092
76c15fe0
TM
8093static void gen_xxspltw(DisasContext *ctx)
8094{
8095 TCGv_i64 b, b2;
8096 TCGv_i64 vsr = (UIM(ctx->opcode) & 2) ?
8097 cpu_vsrl(xB(ctx->opcode)) :
8098 cpu_vsrh(xB(ctx->opcode));
8099
8100 if (unlikely(!ctx->vsx_enabled)) {
8101 gen_exception(ctx, POWERPC_EXCP_VSXU);
8102 return;
8103 }
8104
f976b09e
AG
8105 b = tcg_temp_new_i64();
8106 b2 = tcg_temp_new_i64();
76c15fe0
TM
8107
8108 if (UIM(ctx->opcode) & 1) {
8109 tcg_gen_ext32u_i64(b, vsr);
8110 } else {
8111 tcg_gen_shri_i64(b, vsr, 32);
8112 }
8113
8114 tcg_gen_shli_i64(b2, b, 32);
8115 tcg_gen_or_i64(cpu_vsrh(xT(ctx->opcode)), b, b2);
8116 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), cpu_vsrh(xT(ctx->opcode)));
8117
f976b09e
AG
8118 tcg_temp_free_i64(b);
8119 tcg_temp_free_i64(b2);
76c15fe0
TM
8120}
8121
acc42968
TM
8122static void gen_xxsldwi(DisasContext *ctx)
8123{
8124 TCGv_i64 xth, xtl;
8125 if (unlikely(!ctx->vsx_enabled)) {
8126 gen_exception(ctx, POWERPC_EXCP_VSXU);
8127 return;
8128 }
f976b09e
AG
8129 xth = tcg_temp_new_i64();
8130 xtl = tcg_temp_new_i64();
acc42968
TM
8131
8132 switch (SHW(ctx->opcode)) {
8133 case 0: {
8134 tcg_gen_mov_i64(xth, cpu_vsrh(xA(ctx->opcode)));
8135 tcg_gen_mov_i64(xtl, cpu_vsrl(xA(ctx->opcode)));
8136 break;
8137 }
8138 case 1: {
f976b09e 8139 TCGv_i64 t0 = tcg_temp_new_i64();
acc42968
TM
8140 tcg_gen_mov_i64(xth, cpu_vsrh(xA(ctx->opcode)));
8141 tcg_gen_shli_i64(xth, xth, 32);
8142 tcg_gen_mov_i64(t0, cpu_vsrl(xA(ctx->opcode)));
8143 tcg_gen_shri_i64(t0, t0, 32);
8144 tcg_gen_or_i64(xth, xth, t0);
8145 tcg_gen_mov_i64(xtl, cpu_vsrl(xA(ctx->opcode)));
8146 tcg_gen_shli_i64(xtl, xtl, 32);
8147 tcg_gen_mov_i64(t0, cpu_vsrh(xB(ctx->opcode)));
8148 tcg_gen_shri_i64(t0, t0, 32);
8149 tcg_gen_or_i64(xtl, xtl, t0);
f976b09e 8150 tcg_temp_free_i64(t0);
acc42968
TM
8151 break;
8152 }
8153 case 2: {
8154 tcg_gen_mov_i64(xth, cpu_vsrl(xA(ctx->opcode)));
8155 tcg_gen_mov_i64(xtl, cpu_vsrh(xB(ctx->opcode)));
8156 break;
8157 }
8158 case 3: {
f976b09e 8159 TCGv_i64 t0 = tcg_temp_new_i64();
acc42968
TM
8160 tcg_gen_mov_i64(xth, cpu_vsrl(xA(ctx->opcode)));
8161 tcg_gen_shli_i64(xth, xth, 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(xth, xth, t0);
8165 tcg_gen_mov_i64(xtl, cpu_vsrh(xB(ctx->opcode)));
8166 tcg_gen_shli_i64(xtl, xtl, 32);
8167 tcg_gen_mov_i64(t0, cpu_vsrl(xB(ctx->opcode)));
8168 tcg_gen_shri_i64(t0, t0, 32);
8169 tcg_gen_or_i64(xtl, xtl, t0);
f976b09e 8170 tcg_temp_free_i64(t0);
acc42968
TM
8171 break;
8172 }
8173 }
8174
8175 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xth);
8176 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), xtl);
8177
f976b09e
AG
8178 tcg_temp_free_i64(xth);
8179 tcg_temp_free_i64(xtl);
acc42968
TM
8180}
8181
ce577d2e 8182
0487d6a8 8183/*** SPE extension ***/
0487d6a8 8184/* Register moves */
3cd7d1dd 8185
a0e13900
FC
8186static inline void gen_evmra(DisasContext *ctx)
8187{
8188
8189 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8190 gen_exception(ctx, POWERPC_EXCP_SPEU);
a0e13900
FC
8191 return;
8192 }
8193
8194#if defined(TARGET_PPC64)
8195 /* rD := rA */
8196 tcg_gen_mov_i64(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
8197
8198 /* spe_acc := rA */
8199 tcg_gen_st_i64(cpu_gpr[rA(ctx->opcode)],
8200 cpu_env,
1328c2bf 8201 offsetof(CPUPPCState, spe_acc));
a0e13900
FC
8202#else
8203 TCGv_i64 tmp = tcg_temp_new_i64();
8204
8205 /* tmp := rA_lo + rA_hi << 32 */
8206 tcg_gen_concat_i32_i64(tmp, cpu_gpr[rA(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
8207
8208 /* spe_acc := tmp */
1328c2bf 8209 tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
8210 tcg_temp_free_i64(tmp);
8211
8212 /* rD := rA */
8213 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
8214 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
8215#endif
8216}
8217
636aa200
BS
8218static inline void gen_load_gpr64(TCGv_i64 t, int reg)
8219{
f78fb44e
AJ
8220#if defined(TARGET_PPC64)
8221 tcg_gen_mov_i64(t, cpu_gpr[reg]);
8222#else
36aa55dc 8223 tcg_gen_concat_i32_i64(t, cpu_gpr[reg], cpu_gprh[reg]);
3cd7d1dd 8224#endif
f78fb44e 8225}
3cd7d1dd 8226
636aa200
BS
8227static inline void gen_store_gpr64(int reg, TCGv_i64 t)
8228{
f78fb44e
AJ
8229#if defined(TARGET_PPC64)
8230 tcg_gen_mov_i64(cpu_gpr[reg], t);
8231#else
a7812ae4 8232 TCGv_i64 tmp = tcg_temp_new_i64();
f78fb44e 8233 tcg_gen_trunc_i64_i32(cpu_gpr[reg], t);
f78fb44e
AJ
8234 tcg_gen_shri_i64(tmp, t, 32);
8235 tcg_gen_trunc_i64_i32(cpu_gprh[reg], tmp);
a7812ae4 8236 tcg_temp_free_i64(tmp);
3cd7d1dd 8237#endif
f78fb44e 8238}
3cd7d1dd 8239
70560da7 8240#define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \
99e300ef 8241static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
0487d6a8
JM
8242{ \
8243 if (Rc(ctx->opcode)) \
8244 gen_##name1(ctx); \
8245 else \
8246 gen_##name0(ctx); \
8247}
8248
8249/* Handler for undefined SPE opcodes */
636aa200 8250static inline void gen_speundef(DisasContext *ctx)
0487d6a8 8251{
e06fcd75 8252 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
0487d6a8
JM
8253}
8254
57951c27
AJ
8255/* SPE logic */
8256#if defined(TARGET_PPC64)
8257#define GEN_SPEOP_LOGIC2(name, tcg_op) \
636aa200 8258static inline void gen_##name(DisasContext *ctx) \
0487d6a8
JM
8259{ \
8260 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8261 gen_exception(ctx, POWERPC_EXCP_SPEU); \
0487d6a8
JM
8262 return; \
8263 } \
57951c27
AJ
8264 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
8265 cpu_gpr[rB(ctx->opcode)]); \
8266}
8267#else
8268#define GEN_SPEOP_LOGIC2(name, tcg_op) \
636aa200 8269static inline void gen_##name(DisasContext *ctx) \
57951c27
AJ
8270{ \
8271 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8272 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
8273 return; \
8274 } \
8275 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
8276 cpu_gpr[rB(ctx->opcode)]); \
8277 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
8278 cpu_gprh[rB(ctx->opcode)]); \
0487d6a8 8279}
57951c27
AJ
8280#endif
8281
8282GEN_SPEOP_LOGIC2(evand, tcg_gen_and_tl);
8283GEN_SPEOP_LOGIC2(evandc, tcg_gen_andc_tl);
8284GEN_SPEOP_LOGIC2(evxor, tcg_gen_xor_tl);
8285GEN_SPEOP_LOGIC2(evor, tcg_gen_or_tl);
8286GEN_SPEOP_LOGIC2(evnor, tcg_gen_nor_tl);
8287GEN_SPEOP_LOGIC2(eveqv, tcg_gen_eqv_tl);
8288GEN_SPEOP_LOGIC2(evorc, tcg_gen_orc_tl);
8289GEN_SPEOP_LOGIC2(evnand, tcg_gen_nand_tl);
0487d6a8 8290
57951c27
AJ
8291/* SPE logic immediate */
8292#if defined(TARGET_PPC64)
8293#define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \
636aa200 8294static inline void gen_##name(DisasContext *ctx) \
3d3a6a0a
AJ
8295{ \
8296 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8297 gen_exception(ctx, POWERPC_EXCP_SPEU); \
3d3a6a0a
AJ
8298 return; \
8299 } \
a7812ae4
PB
8300 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
8301 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
8302 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
57951c27
AJ
8303 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8304 tcg_opi(t0, t0, rB(ctx->opcode)); \
8305 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
8306 tcg_gen_trunc_i64_i32(t1, t2); \
a7812ae4 8307 tcg_temp_free_i64(t2); \
57951c27
AJ
8308 tcg_opi(t1, t1, rB(ctx->opcode)); \
8309 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
a7812ae4
PB
8310 tcg_temp_free_i32(t0); \
8311 tcg_temp_free_i32(t1); \
3d3a6a0a 8312}
57951c27
AJ
8313#else
8314#define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \
636aa200 8315static inline void gen_##name(DisasContext *ctx) \
0487d6a8
JM
8316{ \
8317 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8318 gen_exception(ctx, POWERPC_EXCP_SPEU); \
0487d6a8
JM
8319 return; \
8320 } \
57951c27
AJ
8321 tcg_opi(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
8322 rB(ctx->opcode)); \
8323 tcg_opi(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
8324 rB(ctx->opcode)); \
0487d6a8 8325}
57951c27
AJ
8326#endif
8327GEN_SPEOP_TCG_LOGIC_IMM2(evslwi, tcg_gen_shli_i32);
8328GEN_SPEOP_TCG_LOGIC_IMM2(evsrwiu, tcg_gen_shri_i32);
8329GEN_SPEOP_TCG_LOGIC_IMM2(evsrwis, tcg_gen_sari_i32);
8330GEN_SPEOP_TCG_LOGIC_IMM2(evrlwi, tcg_gen_rotli_i32);
0487d6a8 8331
57951c27
AJ
8332/* SPE arithmetic */
8333#if defined(TARGET_PPC64)
8334#define GEN_SPEOP_ARITH1(name, tcg_op) \
636aa200 8335static inline void gen_##name(DisasContext *ctx) \
0487d6a8
JM
8336{ \
8337 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8338 gen_exception(ctx, POWERPC_EXCP_SPEU); \
0487d6a8
JM
8339 return; \
8340 } \
a7812ae4
PB
8341 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
8342 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
8343 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
57951c27
AJ
8344 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8345 tcg_op(t0, t0); \
8346 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
8347 tcg_gen_trunc_i64_i32(t1, t2); \
a7812ae4 8348 tcg_temp_free_i64(t2); \
57951c27
AJ
8349 tcg_op(t1, t1); \
8350 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
a7812ae4
PB
8351 tcg_temp_free_i32(t0); \
8352 tcg_temp_free_i32(t1); \
0487d6a8 8353}
57951c27 8354#else
a7812ae4 8355#define GEN_SPEOP_ARITH1(name, tcg_op) \
636aa200 8356static inline void gen_##name(DisasContext *ctx) \
57951c27
AJ
8357{ \
8358 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8359 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
8360 return; \
8361 } \
8362 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); \
8363 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); \
8364}
8365#endif
0487d6a8 8366
636aa200 8367static inline void gen_op_evabs(TCGv_i32 ret, TCGv_i32 arg1)
57951c27
AJ
8368{
8369 int l1 = gen_new_label();
8370 int l2 = gen_new_label();
0487d6a8 8371
57951c27
AJ
8372 tcg_gen_brcondi_i32(TCG_COND_GE, arg1, 0, l1);
8373 tcg_gen_neg_i32(ret, arg1);
8374 tcg_gen_br(l2);
8375 gen_set_label(l1);
a7812ae4 8376 tcg_gen_mov_i32(ret, arg1);
57951c27
AJ
8377 gen_set_label(l2);
8378}
8379GEN_SPEOP_ARITH1(evabs, gen_op_evabs);
8380GEN_SPEOP_ARITH1(evneg, tcg_gen_neg_i32);
8381GEN_SPEOP_ARITH1(evextsb, tcg_gen_ext8s_i32);
8382GEN_SPEOP_ARITH1(evextsh, tcg_gen_ext16s_i32);
636aa200 8383static inline void gen_op_evrndw(TCGv_i32 ret, TCGv_i32 arg1)
0487d6a8 8384{
57951c27
AJ
8385 tcg_gen_addi_i32(ret, arg1, 0x8000);
8386 tcg_gen_ext16u_i32(ret, ret);
8387}
8388GEN_SPEOP_ARITH1(evrndw, gen_op_evrndw);
a7812ae4
PB
8389GEN_SPEOP_ARITH1(evcntlsw, gen_helper_cntlsw32);
8390GEN_SPEOP_ARITH1(evcntlzw, gen_helper_cntlzw32);
0487d6a8 8391
57951c27
AJ
8392#if defined(TARGET_PPC64)
8393#define GEN_SPEOP_ARITH2(name, tcg_op) \
636aa200 8394static inline void gen_##name(DisasContext *ctx) \
0487d6a8
JM
8395{ \
8396 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8397 gen_exception(ctx, POWERPC_EXCP_SPEU); \
0487d6a8
JM
8398 return; \
8399 } \
a7812ae4
PB
8400 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
8401 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
8402 TCGv_i32 t2 = tcg_temp_local_new_i32(); \
501e23c4 8403 TCGv_i64 t3 = tcg_temp_local_new_i64(); \
57951c27
AJ
8404 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8405 tcg_gen_trunc_i64_i32(t2, cpu_gpr[rB(ctx->opcode)]); \
8406 tcg_op(t0, t0, t2); \
8407 tcg_gen_shri_i64(t3, cpu_gpr[rA(ctx->opcode)], 32); \
8408 tcg_gen_trunc_i64_i32(t1, t3); \
8409 tcg_gen_shri_i64(t3, cpu_gpr[rB(ctx->opcode)], 32); \
8410 tcg_gen_trunc_i64_i32(t2, t3); \
a7812ae4 8411 tcg_temp_free_i64(t3); \
57951c27 8412 tcg_op(t1, t1, t2); \
a7812ae4 8413 tcg_temp_free_i32(t2); \
57951c27 8414 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
a7812ae4
PB
8415 tcg_temp_free_i32(t0); \
8416 tcg_temp_free_i32(t1); \
0487d6a8 8417}
57951c27
AJ
8418#else
8419#define GEN_SPEOP_ARITH2(name, tcg_op) \
636aa200 8420static inline void gen_##name(DisasContext *ctx) \
0487d6a8
JM
8421{ \
8422 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8423 gen_exception(ctx, POWERPC_EXCP_SPEU); \
0487d6a8
JM
8424 return; \
8425 } \
57951c27
AJ
8426 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
8427 cpu_gpr[rB(ctx->opcode)]); \
8428 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
8429 cpu_gprh[rB(ctx->opcode)]); \
0487d6a8 8430}
57951c27 8431#endif
0487d6a8 8432
636aa200 8433static inline void gen_op_evsrwu(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
57951c27 8434{
a7812ae4 8435 TCGv_i32 t0;
57951c27 8436 int l1, l2;
0487d6a8 8437
57951c27
AJ
8438 l1 = gen_new_label();
8439 l2 = gen_new_label();
a7812ae4 8440 t0 = tcg_temp_local_new_i32();
57951c27
AJ
8441 /* No error here: 6 bits are used */
8442 tcg_gen_andi_i32(t0, arg2, 0x3F);
8443 tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1);
8444 tcg_gen_shr_i32(ret, arg1, t0);
8445 tcg_gen_br(l2);
8446 gen_set_label(l1);
8447 tcg_gen_movi_i32(ret, 0);
0aef4261 8448 gen_set_label(l2);
a7812ae4 8449 tcg_temp_free_i32(t0);
57951c27
AJ
8450}
8451GEN_SPEOP_ARITH2(evsrwu, gen_op_evsrwu);
636aa200 8452static inline void gen_op_evsrws(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
57951c27 8453{
a7812ae4 8454 TCGv_i32 t0;
57951c27
AJ
8455 int l1, l2;
8456
8457 l1 = gen_new_label();
8458 l2 = gen_new_label();
a7812ae4 8459 t0 = tcg_temp_local_new_i32();
57951c27
AJ
8460 /* No error here: 6 bits are used */
8461 tcg_gen_andi_i32(t0, arg2, 0x3F);
8462 tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1);
8463 tcg_gen_sar_i32(ret, arg1, t0);
8464 tcg_gen_br(l2);
8465 gen_set_label(l1);
8466 tcg_gen_movi_i32(ret, 0);
0aef4261 8467 gen_set_label(l2);
a7812ae4 8468 tcg_temp_free_i32(t0);
57951c27
AJ
8469}
8470GEN_SPEOP_ARITH2(evsrws, gen_op_evsrws);
636aa200 8471static inline void gen_op_evslw(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
57951c27 8472{
a7812ae4 8473 TCGv_i32 t0;
57951c27
AJ
8474 int l1, l2;
8475
8476 l1 = gen_new_label();
8477 l2 = gen_new_label();
a7812ae4 8478 t0 = tcg_temp_local_new_i32();
57951c27
AJ
8479 /* No error here: 6 bits are used */
8480 tcg_gen_andi_i32(t0, arg2, 0x3F);
8481 tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1);
8482 tcg_gen_shl_i32(ret, arg1, t0);
8483 tcg_gen_br(l2);
8484 gen_set_label(l1);
8485 tcg_gen_movi_i32(ret, 0);
e29ef9fa 8486 gen_set_label(l2);
a7812ae4 8487 tcg_temp_free_i32(t0);
57951c27
AJ
8488}
8489GEN_SPEOP_ARITH2(evslw, gen_op_evslw);
636aa200 8490static inline void gen_op_evrlw(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
57951c27 8491{
a7812ae4 8492 TCGv_i32 t0 = tcg_temp_new_i32();
57951c27
AJ
8493 tcg_gen_andi_i32(t0, arg2, 0x1F);
8494 tcg_gen_rotl_i32(ret, arg1, t0);
a7812ae4 8495 tcg_temp_free_i32(t0);
57951c27
AJ
8496}
8497GEN_SPEOP_ARITH2(evrlw, gen_op_evrlw);
636aa200 8498static inline void gen_evmergehi(DisasContext *ctx)
57951c27
AJ
8499{
8500 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8501 gen_exception(ctx, POWERPC_EXCP_SPEU);
57951c27
AJ
8502 return;
8503 }
8504#if defined(TARGET_PPC64)
a7812ae4
PB
8505 TCGv t0 = tcg_temp_new();
8506 TCGv t1 = tcg_temp_new();
57951c27
AJ
8507 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 32);
8508 tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], 0xFFFFFFFF0000000ULL);
8509 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1);
8510 tcg_temp_free(t0);
8511 tcg_temp_free(t1);
8512#else
8513 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
8514 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
8515#endif
8516}
8517GEN_SPEOP_ARITH2(evaddw, tcg_gen_add_i32);
636aa200 8518static inline void gen_op_evsubf(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
0487d6a8 8519{
57951c27
AJ
8520 tcg_gen_sub_i32(ret, arg2, arg1);
8521}
8522GEN_SPEOP_ARITH2(evsubfw, gen_op_evsubf);
0487d6a8 8523
57951c27
AJ
8524/* SPE arithmetic immediate */
8525#if defined(TARGET_PPC64)
8526#define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \
636aa200 8527static inline void gen_##name(DisasContext *ctx) \
57951c27
AJ
8528{ \
8529 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8530 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
8531 return; \
8532 } \
a7812ae4
PB
8533 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
8534 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
8535 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
57951c27
AJ
8536 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
8537 tcg_op(t0, t0, rA(ctx->opcode)); \
8538 tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32); \
8539 tcg_gen_trunc_i64_i32(t1, t2); \
e06fcd75 8540 tcg_temp_free_i64(t2); \
57951c27
AJ
8541 tcg_op(t1, t1, rA(ctx->opcode)); \
8542 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
a7812ae4
PB
8543 tcg_temp_free_i32(t0); \
8544 tcg_temp_free_i32(t1); \
57951c27
AJ
8545}
8546#else
8547#define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \
636aa200 8548static inline void gen_##name(DisasContext *ctx) \
57951c27
AJ
8549{ \
8550 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8551 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
8552 return; \
8553 } \
8554 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
8555 rA(ctx->opcode)); \
8556 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)], \
8557 rA(ctx->opcode)); \
8558}
8559#endif
8560GEN_SPEOP_ARITH_IMM2(evaddiw, tcg_gen_addi_i32);
8561GEN_SPEOP_ARITH_IMM2(evsubifw, tcg_gen_subi_i32);
8562
8563/* SPE comparison */
8564#if defined(TARGET_PPC64)
8565#define GEN_SPEOP_COMP(name, tcg_cond) \
636aa200 8566static inline void gen_##name(DisasContext *ctx) \
57951c27
AJ
8567{ \
8568 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8569 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
8570 return; \
8571 } \
8572 int l1 = gen_new_label(); \
8573 int l2 = gen_new_label(); \
8574 int l3 = gen_new_label(); \
8575 int l4 = gen_new_label(); \
a7812ae4
PB
8576 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
8577 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
8578 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
57951c27
AJ
8579 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8580 tcg_gen_trunc_i64_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
8581 tcg_gen_brcond_i32(tcg_cond, t0, t1, l1); \
a7812ae4 8582 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], 0); \
57951c27
AJ
8583 tcg_gen_br(l2); \
8584 gen_set_label(l1); \
8585 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \
8586 CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \
8587 gen_set_label(l2); \
8588 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
8589 tcg_gen_trunc_i64_i32(t0, t2); \
8590 tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32); \
8591 tcg_gen_trunc_i64_i32(t1, t2); \
a7812ae4 8592 tcg_temp_free_i64(t2); \
57951c27
AJ
8593 tcg_gen_brcond_i32(tcg_cond, t0, t1, l3); \
8594 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
8595 ~(CRF_CH | CRF_CH_AND_CL)); \
8596 tcg_gen_br(l4); \
8597 gen_set_label(l3); \
8598 tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
8599 CRF_CH | CRF_CH_OR_CL); \
8600 gen_set_label(l4); \
a7812ae4
PB
8601 tcg_temp_free_i32(t0); \
8602 tcg_temp_free_i32(t1); \
57951c27
AJ
8603}
8604#else
8605#define GEN_SPEOP_COMP(name, tcg_cond) \
636aa200 8606static inline void gen_##name(DisasContext *ctx) \
57951c27
AJ
8607{ \
8608 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8609 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
8610 return; \
8611 } \
8612 int l1 = gen_new_label(); \
8613 int l2 = gen_new_label(); \
8614 int l3 = gen_new_label(); \
8615 int l4 = gen_new_label(); \
8616 \
8617 tcg_gen_brcond_i32(tcg_cond, cpu_gpr[rA(ctx->opcode)], \
8618 cpu_gpr[rB(ctx->opcode)], l1); \
8619 tcg_gen_movi_tl(cpu_crf[crfD(ctx->opcode)], 0); \
8620 tcg_gen_br(l2); \
8621 gen_set_label(l1); \
8622 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \
8623 CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \
8624 gen_set_label(l2); \
8625 tcg_gen_brcond_i32(tcg_cond, cpu_gprh[rA(ctx->opcode)], \
8626 cpu_gprh[rB(ctx->opcode)], l3); \
8627 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
8628 ~(CRF_CH | CRF_CH_AND_CL)); \
8629 tcg_gen_br(l4); \
8630 gen_set_label(l3); \
8631 tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
8632 CRF_CH | CRF_CH_OR_CL); \
8633 gen_set_label(l4); \
8634}
8635#endif
8636GEN_SPEOP_COMP(evcmpgtu, TCG_COND_GTU);
8637GEN_SPEOP_COMP(evcmpgts, TCG_COND_GT);
8638GEN_SPEOP_COMP(evcmpltu, TCG_COND_LTU);
8639GEN_SPEOP_COMP(evcmplts, TCG_COND_LT);
8640GEN_SPEOP_COMP(evcmpeq, TCG_COND_EQ);
8641
8642/* SPE misc */
636aa200 8643static inline void gen_brinc(DisasContext *ctx)
57951c27
AJ
8644{
8645 /* Note: brinc is usable even if SPE is disabled */
a7812ae4
PB
8646 gen_helper_brinc(cpu_gpr[rD(ctx->opcode)],
8647 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
0487d6a8 8648}
636aa200 8649static inline void gen_evmergelo(DisasContext *ctx)
57951c27
AJ
8650{
8651 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8652 gen_exception(ctx, POWERPC_EXCP_SPEU);
57951c27
AJ
8653 return;
8654 }
8655#if defined(TARGET_PPC64)
a7812ae4
PB
8656 TCGv t0 = tcg_temp_new();
8657 TCGv t1 = tcg_temp_new();
17d9b3af 8658 tcg_gen_ext32u_tl(t0, cpu_gpr[rB(ctx->opcode)]);
57951c27
AJ
8659 tcg_gen_shli_tl(t1, cpu_gpr[rA(ctx->opcode)], 32);
8660 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1);
8661 tcg_temp_free(t0);
8662 tcg_temp_free(t1);
8663#else
57951c27 8664 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
33890b3e 8665 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
57951c27
AJ
8666#endif
8667}
636aa200 8668static inline void gen_evmergehilo(DisasContext *ctx)
57951c27
AJ
8669{
8670 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8671 gen_exception(ctx, POWERPC_EXCP_SPEU);
57951c27
AJ
8672 return;
8673 }
8674#if defined(TARGET_PPC64)
a7812ae4
PB
8675 TCGv t0 = tcg_temp_new();
8676 TCGv t1 = tcg_temp_new();
17d9b3af 8677 tcg_gen_ext32u_tl(t0, cpu_gpr[rB(ctx->opcode)]);
57951c27
AJ
8678 tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], 0xFFFFFFFF0000000ULL);
8679 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1);
8680 tcg_temp_free(t0);
8681 tcg_temp_free(t1);
8682#else
8683 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
8684 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
8685#endif
8686}
636aa200 8687static inline void gen_evmergelohi(DisasContext *ctx)
57951c27
AJ
8688{
8689 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8690 gen_exception(ctx, POWERPC_EXCP_SPEU);
57951c27
AJ
8691 return;
8692 }
8693#if defined(TARGET_PPC64)
a7812ae4
PB
8694 TCGv t0 = tcg_temp_new();
8695 TCGv t1 = tcg_temp_new();
57951c27
AJ
8696 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 32);
8697 tcg_gen_shli_tl(t1, cpu_gpr[rA(ctx->opcode)], 32);
8698 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1);
8699 tcg_temp_free(t0);
8700 tcg_temp_free(t1);
8701#else
33890b3e
NF
8702 if (rD(ctx->opcode) == rA(ctx->opcode)) {
8703 TCGv_i32 tmp = tcg_temp_new_i32();
8704 tcg_gen_mov_i32(tmp, cpu_gpr[rA(ctx->opcode)]);
8705 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
8706 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], tmp);
8707 tcg_temp_free_i32(tmp);
8708 } else {
8709 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
8710 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
8711 }
57951c27
AJ
8712#endif
8713}
636aa200 8714static inline void gen_evsplati(DisasContext *ctx)
57951c27 8715{
ae01847f 8716 uint64_t imm = ((int32_t)(rA(ctx->opcode) << 27)) >> 27;
0487d6a8 8717
57951c27 8718#if defined(TARGET_PPC64)
38d14952 8719 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], (imm << 32) | imm);
57951c27
AJ
8720#else
8721 tcg_gen_movi_i32(cpu_gpr[rD(ctx->opcode)], imm);
8722 tcg_gen_movi_i32(cpu_gprh[rD(ctx->opcode)], imm);
8723#endif
8724}
636aa200 8725static inline void gen_evsplatfi(DisasContext *ctx)
0487d6a8 8726{
ae01847f 8727 uint64_t imm = rA(ctx->opcode) << 27;
0487d6a8 8728
57951c27 8729#if defined(TARGET_PPC64)
38d14952 8730 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], (imm << 32) | imm);
57951c27
AJ
8731#else
8732 tcg_gen_movi_i32(cpu_gpr[rD(ctx->opcode)], imm);
8733 tcg_gen_movi_i32(cpu_gprh[rD(ctx->opcode)], imm);
8734#endif
0487d6a8
JM
8735}
8736
636aa200 8737static inline void gen_evsel(DisasContext *ctx)
57951c27
AJ
8738{
8739 int l1 = gen_new_label();
8740 int l2 = gen_new_label();
8741 int l3 = gen_new_label();
8742 int l4 = gen_new_label();
a7812ae4 8743 TCGv_i32 t0 = tcg_temp_local_new_i32();
57951c27 8744#if defined(TARGET_PPC64)
a7812ae4
PB
8745 TCGv t1 = tcg_temp_local_new();
8746 TCGv t2 = tcg_temp_local_new();
57951c27
AJ
8747#endif
8748 tcg_gen_andi_i32(t0, cpu_crf[ctx->opcode & 0x07], 1 << 3);
8749 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1);
8750#if defined(TARGET_PPC64)
8751 tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], 0xFFFFFFFF00000000ULL);
8752#else
8753 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
8754#endif
8755 tcg_gen_br(l2);
8756 gen_set_label(l1);
8757#if defined(TARGET_PPC64)
8758 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0xFFFFFFFF00000000ULL);
8759#else
8760 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
8761#endif
8762 gen_set_label(l2);
8763 tcg_gen_andi_i32(t0, cpu_crf[ctx->opcode & 0x07], 1 << 2);
8764 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l3);
8765#if defined(TARGET_PPC64)
17d9b3af 8766 tcg_gen_ext32u_tl(t2, cpu_gpr[rA(ctx->opcode)]);
57951c27
AJ
8767#else
8768 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
8769#endif
8770 tcg_gen_br(l4);
8771 gen_set_label(l3);
8772#if defined(TARGET_PPC64)
17d9b3af 8773 tcg_gen_ext32u_tl(t2, cpu_gpr[rB(ctx->opcode)]);
57951c27
AJ
8774#else
8775 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
8776#endif
8777 gen_set_label(l4);
a7812ae4 8778 tcg_temp_free_i32(t0);
57951c27
AJ
8779#if defined(TARGET_PPC64)
8780 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t1, t2);
8781 tcg_temp_free(t1);
8782 tcg_temp_free(t2);
8783#endif
8784}
e8eaa2c0
BS
8785
8786static void gen_evsel0(DisasContext *ctx)
57951c27
AJ
8787{
8788 gen_evsel(ctx);
8789}
e8eaa2c0
BS
8790
8791static void gen_evsel1(DisasContext *ctx)
57951c27
AJ
8792{
8793 gen_evsel(ctx);
8794}
e8eaa2c0
BS
8795
8796static void gen_evsel2(DisasContext *ctx)
57951c27
AJ
8797{
8798 gen_evsel(ctx);
8799}
e8eaa2c0
BS
8800
8801static void gen_evsel3(DisasContext *ctx)
57951c27
AJ
8802{
8803 gen_evsel(ctx);
8804}
0487d6a8 8805
a0e13900
FC
8806/* Multiply */
8807
8808static inline void gen_evmwumi(DisasContext *ctx)
8809{
8810 TCGv_i64 t0, t1;
8811
8812 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8813 gen_exception(ctx, POWERPC_EXCP_SPEU);
a0e13900
FC
8814 return;
8815 }
8816
8817 t0 = tcg_temp_new_i64();
8818 t1 = tcg_temp_new_i64();
8819
8820 /* t0 := rA; t1 := rB */
8821#if defined(TARGET_PPC64)
8822 tcg_gen_ext32u_tl(t0, cpu_gpr[rA(ctx->opcode)]);
8823 tcg_gen_ext32u_tl(t1, cpu_gpr[rB(ctx->opcode)]);
8824#else
8825 tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
8826 tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
8827#endif
8828
8829 tcg_gen_mul_i64(t0, t0, t1); /* t0 := rA * rB */
8830
8831 gen_store_gpr64(rD(ctx->opcode), t0); /* rD := t0 */
8832
8833 tcg_temp_free_i64(t0);
8834 tcg_temp_free_i64(t1);
8835}
8836
8837static inline void gen_evmwumia(DisasContext *ctx)
8838{
8839 TCGv_i64 tmp;
8840
8841 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8842 gen_exception(ctx, POWERPC_EXCP_SPEU);
a0e13900
FC
8843 return;
8844 }
8845
8846 gen_evmwumi(ctx); /* rD := rA * rB */
8847
8848 tmp = tcg_temp_new_i64();
8849
8850 /* acc := rD */
8851 gen_load_gpr64(tmp, rD(ctx->opcode));
1328c2bf 8852 tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
8853 tcg_temp_free_i64(tmp);
8854}
8855
8856static inline void gen_evmwumiaa(DisasContext *ctx)
8857{
8858 TCGv_i64 acc;
8859 TCGv_i64 tmp;
8860
8861 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8862 gen_exception(ctx, POWERPC_EXCP_SPEU);
a0e13900
FC
8863 return;
8864 }
8865
8866 gen_evmwumi(ctx); /* rD := rA * rB */
8867
8868 acc = tcg_temp_new_i64();
8869 tmp = tcg_temp_new_i64();
8870
8871 /* tmp := rD */
8872 gen_load_gpr64(tmp, rD(ctx->opcode));
8873
8874 /* Load acc */
1328c2bf 8875 tcg_gen_ld_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
8876
8877 /* acc := tmp + acc */
8878 tcg_gen_add_i64(acc, acc, tmp);
8879
8880 /* Store acc */
1328c2bf 8881 tcg_gen_st_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
8882
8883 /* rD := acc */
8884 gen_store_gpr64(rD(ctx->opcode), acc);
8885
8886 tcg_temp_free_i64(acc);
8887 tcg_temp_free_i64(tmp);
8888}
8889
8890static inline void gen_evmwsmi(DisasContext *ctx)
8891{
8892 TCGv_i64 t0, t1;
8893
8894 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8895 gen_exception(ctx, POWERPC_EXCP_SPEU);
a0e13900
FC
8896 return;
8897 }
8898
8899 t0 = tcg_temp_new_i64();
8900 t1 = tcg_temp_new_i64();
8901
8902 /* t0 := rA; t1 := rB */
8903#if defined(TARGET_PPC64)
8904 tcg_gen_ext32s_tl(t0, cpu_gpr[rA(ctx->opcode)]);
8905 tcg_gen_ext32s_tl(t1, cpu_gpr[rB(ctx->opcode)]);
8906#else
8907 tcg_gen_ext_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
8908 tcg_gen_ext_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
8909#endif
8910
8911 tcg_gen_mul_i64(t0, t0, t1); /* t0 := rA * rB */
8912
8913 gen_store_gpr64(rD(ctx->opcode), t0); /* rD := t0 */
8914
8915 tcg_temp_free_i64(t0);
8916 tcg_temp_free_i64(t1);
8917}
8918
8919static inline void gen_evmwsmia(DisasContext *ctx)
8920{
8921 TCGv_i64 tmp;
8922
8923 gen_evmwsmi(ctx); /* rD := rA * rB */
8924
8925 tmp = tcg_temp_new_i64();
8926
8927 /* acc := rD */
8928 gen_load_gpr64(tmp, rD(ctx->opcode));
1328c2bf 8929 tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
8930
8931 tcg_temp_free_i64(tmp);
8932}
8933
8934static inline void gen_evmwsmiaa(DisasContext *ctx)
8935{
8936 TCGv_i64 acc = tcg_temp_new_i64();
8937 TCGv_i64 tmp = tcg_temp_new_i64();
8938
8939 gen_evmwsmi(ctx); /* rD := rA * rB */
8940
8941 acc = tcg_temp_new_i64();
8942 tmp = tcg_temp_new_i64();
8943
8944 /* tmp := rD */
8945 gen_load_gpr64(tmp, rD(ctx->opcode));
8946
8947 /* Load acc */
1328c2bf 8948 tcg_gen_ld_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
8949
8950 /* acc := tmp + acc */
8951 tcg_gen_add_i64(acc, acc, tmp);
8952
8953 /* Store acc */
1328c2bf 8954 tcg_gen_st_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
8955
8956 /* rD := acc */
8957 gen_store_gpr64(rD(ctx->opcode), acc);
8958
8959 tcg_temp_free_i64(acc);
8960 tcg_temp_free_i64(tmp);
8961}
8962
70560da7
FC
8963GEN_SPE(evaddw, speundef, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
8964GEN_SPE(evaddiw, speundef, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE);
8965GEN_SPE(evsubfw, speundef, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
8966GEN_SPE(evsubifw, speundef, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE);
8967GEN_SPE(evabs, evneg, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE); ////
8968GEN_SPE(evextsb, evextsh, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE); ////
8969GEN_SPE(evrndw, evcntlzw, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE); ////
8970GEN_SPE(evcntlsw, brinc, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE); //
8971GEN_SPE(evmra, speundef, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE);
8972GEN_SPE(speundef, evand, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE); ////
8973GEN_SPE(evandc, speundef, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
8974GEN_SPE(evxor, evor, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
8975GEN_SPE(evnor, eveqv, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
8976GEN_SPE(evmwumi, evmwsmi, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE);
8977GEN_SPE(evmwumia, evmwsmia, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE);
8978GEN_SPE(evmwumiaa, evmwsmiaa, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE);
8979GEN_SPE(speundef, evorc, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE); ////
8980GEN_SPE(evnand, speundef, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
8981GEN_SPE(evsrwu, evsrws, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
8982GEN_SPE(evsrwiu, evsrwis, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE);
8983GEN_SPE(evslw, speundef, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
8984GEN_SPE(evslwi, speundef, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE);
8985GEN_SPE(evrlw, evsplati, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE); //
8986GEN_SPE(evrlwi, evsplatfi, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE);
8987GEN_SPE(evmergehi, evmergelo, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
8988GEN_SPE(evmergehilo, evmergelohi, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
8989GEN_SPE(evcmpgtu, evcmpgts, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE); ////
8990GEN_SPE(evcmpltu, evcmplts, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE); ////
8991GEN_SPE(evcmpeq, speundef, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE); ////
0487d6a8 8992
6a6ae23f 8993/* SPE load and stores */
636aa200 8994static inline void gen_addr_spe_imm_index(DisasContext *ctx, TCGv EA, int sh)
6a6ae23f
AJ
8995{
8996 target_ulong uimm = rB(ctx->opcode);
8997
76db3ba4 8998 if (rA(ctx->opcode) == 0) {
6a6ae23f 8999 tcg_gen_movi_tl(EA, uimm << sh);
76db3ba4 9000 } else {
6a6ae23f 9001 tcg_gen_addi_tl(EA, cpu_gpr[rA(ctx->opcode)], uimm << sh);
c791fe84 9002 if (NARROW_MODE(ctx)) {
76db3ba4
AJ
9003 tcg_gen_ext32u_tl(EA, EA);
9004 }
76db3ba4 9005 }
0487d6a8 9006}
6a6ae23f 9007
636aa200 9008static inline void gen_op_evldd(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9009{
9010#if defined(TARGET_PPC64)
76db3ba4 9011 gen_qemu_ld64(ctx, cpu_gpr[rD(ctx->opcode)], addr);
6a6ae23f
AJ
9012#else
9013 TCGv_i64 t0 = tcg_temp_new_i64();
76db3ba4 9014 gen_qemu_ld64(ctx, t0, addr);
6a6ae23f
AJ
9015 tcg_gen_trunc_i64_i32(cpu_gpr[rD(ctx->opcode)], t0);
9016 tcg_gen_shri_i64(t0, t0, 32);
9017 tcg_gen_trunc_i64_i32(cpu_gprh[rD(ctx->opcode)], t0);
9018 tcg_temp_free_i64(t0);
9019#endif
0487d6a8 9020}
6a6ae23f 9021
636aa200 9022static inline void gen_op_evldw(DisasContext *ctx, TCGv addr)
6a6ae23f 9023{
0487d6a8 9024#if defined(TARGET_PPC64)
6a6ae23f 9025 TCGv t0 = tcg_temp_new();
76db3ba4 9026 gen_qemu_ld32u(ctx, t0, addr);
6a6ae23f 9027 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32);
76db3ba4
AJ
9028 gen_addr_add(ctx, addr, addr, 4);
9029 gen_qemu_ld32u(ctx, t0, addr);
6a6ae23f
AJ
9030 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
9031 tcg_temp_free(t0);
9032#else
76db3ba4
AJ
9033 gen_qemu_ld32u(ctx, cpu_gprh[rD(ctx->opcode)], addr);
9034 gen_addr_add(ctx, addr, addr, 4);
9035 gen_qemu_ld32u(ctx, cpu_gpr[rD(ctx->opcode)], addr);
6a6ae23f 9036#endif
0487d6a8 9037}
6a6ae23f 9038
636aa200 9039static inline void gen_op_evldh(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9040{
9041 TCGv t0 = tcg_temp_new();
9042#if defined(TARGET_PPC64)
76db3ba4 9043 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 9044 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48);
76db3ba4
AJ
9045 gen_addr_add(ctx, addr, addr, 2);
9046 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
9047 tcg_gen_shli_tl(t0, t0, 32);
9048 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
76db3ba4
AJ
9049 gen_addr_add(ctx, addr, addr, 2);
9050 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
9051 tcg_gen_shli_tl(t0, t0, 16);
9052 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
76db3ba4
AJ
9053 gen_addr_add(ctx, addr, addr, 2);
9054 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 9055 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
0487d6a8 9056#else
76db3ba4 9057 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 9058 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
76db3ba4
AJ
9059 gen_addr_add(ctx, addr, addr, 2);
9060 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 9061 tcg_gen_or_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0);
76db3ba4
AJ
9062 gen_addr_add(ctx, addr, addr, 2);
9063 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 9064 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
76db3ba4
AJ
9065 gen_addr_add(ctx, addr, addr, 2);
9066 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 9067 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
0487d6a8 9068#endif
6a6ae23f 9069 tcg_temp_free(t0);
0487d6a8
JM
9070}
9071
636aa200 9072static inline void gen_op_evlhhesplat(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9073{
9074 TCGv t0 = tcg_temp_new();
76db3ba4 9075 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
9076#if defined(TARGET_PPC64)
9077 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48);
9078 tcg_gen_shli_tl(t0, t0, 16);
9079 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
9080#else
9081 tcg_gen_shli_tl(t0, t0, 16);
9082 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
9083 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
9084#endif
9085 tcg_temp_free(t0);
0487d6a8
JM
9086}
9087
636aa200 9088static inline void gen_op_evlhhousplat(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9089{
9090 TCGv t0 = tcg_temp_new();
76db3ba4 9091 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
9092#if defined(TARGET_PPC64)
9093 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32);
9094 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
9095#else
9096 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
9097 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
9098#endif
9099 tcg_temp_free(t0);
0487d6a8
JM
9100}
9101
636aa200 9102static inline void gen_op_evlhhossplat(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9103{
9104 TCGv t0 = tcg_temp_new();
76db3ba4 9105 gen_qemu_ld16s(ctx, t0, addr);
6a6ae23f
AJ
9106#if defined(TARGET_PPC64)
9107 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32);
9108 tcg_gen_ext32u_tl(t0, t0);
9109 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
9110#else
9111 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
9112 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
9113#endif
9114 tcg_temp_free(t0);
9115}
9116
636aa200 9117static inline void gen_op_evlwhe(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9118{
9119 TCGv t0 = tcg_temp_new();
9120#if defined(TARGET_PPC64)
76db3ba4 9121 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 9122 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48);
76db3ba4
AJ
9123 gen_addr_add(ctx, addr, addr, 2);
9124 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
9125 tcg_gen_shli_tl(t0, t0, 16);
9126 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
9127#else
76db3ba4 9128 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 9129 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
76db3ba4
AJ
9130 gen_addr_add(ctx, addr, addr, 2);
9131 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
9132 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 16);
9133#endif
9134 tcg_temp_free(t0);
9135}
9136
636aa200 9137static inline void gen_op_evlwhou(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9138{
9139#if defined(TARGET_PPC64)
9140 TCGv t0 = tcg_temp_new();
76db3ba4
AJ
9141 gen_qemu_ld16u(ctx, cpu_gpr[rD(ctx->opcode)], addr);
9142 gen_addr_add(ctx, addr, addr, 2);
9143 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
9144 tcg_gen_shli_tl(t0, t0, 32);
9145 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
9146 tcg_temp_free(t0);
9147#else
76db3ba4
AJ
9148 gen_qemu_ld16u(ctx, cpu_gprh[rD(ctx->opcode)], addr);
9149 gen_addr_add(ctx, addr, addr, 2);
9150 gen_qemu_ld16u(ctx, cpu_gpr[rD(ctx->opcode)], addr);
6a6ae23f
AJ
9151#endif
9152}
9153
636aa200 9154static inline void gen_op_evlwhos(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9155{
9156#if defined(TARGET_PPC64)
9157 TCGv t0 = tcg_temp_new();
76db3ba4 9158 gen_qemu_ld16s(ctx, t0, addr);
6a6ae23f 9159 tcg_gen_ext32u_tl(cpu_gpr[rD(ctx->opcode)], t0);
76db3ba4
AJ
9160 gen_addr_add(ctx, addr, addr, 2);
9161 gen_qemu_ld16s(ctx, t0, addr);
6a6ae23f
AJ
9162 tcg_gen_shli_tl(t0, t0, 32);
9163 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
9164 tcg_temp_free(t0);
9165#else
76db3ba4
AJ
9166 gen_qemu_ld16s(ctx, cpu_gprh[rD(ctx->opcode)], addr);
9167 gen_addr_add(ctx, addr, addr, 2);
9168 gen_qemu_ld16s(ctx, cpu_gpr[rD(ctx->opcode)], addr);
6a6ae23f
AJ
9169#endif
9170}
9171
636aa200 9172static inline void gen_op_evlwwsplat(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9173{
9174 TCGv t0 = tcg_temp_new();
76db3ba4 9175 gen_qemu_ld32u(ctx, t0, addr);
0487d6a8 9176#if defined(TARGET_PPC64)
6a6ae23f
AJ
9177 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32);
9178 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
9179#else
9180 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
9181 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
9182#endif
9183 tcg_temp_free(t0);
9184}
9185
636aa200 9186static inline void gen_op_evlwhsplat(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9187{
9188 TCGv t0 = tcg_temp_new();
9189#if defined(TARGET_PPC64)
76db3ba4 9190 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
9191 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48);
9192 tcg_gen_shli_tl(t0, t0, 32);
9193 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
76db3ba4
AJ
9194 gen_addr_add(ctx, addr, addr, 2);
9195 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
9196 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
9197 tcg_gen_shli_tl(t0, t0, 16);
9198 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
9199#else
76db3ba4 9200 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
9201 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
9202 tcg_gen_or_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0);
76db3ba4
AJ
9203 gen_addr_add(ctx, addr, addr, 2);
9204 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
9205 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 16);
9206 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0);
0487d6a8 9207#endif
6a6ae23f
AJ
9208 tcg_temp_free(t0);
9209}
9210
636aa200 9211static inline void gen_op_evstdd(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9212{
9213#if defined(TARGET_PPC64)
76db3ba4 9214 gen_qemu_st64(ctx, cpu_gpr[rS(ctx->opcode)], addr);
0487d6a8 9215#else
6a6ae23f
AJ
9216 TCGv_i64 t0 = tcg_temp_new_i64();
9217 tcg_gen_concat_i32_i64(t0, cpu_gpr[rS(ctx->opcode)], cpu_gprh[rS(ctx->opcode)]);
76db3ba4 9218 gen_qemu_st64(ctx, t0, addr);
6a6ae23f
AJ
9219 tcg_temp_free_i64(t0);
9220#endif
9221}
9222
636aa200 9223static inline void gen_op_evstdw(DisasContext *ctx, TCGv addr)
6a6ae23f 9224{
0487d6a8 9225#if defined(TARGET_PPC64)
6a6ae23f
AJ
9226 TCGv t0 = tcg_temp_new();
9227 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32);
76db3ba4 9228 gen_qemu_st32(ctx, t0, addr);
6a6ae23f
AJ
9229 tcg_temp_free(t0);
9230#else
76db3ba4 9231 gen_qemu_st32(ctx, cpu_gprh[rS(ctx->opcode)], addr);
6a6ae23f 9232#endif
76db3ba4
AJ
9233 gen_addr_add(ctx, addr, addr, 4);
9234 gen_qemu_st32(ctx, cpu_gpr[rS(ctx->opcode)], addr);
6a6ae23f
AJ
9235}
9236
636aa200 9237static inline void gen_op_evstdh(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9238{
9239 TCGv t0 = tcg_temp_new();
9240#if defined(TARGET_PPC64)
9241 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 48);
9242#else
9243 tcg_gen_shri_tl(t0, cpu_gprh[rS(ctx->opcode)], 16);
9244#endif
76db3ba4
AJ
9245 gen_qemu_st16(ctx, t0, addr);
9246 gen_addr_add(ctx, addr, addr, 2);
6a6ae23f
AJ
9247#if defined(TARGET_PPC64)
9248 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32);
76db3ba4 9249 gen_qemu_st16(ctx, t0, addr);
6a6ae23f 9250#else
76db3ba4 9251 gen_qemu_st16(ctx, cpu_gprh[rS(ctx->opcode)], addr);
6a6ae23f 9252#endif
76db3ba4 9253 gen_addr_add(ctx, addr, addr, 2);
6a6ae23f 9254 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 16);
76db3ba4 9255 gen_qemu_st16(ctx, t0, addr);
6a6ae23f 9256 tcg_temp_free(t0);
76db3ba4
AJ
9257 gen_addr_add(ctx, addr, addr, 2);
9258 gen_qemu_st16(ctx, cpu_gpr[rS(ctx->opcode)], addr);
6a6ae23f
AJ
9259}
9260
636aa200 9261static inline void gen_op_evstwhe(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9262{
9263 TCGv t0 = tcg_temp_new();
9264#if defined(TARGET_PPC64)
9265 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 48);
9266#else
9267 tcg_gen_shri_tl(t0, cpu_gprh[rS(ctx->opcode)], 16);
9268#endif
76db3ba4
AJ
9269 gen_qemu_st16(ctx, t0, addr);
9270 gen_addr_add(ctx, addr, addr, 2);
6a6ae23f 9271 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 16);
76db3ba4 9272 gen_qemu_st16(ctx, t0, addr);
6a6ae23f
AJ
9273 tcg_temp_free(t0);
9274}
9275
636aa200 9276static inline void gen_op_evstwho(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9277{
9278#if defined(TARGET_PPC64)
9279 TCGv t0 = tcg_temp_new();
9280 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32);
76db3ba4 9281 gen_qemu_st16(ctx, t0, addr);
6a6ae23f
AJ
9282 tcg_temp_free(t0);
9283#else
76db3ba4 9284 gen_qemu_st16(ctx, cpu_gprh[rS(ctx->opcode)], addr);
6a6ae23f 9285#endif
76db3ba4
AJ
9286 gen_addr_add(ctx, addr, addr, 2);
9287 gen_qemu_st16(ctx, cpu_gpr[rS(ctx->opcode)], addr);
6a6ae23f
AJ
9288}
9289
636aa200 9290static inline void gen_op_evstwwe(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9291{
9292#if defined(TARGET_PPC64)
9293 TCGv t0 = tcg_temp_new();
9294 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32);
76db3ba4 9295 gen_qemu_st32(ctx, t0, addr);
6a6ae23f
AJ
9296 tcg_temp_free(t0);
9297#else
76db3ba4 9298 gen_qemu_st32(ctx, cpu_gprh[rS(ctx->opcode)], addr);
6a6ae23f
AJ
9299#endif
9300}
9301
636aa200 9302static inline void gen_op_evstwwo(DisasContext *ctx, TCGv addr)
6a6ae23f 9303{
76db3ba4 9304 gen_qemu_st32(ctx, cpu_gpr[rS(ctx->opcode)], addr);
6a6ae23f
AJ
9305}
9306
9307#define GEN_SPEOP_LDST(name, opc2, sh) \
99e300ef 9308static void glue(gen_, name)(DisasContext *ctx) \
6a6ae23f
AJ
9309{ \
9310 TCGv t0; \
9311 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9312 gen_exception(ctx, POWERPC_EXCP_SPEU); \
6a6ae23f
AJ
9313 return; \
9314 } \
76db3ba4 9315 gen_set_access_type(ctx, ACCESS_INT); \
6a6ae23f
AJ
9316 t0 = tcg_temp_new(); \
9317 if (Rc(ctx->opcode)) { \
76db3ba4 9318 gen_addr_spe_imm_index(ctx, t0, sh); \
6a6ae23f 9319 } else { \
76db3ba4 9320 gen_addr_reg_index(ctx, t0); \
6a6ae23f
AJ
9321 } \
9322 gen_op_##name(ctx, t0); \
9323 tcg_temp_free(t0); \
9324}
9325
9326GEN_SPEOP_LDST(evldd, 0x00, 3);
9327GEN_SPEOP_LDST(evldw, 0x01, 3);
9328GEN_SPEOP_LDST(evldh, 0x02, 3);
9329GEN_SPEOP_LDST(evlhhesplat, 0x04, 1);
9330GEN_SPEOP_LDST(evlhhousplat, 0x06, 1);
9331GEN_SPEOP_LDST(evlhhossplat, 0x07, 1);
9332GEN_SPEOP_LDST(evlwhe, 0x08, 2);
9333GEN_SPEOP_LDST(evlwhou, 0x0A, 2);
9334GEN_SPEOP_LDST(evlwhos, 0x0B, 2);
9335GEN_SPEOP_LDST(evlwwsplat, 0x0C, 2);
9336GEN_SPEOP_LDST(evlwhsplat, 0x0E, 2);
9337
9338GEN_SPEOP_LDST(evstdd, 0x10, 3);
9339GEN_SPEOP_LDST(evstdw, 0x11, 3);
9340GEN_SPEOP_LDST(evstdh, 0x12, 3);
9341GEN_SPEOP_LDST(evstwhe, 0x18, 2);
9342GEN_SPEOP_LDST(evstwho, 0x1A, 2);
9343GEN_SPEOP_LDST(evstwwe, 0x1C, 2);
9344GEN_SPEOP_LDST(evstwwo, 0x1E, 2);
0487d6a8
JM
9345
9346/* Multiply and add - TODO */
9347#if 0
70560da7
FC
9348GEN_SPE(speundef, evmhessf, 0x01, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);//
9349GEN_SPE(speundef, evmhossf, 0x03, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9350GEN_SPE(evmheumi, evmhesmi, 0x04, 0x10, 0x00000000, 0x00000000, PPC_SPE);
9351GEN_SPE(speundef, evmhesmf, 0x05, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9352GEN_SPE(evmhoumi, evmhosmi, 0x06, 0x10, 0x00000000, 0x00000000, PPC_SPE);
9353GEN_SPE(speundef, evmhosmf, 0x07, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9354GEN_SPE(speundef, evmhessfa, 0x11, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9355GEN_SPE(speundef, evmhossfa, 0x13, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9356GEN_SPE(evmheumia, evmhesmia, 0x14, 0x10, 0x00000000, 0x00000000, PPC_SPE);
9357GEN_SPE(speundef, evmhesmfa, 0x15, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9358GEN_SPE(evmhoumia, evmhosmia, 0x16, 0x10, 0x00000000, 0x00000000, PPC_SPE);
9359GEN_SPE(speundef, evmhosmfa, 0x17, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9360
9361GEN_SPE(speundef, evmwhssf, 0x03, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9362GEN_SPE(evmwlumi, speundef, 0x04, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE);
9363GEN_SPE(evmwhumi, evmwhsmi, 0x06, 0x11, 0x00000000, 0x00000000, PPC_SPE);
9364GEN_SPE(speundef, evmwhsmf, 0x07, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9365GEN_SPE(speundef, evmwssf, 0x09, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9366GEN_SPE(speundef, evmwsmf, 0x0D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9367GEN_SPE(speundef, evmwhssfa, 0x13, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9368GEN_SPE(evmwlumia, speundef, 0x14, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE);
9369GEN_SPE(evmwhumia, evmwhsmia, 0x16, 0x11, 0x00000000, 0x00000000, PPC_SPE);
9370GEN_SPE(speundef, evmwhsmfa, 0x17, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9371GEN_SPE(speundef, evmwssfa, 0x19, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9372GEN_SPE(speundef, evmwsmfa, 0x1D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9373
9374GEN_SPE(evadduiaaw, evaddsiaaw, 0x00, 0x13, 0x0000F800, 0x0000F800, PPC_SPE);
9375GEN_SPE(evsubfusiaaw, evsubfssiaaw, 0x01, 0x13, 0x0000F800, 0x0000F800, PPC_SPE);
9376GEN_SPE(evaddumiaaw, evaddsmiaaw, 0x04, 0x13, 0x0000F800, 0x0000F800, PPC_SPE);
9377GEN_SPE(evsubfumiaaw, evsubfsmiaaw, 0x05, 0x13, 0x0000F800, 0x0000F800, PPC_SPE);
9378GEN_SPE(evdivws, evdivwu, 0x06, 0x13, 0x00000000, 0x00000000, PPC_SPE);
9379
9380GEN_SPE(evmheusiaaw, evmhessiaaw, 0x00, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9381GEN_SPE(speundef, evmhessfaaw, 0x01, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9382GEN_SPE(evmhousiaaw, evmhossiaaw, 0x02, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9383GEN_SPE(speundef, evmhossfaaw, 0x03, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9384GEN_SPE(evmheumiaaw, evmhesmiaaw, 0x04, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9385GEN_SPE(speundef, evmhesmfaaw, 0x05, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9386GEN_SPE(evmhoumiaaw, evmhosmiaaw, 0x06, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9387GEN_SPE(speundef, evmhosmfaaw, 0x07, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9388GEN_SPE(evmhegumiaa, evmhegsmiaa, 0x14, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9389GEN_SPE(speundef, evmhegsmfaa, 0x15, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9390GEN_SPE(evmhogumiaa, evmhogsmiaa, 0x16, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9391GEN_SPE(speundef, evmhogsmfaa, 0x17, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9392
9393GEN_SPE(evmwlusiaaw, evmwlssiaaw, 0x00, 0x15, 0x00000000, 0x00000000, PPC_SPE);
9394GEN_SPE(evmwlumiaaw, evmwlsmiaaw, 0x04, 0x15, 0x00000000, 0x00000000, PPC_SPE);
9395GEN_SPE(speundef, evmwssfaa, 0x09, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9396GEN_SPE(speundef, evmwsmfaa, 0x0D, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9397
9398GEN_SPE(evmheusianw, evmhessianw, 0x00, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9399GEN_SPE(speundef, evmhessfanw, 0x01, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9400GEN_SPE(evmhousianw, evmhossianw, 0x02, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9401GEN_SPE(speundef, evmhossfanw, 0x03, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9402GEN_SPE(evmheumianw, evmhesmianw, 0x04, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9403GEN_SPE(speundef, evmhesmfanw, 0x05, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9404GEN_SPE(evmhoumianw, evmhosmianw, 0x06, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9405GEN_SPE(speundef, evmhosmfanw, 0x07, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9406GEN_SPE(evmhegumian, evmhegsmian, 0x14, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9407GEN_SPE(speundef, evmhegsmfan, 0x15, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9408GEN_SPE(evmhigumian, evmhigsmian, 0x16, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9409GEN_SPE(speundef, evmhogsmfan, 0x17, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9410
9411GEN_SPE(evmwlusianw, evmwlssianw, 0x00, 0x17, 0x00000000, 0x00000000, PPC_SPE);
9412GEN_SPE(evmwlumianw, evmwlsmianw, 0x04, 0x17, 0x00000000, 0x00000000, PPC_SPE);
9413GEN_SPE(speundef, evmwssfan, 0x09, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9414GEN_SPE(evmwumian, evmwsmian, 0x0C, 0x17, 0x00000000, 0x00000000, PPC_SPE);
9415GEN_SPE(speundef, evmwsmfan, 0x0D, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE);
0487d6a8
JM
9416#endif
9417
9418/*** SPE floating-point extension ***/
1c97856d
AJ
9419#if defined(TARGET_PPC64)
9420#define GEN_SPEFPUOP_CONV_32_32(name) \
636aa200 9421static inline void gen_##name(DisasContext *ctx) \
0487d6a8 9422{ \
1c97856d
AJ
9423 TCGv_i32 t0; \
9424 TCGv t1; \
9425 t0 = tcg_temp_new_i32(); \
9426 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
8e703949 9427 gen_helper_##name(t0, cpu_env, t0); \
1c97856d
AJ
9428 t1 = tcg_temp_new(); \
9429 tcg_gen_extu_i32_tl(t1, t0); \
9430 tcg_temp_free_i32(t0); \
9431 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
9432 0xFFFFFFFF00000000ULL); \
9433 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t1); \
9434 tcg_temp_free(t1); \
0487d6a8 9435}
1c97856d 9436#define GEN_SPEFPUOP_CONV_32_64(name) \
636aa200 9437static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9438{ \
9439 TCGv_i32 t0; \
9440 TCGv t1; \
9441 t0 = tcg_temp_new_i32(); \
8e703949 9442 gen_helper_##name(t0, cpu_env, cpu_gpr[rB(ctx->opcode)]); \
1c97856d
AJ
9443 t1 = tcg_temp_new(); \
9444 tcg_gen_extu_i32_tl(t1, t0); \
9445 tcg_temp_free_i32(t0); \
9446 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
9447 0xFFFFFFFF00000000ULL); \
9448 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t1); \
9449 tcg_temp_free(t1); \
9450}
9451#define GEN_SPEFPUOP_CONV_64_32(name) \
636aa200 9452static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9453{ \
9454 TCGv_i32 t0 = tcg_temp_new_i32(); \
9455 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
8e703949 9456 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); \
1c97856d
AJ
9457 tcg_temp_free_i32(t0); \
9458}
9459#define GEN_SPEFPUOP_CONV_64_64(name) \
636aa200 9460static inline void gen_##name(DisasContext *ctx) \
1c97856d 9461{ \
8e703949
BS
9462 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
9463 cpu_gpr[rB(ctx->opcode)]); \
1c97856d
AJ
9464}
9465#define GEN_SPEFPUOP_ARITH2_32_32(name) \
636aa200 9466static inline void gen_##name(DisasContext *ctx) \
57951c27 9467{ \
1c97856d
AJ
9468 TCGv_i32 t0, t1; \
9469 TCGv_i64 t2; \
57951c27 9470 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9471 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
9472 return; \
9473 } \
1c97856d
AJ
9474 t0 = tcg_temp_new_i32(); \
9475 t1 = tcg_temp_new_i32(); \
9476 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
9477 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
8e703949 9478 gen_helper_##name(t0, cpu_env, t0, t1); \
1c97856d
AJ
9479 tcg_temp_free_i32(t1); \
9480 t2 = tcg_temp_new(); \
9481 tcg_gen_extu_i32_tl(t2, t0); \
9482 tcg_temp_free_i32(t0); \
9483 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
9484 0xFFFFFFFF00000000ULL); \
9485 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t2); \
9486 tcg_temp_free(t2); \
57951c27 9487}
1c97856d 9488#define GEN_SPEFPUOP_ARITH2_64_64(name) \
636aa200 9489static inline void gen_##name(DisasContext *ctx) \
57951c27
AJ
9490{ \
9491 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9492 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
9493 return; \
9494 } \
8e703949
BS
9495 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
9496 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
57951c27 9497}
1c97856d 9498#define GEN_SPEFPUOP_COMP_32(name) \
636aa200 9499static inline void gen_##name(DisasContext *ctx) \
57951c27 9500{ \
1c97856d 9501 TCGv_i32 t0, t1; \
57951c27 9502 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9503 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
9504 return; \
9505 } \
1c97856d
AJ
9506 t0 = tcg_temp_new_i32(); \
9507 t1 = tcg_temp_new_i32(); \
9508 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
9509 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
8e703949 9510 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, t0, t1); \
1c97856d
AJ
9511 tcg_temp_free_i32(t0); \
9512 tcg_temp_free_i32(t1); \
9513}
9514#define GEN_SPEFPUOP_COMP_64(name) \
636aa200 9515static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9516{ \
9517 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9518 gen_exception(ctx, POWERPC_EXCP_SPEU); \
1c97856d
AJ
9519 return; \
9520 } \
8e703949 9521 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, \
1c97856d
AJ
9522 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
9523}
9524#else
9525#define GEN_SPEFPUOP_CONV_32_32(name) \
636aa200 9526static inline void gen_##name(DisasContext *ctx) \
1c97856d 9527{ \
8e703949
BS
9528 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
9529 cpu_gpr[rB(ctx->opcode)]); \
57951c27 9530}
1c97856d 9531#define GEN_SPEFPUOP_CONV_32_64(name) \
636aa200 9532static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9533{ \
9534 TCGv_i64 t0 = tcg_temp_new_i64(); \
9535 gen_load_gpr64(t0, rB(ctx->opcode)); \
8e703949 9536 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); \
1c97856d
AJ
9537 tcg_temp_free_i64(t0); \
9538}
9539#define GEN_SPEFPUOP_CONV_64_32(name) \
636aa200 9540static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9541{ \
9542 TCGv_i64 t0 = tcg_temp_new_i64(); \
8e703949 9543 gen_helper_##name(t0, cpu_env, cpu_gpr[rB(ctx->opcode)]); \
1c97856d
AJ
9544 gen_store_gpr64(rD(ctx->opcode), t0); \
9545 tcg_temp_free_i64(t0); \
9546}
9547#define GEN_SPEFPUOP_CONV_64_64(name) \
636aa200 9548static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9549{ \
9550 TCGv_i64 t0 = tcg_temp_new_i64(); \
9551 gen_load_gpr64(t0, rB(ctx->opcode)); \
8e703949 9552 gen_helper_##name(t0, cpu_env, t0); \
1c97856d
AJ
9553 gen_store_gpr64(rD(ctx->opcode), t0); \
9554 tcg_temp_free_i64(t0); \
9555}
9556#define GEN_SPEFPUOP_ARITH2_32_32(name) \
636aa200 9557static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9558{ \
9559 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9560 gen_exception(ctx, POWERPC_EXCP_SPEU); \
1c97856d
AJ
9561 return; \
9562 } \
8e703949 9563 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
1c97856d
AJ
9564 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
9565}
9566#define GEN_SPEFPUOP_ARITH2_64_64(name) \
636aa200 9567static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9568{ \
9569 TCGv_i64 t0, t1; \
9570 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9571 gen_exception(ctx, POWERPC_EXCP_SPEU); \
1c97856d
AJ
9572 return; \
9573 } \
9574 t0 = tcg_temp_new_i64(); \
9575 t1 = tcg_temp_new_i64(); \
9576 gen_load_gpr64(t0, rA(ctx->opcode)); \
9577 gen_load_gpr64(t1, rB(ctx->opcode)); \
8e703949 9578 gen_helper_##name(t0, cpu_env, t0, t1); \
1c97856d
AJ
9579 gen_store_gpr64(rD(ctx->opcode), t0); \
9580 tcg_temp_free_i64(t0); \
9581 tcg_temp_free_i64(t1); \
9582}
9583#define GEN_SPEFPUOP_COMP_32(name) \
636aa200 9584static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9585{ \
9586 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9587 gen_exception(ctx, POWERPC_EXCP_SPEU); \
1c97856d
AJ
9588 return; \
9589 } \
8e703949 9590 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, \
1c97856d
AJ
9591 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
9592}
9593#define GEN_SPEFPUOP_COMP_64(name) \
636aa200 9594static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9595{ \
9596 TCGv_i64 t0, t1; \
9597 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9598 gen_exception(ctx, POWERPC_EXCP_SPEU); \
1c97856d
AJ
9599 return; \
9600 } \
9601 t0 = tcg_temp_new_i64(); \
9602 t1 = tcg_temp_new_i64(); \
9603 gen_load_gpr64(t0, rA(ctx->opcode)); \
9604 gen_load_gpr64(t1, rB(ctx->opcode)); \
8e703949 9605 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, t0, t1); \
1c97856d
AJ
9606 tcg_temp_free_i64(t0); \
9607 tcg_temp_free_i64(t1); \
9608}
9609#endif
57951c27 9610
0487d6a8
JM
9611/* Single precision floating-point vectors operations */
9612/* Arithmetic */
1c97856d
AJ
9613GEN_SPEFPUOP_ARITH2_64_64(evfsadd);
9614GEN_SPEFPUOP_ARITH2_64_64(evfssub);
9615GEN_SPEFPUOP_ARITH2_64_64(evfsmul);
9616GEN_SPEFPUOP_ARITH2_64_64(evfsdiv);
636aa200 9617static inline void gen_evfsabs(DisasContext *ctx)
1c97856d
AJ
9618{
9619 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9620 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9621 return;
9622 }
9623#if defined(TARGET_PPC64)
6d5c34fa 9624 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~0x8000000080000000LL);
1c97856d 9625#else
6d5c34fa
MP
9626 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~0x80000000);
9627 tcg_gen_andi_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], ~0x80000000);
1c97856d
AJ
9628#endif
9629}
636aa200 9630static inline void gen_evfsnabs(DisasContext *ctx)
1c97856d
AJ
9631{
9632 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9633 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9634 return;
9635 }
9636#if defined(TARGET_PPC64)
6d5c34fa 9637 tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000080000000LL);
1c97856d 9638#else
6d5c34fa
MP
9639 tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000);
9640 tcg_gen_ori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000);
1c97856d
AJ
9641#endif
9642}
636aa200 9643static inline void gen_evfsneg(DisasContext *ctx)
1c97856d
AJ
9644{
9645 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9646 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9647 return;
9648 }
9649#if defined(TARGET_PPC64)
6d5c34fa 9650 tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000080000000LL);
1c97856d 9651#else
6d5c34fa
MP
9652 tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000);
9653 tcg_gen_xori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000);
1c97856d
AJ
9654#endif
9655}
9656
0487d6a8 9657/* Conversion */
1c97856d
AJ
9658GEN_SPEFPUOP_CONV_64_64(evfscfui);
9659GEN_SPEFPUOP_CONV_64_64(evfscfsi);
9660GEN_SPEFPUOP_CONV_64_64(evfscfuf);
9661GEN_SPEFPUOP_CONV_64_64(evfscfsf);
9662GEN_SPEFPUOP_CONV_64_64(evfsctui);
9663GEN_SPEFPUOP_CONV_64_64(evfsctsi);
9664GEN_SPEFPUOP_CONV_64_64(evfsctuf);
9665GEN_SPEFPUOP_CONV_64_64(evfsctsf);
9666GEN_SPEFPUOP_CONV_64_64(evfsctuiz);
9667GEN_SPEFPUOP_CONV_64_64(evfsctsiz);
9668
0487d6a8 9669/* Comparison */
1c97856d
AJ
9670GEN_SPEFPUOP_COMP_64(evfscmpgt);
9671GEN_SPEFPUOP_COMP_64(evfscmplt);
9672GEN_SPEFPUOP_COMP_64(evfscmpeq);
9673GEN_SPEFPUOP_COMP_64(evfststgt);
9674GEN_SPEFPUOP_COMP_64(evfststlt);
9675GEN_SPEFPUOP_COMP_64(evfststeq);
0487d6a8
JM
9676
9677/* Opcodes definitions */
70560da7
FC
9678GEN_SPE(evfsadd, evfssub, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE); //
9679GEN_SPE(evfsabs, evfsnabs, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE); //
9680GEN_SPE(evfsneg, speundef, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9681GEN_SPE(evfsmul, evfsdiv, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE); //
9682GEN_SPE(evfscmpgt, evfscmplt, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE); //
9683GEN_SPE(evfscmpeq, speundef, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9684GEN_SPE(evfscfui, evfscfsi, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9685GEN_SPE(evfscfuf, evfscfsf, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9686GEN_SPE(evfsctui, evfsctsi, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9687GEN_SPE(evfsctuf, evfsctsf, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9688GEN_SPE(evfsctuiz, speundef, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9689GEN_SPE(evfsctsiz, speundef, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9690GEN_SPE(evfststgt, evfststlt, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE); //
9691GEN_SPE(evfststeq, speundef, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
0487d6a8
JM
9692
9693/* Single precision floating-point operations */
9694/* Arithmetic */
1c97856d
AJ
9695GEN_SPEFPUOP_ARITH2_32_32(efsadd);
9696GEN_SPEFPUOP_ARITH2_32_32(efssub);
9697GEN_SPEFPUOP_ARITH2_32_32(efsmul);
9698GEN_SPEFPUOP_ARITH2_32_32(efsdiv);
636aa200 9699static inline void gen_efsabs(DisasContext *ctx)
1c97856d
AJ
9700{
9701 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9702 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9703 return;
9704 }
6d5c34fa 9705 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], (target_long)~0x80000000LL);
1c97856d 9706}
636aa200 9707static inline void gen_efsnabs(DisasContext *ctx)
1c97856d
AJ
9708{
9709 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9710 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9711 return;
9712 }
6d5c34fa 9713 tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000);
1c97856d 9714}
636aa200 9715static inline void gen_efsneg(DisasContext *ctx)
1c97856d
AJ
9716{
9717 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9718 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9719 return;
9720 }
6d5c34fa 9721 tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000);
1c97856d
AJ
9722}
9723
0487d6a8 9724/* Conversion */
1c97856d
AJ
9725GEN_SPEFPUOP_CONV_32_32(efscfui);
9726GEN_SPEFPUOP_CONV_32_32(efscfsi);
9727GEN_SPEFPUOP_CONV_32_32(efscfuf);
9728GEN_SPEFPUOP_CONV_32_32(efscfsf);
9729GEN_SPEFPUOP_CONV_32_32(efsctui);
9730GEN_SPEFPUOP_CONV_32_32(efsctsi);
9731GEN_SPEFPUOP_CONV_32_32(efsctuf);
9732GEN_SPEFPUOP_CONV_32_32(efsctsf);
9733GEN_SPEFPUOP_CONV_32_32(efsctuiz);
9734GEN_SPEFPUOP_CONV_32_32(efsctsiz);
9735GEN_SPEFPUOP_CONV_32_64(efscfd);
9736
0487d6a8 9737/* Comparison */
1c97856d
AJ
9738GEN_SPEFPUOP_COMP_32(efscmpgt);
9739GEN_SPEFPUOP_COMP_32(efscmplt);
9740GEN_SPEFPUOP_COMP_32(efscmpeq);
9741GEN_SPEFPUOP_COMP_32(efststgt);
9742GEN_SPEFPUOP_COMP_32(efststlt);
9743GEN_SPEFPUOP_COMP_32(efststeq);
0487d6a8
JM
9744
9745/* Opcodes definitions */
70560da7
FC
9746GEN_SPE(efsadd, efssub, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE); //
9747GEN_SPE(efsabs, efsnabs, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE); //
9748GEN_SPE(efsneg, speundef, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9749GEN_SPE(efsmul, efsdiv, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE); //
9750GEN_SPE(efscmpgt, efscmplt, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE); //
9751GEN_SPE(efscmpeq, efscfd, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE); //
9752GEN_SPE(efscfui, efscfsi, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9753GEN_SPE(efscfuf, efscfsf, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9754GEN_SPE(efsctui, efsctsi, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9755GEN_SPE(efsctuf, efsctsf, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9756GEN_SPE(efsctuiz, speundef, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9757GEN_SPE(efsctsiz, speundef, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9758GEN_SPE(efststgt, efststlt, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE); //
9759GEN_SPE(efststeq, speundef, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
0487d6a8
JM
9760
9761/* Double precision floating-point operations */
9762/* Arithmetic */
1c97856d
AJ
9763GEN_SPEFPUOP_ARITH2_64_64(efdadd);
9764GEN_SPEFPUOP_ARITH2_64_64(efdsub);
9765GEN_SPEFPUOP_ARITH2_64_64(efdmul);
9766GEN_SPEFPUOP_ARITH2_64_64(efddiv);
636aa200 9767static inline void gen_efdabs(DisasContext *ctx)
1c97856d
AJ
9768{
9769 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9770 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9771 return;
9772 }
9773#if defined(TARGET_PPC64)
6d5c34fa 9774 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~0x8000000000000000LL);
1c97856d 9775#else
6d5c34fa
MP
9776 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
9777 tcg_gen_andi_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], ~0x80000000);
1c97856d
AJ
9778#endif
9779}
636aa200 9780static inline void gen_efdnabs(DisasContext *ctx)
1c97856d
AJ
9781{
9782 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9783 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9784 return;
9785 }
9786#if defined(TARGET_PPC64)
6d5c34fa 9787 tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000000000000LL);
1c97856d 9788#else
6d5c34fa
MP
9789 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
9790 tcg_gen_ori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000);
1c97856d
AJ
9791#endif
9792}
636aa200 9793static inline void gen_efdneg(DisasContext *ctx)
1c97856d
AJ
9794{
9795 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9796 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9797 return;
9798 }
9799#if defined(TARGET_PPC64)
6d5c34fa 9800 tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000000000000LL);
1c97856d 9801#else
6d5c34fa
MP
9802 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
9803 tcg_gen_xori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000);
1c97856d
AJ
9804#endif
9805}
9806
0487d6a8 9807/* Conversion */
1c97856d
AJ
9808GEN_SPEFPUOP_CONV_64_32(efdcfui);
9809GEN_SPEFPUOP_CONV_64_32(efdcfsi);
9810GEN_SPEFPUOP_CONV_64_32(efdcfuf);
9811GEN_SPEFPUOP_CONV_64_32(efdcfsf);
9812GEN_SPEFPUOP_CONV_32_64(efdctui);
9813GEN_SPEFPUOP_CONV_32_64(efdctsi);
9814GEN_SPEFPUOP_CONV_32_64(efdctuf);
9815GEN_SPEFPUOP_CONV_32_64(efdctsf);
9816GEN_SPEFPUOP_CONV_32_64(efdctuiz);
9817GEN_SPEFPUOP_CONV_32_64(efdctsiz);
9818GEN_SPEFPUOP_CONV_64_32(efdcfs);
9819GEN_SPEFPUOP_CONV_64_64(efdcfuid);
9820GEN_SPEFPUOP_CONV_64_64(efdcfsid);
9821GEN_SPEFPUOP_CONV_64_64(efdctuidz);
9822GEN_SPEFPUOP_CONV_64_64(efdctsidz);
0487d6a8 9823
0487d6a8 9824/* Comparison */
1c97856d
AJ
9825GEN_SPEFPUOP_COMP_64(efdcmpgt);
9826GEN_SPEFPUOP_COMP_64(efdcmplt);
9827GEN_SPEFPUOP_COMP_64(efdcmpeq);
9828GEN_SPEFPUOP_COMP_64(efdtstgt);
9829GEN_SPEFPUOP_COMP_64(efdtstlt);
9830GEN_SPEFPUOP_COMP_64(efdtsteq);
0487d6a8
JM
9831
9832/* Opcodes definitions */
70560da7
FC
9833GEN_SPE(efdadd, efdsub, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE); //
9834GEN_SPE(efdcfuid, efdcfsid, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9835GEN_SPE(efdabs, efdnabs, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE); //
9836GEN_SPE(efdneg, speundef, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE); //
9837GEN_SPE(efdmul, efddiv, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE); //
9838GEN_SPE(efdctuidz, efdctsidz, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9839GEN_SPE(efdcmpgt, efdcmplt, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE); //
9840GEN_SPE(efdcmpeq, efdcfs, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE); //
9841GEN_SPE(efdcfui, efdcfsi, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9842GEN_SPE(efdcfuf, efdcfsf, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9843GEN_SPE(efdctui, efdctsi, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9844GEN_SPE(efdctuf, efdctsf, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9845GEN_SPE(efdctuiz, speundef, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE); //
9846GEN_SPE(efdctsiz, speundef, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE); //
9847GEN_SPE(efdtstgt, efdtstlt, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE); //
9848GEN_SPE(efdtsteq, speundef, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE); //
0487d6a8 9849
c227f099 9850static opcode_t opcodes[] = {
5c55ff99
BS
9851GEN_HANDLER(invalid, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE),
9852GEN_HANDLER(cmp, 0x1F, 0x00, 0x00, 0x00400000, PPC_INTEGER),
9853GEN_HANDLER(cmpi, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER),
9854GEN_HANDLER(cmpl, 0x1F, 0x00, 0x01, 0x00400000, PPC_INTEGER),
9855GEN_HANDLER(cmpli, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER),
fcfda20f 9856GEN_HANDLER_E(cmpb, 0x1F, 0x1C, 0x0F, 0x00000001, PPC_NONE, PPC2_ISA205),
5c55ff99
BS
9857GEN_HANDLER(isel, 0x1F, 0x0F, 0xFF, 0x00000001, PPC_ISEL),
9858GEN_HANDLER(addi, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9859GEN_HANDLER(addic, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9860GEN_HANDLER2(addic_, "addic.", 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9861GEN_HANDLER(addis, 0x0F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9862GEN_HANDLER(mulhw, 0x1F, 0x0B, 0x02, 0x00000400, PPC_INTEGER),
9863GEN_HANDLER(mulhwu, 0x1F, 0x0B, 0x00, 0x00000400, PPC_INTEGER),
9864GEN_HANDLER(mullw, 0x1F, 0x0B, 0x07, 0x00000000, PPC_INTEGER),
9865GEN_HANDLER(mullwo, 0x1F, 0x0B, 0x17, 0x00000000, PPC_INTEGER),
9866GEN_HANDLER(mulli, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9867#if defined(TARGET_PPC64)
9868GEN_HANDLER(mulld, 0x1F, 0x09, 0x07, 0x00000000, PPC_64B),
9869#endif
9870GEN_HANDLER(neg, 0x1F, 0x08, 0x03, 0x0000F800, PPC_INTEGER),
9871GEN_HANDLER(nego, 0x1F, 0x08, 0x13, 0x0000F800, PPC_INTEGER),
9872GEN_HANDLER(subfic, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9873GEN_HANDLER2(andi_, "andi.", 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9874GEN_HANDLER2(andis_, "andis.", 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9875GEN_HANDLER(cntlzw, 0x1F, 0x1A, 0x00, 0x00000000, PPC_INTEGER),
9876GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER),
9877GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER),
9878GEN_HANDLER(ori, 0x18, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9879GEN_HANDLER(oris, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9880GEN_HANDLER(xori, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9881GEN_HANDLER(xoris, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9882GEN_HANDLER(popcntb, 0x1F, 0x03, 0x03, 0x0000F801, PPC_POPCNTB),
eaabeef2 9883GEN_HANDLER(popcntw, 0x1F, 0x1A, 0x0b, 0x0000F801, PPC_POPCNTWD),
725bcec2 9884GEN_HANDLER_E(prtyw, 0x1F, 0x1A, 0x04, 0x0000F801, PPC_NONE, PPC2_ISA205),
5c55ff99 9885#if defined(TARGET_PPC64)
eaabeef2 9886GEN_HANDLER(popcntd, 0x1F, 0x1A, 0x0F, 0x0000F801, PPC_POPCNTWD),
5c55ff99 9887GEN_HANDLER(cntlzd, 0x1F, 0x1A, 0x01, 0x00000000, PPC_64B),
725bcec2 9888GEN_HANDLER_E(prtyd, 0x1F, 0x1A, 0x05, 0x0000F801, PPC_NONE, PPC2_ISA205),
86ba37ed 9889GEN_HANDLER_E(bpermd, 0x1F, 0x1C, 0x07, 0x00000001, PPC_NONE, PPC2_PERM_ISA206),
5c55ff99
BS
9890#endif
9891GEN_HANDLER(rlwimi, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9892GEN_HANDLER(rlwinm, 0x15, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9893GEN_HANDLER(rlwnm, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9894GEN_HANDLER(slw, 0x1F, 0x18, 0x00, 0x00000000, PPC_INTEGER),
9895GEN_HANDLER(sraw, 0x1F, 0x18, 0x18, 0x00000000, PPC_INTEGER),
9896GEN_HANDLER(srawi, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER),
9897GEN_HANDLER(srw, 0x1F, 0x18, 0x10, 0x00000000, PPC_INTEGER),
9898#if defined(TARGET_PPC64)
9899GEN_HANDLER(sld, 0x1F, 0x1B, 0x00, 0x00000000, PPC_64B),
9900GEN_HANDLER(srad, 0x1F, 0x1A, 0x18, 0x00000000, PPC_64B),
9901GEN_HANDLER2(sradi0, "sradi", 0x1F, 0x1A, 0x19, 0x00000000, PPC_64B),
9902GEN_HANDLER2(sradi1, "sradi", 0x1F, 0x1B, 0x19, 0x00000000, PPC_64B),
9903GEN_HANDLER(srd, 0x1F, 0x1B, 0x10, 0x00000000, PPC_64B),
9904#endif
9905GEN_HANDLER(frsqrtes, 0x3B, 0x1A, 0xFF, 0x001F07C0, PPC_FLOAT_FRSQRTES),
9906GEN_HANDLER(fsqrt, 0x3F, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT),
9907GEN_HANDLER(fsqrts, 0x3B, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT),
9908GEN_HANDLER(fcmpo, 0x3F, 0x00, 0x01, 0x00600001, PPC_FLOAT),
9909GEN_HANDLER(fcmpu, 0x3F, 0x00, 0x00, 0x00600001, PPC_FLOAT),
bf45a2e6 9910GEN_HANDLER(fabs, 0x3F, 0x08, 0x08, 0x001F0000, PPC_FLOAT),
5c55ff99 9911GEN_HANDLER(fmr, 0x3F, 0x08, 0x02, 0x001F0000, PPC_FLOAT),
bf45a2e6
AJ
9912GEN_HANDLER(fnabs, 0x3F, 0x08, 0x04, 0x001F0000, PPC_FLOAT),
9913GEN_HANDLER(fneg, 0x3F, 0x08, 0x01, 0x001F0000, PPC_FLOAT),
f0332888 9914GEN_HANDLER_E(fcpsgn, 0x3F, 0x08, 0x00, 0x00000000, PPC_NONE, PPC2_ISA205),
097ec5d8
TM
9915GEN_HANDLER_E(fmrgew, 0x3F, 0x06, 0x1E, 0x00000001, PPC_NONE, PPC2_VSX207),
9916GEN_HANDLER_E(fmrgow, 0x3F, 0x06, 0x1A, 0x00000001, PPC_NONE, PPC2_VSX207),
5c55ff99
BS
9917GEN_HANDLER(mcrfs, 0x3F, 0x00, 0x02, 0x0063F801, PPC_FLOAT),
9918GEN_HANDLER(mffs, 0x3F, 0x07, 0x12, 0x001FF800, PPC_FLOAT),
9919GEN_HANDLER(mtfsb0, 0x3F, 0x06, 0x02, 0x001FF800, PPC_FLOAT),
9920GEN_HANDLER(mtfsb1, 0x3F, 0x06, 0x01, 0x001FF800, PPC_FLOAT),
7d08d856
AJ
9921GEN_HANDLER(mtfsf, 0x3F, 0x07, 0x16, 0x00000000, PPC_FLOAT),
9922GEN_HANDLER(mtfsfi, 0x3F, 0x06, 0x04, 0x006e0800, PPC_FLOAT),
5c55ff99
BS
9923#if defined(TARGET_PPC64)
9924GEN_HANDLER(ld, 0x3A, 0xFF, 0xFF, 0x00000000, PPC_64B),
9925GEN_HANDLER(lq, 0x38, 0xFF, 0xFF, 0x00000000, PPC_64BX),
9926GEN_HANDLER(std, 0x3E, 0xFF, 0xFF, 0x00000000, PPC_64B),
9927#endif
9928GEN_HANDLER(lmw, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9929GEN_HANDLER(stmw, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9930GEN_HANDLER(lswi, 0x1F, 0x15, 0x12, 0x00000001, PPC_STRING),
9931GEN_HANDLER(lswx, 0x1F, 0x15, 0x10, 0x00000001, PPC_STRING),
9932GEN_HANDLER(stswi, 0x1F, 0x15, 0x16, 0x00000001, PPC_STRING),
9933GEN_HANDLER(stswx, 0x1F, 0x15, 0x14, 0x00000001, PPC_STRING),
9934GEN_HANDLER(eieio, 0x1F, 0x16, 0x1A, 0x03FFF801, PPC_MEM_EIEIO),
9935GEN_HANDLER(isync, 0x13, 0x16, 0x04, 0x03FFF801, PPC_MEM),
5c77a786
TM
9936GEN_HANDLER_E(lbarx, 0x1F, 0x14, 0x01, 0, PPC_NONE, PPC2_ATOMIC_ISA206),
9937GEN_HANDLER_E(lharx, 0x1F, 0x14, 0x03, 0, PPC_NONE, PPC2_ATOMIC_ISA206),
f844c817 9938GEN_HANDLER(lwarx, 0x1F, 0x14, 0x00, 0x00000000, PPC_RES),
587c51f7
TM
9939GEN_HANDLER_E(stbcx_, 0x1F, 0x16, 0x15, 0, PPC_NONE, PPC2_ATOMIC_ISA206),
9940GEN_HANDLER_E(sthcx_, 0x1F, 0x16, 0x16, 0, PPC_NONE, PPC2_ATOMIC_ISA206),
5c55ff99
BS
9941GEN_HANDLER2(stwcx_, "stwcx.", 0x1F, 0x16, 0x04, 0x00000000, PPC_RES),
9942#if defined(TARGET_PPC64)
f844c817 9943GEN_HANDLER(ldarx, 0x1F, 0x14, 0x02, 0x00000000, PPC_64B),
9c294d5a 9944GEN_HANDLER_E(lqarx, 0x1F, 0x14, 0x08, 0, PPC_NONE, PPC2_LSQ_ISA207),
5c55ff99 9945GEN_HANDLER2(stdcx_, "stdcx.", 0x1F, 0x16, 0x06, 0x00000000, PPC_64B),
27b95bfe 9946GEN_HANDLER_E(stqcx_, 0x1F, 0x16, 0x05, 0, PPC_NONE, PPC2_LSQ_ISA207),
5c55ff99
BS
9947#endif
9948GEN_HANDLER(sync, 0x1F, 0x16, 0x12, 0x039FF801, PPC_MEM_SYNC),
9949GEN_HANDLER(wait, 0x1F, 0x1E, 0x01, 0x03FFF801, PPC_WAIT),
9950GEN_HANDLER(b, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW),
9951GEN_HANDLER(bc, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW),
9952GEN_HANDLER(bcctr, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW),
9953GEN_HANDLER(bclr, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW),
52a4984d 9954GEN_HANDLER_E(bctar, 0x13, 0x10, 0x11, 0, PPC_NONE, PPC2_BCTAR_ISA207),
5c55ff99
BS
9955GEN_HANDLER(mcrf, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER),
9956GEN_HANDLER(rfi, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW),
9957#if defined(TARGET_PPC64)
9958GEN_HANDLER(rfid, 0x13, 0x12, 0x00, 0x03FF8001, PPC_64B),
9959GEN_HANDLER(hrfid, 0x13, 0x12, 0x08, 0x03FF8001, PPC_64H),
9960#endif
9961GEN_HANDLER(sc, 0x11, 0xFF, 0xFF, 0x03FFF01D, PPC_FLOW),
9962GEN_HANDLER(tw, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW),
9963GEN_HANDLER(twi, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW),
9964#if defined(TARGET_PPC64)
9965GEN_HANDLER(td, 0x1F, 0x04, 0x02, 0x00000001, PPC_64B),
9966GEN_HANDLER(tdi, 0x02, 0xFF, 0xFF, 0x00000000, PPC_64B),
9967#endif
9968GEN_HANDLER(mcrxr, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC),
9969GEN_HANDLER(mfcr, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC),
9970GEN_HANDLER(mfmsr, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC),
9971GEN_HANDLER(mfspr, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC),
9972GEN_HANDLER(mftb, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MFTB),
9973GEN_HANDLER(mtcrf, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC),
9974#if defined(TARGET_PPC64)
9975GEN_HANDLER(mtmsrd, 0x1F, 0x12, 0x05, 0x001EF801, PPC_64B),
9976#endif
9977GEN_HANDLER(mtmsr, 0x1F, 0x12, 0x04, 0x001FF801, PPC_MISC),
9978GEN_HANDLER(mtspr, 0x1F, 0x13, 0x0E, 0x00000001, PPC_MISC),
9979GEN_HANDLER(dcbf, 0x1F, 0x16, 0x02, 0x03C00001, PPC_CACHE),
9980GEN_HANDLER(dcbi, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE),
9981GEN_HANDLER(dcbst, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE),
3f34cf91
CLG
9982GEN_HANDLER(dcbt, 0x1F, 0x16, 0x08, 0x00000001, PPC_CACHE),
9983GEN_HANDLER(dcbtst, 0x1F, 0x16, 0x07, 0x00000001, PPC_CACHE),
8e33944f 9984GEN_HANDLER(dcbz, 0x1F, 0x16, 0x1F, 0x03C00001, PPC_CACHE_DCBZ),
5c55ff99
BS
9985GEN_HANDLER(dst, 0x1F, 0x16, 0x0A, 0x01800001, PPC_ALTIVEC),
9986GEN_HANDLER(dstst, 0x1F, 0x16, 0x0B, 0x02000001, PPC_ALTIVEC),
9987GEN_HANDLER(dss, 0x1F, 0x16, 0x19, 0x019FF801, PPC_ALTIVEC),
9988GEN_HANDLER(icbi, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE_ICBI),
9989GEN_HANDLER(dcba, 0x1F, 0x16, 0x17, 0x03E00001, PPC_CACHE_DCBA),
9990GEN_HANDLER(mfsr, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT),
9991GEN_HANDLER(mfsrin, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT),
9992GEN_HANDLER(mtsr, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT),
9993GEN_HANDLER(mtsrin, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT),
9994#if defined(TARGET_PPC64)
9995GEN_HANDLER2(mfsr_64b, "mfsr", 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT_64B),
9996GEN_HANDLER2(mfsrin_64b, "mfsrin", 0x1F, 0x13, 0x14, 0x001F0001,
9997 PPC_SEGMENT_64B),
9998GEN_HANDLER2(mtsr_64b, "mtsr", 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT_64B),
9999GEN_HANDLER2(mtsrin_64b, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001,
10000 PPC_SEGMENT_64B),
efdef95f
DG
10001GEN_HANDLER2(slbmte, "slbmte", 0x1F, 0x12, 0x0C, 0x001F0001, PPC_SEGMENT_64B),
10002GEN_HANDLER2(slbmfee, "slbmfee", 0x1F, 0x13, 0x1C, 0x001F0001, PPC_SEGMENT_64B),
10003GEN_HANDLER2(slbmfev, "slbmfev", 0x1F, 0x13, 0x1A, 0x001F0001, PPC_SEGMENT_64B),
5c55ff99
BS
10004#endif
10005GEN_HANDLER(tlbia, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA),
10006GEN_HANDLER(tlbiel, 0x1F, 0x12, 0x08, 0x03FF0001, PPC_MEM_TLBIE),
10007GEN_HANDLER(tlbie, 0x1F, 0x12, 0x09, 0x03FF0001, PPC_MEM_TLBIE),
10008GEN_HANDLER(tlbsync, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC),
10009#if defined(TARGET_PPC64)
10010GEN_HANDLER(slbia, 0x1F, 0x12, 0x0F, 0x03FFFC01, PPC_SLBI),
10011GEN_HANDLER(slbie, 0x1F, 0x12, 0x0D, 0x03FF0001, PPC_SLBI),
10012#endif
10013GEN_HANDLER(eciwx, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN),
10014GEN_HANDLER(ecowx, 0x1F, 0x16, 0x09, 0x00000001, PPC_EXTERN),
10015GEN_HANDLER(abs, 0x1F, 0x08, 0x0B, 0x0000F800, PPC_POWER_BR),
10016GEN_HANDLER(abso, 0x1F, 0x08, 0x1B, 0x0000F800, PPC_POWER_BR),
10017GEN_HANDLER(clcs, 0x1F, 0x10, 0x13, 0x0000F800, PPC_POWER_BR),
10018GEN_HANDLER(div, 0x1F, 0x0B, 0x0A, 0x00000000, PPC_POWER_BR),
10019GEN_HANDLER(divo, 0x1F, 0x0B, 0x1A, 0x00000000, PPC_POWER_BR),
10020GEN_HANDLER(divs, 0x1F, 0x0B, 0x0B, 0x00000000, PPC_POWER_BR),
10021GEN_HANDLER(divso, 0x1F, 0x0B, 0x1B, 0x00000000, PPC_POWER_BR),
10022GEN_HANDLER(doz, 0x1F, 0x08, 0x08, 0x00000000, PPC_POWER_BR),
10023GEN_HANDLER(dozo, 0x1F, 0x08, 0x18, 0x00000000, PPC_POWER_BR),
10024GEN_HANDLER(dozi, 0x09, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR),
10025GEN_HANDLER(lscbx, 0x1F, 0x15, 0x08, 0x00000000, PPC_POWER_BR),
10026GEN_HANDLER(maskg, 0x1F, 0x1D, 0x00, 0x00000000, PPC_POWER_BR),
10027GEN_HANDLER(maskir, 0x1F, 0x1D, 0x10, 0x00000000, PPC_POWER_BR),
10028GEN_HANDLER(mul, 0x1F, 0x0B, 0x03, 0x00000000, PPC_POWER_BR),
10029GEN_HANDLER(mulo, 0x1F, 0x0B, 0x13, 0x00000000, PPC_POWER_BR),
10030GEN_HANDLER(nabs, 0x1F, 0x08, 0x0F, 0x00000000, PPC_POWER_BR),
10031GEN_HANDLER(nabso, 0x1F, 0x08, 0x1F, 0x00000000, PPC_POWER_BR),
10032GEN_HANDLER(rlmi, 0x16, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR),
10033GEN_HANDLER(rrib, 0x1F, 0x19, 0x10, 0x00000000, PPC_POWER_BR),
10034GEN_HANDLER(sle, 0x1F, 0x19, 0x04, 0x00000000, PPC_POWER_BR),
10035GEN_HANDLER(sleq, 0x1F, 0x19, 0x06, 0x00000000, PPC_POWER_BR),
10036GEN_HANDLER(sliq, 0x1F, 0x18, 0x05, 0x00000000, PPC_POWER_BR),
10037GEN_HANDLER(slliq, 0x1F, 0x18, 0x07, 0x00000000, PPC_POWER_BR),
10038GEN_HANDLER(sllq, 0x1F, 0x18, 0x06, 0x00000000, PPC_POWER_BR),
10039GEN_HANDLER(slq, 0x1F, 0x18, 0x04, 0x00000000, PPC_POWER_BR),
10040GEN_HANDLER(sraiq, 0x1F, 0x18, 0x1D, 0x00000000, PPC_POWER_BR),
10041GEN_HANDLER(sraq, 0x1F, 0x18, 0x1C, 0x00000000, PPC_POWER_BR),
10042GEN_HANDLER(sre, 0x1F, 0x19, 0x14, 0x00000000, PPC_POWER_BR),
10043GEN_HANDLER(srea, 0x1F, 0x19, 0x1C, 0x00000000, PPC_POWER_BR),
10044GEN_HANDLER(sreq, 0x1F, 0x19, 0x16, 0x00000000, PPC_POWER_BR),
10045GEN_HANDLER(sriq, 0x1F, 0x18, 0x15, 0x00000000, PPC_POWER_BR),
10046GEN_HANDLER(srliq, 0x1F, 0x18, 0x17, 0x00000000, PPC_POWER_BR),
10047GEN_HANDLER(srlq, 0x1F, 0x18, 0x16, 0x00000000, PPC_POWER_BR),
10048GEN_HANDLER(srq, 0x1F, 0x18, 0x14, 0x00000000, PPC_POWER_BR),
10049GEN_HANDLER(dsa, 0x1F, 0x14, 0x13, 0x03FFF801, PPC_602_SPEC),
10050GEN_HANDLER(esa, 0x1F, 0x14, 0x12, 0x03FFF801, PPC_602_SPEC),
10051GEN_HANDLER(mfrom, 0x1F, 0x09, 0x08, 0x03E0F801, PPC_602_SPEC),
10052GEN_HANDLER2(tlbld_6xx, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB),
10053GEN_HANDLER2(tlbli_6xx, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_6xx_TLB),
10054GEN_HANDLER2(tlbld_74xx, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_74xx_TLB),
10055GEN_HANDLER2(tlbli_74xx, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_74xx_TLB),
10056GEN_HANDLER(clf, 0x1F, 0x16, 0x03, 0x03E00000, PPC_POWER),
10057GEN_HANDLER(cli, 0x1F, 0x16, 0x0F, 0x03E00000, PPC_POWER),
10058GEN_HANDLER(dclst, 0x1F, 0x16, 0x13, 0x03E00000, PPC_POWER),
10059GEN_HANDLER(mfsri, 0x1F, 0x13, 0x13, 0x00000001, PPC_POWER),
10060GEN_HANDLER(rac, 0x1F, 0x12, 0x19, 0x00000001, PPC_POWER),
10061GEN_HANDLER(rfsvc, 0x13, 0x12, 0x02, 0x03FFF0001, PPC_POWER),
10062GEN_HANDLER(lfq, 0x38, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
10063GEN_HANDLER(lfqu, 0x39, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
10064GEN_HANDLER(lfqux, 0x1F, 0x17, 0x19, 0x00000001, PPC_POWER2),
10065GEN_HANDLER(lfqx, 0x1F, 0x17, 0x18, 0x00000001, PPC_POWER2),
10066GEN_HANDLER(stfq, 0x3C, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
10067GEN_HANDLER(stfqu, 0x3D, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
10068GEN_HANDLER(stfqux, 0x1F, 0x17, 0x1D, 0x00000001, PPC_POWER2),
10069GEN_HANDLER(stfqx, 0x1F, 0x17, 0x1C, 0x00000001, PPC_POWER2),
10070GEN_HANDLER(mfapidi, 0x1F, 0x13, 0x08, 0x0000F801, PPC_MFAPIDI),
10071GEN_HANDLER(tlbiva, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_TLBIVA),
10072GEN_HANDLER(mfdcr, 0x1F, 0x03, 0x0A, 0x00000001, PPC_DCR),
10073GEN_HANDLER(mtdcr, 0x1F, 0x03, 0x0E, 0x00000001, PPC_DCR),
10074GEN_HANDLER(mfdcrx, 0x1F, 0x03, 0x08, 0x00000000, PPC_DCRX),
10075GEN_HANDLER(mtdcrx, 0x1F, 0x03, 0x0C, 0x00000000, PPC_DCRX),
10076GEN_HANDLER(mfdcrux, 0x1F, 0x03, 0x09, 0x00000000, PPC_DCRUX),
10077GEN_HANDLER(mtdcrux, 0x1F, 0x03, 0x0D, 0x00000000, PPC_DCRUX),
10078GEN_HANDLER(dccci, 0x1F, 0x06, 0x0E, 0x03E00001, PPC_4xx_COMMON),
10079GEN_HANDLER(dcread, 0x1F, 0x06, 0x0F, 0x00000001, PPC_4xx_COMMON),
10080GEN_HANDLER2(icbt_40x, "icbt", 0x1F, 0x06, 0x08, 0x03E00001, PPC_40x_ICBT),
10081GEN_HANDLER(iccci, 0x1F, 0x06, 0x1E, 0x00000001, PPC_4xx_COMMON),
10082GEN_HANDLER(icread, 0x1F, 0x06, 0x1F, 0x03E00001, PPC_4xx_COMMON),
10083GEN_HANDLER2(rfci_40x, "rfci", 0x13, 0x13, 0x01, 0x03FF8001, PPC_40x_EXCP),
01662f3e 10084GEN_HANDLER_E(rfci, 0x13, 0x13, 0x01, 0x03FF8001, PPC_BOOKE, PPC2_BOOKE206),
5c55ff99
BS
10085GEN_HANDLER(rfdi, 0x13, 0x07, 0x01, 0x03FF8001, PPC_RFDI),
10086GEN_HANDLER(rfmci, 0x13, 0x06, 0x01, 0x03FF8001, PPC_RFMCI),
10087GEN_HANDLER2(tlbre_40x, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_40x_TLB),
10088GEN_HANDLER2(tlbsx_40x, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_40x_TLB),
10089GEN_HANDLER2(tlbwe_40x, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_TLB),
10090GEN_HANDLER2(tlbre_440, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_BOOKE),
10091GEN_HANDLER2(tlbsx_440, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_BOOKE),
10092GEN_HANDLER2(tlbwe_440, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_BOOKE),
01662f3e
AG
10093GEN_HANDLER2_E(tlbre_booke206, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001,
10094 PPC_NONE, PPC2_BOOKE206),
10095GEN_HANDLER2_E(tlbsx_booke206, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000,
10096 PPC_NONE, PPC2_BOOKE206),
10097GEN_HANDLER2_E(tlbwe_booke206, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001,
10098 PPC_NONE, PPC2_BOOKE206),
10099GEN_HANDLER2_E(tlbivax_booke206, "tlbivax", 0x1F, 0x12, 0x18, 0x00000001,
10100 PPC_NONE, PPC2_BOOKE206),
6d3db821
AG
10101GEN_HANDLER2_E(tlbilx_booke206, "tlbilx", 0x1F, 0x12, 0x00, 0x03800001,
10102 PPC_NONE, PPC2_BOOKE206),
d5d11a39
AG
10103GEN_HANDLER2_E(msgsnd, "msgsnd", 0x1F, 0x0E, 0x06, 0x03ff0001,
10104 PPC_NONE, PPC2_PRCNTL),
9e0b5cb1
AG
10105GEN_HANDLER2_E(msgclr, "msgclr", 0x1F, 0x0E, 0x07, 0x03ff0001,
10106 PPC_NONE, PPC2_PRCNTL),
5c55ff99 10107GEN_HANDLER(wrtee, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_WRTEE),
fbe73008 10108GEN_HANDLER(wrteei, 0x1F, 0x03, 0x05, 0x000E7C01, PPC_WRTEE),
5c55ff99 10109GEN_HANDLER(dlmzb, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC),
01662f3e
AG
10110GEN_HANDLER_E(mbar, 0x1F, 0x16, 0x1a, 0x001FF801,
10111 PPC_BOOKE, PPC2_BOOKE206),
dcb2b9e1 10112GEN_HANDLER(msync_4xx, 0x1F, 0x16, 0x12, 0x03FFF801, PPC_BOOKE),
01662f3e
AG
10113GEN_HANDLER2_E(icbt_440, "icbt", 0x1F, 0x16, 0x00, 0x03E00001,
10114 PPC_BOOKE, PPC2_BOOKE206),
5c55ff99
BS
10115GEN_HANDLER(lvsl, 0x1f, 0x06, 0x00, 0x00000001, PPC_ALTIVEC),
10116GEN_HANDLER(lvsr, 0x1f, 0x06, 0x01, 0x00000001, PPC_ALTIVEC),
10117GEN_HANDLER(mfvscr, 0x04, 0x2, 0x18, 0x001ff800, PPC_ALTIVEC),
10118GEN_HANDLER(mtvscr, 0x04, 0x2, 0x19, 0x03ff0000, PPC_ALTIVEC),
5c55ff99
BS
10119GEN_HANDLER(vmladduhm, 0x04, 0x11, 0xFF, 0x00000000, PPC_ALTIVEC),
10120GEN_HANDLER2(evsel0, "evsel", 0x04, 0x1c, 0x09, 0x00000000, PPC_SPE),
10121GEN_HANDLER2(evsel1, "evsel", 0x04, 0x1d, 0x09, 0x00000000, PPC_SPE),
10122GEN_HANDLER2(evsel2, "evsel", 0x04, 0x1e, 0x09, 0x00000000, PPC_SPE),
10123GEN_HANDLER2(evsel3, "evsel", 0x04, 0x1f, 0x09, 0x00000000, PPC_SPE),
10124
10125#undef GEN_INT_ARITH_ADD
10126#undef GEN_INT_ARITH_ADD_CONST
10127#define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
10128GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x00000000, PPC_INTEGER),
10129#define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
10130 add_ca, compute_ca, compute_ov) \
10131GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x0000F800, PPC_INTEGER),
10132GEN_INT_ARITH_ADD(add, 0x08, 0, 0, 0)
10133GEN_INT_ARITH_ADD(addo, 0x18, 0, 0, 1)
10134GEN_INT_ARITH_ADD(addc, 0x00, 0, 1, 0)
10135GEN_INT_ARITH_ADD(addco, 0x10, 0, 1, 1)
10136GEN_INT_ARITH_ADD(adde, 0x04, 1, 1, 0)
10137GEN_INT_ARITH_ADD(addeo, 0x14, 1, 1, 1)
10138GEN_INT_ARITH_ADD_CONST(addme, 0x07, -1LL, 1, 1, 0)
10139GEN_INT_ARITH_ADD_CONST(addmeo, 0x17, -1LL, 1, 1, 1)
10140GEN_INT_ARITH_ADD_CONST(addze, 0x06, 0, 1, 1, 0)
10141GEN_INT_ARITH_ADD_CONST(addzeo, 0x16, 0, 1, 1, 1)
10142
10143#undef GEN_INT_ARITH_DIVW
10144#define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
10145GEN_HANDLER(name, 0x1F, 0x0B, opc3, 0x00000000, PPC_INTEGER)
10146GEN_INT_ARITH_DIVW(divwu, 0x0E, 0, 0),
10147GEN_INT_ARITH_DIVW(divwuo, 0x1E, 0, 1),
10148GEN_INT_ARITH_DIVW(divw, 0x0F, 1, 0),
10149GEN_INT_ARITH_DIVW(divwo, 0x1F, 1, 1),
a98eb9e9
TM
10150GEN_HANDLER_E(divwe, 0x1F, 0x0B, 0x0D, 0, PPC_NONE, PPC2_DIVE_ISA206),
10151GEN_HANDLER_E(divweo, 0x1F, 0x0B, 0x1D, 0, PPC_NONE, PPC2_DIVE_ISA206),
6a4fda33
TM
10152GEN_HANDLER_E(divweu, 0x1F, 0x0B, 0x0C, 0, PPC_NONE, PPC2_DIVE_ISA206),
10153GEN_HANDLER_E(divweuo, 0x1F, 0x0B, 0x1C, 0, PPC_NONE, PPC2_DIVE_ISA206),
5c55ff99
BS
10154
10155#if defined(TARGET_PPC64)
10156#undef GEN_INT_ARITH_DIVD
10157#define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
10158GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
10159GEN_INT_ARITH_DIVD(divdu, 0x0E, 0, 0),
10160GEN_INT_ARITH_DIVD(divduo, 0x1E, 0, 1),
10161GEN_INT_ARITH_DIVD(divd, 0x0F, 1, 0),
10162GEN_INT_ARITH_DIVD(divdo, 0x1F, 1, 1),
10163
98d1eb27
TM
10164GEN_HANDLER_E(divdeu, 0x1F, 0x09, 0x0C, 0, PPC_NONE, PPC2_DIVE_ISA206),
10165GEN_HANDLER_E(divdeuo, 0x1F, 0x09, 0x1C, 0, PPC_NONE, PPC2_DIVE_ISA206),
e44259b6
TM
10166GEN_HANDLER_E(divde, 0x1F, 0x09, 0x0D, 0, PPC_NONE, PPC2_DIVE_ISA206),
10167GEN_HANDLER_E(divdeo, 0x1F, 0x09, 0x1D, 0, PPC_NONE, PPC2_DIVE_ISA206),
98d1eb27 10168
5c55ff99
BS
10169#undef GEN_INT_ARITH_MUL_HELPER
10170#define GEN_INT_ARITH_MUL_HELPER(name, opc3) \
10171GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
10172GEN_INT_ARITH_MUL_HELPER(mulhdu, 0x00),
10173GEN_INT_ARITH_MUL_HELPER(mulhd, 0x02),
10174GEN_INT_ARITH_MUL_HELPER(mulldo, 0x17),
10175#endif
10176
10177#undef GEN_INT_ARITH_SUBF
10178#undef GEN_INT_ARITH_SUBF_CONST
10179#define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
10180GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x00000000, PPC_INTEGER),
10181#define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
10182 add_ca, compute_ca, compute_ov) \
10183GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x0000F800, PPC_INTEGER),
10184GEN_INT_ARITH_SUBF(subf, 0x01, 0, 0, 0)
10185GEN_INT_ARITH_SUBF(subfo, 0x11, 0, 0, 1)
10186GEN_INT_ARITH_SUBF(subfc, 0x00, 0, 1, 0)
10187GEN_INT_ARITH_SUBF(subfco, 0x10, 0, 1, 1)
10188GEN_INT_ARITH_SUBF(subfe, 0x04, 1, 1, 0)
10189GEN_INT_ARITH_SUBF(subfeo, 0x14, 1, 1, 1)
10190GEN_INT_ARITH_SUBF_CONST(subfme, 0x07, -1LL, 1, 1, 0)
10191GEN_INT_ARITH_SUBF_CONST(subfmeo, 0x17, -1LL, 1, 1, 1)
10192GEN_INT_ARITH_SUBF_CONST(subfze, 0x06, 0, 1, 1, 0)
10193GEN_INT_ARITH_SUBF_CONST(subfzeo, 0x16, 0, 1, 1, 1)
10194
10195#undef GEN_LOGICAL1
10196#undef GEN_LOGICAL2
10197#define GEN_LOGICAL2(name, tcg_op, opc, type) \
10198GEN_HANDLER(name, 0x1F, 0x1C, opc, 0x00000000, type)
10199#define GEN_LOGICAL1(name, tcg_op, opc, type) \
10200GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, type)
10201GEN_LOGICAL2(and, tcg_gen_and_tl, 0x00, PPC_INTEGER),
10202GEN_LOGICAL2(andc, tcg_gen_andc_tl, 0x01, PPC_INTEGER),
10203GEN_LOGICAL2(eqv, tcg_gen_eqv_tl, 0x08, PPC_INTEGER),
10204GEN_LOGICAL1(extsb, tcg_gen_ext8s_tl, 0x1D, PPC_INTEGER),
10205GEN_LOGICAL1(extsh, tcg_gen_ext16s_tl, 0x1C, PPC_INTEGER),
10206GEN_LOGICAL2(nand, tcg_gen_nand_tl, 0x0E, PPC_INTEGER),
10207GEN_LOGICAL2(nor, tcg_gen_nor_tl, 0x03, PPC_INTEGER),
10208GEN_LOGICAL2(orc, tcg_gen_orc_tl, 0x0C, PPC_INTEGER),
10209#if defined(TARGET_PPC64)
10210GEN_LOGICAL1(extsw, tcg_gen_ext32s_tl, 0x1E, PPC_64B),
10211#endif
10212
10213#if defined(TARGET_PPC64)
10214#undef GEN_PPC64_R2
10215#undef GEN_PPC64_R4
10216#define GEN_PPC64_R2(name, opc1, opc2) \
10217GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
10218GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
10219 PPC_64B)
10220#define GEN_PPC64_R4(name, opc1, opc2) \
10221GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
10222GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x01, 0xFF, 0x00000000, \
10223 PPC_64B), \
10224GEN_HANDLER2(name##2, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
10225 PPC_64B), \
10226GEN_HANDLER2(name##3, stringify(name), opc1, opc2 | 0x11, 0xFF, 0x00000000, \
10227 PPC_64B)
10228GEN_PPC64_R4(rldicl, 0x1E, 0x00),
10229GEN_PPC64_R4(rldicr, 0x1E, 0x02),
10230GEN_PPC64_R4(rldic, 0x1E, 0x04),
10231GEN_PPC64_R2(rldcl, 0x1E, 0x08),
10232GEN_PPC64_R2(rldcr, 0x1E, 0x09),
10233GEN_PPC64_R4(rldimi, 0x1E, 0x06),
10234#endif
10235
10236#undef _GEN_FLOAT_ACB
10237#undef GEN_FLOAT_ACB
10238#undef _GEN_FLOAT_AB
10239#undef GEN_FLOAT_AB
10240#undef _GEN_FLOAT_AC
10241#undef GEN_FLOAT_AC
10242#undef GEN_FLOAT_B
10243#undef GEN_FLOAT_BS
10244#define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
10245GEN_HANDLER(f##name, op1, op2, 0xFF, 0x00000000, type)
10246#define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
10247_GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type), \
10248_GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type)
10249#define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
10250GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type)
10251#define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
10252_GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type), \
10253_GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type)
10254#define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
10255GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type)
10256#define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
10257_GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type), \
10258_GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type)
10259#define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
10260GEN_HANDLER(f##name, 0x3F, op2, op3, 0x001F0000, type)
10261#define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
10262GEN_HANDLER(f##name, op1, op2, 0xFF, 0x001F07C0, type)
10263
10264GEN_FLOAT_AB(add, 0x15, 0x000007C0, 1, PPC_FLOAT),
10265GEN_FLOAT_AB(div, 0x12, 0x000007C0, 1, PPC_FLOAT),
10266GEN_FLOAT_AC(mul, 0x19, 0x0000F800, 1, PPC_FLOAT),
10267GEN_FLOAT_BS(re, 0x3F, 0x18, 1, PPC_FLOAT_EXT),
10268GEN_FLOAT_BS(res, 0x3B, 0x18, 1, PPC_FLOAT_FRES),
10269GEN_FLOAT_BS(rsqrte, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE),
10270_GEN_FLOAT_ACB(sel, sel, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL),
10271GEN_FLOAT_AB(sub, 0x14, 0x000007C0, 1, PPC_FLOAT),
10272GEN_FLOAT_ACB(madd, 0x1D, 1, PPC_FLOAT),
10273GEN_FLOAT_ACB(msub, 0x1C, 1, PPC_FLOAT),
10274GEN_FLOAT_ACB(nmadd, 0x1F, 1, PPC_FLOAT),
10275GEN_FLOAT_ACB(nmsub, 0x1E, 1, PPC_FLOAT),
da29cb7b 10276GEN_HANDLER_E(ftdiv, 0x3F, 0x00, 0x04, 1, PPC_NONE, PPC2_FP_TST_ISA206),
6d41d146 10277GEN_HANDLER_E(ftsqrt, 0x3F, 0x00, 0x05, 1, PPC_NONE, PPC2_FP_TST_ISA206),
5c55ff99 10278GEN_FLOAT_B(ctiw, 0x0E, 0x00, 0, PPC_FLOAT),
fab7fe42 10279GEN_HANDLER_E(fctiwu, 0x3F, 0x0E, 0x04, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
5c55ff99 10280GEN_FLOAT_B(ctiwz, 0x0F, 0x00, 0, PPC_FLOAT),
fab7fe42 10281GEN_HANDLER_E(fctiwuz, 0x3F, 0x0F, 0x04, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
5c55ff99
BS
10282GEN_FLOAT_B(rsp, 0x0C, 0x00, 1, PPC_FLOAT),
10283#if defined(TARGET_PPC64)
10284GEN_FLOAT_B(cfid, 0x0E, 0x1A, 1, PPC_64B),
28288b48
TM
10285GEN_HANDLER_E(fcfids, 0x3B, 0x0E, 0x1A, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
10286GEN_HANDLER_E(fcfidu, 0x3F, 0x0E, 0x1E, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
10287GEN_HANDLER_E(fcfidus, 0x3B, 0x0E, 0x1E, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
5c55ff99 10288GEN_FLOAT_B(ctid, 0x0E, 0x19, 0, PPC_64B),
fab7fe42 10289GEN_HANDLER_E(fctidu, 0x3F, 0x0E, 0x1D, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
5c55ff99 10290GEN_FLOAT_B(ctidz, 0x0F, 0x19, 0, PPC_64B),
fab7fe42 10291GEN_HANDLER_E(fctiduz, 0x3F, 0x0F, 0x1D, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
5c55ff99
BS
10292#endif
10293GEN_FLOAT_B(rin, 0x08, 0x0C, 1, PPC_FLOAT_EXT),
10294GEN_FLOAT_B(riz, 0x08, 0x0D, 1, PPC_FLOAT_EXT),
10295GEN_FLOAT_B(rip, 0x08, 0x0E, 1, PPC_FLOAT_EXT),
10296GEN_FLOAT_B(rim, 0x08, 0x0F, 1, PPC_FLOAT_EXT),
5c55ff99
BS
10297
10298#undef GEN_LD
10299#undef GEN_LDU
10300#undef GEN_LDUX
cd6e9320 10301#undef GEN_LDX_E
5c55ff99
BS
10302#undef GEN_LDS
10303#define GEN_LD(name, ldop, opc, type) \
10304GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
10305#define GEN_LDU(name, ldop, opc, type) \
10306GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
10307#define GEN_LDUX(name, ldop, opc2, opc3, type) \
10308GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
cd6e9320
TH
10309#define GEN_LDX_E(name, ldop, opc2, opc3, type, type2) \
10310GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2),
5c55ff99
BS
10311#define GEN_LDS(name, ldop, op, type) \
10312GEN_LD(name, ldop, op | 0x20, type) \
10313GEN_LDU(name, ldop, op | 0x21, type) \
10314GEN_LDUX(name, ldop, 0x17, op | 0x01, type) \
10315GEN_LDX(name, ldop, 0x17, op | 0x00, type)
10316
10317GEN_LDS(lbz, ld8u, 0x02, PPC_INTEGER)
10318GEN_LDS(lha, ld16s, 0x0A, PPC_INTEGER)
10319GEN_LDS(lhz, ld16u, 0x08, PPC_INTEGER)
10320GEN_LDS(lwz, ld32u, 0x00, PPC_INTEGER)
10321#if defined(TARGET_PPC64)
10322GEN_LDUX(lwa, ld32s, 0x15, 0x0B, PPC_64B)
10323GEN_LDX(lwa, ld32s, 0x15, 0x0A, PPC_64B)
10324GEN_LDUX(ld, ld64, 0x15, 0x01, PPC_64B)
10325GEN_LDX(ld, ld64, 0x15, 0x00, PPC_64B)
cd6e9320 10326GEN_LDX_E(ldbr, ld64ur, 0x14, 0x10, PPC_NONE, PPC2_DBRX)
5c55ff99
BS
10327#endif
10328GEN_LDX(lhbr, ld16ur, 0x16, 0x18, PPC_INTEGER)
10329GEN_LDX(lwbr, ld32ur, 0x16, 0x10, PPC_INTEGER)
10330
10331#undef GEN_ST
10332#undef GEN_STU
10333#undef GEN_STUX
cd6e9320 10334#undef GEN_STX_E
5c55ff99
BS
10335#undef GEN_STS
10336#define GEN_ST(name, stop, opc, type) \
10337GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
10338#define GEN_STU(name, stop, opc, type) \
10339GEN_HANDLER(stop##u, opc, 0xFF, 0xFF, 0x00000000, type),
10340#define GEN_STUX(name, stop, opc2, opc3, type) \
10341GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
cd6e9320
TH
10342#define GEN_STX_E(name, stop, opc2, opc3, type, type2) \
10343GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2),
5c55ff99
BS
10344#define GEN_STS(name, stop, op, type) \
10345GEN_ST(name, stop, op | 0x20, type) \
10346GEN_STU(name, stop, op | 0x21, type) \
10347GEN_STUX(name, stop, 0x17, op | 0x01, type) \
10348GEN_STX(name, stop, 0x17, op | 0x00, type)
10349
10350GEN_STS(stb, st8, 0x06, PPC_INTEGER)
10351GEN_STS(sth, st16, 0x0C, PPC_INTEGER)
10352GEN_STS(stw, st32, 0x04, PPC_INTEGER)
10353#if defined(TARGET_PPC64)
10354GEN_STUX(std, st64, 0x15, 0x05, PPC_64B)
10355GEN_STX(std, st64, 0x15, 0x04, PPC_64B)
cd6e9320 10356GEN_STX_E(stdbr, st64r, 0x14, 0x14, PPC_NONE, PPC2_DBRX)
5c55ff99
BS
10357#endif
10358GEN_STX(sthbr, st16r, 0x16, 0x1C, PPC_INTEGER)
10359GEN_STX(stwbr, st32r, 0x16, 0x14, PPC_INTEGER)
10360
10361#undef GEN_LDF
10362#undef GEN_LDUF
10363#undef GEN_LDUXF
10364#undef GEN_LDXF
10365#undef GEN_LDFS
10366#define GEN_LDF(name, ldop, opc, type) \
10367GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
10368#define GEN_LDUF(name, ldop, opc, type) \
10369GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
10370#define GEN_LDUXF(name, ldop, opc, type) \
10371GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type),
10372#define GEN_LDXF(name, ldop, opc2, opc3, type) \
10373GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
10374#define GEN_LDFS(name, ldop, op, type) \
10375GEN_LDF(name, ldop, op | 0x20, type) \
10376GEN_LDUF(name, ldop, op | 0x21, type) \
10377GEN_LDUXF(name, ldop, op | 0x01, type) \
10378GEN_LDXF(name, ldop, 0x17, op | 0x00, type)
10379
10380GEN_LDFS(lfd, ld64, 0x12, PPC_FLOAT)
10381GEN_LDFS(lfs, ld32fs, 0x10, PPC_FLOAT)
199f830d 10382GEN_HANDLER_E(lfiwax, 0x1f, 0x17, 0x1a, 0x00000001, PPC_NONE, PPC2_ISA205),
66c3e328 10383GEN_HANDLER_E(lfiwzx, 0x1f, 0x17, 0x1b, 0x1, PPC_NONE, PPC2_FP_CVT_ISA206),
05050ee8
AJ
10384GEN_HANDLER_E(lfdp, 0x39, 0xFF, 0xFF, 0x00200003, PPC_NONE, PPC2_ISA205),
10385GEN_HANDLER_E(lfdpx, 0x1F, 0x17, 0x18, 0x00200001, PPC_NONE, PPC2_ISA205),
5c55ff99
BS
10386
10387#undef GEN_STF
10388#undef GEN_STUF
10389#undef GEN_STUXF
10390#undef GEN_STXF
10391#undef GEN_STFS
10392#define GEN_STF(name, stop, opc, type) \
10393GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
10394#define GEN_STUF(name, stop, opc, type) \
10395GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
10396#define GEN_STUXF(name, stop, opc, type) \
10397GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type),
10398#define GEN_STXF(name, stop, opc2, opc3, type) \
10399GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
10400#define GEN_STFS(name, stop, op, type) \
10401GEN_STF(name, stop, op | 0x20, type) \
10402GEN_STUF(name, stop, op | 0x21, type) \
10403GEN_STUXF(name, stop, op | 0x01, type) \
10404GEN_STXF(name, stop, 0x17, op | 0x00, type)
10405
10406GEN_STFS(stfd, st64, 0x16, PPC_FLOAT)
10407GEN_STFS(stfs, st32fs, 0x14, PPC_FLOAT)
10408GEN_STXF(stfiw, st32fiw, 0x17, 0x1E, PPC_FLOAT_STFIWX)
44bc0c4d
AJ
10409GEN_HANDLER_E(stfdp, 0x3D, 0xFF, 0xFF, 0x00200003, PPC_NONE, PPC2_ISA205),
10410GEN_HANDLER_E(stfdpx, 0x1F, 0x17, 0x1C, 0x00200001, PPC_NONE, PPC2_ISA205),
5c55ff99
BS
10411
10412#undef GEN_CRLOGIC
10413#define GEN_CRLOGIC(name, tcg_op, opc) \
10414GEN_HANDLER(name, 0x13, 0x01, opc, 0x00000001, PPC_INTEGER)
10415GEN_CRLOGIC(crand, tcg_gen_and_i32, 0x08),
10416GEN_CRLOGIC(crandc, tcg_gen_andc_i32, 0x04),
10417GEN_CRLOGIC(creqv, tcg_gen_eqv_i32, 0x09),
10418GEN_CRLOGIC(crnand, tcg_gen_nand_i32, 0x07),
10419GEN_CRLOGIC(crnor, tcg_gen_nor_i32, 0x01),
10420GEN_CRLOGIC(cror, tcg_gen_or_i32, 0x0E),
10421GEN_CRLOGIC(crorc, tcg_gen_orc_i32, 0x0D),
10422GEN_CRLOGIC(crxor, tcg_gen_xor_i32, 0x06),
10423
10424#undef GEN_MAC_HANDLER
10425#define GEN_MAC_HANDLER(name, opc2, opc3) \
10426GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_405_MAC)
10427GEN_MAC_HANDLER(macchw, 0x0C, 0x05),
10428GEN_MAC_HANDLER(macchwo, 0x0C, 0x15),
10429GEN_MAC_HANDLER(macchws, 0x0C, 0x07),
10430GEN_MAC_HANDLER(macchwso, 0x0C, 0x17),
10431GEN_MAC_HANDLER(macchwsu, 0x0C, 0x06),
10432GEN_MAC_HANDLER(macchwsuo, 0x0C, 0x16),
10433GEN_MAC_HANDLER(macchwu, 0x0C, 0x04),
10434GEN_MAC_HANDLER(macchwuo, 0x0C, 0x14),
10435GEN_MAC_HANDLER(machhw, 0x0C, 0x01),
10436GEN_MAC_HANDLER(machhwo, 0x0C, 0x11),
10437GEN_MAC_HANDLER(machhws, 0x0C, 0x03),
10438GEN_MAC_HANDLER(machhwso, 0x0C, 0x13),
10439GEN_MAC_HANDLER(machhwsu, 0x0C, 0x02),
10440GEN_MAC_HANDLER(machhwsuo, 0x0C, 0x12),
10441GEN_MAC_HANDLER(machhwu, 0x0C, 0x00),
10442GEN_MAC_HANDLER(machhwuo, 0x0C, 0x10),
10443GEN_MAC_HANDLER(maclhw, 0x0C, 0x0D),
10444GEN_MAC_HANDLER(maclhwo, 0x0C, 0x1D),
10445GEN_MAC_HANDLER(maclhws, 0x0C, 0x0F),
10446GEN_MAC_HANDLER(maclhwso, 0x0C, 0x1F),
10447GEN_MAC_HANDLER(maclhwu, 0x0C, 0x0C),
10448GEN_MAC_HANDLER(maclhwuo, 0x0C, 0x1C),
10449GEN_MAC_HANDLER(maclhwsu, 0x0C, 0x0E),
10450GEN_MAC_HANDLER(maclhwsuo, 0x0C, 0x1E),
10451GEN_MAC_HANDLER(nmacchw, 0x0E, 0x05),
10452GEN_MAC_HANDLER(nmacchwo, 0x0E, 0x15),
10453GEN_MAC_HANDLER(nmacchws, 0x0E, 0x07),
10454GEN_MAC_HANDLER(nmacchwso, 0x0E, 0x17),
10455GEN_MAC_HANDLER(nmachhw, 0x0E, 0x01),
10456GEN_MAC_HANDLER(nmachhwo, 0x0E, 0x11),
10457GEN_MAC_HANDLER(nmachhws, 0x0E, 0x03),
10458GEN_MAC_HANDLER(nmachhwso, 0x0E, 0x13),
10459GEN_MAC_HANDLER(nmaclhw, 0x0E, 0x0D),
10460GEN_MAC_HANDLER(nmaclhwo, 0x0E, 0x1D),
10461GEN_MAC_HANDLER(nmaclhws, 0x0E, 0x0F),
10462GEN_MAC_HANDLER(nmaclhwso, 0x0E, 0x1F),
10463GEN_MAC_HANDLER(mulchw, 0x08, 0x05),
10464GEN_MAC_HANDLER(mulchwu, 0x08, 0x04),
10465GEN_MAC_HANDLER(mulhhw, 0x08, 0x01),
10466GEN_MAC_HANDLER(mulhhwu, 0x08, 0x00),
10467GEN_MAC_HANDLER(mullhw, 0x08, 0x0D),
10468GEN_MAC_HANDLER(mullhwu, 0x08, 0x0C),
10469
10470#undef GEN_VR_LDX
10471#undef GEN_VR_STX
10472#undef GEN_VR_LVE
10473#undef GEN_VR_STVE
10474#define GEN_VR_LDX(name, opc2, opc3) \
10475GEN_HANDLER(name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10476#define GEN_VR_STX(name, opc2, opc3) \
10477GEN_HANDLER(st##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10478#define GEN_VR_LVE(name, opc2, opc3) \
10479 GEN_HANDLER(lve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10480#define GEN_VR_STVE(name, opc2, opc3) \
10481 GEN_HANDLER(stve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10482GEN_VR_LDX(lvx, 0x07, 0x03),
10483GEN_VR_LDX(lvxl, 0x07, 0x0B),
10484GEN_VR_LVE(bx, 0x07, 0x00),
10485GEN_VR_LVE(hx, 0x07, 0x01),
10486GEN_VR_LVE(wx, 0x07, 0x02),
10487GEN_VR_STX(svx, 0x07, 0x07),
10488GEN_VR_STX(svxl, 0x07, 0x0F),
10489GEN_VR_STVE(bx, 0x07, 0x04),
10490GEN_VR_STVE(hx, 0x07, 0x05),
10491GEN_VR_STVE(wx, 0x07, 0x06),
10492
10493#undef GEN_VX_LOGICAL
10494#define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \
10495GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
111c5f54
TM
10496
10497#undef GEN_VX_LOGICAL_207
10498#define GEN_VX_LOGICAL_207(name, tcg_op, opc2, opc3) \
10499GEN_HANDLER_E(name, 0x04, opc2, opc3, 0x00000000, PPC_NONE, PPC2_ALTIVEC_207)
10500
5c55ff99
BS
10501GEN_VX_LOGICAL(vand, tcg_gen_and_i64, 2, 16),
10502GEN_VX_LOGICAL(vandc, tcg_gen_andc_i64, 2, 17),
10503GEN_VX_LOGICAL(vor, tcg_gen_or_i64, 2, 18),
10504GEN_VX_LOGICAL(vxor, tcg_gen_xor_i64, 2, 19),
10505GEN_VX_LOGICAL(vnor, tcg_gen_nor_i64, 2, 20),
111c5f54
TM
10506GEN_VX_LOGICAL_207(veqv, tcg_gen_eqv_i64, 2, 26),
10507GEN_VX_LOGICAL_207(vnand, tcg_gen_nand_i64, 2, 22),
10508GEN_VX_LOGICAL_207(vorc, tcg_gen_orc_i64, 2, 21),
5c55ff99
BS
10509
10510#undef GEN_VXFORM
10511#define GEN_VXFORM(name, opc2, opc3) \
10512GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
50f5fc0c
TM
10513
10514#undef GEN_VXFORM_207
10515#define GEN_VXFORM_207(name, opc2, opc3) \
10516GEN_HANDLER_E(name, 0x04, opc2, opc3, 0x00000000, PPC_NONE, PPC2_ALTIVEC_207)
10517
5dffff5a
TM
10518#undef GEN_VXFORM_DUAL
10519#define GEN_VXFORM_DUAL(name0, name1, opc2, opc3, type0, type1) \
10520GEN_HANDLER_E(name0##_##name1, 0x4, opc2, opc3, 0x00000000, type0, type1)
10521
a737d3eb
TM
10522#undef GEN_VXRFORM_DUAL
10523#define GEN_VXRFORM_DUAL(name0, name1, opc2, opc3, tp0, tp1) \
10524GEN_HANDLER_E(name0##_##name1, 0x4, opc2, opc3, 0x00000000, tp0, tp1), \
10525GEN_HANDLER_E(name0##_##name1, 0x4, opc2, (opc3 | 0x10), 0x00000000, tp0, tp1),
10526
5c55ff99
BS
10527GEN_VXFORM(vaddubm, 0, 0),
10528GEN_VXFORM(vadduhm, 0, 1),
10529GEN_VXFORM(vadduwm, 0, 2),
56eabc75 10530GEN_VXFORM_207(vaddudm, 0, 3),
e8f7b27b
TM
10531GEN_VXFORM_DUAL(vsububm, bcdadd, 0, 16, PPC_ALTIVEC, PPC_NONE),
10532GEN_VXFORM_DUAL(vsubuhm, bcdsub, 0, 17, PPC_ALTIVEC, PPC_NONE),
5c55ff99 10533GEN_VXFORM(vsubuwm, 0, 18),
56eabc75 10534GEN_VXFORM_207(vsubudm, 0, 19),
5c55ff99
BS
10535GEN_VXFORM(vmaxub, 1, 0),
10536GEN_VXFORM(vmaxuh, 1, 1),
10537GEN_VXFORM(vmaxuw, 1, 2),
8203e31b 10538GEN_VXFORM_207(vmaxud, 1, 3),
5c55ff99
BS
10539GEN_VXFORM(vmaxsb, 1, 4),
10540GEN_VXFORM(vmaxsh, 1, 5),
10541GEN_VXFORM(vmaxsw, 1, 6),
8203e31b 10542GEN_VXFORM_207(vmaxsd, 1, 7),
5c55ff99
BS
10543GEN_VXFORM(vminub, 1, 8),
10544GEN_VXFORM(vminuh, 1, 9),
10545GEN_VXFORM(vminuw, 1, 10),
8203e31b 10546GEN_VXFORM_207(vminud, 1, 11),
5c55ff99
BS
10547GEN_VXFORM(vminsb, 1, 12),
10548GEN_VXFORM(vminsh, 1, 13),
10549GEN_VXFORM(vminsw, 1, 14),
8203e31b 10550GEN_VXFORM_207(vminsd, 1, 15),
5c55ff99
BS
10551GEN_VXFORM(vavgub, 1, 16),
10552GEN_VXFORM(vavguh, 1, 17),
10553GEN_VXFORM(vavguw, 1, 18),
10554GEN_VXFORM(vavgsb, 1, 20),
10555GEN_VXFORM(vavgsh, 1, 21),
10556GEN_VXFORM(vavgsw, 1, 22),
10557GEN_VXFORM(vmrghb, 6, 0),
10558GEN_VXFORM(vmrghh, 6, 1),
10559GEN_VXFORM(vmrghw, 6, 2),
10560GEN_VXFORM(vmrglb, 6, 4),
10561GEN_VXFORM(vmrglh, 6, 5),
10562GEN_VXFORM(vmrglw, 6, 6),
e0ffe77f
TM
10563GEN_VXFORM_207(vmrgew, 6, 30),
10564GEN_VXFORM_207(vmrgow, 6, 26),
5c55ff99
BS
10565GEN_VXFORM(vmuloub, 4, 0),
10566GEN_VXFORM(vmulouh, 4, 1),
953f0f58 10567GEN_VXFORM_DUAL(vmulouw, vmuluwm, 4, 2, PPC_ALTIVEC, PPC_NONE),
5c55ff99
BS
10568GEN_VXFORM(vmulosb, 4, 4),
10569GEN_VXFORM(vmulosh, 4, 5),
63be0936 10570GEN_VXFORM_207(vmulosw, 4, 6),
5c55ff99
BS
10571GEN_VXFORM(vmuleub, 4, 8),
10572GEN_VXFORM(vmuleuh, 4, 9),
63be0936 10573GEN_VXFORM_207(vmuleuw, 4, 10),
5c55ff99
BS
10574GEN_VXFORM(vmulesb, 4, 12),
10575GEN_VXFORM(vmulesh, 4, 13),
63be0936 10576GEN_VXFORM_207(vmulesw, 4, 14),
5c55ff99
BS
10577GEN_VXFORM(vslb, 2, 4),
10578GEN_VXFORM(vslh, 2, 5),
10579GEN_VXFORM(vslw, 2, 6),
2fdf78e6 10580GEN_VXFORM_207(vsld, 2, 23),
5c55ff99
BS
10581GEN_VXFORM(vsrb, 2, 8),
10582GEN_VXFORM(vsrh, 2, 9),
10583GEN_VXFORM(vsrw, 2, 10),
2fdf78e6 10584GEN_VXFORM_207(vsrd, 2, 27),
5c55ff99
BS
10585GEN_VXFORM(vsrab, 2, 12),
10586GEN_VXFORM(vsrah, 2, 13),
10587GEN_VXFORM(vsraw, 2, 14),
2fdf78e6 10588GEN_VXFORM_207(vsrad, 2, 15),
5c55ff99
BS
10589GEN_VXFORM(vslo, 6, 16),
10590GEN_VXFORM(vsro, 6, 17),
10591GEN_VXFORM(vaddcuw, 0, 6),
10592GEN_VXFORM(vsubcuw, 0, 22),
10593GEN_VXFORM(vaddubs, 0, 8),
10594GEN_VXFORM(vadduhs, 0, 9),
10595GEN_VXFORM(vadduws, 0, 10),
10596GEN_VXFORM(vaddsbs, 0, 12),
10597GEN_VXFORM(vaddshs, 0, 13),
10598GEN_VXFORM(vaddsws, 0, 14),
e8f7b27b
TM
10599GEN_VXFORM_DUAL(vsububs, bcdadd, 0, 24, PPC_ALTIVEC, PPC_NONE),
10600GEN_VXFORM_DUAL(vsubuhs, bcdsub, 0, 25, PPC_ALTIVEC, PPC_NONE),
5c55ff99
BS
10601GEN_VXFORM(vsubuws, 0, 26),
10602GEN_VXFORM(vsubsbs, 0, 28),
10603GEN_VXFORM(vsubshs, 0, 29),
10604GEN_VXFORM(vsubsws, 0, 30),
b41da4eb
TM
10605GEN_VXFORM_207(vadduqm, 0, 4),
10606GEN_VXFORM_207(vaddcuq, 0, 5),
10607GEN_VXFORM_DUAL(vaddeuqm, vaddecuq, 30, 0xFF, PPC_NONE, PPC2_ALTIVEC_207),
10608GEN_VXFORM_207(vsubuqm, 0, 20),
10609GEN_VXFORM_207(vsubcuq, 0, 21),
10610GEN_VXFORM_DUAL(vsubeuqm, vsubecuq, 31, 0xFF, PPC_NONE, PPC2_ALTIVEC_207),
5c55ff99
BS
10611GEN_VXFORM(vrlb, 2, 0),
10612GEN_VXFORM(vrlh, 2, 1),
10613GEN_VXFORM(vrlw, 2, 2),
2fdf78e6 10614GEN_VXFORM_207(vrld, 2, 3),
5c55ff99
BS
10615GEN_VXFORM(vsl, 2, 7),
10616GEN_VXFORM(vsr, 2, 11),
10617GEN_VXFORM(vpkuhum, 7, 0),
10618GEN_VXFORM(vpkuwum, 7, 1),
024215b2 10619GEN_VXFORM_207(vpkudum, 7, 17),
5c55ff99
BS
10620GEN_VXFORM(vpkuhus, 7, 2),
10621GEN_VXFORM(vpkuwus, 7, 3),
024215b2 10622GEN_VXFORM_207(vpkudus, 7, 19),
5c55ff99
BS
10623GEN_VXFORM(vpkshus, 7, 4),
10624GEN_VXFORM(vpkswus, 7, 5),
024215b2 10625GEN_VXFORM_207(vpksdus, 7, 21),
5c55ff99
BS
10626GEN_VXFORM(vpkshss, 7, 6),
10627GEN_VXFORM(vpkswss, 7, 7),
024215b2 10628GEN_VXFORM_207(vpksdss, 7, 23),
5c55ff99
BS
10629GEN_VXFORM(vpkpx, 7, 12),
10630GEN_VXFORM(vsum4ubs, 4, 24),
10631GEN_VXFORM(vsum4sbs, 4, 28),
10632GEN_VXFORM(vsum4shs, 4, 25),
10633GEN_VXFORM(vsum2sws, 4, 26),
10634GEN_VXFORM(vsumsws, 4, 30),
10635GEN_VXFORM(vaddfp, 5, 0),
10636GEN_VXFORM(vsubfp, 5, 1),
10637GEN_VXFORM(vmaxfp, 5, 16),
10638GEN_VXFORM(vminfp, 5, 17),
10639
10640#undef GEN_VXRFORM1
10641#undef GEN_VXRFORM
10642#define GEN_VXRFORM1(opname, name, str, opc2, opc3) \
10643 GEN_HANDLER2(name, str, 0x4, opc2, opc3, 0x00000000, PPC_ALTIVEC),
10644#define GEN_VXRFORM(name, opc2, opc3) \
10645 GEN_VXRFORM1(name, name, #name, opc2, opc3) \
10646 GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4)))
10647GEN_VXRFORM(vcmpequb, 3, 0)
10648GEN_VXRFORM(vcmpequh, 3, 1)
10649GEN_VXRFORM(vcmpequw, 3, 2)
10650GEN_VXRFORM(vcmpgtsb, 3, 12)
10651GEN_VXRFORM(vcmpgtsh, 3, 13)
10652GEN_VXRFORM(vcmpgtsw, 3, 14)
10653GEN_VXRFORM(vcmpgtub, 3, 8)
10654GEN_VXRFORM(vcmpgtuh, 3, 9)
10655GEN_VXRFORM(vcmpgtuw, 3, 10)
6f3dab41 10656GEN_VXRFORM_DUAL(vcmpeqfp, vcmpequd, 3, 3, PPC_ALTIVEC, PPC_NONE)
5c55ff99 10657GEN_VXRFORM(vcmpgefp, 3, 7)
6f3dab41
TM
10658GEN_VXRFORM_DUAL(vcmpgtfp, vcmpgtud, 3, 11, PPC_ALTIVEC, PPC_NONE)
10659GEN_VXRFORM_DUAL(vcmpbfp, vcmpgtsd, 3, 15, PPC_ALTIVEC, PPC_NONE)
5c55ff99
BS
10660
10661#undef GEN_VXFORM_SIMM
10662#define GEN_VXFORM_SIMM(name, opc2, opc3) \
10663 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
10664GEN_VXFORM_SIMM(vspltisb, 6, 12),
10665GEN_VXFORM_SIMM(vspltish, 6, 13),
10666GEN_VXFORM_SIMM(vspltisw, 6, 14),
10667
10668#undef GEN_VXFORM_NOA
10669#define GEN_VXFORM_NOA(name, opc2, opc3) \
10670 GEN_HANDLER(name, 0x04, opc2, opc3, 0x001f0000, PPC_ALTIVEC)
10671GEN_VXFORM_NOA(vupkhsb, 7, 8),
10672GEN_VXFORM_NOA(vupkhsh, 7, 9),
4430e076 10673GEN_VXFORM_207(vupkhsw, 7, 25),
5c55ff99
BS
10674GEN_VXFORM_NOA(vupklsb, 7, 10),
10675GEN_VXFORM_NOA(vupklsh, 7, 11),
4430e076 10676GEN_VXFORM_207(vupklsw, 7, 27),
5c55ff99
BS
10677GEN_VXFORM_NOA(vupkhpx, 7, 13),
10678GEN_VXFORM_NOA(vupklpx, 7, 15),
10679GEN_VXFORM_NOA(vrefp, 5, 4),
10680GEN_VXFORM_NOA(vrsqrtefp, 5, 5),
0bffbc6c 10681GEN_VXFORM_NOA(vexptefp, 5, 6),
5c55ff99
BS
10682GEN_VXFORM_NOA(vlogefp, 5, 7),
10683GEN_VXFORM_NOA(vrfim, 5, 8),
10684GEN_VXFORM_NOA(vrfin, 5, 9),
10685GEN_VXFORM_NOA(vrfip, 5, 10),
10686GEN_VXFORM_NOA(vrfiz, 5, 11),
10687
10688#undef GEN_VXFORM_UIMM
10689#define GEN_VXFORM_UIMM(name, opc2, opc3) \
10690 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
10691GEN_VXFORM_UIMM(vspltb, 6, 8),
10692GEN_VXFORM_UIMM(vsplth, 6, 9),
10693GEN_VXFORM_UIMM(vspltw, 6, 10),
10694GEN_VXFORM_UIMM(vcfux, 5, 12),
10695GEN_VXFORM_UIMM(vcfsx, 5, 13),
10696GEN_VXFORM_UIMM(vctuxs, 5, 14),
10697GEN_VXFORM_UIMM(vctsxs, 5, 15),
10698
10699#undef GEN_VAFORM_PAIRED
10700#define GEN_VAFORM_PAIRED(name0, name1, opc2) \
10701 GEN_HANDLER(name0##_##name1, 0x04, opc2, 0xFF, 0x00000000, PPC_ALTIVEC)
10702GEN_VAFORM_PAIRED(vmhaddshs, vmhraddshs, 16),
10703GEN_VAFORM_PAIRED(vmsumubm, vmsummbm, 18),
10704GEN_VAFORM_PAIRED(vmsumuhm, vmsumuhs, 19),
10705GEN_VAFORM_PAIRED(vmsumshm, vmsumshs, 20),
10706GEN_VAFORM_PAIRED(vsel, vperm, 21),
10707GEN_VAFORM_PAIRED(vmaddfp, vnmsubfp, 23),
10708
e13500b3
TM
10709GEN_VXFORM_DUAL(vclzb, vpopcntb, 1, 28, PPC_NONE, PPC2_ALTIVEC_207),
10710GEN_VXFORM_DUAL(vclzh, vpopcnth, 1, 29, PPC_NONE, PPC2_ALTIVEC_207),
10711GEN_VXFORM_DUAL(vclzw, vpopcntw, 1, 30, PPC_NONE, PPC2_ALTIVEC_207),
10712GEN_VXFORM_DUAL(vclzd, vpopcntd, 1, 31, PPC_NONE, PPC2_ALTIVEC_207),
10713
4d82038e 10714GEN_VXFORM_207(vbpermq, 6, 21),
f1064f61 10715GEN_VXFORM_207(vgbbd, 6, 20),
b8476fc7
TM
10716GEN_VXFORM_207(vpmsumb, 4, 16),
10717GEN_VXFORM_207(vpmsumh, 4, 17),
10718GEN_VXFORM_207(vpmsumw, 4, 18),
10719GEN_VXFORM_207(vpmsumd, 4, 19),
f293f04a 10720
557d52fa
TM
10721GEN_VXFORM_207(vsbox, 4, 23),
10722
10723GEN_VXFORM_DUAL(vcipher, vcipherlast, 4, 20, PPC_NONE, PPC2_ALTIVEC_207),
10724GEN_VXFORM_DUAL(vncipher, vncipherlast, 4, 21, PPC_NONE, PPC2_ALTIVEC_207),
10725
57354f8f
TM
10726GEN_VXFORM_207(vshasigmaw, 1, 26),
10727GEN_VXFORM_207(vshasigmad, 1, 27),
10728
ac174549
TM
10729GEN_VXFORM_DUAL(vsldoi, vpermxor, 22, 0xFF, PPC_ALTIVEC, PPC_NONE),
10730
fa1832d7 10731GEN_HANDLER_E(lxsdx, 0x1F, 0x0C, 0x12, 0, PPC_NONE, PPC2_VSX),
cac7f0ba
TM
10732GEN_HANDLER_E(lxsiwax, 0x1F, 0x0C, 0x02, 0, PPC_NONE, PPC2_VSX207),
10733GEN_HANDLER_E(lxsiwzx, 0x1F, 0x0C, 0x00, 0, PPC_NONE, PPC2_VSX207),
10734GEN_HANDLER_E(lxsspx, 0x1F, 0x0C, 0x10, 0, PPC_NONE, PPC2_VSX207),
304af367 10735GEN_HANDLER_E(lxvd2x, 0x1F, 0x0C, 0x1A, 0, PPC_NONE, PPC2_VSX),
ca03b467 10736GEN_HANDLER_E(lxvdsx, 0x1F, 0x0C, 0x0A, 0, PPC_NONE, PPC2_VSX),
897e61d1 10737GEN_HANDLER_E(lxvw4x, 0x1F, 0x0C, 0x18, 0, PPC_NONE, PPC2_VSX),
304af367 10738
9231ba9e 10739GEN_HANDLER_E(stxsdx, 0x1F, 0xC, 0x16, 0, PPC_NONE, PPC2_VSX),
e16a626b
TM
10740GEN_HANDLER_E(stxsiwx, 0x1F, 0xC, 0x04, 0, PPC_NONE, PPC2_VSX207),
10741GEN_HANDLER_E(stxsspx, 0x1F, 0xC, 0x14, 0, PPC_NONE, PPC2_VSX207),
fbed2478 10742GEN_HANDLER_E(stxvd2x, 0x1F, 0xC, 0x1E, 0, PPC_NONE, PPC2_VSX),
86e61ce3 10743GEN_HANDLER_E(stxvw4x, 0x1F, 0xC, 0x1C, 0, PPC_NONE, PPC2_VSX),
fbed2478 10744
f5c0f7f9
TM
10745GEN_HANDLER_E(mfvsrwz, 0x1F, 0x13, 0x03, 0x0000F800, PPC_NONE, PPC2_VSX207),
10746GEN_HANDLER_E(mtvsrwa, 0x1F, 0x13, 0x06, 0x0000F800, PPC_NONE, PPC2_VSX207),
10747GEN_HANDLER_E(mtvsrwz, 0x1F, 0x13, 0x07, 0x0000F800, PPC_NONE, PPC2_VSX207),
10748#if defined(TARGET_PPC64)
10749GEN_HANDLER_E(mfvsrd, 0x1F, 0x13, 0x01, 0x0000F800, PPC_NONE, PPC2_VSX207),
10750GEN_HANDLER_E(mtvsrd, 0x1F, 0x13, 0x05, 0x0000F800, PPC_NONE, PPC2_VSX207),
10751#endif
10752
df020ce0
TM
10753#undef GEN_XX2FORM
10754#define GEN_XX2FORM(name, opc2, opc3, fl2) \
10755GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0, opc3, 0, PPC_NONE, fl2), \
10756GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 1, opc3, 0, PPC_NONE, fl2)
10757
10758#undef GEN_XX3FORM
10759#define GEN_XX3FORM(name, opc2, opc3, fl2) \
10760GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0, opc3, 0, PPC_NONE, fl2), \
10761GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 1, opc3, 0, PPC_NONE, fl2), \
10762GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 2, opc3, 0, PPC_NONE, fl2), \
10763GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 3, opc3, 0, PPC_NONE, fl2)
10764
354a6dec
TM
10765#undef GEN_XX3_RC_FORM
10766#define GEN_XX3_RC_FORM(name, opc2, opc3, fl2) \
10767GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x00, opc3 | 0x00, 0, PPC_NONE, fl2), \
10768GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x01, opc3 | 0x00, 0, PPC_NONE, fl2), \
10769GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x02, opc3 | 0x00, 0, PPC_NONE, fl2), \
10770GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x03, opc3 | 0x00, 0, PPC_NONE, fl2), \
10771GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x00, opc3 | 0x10, 0, PPC_NONE, fl2), \
10772GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x01, opc3 | 0x10, 0, PPC_NONE, fl2), \
10773GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x02, opc3 | 0x10, 0, PPC_NONE, fl2), \
10774GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x03, opc3 | 0x10, 0, PPC_NONE, fl2)
10775
cd73f2c9
TM
10776#undef GEN_XX3FORM_DM
10777#define GEN_XX3FORM_DM(name, opc2, opc3) \
10778GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
10779GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
10780GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
10781GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
10782GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
10783GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
10784GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
10785GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
10786GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
10787GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
10788GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
10789GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
10790GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x0C, 0, PPC_NONE, PPC2_VSX),\
10791GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x0C, 0, PPC_NONE, PPC2_VSX),\
10792GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x0C, 0, PPC_NONE, PPC2_VSX),\
10793GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x0C, 0, PPC_NONE, PPC2_VSX)
10794
df020ce0
TM
10795GEN_XX2FORM(xsabsdp, 0x12, 0x15, PPC2_VSX),
10796GEN_XX2FORM(xsnabsdp, 0x12, 0x16, PPC2_VSX),
10797GEN_XX2FORM(xsnegdp, 0x12, 0x17, PPC2_VSX),
10798GEN_XX3FORM(xscpsgndp, 0x00, 0x16, PPC2_VSX),
10799
be574920
TM
10800GEN_XX2FORM(xvabsdp, 0x12, 0x1D, PPC2_VSX),
10801GEN_XX2FORM(xvnabsdp, 0x12, 0x1E, PPC2_VSX),
10802GEN_XX2FORM(xvnegdp, 0x12, 0x1F, PPC2_VSX),
10803GEN_XX3FORM(xvcpsgndp, 0x00, 0x1E, PPC2_VSX),
10804GEN_XX2FORM(xvabssp, 0x12, 0x19, PPC2_VSX),
10805GEN_XX2FORM(xvnabssp, 0x12, 0x1A, PPC2_VSX),
10806GEN_XX2FORM(xvnegsp, 0x12, 0x1B, PPC2_VSX),
10807GEN_XX3FORM(xvcpsgnsp, 0x00, 0x1A, PPC2_VSX),
79ca8a6a 10808
ee6e02c0
TM
10809GEN_XX3FORM(xsadddp, 0x00, 0x04, PPC2_VSX),
10810GEN_XX3FORM(xssubdp, 0x00, 0x05, PPC2_VSX),
5e591d88 10811GEN_XX3FORM(xsmuldp, 0x00, 0x06, PPC2_VSX),
4b98eeef 10812GEN_XX3FORM(xsdivdp, 0x00, 0x07, PPC2_VSX),
2009227f 10813GEN_XX2FORM(xsredp, 0x14, 0x05, PPC2_VSX),
d32404fe 10814GEN_XX2FORM(xssqrtdp, 0x16, 0x04, PPC2_VSX),
d3f9df8f 10815GEN_XX2FORM(xsrsqrtedp, 0x14, 0x04, PPC2_VSX),
bc80838f 10816GEN_XX3FORM(xstdivdp, 0x14, 0x07, PPC2_VSX),
5cb151ac 10817GEN_XX2FORM(xstsqrtdp, 0x14, 0x06, PPC2_VSX),
595c6eef
TM
10818GEN_XX3FORM(xsmaddadp, 0x04, 0x04, PPC2_VSX),
10819GEN_XX3FORM(xsmaddmdp, 0x04, 0x05, PPC2_VSX),
10820GEN_XX3FORM(xsmsubadp, 0x04, 0x06, PPC2_VSX),
10821GEN_XX3FORM(xsmsubmdp, 0x04, 0x07, PPC2_VSX),
10822GEN_XX3FORM(xsnmaddadp, 0x04, 0x14, PPC2_VSX),
10823GEN_XX3FORM(xsnmaddmdp, 0x04, 0x15, PPC2_VSX),
10824GEN_XX3FORM(xsnmsubadp, 0x04, 0x16, PPC2_VSX),
10825GEN_XX3FORM(xsnmsubmdp, 0x04, 0x17, PPC2_VSX),
4f17e9c7
TM
10826GEN_XX2FORM(xscmpodp, 0x0C, 0x05, PPC2_VSX),
10827GEN_XX2FORM(xscmpudp, 0x0C, 0x04, PPC2_VSX),
959e9c9d
TM
10828GEN_XX3FORM(xsmaxdp, 0x00, 0x14, PPC2_VSX),
10829GEN_XX3FORM(xsmindp, 0x00, 0x15, PPC2_VSX),
ed8ac568 10830GEN_XX2FORM(xscvdpsp, 0x12, 0x10, PPC2_VSX),
7ee19fb9 10831GEN_XX2FORM(xscvdpspn, 0x16, 0x10, PPC2_VSX207),
ed8ac568 10832GEN_XX2FORM(xscvspdp, 0x12, 0x14, PPC2_VSX),
7ee19fb9 10833GEN_XX2FORM(xscvspdpn, 0x16, 0x14, PPC2_VSX207),
5177d2ca
TM
10834GEN_XX2FORM(xscvdpsxds, 0x10, 0x15, PPC2_VSX),
10835GEN_XX2FORM(xscvdpsxws, 0x10, 0x05, PPC2_VSX),
10836GEN_XX2FORM(xscvdpuxds, 0x10, 0x14, PPC2_VSX),
10837GEN_XX2FORM(xscvdpuxws, 0x10, 0x04, PPC2_VSX),
10838GEN_XX2FORM(xscvsxddp, 0x10, 0x17, PPC2_VSX),
10839GEN_XX2FORM(xscvuxddp, 0x10, 0x16, PPC2_VSX),
88e33d08
TM
10840GEN_XX2FORM(xsrdpi, 0x12, 0x04, PPC2_VSX),
10841GEN_XX2FORM(xsrdpic, 0x16, 0x06, PPC2_VSX),
10842GEN_XX2FORM(xsrdpim, 0x12, 0x07, PPC2_VSX),
10843GEN_XX2FORM(xsrdpip, 0x12, 0x06, PPC2_VSX),
10844GEN_XX2FORM(xsrdpiz, 0x12, 0x05, PPC2_VSX),
ee6e02c0 10845
3fd0aadf
TM
10846GEN_XX3FORM(xsaddsp, 0x00, 0x00, PPC2_VSX207),
10847GEN_XX3FORM(xssubsp, 0x00, 0x01, PPC2_VSX207),
ab9408a2 10848GEN_XX3FORM(xsmulsp, 0x00, 0x02, PPC2_VSX207),
b24d0b47 10849GEN_XX3FORM(xsdivsp, 0x00, 0x03, PPC2_VSX207),
2c0c52ae 10850GEN_XX2FORM(xsresp, 0x14, 0x01, PPC2_VSX207),
3d1140bf 10851GEN_XX2FORM(xsrsp, 0x12, 0x11, PPC2_VSX207),
cea4e574 10852GEN_XX2FORM(xssqrtsp, 0x16, 0x00, PPC2_VSX207),
968e76bc 10853GEN_XX2FORM(xsrsqrtesp, 0x14, 0x00, PPC2_VSX207),
f53f81e0
TM
10854GEN_XX3FORM(xsmaddasp, 0x04, 0x00, PPC2_VSX207),
10855GEN_XX3FORM(xsmaddmsp, 0x04, 0x01, PPC2_VSX207),
10856GEN_XX3FORM(xsmsubasp, 0x04, 0x02, PPC2_VSX207),
10857GEN_XX3FORM(xsmsubmsp, 0x04, 0x03, PPC2_VSX207),
10858GEN_XX3FORM(xsnmaddasp, 0x04, 0x10, PPC2_VSX207),
10859GEN_XX3FORM(xsnmaddmsp, 0x04, 0x11, PPC2_VSX207),
10860GEN_XX3FORM(xsnmsubasp, 0x04, 0x12, PPC2_VSX207),
10861GEN_XX3FORM(xsnmsubmsp, 0x04, 0x13, PPC2_VSX207),
74698350
TM
10862GEN_XX2FORM(xscvsxdsp, 0x10, 0x13, PPC2_VSX207),
10863GEN_XX2FORM(xscvuxdsp, 0x10, 0x12, PPC2_VSX207),
3fd0aadf 10864
ee6e02c0
TM
10865GEN_XX3FORM(xvadddp, 0x00, 0x0C, PPC2_VSX),
10866GEN_XX3FORM(xvsubdp, 0x00, 0x0D, PPC2_VSX),
5e591d88 10867GEN_XX3FORM(xvmuldp, 0x00, 0x0E, PPC2_VSX),
4b98eeef 10868GEN_XX3FORM(xvdivdp, 0x00, 0x0F, PPC2_VSX),
2009227f 10869GEN_XX2FORM(xvredp, 0x14, 0x0D, PPC2_VSX),
d32404fe 10870GEN_XX2FORM(xvsqrtdp, 0x16, 0x0C, PPC2_VSX),
d3f9df8f 10871GEN_XX2FORM(xvrsqrtedp, 0x14, 0x0C, PPC2_VSX),
bc80838f 10872GEN_XX3FORM(xvtdivdp, 0x14, 0x0F, PPC2_VSX),
5cb151ac 10873GEN_XX2FORM(xvtsqrtdp, 0x14, 0x0E, PPC2_VSX),
595c6eef
TM
10874GEN_XX3FORM(xvmaddadp, 0x04, 0x0C, PPC2_VSX),
10875GEN_XX3FORM(xvmaddmdp, 0x04, 0x0D, PPC2_VSX),
10876GEN_XX3FORM(xvmsubadp, 0x04, 0x0E, PPC2_VSX),
10877GEN_XX3FORM(xvmsubmdp, 0x04, 0x0F, PPC2_VSX),
10878GEN_XX3FORM(xvnmaddadp, 0x04, 0x1C, PPC2_VSX),
10879GEN_XX3FORM(xvnmaddmdp, 0x04, 0x1D, PPC2_VSX),
10880GEN_XX3FORM(xvnmsubadp, 0x04, 0x1E, PPC2_VSX),
10881GEN_XX3FORM(xvnmsubmdp, 0x04, 0x1F, PPC2_VSX),
959e9c9d
TM
10882GEN_XX3FORM(xvmaxdp, 0x00, 0x1C, PPC2_VSX),
10883GEN_XX3FORM(xvmindp, 0x00, 0x1D, PPC2_VSX),
354a6dec
TM
10884GEN_XX3_RC_FORM(xvcmpeqdp, 0x0C, 0x0C, PPC2_VSX),
10885GEN_XX3_RC_FORM(xvcmpgtdp, 0x0C, 0x0D, PPC2_VSX),
10886GEN_XX3_RC_FORM(xvcmpgedp, 0x0C, 0x0E, PPC2_VSX),
ed8ac568 10887GEN_XX2FORM(xvcvdpsp, 0x12, 0x18, PPC2_VSX),
5177d2ca
TM
10888GEN_XX2FORM(xvcvdpsxds, 0x10, 0x1D, PPC2_VSX),
10889GEN_XX2FORM(xvcvdpsxws, 0x10, 0x0D, PPC2_VSX),
10890GEN_XX2FORM(xvcvdpuxds, 0x10, 0x1C, PPC2_VSX),
10891GEN_XX2FORM(xvcvdpuxws, 0x10, 0x0C, PPC2_VSX),
10892GEN_XX2FORM(xvcvsxddp, 0x10, 0x1F, PPC2_VSX),
10893GEN_XX2FORM(xvcvuxddp, 0x10, 0x1E, PPC2_VSX),
10894GEN_XX2FORM(xvcvsxwdp, 0x10, 0x0F, PPC2_VSX),
10895GEN_XX2FORM(xvcvuxwdp, 0x10, 0x0E, PPC2_VSX),
88e33d08
TM
10896GEN_XX2FORM(xvrdpi, 0x12, 0x0C, PPC2_VSX),
10897GEN_XX2FORM(xvrdpic, 0x16, 0x0E, PPC2_VSX),
10898GEN_XX2FORM(xvrdpim, 0x12, 0x0F, PPC2_VSX),
10899GEN_XX2FORM(xvrdpip, 0x12, 0x0E, PPC2_VSX),
10900GEN_XX2FORM(xvrdpiz, 0x12, 0x0D, PPC2_VSX),
ee6e02c0
TM
10901
10902GEN_XX3FORM(xvaddsp, 0x00, 0x08, PPC2_VSX),
10903GEN_XX3FORM(xvsubsp, 0x00, 0x09, PPC2_VSX),
5e591d88 10904GEN_XX3FORM(xvmulsp, 0x00, 0x0A, PPC2_VSX),
4b98eeef 10905GEN_XX3FORM(xvdivsp, 0x00, 0x0B, PPC2_VSX),
2009227f 10906GEN_XX2FORM(xvresp, 0x14, 0x09, PPC2_VSX),
d32404fe 10907GEN_XX2FORM(xvsqrtsp, 0x16, 0x08, PPC2_VSX),
d3f9df8f 10908GEN_XX2FORM(xvrsqrtesp, 0x14, 0x08, PPC2_VSX),
bc80838f 10909GEN_XX3FORM(xvtdivsp, 0x14, 0x0B, PPC2_VSX),
5cb151ac 10910GEN_XX2FORM(xvtsqrtsp, 0x14, 0x0A, PPC2_VSX),
595c6eef
TM
10911GEN_XX3FORM(xvmaddasp, 0x04, 0x08, PPC2_VSX),
10912GEN_XX3FORM(xvmaddmsp, 0x04, 0x09, PPC2_VSX),
10913GEN_XX3FORM(xvmsubasp, 0x04, 0x0A, PPC2_VSX),
10914GEN_XX3FORM(xvmsubmsp, 0x04, 0x0B, PPC2_VSX),
10915GEN_XX3FORM(xvnmaddasp, 0x04, 0x18, PPC2_VSX),
10916GEN_XX3FORM(xvnmaddmsp, 0x04, 0x19, PPC2_VSX),
10917GEN_XX3FORM(xvnmsubasp, 0x04, 0x1A, PPC2_VSX),
10918GEN_XX3FORM(xvnmsubmsp, 0x04, 0x1B, PPC2_VSX),
959e9c9d
TM
10919GEN_XX3FORM(xvmaxsp, 0x00, 0x18, PPC2_VSX),
10920GEN_XX3FORM(xvminsp, 0x00, 0x19, PPC2_VSX),
354a6dec
TM
10921GEN_XX3_RC_FORM(xvcmpeqsp, 0x0C, 0x08, PPC2_VSX),
10922GEN_XX3_RC_FORM(xvcmpgtsp, 0x0C, 0x09, PPC2_VSX),
10923GEN_XX3_RC_FORM(xvcmpgesp, 0x0C, 0x0A, PPC2_VSX),
ed8ac568 10924GEN_XX2FORM(xvcvspdp, 0x12, 0x1C, PPC2_VSX),
5177d2ca
TM
10925GEN_XX2FORM(xvcvspsxds, 0x10, 0x19, PPC2_VSX),
10926GEN_XX2FORM(xvcvspsxws, 0x10, 0x09, PPC2_VSX),
10927GEN_XX2FORM(xvcvspuxds, 0x10, 0x18, PPC2_VSX),
10928GEN_XX2FORM(xvcvspuxws, 0x10, 0x08, PPC2_VSX),
10929GEN_XX2FORM(xvcvsxdsp, 0x10, 0x1B, PPC2_VSX),
10930GEN_XX2FORM(xvcvuxdsp, 0x10, 0x1A, PPC2_VSX),
10931GEN_XX2FORM(xvcvsxwsp, 0x10, 0x0B, PPC2_VSX),
10932GEN_XX2FORM(xvcvuxwsp, 0x10, 0x0A, PPC2_VSX),
88e33d08
TM
10933GEN_XX2FORM(xvrspi, 0x12, 0x08, PPC2_VSX),
10934GEN_XX2FORM(xvrspic, 0x16, 0x0A, PPC2_VSX),
10935GEN_XX2FORM(xvrspim, 0x12, 0x0B, PPC2_VSX),
10936GEN_XX2FORM(xvrspip, 0x12, 0x0A, PPC2_VSX),
10937GEN_XX2FORM(xvrspiz, 0x12, 0x09, PPC2_VSX),
ee6e02c0 10938
79ca8a6a
TM
10939#undef VSX_LOGICAL
10940#define VSX_LOGICAL(name, opc2, opc3, fl2) \
10941GEN_XX3FORM(name, opc2, opc3, fl2)
10942
10943VSX_LOGICAL(xxland, 0x8, 0x10, PPC2_VSX),
10944VSX_LOGICAL(xxlandc, 0x8, 0x11, PPC2_VSX),
10945VSX_LOGICAL(xxlor, 0x8, 0x12, PPC2_VSX),
10946VSX_LOGICAL(xxlxor, 0x8, 0x13, PPC2_VSX),
10947VSX_LOGICAL(xxlnor, 0x8, 0x14, PPC2_VSX),
67a33f37
TM
10948VSX_LOGICAL(xxleqv, 0x8, 0x17, PPC2_VSX207),
10949VSX_LOGICAL(xxlnand, 0x8, 0x16, PPC2_VSX207),
10950VSX_LOGICAL(xxlorc, 0x8, 0x15, PPC2_VSX207),
ce577d2e
TM
10951GEN_XX3FORM(xxmrghw, 0x08, 0x02, PPC2_VSX),
10952GEN_XX3FORM(xxmrglw, 0x08, 0x06, PPC2_VSX),
76c15fe0 10953GEN_XX2FORM(xxspltw, 0x08, 0x0A, PPC2_VSX),
acc42968 10954GEN_XX3FORM_DM(xxsldwi, 0x08, 0x00),
79ca8a6a 10955
551e3ef7
TM
10956#define GEN_XXSEL_ROW(opc3) \
10957GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x18, opc3, 0, PPC_NONE, PPC2_VSX), \
10958GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x19, opc3, 0, PPC_NONE, PPC2_VSX), \
10959GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1A, opc3, 0, PPC_NONE, PPC2_VSX), \
10960GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1B, opc3, 0, PPC_NONE, PPC2_VSX), \
10961GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1C, opc3, 0, PPC_NONE, PPC2_VSX), \
10962GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1D, opc3, 0, PPC_NONE, PPC2_VSX), \
10963GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1E, opc3, 0, PPC_NONE, PPC2_VSX), \
10964GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1F, opc3, 0, PPC_NONE, PPC2_VSX), \
10965
10966GEN_XXSEL_ROW(0x00)
10967GEN_XXSEL_ROW(0x01)
10968GEN_XXSEL_ROW(0x02)
10969GEN_XXSEL_ROW(0x03)
10970GEN_XXSEL_ROW(0x04)
10971GEN_XXSEL_ROW(0x05)
10972GEN_XXSEL_ROW(0x06)
10973GEN_XXSEL_ROW(0x07)
10974GEN_XXSEL_ROW(0x08)
10975GEN_XXSEL_ROW(0x09)
10976GEN_XXSEL_ROW(0x0A)
10977GEN_XXSEL_ROW(0x0B)
10978GEN_XXSEL_ROW(0x0C)
10979GEN_XXSEL_ROW(0x0D)
10980GEN_XXSEL_ROW(0x0E)
10981GEN_XXSEL_ROW(0x0F)
10982GEN_XXSEL_ROW(0x10)
10983GEN_XXSEL_ROW(0x11)
10984GEN_XXSEL_ROW(0x12)
10985GEN_XXSEL_ROW(0x13)
10986GEN_XXSEL_ROW(0x14)
10987GEN_XXSEL_ROW(0x15)
10988GEN_XXSEL_ROW(0x16)
10989GEN_XXSEL_ROW(0x17)
10990GEN_XXSEL_ROW(0x18)
10991GEN_XXSEL_ROW(0x19)
10992GEN_XXSEL_ROW(0x1A)
10993GEN_XXSEL_ROW(0x1B)
10994GEN_XXSEL_ROW(0x1C)
10995GEN_XXSEL_ROW(0x1D)
10996GEN_XXSEL_ROW(0x1E)
10997GEN_XXSEL_ROW(0x1F)
10998
cd73f2c9
TM
10999GEN_XX3FORM_DM(xxpermdi, 0x08, 0x01),
11000
5c55ff99 11001#undef GEN_SPE
70560da7
FC
11002#define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \
11003 GEN_OPCODE_DUAL(name0##_##name1, 0x04, opc2, opc3, inval0, inval1, type, PPC_NONE)
11004GEN_SPE(evaddw, speundef, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11005GEN_SPE(evaddiw, speundef, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11006GEN_SPE(evsubfw, speundef, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11007GEN_SPE(evsubifw, speundef, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11008GEN_SPE(evabs, evneg, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE),
11009GEN_SPE(evextsb, evextsh, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE),
11010GEN_SPE(evrndw, evcntlzw, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE),
11011GEN_SPE(evcntlsw, brinc, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE),
11012GEN_SPE(evmra, speundef, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE),
11013GEN_SPE(speundef, evand, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE),
11014GEN_SPE(evandc, speundef, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11015GEN_SPE(evxor, evor, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE),
11016GEN_SPE(evnor, eveqv, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE),
11017GEN_SPE(evmwumi, evmwsmi, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE),
11018GEN_SPE(evmwumia, evmwsmia, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE),
11019GEN_SPE(evmwumiaa, evmwsmiaa, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE),
11020GEN_SPE(speundef, evorc, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE),
11021GEN_SPE(evnand, speundef, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11022GEN_SPE(evsrwu, evsrws, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE),
11023GEN_SPE(evsrwiu, evsrwis, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE),
11024GEN_SPE(evslw, speundef, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11025GEN_SPE(evslwi, speundef, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11026GEN_SPE(evrlw, evsplati, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE),
11027GEN_SPE(evrlwi, evsplatfi, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE),
11028GEN_SPE(evmergehi, evmergelo, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE),
11029GEN_SPE(evmergehilo, evmergelohi, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE),
11030GEN_SPE(evcmpgtu, evcmpgts, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE),
11031GEN_SPE(evcmpltu, evcmplts, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE),
11032GEN_SPE(evcmpeq, speundef, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE),
11033
11034GEN_SPE(evfsadd, evfssub, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE),
11035GEN_SPE(evfsabs, evfsnabs, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE),
11036GEN_SPE(evfsneg, speundef, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE),
11037GEN_SPE(evfsmul, evfsdiv, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE),
11038GEN_SPE(evfscmpgt, evfscmplt, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE),
11039GEN_SPE(evfscmpeq, speundef, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11040GEN_SPE(evfscfui, evfscfsi, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11041GEN_SPE(evfscfuf, evfscfsf, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11042GEN_SPE(evfsctui, evfsctsi, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11043GEN_SPE(evfsctuf, evfsctsf, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11044GEN_SPE(evfsctuiz, speundef, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11045GEN_SPE(evfsctsiz, speundef, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11046GEN_SPE(evfststgt, evfststlt, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE),
11047GEN_SPE(evfststeq, speundef, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11048
11049GEN_SPE(efsadd, efssub, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE),
11050GEN_SPE(efsabs, efsnabs, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE),
11051GEN_SPE(efsneg, speundef, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE),
11052GEN_SPE(efsmul, efsdiv, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE),
11053GEN_SPE(efscmpgt, efscmplt, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE),
11054GEN_SPE(efscmpeq, efscfd, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE),
11055GEN_SPE(efscfui, efscfsi, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11056GEN_SPE(efscfuf, efscfsf, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11057GEN_SPE(efsctui, efsctsi, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11058GEN_SPE(efsctuf, efsctsf, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11059GEN_SPE(efsctuiz, speundef, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11060GEN_SPE(efsctsiz, speundef, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11061GEN_SPE(efststgt, efststlt, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE),
11062GEN_SPE(efststeq, speundef, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11063
11064GEN_SPE(efdadd, efdsub, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE),
11065GEN_SPE(efdcfuid, efdcfsid, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
11066GEN_SPE(efdabs, efdnabs, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE),
11067GEN_SPE(efdneg, speundef, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE),
11068GEN_SPE(efdmul, efddiv, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE),
11069GEN_SPE(efdctuidz, efdctsidz, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
11070GEN_SPE(efdcmpgt, efdcmplt, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE),
11071GEN_SPE(efdcmpeq, efdcfs, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE),
11072GEN_SPE(efdcfui, efdcfsi, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
11073GEN_SPE(efdcfuf, efdcfsf, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
11074GEN_SPE(efdctui, efdctsi, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
11075GEN_SPE(efdctuf, efdctsf, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
11076GEN_SPE(efdctuiz, speundef, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE),
11077GEN_SPE(efdctsiz, speundef, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE),
11078GEN_SPE(efdtstgt, efdtstlt, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE),
11079GEN_SPE(efdtsteq, speundef, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE),
5c55ff99
BS
11080
11081#undef GEN_SPEOP_LDST
11082#define GEN_SPEOP_LDST(name, opc2, sh) \
11083GEN_HANDLER(name, 0x04, opc2, 0x0C, 0x00000000, PPC_SPE)
11084GEN_SPEOP_LDST(evldd, 0x00, 3),
11085GEN_SPEOP_LDST(evldw, 0x01, 3),
11086GEN_SPEOP_LDST(evldh, 0x02, 3),
11087GEN_SPEOP_LDST(evlhhesplat, 0x04, 1),
11088GEN_SPEOP_LDST(evlhhousplat, 0x06, 1),
11089GEN_SPEOP_LDST(evlhhossplat, 0x07, 1),
11090GEN_SPEOP_LDST(evlwhe, 0x08, 2),
11091GEN_SPEOP_LDST(evlwhou, 0x0A, 2),
11092GEN_SPEOP_LDST(evlwhos, 0x0B, 2),
11093GEN_SPEOP_LDST(evlwwsplat, 0x0C, 2),
11094GEN_SPEOP_LDST(evlwhsplat, 0x0E, 2),
11095
11096GEN_SPEOP_LDST(evstdd, 0x10, 3),
11097GEN_SPEOP_LDST(evstdw, 0x11, 3),
11098GEN_SPEOP_LDST(evstdh, 0x12, 3),
11099GEN_SPEOP_LDST(evstwhe, 0x18, 2),
11100GEN_SPEOP_LDST(evstwho, 0x1A, 2),
11101GEN_SPEOP_LDST(evstwwe, 0x1C, 2),
11102GEN_SPEOP_LDST(evstwwo, 0x1E, 2),
11103};
11104
0411a972 11105#include "helper_regs.h"
a1389542 11106#include "translate_init.c"
79aceca5 11107
9a64fbe4 11108/*****************************************************************************/
3fc6c082 11109/* Misc PowerPC helpers */
878096ee
AF
11110void ppc_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf,
11111 int flags)
79aceca5 11112{
3fc6c082
FB
11113#define RGPL 4
11114#define RFPL 4
3fc6c082 11115
878096ee
AF
11116 PowerPCCPU *cpu = POWERPC_CPU(cs);
11117 CPUPPCState *env = &cpu->env;
79aceca5
FB
11118 int i;
11119
90e189ec 11120 cpu_fprintf(f, "NIP " TARGET_FMT_lx " LR " TARGET_FMT_lx " CTR "
9a78eead 11121 TARGET_FMT_lx " XER " TARGET_FMT_lx "\n",
da91a00f 11122 env->nip, env->lr, env->ctr, cpu_read_xer(env));
90e189ec
BS
11123 cpu_fprintf(f, "MSR " TARGET_FMT_lx " HID0 " TARGET_FMT_lx " HF "
11124 TARGET_FMT_lx " idx %d\n", env->msr, env->spr[SPR_HID0],
11125 env->hflags, env->mmu_idx);
d9bce9d9 11126#if !defined(NO_TIMER_DUMP)
9a78eead 11127 cpu_fprintf(f, "TB %08" PRIu32 " %08" PRIu64
76a66253 11128#if !defined(CONFIG_USER_ONLY)
9a78eead 11129 " DECR %08" PRIu32
76a66253
JM
11130#endif
11131 "\n",
077fc206 11132 cpu_ppc_load_tbu(env), cpu_ppc_load_tbl(env)
76a66253
JM
11133#if !defined(CONFIG_USER_ONLY)
11134 , cpu_ppc_load_decr(env)
11135#endif
11136 );
077fc206 11137#endif
76a66253 11138 for (i = 0; i < 32; i++) {
3fc6c082
FB
11139 if ((i & (RGPL - 1)) == 0)
11140 cpu_fprintf(f, "GPR%02d", i);
b11ebf64 11141 cpu_fprintf(f, " %016" PRIx64, ppc_dump_gpr(env, i));
3fc6c082 11142 if ((i & (RGPL - 1)) == (RGPL - 1))
7fe48483 11143 cpu_fprintf(f, "\n");
76a66253 11144 }
3fc6c082 11145 cpu_fprintf(f, "CR ");
76a66253 11146 for (i = 0; i < 8; i++)
7fe48483
FB
11147 cpu_fprintf(f, "%01x", env->crf[i]);
11148 cpu_fprintf(f, " [");
76a66253
JM
11149 for (i = 0; i < 8; i++) {
11150 char a = '-';
11151 if (env->crf[i] & 0x08)
11152 a = 'L';
11153 else if (env->crf[i] & 0x04)
11154 a = 'G';
11155 else if (env->crf[i] & 0x02)
11156 a = 'E';
7fe48483 11157 cpu_fprintf(f, " %c%c", a, env->crf[i] & 0x01 ? 'O' : ' ');
76a66253 11158 }
90e189ec
BS
11159 cpu_fprintf(f, " ] RES " TARGET_FMT_lx "\n",
11160 env->reserve_addr);
3fc6c082
FB
11161 for (i = 0; i < 32; i++) {
11162 if ((i & (RFPL - 1)) == 0)
11163 cpu_fprintf(f, "FPR%02d", i);
26a76461 11164 cpu_fprintf(f, " %016" PRIx64, *((uint64_t *)&env->fpr[i]));
3fc6c082 11165 if ((i & (RFPL - 1)) == (RFPL - 1))
7fe48483 11166 cpu_fprintf(f, "\n");
79aceca5 11167 }
30304420 11168 cpu_fprintf(f, "FPSCR " TARGET_FMT_lx "\n", env->fpscr);
f2e63a42 11169#if !defined(CONFIG_USER_ONLY)
90dc8812
SW
11170 cpu_fprintf(f, " SRR0 " TARGET_FMT_lx " SRR1 " TARGET_FMT_lx
11171 " PVR " TARGET_FMT_lx " VRSAVE " TARGET_FMT_lx "\n",
11172 env->spr[SPR_SRR0], env->spr[SPR_SRR1],
11173 env->spr[SPR_PVR], env->spr[SPR_VRSAVE]);
11174
11175 cpu_fprintf(f, "SPRG0 " TARGET_FMT_lx " SPRG1 " TARGET_FMT_lx
11176 " SPRG2 " TARGET_FMT_lx " SPRG3 " TARGET_FMT_lx "\n",
11177 env->spr[SPR_SPRG0], env->spr[SPR_SPRG1],
11178 env->spr[SPR_SPRG2], env->spr[SPR_SPRG3]);
11179
11180 cpu_fprintf(f, "SPRG4 " TARGET_FMT_lx " SPRG5 " TARGET_FMT_lx
11181 " SPRG6 " TARGET_FMT_lx " SPRG7 " TARGET_FMT_lx "\n",
11182 env->spr[SPR_SPRG4], env->spr[SPR_SPRG5],
11183 env->spr[SPR_SPRG6], env->spr[SPR_SPRG7]);
11184
11185 if (env->excp_model == POWERPC_EXCP_BOOKE) {
11186 cpu_fprintf(f, "CSRR0 " TARGET_FMT_lx " CSRR1 " TARGET_FMT_lx
11187 " MCSRR0 " TARGET_FMT_lx " MCSRR1 " TARGET_FMT_lx "\n",
11188 env->spr[SPR_BOOKE_CSRR0], env->spr[SPR_BOOKE_CSRR1],
11189 env->spr[SPR_BOOKE_MCSRR0], env->spr[SPR_BOOKE_MCSRR1]);
11190
11191 cpu_fprintf(f, " TCR " TARGET_FMT_lx " TSR " TARGET_FMT_lx
11192 " ESR " TARGET_FMT_lx " DEAR " TARGET_FMT_lx "\n",
11193 env->spr[SPR_BOOKE_TCR], env->spr[SPR_BOOKE_TSR],
11194 env->spr[SPR_BOOKE_ESR], env->spr[SPR_BOOKE_DEAR]);
11195
11196 cpu_fprintf(f, " PIR " TARGET_FMT_lx " DECAR " TARGET_FMT_lx
11197 " IVPR " TARGET_FMT_lx " EPCR " TARGET_FMT_lx "\n",
11198 env->spr[SPR_BOOKE_PIR], env->spr[SPR_BOOKE_DECAR],
11199 env->spr[SPR_BOOKE_IVPR], env->spr[SPR_BOOKE_EPCR]);
11200
11201 cpu_fprintf(f, " MCSR " TARGET_FMT_lx " SPRG8 " TARGET_FMT_lx
11202 " EPR " TARGET_FMT_lx "\n",
11203 env->spr[SPR_BOOKE_MCSR], env->spr[SPR_BOOKE_SPRG8],
11204 env->spr[SPR_BOOKE_EPR]);
11205
11206 /* FSL-specific */
11207 cpu_fprintf(f, " MCAR " TARGET_FMT_lx " PID1 " TARGET_FMT_lx
11208 " PID2 " TARGET_FMT_lx " SVR " TARGET_FMT_lx "\n",
11209 env->spr[SPR_Exxx_MCAR], env->spr[SPR_BOOKE_PID1],
11210 env->spr[SPR_BOOKE_PID2], env->spr[SPR_E500_SVR]);
11211
11212 /*
11213 * IVORs are left out as they are large and do not change often --
11214 * they can be read with "p $ivor0", "p $ivor1", etc.
11215 */
11216 }
11217
697ab892
DG
11218#if defined(TARGET_PPC64)
11219 if (env->flags & POWERPC_FLAG_CFAR) {
11220 cpu_fprintf(f, " CFAR " TARGET_FMT_lx"\n", env->cfar);
11221 }
11222#endif
11223
90dc8812
SW
11224 switch (env->mmu_model) {
11225 case POWERPC_MMU_32B:
11226 case POWERPC_MMU_601:
11227 case POWERPC_MMU_SOFT_6xx:
11228 case POWERPC_MMU_SOFT_74xx:
11229#if defined(TARGET_PPC64)
90dc8812 11230 case POWERPC_MMU_64B:
ca480de6
AB
11231 case POWERPC_MMU_2_06:
11232 case POWERPC_MMU_2_06a:
11233 case POWERPC_MMU_2_06d:
90dc8812 11234#endif
ca480de6
AB
11235 cpu_fprintf(f, " SDR1 " TARGET_FMT_lx " DAR " TARGET_FMT_lx
11236 " DSISR " TARGET_FMT_lx "\n", env->spr[SPR_SDR1],
11237 env->spr[SPR_DAR], env->spr[SPR_DSISR]);
90dc8812 11238 break;
01662f3e 11239 case POWERPC_MMU_BOOKE206:
90dc8812
SW
11240 cpu_fprintf(f, " MAS0 " TARGET_FMT_lx " MAS1 " TARGET_FMT_lx
11241 " MAS2 " TARGET_FMT_lx " MAS3 " TARGET_FMT_lx "\n",
11242 env->spr[SPR_BOOKE_MAS0], env->spr[SPR_BOOKE_MAS1],
11243 env->spr[SPR_BOOKE_MAS2], env->spr[SPR_BOOKE_MAS3]);
11244
11245 cpu_fprintf(f, " MAS4 " TARGET_FMT_lx " MAS6 " TARGET_FMT_lx
11246 " MAS7 " TARGET_FMT_lx " PID " TARGET_FMT_lx "\n",
11247 env->spr[SPR_BOOKE_MAS4], env->spr[SPR_BOOKE_MAS6],
11248 env->spr[SPR_BOOKE_MAS7], env->spr[SPR_BOOKE_PID]);
11249
11250 cpu_fprintf(f, "MMUCFG " TARGET_FMT_lx " TLB0CFG " TARGET_FMT_lx
11251 " TLB1CFG " TARGET_FMT_lx "\n",
11252 env->spr[SPR_MMUCFG], env->spr[SPR_BOOKE_TLB0CFG],
11253 env->spr[SPR_BOOKE_TLB1CFG]);
11254 break;
11255 default:
11256 break;
11257 }
f2e63a42 11258#endif
79aceca5 11259
3fc6c082
FB
11260#undef RGPL
11261#undef RFPL
79aceca5
FB
11262}
11263
878096ee
AF
11264void ppc_cpu_dump_statistics(CPUState *cs, FILE*f,
11265 fprintf_function cpu_fprintf, int flags)
76a66253
JM
11266{
11267#if defined(DO_PPC_STATISTICS)
878096ee 11268 PowerPCCPU *cpu = POWERPC_CPU(cs);
c227f099 11269 opc_handler_t **t1, **t2, **t3, *handler;
76a66253
JM
11270 int op1, op2, op3;
11271
878096ee 11272 t1 = cpu->env.opcodes;
76a66253
JM
11273 for (op1 = 0; op1 < 64; op1++) {
11274 handler = t1[op1];
11275 if (is_indirect_opcode(handler)) {
11276 t2 = ind_table(handler);
11277 for (op2 = 0; op2 < 32; op2++) {
11278 handler = t2[op2];
11279 if (is_indirect_opcode(handler)) {
11280 t3 = ind_table(handler);
11281 for (op3 = 0; op3 < 32; op3++) {
11282 handler = t3[op3];
11283 if (handler->count == 0)
11284 continue;
11285 cpu_fprintf(f, "%02x %02x %02x (%02x %04d) %16s: "
0bfcd599 11286 "%016" PRIx64 " %" PRId64 "\n",
76a66253
JM
11287 op1, op2, op3, op1, (op3 << 5) | op2,
11288 handler->oname,
11289 handler->count, handler->count);
11290 }
11291 } else {
11292 if (handler->count == 0)
11293 continue;
11294 cpu_fprintf(f, "%02x %02x (%02x %04d) %16s: "
0bfcd599 11295 "%016" PRIx64 " %" PRId64 "\n",
76a66253
JM
11296 op1, op2, op1, op2, handler->oname,
11297 handler->count, handler->count);
11298 }
11299 }
11300 } else {
11301 if (handler->count == 0)
11302 continue;
0bfcd599
BS
11303 cpu_fprintf(f, "%02x (%02x ) %16s: %016" PRIx64
11304 " %" PRId64 "\n",
76a66253
JM
11305 op1, op1, handler->oname,
11306 handler->count, handler->count);
11307 }
11308 }
11309#endif
11310}
11311
9a64fbe4 11312/*****************************************************************************/
213fe1f5 11313static inline void gen_intermediate_code_internal(PowerPCCPU *cpu,
636aa200 11314 TranslationBlock *tb,
213fe1f5 11315 bool search_pc)
79aceca5 11316{
ed2803da 11317 CPUState *cs = CPU(cpu);
213fe1f5 11318 CPUPPCState *env = &cpu->env;
9fddaa0c 11319 DisasContext ctx, *ctxp = &ctx;
c227f099 11320 opc_handler_t **table, *handler;
0fa85d43 11321 target_ulong pc_start;
79aceca5 11322 uint16_t *gen_opc_end;
a1d1bb31 11323 CPUBreakpoint *bp;
79aceca5 11324 int j, lj = -1;
2e70f6ef
PB
11325 int num_insns;
11326 int max_insns;
79aceca5
FB
11327
11328 pc_start = tb->pc;
92414b31 11329 gen_opc_end = tcg_ctx.gen_opc_buf + OPC_MAX_SIZE;
046d6672 11330 ctx.nip = pc_start;
79aceca5 11331 ctx.tb = tb;
e1833e1f 11332 ctx.exception = POWERPC_EXCP_NONE;
3fc6c082 11333 ctx.spr_cb = env->spr_cb;
76db3ba4 11334 ctx.mem_idx = env->mmu_idx;
7d08d856
AJ
11335 ctx.insns_flags = env->insns_flags;
11336 ctx.insns_flags2 = env->insns_flags2;
76db3ba4
AJ
11337 ctx.access_type = -1;
11338 ctx.le_mode = env->hflags & (1 << MSR_LE) ? 1 : 0;
d9bce9d9 11339#if defined(TARGET_PPC64)
e42a61f1 11340 ctx.sf_mode = msr_is_64bit(env, env->msr);
697ab892 11341 ctx.has_cfar = !!(env->flags & POWERPC_FLAG_CFAR);
9a64fbe4 11342#endif
3cc62370 11343 ctx.fpu_enabled = msr_fp;
a9d9eb8f 11344 if ((env->flags & POWERPC_FLAG_SPE) && msr_spe)
d26bfc9a
JM
11345 ctx.spe_enabled = msr_spe;
11346 else
11347 ctx.spe_enabled = 0;
a9d9eb8f
JM
11348 if ((env->flags & POWERPC_FLAG_VRE) && msr_vr)
11349 ctx.altivec_enabled = msr_vr;
11350 else
11351 ctx.altivec_enabled = 0;
1f29871c
TM
11352 if ((env->flags & POWERPC_FLAG_VSX) && msr_vsx) {
11353 ctx.vsx_enabled = msr_vsx;
11354 } else {
11355 ctx.vsx_enabled = 0;
11356 }
d26bfc9a 11357 if ((env->flags & POWERPC_FLAG_SE) && msr_se)
8cbcb4fa 11358 ctx.singlestep_enabled = CPU_SINGLE_STEP;
d26bfc9a 11359 else
8cbcb4fa 11360 ctx.singlestep_enabled = 0;
d26bfc9a 11361 if ((env->flags & POWERPC_FLAG_BE) && msr_be)
8cbcb4fa 11362 ctx.singlestep_enabled |= CPU_BRANCH_STEP;
ed2803da 11363 if (unlikely(cs->singlestep_enabled)) {
8cbcb4fa 11364 ctx.singlestep_enabled |= GDBSTUB_SINGLE_STEP;
ed2803da 11365 }
3fc6c082 11366#if defined (DO_SINGLE_STEP) && 0
9a64fbe4
FB
11367 /* Single step trace mode */
11368 msr_se = 1;
11369#endif
2e70f6ef
PB
11370 num_insns = 0;
11371 max_insns = tb->cflags & CF_COUNT_MASK;
11372 if (max_insns == 0)
11373 max_insns = CF_COUNT_MASK;
11374
806f352d 11375 gen_tb_start();
9a64fbe4 11376 /* Set env in case of segfault during code fetch */
efd7f486
EV
11377 while (ctx.exception == POWERPC_EXCP_NONE
11378 && tcg_ctx.gen_opc_ptr < gen_opc_end) {
f0c3c505
AF
11379 if (unlikely(!QTAILQ_EMPTY(&cs->breakpoints))) {
11380 QTAILQ_FOREACH(bp, &cs->breakpoints, entry) {
a1d1bb31 11381 if (bp->pc == ctx.nip) {
e06fcd75 11382 gen_debug_exception(ctxp);
ea4e754f
FB
11383 break;
11384 }
11385 }
11386 }
76a66253 11387 if (unlikely(search_pc)) {
92414b31 11388 j = tcg_ctx.gen_opc_ptr - tcg_ctx.gen_opc_buf;
79aceca5
FB
11389 if (lj < j) {
11390 lj++;
11391 while (lj < j)
ab1103de 11392 tcg_ctx.gen_opc_instr_start[lj++] = 0;
79aceca5 11393 }
25983cad 11394 tcg_ctx.gen_opc_pc[lj] = ctx.nip;
ab1103de 11395 tcg_ctx.gen_opc_instr_start[lj] = 1;
c9c99c22 11396 tcg_ctx.gen_opc_icount[lj] = num_insns;
79aceca5 11397 }
d12d51d5 11398 LOG_DISAS("----------------\n");
90e189ec 11399 LOG_DISAS("nip=" TARGET_FMT_lx " super=%d ir=%d\n",
d12d51d5 11400 ctx.nip, ctx.mem_idx, (int)msr_ir);
2e70f6ef
PB
11401 if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO))
11402 gen_io_start();
76db3ba4 11403 if (unlikely(ctx.le_mode)) {
2f5a189c 11404 ctx.opcode = bswap32(cpu_ldl_code(env, ctx.nip));
056401ea 11405 } else {
2f5a189c 11406 ctx.opcode = cpu_ldl_code(env, ctx.nip);
111bfab3 11407 }
d12d51d5 11408 LOG_DISAS("translate opcode %08x (%02x %02x %02x) (%s)\n",
9a64fbe4 11409 ctx.opcode, opc1(ctx.opcode), opc2(ctx.opcode),
476b6d16 11410 opc3(ctx.opcode), ctx.le_mode ? "little" : "big");
fdefe51c 11411 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP | CPU_LOG_TB_OP_OPT))) {
731c54f8 11412 tcg_gen_debug_insn_start(ctx.nip);
fdefe51c 11413 }
046d6672 11414 ctx.nip += 4;
3fc6c082 11415 table = env->opcodes;
2e70f6ef 11416 num_insns++;
79aceca5
FB
11417 handler = table[opc1(ctx.opcode)];
11418 if (is_indirect_opcode(handler)) {
11419 table = ind_table(handler);
11420 handler = table[opc2(ctx.opcode)];
11421 if (is_indirect_opcode(handler)) {
11422 table = ind_table(handler);
11423 handler = table[opc3(ctx.opcode)];
11424 }
11425 }
11426 /* Is opcode *REALLY* valid ? */
76a66253 11427 if (unlikely(handler->handler == &gen_invalid)) {
93fcfe39
AL
11428 if (qemu_log_enabled()) {
11429 qemu_log("invalid/unsupported opcode: "
90e189ec
BS
11430 "%02x - %02x - %02x (%08x) " TARGET_FMT_lx " %d\n",
11431 opc1(ctx.opcode), opc2(ctx.opcode),
11432 opc3(ctx.opcode), ctx.opcode, ctx.nip - 4, (int)msr_ir);
4b3686fa 11433 }
76a66253 11434 } else {
70560da7
FC
11435 uint32_t inval;
11436
11437 if (unlikely(handler->type & (PPC_SPE | PPC_SPE_SINGLE | PPC_SPE_DOUBLE) && Rc(ctx.opcode))) {
11438 inval = handler->inval2;
11439 } else {
11440 inval = handler->inval1;
11441 }
11442
11443 if (unlikely((ctx.opcode & inval) != 0)) {
93fcfe39
AL
11444 if (qemu_log_enabled()) {
11445 qemu_log("invalid bits: %08x for opcode: "
90e189ec 11446 "%02x - %02x - %02x (%08x) " TARGET_FMT_lx "\n",
70560da7 11447 ctx.opcode & inval, opc1(ctx.opcode),
90e189ec
BS
11448 opc2(ctx.opcode), opc3(ctx.opcode),
11449 ctx.opcode, ctx.nip - 4);
76a66253 11450 }
e06fcd75 11451 gen_inval_exception(ctxp, POWERPC_EXCP_INVAL_INVAL);
4b3686fa 11452 break;
79aceca5 11453 }
79aceca5 11454 }
4b3686fa 11455 (*(handler->handler))(&ctx);
76a66253
JM
11456#if defined(DO_PPC_STATISTICS)
11457 handler->count++;
11458#endif
9a64fbe4 11459 /* Check trace mode exceptions */
8cbcb4fa
AJ
11460 if (unlikely(ctx.singlestep_enabled & CPU_SINGLE_STEP &&
11461 (ctx.nip <= 0x100 || ctx.nip > 0xF00) &&
11462 ctx.exception != POWERPC_SYSCALL &&
11463 ctx.exception != POWERPC_EXCP_TRAP &&
11464 ctx.exception != POWERPC_EXCP_BRANCH)) {
e06fcd75 11465 gen_exception(ctxp, POWERPC_EXCP_TRACE);
d26bfc9a 11466 } else if (unlikely(((ctx.nip & (TARGET_PAGE_SIZE - 1)) == 0) ||
ed2803da 11467 (cs->singlestep_enabled) ||
1b530a6d 11468 singlestep ||
2e70f6ef 11469 num_insns >= max_insns)) {
d26bfc9a
JM
11470 /* if we reach a page boundary or are single stepping, stop
11471 * generation
11472 */
8dd4983c 11473 break;
76a66253 11474 }
3fc6c082 11475 }
2e70f6ef
PB
11476 if (tb->cflags & CF_LAST_IO)
11477 gen_io_end();
e1833e1f 11478 if (ctx.exception == POWERPC_EXCP_NONE) {
c1942362 11479 gen_goto_tb(&ctx, 0, ctx.nip);
e1833e1f 11480 } else if (ctx.exception != POWERPC_EXCP_BRANCH) {
ed2803da 11481 if (unlikely(cs->singlestep_enabled)) {
e06fcd75 11482 gen_debug_exception(ctxp);
8cbcb4fa 11483 }
76a66253 11484 /* Generate the return instruction */
57fec1fe 11485 tcg_gen_exit_tb(0);
9a64fbe4 11486 }
806f352d 11487 gen_tb_end(tb, num_insns);
efd7f486 11488 *tcg_ctx.gen_opc_ptr = INDEX_op_end;
76a66253 11489 if (unlikely(search_pc)) {
92414b31 11490 j = tcg_ctx.gen_opc_ptr - tcg_ctx.gen_opc_buf;
9a64fbe4
FB
11491 lj++;
11492 while (lj <= j)
ab1103de 11493 tcg_ctx.gen_opc_instr_start[lj++] = 0;
9a64fbe4 11494 } else {
046d6672 11495 tb->size = ctx.nip - pc_start;
2e70f6ef 11496 tb->icount = num_insns;
9a64fbe4 11497 }
d9bce9d9 11498#if defined(DEBUG_DISAS)
8fec2b8c 11499 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
76a66253 11500 int flags;
237c0af0 11501 flags = env->bfd_mach;
76db3ba4 11502 flags |= ctx.le_mode << 16;
93fcfe39 11503 qemu_log("IN: %s\n", lookup_symbol(pc_start));
f4359b9f 11504 log_target_disas(env, pc_start, ctx.nip - pc_start, flags);
93fcfe39 11505 qemu_log("\n");
9fddaa0c 11506 }
79aceca5 11507#endif
79aceca5
FB
11508}
11509
1328c2bf 11510void gen_intermediate_code (CPUPPCState *env, struct TranslationBlock *tb)
79aceca5 11511{
213fe1f5 11512 gen_intermediate_code_internal(ppc_env_get_cpu(env), tb, false);
79aceca5
FB
11513}
11514
1328c2bf 11515void gen_intermediate_code_pc (CPUPPCState *env, struct TranslationBlock *tb)
79aceca5 11516{
213fe1f5 11517 gen_intermediate_code_internal(ppc_env_get_cpu(env), tb, true);
79aceca5 11518}
d2856f1a 11519
1328c2bf 11520void restore_state_to_opc(CPUPPCState *env, TranslationBlock *tb, int pc_pos)
d2856f1a 11521{
25983cad 11522 env->nip = tcg_ctx.gen_opc_pc[pc_pos];
d2856f1a 11523}