1 /* { dg-do run { target { vsx_hw } } } */
2 /* { dg-require-effective-target vsx_hw } */
3 /* { dg-options "-maltivec -mvsx" } */
5 #include <altivec.h> // vector
17 void test_int_result(int check
, vector
int vec_result
, vector
int vec_expected
)
21 for (i
= 0; i
< 4; i
++) {
37 if (vec_result
[i
] != vec_expected
[i
]) {
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
]);
49 void test_unsigned_int_result(int check
, vector
unsigned int vec_result
,
50 vector
unsigned int vec_expected
)
54 for (i
= 0; i
< 4; i
++) {
70 if (vec_result
[i
] != vec_expected
[i
]) {
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
]);
83 void test_ll_int_result(vector
long long int vec_result
,
84 vector
long long int vec_expected
)
88 for (i
= 0; i
< 2; i
++)
89 if (vec_result
[i
] != vec_expected
[i
]) {
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
]);
100 void test_ll_unsigned_int_result(vector
long long unsigned int vec_result
,
101 vector
long long unsigned int vec_expected
)
105 for (i
= 0; i
< 2; i
++)
106 if (vec_result
[i
] != vec_expected
[i
]) {
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
]);
117 void test_result_sp(int check
, vector
float vec_result
,
118 vector
float vec_expected
)
121 for(i
= 0; i
<4; i
++) {
138 if (vec_result
[i
] != vec_expected
[i
]) {
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
]);
150 void test_result_dp(vector
double vec_result
, vector
double vec_expected
)
152 if (vec_result
[0] != vec_expected
[0]) {
154 printf("Test_result_dp: ");
155 printf("vec_result[0] (%f) != vec_expected[0] (%f)\n",
156 vec_result
[0], vec_expected
[0]);
162 if (vec_result
[1] != vec_expected
[1]) {
164 printf("Test_result_dp: ");
165 printf("vec_result[1] (%lld) != vec_expected[1] (%lld)\n",
166 vec_result
[1], vec_expected
[1]);
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,
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,
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
);