rs6000: Add cntlzdm and cnttzdm
authorKelvin Nilsen <kelvin@gcc.gnu.org>
Mon, 11 May 2020 20:10:24 +0000 (15:10 -0500)
committerBill Schmidt <wschmidt@linux.ibm.com>
Mon, 11 May 2020 20:27:24 +0000 (15:27 -0500)
Add support for new scalar instructions for counting leading or
trailing zeros under control of a bitmask.

[gcc]

2020-05-11  Kelvin Nilsen  <kelvin@gcc.gnu.org>

* config/rs6000/rs6000-builtin.def (__builtin_cntlzdm): New
built-in function definition.
(__builtin_cnttzdm): Likewise.
* config/rs6000/rs6000.md (UNSPEC_CNTLZDM): New constant.
(UNSPEC_CNTTZDM): Likewise.
(cntlzdm): New insn.
(cnttzdm): Likewise.
* doc/extend.texi (Basic PowerPC Built-in Functions available for
a Future Architecture): Add descriptions of __builtin_cntlzdm and
__builtin_cnttzdm functions.

[gcc/testsuite]

2020-05-11  Kelvin Nilsen  <kelvin@gcc.gnu.org>

* gcc.target/powerpc/cntlzdm-0.c: New test.
* gcc.target/powerpc/cntlzdm-1.c: New test.
* gcc.target/powerpc/cnttzdm-0.c: New test.
* gcc.target/powerpc/cnttzdm-1.c: New test.

gcc/ChangeLog
gcc/config/rs6000/rs6000-builtin.def
gcc/config/rs6000/rs6000.md
gcc/doc/extend.texi
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/powerpc/cntlzdm-0.c [new file with mode: 0644]
gcc/testsuite/gcc.target/powerpc/cntlzdm-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/powerpc/cnttzdm-0.c [new file with mode: 0644]
gcc/testsuite/gcc.target/powerpc/cnttzdm-1.c [new file with mode: 0644]

index d9f96a5..4dea211 100644 (file)
@@ -5,6 +5,19 @@
 
 2020-05-11  Kelvin Nilsen  <kelvin@gcc.gnu.org>
 
+       * config/rs6000/rs6000-builtin.def (__builtin_cntlzdm): New
+       built-in function definition.
+       (__builtin_cnttzdm): Likewise.
+       * config/rs6000/rs6000.md (UNSPEC_CNTLZDM): New constant.
+       (UNSPEC_CNTTZDM): Likewise.
+       (cntlzdm): New insn.
+       (cnttzdm): Likewise.
+       * doc/extend.texi (Basic PowerPC Built-in Functions available for
+       a Future Architecture): Add descriptions of __builtin_cntlzdm and
+       __builtin_cnttzdm functions.
+
+2020-05-11  Kelvin Nilsen  <kelvin@gcc.gnu.org>
+
        * config/rs6000/altivec.h (vec_cfuge): New #define.
        * config/rs6000/altivec.md (UNSPEC_VCFUGED): New constant.
        (vcfuged): New insn.
index 9d80d03..c05d9f5 100644 (file)
@@ -2575,6 +2575,8 @@ BU_P9_OVERLOAD_2 (CMPEQB, "byte_in_set")
 \f
 /* Future architecture scalar built-ins.  */
 BU_FUTURE_MISC_2 (CFUGED, "cfuged", CONST, cfuged)
+BU_FUTURE_MISC_2 (CNTLZDM, "cntlzdm", CONST, cntlzdm)
+BU_FUTURE_MISC_2 (CNTTZDM, "cnttzdm", CONST, cnttzdm)
 
 /* Future architecture vector built-ins.  */
 BU_FUTURE_V_2 (VCFUGED, "vcfuged", CONST, vcfuged)
index 1ceb393..6c9bae9 100644 (file)
    UNSPEC_PLTSEQ
    UNSPEC_PLT16_HA
    UNSPEC_CFUGED
+   UNSPEC_CNTLZDM
+   UNSPEC_CNTTZDM
   ])
 
 ;;
    "cfuged %0,%1,%2"
    [(set_attr "type" "integer")])
 
