Skip to contentSkip to conversation

POWER9 TCG enablements - part9

PATCH In review Nikunj A Dadhania 3 participants 14 messages Dec 9, 2016 – Dec 19, 2016

lore
Share & tools
lore
#0 lore raw

v2 cover POWER9 TCG enablements - part9

This series contains 6 new instructions for POWER9 ISA3.0
VSX Vector Insert/Extract Word
VSX Load/Store with length

Although, lxvl/lxvll and stxvl/stxvll can be combined as single patch, have left it for detailed commit log for instruction explanation.

Changelog:
v1:
* Combine helpers of lxvl and lxvll
* Combine helpers of stxvl and stxvll
* Rework xxextractuw and xxinsertw to simplify helper

v0:
* Fixed lxvl/lxvll and stxvl/stxvll as suggested by Richard
* Dropped mask_u128, which is not needed anymore
* Prevent UIMM > 12 in xxextractuw
* Drop xori from xsnegqp
* Rewrite xxperm/xxpermr without double copy

Nikunj A Dadhania (6):
target-ppc: implement lxvl instruction
target-ppc: implement lxvll instruction
target-ppc: implement stxvl instruction
target-ppc: implement stxvll instructions
target-ppc: implement xxextractuw instruction
target-ppc: implement xxinsertw instruction

 target-ppc/helper.h                 |  8 +++++
 target-ppc/int_helper.c             | 42 +++++++++++++++++++++++
 target-ppc/mem_helper.c             | 66 +++++++++++++++++++++++++++++++++++++
 target-ppc/translate/vsx-impl.inc.c | 60 +++++++++++++++++++++++++++++++++
 target-ppc/translate/vsx-ops.inc.c  | 14 ++++++++
 5 files changed, 190 insertions(+)
Signature · 1 line
2.7.4
#2 lore raw

PATCH v2 2/6 target-ppc: implement lxvll instruction

lxvll: Load VSX Vector Left-justified with Length

Little/Big-endian Storage:

+---+---+---+---+---+---+---+---+---+---+---+---+---+---+--+--+
|“T”|“h”|“i”|“s”|“ ”|“i”|“s”|“ ”|“a”|“ ”|“T”|“E”|“S”|“T”|FF|FF|
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+--+--+

Loading 14 bytes to vector (8-bit elements) in BE/LE:

+---+---+---+---+---+---+---+---+---+---+---+---+---+---+--+--+
|“T”|“h”|“i”|“s”|“ ”|“i”|“s”|“ ”|“a”|“ ”|“T”|“E”|“S”|“T”|00|00|
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+--+--+
---
 target-ppc/helper.h                 | 1 +
 target-ppc/mem_helper.c             | 1 +
 target-ppc/translate/vsx-impl.inc.c | 1 +
 target-ppc/translate/vsx-ops.inc.c  | 1 +
 4 files changed, 4 insertions(+)
target-ppc/helper.h +1 -0
index 16ed2c1..6c44731 100644
@@ -319,6 +319,7 @@ DEF_HELPER_3(stvehx, void, env, avr, tl)
 DEF_HELPER_3(stvewx, void, env, avr, tl)
 #if defined(TARGET_PPC64)
 DEF_HELPER_4(lxvl, void, env, tl, tl, tl)
+DEF_HELPER_4(lxvll, void, env, tl, tl, tl)
 #endif
 DEF_HELPER_4(vsumsws, void, env, avr, avr, avr)
 DEF_HELPER_4(vsum2sws, void, env, avr, avr, avr)
target-ppc/mem_helper.c +1 -0
index c4ddc5b..da51465 100644
@@ -315,6 +315,7 @@ void helper_##name(CPUPPCState *env, target_ulong addr,                 \
 }
 
 VSX_LXVL(lxvl, 0)
+VSX_LXVL(lxvll, 1)
 #undef VSX_LXVL
 #undef GET_NB
 #endif /* TARGET_PPC64 */
target-ppc/translate/vsx-impl.inc.c +1 -0
index 1f64fb7..ce20579 100644
@@ -267,6 +267,7 @@ static void gen_##name(DisasContext *ctx)                       \
 }
 
 VSX_VECTOR_LOAD_STORE_LENGTH(lxvl)
+VSX_VECTOR_LOAD_STORE_LENGTH(lxvll)
 #endif
 
 #define VSX_LOAD_SCALAR_DS(name, operation)                       \
target-ppc/translate/vsx-ops.inc.c +1 -0
index 62a0afc..c207804 100644
@@ -12,6 +12,7 @@ GEN_HANDLER_E(lxvb16x, 0x1F, 0x0C, 0x1B, 0, PPC_NONE, PPC2_ISA300),
 GEN_HANDLER_E(lxvx, 0x1F, 0x0C, 0x08, 0x00000040, PPC_NONE, PPC2_ISA300),
 #if defined(TARGET_PPC64)
 GEN_HANDLER_E(lxvl, 0x1F, 0x0D, 0x08, 0, PPC_NONE, PPC2_ISA300),
+GEN_HANDLER_E(lxvll, 0x1F, 0x0D, 0x09, 0, PPC_NONE, PPC2_ISA300),
 #endif
 
 GEN_HANDLER_E(stxsdx, 0x1F, 0xC, 0x16, 0, PPC_NONE, PPC2_VSX),
Signature · 1 line
2.7.4
#3 lore raw

PATCH v2 3/6 target-ppc: implement stxvl instruction

In reply to Nikunj A Dadhania

stxvl: Store VSX Vector with Length

Vector (8-bit elements) in BE:

+---+---+---+---+---+---+---+---+---+---+---+---+---+---+--+--+
|“T”|“h”|“i”|“s”|“ ”|“i”|“s”|“ ”|“a”|“ ”|“T”|“E”|“S”|“T”|00|00|
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+--+--+

Vector (8-bit elements) in LE:

+--+--+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
|00|00|“T”|“S”|“E”|“T”|“ ”|“a”|“ ”|“s”|“i”|“ ”|“s”|“i”|"h"|"T"|
+--+--+---+---+---+---+---+---+---+---+---+---+---+---+---+---+

Storing 14 bytes would result in following Little/Big-endian Storage:

+---+---+---+---+---+---+---+---+---+---+---+---+---+---+--+--+
|“T”|“h”|“i”|“s”|“ ”|“i”|“s”|“ ”|“a”|“ ”|“T”|“E”|“S”|“T”|FF|FF|
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+--+--+
---
 target-ppc/helper.h                 |  1 +
 target-ppc/mem_helper.c             | 29 +++++++++++++++++++++++++++++
 target-ppc/translate/vsx-impl.inc.c |  1 +
 target-ppc/translate/vsx-ops.inc.c  |  3 +++
 4 files changed, 34 insertions(+)
target-ppc/helper.h +1 -0
index 6c44731..211313d 100644
@@ -320,6 +320,7 @@ DEF_HELPER_3(stvewx, void, env, avr, tl)
 #if defined(TARGET_PPC64)
 DEF_HELPER_4(lxvl, void, env, tl, tl, tl)
 DEF_HELPER_4(lxvll, void, env, tl, tl, tl)
