[testsuite] require sqrt_insn effective target where needed
[official-gcc.git] / gcc / testsuite / gcc.target / powerpc / builtins-3-runnable.c
blob0231a1fd086b96ffbf9dcd55a7fa85d859b8ae08
1 /* { dg-do run { target { vsx_hw } } } */
2 /* { dg-require-effective-target vsx_hw } */
3 /* { dg-options "-maltivec -mvsx" } */
5 #include <altivec.h> // vector
7 #ifdef DEBUG
8 #include <stdio.h>
9 #endif
11 #define ALL 1
12 #define EVEN 2
13 #define ODD 3
15 void abort (void);
17 void test_int_result(int check, vector int vec_result, vector int vec_expected)
19 int i;
21 for (i = 0; i < 4; i++) {
22 switch (check) {
23 case ALL:
24 break;
25 case EVEN:
26 if (i%2 == 0)
27 break;
28 else
29 continue;
30 case ODD:
31 if (i%2 != 0)
32 break;
33 else
34 continue;
37 if (vec_result[i] != vec_expected[i]) {
38 #ifdef DEBUG
39 printf("Test_int_result: ");
40 printf("vec_result[%d] (%d) != vec_expected[%d] (%d)\n",
41 i, vec_result[i], i, vec_expected[i]);
42 #else
43 abort();
44 #endif
49 void test_unsigned_int_result(int check, vector unsigned int vec_result,
50 vector unsigned int vec_expected)
52 int i;
54 for (i = 0; i < 4; i++) {
55 switch (check) {
56 case ALL:
57 break;
58 case EVEN:
59 if (i%2 == 0)
60 break;
61 else
62 continue;
63 case ODD:
64 if (i%2 != 0)
65 break;
66 else
67 continue;
70 if (vec_result[i] != vec_expected[i]) {
71 #ifdef DEBUG
72 printf("Test_unsigned int_result: ");
73 printf("vec_result[%d] (%d) != vec_expected[%d] (%d)\n",
74 i, vec_result[i], i, vec_expected[i]);
75 #else
76 abort();
77 #endif
83 void test_ll_int_result(vector long long int vec_result,
84 vector long long int vec_expected)
86 int i;
88 for (i = 0; i < 2; i++)
89 if (vec_result[i] != vec_expected[i]) {
90 #ifdef DEBUG
91 printf("Test_ll_int_result: ");
92 printf("vec_result[%d] (%lld) != vec_expected[%d] (%lld)\n",
93 i, vec_result[i], i, vec_expected[i]);
94 #else
95 abort();
96 #endif
100 void test_ll_unsigned_int_result(vector long long unsigned int vec_result,
101 vector long long unsigned int vec_expected)
103 int i;
105 for (i = 0; i < 2; i++)
106 if (vec_result[i] != vec_expected[i]) {
107 #ifdef DEBUG
108 printf("Test_ll_unsigned_int_result: ");
109 printf("vec_result[%d] (%lld) != vec_expected[%d] (%lld)\n",
110 i, vec_result[i], i, vec_expected[i]);
111 #else
112 abort();
113 #endif
117 void test_result_sp(int check, vector float vec_result,
118 vector float vec_expected)
120 int i;
121 for(i = 0; i<4; i++) {
123 switch (check) {
124 case ALL:
125 break;
126 case EVEN:
127 if (i%2 == 0)
128 break;
129 else
130 continue;
131 case ODD:
132 if (i%2 != 0)
133 break;
134 else
135 continue;
138 if (vec_result[i] != vec_expected[i]) {
139 #ifdef DEBUG
140 printf("Test_result_sp: ");
141 printf("vec_result[%d] (%f) != vec_expected[%d] (%f)\n",
142 i, vec_result[i], i, vec_expected[i]);
143 #else
144 abort();
145 #endif
150 void test_result_dp(vector double vec_result, vector double vec_expected)
152 if (vec_result[0] != vec_expected[0]) {
153 #ifdef DEBUG
154 printf("Test_result_dp: ");
155 printf("vec_result[0] (%f) != vec_expected[0] (%f)\n",
156 vec_result[0], vec_expected[0]);
157 #else
158 abort();
159 #endif
162 if (vec_result[1] != vec_expected[1]) {
163 #ifdef DEBUG
164 printf("Test_result_dp: ");
165 printf("vec_result[1] (%lld) != vec_expected[1] (%lld)\n",
166 vec_result[1], vec_expected[1]);
167 #else
168 abort();
169 #endif
173 int main()
175 int i;
176 vector unsigned int vec_unint, vec_uns_int_expected, vec_uns_int_result;
177 vector signed int vec_int, vec_int_expected, vec_int_result;
178 vector long long int vec_ll_int0, vec_ll_int1;
179 vector long long int vec_ll_int_expected, vec_ll_int_result;
180 vector long long unsigned int vec_ll_uns_int0, vec_ll_uns_int1;
181 vector long long unsigned int vec_ll_uns_int_expected, vec_ll_uns_int_result;
182 vector float vec_flt0, vec_flt1, vec_flt_result, vec_flt_expected;
183 vector double vec_dble0, vec_dble1, vec_dble_result, vec_dble_expected;
185 vec_int = (vector signed int){ -1, 3, -5, 1234567 };
186 vec_ll_int0 = (vector long long int){ -12, -12345678901234 };
187 vec_ll_int1 = (vector long long int){ 12, 9876543210 };
188 vec_unint = (vector unsigned int){ 9, 11, 15, 2468013579 };
189 vec_ll_uns_int0 = (vector unsigned long long int){ 102, 9753108642 };
190 vec_ll_uns_int1 = (vector unsigned long long int){ 23, 29 };
191 vec_flt0 = (vector float){ -21., 3.5, -53., 78. };
192 vec_dble0 = (vector double){ 34.0, 97.0 };
193 vec_dble1 = (vector double){ 214.0, -5.5 };
195 /* conversion of words 0 and 2 */
196 vec_dble_expected = (vector double){-1.000000, -5.000000};
197 vec_dble_result = vec_doublee (vec_int);
198 test_result_dp(vec_dble_result, vec_dble_expected);
200 vec_dble_expected = (vector double){9.000000, 15.000000};
201 vec_dble_result = vec_doublee (vec_unint);
202 test_result_dp(vec_dble_result, vec_dble_expected);
204 vec_dble_expected = (vector double){-21.000000, -53.000000};
205 vec_dble_result = vec_doublee (vec_flt0);
206 test_result_dp(vec_dble_result, vec_dble_expected);
209 /* conversion of words 1 and 3 */
210 vec_dble_expected = (vector double){3.000000, 1234567.000000};
211 vec_dble_result = vec_doubleo (vec_int);
212 test_result_dp(vec_dble_result, vec_dble_expected);
214 vec_dble_expected = (vector double){11.000000, 2468013579.000000};
215 vec_dble_result = vec_doubleo (vec_unint);
216 test_result_dp(vec_dble_result, vec_dble_expected);
218 vec_dble_expected = (vector double){3.500000, 78.000000};
219 vec_dble_result = vec_doubleo (vec_flt0);
220 test_result_dp(vec_dble_result, vec_dble_expected);
223 /* conversion of words 0 and 1 */
224 vec_dble_expected = (vector double){-5.000000, 1234567.000000};
225 vec_dble_result = vec_doublel (vec_int);
226 test_result_dp(vec_dble_result, vec_dble_expected);
228 vec_dble_expected = (vector double){15.000000, 2468013579.000000};
229 vec_dble_result = vec_doublel (vec_unint);
230 test_result_dp(vec_dble_result, vec_dble_expected);
232 vec_dble_expected = (vector double){-53.000000, 78.000000};
233 vec_dble_result = vec_doublel (vec_flt0);
234 test_result_dp(vec_dble_result, vec_dble_expected);
237 /* conversion of words 2 and 3 */
238 vec_dble_expected = (vector double){-1.000000, 3.000000};
239 vec_dble_result = vec_doubleh (vec_int);
240 test_result_dp(vec_dble_result, vec_dble_expected);
242 vec_dble_expected = (vector double){9.000000, 11.000000};
243 vec_dble_result = vec_doubleh (vec_unint);
244 test_result_dp(vec_dble_result, vec_dble_expected);
246 vec_dble_expected = (vector double){-21.000000, 3.500000};
247 vec_dble_result = vec_doubleh (vec_flt0);
248 test_result_dp(vec_dble_result, vec_dble_expected);
250 /* conversion of integer vector to single precision float vector */
251 vec_flt_expected = (vector float){-1.00, 3.00, -5.00, 1234567.00};
252 vec_flt_result = vec_float (vec_int);
253 test_result_sp(ALL, vec_flt_result, vec_flt_expected);
255 vec_flt_expected = (vector float){9.00, 11.00, 15.00, 2468013579.0};
256 vec_flt_result = vec_float (vec_unint);
257 test_result_sp(ALL, vec_flt_result, vec_flt_expected);
259 /* conversion of even words in double precision vector to single precision vector */
260 vec_flt_expected = (vector float){-12.00, 00.00, -12345678901234.00, 0.00};
261 vec_flt_result = vec_floate (vec_ll_int0);
262 test_result_sp(EVEN, vec_flt_result, vec_flt_expected);
264 vec_flt_expected = (vector float){102.00, 0.00, 9753108642.00, 0.00};
265 vec_flt_result = vec_floate (vec_ll_uns_int0);
266 test_result_sp(EVEN, vec_flt_result, vec_flt_expected);
268 vec_flt_expected = (vector float){34.00, 0.00, 97.00, 0.00};
269 vec_flt_result = vec_floate (vec_dble0);
270 test_result_sp(EVEN, vec_flt_result, vec_flt_expected);
272 /* conversion of odd words in double precision vector to single precision vector */
273 vec_flt_expected = (vector float){0.00, -12.00, 00.00, -12345678901234.00};
274 vec_flt_result = vec_floato (vec_ll_int0);
275 test_result_sp(ODD, vec_flt_result, vec_flt_expected);
277 vec_flt_expected = (vector float){0.00, 102.00, 0.00, 9753108642.00};
278 vec_flt_result = vec_floato (vec_ll_uns_int0);
279 test_result_sp(ODD, vec_flt_result, vec_flt_expected);
281 vec_flt_expected = (vector float){0.00, 34.00, 0.00, 97.00};
282 vec_flt_result = vec_floato (vec_dble0);
283 test_result_sp(ODD, vec_flt_result, vec_flt_expected);
285 /* Convert single precision float to int */
286 vec_flt0 = (vector float){-14.30, 34.00, 22.00, 97.00};
287 vec_int_expected = (vector signed int){-14, 34, 22, 97};
288 vec_int_result = vec_signed (vec_flt0);
289 test_int_result (ALL, vec_int_result, vec_int_expected);
291 /* Convert double precision float to long long int */
292 vec_dble0 = (vector double){-124.930, 81234.49};
293 vec_ll_int_expected = (vector long long signed int){-124, 81234};
294 vec_ll_int_result = vec_signed (vec_dble0);
295 test_ll_int_result (vec_ll_int_result, vec_ll_int_expected);
297 /* Convert double precision vector float to vector int, even words */
298 vec_dble0 = (vector double){-124.930, 81234.49};
299 vec_int_expected = (vector signed int){-124, 0, 81234, 0};
300 vec_int_result = vec_signede (vec_dble0);
301 test_int_result (EVEN, vec_int_result, vec_int_expected);
303 /* Convert double precision vector float to vector int, odd words */
304 vec_dble0 = (vector double){-124.930, 81234.49};
305 vec_int_expected = (vector signed int){0, -124, 0, 81234};
306 vec_int_result = vec_signedo (vec_dble0);
307 test_int_result (ODD, vec_int_result, vec_int_expected);
309 /* Convert single precision float to unsigned int */
310 vec_flt0 = (vector float){124.930, 8134.49, 23.3, 45.4};
311 vec_uns_int_expected = (vector unsigned int){124, 8134, 23, 45};
312 vec_uns_int_result = vec_unsigned (vec_flt0);
313 test_unsigned_int_result (ALL, vec_uns_int_result,
314 vec_uns_int_expected);
316 /* Convert double precision float to long long unsigned int */
317 vec_dble0 = (vector double){124.930, 8134.49};
318 vec_ll_uns_int_expected = (vector long long unsigned int){124, 8134};
319 vec_ll_uns_int_result = vec_unsigned (vec_dble0);
320 test_ll_unsigned_int_result (vec_ll_uns_int_result,
321 vec_ll_uns_int_expected);
323 /* Convert double precision vector float to vector unsigned int,
324 even words */
325 vec_dble0 = (vector double){3124.930, 8234.49};
326 vec_uns_int_expected = (vector unsigned int){3124, 0, 8234, 0};
327 vec_uns_int_result = vec_unsignede (vec_dble0);
328 test_unsigned_int_result (EVEN, vec_uns_int_result,
329 vec_uns_int_expected);
331 /* Convert double precision vector float to vector unsigned int,
332 odd words */
333 vec_dble0 = (vector double){1924.930, 81234.49};
334 vec_uns_int_expected = (vector unsigned int){0, 1924, 0, 81234};
335 vec_uns_int_result = vec_unsignedo (vec_dble0);
336 test_unsigned_int_result (ODD, vec_uns_int_result,
337 vec_uns_int_expected);