Skip to contentSkip to conversation

target/ppc: Move fixed-point insns to decodetree.

PATCH Superseded Chinmay Rath 3 participants 27 messages Apr 16, 2024 – Apr 22, 2024

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover target/ppc: Move fixed-point insns to decodetree.

Moving all fixed-point instructions of the following type to decodetree specification : arithmetic, compare, trap, select and logical.

Chinmay Rath (8):
target/ppc: Move mul{li, lw, lwo, hw, hwu} instructions to decodetree. target/ppc: Make divw[u] handler method decodetree compatible. target/ppc: Move divw[u, e, eu] instructions to decodetree. target/ppc: Move neg, darn, mod{sw, uw} to decodetree. target/ppc: Move multiply fixed-point insns (64-bit operands) to
decodetree.
target/ppc: Move div/mod fixed-point insns (64 bits operands) to
decodetree.
target/ppc: Move cmp{rb, eqb}, tw[i], td[i], isel instructions to
decodetree.
target/ppc: Move logical fixed-point instructions to decodetree.

 target/ppc/helper.h                        |  26 +-
 target/ppc/insn32.decode                   |  93 +++
 target/ppc/excp_helper.c                   |   4 +-
 target/ppc/int_helper.c                    |  24 +-
 target/ppc/translate.c                     | 841 +--------------------
 target/ppc/translate/fixedpoint-impl.c.inc | 639 ++++++++++++++++
 6 files changed, 770 insertions(+), 857 deletions(-)
Signature · 1 line
2.39.3
#1 lore raw

PATCH 1/8 target/ppc: Move mul{li, lw, lwo, hw, hwu} instructions to decodetree.

Moving the following instructions to decodetree specification :

	mulli                   	: D-form
	mul{lw, lwo, hw, hwu}[.]	: XO-form

The changes were verified by validating that the tcg ops generated by those instructions remain the same, which were captured with the '-d in_asm,op' flag.

---
 target/ppc/insn32.decode                   |  9 +++
 target/ppc/translate.c                     | 89 ----------------------
 target/ppc/translate/fixedpoint-impl.c.inc | 71 +++++++++++++++++
 3 files changed, 80 insertions(+), 89 deletions(-)
target/ppc/insn32.decode +9 -0
index eada59f59f..0184680db8 100644
@@ -193,6 +193,9 @@
 &XO_ta          rt ra oe:bool rc:bool
 @XO_ta          ...... rt:5 ra:5 ..... oe:1 ......... rc:1      &XO_ta
 
+&XO_tab_rc      rt ra rb rc:bool
+@XO_tab_rc      ...... rt:5 ra:5 rb:5 . ......... rc:1          &XO_tab_rc
+
 %xx_xt          0:1 21:5
 %xx_xb          1:1 11:5
 %xx_xa          2:1 16:5
@@ -353,6 +356,12 @@ SUBFE           011111 ..... ..... ..... . 010001000 .  @XO
 SUBFME          011111 ..... ..... ----- . 011101000 .  @XO_ta
 SUBFZE          011111 ..... ..... ----- . 011001000 .  @XO_ta
 
+MULLI           000111 ..... ..... ................     @D
+MULLW           011111 ..... ..... ..... 0 011101011 .  @XO_tab_rc
+MULLWO          011111 ..... ..... ..... 1 011101011 .  @XO_tab_rc
+MULHW           011111 ..... ..... ..... - 001001011 .  @XO_tab_rc
+MULHWU          011111 ..... ..... ..... - 000001011 .  @XO_tab_rc
+
 ## Fixed-Point Logical Instructions
 
 CFUGED          011111 ..... ..... ..... 0011011100 -   @X
target/ppc/translate.c +0 -89

101 lines not on this page · raw message

target/ppc/translate/fixedpoint-impl.c.inc +71 -0

77 lines not on this page · raw message

Signature · 1 line
2.39.3
Reviewed-by on v1 1/8
#2 lore raw

Re: [PATCH 1/8] target/ppc: Move mul{li, lw, lwo, hw, hwu} instructions to decodetree.

Quoted 7 lines · Chinmay Rath

Moving the following instructions to decodetree specification :

	mulli                   	: D-form
	mul{lw, lwo, hw, hwu}[.]	: XO-form

The changes were verified by validating that the tcg ops generated by those instructions remain the same, which were captured with the '-d in_asm,op' flag.

Quoted 6 lines
---
  target/ppc/insn32.decode                   |  9 +++
  target/ppc/translate.c                     | 89 ----------------------
  target/ppc/translate/fixedpoint-impl.c.inc | 71 +++++++++++++++++
  3 files changed, 80 insertions(+), 89 deletions(-)

This is an accurate reorg of the current code, so

However, as follow-up, the code generation could be cleaned up:

Quoted 7 lines
target/ppc/translate/fixedpoint-impl.c.inc +7 -0
+static bool trans_MULLW(DisasContext *ctx, arg_MULLW *a)
+{
+#if defined(TARGET_PPC64)
+    TCGv_i64 t0, t1;
+    t0 = tcg_temp_new_i64();
+    t1 = tcg_temp_new_i64();
+    tcg_gen_ext32s_tl(t0, cpu_gpr[a->ra]);

target/ppc/translate/fixedpoint-impl.c.inc TRANS(SUBFE, do_subf_XO, true, true) · line 420

Quoted 10 lines
target/ppc/translate/fixedpoint-impl.c.inc +10 -0
+    tcg_gen_ext32s_tl(t1, cpu_gpr[a->rb]);
+    tcg_gen_mul_i64(cpu_gpr[a->rt], t0, t1);
+#else
+    tcg_gen_mul_i32(cpu_gpr[a->rt], cpu_gpr[a->ra], cpu_gpr[a->rb]);
+#endif
+    if (unlikely(a->rc)) {
+        gen_set_Rc0(ctx, cpu_gpr[a->rt]);
+    }
+    return true;
+}

Without ifdefs:

    TCGv t0 = tcg_temp_new();
    TCGv t1 = tcg_temp_new();

    tcg_gen_ext32s_tl(t0, ra);
    tcg_gen_ext32s_tl(t1, rb);
    tcg_gen_mul_tl(rt, t0, t1);

For ppc32, ext32s_tl will turn into a mov, which will be optimized away. So ideal code generation for both modes.

Quoted 7 lines
target/ppc/translate/fixedpoint-impl.c.inc +7 -0
+static bool trans_MULLWO(DisasContext *ctx, arg_MULLWO *a)
+{
+    TCGv_i32 t0 = tcg_temp_new_i32();
+    TCGv_i32 t1 = tcg_temp_new_i32();
+
+    tcg_gen_trunc_tl_i32(t0, cpu_gpr[a->ra]);
+    tcg_gen_trunc_tl_i32(t1, cpu_gpr[a->rb]);

target/ppc/translate/fixedpoint-impl.c.inc TRANS(SUBFE, do_subf_XO, true, true) · line 438

Quoted 10 lines
target/ppc/translate/fixedpoint-impl.c.inc +10 -0
+    tcg_gen_muls2_i32(t0, t1, t0, t1);
+#if defined(TARGET_PPC64)
+    tcg_gen_concat_i32_i64(cpu_gpr[a->rt], t0, t1);
+#else
+    tcg_gen_mov_i32(cpu_gpr[a->rt], t0);
+#endif
+
+    tcg_gen_sari_i32(t0, t0, 31);
+    tcg_gen_setcond_i32(TCG_COND_NE, t0, t0, t1);
+    tcg_gen_extu_i32_tl(cpu_ov, t0);

Usually hosts need to create the full 64-bit product and then break it apart for tcg_gen_muls2_i32, so split followed immediately by concatenate isn't great.

    TCGv t0 = tcg_temp_new();
    TCGv t1 = tcg_temp_new();
#ifdef TARGET_PPC64
    tcg_gen_ext32s_i64(t0, ra);
    tcg_gen_ext32s_i64(t1, rb);
    tcg_gen_mul_i64(rt, t0, t1);
    tcg_gen_sextract_i64(t0, rt, 31, 1);
    tcg_gen_sari_i64(t1, rt, 32);
#else
    tcg_gen_muls2_i32(rt, t1, ra, rb);
    tcg_gen_sari_i32(t0, rt, 31);
#endif
    tcg_gen_setcond_tl(TCG_COND_NE, cpu_ov, t0, t1);

target/ppc/translate/fixedpoint-impl.c.inc TRANS(SUBFE, do_subf_XO, true, true) · line 448

Quoted 10 lines
target/ppc/translate/fixedpoint-impl.c.inc +10 -0
+    if (is_isa300(ctx)) {
+        tcg_gen_mov_tl(cpu_ov32, cpu_ov);
+    }
+    tcg_gen_or_tl(cpu_so, cpu_so, cpu_ov);
+
+    if (unlikely(a->rc)) {
+        gen_set_Rc0(ctx, cpu_gpr[a->rt]);
+    }
+    return true;
+}

r~

#3 lore raw

Re: [PATCH 1/8] target/ppc: Move mul{li, lw, lwo, hw, hwu} instructions to decodetree.

Hi Richard,

Quoted 15 lines · Richard Henderson
Quoted 7 lines · Chinmay Rath

Moving the following instructions to decodetree specification :
    mulli                       : D-form
    mul{lw, lwo, hw, hwu}[.]    : XO-form

The changes were verified by validating that the tcg ops generated by those instructions remain the same, which were captured with the '-d in_asm,op' flag.

Quoted 6 lines

---
  target/ppc/insn32.decode                   |  9 +++ target/ppc/translate.c                     | 89 ---------------------- target/ppc/translate/fixedpoint-impl.c.inc | 71 +++++++++++++++++

  3 files changed, 80 insertions(+), 89 deletions(-)
Quoted 2 lines

This is an accurate reorg of the current code, so

Thank you.

Quoted 58 lines

However, as follow-up, the code generation could be cleaned up:

Quoted 7 lines
target/ppc/translate/fixedpoint-impl.c.inc +7 -0
+static bool trans_MULLW(DisasContext *ctx, arg_MULLW *a)
+{
+#if defined(TARGET_PPC64)
+    TCGv_i64 t0, t1;
+    t0 = tcg_temp_new_i64();
+    t1 = tcg_temp_new_i64();
+    tcg_gen_ext32s_tl(t0, cpu_gpr[a->ra]);

target/ppc/translate/fixedpoint-impl.c.inc TRANS(SUBFE, do_subf_XO, true, true) · line 420

Quoted 10 lines
target/ppc/translate/fixedpoint-impl.c.inc +10 -0
+    tcg_gen_ext32s_tl(t1, cpu_gpr[a->rb]);
+    tcg_gen_mul_i64(cpu_gpr[a->rt], t0, t1);
+#else
+    tcg_gen_mul_i32(cpu_gpr[a->rt], cpu_gpr[a->ra], cpu_gpr[a->rb]);
+#endif
+    if (unlikely(a->rc)) {
+        gen_set_Rc0(ctx, cpu_gpr[a->rt]);
+    }
+    return true;
+}