+DEF_HELPER_4(stxvl, void, env, tl, tl, tl)
 #endif
 DEF_HELPER_4(vsumsws, void, env, avr, avr, avr)
 DEF_HELPER_4(vsum2sws, void, env, avr, avr, avr)
target-ppc/mem_helper.c +29 -0
index da51465..2427b49 100644
@@ -317,6 +317,35 @@ void helper_##name(CPUPPCState *env, target_ulong addr,                 \
 VSX_LXVL(lxvl, 0)
 VSX_LXVL(lxvll, 1)
 #undef VSX_LXVL
+
+#define VSX_STXVL(name, lj)                                       \
+void helper_##name(CPUPPCState *env, target_ulong addr,           \
+                   target_ulong xt_num, target_ulong rb)          \
+{                                                                 \
+    int i;                                                        \
+    ppc_vsr_t xt;                                                 \
+    target_ulong nb = GET_NB(rb);                                 \
+                                                                  \
+    if (!nb) {                                                    \
+        return;                                                   \
+    }                                                             \
+    getVSR(xt_num, &xt, env);                                     \
+    nb = (nb >= 16) ? 16 : nb;                                    \
+    if (msr_le && !lj) {                                          \
+        for (i = 16; i > 16 - nb; i--) {                          \
+            cpu_stb_data_ra(env, addr, xt.VsrB(i - 1), GETPC());  \
+            addr = addr_add(env, addr, 1);                        \
+        }                                                         \
+    } else {                                                      \
+        for (i = 0; i < nb; i++) {                                \
+            cpu_stb_data_ra(env, addr, xt.VsrB(i), GETPC());      \
+            addr = addr_add(env, addr, 1);                        \
+        }                                                         \
+    }                                                             \
+}
+
+VSX_STXVL(stxvl, 0)
+#undef VSX_STXVL
 #undef GET_NB
 #endif /* TARGET_PPC64 */
 
target-ppc/translate/vsx-impl.inc.c +1 -0
index ce20579..5099d44 100644
@@ -268,6 +268,7 @@ static void gen_##name(DisasContext *ctx)                       \
 
 VSX_VECTOR_LOAD_STORE_LENGTH(lxvl)
 VSX_VECTOR_LOAD_STORE_LENGTH(lxvll)
+VSX_VECTOR_LOAD_STORE_LENGTH(stxvl)
 #endif
 
 #define VSX_LOAD_SCALAR_DS(name, operation)                       \
target-ppc/translate/vsx-ops.inc.c +3 -0
index c207804..3afded2 100644
@@ -25,6 +25,9 @@ GEN_HANDLER_E(stxvw4x, 0x1F, 0xC, 0x1C, 0, PPC_NONE, PPC2_VSX),
 GEN_HANDLER_E(stxvh8x, 0x1F, 0x0C, 0x1D, 0, PPC_NONE,  PPC2_ISA300),
 GEN_HANDLER_E(stxvb16x, 0x1F, 0x0C, 0x1F, 0, PPC_NONE, PPC2_ISA300),
 GEN_HANDLER_E(stxvx, 0x1F, 0x0C, 0x0C, 0, PPC_NONE, PPC2_ISA300),
+#if defined(TARGET_PPC64)
+GEN_HANDLER_E(stxvl, 0x1F, 0x0D, 0x0C, 0, PPC_NONE, PPC2_ISA300),
+#endif
 
 GEN_HANDLER_E(mfvsrwz, 0x1F, 0x13, 0x03, 0x0000F800, PPC_NONE, PPC2_VSX207),
 GEN_HANDLER_E(mtvsrwa, 0x1F, 0x13, 0x06, 0x0000F800, PPC_NONE, PPC2_VSX207),
Signature · 1 line
2.7.4
#1 lore raw

PATCH v2 1/6 target-ppc: implement lxvl instruction

In reply to Nikunj A Dadhania

lxvl: Load VSX Vector with Length

Little/Big-endian Storage:

+---+---+---+---+---+---+---+---+---+---+---+---+---+---+--+--+
|“T”|“h”|“i”|“s”|“ ”|“i”|“s”|“ ”|“a”|“ ”|“T”|“E”|“S”|“T”|FF|FF|
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+--+--+

Loading 14 bytes results in:

Vector (8-bit elements) in BE:

+---+---+---+---+---+---+---+---+---+---+---+---+---+---+--+--+
|“T”|“h”|“i”|“s”|“ ”|“i”|“s”|“ ”|“a”|“ ”|“T”|“E”|“S”|“T”|00|00|
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+--+--+

Vector (8-bit elements) in LE:

+--+--+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
|00|00|“T”|“S”|“E”|“T”|“ ”|“a”|“ ”|“s”|“i”|“ ”|“s”|“i”|"h"|"T"|
+--+--+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
---
 target-ppc/helper.h                 |  3 +++
 target-ppc/mem_helper.c             | 35 +++++++++++++++++++++++++++++++++++
 target-ppc/translate/vsx-impl.inc.c | 29 +++++++++++++++++++++++++++++
 target-ppc/translate/vsx-ops.inc.c  |  3 +++
 4 files changed, 70 insertions(+)
target-ppc/helper.h +3 -0
index c3df982..16ed2c1 100644
@@ -317,6 +317,9 @@ DEF_HELPER_3(lvewx, void, env, avr, tl)
 DEF_HELPER_3(stvebx, void, env, avr, tl)
 DEF_HELPER_3(stvehx, void, env, avr, tl)
 DEF_HELPER_3(stvewx, void, env, avr, tl)
+#if defined(TARGET_PPC64)
+DEF_HELPER_4(lxvl, void, env, tl, tl, tl)
+#endif
 DEF_HELPER_4(vsumsws, void, env, avr, avr, avr)
 DEF_HELPER_4(vsum2sws, void, env, avr, avr, avr)
 DEF_HELPER_4(vsum4sbs, void, env, avr, avr, avr)
target-ppc/mem_helper.c +35 -0
index 1ab8a6e..c4ddc5b 100644
@@ -24,6 +24,7 @@
 
 #include "helper_regs.h"
 #include "exec/cpu_ldst.h"
+#include "internal.h"
 
 //#define DEBUG_OP
 
@@ -284,6 +285,40 @@ STVE(stvewx, cpu_stl_data_ra, bswap32, u32)
 #undef I
 #undef LVE
 
