* gcc.target/powerpc/builtins-1-be.c <vclzb>: Rename duplicate test
[official-gcc.git] / gcc / testsuite / gcc.target / powerpc / swaps-p8-29.c
blob943f4e732edcdac60ddb164d96e1e0a78a581725
1 /* { dg-do run { target { powerpc*-*-* } } } */
2 /* { dg-require-effective-target p8vector_hw } */
3 /* { dg-skip-if "do not override -mcpu" { powerpc*-*-* } { "-mcpu=*" } { "-mcpu=power8" } } */
4 /* { dg-options "-mcpu=power8 -O3 " } */
6 #include <altivec.h>
8 extern void abort (void);
10 const vector char y = { 0, 1, 2, 3,
11 4, 5, 6, 7,
12 8, 9, 10, 11,
13 12, 13, 14, 15 };
15 vector char x, z;
17 vector char
18 foo (void)
20 return y; /* Remove 1 swap and use lvx. */
23 vector char
24 foo1 (void)
26 x = y; /* Remove 2 redundant swaps here. */
27 return x; /* Remove 1 swap and use lvx. */
30 void __attribute__ ((noinline))
31 fill_local (vector char *vp)
33 *vp = x; /* Remove 2 redundant swaps here. */
36 /* Test aligned load from local. */
37 vector char
38 foo2 (void)
40 vector char v;
42 /* Need to be clever here because v will normally reside in a
43 register rather than memory. */
44 fill_local (&v);
45 return v; /* Remove 1 swap and use lvx. */
49 /* Test aligned load from pointer. */
50 vector char
51 foo3 (vector char *arg)
53 return *arg; /* Remove 1 swap and use lvx. */
56 /* In this structure, the compiler should insert padding to assure
57 that a_vector is properly aligned. */
58 struct bar {
59 char a_field;
60 vector char a_vector;
63 vector char
64 foo4 (struct bar *bp)
66 return bp->a_vector; /* Remove 1 swap and use lvx. */
69 /* Test aligned store to global. */
70 void
71 baz (vector char arg)
73 x = arg; /* Remove 1 swap and use stvx. */
76 void __attribute__ ((noinline))
77 copy_local (vector char *arg)
79 x = *arg; /* Remove 2 redundant swaps. */
83 /* Test aligned store to local. */
84 void
85 baz1 (vector char arg)
87 vector char v;
89 /* Need cleverness, because v will normally reside in a register
90 rather than memory. */
91 v = arg; /* Aligned store to local: remove 1
92 swap and use stvx. */
93 copy_local (&v);
96 /* Test aligned store to pointer. */
97 void
98 baz2 (vector char *arg1, vector char arg2)
100 /* Assume arg2 resides in register. */
101 *arg1 = arg2; /* Remove 1 swap and use stvx. */
104 void
105 baz3 (struct bar *bp, vector char v)
107 /* Assume v resides in register. */
108 bp->a_vector = v; /* Remove 1 swap and use stvx. */
112 main (int argc, char *argv[])
114 vector char fetched_value = foo ();
115 if (fetched_value[0] != 0 || fetched_value[15] != 15)
116 abort ();
118 fetched_value = foo1 ();
119 if (fetched_value[1] != 1 || fetched_value[14] != 14)
120 abort ();
122 fetched_value = foo2 ();
123 if (fetched_value[2] != 2 || fetched_value[13] != 13)
124 abort ();
126 fetched_value = foo3 (&x);
127 if (fetched_value[3] != 3 || fetched_value[12] != 12)
128 abort ();
130 struct bar a_struct;
131 a_struct.a_vector = x; /* Remove 2 redundant swaps. */
132 fetched_value = foo4 (&a_struct);
133 if (fetched_value[4] != 4 || fetched_value[11] != 11)
134 abort ();
136 for (int i = 0; i < 16; i++)
137 z[i] = 15 - i;
139 baz (z);
140 if (x[0] != 15 || x[15] != 0)
141 abort ();
143 vector char source = { 8, 7, 6, 5, 4, 3, 2, 1,
144 0, 9, 10, 11, 12, 13, 14, 15 };
146 baz1 (source);
147 if (x[3] != 5 || x[8] != 0)
148 abort ();
150 vector char dest;
151 baz2 (&dest, source);
152 if (dest[4] != 4 || dest[1] != 7)
153 abort ();
155 baz3 (&a_struct, source);
156 if (a_struct.a_vector[7] != 1 || a_struct.a_vector[15] != 15)
157 abort ();
159 return 0;