From patchwork Wed Feb 7 11:17:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 127161 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp370111ljc; Wed, 7 Feb 2018 03:21:26 -0800 (PST) X-Google-Smtp-Source: AH8x227e1cKE/q1TDbZorSENTi7sPsmXFe1pVF3ec9Cm8+uKKkBQDjdLSz4AJiE8Pg+CTFPbdq+j X-Received: by 10.37.129.80 with SMTP id j16mr3811751ybm.9.1518002485907; Wed, 07 Feb 2018 03:21:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518002485; cv=none; d=google.com; s=arc-20160816; b=EKxFdRVLhmSZiarVxdIRVc41uOhDENze+sl04ip8+JDwLxrnZXzIW2NDg0A5+7inAO oJ6lzbbZbj+qegZEBwV5+LBnXhaoMfdy8oEAl9+9KHVe4AQIXy5Z3RlTQ9FJksrOKggO 19tU+prxEzjd4DRcEnBzYT+4sOolULxpysMa1m9KJ9SWB+8fOE9mRlEPqzxBd0qLno5B tpi7rnYyq+VdhnJiFVQ9Sft4MtZV2X77+0NByrHmS1otR0hskGZevnStpPJXPYYGUDMI QKbY5/w5iIPhQvzkOn8XH9s1xlsKLQ80GEYoPv6dOu6adKJLpFnahTKH93Z1AMT5dUQv PlMg== 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:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=nMYG/iSulvXqEwNwjkM6ocfYpRorwzriEirPf9UIYks=; b=z11fLFOEn8XKy1DC26tFAAXxXe2D+br9toK+lR4PeGibJ/XEcNa9GKJrBHJ2WkuC3a 5TLwComUSC/kwuUNcPgx2SN4t9XiQuVxnPag1KPaoRmYBDxZMUDISb9uZkXcAgdCT1C1 CXf5qei7HCju+3KlZDRcjS56fhhAkok1kSe87I0L5R2dwKuE6Mq3cayux4inKFb53GmI 07epaEtRYYe9wnGj6D5J77LzKLFXGr61BqGypjO0C/dg8IuIItMAlMVLMcHjx8Gjvwoh nmMh6XL41Rh7HZiGCsl+FGphZ8rk5WunN6FxF0DEUNO5GMJVcWH5rBYYZvf3ztS+ls6+ 3nig== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=A17M+oor; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id f84si213494ywf.598.2018.02.07.03.21.25 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 07 Feb 2018 03:21:25 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=A17M+oor; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:51714 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ejNn3-000878-5G for patch@linaro.org; Wed, 07 Feb 2018 06:21:25 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38764) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ejNjV-0005E0-5m for qemu-devel@nongnu.org; Wed, 07 Feb 2018 06:17:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ejNjT-0005g2-Rf for qemu-devel@nongnu.org; Wed, 07 Feb 2018 06:17:45 -0500 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]:34348) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ejNjT-0005fD-HX for qemu-devel@nongnu.org; Wed, 07 Feb 2018 06:17:43 -0500 Received: by mail-wm0-x243.google.com with SMTP id j21-v6so22162425wmh.1 for ; Wed, 07 Feb 2018 03:17:43 -0800 (PST) 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; bh=nMYG/iSulvXqEwNwjkM6ocfYpRorwzriEirPf9UIYks=; b=A17M+oorxHpbJoxhD1gb5YWn6anaWbf+qJcdKin2kqwyKS5eHEGy0PcGcI8HILo8PK QOHQ5Y3/Uk0yWWLE8odms015jyyTTASUiqYyEJqCOODjbIE3JHr3QRWBPIWyrcT11nAj rTbpYak3SgKZjGu0INWVII/rP34Qf82dIaxKE= 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; bh=nMYG/iSulvXqEwNwjkM6ocfYpRorwzriEirPf9UIYks=; b=fnGF+oiBM9QdyxGW6y9SNcmblmzC7uRoBSNTnbjJMv3fXoh5xzoVy95RaCGZU6+hqM r7AFvv+jF1ftcgCBRGEQzLuaWOov3nNwrjjpZZyuu+zq6X9XGzfvgLFolDCGOXzam6Ua O+NZV980p8fvKomFUJ+sX6ffbUmsIx7b5t9VYm3yb6/rF9BGffgQz8gL/SjsGymrFLmR XOZSQtDwrfTpwPrHN1K2ZSp5v6Fhhv3lUz4qsoTDKzIhPk1tWStA6bnYWR4b3EbwxKgU sso9t70bljm0CeJE34Ofk3IakKkfq1esCmVdPLrDbo4Xf8IuqftLFN+3znaLrtHorkJC OLBQ== X-Gm-Message-State: APf1xPDV3I62eX/Cya+kDnrA1toStyKpVaP0CqRYUWz5SDRYAGrG0WJI x6gijy4WqoE1/RTsTIgdp71L3t0SXjQ= X-Received: by 10.28.185.196 with SMTP id j187mr4914438wmf.94.1518002262072; Wed, 07 Feb 2018 03:17:42 -0800 (PST) Received: from localhost.localdomain ([196.85.252.149]) by smtp.gmail.com with ESMTPSA id h32sm627629wrf.65.2018.02.07.03.17.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Feb 2018 03:17:40 -0800 (PST) From: Ard Biesheuvel To: qemu-devel@nongnu.org Date: Wed, 7 Feb 2018 11:17:26 +0000 Message-Id: <20180207111729.15737-3-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180207111729.15737-1-ard.biesheuvel@linaro.org> References: <20180207111729.15737-1-ard.biesheuvel@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::243 Subject: [Qemu-devel] [PATCH v6 2/5] target/arm: implement SHA-3 instructions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Ard Biesheuvel Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This implements emulation of the new SHA-3 instructions that have been added as an optional extensions to the ARMv8 Crypto Extensions in ARM v8.2. Signed-off-by: Ard Biesheuvel --- target/arm/cpu.h | 1 + target/arm/translate-a64.c | 148 +++++++++++++++++++- 2 files changed, 145 insertions(+), 4 deletions(-) -- 2.11.0 diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 32a18510e70b..d0b19e0cbc88 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -1373,6 +1373,7 @@ enum arm_features { ARM_FEATURE_JAZELLE, /* has (trivial) Jazelle implementation */ ARM_FEATURE_SVE, /* has Scalable Vector Extension */ ARM_FEATURE_V8_SHA512, /* implements SHA512 part of v8 Crypto Extensions */ + ARM_FEATURE_V8_SHA3, /* implements SHA3 part of v8 Crypto Extensions */ }; static inline int arm_feature(CPUARMState *env, int feature) diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c index 888f5a39a283..f697a51ca7ec 100644 --- a/target/arm/translate-a64.c +++ b/target/arm/translate-a64.c @@ -11162,9 +11162,10 @@ static void disas_crypto_three_reg_sha512(DisasContext *s, uint32_t insn) feature = ARM_FEATURE_V8_SHA512; genfn = gen_helper_crypto_sha512su1; break; - default: - unallocated_encoding(s); - return; + case 3: /* RAX1 */ + feature = ARM_FEATURE_V8_SHA3; + genfn = NULL; + break; } } else { unallocated_encoding(s); @@ -11193,7 +11194,28 @@ static void disas_crypto_three_reg_sha512(DisasContext *s, uint32_t insn) tcg_temp_free_ptr(tcg_rn_ptr); tcg_temp_free_ptr(tcg_rm_ptr); } else { - g_assert_not_reached(); + TCGv_i64 tcg_op1, tcg_op2, tcg_res[2]; + int pass; + + tcg_op1 = tcg_temp_new_i64(); + tcg_op2 = tcg_temp_new_i64(); + tcg_res[0] = tcg_temp_new_i64(); + tcg_res[1] = tcg_temp_new_i64(); + + for (pass = 0; pass < 2; pass++) { + read_vec_element(s, tcg_op1, rn, pass, MO_64); + read_vec_element(s, tcg_op2, rm, pass, MO_64); + + tcg_gen_rotli_i64(tcg_res[pass], tcg_op2, 1); + tcg_gen_xor_i64(tcg_res[pass], tcg_res[pass], tcg_op1); + } + write_vec_element(s, tcg_res[0], rd, 0, MO_64); + write_vec_element(s, tcg_res[1], rd, 1, MO_64); + + tcg_temp_free_i64(tcg_op1); + tcg_temp_free_i64(tcg_op2); + tcg_temp_free_i64(tcg_res[0]); + tcg_temp_free_i64(tcg_res[1]); } } @@ -11240,6 +11262,122 @@ static void disas_crypto_two_reg_sha512(DisasContext *s, uint32_t insn) tcg_temp_free_ptr(tcg_rn_ptr); } +/* Crypto four-register + * 31 23 22 21 20 16 15 14 10 9 5 4 0 + * +-------------------+-----+------+---+------+------+------+ + * | 1 1 0 0 1 1 1 0 0 | Op0 | Rm | 0 | Ra | Rn | Rd | + * +-------------------+-----+------+---+------+------+------+ + */ +static void disas_crypto_four_reg(DisasContext *s, uint32_t insn) +{ + int op0 = extract32(insn, 21, 2); + int rm = extract32(insn, 16, 5); + int ra = extract32(insn, 10, 5); + int rn = extract32(insn, 5, 5); + int rd = extract32(insn, 0, 5); + int feature; + + switch (op0) { + case 0: /* EOR3 */ + case 1: /* BCAX */ + feature = ARM_FEATURE_V8_SHA3; + break; + default: + unallocated_encoding(s); + return; + } + + if (!arm_dc_feature(s, feature)) { + unallocated_encoding(s); + return; + } + + if (!fp_access_check(s)) { + return; + } + + if (op0 < 2) { + TCGv_i64 tcg_op1, tcg_op2, tcg_op3, tcg_res[2]; + int pass; + + tcg_op1 = tcg_temp_new_i64(); + tcg_op2 = tcg_temp_new_i64(); + tcg_op3 = tcg_temp_new_i64(); + tcg_res[0] = tcg_temp_new_i64(); + tcg_res[1] = tcg_temp_new_i64(); + + for (pass = 0; pass < 2; pass++) { + read_vec_element(s, tcg_op1, rn, pass, MO_64); + read_vec_element(s, tcg_op2, rm, pass, MO_64); + read_vec_element(s, tcg_op3, ra, pass, MO_64); + + if (op0 == 0) { + /* EOR3 */ + tcg_gen_xor_i64(tcg_res[pass], tcg_op2, tcg_op3); + } else { + /* BCAX */ + tcg_gen_andc_i64(tcg_res[pass], tcg_op2, tcg_op3); + } + tcg_gen_xor_i64(tcg_res[pass], tcg_res[pass], tcg_op1); + } + write_vec_element(s, tcg_res[0], rd, 0, MO_64); + write_vec_element(s, tcg_res[1], rd, 1, MO_64); + + tcg_temp_free_i64(tcg_op1); + tcg_temp_free_i64(tcg_op2); + tcg_temp_free_i64(tcg_op3); + tcg_temp_free_i64(tcg_res[0]); + tcg_temp_free_i64(tcg_res[1]); + } else { + g_assert_not_reached(); + } +} + +/* Crypto XAR + * 31 21 20 16 15 10 9 5 4 0 + * +-----------------------+------+--------+------+------+ + * | 1 1 0 0 1 1 1 0 1 0 0 | Rm | imm6 | Rn | Rd | + * +-----------------------+------+--------+------+------+ + */ +static void disas_crypto_xar(DisasContext *s, uint32_t insn) +{ + int rm = extract32(insn, 16, 5); + int imm6 = extract32(insn, 10, 6); + int rn = extract32(insn, 5, 5); + int rd = extract32(insn, 0, 5); + TCGv_i64 tcg_op1, tcg_op2, tcg_res[2]; + int pass; + + if (!arm_dc_feature(s, ARM_FEATURE_V8_SHA3)) { + unallocated_encoding(s); + return; + } + + if (!fp_access_check(s)) { + return; + } + + tcg_op1 = tcg_temp_new_i64(); + tcg_op2 = tcg_temp_new_i64(); + tcg_res[0] = tcg_temp_new_i64(); + tcg_res[1] = tcg_temp_new_i64(); + + for (pass = 0; pass < 2; pass++) { + read_vec_element(s, tcg_op1, rn, pass, MO_64); + read_vec_element(s, tcg_op2, rm, pass, MO_64); + + tcg_gen_xor_i64(tcg_res[pass], tcg_op1, tcg_op2); + tcg_gen_rotri_i64(tcg_res[pass], tcg_res[pass], imm6); + } + write_vec_element(s, tcg_res[0], rd, 0, MO_64); + write_vec_element(s, tcg_res[1], rd, 1, MO_64); + + tcg_temp_free_i64(tcg_op1); + tcg_temp_free_i64(tcg_op2); + tcg_temp_free_i64(tcg_res[0]); + tcg_temp_free_i64(tcg_res[1]); +} + /* C3.6 Data processing - SIMD, inc Crypto * * As the decode gets a little complex we are using a table based @@ -11271,6 +11409,8 @@ static const AArch64DecodeTable data_proc_simd[] = { { 0x5e280800, 0xff3e0c00, disas_crypto_two_reg_sha }, { 0xce608000, 0xffe0b000, disas_crypto_three_reg_sha512 }, { 0xcec08000, 0xfffff000, disas_crypto_two_reg_sha512 }, + { 0xce000000, 0xff808000, disas_crypto_four_reg }, + { 0xce800000, 0xffe00000, disas_crypto_xar }, { 0x00000000, 0x00000000, NULL } };