target/mips: Optimize MSA <ILVEV|ILVOD>.<B|H|W|D> instructions
v5 cover target/mips: Optimize MSA <ILVEV|ILVOD>.<B|H|W|D> instructions
From: Mateja Marjanovic <[email protected]>
Optimize MSA instructions ILVEV.<B|H|W|D> and ILVOD.<B|H|W|D>, using directly tcg registers and performing logic on them insted of using helpers.
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 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 cover letter.
Mateja Marjanovic (2):
target/mips: Optimize ILVOD.<B|H|W|D> MSA instructions target/mips: Optimize ILVEV.<B|H|W|D> MSA instructions
target/mips/helper.h | 2 - target/mips/msa_helper.c | 16 ---- target/mips/translate.c | 212 ++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 210 insertions(+), 20 deletions(-)
Signature · 1 line
2.7.4
PATCH v5 1/2 target/mips: Optimize ILVOD.<B|H|W|D> MSA instructions
From: Mateja Marjanovic <[email protected]>
Optimize set of MSA instructions ILVOD, using directly tcg registers and performing logic on them instead of using helpers.
instr || before || after
======================================
ilvod.b || 117.50 ms || 24.99 ms ilvod.h || 93.16 ms || 24.27 ms ilvod.w || 119.90 ms || 24.81 ms ilvod.d || 43.01 ms || 20.69 ms
--- target/mips/helper.h | 1 - target/mips/msa_helper.c | 7 ---- target/mips/translate.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 106 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 +106 -1
119 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH v5 1/2] target/mips: Optimize ILVOD.<B|H|W|D> MSA instructions
target/mips/translate.c static void gen_msa_bit(CPUMIPSState *env, DisasContext *ctx) · line 28954
Quoted 8 lines · Mateja Marjanovic
target/mips/translate.c +8
-0+static inline void gen_ilvod_w (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +TCGv_i64 t1 =tcg_temp_new_i64 (); +const uint64_t mask =0xffffffff00000000ULL ; + +tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 ], mask); +tcg_gen_shri_i64 (t1, t1,32 );
The andi is useless. The bits that it discards are also discarded by the shift.
r~
PATCH v5 2/2 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, 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.
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
The solution with deposit is suggested by Richard Henderson.
--- target/mips/helper.h | 1 - target/mips/msa_helper.c | 9 ---- target/mips/translate.c | 105 ++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 104 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 +104 -1
117 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH v5 2/2] target/mips: Optimize ILVEV.<B|H|W|D> MSA instructions
Hi Mateja,
Quoted 5 lines · Mateja Marjanovic
From: Mateja Marjanovic <[email protected]>
Optimize set of MSA instructions ILVEV, using directly tcg registers and performing logic on them instead of using helpers.
Maybe you can still let this previous comment (if still valid):
Performance measurement is done by executing the instructions large number of times on a computer with Intel Core i7-3770 CPU @ 3.40GHz×8.
Quoted 6 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.
You are describing the "no-deposit" which refers to a previous series but won't be accessible in the git repository.
I think this table is useful in the cover of this series, and in the commit message you should use || before || after || and drop the "no-deposit" case.
Quoted 10 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 ilvev.w || 117.86 ms || 23.83 ms || 22.17 ms ilvev.d || 45.49 ms || 19.74 ms || 19.71 msThe solution with deposit is suggested by Richard Henderson.
The gitdm parsable form is:
Quoted 55 lines
Signed-off-by Mateja Marjanovic <[email protected]>--- target/mips/helper.h | 1 - target/mips/msa_helper.c | 9 ---- target/mips/translate.c | 105 ++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 104 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 +8
-0@@ -28974,6 +28974,94 @@ 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)
target/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd, · line 28994
Quoted 10 lines
target/mips/translate.c +10
-0+{ +TCGv_i64 t1 =tcg_temp_new_i64 (); +TCGv_i64 t2 =tcg_temp_new_i64 (); +const uint64_t mask =0x00ff00ff00ff00ffULL ; + +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,8 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 ], t1, t2); +
Richard, is it cheaper to use another register to keep the constant mask (here reused 4x)?
Such:
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);target/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd, · line 28996
Quoted 2 lines
target/mips/translate.c +2
-0+tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 +1 ], mask); +tcg_gen_andi_i64 (t2, msa_wr_d[ws *2 +1 ], mask);
Here use tcg_gen_and_i64() too.
target/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd, · line 28999
Quoted 3 lines
target/mips/translate.c +3
-0+tcg_gen_shli_i64 (t2, t2,8 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 +1 ], t1, t2); +
tcg_temp_free_i64(mask);
target/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd, · line 29001
Quoted 2 lines
target/mips/translate.c +2
-0+tcg_temp_free_i64 (t1); +tcg_temp_free_i64 (t2);
Mateja: Can you test for perf easily?
Quoted 17 lines
target/mips/translate.c +17
-0+} + +/* +* [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 (); +const uint64_t mask =0x0000ffff0000ffffULL ; + +tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 ], mask); +tcg_gen_andi_i64 (t2, msa_wr_d[ws *2 ], mask);
target/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd, · line 29028
Quoted 10 lines
target/mips/translate.c +10
-0+tcg_gen_shli_i64 (t2, t2,16 ); +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,16 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 +1 ], t1, t2); + +tcg_temp_free_i64 (t1); +tcg_temp_free_i64 (t2);
Very similiar to gen_ilvev_b(), changing the mask and shift. Maybe worth a refactor.
Quoted 54 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) +{ +TCGv_i64 t1 =tcg_temp_new_i64 (); +const uint64_t mask =0x00000000ffffffffULL ; + +tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 ], mask); +tcg_gen_deposit_i64 (msa_wr_d[wd *2 ], t1, msa_wr_d[ws *2 ],32 ,32 ); + +tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 +1 ], mask); +tcg_gen_deposit_i64 (msa_wr_d[wd *2 +1 ], t1, msa_wr_d[ws *2 +1 ],32 ,32 ); + +tcg_temp_free_i64 (t1); +} + +/* +* [MSA] ILVEV.D wd, ws, wt +* +* Vector Interleave Even (Double 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)))@@ -29130,7 +29218,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);
target/mips/translate.c static void gen_msa_3r(CPUMIPSState *env, DisasContext *ctx) · line 29239
Quoted 10 lines
target/mips/translate.c +7
-0+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);
Thanks,
Phil.
Re: [Qemu-devel] [PATCH v5 2/2] target/mips: Optimize ILVEV.<B|H|W|D> MSA instructions
Quoted 12 lines
From: Philippe Mathieu-Daudé <[email protected]>
Subject: Re: [Qemu-devel] [PATCH v5 2/2] target/mips: Optimize ILVEV.<B|H|W|D> MSA instructionsHi Mateja,
Quoted 5 lines · Mateja Marjanovic
From: Mateja Marjanovic <[email protected]>
Optimize set of MSA instructions ILVEV, using directly tcg registers and performing logic on them instead of using helpers.
Quoted 6 lines
Maybe you can still let this previous comment (if still valid):
Performance measurement is done by executing the instructions large number of times on a computer with Intel Core i7-3770 CPU @ 3.40GHz×8.
Agreed.
Quoted 7 lines
Quoted 6 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.
Quoted 18 lines
You are describing the "no-deposit" which refers to a previous series but won't be accessible in the git repository.
I think this table is useful in the cover of this series, and in the commit message you should use || before || after || and drop the "no-deposit" case.
Quoted 10 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 ilvev.w || 117.86 ms || 23.83 ms || 22.17 ms ilvev.d || 45.49 ms || 19.74 ms || 19.71 msThe solution with deposit is suggested by Richard Henderson.
I think the table should remain in the commit message, to keep it visible in the git logs.
You could insert the "no-deposit" source code of gen_ilvev_w() in the commit message, for reference reasons - it is not a too large function.
Thanks,
Aleksandar
Quoted 196 lines
The gitdm parsable form is:
Suggested-by Richard Henderson <[email protected]>Quoted 55 lines
Signed-off-by Mateja Marjanovic <[email protected]>--- target/mips/helper.h | 1 - target/mips/msa_helper.c | 9 ---- target/mips/translate.c | 105 ++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 104 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 +8
-0@@ -28974,6 +28974,94 @@ 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)target/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd, · line 28994
Quoted 10 lines
target/mips/translate.c +10
-0+{ +TCGv_i64 t1 =tcg_temp_new_i64 (); +TCGv_i64 t2 =tcg_temp_new_i64 (); +const uint64_t mask =0x00ff00ff00ff00ffULL ; + +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,8 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 ], t1, t2); +Richard, is it cheaper to use another register to keep the constant mask (here reused 4x)?
Such:
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);target/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd, · line 28996
Quoted 2 lines
target/mips/translate.c +2
-0+tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 +1 ], mask); +tcg_gen_andi_i64 (t2, msa_wr_d[ws *2 +1 ], mask);Here use
tcg_gen_and_i64()too.target/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd, · line 28999
Quoted 3 lines
target/mips/translate.c +3
-0+tcg_gen_shli_i64 (t2, t2,8 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 +1 ], t1, t2); +tcg_temp_free_i64(mask);target/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd, · line 29001
Quoted 2 lines
target/mips/translate.c +2
-0+tcg_temp_free_i64 (t1); +tcg_temp_free_i64 (t2);Mateja: Can you test for perf easily?
Quoted 17 lines
target/mips/translate.c +17
-0+} + +/* +* [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 (); +const uint64_t mask =0x0000ffff0000ffffULL ; + +tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 ], mask); +tcg_gen_andi_i64 (t2, msa_wr_d[ws *2 ], mask);target/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd, · line 29028
Quoted 10 lines
target/mips/translate.c +10
-0+tcg_gen_shli_i64 (t2, t2,16 ); +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,16 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 +1 ], t1, t2); + +tcg_temp_free_i64 (t1); +tcg_temp_free_i64 (t2);Very similiar to
gen_ilvev_b(), changing the mask and shift. Maybe worth a refactor.Quoted 54 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) +{ +TCGv_i64 t1 =tcg_temp_new_i64 (); +const uint64_t mask =0x00000000ffffffffULL ; + +tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 ], mask); +tcg_gen_deposit_i64 (msa_wr_d[wd *2 ], t1, msa_wr_d[ws *2 ],32 ,32 ); + +tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 +1 ], mask); +tcg_gen_deposit_i64 (msa_wr_d[wd *2 +1 ], t1, msa_wr_d[ws *2 +1 ],32 ,32 ); + +tcg_temp_free_i64 (t1); +} + +/* +* [MSA] ILVEV.D wd, ws, wt +* +* Vector Interleave Even (Double 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)))@@ -29130,7 +29218,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);target/mips/translate.c static void gen_msa_3r(CPUMIPSState *env, DisasContext *ctx) · line 29239
Quoted 10 lines
target/mips/translate.c +7
-0+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);Thanks,
Quoted 2 lines
Phil.
________________________________________
From: Philippe Mathieu-Daudé <[email protected]>
Sent: Tuesday, April 2, 2019 6:19:19 PM
To: Mateja Marjanovic; [email protected]
Cc: Aleksandar Rikalo; [email protected]; Aleksandar Markovic; [email protected]
Subject: Re: [Qemu-devel] [PATCH v5 2/2] target/mips: Optimize ILVEV.<B|H|W|D> MSA instructions
Hi Mateja,
Quoted 5 lines · Mateja Marjanovic
From: Mateja Marjanovic <[email protected]>
Optimize set of MSA instructions ILVEV, using directly tcg registers and performing logic on them instead of using helpers.
Maybe you can still let this previous comment (if still valid):
Performance measurement is done by executing the instructions large number of times on a computer with Intel Core i7-3770 CPU @ 3.40GHz×8.
Quoted 6 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.
You are describing the "no-deposit" which refers to a previous series but won't be accessible in the git repository.
I think this table is useful in the cover of this series, and in the commit message you should use || before || after || and drop the "no-deposit" case.
Quoted 10 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 ilvev.w || 117.86 ms || 23.83 ms || 22.17 ms ilvev.d || 45.49 ms || 19.74 ms || 19.71 msThe solution with deposit is suggested by Richard Henderson.
The gitdm parsable form is:
Quoted 55 lines
Signed-off-by Mateja Marjanovic <[email protected]>--- target/mips/helper.h | 1 - target/mips/msa_helper.c | 9 ---- target/mips/translate.c | 105 ++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 104 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 +8
-0@@ -28974,6 +28974,94 @@ 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)
target/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd, · line 28994
Quoted 10 lines
target/mips/translate.c +10
-0+{ +TCGv_i64 t1 =tcg_temp_new_i64 (); +TCGv_i64 t2 =tcg_temp_new_i64 (); +const uint64_t mask =0x00ff00ff00ff00ffULL ; + +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,8 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 ], t1, t2); +
Richard, is it cheaper to use another register to keep the constant mask (here reused 4x)?
Such:
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);target/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd, · line 28996
Quoted 2 lines
target/mips/translate.c +2
-0+tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 +1 ], mask); +tcg_gen_andi_i64 (t2, msa_wr_d[ws *2 +1 ], mask);
Here use tcg_gen_and_i64() too.
target/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd, · line 28999
Quoted 3 lines
target/mips/translate.c +3
-0+tcg_gen_shli_i64 (t2, t2,8 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 +1 ], t1, t2); +
tcg_temp_free_i64(mask);
target/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd, · line 29001
Quoted 2 lines
target/mips/translate.c +2
-0+tcg_temp_free_i64 (t1); +tcg_temp_free_i64 (t2);
Mateja: Can you test for perf easily?
Quoted 17 lines
target/mips/translate.c +17
-0+} + +/* +* [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 (); +const uint64_t mask =0x0000ffff0000ffffULL ; + +tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 ], mask); +tcg_gen_andi_i64 (t2, msa_wr_d[ws *2 ], mask);
target/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd, · line 29028
Quoted 10 lines
target/mips/translate.c +10
-0+tcg_gen_shli_i64 (t2, t2,16 ); +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,16 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 +1 ], t1, t2); + +tcg_temp_free_i64 (t1); +tcg_temp_free_i64 (t2);
Very similiar to gen_ilvev_b(), changing the mask and shift. Maybe worth a refactor.
Quoted 54 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) +{ +TCGv_i64 t1 =tcg_temp_new_i64 (); +const uint64_t mask =0x00000000ffffffffULL ; + +tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 ], mask); +tcg_gen_deposit_i64 (msa_wr_d[wd *2 ], t1, msa_wr_d[ws *2 ],32 ,32 ); + +tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 +1 ], mask); +tcg_gen_deposit_i64 (msa_wr_d[wd *2 +1 ], t1, msa_wr_d[ws *2 +1 ],32 ,32 ); + +tcg_temp_free_i64 (t1); +} + +/* +* [MSA] ILVEV.D wd, ws, wt +* +* Vector Interleave Even (Double 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)))@@ -29130,7 +29218,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);
target/mips/translate.c static void gen_msa_3r(CPUMIPSState *env, DisasContext *ctx) · line 29239
Quoted 10 lines
target/mips/translate.c +7
-0+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);
Thanks,
Phil.
Re: [Qemu-devel] [PATCH v5 2/2] target/mips: Optimize ILVEV.<B|H|W|D> MSA instructions
Quoted 47 lines · Aleksandar Markovic
Quoted 12 lines
From: Philippe Mathieu-Daudé <[email protected]>
Subject: Re: [Qemu-devel] [PATCH v5 2/2] target/mips: Optimize ILVEV.<B|H|W|D> MSA instructionsHi Mateja,
Quoted 5 lines · Mateja Marjanovic
From: Mateja Marjanovic <[email protected]>
Optimize set of MSA instructions ILVEV, using directly tcg registers and performing logic on them instead of using helpers.
Quoted 6 lines
Maybe you can still let this previous comment (if still valid):
Performance measurement is done by executing the instructions large number of times on a computer with Intel Core i7-3770 CPU @ 3.40GHz×8.
Agreed.
Quoted 7 lines
Quoted 6 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.Quoted 18 lines
You are describing the "no-deposit" which refers to a previous series but won't be accessible in the git repository.
I think this table is useful in the cover of this series, and in the commit message you should use || before || after || and drop the "no-deposit" case.
Quoted 10 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 ilvev.w || 117.86 ms || 23.83 ms || 22.17 ms ilvev.d || 45.49 ms || 19.74 ms || 19.71 msThe solution with deposit is suggested by Richard Henderson.
Quoted 6 lines
I think the table should remain in the commit message, to keep it visible in the git logs.
You could insert the "no-deposit" source code of
gen_ilvev_w()in the commit message, for reference reasons - it is not a too large function.
Clever :)
Quoted 448 lines
Thanks,
AleksandarQuoted 196 lines
The gitdm parsable form is:
Suggested-by Richard Henderson <[email protected]>Quoted 55 lines
Signed-off-by Mateja Marjanovic <[email protected]>--- target/mips/helper.h | 1 - target/mips/msa_helper.c | 9 ---- target/mips/translate.c | 105 ++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 104 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 +8
-0@@ -28974,6 +28974,94 @@ 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)target/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd, · line 28994
Quoted 10 lines
target/mips/translate.c +10
-0+{ +TCGv_i64 t1 =tcg_temp_new_i64 (); +TCGv_i64 t2 =tcg_temp_new_i64 (); +const uint64_t mask =0x00ff00ff00ff00ffULL ; + +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,8 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 ], t1, t2); +Richard, is it cheaper to use another register to keep the constant mask (here reused 4x)?
Such:
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);target/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd, · line 28996
Quoted 2 lines
target/mips/translate.c +2
-0+tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 +1 ], mask); +tcg_gen_andi_i64 (t2, msa_wr_d[ws *2 +1 ], mask);Here use
tcg_gen_and_i64()too.target/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd, · line 28999
Quoted 3 lines
target/mips/translate.c +3
-0+tcg_gen_shli_i64 (t2, t2,8 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 +1 ], t1, t2); +tcg_temp_free_i64(mask);target/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd, · line 29001
Quoted 2 lines
target/mips/translate.c +2
-0+tcg_temp_free_i64 (t1); +tcg_temp_free_i64 (t2);Mateja: Can you test for perf easily?
Quoted 17 lines
target/mips/translate.c +17
-0+} + +/* +* [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 (); +const uint64_t mask =0x0000ffff0000ffffULL ; + +tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 ], mask); +tcg_gen_andi_i64 (t2, msa_wr_d[ws *2 ], mask);target/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd, · line 29028
Quoted 10 lines
target/mips/translate.c +10
-0+tcg_gen_shli_i64 (t2, t2,16 ); +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,16 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 +1 ], t1, t2); + +tcg_temp_free_i64 (t1); +tcg_temp_free_i64 (t2);Very similiar to
gen_ilvev_b(), changing the mask and shift. Maybe worth a refactor.Quoted 54 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) +{ +TCGv_i64 t1 =tcg_temp_new_i64 (); +const uint64_t mask =0x00000000ffffffffULL ; + +tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 ], mask); +tcg_gen_deposit_i64 (msa_wr_d[wd *2 ], t1, msa_wr_d[ws *2 ],32 ,32 ); + +tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 +1 ], mask); +tcg_gen_deposit_i64 (msa_wr_d[wd *2 +1 ], t1, msa_wr_d[ws *2 +1 ],32 ,32 ); + +tcg_temp_free_i64 (t1); +} + +/* +* [MSA] ILVEV.D wd, ws, wt +* +* Vector Interleave Even (Double 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)))@@ -29130,7 +29218,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);target/mips/translate.c static void gen_msa_3r(CPUMIPSState *env, DisasContext *ctx) · line 29239
Quoted 10 lines
target/mips/translate.c +7
-0+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);Thanks,
Quoted 2 lines
Phil.
________________________________________
From: Philippe Mathieu-Daudé <[email protected]>
Sent: Tuesday, April 2, 2019 6:19:19 PM
To: Mateja Marjanovic; [email protected]
Cc: Aleksandar Rikalo; [email protected]; Aleksandar Markovic; [email protected]
Subject: Re: [Qemu-devel] [PATCH v5 2/2] target/mips: Optimize ILVEV.<B|H|W|D> MSA instructionsHi Mateja,
Quoted 5 lines · Mateja Marjanovic
From: Mateja Marjanovic <[email protected]>
Optimize set of MSA instructions ILVEV, using directly tcg registers and performing logic on them instead of using helpers.
Maybe you can still let this previous comment (if still valid):
Performance measurement is done by executing the instructions large number of times on a computer with Intel Core i7-3770 CPU @ 3.40GHz×8.
Quoted 6 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.You are describing the "no-deposit" which refers to a previous series but won't be accessible in the git repository.
I think this table is useful in the cover of this series, and in the commit message you should use || before || after || and drop the "no-deposit" case.
Quoted 10 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 ilvev.w || 117.86 ms || 23.83 ms || 22.17 ms ilvev.d || 45.49 ms || 19.74 ms || 19.71 msThe solution with deposit is suggested by Richard Henderson.
The gitdm parsable form is:
Suggested-by Richard Henderson <[email protected]>Quoted 55 lines
Signed-off-by Mateja Marjanovic <[email protected]>--- target/mips/helper.h | 1 - target/mips/msa_helper.c | 9 ---- target/mips/translate.c | 105 ++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 104 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 +8
-0@@ -28974,6 +28974,94 @@ 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)target/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd, · line 28994
Quoted 10 lines
target/mips/translate.c +10
-0+{ +TCGv_i64 t1 =tcg_temp_new_i64 (); +TCGv_i64 t2 =tcg_temp_new_i64 (); +const uint64_t mask =0x00ff00ff00ff00ffULL ; + +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,8 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 ], t1, t2); +Richard, is it cheaper to use another register to keep the constant mask (here reused 4x)?
Such:
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);target/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd, · line 28996
Quoted 2 lines
target/mips/translate.c +2
-0+tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 +1 ], mask); +tcg_gen_andi_i64 (t2, msa_wr_d[ws *2 +1 ], mask);Here use
tcg_gen_and_i64()too.target/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd, · line 28999
Quoted 3 lines
target/mips/translate.c +3
-0+tcg_gen_shli_i64 (t2, t2,8 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 +1 ], t1, t2); +tcg_temp_free_i64(mask);target/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd, · line 29001
Quoted 2 lines
target/mips/translate.c +2
-0+tcg_temp_free_i64 (t1); +tcg_temp_free_i64 (t2);Mateja: Can you test for perf easily?
Quoted 17 lines
target/mips/translate.c +17
-0+} + +/* +* [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 (); +const uint64_t mask =0x0000ffff0000ffffULL ; + +tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 ], mask); +tcg_gen_andi_i64 (t2, msa_wr_d[ws *2 ], mask);target/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd, · line 29028
Quoted 10 lines
target/mips/translate.c +10
-0+tcg_gen_shli_i64 (t2, t2,16 ); +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,16 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 +1 ], t1, t2); + +tcg_temp_free_i64 (t1); +tcg_temp_free_i64 (t2);Very similiar to
gen_ilvev_b(), changing the mask and shift. Maybe worth a refactor.Quoted 54 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) +{ +TCGv_i64 t1 =tcg_temp_new_i64 (); +const uint64_t mask =0x00000000ffffffffULL ; + +tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 ], mask); +tcg_gen_deposit_i64 (msa_wr_d[wd *2 ], t1, msa_wr_d[ws *2 ],32 ,32 ); + +tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 +1 ], mask); +tcg_gen_deposit_i64 (msa_wr_d[wd *2 +1 ], t1, msa_wr_d[ws *2 +1 ],32 ,32 ); + +tcg_temp_free_i64 (t1); +} + +/* +* [MSA] ILVEV.D wd, ws, wt +* +* Vector Interleave Even (Double 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)))@@ -29130,7 +29218,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);target/mips/translate.c static void gen_msa_3r(CPUMIPSState *env, DisasContext *ctx) · line 29239
Quoted 10 lines
target/mips/translate.c +7
-0+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);Thanks,
Phil.
Re: [Qemu-devel] [PATCH v5 2/2] target/mips: Optimize ILVEV.<B|H|W|D> MSA instructions
Quoted 12 lines · Philippe Mathieu-Daudé
Quoted 11 lines · Aleksandar Markovic
Quoted 11 lines
From: Philippe Mathieu-Daudé <[email protected]>
Subject: Re: [Qemu-devel] [PATCH v5 2/2] target/mips: Optimize ILVEV.<B|H|W|D> MSA instructionsHi Mateja,
Quoted 5 lines · Mateja Marjanovic
From: Mateja Marjanovic <[email protected]>
Optimize set of MSA instructions ILVEV, using directly tcg registers and performing logic on them instead of using helpers.
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Maybe you can still let this previous comment (if still valid):
Performance measurement is done by executing the instructions large number of times on a computer with Intel Core i7-3770 CPU @ 3.40GHz×8.
Agreed.
I will add that in v6.
Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
Quoted 6 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.You are describing the "no-deposit" which refers to a previous series but won't be accessible in the git repository.
I think this table is useful in the cover of this series, and in the commit message you should use || before || after || and drop the "no-deposit" case.
Quoted 9 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 ilvev.w || 117.86 ms || 23.83 ms || 22.17 ms ilvev.d || 45.49 ms || 19.74 ms || 19.71 msThe solution with deposit is suggested by Richard Henderson.
Quoted 7 lines
Quoted 6 lines
I think the table should remain in the commit message, to keep it visible in the git logs.
You could insert the "no-deposit" source code of
gen_ilvev_w()in the commit message, for reference reasons - it is not a too large function.Clever :)
I agree, I will add the code in the commit message in v6.
Quoted 89 lines
Quoted 89 lines
Thanks,
AleksandarQuoted 85 lines
The gitdm parsable form is:
Suggested-by Richard Henderson <[email protected]>Quoted 55 lines
Signed-off-by Mateja Marjanovic <[email protected]>--- target/mips/helper.h | 1 - target/mips/msa_helper.c | 9 ---- target/mips/translate.c | 105 ++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 104 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 +8
-0@@ -28974,6 +28974,94 @@ 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)target/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd, · line 28994
Quoted 10 lines
target/mips/translate.c +10
-0+{ +TCGv_i64 t1 =tcg_temp_new_i64 (); +TCGv_i64 t2 =tcg_temp_new_i64 (); +const uint64_t mask =0x00ff00ff00ff00ffULL ; + +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,8 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 ], t1, t2); +Richard, is it cheaper to use another register to keep the constant mask (here reused 4x)?
Such:
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);target/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd, · line 28996
Quoted 2 lines
target/mips/translate.c +2
-0+tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 +1 ], mask); +tcg_gen_andi_i64 (t2, msa_wr_d[ws *2 +1 ], mask);Here use
tcg_gen_and_i64()too.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
target/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd, · line 28999
Quoted 3 lines
target/mips/translate.c +3
-0+tcg_gen_shli_i64 (t2, t2,8 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 +1 ], t1, t2); +tcg_temp_free_i64(mask);target/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd, · line 29001
Quoted 2 lines
target/mips/translate.c +2
-0+tcg_temp_free_i64 (t1); +tcg_temp_free_i64 (t2);Mateja: Can you test for perf easily?
I will test that, and notify you with the results.
Quoted 97 lines
Quoted 97 lines
Quoted 97 lines
Quoted 18 lines
target/mips/translate.c +17
-0+} + +/* +* [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 (); +const uint64_t mask =0x0000ffff0000ffffULL ; + +tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 ], mask); +tcg_gen_andi_i64 (t2, msa_wr_d[ws *2 ], mask);target/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd, · line 29028
Quoted 10 lines
target/mips/translate.c +10
-0+tcg_gen_shli_i64 (t2, t2,16 ); +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,16 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 +1 ], t1, t2); + +tcg_temp_free_i64 (t1); +tcg_temp_free_i64 (t2);Very similiar to
gen_ilvev_b(), changing the mask and shift. Maybe worth a refactor.Quoted 54 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) +{ +TCGv_i64 t1 =tcg_temp_new_i64 (); +const uint64_t mask =0x00000000ffffffffULL ; + +tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 ], mask); +tcg_gen_deposit_i64 (msa_wr_d[wd *2 ], t1, msa_wr_d[ws *2 ],32 ,32 ); + +tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 +1 ], mask); +tcg_gen_deposit_i64 (msa_wr_d[wd *2 +1 ], t1, msa_wr_d[ws *2 +1 ],32 ,32 ); + +tcg_temp_free_i64 (t1); +} + +/* +* [MSA] ILVEV.D wd, ws, wt +* +* Vector Interleave Even (Double 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)))@@ -29130,7 +29218,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);target/mips/translate.c static void gen_msa_3r(CPUMIPSState *env, DisasContext *ctx) · line 29239
Quoted 10 lines
target/mips/translate.c +7
-0+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);Thanks,
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Phil.
Thanks,
Mateja
Quoted 234 lines
Quoted 234 lines
________________________________________
From: Philippe Mathieu-Daudé <[email protected]>
Sent: Tuesday, April 2, 2019 6:19:19 PM
To: Mateja Marjanovic; [email protected]
Cc: Aleksandar Rikalo; [email protected]; Aleksandar Markovic; [email protected]
Subject: Re: [Qemu-devel] [PATCH v5 2/2] target/mips: Optimize ILVEV.<B|H|W|D> MSA instructionsHi Mateja,
Quoted 5 lines · Mateja Marjanovic
From: Mateja Marjanovic <[email protected]>
Optimize set of MSA instructions ILVEV, using directly tcg registers and performing logic on them instead of using helpers.
Maybe you can still let this previous comment (if still valid):
Performance measurement is done by executing the instructions large number of times on a computer with Intel Core i7-3770 CPU @ 3.40GHz×8.
Quoted 5 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.You are describing the "no-deposit" which refers to a previous series but won't be accessible in the git repository.
I think this table is useful in the cover of this series, and in the commit message you should use || before || after || and drop the "no-deposit" case.
Quoted 9 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 ilvev.w || 117.86 ms || 23.83 ms || 22.17 ms ilvev.d || 45.49 ms || 19.74 ms || 19.71 msThe solution with deposit is suggested by Richard Henderson.
The gitdm parsable form is:
Suggested-by Richard Henderson <[email protected]>Quoted 55 lines
Signed-off-by Mateja Marjanovic <[email protected]>--- target/mips/helper.h | 1 - target/mips/msa_helper.c | 9 ---- target/mips/translate.c | 105 ++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 104 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 +8
-0@@ -28974,6 +28974,94 @@ 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)target/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd, · line 28994
Quoted 10 lines
target/mips/translate.c +10
-0+{ +TCGv_i64 t1 =tcg_temp_new_i64 (); +TCGv_i64 t2 =tcg_temp_new_i64 (); +const uint64_t mask =0x00ff00ff00ff00ffULL ; + +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,8 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 ], t1, t2); +Richard, is it cheaper to use another register to keep the constant mask (here reused 4x)?
Such:
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);target/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd, · line 28996
Quoted 2 lines
target/mips/translate.c +2
-0+tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 +1 ], mask); +tcg_gen_andi_i64 (t2, msa_wr_d[ws *2 +1 ], mask);Here use
tcg_gen_and_i64()too.target/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd, · line 28999
Quoted 3 lines
target/mips/translate.c +3
-0+tcg_gen_shli_i64 (t2, t2,8 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 +1 ], t1, t2); +tcg_temp_free_i64(mask);target/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd, · line 29001
Quoted 2 lines
target/mips/translate.c +2
-0+tcg_temp_free_i64 (t1); +tcg_temp_free_i64 (t2);Mateja: Can you test for perf easily?
Quoted 17 lines
target/mips/translate.c +17
-0+} + +/* +* [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 (); +const uint64_t mask =0x0000ffff0000ffffULL ; + +tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 ], mask); +tcg_gen_andi_i64 (t2, msa_wr_d[ws *2 ], mask);target/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd, · line 29028
Quoted 10 lines
target/mips/translate.c +10
-0+tcg_gen_shli_i64 (t2, t2,16 ); +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,16 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 +1 ], t1, t2); + +tcg_temp_free_i64 (t1); +tcg_temp_free_i64 (t2);Very similiar to
gen_ilvev_b(), changing the mask and shift. Maybe worth a refactor.Quoted 54 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) +{ +TCGv_i64 t1 =tcg_temp_new_i64 (); +const uint64_t mask =0x00000000ffffffffULL ; + +tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 ], mask); +tcg_gen_deposit_i64 (msa_wr_d[wd *2 ], t1, msa_wr_d[ws *2 ],32 ,32 ); + +tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 +1 ], mask); +tcg_gen_deposit_i64 (msa_wr_d[wd *2 +1 ], t1, msa_wr_d[ws *2 +1 ],32 ,32 ); + +tcg_temp_free_i64 (t1); +} + +/* +* [MSA] ILVEV.D wd, ws, wt +* +* Vector Interleave Even (Double 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)))@@ -29130,7 +29218,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);target/mips/translate.c static void gen_msa_3r(CPUMIPSState *env, DisasContext *ctx) · line 29239
Quoted 10 lines
target/mips/translate.c +7
-0+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);Thanks,
Phil.
Re: [Qemu-devel] [PATCH v5 2/2] target/mips: Optimize ILVEV.<B|H|W|D> MSA instructions
In reply to Philippe Mathieu-DaudéQuoted 16 lines · Philippe Mathieu-Daudé
target/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd, · line 28994
Quoted 12 lines
target/mips/translate.c +12
-0+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 (); +const uint64_t mask =0x00ff00ff00ff00ffULL ; + +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,8 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 ], t1, t2); +Richard, is it cheaper to use another register to keep the constant mask (here reused 4x)?
Quoted 8 lines
Such:
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);
With the current state of the tcg optimizer, yes.
r~
Re: [Qemu-devel] [PATCH v5 2/2] target/mips: Optimize ILVEV.<B|H|W|D> MSA instructions
In reply to Mateja MarjanovicQuoted 6 lines
+/*
+ * [MSA] ILVEV.D wd, ws, wt
+ *
+ * Vector Interleave Even (Double data elements)
+ *
+ */
Double -> Doubleword
Re: [Qemu-devel] [PATCH v5 2/2] target/mips: Optimize ILVEV.<B|H|W|D> MSA instructions
Quoted 7 lines · Aleksandar Markovic
Quoted 6 lines
+/*
+ * [MSA] ILVEV.D wd, ws, wt
+ *
+ * Vector Interleave Even (Double data elements)
+ *
+ */Double -> Doubleword
I will change it in v6.
Re: [Qemu-devel] [PATCH v5 2/2] target/mips: Optimize ILVEV.<B|H|W|D> MSA instructions
In reply to Mateja MarjanovicQuoted 20 lines · Mateja Marjanovic
From: Mateja Marjanovic <[email protected]>
Optimize set of MSA instructions ILVEV, 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.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 7 lines
The solution with deposit is suggested by Richard Henderson.
Signed-off-by Mateja Marjanovic <[email protected]>--- target/mips/helper.h | 1 - target/mips/msa_helper.c | 9 ---- target/mips/translate.c | 105
++++++++++++++++++++++++++++++++++++++++++++++-
target/mips/helper.h DEF_HELPER_5(msa_pckev_df, void, env, i32, i32, i32,
Quoted 7 lines
3 files changed, 104 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)
target/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState
Quoted 32 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#define MSA_LOOP_COND (DF ) \target/mips/translate.c +0
-0@@ -28974,6 +28974,94 @@ static inline void gen_ilvod_d(CPUMIPSState
*env, uint32_t wd,
Quoted 64 lines
target/mips/translate.c +61
-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 (); +const uint64_t mask =0x00ff00ff00ff00ffULL ; + +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,8 ); +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,8 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 +1 ], t1, t2); + +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 (); +const uint64_t mask =0x0000ffff0000ffffULL ; + +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,16 ); +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,16 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 +1 ], t1, t2); + +tcg_temp_free_i64 (t1); +tcg_temp_free_i64 (t2); +} + +/* +* [MSA] ILVEV.W wd, ws, wt +* +* Vector Interleave Even (word data elements) +* +*/ +static inline void gen_ilvev_w(CPUMIPSState *env, uint32_t wd,
target/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd,
Quoted 10 lines
target/mips/translate.c +10
-0+ uint32_t ws, uint32_t wt) +{ +TCGv_i64 t1 =tcg_temp_new_i64 (); +const uint64_t mask =0x00000000ffffffffULL ; + +tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 ], mask); +tcg_gen_deposit_i64 (msa_wr_d[wd *2 ], t1, msa_wr_d[ws *2 ],32 ,32 ); + +tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 +1 ], mask); + tcg_gen_deposit_i64(msa_wr_d[wd * 2 + 1], t1, msa_wr_d[ws * 2 + 1],
32, 32);
target/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd, · line 29003
Quoted 4 lines
target/mips/translate.c +4
-0+ +tcg_temp_free_i64 (t1); +} +
This can be further optimized this way: (doublecheck the accuracy, writing from home)
gen_ilvev_w(CPUMIPSState *env, uint32_t wd,
uint32_t ws, uint32_t wt)
{
tcg_gen_shli_i64(msa_wr_d[wd * 2], msa_wr_d[ws * 2], 32);
tcg_gen_deposit_i64(msa_wr_d[wd * 2], t1, msa_wr_d[wt * 2], 0, 32);tcg_gen_shli_i64(msa_wr_d[wd * 2 + 1], msa_wr_d[ws * 2 + 1], 32);
tcg_gen_deposit_i64(msa_wr_d[wd * 2 + 1], t1, msa_wr_d[wt * 2 + 1], 0,32);
}
target/mips/translate.c static void gen_msa_3r(CPUMIPSState *env,
Quoted 17 lines
target/mips/translate.c +13
-0+/* +* [MSA] ILVEV.D wd, ws, wt +* +* Vector Interleave Even (Double 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)))@@ -29130,7 +29218,22 @@ static void gen_msa_3r(CPUMIPSState *env,
DisasContext *ctx)
Quoted 27 lines
target/mips/translate.c +16
-2gen_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); --2.7.4
Re: [Qemu-devel] [PATCH v5 2/2] target/mips: Optimize ILVEV.<B|H|W|D> MSA instructions
Quoted 13 lines · Aleksandar Markovic
target/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd, · line 29051
Quoted 9 lines
+
tcg_gen_andi_i64(t1, msa_wr_d[wt * 2], mask);
+tcg_gen_deposit_i64(msa_wr_d[wd * 2], t1, msa_wr_d[ws * 2], 32, 32);target/mips/translate.c +7
-0+ + tcg_gen_andi_i64(t1, msa_wr_d[wt * 2 + 1], mask); + tcg_gen_deposit_i64(msa_wr_d[wd * 2 + 1], t1, msa_wr_d[ws * 2 + 1], 32, 32); + + tcg_temp_free_i64(t1); +} +This can be further optimized this way: (doublecheck the accuracy, writing from home)
Quoted 6 lines
gen_ilvev_w(CPUMIPSState *env,
uint32_twd,
uint32_t ws,uint32_twt)
{
tcg_gen_shli_i64(msa_wr_d[wd * 2], msa_wr_d[ws * 2], 32);tcg_gen_deposit_i64(msa_wr_d[wd * 2], t1, msa_wr_d[wt * 2], 0, 32);
No, the shift can be performed by the deposit.
See my other reply in this thread.
r~
Re: [Qemu-devel] [PATCH v5 2/2] target/mips: Optimize ILVEV.<B|H|W|D> MSA instructions
In reply to Mateja MarjanovicQuoted 4 lines · Mateja Marjanovic
From: Mateja Marjanovic <[email protected]>
Optimize set of MSA instructions ILVEV, using directly
Use full instruction names, with the only exception of possible Bachus-Naur forms... again.
Quoted 16 lines
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.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 4 lines
The solution with deposit is suggested by Richard Henderson.
Signed-off-by Mateja Marjanovic <[email protected]>---
The byte and halfword cases of this patch most likely produce highly unoptimized code for cases:
wd == wt == ws
wd == wt != ws
wd != ws == wt
wd == ws != wt
Please take these cases into account.
The same for patch 1/2.
Thanks,
Aleksandar
Quoted 3 lines
target/mips/helper.h | 1 - target/mips/msa_helper.c | 9 ---- target/mips/translate.c | 105
++++++++++++++++++++++++++++++++++++++++++++++-
target/mips/helper.h DEF_HELPER_5(msa_pckev_df, void, env, i32, i32, i32,
Quoted 7 lines
3 files changed, 104 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)
target/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState
Quoted 32 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#define MSA_LOOP_COND (DF ) \target/mips/translate.c +0
-0@@ -28974,6 +28974,94 @@ static inline void gen_ilvod_d(CPUMIPSState
*env, uint32_t wd,
Quoted 64 lines
target/mips/translate.c +61
-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 (); +const uint64_t mask =0x00ff00ff00ff00ffULL ; + +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,8 ); +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,8 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 +1 ], t1, t2); + +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 (); +const uint64_t mask =0x0000ffff0000ffffULL ; + +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,16 ); +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,16 ); +tcg_gen_or_i64 (msa_wr_d[wd *2 +1 ], t1, t2); + +tcg_temp_free_i64 (t1); +tcg_temp_free_i64 (t2); +} + +/* +* [MSA] ILVEV.W wd, ws, wt +* +* Vector Interleave Even (word data elements) +* +*/ +static inline void gen_ilvev_w(CPUMIPSState *env, uint32_t wd,
target/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd,
Quoted 10 lines
target/mips/translate.c +10
-0+ uint32_t ws, uint32_t wt) +{ +TCGv_i64 t1 =tcg_temp_new_i64 (); +const uint64_t mask =0x00000000ffffffffULL ; + +tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 ], mask); +tcg_gen_deposit_i64 (msa_wr_d[wd *2 ], t1, msa_wr_d[ws *2 ],32 ,32 ); + +tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 +1 ], mask); + tcg_gen_deposit_i64(msa_wr_d[wd * 2 + 1], t1, msa_wr_d[ws * 2 + 1],
32, 32);
target/mips/translate.c static void gen_msa_3r(CPUMIPSState *env,
Quoted 21 lines
target/mips/translate.c +17
-0+ +tcg_temp_free_i64 (t1); +} + +/* +* [MSA] ILVEV.D wd, ws, wt +* +* Vector Interleave Even (Double 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)))@@ -29130,7 +29218,22 @@ static void gen_msa_3r(CPUMIPSState *env,
DisasContext *ctx)
Quoted 27 lines
target/mips/translate.c +16
-2gen_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); --2.7.4
Re: [Qemu-devel] [PATCH v5 2/2] target/mips: Optimize ILVEV.<B|H|W|D> MSA instructions
Quoted 11 lines · Aleksandar Markovic
Quoted 2 lines · On Apr 2, 2019 5:20 PM, "Mateja Marjanovic" <[email protected]…
From: Mateja Marjanovic <[email protected]
<mailto:[email protected]>>
Quoted 2 lines
Optimize set of MSA instructions ILVEV, using directly
Use full instruction names, with the only exception of possible Bachus-Naur forms... again.
I will, I didn't change it from some of the previous versions.
Quoted 25 lines
Quoted 12 lines
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.instr || before || no-deposit || with-deposit
========================================================Quoted 8 lines
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 msThe solution with deposit is suggested by Richard Henderson.
Signed-off-by Mateja Marjanovic <[email protected]<mailto:[email protected]>>
Quoted 1 line
---
The byte and halfword cases of this patch most likely produce highly unoptimized code for cases:
Quoted 9 lines
wd == wt == ws
wd == wt != ws
wd != ws == wt
wd == ws != wtPlease take these cases into account.
The same for patch 1/2.
Maybe, but if I put if statements asking are the registers the same, it would affect the performance significantly in all cases. If some registers were equal, it would be faster, but if not, just those if statements would slow things down.
Quoted 4 lines
Thanks,
Aleksandar
Thanks,
Mateja
Quoted 171 lines
Quoted 3 lines
target/mips/helper.h | 1 -
target/mips/msa_helper.c | 9 ----
target/mips/translate.c | 105++++++++++++++++++++++++++++++++++++++++++++++-
target/mips/helper.h DEF_HELPER_5(msa_pckev_df, void, env, i32, i32,
Quoted 7 lines
3 files changed, 104 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)
target/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState
Quoted 32 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 #define MSA_LOOP_COND(DF) \target/mips/translate.c +0
-0@@ -28974,6 +28974,94 @@ static inline void gen_ilvod_d(CPUMIPSState*env,
uint32_twd,Quoted 61 lines
target/mips/translate.c +58
-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(); + const uint64_t mask = 0x00ff00ff00ff00ffULL; + + 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, 8); + 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, 8); + tcg_gen_or_i64(msa_wr_d[wd * 2 + 1], t1, t2); + + 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(); + const uint64_t mask = 0x0000ffff0000ffffULL; + + 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, 16); + 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, 16); + tcg_gen_or_i64(msa_wr_d[wd * 2 + 1], t1, t2); + + tcg_temp_free_i64(t1); + tcg_temp_free_i64(t2); +} + +/* +* [MSA] ILVEV.W wd, ws, wt +* +* Vector Interleave Even (word data elements) target/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd,
Quoted 10 lines
target/mips/translate.c +10
-0+* +*/ +static inline void gen_ilvev_w (CPUMIPSState *env,uint32_t wd, + uint32_t ws, uint32_t wt) +{ + TCGv_i64 t1 = tcg_temp_new_i64(); + const uint64_t mask = 0x00000000ffffffffULL; + + tcg_gen_andi_i64(t1, msa_wr_d[wt * 2], mask); + tcg_gen_deposit_i64(msa_wr_d[wd * 2], t1, msa_wr_d[ws * 2], 32,32);
target/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd,
Quoted 3 lines
target/mips/translate.c +3
-0+ + tcg_gen_andi_i64(t1, msa_wr_d[wt * 2 + 1], mask); + tcg_gen_deposit_i64(msa_wr_d[wd * 2 + 1], t1, msa_wr_d[ws * 2 +1], 32, 32);
target/mips/translate.c static void gen_msa_3r(CPUMIPSState *env,
Quoted 21 lines
target/mips/translate.c +17
-0+ + tcg_temp_free_i64(t1); +} + +/* +* [MSA] ILVEV.D wd, ws, wt +* +* Vector Interleave Even (Double 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)))@@ -29130,7 +29218,22 @@ static void gen_msa_3r(CPUMIPSState *env,DisasContext *ctx)
Quoted 27 lines
target/mips/translate.c +0
-0gen_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) {
+ caseDF_BYTE:
+gen_ilvev_b(env, wd, ws, wt);
+ break;
+ caseDF_HALF:
+gen_ilvev_h(env, wd, ws, wt);
+ break;
+ caseDF_WORD:
+gen_ilvev_w(env, wd, ws, wt);
+ break;
+ caseDF_DOUBLE:
+gen_ilvev_d(env, wd, ws, wt);
+ break;
+ default:
+ assert(0);
+ }
break;
caseOPC_BINSR_df:
gen_helper_msa_binsr_df(cpu_env, tdf, twd, tws, twt); --
2.7.4
Re: [Qemu-devel] [PATCH v5 2/2] target/mips: Optimize ILVEV.<B|H|W|D> MSA instructions
Quoted 21 lines
Quoted 21 lines
From: Mateja Marjanovic <[email protected]>
Subject: Re: [Qemu-devel] [PATCH v5 2/2] target/mips: Optimize ILVEV.<B|H|W|D> MSA > > instructionsOn 3.4.19. 01:25, Aleksandar Markovic wrote:
Quoted 6 lines · On Apr 2, 2019 5:20 PM, "Mateja Marjanovic" <[email protected]<> >…
From: Mateja Marjanovic <[email protected]<> > mailto:[email protected]>>
Optimize set of MSA instructions ILVEV
...
The byte and halfword cases of this patch most likely produce highly unoptimized code > > for cases:
wd == wt == ws
wd == wt != ws
wd != ws == wt
wd == ws != wt
Quoted 8 lines
Quoted 3 lines
Please take these cases into account.
The same for patch 1/2.
Maybe, but if I put if statements asking are the registers the same, it would affect the performance significantly in all cases. If some registers were equal, it would be faster, but if not, just those if statements would slow things down.
Mateja,
It won't affect the performance significantly at all. Distinguish between the code executed in translate time (rarely) and execute time (often). If statement you mention are executed in translate time.
Thanks,
Aleksandar
Re: [Qemu-devel] [PATCH v5 2/2] target/mips: Optimize ILVEV.<B|H|W|D> MSA instructions
In reply to Aleksandar MarkovicQuoted 37 lines · Aleksandar Markovic
Quoted 2 lines · On Apr 2, 2019 5:20 PM, "Mateja Marjanovic" <[email protected]…
From: Mateja Marjanovic <[email protected]
<mailto:[email protected]>>
Quoted 2 lines
Optimize set of MSA instructions ILVEV, using directly
Use full instruction names, with the only exception of possible Bachus-Naur forms... again.
Quoted 11 lines
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.instr || before || no-deposit || with-deposit
========================================================Quoted 8 lines
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 msThe solution with deposit is suggested by Richard Henderson.
Signed-off-by Mateja Marjanovic <[email protected]<mailto:[email protected]>>
Quoted 1 line
---
The byte and halfword cases of this patch most likely produce highly unoptimized code for cases:
Quoted 6 lines
wd == wt == ws
wd == wt != ws
wd != ws == wt
wd == ws != wtPlease take these cases into account.
I beg to differ. We want to minimize the amount of special cases.
If you multiply the different cases like this you also multiply the maintenance overhead. You force future maintainers to wonder if the cases are truly distinct or if they are mere optimization.
The only special cases that I advocate that you add are driven by standard macros that the assembler generates -- e.g. register move (via or), register negate (via nor), etc.
r~
Re: [Qemu-devel] [PATCH v5 2/2] target/mips: Optimize ILVEV.<B|H|W|D> MSA instructions
Quoted 46 lines
From: Richard Henderson <[email protected]>
Subject: Re: [Qemu-devel] [PATCH v5 2/2] target/mips: Optimize ILVEV.<B|H|W|D> MSA > instructionsQuoted 42 lines · Aleksandar Markovic
Quoted 2 lines · On Apr 2, 2019 5:20 PM, "Mateja Marjanovic" <[email protected]…
From: Mateja Marjanovic <[email protected]
<mailto:[email protected]>>
Quoted 2 lines
Optimize set of MSA instructions ILVEV, using directly
Use full instruction names, with the only exception of possible Bachus-Naur forms... again.
Quoted 11 lines
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.instr || before || no-deposit || with-deposit
========================================================Quoted 8 lines
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 msThe solution with deposit is suggested by Richard Henderson.
Signed-off-by Mateja Marjanovic <[email protected]<mailto:[email protected]>>
Quoted 1 line
---
The byte and halfword cases of this patch most likely produce highly unoptimized code for cases:
wd == wt == ws
wd == wt != ws
wd != ws == wt
wd == ws != wt
Quoted 8 lines
Quoted 1 line
Please take these cases into account.
I beg to differ. We want to minimize the amount of special cases.
If you multiply the different cases like this you also multiply the maintenance overhead. You force future maintainers to wonder if the cases are truly distinct or if they are mere optimization.
I find your objection hard to understand.
The subject and the goal of the patch is obviously optimization. If there is a danger of unclarity in the resulting source code, this is easily alleviated by, for example, inserting informative comments, as is routinely done in many other areas of QEMU or any software product.
Sincerely,
Aleksandar
Quoted 6 lines
The only special cases that I advocate that you add are driven by standard macros that the assembler generates -- e.g. register move (via or), register negate (via nor), etc.
r~
Re: [Qemu-devel] [PATCH v5 2/2] target/mips: Optimize ILVEV.<B|H|W|D> MSA instructions
In reply to Mateja Marjanovictarget/mips/translate.c static inline void gen_ilvod_d(CPUMIPSState *env, uint32_t wd, · line 29044
Quoted 8 lines · Mateja Marjanovic
target/mips/translate.c +8
-0+static inline void gen_ilvev_w (CPUMIPSState *env,uint32_t wd, +uint32_t ws,uint32_t wt) +{ +TCGv_i64 t1 =tcg_temp_new_i64 (); +const uint64_t mask =0x00000000ffffffffULL ; + +tcg_gen_andi_i64 (t1, msa_wr_d[wt *2 ], mask); +tcg_gen_deposit_i64 (msa_wr_d[wd *2 ], t1, msa_wr_d[ws *2 ],32 ,32 );
The andi of mask is redundant with the deposit. Remove it. This should be just
tcg_gen_deposit_i64(msa_wr_d[wd * 2], msa_wr_d[wt * 2],
msa_wr_d[ws * 2], 32, 32);r~