Skip to contentSkip to conversation

PPC: Fix cmp on 32bit only targets v2

PATCH In review Alexander Graf 2 participants 5 messages May 8, 2013

lore
Share & tools
lore
#0 lore raw

cover PPC: Fix cmp on 32bit only targets v2

When running 32bit cmp instructions on a TARGET_PPC without 64bit support, we generate incorrect comparisons. This patch set fixes this issue.

v1 -> v2:

- treat L bit as reserved on 32bit targets

Alex

Alexander Graf (2):
PPC: Add 32bit instruction flag
PPC: Introduce 32bit only cmp ops

 target-ppc/cpu.h            |    5 ++-
 target-ppc/translate.c      |   20 ++++++----
 target-ppc/translate_init.c |   88 +++++++++++++++++++++---------------------
 3 files changed, 60 insertions(+), 53 deletions(-)
#1 lore raw

PATCH 1/2 PPC: Add 32bit instruction flag

Some instructions behave differently depending on whether the CPU is 64bit capable or not, regardless of the mode the CPU is in.

Add a new instruction flag that indicates that we're running on a CPU that can not execute 64bit code.

---
 target-ppc/cpu.h            |    5 ++-
 target-ppc/translate_init.c |   88 +++++++++++++++++++++---------------------
 2 files changed, 48 insertions(+), 45 deletions(-)
target-ppc/cpu.h +4 -1
index aa1d013..09a28e1 100644
@@ -1875,8 +1875,11 @@ enum {
     PPC2_DBRX          = 0x0000000000000010ULL,
     /* Book I 2.05 PowerPC specification                                     */
     PPC2_ISA205        = 0x0000000000000020ULL,
+    /* 32bit instructions (!PPC_64B && PPC_INTEGER)                          */
+    PPC2_32B           = 0x0000000000000040ULL,
 
-#define PPC_TCG_INSNS2 (PPC2_BOOKE206 | PPC2_PRCNTL | PPC2_DBRX | PPC2_ISA205)
+#define PPC_TCG_INSNS2 (PPC2_BOOKE206 | PPC2_PRCNTL | PPC2_DBRX | PPC2_ISA205 \
+                      | PPC2_32B)
 };
 
 /*****************************************************************************/
target-ppc/translate_init.c +44 -44

352 lines not on this page · raw message

Signature · 1 line
1.6.0.2
#3 lore raw

PATCH 2/2 PPC: Introduce 32bit only cmp ops

In reply to Alexander Graf

When running a 32bit target CPU with qemu-(system-)-ppc, NARROW_MODE is not set, so we never get to leverage the "32bit only" code path in the compare op handlers.

Introduce new handlers based on the 32bit only flag. That way we can have 2 separate functions for 32bit mode and 64bit mode, which can handle NARROW_MODE.

---

v1 -> v2:

- treat L bit as reserved for 32bit

---
 target-ppc/translate.c |   20 ++++++++++++--------
 1 files changed, 12 insertions(+), 8 deletions(-)
