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