* gcc.target/powerpc/builtins-1-be.c <vclzb>: Rename duplicate test
[official-gcc.git] / gcc / testsuite / gcc.target / powerpc / swaps-p8-37.c
blob775d37fe6f609b6eacbab3d42d54645b3069fa56
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 float x;
11 vector float y = { 0.0F, 0.1F, 0.2F, 0.3F };
12 vector float z;
14 vector float
15 foo (void)
17 return y; /* Remove 1 swap and use lvx. */
20 vector float
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 float *vp)
30 *vp = x; /* Remove 2 redundant swaps here. */
33 /* Test aligned load from local. */
34 vector float
35 foo2 (void)
37 vector float 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 float
48 foo3 (vector float *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 float a_vector;
60 vector float
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 float arg)
70 x = arg; /* Remove 1 swap and use stvx. */
73 void __attribute__ ((noinline))
74 copy_local (vector float *arg)
76 x = *arg; /* Remove 2 redundant swaps. */
80 /* Test aligned store to local. */
81 void
82 baz1 (vector float arg)
84 vector float 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 float *arg1, vector float arg2)
97 /* Assume arg2 resides in register. */
98 *arg1 = arg2; /* Remove 1 swap and use stvx. */
101 void
102 baz3 (struct bar *bp, vector float v)
104 /* Assume v resides in register. */
105 bp->a_vector = v; /* Remove 1 swap and use stvx. */
109 main (float argc, float *argv[])
111 vector float fetched_value = foo ();
112 if (fetched_value[0] != 0.0F || fetched_value[3] != 0.3F)
113 abort ();
115 fetched_value = foo1 ();
116 if (fetched_value[1] != 0.1F || fetched_value[2] != 0.2F)
117 abort ();
119 fetched_value = foo2 ();
120 if (fetched_value[2] != 0.2F || fetched_value[1] != 0.1F)
121 abort ();
123 fetched_value = foo3 (&x);
124 if (fetched_value[3] != 0.3F || fetched_value[0] != 0.0F)
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[2] != 0.2F || fetched_value[3] != 0.3F)
131 abort ();
133 z[0] = 0.7F;
134 z[1] = 0.6F;
135 z[2] = 0.5F;
136 z[3] = 0.4F;
138 baz (z);
139 if (x[0] != 0.7F || x[3] != 0.4F)
140 abort ();
142 vector float source = { 0.8F, 0.7F, 0.6F, 0.5F };
144 baz1 (source);
145 if (x[2] != 0.6F || x[1] != 0.7F)
146 abort ();
148 vector float dest;
149 baz2 (&dest, source);
150 if (dest[0] != 0.8F || dest[1] != 0.7F)
151 abort ();
153 baz3 (&a_struct, source);
154 if (a_struct.a_vector[3] != 0.5F || a_struct.a_vector[0] != 0.8F)
155 abort ();
157 return 0;