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