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