| 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_MacroAssembler_inl_h |
| 8 |
#define jit_MacroAssembler_inl_h |
| 9 |
|
| 10 |
#include "jit/MacroAssembler.h" |
| 11 |
|
| 12 |
#include "mozilla/FloatingPoint.h" |
| 13 |
#include "mozilla/MathAlgorithms.h" |
| 14 |
|
| 15 |
#include "gc/Zone.h" |
| 16 |
#include "jit/CalleeToken.h" |
| 17 |
#include "jit/CompileWrappers.h" |
| 18 |
#include "jit/JitFrames.h" |
| 19 |
#include "jit/JSJitFrameIter.h" |
| 20 |
#include "js/Prefs.h" |
| 21 |
#include "vm/BigIntType.h" |
| 22 |
#include "vm/JSObject.h" |
| 23 |
#include "vm/ProxyObject.h" |
| 24 |
#include "vm/Runtime.h" |
| 25 |
#include "vm/StringType.h" |
| 26 |
|
| 27 |
#include "jit/ABIFunctionList-inl.h" |
| 28 |
|
| 29 |
#if defined(JS_CODEGEN_X86) |
| 30 |
# include "jit/x86/MacroAssembler-x86-inl.h" |
| 31 |
#elif defined(JS_CODEGEN_X64) |
| 32 |
# include "jit/x64/MacroAssembler-x64-inl.h" |
| 33 |
#elif defined(JS_CODEGEN_ARM) |
| 34 |
# include "jit/arm/MacroAssembler-arm-inl.h" |
| 35 |
#elif defined(JS_CODEGEN_ARM64) |
| 36 |
# include "jit/arm64/MacroAssembler-arm64-inl.h" |
| 37 |
#elif defined(JS_CODEGEN_MIPS64) |
| 38 |
# include "jit/mips64/MacroAssembler-mips64-inl.h" |
| 39 |
#elif defined(JS_CODEGEN_LOONG64) |
| 40 |
# include "jit/loong64/MacroAssembler-loong64-inl.h" |
| 41 |
#elif defined(JS_CODEGEN_RISCV64) |
| 42 |
# include "jit/riscv64/MacroAssembler-riscv64-inl.h" |
| 43 |
#elif defined(JS_CODEGEN_WASM32) |
| 44 |
# include "jit/wasm32/MacroAssembler-wasm32-inl.h" |
| 45 |
#elif !defined(JS_CODEGEN_NONE) |
| 46 |
# error "Unknown architecture!" |
| 47 |
#endif |
| 48 |
|
| 49 |
#include "wasm/WasmBuiltins.h" |
| 50 |
|
| 51 |
namespace js { |
| 52 |
namespace jit { |
| 53 |
|
| 54 |
template <typename Sig> |
| 55 |
DynFn DynamicFunction(Sig fun) { |
| 56 |
ABIFunctionSignature<Sig> sig; |
| 57 |
return DynFn{sig.address(fun)}; |
| 58 |
} |
| 59 |
|
| 60 |
// Helper for generatePreBarrier. |
| 61 |
inline DynFn JitPreWriteBarrier(MIRType type) { |
| 62 |
switch (type) { |
| 63 |
case MIRType::Value: { |
| 64 |
using Fn = void (*)(JSRuntime* rt, Value* vp); |
| 65 |
return DynamicFunction<Fn>(JitValuePreWriteBarrier); |
| 66 |
} |
| 67 |
case MIRType::String: { |
| 68 |
using Fn = void (*)(JSRuntime* rt, JSString** stringp); |
| 69 |
return DynamicFunction<Fn>(JitStringPreWriteBarrier); |
| 70 |
} |
| 71 |
case MIRType::Object: { |
| 72 |
using Fn = void (*)(JSRuntime* rt, JSObject** objp); |
| 73 |
return DynamicFunction<Fn>(JitObjectPreWriteBarrier); |
| 74 |
} |
| 75 |
case MIRType::Shape: { |
| 76 |
using Fn = void (*)(JSRuntime* rt, Shape** shapep); |
| 77 |
return DynamicFunction<Fn>(JitShapePreWriteBarrier); |
| 78 |
} |
| 79 |
case MIRType::WasmAnyRef: { |
| 80 |
using Fn = void (*)(JSRuntime* rt, wasm::AnyRef* refp); |
| 81 |
return DynamicFunction<Fn>(JitWasmAnyRefPreWriteBarrier); |
| 82 |
} |
| 83 |
default: |
| 84 |
MOZ_CRASH(); |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
//{{{ check_macroassembler_style |
| 89 |
// =============================================================== |
| 90 |
// Stack manipulation functions. |
| 91 |
|
| 92 |
CodeOffset MacroAssembler::PushWithPatch(ImmWord word) { |
| 93 |
framePushed_ += sizeof(word.value); |
| 94 |
return pushWithPatch(word); |
| 95 |
} |
| 96 |
|
| 97 |
CodeOffset MacroAssembler::PushWithPatch(ImmPtr imm) { |
| 98 |
return PushWithPatch(ImmWord(uintptr_t(imm.value))); |
| 99 |
} |
| 100 |
|
| 101 |
// =============================================================== |
| 102 |
// Simple call functions. |
| 103 |
|
| 104 |
void MacroAssembler::call(TrampolinePtr code) { call(ImmPtr(code.value)); } |
| 105 |
|
| 106 |
CodeOffset MacroAssembler::call(const wasm::CallSiteDesc& desc, |
| 107 |
const Register reg) { |
| 108 |
CodeOffset l = call(reg); |
| 109 |
append(desc, l); |
| 110 |
return l; |
| 111 |
} |
| 112 |
|
| 113 |
CodeOffset MacroAssembler::call(const wasm::CallSiteDesc& desc, |
| 114 |
uint32_t funcIndex) { |
| 115 |
CodeOffset l = callWithPatch(); |
| 116 |
append(desc, l, funcIndex); |
| 117 |
return l; |
| 118 |
} |
| 119 |
|
| 120 |
void MacroAssembler::call(const wasm::CallSiteDesc& desc, wasm::Trap trap) { |
| 121 |
CodeOffset l = callWithPatch(); |
| 122 |
append(desc, l, trap); |
| 123 |
} |
| 124 |
|
| 125 |
CodeOffset MacroAssembler::call(const wasm::CallSiteDesc& desc, |
| 126 |
wasm::SymbolicAddress imm) { |
| 127 |
MOZ_ASSERT(wasm::NeedsBuiltinThunk(imm), |
| 128 |
"only for functions which may appear in profiler"); |
| 129 |
CodeOffset raOffset = call(imm); |
| 130 |
append(desc, raOffset); |
| 131 |
return raOffset; |
| 132 |
} |
| 133 |
|
| 134 |
// =============================================================== |
| 135 |
// ABI function calls. |
| 136 |
|
| 137 |
void MacroAssembler::passABIArg(Register reg) { |
| 138 |
passABIArg(MoveOperand(reg), ABIType::General); |
| 139 |
} |
| 140 |
|
| 141 |
void MacroAssembler::passABIArg(FloatRegister reg, ABIType type) { |
| 142 |
passABIArg(MoveOperand(reg), type); |
| 143 |
} |
| 144 |
|
| 145 |
void MacroAssembler::callWithABI(DynFn fun, ABIType result, |
| 146 |
CheckUnsafeCallWithABI check) { |
| 147 |
AutoProfilerCallInstrumentation profiler(*this); |
| 148 |
callWithABINoProfiler(fun.address, result, check); |
| 149 |
} |
| 150 |
|
| 151 |
template <typename Sig, Sig fun> |
| 152 |
void MacroAssembler::callWithABI(ABIType result, CheckUnsafeCallWithABI check) { |
| 153 |
ABIFunction<Sig, fun> abiFun; |
| 154 |
AutoProfilerCallInstrumentation profiler(*this); |
| 155 |
callWithABINoProfiler(abiFun.address(), result, check); |
| 156 |
} |
| 157 |
|
| 158 |
void MacroAssembler::callWithABI(Register fun, ABIType result) { |
| 159 |
AutoProfilerCallInstrumentation profiler(*this); |
| 160 |
callWithABINoProfiler(fun, result); |
| 161 |
} |
| 162 |
|
| 163 |
void MacroAssembler::callWithABI(const Address& fun, ABIType result) { |
| 164 |
AutoProfilerCallInstrumentation profiler(*this); |
| 165 |
callWithABINoProfiler(fun, result); |
| 166 |
} |
| 167 |
|
| 168 |
void MacroAssembler::appendSignatureType(ABIType type) { |
| 169 |
#ifdef JS_SIMULATOR |
| 170 |
signature_ <<= ABITypeArgShift; |
| 171 |
signature_ |= uint32_t(type); |
| 172 |
#endif |
| 173 |
} |
| 174 |
|
| 175 |
ABIFunctionType MacroAssembler::signature() const { |
| 176 |
#ifdef JS_SIMULATOR |
| 177 |
# ifdef DEBUG |
| 178 |
switch (signature_) { |
| 179 |
case Args_General0: |
| 180 |
case Args_General1: |
| 181 |
case Args_General2: |
| 182 |
case Args_General3: |
| 183 |
case Args_General4: |
| 184 |
case Args_General5: |
| 185 |
case Args_General6: |
| 186 |
case Args_General7: |
| 187 |
case Args_General8: |
| 188 |
case Args_Double_None: |
| 189 |
case Args_Int_Double: |
| 190 |
case Args_Float32_Float32: |
| 191 |
case Args_Float32_Float64: |
| 192 |
case Args_Float32_General: |
| 193 |
case Args_Float32_Int32: |
| 194 |
case Args_Int_Float32: |
| 195 |
case Args_Int32_Float32: |
| 196 |
case Args_Double_Double: |
| 197 |
case Args_Double_Int: |
| 198 |
case Args_Double_DoubleInt: |
| 199 |
case Args_Double_DoubleDouble: |
| 200 |
case Args_Double_IntDouble: |
| 201 |
case Args_Int_IntDouble: |
| 202 |
case Args_Int_DoubleInt: |
| 203 |
case Args_Int_DoubleIntInt: |
| 204 |
case Args_Int_IntDoubleIntInt: |
| 205 |
case Args_Double_DoubleDoubleDouble: |
| 206 |
case Args_Double_DoubleDoubleDoubleDouble: |
| 207 |
case Args_Int64_GeneralGeneral: |
| 208 |
break; |
| 209 |
default: |
| 210 |
MOZ_CRASH("Unexpected type"); |
| 211 |
} |
| 212 |
# endif // DEBUG |
| 213 |
|
| 214 |
return ABIFunctionType(signature_); |
| 215 |
#else |
| 216 |
// No simulator enabled. |
| 217 |
MOZ_CRASH("Only available for making calls within a simulator."); |
| 218 |
#endif |
| 219 |
} |
| 220 |
|
| 221 |
// =============================================================== |
| 222 |
// Jit Frames. |
| 223 |
|
| 224 |
uint32_t MacroAssembler::callJitNoProfiler(Register callee) { |
| 225 |
#ifdef JS_USE_LINK_REGISTER |
| 226 |
// The return address is pushed by the callee. |
| 227 |
call(callee); |
| 228 |
#else |
| 229 |
callAndPushReturnAddress(callee); |
| 230 |
#endif |
| 231 |
return currentOffset(); |
| 232 |
} |
| 233 |
|
| 234 |
uint32_t MacroAssembler::callJit(Register callee) { |
| 235 |
AutoProfilerCallInstrumentation profiler(*this); |
| 236 |
uint32_t ret = callJitNoProfiler(callee); |
| 237 |
return ret; |
| 238 |
} |
| 239 |
|
| 240 |
uint32_t MacroAssembler::callJit(JitCode* callee) { |
| 241 |
AutoProfilerCallInstrumentation profiler(*this); |
| 242 |
call(callee); |
| 243 |
return currentOffset(); |
| 244 |
} |
| 245 |
|
| 246 |
uint32_t MacroAssembler::callJit(TrampolinePtr code) { |
| 247 |
AutoProfilerCallInstrumentation profiler(*this); |
| 248 |
call(code); |
| 249 |
return currentOffset(); |
| 250 |
} |
| 251 |
|
| 252 |
uint32_t MacroAssembler::callJit(ImmPtr callee) { |
| 253 |
AutoProfilerCallInstrumentation profiler(*this); |
| 254 |
call(callee); |
| 255 |
return currentOffset(); |
| 256 |
} |
| 257 |
|
| 258 |
void MacroAssembler::pushFrameDescriptor(FrameType type) { |
| 259 |
uint32_t descriptor = MakeFrameDescriptor(type); |
| 260 |
push(Imm32(descriptor)); |
| 261 |
} |
| 262 |
|
| 263 |
void MacroAssembler::PushFrameDescriptor(FrameType type) { |
| 264 |
uint32_t descriptor = MakeFrameDescriptor(type); |
| 265 |
Push(Imm32(descriptor)); |
| 266 |
} |
| 267 |
|
| 268 |
void MacroAssembler::pushFrameDescriptorForJitCall(FrameType type, |
| 269 |
uint32_t argc) { |
| 270 |
uint32_t descriptor = MakeFrameDescriptorForJitCall(type, argc); |
| 271 |
push(Imm32(descriptor)); |
| 272 |
} |
| 273 |
|
| 274 |
void MacroAssembler::PushFrameDescriptorForJitCall(FrameType type, |
| 275 |
uint32_t argc) { |
| 276 |
uint32_t descriptor = MakeFrameDescriptorForJitCall(type, argc); |
| 277 |
Push(Imm32(descriptor)); |
| 278 |
} |
| 279 |
|
| 280 |
void MacroAssembler::pushFrameDescriptorForJitCall(FrameType type, |
| 281 |
Register argc, |
| 282 |
Register scratch) { |
| 283 |
lshift32(Imm32(NUMACTUALARGS_SHIFT), argc, scratch); |
| 284 |
or32(Imm32(int32_t(type)), scratch); |
| 285 |
push(scratch); |
| 286 |
} |
| 287 |
|
| 288 |
void MacroAssembler::PushFrameDescriptorForJitCall(FrameType type, |
| 289 |
Register argc, |
| 290 |
Register scratch) { |
| 291 |
pushFrameDescriptorForJitCall(type, argc, scratch); |
| 292 |
framePushed_ += sizeof(uintptr_t); |
| 293 |
} |
| 294 |
|
| 295 |
void MacroAssembler::loadNumActualArgs(Register framePtr, Register dest) { |
| 296 |
loadPtr(Address(framePtr, JitFrameLayout::offsetOfDescriptor()), dest); |
| 297 |
rshift32(Imm32(NUMACTUALARGS_SHIFT), dest); |
| 298 |
} |
| 299 |
|
| 300 |
void MacroAssembler::PushCalleeToken(Register callee, bool constructing) { |
| 301 |
if (constructing) { |
| 302 |
orPtr(Imm32(CalleeToken_FunctionConstructing), callee); |
| 303 |
Push(callee); |
| 304 |
andPtr(Imm32(uint32_t(CalleeTokenMask)), callee); |
| 305 |
} else { |
| 306 |
static_assert(CalleeToken_Function == 0, |
| 307 |
"Non-constructing call requires no tagging"); |
| 308 |
Push(callee); |
| 309 |
} |
| 310 |
} |
| 311 |
|
| 312 |
void MacroAssembler::loadFunctionFromCalleeToken(Address token, Register dest) { |
| 313 |
#ifdef DEBUG |
| 314 |
Label ok; |
| 315 |
loadPtr(token, dest); |
| 316 |
andPtr(Imm32(uint32_t(~CalleeTokenMask)), dest); |
| 317 |
branchPtr(Assembler::Equal, dest, Imm32(CalleeToken_Function), &ok); |
| 318 |
branchPtr(Assembler::Equal, dest, Imm32(CalleeToken_FunctionConstructing), |
| 319 |
&ok); |
| 320 |
assumeUnreachable("Unexpected CalleeToken tag"); |
| 321 |
bind(&ok); |
| 322 |
#endif |
| 323 |
loadPtr(token, dest); |
| 324 |
andPtr(Imm32(uint32_t(CalleeTokenMask)), dest); |
| 325 |
} |
| 326 |
|
| 327 |
uint32_t MacroAssembler::buildFakeExitFrame(Register scratch) { |
| 328 |
mozilla::DebugOnly<uint32_t> initialDepth = framePushed(); |
| 329 |
|
| 330 |
PushFrameDescriptor(FrameType::IonJS); |
| 331 |
uint32_t retAddr = pushFakeReturnAddress(scratch); |
| 332 |
Push(FramePointer); |
| 333 |
|
| 334 |
MOZ_ASSERT(framePushed() == initialDepth + ExitFrameLayout::Size()); |
| 335 |
return retAddr; |
| 336 |
} |
| 337 |
|
| 338 |
// =============================================================== |
| 339 |
// Exit frame footer. |
| 340 |
|
| 341 |
void MacroAssembler::enterExitFrame(Register cxreg, Register scratch, |
| 342 |
VMFunctionId f) { |
| 343 |
linkExitFrame(cxreg, scratch); |
| 344 |
// Push `ExitFrameType::VMFunction + VMFunctionId`, for marking the arguments. |
| 345 |
// See ExitFooterFrame::data_. |
| 346 |
uintptr_t type = uintptr_t(ExitFrameType::VMFunction) + uintptr_t(f); |
| 347 |
MOZ_ASSERT(type <= INT32_MAX); |
| 348 |
Push(Imm32(type)); |
| 349 |
} |
| 350 |
|
| 351 |
void MacroAssembler::enterFakeExitFrame(Register cxreg, Register scratch, |
| 352 |
ExitFrameType type) { |
| 353 |
linkExitFrame(cxreg, scratch); |
| 354 |
Push(Imm32(int32_t(type))); |
| 355 |
} |
| 356 |
|
| 357 |
void MacroAssembler::enterFakeExitFrameForNative(Register cxreg, |
| 358 |
Register scratch, |
| 359 |
bool isConstructing) { |
| 360 |
enterFakeExitFrame(cxreg, scratch, |
| 361 |
isConstructing ? ExitFrameType::ConstructNative |
| 362 |
: ExitFrameType::CallNative); |
| 363 |
} |
| 364 |
|
| 365 |
void MacroAssembler::leaveExitFrame(size_t extraFrame) { |
| 366 |
freeStack(ExitFooterFrame::Size() + extraFrame); |
| 367 |
} |
| 368 |
|
| 369 |
// =============================================================== |
| 370 |
// Move instructions |
| 371 |
|
| 372 |
void MacroAssembler::moveValue(const ConstantOrRegister& src, |
| 373 |
const ValueOperand& dest) { |
| 374 |
if (src.constant()) { |
| 375 |
moveValue(src.value(), dest); |
| 376 |
return; |
| 377 |
} |
| 378 |
|
| 379 |
moveValue(src.reg(), dest); |
| 380 |
} |
| 381 |
|
| 382 |
// =============================================================== |
| 383 |
// Copy instructions |
| 384 |
|
| 385 |
void MacroAssembler::copy64(const Address& src, const Address& dest, |
| 386 |
Register scratch) { |
| 387 |
#if JS_BITS_PER_WORD == 32 |
| 388 |
MOZ_RELEASE_ASSERT(src.base != scratch && dest.base != scratch); |
| 389 |
load32(LowWord(src), scratch); |
| 390 |
store32(scratch, LowWord(dest)); |
| 391 |
load32(HighWord(src), scratch); |
| 392 |
store32(scratch, HighWord(dest)); |
| 393 |
#else |
| 394 |
Register64 scratch64(scratch); |
| 395 |
load64(src, scratch64); |
| 396 |
store64(scratch64, dest); |
| 397 |
#endif |
| 398 |
} |
| 399 |
|
| 400 |
// =============================================================== |
| 401 |
// Arithmetic functions |
| 402 |
|
| 403 |
void MacroAssembler::addPtr(ImmPtr imm, Register dest) { |
| 404 |
addPtr(ImmWord(uintptr_t(imm.value)), dest); |
| 405 |
} |
| 406 |
|
| 407 |
// =============================================================== |
| 408 |
// Branch functions |
| 409 |
|
| 410 |
void MacroAssembler::branchTest64(Condition cond, Register64 lhs, |
| 411 |
Register64 rhs, Label* success, Label* fail) { |
| 412 |
branchTest64(cond, lhs, rhs, InvalidReg, success, fail); |
| 413 |
} |
| 414 |
|
| 415 |
void MacroAssembler::branchIfFalseBool(Register reg, Label* label) { |
| 416 |
// Note that C++ bool is only 1 byte, so ignore the higher-order bits. |
| 417 |
branchTest32(Assembler::Zero, reg, Imm32(0xFF), label); |
| 418 |
} |
| 419 |
|
| 420 |
void MacroAssembler::branchIfTrueBool(Register reg, Label* label) { |
| 421 |
// Note that C++ bool is only 1 byte, so ignore the higher-order bits. |
| 422 |
branchTest32(Assembler::NonZero, reg, Imm32(0xFF), label); |
| 423 |
} |
| 424 |
|
| 425 |
void MacroAssembler::branchIfNotNullOrUndefined(ValueOperand val, |
| 426 |
Label* label) { |
| 427 |
Label nullOrUndefined; |
| 428 |
ScratchTagScope tag(*this, val); |
| 429 |
splitTagForTest(val, tag); |
| 430 |
branchTestNull(Assembler::Equal, tag, &nullOrUndefined); |
| 431 |
branchTestUndefined(Assembler::NotEqual, tag, label); |
| 432 |
bind(&nullOrUndefined); |
| 433 |
} |
| 434 |
|
| 435 |
void MacroAssembler::branchIfRope(Register str, Label* label) { |
| 436 |
Address flags(str, JSString::offsetOfFlags()); |
| 437 |
branchTest32(Assembler::Zero, flags, Imm32(JSString::LINEAR_BIT), label); |
| 438 |
} |
| 439 |
|
| 440 |
void MacroAssembler::branchIfNotRope(Register str, Label* label) { |
| 441 |
Address flags(str, JSString::offsetOfFlags()); |
| 442 |
branchTest32(Assembler::NonZero, flags, Imm32(JSString::LINEAR_BIT), label); |
| 443 |
} |
| 444 |
|
| 445 |
void MacroAssembler::branchLatin1String(Register string, Label* label) { |
| 446 |
branchTest32(Assembler::NonZero, Address(string, JSString::offsetOfFlags()), |
| 447 |
Imm32(JSString::LATIN1_CHARS_BIT), label); |
| 448 |
} |
| 449 |
|
| 450 |
void MacroAssembler::branchTwoByteString(Register string, Label* label) { |
| 451 |
branchTest32(Assembler::Zero, Address(string, JSString::offsetOfFlags()), |
| 452 |
Imm32(JSString::LATIN1_CHARS_BIT), label); |
| 453 |
} |
| 454 |
|
| 455 |
void MacroAssembler::branchIfBigIntIsNegative(Register bigInt, Label* label) { |
| 456 |
branchTest32(Assembler::NonZero, Address(bigInt, BigInt::offsetOfFlags()), |
| 457 |
Imm32(BigInt::signBitMask()), label); |
| 458 |
} |
| 459 |
|
| 460 |
void MacroAssembler::branchIfBigIntIsNonNegative(Register bigInt, |
| 461 |
Label* label) { |
| 462 |
branchTest32(Assembler::Zero, Address(bigInt, BigInt::offsetOfFlags()), |
| 463 |
Imm32(BigInt::signBitMask()), label); |
| 464 |
} |
| 465 |
|
| 466 |
void MacroAssembler::branchIfBigIntIsZero(Register bigInt, Label* label) { |
| 467 |
branch32(Assembler::Equal, Address(bigInt, BigInt::offsetOfLength()), |
| 468 |
Imm32(0), label); |
| 469 |
} |
| 470 |
|
| 471 |
void MacroAssembler::branchIfBigIntIsNonZero(Register bigInt, Label* label) { |
| 472 |
branch32(Assembler::NotEqual, Address(bigInt, BigInt::offsetOfLength()), |
| 473 |
Imm32(0), label); |
| 474 |
} |
| 475 |
|
| 476 |
void MacroAssembler::branchTestFunctionFlags(Register fun, uint32_t flags, |
| 477 |
Condition cond, Label* label) { |
| 478 |
Address address(fun, JSFunction::offsetOfFlagsAndArgCount()); |
| 479 |
branchTest32(cond, address, Imm32(flags), label); |
| 480 |
} |
| 481 |
|
| 482 |
void MacroAssembler::branchIfNotFunctionIsNonBuiltinCtor(Register fun, |
| 483 |
Register scratch, |
| 484 |
Label* label) { |
| 485 |
// Guard the function has the BASESCRIPT and CONSTRUCTOR flags and does NOT |
| 486 |
// have the SELF_HOSTED flag. |
| 487 |
// This is equivalent to JSFunction::isNonBuiltinConstructor. |
| 488 |
constexpr int32_t mask = FunctionFlags::BASESCRIPT | |
| 489 |
FunctionFlags::SELF_HOSTED | |
| 490 |
FunctionFlags::CONSTRUCTOR; |
| 491 |
constexpr int32_t expected = |
| 492 |
FunctionFlags::BASESCRIPT | FunctionFlags::CONSTRUCTOR; |
| 493 |
|
| 494 |
load32(Address(fun, JSFunction::offsetOfFlagsAndArgCount()), scratch); |
| 495 |
and32(Imm32(mask), scratch); |
| 496 |
branch32(Assembler::NotEqual, scratch, Imm32(expected), label); |
| 497 |
} |
| 498 |
|
| 499 |
void MacroAssembler::branchIfFunctionHasNoJitEntry(Register fun, Label* label) { |
| 500 |
uint16_t flags = FunctionFlags::HasJitEntryFlags(); |
| 501 |
branchTestFunctionFlags(fun, flags, Assembler::Zero, label); |
| 502 |
} |
| 503 |
|
| 504 |
void MacroAssembler::branchIfFunctionHasJitEntry(Register fun, Label* label) { |
| 505 |
uint16_t flags = FunctionFlags::HasJitEntryFlags(); |
| 506 |
branchTestFunctionFlags(fun, flags, Assembler::NonZero, label); |
| 507 |
} |
| 508 |
|
| 509 |
void MacroAssembler::branchIfScriptHasJitScript(Register script, Label* label) { |
| 510 |
static_assert(ScriptWarmUpData::JitScriptTag == 0, |
| 511 |
"Code below depends on tag value"); |
| 512 |
branchTestPtr(Assembler::Zero, |
| 513 |
Address(script, JSScript::offsetOfWarmUpData()), |
| 514 |
Imm32(ScriptWarmUpData::TagMask), label); |
| 515 |
} |
| 516 |
|
| 517 |
void MacroAssembler::branchIfScriptHasNoJitScript(Register script, |
| 518 |
Label* label) { |
| 519 |
static_assert(ScriptWarmUpData::JitScriptTag == 0, |
| 520 |
"Code below depends on tag value"); |
| 521 |
static_assert(BaseScript::offsetOfWarmUpData() == |
| 522 |
SelfHostedLazyScript::offsetOfWarmUpData(), |
| 523 |
"SelfHostedLazyScript and BaseScript must use same layout for " |
| 524 |
"warmUpData_"); |
| 525 |
branchTestPtr(Assembler::NonZero, |
| 526 |
Address(script, JSScript::offsetOfWarmUpData()), |
| 527 |
Imm32(ScriptWarmUpData::TagMask), label); |
| 528 |
} |
| 529 |
|
| 530 |
void MacroAssembler::loadJitScript(Register script, Register dest) { |
| 531 |
#ifdef DEBUG |
| 532 |
Label ok; |
| 533 |
branchIfScriptHasJitScript(script, &ok); |
| 534 |
assumeUnreachable("Script has no JitScript!"); |
| 535 |
bind(&ok); |
| 536 |
#endif |
| 537 |
|
| 538 |
static_assert(ScriptWarmUpData::JitScriptTag == 0, |
| 539 |
"Code below depends on tag value"); |
| 540 |
loadPtr(Address(script, JSScript::offsetOfWarmUpData()), dest); |
| 541 |
} |
| 542 |
|
| 543 |
void MacroAssembler::loadFunctionArgCount(Register func, Register output) { |
| 544 |
load32(Address(func, JSFunction::offsetOfFlagsAndArgCount()), output); |
| 545 |
rshift32(Imm32(JSFunction::ArgCountShift), output); |
| 546 |
} |
| 547 |
|
| 548 |
void MacroAssembler::branchIfObjectEmulatesUndefined(Register objReg, |
| 549 |
Register scratch, |
| 550 |
Label* slowCheck, |
| 551 |
Label* label) { |
| 552 |
MOZ_ASSERT(objReg != scratch); |
| 553 |
|
| 554 |
Label done; |
| 555 |
|
| 556 |
loadPtr( |
| 557 |
AbsoluteAddress(runtime()->addressOfHasSeenObjectEmulateUndefinedFuse()), |
| 558 |
scratch); |
| 559 |
branchPtr(Assembler::Equal, scratch, ImmPtr(nullptr), &done); |
| 560 |
|
| 561 |
loadObjClassUnsafe(objReg, scratch); |
| 562 |
|
| 563 |
Address flags(scratch, JSClass::offsetOfFlags()); |
| 564 |
branchTest32(Assembler::NonZero, flags, Imm32(JSCLASS_EMULATES_UNDEFINED), |
| 565 |
label); |
| 566 |
|
| 567 |
// Call into C++ if the object is a wrapper. |
| 568 |
branchTestClassIsProxy(false, scratch, &done); |
| 569 |
branchTestProxyHandlerFamily(Assembler::Equal, objReg, scratch, |
| 570 |
&Wrapper::family, slowCheck); |
| 571 |
|
| 572 |
bind(&done); |
| 573 |
} |
| 574 |
|
| 575 |
void MacroAssembler::branchFunctionKind(Condition cond, |
| 576 |
FunctionFlags::FunctionKind kind, |
| 577 |
Register fun, Register scratch, |
| 578 |
Label* label) { |
| 579 |
Address address(fun, JSFunction::offsetOfFlagsAndArgCount()); |
| 580 |
load32(address, scratch); |
| 581 |
and32(Imm32(FunctionFlags::FUNCTION_KIND_MASK), scratch); |
| 582 |
branch32(cond, scratch, Imm32(kind), label); |
| 583 |
} |
| 584 |
|
| 585 |
void MacroAssembler::branchTestObjClass(Condition cond, Register obj, |
| 586 |
const JSClass* clasp, Register scratch, |
| 587 |
Register spectreRegToZero, |
| 588 |
Label* label) { |
| 589 |
MOZ_ASSERT(obj != scratch); |
| 590 |
MOZ_ASSERT(scratch != spectreRegToZero); |
| 591 |
|
| 592 |
loadPtr(Address(obj, JSObject::offsetOfShape()), scratch); |
| 593 |
loadPtr(Address(scratch, Shape::offsetOfBaseShape()), scratch); |
| 594 |
branchPtr(cond, Address(scratch, BaseShape::offsetOfClasp()), ImmPtr(clasp), |
| 595 |
label); |
| 596 |
|
| 597 |
if (JitOptions.spectreObjectMitigations) { |
| 598 |
spectreZeroRegister(cond, scratch, spectreRegToZero); |
| 599 |
} |
| 600 |
} |
| 601 |
|
| 602 |
void MacroAssembler::branchTestObjClassNoSpectreMitigations( |
| 603 |
Condition cond, Register obj, const JSClass* clasp, Register scratch, |
| 604 |
Label* label) { |
| 605 |
loadPtr(Address(obj, JSObject::offsetOfShape()), scratch); |
| 606 |
loadPtr(Address(scratch, Shape::offsetOfBaseShape()), scratch); |
| 607 |
branchPtr(cond, Address(scratch, BaseShape::offsetOfClasp()), ImmPtr(clasp), |
| 608 |
label); |
| 609 |
} |
| 610 |
|
| 611 |
void MacroAssembler::branchTestObjClass(Condition cond, Register obj, |
| 612 |
const Address& clasp, Register scratch, |
| 613 |
Register spectreRegToZero, |
| 614 |
Label* label) { |
| 615 |
MOZ_ASSERT(obj != scratch); |
| 616 |
MOZ_ASSERT(scratch != spectreRegToZero); |
| 617 |
|
| 618 |
loadObjClassUnsafe(obj, scratch); |
| 619 |
branchPtr(cond, clasp, scratch, label); |
| 620 |
|
| 621 |
if (JitOptions.spectreObjectMitigations) { |
| 622 |
spectreZeroRegister(cond, scratch, spectreRegToZero); |
| 623 |
} |
| 624 |
} |
| 625 |
|
| 626 |
void MacroAssembler::branchTestObjClassNoSpectreMitigations( |
| 627 |
Condition cond, Register obj, const Address& clasp, Register scratch, |
| 628 |
Label* label) { |
| 629 |
MOZ_ASSERT(obj != scratch); |
| 630 |
loadObjClassUnsafe(obj, scratch); |
| 631 |
branchPtr(cond, clasp, scratch, label); |
| 632 |
} |
| 633 |
|
| 634 |
void MacroAssembler::branchTestObjClass(Condition cond, Register obj, |
| 635 |
Register clasp, Register scratch, |
| 636 |
Register spectreRegToZero, |
| 637 |
Label* label) { |
| 638 |
MOZ_ASSERT(obj != scratch); |
| 639 |
MOZ_ASSERT(scratch != spectreRegToZero); |
| 640 |
|
| 641 |
loadObjClassUnsafe(obj, scratch); |
| 642 |
branchPtr(cond, clasp, scratch, label); |
| 643 |
|
| 644 |
if (JitOptions.spectreObjectMitigations) { |
| 645 |
spectreZeroRegister(cond, scratch, spectreRegToZero); |
| 646 |
} |
| 647 |
} |
| 648 |
|
| 649 |
void MacroAssembler::branchTestClass( |
| 650 |
Condition cond, Register clasp, |
| 651 |
std::pair<const JSClass*, const JSClass*> classes, Label* label) { |
| 652 |
MOZ_ASSERT(cond == Assembler::Equal || cond == Assembler::NotEqual); |
| 653 |
|
| 654 |
if (cond == Assembler::Equal) { |
| 655 |
branchPtr(Assembler::Equal, clasp, ImmPtr(classes.first), label); |
| 656 |
branchPtr(Assembler::Equal, clasp, ImmPtr(classes.second), label); |
| 657 |
return; |
| 658 |
} |
| 659 |
|
| 660 |
Label isClass; |
| 661 |
branchPtr(Assembler::Equal, clasp, ImmPtr(classes.first), &isClass); |
| 662 |
branchPtr(Assembler::NotEqual, clasp, ImmPtr(classes.second), label); |
| 663 |
bind(&isClass); |
| 664 |
} |
| 665 |
|
| 666 |
void MacroAssembler::branchTestObjClass( |
| 667 |
Condition cond, Register obj, |
| 668 |
std::pair<const JSClass*, const JSClass*> classes, Register scratch, |
| 669 |
Register spectreRegToZero, Label* label) { |
| 670 |
MOZ_ASSERT(scratch != spectreRegToZero); |
| 671 |
|
| 672 |
branchTestObjClassNoSpectreMitigations(cond, obj, classes, scratch, label); |
| 673 |
|
| 674 |
if (JitOptions.spectreObjectMitigations) { |
| 675 |
spectreZeroRegister(cond, scratch, spectreRegToZero); |
| 676 |
} |
| 677 |
} |
| 678 |
|
| 679 |
void MacroAssembler::branchTestObjClassNoSpectreMitigations( |
| 680 |
Condition cond, Register obj, |
| 681 |
std::pair<const JSClass*, const JSClass*> classes, Register scratch, |
| 682 |
Label* label) { |
| 683 |
MOZ_ASSERT(cond == Assembler::Equal || cond == Assembler::NotEqual); |
| 684 |
MOZ_ASSERT(obj != scratch); |
| 685 |
|
| 686 |
loadObjClassUnsafe(obj, scratch); |
| 687 |
branchTestClass(cond, scratch, classes, label); |
| 688 |
} |
| 689 |
|
| 690 |
void MacroAssembler::branchTestClassIsFunction(Condition cond, Register clasp, |
| 691 |
Label* label) { |
| 692 |
return branchTestClass(cond, clasp, {&FunctionClass, &ExtendedFunctionClass}, |
| 693 |
label); |
| 694 |
} |
| 695 |
|
| 696 |
void MacroAssembler::branchTestObjIsFunction(Condition cond, Register obj, |
| 697 |
Register scratch, |
| 698 |
Register spectreRegToZero, |
| 699 |
Label* label) { |
| 700 |
MOZ_ASSERT(scratch != spectreRegToZero); |
| 701 |
|
| 702 |
branchTestObjIsFunctionNoSpectreMitigations(cond, obj, scratch, label); |
| 703 |
|
| 704 |
if (JitOptions.spectreObjectMitigations) { |
| 705 |
spectreZeroRegister(cond, scratch, spectreRegToZero); |
| 706 |
} |
| 707 |
} |
| 708 |
|
| 709 |
void MacroAssembler::branchTestObjIsFunctionNoSpectreMitigations( |
| 710 |
Condition cond, Register obj, Register scratch, Label* label) { |
| 711 |
MOZ_ASSERT(cond == Assembler::Equal || cond == Assembler::NotEqual); |
| 712 |
MOZ_ASSERT(obj != scratch); |
| 713 |
|
| 714 |
loadObjClassUnsafe(obj, scratch); |
| 715 |
branchTestClassIsFunction(cond, scratch, label); |
| 716 |
} |
| 717 |
|
| 718 |
void MacroAssembler::branchTestObjShape(Condition cond, Register obj, |
| 719 |
const Shape* shape, Register scratch, |
| 720 |
Register spectreRegToZero, |
| 721 |
Label* label) { |
| 722 |
MOZ_ASSERT(obj != scratch); |
| 723 |
MOZ_ASSERT(spectreRegToZero != scratch); |
| 724 |
|
| 725 |
if (JitOptions.spectreObjectMitigations) { |
| 726 |
move32(Imm32(0), scratch); |
| 727 |
} |
| 728 |
|
| 729 |
branchPtr(cond, Address(obj, JSObject::offsetOfShape()), ImmGCPtr(shape), |
| 730 |
label); |
| 731 |
|
| 732 |
if (JitOptions.spectreObjectMitigations) { |
| 733 |
spectreMovePtr(cond, scratch, spectreRegToZero); |
| 734 |
} |
| 735 |
} |
| 736 |
|
| 737 |
void MacroAssembler::branchTestObjShapeNoSpectreMitigations(Condition cond, |
| 738 |
Register obj, |
| 739 |
const Shape* shape, |
| 740 |
Label* label) { |
| 741 |
branchPtr(cond, Address(obj, JSObject::offsetOfShape()), ImmGCPtr(shape), |
| 742 |
label); |
| 743 |
} |
| 744 |
|
| 745 |
void MacroAssembler::branchTestObjShape(Condition cond, Register obj, |
| 746 |
Register shape, Register scratch, |
| 747 |
Register spectreRegToZero, |
| 748 |
Label* label) { |
| 749 |
MOZ_ASSERT(obj != scratch); |
| 750 |
MOZ_ASSERT(obj != shape); |
| 751 |
MOZ_ASSERT(spectreRegToZero != scratch); |
| 752 |
|
| 753 |
if (JitOptions.spectreObjectMitigations) { |
| 754 |
move32(Imm32(0), scratch); |
| 755 |
} |
| 756 |
|
| 757 |
branchPtr(cond, Address(obj, JSObject::offsetOfShape()), shape, label); |
| 758 |
|
| 759 |
if (JitOptions.spectreObjectMitigations) { |
| 760 |
spectreMovePtr(cond, scratch, spectreRegToZero); |
| 761 |
} |
| 762 |
} |
| 763 |
|
| 764 |
void MacroAssembler::branchTestObjShapeNoSpectreMitigations(Condition cond, |
| 765 |
Register obj, |
| 766 |
Register shape, |
| 767 |
Label* label) { |
| 768 |
branchPtr(cond, Address(obj, JSObject::offsetOfShape()), shape, label); |
| 769 |
} |
| 770 |
|
| 771 |
void MacroAssembler::branchTestObjShapeUnsafe(Condition cond, Register obj, |
| 772 |
Register shape, Label* label) { |
| 773 |
branchTestObjShapeNoSpectreMitigations(cond, obj, shape, label); |
| 774 |
} |
| 775 |
|
| 776 |
void MacroAssembler::branchTestClassIsProxy(bool proxy, Register clasp, |
| 777 |
Label* label) { |
| 778 |
branchTest32(proxy ? Assembler::NonZero : Assembler::Zero, |
| 779 |
Address(clasp, JSClass::offsetOfFlags()), |
| 780 |
Imm32(JSCLASS_IS_PROXY), label); |
| 781 |
} |
| 782 |
|
| 783 |
void MacroAssembler::branchTestObjectIsProxy(bool proxy, Register object, |
| 784 |
Register scratch, Label* label) { |
| 785 |
constexpr uint32_t ShiftedMask = (Shape::kindMask() << Shape::kindShift()); |
| 786 |
static_assert(uint32_t(Shape::Kind::Proxy) == 0, |
| 787 |
"branchTest32 below depends on proxy kind being 0"); |
| 788 |
loadPtr(Address(object, JSObject::offsetOfShape()), scratch); |
| 789 |
branchTest32(proxy ? Assembler::Zero : Assembler::NonZero, |
| 790 |
Address(scratch, Shape::offsetOfImmutableFlags()), |
| 791 |
Imm32(ShiftedMask), label); |
| 792 |
} |
| 793 |
|
| 794 |
void MacroAssembler::branchTestProxyHandlerFamily(Condition cond, |
| 795 |
Register proxy, |
| 796 |
Register scratch, |
| 797 |
const void* handlerp, |
| 798 |
Label* label) { |
| 799 |
#ifdef DEBUG |
| 800 |
Label ok; |
| 801 |
branchTestObjectIsProxy(true, proxy, scratch, &ok); |
| 802 |
assumeUnreachable("Expected ProxyObject in branchTestProxyHandlerFamily"); |
| 803 |
bind(&ok); |
| 804 |
#endif |
| 805 |
|
| 806 |
Address handlerAddr(proxy, ProxyObject::offsetOfHandler()); |
| 807 |
loadPtr(handlerAddr, scratch); |
| 808 |
Address familyAddr(scratch, BaseProxyHandler::offsetOfFamily()); |
| 809 |
branchPtr(cond, familyAddr, ImmPtr(handlerp), label); |
| 810 |
} |
| 811 |
|
| 812 |
void MacroAssembler::branchTestNeedsIncrementalBarrier(Condition cond, |
| 813 |
Label* label) { |
| 814 |
MOZ_ASSERT(cond == Zero || cond == NonZero); |
| 815 |
CompileZone* zone = realm()->zone(); |
| 816 |
const uint32_t* needsBarrierAddr = zone->addressOfNeedsIncrementalBarrier(); |
| 817 |
branchTest32(cond, AbsoluteAddress(needsBarrierAddr), Imm32(0x1), label); |
| 818 |
} |
| 819 |
|
| 820 |
void MacroAssembler::branchTestNeedsIncrementalBarrierAnyZone( |
| 821 |
Condition cond, Label* label, Register scratch) { |
| 822 |
MOZ_ASSERT(cond == Zero || cond == NonZero); |
| 823 |
if (maybeRealm_) { |
| 824 |
branchTestNeedsIncrementalBarrier(cond, label); |
| 825 |
} else { |
| 826 |
// We are compiling the interpreter or another runtime-wide trampoline, so |
| 827 |
// we have to load cx->zone. |
| 828 |
loadPtr(AbsoluteAddress(runtime()->addressOfZone()), scratch); |
| 829 |
Address needsBarrierAddr(scratch, Zone::offsetOfNeedsIncrementalBarrier()); |
| 830 |
branchTest32(cond, needsBarrierAddr, Imm32(0x1), label); |
| 831 |
} |
| 832 |
} |
| 833 |
|
| 834 |
void MacroAssembler::branchTestMagicValue(Condition cond, |
| 835 |
const ValueOperand& val, |
| 836 |
JSWhyMagic why, Label* label) { |
| 837 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 838 |
branchTestValue(cond, val, MagicValue(why), label); |
| 839 |
} |
| 840 |
|
| 841 |
void MacroAssembler::branchDoubleNotInInt64Range(Address src, Register temp, |
| 842 |
Label* fail) { |
| 843 |
using mozilla::FloatingPoint; |
| 844 |
|
| 845 |
// Tests if double is in [INT64_MIN; INT64_MAX] range |
| 846 |
uint32_t EXPONENT_MASK = 0x7ff00000; |
| 847 |
uint32_t EXPONENT_SHIFT = FloatingPoint<double>::kExponentShift - 32; |
| 848 |
uint32_t TOO_BIG_EXPONENT = (FloatingPoint<double>::kExponentBias + 63) |
| 849 |
<< EXPONENT_SHIFT; |
| 850 |
|
| 851 |
load32(Address(src.base, src.offset + sizeof(int32_t)), temp); |
| 852 |
and32(Imm32(EXPONENT_MASK), temp); |
| 853 |
branch32(Assembler::GreaterThanOrEqual, temp, Imm32(TOO_BIG_EXPONENT), fail); |
| 854 |
} |
| 855 |
|
| 856 |
void MacroAssembler::branchDoubleNotInUInt64Range(Address src, Register temp, |
| 857 |
Label* fail) { |
| 858 |
using mozilla::FloatingPoint; |
| 859 |
|
| 860 |
// Note: returns failure on -0.0 |
| 861 |
// Tests if double is in [0; UINT64_MAX] range |
| 862 |
// Take the sign also in the equation. That way we can compare in one test? |
| 863 |
uint32_t EXPONENT_MASK = 0xfff00000; |
| 864 |
uint32_t EXPONENT_SHIFT = FloatingPoint<double>::kExponentShift - 32; |
| 865 |
uint32_t TOO_BIG_EXPONENT = (FloatingPoint<double>::kExponentBias + 64) |
| 866 |
<< EXPONENT_SHIFT; |
| 867 |
|
| 868 |
load32(Address(src.base, src.offset + sizeof(int32_t)), temp); |
| 869 |
and32(Imm32(EXPONENT_MASK), temp); |
| 870 |
branch32(Assembler::AboveOrEqual, temp, Imm32(TOO_BIG_EXPONENT), fail); |
| 871 |
} |
| 872 |
|
| 873 |
void MacroAssembler::branchFloat32NotInInt64Range(Address src, Register temp, |
| 874 |
Label* fail) { |
| 875 |
using mozilla::FloatingPoint; |
| 876 |
|
| 877 |
// Tests if float is in [INT64_MIN; INT64_MAX] range |
| 878 |
uint32_t EXPONENT_MASK = 0x7f800000; |
| 879 |
uint32_t EXPONENT_SHIFT = FloatingPoint<float>::kExponentShift; |
| 880 |
uint32_t TOO_BIG_EXPONENT = (FloatingPoint<float>::kExponentBias + 63) |
| 881 |
<< EXPONENT_SHIFT; |
| 882 |
|
| 883 |
load32(src, temp); |
| 884 |
and32(Imm32(EXPONENT_MASK), temp); |
| 885 |
branch32(Assembler::GreaterThanOrEqual, temp, Imm32(TOO_BIG_EXPONENT), fail); |
| 886 |
} |
| 887 |
|
| 888 |
void MacroAssembler::branchFloat32NotInUInt64Range(Address src, Register temp, |
| 889 |
Label* fail) { |
| 890 |
using mozilla::FloatingPoint; |
| 891 |
|
| 892 |
// Note: returns failure on -0.0 |
| 893 |
// Tests if float is in [0; UINT64_MAX] range |
| 894 |
// Take the sign also in the equation. That way we can compare in one test? |
| 895 |
uint32_t EXPONENT_MASK = 0xff800000; |
| 896 |
uint32_t EXPONENT_SHIFT = FloatingPoint<float>::kExponentShift; |
| 897 |
uint32_t TOO_BIG_EXPONENT = (FloatingPoint<float>::kExponentBias + 64) |
| 898 |
<< EXPONENT_SHIFT; |
| 899 |
|
| 900 |
load32(src, temp); |
| 901 |
and32(Imm32(EXPONENT_MASK), temp); |
| 902 |
branch32(Assembler::AboveOrEqual, temp, Imm32(TOO_BIG_EXPONENT), fail); |
| 903 |
} |
| 904 |
|
| 905 |
// ======================================================================== |
| 906 |
// Canonicalization primitives. |
| 907 |
void MacroAssembler::canonicalizeFloat(FloatRegister reg) { |
| 908 |
Label notNaN; |
| 909 |
branchFloat(DoubleOrdered, reg, reg, ¬NaN); |
| 910 |
loadConstantFloat32(float(JS::GenericNaN()), reg); |
| 911 |
bind(¬NaN); |
| 912 |
} |
| 913 |
|
| 914 |
void MacroAssembler::canonicalizeDouble(FloatRegister reg) { |
| 915 |
Label notNaN; |
| 916 |
branchDouble(DoubleOrdered, reg, reg, ¬NaN); |
| 917 |
loadConstantDouble(JS::GenericNaN(), reg); |
| 918 |
bind(¬NaN); |
| 919 |
} |
| 920 |
|
| 921 |
// ======================================================================== |
| 922 |
// Memory access primitives. |
| 923 |
|
| 924 |
template <class T> |
| 925 |
void MacroAssembler::boxDouble(FloatRegister src, const T& dest) { |
| 926 |
storeDouble(src, dest); |
| 927 |
} |
| 928 |
|
| 929 |
template <typename T> |
| 930 |
void MacroAssembler::fallibleUnboxInt32(const T& src, Register dest, |
| 931 |
Label* fail) { |
| 932 |
// Int32Value can be unboxed efficiently with unboxInt32, so use that. |
| 933 |
branchTestInt32(Assembler::NotEqual, src, fail); |
| 934 |
unboxInt32(src, dest); |
| 935 |
} |
| 936 |
|
| 937 |
template <typename T> |
| 938 |
void MacroAssembler::fallibleUnboxBoolean(const T& src, Register dest, |
| 939 |
Label* fail) { |
| 940 |
// BooleanValue can be unboxed efficiently with unboxBoolean, so use that. |
| 941 |
branchTestBoolean(Assembler::NotEqual, src, fail); |
| 942 |
unboxBoolean(src, dest); |
| 943 |
} |
| 944 |
|
| 945 |
template <typename T> |
| 946 |
void MacroAssembler::fallibleUnboxObject(const T& src, Register dest, |
| 947 |
Label* fail) { |
| 948 |
fallibleUnboxPtr(src, dest, JSVAL_TYPE_OBJECT, fail); |
| 949 |
} |
| 950 |
|
| 951 |
template <typename T> |
| 952 |
void MacroAssembler::fallibleUnboxString(const T& src, Register dest, |
| 953 |
Label* fail) { |
| 954 |
fallibleUnboxPtr(src, dest, JSVAL_TYPE_STRING, fail); |
| 955 |
} |
| 956 |
|
| 957 |
template <typename T> |
| 958 |
void MacroAssembler::fallibleUnboxSymbol(const T& src, Register dest, |
| 959 |
Label* fail) { |
| 960 |
fallibleUnboxPtr(src, dest, JSVAL_TYPE_SYMBOL, fail); |
| 961 |
} |
| 962 |
|
| 963 |
template <typename T> |
| 964 |
void MacroAssembler::fallibleUnboxBigInt(const T& src, Register dest, |
| 965 |
Label* fail) { |
| 966 |
fallibleUnboxPtr(src, dest, JSVAL_TYPE_BIGINT, fail); |
| 967 |
} |
| 968 |
|
| 969 |
//}}} check_macroassembler_style |
| 970 |
// =============================================================== |
| 971 |
|
| 972 |
void MacroAssembler::ensureDouble(const ValueOperand& source, |
| 973 |
FloatRegister dest, Label* failure) { |
| 974 |
Label isDouble, done; |
| 975 |
|
| 976 |
{ |
| 977 |
ScratchTagScope tag(*this, source); |
| 978 |
splitTagForTest(source, tag); |
| 979 |
branchTestDouble(Assembler::Equal, tag, &isDouble); |
| 980 |
branchTestInt32(Assembler::NotEqual, tag, failure); |
| 981 |
} |
| 982 |
|
| 983 |
convertInt32ToDouble(source.payloadOrValueReg(), dest); |
| 984 |
jump(&done); |
| 985 |
|
| 986 |
bind(&isDouble); |
| 987 |
unboxDouble(source, dest); |
| 988 |
|
| 989 |
bind(&done); |
| 990 |
} |
| 991 |
|
| 992 |
#ifndef JS_CODEGEN_ARM64 |
| 993 |
|
| 994 |
template <typename T> |
| 995 |
void MacroAssembler::branchTestStackPtr(Condition cond, T t, Label* label) { |
| 996 |
branchTestPtr(cond, getStackPointer(), t, label); |
| 997 |
} |
| 998 |
|
| 999 |
template <typename T> |
| 1000 |
void MacroAssembler::branchStackPtr(Condition cond, T rhs, Label* label) { |
| 1001 |
branchPtr(cond, getStackPointer(), rhs, label); |
| 1002 |
} |
| 1003 |
|
| 1004 |
template <typename T> |
| 1005 |
void MacroAssembler::branchStackPtrRhs(Condition cond, T lhs, Label* label) { |
| 1006 |
branchPtr(cond, lhs, getStackPointer(), label); |
| 1007 |
} |
| 1008 |
|
| 1009 |
template <typename T> |
| 1010 |
void MacroAssembler::addToStackPtr(T t) { |
| 1011 |
addPtr(t, getStackPointer()); |
| 1012 |
} |
| 1013 |
|
| 1014 |
template <typename T> |
| 1015 |
void MacroAssembler::addStackPtrTo(T t) { |
| 1016 |
addPtr(getStackPointer(), t); |
| 1017 |
} |
| 1018 |
|
| 1019 |
void MacroAssembler::reserveStack(uint32_t amount) { |
| 1020 |
subFromStackPtr(Imm32(amount)); |
| 1021 |
adjustFrame(amount); |
| 1022 |
} |
| 1023 |
#endif // !JS_CODEGEN_ARM64 |
| 1024 |
|
| 1025 |
void MacroAssembler::loadObjClassUnsafe(Register obj, Register dest) { |
| 1026 |
loadPtr(Address(obj, JSObject::offsetOfShape()), dest); |
| 1027 |
loadPtr(Address(dest, Shape::offsetOfBaseShape()), dest); |
| 1028 |
loadPtr(Address(dest, BaseShape::offsetOfClasp()), dest); |
| 1029 |
} |
| 1030 |
|
| 1031 |
void MacroAssembler::loadObjShapeUnsafe(Register obj, Register dest) { |
| 1032 |
loadPtr(Address(obj, JSObject::offsetOfShape()), dest); |
| 1033 |
} |
| 1034 |
|
| 1035 |
template <typename EmitPreBarrier> |
| 1036 |
void MacroAssembler::storeObjShape(Register shape, Register obj, |
| 1037 |
EmitPreBarrier emitPreBarrier) { |
| 1038 |
MOZ_ASSERT(shape != obj); |
| 1039 |
Address shapeAddr(obj, JSObject::offsetOfShape()); |
| 1040 |
emitPreBarrier(*this, shapeAddr); |
| 1041 |
storePtr(shape, shapeAddr); |
| 1042 |
} |
| 1043 |
|
| 1044 |
template <typename EmitPreBarrier> |
| 1045 |
void MacroAssembler::storeObjShape(Shape* shape, Register obj, |
| 1046 |
EmitPreBarrier emitPreBarrier) { |
| 1047 |
Address shapeAddr(obj, JSObject::offsetOfShape()); |
| 1048 |
emitPreBarrier(*this, shapeAddr); |
| 1049 |
storePtr(ImmGCPtr(shape), shapeAddr); |
| 1050 |
} |
| 1051 |
|
| 1052 |
void MacroAssembler::loadObjProto(Register obj, Register dest) { |
| 1053 |
loadPtr(Address(obj, JSObject::offsetOfShape()), dest); |
| 1054 |
loadPtr(Address(dest, Shape::offsetOfBaseShape()), dest); |
| 1055 |
loadPtr(Address(dest, BaseShape::offsetOfProto()), dest); |
| 1056 |
} |
| 1057 |
|
| 1058 |
void MacroAssembler::loadStringLength(Register str, Register dest) { |
| 1059 |
load32(Address(str, JSString::offsetOfLength()), dest); |
| 1060 |
} |
| 1061 |
|
| 1062 |
void MacroAssembler::assertStackAlignment(uint32_t alignment, |
| 1063 |
int32_t offset /* = 0 */) { |
| 1064 |
#ifdef DEBUG |
| 1065 |
Label ok, bad; |
| 1066 |
MOZ_ASSERT(mozilla::IsPowerOfTwo(alignment)); |
| 1067 |
|
| 1068 |
// Wrap around the offset to be a non-negative number. |
| 1069 |
offset %= alignment; |
| 1070 |
if (offset < 0) { |
| 1071 |
offset += alignment; |
| 1072 |
} |
| 1073 |
|
| 1074 |
// Test if each bit from offset is set. |
| 1075 |
uint32_t off = offset; |
| 1076 |
while (off) { |
| 1077 |
uint32_t lowestBit = 1 << mozilla::CountTrailingZeroes32(off); |
| 1078 |
branchTestStackPtr(Assembler::Zero, Imm32(lowestBit), &bad); |
| 1079 |
off ^= lowestBit; |
| 1080 |
} |
| 1081 |
|
| 1082 |
// Check that all remaining bits are zero. |
| 1083 |
branchTestStackPtr(Assembler::Zero, Imm32((alignment - 1) ^ offset), &ok); |
| 1084 |
|
| 1085 |
bind(&bad); |
| 1086 |
breakpoint(); |
| 1087 |
bind(&ok); |
| 1088 |
#endif |
| 1089 |
} |
| 1090 |
|
| 1091 |
void MacroAssembler::storeCallBoolResult(Register reg) { |
| 1092 |
convertBoolToInt32(ReturnReg, reg); |
| 1093 |
} |
| 1094 |
|
| 1095 |
void MacroAssembler::storeCallInt32Result(Register reg) { |
| 1096 |
#if JS_BITS_PER_WORD == 32 |
| 1097 |
storeCallPointerResult(reg); |
| 1098 |
#else |
| 1099 |
// Ensure the upper 32 bits are cleared. |
| 1100 |
move32(ReturnReg, reg); |
| 1101 |
#endif |
| 1102 |
} |
| 1103 |
|
| 1104 |
void MacroAssembler::storeCallResultValue(AnyRegister dest, JSValueType type) { |
| 1105 |
unboxValue(JSReturnOperand, dest, type); |
| 1106 |
} |
| 1107 |
|
| 1108 |
void MacroAssembler::storeCallResultValue(TypedOrValueRegister dest) { |
| 1109 |
if (dest.hasValue()) { |
| 1110 |
storeCallResultValue(dest.valueReg()); |
| 1111 |
} else { |
| 1112 |
storeCallResultValue(dest.typedReg(), ValueTypeFromMIRType(dest.type())); |
| 1113 |
} |
| 1114 |
} |
| 1115 |
|
| 1116 |
} // namespace jit |
| 1117 |
} // namespace js |
| 1118 |
|
| 1119 |
#endif /* jit_MacroAssembler_inl_h */ |