target/mips: Convert Loongson LEXT opcodes to decodetree
v3 cover target/mips: Convert Loongson LEXT opcodes to decodetree
Missing review: 1 & 9
Since v2:
- Extract decode_64bit_enabled()
- Remove unreachable 32-bit code
Since v1:
- Fixed '!is_double' check (rth)
- Rebased (removing tcg_temp_free calls)
- Simplified MULT[U].G (rth)
- Added R-b
Philippe Mathieu-Daudé (9):
target/mips: Extract decode_64bit_enabled() helper 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: Remove unreachable 32-bit code on 64-bit Loongson Ext
target/mips/tcg/translate.h | 3 + target/mips/tcg/godson2.decode | 27 +++ target/mips/tcg/loong-ext.decode | 28 +++ target/mips/tcg/loong_translate.c | 271 ++++++++++++++++++++++++++++++ target/mips/tcg/translate.c | 271 ++---------------------------- target/mips/tcg/meson.build | 3 + 6 files changed, 348 insertions(+), 255 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.45.2
PATCH v3 1/9 target/mips: Extract decode_64bit_enabled() helper
Extract the decode_64bit_enabled() helper which detects whether CPUs can run 64-bit instructions.
--- target/mips/tcg/translate.h | 2 ++ target/mips/tcg/translate.c | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-)
target/mips/tcg/translate.h +2 -0
@@ -217,6 +217,8 @@ void msa_translate_init(void);void mxu_translate_init (void );bool decode_ase_mxu (DisasContext *ctx,uint32_t insn); +bool decode_64bit_enabled (DisasContext *ctx); +/* decodetree generated */ bool decode_isa_rel6 (DisasContext *ctx,uint32_t insn);bool decode_ase_msa (DisasContext *ctx,uint32_t insn);
target/mips/tcg/translate.c +6 -1
@@ -1645,13 +1645,18 @@ static inline void check_ps(DisasContext *ctx)check_cp1_64bitmode (ctx); } +bool decode_64bit_enabled (DisasContext *ctx) +{ +return ctx->hflags &MIPS_HFLAG_64 ; +} +/* * This code generates a "reserved instruction" exception if cpu is not * 64-bit or 64-bit instructions are not enabled. */ void check_mips_64 (DisasContext *ctx) { -if (unlikely ((TARGET_LONG_BITS !=64 ) || !(ctx->hflags &MIPS_HFLAG_64 ))) { +if (unlikely ((TARGET_LONG_BITS !=64 ) || !decode_64bit_enabled (ctx))) {gen_reserved_instruction (ctx); } }
Signature · 1 line
2.45.2
Re: [PATCH v3 1/9] target/mips: Extract decode_64bit_enabled() helper
Quoted 36 lines · Philippe Mathieu-Daudé
Extract the
decode_64bit_enabled()helper which detects whether CPUs can run 64-bit instructions.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/mips/tcg/translate.h | 2 ++ target/mips/tcg/translate.c | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-)target/mips/tcg/translate.h +2
-0@@ -217,6 +217,8 @@ void msa_translate_init(void);void mxu_translate_init (void );bool decode_ase_mxu (DisasContext *ctx,uint32_t insn); +bool decode_64bit_enabled (DisasContext *ctx); +/* decodetree generated */ bool decode_isa_rel6 (DisasContext *ctx,uint32_t insn);bool decode_ase_msa (DisasContext *ctx,uint32_t insn);target/mips/tcg/translate.c +5
-0@@ -1645,13 +1645,18 @@ static inline void check_ps(DisasContext *ctx)check_cp1_64bitmode (ctx); } +bool decode_64bit_enabled (DisasContext *ctx) +{ +return ctx->hflags &MIPS_HFLAG_64 ; +} +/*
target/mips/tcg/translate.c static inline void check_ps(DisasContext *ctx) · line 1662
Quoted 10 lines
target/mips/tcg/translate.c +1
-1* This code generates a "reserved instruction" exception if cpu is not * 64-bit or 64-bit instructions are not enabled. */ void check_mips_64 (DisasContext *ctx) { -if (unlikely ((TARGET_LONG_BITS !=64 ) || !(ctx->hflags &MIPS_HFLAG_64 ))) { +if (unlikely ((TARGET_LONG_BITS !=64 ) || !decode_64bit_enabled (ctx))) {gen_reserved_instruction (ctx); } }
PATCH v3 2/9 target/mips: Simplify Loongson MULTU.G opcode
In reply to 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.
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
@@ -3615,8 +3615,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.45.2
PATCH v3 3/9 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
@@ -389,16 +389,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 */
@@ -556,7 +554,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 */
@@ -11587,8 +11584,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 :
@@ -12271,11 +12267,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 :
@@ -13811,7 +13803,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.45.2
PATCH v3 4/9 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 | 86 +++++++++++++++++++++++++++++++ target/mips/tcg/translate.c | 26 ++-------- target/mips/tcg/meson.build | 3 ++ 6 files changed, 126 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
@@ -223,6 +223,7 @@ bool decode_64bit_enabled(DisasContext *ctx);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 64-bit 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 64-bit 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 +86 -0
86 lines not on this page · raw message
target/mips/tcg/translate.c +3 -23
@@ -333,7 +333,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,
@@ -375,7 +374,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,
@@ -3698,25 +3696,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 : {
@@ -13654,7 +13633,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 :
@@ -14061,7 +14039,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 :
@@ -15262,6 +15239,9 @@ static void decode_opc(CPUMIPSState *env, DisasContext *ctx)if (cpu_supports_isa (env,INSN_VR54XX ) &&decode_ext_vr54xx (ctx, ctx->opcode)) {return ; } +if (TARGET_LONG_BITS ==64 &&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'),
@@ -28,6 +30,7 @@ mips_ss.add(when: 'TARGET_MIPS64', if_true: files( 'tx79_translate.c', 'octeon_translate.c', 'lcsr_translate.c', + 'loong_translate.c', ), if_false: files( 'mxu_translate.c', ))
Signature · 1 line
2.45.2
PATCH v3 5/9 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 @@* one result 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
@@ -332,7 +332,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,
@@ -370,7 +369,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,
@@ -3613,28 +3611,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 : {
@@ -13598,7 +13574,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 :
@@ -13771,7 +13746,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.45.2
PATCH v3 6/9 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
@@ -332,8 +332,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,
@@ -369,10 +367,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,
@@ -3611,22 +3607,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 : {
@@ -3672,19 +3652,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 : {
@@ -13574,7 +13541,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 :
@@ -13608,7 +13574,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 );
@@ -13746,7 +13711,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 :
@@ -14013,7 +13977,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.45.2
Quoted 5 lines · Philippe Mathieu-Daudé
target/mips/tcg/translate.h | 3 + target/mips/tcg/godson2.decode | 27 +++ target/mips/tcg/loong-ext.decode | 28 +++ target/mips/tcg/loong_translate.c | 271 ++++++++++++++++++++++++++++++ target/mips/tcg/translate.c | 271 ++----------------------------
Amusing diff-stat =)
Quoted 2 lines
target/mips/tcg/meson.build | 3 + 6 files changed, 348 insertions(+), 255 deletions(-)
PATCH v3 7/9 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.45.2
PATCH v3 8/9 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.45.2
PATCH v3 9/9 target/mips: Remove unreachable 32-bit code on 64-bit Loongson Ext
In reply to Philippe Mathieu-DaudéLoongson fixed-point multiplies and divisions opcodes are specific to 64-bit cores (Loongson-2 and Loongson-3 families). Simplify by removing the 32-bit checks.
--- target/mips/tcg/loong_translate.c | 41 ++----------------------------- 1 file changed, 2 insertions(+), 39 deletions(-)
target/mips/tcg/loong_translate.c +2 -39
@@ -31,13 +31,6 @@ static bool gen_lext_DIV_G(DisasContext *s, int rd, int rs, int rt,TCGv t0, t1;TCGLabel *l1, *l2, *l3; -if (is_double) { -if (TARGET_LONG_BITS !=64 ) { -return false; - } -check_mips_64 (s); - } -if (rd ==0 ) {/* Treat as NOP. */ return true;
@@ -61,8 +54,7 @@ static bool gen_lext_DIV_G(DisasContext *s, int rd, int rs, int rt,tcg_gen_br (l3);gen_set_label (l1); -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 , t0, is_double ?LLONG_MIN :INT_MIN , l2);tcg_gen_brcondi_tl (TCG_COND_NE , t1,-1LL , l2);tcg_gen_mov_tl (cpu_gpr[rd], t0);
@@ -93,13 +85,6 @@ static bool gen_lext_DIVU_G(DisasContext *s, int rd, int rs, int rt,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;
@@ -147,13 +132,6 @@ static bool gen_lext_MOD_G(DisasContext *s, int rd, int rs, int rt,TCGv t0, t1;TCGLabel *l1, *l2, *l3; -if (is_double) { -if (TARGET_LONG_BITS !=64 ) { -return false; - } -check_mips_64 (s); - } -if (rd ==0 ) {/* Treat as NOP. */ return true;
@@ -173,8 +151,7 @@ static bool gen_lext_MOD_G(DisasContext *s, int rd, int rs, int rt,tcg_gen_ext32u_tl (t1, t1); }tcg_gen_brcondi_tl (TCG_COND_EQ , t1,0 , l1); -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 , t0, is_double ?LLONG_MIN :INT_MIN , l2);tcg_gen_brcondi_tl (TCG_COND_NE , t1,-1LL , l2);gen_set_label (l1);tcg_gen_movi_tl (cpu_gpr[rd],0 );
@@ -205,13 +182,6 @@ static bool gen_lext_MODU_G(DisasContext *s, int rd, int rs, int rt,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;
@@ -257,13 +227,6 @@ static bool gen_lext_MULT_G(DisasContext *s, int rd, int rs, int rt, {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;
Signature · 1 line
2.45.2
Re: [PATCH v3 9/9] target/mips: Remove unreachable 32-bit code on 64-bit Loongson Ext
Quoted 94 lines · Philippe Mathieu-Daudé
Loongson fixed-point multiplies and divisions opcodes are specific to 64-bit cores (Loongson-2 and Loongson-3 families). Simplify by removing the 32-bit checks.
Reported-by Richard Henderson <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/mips/tcg/loong_translate.c | 41 ++----------------------------- 1 file changed, 2 insertions(+), 39 deletions(-)target/mips/tcg/loong_translate.c +2
-32@@ -31,13 +31,6 @@ static bool gen_lext_DIV_G(DisasContext *s, int rd, int rs, int rt,TCGv t0, t1;TCGLabel *l1, *l2, *l3; -if (is_double) { -if (TARGET_LONG_BITS !=64 ) { -return false; - } -check_mips_64 (s); - } -if (rd ==0 ) {/* Treat as NOP. */ return true;@@ -61,8 +54,7 @@ static bool gen_lext_DIV_G(DisasContext *s, int rd, int rs, int rt,tcg_gen_br (l3);gen_set_label (l1); -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 , t0, is_double ?LLONG_MIN :INT_MIN , l2);tcg_gen_brcondi_tl (TCG_COND_NE , t1,-1LL , l2);tcg_gen_mov_tl (cpu_gpr[rd], t0);@@ -93,13 +85,6 @@ static bool gen_lext_DIVU_G(DisasContext *s, int rd, int rs, int rt,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;@@ -147,13 +132,6 @@ static bool gen_lext_MOD_G(DisasContext *s, int rd, int rs, int rt,TCGv t0, t1;TCGLabel *l1, *l2, *l3; -if (is_double) { -if (TARGET_LONG_BITS !=64 ) { -return false; - } -check_mips_64 (s); - } -if (rd ==0 ) {/* Treat as NOP. */ return true;@@ -173,8 +151,7 @@ static bool gen_lext_MOD_G(DisasContext *s, int rd, int rs, int rt,tcg_gen_ext32u_tl (t1, t1); }tcg_gen_brcondi_tl (TCG_COND_EQ , t1,0 , l1); -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 , t0, is_double ?LLONG_MIN :INT_MIN , l2);tcg_gen_brcondi_tl (TCG_COND_NE , t1,-1LL , l2);gen_set_label (l1);tcg_gen_movi_tl (cpu_gpr[rd],0 );@@ -205,13 +182,6 @@ static bool gen_lext_MODU_G(DisasContext *s, int rd, int rs, int rt,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;@@ -257,13 +227,6 @@ static bool gen_lext_MULT_G(DisasContext *s, int rd, int rs, int rt, {TCGv t0, t1;
target/mips/tcg/loong_translate.c static bool gen_lext_MULT_G(DisasContext *s, int rd, int rs, int rt, · line 232
Quoted 10 lines
target/mips/tcg/loong_translate.c +0
-7-if (is_double) { -if (TARGET_LONG_BITS !=64 ) { -return false; - } -check_mips_64 (s); - } -if (rd ==0 ) {/* Treat as NOP. */ return true;
Quoted 10 lines · Philippe Mathieu-Daudé
Philippe Mathieu-Daudé (9):
target/mips: Extractdecode_64bit_enabled()helper target/mips: Simplify Loongson MULTU.G opcode 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 target/mips: Remove unreachable 32-bit code on 64-bit Loongson Ext
Series queued.