Skip to contentSkip to conversation

target-mips: Sign-extend the result of LWR

PATCH New Richard Sandiford 1 participant 1 message Jan 20, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target-mips: Sign-extend the result of LWR

Sign-extend the result of LWR, as is already done for LWL. This is necessary in the case where LWR loads the full word (i.e. the address is actually aligned). In the other cases, it is implementation defined whether the upper 32 bits of the result are unchanged or a copy of bit 31. The latter seems easier to implement.

Previously the code used:

    (oldval & (0xfffffffe << (31 - bitshift))) | (newval >> bitshift)

which zeroed the upper bits of the register, losing any previous sign extension in the unaligned cases.

---
 target-mips/translate.c | 1 +
 1 file changed, 1 insertion(+)
target-mips/translate.c +1 -0
index 623edd0..08e28f3 100644
@@ -1735,6 +1735,7 @@ static void gen_ld (CPUMIPSState *env, DisasContext *ctx, uint32_t opc,
         tcg_temp_free(t2);
         tcg_gen_or_tl(t0, t0, t1);
         tcg_temp_free(t1);
+        tcg_gen_ext32s_tl(t0, t0);
         gen_store_gpr(t0, rt);
         opn = "lwr";
         break;
Signature · 1 line
1.7.11.7