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