1 #include <arm_neon.h>
2 #include "arm-neon-ref.h"
3 #include "compute-ref-data.h"
4 
5 /* Expected results for vtbl1.  */
6 VECT_VAR_DECL(expected_vtbl1,int,8,8) [] = { 0x0, 0xf2, 0xf2, 0xf2,
7 					     0x0, 0x0, 0xf2, 0xf2 };
8 VECT_VAR_DECL(expected_vtbl1,uint,8,8) [] = { 0x0, 0xf3, 0xf3, 0xf3,
9 					      0x0, 0x0, 0xf3, 0xf3 };
10 VECT_VAR_DECL(expected_vtbl1,poly,8,8) [] = { 0x0, 0xf3, 0xf3, 0xf3,
11 					      0x0, 0x0, 0xf3, 0xf3 };
12 
13 /* Expected results for vtbl2.  */
14 VECT_VAR_DECL(expected_vtbl2,int,8,8) [] = { 0xf6, 0xf3, 0xf3, 0xf3,
15 					     0x0, 0x0, 0xf3, 0xf3 };
16 VECT_VAR_DECL(expected_vtbl2,uint,8,8) [] = { 0xf6, 0xf5, 0xf5, 0xf5,
17 					      0x0, 0x0, 0xf5, 0xf5 };
18 VECT_VAR_DECL(expected_vtbl2,poly,8,8) [] = { 0xf6, 0xf5, 0xf5, 0xf5,
19 					      0x0, 0x0, 0xf5, 0xf5 };
20 
21 /* Expected results for vtbl3.  */
22 VECT_VAR_DECL(expected_vtbl3,int,8,8) [] = { 0xf8, 0xf4, 0xf4, 0xf4,
23 					     0xff, 0x0, 0xf4, 0xf4 };
24 VECT_VAR_DECL(expected_vtbl3,uint,8,8) [] = { 0xf8, 0xf7, 0xf7, 0xf7,
25 					      0xff, 0x0, 0xf7, 0xf7 };
26 VECT_VAR_DECL(expected_vtbl3,poly,8,8) [] = { 0xf8, 0xf7, 0xf7, 0xf7,
27 					      0xff, 0x0, 0xf7, 0xf7 };
28 
29 /* Expected results for vtbl4.  */
30 VECT_VAR_DECL(expected_vtbl4,int,8,8) [] = { 0xfa, 0xf5, 0xf5, 0xf5,
31 					    0x3, 0x0, 0xf5, 0xf5 };
32 VECT_VAR_DECL(expected_vtbl4,uint,8,8) [] = { 0xfa, 0xf9, 0xf9, 0xf9,
33 					     0x3, 0x0, 0xf9, 0xf9 };
34 VECT_VAR_DECL(expected_vtbl4,poly,8,8) [] = { 0xfa, 0xf9, 0xf9, 0xf9,
35 					     0x3, 0x0, 0xf9, 0xf9 };
36 
37 /* Expected results for vtbx1.  */
38 VECT_VAR_DECL(expected_vtbx1,int,8,8) [] = { 0x33, 0xf2, 0xf2, 0xf2,
39 					    0x33, 0x33, 0xf2, 0xf2 };
40 VECT_VAR_DECL(expected_vtbx1,uint,8,8) [] = { 0xcc, 0xf3, 0xf3, 0xf3,
41 					     0xcc, 0xcc, 0xf3, 0xf3 };
42 VECT_VAR_DECL(expected_vtbx1,poly,8,8) [] = { 0xcc, 0xf3, 0xf3, 0xf3,
43 					     0xcc, 0xcc, 0xf3, 0xf3 };
44 
45 /* Expected results for vtbx2.  */
46 VECT_VAR_DECL(expected_vtbx2,int,8,8) [] = { 0xf6, 0xf3, 0xf3, 0xf3,
47 					    0x33, 0x33, 0xf3, 0xf3 };
48 VECT_VAR_DECL(expected_vtbx2,uint,8,8) [] = { 0xf6, 0xf5, 0xf5, 0xf5,
49 					     0xcc, 0xcc, 0xf5, 0xf5 };
50 VECT_VAR_DECL(expected_vtbx2,poly,8,8) [] = { 0xf6, 0xf5, 0xf5, 0xf5,
51 					     0xcc, 0xcc, 0xf5, 0xf5 };
52 
53 /* Expected results for vtbx3.  */
54 VECT_VAR_DECL(expected_vtbx3,int,8,8) [] = { 0xf8, 0xf4, 0xf4, 0xf4,
55 					    0xff, 0x33, 0xf4, 0xf4 };
56 VECT_VAR_DECL(expected_vtbx3,uint,8,8) [] = { 0xf8, 0xf7, 0xf7, 0xf7,
57 					     0xff, 0xcc, 0xf7, 0xf7 };
58 VECT_VAR_DECL(expected_vtbx3,poly,8,8) [] = { 0xf8, 0xf7, 0xf7, 0xf7,
59 					     0xff, 0xcc, 0xf7, 0xf7 };
60 
61 /* Expected results for vtbx4.  */
62 VECT_VAR_DECL(expected_vtbx4,int,8,8) [] = { 0xfa, 0xf5, 0xf5, 0xf5,
63 					     0x3, 0x33, 0xf5, 0xf5 };
64 VECT_VAR_DECL(expected_vtbx4,uint,8,8) [] = { 0xfa, 0xf9, 0xf9, 0xf9,
65 					      0x3, 0xcc, 0xf9, 0xf9 };
66 VECT_VAR_DECL(expected_vtbx4,poly,8,8) [] = { 0xfa, 0xf9, 0xf9, 0xf9,
67 					      0x3, 0xcc, 0xf9, 0xf9 };
68 
exec_vtbX(void)69 void exec_vtbX (void)
70 {
71   int i;
72 
73   /* In this case, input variables are arrays of vectors.  */
74 #define DECL_VTBX(T1, W, N, X)						\
75   VECT_ARRAY_TYPE(T1, W, N, X) VECT_ARRAY_VAR(table_vector, T1, W, N, X)
76 
77   /* The vtbl1 variant is different from vtbl{2,3,4} because it takes a
78      vector as 1st param, instead of an array of vectors.  */
79 #define TEST_VTBL1(T1, T2, T3, W, N)			\
80   VECT_VAR(table_vector, T1, W, N) =			\
81     vld1##_##T2##W((T1##W##_t *)lookup_table);		\
82 							\
83   VECT_VAR(vector_res, T1, W, N) =			\
84     vtbl1_##T2##W(VECT_VAR(table_vector, T1, W, N),	\
85 		  VECT_VAR(vector, T3, W, N));		\
86   vst1_##T2##W(VECT_VAR(result, T1, W, N),		\
87 	       VECT_VAR(vector_res, T1, W, N));
88 
89 #define TEST_VTBLX(T1, T2, T3, W, N, X)					\
90   VECT_ARRAY_VAR(table_vector, T1, W, N, X) =				\
91     vld##X##_##T2##W((T1##W##_t *)lookup_table);			\
92 									\
93   VECT_VAR(vector_res, T1, W, N) =					\
94     vtbl##X##_##T2##W(VECT_ARRAY_VAR(table_vector, T1, W, N, X),	\
95 		      VECT_VAR(vector, T3, W, N));			\
96   vst1_##T2##W(VECT_VAR(result, T1, W, N),				\
97 	       VECT_VAR(vector_res, T1, W, N));
98 
99   /* We need to define a lookup table.  */
100   uint8_t lookup_table[32];
101 
102   DECL_VARIABLE(vector, int, 8, 8);
103   DECL_VARIABLE(vector, uint, 8, 8);
104   DECL_VARIABLE(vector, poly, 8, 8);
105   DECL_VARIABLE(vector_res, int, 8, 8);
106   DECL_VARIABLE(vector_res, uint, 8, 8);
107   DECL_VARIABLE(vector_res, poly, 8, 8);
108 
109   /* For vtbl1.  */
110   DECL_VARIABLE(table_vector, int, 8, 8);
111   DECL_VARIABLE(table_vector, uint, 8, 8);
112   DECL_VARIABLE(table_vector, poly, 8, 8);
113 
114   /* For vtbx*.  */
115   DECL_VARIABLE(default_vector, int, 8, 8);
116   DECL_VARIABLE(default_vector, uint, 8, 8);
117   DECL_VARIABLE(default_vector, poly, 8, 8);
118 
119   /* We need only 8 bits variants.  */
120 #define DECL_ALL_VTBLX(X)			\
121   DECL_VTBX(int, 8, 8, X);			\
122   DECL_VTBX(uint, 8, 8, X);			\
123   DECL_VTBX(poly, 8, 8, X)
124 
125 #define TEST_ALL_VTBL1()			\
126   TEST_VTBL1(int, s, int, 8, 8);		\
127   TEST_VTBL1(uint, u, uint, 8, 8);		\
128   TEST_VTBL1(poly, p, uint, 8, 8)
129 
130 #define TEST_ALL_VTBLX(X)			\
131   TEST_VTBLX(int, s, int, 8, 8, X);		\
132   TEST_VTBLX(uint, u, uint, 8, 8, X);		\
133   TEST_VTBLX(poly, p, uint, 8, 8, X)
134 
135   /* Declare the temporary buffers / variables.  */
136   DECL_ALL_VTBLX(2);
137   DECL_ALL_VTBLX(3);
138   DECL_ALL_VTBLX(4);
139 
140   /* Fill the lookup table.  */
141   for (i=0; i<32; i++) {
142     lookup_table[i] = i-15;
143   }
144 
145   /* Choose init value arbitrarily, will be used as table index.  */
146   VDUP(vector, , int, s, 8, 8, 1);
147   VDUP(vector, , uint, u, 8, 8, 2);
148   VDUP(vector, , poly, p, 8, 8, 2);
149 
150   /* To ensure coverage, add some indexes larger than 8, 16 and 32
151      except: lane 0 (by 10), lane 4 (by 20) and lane 5 (by 40).  */
152   VSET_LANE(vector, , int, s, 8, 8, 0, 10);
153   VSET_LANE(vector, , int, s, 8, 8, 4, 20);
154   VSET_LANE(vector, , int, s, 8, 8, 5, 40);
155   VSET_LANE(vector, , uint, u, 8, 8, 0, 10);
156   VSET_LANE(vector, , uint, u, 8, 8, 4, 20);
157   VSET_LANE(vector, , uint, u, 8, 8, 5, 40);
158   VSET_LANE(vector, , poly, p, 8, 8, 0, 10);
159   VSET_LANE(vector, , poly, p, 8, 8, 4, 20);
160   VSET_LANE(vector, , poly, p, 8, 8, 5, 40);
161 
162 
163   /* Check vtbl1.  */
164   clean_results ();
165 #define TEST_MSG "VTBL1"
166   TEST_ALL_VTBL1();
167 
168   CHECK(TEST_MSG, int, 8, 8, PRIx8, expected_vtbl1, "");
169   CHECK(TEST_MSG, uint, 8, 8, PRIx8, expected_vtbl1, "");
170   CHECK_POLY(TEST_MSG, poly, 8, 8, PRIx8, expected_vtbl1, "");
171 
172   /* Check vtbl2.  */
173   clean_results ();
174 #undef TEST_MSG
175 #define TEST_MSG "VTBL2"
176   TEST_ALL_VTBLX(2);
177 
178   CHECK(TEST_MSG, int, 8, 8, PRIx8, expected_vtbl2, "");
179   CHECK(TEST_MSG, uint, 8, 8, PRIx8, expected_vtbl2, "");
180   CHECK_POLY(TEST_MSG, poly, 8, 8, PRIx8, expected_vtbl2, "");
181 
182   /* Check vtbl3.  */
183   clean_results ();
184 #undef TEST_MSG
185 #define TEST_MSG "VTBL3"
186   TEST_ALL_VTBLX(3);
187 
188   CHECK(TEST_MSG, int, 8, 8, PRIx8, expected_vtbl3, "");
189   CHECK(TEST_MSG, uint, 8, 8, PRIx8, expected_vtbl3, "");
190   CHECK_POLY(TEST_MSG, poly, 8, 8, PRIx8, expected_vtbl3, "");
191 
192   /* Check vtbl4.  */
193   clean_results ();
194 #undef TEST_MSG
195 #define TEST_MSG "VTBL4"
196   TEST_ALL_VTBLX(4);
197 
198   CHECK(TEST_MSG, int, 8, 8, PRIx8, expected_vtbl4, "");
199   CHECK(TEST_MSG, uint, 8, 8, PRIx8, expected_vtbl4, "");
200   CHECK_POLY(TEST_MSG, poly, 8, 8, PRIx8, expected_vtbl4, "");
201 
202 
203   /* Now test VTBX.  */
204 
205   /* The vtbx1 variant is different from vtbx{2,3,4} because it takes a
206      vector as 1st param, instead of an array of vectors.  */
207 #define TEST_VTBX1(T1, T2, T3, W, N)			\
208   VECT_VAR(table_vector, T1, W, N) =			\
209     vld1##_##T2##W((T1##W##_t *)lookup_table);		\
210 							\
211   VECT_VAR(vector_res, T1, W, N) =			\
212     vtbx1_##T2##W(VECT_VAR(default_vector, T1, W, N),	\
213 		  VECT_VAR(table_vector, T1, W, N),	\
214 		  VECT_VAR(vector, T3, W, N));		\
215   vst1_##T2##W(VECT_VAR(result, T1, W, N),		\
216 	       VECT_VAR(vector_res, T1, W, N));
217 
218 #define TEST_VTBXX(T1, T2, T3, W, N, X)					\
219   VECT_ARRAY_VAR(table_vector, T1, W, N, X) =				\
220     vld##X##_##T2##W((T1##W##_t *)lookup_table);			\
221 									\
222   VECT_VAR(vector_res, T1, W, N) =					\
223     vtbx##X##_##T2##W(VECT_VAR(default_vector, T1, W, N),		\
224 		      VECT_ARRAY_VAR(table_vector, T1, W, N, X),	\
225 		      VECT_VAR(vector, T3, W, N));			\
226   vst1_##T2##W(VECT_VAR(result, T1, W, N),				\
227 	       VECT_VAR(vector_res, T1, W, N));
228 
229 #define TEST_ALL_VTBX1()			\
230   TEST_VTBX1(int, s, int, 8, 8);		\
231   TEST_VTBX1(uint, u, uint, 8, 8);		\
232   TEST_VTBX1(poly, p, uint, 8, 8)
233 
234 #define TEST_ALL_VTBXX(X)			\
235   TEST_VTBXX(int, s, int, 8, 8, X);		\
236   TEST_VTBXX(uint, u, uint, 8, 8, X);		\
237   TEST_VTBXX(poly, p, uint, 8, 8, X)
238 
239   /* Choose init value arbitrarily, will be used as default value.  */
240   VDUP(default_vector, , int, s, 8, 8, 0x33);
241   VDUP(default_vector, , uint, u, 8, 8, 0xCC);
242   VDUP(default_vector, , poly, p, 8, 8, 0xCC);
243 
244   /* Check vtbx1.  */
245   clean_results ();
246 #undef TEST_MSG
247 #define TEST_MSG "VTBX1"
248   TEST_ALL_VTBX1();
249 
250   CHECK(TEST_MSG, int, 8, 8, PRIx8, expected_vtbx1, "");
251   CHECK(TEST_MSG, uint, 8, 8, PRIx8, expected_vtbx1, "");
252   CHECK_POLY(TEST_MSG, poly, 8, 8, PRIx8, expected_vtbx1, "");
253 
254   /* Check vtbx2.  */
255   clean_results ();
256 #undef TEST_MSG
257 #define TEST_MSG "VTBX2"
258   TEST_ALL_VTBXX(2);
259 
260   CHECK(TEST_MSG, int, 8, 8, PRIx8, expected_vtbx2, "");
261   CHECK(TEST_MSG, uint, 8, 8, PRIx8, expected_vtbx2, "");
262   CHECK_POLY(TEST_MSG, poly, 8, 8, PRIx8, expected_vtbx2, "");
263 
264   /* Check vtbx3.  */
265   clean_results ();
266 #undef TEST_MSG
267 #define TEST_MSG "VTBX3"
268   TEST_ALL_VTBXX(3);
269 
270   CHECK(TEST_MSG, int, 8, 8, PRIx8, expected_vtbx3, "");
271   CHECK(TEST_MSG, uint, 8, 8, PRIx8, expected_vtbx3, "");
272   CHECK_POLY(TEST_MSG, poly, 8, 8, PRIx8, expected_vtbx3, "");
273 
274   /* Check vtbx4.  */
275   clean_results ();
276 #undef TEST_MSG
277 #define TEST_MSG "VTBX4"
278   TEST_ALL_VTBXX(4);
279 
280   CHECK(TEST_MSG, int, 8, 8, PRIx8, expected_vtbx4, "");
281   CHECK(TEST_MSG, uint, 8, 8, PRIx8, expected_vtbx4, "");
282   CHECK_POLY(TEST_MSG, poly, 8, 8, PRIx8, expected_vtbx4, "");
283 }
284 
main(void)285 int main (void)
286 {
287   exec_vtbX ();
288   return 0;
289 }
290