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
47namespace vixl {
48namespace aarch32 {
49
50// List of instruction mnemonics.
51#define FOREACH_INSTRUCTION(M) M(add)
52
53
54// The following definitions are defined again in each generated test, therefore
55// we need to place them in an anomymous namespace. It expresses that they are
56// local to this file only, and the compiler is not allowed to share these types
57// across test files during template instantiation. Specifically, `Operands` has
58// various layouts across generated tests so it absolutely cannot be shared.
59
60#ifdef VIXL_INCLUDE_TARGET_T32
61namespace {
62
63// Values to be passed to the assembler to produce the instruction under test.
64struct Operands {
65  Condition cond;
66  Register rd;
67  Register rn;
68  Register rm;
69};
70
71// This structure contains all data needed to test one specific
72// instruction.
73struct TestData {
74  // The `operands` field represents what to pass to the assembler to
75  // produce the instruction.
76  Operands operands;
77  // True if we need to generate an IT instruction for this test to be valid.
78  bool in_it_block;
79  // The condition to give the IT instruction, this will be set to "al" by
80  // default.
81  Condition it_condition;
82  // Description of the operands, used for error reporting.
83  const char* operands_description;
84  // Unique identifier, used for generating traces.
85  const char* identifier;
86};
87
88struct TestResult {
89  size_t size;
90  const byte* encoding;
91};
92
93// Each element of this array produce one instruction encoding.
94const TestData kTests[] =
95    {{{eq, r13, r13, r0}, true, eq, "eq r13 r13 r0", "eq_r13_r13_r0"},
96     {{eq, r13, r13, r1}, true, eq, "eq r13 r13 r1", "eq_r13_r13_r1"},
97     {{eq, r13, r13, r2}, true, eq, "eq r13 r13 r2", "eq_r13_r13_r2"},
98     {{eq, r13, r13, r3}, true, eq, "eq r13 r13 r3", "eq_r13_r13_r3"},
99     {{eq, r13, r13, r4}, true, eq, "eq r13 r13 r4", "eq_r13_r13_r4"},
100     {{eq, r13, r13, r5}, true, eq, "eq r13 r13 r5", "eq_r13_r13_r5"},
101     {{eq, r13, r13, r6}, true, eq, "eq r13 r13 r6", "eq_r13_r13_r6"},
102     {{eq, r13, r13, r7}, true, eq, "eq r13 r13 r7", "eq_r13_r13_r7"},
103     {{eq, r13, r13, r8}, true, eq, "eq r13 r13 r8", "eq_r13_r13_r8"},
104     {{eq, r13, r13, r9}, true, eq, "eq r13 r13 r9", "eq_r13_r13_r9"},
105     {{eq, r13, r13, r10}, true, eq, "eq r13 r13 r10", "eq_r13_r13_r10"},
106     {{eq, r13, r13, r11}, true, eq, "eq r13 r13 r11", "eq_r13_r13_r11"},
107     {{eq, r13, r13, r12}, true, eq, "eq r13 r13 r12", "eq_r13_r13_r12"},
108     {{eq, r13, r13, r13}, true, eq, "eq r13 r13 r13", "eq_r13_r13_r13"},
109     {{eq, r13, r13, r14}, true, eq, "eq r13 r13 r14", "eq_r13_r13_r14"},
110     {{ne, r13, r13, r0}, true, ne, "ne r13 r13 r0", "ne_r13_r13_r0"},
111     {{ne, r13, r13, r1}, true, ne, "ne r13 r13 r1", "ne_r13_r13_r1"},
112     {{ne, r13, r13, r2}, true, ne, "ne r13 r13 r2", "ne_r13_r13_r2"},
113     {{ne, r13, r13, r3}, true, ne, "ne r13 r13 r3", "ne_r13_r13_r3"},
114     {{ne, r13, r13, r4}, true, ne, "ne r13 r13 r4", "ne_r13_r13_r4"},
115     {{ne, r13, r13, r5}, true, ne, "ne r13 r13 r5", "ne_r13_r13_r5"},
116     {{ne, r13, r13, r6}, true, ne, "ne r13 r13 r6", "ne_r13_r13_r6"},
117     {{ne, r13, r13, r7}, true, ne, "ne r13 r13 r7", "ne_r13_r13_r7"},
118     {{ne, r13, r13, r8}, true, ne, "ne r13 r13 r8", "ne_r13_r13_r8"},
119     {{ne, r13, r13, r9}, true, ne, "ne r13 r13 r9", "ne_r13_r13_r9"},
120     {{ne, r13, r13, r10}, true, ne, "ne r13 r13 r10", "ne_r13_r13_r10"},
121     {{ne, r13, r13, r11}, true, ne, "ne r13 r13 r11", "ne_r13_r13_r11"},
122     {{ne, r13, r13, r12}, true, ne, "ne r13 r13 r12", "ne_r13_r13_r12"},
123     {{ne, r13, r13, r13}, true, ne, "ne r13 r13 r13", "ne_r13_r13_r13"},
124     {{ne, r13, r13, r14}, true, ne, "ne r13 r13 r14", "ne_r13_r13_r14"},
125     {{cs, r13, r13, r0}, true, cs, "cs r13 r13 r0", "cs_r13_r13_r0"},
126     {{cs, r13, r13, r1}, true, cs, "cs r13 r13 r1", "cs_r13_r13_r1"},
127     {{cs, r13, r13, r2}, true, cs, "cs r13 r13 r2", "cs_r13_r13_r2"},
128     {{cs, r13, r13, r3}, true, cs, "cs r13 r13 r3", "cs_r13_r13_r3"},
129     {{cs, r13, r13, r4}, true, cs, "cs r13 r13 r4", "cs_r13_r13_r4"},
130     {{cs, r13, r13, r5}, true, cs, "cs r13 r13 r5", "cs_r13_r13_r5"},
131     {{cs, r13, r13, r6}, true, cs, "cs r13 r13 r6", "cs_r13_r13_r6"},
132     {{cs, r13, r13, r7}, true, cs, "cs r13 r13 r7", "cs_r13_r13_r7"},
133     {{cs, r13, r13, r8}, true, cs, "cs r13 r13 r8", "cs_r13_r13_r8"},
134     {{cs, r13, r13, r9}, true, cs, "cs r13 r13 r9", "cs_r13_r13_r9"},
135     {{cs, r13, r13, r10}, true, cs, "cs r13 r13 r10", "cs_r13_r13_r10"},
136     {{cs, r13, r13, r11}, true, cs, "cs r13 r13 r11", "cs_r13_r13_r11"},
137     {{cs, r13, r13, r12}, true, cs, "cs r13 r13 r12", "cs_r13_r13_r12"},
138     {{cs, r13, r13, r13}, true, cs, "cs r13 r13 r13", "cs_r13_r13_r13"},
139     {{cs, r13, r13, r14}, true, cs, "cs r13 r13 r14", "cs_r13_r13_r14"},
140     {{cc, r13, r13, r0}, true, cc, "cc r13 r13 r0", "cc_r13_r13_r0"},
141     {{cc, r13, r13, r1}, true, cc, "cc r13 r13 r1", "cc_r13_r13_r1"},
142     {{cc, r13, r13, r2}, true, cc, "cc r13 r13 r2", "cc_r13_r13_r2"},
143     {{cc, r13, r13, r3}, true, cc, "cc r13 r13 r3", "cc_r13_r13_r3"},
144     {{cc, r13, r13, r4}, true, cc, "cc r13 r13 r4", "cc_r13_r13_r4"},
145     {{cc, r13, r13, r5}, true, cc, "cc r13 r13 r5", "cc_r13_r13_r5"},
146     {{cc, r13, r13, r6}, true, cc, "cc r13 r13 r6", "cc_r13_r13_r6"},
147     {{cc, r13, r13, r7}, true, cc, "cc r13 r13 r7", "cc_r13_r13_r7"},
148     {{cc, r13, r13, r8}, true, cc, "cc r13 r13 r8", "cc_r13_r13_r8"},
149     {{cc, r13, r13, r9}, true, cc, "cc r13 r13 r9", "cc_r13_r13_r9"},
150     {{cc, r13, r13, r10}, true, cc, "cc r13 r13 r10", "cc_r13_r13_r10"},
151     {{cc, r13, r13, r11}, true, cc, "cc r13 r13 r11", "cc_r13_r13_r11"},
152     {{cc, r13, r13, r12}, true, cc, "cc r13 r13 r12", "cc_r13_r13_r12"},
153     {{cc, r13, r13, r13}, true, cc, "cc r13 r13 r13", "cc_r13_r13_r13"},
154     {{cc, r13, r13, r14}, true, cc, "cc r13 r13 r14", "cc_r13_r13_r14"},
155     {{mi, r13, r13, r0}, true, mi, "mi r13 r13 r0", "mi_r13_r13_r0"},
156     {{mi, r13, r13, r1}, true, mi, "mi r13 r13 r1", "mi_r13_r13_r1"},
157     {{mi, r13, r13, r2}, true, mi, "mi r13 r13 r2", "mi_r13_r13_r2"},
158     {{mi, r13, r13, r3}, true, mi, "mi r13 r13 r3", "mi_r13_r13_r3"},
159     {{mi, r13, r13, r4}, true, mi, "mi r13 r13 r4", "mi_r13_r13_r4"},
160     {{mi, r13, r13, r5}, true, mi, "mi r13 r13 r5", "mi_r13_r13_r5"},
161     {{mi, r13, r13, r6}, true, mi, "mi r13 r13 r6", "mi_r13_r13_r6"},
162     {{mi, r13, r13, r7}, true, mi, "mi r13 r13 r7", "mi_r13_r13_r7"},
163     {{mi, r13, r13, r8}, true, mi, "mi r13 r13 r8", "mi_r13_r13_r8"},
164     {{mi, r13, r13, r9}, true, mi, "mi r13 r13 r9", "mi_r13_r13_r9"},
165     {{mi, r13, r13, r10}, true, mi, "mi r13 r13 r10", "mi_r13_r13_r10"},
166     {{mi, r13, r13, r11}, true, mi, "mi r13 r13 r11", "mi_r13_r13_r11"},
167     {{mi, r13, r13, r12}, true, mi, "mi r13 r13 r12", "mi_r13_r13_r12"},
168     {{mi, r13, r13, r13}, true, mi, "mi r13 r13 r13", "mi_r13_r13_r13"},
169     {{mi, r13, r13, r14}, true, mi, "mi r13 r13 r14", "mi_r13_r13_r14"},
170     {{pl, r13, r13, r0}, true, pl, "pl r13 r13 r0", "pl_r13_r13_r0"},
171     {{pl, r13, r13, r1}, true, pl, "pl r13 r13 r1", "pl_r13_r13_r1"},
172     {{pl, r13, r13, r2}, true, pl, "pl r13 r13 r2", "pl_r13_r13_r2"},
173     {{pl, r13, r13, r3}, true, pl, "pl r13 r13 r3", "pl_r13_r13_r3"},
174     {{pl, r13, r13, r4}, true, pl, "pl r13 r13 r4", "pl_r13_r13_r4"},
175     {{pl, r13, r13, r5}, true, pl, "pl r13 r13 r5", "pl_r13_r13_r5"},
176     {{pl, r13, r13, r6}, true, pl, "pl r13 r13 r6", "pl_r13_r13_r6"},
177     {{pl, r13, r13, r7}, true, pl, "pl r13 r13 r7", "pl_r13_r13_r7"},
178     {{pl, r13, r13, r8}, true, pl, "pl r13 r13 r8", "pl_r13_r13_r8"},
179     {{pl, r13, r13, r9}, true, pl, "pl r13 r13 r9", "pl_r13_r13_r9"},
180     {{pl, r13, r13, r10}, true, pl, "pl r13 r13 r10", "pl_r13_r13_r10"},
181     {{pl, r13, r13, r11}, true, pl, "pl r13 r13 r11", "pl_r13_r13_r11"},
182     {{pl, r13, r13, r12}, true, pl, "pl r13 r13 r12", "pl_r13_r13_r12"},
183     {{pl, r13, r13, r13}, true, pl, "pl r13 r13 r13", "pl_r13_r13_r13"},
184     {{pl, r13, r13, r14}, true, pl, "pl r13 r13 r14", "pl_r13_r13_r14"},
185     {{vs, r13, r13, r0}, true, vs, "vs r13 r13 r0", "vs_r13_r13_r0"},
186     {{vs, r13, r13, r1}, true, vs, "vs r13 r13 r1", "vs_r13_r13_r1"},
187     {{vs, r13, r13, r2}, true, vs, "vs r13 r13 r2", "vs_r13_r13_r2"},
188     {{vs, r13, r13, r3}, true, vs, "vs r13 r13 r3", "vs_r13_r13_r3"},
189     {{vs, r13, r13, r4}, true, vs, "vs r13 r13 r4", "vs_r13_r13_r4"},
190     {{vs, r13, r13, r5}, true, vs, "vs r13 r13 r5", "vs_r13_r13_r5"},
191     {{vs, r13, r13, r6}, true, vs, "vs r13 r13 r6", "vs_r13_r13_r6"},
192     {{vs, r13, r13, r7}, true, vs, "vs r13 r13 r7", "vs_r13_r13_r7"},
193     {{vs, r13, r13, r8}, true, vs, "vs r13 r13 r8", "vs_r13_r13_r8"},
194     {{vs, r13, r13, r9}, true, vs, "vs r13 r13 r9", "vs_r13_r13_r9"},
195     {{vs, r13, r13, r10}, true, vs, "vs r13 r13 r10", "vs_r13_r13_r10"},
196     {{vs, r13, r13, r11}, true, vs, "vs r13 r13 r11", "vs_r13_r13_r11"},
197     {{vs, r13, r13, r12}, true, vs, "vs r13 r13 r12", "vs_r13_r13_r12"},
198     {{vs, r13, r13, r13}, true, vs, "vs r13 r13 r13", "vs_r13_r13_r13"},
199     {{vs, r13, r13, r14}, true, vs, "vs r13 r13 r14", "vs_r13_r13_r14"},
200     {{vc, r13, r13, r0}, true, vc, "vc r13 r13 r0", "vc_r13_r13_r0"},
201     {{vc, r13, r13, r1}, true, vc, "vc r13 r13 r1", "vc_r13_r13_r1"},
202     {{vc, r13, r13, r2}, true, vc, "vc r13 r13 r2", "vc_r13_r13_r2"},
203     {{vc, r13, r13, r3}, true, vc, "vc r13 r13 r3", "vc_r13_r13_r3"},
204     {{vc, r13, r13, r4}, true, vc, "vc r13 r13 r4", "vc_r13_r13_r4"},
205     {{vc, r13, r13, r5}, true, vc, "vc r13 r13 r5", "vc_r13_r13_r5"},
206     {{vc, r13, r13, r6}, true, vc, "vc r13 r13 r6", "vc_r13_r13_r6"},
207     {{vc, r13, r13, r7}, true, vc, "vc r13 r13 r7", "vc_r13_r13_r7"},
208     {{vc, r13, r13, r8}, true, vc, "vc r13 r13 r8", "vc_r13_r13_r8"},
209     {{vc, r13, r13, r9}, true, vc, "vc r13 r13 r9", "vc_r13_r13_r9"},
210     {{vc, r13, r13, r10}, true, vc, "vc r13 r13 r10", "vc_r13_r13_r10"},
211     {{vc, r13, r13, r11}, true, vc, "vc r13 r13 r11", "vc_r13_r13_r11"},
212     {{vc, r13, r13, r12}, true, vc, "vc r13 r13 r12", "vc_r13_r13_r12"},
213     {{vc, r13, r13, r13}, true, vc, "vc r13 r13 r13", "vc_r13_r13_r13"},
214     {{vc, r13, r13, r14}, true, vc, "vc r13 r13 r14", "vc_r13_r13_r14"},
215     {{hi, r13, r13, r0}, true, hi, "hi r13 r13 r0", "hi_r13_r13_r0"},
216     {{hi, r13, r13, r1}, true, hi, "hi r13 r13 r1", "hi_r13_r13_r1"},
217     {{hi, r13, r13, r2}, true, hi, "hi r13 r13 r2", "hi_r13_r13_r2"},
218     {{hi, r13, r13, r3}, true, hi, "hi r13 r13 r3", "hi_r13_r13_r3"},
219     {{hi, r13, r13, r4}, true, hi, "hi r13 r13 r4", "hi_r13_r13_r4"},
220     {{hi, r13, r13, r5}, true, hi, "hi r13 r13 r5", "hi_r13_r13_r5"},
221     {{hi, r13, r13, r6}, true, hi, "hi r13 r13 r6", "hi_r13_r13_r6"},
222     {{hi, r13, r13, r7}, true, hi, "hi r13 r13 r7", "hi_r13_r13_r7"},
223     {{hi, r13, r13, r8}, true, hi, "hi r13 r13 r8", "hi_r13_r13_r8"},
224     {{hi, r13, r13, r9}, true, hi, "hi r13 r13 r9", "hi_r13_r13_r9"},
225     {{hi, r13, r13, r10}, true, hi, "hi r13 r13 r10", "hi_r13_r13_r10"},
226     {{hi, r13, r13, r11}, true, hi, "hi r13 r13 r11", "hi_r13_r13_r11"},
227     {{hi, r13, r13, r12}, true, hi, "hi r13 r13 r12", "hi_r13_r13_r12"},
228     {{hi, r13, r13, r13}, true, hi, "hi r13 r13 r13", "hi_r13_r13_r13"},
229     {{hi, r13, r13, r14}, true, hi, "hi r13 r13 r14", "hi_r13_r13_r14"},
230     {{ls, r13, r13, r0}, true, ls, "ls r13 r13 r0", "ls_r13_r13_r0"},
231     {{ls, r13, r13, r1}, true, ls, "ls r13 r13 r1", "ls_r13_r13_r1"},
232     {{ls, r13, r13, r2}, true, ls, "ls r13 r13 r2", "ls_r13_r13_r2"},
233     {{ls, r13, r13, r3}, true, ls, "ls r13 r13 r3", "ls_r13_r13_r3"},
234     {{ls, r13, r13, r4}, true, ls, "ls r13 r13 r4", "ls_r13_r13_r4"},
235     {{ls, r13, r13, r5}, true, ls, "ls r13 r13 r5", "ls_r13_r13_r5"},
236     {{ls, r13, r13, r6}, true, ls, "ls r13 r13 r6", "ls_r13_r13_r6"},
237     {{ls, r13, r13, r7}, true, ls, "ls r13 r13 r7", "ls_r13_r13_r7"},
238     {{ls, r13, r13, r8}, true, ls, "ls r13 r13 r8", "ls_r13_r13_r8"},
239     {{ls, r13, r13, r9}, true, ls, "ls r13 r13 r9", "ls_r13_r13_r9"},
240     {{ls, r13, r13, r10}, true, ls, "ls r13 r13 r10", "ls_r13_r13_r10"},
241     {{ls, r13, r13, r11}, true, ls, "ls r13 r13 r11", "ls_r13_r13_r11"},
242     {{ls, r13, r13, r12}, true, ls, "ls r13 r13 r12", "ls_r13_r13_r12"},
243     {{ls, r13, r13, r13}, true, ls, "ls r13 r13 r13", "ls_r13_r13_r13"},
244     {{ls, r13, r13, r14}, true, ls, "ls r13 r13 r14", "ls_r13_r13_r14"},
245     {{ge, r13, r13, r0}, true, ge, "ge r13 r13 r0", "ge_r13_r13_r0"},
246     {{ge, r13, r13, r1}, true, ge, "ge r13 r13 r1", "ge_r13_r13_r1"},
247     {{ge, r13, r13, r2}, true, ge, "ge r13 r13 r2", "ge_r13_r13_r2"},
248     {{ge, r13, r13, r3}, true, ge, "ge r13 r13 r3", "ge_r13_r13_r3"},
249     {{ge, r13, r13, r4}, true, ge, "ge r13 r13 r4", "ge_r13_r13_r4"},
250     {{ge, r13, r13, r5}, true, ge, "ge r13 r13 r5", "ge_r13_r13_r5"},
251     {{ge, r13, r13, r6}, true, ge, "ge r13 r13 r6", "ge_r13_r13_r6"},
252     {{ge, r13, r13, r7}, true, ge, "ge r13 r13 r7", "ge_r13_r13_r7"},
253     {{ge, r13, r13, r8}, true, ge, "ge r13 r13 r8", "ge_r13_r13_r8"},
254     {{ge, r13, r13, r9}, true, ge, "ge r13 r13 r9", "ge_r13_r13_r9"},
255     {{ge, r13, r13, r10}, true, ge, "ge r13 r13 r10", "ge_r13_r13_r10"},
256     {{ge, r13, r13, r11}, true, ge, "ge r13 r13 r11", "ge_r13_r13_r11"},
257     {{ge, r13, r13, r12}, true, ge, "ge r13 r13 r12", "ge_r13_r13_r12"},
258     {{ge, r13, r13, r13}, true, ge, "ge r13 r13 r13", "ge_r13_r13_r13"},
259     {{ge, r13, r13, r14}, true, ge, "ge r13 r13 r14", "ge_r13_r13_r14"},
260     {{lt, r13, r13, r0}, true, lt, "lt r13 r13 r0", "lt_r13_r13_r0"},
261     {{lt, r13, r13, r1}, true, lt, "lt r13 r13 r1", "lt_r13_r13_r1"},
262     {{lt, r13, r13, r2}, true, lt, "lt r13 r13 r2", "lt_r13_r13_r2"},
263     {{lt, r13, r13, r3}, true, lt, "lt r13 r13 r3", "lt_r13_r13_r3"},
264     {{lt, r13, r13, r4}, true, lt, "lt r13 r13 r4", "lt_r13_r13_r4"},
265     {{lt, r13, r13, r5}, true, lt, "lt r13 r13 r5", "lt_r13_r13_r5"},
266     {{lt, r13, r13, r6}, true, lt, "lt r13 r13 r6", "lt_r13_r13_r6"},
267     {{lt, r13, r13, r7}, true, lt, "lt r13 r13 r7", "lt_r13_r13_r7"},
268     {{lt, r13, r13, r8}, true, lt, "lt r13 r13 r8", "lt_r13_r13_r8"},
269     {{lt, r13, r13, r9}, true, lt, "lt r13 r13 r9", "lt_r13_r13_r9"},
270     {{lt, r13, r13, r10}, true, lt, "lt r13 r13 r10", "lt_r13_r13_r10"},
271     {{lt, r13, r13, r11}, true, lt, "lt r13 r13 r11", "lt_r13_r13_r11"},
272     {{lt, r13, r13, r12}, true, lt, "lt r13 r13 r12", "lt_r13_r13_r12"},
273     {{lt, r13, r13, r13}, true, lt, "lt r13 r13 r13", "lt_r13_r13_r13"},
274     {{lt, r13, r13, r14}, true, lt, "lt r13 r13 r14", "lt_r13_r13_r14"},
275     {{gt, r13, r13, r0}, true, gt, "gt r13 r13 r0", "gt_r13_r13_r0"},
276     {{gt, r13, r13, r1}, true, gt, "gt r13 r13 r1", "gt_r13_r13_r1"},
277     {{gt, r13, r13, r2}, true, gt, "gt r13 r13 r2", "gt_r13_r13_r2"},
278     {{gt, r13, r13, r3}, true, gt, "gt r13 r13 r3", "gt_r13_r13_r3"},
279     {{gt, r13, r13, r4}, true, gt, "gt r13 r13 r4", "gt_r13_r13_r4"},
280     {{gt, r13, r13, r5}, true, gt, "gt r13 r13 r5", "gt_r13_r13_r5"},
281     {{gt, r13, r13, r6}, true, gt, "gt r13 r13 r6", "gt_r13_r13_r6"},
282     {{gt, r13, r13, r7}, true, gt, "gt r13 r13 r7", "gt_r13_r13_r7"},
283     {{gt, r13, r13, r8}, true, gt, "gt r13 r13 r8", "gt_r13_r13_r8"},
284     {{gt, r13, r13, r9}, true, gt, "gt r13 r13 r9", "gt_r13_r13_r9"},
285     {{gt, r13, r13, r10}, true, gt, "gt r13 r13 r10", "gt_r13_r13_r10"},
286     {{gt, r13, r13, r11}, true, gt, "gt r13 r13 r11", "gt_r13_r13_r11"},
287     {{gt, r13, r13, r12}, true, gt, "gt r13 r13 r12", "gt_r13_r13_r12"},
288     {{gt, r13, r13, r13}, true, gt, "gt r13 r13 r13", "gt_r13_r13_r13"},
289     {{gt, r13, r13, r14}, true, gt, "gt r13 r13 r14", "gt_r13_r13_r14"},
290     {{le, r13, r13, r0}, true, le, "le r13 r13 r0", "le_r13_r13_r0"},
291     {{le, r13, r13, r1}, true, le, "le r13 r13 r1", "le_r13_r13_r1"},
292     {{le, r13, r13, r2}, true, le, "le r13 r13 r2", "le_r13_r13_r2"},
293     {{le, r13, r13, r3}, true, le, "le r13 r13 r3", "le_r13_r13_r3"},
294     {{le, r13, r13, r4}, true, le, "le r13 r13 r4", "le_r13_r13_r4"},
295     {{le, r13, r13, r5}, true, le, "le r13 r13 r5", "le_r13_r13_r5"},
296     {{le, r13, r13, r6}, true, le, "le r13 r13 r6", "le_r13_r13_r6"},
297     {{le, r13, r13, r7}, true, le, "le r13 r13 r7", "le_r13_r13_r7"},
298     {{le, r13, r13, r8}, true, le, "le r13 r13 r8", "le_r13_r13_r8"},
299     {{le, r13, r13, r9}, true, le, "le r13 r13 r9", "le_r13_r13_r9"},
300     {{le, r13, r13, r10}, true, le, "le r13 r13 r10", "le_r13_r13_r10"},
301     {{le, r13, r13, r11}, true, le, "le r13 r13 r11", "le_r13_r13_r11"},
302     {{le, r13, r13, r12}, true, le, "le r13 r13 r12", "le_r13_r13_r12"},
303     {{le, r13, r13, r13}, true, le, "le r13 r13 r13", "le_r13_r13_r13"},
304     {{le, r13, r13, r14}, true, le, "le r13 r13 r14", "le_r13_r13_r14"}};
305
306// These headers each contain an array of `TestResult` with the reference output
307// values. The reference arrays are names `kReference{mnemonic}`.
308#include "aarch32/traces/assembler-cond-rd-rn-operand-rm-rd-is-rn-is-sp-in-it-block-add-t32.h"
309
310
311// The maximum number of errors to report in detail for each test.
312const unsigned kErrorReportLimit = 8;
313
314typedef void (MacroAssembler::*Fn)(Condition cond,
315                                   Register rd,
316                                   Register rn,
317                                   const Operand& op);
318
319void TestHelper(Fn instruction,
320                const char* mnemonic,
321                const TestResult reference[]) {
322  unsigned total_error_count = 0;
323  MacroAssembler masm(BUF_SIZE);
324
325  masm.UseT32();
326
327  for (unsigned i = 0; i < ARRAY_SIZE(kTests); i++) {
328    // Values to pass to the macro-assembler.
329    Condition cond = kTests[i].operands.cond;
330    Register rd = kTests[i].operands.rd;
331    Register rn = kTests[i].operands.rn;
332    Register rm = kTests[i].operands.rm;
333    Operand op(rm);
334
335    int32_t start = masm.GetCursorOffset();
336    {
337      // We never generate more that 4 bytes, as IT instructions are only
338      // allowed for narrow encodings.
339      ExactAssemblyScope scope(&masm, 4, ExactAssemblyScope::kMaximumSize);
340      if (kTests[i].in_it_block) {
341        masm.it(kTests[i].it_condition);
342      }
343      (masm.*instruction)(cond, rd, rn, op);
344    }
345    int32_t end = masm.GetCursorOffset();
346
347    const byte* result_ptr =
348        masm.GetBuffer()->GetOffsetAddress<const byte*>(start);
349    VIXL_ASSERT(start < end);
350    uint32_t result_size = end - start;
351
352    if (Test::generate_test_trace()) {
353      // Print the result bytes.
354      printf("const byte kInstruction_%s_%s[] = {\n",
355             mnemonic,
356             kTests[i].identifier);
357      for (uint32_t j = 0; j < result_size; j++) {
358        if (j == 0) {
359          printf("  0x%02" PRIx8, result_ptr[j]);
360        } else {
361          printf(", 0x%02" PRIx8, result_ptr[j]);
362        }
363      }
364      // This comment is meant to be used by external tools to validate
365      // the encoding. We can parse the comment to figure out what
366      // instruction this corresponds to.
367      if (kTests[i].in_it_block) {
368        printf(" // It %s; %s %s\n};\n",
369               kTests[i].it_condition.GetName(),
370               mnemonic,
371               kTests[i].operands_description);
372      } else {
373        printf(" // %s %s\n};\n", mnemonic, kTests[i].operands_description);
374      }
375    } else {
376      // Check we've emitted the exact same encoding as present in the
377      // trace file. Only print up to `kErrorReportLimit` errors.
378      if (((result_size != reference[i].size) ||
379           (memcmp(result_ptr, reference[i].encoding, reference[i].size) !=
380            0)) &&
381          (++total_error_count <= kErrorReportLimit)) {
382        printf("Error when testing \"%s\" with operands \"%s\":\n",
383               mnemonic,
384               kTests[i].operands_description);
385        printf("  Expected: ");
386        for (uint32_t j = 0; j < reference[i].size; j++) {
387          if (j == 0) {
388            printf("0x%02" PRIx8, reference[i].encoding[j]);
389          } else {
390            printf(", 0x%02" PRIx8, reference[i].encoding[j]);
391          }
392        }
393        printf("\n");
394        printf("  Found:    ");
395        for (uint32_t j = 0; j < result_size; j++) {
396          if (j == 0) {
397            printf("0x%02" PRIx8, result_ptr[j]);
398          } else {
399            printf(", 0x%02" PRIx8, result_ptr[j]);
400          }
401        }
402        printf("\n");
403      }
404    }
405  }
406
407  masm.FinalizeCode();
408
409  if (Test::generate_test_trace()) {
410    // Finalize the trace file by writing the final `TestResult` array
411    // which links all generated instruction encodings.
412    printf("const TestResult kReference%s[] = {\n", mnemonic);
413    for (unsigned i = 0; i < ARRAY_SIZE(kTests); i++) {
414      printf("  {\n");
415      printf("    ARRAY_SIZE(kInstruction_%s_%s),\n",
416             mnemonic,
417             kTests[i].identifier);
418      printf("    kInstruction_%s_%s,\n", mnemonic, kTests[i].identifier);
419      printf("  },\n");
420    }
421    printf("};\n");
422  } else {
423    if (total_error_count > kErrorReportLimit) {
424      printf("%u other errors follow.\n",
425             total_error_count - kErrorReportLimit);
426    }
427    // Crash if the test failed.
428    VIXL_CHECK(total_error_count == 0);
429  }
430}
431
432// Instantiate tests for each instruction in the list.
433#define TEST(mnemonic)                                                      \
434  void Test_##mnemonic() {                                                  \
435    TestHelper(&MacroAssembler::mnemonic, #mnemonic, kReference##mnemonic); \
436  }                                                                         \
437  Test test_##mnemonic(                                                     \
438      "AARCH32_ASSEMBLER_COND_RD_RN_OPERAND_RM_RD_IS_RN_IS_SP_IN_IT_"       \
439      "BLOCK_" #mnemonic "_T32",                                            \
440      &Test_##mnemonic);
441FOREACH_INSTRUCTION(TEST)
442#undef TEST
443
444}  // namespace
445#endif
446
447}  // namespace aarch32
448}  // namespace vixl
449