public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 0/2] RISC-V: Introduce new architecture extension test macros
@ 2021-01-04  9:48 Kito Cheng
  2021-01-04  9:48 ` [PATCH 1/2] RISC-V: Move class riscv_subset_list and riscv_subset_t to riscv-protos.h Kito Cheng
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Kito Cheng @ 2021-01-04  9:48 UTC (permalink / raw)
  To: gcc-patches, kito.cheng, jimw

This patch set introduce new set of architecture extension test macros
which is accept on riscv-c-api-doc[1] recently.

The motivation of this scheme is have an unify naming scheme for
extension macro and add the capability to checking version.

[1] https://github.com/riscv/riscv-c-api-doc/blob/master/riscv-c-api.md#architecture-extension-test-macro




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

* [PATCH 1/2] RISC-V: Move class riscv_subset_list and riscv_subset_t to riscv-protos.h
  2021-01-04  9:48 [PATCH 0/2] RISC-V: Introduce new architecture extension test macros Kito Cheng
@ 2021-01-04  9:48 ` Kito Cheng
  2021-01-04  9:48 ` [PATCH 2/2] RISC-V: Implement new style of architecture extension test macros Kito Cheng
  2021-01-06 15:23 ` [PATCH 0/2] RISC-V: Introduce new " Kito Cheng
  2 siblings, 0 replies; 4+ messages in thread
From: Kito Cheng @ 2021-01-04  9:48 UTC (permalink / raw)
  To: gcc-patches, kito.cheng, jimw; +Cc: Kito Cheng

Pre-work of new style of architecture extension test macros, we need the
list used in `config/riscv/riscv-c.c`, so those struct/class declaration
must move to header file rather than local C file.

gcc/ChangeLog

	* common/config/riscv/riscv-common.c (RISCV_DONT_CARE_VERSION):
	Move to riscv-protos.h.
	(struct riscv_subset_t): Ditto.
	(class riscv_subset_list): Ditto.
	* config/riscv/riscv-protos.h (RISCV_DONT_CARE_VERSION): Move
	from riscv-common.c.
	(struct riscv_subset_t): Ditto.
	(class riscv_subset_list): Ditto.
---
 gcc/common/config/riscv/riscv-common.c | 66 -------------------------
 gcc/config/riscv/riscv-protos.h        | 67 ++++++++++++++++++++++++++
 2 files changed, 67 insertions(+), 66 deletions(-)

diff --git a/gcc/common/config/riscv/riscv-common.c b/gcc/common/config/riscv/riscv-common.c
index 5e3ddcf3f81..3a8bcbef006 100644
--- a/gcc/common/config/riscv/riscv-common.c
+++ b/gcc/common/config/riscv/riscv-common.c
@@ -31,22 +31,6 @@ along with GCC; see the file COPYING3.  If not see
 #include "diagnostic-core.h"
 #include "config/riscv/riscv-protos.h"
 
-#define RISCV_DONT_CARE_VERSION -1
-
-/* Subset info.  */
-struct riscv_subset_t
-{
-  riscv_subset_t ();
-
-  std::string name;
-  int major_version;
-  int minor_version;
-  struct riscv_subset_t *next;
-
-  bool explicit_version_p;
-  bool implied_p;
-};
-
 /* Type for implied ISA info.  */
 struct riscv_implied_info_t
 {
@@ -123,56 +107,6 @@ static const riscv_cpu_info riscv_cpu_tables[] =
     {NULL, NULL, NULL}
 };
 