target-ppc/translate.c +12 -8
index a018616..feca162 100644
@@ -675,7 +675,7 @@ static inline void gen_set_Rc0(DisasContext *ctx, TCGv reg)
 /* cmp */
 static void gen_cmp(DisasContext *ctx)
 {
-    if (NARROW_MODE(ctx) || !(ctx->opcode & 0x00200000)) {
+    if (!(ctx->opcode & 0x00200000)) {
         gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
                      1, crfD(ctx->opcode));
     } else {
@@ -687,7 +687,7 @@ static void gen_cmp(DisasContext *ctx)
 /* cmpi */
 static void gen_cmpi(DisasContext *ctx)
 {
-    if (NARROW_MODE(ctx) || !(ctx->opcode & 0x00200000)) {
+    if (!(ctx->opcode & 0x00200000)) {
         gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], SIMM(ctx->opcode),
                       1, crfD(ctx->opcode));
     } else {
@@ -699,7 +699,7 @@ static void gen_cmpi(DisasContext *ctx)
 /* cmpl */
 static void gen_cmpl(DisasContext *ctx)
 {
-    if (NARROW_MODE(ctx) || !(ctx->opcode & 0x00200000)) {
+    if (!(ctx->opcode & 0x00200000)) {
         gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
                      0, crfD(ctx->opcode));
     } else {
@@ -711,7 +711,7 @@ static void gen_cmpl(DisasContext *ctx)
 /* cmpli */
 static void gen_cmpli(DisasContext *ctx)
 {
-    if (NARROW_MODE(ctx) || !(ctx->opcode & 0x00200000)) {
+    if (!(ctx->opcode & 0x00200000)) {
         gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], UIMM(ctx->opcode),
                       0, crfD(ctx->opcode));
     } else {
@@ -8638,10 +8638,14 @@ GEN_SPE(efdtsteq,  speundef,  0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE
 
 static opcode_t opcodes[] = {
 GEN_HANDLER(invalid, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE),
-GEN_HANDLER(cmp, 0x1F, 0x00, 0x00, 0x00400000, PPC_INTEGER),
-GEN_HANDLER(cmpi, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER),
-GEN_HANDLER(cmpl, 0x1F, 0x00, 0x01, 0x00400000, PPC_INTEGER),
-GEN_HANDLER(cmpli, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER),
+GEN_HANDLER(cmp, 0x1F, 0x00, 0x00, 0x00400000, PPC_64B),
+GEN_HANDLER_E(cmp, 0x1F, 0x00, 0x00, 0x00600000, PPC_NONE, PPC2_32B),
+GEN_HANDLER(cmpi, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_64B),
+GEN_HANDLER_E(cmpi, 0x0B, 0xFF, 0xFF, 0x00600000, PPC_NONE, PPC2_32B),
+GEN_HANDLER(cmpl, 0x1F, 0x00, 0x01, 0x00400000, PPC_64B),
+GEN_HANDLER_E(cmpl, 0x1F, 0x00, 0x01, 0x00600000, PPC_NONE, PPC2_32B),
+GEN_HANDLER(cmpli, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_64B),
+GEN_HANDLER_E(cmpli, 0x0A, 0xFF, 0xFF, 0x00600000, PPC_NONE, PPC2_32B),
 GEN_HANDLER_E(cmpb, 0x1F, 0x1C, 0x0F, 0x00000001, PPC_NONE, PPC2_ISA205),
 GEN_HANDLER(isel, 0x1F, 0x0F, 0xFF, 0x00000001, PPC_ISEL),
 GEN_HANDLER(addi, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
Signature · 1 line
1.6.0.2
Reviewed-by on v1 2/2
#4 lore raw

Re: [Qemu-devel] [PATCH 2/2] PPC: Introduce 32bit only cmp ops

Quoted 11 lines · Alexander Graf

When running a 32bit target CPU with qemu-(system-)-ppc, NARROW_MODE is not set, so we never get to leverage the "32bit only" code path in the compare op handlers.

Introduce new handlers based on the 32bit only flag. That way we can have 2 separate functions for 32bit mode and 64bit mode, which can handle NARROW_MODE.

r~

Reviewed-by on v1 1/2
#2 lore raw

Re: [Qemu-devel] [PATCH 1/2] PPC: Add 32bit instruction flag

In reply to Alexander Graf
Quoted 11 lines · Alexander Graf

Some instructions behave differently depending on whether the CPU is 64bit capable or not, regardless of the mode the CPU is in.

Add a new instruction flag that indicates that we're running on a CPU that can not execute 64bit code.

---
  target-ppc/cpu.h            |    5 ++-
  target-ppc/translate_init.c |   88 +++++++++++++++++++++---------------------
  2 files changed, 48 insertions(+), 45 deletions(-)

r~