Re: [PATCH] rs6000: add effective-target test ppc_mma_hw

2020-07-11 Thread Segher Boessenkool
Hi Aaron,

On Fri, Jul 10, 2020 at 05:58:59PM -0500, Aaron Sawdey via Gcc-patches wrote:
> Add a test for dejagnu to determine if execution of MMA instructions is
> supported in the test environment. Add an execution test to make sure
> that __builtin_cpu_supports("mma") is true if we can execute MMA
> instructions.

> +int
> +main (int argc, char *argv[])
> +{
> +  int ret = 0;
> +#ifdef __BUILTIN_CPU_SUPPORTS__
> +  if ( !__builtin_cpu_supports ("mma"))
> +{
> +  printf ("Error: __builtin_cpu_supports says mma not supported, but 
> ppc_mma_hw test passed.\n");
> +  ret++;
> +}
> +#endif
> +  return ret;
> +}

This will complain about spurious test output, I think?  We usually put
#ifdef DEBUG  around such prints, but here you could just remove it, make
it a comment?  And maybe just do  exit(1);  or  abort();  or whatever.

> + __vector_quad acc0;
> + v4sf_t result[4];
> + result[0][0] = 1.0;
> + __builtin_mma_xxsetaccz ();
> + __builtin_mma_disassemble_acc (result, );
> + if ( result[0][0] != 0.0 )
> + return 1;
> + return 0;

No spaces inside ( ) please, and indent that first return statement?  We
don't care about the testcases themselves (more styles tests ever so
slightly more, even ;-) ), but this isn't a testcase :-)  Not that it is
important here, but hey.

> @@ -7865,6 +7891,7 @@ proc is-effective-target-keyword { arg } {
> "named_sections" { return 1 }
> "gc_sections"{ return 1 }
> "cxa_atexit" { return 1 }
> +   "ppc_mma_hw" { return 1 }
> default  { return 0 }
>   }

Hrm, do we want it to be named ppc_mma_hw?  Why not mma_hw just like
most other things?

And keep all rs6000 keywords together please (also power10_hw).

(I also wonder why rs6000 does things differently here, it's the only
arch that uses this apparently, hrm).


Okay for trunk (and backport to 10) modulo those nits.  Thanks!


Segher


[PATCH] rs6000: add effective-target test ppc_mma_hw

2020-07-10 Thread Aaron Sawdey via Gcc-patches
Add a test for dejagnu to determine if execution of MMA instructions is
supported in the test environment. Add an execution test to make sure
that __builtin_cpu_supports("mma") is true if we can execute MMA
instructions.

OK for trunk and backport to 10?

Thanks!
   Aaron

gcc/testsuite/

* lib/target-supports.exp (check_ppc_mma_hw_available):
New function.
(is-effective-target): Add ppc_mma_hw.
(is-effective-target-keyword): Add ppc_mma_hw.
* gcc.target/powerpc/mma-supported.c: New file.
* gcc.target/powerpc/mma-single-test.c: Require ppc_mma_hw.
* gcc.target/powerpc/mma-double-test.c: Require ppc_mma_hw.
---
 .../gcc.target/powerpc/mma-double-test.c  |  1 +
 .../gcc.target/powerpc/mma-single-test.c  |  1 +
 .../gcc.target/powerpc/mma-supported.c| 24 +
 gcc/testsuite/lib/target-supports.exp | 27 +++
 4 files changed, 53 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/powerpc/mma-supported.c

diff --git a/gcc/testsuite/gcc.target/powerpc/mma-double-test.c 
b/gcc/testsuite/gcc.target/powerpc/mma-double-test.c
index 9ba0010978f..ac84ae30004 100755
--- a/gcc/testsuite/gcc.target/powerpc/mma-double-test.c
+++ b/gcc/testsuite/gcc.target/powerpc/mma-double-test.c
@@ -1,5 +1,6 @@
 /* { dg-do run } */
 /* { dg-require-effective-target power10_hw } */
