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(clz) \
53 M(rbit) \
54 M(rev) \
55 M(rev16) \
56 M(revsh) \
57 M(rrx) \
58 M(rrxs)
59
60
61 // The following definitions are defined again in each generated test, therefore
62 // we need to place them in an anomymous namespace. It expresses that they are
63 // local to this file only, and the compiler is not allowed to share these types
64 // across test files during template instantiation. Specifically, `Operands` has
65 // various layouts across generated tests so it absolutely cannot be shared.
66
67 #ifdef VIXL_INCLUDE_TARGET_T32
68 namespace {
69
70 // Values to be passed to the assembler to produce the instruction under test.
71 struct Operands {
72 Condition cond;
73 Register rd;
74 Register rn;
75 };
76
77 // This structure contains all data needed to test one specific
78 // instruction.
79 struct TestData {
80 // The `operands` field represents what to pass to the assembler to
81 // produce the instruction.
82 Operands operands;
83 // True if we need to generate an IT instruction for this test to be valid.
84 bool in_it_block;
85 // The condition to give the IT instruction, this will be set to "al" by
86 // default.
87 Condition it_condition;
88 // Description of the operands, used for error reporting.
89 const char* operands_description;
90 // Unique identifier, used for generating traces.
91 const char* identifier;
92 };
93
94 struct TestResult {
95 size_t size;
96 const byte* encoding;
97 };
98
99 // Each element of this array produce one instruction encoding.
100 const TestData kTests[] =
101 {{{al, r0, r0}, false, al, "al r0 r0", "al_r0_r0"},
102 {{al, r0, r1}, false, al, "al r0 r1", "al_r0_r1"},
103 {{al, r0, r2}, false, al, "al r0 r2", "al_r0_r2"},
104 {{al, r0, r3}, false, al, "al r0 r3", "al_r0_r3"},
105 {{al, r0, r4}, false, al, "al r0 r4", "al_r0_r4"},
106 {{al, r0, r5}, false, al, "al r0 r5", "al_r0_r5"},
107 {{al, r0, r6}, false, al, "al r0 r6", "al_r0_r6"},
108 {{al, r0, r7}, false, al, "al r0 r7", "al_r0_r7"},
109 {{al, r0, r8}, false, al, "al r0 r8", "al_r0_r8"},
110 {{al, r0, r9}, false, al, "al r0 r9", "al_r0_r9"},
111 {{al, r0, r10}, false, al, "al r0 r10", "al_r0_r10"},
112 {{al, r0, r11}, false, al, "al r0 r11", "al_r0_r11"},
113 {{al, r0, r12}, false, al, "al r0 r12", "al_r0_r12"},
114 {{al, r0, r13}, false, al, "al r0 r13", "al_r0_r13"},
115 {{al, r0, r14}, false, al, "al r0 r14", "al_r0_r14"},
116 {{al, r1, r0}, false, al, "al r1 r0", "al_r1_r0"},
117 {{al, r1, r1}, false, al, "al r1 r1", "al_r1_r1"},
118 {{al, r1, r2}, false, al, "al r1 r2", "al_r1_r2"},
119 {{al, r1, r3}, false, al, "al r1 r3", "al_r1_r3"},
120 {{al, r1, r4}, false, al, "al r1 r4", "al_r1_r4"},
121 {{al, r1, r5}, false, al, "al r1 r5", "al_r1_r5"},
122 {{al, r1, r6}, false, al, "al r1 r6", "al_r1_r6"},
123 {{al, r1, r7}, false, al, "al r1 r7", "al_r1_r7"},
124 {{al, r1, r8}, false, al, "al r1 r8", "al_r1_r8"},
125 {{al, r1, r9}, false, al, "al r1 r9", "al_r1_r9"},
126 {{al, r1, r10}, false, al, "al r1 r10", "al_r1_r10"},
127 {{al, r1, r11}, false, al, "al r1 r11", "al_r1_r11"},
128 {{al, r1, r12}, false, al, "al r1 r12", "al_r1_r12"},
129 {{al, r1, r13}, false, al, "al r1 r13", "al_r1_r13"},
130 {{al, r1, r14}, false, al, "al r1 r14", "al_r1_r14"},
131 {{al, r2, r0}, false, al, "al r2 r0", "al_r2_r0"},
132 {{al, r2, r1}, false, al, "al r2 r1", "al_r2_r1"},
133 {{al, r2, r2}, false, al, "al r2 r2", "al_r2_r2"},
134 {{al, r2, r3}, false, al, "al r2 r3", "al_r2_r3"},
135 {{al, r2, r4}, false, al, "al r2 r4", "al_r2_r4"},
136 {{al, r2, r5}, false, al, "al r2 r5", "al_r2_r5"},
137 {{al, r2, r6}, false, al, "al r2 r6", "al_r2_r6"},
138 {{al, r2, r7}, false, al, "al r2 r7", "al_r2_r7"},
139 {{al, r2, r8}, false, al, "al r2 r8", "al_r2_r8"},
140 {{al, r2, r9}, false, al, "al r2 r9", "al_r2_r9"},
141 {{al, r2, r10}, false, al, "al r2 r10", "al_r2_r10"},
142 {{al, r2, r11}, false, al, "al r2 r11", "al_r2_r11"},
143 {{al, r2, r12}, false, al, "al r2 r12", "al_r2_r12"},
144 {{al, r2, r13}, false, al, "al r2 r13", "al_r2_r13"},
145 {{al, r2, r14}, false, al, "al r2 r14", "al_r2_r14"},
146 {{al, r3, r0}, false, al, "al r3 r0", "al_r3_r0"},
147 {{al, r3, r1}, false, al, "al r3 r1", "al_r3_r1"},
148 {{al, r3, r2}, false, al, "al r3 r2", "al_r3_r2"},
149 {{al, r3, r3}, false, al, "al r3 r3", "al_r3_r3"},
150 {{al, r3, r4}, false, al, "al r3 r4", "al_r3_r4"},
151 {{al, r3, r5}, false, al, "al r3 r5", "al_r3_r5"},
152 {{al, r3, r6}, false, al, "al r3 r6", "al_r3_r6"},
153 {{al, r3, r7}, false, al, "al r3 r7", "al_r3_r7"},
154 {{al, r3, r8}, false, al, "al r3 r8", "al_r3_r8"},
155 {{al, r3, r9}, false, al, "al r3 r9", "al_r3_r9"},
156 {{al, r3, r10}, false, al, "al r3 r10", "al_r3_r10"},
157 {{al, r3, r11}, false, al, "al r3 r11", "al_r3_r11"},
158 {{al, r3, r12}, false, al, "al r3 r12", "al_r3_r12"},
159 {{al, r3, r13}, false, al, "al r3 r13", "al_r3_r13"},
160 {{al, r3, r14}, false, al, "al r3 r14", "al_r3_r14"},
161 {{al, r4, r0}, false, al, "al r4 r0", "al_r4_r0"},
162 {{al, r4, r1}, false, al, "al r4 r1", "al_r4_r1"},
163 {{al, r4, r2}, false, al, "al r4 r2", "al_r4_r2"},
164 {{al, r4, r3}, false, al, "al r4 r3", "al_r4_r3"},
165 {{al, r4, r4}, false, al, "al r4 r4", "al_r4_r4"},
166 {{al, r4, r5}, false, al, "al r4 r5", "al_r4_r5"},
167 {{al, r4, r6}, false, al, "al r4 r6", "al_r4_r6"},
168 {{al, r4, r7}, false, al, "al r4 r7", "al_r4_r7"},
169 {{al, r4, r8}, false, al, "al r4 r8", "al_r4_r8"},
170 {{al, r4, r9}, false, al, "al r4 r9", "al_r4_r9"},
171 {{al, r4, r10}, false, al, "al r4 r10", "al_r4_r10"},
172 {{al, r4, r11}, false, al, "al r4 r11", "al_r4_r11"},
173 {{al, r4, r12}, false, al, "al r4 r12", "al_r4_r12"},
174 {{al, r4, r13}, false, al, "al r4 r13", "al_r4_r13"},
175 {{al, r4, r14}, false, al, "al r4 r14", "al_r4_r14"},
176 {{al, r5, r0}, false, al, "al r5 r0", "al_r5_r0"},
177 {{al, r5, r1}, false, al, "al r5 r1", "al_r5_r1"},
178 {{al, r5, r2}, false, al, "al r5 r2", "al_r5_r2"},
179 {{al, r5, r3}, false, al, "al r5 r3", "al_r5_r3"},
180 {{al, r5, r4}, false, al, "al r5 r4", "al_r5_r4"},
181 {{al, r5, r5}, false, al, "al r5 r5", "al_r5_r5"},
182 {{al, r5, r6}, false, al, "al r5 r6", "al_r5_r6"},
183 {{al, r5, r7}, false, al, "al r5 r7", "al_r5_r7"},
184 {{al, r5, r8}, false, al, "al r5 r8", "al_r5_r8"},
185 {{al, r5, r9}, false, al, "al r5 r9", "al_r5_r9"},
186 {{al, r5, r10}, false, al, "al r5 r10", "al_r5_r10"},
187 {{al, r5, r11}, false, al, "al r5 r11", "al_r5_r11"},
188 {{al, r5, r12}, false, al, "al r5 r12", "al_r5_r12"},
189 {{al, r5, r13}, false, al, "al r5 r13", "al_r5_r13"},
190 {{al, r5, r14}, false, al, "al r5 r14", "al_r5_r14"},
191 {{al, r6, r0}, false, al, "al r6 r0", "al_r6_r0"},
192 {{al, r6, r1}, false, al, "al r6 r1", "al_r6_r1"},
193 {{al, r6, r2}, false, al, "al r6 r2", "al_r6_r2"},
194 {{al, r6, r3}, false, al, "al r6 r3", "al_r6_r3"},
195 {{al, r6, r4}, false, al, "al r6 r4", "al_r6_r4"},
196 {{al, r6, r5}, false, al, "al r6 r5", "al_r6_r5"},
197 {{al, r6, r6}, false, al, "al r6 r6", "al_r6_r6"},
198 {{al, r6, r7}, false, al, "al r6 r7", "al_r6_r7"},
199 {{al, r6, r8}, false, al, "al r6 r8", "al_r6_r8"},
200 {{al, r6, r9}, false, al, "al r6 r9", "al_r6_r9"},
201 {{al, r6, r10}, false, al, "al r6 r10", "al_r6_r10"},
202 {{al, r6, r11}, false, al, "al r6 r11", "al_r6_r11"},
203 {{al, r6, r12}, false, al, "al r6 r12", "al_r6_r12"},
204 {{al, r6, r13}, false, al, "al r6 r13", "al_r6_r13"},
205 {{al, r6, r14}, false, al, "al r6 r14", "al_r6_r14"},
206 {{al, r7, r0}, false, al, "al r7 r0", "al_r7_r0"},
207 {{al, r7, r1}, false, al, "al r7 r1", "al_r7_r1"},
208 {{al, r7, r2}, false, al, "al r7 r2", "al_r7_r2"},
209 {{al, r7, r3}, false, al, "al r7 r3", "al_r7_r3"},
210 {{al, r7, r4}, false, al, "al r7 r4", "al_r7_r4"},
211 {{al, r7, r5}, false, al, "al r7 r5", "al_r7_r5"},
212 {{al, r7, r6}, false, al, "al r7 r6", "al_r7_r6"},
213 {{al, r7, r7}, false, al, "al r7 r7", "al_r7_r7"},
214 {{al, r7, r8}, false, al, "al r7 r8", "al_r7_r8"},
215 {{al, r7, r9}, false, al, "al r7 r9", "al_r7_r9"},
216 {{al, r7, r10}, false, al, "al r7 r10", "al_r7_r10"},
217 {{al, r7, r11}, false, al, "al r7 r11", "al_r7_r11"},
218 {{al, r7, r12}, false, al, "al r7 r12", "al_r7_r12"},
219 {{al, r7, r13}, false, al, "al r7 r13", "al_r7_r13"},
220 {{al, r7, r14}, false, al, "al r7 r14", "al_r7_r14"},
221 {{al, r8, r0}, false, al, "al r8 r0", "al_r8_r0"},
222 {{al, r8, r1}, false, al, "al r8 r1", "al_r8_r1"},
223 {{al, r8, r2}, false, al, "al r8 r2", "al_r8_r2"},
224 {{al, r8, r3}, false, al, "al r8 r3", "al_r8_r3"},
225 {{al, r8, r4}, false, al, "al r8 r4", "al_r8_r4"},
226 {{al, r8, r5}, false, al, "al r8 r5", "al_r8_r5"},
227 {{al, r8, r6}, false, al, "al r8 r6", "al_r8_r6"},
228 {{al, r8, r7}, false, al, "al r8 r7", "al_r8_r7"},
229 {{al, r8, r8}, false, al, "al r8 r8", "al_r8_r8"},
230 {{al, r8, r9}, false, al, "al r8 r9", "al_r8_r9"},
231 {{al, r8, r10}, false, al, "al r8 r10", "al_r8_r10"},
232 {{al, r8, r11}, false, al, "al r8 r11", "al_r8_r11"},
233 {{al, r8, r12}, false, al, "al r8 r12", "al_r8_r12"},
234 {{al, r8, r13}, false, al, "al r8 r13", "al_r8_r13"},
235 {{al, r8, r14}, false, al, "al r8 r14", "al_r8_r14"},
236 {{al, r9, r0}, false, al, "al r9 r0", "al_r9_r0"},
237 {{al, r9, r1}, false, al, "al r9 r1", "al_r9_r1"},
238 {{al, r9, r2}, false, al, "al r9 r2", "al_r9_r2"},
239 {{al, r9, r3}, false, al, "al r9 r3", "al_r9_r3"},
240 {{al, r9, r4}, false, al, "al r9 r4", "al_r9_r4"},
241 {{al, r9, r5}, false, al, "al r9 r5", "al_r9_r5"},
242 {{al, r9, r6}, false, al, "al r9 r6", "al_r9_r6"},
243 {{al, r9, r7}, false, al, "al r9 r7", "al_r9_r7"},
244 {{al, r9, r8}, false, al, "al r9 r8", "al_r9_r8"},
245 {{al, r9, r9}, false, al, "al r9 r9", "al_r9_r9"},
246 {{al, r9, r10}, false, al, "al r9 r10", "al_r9_r10"},
247 {{al, r9, r11}, false, al, "al r9 r11", "al_r9_r11"},
248 {{al, r9, r12}, false, al, "al r9 r12", "al_r9_r12"},
249 {{al, r9, r13}, false, al, "al r9 r13", "al_r9_r13"},
250 {{al, r9, r14}, false, al, "al r9 r14", "al_r9_r14"},
251 {{al, r10, r0}, false, al, "al r10 r0", "al_r10_r0"},
252 {{al, r10, r1}, false, al, "al r10 r1", "al_r10_r1"},
253 {{al, r10, r2}, false, al, "al r10 r2", "al_r10_r2"},
254 {{al, r10, r3}, false, al, "al r10 r3", "al_r10_r3"},
255 {{al, r10, r4}, false, al, "al r10 r4", "al_r10_r4"},
256 {{al, r10, r5}, false, al, "al r10 r5", "al_r10_r5"},
257 {{al, r10, r6}, false, al, "al r10 r6", "al_r10_r6"},
258 {{al, r10, r7}, false, al, "al r10 r7", "al_r10_r7"},
259 {{al, r10, r8}, false, al, "al r10 r8", "al_r10_r8"},
260 {{al, r10, r9}, false, al, "al r10 r9", "al_r10_r9"},
261 {{al, r10, r10}, false, al, "al r10 r10", "al_r10_r10"},
262 {{al, r10, r11}, false, al, "al r10 r11", "al_r10_r11"},
263 {{al, r10, r12}, false, al, "al r10 r12", "al_r10_r12"},
264 {{al, r10, r13}, false, al, "al r10 r13", "al_r10_r13"},
265 {{al, r10, r14}, false, al, "al r10 r14", "al_r10_r14"},
266 {{al, r11, r0}, false, al, "al r11 r0", "al_r11_r0"},
267 {{al, r11, r1}, false, al, "al r11 r1", "al_r11_r1"},
268 {{al, r11, r2}, false, al, "al r11 r2", "al_r11_r2"},
269 {{al, r11, r3}, false, al, "al r11 r3", "al_r11_r3"},
270 {{al, r11, r4}, false, al, "al r11 r4", "al_r11_r4"},
271 {{al, r11, r5}, false, al, "al r11 r5", "al_r11_r5"},
272 {{al, r11, r6}, false, al, "al r11 r6", "al_r11_r6"},
273 {{al, r11, r7}, false, al, "al r11 r7", "al_r11_r7"},
274 {{al, r11, r8}, false, al, "al r11 r8", "al_r11_r8"},
275 {{al, r11, r9}, false, al, "al r11 r9", "al_r11_r9"},
276 {{al, r11, r10}, false, al, "al r11 r10", "al_r11_r10"},
277 {{al, r11, r11}, false, al, "al r11 r11", "al_r11_r11"},
278 {{al, r11, r12}, false, al, "al r11 r12", "al_r11_r12"},
279 {{al, r11, r13}, false, al, "al r11 r13", "al_r11_r13"},
280 {{al, r11, r14}, false, al, "al r11 r14", "al_r11_r14"},
281 {{al, r12, r0}, false, al, "al r12 r0", "al_r12_r0"},
282 {{al, r12, r1}, false, al, "al r12 r1", "al_r12_r1"},
283 {{al, r12, r2}, false, al, "al r12 r2", "al_r12_r2"},
284 {{al, r12, r3}, false, al, "al r12 r3", "al_r12_r3"},
285 {{al, r12, r4}, false, al, "al r12 r4", "al_r12_r4"},
286 {{al, r12, r5}, false, al, "al r12 r5", "al_r12_r5"},
287 {{al, r12, r6}, false, al, "al r12 r6", "al_r12_r6"},
288 {{al, r12, r7}, false, al, "al r12 r7", "al_r12_r7"},
289 {{al, r12, r8}, false, al, "al r12 r8", "al_r12_r8"},
290 {{al, r12, r9}, false, al, "al r12 r9", "al_r12_r9"},
291 {{al, r12, r10}, false, al, "al r12 r10", "al_r12_r10"},
292 {{al, r12, r11}, false, al, "al r12 r11", "al_r12_r11"},
293 {{al, r12, r12}, false, al, "al r12 r12", "al_r12_r12"},
294 {{al, r12, r13}, false, al, "al r12 r13", "al_r12_r13"},
295 {{al, r12, r14}, false, al, "al r12 r14", "al_r12_r14"},
296 {{al, r13, r0}, false, al, "al r13 r0", "al_r13_r0"},
297 {{al, r13, r1}, false, al, "al r13 r1", "al_r13_r1"},
298 {{al, r13, r2}, false, al, "al r13 r2", "al_r13_r2"},
299 {{al, r13, r3}, false, al, "al r13 r3", "al_r13_r3"},
300 {{al, r13, r4}, false, al, "al r13 r4", "al_r13_r4"},
301 {{al, r13, r5}, false, al, "al r13 r5", "al_r13_r5"},
302 {{al, r13, r6}, false, al, "al r13 r6", "al_r13_r6"},
303 {{al, r13, r7}, false, al, "al r13 r7", "al_r13_r7"},
304 {{al, r13, r8}, false, al, "al r13 r8", "al_r13_r8"},
305 {{al, r13, r9}, false, al, "al r13 r9", "al_r13_r9"},
306 {{al, r13, r10}, false, al, "al r13 r10", "al_r13_r10"},
307 {{al, r13, r11}, false, al, "al r13 r11", "al_r13_r11"},
308 {{al, r13, r12}, false, al, "al r13 r12", "al_r13_r12"},
309 {{al, r13, r13}, false, al, "al r13 r13", "al_r13_r13"},
310 {{al, r13, r14}, false, al, "al r13 r14", "al_r13_r14"},
311 {{al, r14, r0}, false, al, "al r14 r0", "al_r14_r0"},
312 {{al, r14, r1}, false, al, "al r14 r1", "al_r14_r1"},
313 {{al, r14, r2}, false, al, "al r14 r2", "al_r14_r2"},
314 {{al, r14, r3}, false, al, "al r14 r3", "al_r14_r3"},
315 {{al, r14, r4}, false, al, "al r14 r4", "al_r14_r4"},
316 {{al, r14, r5}, false, al, "al r14 r5", "al_r14_r5"},
317 {{al, r14, r6}, false, al, "al r14 r6", "al_r14_r6"},
318 {{al, r14, r7}, false, al, "al r14 r7", "al_r14_r7"},
319 {{al, r14, r8}, false, al, "al r14 r8", "al_r14_r8"},
320 {{al, r14, r9}, false, al, "al r14 r9", "al_r14_r9"},
321 {{al, r14, r10}, false, al, "al r14 r10", "al_r14_r10"},
322 {{al, r14, r11}, false, al, "al r14 r11", "al_r14_r11"},
323 {{al, r14, r12}, false, al, "al r14 r12", "al_r14_r12"},
324 {{al, r14, r13}, false, al, "al r14 r13", "al_r14_r13"},
325 {{al, r14, r14}, false, al, "al r14 r14", "al_r14_r14"}};
326
327 // These headers each contain an array of `TestResult` with the reference output
328 // values. The reference arrays are names `kReference{mnemonic}`.
329 #include "aarch32/traces/assembler-cond-rd-rn-clz-t32.h"
330 #include "aarch32/traces/assembler-cond-rd-rn-rbit-t32.h"
331 #include "aarch32/traces/assembler-cond-rd-rn-rev-t32.h"
332 #include "aarch32/traces/assembler-cond-rd-rn-rev16-t32.h"
333 #include "aarch32/traces/assembler-cond-rd-rn-revsh-t32.h"
334 #include "aarch32/traces/assembler-cond-rd-rn-rrx-t32.h"
335 #include "aarch32/traces/assembler-cond-rd-rn-rrxs-t32.h"
336
337
338 // The maximum number of errors to report in detail for each test.
339 const unsigned kErrorReportLimit = 8;
340
341 typedef void (MacroAssembler::*Fn)(Condition cond, Register rd, Register rn);
342
TestHelper(Fn instruction,const char * mnemonic,const TestResult reference[])343 void TestHelper(Fn instruction,
344 const char* mnemonic,
345 const TestResult reference[]) {
346 unsigned total_error_count = 0;
347 MacroAssembler masm(BUF_SIZE);
348
349 masm.UseT32();
350
351 for (unsigned i = 0; i < ARRAY_SIZE(kTests); i++) {
352 // Values to pass to the macro-assembler.
353 Condition cond = kTests[i].operands.cond;
354 Register rd = kTests[i].operands.rd;
355 Register rn = kTests[i].operands.rn;
356
357 int32_t start = masm.GetCursorOffset();
358 {
359 // We never generate more that 4 bytes, as IT instructions are only
360 // allowed for narrow encodings.
361 ExactAssemblyScope scope(&masm, 4, ExactAssemblyScope::kMaximumSize);
362 if (kTests[i].in_it_block) {
363 masm.it(kTests[i].it_condition);
364 }
365 (masm.*instruction)(cond, rd, rn);
366 }
367 int32_t end = masm.GetCursorOffset();
368
369 const byte* result_ptr =
370 masm.GetBuffer()->GetOffsetAddress<const byte*>(start);
371 VIXL_ASSERT(start < end);
372 uint32_t result_size = end - start;
373
374 if (Test::generate_test_trace()) {
375 // Print the result bytes.
376 printf("const byte kInstruction_%s_%s[] = {\n",
377 mnemonic,
378 kTests[i].identifier);
379 for (uint32_t j = 0; j < result_size; j++) {
380 if (j == 0) {
381 printf(" 0x%02" PRIx8, result_ptr[j]);
382 } else {
383 printf(", 0x%02" PRIx8, result_ptr[j]);
384 }
385 }
386 // This comment is meant to be used by external tools to validate
387 // the encoding. We can parse the comment to figure out what
388 // instruction this corresponds to.
389 if (kTests[i].in_it_block) {
390 printf(" // It %s; %s %s\n};\n",
391 kTests[i].it_condition.GetName(),
392 mnemonic,
393 kTests[i].operands_description);
394 } else {
395 printf(" // %s %s\n};\n", mnemonic, kTests[i].operands_description);
396 }
397 } else {
398 // Check we've emitted the exact same encoding as present in the
399 // trace file. Only print up to `kErrorReportLimit` errors.
400 if (((result_size != reference[i].size) ||
401 (memcmp(result_ptr, reference[i].encoding, reference[i].size) !=
402 0)) &&
403 (++total_error_count <= kErrorReportLimit)) {
404 printf("Error when testing \"%s\" with operands \"%s\":\n",
405 mnemonic,
406 kTests[i].operands_description);
407 printf(" Expected: ");
408 for (uint32_t j = 0; j < reference[i].size; j++) {
409 if (j == 0) {
410 printf("0x%02" PRIx8, reference[i].encoding[j]);
411 } else {
412 printf(", 0x%02" PRIx8, reference[i].encoding[j]);
413 }
414 }
415 printf("\n");
416 printf(" Found: ");
417 for (uint32_t j = 0; j < result_size; j++) {
418 if (j == 0) {
419 printf("0x%02" PRIx8, result_ptr[j]);
420 } else {
421 printf(", 0x%02" PRIx8, result_ptr[j]);
422 }
423 }
424 printf("\n");
425 }
426 }
427 }
428
429 masm.FinalizeCode();
430
431 if (Test::generate_test_trace()) {
432 // Finalize the trace file by writing the final `TestResult` array
433 // which links all generated instruction encodings.
434 printf("const TestResult kReference%s[] = {\n", mnemonic);
435 for (unsigned i = 0; i < ARRAY_SIZE(kTests); i++) {
436 printf(" {\n");
437 printf(" ARRAY_SIZE(kInstruction_%s_%s),\n",
438 mnemonic,
439 kTests[i].identifier);
440 printf(" kInstruction_%s_%s,\n", mnemonic, kTests[i].identifier);
441 printf(" },\n");
442 }
443 printf("};\n");
444 } else {
445 if (total_error_count > kErrorReportLimit) {
446 printf("%u other errors follow.\n",
447 total_error_count - kErrorReportLimit);
448 }
449 // Crash if the test failed.
450 VIXL_CHECK(total_error_count == 0);
451 }
452 }
453
454 // Instantiate tests for each instruction in the list.
455 #define TEST(mnemonic) \
456 void Test_##mnemonic() { \
457 TestHelper(&MacroAssembler::mnemonic, #mnemonic, kReference##mnemonic); \
458 } \
459 Test test_##mnemonic("AARCH32_ASSEMBLER_COND_RD_RN_" #mnemonic "_T32", \
460 &Test_##mnemonic);
461 FOREACH_INSTRUCTION(TEST)
462 #undef TEST
463
464 } // namespace
465 #endif
466
467 } // namespace aarch32
468 } // namespace vixl
469