+#ifdef TARGET_PPC64
+#define GET_NB(rb) ((rb >> 56) & 0xFF)
+
+#define VSX_LXVL(name, lj)                                              \
+void helper_##name(CPUPPCState *env, target_ulong addr,                 \
+                   target_ulong xt_num, target_ulong rb)                \
+{                                                                       \
+    int i;                                                              \
+    ppc_vsr_t xt;                                                       \
+    uint64_t nb = GET_NB(rb);                                           \
+                                                                        \
+    xt.s128 = int128_zero();                                            \
+    if (nb) {                                                           \
+        nb = (nb >= 16) ? 16 : nb;                                      \
+        if (msr_le && !lj) {                                            \
+            for (i = 16; i > 16 - nb; i--) {                            \
+                xt.VsrB(i - 1) = cpu_ldub_data_ra(env, addr, GETPC());  \
+                addr = addr_add(env, addr, 1);                          \
+            }                                                           \
+        } else {                                                        \
+            for (i = 0; i < nb; i++) {                                  \
+                xt.VsrB(i) = cpu_ldub_data_ra(env, addr, GETPC());      \
+                addr = addr_add(env, addr, 1);                          \
+            }                                                           \
+        }                                                               \
+    }                                                                   \
+    putVSR(xt_num, &xt, env);                                           \
+}
+
+VSX_LXVL(lxvl, 0)
+#undef VSX_LXVL
+#undef GET_NB
+#endif /* TARGET_PPC64 */
+
 #undef HI_IDX
 #undef LO_IDX
 
target-ppc/translate/vsx-impl.inc.c +29 -0
index 7000035..1f64fb7 100644
@@ -240,6 +240,35 @@ VSX_VECTOR_LOAD_STORE(stxv, st_i64, 0)
 VSX_VECTOR_LOAD_STORE(lxvx, ld_i64, 1)
 VSX_VECTOR_LOAD_STORE(stxvx, st_i64, 1)
 
+#ifdef TARGET_PPC64
+#define VSX_VECTOR_LOAD_STORE_LENGTH(name)                      \
+static void gen_##name(DisasContext *ctx)                       \
+{                                                               \
+    TCGv EA, xt;                                                \
+                                                                \
+    if (xT(ctx->opcode) < 32) {                                 \
+        if (unlikely(!ctx->vsx_enabled)) {                      \
+            gen_exception(ctx, POWERPC_EXCP_VSXU);              \
+            return;                                             \
+        }                                                       \
+    } else {                                                    \
+        if (unlikely(!ctx->altivec_enabled)) {                  \
+            gen_exception(ctx, POWERPC_EXCP_VPU);               \
+            return;                                             \
+        }                                                       \
+    }                                                           \
+    EA = tcg_temp_new();                                        \
+    xt = tcg_const_tl(xT(ctx->opcode));                         \
+    gen_set_access_type(ctx, ACCESS_INT);                       \
+    gen_addr_register(ctx, EA);                                 \
+    gen_helper_##name(cpu_env, EA, xt, cpu_gpr[rB(ctx->opcode)]); \
+    tcg_temp_free(EA);                                          \
+    tcg_temp_free(xt);                                          \
+}
+
+VSX_VECTOR_LOAD_STORE_LENGTH(lxvl)
+#endif
+
 #define VSX_LOAD_SCALAR_DS(name, operation)                       \
 static void gen_##name(DisasContext *ctx)                         \
 {                                                                 \
target-ppc/translate/vsx-ops.inc.c +3 -0
index f684066..62a0afc 100644
@@ -10,6 +10,9 @@ GEN_HANDLER_E(lxvw4x, 0x1F, 0x0C, 0x18, 0, PPC_NONE, PPC2_VSX),
 GEN_HANDLER_E(lxvh8x, 0x1F, 0x0C, 0x19, 0, PPC_NONE,  PPC2_ISA300),
 GEN_HANDLER_E(lxvb16x, 0x1F, 0x0C, 0x1B, 0, PPC_NONE, PPC2_ISA300),
 GEN_HANDLER_E(lxvx, 0x1F, 0x0C, 0x08, 0x00000040, PPC_NONE, PPC2_ISA300),
+#if defined(TARGET_PPC64)
+GEN_HANDLER_E(lxvl, 0x1F, 0x0D, 0x08, 0, PPC_NONE, PPC2_ISA300),
+#endif
 
 GEN_HANDLER_E(stxsdx, 0x1F, 0xC, 0x16, 0, PPC_NONE, PPC2_VSX),
 GEN_HANDLER_E(stxsibx, 0x1F, 0xD, 0x1C, 0, PPC_NONE, PPC2_ISA300),
Signature · 1 line
2.7.4
#4 lore raw

PATCH v2 4/6 target-ppc: implement stxvll instructions

In reply to Nikunj A Dadhania

stxvll: Store VSX Vector Left-justified with Length

Vector (8-bit elements) in BE/LE:

+---+---+---+---+---+---+---+---+---+---+---+---+---+---+--+--+
|“T”|“h”|“i”|“s”|“ ”|“i”|“s”|“ ”|“a”|“ ”|“T”|“E”|“S”|“T”|00|00|
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+--+--+

Storing 14 bytes would result in following Little/Big-endian Storage:

+---+---+---+---+---+---+---+---+---+---+---+---+---+---+--+--+
|“T”|“h”|“i”|“s”|“ ”|“i”|“s”|“ ”|“a”|“ ”|“T”|“E”|“S”|“T”|FF|FF|
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+--+--+
---
 target-ppc/helper.h                 | 1 +
 target-ppc/mem_helper.c             | 1 +
 target-ppc/translate/vsx-impl.inc.c | 1 +
 target-ppc/translate/vsx-ops.inc.c  | 1 +
 4 files changed, 4 insertions(+)
target-ppc/helper.h +1 -0
index 211313d..4707db4 100644
@@ -321,6 +321,7 @@ DEF_HELPER_3(stvewx, void, env, avr, tl)
 DEF_HELPER_4(lxvl, void, env, tl, tl, tl)
 DEF_HELPER_4(lxvll, void, env, tl, tl, tl)
 DEF_HELPER_4(stxvl, void, env, tl, tl, tl)
+DEF_HELPER_4(stxvll, void, env, tl, tl, tl)
 #endif
 DEF_HELPER_4(vsumsws, void, env, avr, avr, avr)
 DEF_HELPER_4(vsum2sws, void, env, avr, avr, avr)
target-ppc/mem_helper.c +1 -0
index 2427b49..e6383c6 100644
@@ -345,6 +345,7 @@ void helper_##name(CPUPPCState *env, target_ulong addr,           \
 }
 
 VSX_STXVL(stxvl, 0)
+VSX_STXVL(stxvll, 1)
 #undef VSX_STXVL
 #undef GET_NB
 #endif /* TARGET_PPC64 */
target-ppc/translate/vsx-impl.inc.c +1 -0
index 5099d44..2a17c35 100644
@@ -269,6 +269,7 @@ static void gen_##name(DisasContext *ctx)                       \
 VSX_VECTOR_LOAD_STORE_LENGTH(lxvl)
 VSX_VECTOR_LOAD_STORE_LENGTH(lxvll)
 VSX_VECTOR_LOAD_STORE_LENGTH(stxvl)
+VSX_VECTOR_LOAD_STORE_LENGTH(stxvll)
 #endif
 
 #define VSX_LOAD_SCALAR_DS(name, operation)                       \
