1 /* { dg-do run { target { powerpc*-*-* && p9vector_hw } } } */
2 /* { dg-require-effective-target powerpc_p9vector_ok } */
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 vec_uc_expected = (vector unsigned char){0xC, 0, 0, 0,
97 5, 6, 7, 8,
98 9, 10, 11, 12,
99 13, 14, 15, 16};
100 /* Test vec_insert4b() */
101 /* Insert into char 0 location */
102 vec_uc_result = vec_insert4b (vsi_arg, vec_uc_arg, 0);
103
104 if (result_wrong_uc(vec_uc_expected, vec_uc_result))
105 {
106 #ifdef DEBUG
107 printf("Error: vec_insert4b pos 0, result does not match expected result\n");
108 print_uc (vec_uc_expected, vec_uc_result);
109 #else
110 abort();
111 #endif
112 }
113
114 /* insert into char 4 location */
115 vec_uc_expected = (vector unsigned char){1, 2, 3, 4,
116 2, 0, 0, 0,
117 9, 10, 11, 12,
118 13, 14, 15, 16};
119 vui_arg = (vector unsigned int){0x4, 0x3, 0x2, 0x1};
120
121 vec_uc_result = vec_insert4b (vui_arg, vec_uc_arg, 4);
122
123 if (result_wrong_uc(vec_uc_expected, vec_uc_result))
124 {
125 #ifdef DEBUG
126 printf("Error: vec_insert4b pos 4, result does not match expected result\n");
127 print_uc (vec_uc_expected, vec_uc_result);
128 #else
129 abort();
130 #endif
131 }
132
133 /* Test vec_extract4b() */
134 /* Extract 4b, from char 0 location */
135 vec_uc_arg = (vector unsigned char){10, 0, 0, 0,
136 20, 0, 0, 0,
137 30, 0, 0, 0,
138 40, 0, 0, 0};
139
140 vec_ull_expected = (vector unsigned long long){0, 10};
141 vec_ull_result = vec_extract4b(vec_uc_arg, 0);
142
143 if (result_wrong_ull(vec_ull_expected, vec_ull_result))
144 {
145 #ifdef DEBUG
146 printf("Error: vec_extract4b pos 0, result does not match expected result\n");
147 print_ull (vec_ull_expected, vec_ull_result);
148 #else
149 abort();
150 #endif
151 }
152
153 /* Extract 4b, from char 12 location */
154 vec_uc_arg = (vector unsigned char){10, 0, 0, 0,
155 20, 0, 0, 0,
156 30, 0, 0, 0,
157 40, 0, 0, 0};
158
159 vec_ull_expected = (vector unsigned long long){0, 40};
160 vec_ull_result = vec_extract4b(vec_uc_arg, 12);
161
162 if (result_wrong_ull(vec_ull_expected, vec_ull_result))
163 {
164 #ifdef DEBUG
165 printf("Error: vec_extract4b pos 12, result does not match expected result\n");
166 print_ull (vec_ull_expected, vec_ull_result);
167 #else
168 abort();
169 #endif
170 }
171 }
172