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