From 75a4c5793eac34019218a5d36fd8b5efc167ad41 Mon Sep 17 00:00:00 2001 From: fridtjof Date: Wed, 20 Aug 2025 01:28:49 +0200 Subject: [PATCH] wip! translate: implement BR{EQ,NE}0{B,W} --- target/cr16c/insn.decode | 2 ++ target/cr16c/translate.c | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/target/cr16c/insn.decode b/target/cr16c/insn.decode index 57bfa2fe54..d2681318b1 100644 --- a/target/cr16c/insn.decode +++ b/target/cr16c/insn.decode @@ -253,6 +253,8 @@ TBIT_mem_abs 0000 0000 0001 0001 1111 .... .... .... .... .... .... .... wid BRCOND 0001 .... cond:4 .... dest=%br_disp8 +BR0 0000 11 word:1 ne:1 dest:4 src:4 + JCOND 0000 1010 cond:4 ra:4 EXCP 0000 0000 1100 id:4 diff --git a/target/cr16c/translate.c b/target/cr16c/translate.c index b474c47df8..7b549cdf40 100644 --- a/target/cr16c/translate.c +++ b/target/cr16c/translate.c @@ -1328,6 +1328,30 @@ static bool trans_BRCOND(DisasContext* ctx, arg_BRCOND *a) { return true; } +static bool trans_BR0(DisasContext* ctx, arg_BR0* a) { + int disp5 = (a->dest + 1) * 2; // disp*2+ + + TCGv tmp = tcg_temp_new_i32(); + if (a->word == 1) { + tcg_gen_ext16u_i32(tmp, r[a->src]); + } else { + tcg_gen_ext8u_i32(tmp, r[a->src]); + } + + TCGLabel* l = gen_new_label(); + tcg_gen_brcondi_i32(a->ne == 1 ? TCG_COND_NE : TCG_COND_EQ, tmp, 0, l); + + gen_goto(&ctx->base, ctx->base.pc_next, 0); + + gen_set_label(l); + + vaddr pc_this = ctx->base.pc_next - 2; + gen_goto(&ctx->base, pc_this + disp5, 1); + + ctx->base.is_jmp = DISAS_NORETURN; + return true; +} + static bool trans_JCOND(DisasContext* ctx, arg_JCOND *a) { TCGLabel* l = gen_new_label();