From patchwork Thu Apr 30 02:02:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 185851 Delivered-To: patch@linaro.org Received: by 2002:a92:3d9a:0:0:0:0:0 with SMTP id k26csp1496006ilf; Wed, 29 Apr 2020 19:05:14 -0700 (PDT) X-Google-Smtp-Source: APiQypJ4psV0Agxf9wW4n6RzU9IY8mbLrFaFXgrh02bzQ/FafHoQlHhnzEFl5tEP0a1I0PY9dCQg X-Received: by 2002:a37:6511:: with SMTP id z17mr1303945qkb.405.1588212314781; Wed, 29 Apr 2020 19:05:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588212314; cv=none; d=google.com; s=arc-20160816; b=twtHeBFHk6lL74XGmGLopAa47QfgQuOZUooycEdPpCxWKxAJ3RcbwV7djJEMF4+hbW dy1+bfydSAzA+NIFk1TLZhKfcbSDvyGAlEGam6AWIei+DlCFCA42CyrRkH6477X54f+n +VQCocxZb9fX8Br8IX6sS7FNzU6MEVVIg2N4RR+Q1vZkg+8kUV/BNnKNGWuv2wE2Czgq P3SDMUTOiaNffircXrRDdAmGJkTJ9xvrNCajbohM3WJfEppOpzLh8EeqGWoQz8+VU5I0 3E+DDvgmdEiXenxdD/Z92U8QRI1PU53IppYjpC66dVlvyFpkT9d5fDKZZZiEvt9G3/Me eF1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=UBqJb5Jdsa7NV9JcGHmEClWTryX2MT6M5prjM2Nl448=; b=L3vCxPh3BUaDpGYmDjM/1Y62n0v8hgvp09LtRPl0WiKN6ZzyKFG76g6nx5L2BWdoT7 FpB3yfAEhzuCy8cWnnFGCJuZ7BsaYh4twAPo4WhP15lpmI7gzc9en4sc2ETz5dmj3Nx/ 2qVZwPjiufa//mskRHnD3mNQCF/HXABWBCczYsfYTgcF6AJoVx7WuzMpkQBppFdtKTyM HaKfCN8lwvCqU2aUjcf9Mfyfq1qO0AvMet2K6kTqxbflzRHYho9iu+TyHfOWcaKiEoED +cALV3ivTP6ydDwQSxtaqwznbq4KjbI+XgBGjCbO0Zz8pK1CEJ4AYlqusjR1l59TjSLD V83Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DpOmy8el; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:470:142::17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:470:142::17]) by mx.google.com with ESMTPS id 93si687240qtg.220.2020.04.29.19.05.14 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 29 Apr 2020 19:05:14 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:470:142::17 as permitted sender) client-ip=2001:470:142::17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DpOmy8el; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:470:142::17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:46250 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jTyZe-0007Ca-7Q for patch@linaro.org; Wed, 29 Apr 2020 22:05:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37316) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jTyYw-0006yS-Ub for qemu-devel@nongnu.org; Wed, 29 Apr 2020 22:04:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jTyXh-0004jn-5s for qemu-devel@nongnu.org; Wed, 29 Apr 2020 22:04:30 -0400 Received: from mail-pj1-x1043.google.com ([2607:f8b0:4864:20::1043]:55893) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jTyXg-0004jQ-Kf for qemu-devel@nongnu.org; Wed, 29 Apr 2020 22:03:12 -0400 Received: by mail-pj1-x1043.google.com with SMTP id a32so54397pje.5 for ; Wed, 29 Apr 2020 19:03:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UBqJb5Jdsa7NV9JcGHmEClWTryX2MT6M5prjM2Nl448=; b=DpOmy8el0LgZG9lbalpewJt+t0k0JNzziaCR11MqU2AIbJ0/QEQjj15mkMQpdGHvce eSRGswcN4ZbjvSpqIJ4hmrBFmbrPyIfNCPYygVj+k3tyw5Pn/LIX4raWp3edMhzwar4t cT9xJsw5WMeiYfX+2LP4ZPgahM9nFB2+WJ+uUpDLE2smD3xbbSInC6yEvt9kUsRKHQDY OSAI4t+/5plgTRSDJd8zq5e56IRXar5/6Ye6yroo93wf5kBvlJV+aSbmRF8sjU5g1xvf yvAXeeEAZrCQwzhcGZHE1kPDHJiOvvtWTdpyr/ri/pIUYHEH8dNaeKtsPB1fhPkyLY7c ooEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=UBqJb5Jdsa7NV9JcGHmEClWTryX2MT6M5prjM2Nl448=; b=S7MgGji+KASoOrPN72WKN+VKqG7OXgdEqVNyrRhLyf0Kbea6UrkXmneWo8juoDf5qa zoUV7b/GFQ4ot+KHOAJtaJ3woDsuPu8vRS7+sslQDh1wlt6OTEUw+qQtGLUFWPrd3Wsf wUHyk/hxvF183MJ1xiGd6USt5NIleuedt0Tmkg2lA6giRUdJel2bMqbhAUcIETM4pNqz 7vHd7VkfM612TN+kt6/LMIAv5Pfaxek06t1Vj9iutZfEAt21dNVSOcxyuHXlL1OrWTSZ bsTIidpuNXgQEIo2A8V2OCAypLzmdIsi0eFOjFBSrMKrsRKJpbPVY2htI+T9/vOYedSF n8Rw== X-Gm-Message-State: AGi0Puajc7yn/zJYJUszGuSK49ml8oT3ncdoQqnu2iyD6yoJ1fK3TE+b /PkhST7ZaCC03h9LGqVgrR49X8fVBA0= X-Received: by 2002:a17:902:d30a:: with SMTP id b10mr1357888plc.3.1588212189064; Wed, 29 Apr 2020 19:03:09 -0700 (PDT) Received: from localhost.localdomain (174-21-149-226.tukw.qwest.net. [174.21.149.226]) by smtp.gmail.com with ESMTPSA id y3sm409284pjb.41.2020.04.29.19.03.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Apr 2020 19:03:08 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 3/9] target/arm: Convert sha512 and sm3 to gvec helpers Date: Wed, 29 Apr 2020 19:02:57 -0700 Message-Id: <20200430020303.20264-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200430020303.20264-1-richard.henderson@linaro.org> References: <20200430020303.20264-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1043; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1043.google.com X-detected-operating-system: by eggs.gnu.org: Error: [-] PROGRAM ABORT : Malformed IPv6 address (bad octet value). Location : parse_addr6(), p0f-client.c:67 X-Received-From: 2607:f8b0:4864:20::1043 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: steplong@quicinc.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Do not yet convert the helpers to loop over opr_sz, but the descriptor allows the vector tail to be cleared. Which fixes an existing bug. Signed-off-by: Richard Henderson --- target/arm/helper.h | 15 +++++---- target/arm/crypto_helper.c | 37 +++++++++++++++++++---- target/arm/translate-a64.c | 62 +++++++++++++++----------------------- 3 files changed, 64 insertions(+), 50 deletions(-) -- 2.20.1 diff --git a/target/arm/helper.h b/target/arm/helper.h index 96cf4464be..d564747808 100644 --- a/target/arm/helper.h +++ b/target/arm/helper.h @@ -525,14 +525,17 @@ DEF_HELPER_FLAGS_3(crypto_sha256h2, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) DEF_HELPER_FLAGS_2(crypto_sha256su0, TCG_CALL_NO_RWG, void, ptr, ptr) DEF_HELPER_FLAGS_3(crypto_sha256su1, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) -DEF_HELPER_FLAGS_3(crypto_sha512h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) -DEF_HELPER_FLAGS_3(crypto_sha512h2, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) -DEF_HELPER_FLAGS_2(crypto_sha512su0, TCG_CALL_NO_RWG, void, ptr, ptr) -DEF_HELPER_FLAGS_3(crypto_sha512su1, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) +DEF_HELPER_FLAGS_4(crypto_sha512h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) +DEF_HELPER_FLAGS_4(crypto_sha512h2, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) +DEF_HELPER_FLAGS_3(crypto_sha512su0, TCG_CALL_NO_RWG, void, ptr, ptr, i32) +DEF_HELPER_FLAGS_4(crypto_sha512su1, TCG_CALL_NO_RWG, + void, ptr, ptr, ptr, i32) DEF_HELPER_FLAGS_5(crypto_sm3tt, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32, i32) -DEF_HELPER_FLAGS_3(crypto_sm3partw1, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) -DEF_HELPER_FLAGS_3(crypto_sm3partw2, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) +DEF_HELPER_FLAGS_4(crypto_sm3partw1, TCG_CALL_NO_RWG, + void, ptr, ptr, ptr, i32) +DEF_HELPER_FLAGS_4(crypto_sm3partw2, TCG_CALL_NO_RWG, + void, ptr, ptr, ptr, i32) DEF_HELPER_FLAGS_4(crypto_sm4e, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) DEF_HELPER_FLAGS_4(crypto_sm4ekey, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) diff --git a/target/arm/crypto_helper.c b/target/arm/crypto_helper.c index 372d8350e4..637e4c00bb 100644 --- a/target/arm/crypto_helper.c +++ b/target/arm/crypto_helper.c @@ -31,6 +31,19 @@ union CRYPTO_STATE { #define CR_ST_WORD(state, i) (state.words[i]) #endif +/* + * The caller has not been converted to full gvec, and so only + * modifies the low 16 bytes of the vector register. + */ +static void clear_tail_16(void *vd, uint32_t desc) +{ + int opr_sz = simd_oprsz(desc); + int max_sz = simd_maxsz(desc); + + assert(opr_sz == 16); + clear_tail(vd, opr_sz, max_sz); +} + static void do_crypto_aese(uint64_t *rd, uint64_t *rn, uint64_t *rm, bool decrypt) { @@ -470,7 +483,7 @@ static uint64_t s1_512(uint64_t x) return ror64(x, 19) ^ ror64(x, 61) ^ (x >> 6); } -void HELPER(crypto_sha512h)(void *vd, void *vn, void *vm) +void HELPER(crypto_sha512h)(void *vd, void *vn, void *vm, uint32_t desc) { uint64_t *rd = vd; uint64_t *rn = vn; @@ -483,9 +496,11 @@ void HELPER(crypto_sha512h)(void *vd, void *vn, void *vm) rd[0] = d0; rd[1] = d1; + + clear_tail_16(vd, desc); } -void HELPER(crypto_sha512h2)(void *vd, void *vn, void *vm) +void HELPER(crypto_sha512h2)(void *vd, void *vn, void *vm, uint32_t desc) { uint64_t *rd = vd; uint64_t *rn = vn; @@ -498,9 +513,11 @@ void HELPER(crypto_sha512h2)(void *vd, void *vn, void *vm) rd[0] = d0; rd[1] = d1; + + clear_tail_16(vd, desc); } -void HELPER(crypto_sha512su0)(void *vd, void *vn) +void HELPER(crypto_sha512su0)(void *vd, void *vn, uint32_t desc) { uint64_t *rd = vd; uint64_t *rn = vn; @@ -512,9 +529,11 @@ void HELPER(crypto_sha512su0)(void *vd, void *vn) rd[0] = d0; rd[1] = d1; + + clear_tail_16(vd, desc); } -void HELPER(crypto_sha512su1)(void *vd, void *vn, void *vm) +void HELPER(crypto_sha512su1)(void *vd, void *vn, void *vm, uint32_t desc) { uint64_t *rd = vd; uint64_t *rn = vn; @@ -522,9 +541,11 @@ void HELPER(crypto_sha512su1)(void *vd, void *vn, void *vm) rd[0] += s1_512(rn[0]) + rm[0]; rd[1] += s1_512(rn[1]) + rm[1]; + + clear_tail_16(vd, desc); } -void HELPER(crypto_sm3partw1)(void *vd, void *vn, void *vm) +void HELPER(crypto_sm3partw1)(void *vd, void *vn, void *vm, uint32_t desc) { uint64_t *rd = vd; uint64_t *rn = vn; @@ -548,9 +569,11 @@ void HELPER(crypto_sm3partw1)(void *vd, void *vn, void *vm) rd[0] = d.l[0]; rd[1] = d.l[1]; + + clear_tail_16(vd, desc); } -void HELPER(crypto_sm3partw2)(void *vd, void *vn, void *vm) +void HELPER(crypto_sm3partw2)(void *vd, void *vn, void *vm, uint32_t desc) { uint64_t *rd = vd; uint64_t *rn = vn; @@ -568,6 +591,8 @@ void HELPER(crypto_sm3partw2)(void *vd, void *vn, void *vm) rd[0] = d.l[0]; rd[1] = d.l[1]; + + clear_tail_16(vd, desc); } void HELPER(crypto_sm3tt)(void *vd, void *vn, void *vm, uint32_t imm2, diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c index 2eb4315b6d..c737a409d0 100644 --- a/target/arm/translate-a64.c +++ b/target/arm/translate-a64.c @@ -14668,28 +14668,36 @@ const GVecGen3 rax1_op = static void disas_crypto_three_reg_sha512(DisasContext *s, uint32_t insn) { static const GVecGen3 sm4ekey_op = { .fno = gen_helper_crypto_sm4ekey }; + static const GVecGen3 sha512h_op = { .fno = gen_helper_crypto_sha512h }; + static const GVecGen3 sha512h2_op + = { .fno = gen_helper_crypto_sha512h2 }; + static const GVecGen3 sha512su1_op + = { .fno = gen_helper_crypto_sha512su1 }; + static const GVecGen3 sm3partw1_op + = { .fno = gen_helper_crypto_sm3partw1 }; + static const GVecGen3 sm3partw2_op + = { .fno = gen_helper_crypto_sm3partw2 }; int opcode = extract32(insn, 10, 2); int o = extract32(insn, 14, 1); int rm = extract32(insn, 16, 5); int rn = extract32(insn, 5, 5); int rd = extract32(insn, 0, 5); bool feature; - CryptoThreeOpFn *genfn = NULL; const GVecGen3 *gvecop = NULL; if (o == 0) { switch (opcode) { case 0: /* SHA512H */ feature = dc_isar_feature(aa64_sha512, s); - genfn = gen_helper_crypto_sha512h; + gvecop = &sha512h_op; break; case 1: /* SHA512H2 */ feature = dc_isar_feature(aa64_sha512, s); - genfn = gen_helper_crypto_sha512h2; + gvecop = &sha512h2_op; break; case 2: /* SHA512SU1 */ feature = dc_isar_feature(aa64_sha512, s); - genfn = gen_helper_crypto_sha512su1; + gvecop = &sha512su1_op; break; case 3: /* RAX1 */ feature = dc_isar_feature(aa64_sha3, s); @@ -14702,11 +14710,11 @@ static void disas_crypto_three_reg_sha512(DisasContext *s, uint32_t insn) switch (opcode) { case 0: /* SM3PARTW1 */ feature = dc_isar_feature(aa64_sm3, s); - genfn = gen_helper_crypto_sm3partw1; + gvecop = &sm3partw1_op; break; case 1: /* SM3PARTW2 */ feature = dc_isar_feature(aa64_sm3, s); - genfn = gen_helper_crypto_sm3partw2; + gvecop = &sm3partw2_op; break; case 2: /* SM4EKEY */ feature = dc_isar_feature(aa64_sm4, s); @@ -14726,22 +14734,7 @@ static void disas_crypto_three_reg_sha512(DisasContext *s, uint32_t insn) if (!fp_access_check(s)) { return; } - - if (gvecop) { - gen_gvec_op3(s, true, rd, rn, rm, gvecop); - } else { - TCGv_ptr tcg_rd_ptr, tcg_rn_ptr, tcg_rm_ptr; - - tcg_rd_ptr = vec_full_reg_ptr(s, rd); - tcg_rn_ptr = vec_full_reg_ptr(s, rn); - tcg_rm_ptr = vec_full_reg_ptr(s, rm); - - genfn(tcg_rd_ptr, tcg_rn_ptr, tcg_rm_ptr); - - tcg_temp_free_ptr(tcg_rd_ptr); - tcg_temp_free_ptr(tcg_rn_ptr); - tcg_temp_free_ptr(tcg_rm_ptr); - } + gen_gvec_op3(s, true, rd, rn, rm, gvecop); } /* Crypto two-reg SHA512 @@ -14755,19 +14748,14 @@ static void disas_crypto_two_reg_sha512(DisasContext *s, uint32_t insn) int opcode = extract32(insn, 10, 2); int rn = extract32(insn, 5, 5); int rd = extract32(insn, 0, 5); - TCGv_ptr tcg_rd_ptr, tcg_rn_ptr; bool feature; - CryptoTwoOpFn *genfn; - gen_helper_gvec_3 *gvecfn = NULL; switch (opcode) { case 0: /* SHA512SU0 */ feature = dc_isar_feature(aa64_sha512, s); - genfn = gen_helper_crypto_sha512su0; break; case 1: /* SM4E */ feature = dc_isar_feature(aa64_sm4, s); - gvecfn = gen_helper_crypto_sm4e; break; default: unallocated_encoding(s); @@ -14783,18 +14771,16 @@ static void disas_crypto_two_reg_sha512(DisasContext *s, uint32_t insn) return; } - if (gvecfn) { - gen_gvec_op3_ool(s, true, rd, rd, rn, 0, gvecfn); - return; + switch (opcode) { + case 0: /* SHA512SU0 */ + gen_gvec_op2_ool(s, true, rd, rn, 0, gen_helper_crypto_sha512su0); + break; + case 1: /* SM4E */ + gen_gvec_op3_ool(s, true, rd, rd, rn, 0, gen_helper_crypto_sm4e); + break; + default: + g_assert_not_reached(); } - - tcg_rd_ptr = vec_full_reg_ptr(s, rd); - tcg_rn_ptr = vec_full_reg_ptr(s, rn); - - genfn(tcg_rd_ptr, tcg_rn_ptr); - - tcg_temp_free_ptr(tcg_rd_ptr); - tcg_temp_free_ptr(tcg_rn_ptr); } /* Crypto four-register