target/riscv: Use gen_shift*_per_ol for RVB, RVI
Most shift instructions require a separate implementation for RV32 when TARGET_LONG_BITS == 64. Reviewed-by: LIU Zhiwei <zhiwei_liu@c-sky.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Message-id: 20211020031709.359469-14-richard.henderson@linaro.org Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
This commit is contained in:
parent
fdab665f6e
commit
a0245d91dd
@ -227,22 +227,70 @@ static bool trans_bexti(DisasContext *ctx, arg_bexti *a)
|
||||
return gen_shift_imm_tl(ctx, a, EXT_NONE, gen_bext);
|
||||
}
|
||||
|
||||
static void gen_rorw(TCGv ret, TCGv arg1, TCGv arg2)
|
||||
{
|
||||
TCGv_i32 t1 = tcg_temp_new_i32();
|
||||
TCGv_i32 t2 = tcg_temp_new_i32();
|
||||
|
||||
/* truncate to 32-bits */
|
||||
tcg_gen_trunc_tl_i32(t1, arg1);
|
||||
tcg_gen_trunc_tl_i32(t2, arg2);
|
||||
|
||||
tcg_gen_rotr_i32(t1, t1, t2);
|
||||
|
||||
/* sign-extend 64-bits */
|
||||
tcg_gen_ext_i32_tl(ret, t1);
|
||||
|
||||
tcg_temp_free_i32(t1);
|
||||
tcg_temp_free_i32(t2);
|
||||
}
|
||||
|
||||
static bool trans_ror(DisasContext *ctx, arg_ror *a)
|
||||
{
|
||||
REQUIRE_ZBB(ctx);
|
||||
return gen_shift(ctx, a, EXT_NONE, tcg_gen_rotr_tl);
|
||||
return gen_shift_per_ol(ctx, a, EXT_NONE, tcg_gen_rotr_tl, gen_rorw);
|
||||
}
|
||||
|
||||
static void gen_roriw(TCGv ret, TCGv arg1, target_long shamt)
|
||||
{
|
||||
TCGv_i32 t1 = tcg_temp_new_i32();
|
||||
|
||||
tcg_gen_trunc_tl_i32(t1, arg1);
|
||||
tcg_gen_rotri_i32(t1, t1, shamt);
|
||||
tcg_gen_ext_i32_tl(ret, t1);
|
||||
|
||||
tcg_temp_free_i32(t1);
|
||||
}
|
||||
|
||||
static bool trans_rori(DisasContext *ctx, arg_rori *a)
|
||||
{
|
||||
REQUIRE_ZBB(ctx);
|
||||
return gen_shift_imm_fn(ctx, a, EXT_NONE, tcg_gen_rotri_tl);
|
||||
return gen_shift_imm_fn_per_ol(ctx, a, EXT_NONE,
|
||||
tcg_gen_rotri_tl, gen_roriw);
|
||||
}
|
||||
|
||||
static void gen_rolw(TCGv ret, TCGv arg1, TCGv arg2)
|
||||
{
|
||||
TCGv_i32 t1 = tcg_temp_new_i32();
|
||||
TCGv_i32 t2 = tcg_temp_new_i32();
|
||||
|
||||
/* truncate to 32-bits */
|
||||
tcg_gen_trunc_tl_i32(t1, arg1);
|
||||
tcg_gen_trunc_tl_i32(t2, arg2);
|
||||
|
||||
tcg_gen_rotl_i32(t1, t1, t2);
|
||||
|
||||
/* sign-extend 64-bits */
|
||||
tcg_gen_ext_i32_tl(ret, t1);
|
||||
|
||||
tcg_temp_free_i32(t1);
|
||||
tcg_temp_free_i32(t2);
|
||||
}
|
||||
|
||||
static bool trans_rol(DisasContext *ctx, arg_rol *a)
|
||||
{
|
||||
REQUIRE_ZBB(ctx);
|
||||
return gen_shift(ctx, a, EXT_NONE, tcg_gen_rotl_tl);
|
||||
return gen_shift_per_ol(ctx, a, EXT_NONE, tcg_gen_rotl_tl, gen_rolw);
|
||||
}
|
||||
|
||||
static void gen_rev8_32(TCGv ret, TCGv src1)
|
||||
@ -352,24 +400,6 @@ static bool trans_cpopw(DisasContext *ctx, arg_cpopw *a)
|
||||
return gen_unary(ctx, a, EXT_ZERO, tcg_gen_ctpop_tl);
|
||||
}
|
||||
|
||||
static void gen_rorw(TCGv ret, TCGv arg1, TCGv arg2)
|
||||
{
|
||||
TCGv_i32 t1 = tcg_temp_new_i32();
|
||||
TCGv_i32 t2 = tcg_temp_new_i32();
|
||||
|
||||
/* truncate to 32-bits */
|
||||
tcg_gen_trunc_tl_i32(t1, arg1);
|
||||
tcg_gen_trunc_tl_i32(t2, arg2);
|
||||
|
||||
tcg_gen_rotr_i32(t1, t1, t2);
|
||||
|
||||
/* sign-extend 64-bits */
|
||||
tcg_gen_ext_i32_tl(ret, t1);
|
||||
|
||||
tcg_temp_free_i32(t1);
|
||||
tcg_temp_free_i32(t2);
|
||||
}
|
||||
|
||||
static bool trans_rorw(DisasContext *ctx, arg_rorw *a)
|
||||
{
|
||||
REQUIRE_64BIT(ctx);
|
||||
@ -383,25 +413,7 @@ static bool trans_roriw(DisasContext *ctx, arg_roriw *a)
|
||||
REQUIRE_64BIT(ctx);
|
||||
REQUIRE_ZBB(ctx);
|
||||
ctx->ol = MXL_RV32;
|
||||
return gen_shift_imm_tl(ctx, a, EXT_NONE, gen_rorw);
|
||||
}
|
||||
|
||||
static void gen_rolw(TCGv ret, TCGv arg1, TCGv arg2)
|
||||
{
|
||||
TCGv_i32 t1 = tcg_temp_new_i32();
|
||||
TCGv_i32 t2 = tcg_temp_new_i32();
|
||||
|
||||
/* truncate to 32-bits */
|
||||
tcg_gen_trunc_tl_i32(t1, arg1);
|
||||
tcg_gen_trunc_tl_i32(t2, arg2);
|
||||
|
||||
tcg_gen_rotl_i32(t1, t1, t2);
|
||||
|
||||
/* sign-extend 64-bits */
|
||||
tcg_gen_ext_i32_tl(ret, t1);
|
||||
|
||||
tcg_temp_free_i32(t1);
|
||||
tcg_temp_free_i32(t2);
|
||||
return gen_shift_imm_fn(ctx, a, EXT_NONE, gen_roriw);
|
||||
}
|
||||
|
||||
static bool trans_rolw(DisasContext *ctx, arg_rolw *a)
|
||||
|
@ -268,14 +268,26 @@ static bool trans_slli(DisasContext *ctx, arg_slli *a)
|
||||
return gen_shift_imm_fn(ctx, a, EXT_NONE, tcg_gen_shli_tl);
|
||||
}
|
||||
|
||||
static void gen_srliw(TCGv dst, TCGv src, target_long shamt)
|
||||
{
|
||||
tcg_gen_extract_tl(dst, src, shamt, 32 - shamt);
|
||||
}
|
||||
|
||||
static bool trans_srli(DisasContext *ctx, arg_srli *a)
|
||||
{
|
||||
return gen_shift_imm_fn(ctx, a, EXT_ZERO, tcg_gen_shri_tl);
|
||||
return gen_shift_imm_fn_per_ol(ctx, a, EXT_NONE,
|
||||
tcg_gen_shri_tl, gen_srliw);
|
||||
}
|
||||
|
||||
static void gen_sraiw(TCGv dst, TCGv src, target_long shamt)
|
||||
{
|
||||
tcg_gen_sextract_tl(dst, src, shamt, 32 - shamt);
|
||||
}
|
||||
|
||||
static bool trans_srai(DisasContext *ctx, arg_srai *a)
|
||||
{
|
||||
return gen_shift_imm_fn(ctx, a, EXT_SIGN, tcg_gen_sari_tl);
|
||||
return gen_shift_imm_fn_per_ol(ctx, a, EXT_NONE,
|
||||
tcg_gen_sari_tl, gen_sraiw);
|
||||
}
|
||||
|
||||
static bool trans_add(DisasContext *ctx, arg_add *a)
|
||||
@ -342,11 +354,6 @@ static bool trans_slliw(DisasContext *ctx, arg_slliw *a)
|
||||
return gen_shift_imm_fn(ctx, a, EXT_NONE, tcg_gen_shli_tl);
|
||||
}
|
||||
|
||||
static void gen_srliw(TCGv dst, TCGv src, target_long shamt)
|
||||
{
|
||||
tcg_gen_extract_tl(dst, src, shamt, 32 - shamt);
|
||||
}
|
||||
|
||||
static bool trans_srliw(DisasContext *ctx, arg_srliw *a)
|
||||
{
|
||||
REQUIRE_64BIT(ctx);
|
||||
@ -354,11 +361,6 @@ static bool trans_srliw(DisasContext *ctx, arg_srliw *a)
|
||||
return gen_shift_imm_fn(ctx, a, EXT_NONE, gen_srliw);
|
||||
}
|
||||
|
||||
static void gen_sraiw(TCGv dst, TCGv src, target_long shamt)
|
||||
{
|
||||
tcg_gen_sextract_tl(dst, src, shamt, 32 - shamt);
|
||||
}
|
||||
|
||||
static bool trans_sraiw(DisasContext *ctx, arg_sraiw *a)
|
||||
{
|
||||
REQUIRE_64BIT(ctx);
|
||||
|
@ -438,6 +438,22 @@ static bool gen_shift_imm_fn(DisasContext *ctx, arg_shift *a, DisasExtend ext,
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool gen_shift_imm_fn_per_ol(DisasContext *ctx, arg_shift *a,
|
||||
DisasExtend ext,
|
||||
void (*f_tl)(TCGv, TCGv, target_long),
|
||||
void (*f_32)(TCGv, TCGv, target_long))
|
||||
{
|
||||
int olen = get_olen(ctx);
|
||||
if (olen != TARGET_LONG_BITS) {
|
||||
if (olen == 32) {
|
||||
f_tl = f_32;
|
||||
} else {
|
||||
g_assert_not_reached();
|
||||
}
|
||||
}
|
||||
return gen_shift_imm_fn(ctx, a, ext, f_tl);
|
||||
}
|
||||
|
||||
static bool gen_shift_imm_tl(DisasContext *ctx, arg_shift *a, DisasExtend ext,
|
||||
void (*func)(TCGv, TCGv, TCGv))
|
||||
{
|
||||
@ -474,6 +490,21 @@ static bool gen_shift(DisasContext *ctx, arg_r *a, DisasExtend ext,
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool gen_shift_per_ol(DisasContext *ctx, arg_r *a, DisasExtend ext,
|
||||
void (*f_tl)(TCGv, TCGv, TCGv),
|
||||
void (*f_32)(TCGv, TCGv, TCGv))
|
||||
{
|
||||
int olen = get_olen(ctx);
|
||||
if (olen != TARGET_LONG_BITS) {
|
||||
if (olen == 32) {
|
||||
f_tl = f_32;
|
||||
} else {
|
||||
g_assert_not_reached();
|
||||
}
|
||||
}
|
||||
return gen_shift(ctx, a, ext, f_tl);
|
||||
}
|
||||
|
||||
static bool gen_unary(DisasContext *ctx, arg_r2 *a, DisasExtend ext,
|
||||
void (*func)(TCGv, TCGv))
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user