|
From: | Weiwei Li |
Subject: | Re: [PATCH v6 09/14] target/riscv: rvk: add support for sha512 related instructions for RV32 in zknh extension |
Date: | Mon, 28 Feb 2022 11:17:49 +0800 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 |
在 2022/2/28 上午3:36, Richard Henderson 写道:
Yeah. It's not necessary to extend to uint64_t. I'll try to change them to inline later.On 2/27/22 04:25, Weiwei Li wrote:- add sha512sum0r, sha512sig0l, sha512sum1r, sha512sig1l, sha512sig0h and sha512sig1h instructionsCo-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> --- target/riscv/crypto_helper.c | 57 ++++++++++++++++ target/riscv/helper.h | 7 ++ target/riscv/insn32.decode | 6 ++ target/riscv/insn_trans/trans_rvk.c.inc | 90 +++++++++++++++++++++++++ 4 files changed, 160 insertions(+) diff --git a/target/riscv/crypto_helper.c b/target/riscv/crypto_helper.c index f5ffc262f2..6cd2a92b86 100644 --- a/target/riscv/crypto_helper.c +++ b/target/riscv/crypto_helper.c @@ -303,4 +303,61 @@ target_ulong HELPER(sha256sum1)(target_ulong rs1) return sext_xlen(ROR32(a, 6) ^ ROR32(a, 11) ^ ROR32(a, 25)); } #undef ROR32 + +#define zext32(x) ((uint64_t)(uint32_t)(x)) + +target_ulong HELPER(sha512sum0r)(target_ulong rs1, target_ulong rs2) +{ + uint64_t result = (zext32(rs1) << 25) ^ (zext32(rs1) << 30) ^ + (zext32(rs1) >> 28) ^ (zext32(rs2) >> 7) ^ + (zext32(rs2) >> 2) ^ (zext32(rs2) << 4); + + return sext_xlen(result); +}I'm a little confused as to why you're extending back to uint64_t? Especially since the top 32 are discarded.Also, I think sext_xlen is a bad name -- sext32_xlen would be better. It confused me here for a bit, and I went off on a bit of an irrelevant tangent.These could also be implemented inline. I count 12 instructions. The overhead of a function call is about 7.
+DEF_HELPER_2(sha512sum0r, tl, tl, tl) +DEF_HELPER_2(sha512sum1r, tl, tl, tl) +DEF_HELPER_2(sha512sig0l, tl, tl, tl) +DEF_HELPER_2(sha512sig0h, tl, tl, tl) +DEF_HELPER_2(sha512sig1l, tl, tl, tl) +DEF_HELPER_2(sha512sig1h, tl, tl, tl)DEF_HELPER_FLAGS.+static bool trans_sha512sum0r(DisasContext *ctx, arg_sha512sum0r *a) +{ + REQUIRE_32BIT(ctx); + REQUIRE_ZKNH(ctx); + + TCGv dest = dest_gpr(ctx, a->rd); + TCGv src1 = get_gpr(ctx, a->rs1, EXT_NONE); + TCGv src2 = get_gpr(ctx, a->rs2, EXT_NONE); + + gen_helper_sha512sum0r(dest, src1, src2); + gen_set_gpr(ctx, a->rd, dest); + + return true; +}gen_arith.
OK. I'll fix them. Regards, Weiwei Li
r~
[Prev in Thread] | Current Thread | [Next in Thread] |