Skip to contentSkip to conversation

target/ppc: Move VMX int add/sub saturate insns to decodetree.

PATCH Superseded Chinmay Rath 3 participants 6 messages May 12, 2024 – May 16, 2024

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

Moving the following instructions to decodetree :
v{add,sub}{u,s}{b,h,w}s : VX-form

However, the following instructions were paired using the GEN_VXFORM_DUAL macros in the vmx-impl and vmx-ops files :

vaddubs and vmul10uq
vadduhs and vmul10euq
vaddshs and bcdcpsgn
vsububs and bcdadd
vsubuhs and bcdsub
vsubsbs and bcdtrunc
vsubsws and xpnd04_2

Out of those 7 above mentioned pairs, I have moved the first one of each pair and added respective entry of the 2nd one in the vmx-ops file. However, I lack some clarity on those flag checks added for those insns in the ops file. It would be great if someone sheds some light at this.

The issue; let's take the following example :

1. vsubsbs and bcdtrunc :

In this pair, bcdtrunc has the insn flag check PPC2_ISA300 in the vmx-impl file, within the GEN_VXFORM_DUAL macro, which does this flag check.
However it also has this flag check in the vmx-ops file. Hence I have retained the same in the new entry in the vmx-ops file. This is consistent with the behaviour in done in the following commit :
https://github.com/qemu/qemu/commit/b132be53a4ba6a0a40d5643d791822f958a36e53
So even though the flag check is removed from the vmx-impl file, it is retained in the vmx-ops file. All good here.

2. vadduhs and vmul10euq :

In this pair, vmul10euq has the insn flag check PPC2_ISA300 in the vmx-impl file, check done within the GEN_VXFORM_DUAL macro. However the same flag was NOT originally present in the vmx-ops file, so I have NOT included in its new entry in the vmx-ops file. I have done this, following the behaviour done in the following commit :
https://github.com/qemu/qemu/commit/c85929b2ddf6bbad737635c9b85213007ec043af
So this flag check for vmul10euq is excluded now. Is this not a problem ? I feel that this leads to the flag check being skipped now, however this behaviour was followed in the above mentioned commit.

Requesting anyone to please let me know why this behaviour was followed and how the flag checks are retained here, or if they are really skipped, why is it okay to skip them here ?

Regards,
Chinmay

Chinmay Rath (1):
target/ppc: Move VMX integer add/sub saturate insns to decodetree.

 target/ppc/helper.h                 |  24 +--
 target/ppc/insn32.decode            |  16 ++
 target/ppc/int_helper.c             |  22 +--
 target/ppc/translate/vmx-impl.c.inc | 242 ++++++++++++++++++++--------
 target/ppc/translate/vmx-ops.c.inc  |  19 +--
 5 files changed, 224 insertions(+), 99 deletions(-)
Signature · 1 line
2.39.3
#1 lore raw

PATCH 1/1 target/ppc: Move VMX integer add/sub saturate insns to decodetree.

Moving the following instructions to decodetree specification :

	v{add,sub}{u,s}{b,h,w}s		: VX-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                 |  24 +--
 target/ppc/insn32.decode            |  16 ++
 target/ppc/int_helper.c             |  22 +--
 target/ppc/translate/vmx-impl.c.inc | 242 ++++++++++++++++++++--------
 target/ppc/translate/vmx-ops.c.inc  |  19 +--
 5 files changed, 224 insertions(+), 99 deletions(-)
target/ppc/helper.h +12 -12
index f397ef459a..2963e48fdc 100644
@@ -200,18 +200,18 @@ DEF_HELPER_FLAGS_3(vsro, TCG_CALL_NO_RWG, void, avr, avr, avr)
 DEF_HELPER_FLAGS_3(vsrv, TCG_CALL_NO_RWG, void, avr, avr, avr)
 DEF_HELPER_FLAGS_3(vslv, TCG_CALL_NO_RWG, void, avr, avr, avr)
 DEF_HELPER_FLAGS_3(VPRTYBQ, TCG_CALL_NO_RWG, void, avr, avr, i32)
