BLTUC rs, rt branches if unsigned(rs) < unsigned(rt) (MD01247 p.55).
With rs == $zero it is taken when rt != 0, but the decoder treated
it as a NOP. Only skip the branch when rs == rt (never taken).
Reaching the generic path exposes the R6 BGTZALC/BLTZALC-like special
cases in gen_compute_compact_branch_nm(), which set $ra and compare as
signed; nanoMIPS has neither. Drop them from the unsigned branches
(they were unreachable for BGEUC, which the decoder maps to BC/BEQZC).
Fixes: 11d0fc10b7ef ("target/mips: Add emulation of nanoMIPS 32-bit branch")
Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
---
target/mips/tcg/nanomips_translate.c.inc | 34 +++---------------------
1 file changed, 3 insertions(+), 31 deletions(-)
diff --git a/target/mips/tcg/nanomips_translate.c.inc
b/target/mips/tcg/nanomips_translate.c.inc
index 25d57e75a0b0..524972b24a98 100644
--- a/target/mips/tcg/nanomips_translate.c.inc
+++ b/target/mips/tcg/nanomips_translate.c.inc
@@ -2419,18 +2419,8 @@ static void gen_compute_compact_branch_nm(DisasContext
*ctx, uint32_t opc,
/* compact branch */
case OPC_BGEC:
case OPC_BLTC:
- gen_load_gpr(t0, rs);
- gen_load_gpr(t1, rt);
- bcond_compute = 1;
- ctx->btarget = addr_add(ctx, ctx->base.pc_next + 4, offset);
- break;
case OPC_BGEUC:
case OPC_BLTUC:
- if (rs == 0 || rs == rt) {
- /* OPC_BLEZALC, OPC_BGEZALC */
- /* OPC_BGTZALC, OPC_BLTZALC */
- tcg_gen_movi_tl(cpu_gpr[31], ctx->base.pc_next + 4);
- }
gen_load_gpr(t0, rs);
gen_load_gpr(t1, rt);
bcond_compute = 1;
@@ -2476,28 +2466,10 @@ static void gen_compute_compact_branch_nm(DisasContext
*ctx, uint32_t opc,
switch (opc) {
case OPC_BGEUC:
- if (rs == 0 && rt != 0) {
- /* OPC_BLEZALC */
- tcg_gen_brcondi_tl(tcg_invert_cond(TCG_COND_LE), t1, 0, fs);
- } else if (rs != 0 && rt != 0 && rs == rt) {
- /* OPC_BGEZALC */
- tcg_gen_brcondi_tl(tcg_invert_cond(TCG_COND_GE), t1, 0, fs);
- } else {
- /* OPC_BGEUC */
- tcg_gen_brcond_tl(tcg_invert_cond(TCG_COND_GEU), t0, t1, fs);
- }
+ tcg_gen_brcond_tl(tcg_invert_cond(TCG_COND_GEU), t0, t1, fs);
break;
case OPC_BLTUC:
- if (rs == 0 && rt != 0) {
- /* OPC_BGTZALC */
- tcg_gen_brcondi_tl(tcg_invert_cond(TCG_COND_GT), t1, 0, fs);
- } else if (rs != 0 && rt != 0 && rs == rt) {
- /* OPC_BLTZALC */
- tcg_gen_brcondi_tl(tcg_invert_cond(TCG_COND_LT), t1, 0, fs);
- } else {
- /* OPC_BLTUC */
- tcg_gen_brcond_tl(tcg_invert_cond(TCG_COND_LTU), t0, t1, fs);
- }
+ tcg_gen_brcond_tl(tcg_invert_cond(TCG_COND_LTU), t0, t1, fs);
break;
case OPC_BGEC:
if (rs == 0 && rt != 0) {
@@ -4414,7 +4386,7 @@ static int decode_nanomips_32_48_opc(CPUMIPSState *env,
DisasContext *ctx)
}
break;
case NM_BLTUC:
- if (rs == 0 || rs == rt) {
+ if (rs == rt) {
/* NOP */
ctx->hflags |= MIPS_HFLAG_FBNSLOT;
} else {
--
2.55.0