Commit a46256129e80d993d23ed9d95566c79bcfa65e2d

Authored by aurel32
1 parent 3a8a44c4

SH4: convert simple compare instructions to TCG

(Shin-ichiro KAWASAKI)

git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5108 c046a42c-6fe2-441c-8c8c-71466251a162
target-sh4/op.c
@@ -37,12 +37,6 @@ static inline void cond_t(int cond) @@ -37,12 +37,6 @@ static inline void cond_t(int cond)
37 clr_t(); 37 clr_t();
38 } 38 }
39 39
40 -void OPPROTO op_cmp_eq_imm_T0(void)  
41 -{  
42 - cond_t((int32_t) T0 == (int32_t) PARAM1);  
43 - RETURN();  
44 -}  
45 -  
46 void OPPROTO op_bf_s(void) 40 void OPPROTO op_bf_s(void)
47 { 41 {
48 env->delayed_pc = PARAM1; 42 env->delayed_pc = PARAM1;
@@ -144,36 +138,6 @@ void OPPROTO op_addv_T0_T1(void) @@ -144,36 +138,6 @@ void OPPROTO op_addv_T0_T1(void)
144 RETURN(); 138 RETURN();
145 } 139 }
146 140
147 -void OPPROTO op_cmp_eq_T0_T1(void)  
148 -{  
149 - cond_t(T1 == T0);  
150 - RETURN();  
151 -}  
152 -  
153 -void OPPROTO op_cmp_ge_T0_T1(void)  
154 -{  
155 - cond_t((int32_t) T1 >= (int32_t) T0);  
156 - RETURN();  
157 -}  
158 -  
159 -void OPPROTO op_cmp_gt_T0_T1(void)  
160 -{  
161 - cond_t((int32_t) T1 > (int32_t) T0);  
162 - RETURN();  
163 -}  
164 -  
165 -void OPPROTO op_cmp_hi_T0_T1(void)  
166 -{  
167 - cond_t((uint32_t) T1 > (uint32_t) T0);  
168 - RETURN();  
169 -}  
170 -  
171 -void OPPROTO op_cmp_hs_T0_T1(void)  
172 -{  
173 - cond_t((uint32_t) T1 >= (uint32_t) T0);  
174 - RETURN();  
175 -}  
176 -  
177 void OPPROTO op_cmp_str_T0_T1(void) 141 void OPPROTO op_cmp_str_T0_T1(void)
178 { 142 {
179 cond_t((T0 & 0x000000ff) == (T1 & 0x000000ff) || 143 cond_t((T0 & 0x000000ff) == (T1 & 0x000000ff) ||
@@ -183,12 +147,6 @@ void OPPROTO op_cmp_str_T0_T1(void) @@ -183,12 +147,6 @@ void OPPROTO op_cmp_str_T0_T1(void)
183 RETURN(); 147 RETURN();
184 } 148 }
185 149
186 -void OPPROTO op_tst_T0_T1(void)  
187 -{  
188 - cond_t((T1 & T0) == 0);  
189 - RETURN();  
190 -}  
191 -  
192 void OPPROTO op_div0s_T0_T1(void) 150 void OPPROTO op_div0s_T0_T1(void)
193 { 151 {
194 if (T1 & 0x80000000) 152 if (T1 & 0x80000000)
@@ -299,18 +257,6 @@ void OPPROTO op_trapa(void) @@ -299,18 +257,6 @@ void OPPROTO op_trapa(void)
299 RETURN(); 257 RETURN();
300 } 258 }
301 259
302 -void OPPROTO op_cmp_pl_T0(void)  
303 -{  
304 - cond_t((int32_t) T0 > 0);  
305 - RETURN();  
306 -}  
307 -  
308 -void OPPROTO op_cmp_pz_T0(void)  
309 -{  
310 - cond_t((int32_t) T0 >= 0);  
311 - RETURN();  
312 -}  
313 -  
314 void OPPROTO op_jmp_T0(void) 260 void OPPROTO op_jmp_T0(void)
315 { 261 {
316 env->delayed_pc = T0; 262 env->delayed_pc = T0;
@@ -610,18 +556,6 @@ void OPPROTO op_fmov_T0_frN(void) @@ -610,18 +556,6 @@ void OPPROTO op_fmov_T0_frN(void)
610 RETURN(); 556 RETURN();
611 } 557 }
612 558
613 -void OPPROTO op_dt_rN(void)  
614 -{  
615 - cond_t((--env->gregs[PARAM1]) == 0);  
616 - RETURN();  
617 -}  
618 -  
619 -void OPPROTO op_tst_imm_rN(void)  
620 -{  
621 - cond_t((env->gregs[PARAM2] & PARAM1) == 0);  
622 - RETURN();  
623 -}  
624 -  
625 void OPPROTO op_movl_fpul_FT0(void) 559 void OPPROTO op_movl_fpul_FT0(void)
626 { 560 {
627 FT0 = *(float32 *)&env->fpul; 561 FT0 = *(float32 *)&env->fpul;
@@ -656,12 +590,6 @@ void OPPROTO op_movl_delayed_pc_PC(void) @@ -656,12 +590,6 @@ void OPPROTO op_movl_delayed_pc_PC(void)
656 RETURN(); 590 RETURN();
657 } 591 }
658 592
659 -void OPPROTO op_tst_imm_T0(void)  
660 -{  
661 - cond_t((T0 & PARAM1) == 0);  
662 - RETURN();  
663 -}  
664 -  
665 void OPPROTO op_raise_illegal_instruction(void) 593 void OPPROTO op_raise_illegal_instruction(void)
666 { 594 {
667 env->exception_index = 0x180; 595 env->exception_index = 0x180;
target-sh4/translate.c
@@ -283,6 +283,40 @@ static void gen_delayed_conditional_jump(DisasContext * ctx) @@ -283,6 +283,40 @@ static void gen_delayed_conditional_jump(DisasContext * ctx)
283 gen_jump(ctx); 283 gen_jump(ctx);
284 } 284 }
285 285
  286 +static inline void gen_set_t(void)
  287 +{
  288 + tcg_gen_ori_i32(cpu_sr, cpu_sr, SR_T);
  289 +}
  290 +
  291 +static inline void gen_clr_t(void)
  292 +{
  293 + tcg_gen_andi_i32(cpu_sr, cpu_sr, ~SR_T);
  294 +}
  295 +
  296 +static inline void gen_cmp(int cond, TCGv t0, TCGv t1)
  297 +{
  298 + int label1 = gen_new_label();
  299 + int label2 = gen_new_label();
  300 + tcg_gen_brcond_i32(cond, t1, t0, label1);
  301 + gen_clr_t();
  302 + tcg_gen_br(label2);
  303 + gen_set_label(label1);
  304 + gen_set_t();
  305 + gen_set_label(label2);
  306 +}
  307 +
  308 +static inline void gen_cmp_imm(int cond, TCGv t0, int32_t imm)
  309 +{
  310 + int label1 = gen_new_label();
  311 + int label2 = gen_new_label();
  312 + tcg_gen_brcondi_i32(cond, t0, imm, label1);
  313 + gen_clr_t();
  314 + tcg_gen_br(label2);
  315 + gen_set_label(label1);
  316 + gen_set_t();
  317 + gen_set_label(label2);
  318 +}
  319 +
286 #define B3_0 (ctx->opcode & 0xf) 320 #define B3_0 (ctx->opcode & 0xf)
287 #define B6_4 ((ctx->opcode >> 4) & 0x7) 321 #define B6_4 ((ctx->opcode >> 4) & 0x7)
288 #define B7_4 ((ctx->opcode >> 4) & 0xf) 322 #define B7_4 ((ctx->opcode >> 4) & 0xf)
@@ -331,7 +365,7 @@ void _decode_opc(DisasContext * ctx) @@ -331,7 +365,7 @@ void _decode_opc(DisasContext * ctx)
331 tcg_gen_andi_i32(cpu_sr, cpu_sr, ~SR_S); 365 tcg_gen_andi_i32(cpu_sr, cpu_sr, ~SR_S);
332 return; 366 return;
333 case 0x0008: /* clrt */ 367 case 0x0008: /* clrt */
334 - tcg_gen_andi_i32(cpu_sr, cpu_sr, ~SR_T); 368 + gen_clr_t();
335 return; 369 return;
336 case 0x0038: /* ldtlb */ 370 case 0x0038: /* ldtlb */
337 #if defined(CONFIG_USER_ONLY) 371 #if defined(CONFIG_USER_ONLY)
@@ -349,7 +383,7 @@ void _decode_opc(DisasContext * ctx) @@ -349,7 +383,7 @@ void _decode_opc(DisasContext * ctx)
349 tcg_gen_ori_i32(cpu_sr, cpu_sr, SR_S); 383 tcg_gen_ori_i32(cpu_sr, cpu_sr, SR_S);
350 return; 384 return;
351 case 0x0018: /* sett */ 385 case 0x0018: /* sett */
352 - tcg_gen_ori_i32(cpu_sr, cpu_sr, SR_T); 386 + gen_set_t();
353 return; 387 return;
354 case 0xfbfd: /* frchg */ 388 case 0xfbfd: /* frchg */
355 gen_op_frchg(); 389 gen_op_frchg();
@@ -582,27 +616,27 @@ void _decode_opc(DisasContext * ctx) @@ -582,27 +616,27 @@ void _decode_opc(DisasContext * ctx)
582 case 0x3000: /* cmp/eq Rm,Rn */ 616 case 0x3000: /* cmp/eq Rm,Rn */
583 tcg_gen_mov_i32(cpu_T[0], cpu_gregs[REG(B7_4)]); 617 tcg_gen_mov_i32(cpu_T[0], cpu_gregs[REG(B7_4)]);
584 tcg_gen_mov_i32(cpu_T[1], cpu_gregs[REG(B11_8)]); 618 tcg_gen_mov_i32(cpu_T[1], cpu_gregs[REG(B11_8)]);
585 - gen_op_cmp_eq_T0_T1(); 619 + gen_cmp(TCG_COND_EQ, cpu_T[0], cpu_T[1]);
586 return; 620 return;
587 case 0x3003: /* cmp/ge Rm,Rn */ 621 case 0x3003: /* cmp/ge Rm,Rn */
588 tcg_gen_mov_i32(cpu_T[0], cpu_gregs[REG(B7_4)]); 622 tcg_gen_mov_i32(cpu_T[0], cpu_gregs[REG(B7_4)]);
589 tcg_gen_mov_i32(cpu_T[1], cpu_gregs[REG(B11_8)]); 623 tcg_gen_mov_i32(cpu_T[1], cpu_gregs[REG(B11_8)]);
590 - gen_op_cmp_ge_T0_T1(); 624 + gen_cmp(TCG_COND_GE, cpu_T[0], cpu_T[1]);
591 return; 625 return;
592 case 0x3007: /* cmp/gt Rm,Rn */ 626 case 0x3007: /* cmp/gt Rm,Rn */
593 tcg_gen_mov_i32(cpu_T[0], cpu_gregs[REG(B7_4)]); 627 tcg_gen_mov_i32(cpu_T[0], cpu_gregs[REG(B7_4)]);
594 tcg_gen_mov_i32(cpu_T[1], cpu_gregs[REG(B11_8)]); 628 tcg_gen_mov_i32(cpu_T[1], cpu_gregs[REG(B11_8)]);
595 - gen_op_cmp_gt_T0_T1(); 629 + gen_cmp(TCG_COND_GT, cpu_T[0], cpu_T[1]);
596 return; 630 return;
597 case 0x3006: /* cmp/hi Rm,Rn */ 631 case 0x3006: /* cmp/hi Rm,Rn */
598 tcg_gen_mov_i32(cpu_T[0], cpu_gregs[REG(B7_4)]); 632 tcg_gen_mov_i32(cpu_T[0], cpu_gregs[REG(B7_4)]);
599 tcg_gen_mov_i32(cpu_T[1], cpu_gregs[REG(B11_8)]); 633 tcg_gen_mov_i32(cpu_T[1], cpu_gregs[REG(B11_8)]);
600 - gen_op_cmp_hi_T0_T1(); 634 + gen_cmp(TCG_COND_GTU, cpu_T[0], cpu_T[1]);
601 return; 635 return;
602 case 0x3002: /* cmp/hs Rm,Rn */ 636 case 0x3002: /* cmp/hs Rm,Rn */
603 tcg_gen_mov_i32(cpu_T[0], cpu_gregs[REG(B7_4)]); 637 tcg_gen_mov_i32(cpu_T[0], cpu_gregs[REG(B7_4)]);
604 tcg_gen_mov_i32(cpu_T[1], cpu_gregs[REG(B11_8)]); 638 tcg_gen_mov_i32(cpu_T[1], cpu_gregs[REG(B11_8)]);
605 - gen_op_cmp_hs_T0_T1(); 639 + gen_cmp(TCG_COND_GEU, cpu_T[0], cpu_T[1]);
606 return; 640 return;
607 case 0x200c: /* cmp/str Rm,Rn */ 641 case 0x200c: /* cmp/str Rm,Rn */
608 tcg_gen_mov_i32(cpu_T[0], cpu_gregs[REG(B7_4)]); 642 tcg_gen_mov_i32(cpu_T[0], cpu_gregs[REG(B7_4)]);
@@ -737,7 +771,8 @@ void _decode_opc(DisasContext * ctx) @@ -737,7 +771,8 @@ void _decode_opc(DisasContext * ctx)
737 case 0x2008: /* tst Rm,Rn */ 771 case 0x2008: /* tst Rm,Rn */
738 tcg_gen_mov_i32(cpu_T[0], cpu_gregs[REG(B7_4)]); 772 tcg_gen_mov_i32(cpu_T[0], cpu_gregs[REG(B7_4)]);
739 tcg_gen_mov_i32(cpu_T[1], cpu_gregs[REG(B11_8)]); 773 tcg_gen_mov_i32(cpu_T[1], cpu_gregs[REG(B11_8)]);
740 - gen_op_tst_T0_T1(); 774 + tcg_gen_and_i32(cpu_T[0], cpu_T[0], cpu_T[1]);
  775 + gen_cmp_imm(TCG_COND_EQ, cpu_T[0], 0);
741 return; 776 return;
742 case 0x200a: /* xor Rm,Rn */ 777 case 0x200a: /* xor Rm,Rn */
743 tcg_gen_xor_i32(cpu_gregs[REG(B11_8)], cpu_gregs[REG(B11_8)], cpu_gregs[REG(B7_4)]); 778 tcg_gen_xor_i32(cpu_gregs[REG(B11_8)], cpu_gregs[REG(B11_8)], cpu_gregs[REG(B7_4)]);
@@ -911,7 +946,7 @@ void _decode_opc(DisasContext * ctx) @@ -911,7 +946,7 @@ void _decode_opc(DisasContext * ctx)
911 return; 946 return;
912 case 0x8800: /* cmp/eq #imm,R0 */ 947 case 0x8800: /* cmp/eq #imm,R0 */
913 tcg_gen_mov_i32(cpu_T[0], cpu_gregs[REG(0)]); 948 tcg_gen_mov_i32(cpu_T[0], cpu_gregs[REG(0)]);
914 - gen_op_cmp_eq_imm_T0(B7_0s); 949 + gen_cmp_imm(TCG_COND_EQ, cpu_T[0], B7_0s);
915 return; 950 return;
916 case 0xc400: /* mov.b @(disp,GBR),R0 */ 951 case 0xc400: /* mov.b @(disp,GBR),R0 */
917 gen_op_stc_gbr_T0(); 952 gen_op_stc_gbr_T0();
@@ -997,13 +1032,15 @@ void _decode_opc(DisasContext * ctx) @@ -997,13 +1032,15 @@ void _decode_opc(DisasContext * ctx)
997 ctx->bstate = BS_BRANCH; 1032 ctx->bstate = BS_BRANCH;
998 return; 1033 return;
999 case 0xc800: /* tst #imm,R0 */ 1034 case 0xc800: /* tst #imm,R0 */
1000 - gen_op_tst_imm_rN(B7_0, REG(0)); 1035 + tcg_gen_andi_i32(cpu_T[0], cpu_gregs[REG(0)], B7_0);
  1036 + gen_cmp_imm(TCG_COND_EQ, cpu_T[0], 0);
1001 return; 1037 return;
1002 case 0xcc00: /* tst.b #imm,@(R0,GBR) */ 1038 case 0xcc00: /* tst.b #imm,@(R0,GBR) */
1003 tcg_gen_mov_i32(cpu_T[0], cpu_gregs[REG(0)]); 1039 tcg_gen_mov_i32(cpu_T[0], cpu_gregs[REG(0)]);
1004 tcg_gen_add_i32(cpu_T[0], cpu_T[0], cpu_gbr); 1040 tcg_gen_add_i32(cpu_T[0], cpu_T[0], cpu_gbr);
1005 gen_op_ldub_T0_T0(ctx); 1041 gen_op_ldub_T0_T0(ctx);
1006 - gen_op_tst_imm_T0(B7_0); 1042 + tcg_gen_andi_i32(cpu_T[0], cpu_T[0], B7_0);
  1043 + gen_cmp_imm(TCG_COND_EQ, cpu_T[0], 0);
1007 return; 1044 return;
1008 case 0xca00: /* xor #imm,R0 */ 1045 case 0xca00: /* xor #imm,R0 */
1009 tcg_gen_xori_i32(cpu_gregs[REG(0)], cpu_gregs[REG(0)], B7_0); 1046 tcg_gen_xori_i32(cpu_gregs[REG(0)], cpu_gregs[REG(0)], B7_0);
@@ -1058,14 +1095,15 @@ void _decode_opc(DisasContext * ctx) @@ -1058,14 +1095,15 @@ void _decode_opc(DisasContext * ctx)
1058 return; 1095 return;
1059 case 0x4015: /* cmp/pl Rn */ 1096 case 0x4015: /* cmp/pl Rn */
1060 tcg_gen_mov_i32(cpu_T[0], cpu_gregs[REG(B11_8)]); 1097 tcg_gen_mov_i32(cpu_T[0], cpu_gregs[REG(B11_8)]);
1061 - gen_op_cmp_pl_T0(); 1098 + gen_cmp_imm(TCG_COND_GT, cpu_T[0], 0);
1062 return; 1099 return;
1063 case 0x4011: /* cmp/pz Rn */ 1100 case 0x4011: /* cmp/pz Rn */
1064 tcg_gen_mov_i32(cpu_T[0], cpu_gregs[REG(B11_8)]); 1101 tcg_gen_mov_i32(cpu_T[0], cpu_gregs[REG(B11_8)]);
1065 - gen_op_cmp_pz_T0(); 1102 + gen_cmp_imm(TCG_COND_GE, cpu_T[0], 0);
1066 return; 1103 return;
1067 case 0x4010: /* dt Rn */ 1104 case 0x4010: /* dt Rn */
1068 - gen_op_dt_rN(REG(B11_8)); 1105 + tcg_gen_subi_i32(cpu_gregs[REG(B11_8)], cpu_gregs[REG(B11_8)], 1);
  1106 + gen_cmp_imm(TCG_COND_EQ, cpu_gregs[REG(B11_8)], 0);
1069 return; 1107 return;
1070 case 0x402b: /* jmp @Rn */ 1108 case 0x402b: /* jmp @Rn */
1071 CHECK_NOT_DELAY_SLOT tcg_gen_mov_i32(cpu_T[0], cpu_gregs[REG(B11_8)]); 1109 CHECK_NOT_DELAY_SLOT tcg_gen_mov_i32(cpu_T[0], cpu_gregs[REG(B11_8)]);
@@ -1187,7 +1225,7 @@ void _decode_opc(DisasContext * ctx) @@ -1187,7 +1225,7 @@ void _decode_opc(DisasContext * ctx)
1187 tcg_gen_mov_i32(cpu_T[0], cpu_gregs[REG(B11_8)]); 1225 tcg_gen_mov_i32(cpu_T[0], cpu_gregs[REG(B11_8)]);
1188 tcg_gen_mov_i32(cpu_T[1], cpu_T[0]); 1226 tcg_gen_mov_i32(cpu_T[1], cpu_T[0]);
1189 gen_op_ldub_T0_T0(ctx); 1227 gen_op_ldub_T0_T0(ctx);
1190 - gen_op_cmp_eq_imm_T0(0); 1228 + gen_cmp_imm(TCG_COND_EQ, cpu_T[0], 0);
1191 tcg_gen_ori_i32(cpu_T[0], cpu_T[0], 0x80); 1229 tcg_gen_ori_i32(cpu_T[0], cpu_T[0], 0x80);
1192 gen_op_stb_T0_T1(ctx); 1230 gen_op_stb_T0_T1(ctx);
1193 return; 1231 return;