public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 1/2] RISC-V: Update march parser
@ 2020-03-31  9:06 Kito Cheng
  2020-03-31  9:06 ` [PATCH 2/2] RISC-V: Handle implied extension for -march parser Kito Cheng
  2020-04-06 22:45 ` [PATCH 1/2] RISC-V: Update march parser Jim Wilson
  0 siblings, 2 replies; 5+ messages in thread
From: Kito Cheng @ 2020-03-31  9:06 UTC (permalink / raw)
  To: gcc-patches, kito.cheng, jimw; +Cc: Kito Cheng

 - The arch string rule has changed in latest spec, it introduced new
   multi-letter extension prefix with 'h' and 'z', and drop `sx`. also
   adjust parsing order for 's' and 'x'.

gcc/ChangeLog

	* riscv-common.c (parse_sv_or_non_std_ext): Rename to
	parse_multiletter_ext.
	(parse_multiletter_ext): Add parsing `h` and `z`, drop `sx`,
	adjust parsing order for 's' and 'x'.

gcc/testsuite/ChangeLog

	* gcc.target/riscv/arch-3.c: Adjust option.
	* gcc.target/riscv/arch-5.c: New.
	* gcc.target/riscv/attribute-9.c: Adjust option and test
	condition.
---
 gcc/common/config/riscv/riscv-common.c       | 40 ++++++++++----------
 gcc/testsuite/gcc.target/riscv/arch-3.c      |  2 +-
 gcc/testsuite/gcc.target/riscv/arch-5.c      |  5 +++
 gcc/testsuite/gcc.target/riscv/attribute-9.c |  4 +-
 4 files changed, 28 insertions(+), 23 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/riscv/arch-5.c

diff --git a/gcc/common/config/riscv/riscv-common.c b/gcc/common/config/riscv/riscv-common.c
index d2ef83b1971..a2e8d7003cc 100644
--- a/gcc/common/config/riscv/riscv-common.c
+++ b/gcc/common/config/riscv/riscv-common.c
@@ -70,8 +70,8 @@ private:
 
   const char *parse_std_ext (const char *);
 
-  const char *parse_sv_or_non_std_ext (const char *, const char *,
-				       const char *);
+  const char *parse_multiletter_ext (const char *, const char *,
+				     const char *);
 
 public:
   ~riscv_subset_list ();
@@ -357,7 +357,7 @@ riscv_subset_list::parse_std_ext (const char *p)
     {
       char subset[2] = {0, 0};
 
-      if (*p == 'x' || *p == 's')
+      if (*p == 'x' || *p == 's' || *p == 'h' || *p == 'z')
 	break;
 
       if (*p == '_')
@@ -399,20 +399,20 @@ riscv_subset_list::parse_std_ext (const char *p)
   return p;
 }
 
-/* Parsing function for non-standard and supervisor extensions.
+/* Parsing function for multi-letter extensions.
 
    Return Value:
      Points to the end of extensions.
 
    Arguments:
      `p`: Current parsing position.
-     `ext_type`: What kind of extensions, 'x', 's' or 'sx'.
+     `ext_type`: What kind of extensions, 's', 'h', 'z' or 'x'.
      `ext_type_str`: Full name for kind of extension.  */
 
 const char *
