[testsuite] require sqrt_insn effective target where needed
[official-gcc.git] / gcc / testsuite / gcc.target / powerpc / swaps-p8-32.c
blobcafb5d4c39ca27ae48ac79483b7c820546203156
1 /* { dg-do run } */
2 /* { dg-require-effective-target p8vector_hw } */
3 /* { dg-options "-mdejagnu-cpu=power8 -O3 " } */
5 #include <altivec.h>
7 extern void abort (void);
9 vector short x;
10 const vector short y = { 0, 1, 2, 3, 4, 5, 6, 7 };
11 vector short z;
13 vector short
14 foo (void)
16 return y; /* Remove 1 swap and use lvx. */
19 vector short
20 foo1 (void)
22 x = y; /* Remove 2 redundant swaps here. */
23 return x; /* Remove 1 swap and use lvx. */
26 void __attribute__ ((noinline))
27 fill_local (vector short *vp)
29 *vp = x; /* Remove 2 redundant swaps here. */
32 /* Test aligned load from local. */
33 vector short
34 foo2 (void)
36 vector short v;
38 /* Need to be clever here because v will normally reside in a
39 register rather than memory. */
40 fill_local (&v);
41 return v; /* Remove 1 swap and use lvx. */
45 /* Test aligned load from pointer. */
46 vector short
47 foo3 (vector short *arg)
49 return *arg; /* Remove 1 swap and use lvx. */
52 /* In this structure, the compiler should insert padding to assure
53 that a_vector is properly aligned. */
54 struct bar {
55 short a_field;
56 vector short a_vector;
59 vector short
60 foo4 (struct bar *bp)
62 return bp->a_vector; /* Remove 1 swap and use lvx. */
65 /* Test aligned store to global. */
66 void
67 baz (vector short arg)
69 x = arg; /* Remove 1 swap and use stvx. */
72 void __attribute__ ((noinline))
73 copy_local (vector short *arg)
75 x = *arg; /* Remove 2 redundant swaps. */
79 /* Test aligned store to local. */
80 void
81 baz1 (vector short arg)
83 vector short v;
85 /* Need cleverness, because v will normally reside in a register
86 rather than memory. */
87 v = arg; /* Aligned store to local: remove 1
88 swap and use stvx. */
89 copy_local (&v);
92 /* Test aligned store to pointer. */
93 void
94 baz2 (vector short *arg1, vector short arg2)
96 /* Assume arg2 resides in register. */
97 *arg1 = arg2; /* Remove 1 swap and use stvx. */
100 void
101 baz3 (struct bar *bp, vector short v)
103 /* Assume v resides in register. */
104 bp->a_vector = v; /* Remove 1 swap and use stvx. */
108 main (int argc, short *argv[])
110 vector short fetched_value = foo ();
111 if (fetched_value[0] != 0 || fetched_value[7] != 7)
112 abort ();
114 fetched_value = foo1 ();
115 if (fetched_value[1] != 1 || fetched_value[6] != 6)
116 abort ();
118 fetched_value = foo2 ();
119 if (fetched_value[2] != 2 || fetched_value[5] != 5)
120 abort ();
122 fetched_value = foo3 (&x);
123 if (fetched_value[3] != 3 || fetched_value[4] != 4)
124 abort ();
126 struct bar a_struct;
127 a_struct.a_vector = x; /* Remove 2 redundant swaps. */
128 fetched_value = foo4 (&a_struct);
129 if (fetched_value[4] != 4 || fetched_value[3] != 3)
130 abort ();
132 for (int i = 0; i < 8; i++)
133 z[i] = 7 - i;
135 baz (z);
136 if (x[0] != 7 || x[7] != 0)
137 abort ();
139 vector short source = { 8, 7, 6, 5, 4, 3, 2, 1 };
141 baz1 (source);
142 if (x[3] != 5 || x[7] != 1)
143 abort ();
145 vector short dest;
146 baz2 (&dest, source);
147 if (dest[4] != 4 || dest[1] != 7)
148 abort ();
150 baz3 (&a_struct, source);
151 if (a_struct.a_vector[7] != 1 || a_struct.a_vector[5] != 3)
152 abort ();
154 return 0;