| 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 |
#ifndef jit_x64_MacroAssembler_x64_h |
| 8 |
#define jit_x64_MacroAssembler_x64_h |
| 9 |
|
| 10 |
#include "jit/x86-shared/MacroAssembler-x86-shared.h" |
| 11 |
#include "js/HeapAPI.h" |
| 12 |
#include "wasm/WasmBuiltins.h" |
| 13 |
|
| 14 |
namespace js { |
| 15 |
namespace jit { |
| 16 |
|
| 17 |
struct ImmShiftedTag : public ImmWord { |
| 18 |
explicit ImmShiftedTag(JSValueType type) |
| 19 |
: ImmWord(uintptr_t(JSVAL_TYPE_TO_SHIFTED_TAG(type))) {} |
| 20 |
}; |
| 21 |
|
| 22 |
struct ImmTag : public Imm32 { |
| 23 |
explicit ImmTag(JSValueTag tag) : Imm32(tag) {} |
| 24 |
}; |
| 25 |
|
| 26 |
// ScratchTagScope and ScratchTagScopeRelease are used to manage the tag |
| 27 |
// register for splitTagForTest(), which has different register management on |
| 28 |
// different platforms. On 64-bit platforms it requires a scratch register that |
| 29 |
// does not interfere with other operations; on 32-bit platforms it uses a |
| 30 |
// register that is already part of the Value. |
| 31 |
// |
| 32 |
// The ScratchTagScope RAII type acquires the appropriate register; a reference |
| 33 |
// to a variable of this type is then passed to splitTagForTest(). |
| 34 |
// |
| 35 |
// On 64-bit platforms ScratchTagScopeRelease makes the owned scratch register |
| 36 |
// available in a dynamic scope during compilation. However it is important to |
| 37 |
// remember that that does not preserve the register value in any way, so this |
| 38 |
// RAII type should only be used along paths that eventually branch past further |
| 39 |
// uses of the extracted tag value. |
| 40 |
// |
| 41 |
// On 32-bit platforms ScratchTagScopeRelease has no effect, since it does not |
| 42 |
// manage a register, it only aliases a register in the ValueOperand. |
| 43 |
|
| 44 |
class ScratchTagScope : public ScratchRegisterScope { |
| 45 |
public: |
| 46 |
ScratchTagScope(MacroAssembler& masm, const ValueOperand&) |
| 47 |
: ScratchRegisterScope(masm) {} |
| 48 |
}; |
| 49 |
|
| 50 |
class ScratchTagScopeRelease { |
| 51 |
ScratchTagScope* ts_; |
| 52 |
|
| 53 |
public: |
| 54 |
explicit ScratchTagScopeRelease(ScratchTagScope* ts) : ts_(ts) { |
| 55 |
ts_->release(); |
| 56 |
} |
| 57 |
~ScratchTagScopeRelease() { ts_->reacquire(); } |
| 58 |
}; |
| 59 |
|
| 60 |
class MacroAssemblerX64 : public MacroAssemblerX86Shared { |
| 61 |
private: |
| 62 |
// Perform a downcast. Should be removed by Bug 996602. |
| 63 |
MacroAssembler& asMasm(); |
| 64 |
const MacroAssembler& asMasm() const; |
| 65 |
|
| 66 |
void bindOffsets(const MacroAssemblerX86Shared::UsesVector&); |
| 67 |
|
| 68 |
void vpRiprOpSimd128(const SimdConstant& v, FloatRegister reg, |
| 69 |
JmpSrc (X86Encoding::BaseAssemblerX64::*op)( |
| 70 |
X86Encoding::XMMRegisterID id)); |
| 71 |
|
| 72 |
void vpRiprOpSimd128(const SimdConstant& v, FloatRegister lhs, |
| 73 |
FloatRegister dest, |
| 74 |
JmpSrc (X86Encoding::BaseAssemblerX64::*op)( |
| 75 |
X86Encoding::XMMRegisterID srcId, |
| 76 |
X86Encoding::XMMRegisterID destId)); |
| 77 |
|
| 78 |
protected: |
| 79 |
void flexibleDivMod64(Register rhs, Register lhsOutput, bool isUnsigned, |
| 80 |
bool isDiv); |
| 81 |
|
| 82 |
public: |
| 83 |
using MacroAssemblerX86Shared::load32; |
| 84 |
using MacroAssemblerX86Shared::store16; |
| 85 |
using MacroAssemblerX86Shared::store32; |
| 86 |
|
| 87 |
MacroAssemblerX64() = default; |
| 88 |
|
| 89 |
// The buffer is about to be linked, make sure any constant pools or excess |
| 90 |
// bookkeeping has been flushed to the instruction stream. |
| 91 |
void finish(); |
| 92 |
|
| 93 |
///////////////////////////////////////////////////////////////// |
| 94 |
// X64 helpers. |
| 95 |
///////////////////////////////////////////////////////////////// |
| 96 |
void writeDataRelocation(const Value& val) { |
| 97 |
// Raw GC pointer relocations and Value relocations both end up in |
| 98 |
// Assembler::TraceDataRelocations. |
| 99 |
if (val.isGCThing()) { |
| 100 |
gc::Cell* cell = val.toGCThing(); |
| 101 |
if (cell && gc::IsInsideNursery(cell)) { |
| 102 |
embedsNurseryPointers_ = true; |
| 103 |
} |
| 104 |
dataRelocations_.writeUnsigned(masm.currentOffset()); |
| 105 |
} |
| 106 |
} |
| 107 |
|
| 108 |
// Refers to the upper 32 bits of a 64-bit Value operand. |
| 109 |
// On x86_64, the upper 32 bits do not necessarily only contain the type. |
| 110 |
Operand ToUpper32(Operand base) { |
| 111 |
switch (base.kind()) { |
| 112 |
case Operand::MEM_REG_DISP: |
| 113 |
return Operand(Register::FromCode(base.base()), base.disp() + 4); |
| 114 |
|
| 115 |
case Operand::MEM_SCALE: |
| 116 |
return Operand(Register::FromCode(base.base()), |
| 117 |
Register::FromCode(base.index()), base.scale(), |
| 118 |
base.disp() + 4); |
| 119 |
|
| 120 |
default: |
| 121 |
MOZ_CRASH("unexpected operand kind"); |
| 122 |
} |
| 123 |
} |
| 124 |
static inline Operand ToUpper32(const Address& address) { |
| 125 |
return Operand(address.base, address.offset + 4); |
| 126 |
} |
| 127 |
static inline Operand ToUpper32(const BaseIndex& address) { |
| 128 |
return Operand(address.base, address.index, address.scale, |
| 129 |
address.offset + 4); |
| 130 |
} |
| 131 |
|
| 132 |
uint32_t Upper32Of(JSValueShiftedTag tag) { return uint32_t(tag >> 32); } |
| 133 |
|
| 134 |
JSValueShiftedTag GetShiftedTag(JSValueType type) { |
| 135 |
return (JSValueShiftedTag)JSVAL_TYPE_TO_SHIFTED_TAG(type); |
| 136 |
} |
| 137 |
|
| 138 |
///////////////////////////////////////////////////////////////// |
| 139 |
// X86/X64-common interface. |
| 140 |
///////////////////////////////////////////////////////////////// |
| 141 |
|
| 142 |
void storeValue(ValueOperand val, Operand dest) { |
| 143 |
movq(val.valueReg(), dest); |
| 144 |
} |
| 145 |
void storeValue(ValueOperand val, const Address& dest) { |
| 146 |
storeValue(val, Operand(dest)); |
| 147 |
} |
| 148 |
template <typename T> |
| 149 |
void storeValue(JSValueType type, Register reg, const T& dest) { |
| 150 |
ScratchRegisterScope scratch(asMasm()); |
| 151 |
boxValue(type, reg, scratch); |
| 152 |
movq(scratch, Operand(dest)); |
| 153 |
} |
| 154 |
template <typename T> |
| 155 |
void storeValue(const Value& val, const T& dest) { |
| 156 |
ScratchRegisterScope scratch(asMasm()); |
| 157 |
if (val.isGCThing()) { |
| 158 |
movWithPatch(ImmWord(val.asRawBits()), scratch); |
| 159 |
writeDataRelocation(val); |
| 160 |
} else { |
| 161 |
mov(ImmWord(val.asRawBits()), scratch); |
| 162 |
} |
| 163 |
movq(scratch, Operand(dest)); |
| 164 |
} |
| 165 |
void storeValue(ValueOperand val, BaseIndex dest) { |
| 166 |
storeValue(val, Operand(dest)); |
| 167 |
} |
| 168 |
void storeValue(const Address& src, const Address& dest, Register temp) { |
| 169 |
loadPtr(src, temp); |
| 170 |
storePtr(temp, dest); |
| 171 |
} |
| 172 |
void storePrivateValue(Register src, const Address& dest) { |
| 173 |
storePtr(src, dest); |
| 174 |
} |
| 175 |
void storePrivateValue(ImmGCPtr imm, const Address& dest) { |
| 176 |
storePtr(imm, dest); |
| 177 |
} |
| 178 |
void loadValue(Operand src, ValueOperand val) { movq(src, val.valueReg()); } |
| 179 |
void loadValue(Address src, ValueOperand val) { |
| 180 |
loadValue(Operand(src), val); |
| 181 |
} |
| 182 |
void loadValue(const BaseIndex& src, ValueOperand val) { |
| 183 |
loadValue(Operand(src), val); |
| 184 |
} |
| 185 |
void loadUnalignedValue(const Address& src, ValueOperand dest) { |
| 186 |
loadValue(src, dest); |
| 187 |
} |
| 188 |
void tagValue(JSValueType type, Register payload, ValueOperand dest) { |
| 189 |
ScratchRegisterScope scratch(asMasm()); |
| 190 |
MOZ_ASSERT(dest.valueReg() != scratch); |
| 191 |
if (payload != dest.valueReg()) { |
| 192 |
movq(payload, dest.valueReg()); |
| 193 |
} |
| 194 |
mov(ImmShiftedTag(type), scratch); |
| 195 |
orq(scratch, dest.valueReg()); |
| 196 |
} |
| 197 |
void pushValue(ValueOperand val) { push(val.valueReg()); } |
| 198 |
void popValue(ValueOperand val) { pop(val.valueReg()); } |
| 199 |
void pushValue(const Value& val) { |
| 200 |
if (val.isGCThing()) { |
| 201 |
ScratchRegisterScope scratch(asMasm()); |
| 202 |
movWithPatch(ImmWord(val.asRawBits()), scratch); |
| 203 |
writeDataRelocation(val); |
| 204 |
push(scratch); |
| 205 |
} else { |
| 206 |
push(ImmWord(val.asRawBits())); |
| 207 |
} |
| 208 |
} |
| 209 |
void pushValue(JSValueType type, Register reg) { |
| 210 |
ScratchRegisterScope scratch(asMasm()); |
| 211 |
boxValue(type, reg, scratch); |
| 212 |
push(scratch); |
| 213 |
} |
| 214 |
void pushValue(const Address& addr) { push(Operand(addr)); } |
| 215 |
|
| 216 |
void pushValue(const BaseIndex& addr, Register scratch) { |
| 217 |
push(Operand(addr)); |
| 218 |
} |
| 219 |
|
| 220 |
void boxValue(JSValueType type, Register src, Register dest); |
| 221 |
|
| 222 |
Condition testUndefined(Condition cond, Register tag) { |
| 223 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 224 |
cmp32(tag, ImmTag(JSVAL_TAG_UNDEFINED)); |
| 225 |
return cond; |
| 226 |
} |
| 227 |
Condition testInt32(Condition cond, Register tag) { |
| 228 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 229 |
cmp32(tag, ImmTag(JSVAL_TAG_INT32)); |
| 230 |
return cond; |
| 231 |
} |
| 232 |
Condition testBoolean(Condition cond, Register tag) { |
| 233 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 234 |
cmp32(tag, ImmTag(JSVAL_TAG_BOOLEAN)); |
| 235 |
return cond; |
| 236 |
} |
| 237 |
Condition testNull(Condition cond, Register tag) { |
| 238 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 239 |
cmp32(tag, ImmTag(JSVAL_TAG_NULL)); |
| 240 |
return cond; |
| 241 |
} |
| 242 |
Condition testString(Condition cond, Register tag) { |
| 243 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 244 |
cmp32(tag, ImmTag(JSVAL_TAG_STRING)); |
| 245 |
return cond; |
| 246 |
} |
| 247 |
Condition testSymbol(Condition cond, Register tag) { |
| 248 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 249 |
cmp32(tag, ImmTag(JSVAL_TAG_SYMBOL)); |
| 250 |
return cond; |
| 251 |
} |
| 252 |
Condition testBigInt(Condition cond, Register tag) { |
| 253 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 254 |
cmp32(tag, ImmTag(JSVAL_TAG_BIGINT)); |
| 255 |
return cond; |
| 256 |
} |
| 257 |
Condition testObject(Condition cond, Register tag) { |
| 258 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 259 |
cmp32(tag, ImmTag(JSVAL_TAG_OBJECT)); |
| 260 |
return cond; |
| 261 |
} |
| 262 |
Condition testDouble(Condition cond, Register tag) { |
| 263 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 264 |
cmp32(tag, Imm32(JSVAL_TAG_MAX_DOUBLE)); |
| 265 |
return cond == Equal ? BelowOrEqual : Above; |
| 266 |
} |
| 267 |
Condition testNumber(Condition cond, Register tag) { |
| 268 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 269 |
cmp32(tag, Imm32(JS::detail::ValueUpperInclNumberTag)); |
| 270 |
return cond == Equal ? BelowOrEqual : Above; |
| 271 |
} |
| 272 |
Condition testGCThing(Condition cond, Register tag) { |
| 273 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 274 |
cmp32(tag, Imm32(JS::detail::ValueLowerInclGCThingTag)); |
| 275 |
return cond == Equal ? AboveOrEqual : Below; |
| 276 |
} |
| 277 |
|
| 278 |
Condition testMagic(Condition cond, Register tag) { |
| 279 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 280 |
cmp32(tag, ImmTag(JSVAL_TAG_MAGIC)); |
| 281 |
return cond; |
| 282 |
} |
| 283 |
Condition testError(Condition cond, Register tag) { |
| 284 |
return testMagic(cond, tag); |
| 285 |
} |
| 286 |
Condition testPrimitive(Condition cond, Register tag) { |
| 287 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 288 |
cmp32(tag, ImmTag(JS::detail::ValueUpperExclPrimitiveTag)); |
| 289 |
return cond == Equal ? Below : AboveOrEqual; |
| 290 |
} |
| 291 |
|
| 292 |
Condition testUndefined(Condition cond, const ValueOperand& src) { |
| 293 |
ScratchRegisterScope scratch(asMasm()); |
| 294 |
splitTag(src, scratch); |
| 295 |
return testUndefined(cond, scratch); |
| 296 |
} |
| 297 |
Condition testInt32(Condition cond, const ValueOperand& src) { |
| 298 |
ScratchRegisterScope scratch(asMasm()); |
| 299 |
splitTag(src, scratch); |
| 300 |
return testInt32(cond, scratch); |
| 301 |
} |
| 302 |
Condition testBoolean(Condition cond, const ValueOperand& src) { |
| 303 |
ScratchRegisterScope scratch(asMasm()); |
| 304 |
splitTag(src, scratch); |
| 305 |
return testBoolean(cond, scratch); |
| 306 |
} |
| 307 |
Condition testDouble(Condition cond, const ValueOperand& src) { |
| 308 |
ScratchRegisterScope scratch(asMasm()); |
| 309 |
splitTag(src, scratch); |
| 310 |
return testDouble(cond, scratch); |
| 311 |
} |
| 312 |
Condition testNumber(Condition cond, const ValueOperand& src) { |
| 313 |
ScratchRegisterScope scratch(asMasm()); |
| 314 |
splitTag(src, scratch); |
| 315 |
return testNumber(cond, scratch); |
| 316 |
} |
| 317 |
Condition testNull(Condition cond, const ValueOperand& src) { |
| 318 |
ScratchRegisterScope scratch(asMasm()); |
| 319 |
splitTag(src, scratch); |
| 320 |
return testNull(cond, scratch); |
| 321 |
} |
| 322 |
Condition testString(Condition cond, const ValueOperand& src) { |
| 323 |
ScratchRegisterScope scratch(asMasm()); |
| 324 |
splitTag(src, scratch); |
| 325 |
return testString(cond, scratch); |
| 326 |
} |
| 327 |
Condition testSymbol(Condition cond, const ValueOperand& src) { |
| 328 |
ScratchRegisterScope scratch(asMasm()); |
| 329 |
splitTag(src, scratch); |
| 330 |
return testSymbol(cond, scratch); |
| 331 |
} |
| 332 |
Condition testBigInt(Condition cond, const ValueOperand& src) { |
| 333 |
ScratchRegisterScope scratch(asMasm()); |
| 334 |
splitTag(src, scratch); |
| 335 |
return testBigInt(cond, scratch); |
| 336 |
} |
| 337 |
Condition testObject(Condition cond, const ValueOperand& src) { |
| 338 |
ScratchRegisterScope scratch(asMasm()); |
| 339 |
splitTag(src, scratch); |
| 340 |
return testObject(cond, scratch); |
| 341 |
} |
| 342 |
Condition testGCThing(Condition cond, const ValueOperand& src) { |
| 343 |
ScratchRegisterScope scratch(asMasm()); |
| 344 |
splitTag(src, scratch); |
| 345 |
return testGCThing(cond, scratch); |
| 346 |
} |
| 347 |
Condition testPrimitive(Condition cond, const ValueOperand& src) { |
| 348 |
ScratchRegisterScope scratch(asMasm()); |
| 349 |
splitTag(src, scratch); |
| 350 |
return testPrimitive(cond, scratch); |
| 351 |
} |
| 352 |
|
| 353 |
Condition testUndefined(Condition cond, const Address& src) { |
| 354 |
cmp32(ToUpper32(src), |
| 355 |
Imm32(Upper32Of(GetShiftedTag(JSVAL_TYPE_UNDEFINED)))); |
| 356 |
return cond; |
| 357 |
} |
| 358 |
Condition testInt32(Condition cond, const Address& src) { |
| 359 |
cmp32(ToUpper32(src), Imm32(Upper32Of(GetShiftedTag(JSVAL_TYPE_INT32)))); |
| 360 |
return cond; |
| 361 |
} |
| 362 |
Condition testBoolean(Condition cond, const Address& src) { |
| 363 |
cmp32(ToUpper32(src), Imm32(Upper32Of(GetShiftedTag(JSVAL_TYPE_BOOLEAN)))); |
| 364 |
return cond; |
| 365 |
} |
| 366 |
Condition testDouble(Condition cond, const Address& src) { |
| 367 |
ScratchRegisterScope scratch(asMasm()); |
| 368 |
splitTag(src, scratch); |
| 369 |
return testDouble(cond, scratch); |
| 370 |
} |
| 371 |
Condition testNumber(Condition cond, const Address& src) { |
| 372 |
ScratchRegisterScope scratch(asMasm()); |
| 373 |
splitTag(src, scratch); |
| 374 |
return testNumber(cond, scratch); |
| 375 |
} |
| 376 |
Condition testNull(Condition cond, const Address& src) { |
| 377 |
cmp32(ToUpper32(src), Imm32(Upper32Of(GetShiftedTag(JSVAL_TYPE_NULL)))); |
| 378 |
return cond; |
| 379 |
} |
| 380 |
Condition testString(Condition cond, const Address& src) { |
| 381 |
ScratchRegisterScope scratch(asMasm()); |
| 382 |
splitTag(src, scratch); |
| 383 |
return testString(cond, scratch); |
| 384 |
} |
| 385 |
Condition testSymbol(Condition cond, const Address& src) { |
| 386 |
ScratchRegisterScope scratch(asMasm()); |
| 387 |
splitTag(src, scratch); |
| 388 |
return testSymbol(cond, scratch); |
| 389 |
} |
| 390 |
Condition testBigInt(Condition cond, const Address& src) { |
| 391 |
ScratchRegisterScope scratch(asMasm()); |
| 392 |
splitTag(src, scratch); |
| 393 |
return testBigInt(cond, scratch); |
| 394 |
} |
| 395 |
Condition testObject(Condition cond, const Address& src) { |
| 396 |
ScratchRegisterScope scratch(asMasm()); |
| 397 |
splitTag(src, scratch); |
| 398 |
return testObject(cond, scratch); |
| 399 |
} |
| 400 |
Condition testPrimitive(Condition cond, const Address& src) { |
| 401 |
ScratchRegisterScope scratch(asMasm()); |
| 402 |
splitTag(src, scratch); |
| 403 |
return testPrimitive(cond, scratch); |
| 404 |
} |
| 405 |
Condition testGCThing(Condition cond, const Address& src) { |
| 406 |
ScratchRegisterScope scratch(asMasm()); |
| 407 |
splitTag(src, scratch); |
| 408 |
return testGCThing(cond, scratch); |
| 409 |
} |
| 410 |
Condition testMagic(Condition cond, const Address& src) { |
| 411 |
ScratchRegisterScope scratch(asMasm()); |
| 412 |
splitTag(src, scratch); |
| 413 |
return testMagic(cond, scratch); |
| 414 |
} |
| 415 |
|
| 416 |
Condition testUndefined(Condition cond, const BaseIndex& src) { |
| 417 |
ScratchRegisterScope scratch(asMasm()); |
| 418 |
splitTag(src, scratch); |
| 419 |
return testUndefined(cond, scratch); |
| 420 |
} |
| 421 |
Condition testNull(Condition cond, const BaseIndex& src) { |
| 422 |
ScratchRegisterScope scratch(asMasm()); |
| 423 |
splitTag(src, scratch); |
| 424 |
return testNull(cond, scratch); |
| 425 |
} |
| 426 |
Condition testBoolean(Condition cond, const BaseIndex& src) { |
| 427 |
ScratchRegisterScope scratch(asMasm()); |
| 428 |
splitTag(src, scratch); |
| 429 |
return testBoolean(cond, scratch); |
| 430 |
} |
| 431 |
Condition testString(Condition cond, const BaseIndex& src) { |
| 432 |
ScratchRegisterScope scratch(asMasm()); |
| 433 |
splitTag(src, scratch); |
| 434 |
return testString(cond, scratch); |
| 435 |
} |
| 436 |
Condition testSymbol(Condition cond, const BaseIndex& src) { |
| 437 |
ScratchRegisterScope scratch(asMasm()); |
| 438 |
splitTag(src, scratch); |
| 439 |
return testSymbol(cond, scratch); |
| 440 |
} |
| 441 |
Condition testBigInt(Condition cond, const BaseIndex& src) { |
| 442 |
ScratchRegisterScope scratch(asMasm()); |
| 443 |
splitTag(src, scratch); |
| 444 |
return testBigInt(cond, scratch); |
| 445 |
} |
| 446 |
Condition testInt32(Condition cond, const BaseIndex& src) { |
| 447 |
ScratchRegisterScope scratch(asMasm()); |
| 448 |
splitTag(src, scratch); |
| 449 |
return testInt32(cond, scratch); |
| 450 |
} |
| 451 |
Condition testObject(Condition cond, const BaseIndex& src) { |
| 452 |
ScratchRegisterScope scratch(asMasm()); |
| 453 |
splitTag(src, scratch); |
| 454 |
return testObject(cond, scratch); |
| 455 |
} |
| 456 |
Condition testDouble(Condition cond, const BaseIndex& src) { |
| 457 |
ScratchRegisterScope scratch(asMasm()); |
| 458 |
splitTag(src, scratch); |
| 459 |
return testDouble(cond, scratch); |
| 460 |
} |
| 461 |
Condition testMagic(Condition cond, const BaseIndex& src) { |
| 462 |
ScratchRegisterScope scratch(asMasm()); |
| 463 |
splitTag(src, scratch); |
| 464 |
return testMagic(cond, scratch); |
| 465 |
} |
| 466 |
Condition testGCThing(Condition cond, const BaseIndex& src) { |
| 467 |
ScratchRegisterScope scratch(asMasm()); |
| 468 |
splitTag(src, scratch); |
| 469 |
return testGCThing(cond, scratch); |
| 470 |
} |
| 471 |
|
| 472 |
Condition isMagic(Condition cond, const ValueOperand& src, JSWhyMagic why) { |
| 473 |
uint64_t magic = MagicValue(why).asRawBits(); |
| 474 |
cmpPtr(src.valueReg(), ImmWord(magic)); |
| 475 |
return cond; |
| 476 |
} |
| 477 |
|
| 478 |
void cmpPtr(Register lhs, const ImmWord rhs) { |
| 479 |
ScratchRegisterScope scratch(asMasm()); |
| 480 |
MOZ_ASSERT(lhs != scratch); |
| 481 |
if (intptr_t(rhs.value) <= INT32_MAX && intptr_t(rhs.value) >= INT32_MIN) { |
| 482 |
cmpPtr(lhs, Imm32(int32_t(rhs.value))); |
| 483 |
} else { |
| 484 |
movePtr(rhs, scratch); |
| 485 |
cmpPtr(lhs, scratch); |
| 486 |
} |
| 487 |
} |
| 488 |
void cmpPtr(Register lhs, const ImmPtr rhs) { |
| 489 |
cmpPtr(lhs, ImmWord(uintptr_t(rhs.value))); |
| 490 |
} |
| 491 |
void cmpPtr(Register lhs, const ImmGCPtr rhs) { |
| 492 |
ScratchRegisterScope scratch(asMasm()); |
| 493 |
MOZ_ASSERT(lhs != scratch); |
| 494 |
movePtr(rhs, scratch); |
| 495 |
cmpPtr(lhs, scratch); |
| 496 |
} |
| 497 |
void cmpPtr(Register lhs, const Imm32 rhs) { cmpq(rhs, lhs); } |
| 498 |
void cmpPtr(const Operand& lhs, const ImmGCPtr rhs) { |
| 499 |
ScratchRegisterScope scratch(asMasm()); |
| 500 |
MOZ_ASSERT(!lhs.containsReg(scratch)); |
| 501 |
movePtr(rhs, scratch); |
| 502 |
cmpPtr(lhs, scratch); |
| 503 |
} |
| 504 |
void cmpPtr(const Operand& lhs, const ImmWord rhs) { |
| 505 |
if ((intptr_t)rhs.value <= INT32_MAX && (intptr_t)rhs.value >= INT32_MIN) { |
| 506 |
cmpPtr(lhs, Imm32((int32_t)rhs.value)); |
| 507 |
} else { |
| 508 |
ScratchRegisterScope scratch(asMasm()); |
| 509 |
movePtr(rhs, scratch); |
| 510 |
cmpPtr(lhs, scratch); |
| 511 |
} |
| 512 |
} |
| 513 |
void cmpPtr(const Operand& lhs, const ImmPtr rhs) { |
| 514 |
cmpPtr(lhs, ImmWord(uintptr_t(rhs.value))); |
| 515 |
} |
| 516 |
void cmpPtr(const Address& lhs, const ImmGCPtr rhs) { |
| 517 |
cmpPtr(Operand(lhs), rhs); |
| 518 |
} |
| 519 |
void cmpPtr(const Address& lhs, const ImmWord rhs) { |
| 520 |
cmpPtr(Operand(lhs), rhs); |
| 521 |
} |
| 522 |
void cmpPtr(const Address& lhs, const ImmPtr rhs) { |
| 523 |
cmpPtr(lhs, ImmWord(uintptr_t(rhs.value))); |
| 524 |
} |
| 525 |
void cmpPtr(const Operand& lhs, Register rhs) { cmpq(rhs, lhs); } |
| 526 |
void cmpPtr(Register lhs, const Operand& rhs) { cmpq(rhs, lhs); } |
| 527 |
void cmpPtr(const Operand& lhs, const Imm32 rhs) { cmpq(rhs, lhs); } |
| 528 |
void cmpPtr(const Address& lhs, Register rhs) { cmpPtr(Operand(lhs), rhs); } |
| 529 |
void cmpPtr(Register lhs, Register rhs) { cmpq(rhs, lhs); } |
| 530 |
void testPtr(Register lhs, Register rhs) { testq(rhs, lhs); } |
| 531 |
void testPtr(Register lhs, Imm32 rhs) { testq(rhs, lhs); } |
| 532 |
void testPtr(Register lhs, ImmWord rhs) { test64(lhs, Imm64(rhs.value)); } |
| 533 |
void testPtr(const Operand& lhs, Imm32 rhs) { testq(rhs, lhs); } |
| 534 |
void test64(Register lhs, Register rhs) { testq(rhs, lhs); } |
| 535 |
void test64(Register lhs, const Imm64 rhs) { |
| 536 |
if ((intptr_t)rhs.value <= INT32_MAX && (intptr_t)rhs.value >= INT32_MIN) { |
| 537 |
testq(Imm32((int32_t)rhs.value), lhs); |
| 538 |
} else { |
| 539 |
ScratchRegisterScope scratch(asMasm()); |
| 540 |
movq(ImmWord(rhs.value), scratch); |
| 541 |
testq(scratch, lhs); |
| 542 |
} |
| 543 |
} |
| 544 |
|
| 545 |
// Compare-then-conditionally-move/load, for integer types |
| 546 |
template <size_t CmpSize, size_t MoveSize> |
| 547 |
void cmpMove(Condition cond, Register lhs, Register rhs, Register falseVal, |
| 548 |
Register trueValAndDest); |
| 549 |
|
| 550 |
template <size_t CmpSize, size_t MoveSize> |
| 551 |
void cmpMove(Condition cond, Register lhs, const Address& rhs, |
| 552 |
Register falseVal, Register trueValAndDest); |
| 553 |
|
| 554 |
template <size_t CmpSize, size_t LoadSize> |
| 555 |
void cmpLoad(Condition cond, Register lhs, Register rhs, |
| 556 |
const Address& falseVal, Register trueValAndDest); |
| 557 |
|
| 558 |
template <size_t CmpSize, size_t LoadSize> |
| 559 |
void cmpLoad(Condition cond, Register lhs, const Address& rhs, |
| 560 |
const Address& falseVal, Register trueValAndDest); |
| 561 |
|
| 562 |
///////////////////////////////////////////////////////////////// |
| 563 |
// Common interface. |
| 564 |
///////////////////////////////////////////////////////////////// |
| 565 |
|
| 566 |
void movePtr(Register src, Register dest) { movq(src, dest); } |
| 567 |
void movePtr(Register src, const Operand& dest) { movq(src, dest); } |
| 568 |
void movePtr(ImmWord imm, Register dest) { mov(imm, dest); } |
| 569 |
void movePtr(ImmPtr imm, Register dest) { mov(imm, dest); } |
| 570 |
void movePtr(wasm::SymbolicAddress imm, Register dest) { mov(imm, dest); } |
| 571 |
void movePtr(ImmGCPtr imm, Register dest) { movq(imm, dest); } |
| 572 |
void loadPtr(AbsoluteAddress address, Register dest) { |
| 573 |
if (X86Encoding::IsAddressImmediate(address.addr)) { |
| 574 |
movq(Operand(address), dest); |
| 575 |
} else { |
| 576 |
ScratchRegisterScope scratch(asMasm()); |
| 577 |
mov(ImmPtr(address.addr), scratch); |
| 578 |
loadPtr(Address(scratch, 0x0), dest); |
| 579 |
} |
| 580 |
} |
| 581 |
FaultingCodeOffset loadPtr(const Address& address, Register dest) { |
| 582 |
FaultingCodeOffset fco = FaultingCodeOffset(currentOffset()); |
| 583 |
movq(Operand(address), dest); |
| 584 |
return fco; |
| 585 |
} |
| 586 |
void load64(const Address& address, Register dest) { |
| 587 |
movq(Operand(address), dest); |
| 588 |
} |
| 589 |
void loadPtr(const Operand& src, Register dest) { movq(src, dest); } |
| 590 |
FaultingCodeOffset loadPtr(const BaseIndex& src, Register dest) { |
| 591 |
FaultingCodeOffset fco = FaultingCodeOffset(currentOffset()); |
| 592 |
movq(Operand(src), dest); |
| 593 |
return fco; |
| 594 |
} |
| 595 |
void loadPrivate(const Address& src, Register dest) { loadPtr(src, dest); } |
| 596 |
void load32(AbsoluteAddress address, Register dest) { |
| 597 |
if (X86Encoding::IsAddressImmediate(address.addr)) { |
| 598 |
movl(Operand(address), dest); |
| 599 |
} else { |
| 600 |
ScratchRegisterScope scratch(asMasm()); |
| 601 |
mov(ImmPtr(address.addr), scratch); |
| 602 |
load32(Address(scratch, 0x0), dest); |
| 603 |
} |
| 604 |
} |
| 605 |
void load64(const Operand& address, Register64 dest) { |
| 606 |
movq(address, dest.reg); |
| 607 |
} |
| 608 |
FaultingCodeOffset load64(const Address& address, Register64 dest) { |
| 609 |
FaultingCodeOffset fco = FaultingCodeOffset(currentOffset()); |
| 610 |
movq(Operand(address), dest.reg); |
| 611 |
return fco; |
| 612 |
} |
| 613 |
FaultingCodeOffset load64(const BaseIndex& address, Register64 dest) { |
| 614 |
FaultingCodeOffset fco = FaultingCodeOffset(currentOffset()); |
| 615 |
movq(Operand(address), dest.reg); |
| 616 |
return fco; |
| 617 |
} |
| 618 |
template <typename S> |
| 619 |
void load64Unaligned(const S& src, Register64 dest) { |
| 620 |
load64(src, dest); |
| 621 |
} |
| 622 |
template <typename T> |
| 623 |
void storePtr(ImmWord imm, T address) { |
| 624 |
if ((intptr_t)imm.value <= INT32_MAX && (intptr_t)imm.value >= INT32_MIN) { |
| 625 |
movq(Imm32((int32_t)imm.value), Operand(address)); |
| 626 |
} else { |
| 627 |
ScratchRegisterScope scratch(asMasm()); |
| 628 |
mov(imm, scratch); |
| 629 |
movq(scratch, Operand(address)); |
| 630 |
} |
| 631 |
} |
| 632 |
template <typename T> |
| 633 |
void storePtr(ImmPtr imm, T address) { |
| 634 |
storePtr(ImmWord(uintptr_t(imm.value)), address); |
| 635 |
} |
| 636 |
template <typename T> |
| 637 |
void storePtr(ImmGCPtr imm, T address) { |
| 638 |
ScratchRegisterScope scratch(asMasm()); |
| 639 |
movq(imm, scratch); |
| 640 |
movq(scratch, Operand(address)); |
| 641 |
} |
| 642 |
FaultingCodeOffset storePtr(Register src, const Address& address) { |
| 643 |
FaultingCodeOffset fco = FaultingCodeOffset(currentOffset()); |
| 644 |
movq(src, Operand(address)); |
| 645 |
return fco; |
| 646 |
} |
| 647 |
void store64(Register src, const Address& address) { |
| 648 |
movq(src, Operand(address)); |
| 649 |
} |
| 650 |
void store64(Register64 src, const Operand& address) { |
| 651 |
movq(src.reg, address); |
| 652 |
} |
| 653 |
FaultingCodeOffset storePtr(Register src, const BaseIndex& address) { |
| 654 |
FaultingCodeOffset fco = FaultingCodeOffset(currentOffset()); |
| 655 |
movq(src, Operand(address)); |
| 656 |
return fco; |
| 657 |
} |
| 658 |
void storePtr(Register src, const Operand& dest) { movq(src, dest); } |
| 659 |
void storePtr(Register src, AbsoluteAddress address) { |
| 660 |
if (X86Encoding::IsAddressImmediate(address.addr)) { |
| 661 |
movq(src, Operand(address)); |
| 662 |
} else { |
| 663 |
ScratchRegisterScope scratch(asMasm()); |
| 664 |
mov(ImmPtr(address.addr), scratch); |
| 665 |
storePtr(src, Address(scratch, 0x0)); |
| 666 |
} |
| 667 |
} |
| 668 |
void store32(Register src, AbsoluteAddress address) { |
| 669 |
if (X86Encoding::IsAddressImmediate(address.addr)) { |
| 670 |
movl(src, Operand(address)); |
| 671 |
} else { |
| 672 |
ScratchRegisterScope scratch(asMasm()); |
| 673 |
mov(ImmPtr(address.addr), scratch); |
| 674 |
store32(src, Address(scratch, 0x0)); |
| 675 |
} |
| 676 |
} |
| 677 |
void store16(Register src, AbsoluteAddress address) { |
| 678 |
if (X86Encoding::IsAddressImmediate(address.addr)) { |
| 679 |
movw(src, Operand(address)); |
| 680 |
} else { |
| 681 |
ScratchRegisterScope scratch(asMasm()); |
| 682 |
mov(ImmPtr(address.addr), scratch); |
| 683 |
store16(src, Address(scratch, 0x0)); |
| 684 |
} |
| 685 |
} |
| 686 |
FaultingCodeOffset store64(Register64 src, Address address) { |
| 687 |
FaultingCodeOffset fco = FaultingCodeOffset(currentOffset()); |
| 688 |
storePtr(src.reg, address); |
| 689 |
return fco; |
| 690 |
} |
| 691 |
FaultingCodeOffset store64(Register64 src, const BaseIndex& address) { |
| 692 |
return storePtr(src.reg, address); |
| 693 |
} |
| 694 |
void store64(Imm64 imm, Address address) { |
| 695 |
storePtr(ImmWord(imm.value), address); |
| 696 |
} |
| 697 |
void store64(Imm64 imm, const BaseIndex& address) { |
| 698 |
storePtr(ImmWord(imm.value), address); |
| 699 |
} |
| 700 |
template <typename S, typename T> |
| 701 |
void store64Unaligned(const S& src, const T& dest) { |
| 702 |
store64(src, dest); |
| 703 |
} |
| 704 |
|
| 705 |
void splitTag(Register src, Register dest) { |
| 706 |
if (src != dest) { |
| 707 |
movq(src, dest); |
| 708 |
} |
| 709 |
shrq(Imm32(JSVAL_TAG_SHIFT), dest); |
| 710 |
} |
| 711 |
void splitTag(const ValueOperand& operand, Register dest) { |
| 712 |
splitTag(operand.valueReg(), dest); |
| 713 |
} |
| 714 |
void splitTag(const Operand& operand, Register dest) { |
| 715 |
movq(operand, dest); |
| 716 |
shrq(Imm32(JSVAL_TAG_SHIFT), dest); |
| 717 |
} |
| 718 |
void splitTag(const Address& operand, Register dest) { |
| 719 |
splitTag(Operand(operand), dest); |
| 720 |
} |
| 721 |
void splitTag(const BaseIndex& operand, Register dest) { |
| 722 |
splitTag(Operand(operand), dest); |
| 723 |
} |
| 724 |
|
| 725 |
// Extracts the tag of a value and places it in tag. |
| 726 |
void splitTagForTest(const ValueOperand& value, ScratchTagScope& tag) { |
| 727 |
splitTag(value, tag); |
| 728 |
} |
| 729 |
void cmpTag(const ValueOperand& operand, ImmTag tag) { |
| 730 |
ScratchTagScope reg(asMasm(), operand); |
| 731 |
splitTagForTest(operand, reg); |
| 732 |
cmp32(reg, tag); |
| 733 |
} |
| 734 |
|
| 735 |
Condition testMagic(Condition cond, const ValueOperand& src) { |
| 736 |
ScratchTagScope scratch(asMasm(), src); |
| 737 |
splitTagForTest(src, scratch); |
| 738 |
return testMagic(cond, scratch); |
| 739 |
} |
| 740 |
Condition testError(Condition cond, const ValueOperand& src) { |
| 741 |
return testMagic(cond, src); |
| 742 |
} |
| 743 |
|
| 744 |
void testNullSet(Condition cond, const ValueOperand& value, Register dest) { |
| 745 |
bool destIsZero = maybeEmitSetZeroByteRegister(value, dest); |
| 746 |
cond = testNull(cond, value); |
| 747 |
emitSet(cond, dest, destIsZero); |
| 748 |
} |
| 749 |
|
| 750 |
void testObjectSet(Condition cond, const ValueOperand& value, Register dest) { |
| 751 |
bool destIsZero = maybeEmitSetZeroByteRegister(value, dest); |
| 752 |
cond = testObject(cond, value); |
| 753 |
emitSet(cond, dest, destIsZero); |
| 754 |
} |
| 755 |
|
| 756 |
void testUndefinedSet(Condition cond, const ValueOperand& value, |
| 757 |
Register dest) { |
| 758 |
bool destIsZero = maybeEmitSetZeroByteRegister(value, dest); |
| 759 |
cond = testUndefined(cond, value); |
| 760 |
emitSet(cond, dest, destIsZero); |
| 761 |
} |
| 762 |
|
| 763 |
void boxDouble(FloatRegister src, const ValueOperand& dest, FloatRegister) { |
| 764 |
vmovq(src, dest.valueReg()); |
| 765 |
} |
| 766 |
void boxNonDouble(JSValueType type, Register src, const ValueOperand& dest) { |
| 767 |
MOZ_ASSERT(src != dest.valueReg()); |
| 768 |
boxValue(type, src, dest.valueReg()); |
| 769 |
} |
| 770 |
|
| 771 |
// Note that the |dest| register here may be ScratchReg, so we shouldn't |
| 772 |
// use it. |
| 773 |
void unboxInt32(const ValueOperand& src, Register dest) { |
| 774 |
movl(src.valueReg(), dest); |
| 775 |
} |
| 776 |
void unboxInt32(const Operand& src, Register dest) { movl(src, dest); } |
| 777 |
void unboxInt32(const Address& src, Register dest) { |
| 778 |
unboxInt32(Operand(src), dest); |
| 779 |
} |
| 780 |
void unboxInt32(const BaseIndex& src, Register dest) { |
| 781 |
unboxInt32(Operand(src), dest); |
| 782 |
} |
| 783 |
template <typename T> |
| 784 |
void unboxDouble(const T& src, FloatRegister dest) { |
| 785 |
loadDouble(Operand(src), dest); |
| 786 |
} |
| 787 |
|
| 788 |
void unboxArgObjMagic(const ValueOperand& src, Register dest) { |
| 789 |
unboxArgObjMagic(Operand(src.valueReg()), dest); |
| 790 |
} |
| 791 |
void unboxArgObjMagic(const Operand& src, Register dest) { |
| 792 |
mov(ImmWord(0), dest); |
| 793 |
} |
| 794 |
void unboxArgObjMagic(const Address& src, Register dest) { |
| 795 |
unboxArgObjMagic(Operand(src), dest); |
| 796 |
} |
| 797 |
|
| 798 |
void unboxBoolean(const ValueOperand& src, Register dest) { |
| 799 |
movl(src.valueReg(), dest); |
| 800 |
} |
| 801 |
void unboxBoolean(const Operand& src, Register dest) { movl(src, dest); } |
| 802 |
void unboxBoolean(const Address& src, Register dest) { |
| 803 |
unboxBoolean(Operand(src), dest); |
| 804 |
} |
| 805 |
void unboxBoolean(const BaseIndex& src, Register dest) { |
| 806 |
unboxBoolean(Operand(src), dest); |
| 807 |
} |
| 808 |
|
| 809 |
void unboxMagic(const ValueOperand& src, Register dest) { |
| 810 |
movl(src.valueReg(), dest); |
| 811 |
} |
| 812 |
|
| 813 |
void unboxDouble(const ValueOperand& src, FloatRegister dest) { |
| 814 |
vmovq(src.valueReg(), dest); |
| 815 |
} |
| 816 |
|
| 817 |
void notBoolean(const ValueOperand& val) { xorq(Imm32(1), val.valueReg()); } |
| 818 |
|
| 819 |
void unboxNonDouble(const ValueOperand& src, Register dest, |
| 820 |
JSValueType type) { |
| 821 |
MOZ_ASSERT(type != JSVAL_TYPE_DOUBLE); |
| 822 |
if (type == JSVAL_TYPE_INT32 || type == JSVAL_TYPE_BOOLEAN) { |
| 823 |
movl(src.valueReg(), dest); |
| 824 |
return; |
| 825 |
} |
| 826 |
if (src.valueReg() == dest) { |
| 827 |
ScratchRegisterScope scratch(asMasm()); |
| 828 |
mov(ImmShiftedTag(type), scratch); |
| 829 |
xorq(scratch, dest); |
| 830 |
} else { |
| 831 |
mov(ImmShiftedTag(type), dest); |
| 832 |
xorq(src.valueReg(), dest); |
| 833 |
} |
| 834 |
} |
| 835 |
void unboxNonDouble(const Operand& src, Register dest, JSValueType type) { |
| 836 |
MOZ_ASSERT(type != JSVAL_TYPE_DOUBLE); |
| 837 |
if (type == JSVAL_TYPE_INT32 || type == JSVAL_TYPE_BOOLEAN) { |
| 838 |
movl(src, dest); |
| 839 |
return; |
| 840 |
} |
| 841 |
// Explicitly permits |dest| to be used in |src|. |
| 842 |
ScratchRegisterScope scratch(asMasm()); |
| 843 |
MOZ_ASSERT(dest != scratch); |
| 844 |
if (src.containsReg(dest)) { |
| 845 |
mov(ImmShiftedTag(type), scratch); |
| 846 |
// If src is already a register, then src and dest are the same |
| 847 |
// thing and we don't need to move anything into dest. |
| 848 |
if (src.kind() != Operand::REG) { |
| 849 |
movq(src, dest); |
| 850 |
} |
| 851 |
xorq(scratch, dest); |
| 852 |
} else { |
| 853 |
mov(ImmShiftedTag(type), dest); |
| 854 |
xorq(src, dest); |
| 855 |
} |
| 856 |
} |
| 857 |
void unboxNonDouble(const Address& src, Register dest, JSValueType type) { |
| 858 |
unboxNonDouble(Operand(src), dest, type); |
| 859 |
} |
| 860 |
void unboxNonDouble(const BaseIndex& src, Register dest, JSValueType type) { |
| 861 |
unboxNonDouble(Operand(src), dest, type); |
| 862 |
} |
| 863 |
|
| 864 |
void unboxString(const ValueOperand& src, Register dest) { |
| 865 |
unboxNonDouble(src, dest, JSVAL_TYPE_STRING); |
| 866 |
} |
| 867 |
void unboxString(const Operand& src, Register dest) { |
| 868 |
unboxNonDouble(src, dest, JSVAL_TYPE_STRING); |
| 869 |
} |
| 870 |
void unboxString(const Address& src, Register dest) { |
| 871 |
unboxNonDouble(src, dest, JSVAL_TYPE_STRING); |
| 872 |
} |
| 873 |
|
| 874 |
void unboxSymbol(const ValueOperand& src, Register dest) { |
| 875 |
unboxNonDouble(src, dest, JSVAL_TYPE_SYMBOL); |
| 876 |
} |
| 877 |
void unboxSymbol(const Operand& src, Register dest) { |
| 878 |
unboxNonDouble(src, dest, JSVAL_TYPE_SYMBOL); |
| 879 |
} |
| 880 |
|
| 881 |
void unboxBigInt(const ValueOperand& src, Register dest) { |
| 882 |
unboxNonDouble(src, dest, JSVAL_TYPE_BIGINT); |
| 883 |
} |
| 884 |
void unboxBigInt(const Operand& src, Register dest) { |
| 885 |
unboxNonDouble(src, dest, JSVAL_TYPE_BIGINT); |
| 886 |
} |
| 887 |
void unboxBigInt(const Address& src, Register dest) { |
| 888 |
unboxNonDouble(src, dest, JSVAL_TYPE_BIGINT); |
| 889 |
} |
| 890 |
|
| 891 |
void unboxObject(const ValueOperand& src, Register dest) { |
| 892 |
unboxNonDouble(src, dest, JSVAL_TYPE_OBJECT); |
| 893 |
} |
| 894 |
void unboxObject(const Operand& src, Register dest) { |
| 895 |
unboxNonDouble(src, dest, JSVAL_TYPE_OBJECT); |
| 896 |
} |
| 897 |
void unboxObject(const Address& src, Register dest) { |
| 898 |
unboxNonDouble(Operand(src), dest, JSVAL_TYPE_OBJECT); |
| 899 |
} |
| 900 |
void unboxObject(const BaseIndex& src, Register dest) { |
| 901 |
unboxNonDouble(Operand(src), dest, JSVAL_TYPE_OBJECT); |
| 902 |
} |
| 903 |
|
| 904 |
template <typename T> |
| 905 |
void unboxObjectOrNull(const T& src, Register dest) { |
| 906 |
unboxNonDouble(src, dest, JSVAL_TYPE_OBJECT); |
| 907 |
ScratchRegisterScope scratch(asMasm()); |
| 908 |
mov(ImmWord(~JS::detail::ValueObjectOrNullBit), scratch); |
| 909 |
andq(scratch, dest); |
| 910 |
} |
| 911 |
|
| 912 |
// This should only be used for GC barrier code, to unbox a GC thing Value. |
| 913 |
// It's fine there because we don't depend on the actual Value type (all Cells |
| 914 |
// are treated the same way). In almost all other cases this would be |
| 915 |
// Spectre-unsafe - use unboxNonDouble and friends instead. |
| 916 |
void unboxGCThingForGCBarrier(const Address& src, Register dest) { |
| 917 |
movq(ImmWord(JS::detail::ValueGCThingPayloadMask), dest); |
| 918 |
andq(Operand(src), dest); |
| 919 |
} |
| 920 |
void unboxGCThingForGCBarrier(const ValueOperand& src, Register dest) { |
| 921 |
MOZ_ASSERT(src.valueReg() != dest); |
| 922 |
movq(ImmWord(JS::detail::ValueGCThingPayloadMask), dest); |
| 923 |
andq(src.valueReg(), dest); |
| 924 |
} |
| 925 |
|
| 926 |
void unboxWasmAnyRefGCThingForGCBarrier(const Address& src, Register dest) { |
| 927 |
movq(ImmWord(wasm::AnyRef::GCThingMask), dest); |
| 928 |
andq(Operand(src), dest); |
| 929 |
} |
| 930 |
|
| 931 |
// Like unboxGCThingForGCBarrier, but loads the GC thing's chunk base. |
| 932 |
void getGCThingValueChunk(const Address& src, Register dest) { |
| 933 |
movq(ImmWord(JS::detail::ValueGCThingPayloadChunkMask), dest); |
| 934 |
andq(Operand(src), dest); |
| 935 |
} |
| 936 |
void getGCThingValueChunk(const ValueOperand& src, Register dest) { |
| 937 |
MOZ_ASSERT(src.valueReg() != dest); |
| 938 |
movq(ImmWord(JS::detail::ValueGCThingPayloadChunkMask), dest); |
| 939 |
andq(src.valueReg(), dest); |
| 940 |
} |
| 941 |
|
| 942 |
void getWasmAnyRefGCThingChunk(Register src, Register dest) { |
| 943 |
MOZ_ASSERT(src != dest); |
| 944 |
movq(ImmWord(wasm::AnyRef::GCThingChunkMask), dest); |
| 945 |
andq(src, dest); |
| 946 |
} |
| 947 |
|
| 948 |
inline void fallibleUnboxPtrImpl(const Operand& src, Register dest, |
| 949 |
JSValueType type, Label* fail); |
| 950 |
|
| 951 |
// Extended unboxing API. If the payload is already in a register, returns |
| 952 |
// that register. Otherwise, provides a move to the given scratch register, |
| 953 |
// and returns that. |
| 954 |
[[nodiscard]] Register extractObject(const Address& address, |
| 955 |
Register scratch) { |
| 956 |
MOZ_ASSERT(scratch != ScratchReg); |
| 957 |
unboxObject(address, scratch); |
| 958 |
return scratch; |
| 959 |
} |
| 960 |
[[nodiscard]] Register extractObject(const ValueOperand& value, |
| 961 |
Register scratch) { |
| 962 |
MOZ_ASSERT(scratch != ScratchReg); |
| 963 |
unboxObject(value, scratch); |
| 964 |
return scratch; |
| 965 |
} |
| 966 |
[[nodiscard]] Register extractSymbol(const ValueOperand& value, |
| 967 |
Register scratch) { |
| 968 |
MOZ_ASSERT(scratch != ScratchReg); |
| 969 |
unboxSymbol(value, scratch); |
| 970 |
return scratch; |
| 971 |
} |
| 972 |
[[nodiscard]] Register extractInt32(const ValueOperand& value, |
| 973 |
Register scratch) { |
| 974 |
MOZ_ASSERT(scratch != ScratchReg); |
| 975 |
unboxInt32(value, scratch); |
| 976 |
return scratch; |
| 977 |
} |
| 978 |
[[nodiscard]] Register extractBoolean(const ValueOperand& value, |
| 979 |
Register scratch) { |
| 980 |
MOZ_ASSERT(scratch != ScratchReg); |
| 981 |
unboxBoolean(value, scratch); |
| 982 |
return scratch; |
| 983 |
} |
| 984 |
[[nodiscard]] Register extractTag(const Address& address, Register scratch) { |
| 985 |
MOZ_ASSERT(scratch != ScratchReg); |
| 986 |
loadPtr(address, scratch); |
| 987 |
splitTag(scratch, scratch); |
| 988 |
return scratch; |
| 989 |
} |
| 990 |
[[nodiscard]] Register extractTag(const ValueOperand& value, |
| 991 |
Register scratch) { |
| 992 |
MOZ_ASSERT(scratch != ScratchReg); |
| 993 |
splitTag(value, scratch); |
| 994 |
return scratch; |
| 995 |
} |
| 996 |
|
| 997 |
inline void unboxValue(const ValueOperand& src, AnyRegister dest, |
| 998 |
JSValueType type); |
| 999 |
|
| 1000 |
void loadConstantDouble(double d, FloatRegister dest); |
| 1001 |
void loadConstantFloat32(float f, FloatRegister dest); |
| 1002 |
|
| 1003 |
void loadConstantSimd128Int(const SimdConstant& v, FloatRegister dest); |
| 1004 |
void loadConstantSimd128Float(const SimdConstant& v, FloatRegister dest); |
| 1005 |
void vpaddbSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1006 |
FloatRegister dest); |
| 1007 |
void vpaddwSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1008 |
FloatRegister dest); |
| 1009 |
void vpadddSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1010 |
FloatRegister dest); |
| 1011 |
void vpaddqSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1012 |
FloatRegister dest); |
| 1013 |
void vpsubbSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1014 |
FloatRegister dest); |
| 1015 |
void vpsubwSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1016 |
FloatRegister dest); |
| 1017 |
void vpsubdSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1018 |
FloatRegister dest); |
| 1019 |
void vpsubqSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1020 |
FloatRegister dest); |
| 1021 |
void vpmullwSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1022 |
FloatRegister dest); |
| 1023 |
void vpmulldSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1024 |
FloatRegister dest); |
| 1025 |
void vpaddsbSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1026 |
FloatRegister dest); |
| 1027 |
void vpaddusbSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1028 |
FloatRegister dest); |
| 1029 |
void vpaddswSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1030 |
FloatRegister dest); |
| 1031 |
void vpadduswSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1032 |
FloatRegister dest); |
| 1033 |
void vpsubsbSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1034 |
FloatRegister dest); |
| 1035 |
void vpsubusbSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1036 |
FloatRegister dest); |
| 1037 |
void vpsubswSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1038 |
FloatRegister dest); |
| 1039 |
void vpsubuswSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1040 |
FloatRegister dest); |
| 1041 |
void vpminsbSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1042 |
FloatRegister dest); |
| 1043 |
void vpminubSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1044 |
FloatRegister dest); |
| 1045 |
void vpminswSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1046 |
FloatRegister dest); |
| 1047 |
void vpminuwSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1048 |
FloatRegister dest); |
| 1049 |
void vpminsdSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1050 |
FloatRegister dest); |
| 1051 |
void vpminudSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1052 |
FloatRegister dest); |
| 1053 |
void vpmaxsbSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1054 |
FloatRegister dest); |
| 1055 |
void vpmaxubSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1056 |
FloatRegister dest); |
| 1057 |
void vpmaxswSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1058 |
FloatRegister dest); |
| 1059 |
void vpmaxuwSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1060 |
FloatRegister dest); |
| 1061 |
void vpmaxsdSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1062 |
FloatRegister dest); |
| 1063 |
void vpmaxudSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1064 |
FloatRegister dest); |
| 1065 |
void vpandSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1066 |
FloatRegister dest); |
| 1067 |
void vpxorSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1068 |
FloatRegister dest); |
| 1069 |
void vporSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1070 |
FloatRegister dest); |
| 1071 |
void vaddpsSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1072 |
FloatRegister dest); |
| 1073 |
void vaddpdSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1074 |
FloatRegister dest); |
| 1075 |
void vsubpsSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1076 |
FloatRegister dest); |
| 1077 |
void vsubpdSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1078 |
FloatRegister dest); |
| 1079 |
void vdivpsSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1080 |
FloatRegister dest); |
| 1081 |
void vdivpdSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1082 |
FloatRegister dest); |
| 1083 |
void vmulpsSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1084 |
FloatRegister dest); |
| 1085 |
void vmulpdSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1086 |
FloatRegister dest); |
| 1087 |
void vandpdSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1088 |
FloatRegister dest); |
| 1089 |
void vminpdSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1090 |
FloatRegister dest); |
| 1091 |
void vpacksswbSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1092 |
FloatRegister dest); |
| 1093 |
void vpackuswbSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1094 |
FloatRegister dest); |
| 1095 |
void vpackssdwSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1096 |
FloatRegister dest); |
| 1097 |
void vpackusdwSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1098 |
FloatRegister dest); |
| 1099 |
void vpunpckldqSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1100 |
FloatRegister dest); |
| 1101 |
void vunpcklpsSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1102 |
FloatRegister dest); |
| 1103 |
void vpshufbSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1104 |
FloatRegister dest); |
| 1105 |
void vptestSimd128(const SimdConstant& v, FloatRegister lhs); |
| 1106 |
void vpmaddwdSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1107 |
FloatRegister dest); |
| 1108 |
void vpcmpeqbSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1109 |
FloatRegister dest); |
| 1110 |
void vpcmpgtbSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1111 |
FloatRegister dest); |
| 1112 |
void vpcmpeqwSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1113 |
FloatRegister dest); |
| 1114 |
void vpcmpgtwSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1115 |
FloatRegister dest); |
| 1116 |
void vpcmpeqdSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1117 |
FloatRegister dest); |
| 1118 |
void vpcmpgtdSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1119 |
FloatRegister dest); |
| 1120 |
void vcmpeqpsSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1121 |
FloatRegister dest); |
| 1122 |
void vcmpneqpsSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1123 |
FloatRegister dest); |
| 1124 |
void vcmpltpsSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1125 |
FloatRegister dest); |
| 1126 |
void vcmplepsSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1127 |
FloatRegister dest); |
| 1128 |
void vcmpgepsSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1129 |
FloatRegister dest); |
| 1130 |
void vcmpeqpdSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1131 |
FloatRegister dest); |
| 1132 |
void vcmpneqpdSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1133 |
FloatRegister dest); |
| 1134 |
void vcmpltpdSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1135 |
FloatRegister dest); |
| 1136 |
void vcmplepdSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1137 |
FloatRegister dest); |
| 1138 |
void vpmaddubswSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1139 |
FloatRegister dest); |
| 1140 |
void vpmuludqSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1141 |
FloatRegister dest); |
| 1142 |
|
| 1143 |
public: |
| 1144 |
Condition testInt32Truthy(bool truthy, const ValueOperand& operand) { |
| 1145 |
test32(operand.valueReg(), operand.valueReg()); |
| 1146 |
return truthy ? NonZero : Zero; |
| 1147 |
} |
| 1148 |
Condition testStringTruthy(bool truthy, const ValueOperand& value); |
| 1149 |
Condition testBigIntTruthy(bool truthy, const ValueOperand& value); |
| 1150 |
|
| 1151 |
template <typename T> |
| 1152 |
inline void loadInt32OrDouble(const T& src, FloatRegister dest); |
| 1153 |
|
| 1154 |
template <typename T> |
| 1155 |
void loadUnboxedValue(const T& src, MIRType type, AnyRegister dest) { |
| 1156 |
if (dest.isFloat()) { |
| 1157 |
loadInt32OrDouble(src, dest.fpu()); |
| 1158 |
} else { |
| 1159 |
unboxNonDouble(Operand(src), dest.gpr(), ValueTypeFromMIRType(type)); |
| 1160 |
} |
| 1161 |
} |
| 1162 |
|
| 1163 |
template <typename T> |
| 1164 |
void storeUnboxedPayload(ValueOperand value, T address, size_t nbytes, |
| 1165 |
JSValueType type) { |
| 1166 |
switch (nbytes) { |
| 1167 |
case 8: { |
| 1168 |
ScratchRegisterScope scratch(asMasm()); |
| 1169 |
unboxNonDouble(value, scratch, type); |
| 1170 |
storePtr(scratch, address); |
| 1171 |
if (type == JSVAL_TYPE_OBJECT) { |
| 1172 |
// Ideally we would call unboxObjectOrNull, but we need an extra |
| 1173 |
// scratch register for that. So unbox as object, then clear the |
| 1174 |
// object-or-null bit. |
| 1175 |
mov(ImmWord(~JS::detail::ValueObjectOrNullBit), scratch); |
| 1176 |
andq(scratch, Operand(address)); |
| 1177 |
} |
| 1178 |
return; |
| 1179 |
} |
| 1180 |
case 4: |
| 1181 |
store32(value.valueReg(), address); |
| 1182 |
return; |
| 1183 |
case 1: |
| 1184 |
store8(value.valueReg(), address); |
| 1185 |
return; |
| 1186 |
default: |
| 1187 |
MOZ_CRASH("Bad payload width"); |
| 1188 |
} |
| 1189 |
} |
| 1190 |
|
| 1191 |
// Checks whether a double is representable as a 64-bit integer. If so, the |
| 1192 |
// integer is written to the output register. Otherwise, a bailout is taken to |
| 1193 |
// the given snapshot. This function overwrites the scratch float register. |
| 1194 |
void convertDoubleToPtr(FloatRegister src, Register dest, Label* fail, |
| 1195 |
bool negativeZeroCheck = true); |
| 1196 |
|
| 1197 |
void convertUInt32ToDouble(Register src, FloatRegister dest) { |
| 1198 |
// Zero the output register to break dependencies, see convertInt32ToDouble. |
| 1199 |
zeroDouble(dest); |
| 1200 |
|
| 1201 |
vcvtsq2sd(src, dest, dest); |
| 1202 |
} |
| 1203 |
|
| 1204 |
void convertUInt32ToFloat32(Register src, FloatRegister dest) { |
| 1205 |
// Zero the output register to break dependencies, see convertInt32ToDouble. |
| 1206 |
zeroDouble(dest); |
| 1207 |
|
| 1208 |
vcvtsq2ss(src, dest, dest); |
| 1209 |
} |
| 1210 |
|
| 1211 |
void truncateFloat32ModUint32(FloatRegister src, Register dest) { |
| 1212 |
// vcvttss2sq returns 0x8000000000000000 on failure. It fails if |
| 1213 |
// 1. The input is non-finite (NaN or ±Infinity). |
| 1214 |
// 2. The input's exponent is at least 63. |
| 1215 |
// |
| 1216 |
// In both cases the input is too large for an int32 and the truncated |
| 1217 |
// result is zero. So unconditionally zeroing the upper 32-bits gives the |
| 1218 |
// correct result for all inputs. |
| 1219 |
|
| 1220 |
vcvttss2sq(src, dest); |
| 1221 |
movl(dest, dest); // Zero upper 32-bits. |
| 1222 |
} |
| 1223 |
|
| 1224 |
inline void incrementInt32Value(const Address& addr); |
| 1225 |
|
| 1226 |
public: |
| 1227 |
void handleFailureWithHandlerTail(Label* profilerExitTail, Label* bailoutTail, |
| 1228 |
uint32_t* returnValueCheckOffset); |
| 1229 |
|
| 1230 |
// Instrumentation for entering and leaving the profiler. |
| 1231 |
void profilerEnterFrame(Register framePtr, Register scratch); |
| 1232 |
void profilerExitFrame(); |
| 1233 |
}; |
| 1234 |
|
| 1235 |
using MacroAssemblerSpecific = MacroAssemblerX64; |
| 1236 |
|
| 1237 |
} // namespace jit |
| 1238 |
} // namespace js |
| 1239 |
|
| 1240 |
#endif /* jit_x64_MacroAssembler_x64_h */ |