Skip to contentSkip to conversation

TCG: Fix tcg_gen_extr_i64_tl for 32bit

PATCH Applied Alexander Graf 2 participants 6 messages Jun 4, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 TCG: Fix tcg_gen_extr_i64_tl for 32bit

We expose a generic helper "tcg_gen_extr_i64_tl" for 64bit targets, but the same function for 32bit targets is a misnomer and refers to an invalid function name.

Fix up the definition to point to the correct internal helper names instead.

---
 tcg/tcg-op.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tcg/tcg-op.h +1 -1
index 719533a..019dd9b 100644
@@ -2718,7 +2718,7 @@ static inline void tcg_gen_qemu_st64(TCGv_i64 arg, TCGv addr, int mem_index)
 #define tcg_gen_bswap16_tl tcg_gen_bswap16_i32
 #define tcg_gen_bswap32_tl tcg_gen_bswap32_i32
 #define tcg_gen_concat_tl_i64 tcg_gen_concat_i32_i64
-#define tcg_gen_extr_tl_i64 tcg_gen_extr_i32_i64
+#define tcg_gen_extr_i64_tl tcg_gen_extr_i64_i32
 #define tcg_gen_andc_tl tcg_gen_andc_i32
 #define tcg_gen_eqv_tl tcg_gen_eqv_i32
 #define tcg_gen_nand_tl tcg_gen_nand_i32
Signature · 1 line
1.8.1.4
#1 lore raw

PATCH 2/2 PPC: e500: Merge 32 and 64 bit SPE emulation

Today we have a lot of conditional code in the SPE emulation depending on whether we have 64bit GPRs or not.

Unfortunately the assumption that we can just recycle the 64bit GPR implementation is wrong. Normal SPE implementations maintain the upper 32 bits on all non-SPE instructions which then only modify the low 32 bits. However all instructions we model that adhere to the normal SF based switching don't care whether they operate on 32 or 64 bit registers and just always use the full 64 bits.

So let's remove that dubious SPE optimization and revert everything to the same code path the 32bit target code was taking. That way we get rid of differences between the two implementations, but will get a slight performance hit when emulating SPE instructions.

This fixes SPE emulation with qemu-system-ppc64 for me.

---
 target-ppc/cpu.h       |   4 -
 target-ppc/translate.c | 711 +++++++++----------------------------------------
 2 files changed, 132 insertions(+), 583 deletions(-)
