2017-08-28 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / gcc.target / powerpc / vec-init-4.c
blob5e724c8b0df2cc363cd7883bdf98cbad3e8cb699
1 /* { dg-do run { target { powerpc*-*-linux* } } } */
2 /* { dg-require-effective-target vsx_hw } */
3 /* { dg-options "-O2 -mvsx" } */
5 #include <stdlib.h>
6 #include <stddef.h>
7 #include <altivec.h>
9 #define ELEMENTS -1, 2, 0, -32768, 32767, 53, 1, 16000
10 #define SPLAT 0x0123
12 vector short sv = (vector short) { ELEMENTS };
13 vector short splat = (vector short) { SPLAT, SPLAT, SPLAT, SPLAT,
14 SPLAT, SPLAT, SPLAT, SPLAT };
15 vector short sv_global, sp_global;
16 static vector short sv_static, sp_static;
17 static short expected[] = { ELEMENTS };
18 static short splat_expected = SPLAT;
20 extern void check (vector short a)
21 __attribute__((__noinline__));
23 extern void check_splat (vector short a)
24 __attribute__((__noinline__));
26 extern vector short pack_reg (short a, short b, short c, short d,
27 short e, short f, short g, short h)
28 __attribute__((__noinline__));
30 extern vector short pack_from_ptr (short *p_a, short *p_b,
31 short *p_c, short *p_d,
32 short *p_e, short *p_f,
33 short *p_g, short *p_h)
34 __attribute__((__noinline__));
36 extern vector short pack_const (void)
37 __attribute__((__noinline__));
39 extern void pack_ptr (vector short *p,
40 short a, short b, short c, short d,
41 short e, short f, short g, short h)
42 __attribute__((__noinline__));
44 extern void pack_static (short a, short b, short c, short d,
45 short e, short f, short g, short h)
46 __attribute__((__noinline__));
48 extern void pack_global (short a, short b, short c, short d,
49 short e, short f, short g, short h)
50 __attribute__((__noinline__));
52 extern vector short splat_reg (short a)
53 __attribute__((__noinline__));
55 extern vector short splat_from_ptr (short *p_a)
56 __attribute__((__noinline__));
58 extern vector short splat_const (void)
59 __attribute__((__noinline__));
61 extern void splat_ptr (vector short *p, short a)
62 __attribute__((__noinline__));
64 extern void splat_static (short a)
65 __attribute__((__noinline__));
67 extern void splat_global (short a)
68 __attribute__((__noinline__));
70 void
71 check (vector short a)
73 size_t i;
75 for (i = 0; i < 8; i++)
76 if (vec_extract (a, i) != expected[i])
77 abort ();
80 void
81 check_splat (vector short a)
83 size_t i;
85 for (i = 0; i < 8; i++)
86 if (vec_extract (a, i) != SPLAT)
87 abort ();
90 vector short
91 pack_reg (short a, short b, short c, short d,
92 short e, short f, short g, short h)
94 return (vector short) { a, b, c, d, e, f, g, h };
97 vector short
98 pack_from_ptr (short *p_a, short *p_b, short *p_c, short *p_d,
99 short *p_e, short *p_f, short *p_g, short *p_h)
101 return (vector short) { *p_a, *p_b, *p_c, *p_d,
102 *p_e, *p_f, *p_g, *p_h };
105 vector short
106 pack_const (void)
108 return (vector short) { ELEMENTS };
111 void
112 pack_ptr (vector short *p,
113 short a, short b, short c, short d,
114 short e, short f, short g, short h)
116 *p = (vector short) { a, b, c, d, e, f, g, h };
119 void
120 pack_static (short a, short b, short c, short d,
121 short e, short f, short g, short h)
123 sv_static = (vector short) { a, b, c, d, e, f, g, h };
126 void
127 pack_global (short a, short b, short c, short d,
128 short e, short f, short g, short h)
130 sv_global = (vector short) { a, b, c, d, e, f, g, h };
133 vector short
134 splat_reg (short a)
136 return (vector short) { a, a, a, a, a, a, a, a };
139 vector short
140 splat_from_ptr (short *p_a)
142 return (vector short) { *p_a, *p_a, *p_a, *p_a,
143 *p_a, *p_a, *p_a, *p_a };
146 vector short
147 splat_const (void)
149 return (vector short) { SPLAT, SPLAT, SPLAT, SPLAT,
150 SPLAT, SPLAT, SPLAT, SPLAT };
153 void
154 splat_ptr (vector short *p, short a)
156 *p = (vector short) { a, a, a, a, a, a, a, a };
159 void
160 splat_static (short a)
162 sp_static = (vector short) { a, a, a, a, a, a, a, a };
165 void
166 splat_global (short a)
168 sp_global = (vector short) { a, a, a, a, a, a, a, a };
171 int main (void)
173 vector short sv2, sv3;
175 check (sv);
177 check (pack_reg (ELEMENTS));
179 check (pack_from_ptr (&expected[0], &expected[1], &expected[2],
180 &expected[3], &expected[4], &expected[5],
181 &expected[6], &expected[7]));
183 check (pack_const ());
185 pack_ptr (&sv2, ELEMENTS);
186 check (sv2);
188 pack_static (ELEMENTS);
189 check (sv_static);
191 pack_global (ELEMENTS);
192 check (sv_global);
194 check_splat (splat);
196 check_splat (splat_reg (SPLAT));
198 check_splat (splat_from_ptr (&splat_expected));
200 check_splat (splat_const ());
202 splat_ptr (&sv2, SPLAT);
203 check_splat (sv2);
205 splat_static (SPLAT);
206 check_splat (sp_static);
208 splat_global (SPLAT);
209 check_splat (sp_global);
211 return 0;