target/mips: Translate MSA vector load/store opcodes
v6 cover target/mips: Translate MSA vector load/store opcodes
Missing review: 3 and 5
Since v5:
- Rebased
- Swap temporaries during store (rth)
- Bswap d0 and d1 in ST.D (rth)
Since v4:
- No algorithm change
- Split to ease review
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) accel/tcg: Remove non-explicit endian cpu_ld/st*_data*() helpers
docs/devel/loads-stores.rst | 18 +-- include/accel/tcg/cpu-ldst.h | 48 -------- target/mips/tcg/msa_helper.h.inc | 9 -- target/mips/tcg/msa_helper.c | 186 ------------------------------- target/mips/tcg/msa_translate.c | 106 ++++++++++++++++-- 5 files changed, 103 insertions(+), 264 deletions(-)
Signature · 1 line
2.55.0
PATCH v6 1/6 target/mips: Expand TRANS_DF_iv() macro for MSA Load/Store
From: Philippe Mathieu-Daudé <[email protected]>
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.55.0
PATCH v6 2/6 target/mips: Convert MSA LD/ST.B (Byte Vector)
In reply to Philippe Mathieu-DaudéFrom: Philippe Mathieu-Daudé <[email protected]>
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 | 29 +++++++++++++++++++++++------ 3 files changed, 23 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
@@ -8237,20 +8237,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) {
@@ -8329,20 +8315,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 +23 -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,21 @@ 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 |= 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.55.0
PATCH v6 3/6 target/mips: Convert MSA LD/ST.H (Halfword Vector)
In reply to Philippe Mathieu-DaudéFrom: Philippe Mathieu-Daudé <[email protected]>
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 | 42 ++++++++++++++++++++++++---- 3 files changed, 36 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 +36 -6
70 lines not on this page · raw message
Signature · 1 line
2.55.0
PATCH v6 4/6 target/mips: Convert MSA LD/ST.W (Word Vector)
In reply to Philippe Mathieu-DaudéFrom: Philippe Mathieu-Daudé <[email protected]>
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;
@@ -839,6 +843,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.55.0
PATCH v6 5/6 target/mips: Convert MSA LD/ST.D (Doubleword Vector)
In reply to Philippe Mathieu-DaudéFrom: Philippe Mathieu-Daudé <[email protected]>
Replace runtime helpers by translation.
BE LD.D/ST.D now uses MO_BE with exchanged half handles; no explicit D swaps or store-copy temporaries.
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 | 63 -------------------------------- target/mips/tcg/msa_translate.c | 28 +++++--------- 3 files changed, 10 insertions(+), 87 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 -63
74 lines not on this page · raw message
target/mips/tcg/msa_translate.c +10 -18
@@ -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,33 +801,25 @@ 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 ; mop |= mo_atom_df[a->df]; +if (a->df ==3 &&mo_endian (ctx) !=MO_LE ) { +TCGv_i64 saved_d0 = d0; + + mop = (mop & ~MO_BSWAP ) |MO_BE ; + d0 = d1; + d1 = saved_d0; + } +if (is_load) {tcg_gen_qemu_ld_i128 (t16, addr, ctx->mem_idx, mop);tcg_gen_extr_i128_i64 (d0, d1, t16); } -if (mo_endian (ctx) !=MO_LE ) { +if (mo_endian (ctx) !=MO_LE && a->df !=3 ) {if (!is_load) {TCGv_i64 temp_d0 =tcg_temp_new_i64 ();TCGv_i64 temp_d1 =tcg_temp_new_i64 ();
Signature · 1 line
2.55.0
PATCH v6 6/6 accel/tcg: Remove non-explicit endian cpu_ld/st*_data*() helpers
In reply to Philippe Mathieu-DaudéFrom: Philippe Mathieu-Daudé <[email protected]>
All uses were converted to the explicit cpu_ld/st*_{be,le}_data*() helpers, no need for the non-explicit versions anymore.
--- docs/devel/loads-stores.rst | 18 +++++++------- include/accel/tcg/cpu-ldst.h | 48 ------------------------------------ 2 files changed, 9 insertions(+), 57 deletions(-)
docs/devel/loads-stores.rst +9 -9
@@ -150,13 +150,13 @@ store: ``cpu_st{size}{end}_mmuidx_ra(env, ptr, val, mmuidx, retaddr)`` - ``q`` : 64 bits ``end`` - - (empty) : for target endian, or 8 bit sizes + - (empty) : for 8 bit sizes - ``_be`` : big endian - ``_le`` : little endian Regexes for git grep: - - ``\<cpu_ld[us]\?[bwlq]\(_[bl]e\)\?_mmuidx_ra\>`` - - ``\<cpu_st[bwlq]\(_[bl]e\)\?_mmuidx_ra\>`` + - ``\<cpu_ld[us]\?\(b\|[wlq]\(_[bl]e\)\)_mmuidx_ra\>`` + - ``\<cpu_st\(b\|[wlq]\(_[bl]e\)\)_mmuidx_ra\>`` ``cpu_{ld,st}*_data_ra`` ~~~~~~~~~~~~~~~~~~~~~~~~
@@ -188,13 +188,13 @@ store: ``cpu_st{size}{end}_data_ra(env, ptr, val, ra)`` - ``q`` : 64 bits ``end`` - - (empty) : for target endian, or 8 bit sizes + - (empty) : for 8 bit sizes - ``_be`` : big endian - ``_le`` : little endian Regexes for git grep: - - ``\<cpu_ld[us]\?[bwlq]\(_[bl]e\)\?_data_ra\>`` - - ``\<cpu_st[bwlq]\(_[bl]e\)\?_data_ra\>`` + - ``\<cpu_ld[us]\?\(b\|[wlq]\(_[bl]e\)\)_data_ra\>`` + - ``\<cpu_st\(b\|[wlq]\(_[bl]e\)\)_data_ra\>`` ``cpu_{ld,st}*_data`` ~~~~~~~~~~~~~~~~~~~~~
@@ -227,13 +227,13 @@ store: ``cpu_st{size}{end}_data(env, ptr, val)`` - ``q`` : 64 bits ``end`` - - (empty) : for target endian, or 8 bit sizes + - (empty) : for 8 bit sizes - ``_be`` : big endian - ``_le`` : little endian Regexes for git grep: - - ``\<cpu_ld[us]\?[bwlq]\(_[bl]e\)\?_data\>`` - - ``\<cpu_st[bwlq]\(_[bl]e\)\?_data\+\>`` + - ``\<cpu_ld[us]\?\(b\|[wlq]\(_[bl]e\)\)_data\>`` + - ``\<cpu_st\(b\|[wlq]\(_[bl]e\)\)_data\+\>`` ``cpu_ld*_code_mmu`` ~~~~~~~~~~~~~~~~~~~~
include/accel/tcg/cpu-ldst.h +0 -48
52 lines not on this page · raw message
Signature · 1 line
2.55.0
Quoted 11 lines · Philippe Mathieu-Daudé
Missing review: 3 and 5
Since v5:
- Rebased
- Swap temporaries during store (rth)
- Bswap d0 and d1 in ST.D (rth)Since v4:
- No algorithm change
- Split to ease review
Quoted 7 lines
Philippe Mathieu-Daudé (6):
target/mips: ExpandTRANS_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) accel/tcg: Remove non-explicit endian cpu_ld/st*_data*() helpers
r~
Quoted 11 lines · Richard Henderson
Quoted 7 lines · Philippe Mathieu-Daudé
Philippe Mathieu-Daudé (6):
target/mips: ExpandTRANS_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) accel/tcg: Remove non-explicit endian cpu_ld/st*_data*() helpers
Quoted 1 line
Reviewed-by Richard Henderson <[email protected]>
\o/ finally \o/ took me 5 years hehe \o/ thanks :)