* gcc.target/powerpc/builtins-1-be.c <vclzb>: Rename duplicate test
[official-gcc.git] / gcc / testsuite / gcc.target / powerpc / swaps-p8-45.c
blob3e8c7e7756774321f583d424f6bacc0d06400aa0
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 vector double x;
17 const vector double y = { 0.1, 0.2 };
18 vector double z;
20 vector double
21 foo (void)
23 return y; /* Remove 1 swap and use lvx. */
26 vector double
27 foo1 (void)
29 x = y; /* Remove 2 redundant swaps here. */
30 return x; /* Remove 1 swap and use lvx. */
33 void __attribute__ ((noinline))
34 fill_local (vector double *vp)
36 *vp = x; /* Remove 2 redundant swaps here. */
39 /* Test aligned load from local. */
40 vector double
41 foo2 (void)
43 vector double v;
45 /* Need to be clever here because v will normally reside in a
46 register rather than memory. */
47 fill_local (&v);
48 return v; /* Remove 1 swap and use lvx. */
52 /* Test aligned load from pointer. */
53 vector double
54 foo3 (vector double *arg)
56 return *arg; /* Remove 1 swap and use lvx. */
59 /* In this structure, the compiler should insert padding to assure
60 that a_vector is properly aligned. */
61 struct bar {
62 short a_field;
63 vector double a_vector;
66 vector double
67 foo4 (struct bar *bp)
69 return bp->a_vector; /* Remove 1 swap and use lvx. */
72 /* Test aligned store to global. */
73 void
74 baz (vector double arg)
76 x = arg; /* Remove 1 swap and use stvx. */
79 void __attribute__ ((noinline))
80 copy_local (vector double *arg)
82 x = *arg; /* Remove 2 redundant swaps. */
86 /* Test aligned store to local. */
87 void
88 baz1 (vector double arg)
90 vector double v;
92 /* Need cleverness, because v will normally reside in a register
93 rather than memory. */
94 v = arg; /* Aligned store to local: remove 1
95 swap and use stvx. */
96 copy_local (&v);
99 /* Test aligned store to pointer. */
100 void
101 baz2 (vector double *arg1, vector double arg2)
103 /* Assume arg2 resides in register. */
104 *arg1 = arg2; /* Remove 1 swap and use stvx. */
107 void
108 baz3 (struct bar *bp, vector double v)
110 /* Assume v resides in register. */
111 bp->a_vector = v; /* Remove 1 swap and use stvx. */
115 main (double argc, double *argv[])
117 vector double fetched_value = foo ();
118 if (fetched_value[0] != 0.1 || fetched_value[1] != 0.2)
119 abort ();
121 fetched_value = foo1 ();
122 if (fetched_value[1] != 0.2 || fetched_value[0] != 0.1)
123 abort ();
125 fetched_value = foo2 ();
126 if (fetched_value[0] != 0.1 || fetched_value[1] != 0.2)
127 abort ();
129 fetched_value = foo3 (&x);
130 if (fetched_value[1] != 0.2 || fetched_value[0] != 0.1)
131 abort ();
133 struct bar a_struct;
134 a_struct.a_vector = x; /* Remove 2 redundant swaps. */
135 fetched_value = foo4 (&a_struct);
136 if (fetched_value[1] != 0.2 || fetched_value[0] != 0.1)
137 abort ();
139 z[0] = 0.7;
140 z[1] = 0.6;
142 baz (z);
143 if (x[0] != 0.7 || x[1] != 0.6)
144 abort ();
146 vector double source = { 0.8, 0.7 };
148 baz1 (source);
149 if (x[0] != 0.8 || x[1] != 0.7)
150 abort ();
152 vector double dest;
153 baz2 (&dest, source);
154 if (dest[0] != 0.8 || dest[1] != 0.7)
155 abort ();
157 baz3 (&a_struct, source);
158 if (a_struct.a_vector[1] != 0.7 || a_struct.a_vector[0] != 0.8)
159 abort ();
161 return 0;