-DEF_HELPER_FLAGS_5(vaddsbs, TCG_CALL_NO_RWG, void, avr, avr, avr, avr, i32)
-DEF_HELPER_FLAGS_5(vaddshs, TCG_CALL_NO_RWG, void, avr, avr, avr, avr, i32)
-DEF_HELPER_FLAGS_5(vaddsws, TCG_CALL_NO_RWG, void, avr, avr, avr, avr, i32)
-DEF_HELPER_FLAGS_5(vsubsbs, TCG_CALL_NO_RWG, void, avr, avr, avr, avr, i32)
-DEF_HELPER_FLAGS_5(vsubshs, TCG_CALL_NO_RWG, void, avr, avr, avr, avr, i32)
-DEF_HELPER_FLAGS_5(vsubsws, TCG_CALL_NO_RWG, void, avr, avr, avr, avr, i32)
-DEF_HELPER_FLAGS_5(vaddubs, TCG_CALL_NO_RWG, void, avr, avr, avr, avr, i32)
-DEF_HELPER_FLAGS_5(vadduhs, TCG_CALL_NO_RWG, void, avr, avr, avr, avr, i32)
-DEF_HELPER_FLAGS_5(vadduws, TCG_CALL_NO_RWG, void, avr, avr, avr, avr, i32)
-DEF_HELPER_FLAGS_5(vsububs, TCG_CALL_NO_RWG, void, avr, avr, avr, avr, i32)
-DEF_HELPER_FLAGS_5(vsubuhs, TCG_CALL_NO_RWG, void, avr, avr, avr, avr, i32)
-DEF_HELPER_FLAGS_5(vsubuws, TCG_CALL_NO_RWG, void, avr, avr, avr, avr, i32)
+DEF_HELPER_FLAGS_5(VADDSBS, TCG_CALL_NO_RWG, void, avr, avr, avr, avr, i32)
+DEF_HELPER_FLAGS_5(VADDSHS, TCG_CALL_NO_RWG, void, avr, avr, avr, avr, i32)
+DEF_HELPER_FLAGS_5(VADDSWS, TCG_CALL_NO_RWG, void, avr, avr, avr, avr, i32)
+DEF_HELPER_FLAGS_5(VSUBSBS, TCG_CALL_NO_RWG, void, avr, avr, avr, avr, i32)
+DEF_HELPER_FLAGS_5(VSUBSHS, TCG_CALL_NO_RWG, void, avr, avr, avr, avr, i32)
+DEF_HELPER_FLAGS_5(VSUBSWS, TCG_CALL_NO_RWG, void, avr, avr, avr, avr, i32)
+DEF_HELPER_FLAGS_5(VADDUBS, TCG_CALL_NO_RWG, void, avr, avr, avr, avr, i32)
+DEF_HELPER_FLAGS_5(VADDUHS, TCG_CALL_NO_RWG, void, avr, avr, avr, avr, i32)
+DEF_HELPER_FLAGS_5(VADDUWS, TCG_CALL_NO_RWG, void, avr, avr, avr, avr, i32)
+DEF_HELPER_FLAGS_5(VSUBUBS, TCG_CALL_NO_RWG, void, avr, avr, avr, avr, i32)
+DEF_HELPER_FLAGS_5(VSUBUHS, TCG_CALL_NO_RWG, void, avr, avr, avr, avr, i32)
+DEF_HELPER_FLAGS_5(VSUBUWS, TCG_CALL_NO_RWG, void, avr, avr, avr, avr, i32)
 DEF_HELPER_FLAGS_3(VADDUQM, TCG_CALL_NO_RWG, void, avr, avr, avr)
 DEF_HELPER_FLAGS_4(VADDECUQ, TCG_CALL_NO_RWG, void, avr, avr, avr, avr)
 DEF_HELPER_FLAGS_4(VADDEUQM, TCG_CALL_NO_RWG, void, avr, avr, avr, avr)
target/ppc/insn32.decode +16 -0
index 847a2f4356..d7d77eaa99 100644
@@ -697,6 +697,14 @@ VADDCUW         000100 ..... ..... ..... 00110000000    @VX
 VADDCUQ         000100 ..... ..... ..... 00101000000    @VX
 VADDUQM         000100 ..... ..... ..... 00100000000    @VX
 
