1 /* { dg-do run } */
2 /* { dg-require-effective-target p9vector_hw } */
3 /* { dg-options "-mdejagnu-cpu=power9 -O2" } */
4
5 #include <altivec.h>
6 #define TRUE 1
7 #define FALSE 0
8
9 #ifdef DEBUG
10 #include <stdio.h>
11 #endif
12
13 #define EXTRACT 0
14
15 void abort (void);
16
result_wrong_ull(vector unsigned long long vec_expected,vector unsigned long long vec_actual)17 int result_wrong_ull (vector unsigned long long vec_expected,
18 vector unsigned long long vec_actual)
19 {
20 int i;
21
22 for (i = 0; i < 2; i++)
23 if (vec_expected[i] != vec_actual[i])
24 return TRUE;
25
26 return FALSE;
27 }
28
result_wrong_uc(vector unsigned char vec_expected,vector unsigned char vec_actual)29 int result_wrong_uc (vector unsigned char vec_expected,
30 vector unsigned char vec_actual)
31 {
32 int i;
33
34 for (i = 0; i < 16; i++)
35 if (vec_expected[i] != vec_actual[i])
36 return TRUE;
37
38 return FALSE;
39 }
40
41 #ifdef DEBUG
print_ull(vector unsigned long long vec_expected,vector unsigned long long vec_actual)42 void print_ull (vector unsigned long long vec_expected,
43 vector unsigned long long vec_actual)
44 {
45 int i;
46
47 printf("expected unsigned long long data\n");
48 for (i = 0; i < 2; i++)
49 printf(" %lld,", vec_expected[i]);
50
51 printf("\nactual signed char data\n");
52 for (i = 0; i < 2; i++)
53 printf(" %lld,", vec_actual[i]);
54 printf("\n");
55 }
56
print_uc(vector unsigned char vec_expected,vector unsigned char vec_actual)57 void print_uc (vector unsigned char vec_expected,
58 vector unsigned char vec_actual)
59 {
60 int i;
61
62 printf("expected unsigned char data\n");
63 for (i = 0; i < 16; i++)
64 printf(" %d,", vec_expected[i]);
65
66 printf("\nactual unsigned char data\n");
67 for (i = 0; i < 16; i++)
68 printf(" %d,", vec_actual[i]);
69 printf("\n");
70 }
71 #endif
72
73 #if EXTRACT
74 vector unsigned long long
vext(vector unsigned char * vc)75 vext (vector unsigned char *vc)
76 {
77 return vextract_si_vchar (*vc, 5);
78 }
79 #endif
80
main()81 int main()
82 {
83 vector signed int vsi_arg;
84 vector unsigned int vui_arg;
85 vector unsigned char vec_uc_arg, vec_uc_result, vec_uc_expected;
86 vector unsigned long long vec_ull_result, vec_ull_expected;
87 unsigned long long ull_result, ull_expected;
88
89 vec_uc_arg = (vector unsigned char){1, 2, 3, 4,
90 5, 6, 7, 8,
91 9, 10, 11, 12,
92 13, 14, 15, 16};
93
94 vsi_arg = (vector signed int){0xA, 0xB, 0xC, 0xD};
95
96 #ifdef __BIG_ENDIAN__
97 vec_uc_expected = (vector unsigned char){0, 0, 0, 0xB,
98 5, 6, 7, 8,
99 9, 10, 11, 12,
100 13, 14, 15, 16};
101 #else
102 vec_uc_expected = (vector unsigned char){0xC, 0, 0, 0,
103 5, 6, 7, 8,
104 9, 10, 11, 12,
105 13, 14, 15, 16};
106 #endif
107 /* Test vec_insert4b() */
108 /* Insert into char 0 location */
109 vec_uc_result = vec_insert4b (vsi_arg, vec_uc_arg, 0);
110
111 if (result_wrong_uc(vec_uc_expected, vec_uc_result))
112 {
113 #ifdef DEBUG
114 printf("Error: vec_insert4b pos 0, result does not match expected result\n");
115 print_uc (vec_uc_expected, vec_uc_result);
116 #else
117 abort();
118 #endif
119 }
120
121 /* insert into char 4 location */
122 #ifdef __BIG_ENDIAN__
123 vec_uc_expected = (vector unsigned char){1, 2, 3, 4,
124 0, 0, 0, 3,
125 9, 10, 11, 12,
126 13, 14, 15, 16};
127 #else
128 vec_uc_expected = (vector unsigned char){1, 2, 3, 4,
129 2, 0, 0, 0,
130 9, 10, 11, 12,
131 13, 14, 15, 16};
132 #endif
133 vui_arg = (vector unsigned int){0x4, 0x3, 0x2, 0x1};
134
135 vec_uc_result = vec_insert4b (vui_arg, vec_uc_arg, 4);
136
137 if (result_wrong_uc(vec_uc_expected, vec_uc_result))
138 {
139 #ifdef DEBUG
140 printf("Error: vec_insert4b pos 4, result does not match expected result\n");
141 print_uc (vec_uc_expected, vec_uc_result);
142 #else
143 abort();
144 #endif
145 }
146
147 /* Test vec_extract4b() */
148 /* Extract 4b, from char 0 location */
149 #ifdef __BIG_ENDIAN__
150 vec_uc_arg = (vector unsigned char){0, 0, 0, 10,
151 0, 0, 0, 20,
152 0, 0, 0, 30,
153 0, 0, 0, 40};
154 vec_ull_expected = (vector unsigned long long){10, 0};
155 #else
156 vec_uc_arg = (vector unsigned char){10, 0, 0, 0,
157 20, 0, 0, 0,
158 30, 0, 0, 0,
159 40, 0, 0, 0};
160 vec_ull_expected = (vector unsigned long long){0, 10};
161 #endif
162
163 vec_ull_result = vec_extract4b(vec_uc_arg, 0);
164
165 if (result_wrong_ull(vec_ull_expected, vec_ull_result))
166 {
167 #ifdef DEBUG
168 printf("Error: vec_extract4b pos 0, result does not match expected result\n");
169 print_ull (vec_ull_expected, vec_ull_result);
170 #else
171 abort();
172 #endif
173 }
174
175 /* Extract 4b, from char 12 location */
176 #ifdef __BIG_ENDIAN__
177 vec_uc_arg = (vector unsigned char){0, 0, 0, 10,
178 0, 0, 0, 20,
179 0, 0, 0, 30,
180 0, 0, 0, 40};
181 vec_ull_expected = (vector unsigned long long){40, 0};
182 #else
183 vec_uc_arg = (vector unsigned char){10, 0, 0, 0,
184 20, 0, 0, 0,
185 30, 0, 0, 0,
186 40, 0, 0, 0};
187 vec_ull_expected = (vector unsigned long long){0, 40};
188 #endif
189
190 vec_ull_result = vec_extract4b(vec_uc_arg, 12);
191
192 if (result_wrong_ull(vec_ull_expected, vec_ull_result))
193 {
194 #ifdef DEBUG
195 printf("Error: vec_extract4b pos 12, result does not match expected result\n");
196 print_ull (vec_ull_expected, vec_ull_result);
197 #else
198 abort();
199 #endif
200 }
201 }
202