[gcc r11-6556] IBM Z: Introduce __LONG_DOUBLE_VX__ macro

Ilya Leoshkevich iii@gcc.gnu.org
Fri Jan 8 16:45:00 GMT 2021


https://gcc.gnu.org/g:f47df2af313d2ce7f9149149010a142c2237beda

commit r11-6556-gf47df2af313d2ce7f9149149010a142c2237beda
Author: Ilya Leoshkevich <iii@linux.ibm.com>
Date:   Mon Dec 14 14:05:28 2020 +0100

    IBM Z: Introduce __LONG_DOUBLE_VX__ macro
    
    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.
    
    2020-12-14  Ilya Leoshkevich  <iii@linux.ibm.com>
    
    gcc/testsuite/ChangeLog:
    
            * gcc.target/s390/vector/long-double-vx-macro-off-on.c: New test.
            * gcc.target/s390/vector/long-double-vx-macro-on-off.c: New test.

Diff:
---
 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(-)

diff --git a/gcc/config/s390/s390-c.c b/gcc/config/s390/s390-c.c
index 95cd2df505d..a5f5f56311a 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_VXE_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


More information about the Gcc-cvs mailing list