-riscv_subset_list::parse_sv_or_non_std_ext (const char *p,
-					    const char *ext_type,
-					    const char *ext_type_str)
+riscv_subset_list::parse_multiletter_ext (const char *p,
+					  const char *ext_type,
+					  const char *ext_type_str)
 {
   unsigned major_version = 0;
   unsigned minor_version = 0;
@@ -429,11 +429,6 @@ riscv_subset_list::parse_sv_or_non_std_ext (const char *p,
       if (strncmp (p, ext_type, ext_type_len) != 0)
 	break;
 
-      /* It's non-standard supervisor extension if it prefix with sx.  */
-      if ((ext_type[0] == 's') && (ext_type_len == 1)
-	  && (*(p + 1) == 'x'))
-	break;
-
       char *subset = xstrdup (p);
       char *q = subset;
       const char *end_of_version;
@@ -494,21 +489,26 @@ riscv_subset_list::parse (const char *arch, location_t loc)
   if (p == NULL)
     goto fail;
 
-  /* Parsing non-standard extension.  */
-  p = subset_list->parse_sv_or_non_std_ext (p, "x", "non-standard extension");
+  /* Parsing supervisor extension.  */
+  p = subset_list->parse_multiletter_ext (p, "s", "supervisor extension");
 
   if (p == NULL)
     goto fail;
 
-  /* Parsing supervisor extension.  */
-  p = subset_list->parse_sv_or_non_std_ext (p, "s", "supervisor extension");
+  /* Parsing hypervisor extension.  */
+  p = subset_list->parse_multiletter_ext (p, "h", "hypervisor extension");
 
   if (p == NULL)
     goto fail;
 
-  /* Parsing non-standard supervisor extension.  */
-  p = subset_list->parse_sv_or_non_std_ext
-    (p, "sx", "non-standard supervisor extension");
+  /* Parsing sub-extensions.  */
+  p = subset_list->parse_multiletter_ext (p, "z", "sub-extension");
+
+  if (p == NULL)
+    goto fail;
+
+  /* Parsing non-standard extension.  */
+  p = subset_list->parse_multiletter_ext (p, "x", "non-standard extension");
 
   if (p == NULL)
     goto fail;
diff --git a/gcc/testsuite/gcc.target/riscv/arch-3.c b/gcc/testsuite/gcc.target/riscv/arch-3.c
index 6aaa0a650fa..124699405c5 100644
--- a/gcc/testsuite/gcc.target/riscv/arch-3.c
+++ b/gcc/testsuite/gcc.target/riscv/arch-3.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O -march=rv32ixbar_sabc_sxfoo -mabi=ilp32" } */
+/* { dg-options "-O -march=rv32isabc_xbar -mabi=ilp32" } */
 int foo()
 {
 }
diff --git a/gcc/testsuite/gcc.target/riscv/arch-5.c b/gcc/testsuite/gcc.target/riscv/arch-5.c
new file mode 100644
index 00000000000..b0a1bd445fe
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/arch-5.c
@@ -0,0 +1,5 @@
+/* { dg-do compile } */
+/* { dg-options "-O -march=rv32isabc_hghi_zfoo_xbar -mabi=ilp32" } */
+int foo()
+{
+}
diff --git a/gcc/testsuite/gcc.target/riscv/attribute-9.c b/gcc/testsuite/gcc.target/riscv/attribute-9.c
index 670944a1cbe..bc4db0eb647 100644
--- a/gcc/testsuite/gcc.target/riscv/attribute-9.c
+++ b/gcc/testsuite/gcc.target/riscv/attribute-9.c
@@ -1,6 +1,6 @@
 /* { dg-do compile } */
-/* { dg-options "-O -mriscv-attribute -march=rv32i2p0xbar_sabc_sxfoo -mabi=ilp32e" } */
+/* { dg-options "-O -mriscv-attribute -march=rv32i2p0sabc_xbar -mabi=ilp32e" } */
 int foo()
 {
 }
-/* { dg-final { scan-assembler ".attribute arch, \"rv32i2p0_xbar2p0_sabc2p0_sxfoo2p0\"" } } */
+/* { dg-final { scan-assembler ".attribute arch, \"rv32i2p0_sabc2p0_xbar2p0\"" } } */
-- 
2.25.2


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

* [PATCH 2/2] RISC-V: Handle implied extension for -march parser.
  2020-03-31  9:06 [PATCH 1/2] RISC-V: Update march parser Kito Cheng
@ 2020-03-31  9:06 ` Kito Cheng
  2020-04-06 22:51   ` Jim Wilson
  2020-04-06 22:45 ` [PATCH 1/2] RISC-V: Update march parser Jim Wilson
  1 sibling, 1 reply; 5+ messages in thread
From: Kito Cheng @ 2020-03-31  9:06 UTC (permalink / raw)
  To: gcc-patches, kito.cheng, jimw; +Cc: Kito Cheng

  - Implied rule are introduced into latest RISC-V isa spec.

  - Only implemented D implied F-extension. Zicsr and Zifence are not
    implement yet, so the rule not included in this patch.

gcc/ChangeLog

	* common/config/riscv/riscv-common.c (riscv_implied_info_t): New.
	(riscv_implied_info): New.
	(riscv_subset_list): Add handle_implied_ext.
	(riscv_subset_list::handle_implied_ext): New.
	(riscv_subset_list::parse_std_ext): Call handle_implied_ext.

gcc/testsuite/ChangeLog

	* gcc.target/riscv/arch-6.c: New.
	* gcc.target/riscv/attribute-11.c: New.
---
 gcc/common/config/riscv/riscv-common.c        | 39 +++++++++++++++++++
 gcc/testsuite/gcc.target/riscv/arch-6.c       |  5 +++
 gcc/testsuite/gcc.target/riscv/attribute-11.c |  6 +++
 3 files changed, 50 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/riscv/arch-6.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/attribute-11.c

diff --git a/gcc/common/config/riscv/riscv-common.c b/gcc/common/config/riscv/riscv-common.c
index a2e8d7003cc..24100cfae74 100644
--- a/gcc/common/config/riscv/riscv-common.c
+++ b/gcc/common/config/riscv/riscv-common.c
@@ -44,6 +44,20 @@ struct riscv_subset_t
   struct riscv_subset_t *next;
 };
 
+/* Type for implied ISA info.  */
+struct riscv_implied_info_t
+{
+  const char *ext;
+  const char *implied_ext;
+};
+
+/* Implied ISA info, must end with NULL sentinel.  */
+riscv_implied_info_t riscv_implied_info[] =
+{
+  {"d", "f"},
+  {NULL, NULL}
+};
+
 /* Subset list.  */
 class riscv_subset_list
 {
@@ -73,6 +87,8 @@ private:
   const char *parse_multiletter_ext (const char *, const char *,
 				     const char *);
 
+  void handle_implied_ext (const char *, int, int);
+
 public:
   ~riscv_subset_list ();
 
@@ -394,11 +410,34 @@ riscv_subset_list::parse_std_ext (const char *p)
 
       subset[0] = std_ext;
 
+      handle_implied_ext (subset, major_version, minor_version);
+
       add (subset, major_version, minor_version);
     }
   return p;
 }
 
+
+/* Check any implied extensions for EXT with version
+   MAJOR_VERSION.MINOR_VERSION.  */
+void
+riscv_subset_list::handle_implied_ext (const char *ext,
+				       int major_version,
+				       int minor_version)
+{
+  riscv_implied_info_t *implied_info;
+  for (implied_info = &riscv_implied_info[0];
+       implied_info->ext;
+       ++implied_info)
+    {
+      if (strcmp (ext, implied_info->ext) != 0)
+	continue;
+
+      /* TODO: Implied extension might use differet version.  */
+      add (implied_info->implied_ext, major_version, minor_version);
+    }
+}
+
 /* Parsing function for multi-letter extensions.
 
    Return Value:
diff --git a/gcc/testsuite/gcc.target/riscv/arch-6.c b/gcc/testsuite/gcc.target/riscv/arch-6.c
new file mode 100644
index 00000000000..b36dccbf46b
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/arch-6.c
@@ -0,0 +1,5 @@
+/* { dg-do compile } */
+/* { dg-options "-O -march=rv32id -mabi=ilp32" } */
+int foo()
+{
+}
diff --git a/gcc/testsuite/gcc.target/riscv/attribute-11.c b/gcc/testsuite/gcc.target/riscv/attribute-11.c
new file mode 100644
index 00000000000..a8649508b2f
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/attribute-11.c
@@ -0,0 +1,6 @@
+/* { dg-do compile } */
+/* { dg-options "-O -mriscv-attribute -march=rv32id -mabi=ilp32" } */
+int foo()
+{
+}
+/* { dg-final { scan-assembler ".attribute arch, \"rv32i2p0_f2p0_d2p0\"" } } */
-- 
2.25.2


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

* Re: [PATCH 1/2] RISC-V: Update march parser
  2020-03-31  9:06 [PATCH 1/2] RISC-V: Update march parser Kito Cheng
  2020-03-31  9:06 ` [PATCH 2/2] RISC-V: Handle implied extension for -march parser Kito Cheng
@ 2020-04-06 22:45 ` Jim Wilson
  1 sibling, 0 replies; 5+ messages in thread
From: Jim Wilson @ 2020-04-06 22:45 UTC (permalink / raw)
  To: Kito Cheng; +Cc: GCC Patches, Kito Cheng

On Tue, Mar 31, 2020 at 2:06 AM Kito Cheng <kito.cheng@sifive.com> wrote:
>  - The arch string rule has changed in latest spec, it introduced new
>    multi-letter extension prefix with 'h' and 'z', and drop `sx`. also
>    adjust parsing order for 's' and 'x'.

This looks OK to me.

Jim

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

* Re: [PATCH 2/2] RISC-V: Handle implied extension for -march parser.
  2020-03-31  9:06 ` [PATCH 2/2] RISC-V: Handle implied extension for -march parser Kito Cheng
@ 2020-04-06 22:51   ` Jim Wilson
  2020-04-07 14:10     ` Kito Cheng
  0 siblings, 1 reply; 5+ messages in thread
From: Jim Wilson @ 2020-04-06 22:51 UTC (permalink / raw)
  To: Kito Cheng; +Cc: GCC Patches, Kito Cheng

On Tue, Mar 31, 2020 at 2:07 AM Kito Cheng <kito.cheng@sifive.com> wrote:
>   - Implied rule are introduced into latest RISC-V isa spec.
>
>   - Only implemented D implied F-extension. Zicsr and Zifence are not
>     implement yet, so the rule not included in this patch.

When I try this patch, I see an error:

rohan:2132$ ./xgcc -B./ -O -march=rv64imafdc -mabi=lp64d  tmp.c
/tmp/ccULN36f.s: Assembler messages:
/tmp/ccULN36f.s:3: Fatal error:
-march=rv64i2p0_m2p0_a2p0_f2p0_f2p0_d2p0_c2p0: ISA string is not in
canonical order. `f'
rohan:2133$

Looks like you need to make sure that we don't add the implied F if it
is already there.  Otherwise, this looks OK to me.

We don't have support for these implied extensions in binutils yet.
If we are adding it to gcc, we should probably add it to binutils too.
Maybe you can ask Nelson to work on that.

> +      /* TODO: Implied extension might use differet version.  */

differet -> different

Jim

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

* Re: [PATCH 2/2] RISC-V: Handle implied extension for -march parser.
  2020-04-06 22:51   ` Jim Wilson
@ 2020-04-07 14:10     ` Kito Cheng
  0 siblings, 0 replies; 5+ messages in thread
From: Kito Cheng @ 2020-04-07 14:10 UTC (permalink / raw)
  To: Jim Wilson; +Cc: GCC Patches, Kito Cheng

Hi Jim:

> When I try this patch, I see an error:
>
> rohan:2132$ ./xgcc -B./ -O -march=rv64imafdc -mabi=lp64d  tmp.c
> /tmp/ccULN36f.s: Assembler messages:
> /tmp/ccULN36f.s:3: Fatal error:
> -march=rv64i2p0_m2p0_a2p0_f2p0_f2p0_d2p0_c2p0: ISA string is not in
> canonical order. `f'
> rohan:2133$
>
> Looks like you need to make sure that we don't add the implied F if it
> is already there.  Otherwise, this looks OK to me.

Thanks, I should add a testcase for that :)

>
> We don't have support for these implied extensions in binutils yet.
> If we are adding it to gcc, we should probably add it to binutils too.
> Maybe you can ask Nelson to work on that.

I also found another issue: assembler will complain when passing -march=rv64id,
 because it does not accept implied extensions yet...

$ riscv64-unknown-elf-gcc ~/hello.c -march=rv64id  -c
# GCC also invoke as with -march=rv64id
Assembler messages:
Fatal error: -march=rv64id: `d' extension requires `f' extension

However if we require assembler support that means we need to bump the
binutils version requirement again and might break backward compatibility,
so I guess we can transform -march= via spec functions?
I'll send a v2 patch with this approach.

diff --git a/gcc/config/riscv/riscv.h b/gcc/config/riscv/riscv.h
index 567c23380fe..38644436f7c 100644
--- a/gcc/config/riscv/riscv.h
+++ b/gcc/config/riscv/riscv.h
@@ -46,7 +46,7 @@ along with GCC; see the file COPYING3.  If not see
   --with-tune is ignored if -mtune is specified.  */
#define OPTION_DEFAULT_SPECS \
  {"tune", "%{!mtune=*:-mtune=%(VALUE)}" }, \
-  {"arch", "%{!march=*:-march=%(VALUE)}" }, \
+  {"arch", "%{!march=*:%:riscv_expand_arch(%(VALUE))}" }, \
  {"abi", "%{!mabi=*:-mabi=%(VALUE)}" }, \

#ifdef IN_LIBGCC2


Thanks :)

>
> > +      /* TODO: Implied extension might use differet version.  */
>
> differet -> different
>
> Jim

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

end of thread, other threads:[~2020-04-07 14:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-31  9:06 [PATCH 1/2] RISC-V: Update march parser Kito Cheng
2020-03-31  9:06 ` [PATCH 2/2] RISC-V: Handle implied extension for -march parser Kito Cheng
2020-04-06 22:51   ` Jim Wilson
2020-04-07 14:10     ` Kito Cheng
2020-04-06 22:45 ` [PATCH 1/2] RISC-V: Update march parser Jim Wilson

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