[PATCH,rs6000] Add tests for vec_insert and vec_extract implemented with VSX instructions

Bill Schmidt wschmidt@linux.vnet.ibm.com
Tue Jan 21 17:14:00 GMT 2014


Hi,

A previous patch of mine implemented support for -maltivec=be for little
endian targets when expanding the vec_insert and vec_extract builtins.
However, I neglected to include test cases for V2DI and V2DF, which are
implemented using VSX instructions and therefore need different compile
options.  This patch adds those tests, which pass for
powerpc64{,le}-unknown-linux-gnu without further changes to GCC.  Ok for
trunk?

Thanks,
Bill


2014-01-21  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>

	* gcc.dg/vmx/insert-vsx-be-order.c: New.
	* gcc.dg/vmx/extract-vsx.c: New.
	* gcc.dg/vmx/extract-vsx-be-order.c: New.
	* gcc.dg/vmx/insert-vsx.c: New.


Index: gcc/testsuite/gcc.dg/vmx/insert-vsx-be-order.c
===================================================================
--- gcc/testsuite/gcc.dg/vmx/insert-vsx-be-order.c	(revision 0)
+++ gcc/testsuite/gcc.dg/vmx/insert-vsx-be-order.c	(revision 0)
@@ -0,0 +1,34 @@
+/* { dg-skip-if "" { powerpc*-*-darwin* } { "*" } { "" } } */
+/* { dg-require-effective-target powerpc_vsx_ok } */
+/* { dg-options "-maltivec=be -mabi=altivec -std=gnu99 -mvsx" } */
+
+#include "harness.h"
+
+static int vec_long_eq (vector long x, vector long y)
+{
+  return (x[0] == y[0] && x[1] == y[1]);
+}
+
+static int vec_dbl_eq (vector double x, vector double y)
+{
+  return (x[0] == y[0] && x[1] == y[1]);
+}
+
+static void test()
+{
+  vector long vl = {0, 1};
+  vector double vd = {0.0, 1.0};
+  vector long vlr = vec_insert (2, vl, 0);
+  vector double vdr = vec_insert (2.0, vd, 1);
+
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+  vector long vler = {0, 2};
+  vector double vder = {2.0, 1.0};
+#else
+  vector long vler = {2, 1};
+  vector double vder = {0.0, 2.0};
+#endif
+
+  check (vec_long_eq (vlr, vler), "vl");
+  check (vec_dbl_eq (vdr, vder), "vd");
+}
Index: gcc/testsuite/gcc.dg/vmx/extract-vsx.c
===================================================================
--- gcc/testsuite/gcc.dg/vmx/extract-vsx.c	(revision 0)
+++ gcc/testsuite/gcc.dg/vmx/extract-vsx.c	(revision 0)
@@ -0,0 +1,16 @@
+/* { dg-skip-if "" { powerpc*-*-darwin* } { "*" } { "" } } */
+/* { dg-require-effective-target powerpc_vsx_ok } */
+/* { dg-options "-maltivec -mabi=altivec -std=gnu99 -mvsx" } */
+
+#include "harness.h"
+
+static void test()
+{
+  vector long vl = {0, 1};
+  vector double vd = {0.0, 1.0};
+
+  check (vec_extract (vl, 0) == 0, "vec_extract, vl, 0");
+  check (vec_extract (vd, 1) == 1.0, "vec_extract, vd, 1");
+  check (vl[0] == 0, "[], vl, 0");
+  check (vd[1] == 1.0, "[], vd, 0");
+}
Index: gcc/testsuite/gcc.dg/vmx/extract-vsx-be-order.c
===================================================================
--- gcc/testsuite/gcc.dg/vmx/extract-vsx-be-order.c	(revision 0)
+++ gcc/testsuite/gcc.dg/vmx/extract-vsx-be-order.c	(revision 0)
@@ -0,0 +1,19 @@
+/* { dg-skip-if "" { powerpc*-*-darwin* } { "*" } { "" } } */
+/* { dg-require-effective-target powerpc_vsx_ok } */
+/* { dg-options "-maltivec=be -mabi=altivec -std=gnu99 -mvsx" } */
+
+#include "harness.h"
+
+static void test()
+{
+  vector long vl = {0, 1};
+  vector double vd = {0.0, 1.0};
+
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+  check (vec_extract (vl, 0) == 1, "vl, 0");
+  check (vec_extract (vd, 1) == 0.0, "vd, 1");
+#else
+  check (vec_extract (vl, 0) == 0, "vl, 0");
+  check (vec_extract (vd, 1) == 1.0, "vd, 1");
+#endif
+}
Index: gcc/testsuite/gcc.dg/vmx/insert-vsx.c
===================================================================
--- gcc/testsuite/gcc.dg/vmx/insert-vsx.c	(revision 0)
+++ gcc/testsuite/gcc.dg/vmx/insert-vsx.c	(revision 0)
@@ -0,0 +1,28 @@
+/* { dg-skip-if "" { powerpc*-*-darwin* } { "*" } { "" } } */
+/* { dg-require-effective-target powerpc_vsx_ok } */
+/* { dg-options "-maltivec -mabi=altivec -std=gnu99 -mvsx" } */
+
+#include "harness.h"
+
+static int vec_long_eq (vector long x, vector long y)
+{
+  return (x[0] == y[0] && x[1] == y[1]);
+}
+
+static int vec_dbl_eq (vector double x, vector double y)
+{
+  return (x[0] == y[0] && x[1] == y[1]);
+}
+
+static void test()
+{
+  vector long vl = {0, 1};
+  vector double vd = {0.0, 1.0};
+  vector long vlr = vec_insert (2, vl, 0);
+  vector double vdr = vec_insert (2.0, vd, 1);
+  vector long vler = {2, 1};
+  vector double vder = {0.0, 2.0};
+
+  check (vec_long_eq (vlr, vler), "vl");
+  check (vec_dbl_eq (vdr, vder), "vd");
+}




More information about the Gcc-patches mailing list