From patchwork Thu Feb 16 07:50:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liao Shihua X-Patchwork-Id: 57902 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp166200wrn; Wed, 15 Feb 2023 23:52:29 -0800 (PST) X-Google-Smtp-Source: AK7set86H2STMOWb+IxaOUQlwDr7k8T21YVlG0lI7+AMz9JylbaQ9eq4VCcEd/GMmEzhcuoMTMTX X-Received: by 2002:a17:906:868a:b0:87f:89f2:c012 with SMTP id g10-20020a170906868a00b0087f89f2c012mr5555335ejx.24.1676533949813; Wed, 15 Feb 2023 23:52:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676533949; cv=none; d=google.com; s=arc-20160816; b=Jag+CV8zSE1v69loclNw2Zgksh2pmDcyKhrKIebWkwHECna6lri/4X5w8eRBTL6DRG a/7E8NQ2BhK6V2/GHhuxIFQBnQXicBFJT2xUantxQf9Eq8MQnCbuHV6dUj2JSAz/2R+r UX7Uzg5L3qZDgATGe/AkP7R/sg/QoZpJgrxc7inKP9XN53BNwT4VWhDggDEqQOWBOioj 7cLAIAw644wIi4ZCJC/3i26bu/pqrKJDcXoGpMtbICpsE+NLx1J/BpehRGdWoTwgt2hZ WI8j2LlOXQXSYb/7/QEwOShyY3+rPKzGfcrzmU9O85SQ+8Rk3mcxy8nqvBFEkkStuQGe GL/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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:cc:to :from:dmarc-filter:delivered-to; bh=wqzuycXDaU/3lBKYCAkHqBsWhLtrfT8S5Dt99ShCBnU=; b=lJm5SvOo+QdqaqWXWnWihV5vdlvvLvaN0SndHJ2Yuo+ZEro1LONrpVwdk4GgQJfz0G AcBzEMIXGdDe+N0npUtTMF6lyOqfHHk32CG23XIjBAw1iM1L5LJo6Kz5ofy/aBX7aHVK x1sMjyJzY522IrPk9oLWwhAZeoaUqAmDVdiv7hwsxN6QtGK+/wpAs+UqQSPJVY+H2ilH Iq7d+R3EWkIrbIlUtEUgj7Sk2vLfPPzWhIgn01irKR46ZdSPjeiWa6HZ1RbsZYZySPUS OJiHqL0VqvDl+86mEoZ6b/ARjgxm6g9J35u9jpSJHgdIWXEGB86KnBj4Nm7N+dY9a6DL MX7w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id n17-20020a17090673d100b00877a6da8f41si978532ejl.722.2023.02.15.23.52.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Feb 2023 23:52:29 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1B4B8385800A for ; Thu, 16 Feb 2023 07:51:30 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from cstnet.cn (smtp80.cstnet.cn [159.226.251.80]) by sourceware.org (Postfix) with ESMTP id D5B6C3858C5F for ; Thu, 16 Feb 2023 07:50:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D5B6C3858C5F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=iscas.ac.cn Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=iscas.ac.cn Received: from localhost.localdomain (unknown [39.170.88.238]) by APP-01 (Coremail) with SMTP id qwCowAAXG0c54O1jP3dbBQ--.9892S5; Thu, 16 Feb 2023 15:50:20 +0800 (CST) From: Liao Shihua To: gcc-patches@gcc.gnu.org Cc: jiawei@iscas.ac.cn, kito.cheng@gmail.com, mjos@iki.fi, palmer@dabbelt.com, shiyulong@iscas.ac.cn, ben.marshall@pqshield.com, christoph.muellner@vrull.eu, Liao Shihua Subject: [PATCH V2 3/5] Implement ZKND and ZKNE extensions Date: Thu, 16 Feb 2023 15:50:03 +0800 Message-Id: <20230216075005.2600-4-shihua@iscas.ac.cn> X-Mailer: git-send-email 2.38.1.windows.1 In-Reply-To: <20230216075005.2600-1-shihua@iscas.ac.cn> References: <20230216075005.2600-1-shihua@iscas.ac.cn> MIME-Version: 1.0 X-CM-TRANSID: qwCowAAXG0c54O1jP3dbBQ--.9892S5 X-Coremail-Antispam: 1UD129KBjvAXoWfXr15Xry7JrW3KF1UAFW7twb_yoW8Xw4UCo ZYgFn5JF4fGF1I9wsI9w4fGr1DXFyvyr45Xa9YgrW5tan5Jrn5Kr1Ykan8uas7twsrXFy8 X3Z7uF4xAFWkC3s3n29KB7ZKAUJUUUU5529EdanIXcx71UUUUU7v73VFW2AGmfu7bjvjm3 AaLaJ3UjIYCTnIWjp_UUUOU7AC8VAFwI0_Wr0E3s1l1xkIjI8I6I8E6xAIw20EY4v20xva j40_Wr0E3s1l1IIY67AEw4v_Jr0_Jr4l82xGYIkIc2x26280x7IE14v26r1rM28IrcIa0x kI8VCY1x0267AKxVW5JVCq3wA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK021l84AC jcxK6xIIjxv20xvE14v26r4j6ryUM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26F4j6r4UJw A2z4x0Y4vEx4A2jsIE14v26r4UJVWxJr1l84ACjcxK6I8E87Iv6xkF7I0E14v26F4UJVW0 owAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUGVWUXwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCY1x0262kKe7AKxVWUtV W8ZwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v2 6r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2 Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUCVW8JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_ Cr0_Gr1UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JVWxJw CI42IY6I8E87Iv6xkF7I0E14v26r4UJVWxJrUvcSsGvfC2KfnxnUUI43ZEXa7VU1sYFtUU UUU== X-Originating-IP: [39.170.88.238] X-CM-SenderInfo: xvklx33d6l2u1dvotugofq/1tbiBwUEEWPt1e4jCQAAsI X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757973262746049554?= X-GMAIL-MSGID: =?utf-8?q?1757973262746049554?= This patch support Zkne and Zknd extension. It includes instruction's machine description, built-in funtion, and intrinsics. gcc/ChangeLog: * config/riscv/constraints.md (D03): New constraints of bs. (DsA):New constraints of rnum. * config/riscv/crypto.md (riscv_aes32dsi):Add ZKND,ZKNE instructions. (riscv_aes32dsmi): Likewise. (riscv_aes64ds): Likewise. (riscv_aes64dsm): Likewise. (riscv_aes64im): Likewise. (riscv_aes64ks1i): Likewise. (riscv_aes64ks2): Likewise. (riscv_aes32esi): Likewise. (riscv_aes32esmi): Likewise. (riscv_aes64es): Likewise. (riscv_aes64esm): Likewise. * config/riscv/riscv-builtins.cc (AVAIL): Add ZKND's and ZKNE's AVAIL. * config/riscv/riscv-crypto.def (DIRECT_BUILTIN):Add ZKND's and ZKNE's built-in functions. * config/riscv/riscv_scalar_crypto.h (__riscv_aes32dsi):Add ZKND's and ZKNE's intrinsics. (__riscv_aes32dsmi): Likewise. (__riscv_aes64ds): Likewise. (__riscv_aes64dsm): Likewise. (__riscv_aes64im): Likewise. (__riscv_aes64ks1i): Likewise. (__riscv_aes64ks2): Likewise. (__riscv_aes32esi): Likewise. (__riscv_aes32esmi): Likewise. (__riscv_aes64es): Likewise. (__riscv_aes64esm): Likewise. gcc/testsuite/ChangeLog: * gcc.target/riscv/zknd32.c: New test. * gcc.target/riscv/zknd64.c: New test. * gcc.target/riscv/zkne32.c: New test. * gcc.target/riscv/zkne64.c: New test. Co-Authored-By: SiYu Wu --- gcc/config/riscv/constraints.md | 8 ++ gcc/config/riscv/crypto.md | 121 +++++++++++++++++++++++- gcc/config/riscv/riscv-builtins.cc | 5 + gcc/config/riscv/riscv-crypto.def | 15 +++ gcc/config/riscv/riscv_scalar_crypto.h | 46 +++++++++ gcc/testsuite/gcc.target/riscv/zknd32.c | 18 ++++ gcc/testsuite/gcc.target/riscv/zknd64.c | 36 +++++++ gcc/testsuite/gcc.target/riscv/zkne32.c | 18 ++++ gcc/testsuite/gcc.target/riscv/zkne64.c | 30 ++++++ 9 files changed, 296 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.target/riscv/zknd32.c create mode 100644 gcc/testsuite/gcc.target/riscv/zknd64.c create mode 100644 gcc/testsuite/gcc.target/riscv/zkne32.c create mode 100644 gcc/testsuite/gcc.target/riscv/zkne64.c diff --git a/gcc/config/riscv/constraints.md b/gcc/config/riscv/constraints.md index 3637380ee47..3f46f14b10f 100644 --- a/gcc/config/riscv/constraints.md +++ b/gcc/config/riscv/constraints.md @@ -83,6 +83,14 @@ (and (match_code "const_int") (match_test "SINGLE_BIT_MASK_OPERAND (~ival)"))) +(define_constraint "D03" + "0, 1, 2 or 3 immediate" + (match_test "IN_RANGE (ival, 0, 3)")) + +(define_constraint "DsA" + "0 - 10 immediate" + (match_test "IN_RANGE (ival, 0, 10)")) + ;; Floating-point constant +0.0, used for FCVT-based moves when FMV is ;; not available in RV32. (define_constraint "G" diff --git a/gcc/config/riscv/crypto.md b/gcc/config/riscv/crypto.md index 6792f19ed68..d76a872775f 100644 --- a/gcc/config/riscv/crypto.md +++ b/gcc/config/riscv/crypto.md @@ -34,7 +34,20 @@ UNSPEC_XPERM8 UNSPEC_XPERM4 - + ;; ZKND unspecs + UNSPEC_AES_DSI + UNSPEC_AES_DSMI + UNSPEC_AES_DS + UNSPEC_AES_DSM + UNSPEC_AES_IM + UNSPEC_AES_KS1I + UNSPEC_AES_KS2 + + ;; ZKNE unspecs + UNSPEC_AES_ES + UNSPEC_AES_ESM + UNSPEC_AES_ESI + UNSPEC_AES_ESMI ]) ;; ZBKB extension @@ -128,3 +141,109 @@ "TARGET_ZBKX" "xperm8\t%0,%1,%2" [(set_attr "type" "crypto")]) + +;; ZKND extension + +(define_insn "riscv_aes32dsi" + [(set (match_operand:SI 0 "register_operand" "=r") + (unspec:SI [(match_operand:SI 1 "register_operand" "r") + (match_operand:SI 2 "register_operand" "r") + (match_operand:SI 3 "register_operand" "D03")] + UNSPEC_AES_DSI))] + "TARGET_ZKND && !TARGET_64BIT" + "aes32dsi\t%0,%1,%2,%3" + [(set_attr "type" "crypto")]) + +(define_insn "riscv_aes32dsmi" + [(set (match_operand:SI 0 "register_operand" "=r") + (unspec:SI [(match_operand:SI 1 "register_operand" "r") + (match_operand:SI 2 "register_operand" "r") + (match_operand:SI 3 "register_operand" "D03")] + UNSPEC_AES_DSMI))] + "TARGET_ZKND && !TARGET_64BIT" + "aes32dsmi\t%0,%1,%2,%3" + [(set_attr "type" "crypto")]) + +(define_insn "riscv_aes64ds" + [(set (match_operand:DI 0 "register_operand" "=r") + (unspec:DI [(match_operand:DI 1 "register_operand" "r") + (match_operand:DI 2 "register_operand" "r")] + UNSPEC_AES_DS))] + "TARGET_ZKND && TARGET_64BIT" + "aes64ds\t%0,%1,%2" + [(set_attr "type" "crypto")]) + +(define_insn "riscv_aes64dsm" + [(set (match_operand:DI 0 "register_operand" "=r") + (unspec:DI [(match_operand:DI 1 "register_operand" "r") + (match_operand:DI 2 "register_operand" "r")] + UNSPEC_AES_DSM))] + "TARGET_ZKND && TARGET_64BIT" + "aes64dsm\t%0,%1,%2" + [(set_attr "type" "crypto")]) + +(define_insn "riscv_aes64im" + [(set (match_operand:DI 0 "register_operand" "=r") + (unspec:DI [(match_operand:DI 1 "register_operand" "r")] + UNSPEC_AES_IM))] + "TARGET_ZKND && TARGET_64BIT" + "aes64im\t%0,%1" + [(set_attr "type" "crypto")]) + +(define_insn "riscv_aes64ks1i" + [(set (match_operand:DI 0 "register_operand" "=r") + (unspec:DI [(match_operand:DI 1 "register_operand" "r") + (match_operand:SI 2 "register_operand" "DsA")] + UNSPEC_AES_KS1I))] + "(TARGET_ZKND || TARGET_ZKNE) && TARGET_64BIT" + "aes64ks1i\t%0,%1,%2" + [(set_attr "type" "crypto")]) + +(define_insn "riscv_aes64ks2" + [(set (match_operand:DI 0 "register_operand" "=r") + (unspec:DI [(match_operand:DI 1 "register_operand" "r") + (match_operand:DI 2 "register_operand" "r")] + UNSPEC_AES_KS2))] + "(TARGET_ZKND || TARGET_ZKNE) && TARGET_64BIT" + "aes64ks2\t%0,%1,%2" + [(set_attr "type" "crypto")]) + +;; ZKNE extension + +(define_insn "riscv_aes32esi" + [(set (match_operand:SI 0 "register_operand" "=r") + (unspec:SI [(match_operand:SI 1 "register_operand" "r") + (match_operand:SI 2 "register_operand" "r") + (match_operand:SI 3 "register_operand" "D03")] + UNSPEC_AES_ESI))] + "TARGET_ZKNE && !TARGET_64BIT" + "aes32esi\t%0,%1,%2,%3" + [(set_attr "type" "crypto")]) + +(define_insn "riscv_aes32esmi" + [(set (match_operand:SI 0 "register_operand" "=r") + (unspec:SI [(match_operand:SI 1 "register_operand" "r") + (match_operand:SI 2 "register_operand" "r") + (match_operand:SI 3 "register_operand" "D03")] + UNSPEC_AES_ESMI))] + "TARGET_ZKNE && !TARGET_64BIT" + "aes32esmi\t%0,%1,%2,%3" + [(set_attr "type" "crypto")]) + +(define_insn "riscv_aes64es" + [(set (match_operand:DI 0 "register_operand" "=r") + (unspec:DI [(match_operand:DI 1 "register_operand" "r") + (match_operand:DI 2 "register_operand" "r")] + UNSPEC_AES_ES))] + "TARGET_ZKNE && TARGET_64BIT" + "aes64es\t%0,%1,%2" + [(set_attr "type" "crypto")]) + +(define_insn "riscv_aes64esm" + [(set (match_operand:DI 0 "register_operand" "=r") + (unspec:DI [(match_operand:DI 1 "register_operand" "r") + (match_operand:DI 2 "register_operand" "r")] + UNSPEC_AES_ESM))] + "TARGET_ZKNE && TARGET_64BIT" + "aes64esm\t%0,%1,%2" + [(set_attr "type" "crypto")]) diff --git a/gcc/config/riscv/riscv-builtins.cc b/gcc/config/riscv/riscv-builtins.cc index e9c2d92f0d3..b92619f99e4 100644 --- a/gcc/config/riscv/riscv-builtins.cc +++ b/gcc/config/riscv/riscv-builtins.cc @@ -106,6 +106,11 @@ AVAIL (crypto_zbkc32, TARGET_ZBKC && !TARGET_64BIT) AVAIL (crypto_zbkc64, TARGET_ZBKC && TARGET_64BIT) AVAIL (crypto_zbkx32, TARGET_ZBKX && !TARGET_64BIT) AVAIL (crypto_zbkx64, TARGET_ZBKX && TARGET_64BIT) +AVAIL (crypto_zknd32, TARGET_ZKND && !TARGET_64BIT) +AVAIL (crypto_zknd64, TARGET_ZKND && TARGET_64BIT) +AVAIL (crypto_zkne32, TARGET_ZKNE && !TARGET_64BIT) +AVAIL (crypto_zkne64, TARGET_ZKNE && TARGET_64BIT) +AVAIL (crypto_zkne_or_zknd, (TARGET_ZKNE || TARGET_ZKND) && TARGET_64BIT) AVAIL (always, (!0)) /* Construct a riscv_builtin_description from the given arguments. diff --git a/gcc/config/riscv/riscv-crypto.def b/gcc/config/riscv/riscv-crypto.def index ebb82629296..57d031c2e09 100644 --- a/gcc/config/riscv/riscv-crypto.def +++ b/gcc/config/riscv/riscv-crypto.def @@ -43,3 +43,18 @@ RISCV_BUILTIN (xperm4_si, "xperm4", RISCV_BUILTIN_DIRECT, RISCV_SI_FTYPE_SI_SI, RISCV_BUILTIN (xperm4_di, "xperm4", RISCV_BUILTIN_DIRECT, RISCV_DI_FTYPE_DI_DI, crypto_zbkx64), RISCV_BUILTIN (xperm8_si, "xperm8", RISCV_BUILTIN_DIRECT, RISCV_SI_FTYPE_SI_SI, crypto_zbkx32), RISCV_BUILTIN (xperm8_di, "xperm8", RISCV_BUILTIN_DIRECT, RISCV_DI_FTYPE_DI_DI, crypto_zbkx64), + +// ZKND +DIRECT_BUILTIN (aes32dsi, RISCV_SI_FTYPE_SI_SI_SI, crypto_zknd32), +DIRECT_BUILTIN (aes32dsmi, RISCV_SI_FTYPE_SI_SI_SI, crypto_zknd32), +DIRECT_BUILTIN (aes64ds, RISCV_DI_FTYPE_DI_DI, crypto_zknd64), +DIRECT_BUILTIN (aes64dsm, RISCV_DI_FTYPE_DI_DI, crypto_zknd64), +DIRECT_BUILTIN (aes64im, RISCV_DI_FTYPE_DI, crypto_zknd64), +DIRECT_BUILTIN (aes64ks1i, RISCV_DI_FTYPE_DI_SI, crypto_zkne_or_zknd), +DIRECT_BUILTIN (aes64ks2, RISCV_DI_FTYPE_DI_DI, crypto_zkne_or_zknd), + +// ZKNE +DIRECT_BUILTIN (aes32esi, RISCV_SI_FTYPE_SI_SI_SI, crypto_zkne32), +DIRECT_BUILTIN (aes32esmi, RISCV_SI_FTYPE_SI_SI_SI, crypto_zkne32), +DIRECT_BUILTIN (aes64es, RISCV_DI_FTYPE_DI_DI, crypto_zkne64), +DIRECT_BUILTIN (aes64esm, RISCV_DI_FTYPE_DI_DI, crypto_zkne64), diff --git a/gcc/config/riscv/riscv_scalar_crypto.h b/gcc/config/riscv/riscv_scalar_crypto.h index 2e2644fa323..3418bcf5774 100644 --- a/gcc/config/riscv/riscv_scalar_crypto.h +++ b/gcc/config/riscv/riscv_scalar_crypto.h @@ -102,3 +102,49 @@ static inline long __riscv_xperm8(long rs1, long rs2) static inline long __riscv_xperm4(long rs1, long rs2) { return _RVK_INTRIN_IMPL(xperm4_64)(rs1, rs2); } // XPERM4 + + +// === (mapping) Zknd: NIST Suite: AES Decryption + +#ifdef RVKINTRIN_RV32 +static inline int32_t __riscv_aes32dsi(int32_t rs1, int32_t rs2, int bs) + { return _RVK_INTRIN_IMPL(aes32dsi)(rs1, rs2, bs); } // AES32DSI + +static inline int32_t __riscv_aes32dsmi(int32_t rs1, int32_t rs2, int bs) + { return _RVK_INTRIN_IMPL(aes32dsmi)(rs1, rs2, bs); } // AES32DSMI +#endif + +#ifdef RVKINTRIN_RV64 +static inline int64_t __riscv_aes64ds(int64_t rs1, int64_t rs2) + { return _RVK_INTRIN_IMPL(aes64ds)(rs1, rs2); } // AES64DS + +static inline int64_t __riscv_aes64dsm(int64_t rs1, int64_t rs2) + { return _RVK_INTRIN_IMPL(aes64dsm)(rs1, rs2); } // AES64DSM + +static inline int64_t __riscv_aes64im(int64_t rs1) + { return _RVK_INTRIN_IMPL(aes64im)(rs1); } // AES64IM + +static inline int64_t __riscv_aes64ks1i(int64_t rs1, int rnum) + { return _RVK_INTRIN_IMPL(aes64ks1i)(rs1, rnum); } // AES64KS1I + +static inline int64_t __riscv_aes64ks2(int64_t rs1, int64_t rs2) + { return _RVK_INTRIN_IMPL(aes64ks2)(rs1, rs2); } // AES64KS2 +#endif + +// === (mapping) Zkne: NIST Suite: AES Encryption + +#ifdef RVKINTRIN_RV32 +static inline int32_t __riscv_aes32esi(int32_t rs1, int32_t rs2, int bs) + { return _RVK_INTRIN_IMPL(aes32esi)(rs1, rs2, bs); } // AES32ESI + +static inline int32_t __riscv_aes32esmi(int32_t rs1, int32_t rs2, int bs) + { return _RVK_INTRIN_IMPL(aes32esmi)(rs1, rs2, bs); } // AES32ESMI +#endif + +#ifdef RVKINTRIN_RV64 +static inline int64_t __riscv_aes64es(int64_t rs1, int64_t rs2) + { return _RVK_INTRIN_IMPL(aes64es)(rs1, rs2); } // AES64ES + +static inline int64_t __riscv_aes64esm(int64_t rs1, int64_t rs2) + { return _RVK_INTRIN_IMPL(aes64esm)(rs1, rs2); } // AES64ESM +#endif diff --git a/gcc/testsuite/gcc.target/riscv/zknd32.c b/gcc/testsuite/gcc.target/riscv/zknd32.c new file mode 100644 index 00000000000..b7bde2bb20d --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/zknd32.c @@ -0,0 +1,18 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -march=rv32gc_zknd -mabi=ilp32d" } */ +/* { dg-skip-if "" { *-*-* } { "-g" "-flto"} } */ + +#include "riscv_scalar_crypto.h" + +int32_t foo1(int32_t rs1, int32_t rs2, int bs) +{ + return __riscv_aes32dsi(rs1,rs2,bs); +} + +int32_t foo2(int32_t rs1, int32_t rs2, int bs) +{ + return __riscv_aes32dsmi(rs1,rs2,bs); +} + +/* { dg-final { scan-assembler-times "aes32dsi" 1 } } */ +/* { dg-final { scan-assembler-times "aes32dsmi" 1 } } */ diff --git a/gcc/testsuite/gcc.target/riscv/zknd64.c b/gcc/testsuite/gcc.target/riscv/zknd64.c new file mode 100644 index 00000000000..8ad3c55341c --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/zknd64.c @@ -0,0 +1,36 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -march=rv64gc_zknd -mabi=lp64" } */ +/* { dg-skip-if "" { *-*-* } { "-g" "-flto"} } */ + +#include"riscv_scalar_crypto.h" + +int64_t foo1(int64_t rs1, int64_t rs2) +{ + return __riscv_aes64ds(rs1,rs2); +} + +int64_t foo2(int64_t rs1, int64_t rs2) +{ + return __riscv_aes64dsm(rs1,rs2); +} + +int64_t foo3(int64_t rs1, int rnum) +{ + return __riscv_aes64ks1i(rs1,rnum); +} + +int64_t foo4(int64_t rs1, int64_t rs2) +{ + return __riscv_aes64ks2(rs1,rs2); +} + +int64_t foo5(int64_t rs1) +{ + return __riscv_aes64im(rs1); +} + +/* { dg-final { scan-assembler-times "aes64ds\t" 1 } } */ +/* { dg-final { scan-assembler-times "aes64dsm" 1 } } */ +/* { dg-final { scan-assembler-times "aes64ks1i" 1 } } */ +/* { dg-final { scan-assembler-times "aes64ks2" 1 } } */ +/* { dg-final { scan-assembler-times "aes64im" 1 } } */ diff --git a/gcc/testsuite/gcc.target/riscv/zkne32.c b/gcc/testsuite/gcc.target/riscv/zkne32.c new file mode 100644 index 00000000000..48a1dda8a3e --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/zkne32.c @@ -0,0 +1,18 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -march=rv32gc_zkne -mabi=ilp32d" } */ +/* { dg-skip-if "" { *-*-* } { "-g" "-flto"} } */ + +#include "riscv_scalar_crypto.h" + +int32_t foo1(int32_t rs1, int32_t rs2, int bs) +{ + return __riscv_aes32esi(rs1, rs2, bs); +} + +int32_t foo2(int32_t rs1, int32_t rs2, int bs) +{ + return __riscv_aes32esmi(rs1, rs2, bs); +} + +/* { dg-final { scan-assembler-times "aes32esi" 1 } } */ +/* { dg-final { scan-assembler-times "aes32esmi" 1 } } */ diff --git a/gcc/testsuite/gcc.target/riscv/zkne64.c b/gcc/testsuite/gcc.target/riscv/zkne64.c new file mode 100644 index 00000000000..6d5be92f666 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/zkne64.c @@ -0,0 +1,30 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -march=rv64gc_zkne -mabi=lp64" } */ +/* { dg-skip-if "" { *-*-* } { "-g" "-flto"} } */ + +#include"riscv_scalar_crypto.h" + +int64_t foo1(int64_t rs1, int64_t rs2) +{ + return __riscv_aes64es(rs1,rs2); +} + +int64_t foo2(int64_t rs1, int64_t rs2) +{ + return __riscv_aes64esm(rs1,rs2); +} + +int64_t foo3(int64_t rs1, int rnum) +{ + return __riscv_aes64ks1i(rs1,rnum); +} + +int64_t foo4(int64_t rs1, int64_t rs2) +{ + return __riscv_aes64ks2(rs1,rs2); +} + +/* { dg-final { scan-assembler-times "aes64es\t" 1 } } */ +/* { dg-final { scan-assembler-times "aes64esm" 1 } } */ +/* { dg-final { scan-assembler-times "aes64ks1i" 1 } } */ +/* { dg-final { scan-assembler-times "aes64ks2" 1 } } */