27
27
#include "exec-all.h"
31
#include "qemu-common.h"
33
#define CPU_SINGLE_STEP 0x1
34
#define CPU_BRANCH_STEP 0x2
35
#define GDBSTUB_SINGLE_STEP 0x4
37
30
/* Include definitions for instructions classes and implementations flags */
38
31
//#define DO_SINGLE_STEP
39
32
//#define PPC_DEBUG_DISAS
33
//#define DEBUG_MEMORY_ACCESSES
40
34
//#define DO_PPC_STATISTICS
41
//#define OPTIMIZE_FPRF_UPDATE
43
36
/*****************************************************************************/
44
37
/* Code translation helpers */
46
/* global register indexes */
48
static char cpu_reg_names[10*3 + 22*4 /* GPR */
49
#if !defined(TARGET_PPC64)
50
+ 10*4 + 22*5 /* SPE GPRh */
52
+ 10*4 + 22*5 /* FPR */
53
+ 2*(10*6 + 22*7) /* AVRh, AVRl */
55
static TCGv cpu_gpr[32];
56
#if !defined(TARGET_PPC64)
57
static TCGv cpu_gprh[32];
59
static TCGv cpu_fpr[32];
60
static TCGv cpu_avrh[32], cpu_avrl[32];
61
static TCGv cpu_crf[8];
66
static TCGv cpu_fpscr;
68
/* dyngen register indexes */
70
#if defined(TARGET_PPC64)
73
static TCGv cpu_T64[3];
75
static TCGv cpu_FT[3];
76
static TCGv cpu_AVRh[3], cpu_AVRl[3];
78
#include "gen-icount.h"
80
void ppc_translate_init(void)
84
static int done_init = 0;
89
cpu_env = tcg_global_reg_new(TCG_TYPE_PTR, TCG_AREG0, "env");
90
#if TARGET_LONG_BITS > HOST_LONG_BITS
91
cpu_T[0] = tcg_global_mem_new(TCG_TYPE_TL,
92
TCG_AREG0, offsetof(CPUState, t0), "T0");
93
cpu_T[1] = tcg_global_mem_new(TCG_TYPE_TL,
94
TCG_AREG0, offsetof(CPUState, t1), "T1");
95
cpu_T[2] = tcg_global_mem_new(TCG_TYPE_TL,
96
TCG_AREG0, offsetof(CPUState, t2), "T2");
98
cpu_T[0] = tcg_global_reg_new(TCG_TYPE_TL, TCG_AREG1, "T0");
99
cpu_T[1] = tcg_global_reg_new(TCG_TYPE_TL, TCG_AREG2, "T1");
101
/* XXX: This is a temporary workaround for i386.
102
* On i386 qemu_st32 runs out of registers.
103
* The proper fix is to remove cpu_T.
105
cpu_T[2] = tcg_global_mem_new(TCG_TYPE_TL,
106
TCG_AREG0, offsetof(CPUState, t2), "T2");
108
cpu_T[2] = tcg_global_reg_new(TCG_TYPE_TL, TCG_AREG3, "T2");
111
#if !defined(TARGET_PPC64)
112
cpu_T64[0] = tcg_global_mem_new(TCG_TYPE_I64,
113
TCG_AREG0, offsetof(CPUState, t0_64),
115
cpu_T64[1] = tcg_global_mem_new(TCG_TYPE_I64,
116
TCG_AREG0, offsetof(CPUState, t1_64),
118
cpu_T64[2] = tcg_global_mem_new(TCG_TYPE_I64,
119
TCG_AREG0, offsetof(CPUState, t2_64),
123
cpu_FT[0] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
124
offsetof(CPUState, ft0), "FT0");
125
cpu_FT[1] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
126
offsetof(CPUState, ft1), "FT1");
127
cpu_FT[2] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
128
offsetof(CPUState, ft2), "FT2");
130
cpu_AVRh[0] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
131
offsetof(CPUState, avr0.u64[0]), "AVR0H");
132
cpu_AVRl[0] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
133
offsetof(CPUState, avr0.u64[1]), "AVR0L");
134
cpu_AVRh[1] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
135
offsetof(CPUState, avr1.u64[0]), "AVR1H");
136
cpu_AVRl[1] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
137
offsetof(CPUState, avr1.u64[1]), "AVR1L");
138
cpu_AVRh[2] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
139
offsetof(CPUState, avr2.u64[0]), "AVR2H");
140
cpu_AVRl[2] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
141
offsetof(CPUState, avr2.u64[1]), "AVR2L");
145
for (i = 0; i < 8; i++) {
146
sprintf(p, "crf%d", i);
147
cpu_crf[i] = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0,
148
offsetof(CPUState, crf[i]), p);
152
for (i = 0; i < 32; i++) {
153
sprintf(p, "r%d", i);
154
cpu_gpr[i] = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
155
offsetof(CPUState, gpr[i]), p);
156
p += (i < 10) ? 3 : 4;
157
#if !defined(TARGET_PPC64)
158
sprintf(p, "r%dH", i);
159
cpu_gprh[i] = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0,
160
offsetof(CPUState, gprh[i]), p);
161
p += (i < 10) ? 4 : 5;
164
sprintf(p, "fp%d", i);
165
cpu_fpr[i] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
166
offsetof(CPUState, fpr[i]), p);
167
p += (i < 10) ? 4 : 5;
169
sprintf(p, "avr%dH", i);
170
cpu_avrh[i] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
171
offsetof(CPUState, avr[i].u64[0]), p);
172
p += (i < 10) ? 6 : 7;
174
sprintf(p, "avr%dL", i);
175
cpu_avrl[i] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
176
offsetof(CPUState, avr[i].u64[1]), p);
177
p += (i < 10) ? 6 : 7;
180
cpu_nip = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
181
offsetof(CPUState, nip), "nip");
183
cpu_ctr = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
184
offsetof(CPUState, ctr), "ctr");
186
cpu_lr = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
187
offsetof(CPUState, lr), "lr");
189
cpu_xer = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0,
190
offsetof(CPUState, xer), "xer");
192
cpu_fpscr = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0,
193
offsetof(CPUState, fpscr), "fpscr");
195
/* register helpers */
197
#define DEF_HELPER(ret, name, params) tcg_register_helper(name, #name);
203
#if defined(OPTIMIZE_FPRF_UPDATE)
204
static uint16_t *gen_fprf_buf[OPC_BUF_SIZE];
205
static uint16_t **gen_fprf_ptr;
38
#if defined(USE_DIRECT_JUMP)
41
#define TBPARAM(x) (long)(x)
45
#define DEF(s, n, copy_size) INDEX_op_ ## s,
51
static uint16_t *gen_opc_ptr;
52
static uint32_t *gen_opparam_ptr;
56
static always_inline void gen_set_T0 (target_ulong val)
58
#if defined(TARGET_PPC64)
60
gen_op_set_T0_64(val >> 32, val);
66
static always_inline void gen_set_T1 (target_ulong val)
68
#if defined(TARGET_PPC64)
70
gen_op_set_T1_64(val >> 32, val);
76
#define GEN8(func, NAME) \
77
static GenOpFunc *NAME ## _table [8] = { \
78
NAME ## 0, NAME ## 1, NAME ## 2, NAME ## 3, \
79
NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \
81
static always_inline void func (int n) \
83
NAME ## _table[n](); \
86
#define GEN16(func, NAME) \
87
static GenOpFunc *NAME ## _table [16] = { \
88
NAME ## 0, NAME ## 1, NAME ## 2, NAME ## 3, \
89
NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \
90
NAME ## 8, NAME ## 9, NAME ## 10, NAME ## 11, \
91
NAME ## 12, NAME ## 13, NAME ## 14, NAME ## 15, \
93
static always_inline void func (int n) \
95
NAME ## _table[n](); \
98
#define GEN32(func, NAME) \
99
static GenOpFunc *NAME ## _table [32] = { \
100
NAME ## 0, NAME ## 1, NAME ## 2, NAME ## 3, \
101
NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \
102
NAME ## 8, NAME ## 9, NAME ## 10, NAME ## 11, \
103
NAME ## 12, NAME ## 13, NAME ## 14, NAME ## 15, \
104
NAME ## 16, NAME ## 17, NAME ## 18, NAME ## 19, \
105
NAME ## 20, NAME ## 21, NAME ## 22, NAME ## 23, \
106
NAME ## 24, NAME ## 25, NAME ## 26, NAME ## 27, \
107
NAME ## 28, NAME ## 29, NAME ## 30, NAME ## 31, \
109
static always_inline void func (int n) \
111
NAME ## _table[n](); \
114
/* Condition register moves */
115
GEN8(gen_op_load_crf_T0, gen_op_load_crf_T0_crf);
116
GEN8(gen_op_load_crf_T1, gen_op_load_crf_T1_crf);
117
GEN8(gen_op_store_T0_crf, gen_op_store_T0_crf_crf);
118
GEN8(gen_op_store_T1_crf, gen_op_store_T1_crf_crf);
120
/* Floating point condition and status register moves */
121
GEN8(gen_op_load_fpscr_T0, gen_op_load_fpscr_T0_fpscr);
122
GEN8(gen_op_store_T0_fpscr, gen_op_store_T0_fpscr_fpscr);
123
GEN8(gen_op_clear_fpscr, gen_op_clear_fpscr_fpscr);
124
static always_inline void gen_op_store_T0_fpscri (int n, uint8_t param)
126
gen_op_set_T0(param);
127
gen_op_store_T0_fpscr(n);
130
/* General purpose registers moves */
131
GEN32(gen_op_load_gpr_T0, gen_op_load_gpr_T0_gpr);
132
GEN32(gen_op_load_gpr_T1, gen_op_load_gpr_T1_gpr);
133
GEN32(gen_op_load_gpr_T2, gen_op_load_gpr_T2_gpr);
135
GEN32(gen_op_store_T0_gpr, gen_op_store_T0_gpr_gpr);
136
GEN32(gen_op_store_T1_gpr, gen_op_store_T1_gpr_gpr);
138
GEN32(gen_op_store_T2_gpr, gen_op_store_T2_gpr_gpr);
141
/* floating point registers moves */
142
GEN32(gen_op_load_fpr_FT0, gen_op_load_fpr_FT0_fpr);
143
GEN32(gen_op_load_fpr_FT1, gen_op_load_fpr_FT1_fpr);
144
GEN32(gen_op_load_fpr_FT2, gen_op_load_fpr_FT2_fpr);
145
GEN32(gen_op_store_FT0_fpr, gen_op_store_FT0_fpr_fpr);
146
GEN32(gen_op_store_FT1_fpr, gen_op_store_FT1_fpr_fpr);
148
GEN32(gen_op_store_FT2_fpr, gen_op_store_FT2_fpr_fpr);
208
151
/* internal defines */
475
388
/*****************************************************************************/
476
389
/* PowerPC Instructions types definitions */
478
PPC_NONE = 0x0000000000000000ULL,
391
PPC_NONE = 0x0000000000000000ULL,
479
392
/* PowerPC base instructions set */
480
PPC_INSNS_BASE = 0x0000000000000001ULL,
481
/* integer operations instructions */
393
PPC_INSNS_BASE = 0x0000000000000001ULL,
394
/* integer operations instructions */
482
395
#define PPC_INTEGER PPC_INSNS_BASE
483
/* flow control instructions */
396
/* flow control instructions */
484
397
#define PPC_FLOW PPC_INSNS_BASE
485
/* virtual memory instructions */
398
/* virtual memory instructions */
486
399
#define PPC_MEM PPC_INSNS_BASE
487
/* ld/st with reservation instructions */
400
/* ld/st with reservation instructions */
488
401
#define PPC_RES PPC_INSNS_BASE
489
/* spr/msr access instructions */
402
/* cache control instructions */
403
#define PPC_CACHE PPC_INSNS_BASE
404
/* spr/msr access instructions */
490
405
#define PPC_MISC PPC_INSNS_BASE
491
/* Deprecated instruction sets */
492
/* Original POWER instruction set */
493
PPC_POWER = 0x0000000000000002ULL,
494
/* POWER2 instruction set extension */
495
PPC_POWER2 = 0x0000000000000004ULL,
496
/* Power RTC support */
497
PPC_POWER_RTC = 0x0000000000000008ULL,
498
/* Power-to-PowerPC bridge (601) */
499
PPC_POWER_BR = 0x0000000000000010ULL,
500
/* 64 bits PowerPC instruction set */
501
PPC_64B = 0x0000000000000020ULL,
502
/* New 64 bits extensions (PowerPC 2.0x) */
503
PPC_64BX = 0x0000000000000040ULL,
504
/* 64 bits hypervisor extensions */
505
PPC_64H = 0x0000000000000080ULL,
506
/* New wait instruction (PowerPC 2.0x) */
507
PPC_WAIT = 0x0000000000000100ULL,
508
/* Time base mftb instruction */
509
PPC_MFTB = 0x0000000000000200ULL,
511
/* Fixed-point unit extensions */
512
/* PowerPC 602 specific */
513
PPC_602_SPEC = 0x0000000000000400ULL,
514
/* isel instruction */
515
PPC_ISEL = 0x0000000000000800ULL,
516
/* popcntb instruction */
517
PPC_POPCNTB = 0x0000000000001000ULL,
518
/* string load / store */
519
PPC_STRING = 0x0000000000002000ULL,
521
/* Floating-point unit extensions */
522
/* Optional floating point instructions */
523
PPC_FLOAT = 0x0000000000010000ULL,
524
/* New floating-point extensions (PowerPC 2.0x) */
525
PPC_FLOAT_EXT = 0x0000000000020000ULL,
526
PPC_FLOAT_FSQRT = 0x0000000000040000ULL,
527
PPC_FLOAT_FRES = 0x0000000000080000ULL,
528
PPC_FLOAT_FRSQRTE = 0x0000000000100000ULL,
529
PPC_FLOAT_FRSQRTES = 0x0000000000200000ULL,
530
PPC_FLOAT_FSEL = 0x0000000000400000ULL,
531
PPC_FLOAT_STFIWX = 0x0000000000800000ULL,
533
/* Vector/SIMD extensions */
534
/* Altivec support */
535
PPC_ALTIVEC = 0x0000000001000000ULL,
536
/* PowerPC 2.03 SPE extension */
537
PPC_SPE = 0x0000000002000000ULL,
538
/* PowerPC 2.03 SPE floating-point extension */
539
PPC_SPEFPU = 0x0000000004000000ULL,
406
/* Optional floating point instructions */
407
PPC_FLOAT = 0x0000000000000002ULL,
408
PPC_FLOAT_FSQRT = 0x0000000000000004ULL,
409
PPC_FLOAT_FRES = 0x0000000000000008ULL,
410
PPC_FLOAT_FRSQRTE = 0x0000000000000010ULL,
411
PPC_FLOAT_FSEL = 0x0000000000000020ULL,
412
PPC_FLOAT_STFIWX = 0x0000000000000040ULL,
413
/* external control instructions */
414
PPC_EXTERN = 0x0000000000000080ULL,
415
/* segment register access instructions */
416
PPC_SEGMENT = 0x0000000000000100ULL,
417
/* Optional cache control instruction */
418
PPC_CACHE_DCBA = 0x0000000000000200ULL,
541
419
/* Optional memory control instructions */
542
PPC_MEM_TLBIA = 0x0000000010000000ULL,
543
PPC_MEM_TLBIE = 0x0000000020000000ULL,
544
PPC_MEM_TLBSYNC = 0x0000000040000000ULL,
545
/* sync instruction */
546
PPC_MEM_SYNC = 0x0000000080000000ULL,
547
/* eieio instruction */
548
PPC_MEM_EIEIO = 0x0000000100000000ULL,
550
/* Cache control instructions */
551
PPC_CACHE = 0x0000000200000000ULL,
552
/* icbi instruction */
553
PPC_CACHE_ICBI = 0x0000000400000000ULL,
554
/* dcbz instruction with fixed cache line size */
555
PPC_CACHE_DCBZ = 0x0000000800000000ULL,
556
/* dcbz instruction with tunable cache line size */
557
PPC_CACHE_DCBZT = 0x0000001000000000ULL,
558
/* dcba instruction */
559
PPC_CACHE_DCBA = 0x0000002000000000ULL,
560
/* Freescale cache locking instructions */
561
PPC_CACHE_LOCK = 0x0000004000000000ULL,
563
/* MMU related extensions */
564
/* external control instructions */
565
PPC_EXTERN = 0x0000010000000000ULL,
566
/* segment register access instructions */
567
PPC_SEGMENT = 0x0000020000000000ULL,
568
/* PowerPC 6xx TLB management instructions */
569
PPC_6xx_TLB = 0x0000040000000000ULL,
570
/* PowerPC 74xx TLB management instructions */
571
PPC_74xx_TLB = 0x0000080000000000ULL,
572
/* PowerPC 40x TLB management instructions */
573
PPC_40x_TLB = 0x0000100000000000ULL,
574
/* segment register access instructions for PowerPC 64 "bridge" */
575
PPC_SEGMENT_64B = 0x0000200000000000ULL,
577
PPC_SLBI = 0x0000400000000000ULL,
420
PPC_MEM_TLBIA = 0x0000000000000400ULL,
421
PPC_MEM_TLBIE = 0x0000000000000800ULL,
422
PPC_MEM_TLBSYNC = 0x0000000000001000ULL,
424
PPC_MEM_SYNC = 0x0000000000002000ULL,
425
/* PowerPC 6xx TLB management instructions */
426
PPC_6xx_TLB = 0x0000000000004000ULL,
427
/* Altivec support */
428
PPC_ALTIVEC = 0x0000000000008000ULL,
429
/* Time base mftb instruction */
430
PPC_MFTB = 0x0000000000010000ULL,
579
431
/* Embedded PowerPC dedicated instructions */
580
PPC_WRTEE = 0x0001000000000000ULL,
432
PPC_EMB_COMMON = 0x0000000000020000ULL,
581
433
/* PowerPC 40x exception model */
582
PPC_40x_EXCP = 0x0002000000000000ULL,
434
PPC_40x_EXCP = 0x0000000000040000ULL,
435
/* PowerPC 40x TLB management instructions */
436
PPC_40x_TLB = 0x0000000000080000ULL,
583
437
/* PowerPC 405 Mac instructions */
584
PPC_405_MAC = 0x0004000000000000ULL,
438
PPC_405_MAC = 0x0000000000100000ULL,
585
439
/* PowerPC 440 specific instructions */
586
PPC_440_SPEC = 0x0008000000000000ULL,
440
PPC_440_SPEC = 0x0000000000200000ULL,
441
/* Power-to-PowerPC bridge (601) */
442
PPC_POWER_BR = 0x0000000000400000ULL,
443
/* PowerPC 602 specific */
444
PPC_602_SPEC = 0x0000000000800000ULL,
445
/* Deprecated instructions */
446
/* Original POWER instruction set */
447
PPC_POWER = 0x0000000001000000ULL,
448
/* POWER2 instruction set extension */
449
PPC_POWER2 = 0x0000000002000000ULL,
450
/* Power RTC support */
451
PPC_POWER_RTC = 0x0000000004000000ULL,
452
/* 64 bits PowerPC instruction set */
453
PPC_64B = 0x0000000008000000ULL,
454
/* 64 bits hypervisor extensions */
455
PPC_64H = 0x0000000010000000ULL,
456
/* segment register access instructions for PowerPC 64 "bridge" */
457
PPC_SEGMENT_64B = 0x0000000020000000ULL,
587
458
/* BookE (embedded) PowerPC specification */
588
PPC_BOOKE = 0x0010000000000000ULL,
589
/* mfapidi instruction */
590
PPC_MFAPIDI = 0x0020000000000000ULL,
591
/* tlbiva instruction */
592
PPC_TLBIVA = 0x0040000000000000ULL,
593
/* tlbivax instruction */
594
PPC_TLBIVAX = 0x0080000000000000ULL,
459
PPC_BOOKE = 0x0000000040000000ULL,
461
PPC_MEM_EIEIO = 0x0000000080000000ULL,
462
/* e500 vector instructions */
463
PPC_E500_VECTOR = 0x0000000100000000ULL,
595
464
/* PowerPC 4xx dedicated instructions */
596
PPC_4xx_COMMON = 0x0100000000000000ULL,
465
PPC_4xx_COMMON = 0x0000000200000000ULL,
466
/* PowerPC 2.03 specification extensions */
467
PPC_203 = 0x0000000400000000ULL,
468
/* PowerPC 2.03 SPE extension */
469
PPC_SPE = 0x0000000800000000ULL,
470
/* PowerPC 2.03 SPE floating-point extension */
471
PPC_SPEFPU = 0x0000001000000000ULL,
473
PPC_SLBI = 0x0000002000000000ULL,
597
474
/* PowerPC 40x ibct instructions */
598
PPC_40x_ICBT = 0x0200000000000000ULL,
475
PPC_40x_ICBT = 0x0000004000000000ULL,
476
/* PowerPC 74xx TLB management instructions */
477
PPC_74xx_TLB = 0x0000008000000000ULL,
478
/* More BookE (embedded) instructions... */
479
PPC_BOOKE_EXT = 0x0000010000000000ULL,
599
480
/* rfmci is not implemented in all BookE PowerPC */
600
PPC_RFMCI = 0x0400000000000000ULL,
601
/* rfdi instruction */
602
PPC_RFDI = 0x0800000000000000ULL,
604
PPC_DCR = 0x1000000000000000ULL,
605
/* DCR extended accesse */
606
PPC_DCRX = 0x2000000000000000ULL,
481
PPC_RFMCI = 0x0000020000000000ULL,
607
482
/* user-mode DCR access, implemented in PowerPC 460 */
608
PPC_DCRUX = 0x4000000000000000ULL,
483
PPC_DCRUX = 0x0000040000000000ULL,
484
/* New floating-point extensions (PowerPC 2.0x) */
485
PPC_FLOAT_EXT = 0x0000080000000000ULL,
486
/* New wait instruction (PowerPC 2.0x) */
487
PPC_WAIT = 0x0000100000000000ULL,
488
/* New 64 bits extensions (PowerPC 2.0x) */
489
PPC_64BX = 0x0000200000000000ULL,
490
/* dcbz instruction with fixed cache line size */
491
PPC_CACHE_DCBZ = 0x0000400000000000ULL,
492
/* dcbz instruction with tunable cache line size */
493
PPC_CACHE_DCBZT = 0x0000800000000000ULL,
611
496
/*****************************************************************************/
710
568
.handler = gen_invalid,
713
/*** Integer comparison ***/
715
static always_inline void gen_op_cmp(TCGv arg0, TCGv arg1, int s, int crf)
719
tcg_gen_trunc_tl_i32(cpu_crf[crf], cpu_xer);
720
tcg_gen_shri_i32(cpu_crf[crf], cpu_crf[crf], XER_SO);
721
tcg_gen_andi_i32(cpu_crf[crf], cpu_crf[crf], 1);
723
l1 = gen_new_label();
724
l2 = gen_new_label();
725
l3 = gen_new_label();
727
tcg_gen_brcond_tl(TCG_COND_LT, arg0, arg1, l1);
728
tcg_gen_brcond_tl(TCG_COND_GT, arg0, arg1, l2);
730
tcg_gen_brcond_tl(TCG_COND_LTU, arg0, arg1, l1);
731
tcg_gen_brcond_tl(TCG_COND_GTU, arg0, arg1, l2);
733
tcg_gen_ori_i32(cpu_crf[crf], cpu_crf[crf], 1 << CRF_EQ);
736
tcg_gen_ori_i32(cpu_crf[crf], cpu_crf[crf], 1 << CRF_LT);
739
tcg_gen_ori_i32(cpu_crf[crf], cpu_crf[crf], 1 << CRF_GT);
743
static always_inline void gen_op_cmpi(TCGv arg0, target_ulong arg1, int s, int crf)
745
TCGv t0 = tcg_const_local_tl(arg1);
746
gen_op_cmp(arg0, t0, s, crf);
750
#if defined(TARGET_PPC64)
751
static always_inline void gen_op_cmp32(TCGv arg0, TCGv arg1, int s, int crf)
754
t0 = tcg_temp_local_new(TCG_TYPE_TL);
755
t1 = tcg_temp_local_new(TCG_TYPE_TL);
757
tcg_gen_ext32s_tl(t0, arg0);
758
tcg_gen_ext32s_tl(t1, arg1);
760
tcg_gen_ext32u_tl(t0, arg0);
761
tcg_gen_ext32u_tl(t1, arg1);
763
gen_op_cmp(t0, t1, s, crf);
768
static always_inline void gen_op_cmpi32(TCGv arg0, target_ulong arg1, int s, int crf)
770
TCGv t0 = tcg_const_local_tl(arg1);
771
gen_op_cmp32(arg0, t0, s, crf);
776
static always_inline void gen_set_Rc0 (DisasContext *ctx, TCGv reg)
778
#if defined(TARGET_PPC64)
780
gen_op_cmpi32(reg, 0, 1, 0);
783
gen_op_cmpi(reg, 0, 1, 0);
787
GEN_HANDLER(cmp, 0x1F, 0x00, 0x00, 0x00400000, PPC_INTEGER)
789
#if defined(TARGET_PPC64)
790
if (!(ctx->sf_mode && (ctx->opcode & 0x00200000)))
791
gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
792
1, crfD(ctx->opcode));
795
gen_op_cmp(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
796
1, crfD(ctx->opcode));
800
GEN_HANDLER(cmpi, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER)
802
#if defined(TARGET_PPC64)
803
if (!(ctx->sf_mode && (ctx->opcode & 0x00200000)))
804
gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], SIMM(ctx->opcode),
805
1, crfD(ctx->opcode));
808
gen_op_cmpi(cpu_gpr[rA(ctx->opcode)], SIMM(ctx->opcode),
809
1, crfD(ctx->opcode));
813
GEN_HANDLER(cmpl, 0x1F, 0x00, 0x01, 0x00400000, PPC_INTEGER)
815
#if defined(TARGET_PPC64)
816
if (!(ctx->sf_mode && (ctx->opcode & 0x00200000)))
817
gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
818
0, crfD(ctx->opcode));
821
gen_op_cmp(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
822
0, crfD(ctx->opcode));
826
GEN_HANDLER(cmpli, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER)
828
#if defined(TARGET_PPC64)
829
if (!(ctx->sf_mode && (ctx->opcode & 0x00200000)))
830
gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], UIMM(ctx->opcode),
831
0, crfD(ctx->opcode));
834
gen_op_cmpi(cpu_gpr[rA(ctx->opcode)], UIMM(ctx->opcode),
835
0, crfD(ctx->opcode));
838
/* isel (PowerPC 2.03 specification) */
839
GEN_HANDLER(isel, 0x1F, 0x0F, 0xFF, 0x00000001, PPC_ISEL)
842
uint32_t bi = rC(ctx->opcode);
846
l1 = gen_new_label();
847
l2 = gen_new_label();
849
mask = 1 << (3 - (bi & 0x03));
850
t0 = tcg_temp_new(TCG_TYPE_I32);
851
tcg_gen_andi_i32(t0, cpu_crf[bi >> 2], mask);
852
tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1);
853
if (rA(ctx->opcode) == 0)
854
tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
856
tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
859
tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
864
571
/*** Integer arithmetic ***/
866
static always_inline void gen_op_arith_compute_ov(DisasContext *ctx, TCGv arg0, TCGv arg1, TCGv arg2, int sub)
871
l1 = gen_new_label();
872
/* Start with XER OV disabled, the most likely case */
873
tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV));
874
t0 = tcg_temp_local_new(TCG_TYPE_TL);
875
tcg_gen_xor_tl(t0, arg0, arg1);
876
#if defined(TARGET_PPC64)
878
tcg_gen_ext32s_tl(t0, t0);
881
tcg_gen_brcondi_tl(TCG_COND_LT, t0, 0, l1);
883
tcg_gen_brcondi_tl(TCG_COND_GE, t0, 0, l1);
884
tcg_gen_xor_tl(t0, arg1, arg2);
885
#if defined(TARGET_PPC64)
887
tcg_gen_ext32s_tl(t0, t0);
890
tcg_gen_brcondi_tl(TCG_COND_GE, t0, 0, l1);
892
tcg_gen_brcondi_tl(TCG_COND_LT, t0, 0, l1);
893
tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO));
898
static always_inline void gen_op_arith_compute_ca(DisasContext *ctx, TCGv arg1, TCGv arg2, int sub)
900
int l1 = gen_new_label();
902
#if defined(TARGET_PPC64)
903
if (!(ctx->sf_mode)) {
905
t0 = tcg_temp_new(TCG_TYPE_TL);
906
t1 = tcg_temp_new(TCG_TYPE_TL);
908
tcg_gen_ext32u_tl(t0, arg1);
909
tcg_gen_ext32u_tl(t1, arg2);
911
tcg_gen_brcond_tl(TCG_COND_GTU, t0, t1, l1);
913
tcg_gen_brcond_tl(TCG_COND_GEU, t0, t1, l1);
915
tcg_gen_ori_tl(cpu_xer, cpu_xer, 1 << XER_CA);
923
tcg_gen_brcond_tl(TCG_COND_GTU, arg1, arg2, l1);
925
tcg_gen_brcond_tl(TCG_COND_GEU, arg1, arg2, l1);
927
tcg_gen_ori_tl(cpu_xer, cpu_xer, 1 << XER_CA);
932
/* Common add function */
933
static always_inline void gen_op_arith_add(DisasContext *ctx, TCGv ret, TCGv arg1, TCGv arg2,
934
int add_ca, int compute_ca, int compute_ov)
938
if ((!compute_ca && !compute_ov) ||
939
(GET_TCGV(ret) != GET_TCGV(arg1) && GET_TCGV(ret) != GET_TCGV(arg2))) {
942
t0 = tcg_temp_local_new(TCG_TYPE_TL);
946
t1 = tcg_temp_local_new(TCG_TYPE_TL);
947
tcg_gen_andi_tl(t1, cpu_xer, (1 << XER_CA));
948
tcg_gen_shri_tl(t1, t1, XER_CA);
951
if (compute_ca && compute_ov) {
952
/* Start with XER CA and OV disabled, the most likely case */
953
tcg_gen_andi_tl(cpu_xer, cpu_xer, ~((1 << XER_CA) | (1 << XER_OV)));
954
} else if (compute_ca) {
955
/* Start with XER CA disabled, the most likely case */
956
tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA));
957
} else if (compute_ov) {
958
/* Start with XER OV disabled, the most likely case */
959
tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV));
962
tcg_gen_add_tl(t0, arg1, arg2);
965
gen_op_arith_compute_ca(ctx, t0, arg1, 0);
968
tcg_gen_add_tl(t0, t0, t1);
969
gen_op_arith_compute_ca(ctx, t0, t1, 0);
973
gen_op_arith_compute_ov(ctx, t0, arg1, arg2, 0);
976
if (unlikely(Rc(ctx->opcode) != 0))
977
gen_set_Rc0(ctx, t0);
979
if (GET_TCGV(t0) != GET_TCGV(ret)) {
980
tcg_gen_mov_tl(ret, t0);
984
/* Add functions with two operands */
985
#define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
986
GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x00000000, PPC_INTEGER) \
988
gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
989
cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
990
add_ca, compute_ca, compute_ov); \
992
/* Add functions with one operand and one immediate */
993
#define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
994
add_ca, compute_ca, compute_ov) \
995
GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x0000F800, PPC_INTEGER) \
997
TCGv t0 = tcg_const_local_tl(const_val); \
998
gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
999
cpu_gpr[rA(ctx->opcode)], t0, \
1000
add_ca, compute_ca, compute_ov); \
1001
tcg_temp_free(t0); \
1004
/* add add. addo addo. */
1005
GEN_INT_ARITH_ADD(add, 0x08, 0, 0, 0)
1006
GEN_INT_ARITH_ADD(addo, 0x18, 0, 0, 1)
1007
/* addc addc. addco addco. */
1008
GEN_INT_ARITH_ADD(addc, 0x00, 0, 1, 0)
1009
GEN_INT_ARITH_ADD(addco, 0x10, 0, 1, 1)
1010
/* adde adde. addeo addeo. */
1011
GEN_INT_ARITH_ADD(adde, 0x04, 1, 1, 0)
1012
GEN_INT_ARITH_ADD(addeo, 0x14, 1, 1, 1)
572
#define __GEN_INT_ARITH2(name, opc1, opc2, opc3, inval, type) \
573
GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
575
gen_op_load_gpr_T0(rA(ctx->opcode)); \
576
gen_op_load_gpr_T1(rB(ctx->opcode)); \
578
gen_op_store_T0_gpr(rD(ctx->opcode)); \
579
if (unlikely(Rc(ctx->opcode) != 0)) \
583
#define __GEN_INT_ARITH2_O(name, opc1, opc2, opc3, inval, type) \
584
GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
586
gen_op_load_gpr_T0(rA(ctx->opcode)); \
587
gen_op_load_gpr_T1(rB(ctx->opcode)); \
589
gen_op_store_T0_gpr(rD(ctx->opcode)); \
590
if (unlikely(Rc(ctx->opcode) != 0)) \
594
#define __GEN_INT_ARITH1(name, opc1, opc2, opc3, type) \
595
GEN_HANDLER(name, opc1, opc2, opc3, 0x0000F800, type) \
597
gen_op_load_gpr_T0(rA(ctx->opcode)); \
599
gen_op_store_T0_gpr(rD(ctx->opcode)); \
600
if (unlikely(Rc(ctx->opcode) != 0)) \
603
#define __GEN_INT_ARITH1_O(name, opc1, opc2, opc3, type) \
604
GEN_HANDLER(name, opc1, opc2, opc3, 0x0000F800, type) \
606
gen_op_load_gpr_T0(rA(ctx->opcode)); \
608
gen_op_store_T0_gpr(rD(ctx->opcode)); \
609
if (unlikely(Rc(ctx->opcode) != 0)) \
613
/* Two operands arithmetic functions */
614
#define GEN_INT_ARITH2(name, opc1, opc2, opc3, type) \
615
__GEN_INT_ARITH2(name, opc1, opc2, opc3, 0x00000000, type) \
616
__GEN_INT_ARITH2_O(name##o, opc1, opc2, opc3 | 0x10, 0x00000000, type)
618
/* Two operands arithmetic functions with no overflow allowed */
619
#define GEN_INT_ARITHN(name, opc1, opc2, opc3, type) \
620
__GEN_INT_ARITH2(name, opc1, opc2, opc3, 0x00000400, type)
622
/* One operand arithmetic functions */
623
#define GEN_INT_ARITH1(name, opc1, opc2, opc3, type) \
624
__GEN_INT_ARITH1(name, opc1, opc2, opc3, type) \
625
__GEN_INT_ARITH1_O(name##o, opc1, opc2, opc3 | 0x10, type)
627
#if defined(TARGET_PPC64)
628
#define __GEN_INT_ARITH2_64(name, opc1, opc2, opc3, inval, type) \
629
GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
631
gen_op_load_gpr_T0(rA(ctx->opcode)); \
632
gen_op_load_gpr_T1(rB(ctx->opcode)); \
634
gen_op_##name##_64(); \
637
gen_op_store_T0_gpr(rD(ctx->opcode)); \
638
if (unlikely(Rc(ctx->opcode) != 0)) \
642
#define __GEN_INT_ARITH2_O_64(name, opc1, opc2, opc3, inval, type) \
643
GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
645
gen_op_load_gpr_T0(rA(ctx->opcode)); \
646
gen_op_load_gpr_T1(rB(ctx->opcode)); \
648
gen_op_##name##_64(); \
651
gen_op_store_T0_gpr(rD(ctx->opcode)); \
652
if (unlikely(Rc(ctx->opcode) != 0)) \
656
#define __GEN_INT_ARITH1_64(name, opc1, opc2, opc3, type) \
657
GEN_HANDLER(name, opc1, opc2, opc3, 0x0000F800, type) \
659
gen_op_load_gpr_T0(rA(ctx->opcode)); \
661
gen_op_##name##_64(); \
664
gen_op_store_T0_gpr(rD(ctx->opcode)); \
665
if (unlikely(Rc(ctx->opcode) != 0)) \
668
#define __GEN_INT_ARITH1_O_64(name, opc1, opc2, opc3, type) \
669
GEN_HANDLER(name, opc1, opc2, opc3, 0x0000F800, type) \
671
gen_op_load_gpr_T0(rA(ctx->opcode)); \
673
gen_op_##name##_64(); \
676
gen_op_store_T0_gpr(rD(ctx->opcode)); \
677
if (unlikely(Rc(ctx->opcode) != 0)) \
681
/* Two operands arithmetic functions */
682
#define GEN_INT_ARITH2_64(name, opc1, opc2, opc3, type) \
683
__GEN_INT_ARITH2_64(name, opc1, opc2, opc3, 0x00000000, type) \
684
__GEN_INT_ARITH2_O_64(name##o, opc1, opc2, opc3 | 0x10, 0x00000000, type)
686
/* Two operands arithmetic functions with no overflow allowed */
687
#define GEN_INT_ARITHN_64(name, opc1, opc2, opc3, type) \
688
__GEN_INT_ARITH2_64(name, opc1, opc2, opc3, 0x00000400, type)
690
/* One operand arithmetic functions */
691
#define GEN_INT_ARITH1_64(name, opc1, opc2, opc3, type) \
692
__GEN_INT_ARITH1_64(name, opc1, opc2, opc3, type) \
693
__GEN_INT_ARITH1_O_64(name##o, opc1, opc2, opc3 | 0x10, type)
695
#define GEN_INT_ARITH2_64 GEN_INT_ARITH2
696
#define GEN_INT_ARITHN_64 GEN_INT_ARITHN
697
#define GEN_INT_ARITH1_64 GEN_INT_ARITH1
700
/* add add. addo addo. */
701
static always_inline void gen_op_addo (void)
707
#if defined(TARGET_PPC64)
708
#define gen_op_add_64 gen_op_add
709
static always_inline void gen_op_addo_64 (void)
713
gen_op_check_addo_64();
716
GEN_INT_ARITH2_64 (add, 0x1F, 0x0A, 0x08, PPC_INTEGER);
717
/* addc addc. addco addco. */
718
static always_inline void gen_op_addc (void)
724
static always_inline void gen_op_addco (void)
731
#if defined(TARGET_PPC64)
732
static always_inline void gen_op_addc_64 (void)
736
gen_op_check_addc_64();
738
static always_inline void gen_op_addco_64 (void)
742
gen_op_check_addc_64();
743
gen_op_check_addo_64();
746
GEN_INT_ARITH2_64 (addc, 0x1F, 0x0A, 0x00, PPC_INTEGER);
747
/* adde adde. addeo addeo. */
748
static always_inline void gen_op_addeo (void)
754
#if defined(TARGET_PPC64)
755
static always_inline void gen_op_addeo_64 (void)
759
gen_op_check_addo_64();
762
GEN_INT_ARITH2_64 (adde, 0x1F, 0x0A, 0x04, PPC_INTEGER);
1013
763
/* addme addme. addmeo addmeo. */
1014
GEN_INT_ARITH_ADD_CONST(addme, 0x07, -1LL, 1, 1, 0)
1015
GEN_INT_ARITH_ADD_CONST(addmeo, 0x17, -1LL, 1, 1, 1)
1016
/* addze addze. addzeo addzeo.*/
1017
GEN_INT_ARITH_ADD_CONST(addze, 0x06, 0, 1, 1, 0)
1018
GEN_INT_ARITH_ADD_CONST(addzeo, 0x16, 0, 1, 1, 1)
764
static always_inline void gen_op_addme (void)
769
#if defined(TARGET_PPC64)
770
static always_inline void gen_op_addme_64 (void)
776
GEN_INT_ARITH1_64 (addme, 0x1F, 0x0A, 0x07, PPC_INTEGER);
777
/* addze addze. addzeo addzeo. */
778
static always_inline void gen_op_addze (void)
784
static always_inline void gen_op_addzeo (void)
791
#if defined(TARGET_PPC64)
792
static always_inline void gen_op_addze_64 (void)
796
gen_op_check_addc_64();
798
static always_inline void gen_op_addzeo_64 (void)
802
gen_op_check_addc_64();
803
gen_op_check_addo_64();
806
GEN_INT_ARITH1_64 (addze, 0x1F, 0x0A, 0x06, PPC_INTEGER);
807
/* divw divw. divwo divwo. */
808
GEN_INT_ARITH2 (divw, 0x1F, 0x0B, 0x0F, PPC_INTEGER);
809
/* divwu divwu. divwuo divwuo. */
810
GEN_INT_ARITH2 (divwu, 0x1F, 0x0B, 0x0E, PPC_INTEGER);
812
GEN_INT_ARITHN (mulhw, 0x1F, 0x0B, 0x02, PPC_INTEGER);
814
GEN_INT_ARITHN (mulhwu, 0x1F, 0x0B, 0x00, PPC_INTEGER);
815
/* mullw mullw. mullwo mullwo. */
816
GEN_INT_ARITH2 (mullw, 0x1F, 0x0B, 0x07, PPC_INTEGER);
817
/* neg neg. nego nego. */
818
GEN_INT_ARITH1_64 (neg, 0x1F, 0x08, 0x03, PPC_INTEGER);
819
/* subf subf. subfo subfo. */
820
static always_inline void gen_op_subfo (void)
824
gen_op_check_subfo();
826
#if defined(TARGET_PPC64)
827
#define gen_op_subf_64 gen_op_subf
828
static always_inline void gen_op_subfo_64 (void)
832
gen_op_check_subfo_64();
835
GEN_INT_ARITH2_64 (subf, 0x1F, 0x08, 0x01, PPC_INTEGER);
836
/* subfc subfc. subfco subfco. */
837
static always_inline void gen_op_subfc (void)
840
gen_op_check_subfc();
842
static always_inline void gen_op_subfco (void)
846
gen_op_check_subfc();
847
gen_op_check_subfo();
849
#if defined(TARGET_PPC64)
850
static always_inline void gen_op_subfc_64 (void)
853
gen_op_check_subfc_64();
855
static always_inline void gen_op_subfco_64 (void)
859
gen_op_check_subfc_64();
860
gen_op_check_subfo_64();
863
GEN_INT_ARITH2_64 (subfc, 0x1F, 0x08, 0x00, PPC_INTEGER);
864
/* subfe subfe. subfeo subfeo. */
865
static always_inline void gen_op_subfeo (void)
869
gen_op_check_subfo();
871
#if defined(TARGET_PPC64)
872
#define gen_op_subfe_64 gen_op_subfe
873
static always_inline void gen_op_subfeo_64 (void)
877
gen_op_check_subfo_64();
880
GEN_INT_ARITH2_64 (subfe, 0x1F, 0x08, 0x04, PPC_INTEGER);
881
/* subfme subfme. subfmeo subfmeo. */
882
GEN_INT_ARITH1_64 (subfme, 0x1F, 0x08, 0x07, PPC_INTEGER);
883
/* subfze subfze. subfzeo subfzeo. */
884
GEN_INT_ARITH1_64 (subfze, 0x1F, 0x08, 0x06, PPC_INTEGER);
1020
886
GEN_HANDLER(addi, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1066
946
if (rA(ctx->opcode) == 0) {
1068
tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], simm << 16);
1070
tcg_gen_addi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], simm << 16);
1074
static always_inline void gen_op_arith_divw (DisasContext *ctx, TCGv ret, TCGv arg1, TCGv arg2,
1075
int sign, int compute_ov)
1077
int l1 = gen_new_label();
1078
int l2 = gen_new_label();
1079
TCGv t0 = tcg_temp_local_new(TCG_TYPE_I32);
1080
TCGv t1 = tcg_temp_local_new(TCG_TYPE_I32);
1082
tcg_gen_trunc_tl_i32(t0, arg1);
1083
tcg_gen_trunc_tl_i32(t1, arg2);
1084
tcg_gen_brcondi_i32(TCG_COND_EQ, t1, 0, l1);
1086
int l3 = gen_new_label();
1087
tcg_gen_brcondi_i32(TCG_COND_NE, t1, -1, l3);
1088
tcg_gen_brcondi_i32(TCG_COND_EQ, t0, INT32_MIN, l1);
1090
tcg_gen_div_i32(t0, t0, t1);
1092
tcg_gen_divu_i32(t0, t0, t1);
1095
tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV));
1100
tcg_gen_sari_i32(t0, t0, 31);
1102
tcg_gen_movi_i32(t0, 0);
1105
tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO));
1108
tcg_gen_extu_i32_tl(ret, t0);
1111
if (unlikely(Rc(ctx->opcode) != 0))
1112
gen_set_Rc0(ctx, ret);
1115
#define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
1116
GEN_HANDLER(name, 0x1F, 0x0B, opc3, 0x00000000, PPC_INTEGER) \
1118
gen_op_arith_divw(ctx, cpu_gpr[rD(ctx->opcode)], \
1119
cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1120
sign, compute_ov); \
1122
/* divwu divwu. divwuo divwuo. */
1123
GEN_INT_ARITH_DIVW(divwu, 0x0E, 0, 0);
1124
GEN_INT_ARITH_DIVW(divwuo, 0x1E, 0, 1);
1125
/* divw divw. divwo divwo. */
1126
GEN_INT_ARITH_DIVW(divw, 0x0F, 1, 0);
1127
GEN_INT_ARITH_DIVW(divwo, 0x1F, 1, 1);
1128
#if defined(TARGET_PPC64)
1129
static always_inline void gen_op_arith_divd (DisasContext *ctx, TCGv ret, TCGv arg1, TCGv arg2,
1130
int sign, int compute_ov)
1132
int l1 = gen_new_label();
1133
int l2 = gen_new_label();
1135
tcg_gen_brcondi_i64(TCG_COND_EQ, arg2, 0, l1);
1137
int l3 = gen_new_label();
1138
tcg_gen_brcondi_i64(TCG_COND_NE, arg2, -1, l3);
1139
tcg_gen_brcondi_i64(TCG_COND_EQ, arg1, INT64_MIN, l1);
1141
tcg_gen_div_i64(ret, arg1, arg2);
1143
tcg_gen_divu_i64(ret, arg1, arg2);
1146
tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV));
1151
tcg_gen_sari_i64(ret, arg1, 63);
1153
tcg_gen_movi_i64(ret, 0);
1156
tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO));
1159
if (unlikely(Rc(ctx->opcode) != 0))
1160
gen_set_Rc0(ctx, ret);
1162
#define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
1163
GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B) \
1165
gen_op_arith_divd(ctx, cpu_gpr[rD(ctx->opcode)], \
1166
cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1167
sign, compute_ov); \
1169
/* divwu divwu. divwuo divwuo. */
1170
GEN_INT_ARITH_DIVD(divdu, 0x0E, 0, 0);
1171
GEN_INT_ARITH_DIVD(divduo, 0x1E, 0, 1);
1172
/* divw divw. divwo divwo. */
1173
GEN_INT_ARITH_DIVD(divd, 0x0F, 1, 0);
1174
GEN_INT_ARITH_DIVD(divdo, 0x1F, 1, 1);
1178
GEN_HANDLER(mulhw, 0x1F, 0x0B, 0x02, 0x00000400, PPC_INTEGER)
1182
t0 = tcg_temp_new(TCG_TYPE_I64);
1183
t1 = tcg_temp_new(TCG_TYPE_I64);
1184
#if defined(TARGET_PPC64)
1185
tcg_gen_ext32s_tl(t0, cpu_gpr[rA(ctx->opcode)]);
1186
tcg_gen_ext32s_tl(t1, cpu_gpr[rB(ctx->opcode)]);
1187
tcg_gen_mul_i64(t0, t0, t1);
1188
tcg_gen_shri_i64(cpu_gpr[rD(ctx->opcode)], t0, 32);
1190
tcg_gen_ext_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
1191
tcg_gen_ext_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
1192
tcg_gen_mul_i64(t0, t0, t1);
1193
tcg_gen_shri_i64(t0, t0, 32);
1194
tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t0);
1198
if (unlikely(Rc(ctx->opcode) != 0))
1199
gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1201
/* mulhwu mulhwu. */
1202
GEN_HANDLER(mulhwu, 0x1F, 0x0B, 0x00, 0x00000400, PPC_INTEGER)
1206
t0 = tcg_temp_new(TCG_TYPE_I64);
1207
t1 = tcg_temp_new(TCG_TYPE_I64);
1208
#if defined(TARGET_PPC64)
1209
tcg_gen_ext32u_i64(t0, cpu_gpr[rA(ctx->opcode)]);
1210
tcg_gen_ext32u_i64(t1, cpu_gpr[rB(ctx->opcode)]);
1211
tcg_gen_mul_i64(t0, t0, t1);
1212
tcg_gen_shri_i64(cpu_gpr[rD(ctx->opcode)], t0, 32);
1214
tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
1215
tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
1216
tcg_gen_mul_i64(t0, t0, t1);
1217
tcg_gen_shri_i64(t0, t0, 32);
1218
tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t0);
1222
if (unlikely(Rc(ctx->opcode) != 0))
1223
gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1226
GEN_HANDLER(mullw, 0x1F, 0x0B, 0x07, 0x00000000, PPC_INTEGER)
1228
tcg_gen_mul_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1229
cpu_gpr[rB(ctx->opcode)]);
1230
tcg_gen_ext32s_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)]);
1231
if (unlikely(Rc(ctx->opcode) != 0))
1232
gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1234
/* mullwo mullwo. */
1235
GEN_HANDLER(mullwo, 0x1F, 0x0B, 0x17, 0x00000000, PPC_INTEGER)
1240
t0 = tcg_temp_new(TCG_TYPE_I64);
1241
t1 = tcg_temp_new(TCG_TYPE_I64);
1242
l1 = gen_new_label();
1243
/* Start with XER OV disabled, the most likely case */
1244
tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV));
1245
#if defined(TARGET_PPC64)
1246
tcg_gen_ext32s_i64(t0, cpu_gpr[rA(ctx->opcode)]);
1247
tcg_gen_ext32s_i64(t1, cpu_gpr[rB(ctx->opcode)]);
1249
tcg_gen_ext_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
1250
tcg_gen_ext_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
1252
tcg_gen_mul_i64(t0, t0, t1);
1253
#if defined(TARGET_PPC64)
1254
tcg_gen_ext32s_i64(cpu_gpr[rD(ctx->opcode)], t0);
1255
tcg_gen_brcond_i64(TCG_COND_EQ, t0, cpu_gpr[rD(ctx->opcode)], l1);
1257
tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t0);
1258
tcg_gen_ext32s_i64(t1, t0);
1259
tcg_gen_brcond_i64(TCG_COND_EQ, t0, t1, l1);
1261
tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO));
1265
if (unlikely(Rc(ctx->opcode) != 0))
1266
gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
948
gen_set_T0(simm << 16);
950
gen_op_load_gpr_T0(rA(ctx->opcode));
951
if (likely(simm != 0))
952
gen_op_addi(simm << 16);
954
gen_op_store_T0_gpr(rD(ctx->opcode));
1269
957
GEN_HANDLER(mulli, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1271
tcg_gen_muli_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1274
#if defined(TARGET_PPC64)
1275
#define GEN_INT_ARITH_MUL_HELPER(name, opc3) \
1276
GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B) \
1278
tcg_gen_helper_1_2(helper_##name, cpu_gpr[rD(ctx->opcode)], \
1279
cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
1280
if (unlikely(Rc(ctx->opcode) != 0)) \
1281
gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); \
1284
GEN_INT_ARITH_MUL_HELPER(mulhdu, 0x00);
1285
/* mulhdu mulhdu. */
1286
GEN_INT_ARITH_MUL_HELPER(mulhd, 0x02);
1288
GEN_HANDLER(mulld, 0x1F, 0x09, 0x07, 0x00000000, PPC_64B)
1290
tcg_gen_mul_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1291
cpu_gpr[rB(ctx->opcode)]);
1292
if (unlikely(Rc(ctx->opcode) != 0))
1293
gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1295
/* mulldo mulldo. */
1296
GEN_INT_ARITH_MUL_HELPER(mulldo, 0x17);
1299
/* neg neg. nego nego. */
1300
static always_inline void gen_op_arith_neg (DisasContext *ctx, TCGv ret, TCGv arg1, int ov_check)
1302
int l1 = gen_new_label();
1303
int l2 = gen_new_label();
1304
TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
1305
#if defined(TARGET_PPC64)
1307
tcg_gen_mov_tl(t0, arg1);
1308
tcg_gen_brcondi_tl(TCG_COND_EQ, t0, INT64_MIN, l1);
1312
tcg_gen_ext32s_tl(t0, arg1);
1313
tcg_gen_brcondi_tl(TCG_COND_EQ, t0, INT32_MIN, l1);
1315
tcg_gen_neg_tl(ret, arg1);
1317
tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV));
1321
tcg_gen_mov_tl(ret, t0);
1323
tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO));
1327
if (unlikely(Rc(ctx->opcode) != 0))
1328
gen_set_Rc0(ctx, ret);
1330
GEN_HANDLER(neg, 0x1F, 0x08, 0x03, 0x0000F800, PPC_INTEGER)
1332
gen_op_arith_neg(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0);
1334
GEN_HANDLER(nego, 0x1F, 0x08, 0x13, 0x0000F800, PPC_INTEGER)
1336
gen_op_arith_neg(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 1);
1339
/* Common subf function */
1340
static always_inline void gen_op_arith_subf(DisasContext *ctx, TCGv ret, TCGv arg1, TCGv arg2,
1341
int add_ca, int compute_ca, int compute_ov)
1345
if ((!compute_ca && !compute_ov) ||
1346
(GET_TCGV(ret) != GET_TCGV(arg1) && GET_TCGV(ret) != GET_TCGV(arg2))) {
1349
t0 = tcg_temp_local_new(TCG_TYPE_TL);
1353
t1 = tcg_temp_local_new(TCG_TYPE_TL);
1354
tcg_gen_andi_tl(t1, cpu_xer, (1 << XER_CA));
1355
tcg_gen_shri_tl(t1, t1, XER_CA);
1358
if (compute_ca && compute_ov) {
1359
/* Start with XER CA and OV disabled, the most likely case */
1360
tcg_gen_andi_tl(cpu_xer, cpu_xer, ~((1 << XER_CA) | (1 << XER_OV)));
1361
} else if (compute_ca) {
1362
/* Start with XER CA disabled, the most likely case */
1363
tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA));
1364
} else if (compute_ov) {
1365
/* Start with XER OV disabled, the most likely case */
1366
tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV));
1370
tcg_gen_not_tl(t0, arg1);
1371
tcg_gen_add_tl(t0, t0, arg2);
1372
gen_op_arith_compute_ca(ctx, t0, arg2, 0);
1373
tcg_gen_add_tl(t0, t0, t1);
1374
gen_op_arith_compute_ca(ctx, t0, t1, 0);
1377
tcg_gen_sub_tl(t0, arg2, arg1);
1379
gen_op_arith_compute_ca(ctx, t0, arg2, 1);
1383
gen_op_arith_compute_ov(ctx, t0, arg1, arg2, 1);
1386
if (unlikely(Rc(ctx->opcode) != 0))
1387
gen_set_Rc0(ctx, t0);
1389
if (GET_TCGV(t0) != GET_TCGV(ret)) {
1390
tcg_gen_mov_tl(ret, t0);
1394
/* Sub functions with Two operands functions */
1395
#define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
1396
GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x00000000, PPC_INTEGER) \
1398
gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1399
cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1400
add_ca, compute_ca, compute_ov); \
1402
/* Sub functions with one operand and one immediate */
1403
#define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
1404
add_ca, compute_ca, compute_ov) \
1405
GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x0000F800, PPC_INTEGER) \
1407
TCGv t0 = tcg_const_local_tl(const_val); \
1408
gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1409
cpu_gpr[rA(ctx->opcode)], t0, \
1410
add_ca, compute_ca, compute_ov); \
1411
tcg_temp_free(t0); \
1413
/* subf subf. subfo subfo. */
1414
GEN_INT_ARITH_SUBF(subf, 0x01, 0, 0, 0)
1415
GEN_INT_ARITH_SUBF(subfo, 0x11, 0, 0, 1)
1416
/* subfc subfc. subfco subfco. */
1417
GEN_INT_ARITH_SUBF(subfc, 0x00, 0, 1, 0)
1418
GEN_INT_ARITH_SUBF(subfco, 0x10, 0, 1, 1)
1419
/* subfe subfe. subfeo subfo. */
1420
GEN_INT_ARITH_SUBF(subfe, 0x04, 1, 1, 0)
1421
GEN_INT_ARITH_SUBF(subfeo, 0x14, 1, 1, 1)
1422
/* subfme subfme. subfmeo subfmeo. */
1423
GEN_INT_ARITH_SUBF_CONST(subfme, 0x07, -1LL, 1, 1, 0)
1424
GEN_INT_ARITH_SUBF_CONST(subfmeo, 0x17, -1LL, 1, 1, 1)
1425
/* subfze subfze. subfzeo subfzeo.*/
1426
GEN_INT_ARITH_SUBF_CONST(subfze, 0x06, 0, 1, 1, 0)
1427
GEN_INT_ARITH_SUBF_CONST(subfzeo, 0x16, 0, 1, 1, 1)
959
gen_op_load_gpr_T0(rA(ctx->opcode));
960
gen_op_mulli(SIMM(ctx->opcode));
961
gen_op_store_T0_gpr(rD(ctx->opcode));
1429
964
GEN_HANDLER(subfic, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1431
/* Start with XER CA and OV disabled, the most likely case */
1432
tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA));
1433
TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
1434
TCGv t1 = tcg_const_local_tl(SIMM(ctx->opcode));
1435
tcg_gen_sub_tl(t0, t1, cpu_gpr[rA(ctx->opcode)]);
1436
gen_op_arith_compute_ca(ctx, t0, t1, 1);
1438
tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
966
gen_op_load_gpr_T0(rA(ctx->opcode));
967
#if defined(TARGET_PPC64)
969
gen_op_subfic_64(SIMM(ctx->opcode));
972
gen_op_subfic(SIMM(ctx->opcode));
973
gen_op_store_T0_gpr(rD(ctx->opcode));
976
#if defined(TARGET_PPC64)
978
GEN_INT_ARITHN (mulhd, 0x1F, 0x09, 0x02, PPC_64B);
980
GEN_INT_ARITHN (mulhdu, 0x1F, 0x09, 0x00, PPC_64B);
981
/* mulld mulld. mulldo mulldo. */
982
GEN_INT_ARITH2 (mulld, 0x1F, 0x09, 0x07, PPC_64B);
983
/* divd divd. divdo divdo. */
984
GEN_INT_ARITH2 (divd, 0x1F, 0x09, 0x0F, PPC_64B);
985
/* divdu divdu. divduo divduo. */
986
GEN_INT_ARITH2 (divdu, 0x1F, 0x09, 0x0E, PPC_64B);
989
/*** Integer comparison ***/
990
#if defined(TARGET_PPC64)
991
#define GEN_CMP(name, opc, type) \
992
GEN_HANDLER(name, 0x1F, 0x00, opc, 0x00400000, type) \
994
gen_op_load_gpr_T0(rA(ctx->opcode)); \
995
gen_op_load_gpr_T1(rB(ctx->opcode)); \
996
if (ctx->sf_mode && (ctx->opcode & 0x00200000)) \
997
gen_op_##name##_64(); \
1000
gen_op_store_T0_crf(crfD(ctx->opcode)); \
1003
#define GEN_CMP(name, opc, type) \
1004
GEN_HANDLER(name, 0x1F, 0x00, opc, 0x00400000, type) \
1006
gen_op_load_gpr_T0(rA(ctx->opcode)); \
1007
gen_op_load_gpr_T1(rB(ctx->opcode)); \
1009
gen_op_store_T0_crf(crfD(ctx->opcode)); \
1014
GEN_CMP(cmp, 0x00, PPC_INTEGER);
1016
GEN_HANDLER(cmpi, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER)
1018
gen_op_load_gpr_T0(rA(ctx->opcode));
1019
#if defined(TARGET_PPC64)
1020
if (ctx->sf_mode && (ctx->opcode & 0x00200000))
1021
gen_op_cmpi_64(SIMM(ctx->opcode));
1024
gen_op_cmpi(SIMM(ctx->opcode));
1025
gen_op_store_T0_crf(crfD(ctx->opcode));
1028
GEN_CMP(cmpl, 0x01, PPC_INTEGER);
1030
GEN_HANDLER(cmpli, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER)
1032
gen_op_load_gpr_T0(rA(ctx->opcode));
1033
#if defined(TARGET_PPC64)
1034
if (ctx->sf_mode && (ctx->opcode & 0x00200000))
1035
gen_op_cmpli_64(UIMM(ctx->opcode));
1038
gen_op_cmpli(UIMM(ctx->opcode));
1039
gen_op_store_T0_crf(crfD(ctx->opcode));
1042
/* isel (PowerPC 2.03 specification) */
1043
GEN_HANDLER(isel, 0x1F, 0x0F, 0x00, 0x00000001, PPC_203)
1045
uint32_t bi = rC(ctx->opcode);
1048
if (rA(ctx->opcode) == 0) {
1051
gen_op_load_gpr_T1(rA(ctx->opcode));
1053
gen_op_load_gpr_T2(rB(ctx->opcode));
1054
mask = 1 << (3 - (bi & 0x03));
1055
gen_op_load_crf_T0(bi >> 2);
1056
gen_op_test_true(mask);
1058
gen_op_store_T0_gpr(rD(ctx->opcode));
1442
1061
/*** Integer logical ***/
1443
#define GEN_LOGICAL2(name, tcg_op, opc, type) \
1444
GEN_HANDLER(name, 0x1F, 0x1C, opc, 0x00000000, type) \
1062
#define __GEN_LOGICAL2(name, opc2, opc3, type) \
1063
GEN_HANDLER(name, 0x1F, opc2, opc3, 0x00000000, type) \
1446
tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], \
1447
cpu_gpr[rB(ctx->opcode)]); \
1065
gen_op_load_gpr_T0(rS(ctx->opcode)); \
1066
gen_op_load_gpr_T1(rB(ctx->opcode)); \
1068
gen_op_store_T0_gpr(rA(ctx->opcode)); \
1448
1069
if (unlikely(Rc(ctx->opcode) != 0)) \
1449
gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
1072
#define GEN_LOGICAL2(name, opc, type) \
1073
__GEN_LOGICAL2(name, 0x1C, opc, type)
1452
#define GEN_LOGICAL1(name, tcg_op, opc, type) \
1075
#define GEN_LOGICAL1(name, opc, type) \
1453
1076
GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, type) \
1455
tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); \
1078
gen_op_load_gpr_T0(rS(ctx->opcode)); \
1080
gen_op_store_T0_gpr(rA(ctx->opcode)); \
1456
1081
if (unlikely(Rc(ctx->opcode) != 0)) \
1457
gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
1460
1085
/* and & and. */
1461
GEN_LOGICAL2(and, tcg_gen_and_tl, 0x00, PPC_INTEGER);
1086
GEN_LOGICAL2(and, 0x00, PPC_INTEGER);
1462
1087
/* andc & andc. */
1463
GEN_LOGICAL2(andc, tcg_gen_andc_tl, 0x01, PPC_INTEGER);
1088
GEN_LOGICAL2(andc, 0x01, PPC_INTEGER);
1465
GEN_HANDLER2(andi_, "andi.", 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1090
GEN_HANDLER(andi_, 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1467
tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], UIMM(ctx->opcode));
1468
gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1092
gen_op_load_gpr_T0(rS(ctx->opcode));
1093
gen_op_andi_T0(UIMM(ctx->opcode));
1094
gen_op_store_T0_gpr(rA(ctx->opcode));
1471
GEN_HANDLER2(andis_, "andis.", 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1098
GEN_HANDLER(andis_, 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1473
tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], UIMM(ctx->opcode) << 16);
1474
gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1100
gen_op_load_gpr_T0(rS(ctx->opcode));
1101
gen_op_andi_T0(UIMM(ctx->opcode) << 16);
1102
gen_op_store_T0_gpr(rA(ctx->opcode));
1477
GEN_HANDLER(cntlzw, 0x1F, 0x1A, 0x00, 0x00000000, PPC_INTEGER)
1479
tcg_gen_helper_1_1(helper_cntlzw, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1480
if (unlikely(Rc(ctx->opcode) != 0))
1481
gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1107
GEN_LOGICAL1(cntlzw, 0x00, PPC_INTEGER);
1483
1108
/* eqv & eqv. */
1484
GEN_LOGICAL2(eqv, tcg_gen_eqv_tl, 0x08, PPC_INTEGER);
1109
GEN_LOGICAL2(eqv, 0x08, PPC_INTEGER);
1485
1110
/* extsb & extsb. */
1486
GEN_LOGICAL1(extsb, tcg_gen_ext8s_tl, 0x1D, PPC_INTEGER);
1111
GEN_LOGICAL1(extsb, 0x1D, PPC_INTEGER);
1487
1112
/* extsh & extsh. */
1488
GEN_LOGICAL1(extsh, tcg_gen_ext16s_tl, 0x1C, PPC_INTEGER);
1113
GEN_LOGICAL1(extsh, 0x1C, PPC_INTEGER);
1489
1114
/* nand & nand. */
1490
GEN_LOGICAL2(nand, tcg_gen_nand_tl, 0x0E, PPC_INTEGER);
1115
GEN_LOGICAL2(nand, 0x0E, PPC_INTEGER);
1491
1116
/* nor & nor. */
1492
GEN_LOGICAL2(nor, tcg_gen_nor_tl, 0x03, PPC_INTEGER);
1117
GEN_LOGICAL2(nor, 0x03, PPC_INTEGER);
1494
1120
GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER)
1695
1331
sh = SH(ctx->opcode);
1696
1332
mb = MB(ctx->opcode);
1697
1333
me = ME(ctx->opcode);
1699
if (likely(mb == 0 && me == (31 - sh))) {
1700
if (likely(sh == 0)) {
1701
tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1703
TCGv t0 = tcg_temp_new(TCG_TYPE_TL);
1704
tcg_gen_ext32u_tl(t0, cpu_gpr[rS(ctx->opcode)]);
1705
tcg_gen_shli_tl(t0, t0, sh);
1706
tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], t0);
1709
} else if (likely(sh != 0 && me == 31 && sh == (32 - mb))) {
1710
TCGv t0 = tcg_temp_new(TCG_TYPE_TL);
1711
tcg_gen_ext32u_tl(t0, cpu_gpr[rS(ctx->opcode)]);
1712
tcg_gen_shri_tl(t0, t0, mb);
1713
tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], t0);
1716
TCGv t0 = tcg_temp_new(TCG_TYPE_TL);
1717
#if defined(TARGET_PPC64)
1718
TCGv t1 = tcg_temp_new(TCG_TYPE_I32);
1719
tcg_gen_trunc_i64_i32(t1, cpu_gpr[rS(ctx->opcode)]);
1720
tcg_gen_rotli_i32(t1, t1, sh);
1721
tcg_gen_extu_i32_i64(t0, t1);
1724
tcg_gen_rotli_i32(t0, cpu_gpr[rS(ctx->opcode)], sh);
1726
#if defined(TARGET_PPC64)
1730
tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me));
1334
gen_op_load_gpr_T0(rS(ctx->opcode));
1335
if (likely(sh == 0)) {
1338
if (likely(mb == 0)) {
1339
if (likely(me == 31)) {
1340
gen_op_rotli32_T0(sh);
1342
} else if (likely(me == (31 - sh))) {
1346
} else if (likely(me == 31)) {
1347
if (likely(sh == (32 - mb))) {
1352
gen_op_rotli32_T0(sh);
1354
#if defined(TARGET_PPC64)
1358
gen_op_andi_T0(MASK(mb, me));
1360
gen_op_store_T0_gpr(rA(ctx->opcode));
1733
1361
if (unlikely(Rc(ctx->opcode) != 0))
1734
gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1736
1364
/* rlwnm & rlwnm. */
1737
1365
GEN_HANDLER(rlwnm, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1739
1367
uint32_t mb, me;
1741
#if defined(TARGET_PPC64)
1745
1369
mb = MB(ctx->opcode);
1746
1370
me = ME(ctx->opcode);
1747
t0 = tcg_temp_new(TCG_TYPE_TL);
1748
tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1f);
1749
#if defined(TARGET_PPC64)
1750
t1 = tcg_temp_new(TCG_TYPE_I32);
1751
t2 = tcg_temp_new(TCG_TYPE_I32);
1752
tcg_gen_trunc_i64_i32(t1, cpu_gpr[rS(ctx->opcode)]);
1753
tcg_gen_trunc_i64_i32(t2, t0);
1754
tcg_gen_rotl_i32(t1, t1, t2);
1755
tcg_gen_extu_i32_i64(t0, t1);
1759
tcg_gen_rotl_i32(t0, cpu_gpr[rS(ctx->opcode)], t0);
1371
gen_op_load_gpr_T0(rS(ctx->opcode));
1372
gen_op_load_gpr_T1(rB(ctx->opcode));
1373
gen_op_rotl32_T0_T1();
1761
1374
if (unlikely(mb != 0 || me != 31)) {
1762
1375
#if defined(TARGET_PPC64)
1766
tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me));
1768
tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
1379
gen_op_andi_T0(MASK(mb, me));
1381
gen_op_store_T0_gpr(rA(ctx->opcode));
1771
1382
if (unlikely(Rc(ctx->opcode) != 0))
1772
gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1775
1386
#if defined(TARGET_PPC64)
1776
1387
#define GEN_PPC64_R2(name, opc1, opc2) \
1777
GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B) \
1388
GEN_HANDLER(name##0, opc1, opc2, 0xFF, 0x00000000, PPC_64B) \
1779
1390
gen_##name(ctx, 0); \
1781
GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
1392
GEN_HANDLER(name##1, opc1, opc2 | 0x10, 0xFF, 0x00000000, PPC_64B) \
1784
1394
gen_##name(ctx, 1); \
1786
1396
#define GEN_PPC64_R4(name, opc1, opc2) \
1787
GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B) \
1397
GEN_HANDLER(name##0, opc1, opc2, 0xFF, 0x00000000, PPC_64B) \
1789
1399
gen_##name(ctx, 0, 0); \
1791
GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x01, 0xFF, 0x00000000, \
1401
GEN_HANDLER(name##1, opc1, opc2 | 0x01, 0xFF, 0x00000000, PPC_64B) \
1794
1403
gen_##name(ctx, 0, 1); \
1796
GEN_HANDLER2(name##2, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
1405
GEN_HANDLER(name##2, opc1, opc2 | 0x10, 0xFF, 0x00000000, PPC_64B) \
1799
1407
gen_##name(ctx, 1, 0); \
1801
GEN_HANDLER2(name##3, stringify(name), opc1, opc2 | 0x11, 0xFF, 0x00000000, \
1409
GEN_HANDLER(name##3, opc1, opc2 | 0x11, 0xFF, 0x00000000, PPC_64B) \
1804
1411
gen_##name(ctx, 1, 1); \
1414
static always_inline void gen_andi_T0_64 (DisasContext *ctx, uint64_t mask)
1417
gen_op_andi_T0_64(mask >> 32, mask & 0xFFFFFFFF);
1419
gen_op_andi_T0(mask);
1422
static always_inline void gen_andi_T1_64 (DisasContext *ctx, uint64_t mask)
1425
gen_op_andi_T1_64(mask >> 32, mask & 0xFFFFFFFF);
1427
gen_op_andi_T1(mask);
1807
1430
static always_inline void gen_rldinm (DisasContext *ctx, uint32_t mb,
1808
1431
uint32_t me, uint32_t sh)
1810
if (likely(sh != 0 && mb == 0 && me == (63 - sh))) {
1811
tcg_gen_shli_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], sh);
1812
} else if (likely(sh != 0 && me == 63 && sh == (64 - mb))) {
1813
tcg_gen_shri_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], mb);
1815
TCGv t0 = tcg_temp_new(TCG_TYPE_TL);
1816
tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
1817
if (likely(mb == 0 && me == 63)) {
1818
tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
1820
tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me));
1433
gen_op_load_gpr_T0(rS(ctx->opcode));
1434
if (likely(sh == 0)) {
1437
if (likely(mb == 0)) {
1438
if (likely(me == 63)) {
1439
gen_op_rotli64_T0(sh);
1441
} else if (likely(me == (63 - sh))) {
1445
} else if (likely(me == 63)) {
1446
if (likely(sh == (64 - mb))) {
1447
gen_op_srli_T0_64(mb);
1451
gen_op_rotli64_T0(sh);
1453
gen_andi_T0_64(ctx, MASK(mb, me));
1455
gen_op_store_T0_gpr(rA(ctx->opcode));
1824
1456
if (unlikely(Rc(ctx->opcode) != 0))
1825
gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1827
1459
/* rldicl - rldicl. */
1828
1460
static always_inline void gen_rldicl (DisasContext *ctx, int mbn, int shn)
1896
1522
/* rldimi - rldimi. */
1897
1523
static always_inline void gen_rldimi (DisasContext *ctx, int mbn, int shn)
1899
uint32_t sh, mb, me;
1901
1528
sh = SH(ctx->opcode) | (shn << 5);
1902
1529
mb = MB(ctx->opcode) | (mbn << 5);
1904
if (unlikely(sh == 0 && mb == 0)) {
1905
tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1910
t0 = tcg_temp_new(TCG_TYPE_TL);
1911
tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
1912
t1 = tcg_temp_new(TCG_TYPE_TL);
1913
mask = MASK(mb, me);
1914
tcg_gen_andi_tl(t0, t0, mask);
1915
tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], ~mask);
1916
tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1530
if (likely(sh == 0)) {
1531
if (likely(mb == 0)) {
1532
gen_op_load_gpr_T0(rS(ctx->opcode));
1534
} else if (likely(mb == 63)) {
1535
gen_op_load_gpr_T0(rA(ctx->opcode));
1538
gen_op_load_gpr_T0(rS(ctx->opcode));
1539
gen_op_load_gpr_T1(rA(ctx->opcode));
1542
gen_op_load_gpr_T0(rS(ctx->opcode));
1543
gen_op_load_gpr_T1(rA(ctx->opcode));
1544
gen_op_rotli64_T0(sh);
1546
mask = MASK(mb, 63 - sh);
1547
gen_andi_T0_64(ctx, mask);
1548
gen_andi_T1_64(ctx, ~mask);
1551
gen_op_store_T0_gpr(rA(ctx->opcode));
1920
1552
if (unlikely(Rc(ctx->opcode) != 0))
1921
gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1923
1555
GEN_PPC64_R4(rldimi, 0x1E, 0x06);
1926
1558
/*** Integer shift ***/
1927
1559
/* slw & slw. */
1928
GEN_HANDLER(slw, 0x1F, 0x18, 0x00, 0x00000000, PPC_INTEGER)
1932
l1 = gen_new_label();
1933
l2 = gen_new_label();
1935
t0 = tcg_temp_local_new(TCG_TYPE_TL);
1936
tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3f);
1937
tcg_gen_brcondi_tl(TCG_COND_LT, t0, 0x20, l1);
1938
tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
1941
tcg_gen_shl_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], t0);
1942
tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
1945
if (unlikely(Rc(ctx->opcode) != 0))
1946
gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1560
__GEN_LOGICAL2(slw, 0x18, 0x00, PPC_INTEGER);
1948
1561
/* sraw & sraw. */
1949
GEN_HANDLER(sraw, 0x1F, 0x18, 0x18, 0x00000000, PPC_INTEGER)
1951
tcg_gen_helper_1_2(helper_sraw, cpu_gpr[rA(ctx->opcode)],
1952
cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1953
if (unlikely(Rc(ctx->opcode) != 0))
1954
gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1562
__GEN_LOGICAL2(sraw, 0x18, 0x18, PPC_INTEGER);
1956
1563
/* srawi & srawi. */
1957
1564
GEN_HANDLER(srawi, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER)
1959
int sh = SH(ctx->opcode);
1963
l1 = gen_new_label();
1964
l2 = gen_new_label();
1965
t0 = tcg_temp_local_new(TCG_TYPE_TL);
1966
tcg_gen_ext32s_tl(t0, cpu_gpr[rS(ctx->opcode)]);
1967
tcg_gen_brcondi_tl(TCG_COND_GE, t0, 0, l1);
1968
tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1ULL << sh) - 1);
1969
tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
1970
tcg_gen_ori_tl(cpu_xer, cpu_xer, 1 << XER_CA);
1973
tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA));
1975
tcg_gen_ext32s_tl(t0, cpu_gpr[rS(ctx->opcode)]);
1976
tcg_gen_sari_tl(cpu_gpr[rA(ctx->opcode)], t0, sh);
1979
tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1980
tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA));
1567
gen_op_load_gpr_T0(rS(ctx->opcode));
1568
if (SH(ctx->opcode) != 0) {
1569
gen_op_move_T1_T0();
1570
mb = 32 - SH(ctx->opcode);
1572
#if defined(TARGET_PPC64)
1576
gen_op_srawi(SH(ctx->opcode), MASK(mb, me));
1578
gen_op_store_T0_gpr(rA(ctx->opcode));
1982
1579
if (unlikely(Rc(ctx->opcode) != 0))
1983
gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1985
1582
/* srw & srw. */
1986
GEN_HANDLER(srw, 0x1F, 0x18, 0x10, 0x00000000, PPC_INTEGER)
1990
l1 = gen_new_label();
1991
l2 = gen_new_label();
1583
__GEN_LOGICAL2(srw, 0x18, 0x10, PPC_INTEGER);
1993
t0 = tcg_temp_local_new(TCG_TYPE_TL);
1994
tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3f);
1995
tcg_gen_brcondi_tl(TCG_COND_LT, t0, 0x20, l1);
1996
tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
1999
t1 = tcg_temp_new(TCG_TYPE_TL);
2000
tcg_gen_ext32u_tl(t1, cpu_gpr[rS(ctx->opcode)]);
2001
tcg_gen_shr_tl(cpu_gpr[rA(ctx->opcode)], t1, t0);
2005
if (unlikely(Rc(ctx->opcode) != 0))
2006
gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
2008
1585
#if defined(TARGET_PPC64)
2009
1586
/* sld & sld. */
2010
GEN_HANDLER(sld, 0x1F, 0x1B, 0x00, 0x00000000, PPC_64B)
2014
l1 = gen_new_label();
2015
l2 = gen_new_label();
2017
t0 = tcg_temp_local_new(TCG_TYPE_TL);
2018
tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x7f);
2019
tcg_gen_brcondi_tl(TCG_COND_LT, t0, 0x40, l1);
2020
tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
2023
tcg_gen_shl_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], t0);
2026
if (unlikely(Rc(ctx->opcode) != 0))
2027
gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1587
__GEN_LOGICAL2(sld, 0x1B, 0x00, PPC_64B);
2029
1588
/* srad & srad. */
2030
GEN_HANDLER(srad, 0x1F, 0x1A, 0x18, 0x00000000, PPC_64B)
2032
tcg_gen_helper_1_2(helper_srad, cpu_gpr[rA(ctx->opcode)],
2033
cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
2034
if (unlikely(Rc(ctx->opcode) != 0))
2035
gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1589
__GEN_LOGICAL2(srad, 0x1A, 0x18, PPC_64B);
2037
1590
/* sradi & sradi. */
2038
1591
static always_inline void gen_sradi (DisasContext *ctx, int n)
2040
int sh = SH(ctx->opcode) + (n << 5);
1596
gen_op_load_gpr_T0(rS(ctx->opcode));
1597
sh = SH(ctx->opcode) + (n << 5);
2044
l1 = gen_new_label();
2045
l2 = gen_new_label();
2046
t0 = tcg_temp_local_new(TCG_TYPE_TL);
2047
tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rS(ctx->opcode)], 0, l1);
2048
tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1ULL << sh) - 1);
2049
tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
2050
tcg_gen_ori_tl(cpu_xer, cpu_xer, 1 << XER_CA);
2053
tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA));
2056
tcg_gen_sari_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], sh);
2058
tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
2059
tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA));
1599
gen_op_move_T1_T0();
1600
mb = 64 - SH(ctx->opcode);
1602
mask = MASK(mb, me);
1603
gen_op_sradi(sh, mask >> 32, mask);
1605
gen_op_store_T0_gpr(rA(ctx->opcode));
2061
1606
if (unlikely(Rc(ctx->opcode) != 0))
2062
gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
2064
GEN_HANDLER2(sradi0, "sradi", 0x1F, 0x1A, 0x19, 0x00000000, PPC_64B)
1609
GEN_HANDLER(sradi0, 0x1F, 0x1A, 0x19, 0x00000000, PPC_64B)
2066
1611
gen_sradi(ctx, 0);
2068
GEN_HANDLER2(sradi1, "sradi", 0x1F, 0x1B, 0x19, 0x00000000, PPC_64B)
1613
GEN_HANDLER(sradi1, 0x1F, 0x1B, 0x19, 0x00000000, PPC_64B)
2070
1615
gen_sradi(ctx, 1);
2072
1617
/* srd & srd. */
2073
GEN_HANDLER(srd, 0x1F, 0x1B, 0x10, 0x00000000, PPC_64B)
2077
l1 = gen_new_label();
2078
l2 = gen_new_label();
2080
t0 = tcg_temp_local_new(TCG_TYPE_TL);
2081
tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x7f);
2082
tcg_gen_brcondi_tl(TCG_COND_LT, t0, 0x40, l1);
2083
tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
2086
tcg_gen_shr_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], t0);
2089
if (unlikely(Rc(ctx->opcode) != 0))
2090
gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1618
__GEN_LOGICAL2(srd, 0x1B, 0x10, PPC_64B);
2094
1621
/*** Floating-Point arithmetic ***/
2095
#define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
1622
#define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, type) \
2096
1623
GEN_HANDLER(f##name, op1, op2, 0xFF, 0x00000000, type) \
2098
1625
if (unlikely(!ctx->fpu_enabled)) { \
2099
1626
GEN_EXCP_NO_FP(ctx); \
2102
tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rA(ctx->opcode)]); \
2103
tcg_gen_mov_i64(cpu_FT[1], cpu_fpr[rC(ctx->opcode)]); \
2104
tcg_gen_mov_i64(cpu_FT[2], cpu_fpr[rB(ctx->opcode)]); \
2105
gen_reset_fpstatus(); \
2110
tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]); \
2111
gen_compute_fprf(set_fprf, Rc(ctx->opcode) != 0); \
2114
#define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
2115
_GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type); \
2116
_GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type);
2118
#define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
2119
GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type) \
2121
if (unlikely(!ctx->fpu_enabled)) { \
2122
GEN_EXCP_NO_FP(ctx); \
2125
tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rA(ctx->opcode)]); \
2126
tcg_gen_mov_i64(cpu_FT[1], cpu_fpr[rB(ctx->opcode)]); \
2127
gen_reset_fpstatus(); \
2132
tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]); \
2133
gen_compute_fprf(set_fprf, Rc(ctx->opcode) != 0); \
2135
#define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
2136
_GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2137
_GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
2139
#define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
2140
GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type) \
2142
if (unlikely(!ctx->fpu_enabled)) { \
2143
GEN_EXCP_NO_FP(ctx); \
2146
tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rA(ctx->opcode)]); \
2147
tcg_gen_mov_i64(cpu_FT[1], cpu_fpr[rC(ctx->opcode)]); \
2148
gen_reset_fpstatus(); \
2153
tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]); \
2154
gen_compute_fprf(set_fprf, Rc(ctx->opcode) != 0); \
2156
#define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
2157
_GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2158
_GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
2160
#define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
1629
gen_op_reset_scrfx(); \
1630
gen_op_load_fpr_FT0(rA(ctx->opcode)); \
1631
gen_op_load_fpr_FT1(rC(ctx->opcode)); \
1632
gen_op_load_fpr_FT2(rB(ctx->opcode)); \
1637
gen_op_store_FT0_fpr(rD(ctx->opcode)); \
1638
if (unlikely(Rc(ctx->opcode) != 0)) \
1642
#define GEN_FLOAT_ACB(name, op2, type) \
1643
_GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, type); \
1644
_GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, type);
1646
#define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat) \
1647
GEN_HANDLER(f##name, op1, op2, 0xFF, inval, PPC_FLOAT) \
1649
if (unlikely(!ctx->fpu_enabled)) { \
1650
GEN_EXCP_NO_FP(ctx); \
1653
gen_op_reset_scrfx(); \
1654
gen_op_load_fpr_FT0(rA(ctx->opcode)); \
1655
gen_op_load_fpr_FT1(rB(ctx->opcode)); \
1660
gen_op_store_FT0_fpr(rD(ctx->opcode)); \
1661
if (unlikely(Rc(ctx->opcode) != 0)) \
1664
#define GEN_FLOAT_AB(name, op2, inval) \
1665
_GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0); \
1666
_GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1);
1668
#define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat) \
1669
GEN_HANDLER(f##name, op1, op2, 0xFF, inval, PPC_FLOAT) \
1671
if (unlikely(!ctx->fpu_enabled)) { \
1672
GEN_EXCP_NO_FP(ctx); \
1675
gen_op_reset_scrfx(); \
1676
gen_op_load_fpr_FT0(rA(ctx->opcode)); \
1677
gen_op_load_fpr_FT1(rC(ctx->opcode)); \
1682
gen_op_store_FT0_fpr(rD(ctx->opcode)); \
1683
if (unlikely(Rc(ctx->opcode) != 0)) \
1686
#define GEN_FLOAT_AC(name, op2, inval) \
1687
_GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0); \
1688
_GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1);
1690
#define GEN_FLOAT_B(name, op2, op3, type) \
2161
1691
GEN_HANDLER(f##name, 0x3F, op2, op3, 0x001F0000, type) \
2163
1693
if (unlikely(!ctx->fpu_enabled)) { \
2164
1694
GEN_EXCP_NO_FP(ctx); \
2167
tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rB(ctx->opcode)]); \
2168
gen_reset_fpstatus(); \
1697
gen_op_reset_scrfx(); \
1698
gen_op_load_fpr_FT0(rB(ctx->opcode)); \
2169
1699
gen_op_f##name(); \
2170
tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]); \
2171
gen_compute_fprf(set_fprf, Rc(ctx->opcode) != 0); \
1700
gen_op_store_FT0_fpr(rD(ctx->opcode)); \
1701
if (unlikely(Rc(ctx->opcode) != 0)) \
2174
#define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
1705
#define GEN_FLOAT_BS(name, op1, op2, type) \
2175
1706
GEN_HANDLER(f##name, op1, op2, 0xFF, 0x001F07C0, type) \
2177
1708
if (unlikely(!ctx->fpu_enabled)) { \
2178
1709
GEN_EXCP_NO_FP(ctx); \
2181
tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rB(ctx->opcode)]); \
2182
gen_reset_fpstatus(); \
1712
gen_op_reset_scrfx(); \
1713
gen_op_load_fpr_FT0(rB(ctx->opcode)); \
2183
1714
gen_op_f##name(); \
2184
tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]); \
2185
gen_compute_fprf(set_fprf, Rc(ctx->opcode) != 0); \
1715
gen_op_store_FT0_fpr(rD(ctx->opcode)); \
1716
if (unlikely(Rc(ctx->opcode) != 0)) \
2188
1720
/* fadd - fadds */
2189
GEN_FLOAT_AB(add, 0x15, 0x000007C0, 1, PPC_FLOAT);
1721
GEN_FLOAT_AB(add, 0x15, 0x000007C0);
2190
1722
/* fdiv - fdivs */
2191
GEN_FLOAT_AB(div, 0x12, 0x000007C0, 1, PPC_FLOAT);
1723
GEN_FLOAT_AB(div, 0x12, 0x000007C0);
2192
1724
/* fmul - fmuls */
2193
GEN_FLOAT_AC(mul, 0x19, 0x0000F800, 1, PPC_FLOAT);
1725
GEN_FLOAT_AC(mul, 0x19, 0x0000F800);
2196
GEN_FLOAT_BS(re, 0x3F, 0x18, 1, PPC_FLOAT_EXT);
1728
GEN_FLOAT_BS(re, 0x3F, 0x18, PPC_FLOAT_EXT);
2199
GEN_FLOAT_BS(res, 0x3B, 0x18, 1, PPC_FLOAT_FRES);
1731
GEN_FLOAT_BS(res, 0x3B, 0x18, PPC_FLOAT_FRES);
2202
GEN_FLOAT_BS(rsqrte, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE);
2205
static always_inline void gen_op_frsqrtes (void)
2210
GEN_FLOAT_BS(rsqrtes, 0x3B, 0x1A, 1, PPC_FLOAT_FRSQRTES);
1734
GEN_FLOAT_BS(rsqrte, 0x3F, 0x1A, PPC_FLOAT_FRSQRTE);
2213
_GEN_FLOAT_ACB(sel, sel, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL);
1737
_GEN_FLOAT_ACB(sel, sel, 0x3F, 0x17, 0, PPC_FLOAT_FSEL);
2214
1738
/* fsub - fsubs */
2215
GEN_FLOAT_AB(sub, 0x14, 0x000007C0, 1, PPC_FLOAT);
1739
GEN_FLOAT_AB(sub, 0x14, 0x000007C0);
2216
1740
/* Optional: */
2218
1742
GEN_HANDLER(fsqrt, 0x3F, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT)
2410
1922
GEN_EXCP_NO_FP(ctx);
2413
gen_optimize_fprf();
2414
tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rB(ctx->opcode)]);
2415
gen_reset_fpstatus();
1925
gen_op_load_fpr_FT0(rB(ctx->opcode));
2416
1926
gen_op_store_fpscr(FM(ctx->opcode));
2417
if (unlikely(Rc(ctx->opcode) != 0)) {
2418
tcg_gen_shri_i32(cpu_crf[1], cpu_fpscr, FPSCR_OX);
2420
/* We can raise a differed exception */
2421
gen_op_float_check_status();
1927
if (unlikely(Rc(ctx->opcode) != 0))
2425
1932
GEN_HANDLER(mtfsfi, 0x3F, 0x06, 0x04, 0x006f0800, PPC_FLOAT)
2429
1934
if (unlikely(!ctx->fpu_enabled)) {
2430
1935
GEN_EXCP_NO_FP(ctx);
2433
bf = crbD(ctx->opcode) >> 2;
2435
gen_optimize_fprf();
2436
tcg_gen_movi_i64(cpu_FT[0], FPIMM(ctx->opcode) << (4 * sh));
2437
gen_reset_fpstatus();
2438
gen_op_store_fpscr(1 << sh);
2439
if (unlikely(Rc(ctx->opcode) != 0)) {
2440
tcg_gen_shri_i32(cpu_crf[1], cpu_fpscr, FPSCR_OX);
2442
/* We can raise a differed exception */
2443
gen_op_float_check_status();
1938
gen_op_store_T0_fpscri(crbD(ctx->opcode) >> 2, FPIMM(ctx->opcode));
1939
if (unlikely(Rc(ctx->opcode) != 0))
2446
1943
/*** Addressing modes ***/
2447
1944
/* Register indirect with immediate index : EA = (rA|0) + SIMM */
2448
static always_inline void gen_addr_imm_index (TCGv EA,
1945
static always_inline void gen_addr_imm_index (DisasContext *ctx,
2450
1946
target_long maskl)
2452
1948
target_long simm = SIMM(ctx->opcode);
2454
1950
simm &= ~maskl;
2455
if (rA(ctx->opcode) == 0)
2456
tcg_gen_movi_tl(EA, simm);
2457
else if (likely(simm != 0))
2458
tcg_gen_addi_tl(EA, cpu_gpr[rA(ctx->opcode)], simm);
2460
tcg_gen_mov_tl(EA, cpu_gpr[rA(ctx->opcode)]);
2463
static always_inline void gen_addr_reg_index (TCGv EA,
2466
if (rA(ctx->opcode) == 0)
2467
tcg_gen_mov_tl(EA, cpu_gpr[rB(ctx->opcode)]);
2469
tcg_gen_add_tl(EA, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
2472
static always_inline void gen_addr_register (TCGv EA,
2475
if (rA(ctx->opcode) == 0)
2476
tcg_gen_movi_tl(EA, 0);
2478
tcg_gen_mov_tl(EA, cpu_gpr[rA(ctx->opcode)]);
2481
#if defined(TARGET_PPC64)
2482
#define _GEN_MEM_FUNCS(name, mode) \
2483
&gen_op_##name##_##mode, \
2484
&gen_op_##name##_le_##mode, \
2485
&gen_op_##name##_64_##mode, \
2486
&gen_op_##name##_le_64_##mode
2488
#define _GEN_MEM_FUNCS(name, mode) \
2489
&gen_op_##name##_##mode, \
2490
&gen_op_##name##_le_##mode
2492
#if defined(CONFIG_USER_ONLY)
2493
#if defined(TARGET_PPC64)
2494
#define NB_MEM_FUNCS 4
2496
#define NB_MEM_FUNCS 2
2498
#define GEN_MEM_FUNCS(name) \
2499
_GEN_MEM_FUNCS(name, raw)
2501
#if defined(TARGET_PPC64)
2502
#define NB_MEM_FUNCS 12
2504
#define NB_MEM_FUNCS 6
2506
#define GEN_MEM_FUNCS(name) \
2507
_GEN_MEM_FUNCS(name, user), \
2508
_GEN_MEM_FUNCS(name, kernel), \
2509
_GEN_MEM_FUNCS(name, hypv)
1951
if (rA(ctx->opcode) == 0) {
1954
gen_op_load_gpr_T0(rA(ctx->opcode));
1955
if (likely(simm != 0))
1958
#ifdef DEBUG_MEMORY_ACCESSES
1959
gen_op_print_mem_EA();
1963
static always_inline void gen_addr_reg_index (DisasContext *ctx)
1965
if (rA(ctx->opcode) == 0) {
1966
gen_op_load_gpr_T0(rB(ctx->opcode));
1968
gen_op_load_gpr_T0(rA(ctx->opcode));
1969
gen_op_load_gpr_T1(rB(ctx->opcode));
1972
#ifdef DEBUG_MEMORY_ACCESSES
1973
gen_op_print_mem_EA();
1977
static always_inline void gen_addr_register (DisasContext *ctx)
1979
if (rA(ctx->opcode) == 0) {
1982
gen_op_load_gpr_T0(rA(ctx->opcode));
1984
#ifdef DEBUG_MEMORY_ACCESSES
1985
gen_op_print_mem_EA();
2512
1989
/*** Integer load ***/
2513
1990
#define op_ldst(name) (*gen_op_##name[ctx->mem_idx])()
2514
#define OP_LD_TABLE(width) \
2515
static GenOpFunc *gen_op_l##width[NB_MEM_FUNCS] = { \
2516
GEN_MEM_FUNCS(l##width), \
2518
#define OP_ST_TABLE(width) \
2519
static GenOpFunc *gen_op_st##width[NB_MEM_FUNCS] = { \
2520
GEN_MEM_FUNCS(st##width), \
2524
#if defined(TARGET_PPC64)
2525
#define GEN_QEMU_LD_PPC64(width) \
2526
static always_inline void gen_qemu_ld##width##_ppc64(TCGv t0, TCGv t1, int flags)\
2528
if (likely(flags & 2)) \
2529
tcg_gen_qemu_ld##width(t0, t1, flags >> 2); \
2531
TCGv addr = tcg_temp_new(TCG_TYPE_TL); \
2532
tcg_gen_ext32u_tl(addr, t1); \
2533
tcg_gen_qemu_ld##width(t0, addr, flags >> 2); \
2534
tcg_temp_free(addr); \
2537
GEN_QEMU_LD_PPC64(8u)
2538
GEN_QEMU_LD_PPC64(8s)
2539
GEN_QEMU_LD_PPC64(16u)
2540
GEN_QEMU_LD_PPC64(16s)
2541
GEN_QEMU_LD_PPC64(32u)
2542
GEN_QEMU_LD_PPC64(32s)
2543
GEN_QEMU_LD_PPC64(64)
2545
#define GEN_QEMU_ST_PPC64(width) \
2546
static always_inline void gen_qemu_st##width##_ppc64(TCGv t0, TCGv t1, int flags)\
2548
if (likely(flags & 2)) \
2549
tcg_gen_qemu_st##width(t0, t1, flags >> 2); \
2551
TCGv addr = tcg_temp_new(TCG_TYPE_TL); \
2552
tcg_gen_ext32u_tl(addr, t1); \
2553
tcg_gen_qemu_st##width(t0, addr, flags >> 2); \
2554
tcg_temp_free(addr); \
2557
GEN_QEMU_ST_PPC64(8)
2558
GEN_QEMU_ST_PPC64(16)
2559
GEN_QEMU_ST_PPC64(32)
2560
GEN_QEMU_ST_PPC64(64)
2562
static always_inline void gen_qemu_ld8u(TCGv arg0, TCGv arg1, int flags)
2564
gen_qemu_ld8u_ppc64(arg0, arg1, flags);
2567
static always_inline void gen_qemu_ld8s(TCGv arg0, TCGv arg1, int flags)
2569
gen_qemu_ld8s_ppc64(arg0, arg1, flags);
2572
static always_inline void gen_qemu_ld16u(TCGv arg0, TCGv arg1, int flags)
2574
if (unlikely(flags & 1)) {
2576
gen_qemu_ld16u_ppc64(arg0, arg1, flags);
2577
t0 = tcg_temp_new(TCG_TYPE_I32);
2578
tcg_gen_trunc_tl_i32(t0, arg0);
2579
tcg_gen_bswap16_i32(t0, t0);
2580
tcg_gen_extu_i32_tl(arg0, t0);
2583
gen_qemu_ld16u_ppc64(arg0, arg1, flags);
2586
static always_inline void gen_qemu_ld16s(TCGv arg0, TCGv arg1, int flags)
2588
if (unlikely(flags & 1)) {
2590
gen_qemu_ld16u_ppc64(arg0, arg1, flags);
2591
t0 = tcg_temp_new(TCG_TYPE_I32);
2592
tcg_gen_trunc_tl_i32(t0, arg0);
2593
tcg_gen_bswap16_i32(t0, t0);
2594
tcg_gen_extu_i32_tl(arg0, t0);
2595
tcg_gen_ext16s_tl(arg0, arg0);
2598
gen_qemu_ld16s_ppc64(arg0, arg1, flags);
2601
static always_inline void gen_qemu_ld32u(TCGv arg0, TCGv arg1, int flags)
2603
if (unlikely(flags & 1)) {
2605
gen_qemu_ld32u_ppc64(arg0, arg1, flags);
2606
t0 = tcg_temp_new(TCG_TYPE_I32);
2607
tcg_gen_trunc_tl_i32(t0, arg0);
2608
tcg_gen_bswap_i32(t0, t0);
2609
tcg_gen_extu_i32_tl(arg0, t0);
2612
gen_qemu_ld32u_ppc64(arg0, arg1, flags);
2615
static always_inline void gen_qemu_ld32s(TCGv arg0, TCGv arg1, int flags)
2617
if (unlikely(flags & 1)) {
2619
gen_qemu_ld32u_ppc64(arg0, arg1, flags);
2620
t0 = tcg_temp_new(TCG_TYPE_I32);
2621
tcg_gen_trunc_tl_i32(t0, arg0);
2622
tcg_gen_bswap_i32(t0, t0);
2623
tcg_gen_ext_i32_tl(arg0, t0);
2626
gen_qemu_ld32s_ppc64(arg0, arg1, flags);
2629
static always_inline void gen_qemu_ld64(TCGv arg0, TCGv arg1, int flags)
2631
gen_qemu_ld64_ppc64(arg0, arg1, flags);
2632
if (unlikely(flags & 1))
2633
tcg_gen_bswap_i64(arg0, arg0);
2636
static always_inline void gen_qemu_st8(TCGv arg0, TCGv arg1, int flags)
2638
gen_qemu_st8_ppc64(arg0, arg1, flags);
2641
static always_inline void gen_qemu_st16(TCGv arg0, TCGv arg1, int flags)
2643
if (unlikely(flags & 1)) {
2645
t0 = tcg_temp_new(TCG_TYPE_I32);
2646
tcg_gen_trunc_tl_i32(t0, arg0);
2647
tcg_gen_ext16u_i32(t0, t0);
2648
tcg_gen_bswap16_i32(t0, t0);
2649
t1 = tcg_temp_new(TCG_TYPE_I64);
2650
tcg_gen_extu_i32_tl(t1, t0);
2652
gen_qemu_st16_ppc64(t1, arg1, flags);
2655
gen_qemu_st16_ppc64(arg0, arg1, flags);
2658
static always_inline void gen_qemu_st32(TCGv arg0, TCGv arg1, int flags)
2660
if (unlikely(flags & 1)) {
2662
t0 = tcg_temp_new(TCG_TYPE_I32);
2663
tcg_gen_trunc_tl_i32(t0, arg0);
2664
tcg_gen_bswap_i32(t0, t0);
2665
t1 = tcg_temp_new(TCG_TYPE_I64);
2666
tcg_gen_extu_i32_tl(t1, t0);
2668
gen_qemu_st32_ppc64(t1, arg1, flags);
2671
gen_qemu_st32_ppc64(arg0, arg1, flags);
2674
static always_inline void gen_qemu_st64(TCGv arg0, TCGv arg1, int flags)
2676
if (unlikely(flags & 1)) {
2677
TCGv t0 = tcg_temp_new(TCG_TYPE_I64);
2678
tcg_gen_bswap_i64(t0, arg0);
2679
gen_qemu_st64_ppc64(t0, arg1, flags);
2682
gen_qemu_st64_ppc64(arg0, arg1, flags);
2686
#else /* defined(TARGET_PPC64) */
2687
#define GEN_QEMU_LD_PPC32(width) \
2688
static always_inline void gen_qemu_ld##width##_ppc32(TCGv arg0, TCGv arg1, int flags)\
2690
tcg_gen_qemu_ld##width(arg0, arg1, flags >> 1); \
2692
GEN_QEMU_LD_PPC32(8u)
2693
GEN_QEMU_LD_PPC32(8s)
2694
GEN_QEMU_LD_PPC32(16u)
2695
GEN_QEMU_LD_PPC32(16s)
2696
GEN_QEMU_LD_PPC32(32u)
2697
GEN_QEMU_LD_PPC32(32s)
2698
GEN_QEMU_LD_PPC32(64)
2700
#define GEN_QEMU_ST_PPC32(width) \
2701
static always_inline void gen_qemu_st##width##_ppc32(TCGv arg0, TCGv arg1, int flags)\
2703
tcg_gen_qemu_st##width(arg0, arg1, flags >> 1); \
2705
GEN_QEMU_ST_PPC32(8)
2706
GEN_QEMU_ST_PPC32(16)
2707
GEN_QEMU_ST_PPC32(32)
2708
GEN_QEMU_ST_PPC32(64)
2710
static always_inline void gen_qemu_ld8u(TCGv arg0, TCGv arg1, int flags)
2712
gen_qemu_ld8u_ppc32(arg0, arg1, flags >> 1);
2715
static always_inline void gen_qemu_ld8s(TCGv arg0, TCGv arg1, int flags)
2717
gen_qemu_ld8s_ppc32(arg0, arg1, flags >> 1);
2720
static always_inline void gen_qemu_ld16u(TCGv arg0, TCGv arg1, int flags)
2722
gen_qemu_ld16u_ppc32(arg0, arg1, flags >> 1);
2723
if (unlikely(flags & 1))
2724
tcg_gen_bswap16_i32(arg0, arg0);
2727
static always_inline void gen_qemu_ld16s(TCGv arg0, TCGv arg1, int flags)
2729
if (unlikely(flags & 1)) {
2730
gen_qemu_ld16u_ppc32(arg0, arg1, flags);
2731
tcg_gen_bswap16_i32(arg0, arg0);
2732
tcg_gen_ext16s_i32(arg0, arg0);
2734
gen_qemu_ld16s_ppc32(arg0, arg1, flags);
2737
static always_inline void gen_qemu_ld32u(TCGv arg0, TCGv arg1, int flags)
2739
gen_qemu_ld32u_ppc32(arg0, arg1, flags);
2740
if (unlikely(flags & 1))
2741
tcg_gen_bswap_i32(arg0, arg0);
2744
static always_inline void gen_qemu_ld64(TCGv arg0, TCGv arg1, int flags)
2746
gen_qemu_ld64_ppc32(arg0, arg1, flags);
2747
if (unlikely(flags & 1))
2748
tcg_gen_bswap_i64(arg0, arg0);
2751
static always_inline void gen_qemu_st8(TCGv arg0, TCGv arg1, int flags)
2753
gen_qemu_st8_ppc32(arg0, arg1, flags);
2756
static always_inline void gen_qemu_st16(TCGv arg0, TCGv arg1, int flags)
2758
if (unlikely(flags & 1)) {
2759
TCGv temp = tcg_temp_new(TCG_TYPE_I32);
2760
tcg_gen_ext16u_i32(temp, arg0);
2761
tcg_gen_bswap16_i32(temp, temp);
2762
gen_qemu_st16_ppc32(temp, arg1, flags);
2763
tcg_temp_free(temp);
2765
gen_qemu_st16_ppc32(arg0, arg1, flags);
2768
static always_inline void gen_qemu_st32(TCGv arg0, TCGv arg1, int flags)
2770
if (unlikely(flags & 1)) {
2771
TCGv temp = tcg_temp_new(TCG_TYPE_I32);
2772
tcg_gen_bswap_i32(temp, arg0);
2773
gen_qemu_st32_ppc32(temp, arg1, flags);
2774
tcg_temp_free(temp);
2776
gen_qemu_st32_ppc32(arg0, arg1, flags);
2779
static always_inline void gen_qemu_st64(TCGv arg0, TCGv arg1, int flags)
2781
if (unlikely(flags & 1)) {
2782
TCGv temp = tcg_temp_new(TCG_TYPE_I64);
2783
tcg_gen_bswap_i64(temp, arg0);
2784
gen_qemu_st64_ppc32(temp, arg1, flags);
2785
tcg_temp_free(temp);
2787
gen_qemu_st64_ppc32(arg0, arg1, flags);
1991
#if defined(CONFIG_USER_ONLY)
1992
#if defined(TARGET_PPC64)
1993
/* User mode only - 64 bits */
1994
#define OP_LD_TABLE(width) \
1995
static GenOpFunc *gen_op_l##width[] = { \
1996
&gen_op_l##width##_raw, \
1997
&gen_op_l##width##_le_raw, \
1998
&gen_op_l##width##_64_raw, \
1999
&gen_op_l##width##_le_64_raw, \
2001
#define OP_ST_TABLE(width) \
2002
static GenOpFunc *gen_op_st##width[] = { \
2003
&gen_op_st##width##_raw, \
2004
&gen_op_st##width##_le_raw, \
2005
&gen_op_st##width##_64_raw, \
2006
&gen_op_st##width##_le_64_raw, \
2008
/* Byte access routine are endian safe */
2009
#define gen_op_stb_le_64_raw gen_op_stb_64_raw
2010
#define gen_op_lbz_le_64_raw gen_op_lbz_64_raw
2012
/* User mode only - 32 bits */
2013
#define OP_LD_TABLE(width) \
2014
static GenOpFunc *gen_op_l##width[] = { \
2015
&gen_op_l##width##_raw, \
2016
&gen_op_l##width##_le_raw, \
2018
#define OP_ST_TABLE(width) \
2019
static GenOpFunc *gen_op_st##width[] = { \
2020
&gen_op_st##width##_raw, \
2021
&gen_op_st##width##_le_raw, \
2024
/* Byte access routine are endian safe */
2025
#define gen_op_stb_le_raw gen_op_stb_raw
2026
#define gen_op_lbz_le_raw gen_op_lbz_raw
2028
#if defined(TARGET_PPC64)
2029
#if defined(TARGET_PPC64H)
2030
/* Full system - 64 bits with hypervisor mode */
2031
#define OP_LD_TABLE(width) \
2032
static GenOpFunc *gen_op_l##width[] = { \
2033
&gen_op_l##width##_user, \
2034
&gen_op_l##width##_le_user, \
2035
&gen_op_l##width##_64_user, \
2036
&gen_op_l##width##_le_64_user, \
2037
&gen_op_l##width##_kernel, \
2038
&gen_op_l##width##_le_kernel, \
2039
&gen_op_l##width##_64_kernel, \
2040
&gen_op_l##width##_le_64_kernel, \
2041
&gen_op_l##width##_hypv, \
2042
&gen_op_l##width##_le_hypv, \
2043
&gen_op_l##width##_64_hypv, \
2044
&gen_op_l##width##_le_64_hypv, \
2046
#define OP_ST_TABLE(width) \
2047
static GenOpFunc *gen_op_st##width[] = { \
2048
&gen_op_st##width##_user, \
2049
&gen_op_st##width##_le_user, \
2050
&gen_op_st##width##_64_user, \
2051
&gen_op_st##width##_le_64_user, \
2052
&gen_op_st##width##_kernel, \
2053
&gen_op_st##width##_le_kernel, \
2054
&gen_op_st##width##_64_kernel, \
2055
&gen_op_st##width##_le_64_kernel, \
2056
&gen_op_st##width##_hypv, \
2057
&gen_op_st##width##_le_hypv, \
2058
&gen_op_st##width##_64_hypv, \
2059
&gen_op_st##width##_le_64_hypv, \
2061
/* Byte access routine are endian safe */
2062
#define gen_op_stb_le_hypv gen_op_stb_64_hypv
2063
#define gen_op_lbz_le_hypv gen_op_lbz_64_hypv
2064
#define gen_op_stb_le_64_hypv gen_op_stb_64_hypv
2065
#define gen_op_lbz_le_64_hypv gen_op_lbz_64_hypv
2067
/* Full system - 64 bits */
2068
#define OP_LD_TABLE(width) \
2069
static GenOpFunc *gen_op_l##width[] = { \
2070
&gen_op_l##width##_user, \
2071
&gen_op_l##width##_le_user, \
2072
&gen_op_l##width##_64_user, \
2073
&gen_op_l##width##_le_64_user, \
2074
&gen_op_l##width##_kernel, \
2075
&gen_op_l##width##_le_kernel, \
2076
&gen_op_l##width##_64_kernel, \
2077
&gen_op_l##width##_le_64_kernel, \
2079
#define OP_ST_TABLE(width) \
2080
static GenOpFunc *gen_op_st##width[] = { \
2081
&gen_op_st##width##_user, \
2082
&gen_op_st##width##_le_user, \
2083
&gen_op_st##width##_64_user, \
2084
&gen_op_st##width##_le_64_user, \
2085
&gen_op_st##width##_kernel, \
2086
&gen_op_st##width##_le_kernel, \
2087
&gen_op_st##width##_64_kernel, \
2088
&gen_op_st##width##_le_64_kernel, \
2091
/* Byte access routine are endian safe */
2092
#define gen_op_stb_le_64_user gen_op_stb_64_user
2093
#define gen_op_lbz_le_64_user gen_op_lbz_64_user
2094
#define gen_op_stb_le_64_kernel gen_op_stb_64_kernel
2095
#define gen_op_lbz_le_64_kernel gen_op_lbz_64_kernel
2097
/* Full system - 32 bits */
2098
#define OP_LD_TABLE(width) \
2099
static GenOpFunc *gen_op_l##width[] = { \
2100
&gen_op_l##width##_user, \
2101
&gen_op_l##width##_le_user, \
2102
&gen_op_l##width##_kernel, \
2103
&gen_op_l##width##_le_kernel, \
2105
#define OP_ST_TABLE(width) \
2106
static GenOpFunc *gen_op_st##width[] = { \
2107
&gen_op_st##width##_user, \
2108
&gen_op_st##width##_le_user, \
2109
&gen_op_st##width##_kernel, \
2110
&gen_op_st##width##_le_kernel, \
2113
/* Byte access routine are endian safe */
2114
#define gen_op_stb_le_user gen_op_stb_user
2115
#define gen_op_lbz_le_user gen_op_lbz_user
2116
#define gen_op_stb_le_kernel gen_op_stb_kernel
2117
#define gen_op_lbz_le_kernel gen_op_lbz_kernel
2792
2120
#define GEN_LD(width, opc, type) \
2793
2121
GEN_HANDLER(l##width, opc, 0xFF, 0xFF, 0x00000000, type) \
2795
TCGv EA = tcg_temp_new(TCG_TYPE_TL); \
2796
gen_addr_imm_index(EA, ctx, 0); \
2797
gen_qemu_ld##width(cpu_gpr[rD(ctx->opcode)], EA, ctx->mem_idx); \
2798
tcg_temp_free(EA); \
2123
gen_addr_imm_index(ctx, 0); \
2124
op_ldst(l##width); \
2125
gen_op_store_T1_gpr(rD(ctx->opcode)); \
2801
2128
#define GEN_LDU(width, opc, type) \
2802
2129
GEN_HANDLER(l##width##u, opc, 0xFF, 0xFF, 0x00000000, type) \
2805
2131
if (unlikely(rA(ctx->opcode) == 0 || \
2806
2132
rA(ctx->opcode) == rD(ctx->opcode))) { \
2807
2133
GEN_EXCP_INVAL(ctx); \
2810
EA = tcg_temp_new(TCG_TYPE_TL); \
2811
2136
if (type == PPC_64B) \
2812
gen_addr_imm_index(EA, ctx, 0x03); \
2137
gen_addr_imm_index(ctx, 0x03); \
2814
gen_addr_imm_index(EA, ctx, 0); \
2815
gen_qemu_ld##width(cpu_gpr[rD(ctx->opcode)], EA, ctx->mem_idx); \
2816
tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2817
tcg_temp_free(EA); \
2139
gen_addr_imm_index(ctx, 0); \
2140
op_ldst(l##width); \
2141
gen_op_store_T1_gpr(rD(ctx->opcode)); \
2142
gen_op_store_T0_gpr(rA(ctx->opcode)); \
2820
2145
#define GEN_LDUX(width, opc2, opc3, type) \
2821
2146
GEN_HANDLER(l##width##ux, 0x1F, opc2, opc3, 0x00000001, type) \
2824
2148
if (unlikely(rA(ctx->opcode) == 0 || \
2825
2149
rA(ctx->opcode) == rD(ctx->opcode))) { \
2826
2150
GEN_EXCP_INVAL(ctx); \
2829
EA = tcg_temp_new(TCG_TYPE_TL); \
2830
gen_addr_reg_index(EA, ctx); \
2831
gen_qemu_ld##width(cpu_gpr[rD(ctx->opcode)], EA, ctx->mem_idx); \
2832
tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2833
tcg_temp_free(EA); \
2153
gen_addr_reg_index(ctx); \
2154
op_ldst(l##width); \
2155
gen_op_store_T1_gpr(rD(ctx->opcode)); \
2156
gen_op_store_T0_gpr(rA(ctx->opcode)); \
2836
2159
#define GEN_LDX(width, opc2, opc3, type) \
2837
2160
GEN_HANDLER(l##width##x, 0x1F, opc2, opc3, 0x00000001, type) \
2839
TCGv EA = tcg_temp_new(TCG_TYPE_TL); \
2840
gen_addr_reg_index(EA, ctx); \
2841
gen_qemu_ld##width(cpu_gpr[rD(ctx->opcode)], EA, ctx->mem_idx); \
2842
tcg_temp_free(EA); \
2162
gen_addr_reg_index(ctx); \
2163
op_ldst(l##width); \
2164
gen_op_store_T1_gpr(rD(ctx->opcode)); \
2845
2167
#define GEN_LDS(width, op, type) \
2168
OP_LD_TABLE(width); \
2846
2169
GEN_LD(width, op | 0x20, type); \
2847
2170
GEN_LDU(width, op | 0x21, type); \
2848
2171
GEN_LDUX(width, 0x17, op | 0x01, type); \
2849
2172
GEN_LDX(width, 0x17, op | 0x00, type)
2851
2174
/* lbz lbzu lbzux lbzx */
2852
GEN_LDS(8u, 0x02, PPC_INTEGER);
2175
GEN_LDS(bz, 0x02, PPC_INTEGER);
2853
2176
/* lha lhau lhaux lhax */
2854
GEN_LDS(16s, 0x0A, PPC_INTEGER);
2177
GEN_LDS(ha, 0x0A, PPC_INTEGER);
2855
2178
/* lhz lhzu lhzux lhzx */
2856
GEN_LDS(16u, 0x08, PPC_INTEGER);
2179
GEN_LDS(hz, 0x08, PPC_INTEGER);
2857
2180
/* lwz lwzu lwzux lwzx */
2858
GEN_LDS(32u, 0x00, PPC_INTEGER);
2181
GEN_LDS(wz, 0x00, PPC_INTEGER);
2859
2182
#if defined(TARGET_PPC64)
2861
GEN_LDUX(32s, 0x15, 0x0B, PPC_64B);
2186
GEN_LDUX(wa, 0x15, 0x0B, PPC_64B);
2863
GEN_LDX(32s, 0x15, 0x0A, PPC_64B);
2188
GEN_LDX(wa, 0x15, 0x0A, PPC_64B);
2865
GEN_LDUX(64, 0x15, 0x01, PPC_64B);
2190
GEN_LDUX(d, 0x15, 0x01, PPC_64B);
2867
GEN_LDX(64, 0x15, 0x00, PPC_64B);
2192
GEN_LDX(d, 0x15, 0x00, PPC_64B);
2868
2193
GEN_HANDLER(ld, 0x3A, 0xFF, 0xFF, 0x00000000, PPC_64B)
2871
2195
if (Rc(ctx->opcode)) {
2872
2196
if (unlikely(rA(ctx->opcode) == 0 ||
2873
2197
rA(ctx->opcode) == rD(ctx->opcode))) {
4446
4193
/* abs - abs. */
4447
4194
GEN_HANDLER(abs, 0x1F, 0x08, 0x0B, 0x0000F800, PPC_POWER_BR)
4449
tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4196
gen_op_load_gpr_T0(rA(ctx->opcode));
4450
4197
gen_op_POWER_abs();
4451
tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4198
gen_op_store_T0_gpr(rD(ctx->opcode));
4452
4199
if (unlikely(Rc(ctx->opcode) != 0))
4453
gen_set_Rc0(ctx, cpu_T[0]);
4456
4203
/* abso - abso. */
4457
4204
GEN_HANDLER(abso, 0x1F, 0x08, 0x1B, 0x0000F800, PPC_POWER_BR)
4459
tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4206
gen_op_load_gpr_T0(rA(ctx->opcode));
4460
4207
gen_op_POWER_abso();
4461
tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4208
gen_op_store_T0_gpr(rD(ctx->opcode));
4462
4209
if (unlikely(Rc(ctx->opcode) != 0))
4463
gen_set_Rc0(ctx, cpu_T[0]);
4467
4214
GEN_HANDLER(clcs, 0x1F, 0x10, 0x13, 0x0000F800, PPC_POWER_BR)
4469
tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4216
gen_op_load_gpr_T0(rA(ctx->opcode));
4470
4217
gen_op_POWER_clcs();
4471
/* Rc=1 sets CR0 to an undefined state */
4472
tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4218
gen_op_store_T0_gpr(rD(ctx->opcode));
4475
4221
/* div - div. */
4476
4222
GEN_HANDLER(div, 0x1F, 0x0B, 0x0A, 0x00000000, PPC_POWER_BR)
4478
tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4479
tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4224
gen_op_load_gpr_T0(rA(ctx->opcode));
4225
gen_op_load_gpr_T1(rB(ctx->opcode));
4480
4226
gen_op_POWER_div();
4481
tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4227
gen_op_store_T0_gpr(rD(ctx->opcode));
4482
4228
if (unlikely(Rc(ctx->opcode) != 0))
4483
gen_set_Rc0(ctx, cpu_T[0]);
4486
4232
/* divo - divo. */
4487
4233
GEN_HANDLER(divo, 0x1F, 0x0B, 0x1A, 0x00000000, PPC_POWER_BR)
4489
tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4490
tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4235
gen_op_load_gpr_T0(rA(ctx->opcode));
4236
gen_op_load_gpr_T1(rB(ctx->opcode));
4491
4237
gen_op_POWER_divo();
4492
tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4238
gen_op_store_T0_gpr(rD(ctx->opcode));
4493
4239
if (unlikely(Rc(ctx->opcode) != 0))
4494
gen_set_Rc0(ctx, cpu_T[0]);
4497
4243
/* divs - divs. */
4498
4244
GEN_HANDLER(divs, 0x1F, 0x0B, 0x0B, 0x00000000, PPC_POWER_BR)
4500
tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4501
tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4246
gen_op_load_gpr_T0(rA(ctx->opcode));
4247
gen_op_load_gpr_T1(rB(ctx->opcode));
4502
4248
gen_op_POWER_divs();
4503
tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4249
gen_op_store_T0_gpr(rD(ctx->opcode));
4504
4250
if (unlikely(Rc(ctx->opcode) != 0))
4505
gen_set_Rc0(ctx, cpu_T[0]);
4508
4254
/* divso - divso. */
4509
4255
GEN_HANDLER(divso, 0x1F, 0x0B, 0x1B, 0x00000000, PPC_POWER_BR)
4511
tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4512
tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4257
gen_op_load_gpr_T0(rA(ctx->opcode));
4258
gen_op_load_gpr_T1(rB(ctx->opcode));
4513
4259
gen_op_POWER_divso();
4514
tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4260
gen_op_store_T0_gpr(rD(ctx->opcode));
4515
4261
if (unlikely(Rc(ctx->opcode) != 0))
4516
gen_set_Rc0(ctx, cpu_T[0]);
4519
4265
/* doz - doz. */
4520
4266
GEN_HANDLER(doz, 0x1F, 0x08, 0x08, 0x00000000, PPC_POWER_BR)
4522
tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4523
tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4268
gen_op_load_gpr_T0(rA(ctx->opcode));
4269
gen_op_load_gpr_T1(rB(ctx->opcode));
4524
4270
gen_op_POWER_doz();
4525
tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4271
gen_op_store_T0_gpr(rD(ctx->opcode));
4526
4272
if (unlikely(Rc(ctx->opcode) != 0))
4527
gen_set_Rc0(ctx, cpu_T[0]);
4530
4276
/* dozo - dozo. */
4531
4277
GEN_HANDLER(dozo, 0x1F, 0x08, 0x18, 0x00000000, PPC_POWER_BR)
4533
tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4534
tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4279
gen_op_load_gpr_T0(rA(ctx->opcode));
4280
gen_op_load_gpr_T1(rB(ctx->opcode));
4535
4281
gen_op_POWER_dozo();
4536
tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4282
gen_op_store_T0_gpr(rD(ctx->opcode));
4537
4283
if (unlikely(Rc(ctx->opcode) != 0))
4538
gen_set_Rc0(ctx, cpu_T[0]);
4542
4288
GEN_HANDLER(dozi, 0x09, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR)
4544
tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4545
tcg_gen_movi_tl(cpu_T[1], SIMM(ctx->opcode));
4290
gen_op_load_gpr_T0(rA(ctx->opcode));
4291
gen_op_set_T1(SIMM(ctx->opcode));
4546
4292
gen_op_POWER_doz();
4547
tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4293
gen_op_store_T0_gpr(rD(ctx->opcode));
4550
/* As lscbx load from memory byte after byte, it's always endian safe.
4551
* Original POWER is 32 bits only, define 64 bits ops as 32 bits ones
4296
/* As lscbx load from memory byte after byte, it's always endian safe */
4553
4297
#define op_POWER_lscbx(start, ra, rb) \
4554
4298
(*gen_op_POWER_lscbx[ctx->mem_idx])(start, ra, rb)
4555
#define gen_op_POWER_lscbx_64_raw gen_op_POWER_lscbx_raw
4556
#define gen_op_POWER_lscbx_64_user gen_op_POWER_lscbx_user
4557
#define gen_op_POWER_lscbx_64_kernel gen_op_POWER_lscbx_kernel
4558
#define gen_op_POWER_lscbx_64_hypv gen_op_POWER_lscbx_hypv
4559
#define gen_op_POWER_lscbx_le_raw gen_op_POWER_lscbx_raw
4560
#define gen_op_POWER_lscbx_le_user gen_op_POWER_lscbx_user
4561
#define gen_op_POWER_lscbx_le_kernel gen_op_POWER_lscbx_kernel
4562
#define gen_op_POWER_lscbx_le_hypv gen_op_POWER_lscbx_hypv
4563
#define gen_op_POWER_lscbx_le_64_raw gen_op_POWER_lscbx_raw
4564
#define gen_op_POWER_lscbx_le_64_user gen_op_POWER_lscbx_user
4565
#define gen_op_POWER_lscbx_le_64_kernel gen_op_POWER_lscbx_kernel
4566
#define gen_op_POWER_lscbx_le_64_hypv gen_op_POWER_lscbx_hypv
4567
static GenOpFunc3 *gen_op_POWER_lscbx[NB_MEM_FUNCS] = {
4568
GEN_MEM_FUNCS(POWER_lscbx),
4299
#if defined(CONFIG_USER_ONLY)
4300
static GenOpFunc3 *gen_op_POWER_lscbx[] = {
4301
&gen_op_POWER_lscbx_raw,
4302
&gen_op_POWER_lscbx_raw,
4305
static GenOpFunc3 *gen_op_POWER_lscbx[] = {
4306
&gen_op_POWER_lscbx_user,
4307
&gen_op_POWER_lscbx_user,
4308
&gen_op_POWER_lscbx_kernel,
4309
&gen_op_POWER_lscbx_kernel,
4571
4313
/* lscbx - lscbx. */
4572
4314
GEN_HANDLER(lscbx, 0x1F, 0x15, 0x08, 0x00000000, PPC_POWER_BR)
4663
4403
mb = MB(ctx->opcode);
4664
4404
me = ME(ctx->opcode);
4665
tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4666
tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rA(ctx->opcode)]);
4667
tcg_gen_mov_tl(cpu_T[2], cpu_gpr[rB(ctx->opcode)]);
4405
gen_op_load_gpr_T0(rS(ctx->opcode));
4406
gen_op_load_gpr_T1(rA(ctx->opcode));
4407
gen_op_load_gpr_T2(rB(ctx->opcode));
4668
4408
gen_op_POWER_rlmi(MASK(mb, me), ~MASK(mb, me));
4669
tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4409
gen_op_store_T0_gpr(rA(ctx->opcode));
4670
4410
if (unlikely(Rc(ctx->opcode) != 0))
4671
gen_set_Rc0(ctx, cpu_T[0]);
4674
4414
/* rrib - rrib. */
4675
4415
GEN_HANDLER(rrib, 0x1F, 0x19, 0x10, 0x00000000, PPC_POWER_BR)
4677
tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4678
tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rA(ctx->opcode)]);
4679
tcg_gen_mov_tl(cpu_T[2], cpu_gpr[rB(ctx->opcode)]);
4417
gen_op_load_gpr_T0(rS(ctx->opcode));
4418
gen_op_load_gpr_T1(rA(ctx->opcode));
4419
gen_op_load_gpr_T2(rB(ctx->opcode));
4680
4420
gen_op_POWER_rrib();
4681
tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4421
gen_op_store_T0_gpr(rA(ctx->opcode));
4682
4422
if (unlikely(Rc(ctx->opcode) != 0))
4683
gen_set_Rc0(ctx, cpu_T[0]);
4686
4426
/* sle - sle. */
4687
4427
GEN_HANDLER(sle, 0x1F, 0x19, 0x04, 0x00000000, PPC_POWER_BR)
4689
tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4690
tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4429
gen_op_load_gpr_T0(rS(ctx->opcode));
4430
gen_op_load_gpr_T1(rB(ctx->opcode));
4691
4431
gen_op_POWER_sle();
4692
tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4432
gen_op_store_T0_gpr(rA(ctx->opcode));
4693
4433
if (unlikely(Rc(ctx->opcode) != 0))
4694
gen_set_Rc0(ctx, cpu_T[0]);
4697
4437
/* sleq - sleq. */
4698
4438
GEN_HANDLER(sleq, 0x1F, 0x19, 0x06, 0x00000000, PPC_POWER_BR)
4700
tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4701
tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4440
gen_op_load_gpr_T0(rS(ctx->opcode));
4441
gen_op_load_gpr_T1(rB(ctx->opcode));
4702
4442
gen_op_POWER_sleq();
4703
tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4443
gen_op_store_T0_gpr(rA(ctx->opcode));
4704
4444
if (unlikely(Rc(ctx->opcode) != 0))
4705
gen_set_Rc0(ctx, cpu_T[0]);
4708
4448
/* sliq - sliq. */
4709
4449
GEN_HANDLER(sliq, 0x1F, 0x18, 0x05, 0x00000000, PPC_POWER_BR)
4711
tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4712
tcg_gen_movi_tl(cpu_T[1], SH(ctx->opcode));
4451
gen_op_load_gpr_T0(rS(ctx->opcode));
4452
gen_op_set_T1(SH(ctx->opcode));
4713
4453
gen_op_POWER_sle();
4714
tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4454
gen_op_store_T0_gpr(rA(ctx->opcode));
4715
4455
if (unlikely(Rc(ctx->opcode) != 0))
4716
gen_set_Rc0(ctx, cpu_T[0]);
4719
4459
/* slliq - slliq. */
4720
4460
GEN_HANDLER(slliq, 0x1F, 0x18, 0x07, 0x00000000, PPC_POWER_BR)
4722
tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4723
tcg_gen_movi_tl(cpu_T[1], SH(ctx->opcode));
4462
gen_op_load_gpr_T0(rS(ctx->opcode));
4463
gen_op_set_T1(SH(ctx->opcode));
4724
4464
gen_op_POWER_sleq();
4725
tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4465
gen_op_store_T0_gpr(rA(ctx->opcode));
4726
4466
if (unlikely(Rc(ctx->opcode) != 0))
4727
gen_set_Rc0(ctx, cpu_T[0]);
4730
4470
/* sllq - sllq. */
4731
4471
GEN_HANDLER(sllq, 0x1F, 0x18, 0x06, 0x00000000, PPC_POWER_BR)
4733
tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4734
tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4473
gen_op_load_gpr_T0(rS(ctx->opcode));
4474
gen_op_load_gpr_T1(rB(ctx->opcode));
4735
4475
gen_op_POWER_sllq();
4736
tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4476
gen_op_store_T0_gpr(rA(ctx->opcode));
4737
4477
if (unlikely(Rc(ctx->opcode) != 0))
4738
gen_set_Rc0(ctx, cpu_T[0]);
4741
4481
/* slq - slq. */
4742
4482
GEN_HANDLER(slq, 0x1F, 0x18, 0x04, 0x00000000, PPC_POWER_BR)
4744
tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4745
tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4484
gen_op_load_gpr_T0(rS(ctx->opcode));
4485
gen_op_load_gpr_T1(rB(ctx->opcode));
4746
4486
gen_op_POWER_slq();
4747
tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4487
gen_op_store_T0_gpr(rA(ctx->opcode));
4748
4488
if (unlikely(Rc(ctx->opcode) != 0))
4749
gen_set_Rc0(ctx, cpu_T[0]);
4752
4492
/* sraiq - sraiq. */
4753
4493
GEN_HANDLER(sraiq, 0x1F, 0x18, 0x1D, 0x00000000, PPC_POWER_BR)
4755
tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4756
tcg_gen_movi_tl(cpu_T[1], SH(ctx->opcode));
4495
gen_op_load_gpr_T0(rS(ctx->opcode));
4496
gen_op_set_T1(SH(ctx->opcode));
4757
4497
gen_op_POWER_sraq();
4758
tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4498
gen_op_store_T0_gpr(rA(ctx->opcode));
4759
4499
if (unlikely(Rc(ctx->opcode) != 0))
4760
gen_set_Rc0(ctx, cpu_T[0]);
4763
4503
/* sraq - sraq. */
4764
4504
GEN_HANDLER(sraq, 0x1F, 0x18, 0x1C, 0x00000000, PPC_POWER_BR)
4766
tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4767
tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4506
gen_op_load_gpr_T0(rS(ctx->opcode));
4507
gen_op_load_gpr_T1(rB(ctx->opcode));
4768
4508
gen_op_POWER_sraq();
4769
tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4509
gen_op_store_T0_gpr(rA(ctx->opcode));
4770
4510
if (unlikely(Rc(ctx->opcode) != 0))
4771
gen_set_Rc0(ctx, cpu_T[0]);
4774
4514
/* sre - sre. */
4775
4515
GEN_HANDLER(sre, 0x1F, 0x19, 0x14, 0x00000000, PPC_POWER_BR)
4777
tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4778
tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4517
gen_op_load_gpr_T0(rS(ctx->opcode));
4518
gen_op_load_gpr_T1(rB(ctx->opcode));
4779
4519
gen_op_POWER_sre();
4780
tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4520
gen_op_store_T0_gpr(rA(ctx->opcode));
4781
4521
if (unlikely(Rc(ctx->opcode) != 0))
4782
gen_set_Rc0(ctx, cpu_T[0]);
4785
4525
/* srea - srea. */
4786
4526
GEN_HANDLER(srea, 0x1F, 0x19, 0x1C, 0x00000000, PPC_POWER_BR)
4788
tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4789
tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4528
gen_op_load_gpr_T0(rS(ctx->opcode));
4529
gen_op_load_gpr_T1(rB(ctx->opcode));
4790
4530
gen_op_POWER_srea();
4791
tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4531
gen_op_store_T0_gpr(rA(ctx->opcode));
4792
4532
if (unlikely(Rc(ctx->opcode) != 0))
4793
gen_set_Rc0(ctx, cpu_T[0]);
4797
4537
GEN_HANDLER(sreq, 0x1F, 0x19, 0x16, 0x00000000, PPC_POWER_BR)
4799
tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4800
tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4539
gen_op_load_gpr_T0(rS(ctx->opcode));
4540
gen_op_load_gpr_T1(rB(ctx->opcode));
4801
4541
gen_op_POWER_sreq();
4802
tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4542
gen_op_store_T0_gpr(rA(ctx->opcode));
4803
4543
if (unlikely(Rc(ctx->opcode) != 0))
4804
gen_set_Rc0(ctx, cpu_T[0]);
4808
4548
GEN_HANDLER(sriq, 0x1F, 0x18, 0x15, 0x00000000, PPC_POWER_BR)
4810
tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4811
tcg_gen_movi_tl(cpu_T[1], SH(ctx->opcode));
4550
gen_op_load_gpr_T0(rS(ctx->opcode));
4551
gen_op_set_T1(SH(ctx->opcode));
4812
4552
gen_op_POWER_srq();
4813
tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4553
gen_op_store_T0_gpr(rA(ctx->opcode));
4814
4554
if (unlikely(Rc(ctx->opcode) != 0))
4815
gen_set_Rc0(ctx, cpu_T[0]);
4819
4559
GEN_HANDLER(srliq, 0x1F, 0x18, 0x17, 0x00000000, PPC_POWER_BR)
4821
tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4822
tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4823
tcg_gen_movi_tl(cpu_T[1], SH(ctx->opcode));
4561
gen_op_load_gpr_T0(rS(ctx->opcode));
4562
gen_op_load_gpr_T1(rB(ctx->opcode));
4563
gen_op_set_T1(SH(ctx->opcode));
4824
4564
gen_op_POWER_srlq();
4825
tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4565
gen_op_store_T0_gpr(rA(ctx->opcode));
4826
4566
if (unlikely(Rc(ctx->opcode) != 0))
4827
gen_set_Rc0(ctx, cpu_T[0]);
4831
4571
GEN_HANDLER(srlq, 0x1F, 0x18, 0x16, 0x00000000, PPC_POWER_BR)
4833
tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4834
tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4573
gen_op_load_gpr_T0(rS(ctx->opcode));
4574
gen_op_load_gpr_T1(rB(ctx->opcode));
4835
4575
gen_op_POWER_srlq();
4836
tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4576
gen_op_store_T0_gpr(rA(ctx->opcode));
4837
4577
if (unlikely(Rc(ctx->opcode) != 0))
4838
gen_set_Rc0(ctx, cpu_T[0]);
4842
4582
GEN_HANDLER(srq, 0x1F, 0x18, 0x14, 0x00000000, PPC_POWER_BR)
4844
tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4845
tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4584
gen_op_load_gpr_T0(rS(ctx->opcode));
4585
gen_op_load_gpr_T1(rB(ctx->opcode));
4846
4586
gen_op_POWER_srq();
4847
tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4587
gen_op_store_T0_gpr(rA(ctx->opcode));
4848
4588
if (unlikely(Rc(ctx->opcode) != 0))
4849
gen_set_Rc0(ctx, cpu_T[0]);
4852
4592
/* PowerPC 602 specific instructions */
5844
5538
/*** Altivec vector extension ***/
5845
5539
/* Altivec registers moves */
5847
static always_inline void gen_load_avr(int t, int reg) {
5848
tcg_gen_mov_i64(cpu_AVRh[t], cpu_avrh[reg]);
5849
tcg_gen_mov_i64(cpu_AVRl[t], cpu_avrl[reg]);
5852
static always_inline void gen_store_avr(int reg, int t) {
5853
tcg_gen_mov_i64(cpu_avrh[reg], cpu_AVRh[t]);
5854
tcg_gen_mov_i64(cpu_avrl[reg], cpu_AVRl[t]);
5540
GEN32(gen_op_load_avr_A0, gen_op_load_avr_A0_avr);
5541
GEN32(gen_op_load_avr_A1, gen_op_load_avr_A1_avr);
5542
GEN32(gen_op_load_avr_A2, gen_op_load_avr_A2_avr);
5544
GEN32(gen_op_store_A0_avr, gen_op_store_A0_avr_avr);
5545
GEN32(gen_op_store_A1_avr, gen_op_store_A1_avr_avr);
5547
GEN32(gen_op_store_A2_avr, gen_op_store_A2_avr_avr);
5857
5550
#define op_vr_ldst(name) (*gen_op_##name[ctx->mem_idx])()
5858
#define OP_VR_LD_TABLE(name) \
5859
static GenOpFunc *gen_op_vr_l##name[NB_MEM_FUNCS] = { \
5860
GEN_MEM_FUNCS(vr_l##name), \
5862
#define OP_VR_ST_TABLE(name) \
5863
static GenOpFunc *gen_op_vr_st##name[NB_MEM_FUNCS] = { \
5864
GEN_MEM_FUNCS(vr_st##name), \
5551
#if defined(CONFIG_USER_ONLY)
5552
#if defined(TARGET_PPC64)
5553
/* User-mode only - 64 bits mode */
5554
#define OP_VR_LD_TABLE(name) \
5555
static GenOpFunc *gen_op_vr_l##name[] = { \
5556
&gen_op_vr_l##name##_raw, \
5557
&gen_op_vr_l##name##_le_raw, \
5558
&gen_op_vr_l##name##_64_raw, \
5559
&gen_op_vr_l##name##_le_64_raw, \
5561
#define OP_VR_ST_TABLE(name) \
5562
static GenOpFunc *gen_op_vr_st##name[] = { \
5563
&gen_op_vr_st##name##_raw, \
5564
&gen_op_vr_st##name##_le_raw, \
5565
&gen_op_vr_st##name##_64_raw, \
5566
&gen_op_vr_st##name##_le_64_raw, \
5568
#else /* defined(TARGET_PPC64) */
5569
/* User-mode only - 32 bits mode */
5570
#define OP_VR_LD_TABLE(name) \
5571
static GenOpFunc *gen_op_vr_l##name[] = { \
5572
&gen_op_vr_l##name##_raw, \
5573
&gen_op_vr_l##name##_le_raw, \
5575
#define OP_VR_ST_TABLE(name) \
5576
static GenOpFunc *gen_op_vr_st##name[] = { \
5577
&gen_op_vr_st##name##_raw, \
5578
&gen_op_vr_st##name##_le_raw, \
5580
#endif /* defined(TARGET_PPC64) */
5581
#else /* defined(CONFIG_USER_ONLY) */
5582
#if defined(TARGET_PPC64H)
5583
/* Full system with hypervisor mode */
5584
#define OP_VR_LD_TABLE(name) \
5585
static GenOpFunc *gen_op_vr_l##name[] = { \
5586
&gen_op_vr_l##name##_user, \
5587
&gen_op_vr_l##name##_le_user, \
5588
&gen_op_vr_l##name##_64_user, \
5589
&gen_op_vr_l##name##_le_64_user, \
5590
&gen_op_vr_l##name##_kernel, \
5591
&gen_op_vr_l##name##_le_kernel, \
5592
&gen_op_vr_l##name##_64_kernel, \
5593
&gen_op_vr_l##name##_le_64_kernel, \
5594
&gen_op_vr_l##name##_hypv, \
5595
&gen_op_vr_l##name##_le_hypv, \
5596
&gen_op_vr_l##name##_64_hypv, \
5597
&gen_op_vr_l##name##_le_64_hypv, \
5599
#define OP_VR_ST_TABLE(name) \
5600
static GenOpFunc *gen_op_vr_st##name[] = { \
5601
&gen_op_vr_st##name##_user, \
5602
&gen_op_vr_st##name##_le_user, \
5603
&gen_op_vr_st##name##_64_user, \
5604
&gen_op_vr_st##name##_le_64_user, \
5605
&gen_op_vr_st##name##_kernel, \
5606
&gen_op_vr_st##name##_le_kernel, \
5607
&gen_op_vr_st##name##_64_kernel, \
5608
&gen_op_vr_st##name##_le_64_kernel, \
5609
&gen_op_vr_st##name##_hypv, \
5610
&gen_op_vr_st##name##_le_hypv, \
5611
&gen_op_vr_st##name##_64_hypv, \
5612
&gen_op_vr_st##name##_le_64_hypv, \
5614
#elif defined(TARGET_PPC64)
5615
/* Full system - 64 bits mode */
5616
#define OP_VR_LD_TABLE(name) \
5617
static GenOpFunc *gen_op_vr_l##name[] = { \
5618
&gen_op_vr_l##name##_user, \
5619
&gen_op_vr_l##name##_le_user, \
5620
&gen_op_vr_l##name##_64_user, \
5621
&gen_op_vr_l##name##_le_64_user, \
5622
&gen_op_vr_l##name##_kernel, \
5623
&gen_op_vr_l##name##_le_kernel, \
5624
&gen_op_vr_l##name##_64_kernel, \
5625
&gen_op_vr_l##name##_le_64_kernel, \
5627
#define OP_VR_ST_TABLE(name) \
5628
static GenOpFunc *gen_op_vr_st##name[] = { \
5629
&gen_op_vr_st##name##_user, \
5630
&gen_op_vr_st##name##_le_user, \
5631
&gen_op_vr_st##name##_64_user, \
5632
&gen_op_vr_st##name##_le_64_user, \
5633
&gen_op_vr_st##name##_kernel, \
5634
&gen_op_vr_st##name##_le_kernel, \
5635
&gen_op_vr_st##name##_64_kernel, \
5636
&gen_op_vr_st##name##_le_64_kernel, \
5638
#else /* defined(TARGET_PPC64) */
5639
/* Full system - 32 bits mode */
5640
#define OP_VR_LD_TABLE(name) \
5641
static GenOpFunc *gen_op_vr_l##name[] = { \
5642
&gen_op_vr_l##name##_user, \
5643
&gen_op_vr_l##name##_le_user, \
5644
&gen_op_vr_l##name##_kernel, \
5645
&gen_op_vr_l##name##_le_kernel, \
5647
#define OP_VR_ST_TABLE(name) \
5648
static GenOpFunc *gen_op_vr_st##name[] = { \
5649
&gen_op_vr_st##name##_user, \
5650
&gen_op_vr_st##name##_le_user, \
5651
&gen_op_vr_st##name##_kernel, \
5652
&gen_op_vr_st##name##_le_kernel, \
5654
#endif /* defined(TARGET_PPC64) */
5655
#endif /* defined(CONFIG_USER_ONLY) */
5867
5657
#define GEN_VR_LDX(name, opc2, opc3) \
5868
5658
GEN_HANDLER(l##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC) \
5941
5724
/* SPE load and stores */
5942
static always_inline void gen_addr_spe_imm_index (TCGv EA, DisasContext *ctx, int sh)
5725
static always_inline void gen_addr_spe_imm_index (DisasContext *ctx, int sh)
5944
5727
target_long simm = rB(ctx->opcode);
5946
if (rA(ctx->opcode) == 0)
5947
tcg_gen_movi_tl(EA, simm << sh);
5948
else if (likely(simm != 0))
5949
tcg_gen_addi_tl(EA, cpu_gpr[rA(ctx->opcode)], simm << sh);
5951
tcg_gen_mov_tl(EA, cpu_gpr[rA(ctx->opcode)]);
5729
if (rA(ctx->opcode) == 0) {
5730
gen_set_T0(simm << sh);
5732
gen_op_load_gpr_T0(rA(ctx->opcode));
5733
if (likely(simm != 0))
5734
gen_op_addi(simm << sh);
5954
5738
#define op_spe_ldst(name) (*gen_op_##name[ctx->mem_idx])()
5955
#define OP_SPE_LD_TABLE(name) \
5956
static GenOpFunc *gen_op_spe_l##name[NB_MEM_FUNCS] = { \
5957
GEN_MEM_FUNCS(spe_l##name), \
5959
#define OP_SPE_ST_TABLE(name) \
5960
static GenOpFunc *gen_op_spe_st##name[NB_MEM_FUNCS] = { \
5961
GEN_MEM_FUNCS(spe_st##name), \
5739
#if defined(CONFIG_USER_ONLY)
5740
#if defined(TARGET_PPC64)
5741
/* User-mode only - 64 bits mode */
5742
#define OP_SPE_LD_TABLE(name) \
5743
static GenOpFunc *gen_op_spe_l##name[] = { \
5744
&gen_op_spe_l##name##_raw, \
5745
&gen_op_spe_l##name##_le_raw, \
5746
&gen_op_spe_l##name##_64_raw, \
5747
&gen_op_spe_l##name##_le_64_raw, \
5749
#define OP_SPE_ST_TABLE(name) \
5750
static GenOpFunc *gen_op_spe_st##name[] = { \
5751
&gen_op_spe_st##name##_raw, \
5752
&gen_op_spe_st##name##_le_raw, \
5753
&gen_op_spe_st##name##_64_raw, \
5754
&gen_op_spe_st##name##_le_64_raw, \
5756
#else /* defined(TARGET_PPC64) */
5757
/* User-mode only - 32 bits mode */
5758
#define OP_SPE_LD_TABLE(name) \
5759
static GenOpFunc *gen_op_spe_l##name[] = { \
5760
&gen_op_spe_l##name##_raw, \
5761
&gen_op_spe_l##name##_le_raw, \
5763
#define OP_SPE_ST_TABLE(name) \
5764
static GenOpFunc *gen_op_spe_st##name[] = { \
5765
&gen_op_spe_st##name##_raw, \
5766
&gen_op_spe_st##name##_le_raw, \
5768
#endif /* defined(TARGET_PPC64) */
5769
#else /* defined(CONFIG_USER_ONLY) */
5770
#if defined(TARGET_PPC64H)
5771
/* Full system with hypervisor mode */
5772
#define OP_SPE_LD_TABLE(name) \
5773
static GenOpFunc *gen_op_spe_l##name[] = { \
5774
&gen_op_spe_l##name##_user, \
5775
&gen_op_spe_l##name##_le_user, \
5776
&gen_op_spe_l##name##_64_user, \
5777
&gen_op_spe_l##name##_le_64_user, \
5778
&gen_op_spe_l##name##_kernel, \
5779
&gen_op_spe_l##name##_le_kernel, \
5780
&gen_op_spe_l##name##_64_kernel, \
5781
&gen_op_spe_l##name##_le_64_kernel, \
5782
&gen_op_spe_l##name##_hypv, \
5783
&gen_op_spe_l##name##_le_hypv, \
5784
&gen_op_spe_l##name##_64_hypv, \
5785
&gen_op_spe_l##name##_le_64_hypv, \
5787
#define OP_SPE_ST_TABLE(name) \
5788
static GenOpFunc *gen_op_spe_st##name[] = { \
5789
&gen_op_spe_st##name##_user, \
5790
&gen_op_spe_st##name##_le_user, \
5791
&gen_op_spe_st##name##_64_user, \
5792
&gen_op_spe_st##name##_le_64_user, \
5793
&gen_op_spe_st##name##_kernel, \
5794
&gen_op_spe_st##name##_le_kernel, \
5795
&gen_op_spe_st##name##_64_kernel, \
5796
&gen_op_spe_st##name##_le_64_kernel, \
5797
&gen_op_spe_st##name##_hypv, \
5798
&gen_op_spe_st##name##_le_hypv, \
5799
&gen_op_spe_st##name##_64_hypv, \
5800
&gen_op_spe_st##name##_le_64_hypv, \
5802
#elif defined(TARGET_PPC64)
5803
/* Full system - 64 bits mode */
5804
#define OP_SPE_LD_TABLE(name) \
5805
static GenOpFunc *gen_op_spe_l##name[] = { \
5806
&gen_op_spe_l##name##_user, \
5807
&gen_op_spe_l##name##_le_user, \
5808
&gen_op_spe_l##name##_64_user, \
5809
&gen_op_spe_l##name##_le_64_user, \
5810
&gen_op_spe_l##name##_kernel, \
5811
&gen_op_spe_l##name##_le_kernel, \
5812
&gen_op_spe_l##name##_64_kernel, \
5813
&gen_op_spe_l##name##_le_64_kernel, \
5815
#define OP_SPE_ST_TABLE(name) \
5816
static GenOpFunc *gen_op_spe_st##name[] = { \
5817
&gen_op_spe_st##name##_user, \
5818
&gen_op_spe_st##name##_le_user, \
5819
&gen_op_spe_st##name##_64_user, \
5820
&gen_op_spe_st##name##_le_64_user, \
5821
&gen_op_spe_st##name##_kernel, \
5822
&gen_op_spe_st##name##_le_kernel, \
5823
&gen_op_spe_st##name##_64_kernel, \
5824
&gen_op_spe_st##name##_le_64_kernel, \
5826
#else /* defined(TARGET_PPC64) */
5827
/* Full system - 32 bits mode */
5828
#define OP_SPE_LD_TABLE(name) \
5829
static GenOpFunc *gen_op_spe_l##name[] = { \
5830
&gen_op_spe_l##name##_user, \
5831
&gen_op_spe_l##name##_le_user, \
5832
&gen_op_spe_l##name##_kernel, \
5833
&gen_op_spe_l##name##_le_kernel, \
5835
#define OP_SPE_ST_TABLE(name) \
5836
static GenOpFunc *gen_op_spe_st##name[] = { \
5837
&gen_op_spe_st##name##_user, \
5838
&gen_op_spe_st##name##_le_user, \
5839
&gen_op_spe_st##name##_kernel, \
5840
&gen_op_spe_st##name##_le_kernel, \
5842
#endif /* defined(TARGET_PPC64) */
5843
#endif /* defined(CONFIG_USER_ONLY) */
5964
5845
#define GEN_SPE_LD(name, sh) \
5965
5846
static always_inline void gen_evl##name (DisasContext *ctx) \
6023
5904
GEN_SPEOP_LD(name, sh); \
6024
5905
GEN_SPEOP_ST(name, sh)
6027
#if defined(TARGET_PPC64)
6028
#define GEN_SPEOP_LOGIC2(name, tcg_op) \
6029
static always_inline void gen_##name (DisasContext *ctx) \
6031
if (unlikely(!ctx->spe_enabled)) { \
6032
GEN_EXCP_NO_AP(ctx); \
6035
tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
6036
cpu_gpr[rB(ctx->opcode)]); \
6039
#define GEN_SPEOP_LOGIC2(name, tcg_op) \
6040
static always_inline void gen_##name (DisasContext *ctx) \
6042
if (unlikely(!ctx->spe_enabled)) { \
6043
GEN_EXCP_NO_AP(ctx); \
6046
tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
6047
cpu_gpr[rB(ctx->opcode)]); \
6048
tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
6049
cpu_gprh[rB(ctx->opcode)]); \
6053
GEN_SPEOP_LOGIC2(evand, tcg_gen_and_tl);
6054
GEN_SPEOP_LOGIC2(evandc, tcg_gen_andc_tl);
6055
GEN_SPEOP_LOGIC2(evxor, tcg_gen_xor_tl);
6056
GEN_SPEOP_LOGIC2(evor, tcg_gen_or_tl);
6057
GEN_SPEOP_LOGIC2(evnor, tcg_gen_nor_tl);
6058
GEN_SPEOP_LOGIC2(eveqv, tcg_gen_eqv_tl);
6059
GEN_SPEOP_LOGIC2(evorc, tcg_gen_orc_tl);
6060
GEN_SPEOP_LOGIC2(evnand, tcg_gen_nand_tl);
6062
/* SPE logic immediate */
6063
#if defined(TARGET_PPC64)
6064
#define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \
6065
static always_inline void gen_##name (DisasContext *ctx) \
6067
if (unlikely(!ctx->spe_enabled)) { \
6068
GEN_EXCP_NO_AP(ctx); \
6071
TCGv t0 = tcg_temp_local_new(TCG_TYPE_I32); \
6072
TCGv t1 = tcg_temp_local_new(TCG_TYPE_I32); \
6073
TCGv t2 = tcg_temp_local_new(TCG_TYPE_I64); \
6074
tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
6075
tcg_opi(t0, t0, rB(ctx->opcode)); \
6076
tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
6077
tcg_gen_trunc_i64_i32(t1, t2); \
6078
tcg_temp_free(t2); \
6079
tcg_opi(t1, t1, rB(ctx->opcode)); \
6080
tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
6081
tcg_temp_free(t0); \
6082
tcg_temp_free(t1); \
6085
#define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \
6086
static always_inline void gen_##name (DisasContext *ctx) \
6088
if (unlikely(!ctx->spe_enabled)) { \
6089
GEN_EXCP_NO_AP(ctx); \
6092
tcg_opi(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
6094
tcg_opi(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
6098
GEN_SPEOP_TCG_LOGIC_IMM2(evslwi, tcg_gen_shli_i32);
6099
GEN_SPEOP_TCG_LOGIC_IMM2(evsrwiu, tcg_gen_shri_i32);
6100
GEN_SPEOP_TCG_LOGIC_IMM2(evsrwis, tcg_gen_sari_i32);
6101
GEN_SPEOP_TCG_LOGIC_IMM2(evrlwi, tcg_gen_rotli_i32);
6103
/* SPE arithmetic */
6104
#if defined(TARGET_PPC64)
6105
#define GEN_SPEOP_ARITH1(name, tcg_op) \
6106
static always_inline void gen_##name (DisasContext *ctx) \
6108
if (unlikely(!ctx->spe_enabled)) { \
6109
GEN_EXCP_NO_AP(ctx); \
6112
TCGv t0 = tcg_temp_local_new(TCG_TYPE_I32); \
6113
TCGv t1 = tcg_temp_local_new(TCG_TYPE_I32); \
6114
TCGv t2 = tcg_temp_local_new(TCG_TYPE_I64); \
6115
tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
6117
tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
6118
tcg_gen_trunc_i64_i32(t1, t2); \
6119
tcg_temp_free(t2); \
6121
tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
6122
tcg_temp_free(t0); \
6123
tcg_temp_free(t1); \
6126
#define GEN_SPEOP_ARITH1(name, tcg_op) \
6127
static always_inline void gen_##name (DisasContext *ctx) \
6129
if (unlikely(!ctx->spe_enabled)) { \
6130
GEN_EXCP_NO_AP(ctx); \
6133
tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); \
6134
tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); \
6138
static always_inline void gen_op_evabs (TCGv ret, TCGv arg1)
6140
int l1 = gen_new_label();
6141
int l2 = gen_new_label();
6143
tcg_gen_brcondi_i32(TCG_COND_GE, arg1, 0, l1);
6144
tcg_gen_neg_i32(ret, arg1);
6147
tcg_gen_mov_tl(ret, arg1);
6150
GEN_SPEOP_ARITH1(evabs, gen_op_evabs);
6151
GEN_SPEOP_ARITH1(evneg, tcg_gen_neg_i32);
6152
GEN_SPEOP_ARITH1(evextsb, tcg_gen_ext8s_i32);
6153
GEN_SPEOP_ARITH1(evextsh, tcg_gen_ext16s_i32);
6154
static always_inline void gen_op_evrndw (TCGv ret, TCGv arg1)
6156
tcg_gen_addi_i32(ret, arg1, 0x8000);
6157
tcg_gen_ext16u_i32(ret, ret);
6159
GEN_SPEOP_ARITH1(evrndw, gen_op_evrndw);
6160
static always_inline void gen_op_cntlsw (TCGv ret, TCGv arg1)
6162
tcg_gen_helper_1_1(helper_cntlsw32, ret, arg1);
6164
GEN_SPEOP_ARITH1(evcntlsw, gen_op_cntlsw);
6165
static always_inline void gen_op_cntlzw (TCGv ret, TCGv arg1)
6167
tcg_gen_helper_1_1(helper_cntlzw32, ret, arg1);
6169
GEN_SPEOP_ARITH1(evcntlzw, gen_op_cntlzw);
6171
#if defined(TARGET_PPC64)
6172
#define GEN_SPEOP_ARITH2(name, tcg_op) \
6173
static always_inline void gen_##name (DisasContext *ctx) \
6175
if (unlikely(!ctx->spe_enabled)) { \
6176
GEN_EXCP_NO_AP(ctx); \
6179
TCGv t0 = tcg_temp_local_new(TCG_TYPE_I32); \
6180
TCGv t1 = tcg_temp_local_new(TCG_TYPE_I32); \
6181
TCGv t2 = tcg_temp_local_new(TCG_TYPE_I32); \
6182
TCGv t3 = tcg_temp_local_new(TCG_TYPE_I64); \
6183
tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
6184
tcg_gen_trunc_i64_i32(t2, cpu_gpr[rB(ctx->opcode)]); \
6185
tcg_op(t0, t0, t2); \
6186
tcg_gen_shri_i64(t3, cpu_gpr[rA(ctx->opcode)], 32); \
6187
tcg_gen_trunc_i64_i32(t1, t3); \
6188
tcg_gen_shri_i64(t3, cpu_gpr[rB(ctx->opcode)], 32); \
6189
tcg_gen_trunc_i64_i32(t2, t3); \
6190
tcg_temp_free(t3); \
6191
tcg_op(t1, t1, t2); \
6192
tcg_temp_free(t2); \
6193
tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
6194
tcg_temp_free(t0); \
6195
tcg_temp_free(t1); \
6198
#define GEN_SPEOP_ARITH2(name, tcg_op) \
6199
static always_inline void gen_##name (DisasContext *ctx) \
6201
if (unlikely(!ctx->spe_enabled)) { \
6202
GEN_EXCP_NO_AP(ctx); \
6205
tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
6206
cpu_gpr[rB(ctx->opcode)]); \
6207
tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
6208
cpu_gprh[rB(ctx->opcode)]); \
6212
static always_inline void gen_op_evsrwu (TCGv ret, TCGv arg1, TCGv arg2)
6217
l1 = gen_new_label();
6218
l2 = gen_new_label();
6219
t0 = tcg_temp_local_new(TCG_TYPE_I32);
6220
/* No error here: 6 bits are used */
6221
tcg_gen_andi_i32(t0, arg2, 0x3F);
6222
tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1);
6223
tcg_gen_shr_i32(ret, arg1, t0);
6226
tcg_gen_movi_i32(ret, 0);
6230
GEN_SPEOP_ARITH2(evsrwu, gen_op_evsrwu);
6231
static always_inline void gen_op_evsrws (TCGv ret, TCGv arg1, TCGv arg2)
6236
l1 = gen_new_label();
6237
l2 = gen_new_label();
6238
t0 = tcg_temp_local_new(TCG_TYPE_I32);
6239
/* No error here: 6 bits are used */
6240
tcg_gen_andi_i32(t0, arg2, 0x3F);
6241
tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1);
6242
tcg_gen_sar_i32(ret, arg1, t0);
6245
tcg_gen_movi_i32(ret, 0);
6249
GEN_SPEOP_ARITH2(evsrws, gen_op_evsrws);
6250
static always_inline void gen_op_evslw (TCGv ret, TCGv arg1, TCGv arg2)
6255
l1 = gen_new_label();
6256
l2 = gen_new_label();
6257
t0 = tcg_temp_local_new(TCG_TYPE_I32);
6258
/* No error here: 6 bits are used */
6259
tcg_gen_andi_i32(t0, arg2, 0x3F);
6260
tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1);
6261
tcg_gen_shl_i32(ret, arg1, t0);
6264
tcg_gen_movi_i32(ret, 0);
6268
GEN_SPEOP_ARITH2(evslw, gen_op_evslw);
6269
static always_inline void gen_op_evrlw (TCGv ret, TCGv arg1, TCGv arg2)
6271
TCGv t0 = tcg_temp_new(TCG_TYPE_I32);
6272
tcg_gen_andi_i32(t0, arg2, 0x1F);
6273
tcg_gen_rotl_i32(ret, arg1, t0);
6276
GEN_SPEOP_ARITH2(evrlw, gen_op_evrlw);
6277
static always_inline void gen_evmergehi (DisasContext *ctx)
6279
if (unlikely(!ctx->spe_enabled)) {
6280
GEN_EXCP_NO_AP(ctx);
6283
#if defined(TARGET_PPC64)
6284
TCGv t0 = tcg_temp_new(TCG_TYPE_TL);
6285
TCGv t1 = tcg_temp_new(TCG_TYPE_TL);
6286
tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 32);
6287
tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], 0xFFFFFFFF0000000ULL);
6288
tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1);
6292
tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
6293
tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
6296
GEN_SPEOP_ARITH2(evaddw, tcg_gen_add_i32);
6297
static always_inline void gen_op_evsubf (TCGv ret, TCGv arg1, TCGv arg2)
6299
tcg_gen_sub_i32(ret, arg2, arg1);
6301
GEN_SPEOP_ARITH2(evsubfw, gen_op_evsubf);
6303
/* SPE arithmetic immediate */
6304
#if defined(TARGET_PPC64)
6305
#define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \
6306
static always_inline void gen_##name (DisasContext *ctx) \
6308
if (unlikely(!ctx->spe_enabled)) { \
6309
GEN_EXCP_NO_AP(ctx); \
6312
TCGv t0 = tcg_temp_local_new(TCG_TYPE_I32); \
6313
TCGv t1 = tcg_temp_local_new(TCG_TYPE_I32); \
6314
TCGv t2 = tcg_temp_local_new(TCG_TYPE_I64); \
6315
tcg_gen_trunc_i64_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
6316
tcg_op(t0, t0, rA(ctx->opcode)); \
6317
tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32); \
6318
tcg_gen_trunc_i64_i32(t1, t2); \
6319
tcg_temp_free(t2); \
6320
tcg_op(t1, t1, rA(ctx->opcode)); \
6321
tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
6322
tcg_temp_free(t0); \
6323
tcg_temp_free(t1); \
6326
#define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \
6327
static always_inline void gen_##name (DisasContext *ctx) \
6329
if (unlikely(!ctx->spe_enabled)) { \
6330
GEN_EXCP_NO_AP(ctx); \
6333
tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
6335
tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)], \
6339
GEN_SPEOP_ARITH_IMM2(evaddiw, tcg_gen_addi_i32);
6340
GEN_SPEOP_ARITH_IMM2(evsubifw, tcg_gen_subi_i32);
6342
/* SPE comparison */
6343
#if defined(TARGET_PPC64)
6344
#define GEN_SPEOP_COMP(name, tcg_cond) \
6345
static always_inline void gen_##name (DisasContext *ctx) \
6347
if (unlikely(!ctx->spe_enabled)) { \
6348
GEN_EXCP_NO_AP(ctx); \
6351
int l1 = gen_new_label(); \
6352
int l2 = gen_new_label(); \
6353
int l3 = gen_new_label(); \
6354
int l4 = gen_new_label(); \
6355
TCGv t0 = tcg_temp_local_new(TCG_TYPE_I32); \
6356
TCGv t1 = tcg_temp_local_new(TCG_TYPE_I32); \
6357
TCGv t2 = tcg_temp_local_new(TCG_TYPE_I64); \
6358
tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
6359
tcg_gen_trunc_i64_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
6360
tcg_gen_brcond_i32(tcg_cond, t0, t1, l1); \
6361
tcg_gen_movi_tl(cpu_crf[crfD(ctx->opcode)], 0); \
6363
gen_set_label(l1); \
6364
tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \
6365
CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \
6366
gen_set_label(l2); \
6367
tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
6368
tcg_gen_trunc_i64_i32(t0, t2); \
6369
tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32); \
6370
tcg_gen_trunc_i64_i32(t1, t2); \
6371
tcg_temp_free(t2); \
6372
tcg_gen_brcond_i32(tcg_cond, t0, t1, l3); \
6373
tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
6374
~(CRF_CH | CRF_CH_AND_CL)); \
6376
gen_set_label(l3); \
6377
tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
6378
CRF_CH | CRF_CH_OR_CL); \
6379
gen_set_label(l4); \
6380
tcg_temp_free(t0); \
6381
tcg_temp_free(t1); \
6384
#define GEN_SPEOP_COMP(name, tcg_cond) \
6385
static always_inline void gen_##name (DisasContext *ctx) \
6387
if (unlikely(!ctx->spe_enabled)) { \
6388
GEN_EXCP_NO_AP(ctx); \
6391
int l1 = gen_new_label(); \
6392
int l2 = gen_new_label(); \
6393
int l3 = gen_new_label(); \
6394
int l4 = gen_new_label(); \
6396
tcg_gen_brcond_i32(tcg_cond, cpu_gpr[rA(ctx->opcode)], \
6397
cpu_gpr[rB(ctx->opcode)], l1); \
6398
tcg_gen_movi_tl(cpu_crf[crfD(ctx->opcode)], 0); \
6400
gen_set_label(l1); \
6401
tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \
6402
CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \
6403
gen_set_label(l2); \
6404
tcg_gen_brcond_i32(tcg_cond, cpu_gprh[rA(ctx->opcode)], \
6405
cpu_gprh[rB(ctx->opcode)], l3); \
6406
tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
6407
~(CRF_CH | CRF_CH_AND_CL)); \
6409
gen_set_label(l3); \
6410
tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
6411
CRF_CH | CRF_CH_OR_CL); \
6412
gen_set_label(l4); \
6415
GEN_SPEOP_COMP(evcmpgtu, TCG_COND_GTU);
6416
GEN_SPEOP_COMP(evcmpgts, TCG_COND_GT);
6417
GEN_SPEOP_COMP(evcmpltu, TCG_COND_LTU);
6418
GEN_SPEOP_COMP(evcmplts, TCG_COND_LT);
6419
GEN_SPEOP_COMP(evcmpeq, TCG_COND_EQ);
5907
/* SPE arithmetic and logic */
5908
#define GEN_SPEOP_ARITH2(name) \
5909
static always_inline void gen_##name (DisasContext *ctx) \
5911
if (unlikely(!ctx->spe_enabled)) { \
5912
GEN_EXCP_NO_AP(ctx); \
5915
gen_op_load_gpr64_T0(rA(ctx->opcode)); \
5916
gen_op_load_gpr64_T1(rB(ctx->opcode)); \
5918
gen_op_store_T0_gpr64(rD(ctx->opcode)); \
5921
#define GEN_SPEOP_ARITH1(name) \
5922
static always_inline void gen_##name (DisasContext *ctx) \
5924
if (unlikely(!ctx->spe_enabled)) { \
5925
GEN_EXCP_NO_AP(ctx); \
5928
gen_op_load_gpr64_T0(rA(ctx->opcode)); \
5930
gen_op_store_T0_gpr64(rD(ctx->opcode)); \
5933
#define GEN_SPEOP_COMP(name) \
5934
static always_inline void gen_##name (DisasContext *ctx) \
5936
if (unlikely(!ctx->spe_enabled)) { \
5937
GEN_EXCP_NO_AP(ctx); \
5940
gen_op_load_gpr64_T0(rA(ctx->opcode)); \
5941
gen_op_load_gpr64_T1(rB(ctx->opcode)); \
5943
gen_op_store_T0_crf(crfD(ctx->opcode)); \
5947
GEN_SPEOP_ARITH2(evand);
5948
GEN_SPEOP_ARITH2(evandc);
5949
GEN_SPEOP_ARITH2(evxor);
5950
GEN_SPEOP_ARITH2(evor);
5951
GEN_SPEOP_ARITH2(evnor);
5952
GEN_SPEOP_ARITH2(eveqv);
5953
GEN_SPEOP_ARITH2(evorc);
5954
GEN_SPEOP_ARITH2(evnand);
5955
GEN_SPEOP_ARITH2(evsrwu);
5956
GEN_SPEOP_ARITH2(evsrws);
5957
GEN_SPEOP_ARITH2(evslw);
5958
GEN_SPEOP_ARITH2(evrlw);
5959
GEN_SPEOP_ARITH2(evmergehi);
5960
GEN_SPEOP_ARITH2(evmergelo);
5961
GEN_SPEOP_ARITH2(evmergehilo);
5962
GEN_SPEOP_ARITH2(evmergelohi);
5965
GEN_SPEOP_ARITH2(evaddw);
5966
GEN_SPEOP_ARITH2(evsubfw);
5967
GEN_SPEOP_ARITH1(evabs);
5968
GEN_SPEOP_ARITH1(evneg);
5969
GEN_SPEOP_ARITH1(evextsb);
5970
GEN_SPEOP_ARITH1(evextsh);
5971
GEN_SPEOP_ARITH1(evrndw);
5972
GEN_SPEOP_ARITH1(evcntlzw);
5973
GEN_SPEOP_ARITH1(evcntlsw);
6422
5974
static always_inline void gen_brinc (DisasContext *ctx)
6424
5976
/* Note: brinc is usable even if SPE is disabled */
6425
tcg_gen_helper_1_2(helper_brinc, cpu_gpr[rD(ctx->opcode)],
6426
cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
6428
static always_inline void gen_evmergelo (DisasContext *ctx)
6430
if (unlikely(!ctx->spe_enabled)) {
6431
GEN_EXCP_NO_AP(ctx);
6434
#if defined(TARGET_PPC64)
6435
TCGv t0 = tcg_temp_new(TCG_TYPE_TL);
6436
TCGv t1 = tcg_temp_new(TCG_TYPE_TL);
6437
tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x00000000FFFFFFFFLL);
6438
tcg_gen_shli_tl(t1, cpu_gpr[rA(ctx->opcode)], 32);
6439
tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1);
6443
tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
6444
tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
6447
static always_inline void gen_evmergehilo (DisasContext *ctx)
6449
if (unlikely(!ctx->spe_enabled)) {
6450
GEN_EXCP_NO_AP(ctx);
6453
#if defined(TARGET_PPC64)
6454
TCGv t0 = tcg_temp_new(TCG_TYPE_TL);
6455
TCGv t1 = tcg_temp_new(TCG_TYPE_TL);
6456
tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x00000000FFFFFFFFLL);
6457
tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], 0xFFFFFFFF0000000ULL);
6458
tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1);
6462
tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
6463
tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
6466
static always_inline void gen_evmergelohi (DisasContext *ctx)
6468
if (unlikely(!ctx->spe_enabled)) {
6469
GEN_EXCP_NO_AP(ctx);
6472
#if defined(TARGET_PPC64)
6473
TCGv t0 = tcg_temp_new(TCG_TYPE_TL);
6474
TCGv t1 = tcg_temp_new(TCG_TYPE_TL);
6475
tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 32);
6476
tcg_gen_shli_tl(t1, cpu_gpr[rA(ctx->opcode)], 32);
6477
tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1);
6481
tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
6482
tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5977
gen_op_load_gpr64_T0(rA(ctx->opcode));
5978
gen_op_load_gpr64_T1(rB(ctx->opcode));
5980
gen_op_store_T0_gpr64(rD(ctx->opcode));
5983
#define GEN_SPEOP_ARITH_IMM2(name) \
5984
static always_inline void gen_##name##i (DisasContext *ctx) \
5986
if (unlikely(!ctx->spe_enabled)) { \
5987
GEN_EXCP_NO_AP(ctx); \
5990
gen_op_load_gpr64_T0(rB(ctx->opcode)); \
5991
gen_op_splatwi_T1_64(rA(ctx->opcode)); \
5993
gen_op_store_T0_gpr64(rD(ctx->opcode)); \
5996
#define GEN_SPEOP_LOGIC_IMM2(name) \
5997
static always_inline void gen_##name##i (DisasContext *ctx) \
5999
if (unlikely(!ctx->spe_enabled)) { \
6000
GEN_EXCP_NO_AP(ctx); \
6003
gen_op_load_gpr64_T0(rA(ctx->opcode)); \
6004
gen_op_splatwi_T1_64(rB(ctx->opcode)); \
6006
gen_op_store_T0_gpr64(rD(ctx->opcode)); \
6009
GEN_SPEOP_ARITH_IMM2(evaddw);
6010
#define gen_evaddiw gen_evaddwi
6011
GEN_SPEOP_ARITH_IMM2(evsubfw);
6012
#define gen_evsubifw gen_evsubfwi
6013
GEN_SPEOP_LOGIC_IMM2(evslw);
6014
GEN_SPEOP_LOGIC_IMM2(evsrwu);
6015
#define gen_evsrwis gen_evsrwsi
6016
GEN_SPEOP_LOGIC_IMM2(evsrws);
6017
#define gen_evsrwiu gen_evsrwui
6018
GEN_SPEOP_LOGIC_IMM2(evrlw);
6485
6020
static always_inline void gen_evsplati (DisasContext *ctx)
6487
int32_t imm = (int32_t)(rA(ctx->opcode) << 11) >> 27;
6022
int32_t imm = (int32_t)(rA(ctx->opcode) << 27) >> 27;
6489
#if defined(TARGET_PPC64)
6490
TCGv t0 = tcg_temp_new(TCG_TYPE_TL);
6491
TCGv t1 = tcg_temp_new(TCG_TYPE_TL);
6492
tcg_gen_movi_tl(t0, imm);
6493
tcg_gen_shri_tl(t1, t0, 32);
6494
tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1);
6498
tcg_gen_movi_i32(cpu_gpr[rD(ctx->opcode)], imm);
6499
tcg_gen_movi_i32(cpu_gprh[rD(ctx->opcode)], imm);
6024
gen_op_splatwi_T0_64(imm);
6025
gen_op_store_T0_gpr64(rD(ctx->opcode));
6502
6028
static always_inline void gen_evsplatfi (DisasContext *ctx)
6504
uint32_t imm = rA(ctx->opcode) << 11;
6506
#if defined(TARGET_PPC64)
6507
TCGv t0 = tcg_temp_new(TCG_TYPE_TL);
6508
TCGv t1 = tcg_temp_new(TCG_TYPE_TL);
6509
tcg_gen_movi_tl(t0, imm);
6510
tcg_gen_shri_tl(t1, t0, 32);
6511
tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1);
6515
tcg_gen_movi_i32(cpu_gpr[rD(ctx->opcode)], imm);
6516
tcg_gen_movi_i32(cpu_gprh[rD(ctx->opcode)], imm);
6520
static always_inline void gen_evsel (DisasContext *ctx)
6522
int l1 = gen_new_label();
6523
int l2 = gen_new_label();
6524
int l3 = gen_new_label();
6525
int l4 = gen_new_label();
6526
TCGv t0 = tcg_temp_local_new(TCG_TYPE_I32);
6527
#if defined(TARGET_PPC64)
6528
TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
6529
TCGv t2 = tcg_temp_local_new(TCG_TYPE_TL);
6531
tcg_gen_andi_i32(t0, cpu_crf[ctx->opcode & 0x07], 1 << 3);
6532
tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1);
6533
#if defined(TARGET_PPC64)
6534
tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], 0xFFFFFFFF00000000ULL);
6536
tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
6540
#if defined(TARGET_PPC64)
6541
tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0xFFFFFFFF00000000ULL);
6543
tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
6546
tcg_gen_andi_i32(t0, cpu_crf[ctx->opcode & 0x07], 1 << 2);
6547
tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l3);
6548
#if defined(TARGET_PPC64)
6549
tcg_gen_andi_tl(t2, cpu_gpr[rA(ctx->opcode)], 0x00000000FFFFFFFFULL);
6551
tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
6555
#if defined(TARGET_PPC64)
6556
tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x00000000FFFFFFFFULL);
6558
tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
6562
#if defined(TARGET_PPC64)
6563
tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t1, t2);
6568
GEN_HANDLER2(evsel0, "evsel", 0x04, 0x1c, 0x09, 0x00000000, PPC_SPE)
6572
GEN_HANDLER2(evsel1, "evsel", 0x04, 0x1d, 0x09, 0x00000000, PPC_SPE)
6576
GEN_HANDLER2(evsel2, "evsel", 0x04, 0x1e, 0x09, 0x00000000, PPC_SPE)
6580
GEN_HANDLER2(evsel3, "evsel", 0x04, 0x1f, 0x09, 0x00000000, PPC_SPE)
6030
uint32_t imm = rA(ctx->opcode) << 27;
6032
gen_op_splatwi_T0_64(imm);
6033
gen_op_store_T0_gpr64(rD(ctx->opcode));
6037
GEN_SPEOP_COMP(evcmpgtu);
6038
GEN_SPEOP_COMP(evcmpgts);
6039
GEN_SPEOP_COMP(evcmpltu);
6040
GEN_SPEOP_COMP(evcmplts);
6041
GEN_SPEOP_COMP(evcmpeq);
6585
6043
GEN_SPE(evaddw, speundef, 0x00, 0x08, 0x00000000, PPC_SPE); ////
6586
6044
GEN_SPE(evaddiw, speundef, 0x01, 0x08, 0x00000000, PPC_SPE);
6703
6240
GEN_SPE_LDSPLAT(hhossplat, spe_lhx, le_64_raw);
6243
GEN_OP_SPE_LHE(kernel);
6706
6244
GEN_OP_SPE_LHE(user);
6707
GEN_OP_SPE_LHE(kernel);
6708
GEN_OP_SPE_LHE(hypv);
6245
GEN_SPE_LDSPLAT(hhesplat, spe_lhe, kernel);
6709
6246
GEN_SPE_LDSPLAT(hhesplat, spe_lhe, user);
6710
GEN_SPE_LDSPLAT(hhesplat, spe_lhe, kernel);
6711
GEN_SPE_LDSPLAT(hhesplat, spe_lhe, hypv);
6247
GEN_OP_SPE_LHE(le_kernel);
6712
6248
GEN_OP_SPE_LHE(le_user);
6713
GEN_OP_SPE_LHE(le_kernel);
6714
GEN_OP_SPE_LHE(le_hypv);
6249
GEN_SPE_LDSPLAT(hhesplat, spe_lhe, le_kernel);
6715
6250
GEN_SPE_LDSPLAT(hhesplat, spe_lhe, le_user);
6716
GEN_SPE_LDSPLAT(hhesplat, spe_lhe, le_kernel);
6717
GEN_SPE_LDSPLAT(hhesplat, spe_lhe, le_hypv);
6251
GEN_SPE_LDSPLAT(hhousplat, spe_lh, kernel);
6718
6252
GEN_SPE_LDSPLAT(hhousplat, spe_lh, user);
6719
GEN_SPE_LDSPLAT(hhousplat, spe_lh, kernel);
6720
GEN_SPE_LDSPLAT(hhousplat, spe_lh, hypv);
6253
GEN_SPE_LDSPLAT(hhousplat, spe_lh, le_kernel);
6721
6254
GEN_SPE_LDSPLAT(hhousplat, spe_lh, le_user);
6722
GEN_SPE_LDSPLAT(hhousplat, spe_lh, le_kernel);
6723
GEN_SPE_LDSPLAT(hhousplat, spe_lh, le_hypv);
6255
GEN_OP_SPE_LHX(kernel);
6724
6256
GEN_OP_SPE_LHX(user);
6725
GEN_OP_SPE_LHX(kernel);
6726
GEN_OP_SPE_LHX(hypv);
6257
GEN_SPE_LDSPLAT(hhossplat, spe_lhx, kernel);
6727
6258
GEN_SPE_LDSPLAT(hhossplat, spe_lhx, user);
6728
GEN_SPE_LDSPLAT(hhossplat, spe_lhx, kernel);
6729
GEN_SPE_LDSPLAT(hhossplat, spe_lhx, hypv);
6259
GEN_OP_SPE_LHX(le_kernel);
6730
6260
GEN_OP_SPE_LHX(le_user);
6731
GEN_OP_SPE_LHX(le_kernel);
6732
GEN_OP_SPE_LHX(le_hypv);
6261
GEN_SPE_LDSPLAT(hhossplat, spe_lhx, le_kernel);
6733
6262
GEN_SPE_LDSPLAT(hhossplat, spe_lhx, le_user);
6734
GEN_SPE_LDSPLAT(hhossplat, spe_lhx, le_kernel);
6735
GEN_SPE_LDSPLAT(hhossplat, spe_lhx, le_hypv);
6736
6263
#if defined(TARGET_PPC64)
6264
GEN_OP_SPE_LHE(64_kernel);
6737
6265
GEN_OP_SPE_LHE(64_user);
6738
GEN_OP_SPE_LHE(64_kernel);
6739
GEN_OP_SPE_LHE(64_hypv);
6266
GEN_SPE_LDSPLAT(hhesplat, spe_lhe, 64_kernel);
6740
6267
GEN_SPE_LDSPLAT(hhesplat, spe_lhe, 64_user);
6741
GEN_SPE_LDSPLAT(hhesplat, spe_lhe, 64_kernel);
6742
GEN_SPE_LDSPLAT(hhesplat, spe_lhe, 64_hypv);
6268
GEN_OP_SPE_LHE(le_64_kernel);
6743
6269
GEN_OP_SPE_LHE(le_64_user);
6744
GEN_OP_SPE_LHE(le_64_kernel);
6745
GEN_OP_SPE_LHE(le_64_hypv);
6270
GEN_SPE_LDSPLAT(hhesplat, spe_lhe, le_64_kernel);
6746
6271
GEN_SPE_LDSPLAT(hhesplat, spe_lhe, le_64_user);
6747
GEN_SPE_LDSPLAT(hhesplat, spe_lhe, le_64_kernel);
6748
GEN_SPE_LDSPLAT(hhesplat, spe_lhe, le_64_hypv);
6272
GEN_SPE_LDSPLAT(hhousplat, spe_lh, 64_kernel);
6749
6273
GEN_SPE_LDSPLAT(hhousplat, spe_lh, 64_user);
6750
GEN_SPE_LDSPLAT(hhousplat, spe_lh, 64_kernel);
6751
GEN_SPE_LDSPLAT(hhousplat, spe_lh, 64_hypv);
6274
GEN_SPE_LDSPLAT(hhousplat, spe_lh, le_64_kernel);
6752
6275
GEN_SPE_LDSPLAT(hhousplat, spe_lh, le_64_user);
6753
GEN_SPE_LDSPLAT(hhousplat, spe_lh, le_64_kernel);
6754
GEN_SPE_LDSPLAT(hhousplat, spe_lh, le_64_hypv);
6276
GEN_OP_SPE_LHX(64_kernel);
6755
6277
GEN_OP_SPE_LHX(64_user);
6756
GEN_OP_SPE_LHX(64_kernel);
6757
GEN_OP_SPE_LHX(64_hypv);
6278
GEN_SPE_LDSPLAT(hhossplat, spe_lhx, 64_kernel);
6758
6279
GEN_SPE_LDSPLAT(hhossplat, spe_lhx, 64_user);
6759
GEN_SPE_LDSPLAT(hhossplat, spe_lhx, 64_kernel);
6760
GEN_SPE_LDSPLAT(hhossplat, spe_lhx, 64_hypv);
6280
GEN_OP_SPE_LHX(le_64_kernel);
6761
6281
GEN_OP_SPE_LHX(le_64_user);
6762
GEN_OP_SPE_LHX(le_64_kernel);
6763
GEN_OP_SPE_LHX(le_64_hypv);
6282
GEN_SPE_LDSPLAT(hhossplat, spe_lhx, le_64_kernel);
6764
6283
GEN_SPE_LDSPLAT(hhossplat, spe_lhx, le_64_user);
6765
GEN_SPE_LDSPLAT(hhossplat, spe_lhx, le_64_kernel);
6766
GEN_SPE_LDSPLAT(hhossplat, spe_lhx, le_64_hypv);
6769
6286
GEN_SPEOP_LD(hhesplat, 1);