target-ppc/cpu.h +0 -4
index 406a406..82503a4 100644
@@ -908,10 +908,8 @@ struct CPUPPCState {
      */
     /* general purpose registers */
     target_ulong gpr[32];
-#if !defined(TARGET_PPC64)
     /* Storage for GPR MSB, used by the SPE extension */
     target_ulong gprh[32];
-#endif
     /* LR */
     target_ulong lr;
     /* CTR */
@@ -1164,7 +1162,6 @@ static inline uint64_t ppc_dump_gpr(CPUPPCState *env, int gprn)
     uint64_t gprv;
 
     gprv = env->gpr[gprn];
-#if !defined(TARGET_PPC64)
     if (env->flags & POWERPC_FLAG_SPE) {
         /* If the CPU implements the SPE extension, we have to get the
          * high bits of the GPR from the gprh storage area
@@ -1172,7 +1169,6 @@ static inline uint64_t ppc_dump_gpr(CPUPPCState *env, int gprn)
         gprv &= 0xFFFFFFFFULL;
         gprv |= (uint64_t)env->gprh[gprn] << 32;
     }
-#endif
 
     return gprv;
 }
target-ppc/translate.c +132 -579

1,159 lines not on this page · raw message

Signature · 1 line
1.8.1.4
#2 lore raw

Re: [Qemu-devel] [PATCH 2/2] PPC: e500: Merge 32 and 64 bit SPE emulation

target-ppc/translate.c static inline void gen_evmwumi(DisasContext *ctx) · line 8824

Quoted 10 lines · Alexander Graf
target-ppc/translate.c +1 -4
@@ -9030,13 +8820,10 @@ static inline void gen_evmwumi(DisasContext *ctx)
     t1 = tcg_temp_new_i64();
 
     /* t0 := rA; t1 := rB */
-#if defined(TARGET_PPC64)
-    tcg_gen_ext32u_tl(t0, cpu_gpr[rA(ctx->opcode)]);
-    tcg_gen_ext32u_tl(t1, cpu_gpr[rB(ctx->opcode)]);
-#else
     tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
+    tcg_gen_ext32u_i64(t0, t0);

Better in one step:

tcg_gen_ext32u_i64(t0, cpu_gpr[rA(ctx->opcode)]);

target-ppc/translate.c static inline void gen_evmwsmi(DisasContext *ctx) · line 8905

Quoted 8 lines
target-ppc/translate.c +4 -0
@@ -9112,13 +8899,10 @@ static inline void gen_evmwsmi(DisasContext *ctx)
     t1 = tcg_temp_new_i64();
 
     /* t0 := rA; t1 := rB */
+    tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
+    tcg_gen_ext32s_i64(t0, t0);
+    tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
+    tcg_gen_ext32s_i64(t1, t1);

Similarly.

Although I do wonder about using the actual 32-bit widening multiply
primitives: tcg_gen_mulu2_i32 / tcg_gen_muls2_i32.

I suspect the optimizer would clean up the unsigned version, but it hasn't got a chance with the signed version.

Otherwise, it looks ok.

r~

#3 lore raw

Re: [Qemu-devel] [PATCH 2/2] PPC: e500: Merge 32 and 64 bit SPE emulation

Quoted 13 lines · Richard Henderson

target-ppc/translate.c static inline void gen_evmwumi(DisasContext *ctx) · line 8824

Quoted 10 lines · Alexander Graf
target-ppc/translate.c +1 -4
@@ -9030,13 +8820,10 @@ static inline void gen_evmwumi(DisasContext *ctx)
      t1 = tcg_temp_new_i64();
 
      /* t0 := rA; t1 := rB */
-#if defined(TARGET_PPC64)
-    tcg_gen_ext32u_tl(t0, cpu_gpr[rA(ctx->opcode)]);
-    tcg_gen_ext32u_tl(t1, cpu_gpr[rB(ctx->opcode)]);
-#else
      tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
+    tcg_gen_ext32u_i64(t0, t0);

Better in one step:

Quoted 1 line
  tcg_gen_ext32u_i64(t0, cpu_gpr[rA(ctx->opcode)]);

But cpu_gpr can be i32 for qemu-system-ppc, no?

Quoted 11 lines

target-ppc/translate.c static inline void gen_evmwsmi(DisasContext *ctx) · line 8905

Quoted 9 lines
target-ppc/translate.c +4 -0
@@ -9112,13 +8899,10 @@ static inline void gen_evmwsmi(DisasContext *ctx)
      t1 = tcg_temp_new_i64();
 
      /* t0 := rA; t1 := rB */
+    tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
+    tcg_gen_ext32s_i64(t0, t0);
+    tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
+    tcg_gen_ext32s_i64(t1, t1);

Similarly.

Quoted 5 lines

Although I do wonder about using the actual 32-bit widening multiply
primitives: tcg_gen_mulu2_i32 / tcg_gen_muls2_i32.

I suspect the optimizer would clean up the unsigned version, but it hasn't got a chance with the signed version.

I personally don't really care too much about SPE performance - anything that doesn't fail works for me ;).

Quoted 1 line

Otherwise, it looks ok.

Thanks a lot for looking through it!

Alex

#4 lore raw

Re: [Qemu-devel] [PATCH 2/2] PPC: e500: Merge 32 and 64 bit SPE emulation

Quoted 14 lines · Alexander Graf
Quoted 12 lines · Richard Henderson

target-ppc/translate.c static inline void gen_evmwumi(DisasContext *ctx) · line 8823

Quoted 9 lines · Alexander Graf
target-ppc/translate.c +1 -4
@@ -9030,13 +8820,10 @@ static inline void gen_evmwumi(DisasContext *ctx)
      t1 = tcg_temp_new_i64();
        /* t0 := rA; t1 := rB */
-#if defined(TARGET_PPC64)
-    tcg_gen_ext32u_tl(t0, cpu_gpr[rA(ctx->opcode)]);
-    tcg_gen_ext32u_tl(t1, cpu_gpr[rB(ctx->opcode)]);
-#else
      tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
+    tcg_gen_ext32u_i64(t0, t0);

Better in one step:

Quoted 3 lines
Quoted 1 line
  tcg_gen_ext32u_i64(t0, cpu_gpr[rA(ctx->opcode)]);

But cpu_gpr can be i32 for qemu-system-ppc, no?

Err.. right. We don't have an extend define for this mix.

r~

#5 lore raw
In reply to Alexander Graf
Quoted 7 lines · Alexander Graf

We expose a generic helper "tcg_gen_extr_i64_tl" for 64bit targets, but the same function for 32bit targets is a misnomer and refers to an invalid function name.

Fix up the definition to point to the correct internal helper names instead.

Applied to tcg-next, thanks.

r~