1 /*
2
3 Copyright (c) 2009, 2010, 2011 STMicroelectronics
4 Written by Christophe Lyon
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 THE SOFTWARE.
23
24 */
25
26 #if defined(__arm__) || defined(__aarch64__)
27 #include <arm_neon.h>
28 #else
29 #include "stm-arm-neon.h"
30 #endif
31
32 #include "stm-arm-neon-ref.h"
33
34 #define TEST_MSG "VRSHR_N"
exec_vrshr_n(void)35 void exec_vrshr_n (void)
36 {
37 /* Basic test: y=vrshr_n(x,v), then store the result. */
38 #define TEST_VRSHR_N(Q, T1, T2, W, N, V) \
39 VECT_VAR(vector_res, T1, W, N) = \
40 vrshr##Q##_n_##T2##W(VECT_VAR(vector, T1, W, N), \
41 V); \
42 vst1##Q##_##T2##W(VECT_VAR(result, T1, W, N), VECT_VAR(vector_res, T1, W, N))
43
44 /* With ARM RVCT, we need to declare variables before any executable
45 statement */
46
47 DECL_VARIABLE_ALL_VARIANTS(vector);
48 DECL_VARIABLE_ALL_VARIANTS(vector_res);
49
50 clean_results ();
51
52 /* Initialize input "vector" from "buffer" */
53 TEST_MACRO_ALL_VARIANTS_2_5(VLOAD, vector, buffer);
54
55 /* Choose shift amount arbitrarily */
56 TEST_VRSHR_N(, int, s, 8, 8, 1);
57 TEST_VRSHR_N(, int, s, 16, 4, 12);
58 TEST_VRSHR_N(, int, s, 32, 2, 2);
59 TEST_VRSHR_N(, int, s, 64, 1, 32);
60 TEST_VRSHR_N(, uint, u, 8, 8, 2);
61 TEST_VRSHR_N(, uint, u, 16, 4, 3);
62 TEST_VRSHR_N(, uint, u, 32, 2, 5);
63 TEST_VRSHR_N(, uint, u, 64, 1, 33);
64
65 TEST_VRSHR_N(q, int, s, 8, 16, 1);
66 TEST_VRSHR_N(q, int, s, 16, 8, 12);
67 TEST_VRSHR_N(q, int, s, 32, 4, 2);
68 TEST_VRSHR_N(q, int, s, 64, 2, 32);
69 TEST_VRSHR_N(q, uint, u, 8, 16, 2);
70 TEST_VRSHR_N(q, uint, u, 16, 8, 3);
71 TEST_VRSHR_N(q, uint, u, 32, 4, 5);
72 TEST_VRSHR_N(q, uint, u, 64, 2, 33);
73
74 /* FIXME: only a few result buffers are used, but we output all of them */
75 dump_results_hex (TEST_MSG);
76
77 /* Another set of tests */
78 VDUP(vector, , int, s, 8, 8, 0x7F);
79 VDUP(vector, , int, s, 16, 4, 0x7FFF);
80 VDUP(vector, , int, s, 32, 2, 0x7FFFFFFF);
81 VDUP(vector, , int, s, 64, 1, 0x7FFFFFFFFFFFFFFFLL);
82 VDUP(vector, , uint, u, 8, 8, 0xFF);
83 VDUP(vector, , uint, u, 16, 4, 0xFFFF);
84 VDUP(vector, , uint, u, 32, 2, 0xFFFFFFFF);
85 VDUP(vector, , uint, u, 64, 1, 0xFFFFFFFFFFFFFFFFULL);
86 VDUP(vector, q, int, s, 8, 16, 0x7F);
87 VDUP(vector, q, int, s, 16, 8, 0x7FFF);
88 VDUP(vector, q, int, s, 32, 4, 0x7FFFFFFF);
89 VDUP(vector, q, int, s, 64, 2, 0x7FFFFFFFFFFFFFFFLL);
90 VDUP(vector, q, uint, u, 8, 16, 0xFF);
91 VDUP(vector, q, uint, u, 16, 8, 0xFFFF);
92 VDUP(vector, q, uint, u, 32, 4, 0xFFFFFFFF);
93 VDUP(vector, q, uint, u, 64, 2, 0xFFFFFFFFFFFFFFFFULL);
94
95 /* Use max shift amount, to exercise saturation code in the lib */
96 TEST_VRSHR_N(, int, s, 8, 8, 8);
97 TEST_VRSHR_N(, int, s, 16, 4, 16);
98 TEST_VRSHR_N(, int, s, 32, 2, 32);
99 TEST_VRSHR_N(, int, s, 64, 1, 64);
100 TEST_VRSHR_N(, uint, u, 8, 8, 8);
101 TEST_VRSHR_N(, uint, u, 16, 4, 16);
102 TEST_VRSHR_N(, uint, u, 32, 2, 32);
103 TEST_VRSHR_N(, uint, u, 64, 1, 64);
104 TEST_VRSHR_N(q, int, s, 8, 16, 8);
105 TEST_VRSHR_N(q, int, s, 16, 8, 16);
106 TEST_VRSHR_N(q, int, s, 32, 4, 32);
107 TEST_VRSHR_N(q, int, s, 64, 2, 64);
108 TEST_VRSHR_N(q, uint, u, 8, 16, 8);
109 TEST_VRSHR_N(q, uint, u, 16, 8, 16);
110 TEST_VRSHR_N(q, uint, u, 32, 4, 32);
111 TEST_VRSHR_N(q, uint, u, 64, 2, 64);
112
113 /* FIXME: only a few result buffers are used, but we output all of them */
114 dump_results_hex2 (TEST_MSG, " (overflow test: max shift amount, positive input)");
115
116 /* Use 1 as shift amount, to exercise saturation code in the lib */
117 TEST_VRSHR_N(, int, s, 8, 8, 1);
118 TEST_VRSHR_N(, int, s, 16, 4, 1);
119 TEST_VRSHR_N(, int, s, 32, 2, 1);
120 TEST_VRSHR_N(, int, s, 64, 1, 1);
121 TEST_VRSHR_N(, uint, u, 8, 8, 1);
122 TEST_VRSHR_N(, uint, u, 16, 4, 1);
123 TEST_VRSHR_N(, uint, u, 32, 2, 1);
124 TEST_VRSHR_N(, uint, u, 64, 1, 1);
125 TEST_VRSHR_N(q, int, s, 8, 16, 1);
126 TEST_VRSHR_N(q, int, s, 16, 8, 1);
127 TEST_VRSHR_N(q, int, s, 32, 4, 1);
128 TEST_VRSHR_N(q, int, s, 64, 2, 1);
129 TEST_VRSHR_N(q, uint, u, 8, 16, 1);
130 TEST_VRSHR_N(q, uint, u, 16, 8, 1);
131 TEST_VRSHR_N(q, uint, u, 32, 4, 1);
132 TEST_VRSHR_N(q, uint, u, 64, 2, 1);
133
134 /* FIXME: only a few result buffers are used, but we output all of them */
135 dump_results_hex2 (TEST_MSG, " (overflow test: shift by 1, with negative input)");
136
137 /* Use 3 as shift amount, to exercise saturation code in the lib */
138 TEST_VRSHR_N(, int, s, 8, 8, 3);
139 TEST_VRSHR_N(, int, s, 16, 4, 3);
140 TEST_VRSHR_N(, int, s, 32, 2, 3);
141 TEST_VRSHR_N(, int, s, 64, 1, 3);
142 TEST_VRSHR_N(, uint, u, 8, 8, 3);
143 TEST_VRSHR_N(, uint, u, 16, 4, 3);
144 TEST_VRSHR_N(, uint, u, 32, 2, 3);
145 TEST_VRSHR_N(, uint, u, 64, 1, 3);
146 TEST_VRSHR_N(q, int, s, 8, 16, 3);
147 TEST_VRSHR_N(q, int, s, 16, 8, 3);
148 TEST_VRSHR_N(q, int, s, 32, 4, 3);
149 TEST_VRSHR_N(q, int, s, 64, 2, 3);
150 TEST_VRSHR_N(q, uint, u, 8, 16, 3);
151 TEST_VRSHR_N(q, uint, u, 16, 8, 3);
152 TEST_VRSHR_N(q, uint, u, 32, 4, 3);
153 TEST_VRSHR_N(q, uint, u, 64, 2, 3);
154
155 /* FIXME: only a few result buffers are used, but we output all of them */
156 dump_results_hex2 (TEST_MSG, " (overflow test: shift by 3, positive input)");
157
158 VDUP(vector, , int, s, 8, 8, 0x80);
159 VDUP(vector, , int, s, 16, 4, 0x8000);
160 VDUP(vector, , int, s, 32, 2, 0x80000000);
161 VDUP(vector, , int, s, 64, 1, 0x8000000000000000LL);
162 VDUP(vector, , uint, u, 8, 8, 0xFF);
163 VDUP(vector, , uint, u, 16, 4, 0xFFFF);
164 VDUP(vector, , uint, u, 32, 2, 0xFFFFFFFF);
165 VDUP(vector, , uint, u, 64, 1, 0xFFFFFFFFFFFFFFFFULL);
166 VDUP(vector, q, int, s, 8, 16, 0x80);
167 VDUP(vector, q, int, s, 16, 8, 0x8000);
168 VDUP(vector, q, int, s, 32, 4, 0x80000000);
169 VDUP(vector, q, int, s, 64, 2, 0x8000000000000000LL);
170 VDUP(vector, q, uint, u, 8, 16, 0xFF);
171 VDUP(vector, q, uint, u, 16, 8, 0xFFFF);
172 VDUP(vector, q, uint, u, 32, 4, 0xFFFFFFFF);
173 VDUP(vector, q, uint, u, 64, 2, 0xFFFFFFFFFFFFFFFFULL);
174
175
176 /* Use 1 as shift amount, to exercise saturation code in the lib */
177 TEST_VRSHR_N(, int, s, 8, 8, 1);
178 TEST_VRSHR_N(, int, s, 16, 4, 1);
179 TEST_VRSHR_N(, int, s, 32, 2, 1);
180 TEST_VRSHR_N(, int, s, 64, 1, 1);
181 TEST_VRSHR_N(, uint, u, 8, 8, 1);
182 TEST_VRSHR_N(, uint, u, 16, 4, 1);
183 TEST_VRSHR_N(, uint, u, 32, 2, 1);
184 TEST_VRSHR_N(, uint, u, 64, 1, 1);
185 TEST_VRSHR_N(q, int, s, 8, 16, 1);
186 TEST_VRSHR_N(q, int, s, 16, 8, 1);
187 TEST_VRSHR_N(q, int, s, 32, 4, 1);
188 TEST_VRSHR_N(q, int, s, 64, 2, 1);
189 TEST_VRSHR_N(q, uint, u, 8, 16, 1);
190 TEST_VRSHR_N(q, uint, u, 16, 8, 1);
191 TEST_VRSHR_N(q, uint, u, 32, 4, 1);
192 TEST_VRSHR_N(q, uint, u, 64, 2, 1);
193
194 /* FIXME: only a few result buffers are used, but we output all of them */
195 dump_results_hex2 (TEST_MSG, " (overflow test: shift by 1, with negative input)");
196
197 /* Use 3 as shift amount, to exercise saturation code in the lib */
198 TEST_VRSHR_N(, int, s, 8, 8, 3);
199 TEST_VRSHR_N(, int, s, 16, 4, 3);
200 TEST_VRSHR_N(, int, s, 32, 2, 3);
201 TEST_VRSHR_N(, int, s, 64, 1, 3);
202 TEST_VRSHR_N(, uint, u, 8, 8, 3);
203 TEST_VRSHR_N(, uint, u, 16, 4, 3);
204 TEST_VRSHR_N(, uint, u, 32, 2, 3);
205 TEST_VRSHR_N(, uint, u, 64, 1, 3);
206 TEST_VRSHR_N(q, int, s, 8, 16, 3);
207 TEST_VRSHR_N(q, int, s, 16, 8, 3);
208 TEST_VRSHR_N(q, int, s, 32, 4, 3);
209 TEST_VRSHR_N(q, int, s, 64, 2, 3);
210 TEST_VRSHR_N(q, uint, u, 8, 16, 3);
211 TEST_VRSHR_N(q, uint, u, 16, 8, 3);
212 TEST_VRSHR_N(q, uint, u, 32, 4, 3);
213 TEST_VRSHR_N(q, uint, u, 64, 2, 3);
214
215 /* FIXME: only a few result buffers are used, but we output all of them */
216 dump_results_hex2 (TEST_MSG, " (overflow test: shift by 3, with negative input)");
217 }
218