blob: 6f87d1a130185c00cb5276324ba20d72b94c8596 [file] [log] [blame]
Christophe Lyon073831a2011-01-24 17:37:40 +01001/*
2
Christophe Lyon80902f62013-03-29 16:26:42 +01003Copyright (c) 2009, 2010, 2011, 2013 STMicroelectronics
Christophe Lyon073831a2011-01-24 17:37:40 +01004Written by Christophe Lyon
5
6Permission is hereby granted, free of charge, to any person obtaining a copy
7of this software and associated documentation files (the "Software"), to deal
8in the Software without restriction, including without limitation the rights
9to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10copies of the Software, and to permit persons to whom the Software is
11furnished to do so, subject to the following conditions:
12
13The above copyright notice and this permission notice shall be included in
14all copies or substantial portions of the Software.
15
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22THE SOFTWARE.
23
24*/
25
Christophe Lyon1775be02014-07-10 13:46:54 +020026#if defined(__arm__) || defined(__aarch64__)
Christophe Lyon073831a2011-01-24 17:37:40 +010027#include <arm_neon.h>
28#else
Christophe Lyon0dab5f72011-07-19 17:14:09 +020029#include "stm-arm-neon.h"
Christophe Lyon073831a2011-01-24 17:37:40 +010030#endif
31
32#include "stm-arm-neon-ref.h"
33
34void exec_vtbX (void)
35{
36 int i;
37
38 /* In this case, input variables are arrays of vectors */
39#define DECL_VTBX(T1, W, N, X) \
40 VECT_ARRAY_TYPE(T1, W, N, X) VECT_ARRAY_VAR(table_vector, T1, W, N, X)
41
42 /* The vtbl1 variant is different from vtbl{2,3,4} because it takes a
43 vector as 1st param, instead of an array of vectors */
Christophe Lyon80902f62013-03-29 16:26:42 +010044#define TEST_VTBL1(T1, T2, T3, W, N) \
Christophe Lyon073831a2011-01-24 17:37:40 +010045 VECT_VAR(table_vector, T1, W, N) = \
46 vld1##_##T2##W((T1##W##_t *)lookup_table); \
47 \
48 VECT_VAR(vector_res, T1, W, N) = \
49 vtbl1_##T2##W(VECT_VAR(table_vector, T1, W, N), \
Christophe Lyon80902f62013-03-29 16:26:42 +010050 VECT_VAR(vector, T3, W, N)); \
Christophe Lyon073831a2011-01-24 17:37:40 +010051 vst1_##T2##W(VECT_VAR(result, T1, W, N), \
52 VECT_VAR(vector_res, T1, W, N));
53
Christophe Lyon80902f62013-03-29 16:26:42 +010054#define TEST_VTBLX(T1, T2, T3, W, N, X) \
Christophe Lyon073831a2011-01-24 17:37:40 +010055 VECT_ARRAY_VAR(table_vector, T1, W, N, X) = \
56 vld##X##_##T2##W((T1##W##_t *)lookup_table); \
57 \
58 VECT_VAR(vector_res, T1, W, N) = \
59 vtbl##X##_##T2##W(VECT_ARRAY_VAR(table_vector, T1, W, N, X), \
Christophe Lyon80902f62013-03-29 16:26:42 +010060 VECT_VAR(vector, T3, W, N)); \
Christophe Lyon073831a2011-01-24 17:37:40 +010061 vst1_##T2##W(VECT_VAR(result, T1, W, N), \
62 VECT_VAR(vector_res, T1, W, N));
63
64 /* With ARM RVCT, we need to declare variables before any executable
65 statement */
66
67 /* We need to define a lookup table */
68 uint8_t lookup_table[32];
69
70 DECL_VARIABLE(vector, int, 8, 8);
71 DECL_VARIABLE(vector, uint, 8, 8);
Christophe Lyon80902f62013-03-29 16:26:42 +010072 DECL_VARIABLE(vector, poly, 8, 8);
Christophe Lyon073831a2011-01-24 17:37:40 +010073 DECL_VARIABLE(vector_res, int, 8, 8);
74 DECL_VARIABLE(vector_res, uint, 8, 8);
Christophe Lyon80902f62013-03-29 16:26:42 +010075 DECL_VARIABLE(vector_res, poly, 8, 8);
Christophe Lyon073831a2011-01-24 17:37:40 +010076
77 /* For vtbl1 */
78 DECL_VARIABLE(table_vector, int, 8, 8);
79 DECL_VARIABLE(table_vector, uint, 8, 8);
Christophe Lyon80902f62013-03-29 16:26:42 +010080 DECL_VARIABLE(table_vector, poly, 8, 8);
Christophe Lyon073831a2011-01-24 17:37:40 +010081
82 /* For vtbx* */
83 DECL_VARIABLE(default_vector, int, 8, 8);
84 DECL_VARIABLE(default_vector, uint, 8, 8);
Christophe Lyon80902f62013-03-29 16:26:42 +010085 DECL_VARIABLE(default_vector, poly, 8, 8);
Christophe Lyon073831a2011-01-24 17:37:40 +010086
87 /* We need only 8 bits variants */
88#define DECL_ALL_VTBLX(X) \
89 DECL_VTBX(int, 8, 8, X); \
Christophe Lyon80902f62013-03-29 16:26:42 +010090 DECL_VTBX(uint, 8, 8, X); \
91 DECL_VTBX(poly, 8, 8, X)
Christophe Lyon073831a2011-01-24 17:37:40 +010092
93#define TEST_ALL_VTBL1() \
Christophe Lyon80902f62013-03-29 16:26:42 +010094 TEST_VTBL1(int, s, int, 8, 8); \
95 TEST_VTBL1(uint, u, uint, 8, 8); \
96 TEST_VTBL1(poly, p, uint, 8, 8)
Christophe Lyon073831a2011-01-24 17:37:40 +010097
98#define TEST_ALL_VTBLX(X) \
Christophe Lyon80902f62013-03-29 16:26:42 +010099 TEST_VTBLX(int, s, int, 8, 8, X); \
100 TEST_VTBLX(uint, u, uint, 8, 8, X); \
101 TEST_VTBLX(poly, p, uint, 8, 8, X)
Christophe Lyon073831a2011-01-24 17:37:40 +0100102
103 /* Declare the temporary buffers / variables */
104 DECL_ALL_VTBLX(2);
105 DECL_ALL_VTBLX(3);
106 DECL_ALL_VTBLX(4);
107
108 /* Fill the lookup table */
109 for (i=0; i<32; i++) {
110 lookup_table[i] = i-15;
111 }
112
113 /* Choose init value arbitrarily, will be used as table index */
Christophe Lyonf2053672014-12-16 10:26:00 +0100114 VDUP(vector, , int, s, 8, 8, 1);
115 VDUP(vector, , uint, u, 8, 8, 2);
116 VDUP(vector, , poly, p, 8, 8, 2);
Christophe Lyon073831a2011-01-24 17:37:40 +0100117
118 /* To ensure code coverage of lib, add some indexes larger than 8,16 and 32 */
119 /* except: lane 0 (by 6), lane 1 (by 8) and lane 2 (by 9) */
120 TEST_VSET_LANE(vector, , int, s, 8, 8, 0, 10);
121 TEST_VSET_LANE(vector, , int, s, 8, 8, 4, 20);
122 TEST_VSET_LANE(vector, , int, s, 8, 8, 5, 40);
123 TEST_VSET_LANE(vector, , uint, u, 8, 8, 0, 10);
124 TEST_VSET_LANE(vector, , uint, u, 8, 8, 4, 20);
125 TEST_VSET_LANE(vector, , uint, u, 8, 8, 5, 40);
Christophe Lyon80902f62013-03-29 16:26:42 +0100126 TEST_VSET_LANE(vector, , poly, p, 8, 8, 0, 10);
127 TEST_VSET_LANE(vector, , poly, p, 8, 8, 4, 20);
128 TEST_VSET_LANE(vector, , poly, p, 8, 8, 5, 40);
Christophe Lyon073831a2011-01-24 17:37:40 +0100129
130
131 /* Check vtbl1 */
132 clean_results ();
133#define TEST_MSG "VTBL1"
134 TEST_ALL_VTBL1();
135 dump_results_hex (TEST_MSG);
136
137 /* Check vtbl2 */
138 clean_results ();
139#undef TEST_MSG
140#define TEST_MSG "VTBL2"
141 TEST_ALL_VTBLX(2);
142 dump_results_hex (TEST_MSG);
143
144 /* Check vtbl3 */
145 clean_results ();
146#undef TEST_MSG
147#define TEST_MSG "VTBL3"
148 TEST_ALL_VTBLX(3);
149 dump_results_hex (TEST_MSG);
150
151 /* Check vtbl4 */
152 clean_results ();
153#undef TEST_MSG
154#define TEST_MSG "VTBL4"
155 TEST_ALL_VTBLX(4);
156 dump_results_hex (TEST_MSG);
157
158
159 /* Now test VTBX */
160
161 /* The vtbx1 variant is different from vtbx{2,3,4} because it takes a
162 vector as 1st param, instead of an array of vectors */
Christophe Lyon80902f62013-03-29 16:26:42 +0100163#define TEST_VTBX1(T1, T2, T3, W, N) \
Christophe Lyon073831a2011-01-24 17:37:40 +0100164 VECT_VAR(table_vector, T1, W, N) = \
165 vld1##_##T2##W((T1##W##_t *)lookup_table); \
166 \
167 VECT_VAR(vector_res, T1, W, N) = \
168 vtbx1_##T2##W(VECT_VAR(default_vector, T1, W, N), \
169 VECT_VAR(table_vector, T1, W, N), \
Christophe Lyon80902f62013-03-29 16:26:42 +0100170 VECT_VAR(vector, T3, W, N)); \
Christophe Lyon073831a2011-01-24 17:37:40 +0100171 vst1_##T2##W(VECT_VAR(result, T1, W, N), \
172 VECT_VAR(vector_res, T1, W, N));
173
Christophe Lyon80902f62013-03-29 16:26:42 +0100174#define TEST_VTBXX(T1, T2, T3, W, N, X) \
Christophe Lyon073831a2011-01-24 17:37:40 +0100175 VECT_ARRAY_VAR(table_vector, T1, W, N, X) = \
176 vld##X##_##T2##W((T1##W##_t *)lookup_table); \
177 \
178 VECT_VAR(vector_res, T1, W, N) = \
179 vtbx##X##_##T2##W(VECT_VAR(default_vector, T1, W, N), \
180 VECT_ARRAY_VAR(table_vector, T1, W, N, X), \
Christophe Lyon80902f62013-03-29 16:26:42 +0100181 VECT_VAR(vector, T3, W, N)); \
Christophe Lyon073831a2011-01-24 17:37:40 +0100182 vst1_##T2##W(VECT_VAR(result, T1, W, N), \
183 VECT_VAR(vector_res, T1, W, N));
184
185#define TEST_ALL_VTBX1() \
Christophe Lyon80902f62013-03-29 16:26:42 +0100186 TEST_VTBX1(int, s, int, 8, 8); \
187 TEST_VTBX1(uint, u, uint, 8, 8); \
188 TEST_VTBX1(poly, p, uint, 8, 8)
Christophe Lyon073831a2011-01-24 17:37:40 +0100189
190#define TEST_ALL_VTBXX(X) \
Christophe Lyon80902f62013-03-29 16:26:42 +0100191 TEST_VTBXX(int, s, int, 8, 8, X); \
192 TEST_VTBXX(uint, u, uint, 8, 8, X); \
193 TEST_VTBXX(poly, p, uint, 8, 8, X)
Christophe Lyon073831a2011-01-24 17:37:40 +0100194
195 /* Choose init value arbitrarily, will be used as default value */
Christophe Lyonf2053672014-12-16 10:26:00 +0100196 VDUP(default_vector, , int, s, 8, 8, 0x33);
197 VDUP(default_vector, , uint, u, 8, 8, 0xCC);
198 VDUP(default_vector, , poly, p, 8, 8, 0xCC);
Christophe Lyon073831a2011-01-24 17:37:40 +0100199
200 /* Check vtbx1 */
201 clean_results ();
202#undef TEST_MSG
203#define TEST_MSG "VTBX1"
204 TEST_ALL_VTBX1();
205 dump_results_hex (TEST_MSG);
206
207 /* Check vtbx2 */
208 clean_results ();
209#undef TEST_MSG
210#define TEST_MSG "VTBX2"
211 TEST_ALL_VTBXX(2);
212 dump_results_hex (TEST_MSG);
213
214 /* Check vtbx3 */
215 clean_results ();
216#undef TEST_MSG
217#define TEST_MSG "VTBX3"
218 TEST_ALL_VTBXX(3);
219 dump_results_hex (TEST_MSG);
220
221 /* Check vtbx4 */
222 clean_results ();
223#undef TEST_MSG
224#define TEST_MSG "VTBX4"
225 TEST_ALL_VTBXX(4);
226 dump_results_hex (TEST_MSG);
227}