target/riscv: add gen_shifti() and gen_shiftiw() helper functions

Add gen_shifti() and gen_shiftiw() helper functions to reuse the same
interfaces for immediate shift instructions.

Signed-off-by: Frank Chang <frank.chang@sifive.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Message-id: 20210505160620.15723-9-frank.chang@sifive.com
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
This commit is contained in:
Frank Chang 2021-05-06 00:06:09 +08:00 committed by Alistair Francis
parent 2a81973829
commit 981d3568df
2 changed files with 43 additions and 50 deletions

View file

@ -268,54 +268,17 @@ static bool trans_andi(DisasContext *ctx, arg_andi *a)
}
static bool trans_slli(DisasContext *ctx, arg_slli *a)
{
if (a->shamt >= TARGET_LONG_BITS) {
return false;
}
if (a->rd != 0) {
TCGv t = tcg_temp_new();
gen_get_gpr(t, a->rs1);
tcg_gen_shli_tl(t, t, a->shamt);
gen_set_gpr(a->rd, t);
tcg_temp_free(t);
} /* NOP otherwise */
return true;
return gen_shifti(ctx, a, tcg_gen_shl_tl);
}
static bool trans_srli(DisasContext *ctx, arg_srli *a)
{
if (a->shamt >= TARGET_LONG_BITS) {
return false;
}
if (a->rd != 0) {
TCGv t = tcg_temp_new();
gen_get_gpr(t, a->rs1);
tcg_gen_shri_tl(t, t, a->shamt);
gen_set_gpr(a->rd, t);
tcg_temp_free(t);
} /* NOP otherwise */
return true;
return gen_shifti(ctx, a, tcg_gen_shr_tl);
}
static bool trans_srai(DisasContext *ctx, arg_srai *a)
{
if (a->shamt >= TARGET_LONG_BITS) {
return false;
}
if (a->rd != 0) {
TCGv t = tcg_temp_new();
gen_get_gpr(t, a->rs1);
tcg_gen_sari_tl(t, t, a->shamt);
gen_set_gpr(a->rd, t);
tcg_temp_free(t);
} /* NOP otherwise */
return true;
return gen_shifti(ctx, a, tcg_gen_sar_tl);
}
static bool trans_add(DisasContext *ctx, arg_add *a)
@ -377,16 +340,7 @@ static bool trans_addiw(DisasContext *ctx, arg_addiw *a)
static bool trans_slliw(DisasContext *ctx, arg_slliw *a)
{
REQUIRE_64BIT(ctx);
TCGv source1;
source1 = tcg_temp_new();
gen_get_gpr(source1, a->rs1);
tcg_gen_shli_tl(source1, source1, a->shamt);
tcg_gen_ext32s_tl(source1, source1);
gen_set_gpr(a->rd, source1);
tcg_temp_free(source1);
return true;
return gen_shiftiw(ctx, a, tcg_gen_shl_tl);
}
static bool trans_srliw(DisasContext *ctx, arg_srliw *a)