2 * Copyright (C) 2008 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #ifndef JITInlineMethods_h
27 #define JITInlineMethods_h
34 /* Deprecated: Please use JITStubCall instead. */
36 ALWAYS_INLINE void JIT::emitGetJITStubArg(unsigned argumentNumber, RegisterID dst)
38 unsigned argumentStackOffset = (argumentNumber * (sizeof(JSValue) / sizeof(void*))) + JITSTACKFRAME_ARGS_INDEX;
39 peek(dst, argumentStackOffset);
42 ALWAYS_INLINE bool JIT::isOperandConstantImmediateDouble(unsigned src)
44 return m_codeBlock->isConstantRegisterIndex(src) && getConstantOperand(src).isDouble();
47 ALWAYS_INLINE JSValue JIT::getConstantOperand(unsigned src)
49 ASSERT(m_codeBlock->isConstantRegisterIndex(src));
50 return m_codeBlock->getConstant(src);
53 ALWAYS_INLINE void JIT::emitPutToCallFrameHeader(RegisterID from, RegisterFile::CallFrameHeaderEntry entry)
55 storePtr(from, payloadFor(entry, callFrameRegister));
58 ALWAYS_INLINE void JIT::emitPutCellToCallFrameHeader(RegisterID from, RegisterFile::CallFrameHeaderEntry entry)
61 store32(TrustedImm32(JSValue::CellTag), tagFor(entry, callFrameRegister));
63 storePtr(from, payloadFor(entry, callFrameRegister));
66 ALWAYS_INLINE void JIT::emitPutIntToCallFrameHeader(RegisterID from, RegisterFile::CallFrameHeaderEntry entry)
68 store32(TrustedImm32(Int32Tag), intTagFor(entry, callFrameRegister));
69 store32(from, intPayloadFor(entry, callFrameRegister));
72 ALWAYS_INLINE void JIT::emitPutImmediateToCallFrameHeader(void* value, RegisterFile::CallFrameHeaderEntry entry)
74 storePtr(TrustedImmPtr(value), Address(callFrameRegister, entry * sizeof(Register)));
77 ALWAYS_INLINE void JIT::emitGetFromCallFrameHeaderPtr(RegisterFile::CallFrameHeaderEntry entry, RegisterID to, RegisterID from)
79 loadPtr(Address(from, entry * sizeof(Register)), to);
81 killLastResultRegister();
85 ALWAYS_INLINE void JIT::emitLoadCharacterString(RegisterID src, RegisterID dst, JumpList& failures)
87 failures.append(branchPtr(NotEqual, Address(src), TrustedImmPtr(m_globalData->jsStringVPtr)));
88 failures.append(branch32(NotEqual, MacroAssembler::Address(src, ThunkHelpers::jsStringLengthOffset()), TrustedImm32(1)));
89 loadPtr(MacroAssembler::Address(src, ThunkHelpers::jsStringValueOffset()), dst);
90 failures.append(branchTest32(Zero, dst));
91 loadPtr(MacroAssembler::Address(dst, ThunkHelpers::stringImplFlagsOffset()), regT1);
92 loadPtr(MacroAssembler::Address(dst, ThunkHelpers::stringImplDataOffset()), dst);
96 is16Bit.append(branchTest32(Zero, regT1, TrustedImm32(ThunkHelpers::stringImpl8BitFlag())));
97 load8(MacroAssembler::Address(dst, 0), dst);
98 cont8Bit.append(jump());
100 load16(MacroAssembler::Address(dst, 0), dst);
104 ALWAYS_INLINE void JIT::emitGetFromCallFrameHeader32(RegisterFile::CallFrameHeaderEntry entry, RegisterID to, RegisterID from)
106 load32(Address(from, entry * sizeof(Register)), to);
108 killLastResultRegister();
112 ALWAYS_INLINE JIT::Call JIT::emitNakedCall(CodePtr function)
114 ASSERT(m_bytecodeOffset != (unsigned)-1); // This method should only be called during hot/cold path generation, so that m_bytecodeOffset is set.
116 Call nakedCall = nearCall();
117 m_calls.append(CallRecord(nakedCall, m_bytecodeOffset, function.executableAddress()));
121 ALWAYS_INLINE bool JIT::atJumpTarget()
123 while (m_jumpTargetsPosition < m_codeBlock->numberOfJumpTargets() && m_codeBlock->jumpTarget(m_jumpTargetsPosition) <= m_bytecodeOffset) {
124 if (m_codeBlock->jumpTarget(m_jumpTargetsPosition) == m_bytecodeOffset)
126 ++m_jumpTargetsPosition;
131 #if defined(ASSEMBLER_HAS_CONSTANT_POOL) && ASSEMBLER_HAS_CONSTANT_POOL
133 ALWAYS_INLINE void JIT::beginUninterruptedSequence(int insnSpace, int constSpace)
135 JSInterfaceJIT::beginUninterruptedSequence();
136 #if CPU(ARM_TRADITIONAL)
138 // Ensure the label after the sequence can also fit
139 insnSpace += sizeof(ARMWord);
140 constSpace += sizeof(uint64_t);
143 ensureSpace(insnSpace, constSpace);
147 insnSpace += sizeof(SH4Word);
148 constSpace += sizeof(uint64_t);
151 m_assembler.ensureSpace(insnSpace + m_assembler.maxInstructionSize + 2, constSpace + 8);
154 #if defined(ASSEMBLER_HAS_CONSTANT_POOL) && ASSEMBLER_HAS_CONSTANT_POOL
156 m_uninterruptedInstructionSequenceBegin = label();
157 m_uninterruptedConstantSequenceBegin = sizeOfConstantPool();
162 ALWAYS_INLINE void JIT::endUninterruptedSequence(int insnSpace, int constSpace, int dst)
165 #if defined(ASSEMBLER_HAS_CONSTANT_POOL) && ASSEMBLER_HAS_CONSTANT_POOL
166 /* There are several cases when the uninterrupted sequence is larger than
167 * maximum required offset for pathing the same sequence. Eg.: if in a
168 * uninterrupted sequence the last macroassembler's instruction is a stub
169 * call, it emits store instruction(s) which should not be included in the
170 * calculation of length of uninterrupted sequence. So, the insnSpace and
171 * constSpace should be upper limit instead of hard limit.
174 if ((dst > 15) || (dst < -16)) {
179 if (((dst >= -16) && (dst < 0)) || ((dst > 7) && (dst <= 15)))
182 ASSERT(differenceBetween(m_uninterruptedInstructionSequenceBegin, label()) <= insnSpace);
183 ASSERT(sizeOfConstantPool() - m_uninterruptedConstantSequenceBegin <= constSpace);
185 JSInterfaceJIT::endUninterruptedSequence();
192 ALWAYS_INLINE void JIT::preserveReturnAddressAfterCall(RegisterID reg)
194 move(linkRegister, reg);
197 ALWAYS_INLINE void JIT::restoreReturnAddressBeforeReturn(RegisterID reg)
199 move(reg, linkRegister);
202 ALWAYS_INLINE void JIT::restoreReturnAddressBeforeReturn(Address address)
204 loadPtr(address, linkRegister);
208 ALWAYS_INLINE void JIT::preserveReturnAddressAfterCall(RegisterID reg)
210 m_assembler.stspr(reg);
213 ALWAYS_INLINE void JIT::restoreReturnAddressBeforeReturn(RegisterID reg)
215 m_assembler.ldspr(reg);
218 ALWAYS_INLINE void JIT::restoreReturnAddressBeforeReturn(Address address)
220 loadPtrLinkReg(address);
225 ALWAYS_INLINE void JIT::preserveReturnAddressAfterCall(RegisterID reg)
227 move(returnAddressRegister, reg);
230 ALWAYS_INLINE void JIT::restoreReturnAddressBeforeReturn(RegisterID reg)
232 move(reg, returnAddressRegister);
235 ALWAYS_INLINE void JIT::restoreReturnAddressBeforeReturn(Address address)
237 loadPtr(address, returnAddressRegister);
240 #else // CPU(X86) || CPU(X86_64)
242 ALWAYS_INLINE void JIT::preserveReturnAddressAfterCall(RegisterID reg)
247 ALWAYS_INLINE void JIT::restoreReturnAddressBeforeReturn(RegisterID reg)
252 ALWAYS_INLINE void JIT::restoreReturnAddressBeforeReturn(Address address)
259 ALWAYS_INLINE void JIT::restoreArgumentReference()
261 move(stackPointerRegister, firstArgumentRegister);
262 poke(callFrameRegister, OBJECT_OFFSETOF(struct JITStackFrame, callFrame) / sizeof(void*));
265 ALWAYS_INLINE void JIT::updateTopCallFrame()
267 storePtr(callFrameRegister, &m_globalData->topCallFrame);
270 ALWAYS_INLINE void JIT::restoreArgumentReferenceForTrampoline()
273 // Within a trampoline the return address will be on the stack at this point.
274 addPtr(TrustedImm32(sizeof(void*)), stackPointerRegister, firstArgumentRegister);
276 move(stackPointerRegister, firstArgumentRegister);
278 move(stackPointerRegister, firstArgumentRegister);
280 // In the trampoline on x86-64, the first argument register is not overwritten.
283 ALWAYS_INLINE JIT::Jump JIT::checkStructure(RegisterID reg, Structure* structure)
285 return branchPtr(NotEqual, Address(reg, JSCell::structureOffset()), TrustedImmPtr(structure));
288 ALWAYS_INLINE void JIT::linkSlowCaseIfNotJSCell(Vector<SlowCaseEntry>::iterator& iter, int vReg)
290 if (!m_codeBlock->isKnownNotImmediate(vReg))
294 ALWAYS_INLINE void JIT::addSlowCase(Jump jump)
296 ASSERT(m_bytecodeOffset != (unsigned)-1); // This method should only be called during hot/cold path generation, so that m_bytecodeOffset is set.
298 m_slowCases.append(SlowCaseEntry(jump, m_bytecodeOffset));
301 ALWAYS_INLINE void JIT::addSlowCase(JumpList jumpList)
303 ASSERT(m_bytecodeOffset != (unsigned)-1); // This method should only be called during hot/cold path generation, so that m_bytecodeOffset is set.
305 const JumpList::JumpVector& jumpVector = jumpList.jumps();
306 size_t size = jumpVector.size();
307 for (size_t i = 0; i < size; ++i)
308 m_slowCases.append(SlowCaseEntry(jumpVector[i], m_bytecodeOffset));
311 ALWAYS_INLINE void JIT::addSlowCase()
313 ASSERT(m_bytecodeOffset != (unsigned)-1); // This method should only be called during hot/cold path generation, so that m_bytecodeOffset is set.
315 Jump emptyJump; // Doing it this way to make Windows happy.
316 m_slowCases.append(SlowCaseEntry(emptyJump, m_bytecodeOffset));
319 ALWAYS_INLINE void JIT::addJump(Jump jump, int relativeOffset)
321 ASSERT(m_bytecodeOffset != (unsigned)-1); // This method should only be called during hot/cold path generation, so that m_bytecodeOffset is set.
323 m_jmpTable.append(JumpTable(jump, m_bytecodeOffset + relativeOffset));
326 ALWAYS_INLINE void JIT::emitJumpSlowToHot(Jump jump, int relativeOffset)
328 ASSERT(m_bytecodeOffset != (unsigned)-1); // This method should only be called during hot/cold path generation, so that m_bytecodeOffset is set.
330 jump.linkTo(m_labels[m_bytecodeOffset + relativeOffset], this);
333 ALWAYS_INLINE JIT::Jump JIT::emitJumpIfNotObject(RegisterID structureReg)
335 return branch8(Below, Address(structureReg, Structure::typeInfoTypeOffset()), TrustedImm32(ObjectType));
338 ALWAYS_INLINE JIT::Jump JIT::emitJumpIfNotType(RegisterID baseReg, RegisterID scratchReg, JSType type)
340 loadPtr(Address(baseReg, JSCell::structureOffset()), scratchReg);
341 return branch8(NotEqual, Address(scratchReg, Structure::typeInfoTypeOffset()), TrustedImm32(type));
344 #if ENABLE(SAMPLING_FLAGS)
345 ALWAYS_INLINE void JIT::setSamplingFlag(int32_t flag)
349 or32(TrustedImm32(1u << (flag - 1)), AbsoluteAddress(SamplingFlags::addressOfFlags()));
352 ALWAYS_INLINE void JIT::clearSamplingFlag(int32_t flag)
356 and32(TrustedImm32(~(1u << (flag - 1))), AbsoluteAddress(SamplingFlags::addressOfFlags()));
360 #if ENABLE(SAMPLING_COUNTERS)
361 ALWAYS_INLINE void JIT::emitCount(AbstractSamplingCounter& counter, int32_t count)
363 add64(TrustedImm32(count), AbsoluteAddress(counter.addressOfCounter()));
367 #if ENABLE(OPCODE_SAMPLING)
369 ALWAYS_INLINE void JIT::sampleInstruction(Instruction* instruction, bool inHostFunction)
371 move(TrustedImmPtr(m_interpreter->sampler()->sampleSlot()), X86Registers::ecx);
372 storePtr(TrustedImmPtr(m_interpreter->sampler()->encodeSample(instruction, inHostFunction)), X86Registers::ecx);
375 ALWAYS_INLINE void JIT::sampleInstruction(Instruction* instruction, bool inHostFunction)
377 storePtr(TrustedImmPtr(m_interpreter->sampler()->encodeSample(instruction, inHostFunction)), m_interpreter->sampler()->sampleSlot());
382 #if ENABLE(CODEBLOCK_SAMPLING)
384 ALWAYS_INLINE void JIT::sampleCodeBlock(CodeBlock* codeBlock)
386 move(TrustedImmPtr(m_interpreter->sampler()->codeBlockSlot()), X86Registers::ecx);
387 storePtr(TrustedImmPtr(codeBlock), X86Registers::ecx);
390 ALWAYS_INLINE void JIT::sampleCodeBlock(CodeBlock* codeBlock)
392 storePtr(TrustedImmPtr(codeBlock), m_interpreter->sampler()->codeBlockSlot());
397 ALWAYS_INLINE bool JIT::isOperandConstantImmediateChar(unsigned src)
399 return m_codeBlock->isConstantRegisterIndex(src) && getConstantOperand(src).isString() && asString(getConstantOperand(src).asCell())->length() == 1;
402 template <typename ClassType, typename StructureType> inline void JIT::emitAllocateBasicJSObject(StructureType structure, void* vtable, RegisterID result, RegisterID storagePtr)
404 MarkedSpace::SizeClass* sizeClass = &m_globalData->heap.sizeClassForObject(sizeof(ClassType));
405 loadPtr(&sizeClass->firstFreeCell, result);
406 addSlowCase(branchTestPtr(Zero, result));
408 // remove the object from the free list
409 loadPtr(Address(result), storagePtr);
410 storePtr(storagePtr, &sizeClass->firstFreeCell);
412 // initialize the object's vtable
413 storePtr(TrustedImmPtr(vtable), Address(result));
415 // initialize the object's structure
416 storePtr(structure, Address(result, JSCell::structureOffset()));
418 // initialize the inheritor ID
419 storePtr(TrustedImmPtr(0), Address(result, JSObject::offsetOfInheritorID()));
421 // initialize the object's property storage pointer
422 addPtr(TrustedImm32(sizeof(JSObject)), result, storagePtr);
423 storePtr(storagePtr, Address(result, ClassType::offsetOfPropertyStorage()));
426 template <typename T> inline void JIT::emitAllocateJSFinalObject(T structure, RegisterID result, RegisterID scratch)
428 emitAllocateBasicJSObject<JSFinalObject>(structure, m_globalData->jsFinalObjectVPtr, result, scratch);
431 inline void JIT::emitAllocateJSFunction(FunctionExecutable* executable, RegisterID scopeChain, RegisterID result, RegisterID storagePtr)
433 emitAllocateBasicJSObject<JSFunction>(TrustedImmPtr(m_codeBlock->globalObject()->namedFunctionStructure()), m_globalData->jsFunctionVPtr, result, storagePtr);
435 // store the function's scope chain
436 storePtr(scopeChain, Address(result, JSFunction::offsetOfScopeChain()));
438 // store the function's executable member
439 storePtr(TrustedImmPtr(executable), Address(result, JSFunction::offsetOfExecutable()));
441 // store the function's name
442 ASSERT(executable->nameValue());
443 int functionNameOffset = sizeof(JSValue) * m_codeBlock->globalObject()->functionNameOffset();
444 storePtr(TrustedImmPtr(executable->nameValue()), Address(regT1, functionNameOffset + OBJECT_OFFSETOF(JSValue, u.asBits.payload)));
445 #if USE(JSVALUE32_64)
446 store32(TrustedImm32(JSValue::CellTag), Address(regT1, functionNameOffset + OBJECT_OFFSETOF(JSValue, u.asBits.tag)));
450 #if ENABLE(VALUE_PROFILER)
451 inline void JIT::emitValueProfilingSite(ValueProfilingSiteKind siteKind)
453 if (!shouldEmitProfiling())
456 const RegisterID value = regT0;
457 #if USE(JSVALUE32_64)
458 const RegisterID valueTag = regT1;
460 const RegisterID scratch = regT3;
462 ValueProfile* valueProfile;
463 if (siteKind == FirstProfilingSite)
464 valueProfile = m_codeBlock->addValueProfile(m_bytecodeOffset);
466 ASSERT(siteKind == SubsequentProfilingSite);
467 valueProfile = m_codeBlock->valueProfileForBytecodeOffset(m_bytecodeOffset);
470 ASSERT(valueProfile);
472 if (ValueProfile::numberOfBuckets == 1) {
473 // We're in a simple configuration: only one bucket, so we can just do a direct
476 storePtr(value, valueProfile->m_buckets);
478 EncodedValueDescriptor* descriptor = bitwise_cast<EncodedValueDescriptor*>(valueProfile->m_buckets);
479 store32(value, &descriptor->asBits.payload);
480 store32(valueTag, &descriptor->asBits.tag);
485 if (m_randomGenerator.getUint32() & 1)
486 add32(Imm32(1), bucketCounterRegister);
488 add32(Imm32(3), bucketCounterRegister);
489 and32(Imm32(ValueProfile::bucketIndexMask), bucketCounterRegister);
490 move(ImmPtr(valueProfile->m_buckets), scratch);
492 storePtr(value, BaseIndex(scratch, bucketCounterRegister, TimesEight));
493 #elif USE(JSVALUE32_64)
494 store32(value, BaseIndex(scratch, bucketCounterRegister, TimesEight, OBJECT_OFFSETOF(JSValue, u.asBits.payload)));
495 store32(valueTag, BaseIndex(scratch, bucketCounterRegister, TimesEight, OBJECT_OFFSETOF(JSValue, u.asBits.tag)));
500 #if USE(JSVALUE32_64)
502 inline void JIT::emitLoadTag(int index, RegisterID tag)
504 RegisterID mappedTag;
505 if (getMappedTag(index, mappedTag)) {
506 move(mappedTag, tag);
511 if (m_codeBlock->isConstantRegisterIndex(index)) {
512 move(Imm32(getConstantOperand(index).tag()), tag);
517 load32(tagFor(index), tag);
521 inline void JIT::emitLoadPayload(int index, RegisterID payload)
523 RegisterID mappedPayload;
524 if (getMappedPayload(index, mappedPayload)) {
525 move(mappedPayload, payload);
530 if (m_codeBlock->isConstantRegisterIndex(index)) {
531 move(Imm32(getConstantOperand(index).payload()), payload);
536 load32(payloadFor(index), payload);
540 inline void JIT::emitLoad(const JSValue& v, RegisterID tag, RegisterID payload)
542 move(Imm32(v.payload()), payload);
543 move(Imm32(v.tag()), tag);
546 inline void JIT::emitLoad(int index, RegisterID tag, RegisterID payload, RegisterID base)
548 ASSERT(tag != payload);
550 if (base == callFrameRegister) {
551 ASSERT(payload != base);
552 emitLoadPayload(index, payload);
553 emitLoadTag(index, tag);
557 if (payload == base) { // avoid stomping base
558 load32(tagFor(index, base), tag);
559 load32(payloadFor(index, base), payload);
563 load32(payloadFor(index, base), payload);
564 load32(tagFor(index, base), tag);
567 inline void JIT::emitLoad2(int index1, RegisterID tag1, RegisterID payload1, int index2, RegisterID tag2, RegisterID payload2)
569 if (isMapped(index1)) {
570 emitLoad(index1, tag1, payload1);
571 emitLoad(index2, tag2, payload2);
574 emitLoad(index2, tag2, payload2);
575 emitLoad(index1, tag1, payload1);
578 inline void JIT::emitLoadDouble(int index, FPRegisterID value)
580 if (m_codeBlock->isConstantRegisterIndex(index)) {
581 WriteBarrier<Unknown>& inConstantPool = m_codeBlock->constantRegister(index);
582 loadDouble(&inConstantPool, value);
584 loadDouble(addressFor(index), value);
587 inline void JIT::emitLoadInt32ToDouble(int index, FPRegisterID value)
589 if (m_codeBlock->isConstantRegisterIndex(index)) {
590 WriteBarrier<Unknown>& inConstantPool = m_codeBlock->constantRegister(index);
591 char* bytePointer = reinterpret_cast<char*>(&inConstantPool);
592 convertInt32ToDouble(AbsoluteAddress(bytePointer + OBJECT_OFFSETOF(JSValue, u.asBits.payload)), value);
594 convertInt32ToDouble(payloadFor(index), value);
597 inline void JIT::emitStore(int index, RegisterID tag, RegisterID payload, RegisterID base)
599 store32(payload, payloadFor(index, base));
600 store32(tag, tagFor(index, base));
603 inline void JIT::emitStoreInt32(int index, RegisterID payload, bool indexIsInt32)
605 store32(payload, payloadFor(index, callFrameRegister));
607 store32(TrustedImm32(JSValue::Int32Tag), tagFor(index, callFrameRegister));
610 inline void JIT::emitStoreAndMapInt32(int index, RegisterID tag, RegisterID payload, bool indexIsInt32, size_t opcodeLength)
612 emitStoreInt32(index, payload, indexIsInt32);
613 map(m_bytecodeOffset + opcodeLength, index, tag, payload);
616 inline void JIT::emitStoreInt32(int index, TrustedImm32 payload, bool indexIsInt32)
618 store32(payload, payloadFor(index, callFrameRegister));
620 store32(TrustedImm32(JSValue::Int32Tag), tagFor(index, callFrameRegister));
623 inline void JIT::emitStoreCell(int index, RegisterID payload, bool indexIsCell)
625 store32(payload, payloadFor(index, callFrameRegister));
627 store32(TrustedImm32(JSValue::CellTag), tagFor(index, callFrameRegister));
630 inline void JIT::emitStoreBool(int index, RegisterID payload, bool indexIsBool)
632 store32(payload, payloadFor(index, callFrameRegister));
634 store32(TrustedImm32(JSValue::BooleanTag), tagFor(index, callFrameRegister));
637 inline void JIT::emitStoreDouble(int index, FPRegisterID value)
639 storeDouble(value, addressFor(index));
642 inline void JIT::emitStore(int index, const JSValue constant, RegisterID base)
644 store32(Imm32(constant.payload()), payloadFor(index, base));
645 store32(Imm32(constant.tag()), tagFor(index, base));
648 ALWAYS_INLINE void JIT::emitInitRegister(unsigned dst)
650 emitStore(dst, jsUndefined());
653 inline bool JIT::isLabeled(unsigned bytecodeOffset)
655 for (size_t numberOfJumpTargets = m_codeBlock->numberOfJumpTargets(); m_jumpTargetIndex != numberOfJumpTargets; ++m_jumpTargetIndex) {
656 unsigned jumpTarget = m_codeBlock->jumpTarget(m_jumpTargetIndex);
657 if (jumpTarget == bytecodeOffset)
659 if (jumpTarget > bytecodeOffset)
665 inline void JIT::map(unsigned bytecodeOffset, int virtualRegisterIndex, RegisterID tag, RegisterID payload)
667 if (isLabeled(bytecodeOffset))
670 m_mappedBytecodeOffset = bytecodeOffset;
671 m_mappedVirtualRegisterIndex = virtualRegisterIndex;
673 m_mappedPayload = payload;
676 inline void JIT::unmap(RegisterID registerID)
678 if (m_mappedTag == registerID)
679 m_mappedTag = (RegisterID)-1;
680 else if (m_mappedPayload == registerID)
681 m_mappedPayload = (RegisterID)-1;
684 inline void JIT::unmap()
686 m_mappedBytecodeOffset = (unsigned)-1;
687 m_mappedVirtualRegisterIndex = RegisterFile::ReturnPC;
688 m_mappedTag = (RegisterID)-1;
689 m_mappedPayload = (RegisterID)-1;
692 inline bool JIT::isMapped(int virtualRegisterIndex)
694 if (m_mappedBytecodeOffset != m_bytecodeOffset)
696 if (m_mappedVirtualRegisterIndex != virtualRegisterIndex)
701 inline bool JIT::getMappedPayload(int virtualRegisterIndex, RegisterID& payload)
703 if (m_mappedBytecodeOffset != m_bytecodeOffset)
705 if (m_mappedVirtualRegisterIndex != virtualRegisterIndex)
707 if (m_mappedPayload == (RegisterID)-1)
709 payload = m_mappedPayload;
713 inline bool JIT::getMappedTag(int virtualRegisterIndex, RegisterID& tag)
715 if (m_mappedBytecodeOffset != m_bytecodeOffset)
717 if (m_mappedVirtualRegisterIndex != virtualRegisterIndex)
719 if (m_mappedTag == (RegisterID)-1)
725 inline void JIT::emitJumpSlowCaseIfNotJSCell(int virtualRegisterIndex)
727 if (!m_codeBlock->isKnownNotImmediate(virtualRegisterIndex)) {
728 if (m_codeBlock->isConstantRegisterIndex(virtualRegisterIndex))
731 addSlowCase(emitJumpIfNotJSCell(virtualRegisterIndex));
735 inline void JIT::emitJumpSlowCaseIfNotJSCell(int virtualRegisterIndex, RegisterID tag)
737 if (!m_codeBlock->isKnownNotImmediate(virtualRegisterIndex)) {
738 if (m_codeBlock->isConstantRegisterIndex(virtualRegisterIndex))
741 addSlowCase(branch32(NotEqual, tag, TrustedImm32(JSValue::CellTag)));
745 ALWAYS_INLINE bool JIT::isOperandConstantImmediateInt(unsigned src)
747 return m_codeBlock->isConstantRegisterIndex(src) && getConstantOperand(src).isInt32();
750 ALWAYS_INLINE bool JIT::getOperandConstantImmediateInt(unsigned op1, unsigned op2, unsigned& op, int32_t& constant)
752 if (isOperandConstantImmediateInt(op1)) {
753 constant = getConstantOperand(op1).asInt32();
758 if (isOperandConstantImmediateInt(op2)) {
759 constant = getConstantOperand(op2).asInt32();
767 #else // USE(JSVALUE32_64)
769 ALWAYS_INLINE void JIT::killLastResultRegister()
771 m_lastResultBytecodeRegister = std::numeric_limits<int>::max();
774 // get arg puts an arg from the SF register array into a h/w register
775 ALWAYS_INLINE void JIT::emitGetVirtualRegister(int src, RegisterID dst)
777 ASSERT(m_bytecodeOffset != (unsigned)-1); // This method should only be called during hot/cold path generation, so that m_bytecodeOffset is set.
779 // TODO: we want to reuse values that are already in registers if we can - add a register allocator!
780 if (m_codeBlock->isConstantRegisterIndex(src)) {
781 JSValue value = m_codeBlock->getConstant(src);
782 move(ImmPtr(JSValue::encode(value)), dst);
783 killLastResultRegister();
787 if (src == m_lastResultBytecodeRegister && m_codeBlock->isTemporaryRegisterIndex(src) && !atJumpTarget()) {
788 // The argument we want is already stored in eax
789 if (dst != cachedResultRegister)
790 move(cachedResultRegister, dst);
791 killLastResultRegister();
795 loadPtr(Address(callFrameRegister, src * sizeof(Register)), dst);
796 killLastResultRegister();
799 ALWAYS_INLINE void JIT::emitGetVirtualRegisters(int src1, RegisterID dst1, int src2, RegisterID dst2)
801 if (src2 == m_lastResultBytecodeRegister) {
802 emitGetVirtualRegister(src2, dst2);
803 emitGetVirtualRegister(src1, dst1);
805 emitGetVirtualRegister(src1, dst1);
806 emitGetVirtualRegister(src2, dst2);
810 ALWAYS_INLINE int32_t JIT::getConstantOperandImmediateInt(unsigned src)
812 return getConstantOperand(src).asInt32();
815 ALWAYS_INLINE bool JIT::isOperandConstantImmediateInt(unsigned src)
817 return m_codeBlock->isConstantRegisterIndex(src) && getConstantOperand(src).isInt32();
820 ALWAYS_INLINE void JIT::emitPutVirtualRegister(unsigned dst, RegisterID from)
822 storePtr(from, Address(callFrameRegister, dst * sizeof(Register)));
823 m_lastResultBytecodeRegister = (from == cachedResultRegister) ? static_cast<int>(dst) : std::numeric_limits<int>::max();
826 ALWAYS_INLINE void JIT::emitInitRegister(unsigned dst)
828 storePtr(TrustedImmPtr(JSValue::encode(jsUndefined())), Address(callFrameRegister, dst * sizeof(Register)));
831 ALWAYS_INLINE JIT::Jump JIT::emitJumpIfJSCell(RegisterID reg)
834 return branchTestPtr(Zero, reg, tagMaskRegister);
836 return branchTest32(Zero, reg, TrustedImm32(TagMask));
840 ALWAYS_INLINE JIT::Jump JIT::emitJumpIfBothJSCells(RegisterID reg1, RegisterID reg2, RegisterID scratch)
843 orPtr(reg2, scratch);
844 return emitJumpIfJSCell(scratch);
847 ALWAYS_INLINE void JIT::emitJumpSlowCaseIfJSCell(RegisterID reg)
849 addSlowCase(emitJumpIfJSCell(reg));
852 ALWAYS_INLINE JIT::Jump JIT::emitJumpIfNotJSCell(RegisterID reg)
855 return branchTestPtr(NonZero, reg, tagMaskRegister);
857 return branchTest32(NonZero, reg, TrustedImm32(TagMask));
861 ALWAYS_INLINE void JIT::emitJumpSlowCaseIfNotJSCell(RegisterID reg)
863 addSlowCase(emitJumpIfNotJSCell(reg));
866 ALWAYS_INLINE void JIT::emitJumpSlowCaseIfNotJSCell(RegisterID reg, int vReg)
868 if (!m_codeBlock->isKnownNotImmediate(vReg))
869 emitJumpSlowCaseIfNotJSCell(reg);
874 inline void JIT::emitLoadDouble(int index, FPRegisterID value)
876 if (m_codeBlock->isConstantRegisterIndex(index)) {
877 WriteBarrier<Unknown>& inConstantPool = m_codeBlock->constantRegister(index);
878 loadDouble(&inConstantPool, value);
880 loadDouble(addressFor(index), value);
883 inline void JIT::emitLoadInt32ToDouble(int index, FPRegisterID value)
885 if (m_codeBlock->isConstantRegisterIndex(index)) {
886 ASSERT(isOperandConstantImmediateInt(index));
887 convertInt32ToDouble(Imm32(getConstantOperand(index).asInt32()), value);
889 convertInt32ToDouble(addressFor(index), value);
893 ALWAYS_INLINE JIT::Jump JIT::emitJumpIfImmediateInteger(RegisterID reg)
896 return branchPtr(AboveOrEqual, reg, tagTypeNumberRegister);
898 return branchTest32(NonZero, reg, TrustedImm32(TagTypeNumber));
902 ALWAYS_INLINE JIT::Jump JIT::emitJumpIfNotImmediateInteger(RegisterID reg)
905 return branchPtr(Below, reg, tagTypeNumberRegister);
907 return branchTest32(Zero, reg, TrustedImm32(TagTypeNumber));
911 ALWAYS_INLINE JIT::Jump JIT::emitJumpIfNotImmediateIntegers(RegisterID reg1, RegisterID reg2, RegisterID scratch)
914 andPtr(reg2, scratch);
915 return emitJumpIfNotImmediateInteger(scratch);
918 ALWAYS_INLINE void JIT::emitJumpSlowCaseIfNotImmediateInteger(RegisterID reg)
920 addSlowCase(emitJumpIfNotImmediateInteger(reg));
923 ALWAYS_INLINE void JIT::emitJumpSlowCaseIfNotImmediateIntegers(RegisterID reg1, RegisterID reg2, RegisterID scratch)
925 addSlowCase(emitJumpIfNotImmediateIntegers(reg1, reg2, scratch));
928 ALWAYS_INLINE void JIT::emitJumpSlowCaseIfNotImmediateNumber(RegisterID reg)
930 addSlowCase(emitJumpIfNotImmediateNumber(reg));
933 #if USE(JSVALUE32_64)
934 ALWAYS_INLINE void JIT::emitFastArithDeTagImmediate(RegisterID reg)
936 subPtr(TrustedImm32(TagTypeNumber), reg);
939 ALWAYS_INLINE JIT::Jump JIT::emitFastArithDeTagImmediateJumpIfZero(RegisterID reg)
941 return branchSubPtr(Zero, TrustedImm32(TagTypeNumber), reg);
945 ALWAYS_INLINE void JIT::emitFastArithReTagImmediate(RegisterID src, RegisterID dest)
948 emitFastArithIntToImmNoCheck(src, dest);
952 addPtr(TrustedImm32(TagTypeNumber), dest);
956 // operand is int32_t, must have been zero-extended if register is 64-bit.
957 ALWAYS_INLINE void JIT::emitFastArithIntToImmNoCheck(RegisterID src, RegisterID dest)
962 orPtr(tagTypeNumberRegister, dest);
964 signExtend32ToPtr(src, dest);
966 emitFastArithReTagImmediate(dest, dest);
970 ALWAYS_INLINE void JIT::emitTagAsBoolImmediate(RegisterID reg)
972 or32(TrustedImm32(static_cast<int32_t>(ValueFalse)), reg);
975 #endif // USE(JSVALUE32_64)
979 #endif // ENABLE(JIT)