1 /* { dg-do run { target { powerpc*-*-linux* } } } */
2 /* { dg-require-effective-target vsx_hw } */
3 /* { dg-options "-O2 -mvsx" } */
4
5 #include <stdlib.h>
6 #include <stddef.h>
7 #include <altivec.h>
8
9 #define ELEMENTS -1, 2, 0, -123456
10 #define SPLAT 0x01234567
11
12 vector int sv = (vector int) { ELEMENTS };
13 vector int splat = (vector int) { SPLAT, SPLAT, SPLAT, SPLAT };
14 vector int sv_global, sp_global;
15 static vector int sv_static, sp_static;
16 static const int expected[] = { ELEMENTS };
17
18 extern void check (vector int a)
19 __attribute__((__noinline__));
20
21 extern void check_splat (vector int a)
22 __attribute__((__noinline__));
23
24 extern vector int pack_reg (int a, int b, int c, int d)
25 __attribute__((__noinline__));
26
27 extern vector int pack_from_ptr (int *p_a, int *p_b, int *p_c, int *p_d)
28 __attribute__((__noinline__));
29
30 extern vector int pack_const (void)
31 __attribute__((__noinline__));
32
33 extern void pack_ptr (vector int *p, int a, int b, int c, int d)
34 __attribute__((__noinline__));
35
36 extern void pack_static (int a, int b, int c, int d)
37 __attribute__((__noinline__));
38
39 extern void pack_global (int a, int b, int c, int d)
40 __attribute__((__noinline__));
41
42 extern vector int splat_reg (int a)
43 __attribute__((__noinline__));
44
45 extern vector int splat_from_ptr (int *p)
46 __attribute__((__noinline__));
47
48 extern vector int splat_const (void)
49 __attribute__((__noinline__));
50
51 extern void splat_ptr (vector int *p, int a)
52 __attribute__((__noinline__));
53
54 extern void splat_static (int a)
55 __attribute__((__noinline__));
56
57 extern void splat_global (int a)
58 __attribute__((__noinline__));
59
60 void
check(vector int a)61 check (vector int a)
62 {
63 size_t i;
64
65 for (i = 0; i < 4; i++)
66 if (vec_extract (a, i) != expected[i])
67 abort ();
68 }
69
70 void
check_splat(vector int a)71 check_splat (vector int a)
72 {
73 size_t i;
74
75 for (i = 0; i < 4; i++)
76 if (vec_extract (a, i) != SPLAT)
77 abort ();
78 }
79
80 vector int
pack_reg(int a,int b,int c,int d)81 pack_reg (int a, int b, int c, int d)
82 {
83 return (vector int) { a, b, c, d };
84 }
85
86 vector int
pack_from_ptr(int * p_a,int * p_b,int * p_c,int * p_d)87 pack_from_ptr (int *p_a, int *p_b, int *p_c, int *p_d)
88 {
89 return (vector int) { *p_a, *p_b, *p_c, *p_d };
90 }
91
92 vector int
pack_const(void)93 pack_const (void)
94 {
95 return (vector int) { ELEMENTS };
96 }
97
98 void
pack_ptr(vector int * p,int a,int b,int c,int d)99 pack_ptr (vector int *p, int a, int b, int c, int d)
100 {
101 *p = (vector int) { a, b, c, d };
102 }
103
104 void
pack_static(int a,int b,int c,int d)105 pack_static (int a, int b, int c, int d)
106 {
107 sv_static = (vector int) { a, b, c, d };
108 }
109
110 void
pack_global(int a,int b,int c,int d)111 pack_global (int a, int b, int c, int d)
112 {
113 sv_global = (vector int) { a, b, c, d };
114 }
115
116 vector int
splat_reg(int a)117 splat_reg (int a)
118 {
119 return (vector int) { a, a, a, a };
120 }
121
122 vector int
splat_from_ptr(int * p)123 splat_from_ptr (int *p)
124 {
125 return (vector int) { *p, *p, *p, *p };
126 }
127
128 vector int
splat_const(void)129 splat_const (void)
130 {
131 return (vector int) { SPLAT, SPLAT, SPLAT, SPLAT };
132 }
133
134 void
splat_ptr(vector int * p,int a)135 splat_ptr (vector int *p, int a)
136 {
137 *p = (vector int) { a, a, a, a };
138 }
139
140 void
splat_static(int a)141 splat_static (int a)
142 {
143 sp_static = (vector int) { a, a, a, a };
144 }
145
146 void
splat_global(int a)147 splat_global (int a)
148 {
149 sp_global = (vector int) { a, a, a, a };
150 }
151
main(void)152 int main (void)
153 {
154 vector int sv2, sv3;
155 int mem = SPLAT;
156 int mem2[4] = { ELEMENTS };
157
158 check (sv);
159
160 check (pack_reg (ELEMENTS));
161
162 check (pack_from_ptr (&mem2[0], &mem2[1], &mem2[2], &mem2[3]));
163
164 check (pack_const ());
165
166 pack_ptr (&sv2, ELEMENTS);
167 check (sv2);
168
169 pack_static (ELEMENTS);
170 check (sv_static);
171
172 pack_global (ELEMENTS);
173 check (sv_global);
174
175 check_splat (splat);
176
177 check_splat (splat_reg (SPLAT));
178
179 check_splat (splat_from_ptr (&mem));
180
181 check_splat (splat_const ());
182
183 splat_ptr (&sv2, SPLAT);
184 check_splat (sv2);
185
186 splat_static (SPLAT);
187 check_splat (sp_static);
188
189 splat_global (SPLAT);
190 check_splat (sp_global);
191
192 return 0;
193 }
194