blob: a9d29d787286a0f0c5eb22504163de529d13c2f5 [file] [log] [blame]
Christophe Lyon073831a2011-01-24 17:37:40 +01001/*
2
3Copyright (c) 2009, 2010, 2011 STMicroelectronics
4Written 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
34#define INSN vqshl
35#define TEST_MSG "VQSHL/VQSHLQ"
36
37#define FNNAME1(NAME) void exec_ ## NAME (void)
38#define FNNAME(NAME) FNNAME1(NAME)
39
40FNNAME (INSN)
41{
42 /* Basic test: v3=vqshl(v1,v2), then store the result. */
Christophe Lyonc1cc7822015-01-20 16:04:24 +010043#define TEST_VQSHL2(INSN, T3, Q, T1, T2, W, N) \
44 Set_Neon_Cumulative_Sat(0, VECT_VAR(vector_res, T1, W, N)); \
45 VECT_VAR(vector_res, T1, W, N) = \
46 INSN##Q##_##T2##W(VECT_VAR(vector, T1, W, N), \
47 VECT_VAR(vector_shift, T3, W, N)); \
48 vst1##Q##_##T2##W(VECT_VAR(result, T1, W, N), \
49 VECT_VAR(vector_res, T1, W, N)); \
50 dump_neon_cumulative_sat(TEST_MSG, xSTR(INSN##Q##_##T2##W), \
51 xSTR(T1), W, N)
Christophe Lyon073831a2011-01-24 17:37:40 +010052
53 /* Two auxliary macros are necessary to expand INSN */
54#define TEST_VQSHL1(INSN, T3, Q, T1, T2, W, N) \
55 TEST_VQSHL2(INSN, T3, Q, T1, T2, W, N)
56
57#define TEST_VQSHL(T3, Q, T1, T2, W, N) \
58 TEST_VQSHL1(INSN, T3, Q, T1, T2, W, N)
59
60
61 /* With ARM RVCT, we need to declare variables before any executable
62 statement */
63 DECL_VARIABLE_ALL_VARIANTS(vector);
64 DECL_VARIABLE_ALL_VARIANTS(vector_res);
65
66 DECL_VARIABLE_SIGNED_VARIANTS(vector_shift);
67
68 clean_results ();
69
70 /* Fill input vector with 0, to check saturation on limits */
Christophe Lyonf2053672014-12-16 10:26:00 +010071 VDUP(vector, , int, s, 8, 8, 0);
72 VDUP(vector, , int, s, 16, 4, 0);
73 VDUP(vector, , int, s, 32, 2, 0);
74 VDUP(vector, , int, s, 64, 1, 0);
75 VDUP(vector, , uint, u, 8, 8, 0);
76 VDUP(vector, , uint, u, 16, 4, 0);
77 VDUP(vector, , uint, u, 32, 2, 0);
78 VDUP(vector, , uint, u, 64, 1, 0);
79 VDUP(vector, q, int, s, 8, 16, 0);
80 VDUP(vector, q, int, s, 16, 8, 0);
81 VDUP(vector, q, int, s, 32, 4, 0);
82 VDUP(vector, q, int, s, 64, 2, 0);
83 VDUP(vector, q, uint, u, 8, 16, 0);
84 VDUP(vector, q, uint, u, 16, 8, 0);
85 VDUP(vector, q, uint, u, 32, 4, 0);
86 VDUP(vector, q, uint, u, 64, 2, 0);
Christophe Lyon073831a2011-01-24 17:37:40 +010087
88 /* Choose init value arbitrarily, will be used as shift amount */
89 /* Use values equal or one-less-than the type width to check
90 behaviour on limits */
91 /* Shift all lanes by 7 ... */
Christophe Lyonf2053672014-12-16 10:26:00 +010092 VDUP(vector_shift, , int, s, 8, 8, 7);
Christophe Lyon073831a2011-01-24 17:37:40 +010093 /* except: lane 0 (by 6), lane 1 (by 8) and lane 2 (by 9) */
94 TEST_VSET_LANE(vector_shift, , int, s, 8, 8, 0, 6);
95 TEST_VSET_LANE(vector_shift, , int, s, 8, 8, 1, 8);
96 TEST_VSET_LANE(vector_shift, , int, s, 8, 8, 2, 9);
97
Christophe Lyonf2053672014-12-16 10:26:00 +010098 VDUP(vector_shift, , int, s, 16, 4, 15);
Christophe Lyon073831a2011-01-24 17:37:40 +010099 TEST_VSET_LANE(vector_shift, , int, s, 16, 4, 0, 14);
100 TEST_VSET_LANE(vector_shift, , int, s, 16, 4, 1, 16);
101 TEST_VSET_LANE(vector_shift, , int, s, 16, 4, 2, 17);
102
Christophe Lyonf2053672014-12-16 10:26:00 +0100103 VDUP(vector_shift, , int, s, 32, 2, 31);
Christophe Lyon073831a2011-01-24 17:37:40 +0100104 TEST_VSET_LANE(vector_shift, , int, s, 32, 2, 1, 30);
105
Christophe Lyonf2053672014-12-16 10:26:00 +0100106 VDUP(vector_shift, , int, s, 64, 1, 63);
Christophe Lyon073831a2011-01-24 17:37:40 +0100107
Christophe Lyonf2053672014-12-16 10:26:00 +0100108 VDUP(vector_shift, q, int, s, 8, 16, 8);
109 VDUP(vector_shift, q, int, s, 16, 8, 16);
110 VDUP(vector_shift, q, int, s, 32, 4, 32);
Christophe Lyon073831a2011-01-24 17:37:40 +0100111 TEST_VSET_LANE(vector_shift, q, int, s, 32, 4, 1, 33);
112
Christophe Lyonf2053672014-12-16 10:26:00 +0100113 VDUP(vector_shift, q, int, s, 64, 2, 64);
Christophe Lyon073831a2011-01-24 17:37:40 +0100114 TEST_VSET_LANE(vector_shift, q, int, s, 64, 2, 1, 62);
115
Christophe Lyon4a6e5cc2014-06-03 22:47:52 +0200116 fprintf(ref_file, "\n%s cumulative saturation output:\n",
117 TEST_MSG " (with input = 0)");
Christophe Lyon073831a2011-01-24 17:37:40 +0100118 TEST_MACRO_ALL_VARIANTS_1_5(TEST_VQSHL, int);
119 dump_results_hex2 (TEST_MSG, " (with input = 0)");
120
121
122 /* Use negative shift amounts */
Christophe Lyonf2053672014-12-16 10:26:00 +0100123 VDUP(vector_shift, , int, s, 8, 8, -1);
124 VDUP(vector_shift, , int, s, 16, 4, -2);
125 VDUP(vector_shift, , int, s, 32, 2, -3);
126 VDUP(vector_shift, , int, s, 64, 1, -4);
127 VDUP(vector_shift, q, int, s, 8, 16, -7);
128 VDUP(vector_shift, q, int, s, 16, 8, -11);
129 VDUP(vector_shift, q, int, s, 32, 4, -13);
130 VDUP(vector_shift, q, int, s, 64, 2, -20);
Christophe Lyon073831a2011-01-24 17:37:40 +0100131
Christophe Lyon4a6e5cc2014-06-03 22:47:52 +0200132 fprintf(ref_file, "\n%s cumulative saturation output:\n",
Christophe Lyon073831a2011-01-24 17:37:40 +0100133 TEST_MSG " (input 0 and negative shift amount)");
134 TEST_MACRO_ALL_VARIANTS_1_5(TEST_VQSHL, int);
135 dump_results_hex2 (TEST_MSG, " (input 0 and negative shift amount)");
136
137 /* Test again, with predefined input values */
Christophe Lyonf2053672014-12-16 10:26:00 +0100138 TEST_MACRO_ALL_VARIANTS_2_5(VLOAD, vector, buffer);
Christophe Lyon073831a2011-01-24 17:37:40 +0100139
140 /* Choose init value arbitrarily, will be used as shift amount */
Christophe Lyonf2053672014-12-16 10:26:00 +0100141 VDUP(vector_shift, , int, s, 8, 8, 1);
142 VDUP(vector_shift, , int, s, 16, 4, 3);
143 VDUP(vector_shift, , int, s, 32, 2, 8);
144 VDUP(vector_shift, , int, s, 64, 1, -3);
145 VDUP(vector_shift, q, int, s, 8, 16, 10);
146 VDUP(vector_shift, q, int, s, 16, 8, 12);
147 VDUP(vector_shift, q, int, s, 32, 4, 32);
148 VDUP(vector_shift, q, int, s, 64, 2, 63);
Christophe Lyon073831a2011-01-24 17:37:40 +0100149
Christophe Lyon4a6e5cc2014-06-03 22:47:52 +0200150 fprintf(ref_file, "\n%s cumulative saturation output:\n", TEST_MSG);
Christophe Lyon073831a2011-01-24 17:37:40 +0100151 TEST_MACRO_ALL_VARIANTS_1_5(TEST_VQSHL, int);
152 dump_results_hex (TEST_MSG);
153
154 /* Use negative shift amounts */
Christophe Lyonf2053672014-12-16 10:26:00 +0100155 VDUP(vector_shift, , int, s, 8, 8, -1);
156 VDUP(vector_shift, , int, s, 16, 4, -2);
157 VDUP(vector_shift, , int, s, 32, 2, -3);
158 VDUP(vector_shift, , int, s, 64, 1, -4);
159 VDUP(vector_shift, q, int, s, 8, 16, -7);
160 VDUP(vector_shift, q, int, s, 16, 8, -11);
161 VDUP(vector_shift, q, int, s, 32, 4, -13);
162 VDUP(vector_shift, q, int, s, 64, 2, -20);
Christophe Lyon073831a2011-01-24 17:37:40 +0100163
Christophe Lyon4a6e5cc2014-06-03 22:47:52 +0200164 fprintf(ref_file, "\n%s cumulative saturation output:\n",
Christophe Lyon073831a2011-01-24 17:37:40 +0100165 TEST_MSG " (negative shift amount)");
166 TEST_MACRO_ALL_VARIANTS_1_5(TEST_VQSHL, int);
167 dump_results_hex2 (TEST_MSG, " (negative shift amount)");
168
169 /* Use large shift amounts */
Christophe Lyonf2053672014-12-16 10:26:00 +0100170 VDUP(vector_shift, , int, s, 8, 8, 8);
171 VDUP(vector_shift, , int, s, 16, 4, 16);
172 VDUP(vector_shift, , int, s, 32, 2, 32);
173 VDUP(vector_shift, , int, s, 64, 1, 64);
174 VDUP(vector_shift, q, int, s, 8, 16, 8);
175 VDUP(vector_shift, q, int, s, 16, 8, 16);
176 VDUP(vector_shift, q, int, s, 32, 4, 32);
177 VDUP(vector_shift, q, int, s, 64, 2, 64);
Christophe Lyon073831a2011-01-24 17:37:40 +0100178
Christophe Lyon4a6e5cc2014-06-03 22:47:52 +0200179 fprintf(ref_file, "\n%s cumulative saturation output:\n",
Christophe Lyon073831a2011-01-24 17:37:40 +0100180 TEST_MSG " (large shift amount, negative input)");
181 TEST_MACRO_ALL_VARIANTS_1_5(TEST_VQSHL, int);
182 dump_results_hex2 (TEST_MSG, " (large shift amount, negative input)");
183
184 /* Fill input vector with max value, to check saturation on limits */
Christophe Lyonf2053672014-12-16 10:26:00 +0100185 VDUP(vector, , int, s, 8, 8, 0x7F);
186 VDUP(vector, , int, s, 16, 4, 0x7FFF);
187 VDUP(vector, , int, s, 32, 2, 0x7FFFFFFF);
188 VDUP(vector, , int, s, 64, 1, 0x7FFFFFFFFFFFFFFFLL);
189 VDUP(vector, , uint, u, 8, 8, 0xFF);
190 VDUP(vector, , uint, u, 16, 4, 0xFFFF);
191 VDUP(vector, , uint, u, 32, 2, 0xFFFFFFFF);
192 VDUP(vector, , uint, u, 64, 1, 0xFFFFFFFFFFFFFFFFULL);
193 VDUP(vector, q, int, s, 8, 16, 0x7F);
194 VDUP(vector, q, int, s, 16, 8, 0x7FFF);
195 VDUP(vector, q, int, s, 32, 4, 0x7FFFFFFF);
196 VDUP(vector, q, int, s, 64, 2, 0x7FFFFFFFFFFFFFFFLL);
197 VDUP(vector, q, uint, u, 8, 16, 0xFF);
198 VDUP(vector, q, uint, u, 16, 8, 0xFFFF);
199 VDUP(vector, q, uint, u, 32, 4, 0xFFFFFFFF);
200 VDUP(vector, q, uint, u, 64, 2, 0xFFFFFFFFFFFFFFFFULL);
Christophe Lyon073831a2011-01-24 17:37:40 +0100201
202 /* Shift by -1 */
Christophe Lyonf2053672014-12-16 10:26:00 +0100203 VDUP(vector_shift, , int, s, 8, 8, -1);
204 VDUP(vector_shift, , int, s, 16, 4, -1);
205 VDUP(vector_shift, , int, s, 32, 2, -1);
206 VDUP(vector_shift, , int, s, 64, 1, -1);
207 VDUP(vector_shift, q, int, s, 8, 16, -1);
208 VDUP(vector_shift, q, int, s, 16, 8, -1);
209 VDUP(vector_shift, q, int, s, 32, 4, -1);
210 VDUP(vector_shift, q, int, s, 64, 2, -1);
Christophe Lyon073831a2011-01-24 17:37:40 +0100211
Christophe Lyon4a6e5cc2014-06-03 22:47:52 +0200212 fprintf(ref_file, "\n%s cumulative saturation output:\n",
213 TEST_MSG " (check cumulative saturation)");
Christophe Lyon073831a2011-01-24 17:37:40 +0100214 TEST_MACRO_ALL_VARIANTS_1_5(TEST_VQSHL, int);
Christophe Lyon4a6e5cc2014-06-03 22:47:52 +0200215 dump_results_hex2 (TEST_MSG, " (check cumulative saturation)");
Christophe Lyon073831a2011-01-24 17:37:40 +0100216
217 /* Use large shift amounts */
Christophe Lyonf2053672014-12-16 10:26:00 +0100218 VDUP(vector_shift, , int, s, 8, 8, 8);
219 VDUP(vector_shift, , int, s, 16, 4, 16);
220 VDUP(vector_shift, , int, s, 32, 2, 32);
221 VDUP(vector_shift, , int, s, 64, 1, 64);
222 VDUP(vector_shift, q, int, s, 8, 16, 8);
223 VDUP(vector_shift, q, int, s, 16, 8, 16);
224 VDUP(vector_shift, q, int, s, 32, 4, 32);
225 VDUP(vector_shift, q, int, s, 64, 2, 64);
Christophe Lyon073831a2011-01-24 17:37:40 +0100226
Christophe Lyon4a6e5cc2014-06-03 22:47:52 +0200227 fprintf(ref_file, "\n%s cumulative saturation output:\n",
Christophe Lyon073831a2011-01-24 17:37:40 +0100228 TEST_MSG " (large shift amount, positive input)");
229 TEST_MACRO_ALL_VARIANTS_1_5(TEST_VQSHL, int);
230 dump_results_hex2 (TEST_MSG, " (large shift amount, positive input)");
231
232 /* Check 64 bits saturation */
Christophe Lyonf2053672014-12-16 10:26:00 +0100233 VDUP(vector, , int, s, 64, 1, -10);
234 VDUP(vector_shift, , int, s, 64, 1, 64);
235 VDUP(vector, q, int, s, 64, 2, 10);
236 VDUP(vector_shift, q, int, s, 64, 2, 64);
Christophe Lyon4a6e5cc2014-06-03 22:47:52 +0200237 fprintf(ref_file, "\n%s cumulative saturation output:\n",
Christophe Lyon073831a2011-01-24 17:37:40 +0100238 TEST_MSG " (check saturation on 64 bits)");
239 TEST_MACRO_ALL_VARIANTS_1_5(TEST_VQSHL, int);
240 dump_results_hex2 (TEST_MSG, " (check saturation on 64 bits)");
241}