* gcc.target/powerpc/builtins-1-be.c <vclzb>: Rename duplicate test
[official-gcc.git] / gcc / testsuite / gcc.target / powerpc / swaps-p8-40.c
blob50610d9ab81d4b56f8b1866543af8c42de2de2ed
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 vector long long x;
11 vector long long y = { 1024, 2048 };
12 vector long long z;
14 vector long long
15 foo (void)
17 return y; /* Remove 1 swap and use lvx. */
20 vector long long
21 foo1 (void)
23 x = y; /* Remove 2 redundant swaps here. */
24 return x; /* Remove 1 swap and use lvx. */
27 void __attribute__ ((noinline))
28 fill_local (vector long long *vp)
30 *vp = x; /* Remove 2 redundant swaps here. */
33 /* Test aligned load from local. */
34 vector long long
35 foo2 (void)
37 vector long long v;
39 /* Need to be clever here because v will normally reside in a
40 register rather than memory. */
41 fill_local (&v);
42 return v; /* Remove 1 swap and use lvx. */
46 /* Test aligned load from pointer. */
47 vector long long
48 foo3 (vector long long *arg)
50 return *arg; /* Remove 1 swap and use lvx. */
53 /* In this structure, the compiler should insert padding to assure
54 that a_vector is properly aligned. */
55 struct bar {
56 short a_field;
57 vector long long a_vector;
60 vector long long
61 foo4 (struct bar *bp)
63 return bp->a_vector; /* Remove 1 swap and use lvx. */
66 /* Test aligned store to global. */
67 void
68 baz (vector long long arg)
70 x = arg; /* Remove 1 swap and use stvx. */
73 void __attribute__ ((noinline))
74 copy_local (vector long long *arg)
76 x = *arg; /* Remove 2 redundant swaps. */
80 /* Test aligned store to local. */
81 void
82 baz1 (vector long long arg)
84 vector long long v;
86 /* Need cleverness, because v will normally reside in a register
87 rather than memory. */
88 v = arg; /* Aligned store to local: remove 1
89 swap and use stvx. */
90 copy_local (&v);
93 /* Test aligned store to pointer. */
94 void
95 baz2 (vector long long *arg1, vector long long arg2)
97 /* Assume arg2 resides in register. */
98 *arg1 = arg2; /* Remove 1 swap and use stvx. */
101 void
102 baz3 (struct bar *bp, vector long long v)
104 /* Assume v resides in register. */
105 bp->a_vector = v; /* Remove 1 swap and use stvx. */
109 main (long long argc, long long *argv[])
111 vector long long fetched_value = foo ();
112 if (fetched_value[0] != 1024 || fetched_value[1] != 2048)
113 abort ();
115 fetched_value = foo1 ();
116 if (fetched_value[1] != 2048 || fetched_value[0] != 1024)
117 abort ();
119 fetched_value = foo2 ();
120 if (fetched_value[0] != 1024 || fetched_value[1] != 2048)
121 abort ();
123 fetched_value = foo3 (&x);
124 if (fetched_value[1] != 2048 || fetched_value[0] != 1024)
125 abort ();
127 struct bar a_struct;
128 a_struct.a_vector = x; /* Remove 2 redundant swaps. */
129 fetched_value = foo4 (&a_struct);
130 if (fetched_value[1] != 2048 || fetched_value[0] != 1024)
131 abort ();
133 z[0] = 7096;
134 z[1] = 6048;
136 baz (z);
137 if (x[0] != 7096 || x[1] != 6048)
138 abort ();
140 vector long long source = { 8192, 7096};
142 baz1 (source);
143 if (x[0] != 8192 || x[1] != 7096)
144 abort ();
146 vector long long dest;
147 baz2 (&dest, source);
148 if (dest[0] != 8192 || dest[1] != 7096)
149 abort ();
151 baz3 (&a_struct, source);
152 if (a_struct.a_vector[1] != 7096 || a_struct.a_vector[0] != 8192)
153 abort ();
155 return 0;