• 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 "VRSHL/VRSHLQ"
exec_vrshl(void)35 void exec_vrshl (void)
36 {
37   /* Basic test: v3=vrshl(v1,v2), then store the result.  */
38 #define TEST_VRSHL(T3, Q, T1, T2, W, N)					\
39   VECT_VAR(vector_res, T1, W, N) =					\
40     vrshl##Q##_##T2##W(VECT_VAR(vector, T1, W, N),			\
41 		       VECT_VAR(vector_shift, T3, W, N));		\
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   DECL_VARIABLE_ALL_VARIANTS(vector);
47   DECL_VARIABLE_ALL_VARIANTS(vector_res);
48 
49   DECL_VARIABLE_SIGNED_VARIANTS(vector_shift);
50 
51   clean_results ();
52 
53   /* Fill input vector with 0, to check behavior on limits */
54   VDUP(vector, , int, s, 8, 8, 0);
55   VDUP(vector, , int, s, 16, 4, 0);
56   VDUP(vector, , int, s, 32, 2, 0);
57   VDUP(vector, , int, s, 64, 1, 0);
58   VDUP(vector, , uint, u, 8, 8, 0);
59   VDUP(vector, , uint, u, 16, 4, 0);
60   VDUP(vector, , uint, u, 32, 2, 0);
61   VDUP(vector, , uint, u, 64, 1, 0);
62   VDUP(vector, q, int, s, 8, 16, 0);
63   VDUP(vector, q, int, s, 16, 8, 0);
64   VDUP(vector, q, int, s, 32, 4, 0);
65   VDUP(vector, q, int, s, 64, 2, 0);
66   VDUP(vector, q, uint, u, 8, 16, 0);
67   VDUP(vector, q, uint, u, 16, 8, 0);
68   VDUP(vector, q, uint, u, 32, 4, 0);
69   VDUP(vector, q, uint, u, 64, 2, 0);
70 
71   /* Choose init value arbitrarily, will be used as shift amount */
72   /* Use values equal to one-less-than the type width to check
73      behaviour on limits */
74   VDUP(vector_shift, , int, s, 8, 8, 7);
75   VDUP(vector_shift, , int, s, 16, 4, 15);
76   VDUP(vector_shift, , int, s, 32, 2, 31);
77   VDUP(vector_shift, , int, s, 64, 1, 63);
78   VDUP(vector_shift, q, int, s, 8, 16, 7);
79   VDUP(vector_shift, q, int, s, 16, 8, 15);
80   VDUP(vector_shift, q, int, s, 32, 4, 31);
81   VDUP(vector_shift, q, int, s, 64, 2, 63);
82 
83   TEST_MACRO_ALL_VARIANTS_1_5(TEST_VRSHL, int);
84 
85   dump_results_hex2 (TEST_MSG, " (with input = 0)");
86 
87   /* Use negative shift amounts */
88   VDUP(vector_shift, , int, s, 8, 8, -1);
89   VDUP(vector_shift, , int, s, 16, 4, -2);
90   VDUP(vector_shift, , int, s, 32, 2, -3);
91   VDUP(vector_shift, , int, s, 64, 1, -4);
92   VDUP(vector_shift, q, int, s, 8, 16, -7);
93   VDUP(vector_shift, q, int, s, 16, 8, -11);
94   VDUP(vector_shift, q, int, s, 32, 4, -13);
95   VDUP(vector_shift, q, int, s, 64, 2, -20);
96 
97   TEST_MACRO_ALL_VARIANTS_1_5(TEST_VRSHL, int);
98 
99   dump_results_hex2 (TEST_MSG, " (input 0 and negative shift amount)");
100 
101   /* Test again, with predefined input values */
102   TEST_MACRO_ALL_VARIANTS_2_5(VLOAD, vector, buffer);
103 
104   /* Choose init value arbitrarily, will be used as shift amount */
105   VDUP(vector_shift, , int, s, 8, 8, 1);
106   VDUP(vector_shift, , int, s, 16, 4, 3);
107   VDUP(vector_shift, , int, s, 32, 2, 8);
108   VDUP(vector_shift, , int, s, 64, 1, -3);
109   VDUP(vector_shift, q, int, s, 8, 16, 10);
110   VDUP(vector_shift, q, int, s, 16, 8, 12);
111   VDUP(vector_shift, q, int, s, 32, 4, 32);
112   VDUP(vector_shift, q, int, s, 64, 2, 63);
113 
114   TEST_MACRO_ALL_VARIANTS_1_5(TEST_VRSHL, int);
115 
116   dump_results_hex (TEST_MSG);
117 
118 
119   /* Use negative shift amounts */
120   VDUP(vector_shift, , int, s, 8, 8, -1);
121   VDUP(vector_shift, , int, s, 16, 4, -2);
122   VDUP(vector_shift, , int, s, 32, 2, -3);
123   VDUP(vector_shift, , int, s, 64, 1, -4);
124   VDUP(vector_shift, q, int, s, 8, 16, -7);
125   VDUP(vector_shift, q, int, s, 16, 8, -11);
126   VDUP(vector_shift, q, int, s, 32, 4, -13);
127   VDUP(vector_shift, q, int, s, 64, 2, -20);
128 
129   TEST_MACRO_ALL_VARIANTS_1_5(TEST_VRSHL, int);
130 
131   dump_results_hex2 (TEST_MSG, " (negative shift amount)");
132 
133   /* Fill input vector with max value, to check behavior on limits */
134   VDUP(vector, , int, s, 8, 8, 0x7F);
135   VDUP(vector, , int, s, 16, 4, 0x7FFF);
136   VDUP(vector, , int, s, 32, 2, 0x7FFFFFFF);
137   VDUP(vector, , int, s, 64, 1, 0x7FFFFFFFFFFFFFFFLL);
138   VDUP(vector, , uint, u, 8, 8, 0xFF);
139   VDUP(vector, , uint, u, 16, 4, 0xFFFF);
140   VDUP(vector, , uint, u, 32, 2, 0xFFFFFFFF);
141   VDUP(vector, , uint, u, 64, 1, 0xFFFFFFFFFFFFFFFFULL);
142   VDUP(vector, q, int, s, 8, 16, 0x7F);
143   VDUP(vector, q, int, s, 16, 8, 0x7FFF);
144   VDUP(vector, q, int, s, 32, 4, 0x7FFFFFFF);
145   VDUP(vector, q, int, s, 64, 2, 0x7FFFFFFFFFFFFFFFLL);
146   VDUP(vector, q, uint, u, 8, 16, 0xFF);
147   VDUP(vector, q, uint, u, 16, 8, 0xFFFF);
148   VDUP(vector, q, uint, u, 32, 4, 0xFFFFFFFF);
149   VDUP(vector, q, uint, u, 64, 2, 0xFFFFFFFFFFFFFFFFULL);
150 
151   /* Use -1 shift amount to check overflow with round_const */
152   VDUP(vector_shift, , int, s, 8, 8, -1);
153   VDUP(vector_shift, , int, s, 16, 4, -1);
154   VDUP(vector_shift, , int, s, 32, 2, -1);
155   VDUP(vector_shift, , int, s, 64, 1, -1);
156   VDUP(vector_shift, q, int, s, 8, 16, -1);
157   VDUP(vector_shift, q, int, s, 16, 8, -1);
158   VDUP(vector_shift, q, int, s, 32, 4, -1);
159   VDUP(vector_shift, q, int, s, 64, 2, -1);
160 
161   TEST_MACRO_ALL_VARIANTS_1_5(TEST_VRSHL, int);
162 
163   dump_results_hex2 (TEST_MSG, " (checking round_const overflow: shift by -1)");
164 
165   /* Use -3 shift amount to check overflow with round_const */
166   VDUP(vector_shift, , int, s, 8, 8, -3);
167   VDUP(vector_shift, , int, s, 16, 4, -3);
168   VDUP(vector_shift, , int, s, 32, 2, -3);
169   VDUP(vector_shift, , int, s, 64, 1, -3);
170   VDUP(vector_shift, q, int, s, 8, 16, -3);
171   VDUP(vector_shift, q, int, s, 16, 8, -3);
172   VDUP(vector_shift, q, int, s, 32, 4, -3);
173   VDUP(vector_shift, q, int, s, 64, 2, -3);
174 
175   TEST_MACRO_ALL_VARIANTS_1_5(TEST_VRSHL, int);
176 
177   dump_results_hex2 (TEST_MSG, " (checking round_const overflow: shift by -3)");
178 
179   /* Use negative shift amount as large as input vector width */
180   VDUP(vector_shift, , int, s, 8, 8, -8);
181   VDUP(vector_shift, , int, s, 16, 4, -16);
182   VDUP(vector_shift, , int, s, 32, 2, -32);
183   VDUP(vector_shift, , int, s, 64, 1, -64);
184   VDUP(vector_shift, q, int, s, 8, 16, -8);
185   VDUP(vector_shift, q, int, s, 16, 8, -16);
186   VDUP(vector_shift, q, int, s, 32, 4, -32);
187   VDUP(vector_shift, q, int, s, 64, 2, -64);
188 
189   TEST_MACRO_ALL_VARIANTS_1_5(TEST_VRSHL, int);
190 
191   dump_results_hex2 (TEST_MSG, " (checking negative shift amount as large as input vector width)");
192 
193   /* Test large shift amount */
194   VDUP(vector_shift, , int, s, 8, 8, 10);
195   VDUP(vector_shift, , int, s, 16, 4, 20);
196   VDUP(vector_shift, , int, s, 32, 2, 33);
197   VDUP(vector_shift, , int, s, 64, 1, 65);
198   VDUP(vector_shift, q, int, s, 8, 16, 9);
199   VDUP(vector_shift, q, int, s, 16, 8, 16);
200   VDUP(vector_shift, q, int, s, 32, 4, 32);
201   VDUP(vector_shift, q, int, s, 64, 2, 64);
202 
203   TEST_MACRO_ALL_VARIANTS_1_5(TEST_VRSHL, int);
204 
205   dump_results_hex2 (TEST_MSG, " (large shift amount)");
206 
207   /* Test large negative shift amount */
208   VDUP(vector_shift, , int, s, 8, 8, -10);
209   VDUP(vector_shift, , int, s, 16, 4, -20);
210   VDUP(vector_shift, , int, s, 32, 2, -33);
211   VDUP(vector_shift, , int, s, 64, 1, -65);
212   VDUP(vector_shift, q, int, s, 8, 16, -9);
213   VDUP(vector_shift, q, int, s, 16, 8, -16);
214   VDUP(vector_shift, q, int, s, 32, 4, -32);
215   VDUP(vector_shift, q, int, s, 64, 2, -64);
216 
217   TEST_MACRO_ALL_VARIANTS_1_5(TEST_VRSHL, int);
218 
219   dump_results_hex2 (TEST_MSG, " (large negative shift amount)");
220 }
221