target/mips: Convert Loongson LEXT opcodes to decodetree
v2 cover target/mips: Convert Loongson LEXT opcodes to decodetree
Respin of old series...
Since v1 [*]:
- Fixed '!is_double' check (rth)
- Rebased (removing tcg_temp_free calls)
- Simplified MULT[U].G (rth)
- Added R-b
Cover from v1:
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]>
"target/mips: Simplify Loongson MULTU.G opcode"
[*] https://lore.kernel.org/qemu-devel/[email protected]/
Philippe Mathieu-Daudé (7):
target/mips: Simplify Loongson MULTU.G opcode 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/tcg/translate.h | 1 + target/mips/tcg/godson2.decode | 27 +++ target/mips/tcg/loong-ext.decode | 28 +++ target/mips/tcg/loong_translate.c | 307 ++++++++++++++++++++++++++++++ target/mips/tcg/translate.c | 264 +------------------------ target/mips/tcg/meson.build | 3 + 6 files changed, 376 insertions(+), 254 deletions(-) create mode 100644 target/mips/tcg/godson2.decode create mode 100644 target/mips/tcg/loong-ext.decode create mode 100644 target/mips/tcg/loong_translate.c
Signature · 1 line
2.41.0
PATCH v2 1/7 target/mips: Simplify Loongson MULTU.G opcode
Since MULTU opcodes don't record the most significant bits of the infinite result, sign-extending the sources make no difference in the result.
Once we remove the sign extension of source registers, MULT and MULTU are identical (as are DMULT and DMULTU).
--- target/mips/tcg/translate.c | 2 -- 1 file changed, 2 deletions(-)
target/mips/tcg/translate.c +0 -2
@@ -3625,8 +3625,6 @@ static void gen_loongson_integer(DisasContext *ctx, uint32_t opc,break ;case OPC_MULTU_G_2E :case OPC_MULTU_G_2F : -tcg_gen_ext32u_tl (t0, t0); -tcg_gen_ext32u_tl (t1, t1);tcg_gen_mul_tl (cpu_gpr[rd], t0, t1);tcg_gen_ext32s_tl (cpu_gpr[rd], cpu_gpr[rd]);break ;
Signature · 1 line
2.41.0
Re: [PATCH v2 1/7] target/mips: Simplify Loongson MULTU.G opcode
Quoted 4 lines · Philippe Mathieu-Daudé
Since MULTU opcodes don't record the most significant bits of the infinite result, sign-extending the sources make no difference in the result.
Quoted 8 lines
Once we remove the sign extension of source registers, MULT and MULTU are identical (as are DMULT and DMULTU).
Suggested-by Richard Henderson<[email protected]>Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- target/mips/tcg/translate.c | 2 -- 1 file changed, 2 deletions(-)
r~
PATCH v2 2/7 target/mips: Re-introduce OPC_ADDUH_QB_DSP and OPC_MUL_PH_DSP
In reply to Philippe Mathieu-DaudéFrom: Philippe Mathieu-Daudé <[email protected]>
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/tcg/translate.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-)
target/mips/tcg/translate.c +5 -13
@@ -390,16 +390,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 */
@@ -557,7 +555,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 */
@@ -11663,8 +11660,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 :
@@ -12347,11 +12343,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 :
@@ -13887,7 +13879,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.41.0
PATCH v2 3/7 target/mips: Convert Loongson DDIV.G opcodes to decodetree
In reply to Philippe Mathieu-DaudéFrom: Philippe Mathieu-Daudé <[email protected]>
Introduce decode_loongson() to decode all Loongson vendor specific opcodes. Start converting a single opcode: DDIV.G (divide 64-bit signed integers).
--- target/mips/tcg/translate.h | 1 + target/mips/tcg/godson2.decode | 16 ++++++ target/mips/tcg/loong-ext.decode | 17 +++++++ target/mips/tcg/loong_translate.c | 85 +++++++++++++++++++++++++++++++ target/mips/tcg/translate.c | 26 ++-------- target/mips/tcg/meson.build | 3 ++ 6 files changed, 125 insertions(+), 23 deletions(-) create mode 100644 target/mips/tcg/godson2.decode create mode 100644 target/mips/tcg/loong-ext.decode create mode 100644 target/mips/tcg/loong_translate.c
target/mips/tcg/translate.h +1 -0
@@ -220,6 +220,7 @@ bool decode_ase_mxu(DisasContext *ctx, uint32_t insn);bool decode_isa_rel6 (DisasContext *ctx,uint32_t insn);bool decode_ase_msa (DisasContext *ctx,uint32_t insn);bool decode_ext_txx9 (DisasContext *ctx,uint32_t insn); +bool decode_ext_loongson (DisasContext *ctx,uint32_t insn);#if defined(TARGET_MIPS64 )bool decode_ase_lcsr (DisasContext *ctx,uint32_t insn);bool decode_ext_tx79 (DisasContext *ctx,uint32_t insn);
target/mips/tcg/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/tcg/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/tcg/loong_translate.c new file +85 -0
85 lines not on this page · raw message
target/mips/tcg/translate.c +3 -23
@@ -334,7 +334,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,
@@ -376,7 +375,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,
@@ -3708,25 +3706,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 : {
@@ -13730,7 +13709,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 :
@@ -14137,7 +14115,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 :
@@ -15338,6 +15315,9 @@ static void decode_opc(CPUMIPSState *env, DisasContext *ctx)if (cpu_supports_isa (env,INSN_VR54XX ) &&decode_ext_vr54xx (ctx, ctx->opcode)) {return ; } +if (decode_ext_loongson (ctx, ctx->opcode)) { +return ; + }#if defined(TARGET_MIPS64 )if (ase_lcsr_available (env) &&decode_ase_lcsr (ctx, ctx->opcode)) {return ;
target/mips/tcg/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('rel6.decode', extra_args: ['--decode=decode_isa_rel6']), decodetree.process('msa.decode', extra_args: '--decode=decode_ase_msa'), decodetree.process('tx79.decode', extra_args: '--static-decode=decode_tx79'),
@@ -14,6 +16,7 @@ mips_ss.add(files( 'fpu_helper.c', 'ldst_helper.c', 'lmmi_helper.c', + 'loong_translate.c', 'msa_helper.c', 'msa_translate.c', 'op_helper.c',
Signature · 1 line
2.41.0
PATCH v2 4/7 target/mips: Convert Loongson DIV.G opcodes to decodetree
In reply to Philippe Mathieu-DaudéFrom: Philippe Mathieu-Daudé <[email protected]>
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/tcg/godson2.decode | 1 + target/mips/tcg/loong-ext.decode | 1 + target/mips/tcg/loong_translate.c | 28 ++++++++++++++++++++++------ target/mips/tcg/translate.c | 26 -------------------------- 4 files changed, 24 insertions(+), 32 deletions(-)
target/mips/tcg/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/tcg/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/tcg/loong_translate.c +22 -6
@@ -25,15 +25,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. */
@@ -49,26 +52,39 @@ 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 (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 &&TARGET_LONG_BITS ==64 + ?LLONG_MIN :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);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_ext_loongson (DisasContext *ctx,uint32_t insn)
target/mips/tcg/translate.c +0 -26
@@ -333,7 +333,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,
@@ -371,7 +370,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,
@@ -3623,28 +3621,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 : {
@@ -13674,7 +13650,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 :
@@ -13847,7 +13822,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.41.0
PATCH v2 5/7 target/mips: Convert Loongson [D]DIVU.G opcodes to decodetree
In reply to Philippe Mathieu-DaudéFrom: Philippe Mathieu-Daudé <[email protected]>
Convert DIVU.G (divide 32-bit unsigned integers) and DDIVU.G (divide 64-bit unsigned integers) opcodes to decodetree.
--- target/mips/tcg/godson2.decode | 2 ++ target/mips/tcg/loong-ext.decode | 2 ++ target/mips/tcg/loong_translate.c | 54 +++++++++++++++++++++++++++++++ target/mips/tcg/translate.c | 37 --------------------- 4 files changed, 58 insertions(+), 37 deletions(-)
target/mips/tcg/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/tcg/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/tcg/loong_translate.c +54 -0
60 lines not on this page · raw message
target/mips/tcg/translate.c +0 -37
@@ -333,8 +333,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,
@@ -370,10 +368,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,
@@ -3621,22 +3617,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 : {
@@ -3682,19 +3662,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 : {
@@ -13650,7 +13617,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 :
@@ -13684,7 +13650,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 );
@@ -13822,7 +13787,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 :
@@ -14089,7 +14053,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.41.0
PATCH v2 6/7 target/mips: Convert Loongson [D]MOD[U].G opcodes to decodetree
In reply to Philippe Mathieu-DaudéFrom: Philippe Mathieu-Daudé <[email protected]>
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/tcg/godson2.decode | 5 ++ target/mips/tcg/loong-ext.decode | 5 ++ target/mips/tcg/loong_translate.c | 111 ++++++++++++++++++++++++++++++ target/mips/tcg/translate.c | 82 ---------------------- 4 files changed, 121 insertions(+), 82 deletions(-)
target/mips/tcg/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/tcg/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/tcg/loong_translate.c +111 -0
117 lines not on this page · raw message
target/mips/tcg/translate.c +0 -82
130 lines not on this page · raw message
Signature · 1 line
2.41.0
PATCH v2 7/7 target/mips: Convert Loongson [D]MULT[U].G opcodes to decodetree
In reply to Philippe Mathieu-DaudéFrom: Philippe Mathieu-Daudé <[email protected]>
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/tcg/godson2.decode | 3 ++ target/mips/tcg/loong-ext.decode | 3 ++ target/mips/tcg/loong_translate.c | 41 +++++++++++++++++ target/mips/tcg/translate.c | 73 +------------------------------ 4 files changed, 49 insertions(+), 71 deletions(-)
target/mips/tcg/godson2.decode +3 -0
@@ -13,6 +13,9 @@ @rs_rt_rd ...... rs:5 rt:5 rd:5 ..... ...... &muldiv +MULTu_G 011111 ..... ..... ..... 00000 01100- @rs_rt_rd +DMULTu_G 011111 ..... ..... ..... 00000 01110- @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/tcg/loong-ext.decode +3 -0
@@ -14,6 +14,9 @@ @rs_rt_rd ...... rs:5 rt:5 rd:5 ..... ...... &muldiv +MULTu_G 011100 ..... ..... ..... 00000 0100-0 @rs_rt_rd +DMULTu_G 011100 ..... ..... ..... 00000 0100-1 @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/tcg/loong_translate.c +41 -0
47 lines not on this page · raw message
target/mips/tcg/translate.c +2 -71
122 lines not on this page · raw message
Signature · 1 line
2.41.0
Re: [PATCH v2 7/7] target/mips: Convert Loongson [D]MULT[U].G opcodes to decodetree
Quoted 9 lines · Philippe Mathieu-Daudé
From: Philippe Mathieu-Daudé <[email protected]>
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
Quoted 5 lines
Now 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/tcg/loong_translate.c static bool trans_DMODU_G(DisasContext *s, arg_muldiv *a) · line 265
Quoted 6 lines
target/mips/tcg/loong_translate.c +6
-0+if (is_double) { +if (TARGET_LONG_BITS !=64 ) { +return false; + } +check_mips_64 (s); + }
This preserves existing behaviour vs
target/mips/tcg/translate.c static void gen_cl(DisasContext *ctx, uint32_t opc, · line 3621
Quoted 10 lines
target/mips/tcg/translate.c +0
-10-#if defined(TARGET_MIPS64 ) -case OPC_DMULT_G_2E : -case OPC_DMULT_G_2F : -tcg_gen_mul_tl (cpu_gpr[rd], t0, t1); -break ; -case OPC_DMULTU_G_2E : -case OPC_DMULTU_G_2F : -tcg_gen_mul_tl (cpu_gpr[rd], t0, t1); -break ; -#endif
this ifdef. But it doesn't seem quite right.
It's a behaviour change between qemu-system-mips and qemu-system-mips64 for the same cpu. Returning false allows another insn to match instead. But we have identified the insn, it just isn't legal.
Anyway, aren't all of these loongson cpus 64-bit?
r~
Re: [PATCH v2 7/7] target/mips: Convert Loongson [D]MULT[U].G opcodes to decodetree
Quoted 41 lines · Richard Henderson
Quoted 9 lines · Philippe Mathieu-Daudé
From: Philippe Mathieu-Daudé <[email protected]>
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 integersQuoted 5 lines
Now 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]>Reviewed-by Richard Henderson <[email protected]>Quoted 6 lines
+ if (
is_double) {
+ if (TARGET_LONG_BITS!= 64) {
+ return false;
+ }
+check_mips_64(s);
+ }This preserves existing behaviour vs
target/mips/tcg/translate.c static void gen_cl(DisasContext *ctx, uint32_t opc, · line 3621
Quoted 10 lines
target/mips/tcg/translate.c +0
-10-#if defined(TARGET_MIPS64 ) - case OPC_DMULT_G_2E: - case OPC_DMULT_G_2F: - tcg_gen_mul_tl(cpu_gpr[rd], t0, t1); - break; - case OPC_DMULTU_G_2E: - case OPC_DMULTU_G_2F: - tcg_gen_mul_tl(cpu_gpr[rd], t0, t1); - break; -#endif this ifdef. But it doesn't seem quite right.
Quoted 1 line
It's a behaviour change between qemu-system-mips and qemu-system-mips64 for the same cpu. Returning false allows another insn to match instead. But we have identified the insn, it just isn't legal.
Indeed.
Quoted 1 line
Anyway, aren't all of these loongson cpus 64-bit?
The Loongson-1 cores family is 32-bit but AFAICT it doesn't implement the Loongson Extension, which appeared with the Loongson-2 family, which is 64-bit. QEMU only implement the Loongson-2/3 families, both 64-bit.
I'll post a cleanup patch on top, since this series is already fully reviewed.
Thanks!
Phil.