target-ppc/translate/vsx-ops.inc.c +1 -0
index 3afded2..46b95e3 100644
@@ -27,6 +27,7 @@ GEN_HANDLER_E(stxvb16x, 0x1F, 0x0C, 0x1F, 0, PPC_NONE, PPC2_ISA300),
 GEN_HANDLER_E(stxvx, 0x1F, 0x0C, 0x0C, 0, PPC_NONE, PPC2_ISA300),
 #if defined(TARGET_PPC64)
 GEN_HANDLER_E(stxvl, 0x1F, 0x0D, 0x0C, 0, PPC_NONE, PPC2_ISA300),
+GEN_HANDLER_E(stxvll, 0x1F, 0x0D, 0x0D, 0, PPC_NONE, PPC2_ISA300),
 #endif
 
 GEN_HANDLER_E(mfvsrwz, 0x1F, 0x13, 0x03, 0x0000F800, PPC_NONE, PPC2_VSX207),
Signature · 1 line
2.7.4
#5 lore raw

PATCH v2 5/6 target-ppc: implement xxextractuw instruction

In reply to Nikunj A Dadhania

xxextractuw: VSX Vector Extract Unsigned Word

---
 target-ppc/helper.h                 |  1 +
 target-ppc/int_helper.c             | 21 +++++++++++++++++++++
 target-ppc/translate/vsx-impl.inc.c | 27 +++++++++++++++++++++++++++
 target-ppc/translate/vsx-ops.inc.c  |  5 +++++
 4 files changed, 54 insertions(+)
target-ppc/helper.h +1 -0
index 4707db4..8b30420 100644
@@ -540,6 +540,7 @@ DEF_HELPER_2(xvrspip, void, env, i32)
 DEF_HELPER_2(xvrspiz, void, env, i32)
 DEF_HELPER_2(xxperm, void, env, i32)
 DEF_HELPER_2(xxpermr, void, env, i32)
+DEF_HELPER_4(xxextractuw, void, env, tl, tl, i32)
 
 DEF_HELPER_2(efscfsi, i32, env, i32)
 DEF_HELPER_2(efscfui, i32, env, i32)
target-ppc/int_helper.c +21 -0
index 7989b1f..e3f66ac 100644
@@ -2033,6 +2033,27 @@ VEXTRACT(uw, u32)
 VEXTRACT(d, u64)
 #undef VEXTRACT
 
+void helper_xxextractuw(CPUPPCState *env, target_ulong xtn,
+                        target_ulong xbn, uint32_t index)
+{
+    ppc_vsr_t xt, xb;
+    size_t es = sizeof(uint32_t);
+    uint32_t ext_index;
+
+    getVSR(xbn, &xb, env);
+    memset(&xt, 0, sizeof(xt));
+
+#if defined(HOST_WORDS_BIGENDIAN)
+    ext_index = index;
+    memcpy(&xt.u8[8 - es], &xb.u8[ext_index], es);
+#else
+    ext_index = (16 - index) - es;
+    memcpy(&xt.u8[8], &xb.u8[ext_index], es);
+#endif
+
+    putVSR(xtn, &xt, env);
+}
+
 #define VEXT_SIGNED(name, element, mask, cast, recast)              \
 void helper_##name(ppc_avr_t *r, ppc_avr_t *b)                      \
 {                                                                   \
target-ppc/translate/vsx-impl.inc.c +27 -0
index 2a17c35..1c40a35 100644
@@ -1180,6 +1180,33 @@ static void gen_xxsldwi(DisasContext *ctx)
     tcg_temp_free_i64(xtl);
 }
 
+#define VSX_EXTRACT(name)                                       \
+static void gen_##name(DisasContext *ctx)                       \
+{                                                               \
+    TCGv xt, xb;                                                \
+    TCGv_i32 t0 = tcg_temp_new_i32();                           \
+    uint8_t uimm = UIMM4(ctx->opcode);                          \
+                                                                \
+    if (unlikely(!ctx->vsx_enabled)) {                          \
+        gen_exception(ctx, POWERPC_EXCP_VSXU);                  \
+        return;                                                 \
+    }                                                           \
+    if (uimm > 12) {                                            \
+        tcg_gen_movi_i64(cpu_vsrh(xT(ctx->opcode)), 0);         \
+        tcg_gen_movi_i64(cpu_vsrl(xT(ctx->opcode)), 0);         \
+        return;                                                 \
+    }                                                           \
+    xt = tcg_const_tl(xT(ctx->opcode));                         \
+    xb = tcg_const_tl(xB(ctx->opcode));                         \
+    tcg_gen_movi_i32(t0, uimm);                                 \
+    gen_helper_##name(cpu_env, xt, xb, t0);                     \
+    tcg_temp_free(xb);                                          \
+    tcg_temp_free(xt);                                          \
+    tcg_temp_free_i32(t0);                                      \
+}
+
+VSX_EXTRACT(xxextractuw)
+
 #undef GEN_XX2FORM
 #undef GEN_XX3FORM
 #undef GEN_XX2IFORM
target-ppc/translate/vsx-ops.inc.c +5 -0
index 46b95e3..473d925 100644
@@ -49,6 +49,10 @@ GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 1, opc3, 0, PPC_NONE, fl2)
 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0, opc3, 0, PPC_NONE, fl2), \
 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 1, opc3, 0, PPC_NONE, fl2)
 
