barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 1 | /* |
fpizlo@apple.com | 604d38a | 2012-07-01 03:54:49 +0000 | [diff] [blame] | 2 | * Copyright (C) 2008, 2012 Apple Inc. All rights reserved. |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 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. |
| 12 | * |
| 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. |
| 24 | */ |
| 25 | |
mark.lam@apple.com | a4fe7ab | 2012-11-09 03:03:44 +0000 | [diff] [blame] | 26 | #ifndef JITInlines_h |
| 27 | #define JITInlines_h |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 28 | |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 29 | |
| 30 | #if ENABLE(JIT) |
| 31 | |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 32 | namespace JSC { |
| 33 | |
oliver@apple.com | 8d18163 | 2009-09-25 02:40:59 +0000 | [diff] [blame] | 34 | ALWAYS_INLINE bool JIT::isOperandConstantImmediateDouble(unsigned src) |
| 35 | { |
| 36 | return m_codeBlock->isConstantRegisterIndex(src) && getConstantOperand(src).isDouble(); |
| 37 | } |
| 38 | |
ggaren@apple.com | dc067b6 | 2009-05-01 22:43:39 +0000 | [diff] [blame] | 39 | ALWAYS_INLINE JSValue JIT::getConstantOperand(unsigned src) |
barraclough@apple.com | be1ce03 | 2009-01-02 03:06:10 +0000 | [diff] [blame] | 40 | { |
| 41 | ASSERT(m_codeBlock->isConstantRegisterIndex(src)); |
| 42 | return m_codeBlock->getConstant(src); |
| 43 | } |
| 44 | |
mark.lam@apple.com | 4fbb9c3 | 2012-10-09 07:12:56 +0000 | [diff] [blame] | 45 | ALWAYS_INLINE void JIT::emitPutIntToCallFrameHeader(RegisterID from, JSStack::CallFrameHeaderEntry entry) |
oliver@apple.com | 9d4f0ec | 2011-03-14 18:16:36 +0000 | [diff] [blame] | 46 | { |
yuqiang.xian@intel.com | 5b1cb73 | 2012-10-19 05:46:10 +0000 | [diff] [blame] | 47 | #if USE(JSVALUE32_64) |
oliver@apple.com | be4e067 | 2011-03-28 17:14:57 +0000 | [diff] [blame] | 48 | store32(TrustedImm32(Int32Tag), intTagFor(entry, callFrameRegister)); |
oliver@apple.com | 9d4f0ec | 2011-03-14 18:16:36 +0000 | [diff] [blame] | 49 | store32(from, intPayloadFor(entry, callFrameRegister)); |
yuqiang.xian@intel.com | 5b1cb73 | 2012-10-19 05:46:10 +0000 | [diff] [blame] | 50 | #else |
| 51 | store64(from, addressFor(entry, callFrameRegister)); |
| 52 | #endif |
| 53 | } |
| 54 | |
mark.lam@apple.com | 4fbb9c3 | 2012-10-09 07:12:56 +0000 | [diff] [blame] | 55 | ALWAYS_INLINE void JIT::emitGetFromCallFrameHeaderPtr(JSStack::CallFrameHeaderEntry entry, RegisterID to, RegisterID from) |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 56 | { |
oliver@apple.com | e79807b | 2009-05-05 11:34:23 +0000 | [diff] [blame] | 57 | loadPtr(Address(from, entry * sizeof(Register)), to); |
oliver@apple.com | 0cc25c3 | 2010-10-19 23:55:08 +0000 | [diff] [blame] | 58 | #if USE(JSVALUE64) |
oliver@apple.com | e79807b | 2009-05-05 11:34:23 +0000 | [diff] [blame] | 59 | killLastResultRegister(); |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 60 | #endif |
oliver@apple.com | e79807b | 2009-05-05 11:34:23 +0000 | [diff] [blame] | 61 | } |
| 62 | |
yuqiang.xian@intel.com | 5b1cb73 | 2012-10-19 05:46:10 +0000 | [diff] [blame] | 63 | ALWAYS_INLINE void JIT::emitGetFromCallFrameHeader32(JSStack::CallFrameHeaderEntry entry, RegisterID to, RegisterID from) |
| 64 | { |
| 65 | load32(Address(from, entry * sizeof(Register)), to); |
| 66 | #if USE(JSVALUE64) |
| 67 | killLastResultRegister(); |
| 68 | #endif |
| 69 | } |
| 70 | |
| 71 | #if USE(JSVALUE64) |
| 72 | ALWAYS_INLINE void JIT::emitGetFromCallFrameHeader64(JSStack::CallFrameHeaderEntry entry, RegisterID to, RegisterID from) |
| 73 | { |
| 74 | load64(Address(from, entry * sizeof(Register)), to); |
| 75 | killLastResultRegister(); |
| 76 | } |
| 77 | #endif |
| 78 | |
oliver@apple.com | 5230bd3 | 2010-05-06 19:39:54 +0000 | [diff] [blame] | 79 | ALWAYS_INLINE void JIT::emitLoadCharacterString(RegisterID src, RegisterID dst, JumpList& failures) |
| 80 | { |
mhahnenberg@apple.com | 85c200b | 2012-08-02 17:32:35 +0000 | [diff] [blame] | 81 | failures.append(branchPtr(NotEqual, Address(src, JSCell::structureOffset()), TrustedImmPtr(m_globalData->stringStructure.get()))); |
oliver@apple.com | be4e067 | 2011-03-28 17:14:57 +0000 | [diff] [blame] | 82 | failures.append(branch32(NotEqual, MacroAssembler::Address(src, ThunkHelpers::jsStringLengthOffset()), TrustedImm32(1))); |
oliver@apple.com | 5230bd3 | 2010-05-06 19:39:54 +0000 | [diff] [blame] | 83 | loadPtr(MacroAssembler::Address(src, ThunkHelpers::jsStringValueOffset()), dst); |
ggaren@apple.com | ffbe44d | 2011-10-19 19:45:35 +0000 | [diff] [blame] | 84 | failures.append(branchTest32(Zero, dst)); |
msaboff@apple.com | a64c581 | 2011-10-28 01:09:53 +0000 | [diff] [blame] | 85 | loadPtr(MacroAssembler::Address(dst, ThunkHelpers::stringImplFlagsOffset()), regT1); |
oliver@apple.com | 5230bd3 | 2010-05-06 19:39:54 +0000 | [diff] [blame] | 86 | loadPtr(MacroAssembler::Address(dst, ThunkHelpers::stringImplDataOffset()), dst); |
msaboff@apple.com | a64c581 | 2011-10-28 01:09:53 +0000 | [diff] [blame] | 87 | |
| 88 | JumpList is16Bit; |
| 89 | JumpList cont8Bit; |
| 90 | is16Bit.append(branchTest32(Zero, regT1, TrustedImm32(ThunkHelpers::stringImpl8BitFlag()))); |
| 91 | load8(MacroAssembler::Address(dst, 0), dst); |
| 92 | cont8Bit.append(jump()); |
| 93 | is16Bit.link(this); |
oliver@apple.com | 5230bd3 | 2010-05-06 19:39:54 +0000 | [diff] [blame] | 94 | load16(MacroAssembler::Address(dst, 0), dst); |
msaboff@apple.com | a64c581 | 2011-10-28 01:09:53 +0000 | [diff] [blame] | 95 | cont8Bit.link(this); |
oliver@apple.com | 5230bd3 | 2010-05-06 19:39:54 +0000 | [diff] [blame] | 96 | } |
| 97 | |
barraclough@apple.com | 97bacef | 2009-06-05 07:55:38 +0000 | [diff] [blame] | 98 | ALWAYS_INLINE JIT::Call JIT::emitNakedCall(CodePtr function) |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 99 | { |
ggaren@apple.com | 1ba4981 | 2010-05-19 18:28:54 +0000 | [diff] [blame] | 100 | ASSERT(m_bytecodeOffset != (unsigned)-1); // This method should only be called during hot/cold path generation, so that m_bytecodeOffset is set. |
barraclough@apple.com | 249befb | 2008-12-13 03:18:10 +0000 | [diff] [blame] | 101 | |
barraclough@apple.com | d7e1338 | 2009-02-19 22:51:40 +0000 | [diff] [blame] | 102 | Call nakedCall = nearCall(); |
ggaren@apple.com | 1ba4981 | 2010-05-19 18:28:54 +0000 | [diff] [blame] | 103 | m_calls.append(CallRecord(nakedCall, m_bytecodeOffset, function.executableAddress())); |
barraclough@apple.com | 8092415 | 2008-12-05 06:58:40 +0000 | [diff] [blame] | 104 | return nakedCall; |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 105 | } |
| 106 | |
barraclough@apple.com | 4836c7a | 2011-05-01 22:20:59 +0000 | [diff] [blame] | 107 | ALWAYS_INLINE bool JIT::atJumpTarget() |
| 108 | { |
| 109 | while (m_jumpTargetsPosition < m_codeBlock->numberOfJumpTargets() && m_codeBlock->jumpTarget(m_jumpTargetsPosition) <= m_bytecodeOffset) { |
| 110 | if (m_codeBlock->jumpTarget(m_jumpTargetsPosition) == m_bytecodeOffset) |
| 111 | return true; |
| 112 | ++m_jumpTargetsPosition; |
| 113 | } |
| 114 | return false; |
| 115 | } |
| 116 | |
barraclough@apple.com | 970af2c | 2009-08-13 05:58:36 +0000 | [diff] [blame] | 117 | #if defined(ASSEMBLER_HAS_CONSTANT_POOL) && ASSEMBLER_HAS_CONSTANT_POOL |
| 118 | |
| 119 | ALWAYS_INLINE void JIT::beginUninterruptedSequence(int insnSpace, int constSpace) |
| 120 | { |
mjs@apple.com | cc66821 | 2010-01-04 11:38:56 +0000 | [diff] [blame] | 121 | #if CPU(ARM_TRADITIONAL) |
barraclough@apple.com | 970af2c | 2009-08-13 05:58:36 +0000 | [diff] [blame] | 122 | #ifndef NDEBUG |
| 123 | // Ensure the label after the sequence can also fit |
| 124 | insnSpace += sizeof(ARMWord); |
| 125 | constSpace += sizeof(uint64_t); |
| 126 | #endif |
| 127 | |
| 128 | ensureSpace(insnSpace, constSpace); |
| 129 | |
commit-queue@webkit.org | d5765e4 | 2011-04-11 17:11:38 +0000 | [diff] [blame] | 130 | #elif CPU(SH4) |
| 131 | #ifndef NDEBUG |
| 132 | insnSpace += sizeof(SH4Word); |
| 133 | constSpace += sizeof(uint64_t); |
| 134 | #endif |
| 135 | |
| 136 | m_assembler.ensureSpace(insnSpace + m_assembler.maxInstructionSize + 2, constSpace + 8); |
barraclough@apple.com | 970af2c | 2009-08-13 05:58:36 +0000 | [diff] [blame] | 137 | #endif |
| 138 | |
| 139 | #if defined(ASSEMBLER_HAS_CONSTANT_POOL) && ASSEMBLER_HAS_CONSTANT_POOL |
| 140 | #ifndef NDEBUG |
| 141 | m_uninterruptedInstructionSequenceBegin = label(); |
| 142 | m_uninterruptedConstantSequenceBegin = sizeOfConstantPool(); |
| 143 | #endif |
| 144 | #endif |
| 145 | } |
| 146 | |
commit-queue@webkit.org | d5765e4 | 2011-04-11 17:11:38 +0000 | [diff] [blame] | 147 | ALWAYS_INLINE void JIT::endUninterruptedSequence(int insnSpace, int constSpace, int dst) |
barraclough@apple.com | 970af2c | 2009-08-13 05:58:36 +0000 | [diff] [blame] | 148 | { |
commit-queue@webkit.org | d5765e4 | 2011-04-11 17:11:38 +0000 | [diff] [blame] | 149 | UNUSED_PARAM(dst); |
barraclough@apple.com | 970af2c | 2009-08-13 05:58:36 +0000 | [diff] [blame] | 150 | #if defined(ASSEMBLER_HAS_CONSTANT_POOL) && ASSEMBLER_HAS_CONSTANT_POOL |
loki@webkit.org | ebaef24 | 2010-11-10 07:36:33 +0000 | [diff] [blame] | 151 | /* There are several cases when the uninterrupted sequence is larger than |
| 152 | * maximum required offset for pathing the same sequence. Eg.: if in a |
| 153 | * uninterrupted sequence the last macroassembler's instruction is a stub |
| 154 | * call, it emits store instruction(s) which should not be included in the |
| 155 | * calculation of length of uninterrupted sequence. So, the insnSpace and |
| 156 | * constSpace should be upper limit instead of hard limit. |
| 157 | */ |
commit-queue@webkit.org | d5765e4 | 2011-04-11 17:11:38 +0000 | [diff] [blame] | 158 | #if CPU(SH4) |
| 159 | if ((dst > 15) || (dst < -16)) { |
| 160 | insnSpace += 8; |
| 161 | constSpace += 2; |
| 162 | } |
| 163 | |
| 164 | if (((dst >= -16) && (dst < 0)) || ((dst > 7) && (dst <= 15))) |
| 165 | insnSpace += 8; |
| 166 | #endif |
loki@webkit.org | ebaef24 | 2010-11-10 07:36:33 +0000 | [diff] [blame] | 167 | ASSERT(differenceBetween(m_uninterruptedInstructionSequenceBegin, label()) <= insnSpace); |
| 168 | ASSERT(sizeOfConstantPool() - m_uninterruptedConstantSequenceBegin <= constSpace); |
barraclough@apple.com | 970af2c | 2009-08-13 05:58:36 +0000 | [diff] [blame] | 169 | #endif |
| 170 | } |
| 171 | |
| 172 | #endif |
| 173 | |
commit-queue@webkit.org | 8481462 | 2011-08-25 01:25:38 +0000 | [diff] [blame] | 174 | ALWAYS_INLINE void JIT::updateTopCallFrame() |
| 175 | { |
oliver@apple.com | 8b234c9 | 2012-02-08 21:22:49 +0000 | [diff] [blame] | 176 | ASSERT(static_cast<int>(m_bytecodeOffset) >= 0); |
fpizlo@apple.com | 7bbcaab | 2012-02-22 05:23:19 +0000 | [diff] [blame] | 177 | if (m_bytecodeOffset) { |
| 178 | #if USE(JSVALUE32_64) |
mark.lam@apple.com | 4fbb9c3 | 2012-10-09 07:12:56 +0000 | [diff] [blame] | 179 | storePtr(TrustedImmPtr(m_codeBlock->instructions().begin() + m_bytecodeOffset + 1), intTagFor(JSStack::ArgumentCount)); |
fpizlo@apple.com | 7bbcaab | 2012-02-22 05:23:19 +0000 | [diff] [blame] | 180 | #else |
mark.lam@apple.com | 4fbb9c3 | 2012-10-09 07:12:56 +0000 | [diff] [blame] | 181 | store32(TrustedImm32(m_bytecodeOffset + 1), intTagFor(JSStack::ArgumentCount)); |
fpizlo@apple.com | 7bbcaab | 2012-02-22 05:23:19 +0000 | [diff] [blame] | 182 | #endif |
| 183 | } |
commit-queue@webkit.org | 8481462 | 2011-08-25 01:25:38 +0000 | [diff] [blame] | 184 | storePtr(callFrameRegister, &m_globalData->topCallFrame); |
| 185 | } |
| 186 | |
barraclough@apple.com | 23f0c05 | 2008-12-16 04:48:16 +0000 | [diff] [blame] | 187 | ALWAYS_INLINE void JIT::restoreArgumentReferenceForTrampoline() |
| 188 | { |
mjs@apple.com | cc66821 | 2010-01-04 11:38:56 +0000 | [diff] [blame] | 189 | #if CPU(X86) |
barraclough@apple.com | f545549 | 2009-06-09 06:52:25 +0000 | [diff] [blame] | 190 | // Within a trampoline the return address will be on the stack at this point. |
oliver@apple.com | be4e067 | 2011-03-28 17:14:57 +0000 | [diff] [blame] | 191 | addPtr(TrustedImm32(sizeof(void*)), stackPointerRegister, firstArgumentRegister); |
mjs@apple.com | cc66821 | 2010-01-04 11:38:56 +0000 | [diff] [blame] | 192 | #elif CPU(ARM) |
barraclough@apple.com | ea6b609 | 2009-02-13 04:22:02 +0000 | [diff] [blame] | 193 | move(stackPointerRegister, firstArgumentRegister); |
commit-queue@webkit.org | d5765e4 | 2011-04-11 17:11:38 +0000 | [diff] [blame] | 194 | #elif CPU(SH4) |
| 195 | move(stackPointerRegister, firstArgumentRegister); |
barraclough@apple.com | 289318a | 2008-12-22 01:00:07 +0000 | [diff] [blame] | 196 | #endif |
barraclough@apple.com | f545549 | 2009-06-09 06:52:25 +0000 | [diff] [blame] | 197 | // In the trampoline on x86-64, the first argument register is not overwritten. |
barraclough@apple.com | 23f0c05 | 2008-12-16 04:48:16 +0000 | [diff] [blame] | 198 | } |
barraclough@apple.com | 23f0c05 | 2008-12-16 04:48:16 +0000 | [diff] [blame] | 199 | |
barraclough@apple.com | a2a2e13 | 2008-12-13 23:58:58 +0000 | [diff] [blame] | 200 | ALWAYS_INLINE JIT::Jump JIT::checkStructure(RegisterID reg, Structure* structure) |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 201 | { |
oliver@apple.com | be4e067 | 2011-03-28 17:14:57 +0000 | [diff] [blame] | 202 | return branchPtr(NotEqual, Address(reg, JSCell::structureOffset()), TrustedImmPtr(structure)); |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 203 | } |
| 204 | |
barraclough@apple.com | 4f46a50 | 2008-12-13 01:39:38 +0000 | [diff] [blame] | 205 | ALWAYS_INLINE void JIT::linkSlowCaseIfNotJSCell(Vector<SlowCaseEntry>::iterator& iter, int vReg) |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 206 | { |
barraclough@apple.com | 4f46a50 | 2008-12-13 01:39:38 +0000 | [diff] [blame] | 207 | if (!m_codeBlock->isKnownNotImmediate(vReg)) |
| 208 | linkSlowCase(iter); |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 209 | } |
| 210 | |
barraclough@apple.com | a2a2e13 | 2008-12-13 23:58:58 +0000 | [diff] [blame] | 211 | ALWAYS_INLINE void JIT::addSlowCase(Jump jump) |
barraclough@apple.com | 249befb | 2008-12-13 03:18:10 +0000 | [diff] [blame] | 212 | { |
ggaren@apple.com | 1ba4981 | 2010-05-19 18:28:54 +0000 | [diff] [blame] | 213 | ASSERT(m_bytecodeOffset != (unsigned)-1); // This method should only be called during hot/cold path generation, so that m_bytecodeOffset is set. |
barraclough@apple.com | 249befb | 2008-12-13 03:18:10 +0000 | [diff] [blame] | 214 | |
ggaren@apple.com | 1ba4981 | 2010-05-19 18:28:54 +0000 | [diff] [blame] | 215 | m_slowCases.append(SlowCaseEntry(jump, m_bytecodeOffset)); |
barraclough@apple.com | 249befb | 2008-12-13 03:18:10 +0000 | [diff] [blame] | 216 | } |
| 217 | |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 218 | ALWAYS_INLINE void JIT::addSlowCase(JumpList jumpList) |
| 219 | { |
ggaren@apple.com | 1ba4981 | 2010-05-19 18:28:54 +0000 | [diff] [blame] | 220 | ASSERT(m_bytecodeOffset != (unsigned)-1); // This method should only be called during hot/cold path generation, so that m_bytecodeOffset is set. |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 221 | |
| 222 | const JumpList::JumpVector& jumpVector = jumpList.jumps(); |
| 223 | size_t size = jumpVector.size(); |
| 224 | for (size_t i = 0; i < size; ++i) |
ggaren@apple.com | 1ba4981 | 2010-05-19 18:28:54 +0000 | [diff] [blame] | 225 | m_slowCases.append(SlowCaseEntry(jumpVector[i], m_bytecodeOffset)); |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 226 | } |
| 227 | |
fpizlo@apple.com | 9b0b31e | 2011-09-19 22:27:38 +0000 | [diff] [blame] | 228 | ALWAYS_INLINE void JIT::addSlowCase() |
| 229 | { |
| 230 | ASSERT(m_bytecodeOffset != (unsigned)-1); // This method should only be called during hot/cold path generation, so that m_bytecodeOffset is set. |
| 231 | |
| 232 | Jump emptyJump; // Doing it this way to make Windows happy. |
| 233 | m_slowCases.append(SlowCaseEntry(emptyJump, m_bytecodeOffset)); |
| 234 | } |
| 235 | |
barraclough@apple.com | a2a2e13 | 2008-12-13 23:58:58 +0000 | [diff] [blame] | 236 | ALWAYS_INLINE void JIT::addJump(Jump jump, int relativeOffset) |
barraclough@apple.com | 249befb | 2008-12-13 03:18:10 +0000 | [diff] [blame] | 237 | { |
ggaren@apple.com | 1ba4981 | 2010-05-19 18:28:54 +0000 | [diff] [blame] | 238 | ASSERT(m_bytecodeOffset != (unsigned)-1); // This method should only be called during hot/cold path generation, so that m_bytecodeOffset is set. |
barraclough@apple.com | 249befb | 2008-12-13 03:18:10 +0000 | [diff] [blame] | 239 | |
ggaren@apple.com | 1ba4981 | 2010-05-19 18:28:54 +0000 | [diff] [blame] | 240 | m_jmpTable.append(JumpTable(jump, m_bytecodeOffset + relativeOffset)); |
barraclough@apple.com | 249befb | 2008-12-13 03:18:10 +0000 | [diff] [blame] | 241 | } |
| 242 | |
barraclough@apple.com | a2a2e13 | 2008-12-13 23:58:58 +0000 | [diff] [blame] | 243 | ALWAYS_INLINE void JIT::emitJumpSlowToHot(Jump jump, int relativeOffset) |
barraclough@apple.com | 249befb | 2008-12-13 03:18:10 +0000 | [diff] [blame] | 244 | { |
ggaren@apple.com | 1ba4981 | 2010-05-19 18:28:54 +0000 | [diff] [blame] | 245 | ASSERT(m_bytecodeOffset != (unsigned)-1); // This method should only be called during hot/cold path generation, so that m_bytecodeOffset is set. |
barraclough@apple.com | 249befb | 2008-12-13 03:18:10 +0000 | [diff] [blame] | 246 | |
ggaren@apple.com | 1ba4981 | 2010-05-19 18:28:54 +0000 | [diff] [blame] | 247 | jump.linkTo(m_labels[m_bytecodeOffset + relativeOffset], this); |
barraclough@apple.com | 249befb | 2008-12-13 03:18:10 +0000 | [diff] [blame] | 248 | } |
| 249 | |
barraclough@apple.com | b8bcc94 | 2011-09-07 17:55:50 +0000 | [diff] [blame] | 250 | ALWAYS_INLINE JIT::Jump JIT::emitJumpIfNotObject(RegisterID structureReg) |
| 251 | { |
weinig@apple.com | 58576b2 | 2011-09-16 21:34:20 +0000 | [diff] [blame] | 252 | return branch8(Below, Address(structureReg, Structure::typeInfoTypeOffset()), TrustedImm32(ObjectType)); |
barraclough@apple.com | b8bcc94 | 2011-09-07 17:55:50 +0000 | [diff] [blame] | 253 | } |
| 254 | |
barraclough@apple.com | 536c0db | 2009-05-12 06:21:56 +0000 | [diff] [blame] | 255 | #if ENABLE(SAMPLING_FLAGS) |
barraclough@apple.com | c32f32e | 2009-05-13 09:10:02 +0000 | [diff] [blame] | 256 | ALWAYS_INLINE void JIT::setSamplingFlag(int32_t flag) |
barraclough@apple.com | 536c0db | 2009-05-12 06:21:56 +0000 | [diff] [blame] | 257 | { |
| 258 | ASSERT(flag >= 1); |
| 259 | ASSERT(flag <= 32); |
barraclough@apple.com | 02dee5d | 2011-04-21 01:03:44 +0000 | [diff] [blame] | 260 | or32(TrustedImm32(1u << (flag - 1)), AbsoluteAddress(SamplingFlags::addressOfFlags())); |
barraclough@apple.com | 536c0db | 2009-05-12 06:21:56 +0000 | [diff] [blame] | 261 | } |
| 262 | |
barraclough@apple.com | c32f32e | 2009-05-13 09:10:02 +0000 | [diff] [blame] | 263 | ALWAYS_INLINE void JIT::clearSamplingFlag(int32_t flag) |
barraclough@apple.com | 536c0db | 2009-05-12 06:21:56 +0000 | [diff] [blame] | 264 | { |
| 265 | ASSERT(flag >= 1); |
| 266 | ASSERT(flag <= 32); |
barraclough@apple.com | 02dee5d | 2011-04-21 01:03:44 +0000 | [diff] [blame] | 267 | and32(TrustedImm32(~(1u << (flag - 1))), AbsoluteAddress(SamplingFlags::addressOfFlags())); |
barraclough@apple.com | c32f32e | 2009-05-13 09:10:02 +0000 | [diff] [blame] | 268 | } |
| 269 | #endif |
| 270 | |
| 271 | #if ENABLE(SAMPLING_COUNTERS) |
barraclough@apple.com | 6d410b0 | 2011-11-10 20:24:06 +0000 | [diff] [blame] | 272 | ALWAYS_INLINE void JIT::emitCount(AbstractSamplingCounter& counter, int32_t count) |
barraclough@apple.com | c32f32e | 2009-05-13 09:10:02 +0000 | [diff] [blame] | 273 | { |
barraclough@apple.com | 6d410b0 | 2011-11-10 20:24:06 +0000 | [diff] [blame] | 274 | add64(TrustedImm32(count), AbsoluteAddress(counter.addressOfCounter())); |
barraclough@apple.com | 536c0db | 2009-05-12 06:21:56 +0000 | [diff] [blame] | 275 | } |
| 276 | #endif |
| 277 | |
| 278 | #if ENABLE(OPCODE_SAMPLING) |
mjs@apple.com | cc66821 | 2010-01-04 11:38:56 +0000 | [diff] [blame] | 279 | #if CPU(X86_64) |
barraclough@apple.com | 536c0db | 2009-05-12 06:21:56 +0000 | [diff] [blame] | 280 | ALWAYS_INLINE void JIT::sampleInstruction(Instruction* instruction, bool inHostFunction) |
| 281 | { |
oliver@apple.com | be4e067 | 2011-03-28 17:14:57 +0000 | [diff] [blame] | 282 | move(TrustedImmPtr(m_interpreter->sampler()->sampleSlot()), X86Registers::ecx); |
| 283 | storePtr(TrustedImmPtr(m_interpreter->sampler()->encodeSample(instruction, inHostFunction)), X86Registers::ecx); |
barraclough@apple.com | 536c0db | 2009-05-12 06:21:56 +0000 | [diff] [blame] | 284 | } |
| 285 | #else |
| 286 | ALWAYS_INLINE void JIT::sampleInstruction(Instruction* instruction, bool inHostFunction) |
| 287 | { |
oliver@apple.com | be4e067 | 2011-03-28 17:14:57 +0000 | [diff] [blame] | 288 | storePtr(TrustedImmPtr(m_interpreter->sampler()->encodeSample(instruction, inHostFunction)), m_interpreter->sampler()->sampleSlot()); |
barraclough@apple.com | 536c0db | 2009-05-12 06:21:56 +0000 | [diff] [blame] | 289 | } |
| 290 | #endif |
| 291 | #endif |
| 292 | |
| 293 | #if ENABLE(CODEBLOCK_SAMPLING) |
mjs@apple.com | cc66821 | 2010-01-04 11:38:56 +0000 | [diff] [blame] | 294 | #if CPU(X86_64) |
barraclough@apple.com | 536c0db | 2009-05-12 06:21:56 +0000 | [diff] [blame] | 295 | ALWAYS_INLINE void JIT::sampleCodeBlock(CodeBlock* codeBlock) |
| 296 | { |
oliver@apple.com | be4e067 | 2011-03-28 17:14:57 +0000 | [diff] [blame] | 297 | move(TrustedImmPtr(m_interpreter->sampler()->codeBlockSlot()), X86Registers::ecx); |
| 298 | storePtr(TrustedImmPtr(codeBlock), X86Registers::ecx); |
barraclough@apple.com | 536c0db | 2009-05-12 06:21:56 +0000 | [diff] [blame] | 299 | } |
| 300 | #else |
| 301 | ALWAYS_INLINE void JIT::sampleCodeBlock(CodeBlock* codeBlock) |
| 302 | { |
oliver@apple.com | be4e067 | 2011-03-28 17:14:57 +0000 | [diff] [blame] | 303 | storePtr(TrustedImmPtr(codeBlock), m_interpreter->sampler()->codeBlockSlot()); |
barraclough@apple.com | 536c0db | 2009-05-12 06:21:56 +0000 | [diff] [blame] | 304 | } |
| 305 | #endif |
| 306 | #endif |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 307 | |
oliver@apple.com | 5230bd3 | 2010-05-06 19:39:54 +0000 | [diff] [blame] | 308 | ALWAYS_INLINE bool JIT::isOperandConstantImmediateChar(unsigned src) |
| 309 | { |
| 310 | return m_codeBlock->isConstantRegisterIndex(src) && getConstantOperand(src).isString() && asString(getConstantOperand(src).asCell())->length() == 1; |
| 311 | } |
| 312 | |
mhahnenberg@apple.com | 30738a7 | 2012-10-03 17:51:28 +0000 | [diff] [blame] | 313 | template <typename ClassType, MarkedBlock::DestructorType destructorType, typename StructureType> inline void JIT::emitAllocateBasicJSObject(StructureType structure, RegisterID result, RegisterID storagePtr) |
commit-queue@webkit.org | c9b19ab | 2011-07-18 18:55:48 +0000 | [diff] [blame] | 314 | { |
ggaren@apple.com | ac950c4 | 2012-10-11 20:56:31 +0000 | [diff] [blame] | 315 | size_t size = ClassType::allocationSize(INLINE_STORAGE_CAPACITY); |
mhahnenberg@apple.com | c274832 | 2012-02-10 22:44:09 +0000 | [diff] [blame] | 316 | MarkedAllocator* allocator = 0; |
mhahnenberg@apple.com | 30738a7 | 2012-10-03 17:51:28 +0000 | [diff] [blame] | 317 | if (destructorType == MarkedBlock::Normal) |
ggaren@apple.com | ac950c4 | 2012-10-11 20:56:31 +0000 | [diff] [blame] | 318 | allocator = &m_globalData->heap.allocatorForObjectWithNormalDestructor(size); |
mhahnenberg@apple.com | 30738a7 | 2012-10-03 17:51:28 +0000 | [diff] [blame] | 319 | else if (destructorType == MarkedBlock::ImmortalStructure) |
ggaren@apple.com | ac950c4 | 2012-10-11 20:56:31 +0000 | [diff] [blame] | 320 | allocator = &m_globalData->heap.allocatorForObjectWithImmortalStructureDestructor(size); |
mhahnenberg@apple.com | c274832 | 2012-02-10 22:44:09 +0000 | [diff] [blame] | 321 | else |
ggaren@apple.com | ac950c4 | 2012-10-11 20:56:31 +0000 | [diff] [blame] | 322 | allocator = &m_globalData->heap.allocatorForObjectWithoutDestructor(size); |
mhahnenberg@apple.com | 8b5cfd3 | 2012-04-20 00:05:37 +0000 | [diff] [blame] | 323 | loadPtr(&allocator->m_freeList.head, result); |
commit-queue@webkit.org | c9b19ab | 2011-07-18 18:55:48 +0000 | [diff] [blame] | 324 | addSlowCase(branchTestPtr(Zero, result)); |
oliver@apple.com | e843bc0 | 2011-08-05 20:03:19 +0000 | [diff] [blame] | 325 | |
commit-queue@webkit.org | c9b19ab | 2011-07-18 18:55:48 +0000 | [diff] [blame] | 326 | // remove the object from the free list |
oliver@apple.com | e843bc0 | 2011-08-05 20:03:19 +0000 | [diff] [blame] | 327 | loadPtr(Address(result), storagePtr); |
mhahnenberg@apple.com | 8b5cfd3 | 2012-04-20 00:05:37 +0000 | [diff] [blame] | 328 | storePtr(storagePtr, &allocator->m_freeList.head); |
oliver@apple.com | e843bc0 | 2011-08-05 20:03:19 +0000 | [diff] [blame] | 329 | |
commit-queue@webkit.org | c9b19ab | 2011-07-18 18:55:48 +0000 | [diff] [blame] | 330 | // initialize the object's structure |
| 331 | storePtr(structure, Address(result, JSCell::structureOffset())); |
oliver@apple.com | e843bc0 | 2011-08-05 20:03:19 +0000 | [diff] [blame] | 332 | |
commit-queue@webkit.org | c9b19ab | 2011-07-18 18:55:48 +0000 | [diff] [blame] | 333 | // initialize the object's property storage pointer |
fpizlo@apple.com | d8dd053 | 2012-09-13 04:18:52 +0000 | [diff] [blame] | 334 | storePtr(TrustedImmPtr(0), Address(result, JSObject::butterflyOffset())); |
oliver@apple.com | e843bc0 | 2011-08-05 20:03:19 +0000 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | template <typename T> inline void JIT::emitAllocateJSFinalObject(T structure, RegisterID result, RegisterID scratch) |
| 338 | { |
mhahnenberg@apple.com | 30738a7 | 2012-10-03 17:51:28 +0000 | [diff] [blame] | 339 | emitAllocateBasicJSObject<JSFinalObject, MarkedBlock::None, T>(structure, result, scratch); |
oliver@apple.com | e843bc0 | 2011-08-05 20:03:19 +0000 | [diff] [blame] | 340 | } |
| 341 | |
fpizlo@apple.com | 95a9f0d | 2011-08-20 02:17:49 +0000 | [diff] [blame] | 342 | #if ENABLE(VALUE_PROFILER) |
fpizlo@apple.com | 086d2af | 2011-12-21 02:29:15 +0000 | [diff] [blame] | 343 | inline void JIT::emitValueProfilingSite(ValueProfile* valueProfile) |
fpizlo@apple.com | 95a9f0d | 2011-08-20 02:17:49 +0000 | [diff] [blame] | 344 | { |
fpizlo@apple.com | 086d2af | 2011-12-21 02:29:15 +0000 | [diff] [blame] | 345 | ASSERT(shouldEmitProfiling()); |
| 346 | ASSERT(valueProfile); |
| 347 | |
fpizlo@apple.com | 95a9f0d | 2011-08-20 02:17:49 +0000 | [diff] [blame] | 348 | const RegisterID value = regT0; |
fpizlo@apple.com | 4043e81 | 2011-11-06 11:54:59 +0000 | [diff] [blame] | 349 | #if USE(JSVALUE32_64) |
| 350 | const RegisterID valueTag = regT1; |
| 351 | #endif |
fpizlo@apple.com | 95a9f0d | 2011-08-20 02:17:49 +0000 | [diff] [blame] | 352 | const RegisterID scratch = regT3; |
| 353 | |
fpizlo@apple.com | 4043e81 | 2011-11-06 11:54:59 +0000 | [diff] [blame] | 354 | if (ValueProfile::numberOfBuckets == 1) { |
| 355 | // We're in a simple configuration: only one bucket, so we can just do a direct |
| 356 | // store. |
| 357 | #if USE(JSVALUE64) |
yuqiang.xian@intel.com | 5b1cb73 | 2012-10-19 05:46:10 +0000 | [diff] [blame] | 358 | store64(value, valueProfile->m_buckets); |
fpizlo@apple.com | 4043e81 | 2011-11-06 11:54:59 +0000 | [diff] [blame] | 359 | #else |
| 360 | EncodedValueDescriptor* descriptor = bitwise_cast<EncodedValueDescriptor*>(valueProfile->m_buckets); |
| 361 | store32(value, &descriptor->asBits.payload); |
| 362 | store32(valueTag, &descriptor->asBits.tag); |
| 363 | #endif |
| 364 | return; |
| 365 | } |
| 366 | |
fpizlo@apple.com | 95a9f0d | 2011-08-20 02:17:49 +0000 | [diff] [blame] | 367 | if (m_randomGenerator.getUint32() & 1) |
oliver@apple.com | d5c4868 | 2012-03-06 02:40:05 +0000 | [diff] [blame] | 368 | add32(TrustedImm32(1), bucketCounterRegister); |
fpizlo@apple.com | 95a9f0d | 2011-08-20 02:17:49 +0000 | [diff] [blame] | 369 | else |
oliver@apple.com | b2a14ec | 2012-03-08 01:07:34 +0000 | [diff] [blame] | 370 | add32(TrustedImm32(3), bucketCounterRegister); |
| 371 | and32(TrustedImm32(ValueProfile::bucketIndexMask), bucketCounterRegister); |
| 372 | move(TrustedImmPtr(valueProfile->m_buckets), scratch); |
commit-queue@webkit.org | 387d2ec | 2011-10-09 10:19:23 +0000 | [diff] [blame] | 373 | #if USE(JSVALUE64) |
yuqiang.xian@intel.com | 5b1cb73 | 2012-10-19 05:46:10 +0000 | [diff] [blame] | 374 | store64(value, BaseIndex(scratch, bucketCounterRegister, TimesEight)); |
commit-queue@webkit.org | 387d2ec | 2011-10-09 10:19:23 +0000 | [diff] [blame] | 375 | #elif USE(JSVALUE32_64) |
commit-queue@webkit.org | 387d2ec | 2011-10-09 10:19:23 +0000 | [diff] [blame] | 376 | store32(value, BaseIndex(scratch, bucketCounterRegister, TimesEight, OBJECT_OFFSETOF(JSValue, u.asBits.payload))); |
| 377 | store32(valueTag, BaseIndex(scratch, bucketCounterRegister, TimesEight, OBJECT_OFFSETOF(JSValue, u.asBits.tag))); |
| 378 | #endif |
fpizlo@apple.com | 95a9f0d | 2011-08-20 02:17:49 +0000 | [diff] [blame] | 379 | } |
fpizlo@apple.com | 086d2af | 2011-12-21 02:29:15 +0000 | [diff] [blame] | 380 | |
fpizlo@apple.com | afcf904 | 2012-01-20 20:22:18 +0000 | [diff] [blame] | 381 | inline void JIT::emitValueProfilingSite(unsigned bytecodeOffset) |
fpizlo@apple.com | 086d2af | 2011-12-21 02:29:15 +0000 | [diff] [blame] | 382 | { |
| 383 | if (!shouldEmitProfiling()) |
| 384 | return; |
fpizlo@apple.com | afcf904 | 2012-01-20 20:22:18 +0000 | [diff] [blame] | 385 | emitValueProfilingSite(m_codeBlock->valueProfileForBytecodeOffset(bytecodeOffset)); |
| 386 | } |
| 387 | |
| 388 | inline void JIT::emitValueProfilingSite() |
| 389 | { |
| 390 | emitValueProfilingSite(m_bytecodeOffset); |
fpizlo@apple.com | 086d2af | 2011-12-21 02:29:15 +0000 | [diff] [blame] | 391 | } |
fpizlo@apple.com | c7be5be0 | 2012-09-17 19:07:32 +0000 | [diff] [blame] | 392 | #endif // ENABLE(VALUE_PROFILER) |
| 393 | |
| 394 | inline void JIT::emitArrayProfilingSite(RegisterID structureAndIndexingType, RegisterID scratch, ArrayProfile* arrayProfile) |
| 395 | { |
fpizlo@apple.com | 44e9ef4 | 2012-10-19 07:24:32 +0000 | [diff] [blame] | 396 | UNUSED_PARAM(scratch); // We had found this scratch register useful here before, so I will keep it for now. |
| 397 | |
fpizlo@apple.com | c7be5be0 | 2012-09-17 19:07:32 +0000 | [diff] [blame] | 398 | RegisterID structure = structureAndIndexingType; |
| 399 | RegisterID indexingType = structureAndIndexingType; |
| 400 | |
fpizlo@apple.com | 44e9ef4 | 2012-10-19 07:24:32 +0000 | [diff] [blame] | 401 | if (canBeOptimized()) |
fpizlo@apple.com | c7be5be0 | 2012-09-17 19:07:32 +0000 | [diff] [blame] | 402 | storePtr(structure, arrayProfile->addressOfLastSeenStructure()); |
fpizlo@apple.com | 44e9ef4 | 2012-10-19 07:24:32 +0000 | [diff] [blame] | 403 | |
| 404 | load8(Address(structure, Structure::indexingTypeOffset()), indexingType); |
fpizlo@apple.com | c7be5be0 | 2012-09-17 19:07:32 +0000 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | inline void JIT::emitArrayProfilingSiteForBytecodeIndex(RegisterID structureAndIndexingType, RegisterID scratch, unsigned bytecodeIndex) |
| 408 | { |
| 409 | #if ENABLE(VALUE_PROFILER) |
| 410 | emitArrayProfilingSite(structureAndIndexingType, scratch, m_codeBlock->getOrAddArrayProfile(bytecodeIndex)); |
| 411 | #else |
barraclough@apple.com | b46d57b4 | 2012-09-22 00:43:03 +0000 | [diff] [blame] | 412 | UNUSED_PARAM(bytecodeIndex); |
fpizlo@apple.com | c7be5be0 | 2012-09-17 19:07:32 +0000 | [diff] [blame] | 413 | emitArrayProfilingSite(structureAndIndexingType, scratch, 0); |
fpizlo@apple.com | 95a9f0d | 2011-08-20 02:17:49 +0000 | [diff] [blame] | 414 | #endif |
fpizlo@apple.com | c7be5be0 | 2012-09-17 19:07:32 +0000 | [diff] [blame] | 415 | } |
fpizlo@apple.com | 95a9f0d | 2011-08-20 02:17:49 +0000 | [diff] [blame] | 416 | |
fpizlo@apple.com | 69e2784 | 2012-09-19 21:43:10 +0000 | [diff] [blame] | 417 | inline void JIT::emitArrayProfileStoreToHoleSpecialCase(ArrayProfile* arrayProfile) |
| 418 | { |
fpizlo@apple.com | 0e9910a | 2012-10-09 23:39:53 +0000 | [diff] [blame] | 419 | #if ENABLE(VALUE_PROFILER) |
fpizlo@apple.com | 69e2784 | 2012-09-19 21:43:10 +0000 | [diff] [blame] | 420 | store8(TrustedImm32(1), arrayProfile->addressOfMayStoreToHole()); |
fpizlo@apple.com | c14c8d3 | 2012-10-10 02:14:42 +0000 | [diff] [blame] | 421 | #else |
| 422 | UNUSED_PARAM(arrayProfile); |
fpizlo@apple.com | 0e9910a | 2012-10-09 23:39:53 +0000 | [diff] [blame] | 423 | #endif |
| 424 | } |
| 425 | |
fpizlo@apple.com | 304fbca | 2012-12-17 21:38:51 +0000 | [diff] [blame] | 426 | inline void JIT::emitArrayProfileOutOfBoundsSpecialCase(ArrayProfile* arrayProfile) |
| 427 | { |
| 428 | #if ENABLE(VALUE_PROFILER) |
| 429 | store8(TrustedImm32(1), arrayProfile->addressOfOutOfBounds()); |
| 430 | #else |
| 431 | UNUSED_PARAM(arrayProfile); |
| 432 | #endif |
| 433 | } |
| 434 | |
fpizlo@apple.com | 75c91a7 | 2012-11-08 22:28:25 +0000 | [diff] [blame] | 435 | static inline bool arrayProfileSaw(ArrayModes arrayModes, IndexingType capability) |
fpizlo@apple.com | 0e9910a | 2012-10-09 23:39:53 +0000 | [diff] [blame] | 436 | { |
| 437 | #if ENABLE(VALUE_PROFILER) |
fpizlo@apple.com | 75c91a7 | 2012-11-08 22:28:25 +0000 | [diff] [blame] | 438 | return arrayModesInclude(arrayModes, capability); |
fpizlo@apple.com | 0e9910a | 2012-10-09 23:39:53 +0000 | [diff] [blame] | 439 | #else |
fpizlo@apple.com | 75c91a7 | 2012-11-08 22:28:25 +0000 | [diff] [blame] | 440 | UNUSED_PARAM(arrayModes); |
fpizlo@apple.com | c14c8d3 | 2012-10-10 02:14:42 +0000 | [diff] [blame] | 441 | UNUSED_PARAM(capability); |
fpizlo@apple.com | 0e9910a | 2012-10-09 23:39:53 +0000 | [diff] [blame] | 442 | return false; |
| 443 | #endif |
| 444 | } |
| 445 | |
| 446 | inline JITArrayMode JIT::chooseArrayMode(ArrayProfile* profile) |
| 447 | { |
fpizlo@apple.com | af0bea78 | 2012-11-09 01:38:12 +0000 | [diff] [blame] | 448 | #if ENABLE(VALUE_PROFILER) |
fpizlo@apple.com | 75c91a7 | 2012-11-08 22:28:25 +0000 | [diff] [blame] | 449 | profile->computeUpdatedPrediction(m_codeBlock); |
| 450 | ArrayModes arrayModes = profile->observedArrayModes(); |
| 451 | if (arrayProfileSaw(arrayModes, DoubleShape)) |
| 452 | return JITDouble; |
| 453 | if (arrayProfileSaw(arrayModes, Int32Shape)) |
| 454 | return JITInt32; |
| 455 | if (arrayProfileSaw(arrayModes, ArrayStorageShape)) |
fpizlo@apple.com | 0e9910a | 2012-10-09 23:39:53 +0000 | [diff] [blame] | 456 | return JITArrayStorage; |
| 457 | return JITContiguous; |
fpizlo@apple.com | af0bea78 | 2012-11-09 01:38:12 +0000 | [diff] [blame] | 458 | #else |
| 459 | UNUSED_PARAM(profile); |
| 460 | return JITContiguous; |
| 461 | #endif |
fpizlo@apple.com | 69e2784 | 2012-09-19 21:43:10 +0000 | [diff] [blame] | 462 | } |
| 463 | |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 464 | #if USE(JSVALUE32_64) |
| 465 | |
ggaren@apple.com | e1e4591 | 2011-11-14 19:44:32 +0000 | [diff] [blame] | 466 | inline void JIT::emitLoadTag(int index, RegisterID tag) |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 467 | { |
| 468 | RegisterID mappedTag; |
| 469 | if (getMappedTag(index, mappedTag)) { |
| 470 | move(mappedTag, tag); |
| 471 | unmap(tag); |
| 472 | return; |
| 473 | } |
| 474 | |
| 475 | if (m_codeBlock->isConstantRegisterIndex(index)) { |
| 476 | move(Imm32(getConstantOperand(index).tag()), tag); |
| 477 | unmap(tag); |
| 478 | return; |
| 479 | } |
| 480 | |
| 481 | load32(tagFor(index), tag); |
| 482 | unmap(tag); |
| 483 | } |
| 484 | |
ggaren@apple.com | e1e4591 | 2011-11-14 19:44:32 +0000 | [diff] [blame] | 485 | inline void JIT::emitLoadPayload(int index, RegisterID payload) |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 486 | { |
| 487 | RegisterID mappedPayload; |
| 488 | if (getMappedPayload(index, mappedPayload)) { |
| 489 | move(mappedPayload, payload); |
| 490 | unmap(payload); |
| 491 | return; |
| 492 | } |
| 493 | |
| 494 | if (m_codeBlock->isConstantRegisterIndex(index)) { |
| 495 | move(Imm32(getConstantOperand(index).payload()), payload); |
| 496 | unmap(payload); |
| 497 | return; |
| 498 | } |
| 499 | |
| 500 | load32(payloadFor(index), payload); |
| 501 | unmap(payload); |
| 502 | } |
| 503 | |
| 504 | inline void JIT::emitLoad(const JSValue& v, RegisterID tag, RegisterID payload) |
| 505 | { |
| 506 | move(Imm32(v.payload()), payload); |
| 507 | move(Imm32(v.tag()), tag); |
| 508 | } |
| 509 | |
ggaren@apple.com | e1e4591 | 2011-11-14 19:44:32 +0000 | [diff] [blame] | 510 | inline void JIT::emitLoad(int index, RegisterID tag, RegisterID payload, RegisterID base) |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 511 | { |
oliver@apple.com | 903b0c0 | 2013-01-24 01:40:37 +0000 | [diff] [blame] | 512 | RELEASE_ASSERT(tag != payload); |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 513 | |
| 514 | if (base == callFrameRegister) { |
oliver@apple.com | 903b0c0 | 2013-01-24 01:40:37 +0000 | [diff] [blame] | 515 | RELEASE_ASSERT(payload != base); |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 516 | emitLoadPayload(index, payload); |
| 517 | emitLoadTag(index, tag); |
| 518 | return; |
| 519 | } |
| 520 | |
| 521 | if (payload == base) { // avoid stomping base |
| 522 | load32(tagFor(index, base), tag); |
| 523 | load32(payloadFor(index, base), payload); |
| 524 | return; |
| 525 | } |
| 526 | |
| 527 | load32(payloadFor(index, base), payload); |
| 528 | load32(tagFor(index, base), tag); |
| 529 | } |
| 530 | |
ggaren@apple.com | e1e4591 | 2011-11-14 19:44:32 +0000 | [diff] [blame] | 531 | inline void JIT::emitLoad2(int index1, RegisterID tag1, RegisterID payload1, int index2, RegisterID tag2, RegisterID payload2) |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 532 | { |
| 533 | if (isMapped(index1)) { |
| 534 | emitLoad(index1, tag1, payload1); |
| 535 | emitLoad(index2, tag2, payload2); |
| 536 | return; |
| 537 | } |
| 538 | emitLoad(index2, tag2, payload2); |
| 539 | emitLoad(index1, tag1, payload1); |
| 540 | } |
| 541 | |
ggaren@apple.com | e1e4591 | 2011-11-14 19:44:32 +0000 | [diff] [blame] | 542 | inline void JIT::emitLoadDouble(int index, FPRegisterID value) |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 543 | { |
| 544 | if (m_codeBlock->isConstantRegisterIndex(index)) { |
oliver@apple.com | ba10bec | 2011-03-08 23:17:32 +0000 | [diff] [blame] | 545 | WriteBarrier<Unknown>& inConstantPool = m_codeBlock->constantRegister(index); |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 546 | loadDouble(&inConstantPool, value); |
| 547 | } else |
| 548 | loadDouble(addressFor(index), value); |
| 549 | } |
| 550 | |
ggaren@apple.com | e1e4591 | 2011-11-14 19:44:32 +0000 | [diff] [blame] | 551 | inline void JIT::emitLoadInt32ToDouble(int index, FPRegisterID value) |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 552 | { |
| 553 | if (m_codeBlock->isConstantRegisterIndex(index)) { |
oliver@apple.com | ba10bec | 2011-03-08 23:17:32 +0000 | [diff] [blame] | 554 | WriteBarrier<Unknown>& inConstantPool = m_codeBlock->constantRegister(index); |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 555 | char* bytePointer = reinterpret_cast<char*>(&inConstantPool); |
| 556 | convertInt32ToDouble(AbsoluteAddress(bytePointer + OBJECT_OFFSETOF(JSValue, u.asBits.payload)), value); |
| 557 | } else |
| 558 | convertInt32ToDouble(payloadFor(index), value); |
| 559 | } |
| 560 | |
ggaren@apple.com | e1e4591 | 2011-11-14 19:44:32 +0000 | [diff] [blame] | 561 | inline void JIT::emitStore(int index, RegisterID tag, RegisterID payload, RegisterID base) |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 562 | { |
| 563 | store32(payload, payloadFor(index, base)); |
| 564 | store32(tag, tagFor(index, base)); |
| 565 | } |
| 566 | |
ggaren@apple.com | e1e4591 | 2011-11-14 19:44:32 +0000 | [diff] [blame] | 567 | inline void JIT::emitStoreInt32(int index, RegisterID payload, bool indexIsInt32) |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 568 | { |
| 569 | store32(payload, payloadFor(index, callFrameRegister)); |
| 570 | if (!indexIsInt32) |
oliver@apple.com | be4e067 | 2011-03-28 17:14:57 +0000 | [diff] [blame] | 571 | store32(TrustedImm32(JSValue::Int32Tag), tagFor(index, callFrameRegister)); |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 572 | } |
| 573 | |
ggaren@apple.com | e1e4591 | 2011-11-14 19:44:32 +0000 | [diff] [blame] | 574 | inline void JIT::emitStoreAndMapInt32(int index, RegisterID tag, RegisterID payload, bool indexIsInt32, size_t opcodeLength) |
ggaren@apple.com | 2585308 | 2011-09-16 21:05:09 +0000 | [diff] [blame] | 575 | { |
| 576 | emitStoreInt32(index, payload, indexIsInt32); |
| 577 | map(m_bytecodeOffset + opcodeLength, index, tag, payload); |
| 578 | } |
| 579 | |
ggaren@apple.com | e1e4591 | 2011-11-14 19:44:32 +0000 | [diff] [blame] | 580 | inline void JIT::emitStoreInt32(int index, TrustedImm32 payload, bool indexIsInt32) |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 581 | { |
| 582 | store32(payload, payloadFor(index, callFrameRegister)); |
| 583 | if (!indexIsInt32) |
oliver@apple.com | be4e067 | 2011-03-28 17:14:57 +0000 | [diff] [blame] | 584 | store32(TrustedImm32(JSValue::Int32Tag), tagFor(index, callFrameRegister)); |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 585 | } |
| 586 | |
ggaren@apple.com | e1e4591 | 2011-11-14 19:44:32 +0000 | [diff] [blame] | 587 | inline void JIT::emitStoreCell(int index, RegisterID payload, bool indexIsCell) |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 588 | { |
| 589 | store32(payload, payloadFor(index, callFrameRegister)); |
| 590 | if (!indexIsCell) |
oliver@apple.com | be4e067 | 2011-03-28 17:14:57 +0000 | [diff] [blame] | 591 | store32(TrustedImm32(JSValue::CellTag), tagFor(index, callFrameRegister)); |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 592 | } |
| 593 | |
ggaren@apple.com | e1e4591 | 2011-11-14 19:44:32 +0000 | [diff] [blame] | 594 | inline void JIT::emitStoreBool(int index, RegisterID payload, bool indexIsBool) |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 595 | { |
barraclough@apple.com | 5139edc | 2011-04-07 23:47:06 +0000 | [diff] [blame] | 596 | store32(payload, payloadFor(index, callFrameRegister)); |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 597 | if (!indexIsBool) |
barraclough@apple.com | 5139edc | 2011-04-07 23:47:06 +0000 | [diff] [blame] | 598 | store32(TrustedImm32(JSValue::BooleanTag), tagFor(index, callFrameRegister)); |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 599 | } |
| 600 | |
ggaren@apple.com | e1e4591 | 2011-11-14 19:44:32 +0000 | [diff] [blame] | 601 | inline void JIT::emitStoreDouble(int index, FPRegisterID value) |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 602 | { |
| 603 | storeDouble(value, addressFor(index)); |
| 604 | } |
| 605 | |
ggaren@apple.com | e1e4591 | 2011-11-14 19:44:32 +0000 | [diff] [blame] | 606 | inline void JIT::emitStore(int index, const JSValue constant, RegisterID base) |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 607 | { |
| 608 | store32(Imm32(constant.payload()), payloadFor(index, base)); |
| 609 | store32(Imm32(constant.tag()), tagFor(index, base)); |
| 610 | } |
| 611 | |
| 612 | ALWAYS_INLINE void JIT::emitInitRegister(unsigned dst) |
| 613 | { |
| 614 | emitStore(dst, jsUndefined()); |
| 615 | } |
| 616 | |
ggaren@apple.com | 1ba4981 | 2010-05-19 18:28:54 +0000 | [diff] [blame] | 617 | inline bool JIT::isLabeled(unsigned bytecodeOffset) |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 618 | { |
| 619 | for (size_t numberOfJumpTargets = m_codeBlock->numberOfJumpTargets(); m_jumpTargetIndex != numberOfJumpTargets; ++m_jumpTargetIndex) { |
| 620 | unsigned jumpTarget = m_codeBlock->jumpTarget(m_jumpTargetIndex); |
ggaren@apple.com | 1ba4981 | 2010-05-19 18:28:54 +0000 | [diff] [blame] | 621 | if (jumpTarget == bytecodeOffset) |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 622 | return true; |
ggaren@apple.com | 1ba4981 | 2010-05-19 18:28:54 +0000 | [diff] [blame] | 623 | if (jumpTarget > bytecodeOffset) |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 624 | return false; |
| 625 | } |
| 626 | return false; |
| 627 | } |
| 628 | |
ggaren@apple.com | e1e4591 | 2011-11-14 19:44:32 +0000 | [diff] [blame] | 629 | inline void JIT::map(unsigned bytecodeOffset, int virtualRegisterIndex, RegisterID tag, RegisterID payload) |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 630 | { |
ggaren@apple.com | 1ba4981 | 2010-05-19 18:28:54 +0000 | [diff] [blame] | 631 | if (isLabeled(bytecodeOffset)) |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 632 | return; |
| 633 | |
ggaren@apple.com | 1ba4981 | 2010-05-19 18:28:54 +0000 | [diff] [blame] | 634 | m_mappedBytecodeOffset = bytecodeOffset; |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 635 | m_mappedVirtualRegisterIndex = virtualRegisterIndex; |
| 636 | m_mappedTag = tag; |
| 637 | m_mappedPayload = payload; |
fpizlo@apple.com | 7546157 | 2012-02-12 01:24:49 +0000 | [diff] [blame] | 638 | |
| 639 | ASSERT(!canBeOptimized() || m_mappedPayload == regT0); |
| 640 | ASSERT(!canBeOptimized() || m_mappedTag == regT1); |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | inline void JIT::unmap(RegisterID registerID) |
| 644 | { |
| 645 | if (m_mappedTag == registerID) |
| 646 | m_mappedTag = (RegisterID)-1; |
| 647 | else if (m_mappedPayload == registerID) |
| 648 | m_mappedPayload = (RegisterID)-1; |
| 649 | } |
| 650 | |
| 651 | inline void JIT::unmap() |
| 652 | { |
ggaren@apple.com | 1ba4981 | 2010-05-19 18:28:54 +0000 | [diff] [blame] | 653 | m_mappedBytecodeOffset = (unsigned)-1; |
mark.lam@apple.com | 4fbb9c3 | 2012-10-09 07:12:56 +0000 | [diff] [blame] | 654 | m_mappedVirtualRegisterIndex = JSStack::ReturnPC; |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 655 | m_mappedTag = (RegisterID)-1; |
| 656 | m_mappedPayload = (RegisterID)-1; |
| 657 | } |
| 658 | |
ggaren@apple.com | e1e4591 | 2011-11-14 19:44:32 +0000 | [diff] [blame] | 659 | inline bool JIT::isMapped(int virtualRegisterIndex) |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 660 | { |
ggaren@apple.com | 1ba4981 | 2010-05-19 18:28:54 +0000 | [diff] [blame] | 661 | if (m_mappedBytecodeOffset != m_bytecodeOffset) |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 662 | return false; |
| 663 | if (m_mappedVirtualRegisterIndex != virtualRegisterIndex) |
| 664 | return false; |
| 665 | return true; |
| 666 | } |
| 667 | |
ggaren@apple.com | e1e4591 | 2011-11-14 19:44:32 +0000 | [diff] [blame] | 668 | inline bool JIT::getMappedPayload(int virtualRegisterIndex, RegisterID& payload) |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 669 | { |
ggaren@apple.com | 1ba4981 | 2010-05-19 18:28:54 +0000 | [diff] [blame] | 670 | if (m_mappedBytecodeOffset != m_bytecodeOffset) |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 671 | return false; |
| 672 | if (m_mappedVirtualRegisterIndex != virtualRegisterIndex) |
| 673 | return false; |
| 674 | if (m_mappedPayload == (RegisterID)-1) |
| 675 | return false; |
| 676 | payload = m_mappedPayload; |
| 677 | return true; |
| 678 | } |
| 679 | |
ggaren@apple.com | e1e4591 | 2011-11-14 19:44:32 +0000 | [diff] [blame] | 680 | inline bool JIT::getMappedTag(int virtualRegisterIndex, RegisterID& tag) |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 681 | { |
ggaren@apple.com | 1ba4981 | 2010-05-19 18:28:54 +0000 | [diff] [blame] | 682 | if (m_mappedBytecodeOffset != m_bytecodeOffset) |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 683 | return false; |
| 684 | if (m_mappedVirtualRegisterIndex != virtualRegisterIndex) |
| 685 | return false; |
| 686 | if (m_mappedTag == (RegisterID)-1) |
| 687 | return false; |
| 688 | tag = m_mappedTag; |
| 689 | return true; |
| 690 | } |
| 691 | |
ggaren@apple.com | e1e4591 | 2011-11-14 19:44:32 +0000 | [diff] [blame] | 692 | inline void JIT::emitJumpSlowCaseIfNotJSCell(int virtualRegisterIndex) |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 693 | { |
oliver@apple.com | fc502ee | 2010-05-20 00:30:35 +0000 | [diff] [blame] | 694 | if (!m_codeBlock->isKnownNotImmediate(virtualRegisterIndex)) { |
| 695 | if (m_codeBlock->isConstantRegisterIndex(virtualRegisterIndex)) |
| 696 | addSlowCase(jump()); |
| 697 | else |
| 698 | addSlowCase(emitJumpIfNotJSCell(virtualRegisterIndex)); |
| 699 | } |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 700 | } |
| 701 | |
ggaren@apple.com | e1e4591 | 2011-11-14 19:44:32 +0000 | [diff] [blame] | 702 | inline void JIT::emitJumpSlowCaseIfNotJSCell(int virtualRegisterIndex, RegisterID tag) |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 703 | { |
oliver@apple.com | fc502ee | 2010-05-20 00:30:35 +0000 | [diff] [blame] | 704 | if (!m_codeBlock->isKnownNotImmediate(virtualRegisterIndex)) { |
| 705 | if (m_codeBlock->isConstantRegisterIndex(virtualRegisterIndex)) |
| 706 | addSlowCase(jump()); |
| 707 | else |
oliver@apple.com | be4e067 | 2011-03-28 17:14:57 +0000 | [diff] [blame] | 708 | addSlowCase(branch32(NotEqual, tag, TrustedImm32(JSValue::CellTag))); |
oliver@apple.com | fc502ee | 2010-05-20 00:30:35 +0000 | [diff] [blame] | 709 | } |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 710 | } |
| 711 | |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 712 | ALWAYS_INLINE bool JIT::isOperandConstantImmediateInt(unsigned src) |
| 713 | { |
| 714 | return m_codeBlock->isConstantRegisterIndex(src) && getConstantOperand(src).isInt32(); |
| 715 | } |
| 716 | |
| 717 | ALWAYS_INLINE bool JIT::getOperandConstantImmediateInt(unsigned op1, unsigned op2, unsigned& op, int32_t& constant) |
| 718 | { |
| 719 | if (isOperandConstantImmediateInt(op1)) { |
| 720 | constant = getConstantOperand(op1).asInt32(); |
| 721 | op = op2; |
| 722 | return true; |
| 723 | } |
| 724 | |
| 725 | if (isOperandConstantImmediateInt(op2)) { |
| 726 | constant = getConstantOperand(op2).asInt32(); |
| 727 | op = op1; |
| 728 | return true; |
| 729 | } |
| 730 | |
| 731 | return false; |
| 732 | } |
| 733 | |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 734 | #else // USE(JSVALUE32_64) |
| 735 | |
yuqiang.xian@intel.com | 5b1cb73 | 2012-10-19 05:46:10 +0000 | [diff] [blame] | 736 | /* Deprecated: Please use JITStubCall instead. */ |
| 737 | |
| 738 | ALWAYS_INLINE void JIT::emitGetJITStubArg(unsigned argumentNumber, RegisterID dst) |
| 739 | { |
| 740 | unsigned argumentStackOffset = (argumentNumber * (sizeof(JSValue) / sizeof(void*))) + JITSTACKFRAME_ARGS_INDEX; |
| 741 | peek64(dst, argumentStackOffset); |
| 742 | } |
| 743 | |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 744 | ALWAYS_INLINE void JIT::killLastResultRegister() |
| 745 | { |
| 746 | m_lastResultBytecodeRegister = std::numeric_limits<int>::max(); |
| 747 | } |
| 748 | |
| 749 | // get arg puts an arg from the SF register array into a h/w register |
| 750 | ALWAYS_INLINE void JIT::emitGetVirtualRegister(int src, RegisterID dst) |
| 751 | { |
ggaren@apple.com | 1ba4981 | 2010-05-19 18:28:54 +0000 | [diff] [blame] | 752 | ASSERT(m_bytecodeOffset != (unsigned)-1); // This method should only be called during hot/cold path generation, so that m_bytecodeOffset is set. |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 753 | |
| 754 | // TODO: we want to reuse values that are already in registers if we can - add a register allocator! |
| 755 | if (m_codeBlock->isConstantRegisterIndex(src)) { |
| 756 | JSValue value = m_codeBlock->getConstant(src); |
oliver@apple.com | b2a14ec | 2012-03-08 01:07:34 +0000 | [diff] [blame] | 757 | if (!value.isNumber()) |
yuqiang.xian@intel.com | 5b1cb73 | 2012-10-19 05:46:10 +0000 | [diff] [blame] | 758 | move(TrustedImm64(JSValue::encode(value)), dst); |
oliver@apple.com | b2a14ec | 2012-03-08 01:07:34 +0000 | [diff] [blame] | 759 | else |
yuqiang.xian@intel.com | 5b1cb73 | 2012-10-19 05:46:10 +0000 | [diff] [blame] | 760 | move(Imm64(JSValue::encode(value)), dst); |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 761 | killLastResultRegister(); |
| 762 | return; |
| 763 | } |
| 764 | |
barraclough@apple.com | 4836c7a | 2011-05-01 22:20:59 +0000 | [diff] [blame] | 765 | if (src == m_lastResultBytecodeRegister && m_codeBlock->isTemporaryRegisterIndex(src) && !atJumpTarget()) { |
| 766 | // The argument we want is already stored in eax |
| 767 | if (dst != cachedResultRegister) |
| 768 | move(cachedResultRegister, dst); |
| 769 | killLastResultRegister(); |
| 770 | return; |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 771 | } |
| 772 | |
yuqiang.xian@intel.com | 5b1cb73 | 2012-10-19 05:46:10 +0000 | [diff] [blame] | 773 | load64(Address(callFrameRegister, src * sizeof(Register)), dst); |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 774 | killLastResultRegister(); |
| 775 | } |
| 776 | |
| 777 | ALWAYS_INLINE void JIT::emitGetVirtualRegisters(int src1, RegisterID dst1, int src2, RegisterID dst2) |
| 778 | { |
| 779 | if (src2 == m_lastResultBytecodeRegister) { |
| 780 | emitGetVirtualRegister(src2, dst2); |
| 781 | emitGetVirtualRegister(src1, dst1); |
| 782 | } else { |
| 783 | emitGetVirtualRegister(src1, dst1); |
| 784 | emitGetVirtualRegister(src2, dst2); |
| 785 | } |
| 786 | } |
| 787 | |
| 788 | ALWAYS_INLINE int32_t JIT::getConstantOperandImmediateInt(unsigned src) |
| 789 | { |
| 790 | return getConstantOperand(src).asInt32(); |
| 791 | } |
| 792 | |
| 793 | ALWAYS_INLINE bool JIT::isOperandConstantImmediateInt(unsigned src) |
| 794 | { |
| 795 | return m_codeBlock->isConstantRegisterIndex(src) && getConstantOperand(src).isInt32(); |
| 796 | } |
| 797 | |
| 798 | ALWAYS_INLINE void JIT::emitPutVirtualRegister(unsigned dst, RegisterID from) |
| 799 | { |
yuqiang.xian@intel.com | 5b1cb73 | 2012-10-19 05:46:10 +0000 | [diff] [blame] | 800 | store64(from, Address(callFrameRegister, dst * sizeof(Register))); |
andersca@apple.com | d11d25d | 2010-06-15 18:52:31 +0000 | [diff] [blame] | 801 | m_lastResultBytecodeRegister = (from == cachedResultRegister) ? static_cast<int>(dst) : std::numeric_limits<int>::max(); |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 802 | } |
| 803 | |
| 804 | ALWAYS_INLINE void JIT::emitInitRegister(unsigned dst) |
| 805 | { |
yuqiang.xian@intel.com | 5b1cb73 | 2012-10-19 05:46:10 +0000 | [diff] [blame] | 806 | store64(TrustedImm64(JSValue::encode(jsUndefined())), Address(callFrameRegister, dst * sizeof(Register))); |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 807 | } |
| 808 | |
| 809 | ALWAYS_INLINE JIT::Jump JIT::emitJumpIfJSCell(RegisterID reg) |
| 810 | { |
yuqiang.xian@intel.com | 5b1cb73 | 2012-10-19 05:46:10 +0000 | [diff] [blame] | 811 | return branchTest64(Zero, reg, tagMaskRegister); |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 812 | } |
| 813 | |
| 814 | ALWAYS_INLINE JIT::Jump JIT::emitJumpIfBothJSCells(RegisterID reg1, RegisterID reg2, RegisterID scratch) |
| 815 | { |
| 816 | move(reg1, scratch); |
yuqiang.xian@intel.com | 5b1cb73 | 2012-10-19 05:46:10 +0000 | [diff] [blame] | 817 | or64(reg2, scratch); |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 818 | return emitJumpIfJSCell(scratch); |
| 819 | } |
| 820 | |
| 821 | ALWAYS_INLINE void JIT::emitJumpSlowCaseIfJSCell(RegisterID reg) |
| 822 | { |
| 823 | addSlowCase(emitJumpIfJSCell(reg)); |
| 824 | } |
| 825 | |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 826 | ALWAYS_INLINE void JIT::emitJumpSlowCaseIfNotJSCell(RegisterID reg) |
| 827 | { |
| 828 | addSlowCase(emitJumpIfNotJSCell(reg)); |
| 829 | } |
| 830 | |
| 831 | ALWAYS_INLINE void JIT::emitJumpSlowCaseIfNotJSCell(RegisterID reg, int vReg) |
| 832 | { |
| 833 | if (!m_codeBlock->isKnownNotImmediate(vReg)) |
| 834 | emitJumpSlowCaseIfNotJSCell(reg); |
| 835 | } |
| 836 | |
ggaren@apple.com | e1e4591 | 2011-11-14 19:44:32 +0000 | [diff] [blame] | 837 | inline void JIT::emitLoadDouble(int index, FPRegisterID value) |
oliver@apple.com | 8d18163 | 2009-09-25 02:40:59 +0000 | [diff] [blame] | 838 | { |
| 839 | if (m_codeBlock->isConstantRegisterIndex(index)) { |
oliver@apple.com | ba10bec | 2011-03-08 23:17:32 +0000 | [diff] [blame] | 840 | WriteBarrier<Unknown>& inConstantPool = m_codeBlock->constantRegister(index); |
oliver@apple.com | 8d18163 | 2009-09-25 02:40:59 +0000 | [diff] [blame] | 841 | loadDouble(&inConstantPool, value); |
| 842 | } else |
| 843 | loadDouble(addressFor(index), value); |
| 844 | } |
| 845 | |
ggaren@apple.com | e1e4591 | 2011-11-14 19:44:32 +0000 | [diff] [blame] | 846 | inline void JIT::emitLoadInt32ToDouble(int index, FPRegisterID value) |
oliver@apple.com | 8d18163 | 2009-09-25 02:40:59 +0000 | [diff] [blame] | 847 | { |
| 848 | if (m_codeBlock->isConstantRegisterIndex(index)) { |
barraclough@apple.com | 8af7a53 | 2011-03-13 22:11:13 +0000 | [diff] [blame] | 849 | ASSERT(isOperandConstantImmediateInt(index)); |
| 850 | convertInt32ToDouble(Imm32(getConstantOperand(index).asInt32()), value); |
oliver@apple.com | 8d18163 | 2009-09-25 02:40:59 +0000 | [diff] [blame] | 851 | } else |
| 852 | convertInt32ToDouble(addressFor(index), value); |
| 853 | } |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 854 | |
| 855 | ALWAYS_INLINE JIT::Jump JIT::emitJumpIfImmediateInteger(RegisterID reg) |
| 856 | { |
yuqiang.xian@intel.com | 5b1cb73 | 2012-10-19 05:46:10 +0000 | [diff] [blame] | 857 | return branch64(AboveOrEqual, reg, tagTypeNumberRegister); |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | ALWAYS_INLINE JIT::Jump JIT::emitJumpIfNotImmediateInteger(RegisterID reg) |
| 861 | { |
yuqiang.xian@intel.com | 5b1cb73 | 2012-10-19 05:46:10 +0000 | [diff] [blame] | 862 | return branch64(Below, reg, tagTypeNumberRegister); |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 863 | } |
| 864 | |
| 865 | ALWAYS_INLINE JIT::Jump JIT::emitJumpIfNotImmediateIntegers(RegisterID reg1, RegisterID reg2, RegisterID scratch) |
| 866 | { |
| 867 | move(reg1, scratch); |
yuqiang.xian@intel.com | 5b1cb73 | 2012-10-19 05:46:10 +0000 | [diff] [blame] | 868 | and64(reg2, scratch); |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 869 | return emitJumpIfNotImmediateInteger(scratch); |
| 870 | } |
| 871 | |
| 872 | ALWAYS_INLINE void JIT::emitJumpSlowCaseIfNotImmediateInteger(RegisterID reg) |
| 873 | { |
| 874 | addSlowCase(emitJumpIfNotImmediateInteger(reg)); |
| 875 | } |
| 876 | |
| 877 | ALWAYS_INLINE void JIT::emitJumpSlowCaseIfNotImmediateIntegers(RegisterID reg1, RegisterID reg2, RegisterID scratch) |
| 878 | { |
| 879 | addSlowCase(emitJumpIfNotImmediateIntegers(reg1, reg2, scratch)); |
| 880 | } |
| 881 | |
oliver@apple.com | 8d18163 | 2009-09-25 02:40:59 +0000 | [diff] [blame] | 882 | ALWAYS_INLINE void JIT::emitJumpSlowCaseIfNotImmediateNumber(RegisterID reg) |
| 883 | { |
| 884 | addSlowCase(emitJumpIfNotImmediateNumber(reg)); |
| 885 | } |
| 886 | |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 887 | ALWAYS_INLINE void JIT::emitFastArithReTagImmediate(RegisterID src, RegisterID dest) |
| 888 | { |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 889 | emitFastArithIntToImmNoCheck(src, dest); |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 890 | } |
| 891 | |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 892 | ALWAYS_INLINE void JIT::emitTagAsBoolImmediate(RegisterID reg) |
| 893 | { |
barraclough@apple.com | 560dde7 | 2011-04-11 22:18:30 +0000 | [diff] [blame] | 894 | or32(TrustedImm32(static_cast<int32_t>(ValueFalse)), reg); |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 895 | } |
| 896 | |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 897 | #endif // USE(JSVALUE32_64) |
| 898 | |
| 899 | } // namespace JSC |
| 900 | |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 901 | #endif // ENABLE(JIT) |
| 902 | |
mark.lam@apple.com | a4fe7ab | 2012-11-09 03:03:44 +0000 | [diff] [blame] | 903 | #endif // JITInlines_h |
| 904 | |