-/* Subset list.  */
-class riscv_subset_list
-{
-private:
-  /* Original arch string.  */
-  const char *m_arch;
-
-  /* Location of arch string, used for report error.  */
-  location_t m_loc;
-
-  /* Head of subset info list.  */
-  riscv_subset_t *m_head;
-
-  /* Tail of subset info list.  */
-  riscv_subset_t *m_tail;
-
-  /* X-len of m_arch. */
-  unsigned m_xlen;
-
-  riscv_subset_list (const char *, location_t);
-
-  const char *parsing_subset_version (const char *, const char *, unsigned *,
-				      unsigned *, bool, bool *);
-
-  const char *parse_std_ext (const char *);
-
-  const char *parse_multiletter_ext (const char *, const char *,
-				     const char *);
-
-  void handle_implied_ext (riscv_subset_t *);
-
-public:
-  ~riscv_subset_list ();
-
-  void add (const char *, int, int, bool, bool);
-
-  void add (const char *, bool);
-
-  riscv_subset_t *lookup (const char *,
-			  int major_version = RISCV_DONT_CARE_VERSION,
-			  int minor_version = RISCV_DONT_CARE_VERSION) const;
-
-  std::string to_string (bool) const;
-
-  unsigned xlen() const {return m_xlen;};
-
-  static riscv_subset_list *parse (const char *, location_t);
-
-};
-
 static const char *riscv_supported_std_ext (void);
 
 static riscv_subset_list *current_subset_list = NULL;