+#define GEN_XX2FORM_EXT(name, opc2, opc3, fl2)                          \
+GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0, opc3, 0x00100000, PPC_NONE, fl2), \
+GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 1, opc3, 0x00100000, PPC_NONE, fl2)
+
 #define GEN_XX2FORM_EO(name, opc2, opc3, opc4, fl2)                          \
 GEN_HANDLER2_E_2(name, #name, 0x3C, opc2 | 0, opc3, opc4, 0, PPC_NONE, fl2), \
 GEN_HANDLER2_E_2(name, #name, 0x3C, opc2 | 1, opc3, opc4, 0, PPC_NONE, fl2)
@@ -280,6 +284,7 @@ GEN_XX3FORM(xxpermr, 0x08, 0x07, PPC2_ISA300),
 GEN_XX2FORM(xxspltw, 0x08, 0x0A, PPC2_VSX),
 GEN_XX1FORM(xxspltib, 0x08, 0x0B, PPC2_ISA300),
 GEN_XX3FORM_DM(xxsldwi, 0x08, 0x00),
+GEN_XX2FORM_EXT(xxextractuw, 0x0A, 0x0A, PPC2_ISA300),
 
 #define GEN_XXSEL_ROW(opc3) \
 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x18, opc3, 0, PPC_NONE, PPC2_VSX), \
Signature · 1 line
2.7.4
#12 lore raw

PATCH v2 6/6 target-ppc: implement xxinsertw instruction

In reply to Nikunj A Dadhania

xxinsertw: VSX Vector Insert Word

---
 target-ppc/helper.h                 |  1 +
 target-ppc/int_helper.c             | 21 +++++++++++++++++++++
 target-ppc/translate/vsx-impl.inc.c |  5 +++--
 target-ppc/translate/vsx-ops.inc.c  |  1 +
 4 files changed, 26 insertions(+), 2 deletions(-)
target-ppc/helper.h +1 -0
index 8b30420..6c5b194 100644
@@ -541,6 +541,7 @@ DEF_HELPER_2(xvrspiz, void, env, i32)
 DEF_HELPER_2(xxperm, void, env, i32)
 DEF_HELPER_2(xxpermr, void, env, i32)
 DEF_HELPER_4(xxextractuw, void, env, tl, tl, i32)
+DEF_HELPER_4(xxinsertw, void, env, tl, tl, i32)
 
 DEF_HELPER_2(efscfsi, i32, env, i32)
 DEF_HELPER_2(efscfui, i32, env, i32)
target-ppc/int_helper.c +21 -0
index e3f66ac..4d7eab6 100644
@@ -2054,6 +2054,27 @@ void helper_xxextractuw(CPUPPCState *env, target_ulong xtn,
     putVSR(xtn, &xt, env);
 }
 
+void helper_xxinsertw(CPUPPCState *env, target_ulong xtn,
+                      target_ulong xbn, uint32_t index)
+{
+    ppc_vsr_t xt, xb;
+    size_t es = sizeof(uint32_t);
+    uint32_t ins_index;
+
+    getVSR(xbn, &xb, env);
+    getVSR(xtn, &xt, env);
+
+#if defined(HOST_WORDS_BIGENDIAN)
+    ins_index = index;
+    memcpy(&xt.u8[ins_index], &xb.u8[8 - es], es);
+#else
+    ins_index = (16 - index) - es;
+    memcpy(&xt.u8[ins_index], &xb.u8[8], es);
+#endif
+
+    putVSR(xtn, &xt, env);
+}
+
 #define VEXT_SIGNED(name, element, mask, cast, recast)              \
 void helper_##name(ppc_avr_t *r, ppc_avr_t *b)                      \
 {                                                                   \
target-ppc/translate/vsx-impl.inc.c +3 -2
index 1c40a35..9124e99 100644
@@ -1180,7 +1180,7 @@ static void gen_xxsldwi(DisasContext *ctx)
     tcg_temp_free_i64(xtl);
 }
 
-#define VSX_EXTRACT(name)                                       \
+#define VSX_EXTRACT_INSERT(name)                                \
 static void gen_##name(DisasContext *ctx)                       \
 {                                                               \
     TCGv xt, xb;                                                \
@@ -1205,7 +1205,8 @@ static void gen_##name(DisasContext *ctx)                       \
     tcg_temp_free_i32(t0);                                      \
 }
 
-VSX_EXTRACT(xxextractuw)
+VSX_EXTRACT_INSERT(xxextractuw)
+VSX_EXTRACT_INSERT(xxinsertw)
 
 #undef GEN_XX2FORM
 #undef GEN_XX3FORM
target-ppc/translate/vsx-ops.inc.c +1 -0
index 473d925..096d358 100644
@@ -285,6 +285,7 @@ GEN_XX2FORM(xxspltw, 0x08, 0x0A, PPC2_VSX),
 GEN_XX1FORM(xxspltib, 0x08, 0x0B, PPC2_ISA300),
 GEN_XX3FORM_DM(xxsldwi, 0x08, 0x00),
 GEN_XX2FORM_EXT(xxextractuw, 0x0A, 0x0A, PPC2_ISA300),
+GEN_XX2FORM_EXT(xxinsertw, 0x0A, 0x0B, PPC2_ISA300),
 
 #define GEN_XXSEL_ROW(opc3) \
 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x18, opc3, 0, PPC_NONE, PPC2_VSX), \
Signature · 1 line
2.7.4
#6 lore raw

Re: [Qemu-devel] [PATCH v2 5/6] target-ppc: implement xxextractuw instruction

In reply to Nikunj A Dadhania
Quoted 36 lines · Nikunj A Dadhania

xxextractuw: VSX Vector Extract Unsigned Word

---
 target-ppc/helper.h                 |  1 +
 target-ppc/int_helper.c             | 21 +++++++++++++++++++++
 target-ppc/translate/vsx-impl.inc.c | 27 +++++++++++++++++++++++++++
 target-ppc/translate/vsx-ops.inc.c  |  5 +++++
 4 files changed, 54 insertions(+)
target-ppc/helper.h +1 -0
index 4707db4..8b30420 100644
@@ -540,6 +540,7 @@ DEF_HELPER_2(xvrspip, void, env, i32)
 DEF_HELPER_2(xvrspiz, void, env, i32)
 DEF_HELPER_2(xxperm, void, env, i32)
 DEF_HELPER_2(xxpermr, void, env, i32)
+DEF_HELPER_4(xxextractuw, void, env, tl, tl, i32)
 
 DEF_HELPER_2(efscfsi, i32, env, i32)
 DEF_HELPER_2(efscfui, i32, env, i32)
target-ppc/int_helper.c +6 -0
index 7989b1f..e3f66ac 100644
@@ -2033,6 +2033,27 @@ VEXTRACT(uw, u32)
 VEXTRACT(d, u64)
 #undef VEXTRACT
 
+void helper_xxextractuw(CPUPPCState *env, target_ulong xtn,
+                        target_ulong xbn, uint32_t index)
+{
+    ppc_vsr_t xt, xb;
+    size_t es = sizeof(uint32_t);
+    uint32_t ext_index;

target-ppc/int_helper.c VEXTRACT(uw, u32) · line 2051

Quoted 10 lines
target-ppc/int_helper.c +10 -0
+
+    getVSR(xbn, &xb, env);
+    memset(&xt, 0, sizeof(xt));
+
+#if defined(HOST_WORDS_BIGENDIAN)
+    ext_index = index;
+    memcpy(&xt.u8[8 - es], &xb.u8[ext_index], es);
+#else
+    ext_index = (16 - index) - es;
+    memcpy(&xt.u8[8], &xb.u8[ext_index], es);

Hm. So, IIUC, ext_index is the byte element - in IBM numbering - to start copying from. But I thought that when we have an LE host, the IBM byte element ordering is reversed from the actual order in host memory, so we'd need &xb.u8[16 - ext_index - es]

Quoted 18 lines
target-ppc/int_helper.c +5 -0
+#endif
+
+    putVSR(xtn, &xt, env);
+}
+
 #define VEXT_SIGNED(name, element, mask, cast, recast)              \
 void helper_##name(ppc_avr_t *r, ppc_avr_t *b)                      \
 {                                                                   \
target-ppc/translate/vsx-impl.inc.c +2 -0
index 2a17c35..1c40a35 100644
@@ -1180,6 +1180,33 @@ static void gen_xxsldwi(DisasContext *ctx)
     tcg_temp_free_i64(xtl);
 }
 
+#define VSX_EXTRACT(name)                                       \
+static void gen_##name(DisasContext *ctx)                       \

