| 1 |
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
| 2 |
* vim: set ts=8 sts=2 et sw=2 tw=80: |
| 3 |
* This Source Code Form is subject to the terms of the Mozilla Public |
| 4 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 5 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 6 |
|
| 7 |
#include "jit/arm64/Lowering-arm64.h" |
| 8 |
|
| 9 |
#include "mozilla/MathAlgorithms.h" |
| 10 |
|
| 11 |
#include "jit/arm64/Assembler-arm64.h" |
| 12 |
#include "jit/Lowering.h" |
| 13 |
#include "jit/MIR-wasm.h" |
| 14 |
#include "jit/MIR.h" |
| 15 |
#include "wasm/WasmFeatures.h" // for wasm::ReportSimdAnalysis |
| 16 |
|
| 17 |
#include "jit/shared/Lowering-shared-inl.h" |
| 18 |
|
| 19 |
using namespace js; |
| 20 |
using namespace js::jit; |
| 21 |
|
| 22 |
using mozilla::FloorLog2; |
| 23 |
|
| 24 |
LBoxAllocation LIRGeneratorARM64::useBoxFixed(MDefinition* mir, Register reg1, |
| 25 |
Register, bool useAtStart) { |
| 26 |
MOZ_ASSERT(mir->type() == MIRType::Value); |
| 27 |
|
| 28 |
ensureDefined(mir); |
| 29 |
return LBoxAllocation(LUse(reg1, mir->virtualRegister(), useAtStart)); |
| 30 |
} |
| 31 |
|
| 32 |
LAllocation LIRGeneratorARM64::useByteOpRegister(MDefinition* mir) { |
| 33 |
return useRegister(mir); |
| 34 |
} |
| 35 |
|
| 36 |
LAllocation LIRGeneratorARM64::useByteOpRegisterAtStart(MDefinition* mir) { |
| 37 |
return useRegisterAtStart(mir); |
| 38 |
} |
| 39 |
|
| 40 |
LAllocation LIRGeneratorARM64::useByteOpRegisterOrNonDoubleConstant( |
| 41 |
MDefinition* mir) { |
| 42 |
return useRegisterOrNonDoubleConstant(mir); |
| 43 |
} |
| 44 |
|
| 45 |
LDefinition LIRGeneratorARM64::tempByteOpRegister() { return temp(); } |
| 46 |
|
| 47 |
LDefinition LIRGeneratorARM64::tempToUnbox() { return temp(); } |
| 48 |
|
| 49 |
void LIRGenerator::visitBox(MBox* box) { |
| 50 |
MDefinition* opd = box->getOperand(0); |
| 51 |
|
| 52 |
// If the operand is a constant, emit near its uses. |
| 53 |
if (opd->isConstant() && box->canEmitAtUses()) { |
| 54 |
emitAtUses(box); |
| 55 |
return; |
| 56 |
} |
| 57 |
|
| 58 |
if (opd->isConstant()) { |
| 59 |
define(new (alloc()) LValue(opd->toConstant()->toJSValue()), box, |
| 60 |
LDefinition(LDefinition::BOX)); |
| 61 |
} else { |
| 62 |
LBox* ins = new (alloc()) LBox(useRegister(opd), opd->type()); |
| 63 |
define(ins, box, LDefinition(LDefinition::BOX)); |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
void LIRGenerator::visitUnbox(MUnbox* unbox) { |
| 68 |
MDefinition* box = unbox->getOperand(0); |
| 69 |
MOZ_ASSERT(box->type() == MIRType::Value); |
| 70 |
|
| 71 |
LInstructionHelper<1, BOX_PIECES, 0>* lir; |
| 72 |
if (IsFloatingPointType(unbox->type())) { |
| 73 |
MOZ_ASSERT(unbox->type() == MIRType::Double); |
| 74 |
lir = new (alloc()) LUnboxFloatingPoint(useBoxAtStart(box)); |
| 75 |
} else if (unbox->fallible()) { |
| 76 |
// If the unbox is fallible, load the Value in a register first to |
| 77 |
// avoid multiple loads. |
| 78 |
lir = new (alloc()) LUnbox(useRegisterAtStart(box)); |
| 79 |
} else { |
| 80 |
// FIXME: It should be possible to useAtStart() here, but the DEBUG |
| 81 |
// code in CodeGenerator::visitUnbox() needs to handle non-Register |
| 82 |
// cases. ARM64 doesn't have an Operand type. |
| 83 |
lir = new (alloc()) LUnbox(useRegisterAtStart(box)); |
| 84 |
} |
| 85 |
|
| 86 |
if (unbox->fallible()) { |
| 87 |
assignSnapshot(lir, unbox->bailoutKind()); |
| 88 |
} |
| 89 |
|
| 90 |
define(lir, unbox); |
| 91 |
} |
| 92 |
|
| 93 |
void LIRGenerator::visitReturnImpl(MDefinition* opd, bool isGenerator) { |
| 94 |
MOZ_ASSERT(opd->type() == MIRType::Value); |
| 95 |
|
| 96 |
LReturn* ins = new (alloc()) LReturn(isGenerator); |
| 97 |
ins->setOperand(0, useFixed(opd, JSReturnReg)); |
| 98 |
add(ins); |
| 99 |
} |
| 100 |
|
| 101 |
// x = !y |
| 102 |
void LIRGeneratorARM64::lowerForALU(LInstructionHelper<1, 1, 0>* ins, |
| 103 |
MDefinition* mir, MDefinition* input) { |
| 104 |
ins->setOperand( |
| 105 |
0, ins->snapshot() ? useRegister(input) : useRegisterAtStart(input)); |
| 106 |
define( |
| 107 |
ins, mir, |
| 108 |
LDefinition(LDefinition::TypeFrom(mir->type()), LDefinition::REGISTER)); |
| 109 |
} |
| 110 |
|
| 111 |
// z = x+y |
| 112 |
void LIRGeneratorARM64::lowerForALU(LInstructionHelper<1, 2, 0>* ins, |
| 113 |
MDefinition* mir, MDefinition* lhs, |
| 114 |
MDefinition* rhs) { |
| 115 |
ins->setOperand(0, |
| 116 |
ins->snapshot() ? useRegister(lhs) : useRegisterAtStart(lhs)); |
| 117 |
ins->setOperand(1, ins->snapshot() ? useRegisterOrConstant(rhs) |
| 118 |
: useRegisterOrConstantAtStart(rhs)); |
| 119 |
define( |
| 120 |
ins, mir, |
| 121 |
LDefinition(LDefinition::TypeFrom(mir->type()), LDefinition::REGISTER)); |
| 122 |
} |
| 123 |
|
| 124 |
void LIRGeneratorARM64::lowerForFPU(LInstructionHelper<1, 1, 0>* ins, |
| 125 |
MDefinition* mir, MDefinition* input) { |
| 126 |
ins->setOperand(0, useRegisterAtStart(input)); |
| 127 |
define( |
| 128 |
ins, mir, |
| 129 |
LDefinition(LDefinition::TypeFrom(mir->type()), LDefinition::REGISTER)); |
| 130 |
} |
| 131 |
|
| 132 |
template <size_t Temps> |
| 133 |
void LIRGeneratorARM64::lowerForFPU(LInstructionHelper<1, 2, Temps>* ins, |
| 134 |
MDefinition* mir, MDefinition* lhs, |
| 135 |
MDefinition* rhs) { |
| 136 |
ins->setOperand(0, useRegisterAtStart(lhs)); |
| 137 |
ins->setOperand(1, useRegisterAtStart(rhs)); |
| 138 |
define( |
| 139 |
ins, mir, |
| 140 |
LDefinition(LDefinition::TypeFrom(mir->type()), LDefinition::REGISTER)); |
| 141 |
} |
| 142 |
|
| 143 |
template void LIRGeneratorARM64::lowerForFPU(LInstructionHelper<1, 2, 0>* ins, |
| 144 |
MDefinition* mir, MDefinition* lhs, |
| 145 |
MDefinition* rhs); |
| 146 |
template void LIRGeneratorARM64::lowerForFPU(LInstructionHelper<1, 2, 1>* ins, |
| 147 |
MDefinition* mir, MDefinition* lhs, |
| 148 |
MDefinition* rhs); |
| 149 |
|
| 150 |
void LIRGeneratorARM64::lowerForALUInt64( |
| 151 |
LInstructionHelper<INT64_PIECES, INT64_PIECES, 0>* ins, MDefinition* mir, |
| 152 |
MDefinition* input) { |
| 153 |
ins->setInt64Operand(0, useInt64RegisterAtStart(input)); |
| 154 |
defineInt64(ins, mir); |
| 155 |
} |
| 156 |
|
| 157 |
// These all currently have codegen that depends on reuse but only because the |
| 158 |
// masm API depends on that. We need new three-address masm APIs, for both |
| 159 |
// constant and variable rhs. |
| 160 |
// |
| 161 |
// MAdd => LAddI64 |
| 162 |
// MSub => LSubI64 |
| 163 |
// MBitAnd, MBitOr, MBitXor => LBitOpI64 |
| 164 |
void LIRGeneratorARM64::lowerForALUInt64( |
| 165 |
LInstructionHelper<INT64_PIECES, 2 * INT64_PIECES, 0>* ins, |
| 166 |
MDefinition* mir, MDefinition* lhs, MDefinition* rhs) { |
| 167 |
ins->setInt64Operand(0, useInt64RegisterAtStart(lhs)); |
| 168 |
ins->setInt64Operand(INT64_PIECES, useInt64RegisterOrConstantAtStart(rhs)); |
| 169 |
defineInt64(ins, mir); |
| 170 |
} |
| 171 |
|
| 172 |
void LIRGeneratorARM64::lowerForMulInt64(LMulI64* ins, MMul* mir, |
| 173 |
MDefinition* lhs, MDefinition* rhs) { |
| 174 |
ins->setLhs(useInt64RegisterAtStart(lhs)); |
| 175 |
ins->setRhs(useInt64RegisterOrConstantAtStart(rhs)); |
| 176 |
defineInt64(ins, mir); |
| 177 |
} |
| 178 |
|
| 179 |
template <class LInstr> |
| 180 |
void LIRGeneratorARM64::lowerForShiftInt64(LInstr* ins, MDefinition* mir, |
| 181 |
MDefinition* lhs, MDefinition* rhs) { |
| 182 |
if constexpr (std::is_same_v<LInstr, LShiftI64>) { |
| 183 |
ins->setLhs(useInt64RegisterAtStart(lhs)); |
| 184 |
ins->setRhs(useRegisterOrConstantAtStart(rhs)); |
| 185 |
} else { |
| 186 |
ins->setInput(useInt64RegisterAtStart(lhs)); |
| 187 |
ins->setCount(useRegisterOrConstantAtStart(rhs)); |
| 188 |
} |
| 189 |
defineInt64(ins, mir); |
| 190 |
} |
| 191 |
|
| 192 |
template void LIRGeneratorARM64::lowerForShiftInt64(LShiftI64* ins, |
| 193 |
MDefinition* mir, |
| 194 |
MDefinition* lhs, |
| 195 |
MDefinition* rhs); |
| 196 |
template void LIRGeneratorARM64::lowerForShiftInt64(LRotateI64* ins, |
| 197 |
MDefinition* mir, |
| 198 |
MDefinition* lhs, |
| 199 |
MDefinition* rhs); |
| 200 |
|
| 201 |
void LIRGeneratorARM64::lowerWasmBuiltinTruncateToInt32( |
| 202 |
MWasmBuiltinTruncateToInt32* ins) { |
| 203 |
MDefinition* opd = ins->input(); |
| 204 |
MOZ_ASSERT(opd->type() == MIRType::Double || opd->type() == MIRType::Float32); |
| 205 |
|
| 206 |
if (opd->type() == MIRType::Double) { |
| 207 |
define(new (alloc()) LWasmBuiltinTruncateDToInt32( |
| 208 |
useRegister(opd), useFixed(ins->instance(), InstanceReg), |
| 209 |
LDefinition::BogusTemp()), |
| 210 |
ins); |
| 211 |
return; |
| 212 |
} |
| 213 |
|
| 214 |
define(new (alloc()) LWasmBuiltinTruncateFToInt32( |
| 215 |
useRegister(opd), LAllocation(), LDefinition::BogusTemp()), |
| 216 |
ins); |
| 217 |
} |
| 218 |
|
| 219 |
void LIRGeneratorARM64::lowerUntypedPhiInput(MPhi* phi, uint32_t inputPosition, |
| 220 |
LBlock* block, size_t lirIndex) { |
| 221 |
lowerTypedPhiInput(phi, inputPosition, block, lirIndex); |
| 222 |
} |
| 223 |
|
| 224 |
void LIRGeneratorARM64::lowerForShift(LInstructionHelper<1, 2, 0>* ins, |
| 225 |
MDefinition* mir, MDefinition* lhs, |
| 226 |
MDefinition* rhs) { |
| 227 |
ins->setOperand(0, useRegister(lhs)); |
| 228 |
ins->setOperand(1, useRegisterOrConstant(rhs)); |
| 229 |
define(ins, mir); |
| 230 |
} |
| 231 |
|
| 232 |
void LIRGeneratorARM64::lowerDivI(MDiv* div) { |
| 233 |
if (div->isUnsigned()) { |
| 234 |
lowerUDiv(div); |
| 235 |
return; |
| 236 |
} |
| 237 |
|
| 238 |
if (div->rhs()->isConstant()) { |
| 239 |
LAllocation lhs = useRegister(div->lhs()); |
| 240 |
int32_t rhs = div->rhs()->toConstant()->toInt32(); |
| 241 |
int32_t shift = mozilla::FloorLog2(mozilla::Abs(rhs)); |
| 242 |
|
| 243 |
if (rhs != 0 && uint32_t(1) << shift == mozilla::Abs(rhs)) { |
| 244 |
LDivPowTwoI* lir = new (alloc()) LDivPowTwoI(lhs, shift, rhs < 0); |
| 245 |
if (div->fallible()) { |
| 246 |
assignSnapshot(lir, div->bailoutKind()); |
| 247 |
} |
| 248 |
define(lir, div); |
| 249 |
return; |
| 250 |
} |
| 251 |
if (rhs != 0) { |
| 252 |
LDivConstantI* lir = new (alloc()) LDivConstantI(lhs, temp(), rhs); |
| 253 |
if (div->fallible()) { |
| 254 |
assignSnapshot(lir, div->bailoutKind()); |
| 255 |
} |
| 256 |
define(lir, div); |
| 257 |
return; |
| 258 |
} |
| 259 |
} |
| 260 |
|
| 261 |
LDivI* lir = new (alloc()) |
| 262 |
LDivI(useRegister(div->lhs()), useRegister(div->rhs()), temp()); |
| 263 |
if (div->fallible()) { |
| 264 |
assignSnapshot(lir, div->bailoutKind()); |
| 265 |
} |
| 266 |
define(lir, div); |
| 267 |
} |
| 268 |
|
| 269 |
void LIRGeneratorARM64::lowerNegI(MInstruction* ins, MDefinition* input) { |
| 270 |
define(new (alloc()) LNegI(useRegisterAtStart(input)), ins); |
| 271 |
} |
| 272 |
|
| 273 |
void LIRGeneratorARM64::lowerNegI64(MInstruction* ins, MDefinition* input) { |
| 274 |
defineInt64(new (alloc()) LNegI64(useInt64RegisterAtStart(input)), ins); |
| 275 |
} |
| 276 |
|
| 277 |
void LIRGeneratorARM64::lowerMulI(MMul* mul, MDefinition* lhs, |
| 278 |
MDefinition* rhs) { |
| 279 |
LMulI* lir = new (alloc()) LMulI; |
| 280 |
if (mul->fallible()) { |
| 281 |
assignSnapshot(lir, mul->bailoutKind()); |
| 282 |
} |
| 283 |
lowerForALU(lir, mul, lhs, rhs); |
| 284 |
} |
| 285 |
|
| 286 |
void LIRGeneratorARM64::lowerModI(MMod* mod) { |
| 287 |
if (mod->isUnsigned()) { |
| 288 |
lowerUMod(mod); |
| 289 |
return; |
| 290 |
} |
| 291 |
|
| 292 |
if (mod->rhs()->isConstant()) { |
| 293 |
int32_t rhs = mod->rhs()->toConstant()->toInt32(); |
| 294 |
int32_t shift = FloorLog2(rhs); |
| 295 |
if (rhs > 0 && 1 << shift == rhs) { |
| 296 |
LModPowTwoI* lir = |
| 297 |
new (alloc()) LModPowTwoI(useRegister(mod->lhs()), shift); |
| 298 |
if (mod->fallible()) { |
| 299 |
assignSnapshot(lir, mod->bailoutKind()); |
| 300 |
} |
| 301 |
define(lir, mod); |
| 302 |
return; |
| 303 |
} else if (shift < 31 && (1 << (shift + 1)) - 1 == rhs) { |
| 304 |
LModMaskI* lir = new (alloc()) |
| 305 |
LModMaskI(useRegister(mod->lhs()), temp(), temp(), shift + 1); |
| 306 |
if (mod->fallible()) { |
| 307 |
assignSnapshot(lir, mod->bailoutKind()); |
| 308 |
} |
| 309 |
define(lir, mod); |
| 310 |
} |
| 311 |
} |
| 312 |
|
| 313 |
LModI* lir = |
| 314 |
new (alloc()) LModI(useRegister(mod->lhs()), useRegister(mod->rhs())); |
| 315 |
if (mod->fallible()) { |
| 316 |
assignSnapshot(lir, mod->bailoutKind()); |
| 317 |
} |
| 318 |
define(lir, mod); |
| 319 |
} |
| 320 |
|
| 321 |
void LIRGeneratorARM64::lowerDivI64(MDiv* div) { |
| 322 |
if (div->isUnsigned()) { |
| 323 |
lowerUDivI64(div); |
| 324 |
return; |
| 325 |
} |
| 326 |
|
| 327 |
LDivOrModI64* lir = new (alloc()) |
| 328 |
LDivOrModI64(useRegister(div->lhs()), useRegister(div->rhs())); |
| 329 |
defineInt64(lir, div); |
| 330 |
} |
| 331 |
|
| 332 |
void LIRGeneratorARM64::lowerUDivI64(MDiv* div) { |
| 333 |
LUDivOrModI64* lir = new (alloc()) |
| 334 |
LUDivOrModI64(useRegister(div->lhs()), useRegister(div->rhs())); |
| 335 |
defineInt64(lir, div); |
| 336 |
} |
| 337 |
|
| 338 |
void LIRGeneratorARM64::lowerUModI64(MMod* mod) { |
| 339 |
LUDivOrModI64* lir = new (alloc()) |
| 340 |
LUDivOrModI64(useRegister(mod->lhs()), useRegister(mod->rhs())); |
| 341 |
defineInt64(lir, mod); |
| 342 |
} |
| 343 |
|
| 344 |
void LIRGeneratorARM64::lowerWasmBuiltinDivI64(MWasmBuiltinDivI64* div) { |
| 345 |
MOZ_CRASH("We don't use runtime div for this architecture"); |
| 346 |
} |
| 347 |
|
| 348 |
void LIRGeneratorARM64::lowerModI64(MMod* mod) { |
| 349 |
if (mod->isUnsigned()) { |
| 350 |
lowerUModI64(mod); |
| 351 |
return; |
| 352 |
} |
| 353 |
|
| 354 |
LDivOrModI64* lir = new (alloc()) |
| 355 |
LDivOrModI64(useRegister(mod->lhs()), useRegister(mod->rhs())); |
| 356 |
defineInt64(lir, mod); |
| 357 |
} |
| 358 |
|
| 359 |
void LIRGeneratorARM64::lowerWasmBuiltinModI64(MWasmBuiltinModI64* mod) { |
| 360 |
MOZ_CRASH("We don't use runtime mod for this architecture"); |
| 361 |
} |
| 362 |
|
| 363 |
void LIRGenerator::visitPowHalf(MPowHalf* ins) { |
| 364 |
MDefinition* input = ins->input(); |
| 365 |
MOZ_ASSERT(input->type() == MIRType::Double); |
| 366 |
LPowHalfD* lir = new (alloc()) LPowHalfD(useRegister(input)); |
| 367 |
define(lir, ins); |
| 368 |
} |
| 369 |
|
| 370 |
void LIRGeneratorARM64::lowerWasmSelectI(MWasmSelect* select) { |
| 371 |
if (select->type() == MIRType::Simd128) { |
| 372 |
LAllocation t = useRegisterAtStart(select->trueExpr()); |
| 373 |
LAllocation f = useRegister(select->falseExpr()); |
| 374 |
LAllocation c = useRegister(select->condExpr()); |
| 375 |
auto* lir = new (alloc()) LWasmSelect(t, f, c); |
| 376 |
defineReuseInput(lir, select, LWasmSelect::TrueExprIndex); |
| 377 |
} else { |
| 378 |
LAllocation t = useRegisterAtStart(select->trueExpr()); |
| 379 |
LAllocation f = useRegisterAtStart(select->falseExpr()); |
| 380 |
LAllocation c = useRegisterAtStart(select->condExpr()); |
| 381 |
define(new (alloc()) LWasmSelect(t, f, c), select); |
| 382 |
} |
| 383 |
} |
| 384 |
|
| 385 |
void LIRGeneratorARM64::lowerWasmSelectI64(MWasmSelect* select) { |
| 386 |
LInt64Allocation t = useInt64RegisterAtStart(select->trueExpr()); |
| 387 |
LInt64Allocation f = useInt64RegisterAtStart(select->falseExpr()); |
| 388 |
LAllocation c = useRegisterAtStart(select->condExpr()); |
| 389 |
defineInt64(new (alloc()) LWasmSelectI64(t, f, c), select); |
| 390 |
} |
| 391 |
|
| 392 |
// On arm64 we specialize the cases: compare is {{U,}Int32, {U,}Int64}, |
| 393 |
// Float32, Double}, and select is {{U,}Int32, {U,}Int64}, Float32, Double}, |
| 394 |
// independently. |
| 395 |
bool LIRGeneratorARM64::canSpecializeWasmCompareAndSelect( |
| 396 |
MCompare::CompareType compTy, MIRType insTy) { |
| 397 |
return (insTy == MIRType::Int32 || insTy == MIRType::Int64 || |
| 398 |
insTy == MIRType::Float32 || insTy == MIRType::Double) && |
| 399 |
(compTy == MCompare::Compare_Int32 || |
| 400 |
compTy == MCompare::Compare_UInt32 || |
| 401 |
compTy == MCompare::Compare_Int64 || |
| 402 |
compTy == MCompare::Compare_UInt64 || |
| 403 |
compTy == MCompare::Compare_Float32 || |
| 404 |
compTy == MCompare::Compare_Double); |
| 405 |
} |
| 406 |
|
| 407 |
void LIRGeneratorARM64::lowerWasmCompareAndSelect(MWasmSelect* ins, |
| 408 |
MDefinition* lhs, |
| 409 |
MDefinition* rhs, |
| 410 |
MCompare::CompareType compTy, |
| 411 |
JSOp jsop) { |
| 412 |
MOZ_ASSERT(canSpecializeWasmCompareAndSelect(compTy, ins->type())); |
| 413 |
LAllocation rhsAlloc; |
| 414 |
if (compTy == MCompare::Compare_Float32 || |
| 415 |
compTy == MCompare::Compare_Double) { |
| 416 |
rhsAlloc = useRegisterAtStart(rhs); |
| 417 |
} else if (compTy == MCompare::Compare_Int32 || |
| 418 |
compTy == MCompare::Compare_UInt32 || |
| 419 |
compTy == MCompare::Compare_Int64 || |
| 420 |
compTy == MCompare::Compare_UInt64) { |
| 421 |
rhsAlloc = useRegisterOrConstantAtStart(rhs); |
| 422 |
} else { |
| 423 |
MOZ_CRASH("Unexpected type"); |
| 424 |
} |
| 425 |
auto* lir = new (alloc()) LWasmCompareAndSelect( |
| 426 |
useRegisterAtStart(lhs), rhsAlloc, useRegisterAtStart(ins->trueExpr()), |
| 427 |
useRegisterAtStart(ins->falseExpr()), compTy, jsop); |
| 428 |
define(lir, ins); |
| 429 |
} |
| 430 |
|
| 431 |
void LIRGenerator::visitAbs(MAbs* ins) { |
| 432 |
define(allocateAbs(ins, useRegisterAtStart(ins->input())), ins); |
| 433 |
} |
| 434 |
|
| 435 |
LTableSwitch* LIRGeneratorARM64::newLTableSwitch(const LAllocation& in, |
| 436 |
const LDefinition& inputCopy) { |
| 437 |
return new (alloc()) LTableSwitch(in, inputCopy, temp()); |
| 438 |
} |
| 439 |
|
| 440 |
LTableSwitchV* LIRGeneratorARM64::newLTableSwitchV(const LBoxAllocation& in) { |
| 441 |
return new (alloc()) LTableSwitchV(in, temp(), tempDouble(), temp()); |
| 442 |
} |
| 443 |
|
| 444 |
void LIRGeneratorARM64::lowerUrshD(MUrsh* mir) { |
| 445 |
MDefinition* lhs = mir->lhs(); |
| 446 |
MDefinition* rhs = mir->rhs(); |
| 447 |
|
| 448 |
MOZ_ASSERT(lhs->type() == MIRType::Int32); |
| 449 |
MOZ_ASSERT(rhs->type() == MIRType::Int32); |
| 450 |
|
| 451 |
LUrshD* lir = new (alloc()) |
| 452 |
LUrshD(useRegister(lhs), useRegisterOrConstant(rhs), temp()); |
| 453 |
define(lir, mir); |
| 454 |
} |
| 455 |
|
| 456 |
void LIRGeneratorARM64::lowerPowOfTwoI(MPow* mir) { |
| 457 |
int32_t base = mir->input()->toConstant()->toInt32(); |
| 458 |
MDefinition* power = mir->power(); |
| 459 |
|
| 460 |
auto* lir = new (alloc()) LPowOfTwoI(useRegister(power), base); |
| 461 |
assignSnapshot(lir, mir->bailoutKind()); |
| 462 |
define(lir, mir); |
| 463 |
} |
| 464 |
|
| 465 |
void LIRGeneratorARM64::lowerBigIntPtrLsh(MBigIntPtrLsh* ins) { |
| 466 |
auto* lir = new (alloc()) LBigIntPtrLsh( |
| 467 |
useRegister(ins->lhs()), useRegister(ins->rhs()), temp(), temp()); |
| 468 |
assignSnapshot(lir, ins->bailoutKind()); |
| 469 |
define(lir, ins); |
| 470 |
} |
| 471 |
|
| 472 |
void LIRGeneratorARM64::lowerBigIntPtrRsh(MBigIntPtrRsh* ins) { |
| 473 |
auto* lir = new (alloc()) LBigIntPtrRsh( |
| 474 |
useRegister(ins->lhs()), useRegister(ins->rhs()), temp(), temp()); |
| 475 |
assignSnapshot(lir, ins->bailoutKind()); |
| 476 |
define(lir, ins); |
| 477 |
} |
| 478 |
|
| 479 |
void LIRGeneratorARM64::lowerBigIntPtrDiv(MBigIntPtrDiv* ins) { |
| 480 |
auto* lir = new (alloc()) |
| 481 |
LBigIntPtrDiv(useRegister(ins->lhs()), useRegister(ins->rhs()), |
| 482 |
LDefinition::BogusTemp(), LDefinition::BogusTemp()); |
| 483 |
assignSnapshot(lir, ins->bailoutKind()); |
| 484 |
define(lir, ins); |
| 485 |
} |
| 486 |
|
| 487 |
void LIRGeneratorARM64::lowerBigIntPtrMod(MBigIntPtrMod* ins) { |
| 488 |
auto* lir = new (alloc()) |
| 489 |
LBigIntPtrMod(useRegister(ins->lhs()), useRegister(ins->rhs()), temp(), |
| 490 |
LDefinition::BogusTemp()); |
| 491 |
if (ins->canBeDivideByZero()) { |
| 492 |
assignSnapshot(lir, ins->bailoutKind()); |
| 493 |
} |
| 494 |
define(lir, ins); |
| 495 |
} |
| 496 |
|
| 497 |
#ifdef ENABLE_WASM_SIMD |
| 498 |
|
| 499 |
bool LIRGeneratorARM64::canFoldReduceSimd128AndBranch(wasm::SimdOp op) { |
| 500 |
switch (op) { |
| 501 |
case wasm::SimdOp::V128AnyTrue: |
| 502 |
case wasm::SimdOp::I8x16AllTrue: |
| 503 |
case wasm::SimdOp::I16x8AllTrue: |
| 504 |
case wasm::SimdOp::I32x4AllTrue: |
| 505 |
case wasm::SimdOp::I64x2AllTrue: |
| 506 |
return true; |
| 507 |
default: |
| 508 |
return false; |
| 509 |
} |
| 510 |
} |
| 511 |
|
| 512 |
bool LIRGeneratorARM64::canEmitWasmReduceSimd128AtUses( |
| 513 |
MWasmReduceSimd128* ins) { |
| 514 |
if (!ins->canEmitAtUses()) { |
| 515 |
return false; |
| 516 |
} |
| 517 |
// Only specific ops generating int32. |
| 518 |
if (ins->type() != MIRType::Int32) { |
| 519 |
return false; |
| 520 |
} |
| 521 |
if (!canFoldReduceSimd128AndBranch(ins->simdOp())) { |
| 522 |
return false; |
| 523 |
} |
| 524 |
// If never used then defer (it will be removed). |
| 525 |
MUseIterator iter(ins->usesBegin()); |
| 526 |
if (iter == ins->usesEnd()) { |
| 527 |
return true; |
| 528 |
} |
| 529 |
// We require an MTest consumer. |
| 530 |
MNode* node = iter->consumer(); |
| 531 |
if (!node->isDefinition() || !node->toDefinition()->isTest()) { |
| 532 |
return false; |
| 533 |
} |
| 534 |
// Defer only if there's only one use. |
| 535 |
iter++; |
| 536 |
return iter == ins->usesEnd(); |
| 537 |
} |
| 538 |
|
| 539 |
#endif |
| 540 |
|
| 541 |
void LIRGenerator::visitWasmNeg(MWasmNeg* ins) { |
| 542 |
switch (ins->type()) { |
| 543 |
case MIRType::Int32: |
| 544 |
define(new (alloc()) LNegI(useRegisterAtStart(ins->input())), ins); |
| 545 |
break; |
| 546 |
case MIRType::Float32: |
| 547 |
define(new (alloc()) LNegF(useRegisterAtStart(ins->input())), ins); |
| 548 |
break; |
| 549 |
case MIRType::Double: |
| 550 |
define(new (alloc()) LNegD(useRegisterAtStart(ins->input())), ins); |
| 551 |
break; |
| 552 |
default: |
| 553 |
MOZ_CRASH("unexpected type"); |
| 554 |
} |
| 555 |
} |
| 556 |
|
| 557 |
void LIRGeneratorARM64::lowerUDiv(MDiv* div) { |
| 558 |
LAllocation lhs = useRegister(div->lhs()); |
| 559 |
if (div->rhs()->isConstant()) { |
| 560 |
// NOTE: the result of toInt32 is coerced to uint32_t. |
| 561 |
uint32_t rhs = div->rhs()->toConstant()->toInt32(); |
| 562 |
int32_t shift = mozilla::FloorLog2(rhs); |
| 563 |
|
| 564 |
if (rhs != 0 && uint32_t(1) << shift == rhs) { |
| 565 |
LDivPowTwoI* lir = new (alloc()) LDivPowTwoI(lhs, shift, false); |
| 566 |
if (div->fallible()) { |
| 567 |
assignSnapshot(lir, div->bailoutKind()); |
| 568 |
} |
| 569 |
define(lir, div); |
| 570 |
return; |
| 571 |
} |
| 572 |
|
| 573 |
LUDivConstantI* lir = new (alloc()) LUDivConstantI(lhs, temp(), rhs); |
| 574 |
if (div->fallible()) { |
| 575 |
assignSnapshot(lir, div->bailoutKind()); |
| 576 |
} |
| 577 |
define(lir, div); |
| 578 |
return; |
| 579 |
} |
| 580 |
|
| 581 |
// Generate UDiv |
| 582 |
LAllocation rhs = useRegister(div->rhs()); |
| 583 |
LDefinition remainder = LDefinition::BogusTemp(); |
| 584 |
if (!div->canTruncateRemainder()) { |
| 585 |
remainder = temp(); |
| 586 |
} |
| 587 |
|
| 588 |
LUDiv* lir = new (alloc()) LUDiv(lhs, rhs, remainder); |
| 589 |
if (div->fallible()) { |
| 590 |
assignSnapshot(lir, div->bailoutKind()); |
| 591 |
} |
| 592 |
define(lir, div); |
| 593 |
} |
| 594 |
|
| 595 |
void LIRGeneratorARM64::lowerUMod(MMod* mod) { |
| 596 |
LUMod* lir = new (alloc()) |
| 597 |
LUMod(useRegister(mod->getOperand(0)), useRegister(mod->getOperand(1))); |
| 598 |
if (mod->fallible()) { |
| 599 |
assignSnapshot(lir, mod->bailoutKind()); |
| 600 |
} |
| 601 |
define(lir, mod); |
| 602 |
} |
| 603 |
|
| 604 |
void LIRGenerator::visitWasmUnsignedToDouble(MWasmUnsignedToDouble* ins) { |
| 605 |
MOZ_ASSERT(ins->input()->type() == MIRType::Int32); |
| 606 |
LWasmUint32ToDouble* lir = |
| 607 |
new (alloc()) LWasmUint32ToDouble(useRegisterAtStart(ins->input())); |
| 608 |
define(lir, ins); |
| 609 |
} |
| 610 |
|
| 611 |
void LIRGenerator::visitWasmUnsignedToFloat32(MWasmUnsignedToFloat32* ins) { |
| 612 |
MOZ_ASSERT(ins->input()->type() == MIRType::Int32); |
| 613 |
LWasmUint32ToFloat32* lir = |
| 614 |
new (alloc()) LWasmUint32ToFloat32(useRegisterAtStart(ins->input())); |
| 615 |
define(lir, ins); |
| 616 |
} |
| 617 |
|
| 618 |
void LIRGenerator::visitAsmJSLoadHeap(MAsmJSLoadHeap* ins) { |
| 619 |
MDefinition* base = ins->base(); |
| 620 |
MOZ_ASSERT(base->type() == MIRType::Int32); |
| 621 |
|
| 622 |
MDefinition* boundsCheckLimit = ins->boundsCheckLimit(); |
| 623 |
MOZ_ASSERT_IF(ins->needsBoundsCheck(), |
| 624 |
boundsCheckLimit->type() == MIRType::Int32); |
| 625 |
|
| 626 |
LAllocation baseAlloc = useRegisterAtStart(base); |
| 627 |
|
| 628 |
LAllocation limitAlloc = ins->needsBoundsCheck() |
| 629 |
? useRegisterAtStart(boundsCheckLimit) |
| 630 |
: LAllocation(); |
| 631 |
|
| 632 |
// We have no memory-base value, meaning that HeapReg is to be used as the |
| 633 |
// memory base. This follows from the definition of |
| 634 |
// FunctionCompiler::maybeLoadMemoryBase() in WasmIonCompile.cpp. |
| 635 |
MOZ_ASSERT(!ins->hasMemoryBase()); |
| 636 |
auto* lir = |
| 637 |
new (alloc()) LAsmJSLoadHeap(baseAlloc, limitAlloc, LAllocation()); |
| 638 |
define(lir, ins); |
| 639 |
} |
| 640 |
|
| 641 |
void LIRGenerator::visitAsmJSStoreHeap(MAsmJSStoreHeap* ins) { |
| 642 |
MDefinition* base = ins->base(); |
| 643 |
MOZ_ASSERT(base->type() == MIRType::Int32); |
| 644 |
|
| 645 |
MDefinition* boundsCheckLimit = ins->boundsCheckLimit(); |
| 646 |
MOZ_ASSERT_IF(ins->needsBoundsCheck(), |
| 647 |
boundsCheckLimit->type() == MIRType::Int32); |
| 648 |
|
| 649 |
LAllocation baseAlloc = useRegisterAtStart(base); |
| 650 |
|
| 651 |
LAllocation limitAlloc = ins->needsBoundsCheck() |
| 652 |
? useRegisterAtStart(boundsCheckLimit) |
| 653 |
: LAllocation(); |
| 654 |
|
| 655 |
// See comment in LIRGenerator::visitAsmJSStoreHeap just above. |
| 656 |
MOZ_ASSERT(!ins->hasMemoryBase()); |
| 657 |
add(new (alloc()) LAsmJSStoreHeap(baseAlloc, useRegisterAtStart(ins->value()), |
| 658 |
limitAlloc, LAllocation()), |
| 659 |
ins); |
| 660 |
} |
| 661 |
|
| 662 |
void LIRGenerator::visitWasmCompareExchangeHeap(MWasmCompareExchangeHeap* ins) { |
| 663 |
MDefinition* base = ins->base(); |
| 664 |
// See comment in visitWasmLoad re the type of 'base'. |
| 665 |
MOZ_ASSERT(base->type() == MIRType::Int32 || base->type() == MIRType::Int64); |
| 666 |
|
| 667 |
LAllocation memoryBase = ins->hasMemoryBase() |
| 668 |
? LAllocation(useRegister(ins->memoryBase())) |
| 669 |
: LGeneralReg(HeapReg); |
| 670 |
|
| 671 |
// Note, the access type may be Int64 here. |
| 672 |
|
| 673 |
LWasmCompareExchangeHeap* lir = new (alloc()) |
| 674 |
LWasmCompareExchangeHeap(useRegister(base), useRegister(ins->oldValue()), |
| 675 |
useRegister(ins->newValue()), memoryBase); |
| 676 |
|
| 677 |
define(lir, ins); |
| 678 |
} |
| 679 |
|
| 680 |
void LIRGenerator::visitWasmAtomicExchangeHeap(MWasmAtomicExchangeHeap* ins) { |
| 681 |
MDefinition* base = ins->base(); |
| 682 |
// See comment in visitWasmLoad re the type of 'base'. |
| 683 |
MOZ_ASSERT(base->type() == MIRType::Int32 || base->type() == MIRType::Int64); |
| 684 |
|
| 685 |
LAllocation memoryBase = ins->hasMemoryBase() |
| 686 |
? LAllocation(useRegister(ins->memoryBase())) |
| 687 |
: LGeneralReg(HeapReg); |
| 688 |
|
| 689 |
// Note, the access type may be Int64 here. |
| 690 |
|
| 691 |
LWasmAtomicExchangeHeap* lir = new (alloc()) LWasmAtomicExchangeHeap( |
| 692 |
useRegister(base), useRegister(ins->value()), memoryBase); |
| 693 |
define(lir, ins); |
| 694 |
} |
| 695 |
|
| 696 |
void LIRGenerator::visitWasmAtomicBinopHeap(MWasmAtomicBinopHeap* ins) { |
| 697 |
MDefinition* base = ins->base(); |
| 698 |
// See comment in visitWasmLoad re the type of 'base'. |
| 699 |
MOZ_ASSERT(base->type() == MIRType::Int32 || base->type() == MIRType::Int64); |
| 700 |
|
| 701 |
LAllocation memoryBase = ins->hasMemoryBase() |
| 702 |
? LAllocation(useRegister(ins->memoryBase())) |
| 703 |
: LGeneralReg(HeapReg); |
| 704 |
|
| 705 |
// Note, the access type may be Int64 here. |
| 706 |
|
| 707 |
if (!ins->hasUses()) { |
| 708 |
auto* lir = new (alloc()) LWasmAtomicBinopHeapForEffect( |
| 709 |
useRegister(base), useRegister(ins->value()), memoryBase, temp()); |
| 710 |
add(lir, ins); |
| 711 |
return; |
| 712 |
} |
| 713 |
|
| 714 |
auto* lir = new (alloc()) LWasmAtomicBinopHeap( |
| 715 |
useRegister(base), useRegister(ins->value()), memoryBase, temp()); |
| 716 |
define(lir, ins); |
| 717 |
} |
| 718 |
|
| 719 |
void LIRGeneratorARM64::lowerTruncateDToInt32(MTruncateToInt32* ins) { |
| 720 |
MDefinition* opd = ins->input(); |
| 721 |
MOZ_ASSERT(opd->type() == MIRType::Double); |
| 722 |
define(new (alloc()) |
| 723 |
LTruncateDToInt32(useRegister(opd), LDefinition::BogusTemp()), |
| 724 |
ins); |
| 725 |
} |
| 726 |
|
| 727 |
void LIRGeneratorARM64::lowerTruncateFToInt32(MTruncateToInt32* ins) { |
| 728 |
MDefinition* opd = ins->input(); |
| 729 |
MOZ_ASSERT(opd->type() == MIRType::Float32); |
| 730 |
define(new (alloc()) |
| 731 |
LTruncateFToInt32(useRegister(opd), LDefinition::BogusTemp()), |
| 732 |
ins); |
| 733 |
} |
| 734 |
|
| 735 |
void LIRGenerator::visitAtomicTypedArrayElementBinop( |
| 736 |
MAtomicTypedArrayElementBinop* ins) { |
| 737 |
MOZ_ASSERT(ins->arrayType() != Scalar::Uint8Clamped); |
| 738 |
MOZ_ASSERT(!Scalar::isFloatingType(ins->arrayType())); |
| 739 |
MOZ_ASSERT(ins->elements()->type() == MIRType::Elements); |
| 740 |
MOZ_ASSERT(ins->index()->type() == MIRType::IntPtr); |
| 741 |
|
| 742 |
const LUse elements = useRegister(ins->elements()); |
| 743 |
const LAllocation index = |
| 744 |
useRegisterOrIndexConstant(ins->index(), ins->arrayType()); |
| 745 |
|
| 746 |
if (Scalar::isBigIntType(ins->arrayType())) { |
| 747 |
LInt64Allocation value = useInt64Register(ins->value()); |
| 748 |
LInt64Definition temp = tempInt64(); |
| 749 |
|
| 750 |
// Case 1: the result of the operation is not used. |
| 751 |
|
| 752 |
if (ins->isForEffect()) { |
| 753 |
auto* lir = new (alloc()) LAtomicTypedArrayElementBinopForEffect64( |
| 754 |
elements, index, value, temp); |
| 755 |
add(lir, ins); |
| 756 |
return; |
| 757 |
} |
| 758 |
|
| 759 |
// Case 2: the result of the operation is used. |
| 760 |
|
| 761 |
auto* lir = new (alloc()) |
| 762 |
LAtomicTypedArrayElementBinop64(elements, index, value, temp); |
| 763 |
defineInt64(lir, ins); |
| 764 |
return; |
| 765 |
} |
| 766 |
|
| 767 |
LAllocation value = useRegister(ins->value()); |
| 768 |
|
| 769 |
if (ins->isForEffect()) { |
| 770 |
auto* lir = new (alloc()) |
| 771 |
LAtomicTypedArrayElementBinopForEffect(elements, index, value, temp()); |
| 772 |
add(lir, ins); |
| 773 |
return; |
| 774 |
} |
| 775 |
|
| 776 |
LDefinition tempDef1 = temp(); |
| 777 |
LDefinition tempDef2 = LDefinition::BogusTemp(); |
| 778 |
if (ins->arrayType() == Scalar::Uint32) { |
| 779 |
tempDef2 = temp(); |
| 780 |
} |
| 781 |
|
| 782 |
LAtomicTypedArrayElementBinop* lir = new (alloc()) |
| 783 |
LAtomicTypedArrayElementBinop(elements, index, value, tempDef1, tempDef2); |
| 784 |
|
| 785 |
define(lir, ins); |
| 786 |
} |
| 787 |
|
| 788 |
void LIRGenerator::visitCompareExchangeTypedArrayElement( |
| 789 |
MCompareExchangeTypedArrayElement* ins) { |
| 790 |
MOZ_ASSERT(!Scalar::isFloatingType(ins->arrayType())); |
| 791 |
MOZ_ASSERT(ins->elements()->type() == MIRType::Elements); |
| 792 |
MOZ_ASSERT(ins->index()->type() == MIRType::IntPtr); |
| 793 |
|
| 794 |
const LUse elements = useRegister(ins->elements()); |
| 795 |
const LAllocation index = |
| 796 |
useRegisterOrIndexConstant(ins->index(), ins->arrayType()); |
| 797 |
|
| 798 |
if (Scalar::isBigIntType(ins->arrayType())) { |
| 799 |
LInt64Allocation oldval = useInt64Register(ins->oldval()); |
| 800 |
LInt64Allocation newval = useInt64Register(ins->newval()); |
| 801 |
|
| 802 |
auto* lir = new (alloc()) |
| 803 |
LCompareExchangeTypedArrayElement64(elements, index, oldval, newval); |
| 804 |
defineInt64(lir, ins); |
| 805 |
return; |
| 806 |
} |
| 807 |
|
| 808 |
const LAllocation oldval = useRegister(ins->oldval()); |
| 809 |
const LAllocation newval = useRegister(ins->newval()); |
| 810 |
|
| 811 |
// If the target is an FPReg then we need a temporary at the CodeGenerator |
| 812 |
// level for creating the result. |
| 813 |
|
| 814 |
LDefinition outTemp = LDefinition::BogusTemp(); |
| 815 |
if (ins->arrayType() == Scalar::Uint32) { |
| 816 |
outTemp = temp(); |
| 817 |
} |
| 818 |
|
| 819 |
LCompareExchangeTypedArrayElement* lir = |
| 820 |
new (alloc()) LCompareExchangeTypedArrayElement(elements, index, oldval, |
| 821 |
newval, outTemp); |
| 822 |
|
| 823 |
define(lir, ins); |
| 824 |
} |
| 825 |
|
| 826 |
void LIRGenerator::visitAtomicExchangeTypedArrayElement( |
| 827 |
MAtomicExchangeTypedArrayElement* ins) { |
| 828 |
MOZ_ASSERT(ins->elements()->type() == MIRType::Elements); |
| 829 |
MOZ_ASSERT(ins->index()->type() == MIRType::IntPtr); |
| 830 |
|
| 831 |
const LUse elements = useRegister(ins->elements()); |
| 832 |
const LAllocation index = |
| 833 |
useRegisterOrIndexConstant(ins->index(), ins->arrayType()); |
| 834 |
|
| 835 |
if (Scalar::isBigIntType(ins->arrayType())) { |
| 836 |
LInt64Allocation value = useInt64Register(ins->value()); |
| 837 |
|
| 838 |
auto* lir = new (alloc()) |
| 839 |
LAtomicExchangeTypedArrayElement64(elements, index, value); |
| 840 |
defineInt64(lir, ins); |
| 841 |
return; |
| 842 |
} |
| 843 |
|
| 844 |
MOZ_ASSERT(ins->arrayType() <= Scalar::Uint32); |
| 845 |
|
| 846 |
const LAllocation value = useRegister(ins->value()); |
| 847 |
|
| 848 |
LDefinition tempDef = LDefinition::BogusTemp(); |
| 849 |
if (ins->arrayType() == Scalar::Uint32) { |
| 850 |
tempDef = temp(); |
| 851 |
} |
| 852 |
|
| 853 |
LAtomicExchangeTypedArrayElement* lir = new (alloc()) |
| 854 |
LAtomicExchangeTypedArrayElement(elements, index, value, tempDef); |
| 855 |
|
| 856 |
define(lir, ins); |
| 857 |
} |
| 858 |
|
| 859 |
void LIRGeneratorARM64::lowerAtomicLoad64(MLoadUnboxedScalar* ins) { |
| 860 |
const LUse elements = useRegister(ins->elements()); |
| 861 |
const LAllocation index = |
| 862 |
useRegisterOrIndexConstant(ins->index(), ins->storageType()); |
| 863 |
|
| 864 |
auto* lir = new (alloc()) LAtomicLoad64(elements, index); |
| 865 |
defineInt64(lir, ins); |
| 866 |
} |
| 867 |
|
| 868 |
void LIRGeneratorARM64::lowerAtomicStore64(MStoreUnboxedScalar* ins) { |
| 869 |
LUse elements = useRegister(ins->elements()); |
| 870 |
LAllocation index = |
| 871 |
useRegisterOrIndexConstant(ins->index(), ins->writeType()); |
| 872 |
LInt64Allocation value = useInt64Register(ins->value()); |
| 873 |
|
| 874 |
add(new (alloc()) LAtomicStore64(elements, index, value), ins); |
| 875 |
} |
| 876 |
|
| 877 |
void LIRGenerator::visitSubstr(MSubstr* ins) { |
| 878 |
LSubstr* lir = new (alloc()) |
| 879 |
LSubstr(useRegister(ins->string()), useRegister(ins->begin()), |
| 880 |
useRegister(ins->length()), temp(), temp(), temp()); |
| 881 |
define(lir, ins); |
| 882 |
assignSafepoint(lir, ins); |
| 883 |
} |
| 884 |
|
| 885 |
void LIRGenerator::visitWasmTruncateToInt64(MWasmTruncateToInt64* ins) { |
| 886 |
MDefinition* opd = ins->input(); |
| 887 |
MOZ_ASSERT(opd->type() == MIRType::Double || opd->type() == MIRType::Float32); |
| 888 |
|
| 889 |
defineInt64(new (alloc()) LWasmTruncateToInt64(useRegister(opd)), ins); |
| 890 |
} |
| 891 |
|
| 892 |
void LIRGeneratorARM64::lowerWasmBuiltinTruncateToInt64( |
| 893 |
MWasmBuiltinTruncateToInt64* ins) { |
| 894 |
MOZ_CRASH("We don't use WasmBuiltinTruncateToInt64 for arm64"); |
| 895 |
} |
| 896 |
|
| 897 |
void LIRGeneratorARM64::lowerBuiltinInt64ToFloatingPoint( |
| 898 |
MBuiltinInt64ToFloatingPoint* ins) { |
| 899 |
MOZ_CRASH("We don't use it for this architecture"); |
| 900 |
} |
| 901 |
|
| 902 |
void LIRGenerator::visitWasmLoad(MWasmLoad* ins) { |
| 903 |
MDefinition* base = ins->base(); |
| 904 |
// 'base' is a GPR but may be of either type. If it is 32-bit it is |
| 905 |
// zero-extended and can act as 64-bit. |
| 906 |
MOZ_ASSERT(base->type() == MIRType::Int32 || base->type() == MIRType::Int64); |
| 907 |
|
| 908 |
LAllocation memoryBase = |
| 909 |
ins->hasMemoryBase() ? LAllocation(useRegisterAtStart(ins->memoryBase())) |
| 910 |
: LGeneralReg(HeapReg); |
| 911 |
LAllocation ptr = useRegisterOrConstantAtStart(base); |
| 912 |
|
| 913 |
if (ins->type() == MIRType::Int64) { |
| 914 |
auto* lir = new (alloc()) LWasmLoadI64(ptr, memoryBase); |
| 915 |
defineInt64(lir, ins); |
| 916 |
} else { |
| 917 |
auto* lir = new (alloc()) LWasmLoad(ptr, memoryBase); |
| 918 |
define(lir, ins); |
| 919 |
} |
| 920 |
} |
| 921 |
|
| 922 |
void LIRGenerator::visitWasmStore(MWasmStore* ins) { |
| 923 |
MDefinition* base = ins->base(); |
| 924 |
// See comment in visitWasmLoad re the type of 'base'. |
| 925 |
MOZ_ASSERT(base->type() == MIRType::Int32 || base->type() == MIRType::Int64); |
| 926 |
|
| 927 |
MDefinition* value = ins->value(); |
| 928 |
|
| 929 |
LAllocation memoryBase = |
| 930 |
ins->hasMemoryBase() ? LAllocation(useRegisterAtStart(ins->memoryBase())) |
| 931 |
: LGeneralReg(HeapReg); |
| 932 |
LAllocation baseAlloc = useRegisterOrConstantAtStart(base); |
| 933 |
|
| 934 |
if (ins->access().type() == Scalar::Int64) { |
| 935 |
LInt64Allocation valueAlloc = useInt64RegisterAtStart(value); |
| 936 |
auto* lir = new (alloc()) LWasmStoreI64(baseAlloc, valueAlloc, memoryBase); |
| 937 |
add(lir, ins); |
| 938 |
return; |
| 939 |
} |
| 940 |
|
| 941 |
LAllocation valueAlloc = useRegisterAtStart(value); |
| 942 |
auto* lir = new (alloc()) LWasmStore(baseAlloc, valueAlloc, memoryBase); |
| 943 |
add(lir, ins); |
| 944 |
} |
| 945 |
|
| 946 |
void LIRGenerator::visitInt64ToFloatingPoint(MInt64ToFloatingPoint* ins) { |
| 947 |
MDefinition* opd = ins->input(); |
| 948 |
MOZ_ASSERT(opd->type() == MIRType::Int64); |
| 949 |
MOZ_ASSERT(IsFloatingPointType(ins->type())); |
| 950 |
|
| 951 |
define(new (alloc()) LInt64ToFloatingPoint(useInt64Register(opd)), ins); |
| 952 |
} |
| 953 |
|
| 954 |
void LIRGenerator::visitCopySign(MCopySign* ins) { |
| 955 |
MDefinition* lhs = ins->lhs(); |
| 956 |
MDefinition* rhs = ins->rhs(); |
| 957 |
|
| 958 |
MOZ_ASSERT(IsFloatingPointType(lhs->type())); |
| 959 |
MOZ_ASSERT(lhs->type() == rhs->type()); |
| 960 |
MOZ_ASSERT(lhs->type() == ins->type()); |
| 961 |
|
| 962 |
LInstructionHelper<1, 2, 2>* lir; |
| 963 |
if (lhs->type() == MIRType::Double) { |
| 964 |
lir = new (alloc()) LCopySignD(); |
| 965 |
} else { |
| 966 |
lir = new (alloc()) LCopySignF(); |
| 967 |
} |
| 968 |
|
| 969 |
lir->setOperand(0, useRegisterAtStart(lhs)); |
| 970 |
lir->setOperand(1, willHaveDifferentLIRNodes(lhs, rhs) |
| 971 |
? useRegister(rhs) |
| 972 |
: useRegisterAtStart(rhs)); |
| 973 |
// The copySignDouble and copySignFloat32 are optimized for lhs == output. |
| 974 |
// It also prevents rhs == output when lhs != output, avoids clobbering. |
| 975 |
defineReuseInput(lir, ins, 0); |
| 976 |
} |
| 977 |
|
| 978 |
void LIRGenerator::visitExtendInt32ToInt64(MExtendInt32ToInt64* ins) { |
| 979 |
defineInt64( |
| 980 |
new (alloc()) LExtendInt32ToInt64(useRegisterAtStart(ins->input())), ins); |
| 981 |
} |
| 982 |
|
| 983 |
void LIRGenerator::visitSignExtendInt64(MSignExtendInt64* ins) { |
| 984 |
defineInt64(new (alloc()) |
| 985 |
LSignExtendInt64(useInt64RegisterAtStart(ins->input())), |
| 986 |
ins); |
| 987 |
} |
| 988 |
|
| 989 |
void LIRGenerator::visitWasmTernarySimd128(MWasmTernarySimd128* ins) { |
| 990 |
#ifdef ENABLE_WASM_SIMD |
| 991 |
MOZ_ASSERT(ins->v0()->type() == MIRType::Simd128); |
| 992 |
MOZ_ASSERT(ins->v1()->type() == MIRType::Simd128); |
| 993 |
MOZ_ASSERT(ins->v2()->type() == MIRType::Simd128); |
| 994 |
MOZ_ASSERT(ins->type() == MIRType::Simd128); |
| 995 |
|
| 996 |
switch (ins->simdOp()) { |
| 997 |
case wasm::SimdOp::V128Bitselect: { |
| 998 |
auto* lir = new (alloc()) |
| 999 |
LWasmTernarySimd128(useRegister(ins->v0()), useRegister(ins->v1()), |
| 1000 |
useRegisterAtStart(ins->v2()), |
| 1001 |
LDefinition::BogusTemp(), ins->simdOp()); |
| 1002 |
// On ARM64, control register is used as output at machine instruction. |
| 1003 |
defineReuseInput(lir, ins, LWasmTernarySimd128::V2Index); |
| 1004 |
break; |
| 1005 |
} |
| 1006 |
case wasm::SimdOp::F32x4RelaxedMadd: |
| 1007 |
case wasm::SimdOp::F32x4RelaxedNmadd: |
| 1008 |
case wasm::SimdOp::F64x2RelaxedMadd: |
| 1009 |
case wasm::SimdOp::F64x2RelaxedNmadd: { |
| 1010 |
auto* lir = new (alloc()) |
| 1011 |
LWasmTernarySimd128(useRegister(ins->v0()), useRegister(ins->v1()), |
| 1012 |
useRegisterAtStart(ins->v2()), |
| 1013 |
LDefinition::BogusTemp(), ins->simdOp()); |
| 1014 |
defineReuseInput(lir, ins, LWasmTernarySimd128::V2Index); |
| 1015 |
break; |
| 1016 |
} |
| 1017 |
case wasm::SimdOp::I32x4RelaxedDotI8x16I7x16AddS: { |
| 1018 |
auto* lir = new (alloc()) LWasmTernarySimd128( |
| 1019 |
useRegister(ins->v0()), useRegister(ins->v1()), |
| 1020 |
useRegisterAtStart(ins->v2()), tempSimd128(), ins->simdOp()); |
| 1021 |
defineReuseInput(lir, ins, LWasmTernarySimd128::V2Index); |
| 1022 |
break; |
| 1023 |
} |
| 1024 |
case wasm::SimdOp::I8x16RelaxedLaneSelect: |
| 1025 |
case wasm::SimdOp::I16x8RelaxedLaneSelect: |
| 1026 |
case wasm::SimdOp::I32x4RelaxedLaneSelect: |
| 1027 |
case wasm::SimdOp::I64x2RelaxedLaneSelect: { |
| 1028 |
auto* lir = new (alloc()) |
| 1029 |
LWasmTernarySimd128(useRegister(ins->v0()), useRegister(ins->v1()), |
| 1030 |
useRegisterAtStart(ins->v2()), |
| 1031 |
LDefinition::BogusTemp(), ins->simdOp()); |
| 1032 |
defineReuseInput(lir, ins, LWasmTernarySimd128::V2Index); |
| 1033 |
break; |
| 1034 |
} |
| 1035 |
default: |
| 1036 |
MOZ_CRASH("NYI"); |
| 1037 |
} |
| 1038 |
#else |
| 1039 |
MOZ_CRASH("No SIMD"); |
| 1040 |
#endif |
| 1041 |
} |
| 1042 |
|
| 1043 |
void LIRGenerator::visitWasmBinarySimd128(MWasmBinarySimd128* ins) { |
| 1044 |
#ifdef ENABLE_WASM_SIMD |
| 1045 |
MDefinition* lhs = ins->lhs(); |
| 1046 |
MDefinition* rhs = ins->rhs(); |
| 1047 |
wasm::SimdOp op = ins->simdOp(); |
| 1048 |
|
| 1049 |
MOZ_ASSERT(lhs->type() == MIRType::Simd128); |
| 1050 |
MOZ_ASSERT(rhs->type() == MIRType::Simd128); |
| 1051 |
MOZ_ASSERT(ins->type() == MIRType::Simd128); |
| 1052 |
|
| 1053 |
LAllocation lhsAlloc = useRegisterAtStart(lhs); |
| 1054 |
LAllocation rhsAlloc = useRegisterAtStart(rhs); |
| 1055 |
LDefinition tempReg0 = LDefinition::BogusTemp(); |
| 1056 |
LDefinition tempReg1 = LDefinition::BogusTemp(); |
| 1057 |
if (op == wasm::SimdOp::I64x2Mul) { |
| 1058 |
tempReg0 = tempSimd128(); |
| 1059 |
tempReg1 = tempSimd128(); |
| 1060 |
} |
| 1061 |
auto* lir = new (alloc()) |
| 1062 |
LWasmBinarySimd128(lhsAlloc, rhsAlloc, tempReg0, tempReg1, op); |
| 1063 |
define(lir, ins); |
| 1064 |
#else |
| 1065 |
MOZ_CRASH("No SIMD"); |
| 1066 |
#endif |
| 1067 |
} |
| 1068 |
|
| 1069 |
#ifdef ENABLE_WASM_SIMD |
| 1070 |
bool MWasmTernarySimd128::specializeBitselectConstantMaskAsShuffle( |
| 1071 |
int8_t shuffle[16]) { |
| 1072 |
return false; |
| 1073 |
} |
| 1074 |
bool MWasmTernarySimd128::canRelaxBitselect() { return false; } |
| 1075 |
|
| 1076 |
bool MWasmBinarySimd128::canPmaddubsw() { return false; } |
| 1077 |
#endif |
| 1078 |
|
| 1079 |
bool MWasmBinarySimd128::specializeForConstantRhs() { |
| 1080 |
// Probably many we want to do here |
| 1081 |
return false; |
| 1082 |
} |
| 1083 |
|
| 1084 |
void LIRGenerator::visitWasmBinarySimd128WithConstant( |
| 1085 |
MWasmBinarySimd128WithConstant* ins) { |
| 1086 |
MOZ_CRASH("binary SIMD with constant NYI"); |
| 1087 |
} |
| 1088 |
|
| 1089 |
void LIRGenerator::visitWasmShiftSimd128(MWasmShiftSimd128* ins) { |
| 1090 |
#ifdef ENABLE_WASM_SIMD |
| 1091 |
MDefinition* lhs = ins->lhs(); |
| 1092 |
MDefinition* rhs = ins->rhs(); |
| 1093 |
|
| 1094 |
MOZ_ASSERT(lhs->type() == MIRType::Simd128); |
| 1095 |
MOZ_ASSERT(rhs->type() == MIRType::Int32); |
| 1096 |
MOZ_ASSERT(ins->type() == MIRType::Simd128); |
| 1097 |
|
| 1098 |
if (rhs->isConstant()) { |
| 1099 |
int32_t shiftCount = rhs->toConstant()->toInt32(); |
| 1100 |
switch (ins->simdOp()) { |
| 1101 |
case wasm::SimdOp::I8x16Shl: |
| 1102 |
case wasm::SimdOp::I8x16ShrU: |
| 1103 |
case wasm::SimdOp::I8x16ShrS: |
| 1104 |
shiftCount &= 7; |
| 1105 |
break; |
| 1106 |
case wasm::SimdOp::I16x8Shl: |
| 1107 |
case wasm::SimdOp::I16x8ShrU: |
| 1108 |
case wasm::SimdOp::I16x8ShrS: |
| 1109 |
shiftCount &= 15; |
| 1110 |
break; |
| 1111 |
case wasm::SimdOp::I32x4Shl: |
| 1112 |
case wasm::SimdOp::I32x4ShrU: |
| 1113 |
case wasm::SimdOp::I32x4ShrS: |
| 1114 |
shiftCount &= 31; |
| 1115 |
break; |
| 1116 |
case wasm::SimdOp::I64x2Shl: |
| 1117 |
case wasm::SimdOp::I64x2ShrU: |
| 1118 |
case wasm::SimdOp::I64x2ShrS: |
| 1119 |
shiftCount &= 63; |
| 1120 |
break; |
| 1121 |
default: |
| 1122 |
MOZ_CRASH("Unexpected shift operation"); |
| 1123 |
} |
| 1124 |
# ifdef DEBUG |
| 1125 |
js::wasm::ReportSimdAnalysis("shift -> constant shift"); |
| 1126 |
# endif |
| 1127 |
auto* lir = new (alloc()) |
| 1128 |
LWasmConstantShiftSimd128(useRegisterAtStart(lhs), shiftCount); |
| 1129 |
define(lir, ins); |
| 1130 |
return; |
| 1131 |
} |
| 1132 |
|
| 1133 |
# ifdef DEBUG |
| 1134 |
js::wasm::ReportSimdAnalysis("shift -> variable shift"); |
| 1135 |
# endif |
| 1136 |
|
| 1137 |
LAllocation lhsDestAlloc = useRegisterAtStart(lhs); |
| 1138 |
LAllocation rhsAlloc = useRegisterAtStart(rhs); |
| 1139 |
auto* lir = new (alloc()) LWasmVariableShiftSimd128(lhsDestAlloc, rhsAlloc); |
| 1140 |
define(lir, ins); |
| 1141 |
#else |
| 1142 |
MOZ_CRASH("No SIMD"); |
| 1143 |
#endif |
| 1144 |
} |
| 1145 |
|
| 1146 |
void LIRGenerator::visitWasmShuffleSimd128(MWasmShuffleSimd128* ins) { |
| 1147 |
#ifdef ENABLE_WASM_SIMD |
| 1148 |
MOZ_ASSERT(ins->lhs()->type() == MIRType::Simd128); |
| 1149 |
MOZ_ASSERT(ins->rhs()->type() == MIRType::Simd128); |
| 1150 |
MOZ_ASSERT(ins->type() == MIRType::Simd128); |
| 1151 |
|
| 1152 |
SimdShuffle s = ins->shuffle(); |
| 1153 |
switch (s.opd) { |
| 1154 |
case SimdShuffle::Operand::LEFT: |
| 1155 |
case SimdShuffle::Operand::RIGHT: { |
| 1156 |
LAllocation src; |
| 1157 |
switch (*s.permuteOp) { |
| 1158 |
case SimdPermuteOp::MOVE: |
| 1159 |
case SimdPermuteOp::BROADCAST_8x16: |
| 1160 |
case SimdPermuteOp::BROADCAST_16x8: |
| 1161 |
case SimdPermuteOp::PERMUTE_8x16: |
| 1162 |
case SimdPermuteOp::PERMUTE_16x8: |
| 1163 |
case SimdPermuteOp::PERMUTE_32x4: |
| 1164 |
case SimdPermuteOp::ROTATE_RIGHT_8x16: |
| 1165 |
case SimdPermuteOp::SHIFT_LEFT_8x16: |
| 1166 |
case SimdPermuteOp::SHIFT_RIGHT_8x16: |
| 1167 |
case SimdPermuteOp::REVERSE_16x8: |
| 1168 |
case SimdPermuteOp::REVERSE_32x4: |
| 1169 |
case SimdPermuteOp::REVERSE_64x2: |
| 1170 |
case SimdPermuteOp::ZERO_EXTEND_8x16_TO_16x8: |
| 1171 |
case SimdPermuteOp::ZERO_EXTEND_8x16_TO_32x4: |
| 1172 |
case SimdPermuteOp::ZERO_EXTEND_8x16_TO_64x2: |
| 1173 |
case SimdPermuteOp::ZERO_EXTEND_16x8_TO_32x4: |
| 1174 |
case SimdPermuteOp::ZERO_EXTEND_16x8_TO_64x2: |
| 1175 |
case SimdPermuteOp::ZERO_EXTEND_32x4_TO_64x2: |
| 1176 |
break; |
| 1177 |
default: |
| 1178 |
MOZ_CRASH("Unexpected operator"); |
| 1179 |
} |
| 1180 |
if (s.opd == SimdShuffle::Operand::LEFT) { |
| 1181 |
src = useRegisterAtStart(ins->lhs()); |
| 1182 |
} else { |
| 1183 |
src = useRegisterAtStart(ins->rhs()); |
| 1184 |
} |
| 1185 |
auto* lir = |
| 1186 |
new (alloc()) LWasmPermuteSimd128(src, *s.permuteOp, s.control); |
| 1187 |
define(lir, ins); |
| 1188 |
break; |
| 1189 |
} |
| 1190 |
case SimdShuffle::Operand::BOTH: |
| 1191 |
case SimdShuffle::Operand::BOTH_SWAPPED: { |
| 1192 |
LAllocation lhs; |
| 1193 |
LAllocation rhs; |
| 1194 |
if (s.opd == SimdShuffle::Operand::BOTH) { |
| 1195 |
lhs = useRegisterAtStart(ins->lhs()); |
| 1196 |
rhs = useRegisterAtStart(ins->rhs()); |
| 1197 |
} else { |
| 1198 |
lhs = useRegisterAtStart(ins->rhs()); |
| 1199 |
rhs = useRegisterAtStart(ins->lhs()); |
| 1200 |
} |
| 1201 |
auto* lir = |
| 1202 |
new (alloc()) LWasmShuffleSimd128(lhs, rhs, *s.shuffleOp, s.control); |
| 1203 |
define(lir, ins); |
| 1204 |
break; |
| 1205 |
} |
| 1206 |
} |
| 1207 |
#else |
| 1208 |
MOZ_CRASH("No SIMD"); |
| 1209 |
#endif |
| 1210 |
} |
| 1211 |
|
| 1212 |
void LIRGenerator::visitWasmReplaceLaneSimd128(MWasmReplaceLaneSimd128* ins) { |
| 1213 |
#ifdef ENABLE_WASM_SIMD |
| 1214 |
MOZ_ASSERT(ins->lhs()->type() == MIRType::Simd128); |
| 1215 |
MOZ_ASSERT(ins->type() == MIRType::Simd128); |
| 1216 |
|
| 1217 |
// Optimal code generation reuses the lhs register because the rhs scalar is |
| 1218 |
// merged into a vector lhs. |
| 1219 |
LAllocation lhs = useRegisterAtStart(ins->lhs()); |
| 1220 |
if (ins->rhs()->type() == MIRType::Int64) { |
| 1221 |
auto* lir = new (alloc()) |
| 1222 |
LWasmReplaceInt64LaneSimd128(lhs, useInt64Register(ins->rhs())); |
| 1223 |
defineReuseInput(lir, ins, 0); |
| 1224 |
} else { |
| 1225 |
auto* lir = |
| 1226 |
new (alloc()) LWasmReplaceLaneSimd128(lhs, useRegister(ins->rhs())); |
| 1227 |
defineReuseInput(lir, ins, 0); |
| 1228 |
} |
| 1229 |
#else |
| 1230 |
MOZ_CRASH("No SIMD"); |
| 1231 |
#endif |
| 1232 |
} |
| 1233 |
|
| 1234 |
void LIRGenerator::visitWasmScalarToSimd128(MWasmScalarToSimd128* ins) { |
| 1235 |
#ifdef ENABLE_WASM_SIMD |
| 1236 |
MOZ_ASSERT(ins->type() == MIRType::Simd128); |
| 1237 |
|
| 1238 |
switch (ins->input()->type()) { |
| 1239 |
case MIRType::Int64: { |
| 1240 |
// 64-bit integer splats. |
| 1241 |
// Load-and-(sign|zero)extend. |
| 1242 |
auto* lir = new (alloc()) |
| 1243 |
LWasmInt64ToSimd128(useInt64RegisterAtStart(ins->input())); |
| 1244 |
define(lir, ins); |
| 1245 |
break; |
| 1246 |
} |
| 1247 |
case MIRType::Float32: |
| 1248 |
case MIRType::Double: { |
| 1249 |
// Floating-point splats. |
| 1250 |
auto* lir = |
| 1251 |
new (alloc()) LWasmScalarToSimd128(useRegisterAtStart(ins->input())); |
| 1252 |
define(lir, ins); |
| 1253 |
break; |
| 1254 |
} |
| 1255 |
default: { |
| 1256 |
// 32-bit integer splats. |
| 1257 |
auto* lir = |
| 1258 |
new (alloc()) LWasmScalarToSimd128(useRegisterAtStart(ins->input())); |
| 1259 |
define(lir, ins); |
| 1260 |
break; |
| 1261 |
} |
| 1262 |
} |
| 1263 |
#else |
| 1264 |
MOZ_CRASH("No SIMD"); |
| 1265 |
#endif |
| 1266 |
} |
| 1267 |
|
| 1268 |
void LIRGenerator::visitWasmUnarySimd128(MWasmUnarySimd128* ins) { |
| 1269 |
#ifdef ENABLE_WASM_SIMD |
| 1270 |
MOZ_ASSERT(ins->input()->type() == MIRType::Simd128); |
| 1271 |
MOZ_ASSERT(ins->type() == MIRType::Simd128); |
| 1272 |
|
| 1273 |
LDefinition tempReg = LDefinition::BogusTemp(); |
| 1274 |
switch (ins->simdOp()) { |
| 1275 |
case wasm::SimdOp::I8x16Neg: |
| 1276 |
case wasm::SimdOp::I16x8Neg: |
| 1277 |
case wasm::SimdOp::I32x4Neg: |
| 1278 |
case wasm::SimdOp::I64x2Neg: |
| 1279 |
case wasm::SimdOp::F32x4Neg: |
| 1280 |
case wasm::SimdOp::F64x2Neg: |
| 1281 |
case wasm::SimdOp::F32x4Abs: |
| 1282 |
case wasm::SimdOp::F64x2Abs: |
| 1283 |
case wasm::SimdOp::V128Not: |
| 1284 |
case wasm::SimdOp::F32x4Sqrt: |
| 1285 |
case wasm::SimdOp::F64x2Sqrt: |
| 1286 |
case wasm::SimdOp::I8x16Abs: |
| 1287 |
case wasm::SimdOp::I16x8Abs: |
| 1288 |
case wasm::SimdOp::I32x4Abs: |
| 1289 |
case wasm::SimdOp::I64x2Abs: |
| 1290 |
case wasm::SimdOp::I32x4TruncSatF32x4S: |
| 1291 |
case wasm::SimdOp::F32x4ConvertI32x4U: |
| 1292 |
case wasm::SimdOp::I32x4TruncSatF32x4U: |
| 1293 |
case wasm::SimdOp::I16x8ExtendLowI8x16S: |
| 1294 |
case wasm::SimdOp::I16x8ExtendHighI8x16S: |
| 1295 |
case wasm::SimdOp::I16x8ExtendLowI8x16U: |
| 1296 |
case wasm::SimdOp::I16x8ExtendHighI8x16U: |
| 1297 |
case wasm::SimdOp::I32x4ExtendLowI16x8S: |
| 1298 |
case wasm::SimdOp::I32x4ExtendHighI16x8S: |
| 1299 |
case wasm::SimdOp::I32x4ExtendLowI16x8U: |
| 1300 |
case wasm::SimdOp::I32x4ExtendHighI16x8U: |
| 1301 |
case wasm::SimdOp::I64x2ExtendLowI32x4S: |
| 1302 |
case wasm::SimdOp::I64x2ExtendHighI32x4S: |
| 1303 |
case wasm::SimdOp::I64x2ExtendLowI32x4U: |
| 1304 |
case wasm::SimdOp::I64x2ExtendHighI32x4U: |
| 1305 |
case wasm::SimdOp::F32x4ConvertI32x4S: |
| 1306 |
case wasm::SimdOp::F32x4Ceil: |
| 1307 |
case wasm::SimdOp::F32x4Floor: |
| 1308 |
case wasm::SimdOp::F32x4Trunc: |
| 1309 |
case wasm::SimdOp::F32x4Nearest: |
| 1310 |
case wasm::SimdOp::F64x2Ceil: |
| 1311 |
case wasm::SimdOp::F64x2Floor: |
| 1312 |
case wasm::SimdOp::F64x2Trunc: |
| 1313 |
case wasm::SimdOp::F64x2Nearest: |
| 1314 |
case wasm::SimdOp::F32x4DemoteF64x2Zero: |
| 1315 |
case wasm::SimdOp::F64x2PromoteLowF32x4: |
| 1316 |
case wasm::SimdOp::F64x2ConvertLowI32x4S: |
| 1317 |
case wasm::SimdOp::F64x2ConvertLowI32x4U: |
| 1318 |
case wasm::SimdOp::I16x8ExtaddPairwiseI8x16S: |
| 1319 |
case wasm::SimdOp::I16x8ExtaddPairwiseI8x16U: |
| 1320 |
case wasm::SimdOp::I32x4ExtaddPairwiseI16x8S: |
| 1321 |
case wasm::SimdOp::I32x4ExtaddPairwiseI16x8U: |
| 1322 |
case wasm::SimdOp::I8x16Popcnt: |
| 1323 |
case wasm::SimdOp::I32x4RelaxedTruncF32x4S: |
| 1324 |
case wasm::SimdOp::I32x4RelaxedTruncF32x4U: |
| 1325 |
case wasm::SimdOp::I32x4RelaxedTruncF64x2SZero: |
| 1326 |
case wasm::SimdOp::I32x4RelaxedTruncF64x2UZero: |
| 1327 |
break; |
| 1328 |
case wasm::SimdOp::I32x4TruncSatF64x2SZero: |
| 1329 |
case wasm::SimdOp::I32x4TruncSatF64x2UZero: |
| 1330 |
tempReg = tempSimd128(); |
| 1331 |
break; |
| 1332 |
default: |
| 1333 |
MOZ_CRASH("Unary SimdOp not implemented"); |
| 1334 |
} |
| 1335 |
|
| 1336 |
LUse input = useRegisterAtStart(ins->input()); |
| 1337 |
LWasmUnarySimd128* lir = new (alloc()) LWasmUnarySimd128(input, tempReg); |
| 1338 |
define(lir, ins); |
| 1339 |
#else |
| 1340 |
MOZ_CRASH("No SIMD"); |
| 1341 |
#endif |
| 1342 |
} |
| 1343 |
|
| 1344 |
void LIRGenerator::visitWasmReduceSimd128(MWasmReduceSimd128* ins) { |
| 1345 |
#ifdef ENABLE_WASM_SIMD |
| 1346 |
if (canEmitWasmReduceSimd128AtUses(ins)) { |
| 1347 |
emitAtUses(ins); |
| 1348 |
return; |
| 1349 |
} |
| 1350 |
|
| 1351 |
// Reductions (any_true, all_true, bitmask, extract_lane) uniformly prefer |
| 1352 |
// useRegisterAtStart: |
| 1353 |
// |
| 1354 |
// - In most cases, the input type differs from the output type, so there's no |
| 1355 |
// conflict and it doesn't really matter. |
| 1356 |
// |
| 1357 |
// - For extract_lane(0) on F32x4 and F64x2, input == output results in zero |
| 1358 |
// code being generated. |
| 1359 |
// |
| 1360 |
// - For extract_lane(k > 0) on F32x4 and F64x2, allowing the input register |
| 1361 |
// to be targeted lowers register pressure if it's the last use of the |
| 1362 |
// input. |
| 1363 |
|
| 1364 |
if (ins->type() == MIRType::Int64) { |
| 1365 |
auto* lir = new (alloc()) |
| 1366 |
LWasmReduceSimd128ToInt64(useRegisterAtStart(ins->input())); |
| 1367 |
defineInt64(lir, ins); |
| 1368 |
} else { |
| 1369 |
LDefinition tempReg = LDefinition::BogusTemp(); |
| 1370 |
switch (ins->simdOp()) { |
| 1371 |
case wasm::SimdOp::I8x16Bitmask: |
| 1372 |
case wasm::SimdOp::I16x8Bitmask: |
| 1373 |
case wasm::SimdOp::I32x4Bitmask: |
| 1374 |
case wasm::SimdOp::I64x2Bitmask: |
| 1375 |
tempReg = tempSimd128(); |
| 1376 |
break; |
| 1377 |
default: |
| 1378 |
break; |
| 1379 |
} |
| 1380 |
|
| 1381 |
// Ideally we would reuse the input register for floating extract_lane if |
| 1382 |
// the lane is zero, but constraints in the register allocator require the |
| 1383 |
// input and output register types to be the same. |
| 1384 |
auto* lir = new (alloc()) |
| 1385 |
LWasmReduceSimd128(useRegisterAtStart(ins->input()), tempReg); |
| 1386 |
define(lir, ins); |
| 1387 |
} |
| 1388 |
#else |
| 1389 |
MOZ_CRASH("No SIMD"); |
| 1390 |
#endif |
| 1391 |
} |
| 1392 |
|
| 1393 |
void LIRGenerator::visitWasmLoadLaneSimd128(MWasmLoadLaneSimd128* ins) { |
| 1394 |
#ifdef ENABLE_WASM_SIMD |
| 1395 |
// On 64-bit systems, the base pointer can be 32 bits or 64 bits. Either way, |
| 1396 |
// it fits in a GPR so we can ignore the Register/Register64 distinction here. |
| 1397 |
|
| 1398 |
// Optimal allocation here reuses the value input for the output register |
| 1399 |
// because codegen otherwise has to copy the input to the output; this is |
| 1400 |
// because load-lane is implemented as load + replace-lane. Bug 1706106 may |
| 1401 |
// change all of that, so leave it alone for now. |
| 1402 |
LUse base = useRegisterAtStart(ins->base()); |
| 1403 |
LUse inputUse = useRegisterAtStart(ins->value()); |
| 1404 |
LAllocation memoryBase = |
| 1405 |
ins->hasMemoryBase() ? LAllocation(useRegisterAtStart(ins->memoryBase())) |
| 1406 |
: LGeneralReg(HeapReg); |
| 1407 |
auto* lir = |
| 1408 |
new (alloc()) LWasmLoadLaneSimd128(base, inputUse, memoryBase, temp()); |
| 1409 |
define(lir, ins); |
| 1410 |
#else |
| 1411 |
MOZ_CRASH("No SIMD"); |
| 1412 |
#endif |
| 1413 |
} |
| 1414 |
|
| 1415 |
void LIRGenerator::visitWasmStoreLaneSimd128(MWasmStoreLaneSimd128* ins) { |
| 1416 |
#ifdef ENABLE_WASM_SIMD |
| 1417 |
// See comment above about the base pointer. |
| 1418 |
|
| 1419 |
LUse base = useRegisterAtStart(ins->base()); |
| 1420 |
LUse input = useRegisterAtStart(ins->value()); |
| 1421 |
LAllocation memoryBase = |
| 1422 |
ins->hasMemoryBase() ? LAllocation(useRegisterAtStart(ins->memoryBase())) |
| 1423 |
: LGeneralReg(HeapReg); |
| 1424 |
auto* lir = |
| 1425 |
new (alloc()) LWasmStoreLaneSimd128(base, input, memoryBase, temp()); |
| 1426 |
add(lir, ins); |
| 1427 |
#else |
| 1428 |
MOZ_CRASH("No SIMD"); |
| 1429 |
#endif |
| 1430 |
} |