[30/52] target-m68k: add scc/dbcc
diff mbox

Message ID 1462392752-17703-31-git-send-email-laurent@vivier.eu
State New
Headers show

Commit Message

Laurent Vivier May 4, 2016, 8:12 p.m. UTC
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 target-m68k/translate.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

Comments

Richard Henderson May 6, 2016, 5:18 p.m. UTC | #1
On 05/04/2016 10:12 AM, Laurent Vivier wrote:
> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
> ---
>  target-m68k/translate.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 46 insertions(+)
>
> diff --git a/target-m68k/translate.c b/target-m68k/translate.c
> index 5914185..cd656fe 100644
> --- a/target-m68k/translate.c
> +++ b/target-m68k/translate.c
> @@ -1096,6 +1096,49 @@ static void gen_jmp_tb(DisasContext *s, int n, uint32_t dest)
>      s->is_jmp = DISAS_TB_JUMP;
>  }
>
> +DISAS_INSN(scc_mem)
> +{
> +    TCGLabel *l1;
> +    int cond;
> +    TCGv dest;
> +
> +    l1 = gen_new_label();
> +    cond = (insn >> 8) & 0xf;
> +    dest = tcg_temp_local_new();
> +    tcg_gen_movi_i32(dest, 0);
> +    gen_jmpcc(s, cond ^ 1, l1);
> +    tcg_gen_movi_i32(dest, 0xff);
> +    gen_set_label(l1);

Use setcond + neg to avoid the jump.  Since you are storing a single byte, it 
doesn't matter that the neg produces -1 instead of 0xff.

> +    DEST_EA(env, insn, OS_BYTE, dest, NULL);
> +    tcg_temp_free(dest);
> +}
> +
> +DISAS_INSN(dbcc)
> +{
> +    TCGLabel *l1;
> +    TCGv reg;
> +    TCGv tmp;
> +    int16_t offset;
> +    uint32_t base;
> +
> +    reg = DREG(insn, 0);
> +    base = s->pc;
> +    offset = (int16_t)read_im16(env, s);
> +    l1 = gen_new_label();
> +    gen_jmpcc(s, (insn >> 8) & 0xf, l1);
> +
> +    tmp = tcg_temp_new();
> +    tcg_gen_ext16s_i32(tmp, reg);
> +    tcg_gen_addi_i32(tmp, tmp, -1);
> +    gen_partset_reg(OS_WORD, reg, tmp);
> +    tcg_gen_brcondi_i32(TCG_COND_EQ, tmp, -1, l1);
> +    update_cc_op(s);
> +    gen_jmp_tb(s, 1, base + offset);
> +    gen_set_label(l1);
> +    update_cc_op(s);
> +    gen_jmp_tb(s, 0, s->pc);

Pull the update_cc_op up to the top, so as to only generate one copy.


r~
Andreas Schwab May 6, 2016, 5:44 p.m. UTC | #2
Richard Henderson <rth@twiddle.net> writes:

> On 05/04/2016 10:12 AM, Laurent Vivier wrote:
>> +    DEST_EA(env, insn, OS_BYTE, dest, NULL);
>> +    tcg_temp_free(dest);
>> +}
>> +
>> +DISAS_INSN(dbcc)
>> +{
>> +    TCGLabel *l1;
>> +    TCGv reg;
>> +    TCGv tmp;
>> +    int16_t offset;
>> +    uint32_t base;
>> +
>> +    reg = DREG(insn, 0);
>> +    base = s->pc;
>> +    offset = (int16_t)read_im16(env, s);
>> +    l1 = gen_new_label();
>> +    gen_jmpcc(s, (insn >> 8) & 0xf, l1);
>> +
>> +    tmp = tcg_temp_new();
>> +    tcg_gen_ext16s_i32(tmp, reg);
>> +    tcg_gen_addi_i32(tmp, tmp, -1);
>> +    gen_partset_reg(OS_WORD, reg, tmp);
>> +    tcg_gen_brcondi_i32(TCG_COND_EQ, tmp, -1, l1);
>> +    update_cc_op(s);
>> +    gen_jmp_tb(s, 1, base + offset);
>> +    gen_set_label(l1);
>> +    update_cc_op(s);
>> +    gen_jmp_tb(s, 0, s->pc);
>
> Pull the update_cc_op up to the top, so as to only generate one copy.

This misses a followup patch which moves it into gen_jmpcc.  In the
current form this would result in a mistranslation.

Andreas.

Patch
diff mbox

diff --git a/target-m68k/translate.c b/target-m68k/translate.c
index 5914185..cd656fe 100644
--- a/target-m68k/translate.c
+++ b/target-m68k/translate.c
@@ -1096,6 +1096,49 @@  static void gen_jmp_tb(DisasContext *s, int n, uint32_t dest)
     s->is_jmp = DISAS_TB_JUMP;
 }
 
+DISAS_INSN(scc_mem)
+{
+    TCGLabel *l1;
+    int cond;
+    TCGv dest;
+
+    l1 = gen_new_label();
+    cond = (insn >> 8) & 0xf;
+    dest = tcg_temp_local_new();
+    tcg_gen_movi_i32(dest, 0);
+    gen_jmpcc(s, cond ^ 1, l1);
+    tcg_gen_movi_i32(dest, 0xff);
+    gen_set_label(l1);
+    DEST_EA(env, insn, OS_BYTE, dest, NULL);
+    tcg_temp_free(dest);
+}
+
+DISAS_INSN(dbcc)
+{
+    TCGLabel *l1;
+    TCGv reg;
+    TCGv tmp;
+    int16_t offset;
+    uint32_t base;
+
+    reg = DREG(insn, 0);
+    base = s->pc;
+    offset = (int16_t)read_im16(env, s);
+    l1 = gen_new_label();
+    gen_jmpcc(s, (insn >> 8) & 0xf, l1);
+
+    tmp = tcg_temp_new();
+    tcg_gen_ext16s_i32(tmp, reg);
+    tcg_gen_addi_i32(tmp, tmp, -1);
+    gen_partset_reg(OS_WORD, reg, tmp);
+    tcg_gen_brcondi_i32(TCG_COND_EQ, tmp, -1, l1);
+    update_cc_op(s);
+    gen_jmp_tb(s, 1, base + offset);
+    gen_set_label(l1);
+    update_cc_op(s);
+    gen_jmp_tb(s, 0, s->pc);
+}
+
 DISAS_INSN(undef_mac)
 {
     gen_exception(s, s->pc - 2, EXCP_LINEA);
@@ -3292,6 +3335,9 @@  void register_m68k_insns (CPUM68KState *env)
     INSN(addsubq,   5000, f080, M68000);
     INSN(addsubq,   5080, f0c0, M68000);
     INSN(scc,       50c0, f0f8, CF_ISA_A);
+    INSN(scc_mem,   50c0, f0c0, M68000);
+    INSN(scc,       50c0, f0f8, M68000);
+    INSN(dbcc,      50c8, f0f8, M68000);
     INSN(addsubq,   5080, f1c0, CF_ISA_A);
     INSN(tpf,       51f8, fff8, CF_ISA_A);