target-ppc/translate/vsx-impl.inc.c static void gen_xxsldwi(DisasContext *ctx) · line 1194

Quoted 10 lines
target-ppc/translate/vsx-impl.inc.c +10 -0
+{                                                               \
+    TCGv xt, xb;                                                \
+    TCGv_i32 t0 = tcg_temp_new_i32();                           \
+    uint8_t uimm = UIMM4(ctx->opcode);                          \
+                                                                \
+    if (unlikely(!ctx->vsx_enabled)) {                          \
+        gen_exception(ctx, POWERPC_EXCP_VSXU);                  \
+        return;                                                 \
+    }                                                           \
+    if (uimm > 12) {                                            \

Throughout the helper you use es == sizeof(uint32_t), but here you hardcode the assumption of 4 bytes, seems a bit inconsistent.

target-ppc/translate/vsx-impl.inc.c static void gen_xxsldwi(DisasContext *ctx) · line 1197

Quoted 3 lines
target-ppc/translate/vsx-impl.inc.c +3 -0
+        tcg_gen_movi_i64(cpu_vsrh(xT(ctx->opcode)), 0);         \
+        tcg_gen_movi_i64(cpu_vsrl(xT(ctx->opcode)), 0);         \
+        return;                                                 \

So, I know the architecture says it is undefined. But since you're testing for the bogus case anyway, why not turn this into an exception. That seems like it would be more helpful for debugging the guest than just setting the result to zero. Or is this done to match actual hardware behaviour?

Quoted 38 lines
target-ppc/translate/vsx-impl.inc.c +12 -0
+    }                                                           \
+    xt = tcg_const_tl(xT(ctx->opcode));                         \
+    xb = tcg_const_tl(xB(ctx->opcode));                         \
+    tcg_gen_movi_i32(t0, uimm);                                 \
+    gen_helper_##name(cpu_env, xt, xb, t0);                     \
+    tcg_temp_free(xb);                                          \
+    tcg_temp_free(xt);                                          \
+    tcg_temp_free_i32(t0);                                      \
+}
+
+VSX_EXTRACT(xxextractuw)
+
 #undef GEN_XX2FORM
 #undef GEN_XX3FORM
 #undef GEN_XX2IFORM
target-ppc/translate/vsx-ops.inc.c +5 -0
index 46b95e3..473d925 100644
@@ -49,6 +49,10 @@ GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 1, opc3, 0, PPC_NONE, fl2)
 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0, opc3, 0, PPC_NONE, fl2), \
 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 1, opc3, 0, PPC_NONE, fl2)
 