Without ifdefs:

    TCGv t0 = tcg_temp_new();
    TCGv t1 = tcg_temp_new();

    tcg_gen_ext32s_tl(t0, ra);
    tcg_gen_ext32s_tl(t1, rb);
    tcg_gen_mul_tl(rt, t0, t1);

For ppc32, ext32s_tl will turn into a mov, which will be optimized away.  So ideal code generation for both modes.

Quoted 7 lines
target/ppc/translate/fixedpoint-impl.c.inc +7 -0
+static bool trans_MULLWO(DisasContext *ctx, arg_MULLWO *a)
+{
+    TCGv_i32 t0 = tcg_temp_new_i32();
+    TCGv_i32 t1 = tcg_temp_new_i32();
+
+    tcg_gen_trunc_tl_i32(t0, cpu_gpr[a->ra]);
+    tcg_gen_trunc_tl_i32(t1, cpu_gpr[a->rb]);

target/ppc/translate/fixedpoint-impl.c.inc TRANS(SUBFE, do_subf_XO, true, true) · line 438

Quoted 10 lines
target/ppc/translate/fixedpoint-impl.c.inc +10 -0
+    tcg_gen_muls2_i32(t0, t1, t0, t1);
+#if defined(TARGET_PPC64)
+    tcg_gen_concat_i32_i64(cpu_gpr[a->rt], t0, t1);
+#else
+    tcg_gen_mov_i32(cpu_gpr[a->rt], t0);
+#endif
+
+    tcg_gen_sari_i32(t0, t0, 31);
+    tcg_gen_setcond_i32(TCG_COND_NE, t0, t0, t1);
+    tcg_gen_extu_i32_tl(cpu_ov, t0);

Usually hosts need to create the full 64-bit product and then break it apart for tcg_gen_muls2_i32, so split followed immediately by concatenate isn't great.

    TCGv t0 = tcg_temp_new();
    TCGv t1 = tcg_temp_new();

Quoted 12 lines

#ifdef TARGET_PPC64
    tcg_gen_ext32s_i64(t0, ra); tcg_gen_ext32s_i64(t1, rb); tcg_gen_mul_i64(rt, t0, t1); tcg_gen_sextract_i64(t0, rt, 31, 1); tcg_gen_sari_i64(t1, rt, 32);
#else
    tcg_gen_muls2_i32(rt, t1, ra, rb); tcg_gen_sari_i32(t0, rt, 31);
#endif
    tcg_gen_setcond_tl(TCG_COND_NE, cpu_ov, t0, t1);

Sure, will update in v2.
Thanks,
Chinmay

Quoted 15 lines

target/ppc/translate/fixedpoint-impl.c.inc TRANS(SUBFE, do_subf_XO, true, true) · line 420

Quoted 11 lines

+    if (is_isa300(ctx)) {
+        tcg_gen_mov_tl(cpu_ov32, cpu_ov);
+    }
+    tcg_gen_or_tl(cpu_so, cpu_so, cpu_ov);

target/ppc/translate/fixedpoint-impl.c.inc +6 -0
+
+    if (unlikely(a->rc)) {
+        gen_set_Rc0(ctx, cpu_gpr[a->rt]);
+    }
+    return true;
+}

r~

#4 lore raw

PATCH 2/8 target/ppc: Make divw[u] handler method decodetree compatible.

In reply to Chinmay Rath

The handler methods for divw[u] instructions internally use Rc(ctx->opcode), for extraction of Rc field of instructions, which poses a problem if we move the above said instructions to decodetree, as the ctx->opcode field is not popluated in decodetree. Hence, making it decodetree compatible, so that the mentioned insns can be safely move to decodetree specs.

---
 target/ppc/translate.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
target/ppc/translate.c +5 -4
index c45547a770..be7d807e3c 100644
@@ -1738,8 +1738,9 @@ static inline void gen_op_arith_add(DisasContext *ctx, TCGv ret, TCGv arg1,
     }
 }
 
-static inline void gen_op_arith_divw(DisasContext *ctx, TCGv ret, TCGv arg1,
-                                     TCGv arg2, int sign, int compute_ov)
+static inline void gen_op_arith_divw(DisasContext *ctx, TCGv ret,
+                                     TCGv arg1, TCGv arg2, bool sign,
+                                     bool compute_ov, bool compute_rc0)
 {
     TCGv_i32 t0 = tcg_temp_new_i32();
     TCGv_i32 t1 = tcg_temp_new_i32();
@@ -1773,7 +1774,7 @@ static inline void gen_op_arith_divw(DisasContext *ctx, TCGv ret, TCGv arg1,
         tcg_gen_or_tl(cpu_so, cpu_so, cpu_ov);
     }
 
-    if (unlikely(Rc(ctx->opcode) != 0)) {
+    if (unlikely(compute_rc0)) {
         gen_set_Rc0(ctx, ret);
     }
 }
@@ -1783,7 +1784,7 @@ static void glue(gen_, name)(DisasContext *ctx)                               \
 {                                                                             \
     gen_op_arith_divw(ctx, cpu_gpr[rD(ctx->opcode)],                          \
                      cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],      \
-                     sign, compute_ov);                                       \
+                     sign, compute_ov, Rc(ctx->opcode));                      \
 }
 /* divwu  divwu.  divwuo  divwuo.   */
 GEN_INT_ARITH_DIVW(divwu, 0x0E, 0, 0);
Signature · 1 line
2.39.3
Reviewed-by on v1 2/8
#5 lore raw

Re: [PATCH 2/8] target/ppc: Make divw[u] handler method decodetree compatible.

Quoted 10 lines · Chinmay Rath

The handler methods for divw[u] instructions internally use Rc(ctx->opcode), for extraction of Rc field of instructions, which poses a problem if we move the above said instructions to decodetree, as the ctx->opcode field is not popluated in decodetree. Hence, making it decodetree compatible, so that the mentioned insns can be safely move to decodetree specs.

---
  target/ppc/translate.c | 9 +++++----
  1 file changed, 5 insertions(+), 4 deletions(-)