+/* { dg-require-effective-target ppc_mma_hw } */
 /* { dg-options "-mdejagnu-cpu=power10 -O2" } */
 
 #include 
diff --git a/gcc/testsuite/gcc.target/powerpc/mma-single-test.c 
b/gcc/testsuite/gcc.target/powerpc/mma-single-test.c
index aa71fa7f0af..15369a64025 100755
--- a/gcc/testsuite/gcc.target/powerpc/mma-single-test.c
+++ b/gcc/testsuite/gcc.target/powerpc/mma-single-test.c
@@ -1,5 +1,6 @@
 /* { dg-do run } */
 /* { dg-require-effective-target power10_hw } */
+/* { dg-require-effective-target ppc_mma_hw } */
 /* { dg-options "-mdejagnu-cpu=power10 -O2" } */
 
 #include 
diff --git a/gcc/testsuite/gcc.target/powerpc/mma-supported.c 
b/gcc/testsuite/gcc.target/powerpc/mma-supported.c
new file mode 100644
index 000..64943e362a8
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/mma-supported.c
@@ -0,0 +1,24 @@
+/* { dg-do run } */
+/* { dg-require-effective-target ppc_mma_hw } */
+/* { dg-options "-mdejagnu-cpu=power10 -O2" } */
+
+/* This test will only run when the ppc_mma_hw test passes.  If that
+   test passes, then we expect to see that mma feature is supported.
+   If this is not the case, then the test environment has problems. */
+
+#include 
+#include 
+
+int
+main (int argc, char *argv[])
+{
+  int ret = 0;
+#ifdef __BUILTIN_CPU_SUPPORTS__
+  if ( !__builtin_cpu_supports ("mma"))
+{
+  printf ("Error: __builtin_cpu_supports says mma not supported, but 
ppc_mma_hw test passed.\n");
+  ret++;
+}
+#endif
+  return ret;
+}
diff --git a/gcc/testsuite/lib/target-supports.exp 
b/gcc/testsuite/lib/target-supports.exp
index aeb0351073d..04f6db53eca 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -2234,6 +2234,31 @@ proc check_power10_hw_available { } {
 }]
 }
 
+# Return 1 if the target supports executing MMA instructions, 0 otherwise.
+# Cache the result.  It is assumed that if a simulator does not support the
+# MMA instructions, that it will generate an error and this test will fail.
+
+proc check_ppc_mma_hw_available { } {
+return [check_cached_effective_target ppc_mma_hw_available {
+   check_runtime_nocache ppc_mma_hw_available {
+   #include 
+   typedef double v4sf_t __attribute__ ((vector_size (16)));
+
+   int main()
+   {
+   __vector_quad acc0;
+   v4sf_t result[4];
+   result[0][0] = 1.0;
+   __builtin_mma_xxsetaccz ();
+   __builtin_mma_disassemble_acc (result, );
+   if ( result[0][0] != 0.0 )
+   return 1;
+   return 0;
+   }
+   } "-mcpu=power10"
+}]
+}
+
 # Return 1 if the target supports executing __float128 on PowerPC via software
 # emulation, 0 otherwise.  Cache the result.
 
@@ -7836,6 +7861,7 @@ proc is-effective-target { arg } {
  "gc_sections"{ set selected [check_gc_sections_available] }
  "cxa_atexit" { set selected [check_cxa_atexit_available] }
  "power10_hw" { set selected [check_power10_hw_available] }
+ "ppc_mma_hw" { set selected [check_ppc_mma_hw_available] }
  default  { error "unknown effective target keyword `$arg'" }
}
 }
@@ -7865,6 +7891,7 @@ proc is-effective-target-keyword { arg } {
  "named_sections" { return 1 }
  "gc_sections"{ return 1 }
  "cxa_atexit" { return 1 }
+ "ppc_mma_hw" { return 1 }
  default  { return 0 }
}
 }
-- 
2.17.1