[testsuite] require sqrt_insn effective target where needed
[official-gcc.git] / gcc / testsuite / gcc.target / powerpc / altivec-2-runnable.c
blob7d1eda909f704d210b0bd5ed7a18210dc78d7fd5
1 /* { dg-do compile { target powerpc*-*-* } } */
2 /* { dg-require-effective-target powerpc_vsx_ok } */
3 /* { dg-options "-mvsx" } */
4 /* { dg-additional-options "-mdejagnu-cpu=power8" { target { ! has_arch_pwr8 } } } */
6 #include <altivec.h>
8 #ifdef DEBUG
9 #include <stdio.h>
10 #endif
12 void abort (void);
14 /* Endian considerations: The "high" half of a vector with n elements is the
15 first n/2 elements of the vector. For little endian, these elements are in
16 the rightmost half of the vector. For big endian, these elements are in the
17 leftmost half of the vector. */
19 int main ()
21 int i;
22 vector bool int vec_bi_arg;
23 vector bool long long vec_bll_result, vec_bll_expected;
25 vector signed int vec_si_arg;
26 vector signed long long int vec_slli_result, vec_slli_expected;
27 vector float vec_float_arg;
28 vector double vec_double_result, vec_double_expected;
30 union conv {
31 double d;
32 unsigned long long l;
33 } conv_exp, conv_val;
35 /* Use of 'double' and ‘long long’ in AltiVec types requires -mvsx */
36 /* __builtin_altivec_vupkhsw and __builtin_altivec_vupklsw
37 requires the -mcpu=power8 -mvsx option */
39 vec_bi_arg = (vector bool int){ 0, 1, 1, 0 };
41 vec_bll_expected = (vector bool long long){ 0, 1 };
43 vec_bll_result = vec_unpackh (vec_bi_arg);
45 for (i = 0; i < 2; i++) {
46 if (vec_bll_expected[i] != vec_bll_result[i])
47 #if DEBUG
48 printf("ERROR: vec_unpackh, vec_bll_expected[%d] = %d does not match vec_bll_result[%d] = %d\n",
49 i, vec_bll_expected[i], i, vec_bll_result[i]);
50 #else
51 abort();
52 #endif
55 vec_bll_expected = (vector bool long long){ 1, 0 };
57 vec_bll_result = vec_unpackl (vec_bi_arg);
59 for (i = 0; i < 2; i++) {
60 if (vec_bll_expected[i] != vec_bll_result[i])
61 #if DEBUG
62 printf("ERROR: vec_unpackl, vec_bll_expected[%d] = %d does not match vec_bll_result[%d] = %d\n",
63 i, vec_bll_expected[i], i, vec_bll_result[i]);
64 #else
65 abort();
66 #endif
70 vec_si_arg = (vector signed int){ 0, 101, 202, 303 };
72 vec_slli_expected = (vector signed long long int){ 0, 101 };
74 vec_slli_result = vec_unpackh (vec_si_arg);
76 for (i = 0; i < 2; i++) {
77 if (vec_slli_expected[i] != vec_slli_result[i])
78 #if DEBUG
79 printf("ERROR: vec_unpackh, vec_slli_expected[%d] = %d does not match vec_slli_result[%d] = %d\n",
80 i, vec_slli_expected[i], i, vec_slli_result[i]);
81 #else
82 abort();
83 #endif
86 vec_slli_result = vec_unpackl (vec_si_arg);
87 vec_slli_expected = (vector signed long long int){ 202, 303 };
89 for (i = 0; i < 2; i++) {
90 if (vec_slli_expected[i] != vec_slli_result[i])
91 #if DEBUG
92 printf("ERROR: vec_unpackl, vec_slli_expected[%d] = %d does not match vec_slli_result[%d] = %d\n",
93 i, vec_slli_expected[i], i, vec_slli_result[i]);
94 #else
95 abort();
96 #endif
99 vec_float_arg = (vector float){ 0.0, 1.5, 2.5, 3.5 };
101 vec_double_expected = (vector double){ 0.0, 1.5 };
103 vec_double_result = vec_unpackh (vec_float_arg);
105 for (i = 0; i < 2; i++) {
106 if (vec_double_expected[i] != vec_double_result[i])
108 #if DEBUG
109 printf("ERROR: vec_unpackh(), vec_double_expected[%d] = %f does not match vec_double_result[%d] = %f\n",
110 i, vec_double_expected[i], i, vec_double_result[i]);
111 conv_val.d = vec_double_result[i];
112 conv_exp.d = vec_double_expected[i];
113 printf(" vec_unpackh(), vec_double_expected[%d] = 0x%llx does not match vec_double_result[%d] = 0x%llx\n",
114 i, conv_exp.l, i,conv_val.l);
115 #else
116 abort();
117 #endif
121 vec_double_expected = (vector double){ 2.5, 3.5 };
123 vec_double_result = vec_unpackl (vec_float_arg);
125 for (i = 0; i < 2; i++) {
126 if (vec_double_expected[i] != vec_double_result[i])
128 #if DEBUG
129 printf("ERROR: vec_unpackl() vec_double_expected[%d] = %f does not match vec_double_result[%d] = %f\n",
130 i, vec_double_expected[i], i, vec_double_result[i]);
131 conv_val.d = vec_double_result[i];
132 conv_exp.d = vec_double_expected[i];
133 printf(" vec_unpackh(), vec_double_expected[%d] = 0x%llx does not match vec_double_result[%d] = 0x%llx\n",
134 i, conv_exp.l, i,conv_val.l);
135 #else
136 abort();
137 #endif
141 return 0;