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-assembler-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 
     45 #define BUF_SIZE (4096)
     46 
     47 namespace vixl {
     48 namespace aarch32 {
     49 
     50 // List of instruction mnemonics.
     51 #define FOREACH_INSTRUCTION(M) \
     52   M(vceq)                      \
     53   M(vpadd)                     \
     54   M(vabd)                      \
     55   M(vcge)                      \
     56   M(vcgt)                      \
     57   M(vcle)                      \
     58   M(vclt)                      \
     59   M(vmax)                      \
     60   M(vmin)                      \
     61   M(vpmax)                     \
     62   M(vpmin)
     63 
     64 
     65 // The following definitions are defined again in each generated test, therefore
     66 // we need to place them in an anomymous namespace. It expresses that they are
     67 // local to this file only, and the compiler is not allowed to share these types
     68 // across test files during template instantiation. Specifically, `Operands` has
     69 // various layouts across generated tests so it absolutely cannot be shared.
     70 
     71 #ifdef VIXL_INCLUDE_TARGET_A32
     72 namespace {
     73 
     74 // Values to be passed to the assembler to produce the instruction under test.
     75 struct Operands {
     76   DataType dt;
     77   DRegister rd;
     78   DRegister rn;
     79   DRegister rm;
     80 };
     81 
     82 // This structure contains all data needed to test one specific
     83 // instruction.
     84 struct TestData {
     85   // The `operands` field represents what to pass to the assembler to
     86   // produce the instruction.
     87   Operands operands;
     88   // True if we need to generate an IT instruction for this test to be valid.
     89   bool in_it_block;
     90   // The condition to give the IT instruction, this will be set to "al" by
     91   // default.
     92   Condition it_condition;
     93   // Description of the operands, used for error reporting.
     94   const char* operands_description;
     95   // Unique identifier, used for generating traces.
     96   const char* identifier;
     97 };
     98 
     99 struct TestResult {
    100   size_t size;
    101   const byte* encoding;
    102 };
    103 
    104 // Each element of this array produce one instruction encoding.
    105 const TestData kTests[] =
    106     {{{F32, d1, d2, d30}, false, al, "F32 d1 d2 d30", "F32_d1_d2_d30"},
    107      {{F32, d12, d5, d13}, false, al, "F32 d12 d5 d13", "F32_d12_d5_d13"},
    108      {{F32, d3, d16, d2}, false, al, "F32 d3 d16 d2", "F32_d3_d16_d2"},
    109      {{F32, d21, d26, d7}, false, al, "F32 d21 d26 d7", "F32_d21_d26_d7"},
    110      {{F32, d30, d1, d16}, false, al, "F32 d30 d1 d16", "F32_d30_d1_d16"},
    111      {{F32, d17, d8, d6}, false, al, "F32 d17 d8 d6", "F32_d17_d8_d6"},
    112      {{F32, d26, d1, d7}, false, al, "F32 d26 d1 d7", "F32_d26_d1_d7"},
    113      {{F32, d17, d6, d28}, false, al, "F32 d17 d6 d28", "F32_d17_d6_d28"},
    114      {{F32, d30, d6, d27}, false, al, "F32 d30 d6 d27", "F32_d30_d6_d27"},
    115      {{F32, d6, d13, d11}, false, al, "F32 d6 d13 d11", "F32_d6_d13_d11"},
    116      {{F32, d30, d17, d15}, false, al, "F32 d30 d17 d15", "F32_d30_d17_d15"},
    117      {{F32, d10, d8, d14}, false, al, "F32 d10 d8 d14", "F32_d10_d8_d14"},
    118      {{F32, d17, d4, d0}, false, al, "F32 d17 d4 d0", "F32_d17_d4_d0"},
    119      {{F32, d25, d5, d14}, false, al, "F32 d25 d5 d14", "F32_d25_d5_d14"},
    120      {{F32, d30, d16, d0}, false, al, "F32 d30 d16 d0", "F32_d30_d16_d0"},
    121      {{F32, d22, d21, d2}, false, al, "F32 d22 d21 d2", "F32_d22_d21_d2"},
    122      {{F32, d15, d10, d12}, false, al, "F32 d15 d10 d12", "F32_d15_d10_d12"},
    123      {{F32, d6, d26, d20}, false, al, "F32 d6 d26 d20", "F32_d6_d26_d20"},
    124      {{F32, d2, d7, d6}, false, al, "F32 d2 d7 d6", "F32_d2_d7_d6"},
    125      {{F32, d27, d13, d30}, false, al, "F32 d27 d13 d30", "F32_d27_d13_d30"},
    126      {{F32, d6, d12, d13}, false, al, "F32 d6 d12 d13", "F32_d6_d12_d13"},
    127      {{F32, d6, d17, d17}, false, al, "F32 d6 d17 d17", "F32_d6_d17_d17"},
    128      {{F32, d18, d7, d6}, false, al, "F32 d18 d7 d6", "F32_d18_d7_d6"},
    129      {{F32, d24, d18, d8}, false, al, "F32 d24 d18 d8", "F32_d24_d18_d8"},
    130      {{F32, d27, d3, d3}, false, al, "F32 d27 d3 d3", "F32_d27_d3_d3"},
    131      {{F32, d20, d12, d4}, false, al, "F32 d20 d12 d4", "F32_d20_d12_d4"},
    132      {{F32, d16, d23, d26}, false, al, "F32 d16 d23 d26", "F32_d16_d23_d26"},
    133      {{F32, d14, d24, d11}, false, al, "F32 d14 d24 d11", "F32_d14_d24_d11"},
    134      {{F32, d14, d29, d28}, false, al, "F32 d14 d29 d28", "F32_d14_d29_d28"},
    135      {{F32, d20, d16, d11}, false, al, "F32 d20 d16 d11", "F32_d20_d16_d11"},
    136      {{F32, d28, d21, d9}, false, al, "F32 d28 d21 d9", "F32_d28_d21_d9"},
    137      {{F32, d0, d11, d1}, false, al, "F32 d0 d11 d1", "F32_d0_d11_d1"},
    138      {{F32, d19, d10, d4}, false, al, "F32 d19 d10 d4", "F32_d19_d10_d4"},
    139      {{F32, d19, d28, d20}, false, al, "F32 d19 d28 d20", "F32_d19_d28_d20"},
    140      {{F32, d16, d15, d6}, false, al, "F32 d16 d15 d6", "F32_d16_d15_d6"},
    141      {{F32, d12, d15, d2}, false, al, "F32 d12 d15 d2", "F32_d12_d15_d2"},
    142      {{F32, d0, d31, d2}, false, al, "F32 d0 d31 d2", "F32_d0_d31_d2"},
    143      {{F32, d6, d22, d19}, false, al, "F32 d6 d22 d19", "F32_d6_d22_d19"},
    144      {{F32, d26, d30, d0}, false, al, "F32 d26 d30 d0", "F32_d26_d30_d0"},
    145      {{F32, d5, d19, d18}, false, al, "F32 d5 d19 d18", "F32_d5_d19_d18"},
    146      {{F32, d7, d3, d3}, false, al, "F32 d7 d3 d3", "F32_d7_d3_d3"},
    147      {{F32, d17, d7, d20}, false, al, "F32 d17 d7 d20", "F32_d17_d7_d20"},
    148      {{F32, d29, d30, d24}, false, al, "F32 d29 d30 d24", "F32_d29_d30_d24"},
    149      {{F32, d26, d4, d30}, false, al, "F32 d26 d4 d30", "F32_d26_d4_d30"},
    150      {{F32, d30, d27, d9}, false, al, "F32 d30 d27 d9", "F32_d30_d27_d9"},
    151      {{F32, d6, d24, d17}, false, al, "F32 d6 d24 d17", "F32_d6_d24_d17"},
    152      {{F32, d16, d21, d20}, false, al, "F32 d16 d21 d20", "F32_d16_d21_d20"},
    153      {{F32, d6, d1, d12}, false, al, "F32 d6 d1 d12", "F32_d6_d1_d12"},
    154      {{F32, d2, d26, d18}, false, al, "F32 d2 d26 d18", "F32_d2_d26_d18"},
    155      {{F32, d21, d31, d7}, false, al, "F32 d21 d31 d7", "F32_d21_d31_d7"},
    156      {{F32, d8, d18, d17}, false, al, "F32 d8 d18 d17", "F32_d8_d18_d17"},
    157      {{F32, d18, d11, d8}, false, al, "F32 d18 d11 d8", "F32_d18_d11_d8"},
    158      {{F32, d25, d14, d5}, false, al, "F32 d25 d14 d5", "F32_d25_d14_d5"},
    159      {{F32, d0, d9, d5}, false, al, "F32 d0 d9 d5", "F32_d0_d9_d5"},
    160      {{F32, d14, d12, d7}, false, al, "F32 d14 d12 d7", "F32_d14_d12_d7"},
    161      {{F32, d23, d0, d22}, false, al, "F32 d23 d0 d22", "F32_d23_d0_d22"},
    162      {{F32, d23, d31, d10}, false, al, "F32 d23 d31 d10", "F32_d23_d31_d10"},
    163      {{F32, d3, d19, d28}, false, al, "F32 d3 d19 d28", "F32_d3_d19_d28"},
    164      {{F32, d9, d26, d15}, false, al, "F32 d9 d26 d15", "F32_d9_d26_d15"},
    165      {{F32, d17, d13, d26}, false, al, "F32 d17 d13 d26", "F32_d17_d13_d26"},
    166      {{F32, d2, d26, d5}, false, al, "F32 d2 d26 d5", "F32_d2_d26_d5"},
    167      {{F32, d18, d28, d11}, false, al, "F32 d18 d28 d11", "F32_d18_d28_d11"},
    168      {{F32, d20, d10, d2}, false, al, "F32 d20 d10 d2", "F32_d20_d10_d2"},
    169      {{F32, d19, d3, d9}, false, al, "F32 d19 d3 d9", "F32_d19_d3_d9"},
    170      {{F32, d4, d29, d17}, false, al, "F32 d4 d29 d17", "F32_d4_d29_d17"},
    171      {{F32, d22, d1, d31}, false, al, "F32 d22 d1 d31", "F32_d22_d1_d31"},
    172      {{F32, d29, d2, d17}, false, al, "F32 d29 d2 d17", "F32_d29_d2_d17"},
    173      {{F32, d18, d8, d10}, false, al, "F32 d18 d8 d10", "F32_d18_d8_d10"},
    174      {{F32, d16, d8, d22}, false, al, "F32 d16 d8 d22", "F32_d16_d8_d22"},
    175      {{F32, d0, d27, d19}, false, al, "F32 d0 d27 d19", "F32_d0_d27_d19"},
    176      {{F32, d26, d23, d0}, false, al, "F32 d26 d23 d0", "F32_d26_d23_d0"},
    177      {{F32, d30, d21, d22}, false, al, "F32 d30 d21 d22", "F32_d30_d21_d22"},
    178      {{F32, d31, d31, d8}, false, al, "F32 d31 d31 d8", "F32_d31_d31_d8"},
    179      {{F32, d4, d7, d2}, false, al, "F32 d4 d7 d2", "F32_d4_d7_d2"},
    180      {{F32, d8, d22, d31}, false, al, "F32 d8 d22 d31", "F32_d8_d22_d31"},
    181      {{F32, d27, d3, d14}, false, al, "F32 d27 d3 d14", "F32_d27_d3_d14"},
    182      {{F32, d11, d26, d6}, false, al, "F32 d11 d26 d6", "F32_d11_d26_d6"},
    183      {{F32, d20, d24, d4}, false, al, "F32 d20 d24 d4", "F32_d20_d24_d4"},
    184      {{F32, d1, d8, d3}, false, al, "F32 d1 d8 d3", "F32_d1_d8_d3"},
    185      {{F32, d27, d17, d17}, false, al, "F32 d27 d17 d17", "F32_d27_d17_d17"},
    186      {{F32, d25, d21, d8}, false, al, "F32 d25 d21 d8", "F32_d25_d21_d8"},
    187      {{F32, d6, d0, d15}, false, al, "F32 d6 d0 d15", "F32_d6_d0_d15"},
    188      {{F32, d4, d10, d9}, false, al, "F32 d4 d10 d9", "F32_d4_d10_d9"},
    189      {{F32, d13, d26, d11}, false, al, "F32 d13 d26 d11", "F32_d13_d26_d11"},
    190      {{F32, d7, d6, d18}, false, al, "F32 d7 d6 d18", "F32_d7_d6_d18"},
    191      {{F32, d11, d7, d10}, false, al, "F32 d11 d7 d10", "F32_d11_d7_d10"},
    192      {{F32, d17, d3, d10}, false, al, "F32 d17 d3 d10", "F32_d17_d3_d10"},
    193      {{F32, d9, d19, d11}, false, al, "F32 d9 d19 d11", "F32_d9_d19_d11"},
    194      {{F32, d9, d22, d10}, false, al, "F32 d9 d22 d10", "F32_d9_d22_d10"},
    195      {{F32, d30, d0, d21}, false, al, "F32 d30 d0 d21", "F32_d30_d0_d21"},
    196      {{F32, d13, d1, d15}, false, al, "F32 d13 d1 d15", "F32_d13_d1_d15"},
    197      {{F32, d27, d11, d10}, false, al, "F32 d27 d11 d10", "F32_d27_d11_d10"},
    198      {{F32, d7, d26, d9}, false, al, "F32 d7 d26 d9", "F32_d7_d26_d9"},
    199      {{F32, d1, d12, d21}, false, al, "F32 d1 d12 d21", "F32_d1_d12_d21"},
    200      {{F32, d26, d28, d30}, false, al, "F32 d26 d28 d30", "F32_d26_d28_d30"},
    201      {{F32, d31, d14, d5}, false, al, "F32 d31 d14 d5", "F32_d31_d14_d5"},
    202      {{F32, d29, d12, d7}, false, al, "F32 d29 d12 d7", "F32_d29_d12_d7"},
    203      {{F32, d19, d30, d1}, false, al, "F32 d19 d30 d1", "F32_d19_d30_d1"},
    204      {{F32, d4, d1, d26}, false, al, "F32 d4 d1 d26", "F32_d4_d1_d26"},
    205      {{F32, d2, d13, d10}, false, al, "F32 d2 d13 d10", "F32_d2_d13_d10"}};
    206 
    207 // These headers each contain an array of `TestResult` with the reference output
    208 // values. The reference arrays are names `kReference{mnemonic}`.
    209 #include "aarch32/traces/assembler-cond-dt-drt-drd-drn-drm-float-f32-only-vabd-a32.h"
    210 #include "aarch32/traces/assembler-cond-dt-drt-drd-drn-drm-float-f32-only-vceq-a32.h"
    211 #include "aarch32/traces/assembler-cond-dt-drt-drd-drn-drm-float-f32-only-vcge-a32.h"
    212 #include "aarch32/traces/assembler-cond-dt-drt-drd-drn-drm-float-f32-only-vcgt-a32.h"
    213 #include "aarch32/traces/assembler-cond-dt-drt-drd-drn-drm-float-f32-only-vcle-a32.h"
    214 #include "aarch32/traces/assembler-cond-dt-drt-drd-drn-drm-float-f32-only-vclt-a32.h"
    215 #include "aarch32/traces/assembler-cond-dt-drt-drd-drn-drm-float-f32-only-vmax-a32.h"
    216 #include "aarch32/traces/assembler-cond-dt-drt-drd-drn-drm-float-f32-only-vmin-a32.h"
    217 #include "aarch32/traces/assembler-cond-dt-drt-drd-drn-drm-float-f32-only-vpadd-a32.h"
    218 #include "aarch32/traces/assembler-cond-dt-drt-drd-drn-drm-float-f32-only-vpmax-a32.h"
    219 #include "aarch32/traces/assembler-cond-dt-drt-drd-drn-drm-float-f32-only-vpmin-a32.h"
    220 
    221 
    222 // The maximum number of errors to report in detail for each test.
    223 const unsigned kErrorReportLimit = 8;
    224 
    225 typedef void (MacroAssembler::*Fn)(DataType dt,
    226                                    DRegister rd,
    227                                    DRegister rn,
    228                                    DRegister rm);
    229 
    230 void TestHelper(Fn instruction,
    231                 const char* mnemonic,
    232                 const TestResult reference[]) {
    233   unsigned total_error_count = 0;
    234   MacroAssembler masm(BUF_SIZE);
    235 
    236   masm.UseA32();
    237 
    238   for (unsigned i = 0; i < ARRAY_SIZE(kTests); i++) {
    239     // Values to pass to the macro-assembler.
    240     DataType dt = kTests[i].operands.dt;
    241     DRegister rd = kTests[i].operands.rd;
    242     DRegister rn = kTests[i].operands.rn;
    243     DRegister rm = kTests[i].operands.rm;
    244 
    245     int32_t start = masm.GetCursorOffset();
    246     {
    247       // We never generate more that 4 bytes, as IT instructions are only
    248       // allowed for narrow encodings.
    249       ExactAssemblyScope scope(&masm, 4, ExactAssemblyScope::kMaximumSize);
    250       if (kTests[i].in_it_block) {
    251         masm.it(kTests[i].it_condition);
    252       }
    253       (masm.*instruction)(dt, rd, rn, rm);
    254     }
    255     int32_t end = masm.GetCursorOffset();
    256 
    257     const byte* result_ptr =
    258         masm.GetBuffer()->GetOffsetAddress<const byte*>(start);
    259     VIXL_ASSERT(start < end);
    260     uint32_t result_size = end - start;
    261 
    262     if (Test::generate_test_trace()) {
    263       // Print the result bytes.
    264       printf("const byte kInstruction_%s_%s[] = {\n",
    265              mnemonic,
    266              kTests[i].identifier);
    267       for (uint32_t j = 0; j < result_size; j++) {
    268         if (j == 0) {
    269           printf("  0x%02" PRIx8, result_ptr[j]);
    270         } else {
    271           printf(", 0x%02" PRIx8, result_ptr[j]);
    272         }
    273       }
    274       // This comment is meant to be used by external tools to validate
    275       // the encoding. We can parse the comment to figure out what
    276       // instruction this corresponds to.
    277       if (kTests[i].in_it_block) {
    278         printf(" // It %s; %s %s\n};\n",
    279                kTests[i].it_condition.GetName(),
    280                mnemonic,
    281                kTests[i].operands_description);
    282       } else {
    283         printf(" // %s %s\n};\n", mnemonic, kTests[i].operands_description);
    284       }
    285     } else {
    286       // Check we've emitted the exact same encoding as present in the
    287       // trace file. Only print up to `kErrorReportLimit` errors.
    288       if (((result_size != reference[i].size) ||
    289            (memcmp(result_ptr, reference[i].encoding, reference[i].size) !=
    290             0)) &&
    291           (++total_error_count <= kErrorReportLimit)) {
    292         printf("Error when testing \"%s\" with operands \"%s\":\n",
    293                mnemonic,
    294                kTests[i].operands_description);
    295         printf("  Expected: ");
    296         for (uint32_t j = 0; j < reference[i].size; j++) {
    297           if (j == 0) {
    298             printf("0x%02" PRIx8, reference[i].encoding[j]);
    299           } else {
    300             printf(", 0x%02" PRIx8, reference[i].encoding[j]);
    301           }
    302         }
    303         printf("\n");
    304         printf("  Found:    ");
    305         for (uint32_t j = 0; j < result_size; j++) {
    306           if (j == 0) {
    307             printf("0x%02" PRIx8, result_ptr[j]);
    308           } else {
    309             printf(", 0x%02" PRIx8, result_ptr[j]);
    310           }
    311         }
    312         printf("\n");
    313       }
    314     }
    315   }
    316 
    317   masm.FinalizeCode();
    318 
    319   if (Test::generate_test_trace()) {
    320     // Finalize the trace file by writing the final `TestResult` array
    321     // which links all generated instruction encodings.
    322     printf("const TestResult kReference%s[] = {\n", mnemonic);
    323     for (unsigned i = 0; i < ARRAY_SIZE(kTests); i++) {
    324       printf("  {\n");
    325       printf("    ARRAY_SIZE(kInstruction_%s_%s),\n",
    326              mnemonic,
    327              kTests[i].identifier);
    328       printf("    kInstruction_%s_%s,\n", mnemonic, kTests[i].identifier);
    329       printf("  },\n");
    330     }
    331     printf("};\n");
    332   } else {
    333     if (total_error_count > kErrorReportLimit) {
    334       printf("%u other errors follow.\n",
    335              total_error_count - kErrorReportLimit);
    336     }
    337     // Crash if the test failed.
    338     VIXL_CHECK(total_error_count == 0);
    339   }
    340 }
    341 
    342 // Instantiate tests for each instruction in the list.
    343 #define TEST(mnemonic)                                                      \
    344   void Test_##mnemonic() {                                                  \
    345     TestHelper(&MacroAssembler::mnemonic, #mnemonic, kReference##mnemonic); \
    346   }                                                                         \
    347   Test test_##mnemonic(                                                     \
    348       "AARCH32_ASSEMBLER_COND_DT_DRT_DRD_DRN_DRM_FLOAT_F32_ONLY_" #mnemonic \
    349       "_A32",                                                               \
    350       &Test_##mnemonic);
    351 FOREACH_INSTRUCTION(TEST)
    352 #undef TEST
    353 
    354 }  // namespace
    355 #endif
    356 
    357 }  // namespace aarch32
    358 }  // namespace vixl
    359