target/mips: Optimize MSA interleave instructions
v6 cover target/mips: Optimize MSA interleave instructions
From: Mateja Marjanovic <[email protected]>
Optimize MSA instructions ILVEV.<B|H|W|D>, ILVOD.<B|H|W|D>, ILVL.<B|H|W|D> and ILVR.<B|H|W|D> using the hybrid approach, MSA helpers in some cases and directly tcg registers in other cases, so the performance would be better.
v6:
- Add ILVL.<B|H|W|D> and ILVR.<B|H|W|D> MSA instructions with mixed approaches (with helpers and with tcg registers).
- Test the performance for ILVL.<B|H|W|D> and ILVR.<B|H|W|D> MSA instructions, with helpers, with tcg and with the mixed approach.
- Use a tcg register instead of an int variable for storing a constant value of the mask (for logic operations).
- Eliminate some unnecessary tcg_gen calls.
- Changes in commit messages and the cover letter.
v5:
- Use tcg_gen_deposit function.
- Added performance number for no-deposit and with-deposit cases of ILVEV.W.
- Minor changes in commit messages and the cover letter.
v4:
- Clean up typing errors.
- Change the commit message and the cover letter.
- Fix bug for ILVEV.D, in case where the destination and one of the sources are the same register.
v3:
- Reduce the number of logic operations to a
minimum.
- Add comments.
v2:
- Minor changes in commit messages and the cover letter.
Mateja Marjanovic (4):
target/mips: Optimize ILVOD.<B|H|W|D> MSA instructions target/mips: Optimize ILVEV.<B|H|W|D> MSA instructions target/mips: Optimize ILVL.<B|H|W|D> MSA instructions target/mips: Optimize ILVR.<B|H|W|D> MSA instructions
target/mips/helper.h | 7 +- target/mips/msa_helper.c | 82 +++++--- target/mips/translate.c | 498 ++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 547 insertions(+), 40 deletions(-)
Signature · 1 line
2.7.4
PATCH v6 1/4 target/mips: Optimize ILVOD.<B|H|W|D> MSA instructions
From: Mateja Marjanovic <[email protected]>
Optimize set of MSA instructions ILVOD.<B|H|W|D>, using directly tcg registers and performing logic on them instead of using helpers.
In the following table, the first column is the performance before this patch. The second represents the performance, after converting from helpers to tcg, but without using tcg_gen_deposit function. The third one is the solution which is implemented in this patch.
Performance measurement is done by executing the instructions a large number of times on a computer with Intel Core i7-3770 CPU @ 3.40GHz×8.
============================================================
|| instr || before || no-deposit || with-deposit ||
============================================================
|| ilvod.b || 117.50 ms || 24.13 ms || 23.71 ms || || ilvod.h || 93.16 ms || 24.21 ms || 23.45 ms || || ilvod.w || 119.90 ms || 24.15 ms || 22.91 ms || || ilvod.d || 43.01 ms || 21.17 ms || 20.53 ms ||
============================================================
No-deposit column and with-deposit column have the same statistical values in every row, except ILVOD.W, which is the only function which uses the deposit function.
No-deposit version of the ILVOD.W implementation:
static inline void gen_ilvod_w(CPUMIPSState *env, uint32_t wd,
uint32_t ws, uint32_t wt)
{
TCGv_i64 t1 = tcg_temp_new_i64();
TCGv_i64 t2 = tcg_temp_new_i64();
TCGv_i64 mask = tcg_const_i64(0xffffffff00000000ULL);
tcg_gen_and_i64(t1, msa_wr_d[wt * 2], mask);
tcg_gen_shri_i64(t1, t1, 32);
tcg_gen_and_i64(t2, msa_wr_d[ws * 2], mask);
tcg_gen_or_i64(msa_wr_d[wd * 2], t1, t2);
tcg_gen_and_i64(t1, msa_wr_d[wt * 2 + 1], mask);
tcg_gen_shri_i64(t1, t1, 32);
tcg_gen_and_i64(t2, msa_wr_d[ws * 2 + 1], mask);
tcg_gen_or_i64(msa_wr_d[wd * 2 + 1], t1, t2);
tcg_temp_free_i64(mask);
tcg_temp_free_i64(t1);
tcg_temp_free_i64(t2);
}--- target/mips/helper.h | 1 - target/mips/msa_helper.c | 7 ---- target/mips/translate.c | 106 ++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 105 insertions(+), 9 deletions(-)
target/mips/helper.h +0 -1
@@ -865,7 +865,6 @@ DEF_HELPER_5(msa_pckod_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_ilvl_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_ilvr_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_ilvev_df, void, env, i32, i32, i32, i32) -DEF_HELPER_5(msa_ilvod_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_vshf_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_srar_df, void, env, i32, i32, i32, i32)DEF_HELPER_5 (msa_srlr_df, void, env, i32, i32, i32, i32)
target/mips/msa_helper.c +0 -7
@@ -1206,13 +1206,6 @@ MSA_FN_DF(ilvr_df) MSA_FN_DF(ilvev_df)#undef MSA_DO -#define MSA_DO (DF ) \ - do { \ - pwx->DF[2*i] = pwt->DF[2*i+1]; \ - pwx->DF[2*i+1] = pws->DF[2*i+1]; \ - } while (0) -MSA_FN_DF(ilvod_df) -#undef MSA_DO#undef MSA_LOOP_COND#define MSA_LOOP_COND (DF ) \
target/mips/translate.c +105 -1
118 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH v6 1/4] target/mips: Optimize ILVOD.<B|H|W|D> MSA instructions
Quoted 145 lines · Mateja Marjanovic
From: Mateja Marjanovic <[email protected]>
Optimize set of MSA instructions ILVOD.<B|H|W|D>, using directly tcg registers and performing logic on them instead of using helpers.
In the following table, the first column is the performance before this patch. The second represents the performance, after converting from helpers to tcg, but without using
tcg_gen_depositfunction. The third one is the solution which is implemented in this patch.Performance measurement is done by executing the instructions a large number of times on a computer with Intel Core i7-3770 CPU @ 3.40GHz×8.
============================================================
|| instr || before || no-deposit || with-deposit ||
============================================================|| ilvod.b || 117.50 ms || 24.13 ms || 23.71 ms || || ilvod.h || 93.16 ms || 24.21 ms || 23.45 ms || || ilvod.w || 119.90 ms || 24.15 ms || 22.91 ms || || ilvod.d || 43.01 ms || 21.17 ms || 20.53 ms ||============================================================
No-deposit column and with-deposit column have the same statistical values in every row, except ILVOD.W, which is the only function which uses the deposit function.
No-deposit version of the ILVOD.W implementation:
static inline void gen_ilvod_w(CPUMIPSState *env,
uint32_twd,uint32_t ws, uint32_t wt) { TCGv_i64 t1 = tcg_temp_new_i64(); TCGv_i64 t2 = tcg_temp_new_i64(); TCGv_i64 mask = tcg_const_i64(0xffffffff00000000ULL); tcg_gen_and_i64(t1, msa_wr_d[wt * 2], mask); tcg_gen_shri_i64(t1, t1, 32); tcg_gen_and_i64(t2, msa_wr_d[ws * 2], mask); tcg_gen_or_i64(msa_wr_d[wd * 2], t1, t2); tcg_gen_and_i64(t1, msa_wr_d[wt * 2 + 1], mask); tcg_gen_shri_i64(t1, t1, 32); tcg_gen_and_i64(t2, msa_wr_d[ws * 2 + 1], mask); tcg_gen_or_i64(msa_wr_d[wd * 2 + 1], t1, t2); tcg_temp_free_i64(mask); tcg_temp_free_i64(t1); tcg_temp_free_i64(t2); }Suggested-by Richard Henderson <[email protected]>Signed-off-by Mateja Marjanovic <[email protected]>--- target/mips/helper.h | 1 - target/mips/msa_helper.c | 7 ---- target/mips/translate.c | 106 ++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 105 insertions(+), 9 deletions(-)target/mips/helper.h +0
-1@@ -865,7 +865,6 @@ DEF_HELPER_5(msa_pckod_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_ilvl_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_ilvr_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_ilvev_df, void, env, i32, i32, i32, i32) -DEF_HELPER_5(msa_ilvod_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_vshf_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_srar_df, void, env, i32, i32, i32, i32)DEF_HELPER_5 (msa_srlr_df, void, env, i32, i32, i32, i32)target/mips/msa_helper.c +0
-7@@ -1206,13 +1206,6 @@ MSA_FN_DF(ilvr_df) MSA_FN_DF(ilvev_df)#undef MSA_DO -#define MSA_DO (DF ) \ - do { \ - pwx->DF[2*i] = pwt->DF[2*i+1]; \ - pwx->DF[2*i+1] = pws->DF[2*i+1]; \ - } while (0) -MSA_FN_DF(ilvod_df) -#undef MSA_DO#undef MSA_LOOP_COND#define MSA_LOOP_COND (DF ) \target/mips/translate.c +45
-0@@ -28884,6 +28884,95 @@ static void gen_msa_bit(CPUMIPSState *env, DisasContext *ctx)tcg_temp_free_i32 (tws); } +/* +* [MSA] ILVOD.B wd, ws, wt +* +* Vector Interleave Odd (byte data elements) +* +*/ +static inline void gen_ilvod_b (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +TCGv_i64 t1 =tcg_temp_new_i64 (); +TCGv_i64 t2 =tcg_temp_new_i64 (); +TCGv_i64 mask =tcg_const_i64 (0xff00ff00ff00ff00ULL ); + +tcg_gen_and_i64 (t1, msa_wr_d[wt *2 ], mask); +tcg_gen_shri_i64 (t1, t1,8 ); +tcg_gen_and_i64 (t2, msa_wr_d[ws *2 ], mask); +tcg_gen_or_i64 (msa_wr_d[wd *2 ], t1, t2); + +tcg_gen_and_i64 (t1, msa_wr_d[wt *2 +1 ], mask); +tcg_gen_shri_i64 (t1, t1,8 ); +tcg_gen_and_i64 (t2, msa_wr_d[ws *2 +1 ], mask); +tcg_gen_or_i64 (msa_wr_d[wd *2 +1 ], t1, t2); + +tcg_temp_free_i64 (mask); +tcg_temp_free_i64 (t1); +tcg_temp_free_i64 (t2); +} + +/* +* [MSA] ILVOD.H wd, ws, wt +* +* Vector Interleave Odd (halfword data elements) +* +*/ +static inline void gen_ilvod_h (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +TCGv_i64 t1 =tcg_temp_new_i64 (); +TCGv_i64 t2 =tcg_temp_new_i64 (); +TCGv_i64 mask =tcg_const_i64 (0xffff0000ffff0000ULL ); + +tcg_gen_and_i64 (t1, msa_wr_d[wt *2 ], mask); +tcg_gen_shri_i64 (t1, t1,16 ); +tcg_gen_and_i64 (t2, msa_wr_d[ws *2 ], mask); +tcg_gen_or_i64 (msa_wr_d[wd *2 ], t1, t2);
target/mips/translate.c static void gen_msa_bit(CPUMIPSState *env, DisasContext *ctx) · line 28941
Quoted 10 lines
target/mips/translate.c +10
-0+ +tcg_gen_and_i64 (t1, msa_wr_d[wt *2 +1 ], mask); +tcg_gen_shri_i64 (t1, t1,16 ); +tcg_gen_and_i64 (t2, msa_wr_d[ws *2 +1 ], mask); +tcg_gen_or_i64 (msa_wr_d[wd *2 +1 ], t1, t2); + +tcg_temp_free_i64 (mask); +tcg_temp_free_i64 (t1); +tcg_temp_free_i64 (t2); +}
Same comment that patch #2 of this series applies here, refactor the b/h cases would ease code maintainance.
Quoted 62 lines
target/mips/translate.c +50
-1+ +/* +* [MSA] ILVOD.W wd, ws, wt +* +* Vector Interleave Odd (word data elements) +* +*/ +static inline void gen_ilvod_w (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +TCGv_i64 t1 =tcg_temp_new_i64 (); + +tcg_gen_shri_i64 (t1, msa_wr_d[wt *2 ],32 ); +tcg_gen_deposit_i64 (msa_wr_d[wd *2 ], msa_wr_d[ws *2 ], t1,0 ,32 ); + +tcg_gen_shri_i64 (t1, msa_wr_d[wt *2 +1 ],32 ); +tcg_gen_deposit_i64 (msa_wr_d[wd *2 +1 ], msa_wr_d[ws *2 +1 ], t1,0 ,32 ); + +tcg_temp_free_i64 (t1); +} + +/* +* [MSA] ILVOD.D wd, ws, wt +* +* Vector Interleave Odd (doubleword data elements) +* +*/ +static inline void gen_ilvod_d (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +tcg_gen_mov_i64 (msa_wr_d[wd *2 ], msa_wr_d[wt *2 +1 ]); +tcg_gen_mov_i64 (msa_wr_d[wd *2 +1 ], msa_wr_d[ws *2 +1 ]); +} +static void gen_msa_3r (CPUMIPSState *env,DisasContext *ctx) {#define MASK_MSA_3R (op) (MASK_MSA_MINOR(op) | (op & (0x7 << 23)))@@ -29055,7 +29144,22 @@ static void gen_msa_3r(CPUMIPSState *env, DisasContext *ctx)gen_helper_msa_mod_u_df (cpu_env, tdf, twd, tws, twt);break ;case OPC_ILVOD_df: -gen_helper_msa_ilvod_df (cpu_env, tdf, twd, tws, twt); +switch (df) { +case DF_BYTE : +gen_ilvod_b (env, wd, ws, wt); +break ; +case DF_HALF : +gen_ilvod_h (env, wd, ws, wt); +break ; +case DF_WORD : +gen_ilvod_w (env, wd, ws, wt); +break ; +case DF_DOUBLE : +gen_ilvod_d (env, wd, ws, wt); +break ; +default : +assert (0 ); + }break ;case OPC_DOTP_S_df:
Re: [Qemu-devel] [PATCH v6 1/4] target/mips: Optimize ILVOD.<B|H|W|D> MSA instructions
In reply to Mateja MarjanovicQuoted 7 lines · Mateja Marjanovic
From: Mateja Marjanovic <[email protected]>
Optimize set of MSA instructions ILVOD.<B|H|W|D>, using directly tcg registers and performing logic on them instead of using helpers.
Please see my comments for ILVEV.D.
Thanks,
Aleksandar
Quoted 214 lines
In the following table, the first column is the performance before this patch. The second represents the performance, after converting from helpers to tcg, but without using
tcg_gen_depositfunction. The third one is the solution which is implemented in this patch.Performance measurement is done by executing the instructions a large number of times on a computer with Intel Core i7-3770 CPU @ 3.40GHz×8.
============================================================
|| instr || before || no-deposit || with-deposit ||
============================================================|| ilvod.b || 117.50 ms || 24.13 ms || 23.71 ms || || ilvod.h || 93.16 ms || 24.21 ms || 23.45 ms || || ilvod.w || 119.90 ms || 24.15 ms || 22.91 ms || || ilvod.d || 43.01 ms || 21.17 ms || 20.53 ms ||============================================================
No-deposit column and with-deposit column have the same statistical values in every row, except ILVOD.W, which is the only function which uses the deposit function.
No-deposit version of the ILVOD.W implementation:
static inline void gen_ilvod_w(CPUMIPSState *env,
uint32_twd,uint32_t ws, uint32_t wt) { TCGv_i64 t1 = tcg_temp_new_i64(); TCGv_i64 t2 = tcg_temp_new_i64(); TCGv_i64 mask = tcg_const_i64(0xffffffff00000000ULL); tcg_gen_and_i64(t1, msa_wr_d[wt * 2], mask); tcg_gen_shri_i64(t1, t1, 32); tcg_gen_and_i64(t2, msa_wr_d[ws * 2], mask); tcg_gen_or_i64(msa_wr_d[wd * 2], t1, t2); tcg_gen_and_i64(t1, msa_wr_d[wt * 2 + 1], mask); tcg_gen_shri_i64(t1, t1, 32); tcg_gen_and_i64(t2, msa_wr_d[ws * 2 + 1], mask); tcg_gen_or_i64(msa_wr_d[wd * 2 + 1], t1, t2); tcg_temp_free_i64(mask); tcg_temp_free_i64(t1); tcg_temp_free_i64(t2); }Suggested-by Richard Henderson <[email protected]>Signed-off-by Mateja Marjanovic <[email protected]>--- target/mips/helper.h | 1 - target/mips/msa_helper.c | 7 ---- target/mips/translate.c | 106 ++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 105 insertions(+), 9 deletions(-)target/mips/helper.h +0
-1@@ -865,7 +865,6 @@ DEF_HELPER_5(msa_pckod_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_ilvl_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_ilvr_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_ilvev_df, void, env, i32, i32, i32, i32) -DEF_HELPER_5(msa_ilvod_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_vshf_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_srar_df, void, env, i32, i32, i32, i32)DEF_HELPER_5 (msa_srlr_df, void, env, i32, i32, i32, i32)target/mips/msa_helper.c +0
-7@@ -1206,13 +1206,6 @@ MSA_FN_DF(ilvr_df) MSA_FN_DF(ilvev_df)#undef MSA_DO -#define MSA_DO (DF ) \ - do { \ - pwx->DF[2*i] = pwt->DF[2*i+1]; \ - pwx->DF[2*i+1] = pws->DF[2*i+1]; \ - } while (0) -MSA_FN_DF(ilvod_df) -#undef MSA_DO#undef MSA_LOOP_COND#define MSA_LOOP_COND (DF ) \target/mips/translate.c +105
-2@@ -28884,6 +28884,95 @@ static void gen_msa_bit(CPUMIPSState *env, DisasContext *ctx)tcg_temp_free_i32 (tws); } +/* +* [MSA] ILVOD.B wd, ws, wt +* +* Vector Interleave Odd (byte data elements) +* +*/ +static inline void gen_ilvod_b (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +TCGv_i64 t1 =tcg_temp_new_i64 (); +TCGv_i64 t2 =tcg_temp_new_i64 (); +TCGv_i64 mask =tcg_const_i64 (0xff00ff00ff00ff00ULL ); + +tcg_gen_and_i64 (t1, msa_wr_d[wt *2 ], mask); +tcg_gen_shri_i64 (t1, t1,8 ); +tcg_gen_and_i64 (t2, msa_wr_d[ws *2 ], mask); +tcg_gen_or_i64 (msa_wr_d[wd *2 ], t1, t2); + +tcg_gen_and_i64 (t1, msa_wr_d[wt *2 +1 ], mask); +tcg_gen_shri_i64 (t1, t1,8 ); +tcg_gen_and_i64 (t2, msa_wr_d[ws *2 +1 ], mask); +tcg_gen_or_i64 (msa_wr_d[wd *2 +1 ], t1, t2); + +tcg_temp_free_i64 (mask); +tcg_temp_free_i64 (t1); +tcg_temp_free_i64 (t2); +} + +/* +* [MSA] ILVOD.H wd, ws, wt +* +* Vector Interleave Odd (halfword data elements) +* +*/ +static inline void gen_ilvod_h (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +TCGv_i64 t1 =tcg_temp_new_i64 (); +TCGv_i64 t2 =tcg_temp_new_i64 (); +TCGv_i64 mask =tcg_const_i64 (0xffff0000ffff0000ULL ); + +tcg_gen_and_i64 (t1, msa_wr_d[wt *2 ], mask); +tcg_gen_shri_i64 (t1, t1,16 ); +tcg_gen_and_i64 (t2, msa_wr_d[ws *2 ], mask); +tcg_gen_or_i64 (msa_wr_d[wd *2 ], t1, t2); + +tcg_gen_and_i64 (t1, msa_wr_d[wt *2 +1 ], mask); +tcg_gen_shri_i64 (t1, t1,16 ); +tcg_gen_and_i64 (t2, msa_wr_d[ws *2 +1 ], mask); +tcg_gen_or_i64 (msa_wr_d[wd *2 +1 ], t1, t2); + +tcg_temp_free_i64 (mask); +tcg_temp_free_i64 (t1); +tcg_temp_free_i64 (t2); +} + +/* +* [MSA] ILVOD.W wd, ws, wt +* +* Vector Interleave Odd (word data elements) +* +*/ +static inline void gen_ilvod_w (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +TCGv_i64 t1 =tcg_temp_new_i64 (); + +tcg_gen_shri_i64 (t1, msa_wr_d[wt *2 ],32 ); +tcg_gen_deposit_i64 (msa_wr_d[wd *2 ], msa_wr_d[ws *2 ], t1,0 ,32 ); + +tcg_gen_shri_i64 (t1, msa_wr_d[wt *2 +1 ],32 ); +tcg_gen_deposit_i64 (msa_wr_d[wd *2 +1 ], msa_wr_d[ws *2 +1 ], t1,0 ,32 ); + +tcg_temp_free_i64 (t1); +} + +/* +* [MSA] ILVOD.D wd, ws, wt +* +* Vector Interleave Odd (doubleword data elements) +* +*/ +static inline void gen_ilvod_d (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +tcg_gen_mov_i64 (msa_wr_d[wd *2 ], msa_wr_d[wt *2 +1 ]); +tcg_gen_mov_i64 (msa_wr_d[wd *2 +1 ], msa_wr_d[ws *2 +1 ]); +} +static void gen_msa_3r (CPUMIPSState *env,DisasContext *ctx) {#define MASK_MSA_3R (op) (MASK_MSA_MINOR(op) | (op & (0x7 << 23)))@@ -29055,7 +29144,22 @@ static void gen_msa_3r(CPUMIPSState *env, DisasContext *ctx)gen_helper_msa_mod_u_df (cpu_env, tdf, twd, tws, twt);break ;case OPC_ILVOD_df: -gen_helper_msa_ilvod_df (cpu_env, tdf, twd, tws, twt); +switch (df) { +case DF_BYTE : +gen_ilvod_b (env, wd, ws, wt); +break ; +case DF_HALF : +gen_ilvod_h (env, wd, ws, wt); +break ; +case DF_WORD : +gen_ilvod_w (env, wd, ws, wt); +break ; +case DF_DOUBLE : +gen_ilvod_d (env, wd, ws, wt); +break ; +default : +assert (0 ); + }break ;case OPC_DOTP_S_df: --2.7.4
PATCH v6 2/4 target/mips: Optimize ILVEV.<B|H|W|D> MSA instructions
In reply to Mateja MarjanovicFrom: Mateja Marjanovic <[email protected]>
Optimize set of MSA instructions ILVEV.<B|H|W|D>, using directly tcg registers and performing logic on them instead of using helpers.
In the following table, the first column is the performance before this patch. The second represents the performance, after converting from helpers to tcg, but without using tcg_gen_deposit function. The third one is the solution which is implemented in this patch.
Performance measurement is done by executing the instructions a large number of times on a computer with Intel Core i7-3770 CPU @ 3.40GHz×8.
============================================================
|| instr || before || no-deposit || with-deposit ||
============================================================
|| ilvev.b || 126.92 ms || 24.52 ms || 24.43 ms || || ilvev.h || 93.67 ms || 23.92 ms || 23.86 ms || || ilvev.w || 117.86 ms || 23.83 ms || 22.17 ms || || ilvev.d || 45.49 ms || 19.74 ms || 19.71 ms ||
============================================================
No-deposit column and with-deposit column have the same statistical values in every row, except ILVEV.W, which is the only function which uses the deposit function.
No-deposit version of the ILVEV.W implementation:
static inline void gen_ilvev_w(CPUMIPSState *env, uint32_t wd,
uint32_t ws, uint32_t wt)
{
TCGv_i64 t1 = tcg_temp_new_i64();
TCGv_i64 t2 = tcg_temp_new_i64();
uint64_t mask = 0x00000000ffffffffULL;
tcg_gen_andi_i64(t1, msa_wr_d[wt * 2], mask);
tcg_gen_andi_i64(t2, msa_wr_d[ws * 2], mask);
tcg_gen_shli_i64(t2, t2, 32);
tcg_gen_or_i64(msa_wr_d[wd * 2], t1, t2);
tcg_gen_andi_i64(t1, msa_wr_d[wt * 2 + 1], mask);
tcg_gen_andi_i64(t2, msa_wr_d[ws * 2 + 1], mask);
tcg_gen_shli_i64(t2, t2, 32);
tcg_gen_or_i64(msa_wr_d[wd * 2 + 1], t1, t2);
tcg_temp_free_i64(t1);
tcg_temp_free_i64(t2);
}--- target/mips/helper.h | 1 - target/mips/msa_helper.c | 9 ----- target/mips/translate.c | 101 ++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 100 insertions(+), 11 deletions(-)
target/mips/helper.h +0 -1
@@ -864,7 +864,6 @@ DEF_HELPER_5(msa_pckev_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_pckod_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_ilvl_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_ilvr_df, void, env, i32, i32, i32, i32) -DEF_HELPER_5(msa_ilvev_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_vshf_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_srar_df, void, env, i32, i32, i32, i32)DEF_HELPER_5 (msa_srlr_df, void, env, i32, i32, i32, i32)
target/mips/msa_helper.c +0 -9
@@ -1197,15 +1197,6 @@ MSA_FN_DF(ilvl_df) }while (0 ) MSA_FN_DF(ilvr_df)#undef MSA_DO - -#define MSA_DO (DF ) \ - do { \ - pwx->DF[2*i] = pwt->DF[2*i]; \ - pwx->DF[2*i+1] = pws->DF[2*i]; \ - } while (0) -MSA_FN_DF(ilvev_df) -#undef MSA_DO -#undef MSA_LOOP_COND#define MSA_LOOP_COND (DF ) \
target/mips/translate.c +100 -1
113 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH v6 2/4] target/mips: Optimize ILVEV.<B|H|W|D> MSA instructions
Hi Mateja,
Quoted 16 lines · Mateja Marjanovic
From: Mateja Marjanovic <[email protected]>
Optimize set of MSA instructions ILVEV.<B|H|W|D>, using directly tcg registers and performing logic on them instead of using helpers.
In the following table, the first column is the performance before this patch. The second represents the performance, after converting from helpers to tcg, but without using
tcg_gen_depositfunction. The third one is the solution which is implemented in this patch.Performance measurement is done by executing the instructions a large number of times on a computer with Intel Core i7-3770 CPU @ 3.40GHz×8.
Quoted 5 lines
============================================================
|| instr || before || no-deposit || with-deposit ||
============================================================|| ilvev.b || 126.92 ms || 24.52 ms || 24.43 ms || || ilvev.h || 93.67 ms || 23.92 ms || 23.86 ms ||
I'm quite surprised there is not a single change here since your v5, are you sure you used the correct result? I was expecting a slighly improvement.
Quoted 125 lines
|| ilvev.w || 117.86 ms || 23.83 ms || 22.17 ms || || ilvev.d || 45.49 ms || 19.74 ms || 19.71 ms ||============================================================
No-deposit column and with-deposit column have the same statistical values in every row, except ILVEV.W, which is the only function which uses the deposit function.
No-deposit version of the ILVEV.W implementation:
static inline void gen_ilvev_w(CPUMIPSState *env,
uint32_twd,uint32_t ws, uint32_t wt) { TCGv_i64 t1 = tcg_temp_new_i64(); TCGv_i64 t2 = tcg_temp_new_i64(); uint64_t mask = 0x00000000ffffffffULL; tcg_gen_andi_i64(t1, msa_wr_d[wt * 2], mask); tcg_gen_andi_i64(t2, msa_wr_d[ws * 2], mask); tcg_gen_shli_i64(t2, t2, 32); tcg_gen_or_i64(msa_wr_d[wd * 2], t1, t2); tcg_gen_andi_i64(t1, msa_wr_d[wt * 2 + 1], mask); tcg_gen_andi_i64(t2, msa_wr_d[ws * 2 + 1], mask); tcg_gen_shli_i64(t2, t2, 32); tcg_gen_or_i64(msa_wr_d[wd * 2 + 1], t1, t2); tcg_temp_free_i64(t1); tcg_temp_free_i64(t2); }Suggested-by Richard Henderson <[email protected]>Signed-off-by Mateja Marjanovic <[email protected]>--- target/mips/helper.h | 1 - target/mips/msa_helper.c | 9 ----- target/mips/translate.c | 101 ++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 100 insertions(+), 11 deletions(-)target/mips/helper.h +0
-1@@ -864,7 +864,6 @@ DEF_HELPER_5(msa_pckev_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_pckod_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_ilvl_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_ilvr_df, void, env, i32, i32, i32, i32) -DEF_HELPER_5(msa_ilvev_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_vshf_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_srar_df, void, env, i32, i32, i32, i32)DEF_HELPER_5 (msa_srlr_df, void, env, i32, i32, i32, i32)target/mips/msa_helper.c +0
-9@@ -1197,15 +1197,6 @@ MSA_FN_DF(ilvl_df) }while (0 ) MSA_FN_DF(ilvr_df)#undef MSA_DO - -#define MSA_DO (DF ) \ - do { \ - pwx->DF[2*i] = pwt->DF[2*i]; \ - pwx->DF[2*i+1] = pws->DF[2*i]; \ - } while (0) -MSA_FN_DF(ilvev_df) -#undef MSA_DO -#undef MSA_LOOP_COND#define MSA_LOOP_COND (DF ) \target/mips/translate.c +45
-0@@ -28973,6 +28973,90 @@ static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd,tcg_gen_mov_i64 (msa_wr_d[wd *2 +1 ], msa_wr_d[ws *2 +1 ]); } +/* +* [MSA] ILVEV.B wd, ws, wt +* +* Vector Interleave Even (byte data elements) +* +*/ +static inline void gen_ilvev_b (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +TCGv_i64 t1 =tcg_temp_new_i64 (); +TCGv_i64 t2 =tcg_temp_new_i64 (); +TCGv_i64 mask =tcg_const_i64 (0x00ff00ff00ff00ffULL ); + +tcg_gen_and_i64 (t1, msa_wr_d[wt *2 ], mask); +tcg_gen_and_i64 (t2, msa_wr_d[ws *2 ], mask); +tcg_gen_shli_i64 (t2, t2,8 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 ], t1, t2); + +tcg_gen_and_i64 (t1, msa_wr_d[wt *2 +1 ], mask); +tcg_gen_and_i64 (t2, msa_wr_d[ws *2 +1 ], mask); +tcg_gen_shli_i64 (t2, t2,8 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 +1 ], t1, t2); + +tcg_temp_free_i64 (mask); +tcg_temp_free_i64 (t1); +tcg_temp_free_i64 (t2); +} + +/* +* [MSA] ILVEV.H wd, ws, wt +* +* Vector Interleave Even (halfword data elements) +* +*/ +static inline void gen_ilvev_h (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +TCGv_i64 t1 =tcg_temp_new_i64 (); +TCGv_i64 t2 =tcg_temp_new_i64 (); +TCGv_i64 mask =tcg_const_i64 (0x0000ffff0000ffffULL ); + +tcg_gen_and_i64 (t1, msa_wr_d[wt *2 ], mask); +tcg_gen_and_i64 (t2, msa_wr_d[ws *2 ], mask); +tcg_gen_shli_i64 (t2, t2,16 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 ], t1, t2);
target/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd, · line 29030
Quoted 10 lines
target/mips/translate.c +10
-0+ +tcg_gen_and_i64 (t1, msa_wr_d[wt *2 +1 ], mask); +tcg_gen_and_i64 (t2, msa_wr_d[ws *2 +1 ], mask); +tcg_gen_shli_i64 (t2, t2,16 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 +1 ], t1, t2); + +tcg_temp_free_i64 (mask); +tcg_temp_free_i64 (t1); +tcg_temp_free_i64 (t2); +}
Apparently you missed my comment about refactoring using mask/shift as arguments:
static inline void gen_ilvev_hb(CPUMIPSState *env, uint32_t wd,
uint32_t ws, uint32_t wt,
int64_t mask, int64_t shift)
{
TCGv_i64 t1 = tcg_temp_new_i64();
TCGv_i64 t2 = tcg_temp_new_i64();
TCGv_i64 tm = tcg_const_i64(mask);
tcg_gen_and_i64(t1, msa_wr_d[wt * 2], tm);
tcg_gen_and_i64(t2, msa_wr_d[ws * 2], tm);
tcg_gen_shli_i64(t2, t2, shift);
tcg_gen_or_i64(msa_wr_d[wd * 2], t1, t2);
tcg_gen_and_i64(t1, msa_wr_d[wt * 2 + 1], tm);
tcg_gen_and_i64(t2, msa_wr_d[ws * 2 + 1], tm);
tcg_gen_shli_i64(t2, t2, shift);
tcg_gen_or_i64(msa_wr_d[wd * 2 + 1], t1, t2);
tcg_temp_free_i64(tm);
tcg_temp_free_i64(t1);
tcg_temp_free_i64(t2);
}static inline void gen_ilvev_b(CPUMIPSState *env, uint32_t wd,
uint32_t ws, uint32_t wt)
{
gen_ilvev_hb(env, wd, ws, wt, 0x00ff00ff00ff00ffLL, 8);
}static inline void gen_ilvev_h(CPUMIPSState *env, uint32_t wd,
uint32_t ws, uint32_t wt)
{
gen_ilvev_hb(env, wd, ws, wt, 0x0000ffff0000ffffLL, 16);
}Quoted 57 lines
target/mips/translate.c +45
-1+ +/* +* [MSA] ILVEV.W wd, ws, wt +* +* Vector Interleave Even (word data elements) +* +*/ +static inline void gen_ilvev_w (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +tcg_gen_deposit_i64 (msa_wr_d[wd *2 ], msa_wr_d[wt *2 ], + msa_wr_d[ws *2 ],32 ,32 ); +tcg_gen_deposit_i64 (msa_wr_d[wd *2 +1 ], msa_wr_d[wt *2 +1 ], + msa_wr_d[ws *2 +1 ],32 ,32 ); +} + +/* +* [MSA] ILVEV.D wd, ws, wt +* +* Vector Interleave Even (Doubleword data elements) +* +*/ +static inline void gen_ilvev_d (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +tcg_gen_mov_i64 (msa_wr_d[wd *2 +1 ], msa_wr_d[ws *2 ]); +tcg_gen_mov_i64 (msa_wr_d[wd *2 ], msa_wr_d[wt *2 ]); +} +static void gen_msa_3r (CPUMIPSState *env,DisasContext *ctx) {#define MASK_MSA_3R (op) (MASK_MSA_MINOR(op) | (op & (0x7 << 23)))@@ -29129,7 +29213,22 @@ static void gen_msa_3r(CPUMIPSState *env, DisasContext *ctx)gen_helper_msa_mod_s_df (cpu_env, tdf, twd, tws, twt);break ;case OPC_ILVEV_df: -gen_helper_msa_ilvev_df (cpu_env, tdf, twd, tws, twt); +switch (df) { +case DF_BYTE : +gen_ilvev_b (env, wd, ws, wt); +break ; +case DF_HALF : +gen_ilvev_h (env, wd, ws, wt); +break ; +case DF_WORD : +gen_ilvev_w (env, wd, ws, wt); +break ; +case DF_DOUBLE : +gen_ilvev_d (env, wd, ws, wt); +break ; +default : +assert (0 ); + }break ;case OPC_BINSR_df:gen_helper_msa_binsr_df (cpu_env, tdf, twd, tws, twt);
Re: [Qemu-devel] [PATCH v6 2/4] target/mips: Optimize ILVEV.<B|H|W|D> MSA instructions
Quoted 22 lines
From: Philippe Mathieu-Daudé <[email protected]>
Subject: Re: [PATCH v6 2/4] target/mips: Optimize ILVEV.<B|H|W|D> MSA instructionsHi Mateja,
Quoted 16 lines · Mateja Marjanovic
From: Mateja Marjanovic <[email protected]>
Optimize set of MSA instructions ILVEV.<B|H|W|D>, using directly tcg registers and performing logic on them instead of using helpers.
In the following table, the first column is the performance before this patch. The second represents the performance, after converting from helpers to tcg, but without using
tcg_gen_depositfunction. The third one is the solution which is implemented in this patch.Performance measurement is done by executing the instructions a large number of times on a computer with Intel Core i7-3770 CPU @ 3.40GHz×8.
Quoted 9 lines
Quoted 5 lines
============================================================
|| instr || before || no-deposit || with-deposit ||
============================================================|| ilvev.b || 126.92 ms || 24.52 ms || 24.43 ms || || ilvev.h || 93.67 ms || 23.92 ms || 23.86 ms ||I'm quite surprised there is not a single change here since your v5, are you sure you used the correct result? I was expecting a slighly improvement.
Hello, Philippe.
First of all, thank you so much for taking your time to provide Matejan with the source code below.
Speaking about your idea, Mateja told me he DID implemented it, and did measurements, and that the improvement is noticeable, but really small. I don't know why he did not include that change
- perhaps he didn't have enough time to integrate it.
I know he is on a long weekend now, so we will have to wait for the next week for Mateja to explain this to us. Mateja, could you perhaps add a column "with-deposit-and-mask-as-tcg-constant"?
Yours,
Aleksandar
Quoted 224 lines
Quoted 125 lines
|| ilvev.w || 117.86 ms || 23.83 ms || 22.17 ms || || ilvev.d || 45.49 ms || 19.74 ms || 19.71 ms ||============================================================
No-deposit column and with-deposit column have the same statistical values in every row, except ILVEV.W, which is the only function which uses the deposit function.
No-deposit version of the ILVEV.W implementation:
static inline void gen_ilvev_w(CPUMIPSState *env,
uint32_twd,uint32_t ws, uint32_t wt) { TCGv_i64 t1 = tcg_temp_new_i64(); TCGv_i64 t2 = tcg_temp_new_i64(); uint64_t mask = 0x00000000ffffffffULL; tcg_gen_andi_i64(t1, msa_wr_d[wt * 2], mask); tcg_gen_andi_i64(t2, msa_wr_d[ws * 2], mask); tcg_gen_shli_i64(t2, t2, 32); tcg_gen_or_i64(msa_wr_d[wd * 2], t1, t2); tcg_gen_andi_i64(t1, msa_wr_d[wt * 2 + 1], mask); tcg_gen_andi_i64(t2, msa_wr_d[ws * 2 + 1], mask); tcg_gen_shli_i64(t2, t2, 32); tcg_gen_or_i64(msa_wr_d[wd * 2 + 1], t1, t2); tcg_temp_free_i64(t1); tcg_temp_free_i64(t2); }Suggested-by Richard Henderson <[email protected]>Signed-off-by Mateja Marjanovic <[email protected]>--- target/mips/helper.h | 1 - target/mips/msa_helper.c | 9 ----- target/mips/translate.c | 101 ++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 100 insertions(+), 11 deletions(-)target/mips/helper.h +0
-1@@ -864,7 +864,6 @@ DEF_HELPER_5(msa_pckev_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_pckod_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_ilvl_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_ilvr_df, void, env, i32, i32, i32, i32) -DEF_HELPER_5(msa_ilvev_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_vshf_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_srar_df, void, env, i32, i32, i32, i32)DEF_HELPER_5 (msa_srlr_df, void, env, i32, i32, i32, i32)target/mips/msa_helper.c +0
-9@@ -1197,15 +1197,6 @@ MSA_FN_DF(ilvl_df) }while (0 ) MSA_FN_DF(ilvr_df)#undef MSA_DO - -#define MSA_DO (DF ) \ - do { \ - pwx->DF[2*i] = pwt->DF[2*i]; \ - pwx->DF[2*i+1] = pws->DF[2*i]; \ - } while (0) -MSA_FN_DF(ilvev_df) -#undef MSA_DO -#undef MSA_LOOP_COND#define MSA_LOOP_COND (DF ) \target/mips/translate.c +45
-0@@ -28973,6 +28973,90 @@ static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd,tcg_gen_mov_i64 (msa_wr_d[wd *2 +1 ], msa_wr_d[ws *2 +1 ]); } +/* +* [MSA] ILVEV.B wd, ws, wt +* +* Vector Interleave Even (byte data elements) +* +*/ +static inline void gen_ilvev_b (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +TCGv_i64 t1 =tcg_temp_new_i64 (); +TCGv_i64 t2 =tcg_temp_new_i64 (); +TCGv_i64 mask =tcg_const_i64 (0x00ff00ff00ff00ffULL ); + +tcg_gen_and_i64 (t1, msa_wr_d[wt *2 ], mask); +tcg_gen_and_i64 (t2, msa_wr_d[ws *2 ], mask); +tcg_gen_shli_i64 (t2, t2,8 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 ], t1, t2); + +tcg_gen_and_i64 (t1, msa_wr_d[wt *2 +1 ], mask); +tcg_gen_and_i64 (t2, msa_wr_d[ws *2 +1 ], mask); +tcg_gen_shli_i64 (t2, t2,8 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 +1 ], t1, t2); + +tcg_temp_free_i64 (mask); +tcg_temp_free_i64 (t1); +tcg_temp_free_i64 (t2); +} + +/* +* [MSA] ILVEV.H wd, ws, wt +* +* Vector Interleave Even (halfword data elements) +* +*/ +static inline void gen_ilvev_h (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +TCGv_i64 t1 =tcg_temp_new_i64 (); +TCGv_i64 t2 =tcg_temp_new_i64 (); +TCGv_i64 mask =tcg_const_i64 (0x0000ffff0000ffffULL ); + +tcg_gen_and_i64 (t1, msa_wr_d[wt *2 ], mask); +tcg_gen_and_i64 (t2, msa_wr_d[ws *2 ], mask); +tcg_gen_shli_i64 (t2, t2,16 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 ], t1, t2);target/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd, · line 29030
Quoted 10 lines
target/mips/translate.c +10
-0+ +tcg_gen_and_i64 (t1, msa_wr_d[wt *2 +1 ], mask); +tcg_gen_and_i64 (t2, msa_wr_d[ws *2 +1 ], mask); +tcg_gen_shli_i64 (t2, t2,16 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 +1 ], t1, t2); + +tcg_temp_free_i64 (mask); +tcg_temp_free_i64 (t1); +tcg_temp_free_i64 (t2); +}Apparently you missed my comment about refactoring using mask/shift as arguments:
static inline void gen_ilvev_hb(CPUMIPSState *env,
uint32_twd,uint32_t ws, uint32_t wt, int64_t mask, int64_t shift) { TCGv_i64 t1 = tcg_temp_new_i64(); TCGv_i64 t2 = tcg_temp_new_i64(); TCGv_i64 tm = tcg_const_i64(mask); tcg_gen_and_i64(t1, msa_wr_d[wt * 2], tm); tcg_gen_and_i64(t2, msa_wr_d[ws * 2], tm); tcg_gen_shli_i64(t2, t2, shift); tcg_gen_or_i64(msa_wr_d[wd * 2], t1, t2); tcg_gen_and_i64(t1, msa_wr_d[wt * 2 + 1], tm); tcg_gen_and_i64(t2, msa_wr_d[ws * 2 + 1], tm); tcg_gen_shli_i64(t2, t2, shift); tcg_gen_or_i64(msa_wr_d[wd * 2 + 1], t1, t2); tcg_temp_free_i64(tm); tcg_temp_free_i64(t1); tcg_temp_free_i64(t2); }static inline void gen_ilvev_b(CPUMIPSState *env,
uint32_twd,uint32_t ws, uint32_t wt) { gen_ilvev_hb(env, wd, ws, wt, 0x00ff00ff00ff00ffLL, 8); }static inline void gen_ilvev_h(CPUMIPSState *env,
uint32_twd,uint32_t ws, uint32_t wt) { gen_ilvev_hb(env, wd, ws, wt, 0x0000ffff0000ffffLL, 16); }Quoted 49 lines
target/mips/translate.c +41
-1+ +/* +* [MSA] ILVEV.W wd, ws, wt +* +* Vector Interleave Even (word data elements) +* +*/ +static inline void gen_ilvev_w (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +tcg_gen_deposit_i64 (msa_wr_d[wd *2 ], msa_wr_d[wt *2 ], + msa_wr_d[ws *2 ],32 ,32 ); +tcg_gen_deposit_i64 (msa_wr_d[wd *2 +1 ], msa_wr_d[wt *2 +1 ], + msa_wr_d[ws *2 +1 ],32 ,32 ); +} + +/* +* [MSA] ILVEV.D wd, ws, wt +* +* Vector Interleave Even (Doubleword data elements) +* +*/ +static inline void gen_ilvev_d (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +tcg_gen_mov_i64 (msa_wr_d[wd *2 +1 ], msa_wr_d[ws *2 ]); +tcg_gen_mov_i64 (msa_wr_d[wd *2 ], msa_wr_d[wt *2 ]); +} +static void gen_msa_3r (CPUMIPSState *env,DisasContext *ctx) {#define MASK_MSA_3R (op) (MASK_MSA_MINOR(op) | (op & (0x7 << 23)))@@ -29129,7 +29213,22 @@ static void gen_msa_3r(CPUMIPSState *env, DisasContext *ctx)gen_helper_msa_mod_s_df (cpu_env, tdf, twd, tws, twt);break ;case OPC_ILVEV_df: -gen_helper_msa_ilvev_df (cpu_env, tdf, twd, tws, twt); +switch (df) { +case DF_BYTE : +gen_ilvev_b (env, wd, ws, wt); +break ; +case DF_HALF : +gen_ilvev_h (env, wd, ws, wt); +break ; +case DF_WORD : +gen_ilvev_w (env, wd, ws, wt); +break ; +case DF_DOUBLE : +gen_ilvev_d (env, wd, ws, wt);
Quoted 9 lines
target/mips/translate.c static void gen_msa_3r(CPUMIPSState *env, DisasContext *ctx) · line 29234
Quoted 8 lines
target/mips/translate.c +4
-0+break ; +default : +assert (0 ); + }break ;case OPC_BINSR_df:gen_helper_msa_binsr_df (cpu_env, tdf, twd, tws, twt);
________________________________________
From: Philippe Mathieu-Daudé <[email protected]>
Sent: Thursday, April 4, 2019 3:42 PM
To: Mateja Marjanovic; [email protected]
Cc: [email protected]; [email protected]; Aleksandar Markovic; Aleksandar Rikalo
Subject: Re: [PATCH v6 2/4] target/mips: Optimize ILVEV.<B|H|W|D> MSA instructions
Hi Mateja,
Quoted 16 lines · Mateja Marjanovic
From: Mateja Marjanovic <[email protected]>
Optimize set of MSA instructions ILVEV.<B|H|W|D>, using directly tcg registers and performing logic on them instead of using helpers.
In the following table, the first column is the performance before this patch. The second represents the performance, after converting from helpers to tcg, but without using
tcg_gen_depositfunction. The third one is the solution which is implemented in this patch.Performance measurement is done by executing the instructions a large number of times on a computer with Intel Core i7-3770 CPU @ 3.40GHz×8.
Quoted 5 lines
============================================================
|| instr || before || no-deposit || with-deposit ||
============================================================|| ilvev.b || 126.92 ms || 24.52 ms || 24.43 ms || || ilvev.h || 93.67 ms || 23.92 ms || 23.86 ms ||
I'm quite surprised there is not a single change here since your v5, are you sure you used the correct result? I was expecting a slighly improvement.
Quoted 125 lines
|| ilvev.w || 117.86 ms || 23.83 ms || 22.17 ms || || ilvev.d || 45.49 ms || 19.74 ms || 19.71 ms ||============================================================
No-deposit column and with-deposit column have the same statistical values in every row, except ILVEV.W, which is the only function which uses the deposit function.
No-deposit version of the ILVEV.W implementation:
static inline void gen_ilvev_w(CPUMIPSState *env,
uint32_twd,uint32_t ws, uint32_t wt) { TCGv_i64 t1 = tcg_temp_new_i64(); TCGv_i64 t2 = tcg_temp_new_i64(); uint64_t mask = 0x00000000ffffffffULL; tcg_gen_andi_i64(t1, msa_wr_d[wt * 2], mask); tcg_gen_andi_i64(t2, msa_wr_d[ws * 2], mask); tcg_gen_shli_i64(t2, t2, 32); tcg_gen_or_i64(msa_wr_d[wd * 2], t1, t2); tcg_gen_andi_i64(t1, msa_wr_d[wt * 2 + 1], mask); tcg_gen_andi_i64(t2, msa_wr_d[ws * 2 + 1], mask); tcg_gen_shli_i64(t2, t2, 32); tcg_gen_or_i64(msa_wr_d[wd * 2 + 1], t1, t2); tcg_temp_free_i64(t1); tcg_temp_free_i64(t2); }Suggested-by Richard Henderson <[email protected]>Signed-off-by Mateja Marjanovic <[email protected]>--- target/mips/helper.h | 1 - target/mips/msa_helper.c | 9 ----- target/mips/translate.c | 101 ++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 100 insertions(+), 11 deletions(-)target/mips/helper.h +0
-1@@ -864,7 +864,6 @@ DEF_HELPER_5(msa_pckev_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_pckod_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_ilvl_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_ilvr_df, void, env, i32, i32, i32, i32) -DEF_HELPER_5(msa_ilvev_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_vshf_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_srar_df, void, env, i32, i32, i32, i32)DEF_HELPER_5 (msa_srlr_df, void, env, i32, i32, i32, i32)target/mips/msa_helper.c +0
-9@@ -1197,15 +1197,6 @@ MSA_FN_DF(ilvl_df) }while (0 ) MSA_FN_DF(ilvr_df)#undef MSA_DO - -#define MSA_DO (DF ) \ - do { \ - pwx->DF[2*i] = pwt->DF[2*i]; \ - pwx->DF[2*i+1] = pws->DF[2*i]; \ - } while (0) -MSA_FN_DF(ilvev_df) -#undef MSA_DO -#undef MSA_LOOP_COND#define MSA_LOOP_COND (DF ) \target/mips/translate.c +45
-0@@ -28973,6 +28973,90 @@ static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd,tcg_gen_mov_i64 (msa_wr_d[wd *2 +1 ], msa_wr_d[ws *2 +1 ]); } +/* +* [MSA] ILVEV.B wd, ws, wt +* +* Vector Interleave Even (byte data elements) +* +*/ +static inline void gen_ilvev_b (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +TCGv_i64 t1 =tcg_temp_new_i64 (); +TCGv_i64 t2 =tcg_temp_new_i64 (); +TCGv_i64 mask =tcg_const_i64 (0x00ff00ff00ff00ffULL ); + +tcg_gen_and_i64 (t1, msa_wr_d[wt *2 ], mask); +tcg_gen_and_i64 (t2, msa_wr_d[ws *2 ], mask); +tcg_gen_shli_i64 (t2, t2,8 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 ], t1, t2); + +tcg_gen_and_i64 (t1, msa_wr_d[wt *2 +1 ], mask); +tcg_gen_and_i64 (t2, msa_wr_d[ws *2 +1 ], mask); +tcg_gen_shli_i64 (t2, t2,8 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 +1 ], t1, t2); + +tcg_temp_free_i64 (mask); +tcg_temp_free_i64 (t1); +tcg_temp_free_i64 (t2); +} + +/* +* [MSA] ILVEV.H wd, ws, wt +* +* Vector Interleave Even (halfword data elements) +* +*/ +static inline void gen_ilvev_h (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +TCGv_i64 t1 =tcg_temp_new_i64 (); +TCGv_i64 t2 =tcg_temp_new_i64 (); +TCGv_i64 mask =tcg_const_i64 (0x0000ffff0000ffffULL ); + +tcg_gen_and_i64 (t1, msa_wr_d[wt *2 ], mask); +tcg_gen_and_i64 (t2, msa_wr_d[ws *2 ], mask); +tcg_gen_shli_i64 (t2, t2,16 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 ], t1, t2);
target/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd, · line 29030
Quoted 10 lines
target/mips/translate.c +10
-0+ +tcg_gen_and_i64 (t1, msa_wr_d[wt *2 +1 ], mask); +tcg_gen_and_i64 (t2, msa_wr_d[ws *2 +1 ], mask); +tcg_gen_shli_i64 (t2, t2,16 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 +1 ], t1, t2); + +tcg_temp_free_i64 (mask); +tcg_temp_free_i64 (t1); +tcg_temp_free_i64 (t2); +}
Apparently you missed my comment about refactoring using mask/shift as arguments:
static inline void gen_ilvev_hb(CPUMIPSState *env, uint32_t wd,
uint32_t ws, uint32_t wt,
int64_t mask, int64_t shift)
{
TCGv_i64 t1 = tcg_temp_new_i64();
TCGv_i64 t2 = tcg_temp_new_i64();
TCGv_i64 tm = tcg_const_i64(mask);
tcg_gen_and_i64(t1, msa_wr_d[wt * 2], tm);
tcg_gen_and_i64(t2, msa_wr_d[ws * 2], tm);
tcg_gen_shli_i64(t2, t2, shift);
tcg_gen_or_i64(msa_wr_d[wd * 2], t1, t2);
tcg_gen_and_i64(t1, msa_wr_d[wt * 2 + 1], tm);
tcg_gen_and_i64(t2, msa_wr_d[ws * 2 + 1], tm);
tcg_gen_shli_i64(t2, t2, shift);
tcg_gen_or_i64(msa_wr_d[wd * 2 + 1], t1, t2);
tcg_temp_free_i64(tm);
tcg_temp_free_i64(t1);
tcg_temp_free_i64(t2);
}static inline void gen_ilvev_b(CPUMIPSState *env, uint32_t wd,
uint32_t ws, uint32_t wt)
{
gen_ilvev_hb(env, wd, ws, wt, 0x00ff00ff00ff00ffLL, 8);
}static inline void gen_ilvev_h(CPUMIPSState *env, uint32_t wd,
uint32_t ws, uint32_t wt)
{
gen_ilvev_hb(env, wd, ws, wt, 0x0000ffff0000ffffLL, 16);
}Quoted 57 lines
target/mips/translate.c +45
-1+ +/* +* [MSA] ILVEV.W wd, ws, wt +* +* Vector Interleave Even (word data elements) +* +*/ +static inline void gen_ilvev_w (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +tcg_gen_deposit_i64 (msa_wr_d[wd *2 ], msa_wr_d[wt *2 ], + msa_wr_d[ws *2 ],32 ,32 ); +tcg_gen_deposit_i64 (msa_wr_d[wd *2 +1 ], msa_wr_d[wt *2 +1 ], + msa_wr_d[ws *2 +1 ],32 ,32 ); +} + +/* +* [MSA] ILVEV.D wd, ws, wt +* +* Vector Interleave Even (Doubleword data elements) +* +*/ +static inline void gen_ilvev_d (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +tcg_gen_mov_i64 (msa_wr_d[wd *2 +1 ], msa_wr_d[ws *2 ]); +tcg_gen_mov_i64 (msa_wr_d[wd *2 ], msa_wr_d[wt *2 ]); +} +static void gen_msa_3r (CPUMIPSState *env,DisasContext *ctx) {#define MASK_MSA_3R (op) (MASK_MSA_MINOR(op) | (op & (0x7 << 23)))@@ -29129,7 +29213,22 @@ static void gen_msa_3r(CPUMIPSState *env, DisasContext *ctx)gen_helper_msa_mod_s_df (cpu_env, tdf, twd, tws, twt);break ;case OPC_ILVEV_df: -gen_helper_msa_ilvev_df (cpu_env, tdf, twd, tws, twt); +switch (df) { +case DF_BYTE : +gen_ilvev_b (env, wd, ws, wt); +break ; +case DF_HALF : +gen_ilvev_h (env, wd, ws, wt); +break ; +case DF_WORD : +gen_ilvev_w (env, wd, ws, wt); +break ; +case DF_DOUBLE : +gen_ilvev_d (env, wd, ws, wt); +break ; +default : +assert (0 ); + }break ;case OPC_BINSR_df:gen_helper_msa_binsr_df (cpu_env, tdf, twd, tws, twt);
Re: [Qemu-devel] [PATCH v6 2/4] target/mips: Optimize ILVEV.<B|H|W|D> MSA instructions
Hi Aleksandar,
Quoted 37 lines · Aleksandar Markovic
Quoted 22 lines
From: Philippe Mathieu-Daudé <[email protected]>
Subject: Re: [PATCH v6 2/4] target/mips: Optimize ILVEV.<B|H|W|D> MSA instructionsHi Mateja,
Quoted 16 lines · Mateja Marjanovic
From: Mateja Marjanovic <[email protected]>
Optimize set of MSA instructions ILVEV.<B|H|W|D>, using directly tcg registers and performing logic on them instead of using helpers.
In the following table, the first column is the performance before this patch. The second represents the performance, after converting from helpers to tcg, but without using
tcg_gen_depositfunction. The third one is the solution which is implemented in this patch.Performance measurement is done by executing the instructions a large number of times on a computer with Intel Core i7-3770 CPU @ 3.40GHz×8.
Quoted 9 lines
Quoted 5 lines
============================================================
|| instr || before || no-deposit || with-deposit ||
============================================================|| ilvev.b || 126.92 ms || 24.52 ms || 24.43 ms || || ilvev.h || 93.67 ms || 23.92 ms || 23.86 ms ||I'm quite surprised there is not a single change here since your v5, are you sure you used the correct result? I was expecting a slighly improvement.
Hello, Philippe.
First of all, thank you so much for taking your time to provide Matejan with the source code below.
Quoted 8 lines
Speaking about your idea, Mateja told me he DID implemented it, and did measurements, and that the improvement is noticeable, but really small. I don't know why he did not include that change
- perhaps he didn't have enough time to integrate it.I know he is on a long weekend now, so we will have to wait for the next week for Mateja to explain this to us. Mateja, could you perhaps add a column "with-deposit-and-mask-as-tcg-constant"?
Ah OK, no worries since this series will enter in the 4.1 dev cycle and there is still 2/3 weeks to go.
I am simply curious to see the difference using the register approach :) I recently noticed I can run those tests myself (I previously mixed threads and thought Mateja was running this on a FPGA).
I try to have a quick look at your work, and I'm pleased to see how Mateja improves the quality/accuracy of each series.
Regards,
Phil.
Quoted 504 lines
Yours,
AleksandarQuoted 224 lines
Quoted 125 lines
|| ilvev.w || 117.86 ms || 23.83 ms || 22.17 ms || || ilvev.d || 45.49 ms || 19.74 ms || 19.71 ms ||============================================================
No-deposit column and with-deposit column have the same statistical values in every row, except ILVEV.W, which is the only function which uses the deposit function.
No-deposit version of the ILVEV.W implementation:
static inline void gen_ilvev_w(CPUMIPSState *env,
uint32_twd,uint32_t ws, uint32_t wt) { TCGv_i64 t1 = tcg_temp_new_i64(); TCGv_i64 t2 = tcg_temp_new_i64(); uint64_t mask = 0x00000000ffffffffULL; tcg_gen_andi_i64(t1, msa_wr_d[wt * 2], mask); tcg_gen_andi_i64(t2, msa_wr_d[ws * 2], mask); tcg_gen_shli_i64(t2, t2, 32); tcg_gen_or_i64(msa_wr_d[wd * 2], t1, t2); tcg_gen_andi_i64(t1, msa_wr_d[wt * 2 + 1], mask); tcg_gen_andi_i64(t2, msa_wr_d[ws * 2 + 1], mask); tcg_gen_shli_i64(t2, t2, 32); tcg_gen_or_i64(msa_wr_d[wd * 2 + 1], t1, t2); tcg_temp_free_i64(t1); tcg_temp_free_i64(t2); }Suggested-by Richard Henderson <[email protected]>Signed-off-by Mateja Marjanovic <[email protected]>--- target/mips/helper.h | 1 - target/mips/msa_helper.c | 9 ----- target/mips/translate.c | 101 ++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 100 insertions(+), 11 deletions(-)target/mips/helper.h +0
-1@@ -864,7 +864,6 @@ DEF_HELPER_5(msa_pckev_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_pckod_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_ilvl_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_ilvr_df, void, env, i32, i32, i32, i32) -DEF_HELPER_5(msa_ilvev_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_vshf_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_srar_df, void, env, i32, i32, i32, i32)DEF_HELPER_5 (msa_srlr_df, void, env, i32, i32, i32, i32)target/mips/msa_helper.c +0
-9@@ -1197,15 +1197,6 @@ MSA_FN_DF(ilvl_df) }while (0 ) MSA_FN_DF(ilvr_df)#undef MSA_DO - -#define MSA_DO (DF ) \ - do { \ - pwx->DF[2*i] = pwt->DF[2*i]; \ - pwx->DF[2*i+1] = pws->DF[2*i]; \ - } while (0) -MSA_FN_DF(ilvev_df) -#undef MSA_DO -#undef MSA_LOOP_COND#define MSA_LOOP_COND (DF ) \target/mips/translate.c +45
-0@@ -28973,6 +28973,90 @@ static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd,tcg_gen_mov_i64 (msa_wr_d[wd *2 +1 ], msa_wr_d[ws *2 +1 ]); } +/* +* [MSA] ILVEV.B wd, ws, wt +* +* Vector Interleave Even (byte data elements) +* +*/ +static inline void gen_ilvev_b (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +TCGv_i64 t1 =tcg_temp_new_i64 (); +TCGv_i64 t2 =tcg_temp_new_i64 (); +TCGv_i64 mask =tcg_const_i64 (0x00ff00ff00ff00ffULL ); + +tcg_gen_and_i64 (t1, msa_wr_d[wt *2 ], mask); +tcg_gen_and_i64 (t2, msa_wr_d[ws *2 ], mask); +tcg_gen_shli_i64 (t2, t2,8 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 ], t1, t2); + +tcg_gen_and_i64 (t1, msa_wr_d[wt *2 +1 ], mask); +tcg_gen_and_i64 (t2, msa_wr_d[ws *2 +1 ], mask); +tcg_gen_shli_i64 (t2, t2,8 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 +1 ], t1, t2); + +tcg_temp_free_i64 (mask); +tcg_temp_free_i64 (t1); +tcg_temp_free_i64 (t2); +} + +/* +* [MSA] ILVEV.H wd, ws, wt +* +* Vector Interleave Even (halfword data elements) +* +*/ +static inline void gen_ilvev_h (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +TCGv_i64 t1 =tcg_temp_new_i64 (); +TCGv_i64 t2 =tcg_temp_new_i64 (); +TCGv_i64 mask =tcg_const_i64 (0x0000ffff0000ffffULL ); + +tcg_gen_and_i64 (t1, msa_wr_d[wt *2 ], mask); +tcg_gen_and_i64 (t2, msa_wr_d[ws *2 ], mask); +tcg_gen_shli_i64 (t2, t2,16 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 ], t1, t2);target/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd, · line 29030
Quoted 10 lines
target/mips/translate.c +10
-0+ +tcg_gen_and_i64 (t1, msa_wr_d[wt *2 +1 ], mask); +tcg_gen_and_i64 (t2, msa_wr_d[ws *2 +1 ], mask); +tcg_gen_shli_i64 (t2, t2,16 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 +1 ], t1, t2); + +tcg_temp_free_i64 (mask); +tcg_temp_free_i64 (t1); +tcg_temp_free_i64 (t2); +}Apparently you missed my comment about refactoring using mask/shift as arguments:
static inline void gen_ilvev_hb(CPUMIPSState *env,
uint32_twd,uint32_t ws, uint32_t wt, int64_t mask, int64_t shift) { TCGv_i64 t1 = tcg_temp_new_i64(); TCGv_i64 t2 = tcg_temp_new_i64(); TCGv_i64 tm = tcg_const_i64(mask); tcg_gen_and_i64(t1, msa_wr_d[wt * 2], tm); tcg_gen_and_i64(t2, msa_wr_d[ws * 2], tm); tcg_gen_shli_i64(t2, t2, shift); tcg_gen_or_i64(msa_wr_d[wd * 2], t1, t2); tcg_gen_and_i64(t1, msa_wr_d[wt * 2 + 1], tm); tcg_gen_and_i64(t2, msa_wr_d[ws * 2 + 1], tm); tcg_gen_shli_i64(t2, t2, shift); tcg_gen_or_i64(msa_wr_d[wd * 2 + 1], t1, t2); tcg_temp_free_i64(tm); tcg_temp_free_i64(t1); tcg_temp_free_i64(t2); }static inline void gen_ilvev_b(CPUMIPSState *env,
uint32_twd,uint32_t ws, uint32_t wt) { gen_ilvev_hb(env, wd, ws, wt, 0x00ff00ff00ff00ffLL, 8); }static inline void gen_ilvev_h(CPUMIPSState *env,
uint32_twd,uint32_t ws, uint32_t wt) { gen_ilvev_hb(env, wd, ws, wt, 0x0000ffff0000ffffLL, 16); }Quoted 49 lines
target/mips/translate.c +41
-1+ +/* +* [MSA] ILVEV.W wd, ws, wt +* +* Vector Interleave Even (word data elements) +* +*/ +static inline void gen_ilvev_w (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +tcg_gen_deposit_i64 (msa_wr_d[wd *2 ], msa_wr_d[wt *2 ], + msa_wr_d[ws *2 ],32 ,32 ); +tcg_gen_deposit_i64 (msa_wr_d[wd *2 +1 ], msa_wr_d[wt *2 +1 ], + msa_wr_d[ws *2 +1 ],32 ,32 ); +} + +/* +* [MSA] ILVEV.D wd, ws, wt +* +* Vector Interleave Even (Doubleword data elements) +* +*/ +static inline void gen_ilvev_d (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +tcg_gen_mov_i64 (msa_wr_d[wd *2 +1 ], msa_wr_d[ws *2 ]); +tcg_gen_mov_i64 (msa_wr_d[wd *2 ], msa_wr_d[wt *2 ]); +} +static void gen_msa_3r (CPUMIPSState *env,DisasContext *ctx) {#define MASK_MSA_3R (op) (MASK_MSA_MINOR(op) | (op & (0x7 << 23)))@@ -29129,7 +29213,22 @@ static void gen_msa_3r(CPUMIPSState *env, DisasContext *ctx)gen_helper_msa_mod_s_df (cpu_env, tdf, twd, tws, twt);break ;case OPC_ILVEV_df: -gen_helper_msa_ilvev_df (cpu_env, tdf, twd, tws, twt); +switch (df) { +case DF_BYTE : +gen_ilvev_b (env, wd, ws, wt); +break ; +case DF_HALF : +gen_ilvev_h (env, wd, ws, wt); +break ; +case DF_WORD : +gen_ilvev_w (env, wd, ws, wt); +break ; +case DF_DOUBLE : +gen_ilvev_d (env, wd, ws, wt);Quoted 9 lines
target/mips/translate.c static void gen_msa_3r(CPUMIPSState *env, DisasContext *ctx) · line 29234
Quoted 8 lines
target/mips/translate.c +4
-0+break ; +default : +assert (0 ); + }break ;case OPC_BINSR_df:gen_helper_msa_binsr_df (cpu_env, tdf, twd, tws, twt);________________________________________
From: Philippe Mathieu-Daudé <[email protected]>
Sent: Thursday, April 4, 2019 3:42 PM
To: Mateja Marjanovic; [email protected]
Cc: [email protected]; [email protected]; Aleksandar Markovic; Aleksandar Rikalo
Subject: Re: [PATCH v6 2/4] target/mips: Optimize ILVEV.<B|H|W|D> MSA instructionsHi Mateja,
Quoted 16 lines · Mateja Marjanovic
From: Mateja Marjanovic <[email protected]>
Optimize set of MSA instructions ILVEV.<B|H|W|D>, using directly tcg registers and performing logic on them instead of using helpers.
In the following table, the first column is the performance before this patch. The second represents the performance, after converting from helpers to tcg, but without using
tcg_gen_depositfunction. The third one is the solution which is implemented in this patch.Performance measurement is done by executing the instructions a large number of times on a computer with Intel Core i7-3770 CPU @ 3.40GHz×8.
Quoted 5 lines
============================================================
|| instr || before || no-deposit || with-deposit ||
============================================================|| ilvev.b || 126.92 ms || 24.52 ms || 24.43 ms || || ilvev.h || 93.67 ms || 23.92 ms || 23.86 ms ||I'm quite surprised there is not a single change here since your v5, are you sure you used the correct result? I was expecting a slighly improvement.
Quoted 125 lines
|| ilvev.w || 117.86 ms || 23.83 ms || 22.17 ms || || ilvev.d || 45.49 ms || 19.74 ms || 19.71 ms ||============================================================
No-deposit column and with-deposit column have the same statistical values in every row, except ILVEV.W, which is the only function which uses the deposit function.
No-deposit version of the ILVEV.W implementation:
static inline void gen_ilvev_w(CPUMIPSState *env,
uint32_twd,uint32_t ws, uint32_t wt) { TCGv_i64 t1 = tcg_temp_new_i64(); TCGv_i64 t2 = tcg_temp_new_i64(); uint64_t mask = 0x00000000ffffffffULL; tcg_gen_andi_i64(t1, msa_wr_d[wt * 2], mask); tcg_gen_andi_i64(t2, msa_wr_d[ws * 2], mask); tcg_gen_shli_i64(t2, t2, 32); tcg_gen_or_i64(msa_wr_d[wd * 2], t1, t2); tcg_gen_andi_i64(t1, msa_wr_d[wt * 2 + 1], mask); tcg_gen_andi_i64(t2, msa_wr_d[ws * 2 + 1], mask); tcg_gen_shli_i64(t2, t2, 32); tcg_gen_or_i64(msa_wr_d[wd * 2 + 1], t1, t2); tcg_temp_free_i64(t1); tcg_temp_free_i64(t2); }Suggested-by Richard Henderson <[email protected]>Signed-off-by Mateja Marjanovic <[email protected]>--- target/mips/helper.h | 1 - target/mips/msa_helper.c | 9 ----- target/mips/translate.c | 101 ++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 100 insertions(+), 11 deletions(-)target/mips/helper.h +0
-1@@ -864,7 +864,6 @@ DEF_HELPER_5(msa_pckev_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_pckod_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_ilvl_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_ilvr_df, void, env, i32, i32, i32, i32) -DEF_HELPER_5(msa_ilvev_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_vshf_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_srar_df, void, env, i32, i32, i32, i32)DEF_HELPER_5 (msa_srlr_df, void, env, i32, i32, i32, i32)target/mips/msa_helper.c +0
-9@@ -1197,15 +1197,6 @@ MSA_FN_DF(ilvl_df) }while (0 ) MSA_FN_DF(ilvr_df)#undef MSA_DO - -#define MSA_DO (DF ) \ - do { \ - pwx->DF[2*i] = pwt->DF[2*i]; \ - pwx->DF[2*i+1] = pws->DF[2*i]; \ - } while (0) -MSA_FN_DF(ilvev_df) -#undef MSA_DO -#undef MSA_LOOP_COND#define MSA_LOOP_COND (DF ) \target/mips/translate.c +45
-0@@ -28973,6 +28973,90 @@ static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd,tcg_gen_mov_i64 (msa_wr_d[wd *2 +1 ], msa_wr_d[ws *2 +1 ]); } +/* +* [MSA] ILVEV.B wd, ws, wt +* +* Vector Interleave Even (byte data elements) +* +*/ +static inline void gen_ilvev_b (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +TCGv_i64 t1 =tcg_temp_new_i64 (); +TCGv_i64 t2 =tcg_temp_new_i64 (); +TCGv_i64 mask =tcg_const_i64 (0x00ff00ff00ff00ffULL ); + +tcg_gen_and_i64 (t1, msa_wr_d[wt *2 ], mask); +tcg_gen_and_i64 (t2, msa_wr_d[ws *2 ], mask); +tcg_gen_shli_i64 (t2, t2,8 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 ], t1, t2); + +tcg_gen_and_i64 (t1, msa_wr_d[wt *2 +1 ], mask); +tcg_gen_and_i64 (t2, msa_wr_d[ws *2 +1 ], mask); +tcg_gen_shli_i64 (t2, t2,8 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 +1 ], t1, t2); + +tcg_temp_free_i64 (mask); +tcg_temp_free_i64 (t1); +tcg_temp_free_i64 (t2); +} + +/* +* [MSA] ILVEV.H wd, ws, wt +* +* Vector Interleave Even (halfword data elements) +* +*/ +static inline void gen_ilvev_h (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +TCGv_i64 t1 =tcg_temp_new_i64 (); +TCGv_i64 t2 =tcg_temp_new_i64 (); +TCGv_i64 mask =tcg_const_i64 (0x0000ffff0000ffffULL ); + +tcg_gen_and_i64 (t1, msa_wr_d[wt *2 ], mask); +tcg_gen_and_i64 (t2, msa_wr_d[ws *2 ], mask); +tcg_gen_shli_i64 (t2, t2,16 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 ], t1, t2);target/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd, · line 29030
Quoted 10 lines
target/mips/translate.c +10
-0+ +tcg_gen_and_i64 (t1, msa_wr_d[wt *2 +1 ], mask); +tcg_gen_and_i64 (t2, msa_wr_d[ws *2 +1 ], mask); +tcg_gen_shli_i64 (t2, t2,16 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 +1 ], t1, t2); + +tcg_temp_free_i64 (mask); +tcg_temp_free_i64 (t1); +tcg_temp_free_i64 (t2); +}Apparently you missed my comment about refactoring using mask/shift as arguments:
static inline void gen_ilvev_hb(CPUMIPSState *env,
uint32_twd,uint32_t ws, uint32_t wt, int64_t mask, int64_t shift) { TCGv_i64 t1 = tcg_temp_new_i64(); TCGv_i64 t2 = tcg_temp_new_i64(); TCGv_i64 tm = tcg_const_i64(mask); tcg_gen_and_i64(t1, msa_wr_d[wt * 2], tm); tcg_gen_and_i64(t2, msa_wr_d[ws * 2], tm); tcg_gen_shli_i64(t2, t2, shift); tcg_gen_or_i64(msa_wr_d[wd * 2], t1, t2); tcg_gen_and_i64(t1, msa_wr_d[wt * 2 + 1], tm); tcg_gen_and_i64(t2, msa_wr_d[ws * 2 + 1], tm); tcg_gen_shli_i64(t2, t2, shift); tcg_gen_or_i64(msa_wr_d[wd * 2 + 1], t1, t2); tcg_temp_free_i64(tm); tcg_temp_free_i64(t1); tcg_temp_free_i64(t2); }static inline void gen_ilvev_b(CPUMIPSState *env,
uint32_twd,uint32_t ws, uint32_t wt) { gen_ilvev_hb(env, wd, ws, wt, 0x00ff00ff00ff00ffLL, 8); }static inline void gen_ilvev_h(CPUMIPSState *env,
uint32_twd,uint32_t ws, uint32_t wt) { gen_ilvev_hb(env, wd, ws, wt, 0x0000ffff0000ffffLL, 16); }Quoted 57 lines
target/mips/translate.c +45
-1+ +/* +* [MSA] ILVEV.W wd, ws, wt +* +* Vector Interleave Even (word data elements) +* +*/ +static inline void gen_ilvev_w (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +tcg_gen_deposit_i64 (msa_wr_d[wd *2 ], msa_wr_d[wt *2 ], + msa_wr_d[ws *2 ],32 ,32 ); +tcg_gen_deposit_i64 (msa_wr_d[wd *2 +1 ], msa_wr_d[wt *2 +1 ], + msa_wr_d[ws *2 +1 ],32 ,32 ); +} + +/* +* [MSA] ILVEV.D wd, ws, wt +* +* Vector Interleave Even (Doubleword data elements) +* +*/ +static inline void gen_ilvev_d (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +tcg_gen_mov_i64 (msa_wr_d[wd *2 +1 ], msa_wr_d[ws *2 ]); +tcg_gen_mov_i64 (msa_wr_d[wd *2 ], msa_wr_d[wt *2 ]); +} +static void gen_msa_3r (CPUMIPSState *env,DisasContext *ctx) {#define MASK_MSA_3R (op) (MASK_MSA_MINOR(op) | (op & (0x7 << 23)))@@ -29129,7 +29213,22 @@ static void gen_msa_3r(CPUMIPSState *env, DisasContext *ctx)gen_helper_msa_mod_s_df (cpu_env, tdf, twd, tws, twt);break ;case OPC_ILVEV_df: -gen_helper_msa_ilvev_df (cpu_env, tdf, twd, tws, twt); +switch (df) { +case DF_BYTE : +gen_ilvev_b (env, wd, ws, wt); +break ; +case DF_HALF : +gen_ilvev_h (env, wd, ws, wt); +break ; +case DF_WORD : +gen_ilvev_w (env, wd, ws, wt); +break ; +case DF_DOUBLE : +gen_ilvev_d (env, wd, ws, wt); +break ; +default : +assert (0 ); + }break ;case OPC_BINSR_df:gen_helper_msa_binsr_df (cpu_env, tdf, twd, tws, twt);
Re: [Qemu-devel] [PATCH v6 2/4] target/mips: Optimize ILVEV.<B|H|W|D> MSA instructions
Quoted 6 lines · Philippe Mathieu-Daudé
Hi Aleksandar,
Quoted 2 lines · Aleksandar Markovic
Quoted 2 lines
From: Philippe Mathieu-Daudé <[email protected]>
Subject: Re: [PATCH v6 2/4] target/mips: Optimize ILVEV.<B|H|W|D> MSA
instructions
Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Hi Mateja,
Quoted 16 lines · Mateja Marjanovic
From: Mateja Marjanovic <[email protected]>
Optimize set of MSA instructions ILVEV.<B|H|W|D>, using directly tcg registers and performing logic on them instead of using helpers.
In the following table, the first column is the performance before this patch. The second represents the performance, after converting from helpers to tcg, but without using
tcg_gen_depositfunction. The third one is the solution which is implemented in this patch.Performance measurement is done by executing the instructions a large number of times on a computer with Intel Core i7-3770 CPU @ 3.40GHz×8.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
============================================================
|| instr || before || no-deposit || with-deposit ||
============================================================|| ilvev.b || 126.92 ms || 24.52 ms || 24.43 ms || || ilvev.h || 93.67 ms || 23.92 ms || 23.86 ms ||I'm quite surprised there is not a single change here since your v5,
are
Quoted 1 line
Quoted 1 line
Quoted 1 line
you sure you used the correct result? I was expecting a slighly
improvement.
Quoted 16 lines
Quoted 7 lines
Quoted 1 line
Hello, Philippe.
First of all, thank you so much for taking your time to provide Matejan with the source code below.
Quoted 8 lines
Speaking about your idea, Mateja told me he DID implemented it, and did measurements, and that the improvement is noticeable, but really small. I don't know why he did not include that change
- perhaps he didn't have enough time to integrate it.I know he is on a long weekend now, so we will have to wait for the next week for Mateja to explain this to us. Mateja, could you perhaps add a column "with-deposit-and-mask-as-tcg-constant"?
Quoted 6 lines
Ah OK, no worries since this series will enter in the 4.1 dev cycle and there is still 2/3 weeks to go.
I am simply curious to see the difference using the register approach :) I recently noticed I can run those tests myself (I previously mixed threads and thought Mateja was running this on a FPGA).
The problem with the test procedure and results that are presented here is that their accuracy is very small if the emulation of the instruction under measurement is fast. The source code is just 10,000,000 single MIPS instruction executions in a C for loop, and that is all nice and dendy if the emulation of that instruction dominates over for loop overhead, in terms of emulation time. But for instructions that are emulated fast, we are measuring more loop overhead than instruction itself.
Actually, the numbers inthat area (under letˊs say 25 ms) are plain misleading.
I think we need to devise better test, and update the table in the commit message with the new results that will be closer to the reality - and hence more informative and valuable.
BTW, I came to the conclusion that there is no faster emulation for special cases when two or three operands are the same, so those cases will not be singled out.
Aleksandar
Quoted 49 lines
I try to have a quick look at your work, and I'm pleased to see how Mateja improves the quality/accuracy of each series.
Regards,
Phil.
Quoted 42 lines
Yours,
AleksandarQuoted 38 lines
Quoted 38 lines
|| ilvev.w || 117.86 ms || 23.83 ms || 22.17 ms || || ilvev.d || 45.49 ms || 19.74 ms || 19.71 ms ||============================================================
No-deposit column and with-deposit column have the same statistical values in every row, except ILVEV.W, which is the only function which uses the deposit function.
No-deposit version of the ILVEV.W implementation:
static inline void gen_ilvev_w(CPUMIPSState *env,
uint32_twd,uint32_t ws, uint32_t wt) { TCGv_i64 t1 = tcg_temp_new_i64(); TCGv_i64 t2 = tcg_temp_new_i64(); uint64_t mask = 0x00000000ffffffffULL; tcg_gen_andi_i64(t1, msa_wr_d[wt * 2], mask); tcg_gen_andi_i64(t2, msa_wr_d[ws * 2], mask); tcg_gen_shli_i64(t2, t2, 32); tcg_gen_or_i64(msa_wr_d[wd * 2], t1, t2); tcg_gen_andi_i64(t1, msa_wr_d[wt * 2 + 1], mask); tcg_gen_andi_i64(t2, msa_wr_d[ws * 2 + 1], mask); tcg_gen_shli_i64(t2, t2, 32); tcg_gen_or_i64(msa_wr_d[wd * 2 + 1], t1, t2); tcg_temp_free_i64(t1); tcg_temp_free_i64(t2); }Suggested-by Richard Henderson <[email protected]>Signed-off-by Mateja Marjanovic <[email protected]>--- target/mips/helper.h | 1 - target/mips/msa_helper.c | 9 ----- target/mips/translate.c | 101
++++++++++++++++++++++++++++++++++++++++++++++-
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
target/mips/helper.h DEF_HELPER_5(msa_pckev_df, void, env, i32, i32,
Quoted 7 lines
3 files changed, 100 insertions(+), 11 deletions(-)target/mips/helper.h +0
-0@@ -864,7 +864,6 @@ DEF_HELPER_5(msa_pckev_df, void, env, i32, i32,
i32, i32)
Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
target/mips/helper.h +0
-1DEF_HELPER_5(msa_pckod_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_ilvl_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_ilvr_df, void, env, i32, i32, i32, i32) -DEF_HELPER_5(msa_ilvev_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_vshf_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_srar_df, void, env, i32, i32, i32, i32)DEF_HELPER_5 (msa_srlr_df, void, env, i32, i32, i32, i32)target/mips/msa_helper.c +0
-9@@ -1197,15 +1197,6 @@ MSA_FN_DF(ilvl_df) }while (0 ) MSA_FN_DF(ilvr_df)#undef MSA_DO - -#define MSA_DO (DF ) \ - do { \ - pwx->DF[2*i] = pwt->DF[2*i]; \ - pwx->DF[2*i+1] = pws->DF[2*i]; \ - } while (0) -MSA_FN_DF(ilvev_df) -#undef MSA_DO -#undef MSA_LOOP_COND
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
target/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState
Quoted 6 lines
target/mips/msa_helper.c +0
-0#define MSA_LOOP_COND (DF ) \target/mips/translate.c +0
-0@@ -28973,6 +28973,90 @@ static inline void gen_ilvod_d(CPUMIPSState
*env, uint32_t wd,
Quoted 123 lines
Quoted 123 lines
Quoted 123 lines
Quoted 48 lines
target/mips/translate.c +45
-0tcg_gen_mov_i64 (msa_wr_d[wd *2 +1 ], msa_wr_d[ws *2 +1 ]); } +/* +* [MSA] ILVEV.B wd, ws, wt +* +* Vector Interleave Even (byte data elements) +* +*/ +static inline void gen_ilvev_b (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +TCGv_i64 t1 =tcg_temp_new_i64 (); +TCGv_i64 t2 =tcg_temp_new_i64 (); +TCGv_i64 mask =tcg_const_i64 (0x00ff00ff00ff00ffULL ); + +tcg_gen_and_i64 (t1, msa_wr_d[wt *2 ], mask); +tcg_gen_and_i64 (t2, msa_wr_d[ws *2 ], mask); +tcg_gen_shli_i64 (t2, t2,8 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 ], t1, t2); + +tcg_gen_and_i64 (t1, msa_wr_d[wt *2 +1 ], mask); +tcg_gen_and_i64 (t2, msa_wr_d[ws *2 +1 ], mask); +tcg_gen_shli_i64 (t2, t2,8 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 +1 ], t1, t2); + +tcg_temp_free_i64 (mask); +tcg_temp_free_i64 (t1); +tcg_temp_free_i64 (t2); +} + +/* +* [MSA] ILVEV.H wd, ws, wt +* +* Vector Interleave Even (halfword data elements) +* +*/ +static inline void gen_ilvev_h (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +TCGv_i64 t1 =tcg_temp_new_i64 (); +TCGv_i64 t2 =tcg_temp_new_i64 (); +TCGv_i64 mask =tcg_const_i64 (0x0000ffff0000ffffULL ); + +tcg_gen_and_i64 (t1, msa_wr_d[wt *2 ], mask); +tcg_gen_and_i64 (t2, msa_wr_d[ws *2 ], mask); +tcg_gen_shli_i64 (t2, t2,16 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 ], t1, t2);target/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd, · line 29030
Quoted 10 lines
target/mips/translate.c +10
-0+ +tcg_gen_and_i64 (t1, msa_wr_d[wt *2 +1 ], mask); +tcg_gen_and_i64 (t2, msa_wr_d[ws *2 +1 ], mask); +tcg_gen_shli_i64 (t2, t2,16 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 +1 ], t1, t2); + +tcg_temp_free_i64 (mask); +tcg_temp_free_i64 (t1); +tcg_temp_free_i64 (t2); +}Apparently you missed my comment about refactoring using mask/shift as arguments:
static inline void gen_ilvev_hb(CPUMIPSState *env,
uint32_twd,uint32_t ws, uint32_t wt, int64_t mask, int64_t shift) { TCGv_i64 t1 = tcg_temp_new_i64(); TCGv_i64 t2 = tcg_temp_new_i64(); TCGv_i64 tm = tcg_const_i64(mask); tcg_gen_and_i64(t1, msa_wr_d[wt * 2], tm); tcg_gen_and_i64(t2, msa_wr_d[ws * 2], tm); tcg_gen_shli_i64(t2, t2, shift); tcg_gen_or_i64(msa_wr_d[wd * 2], t1, t2); tcg_gen_and_i64(t1, msa_wr_d[wt * 2 + 1], tm); tcg_gen_and_i64(t2, msa_wr_d[ws * 2 + 1], tm); tcg_gen_shli_i64(t2, t2, shift); tcg_gen_or_i64(msa_wr_d[wd * 2 + 1], t1, t2); tcg_temp_free_i64(tm); tcg_temp_free_i64(t1); tcg_temp_free_i64(t2); }static inline void gen_ilvev_b(CPUMIPSState *env,
uint32_twd,uint32_t ws, uint32_t wt) { gen_ilvev_hb(env, wd, ws, wt, 0x00ff00ff00ff00ffLL, 8); }static inline void gen_ilvev_h(CPUMIPSState *env,
uint32_twd,uint32_t ws, uint32_t wt) { gen_ilvev_hb(env, wd, ws, wt, 0x0000ffff0000ffffLL, 16); }Quoted 25 lines
target/mips/translate.c +25
-0+ +/* +* [MSA] ILVEV.W wd, ws, wt +* +* Vector Interleave Even (word data elements) +* +*/ +static inline void gen_ilvev_w (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +tcg_gen_deposit_i64 (msa_wr_d[wd *2 ], msa_wr_d[wt *2 ], + msa_wr_d[ws *2 ],32 ,32 ); +tcg_gen_deposit_i64 (msa_wr_d[wd *2 +1 ], msa_wr_d[wt *2 +1 ], + msa_wr_d[ws *2 +1 ],32 ,32 ); +} + +/* +* [MSA] ILVEV.D wd, ws, wt +* +* Vector Interleave Even (Doubleword data elements) +* +*/ +static inline void gen_ilvev_d (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
target/mips/translate.c static void gen_msa_3r(CPUMIPSState *env,
Quoted 8 lines
target/mips/translate.c +4
-0+tcg_gen_mov_i64 (msa_wr_d[wd *2 +1 ], msa_wr_d[ws *2 ]); +tcg_gen_mov_i64 (msa_wr_d[wd *2 ], msa_wr_d[wt *2 ]); +} +static void gen_msa_3r (CPUMIPSState *env,DisasContext *ctx) {#define MASK_MSA_3R (op) (MASK_MSA_MINOR(op) | (op & (0x7 << 23)))@@ -29129,7 +29213,22 @@ static void gen_msa_3r(CPUMIPSState *env,
DisasContext *ctx)
Quoted 25 lines
Quoted 25 lines
Quoted 25 lines
Quoted 24 lines
target/mips/translate.c +16
-1gen_helper_msa_mod_s_df (cpu_env, tdf, twd, tws, twt);break ;case OPC_ILVEV_df: -gen_helper_msa_ilvev_df (cpu_env, tdf, twd, tws, twt); +switch (df) { +case DF_BYTE : +gen_ilvev_b (env, wd, ws, wt); +break ; +case DF_HALF : +gen_ilvev_h (env, wd, ws, wt); +break ; +case DF_WORD : +gen_ilvev_w (env, wd, ws, wt); +break ; +case DF_DOUBLE : +gen_ilvev_d (env, wd, ws, wt); +break ; +default : +assert (0 ); + }break ;case OPC_BINSR_df:gen_helper_msa_binsr_df (cpu_env, tdf, twd, tws, twt);
Quoted 5 lines
Quoted 5 lines
________________________________________
From: Philippe Mathieu-Daudé <[email protected]>
Sent: Thursday, April 4, 2019 3:42 PM
To: Mateja Marjanovic; [email protected]
Cc: [email protected]; [email protected]; Aleksandar
Markovic; Aleksandar Rikalo
Quoted 1 line
Quoted 1 line
Subject: Re: [PATCH v6 2/4] target/mips: Optimize ILVEV.<B|H|W|D> MSA
instructions
Quoted 20 lines
Quoted 20 lines
Hi Mateja,
Quoted 16 lines · Mateja Marjanovic
From: Mateja Marjanovic <[email protected]>
Optimize set of MSA instructions ILVEV.<B|H|W|D>, using directly tcg registers and performing logic on them instead of using helpers.
In the following table, the first column is the performance before this patch. The second represents the performance, after converting from helpers to tcg, but without using
tcg_gen_depositfunction. The third one is the solution which is implemented in this patch.Performance measurement is done by executing the instructions a large number of times on a computer with Intel Core i7-3770 CPU @ 3.40GHz×8.
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
============================================================
|| instr || before || no-deposit || with-deposit ||
============================================================|| ilvev.b || 126.92 ms || 24.52 ms || 24.43 ms || || ilvev.h || 93.67 ms || 23.92 ms || 23.86 ms ||I'm quite surprised there is not a single change here since your v5, are you sure you used the correct result? I was expecting a slighly
improvement.
Quoted 33 lines
Quoted 33 lines
Quoted 33 lines
|| ilvev.w || 117.86 ms || 23.83 ms || 22.17 ms || || ilvev.d || 45.49 ms || 19.74 ms || 19.71 ms ||============================================================
No-deposit column and with-deposit column have the same statistical values in every row, except ILVEV.W, which is the only function which uses the deposit function.
No-deposit version of the ILVEV.W implementation:
static inline void gen_ilvev_w(CPUMIPSState *env,
uint32_twd,uint32_t ws, uint32_t wt) { TCGv_i64 t1 = tcg_temp_new_i64(); TCGv_i64 t2 = tcg_temp_new_i64(); uint64_t mask = 0x00000000ffffffffULL; tcg_gen_andi_i64(t1, msa_wr_d[wt * 2], mask); tcg_gen_andi_i64(t2, msa_wr_d[ws * 2], mask); tcg_gen_shli_i64(t2, t2, 32); tcg_gen_or_i64(msa_wr_d[wd * 2], t1, t2); tcg_gen_andi_i64(t1, msa_wr_d[wt * 2 + 1], mask); tcg_gen_andi_i64(t2, msa_wr_d[ws * 2 + 1], mask); tcg_gen_shli_i64(t2, t2, 32); tcg_gen_or_i64(msa_wr_d[wd * 2 + 1], t1, t2); tcg_temp_free_i64(t1); tcg_temp_free_i64(t2); }
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Suggested-by Richard Henderson <[email protected]>Signed-off-by Mateja Marjanovic <[email protected]>--- target/mips/helper.h | 1 - target/mips/msa_helper.c | 9 ----- target/mips/translate.c | 101
++++++++++++++++++++++++++++++++++++++++++++++-
Quoted 7 lines
Quoted 7 lines
target/mips/helper.h DEF_HELPER_5(msa_pckev_df, void, env, i32, i32,
Quoted 7 lines
3 files changed, 100 insertions(+), 11 deletions(-)target/mips/helper.h +0
-0@@ -864,7 +864,6 @@ DEF_HELPER_5(msa_pckev_df, void, env, i32, i32,
i32, i32)
Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
target/mips/helper.h +0
-1DEF_HELPER_5(msa_pckod_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_ilvl_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_ilvr_df, void, env, i32, i32, i32, i32) -DEF_HELPER_5(msa_ilvev_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_vshf_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_srar_df, void, env, i32, i32, i32, i32)DEF_HELPER_5 (msa_srlr_df, void, env, i32, i32, i32, i32)target/mips/msa_helper.c +0
-9@@ -1197,15 +1197,6 @@ MSA_FN_DF(ilvl_df) }while (0 ) MSA_FN_DF(ilvr_df)#undef MSA_DO - -#define MSA_DO (DF ) \ - do { \ - pwx->DF[2*i] = pwt->DF[2*i]; \ - pwx->DF[2*i+1] = pws->DF[2*i]; \ - } while (0) -MSA_FN_DF(ilvev_df) -#undef MSA_DO -#undef MSA_LOOP_COND
Quoted 6 lines
Quoted 6 lines
target/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState
Quoted 6 lines
target/mips/msa_helper.c +0
-0#define MSA_LOOP_COND (DF ) \target/mips/translate.c +0
-0@@ -28973,6 +28973,90 @@ static inline void gen_ilvod_d(CPUMIPSState
*env, uint32_t wd,
Quoted 123 lines
Quoted 123 lines
Quoted 48 lines
target/mips/translate.c +45
-0tcg_gen_mov_i64 (msa_wr_d[wd *2 +1 ], msa_wr_d[ws *2 +1 ]); } +/* +* [MSA] ILVEV.B wd, ws, wt +* +* Vector Interleave Even (byte data elements) +* +*/ +static inline void gen_ilvev_b (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +TCGv_i64 t1 =tcg_temp_new_i64 (); +TCGv_i64 t2 =tcg_temp_new_i64 (); +TCGv_i64 mask =tcg_const_i64 (0x00ff00ff00ff00ffULL ); + +tcg_gen_and_i64 (t1, msa_wr_d[wt *2 ], mask); +tcg_gen_and_i64 (t2, msa_wr_d[ws *2 ], mask); +tcg_gen_shli_i64 (t2, t2,8 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 ], t1, t2); + +tcg_gen_and_i64 (t1, msa_wr_d[wt *2 +1 ], mask); +tcg_gen_and_i64 (t2, msa_wr_d[ws *2 +1 ], mask); +tcg_gen_shli_i64 (t2, t2,8 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 +1 ], t1, t2); + +tcg_temp_free_i64 (mask); +tcg_temp_free_i64 (t1); +tcg_temp_free_i64 (t2); +} + +/* +* [MSA] ILVEV.H wd, ws, wt +* +* Vector Interleave Even (halfword data elements) +* +*/ +static inline void gen_ilvev_h (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +TCGv_i64 t1 =tcg_temp_new_i64 (); +TCGv_i64 t2 =tcg_temp_new_i64 (); +TCGv_i64 mask =tcg_const_i64 (0x0000ffff0000ffffULL ); + +tcg_gen_and_i64 (t1, msa_wr_d[wt *2 ], mask); +tcg_gen_and_i64 (t2, msa_wr_d[ws *2 ], mask); +tcg_gen_shli_i64 (t2, t2,16 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 ], t1, t2);target/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd, · line 29030
Quoted 10 lines
target/mips/translate.c +10
-0+ +tcg_gen_and_i64 (t1, msa_wr_d[wt *2 +1 ], mask); +tcg_gen_and_i64 (t2, msa_wr_d[ws *2 +1 ], mask); +tcg_gen_shli_i64 (t2, t2,16 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 +1 ], t1, t2); + +tcg_temp_free_i64 (mask); +tcg_temp_free_i64 (t1); +tcg_temp_free_i64 (t2); +}Apparently you missed my comment about refactoring using mask/shift as arguments:
static inline void gen_ilvev_hb(CPUMIPSState *env,
uint32_twd,uint32_t ws, uint32_t wt, int64_t mask, int64_t shift) { TCGv_i64 t1 = tcg_temp_new_i64(); TCGv_i64 t2 = tcg_temp_new_i64(); TCGv_i64 tm = tcg_const_i64(mask); tcg_gen_and_i64(t1, msa_wr_d[wt * 2], tm); tcg_gen_and_i64(t2, msa_wr_d[ws * 2], tm); tcg_gen_shli_i64(t2, t2, shift); tcg_gen_or_i64(msa_wr_d[wd * 2], t1, t2); tcg_gen_and_i64(t1, msa_wr_d[wt * 2 + 1], tm); tcg_gen_and_i64(t2, msa_wr_d[ws * 2 + 1], tm); tcg_gen_shli_i64(t2, t2, shift); tcg_gen_or_i64(msa_wr_d[wd * 2 + 1], t1, t2); tcg_temp_free_i64(tm); tcg_temp_free_i64(t1); tcg_temp_free_i64(t2); }static inline void gen_ilvev_b(CPUMIPSState *env,
uint32_twd,uint32_t ws, uint32_t wt) { gen_ilvev_hb(env, wd, ws, wt, 0x00ff00ff00ff00ffLL, 8); }static inline void gen_ilvev_h(CPUMIPSState *env,
uint32_twd,uint32_t ws, uint32_t wt) { gen_ilvev_hb(env, wd, ws, wt, 0x0000ffff0000ffffLL, 16); }Quoted 25 lines
target/mips/translate.c +25
-0+ +/* +* [MSA] ILVEV.W wd, ws, wt +* +* Vector Interleave Even (word data elements) +* +*/ +static inline void gen_ilvev_w (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +tcg_gen_deposit_i64 (msa_wr_d[wd *2 ], msa_wr_d[wt *2 ], + msa_wr_d[ws *2 ],32 ,32 ); +tcg_gen_deposit_i64 (msa_wr_d[wd *2 +1 ], msa_wr_d[wt *2 +1 ], + msa_wr_d[ws *2 +1 ],32 ,32 ); +} + +/* +* [MSA] ILVEV.D wd, ws, wt +* +* Vector Interleave Even (Doubleword data elements) +* +*/ +static inline void gen_ilvev_d (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{
Quoted 8 lines
Quoted 8 lines
target/mips/translate.c static void gen_msa_3r(CPUMIPSState *env,
Quoted 8 lines
target/mips/translate.c +4
-0+tcg_gen_mov_i64 (msa_wr_d[wd *2 +1 ], msa_wr_d[ws *2 ]); +tcg_gen_mov_i64 (msa_wr_d[wd *2 ], msa_wr_d[wt *2 ]); +} +static void gen_msa_3r (CPUMIPSState *env,DisasContext *ctx) {#define MASK_MSA_3R (op) (MASK_MSA_MINOR(op) | (op & (0x7 << 23)))@@ -29129,7 +29213,22 @@ static void gen_msa_3r(CPUMIPSState *env,
DisasContext *ctx)
Quoted 25 lines
Quoted 24 lines
Quoted 24 lines
target/mips/translate.c +16
-1gen_helper_msa_mod_s_df (cpu_env, tdf, twd, tws, twt);break ;case OPC_ILVEV_df: -gen_helper_msa_ilvev_df (cpu_env, tdf, twd, tws, twt); +switch (df) { +case DF_BYTE : +gen_ilvev_b (env, wd, ws, wt); +break ; +case DF_HALF : +gen_ilvev_h (env, wd, ws, wt); +break ; +case DF_WORD : +gen_ilvev_w (env, wd, ws, wt); +break ; +case DF_DOUBLE : +gen_ilvev_d (env, wd, ws, wt); +break ; +default : +assert (0 ); + }break ;case OPC_BINSR_df:gen_helper_msa_binsr_df (cpu_env, tdf, twd, tws, twt);
Re: [Qemu-devel] [PATCH v6 2/4] target/mips: Optimize ILVEV.<B|H|W|D> MSA instructions
In reply to Philippe Mathieu-DaudéHello Philippe,
Sorry for replying you so late.
Quoted 19 lines · Philippe Mathieu-Daudé
Hi Mateja,
Quoted 16 lines · Mateja Marjanovic
From: Mateja Marjanovic <[email protected]>
Optimize set of MSA instructions ILVEV.<B|H|W|D>, using directly tcg registers and performing logic on them instead of using helpers.
In the following table, the first column is the performance before this patch. The second represents the performance, after converting from helpers to tcg, but without using
tcg_gen_depositfunction. The third one is the solution which is implemented in this patch.Performance measurement is done by executing the instructions a large number of times on a computer with Intel Core i7-3770 CPU @ 3.40GHz×8.
Quoted 7 lines
Quoted 5 lines
============================================================
|| instr || before || no-deposit || with-deposit ||
============================================================|| ilvev.b || 126.92 ms || 24.52 ms || 24.43 ms || || ilvev.h || 93.67 ms || 23.92 ms || 23.86 ms ||I'm quite surprised there is not a single change here since your v5, are you sure you used the correct result? I was expecting a slighly improvement.
There is a slight improvement when using tcg constants instead of int constants variables, but I didn't change the performance table, by mistake. In v7, it will be more clear.
Quoted 168 lines
Quoted 126 lines
|| ilvev.w || 117.86 ms || 23.83 ms || 22.17 ms || || ilvev.d || 45.49 ms || 19.74 ms || 19.71 ms ||============================================================
No-deposit column and with-deposit column have the same statistical values in every row, except ILVEV.W, which is the only function which uses the deposit function.
No-deposit version of the ILVEV.W implementation:
static inline void gen_ilvev_w(CPUMIPSState *env,
uint32_twd,uint32_t ws, uint32_t wt) { TCGv_i64 t1 = tcg_temp_new_i64(); TCGv_i64 t2 = tcg_temp_new_i64(); uint64_t mask = 0x00000000ffffffffULL; tcg_gen_andi_i64(t1, msa_wr_d[wt * 2], mask); tcg_gen_andi_i64(t2, msa_wr_d[ws * 2], mask); tcg_gen_shli_i64(t2, t2, 32); tcg_gen_or_i64(msa_wr_d[wd * 2], t1, t2); tcg_gen_andi_i64(t1, msa_wr_d[wt * 2 + 1], mask); tcg_gen_andi_i64(t2, msa_wr_d[ws * 2 + 1], mask); tcg_gen_shli_i64(t2, t2, 32); tcg_gen_or_i64(msa_wr_d[wd * 2 + 1], t1, t2); tcg_temp_free_i64(t1); tcg_temp_free_i64(t2); }Suggested-by Richard Henderson <[email protected]>Signed-off-by Mateja Marjanovic <[email protected]>--- target/mips/helper.h | 1 - target/mips/msa_helper.c | 9 ----- target/mips/translate.c | 101 ++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 100 insertions(+), 11 deletions(-)target/mips/helper.h +0
-1@@ -864,7 +864,6 @@ DEF_HELPER_5(msa_pckev_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_pckod_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_ilvl_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_ilvr_df, void, env, i32, i32, i32, i32) -DEF_HELPER_5(msa_ilvev_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_vshf_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_srar_df, void, env, i32, i32, i32, i32)DEF_HELPER_5 (msa_srlr_df, void, env, i32, i32, i32, i32)target/mips/msa_helper.c +0
-9@@ -1197,15 +1197,6 @@ MSA_FN_DF(ilvl_df) }while (0 ) MSA_FN_DF(ilvr_df)#undef MSA_DO - -#define MSA_DO (DF ) \ - do { \ - pwx->DF[2*i] = pwt->DF[2*i]; \ - pwx->DF[2*i+1] = pws->DF[2*i]; \ - } while (0) -MSA_FN_DF(ilvev_df) -#undef MSA_DO -#undef MSA_LOOP_COND#define MSA_LOOP_COND (DF ) \target/mips/translate.c +45
-0@@ -28973,6 +28973,90 @@ static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd,tcg_gen_mov_i64 (msa_wr_d[wd *2 +1 ], msa_wr_d[ws *2 +1 ]); } +/* +* [MSA] ILVEV.B wd, ws, wt +* +* Vector Interleave Even (byte data elements) +* +*/ +static inline void gen_ilvev_b (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +TCGv_i64 t1 =tcg_temp_new_i64 (); +TCGv_i64 t2 =tcg_temp_new_i64 (); +TCGv_i64 mask =tcg_const_i64 (0x00ff00ff00ff00ffULL ); + +tcg_gen_and_i64 (t1, msa_wr_d[wt *2 ], mask); +tcg_gen_and_i64 (t2, msa_wr_d[ws *2 ], mask); +tcg_gen_shli_i64 (t2, t2,8 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 ], t1, t2); + +tcg_gen_and_i64 (t1, msa_wr_d[wt *2 +1 ], mask); +tcg_gen_and_i64 (t2, msa_wr_d[ws *2 +1 ], mask); +tcg_gen_shli_i64 (t2, t2,8 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 +1 ], t1, t2); + +tcg_temp_free_i64 (mask); +tcg_temp_free_i64 (t1); +tcg_temp_free_i64 (t2); +} + +/* +* [MSA] ILVEV.H wd, ws, wt +* +* Vector Interleave Even (halfword data elements) +* +*/ +static inline void gen_ilvev_h (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +TCGv_i64 t1 =tcg_temp_new_i64 (); +TCGv_i64 t2 =tcg_temp_new_i64 (); +TCGv_i64 mask =tcg_const_i64 (0x0000ffff0000ffffULL ); + +tcg_gen_and_i64 (t1, msa_wr_d[wt *2 ], mask); +tcg_gen_and_i64 (t2, msa_wr_d[ws *2 ], mask); +tcg_gen_shli_i64 (t2, t2,16 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 ], t1, t2);target/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd, · line 29030
Quoted 10 lines
target/mips/translate.c +10
-0+ +tcg_gen_and_i64 (t1, msa_wr_d[wt *2 +1 ], mask); +tcg_gen_and_i64 (t2, msa_wr_d[ws *2 +1 ], mask); +tcg_gen_shli_i64 (t2, t2,16 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 +1 ], t1, t2); + +tcg_temp_free_i64 (mask); +tcg_temp_free_i64 (t1); +tcg_temp_free_i64 (t2); +}Apparently you missed my comment about refactoring using mask/shift as arguments:
static inline void gen_ilvev_hb(CPUMIPSState *env,
uint32_twd,uint32_t ws, uint32_t wt, int64_t mask, int64_t shift) { TCGv_i64 t1 = tcg_temp_new_i64(); TCGv_i64 t2 = tcg_temp_new_i64(); TCGv_i64 tm = tcg_const_i64(mask); tcg_gen_and_i64(t1, msa_wr_d[wt * 2], tm); tcg_gen_and_i64(t2, msa_wr_d[ws * 2], tm); tcg_gen_shli_i64(t2, t2, shift); tcg_gen_or_i64(msa_wr_d[wd * 2], t1, t2); tcg_gen_and_i64(t1, msa_wr_d[wt * 2 + 1], tm); tcg_gen_and_i64(t2, msa_wr_d[ws * 2 + 1], tm); tcg_gen_shli_i64(t2, t2, shift); tcg_gen_or_i64(msa_wr_d[wd * 2 + 1], t1, t2); tcg_temp_free_i64(tm); tcg_temp_free_i64(t1); tcg_temp_free_i64(t2); }static inline void gen_ilvev_b(CPUMIPSState *env,
uint32_twd,uint32_t ws, uint32_t wt) { gen_ilvev_hb(env, wd, ws, wt, 0x00ff00ff00ff00ffLL, 8); }
Quoted 5 lines
static inline void gen_ilvev_h(CPUMIPSState *env,
uint32_twd,uint32_t ws, uint32_t wt) { gen_ilvev_hb(env, wd, ws, wt, 0x0000ffff0000ffffLL, 16); }
Yes, I did miss it. I will do what you suggested in v7. It represents a nice code reorganisation.
Quoted 50 lines
Quoted 50 lines
target/mips/translate.c +40
-1+ +/* +* [MSA] ILVEV.W wd, ws, wt +* +* Vector Interleave Even (word data elements) +* +*/ +static inline void gen_ilvev_w (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +tcg_gen_deposit_i64 (msa_wr_d[wd *2 ], msa_wr_d[wt *2 ], + msa_wr_d[ws *2 ],32 ,32 ); +tcg_gen_deposit_i64 (msa_wr_d[wd *2 +1 ], msa_wr_d[wt *2 +1 ], + msa_wr_d[ws *2 +1 ],32 ,32 ); +} + +/* +* [MSA] ILVEV.D wd, ws, wt +* +* Vector Interleave Even (Doubleword data elements) +* +*/ +static inline void gen_ilvev_d (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +tcg_gen_mov_i64 (msa_wr_d[wd *2 +1 ], msa_wr_d[ws *2 ]); +tcg_gen_mov_i64 (msa_wr_d[wd *2 ], msa_wr_d[wt *2 ]); +} +static void gen_msa_3r (CPUMIPSState *env,DisasContext *ctx) {#define MASK_MSA_3R (op) (MASK_MSA_MINOR(op) | (op & (0x7 << 23)))@@ -29129,7 +29213,22 @@ static void gen_msa_3r(CPUMIPSState *env, DisasContext *ctx)gen_helper_msa_mod_s_df (cpu_env, tdf, twd, tws, twt);break ;case OPC_ILVEV_df: -gen_helper_msa_ilvev_df (cpu_env, tdf, twd, tws, twt); +switch (df) { +case DF_BYTE : +gen_ilvev_b (env, wd, ws, wt); +break ; +case DF_HALF : +gen_ilvev_h (env, wd, ws, wt); +break ; +case DF_WORD : +gen_ilvev_w (env, wd, ws, wt); +break ; +case DF_DOUBLE :
Quoted 8 lines
target/mips/translate.c static void gen_msa_3r(CPUMIPSState *env, DisasContext *ctx) · line 29234
Quoted 8 lines
target/mips/translate.c +5
-0+gen_ilvev_d (env, wd, ws, wt); +break ; +default : +assert (0 ); + }break ;case OPC_BINSR_df:gen_helper_msa_binsr_df (cpu_env, tdf, twd, tws, twt);
Thank you for looking so deeply into my code.
Regards,
Mateja
Re: [Qemu-devel] [PATCH v6 2/4] target/mips: Optimize ILVEV.<B|H|W|D> MSA instructions
In reply to Mateja MarjanovicQuoted 7 lines · Mateja Marjanovic
From: Mateja Marjanovic <[email protected]>
Optimize set of MSA instructions ILVEV.<B|H|W|D>, using directly tcg registers and performing logic on them instead of using helpers.
Quoted 8 lines
In the following table, the first column is the performance before this patch. The second represents the performance, after converting from helpers to tcg, but without using
tcg_gen_depositfunction. The third one is the solution which is implemented in this patch.Performance measurement is done by executing the instructions a large number of times on a computer
What is the exact number of times?
Quoted 11 lines
with Intel Core i7-3770 CPU @ 3.40GHz×8.
============================================================
|| instr || before || no-deposit || with-deposit ||
============================================================|| ilvev.b || 126.92 ms || 24.52 ms || 24.43 ms || || ilvev.h || 93.67 ms || 23.92 ms || 23.86 ms || || ilvev.w || 117.86 ms || 23.83 ms || 22.17 ms || || ilvev.d || 45.49 ms || 19.74 ms || 19.71 ms ||============================================================
"With-deposit" for ilvev.w can't be the same as in the previous version (22.17 ms), since you eliminated one tcg_gen_andi_i64() in this version compared to the previous one. "With-deposit" for ilvev.wb and ilvev.h also can't be the same. It looks you just copy-pasted the numbers. Please retest the performance and attach the accurate numbers.
Also, there should be five columns and their meanings should be:
- instruction
- before
- no-deposit-no-mask-as-tcg-constant
- with-deposit-no-mask-as-tcg-constant
- with-deposit-with-mask-as-tcg-constant (final)
Quoted 28 lines
No-deposit column and with-deposit column have the same statistical values in every row, except ILVEV.W, which is the only function which uses the deposit function.
No-deposit version of the ILVEV.W implementation:
static inline void gen_ilvev_w(CPUMIPSState *env,
uint32_twd,uint32_t ws, uint32_t wt) { TCGv_i64 t1 = tcg_temp_new_i64(); TCGv_i64 t2 = tcg_temp_new_i64(); uint64_t mask = 0x00000000ffffffffULL; tcg_gen_andi_i64(t1, msa_wr_d[wt * 2], mask); tcg_gen_andi_i64(t2, msa_wr_d[ws * 2], mask); tcg_gen_shli_i64(t2, t2, 32); tcg_gen_or_i64(msa_wr_d[wd * 2], t1, t2); tcg_gen_andi_i64(t1, msa_wr_d[wt * 2 + 1], mask); tcg_gen_andi_i64(t2, msa_wr_d[ws * 2 + 1], mask); tcg_gen_shli_i64(t2, t2, 32); tcg_gen_or_i64(msa_wr_d[wd * 2 + 1], t1, t2); tcg_temp_free_i64(t1); tcg_temp_free_i64(t2); }
Quoted 1 line
Suggested-by Richard Henderson <[email protected]>
You forgot Philippe.
Quoted 92 lines
Signed-off-by Mateja Marjanovic <[email protected]>--- target/mips/helper.h | 1 - target/mips/msa_helper.c | 9 ----- target/mips/translate.c | 101 ++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 100 insertions(+), 11 deletions(-)target/mips/helper.h +0
-1@@ -864,7 +864,6 @@ DEF_HELPER_5(msa_pckev_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_pckod_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_ilvl_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_ilvr_df, void, env, i32, i32, i32, i32) -DEF_HELPER_5(msa_ilvev_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_vshf_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_srar_df, void, env, i32, i32, i32, i32)DEF_HELPER_5 (msa_srlr_df, void, env, i32, i32, i32, i32)target/mips/msa_helper.c +0
-9@@ -1197,15 +1197,6 @@ MSA_FN_DF(ilvl_df) }while (0 ) MSA_FN_DF(ilvr_df)#undef MSA_DO - -#define MSA_DO (DF ) \ - do { \ - pwx->DF[2*i] = pwt->DF[2*i]; \ - pwx->DF[2*i+1] = pws->DF[2*i]; \ - } while (0) -MSA_FN_DF(ilvev_df) -#undef MSA_DO -#undef MSA_LOOP_COND#define MSA_LOOP_COND (DF ) \target/mips/translate.c +45
-0@@ -28973,6 +28973,90 @@ static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd,tcg_gen_mov_i64 (msa_wr_d[wd *2 +1 ], msa_wr_d[ws *2 +1 ]); } +/* +* [MSA] ILVEV.B wd, ws, wt +* +* Vector Interleave Even (byte data elements) +* +*/ +static inline void gen_ilvev_b (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +TCGv_i64 t1 =tcg_temp_new_i64 (); +TCGv_i64 t2 =tcg_temp_new_i64 (); +TCGv_i64 mask =tcg_const_i64 (0x00ff00ff00ff00ffULL ); + +tcg_gen_and_i64 (t1, msa_wr_d[wt *2 ], mask); +tcg_gen_and_i64 (t2, msa_wr_d[ws *2 ], mask); +tcg_gen_shli_i64 (t2, t2,8 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 ], t1, t2); + +tcg_gen_and_i64 (t1, msa_wr_d[wt *2 +1 ], mask); +tcg_gen_and_i64 (t2, msa_wr_d[ws *2 +1 ], mask); +tcg_gen_shli_i64 (t2, t2,8 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 +1 ], t1, t2); + +tcg_temp_free_i64 (mask); +tcg_temp_free_i64 (t1); +tcg_temp_free_i64 (t2); +} + +/* +* [MSA] ILVEV.H wd, ws, wt +* +* Vector Interleave Even (halfword data elements) +* +*/ +static inline void gen_ilvev_h (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +TCGv_i64 t1 =tcg_temp_new_i64 (); +TCGv_i64 t2 =tcg_temp_new_i64 (); +TCGv_i64 mask =tcg_const_i64 (0x0000ffff0000ffffULL ); + +tcg_gen_and_i64 (t1, msa_wr_d[wt *2 ], mask); +tcg_gen_and_i64 (t2, msa_wr_d[ws *2 ], mask); +tcg_gen_shli_i64 (t2, t2,16 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 ], t1, t2);
target/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd, · line 29030
Quoted 10 lines
target/mips/translate.c +10
-0+ +tcg_gen_and_i64 (t1, msa_wr_d[wt *2 +1 ], mask); +tcg_gen_and_i64 (t2, msa_wr_d[ws *2 +1 ], mask); +tcg_gen_shli_i64 (t2, t2,16 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 +1 ], t1, t2); + +tcg_temp_free_i64 (mask); +tcg_temp_free_i64 (t1); +tcg_temp_free_i64 (t2); +}
Please apply Philippe's refactoring for the preceding two functions.
Quoted 10 lines
target/mips/translate.c +10
-0+ +/* +* [MSA] ILVEV.W wd, ws, wt +* +* Vector Interleave Even (word data elements) +* +*/ +static inline void gen_ilvev_w (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{
target/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd, · line 29050
Quoted 10 lines
target/mips/translate.c +10
-0+tcg_gen_deposit_i64 (msa_wr_d[wd *2 ], msa_wr_d[wt *2 ], + msa_wr_d[ws *2 ],32 ,32 ); +tcg_gen_deposit_i64 (msa_wr_d[wd *2 +1 ], msa_wr_d[wt *2 +1 ], + msa_wr_d[ws *2 +1 ],32 ,32 ); +} + +/* +* [MSA] ILVEV.D wd, ws, wt +* +* Vector Interleave Even (Doubleword data elements)
Doubleword -> doubleword
Quoted 37 lines
target/mips/translate.c +25
-2+* +*/ +static inline void gen_ilvev_d (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +tcg_gen_mov_i64 (msa_wr_d[wd *2 +1 ], msa_wr_d[ws *2 ]); +tcg_gen_mov_i64 (msa_wr_d[wd *2 ], msa_wr_d[wt *2 ]); +} +static void gen_msa_3r (CPUMIPSState *env,DisasContext *ctx) {#define MASK_MSA_3R (op) (MASK_MSA_MINOR(op) | (op & (0x7 << 23)))@@ -29129,7 +29213,22 @@ static void gen_msa_3r(CPUMIPSState *env, DisasContext *ctx)gen_helper_msa_mod_s_df (cpu_env, tdf, twd, tws, twt);break ;case OPC_ILVEV_df: -gen_helper_msa_ilvev_df (cpu_env, tdf, twd, tws, twt); +switch (df) { +case DF_BYTE : +gen_ilvev_b (env, wd, ws, wt); +break ; +case DF_HALF : +gen_ilvev_h (env, wd, ws, wt); +break ; +case DF_WORD : +gen_ilvev_w (env, wd, ws, wt); +break ; +case DF_DOUBLE : +gen_ilvev_d (env, wd, ws, wt); +break ; +default : +assert (0 ); + }break ;case OPC_BINSR_df:gen_helper_msa_binsr_df (cpu_env, tdf, twd, tws, twt); --
Quoted 3 lines
2.7.4
Thanks,
Aleksandar
Re: [Qemu-devel] [PATCH v6 2/4] target/mips: Optimize ILVEV.<B|H|W|D> MSA instructions
Quoted 14 lines · Aleksandar Markovic
Quoted 12 lines · Mateja Marjanovic
From: Mateja Marjanovic <[email protected]>
Optimize set of MSA instructions ILVEV.<B|H|W|D>, using directly tcg registers and performing logic on them instead of using helpers.
In the following table, the first column is the performance before this patch. The second represents the performance, after converting from helpers to tcg, but without using
tcg_gen_depositfunction. The third one is the solution which is implemented in this patch.
Quoted 3 lines
Quoted 2 lines
Performance measurement is done by executing the instructions a large number of times on a computer
What is the exact number of times?
I will add that from now on.
Quoted 12 lines
Quoted 12 lines
with Intel Core i7-3770 CPU @ 3.40GHz×8.
============================================================
|| instr || before || no-deposit || with-deposit ||
============================================================|| ilvev.b || 126.92 ms || 24.52 ms || 24.43 ms || || ilvev.h || 93.67 ms || 23.92 ms || 23.86 ms || || ilvev.w || 117.86 ms || 23.83 ms || 22.17 ms || || ilvev.d || 45.49 ms || 19.74 ms || 19.71 ms ||============================================================
Quoted 6 lines
"With-deposit" for ilvev.w can't be the same as in the previous version (22.17 ms), since you eliminated one
tcg_gen_andi_i64()in this version compared to the previous one. "With-deposit" for ilvev.wb andilvev.halso can't be the same. It looks you just copy-pasted the numbers. Please retest the performance and attach the accurate numbers.
My mistake, I will add it in v7.
Quoted 8 lines
Also, there should be five columns and their meanings should be:
- instruction
- before
- no-deposit-no-mask-as-tcg-constant
- with-deposit-no-mask-as-tcg-constant
- with-deposit-with-mask-as-tcg-constant (final)
Alright, but the deposit function and mask as a tcg constant are optimizations for two different problems. The deposit function is used only in case of word, and mask as a tcg constant in halfword and byte.
Quoted 24 lines
Quoted 24 lines
No-deposit column and with-deposit column have the same statistical values in every row, except ILVEV.W, which is the only function which uses the deposit function.
No-deposit version of the ILVEV.W implementation:
static inline void gen_ilvev_w(CPUMIPSState *env,
uint32_twd,uint32_t ws, uint32_t wt) { TCGv_i64 t1 = tcg_temp_new_i64(); TCGv_i64 t2 = tcg_temp_new_i64(); uint64_t mask = 0x00000000ffffffffULL; tcg_gen_andi_i64(t1, msa_wr_d[wt * 2], mask); tcg_gen_andi_i64(t2, msa_wr_d[ws * 2], mask); tcg_gen_shli_i64(t2, t2, 32); tcg_gen_or_i64(msa_wr_d[wd * 2], t1, t2); tcg_gen_andi_i64(t1, msa_wr_d[wt * 2 + 1], mask); tcg_gen_andi_i64(t2, msa_wr_d[ws * 2 + 1], mask); tcg_gen_shli_i64(t2, t2, 32); tcg_gen_or_i64(msa_wr_d[wd * 2 + 1], t1, t2);
Quoted 6 lines
Quoted 5 lines
tcg_temp_free_i64(t1); tcg_temp_free_i64(t2); }Suggested-by Richard Henderson <[email protected]>You forgot Philippe.
I will add Philippe, ofcourse.
Quoted 96 lines
Quoted 96 lines
Signed-off-by Mateja Marjanovic <[email protected]>--- target/mips/helper.h | 1 - target/mips/msa_helper.c | 9 ----- target/mips/translate.c | 101 ++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 100 insertions(+), 11 deletions(-)target/mips/helper.h +0
-1@@ -864,7 +864,6 @@ DEF_HELPER_5(msa_pckev_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_pckod_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_ilvl_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_ilvr_df, void, env, i32, i32, i32, i32) -DEF_HELPER_5(msa_ilvev_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_vshf_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_srar_df, void, env, i32, i32, i32, i32)DEF_HELPER_5 (msa_srlr_df, void, env, i32, i32, i32, i32)target/mips/msa_helper.c +0
-9@@ -1197,15 +1197,6 @@ MSA_FN_DF(ilvl_df) }while (0 ) MSA_FN_DF(ilvr_df)#undef MSA_DO - -#define MSA_DO (DF ) \ - do { \ - pwx->DF[2*i] = pwt->DF[2*i]; \ - pwx->DF[2*i+1] = pws->DF[2*i]; \ - } while (0) -MSA_FN_DF(ilvev_df) -#undef MSA_DO -#undef MSA_LOOP_COND#define MSA_LOOP_COND (DF ) \target/mips/translate.c +48
-0@@ -28973,6 +28973,90 @@ static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd,tcg_gen_mov_i64 (msa_wr_d[wd *2 +1 ], msa_wr_d[ws *2 +1 ]); } +/* +* [MSA] ILVEV.B wd, ws, wt +* +* Vector Interleave Even (byte data elements) +* +*/ +static inline void gen_ilvev_b (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +TCGv_i64 t1 =tcg_temp_new_i64 (); +TCGv_i64 t2 =tcg_temp_new_i64 (); +TCGv_i64 mask =tcg_const_i64 (0x00ff00ff00ff00ffULL ); + +tcg_gen_and_i64 (t1, msa_wr_d[wt *2 ], mask); +tcg_gen_and_i64 (t2, msa_wr_d[ws *2 ], mask); +tcg_gen_shli_i64 (t2, t2,8 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 ], t1, t2); + +tcg_gen_and_i64 (t1, msa_wr_d[wt *2 +1 ], mask); +tcg_gen_and_i64 (t2, msa_wr_d[ws *2 +1 ], mask); +tcg_gen_shli_i64 (t2, t2,8 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 +1 ], t1, t2); + +tcg_temp_free_i64 (mask); +tcg_temp_free_i64 (t1); +tcg_temp_free_i64 (t2); +} + +/* +* [MSA] ILVEV.H wd, ws, wt +* +* Vector Interleave Even (halfword data elements) +* +*/ +static inline void gen_ilvev_h (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +TCGv_i64 t1 =tcg_temp_new_i64 (); +TCGv_i64 t2 =tcg_temp_new_i64 (); +TCGv_i64 mask =tcg_const_i64 (0x0000ffff0000ffffULL ); + +tcg_gen_and_i64 (t1, msa_wr_d[wt *2 ], mask); +tcg_gen_and_i64 (t2, msa_wr_d[ws *2 ], mask); +tcg_gen_shli_i64 (t2, t2,16 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 ], t1, t2); + +tcg_gen_and_i64 (t1, msa_wr_d[wt *2 +1 ], mask); +tcg_gen_and_i64 (t2, msa_wr_d[ws *2 +1 ], mask);
Quoted 8 lines
target/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd, · line 29030
Quoted 7 lines
target/mips/translate.c +7
-0+tcg_gen_shli_i64 (t2, t2,16 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 +1 ], t1, t2); + +tcg_temp_free_i64 (mask); +tcg_temp_free_i64 (t1); +tcg_temp_free_i64 (t2); +}Please apply Philippe's refactoring for the preceding two functions.
I will in v7.
Quoted 14 lines
Quoted 14 lines
target/mips/translate.c +13
-0+ +/* +* [MSA] ILVEV.W wd, ws, wt +* +* Vector Interleave Even (word data elements) +* +*/ +static inline void gen_ilvev_w (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +tcg_gen_deposit_i64 (msa_wr_d[wd *2 ], msa_wr_d[wt *2 ], + msa_wr_d[ws *2 ],32 ,32 ); + tcg_gen_deposit_i64(msa_wr_d[wd * 2 + 1], msa_wr_d[wt * 2 + 1],
Quoted 8 lines
target/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd, · line 29050
Quoted 7 lines
target/mips/translate.c +7
-0+ msa_wr_d[ws * 2 + 1], 32, 32); +} + +/* +* [MSA] ILVEV.D wd, ws, wt +* +* Vector Interleave Even (Doubleword data elements) Doubleword -> doubleword
It will be changed in v7.
Quoted 35 lines
Quoted 35 lines
target/mips/translate.c +25
-1+* +*/ +static inline void gen_ilvev_d (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +tcg_gen_mov_i64 (msa_wr_d[wd *2 +1 ], msa_wr_d[ws *2 ]); +tcg_gen_mov_i64 (msa_wr_d[wd *2 ], msa_wr_d[wt *2 ]); +} +static void gen_msa_3r (CPUMIPSState *env,DisasContext *ctx) {#define MASK_MSA_3R (op) (MASK_MSA_MINOR(op) | (op & (0x7 << 23)))@@ -29129,7 +29213,22 @@ static void gen_msa_3r(CPUMIPSState *env, DisasContext *ctx)gen_helper_msa_mod_s_df (cpu_env, tdf, twd, tws, twt);break ;case OPC_ILVEV_df: -gen_helper_msa_ilvev_df (cpu_env, tdf, twd, tws, twt); +switch (df) { +case DF_BYTE : +gen_ilvev_b (env, wd, ws, wt); +break ; +case DF_HALF : +gen_ilvev_h (env, wd, ws, wt); +break ; +case DF_WORD : +gen_ilvev_w (env, wd, ws, wt); +break ; +case DF_DOUBLE : +gen_ilvev_d (env, wd, ws, wt); +break ; +default : +assert (0 ); + }break ;
Quoted 8 lines
Quoted 6 lines
target/mips/translate.c +0
-1case OPC_BINSR_df:gen_helper_msa_binsr_df (cpu_env, tdf, twd, tws, twt); --2.7.4
Thanks,
Aleksandar
Thanks,
Mateja
PATCH v6 3/4 target/mips: Optimize ILVL.<B|H|W|D> MSA instructions
In reply to Mateja MarjanovicFrom: Mateja Marjanovic <[email protected]>
Optimized ILVL.<B|H|W|D> instructions, using a hybrid approach. For byte data elements, use a helper with an unrolled loop (much better performance), for halfword, word and doubleword data elements use directly tcg registers and logic performed on them.
Performance measurement is done by executing the instructions a large number of times on a computer with Intel Core i7-3770 CPU @ 3.40GHz×8.
==================================================
|| instr || helper || tcg || hybrid ||
==================================================
|| ilvl.b: || 59.91 ms || 74.41 ms || 59.24 ms || <-- helper || ilvl.h: || 41.33 ms || 33.08 ms || 32.96 ms || <-- tcg || ilvl.w: || 30.99 ms || 22.87 ms || 22.81 ms || <-- tcg || ilvl.d: || 26.40 ms || 19.64 ms || 19.45 ms || <-- tcg
==================================================
--- target/mips/helper.h | 3 +- target/mips/msa_helper.c | 33 ++++++--- target/mips/translate.c | 184 ++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 210 insertions(+), 10 deletions(-)
target/mips/helper.h +2 -1
@@ -862,7 +862,6 @@ DEF_HELPER_5(msa_sld_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_splat_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_pckev_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_pckod_df, void, env, i32, i32, i32, i32) -DEF_HELPER_5(msa_ilvl_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_ilvr_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_vshf_df, void, env, i32, i32, i32, i32)DEF_HELPER_5 (msa_srar_df, void, env, i32, i32, i32, i32)
@@ -946,6 +945,8 @@ DEF_HELPER_4(msa_insert_h, void, env, i32, i32, i32) DEF_HELPER_4(msa_insert_w, void, env, i32, i32, i32) DEF_HELPER_4(msa_insert_d, void, env, i32, i32, i32) +DEF_HELPER_4(msa_ilvl_b, void, env, i32, i32, i32) + DEF_HELPER_4(msa_fclass_df, void, env, i32, i32, i32) DEF_HELPER_4(msa_ftrunc_s_df, void, env, i32, i32, i32)DEF_HELPER_4 (msa_ftrunc_u_df, void, env, i32, i32, i32)
target/mips/msa_helper.c +25 -8
@@ -1184,14 +1184,6 @@ MSA_FN_DF(pckod_df)#define MSA_DO (DF ) \ do { \ - pwx->DF[2*i] = L##DF(pwt, i); \ - pwx->DF[2*i+1] = L##DF(pws, i); \ - } while (0) -MSA_FN_DF(ilvl_df) -#undef MSA_DO - -#define MSA_DO (DF ) \ - do { \ pwx->DF[2*i] = R##DF(pwt, i); \ pwx->DF[2*i+1] = R##DF(pws, i); \ } while (0)
@@ -1232,6 +1224,31 @@ void helper_msa_splati_df(CPUMIPSState *env, uint32_t df, uint32_t wd,msa_splat_df (df, pwd, pws, n); } +void helper_msa_ilvl_b (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +wr_t *pwd = &(env->active_fpu.fpr[wd].wr); +wr_t *pws = &(env->active_fpu.fpr[ws].wr); +wr_t *pwt = &(env->active_fpu.fpr[wt].wr); + + pwd->b[0 ] = pwt->b[8 ]; + pwd->b[1 ] = pws->b[8 ]; + pwd->b[2 ] = pwt->b[9 ]; + pwd->b[3 ] = pws->b[9 ]; + pwd->b[4 ] = pwt->b[10 ]; + pwd->b[5 ] = pws->b[10 ]; + pwd->b[6 ] = pwt->b[11 ]; + pwd->b[7 ] = pws->b[11 ]; + pwd->b[8 ] = pwt->b[12 ]; + pwd->b[9 ] = pws->b[12 ]; + pwd->b[10 ] = pwt->b[13 ]; + pwd->b[11 ] = pws->b[13 ]; + pwd->b[12 ] = pwt->b[14 ]; + pwd->b[13 ] = pws->b[14 ]; + pwd->b[14 ] = pwt->b[15 ]; + pwd->b[15 ] = pws->b[15 ]; +} +void helper_msa_copy_s_b (CPUMIPSState *env,uint32_t rd,uint32_t ws,uint32_t n) {
target/mips/translate.c +183 -1
196 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH v6 3/4] target/mips: Optimize ILVL.<B|H|W|D> MSA instructions
Quoted 263 lines · Mateja Marjanovic
From: Mateja Marjanovic <[email protected]>
Optimized ILVL.<B|H|W|D> instructions, using a hybrid approach. For byte data elements, use a helper with an unrolled loop (much better performance), for halfword, word and doubleword data elements use directly tcg registers and logic performed on them.
Performance measurement is done by executing the instructions a large number of times on a computer with Intel Core i7-3770 CPU @ 3.40GHz×8.
==================================================
|| instr || helper || tcg || hybrid ||
==================================================|| ilvl.b: || 59.91 ms || 74.41 ms || 59.24 ms || <-- helper || ilvl.h: || 41.33 ms || 33.08 ms || 32.96 ms || <-- tcg || ilvl.w: || 30.99 ms || 22.87 ms || 22.81 ms || <-- tcg || ilvl.d: || 26.40 ms || 19.64 ms || 19.45 ms || <-- tcg==================================================
Signed-off-by Mateja Marjanovic <[email protected]>--- target/mips/helper.h | 3 +- target/mips/msa_helper.c | 33 ++++++--- target/mips/translate.c | 184 ++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 210 insertions(+), 10 deletions(-)target/mips/helper.h +2
-1@@ -862,7 +862,6 @@ DEF_HELPER_5(msa_sld_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_splat_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_pckev_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_pckod_df, void, env, i32, i32, i32, i32) -DEF_HELPER_5(msa_ilvl_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_ilvr_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_vshf_df, void, env, i32, i32, i32, i32)DEF_HELPER_5 (msa_srar_df, void, env, i32, i32, i32, i32)@@ -946,6 +945,8 @@ DEF_HELPER_4(msa_insert_h, void, env, i32, i32, i32) DEF_HELPER_4(msa_insert_w, void, env, i32, i32, i32) DEF_HELPER_4(msa_insert_d, void, env, i32, i32, i32) +DEF_HELPER_4(msa_ilvl_b, void, env, i32, i32, i32) + DEF_HELPER_4(msa_fclass_df, void, env, i32, i32, i32) DEF_HELPER_4(msa_ftrunc_s_df, void, env, i32, i32, i32)DEF_HELPER_4 (msa_ftrunc_u_df, void, env, i32, i32, i32)target/mips/msa_helper.c +25
-8@@ -1184,14 +1184,6 @@ MSA_FN_DF(pckod_df)#define MSA_DO (DF ) \ do { \ - pwx->DF[2*i] = L##DF(pwt, i); \ - pwx->DF[2*i+1] = L##DF(pws, i); \ - } while (0) -MSA_FN_DF(ilvl_df) -#undef MSA_DO - -#define MSA_DO (DF ) \ - do { \ pwx->DF[2*i] = R##DF(pwt, i); \ pwx->DF[2*i+1] = R##DF(pws, i); \ } while (0)@@ -1232,6 +1224,31 @@ void helper_msa_splati_df(CPUMIPSState *env, uint32_t df, uint32_t wd,msa_splat_df (df, pwd, pws, n); } +void helper_msa_ilvl_b (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +wr_t *pwd = &(env->active_fpu.fpr[wd].wr); +wr_t *pws = &(env->active_fpu.fpr[ws].wr); +wr_t *pwt = &(env->active_fpu.fpr[wt].wr); + + pwd->b[0 ] = pwt->b[8 ]; + pwd->b[1 ] = pws->b[8 ]; + pwd->b[2 ] = pwt->b[9 ]; + pwd->b[3 ] = pws->b[9 ]; + pwd->b[4 ] = pwt->b[10 ]; + pwd->b[5 ] = pws->b[10 ]; + pwd->b[6 ] = pwt->b[11 ]; + pwd->b[7 ] = pws->b[11 ]; + pwd->b[8 ] = pwt->b[12 ]; + pwd->b[9 ] = pws->b[12 ]; + pwd->b[10 ] = pwt->b[13 ]; + pwd->b[11 ] = pws->b[13 ]; + pwd->b[12 ] = pwt->b[14 ]; + pwd->b[13 ] = pws->b[14 ]; + pwd->b[14 ] = pwt->b[15 ]; + pwd->b[15 ] = pws->b[15 ]; +} +void helper_msa_copy_s_b (CPUMIPSState *env,uint32_t rd,uint32_t ws,uint32_t n) {target/mips/translate.c +154
-0@@ -28885,6 +28885,173 @@ static void gen_msa_bit(CPUMIPSState *env, DisasContext *ctx) }/* +* [MSA] ILVL.B wd, ws, wt +* +* Vector Interleave Left (byte data elements) +* +*/ +static inline void gen_ilvl_b (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +TCGv_i64 t1 =tcg_temp_new_i64 (); +TCGv_i64 t2 =tcg_temp_new_i64 (); +uint64_t mask =0x00000000000000ffULL ; + +tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 +1 ], mask); +tcg_gen_mov_i64 (t2, t1); +tcg_gen_andi_i64 (t1, msa_wr_d[ws *2 +1 ], mask); +tcg_gen_shli_i64 (t1, t1,8 ); +tcg_gen_or_i64 (t2, t2, t1); + + mask <<=8 ; +tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 +1 ], mask); +tcg_gen_shli_i64 (t1, t1,8 ); +tcg_gen_or_i64 (t2, t2, t1); +tcg_gen_andi_i64 (t1, msa_wr_d[ws *2 +1 ], mask); +tcg_gen_shli_i64 (t1, t1,16 ); +tcg_gen_or_i64 (t2, t2, t1); + + mask <<=8 ; +tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 +1 ], mask); +tcg_gen_shli_i64 (t1, t1,16 ); +tcg_gen_or_i64 (t2, t2, t1); +tcg_gen_andi_i64 (t1, msa_wr_d[ws *2 +1 ], mask); +tcg_gen_shli_i64 (t1, t1,24 ); +tcg_gen_or_i64 (t2, t2, t1); + + mask <<=8 ; +tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 +1 ], mask); +tcg_gen_shli_i64 (t1, t1,24 ); +tcg_gen_or_i64 (t2, t2, t1); +tcg_gen_andi_i64 (t1, msa_wr_d[ws *2 +1 ], mask); +tcg_gen_shli_i64 (t1, t1,32 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 ], t2, t1); + + mask <<=8 ; +tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 +1 ], mask); +tcg_gen_shri_i64 (t1, t1,32 ); +tcg_gen_mov_i64 (t2, t1); +tcg_gen_andi_i64 (t1, msa_wr_d[ws *2 +1 ], mask); +tcg_gen_shri_i64 (t1, t1,24 ); +tcg_gen_or_i64 (t2, t2, t1); + + mask <<=8 ; +tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 +1 ], mask); +tcg_gen_shri_i64 (t1, t1,24 ); +tcg_gen_or_i64 (t2, t2, t1); +tcg_gen_andi_i64 (t1, msa_wr_d[ws *2 +1 ], mask); +tcg_gen_shri_i64 (t1, t1,16 ); +tcg_gen_or_i64 (t2, t2, t1); + + mask <<=8 ; +tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 +1 ], mask); +tcg_gen_shri_i64 (t1, t1,16 ); +tcg_gen_or_i64 (t2, t2, t1); +tcg_gen_andi_i64 (t1, msa_wr_d[ws *2 +1 ], mask); +tcg_gen_shri_i64 (t1, t1,8 ); +tcg_gen_or_i64 (t2, t2, t1); + + mask <<=8 ; +tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 +1 ], mask); +tcg_gen_shri_i64 (t1, t1,8 ); +tcg_gen_or_i64 (t2, t2, t1); +tcg_gen_andi_i64 (t1, msa_wr_d[ws *2 +1 ], mask); +tcg_gen_or_i64 (msa_wr_d[wd *2 +1 ], t2, t1); + +tcg_temp_free_i64 (t1); +tcg_temp_free_i64 (t2); +} + +/* +* [MSA] ILVL.H wd, ws, wt +* +* Vector Interleave Left (halfword data elements) +* +*/ +static inline void gen_ilvl_h (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +TCGv_i64 t1 =tcg_temp_new_i64 (); +TCGv_i64 t2 =tcg_temp_new_i64 (); +uint64_t mask =0x000000000000ffffULL ; + +tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 +1 ], mask); +tcg_gen_mov_i64 (t2, t1); +tcg_gen_andi_i64 (t1, msa_wr_d[ws *2 +1 ], mask); +tcg_gen_shli_i64 (t1, t1,16 ); +tcg_gen_or_i64 (t2, t2, t1); + + mask <<=16 ; +tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 +1 ], mask); +tcg_gen_shli_i64 (t1, t1,16 ); +tcg_gen_or_i64 (t2, t2, t1); +tcg_gen_andi_i64 (t1, msa_wr_d[ws *2 +1 ], mask); +tcg_gen_shli_i64 (t1, t1,32 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 ], t2, t1); + + mask <<=16 ; +tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 +1 ], mask); +tcg_gen_shri_i64 (t1, t1,32 ); +tcg_gen_mov_i64 (t2, t1); +tcg_gen_andi_i64 (t1, msa_wr_d[ws *2 +1 ], mask); +tcg_gen_shri_i64 (t1, t1,16 ); +tcg_gen_or_i64 (t2, t2, t1); + + mask <<=16 ; +tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 +1 ], mask); +tcg_gen_shri_i64 (t1, t1,16 ); +tcg_gen_or_i64 (t2, t2, t1); +tcg_gen_andi_i64 (t1, msa_wr_d[ws *2 +1 ], mask); +tcg_gen_or_i64 (msa_wr_d[wd *2 +1 ], t2, t1); + +tcg_temp_free_i64 (t1); +tcg_temp_free_i64 (t2); +} + +/* +* [MSA] ILVL.W wd, ws, wt +* +* Vector Interleave Left (word data elements) +* +*/ +static inline void gen_ilvl_w (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +TCGv_i64 t1 =tcg_temp_new_i64 (); +TCGv_i64 t2 =tcg_temp_new_i64 (); +uint64_t mask =0x00000000ffffffffULL ; + +tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 +1 ], mask); +tcg_gen_mov_i64 (t2, t1); +tcg_gen_andi_i64 (t1, msa_wr_d[ws *2 +1 ], mask); +tcg_gen_shli_i64 (t1, t1,32 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 ], t2, t1); + + mask <<=32 ; +tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 +1 ], mask); +tcg_gen_shri_i64 (t1, t1,32 ); +tcg_gen_mov_i64 (t2, t1); +tcg_gen_andi_i64 (t1, msa_wr_d[ws *2 +1 ], mask); +tcg_gen_or_i64 (msa_wr_d[wd *2 +1 ], t2, t1); + +tcg_temp_free_i64 (t1); +tcg_temp_free_i64 (t2); +} + +/*
target/mips/translate.c static void gen_msa_bit(CPUMIPSState *env, DisasContext *ctx) · line 29051
Quoted 10 lines
target/mips/translate.c +10
-0+* [MSA] ILVL.D wd, ws, wt +* +* Vector Interleave Left (doubleword data elements) +* +*/ +static inline void gen_ilvl_d (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +tcg_gen_mov_i64 (msa_wr_d[wd *2 +1 ], msa_wr_d[ws *2 +1 ]); +tcg_gen_mov_i64 (msa_wr_d[wd *2 ], msa_wr_d[wt *2 +1 ]);
This code introduces the bug for the case wd == wt. You keep repeating the same mistake on and on and on.
Please see also my comments for ILVR.D.
Thanks,
Aleksandar
Quoted 34 lines
target/mips/translate.c +19
-2+} + +/* * [MSA] ILVOD.B wd, ws, wt * * Vector Interleave Odd (byte data elements) @@ -29177,7 +29344,22 @@ static void gen_msa_3r(CPUMIPSState *env, DisasContext *ctx)gen_helper_msa_div_s_df (cpu_env, tdf, twd, tws, twt);break ;case OPC_ILVL_df: -gen_helper_msa_ilvl_df (cpu_env, tdf, twd, tws, twt); +switch (df) { +case DF_BYTE : +gen_helper_msa_ilvl_b (cpu_env, twd, tws, twt); +break ; +case DF_HALF : +gen_ilvl_h (env, wd, ws, wt); +break ; +case DF_WORD : +gen_ilvl_w (env, wd, ws, wt); +break ; +case DF_DOUBLE : +gen_ilvl_d (env, wd, ws, wt); +break ; +default : +assert (0 ); + }break ;case OPC_BNEG_df:gen_helper_msa_bneg_df (cpu_env, tdf, twd, tws, twt); --2.7.4
PATCH v6 4/4 target/mips: Optimize ILVR.<B|H|W|D> MSA instructions
In reply to Mateja MarjanovicFrom: Mateja Marjanovic <[email protected]>
Optimized ILVR.<B|H|W|D> instructions, using a hybrid approach. For byte data elements, use a helper with an unrolled loop (much better performance), for halfword, word and doubleword data elements use directly tcg registers and logic performed on them.
Performance measurement is done by executing the instructions a large number of times on a computer with Intel Core i7-3770 CPU @ 3.40GHz×8.
===================================================
|| instr || helper || tcg || hybrid ||
===================================================
|| ilvr.b: || 62.87 ms || 74.76 ms || 61.52 ms || <-- helper || ilvr.h: || 44.11 ms || 33.00 ms || 33.55 ms || <-- tcg || ilvr.w: || 34.97 ms || 23.06 ms || 22.67 ms || <-- tcg || ilvr.d: || 27.33 ms || 19.87 ms || 20.02 ms || <-- tcg
===================================================
--- target/mips/helper.h | 2 +- target/mips/msa_helper.c | 33 +++++++++++---- target/mips/translate.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 132 insertions(+), 10 deletions(-)
target/mips/helper.h +1 -1
@@ -862,7 +862,6 @@ DEF_HELPER_5(msa_sld_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_splat_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_pckev_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_pckod_df, void, env, i32, i32, i32, i32) -DEF_HELPER_5(msa_ilvr_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_vshf_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_srar_df, void, env, i32, i32, i32, i32)DEF_HELPER_5 (msa_srlr_df, void, env, i32, i32, i32, i32)
@@ -946,6 +945,7 @@ DEF_HELPER_4(msa_insert_w, void, env, i32, i32, i32) DEF_HELPER_4(msa_insert_d, void, env, i32, i32, i32) DEF_HELPER_4(msa_ilvl_b, void, env, i32, i32, i32) +DEF_HELPER_4(msa_ilvr_b, void, env, i32, i32, i32) DEF_HELPER_4(msa_fclass_df, void, env, i32, i32, i32)DEF_HELPER_4 (msa_ftrunc_s_df, void, env, i32, i32, i32)
target/mips/msa_helper.c +25 -8
@@ -1181,14 +1181,6 @@ MSA_FN_DF(pckev_df) }while (0 ) MSA_FN_DF(pckod_df)#undef MSA_DO - -#define MSA_DO (DF ) \ - do { \ - pwx->DF[2*i] = R##DF(pwt, i); \ - pwx->DF[2*i+1] = R##DF(pws, i); \ - } while (0) -MSA_FN_DF(ilvr_df) -#undef MSA_DO#undef MSA_LOOP_COND#define MSA_LOOP_COND (DF ) \
@@ -1249,6 +1241,31 @@ void helper_msa_ilvl_b(CPUMIPSState *env, uint32_t wd, pwd->b[15 ] = pws->b[15 ]; } +void helper_msa_ilvr_b (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +wr_t *pwd = &(env->active_fpu.fpr[wd].wr); +wr_t *pws = &(env->active_fpu.fpr[ws].wr); +wr_t *pwt = &(env->active_fpu.fpr[wt].wr); + + pwd->b[15 ] = pws->b[7 ]; + pwd->b[14 ] = pwt->b[7 ]; + pwd->b[13 ] = pws->b[6 ]; + pwd->b[12 ] = pwt->b[6 ]; + pwd->b[11 ] = pws->b[5 ]; + pwd->b[10 ] = pwt->b[5 ]; + pwd->b[9 ] = pws->b[4 ]; + pwd->b[8 ] = pwt->b[4 ]; + pwd->b[7 ] = pws->b[3 ]; + pwd->b[6 ] = pwt->b[3 ]; + pwd->b[5 ] = pws->b[2 ]; + pwd->b[4 ] = pwt->b[2 ]; + pwd->b[3 ] = pws->b[1 ]; + pwd->b[2 ] = pwt->b[1 ]; + pwd->b[1 ] = pws->b[0 ]; + pwd->b[0 ] = pwt->b[0 ]; +} +void helper_msa_copy_s_b (CPUMIPSState *env,uint32_t rd,uint32_t ws,uint32_t n) {
target/mips/translate.c +106 -1
119 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH v6 4/4] target/mips: Optimize ILVR.<B|H|W|D> MSA instructions
Quoted 4 lines · Mateja Marjanovic
From: Mateja Marjanovic <[email protected]>
Optimized ILVR.<B|H|W|D> instructions, using a hybrid
Optimized -> Optimize
Quoted 2 lines
approach. For byte data elements, use a helper with an unrolled loop (much better performance), for halfword,
(much better performance) -> (having much better performance than direct tcg translation)
Quoted 7 lines
word and doubleword data elements use directly tcg registers and logic performed on them.
Performance measurement is done by executing the instructions a large number of times on a computer with Intel Core i7-3770 CPU @ 3.40GHz×8.
Quoted 9 lines
===================================================
|| instr || helper || tcg || hybrid ||
===================================================|| ilvr.b: || 62.87 ms || 74.76 ms || 61.52 ms || <-- helper || ilvr.h: || 44.11 ms || 33.00 ms || 33.55 ms || <-- tcg || ilvr.w: || 34.97 ms || 23.06 ms || 22.67 ms || <-- tcg || ilvr.d: || 27.33 ms || 19.87 ms || 20.02 ms || <-- tcg===================================================
instr -> instruction
|| 61.52 ms || <-- helper -> || 61.52 ms (helper) ||
and similar for other three raws.
Quoted 47 lines
Signed-off-by Mateja Marjanovic <[email protected]>--- target/mips/helper.h | 2 +- target/mips/msa_helper.c | 33 +++++++++++---- target/mips/translate.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 132 insertions(+), 10 deletions(-)target/mips/helper.h +1
-1@@ -862,7 +862,6 @@ DEF_HELPER_5(msa_sld_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_splat_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_pckev_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_pckod_df, void, env, i32, i32, i32, i32) -DEF_HELPER_5(msa_ilvr_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_vshf_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_srar_df, void, env, i32, i32, i32, i32)DEF_HELPER_5 (msa_srlr_df, void, env, i32, i32, i32, i32)@@ -946,6 +945,7 @@ DEF_HELPER_4(msa_insert_w, void, env, i32, i32, i32) DEF_HELPER_4(msa_insert_d, void, env, i32, i32, i32) DEF_HELPER_4(msa_ilvl_b, void, env, i32, i32, i32) +DEF_HELPER_4(msa_ilvr_b, void, env, i32, i32, i32) DEF_HELPER_4(msa_fclass_df, void, env, i32, i32, i32)DEF_HELPER_4 (msa_ftrunc_s_df, void, env, i32, i32, i32)target/mips/msa_helper.c +0
-8@@ -1181,14 +1181,6 @@ MSA_FN_DF(pckev_df) }while (0 ) MSA_FN_DF(pckod_df)#undef MSA_DO - -#define MSA_DO (DF ) \ - do { \ - pwx->DF[2*i] = R##DF(pwt, i); \ - pwx->DF[2*i+1] = R##DF(pws, i); \ - } while (0) -MSA_FN_DF(ilvr_df) -#undef MSA_DO#undef MSA_LOOP_COND#define MSA_LOOP_COND (DF ) \
target/mips/msa_helper.c void helper_msa_ilvl_b(CPUMIPSState *env, uint32_t wd, · line 1250
Quoted 10 lines
target/mips/msa_helper.c +7
-0@@ -1249,6 +1241,31 @@ void helper_msa_ilvl_b(CPUMIPSState *env, uint32_t wd, pwd->b[15 ] = pws->b[15 ]; } +void helper_msa_ilvr_b (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +wr_t *pwd = &(env->active_fpu.fpr[wd].wr); +wr_t *pws = &(env->active_fpu.fpr[ws].wr); +wr_t *pwt = &(env->active_fpu.fpr[wt].wr); +
Why do we use here env->active_fpu.fpr[wd].wr, while for other instructions in this patch, we access msa_wr_d<b|h|w|d[] directly?
Quoted 76 lines
target/mips/msa_helper.c +18
-0+ pwd->b[15 ] = pws->b[7 ]; + pwd->b[14 ] = pwt->b[7 ]; + pwd->b[13 ] = pws->b[6 ]; + pwd->b[12 ] = pwt->b[6 ]; + pwd->b[11 ] = pws->b[5 ]; + pwd->b[10 ] = pwt->b[5 ]; + pwd->b[9 ] = pws->b[4 ]; + pwd->b[8 ] = pwt->b[4 ]; + pwd->b[7 ] = pws->b[3 ]; + pwd->b[6 ] = pwt->b[3 ]; + pwd->b[5 ] = pws->b[2 ]; + pwd->b[4 ] = pwt->b[2 ]; + pwd->b[3 ] = pws->b[1 ]; + pwd->b[2 ] = pwt->b[1 ]; + pwd->b[1 ] = pws->b[0 ]; + pwd->b[0 ] = pwt->b[0 ]; +} +void helper_msa_copy_s_b (CPUMIPSState *env,uint32_t rd,uint32_t ws,uint32_t n) {target/mips/translate.c +47
-0@@ -28885,6 +28885,96 @@ static void gen_msa_bit(CPUMIPSState *env, DisasContext *ctx) }/* +* [MSA] ILVR.H wd, ws, wt +* +* Vector Interleave Right (halfword data elements) +* +*/ +static inline void gen_ilvr_h (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +TCGv_i64 t1 =tcg_temp_new_i64 (); +TCGv_i64 t2 =tcg_temp_new_i64 (); +uint64_t mask =0x000000000000ffffULL ; + +tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 ], mask); +tcg_gen_mov_i64 (t2, t1); +tcg_gen_andi_i64 (t1, msa_wr_d[ws *2 ], mask); +tcg_gen_shli_i64 (t1, t1,16 ); +tcg_gen_or_i64 (t2, t2, t1); + + mask <<=16 ; +tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 ], mask); +tcg_gen_shli_i64 (t1, t1,16 ); +tcg_gen_or_i64 (t2, t2, t1); +tcg_gen_andi_i64 (t1, msa_wr_d[ws *2 ], mask); +tcg_gen_shli_i64 (t1, t1,32 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 ], t2, t1); + + mask <<=16 ; +tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 ], mask); +tcg_gen_shri_i64 (t1, t1,32 ); +tcg_gen_mov_i64 (t2, t1); +tcg_gen_andi_i64 (t1, msa_wr_d[ws *2 ], mask); +tcg_gen_shri_i64 (t1, t1,16 ); +tcg_gen_or_i64 (t2, t2, t1); + + mask <<=16 ; +tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 ], mask); +tcg_gen_shri_i64 (t1, t1,16 ); +tcg_gen_or_i64 (t2, t2, t1); +tcg_gen_andi_i64 (t1, msa_wr_d[ws *2 ], mask); +tcg_gen_or_i64 (msa_wr_d[wd *2 +1 ], t2, t1); + +tcg_temp_free_i64 (t1); +tcg_temp_free_i64 (t2); +} + +/* +* [MSA] ILVR.W wd, ws, wt
target/mips/translate.c static void gen_msa_bit(CPUMIPSState *env, DisasContext *ctx) · line 28944
Quoted 10 lines
target/mips/translate.c +10
-0+* +* Vector Interleave Right (word data elements) +* +*/ +static inline void gen_ilvr_w (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +TCGv_i64 t1 =tcg_temp_new_i64 (); +TCGv_i64 t2 =tcg_temp_new_i64 (); +uint64_t mask =0x00000000ffffffffULL ;
Use tcg_const_i64(). The same for the previous function.
target/mips/translate.c static void gen_msa_bit(CPUMIPSState *env, DisasContext *ctx) · line 28952
Quoted 8 lines
target/mips/translate.c +8
-0+ +tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 ], mask); +tcg_gen_mov_i64 (t2, t1); +tcg_gen_andi_i64 (t1, msa_wr_d[ws *2 ], mask); +tcg_gen_shli_i64 (t1, t1,32 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 ], t2, t1); + + mask <<=32 ;
Just assign the constant value to the mask, no need for shift operation. The same applies for other similar cases in this patch.
Quoted 13 lines
target/mips/translate.c +13
-0+tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 ], mask); +tcg_gen_shri_i64 (t1, t1,32 ); +tcg_gen_mov_i64 (t2, t1); +tcg_gen_andi_i64 (t1, msa_wr_d[ws *2 ], mask); +tcg_gen_or_i64 (msa_wr_d[wd *2 +1 ], t2, t1); + +tcg_temp_free_i64 (t1); +tcg_temp_free_i64 (t2); +} + +/* +* [MSA] ILVR.D wd, ws, wt +*
target/mips/translate.c static void gen_msa_bit(CPUMIPSState *env, DisasContext *ctx) · line 28975
Quoted 10 lines
target/mips/translate.c +10
-0+* Vector Interleave Right (doubleword data elements) +* +*/ +static inline void gen_ilvr_d (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +tcg_gen_mov_i64 (msa_wr_d[wd *2 +1 ], msa_wr_d[ws *2 ]); +tcg_gen_mov_i64 (msa_wr_d[wd *2 ], msa_wr_d[wt *2 ]); +} +
This function seems to be identical to the gen_ilvev_d(). Please, if that is the case, in this patch rename gen_ilvev_d() to gen_ilvev_ilvr_d(), and use it both for hanlding ILVEV.D and ILVR.D.
Quoted 30 lines
target/mips/translate.c +18
-2+ +/* * [MSA] ILVL.B wd, ws, wt * * Vector Interleave Left (byte data elements) @@ -29380,7 +29470,22 @@ static void gen_msa_3r(CPUMIPSState *env, DisasContext *ctx)gen_helper_msa_div_u_df (cpu_env, tdf, twd, tws, twt);break ;case OPC_ILVR_df: -gen_helper_msa_ilvr_df (cpu_env, tdf, twd, tws, twt); +switch (df) { +case DF_BYTE : +gen_helper_msa_ilvr_b (cpu_env, twd, tws, twt); +break ; +case DF_HALF : +gen_ilvr_h (env, wd, ws, wt); +break ; +case DF_WORD : +gen_ilvr_w (env, wd, ws, wt); +break ; +case DF_DOUBLE : +gen_ilvr_d (env, wd, ws, wt); +break ; +default : +assert (0 ); + }break ;case OPC_BINSL_df:gen_helper_msa_binsl_df (cpu_env, tdf, twd, tws, twt); --
Quoted 3 lines
2.7.4
Thanks,
Aleksandar
Re: [Qemu-devel] [PATCH v6 4/4] target/mips: Optimize ILVR.<B|H|W|D> MSA instructions
Quoted 28 lines · Aleksandar Markovic
Quoted 3 lines · Mateja Marjanovic
From: Mateja Marjanovic <[email protected]>
Optimized ILVR.<B|H|W|D> instructions, using a hybrid
Optimized -> Optimize
Quoted 2 lines
approach. For byte data elements, use a helper with an unrolled loop (much better performance), for halfword,
(much better performance) -> (having much better performance than direct tcg translation)
Quoted 7 lines
word and doubleword data elements use directly tcg registers and logic performed on them.
Performance measurement is done by executing the instructions a large number of times on a computer with Intel Core i7-3770 CPU @ 3.40GHz×8.
Quoted 9 lines
===================================================
|| instr || helper || tcg || hybrid ||
===================================================|| ilvr.b: || 62.87 ms || 74.76 ms || 61.52 ms || <-- helper || ilvr.h: || 44.11 ms || 33.00 ms || 33.55 ms || <-- tcg || ilvr.w: || 34.97 ms || 23.06 ms || 22.67 ms || <-- tcg || ilvr.d: || 27.33 ms || 19.87 ms || 20.02 ms || <-- tcg===================================================
Quoted 5 lines
instr -> instruction
|| 61.52 ms || <-- helper -> || 61.52 ms (helper) ||
and similar for other three raws.
I will change those three in v7.
Quoted 51 lines
Quoted 51 lines
Signed-off-by Mateja Marjanovic <[email protected]>--- target/mips/helper.h | 2 +- target/mips/msa_helper.c | 33 +++++++++++---- target/mips/translate.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 132 insertions(+), 10 deletions(-)target/mips/helper.h +1
-1@@ -862,7 +862,6 @@ DEF_HELPER_5(msa_sld_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_splat_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_pckev_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_pckod_df, void, env, i32, i32, i32, i32) -DEF_HELPER_5(msa_ilvr_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_vshf_df, void, env, i32, i32, i32, i32) DEF_HELPER_5(msa_srar_df, void, env, i32, i32, i32, i32)DEF_HELPER_5 (msa_srlr_df, void, env, i32, i32, i32, i32)@@ -946,6 +945,7 @@ DEF_HELPER_4(msa_insert_w, void, env, i32, i32, i32) DEF_HELPER_4(msa_insert_d, void, env, i32, i32, i32) DEF_HELPER_4(msa_ilvl_b, void, env, i32, i32, i32) +DEF_HELPER_4(msa_ilvr_b, void, env, i32, i32, i32) DEF_HELPER_4(msa_fclass_df, void, env, i32, i32, i32)DEF_HELPER_4 (msa_ftrunc_s_df, void, env, i32, i32, i32)target/mips/msa_helper.c +0
-8@@ -1181,14 +1181,6 @@ MSA_FN_DF(pckev_df) }while (0 ) MSA_FN_DF(pckod_df)#undef MSA_DO - -#define MSA_DO (DF ) \ - do { \ - pwx->DF[2*i] = R##DF(pwt, i); \ - pwx->DF[2*i+1] = R##DF(pws, i); \ - } while (0) -MSA_FN_DF(ilvr_df) -#undef MSA_DO#undef MSA_LOOP_COND#define MSA_LOOP_COND (DF ) \@@ -1249,6 +1241,31 @@ void helper_msa_ilvl_b(CPUMIPSState *env, uint32_t wd, pwd->b[15 ] = pws->b[15 ]; }
Quoted 9 lines
target/mips/msa_helper.c void helper_msa_ilvl_b(CPUMIPSState *env, uint32_t wd, · line 1250
Quoted 7 lines
target/mips/msa_helper.c +7
-0+void helper_msa_ilvr_b (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +wr_t *pwd = &(env->active_fpu.fpr[wd].wr); +wr_t *pws = &(env->active_fpu.fpr[ws].wr); +wr_t *pwt = &(env->active_fpu.fpr[wt].wr); +Why do we use here env->active_fpu.fpr[wd].wr, while for other instructions in this patch, we access msa_wr_d<b|h|w|d[] directly?
With a pointer to wr_t we have an array of bytes, halfwords, words or doublewords and can read from them and change them like an ordinary array. In other cases we use a variable that is TCGv_i64 and would have to use tcg_gen functions to modify the value of the register. Before my changes in ilvr instruction helpers env->active_fpu.fpr[wd].wr was used, so I just copy-pasted that.
Quoted 80 lines
Quoted 80 lines
target/mips/msa_helper.c +18
-0+ pwd->b[15 ] = pws->b[7 ]; + pwd->b[14 ] = pwt->b[7 ]; + pwd->b[13 ] = pws->b[6 ]; + pwd->b[12 ] = pwt->b[6 ]; + pwd->b[11 ] = pws->b[5 ]; + pwd->b[10 ] = pwt->b[5 ]; + pwd->b[9 ] = pws->b[4 ]; + pwd->b[8 ] = pwt->b[4 ]; + pwd->b[7 ] = pws->b[3 ]; + pwd->b[6 ] = pwt->b[3 ]; + pwd->b[5 ] = pws->b[2 ]; + pwd->b[4 ] = pwt->b[2 ]; + pwd->b[3 ] = pws->b[1 ]; + pwd->b[2 ] = pwt->b[1 ]; + pwd->b[1 ] = pws->b[0 ]; + pwd->b[0 ] = pwt->b[0 ]; +} +void helper_msa_copy_s_b (CPUMIPSState *env,uint32_t rd,uint32_t ws,uint32_t n) {target/mips/translate.c +50
-0@@ -28885,6 +28885,96 @@ static void gen_msa_bit(CPUMIPSState *env, DisasContext *ctx) }/* +* [MSA] ILVR.H wd, ws, wt +* +* Vector Interleave Right (halfword data elements) +* +*/ +static inline void gen_ilvr_h (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +TCGv_i64 t1 =tcg_temp_new_i64 (); +TCGv_i64 t2 =tcg_temp_new_i64 (); +uint64_t mask =0x000000000000ffffULL ; + +tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 ], mask); +tcg_gen_mov_i64 (t2, t1); +tcg_gen_andi_i64 (t1, msa_wr_d[ws *2 ], mask); +tcg_gen_shli_i64 (t1, t1,16 ); +tcg_gen_or_i64 (t2, t2, t1); + + mask <<=16 ; +tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 ], mask); +tcg_gen_shli_i64 (t1, t1,16 ); +tcg_gen_or_i64 (t2, t2, t1); +tcg_gen_andi_i64 (t1, msa_wr_d[ws *2 ], mask); +tcg_gen_shli_i64 (t1, t1,32 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 ], t2, t1); + + mask <<=16 ; +tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 ], mask); +tcg_gen_shri_i64 (t1, t1,32 ); +tcg_gen_mov_i64 (t2, t1); +tcg_gen_andi_i64 (t1, msa_wr_d[ws *2 ], mask); +tcg_gen_shri_i64 (t1, t1,16 ); +tcg_gen_or_i64 (t2, t2, t1); + + mask <<=16 ; +tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 ], mask); +tcg_gen_shri_i64 (t1, t1,16 ); +tcg_gen_or_i64 (t2, t2, t1); +tcg_gen_andi_i64 (t1, msa_wr_d[ws *2 ], mask); +tcg_gen_or_i64 (msa_wr_d[wd *2 +1 ], t2, t1); + +tcg_temp_free_i64 (t1); +tcg_temp_free_i64 (t2); +} + +/* +* [MSA] ILVR.W wd, ws, wt +* +* Vector Interleave Right (word data elements) +*
Quoted 8 lines
target/mips/translate.c static void gen_msa_bit(CPUMIPSState *env, DisasContext *ctx) · line 28944
Quoted 7 lines
target/mips/translate.c +7
-0+*/ +static inline void gen_ilvr_w (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +TCGv_i64 t1 =tcg_temp_new_i64 (); +TCGv_i64 t2 =tcg_temp_new_i64 (); +uint64_t mask =0x00000000ffffffffULL ;Use
tcg_const_i64(). The same for the previous function.
Will do in v7.
Quoted 11 lines
target/mips/translate.c static void gen_msa_bit(CPUMIPSState *env, DisasContext *ctx) · line 28952
Quoted 9 lines
target/mips/translate.c +8
-0+ +tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 ], mask); +tcg_gen_mov_i64 (t2, t1); +tcg_gen_andi_i64 (t1, msa_wr_d[ws *2 ], mask); +tcg_gen_shli_i64 (t1, t1,32 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 ], t2, t1); + + mask <<=32 ;Just assign the constant value to the mask, no need for shift operation. The same applies for other similar cases in this patch.
I was not sure which would have better performance, so I assumed this with shifting, but I will add with assigning a constant to a register, and test the performance.
Quoted 18 lines
Quoted 18 lines
target/mips/translate.c +18
-0+tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 ], mask); +tcg_gen_shri_i64 (t1, t1,32 ); +tcg_gen_mov_i64 (t2, t1); +tcg_gen_andi_i64 (t1, msa_wr_d[ws *2 ], mask); +tcg_gen_or_i64 (msa_wr_d[wd *2 +1 ], t2, t1); + +tcg_temp_free_i64 (t1); +tcg_temp_free_i64 (t2); +} + +/* +* [MSA] ILVR.D wd, ws, wt +* +* Vector Interleave Right (doubleword data elements) +* +*/ +static inline void gen_ilvr_d (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt)
Quoted 8 lines
target/mips/translate.c static void gen_msa_bit(CPUMIPSState *env, DisasContext *ctx) · line 28975
Quoted 5 lines
target/mips/translate.c +5
-0+{ +tcg_gen_mov_i64 (msa_wr_d[wd *2 +1 ], msa_wr_d[ws *2 ]); +tcg_gen_mov_i64 (msa_wr_d[wd *2 ], msa_wr_d[wt *2 ]); +} +This function seems to be identical to the
gen_ilvev_d(). Please, if that is the case, in this patch renamegen_ilvev_d()togen_ilvev_ilvr_d(), and use it both for hanlding ILVEV.D and ILVR.D.
I didn't notice that. I will check, and if you are right, I will do that in v7.
Quoted 27 lines
Quoted 27 lines
target/mips/translate.c +18
-1+ +/* * [MSA] ILVL.B wd, ws, wt * * Vector Interleave Left (byte data elements) @@ -29380,7 +29470,22 @@ static void gen_msa_3r(CPUMIPSState *env, DisasContext *ctx)gen_helper_msa_div_u_df (cpu_env, tdf, twd, tws, twt);break ;case OPC_ILVR_df: -gen_helper_msa_ilvr_df (cpu_env, tdf, twd, tws, twt); +switch (df) { +case DF_BYTE : +gen_helper_msa_ilvr_b (cpu_env, twd, tws, twt); +break ; +case DF_HALF : +gen_ilvr_h (env, wd, ws, wt); +break ; +case DF_WORD : +gen_ilvr_w (env, wd, ws, wt); +break ; +case DF_DOUBLE : +gen_ilvr_d (env, wd, ws, wt); +break ; +default : +assert (0 ); + }break ;
Quoted 8 lines
Quoted 6 lines
target/mips/translate.c +0
-1case OPC_BINSL_df:gen_helper_msa_binsl_df (cpu_env, tdf, twd, tws, twt); --2.7.4
Thanks,
Aleksandar
Thanks,
Mateja
Re: [Qemu-devel] [PATCH v6 4/4] target/mips: Optimize ILVR.<B|H|W|D> MSA instructions
Quoted 11 lines
From: Mateja Marjanovic <[email protected]>
Quoted 10 lines
target/mips/msa_helper.c void helper_msa_ilvl_b(CPUMIPSState *env, uint32_t wd, · line 1250
Quoted 8 lines
target/mips/msa_helper.c +7
-0+void helper_msa_ilvr_b (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +wr_t *pwd = &(env->active_fpu.fpr[wd].wr); +wr_t *pws = &(env->active_fpu.fpr[ws].wr); +wr_t *pwt = &(env->active_fpu.fpr[wt].wr); +Why do we use here env->active_fpu.fpr[wd].wr, while for other instructions in this patch, we access msa_wr_d<b|h|w|d[] directly?
Quoted 10 lines
With a pointer to
wr_twe have an array of bytes, halfwords, words or doublewords
and can read from them and change them like an ordinary array. In other cases
we use a variable that isTCGv_i64and would have to usetcg_genfunctions to
modify the value of the register. Before my changes in ilvr instruction helpers
env->active_fpu.fpr[wd].wr was used, so I just copy-pasted that.
Your answer touches just surface, and doesn't fully answer my question. I would like you to show deeper understanding of the code you are working with. You can't just copy/paste without thinking.
Why do majority of MSA helpers use env->active_fpu.fpr[<index>].wr, while your code mostly reference the MSA register directly? Is this the same thing? If yes, why all MSA code doesn't use registers directly, which would certainly be simpler than referencing active_fpu? What is the role of "active_fpu"? Can it be changed? Can you analyze the underlying reasons for referencing "active_fpu", and can you claim that it is safe to circumvent it and reference the MSA registers directly?
Thanks,
Aleksandar
Re: [Qemu-devel] [PATCH v6 4/4] target/mips: Optimize ILVR.<B|H|W|D> MSA instructions
Quoted 24 lines · Aleksandar Markovic
Quoted 10 lines
From: Mateja Marjanovic <[email protected]>
Quoted 9 lines
target/mips/msa_helper.c void helper_msa_ilvl_b(CPUMIPSState *env, uint32_t wd, · line 1250
Quoted 7 lines
target/mips/msa_helper.c +7
-0+void helper_msa_ilvr_b (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +wr_t *pwd = &(env->active_fpu.fpr[wd].wr); +wr_t *pws = &(env->active_fpu.fpr[ws].wr); +wr_t *pwt = &(env->active_fpu.fpr[wt].wr); +Why do we use here env->active_fpu.fpr[wd].wr, while for other instructions in this patch, we access msa_wr_d<b|h|w|d[] directly?
Quoted 10 lines
With a pointer to
wr_twe have an array of bytes, halfwords, words or doublewords
and can read from them and change them like an ordinary array. In other cases
we use a variable that isTCGv_i64and would have to usetcg_genfunctions to
modify the value of the register. Before my changes in ilvr instruction helpers
env->active_fpu.fpr[wd].wr was used, so I just copy-pasted that.Your answer touches just surface, and doesn't fully answer my question. I would like you to show deeper understanding of the code you are working with. You can't just copy/paste without thinking.
Quoted 7 lines
Why do majority of MSA helpers use env->active_fpu.fpr[<index>].wr, while your code mostly reference the MSA register directly? Is this the same thing? If yes, why all MSA code doesn't use registers directly, which would certainly be simpler than referencing
active_fpu? What is the role of "active_fpu"? Can it be changed? Can you analyze the underlying reasons for referencing "active_fpu", and can you claim that it is safe to circumvent it and reference the MSA registers directly?
I will look into that, and try to analyze it and understand it. Thanks,
Mateja
Quoted 2 lines
Thanks,
Aleksandar