[testsuite] require sqrt_insn effective target where needed
[official-gcc.git] / gcc / testsuite / gcc.target / powerpc / swaps-p8-42.c
blob5c0b29ccbfbc6c17e63d5d6e8c60ecf2e51ad650
1 /* { dg-do compile } */
2 /* { dg-require-effective-target powerpc_vsx_ok } */
3 /* { dg-options "-mdejagnu-cpu=power8 -mvsx -O3 " } */
5 /* Previous versions of this test required that the assembler does not
6 contain xxpermdi or xxswapd. However, with the more sophisticated
7 code generation used today, it is now possible that xxpermdi (aka
8 xxswapd) show up without being part of a lxvd2x or stxvd2x
9 sequence. */
11 #include <altivec.h>
13 extern void abort (void);
15 vector long long x;
16 const vector long long y = { 1024, 2048 };
17 vector long long z;
19 vector long long
20 foo (void)
22 return y; /* Remove 1 swap and use lvx. */
25 vector long long
26 foo1 (void)
28 x = y; /* Remove 2 redundant swaps here. */
29 return x; /* Remove 1 swap and use lvx. */
32 void __attribute__ ((noinline))
33 fill_local (vector long long *vp)
35 *vp = x; /* Remove 2 redundant swaps here. */
38 /* Test aligned load from local. */
39 vector long long
40 foo2 (void)
42 vector long long v;
44 /* Need to be clever here because v will normally reside in a
45 register rather than memory. */
46 fill_local (&v);
47 return v; /* Remove 1 swap and use lvx. */
51 /* Test aligned load from pointer. */
52 vector long long
53 foo3 (vector long long *arg)
55 return *arg; /* Remove 1 swap and use lvx. */
58 /* In this structure, the compiler should insert padding to assure
59 that a_vector is properly aligned. */
60 struct bar {
61 short a_field;
62 vector long long a_vector;
65 vector long long
66 foo4 (struct bar *bp)
68 return bp->a_vector; /* Remove 1 swap and use lvx. */
71 /* Test aligned store to global. */
72 void
73 baz (vector long long arg)
75 x = arg; /* Remove 1 swap and use stvx. */
78 void __attribute__ ((noinline))
79 copy_local (vector long long *arg)
81 x = *arg; /* Remove 2 redundant swaps. */
85 /* Test aligned store to local. */
86 void
87 baz1 (vector long long arg)
89 vector long long v;
91 /* Need cleverness, because v will normally reside in a register
92 rather than memory. */
93 v = arg; /* Aligned store to local: remove 1
94 swap and use stvx. */
95 copy_local (&v);
98 /* Test aligned store to pointer. */
99 void
100 baz2 (vector long long *arg1, vector long long arg2)
102 /* Assume arg2 resides in register. */
103 *arg1 = arg2; /* Remove 1 swap and use stvx. */
106 void
107 baz3 (struct bar *bp, vector long long v)
109 /* Assume v resides in register. */
110 bp->a_vector = v; /* Remove 1 swap and use stvx. */
114 main (long long argc, long long *argv[])
116 vector long long fetched_value = foo ();
117 if (fetched_value[0] != 1024 || fetched_value[1] != 2048)
118 abort ();
120 fetched_value = foo1 ();
121 if (fetched_value[1] != 2048 || fetched_value[0] != 1024)
122 abort ();
124 fetched_value = foo2 ();
125 if (fetched_value[0] != 1024 || fetched_value[1] != 2048)
126 abort ();
128 fetched_value = foo3 (&x);
129 if (fetched_value[1] != 2048 || fetched_value[0] != 1024)
130 abort ();
132 struct bar a_struct;
133 a_struct.a_vector = x; /* Remove 2 redundant swaps. */
134 fetched_value = foo4 (&a_struct);
135 if (fetched_value[1] != 2048 || fetched_value[0] != 1024)
136 abort ();
138 z[0] = 7096;
139 z[1] = 6048;
141 baz (z);
142 if (x[0] != 7096 || x[1] != 6048)
143 abort ();
145 vector long long source = { 8192, 7096};
147 baz1 (source);
148 if (x[0] != 8192 || x[1] != 7096)
149 abort ();
151 vector long long dest;
152 baz2 (&dest, source);
153 if (dest[0] != 8192 || dest[1] != 7096)
154 abort ();
156 baz3 (&a_struct, source);
157 if (a_struct.a_vector[1] != 7096 || a_struct.a_vector[0] != 8192)
158 abort ();
160 return 0;