Debian Codegraph @

gcc/testsuite/gcc.target/powerpc/p8vector-builtin-9.c

raw
1 /* { dg-do run { target p8vector_hw } } */
2 /* { dg-do compile { target { ! p8vector_hw } } } */
3 /* { dg-options "-O2 -mdejagnu-cpu=power8" } */
4 /* { dg-require-effective-target powerpc_vsx } */
5
6 #include <altivec.h>
7
8 #ifdef DEBUG
9 #include <stdio.h>
10 #endif
11
12 void abort (void);
13
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. */
18
19 int main ()
20 {
21 int i;
22 vector bool int vec_bi_arg;
23 vector bool long long vec_bll_result, vec_bll_expected;
24
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;
29
30 union conv {
31 double d;
32 unsigned long long l;
33 } conv_exp, conv_val;
34
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 */
38
39 vec_bi_arg = (vector bool int){ 0, 1, 1, 0 };
40
41 vec_bll_expected = (vector bool long long){ 0, 1 };
42
43 vec_bll_result = vec_unpackh (vec_bi_arg);
44
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
53 }
54
55 vec_bll_expected = (vector bool long long){ 1, 0 };
56
57 vec_bll_result = vec_unpackl (vec_bi_arg);
58
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
67 }
68
69
70 vec_si_arg = (vector signed int){ 0, 101, 202, 303 };
71
72 vec_slli_expected = (vector signed long long int){ 0, 101 };
73
74 vec_slli_result = vec_unpackh (vec_si_arg);
75
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
84 }
85
86 vec_slli_result = vec_unpackl (vec_si_arg);
87 vec_slli_expected = (vector signed long long int){ 202, 303 };
88
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
97 }
98
99 vec_float_arg = (vector float){ 0.0, 1.5, 2.5, 3.5 };
100
101 vec_double_expected = (vector double){ 0.0, 1.5 };
102
103 vec_double_result = vec_unpackh (vec_float_arg);
104
105 for (i = 0; i < 2; i++) {
106 if (vec_double_expected[i] != vec_double_result[i])
107 {
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
118 }
119 }
120
121 vec_double_expected = (vector double){ 2.5, 3.5 };
122
123 vec_double_result = vec_unpackl (vec_float_arg);
124
125 for (i = 0; i < 2; i++) {
126 if (vec_double_expected[i] != vec_double_result[i])
127 {
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
138 }
139 }
140
141 return 0;
142 }