target/mips: Translate MSA vector load/store opcodes
v5 cover target/mips: Translate MSA vector load/store opcodes
Since v4:
- No algorithm change
- Split to ease review
Hi Richard,
I tried to implement your suggestion from v3 [*]. Unfortunately the box where I had the MSA test suite got erased, so it will take me some time to restore the setup. I was surprised these patches pass our CI tests so I added a pair of abort() which didn't fire, so this code path isn't tested at all there. Anyhow, do you mind having a quick look to see this is going in the right direction?
Thanks!
Phil.
[*] https://lore.kernel.org/qemu-devel/[email protected]/
Philippe Mathieu-Daudé (6):
target/mips: Expand TRANS_DF_iv() macro for MSA Load/Store target/mips: Convert MSA LD/ST.B (Byte Vector) target/mips: Convert MSA LD/ST.H (Halfword Vector) target/mips: Convert MSA LD/ST.W (Word Vector) target/mips: Convert MSA LD/ST.D (Doubleword Vector) target/mips: Endian-swap MSA LD/ST.D (Doubleword Vector)
target/mips/tcg/msa_helper.h.inc | 9 -- target/mips/tcg/msa_helper.c | 176 ------------------------------- target/mips/tcg/msa_translate.c | 93 +++++++++++++--- 3 files changed, 81 insertions(+), 197 deletions(-)
Signature · 1 line
2.53.0
RFC PATCH v5 1/6 target/mips: Expand TRANS_DF_iv() macro for MSA Load/Store
In order to ease the conversion of MSA Load/Store runtime helpers to translated code, expand the TRANS_DF_iv() macro.
--- target/mips/tcg/msa_translate.c | 59 ++++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 12 deletions(-)
target/mips/tcg/msa_translate.c +47 -12
@@ -164,7 +164,6 @@ static inline bool check_msa_enabled(DisasContext *ctx)return true; } -typedef void gen_helper_piv (TCGv_ptr ,TCGv_i32 ,TCGv );typedef void gen_helper_pii (TCGv_ptr ,TCGv_i32 ,TCGv_i32 );typedef void gen_helper_piii (TCGv_ptr ,TCGv_i32 ,TCGv_i32 ,TCGv_i32 );typedef void gen_helper_piiii (TCGv_ptr ,TCGv_i32 ,TCGv_i32 ,TCGv_i32 ,TCGv_i32 );
@@ -175,9 +174,6 @@ typedef void gen_helper_piiii(TCGv_ptr, TCGv_i32, TCGv_i32, TCGv_i32, TCGv_i32); }; \ TRANS(NAME, trans_func, NAME##_tab[a->df]) -#define TRANS_DF_iv (NAME , trans_func, gen_func) \ - TRANS_DF_x(iv, NAME, trans_func, gen_func) -#define TRANS_DF_ii (NAME , trans_func, gen_func) \ TRANS_DF_x(ii, NAME, trans_func, gen_func)
@@ -758,25 +754,64 @@ TRANS(FTINT_U, trans_msa_2rf, gen_helper_msa_ftint_u_df);TRANS (FFINT_S , trans_msa_2rf, gen_helper_msa_ffint_s_df);TRANS (FFINT_U , trans_msa_2rf, gen_helper_msa_ffint_u_df); -static bool trans_msa_ldst (DisasContext *ctx,arg_msa_i *a, -gen_helper_piv *gen_msa_ldst) +static bool trans_msa_ldst (DisasContext *ctx,arg_msa_i *a,bool is_load) { -TCGv taddr; +TCGv_i32 wd; +TCGv_va addr;if (!check_msa_enabled (ctx)) {return true; } - taddr =tcg_temp_new (); + addr =tcgv_va_temp_new (); +gen_base_offset_addr (ctx, addr, a->ws, a->sa << a->df); -gen_base_offset_addr (ctx, taddr, a->ws, a->sa << a->df); -gen_msa_ldst (tcg_env,tcg_constant_i32 (a->wd), taddr); + wd =tcg_constant_i32 (a->wd); + +if (is_load) { +switch (a->df) { +case 0 : +gen_helper_msa_ld_b (tcg_env, wd, addr); +return true; +case 1 : +gen_helper_msa_ld_h (tcg_env, wd, addr); +return true; +case 2 : +gen_helper_msa_ld_w (tcg_env, wd, addr); +return true; +case 3 : +gen_helper_msa_ld_d (tcg_env, wd, addr); +return true; + } + }else { +switch (a->df) { +case 0 : +gen_helper_msa_st_b (tcg_env, wd, addr); +return true; +case 1 : +gen_helper_msa_st_h (tcg_env, wd, addr); +return true; +case 2 : +gen_helper_msa_st_w (tcg_env, wd, addr); +return true; +case 3 : +gen_helper_msa_st_d (tcg_env, wd, addr); +return true; + } + }return true; } -TRANS_DF_iv (LD , trans_msa_ldst, gen_helper_msa_ld); -TRANS_DF_iv (ST , trans_msa_ldst, gen_helper_msa_st); +static bool trans_LD (DisasContext *ctx,arg_msa_i *a) +{ +return trans_msa_ldst (ctx, a, true); +} + +static bool trans_ST (DisasContext *ctx,arg_msa_i *a) +{ +return trans_msa_ldst (ctx, a, false); +}static bool trans_LSA (DisasContext *ctx,arg_r *a) {
Signature · 1 line
2.53.0
Re: [RFC PATCH v5 1/6] target/mips: Expand TRANS_DF_iv() macro for MSA Load/Store
Quoted 7 lines · Philippe Mathieu-Daudé
In order to ease the conversion of MSA Load/Store runtime helpers to translated code, expand the
TRANS_DF_iv()macro.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/mips/tcg/msa_translate.c | 59 ++++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 12 deletions(-)
r~
Quoted 96 lines
target/mips/tcg/msa_translate.c +47
-12@@ -164,7 +164,6 @@ static inline bool check_msa_enabled(DisasContext *ctx)return true; } -typedef void gen_helper_piv (TCGv_ptr ,TCGv_i32 ,TCGv );typedef void gen_helper_pii (TCGv_ptr ,TCGv_i32 ,TCGv_i32 );typedef void gen_helper_piii (TCGv_ptr ,TCGv_i32 ,TCGv_i32 ,TCGv_i32 );typedef void gen_helper_piiii (TCGv_ptr ,TCGv_i32 ,TCGv_i32 ,TCGv_i32 ,TCGv_i32 );@@ -175,9 +174,6 @@ typedef void gen_helper_piiii(TCGv_ptr, TCGv_i32, TCGv_i32, TCGv_i32, TCGv_i32); }; \ TRANS(NAME, trans_func, NAME##_tab[a->df]) -#define TRANS_DF_iv (NAME , trans_func, gen_func) \ - TRANS_DF_x(iv, NAME, trans_func, gen_func) -#define TRANS_DF_ii (NAME , trans_func, gen_func) \ TRANS_DF_x(ii, NAME, trans_func, gen_func)@@ -758,25 +754,64 @@ TRANS(FTINT_U, trans_msa_2rf, gen_helper_msa_ftint_u_df);TRANS (FFINT_S , trans_msa_2rf, gen_helper_msa_ffint_s_df);TRANS (FFINT_U , trans_msa_2rf, gen_helper_msa_ffint_u_df); -static bool trans_msa_ldst (DisasContext *ctx,arg_msa_i *a, -gen_helper_piv *gen_msa_ldst) +static bool trans_msa_ldst (DisasContext *ctx,arg_msa_i *a,bool is_load) { -TCGv taddr; +TCGv_i32 wd; +TCGv_va addr;if (!check_msa_enabled (ctx)) {return true; } - taddr =tcg_temp_new (); + addr =tcgv_va_temp_new (); +gen_base_offset_addr (ctx, addr, a->ws, a->sa << a->df); -gen_base_offset_addr (ctx, taddr, a->ws, a->sa << a->df); -gen_msa_ldst (tcg_env,tcg_constant_i32 (a->wd), taddr); + wd =tcg_constant_i32 (a->wd); + +if (is_load) { +switch (a->df) { +case 0 : +gen_helper_msa_ld_b (tcg_env, wd, addr); +return true; +case 1 : +gen_helper_msa_ld_h (tcg_env, wd, addr); +return true; +case 2 : +gen_helper_msa_ld_w (tcg_env, wd, addr); +return true; +case 3 : +gen_helper_msa_ld_d (tcg_env, wd, addr); +return true; + } + }else { +switch (a->df) { +case 0 : +gen_helper_msa_st_b (tcg_env, wd, addr); +return true; +case 1 : +gen_helper_msa_st_h (tcg_env, wd, addr); +return true; +case 2 : +gen_helper_msa_st_w (tcg_env, wd, addr); +return true; +case 3 : +gen_helper_msa_st_d (tcg_env, wd, addr); +return true; + } + }return true; } -TRANS_DF_iv (LD , trans_msa_ldst, gen_helper_msa_ld); -TRANS_DF_iv (ST , trans_msa_ldst, gen_helper_msa_st); +static bool trans_LD (DisasContext *ctx,arg_msa_i *a) +{ +return trans_msa_ldst (ctx, a, true); +} + +static bool trans_ST (DisasContext *ctx,arg_msa_i *a) +{ +return trans_msa_ldst (ctx, a, false); +}static bool trans_LSA (DisasContext *ctx,arg_r *a) {
RFC PATCH v5 2/6 target/mips: Convert MSA LD/ST.B (Byte Vector)
In reply to Philippe Mathieu-DaudéReplace runtime helpers by translation.
Replace the legacy cpu_ld/st*_data_ra() calls by tcg_gen_qemu_ld/st() which allow to respect atomicity.
Consider the host endianness.
--- target/mips/tcg/msa_helper.h.inc | 1 - target/mips/tcg/msa_helper.c | 28 ---------------------------- target/mips/tcg/msa_translate.c | 30 ++++++++++++++++++++++++------ 3 files changed, 24 insertions(+), 35 deletions(-)
target/mips/tcg/msa_helper.h.inc +0 -1
@@ -436,7 +436,6 @@ DEF_HELPER_4(msa_ffint_u_df, void, env, i32, i32, i32) #define MSALDST_PROTO(type) \ DEF_HELPER_3(msa_ld_ ## type, void, env, i32, tl) \ DEF_HELPER_3(msa_st_ ## type, void, env, i32, tl) -MSALDST_PROTO(b) MSALDST_PROTO(h) MSALDST_PROTO(w) MSALDST_PROTO(d)
target/mips/tcg/msa_helper.c +0 -28
@@ -8223,20 +8223,6 @@ static inline uint64_t bswap32x2(uint64_t x)return ror64 (bswap64 (x),32 ); } -void helper_msa_ld_b (CPUMIPSState *env,uint32_t wd, -target_ulong addr) -{ -wr_t *pwd = &(env->active_fpu.fpr[wd].wr); -uintptr_t ra =GETPC (); -uint64_t d0, d1; - -/* Load 8 bytes at a time. Vector element ordering makes this LE. */ - d0 =cpu_ldq_le_data_ra (env, addr +0 , ra); - d1 =cpu_ldq_le_data_ra (env, addr +8 , ra); - pwd->d[0 ] = d0; - pwd->d[1 ] = d1; -} -void helper_msa_ld_h (CPUMIPSState *env,uint32_t wd,target_ulong addr) {
@@ -8310,20 +8296,6 @@ static inline void ensure_writable_pages(CPUMIPSState *env, } } -void helper_msa_st_b (CPUMIPSState *env,uint32_t wd, -target_ulong addr) -{ -wr_t *pwd = &(env->active_fpu.fpr[wd].wr); -int mmu_idx =mips_env_mmu_index (env); -uintptr_t ra =GETPC (); - -ensure_writable_pages (env, addr, mmu_idx, ra); - -/* Store 8 bytes at a time. Vector element ordering makes this LE. */ -cpu_stq_le_data_ra (env, addr +0 , pwd->d[0 ], ra); -cpu_stq_le_data_ra (env, addr +8 , pwd->d[1 ], ra); -} -void helper_msa_st_h (CPUMIPSState *env,uint32_t wd,target_ulong addr) {
target/mips/tcg/msa_translate.c +24 -6
@@ -756,8 +756,16 @@ TRANS(FFINT_U, trans_msa_2rf, gen_helper_msa_ffint_u_df);static bool trans_msa_ldst (DisasContext *ctx,arg_msa_i *a,bool is_load) { +static const MemOp mo_atom_df[4 ] = { +MO_ATOM_NONE , + };TCGv_i32 wd; +TCGv_i128 t16;TCGv_va addr; +MemOp mop; +int idx = a->wd <<1 ; +TCGv_i64 d0 = msa_wr_d[idx +FP_ENDIAN_IDX ]; +TCGv_i64 d1 = msa_wr_d[idx + !FP_ENDIAN_IDX ];if (!check_msa_enabled (ctx)) {return true;
@@ -770,9 +778,6 @@ static bool trans_msa_ldst(DisasContext *ctx, arg_msa_i *a, bool is_load)if (is_load) {switch (a->df) { -case 0 : -gen_helper_msa_ld_b (tcg_env, wd, addr); -return true;case 1 :gen_helper_msa_ld_h (tcg_env, wd, addr);return true;
@@ -785,9 +790,6 @@ static bool trans_msa_ldst(DisasContext *ctx, arg_msa_i *a, bool is_load) } }else {switch (a->df) { -case 0 : -gen_helper_msa_st_b (tcg_env, wd, addr); -return true;case 1 :gen_helper_msa_st_h (tcg_env, wd, addr);return true;
@@ -800,6 +802,22 @@ static bool trans_msa_ldst(DisasContext *ctx, arg_msa_i *a, bool is_load) } } + t16 =tcg_temp_new_i128 (); + + mop =MO_128 |MO_LE ; + mop |= a->df <<MO_ASHIFT ;/* MO_ALIGN */ + mop |= mo_atom_df[a->df]; + +if (is_load) { +tcg_gen_qemu_ld_i128 (t16, addr, ctx->mem_idx, mop); +tcg_gen_extr_i128_i64 (d0, d1, t16); + } + +if (!is_load) { +tcg_gen_concat_i64_i128 (t16, d0, d1); +tcg_gen_qemu_st_i128 (t16, addr, ctx->mem_idx, mop); + } +return true; }
Signature · 1 line
2.53.0
Re: [RFC PATCH v5 2/6] target/mips: Convert MSA LD/ST.B (Byte Vector)
Quoted 5 lines · Philippe Mathieu-Daudé
Replace runtime helpers by translation.
Replace the legacy cpu_ld/st*_data_ra() calls by tcg_gen_qemu_ld/st() which allow to respect atomicity.
Quoted 8 lines
Consider the host endianness.
Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- target/mips/tcg/msa_helper.h.inc | 1 - target/mips/tcg/msa_helper.c | 28 ---------------------------- target/mips/tcg/msa_translate.c | 30 ++++++++++++++++++++++++------ 3 files changed, 24 insertions(+), 35 deletions(-)
r~
RFC PATCH v5 3/6 target/mips: Convert MSA LD/ST.H (Halfword Vector)
In reply to Philippe Mathieu-DaudéReplace runtime helpers by translation.
Replace the legacy cpu_ld/st*_data_ra() calls by tcg_gen_qemu_ld/st() which allow to respect atomicity.
--- target/mips/tcg/msa_helper.h.inc | 1 - target/mips/tcg/msa_helper.c | 48 -------------------------------- target/mips/tcg/msa_translate.c | 32 +++++++++++++++++---- 3 files changed, 26 insertions(+), 55 deletions(-)
target/mips/tcg/msa_helper.h.inc +0 -1
@@ -436,7 +436,6 @@ DEF_HELPER_4(msa_ffint_u_df, void, env, i32, i32, i32) #define MSALDST_PROTO(type) \ DEF_HELPER_3(msa_ld_ ## type, void, env, i32, tl) \ DEF_HELPER_3(msa_st_ ## type, void, env, i32, tl) -MSALDST_PROTO(h) MSALDST_PROTO(w) MSALDST_PROTO(d) #undef MSALDST_PROTO
target/mips/tcg/msa_helper.c +0 -48
65 lines not on this page · raw message
target/mips/tcg/msa_translate.c +26 -6
@@ -754,10 +754,27 @@ TRANS(FTINT_U, trans_msa_2rf, gen_helper_msa_ftint_u_df);TRANS (FFINT_S , trans_msa_2rf, gen_helper_msa_ffint_s_df);TRANS (FFINT_U , trans_msa_2rf, gen_helper_msa_ffint_u_df); +/* +* Byte pattern: ab.cd.ef.gh -> ba.dc.fe.bg +*/ +static void gen_bswap16x4_i64 (TCGv_i64 dst,TCGv_i64 src) +{ +uint64_t m =0x00ff00ff00ff00ffull ; +TCGv_i64 t0 =tcg_temp_new_i64 (); +TCGv_i64 t1 =tcg_temp_new_i64 (); +/* src = abcdefgh */ +tcg_gen_andi_i64 (t0, src, m);/* t0 = .b.d.f.h */ +tcg_gen_shli_i64 (t0, t0,8 );/* t0 = b.d.f.h. */ +tcg_gen_shri_i64 (t1, src,8 );/* t1 = habcdefg */ +tcg_gen_andi_i64 (t1, t1, m);/* t1 = .a.c.e.g */ +tcg_gen_or_i64 (dst, t0, t1);/* dst = badcfebg */ +} +static bool trans_msa_ldst (DisasContext *ctx,arg_msa_i *a,bool is_load) {static const MemOp mo_atom_df[4 ] = {MO_ATOM_NONE , +MO_ATOM_SUBALIGN ,/* Slightly stronger than required */ };TCGv_i32 wd;TCGv_i128 t16;
@@ -778,9 +795,6 @@ static bool trans_msa_ldst(DisasContext *ctx, arg_msa_i *a, bool is_load)if (is_load) {switch (a->df) { -case 1 : -gen_helper_msa_ld_h (tcg_env, wd, addr); -return true;case 2 :gen_helper_msa_ld_w (tcg_env, wd, addr);return true;
@@ -790,9 +804,6 @@ static bool trans_msa_ldst(DisasContext *ctx, arg_msa_i *a, bool is_load) } }else {switch (a->df) { -case 1 : -gen_helper_msa_st_h (tcg_env, wd, addr); -return true;case 2 :gen_helper_msa_st_w (tcg_env, wd, addr);return true;
@@ -813,6 +824,15 @@ static bool trans_msa_ldst(DisasContext *ctx, arg_msa_i *a, bool is_load)tcg_gen_extr_i128_i64 (d0, d1, t16); } +if (mo_endian (ctx) !=MO_LE ) { +switch (a->df) { +case 1 : +gen_bswap16x4_i64 (d0, d0); +gen_bswap16x4_i64 (d1, d1); +break ; + } + } +if (!is_load) {tcg_gen_concat_i64_i128 (t16, d0, d1);tcg_gen_qemu_st_i128 (t16, addr, ctx->mem_idx, mop);
Signature · 1 line
2.53.0
Re: [RFC PATCH v5 3/6] target/mips: Convert MSA LD/ST.H (Halfword Vector)
Quoted 6 lines · Philippe Mathieu-Daudé
target/mips/tcg/msa_translate.c +2
-0@@ -813,6 +824,15 @@ static bool trans_msa_ldst(DisasContext *ctx, arg_msa_i *a, bool is_load)tcg_gen_extr_i128_i64 (d0, d1, t16); } +if (mo_endian (ctx) !=MO_LE ) { +switch (a->df) {
target/mips/tcg/msa_translate.c static bool trans_msa_ldst(DisasContext *ctx, arg_msa_i *a, bool is_load) · line 838
Quoted 10 lines
target/mips/tcg/msa_translate.c +7
-0+case 1 : +gen_bswap16x4_i64 (d0, d0); +gen_bswap16x4_i64 (d1, d1); +break ; + } + } +if (!is_load) {tcg_gen_concat_i64_i128 (t16, d0, d1);tcg_gen_qemu_st_i128 (t16, addr, ctx->mem_idx, mop);
You've just bswaped the architectural registers.
You need new temporaries here.
r~
Re: [RFC PATCH v5 3/6] target/mips: Convert MSA LD/ST.H (Halfword Vector)
Quoted 12 lines · Richard Henderson
Quoted 11 lines · Philippe Mathieu-Daudé
target/mips/tcg/msa_translate.c +7
-0@@ -813,6 +824,15 @@ static bool trans_msa_ldst(DisasContext *ctx, arg_msa_i *a, bool is_load) tcg_gen_extr_i128_i64(d0, d1, t16); } + if (mo_endian(ctx) != MO_LE) { + switch (a->df) { + case 1: + gen_bswap16x4_i64(d0, d0); + gen_bswap16x4_i64(d1, d1); + break; + }
Quoted 8 lines
target/mips/tcg/msa_translate.c static bool trans_msa_ldst(DisasContext *ctx, arg_msa_i *a, bool is_load) · line 838
Quoted 5 lines
target/mips/tcg/msa_translate.c +2
-0+ } + if (!is_load) { tcg_gen_concat_i64_i128(t16, d0, d1); tcg_gen_qemu_st_i128(t16, addr, ctx->mem_idx, mop);You've just bswaped the architectural registers.
You need new temporaries here...
... for stores.
Hit send too soon. :-)
r~
RFC PATCH v5 4/6 target/mips: Convert MSA LD/ST.W (Word Vector)
In reply to Philippe Mathieu-DaudéReplace runtime helpers by translation.
Replace the legacy cpu_ld/st*_data_ra() calls by tcg_gen_qemu_ld/st() which allow to respect atomicity.
--- target/mips/tcg/msa_helper.h.inc | 1 - target/mips/tcg/msa_helper.c | 47 -------------------------------- target/mips/tcg/msa_translate.c | 20 ++++++++++---- 3 files changed, 14 insertions(+), 54 deletions(-)
target/mips/tcg/msa_helper.h.inc +0 -1
@@ -436,6 +436,5 @@ DEF_HELPER_4(msa_ffint_u_df, void, env, i32, i32, i32) #define MSALDST_PROTO(type) \ DEF_HELPER_3(msa_ld_ ## type, void, env, i32, tl) \ DEF_HELPER_3(msa_st_ ## type, void, env, i32, tl) -MSALDST_PROTO(w) MSALDST_PROTO(d) #undef MSALDST_PROTO
target/mips/tcg/msa_helper.c +0 -47
59 lines not on this page · raw message
target/mips/tcg/msa_translate.c +14 -6
@@ -770,11 +770,21 @@ static void gen_bswap16x4_i64(TCGv_i64 dst, TCGv_i64 src)tcg_gen_or_i64 (dst, t0, t1);/* dst = badcfebg */ } +/* +* Byte pattern: abcd.efgh -> dcba.hgfe +*/ +static void gen_bswap32x2_i64 (TCGv_i64 dst,TCGv_i64 src) +{ +tcg_gen_bswap64_i64 (dst, src); +tcg_gen_rotri_i64 (dst, dst,32 ); +} +static bool trans_msa_ldst (DisasContext *ctx,arg_msa_i *a,bool is_load) {static const MemOp mo_atom_df[4 ] = {MO_ATOM_NONE ,MO_ATOM_SUBALIGN ,/* Slightly stronger than required */ +MO_ATOM_SUBALIGN ,/* Slightly stronger than required */ };TCGv_i32 wd;TCGv_i128 t16;
@@ -795,18 +805,12 @@ static bool trans_msa_ldst(DisasContext *ctx, arg_msa_i *a, bool is_load)if (is_load) {switch (a->df) { -case 2 : -gen_helper_msa_ld_w (tcg_env, wd, addr); -return true;case 3 :gen_helper_msa_ld_d (tcg_env, wd, addr);return true; } }else {switch (a->df) { -case 2 : -gen_helper_msa_st_w (tcg_env, wd, addr); -return true;case 3 :gen_helper_msa_st_d (tcg_env, wd, addr);return true;
@@ -830,6 +834,10 @@ static bool trans_msa_ldst(DisasContext *ctx, arg_msa_i *a, bool is_load)gen_bswap16x4_i64 (d0, d0);gen_bswap16x4_i64 (d1, d1);break ; +case 2 : +gen_bswap32x2_i64 (d0, d0); +gen_bswap32x2_i64 (d1, d1); +break ; } }
Signature · 1 line
2.53.0
Re: [RFC PATCH v5 4/6] target/mips: Convert MSA LD/ST.W (Word Vector)
Quoted 11 lines · Philippe Mathieu-Daudé
Replace runtime helpers by translation.
Replace the legacy cpu_ld/st*_data_ra() calls by tcg_gen_qemu_ld/st() which allow to respect atomicity.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/mips/tcg/msa_helper.h.inc | 1 - target/mips/tcg/msa_helper.c | 47 -------------------------------- target/mips/tcg/msa_translate.c | 20 ++++++++++---- 3 files changed, 14 insertions(+), 54 deletions(-)
Modulo new temps for store,
r~
Quoted 133 lines
target/mips/tcg/msa_helper.h.inc +0
-1@@ -436,6 +436,5 @@ DEF_HELPER_4(msa_ffint_u_df, void, env, i32, i32, i32) #define MSALDST_PROTO(type) \ DEF_HELPER_3(msa_ld_ ## type, void, env, i32, tl) \ DEF_HELPER_3(msa_st_ ## type, void, env, i32, tl) -MSALDST_PROTO(w) MSALDST_PROTO(d) #undef MSALDST_PROTOtarget/mips/tcg/msa_helper.c +0
-47@@ -8212,32 +8212,6 @@ void helper_msa_ffint_u_df(CPUMIPSState *env, uint32_t df, uint32_t wd,/* Element-by-element access macros */ #define DF_ELEMENTS (df) (MSA_WRLEN / DF_BITS(df)) -static inline uint64_t bswap32x2 (uint64_t x) -{ -return ror64 (bswap64 (x),32 ); -} - -void helper_msa_ld_w (CPUMIPSState *env,uint32_t wd, -target_ulong addr) -{ -wr_t *pwd = &(env->active_fpu.fpr[wd].wr); -uintptr_t ra =GETPC (); -uint64_t d0, d1; - -/* -* Load 8 bytes at a time. Use little-endian load, then for -* big-endian target, we must then bswap the two words. -*/ - d0 =cpu_ldq_le_data_ra (env, addr +0 , ra); - d1 =cpu_ldq_le_data_ra (env, addr +8 , ra); -if (mips_env_is_bigendian (env)) { - d0 =bswap32x2 (d0); - d1 =bswap32x2 (d1); - } - pwd->d[0 ] = d0; - pwd->d[1 ] = d1; -} -void helper_msa_ld_d (CPUMIPSState *env,uint32_t wd,target_ulong addr) {@@ -8269,27 +8243,6 @@ static inline void ensure_writable_pages(CPUMIPSState *env, } } -void helper_msa_st_w (CPUMIPSState *env,uint32_t wd, -target_ulong addr) -{ -wr_t *pwd = &(env->active_fpu.fpr[wd].wr); -int mmu_idx =mips_env_mmu_index (env); -uintptr_t ra =GETPC (); -uint64_t d0, d1; - -ensure_writable_pages (env, addr, mmu_idx, ra); - -/* Store 8 bytes at a time. See helper_msa_ld_w. */ - d0 = pwd->d[0 ]; - d1 = pwd->d[1 ]; -if (mips_env_is_bigendian (env)) { - d0 =bswap32x2 (d0); - d1 =bswap32x2 (d1); - } -cpu_stq_le_data_ra (env, addr +0 , d0, ra); -cpu_stq_le_data_ra (env, addr +8 , d1, ra); -} -void helper_msa_st_d (CPUMIPSState *env,uint32_t wd,target_ulong addr) {target/mips/tcg/msa_translate.c +14
-6@@ -770,11 +770,21 @@ static void gen_bswap16x4_i64(TCGv_i64 dst, TCGv_i64 src)tcg_gen_or_i64 (dst, t0, t1);/* dst = badcfebg */ } +/* +* Byte pattern: abcd.efgh -> dcba.hgfe +*/ +static void gen_bswap32x2_i64 (TCGv_i64 dst,TCGv_i64 src) +{ +tcg_gen_bswap64_i64 (dst, src); +tcg_gen_rotri_i64 (dst, dst,32 ); +} +static bool trans_msa_ldst (DisasContext *ctx,arg_msa_i *a,bool is_load) {static const MemOp mo_atom_df[4 ] = {MO_ATOM_NONE ,MO_ATOM_SUBALIGN ,/* Slightly stronger than required */ +MO_ATOM_SUBALIGN ,/* Slightly stronger than required */ };TCGv_i32 wd;TCGv_i128 t16;@@ -795,18 +805,12 @@ static bool trans_msa_ldst(DisasContext *ctx, arg_msa_i *a, bool is_load)if (is_load) {switch (a->df) { -case 2 : -gen_helper_msa_ld_w (tcg_env, wd, addr); -return true;case 3 :gen_helper_msa_ld_d (tcg_env, wd, addr);return true; } }else {switch (a->df) { -case 2 : -gen_helper_msa_st_w (tcg_env, wd, addr); -return true;case 3 :gen_helper_msa_st_d (tcg_env, wd, addr);return true;@@ -830,6 +834,10 @@ static bool trans_msa_ldst(DisasContext *ctx, arg_msa_i *a, bool is_load)gen_bswap16x4_i64 (d0, d0);gen_bswap16x4_i64 (d1, d1);break ; +case 2 : +gen_bswap32x2_i64 (d0, d0); +gen_bswap32x2_i64 (d1, d1); +break ; } }
RFC PATCH v5 5/6 target/mips: Convert MSA LD/ST.D (Doubleword Vector)
In reply to Philippe Mathieu-DaudéReplace runtime helpers by translation.
Replace the legacy cpu_ld/st*_data_ra() calls by tcg_gen_qemu_ld/st() which allow to respect atomicity.
Remove the ensure_writable_pages() hack and MSALDST_PROTO macro.
--- target/mips/tcg/msa_helper.h.inc | 6 ---- target/mips/tcg/msa_helper.c | 53 -------------------------------- target/mips/tcg/msa_translate.c | 18 +---------- 3 files changed, 1 insertion(+), 76 deletions(-)
target/mips/tcg/msa_helper.h.inc +0 -6
@@ -432,9 +432,3 @@ DEF_HELPER_4(msa_ftint_s_df, void, env, i32, i32, i32) DEF_HELPER_4(msa_ftint_u_df, void, env, i32, i32, i32) DEF_HELPER_4(msa_ffint_s_df, void, env, i32, i32, i32) DEF_HELPER_4(msa_ffint_u_df, void, env, i32, i32, i32) - -#define MSALDST_PROTO(type) \ -DEF_HELPER_3(msa_ld_ ## type, void, env, i32, tl) \ -DEF_HELPER_3(msa_st_ ## type, void, env, i32, tl) -MSALDST_PROTO(d) -#undef MSALDST_PROTO
target/mips/tcg/msa_helper.c +0 -53
64 lines not on this page · raw message
target/mips/tcg/msa_translate.c +1 -17
@@ -785,8 +785,8 @@ static bool trans_msa_ldst(DisasContext *ctx, arg_msa_i *a, bool is_load)MO_ATOM_NONE ,MO_ATOM_SUBALIGN ,/* Slightly stronger than required */ MO_ATOM_SUBALIGN ,/* Slightly stronger than required */ + MO_ATOM_IFALIGN_PAIR }; -TCGv_i32 wd;TCGv_i128 t16;TCGv_va addr;MemOp mop;
@@ -801,22 +801,6 @@ static bool trans_msa_ldst(DisasContext *ctx, arg_msa_i *a, bool is_load) addr =tcgv_va_temp_new ();gen_base_offset_addr (ctx, addr, a->ws, a->sa << a->df); - wd =tcg_constant_i32 (a->wd); - -if (is_load) { -switch (a->df) { -case 3 : -gen_helper_msa_ld_d (tcg_env, wd, addr); -return true; - } - }else { -switch (a->df) { -case 3 : -gen_helper_msa_st_d (tcg_env, wd, addr); -return true; - } - } - t16 =tcg_temp_new_i128 (); mop =MO_128 |MO_LE ;
Signature · 1 line
2.53.0
Re: [RFC PATCH v5 5/6] target/mips: Convert MSA LD/ST.D (Doubleword Vector)
Quoted 88 lines · Philippe Mathieu-Daudé
Replace runtime helpers by translation.
Replace the legacy cpu_ld/st*_data_ra() calls by tcg_gen_qemu_ld/st() which allow to respect atomicity.
Remove the
ensure_writable_pages()hack andMSALDST_PROTOmacro.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/mips/tcg/msa_helper.h.inc | 6 ---- target/mips/tcg/msa_helper.c | 53 -------------------------------- target/mips/tcg/msa_translate.c | 18 +---------- 3 files changed, 1 insertion(+), 76 deletions(-)target/mips/tcg/msa_helper.h.inc +0
-6@@ -432,9 +432,3 @@ DEF_HELPER_4(msa_ftint_s_df, void, env, i32, i32, i32) DEF_HELPER_4(msa_ftint_u_df, void, env, i32, i32, i32) DEF_HELPER_4(msa_ffint_s_df, void, env, i32, i32, i32) DEF_HELPER_4(msa_ffint_u_df, void, env, i32, i32, i32) - -#define MSALDST_PROTO(type) \ -DEF_HELPER_3(msa_ld_ ## type, void, env, i32, tl) \ -DEF_HELPER_3(msa_st_ ## type, void, env, i32, tl) -MSALDST_PROTO(d) -#undef MSALDST_PROTOtarget/mips/tcg/msa_helper.c +0
-43@@ -21,11 +21,8 @@#include "cpu.h" #include "internal.h" #include "tcg/tcg.h" -#include "accel/tcg/cpu-ldst.h" -#include "accel/tcg/probe.h" #include "exec/helper-proto.h" #include "exec/memop.h" -#include "exec/target_page.h" #include "fpu/softfloat.h" #include "fpu_helper.h" @@ -8205,53 +8202,3 @@ void helper_msa_ffint_u_df(CPUMIPSState *env, uint32_t df, uint32_t wd,msa_move_v (pwd, pwx); } - -/* Data format min and max values */ -#define DF_BITS (df) (1 << ((df) + 3)) - -/* Element-by-element access macros */ -#define DF_ELEMENTS (df) (MSA_WRLEN / DF_BITS(df)) - -void helper_msa_ld_d (CPUMIPSState *env,uint32_t wd, -target_ulong addr) -{ -wr_t *pwd = &(env->active_fpu.fpr[wd].wr); -uintptr_t ra =GETPC (); -uint64_t d0, d1; - - d0 =cpu_ldq_data_ra (env, addr +0 , ra); - d1 =cpu_ldq_data_ra (env, addr +8 , ra); - pwd->d[0 ] = d0; - pwd->d[1 ] = d1; -} - -#define MSA_PAGESPAN (x) \ - ((((x) & ~TARGET_PAGE_MASK) + MSA_WRLEN / 8 - 1) >= TARGET_PAGE_SIZE) - -static inline void ensure_writable_pages (CPUMIPSState *env, -target_ulong addr, -int mmu_idx, -uintptr_t retaddr) -{ -/* FIXME: Probe the actual accesses (pass and use a size) */ -if (unlikely (MSA_PAGESPAN (addr))) { -/* first page */ -probe_write (env, addr,0 , mmu_idx, retaddr); -/* second page */ - addr = (addr &TARGET_PAGE_MASK ) +TARGET_PAGE_SIZE ; -probe_write (env, addr,0 , mmu_idx, retaddr); - } -} - -void helper_msa_st_d (CPUMIPSState *env,uint32_t wd, -target_ulong addr)
target/mips/tcg/msa_helper.c void helper_msa_ffint_u_df(CPUMIPSState *env, uint32_t df, uint32_t wd, · line 8257
Quoted 10 lines
target/mips/tcg/msa_helper.c +0
-10-{ -wr_t *pwd = &(env->active_fpu.fpr[wd].wr); -int mmu_idx =mips_env_mmu_index (env); -uintptr_t ra =GETPC (); - -ensure_writable_pages (env, addr, mmu_idx,GETPC ()); - -cpu_stq_data_ra (env, addr +0 , pwd->d[0 ], ra); -cpu_stq_data_ra (env, addr +8 , pwd->d[1 ], ra); -}
This isn't using a LE operation...
Quoted 27 lines
target/mips/tcg/msa_translate.c +1
-10@@ -785,8 +785,8 @@ static bool trans_msa_ldst(DisasContext *ctx, arg_msa_i *a, bool is_load)MO_ATOM_NONE ,MO_ATOM_SUBALIGN ,/* Slightly stronger than required */ MO_ATOM_SUBALIGN ,/* Slightly stronger than required */ + MO_ATOM_IFALIGN_PAIR }; -TCGv_i32 wd;TCGv_i128 t16;TCGv_va addr;MemOp mop;@@ -801,22 +801,6 @@ static bool trans_msa_ldst(DisasContext *ctx, arg_msa_i *a, bool is_load) addr =tcgv_va_temp_new ();gen_base_offset_addr (ctx, addr, a->ws, a->sa << a->df); - wd =tcg_constant_i32 (a->wd); - -if (is_load) { -switch (a->df) { -case 3 : -gen_helper_msa_ld_d (tcg_env, wd, addr); -return true; - } - }else {
target/mips/tcg/msa_translate.c static bool trans_msa_ldst(DisasContext *ctx, arg_msa_i *a, bool is_load) · line 806
Quoted 10 lines
target/mips/tcg/msa_translate.c +0
-7-switch (a->df) { -case 3 : -gen_helper_msa_st_d (tcg_env, wd, addr); -return true; - } - } - t16 =tcg_temp_new_i128 (); mop =MO_128 |MO_LE ;
... which you're now getting from here.
You could bswap d0 and d1, or you could have the 64-bit path reorder d0 and d1 in t16 and mop ^= MO_BSWAP.
r~
RFC PATCH v5 6/6 target/mips: Endian-swap MSA LD/ST.D (Doubleword Vector)
In reply to Philippe Mathieu-DaudéDoubleword Vector entries need to be swapped w.r.t. endianness.
Fixes: 83be6b54123 ("Fix MSA instructions LD.<B|H|W|D> on big endian host")
Fixes: 6decc572dce ("Fix MSA instructions ST.<B|H|W|D> on big endian host")---
Probably optimizable since tcg_gen_qemu_ld/st_i128 handles MO_BSWAP.
--- target/mips/tcg/msa_translate.c | 4 ++++ 1 file changed, 4 insertions(+)
target/mips/tcg/msa_translate.c +4 -0
@@ -822,6 +822,10 @@ static bool trans_msa_ldst(DisasContext *ctx, arg_msa_i *a, bool is_load)gen_bswap32x2_i64 (d0, d0);gen_bswap32x2_i64 (d1, d1);break ; +case 3 : +tcg_gen_bswap64_i64 (d0, d0); +tcg_gen_bswap64_i64 (d1, d1); +break ; } }
Signature · 1 line
2.53.0
Re: [RFC PATCH v5 6/6] target/mips: Endian-swap MSA LD/ST.D (Doubleword Vector)
Quoted 16 lines · Philippe Mathieu-Daudé
Doubleword Vector entries need to be swapped w.r.t. endianness.
Fixes: 83be6b54123 ("Fix MSA instructions LD.<B|H|W|D> on big endian host") Fixes: 6decc572dce ("Fix MSA instructions ST.<B|H|W|D> on big endian host")Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
Probably optimizable since tcg_gen_qemu_ld/st_i128 handlesMO_BSWAP.--- target/mips/tcg/msa_translate.c | 4 ++++ 1 file changed, 4 insertions(+)target/mips/tcg/msa_translate.c +0
-0
target/mips/tcg/msa_translate.c static bool trans_msa_ldst(DisasContext *ctx, arg_msa_i *a, bool is_load) · line 831
Quoted 10 lines
target/mips/tcg/msa_translate.c +4
-0@@ -822,6 +822,10 @@ static bool trans_msa_ldst(DisasContext *ctx, arg_msa_i *a, bool is_load)gen_bswap32x2_i64 (d0, d0);gen_bswap32x2_i64 (d1, d1);break ; +case 3 : +tcg_gen_bswap64_i64 (d0, d0); +tcg_gen_bswap64_i64 (d1, d1); +break ; } }
No, this is just a fix to patch 5.
r~