public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Christoph Muellner <christoph.muellner@vrull.eu>
To: gcc-patches@gcc.gnu.org, Kito Cheng <kito.cheng@sifive.com>,
	Jim Wilson <jim.wilson.gcc@gmail.com>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	Andrew Waterman <andrew@sifive.com>,
	Philipp Tomsich <philipp.tomsich@vrull.eu>,
	Jeff Law <jeffreyalaw@gmail.com>,
	Aaron Durbin <adurbin@rivosinc.com>,
	Vineet Gupta <vineetg@rivosinc.com>,
	Andrew de los Reyes <adlr@rivosinc.com>,
	Eric Gouriou <ego@rivosinc.com>,
	Barna Ibrahim <barna@rivosinc.com>
Cc: "Christoph Müllner" <christoph.muellner@vrull.eu>
Subject: [RFC PATCH] RISC-V: Add support for vector crypto extensions
Date: Wed, 21 Dec 2022 19:31:03 +0100	[thread overview]
Message-ID: <20221221183103.3800844-1-christoph.muellner@vrull.eu> (raw)

From: Christoph Müllner <christoph.muellner@vrull.eu>

This series adds basic support for the vector crypto extensions:
* Zvkb
* Zvkg
* Zvkh[a,b]
* Zvkn
* Zvksed
* Zvksh

The implementation follows the version 20221220 of the specification,
which can be found here:
  https://github.com/riscv/riscv-crypto/releases/tag/v20221220

Note, that this specification is not frozen yet, meaning that
incompatible changes are possible.
Therefore, this patchset is marked as RFC and should not be considered
for upstream inclusion.

All extensions come with (passing) tests for the feature test macros.

A Binutils patch series for vector crypto support can be found here:
  https://sourceware.org/pipermail/binutils/2022-December/125272.html

Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu>
---
 gcc/common/config/riscv/riscv-common.cc | 16 ++++++++++++++++
 gcc/config/riscv/riscv-opts.h           | 16 ++++++++++++++++
 gcc/config/riscv/riscv.opt              |  3 +++
 gcc/testsuite/gcc.target/riscv/zvkb.c   | 13 +++++++++++++
 gcc/testsuite/gcc.target/riscv/zvkg.c   | 13 +++++++++++++
 gcc/testsuite/gcc.target/riscv/zvkha.c  | 13 +++++++++++++
 gcc/testsuite/gcc.target/riscv/zvkhb.c  | 13 +++++++++++++
 gcc/testsuite/gcc.target/riscv/zvkn.c   | 13 +++++++++++++
 gcc/testsuite/gcc.target/riscv/zvksed.c | 13 +++++++++++++
 gcc/testsuite/gcc.target/riscv/zvksh.c  | 13 +++++++++++++
 10 files changed, 126 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/riscv/zvkb.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/zvkg.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/zvkha.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/zvkhb.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/zvkn.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/zvksed.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/zvksh.c

diff --git a/gcc/common/config/riscv/riscv-common.cc b/gcc/common/config/riscv/riscv-common.cc
index 4b7f777c103..dfd654eea24 100644
--- a/gcc/common/config/riscv/riscv-common.cc
+++ b/gcc/common/config/riscv/riscv-common.cc
@@ -201,6 +201,14 @@ static const struct riscv_ext_version riscv_ext_version_table[] =
   {"zve64f", ISA_SPEC_CLASS_NONE, 1, 0},
   {"zve64d", ISA_SPEC_CLASS_NONE, 1, 0},
 
+  {"zvkb", ISA_SPEC_CLASS_NONE, 1, 0},
+  {"zvkg", ISA_SPEC_CLASS_NONE, 1, 0},
+  {"zvkha", ISA_SPEC_CLASS_NONE, 1, 0},
+  {"zvkhb", ISA_SPEC_CLASS_NONE, 1, 0},
+  {"zvkn", ISA_SPEC_CLASS_NONE, 1, 0},
+  {"zvksed", ISA_SPEC_CLASS_NONE, 1, 0},
+  {"zvksh", ISA_SPEC_CLASS_NONE, 1, 0},
+
   {"zvl32b", ISA_SPEC_CLASS_NONE, 1, 0},
   {"zvl64b", ISA_SPEC_CLASS_NONE, 1, 0},
   {"zvl128b", ISA_SPEC_CLASS_NONE, 1, 0},
