[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 11/25] target/riscv: rvk: add support for sha256 related instructi
From: |
Alistair Francis |
Subject: |
[PULL 11/25] target/riscv: rvk: add support for sha256 related instructions in zknh extension |
Date: |
Fri, 29 Apr 2022 14:31:05 +1000 |
From: Weiwei Li <liweiwei@iscas.ac.cn>
- add sha256sig0, sha256sig1, sha256sum0 and sha256sum1 instructions
Co-authored-by: Zewen Ye <lustrew@foxmail.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-9-liweiwei@iscas.ac.cn>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
---
target/riscv/insn32.decode | 5 +++
target/riscv/insn_trans/trans_rvk.c.inc | 55 +++++++++++++++++++++++++
2 files changed, 60 insertions(+)
diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode
index 0b800b4093..db28ecdd2b 100644
--- a/target/riscv/insn32.decode
+++ b/target/riscv/insn32.decode
@@ -857,3 +857,8 @@ aes64esm 00 11011 ..... ..... 000 ..... 0110011 @r
# *** RV64 Zkne/zknd Standard Extension ***
aes64ks2 01 11111 ..... ..... 000 ..... 0110011 @r
aes64ks1i 00 11000 1.... ..... 001 ..... 0010011 @i_aes
+# *** RV32 Zknh Standard Extension ***
+sha256sig0 00 01000 00010 ..... 001 ..... 0010011 @r2
+sha256sig1 00 01000 00011 ..... 001 ..... 0010011 @r2
+sha256sum0 00 01000 00000 ..... 001 ..... 0010011 @r2
+sha256sum1 00 01000 00001 ..... 001 ..... 0010011 @r2
diff --git a/target/riscv/insn_trans/trans_rvk.c.inc
b/target/riscv/insn_trans/trans_rvk.c.inc
index 6336b48cb5..531e2c7cb3 100644
--- a/target/riscv/insn_trans/trans_rvk.c.inc
+++ b/target/riscv/insn_trans/trans_rvk.c.inc
@@ -29,6 +29,12 @@
} \
} while (0)
+#define REQUIRE_ZKNH(ctx) do { \
+ if (!ctx->cfg_ptr->ext_zknh) { \
+ return false; \
+ } \
+} while (0)
+
static bool gen_aes32_sm4(DisasContext *ctx, arg_k_aes *a,
void (*func)(TCGv, TCGv, TCGv, TCGv))
{
@@ -123,3 +129,52 @@ static bool trans_aes64im(DisasContext *ctx, arg_aes64im
*a)
REQUIRE_ZKND(ctx);
return gen_unary(ctx, a, EXT_NONE, gen_helper_aes64im);
}
+
+static bool gen_sha256(DisasContext *ctx, arg_r2 *a, DisasExtend ext,
+ void (*func)(TCGv_i32, TCGv_i32, int32_t),
+ int32_t num1, int32_t num2, int32_t num3)
+{
+ TCGv dest = dest_gpr(ctx, a->rd);
+ TCGv src1 = get_gpr(ctx, a->rs1, ext);
+ TCGv_i32 t0 = tcg_temp_new_i32();
+ TCGv_i32 t1 = tcg_temp_new_i32();
+ TCGv_i32 t2 = tcg_temp_new_i32();
+
+ tcg_gen_trunc_tl_i32(t0, src1);
+ tcg_gen_rotri_i32(t1, t0, num1);
+ tcg_gen_rotri_i32(t2, t0, num2);
+ tcg_gen_xor_i32(t1, t1, t2);
+ func(t2, t0, num3);
+ tcg_gen_xor_i32(t1, t1, t2);
+ tcg_gen_ext_i32_tl(dest, t1);
+
+ gen_set_gpr(ctx, a->rd, dest);
+ tcg_temp_free_i32(t0);
+ tcg_temp_free_i32(t1);
+ tcg_temp_free_i32(t2);
+ return true;
+}
+
+static bool trans_sha256sig0(DisasContext *ctx, arg_sha256sig0 *a)
+{
+ REQUIRE_ZKNH(ctx);
+ return gen_sha256(ctx, a, EXT_NONE, tcg_gen_shri_i32, 7, 18, 3);
+}
+
+static bool trans_sha256sig1(DisasContext *ctx, arg_sha256sig1 *a)
+{
+ REQUIRE_ZKNH(ctx);
+ return gen_sha256(ctx, a, EXT_NONE, tcg_gen_shri_i32, 17, 19, 10);
+}
+
+static bool trans_sha256sum0(DisasContext *ctx, arg_sha256sum0 *a)
+{
+ REQUIRE_ZKNH(ctx);
+ return gen_sha256(ctx, a, EXT_NONE, tcg_gen_rotri_i32, 2, 13, 22);
+}
+
+static bool trans_sha256sum1(DisasContext *ctx, arg_sha256sum1 *a)
+{
+ REQUIRE_ZKNH(ctx);
+ return gen_sha256(ctx, a, EXT_NONE, tcg_gen_rotri_i32, 6, 11, 25);
+}
--
2.35.1
- [PULL 02/25] hw/riscv: Don't add empty bootargs to device tree, (continued)
- [PULL 02/25] hw/riscv: Don't add empty bootargs to device tree, Alistair Francis, 2022/04/29
- [PULL 01/25] hw/riscv: spike: Add '/chosen/stdout-path' in device tree unconditionally, Alistair Francis, 2022/04/29
- [PULL 03/25] target/riscv: Support configuarable marchid, mvendorid, mipid CSR values, Alistair Francis, 2022/04/29
- [PULL 04/25] target/riscv: rvk: add cfg properties for zbk* and zk*, Alistair Francis, 2022/04/29
- [PULL 05/25] target/riscv: rvk: add support for zbkb extension, Alistair Francis, 2022/04/29
- [PULL 06/25] target/riscv: rvk: add support for zbkc extension, Alistair Francis, 2022/04/29
- [PULL 07/25] target/riscv: rvk: add support for zbkx extension, Alistair Francis, 2022/04/29
- [PULL 08/25] crypto: move sm4_sbox from target/arm, Alistair Francis, 2022/04/29
- [PULL 09/25] target/riscv: rvk: add support for zknd/zkne extension in RV32, Alistair Francis, 2022/04/29
- [PULL 10/25] target/riscv: rvk: add support for zkne/zknd extension in RV64, Alistair Francis, 2022/04/29
- [PULL 11/25] target/riscv: rvk: add support for sha256 related instructions in zknh extension,
Alistair Francis <=
- [PULL 12/25] target/riscv: rvk: add support for sha512 related instructions for RV32 in zknh extension, Alistair Francis, 2022/04/29
- [PULL 13/25] target/riscv: rvk: add support for sha512 related instructions for RV64 in zknh extension, Alistair Francis, 2022/04/29
- [PULL 14/25] target/riscv: rvk: add support for zksed/zksh extension, Alistair Francis, 2022/04/29
- [PULL 15/25] target/riscv: rvk: add CSR support for Zkr, Alistair Francis, 2022/04/29
- [PULL 16/25] disas/riscv.c: rvk: add disas support for Zbk* and Zk* instructions, Alistair Francis, 2022/04/29
- [PULL 17/25] target/riscv: rvk: expose zbk* and zk* properties, Alistair Francis, 2022/04/29
- [PULL 18/25] target/riscv: Fix incorrect PTE merge in walk_pte, Alistair Francis, 2022/04/29
- [PULL 19/25] target/riscv: add scalar crypto related extenstion strings to isa_string, Alistair Francis, 2022/04/29
- [PULL 20/25] hw/riscv: virt: Add a machine done notifier, Alistair Francis, 2022/04/29
- [PULL 21/25] hw/core: Move the ARM sysbus-fdt to core, Alistair Francis, 2022/04/29