Skip to contentSkip to conversation

target/mips: fix msa copy_[s|u]_df rd = 0 corner case

PATCH In review Miodrag Dinic 2 participants 2 messages Jun 15, 2017 – Jun 17, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/mips: fix msa copy_[s|u]_df rd = 0 corner case

From: Miodrag Dinic <[email protected]>

This patch fixes the msa copy_[s|u]_df instruction emulation when the destination register rd is zero. Without this patch the zero register would get clobbered, which should never happen because it is supposed to be hardwired to 0.

Fix this corner case by explicitly checking rd = 0 and effectively making these instructions emulation no-op in that case.

---
 target/mips/translate.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
target/mips/translate.c +6 -2
index 559f8fe..befb87f 100644
@@ -18712,10 +18712,14 @@ static void gen_msa_elm_df(CPUMIPSState *env, DisasContext *ctx, uint32_t df,
 #endif
         switch (MASK_MSA_ELM(ctx->opcode)) {
         case OPC_COPY_S_df:
-            gen_helper_msa_copy_s_df(cpu_env, tdf, twd, tws, tn);
+            if (likely(wd != 0)) {
+                gen_helper_msa_copy_s_df(cpu_env, tdf, twd, tws, tn);
+            }
             break;
         case OPC_COPY_U_df:
-            gen_helper_msa_copy_u_df(cpu_env, tdf, twd, tws, tn);
+            if (likely(wd != 0)) {
+                gen_helper_msa_copy_u_df(cpu_env, tdf, twd, tws, tn);
+            }
             break;
         case OPC_INSERT_df:
             gen_helper_msa_insert_df(cpu_env, tdf, twd, tws, tn);
Signature · 1 line
1.9.1
Reviewed-by Acked-by on v1 1/1
#1 lore raw
Quoted 7 lines · Miodrag Dinic

From: Miodrag Dinic <[email protected]>

This patch fixes the msa copy_[s|u]_df instruction emulation when the destination register rd is zero. Without this patch the zero register would get clobbered, which should never happen because it is supposed to be hardwired to 0.

Quoted 8 lines

Fix this corner case by explicitly checking rd = 0 and effectively making these instructions emulation no-op in that case.

---
 target/mips/translate.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
Signature · 2 lines
Aurelien Jarno                          GPG: 4096R/1DDD8C9B
[email protected]                 http://www.aurel32.net