]>
Commit | Line | Data |
---|---|---|
4e4e5a6f A |
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; | |
6fe7ccc8 | 40 | SpecializedThunkJIT(int expectedArgCount, JSGlobalData* globalData) |
4e4e5a6f A |
41 | : m_expectedArgCount(expectedArgCount) |
42 | , m_globalData(globalData) | |
4e4e5a6f A |
43 | { |
44 | // Check that we have the expected number of arguments | |
6fe7ccc8 | 45 | m_failures.append(branch32(NotEqual, payloadFor(RegisterFile::ArgumentCount), TrustedImm32(expectedArgCount + 1))); |
4e4e5a6f A |
46 | } |
47 | ||
48 | void loadDoubleArgument(int argument, FPRegisterID dst, RegisterID scratch) | |
49 | { | |
6fe7ccc8 | 50 | unsigned src = CallFrame::argumentOffset(argument); |
4e4e5a6f A |
51 | m_failures.append(emitLoadDouble(src, dst, scratch)); |
52 | } | |
53 | ||
54 | void loadCellArgument(int argument, RegisterID dst) | |
55 | { | |
6fe7ccc8 | 56 | unsigned src = CallFrame::argumentOffset(argument); |
4e4e5a6f A |
57 | m_failures.append(emitLoadJSCell(src, dst)); |
58 | } | |
59 | ||
60 | void loadJSStringArgument(int argument, RegisterID dst) | |
61 | { | |
62 | loadCellArgument(argument, dst); | |
6fe7ccc8 | 63 | m_failures.append(branchPtr(NotEqual, Address(dst, JSCell::classInfoOffset()), TrustedImmPtr(&JSString::s_info))); |
4e4e5a6f A |
64 | } |
65 | ||
66 | void loadInt32Argument(int argument, RegisterID dst, Jump& failTarget) | |
67 | { | |
6fe7ccc8 | 68 | unsigned src = CallFrame::argumentOffset(argument); |
4e4e5a6f A |
69 | failTarget = emitLoadInt32(src, dst); |
70 | } | |
71 | ||
72 | void loadInt32Argument(int argument, RegisterID dst) | |
73 | { | |
74 | Jump conversionFailed; | |
75 | loadInt32Argument(argument, dst, conversionFailed); | |
76 | m_failures.append(conversionFailed); | |
77 | } | |
78 | ||
79 | void appendFailure(const Jump& failure) | |
80 | { | |
81 | m_failures.append(failure); | |
82 | } | |
83 | ||
84 | void returnJSValue(RegisterID src) | |
85 | { | |
86 | if (src != regT0) | |
87 | move(src, regT0); | |
14957cd0 | 88 | loadPtr(payloadFor(RegisterFile::CallerFrame, callFrameRegister), callFrameRegister); |
4e4e5a6f A |
89 | ret(); |
90 | } | |
91 | ||
92 | void returnDouble(FPRegisterID src) | |
93 | { | |
94 | #if USE(JSVALUE64) | |
95 | moveDoubleToPtr(src, regT0); | |
6fe7ccc8 | 96 | Jump zero = branchTestPtr(Zero, regT0); |
4e4e5a6f | 97 | subPtr(tagTypeNumberRegister, regT0); |
6fe7ccc8 A |
98 | Jump done = jump(); |
99 | zero.link(this); | |
100 | move(tagTypeNumberRegister, regT0); | |
101 | done.link(this); | |
14957cd0 | 102 | #else |
4e4e5a6f A |
103 | storeDouble(src, Address(stackPointerRegister, -(int)sizeof(double))); |
104 | loadPtr(Address(stackPointerRegister, OBJECT_OFFSETOF(JSValue, u.asBits.tag) - sizeof(double)), regT1); | |
105 | loadPtr(Address(stackPointerRegister, OBJECT_OFFSETOF(JSValue, u.asBits.payload) - sizeof(double)), regT0); | |
6fe7ccc8 A |
106 | Jump lowNonZero = branchTestPtr(NonZero, regT1); |
107 | Jump highNonZero = branchTestPtr(NonZero, regT0); | |
108 | move(TrustedImm32(0), regT0); | |
109 | move(TrustedImm32(Int32Tag), regT1); | |
110 | lowNonZero.link(this); | |
111 | highNonZero.link(this); | |
4e4e5a6f | 112 | #endif |
14957cd0 | 113 | loadPtr(payloadFor(RegisterFile::CallerFrame, callFrameRegister), callFrameRegister); |
4e4e5a6f A |
114 | ret(); |
115 | } | |
116 | ||
117 | void returnInt32(RegisterID src) | |
118 | { | |
119 | if (src != regT0) | |
120 | move(src, regT0); | |
121 | tagReturnAsInt32(); | |
14957cd0 | 122 | loadPtr(payloadFor(RegisterFile::CallerFrame, callFrameRegister), callFrameRegister); |
4e4e5a6f A |
123 | ret(); |
124 | } | |
125 | ||
126 | void returnJSCell(RegisterID src) | |
127 | { | |
128 | if (src != regT0) | |
129 | move(src, regT0); | |
130 | tagReturnAsJSCell(); | |
14957cd0 | 131 | loadPtr(payloadFor(RegisterFile::CallerFrame, callFrameRegister), callFrameRegister); |
4e4e5a6f A |
132 | ret(); |
133 | } | |
134 | ||
6fe7ccc8 | 135 | MacroAssemblerCodeRef finalize(JSGlobalData& globalData, MacroAssemblerCodePtr fallback) |
4e4e5a6f | 136 | { |
6fe7ccc8 | 137 | LinkBuffer patchBuffer(globalData, this, GLOBAL_THUNK_ID); |
14957cd0 | 138 | patchBuffer.link(m_failures, CodeLocationLabel(fallback)); |
6fe7ccc8 A |
139 | for (unsigned i = 0; i < m_calls.size(); i++) |
140 | patchBuffer.link(m_calls[i].first, m_calls[i].second); | |
141 | return patchBuffer.finalizeCode(); | |
4e4e5a6f | 142 | } |
6fe7ccc8 A |
143 | |
144 | // Assumes that the target function uses fpRegister0 as the first argument | |
145 | // and return value. Like any sensible architecture would. | |
146 | void callDoubleToDouble(FunctionPtr function) | |
4e4e5a6f | 147 | { |
6fe7ccc8 | 148 | m_calls.append(std::make_pair(call(), function)); |
4e4e5a6f A |
149 | } |
150 | ||
6fe7ccc8 A |
151 | private: |
152 | ||
4e4e5a6f A |
153 | void tagReturnAsInt32() |
154 | { | |
155 | #if USE(JSVALUE64) | |
156 | orPtr(tagTypeNumberRegister, regT0); | |
4e4e5a6f | 157 | #else |
14957cd0 | 158 | move(TrustedImm32(JSValue::Int32Tag), regT1); |
4e4e5a6f A |
159 | #endif |
160 | } | |
161 | ||
162 | void tagReturnAsJSCell() | |
163 | { | |
164 | #if USE(JSVALUE32_64) | |
14957cd0 | 165 | move(TrustedImm32(JSValue::CellTag), regT1); |
4e4e5a6f A |
166 | #endif |
167 | } | |
168 | ||
169 | int m_expectedArgCount; | |
170 | JSGlobalData* m_globalData; | |
4e4e5a6f | 171 | MacroAssembler::JumpList m_failures; |
6fe7ccc8 | 172 | Vector<std::pair<Call, FunctionPtr> > m_calls; |
4e4e5a6f A |
173 | }; |
174 | ||
175 | } | |
176 | ||
177 | #endif // ENABLE(JIT) | |
178 | ||
179 | #endif // SpecializedThunkJIT_h |