public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] RISC-V: Handle combine extension in canonical ordering.
@ 2022-03-08  3:30 shihua
  2022-03-16 13:08 ` Kito Cheng
  0 siblings, 1 reply; 2+ messages in thread
From: shihua @ 2022-03-08  3:30 UTC (permalink / raw)
  To: gcc-patches
  Cc: jim.wilson.gcc, kito.cheng, lazyparser, jiawei, yulong,
	ben.marshall, andrew, palmer, LiaoShihua

From: LiaoShihua <shihua@iscas.ac.cn>

The crypto extension have several shorthand extensions that don't consist of any extra instructions.
Take zk for example, while the extension would imply zkn, zkr, zkt. 
The 3 extensions should also combine back into zk to maintain the canonical order in isa strings.
This patch addresses the above.
And if the other extension has the same situation, you can add them in riscv_combine_info[]



gcc/ChangeLog:

        * common/config/riscv/riscv-common.cc (riscv_subset_list::handle_combine_ext):Combine back into zk to maintain the canonical order in isa strings.
        (riscv_subset_list::parse):Ditto.
        * config/riscv/riscv-subset.h:Declare handle_combine_ext();

gcc/testsuite/ChangeLog:

        * gcc.target/riscv/predef-17.c: New test.

---
 gcc/common/config/riscv/riscv-common.cc    | 56 +++++++++++++++++++
 gcc/config/riscv/riscv-subset.h            |  1 +
 gcc/testsuite/gcc.target/riscv/predef-17.c | 63 ++++++++++++++++++++++
 3 files changed, 120 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/riscv/predef-17.c

diff --git a/gcc/common/config/riscv/riscv-common.cc b/gcc/common/config/riscv/riscv-common.cc
index a904893b9ed..1c06f83cc1c 100644
--- a/gcc/common/config/riscv/riscv-common.cc
+++ b/gcc/common/config/riscv/riscv-common.cc
@@ -189,6 +189,16 @@ static const struct riscv_ext_version riscv_ext_version_table[] =
   {NULL, ISA_SPEC_CLASS_NONE, 0, 0}
 };
 
+/* Combine extensions defined in this table  */
+static const struct riscv_ext_version riscv_combine_info[] =
+{
+  {"zk",  ISA_SPEC_CLASS_NONE, 1, 0},
+  {"zkn",  ISA_SPEC_CLASS_NONE, 1, 0},
+  {"zks",  ISA_SPEC_CLASS_NONE, 1, 0},
+  /* Terminate the list.  */
+  {NULL, ISA_SPEC_CLASS_NONE, 0, 0}
+};
+
 static const riscv_cpu_info riscv_cpu_tables[] =
 {
 #define RISCV_CORE(CORE_NAME, ARCH, TUNE) \
@@ -813,6 +823,50 @@ riscv_subset_list::handle_implied_ext (riscv_subset_t *ext)
     }
 }
 
+/* Check any combine extensions for EXT.  */
+void
+riscv_subset_list::handle_combine_ext (riscv_subset_list *subset_list)
+{
+  const riscv_ext_version *combine_info;
+  const riscv_implied_info_t *implied_info;
+  bool IsCombined = false;
+
+  for (combine_info = &riscv_combine_info[0]; combine_info->name; ++combine_info)
+  {
+
+    /* Skip if combine extensions are present */
+    if (subset_list->lookup(combine_info->name))
+      continue;
+
+    /* Find all extensions of the combine extension   */
+    for (implied_info = &riscv_implied_info[0]; implied_info->ext; ++implied_info)
+    {
+      /* Skip if implied extension don't match combine extension */
+      if (strcmp(combine_info->name, implied_info->ext) != 0)
+        continue; 
+
+      if (subset_list->lookup(implied_info->implied_ext))
+          {
+            IsCombined = true;
+          }
+      else
+          {
+            IsCombined = false;
+            break;
+          }
+    }
+
+    /* Add combine extensions */
+    if (IsCombined)
+    {
+      if (subset_list->lookup(combine_info->name) == NULL)
+      {
+        subset_list->add (combine_info->name, combine_info->major_version, combine_info->minor_version, false, true);
+      }
+    }
+  }
+}
+
 /* Parsing function for multi-letter extensions.
 
    Return Value:
@@ -992,6 +1046,8 @@ riscv_subset_list::parse (const char *arch, location_t loc)
       subset_list->handle_implied_ext (itr);
     }
 
+  subset_list->handle_combine_ext (subset_list);
+
   return subset_list;
 
 fail:
diff --git a/gcc/config/riscv/riscv-subset.h b/gcc/config/riscv/riscv-subset.h
index 4f3556a8d9b..da2e22d34f2 100644
--- a/gcc/config/riscv/riscv-subset.h
+++ b/gcc/config/riscv/riscv-subset.h
@@ -68,6 +68,7 @@ private:
 				     const char *);
 
   void handle_implied_ext (riscv_subset_t *);
+  void handle_combine_ext (riscv_subset_list *);
 
 public:
   ~riscv_subset_list ();
diff --git a/gcc/testsuite/gcc.target/riscv/predef-17.c b/gcc/testsuite/gcc.target/riscv/predef-17.c
new file mode 100644
index 00000000000..68f5f95a66c
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/predef-17.c
@@ -0,0 +1,63 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64i_zbkb_zbkc_zbkx_zknd_zkne_zknh_zksed_zksh_zkr_zkt -mabi=lp64 -mcmodel=medlow -misa-spec=2.2" } */
+
+int main () {
+
+#ifndef __riscv_arch_test
+#error "__riscv_arch_test"
+#endif
+
+#if __riscv_xlen != 64
+#error "__riscv_xlen"
+#endif
+
+#if !defined(__riscv_i)
+#error "__riscv_i"
+#endif
+
+#if !defined(__riscv_zk)
+#error "__riscv_zk"
+#endif
+
+#if !defined(__riscv_zkr)
+#error "__riscv_zkr"
+#endif
+
+#if !defined(__riscv_zkn)
+#error "__riscv_zkn"
+#endif
+
+#if !defined(__riscv_zks)
+#error "__riscv_zks"
+#endif
+
+#if !defined(__riscv_zbkb)
+#error "__riscv_zbkb"
+#endif
+
+#if !defined(__riscv_zbkc)
+#error "__riscv_zbkc"
+#endif
+
+#if !defined(__riscv_zbkx)
+#error "__riscv_zbkx"
+#endif
+
+#if !defined(__riscv_zknd)
+#error "__riscv_zknd"
+#endif
+
+#if !defined(__riscv_zkne)
+#error "__riscv_zkne"
+#endif
+
+#if !defined(__riscv_zknh)
+#error "__riscv_zknh"
+#endif
+
+#if !defined(__riscv_zksh)
+#error "__riscv_zksh"
+#endif
+
+  return 0;
+}
\ No newline at end of file
-- 
2.31.1.windows.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] RISC-V: Handle combine extension in canonical ordering.
  2022-03-08  3:30 [PATCH] RISC-V: Handle combine extension in canonical ordering shihua
@ 2022-03-16 13:08 ` Kito Cheng
  0 siblings, 0 replies; 2+ messages in thread
