| 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/loong64/CodeGenerator-loong64.h" |
| 8 |
|
| 9 |
#include "mozilla/MathAlgorithms.h" |
| 10 |
|
| 11 |
#include "jsnum.h" |
| 12 |
|
| 13 |
#include "jit/CodeGenerator.h" |
| 14 |
#include "jit/InlineScriptTree.h" |
| 15 |
#include "jit/JitRuntime.h" |
| 16 |
#include "jit/MIR-wasm.h" |
| 17 |
#include "jit/MIR.h" |
| 18 |
#include "jit/MIRGraph.h" |
| 19 |
#include "vm/JSContext.h" |
| 20 |
#include "vm/Realm.h" |
| 21 |
#include "vm/Shape.h" |
| 22 |
|
| 23 |
#include "jit/shared/CodeGenerator-shared-inl.h" |
| 24 |
#include "vm/JSScript-inl.h" |
| 25 |
|
| 26 |
using namespace js; |
| 27 |
using namespace js::jit; |
| 28 |
|
| 29 |
using JS::GenericNaN; |
| 30 |
using mozilla::FloorLog2; |
| 31 |
using mozilla::NegativeInfinity; |
| 32 |
|
| 33 |
// shared |
| 34 |
CodeGeneratorLOONG64::CodeGeneratorLOONG64( |
| 35 |
MIRGenerator* gen, LIRGraph* graph, MacroAssembler* masm, |
| 36 |
const wasm::CodeMetadata* wasmCodeMeta) |
| 37 |
: CodeGeneratorShared(gen, graph, masm, wasmCodeMeta) {} |
| 38 |
|
| 39 |
Operand CodeGeneratorLOONG64::ToOperand(const LAllocation& a) { |
| 40 |
if (a.isGeneralReg()) { |
| 41 |
return Operand(a.toGeneralReg()->reg()); |
| 42 |
} |
| 43 |
if (a.isFloatReg()) { |
| 44 |
return Operand(a.toFloatReg()->reg()); |
| 45 |
} |
| 46 |
return Operand(ToAddress(a)); |
| 47 |
} |
| 48 |
|
| 49 |
Operand CodeGeneratorLOONG64::ToOperand(const LAllocation* a) { |
| 50 |
return ToOperand(*a); |
| 51 |
} |
| 52 |
|
| 53 |
Operand CodeGeneratorLOONG64::ToOperand(const LDefinition* def) { |
| 54 |
return ToOperand(def->output()); |
| 55 |
} |
| 56 |
|
| 57 |
#ifdef JS_PUNBOX64 |
| 58 |
Operand CodeGeneratorLOONG64::ToOperandOrRegister64( |
| 59 |
const LInt64Allocation& input) { |
| 60 |
return ToOperand(input.value()); |
| 61 |
} |
| 62 |
#else |
| 63 |
Register64 CodeGeneratorLOONG64::ToOperandOrRegister64( |
| 64 |
const LInt64Allocation& input) { |
| 65 |
return ToRegister64(input); |
| 66 |
} |
| 67 |
#endif |
| 68 |
|
| 69 |
void CodeGeneratorLOONG64::branchToBlock(Assembler::FloatFormat fmt, |
| 70 |
FloatRegister lhs, FloatRegister rhs, |
| 71 |
MBasicBlock* mir, |
| 72 |
Assembler::DoubleCondition cond) { |
| 73 |
// Skip past trivial blocks. |
| 74 |
Label* label = skipTrivialBlocks(mir)->lir()->label(); |
| 75 |
if (fmt == Assembler::DoubleFloat) { |
| 76 |
masm.branchDouble(cond, lhs, rhs, label); |
| 77 |
} else { |
| 78 |
masm.branchFloat(cond, lhs, rhs, label); |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
MoveOperand CodeGeneratorLOONG64::toMoveOperand(LAllocation a) const { |
| 83 |
if (a.isGeneralReg()) { |
| 84 |
return MoveOperand(ToRegister(a)); |
| 85 |
} |
| 86 |
if (a.isFloatReg()) { |
| 87 |
return MoveOperand(ToFloatRegister(a)); |
| 88 |
} |
| 89 |
MoveOperand::Kind kind = a.isStackArea() ? MoveOperand::Kind::EffectiveAddress |
| 90 |
: MoveOperand::Kind::Memory; |
| 91 |
Address address = ToAddress(a); |
| 92 |
MOZ_ASSERT((address.offset & 3) == 0); |
| 93 |
|
| 94 |
return MoveOperand(address, kind); |
| 95 |
} |
| 96 |
|
| 97 |
void CodeGeneratorLOONG64::bailoutFrom(Label* label, LSnapshot* snapshot) { |
| 98 |
MOZ_ASSERT_IF(!masm.oom(), label->used()); |
| 99 |
MOZ_ASSERT_IF(!masm.oom(), !label->bound()); |
| 100 |
|
| 101 |
encode(snapshot); |
| 102 |
|
| 103 |
InlineScriptTree* tree = snapshot->mir()->block()->trackedTree(); |
| 104 |
auto* ool = new (alloc()) LambdaOutOfLineCode([=](OutOfLineCode& ool) { |
| 105 |
// Push snapshotOffset and make sure stack is aligned. |
| 106 |
masm.subPtr(Imm32(sizeof(Value)), StackPointer); |
| 107 |
masm.storePtr(ImmWord(snapshot->snapshotOffset()), |
| 108 |
Address(StackPointer, 0)); |
| 109 |
|
| 110 |
masm.jump(&deoptLabel_); |
| 111 |
}); |
| 112 |
addOutOfLineCode(ool, |
| 113 |
new (alloc()) BytecodeSite(tree, tree->script()->code())); |
| 114 |
|
| 115 |
masm.retarget(label, ool->entry()); |
| 116 |
} |
| 117 |
|
| 118 |
void CodeGeneratorLOONG64::bailout(LSnapshot* snapshot) { |
| 119 |
Label label; |
| 120 |
masm.jump(&label); |
| 121 |
bailoutFrom(&label, snapshot); |
| 122 |
} |
| 123 |
|
| 124 |
bool CodeGeneratorLOONG64::generateOutOfLineCode() { |
| 125 |
if (!CodeGeneratorShared::generateOutOfLineCode()) { |
| 126 |
return false; |
| 127 |
} |
| 128 |
|
| 129 |
if (deoptLabel_.used()) { |
| 130 |
// All non-table-based bailouts will go here. |
| 131 |
masm.bind(&deoptLabel_); |
| 132 |
|
| 133 |
// Push the frame size, so the handler can recover the IonScript. |
| 134 |
// Frame size is stored in 'ra' and pushed by GenerateBailoutThunk |
| 135 |
// We have to use 'ra' because generateBailoutTable will implicitly do |
| 136 |
// the same. |
| 137 |
masm.move32(Imm32(frameSize()), ra); |
| 138 |
|
| 139 |
TrampolinePtr handler = gen->jitRuntime()->getGenericBailoutHandler(); |
| 140 |
masm.jump(handler); |
| 141 |
} |
| 142 |
|
| 143 |
return !masm.oom(); |
| 144 |
} |
| 145 |
|
| 146 |
class js::jit::OutOfLineTableSwitch |
| 147 |
: public OutOfLineCodeBase<CodeGeneratorLOONG64> { |
| 148 |
MTableSwitch* mir_; |
| 149 |
CodeLabel jumpLabel_; |
| 150 |
|
| 151 |
void accept(CodeGeneratorLOONG64* codegen) { |
| 152 |
codegen->visitOutOfLineTableSwitch(this); |
| 153 |
} |
| 154 |
|
| 155 |
public: |
| 156 |
OutOfLineTableSwitch(MTableSwitch* mir) : mir_(mir) {} |
| 157 |
|
| 158 |
MTableSwitch* mir() const { return mir_; } |
| 159 |
|
| 160 |
CodeLabel* jumpLabel() { return &jumpLabel_; } |
| 161 |
}; |
| 162 |
|
| 163 |
void CodeGeneratorLOONG64::emitTableSwitchDispatch(MTableSwitch* mir, |
| 164 |
Register index, |
| 165 |
Register base) { |
| 166 |
Label* defaultcase = skipTrivialBlocks(mir->getDefault())->lir()->label(); |
| 167 |
|
| 168 |
// Lower value with low value |
| 169 |
if (mir->low() != 0) { |
| 170 |
masm.subPtr(Imm32(mir->low()), index); |
| 171 |
} |
| 172 |
|
| 173 |
// Jump to default case if input is out of range |
| 174 |
int32_t cases = mir->numCases(); |
| 175 |
masm.branchPtr(Assembler::AboveOrEqual, index, ImmWord(cases), defaultcase); |
| 176 |
|
| 177 |
// To fill in the CodeLabels for the case entries, we need to first |
| 178 |
// generate the case entries (we don't yet know their offsets in the |
| 179 |
// instruction stream). |
| 180 |
OutOfLineTableSwitch* ool = new (alloc()) OutOfLineTableSwitch(mir); |
| 181 |
addOutOfLineCode(ool, mir); |
| 182 |
|
| 183 |
// Compute the position where a pointer to the right case stands. |
| 184 |
masm.ma_li(base, ool->jumpLabel()); |
| 185 |
|
| 186 |
BaseIndex pointer(base, index, ScalePointer); |
| 187 |
|
| 188 |
// Jump to the right case |
| 189 |
masm.branchToComputedAddress(pointer); |
| 190 |
} |
| 191 |
|
| 192 |
template <typename T> |
| 193 |
void CodeGeneratorLOONG64::emitWasmLoad(T* lir) { |
| 194 |
const MWasmLoad* mir = lir->mir(); |
| 195 |
SecondScratchRegisterScope scratch2(masm); |
| 196 |
|
| 197 |
Register memoryBase = ToRegister(lir->memoryBase()); |
| 198 |
Register ptr = ToRegister(lir->ptr()); |
| 199 |
Register ptrScratch = ToTempRegisterOrInvalid(lir->temp0()); |
| 200 |
|
| 201 |
if (mir->base()->type() == MIRType::Int32) { |
| 202 |
masm.move32To64ZeroExtend(ptr, Register64(scratch2)); |
| 203 |
ptr = scratch2; |
| 204 |
ptrScratch = ptrScratch != InvalidReg ? scratch2 : InvalidReg; |
| 205 |
} |
| 206 |
|
| 207 |
// ptr is a GPR and is either a 32-bit value zero-extended to 64-bit, or a |
| 208 |
// true 64-bit value. |
| 209 |
masm.wasmLoad(mir->access(), memoryBase, ptr, ptrScratch, |
| 210 |
ToAnyRegister(lir->output())); |
| 211 |
} |
| 212 |
|
| 213 |
template <typename T> |
| 214 |
void CodeGeneratorLOONG64::emitWasmStore(T* lir) { |
| 215 |
const MWasmStore* mir = lir->mir(); |
| 216 |
SecondScratchRegisterScope scratch2(masm); |
| 217 |
|
| 218 |
Register memoryBase = ToRegister(lir->memoryBase()); |
| 219 |
Register ptr = ToRegister(lir->ptr()); |
| 220 |
Register ptrScratch = ToTempRegisterOrInvalid(lir->temp0()); |
| 221 |
|
| 222 |
if (mir->base()->type() == MIRType::Int32) { |
| 223 |
masm.move32To64ZeroExtend(ptr, Register64(scratch2)); |
| 224 |
ptr = scratch2; |
| 225 |
ptrScratch = ptrScratch != InvalidReg ? scratch2 : InvalidReg; |
| 226 |
} |
| 227 |
|
| 228 |
// ptr is a GPR and is either a 32-bit value zero-extended to 64-bit, or a |
| 229 |
// true 64-bit value. |
| 230 |
masm.wasmStore(mir->access(), ToAnyRegister(lir->value()), memoryBase, ptr, |
| 231 |
ptrScratch); |
| 232 |
} |
| 233 |
|
| 234 |
void CodeGeneratorLOONG64::generateInvalidateEpilogue() { |
| 235 |
// Ensure that there is enough space in the buffer for the OsiPoint |
| 236 |
// patching to occur. Otherwise, we could overwrite the invalidation |
| 237 |
// epilogue |
| 238 |
for (size_t i = 0; i < sizeof(void*); i += Assembler::NopSize()) { |
| 239 |
masm.nop(); |
| 240 |
} |
| 241 |
|
| 242 |
masm.bind(&invalidate_); |
| 243 |
|
| 244 |
// Push the return address of the point that we bailed out at to the stack |
| 245 |
masm.Push(ra); |
| 246 |
|
| 247 |
// Push the Ion script onto the stack (when we determine what that |
| 248 |
// pointer is). |
| 249 |
invalidateEpilogueData_ = masm.pushWithPatch(ImmWord(uintptr_t(-1))); |
| 250 |
|
| 251 |
// Jump to the invalidator which will replace the current frame. |
| 252 |
TrampolinePtr thunk = gen->jitRuntime()->getInvalidationThunk(); |
| 253 |
|
| 254 |
masm.jump(thunk); |
| 255 |
} |
| 256 |
|
| 257 |
void CodeGeneratorLOONG64::visitOutOfLineTableSwitch( |
| 258 |
OutOfLineTableSwitch* ool) { |
| 259 |
MTableSwitch* mir = ool->mir(); |
| 260 |
|
| 261 |
masm.haltingAlign(sizeof(void*)); |
| 262 |
masm.bind(ool->jumpLabel()); |
| 263 |
masm.addCodeLabel(*ool->jumpLabel()); |
| 264 |
|
| 265 |
for (size_t i = 0; i < mir->numCases(); i++) { |
| 266 |
LBlock* caseblock = skipTrivialBlocks(mir->getCase(i))->lir(); |
| 267 |
Label* caseheader = caseblock->label(); |
| 268 |
uint32_t caseoffset = caseheader->offset(); |
| 269 |
|
| 270 |
// The entries of the jump table need to be absolute addresses and thus |
| 271 |
// must be patched after codegen is finished. |
| 272 |
CodeLabel cl; |
| 273 |
masm.writeCodePointer(&cl); |
| 274 |
cl.target()->bind(caseoffset); |
| 275 |
masm.addCodeLabel(cl); |
| 276 |
} |
| 277 |
} |
| 278 |
|
| 279 |
void CodeGeneratorLOONG64::visitOutOfLineWasmTruncateCheck( |
| 280 |
OutOfLineWasmTruncateCheck* ool) { |
| 281 |
if (ool->toType() == MIRType::Int32) { |
| 282 |
masm.outOfLineWasmTruncateToInt32Check(ool->input(), ool->output(), |
| 283 |
ool->fromType(), ool->flags(), |
| 284 |
ool->rejoin(), ool->trapSiteDesc()); |
| 285 |
} else { |
| 286 |
MOZ_ASSERT(ool->toType() == MIRType::Int64); |
| 287 |
masm.outOfLineWasmTruncateToInt64Check(ool->input(), ool->output64(), |
| 288 |
ool->fromType(), ool->flags(), |
| 289 |
ool->rejoin(), ool->trapSiteDesc()); |
| 290 |
} |
| 291 |
} |
| 292 |
|
| 293 |
void CodeGenerator::visitBox(LBox* box) { |
| 294 |
const LAllocation* in = box->payload(); |
| 295 |
ValueOperand result = ToOutValue(box); |
| 296 |
|
| 297 |
masm.moveValue(TypedOrValueRegister(box->type(), ToAnyRegister(in)), result); |
| 298 |
} |
| 299 |
|
| 300 |
void CodeGenerator::visitUnbox(LUnbox* unbox) { |
| 301 |
MUnbox* mir = unbox->mir(); |
| 302 |
|
| 303 |
Register result = ToRegister(unbox->output()); |
| 304 |
|
| 305 |
if (mir->fallible()) { |
| 306 |
ValueOperand value = ToValue(unbox->input()); |
| 307 |
Label bail; |
| 308 |
switch (mir->type()) { |
| 309 |
case MIRType::Int32: |
| 310 |
masm.fallibleUnboxInt32(value, result, &bail); |
| 311 |
break; |
| 312 |
case MIRType::Boolean: |
| 313 |
masm.fallibleUnboxBoolean(value, result, &bail); |
| 314 |
break; |
| 315 |
case MIRType::Object: |
| 316 |
masm.fallibleUnboxObject(value, result, &bail); |
| 317 |
break; |
| 318 |
case MIRType::String: |
| 319 |
masm.fallibleUnboxString(value, result, &bail); |
| 320 |
break; |
| 321 |
case MIRType::Symbol: |
| 322 |
masm.fallibleUnboxSymbol(value, result, &bail); |
| 323 |
break; |
| 324 |
case MIRType::BigInt: |
| 325 |
masm.fallibleUnboxBigInt(value, result, &bail); |
| 326 |
break; |
| 327 |
default: |
| 328 |
MOZ_CRASH("Given MIRType cannot be unboxed."); |
| 329 |
} |
| 330 |
bailoutFrom(&bail, unbox->snapshot()); |
| 331 |
return; |
| 332 |
} |
| 333 |
|
| 334 |
LAllocation* input = unbox->getOperand(LUnbox::Input); |
| 335 |
if (input->isGeneralReg()) { |
| 336 |
Register inputReg = ToRegister(input); |
| 337 |
switch (mir->type()) { |
| 338 |
case MIRType::Int32: |
| 339 |
masm.unboxInt32(inputReg, result); |
| 340 |
break; |
| 341 |
case MIRType::Boolean: |
| 342 |
masm.unboxBoolean(inputReg, result); |
| 343 |
break; |
| 344 |
case MIRType::Object: |
| 345 |
masm.unboxObject(inputReg, result); |
| 346 |
break; |
| 347 |
case MIRType::String: |
| 348 |
masm.unboxString(inputReg, result); |
| 349 |
break; |
| 350 |
case MIRType::Symbol: |
| 351 |
masm.unboxSymbol(inputReg, result); |
| 352 |
break; |
| 353 |
case MIRType::BigInt: |
| 354 |
masm.unboxBigInt(inputReg, result); |
| 355 |
break; |
| 356 |
default: |
| 357 |
MOZ_CRASH("Given MIRType cannot be unboxed."); |
| 358 |
} |
| 359 |
return; |
| 360 |
} |
| 361 |
|
| 362 |
Address inputAddr = ToAddress(input); |
| 363 |
switch (mir->type()) { |
| 364 |
case MIRType::Int32: |
| 365 |
masm.unboxInt32(inputAddr, result); |
| 366 |
break; |
| 367 |
case MIRType::Boolean: |
| 368 |
masm.unboxBoolean(inputAddr, result); |
| 369 |
break; |
| 370 |
case MIRType::Object: |
| 371 |
masm.unboxObject(inputAddr, result); |
| 372 |
break; |
| 373 |
case MIRType::String: |
| 374 |
masm.unboxString(inputAddr, result); |
| 375 |
break; |
| 376 |
case MIRType::Symbol: |
| 377 |
masm.unboxSymbol(inputAddr, result); |
| 378 |
break; |
| 379 |
case MIRType::BigInt: |
| 380 |
masm.unboxBigInt(inputAddr, result); |
| 381 |
break; |
| 382 |
default: |
| 383 |
MOZ_CRASH("Given MIRType cannot be unboxed."); |
| 384 |
} |
| 385 |
} |
| 386 |
|
| 387 |
void CodeGenerator::visitDivOrModI64(LDivOrModI64* lir) { |
| 388 |
Register lhs = ToRegister(lir->lhs()); |
| 389 |
Register rhs = ToRegister(lir->rhs()); |
| 390 |
Register output = ToRegister(lir->output()); |
| 391 |
|
| 392 |
Label done; |
| 393 |
|
| 394 |
// Handle divide by zero. |
| 395 |
if (lir->canBeDivideByZero()) { |
| 396 |
Label nonZero; |
| 397 |
masm.ma_b(rhs, rhs, &nonZero, Assembler::NonZero); |
| 398 |
masm.wasmTrap(wasm::Trap::IntegerDivideByZero, lir->trapSiteDesc()); |
| 399 |
masm.bind(&nonZero); |
| 400 |
} |
| 401 |
|
| 402 |
// Handle an integer overflow exception from INT64_MIN / -1. |
| 403 |
if (lir->canBeNegativeOverflow()) { |
| 404 |
Label notOverflow; |
| 405 |
masm.branchPtr(Assembler::NotEqual, lhs, ImmWord(INT64_MIN), ¬Overflow); |
| 406 |
masm.branchPtr(Assembler::NotEqual, rhs, ImmWord(-1), ¬Overflow); |
| 407 |
if (lir->mir()->isMod()) { |
| 408 |
masm.as_xor(output, output, output); |
| 409 |
} else { |
| 410 |
masm.wasmTrap(wasm::Trap::IntegerOverflow, lir->trapSiteDesc()); |
| 411 |
} |
| 412 |
masm.jump(&done); |
| 413 |
masm.bind(¬Overflow); |
| 414 |
} |
| 415 |
|
| 416 |
if (lir->mir()->isMod()) { |
| 417 |
masm.as_mod_d(output, lhs, rhs); |
| 418 |
} else { |
| 419 |
masm.as_div_d(output, lhs, rhs); |
| 420 |
} |
| 421 |
|
| 422 |
masm.bind(&done); |
| 423 |
} |
| 424 |
|
| 425 |
void CodeGenerator::visitUDivOrModI64(LUDivOrModI64* lir) { |
| 426 |
Register lhs = ToRegister(lir->lhs()); |
| 427 |
Register rhs = ToRegister(lir->rhs()); |
| 428 |
Register output = ToRegister(lir->output()); |
| 429 |
|
| 430 |
Label done; |
| 431 |
|
| 432 |
// Prevent divide by zero. |
| 433 |
if (lir->canBeDivideByZero()) { |
| 434 |
Label nonZero; |
| 435 |
masm.ma_b(rhs, rhs, &nonZero, Assembler::NonZero); |
| 436 |
masm.wasmTrap(wasm::Trap::IntegerDivideByZero, lir->trapSiteDesc()); |
| 437 |
masm.bind(&nonZero); |
| 438 |
} |
| 439 |
|
| 440 |
if (lir->mir()->isMod()) { |
| 441 |
masm.as_mod_du(output, lhs, rhs); |
| 442 |
} else { |
| 443 |
masm.as_div_du(output, lhs, rhs); |
| 444 |
} |
| 445 |
|
| 446 |
masm.bind(&done); |
| 447 |
} |
| 448 |
|
| 449 |
void CodeGeneratorLOONG64::emitBigIntPtrDiv(LBigIntPtrDiv* ins, |
| 450 |
Register dividend, Register divisor, |
| 451 |
Register output) { |
| 452 |
// Callers handle division by zero and integer overflow. |
| 453 |
masm.as_div_d(/* result= */ output, dividend, divisor); |
| 454 |
} |
| 455 |
|
| 456 |
void CodeGeneratorLOONG64::emitBigIntPtrMod(LBigIntPtrMod* ins, |
| 457 |
Register dividend, Register divisor, |
| 458 |
Register output) { |
| 459 |
// Callers handle division by zero and integer overflow. |
| 460 |
masm.as_mod_d(/* result= */ output, dividend, divisor); |
| 461 |
} |
| 462 |
|
| 463 |
void CodeGenerator::visitWasmLoadI64(LWasmLoadI64* lir) { |
| 464 |
const MWasmLoad* mir = lir->mir(); |
| 465 |
|
| 466 |
Register memoryBase = ToRegister(lir->memoryBase()); |
| 467 |
Register ptrScratch = ToTempRegisterOrInvalid(lir->temp0()); |
| 468 |
|
| 469 |
Register ptrReg = ToRegister(lir->ptr()); |
| 470 |
if (mir->base()->type() == MIRType::Int32) { |
| 471 |
// See comment in visitWasmLoad re the type of 'base'. |
| 472 |
masm.move32ZeroExtendToPtr(ptrReg, ptrReg); |
| 473 |
} |
| 474 |
|
| 475 |
masm.wasmLoadI64(mir->access(), memoryBase, ptrReg, ptrScratch, |
| 476 |
ToOutRegister64(lir)); |
| 477 |
} |
| 478 |
|
| 479 |
void CodeGenerator::visitWasmStoreI64(LWasmStoreI64* lir) { |
| 480 |
const MWasmStore* mir = lir->mir(); |
| 481 |
|
| 482 |
Register memoryBase = ToRegister(lir->memoryBase()); |
| 483 |
Register ptrScratch = ToTempRegisterOrInvalid(lir->temp0()); |
| 484 |
|
| 485 |
Register ptrReg = ToRegister(lir->ptr()); |
| 486 |
if (mir->base()->type() == MIRType::Int32) { |
| 487 |
// See comment in visitWasmLoad re the type of 'base'. |
| 488 |
masm.move32ZeroExtendToPtr(ptrReg, ptrReg); |
| 489 |
} |
| 490 |
|
| 491 |
masm.wasmStoreI64(mir->access(), ToRegister64(lir->value()), memoryBase, |
| 492 |
ptrReg, ptrScratch); |
| 493 |
} |
| 494 |
|
| 495 |
void CodeGenerator::visitWasmSelectI64(LWasmSelectI64* lir) { |
| 496 |
MOZ_ASSERT(lir->mir()->type() == MIRType::Int64); |
| 497 |
|
| 498 |
Register cond = ToRegister(lir->condExpr()); |
| 499 |
LInt64Allocation falseExpr = lir->falseExpr(); |
| 500 |
|
| 501 |
Register64 out = ToOutRegister64(lir); |
| 502 |
MOZ_ASSERT(ToRegister64(lir->trueExpr()) == out, |
| 503 |
"true expr is reused for input"); |
| 504 |
|
| 505 |
if (falseExpr.value().isGeneralReg()) { |
| 506 |
masm.moveIfZero(out.reg, ToRegister(falseExpr.value()), cond); |
| 507 |
} else { |
| 508 |
Label done; |
| 509 |
masm.ma_b(cond, cond, &done, Assembler::NonZero, ShortJump); |
| 510 |
masm.loadPtr(ToAddress(falseExpr.value()), out.reg); |
| 511 |
masm.bind(&done); |
| 512 |
} |
| 513 |
} |
| 514 |
|
| 515 |
void CodeGenerator::visitExtendInt32ToInt64(LExtendInt32ToInt64* lir) { |
| 516 |
const LAllocation* input = lir->input(); |
| 517 |
Register output = ToRegister(lir->output()); |
| 518 |
|
| 519 |
if (lir->mir()->isUnsigned()) { |
| 520 |
masm.as_bstrpick_d(output, ToRegister(input), 31, 0); |
| 521 |
} else { |
| 522 |
masm.as_slli_w(output, ToRegister(input), 0); |
| 523 |
} |
| 524 |
} |
| 525 |
|
| 526 |
void CodeGenerator::visitWrapInt64ToInt32(LWrapInt64ToInt32* lir) { |
| 527 |
LInt64Allocation input = lir->input(); |
| 528 |
Register output = ToRegister(lir->output()); |
| 529 |
|
| 530 |
if (lir->mir()->bottomHalf()) { |
| 531 |
if (input.value().isMemory()) { |
| 532 |
masm.load32(ToAddress(input), output); |
| 533 |
} else { |
| 534 |
masm.move64To32(ToRegister64(input), output); |
| 535 |
} |
| 536 |
} else { |
| 537 |
MOZ_CRASH("Not implemented."); |
| 538 |
} |
| 539 |
} |
| 540 |
|
| 541 |
void CodeGenerator::visitSignExtendInt64(LSignExtendInt64* lir) { |
| 542 |
Register64 input = ToRegister64(lir->input()); |
| 543 |
Register64 output = ToOutRegister64(lir); |
| 544 |
switch (lir->mir()->mode()) { |
| 545 |
case MSignExtendInt64::Byte: |
| 546 |
masm.move32To64SignExtend(input.reg, output); |
| 547 |
masm.move8SignExtend(output.reg, output.reg); |
| 548 |
break; |
| 549 |
case MSignExtendInt64::Half: |
| 550 |
masm.move32To64SignExtend(input.reg, output); |
| 551 |
masm.move16SignExtend(output.reg, output.reg); |
| 552 |
break; |
| 553 |
case MSignExtendInt64::Word: |
| 554 |
masm.move32To64SignExtend(input.reg, output); |
| 555 |
break; |
| 556 |
} |
| 557 |
} |
| 558 |
|
| 559 |
void CodeGenerator::visitWasmExtendU32Index(LWasmExtendU32Index* lir) { |
| 560 |
Register input = ToRegister(lir->input()); |
| 561 |
Register output = ToRegister(lir->output()); |
| 562 |
MOZ_ASSERT(input == output); |
| 563 |
masm.move32To64ZeroExtend(input, Register64(output)); |
| 564 |
} |
| 565 |
|
| 566 |
void CodeGenerator::visitWasmWrapU32Index(LWasmWrapU32Index* lir) { |
| 567 |
Register input = ToRegister(lir->input()); |
| 568 |
Register output = ToRegister(lir->output()); |
| 569 |
MOZ_ASSERT(input == output); |
| 570 |
masm.move64To32(Register64(input), output); |
| 571 |
} |
| 572 |
|
| 573 |
void CodeGenerator::visitWasmTruncateToInt64(LWasmTruncateToInt64* lir) { |
| 574 |
FloatRegister input = ToFloatRegister(lir->input()); |
| 575 |
Register64 output = ToOutRegister64(lir); |
| 576 |
|
| 577 |
MWasmTruncateToInt64* mir = lir->mir(); |
| 578 |
MIRType fromType = mir->input()->type(); |
| 579 |
|
| 580 |
MOZ_ASSERT(fromType == MIRType::Double || fromType == MIRType::Float32); |
| 581 |
|
| 582 |
auto* ool = new (alloc()) OutOfLineWasmTruncateCheck(mir, input, output); |
| 583 |
addOutOfLineCode(ool, mir); |
| 584 |
|
| 585 |
Label* oolEntry = ool->entry(); |
| 586 |
Label* oolRejoin = ool->rejoin(); |
| 587 |
bool isSaturating = mir->isSaturating(); |
| 588 |
|
| 589 |
if (fromType == MIRType::Double) { |
| 590 |
if (mir->isUnsigned()) { |
| 591 |
masm.wasmTruncateDoubleToUInt64(input, output, isSaturating, oolEntry, |
| 592 |
oolRejoin, InvalidFloatReg); |
| 593 |
} else { |
| 594 |
masm.wasmTruncateDoubleToInt64(input, output, isSaturating, oolEntry, |
| 595 |
oolRejoin, InvalidFloatReg); |
| 596 |
} |
| 597 |
} else { |
| 598 |
if (mir->isUnsigned()) { |
| 599 |
masm.wasmTruncateFloat32ToUInt64(input, output, isSaturating, oolEntry, |
| 600 |
oolRejoin, InvalidFloatReg); |
| 601 |
} else { |
| 602 |
masm.wasmTruncateFloat32ToInt64(input, output, isSaturating, oolEntry, |
| 603 |
oolRejoin, InvalidFloatReg); |
| 604 |
} |
| 605 |
} |
| 606 |
} |
| 607 |
|
| 608 |
void CodeGenerator::visitInt64ToFloatingPoint(LInt64ToFloatingPoint* lir) { |
| 609 |
Register64 input = ToRegister64(lir->input()); |
| 610 |
FloatRegister output = ToFloatRegister(lir->output()); |
| 611 |
|
| 612 |
MIRType outputType = lir->mir()->type(); |
| 613 |
MOZ_ASSERT(outputType == MIRType::Double || outputType == MIRType::Float32); |
| 614 |
|
| 615 |
if (outputType == MIRType::Double) { |
| 616 |
if (lir->mir()->isUnsigned()) { |
| 617 |
masm.convertUInt64ToDouble(input, output, Register::Invalid()); |
| 618 |
} else { |
| 619 |
masm.convertInt64ToDouble(input, output); |
| 620 |
} |
| 621 |
} else { |
| 622 |
if (lir->mir()->isUnsigned()) { |
| 623 |
masm.convertUInt64ToFloat32(input, output, Register::Invalid()); |
| 624 |
} else { |
| 625 |
masm.convertInt64ToFloat32(input, output); |
| 626 |
} |
| 627 |
} |
| 628 |
} |
| 629 |
|
| 630 |
void CodeGenerator::visitMinMaxD(LMinMaxD* ins) { |
| 631 |
FloatRegister first = ToFloatRegister(ins->first()); |
| 632 |
FloatRegister second = ToFloatRegister(ins->second()); |
| 633 |
|
| 634 |
MOZ_ASSERT(first == ToFloatRegister(ins->output())); |
| 635 |
|
| 636 |
if (ins->mir()->isMax()) { |
| 637 |
masm.maxDouble(second, first, true); |
| 638 |
} else { |
| 639 |
masm.minDouble(second, first, true); |
| 640 |
} |
| 641 |
} |
| 642 |
|
| 643 |
void CodeGenerator::visitMinMaxF(LMinMaxF* ins) { |
| 644 |
FloatRegister first = ToFloatRegister(ins->first()); |
| 645 |
FloatRegister second = ToFloatRegister(ins->second()); |
| 646 |
|
| 647 |
MOZ_ASSERT(first == ToFloatRegister(ins->output())); |
| 648 |
|
| 649 |
if (ins->mir()->isMax()) { |
| 650 |
masm.maxFloat32(second, first, true); |
| 651 |
} else { |
| 652 |
masm.minFloat32(second, first, true); |
| 653 |
} |
| 654 |
} |
| 655 |
|
| 656 |
void CodeGenerator::visitAddI(LAddI* ins) { |
| 657 |
const LAllocation* lhs = ins->lhs(); |
| 658 |
const LAllocation* rhs = ins->rhs(); |
| 659 |
const LDefinition* dest = ins->output(); |
| 660 |
|
| 661 |
MOZ_ASSERT(rhs->isConstant() || rhs->isGeneralReg()); |
| 662 |
|
| 663 |
// If there is no snapshot, we don't need to check for overflow |
| 664 |
if (!ins->snapshot()) { |
| 665 |
if (rhs->isConstant()) { |
| 666 |
masm.ma_add_w(ToRegister(dest), ToRegister(lhs), Imm32(ToInt32(rhs))); |
| 667 |
} else { |
| 668 |
masm.as_add_w(ToRegister(dest), ToRegister(lhs), ToRegister(rhs)); |
| 669 |
} |
| 670 |
return; |
| 671 |
} |
| 672 |
|
| 673 |
Label overflow; |
| 674 |
if (rhs->isConstant()) { |
| 675 |
masm.ma_add32TestOverflow(ToRegister(dest), ToRegister(lhs), |
| 676 |
Imm32(ToInt32(rhs)), &overflow); |
| 677 |
} else { |
| 678 |
masm.ma_add32TestOverflow(ToRegister(dest), ToRegister(lhs), |
| 679 |
ToRegister(rhs), &overflow); |
| 680 |
} |
| 681 |
|
| 682 |
bailoutFrom(&overflow, ins->snapshot()); |
| 683 |
} |
| 684 |
|
| 685 |
void CodeGenerator::visitAddI64(LAddI64* lir) { |
| 686 |
LInt64Allocation lhs = lir->lhs(); |
| 687 |
LInt64Allocation rhs = lir->rhs(); |
| 688 |
|
| 689 |
MOZ_ASSERT(ToOutRegister64(lir) == ToRegister64(lhs)); |
| 690 |
|
| 691 |
if (IsConstant(rhs)) { |
| 692 |
masm.add64(Imm64(ToInt64(rhs)), ToRegister64(lhs)); |
| 693 |
return; |
| 694 |
} |
| 695 |
|
| 696 |
masm.add64(ToOperandOrRegister64(rhs), ToRegister64(lhs)); |
| 697 |
} |
| 698 |
|
| 699 |
void CodeGenerator::visitSubI(LSubI* ins) { |
| 700 |
const LAllocation* lhs = ins->lhs(); |
| 701 |
const LAllocation* rhs = ins->rhs(); |
| 702 |
const LDefinition* dest = ins->output(); |
| 703 |
|
| 704 |
MOZ_ASSERT(rhs->isConstant() || rhs->isGeneralReg()); |
| 705 |
|
| 706 |
// If there is no snapshot, we don't need to check for overflow |
| 707 |
|
| 708 |
if (!ins->snapshot()) { |
| 709 |
if (rhs->isConstant()) { |
| 710 |
masm.ma_sub_w(ToRegister(dest), ToRegister(lhs), Imm32(ToInt32(rhs))); |
| 711 |
} else { |
| 712 |
masm.as_sub_w(ToRegister(dest), ToRegister(lhs), ToRegister(rhs)); |
| 713 |
} |
| 714 |
return; |
| 715 |
} |
| 716 |
|
| 717 |
Label overflow; |
| 718 |
if (rhs->isConstant()) { |
| 719 |
masm.ma_sub32TestOverflow(ToRegister(dest), ToRegister(lhs), |
| 720 |
Imm32(ToInt32(rhs)), &overflow); |
| 721 |
} else { |
| 722 |
masm.ma_sub32TestOverflow(ToRegister(dest), ToRegister(lhs), |
| 723 |
ToRegister(rhs), &overflow); |
| 724 |
} |
| 725 |
|
| 726 |
bailoutFrom(&overflow, ins->snapshot()); |
| 727 |
} |
| 728 |
|
| 729 |
void CodeGenerator::visitSubI64(LSubI64* lir) { |
| 730 |
LInt64Allocation lhs = lir->lhs(); |
| 731 |
LInt64Allocation rhs = lir->rhs(); |
| 732 |
|
| 733 |
MOZ_ASSERT(ToOutRegister64(lir) == ToRegister64(lhs)); |
| 734 |
|
| 735 |
if (IsConstant(rhs)) { |
| 736 |
masm.sub64(Imm64(ToInt64(rhs)), ToRegister64(lhs)); |
| 737 |
return; |
| 738 |
} |
| 739 |
|
| 740 |
masm.sub64(ToOperandOrRegister64(rhs), ToRegister64(lhs)); |
| 741 |
} |
| 742 |
|
| 743 |
void CodeGenerator::visitMulI(LMulI* ins) { |
| 744 |
const LAllocation* lhs = ins->lhs(); |
| 745 |
const LAllocation* rhs = ins->rhs(); |
| 746 |
Register dest = ToRegister(ins->output()); |
| 747 |
MMul* mul = ins->mir(); |
| 748 |
|
| 749 |
MOZ_ASSERT_IF(mul->mode() == MMul::Integer, |
| 750 |
!mul->canBeNegativeZero() && !mul->canOverflow()); |
| 751 |
|
| 752 |
if (rhs->isConstant()) { |
| 753 |
int32_t constant = ToInt32(rhs); |
| 754 |
Register src = ToRegister(lhs); |
| 755 |
|
| 756 |
// Bailout on -0.0 |
| 757 |
if (mul->canBeNegativeZero() && constant <= 0) { |
| 758 |
Assembler::Condition cond = |
| 759 |
(constant == 0) ? Assembler::LessThan : Assembler::Equal; |
| 760 |
bailoutCmp32(cond, src, Imm32(0), ins->snapshot()); |
| 761 |
} |
| 762 |
|
| 763 |
switch (constant) { |
| 764 |
case -1: |
| 765 |
if (mul->canOverflow()) { |
| 766 |
bailoutCmp32(Assembler::Equal, src, Imm32(INT32_MIN), |
| 767 |
ins->snapshot()); |
| 768 |
} |
| 769 |
|
| 770 |
masm.as_sub_w(dest, zero, src); |
| 771 |
break; |
| 772 |
case 0: |
| 773 |
masm.move32(zero, dest); |
| 774 |
break; |
| 775 |
case 1: |
| 776 |
masm.move32(src, dest); |
| 777 |
break; |
| 778 |
case 2: |
| 779 |
if (mul->canOverflow()) { |
| 780 |
Label mulTwoOverflow; |
| 781 |
masm.ma_add32TestOverflow(dest, src, src, &mulTwoOverflow); |
| 782 |
|
| 783 |
bailoutFrom(&mulTwoOverflow, ins->snapshot()); |
| 784 |
} else { |
| 785 |
masm.as_add_w(dest, src, src); |
| 786 |
} |
| 787 |
break; |
| 788 |
default: |
| 789 |
uint32_t shift = FloorLog2(constant); |
| 790 |
|
| 791 |
if (!mul->canOverflow() && (constant > 0)) { |
| 792 |
// If it cannot overflow, we can do lots of optimizations. |
| 793 |
uint32_t rest = constant - (1 << shift); |
| 794 |
|
| 795 |
// See if the constant has one bit set, meaning it can be |
| 796 |
// encoded as a bitshift. |
| 797 |
if ((1 << shift) == constant) { |
| 798 |
masm.as_slli_w(dest, src, shift % 32); |
| 799 |
return; |
| 800 |
} |
| 801 |
|
| 802 |
// If the constant cannot be encoded as (1<<C1), see if it can |
| 803 |
// be encoded as (1<<C1) | (1<<C2), which can be computed |
| 804 |
// using an add and a shift. |
| 805 |
uint32_t shift_rest = FloorLog2(rest); |
| 806 |
if (src != dest && (1u << shift_rest) == rest) { |
| 807 |
masm.as_slli_w(dest, src, (shift - shift_rest) % 32); |
| 808 |
masm.add32(src, dest); |
| 809 |
if (shift_rest != 0) { |
| 810 |
masm.as_slli_w(dest, dest, shift_rest % 32); |
| 811 |
} |
| 812 |
return; |
| 813 |
} |
| 814 |
} |
| 815 |
|
| 816 |
if (mul->canOverflow() && (constant > 0) && (src != dest)) { |
| 817 |
// To stay on the safe side, only optimize things that are a |
| 818 |
// power of 2. |
| 819 |
|
| 820 |
if ((1 << shift) == constant) { |
| 821 |
ScratchRegisterScope scratch(masm); |
| 822 |
// dest = lhs * pow(2, shift) |
| 823 |
masm.as_slli_w(dest, src, shift % 32); |
| 824 |
// At runtime, check (lhs == dest >> shift), if this does |
| 825 |
// not hold, some bits were lost due to overflow, and the |
| 826 |
// computation should be resumed as a double. |
| 827 |
masm.as_srai_w(scratch, dest, shift % 32); |
| 828 |
bailoutCmp32(Assembler::NotEqual, src, Register(scratch), |
| 829 |
ins->snapshot()); |
| 830 |
return; |
| 831 |
} |
| 832 |
} |
| 833 |
|
| 834 |
if (mul->canOverflow()) { |
| 835 |
Label mulConstOverflow; |
| 836 |
masm.ma_mul32TestOverflow(dest, ToRegister(lhs), Imm32(ToInt32(rhs)), |
| 837 |
&mulConstOverflow); |
| 838 |
|
| 839 |
bailoutFrom(&mulConstOverflow, ins->snapshot()); |
| 840 |
} else { |
| 841 |
masm.ma_mul(dest, src, Imm32(ToInt32(rhs))); |
| 842 |
} |
| 843 |
break; |
| 844 |
} |
| 845 |
} else { |
| 846 |
Label multRegOverflow; |
| 847 |
|
| 848 |
if (mul->canOverflow()) { |
| 849 |
masm.ma_mul32TestOverflow(dest, ToRegister(lhs), ToRegister(rhs), |
| 850 |
&multRegOverflow); |
| 851 |
bailoutFrom(&multRegOverflow, ins->snapshot()); |
| 852 |
} else { |
| 853 |
masm.as_mul_w(dest, ToRegister(lhs), ToRegister(rhs)); |
| 854 |
} |
| 855 |
|
| 856 |
if (mul->canBeNegativeZero()) { |
| 857 |
Label done; |
| 858 |
masm.ma_b(dest, dest, &done, Assembler::NonZero, ShortJump); |
| 859 |
|
| 860 |
// Result is -0 if lhs or rhs is negative. |
| 861 |
// In that case result must be double value so bailout |
| 862 |
Register scratch = SecondScratchReg; |
| 863 |
masm.as_or(scratch, ToRegister(lhs), ToRegister(rhs)); |
| 864 |
bailoutCmp32(Assembler::Signed, scratch, scratch, ins->snapshot()); |
| 865 |
|
| 866 |
masm.bind(&done); |
| 867 |
} |
| 868 |
} |
| 869 |
} |
| 870 |
|
| 871 |
void CodeGenerator::visitMulI64(LMulI64* lir) { |
| 872 |
LInt64Allocation lhs = lir->lhs(); |
| 873 |
LInt64Allocation rhs = lir->rhs(); |
| 874 |
Register64 output = ToOutRegister64(lir); |
| 875 |
MOZ_ASSERT(ToRegister64(lhs) == output); |
| 876 |
|
| 877 |
if (IsConstant(rhs)) { |
| 878 |
int64_t constant = ToInt64(rhs); |
| 879 |
switch (constant) { |
| 880 |
case -1: |
| 881 |
masm.neg64(ToRegister64(lhs)); |
| 882 |
return; |
| 883 |
case 0: |
| 884 |
masm.xor64(ToRegister64(lhs), ToRegister64(lhs)); |
| 885 |
return; |
| 886 |
case 1: |
| 887 |
// nop |
| 888 |
return; |
| 889 |
case 2: |
| 890 |
masm.as_add_d(output.reg, ToRegister64(lhs).reg, ToRegister64(lhs).reg); |
| 891 |
return; |
| 892 |
default: |
| 893 |
if (constant > 0) { |
| 894 |
if (mozilla::IsPowerOfTwo(static_cast<uint64_t>(constant + 1))) { |
| 895 |
ScratchRegisterScope scratch(masm); |
| 896 |
masm.movePtr(ToRegister64(lhs).reg, scratch); |
| 897 |
masm.as_slli_d(output.reg, ToRegister64(lhs).reg, |
| 898 |
FloorLog2(constant + 1)); |
| 899 |
masm.sub64(scratch, output); |
| 900 |
return; |
| 901 |
} else if (mozilla::IsPowerOfTwo( |
| 902 |
static_cast<uint64_t>(constant - 1))) { |
| 903 |
int32_t shift = mozilla::FloorLog2(constant - 1); |
| 904 |
if (shift < 5) { |
| 905 |
masm.as_alsl_d(output.reg, ToRegister64(lhs).reg, |
| 906 |
ToRegister64(lhs).reg, shift - 1); |
| 907 |
} else { |
| 908 |
ScratchRegisterScope scratch(masm); |
| 909 |
masm.movePtr(ToRegister64(lhs).reg, scratch); |
| 910 |
masm.as_slli_d(output.reg, ToRegister64(lhs).reg, shift); |
| 911 |
masm.add64(scratch, output); |
| 912 |
} |
| 913 |
return; |
| 914 |
} |
| 915 |
// Use shift if constant is power of 2. |
| 916 |
int32_t shift = mozilla::FloorLog2(constant); |
| 917 |
if (int64_t(1) << shift == constant) { |
| 918 |
masm.lshift64(Imm32(shift), ToRegister64(lhs)); |
| 919 |
return; |
| 920 |
} |
| 921 |
} |
| 922 |
Register temp = ToTempRegisterOrInvalid(lir->temp0()); |
| 923 |
masm.mul64(Imm64(constant), ToRegister64(lhs), temp); |
| 924 |
} |
| 925 |
} else { |
| 926 |
Register temp = ToTempRegisterOrInvalid(lir->temp0()); |
| 927 |
masm.mul64(ToOperandOrRegister64(rhs), ToRegister64(lhs), temp); |
| 928 |
} |
| 929 |
} |
| 930 |
|
| 931 |
void CodeGenerator::visitDivI(LDivI* ins) { |
| 932 |
// Extract the registers from this instruction |
| 933 |
Register lhs = ToRegister(ins->lhs()); |
| 934 |
Register rhs = ToRegister(ins->rhs()); |
| 935 |
Register dest = ToRegister(ins->output()); |
| 936 |
Register temp = ToRegister(ins->temp0()); |
| 937 |
MDiv* mir = ins->mir(); |
| 938 |
|
| 939 |
Label done; |
| 940 |
|
| 941 |
// Handle divide by zero. |
| 942 |
if (mir->canBeDivideByZero()) { |
| 943 |
if (mir->trapOnError()) { |
| 944 |
Label nonZero; |
| 945 |
masm.ma_b(rhs, rhs, &nonZero, Assembler::NonZero); |
| 946 |
masm.wasmTrap(wasm::Trap::IntegerDivideByZero, mir->trapSiteDesc()); |
| 947 |
masm.bind(&nonZero); |
| 948 |
} else if (mir->canTruncateInfinities()) { |
| 949 |
// Truncated division by zero is zero (Infinity|0 == 0) |
| 950 |
Label notzero; |
| 951 |
masm.ma_b(rhs, rhs, ¬zero, Assembler::NonZero, ShortJump); |
| 952 |
masm.move32(Imm32(0), dest); |
| 953 |
masm.ma_b(&done, ShortJump); |
| 954 |
masm.bind(¬zero); |
| 955 |
} else { |
| 956 |
MOZ_ASSERT(mir->fallible()); |
| 957 |
bailoutCmp32(Assembler::Zero, rhs, rhs, ins->snapshot()); |
| 958 |
} |
| 959 |
} |
| 960 |
|
| 961 |
// Handle an integer overflow exception from -2147483648 / -1. |
| 962 |
if (mir->canBeNegativeOverflow()) { |
| 963 |
Label notMinInt; |
| 964 |
masm.move32(Imm32(INT32_MIN), temp); |
| 965 |
masm.ma_b(lhs, temp, ¬MinInt, Assembler::NotEqual, ShortJump); |
| 966 |
|
| 967 |
masm.move32(Imm32(-1), temp); |
| 968 |
if (mir->trapOnError()) { |
| 969 |
Label ok; |
| 970 |
masm.ma_b(rhs, temp, &ok, Assembler::NotEqual); |
| 971 |
masm.wasmTrap(wasm::Trap::IntegerOverflow, mir->trapSiteDesc()); |
| 972 |
masm.bind(&ok); |
| 973 |
} else if (mir->canTruncateOverflow()) { |
| 974 |
// (-INT32_MIN)|0 == INT32_MIN |
| 975 |
Label skip; |
| 976 |
masm.ma_b(rhs, temp, &skip, Assembler::NotEqual, ShortJump); |
| 977 |
masm.move32(Imm32(INT32_MIN), dest); |
| 978 |
masm.ma_b(&done, ShortJump); |
| 979 |
masm.bind(&skip); |
| 980 |
} else { |
| 981 |
MOZ_ASSERT(mir->fallible()); |
| 982 |
bailoutCmp32(Assembler::Equal, rhs, temp, ins->snapshot()); |
| 983 |
} |
| 984 |
masm.bind(¬MinInt); |
| 985 |
} |
| 986 |
|
| 987 |
// Handle negative 0. (0/-Y) |
| 988 |
if (!mir->canTruncateNegativeZero() && mir->canBeNegativeZero()) { |
| 989 |
Label nonzero; |
| 990 |
masm.ma_b(lhs, lhs, &nonzero, Assembler::NonZero, ShortJump); |
| 991 |
bailoutCmp32(Assembler::LessThan, rhs, Imm32(0), ins->snapshot()); |
| 992 |
masm.bind(&nonzero); |
| 993 |
} |
| 994 |
// Note: above safety checks could not be verified as Ion seems to be |
| 995 |
// smarter and requires double arithmetic in such cases. |
| 996 |
|
| 997 |
// All regular. Lets call div. |
| 998 |
if (mir->canTruncateRemainder()) { |
| 999 |
masm.as_div_w(dest, lhs, rhs); |
| 1000 |
} else { |
| 1001 |
MOZ_ASSERT(mir->fallible()); |
| 1002 |
|
| 1003 |
Label remainderNonZero; |
| 1004 |
masm.ma_div_branch_overflow(dest, lhs, rhs, &remainderNonZero); |
| 1005 |
bailoutFrom(&remainderNonZero, ins->snapshot()); |
| 1006 |
} |
| 1007 |
|
| 1008 |
masm.bind(&done); |
| 1009 |
} |
| 1010 |
|
| 1011 |
void CodeGenerator::visitDivPowTwoI(LDivPowTwoI* ins) { |
| 1012 |
Register lhs = ToRegister(ins->numerator()); |
| 1013 |
Register dest = ToRegister(ins->output()); |
| 1014 |
Register tmp = ToRegister(ins->temp0()); |
| 1015 |
int32_t shift = ins->shift(); |
| 1016 |
|
| 1017 |
if (shift != 0) { |
| 1018 |
MDiv* mir = ins->mir(); |
| 1019 |
if (!mir->isTruncated()) { |
| 1020 |
// If the remainder is going to be != 0, bailout since this must |
| 1021 |
// be a double. |
| 1022 |
masm.as_slli_w(tmp, lhs, (32 - shift) % 32); |
| 1023 |
bailoutCmp32(Assembler::NonZero, tmp, tmp, ins->snapshot()); |
| 1024 |
} |
| 1025 |
|
| 1026 |
if (!mir->canBeNegativeDividend()) { |
| 1027 |
// Numerator is unsigned, so needs no adjusting. Do the shift. |
| 1028 |
masm.as_srai_w(dest, lhs, shift % 32); |
| 1029 |
return; |
| 1030 |
} |
| 1031 |
|
| 1032 |
// Adjust the value so that shifting produces a correctly rounded result |
| 1033 |
// when the numerator is negative. See 10-1 "Signed Division by a Known |
| 1034 |
// Power of 2" in Henry S. Warren, Jr.'s Hacker's Delight. |
| 1035 |
if (shift > 1) { |
| 1036 |
masm.as_srai_w(tmp, lhs, 31); |
| 1037 |
masm.as_srli_w(tmp, tmp, (32 - shift) % 32); |
| 1038 |
masm.add32(lhs, tmp); |
| 1039 |
} else { |
| 1040 |
masm.as_srli_w(tmp, lhs, (32 - shift) % 32); |
| 1041 |
masm.add32(lhs, tmp); |
| 1042 |
} |
| 1043 |
|
| 1044 |
// Do the shift. |
| 1045 |
masm.as_srai_w(dest, tmp, shift % 32); |
| 1046 |
} else { |
| 1047 |
masm.move32(lhs, dest); |
| 1048 |
} |
| 1049 |
} |
| 1050 |
|
| 1051 |
void CodeGenerator::visitModI(LModI* ins) { |
| 1052 |
// Extract the registers from this instruction |
| 1053 |
Register lhs = ToRegister(ins->lhs()); |
| 1054 |
Register rhs = ToRegister(ins->rhs()); |
| 1055 |
Register dest = ToRegister(ins->output()); |
| 1056 |
MOZ_ASSERT(rhs != dest && lhs != dest); |
| 1057 |
MMod* mir = ins->mir(); |
| 1058 |
Label done; |
| 1059 |
|
| 1060 |
// Prevent divide by zero. |
| 1061 |
if (mir->canBeDivideByZero()) { |
| 1062 |
if (mir->isTruncated()) { |
| 1063 |
if (mir->trapOnError()) { |
| 1064 |
Label nonZero; |
| 1065 |
masm.ma_b(rhs, rhs, &nonZero, Assembler::NonZero, ShortJump); |
| 1066 |
masm.wasmTrap(wasm::Trap::IntegerDivideByZero, mir->trapSiteDesc()); |
| 1067 |
masm.bind(&nonZero); |
| 1068 |
} else { |
| 1069 |
// Truncated division by zero yields integer zero. |
| 1070 |
masm.move32(rhs, dest); |
| 1071 |
masm.ma_b(rhs, rhs, &done, Assembler::Zero, ShortJump); |
| 1072 |
} |
| 1073 |
} else { |
| 1074 |
MOZ_ASSERT(mir->fallible()); |
| 1075 |
bailoutCmp32(Assembler::Equal, rhs, Imm32(0), ins->snapshot()); |
| 1076 |
} |
| 1077 |
} |
| 1078 |
|
| 1079 |
masm.as_mod_w(dest, lhs, rhs); |
| 1080 |
|
| 1081 |
// If X%Y == 0 and X < 0, then we *actually* wanted to return -0.0 |
| 1082 |
if (mir->canBeNegativeDividend() && !mir->isTruncated()) { |
| 1083 |
MOZ_ASSERT(mir->fallible()); |
| 1084 |
masm.ma_b(dest, Imm32(0), &done, Assembler::NotEqual, ShortJump); |
| 1085 |
bailoutCmp32(Assembler::Signed, lhs, Imm32(0), ins->snapshot()); |
| 1086 |
} |
| 1087 |
masm.bind(&done); |
| 1088 |
} |
| 1089 |
|
| 1090 |
void CodeGenerator::visitModPowTwoI(LModPowTwoI* ins) { |
| 1091 |
Register in = ToRegister(ins->input()); |
| 1092 |
Register out = ToRegister(ins->output()); |
| 1093 |
MMod* mir = ins->mir(); |
| 1094 |
Label negative, done; |
| 1095 |
|
| 1096 |
masm.move32(in, out); |
| 1097 |
masm.ma_b(in, in, &done, Assembler::Zero, ShortJump); |
| 1098 |
// Switch based on sign of the lhs. |
| 1099 |
// Positive numbers are just a bitmask |
| 1100 |
masm.ma_b(in, in, &negative, Assembler::Signed, ShortJump); |
| 1101 |
{ |
| 1102 |
masm.and32(Imm32((1 << ins->shift()) - 1), out); |
| 1103 |
masm.ma_b(&done, ShortJump); |
| 1104 |
} |
| 1105 |
|
| 1106 |
// Negative numbers need a negate, bitmask, negate |
| 1107 |
{ |
| 1108 |
masm.bind(&negative); |
| 1109 |
masm.neg32(out); |
| 1110 |
masm.and32(Imm32((1 << ins->shift()) - 1), out); |
| 1111 |
masm.neg32(out); |
| 1112 |
} |
| 1113 |
if (mir->canBeNegativeDividend()) { |
| 1114 |
if (!mir->isTruncated()) { |
| 1115 |
MOZ_ASSERT(mir->fallible()); |
| 1116 |
bailoutCmp32(Assembler::Equal, out, zero, ins->snapshot()); |
| 1117 |
} else { |
| 1118 |
// -0|0 == 0 |
| 1119 |
} |
| 1120 |
} |
| 1121 |
masm.bind(&done); |
| 1122 |
} |
| 1123 |
|
| 1124 |
void CodeGenerator::visitModMaskI(LModMaskI* ins) { |
| 1125 |
Register src = ToRegister(ins->input()); |
| 1126 |
Register dest = ToRegister(ins->output()); |
| 1127 |
Register tmp0 = ToRegister(ins->temp0()); |
| 1128 |
Register tmp1 = ToRegister(ins->temp1()); |
| 1129 |
MMod* mir = ins->mir(); |
| 1130 |
|
| 1131 |
if (!mir->isTruncated() && mir->canBeNegativeDividend()) { |
| 1132 |
MOZ_ASSERT(mir->fallible()); |
| 1133 |
|
| 1134 |
Label bail; |
| 1135 |
masm.ma_mod_mask(src, dest, tmp0, tmp1, ins->shift(), &bail); |
| 1136 |
bailoutFrom(&bail, ins->snapshot()); |
| 1137 |
} else { |
| 1138 |
masm.ma_mod_mask(src, dest, tmp0, tmp1, ins->shift(), nullptr); |
| 1139 |
} |
| 1140 |
} |
| 1141 |
|
| 1142 |
void CodeGenerator::visitBitNotI(LBitNotI* ins) { |
| 1143 |
const LAllocation* input = ins->input(); |
| 1144 |
const LDefinition* dest = ins->output(); |
| 1145 |
MOZ_ASSERT(!input->isConstant()); |
| 1146 |
|
| 1147 |
masm.as_nor(ToRegister(dest), ToRegister(input), zero); |
| 1148 |
} |
| 1149 |
|
| 1150 |
void CodeGenerator::visitBitNotI64(LBitNotI64* ins) { |
| 1151 |
LInt64Allocation input = ins->input(); |
| 1152 |
MOZ_ASSERT(!IsConstant(input)); |
| 1153 |
Register64 inputReg = ToRegister64(input); |
| 1154 |
MOZ_ASSERT(inputReg == ToOutRegister64(ins)); |
| 1155 |
masm.as_nor(inputReg.reg, inputReg.reg, zero); |
| 1156 |
} |
| 1157 |
|
| 1158 |
void CodeGenerator::visitBitOpI(LBitOpI* ins) { |
| 1159 |
const LAllocation* lhs = ins->lhs(); |
| 1160 |
const LAllocation* rhs = ins->rhs(); |
| 1161 |
const LDefinition* dest = ins->output(); |
| 1162 |
// all of these bitops should be either imm32's, or integer registers. |
| 1163 |
switch (ins->bitop()) { |
| 1164 |
case JSOp::BitOr: |
| 1165 |
if (rhs->isConstant()) { |
| 1166 |
masm.ma_or(ToRegister(dest), ToRegister(lhs), Imm32(ToInt32(rhs)), |
| 1167 |
true); |
| 1168 |
} else { |
| 1169 |
masm.as_or(ToRegister(dest), ToRegister(lhs), ToRegister(rhs)); |
| 1170 |
masm.as_slli_w(ToRegister(dest), ToRegister(dest), 0); |
| 1171 |
} |
| 1172 |
break; |
| 1173 |
case JSOp::BitXor: |
| 1174 |
if (rhs->isConstant()) { |
| 1175 |
masm.ma_xor(ToRegister(dest), ToRegister(lhs), Imm32(ToInt32(rhs)), |
| 1176 |
true); |
| 1177 |
} else { |
| 1178 |
masm.as_xor(ToRegister(dest), ToRegister(lhs), ToRegister(rhs)); |
| 1179 |
masm.as_slli_w(ToRegister(dest), ToRegister(dest), 0); |
| 1180 |
} |
| 1181 |
break; |
| 1182 |
case JSOp::BitAnd: |
| 1183 |
if (rhs->isConstant()) { |
| 1184 |
masm.ma_and(ToRegister(dest), ToRegister(lhs), Imm32(ToInt32(rhs)), |
| 1185 |
true); |
| 1186 |
} else { |
| 1187 |
masm.as_and(ToRegister(dest), ToRegister(lhs), ToRegister(rhs)); |
| 1188 |
masm.as_slli_w(ToRegister(dest), ToRegister(dest), 0); |
| 1189 |
} |
| 1190 |
break; |
| 1191 |
default: |
| 1192 |
MOZ_CRASH("unexpected binary opcode"); |
| 1193 |
} |
| 1194 |
} |
| 1195 |
|
| 1196 |
void CodeGenerator::visitBitOpI64(LBitOpI64* lir) { |
| 1197 |
LInt64Allocation lhs = lir->lhs(); |
| 1198 |
LInt64Allocation rhs = lir->rhs(); |
| 1199 |
|
| 1200 |
MOZ_ASSERT(ToOutRegister64(lir) == ToRegister64(lhs)); |
| 1201 |
|
| 1202 |
switch (lir->bitop()) { |
| 1203 |
case JSOp::BitOr: |
| 1204 |
if (IsConstant(rhs)) { |
| 1205 |
masm.or64(Imm64(ToInt64(rhs)), ToRegister64(lhs)); |
| 1206 |
} else { |
| 1207 |
masm.or64(ToOperandOrRegister64(rhs), ToRegister64(lhs)); |
| 1208 |
} |
| 1209 |
break; |
| 1210 |
case JSOp::BitXor: |
| 1211 |
if (IsConstant(rhs)) { |
| 1212 |
masm.xor64(Imm64(ToInt64(rhs)), ToRegister64(lhs)); |
| 1213 |
} else { |
| 1214 |
masm.xor64(ToOperandOrRegister64(rhs), ToRegister64(lhs)); |
| 1215 |
} |
| 1216 |
break; |
| 1217 |
case JSOp::BitAnd: |
| 1218 |
if (IsConstant(rhs)) { |
| 1219 |
masm.and64(Imm64(ToInt64(rhs)), ToRegister64(lhs)); |
| 1220 |
} else { |
| 1221 |
masm.and64(ToOperandOrRegister64(rhs), ToRegister64(lhs)); |
| 1222 |
} |
| 1223 |
break; |
| 1224 |
default: |
| 1225 |
MOZ_CRASH("unexpected binary opcode"); |
| 1226 |
} |
| 1227 |
} |
| 1228 |
|
| 1229 |
void CodeGenerator::visitShiftI(LShiftI* ins) { |
| 1230 |
Register lhs = ToRegister(ins->lhs()); |
| 1231 |
const LAllocation* rhs = ins->rhs(); |
| 1232 |
Register dest = ToRegister(ins->output()); |
| 1233 |
|
| 1234 |
if (rhs->isConstant()) { |
| 1235 |
int32_t shift = ToInt32(rhs) & 0x1F; |
| 1236 |
switch (ins->bitop()) { |
| 1237 |
case JSOp::Lsh: |
| 1238 |
if (shift) { |
| 1239 |
masm.as_slli_w(dest, lhs, shift % 32); |
| 1240 |
} else { |
| 1241 |
masm.move32(lhs, dest); |
| 1242 |
} |
| 1243 |
break; |
| 1244 |
case JSOp::Rsh: |
| 1245 |
if (shift) { |
| 1246 |
masm.as_srai_w(dest, lhs, shift % 32); |
| 1247 |
} else { |
| 1248 |
masm.move32(lhs, dest); |
| 1249 |
} |
| 1250 |
break; |
| 1251 |
case JSOp::Ursh: |
| 1252 |
if (shift) { |
| 1253 |
masm.as_srli_w(dest, lhs, shift % 32); |
| 1254 |
} else { |
| 1255 |
// x >>> 0 can overflow. |
| 1256 |
if (ins->mir()->toUrsh()->fallible()) { |
| 1257 |
bailoutCmp32(Assembler::LessThan, lhs, Imm32(0), ins->snapshot()); |
| 1258 |
} |
| 1259 |
masm.move32(lhs, dest); |
| 1260 |
} |
| 1261 |
break; |
| 1262 |
default: |
| 1263 |
MOZ_CRASH("Unexpected shift op"); |
| 1264 |
} |
| 1265 |
} else { |
| 1266 |
// The shift amounts should be AND'ed into the 0-31 range |
| 1267 |
masm.ma_and(dest, ToRegister(rhs), Imm32(0x1F)); |
| 1268 |
|
| 1269 |
switch (ins->bitop()) { |
| 1270 |
case JSOp::Lsh: |
| 1271 |
masm.as_sll_w(dest, lhs, dest); |
| 1272 |
break; |
| 1273 |
case JSOp::Rsh: |
| 1274 |
masm.as_sra_w(dest, lhs, dest); |
| 1275 |
break; |
| 1276 |
case JSOp::Ursh: |
| 1277 |
masm.as_srl_w(dest, lhs, dest); |
| 1278 |
if (ins->mir()->toUrsh()->fallible()) { |
| 1279 |
// x >>> 0 can overflow. |
| 1280 |
bailoutCmp32(Assembler::LessThan, dest, Imm32(0), ins->snapshot()); |
| 1281 |
} |
| 1282 |
break; |
| 1283 |
default: |
| 1284 |
MOZ_CRASH("Unexpected shift op"); |
| 1285 |
} |
| 1286 |
} |
| 1287 |
} |
| 1288 |
|
| 1289 |
void CodeGenerator::visitShiftI64(LShiftI64* lir) { |
| 1290 |
LInt64Allocation lhs = lir->lhs(); |
| 1291 |
const LAllocation* rhs = lir->rhs(); |
| 1292 |
|
| 1293 |
MOZ_ASSERT(ToOutRegister64(lir) == ToRegister64(lhs)); |
| 1294 |
|
| 1295 |
if (rhs->isConstant()) { |
| 1296 |
int32_t shift = int32_t(rhs->toConstant()->toInt64() & 0x3F); |
| 1297 |
switch (lir->bitop()) { |
| 1298 |
case JSOp::Lsh: |
| 1299 |
if (shift) { |
| 1300 |
masm.lshift64(Imm32(shift), ToRegister64(lhs)); |
| 1301 |
} |
| 1302 |
break; |
| 1303 |
case JSOp::Rsh: |
| 1304 |
if (shift) { |
| 1305 |
masm.rshift64Arithmetic(Imm32(shift), ToRegister64(lhs)); |
| 1306 |
} |
| 1307 |
break; |
| 1308 |
case JSOp::Ursh: |
| 1309 |
if (shift) { |
| 1310 |
masm.rshift64(Imm32(shift), ToRegister64(lhs)); |
| 1311 |
} |
| 1312 |
break; |
| 1313 |
default: |
| 1314 |
MOZ_CRASH("Unexpected shift op"); |
| 1315 |
} |
| 1316 |
return; |
| 1317 |
} |
| 1318 |
|
| 1319 |
switch (lir->bitop()) { |
| 1320 |
case JSOp::Lsh: |
| 1321 |
masm.lshift64(ToRegister(rhs), ToRegister64(lhs)); |
| 1322 |
break; |
| 1323 |
case JSOp::Rsh: |
| 1324 |
masm.rshift64Arithmetic(ToRegister(rhs), ToRegister64(lhs)); |
| 1325 |
break; |
| 1326 |
case JSOp::Ursh: |
| 1327 |
masm.rshift64(ToRegister(rhs), ToRegister64(lhs)); |
| 1328 |
break; |
| 1329 |
default: |
| 1330 |
MOZ_CRASH("Unexpected shift op"); |
| 1331 |
} |
| 1332 |
} |
| 1333 |
|
| 1334 |
void CodeGenerator::visitUrshD(LUrshD* ins) { |
| 1335 |
Register lhs = ToRegister(ins->lhs()); |
| 1336 |
Register temp = ToRegister(ins->temp0()); |
| 1337 |
|
| 1338 |
const LAllocation* rhs = ins->rhs(); |
| 1339 |
FloatRegister out = ToFloatRegister(ins->output()); |
| 1340 |
|
| 1341 |
if (rhs->isConstant()) { |
| 1342 |
masm.as_srli_w(temp, lhs, ToInt32(rhs) % 32); |
| 1343 |
} else { |
| 1344 |
masm.as_srl_w(temp, lhs, ToRegister(rhs)); |
| 1345 |
} |
| 1346 |
|
| 1347 |
masm.convertUInt32ToDouble(temp, out); |
| 1348 |
} |
| 1349 |
|
| 1350 |
void CodeGenerator::visitPowHalfD(LPowHalfD* ins) { |
| 1351 |
FloatRegister input = ToFloatRegister(ins->input()); |
| 1352 |
FloatRegister output = ToFloatRegister(ins->output()); |
| 1353 |
ScratchDoubleScope fpscratch(masm); |
| 1354 |
|
| 1355 |
Label done, skip; |
| 1356 |
|
| 1357 |
// Masm.pow(-Infinity, 0.5) == Infinity. |
| 1358 |
masm.loadConstantDouble(NegativeInfinity<double>(), fpscratch); |
| 1359 |
masm.ma_bc_d(input, fpscratch, &skip, Assembler::DoubleNotEqualOrUnordered, |
| 1360 |
ShortJump); |
| 1361 |
masm.as_fneg_d(output, fpscratch); |
| 1362 |
masm.ma_b(&done, ShortJump); |
| 1363 |
|
| 1364 |
masm.bind(&skip); |
| 1365 |
// Math.pow(-0, 0.5) == 0 == Math.pow(0, 0.5). |
| 1366 |
// Adding 0 converts any -0 to 0. |
| 1367 |
masm.loadConstantDouble(0.0, fpscratch); |
| 1368 |
masm.as_fadd_d(output, input, fpscratch); |
| 1369 |
masm.as_fsqrt_d(output, output); |
| 1370 |
|
| 1371 |
masm.bind(&done); |
| 1372 |
} |
| 1373 |
|
| 1374 |
void CodeGenerator::visitMathD(LMathD* math) { |
| 1375 |
FloatRegister src1 = ToFloatRegister(math->lhs()); |
| 1376 |
FloatRegister src2 = ToFloatRegister(math->rhs()); |
| 1377 |
FloatRegister output = ToFloatRegister(math->output()); |
| 1378 |
|
| 1379 |
switch (math->jsop()) { |
| 1380 |
case JSOp::Add: |
| 1381 |
masm.as_fadd_d(output, src1, src2); |
| 1382 |
break; |
| 1383 |
case JSOp::Sub: |
| 1384 |
masm.as_fsub_d(output, src1, src2); |
| 1385 |
break; |
| 1386 |
case JSOp::Mul: |
| 1387 |
masm.as_fmul_d(output, src1, src2); |
| 1388 |
break; |
| 1389 |
case JSOp::Div: |
| 1390 |
masm.as_fdiv_d(output, src1, src2); |
| 1391 |
break; |
| 1392 |
default: |
| 1393 |
MOZ_CRASH("unexpected opcode"); |
| 1394 |
} |
| 1395 |
} |
| 1396 |
|
| 1397 |
void CodeGenerator::visitMathF(LMathF* math) { |
| 1398 |
FloatRegister src1 = ToFloatRegister(math->lhs()); |
| 1399 |
FloatRegister src2 = ToFloatRegister(math->rhs()); |
| 1400 |
FloatRegister output = ToFloatRegister(math->output()); |
| 1401 |
|
| 1402 |
switch (math->jsop()) { |
| 1403 |
case JSOp::Add: |
| 1404 |
masm.as_fadd_s(output, src1, src2); |
| 1405 |
break; |
| 1406 |
case JSOp::Sub: |
| 1407 |
masm.as_fsub_s(output, src1, src2); |
| 1408 |
break; |
| 1409 |
case JSOp::Mul: |
| 1410 |
masm.as_fmul_s(output, src1, src2); |
| 1411 |
break; |
| 1412 |
case JSOp::Div: |
| 1413 |
masm.as_fdiv_s(output, src1, src2); |
| 1414 |
break; |
| 1415 |
default: |
| 1416 |
MOZ_CRASH("unexpected opcode"); |
| 1417 |
} |
| 1418 |
} |
| 1419 |
|
| 1420 |
void CodeGenerator::visitTruncateDToInt32(LTruncateDToInt32* ins) { |
| 1421 |
emitTruncateDouble(ToFloatRegister(ins->input()), ToRegister(ins->output()), |
| 1422 |
ins->mir()); |
| 1423 |
} |
| 1424 |
|
| 1425 |
void CodeGenerator::visitTruncateFToInt32(LTruncateFToInt32* ins) { |
| 1426 |
emitTruncateFloat32(ToFloatRegister(ins->input()), ToRegister(ins->output()), |
| 1427 |
ins->mir()); |
| 1428 |
} |
| 1429 |
|
| 1430 |
void CodeGenerator::visitWasmBuiltinTruncateDToInt32( |
| 1431 |
LWasmBuiltinTruncateDToInt32* lir) { |
| 1432 |
emitTruncateDouble(ToFloatRegister(lir->input()), ToRegister(lir->output()), |
| 1433 |
lir->mir()); |
| 1434 |
} |
| 1435 |
|
| 1436 |
void CodeGenerator::visitWasmBuiltinTruncateFToInt32( |
| 1437 |
LWasmBuiltinTruncateFToInt32* lir) { |
| 1438 |
emitTruncateFloat32(ToFloatRegister(lir->input()), ToRegister(lir->output()), |
| 1439 |
lir->mir()); |
| 1440 |
} |
| 1441 |
|
| 1442 |
void CodeGenerator::visitWasmTruncateToInt32(LWasmTruncateToInt32* lir) { |
| 1443 |
auto input = ToFloatRegister(lir->input()); |
| 1444 |
auto output = ToRegister(lir->output()); |
| 1445 |
|
| 1446 |
MWasmTruncateToInt32* mir = lir->mir(); |
| 1447 |
MIRType fromType = mir->input()->type(); |
| 1448 |
|
| 1449 |
MOZ_ASSERT(fromType == MIRType::Double || fromType == MIRType::Float32); |
| 1450 |
|
| 1451 |
auto* ool = new (alloc()) OutOfLineWasmTruncateCheck(mir, input, output); |
| 1452 |
addOutOfLineCode(ool, mir); |
| 1453 |
|
| 1454 |
Label* oolEntry = ool->entry(); |
| 1455 |
if (mir->isUnsigned()) { |
| 1456 |
if (fromType == MIRType::Double) { |
| 1457 |
masm.wasmTruncateDoubleToUInt32(input, output, mir->isSaturating(), |
| 1458 |
oolEntry); |
| 1459 |
} else if (fromType == MIRType::Float32) { |
| 1460 |
masm.wasmTruncateFloat32ToUInt32(input, output, mir->isSaturating(), |
| 1461 |
oolEntry); |
| 1462 |
} else { |
| 1463 |
MOZ_CRASH("unexpected type"); |
| 1464 |
} |
| 1465 |
|
| 1466 |
masm.bind(ool->rejoin()); |
| 1467 |
return; |
| 1468 |
} |
| 1469 |
|
| 1470 |
if (fromType == MIRType::Double) { |
| 1471 |
masm.wasmTruncateDoubleToInt32(input, output, mir->isSaturating(), |
| 1472 |
oolEntry); |
| 1473 |
} else if (fromType == MIRType::Float32) { |
| 1474 |
masm.wasmTruncateFloat32ToInt32(input, output, mir->isSaturating(), |
| 1475 |
oolEntry); |
| 1476 |
} else { |
| 1477 |
MOZ_CRASH("unexpected type"); |
| 1478 |
} |
| 1479 |
|
| 1480 |
masm.bind(ool->rejoin()); |
| 1481 |
} |
| 1482 |
|
| 1483 |
void CodeGenerator::visitCopySignF(LCopySignF* ins) { |
| 1484 |
FloatRegister lhs = ToFloatRegister(ins->lhs()); |
| 1485 |
FloatRegister rhs = ToFloatRegister(ins->rhs()); |
| 1486 |
FloatRegister output = ToFloatRegister(ins->output()); |
| 1487 |
|
| 1488 |
Register lhsi = ToRegister(ins->temp0()); |
| 1489 |
Register rhsi = ToRegister(ins->temp1()); |
| 1490 |
|
| 1491 |
masm.moveFromFloat32(lhs, lhsi); |
| 1492 |
masm.moveFromFloat32(rhs, rhsi); |
| 1493 |
|
| 1494 |
// Combine. |
| 1495 |
masm.as_bstrins_w(rhsi, lhsi, 30, 0); |
| 1496 |
|
| 1497 |
masm.moveToFloat32(rhsi, output); |
| 1498 |
} |
| 1499 |
|
| 1500 |
void CodeGenerator::visitCopySignD(LCopySignD* ins) { |
| 1501 |
FloatRegister lhs = ToFloatRegister(ins->lhs()); |
| 1502 |
FloatRegister rhs = ToFloatRegister(ins->rhs()); |
| 1503 |
FloatRegister output = ToFloatRegister(ins->output()); |
| 1504 |
|
| 1505 |
Register lhsi = ToRegister(ins->temp0()); |
| 1506 |
Register rhsi = ToRegister(ins->temp1()); |
| 1507 |
|
| 1508 |
// Manipulate high words of double inputs. |
| 1509 |
masm.moveFromDoubleHi(lhs, lhsi); |
| 1510 |
masm.moveFromDoubleHi(rhs, rhsi); |
| 1511 |
|
| 1512 |
// Combine. |
| 1513 |
masm.as_bstrins_w(rhsi, lhsi, 30, 0); |
| 1514 |
|
| 1515 |
masm.moveToDoubleHi(rhsi, output); |
| 1516 |
} |
| 1517 |
|
| 1518 |
void CodeGenerator::visitTestDAndBranch(LTestDAndBranch* test) { |
| 1519 |
FloatRegister input = ToFloatRegister(test->input()); |
| 1520 |
ScratchDoubleScope fpscratch(masm); |
| 1521 |
|
| 1522 |
MBasicBlock* ifTrue = test->ifTrue(); |
| 1523 |
MBasicBlock* ifFalse = test->ifFalse(); |
| 1524 |
|
| 1525 |
masm.loadConstantDouble(0.0, fpscratch); |
| 1526 |
// If 0, or NaN, the result is false. |
| 1527 |
if (isNextBlock(ifFalse->lir())) { |
| 1528 |
branchToBlock(Assembler::DoubleFloat, input, fpscratch, ifTrue, |
| 1529 |
Assembler::DoubleNotEqual); |
| 1530 |
} else { |
| 1531 |
branchToBlock(Assembler::DoubleFloat, input, fpscratch, ifFalse, |
| 1532 |
Assembler::DoubleEqualOrUnordered); |
| 1533 |
jumpToBlock(ifTrue); |
| 1534 |
} |
| 1535 |
} |
| 1536 |
|
| 1537 |
void CodeGenerator::visitTestFAndBranch(LTestFAndBranch* test) { |
| 1538 |
FloatRegister input = ToFloatRegister(test->input()); |
| 1539 |
ScratchFloat32Scope fpscratch(masm); |
| 1540 |
|
| 1541 |
MBasicBlock* ifTrue = test->ifTrue(); |
| 1542 |
MBasicBlock* ifFalse = test->ifFalse(); |
| 1543 |
|
| 1544 |
masm.loadConstantFloat32(0.0f, fpscratch); |
| 1545 |
// If 0, or NaN, the result is false. |
| 1546 |
|
| 1547 |
if (isNextBlock(ifFalse->lir())) { |
| 1548 |
branchToBlock(Assembler::SingleFloat, input, fpscratch, ifTrue, |
| 1549 |
Assembler::DoubleNotEqual); |
| 1550 |
} else { |
| 1551 |
branchToBlock(Assembler::SingleFloat, input, fpscratch, ifFalse, |
| 1552 |
Assembler::DoubleEqualOrUnordered); |
| 1553 |
jumpToBlock(ifTrue); |
| 1554 |
} |
| 1555 |
} |
| 1556 |
|
| 1557 |
void CodeGenerator::visitCompareD(LCompareD* comp) { |
| 1558 |
FloatRegister lhs = ToFloatRegister(comp->left()); |
| 1559 |
FloatRegister rhs = ToFloatRegister(comp->right()); |
| 1560 |
Register dest = ToRegister(comp->output()); |
| 1561 |
|
| 1562 |
Assembler::DoubleCondition cond = JSOpToDoubleCondition(comp->mir()->jsop()); |
| 1563 |
masm.ma_cmp_set_double(dest, lhs, rhs, cond); |
| 1564 |
} |
| 1565 |
|
| 1566 |
void CodeGenerator::visitCompareF(LCompareF* comp) { |
| 1567 |
FloatRegister lhs = ToFloatRegister(comp->left()); |
| 1568 |
FloatRegister rhs = ToFloatRegister(comp->right()); |
| 1569 |
Register dest = ToRegister(comp->output()); |
| 1570 |
|
| 1571 |
Assembler::DoubleCondition cond = JSOpToDoubleCondition(comp->mir()->jsop()); |
| 1572 |
masm.ma_cmp_set_float32(dest, lhs, rhs, cond); |
| 1573 |
} |
| 1574 |
|
| 1575 |
void CodeGenerator::visitCompareDAndBranch(LCompareDAndBranch* comp) { |
| 1576 |
FloatRegister lhs = ToFloatRegister(comp->left()); |
| 1577 |
FloatRegister rhs = ToFloatRegister(comp->right()); |
| 1578 |
|
| 1579 |
Assembler::DoubleCondition cond = |
| 1580 |
JSOpToDoubleCondition(comp->cmpMir()->jsop()); |
| 1581 |
MBasicBlock* ifTrue = comp->ifTrue(); |
| 1582 |
MBasicBlock* ifFalse = comp->ifFalse(); |
| 1583 |
|
| 1584 |
if (isNextBlock(ifFalse->lir())) { |
| 1585 |
branchToBlock(Assembler::DoubleFloat, lhs, rhs, ifTrue, cond); |
| 1586 |
} else { |
| 1587 |
branchToBlock(Assembler::DoubleFloat, lhs, rhs, ifFalse, |
| 1588 |
Assembler::InvertCondition(cond)); |
| 1589 |
jumpToBlock(ifTrue); |
| 1590 |
} |
| 1591 |
} |
| 1592 |
|
| 1593 |
void CodeGenerator::visitCompareFAndBranch(LCompareFAndBranch* comp) { |
| 1594 |
FloatRegister lhs = ToFloatRegister(comp->left()); |
| 1595 |
FloatRegister rhs = ToFloatRegister(comp->right()); |
| 1596 |
|
| 1597 |
Assembler::DoubleCondition cond = |
| 1598 |
JSOpToDoubleCondition(comp->cmpMir()->jsop()); |
| 1599 |
MBasicBlock* ifTrue = comp->ifTrue(); |
| 1600 |
MBasicBlock* ifFalse = comp->ifFalse(); |
| 1601 |
|
| 1602 |
if (isNextBlock(ifFalse->lir())) { |
| 1603 |
branchToBlock(Assembler::SingleFloat, lhs, rhs, ifTrue, cond); |
| 1604 |
} else { |
| 1605 |
branchToBlock(Assembler::SingleFloat, lhs, rhs, ifFalse, |
| 1606 |
Assembler::InvertCondition(cond)); |
| 1607 |
jumpToBlock(ifTrue); |
| 1608 |
} |
| 1609 |
} |
| 1610 |
|
| 1611 |
void CodeGenerator::visitWasmUint32ToDouble(LWasmUint32ToDouble* lir) { |
| 1612 |
masm.convertUInt32ToDouble(ToRegister(lir->input()), |
| 1613 |
ToFloatRegister(lir->output())); |
| 1614 |
} |
| 1615 |
|
| 1616 |
void CodeGenerator::visitWasmUint32ToFloat32(LWasmUint32ToFloat32* lir) { |
| 1617 |
masm.convertUInt32ToFloat32(ToRegister(lir->input()), |
| 1618 |
ToFloatRegister(lir->output())); |
| 1619 |
} |
| 1620 |
|
| 1621 |
void CodeGenerator::visitNotD(LNotD* ins) { |
| 1622 |
// Since this operation is not, we want to set a bit if |
| 1623 |
// the double is falsey, which means 0.0, -0.0 or NaN. |
| 1624 |
FloatRegister in = ToFloatRegister(ins->input()); |
| 1625 |
Register dest = ToRegister(ins->output()); |
| 1626 |
ScratchDoubleScope fpscratch(masm); |
| 1627 |
|
| 1628 |
masm.loadConstantDouble(0.0, fpscratch); |
| 1629 |
masm.ma_cmp_set_double(dest, in, fpscratch, |
| 1630 |
Assembler::DoubleEqualOrUnordered); |
| 1631 |
} |
| 1632 |
|
| 1633 |
void CodeGenerator::visitNotF(LNotF* ins) { |
| 1634 |
// Since this operation is not, we want to set a bit if |
| 1635 |
// the float32 is falsey, which means 0.0, -0.0 or NaN. |
| 1636 |
FloatRegister in = ToFloatRegister(ins->input()); |
| 1637 |
Register dest = ToRegister(ins->output()); |
| 1638 |
ScratchFloat32Scope fpscratch(masm); |
| 1639 |
|
| 1640 |
masm.loadConstantFloat32(0.0f, fpscratch); |
| 1641 |
masm.ma_cmp_set_float32(dest, in, fpscratch, |
| 1642 |
Assembler::DoubleEqualOrUnordered); |
| 1643 |
} |
| 1644 |
|
| 1645 |
void CodeGenerator::visitWasmLoad(LWasmLoad* lir) { emitWasmLoad(lir); } |
| 1646 |
|
| 1647 |
void CodeGenerator::visitWasmStore(LWasmStore* lir) { emitWasmStore(lir); } |
| 1648 |
|
| 1649 |
void CodeGenerator::visitAsmJSLoadHeap(LAsmJSLoadHeap* ins) { |
| 1650 |
const MAsmJSLoadHeap* mir = ins->mir(); |
| 1651 |
MOZ_ASSERT(!mir->hasMemoryBase()); |
| 1652 |
|
| 1653 |
const LAllocation* ptr = ins->ptr(); |
| 1654 |
const LDefinition* output = ins->output(); |
| 1655 |
const LAllocation* boundsCheckLimit = ins->boundsCheckLimit(); |
| 1656 |
|
| 1657 |
Register ptrReg = ToRegister(ptr); |
| 1658 |
Scalar::Type accessType = mir->accessType(); |
| 1659 |
bool isFloat = accessType == Scalar::Float32 || accessType == Scalar::Float64; |
| 1660 |
Label done; |
| 1661 |
|
| 1662 |
if (mir->needsBoundsCheck()) { |
| 1663 |
Label boundsCheckPassed; |
| 1664 |
Register boundsCheckLimitReg = ToRegister(boundsCheckLimit); |
| 1665 |
masm.wasmBoundsCheck32(Assembler::Below, ptrReg, boundsCheckLimitReg, |
| 1666 |
&boundsCheckPassed); |
| 1667 |
// Return a default value in case of a bounds-check failure. |
| 1668 |
if (isFloat) { |
| 1669 |
if (accessType == Scalar::Float32) { |
| 1670 |
masm.loadConstantFloat32(GenericNaN(), ToFloatRegister(output)); |
| 1671 |
} else { |
| 1672 |
masm.loadConstantDouble(GenericNaN(), ToFloatRegister(output)); |
| 1673 |
} |
| 1674 |
} else { |
| 1675 |
masm.mov(zero, ToRegister(output)); |
| 1676 |
} |
| 1677 |
masm.jump(&done); |
| 1678 |
masm.bind(&boundsCheckPassed); |
| 1679 |
} |
| 1680 |
|
| 1681 |
// TODO(loong64): zero-extend index in asm.js? |
| 1682 |
SecondScratchRegisterScope scratch2(masm); |
| 1683 |
masm.move32To64ZeroExtend(ptrReg, Register64(scratch2)); |
| 1684 |
|
| 1685 |
switch (accessType) { |
| 1686 |
case Scalar::Int8: |
| 1687 |
masm.as_ldx_b(ToRegister(output), HeapReg, scratch2); |
| 1688 |
break; |
| 1689 |
case Scalar::Uint8: |
| 1690 |
masm.as_ldx_bu(ToRegister(output), HeapReg, scratch2); |
| 1691 |
break; |
| 1692 |
case Scalar::Int16: |
| 1693 |
masm.as_ldx_h(ToRegister(output), HeapReg, scratch2); |
| 1694 |
break; |
| 1695 |
case Scalar::Uint16: |
| 1696 |
masm.as_ldx_hu(ToRegister(output), HeapReg, scratch2); |
| 1697 |
break; |
| 1698 |
case Scalar::Int32: |
| 1699 |
case Scalar::Uint32: |
| 1700 |
masm.as_ldx_w(ToRegister(output), HeapReg, scratch2); |
| 1701 |
break; |
| 1702 |
case Scalar::Float64: |
| 1703 |
masm.as_fldx_d(ToFloatRegister(output), HeapReg, scratch2); |
| 1704 |
break; |
| 1705 |
case Scalar::Float32: |
| 1706 |
masm.as_fldx_s(ToFloatRegister(output), HeapReg, scratch2); |
| 1707 |
break; |
| 1708 |
default: |
| 1709 |
MOZ_CRASH("unexpected array type"); |
| 1710 |
} |
| 1711 |
|
| 1712 |
if (done.used()) { |
| 1713 |
masm.bind(&done); |
| 1714 |
} |
| 1715 |
} |
| 1716 |
|
| 1717 |
void CodeGenerator::visitAsmJSStoreHeap(LAsmJSStoreHeap* ins) { |
| 1718 |
const MAsmJSStoreHeap* mir = ins->mir(); |
| 1719 |
MOZ_ASSERT(!mir->hasMemoryBase()); |
| 1720 |
|
| 1721 |
const LAllocation* value = ins->value(); |
| 1722 |
const LAllocation* ptr = ins->ptr(); |
| 1723 |
const LAllocation* boundsCheckLimit = ins->boundsCheckLimit(); |
| 1724 |
|
| 1725 |
Register ptrReg = ToRegister(ptr); |
| 1726 |
|
| 1727 |
Label done; |
| 1728 |
if (mir->needsBoundsCheck()) { |
| 1729 |
Register boundsCheckLimitReg = ToRegister(boundsCheckLimit); |
| 1730 |
masm.wasmBoundsCheck32(Assembler::AboveOrEqual, ptrReg, boundsCheckLimitReg, |
| 1731 |
&done); |
| 1732 |
} |
| 1733 |
|
| 1734 |
// TODO(loong64): zero-extend index in asm.js? |
| 1735 |
SecondScratchRegisterScope scratch2(masm); |
| 1736 |
masm.move32To64ZeroExtend(ptrReg, Register64(scratch2)); |
| 1737 |
|
| 1738 |
switch (mir->accessType()) { |
| 1739 |
case Scalar::Int8: |
| 1740 |
case Scalar::Uint8: |
| 1741 |
masm.as_stx_b(ToRegister(value), HeapReg, scratch2); |
| 1742 |
break; |
| 1743 |
case Scalar::Int16: |
| 1744 |
case Scalar::Uint16: |
| 1745 |
masm.as_stx_h(ToRegister(value), HeapReg, scratch2); |
| 1746 |
break; |
| 1747 |
case Scalar::Int32: |
| 1748 |
case Scalar::Uint32: |
| 1749 |
masm.as_stx_w(ToRegister(value), HeapReg, scratch2); |
| 1750 |
break; |
| 1751 |
case Scalar::Float64: |
| 1752 |
masm.as_fstx_d(ToFloatRegister(value), HeapReg, scratch2); |
| 1753 |
break; |
| 1754 |
case Scalar::Float32: |
| 1755 |
masm.as_fstx_s(ToFloatRegister(value), HeapReg, scratch2); |
| 1756 |
break; |
| 1757 |
default: |
| 1758 |
MOZ_CRASH("unexpected array type"); |
| 1759 |
} |
| 1760 |
|
| 1761 |
if (done.used()) { |
| 1762 |
masm.bind(&done); |
| 1763 |
} |
| 1764 |
} |
| 1765 |
|
| 1766 |
void CodeGenerator::visitWasmCompareExchangeHeap( |
| 1767 |
LWasmCompareExchangeHeap* ins) { |
| 1768 |
MWasmCompareExchangeHeap* mir = ins->mir(); |
| 1769 |
Register memoryBase = ToRegister(ins->memoryBase()); |
| 1770 |
Register ptrReg = ToRegister(ins->ptr()); |
| 1771 |
BaseIndex srcAddr(memoryBase, ptrReg, TimesOne, mir->access().offset32()); |
| 1772 |
|
| 1773 |
Register oldval = ToRegister(ins->oldValue()); |
| 1774 |
Register newval = ToRegister(ins->newValue()); |
| 1775 |
Register valueTemp = ToTempRegisterOrInvalid(ins->temp0()); |
| 1776 |
Register offsetTemp = ToTempRegisterOrInvalid(ins->temp1()); |
| 1777 |
Register maskTemp = ToTempRegisterOrInvalid(ins->temp2()); |
| 1778 |
|
| 1779 |
masm.wasmCompareExchange(mir->access(), srcAddr, oldval, newval, valueTemp, |
| 1780 |
offsetTemp, maskTemp, ToRegister(ins->output())); |
| 1781 |
} |
| 1782 |
|
| 1783 |
void CodeGenerator::visitWasmAtomicExchangeHeap(LWasmAtomicExchangeHeap* ins) { |
| 1784 |
MWasmAtomicExchangeHeap* mir = ins->mir(); |
| 1785 |
Register memoryBase = ToRegister(ins->memoryBase()); |
| 1786 |
Register ptrReg = ToRegister(ins->ptr()); |
| 1787 |
Register value = ToRegister(ins->value()); |
| 1788 |
BaseIndex srcAddr(memoryBase, ptrReg, TimesOne, mir->access().offset32()); |
| 1789 |
|
| 1790 |
Register valueTemp = ToTempRegisterOrInvalid(ins->temp0()); |
| 1791 |
Register offsetTemp = ToTempRegisterOrInvalid(ins->temp1()); |
| 1792 |
Register maskTemp = ToTempRegisterOrInvalid(ins->temp2()); |
| 1793 |
|
| 1794 |
masm.wasmAtomicExchange(mir->access(), srcAddr, value, valueTemp, offsetTemp, |
| 1795 |
maskTemp, ToRegister(ins->output())); |
| 1796 |
} |
| 1797 |
|
| 1798 |
void CodeGenerator::visitWasmAtomicBinopHeap(LWasmAtomicBinopHeap* ins) { |
| 1799 |
MOZ_ASSERT(ins->mir()->hasUses()); |
| 1800 |
|
| 1801 |
MWasmAtomicBinopHeap* mir = ins->mir(); |
| 1802 |
Register memoryBase = ToRegister(ins->memoryBase()); |
| 1803 |
Register ptrReg = ToRegister(ins->ptr()); |
| 1804 |
Register valueTemp = ToTempRegisterOrInvalid(ins->temp0()); |
| 1805 |
Register offsetTemp = ToTempRegisterOrInvalid(ins->temp1()); |
| 1806 |
Register maskTemp = ToTempRegisterOrInvalid(ins->temp2()); |
| 1807 |
|
| 1808 |
BaseIndex srcAddr(memoryBase, ptrReg, TimesOne, mir->access().offset32()); |
| 1809 |
|
| 1810 |
masm.wasmAtomicFetchOp(mir->access(), mir->operation(), |
| 1811 |
ToRegister(ins->value()), srcAddr, valueTemp, |
| 1812 |
offsetTemp, maskTemp, ToRegister(ins->output())); |
| 1813 |
} |
| 1814 |
|
| 1815 |
void CodeGenerator::visitWasmAtomicBinopHeapForEffect( |
| 1816 |
LWasmAtomicBinopHeapForEffect* ins) { |
| 1817 |
MOZ_ASSERT(!ins->mir()->hasUses()); |
| 1818 |
|
| 1819 |
MWasmAtomicBinopHeap* mir = ins->mir(); |
| 1820 |
Register memoryBase = ToRegister(ins->memoryBase()); |
| 1821 |
Register ptrReg = ToRegister(ins->ptr()); |
| 1822 |
Register valueTemp = ToTempRegisterOrInvalid(ins->temp0()); |
| 1823 |
Register offsetTemp = ToTempRegisterOrInvalid(ins->temp1()); |
| 1824 |
Register maskTemp = ToTempRegisterOrInvalid(ins->temp2()); |
| 1825 |
|
| 1826 |
BaseIndex srcAddr(memoryBase, ptrReg, TimesOne, mir->access().offset32()); |
| 1827 |
masm.wasmAtomicEffectOp(mir->access(), mir->operation(), |
| 1828 |
ToRegister(ins->value()), srcAddr, valueTemp, |
| 1829 |
offsetTemp, maskTemp); |
| 1830 |
} |
| 1831 |
|
| 1832 |
void CodeGenerator::visitWasmStackArg(LWasmStackArg* ins) { |
| 1833 |
const MWasmStackArg* mir = ins->mir(); |
| 1834 |
if (ins->arg()->isConstant()) { |
| 1835 |
masm.storePtr(ImmWord(ToInt32(ins->arg())), |
| 1836 |
Address(StackPointer, mir->spOffset())); |
| 1837 |
} else { |
| 1838 |
if (ins->arg()->isGeneralReg()) { |
| 1839 |
masm.storePtr(ToRegister(ins->arg()), |
| 1840 |
Address(StackPointer, mir->spOffset())); |
| 1841 |
} else if (mir->input()->type() == MIRType::Double) { |
| 1842 |
masm.storeDouble(ToFloatRegister(ins->arg()), |
| 1843 |
Address(StackPointer, mir->spOffset())); |
| 1844 |
} else { |
| 1845 |
masm.storeFloat32(ToFloatRegister(ins->arg()), |
| 1846 |
Address(StackPointer, mir->spOffset())); |
| 1847 |
} |
| 1848 |
} |
| 1849 |
} |
| 1850 |
|
| 1851 |
void CodeGenerator::visitWasmStackArgI64(LWasmStackArgI64* ins) { |
| 1852 |
const MWasmStackArg* mir = ins->mir(); |
| 1853 |
Address dst(StackPointer, mir->spOffset()); |
| 1854 |
if (IsConstant(ins->arg())) { |
| 1855 |
masm.store64(Imm64(ToInt64(ins->arg())), dst); |
| 1856 |
} else { |
| 1857 |
masm.store64(ToRegister64(ins->arg()), dst); |
| 1858 |
} |
| 1859 |
} |
| 1860 |
|
| 1861 |
void CodeGenerator::visitWasmSelect(LWasmSelect* ins) { |
| 1862 |
MIRType mirType = ins->mir()->type(); |
| 1863 |
|
| 1864 |
Register cond = ToRegister(ins->condExpr()); |
| 1865 |
const LAllocation* falseExpr = ins->falseExpr(); |
| 1866 |
|
| 1867 |
if (mirType == MIRType::Int32 || mirType == MIRType::WasmAnyRef) { |
| 1868 |
Register out = ToRegister(ins->output()); |
| 1869 |
MOZ_ASSERT(ToRegister(ins->trueExpr()) == out, |
| 1870 |
"true expr input is reused for output"); |
| 1871 |
if (falseExpr->isGeneralReg()) { |
| 1872 |
masm.moveIfZero(out, ToRegister(falseExpr), cond); |
| 1873 |
} else { |
| 1874 |
masm.cmp32Load32(Assembler::Zero, cond, cond, ToAddress(falseExpr), out); |
| 1875 |
} |
| 1876 |
return; |
| 1877 |
} |
| 1878 |
|
| 1879 |
FloatRegister out = ToFloatRegister(ins->output()); |
| 1880 |
MOZ_ASSERT(ToFloatRegister(ins->trueExpr()) == out, |
| 1881 |
"true expr input is reused for output"); |
| 1882 |
|
| 1883 |
if (falseExpr->isFloatReg()) { |
| 1884 |
if (mirType == MIRType::Float32) { |
| 1885 |
masm.ma_fmovz(Assembler::SingleFloat, out, ToFloatRegister(falseExpr), |
| 1886 |
cond); |
| 1887 |
} else if (mirType == MIRType::Double) { |
| 1888 |
masm.ma_fmovz(Assembler::DoubleFloat, out, ToFloatRegister(falseExpr), |
| 1889 |
cond); |
| 1890 |
} else { |
| 1891 |
MOZ_CRASH("unhandled type in visitWasmSelect!"); |
| 1892 |
} |
| 1893 |
} else { |
| 1894 |
Label done; |
| 1895 |
masm.ma_b(cond, cond, &done, Assembler::NonZero, ShortJump); |
| 1896 |
|
| 1897 |
if (mirType == MIRType::Float32) { |
| 1898 |
masm.loadFloat32(ToAddress(falseExpr), out); |
| 1899 |
} else if (mirType == MIRType::Double) { |
| 1900 |
masm.loadDouble(ToAddress(falseExpr), out); |
| 1901 |
} else { |
| 1902 |
MOZ_CRASH("unhandled type in visitWasmSelect!"); |
| 1903 |
} |
| 1904 |
|
| 1905 |
masm.bind(&done); |
| 1906 |
} |
| 1907 |
} |
| 1908 |
|
| 1909 |
// We expect to handle only the case where compare is {U,}Int32 and select is |
| 1910 |
// {U,}Int32, and the "true" input is reused for the output. |
| 1911 |
void CodeGenerator::visitWasmCompareAndSelect(LWasmCompareAndSelect* ins) { |
| 1912 |
bool cmpIs32bit = ins->compareType() == MCompare::Compare_Int32 || |
| 1913 |
ins->compareType() == MCompare::Compare_UInt32; |
| 1914 |
bool selIs32bit = ins->mir()->type() == MIRType::Int32; |
| 1915 |
|
| 1916 |
MOZ_RELEASE_ASSERT( |
| 1917 |
cmpIs32bit && selIs32bit, |
| 1918 |
"CodeGenerator::visitWasmCompareAndSelect: unexpected types"); |
| 1919 |
|
| 1920 |
Register trueExprAndDest = ToRegister(ins->output()); |
| 1921 |
MOZ_ASSERT(ToRegister(ins->ifTrueExpr()) == trueExprAndDest, |
| 1922 |
"true expr input is reused for output"); |
| 1923 |
|
| 1924 |
Assembler::Condition cond = Assembler::InvertCondition( |
| 1925 |
JSOpToCondition(ins->compareType(), ins->jsop())); |
| 1926 |
const LAllocation* rhs = ins->rightExpr(); |
| 1927 |
const LAllocation* falseExpr = ins->ifFalseExpr(); |
| 1928 |
Register lhs = ToRegister(ins->leftExpr()); |
| 1929 |
|
| 1930 |
masm.cmp32Move32(cond, lhs, ToRegister(rhs), ToRegister(falseExpr), |
| 1931 |
trueExprAndDest); |
| 1932 |
} |
| 1933 |
|
| 1934 |
void CodeGenerator::visitUDivOrMod(LUDivOrMod* ins) { |
| 1935 |
Register lhs = ToRegister(ins->lhs()); |
| 1936 |
Register rhs = ToRegister(ins->rhs()); |
| 1937 |
Register output = ToRegister(ins->output()); |
| 1938 |
Label done; |
| 1939 |
|
| 1940 |
// Prevent divide by zero. |
| 1941 |
if (ins->canBeDivideByZero()) { |
| 1942 |
if (ins->mir()->isTruncated()) { |
| 1943 |
if (ins->trapOnError()) { |
| 1944 |
Label nonZero; |
| 1945 |
masm.ma_b(rhs, rhs, &nonZero, Assembler::NonZero); |
| 1946 |
masm.wasmTrap(wasm::Trap::IntegerDivideByZero, ins->trapSiteDesc()); |
| 1947 |
masm.bind(&nonZero); |
| 1948 |
} else { |
| 1949 |
// Infinity|0 == 0 |
| 1950 |
Label notzero; |
| 1951 |
masm.ma_b(rhs, rhs, ¬zero, Assembler::NonZero, ShortJump); |
| 1952 |
masm.move32(Imm32(0), output); |
| 1953 |
masm.ma_b(&done, ShortJump); |
| 1954 |
masm.bind(¬zero); |
| 1955 |
} |
| 1956 |
} else { |
| 1957 |
bailoutCmp32(Assembler::Equal, rhs, Imm32(0), ins->snapshot()); |
| 1958 |
} |
| 1959 |
} |
| 1960 |
|
| 1961 |
masm.as_mod_wu(output, lhs, rhs); |
| 1962 |
|
| 1963 |
// If the remainder is > 0, bailout since this must be a double. |
| 1964 |
if (ins->mir()->isDiv()) { |
| 1965 |
if (!ins->mir()->toDiv()->canTruncateRemainder()) { |
| 1966 |
bailoutCmp32(Assembler::NonZero, output, output, ins->snapshot()); |
| 1967 |
} |
| 1968 |
// Get quotient |
| 1969 |
masm.as_div_wu(output, lhs, rhs); |
| 1970 |
} |
| 1971 |
|
| 1972 |
if (!ins->mir()->isTruncated()) { |
| 1973 |
bailoutCmp32(Assembler::LessThan, output, Imm32(0), ins->snapshot()); |
| 1974 |
} |
| 1975 |
|
| 1976 |
masm.bind(&done); |
| 1977 |
} |
| 1978 |
|
| 1979 |
void CodeGenerator::visitEffectiveAddress(LEffectiveAddress* ins) { |
| 1980 |
const MEffectiveAddress* mir = ins->mir(); |
| 1981 |
Register base = ToRegister(ins->base()); |
| 1982 |
Register index = ToRegister(ins->index()); |
| 1983 |
Register output = ToRegister(ins->output()); |
| 1984 |
int32_t shift = Imm32::ShiftOf(mir->scale()).value; |
| 1985 |
|
| 1986 |
if (shift) { |
| 1987 |
MOZ_ASSERT(shift <= 4); |
| 1988 |
masm.as_alsl_w(output, index, base, shift - 1); |
| 1989 |
} else { |
| 1990 |
masm.as_add_w(output, base, index); |
| 1991 |
} |
| 1992 |
masm.ma_add_w(output, output, Imm32(mir->displacement())); |
| 1993 |
} |
| 1994 |
|
| 1995 |
void CodeGenerator::visitNegI(LNegI* ins) { |
| 1996 |
Register input = ToRegister(ins->input()); |
| 1997 |
Register output = ToRegister(ins->output()); |
| 1998 |
|
| 1999 |
masm.as_sub_w(output, zero, input); |
| 2000 |
} |
| 2001 |
|
| 2002 |
void CodeGenerator::visitNegI64(LNegI64* ins) { |
| 2003 |
Register64 input = ToRegister64(ins->input()); |
| 2004 |
MOZ_ASSERT(input == ToOutRegister64(ins)); |
| 2005 |
masm.neg64(input); |
| 2006 |
} |
| 2007 |
|
| 2008 |
void CodeGenerator::visitNegD(LNegD* ins) { |
| 2009 |
FloatRegister input = ToFloatRegister(ins->input()); |
| 2010 |
FloatRegister output = ToFloatRegister(ins->output()); |
| 2011 |
|
| 2012 |
masm.as_fneg_d(output, input); |
| 2013 |
} |
| 2014 |
|
| 2015 |
void CodeGenerator::visitNegF(LNegF* ins) { |
| 2016 |
FloatRegister input = ToFloatRegister(ins->input()); |
| 2017 |
FloatRegister output = ToFloatRegister(ins->output()); |
| 2018 |
|
| 2019 |
masm.as_fneg_s(output, input); |
| 2020 |
} |
| 2021 |
|
| 2022 |
void CodeGenerator::visitWasmAddOffset(LWasmAddOffset* lir) { |
| 2023 |
MWasmAddOffset* mir = lir->mir(); |
| 2024 |
Register base = ToRegister(lir->base()); |
| 2025 |
Register out = ToRegister(lir->output()); |
| 2026 |
|
| 2027 |
Label ok; |
| 2028 |
masm.ma_add32TestCarry(Assembler::CarryClear, out, base, Imm32(mir->offset()), |
| 2029 |
&ok); |
| 2030 |
masm.wasmTrap(wasm::Trap::OutOfBounds, mir->trapSiteDesc()); |
| 2031 |
masm.bind(&ok); |
| 2032 |
} |
| 2033 |
|
| 2034 |
void CodeGenerator::visitWasmAddOffset64(LWasmAddOffset64* lir) { |
| 2035 |
MWasmAddOffset* mir = lir->mir(); |
| 2036 |
Register64 base = ToRegister64(lir->base()); |
| 2037 |
Register64 out = ToOutRegister64(lir); |
| 2038 |
|
| 2039 |
Label ok; |
| 2040 |
masm.ma_addPtrTestCarry(Assembler::CarryClear, out.reg, base.reg, |
| 2041 |
ImmWord(mir->offset()), &ok); |
| 2042 |
masm.wasmTrap(wasm::Trap::OutOfBounds, mir->trapSiteDesc()); |
| 2043 |
masm.bind(&ok); |
| 2044 |
} |
| 2045 |
|
| 2046 |
void CodeGenerator::visitAtomicTypedArrayElementBinop( |
| 2047 |
LAtomicTypedArrayElementBinop* lir) { |
| 2048 |
MOZ_ASSERT(!lir->mir()->isForEffect()); |
| 2049 |
|
| 2050 |
AnyRegister output = ToAnyRegister(lir->output()); |
| 2051 |
Register elements = ToRegister(lir->elements()); |
| 2052 |
Register outTemp = ToTempRegisterOrInvalid(lir->temp0()); |
| 2053 |
Register valueTemp = ToTempRegisterOrInvalid(lir->temp1()); |
| 2054 |
Register offsetTemp = ToTempRegisterOrInvalid(lir->temp2()); |
| 2055 |
Register maskTemp = ToTempRegisterOrInvalid(lir->temp3()); |
| 2056 |
Register value = ToRegister(lir->value()); |
| 2057 |
Scalar::Type arrayType = lir->mir()->arrayType(); |
| 2058 |
|
| 2059 |
if (lir->index()->isConstant()) { |
| 2060 |
Address mem = ToAddress(elements, lir->index(), arrayType); |
| 2061 |
masm.atomicFetchOpJS(arrayType, Synchronization::Full(), |
| 2062 |
lir->mir()->operation(), value, mem, valueTemp, |
| 2063 |
offsetTemp, maskTemp, outTemp, output); |
| 2064 |
} else { |
| 2065 |
BaseIndex mem(elements, ToRegister(lir->index()), |
| 2066 |
ScaleFromScalarType(arrayType)); |
| 2067 |
masm.atomicFetchOpJS(arrayType, Synchronization::Full(), |
| 2068 |
lir->mir()->operation(), value, mem, valueTemp, |
| 2069 |
offsetTemp, maskTemp, outTemp, output); |
| 2070 |
} |
| 2071 |
} |
| 2072 |
|
| 2073 |
void CodeGenerator::visitAtomicTypedArrayElementBinopForEffect( |
| 2074 |
LAtomicTypedArrayElementBinopForEffect* lir) { |
| 2075 |
MOZ_ASSERT(lir->mir()->isForEffect()); |
| 2076 |
|
| 2077 |
Register elements = ToRegister(lir->elements()); |
| 2078 |
Register valueTemp = ToTempRegisterOrInvalid(lir->temp0()); |
| 2079 |
Register offsetTemp = ToTempRegisterOrInvalid(lir->temp1()); |
| 2080 |
Register maskTemp = ToTempRegisterOrInvalid(lir->temp2()); |
| 2081 |
Register value = ToRegister(lir->value()); |
| 2082 |
Scalar::Type arrayType = lir->mir()->arrayType(); |
| 2083 |
|
| 2084 |
if (lir->index()->isConstant()) { |
| 2085 |
Address mem = ToAddress(elements, lir->index(), arrayType); |
| 2086 |
masm.atomicEffectOpJS(arrayType, Synchronization::Full(), |
| 2087 |
lir->mir()->operation(), value, mem, valueTemp, |
| 2088 |
offsetTemp, maskTemp); |
| 2089 |
} else { |
| 2090 |
BaseIndex mem(elements, ToRegister(lir->index()), |
| 2091 |
ScaleFromScalarType(arrayType)); |
| 2092 |
masm.atomicEffectOpJS(arrayType, Synchronization::Full(), |
| 2093 |
lir->mir()->operation(), value, mem, valueTemp, |
| 2094 |
offsetTemp, maskTemp); |
| 2095 |
} |
| 2096 |
} |
| 2097 |
|
| 2098 |
void CodeGenerator::visitCompareExchangeTypedArrayElement( |
| 2099 |
LCompareExchangeTypedArrayElement* lir) { |
| 2100 |
Register elements = ToRegister(lir->elements()); |
| 2101 |
AnyRegister output = ToAnyRegister(lir->output()); |
| 2102 |
Register outTemp = ToTempRegisterOrInvalid(lir->temp0()); |
| 2103 |
|
| 2104 |
Register oldval = ToRegister(lir->oldval()); |
| 2105 |
Register newval = ToRegister(lir->newval()); |
| 2106 |
Register valueTemp = ToTempRegisterOrInvalid(lir->temp1()); |
| 2107 |
Register offsetTemp = ToTempRegisterOrInvalid(lir->temp2()); |
| 2108 |
Register maskTemp = ToTempRegisterOrInvalid(lir->temp3()); |
| 2109 |
Scalar::Type arrayType = lir->mir()->arrayType(); |
| 2110 |
|
| 2111 |
if (lir->index()->isConstant()) { |
| 2112 |
Address dest = ToAddress(elements, lir->index(), arrayType); |
| 2113 |
masm.compareExchangeJS(arrayType, Synchronization::Full(), dest, oldval, |
| 2114 |
newval, valueTemp, offsetTemp, maskTemp, outTemp, |
| 2115 |
output); |
| 2116 |
} else { |
| 2117 |
BaseIndex dest(elements, ToRegister(lir->index()), |
| 2118 |
ScaleFromScalarType(arrayType)); |
| 2119 |
masm.compareExchangeJS(arrayType, Synchronization::Full(), dest, oldval, |
| 2120 |
newval, valueTemp, offsetTemp, maskTemp, outTemp, |
| 2121 |
output); |
| 2122 |
} |
| 2123 |
} |
| 2124 |
|
| 2125 |
void CodeGenerator::visitAtomicExchangeTypedArrayElement( |
| 2126 |
LAtomicExchangeTypedArrayElement* lir) { |
| 2127 |
Register elements = ToRegister(lir->elements()); |
| 2128 |
AnyRegister output = ToAnyRegister(lir->output()); |
| 2129 |
Register outTemp = ToTempRegisterOrInvalid(lir->temp0()); |
| 2130 |
|
| 2131 |
Register value = ToRegister(lir->value()); |
| 2132 |
Register valueTemp = ToTempRegisterOrInvalid(lir->temp1()); |
| 2133 |
Register offsetTemp = ToTempRegisterOrInvalid(lir->temp2()); |
| 2134 |
Register maskTemp = ToTempRegisterOrInvalid(lir->temp3()); |
| 2135 |
Scalar::Type arrayType = lir->mir()->arrayType(); |
| 2136 |
|
| 2137 |
if (lir->index()->isConstant()) { |
| 2138 |
Address dest = ToAddress(elements, lir->index(), arrayType); |
| 2139 |
masm.atomicExchangeJS(arrayType, Synchronization::Full(), dest, value, |
| 2140 |
valueTemp, offsetTemp, maskTemp, outTemp, output); |
| 2141 |
} else { |
| 2142 |
BaseIndex dest(elements, ToRegister(lir->index()), |
| 2143 |
ScaleFromScalarType(arrayType)); |
| 2144 |
masm.atomicExchangeJS(arrayType, Synchronization::Full(), dest, value, |
| 2145 |
valueTemp, offsetTemp, maskTemp, outTemp, output); |
| 2146 |
} |
| 2147 |
} |
| 2148 |
|
| 2149 |
void CodeGenerator::visitCompareExchangeTypedArrayElement64( |
| 2150 |
LCompareExchangeTypedArrayElement64* lir) { |
| 2151 |
Register elements = ToRegister(lir->elements()); |
| 2152 |
Register64 oldval = ToRegister64(lir->oldval()); |
| 2153 |
Register64 newval = ToRegister64(lir->newval()); |
| 2154 |
Register64 out = ToOutRegister64(lir); |
| 2155 |
Scalar::Type arrayType = lir->mir()->arrayType(); |
| 2156 |
|
| 2157 |
if (lir->index()->isConstant()) { |
| 2158 |
Address dest = ToAddress(elements, lir->index(), arrayType); |
| 2159 |
masm.compareExchange64(Synchronization::Full(), dest, oldval, newval, out); |
| 2160 |
} else { |
| 2161 |
BaseIndex dest(elements, ToRegister(lir->index()), |
| 2162 |
ScaleFromScalarType(arrayType)); |
| 2163 |
masm.compareExchange64(Synchronization::Full(), dest, oldval, newval, out); |
| 2164 |
} |
| 2165 |
} |
| 2166 |
|
| 2167 |
void CodeGenerator::visitAtomicExchangeTypedArrayElement64( |
| 2168 |
LAtomicExchangeTypedArrayElement64* lir) { |
| 2169 |
Register elements = ToRegister(lir->elements()); |
| 2170 |
Register64 value = ToRegister64(lir->value()); |
| 2171 |
Register64 out = ToOutRegister64(lir); |
| 2172 |
Scalar::Type arrayType = lir->mir()->arrayType(); |
| 2173 |
|
| 2174 |
if (lir->index()->isConstant()) { |
| 2175 |
Address dest = ToAddress(elements, lir->index(), arrayType); |
| 2176 |
masm.atomicExchange64(Synchronization::Full(), dest, value, out); |
| 2177 |
} else { |
| 2178 |
BaseIndex dest(elements, ToRegister(lir->index()), |
| 2179 |
ScaleFromScalarType(arrayType)); |
| 2180 |
masm.atomicExchange64(Synchronization::Full(), dest, value, out); |
| 2181 |
} |
| 2182 |
} |
| 2183 |
|
| 2184 |
void CodeGenerator::visitAtomicTypedArrayElementBinop64( |
| 2185 |
LAtomicTypedArrayElementBinop64* lir) { |
| 2186 |
MOZ_ASSERT(lir->mir()->hasUses()); |
| 2187 |
|
| 2188 |
Register elements = ToRegister(lir->elements()); |
| 2189 |
Register64 value = ToRegister64(lir->value()); |
| 2190 |
Register64 temp = ToRegister64(lir->temp0()); |
| 2191 |
Register64 out = ToOutRegister64(lir); |
| 2192 |
|
| 2193 |
Scalar::Type arrayType = lir->mir()->arrayType(); |
| 2194 |
AtomicOp atomicOp = lir->mir()->operation(); |
| 2195 |
|
| 2196 |
if (lir->index()->isConstant()) { |
| 2197 |
Address dest = ToAddress(elements, lir->index(), arrayType); |
| 2198 |
masm.atomicFetchOp64(Synchronization::Full(), atomicOp, value, dest, temp, |
| 2199 |
out); |
| 2200 |
} else { |
| 2201 |
BaseIndex dest(elements, ToRegister(lir->index()), |
| 2202 |
ScaleFromScalarType(arrayType)); |
| 2203 |
masm.atomicFetchOp64(Synchronization::Full(), atomicOp, value, dest, temp, |
| 2204 |
out); |
| 2205 |
} |
| 2206 |
} |
| 2207 |
|
| 2208 |
void CodeGenerator::visitAtomicTypedArrayElementBinopForEffect64( |
| 2209 |
LAtomicTypedArrayElementBinopForEffect64* lir) { |
| 2210 |
MOZ_ASSERT(!lir->mir()->hasUses()); |
| 2211 |
|
| 2212 |
Register elements = ToRegister(lir->elements()); |
| 2213 |
Register64 value = ToRegister64(lir->value()); |
| 2214 |
Register64 temp = ToRegister64(lir->temp0()); |
| 2215 |
|
| 2216 |
Scalar::Type arrayType = lir->mir()->arrayType(); |
| 2217 |
AtomicOp atomicOp = lir->mir()->operation(); |
| 2218 |
|
| 2219 |
if (lir->index()->isConstant()) { |
| 2220 |
Address dest = ToAddress(elements, lir->index(), arrayType); |
| 2221 |
masm.atomicEffectOp64(Synchronization::Full(), atomicOp, value, dest, temp); |
| 2222 |
} else { |
| 2223 |
BaseIndex dest(elements, ToRegister(lir->index()), |
| 2224 |
ScaleFromScalarType(arrayType)); |
| 2225 |
masm.atomicEffectOp64(Synchronization::Full(), atomicOp, value, dest, temp); |
| 2226 |
} |
| 2227 |
} |
| 2228 |
|
| 2229 |
void CodeGenerator::visitAtomicLoad64(LAtomicLoad64* lir) { |
| 2230 |
Register elements = ToRegister(lir->elements()); |
| 2231 |
Register64 out = ToOutRegister64(lir); |
| 2232 |
const MLoadUnboxedScalar* mir = lir->mir(); |
| 2233 |
|
| 2234 |
Scalar::Type storageType = mir->storageType(); |
| 2235 |
|
| 2236 |
auto sync = Synchronization::Load(); |
| 2237 |
masm.memoryBarrierBefore(sync); |
| 2238 |
if (lir->index()->isConstant()) { |
| 2239 |
Address source = |
| 2240 |
ToAddress(elements, lir->index(), storageType, mir->offsetAdjustment()); |
| 2241 |
masm.load64(source, out); |
| 2242 |
} else { |
| 2243 |
BaseIndex source(elements, ToRegister(lir->index()), |
| 2244 |
ScaleFromScalarType(storageType), mir->offsetAdjustment()); |
| 2245 |
masm.load64(source, out); |
| 2246 |
} |
| 2247 |
masm.memoryBarrierAfter(sync); |
| 2248 |
} |
| 2249 |
|
| 2250 |
void CodeGenerator::visitAtomicStore64(LAtomicStore64* lir) { |
| 2251 |
Register elements = ToRegister(lir->elements()); |
| 2252 |
Register64 value = ToRegister64(lir->value()); |
| 2253 |
|
| 2254 |
Scalar::Type writeType = lir->mir()->writeType(); |
| 2255 |
|
| 2256 |
auto sync = Synchronization::Store(); |
| 2257 |
masm.memoryBarrierBefore(sync); |
| 2258 |
if (lir->index()->isConstant()) { |
| 2259 |
Address dest = ToAddress(elements, lir->index(), writeType); |
| 2260 |
masm.store64(value, dest); |
| 2261 |
} else { |
| 2262 |
BaseIndex dest(elements, ToRegister(lir->index()), |
| 2263 |
ScaleFromScalarType(writeType)); |
| 2264 |
masm.store64(value, dest); |
| 2265 |
} |
| 2266 |
masm.memoryBarrierAfter(sync); |
| 2267 |
} |
| 2268 |
|
| 2269 |
void CodeGenerator::visitWasmCompareExchangeI64(LWasmCompareExchangeI64* lir) { |
| 2270 |
Register memoryBase = ToRegister(lir->memoryBase()); |
| 2271 |
Register ptr = ToRegister(lir->ptr()); |
| 2272 |
Register64 oldValue = ToRegister64(lir->oldValue()); |
| 2273 |
Register64 newValue = ToRegister64(lir->newValue()); |
| 2274 |
Register64 output = ToOutRegister64(lir); |
| 2275 |
uint32_t offset = lir->mir()->access().offset32(); |
| 2276 |
|
| 2277 |
BaseIndex addr(memoryBase, ptr, TimesOne, offset); |
| 2278 |
masm.wasmCompareExchange64(lir->mir()->access(), addr, oldValue, newValue, |
| 2279 |
output); |
| 2280 |
} |
| 2281 |
|
| 2282 |
void CodeGenerator::visitWasmAtomicExchangeI64(LWasmAtomicExchangeI64* lir) { |
| 2283 |
Register memoryBase = ToRegister(lir->memoryBase()); |
| 2284 |
Register ptr = ToRegister(lir->ptr()); |
| 2285 |
Register64 value = ToRegister64(lir->value()); |
| 2286 |
Register64 output = ToOutRegister64(lir); |
| 2287 |
uint32_t offset = lir->mir()->access().offset32(); |
| 2288 |
|
| 2289 |
BaseIndex addr(memoryBase, ptr, TimesOne, offset); |
| 2290 |
masm.wasmAtomicExchange64(lir->mir()->access(), addr, value, output); |
| 2291 |
} |
| 2292 |
|
| 2293 |
void CodeGenerator::visitWasmAtomicBinopI64(LWasmAtomicBinopI64* lir) { |
| 2294 |
Register memoryBase = ToRegister(lir->memoryBase()); |
| 2295 |
Register ptr = ToRegister(lir->ptr()); |
| 2296 |
Register64 value = ToRegister64(lir->value()); |
| 2297 |
Register64 output = ToOutRegister64(lir); |
| 2298 |
Register64 temp = ToRegister64(lir->temp0()); |
| 2299 |
uint32_t offset = lir->mir()->access().offset32(); |
| 2300 |
|
| 2301 |
BaseIndex addr(memoryBase, ptr, TimesOne, offset); |
| 2302 |
|
| 2303 |
masm.wasmAtomicFetchOp64(lir->mir()->access(), lir->mir()->operation(), value, |
| 2304 |
addr, temp, output); |
| 2305 |
} |
| 2306 |
|
| 2307 |
void CodeGenerator::visitNearbyInt(LNearbyInt*) { MOZ_CRASH("NYI"); } |
| 2308 |
|
| 2309 |
void CodeGenerator::visitNearbyIntF(LNearbyIntF*) { MOZ_CRASH("NYI"); } |
| 2310 |
|
| 2311 |
void CodeGenerator::visitSimd128(LSimd128* ins) { MOZ_CRASH("No SIMD"); } |
| 2312 |
|
| 2313 |
void CodeGenerator::visitWasmTernarySimd128(LWasmTernarySimd128* ins) { |
| 2314 |
MOZ_CRASH("No SIMD"); |
| 2315 |
} |
| 2316 |
|
| 2317 |
void CodeGenerator::visitWasmBinarySimd128(LWasmBinarySimd128* ins) { |
| 2318 |
MOZ_CRASH("No SIMD"); |
| 2319 |
} |
| 2320 |
|
| 2321 |
void CodeGenerator::visitWasmBinarySimd128WithConstant( |
| 2322 |
LWasmBinarySimd128WithConstant* ins) { |
| 2323 |
MOZ_CRASH("No SIMD"); |
| 2324 |
} |
| 2325 |
|
| 2326 |
void CodeGenerator::visitWasmVariableShiftSimd128( |
| 2327 |
LWasmVariableShiftSimd128* ins) { |
| 2328 |
MOZ_CRASH("No SIMD"); |
| 2329 |
} |
| 2330 |
|
| 2331 |
void CodeGenerator::visitWasmConstantShiftSimd128( |
| 2332 |
LWasmConstantShiftSimd128* ins) { |
| 2333 |
MOZ_CRASH("No SIMD"); |
| 2334 |
} |
| 2335 |
|
| 2336 |
void CodeGenerator::visitWasmSignReplicationSimd128( |
| 2337 |
LWasmSignReplicationSimd128* ins) { |
| 2338 |
MOZ_CRASH("No SIMD"); |
| 2339 |
} |
| 2340 |
|
| 2341 |
void CodeGenerator::visitWasmShuffleSimd128(LWasmShuffleSimd128* ins) { |
| 2342 |
MOZ_CRASH("No SIMD"); |
| 2343 |
} |
| 2344 |
|
| 2345 |
void CodeGenerator::visitWasmPermuteSimd128(LWasmPermuteSimd128* ins) { |
| 2346 |
MOZ_CRASH("No SIMD"); |
| 2347 |
} |
| 2348 |
|
| 2349 |
void CodeGenerator::visitWasmReplaceLaneSimd128(LWasmReplaceLaneSimd128* ins) { |
| 2350 |
MOZ_CRASH("No SIMD"); |
| 2351 |
} |
| 2352 |
|
| 2353 |
void CodeGenerator::visitWasmReplaceInt64LaneSimd128( |
| 2354 |
LWasmReplaceInt64LaneSimd128* ins) { |
| 2355 |
MOZ_CRASH("No SIMD"); |
| 2356 |
} |
| 2357 |
|
| 2358 |
void CodeGenerator::visitWasmScalarToSimd128(LWasmScalarToSimd128* ins) { |
| 2359 |
MOZ_CRASH("No SIMD"); |
| 2360 |
} |
| 2361 |
|
| 2362 |
void CodeGenerator::visitWasmInt64ToSimd128(LWasmInt64ToSimd128* ins) { |
| 2363 |
MOZ_CRASH("No SIMD"); |
| 2364 |
} |
| 2365 |
|
| 2366 |
void CodeGenerator::visitWasmUnarySimd128(LWasmUnarySimd128* ins) { |
| 2367 |
MOZ_CRASH("No SIMD"); |
| 2368 |
} |
| 2369 |
|
| 2370 |
void CodeGenerator::visitWasmReduceSimd128(LWasmReduceSimd128* ins) { |
| 2371 |
MOZ_CRASH("No SIMD"); |
| 2372 |
} |
| 2373 |
|
| 2374 |
void CodeGenerator::visitWasmReduceAndBranchSimd128( |
| 2375 |
LWasmReduceAndBranchSimd128* ins) { |
| 2376 |
MOZ_CRASH("No SIMD"); |
| 2377 |
} |
| 2378 |
|
| 2379 |
void CodeGenerator::visitWasmReduceSimd128ToInt64( |
| 2380 |
LWasmReduceSimd128ToInt64* ins) { |
| 2381 |
MOZ_CRASH("No SIMD"); |
| 2382 |
} |
| 2383 |
|
| 2384 |
void CodeGenerator::visitWasmLoadLaneSimd128(LWasmLoadLaneSimd128* ins) { |
| 2385 |
MOZ_CRASH("No SIMD"); |
| 2386 |
} |
| 2387 |
|
| 2388 |
void CodeGenerator::visitWasmStoreLaneSimd128(LWasmStoreLaneSimd128* ins) { |
| 2389 |
MOZ_CRASH("No SIMD"); |
| 2390 |
} |