@@ -1226,6 +1234,14 @@ static const riscv_ext_flag_table_t riscv_ext_flag_table[] =
   {"zve64f",   &gcc_options::x_riscv_vector_elen_flags, MASK_VECTOR_ELEN_FP_32},
   {"zve64d",   &gcc_options::x_riscv_vector_elen_flags, MASK_VECTOR_ELEN_FP_64},
 
+  {"zvkb",     &gcc_options::x_riscv_zvk_subext, MASK_ZVKB},
+  {"zvkg",     &gcc_options::x_riscv_zvk_subext, MASK_ZVKG},
+  {"zvkha",    &gcc_options::x_riscv_zvk_subext, MASK_ZVKHA},
+  {"zvkhb",    &gcc_options::x_riscv_zvk_subext, MASK_ZVKHB},
+  {"zvkn",     &gcc_options::x_riscv_zvk_subext, MASK_ZVKN},
+  {"zvksed",   &gcc_options::x_riscv_zvk_subext, MASK_ZVKSED},
+  {"zvksh",    &gcc_options::x_riscv_zvk_subext, MASK_ZVKSH},
+
   {"zvl32b",    &gcc_options::x_riscv_zvl_flags, MASK_ZVL32B},
   {"zvl64b",    &gcc_options::x_riscv_zvl_flags, MASK_ZVL64B},
   {"zvl128b",   &gcc_options::x_riscv_zvl_flags, MASK_ZVL128B},
