test-simulator-cond-rd-rn-rm-t32-sel.cc revision 54fce717d9371fa2e8fc46e1d811bdb4ab74f279
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// This file is auto generated from the
29// test/aarch32/config/template-simulator-aarch32.cc.in template file using
30// tools/generate_tests.py.
31//
32// PLEASE DO NOT EDIT.
33// -----------------------------------------------------------------------------
34
35#include "test-runner.h"
36
37#include "test-utils.h"
38#include "test-utils-aarch32.h"
39
40#include "aarch32/assembler-aarch32.h"
41#include "aarch32/macro-assembler-aarch32.h"
42#include "aarch32/disasm-aarch32.h"
43
44#define __ masm.
45#define BUF_SIZE (4096)
46
47#ifdef VIXL_INCLUDE_SIMULATOR
48// Run tests with the simulator.
49
50#define SETUP() MacroAssembler masm(BUF_SIZE)
51
52#define START() masm.GetBuffer().Reset()
53
54#define END() \
55  __ Hlt(0);  \
56  __ FinalizeCode();
57
58// TODO: Run the tests in the simulator.
59#define RUN()
60
61#define TEARDOWN()
62
63#else  // ifdef VIXL_INCLUDE_SIMULATOR.
64
65#define SETUP() MacroAssembler masm(BUF_SIZE);
66
67#define START()             \
68  masm.GetBuffer().Reset(); \
69  __ Push(r4);              \
70  __ Push(r5);              \
71  __ Push(r6);              \
72  __ Push(r7);              \
73  __ Push(r8);              \
74  __ Push(r9);              \
75  __ Push(r10);             \
76  __ Push(r11);             \
77  __ Push(r12);             \
78  __ Push(lr)
79
80#define END()  \
81  __ Pop(lr);  \
82  __ Pop(r12); \
83  __ Pop(r11); \
84  __ Pop(r10); \
85  __ Pop(r9);  \
86  __ Pop(r8);  \
87  __ Pop(r7);  \
88  __ Pop(r6);  \
89  __ Pop(r5);  \
90  __ Pop(r4);  \
91  __ Bx(lr);   \
92  __ FinalizeCode();
93
94// Copy the generated code into a memory area garanteed to be executable before
95// executing it.
96#define RUN()                                                  \
97  {                                                            \
98    ExecutableMemory code(masm.GetBuffer().GetCursorOffset()); \
99    code.Write(masm.GetBuffer().GetOffsetAddress<byte*>(0),    \
100               masm.GetBuffer().GetCursorOffset());            \
101    int pcs_offset = masm.IsT32() ? 1 : 0;                     \
102    code.Execute(pcs_offset);                                  \
103  }
104
105#define TEARDOWN()
106
107#endif  // ifdef VIXL_INCLUDE_SIMULATOR
108
109namespace vixl {
110namespace aarch32 {
111
112// List of instruction encodings:
113#define FOREACH_INSTRUCTION(M) M(Sel)
114
115// Values to be passed to the assembler to produce the instruction under test.
116struct Operands {
117  Condition cond;
118  Register rd;
119  Register rn;
120  Register rm;
121};
122
123// Input data to feed to the instruction.
124struct Inputs {
125  uint32_t apsr;
126  uint32_t qbit;
127  uint32_t ge;
128  uint32_t rd;
129  uint32_t rn;
130  uint32_t rm;
131};
132
133// This structure contains all input data needed to test one specific encoding.
134// It used to generate a loop over an instruction.
135struct TestLoopData {
136  // The `operands` fields represents the values to pass to the assembler to
137  // produce the instruction.
138  Operands operands;
139  // Description of the operands, used for error reporting.
140  const char* operands_description;
141  // Unique identifier, used for generating traces.
142  const char* identifier;
143  // Array of values to be fed to the instruction.
144  size_t input_size;
145  const Inputs* inputs;
146};
147
148static const Inputs kGE[] = {
149    {NoFlag, NoFlag, GE123Flag, 0xabababab, 0xfffffffe, 0x0000007e},
150    {NoFlag, NoFlag, GE23Flag, 0xabababab, 0x7fffffff, 0xffffff82},
151    {NoFlag, NoFlag, GE123Flag, 0xabababab, 0x7ffffffe, 0xffffff81},
152    {NoFlag, NoFlag, GE13Flag, 0xabababab, 0x7fffffff, 0x0000007d},
153    {NoFlag, NoFlag, NoFlag, 0xabababab, 0xffffffe0, 0xffff8003},
154    {NoFlag, NoFlag, GE13Flag, 0xabababab, 0x00007ffe, 0xffffff83},
155    {NoFlag, NoFlag, GE03Flag, 0xabababab, 0xaaaaaaaa, 0xfffffffd},
156    {NoFlag, NoFlag, GE012Flag, 0xabababab, 0x80000000, 0x80000001},
157    {NoFlag, NoFlag, GE13Flag, 0xabababab, 0xffffff80, 0x7fffffff},
158    {NoFlag, NoFlag, GE03Flag, 0xabababab, 0xffff8000, 0xfffffffd},
159    {NoFlag, NoFlag, NoFlag, 0xabababab, 0xffffff83, 0x0000007e},
160    {NoFlag, NoFlag, GE23Flag, 0xabababab, 0xffff8002, 0x00007ffe},
161    {NoFlag, NoFlag, GE013Flag, 0xabababab, 0x00007ffe, 0x33333333},
162    {NoFlag, NoFlag, NoFlag, 0xabababab, 0xffff8002, 0x00000001},
163    {NoFlag, NoFlag, GE12Flag, 0xabababab, 0xfffffffe, 0x00000020},
164    {NoFlag, NoFlag, GE13Flag, 0xabababab, 0x7ffffffd, 0x00000001},
165    {NoFlag, NoFlag, GE123Flag, 0xabababab, 0xffffff80, 0x80000000},
166    {NoFlag, NoFlag, GE02Flag, 0xabababab, 0x7ffffffe, 0xffffff83},
167    {NoFlag, NoFlag, GE0123Flag, 0xabababab, 0x00007ffe, 0x00000001},
168    {NoFlag, NoFlag, GE01Flag, 0xabababab, 0x7ffffffe, 0x0000007f},
169    {NoFlag, NoFlag, GE012Flag, 0xabababab, 0x00007fff, 0x80000001},
170    {NoFlag, NoFlag, GE02Flag, 0xabababab, 0xaaaaaaaa, 0x0000007d},
171    {NoFlag, NoFlag, GE023Flag, 0xabababab, 0xffff8000, 0x0000007e},
172    {NoFlag, NoFlag, GE123Flag, 0xabababab, 0x80000000, 0xffffff80},
173    {NoFlag, NoFlag, GE23Flag, 0xabababab, 0xffffff82, 0x80000000},
174    {NoFlag, NoFlag, GE0123Flag, 0xabababab, 0xffff8003, 0x00000000},
175    {NoFlag, NoFlag, GE013Flag, 0xabababab, 0x00000001, 0x7ffffffd},
176    {NoFlag, NoFlag, GE13Flag, 0xabababab, 0x00007ffd, 0x00000001},
177    {NoFlag, NoFlag, GE13Flag, 0xabababab, 0xffffff83, 0xaaaaaaaa},
178    {NoFlag, NoFlag, NoFlag, 0xabababab, 0xcccccccc, 0xffffff83},
179    {NoFlag, NoFlag, GE012Flag, 0xabababab, 0x80000001, 0xffffff81},
180    {NoFlag, NoFlag, GE12Flag, 0xabababab, 0xfffffffe, 0x00000000},
181    {NoFlag, NoFlag, GE012Flag, 0xabababab, 0x00007ffd, 0x00000001},
182    {NoFlag, NoFlag, GE02Flag, 0xabababab, 0xffff8002, 0x00000002},
183    {NoFlag, NoFlag, GE23Flag, 0xabababab, 0x00007fff, 0x0000007d},
184    {NoFlag, NoFlag, GE13Flag, 0xabababab, 0x7ffffffd, 0xffffff80},
185    {NoFlag, NoFlag, GE02Flag, 0xabababab, 0x80000000, 0xffffffff},
186    {NoFlag, NoFlag, GE0123Flag, 0xabababab, 0x7fffffff, 0x00007fff},
187    {NoFlag, NoFlag, GE03Flag, 0xabababab, 0xffff8002, 0xffffff82},
188    {NoFlag, NoFlag, NoFlag, 0xabababab, 0x33333333, 0x0000007f},
189    {NoFlag, NoFlag, GE02Flag, 0xabababab, 0xffffffff, 0xfffffffd},
190    {NoFlag, NoFlag, GE013Flag, 0xabababab, 0x00000001, 0x00000001},
191    {NoFlag, NoFlag, GE12Flag, 0xabababab, 0x00007ffd, 0xaaaaaaaa},
192    {NoFlag, NoFlag, GE123Flag, 0xabababab, 0x7fffffff, 0x0000007e},
193    {NoFlag, NoFlag, GE01Flag, 0xabababab, 0x80000001, 0xffff8002},
194    {NoFlag, NoFlag, GE02Flag, 0xabababab, 0xffff8003, 0x80000000},
195    {NoFlag, NoFlag, GE13Flag, 0xabababab, 0x33333333, 0xffffff80},
196    {NoFlag, NoFlag, GE13Flag, 0xabababab, 0x7ffffffe, 0x00007ffd},
197    {NoFlag, NoFlag, GE013Flag, 0xabababab, 0x00007fff, 0x00000000},
198    {NoFlag, NoFlag, GE23Flag, 0xabababab, 0x00000001, 0x55555555},
199    {NoFlag, NoFlag, GE013Flag, 0xabababab, 0x0000007e, 0xffff8003},
200    {NoFlag, NoFlag, GE0123Flag, 0xabababab, 0x00007ffd, 0x0000007e},
201    {NoFlag, NoFlag, GE13Flag, 0xabababab, 0x80000000, 0x00000000},
202    {NoFlag, NoFlag, NoFlag, 0xabababab, 0xffffffff, 0x00007ffd},
203    {NoFlag, NoFlag, GE01Flag, 0xabababab, 0xffffff82, 0xfffffffe},
204    {NoFlag, NoFlag, GE13Flag, 0xabababab, 0xffff8000, 0xffff8001},
205    {NoFlag, NoFlag, GE023Flag, 0xabababab, 0x33333333, 0x0000007d},
206    {NoFlag, NoFlag, GE0123Flag, 0xabababab, 0x00000002, 0xffffff82},
207    {NoFlag, NoFlag, GE12Flag, 0xabababab, 0x0000007f, 0x55555555},
208    {NoFlag, NoFlag, GE123Flag, 0xabababab, 0xffffff81, 0xcccccccc},
209    {NoFlag, NoFlag, GE0123Flag, 0xabababab, 0x7ffffffe, 0x33333333},
210    {NoFlag, NoFlag, NoFlag, 0xabababab, 0xffff8003, 0x80000001},
211    {NoFlag, NoFlag, GE013Flag, 0xabababab, 0xffff8001, 0xcccccccc},
212    {NoFlag, NoFlag, GE03Flag, 0xabababab, 0x33333333, 0xaaaaaaaa},
213    {NoFlag, NoFlag, GE013Flag, 0xabababab, 0x00007fff, 0x0000007f},
214    {NoFlag, NoFlag, GE23Flag, 0xabababab, 0x0000007d, 0x00000001},
215    {NoFlag, NoFlag, GE01Flag, 0xabababab, 0xffff8001, 0x00007ffd},
216    {NoFlag, NoFlag, GE01Flag, 0xabababab, 0x0000007e, 0x80000001},
217    {NoFlag, NoFlag, GE012Flag, 0xabababab, 0xffff8003, 0x00000000},
218    {NoFlag, NoFlag, GE013Flag, 0xabababab, 0xffff8002, 0xfffffffd},
219    {NoFlag, NoFlag, GE123Flag, 0xabababab, 0xffffffff, 0xffffff80},
220    {NoFlag, NoFlag, GE0123Flag, 0xabababab, 0x00007fff, 0xffffffe0},
221    {NoFlag, NoFlag, GE023Flag, 0xabababab, 0xaaaaaaaa, 0x00007fff},
222    {NoFlag, NoFlag, GE12Flag, 0xabababab, 0xffff8002, 0xffffffff},
223    {NoFlag, NoFlag, GE023Flag, 0xabababab, 0x0000007e, 0xffffff81},
224    {NoFlag, NoFlag, GE12Flag, 0xabababab, 0x7fffffff, 0x00007fff},
225    {NoFlag, NoFlag, GE03Flag, 0xabababab, 0xffffff82, 0xffffff83},
226    {NoFlag, NoFlag, GE23Flag, 0xabababab, 0xfffffffe, 0x7ffffffe},
227    {NoFlag, NoFlag, GE02Flag, 0xabababab, 0x00007fff, 0xaaaaaaaa},
228    {NoFlag, NoFlag, GE013Flag, 0xabababab, 0x00000002, 0xffff8003},
229    {NoFlag, NoFlag, GE02Flag, 0xabababab, 0xffffff80, 0x80000000},
230    {NoFlag, NoFlag, GE0123Flag, 0xabababab, 0x7fffffff, 0x80000001},
231    {NoFlag, NoFlag, GE01Flag, 0xabababab, 0x7fffffff, 0x0000007e},
232    {NoFlag, NoFlag, GE023Flag, 0xabababab, 0x55555555, 0x00007fff},
233    {NoFlag, NoFlag, GE123Flag, 0xabababab, 0xffffffff, 0x00007fff},
234    {NoFlag, NoFlag, NoFlag, 0xabababab, 0x00000000, 0x7ffffffd},
235    {NoFlag, NoFlag, GE023Flag, 0xabababab, 0xffffff82, 0xffff8002},
236    {NoFlag, NoFlag, GE0123Flag, 0xabababab, 0xffff8002, 0x0000007e},
237    {NoFlag, NoFlag, GE02Flag, 0xabababab, 0x7ffffffe, 0xcccccccc},
238    {NoFlag, NoFlag, GE012Flag, 0xabababab, 0xffff8002, 0xfffffffd},
239    {NoFlag, NoFlag, GE12Flag, 0xabababab, 0xffffff80, 0xffff8003},
240    {NoFlag, NoFlag, GE13Flag, 0xabababab, 0x0000007e, 0xaaaaaaaa},
241    {NoFlag, NoFlag, GE01Flag, 0xabababab, 0x00007fff, 0xffffff83},
242    {NoFlag, NoFlag, GE01Flag, 0xabababab, 0xfffffffe, 0x00007ffd},
243    {NoFlag, NoFlag, GE13Flag, 0xabababab, 0xcccccccc, 0xffff8000},
244    {NoFlag, NoFlag, GE023Flag, 0xabababab, 0x00007ffe, 0x7ffffffd},
245    {NoFlag, NoFlag, GE013Flag, 0xabababab, 0x0000007f, 0x55555555},
246    {NoFlag, NoFlag, GE23Flag, 0xabababab, 0x80000000, 0xffff8000},
247    {NoFlag, NoFlag, GE02Flag, 0xabababab, 0xffffffff, 0xffffffe0},
248    {NoFlag, NoFlag, GE0123Flag, 0xabababab, 0x7fffffff, 0x80000000},
249    {NoFlag, NoFlag, GE03Flag, 0xabababab, 0x0000007d, 0xfffffffd},
250    {NoFlag, NoFlag, GE0123Flag, 0xabababab, 0xfffffffd, 0xffffffff},
251    {NoFlag, NoFlag, GE02Flag, 0xabababab, 0x00007ffd, 0x7ffffffd},
252    {NoFlag, NoFlag, GE023Flag, 0xabababab, 0xffff8003, 0x00000002},
253    {NoFlag, NoFlag, GE012Flag, 0xabababab, 0x55555555, 0xffff8001},
254    {NoFlag, NoFlag, GE01Flag, 0xabababab, 0x00000000, 0x00007fff},
255    {NoFlag, NoFlag, GE12Flag, 0xabababab, 0x00000001, 0xffffff83},
256    {NoFlag, NoFlag, NoFlag, 0xabababab, 0x33333333, 0x00007ffe},
257    {NoFlag, NoFlag, GE03Flag, 0xabababab, 0xffffff81, 0x80000001},
258    {NoFlag, NoFlag, GE12Flag, 0xabababab, 0x0000007d, 0x00000002},
259    {NoFlag, NoFlag, GE0123Flag, 0xabababab, 0xffffff80, 0x7ffffffd},
260    {NoFlag, NoFlag, GE12Flag, 0xabababab, 0xcccccccc, 0xffff8000},
261    {NoFlag, NoFlag, GE12Flag, 0xabababab, 0xcccccccc, 0xffffff81},
262    {NoFlag, NoFlag, GE12Flag, 0xabababab, 0xffffff81, 0x00000000},
263    {NoFlag, NoFlag, GE123Flag, 0xabababab, 0x33333333, 0xffffff82},
264    {NoFlag, NoFlag, GE03Flag, 0xabababab, 0xffffff83, 0xffffffe0},
265    {NoFlag, NoFlag, GE03Flag, 0xabababab, 0xfffffffe, 0x0000007d},
266    {NoFlag, NoFlag, GE023Flag, 0xabababab, 0x00000020, 0xffff8000},
267    {NoFlag, NoFlag, GE023Flag, 0xabababab, 0x00000002, 0x00007ffe},
268    {NoFlag, NoFlag, GE013Flag, 0xabababab, 0xffff8000, 0xffffff80},
269    {NoFlag, NoFlag, GE012Flag, 0xabababab, 0xfffffffe, 0xffffff81},
270    {NoFlag, NoFlag, GE03Flag, 0xabababab, 0xffffffff, 0xffffffff},
271    {NoFlag, NoFlag, GE03Flag, 0xabababab, 0x00007ffd, 0xffffff81},
272    {NoFlag, NoFlag, GE123Flag, 0xabababab, 0xcccccccc, 0xffffff82},
273    {NoFlag, NoFlag, GE013Flag, 0xabababab, 0x00007ffd, 0xfffffffd},
274    {NoFlag, NoFlag, GE013Flag, 0xabababab, 0xffff8002, 0x0000007d},
275    {NoFlag, NoFlag, GE13Flag, 0xabababab, 0xaaaaaaaa, 0x0000007f},
276    {NoFlag, NoFlag, GE13Flag, 0xabababab, 0xffff8000, 0x7ffffffd},
277    {NoFlag, NoFlag, GE013Flag, 0xabababab, 0xcccccccc, 0x00007ffe},
278    {NoFlag, NoFlag, GE03Flag, 0xabababab, 0x0000007e, 0xffff8002},
279    {NoFlag, NoFlag, GE123Flag, 0xabababab, 0xffffffe0, 0x7ffffffd},
280    {NoFlag, NoFlag, GE013Flag, 0xabababab, 0xfffffffd, 0xffffff82},
281    {NoFlag, NoFlag, GE01Flag, 0xabababab, 0xffff8002, 0x7fffffff},
282    {NoFlag, NoFlag, GE03Flag, 0xabababab, 0x7ffffffe, 0xfffffffd},
283    {NoFlag, NoFlag, GE12Flag, 0xabababab, 0x80000001, 0xffffffff},
284    {NoFlag, NoFlag, GE013Flag, 0xabababab, 0x00007fff, 0x00000020},
285    {NoFlag, NoFlag, GE02Flag, 0xabababab, 0xffffff82, 0xffff8001},
286    {NoFlag, NoFlag, GE012Flag, 0xabababab, 0xffffff80, 0x00000000},
287    {NoFlag, NoFlag, GE23Flag, 0xabababab, 0xaaaaaaaa, 0x00000001},
288    {NoFlag, NoFlag, GE03Flag, 0xabababab, 0x55555555, 0xffff8003},
289    {NoFlag, NoFlag, GE12Flag, 0xabababab, 0xffffff82, 0x0000007e},
290    {NoFlag, NoFlag, GE01Flag, 0xabababab, 0xfffffffd, 0x55555555},
291    {NoFlag, NoFlag, GE01Flag, 0xabababab, 0x00000002, 0xfffffffe},
292    {NoFlag, NoFlag, GE12Flag, 0xabababab, 0x00007ffe, 0xfffffffd},
293    {NoFlag, NoFlag, GE02Flag, 0xabababab, 0xffffff82, 0x7ffffffe},
294    {NoFlag, NoFlag, GE03Flag, 0xabababab, 0xffffff80, 0x0000007d},
295    {NoFlag, NoFlag, GE023Flag, 0xabababab, 0xffff8003, 0xffffff82},
296    {NoFlag, NoFlag, GE13Flag, 0xabababab, 0x55555555, 0x80000000},
297    {NoFlag, NoFlag, GE03Flag, 0xabababab, 0x00000001, 0xffff8003},
298    {NoFlag, NoFlag, GE13Flag, 0xabababab, 0x00000002, 0xffffff80},
299    {NoFlag, NoFlag, GE0123Flag, 0xabababab, 0xffffffff, 0x00000002},
300    {NoFlag, NoFlag, GE0123Flag, 0xabababab, 0x0000007f, 0x33333333},
301    {NoFlag, NoFlag, GE013Flag, 0xabababab, 0xffff8002, 0x55555555},
302    {NoFlag, NoFlag, GE23Flag, 0xabababab, 0xfffffffd, 0x7ffffffd},
303    {NoFlag, NoFlag, GE01Flag, 0xabababab, 0xcccccccc, 0xfffffffe},
304    {NoFlag, NoFlag, GE12Flag, 0xabababab, 0x00000001, 0x33333333},
305    {NoFlag, NoFlag, NoFlag, 0xabababab, 0xffffff83, 0xffffff83},
306    {NoFlag, NoFlag, GE0123Flag, 0xabababab, 0x80000001, 0x0000007f},
307    {NoFlag, NoFlag, GE13Flag, 0xabababab, 0xffffff81, 0xffff8001},
308    {NoFlag, NoFlag, GE013Flag, 0xabababab, 0xffffffe0, 0x00007fff},
309    {NoFlag, NoFlag, GE023Flag, 0xabababab, 0xffffff80, 0x33333333},
310    {NoFlag, NoFlag, GE01Flag, 0xabababab, 0x00007ffe, 0x00007ffe},
311    {NoFlag, NoFlag, GE02Flag, 0xabababab, 0x55555555, 0x00000002},
312    {NoFlag, NoFlag, GE013Flag, 0xabababab, 0x00000002, 0x7ffffffd},
313    {NoFlag, NoFlag, GE023Flag, 0xabababab, 0xffffff81, 0xffffff80},
314    {NoFlag, NoFlag, NoFlag, 0xabababab, 0x80000001, 0x00007ffe},
315    {NoFlag, NoFlag, GE123Flag, 0xabababab, 0xffff8001, 0xffff8002},
316    {NoFlag, NoFlag, GE0123Flag, 0xabababab, 0xaaaaaaaa, 0x7ffffffd},
317    {NoFlag, NoFlag, GE0123Flag, 0xabababab, 0x80000001, 0xffff8003},
318    {NoFlag, NoFlag, GE23Flag, 0xabababab, 0x80000000, 0xffffffff},
319    {NoFlag, NoFlag, GE23Flag, 0xabababab, 0xfffffffe, 0x33333333},
320    {NoFlag, NoFlag, GE13Flag, 0xabababab, 0x00000002, 0xffffff82},
321    {NoFlag, NoFlag, GE0123Flag, 0xabababab, 0x7fffffff, 0x7ffffffe},
322    {NoFlag, NoFlag, GE012Flag, 0xabababab, 0x00000002, 0x00000001},
323    {NoFlag, NoFlag, GE0123Flag, 0xabababab, 0x80000001, 0xffffffff},
324    {NoFlag, NoFlag, GE03Flag, 0xabababab, 0x00007ffd, 0x00000001},
325    {NoFlag, NoFlag, GE123Flag, 0xabababab, 0x55555555, 0x7fffffff},
326    {NoFlag, NoFlag, GE23Flag, 0xabababab, 0xfffffffe, 0x00000002},
327    {NoFlag, NoFlag, GE01Flag, 0xabababab, 0x0000007d, 0x7ffffffe},
328    {NoFlag, NoFlag, GE13Flag, 0xabababab, 0x0000007d, 0x7fffffff},
329    {NoFlag, NoFlag, GE023Flag, 0xabababab, 0xffffff80, 0x7fffffff},
330    {NoFlag, NoFlag, GE23Flag, 0xabababab, 0xffffff82, 0x00000001},
331    {NoFlag, NoFlag, GE013Flag, 0xabababab, 0xffffff82, 0xffffff80},
332    {NoFlag, NoFlag, GE13Flag, 0xabababab, 0xffff8003, 0xffff8000},
333    {NoFlag, NoFlag, GE123Flag, 0xabababab, 0xfffffffe, 0xffffff82},
334    {NoFlag, NoFlag, GE013Flag, 0xabababab, 0x0000007f, 0xffffffe0},
335    {NoFlag, NoFlag, GE01Flag, 0xabababab, 0x00000002, 0x00007ffe},
336    {NoFlag, NoFlag, GE023Flag, 0xabababab, 0x0000007e, 0xffffff83},
337    {NoFlag, NoFlag, GE013Flag, 0xabababab, 0x00007ffd, 0xffffffff},
338    {NoFlag, NoFlag, NoFlag, 0xabababab, 0x00007ffd, 0xffff8001},
339    {NoFlag, NoFlag, GE01Flag, 0xabababab, 0xffffffe0, 0x33333333},
340    {NoFlag, NoFlag, GE012Flag, 0xabababab, 0xffffff83, 0xffffff83},
341    {NoFlag, NoFlag, NoFlag, 0xabababab, 0x80000000, 0x00007fff},
342    {NoFlag, NoFlag, GE123Flag, 0xabababab, 0x0000007d, 0x00007ffe},
343    {NoFlag, NoFlag, GE13Flag, 0xabababab, 0x0000007d, 0xaaaaaaaa},
344    {NoFlag, NoFlag, GE03Flag, 0xabababab, 0x0000007d, 0xaaaaaaaa},
345    {NoFlag, NoFlag, GE03Flag, 0xabababab, 0xaaaaaaaa, 0x80000001},
346    {NoFlag, NoFlag, GE23Flag, 0xabababab, 0x0000007d, 0x55555555},
347    {NoFlag, NoFlag, GE012Flag, 0xabababab, 0xfffffffd, 0x00007ffd},
348    {NoFlag, NoFlag, GE12Flag, 0xabababab, 0xffff8001, 0xfffffffe}};
349
350// A loop will be generated for each element of this array.
351static const TestLoopData kTests[] = {{{al, r9, r2, r10},
352                                       "al r9 r2 r10",
353                                       "GE_al_r9_r2_r10",
354                                       ARRAY_SIZE(kGE),
355                                       kGE}};
356
357// We record all inputs to the instructions as outputs. This way, we also check
358// that what shouldn't change didn't change.
359struct TestResult {
360  size_t output_size;
361  const Inputs* outputs;
362};
363
364// These headers each contain an array of `TestResult` with the reference output
365// values. The reference arrays are names `kReference{mnemonic}`.
366#include "aarch32/traces/simulator-cond-rd-rn-rm-t32-sel-sel.h"
367
368// The maximum number of errors to report in detail for each test.
369static const unsigned kErrorReportLimit = 8;
370
371typedef void (MacroAssembler::*Fn)(Condition cond, Register rd, Register rn,
372                                   Register rm);
373
374static void TestHelper(Fn instruction, const char* mnemonic,
375                       const TestResult reference[]) {
376  SETUP();
377  masm.SetT32(true);
378  START();
379
380  // Data to compare to `reference`.
381  TestResult* results[ARRAY_SIZE(kTests)];
382
383  // Test cases for memory bound instructions may allocate a buffer and save its
384  // address in this array.
385  byte* scratch_memory_buffers[ARRAY_SIZE(kTests)];
386
387  // Generate a loop for each element in `kTests`. Each loop tests one specific
388  // instruction.
389  for (unsigned i = 0; i < ARRAY_SIZE(kTests); i++) {
390    // Allocate results on the heap for this test.
391    results[i] = new TestResult;
392    results[i]->outputs = new Inputs[kTests[i].input_size];
393    results[i]->output_size = kTests[i].input_size;
394
395    uintptr_t input_address = reinterpret_cast<uintptr_t>(kTests[i].inputs);
396    uintptr_t result_address = reinterpret_cast<uintptr_t>(results[i]->outputs);
397
398    scratch_memory_buffers[i] = NULL;
399
400    Label loop;
401    UseScratchRegisterScope scratch_registers(&masm);
402    // Include all registers from r0 ro r12.
403    scratch_registers.Include(RegisterList(0x1fff));
404
405    // Values to pass to the macro-assembler.
406    Condition cond = kTests[i].operands.cond;
407    Register rd = kTests[i].operands.rd;
408    Register rn = kTests[i].operands.rn;
409    Register rm = kTests[i].operands.rm;
410    scratch_registers.Exclude(rd);
411    scratch_registers.Exclude(rn);
412    scratch_registers.Exclude(rm);
413
414    // Allocate reserved registers for our own use.
415    Register input_ptr = scratch_registers.Acquire();
416    Register input_end = scratch_registers.Acquire();
417    Register result_ptr = scratch_registers.Acquire();
418
419    // Initialize `input_ptr` to the first element and `input_end` the address
420    // after the array.
421    __ Mov(input_ptr, input_address);
422    __ Add(input_end, input_ptr,
423           sizeof(kTests[i].inputs[0]) * kTests[i].input_size);
424    __ Mov(result_ptr, result_address);
425    __ Bind(&loop);
426
427    {
428      UseScratchRegisterScope temp_registers(&masm);
429      Register nzcv_bits = temp_registers.Acquire();
430      Register saved_q_bit = temp_registers.Acquire();
431      // Save the `Q` bit flag.
432      __ Mrs(saved_q_bit, APSR);
433      __ And(saved_q_bit, saved_q_bit, QFlag);
434      // Set the `NZCV` and `Q` flags together.
435      __ Ldr(nzcv_bits, MemOperand(input_ptr, offsetof(Inputs, apsr)));
436      __ Orr(nzcv_bits, nzcv_bits, saved_q_bit);
437      __ Msr(APSR_nzcvq, nzcv_bits);
438    }
439    {
440      UseScratchRegisterScope temp_registers(&masm);
441      Register q_bit = temp_registers.Acquire();
442      Register saved_nzcv_bits = temp_registers.Acquire();
443      // Save the `NZCV` flags.
444      __ Mrs(saved_nzcv_bits, APSR);
445      __ And(saved_nzcv_bits, saved_nzcv_bits, NZCVFlag);
446      // Set the `NZCV` and `Q` flags together.
447      __ Ldr(q_bit, MemOperand(input_ptr, offsetof(Inputs, qbit)));
448      __ Orr(q_bit, q_bit, saved_nzcv_bits);
449      __ Msr(APSR_nzcvq, q_bit);
450    }
451    {
452      UseScratchRegisterScope temp_registers(&masm);
453      Register ge_bits = temp_registers.Acquire();
454      __ Ldr(ge_bits, MemOperand(input_ptr, offsetof(Inputs, ge)));
455      __ Msr(APSR_g, ge_bits);
456    }
457    __ Ldr(rd, MemOperand(input_ptr, offsetof(Inputs, rd)));
458    __ Ldr(rn, MemOperand(input_ptr, offsetof(Inputs, rn)));
459    __ Ldr(rm, MemOperand(input_ptr, offsetof(Inputs, rm)));
460
461    (masm.*instruction)(cond, rd, rn, rm);
462
463    {
464      UseScratchRegisterScope temp_registers(&masm);
465      Register nzcv_bits = temp_registers.Acquire();
466      __ Mrs(nzcv_bits, APSR);
467      // Only record the NZCV bits.
468      __ And(nzcv_bits, nzcv_bits, NZCVFlag);
469      __ Str(nzcv_bits, MemOperand(result_ptr, offsetof(Inputs, apsr)));
470    }
471    {
472      UseScratchRegisterScope temp_registers(&masm);
473      Register q_bit = temp_registers.Acquire();
474      __ Mrs(q_bit, APSR);
475      // Only record the Q bit.
476      __ And(q_bit, q_bit, QFlag);
477      __ Str(q_bit, MemOperand(result_ptr, offsetof(Inputs, qbit)));
478    }
479    {
480      UseScratchRegisterScope temp_registers(&masm);
481      Register ge_bits = temp_registers.Acquire();
482      __ Mrs(ge_bits, APSR);
483      // Only record the GE bits.
484      __ And(ge_bits, ge_bits, GEFlags);
485      __ Str(ge_bits, MemOperand(result_ptr, offsetof(Inputs, ge)));
486    }
487    __ Str(rd, MemOperand(result_ptr, offsetof(Inputs, rd)));
488    __ Str(rn, MemOperand(result_ptr, offsetof(Inputs, rn)));
489    __ Str(rm, MemOperand(result_ptr, offsetof(Inputs, rm)));
490
491    // Advance the result pointer.
492    __ Add(result_ptr, result_ptr, sizeof(kTests[i].inputs[0]));
493    // Loop back until `input_ptr` is lower than `input_base`.
494    __ Add(input_ptr, input_ptr, sizeof(kTests[i].inputs[0]));
495    __ Cmp(input_ptr, input_end);
496    __ B(ne, &loop);
497  }
498
499  END();
500
501  RUN();
502
503  if (Test::generate_test_trace()) {
504    // Print the results.
505    for (size_t i = 0; i < ARRAY_SIZE(kTests); i++) {
506      printf("static const Inputs kOutputs_%s_%s[] = {\n", mnemonic,
507             kTests[i].identifier);
508      for (size_t j = 0; j < results[i]->output_size; j++) {
509        printf("  { ");
510        printf("0x%08" PRIx32, results[i]->outputs[j].apsr);
511        printf(", ");
512        printf("0x%08" PRIx32, results[i]->outputs[j].qbit);
513        printf(", ");
514        printf("0x%08" PRIx32, results[i]->outputs[j].ge);
515        printf(", ");
516        printf("0x%08" PRIx32, results[i]->outputs[j].rd);
517        printf(", ");
518        printf("0x%08" PRIx32, results[i]->outputs[j].rn);
519        printf(", ");
520        printf("0x%08" PRIx32, results[i]->outputs[j].rm);
521        printf(" },\n");
522      }
523      printf("};\n");
524    }
525    printf("static const TestResult kReference%s[] = {\n", mnemonic);
526    for (size_t i = 0; i < ARRAY_SIZE(kTests); i++) {
527      printf("  {\n");
528      printf("    ARRAY_SIZE(kOutputs_%s_%s),\n", mnemonic,
529             kTests[i].identifier);
530      printf("    kOutputs_%s_%s,\n", mnemonic, kTests[i].identifier);
531      printf("  },\n");
532    }
533    printf("};\n");
534  } else if (kCheckSimulatorTestResults) {
535    // Check the results.
536    unsigned total_error_count = 0;
537    for (size_t i = 0; i < ARRAY_SIZE(kTests); i++) {
538      bool instruction_has_errors = false;
539      for (size_t j = 0; j < kTests[i].input_size; j++) {
540        uint32_t apsr = results[i]->outputs[j].apsr;
541        uint32_t qbit = results[i]->outputs[j].qbit;
542        uint32_t ge = results[i]->outputs[j].ge;
543        uint32_t rd = results[i]->outputs[j].rd;
544        uint32_t rn = results[i]->outputs[j].rn;
545        uint32_t rm = results[i]->outputs[j].rm;
546        uint32_t apsr_input = kTests[i].inputs[j].apsr;
547        uint32_t qbit_input = kTests[i].inputs[j].qbit;
548        uint32_t ge_input = kTests[i].inputs[j].ge;
549        uint32_t rd_input = kTests[i].inputs[j].rd;
550        uint32_t rn_input = kTests[i].inputs[j].rn;
551        uint32_t rm_input = kTests[i].inputs[j].rm;
552        uint32_t apsr_ref = reference[i].outputs[j].apsr;
553        uint32_t qbit_ref = reference[i].outputs[j].qbit;
554        uint32_t ge_ref = reference[i].outputs[j].ge;
555        uint32_t rd_ref = reference[i].outputs[j].rd;
556        uint32_t rn_ref = reference[i].outputs[j].rn;
557        uint32_t rm_ref = reference[i].outputs[j].rm;
558
559        if (((apsr != apsr_ref) || (qbit != qbit_ref) || (ge != ge_ref) ||
560             (rd != rd_ref) || (rn != rn_ref) || (rm != rm_ref)) &&
561            (++total_error_count <= kErrorReportLimit)) {
562          // Print the instruction once even if it triggered multiple failures.
563          if (!instruction_has_errors) {
564            printf("Error(s) when testing \"%s %s\":\n", mnemonic,
565                   kTests[i].operands_description);
566            instruction_has_errors = true;
567          }
568          // Print subsequent errors.
569          printf("  Input:    ");
570          printf("0x%08" PRIx32, apsr_input);
571          printf(", ");
572          printf("0x%08" PRIx32, qbit_input);
573          printf(", ");
574          printf("0x%08" PRIx32, ge_input);
575          printf(", ");
576          printf("0x%08" PRIx32, rd_input);
577          printf(", ");
578          printf("0x%08" PRIx32, rn_input);
579          printf(", ");
580          printf("0x%08" PRIx32, rm_input);
581          printf("\n");
582          printf("  Expected: ");
583          printf("0x%08" PRIx32, apsr_ref);
584          printf(", ");
585          printf("0x%08" PRIx32, qbit_ref);
586          printf(", ");
587          printf("0x%08" PRIx32, ge_ref);
588          printf(", ");
589          printf("0x%08" PRIx32, rd_ref);
590          printf(", ");
591          printf("0x%08" PRIx32, rn_ref);
592          printf(", ");
593          printf("0x%08" PRIx32, rm_ref);
594          printf("\n");
595          printf("  Found:    ");
596          printf("0x%08" PRIx32, apsr);
597          printf(", ");
598          printf("0x%08" PRIx32, qbit);
599          printf(", ");
600          printf("0x%08" PRIx32, ge);
601          printf(", ");
602          printf("0x%08" PRIx32, rd);
603          printf(", ");
604          printf("0x%08" PRIx32, rn);
605          printf(", ");
606          printf("0x%08" PRIx32, rm);
607          printf("\n\n");
608        }
609      }
610    }
611
612    if (total_error_count > kErrorReportLimit) {
613      printf("%u other errors follow.\n",
614             total_error_count - kErrorReportLimit);
615    }
616// TODO: Do this check for the simulator too when it is ready.
617#ifndef VIXL_INCLUDE_SIMULATOR
618    VIXL_CHECK(total_error_count == 0);
619#endif
620  } else {
621    VIXL_WARNING("Assembled the code, but did not run anything.\n");
622  }
623
624  for (size_t i = 0; i < ARRAY_SIZE(kTests); i++) {
625    delete[] results[i]->outputs;
626    delete results[i];
627    delete scratch_memory_buffers[i];
628  }
629
630  TEARDOWN();
631}
632
633// Instantiate tests for each instruction in the list.
634#define TEST(mnemonic)                                                      \
635  static void Test_##mnemonic() {                                           \
636    TestHelper(&MacroAssembler::mnemonic, #mnemonic, kReference##mnemonic); \
637  }                                                                         \
638  static Test test_##mnemonic(                                              \
639      "AARCH32_SIMULATOR_COND_RD_RN_RM_T32_SEL_" #mnemonic, &Test_##mnemonic);
640FOREACH_INSTRUCTION(TEST)
641#undef TEST
642
643}  // aarch32
644}  // vixl
645