| 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_x86_MacroAssembler_x86_h |
| 8 |
#define jit_x86_MacroAssembler_x86_h |
| 9 |
|
| 10 |
#include "jit/JitOptions.h" |
| 11 |
#include "jit/MoveResolver.h" |
| 12 |
#include "jit/x86-shared/MacroAssembler-x86-shared.h" |
| 13 |
#include "js/HeapAPI.h" |
| 14 |
#include "wasm/WasmBuiltins.h" |
| 15 |
#include "wasm/WasmCodegenTypes.h" |
| 16 |
|
| 17 |
using js::wasm::FaultingCodeOffsetPair; |
| 18 |
|
| 19 |
namespace js { |
| 20 |
namespace jit { |
| 21 |
|
| 22 |
// See documentation for ScratchTagScope and ScratchTagScopeRelease in |
| 23 |
// MacroAssembler-x64.h. |
| 24 |
|
| 25 |
class ScratchTagScope { |
| 26 |
const ValueOperand& v_; |
| 27 |
|
| 28 |
public: |
| 29 |
ScratchTagScope(MacroAssembler&, const ValueOperand& v) : v_(v) {} |
| 30 |
operator Register() { return v_.typeReg(); } |
| 31 |
void release() {} |
| 32 |
void reacquire() {} |
| 33 |
}; |
| 34 |
|
| 35 |
class ScratchTagScopeRelease { |
| 36 |
public: |
| 37 |
explicit ScratchTagScopeRelease(ScratchTagScope*) {} |
| 38 |
}; |
| 39 |
|
| 40 |
class MacroAssemblerX86 : public MacroAssemblerX86Shared { |
| 41 |
private: |
| 42 |
// Perform a downcast. Should be removed by Bug 996602. |
| 43 |
MacroAssembler& asMasm(); |
| 44 |
const MacroAssembler& asMasm() const; |
| 45 |
|
| 46 |
protected: |
| 47 |
MoveResolver moveResolver_; |
| 48 |
|
| 49 |
private: |
| 50 |
Operand payloadOfAfterStackPush(const Address& address) { |
| 51 |
// If we are basing off %esp, the address will be invalid after the |
| 52 |
// first push. |
| 53 |
if (address.base == StackPointer) { |
| 54 |
return Operand(address.base, address.offset + 4); |
| 55 |
} |
| 56 |
return payloadOf(address); |
| 57 |
} |
| 58 |
Operand payloadOfAfterStackPush(const BaseIndex& address) { |
| 59 |
// If we are basing off %esp, the address will be invalid after the |
| 60 |
// first push. |
| 61 |
if (address.base == StackPointer) { |
| 62 |
return Operand(address.base, address.index, address.scale, |
| 63 |
address.offset + 4); |
| 64 |
} |
| 65 |
return payloadOf(address); |
| 66 |
} |
| 67 |
Operand payloadOf(const Address& address) { |
| 68 |
return Operand(address.base, address.offset); |
| 69 |
} |
| 70 |
Operand payloadOf(const BaseIndex& address) { |
| 71 |
return Operand(address.base, address.index, address.scale, address.offset); |
| 72 |
} |
| 73 |
Operand tagOf(const Address& address) { |
| 74 |
return Operand(address.base, address.offset + 4); |
| 75 |
} |
| 76 |
Operand tagOf(const BaseIndex& address) { |
| 77 |
return Operand(address.base, address.index, address.scale, |
| 78 |
address.offset + 4); |
| 79 |
} |
| 80 |
|
| 81 |
void setupABICall(uint32_t args); |
| 82 |
|
| 83 |
void vpPatchOpSimd128(const SimdConstant& v, FloatRegister reg, |
| 84 |
void (X86Encoding::BaseAssemblerX86::*op)( |
| 85 |
const void* address, |
| 86 |
X86Encoding::XMMRegisterID srcId, |
| 87 |
X86Encoding::XMMRegisterID destId)) { |
| 88 |
vpPatchOpSimd128(v, reg, reg, op); |
| 89 |
} |
| 90 |
|
| 91 |
void vpPatchOpSimd128(const SimdConstant& v, FloatRegister lhs, |
| 92 |
FloatRegister dest, |
| 93 |
void (X86Encoding::BaseAssemblerX86::*op)( |
| 94 |
const void* address, |
| 95 |
X86Encoding::XMMRegisterID srcId, |
| 96 |
X86Encoding::XMMRegisterID destId)); |
| 97 |
|
| 98 |
void vpPatchOpSimd128(const SimdConstant& v, FloatRegister reg, |
| 99 |
size_t (X86Encoding::BaseAssemblerX86::*op)( |
| 100 |
const void* address, |
| 101 |
X86Encoding::XMMRegisterID srcId, |
| 102 |
X86Encoding::XMMRegisterID destId)) { |
| 103 |
vpPatchOpSimd128(v, reg, reg, op); |
| 104 |
} |
| 105 |
|
| 106 |
void vpPatchOpSimd128(const SimdConstant& v, FloatRegister lhs, |
| 107 |
FloatRegister dest, |
| 108 |
size_t (X86Encoding::BaseAssemblerX86::*op)( |
| 109 |
const void* address, |
| 110 |
X86Encoding::XMMRegisterID srcId, |
| 111 |
X86Encoding::XMMRegisterID destId)); |
| 112 |
|
| 113 |
public: |
| 114 |
using MacroAssemblerX86Shared::call; |
| 115 |
using MacroAssemblerX86Shared::load32; |
| 116 |
using MacroAssemblerX86Shared::store16; |
| 117 |
using MacroAssemblerX86Shared::store32; |
| 118 |
|
| 119 |
MacroAssemblerX86() {} |
| 120 |
|
| 121 |
// The buffer is about to be linked, make sure any constant pools or excess |
| 122 |
// bookkeeping has been flushed to the instruction stream. |
| 123 |
void finish(); |
| 124 |
|
| 125 |
///////////////////////////////////////////////////////////////// |
| 126 |
// X86-specific interface. |
| 127 |
///////////////////////////////////////////////////////////////// |
| 128 |
|
| 129 |
Operand ToPayload(Operand base) { return base; } |
| 130 |
Address ToPayload(Address base) { return base; } |
| 131 |
BaseIndex ToPayload(BaseIndex base) { return base; } |
| 132 |
Operand ToType(Operand base) { |
| 133 |
switch (base.kind()) { |
| 134 |
case Operand::MEM_REG_DISP: |
| 135 |
return Operand(Register::FromCode(base.base()), |
| 136 |
base.disp() + sizeof(void*)); |
| 137 |
|
| 138 |
case Operand::MEM_SCALE: |
| 139 |
return Operand(Register::FromCode(base.base()), |
| 140 |
Register::FromCode(base.index()), base.scale(), |
| 141 |
base.disp() + sizeof(void*)); |
| 142 |
|
| 143 |
default: |
| 144 |
MOZ_CRASH("unexpected operand kind"); |
| 145 |
} |
| 146 |
} |
| 147 |
Address ToType(Address base) { return ToType(Operand(base)).toAddress(); } |
| 148 |
BaseIndex ToType(BaseIndex base) { |
| 149 |
return ToType(Operand(base)).toBaseIndex(); |
| 150 |
} |
| 151 |
|
| 152 |
template <typename T> |
| 153 |
void add64FromMemory(const T& address, Register64 dest) { |
| 154 |
addl(Operand(LowWord(address)), dest.low); |
| 155 |
adcl(Operand(HighWord(address)), dest.high); |
| 156 |
} |
| 157 |
template <typename T> |
| 158 |
void sub64FromMemory(const T& address, Register64 dest) { |
| 159 |
subl(Operand(LowWord(address)), dest.low); |
| 160 |
sbbl(Operand(HighWord(address)), dest.high); |
| 161 |
} |
| 162 |
template <typename T> |
| 163 |
void and64FromMemory(const T& address, Register64 dest) { |
| 164 |
andl(Operand(LowWord(address)), dest.low); |
| 165 |
andl(Operand(HighWord(address)), dest.high); |
| 166 |
} |
| 167 |
template <typename T> |
| 168 |
void or64FromMemory(const T& address, Register64 dest) { |
| 169 |
orl(Operand(LowWord(address)), dest.low); |
| 170 |
orl(Operand(HighWord(address)), dest.high); |
| 171 |
} |
| 172 |
template <typename T> |
| 173 |
void xor64FromMemory(const T& address, Register64 dest) { |
| 174 |
xorl(Operand(LowWord(address)), dest.low); |
| 175 |
xorl(Operand(HighWord(address)), dest.high); |
| 176 |
} |
| 177 |
|
| 178 |
template <typename T1, typename T2> |
| 179 |
inline void cmp64SetAliased(Condition cond, T1 lhs, T2 rhs, Register dest); |
| 180 |
|
| 181 |
template <typename T1, typename T2> |
| 182 |
inline void cmp64SetNonAliased(Condition cond, T1 lhs, T2 rhs, Register dest); |
| 183 |
|
| 184 |
template <typename T1, typename T2> |
| 185 |
inline void branch64Impl(Condition cond, T1 lhs, T2 rhs, Label* success, |
| 186 |
Label* fail); |
| 187 |
|
| 188 |
///////////////////////////////////////////////////////////////// |
| 189 |
// X86/X64-common interface. |
| 190 |
///////////////////////////////////////////////////////////////// |
| 191 |
void storeValue(ValueOperand val, Operand dest) { |
| 192 |
movl(val.payloadReg(), ToPayload(dest)); |
| 193 |
movl(val.typeReg(), ToType(dest)); |
| 194 |
} |
| 195 |
void storeValue(ValueOperand val, const Address& dest) { |
| 196 |
storeValue(val, Operand(dest)); |
| 197 |
} |
| 198 |
template <typename T> |
| 199 |
void storeValue(JSValueType type, Register reg, const T& dest) { |
| 200 |
storeTypeTag(ImmTag(JSVAL_TYPE_TO_TAG(type)), Operand(dest)); |
| 201 |
storePayload(reg, Operand(dest)); |
| 202 |
} |
| 203 |
template <typename T> |
| 204 |
void storeValue(const Value& val, const T& dest) { |
| 205 |
storeTypeTag(ImmTag(val.toNunboxTag()), Operand(dest)); |
| 206 |
storePayload(val, Operand(dest)); |
| 207 |
} |
| 208 |
void storeValue(ValueOperand val, BaseIndex dest) { |
| 209 |
storeValue(val, Operand(dest)); |
| 210 |
} |
| 211 |
void storeValue(const Address& src, const Address& dest, Register temp) { |
| 212 |
MOZ_ASSERT(src.base != temp); |
| 213 |
MOZ_ASSERT(dest.base != temp); |
| 214 |
|
| 215 |
load32(ToType(src), temp); |
| 216 |
store32(temp, ToType(dest)); |
| 217 |
|
| 218 |
load32(ToPayload(src), temp); |
| 219 |
store32(temp, ToPayload(dest)); |
| 220 |
} |
| 221 |
void storePrivateValue(Register src, const Address& dest) { |
| 222 |
store32(Imm32(0), ToType(dest)); |
| 223 |
store32(src, ToPayload(dest)); |
| 224 |
} |
| 225 |
void storePrivateValue(ImmGCPtr imm, const Address& dest) { |
| 226 |
store32(Imm32(0), ToType(dest)); |
| 227 |
movl(imm, Operand(ToPayload(dest))); |
| 228 |
} |
| 229 |
void loadValue(Operand src, ValueOperand val) { |
| 230 |
Operand payload = ToPayload(src); |
| 231 |
Operand type = ToType(src); |
| 232 |
|
| 233 |
// Ensure that loading the payload does not erase the pointer to the |
| 234 |
// Value in memory or the index. |
| 235 |
Register baseReg = Register::FromCode(src.base()); |
| 236 |
Register indexReg = (src.kind() == Operand::MEM_SCALE) |
| 237 |
? Register::FromCode(src.index()) |
| 238 |
: InvalidReg; |
| 239 |
|
| 240 |
// If we have a BaseIndex that uses both result registers, first compute |
| 241 |
// the address and then load the Value from there. |
| 242 |
if ((baseReg == val.payloadReg() && indexReg == val.typeReg()) || |
| 243 |
(baseReg == val.typeReg() && indexReg == val.payloadReg())) { |
| 244 |
computeEffectiveAddress(src, val.scratchReg()); |
| 245 |
loadValue(Address(val.scratchReg(), 0), val); |
| 246 |
return; |
| 247 |
} |
| 248 |
|
| 249 |
if (baseReg == val.payloadReg() || indexReg == val.payloadReg()) { |
| 250 |
MOZ_ASSERT(baseReg != val.typeReg()); |
| 251 |
MOZ_ASSERT(indexReg != val.typeReg()); |
| 252 |
|
| 253 |
movl(type, val.typeReg()); |
| 254 |
movl(payload, val.payloadReg()); |
| 255 |
} else { |
| 256 |
MOZ_ASSERT(baseReg != val.payloadReg()); |
| 257 |
MOZ_ASSERT(indexReg != val.payloadReg()); |
| 258 |
|
| 259 |
movl(payload, val.payloadReg()); |
| 260 |
movl(type, val.typeReg()); |
| 261 |
} |
| 262 |
} |
| 263 |
void loadValue(Address src, ValueOperand val) { |
| 264 |
loadValue(Operand(src), val); |
| 265 |
} |
| 266 |
void loadValue(const BaseIndex& src, ValueOperand val) { |
| 267 |
loadValue(Operand(src), val); |
| 268 |
} |
| 269 |
void loadUnalignedValue(const Address& src, ValueOperand dest) { |
| 270 |
loadValue(src, dest); |
| 271 |
} |
| 272 |
void tagValue(JSValueType type, Register payload, ValueOperand dest) { |
| 273 |
MOZ_ASSERT(dest.typeReg() != dest.payloadReg()); |
| 274 |
if (payload != dest.payloadReg()) { |
| 275 |
movl(payload, dest.payloadReg()); |
| 276 |
} |
| 277 |
movl(ImmType(type), dest.typeReg()); |
| 278 |
} |
| 279 |
void pushValue(ValueOperand val) { |
| 280 |
push(val.typeReg()); |
| 281 |
push(val.payloadReg()); |
| 282 |
} |
| 283 |
void popValue(ValueOperand val) { |
| 284 |
pop(val.payloadReg()); |
| 285 |
pop(val.typeReg()); |
| 286 |
} |
| 287 |
void pushValue(const Value& val) { |
| 288 |
push(Imm32(val.toNunboxTag())); |
| 289 |
if (val.isGCThing()) { |
| 290 |
push(ImmGCPtr(val.toGCThing())); |
| 291 |
} else { |
| 292 |
push(Imm32(val.toNunboxPayload())); |
| 293 |
} |
| 294 |
} |
| 295 |
void pushValue(JSValueType type, Register reg) { |
| 296 |
push(ImmTag(JSVAL_TYPE_TO_TAG(type))); |
| 297 |
push(reg); |
| 298 |
} |
| 299 |
void pushValue(const Address& addr) { |
| 300 |
push(tagOf(addr)); |
| 301 |
push(payloadOfAfterStackPush(addr)); |
| 302 |
} |
| 303 |
void pushValue(const BaseIndex& addr, Register scratch) { |
| 304 |
push(tagOf(addr)); |
| 305 |
push(payloadOfAfterStackPush(addr)); |
| 306 |
} |
| 307 |
void push64(Register64 src) { |
| 308 |
push(src.high); |
| 309 |
push(src.low); |
| 310 |
} |
| 311 |
void pop64(Register64 dest) { |
| 312 |
pop(dest.low); |
| 313 |
pop(dest.high); |
| 314 |
} |
| 315 |
void storePayload(const Value& val, Operand dest) { |
| 316 |
if (val.isGCThing()) { |
| 317 |
movl(ImmGCPtr(val.toGCThing()), ToPayload(dest)); |
| 318 |
} else { |
| 319 |
movl(Imm32(val.toNunboxPayload()), ToPayload(dest)); |
| 320 |
} |
| 321 |
} |
| 322 |
void storePayload(Register src, Operand dest) { movl(src, ToPayload(dest)); } |
| 323 |
void storeTypeTag(ImmTag tag, Operand dest) { movl(tag, ToType(dest)); } |
| 324 |
|
| 325 |
void movePtr(Register src, Register dest) { movl(src, dest); } |
| 326 |
void movePtr(Register src, const Operand& dest) { movl(src, dest); } |
| 327 |
|
| 328 |
void splitTagForTest(const ValueOperand& value, ScratchTagScope& tag) { |
| 329 |
MOZ_ASSERT(value.typeReg() == tag); |
| 330 |
} |
| 331 |
|
| 332 |
Condition testUndefined(Condition cond, Register tag) { |
| 333 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 334 |
cmp32(tag, ImmTag(JSVAL_TAG_UNDEFINED)); |
| 335 |
return cond; |
| 336 |
} |
| 337 |
Condition testBoolean(Condition cond, Register tag) { |
| 338 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 339 |
cmp32(tag, ImmTag(JSVAL_TAG_BOOLEAN)); |
| 340 |
return cond; |
| 341 |
} |
| 342 |
Condition testInt32(Condition cond, Register tag) { |
| 343 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 344 |
cmp32(tag, ImmTag(JSVAL_TAG_INT32)); |
| 345 |
return cond; |
| 346 |
} |
| 347 |
Condition testDouble(Condition cond, Register tag) { |
| 348 |
MOZ_ASSERT(cond == Assembler::Equal || cond == Assembler::NotEqual); |
| 349 |
Condition actual = (cond == Equal) ? Below : AboveOrEqual; |
| 350 |
cmp32(tag, ImmTag(JSVAL_TAG_CLEAR)); |
| 351 |
return actual; |
| 352 |
} |
| 353 |
Condition testNull(Condition cond, Register tag) { |
| 354 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 355 |
cmp32(tag, ImmTag(JSVAL_TAG_NULL)); |
| 356 |
return cond; |
| 357 |
} |
| 358 |
Condition testString(Condition cond, Register tag) { |
| 359 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 360 |
cmp32(tag, ImmTag(JSVAL_TAG_STRING)); |
| 361 |
return cond; |
| 362 |
} |
| 363 |
Condition testSymbol(Condition cond, Register tag) { |
| 364 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 365 |
cmp32(tag, ImmTag(JSVAL_TAG_SYMBOL)); |
| 366 |
return cond; |
| 367 |
} |
| 368 |
Condition testBigInt(Condition cond, Register tag) { |
| 369 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 370 |
cmp32(tag, ImmTag(JSVAL_TAG_BIGINT)); |
| 371 |
return cond; |
| 372 |
} |
| 373 |
Condition testObject(Condition cond, Register tag) { |
| 374 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 375 |
cmp32(tag, ImmTag(JSVAL_TAG_OBJECT)); |
| 376 |
return cond; |
| 377 |
} |
| 378 |
Condition testNumber(Condition cond, Register tag) { |
| 379 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 380 |
cmp32(tag, ImmTag(JS::detail::ValueUpperInclNumberTag)); |
| 381 |
return cond == Equal ? BelowOrEqual : Above; |
| 382 |
} |
| 383 |
Condition testGCThing(Condition cond, Register tag) { |
| 384 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 385 |
cmp32(tag, ImmTag(JS::detail::ValueLowerInclGCThingTag)); |
| 386 |
return cond == Equal ? AboveOrEqual : Below; |
| 387 |
} |
| 388 |
Condition testGCThing(Condition cond, const Address& address) { |
| 389 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 390 |
cmp32(tagOf(address), ImmTag(JS::detail::ValueLowerInclGCThingTag)); |
| 391 |
return cond == Equal ? AboveOrEqual : Below; |
| 392 |
} |
| 393 |
Condition testMagic(Condition cond, const Address& address) { |
| 394 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 395 |
cmp32(tagOf(address), ImmTag(JSVAL_TAG_MAGIC)); |
| 396 |
return cond; |
| 397 |
} |
| 398 |
Condition testMagic(Condition cond, Register tag) { |
| 399 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 400 |
cmp32(tag, ImmTag(JSVAL_TAG_MAGIC)); |
| 401 |
return cond; |
| 402 |
} |
| 403 |
Condition testMagic(Condition cond, const Operand& operand) { |
| 404 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 405 |
cmp32(ToType(operand), ImmTag(JSVAL_TAG_MAGIC)); |
| 406 |
return cond; |
| 407 |
} |
| 408 |
Condition testPrimitive(Condition cond, Register tag) { |
| 409 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 410 |
cmp32(tag, ImmTag(JS::detail::ValueUpperExclPrimitiveTag)); |
| 411 |
return cond == Equal ? Below : AboveOrEqual; |
| 412 |
} |
| 413 |
Condition testError(Condition cond, Register tag) { |
| 414 |
return testMagic(cond, tag); |
| 415 |
} |
| 416 |
Condition testBoolean(Condition cond, const Address& address) { |
| 417 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 418 |
cmp32(Operand(ToType(address)), ImmTag(JSVAL_TAG_BOOLEAN)); |
| 419 |
return cond; |
| 420 |
} |
| 421 |
Condition testInt32(Condition cond, const Operand& operand) { |
| 422 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 423 |
cmp32(ToType(operand), ImmTag(JSVAL_TAG_INT32)); |
| 424 |
return cond; |
| 425 |
} |
| 426 |
Condition testInt32(Condition cond, const Address& address) { |
| 427 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 428 |
return testInt32(cond, Operand(address)); |
| 429 |
} |
| 430 |
Condition testObject(Condition cond, const Operand& operand) { |
| 431 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 432 |
cmp32(ToType(operand), ImmTag(JSVAL_TAG_OBJECT)); |
| 433 |
return cond; |
| 434 |
} |
| 435 |
Condition testObject(Condition cond, const Address& address) { |
| 436 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 437 |
return testObject(cond, Operand(address)); |
| 438 |
} |
| 439 |
Condition testDouble(Condition cond, const Operand& operand) { |
| 440 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 441 |
Condition actual = (cond == Equal) ? Below : AboveOrEqual; |
| 442 |
cmp32(ToType(operand), ImmTag(JSVAL_TAG_CLEAR)); |
| 443 |
return actual; |
| 444 |
} |
| 445 |
Condition testDouble(Condition cond, const Address& address) { |
| 446 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 447 |
return testDouble(cond, Operand(address)); |
| 448 |
} |
| 449 |
|
| 450 |
Condition testUndefined(Condition cond, const Operand& operand) { |
| 451 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 452 |
cmp32(ToType(operand), ImmTag(JSVAL_TAG_UNDEFINED)); |
| 453 |
return cond; |
| 454 |
} |
| 455 |
Condition testUndefined(Condition cond, const Address& addr) { |
| 456 |
return testUndefined(cond, Operand(addr)); |
| 457 |
} |
| 458 |
Condition testNull(Condition cond, const Operand& operand) { |
| 459 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 460 |
cmp32(ToType(operand), ImmTag(JSVAL_TAG_NULL)); |
| 461 |
return cond; |
| 462 |
} |
| 463 |
Condition testNull(Condition cond, const Address& addr) { |
| 464 |
return testNull(cond, Operand(addr)); |
| 465 |
} |
| 466 |
|
| 467 |
Condition testUndefined(Condition cond, const ValueOperand& value) { |
| 468 |
return testUndefined(cond, value.typeReg()); |
| 469 |
} |
| 470 |
Condition testBoolean(Condition cond, const ValueOperand& value) { |
| 471 |
return testBoolean(cond, value.typeReg()); |
| 472 |
} |
| 473 |
Condition testInt32(Condition cond, const ValueOperand& value) { |
| 474 |
return testInt32(cond, value.typeReg()); |
| 475 |
} |
| 476 |
Condition testDouble(Condition cond, const ValueOperand& value) { |
| 477 |
return testDouble(cond, value.typeReg()); |
| 478 |
} |
| 479 |
Condition testNull(Condition cond, const ValueOperand& value) { |
| 480 |
return testNull(cond, value.typeReg()); |
| 481 |
} |
| 482 |
Condition testString(Condition cond, const ValueOperand& value) { |
| 483 |
return testString(cond, value.typeReg()); |
| 484 |
} |
| 485 |
Condition testSymbol(Condition cond, const ValueOperand& value) { |
| 486 |
return testSymbol(cond, value.typeReg()); |
| 487 |
} |
| 488 |
Condition testBigInt(Condition cond, const ValueOperand& value) { |
| 489 |
return testBigInt(cond, value.typeReg()); |
| 490 |
} |
| 491 |
Condition testObject(Condition cond, const ValueOperand& value) { |
| 492 |
return testObject(cond, value.typeReg()); |
| 493 |
} |
| 494 |
Condition testMagic(Condition cond, const ValueOperand& value) { |
| 495 |
return testMagic(cond, value.typeReg()); |
| 496 |
} |
| 497 |
Condition testError(Condition cond, const ValueOperand& value) { |
| 498 |
return testMagic(cond, value); |
| 499 |
} |
| 500 |
Condition testNumber(Condition cond, const ValueOperand& value) { |
| 501 |
return testNumber(cond, value.typeReg()); |
| 502 |
} |
| 503 |
Condition testGCThing(Condition cond, const ValueOperand& value) { |
| 504 |
return testGCThing(cond, value.typeReg()); |
| 505 |
} |
| 506 |
Condition testPrimitive(Condition cond, const ValueOperand& value) { |
| 507 |
return testPrimitive(cond, value.typeReg()); |
| 508 |
} |
| 509 |
|
| 510 |
Condition testUndefined(Condition cond, const BaseIndex& address) { |
| 511 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 512 |
cmp32(tagOf(address), ImmTag(JSVAL_TAG_UNDEFINED)); |
| 513 |
return cond; |
| 514 |
} |
| 515 |
Condition testNull(Condition cond, const BaseIndex& address) { |
| 516 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 517 |
cmp32(tagOf(address), ImmTag(JSVAL_TAG_NULL)); |
| 518 |
return cond; |
| 519 |
} |
| 520 |
Condition testBoolean(Condition cond, const BaseIndex& address) { |
| 521 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 522 |
cmp32(tagOf(address), ImmTag(JSVAL_TAG_BOOLEAN)); |
| 523 |
return cond; |
| 524 |
} |
| 525 |
Condition testString(Condition cond, const Address& address) { |
| 526 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 527 |
cmp32(tagOf(address), ImmTag(JSVAL_TAG_STRING)); |
| 528 |
return cond; |
| 529 |
} |
| 530 |
Condition testString(Condition cond, const BaseIndex& address) { |
| 531 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 532 |
cmp32(tagOf(address), ImmTag(JSVAL_TAG_STRING)); |
| 533 |
return cond; |
| 534 |
} |
| 535 |
Condition testSymbol(Condition cond, const Address& address) { |
| 536 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 537 |
cmp32(tagOf(address), ImmTag(JSVAL_TAG_SYMBOL)); |
| 538 |
return cond; |
| 539 |
} |
| 540 |
Condition testSymbol(Condition cond, const BaseIndex& address) { |
| 541 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 542 |
cmp32(tagOf(address), ImmTag(JSVAL_TAG_SYMBOL)); |
| 543 |
return cond; |
| 544 |
} |
| 545 |
Condition testBigInt(Condition cond, const Address& address) { |
| 546 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 547 |
cmp32(tagOf(address), ImmTag(JSVAL_TAG_BIGINT)); |
| 548 |
return cond; |
| 549 |
} |
| 550 |
Condition testBigInt(Condition cond, const BaseIndex& address) { |
| 551 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 552 |
cmp32(tagOf(address), ImmTag(JSVAL_TAG_BIGINT)); |
| 553 |
return cond; |
| 554 |
} |
| 555 |
Condition testInt32(Condition cond, const BaseIndex& address) { |
| 556 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 557 |
cmp32(tagOf(address), ImmTag(JSVAL_TAG_INT32)); |
| 558 |
return cond; |
| 559 |
} |
| 560 |
Condition testObject(Condition cond, const BaseIndex& address) { |
| 561 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 562 |
cmp32(tagOf(address), ImmTag(JSVAL_TAG_OBJECT)); |
| 563 |
return cond; |
| 564 |
} |
| 565 |
Condition testDouble(Condition cond, const BaseIndex& address) { |
| 566 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 567 |
Condition actual = (cond == Equal) ? Below : AboveOrEqual; |
| 568 |
cmp32(tagOf(address), ImmTag(JSVAL_TAG_CLEAR)); |
| 569 |
return actual; |
| 570 |
} |
| 571 |
Condition testMagic(Condition cond, const BaseIndex& address) { |
| 572 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 573 |
cmp32(tagOf(address), ImmTag(JSVAL_TAG_MAGIC)); |
| 574 |
return cond; |
| 575 |
} |
| 576 |
Condition testGCThing(Condition cond, const BaseIndex& address) { |
| 577 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 578 |
cmp32(tagOf(address), ImmTag(JS::detail::ValueLowerInclGCThingTag)); |
| 579 |
return cond == Equal ? AboveOrEqual : Below; |
| 580 |
} |
| 581 |
|
| 582 |
void testNullSet(Condition cond, const ValueOperand& value, Register dest) { |
| 583 |
bool destIsZero = maybeEmitSetZeroByteRegister(value, dest); |
| 584 |
cond = testNull(cond, value); |
| 585 |
emitSet(cond, dest, destIsZero); |
| 586 |
} |
| 587 |
|
| 588 |
void testObjectSet(Condition cond, const ValueOperand& value, Register dest) { |
| 589 |
bool destIsZero = maybeEmitSetZeroByteRegister(value, dest); |
| 590 |
cond = testObject(cond, value); |
| 591 |
emitSet(cond, dest, destIsZero); |
| 592 |
} |
| 593 |
|
| 594 |
void testUndefinedSet(Condition cond, const ValueOperand& value, |
| 595 |
Register dest) { |
| 596 |
bool destIsZero = maybeEmitSetZeroByteRegister(value, dest); |
| 597 |
cond = testUndefined(cond, value); |
| 598 |
emitSet(cond, dest, destIsZero); |
| 599 |
} |
| 600 |
|
| 601 |
void cmpPtr(Register lhs, const Imm32 rhs) { cmpl(rhs, lhs); } |
| 602 |
void cmpPtr(Register lhs, const ImmWord rhs) { cmpl(Imm32(rhs.value), lhs); } |
| 603 |
void cmpPtr(Register lhs, const ImmPtr imm) { |
| 604 |
cmpPtr(lhs, ImmWord(uintptr_t(imm.value))); |
| 605 |
} |
| 606 |
void cmpPtr(Register lhs, const ImmGCPtr rhs) { cmpl(rhs, lhs); } |
| 607 |
void cmpPtr(const Operand& lhs, Imm32 rhs) { cmp32(lhs, rhs); } |
| 608 |
void cmpPtr(const Operand& lhs, const ImmWord rhs) { |
| 609 |
cmp32(lhs, Imm32(rhs.value)); |
| 610 |
} |
| 611 |
void cmpPtr(const Operand& lhs, const ImmPtr imm) { |
| 612 |
cmpPtr(lhs, ImmWord(uintptr_t(imm.value))); |
| 613 |
} |
| 614 |
void cmpPtr(const Operand& lhs, const ImmGCPtr rhs) { cmpl(rhs, lhs); } |
| 615 |
void cmpPtr(const Address& lhs, Register rhs) { cmpPtr(Operand(lhs), rhs); } |
| 616 |
void cmpPtr(const Operand& lhs, Register rhs) { cmp32(lhs, rhs); } |
| 617 |
void cmpPtr(const Address& lhs, const ImmWord rhs) { |
| 618 |
cmpPtr(Operand(lhs), rhs); |
| 619 |
} |
| 620 |
void cmpPtr(const Address& lhs, const ImmPtr rhs) { |
| 621 |
cmpPtr(lhs, ImmWord(uintptr_t(rhs.value))); |
| 622 |
} |
| 623 |
void cmpPtr(const Address& lhs, const ImmGCPtr rhs) { |
| 624 |
cmpPtr(Operand(lhs), rhs); |
| 625 |
} |
| 626 |
void cmpPtr(Register lhs, Register rhs) { cmp32(lhs, rhs); } |
| 627 |
void testPtr(Register lhs, Register rhs) { test32(lhs, rhs); } |
| 628 |
void testPtr(Register lhs, Imm32 rhs) { test32(lhs, rhs); } |
| 629 |
void testPtr(Register lhs, ImmWord rhs) { test32(lhs, Imm32(rhs.value)); } |
| 630 |
void testPtr(const Operand& lhs, Imm32 rhs) { test32(lhs, rhs); } |
| 631 |
void testPtr(const Operand& lhs, ImmWord rhs) { |
| 632 |
test32(lhs, Imm32(rhs.value)); |
| 633 |
} |
| 634 |
|
| 635 |
///////////////////////////////////////////////////////////////// |
| 636 |
// Common interface. |
| 637 |
///////////////////////////////////////////////////////////////// |
| 638 |
|
| 639 |
void movePtr(ImmWord imm, Register dest) { movl(Imm32(imm.value), dest); } |
| 640 |
void movePtr(ImmPtr imm, Register dest) { movl(imm, dest); } |
| 641 |
void movePtr(wasm::SymbolicAddress imm, Register dest) { mov(imm, dest); } |
| 642 |
void movePtr(ImmGCPtr imm, Register dest) { movl(imm, dest); } |
| 643 |
FaultingCodeOffset loadPtr(const Address& address, Register dest) { |
| 644 |
FaultingCodeOffset fco = FaultingCodeOffset(currentOffset()); |
| 645 |
movl(Operand(address), dest); |
| 646 |
return fco; |
| 647 |
} |
| 648 |
void loadPtr(const Operand& src, Register dest) { movl(src, dest); } |
| 649 |
FaultingCodeOffset loadPtr(const BaseIndex& src, Register dest) { |
| 650 |
FaultingCodeOffset fco = FaultingCodeOffset(currentOffset()); |
| 651 |
movl(Operand(src), dest); |
| 652 |
return fco; |
| 653 |
} |
| 654 |
void loadPtr(AbsoluteAddress address, Register dest) { |
| 655 |
movl(Operand(address), dest); |
| 656 |
} |
| 657 |
void loadPrivate(const Address& src, Register dest) { |
| 658 |
movl(payloadOf(src), dest); |
| 659 |
} |
| 660 |
void load32(AbsoluteAddress address, Register dest) { |
| 661 |
movl(Operand(address), dest); |
| 662 |
} |
| 663 |
FaultingCodeOffsetPair load64(const Address& address, Register64 dest) { |
| 664 |
FaultingCodeOffset fco1, fco2; |
| 665 |
bool highBeforeLow = address.base == dest.low; |
| 666 |
if (highBeforeLow) { |
| 667 |
fco1 = FaultingCodeOffset(currentOffset()); |
| 668 |
movl(Operand(HighWord(address)), dest.high); |
| 669 |
fco2 = FaultingCodeOffset(currentOffset()); |
| 670 |
movl(Operand(LowWord(address)), dest.low); |
| 671 |
} else { |
| 672 |
fco1 = FaultingCodeOffset(currentOffset()); |
| 673 |
movl(Operand(LowWord(address)), dest.low); |
| 674 |
fco2 = FaultingCodeOffset(currentOffset()); |
| 675 |
movl(Operand(HighWord(address)), dest.high); |
| 676 |
} |
| 677 |
return FaultingCodeOffsetPair(fco1, fco2); |
| 678 |
} |
| 679 |
FaultingCodeOffsetPair load64(const BaseIndex& address, Register64 dest) { |
| 680 |
// If you run into this, relax your register allocation constraints. |
| 681 |
MOZ_RELEASE_ASSERT( |
| 682 |
!((address.base == dest.low || address.base == dest.high) && |
| 683 |
(address.index == dest.low || address.index == dest.high))); |
| 684 |
FaultingCodeOffset fco1, fco2; |
| 685 |
bool highBeforeLow = address.base == dest.low || address.index == dest.low; |
| 686 |
if (highBeforeLow) { |
| 687 |
fco1 = FaultingCodeOffset(currentOffset()); |
| 688 |
movl(Operand(HighWord(address)), dest.high); |
| 689 |
fco2 = FaultingCodeOffset(currentOffset()); |
| 690 |
movl(Operand(LowWord(address)), dest.low); |
| 691 |
} else { |
| 692 |
fco1 = FaultingCodeOffset(currentOffset()); |
| 693 |
movl(Operand(LowWord(address)), dest.low); |
| 694 |
fco2 = FaultingCodeOffset(currentOffset()); |
| 695 |
movl(Operand(HighWord(address)), dest.high); |
| 696 |
} |
| 697 |
return FaultingCodeOffsetPair(fco1, fco2); |
| 698 |
} |
| 699 |
template <typename T> |
| 700 |
void load64Unaligned(const T& address, Register64 dest) { |
| 701 |
load64(address, dest); |
| 702 |
} |
| 703 |
template <typename T> |
| 704 |
void storePtr(ImmWord imm, T address) { |
| 705 |
movl(Imm32(imm.value), Operand(address)); |
| 706 |
} |
| 707 |
template <typename T> |
| 708 |
void storePtr(ImmPtr imm, T address) { |
| 709 |
storePtr(ImmWord(uintptr_t(imm.value)), address); |
| 710 |
} |
| 711 |
template <typename T> |
| 712 |
void storePtr(ImmGCPtr imm, T address) { |
| 713 |
movl(imm, Operand(address)); |
| 714 |
} |
| 715 |
FaultingCodeOffset storePtr(Register src, const Address& address) { |
| 716 |
FaultingCodeOffset fco = FaultingCodeOffset(currentOffset()); |
| 717 |
movl(src, Operand(address)); |
| 718 |
return fco; |
| 719 |
} |
| 720 |
FaultingCodeOffset storePtr(Register src, const BaseIndex& address) { |
| 721 |
FaultingCodeOffset fco = FaultingCodeOffset(currentOffset()); |
| 722 |
movl(src, Operand(address)); |
| 723 |
return fco; |
| 724 |
} |
| 725 |
void storePtr(Register src, const Operand& dest) { movl(src, dest); } |
| 726 |
void storePtr(Register src, AbsoluteAddress address) { |
| 727 |
movl(src, Operand(address)); |
| 728 |
} |
| 729 |
void store32(Register src, AbsoluteAddress address) { |
| 730 |
movl(src, Operand(address)); |
| 731 |
} |
| 732 |
void store16(Register src, AbsoluteAddress address) { |
| 733 |
movw(src, Operand(address)); |
| 734 |
} |
| 735 |
template <typename T> |
| 736 |
FaultingCodeOffsetPair store64(Register64 src, const T& address) { |
| 737 |
FaultingCodeOffset fco1 = FaultingCodeOffset(currentOffset()); |
| 738 |
movl(src.low, Operand(LowWord(address))); |
| 739 |
FaultingCodeOffset fco2 = FaultingCodeOffset(currentOffset()); |
| 740 |
movl(src.high, Operand(HighWord(address))); |
| 741 |
return FaultingCodeOffsetPair(fco1, fco2); |
| 742 |
} |
| 743 |
void store64(Imm64 imm, Address address) { |
| 744 |
movl(imm.low(), Operand(LowWord(address))); |
| 745 |
movl(imm.hi(), Operand(HighWord(address))); |
| 746 |
} |
| 747 |
void store64(Imm64 imm, const BaseIndex& address) { |
| 748 |
movl(imm.low(), Operand(LowWord(address))); |
| 749 |
movl(imm.hi(), Operand(HighWord(address))); |
| 750 |
} |
| 751 |
template <typename S, typename T> |
| 752 |
void store64Unaligned(const S& src, const T& dest) { |
| 753 |
store64(src, dest); |
| 754 |
} |
| 755 |
|
| 756 |
void setStackArg(Register reg, uint32_t arg) { |
| 757 |
movl(reg, Operand(esp, arg * sizeof(intptr_t))); |
| 758 |
} |
| 759 |
|
| 760 |
void boxDouble(FloatRegister src, const ValueOperand& dest, |
| 761 |
FloatRegister temp) { |
| 762 |
if (Assembler::HasSSE41()) { |
| 763 |
vmovd(src, dest.payloadReg()); |
| 764 |
vpextrd(1, src, dest.typeReg()); |
| 765 |
} else { |
| 766 |
vmovd(src, dest.payloadReg()); |
| 767 |
if (src != temp) { |
| 768 |
moveDouble(src, temp); |
| 769 |
} |
| 770 |
vpsrldq(Imm32(4), temp, temp); |
| 771 |
vmovd(temp, dest.typeReg()); |
| 772 |
} |
| 773 |
} |
| 774 |
void boxNonDouble(JSValueType type, Register src, const ValueOperand& dest) { |
| 775 |
if (src != dest.payloadReg()) { |
| 776 |
movl(src, dest.payloadReg()); |
| 777 |
} |
| 778 |
movl(ImmType(type), dest.typeReg()); |
| 779 |
} |
| 780 |
|
| 781 |
void unboxNonDouble(const ValueOperand& src, Register dest, JSValueType type, |
| 782 |
Register scratch = InvalidReg) { |
| 783 |
unboxNonDouble(Operand(src.typeReg()), Operand(src.payloadReg()), dest, |
| 784 |
type, scratch); |
| 785 |
} |
| 786 |
void unboxNonDouble(const Operand& tag, const Operand& payload, Register dest, |
| 787 |
JSValueType type, Register scratch = InvalidReg) { |
| 788 |
auto movPayloadToDest = [&]() { |
| 789 |
if (payload.kind() != Operand::REG || !payload.containsReg(dest)) { |
| 790 |
movl(payload, dest); |
| 791 |
} |
| 792 |
}; |
| 793 |
if (!JitOptions.spectreValueMasking) { |
| 794 |
movPayloadToDest(); |
| 795 |
return; |
| 796 |
} |
| 797 |
|
| 798 |
// Spectre mitigation: We zero the payload if the tag does not match the |
| 799 |
// expected type and if this is a pointer type. |
| 800 |
if (type == JSVAL_TYPE_INT32 || type == JSVAL_TYPE_BOOLEAN) { |
| 801 |
movPayloadToDest(); |
| 802 |
return; |
| 803 |
} |
| 804 |
|
| 805 |
if (!tag.containsReg(dest) && !payload.containsReg(dest)) { |
| 806 |
// We zero the destination register and move the payload into it if |
| 807 |
// the tag corresponds to the given type. |
| 808 |
xorl(dest, dest); |
| 809 |
cmpl(Imm32(JSVAL_TYPE_TO_TAG(type)), tag); |
| 810 |
cmovCCl(Condition::Equal, payload, dest); |
| 811 |
return; |
| 812 |
} |
| 813 |
|
| 814 |
if (scratch == InvalidReg || scratch == dest || tag.containsReg(scratch) || |
| 815 |
payload.containsReg(scratch)) { |
| 816 |
// UnboxedLayout::makeConstructorCode calls extractObject with a |
| 817 |
// scratch register which aliases the tag register, thus we cannot |
| 818 |
// assert the above condition. |
| 819 |
scratch = InvalidReg; |
| 820 |
} |
| 821 |
|
| 822 |
// The destination register aliases one of the operands. We create a |
| 823 |
// zero value either in a scratch register or on the stack and use it |
| 824 |
// to reset the destination register after reading both the tag and the |
| 825 |
// payload. |
| 826 |
Operand zero(Address(esp, 0)); |
| 827 |
if (scratch == InvalidReg) { |
| 828 |
push(Imm32(0)); |
| 829 |
} else { |
| 830 |
xorl(scratch, scratch); |
| 831 |
zero = Operand(scratch); |
| 832 |
} |
| 833 |
cmpl(Imm32(JSVAL_TYPE_TO_TAG(type)), tag); |
| 834 |
movPayloadToDest(); |
| 835 |
cmovCCl(Condition::NotEqual, zero, dest); |
| 836 |
if (scratch == InvalidReg) { |
| 837 |
addl(Imm32(sizeof(void*)), esp); |
| 838 |
} |
| 839 |
} |
| 840 |
void unboxNonDouble(const Address& src, Register dest, JSValueType type) { |
| 841 |
unboxNonDouble(tagOf(src), payloadOf(src), dest, type); |
| 842 |
} |
| 843 |
void unboxNonDouble(const BaseIndex& src, Register dest, JSValueType type) { |
| 844 |
unboxNonDouble(tagOf(src), payloadOf(src), dest, type); |
| 845 |
} |
| 846 |
void unboxInt32(const ValueOperand& src, Register dest) { |
| 847 |
unboxNonDouble(src, dest, JSVAL_TYPE_INT32); |
| 848 |
} |
| 849 |
void unboxInt32(const Address& src, Register dest) { |
| 850 |
unboxNonDouble(src, dest, JSVAL_TYPE_INT32); |
| 851 |
} |
| 852 |
void unboxInt32(const BaseIndex& src, Register dest) { |
| 853 |
unboxNonDouble(src, dest, JSVAL_TYPE_INT32); |
| 854 |
} |
| 855 |
void unboxBoolean(const ValueOperand& src, Register dest) { |
| 856 |
unboxNonDouble(src, dest, JSVAL_TYPE_BOOLEAN); |
| 857 |
} |
| 858 |
void unboxBoolean(const Address& src, Register dest) { |
| 859 |
unboxNonDouble(src, dest, JSVAL_TYPE_BOOLEAN); |
| 860 |
} |
| 861 |
void unboxBoolean(const BaseIndex& src, Register dest) { |
| 862 |
unboxNonDouble(src, dest, JSVAL_TYPE_BOOLEAN); |
| 863 |
} |
| 864 |
void unboxString(const ValueOperand& src, Register dest) { |
| 865 |
unboxNonDouble(src, dest, JSVAL_TYPE_STRING); |
| 866 |
} |
| 867 |
void unboxString(const Address& src, Register dest) { |
| 868 |
unboxNonDouble(src, dest, JSVAL_TYPE_STRING); |
| 869 |
} |
| 870 |
void unboxSymbol(const ValueOperand& src, Register dest) { |
| 871 |
unboxNonDouble(src, dest, JSVAL_TYPE_SYMBOL); |
| 872 |
} |
| 873 |
void unboxSymbol(const Address& src, Register dest) { |
| 874 |
unboxNonDouble(src, dest, JSVAL_TYPE_SYMBOL); |
| 875 |
} |
| 876 |
void unboxBigInt(const ValueOperand& src, Register dest) { |
| 877 |
unboxNonDouble(src, dest, JSVAL_TYPE_BIGINT); |
| 878 |
} |
| 879 |
void unboxBigInt(const Address& src, Register dest) { |
| 880 |
unboxNonDouble(src, dest, JSVAL_TYPE_BIGINT); |
| 881 |
} |
| 882 |
void unboxObject(const ValueOperand& src, Register dest) { |
| 883 |
unboxNonDouble(src, dest, JSVAL_TYPE_OBJECT); |
| 884 |
} |
| 885 |
void unboxObject(const Address& src, Register dest) { |
| 886 |
unboxNonDouble(src, dest, JSVAL_TYPE_OBJECT); |
| 887 |
} |
| 888 |
void unboxObject(const BaseIndex& src, Register dest) { |
| 889 |
unboxNonDouble(src, dest, JSVAL_TYPE_OBJECT); |
| 890 |
} |
| 891 |
template <typename T> |
| 892 |
void unboxObjectOrNull(const T& src, Register dest) { |
| 893 |
// Due to Spectre mitigation logic (see Value.h), if the value is an Object |
| 894 |
// then this yields the object; otherwise it yields zero (null), as desired. |
| 895 |
unboxNonDouble(src, dest, JSVAL_TYPE_OBJECT); |
| 896 |
} |
| 897 |
template <typename T> |
| 898 |
void unboxDouble(const T& src, FloatRegister dest) { |
| 899 |
loadDouble(Operand(src), dest); |
| 900 |
} |
| 901 |
void unboxDouble(const ValueOperand& src, FloatRegister dest) { |
| 902 |
if (Assembler::HasSSE41()) { |
| 903 |
vmovd(src.payloadReg(), dest); |
| 904 |
vpinsrd(1, src.typeReg(), dest, dest); |
| 905 |
} else { |
| 906 |
ScratchDoubleScope fpscratch(asMasm()); |
| 907 |
vmovd(src.payloadReg(), dest); |
| 908 |
vmovd(src.typeReg(), fpscratch); |
| 909 |
vunpcklps(fpscratch, dest, dest); |
| 910 |
} |
| 911 |
} |
| 912 |
void unboxDouble(const Operand& payload, const Operand& type, |
| 913 |
Register scratch, FloatRegister dest) { |
| 914 |
if (Assembler::HasSSE41()) { |
| 915 |
movl(payload, scratch); |
| 916 |
vmovd(scratch, dest); |
| 917 |
movl(type, scratch); |
| 918 |
vpinsrd(1, scratch, dest, dest); |
| 919 |
} else { |
| 920 |
ScratchDoubleScope fpscratch(asMasm()); |
| 921 |
movl(payload, scratch); |
| 922 |
vmovd(scratch, dest); |
| 923 |
movl(type, scratch); |
| 924 |
vmovd(scratch, fpscratch); |
| 925 |
vunpcklps(fpscratch, dest, dest); |
| 926 |
} |
| 927 |
} |
| 928 |
inline void unboxValue(const ValueOperand& src, AnyRegister dest, |
| 929 |
JSValueType type); |
| 930 |
|
| 931 |
// See comment in MacroAssembler-x64.h. |
| 932 |
void unboxGCThingForGCBarrier(const Address& src, Register dest) { |
| 933 |
movl(payloadOf(src), dest); |
| 934 |
} |
| 935 |
|
| 936 |
void unboxWasmAnyRefGCThingForGCBarrier(const Address& src, Register dest) { |
| 937 |
movl(ImmWord(wasm::AnyRef::GCThingMask), dest); |
| 938 |
andl(Operand(src), dest); |
| 939 |
} |
| 940 |
|
| 941 |
void getWasmAnyRefGCThingChunk(Register src, Register dest) { |
| 942 |
MOZ_ASSERT(src != dest); |
| 943 |
movl(ImmWord(wasm::AnyRef::GCThingChunkMask), dest); |
| 944 |
andl(src, dest); |
| 945 |
} |
| 946 |
|
| 947 |
void notBoolean(const ValueOperand& val) { xorl(Imm32(1), val.payloadReg()); } |
| 948 |
|
| 949 |
template <typename T> |
| 950 |
void fallibleUnboxPtrImpl(const T& src, Register dest, JSValueType type, |
| 951 |
Label* fail); |
| 952 |
|
| 953 |
// Extended unboxing API. If the payload is already in a register, returns |
| 954 |
// that register. Otherwise, provides a move to the given scratch register, |
| 955 |
// and returns that. |
| 956 |
[[nodiscard]] Register extractObject(const Address& address, Register dest) { |
| 957 |
unboxObject(address, dest); |
| 958 |
return dest; |
| 959 |
} |
| 960 |
[[nodiscard]] Register extractObject(const ValueOperand& value, |
| 961 |
Register scratch) { |
| 962 |
unboxNonDouble(value, value.payloadReg(), JSVAL_TYPE_OBJECT, scratch); |
| 963 |
return value.payloadReg(); |
| 964 |
} |
| 965 |
[[nodiscard]] Register extractSymbol(const ValueOperand& value, |
| 966 |
Register scratch) { |
| 967 |
unboxNonDouble(value, value.payloadReg(), JSVAL_TYPE_SYMBOL, scratch); |
| 968 |
return value.payloadReg(); |
| 969 |
} |
| 970 |
[[nodiscard]] Register extractInt32(const ValueOperand& value, |
| 971 |
Register scratch) { |
| 972 |
return value.payloadReg(); |
| 973 |
} |
| 974 |
[[nodiscard]] Register extractBoolean(const ValueOperand& value, |
| 975 |
Register scratch) { |
| 976 |
return value.payloadReg(); |
| 977 |
} |
| 978 |
[[nodiscard]] Register extractTag(const Address& address, Register scratch) { |
| 979 |
movl(tagOf(address), scratch); |
| 980 |
return scratch; |
| 981 |
} |
| 982 |
[[nodiscard]] Register extractTag(const ValueOperand& value, |
| 983 |
Register scratch) { |
| 984 |
return value.typeReg(); |
| 985 |
} |
| 986 |
|
| 987 |
void convertDoubleToPtr(FloatRegister src, Register dest, Label* fail, |
| 988 |
bool negativeZeroCheck = true) { |
| 989 |
convertDoubleToInt32(src, dest, fail, negativeZeroCheck); |
| 990 |
} |
| 991 |
|
| 992 |
void loadConstantDouble(double d, FloatRegister dest); |
| 993 |
void loadConstantFloat32(float f, FloatRegister dest); |
| 994 |
|
| 995 |
void loadConstantSimd128Int(const SimdConstant& v, FloatRegister dest); |
| 996 |
void loadConstantSimd128Float(const SimdConstant& v, FloatRegister dest); |
| 997 |
void vpaddbSimd128(const SimdConstant& v, FloatRegister lhs, |
| 998 |
FloatRegister dest); |
| 999 |
void vpaddwSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1000 |
FloatRegister dest); |
| 1001 |
void vpadddSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1002 |
FloatRegister dest); |
| 1003 |
void vpaddqSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1004 |
FloatRegister dest); |
| 1005 |
void vpsubbSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1006 |
FloatRegister dest); |
| 1007 |
void vpsubwSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1008 |
FloatRegister dest); |
| 1009 |
void vpsubdSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1010 |
FloatRegister dest); |
| 1011 |
void vpsubqSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1012 |
FloatRegister dest); |
| 1013 |
void vpmullwSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1014 |
FloatRegister dest); |
| 1015 |
void vpmulldSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1016 |
FloatRegister dest); |
| 1017 |
void vpaddsbSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1018 |
FloatRegister dest); |
| 1019 |
void vpaddusbSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1020 |
FloatRegister dest); |
| 1021 |
void vpaddswSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1022 |
FloatRegister dest); |
| 1023 |
void vpadduswSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1024 |
FloatRegister dest); |
| 1025 |
void vpsubsbSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1026 |
FloatRegister dest); |
| 1027 |
void vpsubusbSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1028 |
FloatRegister dest); |
| 1029 |
void vpsubswSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1030 |
FloatRegister dest); |
| 1031 |
void vpsubuswSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1032 |
FloatRegister dest); |
| 1033 |
void vpminsbSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1034 |
FloatRegister dest); |
| 1035 |
void vpminubSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1036 |
FloatRegister dest); |
| 1037 |
void vpminswSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1038 |
FloatRegister dest); |
| 1039 |
void vpminuwSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1040 |
FloatRegister dest); |
| 1041 |
void vpminsdSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1042 |
FloatRegister dest); |
| 1043 |
void vpminudSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1044 |
FloatRegister dest); |
| 1045 |
void vpmaxsbSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1046 |
FloatRegister dest); |
| 1047 |
void vpmaxubSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1048 |
FloatRegister dest); |
| 1049 |
void vpmaxswSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1050 |
FloatRegister dest); |
| 1051 |
void vpmaxuwSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1052 |
FloatRegister dest); |
| 1053 |
void vpmaxsdSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1054 |
FloatRegister dest); |
| 1055 |
void vpmaxudSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1056 |
FloatRegister dest); |
| 1057 |
void vpandSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1058 |
FloatRegister dest); |
| 1059 |
void vpxorSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1060 |
FloatRegister dest); |
| 1061 |
void vporSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1062 |
FloatRegister dest); |
| 1063 |
void vaddpsSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1064 |
FloatRegister dest); |
| 1065 |
void vaddpdSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1066 |
FloatRegister dest); |
| 1067 |
void vsubpsSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1068 |
FloatRegister dest); |
| 1069 |
void vsubpdSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1070 |
FloatRegister dest); |
| 1071 |
void vdivpsSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1072 |
FloatRegister dest); |
| 1073 |
void vdivpdSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1074 |
FloatRegister dest); |
| 1075 |
void vmulpsSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1076 |
FloatRegister dest); |
| 1077 |
void vmulpdSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1078 |
FloatRegister dest); |
| 1079 |
void vandpdSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1080 |
FloatRegister dest); |
| 1081 |
void vminpdSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1082 |
FloatRegister dest); |
| 1083 |
void vpacksswbSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1084 |
FloatRegister dest); |
| 1085 |
void vpackuswbSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1086 |
FloatRegister dest); |
| 1087 |
void vpackssdwSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1088 |
FloatRegister dest); |
| 1089 |
void vpackusdwSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1090 |
FloatRegister dest); |
| 1091 |
void vpunpckldqSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1092 |
FloatRegister dest); |
| 1093 |
void vunpcklpsSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1094 |
FloatRegister dest); |
| 1095 |
void vpshufbSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1096 |
FloatRegister dest); |
| 1097 |
void vptestSimd128(const SimdConstant& v, FloatRegister lhs); |
| 1098 |
void vpmaddwdSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1099 |
FloatRegister dest); |
| 1100 |
void vpcmpeqbSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1101 |
FloatRegister dest); |
| 1102 |
void vpcmpgtbSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1103 |
FloatRegister dest); |
| 1104 |
void vpcmpeqwSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1105 |
FloatRegister dest); |
| 1106 |
void vpcmpgtwSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1107 |
FloatRegister dest); |
| 1108 |
void vpcmpeqdSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1109 |
FloatRegister dest); |
| 1110 |
void vpcmpgtdSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1111 |
FloatRegister dest); |
| 1112 |
void vcmpeqpsSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1113 |
FloatRegister dest); |
| 1114 |
void vcmpneqpsSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1115 |
FloatRegister dest); |
| 1116 |
void vcmpltpsSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1117 |
FloatRegister dest); |
| 1118 |
void vcmplepsSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1119 |
FloatRegister dest); |
| 1120 |
void vcmpgepsSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1121 |
FloatRegister dest); |
| 1122 |
void vcmpeqpdSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1123 |
FloatRegister dest); |
| 1124 |
void vcmpneqpdSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1125 |
FloatRegister dest); |
| 1126 |
void vcmpltpdSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1127 |
FloatRegister dest); |
| 1128 |
void vcmplepdSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1129 |
FloatRegister dest); |
| 1130 |
void vpmaddubswSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1131 |
FloatRegister dest); |
| 1132 |
void vpmuludqSimd128(const SimdConstant& v, FloatRegister lhs, |
| 1133 |
FloatRegister dest); |
| 1134 |
|
| 1135 |
Condition testInt32Truthy(bool truthy, const ValueOperand& operand) { |
| 1136 |
test32(operand.payloadReg(), operand.payloadReg()); |
| 1137 |
return truthy ? NonZero : Zero; |
| 1138 |
} |
| 1139 |
Condition testStringTruthy(bool truthy, const ValueOperand& value); |
| 1140 |
Condition testBigIntTruthy(bool truthy, const ValueOperand& value); |
| 1141 |
|
| 1142 |
template <typename T> |
| 1143 |
inline void loadInt32OrDouble(const T& src, FloatRegister dest); |
| 1144 |
|
| 1145 |
template <typename T> |
| 1146 |
inline void loadUnboxedValue(const T& src, MIRType type, AnyRegister dest); |
| 1147 |
|
| 1148 |
template <typename T> |
| 1149 |
void storeUnboxedPayload(ValueOperand value, T address, size_t nbytes, |
| 1150 |
JSValueType) { |
| 1151 |
switch (nbytes) { |
| 1152 |
case 4: |
| 1153 |
storePtr(value.payloadReg(), address); |
| 1154 |
return; |
| 1155 |
case 1: |
| 1156 |
store8(value.payloadReg(), address); |
| 1157 |
return; |
| 1158 |
default: |
| 1159 |
MOZ_CRASH("Bad payload width"); |
| 1160 |
} |
| 1161 |
} |
| 1162 |
|
| 1163 |
// Note: this function clobbers the source register. |
| 1164 |
inline void convertUInt32ToDouble(Register src, FloatRegister dest); |
| 1165 |
|
| 1166 |
// Note: this function clobbers the source register. |
| 1167 |
inline void convertUInt32ToFloat32(Register src, FloatRegister dest); |
| 1168 |
|
| 1169 |
void incrementInt32Value(const Address& addr) { |
| 1170 |
addl(Imm32(1), payloadOf(addr)); |
| 1171 |
} |
| 1172 |
|
| 1173 |
public: |
| 1174 |
// Used from within an Exit frame to handle a pending exception. |
| 1175 |
void handleFailureWithHandlerTail(Label* profilerExitTail, Label* bailoutTail, |
| 1176 |
uint32_t* returnValueCheckOffset); |
| 1177 |
|
| 1178 |
// Instrumentation for entering and leaving the profiler. |
| 1179 |
void profilerEnterFrame(Register framePtr, Register scratch); |
| 1180 |
void profilerExitFrame(); |
| 1181 |
}; |
| 1182 |
|
| 1183 |
using MacroAssemblerSpecific = MacroAssemblerX86; |
| 1184 |
|
| 1185 |
} // namespace jit |
| 1186 |
} // namespace js |
| 1187 |
|
| 1188 |
#endif /* jit_x86_MacroAssembler_x86_h */ |