+#define GEN_XX2FORM_EXT(name, opc2, opc3, fl2)                          \
+GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0, opc3, 0x00100000, PPC_NONE, fl2), \
+GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 1, opc3, 0x00100000, PPC_NONE, fl2)
+
 #define GEN_XX2FORM_EO(name, opc2, opc3, opc4, fl2)                          \
 GEN_HANDLER2_E_2(name, #name, 0x3C, opc2 | 0, opc3, opc4, 0, PPC_NONE, fl2), \
 GEN_HANDLER2_E_2(name, #name, 0x3C, opc2 | 1, opc3, opc4, 0, PPC_NONE, fl2)
@@ -280,6 +284,7 @@ GEN_XX3FORM(xxpermr, 0x08, 0x07, PPC2_ISA300),
 GEN_XX2FORM(xxspltw, 0x08, 0x0A, PPC2_VSX),
 GEN_XX1FORM(xxspltib, 0x08, 0x0B, PPC2_ISA300),
 GEN_XX3FORM_DM(xxsldwi, 0x08, 0x00),
+GEN_XX2FORM_EXT(xxextractuw, 0x0A, 0x0A, PPC2_ISA300),
 
 #define GEN_XXSEL_ROW(opc3) \
 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x18, opc3, 0, PPC_NONE, PPC2_VSX), \
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#13 lore raw
In reply to Nikunj A Dadhania
Quoted 6 lines · Nikunj A Dadhania

This series contains 6 new instructions for POWER9 ISA3.0
VSX Vector Insert/Extract Word
VSX Load/Store with length

Although, lxvl/lxvll and stxvl/stxvll can be combined as single patch, have left it for detailed commit log for instruction explanation.

I've applied patches 1-4 to ppc-for-2.9. 5 & 6 I still have some questions about.

Quoted 29 lines

Changelog:
v1:
* Combine helpers of lxvl and lxvll
* Combine helpers of stxvl and stxvll
* Rework xxextractuw and xxinsertw to simplify helper

v0:
* Fixed lxvl/lxvll and stxvl/stxvll as suggested by Richard
* Dropped mask_u128, which is not needed anymore
* Prevent UIMM > 12 in xxextractuw
* Drop xori from xsnegqp
* Rewrite xxperm/xxpermr without double copy

Nikunj A Dadhania (6):
target-ppc: implement lxvl instruction
target-ppc: implement lxvll instruction
target-ppc: implement stxvl instruction
target-ppc: implement stxvll instructions
target-ppc: implement xxextractuw instruction
target-ppc: implement xxinsertw instruction

 target-ppc/helper.h                 |  8 +++++
 target-ppc/int_helper.c             | 42 +++++++++++++++++++++++
 target-ppc/mem_helper.c             | 66 +++++++++++++++++++++++++++++++++++++
 target-ppc/translate/vsx-impl.inc.c | 60 +++++++++++++++++++++++++++++++++
 target-ppc/translate/vsx-ops.inc.c  | 14 ++++++++
 5 files changed, 190 insertions(+)
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#7 lore raw

Re: [Qemu-devel] [Qemu-ppc] [PATCH v2 5/6] target-ppc: implement xxextractuw instruction

In reply to David Gibson
Quoted 44 lines · David Gibson
Quoted 43 lines · Nikunj A Dadhania

xxextractuw: VSX Vector Extract Unsigned Word

---
 target-ppc/helper.h                 |  1 +
 target-ppc/int_helper.c             | 21 +++++++++++++++++++++
 target-ppc/translate/vsx-impl.inc.c | 27 +++++++++++++++++++++++++++
 target-ppc/translate/vsx-ops.inc.c  |  5 +++++
 4 files changed, 54 insertions(+)
target-ppc/helper.h +1 -0
index 4707db4..8b30420 100644
@@ -540,6 +540,7 @@ DEF_HELPER_2(xvrspip, void, env, i32)
 DEF_HELPER_2(xvrspiz, void, env, i32)
 DEF_HELPER_2(xxperm, void, env, i32)
 DEF_HELPER_2(xxpermr, void, env, i32)
+DEF_HELPER_4(xxextractuw, void, env, tl, tl, i32)
 
 DEF_HELPER_2(efscfsi, i32, env, i32)
 DEF_HELPER_2(efscfui, i32, env, i32)
target-ppc/int_helper.c +13 -0
index 7989b1f..e3f66ac 100644
@@ -2033,6 +2033,27 @@ VEXTRACT(uw, u32)
 VEXTRACT(d, u64)
 #undef VEXTRACT
 
+void helper_xxextractuw(CPUPPCState *env, target_ulong xtn,
+                        target_ulong xbn, uint32_t index)
+{
+    ppc_vsr_t xt, xb;
+    size_t es = sizeof(uint32_t);
+    uint32_t ext_index;
+
+    getVSR(xbn, &xb, env);
+    memset(&xt, 0, sizeof(xt));
+
+#if defined(HOST_WORDS_BIGENDIAN)
+    ext_index = index;
+    memcpy(&xt.u8[8 - es], &xb.u8[ext_index], es);
Quoted 8 lines

target-ppc/int_helper.c VEXTRACT(uw, u32) · line 2051

Quoted 3 lines
target-ppc/int_helper.c +3 -0
+#else
+    ext_index = (16 - index) - es;
+    memcpy(&xt.u8[8], &xb.u8[ext_index], es);

Hm. So, IIUC, ext_index is the byte element - in IBM numbering - to start copying from. But I thought that when we have an LE host, the IBM byte element ordering is reversed from the actual order in host memory, so we'd need &xb.u8[16 - ext_index - es]

I am not getting you, I am getting index from user. So in case of BE host:

ext_index = index;

LE Host:

ext_index = (16 - index) - es;

I am already doing that. Am I missing something.

Quoted 37 lines
Quoted 19 lines
target-ppc/int_helper.c +5 -0
+#endif
+
+    putVSR(xtn, &xt, env);
+}
+
 #define VEXT_SIGNED(name, element, mask, cast, recast)              \
 void helper_##name(ppc_avr_t *r, ppc_avr_t *b)                      \
 {                                                                   \
target-ppc/translate/vsx-impl.inc.c +2 -0
index 2a17c35..1c40a35 100644
@@ -1180,6 +1180,33 @@ static void gen_xxsldwi(DisasContext *ctx)
     tcg_temp_free_i64(xtl);
 }
 
+#define VSX_EXTRACT(name)                                       \
+static void gen_##name(DisasContext *ctx)                       \

target-ppc/translate/vsx-impl.inc.c static void gen_xxsldwi(DisasContext *ctx) · line 1194

Quoted 10 lines
target-ppc/translate/vsx-impl.inc.c +10 -0
+{                                                               \
+    TCGv xt, xb;                                                \
+    TCGv_i32 t0 = tcg_temp_new_i32();                           \
+    uint8_t uimm = UIMM4(ctx->opcode);                          \
+                                                                \
+    if (unlikely(!ctx->vsx_enabled)) {                          \
+        gen_exception(ctx, POWERPC_EXCP_VSXU);                  \
+        return;                                                 \
+    }                                                           \
+    if (uimm > 12) {                                            \

Throughout the helper you use es == sizeof(uint32_t), but here you hardcode the assumption of 4 bytes, seems a bit inconsistent.

target-ppc/translate/vsx-impl.inc.c static void gen_xxsldwi(DisasContext *ctx) · line 1197

Quoted 3 lines
target-ppc/translate/vsx-impl.inc.c +3 -0
+        tcg_gen_movi_i64(cpu_vsrh(xT(ctx->opcode)), 0);         \
+        tcg_gen_movi_i64(cpu_vsrl(xT(ctx->opcode)), 0);         \
+        return;                                                 \
Quoted 5 lines

So, I know the architecture says it is undefined. But since you're testing for the bogus case anyway, why not turn this into an exception. That seems like it would be more helpful for debugging the guest than just setting the result to zero. Or is this done to match actual hardware behaviour?

I havent had a change to run on the real hardware, but on the system simulator, it happily
returns extracted content even if UIMM > 12.

Regards
Nikunj

#8 lore raw

Re: [Qemu-devel] [Qemu-ppc] [PATCH v2 5/6] target-ppc: implement xxextractuw instruction

Quoted 56 lines · Nikunj Dadhania
Quoted 44 lines · David Gibson
Quoted 43 lines · Nikunj A Dadhania

xxextractuw: VSX Vector Extract Unsigned Word

---
 target-ppc/helper.h                 |  1 +
 target-ppc/int_helper.c             | 21 +++++++++++++++++++++
 target-ppc/translate/vsx-impl.inc.c | 27 +++++++++++++++++++++++++++
 target-ppc/translate/vsx-ops.inc.c  |  5 +++++
 4 files changed, 54 insertions(+)
target-ppc/helper.h +1 -0
index 4707db4..8b30420 100644
@@ -540,6 +540,7 @@ DEF_HELPER_2(xvrspip, void, env, i32)
 DEF_HELPER_2(xvrspiz, void, env, i32)
 DEF_HELPER_2(xxperm, void, env, i32)
 DEF_HELPER_2(xxpermr, void, env, i32)
+DEF_HELPER_4(xxextractuw, void, env, tl, tl, i32)
 
 DEF_HELPER_2(efscfsi, i32, env, i32)
 DEF_HELPER_2(efscfui, i32, env, i32)
target-ppc/int_helper.c +13 -0
index 7989b1f..e3f66ac 100644
@@ -2033,6 +2033,27 @@ VEXTRACT(uw, u32)
 VEXTRACT(d, u64)
 #undef VEXTRACT
 
+void helper_xxextractuw(CPUPPCState *env, target_ulong xtn,
+                        target_ulong xbn, uint32_t index)
+{
+    ppc_vsr_t xt, xb;
+    size_t es = sizeof(uint32_t);
+    uint32_t ext_index;
+
+    getVSR(xbn, &xb, env);
+    memset(&xt, 0, sizeof(xt));
+
+#if defined(HOST_WORDS_BIGENDIAN)
+    ext_index = index;
+    memcpy(&xt.u8[8 - es], &xb.u8[ext_index], es);
Quoted 8 lines

target-ppc/int_helper.c VEXTRACT(uw, u32) · line 2051

Quoted 3 lines
target-ppc/int_helper.c +3 -0
+#else
+    ext_index = (16 - index) - es;
+    memcpy(&xt.u8[8], &xb.u8[ext_index], es);

Hm. So, IIUC, ext_index is the byte element - in IBM numbering - to start copying from. But I thought that when we have an LE host, the IBM byte element ordering is reversed from the actual order in host memory, so we'd need &xb.u8[16 - ext_index - es]

I am not getting you, I am getting index from user. So in case of BE host:

Quoted 7 lines

ext_index = index;

LE Host:

ext_index = (16 - index) - es;

I am already doing that. Am I missing something.

Duh, sorry, apparently I'm blind and missed that logic.

Quoted 42 lines
Quoted 36 lines
Quoted 18 lines
target-ppc/int_helper.c +5 -0
+#endif
+
+    putVSR(xtn, &xt, env);
+}
+
 #define VEXT_SIGNED(name, element, mask, cast, recast)              \
 void helper_##name(ppc_avr_t *r, ppc_avr_t *b)                      \
 {                                                                   \
target-ppc/translate/vsx-impl.inc.c +2 -0
index 2a17c35..1c40a35 100644
@@ -1180,6 +1180,33 @@ static void gen_xxsldwi(DisasContext *ctx)
     tcg_temp_free_i64(xtl);
 }
 
+#define VSX_EXTRACT(name)                                       \
+static void gen_##name(DisasContext *ctx)                       \

target-ppc/translate/vsx-impl.inc.c static void gen_xxsldwi(DisasContext *ctx) · line 1194

Quoted 10 lines
target-ppc/translate/vsx-impl.inc.c +10 -0
+{                                                               \
+    TCGv xt, xb;                                                \
+    TCGv_i32 t0 = tcg_temp_new_i32();                           \
+    uint8_t uimm = UIMM4(ctx->opcode);                          \
+                                                                \
+    if (unlikely(!ctx->vsx_enabled)) {                          \
+        gen_exception(ctx, POWERPC_EXCP_VSXU);                  \
+        return;                                                 \
+    }                                                           \
+    if (uimm > 12) {                                            \

Throughout the helper you use es == sizeof(uint32_t), but here you hardcode the assumption of 4 bytes, seems a bit inconsistent.

target-ppc/translate/vsx-impl.inc.c static void gen_xxsldwi(DisasContext *ctx) · line 1197

Quoted 3 lines
target-ppc/translate/vsx-impl.inc.c +3 -0
+        tcg_gen_movi_i64(cpu_vsrh(xT(ctx->opcode)), 0);         \
+        tcg_gen_movi_i64(cpu_vsrl(xT(ctx->opcode)), 0);         \
+        return;                                                 \
Quoted 5 lines

So, I know the architecture says it is undefined. But since you're testing for the bogus case anyway, why not turn this into an exception. That seems like it would be more helpful for debugging the guest than just setting the result to zero. Or is this done to match actual hardware behaviour?

Quoted 3 lines

I havent had a change to run on the real hardware, but on the system simulator, it happily
returns extracted content even if UIMM > 12.

Hm. Returns what exactly?

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#9 lore raw

Re: [Qemu-devel] [Qemu-ppc] [PATCH v2 5/6] target-ppc: implement xxextractuw instruction

Quoted 17 lines · David Gibson

[ Unknown signature status ]

Quoted 15 lines · Nikunj Dadhania
Quoted 13 lines · David Gibson

target-ppc/translate/vsx-impl.inc.c static void gen_xxsldwi(DisasContext *ctx) · line 1197

Quoted 6 lines · Nikunj A Dadhania

xxextractuw: VSX Vector Extract Unsigned Word

target-ppc/translate/vsx-impl.inc.c +3 -0
+        tcg_gen_movi_i64(cpu_vsrh(xT(ctx->opcode)), 0);         \
+        tcg_gen_movi_i64(cpu_vsrl(xT(ctx->opcode)), 0);         \
+        return;                                                 \

So, I know the architecture says it is undefined. But since you're testing for the bogus case anyway, why not turn this into an exception. That seems like it would be more helpful for debugging the guest than just setting the result to zero. Or is this done to match actual hardware behaviour?

Quoted 5 lines
Quoted 3 lines

I havent had a change to run on the real hardware, but on the system simulator, it happily
returns extracted content even if UIMM > 12.

Hm. Returns what exactly?

So for LE case extracting from 15 returns following, basically its rounding up to 0.

xxextractuw: 15 - ooTSET a si sihT

                  ________ihTo____

Regards,
Nikunj

#10 lore raw

Re: [Qemu-devel] [Qemu-ppc] [PATCH v2 5/6] target-ppc: implement xxextractuw instruction

Quoted 23 lines · Nikunj A Dadhania
Quoted 21 lines · David Gibson

[ Unknown signature status ]

Quoted 18 lines · Nikunj Dadhania
Quoted 8 lines · David Gibson

target-ppc/translate/vsx-impl.inc.c static void gen_xxsldwi(DisasContext *ctx) · line 1197

Quoted 6 lines · Nikunj A Dadhania

xxextractuw: VSX Vector Extract Unsigned Word

target-ppc/translate/vsx-impl.inc.c +3 -0
+        tcg_gen_movi_i64(cpu_vsrh(xT(ctx->opcode)), 0);         \
+        tcg_gen_movi_i64(cpu_vsrl(xT(ctx->opcode)), 0);         \
+        return;                                                 \
Quoted 5 lines

So, I know the architecture says it is undefined. But since you're testing for the bogus case anyway, why not turn this into an exception. That seems like it would be more helpful for debugging the guest than just setting the result to zero. Or is this done to match actual hardware behaviour?

I havent had a change to run on the real hardware, but on the system simulator, it happily
returns extracted content even if UIMM > 12.

Quoted 7 lines
Quoted 1 line

Hm. Returns what exactly?

So for LE case extracting from 15 returns following, basically its rounding up to 0.

xxextractuw: 15 - ooTSET a si sihT

                  ________ihTo____

Ok. IIRC your implementation did not do this - it set the "overflowed" bytes to 0 instead of wrapping round and taking them from the other end of the input. If think we should either match hardware behaviour or simply trap here, rather than do something else.

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#11 lore raw

Re: [Qemu-devel] [Qemu-ppc] [PATCH v2 5/6] target-ppc: implement xxextractuw instruction

Quoted 30 lines · David Gibson

[ Unknown signature status ]

Quoted 27 lines · Nikunj A Dadhania
Quoted 17 lines · David Gibson

[ Unknown signature status ]

Quoted 15 lines · Nikunj Dadhania
Quoted 13 lines · David Gibson

target-ppc/translate/vsx-impl.inc.c static void gen_xxsldwi(DisasContext *ctx) · line 1197

Quoted 6 lines · Nikunj A Dadhania

xxextractuw: VSX Vector Extract Unsigned Word

target-ppc/translate/vsx-impl.inc.c +3 -0
+        tcg_gen_movi_i64(cpu_vsrh(xT(ctx->opcode)), 0);         \
+        tcg_gen_movi_i64(cpu_vsrl(xT(ctx->opcode)), 0);         \
+        return;                                                 \

So, I know the architecture says it is undefined. But since you're testing for the bogus case anyway, why not turn this into an exception. That seems like it would be more helpful for debugging the guest than just setting the result to zero. Or is this done to match actual hardware behaviour?

Quoted 5 lines
Quoted 3 lines

I havent had a change to run on the real hardware, but on the system simulator, it happily
returns extracted content even if UIMM > 12.

Hm. Returns what exactly?

So for LE case extracting from 15 returns following, basically its rounding up to 0.

Quoted 7 lines
Quoted 2 lines

xxextractuw: 15 - ooTSET a si sihT

                  ________ihTo____

Ok. IIRC your implementation did not do this - it set the "overflowed" bytes to 0 instead of wrapping round and taking them from the other end of the input. If think we should either match hardware behaviour or simply trap here, rather than do something else.

Sure, will update and send the patch matching hardware behaviour.

Regards
Nikunj