target/mips: Convert Loongson LEXT opcodes to decodetree
cover target/mips: Convert Loongson LEXT opcodes to decodetree
Loongson is next step in the "MIPS decodetree conversion" epic. Start with the simplest extension.
The diffstat addition comes from the TCG functions expanded. The code is easier to review now.
IMO this is also a good template to show how easy a decodetree conversion can be (and how nice the .decode file is to review) :P
Please review,
Phil.
Based-on: <[email protected]>
"decodetree: Allow 'dot' in opcode names"
Philippe Mathieu-Daudé (6):
target/mips: Re-introduce OPC_ADDUH_QB_DSP and OPC_MUL_PH_DSP target/mips: Convert Loongson DDIV.G opcodes to decodetree target/mips: Convert Loongson DIV.G opcodes to decodetree target/mips: Convert Loongson [D]DIVU.G opcodes to decodetree target/mips: Convert Loongson [D]MOD[U].G opcodes to decodetree target/mips: Convert Loongson [D]MULT[U].G opcodes to decodetree
target/mips/translate.h | 1 + target/mips/godson2.decode | 29 +++ target/mips/loong-ext.decode | 30 +++ target/mips/loong_translate.c | 334 ++++++++++++++++++++++++++++++++++ target/mips/translate.c | 287 ++--------------------------- target/mips/meson.build | 3 + 6 files changed, 409 insertions(+), 275 deletions(-) create mode 100644 target/mips/godson2.decode create mode 100644 target/mips/loong-ext.decode create mode 100644 target/mips/loong_translate.c
Signature · 1 line
2.26.2
PATCH 1/6 target/mips: Re-introduce OPC_ADDUH_QB_DSP and OPC_MUL_PH_DSP
There is no issue having multiple enum declarations with the same value. As we are going to remove the OPC_MULT_G_2E definition in few commits, restore the OPC_ADDUH_QB_DSP and OPC_MUL_PH_DSP definitions and use them where they belong.
--- target/mips/translate.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-)
target/mips/translate.c +5 -13
@@ -399,16 +399,14 @@ enum {OPC_ADDU_OB_DSP =0x14 |OPC_SPECIAL3 ,OPC_ABSQ_S_PH_DSP =0x12 |OPC_SPECIAL3 ,OPC_ABSQ_S_QH_DSP =0x16 |OPC_SPECIAL3 , -/* OPC_ADDUH_QB_DSP is same as OPC_MULT_G_2E. */ -/* OPC_ADDUH_QB_DSP = 0x18 | OPC_SPECIAL3, */ +OPC_ADDUH_QB_DSP =0x18 |OPC_SPECIAL3 ,OPC_CMPU_EQ_QB_DSP =0x11 |OPC_SPECIAL3 ,OPC_CMPU_EQ_OB_DSP =0x15 |OPC_SPECIAL3 ,/* MIPS DSP GPR-Based Shift Sub-class */ OPC_SHLL_QB_DSP =0x13 |OPC_SPECIAL3 ,OPC_SHLL_OB_DSP =0x17 |OPC_SPECIAL3 ,/* MIPS DSP Multiply Sub-class insns */ -/* OPC_MUL_PH_DSP is same as OPC_ADDUH_QB_DSP. */ -/* OPC_MUL_PH_DSP = 0x18 | OPC_SPECIAL3, */ +OPC_MUL_PH_DSP =0x18 |OPC_SPECIAL3 ,OPC_DPA_W_PH_DSP =0x30 |OPC_SPECIAL3 ,OPC_DPAQ_W_QH_DSP =0x34 |OPC_SPECIAL3 , /* DSP Bit/Manipulation Sub-class */
@@ -566,7 +564,6 @@ enum { OPC_MULQ_S_PH = (0x1E << 6) | OPC_ADDU_QB_DSP, }; -#define OPC_ADDUH_QB_DSP OPC_MULT_G_2E#define MASK_ADDUH_QB (op) (MASK_SPECIAL3(op) | (op & (0x1F << 6)))enum {/* MIPS DSP Arithmetic Sub-class */
@@ -22681,8 +22678,7 @@ static void gen_mipsdsp_arith(DisasContext *ctx, uint32_t op1, uint32_t op2,gen_load_gpr (v2_t, v2);switch (op1) { -/* OPC_MULT_G_2E is equal OPC_ADDUH_QB_DSP */ -case OPC_MULT_G_2E : +case OPC_ADDUH_QB_DSP :check_dsp_r2 (ctx);switch (op2) {case OPC_ADDUH_QB :
@@ -23376,11 +23372,7 @@ static void gen_mipsdsp_multiply(DisasContext *ctx, uint32_t op1, uint32_t op2,gen_load_gpr (v2_t, v2);switch (op1) { -/* -* OPC_MULT_G_2E, OPC_ADDUH_QB_DSP, OPC_MUL_PH_DSP have -* the same mask and op1. -*/ -case OPC_MULT_G_2E : +case OPC_MUL_PH_DSP :check_dsp_r2 (ctx);switch (op2) {case OPC_MUL_PH :
@@ -27337,7 +27329,7 @@ static void decode_opc_special3_legacy(CPUMIPSState *env, DisasContext *ctx)* OPC_MULT_G_2E, OPC_ADDUH_QB_DSP, OPC_MUL_PH_DSP have * the same mask and op1. */ -if ((ctx->insn_flags &ASE_DSP_R2 ) && (op1 ==OPC_MULT_G_2E )) { +if ((ctx->insn_flags &ASE_DSP_R2 ) && (op1 ==OPC_MUL_PH_DSP )) { op2 =MASK_ADDUH_QB (ctx->opcode);switch (op2) {case OPC_ADDUH_QB :
Signature · 1 line
2.26.2
Re: [PATCH 1/6] target/mips: Re-introduce OPC_ADDUH_QB_DSP and OPC_MUL_PH_DSP
Quoted 6 lines · Philippe Mathieu-Daudé
There is no issue having multiple enum declarations with the same value. As we are going to remove the
OPC_MULT_G_2Edefinition in few commits, restore theOPC_ADDUH_QB_DSPandOPC_MUL_PH_DSPdefinitions and use them where they belong.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 67 lines
--- target/mips/translate.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-)target/mips/translate.c +5
-13@@ -399,16 +399,14 @@ enum {OPC_ADDU_OB_DSP =0x14 |OPC_SPECIAL3 ,OPC_ABSQ_S_PH_DSP =0x12 |OPC_SPECIAL3 ,OPC_ABSQ_S_QH_DSP =0x16 |OPC_SPECIAL3 , -/* OPC_ADDUH_QB_DSP is same as OPC_MULT_G_2E. */ -/* OPC_ADDUH_QB_DSP = 0x18 | OPC_SPECIAL3, */ +OPC_ADDUH_QB_DSP =0x18 |OPC_SPECIAL3 ,OPC_CMPU_EQ_QB_DSP =0x11 |OPC_SPECIAL3 ,OPC_CMPU_EQ_OB_DSP =0x15 |OPC_SPECIAL3 ,/* MIPS DSP GPR-Based Shift Sub-class */ OPC_SHLL_QB_DSP =0x13 |OPC_SPECIAL3 ,OPC_SHLL_OB_DSP =0x17 |OPC_SPECIAL3 ,/* MIPS DSP Multiply Sub-class insns */ -/* OPC_MUL_PH_DSP is same as OPC_ADDUH_QB_DSP. */ -/* OPC_MUL_PH_DSP = 0x18 | OPC_SPECIAL3, */ +OPC_MUL_PH_DSP =0x18 |OPC_SPECIAL3 ,OPC_DPA_W_PH_DSP =0x30 |OPC_SPECIAL3 ,OPC_DPAQ_W_QH_DSP =0x34 |OPC_SPECIAL3 , /* DSP Bit/Manipulation Sub-class */@@ -566,7 +564,6 @@ enum { OPC_MULQ_S_PH = (0x1E << 6) | OPC_ADDU_QB_DSP, }; -#define OPC_ADDUH_QB_DSP OPC_MULT_G_2E#define MASK_ADDUH_QB (op) (MASK_SPECIAL3(op) | (op & (0x1F << 6)))enum {/* MIPS DSP Arithmetic Sub-class */ @@ -22681,8 +22678,7 @@ static void gen_mipsdsp_arith(DisasContext *ctx, uint32_t op1, uint32_t op2,gen_load_gpr (v2_t, v2);switch (op1) { -/* OPC_MULT_G_2E is equal OPC_ADDUH_QB_DSP */ -case OPC_MULT_G_2E : +case OPC_ADDUH_QB_DSP :check_dsp_r2 (ctx);switch (op2) {case OPC_ADDUH_QB :@@ -23376,11 +23372,7 @@ static void gen_mipsdsp_multiply(DisasContext *ctx, uint32_t op1, uint32_t op2,gen_load_gpr (v2_t, v2);switch (op1) { -/* -* OPC_MULT_G_2E, OPC_ADDUH_QB_DSP, OPC_MUL_PH_DSP have -* the same mask and op1. -*/ -case OPC_MULT_G_2E : +case OPC_MUL_PH_DSP :check_dsp_r2 (ctx);switch (op2) {case OPC_MUL_PH :@@ -27337,7 +27329,7 @@ static void decode_opc_special3_legacy(CPUMIPSState *env, DisasContext *ctx)* OPC_MULT_G_2E, OPC_ADDUH_QB_DSP, OPC_MUL_PH_DSP have * the same mask and op1. */ -if ((ctx->insn_flags &ASE_DSP_R2 ) && (op1 ==OPC_MULT_G_2E )) { +if ((ctx->insn_flags &ASE_DSP_R2 ) && (op1 ==OPC_MUL_PH_DSP )) { op2 =MASK_ADDUH_QB (ctx->opcode);switch (op2) {case OPC_ADDUH_QB :
Re: [PATCH 1/6] target/mips: Re-introduce OPC_ADDUH_QB_DSP and OPC_MUL_PH_DSP
In reply to Philippe Mathieu-DaudéQuoted 9 lines · Philippe Mathieu-Daudé
There is no issue having multiple enum declarations with the same value. As we are going to remove the
OPC_MULT_G_2Edefinition in few commits, restore theOPC_ADDUH_QB_DSPandOPC_MUL_PH_DSPdefinitions and use them where they belong.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/mips/translate.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-)
r~
PATCH 2/6 target/mips: Convert Loongson DDIV.G opcodes to decodetree
In reply to Philippe Mathieu-DaudéIntroduce decode_loongson() to decode all Loongson vendor specific opcodes. Start converting a single opcode: DDIV.G (divide 64-bit signed integers).
--- target/mips/translate.h | 1 + target/mips/godson2.decode | 16 +++++++ target/mips/loong-ext.decode | 17 +++++++ target/mips/loong_translate.c | 89 +++++++++++++++++++++++++++++++++++ target/mips/translate.c | 28 ++--------- target/mips/meson.build | 3 ++ 6 files changed, 131 insertions(+), 23 deletions(-) create mode 100644 target/mips/godson2.decode create mode 100644 target/mips/loong-ext.decode create mode 100644 target/mips/loong_translate.c
target/mips/translate.h +1 -0
@@ -164,5 +164,6 @@ void msa_translate_init(void);/* decodetree generated */ bool decode_isa_rel6 (DisasContext *ctx,uint32_t insn);bool decode_ase_msa (DisasContext *ctx,uint32_t insn); +bool decode_loongson (DisasContext *ctx,uint32_t insn);#endif
target/mips/godson2.decode new file +16 -0
@@ -0,0 +1,16 @@ +# Godson2 Integer instructions +# +# Copyright (C) 2021 Philippe Mathieu-Daudé +# +# SPDX-License-Identifier: LGPL-2.1-or-later +# +# Reference: +# Godson-2E Software Manual +# (Document Number: godson2e-user-manual-V0.6) +# + +&muldiv rs rt rd + +@rs_rt_rd ...... rs:5 rt:5 rd:5 ..... ...... &muldiv + +DDIV.G 011111 ..... ..... ..... 00000 011110 @rs_rt_rd
target/mips/loong-ext.decode new file +17 -0
@@ -0,0 +1,17 @@ +# Loongson Extension instructions +# +# Copyright (C) 2021 Philippe Mathieu-Daudé +# +# SPDX-License-Identifier: LGPL-2.1-or-later +# +# Reference: +# STLS2F01 User Manual +# Appendix A: new integer instructions +# (Document Number: UM0447) +# + +&muldiv rs rt rd !extern + +@rs_rt_rd ...... rs:5 rt:5 rd:5 ..... ...... &muldiv + +DDIV.G 011100 ..... ..... ..... 00000 010101 @rs_rt_rd
target/mips/loong_translate.c new file +89 -0
89 lines not on this page · raw message
target/mips/translate.c +5 -23
@@ -343,7 +343,6 @@ enum {OPC_MULTU_G_2F =0x12 |OPC_SPECIAL2 ,OPC_DMULTU_G_2F =0x13 |OPC_SPECIAL2 ,OPC_DIV_G_2F =0x14 |OPC_SPECIAL2 , -OPC_DDIV_G_2F =0x15 |OPC_SPECIAL2 ,OPC_DIVU_G_2F =0x16 |OPC_SPECIAL2 ,OPC_DDIVU_G_2F =0x17 |OPC_SPECIAL2 , OPC_MOD_G_2F = 0x1c | OPC_SPECIAL2,
@@ -385,7 +384,6 @@ enum {OPC_DIVU_G_2E =0x1B |OPC_SPECIAL3 ,OPC_DMULT_G_2E =0x1C |OPC_SPECIAL3 ,OPC_DMULTU_G_2E =0x1D |OPC_SPECIAL3 , -OPC_DDIV_G_2E =0x1E |OPC_SPECIAL3 ,OPC_DDIVU_G_2E =0x1F |OPC_SPECIAL3 ,OPC_MOD_G_2E =0x22 |OPC_SPECIAL3 , OPC_MODU_G_2E = 0x23 | OPC_SPECIAL3,
@@ -5108,25 +5106,6 @@ static void gen_loongson_integer(DisasContext *ctx, uint32_t opc,case OPC_DMULTU_G_2F :tcg_gen_mul_tl (cpu_gpr[rd], t0, t1);break ; -case OPC_DDIV_G_2E : -case OPC_DDIV_G_2F : - { -TCGLabel *l1 =gen_new_label (); -TCGLabel *l2 =gen_new_label (); -TCGLabel *l3 =gen_new_label (); -tcg_gen_brcondi_tl (TCG_COND_NE , t1,0 , l1); -tcg_gen_movi_tl (cpu_gpr[rd],0 ); -tcg_gen_br (l3); -gen_set_label (l1); -tcg_gen_brcondi_tl (TCG_COND_NE , t0,-1LL <<63 , l2); -tcg_gen_brcondi_tl (TCG_COND_NE , t1,-1LL , l2); -tcg_gen_mov_tl (cpu_gpr[rd], t0); -tcg_gen_br (l3); -gen_set_label (l2); -tcg_gen_div_tl (cpu_gpr[rd], t0, t1); -gen_set_label (l3); - } -break ;case OPC_DDIVU_G_2E :case OPC_DDIVU_G_2F : {
@@ -27180,7 +27159,6 @@ static void decode_opc_special2_legacy(CPUMIPSState *env, DisasContext *ctx)break ;case OPC_DMULT_G_2F :case OPC_DMULTU_G_2F : -case OPC_DDIV_G_2F :case OPC_DDIVU_G_2F :case OPC_DMOD_G_2F :case OPC_DMODU_G_2F :
@@ -27590,7 +27568,6 @@ static void decode_opc_special3_legacy(CPUMIPSState *env, DisasContext *ctx) }break ;#if defined(TARGET_MIPS64 ) -case OPC_DDIV_G_2E :case OPC_DDIVU_G_2E :case OPC_DMULT_G_2E :case OPC_DMULTU_G_2E :
@@ -28976,6 +28953,11 @@ static void decode_opc(CPUMIPSState *env, DisasContext *ctx)/* Transition to the auto-generated decoder. */ +/* Vendor specific extensions */ +if (decode_loongson (ctx, ctx->opcode)) { +return ; + } +/* ISA extensions */ if (ase_msa_available (env) &&decode_ase_msa (ctx, ctx->opcode)) {return ;
target/mips/meson.build +3 -0
@@ -1,4 +1,6 @@ gen = [ + decodetree.process('godson2.decode', extra_args: ['--static-decode=decode_godson2']), + decodetree.process('loong-ext.decode', extra_args: ['--static-decode=decode_loong_ext']), decodetree.process('mips32r6.decode', extra_args: '--static-decode=decode_mips32r6'), decodetree.process('mips64r6.decode', extra_args: '--static-decode=decode_mips64r6'), decodetree.process('msa32.decode', extra_args: '--static-decode=decode_msa32'),
@@ -15,6 +17,7 @@ 'dsp_helper.c', 'fpu_helper.c', 'lmmi_helper.c', + 'loong_translate.c', 'msa_helper.c', 'msa_translate.c', 'op_helper.c',
Signature · 1 line
2.26.2
Re: [PATCH 2/6] target/mips: Convert Loongson DDIV.G opcodes to decodetree
Quoted 5 lines · Philippe Mathieu-Daudé
Introduce
decode_loongson()to decode all Loongson vendor specific opcodes. Start converting a single opcode: DDIV.G (divide 64-bit signed integers).Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 11 lines
--- target/mips/translate.h | 1 + target/mips/godson2.decode | 16 +++++++ target/mips/loong-ext.decode | 17 +++++++ target/mips/loong_translate.c | 89 +++++++++++++++++++++++++++++++++++ target/mips/translate.c | 28 ++--------- target/mips/meson.build | 3 ++ 6 files changed, 131 insertions(+), 23 deletions(-) create mode 100644 target/mips/godson2.decode create mode 100644 target/mips/loong-ext.decode create mode 100644 target/mips/loong_translate.c
r~
PATCH 3/6 target/mips: Convert Loongson DIV.G opcodes to decodetree
In reply to Philippe Mathieu-DaudéDIV.G and DDIV.G are very similar. Provide gen_lext_DIV_G() a 'is_double' argument so it can generate DIV.G (divide 32-bit signed integers).
With this commit we explicit the template used to generate opcode for 32/64-bit word variants. Next commits will be less verbose by providing both variants at once.
--- target/mips/godson2.decode | 1 + target/mips/loong-ext.decode | 1 + target/mips/loong_translate.c | 28 ++++++++++++++++++++++------ target/mips/translate.c | 26 -------------------------- 4 files changed, 24 insertions(+), 32 deletions(-)
target/mips/godson2.decode +1 -0
@@ -13,4 +13,5 @@ @rs_rt_rd ...... rs:5 rt:5 rd:5 ..... ...... &muldiv +DIV.G 011111 ..... ..... ..... 00000 011010 @rs_rt_rd DDIV.G 011111 ..... ..... ..... 00000 011110 @rs_rt_rd
target/mips/loong-ext.decode +1 -0
@@ -14,4 +14,5 @@ @rs_rt_rd ...... rs:5 rt:5 rd:5 ..... ...... &muldiv +DIV.G 011100 ..... ..... ..... 00000 010100 @rs_rt_rd DDIV.G 011100 ..... ..... ..... 00000 010101 @rs_rt_rd
target/mips/loong_translate.c +22 -6
@@ -27,15 +27,18 @@* into general-purpose registers. */ -static bool gen_lext_DIV_G (DisasContext *s,int rd,int rs,int rt) +static bool gen_lext_DIV_G (DisasContext *s,int rd,int rs,int rt, +bool is_double) {TCGv t0, t1;TCGLabel *l1, *l2, *l3; -if (TARGET_LONG_BITS !=64 ) { -return false; +if (is_double) { +if (TARGET_LONG_BITS !=64 ) { +return false; + } +check_mips_64 (s); } -check_mips_64 (s);if (rd ==0 ) {/* Treat as NOP. */
@@ -51,18 +54,26 @@ static bool gen_lext_DIV_G(DisasContext *s, int rd, int rs, int rt)gen_load_gpr (t0, rs);gen_load_gpr (t1, rt); +if (!is_double) { +tcg_gen_ext32s_tl (t0, t0); +tcg_gen_ext32s_tl (t0, t0); +tcg_gen_ext32s_tl (t1, t1); + }tcg_gen_brcondi_tl (TCG_COND_NE , t1,0 , l1);tcg_gen_movi_tl (cpu_gpr[rd],0 );tcg_gen_br (l3);gen_set_label (l1); -tcg_gen_brcondi_tl (TCG_COND_NE , t0,-1LL <<63 , l2); +tcg_gen_brcondi_tl (TCG_COND_NE , t0, is_double ?-1LL <<63 :INT_MIN , l2);tcg_gen_brcondi_tl (TCG_COND_NE , t1,-1LL , l2);tcg_gen_mov_tl (cpu_gpr[rd], t0);tcg_gen_br (l3);gen_set_label (l2);tcg_gen_div_tl (cpu_gpr[rd], t0, t1); +if (!is_double) { +tcg_gen_ext32s_tl (cpu_gpr[rd], cpu_gpr[rd]); + }gen_set_label (l3);tcg_temp_free (t0);
@@ -71,9 +82,14 @@ static bool gen_lext_DIV_G(DisasContext *s, int rd, int rs, int rt)return true; } +static bool trans_DIV_G (DisasContext *s,arg_muldiv *a) +{ +return gen_lext_DIV_G (s, a->rt, a->rs, a->rd, false); +} +static bool trans_DDIV_G (DisasContext *s,arg_muldiv *a) { -return gen_lext_DIV_G (s, a->rt, a->rs, a->rd); +return gen_lext_DIV_G (s, a->rt, a->rs, a->rd, true); }bool decode_loongson (DisasContext *ctx,uint32_t insn)
target/mips/translate.c +0 -26
@@ -342,7 +342,6 @@ enum {OPC_DMULT_G_2F =0x11 |OPC_SPECIAL2 ,OPC_MULTU_G_2F =0x12 |OPC_SPECIAL2 ,OPC_DMULTU_G_2F =0x13 |OPC_SPECIAL2 , -OPC_DIV_G_2F =0x14 |OPC_SPECIAL2 ,OPC_DIVU_G_2F =0x16 |OPC_SPECIAL2 ,OPC_DDIVU_G_2F =0x17 |OPC_SPECIAL2 , OPC_MOD_G_2F = 0x1c | OPC_SPECIAL2,
@@ -380,7 +379,6 @@ enum {/* Loongson 2E */ OPC_MULT_G_2E =0x18 |OPC_SPECIAL3 ,OPC_MULTU_G_2E =0x19 |OPC_SPECIAL3 , -OPC_DIV_G_2E =0x1A |OPC_SPECIAL3 ,OPC_DIVU_G_2E =0x1B |OPC_SPECIAL3 ,OPC_DMULT_G_2E =0x1C |OPC_SPECIAL3 , OPC_DMULTU_G_2E = 0x1D | OPC_SPECIAL3,
@@ -5023,28 +5021,6 @@ static void gen_loongson_integer(DisasContext *ctx, uint32_t opc,tcg_gen_mul_tl (cpu_gpr[rd], t0, t1);tcg_gen_ext32s_tl (cpu_gpr[rd], cpu_gpr[rd]);break ; -case OPC_DIV_G_2E : -case OPC_DIV_G_2F : - { -TCGLabel *l1 =gen_new_label (); -TCGLabel *l2 =gen_new_label (); -TCGLabel *l3 =gen_new_label (); -tcg_gen_ext32s_tl (t0, t0); -tcg_gen_ext32s_tl (t1, t1); -tcg_gen_brcondi_tl (TCG_COND_NE , t1,0 , l1); -tcg_gen_movi_tl (cpu_gpr[rd],0 ); -tcg_gen_br (l3); -gen_set_label (l1); -tcg_gen_brcondi_tl (TCG_COND_NE , t0,INT_MIN , l2); -tcg_gen_brcondi_tl (TCG_COND_NE , t1,-1 , l2); -tcg_gen_mov_tl (cpu_gpr[rd], t0); -tcg_gen_br (l3); -gen_set_label (l2); -tcg_gen_div_tl (cpu_gpr[rd], t0, t1); -tcg_gen_ext32s_tl (cpu_gpr[rd], cpu_gpr[rd]); -gen_set_label (l3); - } -break ;case OPC_DIVU_G_2E :case OPC_DIVU_G_2F : {
@@ -27124,7 +27100,6 @@ static void decode_opc_special2_legacy(CPUMIPSState *env, DisasContext *ctx)case OPC_MUL :gen_arith (ctx, op1, rd, rs, rt);break ; -case OPC_DIV_G_2F :case OPC_DIVU_G_2F :case OPC_MULT_G_2F :case OPC_MULTU_G_2F :
@@ -27297,7 +27272,6 @@ static void decode_opc_special3_legacy(CPUMIPSState *env, DisasContext *ctx) op1 =MASK_SPECIAL3 (ctx->opcode);switch (op1) { -case OPC_DIV_G_2E :case OPC_DIVU_G_2E :case OPC_MOD_G_2E :case OPC_MODU_G_2E :
Signature · 1 line
2.26.2
Re: [PATCH 3/6] target/mips: Convert Loongson DIV.G opcodes to decodetree
Quoted 16 lines · Philippe Mathieu-Daudé
DIV.G and DDIV.G are very similar. Provide
gen_lext_DIV_G()a 'is_double' argument so it can generate DIV.G (divide 32-bit signed integers).With this commit we explicit the template used to generate opcode for 32/64-bit word variants. Next commits will be less verbose by providing both variants at once.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/mips/godson2.decode | 1 + target/mips/loong-ext.decode | 1 + target/mips/loong_translate.c | 28 ++++++++++++++++++++++------ target/mips/translate.c | 26 -------------------------- 4 files changed, 24 insertions(+), 32 deletions(-)
...
target/mips/loong_translate.c static bool gen_lext_DIV_G(DisasContext *s, int rd, int rs, int rt) · line 59
Quoted 7 lines
target/mips/loong_translate.c +3
-0@@ -51,18 +54,26 @@ static bool gen_lext_DIV_G(DisasContext *s, int rd, int rs, int rt)gen_load_gpr (t0, rs);gen_load_gpr (t1, rt); +if (!is_double) { +tcg_gen_ext32s_tl (t0, t0); +tcg_gen_ext32s_tl (t0, t0);
Oops copy/paste problem...
Quoted 6 lines
target/mips/loong_translate.c +2
-0+tcg_gen_ext32s_tl (t1, t1); + }tcg_gen_brcondi_tl (TCG_COND_NE , t1,0 , l1);tcg_gen_movi_tl (cpu_gpr[rd],0 );tcg_gen_br (l3);gen_set_label (l1);
...
Re: [PATCH 3/6] target/mips: Convert Loongson DIV.G opcodes to decodetree
In reply to Philippe Mathieu-DaudéQuoted 8 lines · Philippe Mathieu-Daudé
DIV.G and DDIV.G are very similar. Provide
gen_lext_DIV_G()a 'is_double' argument so it can generate DIV.G (divide 32-bit signed integers).With this commit we explicit the template used to generate opcode for 32/64-bit word variants. Next commits will be less verbose by providing both variants at once.
Quoted 7 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/mips/godson2.decode | 1 + target/mips/loong-ext.decode | 1 + target/mips/loong_translate.c | 28 ++++++++++++++++++++++------ target/mips/translate.c | 26 -------------------------- 4 files changed, 24 insertions(+), 32 deletions(-)
With the double-extend pasto fixed,
r~
PATCH 4/6 target/mips: Convert Loongson [D]DIVU.G opcodes to decodetree
In reply to Philippe Mathieu-DaudéConvert DIVU.G (divide 32-bit unsigned integers) and DDIVU.G (divide 64-bit unsigned integers) opcodes to decodetree.
--- target/mips/godson2.decode | 2 ++ target/mips/loong-ext.decode | 2 ++ target/mips/loong_translate.c | 55 +++++++++++++++++++++++++++++++++++ target/mips/translate.c | 37 ----------------------- 4 files changed, 59 insertions(+), 37 deletions(-)
target/mips/godson2.decode +2 -0
@@ -14,4 +14,6 @@ @rs_rt_rd ...... rs:5 rt:5 rd:5 ..... ...... &muldiv DIV.G 011111 ..... ..... ..... 00000 011010 @rs_rt_rd +DIVU.G 011111 ..... ..... ..... 00000 011011 @rs_rt_rd DDIV.G 011111 ..... ..... ..... 00000 011110 @rs_rt_rd +DDIVU.G 011111 ..... ..... ..... 00000 011111 @rs_rt_rd
target/mips/loong-ext.decode +2 -0
@@ -16,3 +16,5 @@ DIV.G 011100 ..... ..... ..... 00000 010100 @rs_rt_rd DDIV.G 011100 ..... ..... ..... 00000 010101 @rs_rt_rd +DIVU.G 011100 ..... ..... ..... 00000 010110 @rs_rt_rd +DDIVU.G 011100 ..... ..... ..... 00000 010111 @rs_rt_rd
target/mips/loong_translate.c +55 -0
61 lines not on this page · raw message
target/mips/translate.c +0 -37
@@ -342,8 +342,6 @@ enum {OPC_DMULT_G_2F =0x11 |OPC_SPECIAL2 ,OPC_MULTU_G_2F =0x12 |OPC_SPECIAL2 ,OPC_DMULTU_G_2F =0x13 |OPC_SPECIAL2 , -OPC_DIVU_G_2F =0x16 |OPC_SPECIAL2 , -OPC_DDIVU_G_2F =0x17 |OPC_SPECIAL2 ,OPC_MOD_G_2F =0x1c |OPC_SPECIAL2 ,OPC_DMOD_G_2F =0x1d |OPC_SPECIAL2 , OPC_MODU_G_2F = 0x1e | OPC_SPECIAL2,
@@ -379,10 +377,8 @@ enum {/* Loongson 2E */ OPC_MULT_G_2E =0x18 |OPC_SPECIAL3 ,OPC_MULTU_G_2E =0x19 |OPC_SPECIAL3 , -OPC_DIVU_G_2E =0x1B |OPC_SPECIAL3 ,OPC_DMULT_G_2E =0x1C |OPC_SPECIAL3 ,OPC_DMULTU_G_2E =0x1D |OPC_SPECIAL3 , -OPC_DDIVU_G_2E =0x1F |OPC_SPECIAL3 ,OPC_MOD_G_2E =0x22 |OPC_SPECIAL3 ,OPC_MODU_G_2E =0x23 |OPC_SPECIAL3 , OPC_DMOD_G_2E = 0x26 | OPC_SPECIAL3,
@@ -5021,22 +5017,6 @@ static void gen_loongson_integer(DisasContext *ctx, uint32_t opc,tcg_gen_mul_tl (cpu_gpr[rd], t0, t1);tcg_gen_ext32s_tl (cpu_gpr[rd], cpu_gpr[rd]);break ; -case OPC_DIVU_G_2E : -case OPC_DIVU_G_2F : - { -TCGLabel *l1 =gen_new_label (); -TCGLabel *l2 =gen_new_label (); -tcg_gen_ext32u_tl (t0, t0); -tcg_gen_ext32u_tl (t1, t1); -tcg_gen_brcondi_tl (TCG_COND_NE , t1,0 , l1); -tcg_gen_movi_tl (cpu_gpr[rd],0 ); -tcg_gen_br (l2); -gen_set_label (l1); -tcg_gen_divu_tl (cpu_gpr[rd], t0, t1); -tcg_gen_ext32s_tl (cpu_gpr[rd], cpu_gpr[rd]); -gen_set_label (l2); - } -break ;case OPC_MOD_G_2E :case OPC_MOD_G_2F : {
@@ -5082,19 +5062,6 @@ static void gen_loongson_integer(DisasContext *ctx, uint32_t opc,case OPC_DMULTU_G_2F :tcg_gen_mul_tl (cpu_gpr[rd], t0, t1);break ; -case OPC_DDIVU_G_2E : -case OPC_DDIVU_G_2F : - { -TCGLabel *l1 =gen_new_label (); -TCGLabel *l2 =gen_new_label (); -tcg_gen_brcondi_tl (TCG_COND_NE , t1,0 , l1); -tcg_gen_movi_tl (cpu_gpr[rd],0 ); -tcg_gen_br (l2); -gen_set_label (l1); -tcg_gen_divu_tl (cpu_gpr[rd], t0, t1); -gen_set_label (l2); - } -break ;case OPC_DMOD_G_2E :case OPC_DMOD_G_2F : {
@@ -27100,7 +27067,6 @@ static void decode_opc_special2_legacy(CPUMIPSState *env, DisasContext *ctx)case OPC_MUL :gen_arith (ctx, op1, rd, rs, rt);break ; -case OPC_DIVU_G_2F :case OPC_MULT_G_2F :case OPC_MULTU_G_2F :case OPC_MOD_G_2F :
@@ -27134,7 +27100,6 @@ static void decode_opc_special2_legacy(CPUMIPSState *env, DisasContext *ctx)break ;case OPC_DMULT_G_2F :case OPC_DMULTU_G_2F : -case OPC_DDIVU_G_2F :case OPC_DMOD_G_2F :case OPC_DMODU_G_2F :check_insn (ctx,INSN_LOONGSON2F |ASE_LEXT );
@@ -27272,7 +27237,6 @@ static void decode_opc_special3_legacy(CPUMIPSState *env, DisasContext *ctx) op1 =MASK_SPECIAL3 (ctx->opcode);switch (op1) { -case OPC_DIVU_G_2E :case OPC_MOD_G_2E :case OPC_MODU_G_2E :case OPC_MULT_G_2E :
@@ -27542,7 +27506,6 @@ static void decode_opc_special3_legacy(CPUMIPSState *env, DisasContext *ctx) }break ;#if defined(TARGET_MIPS64 ) -case OPC_DDIVU_G_2E :case OPC_DMULT_G_2E :case OPC_DMULTU_G_2E :case OPC_DMOD_G_2E :
Signature · 1 line
2.26.2
Re: [PATCH 4/6] target/mips: Convert Loongson [D]DIVU.G opcodes to decodetree
Quoted 67 lines · Philippe Mathieu-Daudé
Convert DIVU.G (divide 32-bit unsigned integers) and DDIVU.G (divide 64-bit unsigned integers) opcodes to decodetree.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/mips/godson2.decode | 2 ++ target/mips/loong-ext.decode | 2 ++ target/mips/loong_translate.c | 55 +++++++++++++++++++++++++++++++++++ target/mips/translate.c | 37 ----------------------- 4 files changed, 59 insertions(+), 37 deletions(-)target/mips/godson2.decode +2
-0@@ -14,4 +14,6 @@ @rs_rt_rd ...... rs:5 rt:5 rd:5 ..... ...... &muldiv DIV.G 011111 ..... ..... ..... 00000 011010 @rs_rt_rd +DIVU.G 011111 ..... ..... ..... 00000 011011 @rs_rt_rd DDIV.G 011111 ..... ..... ..... 00000 011110 @rs_rt_rd +DDIVU.G 011111 ..... ..... ..... 00000 011111 @rs_rt_rdtarget/mips/loong-ext.decode +2
-0@@ -16,3 +16,5 @@ DIV.G 011100 ..... ..... ..... 00000 010100 @rs_rt_rd DDIV.G 011100 ..... ..... ..... 00000 010101 @rs_rt_rd +DIVU.G 011100 ..... ..... ..... 00000 010110 @rs_rt_rd +DDIVU.G 011100 ..... ..... ..... 00000 010111 @rs_rt_rdtarget/mips/loong_translate.c +27
-0@@ -92,6 +92,61 @@ static bool trans_DDIV_G(DisasContext *s, arg_muldiv *a)return gen_lext_DIV_G (s, a->rt, a->rs, a->rd, true); } +static bool gen_lext_DIVU_G (DisasContext *s,int rd,int rs,int rt, +bool is_double) +{ +TCGv t0, t1; +TCGLabel *l1, *l2; + +if (is_double) { +if (TARGET_LONG_BITS !=64 ) { +return false; + } +check_mips_64 (s); + } + +if (rd ==0 ) { +/* Treat as NOP. */ +return true; + } + + t0 =tcg_temp_local_new (); + t1 =tcg_temp_local_new (); + l1 =gen_new_label (); + l2 =gen_new_label (); + +gen_load_gpr (t0, rs); +gen_load_gpr (t1, rt); + +if (!is_double) {
target/mips/loong_translate.c static bool trans_DDIV_G(DisasContext *s, arg_muldiv *a) · line 131
Quoted 10 lines
target/mips/loong_translate.c +10
-0+tcg_gen_ext32u_tl (t0, t0); +tcg_gen_ext32u_tl (t1, t1); + } +tcg_gen_brcondi_tl (TCG_COND_NE , t1,0 , l1); +tcg_gen_movi_tl (cpu_gpr[rd],0 ); + +tcg_gen_br (l2); +gen_set_label (l1); +tcg_gen_divu_tl (cpu_gpr[rd], t0, t1); +tcg_gen_ext32s_tl (cpu_gpr[rd], cpu_gpr[rd]);
this extend should be conditional on !is_double.
Otherwise,
r~
Re: [PATCH 4/6] target/mips: Convert Loongson [D]DIVU.G opcodes to decodetree
Quoted 43 lines · Richard Henderson
Quoted 42 lines · Philippe Mathieu-Daudé
Convert DIVU.G (divide 32-bit unsigned integers) and DDIVU.G (divide 64-bit unsigned integers) opcodes to decodetree.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/mips/godson2.decode | 2 ++ target/mips/loong-ext.decode | 2 ++ target/mips/loong_translate.c | 55 +++++++++++++++++++++++++++++++++++ target/mips/translate.c | 37 ----------------------- 4 files changed, 59 insertions(+), 37 deletions(-)target/mips/loong_translate.c +31
-0+static bool gen_lext_DIVU_G (DisasContext *s,int rd,int rs,int rt, +bool is_double) +{ +TCGv t0, t1; +TCGLabel *l1, *l2; + +if (is_double) { +if (TARGET_LONG_BITS !=64 ) { +return false; + } +check_mips_64 (s); + } + +if (rd ==0 ) { +/* Treat as NOP. */ +return true; + } + + t0 =tcg_temp_local_new (); + t1 =tcg_temp_local_new (); + l1 =gen_new_label (); + l2 =gen_new_label (); + +gen_load_gpr (t0, rs); +gen_load_gpr (t1, rt); + +if (!is_double) { +tcg_gen_ext32u_tl (t0, t0); +tcg_gen_ext32u_tl (t1, t1); + } +tcg_gen_brcondi_tl (TCG_COND_NE , t1,0 , l1);
Quoted 8 lines
target/mips/loong_translate.c static bool trans_DDIV_G(DisasContext *s, arg_muldiv *a) · line 131
Quoted 6 lines
target/mips/loong_translate.c +6
-0+tcg_gen_movi_tl (cpu_gpr[rd],0 ); + +tcg_gen_br (l2); +gen_set_label (l1); +tcg_gen_divu_tl (cpu_gpr[rd], t0, t1); +tcg_gen_ext32s_tl (cpu_gpr[rd], cpu_gpr[rd]);this extend should be conditional on !is_double.
Oops, thanks!
Quoted 6 lines
Otherwise,
Reviewed-by Richard Henderson <[email protected]>r~
PATCH 5/6 target/mips: Convert Loongson [D]MOD[U].G opcodes to decodetree
In reply to Philippe Mathieu-DaudéConvert the following opcodes to decodetree:
- MOD.G - mod 32-bit signed integers
- MODU.G - mod 32-bit unsigned integers
- DMOD.G - mod 64-bit signed integers
- DMODU.G - mod 64-bit unsigned integers
--- target/mips/godson2.decode | 5 ++ target/mips/loong-ext.decode | 5 ++ target/mips/loong_translate.c | 116 ++++++++++++++++++++++++++++++++++ target/mips/translate.c | 86 ------------------------- 4 files changed, 126 insertions(+), 86 deletions(-)
target/mips/godson2.decode +5 -0
@@ -17,3 +17,8 @@ DIV.G 011111 ..... ..... ..... 00000 011010 @rs_rt_rd DIVU.G 011111 ..... ..... ..... 00000 011011 @rs_rt_rd DDIV.G 011111 ..... ..... ..... 00000 011110 @rs_rt_rd DDIVU.G 011111 ..... ..... ..... 00000 011111 @rs_rt_rd + +MOD.G 011111 ..... ..... ..... 00000 100010 @rs_rt_rd +MODU.G 011111 ..... ..... ..... 00000 100011 @rs_rt_rd +DMOD.G 011111 ..... ..... ..... 00000 100110 @rs_rt_rd +DMODU.G 011111 ..... ..... ..... 00000 100111 @rs_rt_rd
target/mips/loong-ext.decode +5 -0
@@ -18,3 +18,8 @@ DIV.G 011100 ..... ..... ..... 00000 010100 @rs_rt_rd DDIV.G 011100 ..... ..... ..... 00000 010101 @rs_rt_rd DIVU.G 011100 ..... ..... ..... 00000 010110 @rs_rt_rd DDIVU.G 011100 ..... ..... ..... 00000 010111 @rs_rt_rd + +MOD.G 011100 ..... ..... ..... 00000 011100 @rs_rt_rd +DMOD.G 011100 ..... ..... ..... 00000 011101 @rs_rt_rd +MODU.G 011100 ..... ..... ..... 00000 011110 @rs_rt_rd +DMODU.G 011100 ..... ..... ..... 00000 011111 @rs_rt_rd
target/mips/loong_translate.c +116 -0
122 lines not on this page · raw message
target/mips/translate.c +0 -86
140 lines not on this page · raw message
Signature · 1 line
2.26.2
Re: [PATCH 5/6] target/mips: Convert Loongson [D]MOD[U].G opcodes to decodetree
Quoted 7 lines · Philippe Mathieu-Daudé
Convert the following opcodes to decodetree:
- MOD.G - mod 32-bit signed integers
- MODU.G - mod 32-bit unsigned integers
- DMOD.G - mod 64-bit signed integers
- DMODU.G - mod 64-bit unsigned integers
Quoted 7 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/mips/godson2.decode | 5 ++ target/mips/loong-ext.decode | 5 ++ target/mips/loong_translate.c | 116 ++++++++++++++++++++++++++++++++++ target/mips/translate.c | 86 ------------------------- 4 files changed, 126 insertions(+), 86 deletions(-)
r~
PATCH 6/6 target/mips: Convert Loongson [D]MULT[U].G opcodes to decodetree
In reply to Philippe Mathieu-DaudéConvert the following opcodes to decodetree:
- MULT.G - multiply 32-bit signed integers
- MULTU.G - multiply 32-bit unsigned integers
- DMULT.G - multiply 64-bit signed integers
- DMULTU.G - multiply 64-bit unsigned integers
Now that all opcodes from the extension have been converted, we can remove completely gen_loongson_integer() and its 2 calls in decode_opc_special2_legacy() and decode_opc_special3_legacy().
--- target/mips/godson2.decode | 5 ++ target/mips/loong-ext.decode | 5 ++ target/mips/loong_translate.c | 58 ++++++++++++++++++++++ target/mips/translate.c | 92 +---------------------------------- 4 files changed, 70 insertions(+), 90 deletions(-)
target/mips/godson2.decode +5 -0
@@ -13,6 +13,11 @@ @rs_rt_rd ...... rs:5 rt:5 rd:5 ..... ...... &muldiv +MULT.G 011111 ..... ..... ..... 00000 011000 @rs_rt_rd +MULTU.G 011111 ..... ..... ..... 00000 011001 @rs_rt_rd +DMULT.G 011111 ..... ..... ..... 00000 011100 @rs_rt_rd +DMULTU.G 011111 ..... ..... ..... 00000 011101 @rs_rt_rd + DIV.G 011111 ..... ..... ..... 00000 011010 @rs_rt_rd DIVU.G 011111 ..... ..... ..... 00000 011011 @rs_rt_rd DDIV.G 011111 ..... ..... ..... 00000 011110 @rs_rt_rd
target/mips/loong-ext.decode +5 -0
@@ -14,6 +14,11 @@ @rs_rt_rd ...... rs:5 rt:5 rd:5 ..... ...... &muldiv +MULT.G 011100 ..... ..... ..... 00000 010000 @rs_rt_rd +DMULT.G 011100 ..... ..... ..... 00000 010001 @rs_rt_rd +MULTU.G 011100 ..... ..... ..... 00000 010010 @rs_rt_rd +DMULTU.G 011100 ..... ..... ..... 00000 010011 @rs_rt_rd + DIV.G 011100 ..... ..... ..... 00000 010100 @rs_rt_rd DDIV.G 011100 ..... ..... ..... 00000 010101 @rs_rt_rd DIVU.G 011100 ..... ..... ..... 00000 010110 @rs_rt_rd
target/mips/loong_translate.c +58 -0
64 lines not on this page · raw message
target/mips/translate.c +2 -90
141 lines not on this page · raw message
Signature · 1 line
2.26.2
Re: [PATCH 6/6] target/mips: Convert Loongson [D]MULT[U].G opcodes to decodetree
Quoted 76 lines · Philippe Mathieu-Daudé
Convert the following opcodes to decodetree:
- MULT.G - multiply 32-bit signed integers
- MULTU.G - multiply 32-bit unsigned integers
- DMULT.G - multiply 64-bit signed integers
- DMULTU.G - multiply 64-bit unsigned integersNow that all opcodes from the extension have been converted, we can remove completely
gen_loongson_integer()and its 2 calls indecode_opc_special2_legacy()anddecode_opc_special3_legacy().Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/mips/godson2.decode | 5 ++ target/mips/loong-ext.decode | 5 ++ target/mips/loong_translate.c | 58 ++++++++++++++++++++++ target/mips/translate.c | 92 +---------------------------------- 4 files changed, 70 insertions(+), 90 deletions(-)target/mips/godson2.decode +5
-0@@ -13,6 +13,11 @@ @rs_rt_rd ...... rs:5 rt:5 rd:5 ..... ...... &muldiv +MULT.G 011111 ..... ..... ..... 00000 011000 @rs_rt_rd +MULTU.G 011111 ..... ..... ..... 00000 011001 @rs_rt_rd +DMULT.G 011111 ..... ..... ..... 00000 011100 @rs_rt_rd +DMULTU.G 011111 ..... ..... ..... 00000 011101 @rs_rt_rd + DIV.G 011111 ..... ..... ..... 00000 011010 @rs_rt_rd DIVU.G 011111 ..... ..... ..... 00000 011011 @rs_rt_rd DDIV.G 011111 ..... ..... ..... 00000 011110 @rs_rt_rdtarget/mips/loong-ext.decode +5
-0@@ -14,6 +14,11 @@ @rs_rt_rd ...... rs:5 rt:5 rd:5 ..... ...... &muldiv +MULT.G 011100 ..... ..... ..... 00000 010000 @rs_rt_rd +DMULT.G 011100 ..... ..... ..... 00000 010001 @rs_rt_rd +MULTU.G 011100 ..... ..... ..... 00000 010010 @rs_rt_rd +DMULTU.G 011100 ..... ..... ..... 00000 010011 @rs_rt_rd + DIV.G 011100 ..... ..... ..... 00000 010100 @rs_rt_rd DDIV.G 011100 ..... ..... ..... 00000 010101 @rs_rt_rd DIVU.G 011100 ..... ..... ..... 00000 010110 @rs_rt_rdtarget/mips/loong_translate.c +17
-0@@ -263,6 +263,64 @@ static bool trans_DMODU_G(DisasContext *s, arg_muldiv *a)return gen_lext_MODU_G (s, a->rt, a->rs, a->rd, true); } +static bool gen_lext_MULT_G (DisasContext *s,int rd,int rs,int rt, +bool is_double,bool is_unsigned) +{ +TCGv t0, t1; + +if (is_double) { +if (TARGET_LONG_BITS !=64 ) { +return false; + } +check_mips_64 (s); + } + +if (rd ==0 ) { +/* Treat as NOP. */ +return true; + } +
target/mips/loong_translate.c static bool trans_DMODU_G(DisasContext *s, arg_muldiv *a) · line 292
Quoted 10 lines
target/mips/loong_translate.c +10
-0+ t0 =tcg_temp_new (); + t1 =tcg_temp_new (); + +gen_load_gpr (t0, rs); +gen_load_gpr (t1, rt); + +if (is_unsigned && !is_double) { +tcg_gen_ext32u_tl (t0, t0); +tcg_gen_ext32u_tl (t1, t1); + }
While this is a faithful conversion of the existing code, these extensions make no difference to the result. They are redundant with
target/mips/loong_translate.c static bool trans_DMODU_G(DisasContext *s, arg_muldiv *a) · line 295
Quoted 3 lines
target/mips/loong_translate.c +3
-0+tcg_gen_mul_tl (cpu_gpr[rd], t0, t1); +if (!is_double) { +tcg_gen_ext32s_tl (cpu_gpr[rd], cpu_gpr[rd]);
this one, which discards any bit that might have been set by the input bits that are cleared.
There is no actual difference between MULT.G and MULTU.G, or DMULT.G and DMULTU.G, because they don't record the most significant bits of the infinite result in any way.
Quoted 9 lines
target/mips/loong_translate.c +9
-0+static bool trans_MULT_G (DisasContext *s,arg_muldiv *a) +{ +return gen_lext_MULT_G (s, a->rt, a->rs, a->rd, false, false); +} + +static bool trans_MULTU_G (DisasContext *s,arg_muldiv *a) +{ +return gen_lext_MULT_G (s, a->rt, a->rs, a->rd, false, true); +}
target/mips/loong_translate.c static bool trans_DMODU_G(DisasContext *s, arg_muldiv *a) · line 322
Quoted 10 lines
target/mips/loong_translate.c +10
-0+ +static bool trans_DMULT_G (DisasContext *s,arg_muldiv *a) +{ +return gen_lext_MULT_G (s, a->rt, a->rs, a->rd, true, false); +} + +static bool trans_DMULTU_G (DisasContext *s,arg_muldiv *a) +{ +return gen_lext_MULT_G (s, a->rt, a->rs, a->rd, true, true); +}
So... if you want to clean this up afterward, or before is up to you.
r~
Re: [PATCH 6/6] target/mips: Convert Loongson [D]MULT[U].G opcodes to decodetree
Quoted 91 lines · Richard Henderson
Quoted 76 lines · Philippe Mathieu-Daudé
Convert the following opcodes to decodetree:
- MULT.G - multiply 32-bit signed integers
- MULTU.G - multiply 32-bit unsigned integers
- DMULT.G - multiply 64-bit signed integers
- DMULTU.G - multiply 64-bit unsigned integersNow that all opcodes from the extension have been converted, we can remove completely
gen_loongson_integer()and its 2 calls indecode_opc_special2_legacy()anddecode_opc_special3_legacy().Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/mips/godson2.decode | 5 ++ target/mips/loong-ext.decode | 5 ++ target/mips/loong_translate.c | 58 ++++++++++++++++++++++ target/mips/translate.c | 92 +---------------------------------- 4 files changed, 70 insertions(+), 90 deletions(-)target/mips/godson2.decode +5
-0@@ -13,6 +13,11 @@ @rs_rt_rd ...... rs:5 rt:5 rd:5 ..... ...... &muldiv +MULT.G 011111 ..... ..... ..... 00000 011000 @rs_rt_rd +MULTU.G 011111 ..... ..... ..... 00000 011001 @rs_rt_rd +DMULT.G 011111 ..... ..... ..... 00000 011100 @rs_rt_rd +DMULTU.G 011111 ..... ..... ..... 00000 011101 @rs_rt_rd + DIV.G 011111 ..... ..... ..... 00000 011010 @rs_rt_rd DIVU.G 011111 ..... ..... ..... 00000 011011 @rs_rt_rd DDIV.G 011111 ..... ..... ..... 00000 011110 @rs_rt_rdtarget/mips/loong-ext.decode +5
-0@@ -14,6 +14,11 @@ @rs_rt_rd ...... rs:5 rt:5 rd:5 ..... ...... &muldiv +MULT.G 011100 ..... ..... ..... 00000 010000 @rs_rt_rd +DMULT.G 011100 ..... ..... ..... 00000 010001 @rs_rt_rd +MULTU.G 011100 ..... ..... ..... 00000 010010 @rs_rt_rd +DMULTU.G 011100 ..... ..... ..... 00000 010011 @rs_rt_rd + DIV.G 011100 ..... ..... ..... 00000 010100 @rs_rt_rd DDIV.G 011100 ..... ..... ..... 00000 010101 @rs_rt_rd DIVU.G 011100 ..... ..... ..... 00000 010110 @rs_rt_rdtarget/mips/loong_translate.c +17
-0@@ -263,6 +263,64 @@ static bool trans_DMODU_G(DisasContext *s, arg_muldiv *a)return gen_lext_MODU_G (s, a->rt, a->rs, a->rd, true); } +static bool gen_lext_MULT_G (DisasContext *s,int rd,int rs,int rt, +bool is_double,bool is_unsigned) +{ +TCGv t0, t1; + +if (is_double) { +if (TARGET_LONG_BITS !=64 ) { +return false; + } +check_mips_64 (s); + } + +if (rd ==0 ) { +/* Treat as NOP. */ +return true; + } +target/mips/loong_translate.c static bool trans_DMODU_G(DisasContext *s, arg_muldiv *a) · line 292
Quoted 10 lines
target/mips/loong_translate.c +10
-0+ t0 =tcg_temp_new (); + t1 =tcg_temp_new (); + +gen_load_gpr (t0, rs); +gen_load_gpr (t1, rt); + +if (is_unsigned && !is_double) { +tcg_gen_ext32u_tl (t0, t0); +tcg_gen_ext32u_tl (t1, t1); + }While this is a faithful conversion of the existing code, these extensions make no difference to the result. They are redundant with
Quoted 6 lines
target/mips/loong_translate.c static bool trans_DMODU_G(DisasContext *s, arg_muldiv *a) · line 295
Quoted 3 lines
target/mips/loong_translate.c +3
-0+tcg_gen_mul_tl (cpu_gpr[rd], t0, t1); +if (!is_double) { +tcg_gen_ext32s_tl (cpu_gpr[rd], cpu_gpr[rd]);this one, which discards any bit that might have been set by the input bits that are cleared.
I see.
Quoted 3 lines
There is no actual difference between MULT.G and MULTU.G, or DMULT.G and DMULTU.G, because they don't record the most significant bits of the infinite result in any way.
Right.
Quoted 13 lines
Quoted 13 lines
target/mips/loong_translate.c +13
-0+static bool trans_MULT_G (DisasContext *s,arg_muldiv *a) +{ +return gen_lext_MULT_G (s, a->rt, a->rs, a->rd, false, false); +} + +static bool trans_MULTU_G (DisasContext *s,arg_muldiv *a) +{ +return gen_lext_MULT_G (s, a->rt, a->rs, a->rd, false, true); +} + +static bool trans_DMULT_G (DisasContext *s,arg_muldiv *a) +{ +return gen_lext_MULT_G (s, a->rt, a->rs, a->rd, true, false);
Quoted 8 lines
target/mips/loong_translate.c static bool trans_DMODU_G(DisasContext *s, arg_muldiv *a) · line 314
Quoted 6 lines
target/mips/loong_translate.c +6
-0+} + +static bool trans_DMULTU_G (DisasContext *s,arg_muldiv *a) +{ +return gen_lext_MULT_G (s, a->rt, a->rs, a->rd, true, true); +}So... if you want to clean this up afterward, or before is up to you.
IIUC you are suggesting this simplification:
-- >8 --
target/mips/tcg/godson2.decode +2 -4
@@ -15,6 +15,4 @@ -MULT_G 011111 ..... ..... ..... 00000 011000 @rs_rt_rd -MULTU_G 011111 ..... ..... ..... 00000 011001 @rs_rt_rd -DMULT_G 011111 ..... ..... ..... 00000 011100 @rs_rt_rd -DMULTU_G 011111 ..... ..... ..... 00000 011101 @rs_rt_rd +MULTu_G 011111 ..... ..... ..... 00000 01100- @rs_rt_rd +DMULTu_G 011111 ..... ..... ..... 00000 01110- @rs_rt_rd
target/mips/tcg/loong-ext.decode +2 -4
@@ -16,6 +16,4 @@ -MULT_G 011100 ..... ..... ..... 00000 010000 @rs_rt_rd -DMULT_G 011100 ..... ..... ..... 00000 010001 @rs_rt_rd -MULTU_G 011100 ..... ..... ..... 00000 010010 @rs_rt_rd -DMULTU_G 011100 ..... ..... ..... 00000 010011 @rs_rt_rd +MULTu_G 011100 ..... ..... ..... 00000 0100-0 @rs_rt_rd +DMULTu_G 011100 ..... ..... ..... 00000 0100-1 @rs_rt_rd
target/mips/tcg/loong_translate.c +5 -19
@@ -253,3 +253,3 @@ static bool trans_DMODU_G(DisasContext *s, arg_muldiv *a)static bool gen_lext_MULT_G (DisasContext *s,int rd,int rs,int rt, -bool is_double,bool is_unsigned) +bool is_double) {
@@ -275,6 +275,2 @@ static bool gen_lext_MULT_G(DisasContext *s, int rd, int rs, int rt, -if (is_unsigned && !is_double) { -tcg_gen_ext32u_tl (t0, t0); -tcg_gen_ext32u_tl (t1, t1); - }tcg_gen_mul_tl (cpu_gpr[rd], t0, t1);
@@ -287,20 +283,10 @@ static bool gen_lext_MULT_G(DisasContext *s, int rd, int rs, int rt, -static bool trans_MULT_G (DisasContext *s,arg_muldiv *a) +static bool trans_MULTu_G (DisasContext *s,arg_muldiv *a) { -return gen_lext_MULT_G (s, a->rt, a->rs, a->rd, false, false); +return gen_lext_MULT_G (s, a->rt, a->rs, a->rd, false); } -static bool trans_MULTU_G (DisasContext *s,arg_muldiv *a) +static bool trans_DMULTu_G (DisasContext *s,arg_muldiv *a) { -return gen_lext_MULT_G (s, a->rt, a->rs, a->rd, false, true); -} - -static bool trans_DMULT_G (DisasContext *s,arg_muldiv *a) -{ -return gen_lext_MULT_G (s, a->rt, a->rs, a->rd, true, false); -} - -static bool trans_DMULTU_G (DisasContext *s,arg_muldiv *a) -{ -return gen_lext_MULT_G (s, a->rt, a->rs, a->rd, true, true); +return gen_lext_MULT_G (s, a->rt, a->rs, a->rd, true); }
---
Is that correct?
Re: [PATCH 6/6] target/mips: Convert Loongson [D]MULT[U].G opcodes to decodetree
Quoted 60 lines · Philippe Mathieu-Daudé
Quoted 52 lines · Richard Henderson
Quoted 37 lines · Philippe Mathieu-Daudé
Convert the following opcodes to decodetree:
- MULT.G - multiply 32-bit signed integers
- MULTU.G - multiply 32-bit unsigned integers
- DMULT.G - multiply 64-bit signed integers
- DMULTU.G - multiply 64-bit unsigned integersNow that all opcodes from the extension have been converted, we can remove completely
gen_loongson_integer()and its 2 calls indecode_opc_special2_legacy()anddecode_opc_special3_legacy().Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
target/mips/godson2.decode | 5 ++ target/mips/loong-ext.decode | 5 ++target/mips/loong_translate.c| 58 ++++++++++++++++++++++ target/mips/translate.c | 92 +----------------------------------4 files changed, 70 insertions(+), 90 deletions(-)(quoted diff) +17
-0+static bool gen_lext_MULT_G(DisasContext *s, int rd, int rs, int rt, + bool is_double, bool is_unsigned) +{ + TCGv t0, t1; + + if (is_double) { + if (TARGET_LONG_BITS != 64) { + return false; + } + check_mips_64(s); + } + + if (rd == 0) { + /* Treat as NOP. */ + return true; + } +Review
Quoted 10 lines
(quoted diff) +10
-0+ t0 = tcg_temp_new(); + t1 = tcg_temp_new(); + + gen_load_gpr(t0, rs); + gen_load_gpr(t1, rt); + + if (is_unsigned && !is_double) { + tcg_gen_ext32u_tl(t0, t0); + tcg_gen_ext32u_tl(t1, t1); + }While this is a faithful conversion of the existing code, these extensions make no difference to the result. They are redundant with
Quoted 6 lines
Quoted 3 lines
+
tcg_gen_mul_tl(cpu_gpr[rd], t0, t1);
+ if (!is_double) {
+tcg_gen_ext32s_tl(cpu_gpr[rd], cpu_gpr[rd]);this one, which discards any bit that might have been set by the input bits that are cleared.
Quoted 29 lines
I see.
Quoted 3 lines
There is no actual difference between MULT.G and MULTU.G, or DMULT.G and DMULTU.G, because they don't record the most significant bits of the infinite result in any way.
Right.
Quoted 21 lines
Quoted 9 lines
(quoted diff) +9
-0+static bool trans_MULT_G(DisasContext *s, arg_muldiv *a) +{ + return gen_lext_MULT_G(s, a->rt, a->rs, a->rd, false, false); +} + +static bool trans_MULTU_G(DisasContext *s, arg_muldiv *a) +{ + return gen_lext_MULT_G(s, a->rt, a->rs, a->rd, false, true); +}Review
Quoted 10 lines
(quoted diff) +10
-0+ +static bool trans_DMULT_G(DisasContext *s, arg_muldiv *a) +{ + return gen_lext_MULT_G(s, a->rt, a->rs, a->rd, true, false); +} + +static bool trans_DMULTU_G(DisasContext *s, arg_muldiv *a) +{ + return gen_lext_MULT_G(s, a->rt, a->rs, a->rd, true, true); +}So... if you want to clean this up afterward, or before is up to you.
"before" ended being way simpler :>
Quoted 23 lines · Philippe Mathieu-Daudé
Loongson is next step in the "MIPS decodetree conversion" epic. Start with the simplest extension.
The diffstat addition comes from the TCG functions expanded. The code is easier to review now.
IMO this is also a good template to show how easy a decodetree conversion can be (and how nice the .decode file is to review) :PPlease review,
Phil.
Based-on: <[email protected]>
"decodetree: Allow 'dot' in opcode names"Philippe Mathieu-Daudé (6):
target/mips: Re-introduceOPC_ADDUH_QB_DSPandOPC_MUL_PH_DSPtarget/mips: Convert Loongson DDIV.G opcodes to decodetree target/mips: Convert Loongson DIV.G opcodes to decodetree target/mips: Convert Loongson [D]DIVU.G opcodes to decodetree target/mips: Convert Loongson [D]MOD[U].G opcodes to decodetree target/mips: Convert Loongson [D]MULT[U].G opcodes to decodetree
Quoted 3 lines
target/mips/translate.h | 1 + target/mips/godson2.decode | 29 +++ target/mips/loong-ext.decode | 30 +++
Hi Philippe,
Thanks for the template!
Just a small question, where should we perform ISA availability check? Before calling generated decoder or after decoded?
Loong-EXT is a super set of Loongson2F's Godson2 and MMI instructions, how could we tell it?
Thanks.
- Jiaxun
Quoted 8 lines
target/mips/loong_translate.c | 334 ++++++++++++++++++++++++++++++++++ target/mips/translate.c | 287 ++--------------------------- target/mips/meson.build | 3 + 6 files changed, 409 insertions(+), 275 deletions(-)create mode 100644 target/mips/godson2.decode create mode 100644 target/mips/loong-ext.decode create mode 100644
target/mips/loong_translate.c
Quoted 28 lines · Jiaxun Yang
Quoted 23 lines · Philippe Mathieu-Daudé
Loongson is next step in the "MIPS decodetree conversion" epic. Start with the simplest extension.
The diffstat addition comes from the TCG functions expanded. The code is easier to review now.
IMO this is also a good template to show how easy a decodetree conversion can be (and how nice the .decode file is to review) :PPlease review,
Phil.
Based-on: <[email protected]> "decodetree: Allow 'dot' in opcode names"
Philippe Mathieu-Daudé (6):
target/mips: Re-introduceOPC_ADDUH_QB_DSPandOPC_MUL_PH_DSPtarget/mips: Convert Loongson DDIV.G opcodes to decodetree target/mips: Convert Loongson DIV.G opcodes to decodetree target/mips: Convert Loongson [D]DIVU.G opcodes to decodetree target/mips: Convert Loongson [D]MOD[U].G opcodes to decodetree target/mips: Convert Loongson [D]MULT[U].G opcodes to decodetreeQuoted 3 lines
target/mips/translate.h | 1 +
target/mips/godson2.decode | 29 +++
target/mips/loong-ext.decode | 30 +++
Quoted 6 lines
Hi Philippe,
Thanks for the template!
Just a small question, where should we perform ISA availability check? Before calling generated decoder or after decoded?
The check is done before in decode_loongson:
bool decode_loongson(DisasContext *ctx, uint32_t insn)
{
if ((ctx->insn_flags & INSN_LOONGSON2E)
// if ISA available ...
&& decode_godson2(ctx, ctx->opcode)) {
// and opcode supported
// return success
return true;
}
// else keep going ...
if ((ctx->insn_flags & ASE_LEXT)
&& decode_loong_ext(ctx, ctx->opcode)) {
return true;
}
// finally return false, if nothing else decoded
// gen_reserved_instruction will be called in the
// main decode loop.
return false;}
Quoted 3 lines
Loong-EXT is a super set of Loongson2F's Godson2 and MMI instructions, how could we tell it?
MMI instructions are currently handled by the ASE_LMMI flag, a different decoder (which will also be handled by this function, similarly to ASE_LEXT).
Regards,
Phil.
Quoted 7 lines · Philippe Mathieu-Daudé
Quoted 2 lines · Jiaxun Yang
Loong-EXT is a super set of Loongson2F's Godson2 and MMI instructions, how could we tell it?
MMI instructions are currently handled by the
ASE_LMMIflag, a different decoder (which will also be handled by this function, similarly toASE_LEXT).
(BTW no need to spend time converting ASE_LMMI, I already did it, I'm waiting for the review outcome of this series before posting it).
Quoted 61 lines · Philippe Mathieu-Daudé
Quoted 28 lines · Jiaxun Yang
Quoted 23 lines · Philippe Mathieu-Daudé
Loongson is next step in the "MIPS decodetree conversion" epic. Start with the simplest extension.
The diffstat addition comes from the TCG functions expanded. The code is easier to review now.
IMO this is also a good template to show how easy a decodetree conversion can be (and how nice the .decode file is to review) :PPlease review,
Phil.
Based-on: <[email protected]> "decodetree: Allow 'dot' in opcode names"
Philippe Mathieu-Daudé (6):
target/mips: Re-introduceOPC_ADDUH_QB_DSPandOPC_MUL_PH_DSPtarget/mips: Convert Loongson DDIV.G opcodes to decodetree target/mips: Convert Loongson DIV.G opcodes to decodetree target/mips: Convert Loongson [D]DIVU.G opcodes to decodetree target/mips: Convert Loongson [D]MOD[U].G opcodes to decodetree target/mips: Convert Loongson [D]MULT[U].G opcodes to decodetreeQuoted 3 lines
target/mips/translate.h | 1 +
target/mips/godson2.decode | 29 +++
target/mips/loong-ext.decode | 30 +++Quoted 6 lines
Hi Philippe,
Thanks for the template!
Just a small question, where should we perform ISA availability check? Before calling generated decoder or after decoded?
The check is done before in
decode_loongson:bool
decode_loongson(DisasContext *ctx, uint32_t insn){ if ((ctx->insn_flags & INSN_LOONGSON2E) // if ISA available ... && decode_godson2(ctx, ctx->opcode)) { // and opcode supported // return success return true; } // else keep going ... if ((ctx->insn_flags & ASE_LEXT) && decode_loong_ext(ctx, ctx->opcode)) { return true; } // finally return false, if nothing else decoded // gen_reserved_instruction will be called in the // main decode loop. return false;}
Quoted 1 line
Quoted 6 lines
Quoted 2 lines
Loong-EXT is a super set of Loongson2F's Godson2 and MMI instructions, how could we tell it?
MMI instructions are currently handled by the
ASE_LMMIflag, a different decoder (which will also be handled by this function, similarly toASE_LEXT).
SWC2/LWC2/SDC2/LDC2 family of LEXT instructions do exist on LEXT but not Loongson-2F.
Thanks.
Quoted 5 lines
Regards,
Phil.
Signature · 1 line
- Jiaxun
Quoted 2 lines · Philippe Mathieu-Daudé
Based-on: <[email protected]>
"decodetree: Allow 'dot' in opcode names"
I'm still unconvinced about this. I've reviewed the code without regard to the spelling in the decodetree files.
r~
Quoted 6 lines · Richard Henderson
Quoted 2 lines · Philippe Mathieu-Daudé
Based-on: <[email protected]>
"decodetree: Allow 'dot' in opcode names"I'm still unconvinced about this. I've reviewed the code without regard to the spelling in the decodetree files.
Understood.
Thanks for your review!
Phil.
Quoted 5 lines · Richard Henderson
Quoted 2 lines · Philippe Mathieu-Daudé
Based-on: <[email protected]>
"decodetree: Allow 'dot' in opcode names"I'm still unconvinced about this. I've reviewed the code without regard to the spelling in the decodetree files.
Should we use '_' in decodetree to replace dot?
Thanks.
- Jiaxun
Quoted 3 lines
r~