| 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/x64/CodeGenerator-x64.h" |
| 8 |
|
| 9 |
#include "mozilla/CheckedInt.h" |
| 10 |
#include "mozilla/FloatingPoint.h" |
| 11 |
|
| 12 |
#include "jit/CodeGenerator.h" |
| 13 |
#include "jit/MIR-wasm.h" |
| 14 |
#include "jit/MIR.h" |
| 15 |
#include "js/ScalarType.h" // js::Scalar::Type |
| 16 |
|
| 17 |
#include "jit/MacroAssembler-inl.h" |
| 18 |
#include "jit/shared/CodeGenerator-shared-inl.h" |
| 19 |
|
| 20 |
using namespace js; |
| 21 |
using namespace js::jit; |
| 22 |
|
| 23 |
using mozilla::DebugOnly; |
| 24 |
|
| 25 |
CodeGeneratorX64::CodeGeneratorX64(MIRGenerator* gen, LIRGraph* graph, |
| 26 |
MacroAssembler* masm, |
| 27 |
const wasm::CodeMetadata* wasmCodeMeta) |
| 28 |
: CodeGeneratorX86Shared(gen, graph, masm, wasmCodeMeta) {} |
| 29 |
|
| 30 |
Operand CodeGeneratorX64::ToOperand64(const LInt64Allocation& a64) { |
| 31 |
const LAllocation& a = a64.value(); |
| 32 |
MOZ_ASSERT(!a.isFloatReg()); |
| 33 |
if (a.isGeneralReg()) { |
| 34 |
return Operand(a.toGeneralReg()->reg()); |
| 35 |
} |
| 36 |
return Operand(ToAddress(a)); |
| 37 |
} |
| 38 |
|
| 39 |
void CodeGenerator::visitBox(LBox* box) { |
| 40 |
const LAllocation* in = box->payload(); |
| 41 |
ValueOperand result = ToOutValue(box); |
| 42 |
|
| 43 |
masm.moveValue(TypedOrValueRegister(box->type(), ToAnyRegister(in)), result); |
| 44 |
|
| 45 |
if (JitOptions.spectreValueMasking && IsFloatingPointType(box->type())) { |
| 46 |
ScratchRegisterScope scratch(masm); |
| 47 |
masm.movePtr(ImmWord(JSVAL_SHIFTED_TAG_MAX_DOUBLE), scratch); |
| 48 |
masm.cmpPtrMovePtr(Assembler::Below, scratch, result.valueReg(), scratch, |
| 49 |
result.valueReg()); |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
void CodeGenerator::visitUnbox(LUnbox* unbox) { |
| 54 |
MUnbox* mir = unbox->mir(); |
| 55 |
|
| 56 |
Register result = ToRegister(unbox->output()); |
| 57 |
|
| 58 |
if (mir->fallible()) { |
| 59 |
ValueOperand value = ToValue(unbox->input()); |
| 60 |
Label bail; |
| 61 |
switch (mir->type()) { |
| 62 |
case MIRType::Int32: |
| 63 |
masm.fallibleUnboxInt32(value, result, &bail); |
| 64 |
break; |
| 65 |
case MIRType::Boolean: |
| 66 |
masm.fallibleUnboxBoolean(value, result, &bail); |
| 67 |
break; |
| 68 |
case MIRType::Object: |
| 69 |
masm.fallibleUnboxObject(value, result, &bail); |
| 70 |
break; |
| 71 |
case MIRType::String: |
| 72 |
masm.fallibleUnboxString(value, result, &bail); |
| 73 |
break; |
| 74 |
case MIRType::Symbol: |
| 75 |
masm.fallibleUnboxSymbol(value, result, &bail); |
| 76 |
break; |
| 77 |
case MIRType::BigInt: |
| 78 |
masm.fallibleUnboxBigInt(value, result, &bail); |
| 79 |
break; |
| 80 |
default: |
| 81 |
MOZ_CRASH("Given MIRType cannot be unboxed."); |
| 82 |
} |
| 83 |
bailoutFrom(&bail, unbox->snapshot()); |
| 84 |
return; |
| 85 |
} |
| 86 |
|
| 87 |
// Infallible unbox. |
| 88 |
|
| 89 |
Operand input = ToOperand(unbox->getOperand(LUnbox::Input)); |
| 90 |
|
| 91 |
#ifdef DEBUG |
| 92 |
// Assert the types match. |
| 93 |
JSValueTag tag = MIRTypeToTag(mir->type()); |
| 94 |
Label ok; |
| 95 |
masm.splitTag(input, ScratchReg); |
| 96 |
masm.branch32(Assembler::Equal, ScratchReg, Imm32(tag), &ok); |
| 97 |
masm.assumeUnreachable("Infallible unbox type mismatch"); |
| 98 |
masm.bind(&ok); |
| 99 |
#endif |
| 100 |
|
| 101 |
switch (mir->type()) { |
| 102 |
case MIRType::Int32: |
| 103 |
masm.unboxInt32(input, result); |
| 104 |
break; |
| 105 |
case MIRType::Boolean: |
| 106 |
masm.unboxBoolean(input, result); |
| 107 |
break; |
| 108 |
case MIRType::Object: |
| 109 |
masm.unboxObject(input, result); |
| 110 |
break; |
| 111 |
case MIRType::String: |
| 112 |
masm.unboxString(input, result); |
| 113 |
break; |
| 114 |
case MIRType::Symbol: |
| 115 |
masm.unboxSymbol(input, result); |
| 116 |
break; |
| 117 |
case MIRType::BigInt: |
| 118 |
masm.unboxBigInt(input, result); |
| 119 |
break; |
| 120 |
default: |
| 121 |
MOZ_CRASH("Given MIRType cannot be unboxed."); |
| 122 |
} |
| 123 |
} |
| 124 |
|
| 125 |
void CodeGenerator::visitDivOrModI64(LDivOrModI64* lir) { |
| 126 |
Register lhs = ToRegister(lir->lhs()); |
| 127 |
Register rhs = ToRegister(lir->rhs()); |
| 128 |
Register output = ToRegister(lir->output()); |
| 129 |
|
| 130 |
MOZ_ASSERT_IF(lhs != rhs, rhs != rax); |
| 131 |
MOZ_ASSERT(rhs != rdx); |
| 132 |
MOZ_ASSERT_IF(output == rax, ToRegister(lir->remainder()) == rdx); |
| 133 |
MOZ_ASSERT_IF(output == rdx, ToRegister(lir->remainder()) == rax); |
| 134 |
|
| 135 |
Label done; |
| 136 |
|
| 137 |
// Put the lhs in rax. |
| 138 |
if (lhs != rax) { |
| 139 |
masm.mov(lhs, rax); |
| 140 |
} |
| 141 |
|
| 142 |
// Handle divide by zero. |
| 143 |
if (lir->canBeDivideByZero()) { |
| 144 |
Label nonZero; |
| 145 |
masm.branchTestPtr(Assembler::NonZero, rhs, rhs, &nonZero); |
| 146 |
masm.wasmTrap(wasm::Trap::IntegerDivideByZero, lir->trapSiteDesc()); |
| 147 |
masm.bind(&nonZero); |
| 148 |
} |
| 149 |
|
| 150 |
// Handle an integer overflow exception from INT64_MIN / -1. |
| 151 |
if (lir->canBeNegativeOverflow()) { |
| 152 |
Label notOverflow; |
| 153 |
masm.branchPtr(Assembler::NotEqual, lhs, ImmWord(INT64_MIN), ¬Overflow); |
| 154 |
masm.branchPtr(Assembler::NotEqual, rhs, ImmWord(-1), ¬Overflow); |
| 155 |
if (lir->mir()->isMod()) { |
| 156 |
masm.xorl(output, output); |
| 157 |
} else { |
| 158 |
masm.wasmTrap(wasm::Trap::IntegerOverflow, lir->trapSiteDesc()); |
| 159 |
} |
| 160 |
masm.jump(&done); |
| 161 |
masm.bind(¬Overflow); |
| 162 |
} |
| 163 |
|
| 164 |
// Sign extend the lhs into rdx to make rdx:rax. |
| 165 |
masm.cqo(); |
| 166 |
masm.idivq(rhs); |
| 167 |
|
| 168 |
masm.bind(&done); |
| 169 |
} |
| 170 |
|
| 171 |
void CodeGenerator::visitUDivOrModI64(LUDivOrModI64* lir) { |
| 172 |
Register lhs = ToRegister(lir->lhs()); |
| 173 |
Register rhs = ToRegister(lir->rhs()); |
| 174 |
|
| 175 |
DebugOnly<Register> output = ToRegister(lir->output()); |
| 176 |
MOZ_ASSERT_IF(lhs != rhs, rhs != rax); |
| 177 |
MOZ_ASSERT(rhs != rdx); |
| 178 |
MOZ_ASSERT_IF(output.value == rax, ToRegister(lir->remainder()) == rdx); |
| 179 |
MOZ_ASSERT_IF(output.value == rdx, ToRegister(lir->remainder()) == rax); |
| 180 |
|
| 181 |
// Put the lhs in rax. |
| 182 |
if (lhs != rax) { |
| 183 |
masm.mov(lhs, rax); |
| 184 |
} |
| 185 |
|
| 186 |
Label done; |
| 187 |
|
| 188 |
// Prevent divide by zero. |
| 189 |
if (lir->canBeDivideByZero()) { |
| 190 |
Label nonZero; |
| 191 |
masm.branchTestPtr(Assembler::NonZero, rhs, rhs, &nonZero); |
| 192 |
masm.wasmTrap(wasm::Trap::IntegerDivideByZero, lir->trapSiteDesc()); |
| 193 |
masm.bind(&nonZero); |
| 194 |
} |
| 195 |
|
| 196 |
// Zero extend the lhs into rdx to make (rdx:rax). |
| 197 |
masm.xorl(rdx, rdx); |
| 198 |
masm.udivq(rhs); |
| 199 |
|
| 200 |
masm.bind(&done); |
| 201 |
} |
| 202 |
|
| 203 |
void CodeGeneratorX64::emitBigIntPtrDiv(LBigIntPtrDiv* ins, Register dividend, |
| 204 |
Register divisor, Register output) { |
| 205 |
// Callers handle division by zero and integer overflow. |
| 206 |
|
| 207 |
MOZ_ASSERT(ToRegister(ins->temp0()) == rdx); |
| 208 |
MOZ_ASSERT(output == rax); |
| 209 |
|
| 210 |
if (dividend != rax) { |
| 211 |
masm.movePtr(dividend, rax); |
| 212 |
} |
| 213 |
|
| 214 |
// Sign extend the lhs into rdx to make rdx:rax. |
| 215 |
masm.cqo(); |
| 216 |
|
| 217 |
masm.idivq(divisor); |
| 218 |
} |
| 219 |
|
| 220 |
void CodeGeneratorX64::emitBigIntPtrMod(LBigIntPtrMod* ins, Register dividend, |
| 221 |
Register divisor, Register output) { |
| 222 |
// Callers handle division by zero and integer overflow. |
| 223 |
|
| 224 |
MOZ_ASSERT(dividend == rax); |
| 225 |
MOZ_ASSERT(output == rdx); |
| 226 |
|
| 227 |
// Sign extend the lhs into rdx to make rdx:rax. |
| 228 |
masm.cqo(); |
| 229 |
|
| 230 |
masm.idivq(divisor); |
| 231 |
} |
| 232 |
|
| 233 |
void CodeGenerator::visitAtomicLoad64(LAtomicLoad64* lir) { |
| 234 |
Register elements = ToRegister(lir->elements()); |
| 235 |
Register64 out = ToOutRegister64(lir); |
| 236 |
|
| 237 |
const MLoadUnboxedScalar* mir = lir->mir(); |
| 238 |
|
| 239 |
Scalar::Type storageType = mir->storageType(); |
| 240 |
|
| 241 |
// NOTE: the generated code must match the assembly code in gen_load in |
| 242 |
// GenerateAtomicOperations.py |
| 243 |
auto sync = Synchronization::Load(); |
| 244 |
|
| 245 |
masm.memoryBarrierBefore(sync); |
| 246 |
if (lir->index()->isConstant()) { |
| 247 |
Address source = |
| 248 |
ToAddress(elements, lir->index(), storageType, mir->offsetAdjustment()); |
| 249 |
masm.load64(source, out); |
| 250 |
} else { |
| 251 |
BaseIndex source(elements, ToRegister(lir->index()), |
| 252 |
ScaleFromScalarType(storageType), mir->offsetAdjustment()); |
| 253 |
masm.load64(source, out); |
| 254 |
} |
| 255 |
masm.memoryBarrierAfter(sync); |
| 256 |
} |
| 257 |
|
| 258 |
void CodeGenerator::visitAtomicStore64(LAtomicStore64* lir) { |
| 259 |
Register elements = ToRegister(lir->elements()); |
| 260 |
Register64 value = ToRegister64(lir->value()); |
| 261 |
|
| 262 |
Scalar::Type writeType = lir->mir()->writeType(); |
| 263 |
|
| 264 |
// NOTE: the generated code must match the assembly code in gen_store in |
| 265 |
// GenerateAtomicOperations.py |
| 266 |
auto sync = Synchronization::Store(); |
| 267 |
|
| 268 |
masm.memoryBarrierBefore(sync); |
| 269 |
if (lir->index()->isConstant()) { |
| 270 |
Address dest = ToAddress(elements, lir->index(), writeType); |
| 271 |
masm.store64(value, dest); |
| 272 |
} else { |
| 273 |
BaseIndex dest(elements, ToRegister(lir->index()), |
| 274 |
ScaleFromScalarType(writeType)); |
| 275 |
masm.store64(value, dest); |
| 276 |
} |
| 277 |
masm.memoryBarrierAfter(sync); |
| 278 |
} |
| 279 |
|
| 280 |
void CodeGenerator::visitCompareExchangeTypedArrayElement64( |
| 281 |
LCompareExchangeTypedArrayElement64* lir) { |
| 282 |
Register elements = ToRegister(lir->elements()); |
| 283 |
Register64 oldval = ToRegister64(lir->oldval()); |
| 284 |
Register64 newval = ToRegister64(lir->newval()); |
| 285 |
Register64 out = ToOutRegister64(lir); |
| 286 |
|
| 287 |
MOZ_ASSERT(out.reg == rax); |
| 288 |
|
| 289 |
Scalar::Type arrayType = lir->mir()->arrayType(); |
| 290 |
|
| 291 |
if (lir->index()->isConstant()) { |
| 292 |
Address dest = ToAddress(elements, lir->index(), arrayType); |
| 293 |
masm.compareExchange64(Synchronization::Full(), dest, oldval, newval, out); |
| 294 |
} else { |
| 295 |
BaseIndex dest(elements, ToRegister(lir->index()), |
| 296 |
ScaleFromScalarType(arrayType)); |
| 297 |
masm.compareExchange64(Synchronization::Full(), dest, oldval, newval, out); |
| 298 |
} |
| 299 |
} |
| 300 |
|
| 301 |
void CodeGenerator::visitAtomicExchangeTypedArrayElement64( |
| 302 |
LAtomicExchangeTypedArrayElement64* lir) { |
| 303 |
Register elements = ToRegister(lir->elements()); |
| 304 |
Register64 value = ToRegister64(lir->value()); |
| 305 |
Register64 out = ToOutRegister64(lir); |
| 306 |
|
| 307 |
Scalar::Type arrayType = lir->mir()->arrayType(); |
| 308 |
|
| 309 |
if (lir->index()->isConstant()) { |
| 310 |
Address dest = ToAddress(elements, lir->index(), arrayType); |
| 311 |
masm.atomicExchange64(Synchronization::Full(), dest, value, out); |
| 312 |
} else { |
| 313 |
BaseIndex dest(elements, ToRegister(lir->index()), |
| 314 |
ScaleFromScalarType(arrayType)); |
| 315 |
masm.atomicExchange64(Synchronization::Full(), dest, value, out); |
| 316 |
} |
| 317 |
} |
| 318 |
|
| 319 |
void CodeGenerator::visitAtomicTypedArrayElementBinop64( |
| 320 |
LAtomicTypedArrayElementBinop64* lir) { |
| 321 |
MOZ_ASSERT(!lir->mir()->isForEffect()); |
| 322 |
|
| 323 |
Register elements = ToRegister(lir->elements()); |
| 324 |
Register64 value = ToRegister64(lir->value()); |
| 325 |
Register64 temp = ToTempRegister64OrInvalid(lir->temp0()); |
| 326 |
Register64 out = ToOutRegister64(lir); |
| 327 |
|
| 328 |
Scalar::Type arrayType = lir->mir()->arrayType(); |
| 329 |
AtomicOp atomicOp = lir->mir()->operation(); |
| 330 |
|
| 331 |
// Add and Sub don't need |temp| and can save a `mov` when the value and |
| 332 |
// output register are equal to each other. |
| 333 |
if (atomicOp == AtomicOp::Add || atomicOp == AtomicOp::Sub) { |
| 334 |
MOZ_ASSERT(temp == Register64::Invalid()); |
| 335 |
MOZ_ASSERT(value == out); |
| 336 |
} else { |
| 337 |
MOZ_ASSERT(out.reg == rax); |
| 338 |
} |
| 339 |
|
| 340 |
if (lir->index()->isConstant()) { |
| 341 |
Address dest = ToAddress(elements, lir->index(), arrayType); |
| 342 |
masm.atomicFetchOp64(Synchronization::Full(), atomicOp, value, dest, temp, |
| 343 |
out); |
| 344 |
} else { |
| 345 |
BaseIndex dest(elements, ToRegister(lir->index()), |
| 346 |
ScaleFromScalarType(arrayType)); |
| 347 |
masm.atomicFetchOp64(Synchronization::Full(), atomicOp, value, dest, temp, |
| 348 |
out); |
| 349 |
} |
| 350 |
} |
| 351 |
|
| 352 |
void CodeGenerator::visitAtomicTypedArrayElementBinopForEffect64( |
| 353 |
LAtomicTypedArrayElementBinopForEffect64* lir) { |
| 354 |
MOZ_ASSERT(lir->mir()->isForEffect()); |
| 355 |
|
| 356 |
Register elements = ToRegister(lir->elements()); |
| 357 |
Register64 value = ToRegister64(lir->value()); |
| 358 |
|
| 359 |
Scalar::Type arrayType = lir->mir()->arrayType(); |
| 360 |
AtomicOp atomicOp = lir->mir()->operation(); |
| 361 |
|
| 362 |
if (lir->index()->isConstant()) { |
| 363 |
Address dest = ToAddress(elements, lir->index(), arrayType); |
| 364 |
masm.atomicEffectOp64(Synchronization::Full(), atomicOp, value, dest); |
| 365 |
} else { |
| 366 |
BaseIndex dest(elements, ToRegister(lir->index()), |
| 367 |
ScaleFromScalarType(arrayType)); |
| 368 |
masm.atomicEffectOp64(Synchronization::Full(), atomicOp, value, dest); |
| 369 |
} |
| 370 |
} |
| 371 |
|
| 372 |
void CodeGenerator::visitWasmSelectI64(LWasmSelectI64* lir) { |
| 373 |
MOZ_ASSERT(lir->mir()->type() == MIRType::Int64); |
| 374 |
|
| 375 |
Register cond = ToRegister(lir->condExpr()); |
| 376 |
|
| 377 |
Operand falseExpr = ToOperandOrRegister64(lir->falseExpr()); |
| 378 |
|
| 379 |
Register64 out = ToOutRegister64(lir); |
| 380 |
MOZ_ASSERT(ToRegister64(lir->trueExpr()) == out, |
| 381 |
"true expr is reused for input"); |
| 382 |
|
| 383 |
masm.test32(cond, cond); |
| 384 |
masm.cmovzq(falseExpr, out.reg); |
| 385 |
} |
| 386 |
|
| 387 |
// We expect to handle only the cases: compare is {U,}Int{32,64}, and select |
| 388 |
// is {U,}Int{32,64}, independently. Some values may be stack allocated, and |
| 389 |
// the "true" input is reused for the output. |
| 390 |
void CodeGenerator::visitWasmCompareAndSelect(LWasmCompareAndSelect* ins) { |
| 391 |
bool cmpIs32bit = ins->compareType() == MCompare::Compare_Int32 || |
| 392 |
ins->compareType() == MCompare::Compare_UInt32; |
| 393 |
bool cmpIs64bit = ins->compareType() == MCompare::Compare_Int64 || |
| 394 |
ins->compareType() == MCompare::Compare_UInt64; |
| 395 |
bool selIs32bit = ins->mir()->type() == MIRType::Int32; |
| 396 |
bool selIs64bit = ins->mir()->type() == MIRType::Int64; |
| 397 |
|
| 398 |
// Throw out unhandled cases |
| 399 |
MOZ_RELEASE_ASSERT( |
| 400 |
cmpIs32bit != cmpIs64bit && selIs32bit != selIs64bit, |
| 401 |
"CodeGenerator::visitWasmCompareAndSelect: unexpected types"); |
| 402 |
|
| 403 |
using C = Assembler::Condition; |
| 404 |
using R = Register; |
| 405 |
using A = const Address&; |
| 406 |
|
| 407 |
// Identify macroassembler methods to generate instructions, based on the |
| 408 |
// type of the comparison and the select. This avoids having to duplicate |
| 409 |
// the code-generation tree below 4 times. These assignments to |
| 410 |
// `cmpMove_CRRRR` et al are unambiguous as a result of the combination of |
| 411 |
// the template parameters and the 5 argument types ((C, R, R, R, R) etc). |
| 412 |
void (MacroAssembler::*cmpMove_CRRRR)(C, R, R, R, R) = nullptr; |
| 413 |
void (MacroAssembler::*cmpMove_CRARR)(C, R, A, R, R) = nullptr; |
| 414 |
void (MacroAssembler::*cmpLoad_CRRAR)(C, R, R, A, R) = nullptr; |
| 415 |
void (MacroAssembler::*cmpLoad_CRAAR)(C, R, A, A, R) = nullptr; |
| 416 |
|
| 417 |
if (cmpIs32bit) { |
| 418 |
if (selIs32bit) { |
| 419 |
cmpMove_CRRRR = &MacroAssemblerX64::cmpMove<32, 32>; |
| 420 |
cmpMove_CRARR = &MacroAssemblerX64::cmpMove<32, 32>; |
| 421 |
cmpLoad_CRRAR = &MacroAssemblerX64::cmpLoad<32, 32>; |
| 422 |
cmpLoad_CRAAR = &MacroAssemblerX64::cmpLoad<32, 32>; |
| 423 |
} else { |
| 424 |
cmpMove_CRRRR = &MacroAssemblerX64::cmpMove<32, 64>; |
| 425 |
cmpMove_CRARR = &MacroAssemblerX64::cmpMove<32, 64>; |
| 426 |
cmpLoad_CRRAR = &MacroAssemblerX64::cmpLoad<32, 64>; |
| 427 |
cmpLoad_CRAAR = &MacroAssemblerX64::cmpLoad<32, 64>; |
| 428 |
} |
| 429 |
} else { |
| 430 |
if (selIs32bit) { |
| 431 |
cmpMove_CRRRR = &MacroAssemblerX64::cmpMove<64, 32>; |
| 432 |
cmpMove_CRARR = &MacroAssemblerX64::cmpMove<64, 32>; |
| 433 |
cmpLoad_CRRAR = &MacroAssemblerX64::cmpLoad<64, 32>; |
| 434 |
cmpLoad_CRAAR = &MacroAssemblerX64::cmpLoad<64, 32>; |
| 435 |
} else { |
| 436 |
cmpMove_CRRRR = &MacroAssemblerX64::cmpMove<64, 64>; |
| 437 |
cmpMove_CRARR = &MacroAssemblerX64::cmpMove<64, 64>; |
| 438 |
cmpLoad_CRRAR = &MacroAssemblerX64::cmpLoad<64, 64>; |
| 439 |
cmpLoad_CRAAR = &MacroAssemblerX64::cmpLoad<64, 64>; |
| 440 |
} |
| 441 |
} |
| 442 |
|
| 443 |
Register trueExprAndDest = ToRegister(ins->output()); |
| 444 |
MOZ_ASSERT(ToRegister(ins->ifTrueExpr()) == trueExprAndDest, |
| 445 |
"true expr input is reused for output"); |
| 446 |
|
| 447 |
Assembler::Condition cond = Assembler::InvertCondition( |
| 448 |
JSOpToCondition(ins->compareType(), ins->jsop())); |
| 449 |
const LAllocation* rhs = ins->rightExpr(); |
| 450 |
const LAllocation* falseExpr = ins->ifFalseExpr(); |
| 451 |
Register lhs = ToRegister(ins->leftExpr()); |
| 452 |
|
| 453 |
// We generate one of four cmp+cmov pairings, depending on whether one of |
| 454 |
// the cmp args and one of the cmov args is in memory or a register. |
| 455 |
if (rhs->isGeneralReg()) { |
| 456 |
if (falseExpr->isGeneralReg()) { |
| 457 |
(masm.*cmpMove_CRRRR)(cond, lhs, ToRegister(rhs), ToRegister(falseExpr), |
| 458 |
trueExprAndDest); |
| 459 |
} else { |
| 460 |
(masm.*cmpLoad_CRRAR)(cond, lhs, ToRegister(rhs), ToAddress(falseExpr), |
| 461 |
trueExprAndDest); |
| 462 |
} |
| 463 |
} else { |
| 464 |
if (falseExpr->isGeneralReg()) { |
| 465 |
(masm.*cmpMove_CRARR)(cond, lhs, ToAddress(rhs), ToRegister(falseExpr), |
| 466 |
trueExprAndDest); |
| 467 |
} else { |
| 468 |
(masm.*cmpLoad_CRAAR)(cond, lhs, ToAddress(rhs), ToAddress(falseExpr), |
| 469 |
trueExprAndDest); |
| 470 |
} |
| 471 |
} |
| 472 |
} |
| 473 |
|
| 474 |
void CodeGenerator::visitWasmUint32ToDouble(LWasmUint32ToDouble* lir) { |
| 475 |
masm.convertUInt32ToDouble(ToRegister(lir->input()), |
| 476 |
ToFloatRegister(lir->output())); |
| 477 |
} |
| 478 |
|
| 479 |
void CodeGenerator::visitWasmUint32ToFloat32(LWasmUint32ToFloat32* lir) { |
| 480 |
masm.convertUInt32ToFloat32(ToRegister(lir->input()), |
| 481 |
ToFloatRegister(lir->output())); |
| 482 |
} |
| 483 |
|
| 484 |
void CodeGeneratorX64::wasmStore(const wasm::MemoryAccessDesc& access, |
| 485 |
const LAllocation* value, Operand dstAddr) { |
| 486 |
if (value->isConstant()) { |
| 487 |
masm.memoryBarrierBefore(access.sync()); |
| 488 |
|
| 489 |
const MConstant* mir = value->toConstant(); |
| 490 |
Imm32 cst = |
| 491 |
Imm32(mir->type() == MIRType::Int32 ? mir->toInt32() : mir->toInt64()); |
| 492 |
|
| 493 |
switch (access.type()) { |
| 494 |
case Scalar::Int8: |
| 495 |
case Scalar::Uint8: |
| 496 |
masm.append(access, wasm::TrapMachineInsn::Store8, |
| 497 |
FaultingCodeOffset(masm.currentOffset())); |
| 498 |
masm.movb(cst, dstAddr); |
| 499 |
break; |
| 500 |
case Scalar::Int16: |
| 501 |
case Scalar::Uint16: |
| 502 |
masm.append(access, wasm::TrapMachineInsn::Store16, |
| 503 |
FaultingCodeOffset(masm.currentOffset())); |
| 504 |
masm.movw(cst, dstAddr); |
| 505 |
break; |
| 506 |
case Scalar::Int32: |
| 507 |
case Scalar::Uint32: |
| 508 |
masm.append(access, wasm::TrapMachineInsn::Store32, |
| 509 |
FaultingCodeOffset(masm.currentOffset())); |
| 510 |
masm.movl(cst, dstAddr); |
| 511 |
break; |
| 512 |
case Scalar::Int64: |
| 513 |
MOZ_ASSERT_IF(mir->type() == MIRType::Int64, |
| 514 |
mozilla::CheckedInt32(mir->toInt64()).isValid()); |
| 515 |
masm.append(access, wasm::TrapMachineInsn::Store64, |
| 516 |
FaultingCodeOffset(masm.currentOffset())); |
| 517 |
masm.movq(cst, dstAddr); |
| 518 |
break; |
| 519 |
case Scalar::Simd128: |
| 520 |
case Scalar::Float16: |
| 521 |
case Scalar::Float32: |
| 522 |
case Scalar::Float64: |
| 523 |
case Scalar::Uint8Clamped: |
| 524 |
case Scalar::BigInt64: |
| 525 |
case Scalar::BigUint64: |
| 526 |
case Scalar::MaxTypedArrayViewType: |
| 527 |
MOZ_CRASH("unexpected array type"); |
| 528 |
} |
| 529 |
|
| 530 |
masm.memoryBarrierAfter(access.sync()); |
| 531 |
} else { |
| 532 |
masm.wasmStore(access, ToAnyRegister(value), dstAddr); |
| 533 |
} |
| 534 |
} |
| 535 |
|
| 536 |
template <typename T> |
| 537 |
void CodeGeneratorX64::emitWasmLoad(T* ins) { |
| 538 |
const MWasmLoad* mir = ins->mir(); |
| 539 |
|
| 540 |
mir->access().assertOffsetInGuardPages(); |
| 541 |
uint32_t offset = mir->access().offset32(); |
| 542 |
|
| 543 |
// ptr is a GPR and is either a 32-bit value zero-extended to 64-bit, or a |
| 544 |
// true 64-bit value. |
| 545 |
const LAllocation* ptr = ins->ptr(); |
| 546 |
Register memoryBase = ToRegister(ins->memoryBase()); |
| 547 |
Operand srcAddr = |
| 548 |
ptr->isBogus() ? Operand(memoryBase, offset) |
| 549 |
: Operand(memoryBase, ToRegister(ptr), TimesOne, offset); |
| 550 |
|
| 551 |
if (mir->type() == MIRType::Int64) { |
| 552 |
masm.wasmLoadI64(mir->access(), srcAddr, ToOutRegister64(ins)); |
| 553 |
} else { |
| 554 |
masm.wasmLoad(mir->access(), srcAddr, ToAnyRegister(ins->output())); |
| 555 |
} |
| 556 |
} |
| 557 |
|
| 558 |
void CodeGenerator::visitWasmLoad(LWasmLoad* ins) { emitWasmLoad(ins); } |
| 559 |
|
| 560 |
void CodeGenerator::visitWasmLoadI64(LWasmLoadI64* ins) { emitWasmLoad(ins); } |
| 561 |
|
| 562 |
template <typename T> |
| 563 |
void CodeGeneratorX64::emitWasmStore(T* ins) { |
| 564 |
const MWasmStore* mir = ins->mir(); |
| 565 |
const wasm::MemoryAccessDesc& access = mir->access(); |
| 566 |
|
| 567 |
mir->access().assertOffsetInGuardPages(); |
| 568 |
uint32_t offset = access.offset32(); |
| 569 |
|
| 570 |
const LAllocation* value = ins->value(); |
| 571 |
const LAllocation* ptr = ins->ptr(); |
| 572 |
Register memoryBase = ToRegister(ins->memoryBase()); |
| 573 |
Operand dstAddr = |
| 574 |
ptr->isBogus() ? Operand(memoryBase, offset) |
| 575 |
: Operand(memoryBase, ToRegister(ptr), TimesOne, offset); |
| 576 |
|
| 577 |
wasmStore(access, value, dstAddr); |
| 578 |
} |
| 579 |
|
| 580 |
void CodeGenerator::visitWasmStore(LWasmStore* ins) { emitWasmStore(ins); } |
| 581 |
|
| 582 |
void CodeGenerator::visitWasmStoreI64(LWasmStoreI64* ins) { |
| 583 |
MOZ_CRASH("Unused on this platform"); |
| 584 |
} |
| 585 |
|
| 586 |
void CodeGenerator::visitWasmCompareExchangeHeap( |
| 587 |
LWasmCompareExchangeHeap* ins) { |
| 588 |
MWasmCompareExchangeHeap* mir = ins->mir(); |
| 589 |
|
| 590 |
Register ptr = ToRegister(ins->ptr()); |
| 591 |
Register oldval = ToRegister(ins->oldValue()); |
| 592 |
Register newval = ToRegister(ins->newValue()); |
| 593 |
Register memoryBase = ToRegister(ins->memoryBase()); |
| 594 |
|
| 595 |
Scalar::Type accessType = mir->access().type(); |
| 596 |
BaseIndex srcAddr(memoryBase, ptr, TimesOne, mir->access().offset32()); |
| 597 |
|
| 598 |
if (accessType == Scalar::Int64) { |
| 599 |
masm.wasmCompareExchange64(mir->access(), srcAddr, Register64(oldval), |
| 600 |
Register64(newval), ToOutRegister64(ins)); |
| 601 |
} else { |
| 602 |
masm.wasmCompareExchange(mir->access(), srcAddr, oldval, newval, |
| 603 |
ToRegister(ins->output())); |
| 604 |
} |
| 605 |
} |
| 606 |
|
| 607 |
void CodeGenerator::visitWasmAtomicExchangeHeap(LWasmAtomicExchangeHeap* ins) { |
| 608 |
MWasmAtomicExchangeHeap* mir = ins->mir(); |
| 609 |
|
| 610 |
Register ptr = ToRegister(ins->ptr()); |
| 611 |
Register value = ToRegister(ins->value()); |
| 612 |
Register memoryBase = ToRegister(ins->memoryBase()); |
| 613 |
|
| 614 |
Scalar::Type accessType = mir->access().type(); |
| 615 |
|
| 616 |
BaseIndex srcAddr(memoryBase, ptr, TimesOne, mir->access().offset32()); |
| 617 |
|
| 618 |
if (accessType == Scalar::Int64) { |
| 619 |
masm.wasmAtomicExchange64(mir->access(), srcAddr, Register64(value), |
| 620 |
ToOutRegister64(ins)); |
| 621 |
} else { |
| 622 |
masm.wasmAtomicExchange(mir->access(), srcAddr, value, |
| 623 |
ToRegister(ins->output())); |
| 624 |
} |
| 625 |
} |
| 626 |
|
| 627 |
void CodeGenerator::visitWasmAtomicBinopHeap(LWasmAtomicBinopHeap* ins) { |
| 628 |
MWasmAtomicBinopHeap* mir = ins->mir(); |
| 629 |
MOZ_ASSERT(mir->hasUses()); |
| 630 |
|
| 631 |
Register ptr = ToRegister(ins->ptr()); |
| 632 |
Register memoryBase = ToRegister(ins->memoryBase()); |
| 633 |
const LAllocation* value = ins->value(); |
| 634 |
Register temp = ToTempRegisterOrInvalid(ins->temp0()); |
| 635 |
Register output = ToRegister(ins->output()); |
| 636 |
|
| 637 |
Scalar::Type accessType = mir->access().type(); |
| 638 |
if (accessType == Scalar::Uint32) { |
| 639 |
accessType = Scalar::Int32; |
| 640 |
} |
| 641 |
|
| 642 |
AtomicOp op = mir->operation(); |
| 643 |
BaseIndex srcAddr(memoryBase, ptr, TimesOne, mir->access().offset32()); |
| 644 |
|
| 645 |
if (accessType == Scalar::Int64) { |
| 646 |
Register64 val = Register64(ToRegister(value)); |
| 647 |
Register64 out = Register64(output); |
| 648 |
Register64 tmp = Register64(temp); |
| 649 |
masm.wasmAtomicFetchOp64(mir->access(), op, val, srcAddr, tmp, out); |
| 650 |
} else if (value->isConstant()) { |
| 651 |
masm.wasmAtomicFetchOp(mir->access(), op, Imm32(ToInt32(value)), srcAddr, |
| 652 |
temp, output); |
| 653 |
} else { |
| 654 |
masm.wasmAtomicFetchOp(mir->access(), op, ToRegister(value), srcAddr, temp, |
| 655 |
output); |
| 656 |
} |
| 657 |
} |
| 658 |
|
| 659 |
void CodeGenerator::visitWasmAtomicBinopHeapForEffect( |
| 660 |
LWasmAtomicBinopHeapForEffect* ins) { |
| 661 |
MWasmAtomicBinopHeap* mir = ins->mir(); |
| 662 |
MOZ_ASSERT(!mir->hasUses()); |
| 663 |
|
| 664 |
Register ptr = ToRegister(ins->ptr()); |
| 665 |
Register memoryBase = ToRegister(ins->memoryBase()); |
| 666 |
const LAllocation* value = ins->value(); |
| 667 |
|
| 668 |
Scalar::Type accessType = mir->access().type(); |
| 669 |
AtomicOp op = mir->operation(); |
| 670 |
|
| 671 |
BaseIndex srcAddr(memoryBase, ptr, TimesOne, mir->access().offset32()); |
| 672 |
|
| 673 |
if (accessType == Scalar::Int64) { |
| 674 |
Register64 val = Register64(ToRegister(value)); |
| 675 |
masm.wasmAtomicEffectOp64(mir->access(), op, val, srcAddr); |
| 676 |
} else if (value->isConstant()) { |
| 677 |
Imm32 c(0); |
| 678 |
if (value->toConstant()->type() == MIRType::Int64) { |
| 679 |
c = Imm32(ToInt64(value)); |
| 680 |
} else { |
| 681 |
c = Imm32(ToInt32(value)); |
| 682 |
} |
| 683 |
masm.wasmAtomicEffectOp(mir->access(), op, c, srcAddr, InvalidReg); |
| 684 |
} else { |
| 685 |
masm.wasmAtomicEffectOp(mir->access(), op, ToRegister(value), srcAddr, |
| 686 |
InvalidReg); |
| 687 |
} |
| 688 |
} |
| 689 |
|
| 690 |
class js::jit::OutOfLineTruncate : public OutOfLineCodeBase<CodeGeneratorX64> { |
| 691 |
FloatRegister input_; |
| 692 |
Register output_; |
| 693 |
Register temp_; |
| 694 |
|
| 695 |
public: |
| 696 |
OutOfLineTruncate(FloatRegister input, Register output, Register temp) |
| 697 |
: input_(input), output_(output), temp_(temp) {} |
| 698 |
|
| 699 |
void accept(CodeGeneratorX64* codegen) override { |
| 700 |
codegen->visitOutOfLineTruncate(this); |
| 701 |
} |
| 702 |
|
| 703 |
FloatRegister input() const { return input_; } |
| 704 |
Register output() const { return output_; } |
| 705 |
Register temp() const { return temp_; } |
| 706 |
}; |
| 707 |
|
| 708 |
void CodeGeneratorX64::visitOutOfLineTruncate(OutOfLineTruncate* ool) { |
| 709 |
FloatRegister input = ool->input(); |
| 710 |
Register output = ool->output(); |
| 711 |
Register temp = ool->temp(); |
| 712 |
|
| 713 |
// Inline implementation of `JS::ToInt32(double)` for double values whose |
| 714 |
// exponent is ≥63. |
| 715 |
|
| 716 |
#ifdef DEBUG |
| 717 |
Label ok; |
| 718 |
masm.branchTruncateDoubleMaybeModUint32(input, output, &ok); |
| 719 |
masm.assumeUnreachable("OOL path only used when vcvttsd2sq failed"); |
| 720 |
masm.bind(&ok); |
| 721 |
#endif |
| 722 |
|
| 723 |
constexpr uint32_t ShiftedExponentBits = |
| 724 |
mozilla::FloatingPoint<double>::kExponentBits >> |
| 725 |
mozilla::FloatingPoint<double>::kExponentShift; |
| 726 |
static_assert(ShiftedExponentBits == 0x7ff); |
| 727 |
|
| 728 |
constexpr uint32_t ExponentBiasAndShift = |
| 729 |
mozilla::FloatingPoint<double>::kExponentBias + |
| 730 |
mozilla::FloatingPoint<double>::kExponentShift; |
| 731 |
static_assert(ExponentBiasAndShift == (1023 + 52)); |
| 732 |
|
| 733 |
constexpr size_t ResultWidth = CHAR_BIT * sizeof(int32_t); |
| 734 |
|
| 735 |
// Extract the bit representation of |input|. |
| 736 |
masm.moveDoubleToGPR64(input, Register64(output)); |
| 737 |
|
| 738 |
// Extract the exponent. |
| 739 |
masm.rshiftPtr(Imm32(mozilla::FloatingPoint<double>::kExponentShift), output, |
| 740 |
temp); |
| 741 |
masm.and32(Imm32(ShiftedExponentBits), temp); |
| 742 |
#ifdef DEBUG |
| 743 |
// The biased exponent must be at least `1023 + 63`, because otherwise |
| 744 |
// vcvttsd2sq wouldn't have failed. |
| 745 |
constexpr uint32_t MinBiasedExponent = |
| 746 |
mozilla::FloatingPoint<double>::kExponentBias + 63; |
| 747 |
|
| 748 |
Label exponentOk; |
| 749 |
masm.branch32(Assembler::GreaterThanOrEqual, temp, Imm32(MinBiasedExponent), |
| 750 |
&exponentOk); |
| 751 |
masm.assumeUnreachable("exponent is greater-than-or-equals to 63"); |
| 752 |
masm.bind(&exponentOk); |
| 753 |
#endif |
| 754 |
masm.sub32(Imm32(ExponentBiasAndShift), temp); |
| 755 |
|
| 756 |
// If the exponent is greater than or equal to |ResultWidth|, the number is |
| 757 |
// either infinite, NaN, or too large to have lower-order bits. We have to |
| 758 |
// return zero in this case. |
| 759 |
{ |
| 760 |
ScratchRegisterScope scratch(masm); |
| 761 |
masm.movePtr(ImmWord(0), scratch); |
| 762 |
masm.cmp32MovePtr(Assembler::AboveOrEqual, temp, Imm32(ResultWidth), |
| 763 |
scratch, output); |
| 764 |
} |
| 765 |
|
| 766 |
// Negate if the sign bit is set. |
| 767 |
{ |
| 768 |
ScratchRegisterScope scratch(masm); |
| 769 |
masm.movePtr(output, scratch); |
| 770 |
masm.negPtr(scratch); |
| 771 |
masm.testPtr(output, output); |
| 772 |
masm.cmovCCq(Assembler::Signed, scratch, output); |
| 773 |
} |
| 774 |
|
| 775 |
// The significand contains the bits that will determine the final result. |
| 776 |
// Shift those bits left by the exponent value in |temp|. |
| 777 |
masm.lshift32(temp, output); |
| 778 |
|
| 779 |
// Return from OOL path. |
| 780 |
masm.jump(ool->rejoin()); |
| 781 |
} |
| 782 |
|
| 783 |
void CodeGenerator::visitTruncateDToInt32(LTruncateDToInt32* ins) { |
| 784 |
FloatRegister input = ToFloatRegister(ins->input()); |
| 785 |
Register output = ToRegister(ins->output()); |
| 786 |
Register temp = ToRegister(ins->temp0()); |
| 787 |
|
| 788 |
auto* ool = new (alloc()) OutOfLineTruncate(input, output, temp); |
| 789 |
addOutOfLineCode(ool, ins->mir()); |
| 790 |
|
| 791 |
masm.branchTruncateDoubleMaybeModUint32(input, output, ool->entry()); |
| 792 |
masm.bind(ool->rejoin()); |
| 793 |
} |
| 794 |
|
| 795 |
void CodeGenerator::visitWasmBuiltinTruncateDToInt32( |
| 796 |
LWasmBuiltinTruncateDToInt32* lir) { |
| 797 |
FloatRegister input = ToFloatRegister(lir->input()); |
| 798 |
Register output = ToRegister(lir->output()); |
| 799 |
Register temp = ToRegister(lir->temp0()); |
| 800 |
MOZ_ASSERT(lir->instance()->isBogus(), "instance not used for x64"); |
| 801 |
|
| 802 |
auto* ool = new (alloc()) OutOfLineTruncate(input, output, temp); |
| 803 |
addOutOfLineCode(ool, lir->mir()); |
| 804 |
|
| 805 |
masm.branchTruncateDoubleMaybeModUint32(input, output, ool->entry()); |
| 806 |
masm.bind(ool->rejoin()); |
| 807 |
} |
| 808 |
|
| 809 |
void CodeGenerator::visitWasmBuiltinTruncateFToInt32( |
| 810 |
LWasmBuiltinTruncateFToInt32* lir) { |
| 811 |
FloatRegister input = ToFloatRegister(lir->input()); |
| 812 |
Register output = ToRegister(lir->output()); |
| 813 |
MOZ_ASSERT(lir->instance()->isBogus(), "instance not used for x64"); |
| 814 |
|
| 815 |
masm.truncateFloat32ModUint32(input, output); |
| 816 |
} |
| 817 |
|
| 818 |
void CodeGenerator::visitTruncateFToInt32(LTruncateFToInt32* ins) { |
| 819 |
FloatRegister input = ToFloatRegister(ins->input()); |
| 820 |
Register output = ToRegister(ins->output()); |
| 821 |
|
| 822 |
masm.truncateFloat32ModUint32(input, output); |
| 823 |
} |
| 824 |
|
| 825 |
void CodeGenerator::visitWrapInt64ToInt32(LWrapInt64ToInt32* lir) { |
| 826 |
LInt64Allocation input = lir->input(); |
| 827 |
Register output = ToRegister(lir->output()); |
| 828 |
|
| 829 |
if (lir->mir()->bottomHalf()) { |
| 830 |
if (input.value().isMemory()) { |
| 831 |
masm.load32(ToAddress(input), output); |
| 832 |
} else { |
| 833 |
masm.move64To32(ToRegister64(input), output); |
| 834 |
} |
| 835 |
} else { |
| 836 |
MOZ_CRASH("Not implemented."); |
| 837 |
} |
| 838 |
} |
| 839 |
|
| 840 |
void CodeGenerator::visitExtendInt32ToInt64(LExtendInt32ToInt64* lir) { |
| 841 |
const LAllocation* input = lir->input(); |
| 842 |
Register output = ToRegister(lir->output()); |
| 843 |
|
| 844 |
if (lir->mir()->isUnsigned()) { |
| 845 |
masm.movl(ToOperand(input), output); |
| 846 |
} else { |
| 847 |
masm.movslq(ToOperand(input), output); |
| 848 |
} |
| 849 |
} |
| 850 |
|
| 851 |
void CodeGenerator::visitWasmExtendU32Index(LWasmExtendU32Index* lir) { |
| 852 |
// Generates no code on this platform because the input is assumed to have |
| 853 |
// canonical form. |
| 854 |
Register output = ToRegister(lir->output()); |
| 855 |
MOZ_ASSERT(ToRegister(lir->input()) == output); |
| 856 |
masm.debugAssertCanonicalInt32(output); |
| 857 |
} |
| 858 |
|
| 859 |
void CodeGenerator::visitWasmWrapU32Index(LWasmWrapU32Index* lir) { |
| 860 |
// Generates no code on this platform because the input is assumed to have |
| 861 |
// canonical form. |
| 862 |
Register output = ToRegister(lir->output()); |
| 863 |
MOZ_ASSERT(ToRegister(lir->input()) == output); |
| 864 |
masm.debugAssertCanonicalInt32(output); |
| 865 |
} |
| 866 |
|
| 867 |
void CodeGenerator::visitSignExtendInt64(LSignExtendInt64* ins) { |
| 868 |
Register64 input = ToRegister64(ins->input()); |
| 869 |
Register64 output = ToOutRegister64(ins); |
| 870 |
switch (ins->mir()->mode()) { |
| 871 |
case MSignExtendInt64::Byte: |
| 872 |
masm.movsbq(Operand(input.reg), output.reg); |
| 873 |
break; |
| 874 |
case MSignExtendInt64::Half: |
| 875 |
masm.movswq(Operand(input.reg), output.reg); |
| 876 |
break; |
| 877 |
case MSignExtendInt64::Word: |
| 878 |
masm.movslq(Operand(input.reg), output.reg); |
| 879 |
break; |
| 880 |
} |
| 881 |
} |
| 882 |
|
| 883 |
void CodeGenerator::visitWasmTruncateToInt64(LWasmTruncateToInt64* lir) { |
| 884 |
FloatRegister input = ToFloatRegister(lir->input()); |
| 885 |
Register64 output = ToOutRegister64(lir); |
| 886 |
|
| 887 |
MWasmTruncateToInt64* mir = lir->mir(); |
| 888 |
MIRType inputType = mir->input()->type(); |
| 889 |
|
| 890 |
MOZ_ASSERT(inputType == MIRType::Double || inputType == MIRType::Float32); |
| 891 |
|
| 892 |
auto* ool = new (alloc()) OutOfLineWasmTruncateCheck(mir, input, output); |
| 893 |
addOutOfLineCode(ool, mir); |
| 894 |
|
| 895 |
FloatRegister temp = |
| 896 |
mir->isUnsigned() ? ToFloatRegister(lir->temp0()) : InvalidFloatReg; |
| 897 |
|
| 898 |
Label* oolEntry = ool->entry(); |
| 899 |
Label* oolRejoin = ool->rejoin(); |
| 900 |
bool isSaturating = mir->isSaturating(); |
| 901 |
if (inputType == MIRType::Double) { |
| 902 |
if (mir->isUnsigned()) { |
| 903 |
masm.wasmTruncateDoubleToUInt64(input, output, isSaturating, oolEntry, |
| 904 |
oolRejoin, temp); |
| 905 |
} else { |
| 906 |
masm.wasmTruncateDoubleToInt64(input, output, isSaturating, oolEntry, |
| 907 |
oolRejoin, temp); |
| 908 |
} |
| 909 |
} else { |
| 910 |
if (mir->isUnsigned()) { |
| 911 |
masm.wasmTruncateFloat32ToUInt64(input, output, isSaturating, oolEntry, |
| 912 |
oolRejoin, temp); |
| 913 |
} else { |
| 914 |
masm.wasmTruncateFloat32ToInt64(input, output, isSaturating, oolEntry, |
| 915 |
oolRejoin, temp); |
| 916 |
} |
| 917 |
} |
| 918 |
} |
| 919 |
|
| 920 |
void CodeGenerator::visitInt64ToFloatingPoint(LInt64ToFloatingPoint* lir) { |
| 921 |
Register64 input = ToRegister64(lir->input()); |
| 922 |
FloatRegister output = ToFloatRegister(lir->output()); |
| 923 |
Register temp = ToTempRegisterOrInvalid(lir->temp0()); |
| 924 |
|
| 925 |
MInt64ToFloatingPoint* mir = lir->mir(); |
| 926 |
bool isUnsigned = mir->isUnsigned(); |
| 927 |
|
| 928 |
MIRType outputType = mir->type(); |
| 929 |
MOZ_ASSERT(outputType == MIRType::Double || outputType == MIRType::Float32); |
| 930 |
MOZ_ASSERT(isUnsigned == (temp != InvalidReg)); |
| 931 |
|
| 932 |
if (outputType == MIRType::Double) { |
| 933 |
if (isUnsigned) { |
| 934 |
masm.convertUInt64ToDouble(input, output, temp); |
| 935 |
} else { |
| 936 |
masm.convertInt64ToDouble(input, output); |
| 937 |
} |
| 938 |
} else { |
| 939 |
if (isUnsigned) { |
| 940 |
masm.convertUInt64ToFloat32(input, output, temp); |
| 941 |
} else { |
| 942 |
masm.convertInt64ToFloat32(input, output); |
| 943 |
} |
| 944 |
} |
| 945 |
} |
| 946 |
|
| 947 |
void CodeGenerator::visitBitNotI64(LBitNotI64* ins) { |
| 948 |
LInt64Allocation input = ins->input(); |
| 949 |
MOZ_ASSERT(!IsConstant(input)); |
| 950 |
Register64 inputR = ToRegister64(input); |
| 951 |
MOZ_ASSERT(inputR == ToOutRegister64(ins)); |
| 952 |
masm.notq(inputR.reg); |
| 953 |
} |