From: Kito Cheng @ 2022-03-16 13:08 UTC (permalink / raw)
  To: 廖仕华
  Cc: GCC Patches, ben.marshall, Andrew Waterman, jiawei, yulong

Hi Shi-Hua:

Thanks, generally it's LGTM, just a few coding style issues. I've
fixed that and  committed this time,
but just let you know where you should update your coding style.

And you could use git clang-format and use <gcc>/contrib/clang-format
as format file to save
your time to indent that.

https://stackoverflow.com/questions/43974371/run-git-clang-format-on-series-of-git-commits

On Tue, Mar 8, 2022 at 11:31 AM <shihua@iscas.ac.cn> wrote:
>
> From: LiaoShihua <shihua@iscas.ac.cn>
>
> The crypto extension have several shorthand extensions that don't consist of any extra instructions.
> Take zk for example, while the extension would imply zkn, zkr, zkt.
> The 3 extensions should also combine back into zk to maintain the canonical order in isa strings.
> This patch addresses the above.
> And if the other extension has the same situation, you can add them in riscv_combine_info[]
>
>
>
> gcc/ChangeLog:
>
>         * common/config/riscv/riscv-common.cc (riscv_subset_list::handle_combine_ext):Combine back into zk to maintain the canonical order in isa strings.
>         (riscv_subset_list::parse):Ditto.

You need to mention riscv_combine_info in the change log too :)

>         * config/riscv/riscv-subset.h:Declare handle_combine_ext();
>
> gcc/testsuite/ChangeLog:
>
>         * gcc.target/riscv/predef-17.c: New test.
>
> ---
>  gcc/common/config/riscv/riscv-common.cc    | 56 +++++++++++++++++++
>  gcc/config/riscv/riscv-subset.h            |  1 +
>  gcc/testsuite/gcc.target/riscv/predef-17.c | 63 ++++++++++++++++++++++
>  3 files changed, 120 insertions(+)
>  create mode 100644 gcc/testsuite/gcc.target/riscv/predef-17.c
>
> diff --git a/gcc/common/config/riscv/riscv-common.cc b/gcc/common/config/riscv/riscv-common.cc
> index a904893b9ed..1c06f83cc1c 100644
> --- a/gcc/common/config/riscv/riscv-common.cc
> +++ b/gcc/common/config/riscv/riscv-common.cc
> @@ -189,6 +189,16 @@ static const struct riscv_ext_version riscv_ext_version_table[] =
>    {NULL, ISA_SPEC_CLASS_NONE, 0, 0}
>  };
>
> +/* Combine extensions defined in this table  */
> +static const struct riscv_ext_version riscv_combine_info[] =
> +{
> +  {"zk",  ISA_SPEC_CLASS_NONE, 1, 0},
> +  {"zkn",  ISA_SPEC_CLASS_NONE, 1, 0},
> +  {"zks",  ISA_SPEC_CLASS_NONE, 1, 0},
> +  /* Terminate the list.  */
> +  {NULL, ISA_SPEC_CLASS_NONE, 0, 0}
> +};
> +
>  static const riscv_cpu_info riscv_cpu_tables[] =
>  {
>  #define RISCV_CORE(CORE_NAME, ARCH, TUNE) \
> @@ -813,6 +823,50 @@ riscv_subset_list::handle_implied_ext (riscv_subset_t *ext)
>      }
>  }
>
> +/* Check any combine extensions for EXT.  */
> +void
> +riscv_subset_list::handle_combine_ext (riscv_subset_list *subset_list)

