This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[power7-meissner] Add more bswap tests


I cloned Andreas Krebbel's bswap tests to make sure the appropriate ldbrx,
lwbrx, stdbrx, stwbrx is generated on the powerpc.

[gcc/testsuite]
2009-06-15  Michael Meissner  <meissner@linux.vnet.ibm.com>

	* gcc.target/powerpc/optimize-bswapsi-2.c: Clone bswap tests from
	gcc.dg, adding checks for lwbrx/stwbrx/ldbrx/stbrx being generated
	on the powerpc.
	* gcc.target/powerpc/optimize-bswapdi-2.c: Ditto.
	* gcc.target/powerpc/optimize-bswapdi-3.c: Ditto.

Index: gcc/testsuite/gcc.target/powerpc/optimize-bswapdi-2.c
===================================================================
--- gcc/testsuite/gcc.target/powerpc/optimize-bswapdi-2.c	(revision 0)
+++ gcc/testsuite/gcc.target/powerpc/optimize-bswapdi-2.c	(revision 0)
@@ -0,0 +1,36 @@
+/* { dg-require-effective-target stdint_types } */
+/* { dg-require-effective-target lp64 } */
+/* { dg-options "-O2 -mcpu=power5" } */
+
+/* This is a clone of gcc-dg/optimize-bswapdi-1.c, redone to use load and stores
+   to test whether lwbrx/stwbrx is generated for normal power systems.  */
+
+#include <stdint.h>
+#define __const_swab64(x) ((uint64_t)(			                        \
+	(((uint64_t)(x) & (uint64_t)0x00000000000000ffULL) << 56) |             \
+	(((uint64_t)(x) & (uint64_t)0x000000000000ff00ULL) << 40) |		\
+	(((uint64_t)(x) & (uint64_t)0x0000000000ff0000ULL) << 24) |		\
+	(((uint64_t)(x) & (uint64_t)0x00000000ff000000ULL) <<  8) |		\
+	(((uint64_t)(x) & (uint64_t)0x000000ff00000000ULL) >>  8) |		\
+	(((uint64_t)(x) & (uint64_t)0x0000ff0000000000ULL) >> 24) |		\
+	(((uint64_t)(x) & (uint64_t)0x00ff000000000000ULL) >> 40) |		\
+	(((uint64_t)(x) & (uint64_t)0xff00000000000000ULL) >> 56)))
+
+
+/* This byte swap implementation is used by the Linux kernel and the
+   GNU C library.  */
+
+uint64_t
+swap64_load (uint64_t *in)
+{
+  return __const_swab64 (*in);
+}
+
+void
+swap64_store (uint64_t *out, uint64_t in)
+{
+  *out = __const_swab64 (in);
+}
+
+/* { dg-final { scan-assembler-times "lwbrx" 2 } } */
+/* { dg-final { scan-assembler-times "stwbrx" 2 } } */
Index: gcc/testsuite/gcc.target/powerpc/optimize-bswapdi-3.c
===================================================================
--- gcc/testsuite/gcc.target/powerpc/optimize-bswapdi-3.c	(revision 0)
+++ gcc/testsuite/gcc.target/powerpc/optimize-bswapdi-3.c	(revision 0)
@@ -0,0 +1,36 @@
+/* { dg-require-effective-target stdint_types } */
+/* { dg-require-effective-target lp64 } */
+/* { dg-options "-O2 -mcpu=power7" } */
+
+/* This is a clone of gcc-dg/optimize-bswapdi-1.c, redone to use load and stores
+   to test whether ldbrx/stdbrx is generated for power7.  */
+
+#include <stdint.h>
+#define __const_swab64(x) ((uint64_t)(			                        \
+	(((uint64_t)(x) & (uint64_t)0x00000000000000ffULL) << 56) |             \
+	(((uint64_t)(x) & (uint64_t)0x000000000000ff00ULL) << 40) |		\
+	(((uint64_t)(x) & (uint64_t)0x0000000000ff0000ULL) << 24) |		\
+	(((uint64_t)(x) & (uint64_t)0x00000000ff000000ULL) <<  8) |		\
+	(((uint64_t)(x) & (uint64_t)0x000000ff00000000ULL) >>  8) |		\
+	(((uint64_t)(x) & (uint64_t)0x0000ff0000000000ULL) >> 24) |		\
+	(((uint64_t)(x) & (uint64_t)0x00ff000000000000ULL) >> 40) |		\
+	(((uint64_t)(x) & (uint64_t)0xff00000000000000ULL) >> 56)))
+
+
+/* This byte swap implementation is used by the Linux kernel and the
+   GNU C library.  */
+
+uint64_t
+swap64_load (uint64_t *in)
+{
+  return __const_swab64 (*in);
+}
+
+void
+swap64_store (uint64_t *out, uint64_t in)
+{
+  *out = __const_swab64 (in);
+}
+
+/* { dg-final { scan-assembler "ldbrx" } } */
+/* { dg-final { scan-assembler "stdbrx" } } */
Index: gcc/testsuite/gcc.target/powerpc/optimize-bswapsi-2.c
===================================================================
--- gcc/testsuite/gcc.target/powerpc/optimize-bswapsi-2.c	(revision 0)
+++ gcc/testsuite/gcc.target/powerpc/optimize-bswapsi-2.c	(revision 0)
@@ -0,0 +1,55 @@
+/* { dg-require-effective-target stdint_types } */
+/* { dg-options "-O2 -mcpu=power5" } */
+
+#include <stdint.h>
+
+/* This is a clone of gcc-dg/optimize-bswapsi-1.c, redone to use load and stores
+   to test whether lwbrx/stwbrx is generated for normal power systems.  */
+
+#define __const_swab32(x) ((uint32_t)(				      \
+        (((uint32_t)(x) & (uint32_t)0x000000ffUL) << 24) |            \
+        (((uint32_t)(x) & (uint32_t)0x0000ff00UL) <<  8) |            \
+        (((uint32_t)(x) & (uint32_t)0x00ff0000UL) >>  8) |            \
+        (((uint32_t)(x) & (uint32_t)0xff000000UL) >> 24)))
+
+/* This byte swap implementation is used by the Linux kernel and the
+   GNU C library.  */
+
+uint32_t
+swap32_a_load (uint32_t *in)
+{
+  return __const_swab32 (*in);
+}
+
+/* The OpenSSH byte swap implementation.  */
+uint32_t
+swap32_b_load (uint32_t *in)
+{
+  uint32_t a;
+
+  a = (*in << 16) | (*in >> 16);
+  a = ((a & 0x00ff00ff) << 8) | ((a & 0xff00ff00) >> 8);
+
+  return a;
+}
+
+void
+swap32_a_store (uint32_t *out, uint32_t in)
+{
+  *out = __const_swab32 (in);
+}
+
+/* The OpenSSH byte swap implementation.  */
+void
+swap32_b_store (uint32_t *out, uint32_t in)
+{
+  uint32_t a;
+
+  a = (in << 16) | (in >> 16);
+  a = ((a & 0x00ff00ff) << 8) | ((a & 0xff00ff00) >> 8);
+
+  *out = a;
+}
+
+/* { dg-final { scan-assembler-times "lwbrx" 2 } } */
+/* { dg-final { scan-assembler-times "stwbrx" 2 } } */

-- 
Michael Meissner, IBM
4 Technology Place Drive, MS 2203A, Westford, MA, 01886, USA
meissner@linux.vnet.ibm.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]