diff --git a/gcc/config/riscv/riscv-opts.h b/gcc/config/riscv/riscv-opts.h
index 25fd85b09b1..5b367bd194c 100644
--- a/gcc/config/riscv/riscv-opts.h
+++ b/gcc/config/riscv/riscv-opts.h
@@ -132,6 +132,22 @@ enum stack_protector_guard {
 #define TARGET_VECTOR_ELEN_FP_64 \
   ((riscv_vector_elen_flags & MASK_VECTOR_ELEN_FP_64) != 0)
 
+#define MASK_ZVKB      (1 << 0)
+#define MASK_ZVKG      (1 << 1)
+#define MASK_ZVKHA     (1 << 2)
+#define MASK_ZVKHB     (1 << 3)
+#define MASK_ZVKN      (1 << 4)
+#define MASK_ZVKSED    (1 << 5)
+#define MASK_ZVKSH     (1 << 6)
+
+#define TARGET_ZVKB    ((riscv_zvk_subext & MASK_ZVKB) != 0)
+#define TARGET_ZVKG    ((riscv_zvk_subext & MASK_ZVKG) != 0)
+#define TARGET_ZVKHA   ((riscv_zvk_subext & MASK_ZVKHA) != 0)
+#define TARGET_ZVKHB   ((riscv_zvk_subext & MASK_ZVKHB) != 0)
+#define TARGET_ZVKN    ((riscv_zvk_subext & MASK_ZVKN) != 0)
+#define TARGET_ZVKSED  ((riscv_zvk_subext & MASK_ZVKSED) != 0)
+#define TARGET_ZVKSH   ((riscv_zvk_subext & MASK_ZVKSH) != 0)
+
 #define MASK_ZVL32B    (1 <<  0)
 #define MASK_ZVL64B    (1 <<  1)
 #define MASK_ZVL128B   (1 <<  2)
diff --git a/gcc/config/riscv/riscv.opt b/gcc/config/riscv/riscv.opt
index 7c3ca48d1cc..ea24a80d734 100644
--- a/gcc/config/riscv/riscv.opt
+++ b/gcc/config/riscv/riscv.opt
@@ -218,6 +218,9 @@ int riscv_zk_subext
 TargetVariable
 int riscv_vector_elen_flags
 
+TargetVariable
+int riscv_zvk_subext
+
 TargetVariable
 int riscv_zvl_flags
 
diff --git a/gcc/testsuite/gcc.target/riscv/zvkb.c b/gcc/testsuite/gcc.target/riscv/zvkb.c
new file mode 100644
index 00000000000..7116e98921c
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/zvkb.c
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gc_zvkb" { target { rv64 } } } */
+/* { dg-options "-march=rv32gc_zvkb" { target { rv32 } } } */
+
+#ifndef __riscv_zvkb
+#error Feature macro not defined
+#endif
+
+int
+foo (int a)
+{
+  return a;
+}
diff --git a/gcc/testsuite/gcc.target/riscv/zvkg.c b/gcc/testsuite/gcc.target/riscv/zvkg.c
new file mode 100644
index 00000000000..1e2a05aa1d8
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/zvkg.c
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gc_zvkg" { target { rv64 } } } */
+/* { dg-options "-march=rv32gc_zvkg" { target { rv32 } } } */
+
+#ifndef __riscv_zvkg
+#error Feature macro not defined
+#endif
+
+int
+foo (int a)
+{
+  return a;
+}
diff --git a/gcc/testsuite/gcc.target/riscv/zvkha.c b/gcc/testsuite/gcc.target/riscv/zvkha.c
new file mode 100644
index 00000000000..ca4e8d4c561
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/zvkha.c
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gc_zvkha" { target { rv64 } } } */
+/* { dg-options "-march=rv32gc_zvkha" { target { rv32 } } } */
+
+#ifndef __riscv_zvkha
+#error Feature macro not defined
+#endif
+
+int
+foo (int a)
+{
+  return a;
+}
diff --git a/gcc/testsuite/gcc.target/riscv/zvkhb.c b/gcc/testsuite/gcc.target/riscv/zvkhb.c
new file mode 100644
index 00000000000..8fa25ff52ee
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/zvkhb.c
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gc_zvkhb" { target { rv64 } } } */
+/* { dg-options "-march=rv32gc_zvkhb" { target { rv32 } } } */
+
+#ifndef __riscv_zvkhb
+#error Feature macro not defined
+#endif
+
+int
+foo (int a)
+{
+  return a;
+}
diff --git a/gcc/testsuite/gcc.target/riscv/zvkn.c b/gcc/testsuite/gcc.target/riscv/zvkn.c
new file mode 100644
index 00000000000..3647936d9e9
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/zvkn.c
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gc_zvkn" { target { rv64 } } } */
+/* { dg-options "-march=rv32gc_zvkn" { target { rv32 } } } */
+
+#ifndef __riscv_zvkn
+#error Feature macro not defined
+#endif
+
+int
+foo (int a)
+{
+  return a;
+}
diff --git a/gcc/testsuite/gcc.target/riscv/zvksed.c b/gcc/testsuite/gcc.target/riscv/zvksed.c
new file mode 100644
index 00000000000..439b546bb8a
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/zvksed.c
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gc_zvksed" { target { rv64 } } } */
+/* { dg-options "-march=rv32gc_zvksed" { target { rv32 } } } */
+
+#ifndef __riscv_zvksed
+#error Feature macro not defined
+#endif
+
+int
+foo (int a)
+{
+  return a;
+}
diff --git a/gcc/testsuite/gcc.target/riscv/zvksh.c b/gcc/testsuite/gcc.target/riscv/zvksh.c
new file mode 100644
index 00000000000..5359ca50281
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/zvksh.c
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gc_zvksh" { target { rv64 } } } */
+/* { dg-options "-march=rv32gc_zvksh" { target { rv32 } } } */
+
+#ifndef __riscv_zvksh
+#error Feature macro not defined
+#endif
+
+int
+foo (int a)
+{
+  return a;
+}
-- 
2.38.1


             reply	other threads:[~2022-12-21 18:31 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-21 18:31 Christoph Muellner [this message]
2022-12-27 17:35 ` Jeff Law
2022-12-27 18:58   ` Palmer Dabbelt
2022-12-27 19:47     ` Philipp Tomsich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221221183103.3800844-1-christoph.muellner@vrull.eu \
    --to=christoph.muellner@vrull.eu \
    --cc=adlr@rivosinc.com \
    --cc=adurbin@rivosinc.com \
    --cc=andrew@sifive.com \
    --cc=barna@rivosinc.com \
    --cc=ego@rivosinc.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jeffreyalaw@gmail.com \
    --cc=jim.wilson.gcc@gmail.com \
    --cc=kito.cheng@sifive.com \
    --cc=palmer@dabbelt.com \
    --cc=philipp.tomsich@vrull.eu \
    --cc=vineetg@rivosinc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).