• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "VRSRA_N"
exec_vrsra_n(void)35 void exec_vrsra_n (void)
36 {
37   /* Basic test: y=vrsra_n(x,v), then store the result.  */
38 #define TEST_VRSRA_N(Q, T1, T2, W, N, V)				\
39   VECT_VAR(vector_res, T1, W, N) =					\
40     vrsra##Q##_n_##T2##W(VECT_VAR(vector, T1, W, N),			\
41 			 VECT_VAR(vector2, T1, W, N),			\
42 			 V);						\
43   vst1##Q##_##T2##W(VECT_VAR(result, T1, W, N), VECT_VAR(vector_res, T1, W, N))
44 
45   /* With ARM RVCT, we need to declare variables before any executable
46      statement */
47 
48   DECL_VARIABLE_ALL_VARIANTS(vector);
49   DECL_VARIABLE_ALL_VARIANTS(vector2);
50   DECL_VARIABLE_ALL_VARIANTS(vector_res);
51 
52   clean_results ();
53 
54   /* Initialize input "vector" from "buffer"  */
55   TEST_MACRO_ALL_VARIANTS_2_5(VLOAD, vector, buffer);
56 
57   /* Choose arbitrary initialization values */
58   VDUP(vector2, , int, s, 8, 8, 0x11);
59   VDUP(vector2, , int, s, 16, 4, 0x22);
60   VDUP(vector2, , int, s, 32, 2, 0x33);
61   VDUP(vector2, , int, s, 64, 1, 0x44);
62   VDUP(vector2, , uint, u, 8, 8, 0x55);
63   VDUP(vector2, , uint, u, 16, 4, 0x66);
64   VDUP(vector2, , uint, u, 32, 2, 0x77);
65   VDUP(vector2, , uint, u, 64, 1, 0x88);
66 
67   VDUP(vector2, q, int, s, 8, 16, 0x11);
68   VDUP(vector2, q, int, s, 16, 8, 0x22);
69   VDUP(vector2, q, int, s, 32, 4, 0x33);
70   VDUP(vector2, q, int, s, 64, 2, 0x44);
71   VDUP(vector2, q, uint, u, 8, 16, 0x55);
72   VDUP(vector2, q, uint, u, 16, 8, 0x66);
73   VDUP(vector2, q, uint, u, 32, 4, 0x77);
74   VDUP(vector2, q, uint, u, 64, 2, 0x88);
75 
76   /* Choose shift amount arbitrarily  */
77   TEST_VRSRA_N(, int, s, 8, 8, 1);
78   TEST_VRSRA_N(, int, s, 16, 4, 12);
79   TEST_VRSRA_N(, int, s, 32, 2, 2);
80   TEST_VRSRA_N(, int, s, 64, 1, 32);
81   TEST_VRSRA_N(, uint, u, 8, 8, 2);
82   TEST_VRSRA_N(, uint, u, 16, 4, 3);
83   TEST_VRSRA_N(, uint, u, 32, 2, 5);
84   TEST_VRSRA_N(, uint, u, 64, 1, 33);
85 
86   TEST_VRSRA_N(q, int, s, 8, 16, 1);
87   TEST_VRSRA_N(q, int, s, 16, 8, 12);
88   TEST_VRSRA_N(q, int, s, 32, 4, 2);
89   TEST_VRSRA_N(q, int, s, 64, 2, 32);
90   TEST_VRSRA_N(q, uint, u, 8, 16, 2);
91   TEST_VRSRA_N(q, uint, u, 16, 8, 3);
92   TEST_VRSRA_N(q, uint, u, 32, 4, 5);
93   TEST_VRSRA_N(q, uint, u, 64, 2, 33);
94 
95   /* FIXME: only a few result buffers are used, but we output all of them */
96   dump_results_hex (TEST_MSG);
97 
98   /* Initialize the accumulator with 0 */
99   VDUP(vector, , int, s, 8, 8, 0);
100   VDUP(vector, , int, s, 16, 4, 0);
101   VDUP(vector, , int, s, 32, 2, 0);
102   VDUP(vector, , int, s, 64, 1, 0);
103   VDUP(vector, , uint, u, 8, 8, 0);
104   VDUP(vector, , uint, u, 16, 4, 0);
105   VDUP(vector, , uint, u, 32, 2, 0);
106   VDUP(vector, , uint, u, 64, 1, 0);
107   VDUP(vector, q, int, s, 8, 16, 0);
108   VDUP(vector, q, int, s, 16, 8, 0);
109   VDUP(vector, q, int, s, 32, 4, 0);
110   VDUP(vector, q, int, s, 64, 2, 0);
111   VDUP(vector, q, uint, u, 8, 16, 0);
112   VDUP(vector, q, uint, u, 16, 8, 0);
113   VDUP(vector, q, uint, u, 32, 4, 0);
114   VDUP(vector, q, uint, u, 64, 2, 0);
115 
116   /* Initialize with max values to check overflow */
117   VDUP(vector2, , int, s, 8, 8, 0x7F);
118   VDUP(vector2, , int, s, 16, 4, 0x7FFF);
119   VDUP(vector2, , int, s, 32, 2, 0x7FFFFFFF);
120   VDUP(vector2, , int, s, 64, 1, 0x7FFFFFFFFFFFFFFFLL);
121   VDUP(vector2, , uint, u, 8, 8, 0xFF);
122   VDUP(vector2, , uint, u, 16, 4, 0xFFFF);
123   VDUP(vector2, , uint, u, 32, 2, 0xFFFFFFFF);
124   VDUP(vector2, , uint, u, 64, 1, 0xFFFFFFFFFFFFFFFFULL);
125   VDUP(vector2, q, int, s, 8, 16, 0x7F);
126   VDUP(vector2, q, int, s, 16, 8, 0x7FFF);
127   VDUP(vector2, q, int, s, 32, 4, 0x7FFFFFFF);
128   VDUP(vector2, q, int, s, 64, 2, 0x7FFFFFFFFFFFFFFFLL);
129   VDUP(vector2, q, uint, u, 8, 16, 0xFF);
130   VDUP(vector2, q, uint, u, 16, 8, 0xFFFF);
131   VDUP(vector2, q, uint, u, 32, 4, 0xFFFFFFFF);
132   VDUP(vector2, q, uint, u, 64, 2, 0xFFFFFFFFFFFFFFFFULL);
133 
134   /* Shift by 1 to check overflow with rounding constant  */
135   TEST_VRSRA_N(, int, s, 8, 8, 1);
136   TEST_VRSRA_N(, int, s, 16, 4, 1);
137   TEST_VRSRA_N(, int, s, 32, 2, 1);
138   TEST_VRSRA_N(, int, s, 64, 1, 1);
139   TEST_VRSRA_N(, uint, u, 8, 8, 1);
140   TEST_VRSRA_N(, uint, u, 16, 4, 1);
141   TEST_VRSRA_N(, uint, u, 32, 2, 1);
142   TEST_VRSRA_N(, uint, u, 64, 1, 1);
143   TEST_VRSRA_N(q, int, s, 8, 16, 1);
144   TEST_VRSRA_N(q, int, s, 16, 8, 1);
145   TEST_VRSRA_N(q, int, s, 32, 4, 1);
146   TEST_VRSRA_N(q, int, s, 64, 2, 1);
147   TEST_VRSRA_N(q, uint, u, 8, 16, 1);
148   TEST_VRSRA_N(q, uint, u, 16, 8, 1);
149   TEST_VRSRA_N(q, uint, u, 32, 4, 1);
150   TEST_VRSRA_N(q, uint, u, 64, 2, 1);
151 
152   dump_results_hex2 (TEST_MSG, " (checking overflow: shift by 1, positive input)");
153 
154   /* Shift by 3 to check overflow with rounding constant  */
155   TEST_VRSRA_N(, int, s, 8, 8, 3);
156   TEST_VRSRA_N(, int, s, 16, 4, 3);
157   TEST_VRSRA_N(, int, s, 32, 2, 3);
158   TEST_VRSRA_N(, int, s, 64, 1, 3);
159   TEST_VRSRA_N(, uint, u, 8, 8, 3);
160   TEST_VRSRA_N(, uint, u, 16, 4, 3);
161   TEST_VRSRA_N(, uint, u, 32, 2, 3);
162   TEST_VRSRA_N(, uint, u, 64, 1, 3);
163   TEST_VRSRA_N(q, int, s, 8, 16, 3);
164   TEST_VRSRA_N(q, int, s, 16, 8, 3);
165   TEST_VRSRA_N(q, int, s, 32, 4, 3);
166   TEST_VRSRA_N(q, int, s, 64, 2, 3);
167   TEST_VRSRA_N(q, uint, u, 8, 16, 3);
168   TEST_VRSRA_N(q, uint, u, 16, 8, 3);
169   TEST_VRSRA_N(q, uint, u, 32, 4, 3);
170   TEST_VRSRA_N(q, uint, u, 64, 2, 3);
171 
172   dump_results_hex2 (TEST_MSG, " (checking overflow: shift by 3, positive input)");
173 
174   /* Shift by max to check overflow with rounding constant  */
175   TEST_VRSRA_N(, int, s, 8, 8, 8);
176   TEST_VRSRA_N(, int, s, 16, 4, 16);
177   TEST_VRSRA_N(, int, s, 32, 2, 32);
178   TEST_VRSRA_N(, int, s, 64, 1, 64);
179   TEST_VRSRA_N(, uint, u, 8, 8, 8);
180   TEST_VRSRA_N(, uint, u, 16, 4, 16);
181   TEST_VRSRA_N(, uint, u, 32, 2, 32);
182   TEST_VRSRA_N(, uint, u, 64, 1, 64);
183   TEST_VRSRA_N(q, int, s, 8, 16, 8);
184   TEST_VRSRA_N(q, int, s, 16, 8, 16);
185   TEST_VRSRA_N(q, int, s, 32, 4, 32);
186   TEST_VRSRA_N(q, int, s, 64, 2, 64);
187   TEST_VRSRA_N(q, uint, u, 8, 16, 8);
188   TEST_VRSRA_N(q, uint, u, 16, 8, 16);
189   TEST_VRSRA_N(q, uint, u, 32, 4, 32);
190   TEST_VRSRA_N(q, uint, u, 64, 2, 64);
191 
192   dump_results_hex2 (TEST_MSG, " (checking overflow: shift by max, positive input)");
193   /* Initialize with min values to check overflow */
194   VDUP(vector2, , int, s, 8, 8, 0x80);
195   VDUP(vector2, , int, s, 16, 4, 0x8000);
196   VDUP(vector2, , int, s, 32, 2, 0x80000000);
197   VDUP(vector2, , int, s, 64, 1, 0x8000000000000000LL);
198   VDUP(vector2, q, int, s, 8, 16, 0x80);
199   VDUP(vector2, q, int, s, 16, 8, 0x8000);
200   VDUP(vector2, q, int, s, 32, 4, 0x80000000);
201   VDUP(vector2, q, int, s, 64, 2, 0x8000000000000000ULL);
202 
203   /* Shift by 1 to check overflow with rounding constant  */
204   TEST_VRSRA_N(, int, s, 8, 8, 1);
205   TEST_VRSRA_N(, int, s, 16, 4, 1);
206   TEST_VRSRA_N(, int, s, 32, 2, 1);
207   TEST_VRSRA_N(, int, s, 64, 1, 1);
208   TEST_VRSRA_N(q, int, s, 8, 16, 1);
209   TEST_VRSRA_N(q, int, s, 16, 8, 1);
210   TEST_VRSRA_N(q, int, s, 32, 4, 1);
211   TEST_VRSRA_N(q, int, s, 64, 2, 1);
212 
213   dump_results_hex2 (TEST_MSG, " (checking overflow: shift by 1, negative input)");
214 
215   /* Shift by 3 to check overflow with rounding constant  */
216   TEST_VRSRA_N(, int, s, 8, 8, 3);
217   TEST_VRSRA_N(, int, s, 16, 4, 3);
218   TEST_VRSRA_N(, int, s, 32, 2, 3);
219   TEST_VRSRA_N(, int, s, 64, 1, 3);
220   TEST_VRSRA_N(q, int, s, 8, 16, 3);
221   TEST_VRSRA_N(q, int, s, 16, 8, 3);
222   TEST_VRSRA_N(q, int, s, 32, 4, 3);
223   TEST_VRSRA_N(q, int, s, 64, 2, 3);
224 
225   dump_results_hex2 (TEST_MSG, " (checking overflow: shift by max, negative input)");
226 
227   /* Shift by max to check overflow with rounding constant  */
228   TEST_VRSRA_N(, int, s, 8, 8, 8);
229   TEST_VRSRA_N(, int, s, 16, 4, 16);
230   TEST_VRSRA_N(, int, s, 32, 2, 32);
231   TEST_VRSRA_N(, int, s, 64, 1, 64);
232   TEST_VRSRA_N(q, int, s, 8, 16, 8);
233   TEST_VRSRA_N(q, int, s, 16, 8, 16);
234   TEST_VRSRA_N(q, int, s, 32, 4, 32);
235   TEST_VRSRA_N(q, int, s, 64, 2, 64);
236 
237   dump_results_hex2 (TEST_MSG, " (checking overflow: shift by max, negative input)");
238 }
239