public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] IBM Z: Introduce __LONG_DOUBLE_VX__ macro
@ 2021-01-08  0:17 Ilya Leoshkevich
  2021-01-08  8:35 ` Andreas Krebbel
  0 siblings, 1 reply; 2+ messages in thread
From: Ilya Leoshkevich @ 2021-01-08  0:17 UTC (permalink / raw)
  To: krebbel, stli; +Cc: gcc-patches, Ilya Leoshkevich

Bootstrapped and regtested on s390x-redhat-linux.  Ok for master?



Give end users the opportunity to find out whether long doubles are
stored in floating-point register pairs or in vector registers, so that
they could fine-tune their asm statements.

gcc/ChangeLog:

2020-12-14  Ilya Leoshkevich  <iii@linux.ibm.com>

	* config/s390/s390-c.c (s390_def_or_undef_macro): Accept
	callables instead of mask values.
	(struct target_flag_set_p): New predicate.
	(s390_cpu_cpp_builtins_internal): Define or undefine
	__LONG_DOUBLE_VX__ macro.

gcc/testsuite/ChangeLog:

2020-12-14  Ilya Leoshkevich  <iii@linux.ibm.com>

	* gcc.target/s390/vector/long-double-vx-macro-off.c: New test.
	* gcc.target/s390/vector/long-double-vx-macro-on.c: New test.
---
 gcc/config/s390/s390-c.c                      | 59 ++++++++++++-------
 .../s390/vector/long-double-vx-macro-off-on.c | 11 ++++
 .../s390/vector/long-double-vx-macro-on-off.c | 11 ++++
 3 files changed, 60 insertions(+), 21 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/s390/vector/long-double-vx-macro-off-on.c
 create mode 100644 gcc/testsuite/gcc.target/s390/vector/long-double-vx-macro-on-off.c

diff --git a/gcc/config/s390/s390-c.c b/gcc/config/s390/s390-c.c
index 95cd2df505d..29b87d76ab1 100644
--- a/gcc/config/s390/s390-c.c
+++ b/gcc/config/s390/s390-c.c
@@ -294,9 +294,9 @@ s390_macro_to_expand (cpp_reader *pfile, const cpp_token *tok)
 /* Helper function that defines or undefines macros.  If SET is true, the macro
    MACRO_DEF is defined.  If SET is false, the macro MACRO_UNDEF is undefined.
    Nothing is done if SET and WAS_SET have the same value.  */
+template <typename F>
 static void
-s390_def_or_undef_macro (cpp_reader *pfile,
-			 unsigned int mask,
+s390_def_or_undef_macro (cpp_reader *pfile, F is_set,
 			 const struct cl_target_option *old_opts,
 			 const struct cl_target_option *new_opts,
 			 const char *macro_def, const char *macro_undef)
@@ -304,8 +304,8 @@ s390_def_or_undef_macro (cpp_reader *pfile,
   bool was_set;
   bool set;
 
-  was_set = (!old_opts) ? false : old_opts->x_target_flags & mask;
-  set = new_opts->x_target_flags & mask;
+  was_set = (!old_opts) ? false : is_set (old_opts);
+  set = is_set (new_opts);
   if (was_set == set)
     return;
   if (set)
@@ -314,6 +314,19 @@ s390_def_or_undef_macro (cpp_reader *pfile,
     cpp_undef (pfile, macro_undef);
 }
 
+struct target_flag_set_p
+{
+  target_flag_set_p (unsigned int mask) : m_mask (mask) {}
+
+  bool
+  operator() (const struct cl_target_option *opts) const
+  {
+    return opts->x_target_flags & m_mask;
+  }
+
+  unsigned int m_mask;
+};
+
 /* Internal function to either define or undef the appropriate system
    macros.  */
 static void
@@ -321,18 +334,18 @@ s390_cpu_cpp_builtins_internal (cpp_reader *pfile,
 				struct cl_target_option *opts,
 				const struct cl_target_option *old_opts)
 {
-  s390_def_or_undef_macro (pfile, MASK_OPT_HTM, old_opts, opts,
-			   "__HTM__", "__HTM__");
-  s390_def_or_undef_macro (pfile, MASK_OPT_VX, old_opts, opts,
-			   "__VX__", "__VX__");
-  s390_def_or_undef_macro (pfile, MASK_ZVECTOR, old_opts, opts,
-			   "__VEC__=10303", "__VEC__");
-  s390_def_or_undef_macro (pfile, MASK_ZVECTOR, old_opts, opts,
-			   "__vector=__attribute__((vector_size(16)))",
+  s390_def_or_undef_macro (pfile, target_flag_set_p (MASK_OPT_HTM), old_opts,
+			   opts, "__HTM__", "__HTM__");
+  s390_def_or_undef_macro (pfile, target_flag_set_p (MASK_OPT_VX), old_opts,
+			   opts, "__VX__", "__VX__");
+  s390_def_or_undef_macro (pfile, target_flag_set_p (MASK_ZVECTOR), old_opts,
+			   opts, "__VEC__=10303", "__VEC__");
+  s390_def_or_undef_macro (pfile, target_flag_set_p (MASK_ZVECTOR), old_opts,
+			   opts, "__vector=__attribute__((vector_size(16)))",
 			   "__vector__");
-  s390_def_or_undef_macro (pfile, MASK_ZVECTOR, old_opts, opts,
-			   "__bool=__attribute__((s390_vector_bool)) unsigned",
-			   "__bool");
+  s390_def_or_undef_macro (
+      pfile, target_flag_set_p (MASK_ZVECTOR), old_opts, opts,
+      "__bool=__attribute__((s390_vector_bool)) unsigned", "__bool");
   {
     char macro_def[64];
     gcc_assert (s390_arch != PROCESSOR_NATIVE);
@@ -340,16 +353,20 @@ s390_cpu_cpp_builtins_internal (cpp_reader *pfile,
     cpp_undef (pfile, "__ARCH__");
     cpp_define (pfile, macro_def);
   }
+  s390_def_or_undef_macro (
+      pfile,
+      [] (const struct cl_target_option *opts) { return TARGET_Z14_P (opts); },
+      old_opts, opts, "__LONG_DOUBLE_VX__", "__LONG_DOUBLE_VX__");
 
   if (!flag_iso)
     {
-      s390_def_or_undef_macro (pfile, MASK_ZVECTOR, old_opts, opts,
-			       "__VECTOR_KEYWORD_SUPPORTED__",
+      s390_def_or_undef_macro (pfile, target_flag_set_p (MASK_ZVECTOR),
+			       old_opts, opts, "__VECTOR_KEYWORD_SUPPORTED__",
 			       "__VECTOR_KEYWORD_SUPPORTED__");
-      s390_def_or_undef_macro (pfile, MASK_ZVECTOR, old_opts, opts,
-			       "vector=vector", "vector");
-      s390_def_or_undef_macro (pfile, MASK_ZVECTOR, old_opts, opts,
-			       "bool=bool", "bool");
+      s390_def_or_undef_macro (pfile, target_flag_set_p (MASK_ZVECTOR),
+			       old_opts, opts, "vector=vector", "vector");
+      s390_def_or_undef_macro (pfile, target_flag_set_p (MASK_ZVECTOR),
+			       old_opts, opts, "bool=bool", "bool");
       if (TARGET_ZVECTOR_P (opts->x_target_flags) && __vector_keyword == NULL)
 	{
 	  __vector_keyword = get_identifier ("__vector");
diff --git a/gcc/testsuite/gcc.target/s390/vector/long-double-vx-macro-off-on.c b/gcc/testsuite/gcc.target/s390/vector/long-double-vx-macro-off-on.c
new file mode 100644
index 00000000000..2d67679bb11
--- /dev/null
+++ b/gcc/testsuite/gcc.target/s390/vector/long-double-vx-macro-off-on.c
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target target_attribute } */
+/* { dg-options "-march=z14" } */
+#if !defined(__LONG_DOUBLE_VX__)
+#error
+#endif
+
+#pragma GCC target("arch=zEC12")
+#if defined(__LONG_DOUBLE_VX__)
+#error
+#endif
diff --git a/gcc/testsuite/gcc.target/s390/vector/long-double-vx-macro-on-off.c b/gcc/testsuite/gcc.target/s390/vector/long-double-vx-macro-on-off.c
new file mode 100644
index 00000000000..6f264313408
--- /dev/null
+++ b/gcc/testsuite/gcc.target/s390/vector/long-double-vx-macro-on-off.c
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target target_attribute } */
+/* { dg-options "-march=z13" } */
+#if defined(__LONG_DOUBLE_VX__)
+#error
+#endif
+
+#pragma GCC target("arch=z15")
+#if !defined(__LONG_DOUBLE_VX__)
+#error
+#endif
-- 
2.26.2


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

* Re: [PATCH] IBM Z: Introduce __LONG_DOUBLE_VX__ macro
  2021-01-08  0:17 [PATCH] IBM Z: Introduce __LONG_DOUBLE_VX__ macro Ilya Leoshkevich
@ 2021-01-08  8:35 ` Andreas Krebbel
  0 siblings, 0 replies; 2+ messages in thread
From: Andreas Krebbel @ 2021-01-08  8:35 UTC (permalink / raw)
  To: Ilya Leoshkevich, stli; +Cc: gcc-patches

On 1/8/21 1:17 AM, Ilya Leoshkevich wrote:

> +  s390_def_or_undef_macro (
> +      pfile,
> +      [] (const struct cl_target_option *opts) { return TARGET_Z14_P (opts); },
> +      old_opts, opts, "__LONG_DOUBLE_VX__", "__LONG_DOUBLE_VX__");

Shouldn't this rather check TARGET_VXE_P instead?

Bye,

Andreas

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

end of thread, other threads:[~2021-01-08  8:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-08  0:17 [PATCH] IBM Z: Introduce __LONG_DOUBLE_VX__ macro Ilya Leoshkevich
2021-01-08  8:35 ` Andreas Krebbel

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