diff --git a/gcc/config/riscv/riscv-protos.h b/gcc/config/riscv/riscv-protos.h
index 256dab1d0cf..1a258553d73 100644
--- a/gcc/config/riscv/riscv-protos.h
+++ b/gcc/config/riscv/riscv-protos.h
@@ -108,4 +108,71 @@ struct riscv_cpu_info {
 
 extern const riscv_cpu_info *riscv_find_cpu (const char *);
 
+#define RISCV_DONT_CARE_VERSION -1
+
+/* Subset info.  */
+struct riscv_subset_t
+{
+  riscv_subset_t ();
+
+  std::string name;
+  int major_version;
+  int minor_version;
+  struct riscv_subset_t *next;
+
+  bool explicit_version_p;
+  bool implied_p;
+};
+
+/* Subset list.  */
+class riscv_subset_list
+{
+private:
+  /* Original arch string.  */
+  const char *m_arch;
+
+  /* Location of arch string, used for report error.  */
+  location_t m_loc;
+
+  /* Head of subset info list.  */
+  riscv_subset_t *m_head;
+
+  /* Tail of subset info list.  */
+  riscv_subset_t *m_tail;
+
+  /* X-len of m_arch. */
+  unsigned m_xlen;
+
+  riscv_subset_list (const char *, location_t);
+
+  const char *parsing_subset_version (const char *, const char *, unsigned *,
+				      unsigned *, bool, bool *);
+
+  const char *parse_std_ext (const char *);
+
+  const char *parse_multiletter_ext (const char *, const char *,
+				     const char *);
+
+  void handle_implied_ext (riscv_subset_t *);
+
+public:
+  ~riscv_subset_list ();
+
+  void add (const char *, int, int, bool, bool);
+
+  void add (const char *, bool);
+
+  riscv_subset_t *lookup (const char *,
+			  int major_version = RISCV_DONT_CARE_VERSION,
+			  int minor_version = RISCV_DONT_CARE_VERSION) const;
+
+  std::string to_string (bool) const;
+
+  unsigned xlen () const {return m_xlen;};
+
+  static riscv_subset_list *parse (const char *, location_t);
+
+  int match_score (riscv_subset_list *) const;
+};
+
 #endif /* ! GCC_RISCV_PROTOS_H */
-- 
2.29.2


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

* [PATCH 2/2] RISC-V: Implement new style of architecture extension test macros.
  2021-01-04  9:48 [PATCH 0/2] RISC-V: Introduce new architecture extension test macros Kito Cheng
  2021-01-04  9:48 ` [PATCH 1/2] RISC-V: Move class riscv_subset_list and riscv_subset_t to riscv-protos.h Kito Cheng
@ 2021-01-04  9:48 ` Kito Cheng
  2021-01-06 15:23 ` [PATCH 0/2] RISC-V: Introduce new " Kito Cheng
  2 siblings, 0 replies; 4+ messages in thread
From: Kito Cheng @ 2021-01-04  9:48 UTC (permalink / raw)
  To: gcc-patches, kito.cheng, jimw; +Cc: Kito Cheng

- This patch introduce new set of architecture extension test macros
  which is accept on riscv-c-api-doc recently.
  - https://github.com/riscv/riscv-c-api-doc/blob/master/riscv-c-api.md#architecture-extension-test-macro

- We will also mark deprecated for legacy architecture extension test macros
  in GCC 11, but still support that for 1 or 2 release cycles.

gcc/ChangeLog:

	* common/config/riscv/riscv-common.c (riscv_current_subset_list): New.
	* config/riscv/riscv-c.c (riscv-protos.h): New.
	(riscv_cpu_cpp_builtins): Add new style architecture extension
	test macros.
	* config/riscv/riscv-protos.h (string):
	(riscv_subset_list::begin): New.
	(riscv_subset_list::end): New.
	(riscv_current_subset_list): New.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/predef-10.c: New.
	* gcc.target/riscv/predef-11.c: New.
	* gcc.target/riscv/predef-12.c: New.
	* gcc.target/riscv/predef-13.c: New.
---
 gcc/common/config/riscv/riscv-common.c     |  5 +++
 gcc/config/riscv/riscv-c.c                 | 31 ++++++++++++++++
 gcc/config/riscv/riscv-protos.h            |  7 ++++
 gcc/testsuite/gcc.target/riscv/predef-10.c | 43 ++++++++++++++++++++++
 gcc/testsuite/gcc.target/riscv/predef-11.c | 43 ++++++++++++++++++++++
 gcc/testsuite/gcc.target/riscv/predef-12.c | 43 ++++++++++++++++++++++
 gcc/testsuite/gcc.target/riscv/predef-13.c | 43 ++++++++++++++++++++++
 7 files changed, 215 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/riscv/predef-10.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/predef-11.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/predef-12.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/predef-13.c

diff --git a/gcc/common/config/riscv/riscv-common.c b/gcc/common/config/riscv/riscv-common.c
index 3a8bcbef006..c859440c477 100644
--- a/gcc/common/config/riscv/riscv-common.c
+++ b/gcc/common/config/riscv/riscv-common.c
@@ -111,6 +111,11 @@ static const char *riscv_supported_std_ext (void);
 
 static riscv_subset_list *current_subset_list = NULL;
 
+const riscv_subset_list *riscv_current_subset_list ()
+{
+  return current_subset_list;
+}
+
 riscv_subset_t::riscv_subset_t ()
   : name (), major_version (0), minor_version (0), next (NULL),
     explicit_version_p (false), implied_p (false)
diff --git a/gcc/config/riscv/riscv-c.c b/gcc/config/riscv/riscv-c.c
index c600badb313..e8c5f375374 100644
--- a/gcc/config/riscv/riscv-c.c
+++ b/gcc/config/riscv/riscv-c.c
@@ -26,6 +26,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "tm.h"
 #include "c-family/c-common.h"
 #include "cpplib.h"
+#include "riscv-protos.h"
 
 #define builtin_define(TXT) cpp_define (pfile, TXT)
 
@@ -101,4 +102,34 @@ riscv_cpu_cpp_builtins (cpp_reader *pfile)
       break;
 
     }
+
+  /* Define architecture extension test macros.  */
+  builtin_define_with_int_value ("__riscv_arch_test", 1);
+
+  const riscv_subset_list *subset_list = riscv_current_subset_list ();
+  size_t max_ext_len = 0;
+
+  /* Figure out the max length of extension name for reserving buffer.   */
+  for (const riscv_subset_t *subset = subset_list->begin ();
+       subset != subset_list->end ();
+       subset = subset->next)
+    max_ext_len = MAX (max_ext_len, subset->name.length ());
+
+  char *buf = (char *)alloca (max_ext_len + 10 /* For __riscv_ and '\0'.  */);
+
+  for (const riscv_subset_t *subset = subset_list->begin ();
+       subset != subset_list->end ();
+       subset = subset->next)
+    {
+      int version_value = (subset->major_version * 1000000)
+			   + (subset->minor_version * 1000);
+      /* Special rule for zicsr and zifencei, it's used for ISA spec 2.2 or
+	 earlier.  */
+      if ((subset->name == "zicsr" || subset->name == "zifencei")
+	  && version_value == 0)
+	version_value = 2000000;
+
+      sprintf (buf, "__riscv_%s", subset->name.c_str ());
+      builtin_define_with_int_value (buf, version_value);
+    }
 }
diff --git a/gcc/config/riscv/riscv-protos.h b/gcc/config/riscv/riscv-protos.h
index 1a258553d73..bbd38ff0170 100644
--- a/gcc/config/riscv/riscv-protos.h
+++ b/gcc/config/riscv/riscv-protos.h
@@ -22,6 +22,8 @@ along with GCC; see the file COPYING3.  If not see
 #ifndef GCC_RISCV_PROTOS_H
 #define GCC_RISCV_PROTOS_H
 
+#include <string>
+
 /* Symbol types we understand.  The order of this list must match that of
    the unspec enum in riscv.md, subsequent to UNSPEC_ADDRESS_FIRST.  */
 enum riscv_symbol_type {
@@ -173,6 +175,11 @@ public:
   static riscv_subset_list *parse (const char *, location_t);
 
   int match_score (riscv_subset_list *) const;
+
+  const riscv_subset_t *begin () const {return m_head;};
+  const riscv_subset_t *end () const {return NULL;};
 };
 
+extern const riscv_subset_list *riscv_current_subset_list (void);
+
 #endif /* ! GCC_RISCV_PROTOS_H */
diff --git a/gcc/testsuite/gcc.target/riscv/predef-10.c b/gcc/testsuite/gcc.target/riscv/predef-10.c
new file mode 100644
index 00000000000..7c447bfb08d
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/predef-10.c
@@ -0,0 +1,43 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -march=rv32i2p0 -mabi=ilp32 -mcmodel=medlow -misa-spec=2.2" } */
+
+int main () {
+
+#ifndef __riscv_arch_test
+#error "__riscv_arch_test"
+#endif
+
+#if __riscv_xlen != 32
+#error "__riscv_xlen"
+#endif
+
+#if !defined(__riscv_i) || (__riscv_i != (2 * 1000 * 1000))
+#error "__riscv_i"
+#endif
+
+#if defined(__riscv_c)
+#error "__riscv_c"
+#endif
+
+#if defined(__riscv_e)
+#error "__riscv_e"
+#endif
+
+#if defined(__riscv_a)
+#error "__riscv_a"
+#endif
+
+#if defined(__riscv_m)
+#error "__riscv_m"
+#endif
+
+#if defined(__riscv_f)
+#error "__riscv_f"
+#endif
+
+#if defined(__riscv_d)
+#error "__riscv_d"
+#endif
+
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.target/riscv/predef-11.c b/gcc/testsuite/gcc.target/riscv/predef-11.c
new file mode 100644
index 00000000000..80f48113dfa
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/predef-11.c
@@ -0,0 +1,43 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -march=rv64gc -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) || (__riscv_i != (2 * 1000 * 1000))
+#error "__riscv_i"
+#endif
+
+#if !defined(__riscv_c) || (__riscv_c != (2 * 1000 * 1000))
+#error "__riscv_c"
+#endif
+
+#if defined(__riscv_e)
+#error "__riscv_e"
+#endif
+
+#if !defined(__riscv_a) || (__riscv_a != (2 * 1000 * 1000))
+#error "__riscv_a"
+#endif
+
+#if !defined(__riscv_m) || (__riscv_m != (2 * 1000 * 1000))
+#error "__riscv_m"
+#endif
+
+#if !defined(__riscv_f) || (__riscv_f != (2 * 1000 * 1000))
+#error "__riscv_f"
+#endif
+
+#if !defined(__riscv_d) || (__riscv_d != (2 * 1000 * 1000))
+#error "__riscv_d"
+#endif
+
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.target/riscv/predef-12.c b/gcc/testsuite/gcc.target/riscv/predef-12.c
new file mode 100644
index 00000000000..dd35dbde925
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/predef-12.c
@@ -0,0 +1,43 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -march=rv64gc -mabi=lp64 -mcmodel=medlow -misa-spec=20191213" } */
+
+int main () {
+
+#ifndef __riscv_arch_test
+#error "__riscv_arch_test"
+#endif
+
+#if __riscv_xlen != 64
+#error "__riscv_xlen"
+#endif
+
+#if !defined(__riscv_i) || (__riscv_i != (2 * 1000 * 1000 + 1 * 1000))
+#error "__riscv_i"
+#endif
+
+#if !defined(__riscv_c) || (__riscv_c != (2 * 1000 * 1000))
+#error "__riscv_c"
+#endif
+
+#if defined(__riscv_e)
+#error "__riscv_e"
+#endif
+
+#if !defined(__riscv_a) || (__riscv_a != (2 * 1000 * 1000 + 1 * 1000))
+#error "__riscv_a"
+#endif
+
+#if !defined(__riscv_m) || (__riscv_m != (2 * 1000 * 1000))
+#error "__riscv_m"
+#endif
+
+#if !defined(__riscv_f) || (__riscv_f != (2 * 1000 * 1000 + 2 * 1000))
+#error "__riscv_f"
+#endif
+
+#if !defined(__riscv_d) || (__riscv_d != (2 * 1000 * 1000 + 2 * 1000))
+#error "__riscv_d"
+#endif
+
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.target/riscv/predef-13.c b/gcc/testsuite/gcc.target/riscv/predef-13.c
new file mode 100644
index 00000000000..95cf0012408
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/predef-13.c
@@ -0,0 +1,43 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -march=rv32e -mabi=ilp32e -mcmodel=medlow -misa-spec=2.2" } */
+
+int main () {
+
+#ifndef __riscv_arch_test
+#error "__riscv_arch_test"
+#endif
+
+#if __riscv_xlen != 32
+#error "__riscv_xlen"
+#endif
+
+#if defined(__riscv_i)
+#error "__riscv_i"
+#endif
+
+#if defined(__riscv_c)
+#error "__riscv_c"
+#endif
+
+#if !defined(__riscv_e) || (__riscv_e != (1 * 1000 * 1000 + 9 * 1000))
+#error "__riscv_e"
+#endif
+
+#if defined(__riscv_a)
+#error "__riscv_a"
+#endif
+
+#if defined(__riscv_m)
+#error "__riscv_m"
+#endif
+
+#if defined(__riscv_f)
+#error "__riscv_f"
+#endif
+
+#if defined(__riscv_d)
+#error "__riscv_d"
+#endif
+
+  return 0;
+}
-- 
2.29.2


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

* Re: [PATCH 0/2] RISC-V: Introduce new architecture extension test macros
  2021-01-04  9:48 [PATCH 0/2] RISC-V: Introduce new architecture extension test macros Kito Cheng
  2021-01-04  9:48 ` [PATCH 1/2] RISC-V: Move class riscv_subset_list and riscv_subset_t to riscv-protos.h Kito Cheng
  2021-01-04  9:48 ` [PATCH 2/2] RISC-V: Implement new style of architecture extension test macros Kito Cheng
@ 2021-01-06 15:23 ` Kito Cheng
  2 siblings, 0 replies; 4+ messages in thread
From: Kito Cheng @ 2021-01-06 15:23 UTC (permalink / raw)
  To: Kito Cheng; +Cc: GCC Patches, Jim Wilson

Found some build issue on MacOS, will update v2 patches in next few days

On Mon, Jan 4, 2021 at 5:49 PM Kito Cheng <kito.cheng@sifive.com> wrote:
>
> This patch set introduce new set of architecture extension test macros
> which is accept on riscv-c-api-doc[1] recently.
>
> The motivation of this scheme is have an unify naming scheme for
> extension macro and add the capability to checking version.
>
> [1] https://github.com/riscv/riscv-c-api-doc/blob/master/riscv-c-api.md#architecture-extension-test-macro
>
>
>

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

end of thread, other threads:[~2021-01-06 15:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-04  9:48 [PATCH 0/2] RISC-V: Introduce new architecture extension test macros Kito Cheng
2021-01-04  9:48 ` [PATCH 1/2] RISC-V: Move class riscv_subset_list and riscv_subset_t to riscv-protos.h Kito Cheng
2021-01-04  9:48 ` [PATCH 2/2] RISC-V: Implement new style of architecture extension test macros Kito Cheng
2021-01-06 15:23 ` [PATCH 0/2] RISC-V: Introduce new " 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).