1fcf5ef2aSThomas Huth /*
2fcf5ef2aSThomas Huth * TriCore emulation for qemu: main translation routines.
3fcf5ef2aSThomas Huth *
4fcf5ef2aSThomas Huth * Copyright (c) 2013-2014 Bastian Koppelmann C-Lab/University Paderborn
5fcf5ef2aSThomas Huth *
6fcf5ef2aSThomas Huth * This library is free software; you can redistribute it and/or
7fcf5ef2aSThomas Huth * modify it under the terms of the GNU Lesser General Public
8fcf5ef2aSThomas Huth * License as published by the Free Software Foundation; either
902754acdSThomas Huth * version 2.1 of the License, or (at your option) any later version.
10fcf5ef2aSThomas Huth *
11fcf5ef2aSThomas Huth * This library is distributed in the hope that it will be useful,
12fcf5ef2aSThomas Huth * but WITHOUT ANY WARRANTY; without even the implied warranty of
13fcf5ef2aSThomas Huth * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14fcf5ef2aSThomas Huth * Lesser General Public License for more details.
15fcf5ef2aSThomas Huth *
16fcf5ef2aSThomas Huth * You should have received a copy of the GNU Lesser General Public
17fcf5ef2aSThomas Huth * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18fcf5ef2aSThomas Huth */
19fcf5ef2aSThomas Huth
20fcf5ef2aSThomas Huth
21fcf5ef2aSThomas Huth #include "qemu/osdep.h"
22fcf5ef2aSThomas Huth #include "cpu.h"
23fcf5ef2aSThomas Huth #include "exec/exec-all.h"
24dcb32f1dSPhilippe Mathieu-Daudé #include "tcg/tcg-op.h"
25fcf5ef2aSThomas Huth #include "exec/cpu_ldst.h"
2690c84c56SMarkus Armbruster #include "qemu/qemu-print.h"
27fcf5ef2aSThomas Huth
28fcf5ef2aSThomas Huth #include "exec/helper-proto.h"
29fcf5ef2aSThomas Huth #include "exec/helper-gen.h"
30fcf5ef2aSThomas Huth
31fcf5ef2aSThomas Huth #include "tricore-opcodes.h"
326b9f5a42SBastian Koppelmann #include "exec/translator.h"
33fcf5ef2aSThomas Huth #include "exec/log.h"
34fcf5ef2aSThomas Huth
35d53106c9SRichard Henderson #define HELPER_H "helper.h"
36d53106c9SRichard Henderson #include "exec/helper-info.c.inc"
37d53106c9SRichard Henderson #undef HELPER_H
38d53106c9SRichard Henderson
391706e04fSBastian Koppelmann #define DISAS_EXIT DISAS_TARGET_0
402dbd73bfSBastian Koppelmann #define DISAS_EXIT_UPDATE DISAS_TARGET_1
41d8f466afSBastian Koppelmann #define DISAS_JUMP DISAS_TARGET_2
42d53106c9SRichard Henderson
43fcf5ef2aSThomas Huth /*
44fcf5ef2aSThomas Huth * TCG registers
45fcf5ef2aSThomas Huth */
46fcf5ef2aSThomas Huth static TCGv cpu_PC;
47fcf5ef2aSThomas Huth static TCGv cpu_PCXI;
48fcf5ef2aSThomas Huth static TCGv cpu_PSW;
49fcf5ef2aSThomas Huth static TCGv cpu_ICR;
50fcf5ef2aSThomas Huth /* GPR registers */
51fcf5ef2aSThomas Huth static TCGv cpu_gpr_a[16];
52fcf5ef2aSThomas Huth static TCGv cpu_gpr_d[16];
53fcf5ef2aSThomas Huth /* PSW Flag cache */
54fcf5ef2aSThomas Huth static TCGv cpu_PSW_C;
55fcf5ef2aSThomas Huth static TCGv cpu_PSW_V;
56fcf5ef2aSThomas Huth static TCGv cpu_PSW_SV;
57fcf5ef2aSThomas Huth static TCGv cpu_PSW_AV;
58fcf5ef2aSThomas Huth static TCGv cpu_PSW_SAV;
59fcf5ef2aSThomas Huth
60fcf5ef2aSThomas Huth static const char *regnames_a[] = {
61fcf5ef2aSThomas Huth "a0" , "a1" , "a2" , "a3" , "a4" , "a5" ,
62fcf5ef2aSThomas Huth "a6" , "a7" , "a8" , "a9" , "sp" , "a11" ,
63fcf5ef2aSThomas Huth "a12" , "a13" , "a14" , "a15",
64fcf5ef2aSThomas Huth };
65fcf5ef2aSThomas Huth
66fcf5ef2aSThomas Huth static const char *regnames_d[] = {
67fcf5ef2aSThomas Huth "d0" , "d1" , "d2" , "d3" , "d4" , "d5" ,
68fcf5ef2aSThomas Huth "d6" , "d7" , "d8" , "d9" , "d10" , "d11" ,
69fcf5ef2aSThomas Huth "d12" , "d13" , "d14" , "d15",
70fcf5ef2aSThomas Huth };
71fcf5ef2aSThomas Huth
72fcf5ef2aSThomas Huth typedef struct DisasContext {
736b9f5a42SBastian Koppelmann DisasContextBase base;
746b9f5a42SBastian Koppelmann target_ulong pc_succ_insn;
75fcf5ef2aSThomas Huth uint32_t opcode;
76fcf5ef2aSThomas Huth /* Routine used to access memory */
77fcf5ef2aSThomas Huth int mem_idx;
78878d1b6aSBastian Koppelmann int priv;
7944ee3bafSBastian Koppelmann uint64_t features;
800b9f9b63SBastian Koppelmann uint32_t icr_ie_mask, icr_ie_offset;
81fcf5ef2aSThomas Huth } DisasContext;
82fcf5ef2aSThomas Huth
has_feature(DisasContext * ctx,int feature)8344ee3bafSBastian Koppelmann static int has_feature(DisasContext *ctx, int feature)
8444ee3bafSBastian Koppelmann {
8544ee3bafSBastian Koppelmann return (ctx->features & (1ULL << feature)) != 0;
8644ee3bafSBastian Koppelmann }
8744ee3bafSBastian Koppelmann
88fcf5ef2aSThomas Huth enum {
89fcf5ef2aSThomas Huth MODE_LL = 0,
90fcf5ef2aSThomas Huth MODE_LU = 1,
91fcf5ef2aSThomas Huth MODE_UL = 2,
92fcf5ef2aSThomas Huth MODE_UU = 3,
93fcf5ef2aSThomas Huth };
94fcf5ef2aSThomas Huth
tricore_cpu_dump_state(CPUState * cs,FILE * f,int flags)9590c84c56SMarkus Armbruster void tricore_cpu_dump_state(CPUState *cs, FILE *f, int flags)
96fcf5ef2aSThomas Huth {
9739ac0bacSPhilippe Mathieu-Daudé CPUTriCoreState *env = cpu_env(cs);
98fcf5ef2aSThomas Huth uint32_t psw;
99fcf5ef2aSThomas Huth int i;
100fcf5ef2aSThomas Huth
101fcf5ef2aSThomas Huth psw = psw_read(env);
102fcf5ef2aSThomas Huth
10390c84c56SMarkus Armbruster qemu_fprintf(f, "PC: " TARGET_FMT_lx, env->PC);
10490c84c56SMarkus Armbruster qemu_fprintf(f, " PSW: " TARGET_FMT_lx, psw);
10590c84c56SMarkus Armbruster qemu_fprintf(f, " ICR: " TARGET_FMT_lx, env->ICR);
10690c84c56SMarkus Armbruster qemu_fprintf(f, "\nPCXI: " TARGET_FMT_lx, env->PCXI);
10790c84c56SMarkus Armbruster qemu_fprintf(f, " FCX: " TARGET_FMT_lx, env->FCX);
10890c84c56SMarkus Armbruster qemu_fprintf(f, " LCX: " TARGET_FMT_lx, env->LCX);
109fcf5ef2aSThomas Huth
110fcf5ef2aSThomas Huth for (i = 0; i < 16; ++i) {
111fcf5ef2aSThomas Huth if ((i & 3) == 0) {
11290c84c56SMarkus Armbruster qemu_fprintf(f, "\nGPR A%02d:", i);
113fcf5ef2aSThomas Huth }
11490c84c56SMarkus Armbruster qemu_fprintf(f, " " TARGET_FMT_lx, env->gpr_a[i]);
115fcf5ef2aSThomas Huth }
116fcf5ef2aSThomas Huth for (i = 0; i < 16; ++i) {
117fcf5ef2aSThomas Huth if ((i & 3) == 0) {
11890c84c56SMarkus Armbruster qemu_fprintf(f, "\nGPR D%02d:", i);
119fcf5ef2aSThomas Huth }
12090c84c56SMarkus Armbruster qemu_fprintf(f, " " TARGET_FMT_lx, env->gpr_d[i]);
121fcf5ef2aSThomas Huth }
12290c84c56SMarkus Armbruster qemu_fprintf(f, "\n");
123fcf5ef2aSThomas Huth }
124fcf5ef2aSThomas Huth
125fcf5ef2aSThomas Huth /*
126fcf5ef2aSThomas Huth * Functions to generate micro-ops
127fcf5ef2aSThomas Huth */
128fcf5ef2aSThomas Huth
1298b81968cSMichael Tokarev /* Macros for generating helpers */
130fcf5ef2aSThomas Huth
131fcf5ef2aSThomas Huth #define gen_helper_1arg(name, arg) do { \
132151293c2SRichard Henderson TCGv_i32 helper_tmp = tcg_constant_i32(arg); \
133ad75a51eSRichard Henderson gen_helper_##name(tcg_env, helper_tmp); \
134fcf5ef2aSThomas Huth } while (0)
135fcf5ef2aSThomas Huth
136fcf5ef2aSThomas Huth #define GEN_HELPER_LL(name, ret, arg0, arg1, n) do { \
137fcf5ef2aSThomas Huth TCGv arg00 = tcg_temp_new(); \
138fcf5ef2aSThomas Huth TCGv arg01 = tcg_temp_new(); \
139fcf5ef2aSThomas Huth TCGv arg11 = tcg_temp_new(); \
140fcf5ef2aSThomas Huth tcg_gen_sari_tl(arg00, arg0, 16); \
141fcf5ef2aSThomas Huth tcg_gen_ext16s_tl(arg01, arg0); \
142fcf5ef2aSThomas Huth tcg_gen_ext16s_tl(arg11, arg1); \
143fcf5ef2aSThomas Huth gen_helper_##name(ret, arg00, arg01, arg11, arg11, n); \
144fcf5ef2aSThomas Huth } while (0)
145fcf5ef2aSThomas Huth
146fcf5ef2aSThomas Huth #define GEN_HELPER_LU(name, ret, arg0, arg1, n) do { \
147fcf5ef2aSThomas Huth TCGv arg00 = tcg_temp_new(); \
148fcf5ef2aSThomas Huth TCGv arg01 = tcg_temp_new(); \
149fcf5ef2aSThomas Huth TCGv arg10 = tcg_temp_new(); \
150fcf5ef2aSThomas Huth TCGv arg11 = tcg_temp_new(); \
151fcf5ef2aSThomas Huth tcg_gen_sari_tl(arg00, arg0, 16); \
152fcf5ef2aSThomas Huth tcg_gen_ext16s_tl(arg01, arg0); \
153fcf5ef2aSThomas Huth tcg_gen_sari_tl(arg11, arg1, 16); \
154fcf5ef2aSThomas Huth tcg_gen_ext16s_tl(arg10, arg1); \
155fcf5ef2aSThomas Huth gen_helper_##name(ret, arg00, arg01, arg10, arg11, n); \
156fcf5ef2aSThomas Huth } while (0)
157fcf5ef2aSThomas Huth
158fcf5ef2aSThomas Huth #define GEN_HELPER_UL(name, ret, arg0, arg1, n) do { \
159fcf5ef2aSThomas Huth TCGv arg00 = tcg_temp_new(); \
160fcf5ef2aSThomas Huth TCGv arg01 = tcg_temp_new(); \
161fcf5ef2aSThomas Huth TCGv arg10 = tcg_temp_new(); \
162fcf5ef2aSThomas Huth TCGv arg11 = tcg_temp_new(); \
163fcf5ef2aSThomas Huth tcg_gen_sari_tl(arg00, arg0, 16); \
164fcf5ef2aSThomas Huth tcg_gen_ext16s_tl(arg01, arg0); \
165fcf5ef2aSThomas Huth tcg_gen_sari_tl(arg10, arg1, 16); \
166fcf5ef2aSThomas Huth tcg_gen_ext16s_tl(arg11, arg1); \
167fcf5ef2aSThomas Huth gen_helper_##name(ret, arg00, arg01, arg10, arg11, n); \
168fcf5ef2aSThomas Huth } while (0)
169fcf5ef2aSThomas Huth
170fcf5ef2aSThomas Huth #define GEN_HELPER_UU(name, ret, arg0, arg1, n) do { \
171fcf5ef2aSThomas Huth TCGv arg00 = tcg_temp_new(); \
172fcf5ef2aSThomas Huth TCGv arg01 = tcg_temp_new(); \
173fcf5ef2aSThomas Huth TCGv arg11 = tcg_temp_new(); \
174fcf5ef2aSThomas Huth tcg_gen_sari_tl(arg01, arg0, 16); \
175fcf5ef2aSThomas Huth tcg_gen_ext16s_tl(arg00, arg0); \
176fcf5ef2aSThomas Huth tcg_gen_sari_tl(arg11, arg1, 16); \
177fcf5ef2aSThomas Huth gen_helper_##name(ret, arg00, arg01, arg11, arg11, n); \
178fcf5ef2aSThomas Huth } while (0)
179fcf5ef2aSThomas Huth
180fcf5ef2aSThomas Huth #define GEN_HELPER_RRR(name, rl, rh, al1, ah1, arg2) do { \
181fcf5ef2aSThomas Huth TCGv_i64 ret = tcg_temp_new_i64(); \
182fcf5ef2aSThomas Huth TCGv_i64 arg1 = tcg_temp_new_i64(); \
183fcf5ef2aSThomas Huth \
184fcf5ef2aSThomas Huth tcg_gen_concat_i32_i64(arg1, al1, ah1); \
185fcf5ef2aSThomas Huth gen_helper_##name(ret, arg1, arg2); \
186fcf5ef2aSThomas Huth tcg_gen_extr_i64_i32(rl, rh, ret); \
187fcf5ef2aSThomas Huth } while (0)
188fcf5ef2aSThomas Huth
189fcf5ef2aSThomas Huth #define GEN_HELPER_RR(name, rl, rh, arg1, arg2) do { \
190fcf5ef2aSThomas Huth TCGv_i64 ret = tcg_temp_new_i64(); \
191fcf5ef2aSThomas Huth \
192ad75a51eSRichard Henderson gen_helper_##name(ret, tcg_env, arg1, arg2); \
193fcf5ef2aSThomas Huth tcg_gen_extr_i64_i32(rl, rh, ret); \
194fcf5ef2aSThomas Huth } while (0)
195fcf5ef2aSThomas Huth
196fcf5ef2aSThomas Huth #define EA_ABS_FORMAT(con) (((con & 0x3C000) << 14) + (con & 0x3FFF))
197fcf5ef2aSThomas Huth #define EA_B_ABSOLUT(con) (((offset & 0xf00000) << 8) | \
198fcf5ef2aSThomas Huth ((offset & 0x0fffff) << 1))
199fcf5ef2aSThomas Huth
200fcf5ef2aSThomas Huth /* For two 32-bit registers used a 64-bit register, the first
201fcf5ef2aSThomas Huth registernumber needs to be even. Otherwise we trap. */
202fcf5ef2aSThomas Huth static inline void generate_trap(DisasContext *ctx, int class, int tin);
203fcf5ef2aSThomas Huth #define CHECK_REG_PAIR(reg) do { \
204fcf5ef2aSThomas Huth if (reg & 0x1) { \
205fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_OPD); \
206fcf5ef2aSThomas Huth } \
207fcf5ef2aSThomas Huth } while (0)
208fcf5ef2aSThomas Huth
209fcf5ef2aSThomas Huth /* Functions for load/save to/from memory */
210fcf5ef2aSThomas Huth
gen_offset_ld(DisasContext * ctx,TCGv r1,TCGv r2,int16_t con,MemOp mop)211fcf5ef2aSThomas Huth static inline void gen_offset_ld(DisasContext *ctx, TCGv r1, TCGv r2,
21214776ab5STony Nguyen int16_t con, MemOp mop)
213fcf5ef2aSThomas Huth {
214fcf5ef2aSThomas Huth TCGv temp = tcg_temp_new();
215fcf5ef2aSThomas Huth tcg_gen_addi_tl(temp, r2, con);
216fcf5ef2aSThomas Huth tcg_gen_qemu_ld_tl(r1, temp, ctx->mem_idx, mop);
217fcf5ef2aSThomas Huth }
218fcf5ef2aSThomas Huth
gen_offset_st(DisasContext * ctx,TCGv r1,TCGv r2,int16_t con,MemOp mop)219fcf5ef2aSThomas Huth static inline void gen_offset_st(DisasContext *ctx, TCGv r1, TCGv r2,
22014776ab5STony Nguyen int16_t con, MemOp mop)
221fcf5ef2aSThomas Huth {
222fcf5ef2aSThomas Huth TCGv temp = tcg_temp_new();
223fcf5ef2aSThomas Huth tcg_gen_addi_tl(temp, r2, con);
224fcf5ef2aSThomas Huth tcg_gen_qemu_st_tl(r1, temp, ctx->mem_idx, mop);
225fcf5ef2aSThomas Huth }
226fcf5ef2aSThomas Huth
gen_st_2regs_64(TCGv rh,TCGv rl,TCGv address,DisasContext * ctx)227fcf5ef2aSThomas Huth static void gen_st_2regs_64(TCGv rh, TCGv rl, TCGv address, DisasContext *ctx)
228fcf5ef2aSThomas Huth {
229fcf5ef2aSThomas Huth TCGv_i64 temp = tcg_temp_new_i64();
230fcf5ef2aSThomas Huth
231fcf5ef2aSThomas Huth tcg_gen_concat_i32_i64(temp, rl, rh);
232fc313c64SFrédéric Pétrot tcg_gen_qemu_st_i64(temp, address, ctx->mem_idx, MO_LEUQ);
233fcf5ef2aSThomas Huth }
234fcf5ef2aSThomas Huth
gen_offset_st_2regs(TCGv rh,TCGv rl,TCGv base,int16_t con,DisasContext * ctx)235fcf5ef2aSThomas Huth static void gen_offset_st_2regs(TCGv rh, TCGv rl, TCGv base, int16_t con,
236fcf5ef2aSThomas Huth DisasContext *ctx)
237fcf5ef2aSThomas Huth {
238fcf5ef2aSThomas Huth TCGv temp = tcg_temp_new();
239fcf5ef2aSThomas Huth tcg_gen_addi_tl(temp, base, con);
240fcf5ef2aSThomas Huth gen_st_2regs_64(rh, rl, temp, ctx);
241fcf5ef2aSThomas Huth }
242fcf5ef2aSThomas Huth
gen_ld_2regs_64(TCGv rh,TCGv rl,TCGv address,DisasContext * ctx)243fcf5ef2aSThomas Huth static void gen_ld_2regs_64(TCGv rh, TCGv rl, TCGv address, DisasContext *ctx)
244fcf5ef2aSThomas Huth {
245fcf5ef2aSThomas Huth TCGv_i64 temp = tcg_temp_new_i64();
246fcf5ef2aSThomas Huth
247fc313c64SFrédéric Pétrot tcg_gen_qemu_ld_i64(temp, address, ctx->mem_idx, MO_LEUQ);
248fcf5ef2aSThomas Huth /* write back to two 32 bit regs */
249fcf5ef2aSThomas Huth tcg_gen_extr_i64_i32(rl, rh, temp);
250fcf5ef2aSThomas Huth }
251fcf5ef2aSThomas Huth
gen_offset_ld_2regs(TCGv rh,TCGv rl,TCGv base,int16_t con,DisasContext * ctx)252fcf5ef2aSThomas Huth static void gen_offset_ld_2regs(TCGv rh, TCGv rl, TCGv base, int16_t con,
253fcf5ef2aSThomas Huth DisasContext *ctx)
254fcf5ef2aSThomas Huth {
255fcf5ef2aSThomas Huth TCGv temp = tcg_temp_new();
256fcf5ef2aSThomas Huth tcg_gen_addi_tl(temp, base, con);
257fcf5ef2aSThomas Huth gen_ld_2regs_64(rh, rl, temp, ctx);
258fcf5ef2aSThomas Huth }
259fcf5ef2aSThomas Huth
gen_st_preincr(DisasContext * ctx,TCGv r1,TCGv r2,int16_t off,MemOp mop)260fcf5ef2aSThomas Huth static void gen_st_preincr(DisasContext *ctx, TCGv r1, TCGv r2, int16_t off,
26114776ab5STony Nguyen MemOp mop)
262fcf5ef2aSThomas Huth {
263fcf5ef2aSThomas Huth TCGv temp = tcg_temp_new();
264fcf5ef2aSThomas Huth tcg_gen_addi_tl(temp, r2, off);
265fcf5ef2aSThomas Huth tcg_gen_qemu_st_tl(r1, temp, ctx->mem_idx, mop);
266fcf5ef2aSThomas Huth tcg_gen_mov_tl(r2, temp);
267fcf5ef2aSThomas Huth }
268fcf5ef2aSThomas Huth
gen_ld_preincr(DisasContext * ctx,TCGv r1,TCGv r2,int16_t off,MemOp mop)269fcf5ef2aSThomas Huth static void gen_ld_preincr(DisasContext *ctx, TCGv r1, TCGv r2, int16_t off,
27014776ab5STony Nguyen MemOp mop)
271fcf5ef2aSThomas Huth {
272fcf5ef2aSThomas Huth TCGv temp = tcg_temp_new();
273fcf5ef2aSThomas Huth tcg_gen_addi_tl(temp, r2, off);
274fcf5ef2aSThomas Huth tcg_gen_qemu_ld_tl(r1, temp, ctx->mem_idx, mop);
275fcf5ef2aSThomas Huth tcg_gen_mov_tl(r2, temp);
276fcf5ef2aSThomas Huth }
277fcf5ef2aSThomas Huth
278fcf5ef2aSThomas Huth /* M(EA, word) = (M(EA, word) & ~E[a][63:32]) | (E[a][31:0] & E[a][63:32]); */
gen_ldmst(DisasContext * ctx,int ereg,TCGv ea)279fcf5ef2aSThomas Huth static void gen_ldmst(DisasContext *ctx, int ereg, TCGv ea)
280fcf5ef2aSThomas Huth {
281fcf5ef2aSThomas Huth TCGv temp = tcg_temp_new();
282fcf5ef2aSThomas Huth TCGv temp2 = tcg_temp_new();
283fcf5ef2aSThomas Huth
284fcf5ef2aSThomas Huth CHECK_REG_PAIR(ereg);
285fcf5ef2aSThomas Huth /* temp = (M(EA, word) */
286fcf5ef2aSThomas Huth tcg_gen_qemu_ld_tl(temp, ea, ctx->mem_idx, MO_LEUL);
287fcf5ef2aSThomas Huth /* temp = temp & ~E[a][63:32]) */
288fcf5ef2aSThomas Huth tcg_gen_andc_tl(temp, temp, cpu_gpr_d[ereg+1]);
289fcf5ef2aSThomas Huth /* temp2 = (E[a][31:0] & E[a][63:32]); */
290fcf5ef2aSThomas Huth tcg_gen_and_tl(temp2, cpu_gpr_d[ereg], cpu_gpr_d[ereg+1]);
291fcf5ef2aSThomas Huth /* temp = temp | temp2; */
292fcf5ef2aSThomas Huth tcg_gen_or_tl(temp, temp, temp2);
293fcf5ef2aSThomas Huth /* M(EA, word) = temp; */
294fcf5ef2aSThomas Huth tcg_gen_qemu_st_tl(temp, ea, ctx->mem_idx, MO_LEUL);
295fcf5ef2aSThomas Huth }
296fcf5ef2aSThomas Huth
297fcf5ef2aSThomas Huth /* tmp = M(EA, word);
298fcf5ef2aSThomas Huth M(EA, word) = D[a];
299fcf5ef2aSThomas Huth D[a] = tmp[31:0];*/
gen_swap(DisasContext * ctx,int reg,TCGv ea)300fcf5ef2aSThomas Huth static void gen_swap(DisasContext *ctx, int reg, TCGv ea)
301fcf5ef2aSThomas Huth {
302fcf5ef2aSThomas Huth TCGv temp = tcg_temp_new();
303fcf5ef2aSThomas Huth
304fcf5ef2aSThomas Huth tcg_gen_qemu_ld_tl(temp, ea, ctx->mem_idx, MO_LEUL);
305fcf5ef2aSThomas Huth tcg_gen_qemu_st_tl(cpu_gpr_d[reg], ea, ctx->mem_idx, MO_LEUL);
306fcf5ef2aSThomas Huth tcg_gen_mov_tl(cpu_gpr_d[reg], temp);
307fcf5ef2aSThomas Huth }
308fcf5ef2aSThomas Huth
gen_cmpswap(DisasContext * ctx,int reg,TCGv ea)309fcf5ef2aSThomas Huth static void gen_cmpswap(DisasContext *ctx, int reg, TCGv ea)
310fcf5ef2aSThomas Huth {
311fcf5ef2aSThomas Huth TCGv temp = tcg_temp_new();
312fcf5ef2aSThomas Huth TCGv temp2 = tcg_temp_new();
3136991777eSBastian Koppelmann CHECK_REG_PAIR(reg);
314fcf5ef2aSThomas Huth tcg_gen_qemu_ld_tl(temp, ea, ctx->mem_idx, MO_LEUL);
315fcf5ef2aSThomas Huth tcg_gen_movcond_tl(TCG_COND_EQ, temp2, cpu_gpr_d[reg+1], temp,
316fcf5ef2aSThomas Huth cpu_gpr_d[reg], temp);
317fcf5ef2aSThomas Huth tcg_gen_qemu_st_tl(temp2, ea, ctx->mem_idx, MO_LEUL);
318fcf5ef2aSThomas Huth tcg_gen_mov_tl(cpu_gpr_d[reg], temp);
319fcf5ef2aSThomas Huth }
320fcf5ef2aSThomas Huth
gen_swapmsk(DisasContext * ctx,int reg,TCGv ea)321fcf5ef2aSThomas Huth static void gen_swapmsk(DisasContext *ctx, int reg, TCGv ea)
322fcf5ef2aSThomas Huth {
323fcf5ef2aSThomas Huth TCGv temp = tcg_temp_new();
324fcf5ef2aSThomas Huth TCGv temp2 = tcg_temp_new();
325fcf5ef2aSThomas Huth TCGv temp3 = tcg_temp_new();
3266991777eSBastian Koppelmann CHECK_REG_PAIR(reg);
327fcf5ef2aSThomas Huth tcg_gen_qemu_ld_tl(temp, ea, ctx->mem_idx, MO_LEUL);
328fcf5ef2aSThomas Huth tcg_gen_and_tl(temp2, cpu_gpr_d[reg], cpu_gpr_d[reg+1]);
329fcf5ef2aSThomas Huth tcg_gen_andc_tl(temp3, temp, cpu_gpr_d[reg+1]);
330fcf5ef2aSThomas Huth tcg_gen_or_tl(temp2, temp2, temp3);
331fcf5ef2aSThomas Huth tcg_gen_qemu_st_tl(temp2, ea, ctx->mem_idx, MO_LEUL);
332fcf5ef2aSThomas Huth tcg_gen_mov_tl(cpu_gpr_d[reg], temp);
333fcf5ef2aSThomas Huth }
334fcf5ef2aSThomas Huth
335fcf5ef2aSThomas Huth /* We generate loads and store to core special function register (csfr) through
336fcf5ef2aSThomas Huth the function gen_mfcr and gen_mtcr. To handle access permissions, we use 3
3378b81968cSMichael Tokarev macros R, A and E, which allow read-only, all and endinit protected access.
3388b81968cSMichael Tokarev These macros also specify in which ISA version the csfr was introduced. */
339fcf5ef2aSThomas Huth #define R(ADDRESS, REG, FEATURE) \
340fcf5ef2aSThomas Huth case ADDRESS: \
34144ee3bafSBastian Koppelmann if (has_feature(ctx, FEATURE)) { \
342ad75a51eSRichard Henderson tcg_gen_ld_tl(ret, tcg_env, offsetof(CPUTriCoreState, REG)); \
343fcf5ef2aSThomas Huth } \
344fcf5ef2aSThomas Huth break;
345fcf5ef2aSThomas Huth #define A(ADDRESS, REG, FEATURE) R(ADDRESS, REG, FEATURE)
346fcf5ef2aSThomas Huth #define E(ADDRESS, REG, FEATURE) R(ADDRESS, REG, FEATURE)
gen_mfcr(DisasContext * ctx,TCGv ret,int32_t offset)3472db92a0cSBastian Koppelmann static inline void gen_mfcr(DisasContext *ctx, TCGv ret, int32_t offset)
348fcf5ef2aSThomas Huth {
349fcf5ef2aSThomas Huth /* since we're caching PSW make this a special case */
350fcf5ef2aSThomas Huth if (offset == 0xfe04) {
351ad75a51eSRichard Henderson gen_helper_psw_read(ret, tcg_env);
352fcf5ef2aSThomas Huth } else {
353fcf5ef2aSThomas Huth switch (offset) {
3545d756c82SPhilippe Mathieu-Daudé #include "csfr.h.inc"
355fcf5ef2aSThomas Huth }
356fcf5ef2aSThomas Huth }
357fcf5ef2aSThomas Huth }
358fcf5ef2aSThomas Huth #undef R
359fcf5ef2aSThomas Huth #undef A
360fcf5ef2aSThomas Huth #undef E
361fcf5ef2aSThomas Huth
362fcf5ef2aSThomas Huth #define R(ADDRESS, REG, FEATURE) /* don't gen writes to read-only reg,
3638b81968cSMichael Tokarev since no exception occurs */
364fcf5ef2aSThomas Huth #define A(ADDRESS, REG, FEATURE) R(ADDRESS, REG, FEATURE) \
365fcf5ef2aSThomas Huth case ADDRESS: \
36644ee3bafSBastian Koppelmann if (has_feature(ctx, FEATURE)) { \
367ad75a51eSRichard Henderson tcg_gen_st_tl(r1, tcg_env, offsetof(CPUTriCoreState, REG)); \
368fcf5ef2aSThomas Huth } \
369fcf5ef2aSThomas Huth break;
370fcf5ef2aSThomas Huth /* Endinit protected registers
371fcf5ef2aSThomas Huth TODO: Since the endinit bit is in a register of a not yet implemented
372fcf5ef2aSThomas Huth watchdog device, we handle endinit protected registers like
373fcf5ef2aSThomas Huth all-access registers for now. */
374fcf5ef2aSThomas Huth #define E(ADDRESS, REG, FEATURE) A(ADDRESS, REG, FEATURE)
gen_mtcr(DisasContext * ctx,TCGv r1,int32_t offset)3752db92a0cSBastian Koppelmann static inline void gen_mtcr(DisasContext *ctx, TCGv r1,
376fcf5ef2aSThomas Huth int32_t offset)
377fcf5ef2aSThomas Huth {
378878d1b6aSBastian Koppelmann if (ctx->priv == TRICORE_PRIV_SM) {
379fcf5ef2aSThomas Huth /* since we're caching PSW make this a special case */
380fcf5ef2aSThomas Huth if (offset == 0xfe04) {
381ad75a51eSRichard Henderson gen_helper_psw_write(tcg_env, r1);
38219a18eddSBastian Koppelmann ctx->base.is_jmp = DISAS_EXIT_UPDATE;
383fcf5ef2aSThomas Huth } else {
384fcf5ef2aSThomas Huth switch (offset) {
3855d756c82SPhilippe Mathieu-Daudé #include "csfr.h.inc"
386fcf5ef2aSThomas Huth }
387fcf5ef2aSThomas Huth }
388fcf5ef2aSThomas Huth } else {
38957b9c589SBastian Koppelmann generate_trap(ctx, TRAPC_PROT, TIN1_PRIV);
390fcf5ef2aSThomas Huth }
391fcf5ef2aSThomas Huth }
392fcf5ef2aSThomas Huth
393fcf5ef2aSThomas Huth /* Functions for arithmetic instructions */
394fcf5ef2aSThomas Huth
gen_add_d(TCGv ret,TCGv r1,TCGv r2)395fcf5ef2aSThomas Huth static inline void gen_add_d(TCGv ret, TCGv r1, TCGv r2)
396fcf5ef2aSThomas Huth {
397fcf5ef2aSThomas Huth TCGv t0 = tcg_temp_new_i32();
398fcf5ef2aSThomas Huth TCGv result = tcg_temp_new_i32();
399fcf5ef2aSThomas Huth /* Addition and set V/SV bits */
400fcf5ef2aSThomas Huth tcg_gen_add_tl(result, r1, r2);
401fcf5ef2aSThomas Huth /* calc V bit */
402fcf5ef2aSThomas Huth tcg_gen_xor_tl(cpu_PSW_V, result, r1);
403fcf5ef2aSThomas Huth tcg_gen_xor_tl(t0, r1, r2);
404fcf5ef2aSThomas Huth tcg_gen_andc_tl(cpu_PSW_V, cpu_PSW_V, t0);
405fcf5ef2aSThomas Huth /* Calc SV bit */
406fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SV, cpu_PSW_SV, cpu_PSW_V);
407fcf5ef2aSThomas Huth /* Calc AV/SAV bits */
408fcf5ef2aSThomas Huth tcg_gen_add_tl(cpu_PSW_AV, result, result);
409fcf5ef2aSThomas Huth tcg_gen_xor_tl(cpu_PSW_AV, result, cpu_PSW_AV);
410fcf5ef2aSThomas Huth /* calc SAV */
411fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SAV, cpu_PSW_SAV, cpu_PSW_AV);
412fcf5ef2aSThomas Huth /* write back result */
413fcf5ef2aSThomas Huth tcg_gen_mov_tl(ret, result);
414fcf5ef2aSThomas Huth }
415fcf5ef2aSThomas Huth
416fcf5ef2aSThomas Huth static inline void
gen_add64_d(TCGv_i64 ret,TCGv_i64 r1,TCGv_i64 r2)417fcf5ef2aSThomas Huth gen_add64_d(TCGv_i64 ret, TCGv_i64 r1, TCGv_i64 r2)
418fcf5ef2aSThomas Huth {
419fcf5ef2aSThomas Huth TCGv temp = tcg_temp_new();
420fcf5ef2aSThomas Huth TCGv_i64 t0 = tcg_temp_new_i64();
421fcf5ef2aSThomas Huth TCGv_i64 t1 = tcg_temp_new_i64();
422fcf5ef2aSThomas Huth TCGv_i64 result = tcg_temp_new_i64();
423fcf5ef2aSThomas Huth
424fcf5ef2aSThomas Huth tcg_gen_add_i64(result, r1, r2);
425fcf5ef2aSThomas Huth /* calc v bit */
426fcf5ef2aSThomas Huth tcg_gen_xor_i64(t1, result, r1);
427fcf5ef2aSThomas Huth tcg_gen_xor_i64(t0, r1, r2);
428fcf5ef2aSThomas Huth tcg_gen_andc_i64(t1, t1, t0);
429fcf5ef2aSThomas Huth tcg_gen_extrh_i64_i32(cpu_PSW_V, t1);
430fcf5ef2aSThomas Huth /* calc SV bit */
431fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SV, cpu_PSW_SV, cpu_PSW_V);
432fcf5ef2aSThomas Huth /* calc AV/SAV bits */
433fcf5ef2aSThomas Huth tcg_gen_extrh_i64_i32(temp, result);
434fcf5ef2aSThomas Huth tcg_gen_add_tl(cpu_PSW_AV, temp, temp);
435fcf5ef2aSThomas Huth tcg_gen_xor_tl(cpu_PSW_AV, temp, cpu_PSW_AV);
436fcf5ef2aSThomas Huth /* calc SAV */
437fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SAV, cpu_PSW_SAV, cpu_PSW_AV);
438fcf5ef2aSThomas Huth /* write back result */
439fcf5ef2aSThomas Huth tcg_gen_mov_i64(ret, result);
440fcf5ef2aSThomas Huth }
441fcf5ef2aSThomas Huth
442fcf5ef2aSThomas Huth static inline void
gen_addsub64_h(TCGv ret_low,TCGv ret_high,TCGv r1_low,TCGv r1_high,TCGv r2,TCGv r3,void (* op1)(TCGv,TCGv,TCGv),void (* op2)(TCGv,TCGv,TCGv))443fcf5ef2aSThomas Huth gen_addsub64_h(TCGv ret_low, TCGv ret_high, TCGv r1_low, TCGv r1_high, TCGv r2,
444fcf5ef2aSThomas Huth TCGv r3, void(*op1)(TCGv, TCGv, TCGv),
445fcf5ef2aSThomas Huth void(*op2)(TCGv, TCGv, TCGv))
446fcf5ef2aSThomas Huth {
447fcf5ef2aSThomas Huth TCGv temp = tcg_temp_new();
448fcf5ef2aSThomas Huth TCGv temp2 = tcg_temp_new();
449fcf5ef2aSThomas Huth TCGv temp3 = tcg_temp_new();
450fcf5ef2aSThomas Huth TCGv temp4 = tcg_temp_new();
451fcf5ef2aSThomas Huth
452fcf5ef2aSThomas Huth (*op1)(temp, r1_low, r2);
453fcf5ef2aSThomas Huth /* calc V0 bit */
454fcf5ef2aSThomas Huth tcg_gen_xor_tl(temp2, temp, r1_low);
455fcf5ef2aSThomas Huth tcg_gen_xor_tl(temp3, r1_low, r2);
456fcf5ef2aSThomas Huth if (op1 == tcg_gen_add_tl) {
457fcf5ef2aSThomas Huth tcg_gen_andc_tl(temp2, temp2, temp3);
458fcf5ef2aSThomas Huth } else {
459fcf5ef2aSThomas Huth tcg_gen_and_tl(temp2, temp2, temp3);
460fcf5ef2aSThomas Huth }
461fcf5ef2aSThomas Huth
462fcf5ef2aSThomas Huth (*op2)(temp3, r1_high, r3);
463fcf5ef2aSThomas Huth /* calc V1 bit */
464fcf5ef2aSThomas Huth tcg_gen_xor_tl(cpu_PSW_V, temp3, r1_high);
465fcf5ef2aSThomas Huth tcg_gen_xor_tl(temp4, r1_high, r3);
466fcf5ef2aSThomas Huth if (op2 == tcg_gen_add_tl) {
467fcf5ef2aSThomas Huth tcg_gen_andc_tl(cpu_PSW_V, cpu_PSW_V, temp4);
468fcf5ef2aSThomas Huth } else {
469fcf5ef2aSThomas Huth tcg_gen_and_tl(cpu_PSW_V, cpu_PSW_V, temp4);
470fcf5ef2aSThomas Huth }
471fcf5ef2aSThomas Huth /* combine V0/V1 bits */
472fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_V, cpu_PSW_V, temp2);
473fcf5ef2aSThomas Huth /* calc sv bit */
474fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SV, cpu_PSW_SV, cpu_PSW_V);
475fcf5ef2aSThomas Huth /* write result */
476fcf5ef2aSThomas Huth tcg_gen_mov_tl(ret_low, temp);
477fcf5ef2aSThomas Huth tcg_gen_mov_tl(ret_high, temp3);
478fcf5ef2aSThomas Huth /* calc AV bit */
479fcf5ef2aSThomas Huth tcg_gen_add_tl(temp, ret_low, ret_low);
480fcf5ef2aSThomas Huth tcg_gen_xor_tl(temp, temp, ret_low);
481fcf5ef2aSThomas Huth tcg_gen_add_tl(cpu_PSW_AV, ret_high, ret_high);
482fcf5ef2aSThomas Huth tcg_gen_xor_tl(cpu_PSW_AV, cpu_PSW_AV, ret_high);
483fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_AV, cpu_PSW_AV, temp);
484fcf5ef2aSThomas Huth /* calc SAV bit */
485fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SAV, cpu_PSW_SAV, cpu_PSW_AV);
486fcf5ef2aSThomas Huth }
487fcf5ef2aSThomas Huth
488fcf5ef2aSThomas Huth /* ret = r2 + (r1 * r3); */
gen_madd32_d(TCGv ret,TCGv r1,TCGv r2,TCGv r3)489fcf5ef2aSThomas Huth static inline void gen_madd32_d(TCGv ret, TCGv r1, TCGv r2, TCGv r3)
490fcf5ef2aSThomas Huth {
491fcf5ef2aSThomas Huth TCGv_i64 t1 = tcg_temp_new_i64();
492fcf5ef2aSThomas Huth TCGv_i64 t2 = tcg_temp_new_i64();
493fcf5ef2aSThomas Huth TCGv_i64 t3 = tcg_temp_new_i64();
494fcf5ef2aSThomas Huth
495fcf5ef2aSThomas Huth tcg_gen_ext_i32_i64(t1, r1);
496fcf5ef2aSThomas Huth tcg_gen_ext_i32_i64(t2, r2);
497fcf5ef2aSThomas Huth tcg_gen_ext_i32_i64(t3, r3);
498fcf5ef2aSThomas Huth
499fcf5ef2aSThomas Huth tcg_gen_mul_i64(t1, t1, t3);
500fcf5ef2aSThomas Huth tcg_gen_add_i64(t1, t2, t1);
501fcf5ef2aSThomas Huth
502fcf5ef2aSThomas Huth tcg_gen_extrl_i64_i32(ret, t1);
503fcf5ef2aSThomas Huth /* calc V
504fcf5ef2aSThomas Huth t1 > 0x7fffffff */
505fcf5ef2aSThomas Huth tcg_gen_setcondi_i64(TCG_COND_GT, t3, t1, 0x7fffffffLL);
506fcf5ef2aSThomas Huth /* t1 < -0x80000000 */
507fcf5ef2aSThomas Huth tcg_gen_setcondi_i64(TCG_COND_LT, t2, t1, -0x80000000LL);
508fcf5ef2aSThomas Huth tcg_gen_or_i64(t2, t2, t3);
509fcf5ef2aSThomas Huth tcg_gen_extrl_i64_i32(cpu_PSW_V, t2);
510fcf5ef2aSThomas Huth tcg_gen_shli_tl(cpu_PSW_V, cpu_PSW_V, 31);
511fcf5ef2aSThomas Huth /* Calc SV bit */
512fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SV, cpu_PSW_SV, cpu_PSW_V);
513fcf5ef2aSThomas Huth /* Calc AV/SAV bits */
514fcf5ef2aSThomas Huth tcg_gen_add_tl(cpu_PSW_AV, ret, ret);
515fcf5ef2aSThomas Huth tcg_gen_xor_tl(cpu_PSW_AV, ret, cpu_PSW_AV);
516fcf5ef2aSThomas Huth /* calc SAV */
517fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SAV, cpu_PSW_SAV, cpu_PSW_AV);
518fcf5ef2aSThomas Huth }
519fcf5ef2aSThomas Huth
gen_maddi32_d(TCGv ret,TCGv r1,TCGv r2,int32_t con)520fcf5ef2aSThomas Huth static inline void gen_maddi32_d(TCGv ret, TCGv r1, TCGv r2, int32_t con)
521fcf5ef2aSThomas Huth {
522151293c2SRichard Henderson TCGv temp = tcg_constant_i32(con);
523fcf5ef2aSThomas Huth gen_madd32_d(ret, r1, r2, temp);
524fcf5ef2aSThomas Huth }
525fcf5ef2aSThomas Huth
526fcf5ef2aSThomas Huth static inline void
gen_madd64_d(TCGv ret_low,TCGv ret_high,TCGv r1,TCGv r2_low,TCGv r2_high,TCGv r3)527fcf5ef2aSThomas Huth gen_madd64_d(TCGv ret_low, TCGv ret_high, TCGv r1, TCGv r2_low, TCGv r2_high,
528fcf5ef2aSThomas Huth TCGv r3)
529fcf5ef2aSThomas Huth {
530fcf5ef2aSThomas Huth TCGv t1 = tcg_temp_new();
531fcf5ef2aSThomas Huth TCGv t2 = tcg_temp_new();
532fcf5ef2aSThomas Huth TCGv t3 = tcg_temp_new();
533fcf5ef2aSThomas Huth TCGv t4 = tcg_temp_new();
534fcf5ef2aSThomas Huth
535fcf5ef2aSThomas Huth tcg_gen_muls2_tl(t1, t2, r1, r3);
536fcf5ef2aSThomas Huth /* only the add can overflow */
537fcf5ef2aSThomas Huth tcg_gen_add2_tl(t3, t4, r2_low, r2_high, t1, t2);
538fcf5ef2aSThomas Huth /* calc V bit */
539fcf5ef2aSThomas Huth tcg_gen_xor_tl(cpu_PSW_V, t4, r2_high);
540fcf5ef2aSThomas Huth tcg_gen_xor_tl(t1, r2_high, t2);
541fcf5ef2aSThomas Huth tcg_gen_andc_tl(cpu_PSW_V, cpu_PSW_V, t1);
542fcf5ef2aSThomas Huth /* Calc SV bit */
543fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SV, cpu_PSW_SV, cpu_PSW_V);
544fcf5ef2aSThomas Huth /* Calc AV/SAV bits */
545fcf5ef2aSThomas Huth tcg_gen_add_tl(cpu_PSW_AV, t4, t4);
546fcf5ef2aSThomas Huth tcg_gen_xor_tl(cpu_PSW_AV, t4, cpu_PSW_AV);
547fcf5ef2aSThomas Huth /* calc SAV */
548fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SAV, cpu_PSW_SAV, cpu_PSW_AV);
549fcf5ef2aSThomas Huth /* write back the result */
550fcf5ef2aSThomas Huth tcg_gen_mov_tl(ret_low, t3);
551fcf5ef2aSThomas Huth tcg_gen_mov_tl(ret_high, t4);
552fcf5ef2aSThomas Huth }
553fcf5ef2aSThomas Huth
554fcf5ef2aSThomas Huth static inline void
gen_maddu64_d(TCGv ret_low,TCGv ret_high,TCGv r1,TCGv r2_low,TCGv r2_high,TCGv r3)555fcf5ef2aSThomas Huth gen_maddu64_d(TCGv ret_low, TCGv ret_high, TCGv r1, TCGv r2_low, TCGv r2_high,
556fcf5ef2aSThomas Huth TCGv r3)
557fcf5ef2aSThomas Huth {
558fcf5ef2aSThomas Huth TCGv_i64 t1 = tcg_temp_new_i64();
559fcf5ef2aSThomas Huth TCGv_i64 t2 = tcg_temp_new_i64();
560fcf5ef2aSThomas Huth TCGv_i64 t3 = tcg_temp_new_i64();
561fcf5ef2aSThomas Huth
562fcf5ef2aSThomas Huth tcg_gen_extu_i32_i64(t1, r1);
563fcf5ef2aSThomas Huth tcg_gen_concat_i32_i64(t2, r2_low, r2_high);
564fcf5ef2aSThomas Huth tcg_gen_extu_i32_i64(t3, r3);
565fcf5ef2aSThomas Huth
566fcf5ef2aSThomas Huth tcg_gen_mul_i64(t1, t1, t3);
567fcf5ef2aSThomas Huth tcg_gen_add_i64(t2, t2, t1);
568fcf5ef2aSThomas Huth /* write back result */
569fcf5ef2aSThomas Huth tcg_gen_extr_i64_i32(ret_low, ret_high, t2);
570fcf5ef2aSThomas Huth /* only the add overflows, if t2 < t1
571fcf5ef2aSThomas Huth calc V bit */
572fcf5ef2aSThomas Huth tcg_gen_setcond_i64(TCG_COND_LTU, t2, t2, t1);
573fcf5ef2aSThomas Huth tcg_gen_extrl_i64_i32(cpu_PSW_V, t2);
574fcf5ef2aSThomas Huth tcg_gen_shli_tl(cpu_PSW_V, cpu_PSW_V, 31);
575fcf5ef2aSThomas Huth /* Calc SV bit */
576fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SV, cpu_PSW_SV, cpu_PSW_V);
577fcf5ef2aSThomas Huth /* Calc AV/SAV bits */
578fcf5ef2aSThomas Huth tcg_gen_add_tl(cpu_PSW_AV, ret_high, ret_high);
579fcf5ef2aSThomas Huth tcg_gen_xor_tl(cpu_PSW_AV, ret_high, cpu_PSW_AV);
580fcf5ef2aSThomas Huth /* calc SAV */
581fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SAV, cpu_PSW_SAV, cpu_PSW_AV);
582fcf5ef2aSThomas Huth }
583fcf5ef2aSThomas Huth
584fcf5ef2aSThomas Huth static inline void
gen_maddi64_d(TCGv ret_low,TCGv ret_high,TCGv r1,TCGv r2_low,TCGv r2_high,int32_t con)585fcf5ef2aSThomas Huth gen_maddi64_d(TCGv ret_low, TCGv ret_high, TCGv r1, TCGv r2_low, TCGv r2_high,
586fcf5ef2aSThomas Huth int32_t con)
587fcf5ef2aSThomas Huth {
588151293c2SRichard Henderson TCGv temp = tcg_constant_i32(con);
589fcf5ef2aSThomas Huth gen_madd64_d(ret_low, ret_high, r1, r2_low, r2_high, temp);
590fcf5ef2aSThomas Huth }
591fcf5ef2aSThomas Huth
592fcf5ef2aSThomas Huth static inline void
gen_maddui64_d(TCGv ret_low,TCGv ret_high,TCGv r1,TCGv r2_low,TCGv r2_high,int32_t con)593fcf5ef2aSThomas Huth gen_maddui64_d(TCGv ret_low, TCGv ret_high, TCGv r1, TCGv r2_low, TCGv r2_high,
594fcf5ef2aSThomas Huth int32_t con)
595fcf5ef2aSThomas Huth {
596151293c2SRichard Henderson TCGv temp = tcg_constant_i32(con);
597fcf5ef2aSThomas Huth gen_maddu64_d(ret_low, ret_high, r1, r2_low, r2_high, temp);
598fcf5ef2aSThomas Huth }
599fcf5ef2aSThomas Huth
600fcf5ef2aSThomas Huth static inline void
gen_madd_h(TCGv ret_low,TCGv ret_high,TCGv r1_low,TCGv r1_high,TCGv r2,TCGv r3,uint32_t n,uint32_t mode)601fcf5ef2aSThomas Huth gen_madd_h(TCGv ret_low, TCGv ret_high, TCGv r1_low, TCGv r1_high, TCGv r2,
602fcf5ef2aSThomas Huth TCGv r3, uint32_t n, uint32_t mode)
603fcf5ef2aSThomas Huth {
604bf38ca5cSRichard Henderson TCGv t_n = tcg_constant_i32(n);
605bf38ca5cSRichard Henderson TCGv temp = tcg_temp_new();
606fcf5ef2aSThomas Huth TCGv temp2 = tcg_temp_new();
607fcf5ef2aSThomas Huth TCGv_i64 temp64 = tcg_temp_new_i64();
608fcf5ef2aSThomas Huth switch (mode) {
609fcf5ef2aSThomas Huth case MODE_LL:
610bf38ca5cSRichard Henderson GEN_HELPER_LL(mul_h, temp64, r2, r3, t_n);
611fcf5ef2aSThomas Huth break;
612fcf5ef2aSThomas Huth case MODE_LU:
613bf38ca5cSRichard Henderson GEN_HELPER_LU(mul_h, temp64, r2, r3, t_n);
614fcf5ef2aSThomas Huth break;
615fcf5ef2aSThomas Huth case MODE_UL:
616bf38ca5cSRichard Henderson GEN_HELPER_UL(mul_h, temp64, r2, r3, t_n);
617fcf5ef2aSThomas Huth break;
618fcf5ef2aSThomas Huth case MODE_UU:
619bf38ca5cSRichard Henderson GEN_HELPER_UU(mul_h, temp64, r2, r3, t_n);
620fcf5ef2aSThomas Huth break;
621fcf5ef2aSThomas Huth }
622fcf5ef2aSThomas Huth tcg_gen_extr_i64_i32(temp, temp2, temp64);
623fcf5ef2aSThomas Huth gen_addsub64_h(ret_low, ret_high, r1_low, r1_high, temp, temp2,
624fcf5ef2aSThomas Huth tcg_gen_add_tl, tcg_gen_add_tl);
625fcf5ef2aSThomas Huth }
626fcf5ef2aSThomas Huth
627fcf5ef2aSThomas Huth static inline void
gen_maddsu_h(TCGv ret_low,TCGv ret_high,TCGv r1_low,TCGv r1_high,TCGv r2,TCGv r3,uint32_t n,uint32_t mode)628fcf5ef2aSThomas Huth gen_maddsu_h(TCGv ret_low, TCGv ret_high, TCGv r1_low, TCGv r1_high, TCGv r2,
629fcf5ef2aSThomas Huth TCGv r3, uint32_t n, uint32_t mode)
630fcf5ef2aSThomas Huth {
631bf38ca5cSRichard Henderson TCGv t_n = tcg_constant_i32(n);
632bf38ca5cSRichard Henderson TCGv temp = tcg_temp_new();
633fcf5ef2aSThomas Huth TCGv temp2 = tcg_temp_new();
634fcf5ef2aSThomas Huth TCGv_i64 temp64 = tcg_temp_new_i64();
635fcf5ef2aSThomas Huth switch (mode) {
636fcf5ef2aSThomas Huth case MODE_LL:
637bf38ca5cSRichard Henderson GEN_HELPER_LL(mul_h, temp64, r2, r3, t_n);
638fcf5ef2aSThomas Huth break;
639fcf5ef2aSThomas Huth case MODE_LU:
640bf38ca5cSRichard Henderson GEN_HELPER_LU(mul_h, temp64, r2, r3, t_n);
641fcf5ef2aSThomas Huth break;
642fcf5ef2aSThomas Huth case MODE_UL:
643bf38ca5cSRichard Henderson GEN_HELPER_UL(mul_h, temp64, r2, r3, t_n);
644fcf5ef2aSThomas Huth break;
645fcf5ef2aSThomas Huth case MODE_UU:
646bf38ca5cSRichard Henderson GEN_HELPER_UU(mul_h, temp64, r2, r3, t_n);
647fcf5ef2aSThomas Huth break;
648fcf5ef2aSThomas Huth }
649fcf5ef2aSThomas Huth tcg_gen_extr_i64_i32(temp, temp2, temp64);
650fcf5ef2aSThomas Huth gen_addsub64_h(ret_low, ret_high, r1_low, r1_high, temp, temp2,
651fcf5ef2aSThomas Huth tcg_gen_sub_tl, tcg_gen_add_tl);
652fcf5ef2aSThomas Huth }
653fcf5ef2aSThomas Huth
654fcf5ef2aSThomas Huth static inline void
gen_maddsum_h(TCGv ret_low,TCGv ret_high,TCGv r1_low,TCGv r1_high,TCGv r2,TCGv r3,uint32_t n,uint32_t mode)655fcf5ef2aSThomas Huth gen_maddsum_h(TCGv ret_low, TCGv ret_high, TCGv r1_low, TCGv r1_high, TCGv r2,
656fcf5ef2aSThomas Huth TCGv r3, uint32_t n, uint32_t mode)
657fcf5ef2aSThomas Huth {
658bf38ca5cSRichard Henderson TCGv t_n = tcg_constant_i32(n);
659fcf5ef2aSThomas Huth TCGv_i64 temp64 = tcg_temp_new_i64();
660fcf5ef2aSThomas Huth TCGv_i64 temp64_2 = tcg_temp_new_i64();
661fcf5ef2aSThomas Huth TCGv_i64 temp64_3 = tcg_temp_new_i64();
662fcf5ef2aSThomas Huth switch (mode) {
663fcf5ef2aSThomas Huth case MODE_LL:
664bf38ca5cSRichard Henderson GEN_HELPER_LL(mul_h, temp64, r2, r3, t_n);
665fcf5ef2aSThomas Huth break;
666fcf5ef2aSThomas Huth case MODE_LU:
667bf38ca5cSRichard Henderson GEN_HELPER_LU(mul_h, temp64, r2, r3, t_n);
668fcf5ef2aSThomas Huth break;
669fcf5ef2aSThomas Huth case MODE_UL:
670bf38ca5cSRichard Henderson GEN_HELPER_UL(mul_h, temp64, r2, r3, t_n);
671fcf5ef2aSThomas Huth break;
672fcf5ef2aSThomas Huth case MODE_UU:
673bf38ca5cSRichard Henderson GEN_HELPER_UU(mul_h, temp64, r2, r3, t_n);
674fcf5ef2aSThomas Huth break;
675fcf5ef2aSThomas Huth }
676fcf5ef2aSThomas Huth tcg_gen_concat_i32_i64(temp64_3, r1_low, r1_high);
677fcf5ef2aSThomas Huth tcg_gen_sari_i64(temp64_2, temp64, 32); /* high */
678fcf5ef2aSThomas Huth tcg_gen_ext32s_i64(temp64, temp64); /* low */
679fcf5ef2aSThomas Huth tcg_gen_sub_i64(temp64, temp64_2, temp64);
680fcf5ef2aSThomas Huth tcg_gen_shli_i64(temp64, temp64, 16);
681fcf5ef2aSThomas Huth
682fcf5ef2aSThomas Huth gen_add64_d(temp64_2, temp64_3, temp64);
683fcf5ef2aSThomas Huth /* write back result */
684fcf5ef2aSThomas Huth tcg_gen_extr_i64_i32(ret_low, ret_high, temp64_2);
685fcf5ef2aSThomas Huth }
686fcf5ef2aSThomas Huth
687fcf5ef2aSThomas Huth static inline void gen_adds(TCGv ret, TCGv r1, TCGv r2);
688fcf5ef2aSThomas Huth
689fcf5ef2aSThomas Huth static inline void
gen_madds_h(TCGv ret_low,TCGv ret_high,TCGv r1_low,TCGv r1_high,TCGv r2,TCGv r3,uint32_t n,uint32_t mode)690fcf5ef2aSThomas Huth gen_madds_h(TCGv ret_low, TCGv ret_high, TCGv r1_low, TCGv r1_high, TCGv r2,
691fcf5ef2aSThomas Huth TCGv r3, uint32_t n, uint32_t mode)
692fcf5ef2aSThomas Huth {
693bf38ca5cSRichard Henderson TCGv t_n = tcg_constant_i32(n);
694bf38ca5cSRichard Henderson TCGv temp = tcg_temp_new();
695fcf5ef2aSThomas Huth TCGv temp2 = tcg_temp_new();
696fcf5ef2aSThomas Huth TCGv temp3 = tcg_temp_new();
697fcf5ef2aSThomas Huth TCGv_i64 temp64 = tcg_temp_new_i64();
698fcf5ef2aSThomas Huth
699fcf5ef2aSThomas Huth switch (mode) {
700fcf5ef2aSThomas Huth case MODE_LL:
701bf38ca5cSRichard Henderson GEN_HELPER_LL(mul_h, temp64, r2, r3, t_n);
702fcf5ef2aSThomas Huth break;
703fcf5ef2aSThomas Huth case MODE_LU:
704bf38ca5cSRichard Henderson GEN_HELPER_LU(mul_h, temp64, r2, r3, t_n);
705fcf5ef2aSThomas Huth break;
706fcf5ef2aSThomas Huth case MODE_UL:
707bf38ca5cSRichard Henderson GEN_HELPER_UL(mul_h, temp64, r2, r3, t_n);
708fcf5ef2aSThomas Huth break;
709fcf5ef2aSThomas Huth case MODE_UU:
710bf38ca5cSRichard Henderson GEN_HELPER_UU(mul_h, temp64, r2, r3, t_n);
711fcf5ef2aSThomas Huth break;
712fcf5ef2aSThomas Huth }
713fcf5ef2aSThomas Huth tcg_gen_extr_i64_i32(temp, temp2, temp64);
714fcf5ef2aSThomas Huth gen_adds(ret_low, r1_low, temp);
715fcf5ef2aSThomas Huth tcg_gen_mov_tl(temp, cpu_PSW_V);
716fcf5ef2aSThomas Huth tcg_gen_mov_tl(temp3, cpu_PSW_AV);
717fcf5ef2aSThomas Huth gen_adds(ret_high, r1_high, temp2);
718fcf5ef2aSThomas Huth /* combine v bits */
719fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_V, cpu_PSW_V, temp);
720fcf5ef2aSThomas Huth /* combine av bits */
721fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_AV, cpu_PSW_AV, temp3);
722fcf5ef2aSThomas Huth }
723fcf5ef2aSThomas Huth
724fcf5ef2aSThomas Huth static inline void gen_subs(TCGv ret, TCGv r1, TCGv r2);
725fcf5ef2aSThomas Huth
726fcf5ef2aSThomas Huth static inline void
gen_maddsus_h(TCGv ret_low,TCGv ret_high,TCGv r1_low,TCGv r1_high,TCGv r2,TCGv r3,uint32_t n,uint32_t mode)727fcf5ef2aSThomas Huth gen_maddsus_h(TCGv ret_low, TCGv ret_high, TCGv r1_low, TCGv r1_high, TCGv r2,
728fcf5ef2aSThomas Huth TCGv r3, uint32_t n, uint32_t mode)
729fcf5ef2aSThomas Huth {
730bf38ca5cSRichard Henderson TCGv t_n = tcg_constant_i32(n);
731bf38ca5cSRichard Henderson TCGv temp = tcg_temp_new();
732fcf5ef2aSThomas Huth TCGv temp2 = tcg_temp_new();
733fcf5ef2aSThomas Huth TCGv temp3 = tcg_temp_new();
734fcf5ef2aSThomas Huth TCGv_i64 temp64 = tcg_temp_new_i64();
735fcf5ef2aSThomas Huth
736fcf5ef2aSThomas Huth switch (mode) {
737fcf5ef2aSThomas Huth case MODE_LL:
738bf38ca5cSRichard Henderson GEN_HELPER_LL(mul_h, temp64, r2, r3, t_n);
739fcf5ef2aSThomas Huth break;
740fcf5ef2aSThomas Huth case MODE_LU:
741bf38ca5cSRichard Henderson GEN_HELPER_LU(mul_h, temp64, r2, r3, t_n);
742fcf5ef2aSThomas Huth break;
743fcf5ef2aSThomas Huth case MODE_UL:
744bf38ca5cSRichard Henderson GEN_HELPER_UL(mul_h, temp64, r2, r3, t_n);
745fcf5ef2aSThomas Huth break;
746fcf5ef2aSThomas Huth case MODE_UU:
747bf38ca5cSRichard Henderson GEN_HELPER_UU(mul_h, temp64, r2, r3, t_n);
748fcf5ef2aSThomas Huth break;
749fcf5ef2aSThomas Huth }
750fcf5ef2aSThomas Huth tcg_gen_extr_i64_i32(temp, temp2, temp64);
751fcf5ef2aSThomas Huth gen_subs(ret_low, r1_low, temp);
752fcf5ef2aSThomas Huth tcg_gen_mov_tl(temp, cpu_PSW_V);
753fcf5ef2aSThomas Huth tcg_gen_mov_tl(temp3, cpu_PSW_AV);
754fcf5ef2aSThomas Huth gen_adds(ret_high, r1_high, temp2);
755fcf5ef2aSThomas Huth /* combine v bits */
756fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_V, cpu_PSW_V, temp);
757fcf5ef2aSThomas Huth /* combine av bits */
758fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_AV, cpu_PSW_AV, temp3);
759fcf5ef2aSThomas Huth }
760fcf5ef2aSThomas Huth
761fcf5ef2aSThomas Huth static inline void
gen_maddsums_h(TCGv ret_low,TCGv ret_high,TCGv r1_low,TCGv r1_high,TCGv r2,TCGv r3,uint32_t n,uint32_t mode)762fcf5ef2aSThomas Huth gen_maddsums_h(TCGv ret_low, TCGv ret_high, TCGv r1_low, TCGv r1_high, TCGv r2,
763fcf5ef2aSThomas Huth TCGv r3, uint32_t n, uint32_t mode)
764fcf5ef2aSThomas Huth {
765bf38ca5cSRichard Henderson TCGv t_n = tcg_constant_i32(n);
766fcf5ef2aSThomas Huth TCGv_i64 temp64 = tcg_temp_new_i64();
767fcf5ef2aSThomas Huth TCGv_i64 temp64_2 = tcg_temp_new_i64();
768fcf5ef2aSThomas Huth
769fcf5ef2aSThomas Huth switch (mode) {
770fcf5ef2aSThomas Huth case MODE_LL:
771bf38ca5cSRichard Henderson GEN_HELPER_LL(mul_h, temp64, r2, r3, t_n);
772fcf5ef2aSThomas Huth break;
773fcf5ef2aSThomas Huth case MODE_LU:
774bf38ca5cSRichard Henderson GEN_HELPER_LU(mul_h, temp64, r2, r3, t_n);
775fcf5ef2aSThomas Huth break;
776fcf5ef2aSThomas Huth case MODE_UL:
777bf38ca5cSRichard Henderson GEN_HELPER_UL(mul_h, temp64, r2, r3, t_n);
778fcf5ef2aSThomas Huth break;
779fcf5ef2aSThomas Huth case MODE_UU:
780bf38ca5cSRichard Henderson GEN_HELPER_UU(mul_h, temp64, r2, r3, t_n);
781fcf5ef2aSThomas Huth break;
782fcf5ef2aSThomas Huth }
783fcf5ef2aSThomas Huth tcg_gen_sari_i64(temp64_2, temp64, 32); /* high */
784fcf5ef2aSThomas Huth tcg_gen_ext32s_i64(temp64, temp64); /* low */
785fcf5ef2aSThomas Huth tcg_gen_sub_i64(temp64, temp64_2, temp64);
786fcf5ef2aSThomas Huth tcg_gen_shli_i64(temp64, temp64, 16);
787fcf5ef2aSThomas Huth tcg_gen_concat_i32_i64(temp64_2, r1_low, r1_high);
788fcf5ef2aSThomas Huth
789ad75a51eSRichard Henderson gen_helper_add64_ssov(temp64, tcg_env, temp64_2, temp64);
790fcf5ef2aSThomas Huth tcg_gen_extr_i64_i32(ret_low, ret_high, temp64);
791fcf5ef2aSThomas Huth }
792fcf5ef2aSThomas Huth
793fcf5ef2aSThomas Huth
794fcf5ef2aSThomas Huth static inline void
gen_maddm_h(TCGv ret_low,TCGv ret_high,TCGv r1_low,TCGv r1_high,TCGv r2,TCGv r3,uint32_t n,uint32_t mode)795fcf5ef2aSThomas Huth gen_maddm_h(TCGv ret_low, TCGv ret_high, TCGv r1_low, TCGv r1_high, TCGv r2,
796fcf5ef2aSThomas Huth TCGv r3, uint32_t n, uint32_t mode)
797fcf5ef2aSThomas Huth {
798bf38ca5cSRichard Henderson TCGv t_n = tcg_constant_i32(n);
799fcf5ef2aSThomas Huth TCGv_i64 temp64 = tcg_temp_new_i64();
800fcf5ef2aSThomas Huth TCGv_i64 temp64_2 = tcg_temp_new_i64();
801fcf5ef2aSThomas Huth TCGv_i64 temp64_3 = tcg_temp_new_i64();
802fcf5ef2aSThomas Huth switch (mode) {
803fcf5ef2aSThomas Huth case MODE_LL:
804bf38ca5cSRichard Henderson GEN_HELPER_LL(mulm_h, temp64, r2, r3, t_n);
805fcf5ef2aSThomas Huth break;
806fcf5ef2aSThomas Huth case MODE_LU:
807bf38ca5cSRichard Henderson GEN_HELPER_LU(mulm_h, temp64, r2, r3, t_n);
808fcf5ef2aSThomas Huth break;
809fcf5ef2aSThomas Huth case MODE_UL:
810bf38ca5cSRichard Henderson GEN_HELPER_UL(mulm_h, temp64, r2, r3, t_n);
811fcf5ef2aSThomas Huth break;
812fcf5ef2aSThomas Huth case MODE_UU:
813bf38ca5cSRichard Henderson GEN_HELPER_UU(mulm_h, temp64, r2, r3, t_n);
814fcf5ef2aSThomas Huth break;
815fcf5ef2aSThomas Huth }
816fcf5ef2aSThomas Huth tcg_gen_concat_i32_i64(temp64_2, r1_low, r1_high);
817fcf5ef2aSThomas Huth gen_add64_d(temp64_3, temp64_2, temp64);
818fcf5ef2aSThomas Huth /* write back result */
819fcf5ef2aSThomas Huth tcg_gen_extr_i64_i32(ret_low, ret_high, temp64_3);
820fcf5ef2aSThomas Huth }
821fcf5ef2aSThomas Huth
822fcf5ef2aSThomas Huth static inline void
gen_maddms_h(TCGv ret_low,TCGv ret_high,TCGv r1_low,TCGv r1_high,TCGv r2,TCGv r3,uint32_t n,uint32_t mode)823fcf5ef2aSThomas Huth gen_maddms_h(TCGv ret_low, TCGv ret_high, TCGv r1_low, TCGv r1_high, TCGv r2,
824fcf5ef2aSThomas Huth TCGv r3, uint32_t n, uint32_t mode)
825fcf5ef2aSThomas Huth {
826bf38ca5cSRichard Henderson TCGv t_n = tcg_constant_i32(n);
827fcf5ef2aSThomas Huth TCGv_i64 temp64 = tcg_temp_new_i64();
828fcf5ef2aSThomas Huth TCGv_i64 temp64_2 = tcg_temp_new_i64();
829fcf5ef2aSThomas Huth switch (mode) {
830fcf5ef2aSThomas Huth case MODE_LL:
831bf38ca5cSRichard Henderson GEN_HELPER_LL(mulm_h, temp64, r2, r3, t_n);
832fcf5ef2aSThomas Huth break;
833fcf5ef2aSThomas Huth case MODE_LU:
834bf38ca5cSRichard Henderson GEN_HELPER_LU(mulm_h, temp64, r2, r3, t_n);
835fcf5ef2aSThomas Huth break;
836fcf5ef2aSThomas Huth case MODE_UL:
837bf38ca5cSRichard Henderson GEN_HELPER_UL(mulm_h, temp64, r2, r3, t_n);
838fcf5ef2aSThomas Huth break;
839fcf5ef2aSThomas Huth case MODE_UU:
840bf38ca5cSRichard Henderson GEN_HELPER_UU(mulm_h, temp64, r2, r3, t_n);
841fcf5ef2aSThomas Huth break;
842fcf5ef2aSThomas Huth }
843fcf5ef2aSThomas Huth tcg_gen_concat_i32_i64(temp64_2, r1_low, r1_high);
844ad75a51eSRichard Henderson gen_helper_add64_ssov(temp64, tcg_env, temp64_2, temp64);
845fcf5ef2aSThomas Huth tcg_gen_extr_i64_i32(ret_low, ret_high, temp64);
846fcf5ef2aSThomas Huth }
847fcf5ef2aSThomas Huth
848fcf5ef2aSThomas Huth static inline void
gen_maddr64_h(TCGv ret,TCGv r1_low,TCGv r1_high,TCGv r2,TCGv r3,uint32_t n,uint32_t mode)849fcf5ef2aSThomas Huth gen_maddr64_h(TCGv ret, TCGv r1_low, TCGv r1_high, TCGv r2, TCGv r3, uint32_t n,
850fcf5ef2aSThomas Huth uint32_t mode)
851fcf5ef2aSThomas Huth {
852bf38ca5cSRichard Henderson TCGv t_n = tcg_constant_i32(n);
853fcf5ef2aSThomas Huth TCGv_i64 temp64 = tcg_temp_new_i64();
854fcf5ef2aSThomas Huth switch (mode) {
855fcf5ef2aSThomas Huth case MODE_LL:
856bf38ca5cSRichard Henderson GEN_HELPER_LL(mul_h, temp64, r2, r3, t_n);
857fcf5ef2aSThomas Huth break;
858fcf5ef2aSThomas Huth case MODE_LU:
859bf38ca5cSRichard Henderson GEN_HELPER_LU(mul_h, temp64, r2, r3, t_n);
860fcf5ef2aSThomas Huth break;
861fcf5ef2aSThomas Huth case MODE_UL:
862bf38ca5cSRichard Henderson GEN_HELPER_UL(mul_h, temp64, r2, r3, t_n);
863fcf5ef2aSThomas Huth break;
864fcf5ef2aSThomas Huth case MODE_UU:
865bf38ca5cSRichard Henderson GEN_HELPER_UU(mul_h, temp64, r2, r3, t_n);
866fcf5ef2aSThomas Huth break;
867fcf5ef2aSThomas Huth }
868ad75a51eSRichard Henderson gen_helper_addr_h(ret, tcg_env, temp64, r1_low, r1_high);
869fcf5ef2aSThomas Huth }
870fcf5ef2aSThomas Huth
871fcf5ef2aSThomas Huth static inline void
gen_maddr32_h(TCGv ret,TCGv r1,TCGv r2,TCGv r3,uint32_t n,uint32_t mode)872fcf5ef2aSThomas Huth gen_maddr32_h(TCGv ret, TCGv r1, TCGv r2, TCGv r3, uint32_t n, uint32_t mode)
873fcf5ef2aSThomas Huth {
874fcf5ef2aSThomas Huth TCGv temp = tcg_temp_new();
875fcf5ef2aSThomas Huth TCGv temp2 = tcg_temp_new();
876fcf5ef2aSThomas Huth
877fcf5ef2aSThomas Huth tcg_gen_andi_tl(temp2, r1, 0xffff0000);
878fcf5ef2aSThomas Huth tcg_gen_shli_tl(temp, r1, 16);
879fcf5ef2aSThomas Huth gen_maddr64_h(ret, temp, temp2, r2, r3, n, mode);
880fcf5ef2aSThomas Huth }
881fcf5ef2aSThomas Huth
882fcf5ef2aSThomas Huth static inline void
gen_maddsur32_h(TCGv ret,TCGv r1,TCGv r2,TCGv r3,uint32_t n,uint32_t mode)883fcf5ef2aSThomas Huth gen_maddsur32_h(TCGv ret, TCGv r1, TCGv r2, TCGv r3, uint32_t n, uint32_t mode)
884fcf5ef2aSThomas Huth {
885bf38ca5cSRichard Henderson TCGv t_n = tcg_constant_i32(n);
886bf38ca5cSRichard Henderson TCGv temp = tcg_temp_new();
887fcf5ef2aSThomas Huth TCGv temp2 = tcg_temp_new();
888fcf5ef2aSThomas Huth TCGv_i64 temp64 = tcg_temp_new_i64();
889fcf5ef2aSThomas Huth switch (mode) {
890fcf5ef2aSThomas Huth case MODE_LL:
891bf38ca5cSRichard Henderson GEN_HELPER_LL(mul_h, temp64, r2, r3, t_n);
892fcf5ef2aSThomas Huth break;
893fcf5ef2aSThomas Huth case MODE_LU:
894bf38ca5cSRichard Henderson GEN_HELPER_LU(mul_h, temp64, r2, r3, t_n);
895fcf5ef2aSThomas Huth break;
896fcf5ef2aSThomas Huth case MODE_UL:
897bf38ca5cSRichard Henderson GEN_HELPER_UL(mul_h, temp64, r2, r3, t_n);
898fcf5ef2aSThomas Huth break;
899fcf5ef2aSThomas Huth case MODE_UU:
900bf38ca5cSRichard Henderson GEN_HELPER_UU(mul_h, temp64, r2, r3, t_n);
901fcf5ef2aSThomas Huth break;
902fcf5ef2aSThomas Huth }
903fcf5ef2aSThomas Huth tcg_gen_andi_tl(temp2, r1, 0xffff0000);
904fcf5ef2aSThomas Huth tcg_gen_shli_tl(temp, r1, 16);
905ad75a51eSRichard Henderson gen_helper_addsur_h(ret, tcg_env, temp64, temp, temp2);
906fcf5ef2aSThomas Huth }
907fcf5ef2aSThomas Huth
908fcf5ef2aSThomas Huth
909fcf5ef2aSThomas Huth static inline void
gen_maddr64s_h(TCGv ret,TCGv r1_low,TCGv r1_high,TCGv r2,TCGv r3,uint32_t n,uint32_t mode)910fcf5ef2aSThomas Huth gen_maddr64s_h(TCGv ret, TCGv r1_low, TCGv r1_high, TCGv r2, TCGv r3,
911fcf5ef2aSThomas Huth uint32_t n, uint32_t mode)
912fcf5ef2aSThomas Huth {
913bf38ca5cSRichard Henderson TCGv t_n = tcg_constant_i32(n);
914fcf5ef2aSThomas Huth TCGv_i64 temp64 = tcg_temp_new_i64();
915fcf5ef2aSThomas Huth switch (mode) {
916fcf5ef2aSThomas Huth case MODE_LL:
917bf38ca5cSRichard Henderson GEN_HELPER_LL(mul_h, temp64, r2, r3, t_n);
918fcf5ef2aSThomas Huth break;
919fcf5ef2aSThomas Huth case MODE_LU:
920bf38ca5cSRichard Henderson GEN_HELPER_LU(mul_h, temp64, r2, r3, t_n);
921fcf5ef2aSThomas Huth break;
922fcf5ef2aSThomas Huth case MODE_UL:
923bf38ca5cSRichard Henderson GEN_HELPER_UL(mul_h, temp64, r2, r3, t_n);
924fcf5ef2aSThomas Huth break;
925fcf5ef2aSThomas Huth case MODE_UU:
926bf38ca5cSRichard Henderson GEN_HELPER_UU(mul_h, temp64, r2, r3, t_n);
927fcf5ef2aSThomas Huth break;
928fcf5ef2aSThomas Huth }
929ad75a51eSRichard Henderson gen_helper_addr_h_ssov(ret, tcg_env, temp64, r1_low, r1_high);
930fcf5ef2aSThomas Huth }
931fcf5ef2aSThomas Huth
932fcf5ef2aSThomas Huth static inline void
gen_maddr32s_h(TCGv ret,TCGv r1,TCGv r2,TCGv r3,uint32_t n,uint32_t mode)933fcf5ef2aSThomas Huth gen_maddr32s_h(TCGv ret, TCGv r1, TCGv r2, TCGv r3, uint32_t n, uint32_t mode)
934fcf5ef2aSThomas Huth {
935fcf5ef2aSThomas Huth TCGv temp = tcg_temp_new();
936fcf5ef2aSThomas Huth TCGv temp2 = tcg_temp_new();
937fcf5ef2aSThomas Huth
938fcf5ef2aSThomas Huth tcg_gen_andi_tl(temp2, r1, 0xffff0000);
939fcf5ef2aSThomas Huth tcg_gen_shli_tl(temp, r1, 16);
940fcf5ef2aSThomas Huth gen_maddr64s_h(ret, temp, temp2, r2, r3, n, mode);
941fcf5ef2aSThomas Huth }
942fcf5ef2aSThomas Huth
943fcf5ef2aSThomas Huth static inline void
gen_maddsur32s_h(TCGv ret,TCGv r1,TCGv r2,TCGv r3,uint32_t n,uint32_t mode)944fcf5ef2aSThomas Huth gen_maddsur32s_h(TCGv ret, TCGv r1, TCGv r2, TCGv r3, uint32_t n, uint32_t mode)
945fcf5ef2aSThomas Huth {
946bf38ca5cSRichard Henderson TCGv t_n = tcg_constant_i32(n);
947bf38ca5cSRichard Henderson TCGv temp = tcg_temp_new();
948fcf5ef2aSThomas Huth TCGv temp2 = tcg_temp_new();
949fcf5ef2aSThomas Huth TCGv_i64 temp64 = tcg_temp_new_i64();
950fcf5ef2aSThomas Huth switch (mode) {
951fcf5ef2aSThomas Huth case MODE_LL:
952bf38ca5cSRichard Henderson GEN_HELPER_LL(mul_h, temp64, r2, r3, t_n);
953fcf5ef2aSThomas Huth break;
954fcf5ef2aSThomas Huth case MODE_LU:
955bf38ca5cSRichard Henderson GEN_HELPER_LU(mul_h, temp64, r2, r3, t_n);
956fcf5ef2aSThomas Huth break;
957fcf5ef2aSThomas Huth case MODE_UL:
958bf38ca5cSRichard Henderson GEN_HELPER_UL(mul_h, temp64, r2, r3, t_n);
959fcf5ef2aSThomas Huth break;
960fcf5ef2aSThomas Huth case MODE_UU:
961bf38ca5cSRichard Henderson GEN_HELPER_UU(mul_h, temp64, r2, r3, t_n);
962fcf5ef2aSThomas Huth break;
963fcf5ef2aSThomas Huth }
964fcf5ef2aSThomas Huth tcg_gen_andi_tl(temp2, r1, 0xffff0000);
965fcf5ef2aSThomas Huth tcg_gen_shli_tl(temp, r1, 16);
966ad75a51eSRichard Henderson gen_helper_addsur_h_ssov(ret, tcg_env, temp64, temp, temp2);
967fcf5ef2aSThomas Huth }
968fcf5ef2aSThomas Huth
969fcf5ef2aSThomas Huth static inline void
gen_maddr_q(TCGv ret,TCGv r1,TCGv r2,TCGv r3,uint32_t n)970fcf5ef2aSThomas Huth gen_maddr_q(TCGv ret, TCGv r1, TCGv r2, TCGv r3, uint32_t n)
971fcf5ef2aSThomas Huth {
972bf38ca5cSRichard Henderson TCGv t_n = tcg_constant_i32(n);
973ad75a51eSRichard Henderson gen_helper_maddr_q(ret, tcg_env, r1, r2, r3, t_n);
974fcf5ef2aSThomas Huth }
975fcf5ef2aSThomas Huth
976fcf5ef2aSThomas Huth static inline void
gen_maddrs_q(TCGv ret,TCGv r1,TCGv r2,TCGv r3,uint32_t n)977fcf5ef2aSThomas Huth gen_maddrs_q(TCGv ret, TCGv r1, TCGv r2, TCGv r3, uint32_t n)
978fcf5ef2aSThomas Huth {
979bf38ca5cSRichard Henderson TCGv t_n = tcg_constant_i32(n);
980ad75a51eSRichard Henderson gen_helper_maddr_q_ssov(ret, tcg_env, r1, r2, r3, t_n);
981fcf5ef2aSThomas Huth }
982fcf5ef2aSThomas Huth
983fcf5ef2aSThomas Huth static inline void
gen_madd32_q(TCGv ret,TCGv arg1,TCGv arg2,TCGv arg3,uint32_t n,uint32_t up_shift)984fcf5ef2aSThomas Huth gen_madd32_q(TCGv ret, TCGv arg1, TCGv arg2, TCGv arg3, uint32_t n,
9852db92a0cSBastian Koppelmann uint32_t up_shift)
986fcf5ef2aSThomas Huth {
987fcf5ef2aSThomas Huth TCGv temp = tcg_temp_new();
988fcf5ef2aSThomas Huth TCGv temp2 = tcg_temp_new();
989fcf5ef2aSThomas Huth TCGv temp3 = tcg_temp_new();
990fcf5ef2aSThomas Huth TCGv_i64 t1 = tcg_temp_new_i64();
991fcf5ef2aSThomas Huth TCGv_i64 t2 = tcg_temp_new_i64();
992fcf5ef2aSThomas Huth TCGv_i64 t3 = tcg_temp_new_i64();
993fcf5ef2aSThomas Huth
994fcf5ef2aSThomas Huth tcg_gen_ext_i32_i64(t2, arg2);
995fcf5ef2aSThomas Huth tcg_gen_ext_i32_i64(t3, arg3);
996fcf5ef2aSThomas Huth
997fcf5ef2aSThomas Huth tcg_gen_mul_i64(t2, t2, t3);
998fcf5ef2aSThomas Huth tcg_gen_shli_i64(t2, t2, n);
999fcf5ef2aSThomas Huth
1000fcf5ef2aSThomas Huth tcg_gen_ext_i32_i64(t1, arg1);
1001fcf5ef2aSThomas Huth tcg_gen_sari_i64(t2, t2, up_shift);
1002fcf5ef2aSThomas Huth
1003fcf5ef2aSThomas Huth tcg_gen_add_i64(t3, t1, t2);
1004fcf5ef2aSThomas Huth tcg_gen_extrl_i64_i32(temp3, t3);
1005fcf5ef2aSThomas Huth /* calc v bit */
1006fcf5ef2aSThomas Huth tcg_gen_setcondi_i64(TCG_COND_GT, t1, t3, 0x7fffffffLL);
1007fcf5ef2aSThomas Huth tcg_gen_setcondi_i64(TCG_COND_LT, t2, t3, -0x80000000LL);
1008fcf5ef2aSThomas Huth tcg_gen_or_i64(t1, t1, t2);
1009fcf5ef2aSThomas Huth tcg_gen_extrl_i64_i32(cpu_PSW_V, t1);
1010fcf5ef2aSThomas Huth tcg_gen_shli_tl(cpu_PSW_V, cpu_PSW_V, 31);
1011fcf5ef2aSThomas Huth /* We produce an overflow on the host if the mul before was
1012fcf5ef2aSThomas Huth (0x80000000 * 0x80000000) << 1). If this is the
1013fcf5ef2aSThomas Huth case, we negate the ovf. */
1014fcf5ef2aSThomas Huth if (n == 1) {
1015fcf5ef2aSThomas Huth tcg_gen_setcondi_tl(TCG_COND_EQ, temp, arg2, 0x80000000);
1016fcf5ef2aSThomas Huth tcg_gen_setcond_tl(TCG_COND_EQ, temp2, arg2, arg3);
1017fcf5ef2aSThomas Huth tcg_gen_and_tl(temp, temp, temp2);
1018fcf5ef2aSThomas Huth tcg_gen_shli_tl(temp, temp, 31);
1019fcf5ef2aSThomas Huth /* negate v bit, if special condition */
1020fcf5ef2aSThomas Huth tcg_gen_xor_tl(cpu_PSW_V, cpu_PSW_V, temp);
1021fcf5ef2aSThomas Huth }
1022fcf5ef2aSThomas Huth /* Calc SV bit */
1023fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SV, cpu_PSW_SV, cpu_PSW_V);
1024fcf5ef2aSThomas Huth /* Calc AV/SAV bits */
1025fcf5ef2aSThomas Huth tcg_gen_add_tl(cpu_PSW_AV, temp3, temp3);
1026fcf5ef2aSThomas Huth tcg_gen_xor_tl(cpu_PSW_AV, temp3, cpu_PSW_AV);
1027fcf5ef2aSThomas Huth /* calc SAV */
1028fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SAV, cpu_PSW_SAV, cpu_PSW_AV);
1029fcf5ef2aSThomas Huth /* write back result */
1030fcf5ef2aSThomas Huth tcg_gen_mov_tl(ret, temp3);
1031fcf5ef2aSThomas Huth }
1032fcf5ef2aSThomas Huth
1033fcf5ef2aSThomas Huth static inline void
gen_m16add32_q(TCGv ret,TCGv arg1,TCGv arg2,TCGv arg3,uint32_t n)1034fcf5ef2aSThomas Huth gen_m16add32_q(TCGv ret, TCGv arg1, TCGv arg2, TCGv arg3, uint32_t n)
1035fcf5ef2aSThomas Huth {
1036fcf5ef2aSThomas Huth TCGv temp = tcg_temp_new();
1037fcf5ef2aSThomas Huth TCGv temp2 = tcg_temp_new();
1038fcf5ef2aSThomas Huth if (n == 0) {
1039fcf5ef2aSThomas Huth tcg_gen_mul_tl(temp, arg2, arg3);
1040fcf5ef2aSThomas Huth } else { /* n is expected to be 1 */
1041fcf5ef2aSThomas Huth tcg_gen_mul_tl(temp, arg2, arg3);
1042fcf5ef2aSThomas Huth tcg_gen_shli_tl(temp, temp, 1);
1043fcf5ef2aSThomas Huth /* catch special case r1 = r2 = 0x8000 */
1044fcf5ef2aSThomas Huth tcg_gen_setcondi_tl(TCG_COND_EQ, temp2, temp, 0x80000000);
1045fcf5ef2aSThomas Huth tcg_gen_sub_tl(temp, temp, temp2);
1046fcf5ef2aSThomas Huth }
1047fcf5ef2aSThomas Huth gen_add_d(ret, arg1, temp);
1048fcf5ef2aSThomas Huth }
1049fcf5ef2aSThomas Huth
1050fcf5ef2aSThomas Huth static inline void
gen_m16adds32_q(TCGv ret,TCGv arg1,TCGv arg2,TCGv arg3,uint32_t n)1051fcf5ef2aSThomas Huth gen_m16adds32_q(TCGv ret, TCGv arg1, TCGv arg2, TCGv arg3, uint32_t n)
1052fcf5ef2aSThomas Huth {
1053fcf5ef2aSThomas Huth TCGv temp = tcg_temp_new();
1054fcf5ef2aSThomas Huth TCGv temp2 = tcg_temp_new();
1055fcf5ef2aSThomas Huth if (n == 0) {
1056fcf5ef2aSThomas Huth tcg_gen_mul_tl(temp, arg2, arg3);
1057fcf5ef2aSThomas Huth } else { /* n is expected to be 1 */
1058fcf5ef2aSThomas Huth tcg_gen_mul_tl(temp, arg2, arg3);
1059fcf5ef2aSThomas Huth tcg_gen_shli_tl(temp, temp, 1);
1060fcf5ef2aSThomas Huth /* catch special case r1 = r2 = 0x8000 */
1061fcf5ef2aSThomas Huth tcg_gen_setcondi_tl(TCG_COND_EQ, temp2, temp, 0x80000000);
1062fcf5ef2aSThomas Huth tcg_gen_sub_tl(temp, temp, temp2);
1063fcf5ef2aSThomas Huth }
1064fcf5ef2aSThomas Huth gen_adds(ret, arg1, temp);
1065fcf5ef2aSThomas Huth }
1066fcf5ef2aSThomas Huth
1067fcf5ef2aSThomas Huth static inline void
gen_m16add64_q(TCGv rl,TCGv rh,TCGv arg1_low,TCGv arg1_high,TCGv arg2,TCGv arg3,uint32_t n)1068fcf5ef2aSThomas Huth gen_m16add64_q(TCGv rl, TCGv rh, TCGv arg1_low, TCGv arg1_high, TCGv arg2,
1069fcf5ef2aSThomas Huth TCGv arg3, uint32_t n)
1070fcf5ef2aSThomas Huth {
1071fcf5ef2aSThomas Huth TCGv temp = tcg_temp_new();
1072fcf5ef2aSThomas Huth TCGv temp2 = tcg_temp_new();
1073fcf5ef2aSThomas Huth TCGv_i64 t1 = tcg_temp_new_i64();
1074fcf5ef2aSThomas Huth TCGv_i64 t2 = tcg_temp_new_i64();
1075fcf5ef2aSThomas Huth TCGv_i64 t3 = tcg_temp_new_i64();
1076fcf5ef2aSThomas Huth
1077fcf5ef2aSThomas Huth if (n == 0) {
1078fcf5ef2aSThomas Huth tcg_gen_mul_tl(temp, arg2, arg3);
1079fcf5ef2aSThomas Huth } else { /* n is expected to be 1 */
1080fcf5ef2aSThomas Huth tcg_gen_mul_tl(temp, arg2, arg3);
1081fcf5ef2aSThomas Huth tcg_gen_shli_tl(temp, temp, 1);
1082fcf5ef2aSThomas Huth /* catch special case r1 = r2 = 0x8000 */
1083fcf5ef2aSThomas Huth tcg_gen_setcondi_tl(TCG_COND_EQ, temp2, temp, 0x80000000);
1084fcf5ef2aSThomas Huth tcg_gen_sub_tl(temp, temp, temp2);
1085fcf5ef2aSThomas Huth }
1086fcf5ef2aSThomas Huth tcg_gen_ext_i32_i64(t2, temp);
1087fcf5ef2aSThomas Huth tcg_gen_shli_i64(t2, t2, 16);
1088fcf5ef2aSThomas Huth tcg_gen_concat_i32_i64(t1, arg1_low, arg1_high);
1089fcf5ef2aSThomas Huth gen_add64_d(t3, t1, t2);
1090fcf5ef2aSThomas Huth /* write back result */
1091fcf5ef2aSThomas Huth tcg_gen_extr_i64_i32(rl, rh, t3);
1092fcf5ef2aSThomas Huth }
1093fcf5ef2aSThomas Huth
1094fcf5ef2aSThomas Huth static inline void
gen_m16adds64_q(TCGv rl,TCGv rh,TCGv arg1_low,TCGv arg1_high,TCGv arg2,TCGv arg3,uint32_t n)1095fcf5ef2aSThomas Huth gen_m16adds64_q(TCGv rl, TCGv rh, TCGv arg1_low, TCGv arg1_high, TCGv arg2,
1096fcf5ef2aSThomas Huth TCGv arg3, uint32_t n)
1097fcf5ef2aSThomas Huth {
1098fcf5ef2aSThomas Huth TCGv temp = tcg_temp_new();
1099fcf5ef2aSThomas Huth TCGv temp2 = tcg_temp_new();
1100fcf5ef2aSThomas Huth TCGv_i64 t1 = tcg_temp_new_i64();
1101fcf5ef2aSThomas Huth TCGv_i64 t2 = tcg_temp_new_i64();
1102fcf5ef2aSThomas Huth
1103fcf5ef2aSThomas Huth if (n == 0) {
1104fcf5ef2aSThomas Huth tcg_gen_mul_tl(temp, arg2, arg3);
1105fcf5ef2aSThomas Huth } else { /* n is expected to be 1 */
1106fcf5ef2aSThomas Huth tcg_gen_mul_tl(temp, arg2, arg3);
1107fcf5ef2aSThomas Huth tcg_gen_shli_tl(temp, temp, 1);
1108fcf5ef2aSThomas Huth /* catch special case r1 = r2 = 0x8000 */
1109fcf5ef2aSThomas Huth tcg_gen_setcondi_tl(TCG_COND_EQ, temp2, temp, 0x80000000);
1110fcf5ef2aSThomas Huth tcg_gen_sub_tl(temp, temp, temp2);
1111fcf5ef2aSThomas Huth }
1112fcf5ef2aSThomas Huth tcg_gen_ext_i32_i64(t2, temp);
1113fcf5ef2aSThomas Huth tcg_gen_shli_i64(t2, t2, 16);
1114fcf5ef2aSThomas Huth tcg_gen_concat_i32_i64(t1, arg1_low, arg1_high);
1115fcf5ef2aSThomas Huth
1116ad75a51eSRichard Henderson gen_helper_add64_ssov(t1, tcg_env, t1, t2);
1117fcf5ef2aSThomas Huth tcg_gen_extr_i64_i32(rl, rh, t1);
1118fcf5ef2aSThomas Huth }
1119fcf5ef2aSThomas Huth
1120fcf5ef2aSThomas Huth static inline void
gen_madd64_q(TCGv rl,TCGv rh,TCGv arg1_low,TCGv arg1_high,TCGv arg2,TCGv arg3,uint32_t n)1121fcf5ef2aSThomas Huth gen_madd64_q(TCGv rl, TCGv rh, TCGv arg1_low, TCGv arg1_high, TCGv arg2,
11222db92a0cSBastian Koppelmann TCGv arg3, uint32_t n)
1123fcf5ef2aSThomas Huth {
1124fcf5ef2aSThomas Huth TCGv_i64 t1 = tcg_temp_new_i64();
1125fcf5ef2aSThomas Huth TCGv_i64 t2 = tcg_temp_new_i64();
1126fcf5ef2aSThomas Huth TCGv_i64 t3 = tcg_temp_new_i64();
1127fcf5ef2aSThomas Huth TCGv_i64 t4 = tcg_temp_new_i64();
1128fcf5ef2aSThomas Huth TCGv temp, temp2;
1129fcf5ef2aSThomas Huth
1130fcf5ef2aSThomas Huth tcg_gen_concat_i32_i64(t1, arg1_low, arg1_high);
1131fcf5ef2aSThomas Huth tcg_gen_ext_i32_i64(t2, arg2);
1132fcf5ef2aSThomas Huth tcg_gen_ext_i32_i64(t3, arg3);
1133fcf5ef2aSThomas Huth
1134fcf5ef2aSThomas Huth tcg_gen_mul_i64(t2, t2, t3);
1135fcf5ef2aSThomas Huth if (n != 0) {
1136fcf5ef2aSThomas Huth tcg_gen_shli_i64(t2, t2, 1);
1137fcf5ef2aSThomas Huth }
1138fcf5ef2aSThomas Huth tcg_gen_add_i64(t4, t1, t2);
1139fcf5ef2aSThomas Huth /* calc v bit */
1140fcf5ef2aSThomas Huth tcg_gen_xor_i64(t3, t4, t1);
1141fcf5ef2aSThomas Huth tcg_gen_xor_i64(t2, t1, t2);
1142fcf5ef2aSThomas Huth tcg_gen_andc_i64(t3, t3, t2);
1143fcf5ef2aSThomas Huth tcg_gen_extrh_i64_i32(cpu_PSW_V, t3);
1144fcf5ef2aSThomas Huth /* We produce an overflow on the host if the mul before was
1145fcf5ef2aSThomas Huth (0x80000000 * 0x80000000) << 1). If this is the
1146fcf5ef2aSThomas Huth case, we negate the ovf. */
1147fcf5ef2aSThomas Huth if (n == 1) {
1148fcf5ef2aSThomas Huth temp = tcg_temp_new();
1149fcf5ef2aSThomas Huth temp2 = tcg_temp_new();
1150fcf5ef2aSThomas Huth tcg_gen_setcondi_tl(TCG_COND_EQ, temp, arg2, 0x80000000);
1151fcf5ef2aSThomas Huth tcg_gen_setcond_tl(TCG_COND_EQ, temp2, arg2, arg3);
1152fcf5ef2aSThomas Huth tcg_gen_and_tl(temp, temp, temp2);
1153fcf5ef2aSThomas Huth tcg_gen_shli_tl(temp, temp, 31);
1154fcf5ef2aSThomas Huth /* negate v bit, if special condition */
1155fcf5ef2aSThomas Huth tcg_gen_xor_tl(cpu_PSW_V, cpu_PSW_V, temp);
1156fcf5ef2aSThomas Huth }
1157fcf5ef2aSThomas Huth /* write back result */
1158fcf5ef2aSThomas Huth tcg_gen_extr_i64_i32(rl, rh, t4);
1159fcf5ef2aSThomas Huth /* Calc SV bit */
1160fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SV, cpu_PSW_SV, cpu_PSW_V);
1161fcf5ef2aSThomas Huth /* Calc AV/SAV bits */
1162fcf5ef2aSThomas Huth tcg_gen_add_tl(cpu_PSW_AV, rh, rh);
1163fcf5ef2aSThomas Huth tcg_gen_xor_tl(cpu_PSW_AV, rh, cpu_PSW_AV);
1164fcf5ef2aSThomas Huth /* calc SAV */
1165fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SAV, cpu_PSW_SAV, cpu_PSW_AV);
1166fcf5ef2aSThomas Huth }
1167fcf5ef2aSThomas Huth
1168fcf5ef2aSThomas Huth static inline void
gen_madds32_q(TCGv ret,TCGv arg1,TCGv arg2,TCGv arg3,uint32_t n,uint32_t up_shift)1169fcf5ef2aSThomas Huth gen_madds32_q(TCGv ret, TCGv arg1, TCGv arg2, TCGv arg3, uint32_t n,
1170fcf5ef2aSThomas Huth uint32_t up_shift)
1171fcf5ef2aSThomas Huth {
1172fcf5ef2aSThomas Huth TCGv_i64 t1 = tcg_temp_new_i64();
1173fcf5ef2aSThomas Huth TCGv_i64 t2 = tcg_temp_new_i64();
1174fcf5ef2aSThomas Huth TCGv_i64 t3 = tcg_temp_new_i64();
1175fcf5ef2aSThomas Huth
1176fcf5ef2aSThomas Huth tcg_gen_ext_i32_i64(t1, arg1);
1177fcf5ef2aSThomas Huth tcg_gen_ext_i32_i64(t2, arg2);
1178fcf5ef2aSThomas Huth tcg_gen_ext_i32_i64(t3, arg3);
1179fcf5ef2aSThomas Huth
1180fcf5ef2aSThomas Huth tcg_gen_mul_i64(t2, t2, t3);
1181fcf5ef2aSThomas Huth tcg_gen_sari_i64(t2, t2, up_shift - n);
1182fcf5ef2aSThomas Huth
1183ad75a51eSRichard Henderson gen_helper_madd32_q_add_ssov(ret, tcg_env, t1, t2);
1184fcf5ef2aSThomas Huth }
1185fcf5ef2aSThomas Huth
1186fcf5ef2aSThomas Huth static inline void
gen_madds64_q(TCGv rl,TCGv rh,TCGv arg1_low,TCGv arg1_high,TCGv arg2,TCGv arg3,uint32_t n)1187fcf5ef2aSThomas Huth gen_madds64_q(TCGv rl, TCGv rh, TCGv arg1_low, TCGv arg1_high, TCGv arg2,
1188fcf5ef2aSThomas Huth TCGv arg3, uint32_t n)
1189fcf5ef2aSThomas Huth {
1190fcf5ef2aSThomas Huth TCGv_i64 r1 = tcg_temp_new_i64();
1191bf38ca5cSRichard Henderson TCGv t_n = tcg_constant_i32(n);
1192fcf5ef2aSThomas Huth
1193fcf5ef2aSThomas Huth tcg_gen_concat_i32_i64(r1, arg1_low, arg1_high);
1194ad75a51eSRichard Henderson gen_helper_madd64_q_ssov(r1, tcg_env, r1, arg2, arg3, t_n);
1195fcf5ef2aSThomas Huth tcg_gen_extr_i64_i32(rl, rh, r1);
1196fcf5ef2aSThomas Huth }
119708ee498bSRichard Henderson
1198fcf5ef2aSThomas Huth /* ret = r2 - (r1 * r3); */
gen_msub32_d(TCGv ret,TCGv r1,TCGv r2,TCGv r3)1199fcf5ef2aSThomas Huth static inline void gen_msub32_d(TCGv ret, TCGv r1, TCGv r2, TCGv r3)
1200fcf5ef2aSThomas Huth {
1201fcf5ef2aSThomas Huth TCGv_i64 t1 = tcg_temp_new_i64();
1202fcf5ef2aSThomas Huth TCGv_i64 t2 = tcg_temp_new_i64();
1203fcf5ef2aSThomas Huth TCGv_i64 t3 = tcg_temp_new_i64();
1204fcf5ef2aSThomas Huth
1205fcf5ef2aSThomas Huth tcg_gen_ext_i32_i64(t1, r1);
1206fcf5ef2aSThomas Huth tcg_gen_ext_i32_i64(t2, r2);
1207fcf5ef2aSThomas Huth tcg_gen_ext_i32_i64(t3, r3);
1208fcf5ef2aSThomas Huth
1209fcf5ef2aSThomas Huth tcg_gen_mul_i64(t1, t1, t3);
1210fcf5ef2aSThomas Huth tcg_gen_sub_i64(t1, t2, t1);
1211fcf5ef2aSThomas Huth
1212fcf5ef2aSThomas Huth tcg_gen_extrl_i64_i32(ret, t1);
1213fcf5ef2aSThomas Huth /* calc V
1214fcf5ef2aSThomas Huth t2 > 0x7fffffff */
1215fcf5ef2aSThomas Huth tcg_gen_setcondi_i64(TCG_COND_GT, t3, t1, 0x7fffffffLL);
1216fcf5ef2aSThomas Huth /* result < -0x80000000 */
1217fcf5ef2aSThomas Huth tcg_gen_setcondi_i64(TCG_COND_LT, t2, t1, -0x80000000LL);
1218fcf5ef2aSThomas Huth tcg_gen_or_i64(t2, t2, t3);
1219fcf5ef2aSThomas Huth tcg_gen_extrl_i64_i32(cpu_PSW_V, t2);
1220fcf5ef2aSThomas Huth tcg_gen_shli_tl(cpu_PSW_V, cpu_PSW_V, 31);
1221fcf5ef2aSThomas Huth
1222fcf5ef2aSThomas Huth /* Calc SV bit */
1223fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SV, cpu_PSW_SV, cpu_PSW_V);
1224fcf5ef2aSThomas Huth /* Calc AV/SAV bits */
1225fcf5ef2aSThomas Huth tcg_gen_add_tl(cpu_PSW_AV, ret, ret);
1226fcf5ef2aSThomas Huth tcg_gen_xor_tl(cpu_PSW_AV, ret, cpu_PSW_AV);
1227fcf5ef2aSThomas Huth /* calc SAV */
1228fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SAV, cpu_PSW_SAV, cpu_PSW_AV);
1229fcf5ef2aSThomas Huth }
1230fcf5ef2aSThomas Huth
gen_msubi32_d(TCGv ret,TCGv r1,TCGv r2,int32_t con)1231fcf5ef2aSThomas Huth static inline void gen_msubi32_d(TCGv ret, TCGv r1, TCGv r2, int32_t con)
1232fcf5ef2aSThomas Huth {
1233151293c2SRichard Henderson TCGv temp = tcg_constant_i32(con);
1234fcf5ef2aSThomas Huth gen_msub32_d(ret, r1, r2, temp);
1235fcf5ef2aSThomas Huth }
1236fcf5ef2aSThomas Huth
1237fcf5ef2aSThomas Huth static inline void
gen_msub64_d(TCGv ret_low,TCGv ret_high,TCGv r1,TCGv r2_low,TCGv r2_high,TCGv r3)1238fcf5ef2aSThomas Huth gen_msub64_d(TCGv ret_low, TCGv ret_high, TCGv r1, TCGv r2_low, TCGv r2_high,
1239fcf5ef2aSThomas Huth TCGv r3)
1240fcf5ef2aSThomas Huth {
1241fcf5ef2aSThomas Huth TCGv t1 = tcg_temp_new();
1242fcf5ef2aSThomas Huth TCGv t2 = tcg_temp_new();
1243fcf5ef2aSThomas Huth TCGv t3 = tcg_temp_new();
1244fcf5ef2aSThomas Huth TCGv t4 = tcg_temp_new();
1245fcf5ef2aSThomas Huth
1246fcf5ef2aSThomas Huth tcg_gen_muls2_tl(t1, t2, r1, r3);
1247fcf5ef2aSThomas Huth /* only the sub can overflow */
1248fcf5ef2aSThomas Huth tcg_gen_sub2_tl(t3, t4, r2_low, r2_high, t1, t2);
1249fcf5ef2aSThomas Huth /* calc V bit */
1250fcf5ef2aSThomas Huth tcg_gen_xor_tl(cpu_PSW_V, t4, r2_high);
1251fcf5ef2aSThomas Huth tcg_gen_xor_tl(t1, r2_high, t2);
1252fcf5ef2aSThomas Huth tcg_gen_and_tl(cpu_PSW_V, cpu_PSW_V, t1);
1253fcf5ef2aSThomas Huth /* Calc SV bit */
1254fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SV, cpu_PSW_SV, cpu_PSW_V);
1255fcf5ef2aSThomas Huth /* Calc AV/SAV bits */
1256fcf5ef2aSThomas Huth tcg_gen_add_tl(cpu_PSW_AV, t4, t4);
1257fcf5ef2aSThomas Huth tcg_gen_xor_tl(cpu_PSW_AV, t4, cpu_PSW_AV);
1258fcf5ef2aSThomas Huth /* calc SAV */
1259fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SAV, cpu_PSW_SAV, cpu_PSW_AV);
1260fcf5ef2aSThomas Huth /* write back the result */
1261fcf5ef2aSThomas Huth tcg_gen_mov_tl(ret_low, t3);
1262fcf5ef2aSThomas Huth tcg_gen_mov_tl(ret_high, t4);
1263fcf5ef2aSThomas Huth }
1264fcf5ef2aSThomas Huth
1265fcf5ef2aSThomas Huth static inline void
gen_msubi64_d(TCGv ret_low,TCGv ret_high,TCGv r1,TCGv r2_low,TCGv r2_high,int32_t con)1266fcf5ef2aSThomas Huth gen_msubi64_d(TCGv ret_low, TCGv ret_high, TCGv r1, TCGv r2_low, TCGv r2_high,
1267fcf5ef2aSThomas Huth int32_t con)
1268fcf5ef2aSThomas Huth {
1269151293c2SRichard Henderson TCGv temp = tcg_constant_i32(con);
1270fcf5ef2aSThomas Huth gen_msub64_d(ret_low, ret_high, r1, r2_low, r2_high, temp);
1271fcf5ef2aSThomas Huth }
1272fcf5ef2aSThomas Huth
1273fcf5ef2aSThomas Huth static inline void
gen_msubu64_d(TCGv ret_low,TCGv ret_high,TCGv r1,TCGv r2_low,TCGv r2_high,TCGv r3)1274fcf5ef2aSThomas Huth gen_msubu64_d(TCGv ret_low, TCGv ret_high, TCGv r1, TCGv r2_low, TCGv r2_high,
1275fcf5ef2aSThomas Huth TCGv r3)
1276fcf5ef2aSThomas Huth {
1277fcf5ef2aSThomas Huth TCGv_i64 t1 = tcg_temp_new_i64();
1278fcf5ef2aSThomas Huth TCGv_i64 t2 = tcg_temp_new_i64();
1279fcf5ef2aSThomas Huth TCGv_i64 t3 = tcg_temp_new_i64();
1280fcf5ef2aSThomas Huth
1281fcf5ef2aSThomas Huth tcg_gen_extu_i32_i64(t1, r1);
1282fcf5ef2aSThomas Huth tcg_gen_concat_i32_i64(t2, r2_low, r2_high);
1283fcf5ef2aSThomas Huth tcg_gen_extu_i32_i64(t3, r3);
1284fcf5ef2aSThomas Huth
1285fcf5ef2aSThomas Huth tcg_gen_mul_i64(t1, t1, t3);
1286fcf5ef2aSThomas Huth tcg_gen_sub_i64(t3, t2, t1);
1287fcf5ef2aSThomas Huth tcg_gen_extr_i64_i32(ret_low, ret_high, t3);
1288fcf5ef2aSThomas Huth /* calc V bit, only the sub can overflow, if t1 > t2 */
1289fcf5ef2aSThomas Huth tcg_gen_setcond_i64(TCG_COND_GTU, t1, t1, t2);
1290fcf5ef2aSThomas Huth tcg_gen_extrl_i64_i32(cpu_PSW_V, t1);
1291fcf5ef2aSThomas Huth tcg_gen_shli_tl(cpu_PSW_V, cpu_PSW_V, 31);
1292fcf5ef2aSThomas Huth /* Calc SV bit */
1293fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SV, cpu_PSW_SV, cpu_PSW_V);
1294fcf5ef2aSThomas Huth /* Calc AV/SAV bits */
1295fcf5ef2aSThomas Huth tcg_gen_add_tl(cpu_PSW_AV, ret_high, ret_high);
1296fcf5ef2aSThomas Huth tcg_gen_xor_tl(cpu_PSW_AV, ret_high, cpu_PSW_AV);
1297fcf5ef2aSThomas Huth /* calc SAV */
1298fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SAV, cpu_PSW_SAV, cpu_PSW_AV);
1299fcf5ef2aSThomas Huth }
1300fcf5ef2aSThomas Huth
1301fcf5ef2aSThomas Huth static inline void
gen_msubui64_d(TCGv ret_low,TCGv ret_high,TCGv r1,TCGv r2_low,TCGv r2_high,int32_t con)1302fcf5ef2aSThomas Huth gen_msubui64_d(TCGv ret_low, TCGv ret_high, TCGv r1, TCGv r2_low, TCGv r2_high,
1303fcf5ef2aSThomas Huth int32_t con)
1304fcf5ef2aSThomas Huth {
1305151293c2SRichard Henderson TCGv temp = tcg_constant_i32(con);
1306fcf5ef2aSThomas Huth gen_msubu64_d(ret_low, ret_high, r1, r2_low, r2_high, temp);
1307fcf5ef2aSThomas Huth }
1308fcf5ef2aSThomas Huth
gen_addi_d(TCGv ret,TCGv r1,target_ulong r2)1309fcf5ef2aSThomas Huth static inline void gen_addi_d(TCGv ret, TCGv r1, target_ulong r2)
1310fcf5ef2aSThomas Huth {
1311151293c2SRichard Henderson TCGv temp = tcg_constant_i32(r2);
1312fcf5ef2aSThomas Huth gen_add_d(ret, r1, temp);
1313fcf5ef2aSThomas Huth }
131408ee498bSRichard Henderson
1315fcf5ef2aSThomas Huth /* calculate the carry bit too */
gen_add_CC(TCGv ret,TCGv r1,TCGv r2)1316fcf5ef2aSThomas Huth static inline void gen_add_CC(TCGv ret, TCGv r1, TCGv r2)
1317fcf5ef2aSThomas Huth {
1318fcf5ef2aSThomas Huth TCGv t0 = tcg_temp_new_i32();
1319fcf5ef2aSThomas Huth TCGv result = tcg_temp_new_i32();
1320fcf5ef2aSThomas Huth
1321fcf5ef2aSThomas Huth tcg_gen_movi_tl(t0, 0);
1322fcf5ef2aSThomas Huth /* Addition and set C/V/SV bits */
1323fcf5ef2aSThomas Huth tcg_gen_add2_i32(result, cpu_PSW_C, r1, t0, r2, t0);
1324fcf5ef2aSThomas Huth /* calc V bit */
1325fcf5ef2aSThomas Huth tcg_gen_xor_tl(cpu_PSW_V, result, r1);
1326fcf5ef2aSThomas Huth tcg_gen_xor_tl(t0, r1, r2);
1327fcf5ef2aSThomas Huth tcg_gen_andc_tl(cpu_PSW_V, cpu_PSW_V, t0);
1328fcf5ef2aSThomas Huth /* Calc SV bit */
1329fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SV, cpu_PSW_SV, cpu_PSW_V);
1330fcf5ef2aSThomas Huth /* Calc AV/SAV bits */
1331fcf5ef2aSThomas Huth tcg_gen_add_tl(cpu_PSW_AV, result, result);
1332fcf5ef2aSThomas Huth tcg_gen_xor_tl(cpu_PSW_AV, result, cpu_PSW_AV);
1333fcf5ef2aSThomas Huth /* calc SAV */
1334fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SAV, cpu_PSW_SAV, cpu_PSW_AV);
1335fcf5ef2aSThomas Huth /* write back result */
1336fcf5ef2aSThomas Huth tcg_gen_mov_tl(ret, result);
1337fcf5ef2aSThomas Huth }
1338fcf5ef2aSThomas Huth
gen_addi_CC(TCGv ret,TCGv r1,int32_t con)1339fcf5ef2aSThomas Huth static inline void gen_addi_CC(TCGv ret, TCGv r1, int32_t con)
1340fcf5ef2aSThomas Huth {
1341151293c2SRichard Henderson TCGv temp = tcg_constant_i32(con);
1342fcf5ef2aSThomas Huth gen_add_CC(ret, r1, temp);
1343fcf5ef2aSThomas Huth }
1344fcf5ef2aSThomas Huth
gen_addc_CC(TCGv ret,TCGv r1,TCGv r2)1345fcf5ef2aSThomas Huth static inline void gen_addc_CC(TCGv ret, TCGv r1, TCGv r2)
1346fcf5ef2aSThomas Huth {
1347fcf5ef2aSThomas Huth TCGv carry = tcg_temp_new_i32();
1348fcf5ef2aSThomas Huth TCGv t0 = tcg_temp_new_i32();
1349fcf5ef2aSThomas Huth TCGv result = tcg_temp_new_i32();
1350fcf5ef2aSThomas Huth
1351fcf5ef2aSThomas Huth tcg_gen_movi_tl(t0, 0);
1352fcf5ef2aSThomas Huth tcg_gen_setcondi_tl(TCG_COND_NE, carry, cpu_PSW_C, 0);
1353fcf5ef2aSThomas Huth /* Addition, carry and set C/V/SV bits */
1354fcf5ef2aSThomas Huth tcg_gen_add2_i32(result, cpu_PSW_C, r1, t0, carry, t0);
1355fcf5ef2aSThomas Huth tcg_gen_add2_i32(result, cpu_PSW_C, result, cpu_PSW_C, r2, t0);
1356fcf5ef2aSThomas Huth /* calc V bit */
1357fcf5ef2aSThomas Huth tcg_gen_xor_tl(cpu_PSW_V, result, r1);
1358fcf5ef2aSThomas Huth tcg_gen_xor_tl(t0, r1, r2);
1359fcf5ef2aSThomas Huth tcg_gen_andc_tl(cpu_PSW_V, cpu_PSW_V, t0);
1360fcf5ef2aSThomas Huth /* Calc SV bit */
1361fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SV, cpu_PSW_SV, cpu_PSW_V);
1362fcf5ef2aSThomas Huth /* Calc AV/SAV bits */
1363fcf5ef2aSThomas Huth tcg_gen_add_tl(cpu_PSW_AV, result, result);
1364fcf5ef2aSThomas Huth tcg_gen_xor_tl(cpu_PSW_AV, result, cpu_PSW_AV);
1365fcf5ef2aSThomas Huth /* calc SAV */
1366fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SAV, cpu_PSW_SAV, cpu_PSW_AV);
1367fcf5ef2aSThomas Huth /* write back result */
1368fcf5ef2aSThomas Huth tcg_gen_mov_tl(ret, result);
1369fcf5ef2aSThomas Huth }
1370fcf5ef2aSThomas Huth
gen_addci_CC(TCGv ret,TCGv r1,int32_t con)1371fcf5ef2aSThomas Huth static inline void gen_addci_CC(TCGv ret, TCGv r1, int32_t con)
1372fcf5ef2aSThomas Huth {
1373151293c2SRichard Henderson TCGv temp = tcg_constant_i32(con);
1374fcf5ef2aSThomas Huth gen_addc_CC(ret, r1, temp);
1375fcf5ef2aSThomas Huth }
1376fcf5ef2aSThomas Huth
gen_cond_add(TCGCond cond,TCGv r1,TCGv r2,TCGv r3,TCGv r4)1377fcf5ef2aSThomas Huth static inline void gen_cond_add(TCGCond cond, TCGv r1, TCGv r2, TCGv r3,
1378fcf5ef2aSThomas Huth TCGv r4)
1379fcf5ef2aSThomas Huth {
1380fcf5ef2aSThomas Huth TCGv temp = tcg_temp_new();
1381fcf5ef2aSThomas Huth TCGv temp2 = tcg_temp_new();
1382fcf5ef2aSThomas Huth TCGv result = tcg_temp_new();
1383fcf5ef2aSThomas Huth TCGv mask = tcg_temp_new();
1384151293c2SRichard Henderson TCGv t0 = tcg_constant_i32(0);
1385fcf5ef2aSThomas Huth
1386fcf5ef2aSThomas Huth /* create mask for sticky bits */
1387fcf5ef2aSThomas Huth tcg_gen_setcond_tl(cond, mask, r4, t0);
1388fcf5ef2aSThomas Huth tcg_gen_shli_tl(mask, mask, 31);
1389fcf5ef2aSThomas Huth
1390fcf5ef2aSThomas Huth tcg_gen_add_tl(result, r1, r2);
1391fcf5ef2aSThomas Huth /* Calc PSW_V */
1392fcf5ef2aSThomas Huth tcg_gen_xor_tl(temp, result, r1);
1393fcf5ef2aSThomas Huth tcg_gen_xor_tl(temp2, r1, r2);
1394fcf5ef2aSThomas Huth tcg_gen_andc_tl(temp, temp, temp2);
1395fcf5ef2aSThomas Huth tcg_gen_movcond_tl(cond, cpu_PSW_V, r4, t0, temp, cpu_PSW_V);
1396fcf5ef2aSThomas Huth /* Set PSW_SV */
1397fcf5ef2aSThomas Huth tcg_gen_and_tl(temp, temp, mask);
1398fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SV, temp, cpu_PSW_SV);
1399fcf5ef2aSThomas Huth /* calc AV bit */
1400fcf5ef2aSThomas Huth tcg_gen_add_tl(temp, result, result);
1401fcf5ef2aSThomas Huth tcg_gen_xor_tl(temp, temp, result);
1402fcf5ef2aSThomas Huth tcg_gen_movcond_tl(cond, cpu_PSW_AV, r4, t0, temp, cpu_PSW_AV);
1403fcf5ef2aSThomas Huth /* calc SAV bit */
1404fcf5ef2aSThomas Huth tcg_gen_and_tl(temp, temp, mask);
1405fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SAV, temp, cpu_PSW_SAV);
1406fcf5ef2aSThomas Huth /* write back result */
1407fcf5ef2aSThomas Huth tcg_gen_movcond_tl(cond, r3, r4, t0, result, r1);
1408fcf5ef2aSThomas Huth }
1409fcf5ef2aSThomas Huth
gen_condi_add(TCGCond cond,TCGv r1,int32_t r2,TCGv r3,TCGv r4)1410fcf5ef2aSThomas Huth static inline void gen_condi_add(TCGCond cond, TCGv r1, int32_t r2,
1411fcf5ef2aSThomas Huth TCGv r3, TCGv r4)
1412fcf5ef2aSThomas Huth {
1413151293c2SRichard Henderson TCGv temp = tcg_constant_i32(r2);
1414fcf5ef2aSThomas Huth gen_cond_add(cond, r1, temp, r3, r4);
1415fcf5ef2aSThomas Huth }
1416fcf5ef2aSThomas Huth
gen_sub_d(TCGv ret,TCGv r1,TCGv r2)1417fcf5ef2aSThomas Huth static inline void gen_sub_d(TCGv ret, TCGv r1, TCGv r2)
1418fcf5ef2aSThomas Huth {
1419fcf5ef2aSThomas Huth TCGv temp = tcg_temp_new_i32();
1420fcf5ef2aSThomas Huth TCGv result = tcg_temp_new_i32();
1421fcf5ef2aSThomas Huth
1422fcf5ef2aSThomas Huth tcg_gen_sub_tl(result, r1, r2);
1423fcf5ef2aSThomas Huth /* calc V bit */
1424fcf5ef2aSThomas Huth tcg_gen_xor_tl(cpu_PSW_V, result, r1);
1425fcf5ef2aSThomas Huth tcg_gen_xor_tl(temp, r1, r2);
1426fcf5ef2aSThomas Huth tcg_gen_and_tl(cpu_PSW_V, cpu_PSW_V, temp);
1427fcf5ef2aSThomas Huth /* calc SV bit */
1428fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SV, cpu_PSW_SV, cpu_PSW_V);
1429fcf5ef2aSThomas Huth /* Calc AV bit */
1430fcf5ef2aSThomas Huth tcg_gen_add_tl(cpu_PSW_AV, result, result);
1431fcf5ef2aSThomas Huth tcg_gen_xor_tl(cpu_PSW_AV, result, cpu_PSW_AV);
1432fcf5ef2aSThomas Huth /* calc SAV bit */
1433fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SAV, cpu_PSW_SAV, cpu_PSW_AV);
1434fcf5ef2aSThomas Huth /* write back result */
1435fcf5ef2aSThomas Huth tcg_gen_mov_tl(ret, result);
1436fcf5ef2aSThomas Huth }
1437fcf5ef2aSThomas Huth
1438fcf5ef2aSThomas Huth static inline void
gen_sub64_d(TCGv_i64 ret,TCGv_i64 r1,TCGv_i64 r2)1439fcf5ef2aSThomas Huth gen_sub64_d(TCGv_i64 ret, TCGv_i64 r1, TCGv_i64 r2)
1440fcf5ef2aSThomas Huth {
1441fcf5ef2aSThomas Huth TCGv temp = tcg_temp_new();
1442fcf5ef2aSThomas Huth TCGv_i64 t0 = tcg_temp_new_i64();
1443fcf5ef2aSThomas Huth TCGv_i64 t1 = tcg_temp_new_i64();
1444fcf5ef2aSThomas Huth TCGv_i64 result = tcg_temp_new_i64();
1445fcf5ef2aSThomas Huth
1446fcf5ef2aSThomas Huth tcg_gen_sub_i64(result, r1, r2);
1447fcf5ef2aSThomas Huth /* calc v bit */
1448fcf5ef2aSThomas Huth tcg_gen_xor_i64(t1, result, r1);
1449fcf5ef2aSThomas Huth tcg_gen_xor_i64(t0, r1, r2);
1450fcf5ef2aSThomas Huth tcg_gen_and_i64(t1, t1, t0);
1451fcf5ef2aSThomas Huth tcg_gen_extrh_i64_i32(cpu_PSW_V, t1);
1452fcf5ef2aSThomas Huth /* calc SV bit */
1453fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SV, cpu_PSW_SV, cpu_PSW_V);
1454fcf5ef2aSThomas Huth /* calc AV/SAV bits */
1455fcf5ef2aSThomas Huth tcg_gen_extrh_i64_i32(temp, result);
1456fcf5ef2aSThomas Huth tcg_gen_add_tl(cpu_PSW_AV, temp, temp);
1457fcf5ef2aSThomas Huth tcg_gen_xor_tl(cpu_PSW_AV, temp, cpu_PSW_AV);
1458fcf5ef2aSThomas Huth /* calc SAV */
1459fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SAV, cpu_PSW_SAV, cpu_PSW_AV);
1460fcf5ef2aSThomas Huth /* write back result */
1461fcf5ef2aSThomas Huth tcg_gen_mov_i64(ret, result);
1462fcf5ef2aSThomas Huth }
1463fcf5ef2aSThomas Huth
gen_sub_CC(TCGv ret,TCGv r1,TCGv r2)1464fcf5ef2aSThomas Huth static inline void gen_sub_CC(TCGv ret, TCGv r1, TCGv r2)
1465fcf5ef2aSThomas Huth {
1466fcf5ef2aSThomas Huth TCGv result = tcg_temp_new();
1467fcf5ef2aSThomas Huth TCGv temp = tcg_temp_new();
1468fcf5ef2aSThomas Huth
1469fcf5ef2aSThomas Huth tcg_gen_sub_tl(result, r1, r2);
1470fcf5ef2aSThomas Huth /* calc C bit */
1471fcf5ef2aSThomas Huth tcg_gen_setcond_tl(TCG_COND_GEU, cpu_PSW_C, r1, r2);
1472fcf5ef2aSThomas Huth /* calc V bit */
1473fcf5ef2aSThomas Huth tcg_gen_xor_tl(cpu_PSW_V, result, r1);
1474fcf5ef2aSThomas Huth tcg_gen_xor_tl(temp, r1, r2);
1475fcf5ef2aSThomas Huth tcg_gen_and_tl(cpu_PSW_V, cpu_PSW_V, temp);
1476fcf5ef2aSThomas Huth /* calc SV bit */
1477fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SV, cpu_PSW_SV, cpu_PSW_V);
1478fcf5ef2aSThomas Huth /* Calc AV bit */
1479fcf5ef2aSThomas Huth tcg_gen_add_tl(cpu_PSW_AV, result, result);
1480fcf5ef2aSThomas Huth tcg_gen_xor_tl(cpu_PSW_AV, result, cpu_PSW_AV);
1481fcf5ef2aSThomas Huth /* calc SAV bit */
1482fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SAV, cpu_PSW_SAV, cpu_PSW_AV);
1483fcf5ef2aSThomas Huth /* write back result */
1484fcf5ef2aSThomas Huth tcg_gen_mov_tl(ret, result);
1485fcf5ef2aSThomas Huth }
1486fcf5ef2aSThomas Huth
gen_subc_CC(TCGv ret,TCGv r1,TCGv r2)1487fcf5ef2aSThomas Huth static inline void gen_subc_CC(TCGv ret, TCGv r1, TCGv r2)
1488fcf5ef2aSThomas Huth {
1489fcf5ef2aSThomas Huth TCGv temp = tcg_temp_new();
1490fcf5ef2aSThomas Huth tcg_gen_not_tl(temp, r2);
1491fcf5ef2aSThomas Huth gen_addc_CC(ret, r1, temp);
1492fcf5ef2aSThomas Huth }
1493fcf5ef2aSThomas Huth
gen_cond_sub(TCGCond cond,TCGv r1,TCGv r2,TCGv r3,TCGv r4)1494fcf5ef2aSThomas Huth static inline void gen_cond_sub(TCGCond cond, TCGv r1, TCGv r2, TCGv r3,
1495fcf5ef2aSThomas Huth TCGv r4)
1496fcf5ef2aSThomas Huth {
1497fcf5ef2aSThomas Huth TCGv temp = tcg_temp_new();
1498fcf5ef2aSThomas Huth TCGv temp2 = tcg_temp_new();
1499fcf5ef2aSThomas Huth TCGv result = tcg_temp_new();
1500fcf5ef2aSThomas Huth TCGv mask = tcg_temp_new();
1501151293c2SRichard Henderson TCGv t0 = tcg_constant_i32(0);
1502fcf5ef2aSThomas Huth
1503fcf5ef2aSThomas Huth /* create mask for sticky bits */
1504fcf5ef2aSThomas Huth tcg_gen_setcond_tl(cond, mask, r4, t0);
1505fcf5ef2aSThomas Huth tcg_gen_shli_tl(mask, mask, 31);
1506fcf5ef2aSThomas Huth
1507fcf5ef2aSThomas Huth tcg_gen_sub_tl(result, r1, r2);
1508fcf5ef2aSThomas Huth /* Calc PSW_V */
1509fcf5ef2aSThomas Huth tcg_gen_xor_tl(temp, result, r1);
1510fcf5ef2aSThomas Huth tcg_gen_xor_tl(temp2, r1, r2);
1511fcf5ef2aSThomas Huth tcg_gen_and_tl(temp, temp, temp2);
1512fcf5ef2aSThomas Huth tcg_gen_movcond_tl(cond, cpu_PSW_V, r4, t0, temp, cpu_PSW_V);
1513fcf5ef2aSThomas Huth /* Set PSW_SV */
1514fcf5ef2aSThomas Huth tcg_gen_and_tl(temp, temp, mask);
1515fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SV, temp, cpu_PSW_SV);
1516fcf5ef2aSThomas Huth /* calc AV bit */
1517fcf5ef2aSThomas Huth tcg_gen_add_tl(temp, result, result);
1518fcf5ef2aSThomas Huth tcg_gen_xor_tl(temp, temp, result);
1519fcf5ef2aSThomas Huth tcg_gen_movcond_tl(cond, cpu_PSW_AV, r4, t0, temp, cpu_PSW_AV);
1520fcf5ef2aSThomas Huth /* calc SAV bit */
1521fcf5ef2aSThomas Huth tcg_gen_and_tl(temp, temp, mask);
1522fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SAV, temp, cpu_PSW_SAV);
1523fcf5ef2aSThomas Huth /* write back result */
1524fcf5ef2aSThomas Huth tcg_gen_movcond_tl(cond, r3, r4, t0, result, r1);
1525fcf5ef2aSThomas Huth }
1526fcf5ef2aSThomas Huth
1527fcf5ef2aSThomas Huth static inline void
gen_msub_h(TCGv ret_low,TCGv ret_high,TCGv r1_low,TCGv r1_high,TCGv r2,TCGv r3,uint32_t n,uint32_t mode)1528fcf5ef2aSThomas Huth gen_msub_h(TCGv ret_low, TCGv ret_high, TCGv r1_low, TCGv r1_high, TCGv r2,
1529fcf5ef2aSThomas Huth TCGv r3, uint32_t n, uint32_t mode)
1530fcf5ef2aSThomas Huth {
1531bf38ca5cSRichard Henderson TCGv t_n = tcg_constant_i32(n);
1532bf38ca5cSRichard Henderson TCGv temp = tcg_temp_new();
1533fcf5ef2aSThomas Huth TCGv temp2 = tcg_temp_new();
1534fcf5ef2aSThomas Huth TCGv_i64 temp64 = tcg_temp_new_i64();
1535fcf5ef2aSThomas Huth switch (mode) {
1536fcf5ef2aSThomas Huth case MODE_LL:
1537bf38ca5cSRichard Henderson GEN_HELPER_LL(mul_h, temp64, r2, r3, t_n);
1538fcf5ef2aSThomas Huth break;
1539fcf5ef2aSThomas Huth case MODE_LU:
1540bf38ca5cSRichard Henderson GEN_HELPER_LU(mul_h, temp64, r2, r3, t_n);
1541fcf5ef2aSThomas Huth break;
1542fcf5ef2aSThomas Huth case MODE_UL:
1543bf38ca5cSRichard Henderson GEN_HELPER_UL(mul_h, temp64, r2, r3, t_n);
1544fcf5ef2aSThomas Huth break;
1545fcf5ef2aSThomas Huth case MODE_UU:
1546bf38ca5cSRichard Henderson GEN_HELPER_UU(mul_h, temp64, r2, r3, t_n);
1547fcf5ef2aSThomas Huth break;
1548fcf5ef2aSThomas Huth }
1549fcf5ef2aSThomas Huth tcg_gen_extr_i64_i32(temp, temp2, temp64);
1550fcf5ef2aSThomas Huth gen_addsub64_h(ret_low, ret_high, r1_low, r1_high, temp, temp2,
1551fcf5ef2aSThomas Huth tcg_gen_sub_tl, tcg_gen_sub_tl);
1552fcf5ef2aSThomas Huth }
1553fcf5ef2aSThomas Huth
1554fcf5ef2aSThomas Huth static inline void
gen_msubs_h(TCGv ret_low,TCGv ret_high,TCGv r1_low,TCGv r1_high,TCGv r2,TCGv r3,uint32_t n,uint32_t mode)1555fcf5ef2aSThomas Huth gen_msubs_h(TCGv ret_low, TCGv ret_high, TCGv r1_low, TCGv r1_high, TCGv r2,
1556fcf5ef2aSThomas Huth TCGv r3, uint32_t n, uint32_t mode)
1557fcf5ef2aSThomas Huth {
1558bf38ca5cSRichard Henderson TCGv t_n = tcg_constant_i32(n);
1559bf38ca5cSRichard Henderson TCGv temp = tcg_temp_new();
1560fcf5ef2aSThomas Huth TCGv temp2 = tcg_temp_new();
1561fcf5ef2aSThomas Huth TCGv temp3 = tcg_temp_new();
1562fcf5ef2aSThomas Huth TCGv_i64 temp64 = tcg_temp_new_i64();
1563fcf5ef2aSThomas Huth
1564fcf5ef2aSThomas Huth switch (mode) {
1565fcf5ef2aSThomas Huth case MODE_LL:
1566bf38ca5cSRichard Henderson GEN_HELPER_LL(mul_h, temp64, r2, r3, t_n);
1567fcf5ef2aSThomas Huth break;
1568fcf5ef2aSThomas Huth case MODE_LU:
1569bf38ca5cSRichard Henderson GEN_HELPER_LU(mul_h, temp64, r2, r3, t_n);
1570fcf5ef2aSThomas Huth break;
1571fcf5ef2aSThomas Huth case MODE_UL:
1572bf38ca5cSRichard Henderson GEN_HELPER_UL(mul_h, temp64, r2, r3, t_n);
1573fcf5ef2aSThomas Huth break;
1574fcf5ef2aSThomas Huth case MODE_UU:
1575bf38ca5cSRichard Henderson GEN_HELPER_UU(mul_h, temp64, r2, r3, t_n);
1576fcf5ef2aSThomas Huth break;
1577fcf5ef2aSThomas Huth }
1578fcf5ef2aSThomas Huth tcg_gen_extr_i64_i32(temp, temp2, temp64);
1579fcf5ef2aSThomas Huth gen_subs(ret_low, r1_low, temp);
1580fcf5ef2aSThomas Huth tcg_gen_mov_tl(temp, cpu_PSW_V);
1581fcf5ef2aSThomas Huth tcg_gen_mov_tl(temp3, cpu_PSW_AV);
1582fcf5ef2aSThomas Huth gen_subs(ret_high, r1_high, temp2);
1583fcf5ef2aSThomas Huth /* combine v bits */
1584fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_V, cpu_PSW_V, temp);
1585fcf5ef2aSThomas Huth /* combine av bits */
1586fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_AV, cpu_PSW_AV, temp3);
1587fcf5ef2aSThomas Huth }
1588fcf5ef2aSThomas Huth
1589fcf5ef2aSThomas Huth static inline void
gen_msubm_h(TCGv ret_low,TCGv ret_high,TCGv r1_low,TCGv r1_high,TCGv r2,TCGv r3,uint32_t n,uint32_t mode)1590fcf5ef2aSThomas Huth gen_msubm_h(TCGv ret_low, TCGv ret_high, TCGv r1_low, TCGv r1_high, TCGv r2,
1591fcf5ef2aSThomas Huth TCGv r3, uint32_t n, uint32_t mode)
1592fcf5ef2aSThomas Huth {
1593bf38ca5cSRichard Henderson TCGv t_n = tcg_constant_i32(n);
1594fcf5ef2aSThomas Huth TCGv_i64 temp64 = tcg_temp_new_i64();
1595fcf5ef2aSThomas Huth TCGv_i64 temp64_2 = tcg_temp_new_i64();
1596fcf5ef2aSThomas Huth TCGv_i64 temp64_3 = tcg_temp_new_i64();
1597fcf5ef2aSThomas Huth switch (mode) {
1598fcf5ef2aSThomas Huth case MODE_LL:
1599bf38ca5cSRichard Henderson GEN_HELPER_LL(mulm_h, temp64, r2, r3, t_n);
1600fcf5ef2aSThomas Huth break;
1601fcf5ef2aSThomas Huth case MODE_LU:
1602bf38ca5cSRichard Henderson GEN_HELPER_LU(mulm_h, temp64, r2, r3, t_n);
1603fcf5ef2aSThomas Huth break;
1604fcf5ef2aSThomas Huth case MODE_UL:
1605bf38ca5cSRichard Henderson GEN_HELPER_UL(mulm_h, temp64, r2, r3, t_n);
1606fcf5ef2aSThomas Huth break;
1607fcf5ef2aSThomas Huth case MODE_UU:
1608bf38ca5cSRichard Henderson GEN_HELPER_UU(mulm_h, temp64, r2, r3, t_n);
1609fcf5ef2aSThomas Huth break;
1610fcf5ef2aSThomas Huth }
1611fcf5ef2aSThomas Huth tcg_gen_concat_i32_i64(temp64_2, r1_low, r1_high);
1612fcf5ef2aSThomas Huth gen_sub64_d(temp64_3, temp64_2, temp64);
1613fcf5ef2aSThomas Huth /* write back result */
1614fcf5ef2aSThomas Huth tcg_gen_extr_i64_i32(ret_low, ret_high, temp64_3);
1615fcf5ef2aSThomas Huth }
1616fcf5ef2aSThomas Huth
1617fcf5ef2aSThomas Huth static inline void
gen_msubms_h(TCGv ret_low,TCGv ret_high,TCGv r1_low,TCGv r1_high,TCGv r2,TCGv r3,uint32_t n,uint32_t mode)1618fcf5ef2aSThomas Huth gen_msubms_h(TCGv ret_low, TCGv ret_high, TCGv r1_low, TCGv r1_high, TCGv r2,
1619fcf5ef2aSThomas Huth TCGv r3, uint32_t n, uint32_t mode)
1620fcf5ef2aSThomas Huth {
1621bf38ca5cSRichard Henderson TCGv t_n = tcg_constant_i32(n);
1622fcf5ef2aSThomas Huth TCGv_i64 temp64 = tcg_temp_new_i64();
1623fcf5ef2aSThomas Huth TCGv_i64 temp64_2 = tcg_temp_new_i64();
1624fcf5ef2aSThomas Huth switch (mode) {
1625fcf5ef2aSThomas Huth case MODE_LL:
1626bf38ca5cSRichard Henderson GEN_HELPER_LL(mulm_h, temp64, r2, r3, t_n);
1627fcf5ef2aSThomas Huth break;
1628fcf5ef2aSThomas Huth case MODE_LU:
1629bf38ca5cSRichard Henderson GEN_HELPER_LU(mulm_h, temp64, r2, r3, t_n);
1630fcf5ef2aSThomas Huth break;
1631fcf5ef2aSThomas Huth case MODE_UL:
1632bf38ca5cSRichard Henderson GEN_HELPER_UL(mulm_h, temp64, r2, r3, t_n);
1633fcf5ef2aSThomas Huth break;
1634fcf5ef2aSThomas Huth case MODE_UU:
1635bf38ca5cSRichard Henderson GEN_HELPER_UU(mulm_h, temp64, r2, r3, t_n);
1636fcf5ef2aSThomas Huth break;
1637fcf5ef2aSThomas Huth }
1638fcf5ef2aSThomas Huth tcg_gen_concat_i32_i64(temp64_2, r1_low, r1_high);
1639ad75a51eSRichard Henderson gen_helper_sub64_ssov(temp64, tcg_env, temp64_2, temp64);
1640fcf5ef2aSThomas Huth tcg_gen_extr_i64_i32(ret_low, ret_high, temp64);
1641fcf5ef2aSThomas Huth }
1642fcf5ef2aSThomas Huth
1643fcf5ef2aSThomas Huth static inline void
gen_msubr64_h(TCGv ret,TCGv r1_low,TCGv r1_high,TCGv r2,TCGv r3,uint32_t n,uint32_t mode)1644fcf5ef2aSThomas Huth gen_msubr64_h(TCGv ret, TCGv r1_low, TCGv r1_high, TCGv r2, TCGv r3, uint32_t n,
1645fcf5ef2aSThomas Huth uint32_t mode)
1646fcf5ef2aSThomas Huth {
1647bf38ca5cSRichard Henderson TCGv t_n = tcg_constant_i32(n);
1648fcf5ef2aSThomas Huth TCGv_i64 temp64 = tcg_temp_new_i64();
1649fcf5ef2aSThomas Huth switch (mode) {
1650fcf5ef2aSThomas Huth case MODE_LL:
1651bf38ca5cSRichard Henderson GEN_HELPER_LL(mul_h, temp64, r2, r3, t_n);
1652fcf5ef2aSThomas Huth break;
1653fcf5ef2aSThomas Huth case MODE_LU:
1654bf38ca5cSRichard Henderson GEN_HELPER_LU(mul_h, temp64, r2, r3, t_n);
1655fcf5ef2aSThomas Huth break;
1656fcf5ef2aSThomas Huth case MODE_UL:
1657bf38ca5cSRichard Henderson GEN_HELPER_UL(mul_h, temp64, r2, r3, t_n);
1658fcf5ef2aSThomas Huth break;
1659fcf5ef2aSThomas Huth case MODE_UU:
1660bf38ca5cSRichard Henderson GEN_HELPER_UU(mul_h, temp64, r2, r3, t_n);
1661fcf5ef2aSThomas Huth break;
1662fcf5ef2aSThomas Huth }
1663ad75a51eSRichard Henderson gen_helper_subr_h(ret, tcg_env, temp64, r1_low, r1_high);
1664fcf5ef2aSThomas Huth }
1665fcf5ef2aSThomas Huth
1666fcf5ef2aSThomas Huth static inline void
gen_msubr32_h(TCGv ret,TCGv r1,TCGv r2,TCGv r3,uint32_t n,uint32_t mode)1667fcf5ef2aSThomas Huth gen_msubr32_h(TCGv ret, TCGv r1, TCGv r2, TCGv r3, uint32_t n, uint32_t mode)
1668fcf5ef2aSThomas Huth {
1669fcf5ef2aSThomas Huth TCGv temp = tcg_temp_new();
1670fcf5ef2aSThomas Huth TCGv temp2 = tcg_temp_new();
1671fcf5ef2aSThomas Huth
1672fcf5ef2aSThomas Huth tcg_gen_andi_tl(temp2, r1, 0xffff0000);
1673fcf5ef2aSThomas Huth tcg_gen_shli_tl(temp, r1, 16);
1674fcf5ef2aSThomas Huth gen_msubr64_h(ret, temp, temp2, r2, r3, n, mode);
1675fcf5ef2aSThomas Huth }
1676fcf5ef2aSThomas Huth
1677fcf5ef2aSThomas Huth static inline void
gen_msubr64s_h(TCGv ret,TCGv r1_low,TCGv r1_high,TCGv r2,TCGv r3,uint32_t n,uint32_t mode)1678fcf5ef2aSThomas Huth gen_msubr64s_h(TCGv ret, TCGv r1_low, TCGv r1_high, TCGv r2, TCGv r3,
1679fcf5ef2aSThomas Huth uint32_t n, uint32_t mode)
1680fcf5ef2aSThomas Huth {
1681bf38ca5cSRichard Henderson TCGv t_n = tcg_constant_i32(n);
1682fcf5ef2aSThomas Huth TCGv_i64 temp64 = tcg_temp_new_i64();
1683fcf5ef2aSThomas Huth switch (mode) {
1684fcf5ef2aSThomas Huth case MODE_LL:
1685bf38ca5cSRichard Henderson GEN_HELPER_LL(mul_h, temp64, r2, r3, t_n);
1686fcf5ef2aSThomas Huth break;
1687fcf5ef2aSThomas Huth case MODE_LU:
1688bf38ca5cSRichard Henderson GEN_HELPER_LU(mul_h, temp64, r2, r3, t_n);
1689fcf5ef2aSThomas Huth break;
1690fcf5ef2aSThomas Huth case MODE_UL:
1691bf38ca5cSRichard Henderson GEN_HELPER_UL(mul_h, temp64, r2, r3, t_n);
1692fcf5ef2aSThomas Huth break;
1693fcf5ef2aSThomas Huth case MODE_UU:
1694bf38ca5cSRichard Henderson GEN_HELPER_UU(mul_h, temp64, r2, r3, t_n);
1695fcf5ef2aSThomas Huth break;
1696fcf5ef2aSThomas Huth }
1697ad75a51eSRichard Henderson gen_helper_subr_h_ssov(ret, tcg_env, temp64, r1_low, r1_high);
1698fcf5ef2aSThomas Huth }
1699fcf5ef2aSThomas Huth
1700fcf5ef2aSThomas Huth static inline void
gen_msubr32s_h(TCGv ret,TCGv r1,TCGv r2,TCGv r3,uint32_t n,uint32_t mode)1701fcf5ef2aSThomas Huth gen_msubr32s_h(TCGv ret, TCGv r1, TCGv r2, TCGv r3, uint32_t n, uint32_t mode)
1702fcf5ef2aSThomas Huth {
1703fcf5ef2aSThomas Huth TCGv temp = tcg_temp_new();
1704fcf5ef2aSThomas Huth TCGv temp2 = tcg_temp_new();
1705fcf5ef2aSThomas Huth
1706fcf5ef2aSThomas Huth tcg_gen_andi_tl(temp2, r1, 0xffff0000);
1707fcf5ef2aSThomas Huth tcg_gen_shli_tl(temp, r1, 16);
1708fcf5ef2aSThomas Huth gen_msubr64s_h(ret, temp, temp2, r2, r3, n, mode);
1709fcf5ef2aSThomas Huth }
1710fcf5ef2aSThomas Huth
1711fcf5ef2aSThomas Huth static inline void
gen_msubr_q(TCGv ret,TCGv r1,TCGv r2,TCGv r3,uint32_t n)1712fcf5ef2aSThomas Huth gen_msubr_q(TCGv ret, TCGv r1, TCGv r2, TCGv r3, uint32_t n)
1713fcf5ef2aSThomas Huth {
1714151293c2SRichard Henderson TCGv temp = tcg_constant_i32(n);
1715ad75a51eSRichard Henderson gen_helper_msubr_q(ret, tcg_env, r1, r2, r3, temp);
1716fcf5ef2aSThomas Huth }
1717fcf5ef2aSThomas Huth
1718fcf5ef2aSThomas Huth static inline void
gen_msubrs_q(TCGv ret,TCGv r1,TCGv r2,TCGv r3,uint32_t n)1719fcf5ef2aSThomas Huth gen_msubrs_q(TCGv ret, TCGv r1, TCGv r2, TCGv r3, uint32_t n)
1720fcf5ef2aSThomas Huth {
1721151293c2SRichard Henderson TCGv temp = tcg_constant_i32(n);
1722ad75a51eSRichard Henderson gen_helper_msubr_q_ssov(ret, tcg_env, r1, r2, r3, temp);
1723fcf5ef2aSThomas Huth }
1724fcf5ef2aSThomas Huth
1725fcf5ef2aSThomas Huth static inline void
gen_msub32_q(TCGv ret,TCGv arg1,TCGv arg2,TCGv arg3,uint32_t n,uint32_t up_shift)1726fcf5ef2aSThomas Huth gen_msub32_q(TCGv ret, TCGv arg1, TCGv arg2, TCGv arg3, uint32_t n,
17272db92a0cSBastian Koppelmann uint32_t up_shift)
1728fcf5ef2aSThomas Huth {
1729fcf5ef2aSThomas Huth TCGv temp3 = tcg_temp_new();
1730fcf5ef2aSThomas Huth TCGv_i64 t1 = tcg_temp_new_i64();
1731fcf5ef2aSThomas Huth TCGv_i64 t2 = tcg_temp_new_i64();
1732fcf5ef2aSThomas Huth TCGv_i64 t3 = tcg_temp_new_i64();
1733fcf5ef2aSThomas Huth TCGv_i64 t4 = tcg_temp_new_i64();
1734fcf5ef2aSThomas Huth
1735fcf5ef2aSThomas Huth tcg_gen_ext_i32_i64(t2, arg2);
1736fcf5ef2aSThomas Huth tcg_gen_ext_i32_i64(t3, arg3);
1737fcf5ef2aSThomas Huth
1738fcf5ef2aSThomas Huth tcg_gen_mul_i64(t2, t2, t3);
1739fcf5ef2aSThomas Huth
1740fcf5ef2aSThomas Huth tcg_gen_ext_i32_i64(t1, arg1);
1741fcf5ef2aSThomas Huth /* if we shift part of the fraction out, we need to round up */
1742fcf5ef2aSThomas Huth tcg_gen_andi_i64(t4, t2, (1ll << (up_shift - n)) - 1);
1743fcf5ef2aSThomas Huth tcg_gen_setcondi_i64(TCG_COND_NE, t4, t4, 0);
1744fcf5ef2aSThomas Huth tcg_gen_sari_i64(t2, t2, up_shift - n);
1745fcf5ef2aSThomas Huth tcg_gen_add_i64(t2, t2, t4);
1746fcf5ef2aSThomas Huth
1747fcf5ef2aSThomas Huth tcg_gen_sub_i64(t3, t1, t2);
1748fcf5ef2aSThomas Huth tcg_gen_extrl_i64_i32(temp3, t3);
1749fcf5ef2aSThomas Huth /* calc v bit */
1750fcf5ef2aSThomas Huth tcg_gen_setcondi_i64(TCG_COND_GT, t1, t3, 0x7fffffffLL);
1751fcf5ef2aSThomas Huth tcg_gen_setcondi_i64(TCG_COND_LT, t2, t3, -0x80000000LL);
1752fcf5ef2aSThomas Huth tcg_gen_or_i64(t1, t1, t2);
1753fcf5ef2aSThomas Huth tcg_gen_extrl_i64_i32(cpu_PSW_V, t1);
1754fcf5ef2aSThomas Huth tcg_gen_shli_tl(cpu_PSW_V, cpu_PSW_V, 31);
1755fcf5ef2aSThomas Huth /* Calc SV bit */
1756fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SV, cpu_PSW_SV, cpu_PSW_V);
1757fcf5ef2aSThomas Huth /* Calc AV/SAV bits */
1758fcf5ef2aSThomas Huth tcg_gen_add_tl(cpu_PSW_AV, temp3, temp3);
1759fcf5ef2aSThomas Huth tcg_gen_xor_tl(cpu_PSW_AV, temp3, cpu_PSW_AV);
1760fcf5ef2aSThomas Huth /* calc SAV */
1761fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SAV, cpu_PSW_SAV, cpu_PSW_AV);
1762fcf5ef2aSThomas Huth /* write back result */
1763fcf5ef2aSThomas Huth tcg_gen_mov_tl(ret, temp3);
1764fcf5ef2aSThomas Huth }
1765fcf5ef2aSThomas Huth
1766fcf5ef2aSThomas Huth static inline void
gen_m16sub32_q(TCGv ret,TCGv arg1,TCGv arg2,TCGv arg3,uint32_t n)1767fcf5ef2aSThomas Huth gen_m16sub32_q(TCGv ret, TCGv arg1, TCGv arg2, TCGv arg3, uint32_t n)
1768fcf5ef2aSThomas Huth {
1769fcf5ef2aSThomas Huth TCGv temp = tcg_temp_new();
1770fcf5ef2aSThomas Huth TCGv temp2 = tcg_temp_new();
1771fcf5ef2aSThomas Huth if (n == 0) {
1772fcf5ef2aSThomas Huth tcg_gen_mul_tl(temp, arg2, arg3);
1773fcf5ef2aSThomas Huth } else { /* n is expected to be 1 */
1774fcf5ef2aSThomas Huth tcg_gen_mul_tl(temp, arg2, arg3);
1775fcf5ef2aSThomas Huth tcg_gen_shli_tl(temp, temp, 1);
1776fcf5ef2aSThomas Huth /* catch special case r1 = r2 = 0x8000 */
1777fcf5ef2aSThomas Huth tcg_gen_setcondi_tl(TCG_COND_EQ, temp2, temp, 0x80000000);
1778fcf5ef2aSThomas Huth tcg_gen_sub_tl(temp, temp, temp2);
1779fcf5ef2aSThomas Huth }
1780fcf5ef2aSThomas Huth gen_sub_d(ret, arg1, temp);
1781fcf5ef2aSThomas Huth }
1782fcf5ef2aSThomas Huth
1783fcf5ef2aSThomas Huth static inline void
gen_m16subs32_q(TCGv ret,TCGv arg1,TCGv arg2,TCGv arg3,uint32_t n)1784fcf5ef2aSThomas Huth gen_m16subs32_q(TCGv ret, TCGv arg1, TCGv arg2, TCGv arg3, uint32_t n)
1785fcf5ef2aSThomas Huth {
1786fcf5ef2aSThomas Huth TCGv temp = tcg_temp_new();
1787fcf5ef2aSThomas Huth TCGv temp2 = tcg_temp_new();
1788fcf5ef2aSThomas Huth if (n == 0) {
1789fcf5ef2aSThomas Huth tcg_gen_mul_tl(temp, arg2, arg3);
1790fcf5ef2aSThomas Huth } else { /* n is expected to be 1 */
1791fcf5ef2aSThomas Huth tcg_gen_mul_tl(temp, arg2, arg3);
1792fcf5ef2aSThomas Huth tcg_gen_shli_tl(temp, temp, 1);
1793fcf5ef2aSThomas Huth /* catch special case r1 = r2 = 0x8000 */
1794fcf5ef2aSThomas Huth tcg_gen_setcondi_tl(TCG_COND_EQ, temp2, temp, 0x80000000);
1795fcf5ef2aSThomas Huth tcg_gen_sub_tl(temp, temp, temp2);
1796fcf5ef2aSThomas Huth }
1797fcf5ef2aSThomas Huth gen_subs(ret, arg1, temp);
1798fcf5ef2aSThomas Huth }
1799fcf5ef2aSThomas Huth
1800fcf5ef2aSThomas Huth static inline void
gen_m16sub64_q(TCGv rl,TCGv rh,TCGv arg1_low,TCGv arg1_high,TCGv arg2,TCGv arg3,uint32_t n)1801fcf5ef2aSThomas Huth gen_m16sub64_q(TCGv rl, TCGv rh, TCGv arg1_low, TCGv arg1_high, TCGv arg2,
1802fcf5ef2aSThomas Huth TCGv arg3, uint32_t n)
1803fcf5ef2aSThomas Huth {
1804fcf5ef2aSThomas Huth TCGv temp = tcg_temp_new();
1805fcf5ef2aSThomas Huth TCGv temp2 = tcg_temp_new();
1806fcf5ef2aSThomas Huth TCGv_i64 t1 = tcg_temp_new_i64();
1807fcf5ef2aSThomas Huth TCGv_i64 t2 = tcg_temp_new_i64();
1808fcf5ef2aSThomas Huth TCGv_i64 t3 = tcg_temp_new_i64();
1809fcf5ef2aSThomas Huth
1810fcf5ef2aSThomas Huth if (n == 0) {
1811fcf5ef2aSThomas Huth tcg_gen_mul_tl(temp, arg2, arg3);
1812fcf5ef2aSThomas Huth } else { /* n is expected to be 1 */
1813fcf5ef2aSThomas Huth tcg_gen_mul_tl(temp, arg2, arg3);
1814fcf5ef2aSThomas Huth tcg_gen_shli_tl(temp, temp, 1);
1815fcf5ef2aSThomas Huth /* catch special case r1 = r2 = 0x8000 */
1816fcf5ef2aSThomas Huth tcg_gen_setcondi_tl(TCG_COND_EQ, temp2, temp, 0x80000000);
1817fcf5ef2aSThomas Huth tcg_gen_sub_tl(temp, temp, temp2);
1818fcf5ef2aSThomas Huth }
1819fcf5ef2aSThomas Huth tcg_gen_ext_i32_i64(t2, temp);
1820fcf5ef2aSThomas Huth tcg_gen_shli_i64(t2, t2, 16);
1821fcf5ef2aSThomas Huth tcg_gen_concat_i32_i64(t1, arg1_low, arg1_high);
1822fcf5ef2aSThomas Huth gen_sub64_d(t3, t1, t2);
1823fcf5ef2aSThomas Huth /* write back result */
1824fcf5ef2aSThomas Huth tcg_gen_extr_i64_i32(rl, rh, t3);
1825fcf5ef2aSThomas Huth }
1826fcf5ef2aSThomas Huth
1827fcf5ef2aSThomas Huth static inline void
gen_m16subs64_q(TCGv rl,TCGv rh,TCGv arg1_low,TCGv arg1_high,TCGv arg2,TCGv arg3,uint32_t n)1828fcf5ef2aSThomas Huth gen_m16subs64_q(TCGv rl, TCGv rh, TCGv arg1_low, TCGv arg1_high, TCGv arg2,
1829fcf5ef2aSThomas Huth TCGv arg3, uint32_t n)
1830fcf5ef2aSThomas Huth {
1831fcf5ef2aSThomas Huth TCGv temp = tcg_temp_new();
1832fcf5ef2aSThomas Huth TCGv temp2 = tcg_temp_new();
1833fcf5ef2aSThomas Huth TCGv_i64 t1 = tcg_temp_new_i64();
1834fcf5ef2aSThomas Huth TCGv_i64 t2 = tcg_temp_new_i64();
1835fcf5ef2aSThomas Huth
1836fcf5ef2aSThomas Huth if (n == 0) {
1837fcf5ef2aSThomas Huth tcg_gen_mul_tl(temp, arg2, arg3);
1838fcf5ef2aSThomas Huth } else { /* n is expected to be 1 */
1839fcf5ef2aSThomas Huth tcg_gen_mul_tl(temp, arg2, arg3);
1840fcf5ef2aSThomas Huth tcg_gen_shli_tl(temp, temp, 1);
1841fcf5ef2aSThomas Huth /* catch special case r1 = r2 = 0x8000 */
1842fcf5ef2aSThomas Huth tcg_gen_setcondi_tl(TCG_COND_EQ, temp2, temp, 0x80000000);
1843fcf5ef2aSThomas Huth tcg_gen_sub_tl(temp, temp, temp2);
1844fcf5ef2aSThomas Huth }
1845fcf5ef2aSThomas Huth tcg_gen_ext_i32_i64(t2, temp);
1846fcf5ef2aSThomas Huth tcg_gen_shli_i64(t2, t2, 16);
1847fcf5ef2aSThomas Huth tcg_gen_concat_i32_i64(t1, arg1_low, arg1_high);
1848fcf5ef2aSThomas Huth
1849ad75a51eSRichard Henderson gen_helper_sub64_ssov(t1, tcg_env, t1, t2);
1850fcf5ef2aSThomas Huth tcg_gen_extr_i64_i32(rl, rh, t1);
1851fcf5ef2aSThomas Huth }
1852fcf5ef2aSThomas Huth
1853fcf5ef2aSThomas Huth static inline void
gen_msub64_q(TCGv rl,TCGv rh,TCGv arg1_low,TCGv arg1_high,TCGv arg2,TCGv arg3,uint32_t n)1854fcf5ef2aSThomas Huth gen_msub64_q(TCGv rl, TCGv rh, TCGv arg1_low, TCGv arg1_high, TCGv arg2,
18552db92a0cSBastian Koppelmann TCGv arg3, uint32_t n)
1856fcf5ef2aSThomas Huth {
1857fcf5ef2aSThomas Huth TCGv_i64 t1 = tcg_temp_new_i64();
1858fcf5ef2aSThomas Huth TCGv_i64 t2 = tcg_temp_new_i64();
1859fcf5ef2aSThomas Huth TCGv_i64 t3 = tcg_temp_new_i64();
1860fcf5ef2aSThomas Huth TCGv_i64 t4 = tcg_temp_new_i64();
1861fcf5ef2aSThomas Huth TCGv temp, temp2;
1862fcf5ef2aSThomas Huth
1863fcf5ef2aSThomas Huth tcg_gen_concat_i32_i64(t1, arg1_low, arg1_high);
1864fcf5ef2aSThomas Huth tcg_gen_ext_i32_i64(t2, arg2);
1865fcf5ef2aSThomas Huth tcg_gen_ext_i32_i64(t3, arg3);
1866fcf5ef2aSThomas Huth
1867fcf5ef2aSThomas Huth tcg_gen_mul_i64(t2, t2, t3);
1868fcf5ef2aSThomas Huth if (n != 0) {
1869fcf5ef2aSThomas Huth tcg_gen_shli_i64(t2, t2, 1);
1870fcf5ef2aSThomas Huth }
1871fcf5ef2aSThomas Huth tcg_gen_sub_i64(t4, t1, t2);
1872fcf5ef2aSThomas Huth /* calc v bit */
1873fcf5ef2aSThomas Huth tcg_gen_xor_i64(t3, t4, t1);
1874fcf5ef2aSThomas Huth tcg_gen_xor_i64(t2, t1, t2);
1875fcf5ef2aSThomas Huth tcg_gen_and_i64(t3, t3, t2);
1876fcf5ef2aSThomas Huth tcg_gen_extrh_i64_i32(cpu_PSW_V, t3);
1877fcf5ef2aSThomas Huth /* We produce an overflow on the host if the mul before was
1878fcf5ef2aSThomas Huth (0x80000000 * 0x80000000) << 1). If this is the
1879fcf5ef2aSThomas Huth case, we negate the ovf. */
1880fcf5ef2aSThomas Huth if (n == 1) {
1881fcf5ef2aSThomas Huth temp = tcg_temp_new();
1882fcf5ef2aSThomas Huth temp2 = tcg_temp_new();
1883fcf5ef2aSThomas Huth tcg_gen_setcondi_tl(TCG_COND_EQ, temp, arg2, 0x80000000);
1884fcf5ef2aSThomas Huth tcg_gen_setcond_tl(TCG_COND_EQ, temp2, arg2, arg3);
1885fcf5ef2aSThomas Huth tcg_gen_and_tl(temp, temp, temp2);
1886fcf5ef2aSThomas Huth tcg_gen_shli_tl(temp, temp, 31);
1887fcf5ef2aSThomas Huth /* negate v bit, if special condition */
1888fcf5ef2aSThomas Huth tcg_gen_xor_tl(cpu_PSW_V, cpu_PSW_V, temp);
1889fcf5ef2aSThomas Huth }
1890fcf5ef2aSThomas Huth /* write back result */
1891fcf5ef2aSThomas Huth tcg_gen_extr_i64_i32(rl, rh, t4);
1892fcf5ef2aSThomas Huth /* Calc SV bit */
1893fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SV, cpu_PSW_SV, cpu_PSW_V);
1894fcf5ef2aSThomas Huth /* Calc AV/SAV bits */
1895fcf5ef2aSThomas Huth tcg_gen_add_tl(cpu_PSW_AV, rh, rh);
1896fcf5ef2aSThomas Huth tcg_gen_xor_tl(cpu_PSW_AV, rh, cpu_PSW_AV);
1897fcf5ef2aSThomas Huth /* calc SAV */
1898fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SAV, cpu_PSW_SAV, cpu_PSW_AV);
1899fcf5ef2aSThomas Huth }
1900fcf5ef2aSThomas Huth
1901fcf5ef2aSThomas Huth static inline void
gen_msubs32_q(TCGv ret,TCGv arg1,TCGv arg2,TCGv arg3,uint32_t n,uint32_t up_shift)1902fcf5ef2aSThomas Huth gen_msubs32_q(TCGv ret, TCGv arg1, TCGv arg2, TCGv arg3, uint32_t n,
1903fcf5ef2aSThomas Huth uint32_t up_shift)
1904fcf5ef2aSThomas Huth {
1905fcf5ef2aSThomas Huth TCGv_i64 t1 = tcg_temp_new_i64();
1906fcf5ef2aSThomas Huth TCGv_i64 t2 = tcg_temp_new_i64();
1907fcf5ef2aSThomas Huth TCGv_i64 t3 = tcg_temp_new_i64();
1908fcf5ef2aSThomas Huth TCGv_i64 t4 = tcg_temp_new_i64();
1909fcf5ef2aSThomas Huth
1910fcf5ef2aSThomas Huth tcg_gen_ext_i32_i64(t1, arg1);
1911fcf5ef2aSThomas Huth tcg_gen_ext_i32_i64(t2, arg2);
1912fcf5ef2aSThomas Huth tcg_gen_ext_i32_i64(t3, arg3);
1913fcf5ef2aSThomas Huth
1914fcf5ef2aSThomas Huth tcg_gen_mul_i64(t2, t2, t3);
1915fcf5ef2aSThomas Huth /* if we shift part of the fraction out, we need to round up */
1916fcf5ef2aSThomas Huth tcg_gen_andi_i64(t4, t2, (1ll << (up_shift - n)) - 1);
1917fcf5ef2aSThomas Huth tcg_gen_setcondi_i64(TCG_COND_NE, t4, t4, 0);
1918fcf5ef2aSThomas Huth tcg_gen_sari_i64(t3, t2, up_shift - n);
1919fcf5ef2aSThomas Huth tcg_gen_add_i64(t3, t3, t4);
1920fcf5ef2aSThomas Huth
1921ad75a51eSRichard Henderson gen_helper_msub32_q_sub_ssov(ret, tcg_env, t1, t3);
1922fcf5ef2aSThomas Huth }
1923fcf5ef2aSThomas Huth
1924fcf5ef2aSThomas Huth static inline void
gen_msubs64_q(TCGv rl,TCGv rh,TCGv arg1_low,TCGv arg1_high,TCGv arg2,TCGv arg3,uint32_t n)1925fcf5ef2aSThomas Huth gen_msubs64_q(TCGv rl, TCGv rh, TCGv arg1_low, TCGv arg1_high, TCGv arg2,
1926fcf5ef2aSThomas Huth TCGv arg3, uint32_t n)
1927fcf5ef2aSThomas Huth {
1928fcf5ef2aSThomas Huth TCGv_i64 r1 = tcg_temp_new_i64();
1929bf38ca5cSRichard Henderson TCGv t_n = tcg_constant_i32(n);
1930fcf5ef2aSThomas Huth
1931fcf5ef2aSThomas Huth tcg_gen_concat_i32_i64(r1, arg1_low, arg1_high);
1932ad75a51eSRichard Henderson gen_helper_msub64_q_ssov(r1, tcg_env, r1, arg2, arg3, t_n);
1933fcf5ef2aSThomas Huth tcg_gen_extr_i64_i32(rl, rh, r1);
1934fcf5ef2aSThomas Huth }
1935fcf5ef2aSThomas Huth
1936fcf5ef2aSThomas Huth static inline void
gen_msubad_h(TCGv ret_low,TCGv ret_high,TCGv r1_low,TCGv r1_high,TCGv r2,TCGv r3,uint32_t n,uint32_t mode)1937fcf5ef2aSThomas Huth gen_msubad_h(TCGv ret_low, TCGv ret_high, TCGv r1_low, TCGv r1_high, TCGv r2,
1938fcf5ef2aSThomas Huth TCGv r3, uint32_t n, uint32_t mode)
1939fcf5ef2aSThomas Huth {
1940bf38ca5cSRichard Henderson TCGv t_n = tcg_constant_i32(n);
1941bf38ca5cSRichard Henderson TCGv temp = tcg_temp_new();
1942fcf5ef2aSThomas Huth TCGv temp2 = tcg_temp_new();
1943fcf5ef2aSThomas Huth TCGv_i64 temp64 = tcg_temp_new_i64();
1944fcf5ef2aSThomas Huth switch (mode) {
1945fcf5ef2aSThomas Huth case MODE_LL:
1946bf38ca5cSRichard Henderson GEN_HELPER_LL(mul_h, temp64, r2, r3, t_n);
1947fcf5ef2aSThomas Huth break;
1948fcf5ef2aSThomas Huth case MODE_LU:
1949bf38ca5cSRichard Henderson GEN_HELPER_LU(mul_h, temp64, r2, r3, t_n);
1950fcf5ef2aSThomas Huth break;
1951fcf5ef2aSThomas Huth case MODE_UL:
1952bf38ca5cSRichard Henderson GEN_HELPER_UL(mul_h, temp64, r2, r3, t_n);
1953fcf5ef2aSThomas Huth break;
1954fcf5ef2aSThomas Huth case MODE_UU:
1955bf38ca5cSRichard Henderson GEN_HELPER_UU(mul_h, temp64, r2, r3, t_n);
1956fcf5ef2aSThomas Huth break;
1957fcf5ef2aSThomas Huth }
1958fcf5ef2aSThomas Huth tcg_gen_extr_i64_i32(temp, temp2, temp64);
1959fcf5ef2aSThomas Huth gen_addsub64_h(ret_low, ret_high, r1_low, r1_high, temp, temp2,
1960fcf5ef2aSThomas Huth tcg_gen_add_tl, tcg_gen_sub_tl);
1961fcf5ef2aSThomas Huth }
1962fcf5ef2aSThomas Huth
1963fcf5ef2aSThomas Huth static inline void
gen_msubadm_h(TCGv ret_low,TCGv ret_high,TCGv r1_low,TCGv r1_high,TCGv r2,TCGv r3,uint32_t n,uint32_t mode)1964fcf5ef2aSThomas Huth gen_msubadm_h(TCGv ret_low, TCGv ret_high, TCGv r1_low, TCGv r1_high, TCGv r2,
1965fcf5ef2aSThomas Huth TCGv r3, uint32_t n, uint32_t mode)
1966fcf5ef2aSThomas Huth {
1967bf38ca5cSRichard Henderson TCGv t_n = tcg_constant_i32(n);
1968fcf5ef2aSThomas Huth TCGv_i64 temp64 = tcg_temp_new_i64();
1969fcf5ef2aSThomas Huth TCGv_i64 temp64_2 = tcg_temp_new_i64();
1970fcf5ef2aSThomas Huth TCGv_i64 temp64_3 = tcg_temp_new_i64();
1971fcf5ef2aSThomas Huth switch (mode) {
1972fcf5ef2aSThomas Huth case MODE_LL:
1973bf38ca5cSRichard Henderson GEN_HELPER_LL(mul_h, temp64, r2, r3, t_n);
1974fcf5ef2aSThomas Huth break;
1975fcf5ef2aSThomas Huth case MODE_LU:
1976bf38ca5cSRichard Henderson GEN_HELPER_LU(mul_h, temp64, r2, r3, t_n);
1977fcf5ef2aSThomas Huth break;
1978fcf5ef2aSThomas Huth case MODE_UL:
1979bf38ca5cSRichard Henderson GEN_HELPER_UL(mul_h, temp64, r2, r3, t_n);
1980fcf5ef2aSThomas Huth break;
1981fcf5ef2aSThomas Huth case MODE_UU:
1982bf38ca5cSRichard Henderson GEN_HELPER_UU(mul_h, temp64, r2, r3, t_n);
1983fcf5ef2aSThomas Huth break;
1984fcf5ef2aSThomas Huth }
1985fcf5ef2aSThomas Huth tcg_gen_concat_i32_i64(temp64_3, r1_low, r1_high);
1986fcf5ef2aSThomas Huth tcg_gen_sari_i64(temp64_2, temp64, 32); /* high */
1987fcf5ef2aSThomas Huth tcg_gen_ext32s_i64(temp64, temp64); /* low */
1988fcf5ef2aSThomas Huth tcg_gen_sub_i64(temp64, temp64_2, temp64);
1989fcf5ef2aSThomas Huth tcg_gen_shli_i64(temp64, temp64, 16);
1990fcf5ef2aSThomas Huth
1991fcf5ef2aSThomas Huth gen_sub64_d(temp64_2, temp64_3, temp64);
1992fcf5ef2aSThomas Huth /* write back result */
1993fcf5ef2aSThomas Huth tcg_gen_extr_i64_i32(ret_low, ret_high, temp64_2);
1994fcf5ef2aSThomas Huth }
1995fcf5ef2aSThomas Huth
1996fcf5ef2aSThomas Huth static inline void
gen_msubadr32_h(TCGv ret,TCGv r1,TCGv r2,TCGv r3,uint32_t n,uint32_t mode)1997fcf5ef2aSThomas Huth gen_msubadr32_h(TCGv ret, TCGv r1, TCGv r2, TCGv r3, uint32_t n, uint32_t mode)
1998fcf5ef2aSThomas Huth {
1999bf38ca5cSRichard Henderson TCGv t_n = tcg_constant_i32(n);
2000bf38ca5cSRichard Henderson TCGv temp = tcg_temp_new();
2001fcf5ef2aSThomas Huth TCGv temp2 = tcg_temp_new();
2002fcf5ef2aSThomas Huth TCGv_i64 temp64 = tcg_temp_new_i64();
2003fcf5ef2aSThomas Huth switch (mode) {
2004fcf5ef2aSThomas Huth case MODE_LL:
2005bf38ca5cSRichard Henderson GEN_HELPER_LL(mul_h, temp64, r2, r3, t_n);
2006fcf5ef2aSThomas Huth break;
2007fcf5ef2aSThomas Huth case MODE_LU:
2008bf38ca5cSRichard Henderson GEN_HELPER_LU(mul_h, temp64, r2, r3, t_n);
2009fcf5ef2aSThomas Huth break;
2010fcf5ef2aSThomas Huth case MODE_UL:
2011bf38ca5cSRichard Henderson GEN_HELPER_UL(mul_h, temp64, r2, r3, t_n);
2012fcf5ef2aSThomas Huth break;
2013fcf5ef2aSThomas Huth case MODE_UU:
2014bf38ca5cSRichard Henderson GEN_HELPER_UU(mul_h, temp64, r2, r3, t_n);
2015fcf5ef2aSThomas Huth break;
2016fcf5ef2aSThomas Huth }
2017fcf5ef2aSThomas Huth tcg_gen_andi_tl(temp2, r1, 0xffff0000);
2018fcf5ef2aSThomas Huth tcg_gen_shli_tl(temp, r1, 16);
2019ad75a51eSRichard Henderson gen_helper_subadr_h(ret, tcg_env, temp64, temp, temp2);
2020fcf5ef2aSThomas Huth }
2021fcf5ef2aSThomas Huth
2022fcf5ef2aSThomas Huth static inline void
gen_msubads_h(TCGv ret_low,TCGv ret_high,TCGv r1_low,TCGv r1_high,TCGv r2,TCGv r3,uint32_t n,uint32_t mode)2023fcf5ef2aSThomas Huth gen_msubads_h(TCGv ret_low, TCGv ret_high, TCGv r1_low, TCGv r1_high, TCGv r2,
2024fcf5ef2aSThomas Huth TCGv r3, uint32_t n, uint32_t mode)
2025fcf5ef2aSThomas Huth {
2026bf38ca5cSRichard Henderson TCGv t_n = tcg_constant_i32(n);
2027bf38ca5cSRichard Henderson TCGv temp = tcg_temp_new();
2028fcf5ef2aSThomas Huth TCGv temp2 = tcg_temp_new();
2029fcf5ef2aSThomas Huth TCGv temp3 = tcg_temp_new();
2030fcf5ef2aSThomas Huth TCGv_i64 temp64 = tcg_temp_new_i64();
2031fcf5ef2aSThomas Huth
2032fcf5ef2aSThomas Huth switch (mode) {
2033fcf5ef2aSThomas Huth case MODE_LL:
2034bf38ca5cSRichard Henderson GEN_HELPER_LL(mul_h, temp64, r2, r3, t_n);
2035fcf5ef2aSThomas Huth break;
2036fcf5ef2aSThomas Huth case MODE_LU:
2037bf38ca5cSRichard Henderson GEN_HELPER_LU(mul_h, temp64, r2, r3, t_n);
2038fcf5ef2aSThomas Huth break;
2039fcf5ef2aSThomas Huth case MODE_UL:
2040bf38ca5cSRichard Henderson GEN_HELPER_UL(mul_h, temp64, r2, r3, t_n);
2041fcf5ef2aSThomas Huth break;
2042fcf5ef2aSThomas Huth case MODE_UU:
2043bf38ca5cSRichard Henderson GEN_HELPER_UU(mul_h, temp64, r2, r3, t_n);
2044fcf5ef2aSThomas Huth break;
2045fcf5ef2aSThomas Huth }
2046fcf5ef2aSThomas Huth tcg_gen_extr_i64_i32(temp, temp2, temp64);
2047fcf5ef2aSThomas Huth gen_adds(ret_low, r1_low, temp);
2048fcf5ef2aSThomas Huth tcg_gen_mov_tl(temp, cpu_PSW_V);
2049fcf5ef2aSThomas Huth tcg_gen_mov_tl(temp3, cpu_PSW_AV);
2050fcf5ef2aSThomas Huth gen_subs(ret_high, r1_high, temp2);
2051fcf5ef2aSThomas Huth /* combine v bits */
2052fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_V, cpu_PSW_V, temp);
2053fcf5ef2aSThomas Huth /* combine av bits */
2054fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_AV, cpu_PSW_AV, temp3);
2055fcf5ef2aSThomas Huth }
2056fcf5ef2aSThomas Huth
2057fcf5ef2aSThomas Huth static inline void
gen_msubadms_h(TCGv ret_low,TCGv ret_high,TCGv r1_low,TCGv r1_high,TCGv r2,TCGv r3,uint32_t n,uint32_t mode)2058fcf5ef2aSThomas Huth gen_msubadms_h(TCGv ret_low, TCGv ret_high, TCGv r1_low, TCGv r1_high, TCGv r2,
2059fcf5ef2aSThomas Huth TCGv r3, uint32_t n, uint32_t mode)
2060fcf5ef2aSThomas Huth {
2061bf38ca5cSRichard Henderson TCGv t_n = tcg_constant_i32(n);
2062fcf5ef2aSThomas Huth TCGv_i64 temp64 = tcg_temp_new_i64();
2063fcf5ef2aSThomas Huth TCGv_i64 temp64_2 = tcg_temp_new_i64();
2064fcf5ef2aSThomas Huth
2065fcf5ef2aSThomas Huth switch (mode) {
2066fcf5ef2aSThomas Huth case MODE_LL:
2067bf38ca5cSRichard Henderson GEN_HELPER_LL(mul_h, temp64, r2, r3, t_n);
2068fcf5ef2aSThomas Huth break;
2069fcf5ef2aSThomas Huth case MODE_LU:
2070bf38ca5cSRichard Henderson GEN_HELPER_LU(mul_h, temp64, r2, r3, t_n);
2071fcf5ef2aSThomas Huth break;
2072fcf5ef2aSThomas Huth case MODE_UL:
2073bf38ca5cSRichard Henderson GEN_HELPER_UL(mul_h, temp64, r2, r3, t_n);
2074fcf5ef2aSThomas Huth break;
2075fcf5ef2aSThomas Huth case MODE_UU:
2076bf38ca5cSRichard Henderson GEN_HELPER_UU(mul_h, temp64, r2, r3, t_n);
2077fcf5ef2aSThomas Huth break;
2078fcf5ef2aSThomas Huth }
2079fcf5ef2aSThomas Huth tcg_gen_sari_i64(temp64_2, temp64, 32); /* high */
2080fcf5ef2aSThomas Huth tcg_gen_ext32s_i64(temp64, temp64); /* low */
2081fcf5ef2aSThomas Huth tcg_gen_sub_i64(temp64, temp64_2, temp64);
2082fcf5ef2aSThomas Huth tcg_gen_shli_i64(temp64, temp64, 16);
2083fcf5ef2aSThomas Huth tcg_gen_concat_i32_i64(temp64_2, r1_low, r1_high);
2084fcf5ef2aSThomas Huth
2085ad75a51eSRichard Henderson gen_helper_sub64_ssov(temp64, tcg_env, temp64_2, temp64);
2086fcf5ef2aSThomas Huth tcg_gen_extr_i64_i32(ret_low, ret_high, temp64);
2087fcf5ef2aSThomas Huth }
2088fcf5ef2aSThomas Huth
2089fcf5ef2aSThomas Huth static inline void
gen_msubadr32s_h(TCGv ret,TCGv r1,TCGv r2,TCGv r3,uint32_t n,uint32_t mode)2090fcf5ef2aSThomas Huth gen_msubadr32s_h(TCGv ret, TCGv r1, TCGv r2, TCGv r3, uint32_t n, uint32_t mode)
2091fcf5ef2aSThomas Huth {
2092bf38ca5cSRichard Henderson TCGv t_n = tcg_constant_i32(n);
2093bf38ca5cSRichard Henderson TCGv temp = tcg_temp_new();
2094fcf5ef2aSThomas Huth TCGv temp2 = tcg_temp_new();
2095fcf5ef2aSThomas Huth TCGv_i64 temp64 = tcg_temp_new_i64();
2096fcf5ef2aSThomas Huth switch (mode) {
2097fcf5ef2aSThomas Huth case MODE_LL:
2098bf38ca5cSRichard Henderson GEN_HELPER_LL(mul_h, temp64, r2, r3, t_n);
2099fcf5ef2aSThomas Huth break;
2100fcf5ef2aSThomas Huth case MODE_LU:
2101bf38ca5cSRichard Henderson GEN_HELPER_LU(mul_h, temp64, r2, r3, t_n);
2102fcf5ef2aSThomas Huth break;
2103fcf5ef2aSThomas Huth case MODE_UL:
2104bf38ca5cSRichard Henderson GEN_HELPER_UL(mul_h, temp64, r2, r3, t_n);
2105fcf5ef2aSThomas Huth break;
2106fcf5ef2aSThomas Huth case MODE_UU:
2107bf38ca5cSRichard Henderson GEN_HELPER_UU(mul_h, temp64, r2, r3, t_n);
2108fcf5ef2aSThomas Huth break;
2109fcf5ef2aSThomas Huth }
2110fcf5ef2aSThomas Huth tcg_gen_andi_tl(temp2, r1, 0xffff0000);
2111fcf5ef2aSThomas Huth tcg_gen_shli_tl(temp, r1, 16);
2112ad75a51eSRichard Henderson gen_helper_subadr_h_ssov(ret, tcg_env, temp64, temp, temp2);
2113fcf5ef2aSThomas Huth }
2114fcf5ef2aSThomas Huth
gen_abs(TCGv ret,TCGv r1)2115fcf5ef2aSThomas Huth static inline void gen_abs(TCGv ret, TCGv r1)
2116fcf5ef2aSThomas Huth {
21172f8036d2SPhilippe Mathieu-Daudé tcg_gen_abs_tl(ret, r1);
2118fcf5ef2aSThomas Huth /* overflow can only happen, if r1 = 0x80000000 */
2119fcf5ef2aSThomas Huth tcg_gen_setcondi_tl(TCG_COND_EQ, cpu_PSW_V, r1, 0x80000000);
2120fcf5ef2aSThomas Huth tcg_gen_shli_tl(cpu_PSW_V, cpu_PSW_V, 31);
2121fcf5ef2aSThomas Huth /* calc SV bit */
2122fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SV, cpu_PSW_SV, cpu_PSW_V);
2123fcf5ef2aSThomas Huth /* Calc AV bit */
2124fcf5ef2aSThomas Huth tcg_gen_add_tl(cpu_PSW_AV, ret, ret);
2125fcf5ef2aSThomas Huth tcg_gen_xor_tl(cpu_PSW_AV, ret, cpu_PSW_AV);
2126fcf5ef2aSThomas Huth /* calc SAV bit */
2127fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SAV, cpu_PSW_SAV, cpu_PSW_AV);
2128fcf5ef2aSThomas Huth }
2129fcf5ef2aSThomas Huth
gen_absdif(TCGv ret,TCGv r1,TCGv r2)2130fcf5ef2aSThomas Huth static inline void gen_absdif(TCGv ret, TCGv r1, TCGv r2)
2131fcf5ef2aSThomas Huth {
2132fcf5ef2aSThomas Huth TCGv temp = tcg_temp_new_i32();
2133fcf5ef2aSThomas Huth TCGv result = tcg_temp_new_i32();
2134fcf5ef2aSThomas Huth
2135fcf5ef2aSThomas Huth tcg_gen_sub_tl(result, r1, r2);
2136fcf5ef2aSThomas Huth tcg_gen_sub_tl(temp, r2, r1);
2137fcf5ef2aSThomas Huth tcg_gen_movcond_tl(TCG_COND_GT, result, r1, r2, result, temp);
2138fcf5ef2aSThomas Huth
2139fcf5ef2aSThomas Huth /* calc V bit */
2140fcf5ef2aSThomas Huth tcg_gen_xor_tl(cpu_PSW_V, result, r1);
2141fcf5ef2aSThomas Huth tcg_gen_xor_tl(temp, result, r2);
2142fcf5ef2aSThomas Huth tcg_gen_movcond_tl(TCG_COND_GT, cpu_PSW_V, r1, r2, cpu_PSW_V, temp);
2143fcf5ef2aSThomas Huth tcg_gen_xor_tl(temp, r1, r2);
2144fcf5ef2aSThomas Huth tcg_gen_and_tl(cpu_PSW_V, cpu_PSW_V, temp);
2145fcf5ef2aSThomas Huth /* calc SV bit */
2146fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SV, cpu_PSW_SV, cpu_PSW_V);
2147fcf5ef2aSThomas Huth /* Calc AV bit */
2148fcf5ef2aSThomas Huth tcg_gen_add_tl(cpu_PSW_AV, result, result);
2149fcf5ef2aSThomas Huth tcg_gen_xor_tl(cpu_PSW_AV, result, cpu_PSW_AV);
2150fcf5ef2aSThomas Huth /* calc SAV bit */
2151fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SAV, cpu_PSW_SAV, cpu_PSW_AV);
2152fcf5ef2aSThomas Huth /* write back result */
2153fcf5ef2aSThomas Huth tcg_gen_mov_tl(ret, result);
2154fcf5ef2aSThomas Huth }
2155fcf5ef2aSThomas Huth
gen_absdifi(TCGv ret,TCGv r1,int32_t con)2156fcf5ef2aSThomas Huth static inline void gen_absdifi(TCGv ret, TCGv r1, int32_t con)
2157fcf5ef2aSThomas Huth {
2158151293c2SRichard Henderson TCGv temp = tcg_constant_i32(con);
2159fcf5ef2aSThomas Huth gen_absdif(ret, r1, temp);
2160fcf5ef2aSThomas Huth }
2161fcf5ef2aSThomas Huth
gen_absdifsi(TCGv ret,TCGv r1,int32_t con)2162fcf5ef2aSThomas Huth static inline void gen_absdifsi(TCGv ret, TCGv r1, int32_t con)
2163fcf5ef2aSThomas Huth {
2164151293c2SRichard Henderson TCGv temp = tcg_constant_i32(con);
2165ad75a51eSRichard Henderson gen_helper_absdif_ssov(ret, tcg_env, r1, temp);
2166fcf5ef2aSThomas Huth }
2167fcf5ef2aSThomas Huth
gen_mul_i32s(TCGv ret,TCGv r1,TCGv r2)2168fcf5ef2aSThomas Huth static inline void gen_mul_i32s(TCGv ret, TCGv r1, TCGv r2)
2169fcf5ef2aSThomas Huth {
2170fcf5ef2aSThomas Huth TCGv high = tcg_temp_new();
2171fcf5ef2aSThomas Huth TCGv low = tcg_temp_new();
2172fcf5ef2aSThomas Huth
2173fcf5ef2aSThomas Huth tcg_gen_muls2_tl(low, high, r1, r2);
2174fcf5ef2aSThomas Huth tcg_gen_mov_tl(ret, low);
2175fcf5ef2aSThomas Huth /* calc V bit */
2176fcf5ef2aSThomas Huth tcg_gen_sari_tl(low, low, 31);
2177fcf5ef2aSThomas Huth tcg_gen_setcond_tl(TCG_COND_NE, cpu_PSW_V, high, low);
2178fcf5ef2aSThomas Huth tcg_gen_shli_tl(cpu_PSW_V, cpu_PSW_V, 31);
2179fcf5ef2aSThomas Huth /* calc SV bit */
2180fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SV, cpu_PSW_SV, cpu_PSW_V);
2181fcf5ef2aSThomas Huth /* Calc AV bit */
2182fcf5ef2aSThomas Huth tcg_gen_add_tl(cpu_PSW_AV, ret, ret);
2183fcf5ef2aSThomas Huth tcg_gen_xor_tl(cpu_PSW_AV, ret, cpu_PSW_AV);
2184fcf5ef2aSThomas Huth /* calc SAV bit */
2185fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SAV, cpu_PSW_SAV, cpu_PSW_AV);
2186fcf5ef2aSThomas Huth }
2187fcf5ef2aSThomas Huth
gen_muli_i32s(TCGv ret,TCGv r1,int32_t con)2188fcf5ef2aSThomas Huth static inline void gen_muli_i32s(TCGv ret, TCGv r1, int32_t con)
2189fcf5ef2aSThomas Huth {
2190151293c2SRichard Henderson TCGv temp = tcg_constant_i32(con);
2191fcf5ef2aSThomas Huth gen_mul_i32s(ret, r1, temp);
2192fcf5ef2aSThomas Huth }
2193fcf5ef2aSThomas Huth
gen_mul_i64s(TCGv ret_low,TCGv ret_high,TCGv r1,TCGv r2)2194fcf5ef2aSThomas Huth static inline void gen_mul_i64s(TCGv ret_low, TCGv ret_high, TCGv r1, TCGv r2)
2195fcf5ef2aSThomas Huth {
2196fcf5ef2aSThomas Huth tcg_gen_muls2_tl(ret_low, ret_high, r1, r2);
2197fcf5ef2aSThomas Huth /* clear V bit */
2198fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_PSW_V, 0);
2199fcf5ef2aSThomas Huth /* calc SV bit */
2200fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SV, cpu_PSW_SV, cpu_PSW_V);
2201fcf5ef2aSThomas Huth /* Calc AV bit */
2202fcf5ef2aSThomas Huth tcg_gen_add_tl(cpu_PSW_AV, ret_high, ret_high);
2203fcf5ef2aSThomas Huth tcg_gen_xor_tl(cpu_PSW_AV, ret_high, cpu_PSW_AV);
2204fcf5ef2aSThomas Huth /* calc SAV bit */
2205fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SAV, cpu_PSW_SAV, cpu_PSW_AV);
2206fcf5ef2aSThomas Huth }
2207fcf5ef2aSThomas Huth
gen_muli_i64s(TCGv ret_low,TCGv ret_high,TCGv r1,int32_t con)2208fcf5ef2aSThomas Huth static inline void gen_muli_i64s(TCGv ret_low, TCGv ret_high, TCGv r1,
2209fcf5ef2aSThomas Huth int32_t con)
2210fcf5ef2aSThomas Huth {
2211151293c2SRichard Henderson TCGv temp = tcg_constant_i32(con);
2212fcf5ef2aSThomas Huth gen_mul_i64s(ret_low, ret_high, r1, temp);
2213fcf5ef2aSThomas Huth }
2214fcf5ef2aSThomas Huth
gen_mul_i64u(TCGv ret_low,TCGv ret_high,TCGv r1,TCGv r2)2215fcf5ef2aSThomas Huth static inline void gen_mul_i64u(TCGv ret_low, TCGv ret_high, TCGv r1, TCGv r2)
2216fcf5ef2aSThomas Huth {
2217fcf5ef2aSThomas Huth tcg_gen_mulu2_tl(ret_low, ret_high, r1, r2);
2218fcf5ef2aSThomas Huth /* clear V bit */
2219fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_PSW_V, 0);
2220fcf5ef2aSThomas Huth /* calc SV bit */
2221fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SV, cpu_PSW_SV, cpu_PSW_V);
2222fcf5ef2aSThomas Huth /* Calc AV bit */
2223fcf5ef2aSThomas Huth tcg_gen_add_tl(cpu_PSW_AV, ret_high, ret_high);
2224fcf5ef2aSThomas Huth tcg_gen_xor_tl(cpu_PSW_AV, ret_high, cpu_PSW_AV);
2225fcf5ef2aSThomas Huth /* calc SAV bit */
2226fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SAV, cpu_PSW_SAV, cpu_PSW_AV);
2227fcf5ef2aSThomas Huth }
2228fcf5ef2aSThomas Huth
gen_muli_i64u(TCGv ret_low,TCGv ret_high,TCGv r1,int32_t con)2229fcf5ef2aSThomas Huth static inline void gen_muli_i64u(TCGv ret_low, TCGv ret_high, TCGv r1,
2230fcf5ef2aSThomas Huth int32_t con)
2231fcf5ef2aSThomas Huth {
2232151293c2SRichard Henderson TCGv temp = tcg_constant_i32(con);
2233fcf5ef2aSThomas Huth gen_mul_i64u(ret_low, ret_high, r1, temp);
2234fcf5ef2aSThomas Huth }
2235fcf5ef2aSThomas Huth
gen_mulsi_i32(TCGv ret,TCGv r1,int32_t con)2236fcf5ef2aSThomas Huth static inline void gen_mulsi_i32(TCGv ret, TCGv r1, int32_t con)
2237fcf5ef2aSThomas Huth {
2238151293c2SRichard Henderson TCGv temp = tcg_constant_i32(con);
2239ad75a51eSRichard Henderson gen_helper_mul_ssov(ret, tcg_env, r1, temp);
2240fcf5ef2aSThomas Huth }
2241fcf5ef2aSThomas Huth
gen_mulsui_i32(TCGv ret,TCGv r1,int32_t con)2242fcf5ef2aSThomas Huth static inline void gen_mulsui_i32(TCGv ret, TCGv r1, int32_t con)
2243fcf5ef2aSThomas Huth {
2244151293c2SRichard Henderson TCGv temp = tcg_constant_i32(con);
2245ad75a51eSRichard Henderson gen_helper_mul_suov(ret, tcg_env, r1, temp);
2246fcf5ef2aSThomas Huth }
2247151293c2SRichard Henderson
2248fcf5ef2aSThomas Huth /* gen_maddsi_32(cpu_gpr_d[r4], cpu_gpr_d[r1], cpu_gpr_d[r3], const9); */
gen_maddsi_32(TCGv ret,TCGv r1,TCGv r2,int32_t con)2249fcf5ef2aSThomas Huth static inline void gen_maddsi_32(TCGv ret, TCGv r1, TCGv r2, int32_t con)
2250fcf5ef2aSThomas Huth {
2251151293c2SRichard Henderson TCGv temp = tcg_constant_i32(con);
2252ad75a51eSRichard Henderson gen_helper_madd32_ssov(ret, tcg_env, r1, r2, temp);
2253fcf5ef2aSThomas Huth }
2254fcf5ef2aSThomas Huth
gen_maddsui_32(TCGv ret,TCGv r1,TCGv r2,int32_t con)2255fcf5ef2aSThomas Huth static inline void gen_maddsui_32(TCGv ret, TCGv r1, TCGv r2, int32_t con)
2256fcf5ef2aSThomas Huth {
2257151293c2SRichard Henderson TCGv temp = tcg_constant_i32(con);
2258ad75a51eSRichard Henderson gen_helper_madd32_suov(ret, tcg_env, r1, r2, temp);
2259fcf5ef2aSThomas Huth }
2260fcf5ef2aSThomas Huth
2261fcf5ef2aSThomas Huth static void
gen_mul_q(TCGv rl,TCGv rh,TCGv arg1,TCGv arg2,uint32_t n,uint32_t up_shift)2262fcf5ef2aSThomas Huth gen_mul_q(TCGv rl, TCGv rh, TCGv arg1, TCGv arg2, uint32_t n, uint32_t up_shift)
2263fcf5ef2aSThomas Huth {
2264fcf5ef2aSThomas Huth TCGv_i64 temp_64 = tcg_temp_new_i64();
2265fcf5ef2aSThomas Huth TCGv_i64 temp2_64 = tcg_temp_new_i64();
2266fcf5ef2aSThomas Huth
2267fcf5ef2aSThomas Huth if (n == 0) {
2268fcf5ef2aSThomas Huth if (up_shift == 32) {
2269fcf5ef2aSThomas Huth tcg_gen_muls2_tl(rh, rl, arg1, arg2);
2270fcf5ef2aSThomas Huth } else if (up_shift == 16) {
2271fcf5ef2aSThomas Huth tcg_gen_ext_i32_i64(temp_64, arg1);
2272fcf5ef2aSThomas Huth tcg_gen_ext_i32_i64(temp2_64, arg2);
2273fcf5ef2aSThomas Huth
2274fcf5ef2aSThomas Huth tcg_gen_mul_i64(temp_64, temp_64, temp2_64);
2275fcf5ef2aSThomas Huth tcg_gen_shri_i64(temp_64, temp_64, up_shift);
2276fcf5ef2aSThomas Huth tcg_gen_extr_i64_i32(rl, rh, temp_64);
2277fcf5ef2aSThomas Huth } else {
2278fcf5ef2aSThomas Huth tcg_gen_muls2_tl(rl, rh, arg1, arg2);
2279fcf5ef2aSThomas Huth }
2280fcf5ef2aSThomas Huth /* reset v bit */
2281fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_PSW_V, 0);
2282fcf5ef2aSThomas Huth } else { /* n is expected to be 1 */
2283fcf5ef2aSThomas Huth tcg_gen_ext_i32_i64(temp_64, arg1);
2284fcf5ef2aSThomas Huth tcg_gen_ext_i32_i64(temp2_64, arg2);
2285fcf5ef2aSThomas Huth
2286fcf5ef2aSThomas Huth tcg_gen_mul_i64(temp_64, temp_64, temp2_64);
2287fcf5ef2aSThomas Huth
2288fcf5ef2aSThomas Huth if (up_shift == 0) {
2289fcf5ef2aSThomas Huth tcg_gen_shli_i64(temp_64, temp_64, 1);
2290fcf5ef2aSThomas Huth } else {
2291fcf5ef2aSThomas Huth tcg_gen_shri_i64(temp_64, temp_64, up_shift - 1);
2292fcf5ef2aSThomas Huth }
2293fcf5ef2aSThomas Huth tcg_gen_extr_i64_i32(rl, rh, temp_64);
2294fcf5ef2aSThomas Huth /* overflow only occurs if r1 = r2 = 0x8000 */
2295fcf5ef2aSThomas Huth if (up_shift == 0) {/* result is 64 bit */
2296fcf5ef2aSThomas Huth tcg_gen_setcondi_tl(TCG_COND_EQ, cpu_PSW_V, rh,
2297fcf5ef2aSThomas Huth 0x80000000);
2298fcf5ef2aSThomas Huth } else { /* result is 32 bit */
2299fcf5ef2aSThomas Huth tcg_gen_setcondi_tl(TCG_COND_EQ, cpu_PSW_V, rl,
2300fcf5ef2aSThomas Huth 0x80000000);
2301fcf5ef2aSThomas Huth }
2302fcf5ef2aSThomas Huth tcg_gen_shli_tl(cpu_PSW_V, cpu_PSW_V, 31);
2303fcf5ef2aSThomas Huth /* calc sv overflow bit */
2304fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SV, cpu_PSW_SV, cpu_PSW_V);
2305fcf5ef2aSThomas Huth }
2306fcf5ef2aSThomas Huth /* calc av overflow bit */
2307fcf5ef2aSThomas Huth if (up_shift == 0) {
2308fcf5ef2aSThomas Huth tcg_gen_add_tl(cpu_PSW_AV, rh, rh);
2309fcf5ef2aSThomas Huth tcg_gen_xor_tl(cpu_PSW_AV, rh, cpu_PSW_AV);
2310fcf5ef2aSThomas Huth } else {
2311fcf5ef2aSThomas Huth tcg_gen_add_tl(cpu_PSW_AV, rl, rl);
2312fcf5ef2aSThomas Huth tcg_gen_xor_tl(cpu_PSW_AV, rl, cpu_PSW_AV);
2313fcf5ef2aSThomas Huth }
2314fcf5ef2aSThomas Huth /* calc sav overflow bit */
2315fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SAV, cpu_PSW_SAV, cpu_PSW_AV);
2316fcf5ef2aSThomas Huth }
2317fcf5ef2aSThomas Huth
2318fcf5ef2aSThomas Huth static void
gen_mul_q_16(TCGv ret,TCGv arg1,TCGv arg2,uint32_t n)2319fcf5ef2aSThomas Huth gen_mul_q_16(TCGv ret, TCGv arg1, TCGv arg2, uint32_t n)
2320fcf5ef2aSThomas Huth {
2321fcf5ef2aSThomas Huth TCGv temp = tcg_temp_new();
2322fcf5ef2aSThomas Huth if (n == 0) {
2323fcf5ef2aSThomas Huth tcg_gen_mul_tl(ret, arg1, arg2);
2324fcf5ef2aSThomas Huth } else { /* n is expected to be 1 */
2325fcf5ef2aSThomas Huth tcg_gen_mul_tl(ret, arg1, arg2);
2326fcf5ef2aSThomas Huth tcg_gen_shli_tl(ret, ret, 1);
2327fcf5ef2aSThomas Huth /* catch special case r1 = r2 = 0x8000 */
2328fcf5ef2aSThomas Huth tcg_gen_setcondi_tl(TCG_COND_EQ, temp, ret, 0x80000000);
2329fcf5ef2aSThomas Huth tcg_gen_sub_tl(ret, ret, temp);
2330fcf5ef2aSThomas Huth }
2331fcf5ef2aSThomas Huth /* reset v bit */
2332fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_PSW_V, 0);
2333fcf5ef2aSThomas Huth /* calc av overflow bit */
2334fcf5ef2aSThomas Huth tcg_gen_add_tl(cpu_PSW_AV, ret, ret);
2335fcf5ef2aSThomas Huth tcg_gen_xor_tl(cpu_PSW_AV, ret, cpu_PSW_AV);
2336fcf5ef2aSThomas Huth /* calc sav overflow bit */
2337fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SAV, cpu_PSW_SAV, cpu_PSW_AV);
2338fcf5ef2aSThomas Huth }
2339fcf5ef2aSThomas Huth
gen_mulr_q(TCGv ret,TCGv arg1,TCGv arg2,uint32_t n)2340fcf5ef2aSThomas Huth static void gen_mulr_q(TCGv ret, TCGv arg1, TCGv arg2, uint32_t n)
2341fcf5ef2aSThomas Huth {
2342fcf5ef2aSThomas Huth TCGv temp = tcg_temp_new();
2343fcf5ef2aSThomas Huth if (n == 0) {
2344fcf5ef2aSThomas Huth tcg_gen_mul_tl(ret, arg1, arg2);
2345fcf5ef2aSThomas Huth tcg_gen_addi_tl(ret, ret, 0x8000);
2346fcf5ef2aSThomas Huth } else {
2347fcf5ef2aSThomas Huth tcg_gen_mul_tl(ret, arg1, arg2);
2348fcf5ef2aSThomas Huth tcg_gen_shli_tl(ret, ret, 1);
2349fcf5ef2aSThomas Huth tcg_gen_addi_tl(ret, ret, 0x8000);
2350fcf5ef2aSThomas Huth /* catch special case r1 = r2 = 0x8000 */
2351fcf5ef2aSThomas Huth tcg_gen_setcondi_tl(TCG_COND_EQ, temp, ret, 0x80008000);
2352fcf5ef2aSThomas Huth tcg_gen_muli_tl(temp, temp, 0x8001);
2353fcf5ef2aSThomas Huth tcg_gen_sub_tl(ret, ret, temp);
2354fcf5ef2aSThomas Huth }
2355fcf5ef2aSThomas Huth /* reset v bit */
2356fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_PSW_V, 0);
2357fcf5ef2aSThomas Huth /* calc av overflow bit */
2358fcf5ef2aSThomas Huth tcg_gen_add_tl(cpu_PSW_AV, ret, ret);
2359fcf5ef2aSThomas Huth tcg_gen_xor_tl(cpu_PSW_AV, ret, cpu_PSW_AV);
2360fcf5ef2aSThomas Huth /* calc sav overflow bit */
2361fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SAV, cpu_PSW_SAV, cpu_PSW_AV);
2362fcf5ef2aSThomas Huth /* cut halfword off */
2363fcf5ef2aSThomas Huth tcg_gen_andi_tl(ret, ret, 0xffff0000);
2364fcf5ef2aSThomas Huth }
2365fcf5ef2aSThomas Huth
2366fcf5ef2aSThomas Huth static inline void
gen_madds_64(TCGv ret_low,TCGv ret_high,TCGv r1,TCGv r2_low,TCGv r2_high,TCGv r3)2367fcf5ef2aSThomas Huth gen_madds_64(TCGv ret_low, TCGv ret_high, TCGv r1, TCGv r2_low, TCGv r2_high,
2368fcf5ef2aSThomas Huth TCGv r3)
2369fcf5ef2aSThomas Huth {
2370fcf5ef2aSThomas Huth TCGv_i64 temp64 = tcg_temp_new_i64();
2371fcf5ef2aSThomas Huth tcg_gen_concat_i32_i64(temp64, r2_low, r2_high);
2372ad75a51eSRichard Henderson gen_helper_madd64_ssov(temp64, tcg_env, r1, temp64, r3);
2373fcf5ef2aSThomas Huth tcg_gen_extr_i64_i32(ret_low, ret_high, temp64);
2374fcf5ef2aSThomas Huth }
2375fcf5ef2aSThomas Huth
2376fcf5ef2aSThomas Huth static inline void
gen_maddsi_64(TCGv ret_low,TCGv ret_high,TCGv r1,TCGv r2_low,TCGv r2_high,int32_t con)2377fcf5ef2aSThomas Huth gen_maddsi_64(TCGv ret_low, TCGv ret_high, TCGv r1, TCGv r2_low, TCGv r2_high,
2378fcf5ef2aSThomas Huth int32_t con)
2379fcf5ef2aSThomas Huth {
2380151293c2SRichard Henderson TCGv temp = tcg_constant_i32(con);
2381fcf5ef2aSThomas Huth gen_madds_64(ret_low, ret_high, r1, r2_low, r2_high, temp);
2382fcf5ef2aSThomas Huth }
2383fcf5ef2aSThomas Huth
2384fcf5ef2aSThomas Huth static inline void
gen_maddsu_64(TCGv ret_low,TCGv ret_high,TCGv r1,TCGv r2_low,TCGv r2_high,TCGv r3)2385fcf5ef2aSThomas Huth gen_maddsu_64(TCGv ret_low, TCGv ret_high, TCGv r1, TCGv r2_low, TCGv r2_high,
2386fcf5ef2aSThomas Huth TCGv r3)
2387fcf5ef2aSThomas Huth {
2388fcf5ef2aSThomas Huth TCGv_i64 temp64 = tcg_temp_new_i64();
2389fcf5ef2aSThomas Huth tcg_gen_concat_i32_i64(temp64, r2_low, r2_high);
2390ad75a51eSRichard Henderson gen_helper_madd64_suov(temp64, tcg_env, r1, temp64, r3);
2391fcf5ef2aSThomas Huth tcg_gen_extr_i64_i32(ret_low, ret_high, temp64);
2392fcf5ef2aSThomas Huth }
2393fcf5ef2aSThomas Huth
2394fcf5ef2aSThomas Huth static inline void
gen_maddsui_64(TCGv ret_low,TCGv ret_high,TCGv r1,TCGv r2_low,TCGv r2_high,int32_t con)2395fcf5ef2aSThomas Huth gen_maddsui_64(TCGv ret_low, TCGv ret_high, TCGv r1, TCGv r2_low, TCGv r2_high,
2396fcf5ef2aSThomas Huth int32_t con)
2397fcf5ef2aSThomas Huth {
2398151293c2SRichard Henderson TCGv temp = tcg_constant_i32(con);
2399fcf5ef2aSThomas Huth gen_maddsu_64(ret_low, ret_high, r1, r2_low, r2_high, temp);
2400fcf5ef2aSThomas Huth }
2401fcf5ef2aSThomas Huth
gen_msubsi_32(TCGv ret,TCGv r1,TCGv r2,int32_t con)2402fcf5ef2aSThomas Huth static inline void gen_msubsi_32(TCGv ret, TCGv r1, TCGv r2, int32_t con)
2403fcf5ef2aSThomas Huth {
2404151293c2SRichard Henderson TCGv temp = tcg_constant_i32(con);
2405ad75a51eSRichard Henderson gen_helper_msub32_ssov(ret, tcg_env, r1, r2, temp);
2406fcf5ef2aSThomas Huth }
2407fcf5ef2aSThomas Huth
gen_msubsui_32(TCGv ret,TCGv r1,TCGv r2,int32_t con)2408fcf5ef2aSThomas Huth static inline void gen_msubsui_32(TCGv ret, TCGv r1, TCGv r2, int32_t con)
2409fcf5ef2aSThomas Huth {
2410151293c2SRichard Henderson TCGv temp = tcg_constant_i32(con);
2411ad75a51eSRichard Henderson gen_helper_msub32_suov(ret, tcg_env, r1, r2, temp);
2412fcf5ef2aSThomas Huth }
2413fcf5ef2aSThomas Huth
2414fcf5ef2aSThomas Huth static inline void
gen_msubs_64(TCGv ret_low,TCGv ret_high,TCGv r1,TCGv r2_low,TCGv r2_high,TCGv r3)2415fcf5ef2aSThomas Huth gen_msubs_64(TCGv ret_low, TCGv ret_high, TCGv r1, TCGv r2_low, TCGv r2_high,
2416fcf5ef2aSThomas Huth TCGv r3)
2417fcf5ef2aSThomas Huth {
2418fcf5ef2aSThomas Huth TCGv_i64 temp64 = tcg_temp_new_i64();
2419fcf5ef2aSThomas Huth tcg_gen_concat_i32_i64(temp64, r2_low, r2_high);
2420ad75a51eSRichard Henderson gen_helper_msub64_ssov(temp64, tcg_env, r1, temp64, r3);
2421fcf5ef2aSThomas Huth tcg_gen_extr_i64_i32(ret_low, ret_high, temp64);
2422fcf5ef2aSThomas Huth }
2423fcf5ef2aSThomas Huth
2424fcf5ef2aSThomas Huth static inline void
gen_msubsi_64(TCGv ret_low,TCGv ret_high,TCGv r1,TCGv r2_low,TCGv r2_high,int32_t con)2425fcf5ef2aSThomas Huth gen_msubsi_64(TCGv ret_low, TCGv ret_high, TCGv r1, TCGv r2_low, TCGv r2_high,
2426fcf5ef2aSThomas Huth int32_t con)
2427fcf5ef2aSThomas Huth {
2428151293c2SRichard Henderson TCGv temp = tcg_constant_i32(con);
2429fcf5ef2aSThomas Huth gen_msubs_64(ret_low, ret_high, r1, r2_low, r2_high, temp);
2430fcf5ef2aSThomas Huth }
2431fcf5ef2aSThomas Huth
2432fcf5ef2aSThomas Huth static inline void
gen_msubsu_64(TCGv ret_low,TCGv ret_high,TCGv r1,TCGv r2_low,TCGv r2_high,TCGv r3)2433fcf5ef2aSThomas Huth gen_msubsu_64(TCGv ret_low, TCGv ret_high, TCGv r1, TCGv r2_low, TCGv r2_high,
2434fcf5ef2aSThomas Huth TCGv r3)
2435fcf5ef2aSThomas Huth {
2436fcf5ef2aSThomas Huth TCGv_i64 temp64 = tcg_temp_new_i64();
2437fcf5ef2aSThomas Huth tcg_gen_concat_i32_i64(temp64, r2_low, r2_high);
2438ad75a51eSRichard Henderson gen_helper_msub64_suov(temp64, tcg_env, r1, temp64, r3);
2439fcf5ef2aSThomas Huth tcg_gen_extr_i64_i32(ret_low, ret_high, temp64);
2440fcf5ef2aSThomas Huth }
2441fcf5ef2aSThomas Huth
2442fcf5ef2aSThomas Huth static inline void
gen_msubsui_64(TCGv ret_low,TCGv ret_high,TCGv r1,TCGv r2_low,TCGv r2_high,int32_t con)2443fcf5ef2aSThomas Huth gen_msubsui_64(TCGv ret_low, TCGv ret_high, TCGv r1, TCGv r2_low, TCGv r2_high,
2444fcf5ef2aSThomas Huth int32_t con)
2445fcf5ef2aSThomas Huth {
2446151293c2SRichard Henderson TCGv temp = tcg_constant_i32(con);
2447fcf5ef2aSThomas Huth gen_msubsu_64(ret_low, ret_high, r1, r2_low, r2_high, temp);
2448fcf5ef2aSThomas Huth }
2449fcf5ef2aSThomas Huth
gen_saturate(TCGv ret,TCGv arg,int32_t up,int32_t low)2450fcf5ef2aSThomas Huth static void gen_saturate(TCGv ret, TCGv arg, int32_t up, int32_t low)
2451fcf5ef2aSThomas Huth {
24525a48476eSRichard Henderson tcg_gen_smax_tl(ret, arg, tcg_constant_i32(low));
24535a48476eSRichard Henderson tcg_gen_smin_tl(ret, ret, tcg_constant_i32(up));
2454fcf5ef2aSThomas Huth }
2455fcf5ef2aSThomas Huth
gen_saturate_u(TCGv ret,TCGv arg,int32_t up)2456fcf5ef2aSThomas Huth static void gen_saturate_u(TCGv ret, TCGv arg, int32_t up)
2457fcf5ef2aSThomas Huth {
24585a48476eSRichard Henderson tcg_gen_umin_tl(ret, arg, tcg_constant_i32(up));
2459fcf5ef2aSThomas Huth }
2460fcf5ef2aSThomas Huth
gen_shi(TCGv ret,TCGv r1,int32_t shift_count)2461fcf5ef2aSThomas Huth static void gen_shi(TCGv ret, TCGv r1, int32_t shift_count)
2462fcf5ef2aSThomas Huth {
2463fcf5ef2aSThomas Huth if (shift_count == -32) {
2464fcf5ef2aSThomas Huth tcg_gen_movi_tl(ret, 0);
2465fcf5ef2aSThomas Huth } else if (shift_count >= 0) {
2466fcf5ef2aSThomas Huth tcg_gen_shli_tl(ret, r1, shift_count);
2467fcf5ef2aSThomas Huth } else {
2468fcf5ef2aSThomas Huth tcg_gen_shri_tl(ret, r1, -shift_count);
2469fcf5ef2aSThomas Huth }
2470fcf5ef2aSThomas Huth }
2471fcf5ef2aSThomas Huth
gen_sh_hi(TCGv ret,TCGv r1,int32_t shiftcount)2472fcf5ef2aSThomas Huth static void gen_sh_hi(TCGv ret, TCGv r1, int32_t shiftcount)
2473fcf5ef2aSThomas Huth {
2474fcf5ef2aSThomas Huth TCGv temp_low, temp_high;
2475fcf5ef2aSThomas Huth
2476fcf5ef2aSThomas Huth if (shiftcount == -16) {
2477fcf5ef2aSThomas Huth tcg_gen_movi_tl(ret, 0);
2478fcf5ef2aSThomas Huth } else {
2479fcf5ef2aSThomas Huth temp_high = tcg_temp_new();
2480fcf5ef2aSThomas Huth temp_low = tcg_temp_new();
2481fcf5ef2aSThomas Huth
2482fcf5ef2aSThomas Huth tcg_gen_andi_tl(temp_low, r1, 0xffff);
2483fcf5ef2aSThomas Huth tcg_gen_andi_tl(temp_high, r1, 0xffff0000);
2484fcf5ef2aSThomas Huth gen_shi(temp_low, temp_low, shiftcount);
2485fcf5ef2aSThomas Huth gen_shi(ret, temp_high, shiftcount);
2486fcf5ef2aSThomas Huth tcg_gen_deposit_tl(ret, ret, temp_low, 0, 16);
2487fcf5ef2aSThomas Huth }
2488fcf5ef2aSThomas Huth }
2489fcf5ef2aSThomas Huth
gen_shaci(TCGv ret,TCGv r1,int32_t shift_count)2490fcf5ef2aSThomas Huth static void gen_shaci(TCGv ret, TCGv r1, int32_t shift_count)
2491fcf5ef2aSThomas Huth {
2492fcf5ef2aSThomas Huth uint32_t msk, msk_start;
2493fcf5ef2aSThomas Huth TCGv temp = tcg_temp_new();
2494fcf5ef2aSThomas Huth TCGv temp2 = tcg_temp_new();
2495fcf5ef2aSThomas Huth
2496fcf5ef2aSThomas Huth if (shift_count == 0) {
2497fcf5ef2aSThomas Huth /* Clear PSW.C and PSW.V */
2498fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_PSW_C, 0);
2499fcf5ef2aSThomas Huth tcg_gen_mov_tl(cpu_PSW_V, cpu_PSW_C);
2500fcf5ef2aSThomas Huth tcg_gen_mov_tl(ret, r1);
2501fcf5ef2aSThomas Huth } else if (shift_count == -32) {
2502fcf5ef2aSThomas Huth /* set PSW.C */
2503fcf5ef2aSThomas Huth tcg_gen_mov_tl(cpu_PSW_C, r1);
2504fcf5ef2aSThomas Huth /* fill ret completely with sign bit */
2505fcf5ef2aSThomas Huth tcg_gen_sari_tl(ret, r1, 31);
2506fcf5ef2aSThomas Huth /* clear PSW.V */
2507fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_PSW_V, 0);
2508fcf5ef2aSThomas Huth } else if (shift_count > 0) {
2509151293c2SRichard Henderson TCGv t_max = tcg_constant_i32(0x7FFFFFFF >> shift_count);
2510151293c2SRichard Henderson TCGv t_min = tcg_constant_i32(((int32_t) -0x80000000) >> shift_count);
2511fcf5ef2aSThomas Huth
2512fcf5ef2aSThomas Huth /* calc carry */
2513fcf5ef2aSThomas Huth msk_start = 32 - shift_count;
2514fcf5ef2aSThomas Huth msk = ((1 << shift_count) - 1) << msk_start;
2515fcf5ef2aSThomas Huth tcg_gen_andi_tl(cpu_PSW_C, r1, msk);
2516fcf5ef2aSThomas Huth /* calc v/sv bits */
2517fcf5ef2aSThomas Huth tcg_gen_setcond_tl(TCG_COND_GT, temp, r1, t_max);
2518fcf5ef2aSThomas Huth tcg_gen_setcond_tl(TCG_COND_LT, temp2, r1, t_min);
2519fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_V, temp, temp2);
2520fcf5ef2aSThomas Huth tcg_gen_shli_tl(cpu_PSW_V, cpu_PSW_V, 31);
2521fcf5ef2aSThomas Huth /* calc sv */
2522fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SV, cpu_PSW_V, cpu_PSW_SV);
2523fcf5ef2aSThomas Huth /* do shift */
2524fcf5ef2aSThomas Huth tcg_gen_shli_tl(ret, r1, shift_count);
2525fcf5ef2aSThomas Huth } else {
2526fcf5ef2aSThomas Huth /* clear PSW.V */
2527fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_PSW_V, 0);
2528fcf5ef2aSThomas Huth /* calc carry */
2529fcf5ef2aSThomas Huth msk = (1 << -shift_count) - 1;
2530fcf5ef2aSThomas Huth tcg_gen_andi_tl(cpu_PSW_C, r1, msk);
2531fcf5ef2aSThomas Huth /* do shift */
2532fcf5ef2aSThomas Huth tcg_gen_sari_tl(ret, r1, -shift_count);
2533fcf5ef2aSThomas Huth }
2534fcf5ef2aSThomas Huth /* calc av overflow bit */
2535fcf5ef2aSThomas Huth tcg_gen_add_tl(cpu_PSW_AV, ret, ret);
2536fcf5ef2aSThomas Huth tcg_gen_xor_tl(cpu_PSW_AV, ret, cpu_PSW_AV);
2537fcf5ef2aSThomas Huth /* calc sav overflow bit */
2538fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SAV, cpu_PSW_SAV, cpu_PSW_AV);
2539fcf5ef2aSThomas Huth }
2540fcf5ef2aSThomas Huth
gen_shas(TCGv ret,TCGv r1,TCGv r2)2541fcf5ef2aSThomas Huth static void gen_shas(TCGv ret, TCGv r1, TCGv r2)
2542fcf5ef2aSThomas Huth {
2543ad75a51eSRichard Henderson gen_helper_sha_ssov(ret, tcg_env, r1, r2);
2544fcf5ef2aSThomas Huth }
2545fcf5ef2aSThomas Huth
gen_shasi(TCGv ret,TCGv r1,int32_t con)2546fcf5ef2aSThomas Huth static void gen_shasi(TCGv ret, TCGv r1, int32_t con)
2547fcf5ef2aSThomas Huth {
2548151293c2SRichard Henderson TCGv temp = tcg_constant_i32(con);
2549fcf5ef2aSThomas Huth gen_shas(ret, r1, temp);
2550fcf5ef2aSThomas Huth }
2551fcf5ef2aSThomas Huth
gen_sha_hi(TCGv ret,TCGv r1,int32_t shift_count)2552fcf5ef2aSThomas Huth static void gen_sha_hi(TCGv ret, TCGv r1, int32_t shift_count)
2553fcf5ef2aSThomas Huth {
2554fcf5ef2aSThomas Huth TCGv low, high;
2555fcf5ef2aSThomas Huth
2556fcf5ef2aSThomas Huth if (shift_count == 0) {
2557fcf5ef2aSThomas Huth tcg_gen_mov_tl(ret, r1);
2558fcf5ef2aSThomas Huth } else if (shift_count > 0) {
2559fcf5ef2aSThomas Huth low = tcg_temp_new();
2560fcf5ef2aSThomas Huth high = tcg_temp_new();
2561fcf5ef2aSThomas Huth
2562fcf5ef2aSThomas Huth tcg_gen_andi_tl(high, r1, 0xffff0000);
2563fcf5ef2aSThomas Huth tcg_gen_shli_tl(low, r1, shift_count);
2564fcf5ef2aSThomas Huth tcg_gen_shli_tl(ret, high, shift_count);
2565fcf5ef2aSThomas Huth tcg_gen_deposit_tl(ret, ret, low, 0, 16);
2566fcf5ef2aSThomas Huth } else {
2567fcf5ef2aSThomas Huth low = tcg_temp_new();
2568fcf5ef2aSThomas Huth high = tcg_temp_new();
2569fcf5ef2aSThomas Huth
2570fcf5ef2aSThomas Huth tcg_gen_ext16s_tl(low, r1);
2571fcf5ef2aSThomas Huth tcg_gen_sari_tl(low, low, -shift_count);
2572fcf5ef2aSThomas Huth tcg_gen_sari_tl(ret, r1, -shift_count);
2573fcf5ef2aSThomas Huth tcg_gen_deposit_tl(ret, ret, low, 0, 16);
2574fcf5ef2aSThomas Huth }
2575fcf5ef2aSThomas Huth }
2576fcf5ef2aSThomas Huth
2577fcf5ef2aSThomas Huth /* ret = {ret[30:0], (r1 cond r2)}; */
gen_sh_cond(int cond,TCGv ret,TCGv r1,TCGv r2)2578fcf5ef2aSThomas Huth static void gen_sh_cond(int cond, TCGv ret, TCGv r1, TCGv r2)
2579fcf5ef2aSThomas Huth {
2580fcf5ef2aSThomas Huth TCGv temp = tcg_temp_new();
2581fcf5ef2aSThomas Huth TCGv temp2 = tcg_temp_new();
2582fcf5ef2aSThomas Huth
2583fcf5ef2aSThomas Huth tcg_gen_shli_tl(temp, ret, 1);
2584fcf5ef2aSThomas Huth tcg_gen_setcond_tl(cond, temp2, r1, r2);
2585fcf5ef2aSThomas Huth tcg_gen_or_tl(ret, temp, temp2);
2586fcf5ef2aSThomas Huth }
2587fcf5ef2aSThomas Huth
gen_sh_condi(int cond,TCGv ret,TCGv r1,int32_t con)2588fcf5ef2aSThomas Huth static void gen_sh_condi(int cond, TCGv ret, TCGv r1, int32_t con)
2589fcf5ef2aSThomas Huth {
2590151293c2SRichard Henderson TCGv temp = tcg_constant_i32(con);
2591fcf5ef2aSThomas Huth gen_sh_cond(cond, ret, r1, temp);
2592fcf5ef2aSThomas Huth }
2593fcf5ef2aSThomas Huth
gen_adds(TCGv ret,TCGv r1,TCGv r2)2594fcf5ef2aSThomas Huth static inline void gen_adds(TCGv ret, TCGv r1, TCGv r2)
2595fcf5ef2aSThomas Huth {
2596ad75a51eSRichard Henderson gen_helper_add_ssov(ret, tcg_env, r1, r2);
2597fcf5ef2aSThomas Huth }
2598fcf5ef2aSThomas Huth
gen_addsi(TCGv ret,TCGv r1,int32_t con)2599fcf5ef2aSThomas Huth static inline void gen_addsi(TCGv ret, TCGv r1, int32_t con)
2600fcf5ef2aSThomas Huth {
2601151293c2SRichard Henderson TCGv temp = tcg_constant_i32(con);
2602ad75a51eSRichard Henderson gen_helper_add_ssov(ret, tcg_env, r1, temp);
2603fcf5ef2aSThomas Huth }
2604fcf5ef2aSThomas Huth
gen_addsui(TCGv ret,TCGv r1,int32_t con)2605fcf5ef2aSThomas Huth static inline void gen_addsui(TCGv ret, TCGv r1, int32_t con)
2606fcf5ef2aSThomas Huth {
2607151293c2SRichard Henderson TCGv temp = tcg_constant_i32(con);
2608ad75a51eSRichard Henderson gen_helper_add_suov(ret, tcg_env, r1, temp);
2609fcf5ef2aSThomas Huth }
2610fcf5ef2aSThomas Huth
gen_subs(TCGv ret,TCGv r1,TCGv r2)2611fcf5ef2aSThomas Huth static inline void gen_subs(TCGv ret, TCGv r1, TCGv r2)
2612fcf5ef2aSThomas Huth {
2613ad75a51eSRichard Henderson gen_helper_sub_ssov(ret, tcg_env, r1, r2);
2614fcf5ef2aSThomas Huth }
2615fcf5ef2aSThomas Huth
gen_subsu(TCGv ret,TCGv r1,TCGv r2)2616fcf5ef2aSThomas Huth static inline void gen_subsu(TCGv ret, TCGv r1, TCGv r2)
2617fcf5ef2aSThomas Huth {
2618ad75a51eSRichard Henderson gen_helper_sub_suov(ret, tcg_env, r1, r2);
2619fcf5ef2aSThomas Huth }
2620fcf5ef2aSThomas Huth
gen_bit_2op(TCGv ret,TCGv r1,TCGv r2,int pos1,int pos2,void (* op1)(TCGv,TCGv,TCGv),void (* op2)(TCGv,TCGv,TCGv))2621fcf5ef2aSThomas Huth static inline void gen_bit_2op(TCGv ret, TCGv r1, TCGv r2,
2622fcf5ef2aSThomas Huth int pos1, int pos2,
2623fcf5ef2aSThomas Huth void(*op1)(TCGv, TCGv, TCGv),
2624fcf5ef2aSThomas Huth void(*op2)(TCGv, TCGv, TCGv))
2625fcf5ef2aSThomas Huth {
2626fcf5ef2aSThomas Huth TCGv temp1, temp2;
2627fcf5ef2aSThomas Huth
2628fcf5ef2aSThomas Huth temp1 = tcg_temp_new();
2629fcf5ef2aSThomas Huth temp2 = tcg_temp_new();
2630fcf5ef2aSThomas Huth
2631fcf5ef2aSThomas Huth tcg_gen_shri_tl(temp2, r2, pos2);
2632fcf5ef2aSThomas Huth tcg_gen_shri_tl(temp1, r1, pos1);
2633fcf5ef2aSThomas Huth
2634fcf5ef2aSThomas Huth (*op1)(temp1, temp1, temp2);
2635fcf5ef2aSThomas Huth (*op2)(temp1 , ret, temp1);
2636fcf5ef2aSThomas Huth
2637fcf5ef2aSThomas Huth tcg_gen_deposit_tl(ret, ret, temp1, 0, 1);
2638fcf5ef2aSThomas Huth }
2639fcf5ef2aSThomas Huth
2640fcf5ef2aSThomas Huth /* ret = r1[pos1] op1 r2[pos2]; */
gen_bit_1op(TCGv ret,TCGv r1,TCGv r2,int pos1,int pos2,void (* op1)(TCGv,TCGv,TCGv))2641fcf5ef2aSThomas Huth static inline void gen_bit_1op(TCGv ret, TCGv r1, TCGv r2,
2642fcf5ef2aSThomas Huth int pos1, int pos2,
2643fcf5ef2aSThomas Huth void(*op1)(TCGv, TCGv, TCGv))
2644fcf5ef2aSThomas Huth {
2645fcf5ef2aSThomas Huth TCGv temp1, temp2;
2646fcf5ef2aSThomas Huth
2647fcf5ef2aSThomas Huth temp1 = tcg_temp_new();
2648fcf5ef2aSThomas Huth temp2 = tcg_temp_new();
2649fcf5ef2aSThomas Huth
2650fcf5ef2aSThomas Huth tcg_gen_shri_tl(temp2, r2, pos2);
2651fcf5ef2aSThomas Huth tcg_gen_shri_tl(temp1, r1, pos1);
2652fcf5ef2aSThomas Huth
2653fcf5ef2aSThomas Huth (*op1)(ret, temp1, temp2);
2654fcf5ef2aSThomas Huth
2655fcf5ef2aSThomas Huth tcg_gen_andi_tl(ret, ret, 0x1);
2656fcf5ef2aSThomas Huth }
2657fcf5ef2aSThomas Huth
gen_accumulating_cond(int cond,TCGv ret,TCGv r1,TCGv r2,void (* op)(TCGv,TCGv,TCGv))2658fcf5ef2aSThomas Huth static inline void gen_accumulating_cond(int cond, TCGv ret, TCGv r1, TCGv r2,
2659fcf5ef2aSThomas Huth void(*op)(TCGv, TCGv, TCGv))
2660fcf5ef2aSThomas Huth {
2661fcf5ef2aSThomas Huth TCGv temp = tcg_temp_new();
2662fcf5ef2aSThomas Huth TCGv temp2 = tcg_temp_new();
2663fcf5ef2aSThomas Huth /* temp = (arg1 cond arg2 )*/
2664fcf5ef2aSThomas Huth tcg_gen_setcond_tl(cond, temp, r1, r2);
2665fcf5ef2aSThomas Huth /* temp2 = ret[0]*/
2666fcf5ef2aSThomas Huth tcg_gen_andi_tl(temp2, ret, 0x1);
2667fcf5ef2aSThomas Huth /* temp = temp insn temp2 */
2668fcf5ef2aSThomas Huth (*op)(temp, temp, temp2);
2669fcf5ef2aSThomas Huth /* ret = {ret[31:1], temp} */
2670fcf5ef2aSThomas Huth tcg_gen_deposit_tl(ret, ret, temp, 0, 1);
2671fcf5ef2aSThomas Huth }
2672fcf5ef2aSThomas Huth
2673fcf5ef2aSThomas Huth static inline void
gen_accumulating_condi(int cond,TCGv ret,TCGv r1,int32_t con,void (* op)(TCGv,TCGv,TCGv))2674fcf5ef2aSThomas Huth gen_accumulating_condi(int cond, TCGv ret, TCGv r1, int32_t con,
2675fcf5ef2aSThomas Huth void(*op)(TCGv, TCGv, TCGv))
2676fcf5ef2aSThomas Huth {
2677151293c2SRichard Henderson TCGv temp = tcg_constant_i32(con);
2678fcf5ef2aSThomas Huth gen_accumulating_cond(cond, ret, r1, temp, op);
2679fcf5ef2aSThomas Huth }
2680fcf5ef2aSThomas Huth
gen_eqany_bi(TCGv ret,TCGv r1,int32_t con)2681fcf5ef2aSThomas Huth static inline void gen_eqany_bi(TCGv ret, TCGv r1, int32_t con)
2682fcf5ef2aSThomas Huth {
2683fcf5ef2aSThomas Huth TCGv b0 = tcg_temp_new();
2684fcf5ef2aSThomas Huth TCGv b1 = tcg_temp_new();
2685fcf5ef2aSThomas Huth TCGv b2 = tcg_temp_new();
2686fcf5ef2aSThomas Huth TCGv b3 = tcg_temp_new();
2687fcf5ef2aSThomas Huth
2688fcf5ef2aSThomas Huth /* byte 0 */
2689fcf5ef2aSThomas Huth tcg_gen_andi_tl(b0, r1, 0xff);
2690fcf5ef2aSThomas Huth tcg_gen_setcondi_tl(TCG_COND_EQ, b0, b0, con & 0xff);
2691fcf5ef2aSThomas Huth
2692fcf5ef2aSThomas Huth /* byte 1 */
2693fcf5ef2aSThomas Huth tcg_gen_andi_tl(b1, r1, 0xff00);
2694fcf5ef2aSThomas Huth tcg_gen_setcondi_tl(TCG_COND_EQ, b1, b1, con & 0xff00);
2695fcf5ef2aSThomas Huth
2696fcf5ef2aSThomas Huth /* byte 2 */
2697fcf5ef2aSThomas Huth tcg_gen_andi_tl(b2, r1, 0xff0000);
2698fcf5ef2aSThomas Huth tcg_gen_setcondi_tl(TCG_COND_EQ, b2, b2, con & 0xff0000);
2699fcf5ef2aSThomas Huth
2700fcf5ef2aSThomas Huth /* byte 3 */
2701fcf5ef2aSThomas Huth tcg_gen_andi_tl(b3, r1, 0xff000000);
2702fcf5ef2aSThomas Huth tcg_gen_setcondi_tl(TCG_COND_EQ, b3, b3, con & 0xff000000);
2703fcf5ef2aSThomas Huth
2704fcf5ef2aSThomas Huth /* combine them */
2705fcf5ef2aSThomas Huth tcg_gen_or_tl(ret, b0, b1);
2706fcf5ef2aSThomas Huth tcg_gen_or_tl(ret, ret, b2);
2707fcf5ef2aSThomas Huth tcg_gen_or_tl(ret, ret, b3);
2708fcf5ef2aSThomas Huth }
2709fcf5ef2aSThomas Huth
gen_eqany_hi(TCGv ret,TCGv r1,int32_t con)2710fcf5ef2aSThomas Huth static inline void gen_eqany_hi(TCGv ret, TCGv r1, int32_t con)
2711fcf5ef2aSThomas Huth {
2712fcf5ef2aSThomas Huth TCGv h0 = tcg_temp_new();
2713fcf5ef2aSThomas Huth TCGv h1 = tcg_temp_new();
2714fcf5ef2aSThomas Huth
2715fcf5ef2aSThomas Huth /* halfword 0 */
2716fcf5ef2aSThomas Huth tcg_gen_andi_tl(h0, r1, 0xffff);
2717fcf5ef2aSThomas Huth tcg_gen_setcondi_tl(TCG_COND_EQ, h0, h0, con & 0xffff);
2718fcf5ef2aSThomas Huth
2719fcf5ef2aSThomas Huth /* halfword 1 */
2720fcf5ef2aSThomas Huth tcg_gen_andi_tl(h1, r1, 0xffff0000);
2721fcf5ef2aSThomas Huth tcg_gen_setcondi_tl(TCG_COND_EQ, h1, h1, con & 0xffff0000);
2722fcf5ef2aSThomas Huth
2723fcf5ef2aSThomas Huth /* combine them */
2724fcf5ef2aSThomas Huth tcg_gen_or_tl(ret, h0, h1);
2725fcf5ef2aSThomas Huth }
272608ee498bSRichard Henderson
2727fcf5ef2aSThomas Huth /* mask = ((1 << width) -1) << pos;
2728fcf5ef2aSThomas Huth ret = (r1 & ~mask) | (r2 << pos) & mask); */
gen_insert(TCGv ret,TCGv r1,TCGv r2,TCGv width,TCGv pos)2729fcf5ef2aSThomas Huth static inline void gen_insert(TCGv ret, TCGv r1, TCGv r2, TCGv width, TCGv pos)
2730fcf5ef2aSThomas Huth {
2731fcf5ef2aSThomas Huth TCGv mask = tcg_temp_new();
2732fcf5ef2aSThomas Huth TCGv temp = tcg_temp_new();
2733fcf5ef2aSThomas Huth TCGv temp2 = tcg_temp_new();
2734fcf5ef2aSThomas Huth
2735*96ce24daSPhilippe Mathieu-Daudé tcg_gen_shl_tl(mask, tcg_constant_tl(1), width);
2736fcf5ef2aSThomas Huth tcg_gen_subi_tl(mask, mask, 1);
2737fcf5ef2aSThomas Huth tcg_gen_shl_tl(mask, mask, pos);
2738fcf5ef2aSThomas Huth
2739fcf5ef2aSThomas Huth tcg_gen_shl_tl(temp, r2, pos);
2740fcf5ef2aSThomas Huth tcg_gen_and_tl(temp, temp, mask);
2741fcf5ef2aSThomas Huth tcg_gen_andc_tl(temp2, r1, mask);
2742fcf5ef2aSThomas Huth tcg_gen_or_tl(ret, temp, temp2);
2743fcf5ef2aSThomas Huth }
2744fcf5ef2aSThomas Huth
gen_bsplit(TCGv rl,TCGv rh,TCGv r1)2745fcf5ef2aSThomas Huth static inline void gen_bsplit(TCGv rl, TCGv rh, TCGv r1)
2746fcf5ef2aSThomas Huth {
2747fcf5ef2aSThomas Huth TCGv_i64 temp = tcg_temp_new_i64();
2748fcf5ef2aSThomas Huth
2749fcf5ef2aSThomas Huth gen_helper_bsplit(temp, r1);
2750fcf5ef2aSThomas Huth tcg_gen_extr_i64_i32(rl, rh, temp);
2751fcf5ef2aSThomas Huth }
2752fcf5ef2aSThomas Huth
gen_unpack(TCGv rl,TCGv rh,TCGv r1)2753fcf5ef2aSThomas Huth static inline void gen_unpack(TCGv rl, TCGv rh, TCGv r1)
2754fcf5ef2aSThomas Huth {
2755fcf5ef2aSThomas Huth TCGv_i64 temp = tcg_temp_new_i64();
2756fcf5ef2aSThomas Huth
2757fcf5ef2aSThomas Huth gen_helper_unpack(temp, r1);
2758fcf5ef2aSThomas Huth tcg_gen_extr_i64_i32(rl, rh, temp);
2759fcf5ef2aSThomas Huth }
2760fcf5ef2aSThomas Huth
2761fcf5ef2aSThomas Huth static inline void
gen_dvinit_b(DisasContext * ctx,TCGv rl,TCGv rh,TCGv r1,TCGv r2)27622db92a0cSBastian Koppelmann gen_dvinit_b(DisasContext *ctx, TCGv rl, TCGv rh, TCGv r1, TCGv r2)
2763fcf5ef2aSThomas Huth {
2764fcf5ef2aSThomas Huth TCGv_i64 ret = tcg_temp_new_i64();
2765fcf5ef2aSThomas Huth
276644ee3bafSBastian Koppelmann if (!has_feature(ctx, TRICORE_FEATURE_131)) {
2767ad75a51eSRichard Henderson gen_helper_dvinit_b_13(ret, tcg_env, r1, r2);
2768fcf5ef2aSThomas Huth } else {
2769ad75a51eSRichard Henderson gen_helper_dvinit_b_131(ret, tcg_env, r1, r2);
2770fcf5ef2aSThomas Huth }
2771fcf5ef2aSThomas Huth tcg_gen_extr_i64_i32(rl, rh, ret);
2772fcf5ef2aSThomas Huth }
2773fcf5ef2aSThomas Huth
2774fcf5ef2aSThomas Huth static inline void
gen_dvinit_h(DisasContext * ctx,TCGv rl,TCGv rh,TCGv r1,TCGv r2)27752db92a0cSBastian Koppelmann gen_dvinit_h(DisasContext *ctx, TCGv rl, TCGv rh, TCGv r1, TCGv r2)
2776fcf5ef2aSThomas Huth {
2777fcf5ef2aSThomas Huth TCGv_i64 ret = tcg_temp_new_i64();
2778fcf5ef2aSThomas Huth
277944ee3bafSBastian Koppelmann if (!has_feature(ctx, TRICORE_FEATURE_131)) {
2780ad75a51eSRichard Henderson gen_helper_dvinit_h_13(ret, tcg_env, r1, r2);
2781fcf5ef2aSThomas Huth } else {
2782ad75a51eSRichard Henderson gen_helper_dvinit_h_131(ret, tcg_env, r1, r2);
2783fcf5ef2aSThomas Huth }
2784fcf5ef2aSThomas Huth tcg_gen_extr_i64_i32(rl, rh, ret);
2785fcf5ef2aSThomas Huth }
2786fcf5ef2aSThomas Huth
gen_calc_usb_mul_h(TCGv arg_low,TCGv arg_high)2787fcf5ef2aSThomas Huth static void gen_calc_usb_mul_h(TCGv arg_low, TCGv arg_high)
2788fcf5ef2aSThomas Huth {
2789fcf5ef2aSThomas Huth TCGv temp = tcg_temp_new();
2790fcf5ef2aSThomas Huth /* calc AV bit */
2791fcf5ef2aSThomas Huth tcg_gen_add_tl(temp, arg_low, arg_low);
2792fcf5ef2aSThomas Huth tcg_gen_xor_tl(temp, temp, arg_low);
2793fcf5ef2aSThomas Huth tcg_gen_add_tl(cpu_PSW_AV, arg_high, arg_high);
2794fcf5ef2aSThomas Huth tcg_gen_xor_tl(cpu_PSW_AV, cpu_PSW_AV, arg_high);
2795fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_AV, cpu_PSW_AV, temp);
2796fcf5ef2aSThomas Huth /* calc SAV bit */
2797fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SAV, cpu_PSW_SAV, cpu_PSW_AV);
2798fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_PSW_V, 0);
2799fcf5ef2aSThomas Huth }
2800fcf5ef2aSThomas Huth
gen_calc_usb_mulr_h(TCGv arg)2801fcf5ef2aSThomas Huth static void gen_calc_usb_mulr_h(TCGv arg)
2802fcf5ef2aSThomas Huth {
2803fcf5ef2aSThomas Huth TCGv temp = tcg_temp_new();
2804fcf5ef2aSThomas Huth /* calc AV bit */
2805fcf5ef2aSThomas Huth tcg_gen_add_tl(temp, arg, arg);
2806fcf5ef2aSThomas Huth tcg_gen_xor_tl(temp, temp, arg);
2807fcf5ef2aSThomas Huth tcg_gen_shli_tl(cpu_PSW_AV, temp, 16);
2808fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_AV, cpu_PSW_AV, temp);
2809fcf5ef2aSThomas Huth /* calc SAV bit */
2810fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SAV, cpu_PSW_SAV, cpu_PSW_AV);
2811fcf5ef2aSThomas Huth /* clear V bit */
2812fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_PSW_V, 0);
2813fcf5ef2aSThomas Huth }
2814fcf5ef2aSThomas Huth
2815fcf5ef2aSThomas Huth /* helpers for generating program flow micro-ops */
2816fcf5ef2aSThomas Huth
gen_save_pc(target_ulong pc)2817fcf5ef2aSThomas Huth static inline void gen_save_pc(target_ulong pc)
2818fcf5ef2aSThomas Huth {
2819fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_PC, pc);
2820fcf5ef2aSThomas Huth }
2821fcf5ef2aSThomas Huth
gen_goto_tb(DisasContext * ctx,int n,target_ulong dest)2822d6b6f261SRichard Henderson static void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest)
2823fcf5ef2aSThomas Huth {
2824d6b6f261SRichard Henderson if (translator_use_goto_tb(&ctx->base, dest)) {
2825fcf5ef2aSThomas Huth tcg_gen_goto_tb(n);
2826fcf5ef2aSThomas Huth gen_save_pc(dest);
28276b9f5a42SBastian Koppelmann tcg_gen_exit_tb(ctx->base.tb, n);
2828fcf5ef2aSThomas Huth } else {
2829fcf5ef2aSThomas Huth gen_save_pc(dest);
283038064715SRichard Henderson tcg_gen_lookup_and_goto_ptr();
2831fcf5ef2aSThomas Huth }
28321706e04fSBastian Koppelmann ctx->base.is_jmp = DISAS_NORETURN;
2833fcf5ef2aSThomas Huth }
2834fcf5ef2aSThomas Huth
generate_trap(DisasContext * ctx,int class,int tin)2835fcf5ef2aSThomas Huth static void generate_trap(DisasContext *ctx, int class, int tin)
2836fcf5ef2aSThomas Huth {
2837151293c2SRichard Henderson TCGv_i32 classtemp = tcg_constant_i32(class);
2838151293c2SRichard Henderson TCGv_i32 tintemp = tcg_constant_i32(tin);
2839fcf5ef2aSThomas Huth
28406b9f5a42SBastian Koppelmann gen_save_pc(ctx->base.pc_next);
2841ad75a51eSRichard Henderson gen_helper_raise_exception_sync(tcg_env, classtemp, tintemp);
28426b9f5a42SBastian Koppelmann ctx->base.is_jmp = DISAS_NORETURN;
2843fcf5ef2aSThomas Huth }
2844fcf5ef2aSThomas Huth
gen_branch_cond(DisasContext * ctx,TCGCond cond,TCGv r1,TCGv r2,int16_t address)2845fcf5ef2aSThomas Huth static inline void gen_branch_cond(DisasContext *ctx, TCGCond cond, TCGv r1,
2846fcf5ef2aSThomas Huth TCGv r2, int16_t address)
2847fcf5ef2aSThomas Huth {
2848fcf5ef2aSThomas Huth TCGLabel *jumpLabel = gen_new_label();
2849fcf5ef2aSThomas Huth tcg_gen_brcond_tl(cond, r1, r2, jumpLabel);
2850fcf5ef2aSThomas Huth
28516b9f5a42SBastian Koppelmann gen_goto_tb(ctx, 1, ctx->pc_succ_insn);
2852fcf5ef2aSThomas Huth
2853fcf5ef2aSThomas Huth gen_set_label(jumpLabel);
28546b9f5a42SBastian Koppelmann gen_goto_tb(ctx, 0, ctx->base.pc_next + address * 2);
2855fcf5ef2aSThomas Huth }
2856fcf5ef2aSThomas Huth
gen_branch_condi(DisasContext * ctx,TCGCond cond,TCGv r1,int r2,int16_t address)2857fcf5ef2aSThomas Huth static inline void gen_branch_condi(DisasContext *ctx, TCGCond cond, TCGv r1,
2858fcf5ef2aSThomas Huth int r2, int16_t address)
2859fcf5ef2aSThomas Huth {
2860151293c2SRichard Henderson TCGv temp = tcg_constant_i32(r2);
2861fcf5ef2aSThomas Huth gen_branch_cond(ctx, cond, r1, temp, address);
2862fcf5ef2aSThomas Huth }
2863fcf5ef2aSThomas Huth
gen_loop(DisasContext * ctx,int r1,int32_t offset)2864fcf5ef2aSThomas Huth static void gen_loop(DisasContext *ctx, int r1, int32_t offset)
2865fcf5ef2aSThomas Huth {
2866fcf5ef2aSThomas Huth TCGLabel *l1 = gen_new_label();
2867fcf5ef2aSThomas Huth
2868fcf5ef2aSThomas Huth tcg_gen_subi_tl(cpu_gpr_a[r1], cpu_gpr_a[r1], 1);
2869fcf5ef2aSThomas Huth tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_gpr_a[r1], -1, l1);
28706b9f5a42SBastian Koppelmann gen_goto_tb(ctx, 1, ctx->base.pc_next + offset);
2871fcf5ef2aSThomas Huth gen_set_label(l1);
28726b9f5a42SBastian Koppelmann gen_goto_tb(ctx, 0, ctx->pc_succ_insn);
2873fcf5ef2aSThomas Huth }
2874fcf5ef2aSThomas Huth
gen_fcall_save_ctx(DisasContext * ctx)2875fcf5ef2aSThomas Huth static void gen_fcall_save_ctx(DisasContext *ctx)
2876fcf5ef2aSThomas Huth {
2877fcf5ef2aSThomas Huth TCGv temp = tcg_temp_new();
2878fcf5ef2aSThomas Huth
2879fcf5ef2aSThomas Huth tcg_gen_addi_tl(temp, cpu_gpr_a[10], -4);
2880fcf5ef2aSThomas Huth tcg_gen_qemu_st_tl(cpu_gpr_a[11], temp, ctx->mem_idx, MO_LESL);
28816b9f5a42SBastian Koppelmann tcg_gen_movi_tl(cpu_gpr_a[11], ctx->pc_succ_insn);
2882fcf5ef2aSThomas Huth tcg_gen_mov_tl(cpu_gpr_a[10], temp);
2883fcf5ef2aSThomas Huth }
2884fcf5ef2aSThomas Huth
gen_fret(DisasContext * ctx)2885fcf5ef2aSThomas Huth static void gen_fret(DisasContext *ctx)
2886fcf5ef2aSThomas Huth {
2887fcf5ef2aSThomas Huth TCGv temp = tcg_temp_new();
2888fcf5ef2aSThomas Huth
2889fcf5ef2aSThomas Huth tcg_gen_andi_tl(temp, cpu_gpr_a[11], ~0x1);
2890fcf5ef2aSThomas Huth tcg_gen_qemu_ld_tl(cpu_gpr_a[11], cpu_gpr_a[10], ctx->mem_idx, MO_LESL);
2891fcf5ef2aSThomas Huth tcg_gen_addi_tl(cpu_gpr_a[10], cpu_gpr_a[10], 4);
2892fcf5ef2aSThomas Huth tcg_gen_mov_tl(cpu_PC, temp);
28931706e04fSBastian Koppelmann ctx->base.is_jmp = DISAS_EXIT;
2894fcf5ef2aSThomas Huth }
2895fcf5ef2aSThomas Huth
gen_compute_branch(DisasContext * ctx,uint32_t opc,int r1,int r2,int32_t constant,int32_t offset)2896fcf5ef2aSThomas Huth static void gen_compute_branch(DisasContext *ctx, uint32_t opc, int r1,
2897fcf5ef2aSThomas Huth int r2 , int32_t constant , int32_t offset)
2898fcf5ef2aSThomas Huth {
2899fcf5ef2aSThomas Huth TCGv temp, temp2;
2900fcf5ef2aSThomas Huth int n;
2901fcf5ef2aSThomas Huth
2902fcf5ef2aSThomas Huth switch (opc) {
2903fcf5ef2aSThomas Huth /* SB-format jumps */
2904fcf5ef2aSThomas Huth case OPC1_16_SB_J:
2905fcf5ef2aSThomas Huth case OPC1_32_B_J:
29066b9f5a42SBastian Koppelmann gen_goto_tb(ctx, 0, ctx->base.pc_next + offset * 2);
2907fcf5ef2aSThomas Huth break;
2908fcf5ef2aSThomas Huth case OPC1_32_B_CALL:
2909fcf5ef2aSThomas Huth case OPC1_16_SB_CALL:
29106b9f5a42SBastian Koppelmann gen_helper_1arg(call, ctx->pc_succ_insn);
29116b9f5a42SBastian Koppelmann gen_goto_tb(ctx, 0, ctx->base.pc_next + offset * 2);
2912fcf5ef2aSThomas Huth break;
2913fcf5ef2aSThomas Huth case OPC1_16_SB_JZ:
2914fcf5ef2aSThomas Huth gen_branch_condi(ctx, TCG_COND_EQ, cpu_gpr_d[15], 0, offset);
2915fcf5ef2aSThomas Huth break;
2916fcf5ef2aSThomas Huth case OPC1_16_SB_JNZ:
2917fcf5ef2aSThomas Huth gen_branch_condi(ctx, TCG_COND_NE, cpu_gpr_d[15], 0, offset);
2918fcf5ef2aSThomas Huth break;
2919fcf5ef2aSThomas Huth /* SBC-format jumps */
2920fcf5ef2aSThomas Huth case OPC1_16_SBC_JEQ:
2921fcf5ef2aSThomas Huth gen_branch_condi(ctx, TCG_COND_EQ, cpu_gpr_d[15], constant, offset);
2922fcf5ef2aSThomas Huth break;
2923dedd8c9cSPeer Adelt case OPC1_16_SBC_JEQ2:
2924dedd8c9cSPeer Adelt gen_branch_condi(ctx, TCG_COND_EQ, cpu_gpr_d[15], constant,
2925dedd8c9cSPeer Adelt offset + 16);
2926dedd8c9cSPeer Adelt break;
2927fcf5ef2aSThomas Huth case OPC1_16_SBC_JNE:
2928fcf5ef2aSThomas Huth gen_branch_condi(ctx, TCG_COND_NE, cpu_gpr_d[15], constant, offset);
2929fcf5ef2aSThomas Huth break;
2930dedd8c9cSPeer Adelt case OPC1_16_SBC_JNE2:
2931dedd8c9cSPeer Adelt gen_branch_condi(ctx, TCG_COND_NE, cpu_gpr_d[15],
2932dedd8c9cSPeer Adelt constant, offset + 16);
2933dedd8c9cSPeer Adelt break;
2934fcf5ef2aSThomas Huth /* SBRN-format jumps */
2935fcf5ef2aSThomas Huth case OPC1_16_SBRN_JZ_T:
2936fcf5ef2aSThomas Huth temp = tcg_temp_new();
2937fcf5ef2aSThomas Huth tcg_gen_andi_tl(temp, cpu_gpr_d[15], 0x1u << constant);
2938fcf5ef2aSThomas Huth gen_branch_condi(ctx, TCG_COND_EQ, temp, 0, offset);
2939fcf5ef2aSThomas Huth break;
2940fcf5ef2aSThomas Huth case OPC1_16_SBRN_JNZ_T:
2941fcf5ef2aSThomas Huth temp = tcg_temp_new();
2942fcf5ef2aSThomas Huth tcg_gen_andi_tl(temp, cpu_gpr_d[15], 0x1u << constant);
2943fcf5ef2aSThomas Huth gen_branch_condi(ctx, TCG_COND_NE, temp, 0, offset);
2944fcf5ef2aSThomas Huth break;
2945fcf5ef2aSThomas Huth /* SBR-format jumps */
2946fcf5ef2aSThomas Huth case OPC1_16_SBR_JEQ:
2947fcf5ef2aSThomas Huth gen_branch_cond(ctx, TCG_COND_EQ, cpu_gpr_d[r1], cpu_gpr_d[15],
2948fcf5ef2aSThomas Huth offset);
2949fcf5ef2aSThomas Huth break;
2950defda2d4SDavid Brenken case OPC1_16_SBR_JEQ2:
2951defda2d4SDavid Brenken gen_branch_cond(ctx, TCG_COND_EQ, cpu_gpr_d[r1], cpu_gpr_d[15],
2952defda2d4SDavid Brenken offset + 16);
2953defda2d4SDavid Brenken break;
2954fcf5ef2aSThomas Huth case OPC1_16_SBR_JNE:
2955fcf5ef2aSThomas Huth gen_branch_cond(ctx, TCG_COND_NE, cpu_gpr_d[r1], cpu_gpr_d[15],
2956fcf5ef2aSThomas Huth offset);
2957fcf5ef2aSThomas Huth break;
2958defda2d4SDavid Brenken case OPC1_16_SBR_JNE2:
2959defda2d4SDavid Brenken gen_branch_cond(ctx, TCG_COND_NE, cpu_gpr_d[r1], cpu_gpr_d[15],
2960defda2d4SDavid Brenken offset + 16);
2961defda2d4SDavid Brenken break;
2962fcf5ef2aSThomas Huth case OPC1_16_SBR_JNZ:
2963fcf5ef2aSThomas Huth gen_branch_condi(ctx, TCG_COND_NE, cpu_gpr_d[r1], 0, offset);
2964fcf5ef2aSThomas Huth break;
2965fcf5ef2aSThomas Huth case OPC1_16_SBR_JNZ_A:
2966fcf5ef2aSThomas Huth gen_branch_condi(ctx, TCG_COND_NE, cpu_gpr_a[r1], 0, offset);
2967fcf5ef2aSThomas Huth break;
2968fcf5ef2aSThomas Huth case OPC1_16_SBR_JGEZ:
2969fcf5ef2aSThomas Huth gen_branch_condi(ctx, TCG_COND_GE, cpu_gpr_d[r1], 0, offset);
2970fcf5ef2aSThomas Huth break;
2971fcf5ef2aSThomas Huth case OPC1_16_SBR_JGTZ:
2972fcf5ef2aSThomas Huth gen_branch_condi(ctx, TCG_COND_GT, cpu_gpr_d[r1], 0, offset);
2973fcf5ef2aSThomas Huth break;
2974fcf5ef2aSThomas Huth case OPC1_16_SBR_JLEZ:
2975fcf5ef2aSThomas Huth gen_branch_condi(ctx, TCG_COND_LE, cpu_gpr_d[r1], 0, offset);
2976fcf5ef2aSThomas Huth break;
2977fcf5ef2aSThomas Huth case OPC1_16_SBR_JLTZ:
2978fcf5ef2aSThomas Huth gen_branch_condi(ctx, TCG_COND_LT, cpu_gpr_d[r1], 0, offset);
2979fcf5ef2aSThomas Huth break;
2980fcf5ef2aSThomas Huth case OPC1_16_SBR_JZ:
2981fcf5ef2aSThomas Huth gen_branch_condi(ctx, TCG_COND_EQ, cpu_gpr_d[r1], 0, offset);
2982fcf5ef2aSThomas Huth break;
2983fcf5ef2aSThomas Huth case OPC1_16_SBR_JZ_A:
2984fcf5ef2aSThomas Huth gen_branch_condi(ctx, TCG_COND_EQ, cpu_gpr_a[r1], 0, offset);
2985fcf5ef2aSThomas Huth break;
2986fcf5ef2aSThomas Huth case OPC1_16_SBR_LOOP:
2987fcf5ef2aSThomas Huth gen_loop(ctx, r1, offset * 2 - 32);
2988fcf5ef2aSThomas Huth break;
2989fcf5ef2aSThomas Huth /* SR-format jumps */
2990fcf5ef2aSThomas Huth case OPC1_16_SR_JI:
2991fcf5ef2aSThomas Huth tcg_gen_andi_tl(cpu_PC, cpu_gpr_a[r1], 0xfffffffe);
29921706e04fSBastian Koppelmann ctx->base.is_jmp = DISAS_EXIT;
2993fcf5ef2aSThomas Huth break;
2994fcf5ef2aSThomas Huth case OPC2_32_SYS_RET:
2995fcf5ef2aSThomas Huth case OPC2_16_SR_RET:
2996ad75a51eSRichard Henderson gen_helper_ret(tcg_env);
29971706e04fSBastian Koppelmann ctx->base.is_jmp = DISAS_EXIT;
2998fcf5ef2aSThomas Huth break;
2999fcf5ef2aSThomas Huth /* B-format */
3000fcf5ef2aSThomas Huth case OPC1_32_B_CALLA:
30016b9f5a42SBastian Koppelmann gen_helper_1arg(call, ctx->pc_succ_insn);
3002fcf5ef2aSThomas Huth gen_goto_tb(ctx, 0, EA_B_ABSOLUT(offset));
3003fcf5ef2aSThomas Huth break;
3004fcf5ef2aSThomas Huth case OPC1_32_B_FCALL:
3005fcf5ef2aSThomas Huth gen_fcall_save_ctx(ctx);
30066b9f5a42SBastian Koppelmann gen_goto_tb(ctx, 0, ctx->base.pc_next + offset * 2);
3007fcf5ef2aSThomas Huth break;
3008fcf5ef2aSThomas Huth case OPC1_32_B_FCALLA:
3009fcf5ef2aSThomas Huth gen_fcall_save_ctx(ctx);
3010fcf5ef2aSThomas Huth gen_goto_tb(ctx, 0, EA_B_ABSOLUT(offset));
3011fcf5ef2aSThomas Huth break;
3012fcf5ef2aSThomas Huth case OPC1_32_B_JLA:
30136b9f5a42SBastian Koppelmann tcg_gen_movi_tl(cpu_gpr_a[11], ctx->pc_succ_insn);
3014fcf5ef2aSThomas Huth /* fall through */
3015fcf5ef2aSThomas Huth case OPC1_32_B_JA:
3016fcf5ef2aSThomas Huth gen_goto_tb(ctx, 0, EA_B_ABSOLUT(offset));
3017fcf5ef2aSThomas Huth break;
3018fcf5ef2aSThomas Huth case OPC1_32_B_JL:
30196b9f5a42SBastian Koppelmann tcg_gen_movi_tl(cpu_gpr_a[11], ctx->pc_succ_insn);
30206b9f5a42SBastian Koppelmann gen_goto_tb(ctx, 0, ctx->base.pc_next + offset * 2);
3021fcf5ef2aSThomas Huth break;
3022fcf5ef2aSThomas Huth /* BOL format */
3023fcf5ef2aSThomas Huth case OPCM_32_BRC_EQ_NEQ:
3024fcf5ef2aSThomas Huth if (MASK_OP_BRC_OP2(ctx->opcode) == OPC2_32_BRC_JEQ) {
3025fcf5ef2aSThomas Huth gen_branch_condi(ctx, TCG_COND_EQ, cpu_gpr_d[r1], constant, offset);
3026fcf5ef2aSThomas Huth } else {
3027fcf5ef2aSThomas Huth gen_branch_condi(ctx, TCG_COND_NE, cpu_gpr_d[r1], constant, offset);
3028fcf5ef2aSThomas Huth }
3029fcf5ef2aSThomas Huth break;
3030fcf5ef2aSThomas Huth case OPCM_32_BRC_GE:
3031fcf5ef2aSThomas Huth if (MASK_OP_BRC_OP2(ctx->opcode) == OP2_32_BRC_JGE) {
3032fcf5ef2aSThomas Huth gen_branch_condi(ctx, TCG_COND_GE, cpu_gpr_d[r1], constant, offset);
3033fcf5ef2aSThomas Huth } else {
3034fcf5ef2aSThomas Huth constant = MASK_OP_BRC_CONST4(ctx->opcode);
3035fcf5ef2aSThomas Huth gen_branch_condi(ctx, TCG_COND_GEU, cpu_gpr_d[r1], constant,
3036fcf5ef2aSThomas Huth offset);
3037fcf5ef2aSThomas Huth }
3038fcf5ef2aSThomas Huth break;
3039fcf5ef2aSThomas Huth case OPCM_32_BRC_JLT:
3040fcf5ef2aSThomas Huth if (MASK_OP_BRC_OP2(ctx->opcode) == OPC2_32_BRC_JLT) {
3041fcf5ef2aSThomas Huth gen_branch_condi(ctx, TCG_COND_LT, cpu_gpr_d[r1], constant, offset);
3042fcf5ef2aSThomas Huth } else {
3043fcf5ef2aSThomas Huth constant = MASK_OP_BRC_CONST4(ctx->opcode);
3044fcf5ef2aSThomas Huth gen_branch_condi(ctx, TCG_COND_LTU, cpu_gpr_d[r1], constant,
3045fcf5ef2aSThomas Huth offset);
3046fcf5ef2aSThomas Huth }
3047fcf5ef2aSThomas Huth break;
3048fcf5ef2aSThomas Huth case OPCM_32_BRC_JNE:
3049fcf5ef2aSThomas Huth temp = tcg_temp_new();
3050fcf5ef2aSThomas Huth if (MASK_OP_BRC_OP2(ctx->opcode) == OPC2_32_BRC_JNED) {
3051fcf5ef2aSThomas Huth tcg_gen_mov_tl(temp, cpu_gpr_d[r1]);
3052fcf5ef2aSThomas Huth /* subi is unconditional */
3053fcf5ef2aSThomas Huth tcg_gen_subi_tl(cpu_gpr_d[r1], cpu_gpr_d[r1], 1);
3054fcf5ef2aSThomas Huth gen_branch_condi(ctx, TCG_COND_NE, temp, constant, offset);
3055fcf5ef2aSThomas Huth } else {
3056fcf5ef2aSThomas Huth tcg_gen_mov_tl(temp, cpu_gpr_d[r1]);
3057fcf5ef2aSThomas Huth /* addi is unconditional */
3058fcf5ef2aSThomas Huth tcg_gen_addi_tl(cpu_gpr_d[r1], cpu_gpr_d[r1], 1);
3059fcf5ef2aSThomas Huth gen_branch_condi(ctx, TCG_COND_NE, temp, constant, offset);
3060fcf5ef2aSThomas Huth }
3061fcf5ef2aSThomas Huth break;
3062fcf5ef2aSThomas Huth /* BRN format */
3063fcf5ef2aSThomas Huth case OPCM_32_BRN_JTT:
3064fcf5ef2aSThomas Huth n = MASK_OP_BRN_N(ctx->opcode);
3065fcf5ef2aSThomas Huth
3066fcf5ef2aSThomas Huth temp = tcg_temp_new();
3067fcf5ef2aSThomas Huth tcg_gen_andi_tl(temp, cpu_gpr_d[r1], (1 << n));
3068fcf5ef2aSThomas Huth
3069fcf5ef2aSThomas Huth if (MASK_OP_BRN_OP2(ctx->opcode) == OPC2_32_BRN_JNZ_T) {
3070fcf5ef2aSThomas Huth gen_branch_condi(ctx, TCG_COND_NE, temp, 0, offset);
3071fcf5ef2aSThomas Huth } else {
3072fcf5ef2aSThomas Huth gen_branch_condi(ctx, TCG_COND_EQ, temp, 0, offset);
3073fcf5ef2aSThomas Huth }
3074fcf5ef2aSThomas Huth break;
3075fcf5ef2aSThomas Huth /* BRR Format */
3076fcf5ef2aSThomas Huth case OPCM_32_BRR_EQ_NEQ:
3077fcf5ef2aSThomas Huth if (MASK_OP_BRR_OP2(ctx->opcode) == OPC2_32_BRR_JEQ) {
3078fcf5ef2aSThomas Huth gen_branch_cond(ctx, TCG_COND_EQ, cpu_gpr_d[r1], cpu_gpr_d[r2],
3079fcf5ef2aSThomas Huth offset);
3080fcf5ef2aSThomas Huth } else {
3081fcf5ef2aSThomas Huth gen_branch_cond(ctx, TCG_COND_NE, cpu_gpr_d[r1], cpu_gpr_d[r2],
3082fcf5ef2aSThomas Huth offset);
3083fcf5ef2aSThomas Huth }
3084fcf5ef2aSThomas Huth break;
3085fcf5ef2aSThomas Huth case OPCM_32_BRR_ADDR_EQ_NEQ:
3086fcf5ef2aSThomas Huth if (MASK_OP_BRR_OP2(ctx->opcode) == OPC2_32_BRR_JEQ_A) {
3087fcf5ef2aSThomas Huth gen_branch_cond(ctx, TCG_COND_EQ, cpu_gpr_a[r1], cpu_gpr_a[r2],
3088fcf5ef2aSThomas Huth offset);
3089fcf5ef2aSThomas Huth } else {
3090fcf5ef2aSThomas Huth gen_branch_cond(ctx, TCG_COND_NE, cpu_gpr_a[r1], cpu_gpr_a[r2],
3091fcf5ef2aSThomas Huth offset);
3092fcf5ef2aSThomas Huth }
3093fcf5ef2aSThomas Huth break;
3094fcf5ef2aSThomas Huth case OPCM_32_BRR_GE:
3095fcf5ef2aSThomas Huth if (MASK_OP_BRR_OP2(ctx->opcode) == OPC2_32_BRR_JGE) {
3096fcf5ef2aSThomas Huth gen_branch_cond(ctx, TCG_COND_GE, cpu_gpr_d[r1], cpu_gpr_d[r2],
3097fcf5ef2aSThomas Huth offset);
3098fcf5ef2aSThomas Huth } else {
3099fcf5ef2aSThomas Huth gen_branch_cond(ctx, TCG_COND_GEU, cpu_gpr_d[r1], cpu_gpr_d[r2],
3100fcf5ef2aSThomas Huth offset);
3101fcf5ef2aSThomas Huth }
3102fcf5ef2aSThomas Huth break;
3103fcf5ef2aSThomas Huth case OPCM_32_BRR_JLT:
3104fcf5ef2aSThomas Huth if (MASK_OP_BRR_OP2(ctx->opcode) == OPC2_32_BRR_JLT) {
3105fcf5ef2aSThomas Huth gen_branch_cond(ctx, TCG_COND_LT, cpu_gpr_d[r1], cpu_gpr_d[r2],
3106fcf5ef2aSThomas Huth offset);
3107fcf5ef2aSThomas Huth } else {
3108fcf5ef2aSThomas Huth gen_branch_cond(ctx, TCG_COND_LTU, cpu_gpr_d[r1], cpu_gpr_d[r2],
3109fcf5ef2aSThomas Huth offset);
3110fcf5ef2aSThomas Huth }
3111fcf5ef2aSThomas Huth break;
3112fcf5ef2aSThomas Huth case OPCM_32_BRR_LOOP:
3113fcf5ef2aSThomas Huth if (MASK_OP_BRR_OP2(ctx->opcode) == OPC2_32_BRR_LOOP) {
3114fcf5ef2aSThomas Huth gen_loop(ctx, r2, offset * 2);
3115fcf5ef2aSThomas Huth } else {
3116fcf5ef2aSThomas Huth /* OPC2_32_BRR_LOOPU */
31176b9f5a42SBastian Koppelmann gen_goto_tb(ctx, 0, ctx->base.pc_next + offset * 2);
3118fcf5ef2aSThomas Huth }
3119fcf5ef2aSThomas Huth break;
3120fcf5ef2aSThomas Huth case OPCM_32_BRR_JNE:
3121fcf5ef2aSThomas Huth temp = tcg_temp_new();
3122fcf5ef2aSThomas Huth temp2 = tcg_temp_new();
3123fcf5ef2aSThomas Huth if (MASK_OP_BRC_OP2(ctx->opcode) == OPC2_32_BRR_JNED) {
3124fcf5ef2aSThomas Huth tcg_gen_mov_tl(temp, cpu_gpr_d[r1]);
3125fcf5ef2aSThomas Huth /* also save r2, in case of r1 == r2, so r2 is not decremented */
3126fcf5ef2aSThomas Huth tcg_gen_mov_tl(temp2, cpu_gpr_d[r2]);
3127fcf5ef2aSThomas Huth /* subi is unconditional */
3128fcf5ef2aSThomas Huth tcg_gen_subi_tl(cpu_gpr_d[r1], cpu_gpr_d[r1], 1);
3129fcf5ef2aSThomas Huth gen_branch_cond(ctx, TCG_COND_NE, temp, temp2, offset);
3130fcf5ef2aSThomas Huth } else {
3131fcf5ef2aSThomas Huth tcg_gen_mov_tl(temp, cpu_gpr_d[r1]);
3132fcf5ef2aSThomas Huth /* also save r2, in case of r1 == r2, so r2 is not decremented */
3133fcf5ef2aSThomas Huth tcg_gen_mov_tl(temp2, cpu_gpr_d[r2]);
3134fcf5ef2aSThomas Huth /* addi is unconditional */
3135fcf5ef2aSThomas Huth tcg_gen_addi_tl(cpu_gpr_d[r1], cpu_gpr_d[r1], 1);
3136fcf5ef2aSThomas Huth gen_branch_cond(ctx, TCG_COND_NE, temp, temp2, offset);
3137fcf5ef2aSThomas Huth }
3138fcf5ef2aSThomas Huth break;
3139fcf5ef2aSThomas Huth case OPCM_32_BRR_JNZ:
3140fcf5ef2aSThomas Huth if (MASK_OP_BRR_OP2(ctx->opcode) == OPC2_32_BRR_JNZ_A) {
3141fcf5ef2aSThomas Huth gen_branch_condi(ctx, TCG_COND_NE, cpu_gpr_a[r1], 0, offset);
3142fcf5ef2aSThomas Huth } else {
3143fcf5ef2aSThomas Huth gen_branch_condi(ctx, TCG_COND_EQ, cpu_gpr_a[r1], 0, offset);
3144fcf5ef2aSThomas Huth }
3145fcf5ef2aSThomas Huth break;
3146fcf5ef2aSThomas Huth default:
3147fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
3148fcf5ef2aSThomas Huth }
3149fcf5ef2aSThomas Huth }
3150fcf5ef2aSThomas Huth
3151fcf5ef2aSThomas Huth
3152fcf5ef2aSThomas Huth /*
3153fcf5ef2aSThomas Huth * Functions for decoding instructions
3154fcf5ef2aSThomas Huth */
3155fcf5ef2aSThomas Huth
decode_src_opc(DisasContext * ctx,int op1)31562db92a0cSBastian Koppelmann static void decode_src_opc(DisasContext *ctx, int op1)
3157fcf5ef2aSThomas Huth {
3158fcf5ef2aSThomas Huth int r1;
3159fcf5ef2aSThomas Huth int32_t const4;
3160fcf5ef2aSThomas Huth TCGv temp, temp2;
3161fcf5ef2aSThomas Huth
3162fcf5ef2aSThomas Huth r1 = MASK_OP_SRC_S1D(ctx->opcode);
3163fcf5ef2aSThomas Huth const4 = MASK_OP_SRC_CONST4_SEXT(ctx->opcode);
3164fcf5ef2aSThomas Huth
3165fcf5ef2aSThomas Huth switch (op1) {
3166fcf5ef2aSThomas Huth case OPC1_16_SRC_ADD:
3167fcf5ef2aSThomas Huth gen_addi_d(cpu_gpr_d[r1], cpu_gpr_d[r1], const4);
3168fcf5ef2aSThomas Huth break;
3169fcf5ef2aSThomas Huth case OPC1_16_SRC_ADD_A15:
3170fcf5ef2aSThomas Huth gen_addi_d(cpu_gpr_d[r1], cpu_gpr_d[15], const4);
3171fcf5ef2aSThomas Huth break;
3172fcf5ef2aSThomas Huth case OPC1_16_SRC_ADD_15A:
3173fcf5ef2aSThomas Huth gen_addi_d(cpu_gpr_d[15], cpu_gpr_d[r1], const4);
3174fcf5ef2aSThomas Huth break;
3175fcf5ef2aSThomas Huth case OPC1_16_SRC_ADD_A:
3176fcf5ef2aSThomas Huth tcg_gen_addi_tl(cpu_gpr_a[r1], cpu_gpr_a[r1], const4);
3177fcf5ef2aSThomas Huth break;
3178fcf5ef2aSThomas Huth case OPC1_16_SRC_CADD:
3179fcf5ef2aSThomas Huth gen_condi_add(TCG_COND_NE, cpu_gpr_d[r1], const4, cpu_gpr_d[r1],
3180fcf5ef2aSThomas Huth cpu_gpr_d[15]);
3181fcf5ef2aSThomas Huth break;
3182fcf5ef2aSThomas Huth case OPC1_16_SRC_CADDN:
3183fcf5ef2aSThomas Huth gen_condi_add(TCG_COND_EQ, cpu_gpr_d[r1], const4, cpu_gpr_d[r1],
3184fcf5ef2aSThomas Huth cpu_gpr_d[15]);
3185fcf5ef2aSThomas Huth break;
3186fcf5ef2aSThomas Huth case OPC1_16_SRC_CMOV:
3187151293c2SRichard Henderson temp = tcg_constant_tl(0);
3188151293c2SRichard Henderson temp2 = tcg_constant_tl(const4);
3189fcf5ef2aSThomas Huth tcg_gen_movcond_tl(TCG_COND_NE, cpu_gpr_d[r1], cpu_gpr_d[15], temp,
3190fcf5ef2aSThomas Huth temp2, cpu_gpr_d[r1]);
3191fcf5ef2aSThomas Huth break;
3192fcf5ef2aSThomas Huth case OPC1_16_SRC_CMOVN:
3193151293c2SRichard Henderson temp = tcg_constant_tl(0);
3194151293c2SRichard Henderson temp2 = tcg_constant_tl(const4);
3195fcf5ef2aSThomas Huth tcg_gen_movcond_tl(TCG_COND_EQ, cpu_gpr_d[r1], cpu_gpr_d[15], temp,
3196fcf5ef2aSThomas Huth temp2, cpu_gpr_d[r1]);
3197fcf5ef2aSThomas Huth break;
3198fcf5ef2aSThomas Huth case OPC1_16_SRC_EQ:
3199fcf5ef2aSThomas Huth tcg_gen_setcondi_tl(TCG_COND_EQ, cpu_gpr_d[15], cpu_gpr_d[r1],
3200fcf5ef2aSThomas Huth const4);
3201fcf5ef2aSThomas Huth break;
3202fcf5ef2aSThomas Huth case OPC1_16_SRC_LT:
3203fcf5ef2aSThomas Huth tcg_gen_setcondi_tl(TCG_COND_LT, cpu_gpr_d[15], cpu_gpr_d[r1],
3204fcf5ef2aSThomas Huth const4);
3205fcf5ef2aSThomas Huth break;
3206fcf5ef2aSThomas Huth case OPC1_16_SRC_MOV:
3207fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_gpr_d[r1], const4);
3208fcf5ef2aSThomas Huth break;
3209fcf5ef2aSThomas Huth case OPC1_16_SRC_MOV_A:
3210fcf5ef2aSThomas Huth const4 = MASK_OP_SRC_CONST4(ctx->opcode);
3211fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_gpr_a[r1], const4);
3212fcf5ef2aSThomas Huth break;
3213fcf5ef2aSThomas Huth case OPC1_16_SRC_MOV_E:
321444ee3bafSBastian Koppelmann if (has_feature(ctx, TRICORE_FEATURE_16)) {
32156991777eSBastian Koppelmann CHECK_REG_PAIR(r1);
3216fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_gpr_d[r1], const4);
3217fcf5ef2aSThomas Huth tcg_gen_sari_tl(cpu_gpr_d[r1+1], cpu_gpr_d[r1], 31);
3218fcf5ef2aSThomas Huth } else {
3219fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
3220fcf5ef2aSThomas Huth }
3221fcf5ef2aSThomas Huth break;
3222fcf5ef2aSThomas Huth case OPC1_16_SRC_SH:
3223fcf5ef2aSThomas Huth gen_shi(cpu_gpr_d[r1], cpu_gpr_d[r1], const4);
3224fcf5ef2aSThomas Huth break;
3225fcf5ef2aSThomas Huth case OPC1_16_SRC_SHA:
3226fcf5ef2aSThomas Huth gen_shaci(cpu_gpr_d[r1], cpu_gpr_d[r1], const4);
3227fcf5ef2aSThomas Huth break;
3228fcf5ef2aSThomas Huth default:
3229fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
3230fcf5ef2aSThomas Huth }
3231fcf5ef2aSThomas Huth }
3232fcf5ef2aSThomas Huth
decode_srr_opc(DisasContext * ctx,int op1)3233fcf5ef2aSThomas Huth static void decode_srr_opc(DisasContext *ctx, int op1)
3234fcf5ef2aSThomas Huth {
3235fcf5ef2aSThomas Huth int r1, r2;
3236fcf5ef2aSThomas Huth TCGv temp;
3237fcf5ef2aSThomas Huth
3238fcf5ef2aSThomas Huth r1 = MASK_OP_SRR_S1D(ctx->opcode);
3239fcf5ef2aSThomas Huth r2 = MASK_OP_SRR_S2(ctx->opcode);
3240fcf5ef2aSThomas Huth
3241fcf5ef2aSThomas Huth switch (op1) {
3242fcf5ef2aSThomas Huth case OPC1_16_SRR_ADD:
3243fcf5ef2aSThomas Huth gen_add_d(cpu_gpr_d[r1], cpu_gpr_d[r1], cpu_gpr_d[r2]);
3244fcf5ef2aSThomas Huth break;
3245fcf5ef2aSThomas Huth case OPC1_16_SRR_ADD_A15:
3246fcf5ef2aSThomas Huth gen_add_d(cpu_gpr_d[r1], cpu_gpr_d[15], cpu_gpr_d[r2]);
3247fcf5ef2aSThomas Huth break;
3248fcf5ef2aSThomas Huth case OPC1_16_SRR_ADD_15A:
3249fcf5ef2aSThomas Huth gen_add_d(cpu_gpr_d[15], cpu_gpr_d[r1], cpu_gpr_d[r2]);
3250fcf5ef2aSThomas Huth break;
3251fcf5ef2aSThomas Huth case OPC1_16_SRR_ADD_A:
3252fcf5ef2aSThomas Huth tcg_gen_add_tl(cpu_gpr_a[r1], cpu_gpr_a[r1], cpu_gpr_a[r2]);
3253fcf5ef2aSThomas Huth break;
3254fcf5ef2aSThomas Huth case OPC1_16_SRR_ADDS:
3255fcf5ef2aSThomas Huth gen_adds(cpu_gpr_d[r1], cpu_gpr_d[r1], cpu_gpr_d[r2]);
3256fcf5ef2aSThomas Huth break;
3257fcf5ef2aSThomas Huth case OPC1_16_SRR_AND:
3258fcf5ef2aSThomas Huth tcg_gen_and_tl(cpu_gpr_d[r1], cpu_gpr_d[r1], cpu_gpr_d[r2]);
3259fcf5ef2aSThomas Huth break;
3260fcf5ef2aSThomas Huth case OPC1_16_SRR_CMOV:
3261151293c2SRichard Henderson temp = tcg_constant_tl(0);
3262fcf5ef2aSThomas Huth tcg_gen_movcond_tl(TCG_COND_NE, cpu_gpr_d[r1], cpu_gpr_d[15], temp,
3263fcf5ef2aSThomas Huth cpu_gpr_d[r2], cpu_gpr_d[r1]);
3264fcf5ef2aSThomas Huth break;
3265fcf5ef2aSThomas Huth case OPC1_16_SRR_CMOVN:
3266151293c2SRichard Henderson temp = tcg_constant_tl(0);
3267fcf5ef2aSThomas Huth tcg_gen_movcond_tl(TCG_COND_EQ, cpu_gpr_d[r1], cpu_gpr_d[15], temp,
3268fcf5ef2aSThomas Huth cpu_gpr_d[r2], cpu_gpr_d[r1]);
3269fcf5ef2aSThomas Huth break;
3270fcf5ef2aSThomas Huth case OPC1_16_SRR_EQ:
3271fcf5ef2aSThomas Huth tcg_gen_setcond_tl(TCG_COND_EQ, cpu_gpr_d[15], cpu_gpr_d[r1],
3272fcf5ef2aSThomas Huth cpu_gpr_d[r2]);
3273fcf5ef2aSThomas Huth break;
3274fcf5ef2aSThomas Huth case OPC1_16_SRR_LT:
3275fcf5ef2aSThomas Huth tcg_gen_setcond_tl(TCG_COND_LT, cpu_gpr_d[15], cpu_gpr_d[r1],
3276fcf5ef2aSThomas Huth cpu_gpr_d[r2]);
3277fcf5ef2aSThomas Huth break;
3278fcf5ef2aSThomas Huth case OPC1_16_SRR_MOV:
3279fcf5ef2aSThomas Huth tcg_gen_mov_tl(cpu_gpr_d[r1], cpu_gpr_d[r2]);
3280fcf5ef2aSThomas Huth break;
3281fcf5ef2aSThomas Huth case OPC1_16_SRR_MOV_A:
3282fcf5ef2aSThomas Huth tcg_gen_mov_tl(cpu_gpr_a[r1], cpu_gpr_d[r2]);
3283fcf5ef2aSThomas Huth break;
3284fcf5ef2aSThomas Huth case OPC1_16_SRR_MOV_AA:
3285fcf5ef2aSThomas Huth tcg_gen_mov_tl(cpu_gpr_a[r1], cpu_gpr_a[r2]);
3286fcf5ef2aSThomas Huth break;
3287fcf5ef2aSThomas Huth case OPC1_16_SRR_MOV_D:
3288fcf5ef2aSThomas Huth tcg_gen_mov_tl(cpu_gpr_d[r1], cpu_gpr_a[r2]);
3289fcf5ef2aSThomas Huth break;
3290fcf5ef2aSThomas Huth case OPC1_16_SRR_MUL:
3291fcf5ef2aSThomas Huth gen_mul_i32s(cpu_gpr_d[r1], cpu_gpr_d[r1], cpu_gpr_d[r2]);
3292fcf5ef2aSThomas Huth break;
3293fcf5ef2aSThomas Huth case OPC1_16_SRR_OR:
3294fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_gpr_d[r1], cpu_gpr_d[r1], cpu_gpr_d[r2]);
3295fcf5ef2aSThomas Huth break;
3296fcf5ef2aSThomas Huth case OPC1_16_SRR_SUB:
3297fcf5ef2aSThomas Huth gen_sub_d(cpu_gpr_d[r1], cpu_gpr_d[r1], cpu_gpr_d[r2]);
3298fcf5ef2aSThomas Huth break;
3299fcf5ef2aSThomas Huth case OPC1_16_SRR_SUB_A15B:
3300fcf5ef2aSThomas Huth gen_sub_d(cpu_gpr_d[r1], cpu_gpr_d[15], cpu_gpr_d[r2]);
3301fcf5ef2aSThomas Huth break;
3302fcf5ef2aSThomas Huth case OPC1_16_SRR_SUB_15AB:
3303fcf5ef2aSThomas Huth gen_sub_d(cpu_gpr_d[15], cpu_gpr_d[r1], cpu_gpr_d[r2]);
3304fcf5ef2aSThomas Huth break;
3305fcf5ef2aSThomas Huth case OPC1_16_SRR_SUBS:
3306fcf5ef2aSThomas Huth gen_subs(cpu_gpr_d[r1], cpu_gpr_d[r1], cpu_gpr_d[r2]);
3307fcf5ef2aSThomas Huth break;
3308fcf5ef2aSThomas Huth case OPC1_16_SRR_XOR:
3309fcf5ef2aSThomas Huth tcg_gen_xor_tl(cpu_gpr_d[r1], cpu_gpr_d[r1], cpu_gpr_d[r2]);
3310fcf5ef2aSThomas Huth break;
3311fcf5ef2aSThomas Huth default:
3312fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
3313fcf5ef2aSThomas Huth }
3314fcf5ef2aSThomas Huth }
3315fcf5ef2aSThomas Huth
decode_ssr_opc(DisasContext * ctx,int op1)3316fcf5ef2aSThomas Huth static void decode_ssr_opc(DisasContext *ctx, int op1)
3317fcf5ef2aSThomas Huth {
3318fcf5ef2aSThomas Huth int r1, r2;
3319fcf5ef2aSThomas Huth
3320fcf5ef2aSThomas Huth r1 = MASK_OP_SSR_S1(ctx->opcode);
3321fcf5ef2aSThomas Huth r2 = MASK_OP_SSR_S2(ctx->opcode);
3322fcf5ef2aSThomas Huth
3323fcf5ef2aSThomas Huth switch (op1) {
3324fcf5ef2aSThomas Huth case OPC1_16_SSR_ST_A:
3325fcf5ef2aSThomas Huth tcg_gen_qemu_st_tl(cpu_gpr_a[r1], cpu_gpr_a[r2], ctx->mem_idx, MO_LEUL);
3326fcf5ef2aSThomas Huth break;
3327fcf5ef2aSThomas Huth case OPC1_16_SSR_ST_A_POSTINC:
3328fcf5ef2aSThomas Huth tcg_gen_qemu_st_tl(cpu_gpr_a[r1], cpu_gpr_a[r2], ctx->mem_idx, MO_LEUL);
3329fcf5ef2aSThomas Huth tcg_gen_addi_tl(cpu_gpr_a[r2], cpu_gpr_a[r2], 4);
3330fcf5ef2aSThomas Huth break;
3331fcf5ef2aSThomas Huth case OPC1_16_SSR_ST_B:
3332fcf5ef2aSThomas Huth tcg_gen_qemu_st_tl(cpu_gpr_d[r1], cpu_gpr_a[r2], ctx->mem_idx, MO_UB);
3333fcf5ef2aSThomas Huth break;
3334fcf5ef2aSThomas Huth case OPC1_16_SSR_ST_B_POSTINC:
3335fcf5ef2aSThomas Huth tcg_gen_qemu_st_tl(cpu_gpr_d[r1], cpu_gpr_a[r2], ctx->mem_idx, MO_UB);
3336fcf5ef2aSThomas Huth tcg_gen_addi_tl(cpu_gpr_a[r2], cpu_gpr_a[r2], 1);
3337fcf5ef2aSThomas Huth break;
3338fcf5ef2aSThomas Huth case OPC1_16_SSR_ST_H:
3339fcf5ef2aSThomas Huth tcg_gen_qemu_st_tl(cpu_gpr_d[r1], cpu_gpr_a[r2], ctx->mem_idx, MO_LEUW);
3340fcf5ef2aSThomas Huth break;
3341fcf5ef2aSThomas Huth case OPC1_16_SSR_ST_H_POSTINC:
3342fcf5ef2aSThomas Huth tcg_gen_qemu_st_tl(cpu_gpr_d[r1], cpu_gpr_a[r2], ctx->mem_idx, MO_LEUW);
3343fcf5ef2aSThomas Huth tcg_gen_addi_tl(cpu_gpr_a[r2], cpu_gpr_a[r2], 2);
3344fcf5ef2aSThomas Huth break;
3345fcf5ef2aSThomas Huth case OPC1_16_SSR_ST_W:
3346fcf5ef2aSThomas Huth tcg_gen_qemu_st_tl(cpu_gpr_d[r1], cpu_gpr_a[r2], ctx->mem_idx, MO_LEUL);
3347fcf5ef2aSThomas Huth break;
3348fcf5ef2aSThomas Huth case OPC1_16_SSR_ST_W_POSTINC:
3349fcf5ef2aSThomas Huth tcg_gen_qemu_st_tl(cpu_gpr_d[r1], cpu_gpr_a[r2], ctx->mem_idx, MO_LEUL);
3350fcf5ef2aSThomas Huth tcg_gen_addi_tl(cpu_gpr_a[r2], cpu_gpr_a[r2], 4);
3351fcf5ef2aSThomas Huth break;
3352fcf5ef2aSThomas Huth default:
3353fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
3354fcf5ef2aSThomas Huth }
3355fcf5ef2aSThomas Huth }
3356fcf5ef2aSThomas Huth
decode_sc_opc(DisasContext * ctx,int op1)3357fcf5ef2aSThomas Huth static void decode_sc_opc(DisasContext *ctx, int op1)
3358fcf5ef2aSThomas Huth {
3359fcf5ef2aSThomas Huth int32_t const16;
3360fcf5ef2aSThomas Huth
3361fcf5ef2aSThomas Huth const16 = MASK_OP_SC_CONST8(ctx->opcode);
3362fcf5ef2aSThomas Huth
3363fcf5ef2aSThomas Huth switch (op1) {
3364fcf5ef2aSThomas Huth case OPC1_16_SC_AND:
3365fcf5ef2aSThomas Huth tcg_gen_andi_tl(cpu_gpr_d[15], cpu_gpr_d[15], const16);
3366fcf5ef2aSThomas Huth break;
3367fcf5ef2aSThomas Huth case OPC1_16_SC_BISR:
336857b9c589SBastian Koppelmann if (ctx->priv == TRICORE_PRIV_SM) {
3369fcf5ef2aSThomas Huth gen_helper_1arg(bisr, const16 & 0xff);
337057b9c589SBastian Koppelmann } else {
337157b9c589SBastian Koppelmann generate_trap(ctx, TRAPC_PROT, TIN1_PRIV);
337257b9c589SBastian Koppelmann }
3373fcf5ef2aSThomas Huth break;
3374fcf5ef2aSThomas Huth case OPC1_16_SC_LD_A:
3375fcf5ef2aSThomas Huth gen_offset_ld(ctx, cpu_gpr_a[15], cpu_gpr_a[10], const16 * 4, MO_LESL);
3376fcf5ef2aSThomas Huth break;
3377fcf5ef2aSThomas Huth case OPC1_16_SC_LD_W:
3378fcf5ef2aSThomas Huth gen_offset_ld(ctx, cpu_gpr_d[15], cpu_gpr_a[10], const16 * 4, MO_LESL);
3379fcf5ef2aSThomas Huth break;
3380fcf5ef2aSThomas Huth case OPC1_16_SC_MOV:
3381fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_gpr_d[15], const16);
3382fcf5ef2aSThomas Huth break;
3383fcf5ef2aSThomas Huth case OPC1_16_SC_OR:
3384fcf5ef2aSThomas Huth tcg_gen_ori_tl(cpu_gpr_d[15], cpu_gpr_d[15], const16);
3385fcf5ef2aSThomas Huth break;
3386fcf5ef2aSThomas Huth case OPC1_16_SC_ST_A:
3387fcf5ef2aSThomas Huth gen_offset_st(ctx, cpu_gpr_a[15], cpu_gpr_a[10], const16 * 4, MO_LESL);
3388fcf5ef2aSThomas Huth break;
3389fcf5ef2aSThomas Huth case OPC1_16_SC_ST_W:
3390fcf5ef2aSThomas Huth gen_offset_st(ctx, cpu_gpr_d[15], cpu_gpr_a[10], const16 * 4, MO_LESL);
3391fcf5ef2aSThomas Huth break;
3392fcf5ef2aSThomas Huth case OPC1_16_SC_SUB_A:
3393fcf5ef2aSThomas Huth tcg_gen_subi_tl(cpu_gpr_a[10], cpu_gpr_a[10], const16);
3394fcf5ef2aSThomas Huth break;
3395fcf5ef2aSThomas Huth default:
3396fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
3397fcf5ef2aSThomas Huth }
3398fcf5ef2aSThomas Huth }
3399fcf5ef2aSThomas Huth
decode_slr_opc(DisasContext * ctx,int op1)3400fcf5ef2aSThomas Huth static void decode_slr_opc(DisasContext *ctx, int op1)
3401fcf5ef2aSThomas Huth {
3402fcf5ef2aSThomas Huth int r1, r2;
3403fcf5ef2aSThomas Huth
3404fcf5ef2aSThomas Huth r1 = MASK_OP_SLR_D(ctx->opcode);
3405fcf5ef2aSThomas Huth r2 = MASK_OP_SLR_S2(ctx->opcode);
3406fcf5ef2aSThomas Huth
3407fcf5ef2aSThomas Huth switch (op1) {
3408fcf5ef2aSThomas Huth /* SLR-format */
3409fcf5ef2aSThomas Huth case OPC1_16_SLR_LD_A:
3410fcf5ef2aSThomas Huth tcg_gen_qemu_ld_tl(cpu_gpr_a[r1], cpu_gpr_a[r2], ctx->mem_idx, MO_LESL);
3411fcf5ef2aSThomas Huth break;
3412fcf5ef2aSThomas Huth case OPC1_16_SLR_LD_A_POSTINC:
3413fcf5ef2aSThomas Huth tcg_gen_qemu_ld_tl(cpu_gpr_a[r1], cpu_gpr_a[r2], ctx->mem_idx, MO_LESL);
3414fcf5ef2aSThomas Huth tcg_gen_addi_tl(cpu_gpr_a[r2], cpu_gpr_a[r2], 4);
3415fcf5ef2aSThomas Huth break;
3416fcf5ef2aSThomas Huth case OPC1_16_SLR_LD_BU:
3417fcf5ef2aSThomas Huth tcg_gen_qemu_ld_tl(cpu_gpr_d[r1], cpu_gpr_a[r2], ctx->mem_idx, MO_UB);
3418fcf5ef2aSThomas Huth break;
3419fcf5ef2aSThomas Huth case OPC1_16_SLR_LD_BU_POSTINC:
3420fcf5ef2aSThomas Huth tcg_gen_qemu_ld_tl(cpu_gpr_d[r1], cpu_gpr_a[r2], ctx->mem_idx, MO_UB);
3421fcf5ef2aSThomas Huth tcg_gen_addi_tl(cpu_gpr_a[r2], cpu_gpr_a[r2], 1);
3422fcf5ef2aSThomas Huth break;
3423fcf5ef2aSThomas Huth case OPC1_16_SLR_LD_H:
3424fcf5ef2aSThomas Huth tcg_gen_qemu_ld_tl(cpu_gpr_d[r1], cpu_gpr_a[r2], ctx->mem_idx, MO_LESW);
3425fcf5ef2aSThomas Huth break;
3426fcf5ef2aSThomas Huth case OPC1_16_SLR_LD_H_POSTINC:
3427fcf5ef2aSThomas Huth tcg_gen_qemu_ld_tl(cpu_gpr_d[r1], cpu_gpr_a[r2], ctx->mem_idx, MO_LESW);
3428fcf5ef2aSThomas Huth tcg_gen_addi_tl(cpu_gpr_a[r2], cpu_gpr_a[r2], 2);
3429fcf5ef2aSThomas Huth break;
3430fcf5ef2aSThomas Huth case OPC1_16_SLR_LD_W:
3431fcf5ef2aSThomas Huth tcg_gen_qemu_ld_tl(cpu_gpr_d[r1], cpu_gpr_a[r2], ctx->mem_idx, MO_LESL);
3432fcf5ef2aSThomas Huth break;
3433fcf5ef2aSThomas Huth case OPC1_16_SLR_LD_W_POSTINC:
3434fcf5ef2aSThomas Huth tcg_gen_qemu_ld_tl(cpu_gpr_d[r1], cpu_gpr_a[r2], ctx->mem_idx, MO_LESL);
3435fcf5ef2aSThomas Huth tcg_gen_addi_tl(cpu_gpr_a[r2], cpu_gpr_a[r2], 4);
3436fcf5ef2aSThomas Huth break;
3437fcf5ef2aSThomas Huth default:
3438fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
3439fcf5ef2aSThomas Huth }
3440fcf5ef2aSThomas Huth }
3441fcf5ef2aSThomas Huth
decode_sro_opc(DisasContext * ctx,int op1)3442fcf5ef2aSThomas Huth static void decode_sro_opc(DisasContext *ctx, int op1)
3443fcf5ef2aSThomas Huth {
3444fcf5ef2aSThomas Huth int r2;
3445fcf5ef2aSThomas Huth int32_t address;
3446fcf5ef2aSThomas Huth
3447fcf5ef2aSThomas Huth r2 = MASK_OP_SRO_S2(ctx->opcode);
3448fcf5ef2aSThomas Huth address = MASK_OP_SRO_OFF4(ctx->opcode);
3449fcf5ef2aSThomas Huth
3450fcf5ef2aSThomas Huth /* SRO-format */
3451fcf5ef2aSThomas Huth switch (op1) {
3452fcf5ef2aSThomas Huth case OPC1_16_SRO_LD_A:
3453fcf5ef2aSThomas Huth gen_offset_ld(ctx, cpu_gpr_a[15], cpu_gpr_a[r2], address * 4, MO_LESL);
3454fcf5ef2aSThomas Huth break;
3455fcf5ef2aSThomas Huth case OPC1_16_SRO_LD_BU:
3456fcf5ef2aSThomas Huth gen_offset_ld(ctx, cpu_gpr_d[15], cpu_gpr_a[r2], address, MO_UB);
3457fcf5ef2aSThomas Huth break;
3458fcf5ef2aSThomas Huth case OPC1_16_SRO_LD_H:
345977eb0085SAnton Kochkov gen_offset_ld(ctx, cpu_gpr_d[15], cpu_gpr_a[r2], address * 2, MO_LESW);
3460fcf5ef2aSThomas Huth break;
3461fcf5ef2aSThomas Huth case OPC1_16_SRO_LD_W:
3462fcf5ef2aSThomas Huth gen_offset_ld(ctx, cpu_gpr_d[15], cpu_gpr_a[r2], address * 4, MO_LESL);
3463fcf5ef2aSThomas Huth break;
3464fcf5ef2aSThomas Huth case OPC1_16_SRO_ST_A:
3465fcf5ef2aSThomas Huth gen_offset_st(ctx, cpu_gpr_a[15], cpu_gpr_a[r2], address * 4, MO_LESL);
3466fcf5ef2aSThomas Huth break;
3467fcf5ef2aSThomas Huth case OPC1_16_SRO_ST_B:
3468fcf5ef2aSThomas Huth gen_offset_st(ctx, cpu_gpr_d[15], cpu_gpr_a[r2], address, MO_UB);
3469fcf5ef2aSThomas Huth break;
3470fcf5ef2aSThomas Huth case OPC1_16_SRO_ST_H:
3471fcf5ef2aSThomas Huth gen_offset_st(ctx, cpu_gpr_d[15], cpu_gpr_a[r2], address * 2, MO_LESW);
3472fcf5ef2aSThomas Huth break;
3473fcf5ef2aSThomas Huth case OPC1_16_SRO_ST_W:
3474fcf5ef2aSThomas Huth gen_offset_st(ctx, cpu_gpr_d[15], cpu_gpr_a[r2], address * 4, MO_LESL);
3475fcf5ef2aSThomas Huth break;
3476fcf5ef2aSThomas Huth default:
3477fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
3478fcf5ef2aSThomas Huth }
3479fcf5ef2aSThomas Huth }
3480fcf5ef2aSThomas Huth
decode_sr_system(DisasContext * ctx)34812db92a0cSBastian Koppelmann static void decode_sr_system(DisasContext *ctx)
3482fcf5ef2aSThomas Huth {
3483fcf5ef2aSThomas Huth uint32_t op2;
3484fcf5ef2aSThomas Huth op2 = MASK_OP_SR_OP2(ctx->opcode);
3485fcf5ef2aSThomas Huth
3486fcf5ef2aSThomas Huth switch (op2) {
3487fcf5ef2aSThomas Huth case OPC2_16_SR_NOP:
3488fcf5ef2aSThomas Huth break;
3489fcf5ef2aSThomas Huth case OPC2_16_SR_RET:
3490fcf5ef2aSThomas Huth gen_compute_branch(ctx, op2, 0, 0, 0, 0);
3491fcf5ef2aSThomas Huth break;
3492fcf5ef2aSThomas Huth case OPC2_16_SR_RFE:
3493ad75a51eSRichard Henderson gen_helper_rfe(tcg_env);
34941706e04fSBastian Koppelmann ctx->base.is_jmp = DISAS_EXIT;
3495fcf5ef2aSThomas Huth break;
3496fcf5ef2aSThomas Huth case OPC2_16_SR_DEBUG:
3497fcf5ef2aSThomas Huth /* raise EXCP_DEBUG */
3498fcf5ef2aSThomas Huth break;
3499fcf5ef2aSThomas Huth case OPC2_16_SR_FRET:
3500fcf5ef2aSThomas Huth gen_fret(ctx);
3501fcf5ef2aSThomas Huth break;
3502fcf5ef2aSThomas Huth default:
3503fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
3504fcf5ef2aSThomas Huth }
3505fcf5ef2aSThomas Huth }
3506fcf5ef2aSThomas Huth
decode_sr_accu(DisasContext * ctx)35072db92a0cSBastian Koppelmann static void decode_sr_accu(DisasContext *ctx)
3508fcf5ef2aSThomas Huth {
3509fcf5ef2aSThomas Huth uint32_t op2;
3510fcf5ef2aSThomas Huth uint32_t r1;
3511fcf5ef2aSThomas Huth
3512fcf5ef2aSThomas Huth r1 = MASK_OP_SR_S1D(ctx->opcode);
3513fcf5ef2aSThomas Huth op2 = MASK_OP_SR_OP2(ctx->opcode);
3514fcf5ef2aSThomas Huth
3515fcf5ef2aSThomas Huth switch (op2) {
3516fcf5ef2aSThomas Huth case OPC2_16_SR_RSUB:
35170a476786SRichard Henderson /* calc V bit -- overflow only if r1 = -0x80000000 */
35180a476786SRichard Henderson tcg_gen_setcondi_tl(TCG_COND_EQ, cpu_PSW_V, cpu_gpr_d[r1], -0x80000000);
3519fcf5ef2aSThomas Huth tcg_gen_shli_tl(cpu_PSW_V, cpu_PSW_V, 31);
3520fcf5ef2aSThomas Huth /* calc SV bit */
3521fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SV, cpu_PSW_SV, cpu_PSW_V);
3522fcf5ef2aSThomas Huth /* sub */
3523fcf5ef2aSThomas Huth tcg_gen_neg_tl(cpu_gpr_d[r1], cpu_gpr_d[r1]);
3524fcf5ef2aSThomas Huth /* calc av */
3525fcf5ef2aSThomas Huth tcg_gen_add_tl(cpu_PSW_AV, cpu_gpr_d[r1], cpu_gpr_d[r1]);
3526fcf5ef2aSThomas Huth tcg_gen_xor_tl(cpu_PSW_AV, cpu_gpr_d[r1], cpu_PSW_AV);
3527fcf5ef2aSThomas Huth /* calc sav */
3528fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SAV, cpu_PSW_SAV, cpu_PSW_AV);
3529fcf5ef2aSThomas Huth break;
3530fcf5ef2aSThomas Huth case OPC2_16_SR_SAT_B:
3531fcf5ef2aSThomas Huth gen_saturate(cpu_gpr_d[r1], cpu_gpr_d[r1], 0x7f, -0x80);
3532fcf5ef2aSThomas Huth break;
3533fcf5ef2aSThomas Huth case OPC2_16_SR_SAT_BU:
3534fcf5ef2aSThomas Huth gen_saturate_u(cpu_gpr_d[r1], cpu_gpr_d[r1], 0xff);
3535fcf5ef2aSThomas Huth break;
3536fcf5ef2aSThomas Huth case OPC2_16_SR_SAT_H:
3537fcf5ef2aSThomas Huth gen_saturate(cpu_gpr_d[r1], cpu_gpr_d[r1], 0x7fff, -0x8000);
3538fcf5ef2aSThomas Huth break;
3539fcf5ef2aSThomas Huth case OPC2_16_SR_SAT_HU:
3540fcf5ef2aSThomas Huth gen_saturate_u(cpu_gpr_d[r1], cpu_gpr_d[r1], 0xffff);
3541fcf5ef2aSThomas Huth break;
3542fcf5ef2aSThomas Huth default:
3543fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
3544fcf5ef2aSThomas Huth }
3545fcf5ef2aSThomas Huth }
3546fcf5ef2aSThomas Huth
decode_16Bit_opc(DisasContext * ctx)35472db92a0cSBastian Koppelmann static void decode_16Bit_opc(DisasContext *ctx)
3548fcf5ef2aSThomas Huth {
3549fcf5ef2aSThomas Huth int op1;
3550fcf5ef2aSThomas Huth int r1, r2;
3551fcf5ef2aSThomas Huth int32_t const16;
3552fcf5ef2aSThomas Huth int32_t address;
3553fcf5ef2aSThomas Huth TCGv temp;
3554fcf5ef2aSThomas Huth
3555fcf5ef2aSThomas Huth op1 = MASK_OP_MAJOR(ctx->opcode);
3556fcf5ef2aSThomas Huth
3557fcf5ef2aSThomas Huth /* handle ADDSC.A opcode only being 6 bit long */
3558fcf5ef2aSThomas Huth if (unlikely((op1 & 0x3f) == OPC1_16_SRRS_ADDSC_A)) {
3559fcf5ef2aSThomas Huth op1 = OPC1_16_SRRS_ADDSC_A;
3560fcf5ef2aSThomas Huth }
3561fcf5ef2aSThomas Huth
3562fcf5ef2aSThomas Huth switch (op1) {
3563fcf5ef2aSThomas Huth case OPC1_16_SRC_ADD:
3564fcf5ef2aSThomas Huth case OPC1_16_SRC_ADD_A15:
3565fcf5ef2aSThomas Huth case OPC1_16_SRC_ADD_15A:
3566fcf5ef2aSThomas Huth case OPC1_16_SRC_ADD_A:
3567fcf5ef2aSThomas Huth case OPC1_16_SRC_CADD:
3568fcf5ef2aSThomas Huth case OPC1_16_SRC_CADDN:
3569fcf5ef2aSThomas Huth case OPC1_16_SRC_CMOV:
3570fcf5ef2aSThomas Huth case OPC1_16_SRC_CMOVN:
3571fcf5ef2aSThomas Huth case OPC1_16_SRC_EQ:
3572fcf5ef2aSThomas Huth case OPC1_16_SRC_LT:
3573fcf5ef2aSThomas Huth case OPC1_16_SRC_MOV:
3574fcf5ef2aSThomas Huth case OPC1_16_SRC_MOV_A:
3575fcf5ef2aSThomas Huth case OPC1_16_SRC_MOV_E:
3576fcf5ef2aSThomas Huth case OPC1_16_SRC_SH:
3577fcf5ef2aSThomas Huth case OPC1_16_SRC_SHA:
35782db92a0cSBastian Koppelmann decode_src_opc(ctx, op1);
3579fcf5ef2aSThomas Huth break;
3580fcf5ef2aSThomas Huth /* SRR-format */
3581fcf5ef2aSThomas Huth case OPC1_16_SRR_ADD:
3582fcf5ef2aSThomas Huth case OPC1_16_SRR_ADD_A15:
3583fcf5ef2aSThomas Huth case OPC1_16_SRR_ADD_15A:
3584fcf5ef2aSThomas Huth case OPC1_16_SRR_ADD_A:
3585fcf5ef2aSThomas Huth case OPC1_16_SRR_ADDS:
3586fcf5ef2aSThomas Huth case OPC1_16_SRR_AND:
3587fcf5ef2aSThomas Huth case OPC1_16_SRR_CMOV:
3588fcf5ef2aSThomas Huth case OPC1_16_SRR_CMOVN:
3589fcf5ef2aSThomas Huth case OPC1_16_SRR_EQ:
3590fcf5ef2aSThomas Huth case OPC1_16_SRR_LT:
3591fcf5ef2aSThomas Huth case OPC1_16_SRR_MOV:
3592fcf5ef2aSThomas Huth case OPC1_16_SRR_MOV_A:
3593fcf5ef2aSThomas Huth case OPC1_16_SRR_MOV_AA:
3594fcf5ef2aSThomas Huth case OPC1_16_SRR_MOV_D:
3595fcf5ef2aSThomas Huth case OPC1_16_SRR_MUL:
3596fcf5ef2aSThomas Huth case OPC1_16_SRR_OR:
3597fcf5ef2aSThomas Huth case OPC1_16_SRR_SUB:
3598fcf5ef2aSThomas Huth case OPC1_16_SRR_SUB_A15B:
3599fcf5ef2aSThomas Huth case OPC1_16_SRR_SUB_15AB:
3600fcf5ef2aSThomas Huth case OPC1_16_SRR_SUBS:
3601fcf5ef2aSThomas Huth case OPC1_16_SRR_XOR:
3602fcf5ef2aSThomas Huth decode_srr_opc(ctx, op1);
3603fcf5ef2aSThomas Huth break;
3604fcf5ef2aSThomas Huth /* SSR-format */
3605fcf5ef2aSThomas Huth case OPC1_16_SSR_ST_A:
3606fcf5ef2aSThomas Huth case OPC1_16_SSR_ST_A_POSTINC:
3607fcf5ef2aSThomas Huth case OPC1_16_SSR_ST_B:
3608fcf5ef2aSThomas Huth case OPC1_16_SSR_ST_B_POSTINC:
3609fcf5ef2aSThomas Huth case OPC1_16_SSR_ST_H:
3610fcf5ef2aSThomas Huth case OPC1_16_SSR_ST_H_POSTINC:
3611fcf5ef2aSThomas Huth case OPC1_16_SSR_ST_W:
3612fcf5ef2aSThomas Huth case OPC1_16_SSR_ST_W_POSTINC:
3613fcf5ef2aSThomas Huth decode_ssr_opc(ctx, op1);
3614fcf5ef2aSThomas Huth break;
3615fcf5ef2aSThomas Huth /* SRRS-format */
3616fcf5ef2aSThomas Huth case OPC1_16_SRRS_ADDSC_A:
3617fcf5ef2aSThomas Huth r2 = MASK_OP_SRRS_S2(ctx->opcode);
3618fcf5ef2aSThomas Huth r1 = MASK_OP_SRRS_S1D(ctx->opcode);
3619fcf5ef2aSThomas Huth const16 = MASK_OP_SRRS_N(ctx->opcode);
3620fcf5ef2aSThomas Huth temp = tcg_temp_new();
3621fcf5ef2aSThomas Huth tcg_gen_shli_tl(temp, cpu_gpr_d[15], const16);
3622fcf5ef2aSThomas Huth tcg_gen_add_tl(cpu_gpr_a[r1], cpu_gpr_a[r2], temp);
3623fcf5ef2aSThomas Huth break;
3624fcf5ef2aSThomas Huth /* SLRO-format */
3625fcf5ef2aSThomas Huth case OPC1_16_SLRO_LD_A:
3626fcf5ef2aSThomas Huth r1 = MASK_OP_SLRO_D(ctx->opcode);
3627fcf5ef2aSThomas Huth const16 = MASK_OP_SLRO_OFF4(ctx->opcode);
3628fcf5ef2aSThomas Huth gen_offset_ld(ctx, cpu_gpr_a[r1], cpu_gpr_a[15], const16 * 4, MO_LESL);
3629fcf5ef2aSThomas Huth break;
3630fcf5ef2aSThomas Huth case OPC1_16_SLRO_LD_BU:
3631fcf5ef2aSThomas Huth r1 = MASK_OP_SLRO_D(ctx->opcode);
3632fcf5ef2aSThomas Huth const16 = MASK_OP_SLRO_OFF4(ctx->opcode);
3633fcf5ef2aSThomas Huth gen_offset_ld(ctx, cpu_gpr_d[r1], cpu_gpr_a[15], const16, MO_UB);
3634fcf5ef2aSThomas Huth break;
3635fcf5ef2aSThomas Huth case OPC1_16_SLRO_LD_H:
3636fcf5ef2aSThomas Huth r1 = MASK_OP_SLRO_D(ctx->opcode);
3637fcf5ef2aSThomas Huth const16 = MASK_OP_SLRO_OFF4(ctx->opcode);
3638fcf5ef2aSThomas Huth gen_offset_ld(ctx, cpu_gpr_d[r1], cpu_gpr_a[15], const16 * 2, MO_LESW);
3639fcf5ef2aSThomas Huth break;
3640fcf5ef2aSThomas Huth case OPC1_16_SLRO_LD_W:
3641fcf5ef2aSThomas Huth r1 = MASK_OP_SLRO_D(ctx->opcode);
3642fcf5ef2aSThomas Huth const16 = MASK_OP_SLRO_OFF4(ctx->opcode);
3643fcf5ef2aSThomas Huth gen_offset_ld(ctx, cpu_gpr_d[r1], cpu_gpr_a[15], const16 * 4, MO_LESL);
3644fcf5ef2aSThomas Huth break;
3645fcf5ef2aSThomas Huth /* SB-format */
3646fcf5ef2aSThomas Huth case OPC1_16_SB_CALL:
3647fcf5ef2aSThomas Huth case OPC1_16_SB_J:
3648fcf5ef2aSThomas Huth case OPC1_16_SB_JNZ:
3649fcf5ef2aSThomas Huth case OPC1_16_SB_JZ:
3650fcf5ef2aSThomas Huth address = MASK_OP_SB_DISP8_SEXT(ctx->opcode);
3651fcf5ef2aSThomas Huth gen_compute_branch(ctx, op1, 0, 0, 0, address);
3652fcf5ef2aSThomas Huth break;
3653fcf5ef2aSThomas Huth /* SBC-format */
3654fcf5ef2aSThomas Huth case OPC1_16_SBC_JEQ:
3655fcf5ef2aSThomas Huth case OPC1_16_SBC_JNE:
3656fcf5ef2aSThomas Huth address = MASK_OP_SBC_DISP4(ctx->opcode);
3657fcf5ef2aSThomas Huth const16 = MASK_OP_SBC_CONST4_SEXT(ctx->opcode);
3658fcf5ef2aSThomas Huth gen_compute_branch(ctx, op1, 0, 0, const16, address);
3659fcf5ef2aSThomas Huth break;
3660dedd8c9cSPeer Adelt case OPC1_16_SBC_JEQ2:
3661dedd8c9cSPeer Adelt case OPC1_16_SBC_JNE2:
366244ee3bafSBastian Koppelmann if (has_feature(ctx, TRICORE_FEATURE_16)) {
3663dedd8c9cSPeer Adelt address = MASK_OP_SBC_DISP4(ctx->opcode);
3664dedd8c9cSPeer Adelt const16 = MASK_OP_SBC_CONST4_SEXT(ctx->opcode);
3665dedd8c9cSPeer Adelt gen_compute_branch(ctx, op1, 0, 0, const16, address);
3666dedd8c9cSPeer Adelt } else {
3667dedd8c9cSPeer Adelt generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
3668dedd8c9cSPeer Adelt }
3669dedd8c9cSPeer Adelt break;
3670fcf5ef2aSThomas Huth /* SBRN-format */
3671fcf5ef2aSThomas Huth case OPC1_16_SBRN_JNZ_T:
3672fcf5ef2aSThomas Huth case OPC1_16_SBRN_JZ_T:
3673fcf5ef2aSThomas Huth address = MASK_OP_SBRN_DISP4(ctx->opcode);
3674fcf5ef2aSThomas Huth const16 = MASK_OP_SBRN_N(ctx->opcode);
3675fcf5ef2aSThomas Huth gen_compute_branch(ctx, op1, 0, 0, const16, address);
3676fcf5ef2aSThomas Huth break;
3677fcf5ef2aSThomas Huth /* SBR-format */
3678defda2d4SDavid Brenken case OPC1_16_SBR_JEQ2:
3679defda2d4SDavid Brenken case OPC1_16_SBR_JNE2:
368044ee3bafSBastian Koppelmann if (has_feature(ctx, TRICORE_FEATURE_16)) {
3681defda2d4SDavid Brenken r1 = MASK_OP_SBR_S2(ctx->opcode);
3682defda2d4SDavid Brenken address = MASK_OP_SBR_DISP4(ctx->opcode);
3683defda2d4SDavid Brenken gen_compute_branch(ctx, op1, r1, 0, 0, address);
3684defda2d4SDavid Brenken } else {
3685defda2d4SDavid Brenken generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
3686defda2d4SDavid Brenken }
3687defda2d4SDavid Brenken break;
3688fcf5ef2aSThomas Huth case OPC1_16_SBR_JEQ:
3689fcf5ef2aSThomas Huth case OPC1_16_SBR_JGEZ:
3690fcf5ef2aSThomas Huth case OPC1_16_SBR_JGTZ:
3691fcf5ef2aSThomas Huth case OPC1_16_SBR_JLEZ:
3692fcf5ef2aSThomas Huth case OPC1_16_SBR_JLTZ:
3693fcf5ef2aSThomas Huth case OPC1_16_SBR_JNE:
3694fcf5ef2aSThomas Huth case OPC1_16_SBR_JNZ:
3695fcf5ef2aSThomas Huth case OPC1_16_SBR_JNZ_A:
3696fcf5ef2aSThomas Huth case OPC1_16_SBR_JZ:
3697fcf5ef2aSThomas Huth case OPC1_16_SBR_JZ_A:
3698fcf5ef2aSThomas Huth case OPC1_16_SBR_LOOP:
3699fcf5ef2aSThomas Huth r1 = MASK_OP_SBR_S2(ctx->opcode);
3700fcf5ef2aSThomas Huth address = MASK_OP_SBR_DISP4(ctx->opcode);
3701fcf5ef2aSThomas Huth gen_compute_branch(ctx, op1, r1, 0, 0, address);
3702fcf5ef2aSThomas Huth break;
3703fcf5ef2aSThomas Huth /* SC-format */
3704fcf5ef2aSThomas Huth case OPC1_16_SC_AND:
3705fcf5ef2aSThomas Huth case OPC1_16_SC_BISR:
3706fcf5ef2aSThomas Huth case OPC1_16_SC_LD_A:
3707fcf5ef2aSThomas Huth case OPC1_16_SC_LD_W:
3708fcf5ef2aSThomas Huth case OPC1_16_SC_MOV:
3709fcf5ef2aSThomas Huth case OPC1_16_SC_OR:
3710fcf5ef2aSThomas Huth case OPC1_16_SC_ST_A:
3711fcf5ef2aSThomas Huth case OPC1_16_SC_ST_W:
3712fcf5ef2aSThomas Huth case OPC1_16_SC_SUB_A:
3713fcf5ef2aSThomas Huth decode_sc_opc(ctx, op1);
3714fcf5ef2aSThomas Huth break;
3715fcf5ef2aSThomas Huth /* SLR-format */
3716fcf5ef2aSThomas Huth case OPC1_16_SLR_LD_A:
3717fcf5ef2aSThomas Huth case OPC1_16_SLR_LD_A_POSTINC:
3718fcf5ef2aSThomas Huth case OPC1_16_SLR_LD_BU:
3719fcf5ef2aSThomas Huth case OPC1_16_SLR_LD_BU_POSTINC:
3720fcf5ef2aSThomas Huth case OPC1_16_SLR_LD_H:
3721fcf5ef2aSThomas Huth case OPC1_16_SLR_LD_H_POSTINC:
3722fcf5ef2aSThomas Huth case OPC1_16_SLR_LD_W:
3723fcf5ef2aSThomas Huth case OPC1_16_SLR_LD_W_POSTINC:
3724fcf5ef2aSThomas Huth decode_slr_opc(ctx, op1);
3725fcf5ef2aSThomas Huth break;
3726fcf5ef2aSThomas Huth /* SRO-format */
3727fcf5ef2aSThomas Huth case OPC1_16_SRO_LD_A:
3728fcf5ef2aSThomas Huth case OPC1_16_SRO_LD_BU:
3729fcf5ef2aSThomas Huth case OPC1_16_SRO_LD_H:
3730fcf5ef2aSThomas Huth case OPC1_16_SRO_LD_W:
3731fcf5ef2aSThomas Huth case OPC1_16_SRO_ST_A:
3732fcf5ef2aSThomas Huth case OPC1_16_SRO_ST_B:
3733fcf5ef2aSThomas Huth case OPC1_16_SRO_ST_H:
3734fcf5ef2aSThomas Huth case OPC1_16_SRO_ST_W:
3735fcf5ef2aSThomas Huth decode_sro_opc(ctx, op1);
3736fcf5ef2aSThomas Huth break;
3737fcf5ef2aSThomas Huth /* SSRO-format */
3738fcf5ef2aSThomas Huth case OPC1_16_SSRO_ST_A:
3739fcf5ef2aSThomas Huth r1 = MASK_OP_SSRO_S1(ctx->opcode);
3740fcf5ef2aSThomas Huth const16 = MASK_OP_SSRO_OFF4(ctx->opcode);
3741fcf5ef2aSThomas Huth gen_offset_st(ctx, cpu_gpr_a[r1], cpu_gpr_a[15], const16 * 4, MO_LESL);
3742fcf5ef2aSThomas Huth break;
3743fcf5ef2aSThomas Huth case OPC1_16_SSRO_ST_B:
3744fcf5ef2aSThomas Huth r1 = MASK_OP_SSRO_S1(ctx->opcode);
3745fcf5ef2aSThomas Huth const16 = MASK_OP_SSRO_OFF4(ctx->opcode);
3746fcf5ef2aSThomas Huth gen_offset_st(ctx, cpu_gpr_d[r1], cpu_gpr_a[15], const16, MO_UB);
3747fcf5ef2aSThomas Huth break;
3748fcf5ef2aSThomas Huth case OPC1_16_SSRO_ST_H:
3749fcf5ef2aSThomas Huth r1 = MASK_OP_SSRO_S1(ctx->opcode);
3750fcf5ef2aSThomas Huth const16 = MASK_OP_SSRO_OFF4(ctx->opcode);
3751fcf5ef2aSThomas Huth gen_offset_st(ctx, cpu_gpr_d[r1], cpu_gpr_a[15], const16 * 2, MO_LESW);
3752fcf5ef2aSThomas Huth break;
3753fcf5ef2aSThomas Huth case OPC1_16_SSRO_ST_W:
3754fcf5ef2aSThomas Huth r1 = MASK_OP_SSRO_S1(ctx->opcode);
3755fcf5ef2aSThomas Huth const16 = MASK_OP_SSRO_OFF4(ctx->opcode);
3756fcf5ef2aSThomas Huth gen_offset_st(ctx, cpu_gpr_d[r1], cpu_gpr_a[15], const16 * 4, MO_LESL);
3757fcf5ef2aSThomas Huth break;
3758fcf5ef2aSThomas Huth /* SR-format */
3759fcf5ef2aSThomas Huth case OPCM_16_SR_SYSTEM:
37602db92a0cSBastian Koppelmann decode_sr_system(ctx);
3761fcf5ef2aSThomas Huth break;
3762fcf5ef2aSThomas Huth case OPCM_16_SR_ACCU:
37632db92a0cSBastian Koppelmann decode_sr_accu(ctx);
3764fcf5ef2aSThomas Huth break;
3765fcf5ef2aSThomas Huth case OPC1_16_SR_JI:
3766fcf5ef2aSThomas Huth r1 = MASK_OP_SR_S1D(ctx->opcode);
3767fcf5ef2aSThomas Huth gen_compute_branch(ctx, op1, r1, 0, 0, 0);
3768fcf5ef2aSThomas Huth break;
3769fcf5ef2aSThomas Huth case OPC1_16_SR_NOT:
3770fcf5ef2aSThomas Huth r1 = MASK_OP_SR_S1D(ctx->opcode);
3771fcf5ef2aSThomas Huth tcg_gen_not_tl(cpu_gpr_d[r1], cpu_gpr_d[r1]);
3772fcf5ef2aSThomas Huth break;
3773fcf5ef2aSThomas Huth default:
3774fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
3775fcf5ef2aSThomas Huth }
3776fcf5ef2aSThomas Huth }
3777fcf5ef2aSThomas Huth
3778fcf5ef2aSThomas Huth /*
3779fcf5ef2aSThomas Huth * 32 bit instructions
3780fcf5ef2aSThomas Huth */
3781fcf5ef2aSThomas Huth
3782fcf5ef2aSThomas Huth /* ABS-format */
decode_abs_ldw(DisasContext * ctx)37832db92a0cSBastian Koppelmann static void decode_abs_ldw(DisasContext *ctx)
3784fcf5ef2aSThomas Huth {
3785fcf5ef2aSThomas Huth int32_t op2;
3786fcf5ef2aSThomas Huth int32_t r1;
3787fcf5ef2aSThomas Huth uint32_t address;
3788fcf5ef2aSThomas Huth TCGv temp;
3789fcf5ef2aSThomas Huth
3790fcf5ef2aSThomas Huth r1 = MASK_OP_ABS_S1D(ctx->opcode);
3791fcf5ef2aSThomas Huth address = MASK_OP_ABS_OFF18(ctx->opcode);
3792fcf5ef2aSThomas Huth op2 = MASK_OP_ABS_OP2(ctx->opcode);
3793fcf5ef2aSThomas Huth
3794151293c2SRichard Henderson temp = tcg_constant_i32(EA_ABS_FORMAT(address));
3795fcf5ef2aSThomas Huth
3796fcf5ef2aSThomas Huth switch (op2) {
3797fcf5ef2aSThomas Huth case OPC2_32_ABS_LD_A:
3798fcf5ef2aSThomas Huth tcg_gen_qemu_ld_tl(cpu_gpr_a[r1], temp, ctx->mem_idx, MO_LESL);
3799fcf5ef2aSThomas Huth break;
3800fcf5ef2aSThomas Huth case OPC2_32_ABS_LD_D:
3801fcf5ef2aSThomas Huth CHECK_REG_PAIR(r1);
3802fcf5ef2aSThomas Huth gen_ld_2regs_64(cpu_gpr_d[r1+1], cpu_gpr_d[r1], temp, ctx);
3803fcf5ef2aSThomas Huth break;
3804fcf5ef2aSThomas Huth case OPC2_32_ABS_LD_DA:
3805fcf5ef2aSThomas Huth CHECK_REG_PAIR(r1);
3806fcf5ef2aSThomas Huth gen_ld_2regs_64(cpu_gpr_a[r1+1], cpu_gpr_a[r1], temp, ctx);
3807fcf5ef2aSThomas Huth break;
3808fcf5ef2aSThomas Huth case OPC2_32_ABS_LD_W:
3809fcf5ef2aSThomas Huth tcg_gen_qemu_ld_tl(cpu_gpr_d[r1], temp, ctx->mem_idx, MO_LESL);
3810fcf5ef2aSThomas Huth break;
3811fcf5ef2aSThomas Huth default:
3812fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
3813fcf5ef2aSThomas Huth }
3814fcf5ef2aSThomas Huth }
3815fcf5ef2aSThomas Huth
decode_abs_ldb(DisasContext * ctx)38162db92a0cSBastian Koppelmann static void decode_abs_ldb(DisasContext *ctx)
3817fcf5ef2aSThomas Huth {
3818fcf5ef2aSThomas Huth int32_t op2;
3819fcf5ef2aSThomas Huth int32_t r1;
3820fcf5ef2aSThomas Huth uint32_t address;
3821fcf5ef2aSThomas Huth TCGv temp;
3822fcf5ef2aSThomas Huth
3823fcf5ef2aSThomas Huth r1 = MASK_OP_ABS_S1D(ctx->opcode);
3824fcf5ef2aSThomas Huth address = MASK_OP_ABS_OFF18(ctx->opcode);
3825fcf5ef2aSThomas Huth op2 = MASK_OP_ABS_OP2(ctx->opcode);
3826fcf5ef2aSThomas Huth
3827151293c2SRichard Henderson temp = tcg_constant_i32(EA_ABS_FORMAT(address));
3828fcf5ef2aSThomas Huth
3829fcf5ef2aSThomas Huth switch (op2) {
3830fcf5ef2aSThomas Huth case OPC2_32_ABS_LD_B:
3831fcf5ef2aSThomas Huth tcg_gen_qemu_ld_tl(cpu_gpr_d[r1], temp, ctx->mem_idx, MO_SB);
3832fcf5ef2aSThomas Huth break;
3833fcf5ef2aSThomas Huth case OPC2_32_ABS_LD_BU:
3834fcf5ef2aSThomas Huth tcg_gen_qemu_ld_tl(cpu_gpr_d[r1], temp, ctx->mem_idx, MO_UB);
3835fcf5ef2aSThomas Huth break;
3836fcf5ef2aSThomas Huth case OPC2_32_ABS_LD_H:
3837fcf5ef2aSThomas Huth tcg_gen_qemu_ld_tl(cpu_gpr_d[r1], temp, ctx->mem_idx, MO_LESW);
3838fcf5ef2aSThomas Huth break;
3839fcf5ef2aSThomas Huth case OPC2_32_ABS_LD_HU:
3840fcf5ef2aSThomas Huth tcg_gen_qemu_ld_tl(cpu_gpr_d[r1], temp, ctx->mem_idx, MO_LEUW);
3841fcf5ef2aSThomas Huth break;
3842fcf5ef2aSThomas Huth default:
3843fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
3844fcf5ef2aSThomas Huth }
3845fcf5ef2aSThomas Huth }
3846fcf5ef2aSThomas Huth
decode_abs_ldst_swap(DisasContext * ctx)38472db92a0cSBastian Koppelmann static void decode_abs_ldst_swap(DisasContext *ctx)
3848fcf5ef2aSThomas Huth {
3849fcf5ef2aSThomas Huth int32_t op2;
3850fcf5ef2aSThomas Huth int32_t r1;
3851fcf5ef2aSThomas Huth uint32_t address;
3852fcf5ef2aSThomas Huth TCGv temp;
3853fcf5ef2aSThomas Huth
3854fcf5ef2aSThomas Huth r1 = MASK_OP_ABS_S1D(ctx->opcode);
3855fcf5ef2aSThomas Huth address = MASK_OP_ABS_OFF18(ctx->opcode);
3856fcf5ef2aSThomas Huth op2 = MASK_OP_ABS_OP2(ctx->opcode);
3857fcf5ef2aSThomas Huth
3858151293c2SRichard Henderson temp = tcg_constant_i32(EA_ABS_FORMAT(address));
3859fcf5ef2aSThomas Huth
3860fcf5ef2aSThomas Huth switch (op2) {
3861fcf5ef2aSThomas Huth case OPC2_32_ABS_LDMST:
3862fcf5ef2aSThomas Huth gen_ldmst(ctx, r1, temp);
3863fcf5ef2aSThomas Huth break;
3864fcf5ef2aSThomas Huth case OPC2_32_ABS_SWAP_W:
3865fcf5ef2aSThomas Huth gen_swap(ctx, r1, temp);
3866fcf5ef2aSThomas Huth break;
3867fcf5ef2aSThomas Huth default:
3868fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
3869fcf5ef2aSThomas Huth }
3870fcf5ef2aSThomas Huth }
3871fcf5ef2aSThomas Huth
decode_abs_ldst_context(DisasContext * ctx)38722db92a0cSBastian Koppelmann static void decode_abs_ldst_context(DisasContext *ctx)
3873fcf5ef2aSThomas Huth {
3874fcf5ef2aSThomas Huth uint32_t op2;
3875fcf5ef2aSThomas Huth int32_t off18;
3876fcf5ef2aSThomas Huth
3877fcf5ef2aSThomas Huth off18 = MASK_OP_ABS_OFF18(ctx->opcode);
3878fcf5ef2aSThomas Huth op2 = MASK_OP_ABS_OP2(ctx->opcode);
3879fcf5ef2aSThomas Huth
3880fcf5ef2aSThomas Huth switch (op2) {
3881fcf5ef2aSThomas Huth case OPC2_32_ABS_LDLCX:
3882fcf5ef2aSThomas Huth gen_helper_1arg(ldlcx, EA_ABS_FORMAT(off18));
3883fcf5ef2aSThomas Huth break;
3884fcf5ef2aSThomas Huth case OPC2_32_ABS_LDUCX:
3885fcf5ef2aSThomas Huth gen_helper_1arg(lducx, EA_ABS_FORMAT(off18));
3886fcf5ef2aSThomas Huth break;
3887fcf5ef2aSThomas Huth case OPC2_32_ABS_STLCX:
3888fcf5ef2aSThomas Huth gen_helper_1arg(stlcx, EA_ABS_FORMAT(off18));
3889fcf5ef2aSThomas Huth break;
3890fcf5ef2aSThomas Huth case OPC2_32_ABS_STUCX:
3891fcf5ef2aSThomas Huth gen_helper_1arg(stucx, EA_ABS_FORMAT(off18));
3892fcf5ef2aSThomas Huth break;
3893fcf5ef2aSThomas Huth default:
3894fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
3895fcf5ef2aSThomas Huth }
3896fcf5ef2aSThomas Huth }
3897fcf5ef2aSThomas Huth
decode_abs_store(DisasContext * ctx)38982db92a0cSBastian Koppelmann static void decode_abs_store(DisasContext *ctx)
3899fcf5ef2aSThomas Huth {
3900fcf5ef2aSThomas Huth int32_t op2;
3901fcf5ef2aSThomas Huth int32_t r1;
3902fcf5ef2aSThomas Huth uint32_t address;
3903fcf5ef2aSThomas Huth TCGv temp;
3904fcf5ef2aSThomas Huth
3905fcf5ef2aSThomas Huth r1 = MASK_OP_ABS_S1D(ctx->opcode);
3906fcf5ef2aSThomas Huth address = MASK_OP_ABS_OFF18(ctx->opcode);
3907fcf5ef2aSThomas Huth op2 = MASK_OP_ABS_OP2(ctx->opcode);
3908fcf5ef2aSThomas Huth
3909151293c2SRichard Henderson temp = tcg_constant_i32(EA_ABS_FORMAT(address));
3910fcf5ef2aSThomas Huth
3911fcf5ef2aSThomas Huth switch (op2) {
3912fcf5ef2aSThomas Huth case OPC2_32_ABS_ST_A:
3913fcf5ef2aSThomas Huth tcg_gen_qemu_st_tl(cpu_gpr_a[r1], temp, ctx->mem_idx, MO_LESL);
3914fcf5ef2aSThomas Huth break;
3915fcf5ef2aSThomas Huth case OPC2_32_ABS_ST_D:
3916fcf5ef2aSThomas Huth CHECK_REG_PAIR(r1);
3917fcf5ef2aSThomas Huth gen_st_2regs_64(cpu_gpr_d[r1+1], cpu_gpr_d[r1], temp, ctx);
3918fcf5ef2aSThomas Huth break;
3919fcf5ef2aSThomas Huth case OPC2_32_ABS_ST_DA:
3920fcf5ef2aSThomas Huth CHECK_REG_PAIR(r1);
3921fcf5ef2aSThomas Huth gen_st_2regs_64(cpu_gpr_a[r1+1], cpu_gpr_a[r1], temp, ctx);
3922fcf5ef2aSThomas Huth break;
3923fcf5ef2aSThomas Huth case OPC2_32_ABS_ST_W:
3924fcf5ef2aSThomas Huth tcg_gen_qemu_st_tl(cpu_gpr_d[r1], temp, ctx->mem_idx, MO_LESL);
3925fcf5ef2aSThomas Huth break;
3926fcf5ef2aSThomas Huth default:
3927fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
3928fcf5ef2aSThomas Huth }
3929fcf5ef2aSThomas Huth }
3930fcf5ef2aSThomas Huth
decode_abs_storeb_h(DisasContext * ctx)39312db92a0cSBastian Koppelmann static void decode_abs_storeb_h(DisasContext *ctx)
3932fcf5ef2aSThomas Huth {
3933fcf5ef2aSThomas Huth int32_t op2;
3934fcf5ef2aSThomas Huth int32_t r1;
3935fcf5ef2aSThomas Huth uint32_t address;
3936fcf5ef2aSThomas Huth TCGv temp;
3937fcf5ef2aSThomas Huth
3938fcf5ef2aSThomas Huth r1 = MASK_OP_ABS_S1D(ctx->opcode);
3939fcf5ef2aSThomas Huth address = MASK_OP_ABS_OFF18(ctx->opcode);
3940fcf5ef2aSThomas Huth op2 = MASK_OP_ABS_OP2(ctx->opcode);
3941fcf5ef2aSThomas Huth
3942151293c2SRichard Henderson temp = tcg_constant_i32(EA_ABS_FORMAT(address));
3943fcf5ef2aSThomas Huth
3944fcf5ef2aSThomas Huth switch (op2) {
3945fcf5ef2aSThomas Huth case OPC2_32_ABS_ST_B:
3946fcf5ef2aSThomas Huth tcg_gen_qemu_st_tl(cpu_gpr_d[r1], temp, ctx->mem_idx, MO_UB);
3947fcf5ef2aSThomas Huth break;
3948fcf5ef2aSThomas Huth case OPC2_32_ABS_ST_H:
3949fcf5ef2aSThomas Huth tcg_gen_qemu_st_tl(cpu_gpr_d[r1], temp, ctx->mem_idx, MO_LEUW);
3950fcf5ef2aSThomas Huth break;
3951fcf5ef2aSThomas Huth default:
3952fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
3953fcf5ef2aSThomas Huth }
3954fcf5ef2aSThomas Huth }
3955fcf5ef2aSThomas Huth
3956fcf5ef2aSThomas Huth /* Bit-format */
3957fcf5ef2aSThomas Huth
decode_bit_andacc(DisasContext * ctx)39582db92a0cSBastian Koppelmann static void decode_bit_andacc(DisasContext *ctx)
3959fcf5ef2aSThomas Huth {
3960fcf5ef2aSThomas Huth uint32_t op2;
3961fcf5ef2aSThomas Huth int r1, r2, r3;
3962fcf5ef2aSThomas Huth int pos1, pos2;
3963fcf5ef2aSThomas Huth
3964fcf5ef2aSThomas Huth r1 = MASK_OP_BIT_S1(ctx->opcode);
3965fcf5ef2aSThomas Huth r2 = MASK_OP_BIT_S2(ctx->opcode);
3966fcf5ef2aSThomas Huth r3 = MASK_OP_BIT_D(ctx->opcode);
3967fcf5ef2aSThomas Huth pos1 = MASK_OP_BIT_POS1(ctx->opcode);
3968fcf5ef2aSThomas Huth pos2 = MASK_OP_BIT_POS2(ctx->opcode);
3969fcf5ef2aSThomas Huth op2 = MASK_OP_BIT_OP2(ctx->opcode);
3970fcf5ef2aSThomas Huth
3971fcf5ef2aSThomas Huth
3972fcf5ef2aSThomas Huth switch (op2) {
3973fcf5ef2aSThomas Huth case OPC2_32_BIT_AND_AND_T:
3974fcf5ef2aSThomas Huth gen_bit_2op(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2],
3975fcf5ef2aSThomas Huth pos1, pos2, &tcg_gen_and_tl, &tcg_gen_and_tl);
3976fcf5ef2aSThomas Huth break;
3977fcf5ef2aSThomas Huth case OPC2_32_BIT_AND_ANDN_T:
3978fcf5ef2aSThomas Huth gen_bit_2op(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2],
3979fcf5ef2aSThomas Huth pos1, pos2, &tcg_gen_andc_tl, &tcg_gen_and_tl);
3980fcf5ef2aSThomas Huth break;
3981fcf5ef2aSThomas Huth case OPC2_32_BIT_AND_NOR_T:
3982fcf5ef2aSThomas Huth if (TCG_TARGET_HAS_andc_i32) {
3983fcf5ef2aSThomas Huth gen_bit_2op(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2],
3984fcf5ef2aSThomas Huth pos1, pos2, &tcg_gen_or_tl, &tcg_gen_andc_tl);
3985fcf5ef2aSThomas Huth } else {
3986fcf5ef2aSThomas Huth gen_bit_2op(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2],
3987fcf5ef2aSThomas Huth pos1, pos2, &tcg_gen_nor_tl, &tcg_gen_and_tl);
3988fcf5ef2aSThomas Huth }
3989fcf5ef2aSThomas Huth break;
3990fcf5ef2aSThomas Huth case OPC2_32_BIT_AND_OR_T:
3991fcf5ef2aSThomas Huth gen_bit_2op(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2],
3992fcf5ef2aSThomas Huth pos1, pos2, &tcg_gen_or_tl, &tcg_gen_and_tl);
3993fcf5ef2aSThomas Huth break;
3994fcf5ef2aSThomas Huth default:
3995fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
3996fcf5ef2aSThomas Huth }
3997fcf5ef2aSThomas Huth }
3998fcf5ef2aSThomas Huth
decode_bit_logical_t(DisasContext * ctx)39992db92a0cSBastian Koppelmann static void decode_bit_logical_t(DisasContext *ctx)
4000fcf5ef2aSThomas Huth {
4001fcf5ef2aSThomas Huth uint32_t op2;
4002fcf5ef2aSThomas Huth int r1, r2, r3;
4003fcf5ef2aSThomas Huth int pos1, pos2;
4004fcf5ef2aSThomas Huth r1 = MASK_OP_BIT_S1(ctx->opcode);
4005fcf5ef2aSThomas Huth r2 = MASK_OP_BIT_S2(ctx->opcode);
4006fcf5ef2aSThomas Huth r3 = MASK_OP_BIT_D(ctx->opcode);
4007fcf5ef2aSThomas Huth pos1 = MASK_OP_BIT_POS1(ctx->opcode);
4008fcf5ef2aSThomas Huth pos2 = MASK_OP_BIT_POS2(ctx->opcode);
4009fcf5ef2aSThomas Huth op2 = MASK_OP_BIT_OP2(ctx->opcode);
4010fcf5ef2aSThomas Huth
4011fcf5ef2aSThomas Huth switch (op2) {
4012fcf5ef2aSThomas Huth case OPC2_32_BIT_AND_T:
4013fcf5ef2aSThomas Huth gen_bit_1op(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2],
4014fcf5ef2aSThomas Huth pos1, pos2, &tcg_gen_and_tl);
4015fcf5ef2aSThomas Huth break;
4016fcf5ef2aSThomas Huth case OPC2_32_BIT_ANDN_T:
4017fcf5ef2aSThomas Huth gen_bit_1op(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2],
4018fcf5ef2aSThomas Huth pos1, pos2, &tcg_gen_andc_tl);
4019fcf5ef2aSThomas Huth break;
4020fcf5ef2aSThomas Huth case OPC2_32_BIT_NOR_T:
4021fcf5ef2aSThomas Huth gen_bit_1op(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2],
4022fcf5ef2aSThomas Huth pos1, pos2, &tcg_gen_nor_tl);
4023fcf5ef2aSThomas Huth break;
4024fcf5ef2aSThomas Huth case OPC2_32_BIT_OR_T:
4025fcf5ef2aSThomas Huth gen_bit_1op(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2],
4026fcf5ef2aSThomas Huth pos1, pos2, &tcg_gen_or_tl);
4027fcf5ef2aSThomas Huth break;
4028fcf5ef2aSThomas Huth default:
4029fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
4030fcf5ef2aSThomas Huth }
4031fcf5ef2aSThomas Huth }
4032fcf5ef2aSThomas Huth
decode_bit_insert(DisasContext * ctx)40332db92a0cSBastian Koppelmann static void decode_bit_insert(DisasContext *ctx)
4034fcf5ef2aSThomas Huth {
4035fcf5ef2aSThomas Huth uint32_t op2;
4036fcf5ef2aSThomas Huth int r1, r2, r3;
4037fcf5ef2aSThomas Huth int pos1, pos2;
4038fcf5ef2aSThomas Huth TCGv temp;
4039fcf5ef2aSThomas Huth op2 = MASK_OP_BIT_OP2(ctx->opcode);
4040fcf5ef2aSThomas Huth r1 = MASK_OP_BIT_S1(ctx->opcode);
4041fcf5ef2aSThomas Huth r2 = MASK_OP_BIT_S2(ctx->opcode);
4042fcf5ef2aSThomas Huth r3 = MASK_OP_BIT_D(ctx->opcode);
4043fcf5ef2aSThomas Huth pos1 = MASK_OP_BIT_POS1(ctx->opcode);
4044fcf5ef2aSThomas Huth pos2 = MASK_OP_BIT_POS2(ctx->opcode);
4045fcf5ef2aSThomas Huth
4046fcf5ef2aSThomas Huth temp = tcg_temp_new();
4047fcf5ef2aSThomas Huth
4048fcf5ef2aSThomas Huth tcg_gen_shri_tl(temp, cpu_gpr_d[r2], pos2);
4049fcf5ef2aSThomas Huth if (op2 == OPC2_32_BIT_INSN_T) {
4050fcf5ef2aSThomas Huth tcg_gen_not_tl(temp, temp);
4051fcf5ef2aSThomas Huth }
4052fcf5ef2aSThomas Huth tcg_gen_deposit_tl(cpu_gpr_d[r3], cpu_gpr_d[r1], temp, pos1, 1);
4053fcf5ef2aSThomas Huth }
4054fcf5ef2aSThomas Huth
decode_bit_logical_t2(DisasContext * ctx)40552db92a0cSBastian Koppelmann static void decode_bit_logical_t2(DisasContext *ctx)
4056fcf5ef2aSThomas Huth {
4057fcf5ef2aSThomas Huth uint32_t op2;
4058fcf5ef2aSThomas Huth
4059fcf5ef2aSThomas Huth int r1, r2, r3;
4060fcf5ef2aSThomas Huth int pos1, pos2;
4061fcf5ef2aSThomas Huth
4062fcf5ef2aSThomas Huth op2 = MASK_OP_BIT_OP2(ctx->opcode);
4063fcf5ef2aSThomas Huth r1 = MASK_OP_BIT_S1(ctx->opcode);
4064fcf5ef2aSThomas Huth r2 = MASK_OP_BIT_S2(ctx->opcode);
4065fcf5ef2aSThomas Huth r3 = MASK_OP_BIT_D(ctx->opcode);
4066fcf5ef2aSThomas Huth pos1 = MASK_OP_BIT_POS1(ctx->opcode);
4067fcf5ef2aSThomas Huth pos2 = MASK_OP_BIT_POS2(ctx->opcode);
4068fcf5ef2aSThomas Huth
4069fcf5ef2aSThomas Huth switch (op2) {
4070fcf5ef2aSThomas Huth case OPC2_32_BIT_NAND_T:
4071fcf5ef2aSThomas Huth gen_bit_1op(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2],
4072fcf5ef2aSThomas Huth pos1, pos2, &tcg_gen_nand_tl);
4073fcf5ef2aSThomas Huth break;
4074fcf5ef2aSThomas Huth case OPC2_32_BIT_ORN_T:
4075fcf5ef2aSThomas Huth gen_bit_1op(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2],
4076fcf5ef2aSThomas Huth pos1, pos2, &tcg_gen_orc_tl);
4077fcf5ef2aSThomas Huth break;
4078fcf5ef2aSThomas Huth case OPC2_32_BIT_XNOR_T:
4079fcf5ef2aSThomas Huth gen_bit_1op(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2],
4080fcf5ef2aSThomas Huth pos1, pos2, &tcg_gen_eqv_tl);
4081fcf5ef2aSThomas Huth break;
4082fcf5ef2aSThomas Huth case OPC2_32_BIT_XOR_T:
4083fcf5ef2aSThomas Huth gen_bit_1op(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2],
4084fcf5ef2aSThomas Huth pos1, pos2, &tcg_gen_xor_tl);
4085fcf5ef2aSThomas Huth break;
4086fcf5ef2aSThomas Huth default:
4087fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
4088fcf5ef2aSThomas Huth }
4089fcf5ef2aSThomas Huth }
4090fcf5ef2aSThomas Huth
decode_bit_orand(DisasContext * ctx)40912db92a0cSBastian Koppelmann static void decode_bit_orand(DisasContext *ctx)
4092fcf5ef2aSThomas Huth {
4093fcf5ef2aSThomas Huth uint32_t op2;
4094fcf5ef2aSThomas Huth
4095fcf5ef2aSThomas Huth int r1, r2, r3;
4096fcf5ef2aSThomas Huth int pos1, pos2;
4097fcf5ef2aSThomas Huth
4098fcf5ef2aSThomas Huth op2 = MASK_OP_BIT_OP2(ctx->opcode);
4099fcf5ef2aSThomas Huth r1 = MASK_OP_BIT_S1(ctx->opcode);
4100fcf5ef2aSThomas Huth r2 = MASK_OP_BIT_S2(ctx->opcode);
4101fcf5ef2aSThomas Huth r3 = MASK_OP_BIT_D(ctx->opcode);
4102fcf5ef2aSThomas Huth pos1 = MASK_OP_BIT_POS1(ctx->opcode);
4103fcf5ef2aSThomas Huth pos2 = MASK_OP_BIT_POS2(ctx->opcode);
4104fcf5ef2aSThomas Huth
4105fcf5ef2aSThomas Huth switch (op2) {
4106fcf5ef2aSThomas Huth case OPC2_32_BIT_OR_AND_T:
4107fcf5ef2aSThomas Huth gen_bit_2op(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2],
4108fcf5ef2aSThomas Huth pos1, pos2, &tcg_gen_and_tl, &tcg_gen_or_tl);
4109fcf5ef2aSThomas Huth break;
4110fcf5ef2aSThomas Huth case OPC2_32_BIT_OR_ANDN_T:
4111fcf5ef2aSThomas Huth gen_bit_2op(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2],
4112fcf5ef2aSThomas Huth pos1, pos2, &tcg_gen_andc_tl, &tcg_gen_or_tl);
4113fcf5ef2aSThomas Huth break;
4114fcf5ef2aSThomas Huth case OPC2_32_BIT_OR_NOR_T:
4115fcf5ef2aSThomas Huth if (TCG_TARGET_HAS_orc_i32) {
4116fcf5ef2aSThomas Huth gen_bit_2op(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2],
4117fcf5ef2aSThomas Huth pos1, pos2, &tcg_gen_or_tl, &tcg_gen_orc_tl);
4118fcf5ef2aSThomas Huth } else {
4119fcf5ef2aSThomas Huth gen_bit_2op(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2],
4120fcf5ef2aSThomas Huth pos1, pos2, &tcg_gen_nor_tl, &tcg_gen_or_tl);
4121fcf5ef2aSThomas Huth }
4122fcf5ef2aSThomas Huth break;
4123fcf5ef2aSThomas Huth case OPC2_32_BIT_OR_OR_T:
4124fcf5ef2aSThomas Huth gen_bit_2op(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2],
4125fcf5ef2aSThomas Huth pos1, pos2, &tcg_gen_or_tl, &tcg_gen_or_tl);
4126fcf5ef2aSThomas Huth break;
4127fcf5ef2aSThomas Huth default:
4128fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
4129fcf5ef2aSThomas Huth }
4130fcf5ef2aSThomas Huth }
4131fcf5ef2aSThomas Huth
decode_bit_sh_logic1(DisasContext * ctx)41322db92a0cSBastian Koppelmann static void decode_bit_sh_logic1(DisasContext *ctx)
4133fcf5ef2aSThomas Huth {
4134fcf5ef2aSThomas Huth uint32_t op2;
4135fcf5ef2aSThomas Huth int r1, r2, r3;
4136fcf5ef2aSThomas Huth int pos1, pos2;
4137fcf5ef2aSThomas Huth TCGv temp;
4138fcf5ef2aSThomas Huth
4139fcf5ef2aSThomas Huth op2 = MASK_OP_BIT_OP2(ctx->opcode);
4140fcf5ef2aSThomas Huth r1 = MASK_OP_BIT_S1(ctx->opcode);
4141fcf5ef2aSThomas Huth r2 = MASK_OP_BIT_S2(ctx->opcode);
4142fcf5ef2aSThomas Huth r3 = MASK_OP_BIT_D(ctx->opcode);
4143fcf5ef2aSThomas Huth pos1 = MASK_OP_BIT_POS1(ctx->opcode);
4144fcf5ef2aSThomas Huth pos2 = MASK_OP_BIT_POS2(ctx->opcode);
4145fcf5ef2aSThomas Huth
4146fcf5ef2aSThomas Huth temp = tcg_temp_new();
4147fcf5ef2aSThomas Huth
4148fcf5ef2aSThomas Huth switch (op2) {
4149fcf5ef2aSThomas Huth case OPC2_32_BIT_SH_AND_T:
4150fcf5ef2aSThomas Huth gen_bit_1op(temp, cpu_gpr_d[r1], cpu_gpr_d[r2],
4151fcf5ef2aSThomas Huth pos1, pos2, &tcg_gen_and_tl);
4152fcf5ef2aSThomas Huth break;
4153fcf5ef2aSThomas Huth case OPC2_32_BIT_SH_ANDN_T:
4154fcf5ef2aSThomas Huth gen_bit_1op(temp, cpu_gpr_d[r1], cpu_gpr_d[r2],
4155fcf5ef2aSThomas Huth pos1, pos2, &tcg_gen_andc_tl);
4156fcf5ef2aSThomas Huth break;
4157fcf5ef2aSThomas Huth case OPC2_32_BIT_SH_NOR_T:
4158fcf5ef2aSThomas Huth gen_bit_1op(temp, cpu_gpr_d[r1], cpu_gpr_d[r2],
4159fcf5ef2aSThomas Huth pos1, pos2, &tcg_gen_nor_tl);
4160fcf5ef2aSThomas Huth break;
4161fcf5ef2aSThomas Huth case OPC2_32_BIT_SH_OR_T:
4162fcf5ef2aSThomas Huth gen_bit_1op(temp, cpu_gpr_d[r1], cpu_gpr_d[r2],
4163fcf5ef2aSThomas Huth pos1, pos2, &tcg_gen_or_tl);
4164fcf5ef2aSThomas Huth break;
4165fcf5ef2aSThomas Huth default:
4166fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
4167fcf5ef2aSThomas Huth }
4168fcf5ef2aSThomas Huth tcg_gen_shli_tl(cpu_gpr_d[r3], cpu_gpr_d[r3], 1);
4169fcf5ef2aSThomas Huth tcg_gen_add_tl(cpu_gpr_d[r3], cpu_gpr_d[r3], temp);
4170fcf5ef2aSThomas Huth }
4171fcf5ef2aSThomas Huth
decode_bit_sh_logic2(DisasContext * ctx)41722db92a0cSBastian Koppelmann static void decode_bit_sh_logic2(DisasContext *ctx)
4173fcf5ef2aSThomas Huth {
4174fcf5ef2aSThomas Huth uint32_t op2;
4175fcf5ef2aSThomas Huth int r1, r2, r3;
4176fcf5ef2aSThomas Huth int pos1, pos2;
4177fcf5ef2aSThomas Huth TCGv temp;
4178fcf5ef2aSThomas Huth
4179fcf5ef2aSThomas Huth op2 = MASK_OP_BIT_OP2(ctx->opcode);
4180fcf5ef2aSThomas Huth r1 = MASK_OP_BIT_S1(ctx->opcode);
4181fcf5ef2aSThomas Huth r2 = MASK_OP_BIT_S2(ctx->opcode);
4182fcf5ef2aSThomas Huth r3 = MASK_OP_BIT_D(ctx->opcode);
4183fcf5ef2aSThomas Huth pos1 = MASK_OP_BIT_POS1(ctx->opcode);
4184fcf5ef2aSThomas Huth pos2 = MASK_OP_BIT_POS2(ctx->opcode);
4185fcf5ef2aSThomas Huth
4186fcf5ef2aSThomas Huth temp = tcg_temp_new();
4187fcf5ef2aSThomas Huth
4188fcf5ef2aSThomas Huth switch (op2) {
4189fcf5ef2aSThomas Huth case OPC2_32_BIT_SH_NAND_T:
4190fcf5ef2aSThomas Huth gen_bit_1op(temp, cpu_gpr_d[r1] , cpu_gpr_d[r2] ,
4191fcf5ef2aSThomas Huth pos1, pos2, &tcg_gen_nand_tl);
4192fcf5ef2aSThomas Huth break;
4193fcf5ef2aSThomas Huth case OPC2_32_BIT_SH_ORN_T:
4194fcf5ef2aSThomas Huth gen_bit_1op(temp, cpu_gpr_d[r1], cpu_gpr_d[r2],
4195fcf5ef2aSThomas Huth pos1, pos2, &tcg_gen_orc_tl);
4196fcf5ef2aSThomas Huth break;
4197fcf5ef2aSThomas Huth case OPC2_32_BIT_SH_XNOR_T:
4198fcf5ef2aSThomas Huth gen_bit_1op(temp, cpu_gpr_d[r1], cpu_gpr_d[r2],
4199fcf5ef2aSThomas Huth pos1, pos2, &tcg_gen_eqv_tl);
4200fcf5ef2aSThomas Huth break;
4201fcf5ef2aSThomas Huth case OPC2_32_BIT_SH_XOR_T:
4202fcf5ef2aSThomas Huth gen_bit_1op(temp, cpu_gpr_d[r1], cpu_gpr_d[r2],
4203fcf5ef2aSThomas Huth pos1, pos2, &tcg_gen_xor_tl);
4204fcf5ef2aSThomas Huth break;
4205fcf5ef2aSThomas Huth default:
4206fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
4207fcf5ef2aSThomas Huth }
4208fcf5ef2aSThomas Huth tcg_gen_shli_tl(cpu_gpr_d[r3], cpu_gpr_d[r3], 1);
4209fcf5ef2aSThomas Huth tcg_gen_add_tl(cpu_gpr_d[r3], cpu_gpr_d[r3], temp);
4210fcf5ef2aSThomas Huth }
4211fcf5ef2aSThomas Huth
4212fcf5ef2aSThomas Huth /* BO-format */
4213fcf5ef2aSThomas Huth
4214fcf5ef2aSThomas Huth
decode_bo_addrmode_post_pre_base(DisasContext * ctx)42152db92a0cSBastian Koppelmann static void decode_bo_addrmode_post_pre_base(DisasContext *ctx)
4216fcf5ef2aSThomas Huth {
4217fcf5ef2aSThomas Huth uint32_t op2;
4218fcf5ef2aSThomas Huth uint32_t off10;
4219fcf5ef2aSThomas Huth int32_t r1, r2;
4220fcf5ef2aSThomas Huth TCGv temp;
4221fcf5ef2aSThomas Huth
4222fcf5ef2aSThomas Huth r1 = MASK_OP_BO_S1D(ctx->opcode);
4223fcf5ef2aSThomas Huth r2 = MASK_OP_BO_S2(ctx->opcode);
4224fcf5ef2aSThomas Huth off10 = MASK_OP_BO_OFF10_SEXT(ctx->opcode);
4225fcf5ef2aSThomas Huth op2 = MASK_OP_BO_OP2(ctx->opcode);
4226fcf5ef2aSThomas Huth
4227fcf5ef2aSThomas Huth switch (op2) {
4228fcf5ef2aSThomas Huth case OPC2_32_BO_CACHEA_WI_SHORTOFF:
4229fcf5ef2aSThomas Huth case OPC2_32_BO_CACHEA_W_SHORTOFF:
4230fcf5ef2aSThomas Huth case OPC2_32_BO_CACHEA_I_SHORTOFF:
4231fcf5ef2aSThomas Huth /* instruction to access the cache */
4232fcf5ef2aSThomas Huth break;
4233fcf5ef2aSThomas Huth case OPC2_32_BO_CACHEA_WI_POSTINC:
4234fcf5ef2aSThomas Huth case OPC2_32_BO_CACHEA_W_POSTINC:
4235fcf5ef2aSThomas Huth case OPC2_32_BO_CACHEA_I_POSTINC:
4236fcf5ef2aSThomas Huth /* instruction to access the cache, but we still need to handle
4237fcf5ef2aSThomas Huth the addressing mode */
4238fcf5ef2aSThomas Huth tcg_gen_addi_tl(cpu_gpr_a[r2], cpu_gpr_a[r2], off10);
4239fcf5ef2aSThomas Huth break;
4240fcf5ef2aSThomas Huth case OPC2_32_BO_CACHEA_WI_PREINC:
4241fcf5ef2aSThomas Huth case OPC2_32_BO_CACHEA_W_PREINC:
4242fcf5ef2aSThomas Huth case OPC2_32_BO_CACHEA_I_PREINC:
4243fcf5ef2aSThomas Huth /* instruction to access the cache, but we still need to handle
4244fcf5ef2aSThomas Huth the addressing mode */
4245fcf5ef2aSThomas Huth tcg_gen_addi_tl(cpu_gpr_a[r2], cpu_gpr_a[r2], off10);
4246fcf5ef2aSThomas Huth break;
4247fcf5ef2aSThomas Huth case OPC2_32_BO_CACHEI_WI_SHORTOFF:
4248fcf5ef2aSThomas Huth case OPC2_32_BO_CACHEI_W_SHORTOFF:
424944ee3bafSBastian Koppelmann if (!has_feature(ctx, TRICORE_FEATURE_131)) {
4250fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
4251fcf5ef2aSThomas Huth }
4252fcf5ef2aSThomas Huth break;
4253fcf5ef2aSThomas Huth case OPC2_32_BO_CACHEI_W_POSTINC:
4254fcf5ef2aSThomas Huth case OPC2_32_BO_CACHEI_WI_POSTINC:
425544ee3bafSBastian Koppelmann if (has_feature(ctx, TRICORE_FEATURE_131)) {
4256fcf5ef2aSThomas Huth tcg_gen_addi_tl(cpu_gpr_a[r2], cpu_gpr_a[r2], off10);
4257fcf5ef2aSThomas Huth } else {
4258fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
4259fcf5ef2aSThomas Huth }
4260fcf5ef2aSThomas Huth break;
4261fcf5ef2aSThomas Huth case OPC2_32_BO_CACHEI_W_PREINC:
4262fcf5ef2aSThomas Huth case OPC2_32_BO_CACHEI_WI_PREINC:
426344ee3bafSBastian Koppelmann if (has_feature(ctx, TRICORE_FEATURE_131)) {
4264fcf5ef2aSThomas Huth tcg_gen_addi_tl(cpu_gpr_a[r2], cpu_gpr_a[r2], off10);
4265fcf5ef2aSThomas Huth } else {
4266fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
4267fcf5ef2aSThomas Huth }
4268fcf5ef2aSThomas Huth break;
4269fcf5ef2aSThomas Huth case OPC2_32_BO_ST_A_SHORTOFF:
4270fcf5ef2aSThomas Huth gen_offset_st(ctx, cpu_gpr_a[r1], cpu_gpr_a[r2], off10, MO_LESL);
4271fcf5ef2aSThomas Huth break;
4272fcf5ef2aSThomas Huth case OPC2_32_BO_ST_A_POSTINC:
4273fcf5ef2aSThomas Huth tcg_gen_qemu_st_tl(cpu_gpr_a[r1], cpu_gpr_a[r2], ctx->mem_idx,
4274fcf5ef2aSThomas Huth MO_LESL);
4275fcf5ef2aSThomas Huth tcg_gen_addi_tl(cpu_gpr_a[r2], cpu_gpr_a[r2], off10);
4276fcf5ef2aSThomas Huth break;
4277fcf5ef2aSThomas Huth case OPC2_32_BO_ST_A_PREINC:
4278fcf5ef2aSThomas Huth gen_st_preincr(ctx, cpu_gpr_a[r1], cpu_gpr_a[r2], off10, MO_LESL);
4279fcf5ef2aSThomas Huth break;
4280fcf5ef2aSThomas Huth case OPC2_32_BO_ST_B_SHORTOFF:
4281fcf5ef2aSThomas Huth gen_offset_st(ctx, cpu_gpr_d[r1], cpu_gpr_a[r2], off10, MO_UB);
4282fcf5ef2aSThomas Huth break;
4283fcf5ef2aSThomas Huth case OPC2_32_BO_ST_B_POSTINC:
4284fcf5ef2aSThomas Huth tcg_gen_qemu_st_tl(cpu_gpr_d[r1], cpu_gpr_a[r2], ctx->mem_idx,
4285fcf5ef2aSThomas Huth MO_UB);
4286fcf5ef2aSThomas Huth tcg_gen_addi_tl(cpu_gpr_a[r2], cpu_gpr_a[r2], off10);
4287fcf5ef2aSThomas Huth break;
4288fcf5ef2aSThomas Huth case OPC2_32_BO_ST_B_PREINC:
4289fcf5ef2aSThomas Huth gen_st_preincr(ctx, cpu_gpr_d[r1], cpu_gpr_a[r2], off10, MO_UB);
4290fcf5ef2aSThomas Huth break;
4291fcf5ef2aSThomas Huth case OPC2_32_BO_ST_D_SHORTOFF:
4292fcf5ef2aSThomas Huth CHECK_REG_PAIR(r1);
4293fcf5ef2aSThomas Huth gen_offset_st_2regs(cpu_gpr_d[r1+1], cpu_gpr_d[r1], cpu_gpr_a[r2],
4294fcf5ef2aSThomas Huth off10, ctx);
4295fcf5ef2aSThomas Huth break;
4296fcf5ef2aSThomas Huth case OPC2_32_BO_ST_D_POSTINC:
4297fcf5ef2aSThomas Huth CHECK_REG_PAIR(r1);
4298fcf5ef2aSThomas Huth gen_st_2regs_64(cpu_gpr_d[r1+1], cpu_gpr_d[r1], cpu_gpr_a[r2], ctx);
4299fcf5ef2aSThomas Huth tcg_gen_addi_tl(cpu_gpr_a[r2], cpu_gpr_a[r2], off10);
4300fcf5ef2aSThomas Huth break;
4301fcf5ef2aSThomas Huth case OPC2_32_BO_ST_D_PREINC:
4302fcf5ef2aSThomas Huth CHECK_REG_PAIR(r1);
4303fcf5ef2aSThomas Huth temp = tcg_temp_new();
4304fcf5ef2aSThomas Huth tcg_gen_addi_tl(temp, cpu_gpr_a[r2], off10);
4305fcf5ef2aSThomas Huth gen_st_2regs_64(cpu_gpr_d[r1+1], cpu_gpr_d[r1], temp, ctx);
4306fcf5ef2aSThomas Huth tcg_gen_mov_tl(cpu_gpr_a[r2], temp);
4307fcf5ef2aSThomas Huth break;
4308fcf5ef2aSThomas Huth case OPC2_32_BO_ST_DA_SHORTOFF:
4309fcf5ef2aSThomas Huth CHECK_REG_PAIR(r1);
4310fcf5ef2aSThomas Huth gen_offset_st_2regs(cpu_gpr_a[r1+1], cpu_gpr_a[r1], cpu_gpr_a[r2],
4311fcf5ef2aSThomas Huth off10, ctx);
4312fcf5ef2aSThomas Huth break;
4313fcf5ef2aSThomas Huth case OPC2_32_BO_ST_DA_POSTINC:
4314fcf5ef2aSThomas Huth CHECK_REG_PAIR(r1);
4315fcf5ef2aSThomas Huth gen_st_2regs_64(cpu_gpr_a[r1+1], cpu_gpr_a[r1], cpu_gpr_a[r2], ctx);
4316fcf5ef2aSThomas Huth tcg_gen_addi_tl(cpu_gpr_a[r2], cpu_gpr_a[r2], off10);
4317fcf5ef2aSThomas Huth break;
4318fcf5ef2aSThomas Huth case OPC2_32_BO_ST_DA_PREINC:
4319fcf5ef2aSThomas Huth CHECK_REG_PAIR(r1);
4320fcf5ef2aSThomas Huth temp = tcg_temp_new();
4321fcf5ef2aSThomas Huth tcg_gen_addi_tl(temp, cpu_gpr_a[r2], off10);
4322fcf5ef2aSThomas Huth gen_st_2regs_64(cpu_gpr_a[r1+1], cpu_gpr_a[r1], temp, ctx);
4323fcf5ef2aSThomas Huth tcg_gen_mov_tl(cpu_gpr_a[r2], temp);
4324fcf5ef2aSThomas Huth break;
4325fcf5ef2aSThomas Huth case OPC2_32_BO_ST_H_SHORTOFF:
4326fcf5ef2aSThomas Huth gen_offset_st(ctx, cpu_gpr_d[r1], cpu_gpr_a[r2], off10, MO_LEUW);
4327fcf5ef2aSThomas Huth break;
4328fcf5ef2aSThomas Huth case OPC2_32_BO_ST_H_POSTINC:
4329fcf5ef2aSThomas Huth tcg_gen_qemu_st_tl(cpu_gpr_d[r1], cpu_gpr_a[r2], ctx->mem_idx,
4330fcf5ef2aSThomas Huth MO_LEUW);
4331fcf5ef2aSThomas Huth tcg_gen_addi_tl(cpu_gpr_a[r2], cpu_gpr_a[r2], off10);
4332fcf5ef2aSThomas Huth break;
4333fcf5ef2aSThomas Huth case OPC2_32_BO_ST_H_PREINC:
4334fcf5ef2aSThomas Huth gen_st_preincr(ctx, cpu_gpr_d[r1], cpu_gpr_a[r2], off10, MO_LEUW);
4335fcf5ef2aSThomas Huth break;
4336fcf5ef2aSThomas Huth case OPC2_32_BO_ST_Q_SHORTOFF:
4337fcf5ef2aSThomas Huth temp = tcg_temp_new();
4338fcf5ef2aSThomas Huth tcg_gen_shri_tl(temp, cpu_gpr_d[r1], 16);
4339fcf5ef2aSThomas Huth gen_offset_st(ctx, temp, cpu_gpr_a[r2], off10, MO_LEUW);
4340fcf5ef2aSThomas Huth break;
4341fcf5ef2aSThomas Huth case OPC2_32_BO_ST_Q_POSTINC:
4342fcf5ef2aSThomas Huth temp = tcg_temp_new();
4343fcf5ef2aSThomas Huth tcg_gen_shri_tl(temp, cpu_gpr_d[r1], 16);
4344fcf5ef2aSThomas Huth tcg_gen_qemu_st_tl(temp, cpu_gpr_a[r2], ctx->mem_idx,
4345fcf5ef2aSThomas Huth MO_LEUW);
4346fcf5ef2aSThomas Huth tcg_gen_addi_tl(cpu_gpr_a[r2], cpu_gpr_a[r2], off10);
4347fcf5ef2aSThomas Huth break;
4348fcf5ef2aSThomas Huth case OPC2_32_BO_ST_Q_PREINC:
4349fcf5ef2aSThomas Huth temp = tcg_temp_new();
4350fcf5ef2aSThomas Huth tcg_gen_shri_tl(temp, cpu_gpr_d[r1], 16);
4351fcf5ef2aSThomas Huth gen_st_preincr(ctx, temp, cpu_gpr_a[r2], off10, MO_LEUW);
4352fcf5ef2aSThomas Huth break;
4353fcf5ef2aSThomas Huth case OPC2_32_BO_ST_W_SHORTOFF:
4354fcf5ef2aSThomas Huth gen_offset_st(ctx, cpu_gpr_d[r1], cpu_gpr_a[r2], off10, MO_LEUL);
4355fcf5ef2aSThomas Huth break;
4356fcf5ef2aSThomas Huth case OPC2_32_BO_ST_W_POSTINC:
4357fcf5ef2aSThomas Huth tcg_gen_qemu_st_tl(cpu_gpr_d[r1], cpu_gpr_a[r2], ctx->mem_idx,
4358fcf5ef2aSThomas Huth MO_LEUL);
4359fcf5ef2aSThomas Huth tcg_gen_addi_tl(cpu_gpr_a[r2], cpu_gpr_a[r2], off10);
4360fcf5ef2aSThomas Huth break;
4361fcf5ef2aSThomas Huth case OPC2_32_BO_ST_W_PREINC:
4362fcf5ef2aSThomas Huth gen_st_preincr(ctx, cpu_gpr_d[r1], cpu_gpr_a[r2], off10, MO_LEUL);
4363fcf5ef2aSThomas Huth break;
4364fcf5ef2aSThomas Huth default:
4365fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
4366fcf5ef2aSThomas Huth }
4367fcf5ef2aSThomas Huth }
4368fcf5ef2aSThomas Huth
decode_bo_addrmode_bitreverse_circular(DisasContext * ctx)43692db92a0cSBastian Koppelmann static void decode_bo_addrmode_bitreverse_circular(DisasContext *ctx)
4370fcf5ef2aSThomas Huth {
4371fcf5ef2aSThomas Huth uint32_t op2;
4372fcf5ef2aSThomas Huth uint32_t off10;
4373fcf5ef2aSThomas Huth int32_t r1, r2;
43745c48ad75SRichard Henderson TCGv temp, temp2, t_off10;
4375fcf5ef2aSThomas Huth
4376fcf5ef2aSThomas Huth r1 = MASK_OP_BO_S1D(ctx->opcode);
4377fcf5ef2aSThomas Huth r2 = MASK_OP_BO_S2(ctx->opcode);
4378fcf5ef2aSThomas Huth off10 = MASK_OP_BO_OFF10_SEXT(ctx->opcode);
4379fcf5ef2aSThomas Huth op2 = MASK_OP_BO_OP2(ctx->opcode);
4380fcf5ef2aSThomas Huth
4381fcf5ef2aSThomas Huth temp = tcg_temp_new();
4382fcf5ef2aSThomas Huth temp2 = tcg_temp_new();
43835c48ad75SRichard Henderson t_off10 = tcg_constant_i32(off10);
4384fcf5ef2aSThomas Huth CHECK_REG_PAIR(r2);
4385fcf5ef2aSThomas Huth tcg_gen_ext16u_tl(temp, cpu_gpr_a[r2+1]);
4386fcf5ef2aSThomas Huth tcg_gen_add_tl(temp2, cpu_gpr_a[r2], temp);
4387fcf5ef2aSThomas Huth
4388fcf5ef2aSThomas Huth switch (op2) {
4389fcf5ef2aSThomas Huth case OPC2_32_BO_CACHEA_WI_BR:
4390fcf5ef2aSThomas Huth case OPC2_32_BO_CACHEA_W_BR:
4391fcf5ef2aSThomas Huth case OPC2_32_BO_CACHEA_I_BR:
4392fcf5ef2aSThomas Huth gen_helper_br_update(cpu_gpr_a[r2+1], cpu_gpr_a[r2+1]);
4393fcf5ef2aSThomas Huth break;
4394fcf5ef2aSThomas Huth case OPC2_32_BO_CACHEA_WI_CIRC:
4395fcf5ef2aSThomas Huth case OPC2_32_BO_CACHEA_W_CIRC:
4396fcf5ef2aSThomas Huth case OPC2_32_BO_CACHEA_I_CIRC:
43975c48ad75SRichard Henderson gen_helper_circ_update(cpu_gpr_a[r2+1], cpu_gpr_a[r2+1], t_off10);
4398fcf5ef2aSThomas Huth break;
4399fcf5ef2aSThomas Huth case OPC2_32_BO_ST_A_BR:
4400fcf5ef2aSThomas Huth tcg_gen_qemu_st_tl(cpu_gpr_a[r1], temp2, ctx->mem_idx, MO_LEUL);
4401fcf5ef2aSThomas Huth gen_helper_br_update(cpu_gpr_a[r2+1], cpu_gpr_a[r2+1]);
4402fcf5ef2aSThomas Huth break;
4403fcf5ef2aSThomas Huth case OPC2_32_BO_ST_A_CIRC:
4404fcf5ef2aSThomas Huth tcg_gen_qemu_st_tl(cpu_gpr_a[r1], temp2, ctx->mem_idx, MO_LEUL);
44055c48ad75SRichard Henderson gen_helper_circ_update(cpu_gpr_a[r2+1], cpu_gpr_a[r2+1], t_off10);
4406fcf5ef2aSThomas Huth break;
4407fcf5ef2aSThomas Huth case OPC2_32_BO_ST_B_BR:
4408fcf5ef2aSThomas Huth tcg_gen_qemu_st_tl(cpu_gpr_d[r1], temp2, ctx->mem_idx, MO_UB);
4409fcf5ef2aSThomas Huth gen_helper_br_update(cpu_gpr_a[r2+1], cpu_gpr_a[r2+1]);
4410fcf5ef2aSThomas Huth break;
4411fcf5ef2aSThomas Huth case OPC2_32_BO_ST_B_CIRC:
4412fcf5ef2aSThomas Huth tcg_gen_qemu_st_tl(cpu_gpr_d[r1], temp2, ctx->mem_idx, MO_UB);
44135c48ad75SRichard Henderson gen_helper_circ_update(cpu_gpr_a[r2+1], cpu_gpr_a[r2+1], t_off10);
4414fcf5ef2aSThomas Huth break;
4415fcf5ef2aSThomas Huth case OPC2_32_BO_ST_D_BR:
4416fcf5ef2aSThomas Huth CHECK_REG_PAIR(r1);
4417fcf5ef2aSThomas Huth gen_st_2regs_64(cpu_gpr_d[r1+1], cpu_gpr_d[r1], temp2, ctx);
4418fcf5ef2aSThomas Huth gen_helper_br_update(cpu_gpr_a[r2+1], cpu_gpr_a[r2+1]);
4419fcf5ef2aSThomas Huth break;
4420fcf5ef2aSThomas Huth case OPC2_32_BO_ST_D_CIRC:
4421fcf5ef2aSThomas Huth CHECK_REG_PAIR(r1);
4422fcf5ef2aSThomas Huth tcg_gen_qemu_st_tl(cpu_gpr_d[r1], temp2, ctx->mem_idx, MO_LEUL);
4423fcf5ef2aSThomas Huth tcg_gen_shri_tl(temp2, cpu_gpr_a[r2+1], 16);
4424fcf5ef2aSThomas Huth tcg_gen_addi_tl(temp, temp, 4);
4425fcf5ef2aSThomas Huth tcg_gen_rem_tl(temp, temp, temp2);
4426fcf5ef2aSThomas Huth tcg_gen_add_tl(temp2, cpu_gpr_a[r2], temp);
4427fcf5ef2aSThomas Huth tcg_gen_qemu_st_tl(cpu_gpr_d[r1+1], temp2, ctx->mem_idx, MO_LEUL);
44285c48ad75SRichard Henderson gen_helper_circ_update(cpu_gpr_a[r2+1], cpu_gpr_a[r2+1], t_off10);
4429fcf5ef2aSThomas Huth break;
4430fcf5ef2aSThomas Huth case OPC2_32_BO_ST_DA_BR:
4431fcf5ef2aSThomas Huth CHECK_REG_PAIR(r1);
4432fcf5ef2aSThomas Huth gen_st_2regs_64(cpu_gpr_a[r1+1], cpu_gpr_a[r1], temp2, ctx);
4433fcf5ef2aSThomas Huth gen_helper_br_update(cpu_gpr_a[r2+1], cpu_gpr_a[r2+1]);
4434fcf5ef2aSThomas Huth break;
4435fcf5ef2aSThomas Huth case OPC2_32_BO_ST_DA_CIRC:
4436fcf5ef2aSThomas Huth CHECK_REG_PAIR(r1);
4437fcf5ef2aSThomas Huth tcg_gen_qemu_st_tl(cpu_gpr_a[r1], temp2, ctx->mem_idx, MO_LEUL);
4438fcf5ef2aSThomas Huth tcg_gen_shri_tl(temp2, cpu_gpr_a[r2+1], 16);
4439fcf5ef2aSThomas Huth tcg_gen_addi_tl(temp, temp, 4);
4440fcf5ef2aSThomas Huth tcg_gen_rem_tl(temp, temp, temp2);
4441fcf5ef2aSThomas Huth tcg_gen_add_tl(temp2, cpu_gpr_a[r2], temp);
4442fcf5ef2aSThomas Huth tcg_gen_qemu_st_tl(cpu_gpr_a[r1+1], temp2, ctx->mem_idx, MO_LEUL);
44435c48ad75SRichard Henderson gen_helper_circ_update(cpu_gpr_a[r2+1], cpu_gpr_a[r2+1], t_off10);
4444fcf5ef2aSThomas Huth break;
4445fcf5ef2aSThomas Huth case OPC2_32_BO_ST_H_BR:
4446fcf5ef2aSThomas Huth tcg_gen_qemu_st_tl(cpu_gpr_d[r1], temp2, ctx->mem_idx, MO_LEUW);
4447fcf5ef2aSThomas Huth gen_helper_br_update(cpu_gpr_a[r2+1], cpu_gpr_a[r2+1]);
4448fcf5ef2aSThomas Huth break;
4449fcf5ef2aSThomas Huth case OPC2_32_BO_ST_H_CIRC:
4450fcf5ef2aSThomas Huth tcg_gen_qemu_st_tl(cpu_gpr_d[r1], temp2, ctx->mem_idx, MO_LEUW);
44515c48ad75SRichard Henderson gen_helper_circ_update(cpu_gpr_a[r2+1], cpu_gpr_a[r2+1], t_off10);
4452fcf5ef2aSThomas Huth break;
4453fcf5ef2aSThomas Huth case OPC2_32_BO_ST_Q_BR:
4454fcf5ef2aSThomas Huth tcg_gen_shri_tl(temp, cpu_gpr_d[r1], 16);
4455fcf5ef2aSThomas Huth tcg_gen_qemu_st_tl(temp, temp2, ctx->mem_idx, MO_LEUW);
4456fcf5ef2aSThomas Huth gen_helper_br_update(cpu_gpr_a[r2+1], cpu_gpr_a[r2+1]);
4457fcf5ef2aSThomas Huth break;
4458fcf5ef2aSThomas Huth case OPC2_32_BO_ST_Q_CIRC:
4459fcf5ef2aSThomas Huth tcg_gen_shri_tl(temp, cpu_gpr_d[r1], 16);
4460fcf5ef2aSThomas Huth tcg_gen_qemu_st_tl(temp, temp2, ctx->mem_idx, MO_LEUW);
44615c48ad75SRichard Henderson gen_helper_circ_update(cpu_gpr_a[r2+1], cpu_gpr_a[r2+1], t_off10);
4462fcf5ef2aSThomas Huth break;
4463fcf5ef2aSThomas Huth case OPC2_32_BO_ST_W_BR:
4464fcf5ef2aSThomas Huth tcg_gen_qemu_st_tl(cpu_gpr_d[r1], temp2, ctx->mem_idx, MO_LEUL);
4465fcf5ef2aSThomas Huth gen_helper_br_update(cpu_gpr_a[r2+1], cpu_gpr_a[r2+1]);
4466fcf5ef2aSThomas Huth break;
4467fcf5ef2aSThomas Huth case OPC2_32_BO_ST_W_CIRC:
4468fcf5ef2aSThomas Huth tcg_gen_qemu_st_tl(cpu_gpr_d[r1], temp2, ctx->mem_idx, MO_LEUL);
44695c48ad75SRichard Henderson gen_helper_circ_update(cpu_gpr_a[r2+1], cpu_gpr_a[r2+1], t_off10);
4470fcf5ef2aSThomas Huth break;
4471fcf5ef2aSThomas Huth default:
4472fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
4473fcf5ef2aSThomas Huth }
4474fcf5ef2aSThomas Huth }
4475fcf5ef2aSThomas Huth
decode_bo_addrmode_ld_post_pre_base(DisasContext * ctx)44762db92a0cSBastian Koppelmann static void decode_bo_addrmode_ld_post_pre_base(DisasContext *ctx)
4477fcf5ef2aSThomas Huth {
4478fcf5ef2aSThomas Huth uint32_t op2;
4479fcf5ef2aSThomas Huth uint32_t off10;
4480fcf5ef2aSThomas Huth int32_t r1, r2;
4481fcf5ef2aSThomas Huth TCGv temp;
4482fcf5ef2aSThomas Huth
4483fcf5ef2aSThomas Huth r1 = MASK_OP_BO_S1D(ctx->opcode);
4484fcf5ef2aSThomas Huth r2 = MASK_OP_BO_S2(ctx->opcode);
4485fcf5ef2aSThomas Huth off10 = MASK_OP_BO_OFF10_SEXT(ctx->opcode);
4486fcf5ef2aSThomas Huth op2 = MASK_OP_BO_OP2(ctx->opcode);
4487fcf5ef2aSThomas Huth
4488fcf5ef2aSThomas Huth switch (op2) {
4489fcf5ef2aSThomas Huth case OPC2_32_BO_LD_A_SHORTOFF:
4490fcf5ef2aSThomas Huth gen_offset_ld(ctx, cpu_gpr_a[r1], cpu_gpr_a[r2], off10, MO_LEUL);
4491fcf5ef2aSThomas Huth break;
4492fcf5ef2aSThomas Huth case OPC2_32_BO_LD_A_POSTINC:
4493fcf5ef2aSThomas Huth tcg_gen_qemu_ld_tl(cpu_gpr_a[r1], cpu_gpr_a[r2], ctx->mem_idx,
4494fcf5ef2aSThomas Huth MO_LEUL);
4495fcf5ef2aSThomas Huth tcg_gen_addi_tl(cpu_gpr_a[r2], cpu_gpr_a[r2], off10);
4496fcf5ef2aSThomas Huth break;
4497fcf5ef2aSThomas Huth case OPC2_32_BO_LD_A_PREINC:
4498fcf5ef2aSThomas Huth gen_ld_preincr(ctx, cpu_gpr_a[r1], cpu_gpr_a[r2], off10, MO_LEUL);
4499fcf5ef2aSThomas Huth break;
4500fcf5ef2aSThomas Huth case OPC2_32_BO_LD_B_SHORTOFF:
4501fcf5ef2aSThomas Huth gen_offset_ld(ctx, cpu_gpr_d[r1], cpu_gpr_a[r2], off10, MO_SB);
4502fcf5ef2aSThomas Huth break;
4503fcf5ef2aSThomas Huth case OPC2_32_BO_LD_B_POSTINC:
4504fcf5ef2aSThomas Huth tcg_gen_qemu_ld_tl(cpu_gpr_d[r1], cpu_gpr_a[r2], ctx->mem_idx,
4505fcf5ef2aSThomas Huth MO_SB);
4506fcf5ef2aSThomas Huth tcg_gen_addi_tl(cpu_gpr_a[r2], cpu_gpr_a[r2], off10);
4507fcf5ef2aSThomas Huth break;
4508fcf5ef2aSThomas Huth case OPC2_32_BO_LD_B_PREINC:
4509fcf5ef2aSThomas Huth gen_ld_preincr(ctx, cpu_gpr_d[r1], cpu_gpr_a[r2], off10, MO_SB);
4510fcf5ef2aSThomas Huth break;
4511fcf5ef2aSThomas Huth case OPC2_32_BO_LD_BU_SHORTOFF:
4512fcf5ef2aSThomas Huth gen_offset_ld(ctx, cpu_gpr_d[r1], cpu_gpr_a[r2], off10, MO_UB);
4513fcf5ef2aSThomas Huth break;
4514fcf5ef2aSThomas Huth case OPC2_32_BO_LD_BU_POSTINC:
4515fcf5ef2aSThomas Huth tcg_gen_qemu_ld_tl(cpu_gpr_d[r1], cpu_gpr_a[r2], ctx->mem_idx,
4516fcf5ef2aSThomas Huth MO_UB);
4517fcf5ef2aSThomas Huth tcg_gen_addi_tl(cpu_gpr_a[r2], cpu_gpr_a[r2], off10);
4518fcf5ef2aSThomas Huth break;
4519fcf5ef2aSThomas Huth case OPC2_32_BO_LD_BU_PREINC:
4520d8b33554SBastian Koppelmann gen_ld_preincr(ctx, cpu_gpr_d[r1], cpu_gpr_a[r2], off10, MO_UB);
4521fcf5ef2aSThomas Huth break;
4522fcf5ef2aSThomas Huth case OPC2_32_BO_LD_D_SHORTOFF:
4523fcf5ef2aSThomas Huth CHECK_REG_PAIR(r1);
4524fcf5ef2aSThomas Huth gen_offset_ld_2regs(cpu_gpr_d[r1+1], cpu_gpr_d[r1], cpu_gpr_a[r2],
4525fcf5ef2aSThomas Huth off10, ctx);
4526fcf5ef2aSThomas Huth break;
4527fcf5ef2aSThomas Huth case OPC2_32_BO_LD_D_POSTINC:
4528fcf5ef2aSThomas Huth CHECK_REG_PAIR(r1);
4529fcf5ef2aSThomas Huth gen_ld_2regs_64(cpu_gpr_d[r1+1], cpu_gpr_d[r1], cpu_gpr_a[r2], ctx);
4530fcf5ef2aSThomas Huth tcg_gen_addi_tl(cpu_gpr_a[r2], cpu_gpr_a[r2], off10);
4531fcf5ef2aSThomas Huth break;
4532fcf5ef2aSThomas Huth case OPC2_32_BO_LD_D_PREINC:
4533fcf5ef2aSThomas Huth CHECK_REG_PAIR(r1);
4534fcf5ef2aSThomas Huth temp = tcg_temp_new();
4535fcf5ef2aSThomas Huth tcg_gen_addi_tl(temp, cpu_gpr_a[r2], off10);
4536fcf5ef2aSThomas Huth gen_ld_2regs_64(cpu_gpr_d[r1+1], cpu_gpr_d[r1], temp, ctx);
4537fcf5ef2aSThomas Huth tcg_gen_mov_tl(cpu_gpr_a[r2], temp);
4538fcf5ef2aSThomas Huth break;
4539fcf5ef2aSThomas Huth case OPC2_32_BO_LD_DA_SHORTOFF:
4540fcf5ef2aSThomas Huth CHECK_REG_PAIR(r1);
4541fcf5ef2aSThomas Huth gen_offset_ld_2regs(cpu_gpr_a[r1+1], cpu_gpr_a[r1], cpu_gpr_a[r2],
4542fcf5ef2aSThomas Huth off10, ctx);
4543fcf5ef2aSThomas Huth break;
4544fcf5ef2aSThomas Huth case OPC2_32_BO_LD_DA_POSTINC:
4545fcf5ef2aSThomas Huth CHECK_REG_PAIR(r1);
4546fcf5ef2aSThomas Huth gen_ld_2regs_64(cpu_gpr_a[r1+1], cpu_gpr_a[r1], cpu_gpr_a[r2], ctx);
4547fcf5ef2aSThomas Huth tcg_gen_addi_tl(cpu_gpr_a[r2], cpu_gpr_a[r2], off10);
4548fcf5ef2aSThomas Huth break;
4549fcf5ef2aSThomas Huth case OPC2_32_BO_LD_DA_PREINC:
4550fcf5ef2aSThomas Huth CHECK_REG_PAIR(r1);
4551fcf5ef2aSThomas Huth temp = tcg_temp_new();
4552fcf5ef2aSThomas Huth tcg_gen_addi_tl(temp, cpu_gpr_a[r2], off10);
4553fcf5ef2aSThomas Huth gen_ld_2regs_64(cpu_gpr_a[r1+1], cpu_gpr_a[r1], temp, ctx);
4554fcf5ef2aSThomas Huth tcg_gen_mov_tl(cpu_gpr_a[r2], temp);
4555fcf5ef2aSThomas Huth break;
4556fcf5ef2aSThomas Huth case OPC2_32_BO_LD_H_SHORTOFF:
4557fcf5ef2aSThomas Huth gen_offset_ld(ctx, cpu_gpr_d[r1], cpu_gpr_a[r2], off10, MO_LESW);
4558fcf5ef2aSThomas Huth break;
4559fcf5ef2aSThomas Huth case OPC2_32_BO_LD_H_POSTINC:
4560fcf5ef2aSThomas Huth tcg_gen_qemu_ld_tl(cpu_gpr_d[r1], cpu_gpr_a[r2], ctx->mem_idx,
4561fcf5ef2aSThomas Huth MO_LESW);
4562fcf5ef2aSThomas Huth tcg_gen_addi_tl(cpu_gpr_a[r2], cpu_gpr_a[r2], off10);
4563fcf5ef2aSThomas Huth break;
4564fcf5ef2aSThomas Huth case OPC2_32_BO_LD_H_PREINC:
4565fcf5ef2aSThomas Huth gen_ld_preincr(ctx, cpu_gpr_d[r1], cpu_gpr_a[r2], off10, MO_LESW);
4566fcf5ef2aSThomas Huth break;
4567fcf5ef2aSThomas Huth case OPC2_32_BO_LD_HU_SHORTOFF:
4568fcf5ef2aSThomas Huth gen_offset_ld(ctx, cpu_gpr_d[r1], cpu_gpr_a[r2], off10, MO_LEUW);
4569fcf5ef2aSThomas Huth break;
4570fcf5ef2aSThomas Huth case OPC2_32_BO_LD_HU_POSTINC:
4571fcf5ef2aSThomas Huth tcg_gen_qemu_ld_tl(cpu_gpr_d[r1], cpu_gpr_a[r2], ctx->mem_idx,
4572fcf5ef2aSThomas Huth MO_LEUW);
4573fcf5ef2aSThomas Huth tcg_gen_addi_tl(cpu_gpr_a[r2], cpu_gpr_a[r2], off10);
4574fcf5ef2aSThomas Huth break;
4575fcf5ef2aSThomas Huth case OPC2_32_BO_LD_HU_PREINC:
4576fcf5ef2aSThomas Huth gen_ld_preincr(ctx, cpu_gpr_d[r1], cpu_gpr_a[r2], off10, MO_LEUW);
4577fcf5ef2aSThomas Huth break;
4578fcf5ef2aSThomas Huth case OPC2_32_BO_LD_Q_SHORTOFF:
4579fcf5ef2aSThomas Huth gen_offset_ld(ctx, cpu_gpr_d[r1], cpu_gpr_a[r2], off10, MO_LEUW);
4580fcf5ef2aSThomas Huth tcg_gen_shli_tl(cpu_gpr_d[r1], cpu_gpr_d[r1], 16);
4581fcf5ef2aSThomas Huth break;
4582fcf5ef2aSThomas Huth case OPC2_32_BO_LD_Q_POSTINC:
4583fcf5ef2aSThomas Huth tcg_gen_qemu_ld_tl(cpu_gpr_d[r1], cpu_gpr_a[r2], ctx->mem_idx,
4584fcf5ef2aSThomas Huth MO_LEUW);
4585fcf5ef2aSThomas Huth tcg_gen_shli_tl(cpu_gpr_d[r1], cpu_gpr_d[r1], 16);
4586fcf5ef2aSThomas Huth tcg_gen_addi_tl(cpu_gpr_a[r2], cpu_gpr_a[r2], off10);
4587fcf5ef2aSThomas Huth break;
4588fcf5ef2aSThomas Huth case OPC2_32_BO_LD_Q_PREINC:
4589fcf5ef2aSThomas Huth gen_ld_preincr(ctx, cpu_gpr_d[r1], cpu_gpr_a[r2], off10, MO_LEUW);
4590fcf5ef2aSThomas Huth tcg_gen_shli_tl(cpu_gpr_d[r1], cpu_gpr_d[r1], 16);
4591fcf5ef2aSThomas Huth break;
4592fcf5ef2aSThomas Huth case OPC2_32_BO_LD_W_SHORTOFF:
4593fcf5ef2aSThomas Huth gen_offset_ld(ctx, cpu_gpr_d[r1], cpu_gpr_a[r2], off10, MO_LEUL);
4594fcf5ef2aSThomas Huth break;
4595fcf5ef2aSThomas Huth case OPC2_32_BO_LD_W_POSTINC:
4596fcf5ef2aSThomas Huth tcg_gen_qemu_ld_tl(cpu_gpr_d[r1], cpu_gpr_a[r2], ctx->mem_idx,
4597fcf5ef2aSThomas Huth MO_LEUL);
4598fcf5ef2aSThomas Huth tcg_gen_addi_tl(cpu_gpr_a[r2], cpu_gpr_a[r2], off10);
4599fcf5ef2aSThomas Huth break;
4600fcf5ef2aSThomas Huth case OPC2_32_BO_LD_W_PREINC:
4601fcf5ef2aSThomas Huth gen_ld_preincr(ctx, cpu_gpr_d[r1], cpu_gpr_a[r2], off10, MO_LEUL);
4602fcf5ef2aSThomas Huth break;
4603fcf5ef2aSThomas Huth default:
4604fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
4605fcf5ef2aSThomas Huth }
4606fcf5ef2aSThomas Huth }
4607fcf5ef2aSThomas Huth
decode_bo_addrmode_ld_bitreverse_circular(DisasContext * ctx)46082db92a0cSBastian Koppelmann static void decode_bo_addrmode_ld_bitreverse_circular(DisasContext *ctx)
4609fcf5ef2aSThomas Huth {
4610fcf5ef2aSThomas Huth uint32_t op2;
4611fcf5ef2aSThomas Huth uint32_t off10;
4612fcf5ef2aSThomas Huth int r1, r2;
46135c48ad75SRichard Henderson TCGv temp, temp2, t_off10;
4614fcf5ef2aSThomas Huth
4615fcf5ef2aSThomas Huth r1 = MASK_OP_BO_S1D(ctx->opcode);
4616fcf5ef2aSThomas Huth r2 = MASK_OP_BO_S2(ctx->opcode);
4617fcf5ef2aSThomas Huth off10 = MASK_OP_BO_OFF10_SEXT(ctx->opcode);
4618fcf5ef2aSThomas Huth op2 = MASK_OP_BO_OP2(ctx->opcode);
4619fcf5ef2aSThomas Huth
4620fcf5ef2aSThomas Huth temp = tcg_temp_new();
4621fcf5ef2aSThomas Huth temp2 = tcg_temp_new();
46225c48ad75SRichard Henderson t_off10 = tcg_constant_i32(off10);
4623fcf5ef2aSThomas Huth CHECK_REG_PAIR(r2);
4624fcf5ef2aSThomas Huth tcg_gen_ext16u_tl(temp, cpu_gpr_a[r2+1]);
4625fcf5ef2aSThomas Huth tcg_gen_add_tl(temp2, cpu_gpr_a[r2], temp);
4626fcf5ef2aSThomas Huth
4627fcf5ef2aSThomas Huth
4628fcf5ef2aSThomas Huth switch (op2) {
4629fcf5ef2aSThomas Huth case OPC2_32_BO_LD_A_BR:
4630fcf5ef2aSThomas Huth tcg_gen_qemu_ld_tl(cpu_gpr_a[r1], temp2, ctx->mem_idx, MO_LEUL);
4631fcf5ef2aSThomas Huth gen_helper_br_update(cpu_gpr_a[r2+1], cpu_gpr_a[r2+1]);
4632fcf5ef2aSThomas Huth break;
4633fcf5ef2aSThomas Huth case OPC2_32_BO_LD_A_CIRC:
4634fcf5ef2aSThomas Huth tcg_gen_qemu_ld_tl(cpu_gpr_a[r1], temp2, ctx->mem_idx, MO_LEUL);
46355c48ad75SRichard Henderson gen_helper_circ_update(cpu_gpr_a[r2+1], cpu_gpr_a[r2+1], t_off10);
4636fcf5ef2aSThomas Huth break;
4637fcf5ef2aSThomas Huth case OPC2_32_BO_LD_B_BR:
4638fcf5ef2aSThomas Huth tcg_gen_qemu_ld_tl(cpu_gpr_d[r1], temp2, ctx->mem_idx, MO_SB);
4639fcf5ef2aSThomas Huth gen_helper_br_update(cpu_gpr_a[r2+1], cpu_gpr_a[r2+1]);
4640fcf5ef2aSThomas Huth break;
4641fcf5ef2aSThomas Huth case OPC2_32_BO_LD_B_CIRC:
4642fcf5ef2aSThomas Huth tcg_gen_qemu_ld_tl(cpu_gpr_d[r1], temp2, ctx->mem_idx, MO_SB);
46435c48ad75SRichard Henderson gen_helper_circ_update(cpu_gpr_a[r2+1], cpu_gpr_a[r2+1], t_off10);
4644fcf5ef2aSThomas Huth break;
4645fcf5ef2aSThomas Huth case OPC2_32_BO_LD_BU_BR:
4646fcf5ef2aSThomas Huth tcg_gen_qemu_ld_tl(cpu_gpr_d[r1], temp2, ctx->mem_idx, MO_UB);
4647fcf5ef2aSThomas Huth gen_helper_br_update(cpu_gpr_a[r2+1], cpu_gpr_a[r2+1]);
4648fcf5ef2aSThomas Huth break;
4649fcf5ef2aSThomas Huth case OPC2_32_BO_LD_BU_CIRC:
4650fcf5ef2aSThomas Huth tcg_gen_qemu_ld_tl(cpu_gpr_d[r1], temp2, ctx->mem_idx, MO_UB);
46515c48ad75SRichard Henderson gen_helper_circ_update(cpu_gpr_a[r2+1], cpu_gpr_a[r2+1], t_off10);
4652fcf5ef2aSThomas Huth break;
4653fcf5ef2aSThomas Huth case OPC2_32_BO_LD_D_BR:
4654fcf5ef2aSThomas Huth CHECK_REG_PAIR(r1);
4655fcf5ef2aSThomas Huth gen_ld_2regs_64(cpu_gpr_d[r1+1], cpu_gpr_d[r1], temp2, ctx);
4656fcf5ef2aSThomas Huth gen_helper_br_update(cpu_gpr_a[r2+1], cpu_gpr_a[r2+1]);
4657fcf5ef2aSThomas Huth break;
4658fcf5ef2aSThomas Huth case OPC2_32_BO_LD_D_CIRC:
4659fcf5ef2aSThomas Huth CHECK_REG_PAIR(r1);
4660fcf5ef2aSThomas Huth tcg_gen_qemu_ld_tl(cpu_gpr_d[r1], temp2, ctx->mem_idx, MO_LEUL);
4661fcf5ef2aSThomas Huth tcg_gen_shri_tl(temp2, cpu_gpr_a[r2+1], 16);
4662fcf5ef2aSThomas Huth tcg_gen_addi_tl(temp, temp, 4);
4663fcf5ef2aSThomas Huth tcg_gen_rem_tl(temp, temp, temp2);
4664fcf5ef2aSThomas Huth tcg_gen_add_tl(temp2, cpu_gpr_a[r2], temp);
4665fcf5ef2aSThomas Huth tcg_gen_qemu_ld_tl(cpu_gpr_d[r1+1], temp2, ctx->mem_idx, MO_LEUL);
46665c48ad75SRichard Henderson gen_helper_circ_update(cpu_gpr_a[r2+1], cpu_gpr_a[r2+1], t_off10);
4667fcf5ef2aSThomas Huth break;
4668fcf5ef2aSThomas Huth case OPC2_32_BO_LD_DA_BR:
4669fcf5ef2aSThomas Huth CHECK_REG_PAIR(r1);
4670fcf5ef2aSThomas Huth gen_ld_2regs_64(cpu_gpr_a[r1+1], cpu_gpr_a[r1], temp2, ctx);
4671fcf5ef2aSThomas Huth gen_helper_br_update(cpu_gpr_a[r2+1], cpu_gpr_a[r2+1]);
4672fcf5ef2aSThomas Huth break;
4673fcf5ef2aSThomas Huth case OPC2_32_BO_LD_DA_CIRC:
4674fcf5ef2aSThomas Huth CHECK_REG_PAIR(r1);
4675fcf5ef2aSThomas Huth tcg_gen_qemu_ld_tl(cpu_gpr_a[r1], temp2, ctx->mem_idx, MO_LEUL);
4676fcf5ef2aSThomas Huth tcg_gen_shri_tl(temp2, cpu_gpr_a[r2+1], 16);
4677fcf5ef2aSThomas Huth tcg_gen_addi_tl(temp, temp, 4);
4678fcf5ef2aSThomas Huth tcg_gen_rem_tl(temp, temp, temp2);
4679fcf5ef2aSThomas Huth tcg_gen_add_tl(temp2, cpu_gpr_a[r2], temp);
4680fcf5ef2aSThomas Huth tcg_gen_qemu_ld_tl(cpu_gpr_a[r1+1], temp2, ctx->mem_idx, MO_LEUL);
46815c48ad75SRichard Henderson gen_helper_circ_update(cpu_gpr_a[r2+1], cpu_gpr_a[r2+1], t_off10);
4682fcf5ef2aSThomas Huth break;
4683fcf5ef2aSThomas Huth case OPC2_32_BO_LD_H_BR:
4684fcf5ef2aSThomas Huth tcg_gen_qemu_ld_tl(cpu_gpr_d[r1], temp2, ctx->mem_idx, MO_LESW);
4685fcf5ef2aSThomas Huth gen_helper_br_update(cpu_gpr_a[r2+1], cpu_gpr_a[r2+1]);
4686fcf5ef2aSThomas Huth break;
4687fcf5ef2aSThomas Huth case OPC2_32_BO_LD_H_CIRC:
4688fcf5ef2aSThomas Huth tcg_gen_qemu_ld_tl(cpu_gpr_d[r1], temp2, ctx->mem_idx, MO_LESW);
46895c48ad75SRichard Henderson gen_helper_circ_update(cpu_gpr_a[r2+1], cpu_gpr_a[r2+1], t_off10);
4690fcf5ef2aSThomas Huth break;
4691fcf5ef2aSThomas Huth case OPC2_32_BO_LD_HU_BR:
4692fcf5ef2aSThomas Huth tcg_gen_qemu_ld_tl(cpu_gpr_d[r1], temp2, ctx->mem_idx, MO_LEUW);
4693fcf5ef2aSThomas Huth gen_helper_br_update(cpu_gpr_a[r2+1], cpu_gpr_a[r2+1]);
4694fcf5ef2aSThomas Huth break;
4695fcf5ef2aSThomas Huth case OPC2_32_BO_LD_HU_CIRC:
4696fcf5ef2aSThomas Huth tcg_gen_qemu_ld_tl(cpu_gpr_d[r1], temp2, ctx->mem_idx, MO_LEUW);
46975c48ad75SRichard Henderson gen_helper_circ_update(cpu_gpr_a[r2+1], cpu_gpr_a[r2+1], t_off10);
4698fcf5ef2aSThomas Huth break;
4699fcf5ef2aSThomas Huth case OPC2_32_BO_LD_Q_BR:
4700fcf5ef2aSThomas Huth tcg_gen_qemu_ld_tl(cpu_gpr_d[r1], temp2, ctx->mem_idx, MO_LEUW);
4701fcf5ef2aSThomas Huth tcg_gen_shli_tl(cpu_gpr_d[r1], cpu_gpr_d[r1], 16);
4702fcf5ef2aSThomas Huth gen_helper_br_update(cpu_gpr_a[r2+1], cpu_gpr_a[r2+1]);
4703fcf5ef2aSThomas Huth break;
4704fcf5ef2aSThomas Huth case OPC2_32_BO_LD_Q_CIRC:
4705fcf5ef2aSThomas Huth tcg_gen_qemu_ld_tl(cpu_gpr_d[r1], temp2, ctx->mem_idx, MO_LEUW);
4706fcf5ef2aSThomas Huth tcg_gen_shli_tl(cpu_gpr_d[r1], cpu_gpr_d[r1], 16);
47075c48ad75SRichard Henderson gen_helper_circ_update(cpu_gpr_a[r2+1], cpu_gpr_a[r2+1], t_off10);
4708fcf5ef2aSThomas Huth break;
4709fcf5ef2aSThomas Huth case OPC2_32_BO_LD_W_BR:
4710fcf5ef2aSThomas Huth tcg_gen_qemu_ld_tl(cpu_gpr_d[r1], temp2, ctx->mem_idx, MO_LEUL);
4711fcf5ef2aSThomas Huth gen_helper_br_update(cpu_gpr_a[r2+1], cpu_gpr_a[r2+1]);
4712fcf5ef2aSThomas Huth break;
4713fcf5ef2aSThomas Huth case OPC2_32_BO_LD_W_CIRC:
4714fcf5ef2aSThomas Huth tcg_gen_qemu_ld_tl(cpu_gpr_d[r1], temp2, ctx->mem_idx, MO_LEUL);
47155c48ad75SRichard Henderson gen_helper_circ_update(cpu_gpr_a[r2+1], cpu_gpr_a[r2+1], t_off10);
4716fcf5ef2aSThomas Huth break;
4717fcf5ef2aSThomas Huth default:
4718fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
4719fcf5ef2aSThomas Huth }
4720fcf5ef2aSThomas Huth }
4721fcf5ef2aSThomas Huth
decode_bo_addrmode_stctx_post_pre_base(DisasContext * ctx)47222db92a0cSBastian Koppelmann static void decode_bo_addrmode_stctx_post_pre_base(DisasContext *ctx)
4723fcf5ef2aSThomas Huth {
4724fcf5ef2aSThomas Huth uint32_t op2;
4725fcf5ef2aSThomas Huth uint32_t off10;
4726fcf5ef2aSThomas Huth int r1, r2;
4727fcf5ef2aSThomas Huth
472808ee498bSRichard Henderson TCGv temp;
4729fcf5ef2aSThomas Huth
4730fcf5ef2aSThomas Huth r1 = MASK_OP_BO_S1D(ctx->opcode);
4731fcf5ef2aSThomas Huth r2 = MASK_OP_BO_S2(ctx->opcode);
4732fcf5ef2aSThomas Huth off10 = MASK_OP_BO_OFF10_SEXT(ctx->opcode);
4733fcf5ef2aSThomas Huth op2 = MASK_OP_BO_OP2(ctx->opcode);
4734fcf5ef2aSThomas Huth
4735fcf5ef2aSThomas Huth
4736fcf5ef2aSThomas Huth temp = tcg_temp_new();
4737fcf5ef2aSThomas Huth
4738fcf5ef2aSThomas Huth switch (op2) {
4739fcf5ef2aSThomas Huth case OPC2_32_BO_LDLCX_SHORTOFF:
4740fcf5ef2aSThomas Huth tcg_gen_addi_tl(temp, cpu_gpr_a[r2], off10);
4741ad75a51eSRichard Henderson gen_helper_ldlcx(tcg_env, temp);
4742fcf5ef2aSThomas Huth break;
4743fcf5ef2aSThomas Huth case OPC2_32_BO_LDMST_SHORTOFF:
4744fcf5ef2aSThomas Huth tcg_gen_addi_tl(temp, cpu_gpr_a[r2], off10);
4745fcf5ef2aSThomas Huth gen_ldmst(ctx, r1, temp);
4746fcf5ef2aSThomas Huth break;
4747fcf5ef2aSThomas Huth case OPC2_32_BO_LDMST_POSTINC:
4748fcf5ef2aSThomas Huth gen_ldmst(ctx, r1, cpu_gpr_a[r2]);
4749fcf5ef2aSThomas Huth tcg_gen_addi_tl(cpu_gpr_a[r2], cpu_gpr_a[r2], off10);
4750fcf5ef2aSThomas Huth break;
4751fcf5ef2aSThomas Huth case OPC2_32_BO_LDMST_PREINC:
4752fcf5ef2aSThomas Huth tcg_gen_addi_tl(cpu_gpr_a[r2], cpu_gpr_a[r2], off10);
4753fcf5ef2aSThomas Huth gen_ldmst(ctx, r1, cpu_gpr_a[r2]);
4754fcf5ef2aSThomas Huth break;
4755fcf5ef2aSThomas Huth case OPC2_32_BO_LDUCX_SHORTOFF:
4756fcf5ef2aSThomas Huth tcg_gen_addi_tl(temp, cpu_gpr_a[r2], off10);
4757ad75a51eSRichard Henderson gen_helper_lducx(tcg_env, temp);
4758fcf5ef2aSThomas Huth break;
4759fcf5ef2aSThomas Huth case OPC2_32_BO_LEA_SHORTOFF:
4760fcf5ef2aSThomas Huth tcg_gen_addi_tl(cpu_gpr_a[r1], cpu_gpr_a[r2], off10);
4761fcf5ef2aSThomas Huth break;
4762fcf5ef2aSThomas Huth case OPC2_32_BO_STLCX_SHORTOFF:
4763fcf5ef2aSThomas Huth tcg_gen_addi_tl(temp, cpu_gpr_a[r2], off10);
4764ad75a51eSRichard Henderson gen_helper_stlcx(tcg_env, temp);
4765fcf5ef2aSThomas Huth break;
4766fcf5ef2aSThomas Huth case OPC2_32_BO_STUCX_SHORTOFF:
4767fcf5ef2aSThomas Huth tcg_gen_addi_tl(temp, cpu_gpr_a[r2], off10);
4768ad75a51eSRichard Henderson gen_helper_stucx(tcg_env, temp);
4769fcf5ef2aSThomas Huth break;
4770fcf5ef2aSThomas Huth case OPC2_32_BO_SWAP_W_SHORTOFF:
4771fcf5ef2aSThomas Huth tcg_gen_addi_tl(temp, cpu_gpr_a[r2], off10);
4772fcf5ef2aSThomas Huth gen_swap(ctx, r1, temp);
4773fcf5ef2aSThomas Huth break;
4774fcf5ef2aSThomas Huth case OPC2_32_BO_SWAP_W_POSTINC:
4775fcf5ef2aSThomas Huth gen_swap(ctx, r1, cpu_gpr_a[r2]);
4776fcf5ef2aSThomas Huth tcg_gen_addi_tl(cpu_gpr_a[r2], cpu_gpr_a[r2], off10);
4777fcf5ef2aSThomas Huth break;
4778fcf5ef2aSThomas Huth case OPC2_32_BO_SWAP_W_PREINC:
4779fcf5ef2aSThomas Huth tcg_gen_addi_tl(cpu_gpr_a[r2], cpu_gpr_a[r2], off10);
4780fcf5ef2aSThomas Huth gen_swap(ctx, r1, cpu_gpr_a[r2]);
4781fcf5ef2aSThomas Huth break;
4782fcf5ef2aSThomas Huth case OPC2_32_BO_CMPSWAP_W_SHORTOFF:
4783fcf5ef2aSThomas Huth tcg_gen_addi_tl(temp, cpu_gpr_a[r2], off10);
4784fcf5ef2aSThomas Huth gen_cmpswap(ctx, r1, temp);
4785fcf5ef2aSThomas Huth break;
4786fcf5ef2aSThomas Huth case OPC2_32_BO_CMPSWAP_W_POSTINC:
4787fcf5ef2aSThomas Huth gen_cmpswap(ctx, r1, cpu_gpr_a[r2]);
4788fcf5ef2aSThomas Huth tcg_gen_addi_tl(cpu_gpr_a[r2], cpu_gpr_a[r2], off10);
4789fcf5ef2aSThomas Huth break;
4790fcf5ef2aSThomas Huth case OPC2_32_BO_CMPSWAP_W_PREINC:
4791fcf5ef2aSThomas Huth tcg_gen_addi_tl(cpu_gpr_a[r2], cpu_gpr_a[r2], off10);
4792fcf5ef2aSThomas Huth gen_cmpswap(ctx, r1, cpu_gpr_a[r2]);
4793fcf5ef2aSThomas Huth break;
4794fcf5ef2aSThomas Huth case OPC2_32_BO_SWAPMSK_W_SHORTOFF:
4795fcf5ef2aSThomas Huth tcg_gen_addi_tl(temp, cpu_gpr_a[r2], off10);
4796fcf5ef2aSThomas Huth gen_swapmsk(ctx, r1, temp);
4797fcf5ef2aSThomas Huth break;
4798fcf5ef2aSThomas Huth case OPC2_32_BO_SWAPMSK_W_POSTINC:
4799fcf5ef2aSThomas Huth gen_swapmsk(ctx, r1, cpu_gpr_a[r2]);
4800fcf5ef2aSThomas Huth tcg_gen_addi_tl(cpu_gpr_a[r2], cpu_gpr_a[r2], off10);
4801fcf5ef2aSThomas Huth break;
4802fcf5ef2aSThomas Huth case OPC2_32_BO_SWAPMSK_W_PREINC:
4803fcf5ef2aSThomas Huth tcg_gen_addi_tl(cpu_gpr_a[r2], cpu_gpr_a[r2], off10);
4804fcf5ef2aSThomas Huth gen_swapmsk(ctx, r1, cpu_gpr_a[r2]);
4805fcf5ef2aSThomas Huth break;
4806fcf5ef2aSThomas Huth default:
4807fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
4808fcf5ef2aSThomas Huth }
4809fcf5ef2aSThomas Huth }
4810fcf5ef2aSThomas Huth
decode_bo_addrmode_ldmst_bitreverse_circular(DisasContext * ctx)48112db92a0cSBastian Koppelmann static void decode_bo_addrmode_ldmst_bitreverse_circular(DisasContext *ctx)
4812fcf5ef2aSThomas Huth {
4813fcf5ef2aSThomas Huth uint32_t op2;
4814fcf5ef2aSThomas Huth uint32_t off10;
4815fcf5ef2aSThomas Huth int r1, r2;
48165c48ad75SRichard Henderson TCGv temp, temp2, t_off10;
4817fcf5ef2aSThomas Huth
4818fcf5ef2aSThomas Huth r1 = MASK_OP_BO_S1D(ctx->opcode);
4819fcf5ef2aSThomas Huth r2 = MASK_OP_BO_S2(ctx->opcode);
4820fcf5ef2aSThomas Huth off10 = MASK_OP_BO_OFF10_SEXT(ctx->opcode);
4821fcf5ef2aSThomas Huth op2 = MASK_OP_BO_OP2(ctx->opcode);
4822fcf5ef2aSThomas Huth
4823fcf5ef2aSThomas Huth temp = tcg_temp_new();
4824fcf5ef2aSThomas Huth temp2 = tcg_temp_new();
48255c48ad75SRichard Henderson t_off10 = tcg_constant_i32(off10);
4826fcf5ef2aSThomas Huth CHECK_REG_PAIR(r2);
4827fcf5ef2aSThomas Huth tcg_gen_ext16u_tl(temp, cpu_gpr_a[r2+1]);
4828fcf5ef2aSThomas Huth tcg_gen_add_tl(temp2, cpu_gpr_a[r2], temp);
4829fcf5ef2aSThomas Huth
4830fcf5ef2aSThomas Huth switch (op2) {
4831fcf5ef2aSThomas Huth case OPC2_32_BO_LDMST_BR:
4832fcf5ef2aSThomas Huth gen_ldmst(ctx, r1, temp2);
4833fcf5ef2aSThomas Huth gen_helper_br_update(cpu_gpr_a[r2+1], cpu_gpr_a[r2+1]);
4834fcf5ef2aSThomas Huth break;
4835fcf5ef2aSThomas Huth case OPC2_32_BO_LDMST_CIRC:
4836fcf5ef2aSThomas Huth gen_ldmst(ctx, r1, temp2);
48375c48ad75SRichard Henderson gen_helper_circ_update(cpu_gpr_a[r2+1], cpu_gpr_a[r2+1], t_off10);
4838fcf5ef2aSThomas Huth break;
4839fcf5ef2aSThomas Huth case OPC2_32_BO_SWAP_W_BR:
4840fcf5ef2aSThomas Huth gen_swap(ctx, r1, temp2);
4841fcf5ef2aSThomas Huth gen_helper_br_update(cpu_gpr_a[r2+1], cpu_gpr_a[r2+1]);
4842fcf5ef2aSThomas Huth break;
4843fcf5ef2aSThomas Huth case OPC2_32_BO_SWAP_W_CIRC:
4844fcf5ef2aSThomas Huth gen_swap(ctx, r1, temp2);
48455c48ad75SRichard Henderson gen_helper_circ_update(cpu_gpr_a[r2+1], cpu_gpr_a[r2+1], t_off10);
4846fcf5ef2aSThomas Huth break;
4847fcf5ef2aSThomas Huth case OPC2_32_BO_CMPSWAP_W_BR:
4848fcf5ef2aSThomas Huth gen_cmpswap(ctx, r1, temp2);
4849fcf5ef2aSThomas Huth gen_helper_br_update(cpu_gpr_a[r2+1], cpu_gpr_a[r2+1]);
4850fcf5ef2aSThomas Huth break;
4851fcf5ef2aSThomas Huth case OPC2_32_BO_CMPSWAP_W_CIRC:
4852fcf5ef2aSThomas Huth gen_cmpswap(ctx, r1, temp2);
48535c48ad75SRichard Henderson gen_helper_circ_update(cpu_gpr_a[r2+1], cpu_gpr_a[r2+1], t_off10);
4854fcf5ef2aSThomas Huth break;
4855fcf5ef2aSThomas Huth case OPC2_32_BO_SWAPMSK_W_BR:
4856fcf5ef2aSThomas Huth gen_swapmsk(ctx, r1, temp2);
4857fcf5ef2aSThomas Huth gen_helper_br_update(cpu_gpr_a[r2+1], cpu_gpr_a[r2+1]);
4858fcf5ef2aSThomas Huth break;
4859fcf5ef2aSThomas Huth case OPC2_32_BO_SWAPMSK_W_CIRC:
4860fcf5ef2aSThomas Huth gen_swapmsk(ctx, r1, temp2);
48615c48ad75SRichard Henderson gen_helper_circ_update(cpu_gpr_a[r2+1], cpu_gpr_a[r2+1], t_off10);
4862fcf5ef2aSThomas Huth break;
4863fcf5ef2aSThomas Huth default:
4864fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
4865fcf5ef2aSThomas Huth }
4866fcf5ef2aSThomas Huth }
4867fcf5ef2aSThomas Huth
decode_bol_opc(DisasContext * ctx,int32_t op1)48682db92a0cSBastian Koppelmann static void decode_bol_opc(DisasContext *ctx, int32_t op1)
4869fcf5ef2aSThomas Huth {
4870fcf5ef2aSThomas Huth int r1, r2;
4871fcf5ef2aSThomas Huth int32_t address;
4872fcf5ef2aSThomas Huth TCGv temp;
4873fcf5ef2aSThomas Huth
4874fcf5ef2aSThomas Huth r1 = MASK_OP_BOL_S1D(ctx->opcode);
4875fcf5ef2aSThomas Huth r2 = MASK_OP_BOL_S2(ctx->opcode);
4876fcf5ef2aSThomas Huth address = MASK_OP_BOL_OFF16_SEXT(ctx->opcode);
4877fcf5ef2aSThomas Huth
4878fcf5ef2aSThomas Huth switch (op1) {
4879fcf5ef2aSThomas Huth case OPC1_32_BOL_LD_A_LONGOFF:
4880fcf5ef2aSThomas Huth temp = tcg_temp_new();
4881fcf5ef2aSThomas Huth tcg_gen_addi_tl(temp, cpu_gpr_a[r2], address);
4882fcf5ef2aSThomas Huth tcg_gen_qemu_ld_tl(cpu_gpr_a[r1], temp, ctx->mem_idx, MO_LEUL);
4883fcf5ef2aSThomas Huth break;
4884fcf5ef2aSThomas Huth case OPC1_32_BOL_LD_W_LONGOFF:
4885fcf5ef2aSThomas Huth temp = tcg_temp_new();
4886fcf5ef2aSThomas Huth tcg_gen_addi_tl(temp, cpu_gpr_a[r2], address);
4887fcf5ef2aSThomas Huth tcg_gen_qemu_ld_tl(cpu_gpr_d[r1], temp, ctx->mem_idx, MO_LEUL);
4888fcf5ef2aSThomas Huth break;
4889fcf5ef2aSThomas Huth case OPC1_32_BOL_LEA_LONGOFF:
4890fcf5ef2aSThomas Huth tcg_gen_addi_tl(cpu_gpr_a[r1], cpu_gpr_a[r2], address);
4891fcf5ef2aSThomas Huth break;
4892fcf5ef2aSThomas Huth case OPC1_32_BOL_ST_A_LONGOFF:
489344ee3bafSBastian Koppelmann if (has_feature(ctx, TRICORE_FEATURE_16)) {
4894fcf5ef2aSThomas Huth gen_offset_st(ctx, cpu_gpr_a[r1], cpu_gpr_a[r2], address, MO_LEUL);
4895fcf5ef2aSThomas Huth } else {
4896fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
4897fcf5ef2aSThomas Huth }
4898fcf5ef2aSThomas Huth break;
4899fcf5ef2aSThomas Huth case OPC1_32_BOL_ST_W_LONGOFF:
4900fcf5ef2aSThomas Huth gen_offset_st(ctx, cpu_gpr_d[r1], cpu_gpr_a[r2], address, MO_LEUL);
4901fcf5ef2aSThomas Huth break;
4902fcf5ef2aSThomas Huth case OPC1_32_BOL_LD_B_LONGOFF:
490344ee3bafSBastian Koppelmann if (has_feature(ctx, TRICORE_FEATURE_16)) {
4904fcf5ef2aSThomas Huth gen_offset_ld(ctx, cpu_gpr_d[r1], cpu_gpr_a[r2], address, MO_SB);
4905fcf5ef2aSThomas Huth } else {
4906fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
4907fcf5ef2aSThomas Huth }
4908fcf5ef2aSThomas Huth break;
4909fcf5ef2aSThomas Huth case OPC1_32_BOL_LD_BU_LONGOFF:
491044ee3bafSBastian Koppelmann if (has_feature(ctx, TRICORE_FEATURE_16)) {
4911fcf5ef2aSThomas Huth gen_offset_ld(ctx, cpu_gpr_d[r1], cpu_gpr_a[r2], address, MO_UB);
4912fcf5ef2aSThomas Huth } else {
4913fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
4914fcf5ef2aSThomas Huth }
4915fcf5ef2aSThomas Huth break;
4916fcf5ef2aSThomas Huth case OPC1_32_BOL_LD_H_LONGOFF:
491744ee3bafSBastian Koppelmann if (has_feature(ctx, TRICORE_FEATURE_16)) {
4918fcf5ef2aSThomas Huth gen_offset_ld(ctx, cpu_gpr_d[r1], cpu_gpr_a[r2], address, MO_LESW);
4919fcf5ef2aSThomas Huth } else {
4920fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
4921fcf5ef2aSThomas Huth }
4922fcf5ef2aSThomas Huth break;
4923fcf5ef2aSThomas Huth case OPC1_32_BOL_LD_HU_LONGOFF:
492444ee3bafSBastian Koppelmann if (has_feature(ctx, TRICORE_FEATURE_16)) {
4925fcf5ef2aSThomas Huth gen_offset_ld(ctx, cpu_gpr_d[r1], cpu_gpr_a[r2], address, MO_LEUW);
4926fcf5ef2aSThomas Huth } else {
4927fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
4928fcf5ef2aSThomas Huth }
4929fcf5ef2aSThomas Huth break;
4930fcf5ef2aSThomas Huth case OPC1_32_BOL_ST_B_LONGOFF:
493144ee3bafSBastian Koppelmann if (has_feature(ctx, TRICORE_FEATURE_16)) {
4932fcf5ef2aSThomas Huth gen_offset_st(ctx, cpu_gpr_d[r1], cpu_gpr_a[r2], address, MO_SB);
4933fcf5ef2aSThomas Huth } else {
4934fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
4935fcf5ef2aSThomas Huth }
4936fcf5ef2aSThomas Huth break;
4937fcf5ef2aSThomas Huth case OPC1_32_BOL_ST_H_LONGOFF:
493844ee3bafSBastian Koppelmann if (has_feature(ctx, TRICORE_FEATURE_16)) {
4939fcf5ef2aSThomas Huth gen_offset_st(ctx, cpu_gpr_d[r1], cpu_gpr_a[r2], address, MO_LESW);
4940fcf5ef2aSThomas Huth } else {
4941fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
4942fcf5ef2aSThomas Huth }
4943fcf5ef2aSThomas Huth break;
4944fcf5ef2aSThomas Huth default:
4945fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
4946fcf5ef2aSThomas Huth }
4947fcf5ef2aSThomas Huth }
4948fcf5ef2aSThomas Huth
4949fcf5ef2aSThomas Huth /* RC format */
decode_rc_logical_shift(DisasContext * ctx)49502db92a0cSBastian Koppelmann static void decode_rc_logical_shift(DisasContext *ctx)
4951fcf5ef2aSThomas Huth {
4952fcf5ef2aSThomas Huth uint32_t op2;
4953fcf5ef2aSThomas Huth int r1, r2;
4954fcf5ef2aSThomas Huth int32_t const9;
4955fcf5ef2aSThomas Huth TCGv temp;
4956fcf5ef2aSThomas Huth
4957fcf5ef2aSThomas Huth r2 = MASK_OP_RC_D(ctx->opcode);
4958fcf5ef2aSThomas Huth r1 = MASK_OP_RC_S1(ctx->opcode);
4959fcf5ef2aSThomas Huth const9 = MASK_OP_RC_CONST9(ctx->opcode);
4960fcf5ef2aSThomas Huth op2 = MASK_OP_RC_OP2(ctx->opcode);
4961fcf5ef2aSThomas Huth
4962fcf5ef2aSThomas Huth switch (op2) {
4963fcf5ef2aSThomas Huth case OPC2_32_RC_AND:
4964fcf5ef2aSThomas Huth tcg_gen_andi_tl(cpu_gpr_d[r2], cpu_gpr_d[r1], const9);
4965fcf5ef2aSThomas Huth break;
4966fcf5ef2aSThomas Huth case OPC2_32_RC_ANDN:
4967fcf5ef2aSThomas Huth tcg_gen_andi_tl(cpu_gpr_d[r2], cpu_gpr_d[r1], ~const9);
4968fcf5ef2aSThomas Huth break;
4969fcf5ef2aSThomas Huth case OPC2_32_RC_NAND:
497081b8056aSPhilippe Mathieu-Daudé temp = tcg_temp_new();
4971fcf5ef2aSThomas Huth tcg_gen_movi_tl(temp, const9);
4972fcf5ef2aSThomas Huth tcg_gen_nand_tl(cpu_gpr_d[r2], cpu_gpr_d[r1], temp);
4973fcf5ef2aSThomas Huth break;
4974fcf5ef2aSThomas Huth case OPC2_32_RC_NOR:
497581b8056aSPhilippe Mathieu-Daudé temp = tcg_temp_new();
4976fcf5ef2aSThomas Huth tcg_gen_movi_tl(temp, const9);
4977fcf5ef2aSThomas Huth tcg_gen_nor_tl(cpu_gpr_d[r2], cpu_gpr_d[r1], temp);
4978fcf5ef2aSThomas Huth break;
4979fcf5ef2aSThomas Huth case OPC2_32_RC_OR:
4980fcf5ef2aSThomas Huth tcg_gen_ori_tl(cpu_gpr_d[r2], cpu_gpr_d[r1], const9);
4981fcf5ef2aSThomas Huth break;
4982fcf5ef2aSThomas Huth case OPC2_32_RC_ORN:
4983fcf5ef2aSThomas Huth tcg_gen_ori_tl(cpu_gpr_d[r2], cpu_gpr_d[r1], ~const9);
4984fcf5ef2aSThomas Huth break;
4985fcf5ef2aSThomas Huth case OPC2_32_RC_SH:
4986fcf5ef2aSThomas Huth const9 = sextract32(const9, 0, 6);
4987fcf5ef2aSThomas Huth gen_shi(cpu_gpr_d[r2], cpu_gpr_d[r1], const9);
4988fcf5ef2aSThomas Huth break;
4989fcf5ef2aSThomas Huth case OPC2_32_RC_SH_H:
4990fcf5ef2aSThomas Huth const9 = sextract32(const9, 0, 5);
4991fcf5ef2aSThomas Huth gen_sh_hi(cpu_gpr_d[r2], cpu_gpr_d[r1], const9);
4992fcf5ef2aSThomas Huth break;
4993fcf5ef2aSThomas Huth case OPC2_32_RC_SHA:
4994fcf5ef2aSThomas Huth const9 = sextract32(const9, 0, 6);
4995fcf5ef2aSThomas Huth gen_shaci(cpu_gpr_d[r2], cpu_gpr_d[r1], const9);
4996fcf5ef2aSThomas Huth break;
4997fcf5ef2aSThomas Huth case OPC2_32_RC_SHA_H:
4998fcf5ef2aSThomas Huth const9 = sextract32(const9, 0, 5);
4999fcf5ef2aSThomas Huth gen_sha_hi(cpu_gpr_d[r2], cpu_gpr_d[r1], const9);
5000fcf5ef2aSThomas Huth break;
5001fcf5ef2aSThomas Huth case OPC2_32_RC_SHAS:
5002fcf5ef2aSThomas Huth gen_shasi(cpu_gpr_d[r2], cpu_gpr_d[r1], const9);
5003fcf5ef2aSThomas Huth break;
5004fcf5ef2aSThomas Huth case OPC2_32_RC_XNOR:
5005fcf5ef2aSThomas Huth tcg_gen_xori_tl(cpu_gpr_d[r2], cpu_gpr_d[r1], const9);
5006fcf5ef2aSThomas Huth tcg_gen_not_tl(cpu_gpr_d[r2], cpu_gpr_d[r2]);
5007fcf5ef2aSThomas Huth break;
5008fcf5ef2aSThomas Huth case OPC2_32_RC_XOR:
5009fcf5ef2aSThomas Huth tcg_gen_xori_tl(cpu_gpr_d[r2], cpu_gpr_d[r1], const9);
5010fcf5ef2aSThomas Huth break;
50114e3377bbSBastian Koppelmann case OPC2_32_RC_SHUFFLE:
50124e3377bbSBastian Koppelmann if (has_feature(ctx, TRICORE_FEATURE_162)) {
501381b8056aSPhilippe Mathieu-Daudé temp = tcg_constant_i32(const9);
50144e3377bbSBastian Koppelmann gen_helper_shuffle(cpu_gpr_d[r2], cpu_gpr_d[r1], temp);
50154e3377bbSBastian Koppelmann } else {
50164e3377bbSBastian Koppelmann generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
50174e3377bbSBastian Koppelmann }
50184e3377bbSBastian Koppelmann break;
5019fcf5ef2aSThomas Huth default:
5020fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
5021fcf5ef2aSThomas Huth }
5022fcf5ef2aSThomas Huth }
5023fcf5ef2aSThomas Huth
decode_rc_accumulator(DisasContext * ctx)50242db92a0cSBastian Koppelmann static void decode_rc_accumulator(DisasContext *ctx)
5025fcf5ef2aSThomas Huth {
5026fcf5ef2aSThomas Huth uint32_t op2;
5027fcf5ef2aSThomas Huth int r1, r2;
5028fcf5ef2aSThomas Huth int16_t const9;
5029fcf5ef2aSThomas Huth
5030fcf5ef2aSThomas Huth TCGv temp;
5031fcf5ef2aSThomas Huth
5032fcf5ef2aSThomas Huth r2 = MASK_OP_RC_D(ctx->opcode);
5033fcf5ef2aSThomas Huth r1 = MASK_OP_RC_S1(ctx->opcode);
5034fcf5ef2aSThomas Huth const9 = MASK_OP_RC_CONST9_SEXT(ctx->opcode);
5035fcf5ef2aSThomas Huth
5036fcf5ef2aSThomas Huth op2 = MASK_OP_RC_OP2(ctx->opcode);
5037fcf5ef2aSThomas Huth
5038fcf5ef2aSThomas Huth temp = tcg_temp_new();
5039fcf5ef2aSThomas Huth
5040fcf5ef2aSThomas Huth switch (op2) {
5041fcf5ef2aSThomas Huth case OPC2_32_RC_ABSDIF:
5042fcf5ef2aSThomas Huth gen_absdifi(cpu_gpr_d[r2], cpu_gpr_d[r1], const9);
5043fcf5ef2aSThomas Huth break;
5044fcf5ef2aSThomas Huth case OPC2_32_RC_ABSDIFS:
5045fcf5ef2aSThomas Huth gen_absdifsi(cpu_gpr_d[r2], cpu_gpr_d[r1], const9);
5046fcf5ef2aSThomas Huth break;
5047fcf5ef2aSThomas Huth case OPC2_32_RC_ADD:
5048fcf5ef2aSThomas Huth gen_addi_d(cpu_gpr_d[r2], cpu_gpr_d[r1], const9);
5049fcf5ef2aSThomas Huth break;
5050fcf5ef2aSThomas Huth case OPC2_32_RC_ADDC:
5051fcf5ef2aSThomas Huth gen_addci_CC(cpu_gpr_d[r2], cpu_gpr_d[r1], const9);
5052fcf5ef2aSThomas Huth break;
5053fcf5ef2aSThomas Huth case OPC2_32_RC_ADDS:
5054fcf5ef2aSThomas Huth gen_addsi(cpu_gpr_d[r2], cpu_gpr_d[r1], const9);
5055fcf5ef2aSThomas Huth break;
5056fcf5ef2aSThomas Huth case OPC2_32_RC_ADDS_U:
5057fcf5ef2aSThomas Huth gen_addsui(cpu_gpr_d[r2], cpu_gpr_d[r1], const9);
5058fcf5ef2aSThomas Huth break;
5059fcf5ef2aSThomas Huth case OPC2_32_RC_ADDX:
5060fcf5ef2aSThomas Huth gen_addi_CC(cpu_gpr_d[r2], cpu_gpr_d[r1], const9);
5061fcf5ef2aSThomas Huth break;
5062fcf5ef2aSThomas Huth case OPC2_32_RC_AND_EQ:
5063fcf5ef2aSThomas Huth gen_accumulating_condi(TCG_COND_EQ, cpu_gpr_d[r2], cpu_gpr_d[r1],
5064fcf5ef2aSThomas Huth const9, &tcg_gen_and_tl);
5065fcf5ef2aSThomas Huth break;
5066fcf5ef2aSThomas Huth case OPC2_32_RC_AND_GE:
5067fcf5ef2aSThomas Huth gen_accumulating_condi(TCG_COND_GE, cpu_gpr_d[r2], cpu_gpr_d[r1],
5068fcf5ef2aSThomas Huth const9, &tcg_gen_and_tl);
5069fcf5ef2aSThomas Huth break;
5070fcf5ef2aSThomas Huth case OPC2_32_RC_AND_GE_U:
5071fcf5ef2aSThomas Huth const9 = MASK_OP_RC_CONST9(ctx->opcode);
5072fcf5ef2aSThomas Huth gen_accumulating_condi(TCG_COND_GEU, cpu_gpr_d[r2], cpu_gpr_d[r1],
5073fcf5ef2aSThomas Huth const9, &tcg_gen_and_tl);
5074fcf5ef2aSThomas Huth break;
5075fcf5ef2aSThomas Huth case OPC2_32_RC_AND_LT:
5076fcf5ef2aSThomas Huth gen_accumulating_condi(TCG_COND_LT, cpu_gpr_d[r2], cpu_gpr_d[r1],
5077fcf5ef2aSThomas Huth const9, &tcg_gen_and_tl);
5078fcf5ef2aSThomas Huth break;
5079fcf5ef2aSThomas Huth case OPC2_32_RC_AND_LT_U:
5080fcf5ef2aSThomas Huth const9 = MASK_OP_RC_CONST9(ctx->opcode);
5081fcf5ef2aSThomas Huth gen_accumulating_condi(TCG_COND_LTU, cpu_gpr_d[r2], cpu_gpr_d[r1],
5082fcf5ef2aSThomas Huth const9, &tcg_gen_and_tl);
5083fcf5ef2aSThomas Huth break;
5084fcf5ef2aSThomas Huth case OPC2_32_RC_AND_NE:
5085fcf5ef2aSThomas Huth gen_accumulating_condi(TCG_COND_NE, cpu_gpr_d[r2], cpu_gpr_d[r1],
5086fcf5ef2aSThomas Huth const9, &tcg_gen_and_tl);
5087fcf5ef2aSThomas Huth break;
5088fcf5ef2aSThomas Huth case OPC2_32_RC_EQ:
5089fcf5ef2aSThomas Huth tcg_gen_setcondi_tl(TCG_COND_EQ, cpu_gpr_d[r2], cpu_gpr_d[r1], const9);
5090fcf5ef2aSThomas Huth break;
5091fcf5ef2aSThomas Huth case OPC2_32_RC_EQANY_B:
5092fcf5ef2aSThomas Huth gen_eqany_bi(cpu_gpr_d[r2], cpu_gpr_d[r1], const9);
5093fcf5ef2aSThomas Huth break;
5094fcf5ef2aSThomas Huth case OPC2_32_RC_EQANY_H:
5095fcf5ef2aSThomas Huth gen_eqany_hi(cpu_gpr_d[r2], cpu_gpr_d[r1], const9);
5096fcf5ef2aSThomas Huth break;
5097fcf5ef2aSThomas Huth case OPC2_32_RC_GE:
5098fcf5ef2aSThomas Huth tcg_gen_setcondi_tl(TCG_COND_GE, cpu_gpr_d[r2], cpu_gpr_d[r1], const9);
5099fcf5ef2aSThomas Huth break;
5100fcf5ef2aSThomas Huth case OPC2_32_RC_GE_U:
5101fcf5ef2aSThomas Huth const9 = MASK_OP_RC_CONST9(ctx->opcode);
5102fcf5ef2aSThomas Huth tcg_gen_setcondi_tl(TCG_COND_GEU, cpu_gpr_d[r2], cpu_gpr_d[r1], const9);
5103fcf5ef2aSThomas Huth break;
5104fcf5ef2aSThomas Huth case OPC2_32_RC_LT:
5105fcf5ef2aSThomas Huth tcg_gen_setcondi_tl(TCG_COND_LT, cpu_gpr_d[r2], cpu_gpr_d[r1], const9);
5106fcf5ef2aSThomas Huth break;
5107fcf5ef2aSThomas Huth case OPC2_32_RC_LT_U:
5108fcf5ef2aSThomas Huth const9 = MASK_OP_RC_CONST9(ctx->opcode);
5109fcf5ef2aSThomas Huth tcg_gen_setcondi_tl(TCG_COND_LTU, cpu_gpr_d[r2], cpu_gpr_d[r1], const9);
5110fcf5ef2aSThomas Huth break;
5111fcf5ef2aSThomas Huth case OPC2_32_RC_MAX:
5112fcf5ef2aSThomas Huth tcg_gen_movi_tl(temp, const9);
5113fcf5ef2aSThomas Huth tcg_gen_movcond_tl(TCG_COND_GT, cpu_gpr_d[r2], cpu_gpr_d[r1], temp,
5114fcf5ef2aSThomas Huth cpu_gpr_d[r1], temp);
5115fcf5ef2aSThomas Huth break;
5116fcf5ef2aSThomas Huth case OPC2_32_RC_MAX_U:
5117fcf5ef2aSThomas Huth tcg_gen_movi_tl(temp, MASK_OP_RC_CONST9(ctx->opcode));
5118fcf5ef2aSThomas Huth tcg_gen_movcond_tl(TCG_COND_GTU, cpu_gpr_d[r2], cpu_gpr_d[r1], temp,
5119fcf5ef2aSThomas Huth cpu_gpr_d[r1], temp);
5120fcf5ef2aSThomas Huth break;
5121fcf5ef2aSThomas Huth case OPC2_32_RC_MIN:
5122fcf5ef2aSThomas Huth tcg_gen_movi_tl(temp, const9);
5123fcf5ef2aSThomas Huth tcg_gen_movcond_tl(TCG_COND_LT, cpu_gpr_d[r2], cpu_gpr_d[r1], temp,
5124fcf5ef2aSThomas Huth cpu_gpr_d[r1], temp);
5125fcf5ef2aSThomas Huth break;
5126fcf5ef2aSThomas Huth case OPC2_32_RC_MIN_U:
5127fcf5ef2aSThomas Huth tcg_gen_movi_tl(temp, MASK_OP_RC_CONST9(ctx->opcode));
5128fcf5ef2aSThomas Huth tcg_gen_movcond_tl(TCG_COND_LTU, cpu_gpr_d[r2], cpu_gpr_d[r1], temp,
5129fcf5ef2aSThomas Huth cpu_gpr_d[r1], temp);
5130fcf5ef2aSThomas Huth break;
5131fcf5ef2aSThomas Huth case OPC2_32_RC_NE:
5132fcf5ef2aSThomas Huth tcg_gen_setcondi_tl(TCG_COND_NE, cpu_gpr_d[r2], cpu_gpr_d[r1], const9);
5133fcf5ef2aSThomas Huth break;
5134fcf5ef2aSThomas Huth case OPC2_32_RC_OR_EQ:
5135fcf5ef2aSThomas Huth gen_accumulating_condi(TCG_COND_EQ, cpu_gpr_d[r2], cpu_gpr_d[r1],
5136fcf5ef2aSThomas Huth const9, &tcg_gen_or_tl);
5137fcf5ef2aSThomas Huth break;
5138fcf5ef2aSThomas Huth case OPC2_32_RC_OR_GE:
5139fcf5ef2aSThomas Huth gen_accumulating_condi(TCG_COND_GE, cpu_gpr_d[r2], cpu_gpr_d[r1],
5140fcf5ef2aSThomas Huth const9, &tcg_gen_or_tl);
5141fcf5ef2aSThomas Huth break;
5142fcf5ef2aSThomas Huth case OPC2_32_RC_OR_GE_U:
5143fcf5ef2aSThomas Huth const9 = MASK_OP_RC_CONST9(ctx->opcode);
5144fcf5ef2aSThomas Huth gen_accumulating_condi(TCG_COND_GEU, cpu_gpr_d[r2], cpu_gpr_d[r1],
5145fcf5ef2aSThomas Huth const9, &tcg_gen_or_tl);
5146fcf5ef2aSThomas Huth break;
5147fcf5ef2aSThomas Huth case OPC2_32_RC_OR_LT:
5148fcf5ef2aSThomas Huth gen_accumulating_condi(TCG_COND_LT, cpu_gpr_d[r2], cpu_gpr_d[r1],
5149fcf5ef2aSThomas Huth const9, &tcg_gen_or_tl);
5150fcf5ef2aSThomas Huth break;
5151fcf5ef2aSThomas Huth case OPC2_32_RC_OR_LT_U:
5152fcf5ef2aSThomas Huth const9 = MASK_OP_RC_CONST9(ctx->opcode);
5153fcf5ef2aSThomas Huth gen_accumulating_condi(TCG_COND_LTU, cpu_gpr_d[r2], cpu_gpr_d[r1],
5154fcf5ef2aSThomas Huth const9, &tcg_gen_or_tl);
5155fcf5ef2aSThomas Huth break;
5156fcf5ef2aSThomas Huth case OPC2_32_RC_OR_NE:
5157fcf5ef2aSThomas Huth gen_accumulating_condi(TCG_COND_NE, cpu_gpr_d[r2], cpu_gpr_d[r1],
5158fcf5ef2aSThomas Huth const9, &tcg_gen_or_tl);
5159fcf5ef2aSThomas Huth break;
5160fcf5ef2aSThomas Huth case OPC2_32_RC_RSUB:
5161fcf5ef2aSThomas Huth tcg_gen_movi_tl(temp, const9);
5162fcf5ef2aSThomas Huth gen_sub_d(cpu_gpr_d[r2], temp, cpu_gpr_d[r1]);
5163fcf5ef2aSThomas Huth break;
5164fcf5ef2aSThomas Huth case OPC2_32_RC_RSUBS:
5165fcf5ef2aSThomas Huth tcg_gen_movi_tl(temp, const9);
5166fcf5ef2aSThomas Huth gen_subs(cpu_gpr_d[r2], temp, cpu_gpr_d[r1]);
5167fcf5ef2aSThomas Huth break;
5168fcf5ef2aSThomas Huth case OPC2_32_RC_RSUBS_U:
5169fcf5ef2aSThomas Huth tcg_gen_movi_tl(temp, const9);
5170fcf5ef2aSThomas Huth gen_subsu(cpu_gpr_d[r2], temp, cpu_gpr_d[r1]);
5171fcf5ef2aSThomas Huth break;
5172fcf5ef2aSThomas Huth case OPC2_32_RC_SH_EQ:
5173fcf5ef2aSThomas Huth gen_sh_condi(TCG_COND_EQ, cpu_gpr_d[r2], cpu_gpr_d[r1], const9);
5174fcf5ef2aSThomas Huth break;
5175fcf5ef2aSThomas Huth case OPC2_32_RC_SH_GE:
5176fcf5ef2aSThomas Huth gen_sh_condi(TCG_COND_GE, cpu_gpr_d[r2], cpu_gpr_d[r1], const9);
5177fcf5ef2aSThomas Huth break;
5178fcf5ef2aSThomas Huth case OPC2_32_RC_SH_GE_U:
5179fcf5ef2aSThomas Huth const9 = MASK_OP_RC_CONST9(ctx->opcode);
5180fcf5ef2aSThomas Huth gen_sh_condi(TCG_COND_GEU, cpu_gpr_d[r2], cpu_gpr_d[r1], const9);
5181fcf5ef2aSThomas Huth break;
5182fcf5ef2aSThomas Huth case OPC2_32_RC_SH_LT:
5183fcf5ef2aSThomas Huth gen_sh_condi(TCG_COND_LT, cpu_gpr_d[r2], cpu_gpr_d[r1], const9);
5184fcf5ef2aSThomas Huth break;
5185fcf5ef2aSThomas Huth case OPC2_32_RC_SH_LT_U:
5186fcf5ef2aSThomas Huth const9 = MASK_OP_RC_CONST9(ctx->opcode);
5187fcf5ef2aSThomas Huth gen_sh_condi(TCG_COND_LTU, cpu_gpr_d[r2], cpu_gpr_d[r1], const9);
5188fcf5ef2aSThomas Huth break;
5189fcf5ef2aSThomas Huth case OPC2_32_RC_SH_NE:
5190fcf5ef2aSThomas Huth gen_sh_condi(TCG_COND_NE, cpu_gpr_d[r2], cpu_gpr_d[r1], const9);
5191fcf5ef2aSThomas Huth break;
5192fcf5ef2aSThomas Huth case OPC2_32_RC_XOR_EQ:
5193fcf5ef2aSThomas Huth gen_accumulating_condi(TCG_COND_EQ, cpu_gpr_d[r2], cpu_gpr_d[r1],
5194fcf5ef2aSThomas Huth const9, &tcg_gen_xor_tl);
5195fcf5ef2aSThomas Huth break;
5196fcf5ef2aSThomas Huth case OPC2_32_RC_XOR_GE:
5197fcf5ef2aSThomas Huth gen_accumulating_condi(TCG_COND_GE, cpu_gpr_d[r2], cpu_gpr_d[r1],
5198fcf5ef2aSThomas Huth const9, &tcg_gen_xor_tl);
5199fcf5ef2aSThomas Huth break;
5200fcf5ef2aSThomas Huth case OPC2_32_RC_XOR_GE_U:
5201fcf5ef2aSThomas Huth const9 = MASK_OP_RC_CONST9(ctx->opcode);
5202fcf5ef2aSThomas Huth gen_accumulating_condi(TCG_COND_GEU, cpu_gpr_d[r2], cpu_gpr_d[r1],
5203fcf5ef2aSThomas Huth const9, &tcg_gen_xor_tl);
5204fcf5ef2aSThomas Huth break;
5205fcf5ef2aSThomas Huth case OPC2_32_RC_XOR_LT:
5206fcf5ef2aSThomas Huth gen_accumulating_condi(TCG_COND_LT, cpu_gpr_d[r2], cpu_gpr_d[r1],
5207fcf5ef2aSThomas Huth const9, &tcg_gen_xor_tl);
5208fcf5ef2aSThomas Huth break;
5209fcf5ef2aSThomas Huth case OPC2_32_RC_XOR_LT_U:
5210fcf5ef2aSThomas Huth const9 = MASK_OP_RC_CONST9(ctx->opcode);
5211fcf5ef2aSThomas Huth gen_accumulating_condi(TCG_COND_LTU, cpu_gpr_d[r2], cpu_gpr_d[r1],
5212fcf5ef2aSThomas Huth const9, &tcg_gen_xor_tl);
5213fcf5ef2aSThomas Huth break;
5214fcf5ef2aSThomas Huth case OPC2_32_RC_XOR_NE:
5215fcf5ef2aSThomas Huth gen_accumulating_condi(TCG_COND_NE, cpu_gpr_d[r2], cpu_gpr_d[r1],
5216fcf5ef2aSThomas Huth const9, &tcg_gen_xor_tl);
5217fcf5ef2aSThomas Huth break;
5218fcf5ef2aSThomas Huth default:
5219fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
5220fcf5ef2aSThomas Huth }
5221fcf5ef2aSThomas Huth }
5222fcf5ef2aSThomas Huth
decode_rc_serviceroutine(DisasContext * ctx)52232db92a0cSBastian Koppelmann static void decode_rc_serviceroutine(DisasContext *ctx)
5224fcf5ef2aSThomas Huth {
5225fcf5ef2aSThomas Huth uint32_t op2;
5226fcf5ef2aSThomas Huth uint32_t const9;
5227fcf5ef2aSThomas Huth
5228fcf5ef2aSThomas Huth op2 = MASK_OP_RC_OP2(ctx->opcode);
5229fcf5ef2aSThomas Huth const9 = MASK_OP_RC_CONST9(ctx->opcode);
5230fcf5ef2aSThomas Huth
5231fcf5ef2aSThomas Huth switch (op2) {
5232fcf5ef2aSThomas Huth case OPC2_32_RC_BISR:
523357b9c589SBastian Koppelmann if (ctx->priv == TRICORE_PRIV_SM) {
5234fcf5ef2aSThomas Huth gen_helper_1arg(bisr, const9);
523557b9c589SBastian Koppelmann } else {
523657b9c589SBastian Koppelmann generate_trap(ctx, TRAPC_PROT, TIN1_PRIV);
523757b9c589SBastian Koppelmann }
5238fcf5ef2aSThomas Huth break;
5239fcf5ef2aSThomas Huth case OPC2_32_RC_SYSCALL:
52403b5d136dSBastian Koppelmann generate_trap(ctx, TRAPC_SYSCALL, const9 & 0xff);
5241fcf5ef2aSThomas Huth break;
5242fcf5ef2aSThomas Huth default:
5243fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
5244fcf5ef2aSThomas Huth }
5245fcf5ef2aSThomas Huth }
5246fcf5ef2aSThomas Huth
decode_rc_mul(DisasContext * ctx)52472db92a0cSBastian Koppelmann static void decode_rc_mul(DisasContext *ctx)
5248fcf5ef2aSThomas Huth {
5249fcf5ef2aSThomas Huth uint32_t op2;
5250fcf5ef2aSThomas Huth int r1, r2;
5251fcf5ef2aSThomas Huth int16_t const9;
5252fcf5ef2aSThomas Huth
5253fcf5ef2aSThomas Huth r2 = MASK_OP_RC_D(ctx->opcode);
5254fcf5ef2aSThomas Huth r1 = MASK_OP_RC_S1(ctx->opcode);
5255fcf5ef2aSThomas Huth const9 = MASK_OP_RC_CONST9_SEXT(ctx->opcode);
5256fcf5ef2aSThomas Huth
5257fcf5ef2aSThomas Huth op2 = MASK_OP_RC_OP2(ctx->opcode);
5258fcf5ef2aSThomas Huth
5259fcf5ef2aSThomas Huth switch (op2) {
5260fcf5ef2aSThomas Huth case OPC2_32_RC_MUL_32:
5261fcf5ef2aSThomas Huth gen_muli_i32s(cpu_gpr_d[r2], cpu_gpr_d[r1], const9);
5262fcf5ef2aSThomas Huth break;
5263fcf5ef2aSThomas Huth case OPC2_32_RC_MUL_64:
5264fcf5ef2aSThomas Huth CHECK_REG_PAIR(r2);
5265fcf5ef2aSThomas Huth gen_muli_i64s(cpu_gpr_d[r2], cpu_gpr_d[r2+1], cpu_gpr_d[r1], const9);
5266fcf5ef2aSThomas Huth break;
5267fcf5ef2aSThomas Huth case OPC2_32_RC_MULS_32:
5268fcf5ef2aSThomas Huth gen_mulsi_i32(cpu_gpr_d[r2], cpu_gpr_d[r1], const9);
5269fcf5ef2aSThomas Huth break;
5270fcf5ef2aSThomas Huth case OPC2_32_RC_MUL_U_64:
5271fcf5ef2aSThomas Huth const9 = MASK_OP_RC_CONST9(ctx->opcode);
5272fcf5ef2aSThomas Huth CHECK_REG_PAIR(r2);
5273fcf5ef2aSThomas Huth gen_muli_i64u(cpu_gpr_d[r2], cpu_gpr_d[r2+1], cpu_gpr_d[r1], const9);
5274fcf5ef2aSThomas Huth break;
5275fcf5ef2aSThomas Huth case OPC2_32_RC_MULS_U_32:
5276fcf5ef2aSThomas Huth const9 = MASK_OP_RC_CONST9(ctx->opcode);
5277fcf5ef2aSThomas Huth gen_mulsui_i32(cpu_gpr_d[r2], cpu_gpr_d[r1], const9);
5278fcf5ef2aSThomas Huth break;
5279fcf5ef2aSThomas Huth default:
5280fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
5281fcf5ef2aSThomas Huth }
5282fcf5ef2aSThomas Huth }
5283fcf5ef2aSThomas Huth
5284fcf5ef2aSThomas Huth /* RCPW format */
decode_rcpw_insert(DisasContext * ctx)52852db92a0cSBastian Koppelmann static void decode_rcpw_insert(DisasContext *ctx)
5286fcf5ef2aSThomas Huth {
5287fcf5ef2aSThomas Huth uint32_t op2;
5288fcf5ef2aSThomas Huth int r1, r2;
5289fcf5ef2aSThomas Huth int32_t pos, width, const4;
5290fcf5ef2aSThomas Huth
5291fcf5ef2aSThomas Huth TCGv temp;
5292fcf5ef2aSThomas Huth
5293fcf5ef2aSThomas Huth op2 = MASK_OP_RCPW_OP2(ctx->opcode);
5294fcf5ef2aSThomas Huth r1 = MASK_OP_RCPW_S1(ctx->opcode);
5295fcf5ef2aSThomas Huth r2 = MASK_OP_RCPW_D(ctx->opcode);
5296fcf5ef2aSThomas Huth const4 = MASK_OP_RCPW_CONST4(ctx->opcode);
5297fcf5ef2aSThomas Huth width = MASK_OP_RCPW_WIDTH(ctx->opcode);
5298fcf5ef2aSThomas Huth pos = MASK_OP_RCPW_POS(ctx->opcode);
5299fcf5ef2aSThomas Huth
5300fcf5ef2aSThomas Huth switch (op2) {
5301fcf5ef2aSThomas Huth case OPC2_32_RCPW_IMASK:
5302fcf5ef2aSThomas Huth CHECK_REG_PAIR(r2);
53039b620609SAndreas Konopik /* if pos + width > 32 undefined result */
53049b620609SAndreas Konopik if (pos + width <= 32) {
5305fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_gpr_d[r2+1], ((1u << width) - 1) << pos);
5306fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_gpr_d[r2], (const4 << pos));
5307fcf5ef2aSThomas Huth }
5308fcf5ef2aSThomas Huth break;
5309fcf5ef2aSThomas Huth case OPC2_32_RCPW_INSERT:
531023fa6f56SBastian Koppelmann /* tcg_gen_deposit_tl() does not handle the case of width = 0 */
531123fa6f56SBastian Koppelmann if (width == 0) {
531223fa6f56SBastian Koppelmann tcg_gen_mov_tl(cpu_gpr_d[r2], cpu_gpr_d[r1]);
5313fcf5ef2aSThomas Huth /* if pos + width > 32 undefined result */
531423fa6f56SBastian Koppelmann } else if (pos + width <= 32) {
5315151293c2SRichard Henderson temp = tcg_constant_i32(const4);
5316fcf5ef2aSThomas Huth tcg_gen_deposit_tl(cpu_gpr_d[r2], cpu_gpr_d[r1], temp, pos, width);
5317fcf5ef2aSThomas Huth }
5318fcf5ef2aSThomas Huth break;
5319fcf5ef2aSThomas Huth default:
5320fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
5321fcf5ef2aSThomas Huth }
5322fcf5ef2aSThomas Huth }
5323fcf5ef2aSThomas Huth
5324fcf5ef2aSThomas Huth /* RCRW format */
5325fcf5ef2aSThomas Huth
decode_rcrw_insert(DisasContext * ctx)53262db92a0cSBastian Koppelmann static void decode_rcrw_insert(DisasContext *ctx)
5327fcf5ef2aSThomas Huth {
5328fcf5ef2aSThomas Huth uint32_t op2;
5329fcf5ef2aSThomas Huth int r1, r3, r4;
5330fcf5ef2aSThomas Huth int32_t width, const4;
5331fcf5ef2aSThomas Huth
5332fcf5ef2aSThomas Huth TCGv temp, temp2, temp3;
5333fcf5ef2aSThomas Huth
5334fcf5ef2aSThomas Huth op2 = MASK_OP_RCRW_OP2(ctx->opcode);
5335fcf5ef2aSThomas Huth r1 = MASK_OP_RCRW_S1(ctx->opcode);
5336fcf5ef2aSThomas Huth r3 = MASK_OP_RCRW_S3(ctx->opcode);
5337fcf5ef2aSThomas Huth r4 = MASK_OP_RCRW_D(ctx->opcode);
5338fcf5ef2aSThomas Huth width = MASK_OP_RCRW_WIDTH(ctx->opcode);
5339fcf5ef2aSThomas Huth const4 = MASK_OP_RCRW_CONST4(ctx->opcode);
5340fcf5ef2aSThomas Huth
5341fcf5ef2aSThomas Huth temp = tcg_temp_new();
5342fcf5ef2aSThomas Huth temp2 = tcg_temp_new();
5343fcf5ef2aSThomas Huth
5344fcf5ef2aSThomas Huth switch (op2) {
5345fcf5ef2aSThomas Huth case OPC2_32_RCRW_IMASK:
5346d34b092cSSiqi Chen CHECK_REG_PAIR(r4);
534765e57fdbSBastian Koppelmann tcg_gen_andi_tl(temp, cpu_gpr_d[r3], 0x1f);
5348fcf5ef2aSThomas Huth tcg_gen_movi_tl(temp2, (1 << width) - 1);
534965e57fdbSBastian Koppelmann tcg_gen_shl_tl(cpu_gpr_d[r4 + 1], temp2, temp);
5350fcf5ef2aSThomas Huth tcg_gen_movi_tl(temp2, const4);
535165e57fdbSBastian Koppelmann tcg_gen_shl_tl(cpu_gpr_d[r4], temp2, temp);
5352fcf5ef2aSThomas Huth break;
5353fcf5ef2aSThomas Huth case OPC2_32_RCRW_INSERT:
5354fcf5ef2aSThomas Huth temp3 = tcg_temp_new();
5355fcf5ef2aSThomas Huth
5356fcf5ef2aSThomas Huth tcg_gen_movi_tl(temp, width);
5357fcf5ef2aSThomas Huth tcg_gen_movi_tl(temp2, const4);
53581c6b2e4bSBastian Koppelmann tcg_gen_andi_tl(temp3, cpu_gpr_d[r3], 0x1f);
53591c6b2e4bSBastian Koppelmann gen_insert(cpu_gpr_d[r4], cpu_gpr_d[r1], temp2, temp, temp3);
5360fcf5ef2aSThomas Huth break;
5361fcf5ef2aSThomas Huth default:
5362fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
5363fcf5ef2aSThomas Huth }
5364fcf5ef2aSThomas Huth }
5365fcf5ef2aSThomas Huth
5366fcf5ef2aSThomas Huth /* RCR format */
5367fcf5ef2aSThomas Huth
decode_rcr_cond_select(DisasContext * ctx)53682db92a0cSBastian Koppelmann static void decode_rcr_cond_select(DisasContext *ctx)
5369fcf5ef2aSThomas Huth {
5370fcf5ef2aSThomas Huth uint32_t op2;
5371fcf5ef2aSThomas Huth int r1, r3, r4;
5372fcf5ef2aSThomas Huth int32_t const9;
5373fcf5ef2aSThomas Huth
5374fcf5ef2aSThomas Huth TCGv temp, temp2;
5375fcf5ef2aSThomas Huth
5376fcf5ef2aSThomas Huth op2 = MASK_OP_RCR_OP2(ctx->opcode);
5377fcf5ef2aSThomas Huth r1 = MASK_OP_RCR_S1(ctx->opcode);
5378fcf5ef2aSThomas Huth const9 = MASK_OP_RCR_CONST9_SEXT(ctx->opcode);
5379fcf5ef2aSThomas Huth r3 = MASK_OP_RCR_S3(ctx->opcode);
5380fcf5ef2aSThomas Huth r4 = MASK_OP_RCR_D(ctx->opcode);
5381fcf5ef2aSThomas Huth
5382fcf5ef2aSThomas Huth switch (op2) {
5383fcf5ef2aSThomas Huth case OPC2_32_RCR_CADD:
5384a00585eeSDavid Brenken gen_condi_add(TCG_COND_NE, cpu_gpr_d[r1], const9, cpu_gpr_d[r4],
5385a00585eeSDavid Brenken cpu_gpr_d[r3]);
5386fcf5ef2aSThomas Huth break;
5387fcf5ef2aSThomas Huth case OPC2_32_RCR_CADDN:
5388d1c1d88cSDavid Brenken gen_condi_add(TCG_COND_EQ, cpu_gpr_d[r1], const9, cpu_gpr_d[r4],
5389d1c1d88cSDavid Brenken cpu_gpr_d[r3]);
5390fcf5ef2aSThomas Huth break;
5391fcf5ef2aSThomas Huth case OPC2_32_RCR_SEL:
5392151293c2SRichard Henderson temp = tcg_constant_i32(0);
5393151293c2SRichard Henderson temp2 = tcg_constant_i32(const9);
5394fcf5ef2aSThomas Huth tcg_gen_movcond_tl(TCG_COND_NE, cpu_gpr_d[r4], cpu_gpr_d[r3], temp,
5395fcf5ef2aSThomas Huth cpu_gpr_d[r1], temp2);
5396fcf5ef2aSThomas Huth break;
5397fcf5ef2aSThomas Huth case OPC2_32_RCR_SELN:
5398151293c2SRichard Henderson temp = tcg_constant_i32(0);
5399151293c2SRichard Henderson temp2 = tcg_constant_i32(const9);
5400fcf5ef2aSThomas Huth tcg_gen_movcond_tl(TCG_COND_EQ, cpu_gpr_d[r4], cpu_gpr_d[r3], temp,
5401fcf5ef2aSThomas Huth cpu_gpr_d[r1], temp2);
5402fcf5ef2aSThomas Huth break;
5403fcf5ef2aSThomas Huth default:
5404fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
5405fcf5ef2aSThomas Huth }
5406fcf5ef2aSThomas Huth }
5407fcf5ef2aSThomas Huth
decode_rcr_madd(DisasContext * ctx)54082db92a0cSBastian Koppelmann static void decode_rcr_madd(DisasContext *ctx)
5409fcf5ef2aSThomas Huth {
5410fcf5ef2aSThomas Huth uint32_t op2;
5411fcf5ef2aSThomas Huth int r1, r3, r4;
5412fcf5ef2aSThomas Huth int32_t const9;
5413fcf5ef2aSThomas Huth
5414fcf5ef2aSThomas Huth
5415fcf5ef2aSThomas Huth op2 = MASK_OP_RCR_OP2(ctx->opcode);
5416fcf5ef2aSThomas Huth r1 = MASK_OP_RCR_S1(ctx->opcode);
5417fcf5ef2aSThomas Huth const9 = MASK_OP_RCR_CONST9_SEXT(ctx->opcode);
5418fcf5ef2aSThomas Huth r3 = MASK_OP_RCR_S3(ctx->opcode);
5419fcf5ef2aSThomas Huth r4 = MASK_OP_RCR_D(ctx->opcode);
5420fcf5ef2aSThomas Huth
5421fcf5ef2aSThomas Huth switch (op2) {
5422fcf5ef2aSThomas Huth case OPC2_32_RCR_MADD_32:
5423fcf5ef2aSThomas Huth gen_maddi32_d(cpu_gpr_d[r4], cpu_gpr_d[r1], cpu_gpr_d[r3], const9);
5424fcf5ef2aSThomas Huth break;
5425fcf5ef2aSThomas Huth case OPC2_32_RCR_MADD_64:
5426fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
5427fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
5428fcf5ef2aSThomas Huth gen_maddi64_d(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r1],
5429fcf5ef2aSThomas Huth cpu_gpr_d[r3], cpu_gpr_d[r3+1], const9);
5430fcf5ef2aSThomas Huth break;
5431fcf5ef2aSThomas Huth case OPC2_32_RCR_MADDS_32:
5432fcf5ef2aSThomas Huth gen_maddsi_32(cpu_gpr_d[r4], cpu_gpr_d[r1], cpu_gpr_d[r3], const9);
5433fcf5ef2aSThomas Huth break;
5434fcf5ef2aSThomas Huth case OPC2_32_RCR_MADDS_64:
5435fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
5436fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
5437fcf5ef2aSThomas Huth gen_maddsi_64(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r1],
5438fcf5ef2aSThomas Huth cpu_gpr_d[r3], cpu_gpr_d[r3+1], const9);
5439fcf5ef2aSThomas Huth break;
5440fcf5ef2aSThomas Huth case OPC2_32_RCR_MADD_U_64:
5441fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
5442fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
5443fcf5ef2aSThomas Huth const9 = MASK_OP_RCR_CONST9(ctx->opcode);
5444fcf5ef2aSThomas Huth gen_maddui64_d(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r1],
5445fcf5ef2aSThomas Huth cpu_gpr_d[r3], cpu_gpr_d[r3+1], const9);
5446fcf5ef2aSThomas Huth break;
5447fcf5ef2aSThomas Huth case OPC2_32_RCR_MADDS_U_32:
5448fcf5ef2aSThomas Huth const9 = MASK_OP_RCR_CONST9(ctx->opcode);
5449fcf5ef2aSThomas Huth gen_maddsui_32(cpu_gpr_d[r4], cpu_gpr_d[r1], cpu_gpr_d[r3], const9);
5450fcf5ef2aSThomas Huth break;
5451fcf5ef2aSThomas Huth case OPC2_32_RCR_MADDS_U_64:
5452fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
5453fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
5454fcf5ef2aSThomas Huth const9 = MASK_OP_RCR_CONST9(ctx->opcode);
5455fcf5ef2aSThomas Huth gen_maddsui_64(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r1],
5456fcf5ef2aSThomas Huth cpu_gpr_d[r3], cpu_gpr_d[r3+1], const9);
5457fcf5ef2aSThomas Huth break;
5458fcf5ef2aSThomas Huth default:
5459fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
5460fcf5ef2aSThomas Huth }
5461fcf5ef2aSThomas Huth }
5462fcf5ef2aSThomas Huth
decode_rcr_msub(DisasContext * ctx)54632db92a0cSBastian Koppelmann static void decode_rcr_msub(DisasContext *ctx)
5464fcf5ef2aSThomas Huth {
5465fcf5ef2aSThomas Huth uint32_t op2;
5466fcf5ef2aSThomas Huth int r1, r3, r4;
5467fcf5ef2aSThomas Huth int32_t const9;
5468fcf5ef2aSThomas Huth
5469fcf5ef2aSThomas Huth
5470fcf5ef2aSThomas Huth op2 = MASK_OP_RCR_OP2(ctx->opcode);
5471fcf5ef2aSThomas Huth r1 = MASK_OP_RCR_S1(ctx->opcode);
5472fcf5ef2aSThomas Huth const9 = MASK_OP_RCR_CONST9_SEXT(ctx->opcode);
5473fcf5ef2aSThomas Huth r3 = MASK_OP_RCR_S3(ctx->opcode);
5474fcf5ef2aSThomas Huth r4 = MASK_OP_RCR_D(ctx->opcode);
5475fcf5ef2aSThomas Huth
5476fcf5ef2aSThomas Huth switch (op2) {
5477fcf5ef2aSThomas Huth case OPC2_32_RCR_MSUB_32:
5478fcf5ef2aSThomas Huth gen_msubi32_d(cpu_gpr_d[r4], cpu_gpr_d[r1], cpu_gpr_d[r3], const9);
5479fcf5ef2aSThomas Huth break;
5480fcf5ef2aSThomas Huth case OPC2_32_RCR_MSUB_64:
5481fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
5482fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
5483fcf5ef2aSThomas Huth gen_msubi64_d(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r1],
5484fcf5ef2aSThomas Huth cpu_gpr_d[r3], cpu_gpr_d[r3+1], const9);
5485fcf5ef2aSThomas Huth break;
5486fcf5ef2aSThomas Huth case OPC2_32_RCR_MSUBS_32:
5487fcf5ef2aSThomas Huth gen_msubsi_32(cpu_gpr_d[r4], cpu_gpr_d[r1], cpu_gpr_d[r3], const9);
5488fcf5ef2aSThomas Huth break;
5489fcf5ef2aSThomas Huth case OPC2_32_RCR_MSUBS_64:
5490fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
5491fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
5492fcf5ef2aSThomas Huth gen_msubsi_64(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r1],
5493fcf5ef2aSThomas Huth cpu_gpr_d[r3], cpu_gpr_d[r3+1], const9);
5494fcf5ef2aSThomas Huth break;
5495fcf5ef2aSThomas Huth case OPC2_32_RCR_MSUB_U_64:
5496fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
5497fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
5498fcf5ef2aSThomas Huth const9 = MASK_OP_RCR_CONST9(ctx->opcode);
5499fcf5ef2aSThomas Huth gen_msubui64_d(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r1],
5500fcf5ef2aSThomas Huth cpu_gpr_d[r3], cpu_gpr_d[r3+1], const9);
5501fcf5ef2aSThomas Huth break;
5502fcf5ef2aSThomas Huth case OPC2_32_RCR_MSUBS_U_32:
5503fcf5ef2aSThomas Huth const9 = MASK_OP_RCR_CONST9(ctx->opcode);
5504fcf5ef2aSThomas Huth gen_msubsui_32(cpu_gpr_d[r4], cpu_gpr_d[r1], cpu_gpr_d[r3], const9);
5505fcf5ef2aSThomas Huth break;
5506fcf5ef2aSThomas Huth case OPC2_32_RCR_MSUBS_U_64:
5507fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
5508fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
5509fcf5ef2aSThomas Huth const9 = MASK_OP_RCR_CONST9(ctx->opcode);
5510fcf5ef2aSThomas Huth gen_msubsui_64(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r1],
5511fcf5ef2aSThomas Huth cpu_gpr_d[r3], cpu_gpr_d[r3+1], const9);
5512fcf5ef2aSThomas Huth break;
5513fcf5ef2aSThomas Huth default:
5514fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
5515fcf5ef2aSThomas Huth }
5516fcf5ef2aSThomas Huth }
5517fcf5ef2aSThomas Huth
5518fcf5ef2aSThomas Huth /* RLC format */
5519fcf5ef2aSThomas Huth
decode_rlc_opc(DisasContext * ctx,uint32_t op1)55202db92a0cSBastian Koppelmann static void decode_rlc_opc(DisasContext *ctx,
5521fcf5ef2aSThomas Huth uint32_t op1)
5522fcf5ef2aSThomas Huth {
5523fcf5ef2aSThomas Huth int32_t const16;
5524fcf5ef2aSThomas Huth int r1, r2;
5525fcf5ef2aSThomas Huth
5526fcf5ef2aSThomas Huth const16 = MASK_OP_RLC_CONST16_SEXT(ctx->opcode);
5527fcf5ef2aSThomas Huth r1 = MASK_OP_RLC_S1(ctx->opcode);
5528fcf5ef2aSThomas Huth r2 = MASK_OP_RLC_D(ctx->opcode);
5529fcf5ef2aSThomas Huth
5530fcf5ef2aSThomas Huth switch (op1) {
5531fcf5ef2aSThomas Huth case OPC1_32_RLC_ADDI:
5532fcf5ef2aSThomas Huth gen_addi_d(cpu_gpr_d[r2], cpu_gpr_d[r1], const16);
5533fcf5ef2aSThomas Huth break;
5534fcf5ef2aSThomas Huth case OPC1_32_RLC_ADDIH:
5535fcf5ef2aSThomas Huth gen_addi_d(cpu_gpr_d[r2], cpu_gpr_d[r1], const16 << 16);
5536fcf5ef2aSThomas Huth break;
5537fcf5ef2aSThomas Huth case OPC1_32_RLC_ADDIH_A:
5538fcf5ef2aSThomas Huth tcg_gen_addi_tl(cpu_gpr_a[r2], cpu_gpr_a[r1], const16 << 16);
5539fcf5ef2aSThomas Huth break;
5540fcf5ef2aSThomas Huth case OPC1_32_RLC_MFCR:
5541fcf5ef2aSThomas Huth const16 = MASK_OP_RLC_CONST16(ctx->opcode);
55422db92a0cSBastian Koppelmann gen_mfcr(ctx, cpu_gpr_d[r2], const16);
5543fcf5ef2aSThomas Huth break;
5544fcf5ef2aSThomas Huth case OPC1_32_RLC_MOV:
5545fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_gpr_d[r2], const16);
5546fcf5ef2aSThomas Huth break;
5547fcf5ef2aSThomas Huth case OPC1_32_RLC_MOV_64:
554844ee3bafSBastian Koppelmann if (has_feature(ctx, TRICORE_FEATURE_16)) {
5549fcf5ef2aSThomas Huth CHECK_REG_PAIR(r2);
5550fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_gpr_d[r2], const16);
5551fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_gpr_d[r2+1], const16 >> 15);
5552fcf5ef2aSThomas Huth } else {
5553fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
5554fcf5ef2aSThomas Huth }
5555fcf5ef2aSThomas Huth break;
5556fcf5ef2aSThomas Huth case OPC1_32_RLC_MOV_U:
5557fcf5ef2aSThomas Huth const16 = MASK_OP_RLC_CONST16(ctx->opcode);
5558fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_gpr_d[r2], const16);
5559fcf5ef2aSThomas Huth break;
5560fcf5ef2aSThomas Huth case OPC1_32_RLC_MOV_H:
5561fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_gpr_d[r2], const16 << 16);
5562fcf5ef2aSThomas Huth break;
5563fcf5ef2aSThomas Huth case OPC1_32_RLC_MOVH_A:
5564fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_gpr_a[r2], const16 << 16);
5565fcf5ef2aSThomas Huth break;
5566fcf5ef2aSThomas Huth case OPC1_32_RLC_MTCR:
5567fcf5ef2aSThomas Huth const16 = MASK_OP_RLC_CONST16(ctx->opcode);
55682db92a0cSBastian Koppelmann gen_mtcr(ctx, cpu_gpr_d[r1], const16);
5569fcf5ef2aSThomas Huth break;
5570fcf5ef2aSThomas Huth default:
5571fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
5572fcf5ef2aSThomas Huth }
5573fcf5ef2aSThomas Huth }
5574fcf5ef2aSThomas Huth
5575fcf5ef2aSThomas Huth /* RR format */
decode_rr_accumulator(DisasContext * ctx)55762db92a0cSBastian Koppelmann static void decode_rr_accumulator(DisasContext *ctx)
5577fcf5ef2aSThomas Huth {
5578fcf5ef2aSThomas Huth uint32_t op2;
5579fcf5ef2aSThomas Huth int r3, r2, r1;
5580fcf5ef2aSThomas Huth
5581550929ddSPeer Adelt TCGv temp;
5582550929ddSPeer Adelt
5583fcf5ef2aSThomas Huth r3 = MASK_OP_RR_D(ctx->opcode);
5584fcf5ef2aSThomas Huth r2 = MASK_OP_RR_S2(ctx->opcode);
5585fcf5ef2aSThomas Huth r1 = MASK_OP_RR_S1(ctx->opcode);
5586fcf5ef2aSThomas Huth op2 = MASK_OP_RR_OP2(ctx->opcode);
5587fcf5ef2aSThomas Huth
5588fcf5ef2aSThomas Huth switch (op2) {
5589fcf5ef2aSThomas Huth case OPC2_32_RR_ABS:
5590fcf5ef2aSThomas Huth gen_abs(cpu_gpr_d[r3], cpu_gpr_d[r2]);
5591fcf5ef2aSThomas Huth break;
5592fcf5ef2aSThomas Huth case OPC2_32_RR_ABS_B:
5593ad75a51eSRichard Henderson gen_helper_abs_b(cpu_gpr_d[r3], tcg_env, cpu_gpr_d[r2]);
5594fcf5ef2aSThomas Huth break;
5595fcf5ef2aSThomas Huth case OPC2_32_RR_ABS_H:
5596ad75a51eSRichard Henderson gen_helper_abs_h(cpu_gpr_d[r3], tcg_env, cpu_gpr_d[r2]);
5597fcf5ef2aSThomas Huth break;
5598fcf5ef2aSThomas Huth case OPC2_32_RR_ABSDIF:
5599fcf5ef2aSThomas Huth gen_absdif(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2]);
5600fcf5ef2aSThomas Huth break;
5601fcf5ef2aSThomas Huth case OPC2_32_RR_ABSDIF_B:
5602ad75a51eSRichard Henderson gen_helper_absdif_b(cpu_gpr_d[r3], tcg_env, cpu_gpr_d[r1],
5603fcf5ef2aSThomas Huth cpu_gpr_d[r2]);
5604fcf5ef2aSThomas Huth break;
5605fcf5ef2aSThomas Huth case OPC2_32_RR_ABSDIF_H:
5606ad75a51eSRichard Henderson gen_helper_absdif_h(cpu_gpr_d[r3], tcg_env, cpu_gpr_d[r1],
5607fcf5ef2aSThomas Huth cpu_gpr_d[r2]);
5608fcf5ef2aSThomas Huth break;
5609fcf5ef2aSThomas Huth case OPC2_32_RR_ABSDIFS:
5610ad75a51eSRichard Henderson gen_helper_absdif_ssov(cpu_gpr_d[r3], tcg_env, cpu_gpr_d[r1],
5611fcf5ef2aSThomas Huth cpu_gpr_d[r2]);
5612fcf5ef2aSThomas Huth break;
5613fcf5ef2aSThomas Huth case OPC2_32_RR_ABSDIFS_H:
5614ad75a51eSRichard Henderson gen_helper_absdif_h_ssov(cpu_gpr_d[r3], tcg_env, cpu_gpr_d[r1],
5615fcf5ef2aSThomas Huth cpu_gpr_d[r2]);
5616fcf5ef2aSThomas Huth break;
5617fcf5ef2aSThomas Huth case OPC2_32_RR_ABSS:
5618ad75a51eSRichard Henderson gen_helper_abs_ssov(cpu_gpr_d[r3], tcg_env, cpu_gpr_d[r2]);
5619fcf5ef2aSThomas Huth break;
5620fcf5ef2aSThomas Huth case OPC2_32_RR_ABSS_H:
5621ad75a51eSRichard Henderson gen_helper_abs_h_ssov(cpu_gpr_d[r3], tcg_env, cpu_gpr_d[r2]);
5622fcf5ef2aSThomas Huth break;
5623fcf5ef2aSThomas Huth case OPC2_32_RR_ADD:
5624fcf5ef2aSThomas Huth gen_add_d(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2]);
5625fcf5ef2aSThomas Huth break;
5626fcf5ef2aSThomas Huth case OPC2_32_RR_ADD_B:
5627ad75a51eSRichard Henderson gen_helper_add_b(cpu_gpr_d[r3], tcg_env, cpu_gpr_d[r1], cpu_gpr_d[r2]);
5628fcf5ef2aSThomas Huth break;
5629fcf5ef2aSThomas Huth case OPC2_32_RR_ADD_H:
5630ad75a51eSRichard Henderson gen_helper_add_h(cpu_gpr_d[r3], tcg_env, cpu_gpr_d[r1], cpu_gpr_d[r2]);
5631fcf5ef2aSThomas Huth break;
5632fcf5ef2aSThomas Huth case OPC2_32_RR_ADDC:
5633fcf5ef2aSThomas Huth gen_addc_CC(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2]);
5634fcf5ef2aSThomas Huth break;
5635fcf5ef2aSThomas Huth case OPC2_32_RR_ADDS:
5636fcf5ef2aSThomas Huth gen_adds(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2]);
5637fcf5ef2aSThomas Huth break;
5638fcf5ef2aSThomas Huth case OPC2_32_RR_ADDS_H:
5639ad75a51eSRichard Henderson gen_helper_add_h_ssov(cpu_gpr_d[r3], tcg_env, cpu_gpr_d[r1],
5640fcf5ef2aSThomas Huth cpu_gpr_d[r2]);
5641fcf5ef2aSThomas Huth break;
5642fcf5ef2aSThomas Huth case OPC2_32_RR_ADDS_HU:
5643ad75a51eSRichard Henderson gen_helper_add_h_suov(cpu_gpr_d[r3], tcg_env, cpu_gpr_d[r1],
5644fcf5ef2aSThomas Huth cpu_gpr_d[r2]);
5645fcf5ef2aSThomas Huth break;
5646fcf5ef2aSThomas Huth case OPC2_32_RR_ADDS_U:
5647ad75a51eSRichard Henderson gen_helper_add_suov(cpu_gpr_d[r3], tcg_env, cpu_gpr_d[r1],
5648fcf5ef2aSThomas Huth cpu_gpr_d[r2]);
5649fcf5ef2aSThomas Huth break;
5650fcf5ef2aSThomas Huth case OPC2_32_RR_ADDX:
5651fcf5ef2aSThomas Huth gen_add_CC(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2]);
5652fcf5ef2aSThomas Huth break;
5653fcf5ef2aSThomas Huth case OPC2_32_RR_AND_EQ:
5654fcf5ef2aSThomas Huth gen_accumulating_cond(TCG_COND_EQ, cpu_gpr_d[r3], cpu_gpr_d[r1],
5655fcf5ef2aSThomas Huth cpu_gpr_d[r2], &tcg_gen_and_tl);
5656fcf5ef2aSThomas Huth break;
5657fcf5ef2aSThomas Huth case OPC2_32_RR_AND_GE:
5658fcf5ef2aSThomas Huth gen_accumulating_cond(TCG_COND_GE, cpu_gpr_d[r3], cpu_gpr_d[r1],
5659fcf5ef2aSThomas Huth cpu_gpr_d[r2], &tcg_gen_and_tl);
5660fcf5ef2aSThomas Huth break;
5661fcf5ef2aSThomas Huth case OPC2_32_RR_AND_GE_U:
5662fcf5ef2aSThomas Huth gen_accumulating_cond(TCG_COND_GEU, cpu_gpr_d[r3], cpu_gpr_d[r1],
5663fcf5ef2aSThomas Huth cpu_gpr_d[r2], &tcg_gen_and_tl);
5664fcf5ef2aSThomas Huth break;
5665fcf5ef2aSThomas Huth case OPC2_32_RR_AND_LT:
5666fcf5ef2aSThomas Huth gen_accumulating_cond(TCG_COND_LT, cpu_gpr_d[r3], cpu_gpr_d[r1],
5667fcf5ef2aSThomas Huth cpu_gpr_d[r2], &tcg_gen_and_tl);
5668fcf5ef2aSThomas Huth break;
5669fcf5ef2aSThomas Huth case OPC2_32_RR_AND_LT_U:
5670fcf5ef2aSThomas Huth gen_accumulating_cond(TCG_COND_LTU, cpu_gpr_d[r3], cpu_gpr_d[r1],
5671fcf5ef2aSThomas Huth cpu_gpr_d[r2], &tcg_gen_and_tl);
5672fcf5ef2aSThomas Huth break;
5673fcf5ef2aSThomas Huth case OPC2_32_RR_AND_NE:
5674fcf5ef2aSThomas Huth gen_accumulating_cond(TCG_COND_NE, cpu_gpr_d[r3], cpu_gpr_d[r1],
5675fcf5ef2aSThomas Huth cpu_gpr_d[r2], &tcg_gen_and_tl);
5676fcf5ef2aSThomas Huth break;
5677fcf5ef2aSThomas Huth case OPC2_32_RR_EQ:
5678fcf5ef2aSThomas Huth tcg_gen_setcond_tl(TCG_COND_EQ, cpu_gpr_d[r3], cpu_gpr_d[r1],
5679fcf5ef2aSThomas Huth cpu_gpr_d[r2]);
5680fcf5ef2aSThomas Huth break;
5681fcf5ef2aSThomas Huth case OPC2_32_RR_EQ_B:
5682fcf5ef2aSThomas Huth gen_helper_eq_b(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2]);
5683fcf5ef2aSThomas Huth break;
5684fcf5ef2aSThomas Huth case OPC2_32_RR_EQ_H:
5685fcf5ef2aSThomas Huth gen_helper_eq_h(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2]);
5686fcf5ef2aSThomas Huth break;
5687fcf5ef2aSThomas Huth case OPC2_32_RR_EQ_W:
5688b0a433beSRichard Henderson tcg_gen_negsetcond_tl(TCG_COND_EQ, cpu_gpr_d[r3],
5689b0a433beSRichard Henderson cpu_gpr_d[r1], cpu_gpr_d[r2]);
5690fcf5ef2aSThomas Huth break;
5691fcf5ef2aSThomas Huth case OPC2_32_RR_EQANY_B:
5692fcf5ef2aSThomas Huth gen_helper_eqany_b(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2]);
5693fcf5ef2aSThomas Huth break;
5694fcf5ef2aSThomas Huth case OPC2_32_RR_EQANY_H:
5695fcf5ef2aSThomas Huth gen_helper_eqany_h(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2]);
5696fcf5ef2aSThomas Huth break;
5697fcf5ef2aSThomas Huth case OPC2_32_RR_GE:
5698fcf5ef2aSThomas Huth tcg_gen_setcond_tl(TCG_COND_GE, cpu_gpr_d[r3], cpu_gpr_d[r1],
5699fcf5ef2aSThomas Huth cpu_gpr_d[r2]);
5700fcf5ef2aSThomas Huth break;
5701fcf5ef2aSThomas Huth case OPC2_32_RR_GE_U:
5702fcf5ef2aSThomas Huth tcg_gen_setcond_tl(TCG_COND_GEU, cpu_gpr_d[r3], cpu_gpr_d[r1],
5703fcf5ef2aSThomas Huth cpu_gpr_d[r2]);
5704fcf5ef2aSThomas Huth break;
5705fcf5ef2aSThomas Huth case OPC2_32_RR_LT:
5706fcf5ef2aSThomas Huth tcg_gen_setcond_tl(TCG_COND_LT, cpu_gpr_d[r3], cpu_gpr_d[r1],
5707fcf5ef2aSThomas Huth cpu_gpr_d[r2]);
5708fcf5ef2aSThomas Huth break;
5709fcf5ef2aSThomas Huth case OPC2_32_RR_LT_U:
5710fcf5ef2aSThomas Huth tcg_gen_setcond_tl(TCG_COND_LTU, cpu_gpr_d[r3], cpu_gpr_d[r1],
5711fcf5ef2aSThomas Huth cpu_gpr_d[r2]);
5712fcf5ef2aSThomas Huth break;
5713fcf5ef2aSThomas Huth case OPC2_32_RR_LT_B:
5714fcf5ef2aSThomas Huth gen_helper_lt_b(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2]);
5715fcf5ef2aSThomas Huth break;
5716fcf5ef2aSThomas Huth case OPC2_32_RR_LT_BU:
5717fcf5ef2aSThomas Huth gen_helper_lt_bu(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2]);
5718fcf5ef2aSThomas Huth break;
5719fcf5ef2aSThomas Huth case OPC2_32_RR_LT_H:
5720fcf5ef2aSThomas Huth gen_helper_lt_h(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2]);
5721fcf5ef2aSThomas Huth break;
5722fcf5ef2aSThomas Huth case OPC2_32_RR_LT_HU:
5723fcf5ef2aSThomas Huth gen_helper_lt_hu(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2]);
5724fcf5ef2aSThomas Huth break;
5725fcf5ef2aSThomas Huth case OPC2_32_RR_LT_W:
5726b0a433beSRichard Henderson tcg_gen_negsetcond_tl(TCG_COND_LT, cpu_gpr_d[r3],
5727b0a433beSRichard Henderson cpu_gpr_d[r1], cpu_gpr_d[r2]);
5728fcf5ef2aSThomas Huth break;
5729fcf5ef2aSThomas Huth case OPC2_32_RR_LT_WU:
5730b0a433beSRichard Henderson tcg_gen_negsetcond_tl(TCG_COND_LTU, cpu_gpr_d[r3],
5731b0a433beSRichard Henderson cpu_gpr_d[r1], cpu_gpr_d[r2]);
5732fcf5ef2aSThomas Huth break;
5733fcf5ef2aSThomas Huth case OPC2_32_RR_MAX:
5734fcf5ef2aSThomas Huth tcg_gen_movcond_tl(TCG_COND_GT, cpu_gpr_d[r3], cpu_gpr_d[r1],
5735fcf5ef2aSThomas Huth cpu_gpr_d[r2], cpu_gpr_d[r1], cpu_gpr_d[r2]);
5736fcf5ef2aSThomas Huth break;
5737fcf5ef2aSThomas Huth case OPC2_32_RR_MAX_U:
5738fcf5ef2aSThomas Huth tcg_gen_movcond_tl(TCG_COND_GTU, cpu_gpr_d[r3], cpu_gpr_d[r1],
5739fcf5ef2aSThomas Huth cpu_gpr_d[r2], cpu_gpr_d[r1], cpu_gpr_d[r2]);
5740fcf5ef2aSThomas Huth break;
5741fcf5ef2aSThomas Huth case OPC2_32_RR_MAX_B:
5742fcf5ef2aSThomas Huth gen_helper_max_b(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2]);
5743fcf5ef2aSThomas Huth break;
5744fcf5ef2aSThomas Huth case OPC2_32_RR_MAX_BU:
5745fcf5ef2aSThomas Huth gen_helper_max_bu(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2]);
5746fcf5ef2aSThomas Huth break;
5747fcf5ef2aSThomas Huth case OPC2_32_RR_MAX_H:
5748fcf5ef2aSThomas Huth gen_helper_max_h(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2]);
5749fcf5ef2aSThomas Huth break;
5750fcf5ef2aSThomas Huth case OPC2_32_RR_MAX_HU:
5751fcf5ef2aSThomas Huth gen_helper_max_hu(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2]);
5752fcf5ef2aSThomas Huth break;
5753fcf5ef2aSThomas Huth case OPC2_32_RR_MIN:
5754fcf5ef2aSThomas Huth tcg_gen_movcond_tl(TCG_COND_LT, cpu_gpr_d[r3], cpu_gpr_d[r1],
5755fcf5ef2aSThomas Huth cpu_gpr_d[r2], cpu_gpr_d[r1], cpu_gpr_d[r2]);
5756fcf5ef2aSThomas Huth break;
5757fcf5ef2aSThomas Huth case OPC2_32_RR_MIN_U:
5758fcf5ef2aSThomas Huth tcg_gen_movcond_tl(TCG_COND_LTU, cpu_gpr_d[r3], cpu_gpr_d[r1],
5759fcf5ef2aSThomas Huth cpu_gpr_d[r2], cpu_gpr_d[r1], cpu_gpr_d[r2]);
5760fcf5ef2aSThomas Huth break;
5761fcf5ef2aSThomas Huth case OPC2_32_RR_MIN_B:
5762fcf5ef2aSThomas Huth gen_helper_min_b(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2]);
5763fcf5ef2aSThomas Huth break;
5764fcf5ef2aSThomas Huth case OPC2_32_RR_MIN_BU:
5765fcf5ef2aSThomas Huth gen_helper_min_bu(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2]);
5766fcf5ef2aSThomas Huth break;
5767fcf5ef2aSThomas Huth case OPC2_32_RR_MIN_H:
5768fcf5ef2aSThomas Huth gen_helper_min_h(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2]);
5769fcf5ef2aSThomas Huth break;
5770fcf5ef2aSThomas Huth case OPC2_32_RR_MIN_HU:
5771fcf5ef2aSThomas Huth gen_helper_min_hu(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2]);
5772fcf5ef2aSThomas Huth break;
5773fcf5ef2aSThomas Huth case OPC2_32_RR_MOV:
5774fcf5ef2aSThomas Huth tcg_gen_mov_tl(cpu_gpr_d[r3], cpu_gpr_d[r2]);
5775fcf5ef2aSThomas Huth break;
5776550929ddSPeer Adelt case OPC2_32_RR_MOV_64:
577744ee3bafSBastian Koppelmann if (has_feature(ctx, TRICORE_FEATURE_16)) {
5778550929ddSPeer Adelt temp = tcg_temp_new();
5779550929ddSPeer Adelt
5780550929ddSPeer Adelt CHECK_REG_PAIR(r3);
5781550929ddSPeer Adelt tcg_gen_mov_tl(temp, cpu_gpr_d[r1]);
5782550929ddSPeer Adelt tcg_gen_mov_tl(cpu_gpr_d[r3], cpu_gpr_d[r2]);
5783550929ddSPeer Adelt tcg_gen_mov_tl(cpu_gpr_d[r3 + 1], temp);
5784550929ddSPeer Adelt } else {
5785550929ddSPeer Adelt generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
5786550929ddSPeer Adelt }
5787550929ddSPeer Adelt break;
5788defda2d4SDavid Brenken case OPC2_32_RR_MOVS_64:
578944ee3bafSBastian Koppelmann if (has_feature(ctx, TRICORE_FEATURE_16)) {
5790defda2d4SDavid Brenken CHECK_REG_PAIR(r3);
5791defda2d4SDavid Brenken tcg_gen_mov_tl(cpu_gpr_d[r3], cpu_gpr_d[r2]);
5792defda2d4SDavid Brenken tcg_gen_sari_tl(cpu_gpr_d[r3 + 1], cpu_gpr_d[r2], 31);
5793defda2d4SDavid Brenken } else {
5794defda2d4SDavid Brenken generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
5795defda2d4SDavid Brenken }
5796defda2d4SDavid Brenken break;
5797fcf5ef2aSThomas Huth case OPC2_32_RR_NE:
5798fcf5ef2aSThomas Huth tcg_gen_setcond_tl(TCG_COND_NE, cpu_gpr_d[r3], cpu_gpr_d[r1],
5799fcf5ef2aSThomas Huth cpu_gpr_d[r2]);
5800fcf5ef2aSThomas Huth break;
5801fcf5ef2aSThomas Huth case OPC2_32_RR_OR_EQ:
5802fcf5ef2aSThomas Huth gen_accumulating_cond(TCG_COND_EQ, cpu_gpr_d[r3], cpu_gpr_d[r1],
5803fcf5ef2aSThomas Huth cpu_gpr_d[r2], &tcg_gen_or_tl);
5804fcf5ef2aSThomas Huth break;
5805fcf5ef2aSThomas Huth case OPC2_32_RR_OR_GE:
5806fcf5ef2aSThomas Huth gen_accumulating_cond(TCG_COND_GE, cpu_gpr_d[r3], cpu_gpr_d[r1],
5807fcf5ef2aSThomas Huth cpu_gpr_d[r2], &tcg_gen_or_tl);
5808fcf5ef2aSThomas Huth break;
5809fcf5ef2aSThomas Huth case OPC2_32_RR_OR_GE_U:
5810fcf5ef2aSThomas Huth gen_accumulating_cond(TCG_COND_GEU, cpu_gpr_d[r3], cpu_gpr_d[r1],
5811fcf5ef2aSThomas Huth cpu_gpr_d[r2], &tcg_gen_or_tl);
5812fcf5ef2aSThomas Huth break;
5813fcf5ef2aSThomas Huth case OPC2_32_RR_OR_LT:
5814fcf5ef2aSThomas Huth gen_accumulating_cond(TCG_COND_LT, cpu_gpr_d[r3], cpu_gpr_d[r1],
5815fcf5ef2aSThomas Huth cpu_gpr_d[r2], &tcg_gen_or_tl);
5816fcf5ef2aSThomas Huth break;
5817fcf5ef2aSThomas Huth case OPC2_32_RR_OR_LT_U:
5818fcf5ef2aSThomas Huth gen_accumulating_cond(TCG_COND_LTU, cpu_gpr_d[r3], cpu_gpr_d[r1],
5819fcf5ef2aSThomas Huth cpu_gpr_d[r2], &tcg_gen_or_tl);
5820fcf5ef2aSThomas Huth break;
5821fcf5ef2aSThomas Huth case OPC2_32_RR_OR_NE:
5822fcf5ef2aSThomas Huth gen_accumulating_cond(TCG_COND_NE, cpu_gpr_d[r3], cpu_gpr_d[r1],
5823fcf5ef2aSThomas Huth cpu_gpr_d[r2], &tcg_gen_or_tl);
5824fcf5ef2aSThomas Huth break;
5825fcf5ef2aSThomas Huth case OPC2_32_RR_SAT_B:
5826fcf5ef2aSThomas Huth gen_saturate(cpu_gpr_d[r3], cpu_gpr_d[r1], 0x7f, -0x80);
5827fcf5ef2aSThomas Huth break;
5828fcf5ef2aSThomas Huth case OPC2_32_RR_SAT_BU:
5829fcf5ef2aSThomas Huth gen_saturate_u(cpu_gpr_d[r3], cpu_gpr_d[r1], 0xff);
5830fcf5ef2aSThomas Huth break;
5831fcf5ef2aSThomas Huth case OPC2_32_RR_SAT_H:
5832fcf5ef2aSThomas Huth gen_saturate(cpu_gpr_d[r3], cpu_gpr_d[r1], 0x7fff, -0x8000);
5833fcf5ef2aSThomas Huth break;
5834fcf5ef2aSThomas Huth case OPC2_32_RR_SAT_HU:
5835fcf5ef2aSThomas Huth gen_saturate_u(cpu_gpr_d[r3], cpu_gpr_d[r1], 0xffff);
5836fcf5ef2aSThomas Huth break;
5837fcf5ef2aSThomas Huth case OPC2_32_RR_SH_EQ:
5838fcf5ef2aSThomas Huth gen_sh_cond(TCG_COND_EQ, cpu_gpr_d[r3], cpu_gpr_d[r1],
5839fcf5ef2aSThomas Huth cpu_gpr_d[r2]);
5840fcf5ef2aSThomas Huth break;
5841fcf5ef2aSThomas Huth case OPC2_32_RR_SH_GE:
5842fcf5ef2aSThomas Huth gen_sh_cond(TCG_COND_GE, cpu_gpr_d[r3], cpu_gpr_d[r1],
5843fcf5ef2aSThomas Huth cpu_gpr_d[r2]);
5844fcf5ef2aSThomas Huth break;
5845fcf5ef2aSThomas Huth case OPC2_32_RR_SH_GE_U:
5846fcf5ef2aSThomas Huth gen_sh_cond(TCG_COND_GEU, cpu_gpr_d[r3], cpu_gpr_d[r1],
5847fcf5ef2aSThomas Huth cpu_gpr_d[r2]);
5848fcf5ef2aSThomas Huth break;
5849fcf5ef2aSThomas Huth case OPC2_32_RR_SH_LT:
5850fcf5ef2aSThomas Huth gen_sh_cond(TCG_COND_LT, cpu_gpr_d[r3], cpu_gpr_d[r1],
5851fcf5ef2aSThomas Huth cpu_gpr_d[r2]);
5852fcf5ef2aSThomas Huth break;
5853fcf5ef2aSThomas Huth case OPC2_32_RR_SH_LT_U:
5854fcf5ef2aSThomas Huth gen_sh_cond(TCG_COND_LTU, cpu_gpr_d[r3], cpu_gpr_d[r1],
5855fcf5ef2aSThomas Huth cpu_gpr_d[r2]);
5856fcf5ef2aSThomas Huth break;
5857fcf5ef2aSThomas Huth case OPC2_32_RR_SH_NE:
5858fcf5ef2aSThomas Huth gen_sh_cond(TCG_COND_NE, cpu_gpr_d[r3], cpu_gpr_d[r1],
5859fcf5ef2aSThomas Huth cpu_gpr_d[r2]);
5860fcf5ef2aSThomas Huth break;
5861fcf5ef2aSThomas Huth case OPC2_32_RR_SUB:
5862fcf5ef2aSThomas Huth gen_sub_d(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2]);
5863fcf5ef2aSThomas Huth break;
5864fcf5ef2aSThomas Huth case OPC2_32_RR_SUB_B:
5865ad75a51eSRichard Henderson gen_helper_sub_b(cpu_gpr_d[r3], tcg_env, cpu_gpr_d[r1], cpu_gpr_d[r2]);
5866fcf5ef2aSThomas Huth break;
5867fcf5ef2aSThomas Huth case OPC2_32_RR_SUB_H:
5868ad75a51eSRichard Henderson gen_helper_sub_h(cpu_gpr_d[r3], tcg_env, cpu_gpr_d[r1], cpu_gpr_d[r2]);
5869fcf5ef2aSThomas Huth break;
5870fcf5ef2aSThomas Huth case OPC2_32_RR_SUBC:
5871fcf5ef2aSThomas Huth gen_subc_CC(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2]);
5872fcf5ef2aSThomas Huth break;
5873fcf5ef2aSThomas Huth case OPC2_32_RR_SUBS:
5874fcf5ef2aSThomas Huth gen_subs(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2]);
5875fcf5ef2aSThomas Huth break;
5876fcf5ef2aSThomas Huth case OPC2_32_RR_SUBS_U:
5877fcf5ef2aSThomas Huth gen_subsu(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2]);
5878fcf5ef2aSThomas Huth break;
5879fcf5ef2aSThomas Huth case OPC2_32_RR_SUBS_H:
5880ad75a51eSRichard Henderson gen_helper_sub_h_ssov(cpu_gpr_d[r3], tcg_env, cpu_gpr_d[r1],
5881fcf5ef2aSThomas Huth cpu_gpr_d[r2]);
5882fcf5ef2aSThomas Huth break;
5883fcf5ef2aSThomas Huth case OPC2_32_RR_SUBS_HU:
5884ad75a51eSRichard Henderson gen_helper_sub_h_suov(cpu_gpr_d[r3], tcg_env, cpu_gpr_d[r1],
5885fcf5ef2aSThomas Huth cpu_gpr_d[r2]);
5886fcf5ef2aSThomas Huth break;
5887fcf5ef2aSThomas Huth case OPC2_32_RR_SUBX:
5888fcf5ef2aSThomas Huth gen_sub_CC(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2]);
5889fcf5ef2aSThomas Huth break;
5890fcf5ef2aSThomas Huth case OPC2_32_RR_XOR_EQ:
5891fcf5ef2aSThomas Huth gen_accumulating_cond(TCG_COND_EQ, cpu_gpr_d[r3], cpu_gpr_d[r1],
5892fcf5ef2aSThomas Huth cpu_gpr_d[r2], &tcg_gen_xor_tl);
5893fcf5ef2aSThomas Huth break;
5894fcf5ef2aSThomas Huth case OPC2_32_RR_XOR_GE:
5895fcf5ef2aSThomas Huth gen_accumulating_cond(TCG_COND_GE, cpu_gpr_d[r3], cpu_gpr_d[r1],
5896fcf5ef2aSThomas Huth cpu_gpr_d[r2], &tcg_gen_xor_tl);
5897fcf5ef2aSThomas Huth break;
5898fcf5ef2aSThomas Huth case OPC2_32_RR_XOR_GE_U:
5899fcf5ef2aSThomas Huth gen_accumulating_cond(TCG_COND_GEU, cpu_gpr_d[r3], cpu_gpr_d[r1],
5900fcf5ef2aSThomas Huth cpu_gpr_d[r2], &tcg_gen_xor_tl);
5901fcf5ef2aSThomas Huth break;
5902fcf5ef2aSThomas Huth case OPC2_32_RR_XOR_LT:
5903fcf5ef2aSThomas Huth gen_accumulating_cond(TCG_COND_LT, cpu_gpr_d[r3], cpu_gpr_d[r1],
5904fcf5ef2aSThomas Huth cpu_gpr_d[r2], &tcg_gen_xor_tl);
5905fcf5ef2aSThomas Huth break;
5906fcf5ef2aSThomas Huth case OPC2_32_RR_XOR_LT_U:
5907fcf5ef2aSThomas Huth gen_accumulating_cond(TCG_COND_LTU, cpu_gpr_d[r3], cpu_gpr_d[r1],
5908fcf5ef2aSThomas Huth cpu_gpr_d[r2], &tcg_gen_xor_tl);
5909fcf5ef2aSThomas Huth break;
5910fcf5ef2aSThomas Huth case OPC2_32_RR_XOR_NE:
5911fcf5ef2aSThomas Huth gen_accumulating_cond(TCG_COND_NE, cpu_gpr_d[r3], cpu_gpr_d[r1],
5912fcf5ef2aSThomas Huth cpu_gpr_d[r2], &tcg_gen_xor_tl);
5913fcf5ef2aSThomas Huth break;
5914fcf5ef2aSThomas Huth default:
5915fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
5916fcf5ef2aSThomas Huth }
5917fcf5ef2aSThomas Huth }
5918fcf5ef2aSThomas Huth
decode_rr_logical_shift(DisasContext * ctx)59192db92a0cSBastian Koppelmann static void decode_rr_logical_shift(DisasContext *ctx)
5920fcf5ef2aSThomas Huth {
5921fcf5ef2aSThomas Huth uint32_t op2;
5922fcf5ef2aSThomas Huth int r3, r2, r1;
5923fcf5ef2aSThomas Huth
5924fcf5ef2aSThomas Huth r3 = MASK_OP_RR_D(ctx->opcode);
5925fcf5ef2aSThomas Huth r2 = MASK_OP_RR_S2(ctx->opcode);
5926fcf5ef2aSThomas Huth r1 = MASK_OP_RR_S1(ctx->opcode);
5927fcf5ef2aSThomas Huth op2 = MASK_OP_RR_OP2(ctx->opcode);
5928fcf5ef2aSThomas Huth
5929fcf5ef2aSThomas Huth switch (op2) {
5930fcf5ef2aSThomas Huth case OPC2_32_RR_AND:
5931fcf5ef2aSThomas Huth tcg_gen_and_tl(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2]);
5932fcf5ef2aSThomas Huth break;
5933fcf5ef2aSThomas Huth case OPC2_32_RR_ANDN:
5934fcf5ef2aSThomas Huth tcg_gen_andc_tl(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2]);
5935fcf5ef2aSThomas Huth break;
5936fcf5ef2aSThomas Huth case OPC2_32_RR_CLO:
59370efa8208SRichard Henderson tcg_gen_not_tl(cpu_gpr_d[r3], cpu_gpr_d[r1]);
59380efa8208SRichard Henderson tcg_gen_clzi_tl(cpu_gpr_d[r3], cpu_gpr_d[r3], TARGET_LONG_BITS);
5939fcf5ef2aSThomas Huth break;
5940fcf5ef2aSThomas Huth case OPC2_32_RR_CLO_H:
5941fcf5ef2aSThomas Huth gen_helper_clo_h(cpu_gpr_d[r3], cpu_gpr_d[r1]);
5942fcf5ef2aSThomas Huth break;
5943fcf5ef2aSThomas Huth case OPC2_32_RR_CLS:
594416256947SRichard Henderson tcg_gen_clrsb_tl(cpu_gpr_d[r3], cpu_gpr_d[r1]);
5945fcf5ef2aSThomas Huth break;
5946fcf5ef2aSThomas Huth case OPC2_32_RR_CLS_H:
5947fcf5ef2aSThomas Huth gen_helper_cls_h(cpu_gpr_d[r3], cpu_gpr_d[r1]);
5948fcf5ef2aSThomas Huth break;
5949fcf5ef2aSThomas Huth case OPC2_32_RR_CLZ:
59500efa8208SRichard Henderson tcg_gen_clzi_tl(cpu_gpr_d[r3], cpu_gpr_d[r1], TARGET_LONG_BITS);
5951fcf5ef2aSThomas Huth break;
5952fcf5ef2aSThomas Huth case OPC2_32_RR_CLZ_H:
5953fcf5ef2aSThomas Huth gen_helper_clz_h(cpu_gpr_d[r3], cpu_gpr_d[r1]);
5954fcf5ef2aSThomas Huth break;
5955fcf5ef2aSThomas Huth case OPC2_32_RR_NAND:
5956fcf5ef2aSThomas Huth tcg_gen_nand_tl(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2]);
5957fcf5ef2aSThomas Huth break;
5958fcf5ef2aSThomas Huth case OPC2_32_RR_NOR:
5959fcf5ef2aSThomas Huth tcg_gen_nor_tl(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2]);
5960fcf5ef2aSThomas Huth break;
5961fcf5ef2aSThomas Huth case OPC2_32_RR_OR:
5962fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2]);
5963fcf5ef2aSThomas Huth break;
5964fcf5ef2aSThomas Huth case OPC2_32_RR_ORN:
5965fcf5ef2aSThomas Huth tcg_gen_orc_tl(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2]);
5966fcf5ef2aSThomas Huth break;
5967fcf5ef2aSThomas Huth case OPC2_32_RR_SH:
5968fcf5ef2aSThomas Huth gen_helper_sh(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2]);
5969fcf5ef2aSThomas Huth break;
5970fcf5ef2aSThomas Huth case OPC2_32_RR_SH_H:
5971fcf5ef2aSThomas Huth gen_helper_sh_h(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2]);
5972fcf5ef2aSThomas Huth break;
5973fcf5ef2aSThomas Huth case OPC2_32_RR_SHA:
5974ad75a51eSRichard Henderson gen_helper_sha(cpu_gpr_d[r3], tcg_env, cpu_gpr_d[r1], cpu_gpr_d[r2]);
5975fcf5ef2aSThomas Huth break;
5976fcf5ef2aSThomas Huth case OPC2_32_RR_SHA_H:
5977fcf5ef2aSThomas Huth gen_helper_sha_h(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2]);
5978fcf5ef2aSThomas Huth break;
5979fcf5ef2aSThomas Huth case OPC2_32_RR_SHAS:
5980fcf5ef2aSThomas Huth gen_shas(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2]);
5981fcf5ef2aSThomas Huth break;
5982fcf5ef2aSThomas Huth case OPC2_32_RR_XNOR:
5983fcf5ef2aSThomas Huth tcg_gen_eqv_tl(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2]);
5984fcf5ef2aSThomas Huth break;
5985fcf5ef2aSThomas Huth case OPC2_32_RR_XOR:
5986fcf5ef2aSThomas Huth tcg_gen_xor_tl(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2]);
5987fcf5ef2aSThomas Huth break;
5988fcf5ef2aSThomas Huth default:
5989fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
5990fcf5ef2aSThomas Huth }
5991fcf5ef2aSThomas Huth }
5992fcf5ef2aSThomas Huth
decode_rr_address(DisasContext * ctx)59932db92a0cSBastian Koppelmann static void decode_rr_address(DisasContext *ctx)
5994fcf5ef2aSThomas Huth {
5995fcf5ef2aSThomas Huth uint32_t op2, n;
5996fcf5ef2aSThomas Huth int r1, r2, r3;
5997fcf5ef2aSThomas Huth TCGv temp;
5998fcf5ef2aSThomas Huth
5999fcf5ef2aSThomas Huth op2 = MASK_OP_RR_OP2(ctx->opcode);
6000fcf5ef2aSThomas Huth r3 = MASK_OP_RR_D(ctx->opcode);
6001fcf5ef2aSThomas Huth r2 = MASK_OP_RR_S2(ctx->opcode);
6002fcf5ef2aSThomas Huth r1 = MASK_OP_RR_S1(ctx->opcode);
6003fcf5ef2aSThomas Huth n = MASK_OP_RR_N(ctx->opcode);
6004fcf5ef2aSThomas Huth
6005fcf5ef2aSThomas Huth switch (op2) {
6006fcf5ef2aSThomas Huth case OPC2_32_RR_ADD_A:
6007fcf5ef2aSThomas Huth tcg_gen_add_tl(cpu_gpr_a[r3], cpu_gpr_a[r1], cpu_gpr_a[r2]);
6008fcf5ef2aSThomas Huth break;
6009fcf5ef2aSThomas Huth case OPC2_32_RR_ADDSC_A:
6010fcf5ef2aSThomas Huth temp = tcg_temp_new();
6011fcf5ef2aSThomas Huth tcg_gen_shli_tl(temp, cpu_gpr_d[r1], n);
6012fcf5ef2aSThomas Huth tcg_gen_add_tl(cpu_gpr_a[r3], cpu_gpr_a[r2], temp);
6013fcf5ef2aSThomas Huth break;
6014fcf5ef2aSThomas Huth case OPC2_32_RR_ADDSC_AT:
6015fcf5ef2aSThomas Huth temp = tcg_temp_new();
6016fcf5ef2aSThomas Huth tcg_gen_sari_tl(temp, cpu_gpr_d[r1], 3);
6017fcf5ef2aSThomas Huth tcg_gen_add_tl(temp, cpu_gpr_a[r2], temp);
6018fcf5ef2aSThomas Huth tcg_gen_andi_tl(cpu_gpr_a[r3], temp, 0xFFFFFFFC);
6019fcf5ef2aSThomas Huth break;
6020fcf5ef2aSThomas Huth case OPC2_32_RR_EQ_A:
6021fcf5ef2aSThomas Huth tcg_gen_setcond_tl(TCG_COND_EQ, cpu_gpr_d[r3], cpu_gpr_a[r1],
6022fcf5ef2aSThomas Huth cpu_gpr_a[r2]);
6023fcf5ef2aSThomas Huth break;
6024fcf5ef2aSThomas Huth case OPC2_32_RR_EQZ:
6025fcf5ef2aSThomas Huth tcg_gen_setcondi_tl(TCG_COND_EQ, cpu_gpr_d[r3], cpu_gpr_a[r1], 0);
6026fcf5ef2aSThomas Huth break;
6027fcf5ef2aSThomas Huth case OPC2_32_RR_GE_A:
6028fcf5ef2aSThomas Huth tcg_gen_setcond_tl(TCG_COND_GEU, cpu_gpr_d[r3], cpu_gpr_a[r1],
6029fcf5ef2aSThomas Huth cpu_gpr_a[r2]);
6030fcf5ef2aSThomas Huth break;
6031fcf5ef2aSThomas Huth case OPC2_32_RR_LT_A:
6032fcf5ef2aSThomas Huth tcg_gen_setcond_tl(TCG_COND_LTU, cpu_gpr_d[r3], cpu_gpr_a[r1],
6033fcf5ef2aSThomas Huth cpu_gpr_a[r2]);
6034fcf5ef2aSThomas Huth break;
6035fcf5ef2aSThomas Huth case OPC2_32_RR_MOV_A:
6036fcf5ef2aSThomas Huth tcg_gen_mov_tl(cpu_gpr_a[r3], cpu_gpr_d[r2]);
6037fcf5ef2aSThomas Huth break;
6038fcf5ef2aSThomas Huth case OPC2_32_RR_MOV_AA:
6039fcf5ef2aSThomas Huth tcg_gen_mov_tl(cpu_gpr_a[r3], cpu_gpr_a[r2]);
6040fcf5ef2aSThomas Huth break;
6041fcf5ef2aSThomas Huth case OPC2_32_RR_MOV_D:
6042fcf5ef2aSThomas Huth tcg_gen_mov_tl(cpu_gpr_d[r3], cpu_gpr_a[r2]);
6043fcf5ef2aSThomas Huth break;
6044fcf5ef2aSThomas Huth case OPC2_32_RR_NE_A:
6045fcf5ef2aSThomas Huth tcg_gen_setcond_tl(TCG_COND_NE, cpu_gpr_d[r3], cpu_gpr_a[r1],
6046fcf5ef2aSThomas Huth cpu_gpr_a[r2]);
6047fcf5ef2aSThomas Huth break;
6048fcf5ef2aSThomas Huth case OPC2_32_RR_NEZ_A:
6049fcf5ef2aSThomas Huth tcg_gen_setcondi_tl(TCG_COND_NE, cpu_gpr_d[r3], cpu_gpr_a[r1], 0);
6050fcf5ef2aSThomas Huth break;
6051fcf5ef2aSThomas Huth case OPC2_32_RR_SUB_A:
6052fcf5ef2aSThomas Huth tcg_gen_sub_tl(cpu_gpr_a[r3], cpu_gpr_a[r1], cpu_gpr_a[r2]);
6053fcf5ef2aSThomas Huth break;
6054fcf5ef2aSThomas Huth default:
6055fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
6056fcf5ef2aSThomas Huth }
6057fcf5ef2aSThomas Huth }
6058fcf5ef2aSThomas Huth
decode_rr_idirect(DisasContext * ctx)60592db92a0cSBastian Koppelmann static void decode_rr_idirect(DisasContext *ctx)
6060fcf5ef2aSThomas Huth {
6061fcf5ef2aSThomas Huth uint32_t op2;
6062fcf5ef2aSThomas Huth int r1;
6063fcf5ef2aSThomas Huth
6064fcf5ef2aSThomas Huth op2 = MASK_OP_RR_OP2(ctx->opcode);
6065fcf5ef2aSThomas Huth r1 = MASK_OP_RR_S1(ctx->opcode);
6066fcf5ef2aSThomas Huth
6067fcf5ef2aSThomas Huth switch (op2) {
6068fcf5ef2aSThomas Huth case OPC2_32_RR_JI:
6069fcf5ef2aSThomas Huth tcg_gen_andi_tl(cpu_PC, cpu_gpr_a[r1], ~0x1);
6070fcf5ef2aSThomas Huth break;
6071fcf5ef2aSThomas Huth case OPC2_32_RR_JLI:
6072fcf5ef2aSThomas Huth tcg_gen_andi_tl(cpu_PC, cpu_gpr_a[r1], ~0x1);
60738da70480SBastian Koppelmann tcg_gen_movi_tl(cpu_gpr_a[11], ctx->pc_succ_insn);
6074fcf5ef2aSThomas Huth break;
6075fcf5ef2aSThomas Huth case OPC2_32_RR_CALLI:
60766b9f5a42SBastian Koppelmann gen_helper_1arg(call, ctx->pc_succ_insn);
6077fcf5ef2aSThomas Huth tcg_gen_andi_tl(cpu_PC, cpu_gpr_a[r1], ~0x1);
6078fcf5ef2aSThomas Huth break;
6079fcf5ef2aSThomas Huth case OPC2_32_RR_FCALLI:
6080fcf5ef2aSThomas Huth gen_fcall_save_ctx(ctx);
6081fcf5ef2aSThomas Huth tcg_gen_andi_tl(cpu_PC, cpu_gpr_a[r1], ~0x1);
6082fcf5ef2aSThomas Huth break;
6083fcf5ef2aSThomas Huth default:
6084fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
6085d8f466afSBastian Koppelmann return;
6086fcf5ef2aSThomas Huth }
6087d8f466afSBastian Koppelmann ctx->base.is_jmp = DISAS_JUMP;
6088fcf5ef2aSThomas Huth }
6089fcf5ef2aSThomas Huth
decode_rr_divide(DisasContext * ctx)60902db92a0cSBastian Koppelmann static void decode_rr_divide(DisasContext *ctx)
6091fcf5ef2aSThomas Huth {
6092fcf5ef2aSThomas Huth uint32_t op2;
6093fcf5ef2aSThomas Huth int r1, r2, r3;
6094fcf5ef2aSThomas Huth
6095fcf5ef2aSThomas Huth TCGv temp, temp2, temp3;
6096fcf5ef2aSThomas Huth
6097fcf5ef2aSThomas Huth op2 = MASK_OP_RR_OP2(ctx->opcode);
6098fcf5ef2aSThomas Huth r3 = MASK_OP_RR_D(ctx->opcode);
6099fcf5ef2aSThomas Huth r2 = MASK_OP_RR_S2(ctx->opcode);
6100fcf5ef2aSThomas Huth r1 = MASK_OP_RR_S1(ctx->opcode);
6101fcf5ef2aSThomas Huth
6102fcf5ef2aSThomas Huth switch (op2) {
6103fcf5ef2aSThomas Huth case OPC2_32_RR_BMERGE:
6104fcf5ef2aSThomas Huth gen_helper_bmerge(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2]);
6105fcf5ef2aSThomas Huth break;
6106fcf5ef2aSThomas Huth case OPC2_32_RR_BSPLIT:
6107fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
6108fcf5ef2aSThomas Huth gen_bsplit(cpu_gpr_d[r3], cpu_gpr_d[r3+1], cpu_gpr_d[r1]);
6109fcf5ef2aSThomas Huth break;
6110fcf5ef2aSThomas Huth case OPC2_32_RR_DVINIT_B:
6111fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
61122db92a0cSBastian Koppelmann gen_dvinit_b(ctx, cpu_gpr_d[r3], cpu_gpr_d[r3+1], cpu_gpr_d[r1],
6113fcf5ef2aSThomas Huth cpu_gpr_d[r2]);
6114fcf5ef2aSThomas Huth break;
6115fcf5ef2aSThomas Huth case OPC2_32_RR_DVINIT_BU:
6116fcf5ef2aSThomas Huth temp = tcg_temp_new();
6117fcf5ef2aSThomas Huth temp2 = tcg_temp_new();
6118fcf5ef2aSThomas Huth temp3 = tcg_temp_new();
6119fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
6120fcf5ef2aSThomas Huth tcg_gen_shri_tl(temp3, cpu_gpr_d[r1], 8);
6121fcf5ef2aSThomas Huth /* reset av */
6122fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_PSW_AV, 0);
612344ee3bafSBastian Koppelmann if (!has_feature(ctx, TRICORE_FEATURE_131)) {
6124fcf5ef2aSThomas Huth /* overflow = (abs(D[r3+1]) >= abs(D[r2])) */
61252f8036d2SPhilippe Mathieu-Daudé tcg_gen_abs_tl(temp, temp3);
61262f8036d2SPhilippe Mathieu-Daudé tcg_gen_abs_tl(temp2, cpu_gpr_d[r2]);
6127fcf5ef2aSThomas Huth tcg_gen_setcond_tl(TCG_COND_GE, cpu_PSW_V, temp, temp2);
6128fcf5ef2aSThomas Huth } else {
6129fcf5ef2aSThomas Huth /* overflow = (D[b] == 0) */
6130fcf5ef2aSThomas Huth tcg_gen_setcondi_tl(TCG_COND_EQ, cpu_PSW_V, cpu_gpr_d[r2], 0);
6131fcf5ef2aSThomas Huth }
6132fcf5ef2aSThomas Huth tcg_gen_shli_tl(cpu_PSW_V, cpu_PSW_V, 31);
6133fcf5ef2aSThomas Huth /* sv */
6134fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SV, cpu_PSW_SV, cpu_PSW_V);
6135fcf5ef2aSThomas Huth /* write result */
6136fcf5ef2aSThomas Huth tcg_gen_shli_tl(cpu_gpr_d[r3], cpu_gpr_d[r1], 24);
6137fcf5ef2aSThomas Huth tcg_gen_mov_tl(cpu_gpr_d[r3+1], temp3);
6138fcf5ef2aSThomas Huth break;
6139fcf5ef2aSThomas Huth case OPC2_32_RR_DVINIT_H:
6140fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
61412db92a0cSBastian Koppelmann gen_dvinit_h(ctx, cpu_gpr_d[r3], cpu_gpr_d[r3+1], cpu_gpr_d[r1],
6142fcf5ef2aSThomas Huth cpu_gpr_d[r2]);
6143fcf5ef2aSThomas Huth break;
6144fcf5ef2aSThomas Huth case OPC2_32_RR_DVINIT_HU:
6145fcf5ef2aSThomas Huth temp = tcg_temp_new();
6146fcf5ef2aSThomas Huth temp2 = tcg_temp_new();
6147fcf5ef2aSThomas Huth temp3 = tcg_temp_new();
6148fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
6149fcf5ef2aSThomas Huth tcg_gen_shri_tl(temp3, cpu_gpr_d[r1], 16);
6150fcf5ef2aSThomas Huth /* reset av */
6151fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_PSW_AV, 0);
615244ee3bafSBastian Koppelmann if (!has_feature(ctx, TRICORE_FEATURE_131)) {
6153fcf5ef2aSThomas Huth /* overflow = (abs(D[r3+1]) >= abs(D[r2])) */
61542f8036d2SPhilippe Mathieu-Daudé tcg_gen_abs_tl(temp, temp3);
61552f8036d2SPhilippe Mathieu-Daudé tcg_gen_abs_tl(temp2, cpu_gpr_d[r2]);
6156fcf5ef2aSThomas Huth tcg_gen_setcond_tl(TCG_COND_GE, cpu_PSW_V, temp, temp2);
6157fcf5ef2aSThomas Huth } else {
6158fcf5ef2aSThomas Huth /* overflow = (D[b] == 0) */
6159fcf5ef2aSThomas Huth tcg_gen_setcondi_tl(TCG_COND_EQ, cpu_PSW_V, cpu_gpr_d[r2], 0);
6160fcf5ef2aSThomas Huth }
6161fcf5ef2aSThomas Huth tcg_gen_shli_tl(cpu_PSW_V, cpu_PSW_V, 31);
6162fcf5ef2aSThomas Huth /* sv */
6163fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SV, cpu_PSW_SV, cpu_PSW_V);
6164fcf5ef2aSThomas Huth /* write result */
6165fcf5ef2aSThomas Huth tcg_gen_shli_tl(cpu_gpr_d[r3], cpu_gpr_d[r1], 16);
6166fcf5ef2aSThomas Huth tcg_gen_mov_tl(cpu_gpr_d[r3+1], temp3);
6167fcf5ef2aSThomas Huth break;
6168fcf5ef2aSThomas Huth case OPC2_32_RR_DVINIT:
6169fcf5ef2aSThomas Huth temp = tcg_temp_new();
6170fcf5ef2aSThomas Huth temp2 = tcg_temp_new();
6171fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
6172fcf5ef2aSThomas Huth /* overflow = ((D[b] == 0) ||
6173fcf5ef2aSThomas Huth ((D[b] == 0xFFFFFFFF) && (D[a] == 0x80000000))) */
6174fcf5ef2aSThomas Huth tcg_gen_setcondi_tl(TCG_COND_EQ, temp, cpu_gpr_d[r2], 0xffffffff);
6175fcf5ef2aSThomas Huth tcg_gen_setcondi_tl(TCG_COND_EQ, temp2, cpu_gpr_d[r1], 0x80000000);
6176fcf5ef2aSThomas Huth tcg_gen_and_tl(temp, temp, temp2);
6177fcf5ef2aSThomas Huth tcg_gen_setcondi_tl(TCG_COND_EQ, temp2, cpu_gpr_d[r2], 0);
6178fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_V, temp, temp2);
6179fcf5ef2aSThomas Huth tcg_gen_shli_tl(cpu_PSW_V, cpu_PSW_V, 31);
6180fcf5ef2aSThomas Huth /* sv */
6181fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SV, cpu_PSW_SV, cpu_PSW_V);
6182fcf5ef2aSThomas Huth /* reset av */
6183fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_PSW_AV, 0);
6184fcf5ef2aSThomas Huth /* write result */
6185fcf5ef2aSThomas Huth tcg_gen_mov_tl(cpu_gpr_d[r3], cpu_gpr_d[r1]);
6186fcf5ef2aSThomas Huth /* sign extend to high reg */
6187fcf5ef2aSThomas Huth tcg_gen_sari_tl(cpu_gpr_d[r3+1], cpu_gpr_d[r1], 31);
6188fcf5ef2aSThomas Huth break;
6189fcf5ef2aSThomas Huth case OPC2_32_RR_DVINIT_U:
61906991777eSBastian Koppelmann CHECK_REG_PAIR(r3);
6191fcf5ef2aSThomas Huth /* overflow = (D[b] == 0) */
6192fcf5ef2aSThomas Huth tcg_gen_setcondi_tl(TCG_COND_EQ, cpu_PSW_V, cpu_gpr_d[r2], 0);
6193fcf5ef2aSThomas Huth tcg_gen_shli_tl(cpu_PSW_V, cpu_PSW_V, 31);
6194fcf5ef2aSThomas Huth /* sv */
6195fcf5ef2aSThomas Huth tcg_gen_or_tl(cpu_PSW_SV, cpu_PSW_SV, cpu_PSW_V);
6196fcf5ef2aSThomas Huth /* reset av */
6197fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_PSW_AV, 0);
6198fcf5ef2aSThomas Huth /* write result */
6199fcf5ef2aSThomas Huth tcg_gen_mov_tl(cpu_gpr_d[r3], cpu_gpr_d[r1]);
6200fcf5ef2aSThomas Huth /* zero extend to high reg*/
6201fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_gpr_d[r3+1], 0);
6202fcf5ef2aSThomas Huth break;
6203fcf5ef2aSThomas Huth case OPC2_32_RR_PARITY:
6204fcf5ef2aSThomas Huth gen_helper_parity(cpu_gpr_d[r3], cpu_gpr_d[r1]);
6205fcf5ef2aSThomas Huth break;
6206fcf5ef2aSThomas Huth case OPC2_32_RR_UNPACK:
6207fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
6208fcf5ef2aSThomas Huth gen_unpack(cpu_gpr_d[r3], cpu_gpr_d[r3+1], cpu_gpr_d[r1]);
6209fcf5ef2aSThomas Huth break;
62100eaafe33SBastian Koppelmann case OPC2_32_RR_CRC32_B:
62110eaafe33SBastian Koppelmann if (has_feature(ctx, TRICORE_FEATURE_162)) {
62120eaafe33SBastian Koppelmann gen_helper_crc32b(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2]);
62130eaafe33SBastian Koppelmann } else {
62140eaafe33SBastian Koppelmann generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
62150eaafe33SBastian Koppelmann }
62160eaafe33SBastian Koppelmann break;
6217dc0b4368SBastian Koppelmann case OPC2_32_RR_CRC32: /* CRC32B.W in 1.6.2 */
621844ee3bafSBastian Koppelmann if (has_feature(ctx, TRICORE_FEATURE_161)) {
6219dc0b4368SBastian Koppelmann gen_helper_crc32_be(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2]);
6220fcf5ef2aSThomas Huth } else {
6221fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
6222fcf5ef2aSThomas Huth }
6223fcf5ef2aSThomas Huth break;
6224dc0b4368SBastian Koppelmann case OPC2_32_RR_CRC32L_W:
6225dc0b4368SBastian Koppelmann if (has_feature(ctx, TRICORE_FEATURE_162)) {
6226dc0b4368SBastian Koppelmann gen_helper_crc32_le(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2]);
6227dc0b4368SBastian Koppelmann } else {
6228dc0b4368SBastian Koppelmann generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
6229dc0b4368SBastian Koppelmann }
6230dc0b4368SBastian Koppelmann break;
6231dc0b4368SBastian Koppelmann
6232fd6f446aSBastian Koppelmann case OPC2_32_RR_POPCNT_W:
6233fd6f446aSBastian Koppelmann if (has_feature(ctx, TRICORE_FEATURE_162)) {
6234fd6f446aSBastian Koppelmann tcg_gen_ctpop_tl(cpu_gpr_d[r3], cpu_gpr_d[r1]);
6235fd6f446aSBastian Koppelmann } else {
6236fd6f446aSBastian Koppelmann generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
6237fd6f446aSBastian Koppelmann }
6238fd6f446aSBastian Koppelmann break;
6239fcf5ef2aSThomas Huth case OPC2_32_RR_DIV:
624044ee3bafSBastian Koppelmann if (has_feature(ctx, TRICORE_FEATURE_16)) {
62416991777eSBastian Koppelmann CHECK_REG_PAIR(r3);
6242fcf5ef2aSThomas Huth GEN_HELPER_RR(divide, cpu_gpr_d[r3], cpu_gpr_d[r3+1], cpu_gpr_d[r1],
6243fcf5ef2aSThomas Huth cpu_gpr_d[r2]);
6244fcf5ef2aSThomas Huth } else {
6245fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
6246fcf5ef2aSThomas Huth }
6247fcf5ef2aSThomas Huth break;
6248fcf5ef2aSThomas Huth case OPC2_32_RR_DIV_U:
624944ee3bafSBastian Koppelmann if (has_feature(ctx, TRICORE_FEATURE_16)) {
62506991777eSBastian Koppelmann CHECK_REG_PAIR(r3);
6251fcf5ef2aSThomas Huth GEN_HELPER_RR(divide_u, cpu_gpr_d[r3], cpu_gpr_d[r3+1],
6252fcf5ef2aSThomas Huth cpu_gpr_d[r1], cpu_gpr_d[r2]);
6253fcf5ef2aSThomas Huth } else {
6254fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
6255fcf5ef2aSThomas Huth }
6256fcf5ef2aSThomas Huth break;
6257fcf5ef2aSThomas Huth case OPC2_32_RR_MUL_F:
6258ad75a51eSRichard Henderson gen_helper_fmul(cpu_gpr_d[r3], tcg_env, cpu_gpr_d[r1], cpu_gpr_d[r2]);
6259fcf5ef2aSThomas Huth break;
6260fcf5ef2aSThomas Huth case OPC2_32_RR_DIV_F:
6261ad75a51eSRichard Henderson gen_helper_fdiv(cpu_gpr_d[r3], tcg_env, cpu_gpr_d[r1], cpu_gpr_d[r2]);
6262fcf5ef2aSThomas Huth break;
6263815061b9SBastian Koppelmann case OPC2_32_RR_FTOHP:
6264815061b9SBastian Koppelmann if (has_feature(ctx, TRICORE_FEATURE_162)) {
6265ad75a51eSRichard Henderson gen_helper_ftohp(cpu_gpr_d[r3], tcg_env, cpu_gpr_d[r1]);
6266815061b9SBastian Koppelmann } else {
6267815061b9SBastian Koppelmann generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
6268815061b9SBastian Koppelmann }
6269815061b9SBastian Koppelmann break;
62705e0e06d9SBastian Koppelmann case OPC2_32_RR_HPTOF:
62715e0e06d9SBastian Koppelmann if (has_feature(ctx, TRICORE_FEATURE_162)) {
6272ad75a51eSRichard Henderson gen_helper_hptof(cpu_gpr_d[r3], tcg_env, cpu_gpr_d[r1]);
62735e0e06d9SBastian Koppelmann } else {
62745e0e06d9SBastian Koppelmann generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
62755e0e06d9SBastian Koppelmann }
62765e0e06d9SBastian Koppelmann break;
6277fcf5ef2aSThomas Huth case OPC2_32_RR_CMP_F:
6278ad75a51eSRichard Henderson gen_helper_fcmp(cpu_gpr_d[r3], tcg_env, cpu_gpr_d[r1], cpu_gpr_d[r2]);
6279fcf5ef2aSThomas Huth break;
6280fcf5ef2aSThomas Huth case OPC2_32_RR_FTOI:
6281ad75a51eSRichard Henderson gen_helper_ftoi(cpu_gpr_d[r3], tcg_env, cpu_gpr_d[r1]);
6282fcf5ef2aSThomas Huth break;
6283fcf5ef2aSThomas Huth case OPC2_32_RR_ITOF:
6284ad75a51eSRichard Henderson gen_helper_itof(cpu_gpr_d[r3], tcg_env, cpu_gpr_d[r1]);
6285fcf5ef2aSThomas Huth break;
62862bdbe356SBastian Koppelmann case OPC2_32_RR_FTOU:
6287ad75a51eSRichard Henderson gen_helper_ftou(cpu_gpr_d[r3], tcg_env, cpu_gpr_d[r1]);
62882bdbe356SBastian Koppelmann break;
62898f75983dSBastian Koppelmann case OPC2_32_RR_FTOUZ:
62904f79db47SBastian Koppelmann if (has_feature(ctx, TRICORE_FEATURE_131)) {
6291ad75a51eSRichard Henderson gen_helper_ftouz(cpu_gpr_d[r3], tcg_env, cpu_gpr_d[r1]);
62924f79db47SBastian Koppelmann } else {
62934f79db47SBastian Koppelmann generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
62944f79db47SBastian Koppelmann }
62958f75983dSBastian Koppelmann break;
629650788a3fSBastian Koppelmann case OPC2_32_RR_UPDFL:
6297ad75a51eSRichard Henderson gen_helper_updfl(tcg_env, cpu_gpr_d[r1]);
629850788a3fSBastian Koppelmann break;
62994e6fd2e3SDavid Brenken case OPC2_32_RR_UTOF:
6300ad75a51eSRichard Henderson gen_helper_utof(cpu_gpr_d[r3], tcg_env, cpu_gpr_d[r1]);
63014e6fd2e3SDavid Brenken break;
63021fa79fb0SDavid Brenken case OPC2_32_RR_FTOIZ:
6303ad75a51eSRichard Henderson gen_helper_ftoiz(cpu_gpr_d[r3], tcg_env, cpu_gpr_d[r1]);
63041fa79fb0SDavid Brenken break;
63058317ea06SAndreas Konopik case OPC2_32_RR_QSEED_F:
6306ad75a51eSRichard Henderson gen_helper_qseed(cpu_gpr_d[r3], tcg_env, cpu_gpr_d[r1]);
63078317ea06SAndreas Konopik break;
6308fcf5ef2aSThomas Huth default:
6309fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
6310fcf5ef2aSThomas Huth }
6311fcf5ef2aSThomas Huth }
6312fcf5ef2aSThomas Huth
6313fcf5ef2aSThomas Huth /* RR1 Format */
decode_rr1_mul(DisasContext * ctx)63142db92a0cSBastian Koppelmann static void decode_rr1_mul(DisasContext *ctx)
6315fcf5ef2aSThomas Huth {
6316fcf5ef2aSThomas Huth uint32_t op2;
6317fcf5ef2aSThomas Huth
6318fcf5ef2aSThomas Huth int r1, r2, r3;
6319fcf5ef2aSThomas Huth TCGv n;
6320fcf5ef2aSThomas Huth TCGv_i64 temp64;
6321fcf5ef2aSThomas Huth
6322fcf5ef2aSThomas Huth r1 = MASK_OP_RR1_S1(ctx->opcode);
6323fcf5ef2aSThomas Huth r2 = MASK_OP_RR1_S2(ctx->opcode);
6324fcf5ef2aSThomas Huth r3 = MASK_OP_RR1_D(ctx->opcode);
6325151293c2SRichard Henderson n = tcg_constant_i32(MASK_OP_RR1_N(ctx->opcode));
6326fcf5ef2aSThomas Huth op2 = MASK_OP_RR1_OP2(ctx->opcode);
6327fcf5ef2aSThomas Huth
6328fcf5ef2aSThomas Huth switch (op2) {
6329fcf5ef2aSThomas Huth case OPC2_32_RR1_MUL_H_32_LL:
6330fcf5ef2aSThomas Huth temp64 = tcg_temp_new_i64();
6331fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
6332fcf5ef2aSThomas Huth GEN_HELPER_LL(mul_h, temp64, cpu_gpr_d[r1], cpu_gpr_d[r2], n);
6333fcf5ef2aSThomas Huth tcg_gen_extr_i64_i32(cpu_gpr_d[r3], cpu_gpr_d[r3+1], temp64);
6334fcf5ef2aSThomas Huth gen_calc_usb_mul_h(cpu_gpr_d[r3], cpu_gpr_d[r3+1]);
6335fcf5ef2aSThomas Huth break;
6336fcf5ef2aSThomas Huth case OPC2_32_RR1_MUL_H_32_LU:
6337fcf5ef2aSThomas Huth temp64 = tcg_temp_new_i64();
6338fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
6339fcf5ef2aSThomas Huth GEN_HELPER_LU(mul_h, temp64, cpu_gpr_d[r1], cpu_gpr_d[r2], n);
6340fcf5ef2aSThomas Huth tcg_gen_extr_i64_i32(cpu_gpr_d[r3], cpu_gpr_d[r3+1], temp64);
6341fcf5ef2aSThomas Huth gen_calc_usb_mul_h(cpu_gpr_d[r3], cpu_gpr_d[r3+1]);
6342fcf5ef2aSThomas Huth break;
6343fcf5ef2aSThomas Huth case OPC2_32_RR1_MUL_H_32_UL:
6344fcf5ef2aSThomas Huth temp64 = tcg_temp_new_i64();
6345fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
6346fcf5ef2aSThomas Huth GEN_HELPER_UL(mul_h, temp64, cpu_gpr_d[r1], cpu_gpr_d[r2], n);
6347fcf5ef2aSThomas Huth tcg_gen_extr_i64_i32(cpu_gpr_d[r3], cpu_gpr_d[r3+1], temp64);
6348fcf5ef2aSThomas Huth gen_calc_usb_mul_h(cpu_gpr_d[r3], cpu_gpr_d[r3+1]);
6349fcf5ef2aSThomas Huth break;
6350fcf5ef2aSThomas Huth case OPC2_32_RR1_MUL_H_32_UU:
6351fcf5ef2aSThomas Huth temp64 = tcg_temp_new_i64();
6352fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
6353fcf5ef2aSThomas Huth GEN_HELPER_UU(mul_h, temp64, cpu_gpr_d[r1], cpu_gpr_d[r2], n);
6354fcf5ef2aSThomas Huth tcg_gen_extr_i64_i32(cpu_gpr_d[r3], cpu_gpr_d[r3+1], temp64);
6355fcf5ef2aSThomas Huth gen_calc_usb_mul_h(cpu_gpr_d[r3], cpu_gpr_d[r3+1]);
6356fcf5ef2aSThomas Huth break;
6357fcf5ef2aSThomas Huth case OPC2_32_RR1_MULM_H_64_LL:
6358fcf5ef2aSThomas Huth temp64 = tcg_temp_new_i64();
6359fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
6360fcf5ef2aSThomas Huth GEN_HELPER_LL(mulm_h, temp64, cpu_gpr_d[r1], cpu_gpr_d[r2], n);
6361fcf5ef2aSThomas Huth tcg_gen_extr_i64_i32(cpu_gpr_d[r3], cpu_gpr_d[r3+1], temp64);
6362fcf5ef2aSThomas Huth /* reset V bit */
6363fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_PSW_V, 0);
6364fcf5ef2aSThomas Huth /* reset AV bit */
6365fcf5ef2aSThomas Huth tcg_gen_mov_tl(cpu_PSW_AV, cpu_PSW_V);
6366fcf5ef2aSThomas Huth break;
6367fcf5ef2aSThomas Huth case OPC2_32_RR1_MULM_H_64_LU:
6368fcf5ef2aSThomas Huth temp64 = tcg_temp_new_i64();
6369fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
6370fcf5ef2aSThomas Huth GEN_HELPER_LU(mulm_h, temp64, cpu_gpr_d[r1], cpu_gpr_d[r2], n);
6371fcf5ef2aSThomas Huth tcg_gen_extr_i64_i32(cpu_gpr_d[r3], cpu_gpr_d[r3+1], temp64);
6372fcf5ef2aSThomas Huth /* reset V bit */
6373fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_PSW_V, 0);
6374fcf5ef2aSThomas Huth /* reset AV bit */
6375fcf5ef2aSThomas Huth tcg_gen_mov_tl(cpu_PSW_AV, cpu_PSW_V);
6376fcf5ef2aSThomas Huth break;
6377fcf5ef2aSThomas Huth case OPC2_32_RR1_MULM_H_64_UL:
6378fcf5ef2aSThomas Huth temp64 = tcg_temp_new_i64();
6379fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
6380fcf5ef2aSThomas Huth GEN_HELPER_UL(mulm_h, temp64, cpu_gpr_d[r1], cpu_gpr_d[r2], n);
6381fcf5ef2aSThomas Huth tcg_gen_extr_i64_i32(cpu_gpr_d[r3], cpu_gpr_d[r3+1], temp64);
6382fcf5ef2aSThomas Huth /* reset V bit */
6383fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_PSW_V, 0);
6384fcf5ef2aSThomas Huth /* reset AV bit */
6385fcf5ef2aSThomas Huth tcg_gen_mov_tl(cpu_PSW_AV, cpu_PSW_V);
6386fcf5ef2aSThomas Huth break;
6387fcf5ef2aSThomas Huth case OPC2_32_RR1_MULM_H_64_UU:
6388fcf5ef2aSThomas Huth temp64 = tcg_temp_new_i64();
6389fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
6390fcf5ef2aSThomas Huth GEN_HELPER_UU(mulm_h, temp64, cpu_gpr_d[r1], cpu_gpr_d[r2], n);
6391fcf5ef2aSThomas Huth tcg_gen_extr_i64_i32(cpu_gpr_d[r3], cpu_gpr_d[r3+1], temp64);
6392fcf5ef2aSThomas Huth /* reset V bit */
6393fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_PSW_V, 0);
6394fcf5ef2aSThomas Huth /* reset AV bit */
6395fcf5ef2aSThomas Huth tcg_gen_mov_tl(cpu_PSW_AV, cpu_PSW_V);
6396fcf5ef2aSThomas Huth break;
6397fcf5ef2aSThomas Huth case OPC2_32_RR1_MULR_H_16_LL:
6398fcf5ef2aSThomas Huth GEN_HELPER_LL(mulr_h, cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2], n);
6399fcf5ef2aSThomas Huth gen_calc_usb_mulr_h(cpu_gpr_d[r3]);
6400fcf5ef2aSThomas Huth break;
6401fcf5ef2aSThomas Huth case OPC2_32_RR1_MULR_H_16_LU:
6402fcf5ef2aSThomas Huth GEN_HELPER_LU(mulr_h, cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2], n);
6403fcf5ef2aSThomas Huth gen_calc_usb_mulr_h(cpu_gpr_d[r3]);
6404fcf5ef2aSThomas Huth break;
6405fcf5ef2aSThomas Huth case OPC2_32_RR1_MULR_H_16_UL:
6406fcf5ef2aSThomas Huth GEN_HELPER_UL(mulr_h, cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2], n);
6407fcf5ef2aSThomas Huth gen_calc_usb_mulr_h(cpu_gpr_d[r3]);
6408fcf5ef2aSThomas Huth break;
6409fcf5ef2aSThomas Huth case OPC2_32_RR1_MULR_H_16_UU:
6410fcf5ef2aSThomas Huth GEN_HELPER_UU(mulr_h, cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2], n);
6411fcf5ef2aSThomas Huth gen_calc_usb_mulr_h(cpu_gpr_d[r3]);
6412fcf5ef2aSThomas Huth break;
6413fcf5ef2aSThomas Huth default:
6414fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
6415fcf5ef2aSThomas Huth }
6416fcf5ef2aSThomas Huth }
6417fcf5ef2aSThomas Huth
decode_rr1_mulq(DisasContext * ctx)64182db92a0cSBastian Koppelmann static void decode_rr1_mulq(DisasContext *ctx)
6419fcf5ef2aSThomas Huth {
6420fcf5ef2aSThomas Huth uint32_t op2;
6421fcf5ef2aSThomas Huth int r1, r2, r3;
6422fcf5ef2aSThomas Huth uint32_t n;
6423fcf5ef2aSThomas Huth
6424fcf5ef2aSThomas Huth TCGv temp, temp2;
6425fcf5ef2aSThomas Huth
6426fcf5ef2aSThomas Huth r1 = MASK_OP_RR1_S1(ctx->opcode);
6427fcf5ef2aSThomas Huth r2 = MASK_OP_RR1_S2(ctx->opcode);
6428fcf5ef2aSThomas Huth r3 = MASK_OP_RR1_D(ctx->opcode);
6429fcf5ef2aSThomas Huth n = MASK_OP_RR1_N(ctx->opcode);
6430fcf5ef2aSThomas Huth op2 = MASK_OP_RR1_OP2(ctx->opcode);
6431fcf5ef2aSThomas Huth
6432fcf5ef2aSThomas Huth temp = tcg_temp_new();
6433fcf5ef2aSThomas Huth temp2 = tcg_temp_new();
6434fcf5ef2aSThomas Huth
6435fcf5ef2aSThomas Huth switch (op2) {
6436fcf5ef2aSThomas Huth case OPC2_32_RR1_MUL_Q_32:
6437fcf5ef2aSThomas Huth gen_mul_q(cpu_gpr_d[r3], temp, cpu_gpr_d[r1], cpu_gpr_d[r2], n, 32);
6438fcf5ef2aSThomas Huth break;
6439fcf5ef2aSThomas Huth case OPC2_32_RR1_MUL_Q_64:
6440fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
6441fcf5ef2aSThomas Huth gen_mul_q(cpu_gpr_d[r3], cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2],
6442fcf5ef2aSThomas Huth n, 0);
6443fcf5ef2aSThomas Huth break;
6444fcf5ef2aSThomas Huth case OPC2_32_RR1_MUL_Q_32_L:
6445fcf5ef2aSThomas Huth tcg_gen_ext16s_tl(temp, cpu_gpr_d[r2]);
6446fcf5ef2aSThomas Huth gen_mul_q(cpu_gpr_d[r3], temp, cpu_gpr_d[r1], temp, n, 16);
6447fcf5ef2aSThomas Huth break;
6448fcf5ef2aSThomas Huth case OPC2_32_RR1_MUL_Q_64_L:
6449fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
6450fcf5ef2aSThomas Huth tcg_gen_ext16s_tl(temp, cpu_gpr_d[r2]);
6451fcf5ef2aSThomas Huth gen_mul_q(cpu_gpr_d[r3], cpu_gpr_d[r3+1], cpu_gpr_d[r1], temp, n, 0);
6452fcf5ef2aSThomas Huth break;
6453fcf5ef2aSThomas Huth case OPC2_32_RR1_MUL_Q_32_U:
6454fcf5ef2aSThomas Huth tcg_gen_sari_tl(temp, cpu_gpr_d[r2], 16);
6455fcf5ef2aSThomas Huth gen_mul_q(cpu_gpr_d[r3], temp, cpu_gpr_d[r1], temp, n, 16);
6456fcf5ef2aSThomas Huth break;
6457fcf5ef2aSThomas Huth case OPC2_32_RR1_MUL_Q_64_U:
6458fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
6459fcf5ef2aSThomas Huth tcg_gen_sari_tl(temp, cpu_gpr_d[r2], 16);
6460fcf5ef2aSThomas Huth gen_mul_q(cpu_gpr_d[r3], cpu_gpr_d[r3+1], cpu_gpr_d[r1], temp, n, 0);
6461fcf5ef2aSThomas Huth break;
6462fcf5ef2aSThomas Huth case OPC2_32_RR1_MUL_Q_32_LL:
6463fcf5ef2aSThomas Huth tcg_gen_ext16s_tl(temp, cpu_gpr_d[r1]);
6464fcf5ef2aSThomas Huth tcg_gen_ext16s_tl(temp2, cpu_gpr_d[r2]);
6465fcf5ef2aSThomas Huth gen_mul_q_16(cpu_gpr_d[r3], temp, temp2, n);
6466fcf5ef2aSThomas Huth break;
6467fcf5ef2aSThomas Huth case OPC2_32_RR1_MUL_Q_32_UU:
6468fcf5ef2aSThomas Huth tcg_gen_sari_tl(temp, cpu_gpr_d[r1], 16);
6469fcf5ef2aSThomas Huth tcg_gen_sari_tl(temp2, cpu_gpr_d[r2], 16);
6470fcf5ef2aSThomas Huth gen_mul_q_16(cpu_gpr_d[r3], temp, temp2, n);
6471fcf5ef2aSThomas Huth break;
6472fcf5ef2aSThomas Huth case OPC2_32_RR1_MULR_Q_32_L:
6473fcf5ef2aSThomas Huth tcg_gen_ext16s_tl(temp, cpu_gpr_d[r1]);
6474fcf5ef2aSThomas Huth tcg_gen_ext16s_tl(temp2, cpu_gpr_d[r2]);
6475fcf5ef2aSThomas Huth gen_mulr_q(cpu_gpr_d[r3], temp, temp2, n);
6476fcf5ef2aSThomas Huth break;
6477fcf5ef2aSThomas Huth case OPC2_32_RR1_MULR_Q_32_U:
6478fcf5ef2aSThomas Huth tcg_gen_sari_tl(temp, cpu_gpr_d[r1], 16);
6479fcf5ef2aSThomas Huth tcg_gen_sari_tl(temp2, cpu_gpr_d[r2], 16);
6480fcf5ef2aSThomas Huth gen_mulr_q(cpu_gpr_d[r3], temp, temp2, n);
6481fcf5ef2aSThomas Huth break;
6482fcf5ef2aSThomas Huth default:
6483fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
6484fcf5ef2aSThomas Huth }
6485fcf5ef2aSThomas Huth }
6486fcf5ef2aSThomas Huth
6487fcf5ef2aSThomas Huth /* RR2 format */
decode_rr2_mul(DisasContext * ctx)64882db92a0cSBastian Koppelmann static void decode_rr2_mul(DisasContext *ctx)
6489fcf5ef2aSThomas Huth {
6490fcf5ef2aSThomas Huth uint32_t op2;
6491fcf5ef2aSThomas Huth int r1, r2, r3;
6492fcf5ef2aSThomas Huth
6493fcf5ef2aSThomas Huth op2 = MASK_OP_RR2_OP2(ctx->opcode);
6494fcf5ef2aSThomas Huth r1 = MASK_OP_RR2_S1(ctx->opcode);
6495fcf5ef2aSThomas Huth r2 = MASK_OP_RR2_S2(ctx->opcode);
6496fcf5ef2aSThomas Huth r3 = MASK_OP_RR2_D(ctx->opcode);
6497fcf5ef2aSThomas Huth switch (op2) {
6498fcf5ef2aSThomas Huth case OPC2_32_RR2_MUL_32:
6499fcf5ef2aSThomas Huth gen_mul_i32s(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2]);
6500fcf5ef2aSThomas Huth break;
6501fcf5ef2aSThomas Huth case OPC2_32_RR2_MUL_64:
6502fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
6503fcf5ef2aSThomas Huth gen_mul_i64s(cpu_gpr_d[r3], cpu_gpr_d[r3+1], cpu_gpr_d[r1],
6504fcf5ef2aSThomas Huth cpu_gpr_d[r2]);
6505fcf5ef2aSThomas Huth break;
6506fcf5ef2aSThomas Huth case OPC2_32_RR2_MULS_32:
6507ad75a51eSRichard Henderson gen_helper_mul_ssov(cpu_gpr_d[r3], tcg_env, cpu_gpr_d[r1],
6508fcf5ef2aSThomas Huth cpu_gpr_d[r2]);
6509fcf5ef2aSThomas Huth break;
6510fcf5ef2aSThomas Huth case OPC2_32_RR2_MUL_U_64:
6511fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
6512fcf5ef2aSThomas Huth gen_mul_i64u(cpu_gpr_d[r3], cpu_gpr_d[r3+1], cpu_gpr_d[r1],
6513fcf5ef2aSThomas Huth cpu_gpr_d[r2]);
6514fcf5ef2aSThomas Huth break;
6515fcf5ef2aSThomas Huth case OPC2_32_RR2_MULS_U_32:
6516ad75a51eSRichard Henderson gen_helper_mul_suov(cpu_gpr_d[r3], tcg_env, cpu_gpr_d[r1],
6517fcf5ef2aSThomas Huth cpu_gpr_d[r2]);
6518fcf5ef2aSThomas Huth break;
6519fcf5ef2aSThomas Huth default:
6520fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
6521fcf5ef2aSThomas Huth }
6522fcf5ef2aSThomas Huth }
6523fcf5ef2aSThomas Huth
6524fcf5ef2aSThomas Huth /* RRPW format */
decode_rrpw_extract_insert(DisasContext * ctx)65252db92a0cSBastian Koppelmann static void decode_rrpw_extract_insert(DisasContext *ctx)
6526fcf5ef2aSThomas Huth {
6527fcf5ef2aSThomas Huth uint32_t op2;
6528fcf5ef2aSThomas Huth int r1, r2, r3;
6529fcf5ef2aSThomas Huth int32_t pos, width;
653000747984SBastian Koppelmann TCGv temp;
6531fcf5ef2aSThomas Huth
6532fcf5ef2aSThomas Huth op2 = MASK_OP_RRPW_OP2(ctx->opcode);
6533fcf5ef2aSThomas Huth r1 = MASK_OP_RRPW_S1(ctx->opcode);
6534fcf5ef2aSThomas Huth r2 = MASK_OP_RRPW_S2(ctx->opcode);
6535fcf5ef2aSThomas Huth r3 = MASK_OP_RRPW_D(ctx->opcode);
6536fcf5ef2aSThomas Huth pos = MASK_OP_RRPW_POS(ctx->opcode);
6537fcf5ef2aSThomas Huth width = MASK_OP_RRPW_WIDTH(ctx->opcode);
6538fcf5ef2aSThomas Huth
6539fcf5ef2aSThomas Huth switch (op2) {
6540fcf5ef2aSThomas Huth case OPC2_32_RRPW_EXTR:
6541a21993c7SBastian Koppelmann if (width == 0) {
6542a21993c7SBastian Koppelmann tcg_gen_movi_tl(cpu_gpr_d[r3], 0);
65438b8bb295SRichard Henderson } else if (pos + width <= 32) {
65448b8bb295SRichard Henderson tcg_gen_sextract_tl(cpu_gpr_d[r3], cpu_gpr_d[r1], pos, width);
6545fcf5ef2aSThomas Huth }
6546fcf5ef2aSThomas Huth break;
6547fcf5ef2aSThomas Huth case OPC2_32_RRPW_EXTR_U:
6548fcf5ef2aSThomas Huth if (width == 0) {
6549fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_gpr_d[r3], 0);
6550fcf5ef2aSThomas Huth } else {
65518b8bb295SRichard Henderson tcg_gen_extract_tl(cpu_gpr_d[r3], cpu_gpr_d[r1], pos, width);
6552fcf5ef2aSThomas Huth }
6553fcf5ef2aSThomas Huth break;
6554fcf5ef2aSThomas Huth case OPC2_32_RRPW_IMASK:
6555fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
655600747984SBastian Koppelmann
65579b620609SAndreas Konopik if (pos + width <= 32) {
655800747984SBastian Koppelmann temp = tcg_temp_new();
655900747984SBastian Koppelmann tcg_gen_movi_tl(temp, ((1u << width) - 1) << pos);
6560fcf5ef2aSThomas Huth tcg_gen_shli_tl(cpu_gpr_d[r3], cpu_gpr_d[r2], pos);
656100747984SBastian Koppelmann tcg_gen_mov_tl(cpu_gpr_d[r3 + 1], temp);
6562fcf5ef2aSThomas Huth }
656300747984SBastian Koppelmann
6564fcf5ef2aSThomas Huth break;
6565fcf5ef2aSThomas Huth case OPC2_32_RRPW_INSERT:
656623fa6f56SBastian Koppelmann /* tcg_gen_deposit_tl() does not handle the case of width = 0 */
656723fa6f56SBastian Koppelmann if (width == 0) {
656823fa6f56SBastian Koppelmann tcg_gen_mov_tl(cpu_gpr_d[r3], cpu_gpr_d[r1]);
656923fa6f56SBastian Koppelmann } else if (pos + width <= 32) {
6570fcf5ef2aSThomas Huth tcg_gen_deposit_tl(cpu_gpr_d[r3], cpu_gpr_d[r1], cpu_gpr_d[r2],
657161b26250SDavid Brenken pos, width);
6572fcf5ef2aSThomas Huth }
6573fcf5ef2aSThomas Huth break;
6574fcf5ef2aSThomas Huth default:
6575fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
6576fcf5ef2aSThomas Huth }
6577fcf5ef2aSThomas Huth }
6578fcf5ef2aSThomas Huth
6579fcf5ef2aSThomas Huth /* RRR format */
decode_rrr_cond_select(DisasContext * ctx)65802db92a0cSBastian Koppelmann static void decode_rrr_cond_select(DisasContext *ctx)
6581fcf5ef2aSThomas Huth {
6582fcf5ef2aSThomas Huth uint32_t op2;
6583fcf5ef2aSThomas Huth int r1, r2, r3, r4;
6584fcf5ef2aSThomas Huth TCGv temp;
6585fcf5ef2aSThomas Huth
6586fcf5ef2aSThomas Huth op2 = MASK_OP_RRR_OP2(ctx->opcode);
6587fcf5ef2aSThomas Huth r1 = MASK_OP_RRR_S1(ctx->opcode);
6588fcf5ef2aSThomas Huth r2 = MASK_OP_RRR_S2(ctx->opcode);
6589fcf5ef2aSThomas Huth r3 = MASK_OP_RRR_S3(ctx->opcode);
6590fcf5ef2aSThomas Huth r4 = MASK_OP_RRR_D(ctx->opcode);
6591fcf5ef2aSThomas Huth
6592fcf5ef2aSThomas Huth switch (op2) {
6593fcf5ef2aSThomas Huth case OPC2_32_RRR_CADD:
6594fcf5ef2aSThomas Huth gen_cond_add(TCG_COND_NE, cpu_gpr_d[r1], cpu_gpr_d[r2],
6595fcf5ef2aSThomas Huth cpu_gpr_d[r4], cpu_gpr_d[r3]);
6596fcf5ef2aSThomas Huth break;
6597fcf5ef2aSThomas Huth case OPC2_32_RRR_CADDN:
6598fcf5ef2aSThomas Huth gen_cond_add(TCG_COND_EQ, cpu_gpr_d[r1], cpu_gpr_d[r2], cpu_gpr_d[r4],
6599fcf5ef2aSThomas Huth cpu_gpr_d[r3]);
6600fcf5ef2aSThomas Huth break;
6601fcf5ef2aSThomas Huth case OPC2_32_RRR_CSUB:
6602fcf5ef2aSThomas Huth gen_cond_sub(TCG_COND_NE, cpu_gpr_d[r1], cpu_gpr_d[r2], cpu_gpr_d[r4],
6603fcf5ef2aSThomas Huth cpu_gpr_d[r3]);
6604fcf5ef2aSThomas Huth break;
6605fcf5ef2aSThomas Huth case OPC2_32_RRR_CSUBN:
6606fcf5ef2aSThomas Huth gen_cond_sub(TCG_COND_EQ, cpu_gpr_d[r1], cpu_gpr_d[r2], cpu_gpr_d[r4],
6607fcf5ef2aSThomas Huth cpu_gpr_d[r3]);
6608fcf5ef2aSThomas Huth break;
6609fcf5ef2aSThomas Huth case OPC2_32_RRR_SEL:
6610151293c2SRichard Henderson temp = tcg_constant_i32(0);
6611fcf5ef2aSThomas Huth tcg_gen_movcond_tl(TCG_COND_NE, cpu_gpr_d[r4], cpu_gpr_d[r3], temp,
6612fcf5ef2aSThomas Huth cpu_gpr_d[r1], cpu_gpr_d[r2]);
6613fcf5ef2aSThomas Huth break;
6614fcf5ef2aSThomas Huth case OPC2_32_RRR_SELN:
6615151293c2SRichard Henderson temp = tcg_constant_i32(0);
6616fcf5ef2aSThomas Huth tcg_gen_movcond_tl(TCG_COND_EQ, cpu_gpr_d[r4], cpu_gpr_d[r3], temp,
6617fcf5ef2aSThomas Huth cpu_gpr_d[r1], cpu_gpr_d[r2]);
6618fcf5ef2aSThomas Huth break;
6619fcf5ef2aSThomas Huth default:
6620fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
6621fcf5ef2aSThomas Huth }
6622fcf5ef2aSThomas Huth }
6623fcf5ef2aSThomas Huth
decode_rrr_divide(DisasContext * ctx)66242db92a0cSBastian Koppelmann static void decode_rrr_divide(DisasContext *ctx)
6625fcf5ef2aSThomas Huth {
6626fcf5ef2aSThomas Huth uint32_t op2;
6627fcf5ef2aSThomas Huth
6628fcf5ef2aSThomas Huth int r1, r2, r3, r4;
6629fcf5ef2aSThomas Huth
6630fcf5ef2aSThomas Huth op2 = MASK_OP_RRR_OP2(ctx->opcode);
6631fcf5ef2aSThomas Huth r1 = MASK_OP_RRR_S1(ctx->opcode);
6632fcf5ef2aSThomas Huth r2 = MASK_OP_RRR_S2(ctx->opcode);
6633fcf5ef2aSThomas Huth r3 = MASK_OP_RRR_S3(ctx->opcode);
6634fcf5ef2aSThomas Huth r4 = MASK_OP_RRR_D(ctx->opcode);
6635fcf5ef2aSThomas Huth
6636fcf5ef2aSThomas Huth switch (op2) {
6637fcf5ef2aSThomas Huth case OPC2_32_RRR_DVADJ:
6638fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
6639fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
6640fcf5ef2aSThomas Huth GEN_HELPER_RRR(dvadj, cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
6641fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r2]);
6642fcf5ef2aSThomas Huth break;
6643fcf5ef2aSThomas Huth case OPC2_32_RRR_DVSTEP:
6644fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
6645fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
6646fcf5ef2aSThomas Huth GEN_HELPER_RRR(dvstep, cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
6647fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r2]);
6648fcf5ef2aSThomas Huth break;
6649fcf5ef2aSThomas Huth case OPC2_32_RRR_DVSTEP_U:
6650fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
6651fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
6652fcf5ef2aSThomas Huth GEN_HELPER_RRR(dvstep_u, cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
6653fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r2]);
6654fcf5ef2aSThomas Huth break;
6655fcf5ef2aSThomas Huth case OPC2_32_RRR_IXMAX:
6656fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
6657fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
6658fcf5ef2aSThomas Huth GEN_HELPER_RRR(ixmax, cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
6659fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r2]);
6660fcf5ef2aSThomas Huth break;
6661fcf5ef2aSThomas Huth case OPC2_32_RRR_IXMAX_U:
6662fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
6663fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
6664fcf5ef2aSThomas Huth GEN_HELPER_RRR(ixmax_u, cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
6665fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r2]);
6666fcf5ef2aSThomas Huth break;
6667fcf5ef2aSThomas Huth case OPC2_32_RRR_IXMIN:
6668fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
6669fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
6670fcf5ef2aSThomas Huth GEN_HELPER_RRR(ixmin, cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
6671fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r2]);
6672fcf5ef2aSThomas Huth break;
6673fcf5ef2aSThomas Huth case OPC2_32_RRR_IXMIN_U:
6674fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
6675fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
6676fcf5ef2aSThomas Huth GEN_HELPER_RRR(ixmin_u, cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
6677fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r2]);
6678fcf5ef2aSThomas Huth break;
6679fcf5ef2aSThomas Huth case OPC2_32_RRR_PACK:
6680fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
6681fcf5ef2aSThomas Huth gen_helper_pack(cpu_gpr_d[r4], cpu_PSW_C, cpu_gpr_d[r3],
6682fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1]);
6683fcf5ef2aSThomas Huth break;
66843e2a5107SBastian Koppelmann case OPC2_32_RRR_CRCN:
66853e2a5107SBastian Koppelmann if (has_feature(ctx, TRICORE_FEATURE_162)) {
66863e2a5107SBastian Koppelmann gen_helper_crcn(cpu_gpr_d[r4], cpu_gpr_d[r1], cpu_gpr_d[r2],
66873e2a5107SBastian Koppelmann cpu_gpr_d[r3]);
66883e2a5107SBastian Koppelmann } else {
66893e2a5107SBastian Koppelmann generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
66903e2a5107SBastian Koppelmann }
66913e2a5107SBastian Koppelmann break;
6692fcf5ef2aSThomas Huth case OPC2_32_RRR_ADD_F:
6693ad75a51eSRichard Henderson gen_helper_fadd(cpu_gpr_d[r4], tcg_env, cpu_gpr_d[r1], cpu_gpr_d[r3]);
6694fcf5ef2aSThomas Huth break;
6695fcf5ef2aSThomas Huth case OPC2_32_RRR_SUB_F:
6696ad75a51eSRichard Henderson gen_helper_fsub(cpu_gpr_d[r4], tcg_env, cpu_gpr_d[r1], cpu_gpr_d[r3]);
6697fcf5ef2aSThomas Huth break;
6698ddd7feadSBastian Koppelmann case OPC2_32_RRR_MADD_F:
6699ad75a51eSRichard Henderson gen_helper_fmadd(cpu_gpr_d[r4], tcg_env, cpu_gpr_d[r1],
6700ddd7feadSBastian Koppelmann cpu_gpr_d[r2], cpu_gpr_d[r3]);
6701ddd7feadSBastian Koppelmann break;
6702ddd7feadSBastian Koppelmann case OPC2_32_RRR_MSUB_F:
6703ad75a51eSRichard Henderson gen_helper_fmsub(cpu_gpr_d[r4], tcg_env, cpu_gpr_d[r1],
6704ddd7feadSBastian Koppelmann cpu_gpr_d[r2], cpu_gpr_d[r3]);
6705ddd7feadSBastian Koppelmann break;
6706fcf5ef2aSThomas Huth default:
6707fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
6708fcf5ef2aSThomas Huth }
6709fcf5ef2aSThomas Huth }
6710fcf5ef2aSThomas Huth
6711fcf5ef2aSThomas Huth /* RRR2 format */
decode_rrr2_madd(DisasContext * ctx)67122db92a0cSBastian Koppelmann static void decode_rrr2_madd(DisasContext *ctx)
6713fcf5ef2aSThomas Huth {
6714fcf5ef2aSThomas Huth uint32_t op2;
6715fcf5ef2aSThomas Huth uint32_t r1, r2, r3, r4;
6716fcf5ef2aSThomas Huth
6717fcf5ef2aSThomas Huth op2 = MASK_OP_RRR2_OP2(ctx->opcode);
6718fcf5ef2aSThomas Huth r1 = MASK_OP_RRR2_S1(ctx->opcode);
6719fcf5ef2aSThomas Huth r2 = MASK_OP_RRR2_S2(ctx->opcode);
6720fcf5ef2aSThomas Huth r3 = MASK_OP_RRR2_S3(ctx->opcode);
6721fcf5ef2aSThomas Huth r4 = MASK_OP_RRR2_D(ctx->opcode);
6722fcf5ef2aSThomas Huth switch (op2) {
6723fcf5ef2aSThomas Huth case OPC2_32_RRR2_MADD_32:
6724fcf5ef2aSThomas Huth gen_madd32_d(cpu_gpr_d[r4], cpu_gpr_d[r1], cpu_gpr_d[r3],
6725fcf5ef2aSThomas Huth cpu_gpr_d[r2]);
6726fcf5ef2aSThomas Huth break;
6727fcf5ef2aSThomas Huth case OPC2_32_RRR2_MADD_64:
6728fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
6729fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
6730fcf5ef2aSThomas Huth gen_madd64_d(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r1],
6731fcf5ef2aSThomas Huth cpu_gpr_d[r3], cpu_gpr_d[r3+1], cpu_gpr_d[r2]);
6732fcf5ef2aSThomas Huth break;
6733fcf5ef2aSThomas Huth case OPC2_32_RRR2_MADDS_32:
6734ad75a51eSRichard Henderson gen_helper_madd32_ssov(cpu_gpr_d[r4], tcg_env, cpu_gpr_d[r1],
6735fcf5ef2aSThomas Huth cpu_gpr_d[r3], cpu_gpr_d[r2]);
6736fcf5ef2aSThomas Huth break;
6737fcf5ef2aSThomas Huth case OPC2_32_RRR2_MADDS_64:
6738fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
6739fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
6740fcf5ef2aSThomas Huth gen_madds_64(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r1],
6741fcf5ef2aSThomas Huth cpu_gpr_d[r3], cpu_gpr_d[r3+1], cpu_gpr_d[r2]);
6742fcf5ef2aSThomas Huth break;
6743fcf5ef2aSThomas Huth case OPC2_32_RRR2_MADD_U_64:
6744fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
6745fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
6746fcf5ef2aSThomas Huth gen_maddu64_d(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r1],
6747fcf5ef2aSThomas Huth cpu_gpr_d[r3], cpu_gpr_d[r3+1], cpu_gpr_d[r2]);
6748fcf5ef2aSThomas Huth break;
6749fcf5ef2aSThomas Huth case OPC2_32_RRR2_MADDS_U_32:
6750ad75a51eSRichard Henderson gen_helper_madd32_suov(cpu_gpr_d[r4], tcg_env, cpu_gpr_d[r1],
6751fcf5ef2aSThomas Huth cpu_gpr_d[r3], cpu_gpr_d[r2]);
6752fcf5ef2aSThomas Huth break;
6753fcf5ef2aSThomas Huth case OPC2_32_RRR2_MADDS_U_64:
6754fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
6755fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
6756fcf5ef2aSThomas Huth gen_maddsu_64(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r1],
6757fcf5ef2aSThomas Huth cpu_gpr_d[r3], cpu_gpr_d[r3+1], cpu_gpr_d[r2]);
6758fcf5ef2aSThomas Huth break;
6759fcf5ef2aSThomas Huth default:
6760fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
6761fcf5ef2aSThomas Huth }
6762fcf5ef2aSThomas Huth }
6763fcf5ef2aSThomas Huth
decode_rrr2_msub(DisasContext * ctx)67642db92a0cSBastian Koppelmann static void decode_rrr2_msub(DisasContext *ctx)
6765fcf5ef2aSThomas Huth {
6766fcf5ef2aSThomas Huth uint32_t op2;
6767fcf5ef2aSThomas Huth uint32_t r1, r2, r3, r4;
6768fcf5ef2aSThomas Huth
6769fcf5ef2aSThomas Huth op2 = MASK_OP_RRR2_OP2(ctx->opcode);
6770fcf5ef2aSThomas Huth r1 = MASK_OP_RRR2_S1(ctx->opcode);
6771fcf5ef2aSThomas Huth r2 = MASK_OP_RRR2_S2(ctx->opcode);
6772fcf5ef2aSThomas Huth r3 = MASK_OP_RRR2_S3(ctx->opcode);
6773fcf5ef2aSThomas Huth r4 = MASK_OP_RRR2_D(ctx->opcode);
6774fcf5ef2aSThomas Huth
6775fcf5ef2aSThomas Huth switch (op2) {
6776fcf5ef2aSThomas Huth case OPC2_32_RRR2_MSUB_32:
6777fcf5ef2aSThomas Huth gen_msub32_d(cpu_gpr_d[r4], cpu_gpr_d[r1], cpu_gpr_d[r3],
6778fcf5ef2aSThomas Huth cpu_gpr_d[r2]);
6779fcf5ef2aSThomas Huth break;
6780fcf5ef2aSThomas Huth case OPC2_32_RRR2_MSUB_64:
6781fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
6782fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
6783fcf5ef2aSThomas Huth gen_msub64_d(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r1],
6784fcf5ef2aSThomas Huth cpu_gpr_d[r3], cpu_gpr_d[r3+1], cpu_gpr_d[r2]);
6785fcf5ef2aSThomas Huth break;
6786fcf5ef2aSThomas Huth case OPC2_32_RRR2_MSUBS_32:
6787ad75a51eSRichard Henderson gen_helper_msub32_ssov(cpu_gpr_d[r4], tcg_env, cpu_gpr_d[r1],
6788fcf5ef2aSThomas Huth cpu_gpr_d[r3], cpu_gpr_d[r2]);
6789fcf5ef2aSThomas Huth break;
6790fcf5ef2aSThomas Huth case OPC2_32_RRR2_MSUBS_64:
6791fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
6792fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
6793fcf5ef2aSThomas Huth gen_msubs_64(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r1],
6794fcf5ef2aSThomas Huth cpu_gpr_d[r3], cpu_gpr_d[r3+1], cpu_gpr_d[r2]);
6795fcf5ef2aSThomas Huth break;
6796fcf5ef2aSThomas Huth case OPC2_32_RRR2_MSUB_U_64:
67976991777eSBastian Koppelmann CHECK_REG_PAIR(r4);
67986991777eSBastian Koppelmann CHECK_REG_PAIR(r3);
6799fcf5ef2aSThomas Huth gen_msubu64_d(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r1],
6800fcf5ef2aSThomas Huth cpu_gpr_d[r3], cpu_gpr_d[r3+1], cpu_gpr_d[r2]);
6801fcf5ef2aSThomas Huth break;
6802fcf5ef2aSThomas Huth case OPC2_32_RRR2_MSUBS_U_32:
6803ad75a51eSRichard Henderson gen_helper_msub32_suov(cpu_gpr_d[r4], tcg_env, cpu_gpr_d[r1],
6804fcf5ef2aSThomas Huth cpu_gpr_d[r3], cpu_gpr_d[r2]);
6805fcf5ef2aSThomas Huth break;
6806fcf5ef2aSThomas Huth case OPC2_32_RRR2_MSUBS_U_64:
6807fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
6808fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
6809fcf5ef2aSThomas Huth gen_msubsu_64(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r1],
6810fcf5ef2aSThomas Huth cpu_gpr_d[r3], cpu_gpr_d[r3+1], cpu_gpr_d[r2]);
6811fcf5ef2aSThomas Huth break;
6812fcf5ef2aSThomas Huth default:
6813fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
6814fcf5ef2aSThomas Huth }
6815fcf5ef2aSThomas Huth }
6816fcf5ef2aSThomas Huth
6817fcf5ef2aSThomas Huth /* RRR1 format */
decode_rrr1_madd(DisasContext * ctx)68182db92a0cSBastian Koppelmann static void decode_rrr1_madd(DisasContext *ctx)
6819fcf5ef2aSThomas Huth {
6820fcf5ef2aSThomas Huth uint32_t op2;
6821fcf5ef2aSThomas Huth uint32_t r1, r2, r3, r4, n;
6822fcf5ef2aSThomas Huth
6823fcf5ef2aSThomas Huth op2 = MASK_OP_RRR1_OP2(ctx->opcode);
6824fcf5ef2aSThomas Huth r1 = MASK_OP_RRR1_S1(ctx->opcode);
6825fcf5ef2aSThomas Huth r2 = MASK_OP_RRR1_S2(ctx->opcode);
6826fcf5ef2aSThomas Huth r3 = MASK_OP_RRR1_S3(ctx->opcode);
6827fcf5ef2aSThomas Huth r4 = MASK_OP_RRR1_D(ctx->opcode);
6828fcf5ef2aSThomas Huth n = MASK_OP_RRR1_N(ctx->opcode);
6829fcf5ef2aSThomas Huth
6830fcf5ef2aSThomas Huth switch (op2) {
6831fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADD_H_LL:
6832fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
6833fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
6834fcf5ef2aSThomas Huth gen_madd_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
6835fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2], n, MODE_LL);
6836fcf5ef2aSThomas Huth break;
6837fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADD_H_LU:
6838fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
6839fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
6840fcf5ef2aSThomas Huth gen_madd_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
6841fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2], n, MODE_LU);
6842fcf5ef2aSThomas Huth break;
6843fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADD_H_UL:
6844fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
6845fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
6846fcf5ef2aSThomas Huth gen_madd_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
6847fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2], n, MODE_UL);
6848fcf5ef2aSThomas Huth break;
6849fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADD_H_UU:
6850fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
6851fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
6852fcf5ef2aSThomas Huth gen_madd_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
6853fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2], n, MODE_UU);
6854fcf5ef2aSThomas Huth break;
6855fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDS_H_LL:
6856fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
6857fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
6858fcf5ef2aSThomas Huth gen_madds_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
6859fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2], n, MODE_LL);
6860fcf5ef2aSThomas Huth break;
6861fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDS_H_LU:
6862fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
6863fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
6864fcf5ef2aSThomas Huth gen_madds_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
6865fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2], n, MODE_LU);
6866fcf5ef2aSThomas Huth break;
6867fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDS_H_UL:
6868fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
6869fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
6870fcf5ef2aSThomas Huth gen_madds_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
6871fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2], n, MODE_UL);
6872fcf5ef2aSThomas Huth break;
6873fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDS_H_UU:
6874fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
6875fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
6876fcf5ef2aSThomas Huth gen_madds_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
6877fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2], n, MODE_UU);
6878fcf5ef2aSThomas Huth break;
6879fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDM_H_LL:
6880fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
6881fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
6882fcf5ef2aSThomas Huth gen_maddm_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
6883fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2], n, MODE_LL);
6884fcf5ef2aSThomas Huth break;
6885fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDM_H_LU:
6886fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
6887fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
6888fcf5ef2aSThomas Huth gen_maddm_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
6889fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2], n, MODE_LU);
6890fcf5ef2aSThomas Huth break;
6891fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDM_H_UL:
6892fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
6893fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
6894fcf5ef2aSThomas Huth gen_maddm_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
6895fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2], n, MODE_UL);
6896fcf5ef2aSThomas Huth break;
6897fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDM_H_UU:
6898fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
6899fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
6900fcf5ef2aSThomas Huth gen_maddm_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
6901fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2], n, MODE_UU);
6902fcf5ef2aSThomas Huth break;
6903fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDMS_H_LL:
6904fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
6905fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
6906fcf5ef2aSThomas Huth gen_maddms_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
6907fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2], n, MODE_LL);
6908fcf5ef2aSThomas Huth break;
6909fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDMS_H_LU:
6910fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
6911fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
6912fcf5ef2aSThomas Huth gen_maddms_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
6913fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2], n, MODE_LU);
6914fcf5ef2aSThomas Huth break;
6915fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDMS_H_UL:
6916fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
6917fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
6918fcf5ef2aSThomas Huth gen_maddms_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
6919fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2], n, MODE_UL);
6920fcf5ef2aSThomas Huth break;
6921fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDMS_H_UU:
6922fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
6923fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
6924fcf5ef2aSThomas Huth gen_maddms_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
6925fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2], n, MODE_UU);
6926fcf5ef2aSThomas Huth break;
6927fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDR_H_LL:
6928fcf5ef2aSThomas Huth gen_maddr32_h(cpu_gpr_d[r4], cpu_gpr_d[r3], cpu_gpr_d[r1],
6929fcf5ef2aSThomas Huth cpu_gpr_d[r2], n, MODE_LL);
6930fcf5ef2aSThomas Huth break;
6931fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDR_H_LU:
6932fcf5ef2aSThomas Huth gen_maddr32_h(cpu_gpr_d[r4], cpu_gpr_d[r3], cpu_gpr_d[r1],
6933fcf5ef2aSThomas Huth cpu_gpr_d[r2], n, MODE_LU);
6934fcf5ef2aSThomas Huth break;
6935fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDR_H_UL:
6936fcf5ef2aSThomas Huth gen_maddr32_h(cpu_gpr_d[r4], cpu_gpr_d[r3], cpu_gpr_d[r1],
6937fcf5ef2aSThomas Huth cpu_gpr_d[r2], n, MODE_UL);
6938fcf5ef2aSThomas Huth break;
6939fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDR_H_UU:
6940fcf5ef2aSThomas Huth gen_maddr32_h(cpu_gpr_d[r4], cpu_gpr_d[r3], cpu_gpr_d[r1],
6941fcf5ef2aSThomas Huth cpu_gpr_d[r2], n, MODE_UU);
6942fcf5ef2aSThomas Huth break;
6943fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDRS_H_LL:
6944fcf5ef2aSThomas Huth gen_maddr32s_h(cpu_gpr_d[r4], cpu_gpr_d[r3], cpu_gpr_d[r1],
6945fcf5ef2aSThomas Huth cpu_gpr_d[r2], n, MODE_LL);
6946fcf5ef2aSThomas Huth break;
6947fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDRS_H_LU:
6948fcf5ef2aSThomas Huth gen_maddr32s_h(cpu_gpr_d[r4], cpu_gpr_d[r3], cpu_gpr_d[r1],
6949fcf5ef2aSThomas Huth cpu_gpr_d[r2], n, MODE_LU);
6950fcf5ef2aSThomas Huth break;
6951fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDRS_H_UL:
6952fcf5ef2aSThomas Huth gen_maddr32s_h(cpu_gpr_d[r4], cpu_gpr_d[r3], cpu_gpr_d[r1],
6953fcf5ef2aSThomas Huth cpu_gpr_d[r2], n, MODE_UL);
6954fcf5ef2aSThomas Huth break;
6955fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDRS_H_UU:
6956fcf5ef2aSThomas Huth gen_maddr32s_h(cpu_gpr_d[r4], cpu_gpr_d[r3], cpu_gpr_d[r1],
6957fcf5ef2aSThomas Huth cpu_gpr_d[r2], n, MODE_UU);
6958fcf5ef2aSThomas Huth break;
6959fcf5ef2aSThomas Huth default:
6960fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
6961fcf5ef2aSThomas Huth }
6962fcf5ef2aSThomas Huth }
6963fcf5ef2aSThomas Huth
decode_rrr1_maddq_h(DisasContext * ctx)69642db92a0cSBastian Koppelmann static void decode_rrr1_maddq_h(DisasContext *ctx)
6965fcf5ef2aSThomas Huth {
6966fcf5ef2aSThomas Huth uint32_t op2;
6967fcf5ef2aSThomas Huth uint32_t r1, r2, r3, r4, n;
6968fcf5ef2aSThomas Huth TCGv temp, temp2;
6969fcf5ef2aSThomas Huth
6970fcf5ef2aSThomas Huth op2 = MASK_OP_RRR1_OP2(ctx->opcode);
6971fcf5ef2aSThomas Huth r1 = MASK_OP_RRR1_S1(ctx->opcode);
6972fcf5ef2aSThomas Huth r2 = MASK_OP_RRR1_S2(ctx->opcode);
6973fcf5ef2aSThomas Huth r3 = MASK_OP_RRR1_S3(ctx->opcode);
6974fcf5ef2aSThomas Huth r4 = MASK_OP_RRR1_D(ctx->opcode);
6975fcf5ef2aSThomas Huth n = MASK_OP_RRR1_N(ctx->opcode);
6976fcf5ef2aSThomas Huth
697732f948afSRichard Henderson temp = tcg_temp_new();
6978fcf5ef2aSThomas Huth temp2 = tcg_temp_new();
6979fcf5ef2aSThomas Huth
6980fcf5ef2aSThomas Huth switch (op2) {
6981fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADD_Q_32:
6982fcf5ef2aSThomas Huth gen_madd32_q(cpu_gpr_d[r4], cpu_gpr_d[r3], cpu_gpr_d[r1],
69832db92a0cSBastian Koppelmann cpu_gpr_d[r2], n, 32);
6984fcf5ef2aSThomas Huth break;
6985fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADD_Q_64:
6986fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
6987fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
6988fcf5ef2aSThomas Huth gen_madd64_q(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
6989fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2],
69902db92a0cSBastian Koppelmann n);
6991fcf5ef2aSThomas Huth break;
6992fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADD_Q_32_L:
6993fcf5ef2aSThomas Huth tcg_gen_ext16s_tl(temp, cpu_gpr_d[r2]);
6994fcf5ef2aSThomas Huth gen_madd32_q(cpu_gpr_d[r4], cpu_gpr_d[r3], cpu_gpr_d[r1],
69952db92a0cSBastian Koppelmann temp, n, 16);
6996fcf5ef2aSThomas Huth break;
6997fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADD_Q_64_L:
6998fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
6999fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7000fcf5ef2aSThomas Huth tcg_gen_ext16s_tl(temp, cpu_gpr_d[r2]);
7001fcf5ef2aSThomas Huth gen_madd64_q(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7002fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], temp,
70032db92a0cSBastian Koppelmann n);
7004fcf5ef2aSThomas Huth break;
7005fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADD_Q_32_U:
7006fcf5ef2aSThomas Huth tcg_gen_sari_tl(temp, cpu_gpr_d[r2], 16);
7007fcf5ef2aSThomas Huth gen_madd32_q(cpu_gpr_d[r4], cpu_gpr_d[r3], cpu_gpr_d[r1],
70082db92a0cSBastian Koppelmann temp, n, 16);
7009fcf5ef2aSThomas Huth break;
7010fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADD_Q_64_U:
7011fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7012fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7013fcf5ef2aSThomas Huth tcg_gen_sari_tl(temp, cpu_gpr_d[r2], 16);
7014fcf5ef2aSThomas Huth gen_madd64_q(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7015fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], temp,
70162db92a0cSBastian Koppelmann n);
7017fcf5ef2aSThomas Huth break;
7018fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADD_Q_32_LL:
7019fcf5ef2aSThomas Huth tcg_gen_ext16s_tl(temp, cpu_gpr_d[r1]);
7020fcf5ef2aSThomas Huth tcg_gen_ext16s_tl(temp2, cpu_gpr_d[r2]);
7021fcf5ef2aSThomas Huth gen_m16add32_q(cpu_gpr_d[r4], cpu_gpr_d[r3], temp, temp2, n);
7022fcf5ef2aSThomas Huth break;
7023fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADD_Q_64_LL:
7024fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7025fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7026fcf5ef2aSThomas Huth tcg_gen_ext16s_tl(temp, cpu_gpr_d[r1]);
7027fcf5ef2aSThomas Huth tcg_gen_ext16s_tl(temp2, cpu_gpr_d[r2]);
7028fcf5ef2aSThomas Huth gen_m16add64_q(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7029fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], temp, temp2, n);
7030fcf5ef2aSThomas Huth break;
7031fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADD_Q_32_UU:
7032fcf5ef2aSThomas Huth tcg_gen_sari_tl(temp, cpu_gpr_d[r1], 16);
7033fcf5ef2aSThomas Huth tcg_gen_sari_tl(temp2, cpu_gpr_d[r2], 16);
7034fcf5ef2aSThomas Huth gen_m16add32_q(cpu_gpr_d[r4], cpu_gpr_d[r3], temp, temp2, n);
7035fcf5ef2aSThomas Huth break;
7036fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADD_Q_64_UU:
7037fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7038fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7039fcf5ef2aSThomas Huth tcg_gen_sari_tl(temp, cpu_gpr_d[r1], 16);
7040fcf5ef2aSThomas Huth tcg_gen_sari_tl(temp2, cpu_gpr_d[r2], 16);
7041fcf5ef2aSThomas Huth gen_m16add64_q(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7042fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], temp, temp2, n);
7043fcf5ef2aSThomas Huth break;
7044fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDS_Q_32:
7045fcf5ef2aSThomas Huth gen_madds32_q(cpu_gpr_d[r4], cpu_gpr_d[r3], cpu_gpr_d[r1],
7046fcf5ef2aSThomas Huth cpu_gpr_d[r2], n, 32);
7047fcf5ef2aSThomas Huth break;
7048fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDS_Q_64:
7049fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7050fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7051fcf5ef2aSThomas Huth gen_madds64_q(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7052fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2],
7053fcf5ef2aSThomas Huth n);
7054fcf5ef2aSThomas Huth break;
7055fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDS_Q_32_L:
7056fcf5ef2aSThomas Huth tcg_gen_ext16s_tl(temp, cpu_gpr_d[r2]);
7057fcf5ef2aSThomas Huth gen_madds32_q(cpu_gpr_d[r4], cpu_gpr_d[r3], cpu_gpr_d[r1],
7058fcf5ef2aSThomas Huth temp, n, 16);
7059fcf5ef2aSThomas Huth break;
7060fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDS_Q_64_L:
7061fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7062fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7063fcf5ef2aSThomas Huth tcg_gen_ext16s_tl(temp, cpu_gpr_d[r2]);
7064fcf5ef2aSThomas Huth gen_madds64_q(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7065fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], temp,
7066fcf5ef2aSThomas Huth n);
7067fcf5ef2aSThomas Huth break;
7068fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDS_Q_32_U:
7069fcf5ef2aSThomas Huth tcg_gen_sari_tl(temp, cpu_gpr_d[r2], 16);
7070fcf5ef2aSThomas Huth gen_madds32_q(cpu_gpr_d[r4], cpu_gpr_d[r3], cpu_gpr_d[r1],
7071fcf5ef2aSThomas Huth temp, n, 16);
7072fcf5ef2aSThomas Huth break;
7073fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDS_Q_64_U:
7074fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7075fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7076fcf5ef2aSThomas Huth tcg_gen_sari_tl(temp, cpu_gpr_d[r2], 16);
7077fcf5ef2aSThomas Huth gen_madds64_q(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7078fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], temp,
7079fcf5ef2aSThomas Huth n);
7080fcf5ef2aSThomas Huth break;
7081fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDS_Q_32_LL:
7082fcf5ef2aSThomas Huth tcg_gen_ext16s_tl(temp, cpu_gpr_d[r1]);
7083fcf5ef2aSThomas Huth tcg_gen_ext16s_tl(temp2, cpu_gpr_d[r2]);
7084fcf5ef2aSThomas Huth gen_m16adds32_q(cpu_gpr_d[r4], cpu_gpr_d[r3], temp, temp2, n);
7085fcf5ef2aSThomas Huth break;
7086fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDS_Q_64_LL:
7087fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7088fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7089fcf5ef2aSThomas Huth tcg_gen_ext16s_tl(temp, cpu_gpr_d[r1]);
7090fcf5ef2aSThomas Huth tcg_gen_ext16s_tl(temp2, cpu_gpr_d[r2]);
7091fcf5ef2aSThomas Huth gen_m16adds64_q(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7092fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], temp, temp2, n);
7093fcf5ef2aSThomas Huth break;
7094fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDS_Q_32_UU:
7095fcf5ef2aSThomas Huth tcg_gen_sari_tl(temp, cpu_gpr_d[r1], 16);
7096fcf5ef2aSThomas Huth tcg_gen_sari_tl(temp2, cpu_gpr_d[r2], 16);
7097fcf5ef2aSThomas Huth gen_m16adds32_q(cpu_gpr_d[r4], cpu_gpr_d[r3], temp, temp2, n);
7098fcf5ef2aSThomas Huth break;
7099fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDS_Q_64_UU:
7100fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7101fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7102fcf5ef2aSThomas Huth tcg_gen_sari_tl(temp, cpu_gpr_d[r1], 16);
7103fcf5ef2aSThomas Huth tcg_gen_sari_tl(temp2, cpu_gpr_d[r2], 16);
7104fcf5ef2aSThomas Huth gen_m16adds64_q(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7105fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], temp, temp2, n);
7106fcf5ef2aSThomas Huth break;
7107fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDR_H_64_UL:
7108fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7109fcf5ef2aSThomas Huth gen_maddr64_h(cpu_gpr_d[r4], cpu_gpr_d[r3], cpu_gpr_d[r3+1],
7110fcf5ef2aSThomas Huth cpu_gpr_d[r1], cpu_gpr_d[r2], n, 2);
7111fcf5ef2aSThomas Huth break;
7112fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDRS_H_64_UL:
7113fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7114fcf5ef2aSThomas Huth gen_maddr64s_h(cpu_gpr_d[r4], cpu_gpr_d[r3], cpu_gpr_d[r3+1],
7115fcf5ef2aSThomas Huth cpu_gpr_d[r1], cpu_gpr_d[r2], n, 2);
7116fcf5ef2aSThomas Huth break;
7117fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDR_Q_32_LL:
7118fcf5ef2aSThomas Huth tcg_gen_ext16s_tl(temp, cpu_gpr_d[r1]);
7119fcf5ef2aSThomas Huth tcg_gen_ext16s_tl(temp2, cpu_gpr_d[r2]);
7120fcf5ef2aSThomas Huth gen_maddr_q(cpu_gpr_d[r4], cpu_gpr_d[r3], temp, temp2, n);
7121fcf5ef2aSThomas Huth break;
7122fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDR_Q_32_UU:
7123fcf5ef2aSThomas Huth tcg_gen_sari_tl(temp, cpu_gpr_d[r1], 16);
7124fcf5ef2aSThomas Huth tcg_gen_sari_tl(temp2, cpu_gpr_d[r2], 16);
7125fcf5ef2aSThomas Huth gen_maddr_q(cpu_gpr_d[r4], cpu_gpr_d[r3], temp, temp2, n);
7126fcf5ef2aSThomas Huth break;
7127fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDRS_Q_32_LL:
7128fcf5ef2aSThomas Huth tcg_gen_ext16s_tl(temp, cpu_gpr_d[r1]);
7129fcf5ef2aSThomas Huth tcg_gen_ext16s_tl(temp2, cpu_gpr_d[r2]);
7130fcf5ef2aSThomas Huth gen_maddrs_q(cpu_gpr_d[r4], cpu_gpr_d[r3], temp, temp2, n);
7131fcf5ef2aSThomas Huth break;
7132fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDRS_Q_32_UU:
7133fcf5ef2aSThomas Huth tcg_gen_sari_tl(temp, cpu_gpr_d[r1], 16);
7134fcf5ef2aSThomas Huth tcg_gen_sari_tl(temp2, cpu_gpr_d[r2], 16);
7135fcf5ef2aSThomas Huth gen_maddrs_q(cpu_gpr_d[r4], cpu_gpr_d[r3], temp, temp2, n);
7136fcf5ef2aSThomas Huth break;
7137fcf5ef2aSThomas Huth default:
7138fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
7139fcf5ef2aSThomas Huth }
7140fcf5ef2aSThomas Huth }
7141fcf5ef2aSThomas Huth
decode_rrr1_maddsu_h(DisasContext * ctx)71422db92a0cSBastian Koppelmann static void decode_rrr1_maddsu_h(DisasContext *ctx)
7143fcf5ef2aSThomas Huth {
7144fcf5ef2aSThomas Huth uint32_t op2;
7145fcf5ef2aSThomas Huth uint32_t r1, r2, r3, r4, n;
7146fcf5ef2aSThomas Huth
7147fcf5ef2aSThomas Huth op2 = MASK_OP_RRR1_OP2(ctx->opcode);
7148fcf5ef2aSThomas Huth r1 = MASK_OP_RRR1_S1(ctx->opcode);
7149fcf5ef2aSThomas Huth r2 = MASK_OP_RRR1_S2(ctx->opcode);
7150fcf5ef2aSThomas Huth r3 = MASK_OP_RRR1_S3(ctx->opcode);
7151fcf5ef2aSThomas Huth r4 = MASK_OP_RRR1_D(ctx->opcode);
7152fcf5ef2aSThomas Huth n = MASK_OP_RRR1_N(ctx->opcode);
7153fcf5ef2aSThomas Huth
7154fcf5ef2aSThomas Huth switch (op2) {
7155fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDSU_H_32_LL:
7156fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7157fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7158fcf5ef2aSThomas Huth gen_maddsu_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7159fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2], n, MODE_LL);
7160fcf5ef2aSThomas Huth break;
7161fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDSU_H_32_LU:
7162fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7163fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7164fcf5ef2aSThomas Huth gen_maddsu_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7165fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2], n, MODE_LU);
7166fcf5ef2aSThomas Huth break;
7167fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDSU_H_32_UL:
7168fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7169fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7170fcf5ef2aSThomas Huth gen_maddsu_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7171fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2], n, MODE_UL);
7172fcf5ef2aSThomas Huth break;
7173fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDSU_H_32_UU:
7174fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7175fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7176fcf5ef2aSThomas Huth gen_maddsu_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7177fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2], n, MODE_UU);
7178fcf5ef2aSThomas Huth break;
7179fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDSUS_H_32_LL:
7180fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7181fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7182fcf5ef2aSThomas Huth gen_maddsus_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7183fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2],
7184fcf5ef2aSThomas Huth n, MODE_LL);
7185fcf5ef2aSThomas Huth break;
7186fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDSUS_H_32_LU:
7187fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7188fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7189fcf5ef2aSThomas Huth gen_maddsus_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7190fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2],
7191fcf5ef2aSThomas Huth n, MODE_LU);
7192fcf5ef2aSThomas Huth break;
7193fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDSUS_H_32_UL:
7194fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7195fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7196fcf5ef2aSThomas Huth gen_maddsus_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7197fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2],
7198fcf5ef2aSThomas Huth n, MODE_UL);
7199fcf5ef2aSThomas Huth break;
7200fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDSUS_H_32_UU:
7201fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7202fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7203fcf5ef2aSThomas Huth gen_maddsus_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7204fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2],
7205fcf5ef2aSThomas Huth n, MODE_UU);
7206fcf5ef2aSThomas Huth break;
7207fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDSUM_H_64_LL:
7208fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7209fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7210fcf5ef2aSThomas Huth gen_maddsum_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7211fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2],
7212fcf5ef2aSThomas Huth n, MODE_LL);
7213fcf5ef2aSThomas Huth break;
7214fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDSUM_H_64_LU:
7215fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7216fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7217fcf5ef2aSThomas Huth gen_maddsum_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7218fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2],
7219fcf5ef2aSThomas Huth n, MODE_LU);
7220fcf5ef2aSThomas Huth break;
7221fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDSUM_H_64_UL:
7222fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7223fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7224fcf5ef2aSThomas Huth gen_maddsum_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7225fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2],
7226fcf5ef2aSThomas Huth n, MODE_UL);
7227fcf5ef2aSThomas Huth break;
7228fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDSUM_H_64_UU:
7229fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7230fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7231fcf5ef2aSThomas Huth gen_maddsum_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7232fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2],
7233fcf5ef2aSThomas Huth n, MODE_UU);
7234fcf5ef2aSThomas Huth break;
7235fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDSUMS_H_64_LL:
7236fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7237fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7238fcf5ef2aSThomas Huth gen_maddsums_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7239fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2],
7240fcf5ef2aSThomas Huth n, MODE_LL);
7241fcf5ef2aSThomas Huth break;
7242fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDSUMS_H_64_LU:
7243fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7244fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7245fcf5ef2aSThomas Huth gen_maddsums_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7246fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2],
7247fcf5ef2aSThomas Huth n, MODE_LU);
7248fcf5ef2aSThomas Huth break;
7249fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDSUMS_H_64_UL:
7250fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7251fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7252fcf5ef2aSThomas Huth gen_maddsums_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7253fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2],
7254fcf5ef2aSThomas Huth n, MODE_UL);
7255fcf5ef2aSThomas Huth break;
7256fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDSUMS_H_64_UU:
7257fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7258fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7259fcf5ef2aSThomas Huth gen_maddsums_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7260fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2],
7261fcf5ef2aSThomas Huth n, MODE_UU);
7262fcf5ef2aSThomas Huth break;
7263fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDSUR_H_16_LL:
7264fcf5ef2aSThomas Huth gen_maddsur32_h(cpu_gpr_d[r4], cpu_gpr_d[r3], cpu_gpr_d[r1],
7265fcf5ef2aSThomas Huth cpu_gpr_d[r2], n, MODE_LL);
7266fcf5ef2aSThomas Huth break;
7267fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDSUR_H_16_LU:
7268fcf5ef2aSThomas Huth gen_maddsur32_h(cpu_gpr_d[r4], cpu_gpr_d[r3], cpu_gpr_d[r1],
7269fcf5ef2aSThomas Huth cpu_gpr_d[r2], n, MODE_LU);
7270fcf5ef2aSThomas Huth break;
7271fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDSUR_H_16_UL:
7272fcf5ef2aSThomas Huth gen_maddsur32_h(cpu_gpr_d[r4], cpu_gpr_d[r3], cpu_gpr_d[r1],
7273fcf5ef2aSThomas Huth cpu_gpr_d[r2], n, MODE_UL);
7274fcf5ef2aSThomas Huth break;
7275fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDSUR_H_16_UU:
7276fcf5ef2aSThomas Huth gen_maddsur32_h(cpu_gpr_d[r4], cpu_gpr_d[r3], cpu_gpr_d[r1],
7277fcf5ef2aSThomas Huth cpu_gpr_d[r2], n, MODE_UU);
7278fcf5ef2aSThomas Huth break;
7279fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDSURS_H_16_LL:
7280fcf5ef2aSThomas Huth gen_maddsur32s_h(cpu_gpr_d[r4], cpu_gpr_d[r3], cpu_gpr_d[r1],
7281fcf5ef2aSThomas Huth cpu_gpr_d[r2], n, MODE_LL);
7282fcf5ef2aSThomas Huth break;
7283fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDSURS_H_16_LU:
7284fcf5ef2aSThomas Huth gen_maddsur32s_h(cpu_gpr_d[r4], cpu_gpr_d[r3], cpu_gpr_d[r1],
7285fcf5ef2aSThomas Huth cpu_gpr_d[r2], n, MODE_LU);
7286fcf5ef2aSThomas Huth break;
7287fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDSURS_H_16_UL:
7288fcf5ef2aSThomas Huth gen_maddsur32s_h(cpu_gpr_d[r4], cpu_gpr_d[r3], cpu_gpr_d[r1],
7289fcf5ef2aSThomas Huth cpu_gpr_d[r2], n, MODE_UL);
7290fcf5ef2aSThomas Huth break;
7291fcf5ef2aSThomas Huth case OPC2_32_RRR1_MADDSURS_H_16_UU:
7292fcf5ef2aSThomas Huth gen_maddsur32s_h(cpu_gpr_d[r4], cpu_gpr_d[r3], cpu_gpr_d[r1],
7293fcf5ef2aSThomas Huth cpu_gpr_d[r2], n, MODE_UU);
7294fcf5ef2aSThomas Huth break;
7295fcf5ef2aSThomas Huth default:
7296fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
7297fcf5ef2aSThomas Huth }
7298fcf5ef2aSThomas Huth }
7299fcf5ef2aSThomas Huth
decode_rrr1_msub(DisasContext * ctx)73002db92a0cSBastian Koppelmann static void decode_rrr1_msub(DisasContext *ctx)
7301fcf5ef2aSThomas Huth {
7302fcf5ef2aSThomas Huth uint32_t op2;
7303fcf5ef2aSThomas Huth uint32_t r1, r2, r3, r4, n;
7304fcf5ef2aSThomas Huth
7305fcf5ef2aSThomas Huth op2 = MASK_OP_RRR1_OP2(ctx->opcode);
7306fcf5ef2aSThomas Huth r1 = MASK_OP_RRR1_S1(ctx->opcode);
7307fcf5ef2aSThomas Huth r2 = MASK_OP_RRR1_S2(ctx->opcode);
7308fcf5ef2aSThomas Huth r3 = MASK_OP_RRR1_S3(ctx->opcode);
7309fcf5ef2aSThomas Huth r4 = MASK_OP_RRR1_D(ctx->opcode);
7310fcf5ef2aSThomas Huth n = MASK_OP_RRR1_N(ctx->opcode);
7311fcf5ef2aSThomas Huth
7312fcf5ef2aSThomas Huth switch (op2) {
7313fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUB_H_LL:
7314fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7315fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7316fcf5ef2aSThomas Huth gen_msub_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7317fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2], n, MODE_LL);
7318fcf5ef2aSThomas Huth break;
7319fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUB_H_LU:
7320fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7321fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7322fcf5ef2aSThomas Huth gen_msub_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7323fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2], n, MODE_LU);
7324fcf5ef2aSThomas Huth break;
7325fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUB_H_UL:
7326fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7327fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7328fcf5ef2aSThomas Huth gen_msub_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7329fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2], n, MODE_UL);
7330fcf5ef2aSThomas Huth break;
7331fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUB_H_UU:
7332fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7333fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7334fcf5ef2aSThomas Huth gen_msub_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7335fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2], n, MODE_UU);
7336fcf5ef2aSThomas Huth break;
7337fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBS_H_LL:
7338fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7339fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7340fcf5ef2aSThomas Huth gen_msubs_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7341fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2], n, MODE_LL);
7342fcf5ef2aSThomas Huth break;
7343fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBS_H_LU:
7344fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7345fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7346fcf5ef2aSThomas Huth gen_msubs_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7347fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2], n, MODE_LU);
7348fcf5ef2aSThomas Huth break;
7349fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBS_H_UL:
7350fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7351fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7352fcf5ef2aSThomas Huth gen_msubs_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7353fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2], n, MODE_UL);
7354fcf5ef2aSThomas Huth break;
7355fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBS_H_UU:
7356fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7357fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7358fcf5ef2aSThomas Huth gen_msubs_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7359fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2], n, MODE_UU);
7360fcf5ef2aSThomas Huth break;
7361fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBM_H_LL:
7362fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7363fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7364fcf5ef2aSThomas Huth gen_msubm_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7365fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2], n, MODE_LL);
7366fcf5ef2aSThomas Huth break;
7367fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBM_H_LU:
7368fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7369fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7370fcf5ef2aSThomas Huth gen_msubm_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7371fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2], n, MODE_LU);
7372fcf5ef2aSThomas Huth break;
7373fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBM_H_UL:
7374fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7375fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7376fcf5ef2aSThomas Huth gen_msubm_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7377fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2], n, MODE_UL);
7378fcf5ef2aSThomas Huth break;
7379fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBM_H_UU:
7380fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7381fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7382fcf5ef2aSThomas Huth gen_msubm_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7383fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2], n, MODE_UU);
7384fcf5ef2aSThomas Huth break;
7385fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBMS_H_LL:
7386fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7387fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7388fcf5ef2aSThomas Huth gen_msubms_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7389fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2], n, MODE_LL);
7390fcf5ef2aSThomas Huth break;
7391fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBMS_H_LU:
7392fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7393fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7394fcf5ef2aSThomas Huth gen_msubms_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7395fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2], n, MODE_LU);
7396fcf5ef2aSThomas Huth break;
7397fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBMS_H_UL:
7398fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7399fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7400fcf5ef2aSThomas Huth gen_msubms_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7401fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2], n, MODE_UL);
7402fcf5ef2aSThomas Huth break;
7403fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBMS_H_UU:
7404fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7405fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7406fcf5ef2aSThomas Huth gen_msubms_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7407fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2], n, MODE_UU);
7408fcf5ef2aSThomas Huth break;
7409fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBR_H_LL:
7410fcf5ef2aSThomas Huth gen_msubr32_h(cpu_gpr_d[r4], cpu_gpr_d[r3], cpu_gpr_d[r1],
7411fcf5ef2aSThomas Huth cpu_gpr_d[r2], n, MODE_LL);
7412fcf5ef2aSThomas Huth break;
7413fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBR_H_LU:
7414fcf5ef2aSThomas Huth gen_msubr32_h(cpu_gpr_d[r4], cpu_gpr_d[r3], cpu_gpr_d[r1],
7415fcf5ef2aSThomas Huth cpu_gpr_d[r2], n, MODE_LU);
7416fcf5ef2aSThomas Huth break;
7417fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBR_H_UL:
7418fcf5ef2aSThomas Huth gen_msubr32_h(cpu_gpr_d[r4], cpu_gpr_d[r3], cpu_gpr_d[r1],
7419fcf5ef2aSThomas Huth cpu_gpr_d[r2], n, MODE_UL);
7420fcf5ef2aSThomas Huth break;
7421fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBR_H_UU:
7422fcf5ef2aSThomas Huth gen_msubr32_h(cpu_gpr_d[r4], cpu_gpr_d[r3], cpu_gpr_d[r1],
7423fcf5ef2aSThomas Huth cpu_gpr_d[r2], n, MODE_UU);
7424fcf5ef2aSThomas Huth break;
7425fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBRS_H_LL:
7426fcf5ef2aSThomas Huth gen_msubr32s_h(cpu_gpr_d[r4], cpu_gpr_d[r3], cpu_gpr_d[r1],
7427fcf5ef2aSThomas Huth cpu_gpr_d[r2], n, MODE_LL);
7428fcf5ef2aSThomas Huth break;
7429fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBRS_H_LU:
7430fcf5ef2aSThomas Huth gen_msubr32s_h(cpu_gpr_d[r4], cpu_gpr_d[r3], cpu_gpr_d[r1],
7431fcf5ef2aSThomas Huth cpu_gpr_d[r2], n, MODE_LU);
7432fcf5ef2aSThomas Huth break;
7433fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBRS_H_UL:
7434fcf5ef2aSThomas Huth gen_msubr32s_h(cpu_gpr_d[r4], cpu_gpr_d[r3], cpu_gpr_d[r1],
7435fcf5ef2aSThomas Huth cpu_gpr_d[r2], n, MODE_UL);
7436fcf5ef2aSThomas Huth break;
7437fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBRS_H_UU:
7438fcf5ef2aSThomas Huth gen_msubr32s_h(cpu_gpr_d[r4], cpu_gpr_d[r3], cpu_gpr_d[r1],
7439fcf5ef2aSThomas Huth cpu_gpr_d[r2], n, MODE_UU);
7440fcf5ef2aSThomas Huth break;
7441fcf5ef2aSThomas Huth default:
7442fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
7443fcf5ef2aSThomas Huth }
7444fcf5ef2aSThomas Huth }
7445fcf5ef2aSThomas Huth
decode_rrr1_msubq_h(DisasContext * ctx)74462db92a0cSBastian Koppelmann static void decode_rrr1_msubq_h(DisasContext *ctx)
7447fcf5ef2aSThomas Huth {
7448fcf5ef2aSThomas Huth uint32_t op2;
7449fcf5ef2aSThomas Huth uint32_t r1, r2, r3, r4, n;
7450fcf5ef2aSThomas Huth TCGv temp, temp2;
7451fcf5ef2aSThomas Huth
7452fcf5ef2aSThomas Huth op2 = MASK_OP_RRR1_OP2(ctx->opcode);
7453fcf5ef2aSThomas Huth r1 = MASK_OP_RRR1_S1(ctx->opcode);
7454fcf5ef2aSThomas Huth r2 = MASK_OP_RRR1_S2(ctx->opcode);
7455fcf5ef2aSThomas Huth r3 = MASK_OP_RRR1_S3(ctx->opcode);
7456fcf5ef2aSThomas Huth r4 = MASK_OP_RRR1_D(ctx->opcode);
7457fcf5ef2aSThomas Huth n = MASK_OP_RRR1_N(ctx->opcode);
7458fcf5ef2aSThomas Huth
745932f948afSRichard Henderson temp = tcg_temp_new();
7460fcf5ef2aSThomas Huth temp2 = tcg_temp_new();
7461fcf5ef2aSThomas Huth
7462fcf5ef2aSThomas Huth switch (op2) {
7463fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUB_Q_32:
7464fcf5ef2aSThomas Huth gen_msub32_q(cpu_gpr_d[r4], cpu_gpr_d[r3], cpu_gpr_d[r1],
74652db92a0cSBastian Koppelmann cpu_gpr_d[r2], n, 32);
7466fcf5ef2aSThomas Huth break;
7467fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUB_Q_64:
7468fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7469fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7470fcf5ef2aSThomas Huth gen_msub64_q(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7471fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2],
74722db92a0cSBastian Koppelmann n);
7473fcf5ef2aSThomas Huth break;
7474fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUB_Q_32_L:
7475fcf5ef2aSThomas Huth tcg_gen_ext16s_tl(temp, cpu_gpr_d[r2]);
7476fcf5ef2aSThomas Huth gen_msub32_q(cpu_gpr_d[r4], cpu_gpr_d[r3], cpu_gpr_d[r1],
74772db92a0cSBastian Koppelmann temp, n, 16);
7478fcf5ef2aSThomas Huth break;
7479fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUB_Q_64_L:
7480fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7481fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7482fcf5ef2aSThomas Huth tcg_gen_ext16s_tl(temp, cpu_gpr_d[r2]);
7483fcf5ef2aSThomas Huth gen_msub64_q(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7484fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], temp,
74852db92a0cSBastian Koppelmann n);
7486fcf5ef2aSThomas Huth break;
7487fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUB_Q_32_U:
7488fcf5ef2aSThomas Huth tcg_gen_sari_tl(temp, cpu_gpr_d[r2], 16);
7489fcf5ef2aSThomas Huth gen_msub32_q(cpu_gpr_d[r4], cpu_gpr_d[r3], cpu_gpr_d[r1],
74902db92a0cSBastian Koppelmann temp, n, 16);
7491fcf5ef2aSThomas Huth break;
7492fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUB_Q_64_U:
7493fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7494fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7495fcf5ef2aSThomas Huth tcg_gen_sari_tl(temp, cpu_gpr_d[r2], 16);
7496fcf5ef2aSThomas Huth gen_msub64_q(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7497fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], temp,
74982db92a0cSBastian Koppelmann n);
7499fcf5ef2aSThomas Huth break;
7500fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUB_Q_32_LL:
7501fcf5ef2aSThomas Huth tcg_gen_ext16s_tl(temp, cpu_gpr_d[r1]);
7502fcf5ef2aSThomas Huth tcg_gen_ext16s_tl(temp2, cpu_gpr_d[r2]);
7503fcf5ef2aSThomas Huth gen_m16sub32_q(cpu_gpr_d[r4], cpu_gpr_d[r3], temp, temp2, n);
7504fcf5ef2aSThomas Huth break;
7505fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUB_Q_64_LL:
7506fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7507fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7508fcf5ef2aSThomas Huth tcg_gen_ext16s_tl(temp, cpu_gpr_d[r1]);
7509fcf5ef2aSThomas Huth tcg_gen_ext16s_tl(temp2, cpu_gpr_d[r2]);
7510fcf5ef2aSThomas Huth gen_m16sub64_q(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7511fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], temp, temp2, n);
7512fcf5ef2aSThomas Huth break;
7513fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUB_Q_32_UU:
7514fcf5ef2aSThomas Huth tcg_gen_sari_tl(temp, cpu_gpr_d[r1], 16);
7515fcf5ef2aSThomas Huth tcg_gen_sari_tl(temp2, cpu_gpr_d[r2], 16);
7516fcf5ef2aSThomas Huth gen_m16sub32_q(cpu_gpr_d[r4], cpu_gpr_d[r3], temp, temp2, n);
7517fcf5ef2aSThomas Huth break;
7518fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUB_Q_64_UU:
7519fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7520fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7521fcf5ef2aSThomas Huth tcg_gen_sari_tl(temp, cpu_gpr_d[r1], 16);
7522fcf5ef2aSThomas Huth tcg_gen_sari_tl(temp2, cpu_gpr_d[r2], 16);
7523fcf5ef2aSThomas Huth gen_m16sub64_q(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7524fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], temp, temp2, n);
7525fcf5ef2aSThomas Huth break;
7526fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBS_Q_32:
7527fcf5ef2aSThomas Huth gen_msubs32_q(cpu_gpr_d[r4], cpu_gpr_d[r3], cpu_gpr_d[r1],
7528fcf5ef2aSThomas Huth cpu_gpr_d[r2], n, 32);
7529fcf5ef2aSThomas Huth break;
7530fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBS_Q_64:
7531fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7532fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7533fcf5ef2aSThomas Huth gen_msubs64_q(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7534fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2],
7535fcf5ef2aSThomas Huth n);
7536fcf5ef2aSThomas Huth break;
7537fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBS_Q_32_L:
7538fcf5ef2aSThomas Huth tcg_gen_ext16s_tl(temp, cpu_gpr_d[r2]);
7539fcf5ef2aSThomas Huth gen_msubs32_q(cpu_gpr_d[r4], cpu_gpr_d[r3], cpu_gpr_d[r1],
7540fcf5ef2aSThomas Huth temp, n, 16);
7541fcf5ef2aSThomas Huth break;
7542fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBS_Q_64_L:
7543fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7544fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7545fcf5ef2aSThomas Huth tcg_gen_ext16s_tl(temp, cpu_gpr_d[r2]);
7546fcf5ef2aSThomas Huth gen_msubs64_q(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7547fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], temp,
7548fcf5ef2aSThomas Huth n);
7549fcf5ef2aSThomas Huth break;
7550fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBS_Q_32_U:
7551fcf5ef2aSThomas Huth tcg_gen_sari_tl(temp, cpu_gpr_d[r2], 16);
7552fcf5ef2aSThomas Huth gen_msubs32_q(cpu_gpr_d[r4], cpu_gpr_d[r3], cpu_gpr_d[r1],
7553fcf5ef2aSThomas Huth temp, n, 16);
7554fcf5ef2aSThomas Huth break;
7555fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBS_Q_64_U:
7556fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7557fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7558fcf5ef2aSThomas Huth tcg_gen_sari_tl(temp, cpu_gpr_d[r2], 16);
7559fcf5ef2aSThomas Huth gen_msubs64_q(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7560fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], temp,
7561fcf5ef2aSThomas Huth n);
7562fcf5ef2aSThomas Huth break;
7563fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBS_Q_32_LL:
7564fcf5ef2aSThomas Huth tcg_gen_ext16s_tl(temp, cpu_gpr_d[r1]);
7565fcf5ef2aSThomas Huth tcg_gen_ext16s_tl(temp2, cpu_gpr_d[r2]);
7566fcf5ef2aSThomas Huth gen_m16subs32_q(cpu_gpr_d[r4], cpu_gpr_d[r3], temp, temp2, n);
7567fcf5ef2aSThomas Huth break;
7568fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBS_Q_64_LL:
7569fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7570fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7571fcf5ef2aSThomas Huth tcg_gen_ext16s_tl(temp, cpu_gpr_d[r1]);
7572fcf5ef2aSThomas Huth tcg_gen_ext16s_tl(temp2, cpu_gpr_d[r2]);
7573fcf5ef2aSThomas Huth gen_m16subs64_q(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7574fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], temp, temp2, n);
7575fcf5ef2aSThomas Huth break;
7576fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBS_Q_32_UU:
7577fcf5ef2aSThomas Huth tcg_gen_sari_tl(temp, cpu_gpr_d[r1], 16);
7578fcf5ef2aSThomas Huth tcg_gen_sari_tl(temp2, cpu_gpr_d[r2], 16);
7579fcf5ef2aSThomas Huth gen_m16subs32_q(cpu_gpr_d[r4], cpu_gpr_d[r3], temp, temp2, n);
7580fcf5ef2aSThomas Huth break;
7581fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBS_Q_64_UU:
7582fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7583fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7584fcf5ef2aSThomas Huth tcg_gen_sari_tl(temp, cpu_gpr_d[r1], 16);
7585fcf5ef2aSThomas Huth tcg_gen_sari_tl(temp2, cpu_gpr_d[r2], 16);
7586fcf5ef2aSThomas Huth gen_m16subs64_q(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7587fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], temp, temp2, n);
7588fcf5ef2aSThomas Huth break;
7589fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBR_H_64_UL:
7590fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7591fcf5ef2aSThomas Huth gen_msubr64_h(cpu_gpr_d[r4], cpu_gpr_d[r3], cpu_gpr_d[r3+1],
7592fcf5ef2aSThomas Huth cpu_gpr_d[r1], cpu_gpr_d[r2], n, 2);
7593fcf5ef2aSThomas Huth break;
7594fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBRS_H_64_UL:
7595fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7596fcf5ef2aSThomas Huth gen_msubr64s_h(cpu_gpr_d[r4], cpu_gpr_d[r3], cpu_gpr_d[r3+1],
7597fcf5ef2aSThomas Huth cpu_gpr_d[r1], cpu_gpr_d[r2], n, 2);
7598fcf5ef2aSThomas Huth break;
7599fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBR_Q_32_LL:
7600fcf5ef2aSThomas Huth tcg_gen_ext16s_tl(temp, cpu_gpr_d[r1]);
7601fcf5ef2aSThomas Huth tcg_gen_ext16s_tl(temp2, cpu_gpr_d[r2]);
7602fcf5ef2aSThomas Huth gen_msubr_q(cpu_gpr_d[r4], cpu_gpr_d[r3], temp, temp2, n);
7603fcf5ef2aSThomas Huth break;
7604fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBR_Q_32_UU:
7605fcf5ef2aSThomas Huth tcg_gen_sari_tl(temp, cpu_gpr_d[r1], 16);
7606fcf5ef2aSThomas Huth tcg_gen_sari_tl(temp2, cpu_gpr_d[r2], 16);
7607fcf5ef2aSThomas Huth gen_msubr_q(cpu_gpr_d[r4], cpu_gpr_d[r3], temp, temp2, n);
7608fcf5ef2aSThomas Huth break;
7609fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBRS_Q_32_LL:
7610fcf5ef2aSThomas Huth tcg_gen_ext16s_tl(temp, cpu_gpr_d[r1]);
7611fcf5ef2aSThomas Huth tcg_gen_ext16s_tl(temp2, cpu_gpr_d[r2]);
7612fcf5ef2aSThomas Huth gen_msubrs_q(cpu_gpr_d[r4], cpu_gpr_d[r3], temp, temp2, n);
7613fcf5ef2aSThomas Huth break;
7614fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBRS_Q_32_UU:
7615fcf5ef2aSThomas Huth tcg_gen_sari_tl(temp, cpu_gpr_d[r1], 16);
7616fcf5ef2aSThomas Huth tcg_gen_sari_tl(temp2, cpu_gpr_d[r2], 16);
7617fcf5ef2aSThomas Huth gen_msubrs_q(cpu_gpr_d[r4], cpu_gpr_d[r3], temp, temp2, n);
7618fcf5ef2aSThomas Huth break;
7619fcf5ef2aSThomas Huth default:
7620fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
7621fcf5ef2aSThomas Huth }
7622fcf5ef2aSThomas Huth }
7623fcf5ef2aSThomas Huth
decode_rrr1_msubad_h(DisasContext * ctx)76242db92a0cSBastian Koppelmann static void decode_rrr1_msubad_h(DisasContext *ctx)
7625fcf5ef2aSThomas Huth {
7626fcf5ef2aSThomas Huth uint32_t op2;
7627fcf5ef2aSThomas Huth uint32_t r1, r2, r3, r4, n;
7628fcf5ef2aSThomas Huth
7629fcf5ef2aSThomas Huth op2 = MASK_OP_RRR1_OP2(ctx->opcode);
7630fcf5ef2aSThomas Huth r1 = MASK_OP_RRR1_S1(ctx->opcode);
7631fcf5ef2aSThomas Huth r2 = MASK_OP_RRR1_S2(ctx->opcode);
7632fcf5ef2aSThomas Huth r3 = MASK_OP_RRR1_S3(ctx->opcode);
7633fcf5ef2aSThomas Huth r4 = MASK_OP_RRR1_D(ctx->opcode);
7634fcf5ef2aSThomas Huth n = MASK_OP_RRR1_N(ctx->opcode);
7635fcf5ef2aSThomas Huth
7636fcf5ef2aSThomas Huth switch (op2) {
7637fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBAD_H_32_LL:
7638fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7639fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7640fcf5ef2aSThomas Huth gen_msubad_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7641fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2], n, MODE_LL);
7642fcf5ef2aSThomas Huth break;
7643fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBAD_H_32_LU:
7644fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7645fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7646fcf5ef2aSThomas Huth gen_msubad_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7647fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2], n, MODE_LU);
7648fcf5ef2aSThomas Huth break;
7649fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBAD_H_32_UL:
7650fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7651fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7652fcf5ef2aSThomas Huth gen_msubad_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7653fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2], n, MODE_UL);
7654fcf5ef2aSThomas Huth break;
7655fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBAD_H_32_UU:
7656fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7657fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7658fcf5ef2aSThomas Huth gen_msubad_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7659fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2], n, MODE_UU);
7660fcf5ef2aSThomas Huth break;
7661fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBADS_H_32_LL:
7662fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7663fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7664fcf5ef2aSThomas Huth gen_msubads_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7665fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2],
7666fcf5ef2aSThomas Huth n, MODE_LL);
7667fcf5ef2aSThomas Huth break;
7668fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBADS_H_32_LU:
7669fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7670fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7671fcf5ef2aSThomas Huth gen_msubads_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7672fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2],
7673fcf5ef2aSThomas Huth n, MODE_LU);
7674fcf5ef2aSThomas Huth break;
7675fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBADS_H_32_UL:
7676fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7677fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7678fcf5ef2aSThomas Huth gen_msubads_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7679fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2],
7680fcf5ef2aSThomas Huth n, MODE_UL);
7681fcf5ef2aSThomas Huth break;
7682fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBADS_H_32_UU:
7683fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7684fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7685fcf5ef2aSThomas Huth gen_msubads_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7686fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2],
7687fcf5ef2aSThomas Huth n, MODE_UU);
7688fcf5ef2aSThomas Huth break;
7689fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBADM_H_64_LL:
7690fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7691fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7692fcf5ef2aSThomas Huth gen_msubadm_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7693fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2],
7694fcf5ef2aSThomas Huth n, MODE_LL);
7695fcf5ef2aSThomas Huth break;
7696fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBADM_H_64_LU:
7697fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7698fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7699fcf5ef2aSThomas Huth gen_msubadm_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7700fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2],
7701fcf5ef2aSThomas Huth n, MODE_LU);
7702fcf5ef2aSThomas Huth break;
7703fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBADM_H_64_UL:
7704fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7705fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7706fcf5ef2aSThomas Huth gen_msubadm_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7707fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2],
7708fcf5ef2aSThomas Huth n, MODE_UL);
7709fcf5ef2aSThomas Huth break;
7710fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBADM_H_64_UU:
7711fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7712fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7713fcf5ef2aSThomas Huth gen_msubadm_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7714fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2],
7715fcf5ef2aSThomas Huth n, MODE_UU);
7716fcf5ef2aSThomas Huth break;
7717fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBADMS_H_64_LL:
7718fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7719fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7720fcf5ef2aSThomas Huth gen_msubadms_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7721fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2],
7722fcf5ef2aSThomas Huth n, MODE_LL);
7723fcf5ef2aSThomas Huth break;
7724fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBADMS_H_64_LU:
7725fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7726fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7727fcf5ef2aSThomas Huth gen_msubadms_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7728fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2],
7729fcf5ef2aSThomas Huth n, MODE_LU);
7730fcf5ef2aSThomas Huth break;
7731fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBADMS_H_64_UL:
7732fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7733fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7734fcf5ef2aSThomas Huth gen_msubadms_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7735fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2],
7736fcf5ef2aSThomas Huth n, MODE_UL);
7737fcf5ef2aSThomas Huth break;
7738fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBADMS_H_64_UU:
7739fcf5ef2aSThomas Huth CHECK_REG_PAIR(r4);
7740fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7741fcf5ef2aSThomas Huth gen_msubadms_h(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r3],
7742fcf5ef2aSThomas Huth cpu_gpr_d[r3+1], cpu_gpr_d[r1], cpu_gpr_d[r2],
7743fcf5ef2aSThomas Huth n, MODE_UU);
7744fcf5ef2aSThomas Huth break;
7745fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBADR_H_16_LL:
7746fcf5ef2aSThomas Huth gen_msubadr32_h(cpu_gpr_d[r4], cpu_gpr_d[r3], cpu_gpr_d[r1],
7747fcf5ef2aSThomas Huth cpu_gpr_d[r2], n, MODE_LL);
7748fcf5ef2aSThomas Huth break;
7749fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBADR_H_16_LU:
7750fcf5ef2aSThomas Huth gen_msubadr32_h(cpu_gpr_d[r4], cpu_gpr_d[r3], cpu_gpr_d[r1],
7751fcf5ef2aSThomas Huth cpu_gpr_d[r2], n, MODE_LU);
7752fcf5ef2aSThomas Huth break;
7753fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBADR_H_16_UL:
7754fcf5ef2aSThomas Huth gen_msubadr32_h(cpu_gpr_d[r4], cpu_gpr_d[r3], cpu_gpr_d[r1],
7755fcf5ef2aSThomas Huth cpu_gpr_d[r2], n, MODE_UL);
7756fcf5ef2aSThomas Huth break;
7757fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBADR_H_16_UU:
7758fcf5ef2aSThomas Huth gen_msubadr32_h(cpu_gpr_d[r4], cpu_gpr_d[r3], cpu_gpr_d[r1],
7759fcf5ef2aSThomas Huth cpu_gpr_d[r2], n, MODE_UU);
7760fcf5ef2aSThomas Huth break;
7761fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBADRS_H_16_LL:
7762fcf5ef2aSThomas Huth gen_msubadr32s_h(cpu_gpr_d[r4], cpu_gpr_d[r3], cpu_gpr_d[r1],
7763fcf5ef2aSThomas Huth cpu_gpr_d[r2], n, MODE_LL);
7764fcf5ef2aSThomas Huth break;
7765fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBADRS_H_16_LU:
7766fcf5ef2aSThomas Huth gen_msubadr32s_h(cpu_gpr_d[r4], cpu_gpr_d[r3], cpu_gpr_d[r1],
7767fcf5ef2aSThomas Huth cpu_gpr_d[r2], n, MODE_LU);
7768fcf5ef2aSThomas Huth break;
7769fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBADRS_H_16_UL:
7770fcf5ef2aSThomas Huth gen_msubadr32s_h(cpu_gpr_d[r4], cpu_gpr_d[r3], cpu_gpr_d[r1],
7771fcf5ef2aSThomas Huth cpu_gpr_d[r2], n, MODE_UL);
7772fcf5ef2aSThomas Huth break;
7773fcf5ef2aSThomas Huth case OPC2_32_RRR1_MSUBADRS_H_16_UU:
7774fcf5ef2aSThomas Huth gen_msubadr32s_h(cpu_gpr_d[r4], cpu_gpr_d[r3], cpu_gpr_d[r1],
7775fcf5ef2aSThomas Huth cpu_gpr_d[r2], n, MODE_UU);
7776fcf5ef2aSThomas Huth break;
7777fcf5ef2aSThomas Huth default:
7778fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
7779fcf5ef2aSThomas Huth }
7780fcf5ef2aSThomas Huth }
7781fcf5ef2aSThomas Huth
7782fcf5ef2aSThomas Huth /* RRRR format */
decode_rrrr_extract_insert(DisasContext * ctx)77832db92a0cSBastian Koppelmann static void decode_rrrr_extract_insert(DisasContext *ctx)
7784fcf5ef2aSThomas Huth {
7785fcf5ef2aSThomas Huth uint32_t op2;
7786fcf5ef2aSThomas Huth int r1, r2, r3, r4;
7787fcf5ef2aSThomas Huth TCGv tmp_width, tmp_pos;
7788fcf5ef2aSThomas Huth
7789fcf5ef2aSThomas Huth r1 = MASK_OP_RRRR_S1(ctx->opcode);
7790fcf5ef2aSThomas Huth r2 = MASK_OP_RRRR_S2(ctx->opcode);
7791fcf5ef2aSThomas Huth r3 = MASK_OP_RRRR_S3(ctx->opcode);
7792fcf5ef2aSThomas Huth r4 = MASK_OP_RRRR_D(ctx->opcode);
7793fcf5ef2aSThomas Huth op2 = MASK_OP_RRRR_OP2(ctx->opcode);
7794fcf5ef2aSThomas Huth
7795fcf5ef2aSThomas Huth tmp_pos = tcg_temp_new();
7796fcf5ef2aSThomas Huth tmp_width = tcg_temp_new();
7797fcf5ef2aSThomas Huth
7798fcf5ef2aSThomas Huth switch (op2) {
7799fcf5ef2aSThomas Huth case OPC2_32_RRRR_DEXTR:
7800fcf5ef2aSThomas Huth tcg_gen_andi_tl(tmp_pos, cpu_gpr_d[r3], 0x1f);
7801fcf5ef2aSThomas Huth if (r1 == r2) {
7802fcf5ef2aSThomas Huth tcg_gen_rotl_tl(cpu_gpr_d[r4], cpu_gpr_d[r1], tmp_pos);
7803fcf5ef2aSThomas Huth } else {
7804a4d5d153SBastian Koppelmann TCGv msw = tcg_temp_new();
7805a4d5d153SBastian Koppelmann TCGv zero = tcg_constant_tl(0);
7806fcf5ef2aSThomas Huth tcg_gen_shl_tl(tmp_width, cpu_gpr_d[r1], tmp_pos);
7807a4d5d153SBastian Koppelmann tcg_gen_subfi_tl(msw, 32, tmp_pos);
7808a4d5d153SBastian Koppelmann tcg_gen_shr_tl(msw, cpu_gpr_d[r2], msw);
7809a4d5d153SBastian Koppelmann /*
7810a4d5d153SBastian Koppelmann * if pos == 0, then we do cpu_gpr_d[r2] << 32, which is undefined
7811a4d5d153SBastian Koppelmann * behaviour. So check that case here and set the low bits to zero
7812a4d5d153SBastian Koppelmann * which effectivly returns cpu_gpr_d[r1]
7813a4d5d153SBastian Koppelmann */
7814a4d5d153SBastian Koppelmann tcg_gen_movcond_tl(TCG_COND_EQ, msw, tmp_pos, zero, zero, msw);
7815a4d5d153SBastian Koppelmann tcg_gen_or_tl(cpu_gpr_d[r4], tmp_width, msw);
7816fcf5ef2aSThomas Huth }
7817fcf5ef2aSThomas Huth break;
7818fcf5ef2aSThomas Huth case OPC2_32_RRRR_EXTR:
7819fcf5ef2aSThomas Huth case OPC2_32_RRRR_EXTR_U:
7820fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7821fcf5ef2aSThomas Huth tcg_gen_andi_tl(tmp_width, cpu_gpr_d[r3+1], 0x1f);
7822fcf5ef2aSThomas Huth tcg_gen_andi_tl(tmp_pos, cpu_gpr_d[r3], 0x1f);
7823fcf5ef2aSThomas Huth tcg_gen_add_tl(tmp_pos, tmp_pos, tmp_width);
7824fcf5ef2aSThomas Huth tcg_gen_subfi_tl(tmp_pos, 32, tmp_pos);
7825fcf5ef2aSThomas Huth tcg_gen_shl_tl(cpu_gpr_d[r4], cpu_gpr_d[r1], tmp_pos);
7826fcf5ef2aSThomas Huth tcg_gen_subfi_tl(tmp_width, 32, tmp_width);
7827fcf5ef2aSThomas Huth if (op2 == OPC2_32_RRRR_EXTR) {
7828fcf5ef2aSThomas Huth tcg_gen_sar_tl(cpu_gpr_d[r4], cpu_gpr_d[r4], tmp_width);
7829fcf5ef2aSThomas Huth } else {
7830fcf5ef2aSThomas Huth tcg_gen_shr_tl(cpu_gpr_d[r4], cpu_gpr_d[r4], tmp_width);
7831fcf5ef2aSThomas Huth }
7832fcf5ef2aSThomas Huth break;
7833fcf5ef2aSThomas Huth case OPC2_32_RRRR_INSERT:
7834fcf5ef2aSThomas Huth CHECK_REG_PAIR(r3);
7835fcf5ef2aSThomas Huth tcg_gen_andi_tl(tmp_width, cpu_gpr_d[r3+1], 0x1f);
7836fcf5ef2aSThomas Huth tcg_gen_andi_tl(tmp_pos, cpu_gpr_d[r3], 0x1f);
7837fcf5ef2aSThomas Huth gen_insert(cpu_gpr_d[r4], cpu_gpr_d[r1], cpu_gpr_d[r2], tmp_width,
7838fcf5ef2aSThomas Huth tmp_pos);
7839fcf5ef2aSThomas Huth break;
7840fcf5ef2aSThomas Huth default:
7841fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
7842fcf5ef2aSThomas Huth }
7843fcf5ef2aSThomas Huth }
7844fcf5ef2aSThomas Huth
7845fcf5ef2aSThomas Huth /* RRRW format */
decode_rrrw_extract_insert(DisasContext * ctx)78462db92a0cSBastian Koppelmann static void decode_rrrw_extract_insert(DisasContext *ctx)
7847fcf5ef2aSThomas Huth {
7848fcf5ef2aSThomas Huth uint32_t op2;
7849fcf5ef2aSThomas Huth int r1, r2, r3, r4;
7850fcf5ef2aSThomas Huth int32_t width;
7851fcf5ef2aSThomas Huth
7852fcf5ef2aSThomas Huth TCGv temp, temp2;
7853fcf5ef2aSThomas Huth
7854fcf5ef2aSThomas Huth op2 = MASK_OP_RRRW_OP2(ctx->opcode);
7855fcf5ef2aSThomas Huth r1 = MASK_OP_RRRW_S1(ctx->opcode);
7856fcf5ef2aSThomas Huth r2 = MASK_OP_RRRW_S2(ctx->opcode);
7857fcf5ef2aSThomas Huth r3 = MASK_OP_RRRW_S3(ctx->opcode);
7858fcf5ef2aSThomas Huth r4 = MASK_OP_RRRW_D(ctx->opcode);
7859fcf5ef2aSThomas Huth width = MASK_OP_RRRW_WIDTH(ctx->opcode);
7860fcf5ef2aSThomas Huth
7861fcf5ef2aSThomas Huth temp = tcg_temp_new();
7862fcf5ef2aSThomas Huth
7863fcf5ef2aSThomas Huth switch (op2) {
7864fcf5ef2aSThomas Huth case OPC2_32_RRRW_EXTR:
7865fcf5ef2aSThomas Huth tcg_gen_andi_tl(temp, cpu_gpr_d[r3], 0x1f);
7866fcf5ef2aSThomas Huth tcg_gen_addi_tl(temp, temp, width);
7867fcf5ef2aSThomas Huth tcg_gen_subfi_tl(temp, 32, temp);
7868fcf5ef2aSThomas Huth tcg_gen_shl_tl(cpu_gpr_d[r4], cpu_gpr_d[r1], temp);
7869fcf5ef2aSThomas Huth tcg_gen_sari_tl(cpu_gpr_d[r4], cpu_gpr_d[r4], 32 - width);
7870fcf5ef2aSThomas Huth break;
7871fcf5ef2aSThomas Huth case OPC2_32_RRRW_EXTR_U:
7872fcf5ef2aSThomas Huth if (width == 0) {
7873fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_gpr_d[r4], 0);
7874fcf5ef2aSThomas Huth } else {
7875fcf5ef2aSThomas Huth tcg_gen_andi_tl(temp, cpu_gpr_d[r3], 0x1f);
7876fcf5ef2aSThomas Huth tcg_gen_shr_tl(cpu_gpr_d[r4], cpu_gpr_d[r1], temp);
7877fcf5ef2aSThomas Huth tcg_gen_andi_tl(cpu_gpr_d[r4], cpu_gpr_d[r4], ~0u >> (32-width));
7878fcf5ef2aSThomas Huth }
7879fcf5ef2aSThomas Huth break;
7880fcf5ef2aSThomas Huth case OPC2_32_RRRW_IMASK:
7881fcf5ef2aSThomas Huth temp2 = tcg_temp_new();
78826991777eSBastian Koppelmann CHECK_REG_PAIR(r4);
7883fcf5ef2aSThomas Huth tcg_gen_andi_tl(temp, cpu_gpr_d[r3], 0x1f);
7884fcf5ef2aSThomas Huth tcg_gen_movi_tl(temp2, (1 << width) - 1);
7885fcf5ef2aSThomas Huth tcg_gen_shl_tl(temp2, temp2, temp);
7886fcf5ef2aSThomas Huth tcg_gen_shl_tl(cpu_gpr_d[r4], cpu_gpr_d[r2], temp);
7887fcf5ef2aSThomas Huth tcg_gen_mov_tl(cpu_gpr_d[r4+1], temp2);
7888fcf5ef2aSThomas Huth break;
7889fcf5ef2aSThomas Huth case OPC2_32_RRRW_INSERT:
7890fcf5ef2aSThomas Huth temp2 = tcg_temp_new();
7891fcf5ef2aSThomas Huth
7892fcf5ef2aSThomas Huth tcg_gen_movi_tl(temp, width);
7893fcf5ef2aSThomas Huth tcg_gen_andi_tl(temp2, cpu_gpr_d[r3], 0x1f);
7894fcf5ef2aSThomas Huth gen_insert(cpu_gpr_d[r4], cpu_gpr_d[r1], cpu_gpr_d[r2], temp, temp2);
7895fcf5ef2aSThomas Huth break;
7896fcf5ef2aSThomas Huth default:
7897fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
7898fcf5ef2aSThomas Huth }
7899fcf5ef2aSThomas Huth }
7900fcf5ef2aSThomas Huth
7901fcf5ef2aSThomas Huth /* SYS Format*/
decode_sys_interrupts(DisasContext * ctx)79022db92a0cSBastian Koppelmann static void decode_sys_interrupts(DisasContext *ctx)
7903fcf5ef2aSThomas Huth {
7904fcf5ef2aSThomas Huth uint32_t op2;
7905fcf5ef2aSThomas Huth uint32_t r1;
7906fcf5ef2aSThomas Huth TCGLabel *l1;
7907fcf5ef2aSThomas Huth TCGv tmp;
7908fcf5ef2aSThomas Huth
7909fcf5ef2aSThomas Huth op2 = MASK_OP_SYS_OP2(ctx->opcode);
7910fcf5ef2aSThomas Huth r1 = MASK_OP_SYS_S1D(ctx->opcode);
7911fcf5ef2aSThomas Huth
7912fcf5ef2aSThomas Huth switch (op2) {
7913fcf5ef2aSThomas Huth case OPC2_32_SYS_DEBUG:
7914fcf5ef2aSThomas Huth /* raise EXCP_DEBUG */
7915fcf5ef2aSThomas Huth break;
7916fcf5ef2aSThomas Huth case OPC2_32_SYS_DISABLE:
791757b9c589SBastian Koppelmann if (ctx->priv == TRICORE_PRIV_SM || ctx->priv == TRICORE_PRIV_UM1) {
7918343cdf2cSBastian Koppelmann tcg_gen_andi_tl(cpu_ICR, cpu_ICR, ~ctx->icr_ie_mask);
791957b9c589SBastian Koppelmann } else {
792057b9c589SBastian Koppelmann generate_trap(ctx, TRAPC_PROT, TIN1_PRIV);
792157b9c589SBastian Koppelmann }
7922fcf5ef2aSThomas Huth break;
79230b9f9b63SBastian Koppelmann case OPC2_32_SYS_DISABLE_D:
79240b9f9b63SBastian Koppelmann if (has_feature(ctx, TRICORE_FEATURE_16)) {
792557b9c589SBastian Koppelmann if (ctx->priv == TRICORE_PRIV_SM || ctx->priv == TRICORE_PRIV_UM1) {
792657b9c589SBastian Koppelmann tcg_gen_extract_tl(cpu_gpr_d[r1], cpu_ICR,
792757b9c589SBastian Koppelmann ctx->icr_ie_offset, 1);
79280b9f9b63SBastian Koppelmann tcg_gen_andi_tl(cpu_ICR, cpu_ICR, ~ctx->icr_ie_mask);
79290b9f9b63SBastian Koppelmann } else {
793057b9c589SBastian Koppelmann generate_trap(ctx, TRAPC_PROT, TIN1_PRIV);
793157b9c589SBastian Koppelmann }
793257b9c589SBastian Koppelmann } else {
79330b9f9b63SBastian Koppelmann generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
79340b9f9b63SBastian Koppelmann }
7935fcf5ef2aSThomas Huth case OPC2_32_SYS_DSYNC:
7936fcf5ef2aSThomas Huth break;
7937fcf5ef2aSThomas Huth case OPC2_32_SYS_ENABLE:
793857b9c589SBastian Koppelmann if (ctx->priv == TRICORE_PRIV_SM || ctx->priv == TRICORE_PRIV_UM1) {
7939343cdf2cSBastian Koppelmann tcg_gen_ori_tl(cpu_ICR, cpu_ICR, ctx->icr_ie_mask);
79402dbd73bfSBastian Koppelmann ctx->base.is_jmp = DISAS_EXIT_UPDATE;
794157b9c589SBastian Koppelmann } else {
794257b9c589SBastian Koppelmann generate_trap(ctx, TRAPC_PROT, TIN1_PRIV);
794357b9c589SBastian Koppelmann }
7944fcf5ef2aSThomas Huth break;
7945fcf5ef2aSThomas Huth case OPC2_32_SYS_ISYNC:
7946fcf5ef2aSThomas Huth break;
7947fcf5ef2aSThomas Huth case OPC2_32_SYS_NOP:
7948fcf5ef2aSThomas Huth break;
7949fcf5ef2aSThomas Huth case OPC2_32_SYS_RET:
7950fcf5ef2aSThomas Huth gen_compute_branch(ctx, op2, 0, 0, 0, 0);
7951fcf5ef2aSThomas Huth break;
7952fcf5ef2aSThomas Huth case OPC2_32_SYS_FRET:
7953fcf5ef2aSThomas Huth gen_fret(ctx);
7954fcf5ef2aSThomas Huth break;
7955fcf5ef2aSThomas Huth case OPC2_32_SYS_RFE:
7956ad75a51eSRichard Henderson gen_helper_rfe(tcg_env);
79571706e04fSBastian Koppelmann ctx->base.is_jmp = DISAS_EXIT;
7958fcf5ef2aSThomas Huth break;
7959fcf5ef2aSThomas Huth case OPC2_32_SYS_RFM:
7960878d1b6aSBastian Koppelmann if (ctx->priv == TRICORE_PRIV_SM) {
7961fcf5ef2aSThomas Huth tmp = tcg_temp_new();
7962fcf5ef2aSThomas Huth l1 = gen_new_label();
7963fcf5ef2aSThomas Huth
7964ad75a51eSRichard Henderson tcg_gen_ld32u_tl(tmp, tcg_env, offsetof(CPUTriCoreState, DBGSR));
7965fcf5ef2aSThomas Huth tcg_gen_andi_tl(tmp, tmp, MASK_DBGSR_DE);
7966fcf5ef2aSThomas Huth tcg_gen_brcondi_tl(TCG_COND_NE, tmp, 1, l1);
7967ad75a51eSRichard Henderson gen_helper_rfm(tcg_env);
7968fcf5ef2aSThomas Huth gen_set_label(l1);
79691706e04fSBastian Koppelmann ctx->base.is_jmp = DISAS_EXIT;
7970fcf5ef2aSThomas Huth } else {
797157b9c589SBastian Koppelmann generate_trap(ctx, TRAPC_PROT, TIN1_PRIV);
7972fcf5ef2aSThomas Huth }
7973fcf5ef2aSThomas Huth break;
7974fcf5ef2aSThomas Huth case OPC2_32_SYS_RSLCX:
7975ad75a51eSRichard Henderson gen_helper_rslcx(tcg_env);
7976fcf5ef2aSThomas Huth break;
7977fcf5ef2aSThomas Huth case OPC2_32_SYS_SVLCX:
7978ad75a51eSRichard Henderson gen_helper_svlcx(tcg_env);
7979fcf5ef2aSThomas Huth break;
7980fcf5ef2aSThomas Huth case OPC2_32_SYS_RESTORE:
798144ee3bafSBastian Koppelmann if (has_feature(ctx, TRICORE_FEATURE_16)) {
7982878d1b6aSBastian Koppelmann if (ctx->priv == TRICORE_PRIV_SM || ctx->priv == TRICORE_PRIV_UM1) {
7983a9c37abdSBastian Koppelmann tcg_gen_deposit_tl(cpu_ICR, cpu_ICR, cpu_gpr_d[r1],
7984a9c37abdSBastian Koppelmann ctx->icr_ie_offset, 1);
7985a9c37abdSBastian Koppelmann ctx->base.is_jmp = DISAS_EXIT_UPDATE;
798657b9c589SBastian Koppelmann } else {
798757b9c589SBastian Koppelmann generate_trap(ctx, TRAPC_PROT, TIN1_PRIV);
798857b9c589SBastian Koppelmann }
7989fcf5ef2aSThomas Huth } else {
7990fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
7991fcf5ef2aSThomas Huth }
7992fcf5ef2aSThomas Huth break;
7993fcf5ef2aSThomas Huth case OPC2_32_SYS_TRAPSV:
7994fcf5ef2aSThomas Huth l1 = gen_new_label();
7995fcf5ef2aSThomas Huth tcg_gen_brcondi_tl(TCG_COND_GE, cpu_PSW_SV, 0, l1);
7996fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_ASSERT, TIN5_SOVF);
7997fcf5ef2aSThomas Huth gen_set_label(l1);
7998fcf5ef2aSThomas Huth break;
7999fcf5ef2aSThomas Huth case OPC2_32_SYS_TRAPV:
8000fcf5ef2aSThomas Huth l1 = gen_new_label();
8001fcf5ef2aSThomas Huth tcg_gen_brcondi_tl(TCG_COND_GE, cpu_PSW_V, 0, l1);
8002fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_ASSERT, TIN5_OVF);
8003fcf5ef2aSThomas Huth gen_set_label(l1);
8004fcf5ef2aSThomas Huth break;
8005fcf5ef2aSThomas Huth default:
8006fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
8007fcf5ef2aSThomas Huth }
8008fcf5ef2aSThomas Huth }
8009fcf5ef2aSThomas Huth
decode_32Bit_opc(DisasContext * ctx)80102db92a0cSBastian Koppelmann static void decode_32Bit_opc(DisasContext *ctx)
8011fcf5ef2aSThomas Huth {
801273f874d9SBastian Koppelmann int op1, op2;
8013fcf5ef2aSThomas Huth int32_t r1, r2, r3;
8014fcf5ef2aSThomas Huth int32_t address, const16;
8015fcf5ef2aSThomas Huth int8_t b, const4;
8016fcf5ef2aSThomas Huth int32_t bpos;
8017fcf5ef2aSThomas Huth TCGv temp, temp2, temp3;
8018fcf5ef2aSThomas Huth
8019fcf5ef2aSThomas Huth op1 = MASK_OP_MAJOR(ctx->opcode);
8020fcf5ef2aSThomas Huth
8021fcf5ef2aSThomas Huth /* handle JNZ.T opcode only being 7 bit long */
8022fcf5ef2aSThomas Huth if (unlikely((op1 & 0x7f) == OPCM_32_BRN_JTT)) {
8023fcf5ef2aSThomas Huth op1 = OPCM_32_BRN_JTT;
8024fcf5ef2aSThomas Huth }
8025fcf5ef2aSThomas Huth
8026fcf5ef2aSThomas Huth switch (op1) {
8027fcf5ef2aSThomas Huth /* ABS-format */
8028fcf5ef2aSThomas Huth case OPCM_32_ABS_LDW:
80292db92a0cSBastian Koppelmann decode_abs_ldw(ctx);
8030fcf5ef2aSThomas Huth break;
8031fcf5ef2aSThomas Huth case OPCM_32_ABS_LDB:
80322db92a0cSBastian Koppelmann decode_abs_ldb(ctx);
8033fcf5ef2aSThomas Huth break;
8034fcf5ef2aSThomas Huth case OPCM_32_ABS_LDMST_SWAP:
80352db92a0cSBastian Koppelmann decode_abs_ldst_swap(ctx);
8036fcf5ef2aSThomas Huth break;
8037fcf5ef2aSThomas Huth case OPCM_32_ABS_LDST_CONTEXT:
80382db92a0cSBastian Koppelmann decode_abs_ldst_context(ctx);
8039fcf5ef2aSThomas Huth break;
8040fcf5ef2aSThomas Huth case OPCM_32_ABS_STORE:
80412db92a0cSBastian Koppelmann decode_abs_store(ctx);
8042fcf5ef2aSThomas Huth break;
8043fcf5ef2aSThomas Huth case OPCM_32_ABS_STOREB_H:
80442db92a0cSBastian Koppelmann decode_abs_storeb_h(ctx);
8045fcf5ef2aSThomas Huth break;
8046fcf5ef2aSThomas Huth case OPC1_32_ABS_STOREQ:
8047fcf5ef2aSThomas Huth address = MASK_OP_ABS_OFF18(ctx->opcode);
8048fcf5ef2aSThomas Huth r1 = MASK_OP_ABS_S1D(ctx->opcode);
8049151293c2SRichard Henderson temp = tcg_constant_i32(EA_ABS_FORMAT(address));
8050fcf5ef2aSThomas Huth temp2 = tcg_temp_new();
8051fcf5ef2aSThomas Huth
8052fcf5ef2aSThomas Huth tcg_gen_shri_tl(temp2, cpu_gpr_d[r1], 16);
8053fcf5ef2aSThomas Huth tcg_gen_qemu_st_tl(temp2, temp, ctx->mem_idx, MO_LEUW);
8054fcf5ef2aSThomas Huth break;
8055fcf5ef2aSThomas Huth case OPC1_32_ABS_LD_Q:
8056fcf5ef2aSThomas Huth address = MASK_OP_ABS_OFF18(ctx->opcode);
8057fcf5ef2aSThomas Huth r1 = MASK_OP_ABS_S1D(ctx->opcode);
8058151293c2SRichard Henderson temp = tcg_constant_i32(EA_ABS_FORMAT(address));
8059fcf5ef2aSThomas Huth
8060fcf5ef2aSThomas Huth tcg_gen_qemu_ld_tl(cpu_gpr_d[r1], temp, ctx->mem_idx, MO_LEUW);
8061fcf5ef2aSThomas Huth tcg_gen_shli_tl(cpu_gpr_d[r1], cpu_gpr_d[r1], 16);
8062fcf5ef2aSThomas Huth break;
806373f874d9SBastian Koppelmann case OPCM_32_ABS_LEA_LHA:
8064fcf5ef2aSThomas Huth address = MASK_OP_ABS_OFF18(ctx->opcode);
8065fcf5ef2aSThomas Huth r1 = MASK_OP_ABS_S1D(ctx->opcode);
806673f874d9SBastian Koppelmann
806773f874d9SBastian Koppelmann if (has_feature(ctx, TRICORE_FEATURE_162)) {
806873f874d9SBastian Koppelmann op2 = MASK_OP_ABS_OP2(ctx->opcode);
806973f874d9SBastian Koppelmann if (op2 == OPC2_32_ABS_LHA) {
807073f874d9SBastian Koppelmann tcg_gen_movi_tl(cpu_gpr_a[r1], address << 14);
807173f874d9SBastian Koppelmann break;
807273f874d9SBastian Koppelmann }
807373f874d9SBastian Koppelmann /* otherwise translate regular LEA */
807473f874d9SBastian Koppelmann }
807573f874d9SBastian Koppelmann
8076fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_gpr_a[r1], EA_ABS_FORMAT(address));
8077fcf5ef2aSThomas Huth break;
8078fcf5ef2aSThomas Huth /* ABSB-format */
8079fcf5ef2aSThomas Huth case OPC1_32_ABSB_ST_T:
8080fcf5ef2aSThomas Huth address = MASK_OP_ABS_OFF18(ctx->opcode);
8081fcf5ef2aSThomas Huth b = MASK_OP_ABSB_B(ctx->opcode);
8082fcf5ef2aSThomas Huth bpos = MASK_OP_ABSB_BPOS(ctx->opcode);
8083fcf5ef2aSThomas Huth
8084151293c2SRichard Henderson temp = tcg_constant_i32(EA_ABS_FORMAT(address));
8085fcf5ef2aSThomas Huth temp2 = tcg_temp_new();
8086fcf5ef2aSThomas Huth
8087fcf5ef2aSThomas Huth tcg_gen_qemu_ld_tl(temp2, temp, ctx->mem_idx, MO_UB);
8088fcf5ef2aSThomas Huth tcg_gen_andi_tl(temp2, temp2, ~(0x1u << bpos));
8089fcf5ef2aSThomas Huth tcg_gen_ori_tl(temp2, temp2, (b << bpos));
8090fcf5ef2aSThomas Huth tcg_gen_qemu_st_tl(temp2, temp, ctx->mem_idx, MO_UB);
8091fcf5ef2aSThomas Huth break;
8092fcf5ef2aSThomas Huth /* B-format */
8093fcf5ef2aSThomas Huth case OPC1_32_B_CALL:
8094fcf5ef2aSThomas Huth case OPC1_32_B_CALLA:
8095fcf5ef2aSThomas Huth case OPC1_32_B_FCALL:
8096fcf5ef2aSThomas Huth case OPC1_32_B_FCALLA:
8097fcf5ef2aSThomas Huth case OPC1_32_B_J:
8098fcf5ef2aSThomas Huth case OPC1_32_B_JA:
8099fcf5ef2aSThomas Huth case OPC1_32_B_JL:
8100fcf5ef2aSThomas Huth case OPC1_32_B_JLA:
8101fcf5ef2aSThomas Huth address = MASK_OP_B_DISP24_SEXT(ctx->opcode);
8102fcf5ef2aSThomas Huth gen_compute_branch(ctx, op1, 0, 0, 0, address);
8103fcf5ef2aSThomas Huth break;
8104fcf5ef2aSThomas Huth /* Bit-format */
8105fcf5ef2aSThomas Huth case OPCM_32_BIT_ANDACC:
81062db92a0cSBastian Koppelmann decode_bit_andacc(ctx);
8107fcf5ef2aSThomas Huth break;
8108fcf5ef2aSThomas Huth case OPCM_32_BIT_LOGICAL_T1:
81092db92a0cSBastian Koppelmann decode_bit_logical_t(ctx);
8110fcf5ef2aSThomas Huth break;
8111fcf5ef2aSThomas Huth case OPCM_32_BIT_INSERT:
81122db92a0cSBastian Koppelmann decode_bit_insert(ctx);
8113fcf5ef2aSThomas Huth break;
8114fcf5ef2aSThomas Huth case OPCM_32_BIT_LOGICAL_T2:
81152db92a0cSBastian Koppelmann decode_bit_logical_t2(ctx);
8116fcf5ef2aSThomas Huth break;
8117fcf5ef2aSThomas Huth case OPCM_32_BIT_ORAND:
81182db92a0cSBastian Koppelmann decode_bit_orand(ctx);
8119fcf5ef2aSThomas Huth break;
8120fcf5ef2aSThomas Huth case OPCM_32_BIT_SH_LOGIC1:
81212db92a0cSBastian Koppelmann decode_bit_sh_logic1(ctx);
8122fcf5ef2aSThomas Huth break;
8123fcf5ef2aSThomas Huth case OPCM_32_BIT_SH_LOGIC2:
81242db92a0cSBastian Koppelmann decode_bit_sh_logic2(ctx);
8125fcf5ef2aSThomas Huth break;
8126fcf5ef2aSThomas Huth /* BO Format */
8127fcf5ef2aSThomas Huth case OPCM_32_BO_ADDRMODE_POST_PRE_BASE:
81282db92a0cSBastian Koppelmann decode_bo_addrmode_post_pre_base(ctx);
8129fcf5ef2aSThomas Huth break;
8130fcf5ef2aSThomas Huth case OPCM_32_BO_ADDRMODE_BITREVERSE_CIRCULAR:
81312db92a0cSBastian Koppelmann decode_bo_addrmode_bitreverse_circular(ctx);
8132fcf5ef2aSThomas Huth break;
8133fcf5ef2aSThomas Huth case OPCM_32_BO_ADDRMODE_LD_POST_PRE_BASE:
81342db92a0cSBastian Koppelmann decode_bo_addrmode_ld_post_pre_base(ctx);
8135fcf5ef2aSThomas Huth break;
8136fcf5ef2aSThomas Huth case OPCM_32_BO_ADDRMODE_LD_BITREVERSE_CIRCULAR:
81372db92a0cSBastian Koppelmann decode_bo_addrmode_ld_bitreverse_circular(ctx);
8138fcf5ef2aSThomas Huth break;
8139fcf5ef2aSThomas Huth case OPCM_32_BO_ADDRMODE_STCTX_POST_PRE_BASE:
81402db92a0cSBastian Koppelmann decode_bo_addrmode_stctx_post_pre_base(ctx);
8141fcf5ef2aSThomas Huth break;
8142fcf5ef2aSThomas Huth case OPCM_32_BO_ADDRMODE_LDMST_BITREVERSE_CIRCULAR:
81432db92a0cSBastian Koppelmann decode_bo_addrmode_ldmst_bitreverse_circular(ctx);
8144fcf5ef2aSThomas Huth break;
8145fcf5ef2aSThomas Huth /* BOL-format */
8146fcf5ef2aSThomas Huth case OPC1_32_BOL_LD_A_LONGOFF:
8147fcf5ef2aSThomas Huth case OPC1_32_BOL_LD_W_LONGOFF:
8148fcf5ef2aSThomas Huth case OPC1_32_BOL_LEA_LONGOFF:
8149fcf5ef2aSThomas Huth case OPC1_32_BOL_ST_W_LONGOFF:
8150fcf5ef2aSThomas Huth case OPC1_32_BOL_ST_A_LONGOFF:
8151fcf5ef2aSThomas Huth case OPC1_32_BOL_LD_B_LONGOFF:
8152fcf5ef2aSThomas Huth case OPC1_32_BOL_LD_BU_LONGOFF:
8153fcf5ef2aSThomas Huth case OPC1_32_BOL_LD_H_LONGOFF:
8154fcf5ef2aSThomas Huth case OPC1_32_BOL_LD_HU_LONGOFF:
8155fcf5ef2aSThomas Huth case OPC1_32_BOL_ST_B_LONGOFF:
8156fcf5ef2aSThomas Huth case OPC1_32_BOL_ST_H_LONGOFF:
81572db92a0cSBastian Koppelmann decode_bol_opc(ctx, op1);
8158fcf5ef2aSThomas Huth break;
8159fcf5ef2aSThomas Huth /* BRC Format */
8160fcf5ef2aSThomas Huth case OPCM_32_BRC_EQ_NEQ:
8161fcf5ef2aSThomas Huth case OPCM_32_BRC_GE:
8162fcf5ef2aSThomas Huth case OPCM_32_BRC_JLT:
8163fcf5ef2aSThomas Huth case OPCM_32_BRC_JNE:
8164fcf5ef2aSThomas Huth const4 = MASK_OP_BRC_CONST4_SEXT(ctx->opcode);
8165fcf5ef2aSThomas Huth address = MASK_OP_BRC_DISP15_SEXT(ctx->opcode);
8166fcf5ef2aSThomas Huth r1 = MASK_OP_BRC_S1(ctx->opcode);
8167fcf5ef2aSThomas Huth gen_compute_branch(ctx, op1, r1, 0, const4, address);
8168fcf5ef2aSThomas Huth break;
8169fcf5ef2aSThomas Huth /* BRN Format */
8170fcf5ef2aSThomas Huth case OPCM_32_BRN_JTT:
8171fcf5ef2aSThomas Huth address = MASK_OP_BRN_DISP15_SEXT(ctx->opcode);
8172fcf5ef2aSThomas Huth r1 = MASK_OP_BRN_S1(ctx->opcode);
8173fcf5ef2aSThomas Huth gen_compute_branch(ctx, op1, r1, 0, 0, address);
8174fcf5ef2aSThomas Huth break;
8175fcf5ef2aSThomas Huth /* BRR Format */
8176fcf5ef2aSThomas Huth case OPCM_32_BRR_EQ_NEQ:
8177fcf5ef2aSThomas Huth case OPCM_32_BRR_ADDR_EQ_NEQ:
8178fcf5ef2aSThomas Huth case OPCM_32_BRR_GE:
8179fcf5ef2aSThomas Huth case OPCM_32_BRR_JLT:
8180fcf5ef2aSThomas Huth case OPCM_32_BRR_JNE:
8181fcf5ef2aSThomas Huth case OPCM_32_BRR_JNZ:
8182fcf5ef2aSThomas Huth case OPCM_32_BRR_LOOP:
8183fcf5ef2aSThomas Huth address = MASK_OP_BRR_DISP15_SEXT(ctx->opcode);
8184fcf5ef2aSThomas Huth r2 = MASK_OP_BRR_S2(ctx->opcode);
8185fcf5ef2aSThomas Huth r1 = MASK_OP_BRR_S1(ctx->opcode);
8186fcf5ef2aSThomas Huth gen_compute_branch(ctx, op1, r1, r2, 0, address);
8187fcf5ef2aSThomas Huth break;
8188fcf5ef2aSThomas Huth /* RC Format */
8189fcf5ef2aSThomas Huth case OPCM_32_RC_LOGICAL_SHIFT:
81902db92a0cSBastian Koppelmann decode_rc_logical_shift(ctx);
8191fcf5ef2aSThomas Huth break;
8192fcf5ef2aSThomas Huth case OPCM_32_RC_ACCUMULATOR:
81932db92a0cSBastian Koppelmann decode_rc_accumulator(ctx);
8194fcf5ef2aSThomas Huth break;
8195fcf5ef2aSThomas Huth case OPCM_32_RC_SERVICEROUTINE:
81962db92a0cSBastian Koppelmann decode_rc_serviceroutine(ctx);
8197fcf5ef2aSThomas Huth break;
8198fcf5ef2aSThomas Huth case OPCM_32_RC_MUL:
81992db92a0cSBastian Koppelmann decode_rc_mul(ctx);
8200fcf5ef2aSThomas Huth break;
8201fcf5ef2aSThomas Huth /* RCPW Format */
8202fcf5ef2aSThomas Huth case OPCM_32_RCPW_MASK_INSERT:
82032db92a0cSBastian Koppelmann decode_rcpw_insert(ctx);
8204fcf5ef2aSThomas Huth break;
8205fcf5ef2aSThomas Huth /* RCRR Format */
8206fcf5ef2aSThomas Huth case OPC1_32_RCRR_INSERT:
8207fcf5ef2aSThomas Huth r1 = MASK_OP_RCRR_S1(ctx->opcode);
8208fcf5ef2aSThomas Huth r2 = MASK_OP_RCRR_S3(ctx->opcode);
8209fcf5ef2aSThomas Huth r3 = MASK_OP_RCRR_D(ctx->opcode);
8210fcf5ef2aSThomas Huth const16 = MASK_OP_RCRR_CONST4(ctx->opcode);
8211151293c2SRichard Henderson temp = tcg_constant_i32(const16);
8212fcf5ef2aSThomas Huth temp2 = tcg_temp_new(); /* width*/
8213fcf5ef2aSThomas Huth temp3 = tcg_temp_new(); /* pos */
8214fcf5ef2aSThomas Huth
8215222ff2d3SBastian Koppelmann CHECK_REG_PAIR(r2);
8216fcf5ef2aSThomas Huth
8217222ff2d3SBastian Koppelmann tcg_gen_andi_tl(temp2, cpu_gpr_d[r2 + 1], 0x1f);
8218222ff2d3SBastian Koppelmann tcg_gen_andi_tl(temp3, cpu_gpr_d[r2], 0x1f);
8219fcf5ef2aSThomas Huth
8220222ff2d3SBastian Koppelmann gen_insert(cpu_gpr_d[r3], cpu_gpr_d[r1], temp, temp2, temp3);
8221fcf5ef2aSThomas Huth break;
8222fcf5ef2aSThomas Huth /* RCRW Format */
8223fcf5ef2aSThomas Huth case OPCM_32_RCRW_MASK_INSERT:
82242db92a0cSBastian Koppelmann decode_rcrw_insert(ctx);
8225fcf5ef2aSThomas Huth break;
8226fcf5ef2aSThomas Huth /* RCR Format */
8227fcf5ef2aSThomas Huth case OPCM_32_RCR_COND_SELECT:
82282db92a0cSBastian Koppelmann decode_rcr_cond_select(ctx);
8229fcf5ef2aSThomas Huth break;
8230fcf5ef2aSThomas Huth case OPCM_32_RCR_MADD:
82312db92a0cSBastian Koppelmann decode_rcr_madd(ctx);
8232fcf5ef2aSThomas Huth break;
8233fcf5ef2aSThomas Huth case OPCM_32_RCR_MSUB:
82342db92a0cSBastian Koppelmann decode_rcr_msub(ctx);
8235fcf5ef2aSThomas Huth break;
8236fcf5ef2aSThomas Huth /* RLC Format */
8237fcf5ef2aSThomas Huth case OPC1_32_RLC_ADDI:
8238fcf5ef2aSThomas Huth case OPC1_32_RLC_ADDIH:
8239fcf5ef2aSThomas Huth case OPC1_32_RLC_ADDIH_A:
8240fcf5ef2aSThomas Huth case OPC1_32_RLC_MFCR:
8241fcf5ef2aSThomas Huth case OPC1_32_RLC_MOV:
8242fcf5ef2aSThomas Huth case OPC1_32_RLC_MOV_64:
8243fcf5ef2aSThomas Huth case OPC1_32_RLC_MOV_U:
8244fcf5ef2aSThomas Huth case OPC1_32_RLC_MOV_H:
8245fcf5ef2aSThomas Huth case OPC1_32_RLC_MOVH_A:
8246fcf5ef2aSThomas Huth case OPC1_32_RLC_MTCR:
82472db92a0cSBastian Koppelmann decode_rlc_opc(ctx, op1);
8248fcf5ef2aSThomas Huth break;
8249fcf5ef2aSThomas Huth /* RR Format */
8250fcf5ef2aSThomas Huth case OPCM_32_RR_ACCUMULATOR:
82512db92a0cSBastian Koppelmann decode_rr_accumulator(ctx);
8252fcf5ef2aSThomas Huth break;
8253fcf5ef2aSThomas Huth case OPCM_32_RR_LOGICAL_SHIFT:
82542db92a0cSBastian Koppelmann decode_rr_logical_shift(ctx);
8255fcf5ef2aSThomas Huth break;
8256fcf5ef2aSThomas Huth case OPCM_32_RR_ADDRESS:
82572db92a0cSBastian Koppelmann decode_rr_address(ctx);
8258fcf5ef2aSThomas Huth break;
8259fcf5ef2aSThomas Huth case OPCM_32_RR_IDIRECT:
82602db92a0cSBastian Koppelmann decode_rr_idirect(ctx);
8261fcf5ef2aSThomas Huth break;
8262fcf5ef2aSThomas Huth case OPCM_32_RR_DIVIDE:
82632db92a0cSBastian Koppelmann decode_rr_divide(ctx);
8264fcf5ef2aSThomas Huth break;
8265fcf5ef2aSThomas Huth /* RR1 Format */
8266fcf5ef2aSThomas Huth case OPCM_32_RR1_MUL:
82672db92a0cSBastian Koppelmann decode_rr1_mul(ctx);
8268fcf5ef2aSThomas Huth break;
8269fcf5ef2aSThomas Huth case OPCM_32_RR1_MULQ:
82702db92a0cSBastian Koppelmann decode_rr1_mulq(ctx);
8271fcf5ef2aSThomas Huth break;
8272fcf5ef2aSThomas Huth /* RR2 format */
8273fcf5ef2aSThomas Huth case OPCM_32_RR2_MUL:
82742db92a0cSBastian Koppelmann decode_rr2_mul(ctx);
8275fcf5ef2aSThomas Huth break;
8276fcf5ef2aSThomas Huth /* RRPW format */
8277fcf5ef2aSThomas Huth case OPCM_32_RRPW_EXTRACT_INSERT:
82782db92a0cSBastian Koppelmann decode_rrpw_extract_insert(ctx);
8279fcf5ef2aSThomas Huth break;
8280fcf5ef2aSThomas Huth case OPC1_32_RRPW_DEXTR:
8281fcf5ef2aSThomas Huth r1 = MASK_OP_RRPW_S1(ctx->opcode);
8282fcf5ef2aSThomas Huth r2 = MASK_OP_RRPW_S2(ctx->opcode);
8283fcf5ef2aSThomas Huth r3 = MASK_OP_RRPW_D(ctx->opcode);
8284fcf5ef2aSThomas Huth const16 = MASK_OP_RRPW_POS(ctx->opcode);
828548bffe7fSBastian Koppelmann
828648bffe7fSBastian Koppelmann tcg_gen_extract2_tl(cpu_gpr_d[r3], cpu_gpr_d[r2], cpu_gpr_d[r1],
828748bffe7fSBastian Koppelmann 32 - const16);
8288fcf5ef2aSThomas Huth break;
8289fcf5ef2aSThomas Huth /* RRR Format */
8290fcf5ef2aSThomas Huth case OPCM_32_RRR_COND_SELECT:
82912db92a0cSBastian Koppelmann decode_rrr_cond_select(ctx);
8292fcf5ef2aSThomas Huth break;
8293fcf5ef2aSThomas Huth case OPCM_32_RRR_DIVIDE:
82942db92a0cSBastian Koppelmann decode_rrr_divide(ctx);
8295fcf5ef2aSThomas Huth break;
8296fcf5ef2aSThomas Huth /* RRR2 Format */
8297fcf5ef2aSThomas Huth case OPCM_32_RRR2_MADD:
82982db92a0cSBastian Koppelmann decode_rrr2_madd(ctx);
8299fcf5ef2aSThomas Huth break;
8300fcf5ef2aSThomas Huth case OPCM_32_RRR2_MSUB:
83012db92a0cSBastian Koppelmann decode_rrr2_msub(ctx);
8302fcf5ef2aSThomas Huth break;
8303fcf5ef2aSThomas Huth /* RRR1 format */
8304fcf5ef2aSThomas Huth case OPCM_32_RRR1_MADD:
83052db92a0cSBastian Koppelmann decode_rrr1_madd(ctx);
8306fcf5ef2aSThomas Huth break;
8307fcf5ef2aSThomas Huth case OPCM_32_RRR1_MADDQ_H:
83082db92a0cSBastian Koppelmann decode_rrr1_maddq_h(ctx);
8309fcf5ef2aSThomas Huth break;
8310fcf5ef2aSThomas Huth case OPCM_32_RRR1_MADDSU_H:
83112db92a0cSBastian Koppelmann decode_rrr1_maddsu_h(ctx);
8312fcf5ef2aSThomas Huth break;
8313fcf5ef2aSThomas Huth case OPCM_32_RRR1_MSUB_H:
83142db92a0cSBastian Koppelmann decode_rrr1_msub(ctx);
8315fcf5ef2aSThomas Huth break;
8316fcf5ef2aSThomas Huth case OPCM_32_RRR1_MSUB_Q:
83172db92a0cSBastian Koppelmann decode_rrr1_msubq_h(ctx);
8318fcf5ef2aSThomas Huth break;
8319fcf5ef2aSThomas Huth case OPCM_32_RRR1_MSUBAD_H:
83202db92a0cSBastian Koppelmann decode_rrr1_msubad_h(ctx);
8321fcf5ef2aSThomas Huth break;
8322fcf5ef2aSThomas Huth /* RRRR format */
8323fcf5ef2aSThomas Huth case OPCM_32_RRRR_EXTRACT_INSERT:
83242db92a0cSBastian Koppelmann decode_rrrr_extract_insert(ctx);
8325fcf5ef2aSThomas Huth break;
8326fcf5ef2aSThomas Huth /* RRRW format */
8327fcf5ef2aSThomas Huth case OPCM_32_RRRW_EXTRACT_INSERT:
83282db92a0cSBastian Koppelmann decode_rrrw_extract_insert(ctx);
8329fcf5ef2aSThomas Huth break;
8330fcf5ef2aSThomas Huth /* SYS format */
8331fcf5ef2aSThomas Huth case OPCM_32_SYS_INTERRUPTS:
83322db92a0cSBastian Koppelmann decode_sys_interrupts(ctx);
8333fcf5ef2aSThomas Huth break;
8334fcf5ef2aSThomas Huth case OPC1_32_SYS_RSTV:
8335fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_PSW_V, 0);
8336fcf5ef2aSThomas Huth tcg_gen_mov_tl(cpu_PSW_SV, cpu_PSW_V);
8337fcf5ef2aSThomas Huth tcg_gen_mov_tl(cpu_PSW_AV, cpu_PSW_V);
8338fcf5ef2aSThomas Huth tcg_gen_mov_tl(cpu_PSW_SAV, cpu_PSW_V);
8339fcf5ef2aSThomas Huth break;
8340fcf5ef2aSThomas Huth default:
8341fcf5ef2aSThomas Huth generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
8342fcf5ef2aSThomas Huth }
8343fcf5ef2aSThomas Huth }
8344fcf5ef2aSThomas Huth
tricore_insn_is_16bit(uint32_t insn)8345d4881da9SBastian Koppelmann static bool tricore_insn_is_16bit(uint32_t insn)
8346fcf5ef2aSThomas Huth {
8347d4881da9SBastian Koppelmann return (insn & 0x1) == 0;
8348fcf5ef2aSThomas Huth }
8349fcf5ef2aSThomas Huth
tricore_tr_init_disas_context(DisasContextBase * dcbase,CPUState * cs)83501fae1851SBastian Koppelmann static void tricore_tr_init_disas_context(DisasContextBase *dcbase,
83511fae1851SBastian Koppelmann CPUState *cs)
83521fae1851SBastian Koppelmann {
83531fae1851SBastian Koppelmann DisasContext *ctx = container_of(dcbase, DisasContext, base);
8354b77af26eSRichard Henderson CPUTriCoreState *env = cpu_env(cs);
83553b916140SRichard Henderson ctx->mem_idx = cpu_mmu_index(cs, false);
8356878d1b6aSBastian Koppelmann
8357878d1b6aSBastian Koppelmann uint32_t tb_flags = (uint32_t)ctx->base.tb->flags;
8358878d1b6aSBastian Koppelmann ctx->priv = FIELD_EX32(tb_flags, TB_FLAGS, PRIV);
8359878d1b6aSBastian Koppelmann
836044ee3bafSBastian Koppelmann ctx->features = env->features;
8361343cdf2cSBastian Koppelmann if (has_feature(ctx, TRICORE_FEATURE_161)) {
8362343cdf2cSBastian Koppelmann ctx->icr_ie_mask = R_ICR_IE_161_MASK;
83630b9f9b63SBastian Koppelmann ctx->icr_ie_offset = R_ICR_IE_161_SHIFT;
8364343cdf2cSBastian Koppelmann } else {
8365343cdf2cSBastian Koppelmann ctx->icr_ie_mask = R_ICR_IE_13_MASK;
83660b9f9b63SBastian Koppelmann ctx->icr_ie_offset = R_ICR_IE_13_SHIFT;
8367343cdf2cSBastian Koppelmann }
83681fae1851SBastian Koppelmann }
83691fae1851SBastian Koppelmann
tricore_tr_tb_start(DisasContextBase * db,CPUState * cpu)83701fae1851SBastian Koppelmann static void tricore_tr_tb_start(DisasContextBase *db, CPUState *cpu)
83711fae1851SBastian Koppelmann {
83721fae1851SBastian Koppelmann }
83731fae1851SBastian Koppelmann
tricore_tr_insn_start(DisasContextBase * dcbase,CPUState * cpu)83741fae1851SBastian Koppelmann static void tricore_tr_insn_start(DisasContextBase *dcbase, CPUState *cpu)
83751fae1851SBastian Koppelmann {
83761fae1851SBastian Koppelmann DisasContext *ctx = container_of(dcbase, DisasContext, base);
83771fae1851SBastian Koppelmann
83781fae1851SBastian Koppelmann tcg_gen_insn_start(ctx->base.pc_next);
83791fae1851SBastian Koppelmann }
83801fae1851SBastian Koppelmann
insn_crosses_page(CPUTriCoreState * env,DisasContext * ctx)8381d4881da9SBastian Koppelmann static bool insn_crosses_page(CPUTriCoreState *env, DisasContext *ctx)
8382d4881da9SBastian Koppelmann {
8383d4881da9SBastian Koppelmann /*
8384d4881da9SBastian Koppelmann * Return true if the insn at ctx->base.pc_next might cross a page boundary.
8385d4881da9SBastian Koppelmann * (False positives are OK, false negatives are not.)
8386d4881da9SBastian Koppelmann * Our caller ensures we are only called if dc->base.pc_next is less than
8387d4881da9SBastian Koppelmann * 4 bytes from the page boundary, so we cross the page if the first
8388d4881da9SBastian Koppelmann * 16 bits indicate that this is a 32 bit insn.
8389d4881da9SBastian Koppelmann */
83901f22db19SBastian Koppelmann uint16_t insn = translator_lduw(env, &ctx->base, ctx->base.pc_next);
8391d4881da9SBastian Koppelmann
8392d4881da9SBastian Koppelmann return !tricore_insn_is_16bit(insn);
8393d4881da9SBastian Koppelmann }
8394d4881da9SBastian Koppelmann
8395d4881da9SBastian Koppelmann
tricore_tr_translate_insn(DisasContextBase * dcbase,CPUState * cpu)83961fae1851SBastian Koppelmann static void tricore_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu)
83971fae1851SBastian Koppelmann {
83981fae1851SBastian Koppelmann DisasContext *ctx = container_of(dcbase, DisasContext, base);
8399b77af26eSRichard Henderson CPUTriCoreState *env = cpu_env(cpu);
8400d4881da9SBastian Koppelmann uint16_t insn_lo;
8401d4881da9SBastian Koppelmann bool is_16bit;
84021fae1851SBastian Koppelmann
84031f22db19SBastian Koppelmann insn_lo = translator_lduw(env, &ctx->base, ctx->base.pc_next);
8404d4881da9SBastian Koppelmann is_16bit = tricore_insn_is_16bit(insn_lo);
8405d4881da9SBastian Koppelmann if (is_16bit) {
8406d4881da9SBastian Koppelmann ctx->opcode = insn_lo;
8407d4881da9SBastian Koppelmann ctx->pc_succ_insn = ctx->base.pc_next + 2;
8408d4881da9SBastian Koppelmann decode_16Bit_opc(ctx);
8409d4881da9SBastian Koppelmann } else {
84101f22db19SBastian Koppelmann uint32_t insn_hi = translator_lduw(env, &ctx->base,
84111f22db19SBastian Koppelmann ctx->base.pc_next + 2);
8412d4881da9SBastian Koppelmann ctx->opcode = insn_hi << 16 | insn_lo;
8413d4881da9SBastian Koppelmann ctx->pc_succ_insn = ctx->base.pc_next + 4;
8414d4881da9SBastian Koppelmann decode_32Bit_opc(ctx);
8415d4881da9SBastian Koppelmann }
84161fae1851SBastian Koppelmann ctx->base.pc_next = ctx->pc_succ_insn;
84171fae1851SBastian Koppelmann
84181fae1851SBastian Koppelmann if (ctx->base.is_jmp == DISAS_NEXT) {
84191fae1851SBastian Koppelmann target_ulong page_start;
84201fae1851SBastian Koppelmann
84211fae1851SBastian Koppelmann page_start = ctx->base.pc_first & TARGET_PAGE_MASK;
8422d4881da9SBastian Koppelmann if (ctx->base.pc_next - page_start >= TARGET_PAGE_SIZE
8423d4881da9SBastian Koppelmann || (ctx->base.pc_next - page_start >= TARGET_PAGE_SIZE - 3
8424d4881da9SBastian Koppelmann && insn_crosses_page(env, ctx))) {
84251fae1851SBastian Koppelmann ctx->base.is_jmp = DISAS_TOO_MANY;
84261fae1851SBastian Koppelmann }
84271fae1851SBastian Koppelmann }
84281fae1851SBastian Koppelmann }
84291fae1851SBastian Koppelmann
tricore_tr_tb_stop(DisasContextBase * dcbase,CPUState * cpu)84301fae1851SBastian Koppelmann static void tricore_tr_tb_stop(DisasContextBase *dcbase, CPUState *cpu)
84311fae1851SBastian Koppelmann {
84321fae1851SBastian Koppelmann DisasContext *ctx = container_of(dcbase, DisasContext, base);
84331fae1851SBastian Koppelmann
84341fae1851SBastian Koppelmann switch (ctx->base.is_jmp) {
84351fae1851SBastian Koppelmann case DISAS_TOO_MANY:
84361fae1851SBastian Koppelmann gen_goto_tb(ctx, 0, ctx->base.pc_next);
84371fae1851SBastian Koppelmann break;
84382dbd73bfSBastian Koppelmann case DISAS_EXIT_UPDATE:
84392dbd73bfSBastian Koppelmann gen_save_pc(ctx->base.pc_next);
84402dbd73bfSBastian Koppelmann /* fall through */
84411706e04fSBastian Koppelmann case DISAS_EXIT:
84421706e04fSBastian Koppelmann tcg_gen_exit_tb(NULL, 0);
84431706e04fSBastian Koppelmann break;
8444d8f466afSBastian Koppelmann case DISAS_JUMP:
8445d8f466afSBastian Koppelmann tcg_gen_lookup_and_goto_ptr();
8446d8f466afSBastian Koppelmann break;
84471fae1851SBastian Koppelmann case DISAS_NORETURN:
84481fae1851SBastian Koppelmann break;
84491fae1851SBastian Koppelmann default:
84501fae1851SBastian Koppelmann g_assert_not_reached();
84511fae1851SBastian Koppelmann }
84521fae1851SBastian Koppelmann }
84531fae1851SBastian Koppelmann
84541fae1851SBastian Koppelmann static const TranslatorOps tricore_tr_ops = {
84551fae1851SBastian Koppelmann .init_disas_context = tricore_tr_init_disas_context,
84561fae1851SBastian Koppelmann .tb_start = tricore_tr_tb_start,
84571fae1851SBastian Koppelmann .insn_start = tricore_tr_insn_start,
84581fae1851SBastian Koppelmann .translate_insn = tricore_tr_translate_insn,
84591fae1851SBastian Koppelmann .tb_stop = tricore_tr_tb_stop,
84601fae1851SBastian Koppelmann };
84611fae1851SBastian Koppelmann
84621fae1851SBastian Koppelmann
gen_intermediate_code(CPUState * cs,TranslationBlock * tb,int * max_insns,vaddr pc,void * host_pc)8463597f9b2dSRichard Henderson void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int *max_insns,
846432f0c394SAnton Johansson vaddr pc, void *host_pc)
8465fcf5ef2aSThomas Huth {
8466fcf5ef2aSThomas Huth DisasContext ctx;
8467306c8721SRichard Henderson translator_loop(cs, tb, max_insns, pc, host_pc,
8468306c8721SRichard Henderson &tricore_tr_ops, &ctx.base);
8469fcf5ef2aSThomas Huth }
8470fcf5ef2aSThomas Huth
8471fcf5ef2aSThomas Huth /*
8472fcf5ef2aSThomas Huth *
8473fcf5ef2aSThomas Huth * Initialization
8474fcf5ef2aSThomas Huth *
8475fcf5ef2aSThomas Huth */
8476fcf5ef2aSThomas Huth
cpu_state_reset(CPUTriCoreState * env)8477fcf5ef2aSThomas Huth void cpu_state_reset(CPUTriCoreState *env)
8478fcf5ef2aSThomas Huth {
8479fcf5ef2aSThomas Huth /* Reset Regs to Default Value */
8480fcf5ef2aSThomas Huth env->PSW = 0xb80;
8481fcf5ef2aSThomas Huth fpu_set_state(env);
8482fcf5ef2aSThomas Huth }
8483fcf5ef2aSThomas Huth
tricore_tcg_init_csfr(void)8484fcf5ef2aSThomas Huth static void tricore_tcg_init_csfr(void)
8485fcf5ef2aSThomas Huth {
8486ad75a51eSRichard Henderson cpu_PCXI = tcg_global_mem_new(tcg_env,
8487fcf5ef2aSThomas Huth offsetof(CPUTriCoreState, PCXI), "PCXI");
8488ad75a51eSRichard Henderson cpu_PSW = tcg_global_mem_new(tcg_env,
8489fcf5ef2aSThomas Huth offsetof(CPUTriCoreState, PSW), "PSW");
8490ad75a51eSRichard Henderson cpu_PC = tcg_global_mem_new(tcg_env,
8491fcf5ef2aSThomas Huth offsetof(CPUTriCoreState, PC), "PC");
8492ad75a51eSRichard Henderson cpu_ICR = tcg_global_mem_new(tcg_env,
8493fcf5ef2aSThomas Huth offsetof(CPUTriCoreState, ICR), "ICR");
8494fcf5ef2aSThomas Huth }
8495fcf5ef2aSThomas Huth
tricore_tcg_init(void)8496fcf5ef2aSThomas Huth void tricore_tcg_init(void)
8497fcf5ef2aSThomas Huth {
8498fcf5ef2aSThomas Huth int i;
849955c3ceefSRichard Henderson
8500fcf5ef2aSThomas Huth /* reg init */
8501fcf5ef2aSThomas Huth for (i = 0 ; i < 16 ; i++) {
8502ad75a51eSRichard Henderson cpu_gpr_a[i] = tcg_global_mem_new(tcg_env,
8503fcf5ef2aSThomas Huth offsetof(CPUTriCoreState, gpr_a[i]),
8504fcf5ef2aSThomas Huth regnames_a[i]);
8505fcf5ef2aSThomas Huth }
8506fcf5ef2aSThomas Huth for (i = 0 ; i < 16 ; i++) {
8507ad75a51eSRichard Henderson cpu_gpr_d[i] = tcg_global_mem_new(tcg_env,
8508fcf5ef2aSThomas Huth offsetof(CPUTriCoreState, gpr_d[i]),
8509fcf5ef2aSThomas Huth regnames_d[i]);
8510fcf5ef2aSThomas Huth }
8511fcf5ef2aSThomas Huth tricore_tcg_init_csfr();
8512fcf5ef2aSThomas Huth /* init PSW flag cache */
8513ad75a51eSRichard Henderson cpu_PSW_C = tcg_global_mem_new(tcg_env,
8514fcf5ef2aSThomas Huth offsetof(CPUTriCoreState, PSW_USB_C),
8515fcf5ef2aSThomas Huth "PSW_C");
8516ad75a51eSRichard Henderson cpu_PSW_V = tcg_global_mem_new(tcg_env,
8517fcf5ef2aSThomas Huth offsetof(CPUTriCoreState, PSW_USB_V),
8518fcf5ef2aSThomas Huth "PSW_V");
8519ad75a51eSRichard Henderson cpu_PSW_SV = tcg_global_mem_new(tcg_env,
8520fcf5ef2aSThomas Huth offsetof(CPUTriCoreState, PSW_USB_SV),
8521fcf5ef2aSThomas Huth "PSW_SV");
8522ad75a51eSRichard Henderson cpu_PSW_AV = tcg_global_mem_new(tcg_env,
8523fcf5ef2aSThomas Huth offsetof(CPUTriCoreState, PSW_USB_AV),
8524fcf5ef2aSThomas Huth "PSW_AV");
8525ad75a51eSRichard Henderson cpu_PSW_SAV = tcg_global_mem_new(tcg_env,
8526fcf5ef2aSThomas Huth offsetof(CPUTriCoreState, PSW_USB_SAV),
8527fcf5ef2aSThomas Huth "PSW_SAV");
8528fcf5ef2aSThomas Huth }
8529