+VADDSBS         000100 ..... ..... ..... 01100000000    @VX
+VADDSHS         000100 ..... ..... ..... 01101000000    @VX
+VADDSWS         000100 ..... ..... ..... 01110000000    @VX
+
+VADDUBS         000100 ..... ..... ..... 01000000000    @VX
+VADDUHS         000100 ..... ..... ..... 01001000000    @VX
+VADDUWS         000100 ..... ..... ..... 01010000000    @VX
+
 VADDEUQM        000100 ..... ..... ..... ..... 111100   @VA
 VADDECUQ        000100 ..... ..... ..... ..... 111101   @VA
 
@@ -704,6 +712,14 @@ VSUBCUW         000100 ..... ..... ..... 10110000000    @VX
 VSUBCUQ         000100 ..... ..... ..... 10101000000    @VX
 VSUBUQM         000100 ..... ..... ..... 10100000000    @VX
 
+VSUBSBS         000100 ..... ..... ..... 11100000000    @VX
+VSUBSHS         000100 ..... ..... ..... 11101000000    @VX
+VSUBSWS         000100 ..... ..... ..... 11110000000    @VX
+
+VSUBUBS         000100 ..... ..... ..... 11000000000    @VX
+VSUBUHS         000100 ..... ..... ..... 11001000000    @VX
+VSUBUWS         000100 ..... ..... ..... 11010000000    @VX
+
 VSUBECUQ        000100 ..... ..... ..... ..... 111111   @VA
 VSUBEUQM        000100 ..... ..... ..... ..... 111110   @VA
 
target/ppc/int_helper.c +11 -11
index 0a5c3e78a4..aec2d3d4ec 100644
@@ -541,7 +541,7 @@ VARITHFPFMA(nmsubfp, float_muladd_negate_result | float_muladd_negate_c);
     }
 
 #define VARITHSAT_DO(name, op, optype, cvt, element)                    \
-    void helper_v##name(ppc_avr_t *r, ppc_avr_t *vscr_sat,              \
+    void helper_V##name(ppc_avr_t *r, ppc_avr_t *vscr_sat,              \
                         ppc_avr_t *a, ppc_avr_t *b, uint32_t desc)      \
     {                                                                   \
         int sat = 0;                                                    \
@@ -555,17 +555,17 @@ VARITHFPFMA(nmsubfp, float_muladd_negate_result | float_muladd_negate_c);
         }                                                               \
     }
 #define VARITHSAT_SIGNED(suffix, element, optype, cvt)          \
