1 // Copyright 2016, VIXL authors
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are met:
6 //
7 // * Redistributions of source code must retain the above copyright notice,
8 // this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above copyright notice,
10 // this list of conditions and the following disclaimer in the documentation
11 // and/or other materials provided with the distribution.
12 // * Neither the name of ARM Limited nor the names of its contributors may be
13 // used to endorse or promote products derived from this software without
14 // specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS CONTRIBUTORS "AS IS" AND
17 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
20 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
27
28 // -----------------------------------------------------------------------------
29 // This file is auto generated from the
30 // test/aarch32/config/template-assembler-aarch32.cc.in template file using
31 // tools/generate_tests.py.
32 //
33 // PLEASE DO NOT EDIT.
34 // -----------------------------------------------------------------------------
35
36
37 #include "test-runner.h"
38
39 #include "test-utils.h"
40 #include "test-utils-aarch32.h"
41
42 #include "aarch32/assembler-aarch32.h"
43 #include "aarch32/macro-assembler-aarch32.h"
44
45 #define BUF_SIZE (4096)
46
47 namespace vixl {
48 namespace aarch32 {
49
50 // List of instruction mnemonics.
51 #define FOREACH_INSTRUCTION(M) \
52 M(cmn) \
53 M(cmp) \
54 M(mov) \
55 M(movs) \
56 M(mvn) \
57 M(mvns) \
58 M(teq) \
59 M(tst) \
60 M(sxtb) \
61 M(sxtb16) \
62 M(sxth) \
63 M(uxtb) \
64 M(uxtb16) \
65 M(uxth)
66
67
68 // The following definitions are defined again in each generated test, therefore
69 // we need to place them in an anomymous namespace. It expresses that they are
70 // local to this file only, and the compiler is not allowed to share these types
71 // across test files during template instantiation. Specifically, `Operands` has
72 // various layouts across generated tests so it absolutely cannot be shared.
73
74 #ifdef VIXL_INCLUDE_TARGET_T32
75 namespace {
76
77 // Values to be passed to the assembler to produce the instruction under test.
78 struct Operands {
79 Condition cond;
80 Register rd;
81 Register rn;
82 };
83
84 // This structure contains all data needed to test one specific
85 // instruction.
86 struct TestData {
87 // The `operands` field represents what to pass to the assembler to
88 // produce the instruction.
89 Operands operands;
90 // True if we need to generate an IT instruction for this test to be valid.
91 bool in_it_block;
92 // The condition to give the IT instruction, this will be set to "al" by
93 // default.
94 Condition it_condition;
95 // Description of the operands, used for error reporting.
96 const char* operands_description;
97 // Unique identifier, used for generating traces.
98 const char* identifier;
99 };
100
101 struct TestResult {
102 size_t size;
103 const byte* encoding;
104 };
105
106 // Each element of this array produce one instruction encoding.
107 const TestData kTests[] =
108 {{{al, r0, r0}, false, al, "al r0 r0", "al_r0_r0"},
109 {{al, r0, r1}, false, al, "al r0 r1", "al_r0_r1"},
110 {{al, r0, r2}, false, al, "al r0 r2", "al_r0_r2"},
111 {{al, r0, r3}, false, al, "al r0 r3", "al_r0_r3"},
112 {{al, r0, r4}, false, al, "al r0 r4", "al_r0_r4"},
113 {{al, r0, r5}, false, al, "al r0 r5", "al_r0_r5"},
114 {{al, r0, r6}, false, al, "al r0 r6", "al_r0_r6"},
115 {{al, r0, r7}, false, al, "al r0 r7", "al_r0_r7"},
116 {{al, r0, r8}, false, al, "al r0 r8", "al_r0_r8"},
117 {{al, r0, r9}, false, al, "al r0 r9", "al_r0_r9"},
118 {{al, r0, r10}, false, al, "al r0 r10", "al_r0_r10"},
119 {{al, r0, r11}, false, al, "al r0 r11", "al_r0_r11"},
120 {{al, r0, r12}, false, al, "al r0 r12", "al_r0_r12"},
121 {{al, r0, r13}, false, al, "al r0 r13", "al_r0_r13"},
122 {{al, r0, r14}, false, al, "al r0 r14", "al_r0_r14"},
123 {{al, r1, r0}, false, al, "al r1 r0", "al_r1_r0"},
124 {{al, r1, r1}, false, al, "al r1 r1", "al_r1_r1"},
125 {{al, r1, r2}, false, al, "al r1 r2", "al_r1_r2"},
126 {{al, r1, r3}, false, al, "al r1 r3", "al_r1_r3"},
127 {{al, r1, r4}, false, al, "al r1 r4", "al_r1_r4"},
128 {{al, r1, r5}, false, al, "al r1 r5", "al_r1_r5"},
129 {{al, r1, r6}, false, al, "al r1 r6", "al_r1_r6"},
130 {{al, r1, r7}, false, al, "al r1 r7", "al_r1_r7"},
131 {{al, r1, r8}, false, al, "al r1 r8", "al_r1_r8"},
132 {{al, r1, r9}, false, al, "al r1 r9", "al_r1_r9"},
133 {{al, r1, r10}, false, al, "al r1 r10", "al_r1_r10"},
134 {{al, r1, r11}, false, al, "al r1 r11", "al_r1_r11"},
135 {{al, r1, r12}, false, al, "al r1 r12", "al_r1_r12"},
136 {{al, r1, r13}, false, al, "al r1 r13", "al_r1_r13"},
137 {{al, r1, r14}, false, al, "al r1 r14", "al_r1_r14"},
138 {{al, r2, r0}, false, al, "al r2 r0", "al_r2_r0"},
139 {{al, r2, r1}, false, al, "al r2 r1", "al_r2_r1"},
140 {{al, r2, r2}, false, al, "al r2 r2", "al_r2_r2"},
141 {{al, r2, r3}, false, al, "al r2 r3", "al_r2_r3"},
142 {{al, r2, r4}, false, al, "al r2 r4", "al_r2_r4"},
143 {{al, r2, r5}, false, al, "al r2 r5", "al_r2_r5"},
144 {{al, r2, r6}, false, al, "al r2 r6", "al_r2_r6"},
145 {{al, r2, r7}, false, al, "al r2 r7", "al_r2_r7"},
146 {{al, r2, r8}, false, al, "al r2 r8", "al_r2_r8"},
147 {{al, r2, r9}, false, al, "al r2 r9", "al_r2_r9"},
148 {{al, r2, r10}, false, al, "al r2 r10", "al_r2_r10"},
149 {{al, r2, r11}, false, al, "al r2 r11", "al_r2_r11"},
150 {{al, r2, r12}, false, al, "al r2 r12", "al_r2_r12"},
151 {{al, r2, r13}, false, al, "al r2 r13", "al_r2_r13"},
152 {{al, r2, r14}, false, al, "al r2 r14", "al_r2_r14"},
153 {{al, r3, r0}, false, al, "al r3 r0", "al_r3_r0"},
154 {{al, r3, r1}, false, al, "al r3 r1", "al_r3_r1"},
155 {{al, r3, r2}, false, al, "al r3 r2", "al_r3_r2"},
156 {{al, r3, r3}, false, al, "al r3 r3", "al_r3_r3"},
157 {{al, r3, r4}, false, al, "al r3 r4", "al_r3_r4"},
158 {{al, r3, r5}, false, al, "al r3 r5", "al_r3_r5"},
159 {{al, r3, r6}, false, al, "al r3 r6", "al_r3_r6"},
160 {{al, r3, r7}, false, al, "al r3 r7", "al_r3_r7"},
161 {{al, r3, r8}, false, al, "al r3 r8", "al_r3_r8"},
162 {{al, r3, r9}, false, al, "al r3 r9", "al_r3_r9"},
163 {{al, r3, r10}, false, al, "al r3 r10", "al_r3_r10"},
164 {{al, r3, r11}, false, al, "al r3 r11", "al_r3_r11"},
165 {{al, r3, r12}, false, al, "al r3 r12", "al_r3_r12"},
166 {{al, r3, r13}, false, al, "al r3 r13", "al_r3_r13"},
167 {{al, r3, r14}, false, al, "al r3 r14", "al_r3_r14"},
168 {{al, r4, r0}, false, al, "al r4 r0", "al_r4_r0"},
169 {{al, r4, r1}, false, al, "al r4 r1", "al_r4_r1"},
170 {{al, r4, r2}, false, al, "al r4 r2", "al_r4_r2"},
171 {{al, r4, r3}, false, al, "al r4 r3", "al_r4_r3"},
172 {{al, r4, r4}, false, al, "al r4 r4", "al_r4_r4"},
173 {{al, r4, r5}, false, al, "al r4 r5", "al_r4_r5"},
174 {{al, r4, r6}, false, al, "al r4 r6", "al_r4_r6"},
175 {{al, r4, r7}, false, al, "al r4 r7", "al_r4_r7"},
176 {{al, r4, r8}, false, al, "al r4 r8", "al_r4_r8"},
177 {{al, r4, r9}, false, al, "al r4 r9", "al_r4_r9"},
178 {{al, r4, r10}, false, al, "al r4 r10", "al_r4_r10"},
179 {{al, r4, r11}, false, al, "al r4 r11", "al_r4_r11"},
180 {{al, r4, r12}, false, al, "al r4 r12", "al_r4_r12"},
181 {{al, r4, r13}, false, al, "al r4 r13", "al_r4_r13"},
182 {{al, r4, r14}, false, al, "al r4 r14", "al_r4_r14"},
183 {{al, r5, r0}, false, al, "al r5 r0", "al_r5_r0"},
184 {{al, r5, r1}, false, al, "al r5 r1", "al_r5_r1"},
185 {{al, r5, r2}, false, al, "al r5 r2", "al_r5_r2"},
186 {{al, r5, r3}, false, al, "al r5 r3", "al_r5_r3"},
187 {{al, r5, r4}, false, al, "al r5 r4", "al_r5_r4"},
188 {{al, r5, r5}, false, al, "al r5 r5", "al_r5_r5"},
189 {{al, r5, r6}, false, al, "al r5 r6", "al_r5_r6"},
190 {{al, r5, r7}, false, al, "al r5 r7", "al_r5_r7"},
191 {{al, r5, r8}, false, al, "al r5 r8", "al_r5_r8"},
192 {{al, r5, r9}, false, al, "al r5 r9", "al_r5_r9"},
193 {{al, r5, r10}, false, al, "al r5 r10", "al_r5_r10"},
194 {{al, r5, r11}, false, al, "al r5 r11", "al_r5_r11"},
195 {{al, r5, r12}, false, al, "al r5 r12", "al_r5_r12"},
196 {{al, r5, r13}, false, al, "al r5 r13", "al_r5_r13"},
197 {{al, r5, r14}, false, al, "al r5 r14", "al_r5_r14"},
198 {{al, r6, r0}, false, al, "al r6 r0", "al_r6_r0"},
199 {{al, r6, r1}, false, al, "al r6 r1", "al_r6_r1"},
200 {{al, r6, r2}, false, al, "al r6 r2", "al_r6_r2"},
201 {{al, r6, r3}, false, al, "al r6 r3", "al_r6_r3"},
202 {{al, r6, r4}, false, al, "al r6 r4", "al_r6_r4"},
203 {{al, r6, r5}, false, al, "al r6 r5", "al_r6_r5"},
204 {{al, r6, r6}, false, al, "al r6 r6", "al_r6_r6"},
205 {{al, r6, r7}, false, al, "al r6 r7", "al_r6_r7"},
206 {{al, r6, r8}, false, al, "al r6 r8", "al_r6_r8"},
207 {{al, r6, r9}, false, al, "al r6 r9", "al_r6_r9"},
208 {{al, r6, r10}, false, al, "al r6 r10", "al_r6_r10"},
209 {{al, r6, r11}, false, al, "al r6 r11", "al_r6_r11"},
210 {{al, r6, r12}, false, al, "al r6 r12", "al_r6_r12"},
211 {{al, r6, r13}, false, al, "al r6 r13", "al_r6_r13"},
212 {{al, r6, r14}, false, al, "al r6 r14", "al_r6_r14"},
213 {{al, r7, r0}, false, al, "al r7 r0", "al_r7_r0"},
214 {{al, r7, r1}, false, al, "al r7 r1", "al_r7_r1"},
215 {{al, r7, r2}, false, al, "al r7 r2", "al_r7_r2"},
216 {{al, r7, r3}, false, al, "al r7 r3", "al_r7_r3"},
217 {{al, r7, r4}, false, al, "al r7 r4", "al_r7_r4"},
218 {{al, r7, r5}, false, al, "al r7 r5", "al_r7_r5"},
219 {{al, r7, r6}, false, al, "al r7 r6", "al_r7_r6"},
220 {{al, r7, r7}, false, al, "al r7 r7", "al_r7_r7"},
221 {{al, r7, r8}, false, al, "al r7 r8", "al_r7_r8"},
222 {{al, r7, r9}, false, al, "al r7 r9", "al_r7_r9"},
223 {{al, r7, r10}, false, al, "al r7 r10", "al_r7_r10"},
224 {{al, r7, r11}, false, al, "al r7 r11", "al_r7_r11"},
225 {{al, r7, r12}, false, al, "al r7 r12", "al_r7_r12"},
226 {{al, r7, r13}, false, al, "al r7 r13", "al_r7_r13"},
227 {{al, r7, r14}, false, al, "al r7 r14", "al_r7_r14"},
228 {{al, r8, r0}, false, al, "al r8 r0", "al_r8_r0"},
229 {{al, r8, r1}, false, al, "al r8 r1", "al_r8_r1"},
230 {{al, r8, r2}, false, al, "al r8 r2", "al_r8_r2"},
231 {{al, r8, r3}, false, al, "al r8 r3", "al_r8_r3"},
232 {{al, r8, r4}, false, al, "al r8 r4", "al_r8_r4"},
233 {{al, r8, r5}, false, al, "al r8 r5", "al_r8_r5"},
234 {{al, r8, r6}, false, al, "al r8 r6", "al_r8_r6"},
235 {{al, r8, r7}, false, al, "al r8 r7", "al_r8_r7"},
236 {{al, r8, r8}, false, al, "al r8 r8", "al_r8_r8"},
237 {{al, r8, r9}, false, al, "al r8 r9", "al_r8_r9"},
238 {{al, r8, r10}, false, al, "al r8 r10", "al_r8_r10"},
239 {{al, r8, r11}, false, al, "al r8 r11", "al_r8_r11"},
240 {{al, r8, r12}, false, al, "al r8 r12", "al_r8_r12"},
241 {{al, r8, r13}, false, al, "al r8 r13", "al_r8_r13"},
242 {{al, r8, r14}, false, al, "al r8 r14", "al_r8_r14"},
243 {{al, r9, r0}, false, al, "al r9 r0", "al_r9_r0"},
244 {{al, r9, r1}, false, al, "al r9 r1", "al_r9_r1"},
245 {{al, r9, r2}, false, al, "al r9 r2", "al_r9_r2"},
246 {{al, r9, r3}, false, al, "al r9 r3", "al_r9_r3"},
247 {{al, r9, r4}, false, al, "al r9 r4", "al_r9_r4"},
248 {{al, r9, r5}, false, al, "al r9 r5", "al_r9_r5"},
249 {{al, r9, r6}, false, al, "al r9 r6", "al_r9_r6"},
250 {{al, r9, r7}, false, al, "al r9 r7", "al_r9_r7"},
251 {{al, r9, r8}, false, al, "al r9 r8", "al_r9_r8"},
252 {{al, r9, r9}, false, al, "al r9 r9", "al_r9_r9"},
253 {{al, r9, r10}, false, al, "al r9 r10", "al_r9_r10"},
254 {{al, r9, r11}, false, al, "al r9 r11", "al_r9_r11"},
255 {{al, r9, r12}, false, al, "al r9 r12", "al_r9_r12"},
256 {{al, r9, r13}, false, al, "al r9 r13", "al_r9_r13"},
257 {{al, r9, r14}, false, al, "al r9 r14", "al_r9_r14"},
258 {{al, r10, r0}, false, al, "al r10 r0", "al_r10_r0"},
259 {{al, r10, r1}, false, al, "al r10 r1", "al_r10_r1"},
260 {{al, r10, r2}, false, al, "al r10 r2", "al_r10_r2"},
261 {{al, r10, r3}, false, al, "al r10 r3", "al_r10_r3"},
262 {{al, r10, r4}, false, al, "al r10 r4", "al_r10_r4"},
263 {{al, r10, r5}, false, al, "al r10 r5", "al_r10_r5"},
264 {{al, r10, r6}, false, al, "al r10 r6", "al_r10_r6"},
265 {{al, r10, r7}, false, al, "al r10 r7", "al_r10_r7"},
266 {{al, r10, r8}, false, al, "al r10 r8", "al_r10_r8"},
267 {{al, r10, r9}, false, al, "al r10 r9", "al_r10_r9"},
268 {{al, r10, r10}, false, al, "al r10 r10", "al_r10_r10"},
269 {{al, r10, r11}, false, al, "al r10 r11", "al_r10_r11"},
270 {{al, r10, r12}, false, al, "al r10 r12", "al_r10_r12"},
271 {{al, r10, r13}, false, al, "al r10 r13", "al_r10_r13"},
272 {{al, r10, r14}, false, al, "al r10 r14", "al_r10_r14"},
273 {{al, r11, r0}, false, al, "al r11 r0", "al_r11_r0"},
274 {{al, r11, r1}, false, al, "al r11 r1", "al_r11_r1"},
275 {{al, r11, r2}, false, al, "al r11 r2", "al_r11_r2"},
276 {{al, r11, r3}, false, al, "al r11 r3", "al_r11_r3"},
277 {{al, r11, r4}, false, al, "al r11 r4", "al_r11_r4"},
278 {{al, r11, r5}, false, al, "al r11 r5", "al_r11_r5"},
279 {{al, r11, r6}, false, al, "al r11 r6", "al_r11_r6"},
280 {{al, r11, r7}, false, al, "al r11 r7", "al_r11_r7"},
281 {{al, r11, r8}, false, al, "al r11 r8", "al_r11_r8"},
282 {{al, r11, r9}, false, al, "al r11 r9", "al_r11_r9"},
283 {{al, r11, r10}, false, al, "al r11 r10", "al_r11_r10"},
284 {{al, r11, r11}, false, al, "al r11 r11", "al_r11_r11"},
285 {{al, r11, r12}, false, al, "al r11 r12", "al_r11_r12"},
286 {{al, r11, r13}, false, al, "al r11 r13", "al_r11_r13"},
287 {{al, r11, r14}, false, al, "al r11 r14", "al_r11_r14"},
288 {{al, r12, r0}, false, al, "al r12 r0", "al_r12_r0"},
289 {{al, r12, r1}, false, al, "al r12 r1", "al_r12_r1"},
290 {{al, r12, r2}, false, al, "al r12 r2", "al_r12_r2"},
291 {{al, r12, r3}, false, al, "al r12 r3", "al_r12_r3"},
292 {{al, r12, r4}, false, al, "al r12 r4", "al_r12_r4"},
293 {{al, r12, r5}, false, al, "al r12 r5", "al_r12_r5"},
294 {{al, r12, r6}, false, al, "al r12 r6", "al_r12_r6"},
295 {{al, r12, r7}, false, al, "al r12 r7", "al_r12_r7"},
296 {{al, r12, r8}, false, al, "al r12 r8", "al_r12_r8"},
297 {{al, r12, r9}, false, al, "al r12 r9", "al_r12_r9"},
298 {{al, r12, r10}, false, al, "al r12 r10", "al_r12_r10"},
299 {{al, r12, r11}, false, al, "al r12 r11", "al_r12_r11"},
300 {{al, r12, r12}, false, al, "al r12 r12", "al_r12_r12"},
301 {{al, r12, r13}, false, al, "al r12 r13", "al_r12_r13"},
302 {{al, r12, r14}, false, al, "al r12 r14", "al_r12_r14"},
303 {{al, r13, r0}, false, al, "al r13 r0", "al_r13_r0"},
304 {{al, r13, r1}, false, al, "al r13 r1", "al_r13_r1"},
305 {{al, r13, r2}, false, al, "al r13 r2", "al_r13_r2"},
306 {{al, r13, r3}, false, al, "al r13 r3", "al_r13_r3"},
307 {{al, r13, r4}, false, al, "al r13 r4", "al_r13_r4"},
308 {{al, r13, r5}, false, al, "al r13 r5", "al_r13_r5"},
309 {{al, r13, r6}, false, al, "al r13 r6", "al_r13_r6"},
310 {{al, r13, r7}, false, al, "al r13 r7", "al_r13_r7"},
311 {{al, r13, r8}, false, al, "al r13 r8", "al_r13_r8"},
312 {{al, r13, r9}, false, al, "al r13 r9", "al_r13_r9"},
313 {{al, r13, r10}, false, al, "al r13 r10", "al_r13_r10"},
314 {{al, r13, r11}, false, al, "al r13 r11", "al_r13_r11"},
315 {{al, r13, r12}, false, al, "al r13 r12", "al_r13_r12"},
316 {{al, r13, r13}, false, al, "al r13 r13", "al_r13_r13"},
317 {{al, r13, r14}, false, al, "al r13 r14", "al_r13_r14"},
318 {{al, r14, r0}, false, al, "al r14 r0", "al_r14_r0"},
319 {{al, r14, r1}, false, al, "al r14 r1", "al_r14_r1"},
320 {{al, r14, r2}, false, al, "al r14 r2", "al_r14_r2"},
321 {{al, r14, r3}, false, al, "al r14 r3", "al_r14_r3"},
322 {{al, r14, r4}, false, al, "al r14 r4", "al_r14_r4"},
323 {{al, r14, r5}, false, al, "al r14 r5", "al_r14_r5"},
324 {{al, r14, r6}, false, al, "al r14 r6", "al_r14_r6"},
325 {{al, r14, r7}, false, al, "al r14 r7", "al_r14_r7"},
326 {{al, r14, r8}, false, al, "al r14 r8", "al_r14_r8"},
327 {{al, r14, r9}, false, al, "al r14 r9", "al_r14_r9"},
328 {{al, r14, r10}, false, al, "al r14 r10", "al_r14_r10"},
329 {{al, r14, r11}, false, al, "al r14 r11", "al_r14_r11"},
330 {{al, r14, r12}, false, al, "al r14 r12", "al_r14_r12"},
331 {{al, r14, r13}, false, al, "al r14 r13", "al_r14_r13"},
332 {{al, r14, r14}, false, al, "al r14 r14", "al_r14_r14"}};
333
334 // These headers each contain an array of `TestResult` with the reference output
335 // values. The reference arrays are names `kReference{mnemonic}`.
336 #include "aarch32/traces/assembler-cond-rd-operand-rn-t32-cmn.h"
337 #include "aarch32/traces/assembler-cond-rd-operand-rn-t32-cmp.h"
338 #include "aarch32/traces/assembler-cond-rd-operand-rn-t32-mov.h"
339 #include "aarch32/traces/assembler-cond-rd-operand-rn-t32-movs.h"
340 #include "aarch32/traces/assembler-cond-rd-operand-rn-t32-mvn.h"
341 #include "aarch32/traces/assembler-cond-rd-operand-rn-t32-mvns.h"
342 #include "aarch32/traces/assembler-cond-rd-operand-rn-t32-teq.h"
343 #include "aarch32/traces/assembler-cond-rd-operand-rn-t32-tst.h"
344 #include "aarch32/traces/assembler-cond-rd-operand-rn-t32-sxtb.h"
345 #include "aarch32/traces/assembler-cond-rd-operand-rn-t32-sxtb16.h"
346 #include "aarch32/traces/assembler-cond-rd-operand-rn-t32-sxth.h"
347 #include "aarch32/traces/assembler-cond-rd-operand-rn-t32-uxtb.h"
348 #include "aarch32/traces/assembler-cond-rd-operand-rn-t32-uxtb16.h"
349 #include "aarch32/traces/assembler-cond-rd-operand-rn-t32-uxth.h"
350
351
352 // The maximum number of errors to report in detail for each test.
353 const unsigned kErrorReportLimit = 8;
354
355 typedef void (MacroAssembler::*Fn)(Condition cond,
356 Register rd,
357 const Operand& op);
358
TestHelper(Fn instruction,const char * mnemonic,const TestResult reference[])359 void TestHelper(Fn instruction,
360 const char* mnemonic,
361 const TestResult reference[]) {
362 unsigned total_error_count = 0;
363 MacroAssembler masm(BUF_SIZE);
364
365 masm.UseT32();
366
367 for (unsigned i = 0; i < ARRAY_SIZE(kTests); i++) {
368 // Values to pass to the macro-assembler.
369 Condition cond = kTests[i].operands.cond;
370 Register rd = kTests[i].operands.rd;
371 Register rn = kTests[i].operands.rn;
372 Operand op(rn);
373
374 int32_t start = masm.GetCursorOffset();
375 {
376 // We never generate more that 4 bytes, as IT instructions are only
377 // allowed for narrow encodings.
378 ExactAssemblyScope scope(&masm, 4, ExactAssemblyScope::kMaximumSize);
379 if (kTests[i].in_it_block) {
380 masm.it(kTests[i].it_condition);
381 }
382 (masm.*instruction)(cond, rd, op);
383 }
384 int32_t end = masm.GetCursorOffset();
385
386 const byte* result_ptr =
387 masm.GetBuffer()->GetOffsetAddress<const byte*>(start);
388 VIXL_ASSERT(start < end);
389 uint32_t result_size = end - start;
390
391 if (Test::generate_test_trace()) {
392 // Print the result bytes.
393 printf("const byte kInstruction_%s_%s[] = {\n",
394 mnemonic,
395 kTests[i].identifier);
396 for (uint32_t j = 0; j < result_size; j++) {
397 if (j == 0) {
398 printf(" 0x%02" PRIx8, result_ptr[j]);
399 } else {
400 printf(", 0x%02" PRIx8, result_ptr[j]);
401 }
402 }
403 // This comment is meant to be used by external tools to validate
404 // the encoding. We can parse the comment to figure out what
405 // instruction this corresponds to.
406 if (kTests[i].in_it_block) {
407 printf(" // It %s; %s %s\n};\n",
408 kTests[i].it_condition.GetName(),
409 mnemonic,
410 kTests[i].operands_description);
411 } else {
412 printf(" // %s %s\n};\n", mnemonic, kTests[i].operands_description);
413 }
414 } else {
415 // Check we've emitted the exact same encoding as present in the
416 // trace file. Only print up to `kErrorReportLimit` errors.
417 if (((result_size != reference[i].size) ||
418 (memcmp(result_ptr, reference[i].encoding, reference[i].size) !=
419 0)) &&
420 (++total_error_count <= kErrorReportLimit)) {
421 printf("Error when testing \"%s\" with operands \"%s\":\n",
422 mnemonic,
423 kTests[i].operands_description);
424 printf(" Expected: ");
425 for (uint32_t j = 0; j < reference[i].size; j++) {
426 if (j == 0) {
427 printf("0x%02" PRIx8, reference[i].encoding[j]);
428 } else {
429 printf(", 0x%02" PRIx8, reference[i].encoding[j]);
430 }
431 }
432 printf("\n");
433 printf(" Found: ");
434 for (uint32_t j = 0; j < result_size; j++) {
435 if (j == 0) {
436 printf("0x%02" PRIx8, result_ptr[j]);
437 } else {
438 printf(", 0x%02" PRIx8, result_ptr[j]);
439 }
440 }
441 printf("\n");
442 }
443 }
444 }
445
446 masm.FinalizeCode();
447
448 if (Test::generate_test_trace()) {
449 // Finalize the trace file by writing the final `TestResult` array
450 // which links all generated instruction encodings.
451 printf("const TestResult kReference%s[] = {\n", mnemonic);
452 for (unsigned i = 0; i < ARRAY_SIZE(kTests); i++) {
453 printf(" {\n");
454 printf(" ARRAY_SIZE(kInstruction_%s_%s),\n",
455 mnemonic,
456 kTests[i].identifier);
457 printf(" kInstruction_%s_%s,\n", mnemonic, kTests[i].identifier);
458 printf(" },\n");
459 }
460 printf("};\n");
461 } else {
462 if (total_error_count > kErrorReportLimit) {
463 printf("%u other errors follow.\n",
464 total_error_count - kErrorReportLimit);
465 }
466 // Crash if the test failed.
467 VIXL_CHECK(total_error_count == 0);
468 }
469 }
470
471 // Instantiate tests for each instruction in the list.
472 #define TEST(mnemonic) \
473 void Test_##mnemonic() { \
474 TestHelper(&MacroAssembler::mnemonic, #mnemonic, kReference##mnemonic); \
475 } \
476 Test test_##mnemonic("AARCH32_ASSEMBLER_COND_RD_OPERAND_RN_T32_" #mnemonic, \
477 &Test_##mnemonic);
478 FOREACH_INSTRUCTION(TEST)
479 #undef TEST
480
481 } // namespace
482 #endif
483
484 } // namespace aarch32
485 } // namespace vixl
486