oliver@apple.com | 8e293b7 | 2010-04-27 04:22:46 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 Apple Inc. All rights reserved. |
| 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. AND ITS CONTRIBUTORS ``AS IS'' |
| 14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
| 17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 23 | * THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
| 26 | #ifndef SpecializedThunkJIT_h |
| 27 | #define SpecializedThunkJIT_h |
| 28 | |
| 29 | #if ENABLE(JIT) |
| 30 | |
| 31 | #include "Executable.h" |
| 32 | #include "JSInterfaceJIT.h" |
| 33 | #include "LinkBuffer.h" |
| 34 | |
| 35 | namespace JSC { |
| 36 | |
| 37 | class SpecializedThunkJIT : public JSInterfaceJIT { |
| 38 | public: |
| 39 | static const int ThisArgument = -1; |
commit-queue@webkit.org | c182dfc | 2012-07-06 17:39:20 +0000 | [diff] [blame] | 40 | SpecializedThunkJIT(int expectedArgCount) |
oliver@apple.com | 8e293b7 | 2010-04-27 04:22:46 +0000 | [diff] [blame] | 41 | { |
| 42 | // Check that we have the expected number of arguments |
fpizlo@apple.com | 265b196 | 2011-12-21 06:01:20 +0000 | [diff] [blame] | 43 | m_failures.append(branch32(NotEqual, payloadFor(RegisterFile::ArgumentCount), TrustedImm32(expectedArgCount + 1))); |
oliver@apple.com | 8e293b7 | 2010-04-27 04:22:46 +0000 | [diff] [blame] | 44 | } |
| 45 | |
oliver@apple.com | 2bd947e | 2010-04-29 03:57:16 +0000 | [diff] [blame] | 46 | void loadDoubleArgument(int argument, FPRegisterID dst, RegisterID scratch) |
| 47 | { |
ggaren@apple.com | 0af1468 | 2011-12-12 00:35:51 +0000 | [diff] [blame] | 48 | unsigned src = CallFrame::argumentOffset(argument); |
oliver@apple.com | 2bd947e | 2010-04-29 03:57:16 +0000 | [diff] [blame] | 49 | m_failures.append(emitLoadDouble(src, dst, scratch)); |
| 50 | } |
| 51 | |
oliver@apple.com | 8e293b7 | 2010-04-27 04:22:46 +0000 | [diff] [blame] | 52 | void loadCellArgument(int argument, RegisterID dst) |
| 53 | { |
ggaren@apple.com | 0af1468 | 2011-12-12 00:35:51 +0000 | [diff] [blame] | 54 | unsigned src = CallFrame::argumentOffset(argument); |
oliver@apple.com | 8e293b7 | 2010-04-27 04:22:46 +0000 | [diff] [blame] | 55 | m_failures.append(emitLoadJSCell(src, dst)); |
| 56 | } |
| 57 | |
| 58 | void loadJSStringArgument(int argument, RegisterID dst) |
| 59 | { |
| 60 | loadCellArgument(argument, dst); |
mhahnenberg@apple.com | c58d54d | 2011-12-16 19:06:44 +0000 | [diff] [blame] | 61 | m_failures.append(branchPtr(NotEqual, Address(dst, JSCell::classInfoOffset()), TrustedImmPtr(&JSString::s_info))); |
oliver@apple.com | 8e293b7 | 2010-04-27 04:22:46 +0000 | [diff] [blame] | 62 | } |
| 63 | |
oliver@apple.com | 2bd947e | 2010-04-29 03:57:16 +0000 | [diff] [blame] | 64 | void loadInt32Argument(int argument, RegisterID dst, Jump& failTarget) |
oliver@apple.com | 8e293b7 | 2010-04-27 04:22:46 +0000 | [diff] [blame] | 65 | { |
ggaren@apple.com | 0af1468 | 2011-12-12 00:35:51 +0000 | [diff] [blame] | 66 | unsigned src = CallFrame::argumentOffset(argument); |
oliver@apple.com | 2bd947e | 2010-04-29 03:57:16 +0000 | [diff] [blame] | 67 | failTarget = emitLoadInt32(src, dst); |
| 68 | } |
| 69 | |
| 70 | void loadInt32Argument(int argument, RegisterID dst) |
| 71 | { |
| 72 | Jump conversionFailed; |
| 73 | loadInt32Argument(argument, dst, conversionFailed); |
| 74 | m_failures.append(conversionFailed); |
oliver@apple.com | 8e293b7 | 2010-04-27 04:22:46 +0000 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | void appendFailure(const Jump& failure) |
| 78 | { |
| 79 | m_failures.append(failure); |
| 80 | } |
oliver@apple.com | 2bd947e | 2010-04-29 03:57:16 +0000 | [diff] [blame] | 81 | |
| 82 | void returnJSValue(RegisterID src) |
| 83 | { |
| 84 | if (src != regT0) |
| 85 | move(src, regT0); |
oliver@apple.com | 9d4f0ec | 2011-03-14 18:16:36 +0000 | [diff] [blame] | 86 | loadPtr(payloadFor(RegisterFile::CallerFrame, callFrameRegister), callFrameRegister); |
oliver@apple.com | 2bd947e | 2010-04-29 03:57:16 +0000 | [diff] [blame] | 87 | ret(); |
| 88 | } |
oliver@apple.com | 8e293b7 | 2010-04-27 04:22:46 +0000 | [diff] [blame] | 89 | |
oliver@apple.com | 2bd947e | 2010-04-29 03:57:16 +0000 | [diff] [blame] | 90 | void returnDouble(FPRegisterID src) |
| 91 | { |
| 92 | #if USE(JSVALUE64) |
| 93 | moveDoubleToPtr(src, regT0); |
fpizlo@apple.com | 51baa63 | 2011-09-04 05:43:47 +0000 | [diff] [blame] | 94 | Jump zero = branchTestPtr(Zero, regT0); |
oliver@apple.com | 2bd947e | 2010-04-29 03:57:16 +0000 | [diff] [blame] | 95 | subPtr(tagTypeNumberRegister, regT0); |
fpizlo@apple.com | 51baa63 | 2011-09-04 05:43:47 +0000 | [diff] [blame] | 96 | Jump done = jump(); |
| 97 | zero.link(this); |
| 98 | move(tagTypeNumberRegister, regT0); |
| 99 | done.link(this); |
oliver@apple.com | 0cc25c3 | 2010-10-19 23:55:08 +0000 | [diff] [blame] | 100 | #else |
oliver@apple.com | 2bd947e | 2010-04-29 03:57:16 +0000 | [diff] [blame] | 101 | storeDouble(src, Address(stackPointerRegister, -(int)sizeof(double))); |
| 102 | loadPtr(Address(stackPointerRegister, OBJECT_OFFSETOF(JSValue, u.asBits.tag) - sizeof(double)), regT1); |
| 103 | loadPtr(Address(stackPointerRegister, OBJECT_OFFSETOF(JSValue, u.asBits.payload) - sizeof(double)), regT0); |
fpizlo@apple.com | 51baa63 | 2011-09-04 05:43:47 +0000 | [diff] [blame] | 104 | Jump lowNonZero = branchTestPtr(NonZero, regT1); |
| 105 | Jump highNonZero = branchTestPtr(NonZero, regT0); |
| 106 | move(TrustedImm32(0), regT0); |
| 107 | move(TrustedImm32(Int32Tag), regT1); |
| 108 | lowNonZero.link(this); |
| 109 | highNonZero.link(this); |
oliver@apple.com | 2bd947e | 2010-04-29 03:57:16 +0000 | [diff] [blame] | 110 | #endif |
oliver@apple.com | 9d4f0ec | 2011-03-14 18:16:36 +0000 | [diff] [blame] | 111 | loadPtr(payloadFor(RegisterFile::CallerFrame, callFrameRegister), callFrameRegister); |
oliver@apple.com | 2bd947e | 2010-04-29 03:57:16 +0000 | [diff] [blame] | 112 | ret(); |
| 113 | } |
| 114 | |
oliver@apple.com | 8e293b7 | 2010-04-27 04:22:46 +0000 | [diff] [blame] | 115 | void returnInt32(RegisterID src) |
| 116 | { |
| 117 | if (src != regT0) |
| 118 | move(src, regT0); |
| 119 | tagReturnAsInt32(); |
oliver@apple.com | 9d4f0ec | 2011-03-14 18:16:36 +0000 | [diff] [blame] | 120 | loadPtr(payloadFor(RegisterFile::CallerFrame, callFrameRegister), callFrameRegister); |
oliver@apple.com | 8e293b7 | 2010-04-27 04:22:46 +0000 | [diff] [blame] | 121 | ret(); |
| 122 | } |
oliver@apple.com | 5cdd4f8 | 2010-04-27 18:17:35 +0000 | [diff] [blame] | 123 | |
| 124 | void returnJSCell(RegisterID src) |
| 125 | { |
| 126 | if (src != regT0) |
| 127 | move(src, regT0); |
| 128 | tagReturnAsJSCell(); |
oliver@apple.com | 9d4f0ec | 2011-03-14 18:16:36 +0000 | [diff] [blame] | 129 | loadPtr(payloadFor(RegisterFile::CallerFrame, callFrameRegister), callFrameRegister); |
oliver@apple.com | 5cdd4f8 | 2010-04-27 18:17:35 +0000 | [diff] [blame] | 130 | ret(); |
| 131 | } |
oliver@apple.com | 8e293b7 | 2010-04-27 04:22:46 +0000 | [diff] [blame] | 132 | |
fpizlo@apple.com | 2adf527 | 2012-06-20 01:33:30 +0000 | [diff] [blame] | 133 | MacroAssemblerCodeRef finalize(JSGlobalData& globalData, MacroAssemblerCodePtr fallback, const char* thunkKind) |
oliver@apple.com | 8e293b7 | 2010-04-27 04:22:46 +0000 | [diff] [blame] | 134 | { |
barraclough@apple.com | b6a00d3 | 2012-01-23 21:08:34 +0000 | [diff] [blame] | 135 | LinkBuffer patchBuffer(globalData, this, GLOBAL_THUNK_ID); |
barraclough@apple.com | 8cc4669 | 2010-05-19 06:04:18 +0000 | [diff] [blame] | 136 | patchBuffer.link(m_failures, CodeLocationLabel(fallback)); |
oliver@apple.com | 5b6a0d3 | 2011-07-01 16:33:46 +0000 | [diff] [blame] | 137 | for (unsigned i = 0; i < m_calls.size(); i++) |
| 138 | patchBuffer.link(m_calls[i].first, m_calls[i].second); |
fpizlo@apple.com | 2adf527 | 2012-06-20 01:33:30 +0000 | [diff] [blame] | 139 | return FINALIZE_CODE(patchBuffer, ("Specialized thunk for %s", thunkKind)); |
oliver@apple.com | 8e293b7 | 2010-04-27 04:22:46 +0000 | [diff] [blame] | 140 | } |
oliver@apple.com | 5b6a0d3 | 2011-07-01 16:33:46 +0000 | [diff] [blame] | 141 | |
| 142 | // Assumes that the target function uses fpRegister0 as the first argument |
| 143 | // and return value. Like any sensible architecture would. |
| 144 | void callDoubleToDouble(FunctionPtr function) |
| 145 | { |
| 146 | m_calls.append(std::make_pair(call(), function)); |
| 147 | } |
| 148 | |
oliver@apple.com | 8e293b7 | 2010-04-27 04:22:46 +0000 | [diff] [blame] | 149 | private: |
oliver@apple.com | 8e293b7 | 2010-04-27 04:22:46 +0000 | [diff] [blame] | 150 | |
| 151 | void tagReturnAsInt32() |
| 152 | { |
| 153 | #if USE(JSVALUE64) |
| 154 | orPtr(tagTypeNumberRegister, regT0); |
oliver@apple.com | 8e293b7 | 2010-04-27 04:22:46 +0000 | [diff] [blame] | 155 | #else |
oliver@apple.com | be4e067 | 2011-03-28 17:14:57 +0000 | [diff] [blame] | 156 | move(TrustedImm32(JSValue::Int32Tag), regT1); |
oliver@apple.com | 8e293b7 | 2010-04-27 04:22:46 +0000 | [diff] [blame] | 157 | #endif |
| 158 | } |
oliver@apple.com | 2bd947e | 2010-04-29 03:57:16 +0000 | [diff] [blame] | 159 | |
oliver@apple.com | 5cdd4f8 | 2010-04-27 18:17:35 +0000 | [diff] [blame] | 160 | void tagReturnAsJSCell() |
| 161 | { |
| 162 | #if USE(JSVALUE32_64) |
oliver@apple.com | be4e067 | 2011-03-28 17:14:57 +0000 | [diff] [blame] | 163 | move(TrustedImm32(JSValue::CellTag), regT1); |
oliver@apple.com | 5cdd4f8 | 2010-04-27 18:17:35 +0000 | [diff] [blame] | 164 | #endif |
| 165 | } |
| 166 | |
oliver@apple.com | 8e293b7 | 2010-04-27 04:22:46 +0000 | [diff] [blame] | 167 | MacroAssembler::JumpList m_failures; |
oliver@apple.com | 5b6a0d3 | 2011-07-01 16:33:46 +0000 | [diff] [blame] | 168 | Vector<std::pair<Call, FunctionPtr> > m_calls; |
oliver@apple.com | 8e293b7 | 2010-04-27 04:22:46 +0000 | [diff] [blame] | 169 | }; |
| 170 | |
| 171 | } |
| 172 | |
| 173 | #endif // ENABLE(JIT) |
| 174 | |
| 175 | #endif // SpecializedThunkJIT_h |