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-simulator-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/disasm-aarch32.h"
44#include "aarch32/macro-assembler-aarch32.h"
45
46#define __ masm.
47#define BUF_SIZE (4096)
48
49#ifdef VIXL_INCLUDE_SIMULATOR_AARCH32
50// Run tests with the simulator.
51
52#define SETUP() MacroAssembler masm(BUF_SIZE)
53
54#define START() masm.GetBuffer()->Reset()
55
56#define END() \
57  __ Hlt(0);  \
58  __ FinalizeCode();
59
60// TODO: Run the tests in the simulator.
61#define RUN()
62
63#else  // ifdef VIXL_INCLUDE_SIMULATOR_AARCH32.
64
65#define SETUP()                  \
66  MacroAssembler masm(BUF_SIZE); \
67  UseScratchRegisterScope harness_scratch;
68
69#define START()                 \
70  harness_scratch.Open(&masm);  \
71  harness_scratch.ExcludeAll(); \
72  masm.GetBuffer()->Reset();    \
73  __ Push(r4);                  \
74  __ Push(r5);                  \
75  __ Push(r6);                  \
76  __ Push(r7);                  \
77  __ Push(r8);                  \
78  __ Push(r9);                  \
79  __ Push(r10);                 \
80  __ Push(r11);                 \
81  __ Push(lr);                  \
82  harness_scratch.Include(ip);
83
84#define END()                  \
85  harness_scratch.Exclude(ip); \
86  __ Pop(lr);                  \
87  __ Pop(r11);                 \
88  __ Pop(r10);                 \
89  __ Pop(r9);                  \
90  __ Pop(r8);                  \
91  __ Pop(r7);                  \
92  __ Pop(r6);                  \
93  __ Pop(r5);                  \
94  __ Pop(r4);                  \
95  __ Bx(lr);                   \
96  __ FinalizeCode();           \
97  harness_scratch.Close();
98
99#define RUN()                                                 \
100  {                                                           \
101    int pcs_offset = masm.IsUsingT32() ? 1 : 0;               \
102    masm.GetBuffer()->SetExecutable();                        \
103    ExecuteMemory(masm.GetBuffer()->GetStartAddress<byte*>(), \
104                  masm.GetSizeOfCodeGenerated(),              \
105                  pcs_offset);                                \
106    masm.GetBuffer()->SetWritable();                          \
107  }
108
109#endif  // ifdef VIXL_INCLUDE_SIMULATOR_AARCH32
110
111namespace vixl {
112namespace aarch32 {
113
114// List of instruction encodings:
115#define FOREACH_INSTRUCTION(M) \
116  M(Add)                       \
117  M(Adds)                      \
118  M(Rsb)                       \
119  M(Rsbs)                      \
120  M(Sub)                       \
121  M(Subs)
122
123
124// The following definitions are defined again in each generated test, therefore
125// we need to place them in an anomymous namespace. It expresses that they are
126// local to this file only, and the compiler is not allowed to share these types
127// across test files during template instantiation. Specifically, `Operands` and
128// `Inputs` have various layouts across generated tests so they absolutely
129// cannot be shared.
130
131#ifdef VIXL_INCLUDE_TARGET_T32
132namespace {
133
134// Values to be passed to the assembler to produce the instruction under test.
135struct Operands {
136  Condition cond;
137  Register rd;
138  Register rn;
139  int32_t immediate;
140};
141
142// Input data to feed to the instruction.
143struct Inputs {
144  uint32_t apsr;
145  uint32_t rd;
146  uint32_t rn;
147};
148
149// This structure contains all input data needed to test one specific encoding.
150// It used to generate a loop over an instruction.
151struct TestLoopData {
152  // The `operands` fields represents the values to pass to the assembler to
153  // produce the instruction.
154  Operands operands;
155  // Description of the operands, used for error reporting.
156  const char* operands_description;
157  // Unique identifier, used for generating traces.
158  const char* identifier;
159  // Array of values to be fed to the instruction.
160  size_t input_size;
161  const Inputs* inputs;
162};
163
164static const Inputs kRdIsRn[] =
165    {{ZFlag, 0x00007fff, 0x00007fff},    {CFlag, 0xffffff83, 0xffffff83},
166     {NCFlag, 0x00000000, 0x00000000},   {NCVFlag, 0x00000000, 0x00000000},
167     {NZFlag, 0x00000000, 0x00000000},   {VFlag, 0x00000002, 0x00000002},
168     {NCFlag, 0xfffffffe, 0xfffffffe},   {NCVFlag, 0x00007ffd, 0x00007ffd},
169     {NZCVFlag, 0xffffffff, 0xffffffff}, {ZVFlag, 0xffffffff, 0xffffffff},
170     {CFlag, 0x00000002, 0x00000002},    {ZFlag, 0x80000001, 0x80000001},
171     {ZCFlag, 0x00007ffe, 0x00007ffe},   {ZVFlag, 0xffff8000, 0xffff8000},
172     {CFlag, 0x0000007e, 0x0000007e},    {ZFlag, 0xcccccccc, 0xcccccccc},
173     {NVFlag, 0xffff8000, 0xffff8000},   {CFlag, 0x00000001, 0x00000001},
174     {NFlag, 0x00000001, 0x00000001},    {NZFlag, 0xffffffe0, 0xffffffe0},
175     {CVFlag, 0xfffffffd, 0xfffffffd},   {ZVFlag, 0x00007ffe, 0x00007ffe},
176     {ZCVFlag, 0x55555555, 0x55555555},  {NCFlag, 0x00000020, 0x00000020},
177     {ZCFlag, 0xffffff81, 0xffffff81},   {ZCFlag, 0xcccccccc, 0xcccccccc},
178     {ZCFlag, 0x00000020, 0x00000020},   {NCVFlag, 0xffff8000, 0xffff8000},
179     {NZVFlag, 0xffff8001, 0xffff8001},  {ZVFlag, 0xffffff81, 0xffffff81},
180     {NZVFlag, 0xffffff81, 0xffffff81},  {NZVFlag, 0x00000000, 0x00000000},
181     {NVFlag, 0x00000001, 0x00000001},   {NCVFlag, 0x33333333, 0x33333333},
182     {NZCVFlag, 0xffff8001, 0xffff8001}, {NZCFlag, 0xffffffff, 0xffffffff},
183     {NCVFlag, 0x80000000, 0x80000000},  {ZCFlag, 0x00000001, 0x00000001},
184     {CVFlag, 0x00000020, 0x00000020},   {NCFlag, 0xffff8003, 0xffff8003},
185     {CVFlag, 0x00000002, 0x00000002},   {NZCFlag, 0x80000000, 0x80000000},
186     {VFlag, 0xffffff83, 0xffffff83},    {NZFlag, 0x33333333, 0x33333333},
187     {NCVFlag, 0x00007ffe, 0x00007ffe},  {NFlag, 0xffffff81, 0xffffff81},
188     {NZVFlag, 0x00000020, 0x00000020},  {CVFlag, 0x00007fff, 0x00007fff},
189     {NZCFlag, 0xffff8003, 0xffff8003},  {ZCFlag, 0xfffffffd, 0xfffffffd},
190     {NZFlag, 0xcccccccc, 0xcccccccc},   {ZCFlag, 0xffffffff, 0xffffffff},
191     {ZVFlag, 0xffffffe0, 0xffffffe0},   {ZCFlag, 0x55555555, 0x55555555},
192     {NVFlag, 0x00000020, 0x00000020},   {NFlag, 0xffff8000, 0xffff8000},
193     {ZFlag, 0x00000000, 0x00000000},    {VFlag, 0xffffffe0, 0xffffffe0},
194     {CFlag, 0xffff8001, 0xffff8001},    {NZCVFlag, 0xfffffffd, 0xfffffffd},
195     {NCVFlag, 0x0000007d, 0x0000007d},  {NCVFlag, 0x0000007f, 0x0000007f},
196     {NZFlag, 0xffff8003, 0xffff8003},   {ZCFlag, 0xffffff82, 0xffffff82},
197     {ZFlag, 0xffff8001, 0xffff8001},    {NZFlag, 0xffff8002, 0xffff8002},
198     {NZFlag, 0x00000020, 0x00000020},   {NCFlag, 0x33333333, 0x33333333},
199     {ZCVFlag, 0x80000000, 0x80000000},  {NZCFlag, 0xffffffe0, 0xffffffe0},
200     {NZFlag, 0x00007fff, 0x00007fff},   {NZVFlag, 0x00000002, 0x00000002},
201     {NFlag, 0x55555555, 0x55555555},    {NVFlag, 0xffffffff, 0xffffffff},
202     {NCFlag, 0x00007fff, 0x00007fff},   {NZCVFlag, 0xffffff81, 0xffffff81},
203     {ZCVFlag, 0x00007fff, 0x00007fff},  {NZFlag, 0x0000007d, 0x0000007d},
204     {VFlag, 0x00007ffe, 0x00007ffe},    {CVFlag, 0xffffff83, 0xffffff83},
205     {NZFlag, 0x80000000, 0x80000000},   {ZCFlag, 0xaaaaaaaa, 0xaaaaaaaa},
206     {NCFlag, 0x0000007f, 0x0000007f},   {CFlag, 0x00000020, 0x00000020},
207     {NZCFlag, 0x00000001, 0x00000001},  {NZCFlag, 0xcccccccc, 0xcccccccc},
208     {NZCFlag, 0xffffff80, 0xffffff80},  {NCVFlag, 0xffff8003, 0xffff8003},
209     {NFlag, 0x0000007d, 0x0000007d},    {NZVFlag, 0x55555555, 0x55555555},
210     {NZCVFlag, 0xfffffffe, 0xfffffffe}, {NCFlag, 0xffff8000, 0xffff8000},
211     {CFlag, 0x80000001, 0x80000001},    {NVFlag, 0xffffffe0, 0xffffffe0},
212     {CFlag, 0xffffff82, 0xffffff82},    {NZCVFlag, 0x00007ffd, 0x00007ffd},
213     {CFlag, 0xaaaaaaaa, 0xaaaaaaaa},    {NZCFlag, 0xffffff81, 0xffffff81},
214     {ZFlag, 0x00007ffd, 0x00007ffd},    {NZVFlag, 0xffffffe0, 0xffffffe0},
215     {NZVFlag, 0x00007ffe, 0x00007ffe},  {NZFlag, 0x7ffffffd, 0x7ffffffd},
216     {NZCFlag, 0xfffffffe, 0xfffffffe},  {NZCVFlag, 0x7ffffffd, 0x7ffffffd},
217     {ZVFlag, 0xaaaaaaaa, 0xaaaaaaaa},   {CFlag, 0x00000000, 0x00000000},
218     {ZCVFlag, 0xaaaaaaaa, 0xaaaaaaaa},  {NZFlag, 0x00007ffd, 0x00007ffd},
219     {VFlag, 0xffff8000, 0xffff8000},    {CVFlag, 0xcccccccc, 0xcccccccc},
220     {NZCVFlag, 0xffff8003, 0xffff8003}, {NVFlag, 0x00007ffe, 0x00007ffe},
221     {ZVFlag, 0xfffffffd, 0xfffffffd},   {NZCFlag, 0x0000007e, 0x0000007e},
222     {VFlag, 0x00000000, 0x00000000},    {NZFlag, 0x00000002, 0x00000002},
223     {ZCFlag, 0x7fffffff, 0x7fffffff},   {ZFlag, 0x0000007e, 0x0000007e},
224     {NZCFlag, 0x7fffffff, 0x7fffffff},  {ZVFlag, 0xffff8002, 0xffff8002},
225     {ZFlag, 0x00000020, 0x00000020},    {NZFlag, 0xffffff81, 0xffffff81},
226     {ZCVFlag, 0x00000000, 0x00000000},  {CFlag, 0xffffff81, 0xffffff81},
227     {NVFlag, 0x0000007e, 0x0000007e},   {NZFlag, 0x55555555, 0x55555555},
228     {CFlag, 0x0000007d, 0x0000007d},    {NCFlag, 0x7fffffff, 0x7fffffff},
229     {NCFlag, 0xffff8001, 0xffff8001},   {CFlag, 0xffffffe0, 0xffffffe0},
230     {ZVFlag, 0x7ffffffe, 0x7ffffffe},   {VFlag, 0x7ffffffd, 0x7ffffffd},
231     {CFlag, 0xffffffff, 0xffffffff},    {ZCFlag, 0xffff8000, 0xffff8000},
232     {NZVFlag, 0xffff8003, 0xffff8003},  {NCFlag, 0x0000007d, 0x0000007d},
233     {NZVFlag, 0x0000007f, 0x0000007f},  {CFlag, 0xcccccccc, 0xcccccccc},
234     {CVFlag, 0x00000001, 0x00000001},   {NZCFlag, 0xffff8001, 0xffff8001},
235     {NCVFlag, 0x00000020, 0x00000020},  {NZVFlag, 0xffffff82, 0xffffff82},
236     {NCFlag, 0x00007ffd, 0x00007ffd},   {ZVFlag, 0x0000007e, 0x0000007e},
237     {NZFlag, 0x80000001, 0x80000001},   {NVFlag, 0x7ffffffe, 0x7ffffffe},
238     {NZCVFlag, 0x00000000, 0x00000000}, {CVFlag, 0x55555555, 0x55555555},
239     {ZVFlag, 0x00000020, 0x00000020},   {VFlag, 0x00000020, 0x00000020},
240     {NFlag, 0xcccccccc, 0xcccccccc},    {NVFlag, 0x0000007d, 0x0000007d},
241     {CVFlag, 0x0000007f, 0x0000007f},   {NZCFlag, 0x00000002, 0x00000002},
242     {NZCFlag, 0x00007fff, 0x00007fff},  {NZVFlag, 0x0000007d, 0x0000007d},
243     {NZVFlag, 0xfffffffd, 0xfffffffd},  {NFlag, 0x00000002, 0x00000002},
244     {NZCVFlag, 0x0000007d, 0x0000007d}, {NVFlag, 0xffffff82, 0xffffff82},
245     {VFlag, 0x00007fff, 0x00007fff},    {NZCVFlag, 0x00000001, 0x00000001},
246     {ZFlag, 0xaaaaaaaa, 0xaaaaaaaa},    {CVFlag, 0xffff8002, 0xffff8002},
247     {NFlag, 0x7fffffff, 0x7fffffff},    {NCVFlag, 0xffffff80, 0xffffff80},
248     {ZFlag, 0x33333333, 0x33333333},    {NZFlag, 0x00000001, 0x00000001},
249     {NCVFlag, 0x7ffffffe, 0x7ffffffe},  {VFlag, 0x00000001, 0x00000001},
250     {ZCFlag, 0x0000007f, 0x0000007f},   {ZVFlag, 0x80000001, 0x80000001},
251     {ZVFlag, 0xffff8003, 0xffff8003},   {NCVFlag, 0xaaaaaaaa, 0xaaaaaaaa},
252     {NZCVFlag, 0xffffffe0, 0xffffffe0}, {VFlag, 0x33333333, 0x33333333},
253     {NCFlag, 0xffffff80, 0xffffff80},   {ZFlag, 0x00007ffe, 0x00007ffe},
254     {NVFlag, 0x00000000, 0x00000000},   {NZCFlag, 0x00007ffd, 0x00007ffd},
255     {NZFlag, 0xfffffffd, 0xfffffffd},   {VFlag, 0xffffffff, 0xffffffff},
256     {NZCFlag, 0xffffff83, 0xffffff83},  {NZVFlag, 0xffff8002, 0xffff8002},
257     {NZCVFlag, 0x33333333, 0x33333333}, {ZCVFlag, 0xfffffffd, 0xfffffffd},
258     {ZCFlag, 0x80000001, 0x80000001},   {NCFlag, 0x00007ffe, 0x00007ffe},
259     {NFlag, 0xfffffffd, 0xfffffffd},    {NZCVFlag, 0x7fffffff, 0x7fffffff},
260     {VFlag, 0xffff8001, 0xffff8001},    {NZVFlag, 0xffff8000, 0xffff8000},
261     {ZCVFlag, 0xcccccccc, 0xcccccccc},  {VFlag, 0x7ffffffe, 0x7ffffffe},
262     {ZFlag, 0xffff8002, 0xffff8002},    {ZCFlag, 0x0000007d, 0x0000007d},
263     {NZCVFlag, 0xffffff83, 0xffffff83}, {ZVFlag, 0x00000001, 0x00000001},
264     {NZCVFlag, 0xffff8002, 0xffff8002}, {ZCFlag, 0xffffff83, 0xffffff83},
265     {CFlag, 0xffff8003, 0xffff8003},    {NCVFlag, 0xffffffff, 0xffffffff},
266     {CFlag, 0xfffffffe, 0xfffffffe},    {NZFlag, 0xffffff80, 0xffffff80},
267     {CVFlag, 0x00007ffd, 0x00007ffd},   {ZCVFlag, 0x0000007d, 0x0000007d},
268     {ZVFlag, 0xcccccccc, 0xcccccccc},   {NVFlag, 0x00007ffd, 0x00007ffd},
269     {NZFlag, 0xaaaaaaaa, 0xaaaaaaaa},   {ZFlag, 0x0000007f, 0x0000007f},
270     {CVFlag, 0xffff8003, 0xffff8003},   {ZFlag, 0xffffffe0, 0xffffffe0},
271     {NZVFlag, 0xcccccccc, 0xcccccccc},  {NFlag, 0x00007ffe, 0x00007ffe},
272     {NFlag, 0xffff8003, 0xffff8003},    {NZVFlag, 0xffffffff, 0xffffffff},
273     {CFlag, 0x00007fff, 0x00007fff},    {NCVFlag, 0x7fffffff, 0x7fffffff},
274     {CFlag, 0x33333333, 0x33333333},    {ZCFlag, 0x80000000, 0x80000000},
275     {ZCFlag, 0x0000007e, 0x0000007e},   {NVFlag, 0x7fffffff, 0x7fffffff},
276     {NZFlag, 0x7ffffffe, 0x7ffffffe},   {CFlag, 0xffff8002, 0xffff8002},
277     {NCFlag, 0x80000000, 0x80000000},   {VFlag, 0x7fffffff, 0x7fffffff},
278     {NZFlag, 0xffffffff, 0xffffffff},   {NFlag, 0x7ffffffd, 0x7ffffffd},
279     {ZFlag, 0x00000002, 0x00000002},    {ZCVFlag, 0xffff8003, 0xffff8003},
280     {CFlag, 0x7fffffff, 0x7fffffff},    {CFlag, 0x0000007f, 0x0000007f},
281     {VFlag, 0x80000001, 0x80000001},    {ZCFlag, 0x00007fff, 0x00007fff},
282     {CFlag, 0xfffffffd, 0xfffffffd},    {NZFlag, 0x7fffffff, 0x7fffffff},
283     {CVFlag, 0xffff8001, 0xffff8001},   {NZVFlag, 0x00007fff, 0x00007fff},
284     {NZVFlag, 0x7ffffffe, 0x7ffffffe},  {ZCVFlag, 0x0000007e, 0x0000007e},
285     {NZVFlag, 0x00000001, 0x00000001},  {ZFlag, 0xffffffff, 0xffffffff},
286     {NZFlag, 0xfffffffe, 0xfffffffe},   {NZCVFlag, 0x0000007f, 0x0000007f},
287     {NZCVFlag, 0x80000000, 0x80000000}, {VFlag, 0x55555555, 0x55555555},
288     {NVFlag, 0xffff8001, 0xffff8001},   {NFlag, 0xffffff83, 0xffffff83},
289     {NZVFlag, 0x7ffffffd, 0x7ffffffd},  {ZVFlag, 0x00000000, 0x00000000},
290     {NCVFlag, 0xfffffffd, 0xfffffffd},  {CFlag, 0x00007ffe, 0x00007ffe},
291     {NVFlag, 0xffffff83, 0xffffff83},   {NZFlag, 0x0000007e, 0x0000007e},
292     {VFlag, 0x80000000, 0x80000000},    {NZCFlag, 0xffff8000, 0xffff8000},
293     {ZCFlag, 0xffff8001, 0xffff8001},   {NVFlag, 0x00007fff, 0x00007fff},
294     {ZCVFlag, 0xffffff81, 0xffffff81},  {NZVFlag, 0x0000007e, 0x0000007e},
295     {CVFlag, 0xffff8000, 0xffff8000},   {VFlag, 0xffffff82, 0xffffff82},
296     {VFlag, 0xaaaaaaaa, 0xaaaaaaaa},    {NZCVFlag, 0xcccccccc, 0xcccccccc},
297     {CVFlag, 0x33333333, 0x33333333},   {NCFlag, 0xffffffff, 0xffffffff},
298     {VFlag, 0xffffff80, 0xffffff80},    {NVFlag, 0xffff8002, 0xffff8002},
299     {ZCFlag, 0x00000000, 0x00000000},   {ZCVFlag, 0x80000001, 0x80000001},
300     {NZCVFlag, 0x80000001, 0x80000001}, {NCFlag, 0x55555555, 0x55555555},
301     {CVFlag, 0x7ffffffe, 0x7ffffffe},   {ZVFlag, 0x7ffffffd, 0x7ffffffd},
302     {ZCVFlag, 0xffff8000, 0xffff8000},  {ZCFlag, 0xffff8002, 0xffff8002},
303     {NFlag, 0xfffffffe, 0xfffffffe},    {ZCVFlag, 0x0000007f, 0x0000007f},
304     {NCVFlag, 0xfffffffe, 0xfffffffe},  {ZCVFlag, 0x7fffffff, 0x7fffffff},
305     {CVFlag, 0x0000007e, 0x0000007e},   {NZCVFlag, 0x7ffffffe, 0x7ffffffe},
306     {CFlag, 0xffffff80, 0xffffff80},    {VFlag, 0x00007ffd, 0x00007ffd},
307     {CVFlag, 0xffffffe0, 0xffffffe0},   {CFlag, 0x7ffffffe, 0x7ffffffe},
308     {CFlag, 0x80000000, 0x80000000},    {CVFlag, 0xfffffffe, 0xfffffffe},
309     {NCVFlag, 0xffff8002, 0xffff8002},  {ZCVFlag, 0x33333333, 0x33333333},
310     {NZCFlag, 0xaaaaaaaa, 0xaaaaaaaa},  {NVFlag, 0x55555555, 0x55555555},
311     {NVFlag, 0x80000000, 0x80000000},   {NZCVFlag, 0x00007ffe, 0x00007ffe},
312     {ZFlag, 0xffffff83, 0xffffff83},    {NCFlag, 0xaaaaaaaa, 0xaaaaaaaa},
313     {NZVFlag, 0xfffffffe, 0xfffffffe},  {CVFlag, 0xaaaaaaaa, 0xaaaaaaaa},
314     {NZCFlag, 0xffff8002, 0xffff8002},  {VFlag, 0x0000007d, 0x0000007d}};
315
316static const Inputs kRdIsNotRn[] =
317    {{NZCVFlag, 0xffff8000, 0xffffffff}, {CVFlag, 0xcccccccc, 0xffffff80},
318     {NCFlag, 0xfffffffe, 0xfffffffd},   {NCFlag, 0xcccccccc, 0xcccccccc},
319     {ZFlag, 0x80000001, 0xffffffff},    {NCFlag, 0xffffff82, 0x0000007d},
320     {NCVFlag, 0x0000007d, 0xffff8001},  {NVFlag, 0x00007fff, 0x7fffffff},
321     {NVFlag, 0x80000001, 0xffffff82},   {ZCVFlag, 0xffffffff, 0x0000007e},
322     {ZCVFlag, 0xffffff80, 0x0000007d},  {ZCVFlag, 0x00000020, 0xaaaaaaaa},
323     {CVFlag, 0x00007fff, 0x00000020},   {NVFlag, 0xffff8000, 0xffffff82},
324     {NZFlag, 0xffffff82, 0x7ffffffe},   {NZVFlag, 0xffff8003, 0x33333333},
325     {ZCVFlag, 0x00007ffe, 0x7ffffffe},  {NFlag, 0x0000007f, 0xffffffff},
326     {NZCFlag, 0x33333333, 0x80000000},  {ZCFlag, 0x80000001, 0xffffffff},
327     {VFlag, 0x00007ffd, 0x00000001},    {ZVFlag, 0xffffffff, 0x0000007e},
328     {NZFlag, 0x00000001, 0xcccccccc},   {NZVFlag, 0x00000020, 0xffff8001},
329     {NCVFlag, 0x7ffffffe, 0xffffff80},  {ZCFlag, 0x33333333, 0x00007fff},
330     {CFlag, 0xffffff82, 0x0000007e},    {ZCFlag, 0x55555555, 0xffff8003},
331     {NFlag, 0x0000007f, 0x00000001},    {ZCVFlag, 0x00000020, 0xfffffffd},
332     {ZVFlag, 0x0000007e, 0xffff8003},   {ZCVFlag, 0x00000020, 0x80000001},
333     {ZCFlag, 0xfffffffe, 0x55555555},   {NFlag, 0xfffffffd, 0xfffffffe},
334     {VFlag, 0xffffff82, 0x7ffffffe},    {CVFlag, 0xffffff80, 0x0000007f},
335     {NVFlag, 0x00000020, 0xffff8001},   {NCFlag, 0x0000007d, 0x80000000},
336     {CVFlag, 0x00000020, 0xffffff83},   {NZCVFlag, 0x0000007f, 0x00000000},
337     {ZVFlag, 0xffffff82, 0x7ffffffd},   {ZVFlag, 0xffff8000, 0x80000001},
338     {NFlag, 0xcccccccc, 0x0000007e},    {NFlag, 0x55555555, 0xffffff80},
339     {NCFlag, 0x80000000, 0x00007ffd},   {ZVFlag, 0x00007ffd, 0x00007ffe},
340     {ZCVFlag, 0x00000000, 0x7ffffffe},  {ZFlag, 0xffff8001, 0xffffffff},
341     {NCFlag, 0xfffffffe, 0x55555555},   {VFlag, 0x7ffffffd, 0x80000001},
342     {VFlag, 0x80000000, 0xffffffff},    {CFlag, 0xffffff82, 0xffffff80},
343     {NZCFlag, 0xffff8003, 0xfffffffd},  {CFlag, 0x00000020, 0x00007fff},
344     {NZVFlag, 0xffff8002, 0xfffffffe},  {NVFlag, 0xffffff80, 0x0000007e},
345     {NVFlag, 0xcccccccc, 0x0000007d},   {CFlag, 0x0000007f, 0x00000001},
346     {ZVFlag, 0xffff8002, 0xffffff81},   {NZVFlag, 0x80000000, 0x00007ffe},
347     {NZCVFlag, 0x80000000, 0x7ffffffe}, {ZVFlag, 0x7ffffffe, 0x80000000},
348     {ZFlag, 0xffff8000, 0xffffff80},    {VFlag, 0x00007ffd, 0x00007ffd},
349     {ZCFlag, 0x0000007d, 0x0000007e},   {NCFlag, 0x00000000, 0x7ffffffe},
350     {NVFlag, 0x00000020, 0xaaaaaaaa},   {NVFlag, 0xffffff83, 0x0000007e},
351     {NZFlag, 0xffff8002, 0x7ffffffd},   {CVFlag, 0xcccccccc, 0x00000001},
352     {NZFlag, 0x33333333, 0x0000007e},   {NZCFlag, 0x00000002, 0x7ffffffd},
353     {NZFlag, 0x00007ffd, 0xffffff80},   {ZVFlag, 0x00007ffd, 0xfffffffe},
354     {NZCVFlag, 0xffff8000, 0x80000000}, {NZFlag, 0xffff8002, 0xffffffff},
355     {CFlag, 0x00000002, 0xffff8000},    {NZCFlag, 0x0000007d, 0xffffff80},
356     {ZVFlag, 0x0000007d, 0xffff8003},   {VFlag, 0x55555555, 0xffff8000},
357     {CFlag, 0x00007fff, 0x00000001},    {VFlag, 0x80000001, 0x33333333},
358     {ZCFlag, 0xaaaaaaaa, 0xffffff82},   {VFlag, 0x00000002, 0x00007ffd},
359     {ZVFlag, 0x7ffffffe, 0xffff8001},   {ZCFlag, 0x7fffffff, 0x00000000},
360     {CVFlag, 0x55555555, 0x0000007e},   {VFlag, 0x55555555, 0x0000007e},
361     {NZCVFlag, 0x80000000, 0x7ffffffd}, {ZFlag, 0x0000007d, 0x00000000},
362     {NZVFlag, 0xffffff80, 0x00000002},  {NVFlag, 0xfffffffd, 0x00000001},
363     {ZVFlag, 0x7ffffffd, 0xfffffffd},   {VFlag, 0xffff8002, 0x55555555},
364     {ZCVFlag, 0x00000001, 0xffff8002},  {NVFlag, 0xffff8002, 0x00000020},
365     {ZFlag, 0x33333333, 0xffff8002},    {ZCVFlag, 0x55555555, 0xffffff82},
366     {CVFlag, 0x7ffffffe, 0xffffffe0},   {NVFlag, 0xcccccccc, 0x00007ffd},
367     {NZFlag, 0x00000001, 0x0000007f},   {ZFlag, 0xfffffffe, 0x00007fff},
368     {NCVFlag, 0x80000001, 0xffffff83},  {NCVFlag, 0xaaaaaaaa, 0xffff8002},
369     {ZVFlag, 0x00007fff, 0xffff8000},   {ZFlag, 0xffff8001, 0xfffffffd},
370     {CFlag, 0x55555555, 0x80000000},    {ZCVFlag, 0xcccccccc, 0xfffffffe},
371     {NZCVFlag, 0xffff8003, 0x7fffffff}, {NZCVFlag, 0x00007ffe, 0xffffff81},
372     {NZCFlag, 0xfffffffd, 0xaaaaaaaa},  {NVFlag, 0x00000002, 0x00000020},
373     {ZCVFlag, 0xffff8003, 0xfffffffd},  {NFlag, 0xffff8001, 0x00007ffe},
374     {ZCFlag, 0xaaaaaaaa, 0x00000002},   {NCVFlag, 0xffff8000, 0xfffffffe},
375     {CFlag, 0x00000020, 0x00000000},    {NZVFlag, 0x00007ffd, 0xffffff81},
376     {NVFlag, 0x00007fff, 0x00000020},   {ZFlag, 0x0000007e, 0x80000001},
377     {CVFlag, 0x0000007d, 0xaaaaaaaa},   {NZVFlag, 0x7fffffff, 0x55555555},
378     {VFlag, 0xffffffff, 0x00007ffd},    {NFlag, 0x80000000, 0xffffffe0},
379     {ZVFlag, 0xffffff82, 0xfffffffe},   {CVFlag, 0x0000007d, 0x00007fff},
380     {CFlag, 0x7ffffffe, 0x55555555},    {ZFlag, 0xffffff82, 0x7fffffff},
381     {NZCFlag, 0xfffffffd, 0xffffff83},  {CVFlag, 0x80000001, 0x80000000},
382     {ZVFlag, 0x00000001, 0xfffffffe},   {CVFlag, 0x00000001, 0x33333333},
383     {NZFlag, 0x7ffffffd, 0x80000000},   {NZVFlag, 0x00007ffd, 0xaaaaaaaa},
384     {CVFlag, 0x0000007e, 0xffffff82},   {CVFlag, 0x7ffffffe, 0xffff8002},
385     {NVFlag, 0xfffffffe, 0xffff8003},   {NFlag, 0x7fffffff, 0x80000001},
386     {CFlag, 0xffffff82, 0x00000002},    {CVFlag, 0xcccccccc, 0x0000007e},
387     {NZCVFlag, 0x00000001, 0x7ffffffe}, {NFlag, 0x00000000, 0x55555555},
388     {NZFlag, 0xffffff81, 0x00000000},   {NZVFlag, 0xffffffe0, 0x0000007e},
389     {ZCFlag, 0xffff8002, 0xaaaaaaaa},   {NZVFlag, 0x7fffffff, 0x0000007d},
390     {ZVFlag, 0x0000007e, 0xffff8001},   {NCVFlag, 0xffffff83, 0xaaaaaaaa},
391     {ZFlag, 0xffffff82, 0xffffff83},    {VFlag, 0x00000001, 0x55555555},
392     {NFlag, 0x00000020, 0x80000000},    {NZFlag, 0x00000000, 0xfffffffe},
393     {VFlag, 0xffffff83, 0xaaaaaaaa},    {ZFlag, 0xffff8002, 0xffffff83},
394     {NZVFlag, 0xcccccccc, 0x7ffffffe},  {ZVFlag, 0x00000000, 0x55555555},
395     {NCFlag, 0x33333333, 0xffff8003},   {NZCVFlag, 0xfffffffd, 0x00000000},
396     {NZCVFlag, 0x00000020, 0xffff8000}, {CVFlag, 0xffff8001, 0xffffff83},
397     {CFlag, 0xffffff83, 0x33333333},    {CVFlag, 0x7ffffffd, 0x00000020},
398     {NCVFlag, 0xffffffe0, 0x80000000},  {NCVFlag, 0xffffff82, 0xcccccccc},
399     {NZCVFlag, 0xaaaaaaaa, 0x00007fff}, {VFlag, 0xcccccccc, 0xffff8003},
400     {ZCVFlag, 0x55555555, 0xffffffe0},  {NZCFlag, 0xffffff83, 0xffff8000},
401     {ZVFlag, 0xffff8001, 0x0000007d},   {CVFlag, 0xffffff83, 0x00000002},
402     {NVFlag, 0x7fffffff, 0x0000007d},   {VFlag, 0x55555555, 0x33333333},
403     {NCVFlag, 0x00000002, 0xffffff80},  {ZFlag, 0xfffffffd, 0x00007fff},
404     {ZCFlag, 0xffff8003, 0x0000007d},   {NZCFlag, 0xffff8002, 0xffff8000},
405     {NCVFlag, 0x00000020, 0xffff8002},  {ZVFlag, 0xffff8000, 0x00000020},
406     {ZCVFlag, 0x0000007f, 0xffffffe0},  {NZCFlag, 0xffffff80, 0x33333333},
407     {NCVFlag, 0x00007fff, 0xaaaaaaaa},  {ZCVFlag, 0x00000020, 0xffffff82},
408     {NFlag, 0x00000000, 0x0000007d},    {NCVFlag, 0x00000001, 0x00007ffe},
409     {ZFlag, 0x80000001, 0x00000002},    {NZVFlag, 0xffff8000, 0x00000020},
410     {CVFlag, 0xffff8002, 0xcccccccc},   {NVFlag, 0xffffff83, 0x80000000},
411     {ZCFlag, 0x0000007f, 0xffffff80},   {NZFlag, 0xcccccccc, 0xffffffff},
412     {NZFlag, 0x00007fff, 0x0000007f},   {NZFlag, 0xfffffffd, 0xffff8001},
413     {CFlag, 0x0000007d, 0x7ffffffd},    {ZCFlag, 0xffff8000, 0xffff8003},
414     {ZVFlag, 0xffffffff, 0xffffffe0},   {NZCFlag, 0x00007ffd, 0xcccccccc},
415     {NCVFlag, 0x0000007d, 0x00000020},  {ZCFlag, 0xaaaaaaaa, 0x80000000},
416     {ZCVFlag, 0xfffffffd, 0x0000007d},  {ZFlag, 0xffffffe0, 0xfffffffe},
417     {VFlag, 0xffff8003, 0x80000000},    {NZCFlag, 0x00007fff, 0xffffff82},
418     {NCVFlag, 0x00000002, 0x33333333},  {NZCVFlag, 0x00000000, 0xffffff82},
419     {VFlag, 0x80000000, 0x80000000},    {ZVFlag, 0x80000001, 0x33333333},
420     {ZFlag, 0x7ffffffe, 0x00007fff},    {NZCVFlag, 0x7fffffff, 0x00007fff},
421     {ZCFlag, 0xffffff83, 0xaaaaaaaa},   {NZVFlag, 0xffff8002, 0xffffffe0},
422     {VFlag, 0xfffffffd, 0xffffff81},    {NZFlag, 0x7fffffff, 0x7ffffffd},
423     {NZCVFlag, 0x0000007f, 0xcccccccc}, {NZCFlag, 0xffff8001, 0x00000020},
424     {ZFlag, 0x00000020, 0xffff8002},    {ZVFlag, 0x55555555, 0x00007ffd},
425     {NZVFlag, 0xcccccccc, 0x33333333},  {CFlag, 0x80000000, 0x80000000},
426     {ZCVFlag, 0xcccccccc, 0x00007ffd},  {ZFlag, 0xffff8002, 0xffffff80},
427     {CVFlag, 0x7ffffffd, 0xffffff80},   {NZCVFlag, 0x00000001, 0x00000001},
428     {NFlag, 0xfffffffe, 0xffffffe0},    {ZVFlag, 0x0000007e, 0x0000007f},
429     {NCVFlag, 0xffff8002, 0xffff8002},  {ZCVFlag, 0xffffff82, 0x80000001},
430     {CVFlag, 0x0000007d, 0x0000007d},   {NZVFlag, 0xcccccccc, 0xffffff83},
431     {VFlag, 0xffffff82, 0xfffffffd},    {CFlag, 0x0000007d, 0x0000007f},
432     {NFlag, 0x0000007d, 0x00000001},    {NVFlag, 0x00007ffd, 0xfffffffe},
433     {NZVFlag, 0x33333333, 0xffffff80},  {NVFlag, 0x0000007e, 0x00007ffe},
434     {ZFlag, 0xffff8001, 0x0000007e},    {VFlag, 0x80000000, 0x00000002},
435     {NVFlag, 0x00000020, 0x00007ffe},   {CFlag, 0x00007ffe, 0x0000007f},
436     {ZCFlag, 0xffff8002, 0x00000020},   {NCVFlag, 0x00000001, 0xffff8000},
437     {NZCVFlag, 0x0000007e, 0xffff8001}, {ZCFlag, 0x0000007f, 0xffffff81},
438     {ZVFlag, 0xfffffffd, 0x00007ffd},   {NCFlag, 0x0000007d, 0xcccccccc},
439     {NZFlag, 0xfffffffd, 0xfffffffe},   {ZCFlag, 0xffff8003, 0x80000000},
440     {CFlag, 0x0000007d, 0xffff8002},    {ZVFlag, 0x0000007f, 0x00007ffe},
441     {NCVFlag, 0xffff8002, 0x00000001},  {ZCFlag, 0x80000001, 0x0000007e},
442     {NCFlag, 0x00000000, 0xaaaaaaaa},   {ZCVFlag, 0x33333333, 0x80000001},
443     {CFlag, 0x80000000, 0x0000007d},    {NCVFlag, 0x80000001, 0x80000000},
444     {ZCVFlag, 0x7ffffffe, 0xffffff82},  {ZCFlag, 0xfffffffd, 0xffff8000},
445     {ZFlag, 0x80000000, 0x55555555},    {ZVFlag, 0x0000007d, 0xffff8000},
446     {ZCFlag, 0x80000001, 0xffff8001},   {NVFlag, 0xffff8002, 0x00007ffe},
447     {ZCFlag, 0x00000000, 0xffff8000},   {CFlag, 0xffffff81, 0xffffffff},
448     {CFlag, 0xffffffff, 0x80000001},    {CFlag, 0x80000001, 0x7ffffffd},
449     {ZFlag, 0x80000001, 0x00007fff},    {ZVFlag, 0xffff8002, 0xffff8001},
450     {NZFlag, 0x80000000, 0x00007ffd},   {NZCFlag, 0x33333333, 0xcccccccc},
451     {ZCFlag, 0xffffffff, 0x33333333},   {VFlag, 0x80000001, 0x55555555},
452     {CFlag, 0xffffff82, 0x00000001},    {ZVFlag, 0xffff8003, 0xffff8001},
453     {NCVFlag, 0xffff8003, 0xffffffe0},  {ZCVFlag, 0xffffffe0, 0x7ffffffd},
454     {NFlag, 0xffff8003, 0x7ffffffe},    {VFlag, 0xffffffff, 0x00000001},
455     {CVFlag, 0xcccccccc, 0xfffffffe},   {NZVFlag, 0xffff8003, 0x0000007f},
456     {NZVFlag, 0x0000007d, 0x00000002},  {NVFlag, 0x0000007d, 0x00000000},
457     {NVFlag, 0x00000002, 0xffff8002},   {ZCVFlag, 0xffff8001, 0xfffffffd},
458     {CVFlag, 0x00007fff, 0x0000007d},   {NCFlag, 0x33333333, 0x00000002},
459     {NCVFlag, 0xcccccccc, 0xaaaaaaaa},  {CVFlag, 0x80000000, 0x00007ffd},
460     {NZFlag, 0xffffff81, 0x55555555},   {CFlag, 0xffff8003, 0x33333333},
461     {NZCVFlag, 0xffffffe0, 0xffffff82}, {NVFlag, 0x80000001, 0xfffffffd},
462     {CFlag, 0xffff8000, 0x33333333},    {NCVFlag, 0xffff8003, 0x0000007f},
463     {CFlag, 0x00000000, 0x0000007d},    {NVFlag, 0x0000007e, 0xcccccccc},
464     {NZFlag, 0x7ffffffe, 0xffffffe0},   {ZVFlag, 0xffffffe0, 0xffffff82},
465     {ZCVFlag, 0x80000001, 0x55555555},  {NZFlag, 0xcccccccc, 0xffff8001},
466     {NFlag, 0x55555555, 0x00000020},    {ZVFlag, 0x00007ffd, 0xffffff83}};
467
468static const Inputs kImmediate[] =
469    {{CFlag, 0xabababab, 0xffffff82},    {CVFlag, 0xabababab, 0x0000007f},
470     {NFlag, 0xabababab, 0x80000001},    {NZFlag, 0xabababab, 0xfffffffd},
471     {VFlag, 0xabababab, 0x7ffffffd},    {CFlag, 0xabababab, 0x7ffffffe},
472     {ZFlag, 0xabababab, 0xaaaaaaaa},    {NZVFlag, 0xabababab, 0x0000007e},
473     {NZVFlag, 0xabababab, 0x80000001},  {CFlag, 0xabababab, 0xffffff81},
474     {NZVFlag, 0xabababab, 0xfffffffd},  {NZFlag, 0xabababab, 0x00007fff},
475     {VFlag, 0xabababab, 0x00000001},    {CVFlag, 0xabababab, 0xffffffff},
476     {NZCVFlag, 0xabababab, 0xffffffff}, {CFlag, 0xabababab, 0x00000000},
477     {NZFlag, 0xabababab, 0xffffff83},   {NCFlag, 0xabababab, 0x0000007e},
478     {NZCVFlag, 0xabababab, 0x7fffffff}, {ZCVFlag, 0xabababab, 0x00000002},
479     {CFlag, 0xabababab, 0x80000000},    {NZCFlag, 0xabababab, 0x7ffffffd},
480     {ZFlag, 0xabababab, 0xffff8000},    {CFlag, 0xabababab, 0x7ffffffd},
481     {NVFlag, 0xabababab, 0x55555555},   {NZCFlag, 0xabababab, 0xfffffffd},
482     {CVFlag, 0xabababab, 0xaaaaaaaa},   {NZCVFlag, 0xabababab, 0xffff8003},
483     {NZFlag, 0xabababab, 0xffffffe0},   {NZCFlag, 0xabababab, 0x00007ffd},
484     {ZCVFlag, 0xabababab, 0xffffff80},  {NZFlag, 0xabababab, 0x7ffffffd},
485     {ZCFlag, 0xabababab, 0x7fffffff},   {ZVFlag, 0xabababab, 0xffffff81},
486     {VFlag, 0xabababab, 0x7fffffff},    {NCVFlag, 0xabababab, 0xcccccccc},
487     {ZVFlag, 0xabababab, 0x00007fff},   {NZFlag, 0xabababab, 0x00000002},
488     {NVFlag, 0xabababab, 0x00000002},   {ZVFlag, 0xabababab, 0xffff8002},
489     {NZVFlag, 0xabababab, 0x00000020},  {ZCVFlag, 0xabababab, 0xaaaaaaaa},
490     {ZCFlag, 0xabababab, 0x00000000},   {NZCVFlag, 0xabababab, 0xaaaaaaaa},
491     {NZFlag, 0xabababab, 0xfffffffe},   {NZCFlag, 0xabababab, 0xffffffe0},
492     {NFlag, 0xabababab, 0xaaaaaaaa},    {ZVFlag, 0xabababab, 0xffffff80},
493     {VFlag, 0xabababab, 0x0000007f},    {ZVFlag, 0xabababab, 0x33333333},
494     {NZFlag, 0xabababab, 0x00007ffd},   {NCFlag, 0xabababab, 0x00000002},
495     {NVFlag, 0xabababab, 0x00007ffd},   {ZFlag, 0xabababab, 0x00000001},
496     {CVFlag, 0xabababab, 0x7fffffff},   {CFlag, 0xabababab, 0xaaaaaaaa},
497     {NZCVFlag, 0xabababab, 0x80000001}, {CVFlag, 0xabababab, 0x00000002},
498     {ZVFlag, 0xabababab, 0x0000007e},   {VFlag, 0xabababab, 0xffffffff},
499     {NCFlag, 0xabababab, 0x00000001},   {NZCFlag, 0xabababab, 0xcccccccc},
500     {CVFlag, 0xabababab, 0x80000001},   {NVFlag, 0xabababab, 0xffffff82},
501     {NZCVFlag, 0xabababab, 0x0000007e}, {CFlag, 0xabababab, 0xffffffe0},
502     {ZCFlag, 0xabababab, 0xffff8002},   {NZVFlag, 0xabababab, 0x7fffffff},
503     {NZVFlag, 0xabababab, 0x33333333},  {NZCFlag, 0xabababab, 0x0000007d},
504     {NFlag, 0xabababab, 0x7ffffffe},    {ZCVFlag, 0xabababab, 0xcccccccc},
505     {ZCFlag, 0xabababab, 0xfffffffe},   {NVFlag, 0xabababab, 0x00007ffe},
506     {NZFlag, 0xabababab, 0x00007ffe},   {NCVFlag, 0xabababab, 0xffffff82},
507     {NZVFlag, 0xabababab, 0x00000002},  {ZVFlag, 0xabababab, 0x7fffffff},
508     {NZCFlag, 0xabababab, 0xffff8001},  {VFlag, 0xabababab, 0xffffff83},
509     {ZCVFlag, 0xabababab, 0x0000007e},  {NZCFlag, 0xabababab, 0xffffff83},
510     {NCFlag, 0xabababab, 0x00007fff},   {NCVFlag, 0xabababab, 0x7ffffffe},
511     {CFlag, 0xabababab, 0x00000020},    {NFlag, 0xabababab, 0x00007ffd},
512     {NZFlag, 0xabababab, 0x7fffffff},   {NZCFlag, 0xabababab, 0xffff8002},
513     {ZVFlag, 0xabababab, 0x0000007f},   {NZVFlag, 0xabababab, 0xffffff83},
514     {NZVFlag, 0xabababab, 0xffffffff},  {ZFlag, 0xabababab, 0x80000000},
515     {ZVFlag, 0xabababab, 0xffffff82},   {ZVFlag, 0xabababab, 0x80000000},
516     {NZFlag, 0xabababab, 0xaaaaaaaa},   {CFlag, 0xabababab, 0xfffffffe},
517     {NZCVFlag, 0xabababab, 0x00000000}, {VFlag, 0xabababab, 0x80000001},
518     {ZCVFlag, 0xabababab, 0xfffffffd},  {NFlag, 0xabababab, 0xffffffff},
519     {VFlag, 0xabababab, 0xcccccccc},    {NFlag, 0xabababab, 0xffff8003},
520     {NZVFlag, 0xabababab, 0xfffffffe},  {CVFlag, 0xabababab, 0xffff8001},
521     {NZVFlag, 0xabababab, 0x00007fff},  {VFlag, 0xabababab, 0x33333333},
522     {ZCVFlag, 0xabababab, 0x00007ffd},  {NCFlag, 0xabababab, 0xfffffffe},
523     {ZVFlag, 0xabababab, 0xffffff83},   {NFlag, 0xabababab, 0x00007fff},
524     {NVFlag, 0xabababab, 0x80000000},   {NCVFlag, 0xabababab, 0xffffff80},
525     {ZFlag, 0xabababab, 0x7fffffff},    {NFlag, 0xabababab, 0x00000020},
526     {NFlag, 0xabababab, 0x7ffffffd},    {NFlag, 0xabababab, 0x0000007f},
527     {NZCVFlag, 0xabababab, 0x00000020}, {NCVFlag, 0xabababab, 0xfffffffe},
528     {ZVFlag, 0xabababab, 0xcccccccc},   {NCFlag, 0xabababab, 0xffffffe0},
529     {CVFlag, 0xabababab, 0xffffff82},   {NCFlag, 0xabababab, 0x00000000},
530     {VFlag, 0xabababab, 0xffff8000},    {VFlag, 0xabababab, 0xffff8003},
531     {NCFlag, 0xabababab, 0xffffffff},   {NZCFlag, 0xabababab, 0x55555555},
532     {ZVFlag, 0xabababab, 0xfffffffe},   {NZFlag, 0xabababab, 0x7ffffffe},
533     {ZCVFlag, 0xabababab, 0x7ffffffe},  {ZVFlag, 0xabababab, 0xffffffe0},
534     {NZCFlag, 0xabababab, 0x0000007e},  {CFlag, 0xabababab, 0x7fffffff},
535     {NZVFlag, 0xabababab, 0x55555555},  {NZCVFlag, 0xabababab, 0xcccccccc},
536     {ZCVFlag, 0xabababab, 0x80000000},  {NFlag, 0xabababab, 0x55555555},
537     {ZCVFlag, 0xabababab, 0xffffffe0},  {NCFlag, 0xabababab, 0xffff8000},
538     {NCFlag, 0xabababab, 0xffff8001},   {NVFlag, 0xabababab, 0x7ffffffe},
539     {ZVFlag, 0xabababab, 0x00007ffe},   {NVFlag, 0xabababab, 0x00000020},
540     {NFlag, 0xabababab, 0x7fffffff},    {NZFlag, 0xabababab, 0x33333333},
541     {ZCFlag, 0xabababab, 0xffff8001},   {ZFlag, 0xabababab, 0xffffffe0},
542     {VFlag, 0xabababab, 0xffffffe0},    {VFlag, 0xabababab, 0xffffff80},
543     {NCVFlag, 0xabababab, 0x80000000},  {ZCFlag, 0xabababab, 0x55555555},
544     {CFlag, 0xabababab, 0xffff8001},    {CFlag, 0xabababab, 0xffff8002},
545     {ZVFlag, 0xabababab, 0xffff8000},   {CFlag, 0xabababab, 0x80000001},
546     {NZCVFlag, 0xabababab, 0x0000007d}, {NZCVFlag, 0xabababab, 0xfffffffd},
547     {CVFlag, 0xabababab, 0xffffff81},   {NVFlag, 0xabababab, 0xffff8002},
548     {ZCFlag, 0xabababab, 0x7ffffffe},   {ZCVFlag, 0xabababab, 0xffffff82},
549     {ZCVFlag, 0xabababab, 0x33333333},  {NCFlag, 0xabababab, 0x33333333},
550     {NZCVFlag, 0xabababab, 0x00000002}, {NFlag, 0xabababab, 0x00000001},
551     {NVFlag, 0xabababab, 0xffff8003},   {NZCVFlag, 0xabababab, 0x00000001},
552     {CFlag, 0xabababab, 0xffff8003},    {NVFlag, 0xabababab, 0x0000007e},
553     {CVFlag, 0xabababab, 0x80000000},   {ZFlag, 0xabababab, 0xffffffff},
554     {NFlag, 0xabababab, 0xfffffffd},    {NVFlag, 0xabababab, 0x00007fff},
555     {NZCVFlag, 0xabababab, 0x7ffffffd}, {NZVFlag, 0xabababab, 0x00000000},
556     {NZCFlag, 0xabababab, 0xfffffffe},  {ZVFlag, 0xabababab, 0x7ffffffe},
557     {CFlag, 0xabababab, 0xffffffff},    {ZCFlag, 0xabababab, 0xffffff82},
558     {ZCFlag, 0xabababab, 0xffffff83},   {ZCFlag, 0xabababab, 0x00000002},
559     {NZFlag, 0xabababab, 0x0000007e},   {NZCVFlag, 0xabababab, 0xffffffe0},
560     {NZFlag, 0xabababab, 0x00000001},   {ZVFlag, 0xabababab, 0x55555555},
561     {ZCVFlag, 0xabababab, 0x00007fff},  {NFlag, 0xabababab, 0x33333333},
562     {ZFlag, 0xabababab, 0x00000000},    {NVFlag, 0xabababab, 0x7fffffff},
563     {ZVFlag, 0xabababab, 0xfffffffd},   {ZFlag, 0xabababab, 0x00000020},
564     {NCVFlag, 0xabababab, 0xfffffffd},  {NZCFlag, 0xabababab, 0x80000000},
565     {NVFlag, 0xabababab, 0x80000001},   {ZFlag, 0xabababab, 0xffff8002},
566     {NZCVFlag, 0xabababab, 0xffff8001}, {NFlag, 0xabababab, 0xfffffffe},
567     {ZVFlag, 0xabababab, 0x0000007d},   {NCFlag, 0xabababab, 0x00007ffd},
568     {NFlag, 0xabababab, 0xffff8001},    {NZCFlag, 0xabababab, 0xaaaaaaaa},
569     {NZCFlag, 0xabababab, 0x00000020},  {ZCVFlag, 0xabababab, 0x7fffffff},
570     {ZCVFlag, 0xabababab, 0x00000001},  {NVFlag, 0xabababab, 0xcccccccc},
571     {NFlag, 0xabababab, 0x80000000},    {NFlag, 0xabababab, 0xffffffe0},
572     {ZCFlag, 0xabababab, 0xffffffff},   {CVFlag, 0xabababab, 0x00000000},
573     {ZCFlag, 0xabababab, 0xffff8000},   {ZCFlag, 0xabababab, 0x00007ffd},
574     {NCFlag, 0xabababab, 0x0000007f},   {ZVFlag, 0xabababab, 0x00000020},
575     {VFlag, 0xabababab, 0xffff8002},    {ZFlag, 0xabababab, 0xffffff81},
576     {CVFlag, 0xabababab, 0xffff8003},   {NFlag, 0xabababab, 0xffffff80},
577     {NVFlag, 0xabababab, 0xaaaaaaaa},   {CFlag, 0xabababab, 0x00000001},
578     {ZCVFlag, 0xabababab, 0xffff8003},  {NCFlag, 0xabababab, 0xfffffffd},
579     {CVFlag, 0xabababab, 0xffffff83},   {ZCFlag, 0xabababab, 0xfffffffd},
580     {CVFlag, 0xabababab, 0x0000007d},   {ZCVFlag, 0xabababab, 0xffffff83},
581     {NCFlag, 0xabababab, 0xffffff81},   {NFlag, 0xabababab, 0xffff8000},
582     {NZFlag, 0xabababab, 0x80000001},   {NCFlag, 0xabababab, 0x55555555},
583     {NCVFlag, 0xabababab, 0xaaaaaaaa},  {NZCFlag, 0xabababab, 0xffffffff},
584     {ZFlag, 0xabababab, 0x33333333},    {NCFlag, 0xabababab, 0xffffff82},
585     {NZFlag, 0xabababab, 0xffff8001},   {VFlag, 0xabababab, 0x7ffffffe},
586     {NZCVFlag, 0xabababab, 0x7ffffffe}, {ZFlag, 0xabababab, 0x80000001},
587     {NVFlag, 0xabababab, 0xffffff80},   {NFlag, 0xabababab, 0x0000007e},
588     {NCVFlag, 0xabababab, 0x00007ffd},  {CFlag, 0xabababab, 0x0000007e},
589     {NZVFlag, 0xabababab, 0xcccccccc},  {NZVFlag, 0xabababab, 0x0000007f},
590     {ZFlag, 0xabababab, 0xffffff83},    {VFlag, 0xabababab, 0xaaaaaaaa},
591     {ZVFlag, 0xabababab, 0x7ffffffd},   {ZVFlag, 0xabababab, 0xffffffff},
592     {NZCVFlag, 0xabababab, 0x0000007f}, {NCVFlag, 0xabababab, 0x0000007e},
593     {NZVFlag, 0xabababab, 0xffffff82},  {CFlag, 0xabababab, 0xffffff80},
594     {NZCVFlag, 0xabababab, 0x80000000}, {NZVFlag, 0xabababab, 0x7ffffffe},
595     {NZFlag, 0xabababab, 0xffffff80},   {NZFlag, 0xabababab, 0xffff8000},
596     {NCFlag, 0xabababab, 0xaaaaaaaa},   {NFlag, 0xabababab, 0x00000000},
597     {NZFlag, 0xabababab, 0xcccccccc},   {ZCFlag, 0xabababab, 0xffffffe0},
598     {CVFlag, 0xabababab, 0xcccccccc},   {VFlag, 0xabababab, 0xfffffffd},
599     {CVFlag, 0xabababab, 0x7ffffffd},   {ZCFlag, 0xabababab, 0x00000020},
600     {CVFlag, 0xabababab, 0x00007ffe},   {ZCFlag, 0xabababab, 0xffffff80},
601     {NVFlag, 0xabababab, 0xfffffffd},   {NZCFlag, 0xabababab, 0x00000001},
602     {CVFlag, 0xabababab, 0x00000001},   {NVFlag, 0xabababab, 0xffffff83},
603     {ZCVFlag, 0xabababab, 0x7ffffffd},  {NZVFlag, 0xabababab, 0xffff8000},
604     {CVFlag, 0xabababab, 0xffffffe0},   {NCFlag, 0xabababab, 0x0000007d},
605     {VFlag, 0xabababab, 0x00007ffd},    {NZCFlag, 0xabababab, 0xffffff81},
606     {NCVFlag, 0xabababab, 0x00007fff},  {NVFlag, 0xabababab, 0x0000007f},
607     {CFlag, 0xabababab, 0xcccccccc},    {ZFlag, 0xabababab, 0xcccccccc},
608     {ZCFlag, 0xabababab, 0x80000000},   {VFlag, 0xabababab, 0x0000007d},
609     {NFlag, 0xabababab, 0xcccccccc},    {NCFlag, 0xabababab, 0x7fffffff},
610     {VFlag, 0xabababab, 0xffffff81},    {NCVFlag, 0xabababab, 0xffffffff},
611     {NZFlag, 0xabababab, 0xffff8002},   {NZVFlag, 0xabababab, 0x80000000},
612     {ZCVFlag, 0xabababab, 0x0000007f},  {ZFlag, 0xabababab, 0x0000007f},
613     {VFlag, 0xabababab, 0xffff8001},    {NVFlag, 0xabababab, 0x00000000},
614     {ZFlag, 0xabababab, 0x00007ffd},    {NCVFlag, 0xabababab, 0x80000001},
615     {NCVFlag, 0xabababab, 0xffff8002},  {NCFlag, 0xabababab, 0x7ffffffe},
616     {ZCFlag, 0xabababab, 0x7ffffffd},   {NZCFlag, 0xabababab, 0x80000001},
617     {ZCFlag, 0xabababab, 0x0000007f},   {VFlag, 0xabababab, 0x80000000},
618     {NCFlag, 0xabababab, 0x80000001},   {NVFlag, 0xabababab, 0xffffff81}};
619
620
621// A loop will be generated for each element of this array.
622const TestLoopData kTests[] = {{{ne, r2, r2, 45},
623                                "ne r2 r2 45",
624                                "RdIsRn_ne_r2_r2_45",
625                                ARRAY_SIZE(kRdIsRn),
626                                kRdIsRn},
627                               {{cs, r6, r6, 59},
628                                "cs r6 r6 59",
629                                "RdIsRn_cs_r6_r6_59",
630                                ARRAY_SIZE(kRdIsRn),
631                                kRdIsRn},
632                               {{mi, r6, r6, 211},
633                                "mi r6 r6 211",
634                                "RdIsRn_mi_r6_r6_211",
635                                ARRAY_SIZE(kRdIsRn),
636                                kRdIsRn},
637                               {{lt, r5, r5, 36},
638                                "lt r5 r5 36",
639                                "RdIsRn_lt_r5_r5_36",
640                                ARRAY_SIZE(kRdIsRn),
641                                kRdIsRn},
642                               {{cc, r7, r7, 7},
643                                "cc r7 r7 7",
644                                "RdIsRn_cc_r7_r7_7",
645                                ARRAY_SIZE(kRdIsRn),
646                                kRdIsRn},
647                               {{cs, r7, r7, 215},
648                                "cs r7 r7 215",
649                                "RdIsRn_cs_r7_r7_215",
650                                ARRAY_SIZE(kRdIsRn),
651                                kRdIsRn},
652                               {{pl, r6, r6, 54},
653                                "pl r6 r6 54",
654                                "RdIsRn_pl_r6_r6_54",
655                                ARRAY_SIZE(kRdIsRn),
656                                kRdIsRn},
657                               {{lt, r6, r6, 221},
658                                "lt r6 r6 221",
659                                "RdIsRn_lt_r6_r6_221",
660                                ARRAY_SIZE(kRdIsRn),
661                                kRdIsRn},
662                               {{ne, r2, r2, 40},
663                                "ne r2 r2 40",
664                                "RdIsRn_ne_r2_r2_40",
665                                ARRAY_SIZE(kRdIsRn),
666                                kRdIsRn},
667                               {{hi, r5, r5, 158},
668                                "hi r5 r5 158",
669                                "RdIsRn_hi_r5_r5_158",
670                                ARRAY_SIZE(kRdIsRn),
671                                kRdIsRn},
672                               {{cs, r0, r0, 18},
673                                "cs r0 r0 18",
674                                "RdIsRn_cs_r0_r0_18",
675                                ARRAY_SIZE(kRdIsRn),
676                                kRdIsRn},
677                               {{ne, r3, r3, 205},
678                                "ne r3 r3 205",
679                                "RdIsRn_ne_r3_r3_205",
680                                ARRAY_SIZE(kRdIsRn),
681                                kRdIsRn},
682                               {{vc, r0, r0, 97},
683                                "vc r0 r0 97",
684                                "RdIsRn_vc_r0_r0_97",
685                                ARRAY_SIZE(kRdIsRn),
686                                kRdIsRn},
687                               {{hi, r2, r2, 197},
688                                "hi r2 r2 197",
689                                "RdIsRn_hi_r2_r2_197",
690                                ARRAY_SIZE(kRdIsRn),
691                                kRdIsRn},
692                               {{cs, r0, r0, 248},
693                                "cs r0 r0 248",
694                                "RdIsRn_cs_r0_r0_248",
695                                ARRAY_SIZE(kRdIsRn),
696                                kRdIsRn},
697                               {{ne, r4, r4, 108},
698                                "ne r4 r4 108",
699                                "RdIsRn_ne_r4_r4_108",
700                                ARRAY_SIZE(kRdIsRn),
701                                kRdIsRn},
702                               {{vs, r3, r3, 73},
703                                "vs r3 r3 73",
704                                "RdIsRn_vs_r3_r3_73",
705                                ARRAY_SIZE(kRdIsRn),
706                                kRdIsRn},
707                               {{ne, r7, r7, 230},
708                                "ne r7 r7 230",
709                                "RdIsRn_ne_r7_r7_230",
710                                ARRAY_SIZE(kRdIsRn),
711                                kRdIsRn},
712                               {{eq, r0, r0, 100},
713                                "eq r0 r0 100",
714                                "RdIsRn_eq_r0_r0_100",
715                                ARRAY_SIZE(kRdIsRn),
716                                kRdIsRn},
717                               {{mi, r5, r5, 211},
718                                "mi r5 r5 211",
719                                "RdIsRn_mi_r5_r5_211",
720                                ARRAY_SIZE(kRdIsRn),
721                                kRdIsRn},
722                               {{ge, r2, r3, 225},
723                                "ge r2 r3 225",
724                                "RdIsNotRn_ge_r2_r3_225",
725                                ARRAY_SIZE(kRdIsNotRn),
726                                kRdIsNotRn},
727                               {{vs, r3, r1, 64},
728                                "vs r3 r1 64",
729                                "RdIsNotRn_vs_r3_r1_64",
730                                ARRAY_SIZE(kRdIsNotRn),
731                                kRdIsNotRn},
732                               {{vs, r0, r1, 93},
733                                "vs r0 r1 93",
734                                "RdIsNotRn_vs_r0_r1_93",
735                                ARRAY_SIZE(kRdIsNotRn),
736                                kRdIsNotRn},
737                               {{ne, r5, r1, 247},
738                                "ne r5 r1 247",
739                                "RdIsNotRn_ne_r5_r1_247",
740                                ARRAY_SIZE(kRdIsNotRn),
741                                kRdIsNotRn},
742                               {{vs, r1, r7, 9},
743                                "vs r1 r7 9",
744                                "RdIsNotRn_vs_r1_r7_9",
745                                ARRAY_SIZE(kRdIsNotRn),
746                                kRdIsNotRn},
747                               {{le, r0, r2, 201},
748                                "le r0 r2 201",
749                                "RdIsNotRn_le_r0_r2_201",
750                                ARRAY_SIZE(kRdIsNotRn),
751                                kRdIsNotRn},
752                               {{vs, r6, r0, 176},
753                                "vs r6 r0 176",
754                                "RdIsNotRn_vs_r6_r0_176",
755                                ARRAY_SIZE(kRdIsNotRn),
756                                kRdIsNotRn},
757                               {{vc, r0, r1, 248},
758                                "vc r0 r1 248",
759                                "RdIsNotRn_vc_r0_r1_248",
760                                ARRAY_SIZE(kRdIsNotRn),
761                                kRdIsNotRn},
762                               {{al, r7, r6, 64},
763                                "al r7 r6 64",
764                                "RdIsNotRn_al_r7_r6_64",
765                                ARRAY_SIZE(kRdIsNotRn),
766                                kRdIsNotRn},
767                               {{al, r5, r7, 175},
768                                "al r5 r7 175",
769                                "RdIsNotRn_al_r5_r7_175",
770                                ARRAY_SIZE(kRdIsNotRn),
771                                kRdIsNotRn},
772                               {{al, r0, r4, 182},
773                                "al r0 r4 182",
774                                "RdIsNotRn_al_r0_r4_182",
775                                ARRAY_SIZE(kRdIsNotRn),
776                                kRdIsNotRn},
777                               {{ls, r7, r5, 58},
778                                "ls r7 r5 58",
779                                "RdIsNotRn_ls_r7_r5_58",
780                                ARRAY_SIZE(kRdIsNotRn),
781                                kRdIsNotRn},
782                               {{vc, r0, r7, 205},
783                                "vc r0 r7 205",
784                                "RdIsNotRn_vc_r0_r7_205",
785                                ARRAY_SIZE(kRdIsNotRn),
786                                kRdIsNotRn},
787                               {{pl, r1, r3, 135},
788                                "pl r1 r3 135",
789                                "RdIsNotRn_pl_r1_r3_135",
790                                ARRAY_SIZE(kRdIsNotRn),
791                                kRdIsNotRn},
792                               {{gt, r4, r3, 253},
793                                "gt r4 r3 253",
794                                "RdIsNotRn_gt_r4_r3_253",
795                                ARRAY_SIZE(kRdIsNotRn),
796                                kRdIsNotRn},
797                               {{al, r1, r7, 32},
798                                "al r1 r7 32",
799                                "RdIsNotRn_al_r1_r7_32",
800                                ARRAY_SIZE(kRdIsNotRn),
801                                kRdIsNotRn},
802                               {{eq, r1, r7, 139},
803                                "eq r1 r7 139",
804                                "RdIsNotRn_eq_r1_r7_139",
805                                ARRAY_SIZE(kRdIsNotRn),
806                                kRdIsNotRn},
807                               {{lt, r0, r5, 248},
808                                "lt r0 r5 248",
809                                "RdIsNotRn_lt_r0_r5_248",
810                                ARRAY_SIZE(kRdIsNotRn),
811                                kRdIsNotRn},
812                               {{hi, r0, r6, 89},
813                                "hi r0 r6 89",
814                                "RdIsNotRn_hi_r0_r6_89",
815                                ARRAY_SIZE(kRdIsNotRn),
816                                kRdIsNotRn},
817                               {{cc, r3, r5, 210},
818                                "cc r3 r5 210",
819                                "RdIsNotRn_cc_r3_r5_210",
820                                ARRAY_SIZE(kRdIsNotRn),
821                                kRdIsNotRn},
822                               {{cs, r0, r0, 187},
823                                "cs r0 r0 187",
824                                "Immediate_cs_r0_r0_187",
825                                ARRAY_SIZE(kImmediate),
826                                kImmediate},
827                               {{hi, r0, r0, 236},
828                                "hi r0 r0 236",
829                                "Immediate_hi_r0_r0_236",
830                                ARRAY_SIZE(kImmediate),
831                                kImmediate},
832                               {{eq, r0, r0, 133},
833                                "eq r0 r0 133",
834                                "Immediate_eq_r0_r0_133",
835                                ARRAY_SIZE(kImmediate),
836                                kImmediate},
837                               {{mi, r0, r0, 193},
838                                "mi r0 r0 193",
839                                "Immediate_mi_r0_r0_193",
840                                ARRAY_SIZE(kImmediate),
841                                kImmediate},
842                               {{cc, r0, r0, 73},
843                                "cc r0 r0 73",
844                                "Immediate_cc_r0_r0_73",
845                                ARRAY_SIZE(kImmediate),
846                                kImmediate},
847                               {{cs, r0, r0, 93},
848                                "cs r0 r0 93",
849                                "Immediate_cs_r0_r0_93",
850                                ARRAY_SIZE(kImmediate),
851                                kImmediate},
852                               {{ne, r0, r0, 130},
853                                "ne r0 r0 130",
854                                "Immediate_ne_r0_r0_130",
855                                ARRAY_SIZE(kImmediate),
856                                kImmediate},
857                               {{ge, r0, r0, 209},
858                                "ge r0 r0 209",
859                                "Immediate_ge_r0_r0_209",
860                                ARRAY_SIZE(kImmediate),
861                                kImmediate},
862                               {{lt, r0, r0, 42},
863                                "lt r0 r0 42",
864                                "Immediate_lt_r0_r0_42",
865                                ARRAY_SIZE(kImmediate),
866                                kImmediate},
867                               {{cs, r0, r0, 177},
868                                "cs r0 r0 177",
869                                "Immediate_cs_r0_r0_177",
870                                ARRAY_SIZE(kImmediate),
871                                kImmediate},
872                               {{lt, r0, r0, 139},
873                                "lt r0 r0 139",
874                                "Immediate_lt_r0_r0_139",
875                                ARRAY_SIZE(kImmediate),
876                                kImmediate},
877                               {{mi, r0, r0, 43},
878                                "mi r0 r0 43",
879                                "Immediate_mi_r0_r0_43",
880                                ARRAY_SIZE(kImmediate),
881                                kImmediate},
882                               {{cs, r0, r0, 247},
883                                "cs r0 r0 247",
884                                "Immediate_cs_r0_r0_247",
885                                ARRAY_SIZE(kImmediate),
886                                kImmediate},
887                               {{ls, r0, r0, 170},
888                                "ls r0 r0 170",
889                                "Immediate_ls_r0_r0_170",
890                                ARRAY_SIZE(kImmediate),
891                                kImmediate},
892                               {{cs, r0, r0, 185},
893                                "cs r0 r0 185",
894                                "Immediate_cs_r0_r0_185",
895                                ARRAY_SIZE(kImmediate),
896                                kImmediate},
897                               {{ne, r0, r0, 246},
898                                "ne r0 r0 246",
899                                "Immediate_ne_r0_r0_246",
900                                ARRAY_SIZE(kImmediate),
901                                kImmediate},
902                               {{mi, r0, r0, 179},
903                                "mi r0 r0 179",
904                                "Immediate_mi_r0_r0_179",
905                                ARRAY_SIZE(kImmediate),
906                                kImmediate},
907                               {{pl, r0, r0, 7},
908                                "pl r0 r0 7",
909                                "Immediate_pl_r0_r0_7",
910                                ARRAY_SIZE(kImmediate),
911                                kImmediate},
912                               {{mi, r0, r0, 177},
913                                "mi r0 r0 177",
914                                "Immediate_mi_r0_r0_177",
915                                ARRAY_SIZE(kImmediate),
916                                kImmediate},
917                               {{gt, r0, r0, 175},
918                                "gt r0 r0 175",
919                                "Immediate_gt_r0_r0_175",
920                                ARRAY_SIZE(kImmediate),
921                                kImmediate}};
922
923// We record all inputs to the instructions as outputs. This way, we also check
924// that what shouldn't change didn't change.
925struct TestResult {
926  size_t output_size;
927  const Inputs* outputs;
928};
929
930// These headers each contain an array of `TestResult` with the reference output
931// values. The reference arrays are names `kReference{mnemonic}`.
932#include "aarch32/traces/simulator-cond-rdlow-rnlow-operand-immediate-add-t32.h"
933#include "aarch32/traces/simulator-cond-rdlow-rnlow-operand-immediate-adds-t32.h"
934#include "aarch32/traces/simulator-cond-rdlow-rnlow-operand-immediate-rsb-t32.h"
935#include "aarch32/traces/simulator-cond-rdlow-rnlow-operand-immediate-rsbs-t32.h"
936#include "aarch32/traces/simulator-cond-rdlow-rnlow-operand-immediate-sub-t32.h"
937#include "aarch32/traces/simulator-cond-rdlow-rnlow-operand-immediate-subs-t32.h"
938
939
940// The maximum number of errors to report in detail for each test.
941const unsigned kErrorReportLimit = 8;
942
943typedef void (MacroAssembler::*Fn)(Condition cond,
944                                   Register rd,
945                                   Register rn,
946                                   const Operand& op);
947
948void TestHelper(Fn instruction,
949                const char* mnemonic,
950                const TestResult reference[]) {
951  SETUP();
952  masm.UseT32();
953  START();
954
955  // Data to compare to `reference`.
956  TestResult* results[ARRAY_SIZE(kTests)];
957
958  // Test cases for memory bound instructions may allocate a buffer and save its
959  // address in this array.
960  byte* scratch_memory_buffers[ARRAY_SIZE(kTests)];
961
962  // Generate a loop for each element in `kTests`. Each loop tests one specific
963  // instruction.
964  for (unsigned i = 0; i < ARRAY_SIZE(kTests); i++) {
965    // Allocate results on the heap for this test.
966    results[i] = new TestResult;
967    results[i]->outputs = new Inputs[kTests[i].input_size];
968    results[i]->output_size = kTests[i].input_size;
969
970    size_t input_stride = sizeof(kTests[i].inputs[0]) * kTests[i].input_size;
971    VIXL_ASSERT(IsUint32(input_stride));
972
973    scratch_memory_buffers[i] = NULL;
974
975    Label loop;
976    UseScratchRegisterScope scratch_registers(&masm);
977    // Include all registers from r0 ro r12.
978    scratch_registers.Include(RegisterList(0x1fff));
979
980    // Values to pass to the macro-assembler.
981    Condition cond = kTests[i].operands.cond;
982    Register rd = kTests[i].operands.rd;
983    Register rn = kTests[i].operands.rn;
984    int32_t immediate = kTests[i].operands.immediate;
985    Operand op(immediate);
986    scratch_registers.Exclude(rd);
987    scratch_registers.Exclude(rn);
988
989    // Allocate reserved registers for our own use.
990    Register input_ptr = scratch_registers.Acquire();
991    Register input_end = scratch_registers.Acquire();
992    Register result_ptr = scratch_registers.Acquire();
993
994    // Initialize `input_ptr` to the first element and `input_end` the address
995    // after the array.
996    __ Mov(input_ptr, Operand::From(kTests[i].inputs));
997    __ Add(input_end, input_ptr, static_cast<uint32_t>(input_stride));
998    __ Mov(result_ptr, Operand::From(results[i]->outputs));
999    __ Bind(&loop);
1000
1001    {
1002      UseScratchRegisterScope temp_registers(&masm);
1003      Register nzcv_bits = temp_registers.Acquire();
1004      Register saved_q_bit = temp_registers.Acquire();
1005      // Save the `Q` bit flag.
1006      __ Mrs(saved_q_bit, APSR);
1007      __ And(saved_q_bit, saved_q_bit, QFlag);
1008      // Set the `NZCV` and `Q` flags together.
1009      __ Ldr(nzcv_bits, MemOperand(input_ptr, offsetof(Inputs, apsr)));
1010      __ Orr(nzcv_bits, nzcv_bits, saved_q_bit);
1011      __ Msr(APSR_nzcvq, nzcv_bits);
1012    }
1013    __ Ldr(rd, MemOperand(input_ptr, offsetof(Inputs, rd)));
1014    __ Ldr(rn, MemOperand(input_ptr, offsetof(Inputs, rn)));
1015
1016    (masm.*instruction)(cond, rd, rn, op);
1017
1018    {
1019      UseScratchRegisterScope temp_registers(&masm);
1020      Register nzcv_bits = temp_registers.Acquire();
1021      __ Mrs(nzcv_bits, APSR);
1022      // Only record the NZCV bits.
1023      __ And(nzcv_bits, nzcv_bits, NZCVFlag);
1024      __ Str(nzcv_bits, MemOperand(result_ptr, offsetof(Inputs, apsr)));
1025    }
1026    __ Str(rd, MemOperand(result_ptr, offsetof(Inputs, rd)));
1027    __ Str(rn, MemOperand(result_ptr, offsetof(Inputs, rn)));
1028
1029    // Advance the result pointer.
1030    __ Add(result_ptr, result_ptr, Operand::From(sizeof(kTests[i].inputs[0])));
1031    // Loop back until `input_ptr` is lower than `input_base`.
1032    __ Add(input_ptr, input_ptr, Operand::From(sizeof(kTests[i].inputs[0])));
1033    __ Cmp(input_ptr, input_end);
1034    __ B(ne, &loop);
1035  }
1036
1037  END();
1038
1039  RUN();
1040
1041  if (Test::generate_test_trace()) {
1042    // Print the results.
1043    for (size_t i = 0; i < ARRAY_SIZE(kTests); i++) {
1044      printf("const Inputs kOutputs_%s_%s[] = {\n",
1045             mnemonic,
1046             kTests[i].identifier);
1047      for (size_t j = 0; j < results[i]->output_size; j++) {
1048        printf("  { ");
1049        printf("0x%08" PRIx32, results[i]->outputs[j].apsr);
1050        printf(", ");
1051        printf("0x%08" PRIx32, results[i]->outputs[j].rd);
1052        printf(", ");
1053        printf("0x%08" PRIx32, results[i]->outputs[j].rn);
1054        printf(" },\n");
1055      }
1056      printf("};\n");
1057    }
1058    printf("const TestResult kReference%s[] = {\n", mnemonic);
1059    for (size_t i = 0; i < ARRAY_SIZE(kTests); i++) {
1060      printf("  {\n");
1061      printf("    ARRAY_SIZE(kOutputs_%s_%s),\n",
1062             mnemonic,
1063             kTests[i].identifier);
1064      printf("    kOutputs_%s_%s,\n", mnemonic, kTests[i].identifier);
1065      printf("  },\n");
1066    }
1067    printf("};\n");
1068  } else if (kCheckSimulatorTestResults) {
1069    // Check the results.
1070    unsigned total_error_count = 0;
1071    for (size_t i = 0; i < ARRAY_SIZE(kTests); i++) {
1072      bool instruction_has_errors = false;
1073      for (size_t j = 0; j < kTests[i].input_size; j++) {
1074        uint32_t apsr = results[i]->outputs[j].apsr;
1075        uint32_t rd = results[i]->outputs[j].rd;
1076        uint32_t rn = results[i]->outputs[j].rn;
1077        uint32_t apsr_input = kTests[i].inputs[j].apsr;
1078        uint32_t rd_input = kTests[i].inputs[j].rd;
1079        uint32_t rn_input = kTests[i].inputs[j].rn;
1080        uint32_t apsr_ref = reference[i].outputs[j].apsr;
1081        uint32_t rd_ref = reference[i].outputs[j].rd;
1082        uint32_t rn_ref = reference[i].outputs[j].rn;
1083
1084        if (((apsr != apsr_ref) || (rd != rd_ref) || (rn != rn_ref)) &&
1085            (++total_error_count <= kErrorReportLimit)) {
1086          // Print the instruction once even if it triggered multiple failures.
1087          if (!instruction_has_errors) {
1088            printf("Error(s) when testing \"%s %s\":\n",
1089                   mnemonic,
1090                   kTests[i].operands_description);
1091            instruction_has_errors = true;
1092          }
1093          // Print subsequent errors.
1094          printf("  Input:    ");
1095          printf("0x%08" PRIx32, apsr_input);
1096          printf(", ");
1097          printf("0x%08" PRIx32, rd_input);
1098          printf(", ");
1099          printf("0x%08" PRIx32, rn_input);
1100          printf("\n");
1101          printf("  Expected: ");
1102          printf("0x%08" PRIx32, apsr_ref);
1103          printf(", ");
1104          printf("0x%08" PRIx32, rd_ref);
1105          printf(", ");
1106          printf("0x%08" PRIx32, rn_ref);
1107          printf("\n");
1108          printf("  Found:    ");
1109          printf("0x%08" PRIx32, apsr);
1110          printf(", ");
1111          printf("0x%08" PRIx32, rd);
1112          printf(", ");
1113          printf("0x%08" PRIx32, rn);
1114          printf("\n\n");
1115        }
1116      }
1117    }
1118
1119    if (total_error_count > kErrorReportLimit) {
1120      printf("%u other errors follow.\n",
1121             total_error_count - kErrorReportLimit);
1122    }
1123    VIXL_CHECK(total_error_count == 0);
1124  } else {
1125    VIXL_WARNING("Assembled the code, but did not run anything.\n");
1126  }
1127
1128  for (size_t i = 0; i < ARRAY_SIZE(kTests); i++) {
1129    delete[] results[i]->outputs;
1130    delete results[i];
1131    delete[] scratch_memory_buffers[i];
1132  }
1133}
1134
1135// Instantiate tests for each instruction in the list.
1136// TODO: Remove this limitation by having a sandboxing mechanism.
1137#if defined(VIXL_HOST_POINTER_32)
1138#define TEST(mnemonic)                                                      \
1139  void Test_##mnemonic() {                                                  \
1140    TestHelper(&MacroAssembler::mnemonic, #mnemonic, kReference##mnemonic); \
1141  }                                                                         \
1142  Test test_##mnemonic(                                                     \
1143      "AARCH32_SIMULATOR_COND_RDLOW_RNLOW_OPERAND_IMMEDIATE_" #mnemonic     \
1144      "_T32",                                                               \
1145      &Test_##mnemonic);
1146#else
1147#define TEST(mnemonic)                                                  \
1148  void Test_##mnemonic() {                                              \
1149    VIXL_WARNING("This test can only run on a 32-bit host.\n");         \
1150    USE(TestHelper);                                                    \
1151  }                                                                     \
1152  Test test_##mnemonic(                                                 \
1153      "AARCH32_SIMULATOR_COND_RDLOW_RNLOW_OPERAND_IMMEDIATE_" #mnemonic \
1154      "_T32",                                                           \
1155      &Test_##mnemonic);
1156#endif
1157
1158FOREACH_INSTRUCTION(TEST)
1159#undef TEST
1160
1161}  // namespace
1162#endif
1163
1164}  // namespace aarch32
1165}  // namespace vixl
1166