|
Line 0
Source/JavaScriptCore/b3/air/testair.cpp_sec1
|
|
|
1 |
/* |
| 2 |
* Copyright (C) 2016 Apple Inc. 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 |
| 6 |
* are met: |
| 7 |
* 1. Redistributions of source code must retain the above copyright |
| 8 |
* notice, this list of conditions and the following disclaimer. |
| 9 |
* 2. Redistributions in binary form must reproduce the above copyright |
| 10 |
* notice, this list of conditions and the following disclaimer in the |
| 11 |
* documentation and/or other materials provided with the distribution. |
| 12 |
* |
| 13 |
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
| 14 |
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
| 17 |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 |
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 |
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 |
*/ |
| 25 |
|
| 26 |
#include "config.h" |
| 27 |
|
| 28 |
#include "AirCode.h" |
| 29 |
#include "AirGenerate.h" |
| 30 |
#include "AirInstInlines.h" |
| 31 |
#include "AirRegisterPriority.h" |
| 32 |
#include "AllowMacroScratchRegisterUsage.h" |
| 33 |
#include "B3Compilation.h" |
| 34 |
#include "B3Procedure.h" |
| 35 |
#include "CCallHelpers.h" |
| 36 |
#include "InitializeThreading.h" |
| 37 |
#include "JSCInlines.h" |
| 38 |
#include "LinkBuffer.h" |
| 39 |
#include "PureNaN.h" |
| 40 |
#include "VM.h" |
| 41 |
#include <cmath> |
| 42 |
#include <string> |
| 43 |
#include <wtf/Lock.h> |
| 44 |
#include <wtf/NumberOfCores.h> |
| 45 |
#include <wtf/Threading.h> |
| 46 |
|
| 47 |
// We don't have a NO_RETURN_DUE_TO_EXIT, nor should we. That's ridiculous. |
| 48 |
static bool hiddenTruthBecauseNoReturnIsStupid() { return true; } |
| 49 |
|
| 50 |
static void usage() |
| 51 |
{ |
| 52 |
dataLog("Usage: testb3 [<filter>]\n"); |
| 53 |
if (hiddenTruthBecauseNoReturnIsStupid()) |
| 54 |
exit(1); |
| 55 |
} |
| 56 |
|
| 57 |
#if ENABLE(B3_JIT) |
| 58 |
|
| 59 |
using namespace JSC; |
| 60 |
using namespace JSC::B3::Air; |
| 61 |
|
| 62 |
namespace { |
| 63 |
|
| 64 |
StaticLock crashLock; |
| 65 |
|
| 66 |
// Nothing fancy for now; we just use the existing WTF assertion machinery. |
| 67 |
#define CHECK(x) do { \ |
| 68 |
if (!!(x)) \ |
| 69 |
break; \ |
| 70 |
crashLock.lock(); \ |
| 71 |
WTFReportAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, #x); \ |
| 72 |
CRASH(); \ |
| 73 |
} while (false) |
| 74 |
|
| 75 |
VM* vm; |
| 76 |
|
| 77 |
std::unique_ptr<B3::Compilation> compile(B3::Procedure& proc) |
| 78 |
{ |
| 79 |
prepareForGeneration(proc.code()); |
| 80 |
CCallHelpers jit(vm); |
| 81 |
generate(proc.code(), jit); |
| 82 |
LinkBuffer linkBuffer(*vm, jit, nullptr); |
| 83 |
|
| 84 |
return std::make_unique<B3::Compilation>( |
| 85 |
FINALIZE_CODE(linkBuffer, ("testair compilation")), proc.releaseByproducts()); |
| 86 |
} |
| 87 |
|
| 88 |
template<typename T, typename... Arguments> |
| 89 |
T invoke(const B3::Compilation& code, Arguments... arguments) |
| 90 |
{ |
| 91 |
T (*function)(Arguments...) = bitwise_cast<T(*)(Arguments...)>(code.code().executableAddress()); |
| 92 |
return function(arguments...); |
| 93 |
} |
| 94 |
|
| 95 |
template<typename T, typename... Arguments> |
| 96 |
T compileAndRun(B3::Procedure& procedure, Arguments... arguments) |
| 97 |
{ |
| 98 |
return invoke<T>(*compile(procedure), arguments...); |
| 99 |
} |
| 100 |
|
| 101 |
void testSimple() |
| 102 |
{ |
| 103 |
B3::Procedure proc; |
| 104 |
Code& code = proc.code(); |
| 105 |
|
| 106 |
BasicBlock* root = code.addBlock(); |
| 107 |
root->append(Move, nullptr, Arg::imm(42), Tmp(GPRInfo::returnValueGPR)); |
| 108 |
root->append(Ret32, nullptr, Tmp(GPRInfo::returnValueGPR)); |
| 109 |
|
| 110 |
CHECK(compileAndRun<int>(proc) == 42); |
| 111 |
} |
| 112 |
|
| 113 |
void testShuffleSimpleSwap() |
| 114 |
{ |
| 115 |
B3::Procedure proc; |
| 116 |
Code& code = proc.code(); |
| 117 |
|
| 118 |
BasicBlock* root = code.addBlock(); |
| 119 |
root->append(Move, nullptr, Arg::imm(1), Tmp(GPRInfo::regT0)); |
| 120 |
root->append(Move, nullptr, Arg::imm(2), Tmp(GPRInfo::regT1)); |
| 121 |
root->append(Move, nullptr, Arg::imm(3), Tmp(GPRInfo::regT2)); |
| 122 |
root->append(Move, nullptr, Arg::imm(4), Tmp(GPRInfo::regT3)); |
| 123 |
root->append( |
| 124 |
Shuffle, nullptr, |
| 125 |
Tmp(GPRInfo::regT2), Tmp(GPRInfo::regT3), Arg::widthArg(Arg::Width32), |
| 126 |
Tmp(GPRInfo::regT3), Tmp(GPRInfo::regT2), Arg::widthArg(Arg::Width32)); |
| 127 |
|
| 128 |
int32_t things[4]; |
| 129 |
Tmp base = code.newTmp(Arg::GP); |
| 130 |
root->append(Move, nullptr, Arg::imm64(bitwise_cast<intptr_t>(&things)), base); |
| 131 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT0), Arg::addr(base, 0 * sizeof(int32_t))); |
| 132 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT1), Arg::addr(base, 1 * sizeof(int32_t))); |
| 133 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT2), Arg::addr(base, 2 * sizeof(int32_t))); |
| 134 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT3), Arg::addr(base, 3 * sizeof(int32_t))); |
| 135 |
root->append(Move, nullptr, Arg::imm(0), Tmp(GPRInfo::returnValueGPR)); |
| 136 |
root->append(Ret32, nullptr, Tmp(GPRInfo::returnValueGPR)); |
| 137 |
|
| 138 |
memset(things, 0, sizeof(things)); |
| 139 |
|
| 140 |
CHECK(!compileAndRun<int>(proc)); |
| 141 |
|
| 142 |
CHECK(things[0] == 1); |
| 143 |
CHECK(things[1] == 2); |
| 144 |
CHECK(things[2] == 4); |
| 145 |
CHECK(things[3] == 3); |
| 146 |
} |
| 147 |
|
| 148 |
void testShuffleSimpleShift() |
| 149 |
{ |
| 150 |
B3::Procedure proc; |
| 151 |
Code& code = proc.code(); |
| 152 |
|
| 153 |
BasicBlock* root = code.addBlock(); |
| 154 |
root->append(Move, nullptr, Arg::imm(1), Tmp(GPRInfo::regT0)); |
| 155 |
root->append(Move, nullptr, Arg::imm(2), Tmp(GPRInfo::regT1)); |
| 156 |
root->append(Move, nullptr, Arg::imm(3), Tmp(GPRInfo::regT2)); |
| 157 |
root->append(Move, nullptr, Arg::imm(4), Tmp(GPRInfo::regT3)); |
| 158 |
root->append( |
| 159 |
Shuffle, nullptr, |
| 160 |
Tmp(GPRInfo::regT2), Tmp(GPRInfo::regT3), Arg::widthArg(Arg::Width32), |
| 161 |
Tmp(GPRInfo::regT3), Tmp(GPRInfo::regT4), Arg::widthArg(Arg::Width32)); |
| 162 |
|
| 163 |
int32_t things[5]; |
| 164 |
Tmp base = code.newTmp(Arg::GP); |
| 165 |
root->append(Move, nullptr, Arg::imm64(bitwise_cast<intptr_t>(&things)), base); |
| 166 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT0), Arg::addr(base, 0 * sizeof(int32_t))); |
| 167 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT1), Arg::addr(base, 1 * sizeof(int32_t))); |
| 168 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT2), Arg::addr(base, 2 * sizeof(int32_t))); |
| 169 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT3), Arg::addr(base, 3 * sizeof(int32_t))); |
| 170 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT4), Arg::addr(base, 4 * sizeof(int32_t))); |
| 171 |
root->append(Move, nullptr, Arg::imm(0), Tmp(GPRInfo::returnValueGPR)); |
| 172 |
root->append(Ret32, nullptr, Tmp(GPRInfo::returnValueGPR)); |
| 173 |
|
| 174 |
memset(things, 0, sizeof(things)); |
| 175 |
|
| 176 |
CHECK(!compileAndRun<int>(proc)); |
| 177 |
|
| 178 |
CHECK(things[0] == 1); |
| 179 |
CHECK(things[1] == 2); |
| 180 |
CHECK(things[2] == 3); |
| 181 |
CHECK(things[3] == 3); |
| 182 |
CHECK(things[4] == 4); |
| 183 |
} |
| 184 |
|
| 185 |
void testShuffleLongShift() |
| 186 |
{ |
| 187 |
B3::Procedure proc; |
| 188 |
Code& code = proc.code(); |
| 189 |
|
| 190 |
BasicBlock* root = code.addBlock(); |
| 191 |
root->append(Move, nullptr, Arg::imm(1), Tmp(GPRInfo::regT0)); |
| 192 |
root->append(Move, nullptr, Arg::imm(2), Tmp(GPRInfo::regT1)); |
| 193 |
root->append(Move, nullptr, Arg::imm(3), Tmp(GPRInfo::regT2)); |
| 194 |
root->append(Move, nullptr, Arg::imm(4), Tmp(GPRInfo::regT3)); |
| 195 |
root->append(Move, nullptr, Arg::imm(5), Tmp(GPRInfo::regT4)); |
| 196 |
root->append(Move, nullptr, Arg::imm(6), Tmp(GPRInfo::regT5)); |
| 197 |
root->append(Move, nullptr, Arg::imm(7), Tmp(GPRInfo::regT6)); |
| 198 |
root->append(Move, nullptr, Arg::imm(8), Tmp(GPRInfo::regT7)); |
| 199 |
root->append( |
| 200 |
Shuffle, nullptr, |
| 201 |
Tmp(GPRInfo::regT0), Tmp(GPRInfo::regT1), Arg::widthArg(Arg::Width32), |
| 202 |
Tmp(GPRInfo::regT1), Tmp(GPRInfo::regT2), Arg::widthArg(Arg::Width32), |
| 203 |
Tmp(GPRInfo::regT2), Tmp(GPRInfo::regT3), Arg::widthArg(Arg::Width32), |
| 204 |
Tmp(GPRInfo::regT3), Tmp(GPRInfo::regT4), Arg::widthArg(Arg::Width32), |
| 205 |
Tmp(GPRInfo::regT4), Tmp(GPRInfo::regT5), Arg::widthArg(Arg::Width32), |
| 206 |
Tmp(GPRInfo::regT5), Tmp(GPRInfo::regT6), Arg::widthArg(Arg::Width32), |
| 207 |
Tmp(GPRInfo::regT6), Tmp(GPRInfo::regT7), Arg::widthArg(Arg::Width32)); |
| 208 |
|
| 209 |
int32_t things[8]; |
| 210 |
Tmp base = code.newTmp(Arg::GP); |
| 211 |
root->append(Move, nullptr, Arg::imm64(bitwise_cast<intptr_t>(&things)), base); |
| 212 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT0), Arg::addr(base, 0 * sizeof(int32_t))); |
| 213 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT1), Arg::addr(base, 1 * sizeof(int32_t))); |
| 214 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT2), Arg::addr(base, 2 * sizeof(int32_t))); |
| 215 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT3), Arg::addr(base, 3 * sizeof(int32_t))); |
| 216 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT4), Arg::addr(base, 4 * sizeof(int32_t))); |
| 217 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT5), Arg::addr(base, 5 * sizeof(int32_t))); |
| 218 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT6), Arg::addr(base, 6 * sizeof(int32_t))); |
| 219 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT7), Arg::addr(base, 7 * sizeof(int32_t))); |
| 220 |
root->append(Move, nullptr, Arg::imm(0), Tmp(GPRInfo::returnValueGPR)); |
| 221 |
root->append(Ret32, nullptr, Tmp(GPRInfo::returnValueGPR)); |
| 222 |
|
| 223 |
memset(things, 0, sizeof(things)); |
| 224 |
|
| 225 |
CHECK(!compileAndRun<int>(proc)); |
| 226 |
|
| 227 |
CHECK(things[0] == 1); |
| 228 |
CHECK(things[1] == 1); |
| 229 |
CHECK(things[2] == 2); |
| 230 |
CHECK(things[3] == 3); |
| 231 |
CHECK(things[4] == 4); |
| 232 |
CHECK(things[5] == 5); |
| 233 |
CHECK(things[6] == 6); |
| 234 |
CHECK(things[7] == 7); |
| 235 |
} |
| 236 |
|
| 237 |
void testShuffleLongShiftBackwards() |
| 238 |
{ |
| 239 |
B3::Procedure proc; |
| 240 |
Code& code = proc.code(); |
| 241 |
|
| 242 |
BasicBlock* root = code.addBlock(); |
| 243 |
root->append(Move, nullptr, Arg::imm(1), Tmp(GPRInfo::regT0)); |
| 244 |
root->append(Move, nullptr, Arg::imm(2), Tmp(GPRInfo::regT1)); |
| 245 |
root->append(Move, nullptr, Arg::imm(3), Tmp(GPRInfo::regT2)); |
| 246 |
root->append(Move, nullptr, Arg::imm(4), Tmp(GPRInfo::regT3)); |
| 247 |
root->append(Move, nullptr, Arg::imm(5), Tmp(GPRInfo::regT4)); |
| 248 |
root->append(Move, nullptr, Arg::imm(6), Tmp(GPRInfo::regT5)); |
| 249 |
root->append(Move, nullptr, Arg::imm(7), Tmp(GPRInfo::regT6)); |
| 250 |
root->append(Move, nullptr, Arg::imm(8), Tmp(GPRInfo::regT7)); |
| 251 |
root->append( |
| 252 |
Shuffle, nullptr, |
| 253 |
Tmp(GPRInfo::regT6), Tmp(GPRInfo::regT7), Arg::widthArg(Arg::Width32), |
| 254 |
Tmp(GPRInfo::regT5), Tmp(GPRInfo::regT6), Arg::widthArg(Arg::Width32), |
| 255 |
Tmp(GPRInfo::regT4), Tmp(GPRInfo::regT5), Arg::widthArg(Arg::Width32), |
| 256 |
Tmp(GPRInfo::regT3), Tmp(GPRInfo::regT4), Arg::widthArg(Arg::Width32), |
| 257 |
Tmp(GPRInfo::regT2), Tmp(GPRInfo::regT3), Arg::widthArg(Arg::Width32), |
| 258 |
Tmp(GPRInfo::regT1), Tmp(GPRInfo::regT2), Arg::widthArg(Arg::Width32), |
| 259 |
Tmp(GPRInfo::regT0), Tmp(GPRInfo::regT1), Arg::widthArg(Arg::Width32)); |
| 260 |
|
| 261 |
int32_t things[8]; |
| 262 |
Tmp base = code.newTmp(Arg::GP); |
| 263 |
root->append(Move, nullptr, Arg::imm64(bitwise_cast<intptr_t>(&things)), base); |
| 264 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT0), Arg::addr(base, 0 * sizeof(int32_t))); |
| 265 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT1), Arg::addr(base, 1 * sizeof(int32_t))); |
| 266 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT2), Arg::addr(base, 2 * sizeof(int32_t))); |
| 267 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT3), Arg::addr(base, 3 * sizeof(int32_t))); |
| 268 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT4), Arg::addr(base, 4 * sizeof(int32_t))); |
| 269 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT5), Arg::addr(base, 5 * sizeof(int32_t))); |
| 270 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT6), Arg::addr(base, 6 * sizeof(int32_t))); |
| 271 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT7), Arg::addr(base, 7 * sizeof(int32_t))); |
| 272 |
root->append(Move, nullptr, Arg::imm(0), Tmp(GPRInfo::returnValueGPR)); |
| 273 |
root->append(Ret32, nullptr, Tmp(GPRInfo::returnValueGPR)); |
| 274 |
|
| 275 |
memset(things, 0, sizeof(things)); |
| 276 |
|
| 277 |
CHECK(!compileAndRun<int>(proc)); |
| 278 |
|
| 279 |
CHECK(things[0] == 1); |
| 280 |
CHECK(things[1] == 1); |
| 281 |
CHECK(things[2] == 2); |
| 282 |
CHECK(things[3] == 3); |
| 283 |
CHECK(things[4] == 4); |
| 284 |
CHECK(things[5] == 5); |
| 285 |
CHECK(things[6] == 6); |
| 286 |
CHECK(things[7] == 7); |
| 287 |
} |
| 288 |
|
| 289 |
void testShuffleSimpleRotate() |
| 290 |
{ |
| 291 |
B3::Procedure proc; |
| 292 |
Code& code = proc.code(); |
| 293 |
|
| 294 |
BasicBlock* root = code.addBlock(); |
| 295 |
root->append(Move, nullptr, Arg::imm(1), Tmp(GPRInfo::regT0)); |
| 296 |
root->append(Move, nullptr, Arg::imm(2), Tmp(GPRInfo::regT1)); |
| 297 |
root->append(Move, nullptr, Arg::imm(3), Tmp(GPRInfo::regT2)); |
| 298 |
root->append(Move, nullptr, Arg::imm(4), Tmp(GPRInfo::regT3)); |
| 299 |
root->append( |
| 300 |
Shuffle, nullptr, |
| 301 |
Tmp(GPRInfo::regT0), Tmp(GPRInfo::regT1), Arg::widthArg(Arg::Width32), |
| 302 |
Tmp(GPRInfo::regT1), Tmp(GPRInfo::regT2), Arg::widthArg(Arg::Width32), |
| 303 |
Tmp(GPRInfo::regT2), Tmp(GPRInfo::regT0), Arg::widthArg(Arg::Width32)); |
| 304 |
|
| 305 |
int32_t things[4]; |
| 306 |
Tmp base = code.newTmp(Arg::GP); |
| 307 |
root->append(Move, nullptr, Arg::imm64(bitwise_cast<intptr_t>(&things)), base); |
| 308 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT0), Arg::addr(base, 0 * sizeof(int32_t))); |
| 309 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT1), Arg::addr(base, 1 * sizeof(int32_t))); |
| 310 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT2), Arg::addr(base, 2 * sizeof(int32_t))); |
| 311 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT3), Arg::addr(base, 3 * sizeof(int32_t))); |
| 312 |
root->append(Move, nullptr, Arg::imm(0), Tmp(GPRInfo::returnValueGPR)); |
| 313 |
root->append(Ret32, nullptr, Tmp(GPRInfo::returnValueGPR)); |
| 314 |
|
| 315 |
memset(things, 0, sizeof(things)); |
| 316 |
|
| 317 |
CHECK(!compileAndRun<int>(proc)); |
| 318 |
|
| 319 |
CHECK(things[0] == 3); |
| 320 |
CHECK(things[1] == 1); |
| 321 |
CHECK(things[2] == 2); |
| 322 |
CHECK(things[3] == 4); |
| 323 |
} |
| 324 |
|
| 325 |
void testShuffleSimpleBroadcast() |
| 326 |
{ |
| 327 |
B3::Procedure proc; |
| 328 |
Code& code = proc.code(); |
| 329 |
|
| 330 |
BasicBlock* root = code.addBlock(); |
| 331 |
root->append(Move, nullptr, Arg::imm(1), Tmp(GPRInfo::regT0)); |
| 332 |
root->append(Move, nullptr, Arg::imm(2), Tmp(GPRInfo::regT1)); |
| 333 |
root->append(Move, nullptr, Arg::imm(3), Tmp(GPRInfo::regT2)); |
| 334 |
root->append(Move, nullptr, Arg::imm(4), Tmp(GPRInfo::regT3)); |
| 335 |
root->append( |
| 336 |
Shuffle, nullptr, |
| 337 |
Tmp(GPRInfo::regT0), Tmp(GPRInfo::regT1), Arg::widthArg(Arg::Width32), |
| 338 |
Tmp(GPRInfo::regT0), Tmp(GPRInfo::regT2), Arg::widthArg(Arg::Width32), |
| 339 |
Tmp(GPRInfo::regT0), Tmp(GPRInfo::regT3), Arg::widthArg(Arg::Width32)); |
| 340 |
|
| 341 |
int32_t things[4]; |
| 342 |
Tmp base = code.newTmp(Arg::GP); |
| 343 |
root->append(Move, nullptr, Arg::imm64(bitwise_cast<intptr_t>(&things)), base); |
| 344 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT0), Arg::addr(base, 0 * sizeof(int32_t))); |
| 345 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT1), Arg::addr(base, 1 * sizeof(int32_t))); |
| 346 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT2), Arg::addr(base, 2 * sizeof(int32_t))); |
| 347 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT3), Arg::addr(base, 3 * sizeof(int32_t))); |
| 348 |
root->append(Move, nullptr, Arg::imm(0), Tmp(GPRInfo::returnValueGPR)); |
| 349 |
root->append(Ret32, nullptr, Tmp(GPRInfo::returnValueGPR)); |
| 350 |
|
| 351 |
memset(things, 0, sizeof(things)); |
| 352 |
|
| 353 |
CHECK(!compileAndRun<int>(proc)); |
| 354 |
|
| 355 |
CHECK(things[0] == 1); |
| 356 |
CHECK(things[1] == 1); |
| 357 |
CHECK(things[2] == 1); |
| 358 |
CHECK(things[3] == 1); |
| 359 |
} |
| 360 |
|
| 361 |
void testShuffleBroadcastAllRegs() |
| 362 |
{ |
| 363 |
B3::Procedure proc; |
| 364 |
Code& code = proc.code(); |
| 365 |
|
| 366 |
const Vector<Reg>& regs = regsInPriorityOrder(Arg::GP); |
| 367 |
|
| 368 |
BasicBlock* root = code.addBlock(); |
| 369 |
root->append(Move, nullptr, Arg::imm(35), Tmp(GPRInfo::regT0)); |
| 370 |
unsigned count = 1; |
| 371 |
for (Reg reg : regs) { |
| 372 |
if (reg != Reg(GPRInfo::regT0)) |
| 373 |
root->append(Move, nullptr, Arg::imm(count++), Tmp(reg)); |
| 374 |
} |
| 375 |
Inst& shuffle = root->append(Shuffle, nullptr); |
| 376 |
for (Reg reg : regs) { |
| 377 |
if (reg != Reg(GPRInfo::regT0)) |
| 378 |
shuffle.append(Tmp(GPRInfo::regT0), Tmp(reg), Arg::widthArg(Arg::Width32)); |
| 379 |
} |
| 380 |
|
| 381 |
StackSlot* slot = code.addStackSlot(sizeof(int32_t) * regs.size(), B3::StackSlotKind::Locked); |
| 382 |
for (unsigned i = 0; i < regs.size(); ++i) |
| 383 |
root->append(Move32, nullptr, Tmp(regs[i]), Arg::stack(slot, i * sizeof(int32_t))); |
| 384 |
|
| 385 |
Vector<int32_t> things(regs.size(), 666); |
| 386 |
Tmp base = code.newTmp(Arg::GP); |
| 387 |
root->append(Move, nullptr, Arg::imm64(bitwise_cast<intptr_t>(&things[0])), base); |
| 388 |
for (unsigned i = 0; i < regs.size(); ++i) { |
| 389 |
root->append(Move32, nullptr, Arg::stack(slot, i * sizeof(int32_t)), Tmp(GPRInfo::regT0)); |
| 390 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT0), Arg::addr(base, i * sizeof(int32_t))); |
| 391 |
} |
| 392 |
|
| 393 |
root->append(Move, nullptr, Arg::imm(0), Tmp(GPRInfo::returnValueGPR)); |
| 394 |
root->append(Ret32, nullptr, Tmp(GPRInfo::returnValueGPR)); |
| 395 |
|
| 396 |
CHECK(!compileAndRun<int>(proc)); |
| 397 |
|
| 398 |
for (int32_t thing : things) |
| 399 |
CHECK(thing == 35); |
| 400 |
} |
| 401 |
|
| 402 |
void testShuffleTreeShift() |
| 403 |
{ |
| 404 |
B3::Procedure proc; |
| 405 |
Code& code = proc.code(); |
| 406 |
|
| 407 |
BasicBlock* root = code.addBlock(); |
| 408 |
root->append(Move, nullptr, Arg::imm(1), Tmp(GPRInfo::regT0)); |
| 409 |
root->append(Move, nullptr, Arg::imm(2), Tmp(GPRInfo::regT1)); |
| 410 |
root->append(Move, nullptr, Arg::imm(3), Tmp(GPRInfo::regT2)); |
| 411 |
root->append(Move, nullptr, Arg::imm(4), Tmp(GPRInfo::regT3)); |
| 412 |
root->append(Move, nullptr, Arg::imm(5), Tmp(GPRInfo::regT4)); |
| 413 |
root->append(Move, nullptr, Arg::imm(6), Tmp(GPRInfo::regT5)); |
| 414 |
root->append(Move, nullptr, Arg::imm(7), Tmp(GPRInfo::regT6)); |
| 415 |
root->append(Move, nullptr, Arg::imm(8), Tmp(GPRInfo::regT7)); |
| 416 |
root->append( |
| 417 |
Shuffle, nullptr, |
| 418 |
Tmp(GPRInfo::regT0), Tmp(GPRInfo::regT1), Arg::widthArg(Arg::Width32), |
| 419 |
Tmp(GPRInfo::regT0), Tmp(GPRInfo::regT2), Arg::widthArg(Arg::Width32), |
| 420 |
Tmp(GPRInfo::regT1), Tmp(GPRInfo::regT3), Arg::widthArg(Arg::Width32), |
| 421 |
Tmp(GPRInfo::regT1), Tmp(GPRInfo::regT4), Arg::widthArg(Arg::Width32), |
| 422 |
Tmp(GPRInfo::regT2), Tmp(GPRInfo::regT5), Arg::widthArg(Arg::Width32), |
| 423 |
Tmp(GPRInfo::regT2), Tmp(GPRInfo::regT6), Arg::widthArg(Arg::Width32), |
| 424 |
Tmp(GPRInfo::regT3), Tmp(GPRInfo::regT7), Arg::widthArg(Arg::Width32)); |
| 425 |
|
| 426 |
int32_t things[8]; |
| 427 |
Tmp base = code.newTmp(Arg::GP); |
| 428 |
root->append(Move, nullptr, Arg::imm64(bitwise_cast<intptr_t>(&things)), base); |
| 429 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT0), Arg::addr(base, 0 * sizeof(int32_t))); |
| 430 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT1), Arg::addr(base, 1 * sizeof(int32_t))); |
| 431 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT2), Arg::addr(base, 2 * sizeof(int32_t))); |
| 432 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT3), Arg::addr(base, 3 * sizeof(int32_t))); |
| 433 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT4), Arg::addr(base, 4 * sizeof(int32_t))); |
| 434 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT5), Arg::addr(base, 5 * sizeof(int32_t))); |
| 435 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT6), Arg::addr(base, 6 * sizeof(int32_t))); |
| 436 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT7), Arg::addr(base, 7 * sizeof(int32_t))); |
| 437 |
root->append(Move, nullptr, Arg::imm(0), Tmp(GPRInfo::returnValueGPR)); |
| 438 |
root->append(Ret32, nullptr, Tmp(GPRInfo::returnValueGPR)); |
| 439 |
|
| 440 |
memset(things, 0, sizeof(things)); |
| 441 |
|
| 442 |
CHECK(!compileAndRun<int>(proc)); |
| 443 |
|
| 444 |
CHECK(things[0] == 1); |
| 445 |
CHECK(things[1] == 1); |
| 446 |
CHECK(things[2] == 1); |
| 447 |
CHECK(things[3] == 2); |
| 448 |
CHECK(things[4] == 2); |
| 449 |
CHECK(things[5] == 3); |
| 450 |
CHECK(things[6] == 3); |
| 451 |
CHECK(things[7] == 4); |
| 452 |
} |
| 453 |
|
| 454 |
void testShuffleTreeShiftBackward() |
| 455 |
{ |
| 456 |
B3::Procedure proc; |
| 457 |
Code& code = proc.code(); |
| 458 |
|
| 459 |
BasicBlock* root = code.addBlock(); |
| 460 |
root->append(Move, nullptr, Arg::imm(1), Tmp(GPRInfo::regT0)); |
| 461 |
root->append(Move, nullptr, Arg::imm(2), Tmp(GPRInfo::regT1)); |
| 462 |
root->append(Move, nullptr, Arg::imm(3), Tmp(GPRInfo::regT2)); |
| 463 |
root->append(Move, nullptr, Arg::imm(4), Tmp(GPRInfo::regT3)); |
| 464 |
root->append(Move, nullptr, Arg::imm(5), Tmp(GPRInfo::regT4)); |
| 465 |
root->append(Move, nullptr, Arg::imm(6), Tmp(GPRInfo::regT5)); |
| 466 |
root->append(Move, nullptr, Arg::imm(7), Tmp(GPRInfo::regT6)); |
| 467 |
root->append(Move, nullptr, Arg::imm(8), Tmp(GPRInfo::regT7)); |
| 468 |
root->append( |
| 469 |
Shuffle, nullptr, |
| 470 |
Tmp(GPRInfo::regT3), Tmp(GPRInfo::regT7), Arg::widthArg(Arg::Width32), |
| 471 |
Tmp(GPRInfo::regT2), Tmp(GPRInfo::regT6), Arg::widthArg(Arg::Width32), |
| 472 |
Tmp(GPRInfo::regT2), Tmp(GPRInfo::regT5), Arg::widthArg(Arg::Width32), |
| 473 |
Tmp(GPRInfo::regT1), Tmp(GPRInfo::regT4), Arg::widthArg(Arg::Width32), |
| 474 |
Tmp(GPRInfo::regT1), Tmp(GPRInfo::regT3), Arg::widthArg(Arg::Width32), |
| 475 |
Tmp(GPRInfo::regT0), Tmp(GPRInfo::regT2), Arg::widthArg(Arg::Width32), |
| 476 |
Tmp(GPRInfo::regT0), Tmp(GPRInfo::regT1), Arg::widthArg(Arg::Width32)); |
| 477 |
|
| 478 |
int32_t things[8]; |
| 479 |
Tmp base = code.newTmp(Arg::GP); |
| 480 |
root->append(Move, nullptr, Arg::imm64(bitwise_cast<intptr_t>(&things)), base); |
| 481 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT0), Arg::addr(base, 0 * sizeof(int32_t))); |
| 482 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT1), Arg::addr(base, 1 * sizeof(int32_t))); |
| 483 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT2), Arg::addr(base, 2 * sizeof(int32_t))); |
| 484 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT3), Arg::addr(base, 3 * sizeof(int32_t))); |
| 485 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT4), Arg::addr(base, 4 * sizeof(int32_t))); |
| 486 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT5), Arg::addr(base, 5 * sizeof(int32_t))); |
| 487 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT6), Arg::addr(base, 6 * sizeof(int32_t))); |
| 488 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT7), Arg::addr(base, 7 * sizeof(int32_t))); |
| 489 |
root->append(Move, nullptr, Arg::imm(0), Tmp(GPRInfo::returnValueGPR)); |
| 490 |
root->append(Ret32, nullptr, Tmp(GPRInfo::returnValueGPR)); |
| 491 |
|
| 492 |
memset(things, 0, sizeof(things)); |
| 493 |
|
| 494 |
CHECK(!compileAndRun<int>(proc)); |
| 495 |
|
| 496 |
CHECK(things[0] == 1); |
| 497 |
CHECK(things[1] == 1); |
| 498 |
CHECK(things[2] == 1); |
| 499 |
CHECK(things[3] == 2); |
| 500 |
CHECK(things[4] == 2); |
| 501 |
CHECK(things[5] == 3); |
| 502 |
CHECK(things[6] == 3); |
| 503 |
CHECK(things[7] == 4); |
| 504 |
} |
| 505 |
|
| 506 |
void testShuffleTreeShiftOtherBackward() |
| 507 |
{ |
| 508 |
// NOTE: This test was my original attempt at TreeShiftBackward but mistakes were made. So, this |
| 509 |
// ends up being just a weird test. But weird tests are useful, so I kept it. |
| 510 |
|
| 511 |
B3::Procedure proc; |
| 512 |
Code& code = proc.code(); |
| 513 |
|
| 514 |
BasicBlock* root = code.addBlock(); |
| 515 |
root->append(Move, nullptr, Arg::imm(1), Tmp(GPRInfo::regT0)); |
| 516 |
root->append(Move, nullptr, Arg::imm(2), Tmp(GPRInfo::regT1)); |
| 517 |
root->append(Move, nullptr, Arg::imm(3), Tmp(GPRInfo::regT2)); |
| 518 |
root->append(Move, nullptr, Arg::imm(4), Tmp(GPRInfo::regT3)); |
| 519 |
root->append(Move, nullptr, Arg::imm(5), Tmp(GPRInfo::regT4)); |
| 520 |
root->append(Move, nullptr, Arg::imm(6), Tmp(GPRInfo::regT5)); |
| 521 |
root->append(Move, nullptr, Arg::imm(7), Tmp(GPRInfo::regT6)); |
| 522 |
root->append(Move, nullptr, Arg::imm(8), Tmp(GPRInfo::regT7)); |
| 523 |
root->append( |
| 524 |
Shuffle, nullptr, |
| 525 |
Tmp(GPRInfo::regT4), Tmp(GPRInfo::regT7), Arg::widthArg(Arg::Width32), |
| 526 |
Tmp(GPRInfo::regT5), Tmp(GPRInfo::regT6), Arg::widthArg(Arg::Width32), |
| 527 |
Tmp(GPRInfo::regT5), Tmp(GPRInfo::regT5), Arg::widthArg(Arg::Width32), |
| 528 |
Tmp(GPRInfo::regT6), Tmp(GPRInfo::regT4), Arg::widthArg(Arg::Width32), |
| 529 |
Tmp(GPRInfo::regT6), Tmp(GPRInfo::regT3), Arg::widthArg(Arg::Width32), |
| 530 |
Tmp(GPRInfo::regT7), Tmp(GPRInfo::regT2), Arg::widthArg(Arg::Width32), |
| 531 |
Tmp(GPRInfo::regT7), Tmp(GPRInfo::regT1), Arg::widthArg(Arg::Width32)); |
| 532 |
|
| 533 |
int32_t things[8]; |
| 534 |
Tmp base = code.newTmp(Arg::GP); |
| 535 |
root->append(Move, nullptr, Arg::imm64(bitwise_cast<intptr_t>(&things)), base); |
| 536 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT0), Arg::addr(base, 0 * sizeof(int32_t))); |
| 537 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT1), Arg::addr(base, 1 * sizeof(int32_t))); |
| 538 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT2), Arg::addr(base, 2 * sizeof(int32_t))); |
| 539 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT3), Arg::addr(base, 3 * sizeof(int32_t))); |
| 540 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT4), Arg::addr(base, 4 * sizeof(int32_t))); |
| 541 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT5), Arg::addr(base, 5 * sizeof(int32_t))); |
| 542 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT6), Arg::addr(base, 6 * sizeof(int32_t))); |
| 543 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT7), Arg::addr(base, 7 * sizeof(int32_t))); |
| 544 |
root->append(Move, nullptr, Arg::imm(0), Tmp(GPRInfo::returnValueGPR)); |
| 545 |
root->append(Ret32, nullptr, Tmp(GPRInfo::returnValueGPR)); |
| 546 |
|
| 547 |
memset(things, 0, sizeof(things)); |
| 548 |
|
| 549 |
CHECK(!compileAndRun<int>(proc)); |
| 550 |
|
| 551 |
CHECK(things[0] == 1); |
| 552 |
CHECK(things[1] == 8); |
| 553 |
CHECK(things[2] == 8); |
| 554 |
CHECK(things[3] == 7); |
| 555 |
CHECK(things[4] == 7); |
| 556 |
CHECK(things[5] == 6); |
| 557 |
CHECK(things[6] == 6); |
| 558 |
CHECK(things[7] == 5); |
| 559 |
} |
| 560 |
|
| 561 |
void testShuffleMultipleShifts() |
| 562 |
{ |
| 563 |
B3::Procedure proc; |
| 564 |
Code& code = proc.code(); |
| 565 |
|
| 566 |
BasicBlock* root = code.addBlock(); |
| 567 |
root->append(Move, nullptr, Arg::imm(1), Tmp(GPRInfo::regT0)); |
| 568 |
root->append(Move, nullptr, Arg::imm(2), Tmp(GPRInfo::regT1)); |
| 569 |
root->append(Move, nullptr, Arg::imm(3), Tmp(GPRInfo::regT2)); |
| 570 |
root->append(Move, nullptr, Arg::imm(4), Tmp(GPRInfo::regT3)); |
| 571 |
root->append(Move, nullptr, Arg::imm(5), Tmp(GPRInfo::regT4)); |
| 572 |
root->append(Move, nullptr, Arg::imm(6), Tmp(GPRInfo::regT5)); |
| 573 |
root->append( |
| 574 |
Shuffle, nullptr, |
| 575 |
Tmp(GPRInfo::regT0), Tmp(GPRInfo::regT1), Arg::widthArg(Arg::Width32), |
| 576 |
Tmp(GPRInfo::regT2), Tmp(GPRInfo::regT3), Arg::widthArg(Arg::Width32), |
| 577 |
Tmp(GPRInfo::regT2), Tmp(GPRInfo::regT4), Arg::widthArg(Arg::Width32), |
| 578 |
Tmp(GPRInfo::regT0), Tmp(GPRInfo::regT5), Arg::widthArg(Arg::Width32)); |
| 579 |
|
| 580 |
int32_t things[6]; |
| 581 |
Tmp base = code.newTmp(Arg::GP); |
| 582 |
root->append(Move, nullptr, Arg::imm64(bitwise_cast<intptr_t>(&things)), base); |
| 583 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT0), Arg::addr(base, 0 * sizeof(int32_t))); |
| 584 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT1), Arg::addr(base, 1 * sizeof(int32_t))); |
| 585 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT2), Arg::addr(base, 2 * sizeof(int32_t))); |
| 586 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT3), Arg::addr(base, 3 * sizeof(int32_t))); |
| 587 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT4), Arg::addr(base, 4 * sizeof(int32_t))); |
| 588 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT5), Arg::addr(base, 5 * sizeof(int32_t))); |
| 589 |
root->append(Move, nullptr, Arg::imm(0), Tmp(GPRInfo::returnValueGPR)); |
| 590 |
root->append(Ret32, nullptr, Tmp(GPRInfo::returnValueGPR)); |
| 591 |
|
| 592 |
memset(things, 0, sizeof(things)); |
| 593 |
|
| 594 |
CHECK(!compileAndRun<int>(proc)); |
| 595 |
|
| 596 |
CHECK(things[0] == 1); |
| 597 |
CHECK(things[1] == 1); |
| 598 |
CHECK(things[2] == 3); |
| 599 |
CHECK(things[3] == 3); |
| 600 |
CHECK(things[4] == 3); |
| 601 |
CHECK(things[5] == 1); |
| 602 |
} |
| 603 |
|
| 604 |
void testShuffleRotateWithFringe() |
| 605 |
{ |
| 606 |
B3::Procedure proc; |
| 607 |
Code& code = proc.code(); |
| 608 |
|
| 609 |
BasicBlock* root = code.addBlock(); |
| 610 |
root->append(Move, nullptr, Arg::imm(1), Tmp(GPRInfo::regT0)); |
| 611 |
root->append(Move, nullptr, Arg::imm(2), Tmp(GPRInfo::regT1)); |
| 612 |
root->append(Move, nullptr, Arg::imm(3), Tmp(GPRInfo::regT2)); |
| 613 |
root->append(Move, nullptr, Arg::imm(4), Tmp(GPRInfo::regT3)); |
| 614 |
root->append(Move, nullptr, Arg::imm(5), Tmp(GPRInfo::regT4)); |
| 615 |
root->append(Move, nullptr, Arg::imm(6), Tmp(GPRInfo::regT5)); |
| 616 |
root->append( |
| 617 |
Shuffle, nullptr, |
| 618 |
Tmp(GPRInfo::regT0), Tmp(GPRInfo::regT1), Arg::widthArg(Arg::Width32), |
| 619 |
Tmp(GPRInfo::regT1), Tmp(GPRInfo::regT2), Arg::widthArg(Arg::Width32), |
| 620 |
Tmp(GPRInfo::regT2), Tmp(GPRInfo::regT0), Arg::widthArg(Arg::Width32), |
| 621 |
Tmp(GPRInfo::regT0), Tmp(GPRInfo::regT3), Arg::widthArg(Arg::Width32), |
| 622 |
Tmp(GPRInfo::regT1), Tmp(GPRInfo::regT4), Arg::widthArg(Arg::Width32), |
| 623 |
Tmp(GPRInfo::regT2), Tmp(GPRInfo::regT5), Arg::widthArg(Arg::Width32)); |
| 624 |
|
| 625 |
int32_t things[6]; |
| 626 |
Tmp base = code.newTmp(Arg::GP); |
| 627 |
root->append(Move, nullptr, Arg::imm64(bitwise_cast<intptr_t>(&things)), base); |
| 628 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT0), Arg::addr(base, 0 * sizeof(int32_t))); |
| 629 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT1), Arg::addr(base, 1 * sizeof(int32_t))); |
| 630 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT2), Arg::addr(base, 2 * sizeof(int32_t))); |
| 631 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT3), Arg::addr(base, 3 * sizeof(int32_t))); |
| 632 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT4), Arg::addr(base, 4 * sizeof(int32_t))); |
| 633 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT5), Arg::addr(base, 5 * sizeof(int32_t))); |
| 634 |
root->append(Move, nullptr, Arg::imm(0), Tmp(GPRInfo::returnValueGPR)); |
| 635 |
root->append(Ret32, nullptr, Tmp(GPRInfo::returnValueGPR)); |
| 636 |
|
| 637 |
memset(things, 0, sizeof(things)); |
| 638 |
|
| 639 |
CHECK(!compileAndRun<int>(proc)); |
| 640 |
|
| 641 |
CHECK(things[0] == 3); |
| 642 |
CHECK(things[1] == 1); |
| 643 |
CHECK(things[2] == 2); |
| 644 |
CHECK(things[3] == 1); |
| 645 |
CHECK(things[4] == 2); |
| 646 |
CHECK(things[5] == 3); |
| 647 |
} |
| 648 |
|
| 649 |
void testShuffleRotateWithLongFringe() |
| 650 |
{ |
| 651 |
B3::Procedure proc; |
| 652 |
Code& code = proc.code(); |
| 653 |
|
| 654 |
BasicBlock* root = code.addBlock(); |
| 655 |
root->append(Move, nullptr, Arg::imm(1), Tmp(GPRInfo::regT0)); |
| 656 |
root->append(Move, nullptr, Arg::imm(2), Tmp(GPRInfo::regT1)); |
| 657 |
root->append(Move, nullptr, Arg::imm(3), Tmp(GPRInfo::regT2)); |
| 658 |
root->append(Move, nullptr, Arg::imm(4), Tmp(GPRInfo::regT3)); |
| 659 |
root->append(Move, nullptr, Arg::imm(5), Tmp(GPRInfo::regT4)); |
| 660 |
root->append(Move, nullptr, Arg::imm(6), Tmp(GPRInfo::regT5)); |
| 661 |
root->append( |
| 662 |
Shuffle, nullptr, |
| 663 |
Tmp(GPRInfo::regT0), Tmp(GPRInfo::regT1), Arg::widthArg(Arg::Width32), |
| 664 |
Tmp(GPRInfo::regT1), Tmp(GPRInfo::regT2), Arg::widthArg(Arg::Width32), |
| 665 |
Tmp(GPRInfo::regT2), Tmp(GPRInfo::regT0), Arg::widthArg(Arg::Width32), |
| 666 |
Tmp(GPRInfo::regT0), Tmp(GPRInfo::regT3), Arg::widthArg(Arg::Width32), |
| 667 |
Tmp(GPRInfo::regT3), Tmp(GPRInfo::regT4), Arg::widthArg(Arg::Width32), |
| 668 |
Tmp(GPRInfo::regT4), Tmp(GPRInfo::regT5), Arg::widthArg(Arg::Width32)); |
| 669 |
|
| 670 |
int32_t things[6]; |
| 671 |
Tmp base = code.newTmp(Arg::GP); |
| 672 |
root->append(Move, nullptr, Arg::imm64(bitwise_cast<intptr_t>(&things)), base); |
| 673 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT0), Arg::addr(base, 0 * sizeof(int32_t))); |
| 674 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT1), Arg::addr(base, 1 * sizeof(int32_t))); |
| 675 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT2), Arg::addr(base, 2 * sizeof(int32_t))); |
| 676 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT3), Arg::addr(base, 3 * sizeof(int32_t))); |
| 677 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT4), Arg::addr(base, 4 * sizeof(int32_t))); |
| 678 |
root->append(Move32, nullptr, Tmp(GPRInfo::regT5), Arg::addr(base, 5 * sizeof(int32_t))); |
| 679 |
root->append(Move, nullptr, Arg::imm(0), Tmp(GPRInfo::returnValueGPR)); |
| 680 |
root->append(Ret32, nullptr, Tmp(GPRInfo::returnValueGPR)); |
| 681 |
|
| 682 |
memset(things, 0, sizeof(things)); |
| 683 |
|
| 684 |
CHECK(!compileAndRun<int>(proc)); |
| 685 |
|
| 686 |
CHECK(things[0] == 3); |
| 687 |
CHECK(things[1] == 1); |
| 688 |
CHECK(things[2] == 2); |
| 689 |
CHECK(things[3] == 1); |
| 690 |
CHECK(things[4] == 4); |
| 691 |
CHECK(things[5] == 5); |
| 692 |
} |
| 693 |
|
| 694 |
#define RUN(test) do { \ |
| 695 |
if (!shouldRun(#test)) \ |
| 696 |
break; \ |
| 697 |
tasks.append( \ |
| 698 |
createSharedTask<void()>( \ |
| 699 |
[&] () { \ |
| 700 |
dataLog(#test "...\n"); \ |
| 701 |
test; \ |
| 702 |
dataLog(#test ": OK!\n"); \ |
| 703 |
})); \ |
| 704 |
} while (false); |
| 705 |
|
| 706 |
void run(const char* filter) |
| 707 |
{ |
| 708 |
JSC::initializeThreading(); |
| 709 |
vm = &VM::create(LargeHeap).leakRef(); |
| 710 |
|
| 711 |
Deque<RefPtr<SharedTask<void()>>> tasks; |
| 712 |
|
| 713 |
auto shouldRun = [&] (const char* testName) -> bool { |
| 714 |
return !filter || !!strcasestr(testName, filter); |
| 715 |
}; |
| 716 |
|
| 717 |
RUN(testSimple()); |
| 718 |
RUN(testShuffleSimpleSwap()); |
| 719 |
RUN(testShuffleSimpleShift()); |
| 720 |
RUN(testShuffleLongShift()); |
| 721 |
RUN(testShuffleLongShiftBackwards()); |
| 722 |
RUN(testShuffleSimpleRotate()); |
| 723 |
RUN(testShuffleSimpleBroadcast()); |
| 724 |
RUN(testShuffleBroadcastAllRegs()); |
| 725 |
RUN(testShuffleTreeShift()); |
| 726 |
RUN(testShuffleTreeShiftBackward()); |
| 727 |
RUN(testShuffleTreeShiftOtherBackward()); |
| 728 |
RUN(testShuffleMultipleShifts()); |
| 729 |
RUN(testShuffleRotateWithFringe()); |
| 730 |
RUN(testShuffleRotateWithLongFringe()); |
| 731 |
|
| 732 |
// Still need the following tests: |
| 733 |
// - multiple shifts |
| 734 |
// - multiple rotates |
| 735 |
// - shift and rotate |
| 736 |
// - shift over all registers |
| 737 |
// - rotate over all registers |
| 738 |
// - rotate with multiple widths |
| 739 |
// - memory shift |
| 740 |
// - memory->memory shift |
| 741 |
// - memory->memory shift with no spare registers |
| 742 |
// - memory rotate |
| 743 |
// - memory rotate with multiple widths |
| 744 |
// - memory->memory rotate |
| 745 |
// - memory->memory rotate with multiple widths |
| 746 |
// - memory rotate with no spare registers |
| 747 |
// - memory rotate with no spare registers with multiple widths |
| 748 |
// - memory->memory rotate with no spare registers |
| 749 |
// - memory->memory rotate with no spare registers with multiple widths |
| 750 |
// - floating point |
| 751 |
|
| 752 |
if (tasks.isEmpty()) |
| 753 |
usage(); |
| 754 |
|
| 755 |
Lock lock; |
| 756 |
|
| 757 |
Vector<ThreadIdentifier> threads; |
| 758 |
for (unsigned i = filter ? 1 : WTF::numberOfProcessorCores(); i--;) { |
| 759 |
threads.append( |
| 760 |
createThread( |
| 761 |
"testb3 thread", |
| 762 |
[&] () { |
| 763 |
for (;;) { |
| 764 |
RefPtr<SharedTask<void()>> task; |
| 765 |
{ |
| 766 |
LockHolder locker(lock); |
| 767 |
if (tasks.isEmpty()) |
| 768 |
return; |
| 769 |
task = tasks.takeFirst(); |
| 770 |
} |
| 771 |
|
| 772 |
task->run(); |
| 773 |
} |
| 774 |
})); |
| 775 |
} |
| 776 |
|
| 777 |
for (ThreadIdentifier thread : threads) |
| 778 |
waitForThreadCompletion(thread); |
| 779 |
crashLock.lock(); |
| 780 |
} |
| 781 |
|
| 782 |
} // anonymois namespace |
| 783 |
|
| 784 |
#else // ENABLE(B3_JIT) |
| 785 |
|
| 786 |
static void run(const char*) |
| 787 |
{ |
| 788 |
dataLog("B3 JIT is not enabled.\n"); |
| 789 |
} |
| 790 |
|
| 791 |
#endif // ENABLE(B3_JIT) |
| 792 |
|
| 793 |
int main(int argc, char** argv) |
| 794 |
{ |
| 795 |
const char* filter = nullptr; |
| 796 |
switch (argc) { |
| 797 |
case 1: |
| 798 |
break; |
| 799 |
case 2: |
| 800 |
filter = argv[1]; |
| 801 |
break; |
| 802 |
default: |
| 803 |
usage(); |
| 804 |
break; |
| 805 |
} |
| 806 |
|
| 807 |
run(filter); |
| 808 |
return 0; |
| 809 |
} |