-    VARITHSAT_DO(adds##suffix##s, +, optype, cvt, element)      \
-    VARITHSAT_DO(subs##suffix##s, -, optype, cvt, element)
+    VARITHSAT_DO(ADDS##suffix##S, +, optype, cvt, element)      \
+    VARITHSAT_DO(SUBS##suffix##S, -, optype, cvt, element)
 #define VARITHSAT_UNSIGNED(suffix, element, optype, cvt)        \
-    VARITHSAT_DO(addu##suffix##s, +, optype, cvt, element)      \
-    VARITHSAT_DO(subu##suffix##s, -, optype, cvt, element)
-VARITHSAT_SIGNED(b, s8, int16_t, cvtshsb)
-VARITHSAT_SIGNED(h, s16, int32_t, cvtswsh)
-VARITHSAT_SIGNED(w, s32, int64_t, cvtsdsw)
-VARITHSAT_UNSIGNED(b, u8, uint16_t, cvtshub)
-VARITHSAT_UNSIGNED(h, u16, uint32_t, cvtswuh)
-VARITHSAT_UNSIGNED(w, u32, uint64_t, cvtsduw)
+    VARITHSAT_DO(ADDU##suffix##S, +, optype, cvt, element)      \
+    VARITHSAT_DO(SUBU##suffix##S, -, optype, cvt, element)
+VARITHSAT_SIGNED(B, s8, int16_t, cvtshsb)
+VARITHSAT_SIGNED(H, s16, int32_t, cvtswsh)
+VARITHSAT_SIGNED(W, s32, int64_t, cvtsdsw)
+VARITHSAT_UNSIGNED(B, u8, uint16_t, cvtshub)
+VARITHSAT_UNSIGNED(H, u16, uint32_t, cvtswuh)
+VARITHSAT_UNSIGNED(W, u32, uint64_t, cvtsduw)
 #undef VARITHSAT_CASE
 #undef VARITHSAT_DO
 #undef VARITHSAT_SIGNED
target/ppc/translate/vmx-impl.c.inc +178 -64

268 lines not on this page · raw message

target/ppc/translate/vmx-ops.c.inc +7 -12
index 7bb11b0549..d890dcb0b4 100644
@@ -54,18 +54,13 @@ GEN_VXFORM(vsro, 6, 17),
 GEN_VXFORM(xpnd04_1, 0, 22),
 GEN_VXFORM_300(bcdsr, 0, 23),
 GEN_VXFORM_300(bcdsr, 0, 31),
-GEN_VXFORM_DUAL(vaddubs, vmul10uq, 0, 8, PPC_ALTIVEC, PPC_NONE),
-GEN_VXFORM_DUAL(vadduhs, vmul10euq, 0, 9, PPC_ALTIVEC, PPC_NONE),
-GEN_VXFORM(vadduws, 0, 10),
-GEN_VXFORM(vaddsbs, 0, 12),
-GEN_VXFORM_DUAL(vaddshs, bcdcpsgn, 0, 13, PPC_ALTIVEC, PPC_NONE),
-GEN_VXFORM(vaddsws, 0, 14),
-GEN_VXFORM_DUAL(vsububs, bcdadd, 0, 24, PPC_ALTIVEC, PPC_NONE),
-GEN_VXFORM_DUAL(vsubuhs, bcdsub, 0, 25, PPC_ALTIVEC, PPC_NONE),
-GEN_VXFORM(vsubuws, 0, 26),
-GEN_VXFORM_DUAL(vsubsbs, bcdtrunc, 0, 28, PPC_ALTIVEC, PPC2_ISA300),
-GEN_VXFORM(vsubshs, 0, 29),
-GEN_VXFORM_DUAL(vsubsws, xpnd04_2, 0, 30, PPC_ALTIVEC, PPC_NONE),
+GEN_HANDLER(vmul10uq, 0x04, 0, 8, 0x0000F800, PPC_ALTIVEC),
+GEN_VXFORM(vmul10euq, 0, 9),
+GEN_VXFORM(bcdcpsgn, 0, 13),
+GEN_VXFORM(bcdadd, 0, 24),
+GEN_VXFORM(bcdsub, 0, 25),
+GEN_VXFORM_300(bcdtrunc, 0, 28),
+GEN_VXFORM(xpnd04_2, 0, 30),
 GEN_VXFORM_300(bcdtrunc, 0, 20),
 GEN_VXFORM_300(bcdutrunc, 0, 21),
 GEN_VXFORM(vsl, 2, 7),
Signature · 1 line
2.39.3
#2 lore raw

Re: [PATCH 1/1] target/ppc: Move VMX integer add/sub saturate insns to decodetree.

Quoted 6 lines · Chinmay Rath
target/ppc/translate/vmx-impl.c.inc +2 -0
@@ -2934,6 +2870,184 @@ static bool do_vx_vaddsubcuw(DisasContext *ctx, arg_VX *a, int add)
      return true;
  }
 
+static inline void do_vadd_vsub_sat
+(

target/ppc/translate/vmx-impl.c.inc static bool do_vx_vaddsubcuw(DisasContext *ctx, arg_VX *a, int add) · line 2884

Quoted 10 lines
target/ppc/translate/vmx-impl.c.inc +10 -0
+    unsigned vece, TCGv_vec t, TCGv_vec sat, TCGv_vec a, TCGv_vec b,
+    void (*norm_op)(unsigned, TCGv_vec, TCGv_vec, TCGv_vec),
+    void (*sat_op)(unsigned, TCGv_vec, TCGv_vec, TCGv_vec))
+{
+    TCGv_vec x = tcg_temp_new_vec_matching(t);
+    norm_op(vece, x, a, b);
+    sat_op(vece, t, a, b);
+    tcg_gen_cmp_vec(TCG_COND_NE, vece, x, x, t);
+    tcg_gen_or_vec(vece, sat, sat, x);
+}

As a separate change, before or after, the cmp_vec may be simplified to xor_vec. Which means that INDEX_op_cmp_vec need not be probed in the vecop_lists. See

https://lore.kernel.org/qemu-devel/[email protected]/

which is performing the same operation on AArch64.

Quoted 108 lines
target/ppc/translate/vmx-impl.c.inc +108 -0
+static bool do_vx_vadd_vsub_sat(DisasContext *ctx, arg_VX *a,
+                                int sign, int vece, int add)
+{
+    static const TCGOpcode vecop_list_sub_u[] = {
+        INDEX_op_sub_vec, INDEX_op_ussub_vec, INDEX_op_cmp_vec, 0
+    };
+    static const TCGOpcode vecop_list_sub_s[] = {
+        INDEX_op_sub_vec, INDEX_op_sssub_vec, INDEX_op_cmp_vec, 0
+    };
+    static const TCGOpcode vecop_list_add_u[] = {
+        INDEX_op_add_vec, INDEX_op_usadd_vec, INDEX_op_cmp_vec, 0
+    };
+    static const TCGOpcode vecop_list_add_s[] = {
+        INDEX_op_add_vec, INDEX_op_ssadd_vec, INDEX_op_cmp_vec, 0
+    };
+
+    static const GVecGen4 op[2][3][2] = {
+        {
+            {
+                {
+                    .fniv = gen_vsub_sat_u,
+                    .fno = gen_helper_VSUBUBS,
+                    .opt_opc = vecop_list_sub_u,
+                    .write_aofs = true,
+                    .vece = MO_8
+                },
+                {
+                    .fniv = gen_vadd_sat_u,
+                    .fno = gen_helper_VADDUBS,
+                    .opt_opc = vecop_list_add_u,
+                    .write_aofs = true,
+                    .vece = MO_8
+                },
+            },
+            {
+                {
+                    .fniv = gen_vsub_sat_u,
+                    .fno = gen_helper_VSUBUHS,
+                    .opt_opc = vecop_list_sub_u,
+                    .write_aofs = true,
+                    .vece = MO_16
+                },
+                {
+                    .fniv = gen_vadd_sat_u,
+                    .fno = gen_helper_VADDUHS,
+                    .opt_opc = vecop_list_add_u,
+                    .write_aofs = true,
+                    .vece = MO_16
+                },
+            },
+            {
+                {
+                    .fniv = gen_vsub_sat_u,
+                    .fno = gen_helper_VSUBUWS,
+                    .opt_opc = vecop_list_sub_u,
+                    .write_aofs = true,
+                    .vece = MO_32
+                },
+                {
+                    .fniv = gen_vadd_sat_u,
+                    .fno = gen_helper_VADDUWS,
+                    .opt_opc = vecop_list_add_u,
+                    .write_aofs = true,
+                    .vece = MO_32
+                },
+            },
+        },
+        {
+            {
+                {
+                    .fniv = gen_vsub_sat_s,
+                    .fno = gen_helper_VSUBSBS,
+                    .opt_opc = vecop_list_sub_s,
+                    .write_aofs = true,
+                    .vece = MO_8
+                },
+                {
+                    .fniv = gen_vadd_sat_s,
+                    .fno = gen_helper_VADDSBS,
+                    .opt_opc = vecop_list_add_s,
+                    .write_aofs = true,
+                    .vece = MO_8
+                },
+            },
+            {
+                {
+                    .fniv = gen_vsub_sat_s,
+                    .fno = gen_helper_VSUBSHS,
+                    .opt_opc = vecop_list_sub_s,
+                    .write_aofs = true,
+                    .vece = MO_16
+                },
+                {
+                    .fniv = gen_vadd_sat_s,
+                    .fno = gen_helper_VADDSHS,
+                    .opt_opc = vecop_list_add_s,
+                    .write_aofs = true,
+                    .vece = MO_16
+                },
+            },
+            {
+                {
+                    .fniv = gen_vsub_sat_s,
+                    .fno = gen_helper_VSUBSWS,
+                    .opt_opc = vecop_list_sub_s,
+                    .write_aofs = true,
+                    .vece = MO_32
+                },

target/ppc/translate/vmx-impl.c.inc static bool do_vx_vaddsubcuw(DisasContext *ctx, arg_VX *a, int add) · line 3027

Quoted 10 lines
target/ppc/translate/vmx-impl.c.inc +10 -0
+                {
+                    .fniv = gen_vadd_sat_s,
+                    .fno = gen_helper_VADDSWS,
+                    .opt_opc = vecop_list_add_s,
+                    .write_aofs = true,
+                    .vece = MO_32
+                },
+            },
+        },
+    };

While this table is not wrong, I think it is clearer to have separate tables, one per operation, which are then passed in to a common expander.

target/ppc/translate/vmx-impl.c.inc static bool do_vx_vaddsubcuw(DisasContext *ctx, arg_VX *a, int add) · line 3039

Quoted 12 lines
target/ppc/translate/vmx-impl.c.inc +12 -0
+
+    REQUIRE_INSNS_FLAGS(ctx, ALTIVEC);
+    REQUIRE_VECTOR(ctx);
+
+    tcg_gen_gvec_4(avr_full_offset(a->vrt), offsetof(CPUPPCState, vscr_sat),
+                   avr_full_offset(a->vra), avr_full_offset(a->vrb), 16, 16,
+                   &op[sign][vece][add]);
+
+    return true;
+}
+
+TRANS(VSUBUBS, do_vx_vadd_vsub_sat, 0, MO_8, 0)

I think it is clearer to use TRANS_FLAGS than to sink the ISA check into the helper. In general I seem to find the helper later gets reused for something else with a different ISA check.

Thus

static const TCGOpcode vecop_list_vsub_sat_u[] = {
INDEX_op_sub_vec, INDEX_op_ussub_vec, 0
};
static const GVecGen4 op_vsububs = {
.fno = gen_helper_VSUBUBS,
.fniv = gen_vsub_sat_u,
.opt_opc = vecop_list_vsub_sat_u, .write_aofs = true,
.vece = MO_8
};
TRANS_FLAGS(VSUBUBS, do_vx_vadd_vsub_sat, &op_vsububs)

static const GVecGen4 op_vsubuhs = {
.fno = gen_helper_VSUBUHS,
.fniv = gen_vsub_sat_u,
.opt_opc = vecop_list_vsub_sat_u, .write_aofs = true,
.vece = MO_16
};
TRANS_FLAGS(VSUBUHS, do_vx_vadd_vsub_sat, &op_vsubuhs)

etc.

target/ppc/translate/vmx-ops.c.inc GEN_VXFORM(vsro, 6, 17), · line 57

Quoted 1 line
target/ppc/translate/vmx-ops.c.inc +0 -1
-GEN_VXFORM_DUAL(vaddubs, vmul10uq, 0, 8, PPC_ALTIVEC, PPC_NONE),

You are correct in your cover letter that this is not right. We should have been testing ISA300 for vmul10uq here.

target/ppc/translate/vmx-ops.c.inc GEN_VXFORM(vsro, 6, 17), · line 58

Quoted 1 line
target/ppc/translate/vmx-ops.c.inc +1 -0
+GEN_VXFORM(vmul10euq, 0, 9),

And thus need GEN_VXFORM_300 here.

Quoted 4 lines
target/ppc/translate/vmx-ops.c.inc +4 -0
+GEN_VXFORM(vmul10euq, 0, 9),
+GEN_VXFORM(bcdcpsgn, 0, 13),
+GEN_VXFORM(bcdadd, 0, 24),
+GEN_VXFORM(bcdsub, 0, 25),

...

Quoted 1 line

+GEN_VXFORM(xpnd04_2, 0, 30),

None of these are in the base ISA, so all need a flag check.

r~

#3 lore raw

Re: [PATCH 1/1] target/ppc: Move VMX integer add/sub saturate insns to decodetree.

Hi Richard,

Quoted 20 lines · Richard Henderson
Quoted 6 lines · Chinmay Rath
target/ppc/translate/vmx-impl.c.inc +0 -0
@@ -2934,6 +2870,184 @@ static bool do_vx_vaddsubcuw(DisasContext 
 *ctx, arg_VX *a, int add)
       return true;
   }

  +static inline void do_vadd_vsub_sat

target/ppc/translate/vmx-impl.c.inc +1 -0
+(

target/ppc/translate/vmx-impl.c.inc static bool do_vx_vaddsubcuw(DisasContext *ctx, arg_VX *a, int add) · line 2884

Quoted 10 lines
target/ppc/translate/vmx-impl.c.inc +10 -0
+    unsigned vece, TCGv_vec t, TCGv_vec sat, TCGv_vec a, TCGv_vec b,
+    void (*norm_op)(unsigned, TCGv_vec, TCGv_vec, TCGv_vec),
+    void (*sat_op)(unsigned, TCGv_vec, TCGv_vec, TCGv_vec))
+{
+    TCGv_vec x = tcg_temp_new_vec_matching(t);
+    norm_op(vece, x, a, b);
+    sat_op(vece, t, a, b);
+    tcg_gen_cmp_vec(TCG_COND_NE, vece, x, x, t);
+    tcg_gen_or_vec(vece, sat, sat, x);
+}

As a separate change, before or after, the cmp_vec may be simplified to xor_vec.  Which means that INDEX_op_cmp_vec need not be probed in the vecop_lists.  See

Quoted 5 lines

https://lore.kernel.org/qemu-devel/[email protected]/

which is performing the same operation on AArch64.

Noted ! Will do.

Quoted 19 lines
Quoted 19 lines
target/ppc/translate/vmx-impl.c.inc +18 -0
+static bool do_vx_vadd_vsub_sat(DisasContext *ctx, arg_VX *a,
+                                int sign, int vece, int add)
+{
+    static const TCGOpcode vecop_list_sub_u[] = {
+        INDEX_op_sub_vec, INDEX_op_ussub_vec, INDEX_op_cmp_vec, 0
+    };
+    static const TCGOpcode vecop_list_sub_s[] = {
+        INDEX_op_sub_vec, INDEX_op_sssub_vec, INDEX_op_cmp_vec, 0
+    };
+    static const TCGOpcode vecop_list_add_u[] = {
+        INDEX_op_add_vec, INDEX_op_usadd_vec, INDEX_op_cmp_vec, 0
+    };
+    static const TCGOpcode vecop_list_add_s[] = {
+        INDEX_op_add_vec, INDEX_op_ssadd_vec, INDEX_op_cmp_vec, 0
+    };
+
+    static const GVecGen4 op[2][3][2] = {
+        {
Quoted 8 lines
Quoted 8 lines

+            {
+                {
+                    .fniv = gen_vsub_sat_u,
+                    .fno = gen_helper_VSUBUBS,
+                    .opt_opc = vecop_list_sub_u,
+                    .write_aofs = true,
+                    .vece = MO_8
+                },

.
.
.

Quoted 53 lines
Quoted 10 lines

+                {
+                    .fniv = gen_vadd_sat_s,
+                    .fno = gen_helper_VADDSWS,
+                    .opt_opc = vecop_list_add_s,
+                    .write_aofs = true,
+                    .vece = MO_32
+                },
+            },
+        },
+    };

While this table is not wrong, I think it is clearer to have separate tables, one per operation, which are then passed in to a common expander.

Quoted 9 lines
target/ppc/translate/vmx-impl.c.inc +5 -0
+
+    REQUIRE_INSNS_FLAGS(ctx, ALTIVEC);
+    REQUIRE_VECTOR(ctx);
+
+    tcg_gen_gvec_4(avr_full_offset(a->vrt), offsetof(CPUPPCState, 

vscr_sat),
+                   avr_full_offset(a->vra), avr_full_offset(a->vrb), 16, 16,
+                   &op[sign][vece][add]);

target/ppc/translate/vmx-impl.c.inc static bool do_vx_vaddsubcuw(DisasContext *ctx, arg_VX *a, int add) · line 3039

Quoted 5 lines
target/ppc/translate/vmx-impl.c.inc +5 -0
+
+    return true;
+}
+
+TRANS(VSUBUBS, do_vx_vadd_vsub_sat, 0, MO_8, 0)

I think it is clearer to use TRANS_FLAGS than to sink the ISA check into the helper.  In general I seem to find the helper later gets reused for something else with a different ISA check.

Thus

static const TCGOpcode vecop_list_vsub_sat_u[] = { INDEX_op_sub_vec, INDEX_op_ussub_vec, 0 };
static const GVecGen4 op_vsububs = {
    .fno = gen_helper_VSUBUBS,
    .fniv = gen_vsub_sat_u,
    .opt_opc = vecop_list_vsub_sat_u, .write_aofs = true,
    .vece = MO_8
};
TRANS_FLAGS(VSUBUBS, do_vx_vadd_vsub_sat, &op_vsububs)

static const GVecGen4 op_vsubuhs = {
    .fno = gen_helper_VSUBUHS,
    .fniv = gen_vsub_sat_u,
    .opt_opc = vecop_list_vsub_sat_u, .write_aofs = true,
    .vece = MO_16
};
TRANS_FLAGS(VSUBUHS, do_vx_vadd_vsub_sat, &op_vsubuhs)

Quoted 2 lines

etc.

Will add those changes in v2.

Quoted 5 lines
Quoted 1 line

-GEN_VXFORM_DUAL(vaddubs, vmul10uq, 0, 8, PPC_ALTIVEC, PPC_NONE),

You are correct in your cover letter that this is not right. We should have been testing ISA300 for vmul10uq here.

Thank you very much for the clarification !

Quoted 9 lines
Quoted 1 line

+GEN_VXFORM(vmul10euq, 0, 9),

And thus need GEN_VXFORM_300 here.

Quoted 4 lines
target/ppc/translate/vmx-ops.c.inc +4 -0
+GEN_VXFORM(vmul10euq, 0, 9),
+GEN_VXFORM(bcdcpsgn, 0, 13),
+GEN_VXFORM(bcdadd, 0, 24),
+GEN_VXFORM(bcdsub, 0, 25),

...

Quoted 8 lines
Quoted 1 line

+GEN_VXFORM(xpnd04_2, 0, 30),

None of these are in the base ISA, so all need a flag check.

r~

Thanks & Regards,
Chinmay

#4 lore raw
In reply to Chinmay Rath
Quoted 14 lines · Chinmay Rath

1. vsubsbs and bcdtrunc :

In this pair, bcdtrunc has the insn flag check PPC2_ISA300 in the vmx-impl file, within the GEN_VXFORM_DUAL macro, which does this flag check.
However it also has this flag check in the vmx-ops file. Hence I have retained the same in the new entry in the vmx-ops file. This is consistent with the behaviour in done in the following commit :
https://github.com/qemu/qemu/commit/b132be53a4ba6a0a40d5643d791822f958a36e53
So even though the flag check is removed from the vmx-impl file, it is retained in the vmx-ops file. All good here.

2. vadduhs and vmul10euq :

Quoted 10 lines

In this pair, vmul10euq has the insn flag check PPC2_ISA300 in the vmx-impl file, check done within the GEN_VXFORM_DUAL macro. However the same flag was NOT originally present in the vmx-ops file, so I have NOT included in its new entry in the vmx-ops file. I have done this, following the behaviour done in the following commit :
https://github.com/qemu/qemu/commit/c85929b2ddf6bbad737635c9b85213007ec043af
So this flag check for vmul10euq is excluded now. Is this not a problem ? I feel that this leads to the flag check being skipped now, however this behaviour was followed in the above mentioned commit.

This second link is for VAVG* and VABSD*.

Yes you are correct that this second case was done incorrectly. Thankfully the mistake was fixed in the very next commit, when VABSD* was converted to decodetree as well.

r~

#5 lore raw

Hi Richard,

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

1. vsubsbs and bcdtrunc :

In this pair, bcdtrunc has the insn flag check PPC2_ISA300 in the vmx-impl file, within the GEN_VXFORM_DUAL macro, which does this flag check.
However it also has this flag check in the vmx-ops file. Hence I have retained the same in the new entry in the vmx-ops file. This is consistent with the behaviour in done in the following commit :
https://github.com/qemu/qemu/commit/b132be53a4ba6a0a40d5643d791822f958a36e53

So even though the flag check is removed from the vmx-impl file, it is retained in the vmx-ops file. All good here.

2. vadduhs and vmul10euq :

In this pair, vmul10euq has the insn flag check PPC2_ISA300 in the vmx-impl file, check done within the GEN_VXFORM_DUAL macro. However the same flag was NOT originally present in the vmx-ops file, so I have NOT included in its new entry in the vmx-ops file. I have done this, following the behaviour done in the following commit :
https://github.com/qemu/qemu/commit/c85929b2ddf6bbad737635c9b85213007ec043af

Quoted 8 lines
Quoted 3 lines

So this flag check for vmul10euq is excluded now. Is this not a problem ? I feel that this leads to the flag check being skipped now, however this behaviour was followed in the above mentioned commit.

This second link is for VAVG* and VABSD*.

Yes you are correct that this second case was done incorrectly. Thankfully the mistake was fixed in the very next commit, when VABSD* was converted to decodetree as well.

Thank you very much for the clarification !

Quoted 2 lines

r~

Regards,
Chinmay