target/ppc/translate.c static inline void gen_op_arith_add(DisasContext *ctx, TCGv ret, TCGv arg1, · line 1743

Quoted 3 lines
target/ppc/translate.c +3 -0
+static inline void gen_op_arith_divw(DisasContext *ctx, TCGv ret,
+                                     TCGv arg1, TCGv arg2, bool sign,
+                                     bool compute_ov, bool compute_rc0)

Could drop the inline at the same time.
Let the compiler decide.

r~

#6 lore raw

Re: [PATCH 2/8] target/ppc: Make divw[u] handler method decodetree compatible.

Hi Richard,

Quoted 7 lines · Richard Henderson
Quoted 6 lines · Chinmay Rath

The handler methods for divw[u] instructions internally use Rc(ctx->opcode), for extraction of Rc field of instructions, which poses a problem if we move the above said instructions to decodetree, as the ctx->opcode field is not popluated in decodetree. Hence, making it decodetree compatible, so that the mentioned insns can be safely move to decodetree specs.

Quoted 7 lines
Quoted 4 lines

---
  target/ppc/translate.c | 9 +++++----

  1 file changed, 5 insertions(+), 4 deletions(-)

Thank you.

Quoted 7 lines
Quoted 3 lines

+static inline void gen_op_arith_divw(DisasContext *ctx, TCGv ret, +                                     TCGv arg1, TCGv arg2, bool sign, +                                     bool compute_ov, bool compute_rc0)

Could drop the inline at the same time.
Let the compiler decide.

I kept inline as is, as there are multiple gen_op_* routines with inline and if necessary we could consider removing inline for all of them together in a separate patch :

grep inline target/ppc/translate.c | grep gen_op

static inline void gen_op_cmp(TCGv arg0, TCGv arg1, int s, int crf) static inline void gen_op_cmpi(TCGv arg0, target_ulong arg1, int s, int crf) static inline void gen_op_cmp32(TCGv arg0, TCGv arg1, int s, int crf) static inline void gen_op_cmpi32(TCGv arg0, target_ulong arg1, int s, int crf) static inline void gen_op_arith_compute_ov(DisasContext *ctx, TCGv arg0, static inline void gen_op_arith_compute_ca32(DisasContext *ctx, static inline void gen_op_arith_add(DisasContext *ctx, TCGv ret, TCGv arg1, static inline void gen_op_arith_divw(DisasContext *ctx, TCGv ret, static inline void gen_op_arith_divd(DisasContext *ctx, TCGv ret, static inline void gen_op_arith_modw(DisasContext *ctx, TCGv ret, TCGv arg1, static inline void gen_op_arith_modd(DisasContext *ctx, TCGv ret, TCGv arg1, static inline void gen_op_arith_subf(DisasContext *ctx, TCGv ret, TCGv arg1, static inline void gen_op_mfspr(DisasContext *ctx)

Thanks,
Chinmay

Quoted 2 lines

r~

#7 lore raw

PATCH 3/8 target/ppc: Move divw[u, e, eu] instructions to decodetree.

In reply to Chinmay Rath

Moving the following instructions to decodetree specification :

	 divw[u, e, eu][o][.] 	: XO-form

The changes were verified by validating that the tcg ops generated by those instructions remain the same, which were captured with the '-d in_asm,op' flag.

---
 target/ppc/helper.h                        |  4 +--
 target/ppc/insn32.decode                   |  5 ++++
 target/ppc/int_helper.c                    |  4 +--
 target/ppc/translate.c                     | 31 ----------------------
 target/ppc/translate/fixedpoint-impl.c.inc | 24 +++++++++++++++++
 5 files changed, 33 insertions(+), 35 deletions(-)
target/ppc/helper.h +2 -2
index 86f97ee1e7..1fc8b7c5fd 100644
@@ -55,8 +55,8 @@ DEF_HELPER_5(lscbx, tl, env, tl, i32, i32, i32)
 DEF_HELPER_4(divdeu, i64, env, i64, i64, i32)
 DEF_HELPER_4(divde, i64, env, i64, i64, i32)
 #endif
-DEF_HELPER_4(divweu, tl, env, tl, tl, i32)
-DEF_HELPER_4(divwe, tl, env, tl, tl, i32)
+DEF_HELPER_4(DIVWEU, tl, env, tl, tl, i32)
+DEF_HELPER_4(DIVWE, tl, env, tl, tl, i32)
 
 DEF_HELPER_FLAGS_1(popcntb, TCG_CALL_NO_RWG_SE, tl, tl)
 DEF_HELPER_FLAGS_2(cmpb, TCG_CALL_NO_RWG_SE, tl, tl, tl)
target/ppc/insn32.decode +5 -0
index 0184680db8..bfccebd9a7 100644
@@ -362,6 +362,11 @@ MULLWO          011111 ..... ..... ..... 1 011101011 .  @XO_tab_rc
 MULHW           011111 ..... ..... ..... - 001001011 .  @XO_tab_rc
 MULHWU          011111 ..... ..... ..... - 000001011 .  @XO_tab_rc
 
+DIVW            011111 ..... ..... ..... . 111101011 .  @XO
+DIVWU           011111 ..... ..... ..... . 111001011 .  @XO
+DIVWE           011111 ..... ..... ..... . 110101011 .  @XO
+DIVWEU          011111 ..... ..... ..... . 110001011 .  @XO
+
 ## Fixed-Point Logical Instructions
 
 CFUGED          011111 ..... ..... ..... 0011011100 -   @X
target/ppc/int_helper.c +2 -2
index 0a5c3e78a4..dc1f72ff38 100644
@@ -44,7 +44,7 @@ static inline void helper_update_ov_legacy(CPUPPCState *env, int ov)
     }
 }
 
-target_ulong helper_divweu(CPUPPCState *env, target_ulong ra, target_ulong rb,
+target_ulong helper_DIVWEU(CPUPPCState *env, target_ulong ra, target_ulong rb,
                            uint32_t oe)
 {
     uint64_t rt = 0;
@@ -71,7 +71,7 @@ target_ulong helper_divweu(CPUPPCState *env, target_ulong ra, target_ulong rb,
     return (target_ulong)rt;
 }
 
-target_ulong helper_divwe(CPUPPCState *env, target_ulong ra, target_ulong rb,
+target_ulong helper_DIVWE(CPUPPCState *env, target_ulong ra, target_ulong rb,
                           uint32_t oe)
 {
     int64_t rt = 0;
target/ppc/translate.c +0 -31
index be7d807e3c..0a1d1d63b3 100644
@@ -1778,21 +1778,6 @@ static inline void gen_op_arith_divw(DisasContext *ctx, TCGv ret,
         gen_set_Rc0(ctx, ret);
     }
 }
-/* Div functions */
-#define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov)                      \
-static void glue(gen_, name)(DisasContext *ctx)                               \
-{                                                                             \
-    gen_op_arith_divw(ctx, cpu_gpr[rD(ctx->opcode)],                          \
-                     cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],      \
-                     sign, compute_ov, Rc(ctx->opcode));                      \
-}
-/* divwu  divwu.  divwuo  divwuo.   */
-GEN_INT_ARITH_DIVW(divwu, 0x0E, 0, 0);
-GEN_INT_ARITH_DIVW(divwuo, 0x1E, 0, 1);
-/* divw  divw.  divwo  divwo.   */
-GEN_INT_ARITH_DIVW(divw, 0x0F, 1, 0);
-GEN_INT_ARITH_DIVW(divwo, 0x1F, 1, 1);
-
 /* div[wd]eu[o][.] */
 #define GEN_DIVE(name, hlpr, compute_ov)                                      \
 static void gen_##name(DisasContext *ctx)                                     \
@@ -1805,11 +1790,6 @@ static void gen_##name(DisasContext *ctx)                                     \
     }                                                                         \
 }
 
-GEN_DIVE(divweu, divweu, 0);
-GEN_DIVE(divweuo, divweu, 1);
-GEN_DIVE(divwe, divwe, 0);
-GEN_DIVE(divweo, divwe, 1);
-
 #if defined(TARGET_PPC64)
 static inline void gen_op_arith_divd(DisasContext *ctx, TCGv ret, TCGv arg1,
                                      TCGv arg2, int sign, int compute_ov)
@@ -6562,17 +6542,6 @@ GEN_HANDLER_E(maddhd_maddhdu, 0x04, 0x18, 0xFF, 0x00000000, PPC_NONE,
 GEN_HANDLER_E(maddld, 0x04, 0x19, 0xFF, 0x00000000, PPC_NONE, PPC2_ISA300),
 #endif
 
-#undef GEN_INT_ARITH_DIVW
-#define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov)                      \
-GEN_HANDLER(name, 0x1F, 0x0B, opc3, 0x00000000, PPC_INTEGER)
-GEN_INT_ARITH_DIVW(divwu, 0x0E, 0, 0),
-GEN_INT_ARITH_DIVW(divwuo, 0x1E, 0, 1),
-GEN_INT_ARITH_DIVW(divw, 0x0F, 1, 0),
-GEN_INT_ARITH_DIVW(divwo, 0x1F, 1, 1),
-GEN_HANDLER_E(divwe, 0x1F, 0x0B, 0x0D, 0, PPC_NONE, PPC2_DIVE_ISA206),
-GEN_HANDLER_E(divweo, 0x1F, 0x0B, 0x1D, 0, PPC_NONE, PPC2_DIVE_ISA206),
-GEN_HANDLER_E(divweu, 0x1F, 0x0B, 0x0C, 0, PPC_NONE, PPC2_DIVE_ISA206),
-GEN_HANDLER_E(divweuo, 0x1F, 0x0B, 0x1C, 0, PPC_NONE, PPC2_DIVE_ISA206),
 GEN_HANDLER_E(modsw, 0x1F, 0x0B, 0x18, 0x00000001, PPC_NONE, PPC2_ISA300),
 GEN_HANDLER_E(moduw, 0x1F, 0x0B, 0x08, 0x00000001, PPC_NONE, PPC2_ISA300),
 
target/ppc/translate/fixedpoint-impl.c.inc +24 -0
index e12e533c67..3f787bbeaa 100644
@@ -466,6 +466,30 @@ static bool do_mulhw(DisasContext *ctx, arg_XO_tab_rc *a,
 TRANS(MULHW, do_mulhw, tcg_gen_muls2_i32)
 TRANS(MULHWU, do_mulhw, tcg_gen_mulu2_i32)
 
+static bool do_divw(DisasContext *ctx, arg_XO *a, int sign)
+{
+    gen_op_arith_divw(ctx, cpu_gpr[a->rt], cpu_gpr[a->ra], cpu_gpr[a->rb],
+                      sign, a->oe, a->rc);
+    return true;
+}
+
+static bool do_divwe(DisasContext *ctx, arg_XO *a,
+                     void (*helper)(TCGv, TCGv_ptr, TCGv, TCGv, TCGv_i32))
+{
+    REQUIRE_INSNS_FLAGS2(ctx, DIVE_ISA206);
+    helper(cpu_gpr[a->rt], tcg_env, cpu_gpr[a->ra], cpu_gpr[a->rb],
+           tcg_constant_i32(a->oe));
+    if (unlikely(a->rc)) {
+        gen_set_Rc0(ctx, cpu_gpr[a->rt]);
+    }
+    return true;
+}
+
+TRANS(DIVW, do_divw, 1);
+TRANS(DIVWU, do_divw, 0);
+TRANS(DIVWE, do_divwe, gen_helper_DIVWE);
+TRANS(DIVWEU, do_divwe, gen_helper_DIVWEU);
+
 static bool trans_INVALID(DisasContext *ctx, arg_INVALID *a)
 {
     gen_invalid(ctx);
Signature · 1 line
2.39.3
Reviewed-by on v1 3/8
#8 lore raw

Re: [PATCH 3/8] target/ppc: Move divw[u, e, eu] instructions to decodetree.

Quoted 6 lines · Chinmay Rath

Moving the following instructions to decodetree specification :

	 divw[u, e, eu][o][.] 	: XO-form

The changes were verified by validating that the tcg ops generated by those instructions remain the same, which were captured with the '-d in_asm,op' flag.

Quoted 8 lines
---
  target/ppc/helper.h                        |  4 +--
  target/ppc/insn32.decode                   |  5 ++++
  target/ppc/int_helper.c                    |  4 +--
  target/ppc/translate.c                     | 31 ----------------------
  target/ppc/translate/fixedpoint-impl.c.inc | 24 +++++++++++++++++
  5 files changed, 33 insertions(+), 35 deletions(-)

r~

#9 lore raw

Re: [PATCH 3/8] target/ppc: Move divw[u, e, eu] instructions to decodetree.

Quoted 16 lines · Richard Henderson
Quoted 6 lines · Chinmay Rath

Moving the following instructions to decodetree specification :
     divw[u, e, eu][o][.]     : XO-form

The changes were verified by validating that the tcg ops generated by those instructions remain the same, which were captured with the '-d in_asm,op' flag.

Quoted 8 lines

---
  target/ppc/helper.h                        |  4 +-- target/ppc/insn32.decode                   |  5 ++++ target/ppc/int_helper.c                    |  4 +-- target/ppc/translate.c                     | 31 ---------------------- target/ppc/translate/fixedpoint-impl.c.inc | 24 +++++++++++++++++

  5 files changed, 33 insertions(+), 35 deletions(-)
Quoted 2 lines

Thanks,
Chinmay

Quoted 2 lines

r~

#10 lore raw

PATCH 4/8 target/ppc: Move neg, darn, mod{sw, uw} to decodetree.

In reply to Chinmay Rath

Moving the below instructions to decodetree specification :

	neg[o][.]       	: XO-form
	mod{sw, uw}, darn	: X-form

The changes were verified by validating that the tcg ops generated by those instructions remain the same, which were captured with the '-d in_asm,op' flag.

---
 target/ppc/helper.h                        |  4 +-
 target/ppc/insn32.decode                   |  8 ++++
 target/ppc/int_helper.c                    |  4 +-
 target/ppc/translate.c                     | 56 ----------------------
 target/ppc/translate/fixedpoint-impl.c.inc | 44 +++++++++++++++++
 5 files changed, 56 insertions(+), 60 deletions(-)
target/ppc/helper.h +2 -2
index 1fc8b7c5fd..09d0b0074b 100644
@@ -71,8 +71,8 @@ DEF_HELPER_FLAGS_2(cmpeqb, TCG_CALL_NO_RWG_SE, i32, tl, tl)
 DEF_HELPER_FLAGS_1(popcntw, TCG_CALL_NO_RWG_SE, tl, tl)
 DEF_HELPER_FLAGS_2(bpermd, TCG_CALL_NO_RWG_SE, i64, i64, i64)
 DEF_HELPER_3(srad, tl, env, tl, tl)
-DEF_HELPER_FLAGS_0(darn32, TCG_CALL_NO_RWG, tl)
-DEF_HELPER_FLAGS_0(darn64, TCG_CALL_NO_RWG, tl)
+DEF_HELPER_FLAGS_0(DARN32, TCG_CALL_NO_RWG, tl)
+DEF_HELPER_FLAGS_0(DARN64, TCG_CALL_NO_RWG, tl)
 #endif
 
 DEF_HELPER_FLAGS_1(cntlsw32, TCG_CALL_NO_RWG_SE, i32, i32)
target/ppc/insn32.decode +8 -0
index bfccebd9a7..654f55471b 100644
@@ -187,6 +187,9 @@
 &X_a            ra
 @X_a            ...... ra:3 .. ..... ..... .......... .         &X_a
 
+&X_tl           rt l
+@X_tl           ...... rt:5 ... l:2 ..... .......... .          &X_tl
+
 &XO             rt ra rb oe:bool rc:bool
 @XO             ...... rt:5 ra:5 rb:5 oe:1 ......... rc:1       &XO
 
@@ -367,6 +370,11 @@ DIVWU           011111 ..... ..... ..... . 111001011 .  @XO
 DIVWE           011111 ..... ..... ..... . 110101011 .  @XO
 DIVWEU          011111 ..... ..... ..... . 110001011 .  @XO
 
+MODSW           011111 ..... ..... ..... 1100001011 -   @X
+MODUW           011111 ..... ..... ..... 0100001011 -   @X
+DARN            011111 ..... --- .. ----- 1011110011 -  @X_tl
+NEG             011111 ..... ..... ----- . 001101000 .  @XO_ta
+
 ## Fixed-Point Logical Instructions
 
 CFUGED          011111 ..... ..... ..... 0011011100 -   @X
target/ppc/int_helper.c +2 -2
index dc1f72ff38..bc25d5b062 100644
@@ -171,7 +171,7 @@ uint32_t helper_cmpeqb(target_ulong ra, target_ulong rb)
 /*
  * Return a random number.
  */
-uint64_t helper_darn32(void)
+uint64_t helper_DARN32(void)
 {
     Error *err = NULL;
     uint32_t ret;
@@ -186,7 +186,7 @@ uint64_t helper_darn32(void)
     return ret;
 }
 
-uint64_t helper_darn64(void)
+uint64_t helper_DARN64(void)
 {
     Error *err = NULL;
     uint64_t ret;
target/ppc/translate.c +0 -56

92 lines not on this page · raw message

target/ppc/translate/fixedpoint-impl.c.inc +44 -0

50 lines not on this page · raw message

Signature · 1 line
2.39.3
Reviewed-by on v1 4/8
#11 lore raw

Re: [PATCH 4/8] target/ppc: Move neg, darn, mod{sw, uw} to decodetree.

Quoted 8 lines · Chinmay Rath

Moving the below instructions to decodetree specification :

	neg[o][.]       	: XO-form
	mod{sw, uw}, darn	: X-form

The changes were verified by validating that the tcg ops generated by those instructions remain the same, which were captured with the '-d in_asm,op' flag.

Quoted 8 lines
---
  target/ppc/helper.h                        |  4 +-
  target/ppc/insn32.decode                   |  8 ++++
  target/ppc/int_helper.c                    |  4 +-
  target/ppc/translate.c                     | 56 ----------------------
  target/ppc/translate/fixedpoint-impl.c.inc | 44 +++++++++++++++++
  5 files changed, 56 insertions(+), 60 deletions(-)

r~

#12 lore raw

Re: [PATCH 4/8] target/ppc: Move neg, darn, mod{sw, uw} to decodetree.

Quoted 18 lines · Richard Henderson
Quoted 8 lines · Chinmay Rath

Moving the below instructions to decodetree specification :

    neg[o][.]           : XO-form
    mod{sw, uw}, darn    : X-form

The changes were verified by validating that the tcg ops generated by those instructions remain the same, which were captured with the '-d in_asm,op' flag.

Quoted 8 lines

---
  target/ppc/helper.h                        |  4 +- target/ppc/insn32.decode                   |  8 ++++ target/ppc/int_helper.c                    |  4 +- target/ppc/translate.c                     | 56 ---------------------- target/ppc/translate/fixedpoint-impl.c.inc | 44 +++++++++++++++++

  5 files changed, 56 insertions(+), 60 deletions(-)
Quoted 1 line

Thanks,
Chinmay

Quoted 2 lines

r~

#13 lore raw

PATCH 5/8 target/ppc: Move multiply fixed-point insns (64-bit operands) to decodetree.

In reply to Chinmay Rath

Moving the following instructions to decodetree :

	mul{ld, ldo, hd, hdu}[.]	: XO-form
	madd{hd, hdu, ld}		: VA-form

The changes were verified by validating that the tcg ops generated by those instructions remain the same, which were captured with the '-d in_asm,op' flag.

---
 target/ppc/insn32.decode                   |   9 ++
 target/ppc/translate.c                     | 101 ---------------------
 target/ppc/translate/fixedpoint-impl.c.inc |  85 +++++++++++++++++
 3 files changed, 94 insertions(+), 101 deletions(-)
target/ppc/insn32.decode +9 -0
index 654f55471b..61c59bbde0 100644
@@ -375,6 +375,15 @@ MODUW           011111 ..... ..... ..... 0100001011 -   @X
 DARN            011111 ..... --- .. ----- 1011110011 -  @X_tl
 NEG             011111 ..... ..... ----- . 001101000 .  @XO_ta
 
+MULLD           011111 ..... ..... ..... 0 011101001 .  @XO_tab_rc
+MULLDO          011111 ..... ..... ..... 1 011101001 .  @XO_tab_rc
+MULHD           011111 ..... ..... ..... - 001001001 .  @XO_tab_rc
+MULHDU          011111 ..... ..... ..... - 000001001 .  @XO_tab_rc
+
+MADDLD          000100 ..... ..... ..... ..... 110011   @VA
+MADDHD          000100 ..... ..... ..... ..... 110000   @VA
+MADDHDU         000100 ..... ..... ..... ..... 110001   @VA
+
 ## Fixed-Point Logical Instructions
 
 CFUGED          011111 ..... ..... ..... 0011011100 -   @X
target/ppc/translate.c +0 -101

131 lines not on this page · raw message

target/ppc/translate/fixedpoint-impl.c.inc +85 -0

91 lines not on this page · raw message

Signature · 1 line
2.39.3
Reviewed-by on v1 5/8
#14 lore raw

Re: [PATCH 5/8] target/ppc: Move multiply fixed-point insns (64-bit operands) to decodetree.

Quoted 1 line · Chinmay Rath

+static bool trans_MADDHDU(DisasContext *ctx, arg_MADDHDU *a)

...

Quoted 1 line

+ tcg_gen_movi_i64(t1, 0);

Drop the movi.

Quoted 1 line

+ tcg_gen_add2_i64(t1, cpu_gpr[a->vrt], lo, hi, cpu_gpr[a->rc], t1);

Use tcg_constant_i64(0).

With that,

r~

#15 lore raw

Re: [PATCH 5/8] target/ppc: Move multiply fixed-point insns (64-bit operands) to decodetree.

Hi Richard,

Quoted 11 lines · Richard Henderson
Quoted 1 line · Chinmay Rath

+static bool trans_MADDHDU(DisasContext *ctx, arg_MADDHDU *a)

...

Quoted 1 line

+    tcg_gen_movi_i64(t1, 0);

Drop the movi.

Quoted 1 line

+    tcg_gen_add2_i64(t1, cpu_gpr[a->vrt], lo, hi, cpu_gpr[a->rc], t1);

Use tcg_constant_i64(0).

Looks like tcg_gen_add2_i64 internally modifies the passed arguments, hence constant is not expected. However, I tried using tcg_constant_i64(0) as suggested but this leads to an assert failure :
qemu-system-ppc64: ../tcg/tcg.c:5071: tcg_reg_alloc_op: Assertion `!temp_readonly(ts)' failed.

So I hope it is fine to keep the code change as is for now. Let me know if you have any suggestions.

Thanks,
Chinmay

Quoted 5 lines

With that,

r~

#16 lore raw

Re: [PATCH 5/8] target/ppc: Move multiply fixed-point insns (64-bit operands) to decodetree.

Quoted 10 lines · Chinmay Rath

Hi Richard,

Quoted 7 lines · Richard Henderson
Quoted 1 line · Chinmay Rath

+static bool trans_MADDHDU(DisasContext *ctx, arg_MADDHDU *a)

...

Quoted 1 line

+    tcg_gen_movi_i64(t1, 0);

Drop the movi.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

+    tcg_gen_add2_i64(t1, cpu_gpr[a->vrt], lo, hi, cpu_gpr[a->rc], t1);

Use tcg_constant_i64(0).

Looks like tcg_gen_add2_i64 internally modifies the passed arguments, hence constant is not expected. However, I tried using tcg_constant_i64(0) as suggested but this leads to an assert failure :
qemu-system-ppc64: ../tcg/tcg.c:5071: tcg_reg_alloc_op: Assertion `!temp_readonly(ts)' failed.

You misunderstood my suggestion.

  TCGv_i64 t1 = tcg_temp_new_i64();
  tcg_gen_add2_i64(t1, cpu_gpr[vrt], lo, hi, cpu_gpr[a->rc], tcg_constantant_i64(0));

r~

#17 lore raw

Re: [PATCH 5/8] target/ppc: Move multiply fixed-point insns (64-bit operands) to decodetree.

Hi Richard,

Quoted 16 lines · Richard Henderson
Quoted 15 lines · Chinmay Rath

Hi Richard,

Quoted 12 lines · Richard Henderson
Quoted 1 line · Chinmay Rath

+static bool trans_MADDHDU(DisasContext *ctx, arg_MADDHDU *a)

...

Quoted 1 line

+    tcg_gen_movi_i64(t1, 0);

Drop the movi.

Quoted 2 lines

+    tcg_gen_add2_i64(t1, cpu_gpr[a->vrt], lo, hi, cpu_gpr[a->rc], t1);

Use tcg_constant_i64(0).

Quoted 9 lines
Quoted 3 lines

Looks like tcg_gen_add2_i64 internally modifies the passed arguments, hence constant is not expected. However, I tried using tcg_constant_i64(0) as suggested but this leads to an assert failure :
qemu-system-ppc64: ../tcg/tcg.c:5071: tcg_reg_alloc_op: Assertion `!temp_readonly(ts)' failed.

You misunderstood my suggestion.

  TCGv_i64 t1 = tcg_temp_new_i64();
  tcg_gen_add2_i64(t1, cpu_gpr[vrt], lo, hi, cpu_gpr[a->rc], tcg_constantant_i64(0));

Thank you for the clarification. Will add this to v2. Regards,
Chinmay

Quoted 3 lines

r~

#18 lore raw

PATCH 6/8 target/ppc: Move div/mod fixed-point insns (64 bits operands) to decodetree.

In reply to Chinmay Rath

Moving the below instructions to decodetree specification :

	divd[u, e, eu][o][.]	: XO-form
	mod{sd, ud}		: X-form

With this patch, all the fixed-point arithmetic instructions have been moved to decodetree.
The changes were verified by validating that the tcg ops generated by those instructions remain the same, which were captured using the '-d in_asm,op' flag. Also, remaned do_divwe method in fixedpoint-impl.c.inc to do_dive because it is now used to divide doubleword operands as well, and not just words.

---
 target/ppc/helper.h                        |  4 +-
 target/ppc/insn32.decode                   |  8 +++
 target/ppc/int_helper.c                    |  4 +-
 target/ppc/translate.c                     | 65 ++--------------------
 target/ppc/translate/fixedpoint-impl.c.inc | 29 +++++++++-
 5 files changed, 42 insertions(+), 68 deletions(-)
target/ppc/helper.h +2 -2
index 09d0b0074b..e862bdceaf 100644
@@ -52,8 +52,8 @@ DEF_HELPER_FLAGS_2(icbiep, TCG_CALL_NO_WG, void, env, tl)
 DEF_HELPER_5(lscbx, tl, env, tl, i32, i32, i32)
 
 #if defined(TARGET_PPC64)
-DEF_HELPER_4(divdeu, i64, env, i64, i64, i32)
-DEF_HELPER_4(divde, i64, env, i64, i64, i32)
+DEF_HELPER_4(DIVDEU, i64, env, i64, i64, i32)
+DEF_HELPER_4(DIVDE, i64, env, i64, i64, i32)
 #endif
 DEF_HELPER_4(DIVWEU, tl, env, tl, tl, i32)
 DEF_HELPER_4(DIVWE, tl, env, tl, tl, i32)
target/ppc/insn32.decode +8 -0
index 61c59bbde0..509961023b 100644
@@ -384,6 +384,14 @@ MADDLD          000100 ..... ..... ..... ..... 110011   @VA
 MADDHD          000100 ..... ..... ..... ..... 110000   @VA
 MADDHDU         000100 ..... ..... ..... ..... 110001   @VA
 
+DIVD            011111 ..... ..... ..... . 111101001 .  @XO
+DIVDU           011111 ..... ..... ..... . 111001001 .  @XO
+DIVDE           011111 ..... ..... ..... . 110101001 .  @XO
+DIVDEU          011111 ..... ..... ..... . 110001001 .  @XO
+
+MODSD           011111 ..... ..... ..... 1100001001 -   @X
+MODUD           011111 ..... ..... ..... 0100001001 -   @X
+
 ## Fixed-Point Logical Instructions
 
 CFUGED          011111 ..... ..... ..... 0011011100 -   @X
target/ppc/int_helper.c +2 -2
index bc25d5b062..585c2b65d3 100644
@@ -101,7 +101,7 @@ target_ulong helper_DIVWE(CPUPPCState *env, target_ulong ra, target_ulong rb,
 
 #if defined(TARGET_PPC64)
 
-uint64_t helper_divdeu(CPUPPCState *env, uint64_t ra, uint64_t rb, uint32_t oe)
+uint64_t helper_DIVDEU(CPUPPCState *env, uint64_t ra, uint64_t rb, uint32_t oe)
 {
     uint64_t rt = 0;
     int overflow = 0;
@@ -120,7 +120,7 @@ uint64_t helper_divdeu(CPUPPCState *env, uint64_t ra, uint64_t rb, uint32_t oe)
     return rt;
 }
 
-uint64_t helper_divde(CPUPPCState *env, uint64_t rau, uint64_t rbu, uint32_t oe)
+uint64_t helper_DIVDE(CPUPPCState *env, uint64_t rau, uint64_t rbu, uint32_t oe)
 {
     uint64_t rt = 0;
     int64_t ra = (int64_t)rau;
target/ppc/translate.c +4 -61

94 lines not on this page · raw message

target/ppc/translate/fixedpoint-impl.c.inc +26 -3
index 561fb2d94c..d8a0a21ebe 100644
@@ -473,7 +473,7 @@ static bool do_divw(DisasContext *ctx, arg_XO *a, int sign)
     return true;
 }
 
-static bool do_divwe(DisasContext *ctx, arg_XO *a,
+static bool do_dive(DisasContext *ctx, arg_XO *a,
                      void (*helper)(TCGv, TCGv_ptr, TCGv, TCGv, TCGv_i32))
 {
     REQUIRE_INSNS_FLAGS2(ctx, DIVE_ISA206);
@@ -487,8 +487,8 @@ static bool do_divwe(DisasContext *ctx, arg_XO *a,
 
 TRANS(DIVW, do_divw, 1);
 TRANS(DIVWU, do_divw, 0);
-TRANS(DIVWE, do_divwe, gen_helper_DIVWE);
-TRANS(DIVWEU, do_divwe, gen_helper_DIVWEU);
+TRANS(DIVWE, do_dive, gen_helper_DIVWE);
+TRANS(DIVWEU, do_dive, gen_helper_DIVWEU);
 
 static bool do_modw(DisasContext *ctx, arg_X *a, bool sign)
 {
@@ -619,6 +619,29 @@ static bool trans_MADDHDU(DisasContext *ctx, arg_MADDHDU *a)
     return true;
 }
 
+static bool do_divd(DisasContext *ctx, arg_XO *a, bool sign)
+{
+    gen_op_arith_divd(ctx, cpu_gpr[a->rt], cpu_gpr[a->ra], cpu_gpr[a->rb],
+                      sign, a->oe, a->rc);
+    return true;
+}
+
+static bool do_modd(DisasContext *ctx, arg_X *a, bool sign)
+{
+    REQUIRE_INSNS_FLAGS2(ctx, ISA300);
+    gen_op_arith_modd(ctx, cpu_gpr[a->rt], cpu_gpr[a->ra], cpu_gpr[a->rb],
+                      sign);
+    return true;
+}
+
+TRANS64(DIVD, do_divd, true);
+TRANS64(DIVDU, do_divd, false);
+TRANS64(DIVDE, do_dive, gen_helper_DIVDE);
+TRANS64(DIVDEU, do_dive, gen_helper_DIVDEU);
+
+TRANS64(MODSD, do_modd, true);
+TRANS64(MODUD, do_modd, false);
+
 static bool trans_INVALID(DisasContext *ctx, arg_INVALID *a)
 {
     gen_invalid(ctx);
Signature · 1 line
2.39.3
Reviewed-by on v1 6/8
#19 lore raw

Re: [PATCH 6/8] target/ppc: Move div/mod fixed-point insns (64 bits operands) to decodetree.

Quoted 12 lines · Chinmay Rath

Moving the below instructions to decodetree specification :

	divd[u, e, eu][o][.]	: XO-form
	mod{sd, ud}		: X-form

With this patch, all the fixed-point arithmetic instructions have been moved to decodetree.
The changes were verified by validating that the tcg ops generated by those instructions remain the same, which were captured using the '-d in_asm,op' flag. Also, remaned do_divwe method in fixedpoint-impl.c.inc to do_dive because it is now used to divide doubleword operands as well, and not just words.

Quoted 8 lines
---
  target/ppc/helper.h                        |  4 +-
  target/ppc/insn32.decode                   |  8 +++
  target/ppc/int_helper.c                    |  4 +-
  target/ppc/translate.c                     | 65 ++--------------------
  target/ppc/translate/fixedpoint-impl.c.inc | 29 +++++++++-
  5 files changed, 42 insertions(+), 68 deletions(-)

r~

#20 lore raw

Re: [PATCH 6/8] target/ppc: Move div/mod fixed-point insns (64 bits operands) to decodetree.

Quoted 22 lines · Richard Henderson
Quoted 12 lines · Chinmay Rath

Moving the below instructions to decodetree specification :

    divd[u, e, eu][o][.]    : XO-form
    mod{sd, ud}        : X-form

With this patch, all the fixed-point arithmetic instructions have been moved to decodetree.
The changes were verified by validating that the tcg ops generated by those instructions remain the same, which were captured using the '-d in_asm,op' flag. Also, remaned do_divwe method in fixedpoint-impl.c.inc to do_dive because it is now used to divide doubleword operands as well, and not just words.

Quoted 8 lines

---
  target/ppc/helper.h                        |  4 +- target/ppc/insn32.decode                   |  8 +++ target/ppc/int_helper.c                    |  4 +- target/ppc/translate.c                     | 65 ++-------------------- target/ppc/translate/fixedpoint-impl.c.inc | 29 +++++++++-

  5 files changed, 42 insertions(+), 68 deletions(-)
Quoted 2 lines

Thanks,
Chinmay

Quoted 1 line

r~

#21 lore raw

PATCH 7/8 target/ppc: Move cmp{rb, eqb}, tw[i], td[i], isel instructions to decodetree.

In reply to Chinmay Rath

Moving the following instructions to decodetree specification :

	cmp{rb, eqb}, t{w, d}	: X-form
	t{w, d}i		: D-form
	isel			: A-form

The changes were verified by validating that the tcg ops generated by those instructions remain the same, which were captured using the '-d in_asm,op' flag.

---
 target/ppc/helper.h                        |   6 +-
 target/ppc/insn32.decode                   |  16 +++
 target/ppc/excp_helper.c                   |   4 +-
 target/ppc/int_helper.c                    |   2 +-
 target/ppc/translate.c                     | 133 +--------------------
 target/ppc/translate/fixedpoint-impl.c.inc | 123 +++++++++++++++++++
 6 files changed, 148 insertions(+), 136 deletions(-)
target/ppc/helper.h +3 -3
index e862bdceaf..05f7ab5f6e 100644
@@ -1,8 +1,8 @@
 DEF_HELPER_FLAGS_3(raise_exception_err, TCG_CALL_NO_WG, noreturn, env, i32, i32)
 DEF_HELPER_FLAGS_2(raise_exception, TCG_CALL_NO_WG, noreturn, env, i32)
-DEF_HELPER_FLAGS_4(tw, TCG_CALL_NO_WG, void, env, tl, tl, i32)
+DEF_HELPER_FLAGS_4(TW, TCG_CALL_NO_WG, void, env, tl, tl, i32)
 #if defined(TARGET_PPC64)
-DEF_HELPER_FLAGS_4(td, TCG_CALL_NO_WG, void, env, tl, tl, i32)
+DEF_HELPER_FLAGS_4(TD, TCG_CALL_NO_WG, void, env, tl, tl, i32)
 #endif
 DEF_HELPER_4(HASHST, void, env, tl, tl, tl)
 DEF_HELPER_4(HASHCHK, void, env, tl, tl, tl)
@@ -67,7 +67,7 @@ DEF_HELPER_FLAGS_2(PEXTD, TCG_CALL_NO_RWG_SE, i64, i64, i64)
 DEF_HELPER_FLAGS_1(CDTBCD, TCG_CALL_NO_RWG_SE, tl, tl)
 DEF_HELPER_FLAGS_1(CBCDTD, TCG_CALL_NO_RWG_SE, tl, tl)
 #if defined(TARGET_PPC64)
-DEF_HELPER_FLAGS_2(cmpeqb, TCG_CALL_NO_RWG_SE, i32, tl, tl)
+DEF_HELPER_FLAGS_2(CMPEQB, TCG_CALL_NO_RWG_SE, i32, tl, tl)
 DEF_HELPER_FLAGS_1(popcntw, TCG_CALL_NO_RWG_SE, tl, tl)
 DEF_HELPER_FLAGS_2(bpermd, TCG_CALL_NO_RWG_SE, i64, i64, i64)
 DEF_HELPER_3(srad, tl, env, tl, tl)
target/ppc/insn32.decode +16 -0
index 509961023b..80a7bb1872 100644
@@ -23,6 +23,9 @@
 &A_tb           frt frb rc:bool
 @A_tb           ...... frt:5 ..... frb:5 ..... ..... rc:1       &A_tb
 
+&A_tab_bc       rt ra rb bc
+@A_tab_bc       ...... rt:5 ra:5 rb:5 bc:5 ..... .              &A_tab_bc
+
 &D              rt ra si:int64_t
 @D              ...... rt:5 ra:5 si:s16                         &D
 
@@ -331,6 +334,19 @@ CMP             011111 ... - . ..... ..... 0000000000 - @X_bfl
 CMPL            011111 ... - . ..... ..... 0000100000 - @X_bfl
 CMPI            001011 ... - . ..... ................   @D_bfs
 CMPLI           001010 ... - . ..... ................   @D_bfu
+CMPRB           011111 ... - . ..... ..... 0011000000 - @X_bfl
+CMPEQB          011111 ... -- ..... ..... 0011100000 -  @X_bf
+
+### Fixed-Point Trap Instructions
+
+TW              011111 ..... ..... ..... 0000000100 -   @X
+TD              011111 ..... ..... ..... 0001000100 -   @X
+TWI             000011 ..... ..... ................     @D
+TDI             000010 ..... ..... ................     @D
+
+### Fixed-Point Select Instruction
+
+ISEL            011111 ..... ..... ..... ..... 01111 -  @A_tab_bc
 
 ### Fixed-Point Arithmetic Instructions
 
target/ppc/excp_helper.c +2 -2
index 674c05a2ce..79dd9b82cf 100644
@@ -2750,7 +2750,7 @@ void helper_rfmci(CPUPPCState *env)
 }
 #endif /* !CONFIG_USER_ONLY */
 
-void helper_tw(CPUPPCState *env, target_ulong arg1, target_ulong arg2,
+void helper_TW(CPUPPCState *env, target_ulong arg1, target_ulong arg2,
                uint32_t flags)
 {
     if (!likely(!(((int32_t)arg1 < (int32_t)arg2 && (flags & 0x10)) ||
@@ -2764,7 +2764,7 @@ void helper_tw(CPUPPCState *env, target_ulong arg1, target_ulong arg2,
 }
 
 #ifdef TARGET_PPC64
-void helper_td(CPUPPCState *env, target_ulong arg1, target_ulong arg2,
+void helper_TD(CPUPPCState *env, target_ulong arg1, target_ulong arg2,
                uint32_t flags)
 {
     if (!likely(!(((int64_t)arg1 < (int64_t)arg2 && (flags & 0x10)) ||
target/ppc/int_helper.c +1 -1
index 585c2b65d3..d12dcc28e1 100644
@@ -159,7 +159,7 @@ uint64_t helper_DIVDE(CPUPPCState *env, uint64_t rau, uint64_t rbu, uint32_t oe)
 /* When you XOR the pattern and there is a match, that byte will be zero */
 #define hasvalue(x, n)  (haszero((x) ^ pattern(n)))
 
-uint32_t helper_cmpeqb(target_ulong ra, target_ulong rb)
+uint32_t helper_CMPEQB(target_ulong ra, target_ulong rb)
 {
     return hasvalue(rb, ra) ? CRF_GT : 0;
 }
target/ppc/translate.c +3 -130

169 lines not on this page · raw message

target/ppc/translate/fixedpoint-impl.c.inc +123 -0

135 lines not on this page · raw message

Signature · 1 line
2.39.3
Reviewed-by on v1 7/8
#22 lore raw

Re: [PATCH 7/8] target/ppc: Move cmp{rb, eqb}, tw[i], td[i], isel instructions to decodetree.

Quoted 10 lines · Chinmay Rath

Moving the following instructions to decodetree specification :

	cmp{rb, eqb}, t{w, d}	: X-form
	t{w, d}i		: D-form
	isel			: A-form

The changes were verified by validating that the tcg ops generated by those instructions remain the same, which were captured using the '-d in_asm,op' flag.

A faithful reorg of the existing code, so,

Notes for improvement:

Quoted 6 lines
target/ppc/translate/fixedpoint-impl.c.inc +6 -0
+static bool trans_CMPRB(DisasContext *ctx, arg_CMPRB *a)
+{
+    TCGv_i32 src1 = tcg_temp_new_i32();
+    TCGv_i32 src2 = tcg_temp_new_i32();
+    TCGv_i32 src2lo = tcg_temp_new_i32();
+    TCGv_i32 src2hi = tcg_temp_new_i32();

target/ppc/translate/fixedpoint-impl.c.inc TRANS(CMPL, do_cmp_X, false); · line 307

Quoted 10 lines
target/ppc/translate/fixedpoint-impl.c.inc +10 -0
+    TCGv_i32 crf = cpu_crf[a->bf];
+
+    REQUIRE_INSNS_FLAGS2(ctx, ISA300);
+    tcg_gen_trunc_tl_i32(src1, cpu_gpr[a->ra]);
+    tcg_gen_trunc_tl_i32(src2, cpu_gpr[a->rb]);
+
+    tcg_gen_andi_i32(src1, src1, 0xFF);
+    tcg_gen_ext8u_i32(src2lo, src2);
+    tcg_gen_shri_i32(src2, src2, 8);
+    tcg_gen_ext8u_i32(src2hi, src2);

tcg_gen_extract_i32(src2hi, src2, 8, 8);

target/ppc/translate/fixedpoint-impl.c.inc TRANS(CMPL, do_cmp_X, false); · line 315

Quoted 8 lines
target/ppc/translate/fixedpoint-impl.c.inc +8 -0
+
+    tcg_gen_setcond_i32(TCG_COND_LEU, src2lo, src2lo, src1);
+    tcg_gen_setcond_i32(TCG_COND_LEU, src2hi, src1, src2hi);
+    tcg_gen_and_i32(crf, src2lo, src2hi);
+
+    if (a->l) {
+        tcg_gen_shri_i32(src2, src2, 8);
+        tcg_gen_ext8u_i32(src2lo, src2);

tcg_gen_extract_i32(src2lo, src2, 16, 8);

Review

Quoted 2 lines
(quoted diff) +2 -0
+        tcg_gen_shri_i32(src2, src2, 8);
+        tcg_gen_ext8u_i32(src2hi, src2);

tcg_gen_extract_i32(src2hi, src2, 24, 8);

Quoted 47 lines
target/ppc/translate/fixedpoint-impl.c.inc +47 -0
+/*
+ * Fixed-Point Trap Instructions
+ */
+
+static bool trans_TW(DisasContext *ctx, arg_TW *a)
+{
+    TCGv_i32 t0;
+
+    if (check_unconditional_trap(ctx, a->rt)) {
+        return true;
+    }
+    t0 = tcg_constant_i32(a->rt);
+    gen_helper_TW(tcg_env, cpu_gpr[a->ra], cpu_gpr[a->rb], t0);
+    return true;
+}
+
+static bool trans_TWI(DisasContext *ctx, arg_TWI *a)
+{
+    TCGv t0;
+    TCGv_i32 t1;
+
+    if (check_unconditional_trap(ctx, a->rt)) {
+        return true;
+    }
+    t0 = tcg_constant_tl(a->si);
+    t1 = tcg_constant_i32(a->rt);
+    gen_helper_TW(tcg_env, cpu_gpr[a->ra], t0, t1);
+    return true;
+}
+
+static bool trans_TD(DisasContext *ctx, arg_TD *a)
+{
+    TCGv_i32 t0;
+
+    REQUIRE_64BIT(ctx);
+    if (check_unconditional_trap(ctx, a->rt)) {
+        return true;
+    }
+    t0 = tcg_constant_i32(a->rt);
+    gen_helper_TD(tcg_env, cpu_gpr[a->ra], cpu_gpr[a->rb], t0);
+    return true;
+}
+
+static bool trans_TDI(DisasContext *ctx, arg_TDI *a)
+{
+    TCGv t0;
+    TCGv_i32 t1;

target/ppc/translate/fixedpoint-impl.c.inc TRANS64(DIVDEU, do_dive, gen_helper_DIVDEU); · line 766

Quoted 10 lines
target/ppc/translate/fixedpoint-impl.c.inc +10 -0
+
+    REQUIRE_64BIT(ctx);
+    if (check_unconditional_trap(ctx, a->rt)) {
+        return true;
+    }
+    t0 = tcg_constant_tl(a->si);
+    t1 = tcg_constant_i32(a->rt);
+    gen_helper_TD(tcg_env, cpu_gpr[a->ra], t0, t1);
+    return true;
+}

See target/sparc/translate.c, delay_exception, for a method of implementing compare-and-trap inline with no inline branch penalty.

static void do_conditional_trap(DisasContext *ctx, unsigned to, TCGv a, TCGv b)

{
    static const TCGCond ucond[8] = {
        TCG_COND_NEVER, TCG_COND_GTU, TCG_COND_LTU, TCG_COND_NE,
        TCG_COND_EQ,    TCG_COND_GEU, TCG_COND_LEU, TCG_COND_ALWAYS,
    };
    static const TCGCond scond[8] = {
        TCG_COND_NEVER, TCG_COND_EQ,  TCG_COND_GT,  TCG_COND_GE,
        TCG_COND_LT,    TCG_COND_LE,  TCG_COND_NE,  TCG_COND_ALWAYS,
    };

    TCGCond uc = ucond[to & 7];
    TCGCond sc = scond[to >> 2];

    /* There is overlap with EQ; we may not need both comparisons. */
    if (!(to & 0x18)) {
        sc = TCG_COND_NEVER;
    } else if (!(to & 0x03)) {
        uc = TCG_COND_NEVER;
    }

    if (uc == TCG_COND_ALWAYS || sc == TCG_COND_ALWAYS) {
        unconditional trap;
        return true;
    }
    if (uc == TCG_COND_NEVER && sc == TCG_COND_NEVER) {
        return true;
    }

    e = delay_exception(ctx, POWERPC_EXCP_TRAP);

    if (uc != TCG_COND_NEVER) {
        tcg_gen_brcond_tl(uc, a, b, e->lab);
    }
    if (sc != TCG_COND_NEVER) {
        tcg_gen_brcond_tl(sc, a, b, e->lab);
    }
    return true;
}

bool trans_TW(...)

{
    TCGv a = tcg_temp_new();
    TCGv b = tcg_temp_new();

    /* Note that consistent sign extensions work for unsigned comparisons. */
    tcg_gen_exts_i32_tl(a, ra);
    tcg_gen_exts_i32_tl(b, rb);
    return do_conditional_trap(ctx, to, a, b);
}

etc.

r~

#23 lore raw

Re: [PATCH 7/8] target/ppc: Move cmp{rb, eqb}, tw[i], td[i], isel instructions to decodetree.

Hi Richard,

Quoted 7 lines · Richard Henderson
Quoted 6 lines · Chinmay Rath

Moving the following instructions to decodetree specification :

    cmp{rb, eqb}, t{w, d}    : X-form
    t{w, d}i        : D-form
    isel            : A-form

Quoted 8 lines
Quoted 4 lines

The changes were verified by validating that the tcg ops generated by those instructions remain the same, which were captured using the '-d in_asm,op' flag.

A faithful reorg of the existing code, so,

Thank you.

Quoted 32 lines

Notes for improvement:

Quoted 6 lines
target/ppc/translate/fixedpoint-impl.c.inc +6 -0
+static bool trans_CMPRB(DisasContext *ctx, arg_CMPRB *a)
+{
+    TCGv_i32 src1 = tcg_temp_new_i32();
+    TCGv_i32 src2 = tcg_temp_new_i32();
+    TCGv_i32 src2lo = tcg_temp_new_i32();
+    TCGv_i32 src2hi = tcg_temp_new_i32();

target/ppc/translate/fixedpoint-impl.c.inc TRANS(CMPL, do_cmp_X, false); · line 307

Quoted 10 lines
target/ppc/translate/fixedpoint-impl.c.inc +10 -0
+    TCGv_i32 crf = cpu_crf[a->bf];
+
+    REQUIRE_INSNS_FLAGS2(ctx, ISA300);
+    tcg_gen_trunc_tl_i32(src1, cpu_gpr[a->ra]);
+    tcg_gen_trunc_tl_i32(src2, cpu_gpr[a->rb]);
+
+    tcg_gen_andi_i32(src1, src1, 0xFF);
+    tcg_gen_ext8u_i32(src2lo, src2);
+    tcg_gen_shri_i32(src2, src2, 8);
+    tcg_gen_ext8u_i32(src2hi, src2);

tcg_gen_extract_i32(src2hi, src2, 8, 8);

target/ppc/translate/fixedpoint-impl.c.inc TRANS(CMPL, do_cmp_X, false); · line 315

Quoted 8 lines
target/ppc/translate/fixedpoint-impl.c.inc +8 -0
+
+    tcg_gen_setcond_i32(TCG_COND_LEU, src2lo, src2lo, src1);
+    tcg_gen_setcond_i32(TCG_COND_LEU, src2hi, src1, src2hi);
+    tcg_gen_and_i32(crf, src2lo, src2hi);
+
+    if (a->l) {
+        tcg_gen_shri_i32(src2, src2, 8);
+        tcg_gen_ext8u_i32(src2lo, src2);

tcg_gen_extract_i32(src2lo, src2, 16, 8);

Quoted 5 lines
Quoted 2 lines

+        tcg_gen_shri_i32(src2, src2, 8);
+        tcg_gen_ext8u_i32(src2hi, src2);

tcg_gen_extract_i32(src2hi, src2, 24, 8);

Will update the above in v2.

Will implement the below improvements for trap insns as a separate patch later.

Quoted 105 lines
Quoted 47 lines
target/ppc/translate/fixedpoint-impl.c.inc +47 -0
+/*
+ * Fixed-Point Trap Instructions
+ */
+
+static bool trans_TW(DisasContext *ctx, arg_TW *a)
+{
+    TCGv_i32 t0;
+
+    if (check_unconditional_trap(ctx, a->rt)) {
+        return true;
+    }
+    t0 = tcg_constant_i32(a->rt);
+    gen_helper_TW(tcg_env, cpu_gpr[a->ra], cpu_gpr[a->rb], t0);
+    return true;
+}
+
+static bool trans_TWI(DisasContext *ctx, arg_TWI *a)
+{
+    TCGv t0;
+    TCGv_i32 t1;
+
+    if (check_unconditional_trap(ctx, a->rt)) {
+        return true;
+    }
+    t0 = tcg_constant_tl(a->si);
+    t1 = tcg_constant_i32(a->rt);
+    gen_helper_TW(tcg_env, cpu_gpr[a->ra], t0, t1);
+    return true;
+}
+
+static bool trans_TD(DisasContext *ctx, arg_TD *a)
+{
+    TCGv_i32 t0;
+
+    REQUIRE_64BIT(ctx);
+    if (check_unconditional_trap(ctx, a->rt)) {
+        return true;
+    }
+    t0 = tcg_constant_i32(a->rt);
+    gen_helper_TD(tcg_env, cpu_gpr[a->ra], cpu_gpr[a->rb], t0);
+    return true;
+}
+
+static bool trans_TDI(DisasContext *ctx, arg_TDI *a)
+{
+    TCGv t0;
+    TCGv_i32 t1;

target/ppc/translate/fixedpoint-impl.c.inc TRANS64(DIVDEU, do_dive, gen_helper_DIVDEU); · line 766

Quoted 10 lines
target/ppc/translate/fixedpoint-impl.c.inc +10 -0
+
+    REQUIRE_64BIT(ctx);
+    if (check_unconditional_trap(ctx, a->rt)) {
+        return true;
+    }
+    t0 = tcg_constant_tl(a->si);
+    t1 = tcg_constant_i32(a->rt);
+    gen_helper_TD(tcg_env, cpu_gpr[a->ra], t0, t1);
+    return true;
+}

See target/sparc/translate.c, delay_exception, for a method of implementing compare-and-trap inline with no inline branch penalty.

static void do_conditional_trap(DisasContext *ctx, unsigned to, TCGv a, TCGv b) {
    static const TCGCond ucond[8] = {
        TCG_COND_NEVER, TCG_COND_GTU, TCG_COND_LTU, TCG_COND_NE, TCG_COND_EQ,    TCG_COND_GEU, TCG_COND_LEU, TCG_COND_ALWAYS, };
    static const TCGCond scond[8] = {
        TCG_COND_NEVER, TCG_COND_EQ,  TCG_COND_GT,  TCG_COND_GE, TCG_COND_LT,    TCG_COND_LE,  TCG_COND_NE, TCG_COND_ALWAYS, };

    TCGCond uc = ucond[to & 7];
    TCGCond sc = scond[to >> 2];

    /* There is overlap with EQ; we may not need both comparisons. */ if (!(to & 0x18)) {
        sc = TCG_COND_NEVER;
    } else if (!(to & 0x03)) {
        uc = TCG_COND_NEVER;
    }

    if (uc == TCG_COND_ALWAYS || sc == TCG_COND_ALWAYS) { unconditional trap;
        return true;
    }
    if (uc == TCG_COND_NEVER && sc == TCG_COND_NEVER) { return true;
    }

    e = delay_exception(ctx, POWERPC_EXCP_TRAP);

    if (uc != TCG_COND_NEVER) {
        tcg_gen_brcond_tl(uc, a, b, e->lab);
    }
    if (sc != TCG_COND_NEVER) {
        tcg_gen_brcond_tl(sc, a, b, e->lab);
    }
    return true;
}

bool trans_TW(...)
{
    TCGv a = tcg_temp_new();
    TCGv b = tcg_temp_new();

Quoted 9 lines

    /* Note that consistent sign extensions work for unsigned comparisons. */ tcg_gen_exts_i32_tl(a, ra);
    tcg_gen_exts_i32_tl(b, rb);
    return do_conditional_trap(ctx, to, a, b);
}

etc.

Thanks,
Chinmay

Quoted 1 line

r~

#24 lore raw

PATCH 8/8 target/ppc: Move logical fixed-point instructions to decodetree.

In reply to Chinmay Rath

Moving the below instructions to decodetree specification :

	andi[s]., {ori, xori}[s]			: D-form

	{and, andc, nand, or, orc, nor, xor, eqv}[.],
	exts{b, h, w}[.],  cnt{l, t}z{w, d}[.],
	popcnt{b, w, d},  prty{w, d}, cmp, bpermd	: X-form

With this patch, all the fixed-point logical instructions have been moved to decodetree.
The changes were verified by validating that the tcg ops generated by those instructions remain the same, which were captured with the '-d in_asm,op' flag.

---
 target/ppc/helper.h                        |   8 +-
 target/ppc/insn32.decode                   |  38 +++
 target/ppc/int_helper.c                    |  10 +-
 target/ppc/translate.c                     | 359 ---------------------
 target/ppc/translate/fixedpoint-impl.c.inc | 269 +++++++++++++++
 5 files changed, 316 insertions(+), 368 deletions(-)
target/ppc/helper.h +4 -4
index 05f7ab5f6e..b53abd853a 100644
@@ -58,8 +58,8 @@ DEF_HELPER_4(DIVDE, i64, env, i64, i64, i32)
 DEF_HELPER_4(DIVWEU, tl, env, tl, tl, i32)
 DEF_HELPER_4(DIVWE, tl, env, tl, tl, i32)
 
-DEF_HELPER_FLAGS_1(popcntb, TCG_CALL_NO_RWG_SE, tl, tl)
-DEF_HELPER_FLAGS_2(cmpb, TCG_CALL_NO_RWG_SE, tl, tl, tl)
+DEF_HELPER_FLAGS_1(POPCNTB, TCG_CALL_NO_RWG_SE, tl, tl)
+DEF_HELPER_FLAGS_2(CMPB, TCG_CALL_NO_RWG_SE, tl, tl, tl)
 DEF_HELPER_3(sraw, tl, env, tl, tl)
 DEF_HELPER_FLAGS_2(CFUGED, TCG_CALL_NO_RWG_SE, i64, i64, i64)
 DEF_HELPER_FLAGS_2(PDEPD, TCG_CALL_NO_RWG_SE, i64, i64, i64)
@@ -68,8 +68,8 @@ DEF_HELPER_FLAGS_1(CDTBCD, TCG_CALL_NO_RWG_SE, tl, tl)
 DEF_HELPER_FLAGS_1(CBCDTD, TCG_CALL_NO_RWG_SE, tl, tl)
 #if defined(TARGET_PPC64)
 DEF_HELPER_FLAGS_2(CMPEQB, TCG_CALL_NO_RWG_SE, i32, tl, tl)
-DEF_HELPER_FLAGS_1(popcntw, TCG_CALL_NO_RWG_SE, tl, tl)
-DEF_HELPER_FLAGS_2(bpermd, TCG_CALL_NO_RWG_SE, i64, i64, i64)
+DEF_HELPER_FLAGS_1(POPCNTW, TCG_CALL_NO_RWG_SE, tl, tl)
+DEF_HELPER_FLAGS_2(BPERMD, TCG_CALL_NO_RWG_SE, i64, i64, i64)
 DEF_HELPER_3(srad, tl, env, tl, tl)
 DEF_HELPER_FLAGS_0(DARN32, TCG_CALL_NO_RWG, tl)
 DEF_HELPER_FLAGS_0(DARN64, TCG_CALL_NO_RWG, tl)
target/ppc/insn32.decode +38 -0
index 80a7bb1872..3175810190 100644
@@ -29,6 +29,9 @@
 &D              rt ra si:int64_t
 @D              ...... rt:5 ra:5 si:s16                         &D
 
+&D_ui           rt ra ui:uint64_t
+@D_ui           ...... rt:5 ra:5 ui:16                         &D_ui
+
 &D_bf           bf l:bool ra imm
 @D_bfs          ...... bf:3 . l:1 ra:5 imm:s16                  &D_bf
 @D_bfu          ...... bf:3 . l:1 ra:5 imm:16                   &D_bf
@@ -96,6 +99,9 @@
 &X_sa           rs ra
 @X_sa           ...... rs:5 ra:5 ..... .......... .             &X_sa
 
+&X_sa_rc        rs ra rc
+@X_sa_rc        ...... rs:5 ra:5 ..... .......... rc:1          &X_sa_rc
+
 %x_frtp         22:4 !function=times_2
 %x_frap         17:4 !function=times_2
 %x_frbp         12:4 !function=times_2
@@ -410,6 +416,38 @@ MODUD           011111 ..... ..... ..... 0100001001 -   @X
 
 ## Fixed-Point Logical Instructions
 
+ANDI_           011100 ..... ..... ................     @D_ui
+ANDIS_          011101 ..... ..... ................     @D_ui
+ORI             011000 ..... ..... ................     @D_ui
+ORIS            011001 ..... ..... ................     @D_ui
+XORI            011010 ..... ..... ................     @D_ui
+XORIS           011011 ..... ..... ................     @D_ui
+
+AND             011111 ..... ..... ..... 0000011100 .   @X_rc
+ANDC            011111 ..... ..... ..... 0000111100 .   @X_rc
+NAND            011111 ..... ..... ..... 0111011100 .   @X_rc
+OR              011111 ..... ..... ..... 0110111100 .   @X_rc
+ORC             011111 ..... ..... ..... 0110011100 .   @X_rc
+NOR             011111 ..... ..... ..... 0001111100 .   @X_rc
+XOR             011111 ..... ..... ..... 0100111100 .   @X_rc
+EQV             011111 ..... ..... ..... 0100011100 .   @X_rc
+CMPB            011111 ..... ..... ..... 0111111100 .   @X_rc
+
+EXTSB           011111 ..... ..... ----- 1110111010 .   @X_sa_rc
+EXTSH           011111 ..... ..... ----- 1110011010 .   @X_sa_rc
+EXTSW           011111 ..... ..... ----- 1111011010 .   @X_sa_rc
+CNTLZW          011111 ..... ..... ----- 0000011010 .   @X_sa_rc
+CNTTZW          011111 ..... ..... ----- 1000011010 .   @X_sa_rc
+CNTLZD          011111 ..... ..... ----- 0000111010 .   @X_sa_rc
+CNTTZD          011111 ..... ..... ----- 1000111010 .   @X_sa_rc
+POPCNTB         011111 ..... ..... ----- 0001111010 .   @X_sa_rc
+
+POPCNTW         011111 ..... ..... ----- 0101111010 -   @X_sa
+POPCNTD         011111 ..... ..... ----- 0111111010 -   @X_sa
+PRTYW           011111 ..... ..... ----- 0010011010 -   @X_sa
+PRTYD           011111 ..... ..... ----- 0010111010 -   @X_sa
+
+BPERMD          011111 ..... ..... ..... 0011111100 -   @X
 CFUGED          011111 ..... ..... ..... 0011011100 -   @X
 CNTLZDM         011111 ..... ..... ..... 0000111011 -   @X
 CNTTZDM         011111 ..... ..... ..... 1000111011 -   @X
target/ppc/int_helper.c +5 -5
index d12dcc28e1..2c6b633d65 100644
@@ -201,7 +201,7 @@ uint64_t helper_DARN64(void)
     return ret;
 }
 
-uint64_t helper_bpermd(uint64_t rs, uint64_t rb)
+uint64_t helper_BPERMD(uint64_t rs, uint64_t rb)
 {
     int i;
     uint64_t ra = 0;
@@ -219,7 +219,7 @@ uint64_t helper_bpermd(uint64_t rs, uint64_t rb)
 
 #endif
 
-target_ulong helper_cmpb(target_ulong rs, target_ulong rb)
+target_ulong helper_CMPB(target_ulong rs, target_ulong rb)
 {
     target_ulong mask = 0xff;
     target_ulong ra = 0;
@@ -288,7 +288,7 @@ target_ulong helper_srad(CPUPPCState *env, target_ulong value,
 #endif
 
 #if defined(TARGET_PPC64)
-target_ulong helper_popcntb(target_ulong val)
+target_ulong helper_POPCNTB(target_ulong val)
 {
     /* Note that we don't fold past bytes */
     val = (val & 0x5555555555555555ULL) + ((val >>  1) &
@@ -300,7 +300,7 @@ target_ulong helper_popcntb(target_ulong val)
     return val;
 }
 
-target_ulong helper_popcntw(target_ulong val)
+target_ulong helper_POPCNTW(target_ulong val)
 {
     /* Note that we don't fold past words.  */
     val = (val & 0x5555555555555555ULL) + ((val >>  1) &
@@ -316,7 +316,7 @@ target_ulong helper_popcntw(target_ulong val)
     return val;
 }
 #else
-target_ulong helper_popcntb(target_ulong val)
+target_ulong helper_POPCNTB(target_ulong val)
 {
     /* Note that we don't fold past bytes */
     val = (val & 0x55555555) + ((val >>  1) & 0x55555555);
target/ppc/translate.c +0 -359

392 lines not on this page · raw message

target/ppc/translate/fixedpoint-impl.c.inc +269 -0

281 lines not on this page · raw message

Signature · 1 line
2.39.3
Reviewed-by on v1 8/8
#25 lore raw

Re: [PATCH 8/8] target/ppc: Move logical fixed-point instructions to decodetree.

Quoted 13 lines · Chinmay Rath

Moving the below instructions to decodetree specification :

	andi[s]., {ori, xori}[s]			: D-form

	{and, andc, nand, or, orc, nor, xor, eqv}[.],
	exts{b, h, w}[.],  cnt{l, t}z{w, d}[.],
	popcnt{b, w, d},  prty{w, d}, cmp, bpermd	: X-form

With this patch, all the fixed-point logical instructions have been moved to decodetree.
The changes were verified by validating that the tcg ops generated by those instructions remain the same, which were captured with the '-d in_asm,op' flag.

Quoted 8 lines
---
  target/ppc/helper.h                        |   8 +-
  target/ppc/insn32.decode                   |  38 +++
  target/ppc/int_helper.c                    |  10 +-
  target/ppc/translate.c                     | 359 ---------------------
  target/ppc/translate/fixedpoint-impl.c.inc | 269 +++++++++++++++
  5 files changed, 316 insertions(+), 368 deletions(-)

r~

#26 lore raw

Re: [PATCH 8/8] target/ppc: Move logical fixed-point instructions to decodetree.

Quoted 23 lines · Richard Henderson
Quoted 13 lines · Chinmay Rath

Moving the below instructions to decodetree specification :

    andi[s]., {ori, xori}[s]            : D-form

    {and, andc, nand, or, orc, nor, xor, eqv}[.], exts{b, h, w}[.],  cnt{l, t}z{w, d}[.], popcnt{b, w, d},  prty{w, d}, cmp, bpermd    : X-form

With this patch, all the fixed-point logical instructions have been moved to decodetree.
The changes were verified by validating that the tcg ops generated by those instructions remain the same, which were captured with the '-d in_asm,op' flag.

Quoted 8 lines

---
  target/ppc/helper.h                        |   8 +- target/ppc/insn32.decode                   |  38 +++ target/ppc/int_helper.c                    |  10 +- target/ppc/translate.c                     | 359 --------------------- target/ppc/translate/fixedpoint-impl.c.inc | 269 +++++++++++++++

  5 files changed, 316 insertions(+), 368 deletions(-)
Quoted 1 line

Thanks,
Chinmay

Quoted 3 lines

r~