* gcc.target/powerpc/builtins-1-be.c <vclzb>: Rename duplicate test
[official-gcc.git] / gcc / testsuite / gcc.target / powerpc / swaps-p8-30.c
blobeddecf570c871af890a2ae05665c7e4a84008bba
1 /* { dg-do compile { target { powerpc64le-*-* } } } */
2 /* { dg-require-effective-target powerpc_p8vector_ok } */
3 /* { dg-skip-if "do not override -mcpu" { powerpc*-*-* } { "-mcpu=*" } { "-mcpu=power8" } } */
4 /* { dg-options "-mcpu=power8 -O3 " } */
6 /* Previous versions of this test required that the assembler does not
7 contain xxpermdi or xxswapd. However, with the more sophisticated
8 code generation used today, it is now possible that xxpermdi (aka
9 xxswapd) show up without being part of a lxvd2x or stxvd2x
10 sequence. */
12 #include <altivec.h>
14 extern void abort (void);
16 const vector char y = { 0, 1, 2, 3,
17 4, 5, 6, 7,
18 8, 9, 10, 11,
19 12, 13, 14, 15 };
21 vector char x, z;
23 vector char
24 foo (void)
26 return y; /* Remove 1 swap and use lvx. */
29 vector char
30 foo1 (void)
32 x = y; /* Remove 2 redundant swaps here. */
33 return x; /* Remove 1 swap and use lvx. */
36 void __attribute__ ((noinline))
37 fill_local (vector char *vp)
39 *vp = x; /* Remove 2 redundant swaps here. */
42 /* Test aligned load from local. */
43 vector char
44 foo2 (void)
46 vector char v;
48 /* Need to be clever here because v will normally reside in a
49 register rather than memory. */
50 fill_local (&v);
51 return v; /* Remove 1 swap and use lvx. */
55 /* Test aligned load from pointer. */
56 vector char
57 foo3 (vector char *arg)
59 return *arg; /* Remove 1 swap and use lvx. */
62 /* In this structure, the compiler should insert padding to assure
63 that a_vector is properly aligned. */
64 struct bar {
65 char a_field;
66 vector char a_vector;
69 vector char
70 foo4 (struct bar *bp)
72 return bp->a_vector; /* Remove 1 swap and use lvx. */
75 /* Test aligned store to global. */
76 void
77 baz (vector char arg)
79 x = arg; /* Remove 1 swap and use stvx. */
82 void __attribute__ ((noinline))
83 copy_local (vector char *arg)
85 x = *arg; /* Remove 2 redundant swaps. */
89 /* Test aligned store to local. */
90 void
91 baz1 (vector char arg)
93 vector char v;
95 /* Need cleverness, because v will normally reside in a register
96 rather than memory. */
97 v = arg; /* Aligned store to local: remove 1
98 swap and use stvx. */
99 copy_local (&v);
102 /* Test aligned store to pointer. */
103 void
104 baz2 (vector char *arg1, vector char arg2)
106 /* Assume arg2 resides in register. */
107 *arg1 = arg2; /* Remove 1 swap and use stvx. */
110 void
111 baz3 (struct bar *bp, vector char v)
113 /* Assume v resides in register. */
114 bp->a_vector = v; /* Remove 1 swap and use stvx. */
118 main (int argc, char *argv[])
120 vector char fetched_value = foo ();
121 if (fetched_value[0] != 0 || fetched_value[15] != 15)
122 abort ();
124 fetched_value = foo1 ();
125 if (fetched_value[1] != 1 || fetched_value[14] != 14)
126 abort ();
128 fetched_value = foo2 ();
129 if (fetched_value[2] != 2 || fetched_value[13] != 13)
130 abort ();
132 fetched_value = foo3 (&x);
133 if (fetched_value[3] != 3 || fetched_value[12] != 12)
134 abort ();
136 struct bar a_struct;
137 a_struct.a_vector = x; /* Remove 2 redundant swaps. */
138 fetched_value = foo4 (&a_struct);
139 if (fetched_value[4] != 4 || fetched_value[11] != 11)
140 abort ();
142 for (int i = 0; i < 16; i++)
143 z[i] = 15 - i;
145 baz (z);
146 if (x[0] != 15 || x[15] != 0)
147 abort ();
149 vector char source = { 8, 7, 6, 5, 4, 3, 2, 1,
150 0, 9, 10, 11, 12, 13, 14, 15 };
152 baz1 (source);
153 if (x[3] != 5 || x[8] != 0)
154 abort ();
156 vector char dest;
157 baz2 (&dest, source);
158 if (dest[4] != 4 || dest[1] != 7)
159 abort ();
161 baz3 (&a_struct, source);
162 if (a_struct.a_vector[7] != 1 || a_struct.a_vector[15] != 15)
163 abort ();
165 return 0;