+(define_insn "cntlzdm"
+  [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
+       (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "r")
+                   (match_operand:DI 2 "gpc_reg_operand" "r")]
+        UNSPEC_CNTLZDM))]
+   "TARGET_FUTURE && TARGET_POWERPC64"
+   "cntlzdm %0,%1,%2"
+   [(set_attr "type" "integer")])
+
+(define_insn "cnttzdm"
+  [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
+       (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "r")
+                   (match_operand:DI 2 "gpc_reg_operand" "r")]
+        UNSPEC_CNTTZDM))]
+   "TARGET_FUTURE && TARGET_POWERPC64"
+   "cnttzdm %0,%1,%2"
+   [(set_attr "type" "integer")])
+
 (define_insn "cmpb<mode>3"
   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
        (unspec:GPR [(match_operand:GPR 1 "gpc_reg_operand" "r")
index f7b30c7..8c833d3 100644 (file)
@@ -17556,6 +17556,22 @@ Perform a 64-bit centrifuge operation, as if implemented by the Future
 @code{cfuged} instruction.
 @findex __builtin_cfuged
 
+@smallexample
+@exdent unsigned long long int
+@exdent __builtin_cntlzdm (unsigned long long int, unsigned long long int)
+@end smallexample
+Perform a 64-bit count leading zeros operation under mask, as if
+implemented by the future @code{cntlzdm} instruction.
+@findex __builtin_cntlzdm
+
+@smallexample
+@exdent unsigned long long int
+@exdent __builtin_cnttzdm (unsigned long long int, unsigned long long int)
+@end smallexample
+Perform a 64-bit count trailing zeros operation under mask, as if
+implemented by the future @code{cnttzdm} instruction.
+@findex __builtin_cnttzdm
+
 @node PowerPC AltiVec/VSX Built-in Functions
 @subsection PowerPC AltiVec/VSX Built-in Functions
 
index 99d0683..333b803 100644 (file)
 
 2020-05-11  Kelvin Nilsen  <kelvin@gcc.gnu.org>
 
+       * gcc.target/powerpc/cntlzdm-0.c: New test.
+       * gcc.target/powerpc/cntlzdm-1.c: New test.
+       * gcc.target/powerpc/cnttzdm-0.c: New test.
+       * gcc.target/powerpc/cnttzdm-1.c: New test.
+
+2020-05-11  Kelvin Nilsen  <kelvin@gcc.gnu.org>
+
        * gcc.target/powerpc/vec-cfuged-0.c: New test.
        * gcc.target/powerpc/vec-cfuged-1.c: New test.
 
diff --git a/gcc/testsuite/gcc.target/powerpc/cntlzdm-0.c b/gcc/testsuite/gcc.target/powerpc/cntlzdm-0.c
new file mode 100644 (file)
index 0000000..8cdd261
--- /dev/null
@@ -0,0 +1,56 @@
+/* { dg-require-effective-target powerpc64 } */
+/* { dg-options "-mdejagnu-cpu=future" } */
+
+extern void abort (void);
+
+unsigned long long int
+do_cntlzdm (unsigned long long int source, unsigned long long int mask)
+{
+  return __builtin_cntlzdm (source, mask);
+}
+
+int main (int argc, char *argv [])
+{
+  unsigned long long int sources [4], masks [4];
+  unsigned long long int intermediates [4][4] = {
+    /* sources[0] with each of masks [0 .. 3] */
+    { 0x0000a5f0ll, 0x00007e3cll, 0x000050ecll, 0x0000af73ll },
+    /* sources[1] with each of masks [0 .. 3] */
+    { 0x00007e3cll, 0x0000a5f0ll, 0x0000ec50ll, 0x000073afll },
+    /* sources[2] with each of masks [0 .. 3] */
+    { 0x00003ca5ll, 0x0000f07ell, 0x0000c50ell, 0x00003af7ll },
+    /* sources[3] with each of masks [0 .. 3] */
+    { 0x00005a0fll, 0x0000e7c3ll, 0x0000af73ll, 0x000050ecll },
+  };
+  unsigned long long int results [4][4] = {
+    { 0, 1, 1, 0 },
+    { 1, 0, 0, 1 },
+    { 2, 0, 0, 2 },
+    { 1, 0, 0, 1 },
+  };
+
+  sources[0] = 0xa5f07e3cll;
+  sources[1] = 0x7e3ca5f0ll;
+  sources[2] = 0x3ca5f07ell;
+  sources[3] = 0x5a0fe7c3ll;
+
+  masks[0] = 0xffff0000ll;
+  masks[1] = 0x0000ffffll;
+  masks[2] = 0x0f0f0f0fll;
+  masks[3] = 0xf0f0f0f0ll;
+
+  unsigned long long int result;
+
+  for (int i = 0; i < 4; i++)
+    {
+      for (int j = 0; j < 4; j++)
+       {
+         if (do_cntlzdm (sources[i], masks[j]) != results [i][j])
+           abort ();
+       }
+    }
+
+  return 0;
+}
+
+/* { dg-final { scan-assembler {\mcntlzdm\M} } } */
diff --git a/gcc/testsuite/gcc.target/powerpc/cntlzdm-1.c b/gcc/testsuite/gcc.target/powerpc/cntlzdm-1.c
new file mode 100644 (file)
index 0000000..d5a087f
--- /dev/null
@@ -0,0 +1,56 @@
+/* { dg-do run } */
+/* { dg-require-effective-target powerpc_future_hw } */
+/* { dg-require-effective-target powerpc64 } */
+/* { dg-options "-mdejagnu-cpu=future" } */
+
+extern void abort (void);
+
+unsigned long long int
+do_cntlzdm (unsigned long long int source, unsigned long long int mask)
+{
+  return __builtin_cntlzdm (source, mask);
+}
+
+int main (int argc, char *argv [])
+{
+  unsigned long long int sources [4], masks [4];
+  unsigned long long int intermediates [4][4] = {
+    /* sources[0] with each of masks [0 .. 3] */
+    { 0x0000a5f0ll, 0x00007e3cll, 0x000050ecll, 0x0000af73ll },
+    /* sources[1] with each of masks [0 .. 3] */
+    { 0x00007e3cll, 0x0000a5f0ll, 0x0000ec50ll, 0x000073afll },
+    /* sources[2] with each of masks [0 .. 3] */
+    { 0x00003ca5ll, 0x0000f07ell, 0x0000c50ell, 0x00003af7ll },
+    /* sources[3] with each of masks [0 .. 3] */
+    { 0x00005a0fll, 0x0000e7c3ll, 0x0000af73ll, 0x000050ecll },
+  };
+  unsigned long long int results [4][4] = {
+    { 0, 1, 1, 0 },
+    { 1, 0, 0, 1 },
+    { 2, 0, 0, 2 },
+    { 1, 0, 0, 1 },
+  };
+
+  sources[0] = 0xa5f07e3cll;
+  sources[1] = 0x7e3ca5f0ll;
+  sources[2] = 0x3ca5f07ell;
+  sources[3] = 0x5a0fe7c3ll;
+
+  masks[0] = 0xffff0000ll;
+  masks[1] = 0x0000ffffll;
+  masks[2] = 0x0f0f0f0fll;
+  masks[3] = 0xf0f0f0f0ll;
+
+  unsigned long long int result;
+
+  for (int i = 0; i < 4; i++)
+    {
+      for (int j = 0; j < 4; j++)
+       {
+         if (do_cntlzdm (sources[i], masks[j]) != results [i][j])
+           abort ();
+       }
+    }
+
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.target/powerpc/cnttzdm-0.c b/gcc/testsuite/gcc.target/powerpc/cnttzdm-0.c
new file mode 100644 (file)
index 0000000..36acc0b
--- /dev/null
@@ -0,0 +1,52 @@
+/* { dg-options "-mdejagnu-cpu=future" } */
+
+extern void abort (void);
+
+unsigned long long int
+do_cnttzdm (unsigned long long int source, unsigned long long int mask) {
+  return __builtin_cnttzdm (source, mask);
+}
+
+int main (int argc, char *argv [])
+{
+  unsigned long long int sources [4], masks [4];
+  unsigned long long int intermediates [4][4] = {
+    /* sources[0] with each of masks [0 .. 3] */
+    { 0x0000a5f0ll, 0x00007e3cll, 0x000050ecll, 0x0000af73ll },
+    /* sources[1] with each of masks [0 .. 3] */
+    { 0x00007e3cll, 0x0000a5f0ll, 0x0000ec50ll, 0x000073afll },
+    /* sources[2] with each of masks [0 .. 3] */
+    { 0x00003ca5ll, 0x0000f07ell, 0x0000c50ell, 0x00003af7ll },
+    /* sources[3] with each of masks [0 .. 3] */
+    { 0x00005a0fll, 0x0000e7c3ll, 0x0000af73ll, 0x000050ecll },
+  };
+  unsigned long long int results [4][4] = {
+    { 4, 2, 2, 0 },
+    { 2, 4, 4, 0 },
+    { 0, 1, 1, 0 },
+    { 0, 0, 0, 2 },
+  };
+
+  sources[0] = 0xa5f07e3cll;
+  sources[1] = 0x7e3ca5f0ll;
+  sources[2] = 0x3ca5f07ell;
+  sources[3] = 0x5a0fe7c3ll;
+
+  masks[0] = 0xffff0000ll;
+  masks[1] = 0x0000ffffll;
+  masks[2] = 0x0f0f0f0fll;
+  masks[3] = 0xf0f0f0f0ll;
+
+  for (int i = 0; i < 4; i++)
+    {
+      for (int j = 0; j < 4; j++)
+       {
+         if (do_cnttzdm (sources[i], masks[j]) != results [i][j])
+           abort ();
+       }
+    }
+
+  return 0;
+}
+
+/* { dg-final { scan-assembler {\mcnttzdm\M} } } */
diff --git a/gcc/testsuite/gcc.target/powerpc/cnttzdm-1.c b/gcc/testsuite/gcc.target/powerpc/cnttzdm-1.c
new file mode 100644 (file)
index 0000000..cb11976
--- /dev/null
@@ -0,0 +1,53 @@
+/* { dg-do run } */
+/* { dg-require-effective-target powerpc_future_hw } */
+/* { dg-require-effective-target powerpc64 } */
+/* { dg-options "-mdejagnu-cpu=future" } */
+
+extern void abort (void);
+
+unsigned long long int
+do_cnttzdm (unsigned long long int source, unsigned long long int mask) {
+  return __builtin_cnttzdm (source, mask);
+}
+
+int main (int argc, char *argv [])
+{
+  unsigned long long int sources [4], masks [4];
+  unsigned long long int intermediates [4][4] = {
+    /* sources[0] with each of masks [0 .. 3] */
+    { 0x0000a5f0ll, 0x00007e3cll, 0x000050ecll, 0x0000af73ll },
+    /* sources[1] with each of masks [0 .. 3] */
+    { 0x00007e3cll, 0x0000a5f0ll, 0x0000ec50ll, 0x000073afll },
+    /* sources[2] with each of masks [0 .. 3] */
+    { 0x00003ca5ll, 0x0000f07ell, 0x0000c50ell, 0x00003af7ll },
+    /* sources[3] with each of masks [0 .. 3] */
+    { 0x00005a0fll, 0x0000e7c3ll, 0x0000af73ll, 0x000050ecll },
+  };
+  unsigned long long int results [4][4] = {
+    { 4, 2, 2, 0 },
+    { 2, 4, 4, 0 },
+    { 0, 1, 1, 0 },
+    { 0, 0, 0, 2 },
+  };
+
+  sources[0] = 0xa5f07e3cll;
+  sources[1] = 0x7e3ca5f0ll;
+  sources[2] = 0x3ca5f07ell;
+  sources[3] = 0x5a0fe7c3ll;
+
+  masks[0] = 0xffff0000ll;
+  masks[1] = 0x0000ffffll;
+  masks[2] = 0x0f0f0f0fll;
+  masks[3] = 0xf0f0f0f0ll;
+
+  for (int i = 0; i < 4; i++)
+    {
+      for (int j = 0; j < 4; j++)
+       {
+         if (do_cnttzdm (sources[i], masks[j]) != results [i][j])
+           abort ();
+       }
+    }
+
+  return 0;
+}