[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v7 44/64] target/nios2: Split out helpers for gen_* translate
From: |
Peter Maydell |
Subject: |
Re: [PATCH v7 44/64] target/nios2: Split out helpers for gen_* translate macros |
Date: |
Fri, 22 Apr 2022 14:16:09 +0100 |
On Thu, 21 Apr 2022 at 16:55, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Do as little work as possible within the macros.
> Split out helper functions and pass in arguments instead.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> target/nios2/translate.c | 215 +++++++++++++++++++++++++--------------
> 1 file changed, 141 insertions(+), 74 deletions(-)
>
> diff --git a/target/nios2/translate.c b/target/nios2/translate.c
> index a3c63dbbbd..74672101ca 100644
> --- a/target/nios2/translate.c
> +++ b/target/nios2/translate.c
> @@ -71,6 +71,21 @@ typedef struct {
> .a = extract32((code), 27, 5), \
> }
>
> +static target_ulong imm_unsigned(const InstrIType *i)
> +{
> + return i->imm16.u;
> +}
> +
> +static target_ulong imm_signed(const InstrIType *i)
> +{
> + return i->imm16.s;
> +}
> +
> +static target_ulong imm_shifted(const InstrIType *i)
> +{
> + return i->imm16.u << 16;
> +}
> +
> /* R-Type instruction parsing */
> typedef struct {
> uint8_t op;
> @@ -268,40 +283,62 @@ static void gen_bxx(DisasContext *dc, uint32_t code,
> uint32_t flags)
> }
>
> /* Comparison instructions */
> -#define gen_i_cmpxx(fname, op3)
> \
> -static void (fname)(DisasContext *dc, uint32_t code, uint32_t flags)
> \
> -{
> \
> - I_TYPE(instr, (code));
> \
> - tcg_gen_setcondi_tl(flags, cpu_R[instr.b], cpu_R[instr.a], (op3));
> \
> +static void do_i_cmpxx(DisasContext *dc, uint32_t insn, TCGCond cond,
> + target_ulong (*imm)(const InstrIType *))
Can we have some typedefs if we're passing function pointers around,
please? I think they're easier to read than having raw
function-pointer type signatures in function prototypes.
> +{
> + I_TYPE(instr, insn);
> +
> + if (likely(instr.b != R_ZERO)) {
> + tcg_gen_setcondi_tl(cond, cpu_R[instr.b],
> + load_gpr(dc, instr.a), imm(&instr));
> + }
The old code didn't do this check against R_ZERO.
> }
> /* Math/logic instructions */
> -#define gen_r_math_logic(fname, insn, op3) \
> -static void (fname)(DisasContext *dc, uint32_t code, uint32_t flags) \
> -{ \
> - R_TYPE(instr, (code)); \
> - if (likely(instr.c != R_ZERO)) { \
> - tcg_gen_##insn(cpu_R[instr.c], load_gpr((dc), instr.a), (op3)); \
> - } \
> +static void do_ri_math_logic(DisasContext *dc, uint32_t insn,
> + void (*fn)(TCGv, TCGv, int32_t))
> +{
> + R_TYPE(instr, insn);
> +
> + if (likely(instr.c != R_ZERO)) {
> + fn(cpu_R[instr.c], load_gpr(dc, instr.a), instr.imm5);
> + }
> }
>
> -gen_r_math_logic(add, add_tl, load_gpr(dc, instr.b))
> -gen_r_math_logic(sub, sub_tl, load_gpr(dc, instr.b))
> -gen_r_math_logic(mul, mul_tl, load_gpr(dc, instr.b))
> +static void do_rr_math_logic(DisasContext *dc, uint32_t insn,
> + void (*fn)(TCGv, TCGv, TCGv))
> +{
> + R_TYPE(instr, insn);
>
> -gen_r_math_logic(and, and_tl, load_gpr(dc, instr.b))
> -gen_r_math_logic(or, or_tl, load_gpr(dc, instr.b))
> -gen_r_math_logic(xor, xor_tl, load_gpr(dc, instr.b))
> -gen_r_math_logic(nor, nor_tl, load_gpr(dc, instr.b))
> -
> -gen_r_math_logic(srai, sari_tl, instr.imm5)
> -gen_r_math_logic(srli, shri_tl, instr.imm5)
> -gen_r_math_logic(slli, shli_tl, instr.imm5)
> -gen_r_math_logic(roli, rotli_tl, instr.imm5)
> -
> -#define gen_r_mul(fname, insn) \
> -static void (fname)(DisasContext *dc, uint32_t code, uint32_t flags) \
> -{ \
> - R_TYPE(instr, (code)); \
> - if (likely(instr.c != R_ZERO)) { \
> - TCGv t0 = tcg_temp_new(); \
> - tcg_gen_##insn(t0, cpu_R[instr.c], \
> - load_gpr(dc, instr.a), load_gpr(dc, instr.b)); \
> - tcg_temp_free(t0); \
> - } \
> + if (likely(instr.c != R_ZERO)) {
> + fn(cpu_R[instr.c], load_gpr(dc, instr.a), load_gpr(dc, instr.b));
> + }
> }
>
> -gen_r_mul(mulxss, muls2_tl)
> -gen_r_mul(mulxuu, mulu2_tl)
> -gen_r_mul(mulxsu, mulsu2_tl)
> +#define gen_ri_math_logic(fname, insn) \
> + static void (fname)(DisasContext *dc, uint32_t code, uint32_t flags) \
> + { do_ri_math_logic(dc, code, tcg_gen_##insn##_tl); }
>
> -#define gen_r_shift_s(fname, insn) \
> -static void (fname)(DisasContext *dc, uint32_t code, uint32_t flags) \
> -{ \
> - R_TYPE(instr, (code)); \
> - if (likely(instr.c != R_ZERO)) { \
> - TCGv t0 = tcg_temp_new(); \
> - tcg_gen_andi_tl(t0, load_gpr((dc), instr.b), 31); \
> - tcg_gen_##insn(cpu_R[instr.c], load_gpr((dc), instr.a), t0); \
> - tcg_temp_free(t0); \
> - } \
> +#define gen_rr_math_logic(fname, insn) \
> + static void (fname)(DisasContext *dc, uint32_t code, uint32_t flags) \
> + { do_rr_math_logic(dc, code, tcg_gen_##insn##_tl); }
git diff has made a bit of a pig's ear of this, interleaving the
changes related to math_logic and the ones related to shift and mul.
If you do these changes one insn group at a time rather than
all in one patch I think the resulting diff should be easier to read.
-- PMM
- [PATCH v7 34/64] target/nios2: Handle EXCP_UNALIGN and EXCP_UALIGND, (continued)
- [PATCH v7 34/64] target/nios2: Handle EXCP_UNALIGN and EXCP_UALIGND, Richard Henderson, 2022/04/21
- [PATCH v7 36/64] target/nios2: Clean up handling of tlbmisc in do_exception, Richard Henderson, 2022/04/21
- [PATCH v7 37/64] target/nios2: Prevent writes to read-only or reserved control fields, Richard Henderson, 2022/04/21
- [PATCH v7 38/64] target/nios2: Implement cpuid, Richard Henderson, 2022/04/21
- [PATCH v7 39/64] target/nios2: Implement CR_STATUS.RSIE, Richard Henderson, 2022/04/21
- [PATCH v7 42/64] target/nios2: Use tcg_constant_tl, Richard Henderson, 2022/04/21
- [PATCH v7 41/64] target/nios2: Support division error exception, Richard Henderson, 2022/04/21
- [PATCH v7 44/64] target/nios2: Split out helpers for gen_* translate macros, Richard Henderson, 2022/04/21
- Re: [PATCH v7 44/64] target/nios2: Split out helpers for gen_* translate macros,
Peter Maydell <=
- [PATCH v7 43/64] target/nios2: Split out named structs for [IRJ]_TYPE, Richard Henderson, 2022/04/21
- [PATCH v7 48/64] target/nios2: Create gen_jumpr, Richard Henderson, 2022/04/21
- [PATCH v7 40/64] target/nios2: Remove CPU_INTERRUPT_NMI, Richard Henderson, 2022/04/21
- [PATCH v7 51/64] target/nios2: Use tcg_gen_lookup_and_goto_ptr, Richard Henderson, 2022/04/21
- [PATCH v7 45/64] target/nios2: Introduce dest_gpr, Richard Henderson, 2022/04/21
- [PATCH v7 47/64] target/nios2: Enable unaligned traps for system mode, Richard Henderson, 2022/04/21
- [PATCH v7 46/64] target/nios2: Drop CR_STATUS_EH from tb->flags, Richard Henderson, 2022/04/21
- [PATCH v7 49/64] target/nios2: Hoist set of is_jmp into gen_goto_tb, Richard Henderson, 2022/04/21
- [PATCH v7 50/64] target/nios2: Use gen_goto_tb for DISAS_TOO_MANY, Richard Henderson, 2022/04/21