You don't need to pass subset_list again, you can just use `this`

> +{
> +  const riscv_ext_version *combine_info;
> +  const riscv_implied_info_t *implied_info;
> +  bool IsCombined = false;

is_combined

> +
> +  for (combine_info = &riscv_combine_info[0]; combine_info->name; ++combine_info)
> +  {

for (...)
  { // two space

> +
> +    /* Skip if combine extensions are present */
> +    if (subset_list->lookup(combine_info->name))
> +      continue;
> +
> +    /* Find all extensions of the combine extension   */
> +    for (implied_info = &riscv_implied_info[0]; implied_info->ext; ++implied_info)
> +    {
> +      /* Skip if implied extension don't match combine extension */
> +      if (strcmp(combine_info->name, implied_info->ext) != 0)
> +        continue;
> +
> +      if (subset_list->lookup(implied_info->implied_ext))
> +          {
> +            IsCombined = true;
> +          }

No curly brackets needed if only one line.

> +      else
> +          {
> +            IsCombined = false;
> +            break;
> +          }
> +    }
> +
> +    /* Add combine extensions */
> +    if (IsCombined)
> +    {
> +      if (subset_list->lookup(combine_info->name) == NULL)
> +      {
> +        subset_list->add (combine_info->name, combine_info->major_version, combine_info->minor_version, false, true);
> +      }
> +    }
> +  }
> +}
> +
>  /* Parsing function for multi-letter extensions.
>
>     Return Value:
> @@ -992,6 +1046,8 @@ riscv_subset_list::parse (const char *arch, location_t loc)
>        subset_list->handle_implied_ext (itr);
>      }
>
> +  subset_list->handle_combine_ext (subset_list);
> +
>    return subset_list;
>
>  fail:
> diff --git a/gcc/config/riscv/riscv-subset.h b/gcc/config/riscv/riscv-subset.h
> index 4f3556a8d9b..da2e22d34f2 100644
> --- a/gcc/config/riscv/riscv-subset.h
> +++ b/gcc/config/riscv/riscv-subset.h
> @@ -68,6 +68,7 @@ private:
>                                      const char *);
>
>    void handle_implied_ext (riscv_subset_t *);
> +  void handle_combine_ext (riscv_subset_list *);
>
>  public:
>    ~riscv_subset_list ();
> diff --git a/gcc/testsuite/gcc.target/riscv/predef-17.c b/gcc/testsuite/gcc.target/riscv/predef-17.c
> new file mode 100644
> index 00000000000..68f5f95a66c
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/riscv/predef-17.c
> @@ -0,0 +1,63 @@
> +/* { dg-do compile } */
> +/* { dg-options "-march=rv64i_zbkb_zbkc_zbkx_zknd_zkne_zknh_zksed_zksh_zkr_zkt -mabi=lp64 -mcmodel=medlow -misa-spec=2.2" } */
> +
> +int main () {
> +
> +#ifndef __riscv_arch_test
> +#error "__riscv_arch_test"
> +#endif
> +
> +#if __riscv_xlen != 64
> +#error "__riscv_xlen"
> +#endif
> +
> +#if !defined(__riscv_i)
> +#error "__riscv_i"
> +#endif
> +
> +#if !defined(__riscv_zk)
> +#error "__riscv_zk"
> +#endif
> +
> +#if !defined(__riscv_zkr)
> +#error "__riscv_zkr"
> +#endif
> +
> +#if !defined(__riscv_zkn)
> +#error "__riscv_zkn"
> +#endif
> +
> +#if !defined(__riscv_zks)
> +#error "__riscv_zks"
> +#endif
> +
> +#if !defined(__riscv_zbkb)
> +#error "__riscv_zbkb"
> +#endif
> +
> +#if !defined(__riscv_zbkc)
> +#error "__riscv_zbkc"
> +#endif
> +
> +#if !defined(__riscv_zbkx)
> +#error "__riscv_zbkx"
> +#endif
> +
> +#if !defined(__riscv_zknd)
> +#error "__riscv_zknd"
> +#endif
> +
> +#if !defined(__riscv_zkne)
> +#error "__riscv_zkne"
> +#endif
> +
> +#if !defined(__riscv_zknh)
> +#error "__riscv_zknh"
> +#endif
> +
> +#if !defined(__riscv_zksh)
> +#error "__riscv_zksh"
> +#endif
> +
> +  return 0;
> +}
> \ No newline at end of file
> --
> 2.31.1.windows.1
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-03-16 13:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-08  3:30 [PATCH] RISC-V: Handle combine extension in canonical ordering shihua
2022-03-16 13:08 ` Kito Cheng

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).