target/riscv: rvk: add support for zksed/zksh extension

- add sm3p0, sm3p1, sm4ed and sm4ks instructions

Co-authored-by: Ruibo Lu <luruibo2000@163.com>
Signed-off-by: Weiwei Li <liweiwei@iscas.ac.cn>
Signed-off-by: Junqiang Wang <wangjunqiang@iscas.ac.cn>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Message-Id: <20220423023510.30794-12-liweiwei@iscas.ac.cn>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
This commit is contained in:
Weiwei Li 2022-04-23 10:35:07 +08:00 committed by Alistair Francis
parent 1f7f7b5ede
commit 0976083d1b
4 changed files with 95 additions and 0 deletions

View file

@ -35,6 +35,18 @@
} \
} while (0)
#define REQUIRE_ZKSED(ctx) do { \
if (!ctx->cfg_ptr->ext_zksed) { \
return false; \
} \
} while (0)
#define REQUIRE_ZKSH(ctx) do { \
if (!ctx->cfg_ptr->ext_zksh) { \
return false; \
} \
} while (0)
static bool gen_aes32_sm4(DisasContext *ctx, arg_k_aes *a,
void (*func)(TCGv, TCGv, TCGv, TCGv))
{
@ -331,3 +343,49 @@ static bool trans_sha512sum1(DisasContext *ctx, arg_sha512sum1 *a)
REQUIRE_ZKNH(ctx);
return gen_sha512_rv64(ctx, a, EXT_NONE, tcg_gen_rotri_i64, 14, 18, 41);
}
/* SM3 */
static bool gen_sm3(DisasContext *ctx, arg_r2 *a, int32_t b, int32_t c)
{
TCGv dest = dest_gpr(ctx, a->rd);
TCGv src1 = get_gpr(ctx, a->rs1, EXT_NONE);
TCGv_i32 t0 = tcg_temp_new_i32();
TCGv_i32 t1 = tcg_temp_new_i32();
tcg_gen_trunc_tl_i32(t0, src1);
tcg_gen_rotli_i32(t1, t0, b);
tcg_gen_xor_i32(t1, t0, t1);
tcg_gen_rotli_i32(t0, t0, c);
tcg_gen_xor_i32(t1, t1, t0);
tcg_gen_ext_i32_tl(dest, t1);
gen_set_gpr(ctx, a->rd, dest);
tcg_temp_free_i32(t0);
tcg_temp_free_i32(t1);
return true;
}
static bool trans_sm3p0(DisasContext *ctx, arg_sm3p0 *a)
{
REQUIRE_ZKSH(ctx);
return gen_sm3(ctx, a, 9, 17);
}
static bool trans_sm3p1(DisasContext *ctx, arg_sm3p1 *a)
{
REQUIRE_ZKSH(ctx);
return gen_sm3(ctx, a, 15, 23);
}
/* SM4 */
static bool trans_sm4ed(DisasContext *ctx, arg_sm4ed *a)
{
REQUIRE_ZKSED(ctx);
return gen_aes32_sm4(ctx, a, gen_helper_sm4ed);
}
static bool trans_sm4ks(DisasContext *ctx, arg_sm4ks *a)
{
REQUIRE_ZKSED(ctx);
return gen_aes32_sm4(ctx, a, gen_helper_sm4ks);
}