1 | /*
|
---|
2 | * Copyright (C) 2008 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. ``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 |
|
---|
26 | #include "config.h"
|
---|
27 | #include "JIT.h"
|
---|
28 |
|
---|
29 | #if ENABLE(JIT)
|
---|
30 |
|
---|
31 | #include "CodeBlock.h"
|
---|
32 | #include "JITInlineMethods.h"
|
---|
33 | #include "JSArray.h"
|
---|
34 | #include "JSFunction.h"
|
---|
35 | #include "Interpreter.h"
|
---|
36 | #include "ResultType.h"
|
---|
37 | #include "SamplingTool.h"
|
---|
38 |
|
---|
39 | #ifndef NDEBUG
|
---|
40 | #include <stdio.h>
|
---|
41 | #endif
|
---|
42 |
|
---|
43 | #define __ m_assembler.
|
---|
44 |
|
---|
45 | using namespace std;
|
---|
46 |
|
---|
47 | #if PLATFORM(MAC)
|
---|
48 |
|
---|
49 | static inline bool isSSE2Present()
|
---|
50 | {
|
---|
51 | return true; // All X86 Macs are guaranteed to support at least SSE2
|
---|
52 | }
|
---|
53 |
|
---|
54 | #else
|
---|
55 |
|
---|
56 | static bool isSSE2Present()
|
---|
57 | {
|
---|
58 | static const int SSE2FeatureBit = 1 << 26;
|
---|
59 | struct SSE2Check {
|
---|
60 | SSE2Check()
|
---|
61 | {
|
---|
62 | int flags;
|
---|
63 | #if COMPILER(MSVC)
|
---|
64 | _asm {
|
---|
65 | mov eax, 1 // cpuid function 1 gives us the standard feature set
|
---|
66 | cpuid;
|
---|
67 | mov flags, edx;
|
---|
68 | }
|
---|
69 | #elif COMPILER(GCC)
|
---|
70 | asm (
|
---|
71 | "movl $0x1, %%eax;"
|
---|
72 | "pushl %%ebx;"
|
---|
73 | "cpuid;"
|
---|
74 | "popl %%ebx;"
|
---|
75 | "movl %%edx, %0;"
|
---|
76 | : "=g" (flags)
|
---|
77 | :
|
---|
78 | : "%eax", "%ecx", "%edx"
|
---|
79 | );
|
---|
80 | #else
|
---|
81 | flags = 0;
|
---|
82 | #endif
|
---|
83 | present = (flags & SSE2FeatureBit) != 0;
|
---|
84 | }
|
---|
85 | bool present;
|
---|
86 | };
|
---|
87 | static SSE2Check check;
|
---|
88 | return check.present;
|
---|
89 | }
|
---|
90 |
|
---|
91 | #endif
|
---|
92 |
|
---|
93 | namespace JSC {
|
---|
94 |
|
---|
95 | void JIT::compileFastArith_op_lshift(unsigned result, unsigned op1, unsigned op2)
|
---|
96 | {
|
---|
97 | emitGetVirtualRegisters(op1, regT0, op2, regT2);
|
---|
98 | // FIXME: would we be better using 'emitJumpSlowCaseIfNotImmediateIntegers'? - we *probably* ought to be consistent.
|
---|
99 | emitJumpSlowCaseIfNotImmediateInteger(regT0);
|
---|
100 | emitJumpSlowCaseIfNotImmediateInteger(regT2);
|
---|
101 | emitFastArithImmToInt(regT0);
|
---|
102 | emitFastArithImmToInt(regT2);
|
---|
103 | #if !PLATFORM(X86)
|
---|
104 | // Mask with 0x1f as per ecma-262 11.7.2 step 7.
|
---|
105 | // On 32-bit x86 this is not necessary, since the shift anount is implicitly masked in the instruction.
|
---|
106 | and32(Imm32(0x1f), regT2);
|
---|
107 | #endif
|
---|
108 | lshift32(regT2, regT0);
|
---|
109 | #if !USE(ALTERNATE_JSIMMEDIATE)
|
---|
110 | addSlowCase(branchAdd32(Overflow, regT0, regT0));
|
---|
111 | signExtend32ToPtr(regT0, regT0);
|
---|
112 | #endif
|
---|
113 | emitFastArithReTagImmediate(regT0, regT0);
|
---|
114 | emitPutVirtualRegister(result);
|
---|
115 | }
|
---|
116 | void JIT::compileFastArithSlow_op_lshift(unsigned result, unsigned op1, unsigned op2, Vector<SlowCaseEntry>::iterator& iter)
|
---|
117 | {
|
---|
118 | #if USE(ALTERNATE_JSIMMEDIATE)
|
---|
119 | UNUSED_PARAM(op1);
|
---|
120 | UNUSED_PARAM(op2);
|
---|
121 | linkSlowCase(iter);
|
---|
122 | linkSlowCase(iter);
|
---|
123 | #else
|
---|
124 | // If we are limited to 32-bit immediates there is a third slow case, which required the operands to have been reloaded.
|
---|
125 | Jump notImm1 = getSlowCase(iter);
|
---|
126 | Jump notImm2 = getSlowCase(iter);
|
---|
127 | linkSlowCase(iter);
|
---|
128 | emitGetVirtualRegisters(op1, regT0, op2, regT2);
|
---|
129 | notImm1.link(this);
|
---|
130 | notImm2.link(this);
|
---|
131 | #endif
|
---|
132 | emitPutJITStubArg(regT0, 1);
|
---|
133 | emitPutJITStubArg(regT2, 2);
|
---|
134 | emitCTICall(JITStubs::cti_op_lshift);
|
---|
135 | emitPutVirtualRegister(result);
|
---|
136 | }
|
---|
137 |
|
---|
138 | void JIT::compileFastArith_op_rshift(unsigned result, unsigned op1, unsigned op2)
|
---|
139 | {
|
---|
140 | if (isOperandConstantImmediateInt(op2)) {
|
---|
141 | emitGetVirtualRegister(op1, regT0);
|
---|
142 | emitJumpSlowCaseIfNotImmediateInteger(regT0);
|
---|
143 | // Mask with 0x1f as per ecma-262 11.7.2 step 7.
|
---|
144 | #if USE(ALTERNATE_JSIMMEDIATE)
|
---|
145 | rshift32(Imm32(getConstantOperandImmediateInt(op2) & 0x1f), regT0);
|
---|
146 | #else
|
---|
147 | rshiftPtr(Imm32(getConstantOperandImmediateInt(op2) & 0x1f), regT0);
|
---|
148 | #endif
|
---|
149 | } else {
|
---|
150 | emitGetVirtualRegisters(op1, regT0, op2, regT2);
|
---|
151 | if (isSSE2Present()) {
|
---|
152 | Jump lhsIsInt = emitJumpIfImmediateInteger(regT0);
|
---|
153 | #if USE(ALTERNATE_JSIMMEDIATE)
|
---|
154 | addSlowCase(emitJumpIfNotImmediateNumber(regT0));
|
---|
155 | __ movq_rr(regT0, X86::xmm0);
|
---|
156 | #else
|
---|
157 | emitJumpSlowCaseIfNotJSCell(regT0, op1);
|
---|
158 | addSlowCase(checkStructure(regT0, m_globalData->numberStructure.get()));
|
---|
159 | __ movsd_mr(FIELD_OFFSET(JSNumberCell, m_value), regT0, X86::xmm0);
|
---|
160 | #endif
|
---|
161 | __ cvttsd2si_rr(X86::xmm0, regT0);
|
---|
162 | addSlowCase(branch32(Equal, regT0, Imm32(0x80000000)));
|
---|
163 | #if !USE(ALTERNATE_JSIMMEDIATE)
|
---|
164 | add32(regT0, regT0);
|
---|
165 | addSlowCase(__ jo());
|
---|
166 | #endif
|
---|
167 | lhsIsInt.link(this);
|
---|
168 | } else
|
---|
169 | emitJumpSlowCaseIfNotImmediateInteger(regT0);
|
---|
170 | emitJumpSlowCaseIfNotImmediateInteger(regT2);
|
---|
171 | emitFastArithImmToInt(regT2);
|
---|
172 | #if !PLATFORM(X86)
|
---|
173 | // Mask with 0x1f as per ecma-262 11.7.2 step 7.
|
---|
174 | // On 32-bit x86 this is not necessary, since the shift anount is implicitly masked in the instruction.
|
---|
175 | and32(Imm32(0x1f), regT2);
|
---|
176 | #endif
|
---|
177 | #if USE(ALTERNATE_JSIMMEDIATE)
|
---|
178 | rshift32(regT2, regT0);
|
---|
179 | #else
|
---|
180 | rshiftPtr(regT2, regT0);
|
---|
181 | #endif
|
---|
182 | }
|
---|
183 | #if USE(ALTERNATE_JSIMMEDIATE)
|
---|
184 | emitFastArithIntToImmNoCheck(regT0, regT0);
|
---|
185 | #else
|
---|
186 | orPtr(Imm32(JSImmediate::TagTypeNumber), regT0);
|
---|
187 | #endif
|
---|
188 | emitPutVirtualRegister(result);
|
---|
189 | }
|
---|
190 | void JIT::compileFastArithSlow_op_rshift(unsigned result, unsigned op1, unsigned op2, Vector<SlowCaseEntry>::iterator& iter)
|
---|
191 | {
|
---|
192 | linkSlowCase(iter);
|
---|
193 | if (isOperandConstantImmediateInt(op2))
|
---|
194 | emitPutJITStubArgFromVirtualRegister(op2, 2, regT2);
|
---|
195 | else {
|
---|
196 | if (isSSE2Present()) {
|
---|
197 | #if USE(ALTERNATE_JSIMMEDIATE)
|
---|
198 | linkSlowCase(iter);
|
---|
199 | #else
|
---|
200 | linkSlowCaseIfNotJSCell(iter, op1);
|
---|
201 | linkSlowCase(iter);
|
---|
202 | linkSlowCase(iter);
|
---|
203 | #endif
|
---|
204 | linkSlowCase(iter);
|
---|
205 | // We're reloading op1 to regT0 as we can no longer guarantee that
|
---|
206 | // we have not munged the operand. It may have already been shifted
|
---|
207 | // correctly, but it still will not have been tagged.
|
---|
208 | emitGetVirtualRegister(op1, regT0);
|
---|
209 | } else {
|
---|
210 | linkSlowCase(iter);
|
---|
211 | linkSlowCase(iter);
|
---|
212 | }
|
---|
213 | emitPutJITStubArg(regT2, 2);
|
---|
214 | }
|
---|
215 |
|
---|
216 | emitPutJITStubArg(regT0, 1);
|
---|
217 | emitCTICall(JITStubs::cti_op_rshift);
|
---|
218 | emitPutVirtualRegister(result);
|
---|
219 | }
|
---|
220 |
|
---|
221 | void JIT::compileFastArith_op_bitand(unsigned result, unsigned op1, unsigned op2)
|
---|
222 | {
|
---|
223 | if (isOperandConstantImmediateInt(op1)) {
|
---|
224 | emitGetVirtualRegister(op2, regT0);
|
---|
225 | emitJumpSlowCaseIfNotImmediateInteger(regT0);
|
---|
226 | #if USE(ALTERNATE_JSIMMEDIATE)
|
---|
227 | int32_t imm = getConstantOperandImmediateInt(op1);
|
---|
228 | andPtr(Imm32(imm), regT0);
|
---|
229 | if (imm >= 0)
|
---|
230 | emitFastArithIntToImmNoCheck(regT0, regT0);
|
---|
231 | #else
|
---|
232 | andPtr(Imm32(static_cast<int32_t>(JSImmediate::rawValue(getConstantOperand(op1)))), regT0);
|
---|
233 | #endif
|
---|
234 | } else if (isOperandConstantImmediateInt(op2)) {
|
---|
235 | emitGetVirtualRegister(op1, regT0);
|
---|
236 | emitJumpSlowCaseIfNotImmediateInteger(regT0);
|
---|
237 | #if USE(ALTERNATE_JSIMMEDIATE)
|
---|
238 | int32_t imm = getConstantOperandImmediateInt(op2);
|
---|
239 | andPtr(Imm32(imm), regT0);
|
---|
240 | if (imm >= 0)
|
---|
241 | emitFastArithIntToImmNoCheck(regT0, regT0);
|
---|
242 | #else
|
---|
243 | andPtr(Imm32(static_cast<int32_t>(JSImmediate::rawValue(getConstantOperand(op2)))), regT0);
|
---|
244 | #endif
|
---|
245 | } else {
|
---|
246 | emitGetVirtualRegisters(op1, regT0, op2, regT1);
|
---|
247 | andPtr(regT1, regT0);
|
---|
248 | emitJumpSlowCaseIfNotImmediateInteger(regT0);
|
---|
249 | }
|
---|
250 | emitPutVirtualRegister(result);
|
---|
251 | }
|
---|
252 | void JIT::compileFastArithSlow_op_bitand(unsigned result, unsigned op1, unsigned op2, Vector<SlowCaseEntry>::iterator& iter)
|
---|
253 | {
|
---|
254 | linkSlowCase(iter);
|
---|
255 | if (isOperandConstantImmediateInt(op1)) {
|
---|
256 | emitPutJITStubArgFromVirtualRegister(op1, 1, regT2);
|
---|
257 | emitPutJITStubArg(regT0, 2);
|
---|
258 | } else if (isOperandConstantImmediateInt(op2)) {
|
---|
259 | emitPutJITStubArg(regT0, 1);
|
---|
260 | emitPutJITStubArgFromVirtualRegister(op2, 2, regT2);
|
---|
261 | } else {
|
---|
262 | emitPutJITStubArgFromVirtualRegister(op1, 1, regT2);
|
---|
263 | emitPutJITStubArg(regT1, 2);
|
---|
264 | }
|
---|
265 | emitCTICall(JITStubs::cti_op_bitand);
|
---|
266 | emitPutVirtualRegister(result);
|
---|
267 | }
|
---|
268 |
|
---|
269 | #if PLATFORM(X86) || PLATFORM(X86_64)
|
---|
270 | void JIT::compileFastArith_op_mod(unsigned result, unsigned op1, unsigned op2)
|
---|
271 | {
|
---|
272 | emitGetVirtualRegisters(op1, X86::eax, op2, X86::ecx);
|
---|
273 | emitJumpSlowCaseIfNotImmediateInteger(X86::eax);
|
---|
274 | emitJumpSlowCaseIfNotImmediateInteger(X86::ecx);
|
---|
275 | #if USE(ALTERNATE_JSIMMEDIATE)
|
---|
276 | addSlowCase(branchPtr(Equal, X86::ecx, ImmPtr(JSValue::encode(jsNumber(m_globalData, 0)))));
|
---|
277 | m_assembler.cdq();
|
---|
278 | m_assembler.idivl_r(X86::ecx);
|
---|
279 | #else
|
---|
280 | emitFastArithDeTagImmediate(X86::eax);
|
---|
281 | addSlowCase(emitFastArithDeTagImmediateJumpIfZero(X86::ecx));
|
---|
282 | m_assembler.cdq();
|
---|
283 | m_assembler.idivl_r(X86::ecx);
|
---|
284 | signExtend32ToPtr(X86::edx, X86::edx);
|
---|
285 | #endif
|
---|
286 | emitFastArithReTagImmediate(X86::edx, X86::eax);
|
---|
287 | emitPutVirtualRegister(result);
|
---|
288 | }
|
---|
289 | void JIT::compileFastArithSlow_op_mod(unsigned result, unsigned, unsigned, Vector<SlowCaseEntry>::iterator& iter)
|
---|
290 | {
|
---|
291 | #if USE(ALTERNATE_JSIMMEDIATE)
|
---|
292 | linkSlowCase(iter);
|
---|
293 | linkSlowCase(iter);
|
---|
294 | linkSlowCase(iter);
|
---|
295 | #else
|
---|
296 | Jump notImm1 = getSlowCase(iter);
|
---|
297 | Jump notImm2 = getSlowCase(iter);
|
---|
298 | linkSlowCase(iter);
|
---|
299 | emitFastArithReTagImmediate(X86::eax, X86::eax);
|
---|
300 | emitFastArithReTagImmediate(X86::ecx, X86::ecx);
|
---|
301 | notImm1.link(this);
|
---|
302 | notImm2.link(this);
|
---|
303 | #endif
|
---|
304 | emitPutJITStubArg(X86::eax, 1);
|
---|
305 | emitPutJITStubArg(X86::ecx, 2);
|
---|
306 | emitCTICall(JITStubs::cti_op_mod);
|
---|
307 | emitPutVirtualRegister(result);
|
---|
308 | }
|
---|
309 | #else
|
---|
310 | void JIT::compileFastArith_op_mod(unsigned result, unsigned op1, unsigned op2)
|
---|
311 | {
|
---|
312 | emitPutJITStubArgFromVirtualRegister(op1, 1, regT2);
|
---|
313 | emitPutJITStubArgFromVirtualRegister(op2, 2, regT2);
|
---|
314 | emitCTICall(JITStubs::cti_op_mod);
|
---|
315 | emitPutVirtualRegister(result);
|
---|
316 | }
|
---|
317 | void JIT::compileFastArithSlow_op_mod(unsigned, unsigned, unsigned, Vector<SlowCaseEntry>::iterator&)
|
---|
318 | {
|
---|
319 | ASSERT_NOT_REACHED();
|
---|
320 | }
|
---|
321 | #endif
|
---|
322 |
|
---|
323 | void JIT::compileFastArith_op_post_inc(unsigned result, unsigned srcDst)
|
---|
324 | {
|
---|
325 | emitGetVirtualRegister(srcDst, regT0);
|
---|
326 | move(regT0, regT1);
|
---|
327 | emitJumpSlowCaseIfNotImmediateInteger(regT0);
|
---|
328 | #if USE(ALTERNATE_JSIMMEDIATE)
|
---|
329 | addSlowCase(branchAdd32(Overflow, Imm32(1), regT1));
|
---|
330 | emitFastArithIntToImmNoCheck(regT1, regT1);
|
---|
331 | #else
|
---|
332 | addSlowCase(branchAdd32(Overflow, Imm32(1 << JSImmediate::IntegerPayloadShift), regT1));
|
---|
333 | signExtend32ToPtr(regT1, regT1);
|
---|
334 | #endif
|
---|
335 | emitPutVirtualRegister(srcDst, regT1);
|
---|
336 | emitPutVirtualRegister(result);
|
---|
337 | }
|
---|
338 | void JIT::compileFastArithSlow_op_post_inc(unsigned result, unsigned srcDst, Vector<SlowCaseEntry>::iterator& iter)
|
---|
339 | {
|
---|
340 | linkSlowCase(iter);
|
---|
341 | linkSlowCase(iter);
|
---|
342 | emitPutJITStubArg(regT0, 1);
|
---|
343 | emitCTICall(JITStubs::cti_op_post_inc);
|
---|
344 | emitPutVirtualRegister(srcDst, regT1);
|
---|
345 | emitPutVirtualRegister(result);
|
---|
346 | }
|
---|
347 |
|
---|
348 | void JIT::compileFastArith_op_post_dec(unsigned result, unsigned srcDst)
|
---|
349 | {
|
---|
350 | emitGetVirtualRegister(srcDst, regT0);
|
---|
351 | move(regT0, regT1);
|
---|
352 | emitJumpSlowCaseIfNotImmediateInteger(regT0);
|
---|
353 | #if USE(ALTERNATE_JSIMMEDIATE)
|
---|
354 | addSlowCase(branchSub32(Zero, Imm32(1), regT1));
|
---|
355 | emitFastArithIntToImmNoCheck(regT1, regT1);
|
---|
356 | #else
|
---|
357 | addSlowCase(branchSub32(Zero, Imm32(1 << JSImmediate::IntegerPayloadShift), regT1));
|
---|
358 | signExtend32ToPtr(regT1, regT1);
|
---|
359 | #endif
|
---|
360 | emitPutVirtualRegister(srcDst, regT1);
|
---|
361 | emitPutVirtualRegister(result);
|
---|
362 | }
|
---|
363 | void JIT::compileFastArithSlow_op_post_dec(unsigned result, unsigned srcDst, Vector<SlowCaseEntry>::iterator& iter)
|
---|
364 | {
|
---|
365 | linkSlowCase(iter);
|
---|
366 | linkSlowCase(iter);
|
---|
367 | emitPutJITStubArg(regT0, 1);
|
---|
368 | emitCTICall(JITStubs::cti_op_post_dec);
|
---|
369 | emitPutVirtualRegister(srcDst, regT1);
|
---|
370 | emitPutVirtualRegister(result);
|
---|
371 | }
|
---|
372 |
|
---|
373 | void JIT::compileFastArith_op_pre_inc(unsigned srcDst)
|
---|
374 | {
|
---|
375 | emitGetVirtualRegister(srcDst, regT0);
|
---|
376 | emitJumpSlowCaseIfNotImmediateInteger(regT0);
|
---|
377 | #if USE(ALTERNATE_JSIMMEDIATE)
|
---|
378 | addSlowCase(branchAdd32(Overflow, Imm32(1), regT0));
|
---|
379 | emitFastArithIntToImmNoCheck(regT0, regT0);
|
---|
380 | #else
|
---|
381 | addSlowCase(branchAdd32(Overflow, Imm32(1 << JSImmediate::IntegerPayloadShift), regT0));
|
---|
382 | signExtend32ToPtr(regT0, regT0);
|
---|
383 | #endif
|
---|
384 | emitPutVirtualRegister(srcDst);
|
---|
385 | }
|
---|
386 | void JIT::compileFastArithSlow_op_pre_inc(unsigned srcDst, Vector<SlowCaseEntry>::iterator& iter)
|
---|
387 | {
|
---|
388 | Jump notImm = getSlowCase(iter);
|
---|
389 | linkSlowCase(iter);
|
---|
390 | emitGetVirtualRegister(srcDst, regT0);
|
---|
391 | notImm.link(this);
|
---|
392 | emitPutJITStubArg(regT0, 1);
|
---|
393 | emitCTICall(JITStubs::cti_op_pre_inc);
|
---|
394 | emitPutVirtualRegister(srcDst);
|
---|
395 | }
|
---|
396 |
|
---|
397 | void JIT::compileFastArith_op_pre_dec(unsigned srcDst)
|
---|
398 | {
|
---|
399 | emitGetVirtualRegister(srcDst, regT0);
|
---|
400 | emitJumpSlowCaseIfNotImmediateInteger(regT0);
|
---|
401 | #if USE(ALTERNATE_JSIMMEDIATE)
|
---|
402 | addSlowCase(branchSub32(Zero, Imm32(1), regT0));
|
---|
403 | emitFastArithIntToImmNoCheck(regT0, regT0);
|
---|
404 | #else
|
---|
405 | addSlowCase(branchSub32(Zero, Imm32(1 << JSImmediate::IntegerPayloadShift), regT0));
|
---|
406 | signExtend32ToPtr(regT0, regT0);
|
---|
407 | #endif
|
---|
408 | emitPutVirtualRegister(srcDst);
|
---|
409 | }
|
---|
410 | void JIT::compileFastArithSlow_op_pre_dec(unsigned srcDst, Vector<SlowCaseEntry>::iterator& iter)
|
---|
411 | {
|
---|
412 | Jump notImm = getSlowCase(iter);
|
---|
413 | linkSlowCase(iter);
|
---|
414 | emitGetVirtualRegister(srcDst, regT0);
|
---|
415 | notImm.link(this);
|
---|
416 | emitPutJITStubArg(regT0, 1);
|
---|
417 | emitCTICall(JITStubs::cti_op_pre_dec);
|
---|
418 | emitPutVirtualRegister(srcDst);
|
---|
419 | }
|
---|
420 |
|
---|
421 |
|
---|
422 | #if !ENABLE(JIT_OPTIMIZE_ARITHMETIC)
|
---|
423 |
|
---|
424 | void JIT::compileFastArith_op_add(Instruction* currentInstruction)
|
---|
425 | {
|
---|
426 | unsigned result = currentInstruction[1].u.operand;
|
---|
427 | unsigned op1 = currentInstruction[2].u.operand;
|
---|
428 | unsigned op2 = currentInstruction[3].u.operand;
|
---|
429 |
|
---|
430 | emitPutJITStubArgFromVirtualRegister(op1, 1, regT2);
|
---|
431 | emitPutJITStubArgFromVirtualRegister(op2, 2, regT2);
|
---|
432 | emitCTICall(JITStubs::cti_op_add);
|
---|
433 | emitPutVirtualRegister(result);
|
---|
434 | }
|
---|
435 | void JIT::compileFastArithSlow_op_add(Instruction*, Vector<SlowCaseEntry>::iterator&)
|
---|
436 | {
|
---|
437 | ASSERT_NOT_REACHED();
|
---|
438 | }
|
---|
439 |
|
---|
440 | void JIT::compileFastArith_op_mul(Instruction* currentInstruction)
|
---|
441 | {
|
---|
442 | unsigned result = currentInstruction[1].u.operand;
|
---|
443 | unsigned op1 = currentInstruction[2].u.operand;
|
---|
444 | unsigned op2 = currentInstruction[3].u.operand;
|
---|
445 |
|
---|
446 | emitPutJITStubArgFromVirtualRegister(op1, 1, regT2);
|
---|
447 | emitPutJITStubArgFromVirtualRegister(op2, 2, regT2);
|
---|
448 | emitCTICall(JITStubs::cti_op_mul);
|
---|
449 | emitPutVirtualRegister(result);
|
---|
450 | }
|
---|
451 | void JIT::compileFastArithSlow_op_mul(Instruction*, Vector<SlowCaseEntry>::iterator&)
|
---|
452 | {
|
---|
453 | ASSERT_NOT_REACHED();
|
---|
454 | }
|
---|
455 |
|
---|
456 | void JIT::compileFastArith_op_sub(Instruction* currentInstruction)
|
---|
457 | {
|
---|
458 | unsigned result = currentInstruction[1].u.operand;
|
---|
459 | unsigned op1 = currentInstruction[2].u.operand;
|
---|
460 | unsigned op2 = currentInstruction[3].u.operand;
|
---|
461 |
|
---|
462 | emitPutJITStubArgFromVirtualRegister(op1, 1, regT2);
|
---|
463 | emitPutJITStubArgFromVirtualRegister(op2, 2, regT2);
|
---|
464 | emitCTICall(JITStubs::cti_op_sub);
|
---|
465 | emitPutVirtualRegister(result);
|
---|
466 | }
|
---|
467 | void JIT::compileFastArithSlow_op_sub(Instruction*, Vector<SlowCaseEntry>::iterator&)
|
---|
468 | {
|
---|
469 | ASSERT_NOT_REACHED();
|
---|
470 | }
|
---|
471 |
|
---|
472 | #elif USE(ALTERNATE_JSIMMEDIATE) // *AND* ENABLE(JIT_OPTIMIZE_ARITHMETIC)
|
---|
473 |
|
---|
474 | void JIT::compileBinaryArithOp(OpcodeID opcodeID, unsigned, unsigned op1, unsigned op2, OperandTypes)
|
---|
475 | {
|
---|
476 | emitGetVirtualRegisters(op1, X86::eax, op2, X86::edx);
|
---|
477 | emitJumpSlowCaseIfNotImmediateInteger(X86::eax);
|
---|
478 | emitJumpSlowCaseIfNotImmediateInteger(X86::edx);
|
---|
479 | if (opcodeID == op_add)
|
---|
480 | addSlowCase(branchAdd32(Overflow, X86::edx, X86::eax));
|
---|
481 | else if (opcodeID == op_sub)
|
---|
482 | addSlowCase(branchSub32(Overflow, X86::edx, X86::eax));
|
---|
483 | else {
|
---|
484 | ASSERT(opcodeID == op_mul);
|
---|
485 | addSlowCase(branchMul32(Overflow, X86::edx, X86::eax));
|
---|
486 | addSlowCase(branchTest32(Zero, X86::eax));
|
---|
487 | }
|
---|
488 | emitFastArithIntToImmNoCheck(X86::eax, X86::eax);
|
---|
489 | }
|
---|
490 |
|
---|
491 | void JIT::compileBinaryArithOpSlowCase(OpcodeID opcodeID, Vector<SlowCaseEntry>::iterator& iter, unsigned, unsigned op1, unsigned, OperandTypes types)
|
---|
492 | {
|
---|
493 | // We assume that subtracting TagTypeNumber is equivalent to adding DoubleEncodeOffset.
|
---|
494 | COMPILE_ASSERT(((JSImmediate::TagTypeNumber + JSImmediate::DoubleEncodeOffset) == 0), TagTypeNumber_PLUS_DoubleEncodeOffset_EQUALS_0);
|
---|
495 |
|
---|
496 | Jump notImm1 = getSlowCase(iter);
|
---|
497 | Jump notImm2 = getSlowCase(iter);
|
---|
498 |
|
---|
499 | linkSlowCase(iter); // Integer overflow case - we could handle this in JIT code, but this is likely rare.
|
---|
500 | if (opcodeID == op_mul) // op_mul has an extra slow case to handle 0 * negative number.
|
---|
501 | linkSlowCase(iter);
|
---|
502 | emitGetVirtualRegister(op1, X86::eax);
|
---|
503 |
|
---|
504 | Label stubFunctionCall(this);
|
---|
505 | emitPutJITStubArg(X86::eax, 1);
|
---|
506 | emitPutJITStubArg(X86::edx, 2);
|
---|
507 | if (opcodeID == op_add)
|
---|
508 | emitCTICall(JITStubs::cti_op_add);
|
---|
509 | else if (opcodeID == op_sub)
|
---|
510 | emitCTICall(JITStubs::cti_op_sub);
|
---|
511 | else {
|
---|
512 | ASSERT(opcodeID == op_mul);
|
---|
513 | emitCTICall(JITStubs::cti_op_mul);
|
---|
514 | }
|
---|
515 | Jump end = jump();
|
---|
516 |
|
---|
517 | // if we get here, eax is not an int32, edx not yet checked.
|
---|
518 | notImm1.link(this);
|
---|
519 | if (!types.first().definitelyIsNumber())
|
---|
520 | emitJumpIfNotImmediateNumber(X86::eax).linkTo(stubFunctionCall, this);
|
---|
521 | if (!types.second().definitelyIsNumber())
|
---|
522 | emitJumpIfNotImmediateNumber(X86::edx).linkTo(stubFunctionCall, this);
|
---|
523 | addPtr(tagTypeNumberRegister, X86::eax);
|
---|
524 | m_assembler.movq_rr(X86::eax, X86::xmm1);
|
---|
525 | Jump op2isDouble = emitJumpIfNotImmediateInteger(X86::edx);
|
---|
526 | m_assembler.cvtsi2sd_rr(X86::edx, X86::xmm2);
|
---|
527 | Jump op2wasInteger = jump();
|
---|
528 |
|
---|
529 | // if we get here, eax IS an int32, edx is not.
|
---|
530 | notImm2.link(this);
|
---|
531 | if (!types.second().definitelyIsNumber())
|
---|
532 | emitJumpIfNotImmediateNumber(X86::edx).linkTo(stubFunctionCall, this);
|
---|
533 | m_assembler.cvtsi2sd_rr(X86::eax, X86::xmm1);
|
---|
534 | op2isDouble.link(this);
|
---|
535 | addPtr(tagTypeNumberRegister, X86::edx);
|
---|
536 | m_assembler.movq_rr(X86::edx, X86::xmm2);
|
---|
537 | op2wasInteger.link(this);
|
---|
538 |
|
---|
539 | if (opcodeID == op_add)
|
---|
540 | m_assembler.addsd_rr(X86::xmm2, X86::xmm1);
|
---|
541 | else if (opcodeID == op_sub)
|
---|
542 | m_assembler.subsd_rr(X86::xmm2, X86::xmm1);
|
---|
543 | else {
|
---|
544 | ASSERT(opcodeID == op_mul);
|
---|
545 | m_assembler.mulsd_rr(X86::xmm2, X86::xmm1);
|
---|
546 | }
|
---|
547 | m_assembler.movq_rr(X86::xmm1, X86::eax);
|
---|
548 | subPtr(tagTypeNumberRegister, X86::eax);
|
---|
549 |
|
---|
550 | end.link(this);
|
---|
551 | }
|
---|
552 |
|
---|
553 | void JIT::compileFastArith_op_add(Instruction* currentInstruction)
|
---|
554 | {
|
---|
555 | unsigned result = currentInstruction[1].u.operand;
|
---|
556 | unsigned op1 = currentInstruction[2].u.operand;
|
---|
557 | unsigned op2 = currentInstruction[3].u.operand;
|
---|
558 | OperandTypes types = OperandTypes::fromInt(currentInstruction[4].u.operand);
|
---|
559 |
|
---|
560 | if (!types.first().mightBeNumber() || !types.second().mightBeNumber()) {
|
---|
561 | emitPutJITStubArgFromVirtualRegister(op1, 1, X86::ecx);
|
---|
562 | emitPutJITStubArgFromVirtualRegister(op2, 2, X86::ecx);
|
---|
563 | emitCTICall(JITStubs::cti_op_add);
|
---|
564 | emitPutVirtualRegister(result);
|
---|
565 | return;
|
---|
566 | }
|
---|
567 |
|
---|
568 | if (isOperandConstantImmediateInt(op1)) {
|
---|
569 | emitGetVirtualRegister(op2, X86::eax);
|
---|
570 | emitJumpSlowCaseIfNotImmediateInteger(X86::eax);
|
---|
571 | addSlowCase(branchAdd32(Overflow, Imm32(getConstantOperandImmediateInt(op1)), X86::eax));
|
---|
572 | emitFastArithIntToImmNoCheck(X86::eax, X86::eax);
|
---|
573 | } else if (isOperandConstantImmediateInt(op2)) {
|
---|
574 | emitGetVirtualRegister(op1, X86::eax);
|
---|
575 | emitJumpSlowCaseIfNotImmediateInteger(X86::eax);
|
---|
576 | addSlowCase(branchAdd32(Overflow, Imm32(getConstantOperandImmediateInt(op2)), X86::eax));
|
---|
577 | emitFastArithIntToImmNoCheck(X86::eax, X86::eax);
|
---|
578 | } else
|
---|
579 | compileBinaryArithOp(op_add, result, op1, op2, types);
|
---|
580 |
|
---|
581 | emitPutVirtualRegister(result);
|
---|
582 | }
|
---|
583 | void JIT::compileFastArithSlow_op_add(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
|
---|
584 | {
|
---|
585 | unsigned result = currentInstruction[1].u.operand;
|
---|
586 | unsigned op1 = currentInstruction[2].u.operand;
|
---|
587 | unsigned op2 = currentInstruction[3].u.operand;
|
---|
588 | OperandTypes types = OperandTypes::fromInt(currentInstruction[4].u.operand);
|
---|
589 |
|
---|
590 | if (isOperandConstantImmediateInt(op1)) {
|
---|
591 | linkSlowCase(iter);
|
---|
592 | linkSlowCase(iter);
|
---|
593 | emitPutJITStubArgFromVirtualRegister(op1, 1, X86::ecx);
|
---|
594 | emitPutJITStubArgFromVirtualRegister(op2, 2, X86::ecx);
|
---|
595 | emitCTICall(JITStubs::cti_op_add);
|
---|
596 | } else if (isOperandConstantImmediateInt(op2)) {
|
---|
597 | linkSlowCase(iter);
|
---|
598 | linkSlowCase(iter);
|
---|
599 | emitPutJITStubArgFromVirtualRegister(op1, 1, X86::ecx);
|
---|
600 | emitPutJITStubArgFromVirtualRegister(op2, 2, X86::ecx);
|
---|
601 | emitCTICall(JITStubs::cti_op_add);
|
---|
602 | } else
|
---|
603 | compileBinaryArithOpSlowCase(op_add, iter, result, op1, op2, types);
|
---|
604 |
|
---|
605 | emitPutVirtualRegister(result);
|
---|
606 | }
|
---|
607 |
|
---|
608 | void JIT::compileFastArith_op_mul(Instruction* currentInstruction)
|
---|
609 | {
|
---|
610 | unsigned result = currentInstruction[1].u.operand;
|
---|
611 | unsigned op1 = currentInstruction[2].u.operand;
|
---|
612 | unsigned op2 = currentInstruction[3].u.operand;
|
---|
613 | OperandTypes types = OperandTypes::fromInt(currentInstruction[4].u.operand);
|
---|
614 |
|
---|
615 | // For now, only plant a fast int case if the constant operand is greater than zero.
|
---|
616 | int32_t value;
|
---|
617 | if (isOperandConstantImmediateInt(op1) && ((value = getConstantOperandImmediateInt(op1)) > 0)) {
|
---|
618 | emitGetVirtualRegister(op2, X86::eax);
|
---|
619 | emitJumpSlowCaseIfNotImmediateInteger(X86::eax);
|
---|
620 | addSlowCase(branchMul32(Overflow, Imm32(value), X86::eax, X86::eax));
|
---|
621 | emitFastArithReTagImmediate(X86::eax, X86::eax);
|
---|
622 | } else if (isOperandConstantImmediateInt(op2) && ((value = getConstantOperandImmediateInt(op2)) > 0)) {
|
---|
623 | emitGetVirtualRegister(op1, X86::eax);
|
---|
624 | emitJumpSlowCaseIfNotImmediateInteger(X86::eax);
|
---|
625 | addSlowCase(branchMul32(Overflow, Imm32(value), X86::eax, X86::eax));
|
---|
626 | emitFastArithReTagImmediate(X86::eax, X86::eax);
|
---|
627 | } else
|
---|
628 | compileBinaryArithOp(op_mul, result, op1, op2, types);
|
---|
629 |
|
---|
630 | emitPutVirtualRegister(result);
|
---|
631 | }
|
---|
632 | void JIT::compileFastArithSlow_op_mul(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
|
---|
633 | {
|
---|
634 | unsigned result = currentInstruction[1].u.operand;
|
---|
635 | unsigned op1 = currentInstruction[2].u.operand;
|
---|
636 | unsigned op2 = currentInstruction[3].u.operand;
|
---|
637 | OperandTypes types = OperandTypes::fromInt(currentInstruction[4].u.operand);
|
---|
638 |
|
---|
639 | if ((isOperandConstantImmediateInt(op1) && (getConstantOperandImmediateInt(op1) > 0))
|
---|
640 | || (isOperandConstantImmediateInt(op2) && (getConstantOperandImmediateInt(op2) > 0))) {
|
---|
641 | linkSlowCase(iter);
|
---|
642 | linkSlowCase(iter);
|
---|
643 | // There is an extra slow case for (op1 * -N) or (-N * op2), to check for 0 since this should produce a result of -0.
|
---|
644 | emitPutJITStubArgFromVirtualRegister(op1, 1, X86::ecx);
|
---|
645 | emitPutJITStubArgFromVirtualRegister(op2, 2, X86::ecx);
|
---|
646 | emitCTICall(JITStubs::cti_op_mul);
|
---|
647 | } else
|
---|
648 | compileBinaryArithOpSlowCase(op_mul, iter, result, op1, op2, types);
|
---|
649 |
|
---|
650 | emitPutVirtualRegister(result);
|
---|
651 | }
|
---|
652 |
|
---|
653 | void JIT::compileFastArith_op_sub(Instruction* currentInstruction)
|
---|
654 | {
|
---|
655 | unsigned result = currentInstruction[1].u.operand;
|
---|
656 | unsigned op1 = currentInstruction[2].u.operand;
|
---|
657 | unsigned op2 = currentInstruction[3].u.operand;
|
---|
658 | OperandTypes types = OperandTypes::fromInt(currentInstruction[4].u.operand);
|
---|
659 |
|
---|
660 | compileBinaryArithOp(op_sub, result, op1, op2, types);
|
---|
661 |
|
---|
662 | emitPutVirtualRegister(result);
|
---|
663 | }
|
---|
664 | void JIT::compileFastArithSlow_op_sub(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
|
---|
665 | {
|
---|
666 | unsigned result = currentInstruction[1].u.operand;
|
---|
667 | unsigned op1 = currentInstruction[2].u.operand;
|
---|
668 | unsigned op2 = currentInstruction[3].u.operand;
|
---|
669 | OperandTypes types = OperandTypes::fromInt(currentInstruction[4].u.operand);
|
---|
670 |
|
---|
671 | compileBinaryArithOpSlowCase(op_sub, iter, result, op1, op2, types);
|
---|
672 |
|
---|
673 | emitPutVirtualRegister(result);
|
---|
674 | }
|
---|
675 |
|
---|
676 | #else
|
---|
677 |
|
---|
678 | typedef X86Assembler::JmpSrc JmpSrc;
|
---|
679 | typedef X86Assembler::JmpDst JmpDst;
|
---|
680 | typedef X86Assembler::XMMRegisterID XMMRegisterID;
|
---|
681 |
|
---|
682 |
|
---|
683 | void JIT::compileBinaryArithOp(OpcodeID opcodeID, unsigned dst, unsigned src1, unsigned src2, OperandTypes types)
|
---|
684 | {
|
---|
685 | Structure* numberStructure = m_globalData->numberStructure.get();
|
---|
686 | JmpSrc wasJSNumberCell1;
|
---|
687 | JmpSrc wasJSNumberCell2;
|
---|
688 |
|
---|
689 | emitGetVirtualRegisters(src1, X86::eax, src2, X86::edx);
|
---|
690 |
|
---|
691 | if (types.second().isReusable() && isSSE2Present()) {
|
---|
692 | ASSERT(types.second().mightBeNumber());
|
---|
693 |
|
---|
694 | // Check op2 is a number
|
---|
695 | __ testl_i32r(JSImmediate::TagTypeNumber, X86::edx);
|
---|
696 | JmpSrc op2imm = __ jne();
|
---|
697 | if (!types.second().definitelyIsNumber()) {
|
---|
698 | emitJumpSlowCaseIfNotJSCell(X86::edx, src2);
|
---|
699 | __ cmpl_im(reinterpret_cast<unsigned>(numberStructure), FIELD_OFFSET(JSCell, m_structure), X86::edx);
|
---|
700 | addSlowCase(__ jne());
|
---|
701 | }
|
---|
702 |
|
---|
703 | // (1) In this case src2 is a reusable number cell.
|
---|
704 | // Slow case if src1 is not a number type.
|
---|
705 | __ testl_i32r(JSImmediate::TagTypeNumber, X86::eax);
|
---|
706 | JmpSrc op1imm = __ jne();
|
---|
707 | if (!types.first().definitelyIsNumber()) {
|
---|
708 | emitJumpSlowCaseIfNotJSCell(X86::eax, src1);
|
---|
709 | __ cmpl_im(reinterpret_cast<unsigned>(numberStructure), FIELD_OFFSET(JSCell, m_structure), X86::eax);
|
---|
710 | addSlowCase(__ jne());
|
---|
711 | }
|
---|
712 |
|
---|
713 | // (1a) if we get here, src1 is also a number cell
|
---|
714 | __ movsd_mr(FIELD_OFFSET(JSNumberCell, m_value), X86::eax, X86::xmm0);
|
---|
715 | JmpSrc loadedDouble = __ jmp();
|
---|
716 | // (1b) if we get here, src1 is an immediate
|
---|
717 | __ linkJump(op1imm, __ label());
|
---|
718 | emitFastArithImmToInt(X86::eax);
|
---|
719 | __ cvtsi2sd_rr(X86::eax, X86::xmm0);
|
---|
720 | // (1c)
|
---|
721 | __ linkJump(loadedDouble, __ label());
|
---|
722 | if (opcodeID == op_add)
|
---|
723 | __ addsd_mr(FIELD_OFFSET(JSNumberCell, m_value), X86::edx, X86::xmm0);
|
---|
724 | else if (opcodeID == op_sub)
|
---|
725 | __ subsd_mr(FIELD_OFFSET(JSNumberCell, m_value), X86::edx, X86::xmm0);
|
---|
726 | else {
|
---|
727 | ASSERT(opcodeID == op_mul);
|
---|
728 | __ mulsd_mr(FIELD_OFFSET(JSNumberCell, m_value), X86::edx, X86::xmm0);
|
---|
729 | }
|
---|
730 |
|
---|
731 | // Store the result to the JSNumberCell and jump.
|
---|
732 | __ movsd_rm(X86::xmm0, FIELD_OFFSET(JSNumberCell, m_value), X86::edx);
|
---|
733 | __ movl_rr(X86::edx, X86::eax);
|
---|
734 | emitPutVirtualRegister(dst);
|
---|
735 | wasJSNumberCell2 = __ jmp();
|
---|
736 |
|
---|
737 | // (2) This handles cases where src2 is an immediate number.
|
---|
738 | // Two slow cases - either src1 isn't an immediate, or the subtract overflows.
|
---|
739 | __ linkJump(op2imm, __ label());
|
---|
740 | emitJumpSlowCaseIfNotImmediateInteger(X86::eax);
|
---|
741 | } else if (types.first().isReusable() && isSSE2Present()) {
|
---|
742 | ASSERT(types.first().mightBeNumber());
|
---|
743 |
|
---|
744 | // Check op1 is a number
|
---|
745 | __ testl_i32r(JSImmediate::TagTypeNumber, X86::eax);
|
---|
746 | JmpSrc op1imm = __ jne();
|
---|
747 | if (!types.first().definitelyIsNumber()) {
|
---|
748 | emitJumpSlowCaseIfNotJSCell(X86::eax, src1);
|
---|
749 | __ cmpl_im(reinterpret_cast<unsigned>(numberStructure), FIELD_OFFSET(JSCell, m_structure), X86::eax);
|
---|
750 | addSlowCase(__ jne());
|
---|
751 | }
|
---|
752 |
|
---|
753 | // (1) In this case src1 is a reusable number cell.
|
---|
754 | // Slow case if src2 is not a number type.
|
---|
755 | __ testl_i32r(JSImmediate::TagTypeNumber, X86::edx);
|
---|
756 | JmpSrc op2imm = __ jne();
|
---|
757 | if (!types.second().definitelyIsNumber()) {
|
---|
758 | emitJumpSlowCaseIfNotJSCell(X86::edx, src2);
|
---|
759 | __ cmpl_im(reinterpret_cast<unsigned>(numberStructure), FIELD_OFFSET(JSCell, m_structure), X86::edx);
|
---|
760 | addSlowCase(__ jne());
|
---|
761 | }
|
---|
762 |
|
---|
763 | // (1a) if we get here, src2 is also a number cell
|
---|
764 | __ movsd_mr(FIELD_OFFSET(JSNumberCell, m_value), X86::edx, X86::xmm1);
|
---|
765 | JmpSrc loadedDouble = __ jmp();
|
---|
766 | // (1b) if we get here, src2 is an immediate
|
---|
767 | __ linkJump(op2imm, __ label());
|
---|
768 | emitFastArithImmToInt(X86::edx);
|
---|
769 | __ cvtsi2sd_rr(X86::edx, X86::xmm1);
|
---|
770 | // (1c)
|
---|
771 | __ linkJump(loadedDouble, __ label());
|
---|
772 | __ movsd_mr(FIELD_OFFSET(JSNumberCell, m_value), X86::eax, X86::xmm0);
|
---|
773 | if (opcodeID == op_add)
|
---|
774 | __ addsd_rr(X86::xmm1, X86::xmm0);
|
---|
775 | else if (opcodeID == op_sub)
|
---|
776 | __ subsd_rr(X86::xmm1, X86::xmm0);
|
---|
777 | else {
|
---|
778 | ASSERT(opcodeID == op_mul);
|
---|
779 | __ mulsd_rr(X86::xmm1, X86::xmm0);
|
---|
780 | }
|
---|
781 | __ movsd_rm(X86::xmm0, FIELD_OFFSET(JSNumberCell, m_value), X86::eax);
|
---|
782 | emitPutVirtualRegister(dst);
|
---|
783 |
|
---|
784 | // Store the result to the JSNumberCell and jump.
|
---|
785 | __ movsd_rm(X86::xmm0, FIELD_OFFSET(JSNumberCell, m_value), X86::eax);
|
---|
786 | emitPutVirtualRegister(dst);
|
---|
787 | wasJSNumberCell1 = __ jmp();
|
---|
788 |
|
---|
789 | // (2) This handles cases where src1 is an immediate number.
|
---|
790 | // Two slow cases - either src2 isn't an immediate, or the subtract overflows.
|
---|
791 | __ linkJump(op1imm, __ label());
|
---|
792 | emitJumpSlowCaseIfNotImmediateInteger(X86::edx);
|
---|
793 | } else
|
---|
794 | emitJumpSlowCaseIfNotImmediateIntegers(X86::eax, X86::edx, X86::ecx);
|
---|
795 |
|
---|
796 | if (opcodeID == op_add) {
|
---|
797 | emitFastArithDeTagImmediate(X86::eax);
|
---|
798 | __ addl_rr(X86::edx, X86::eax);
|
---|
799 | addSlowCase(__ jo());
|
---|
800 | } else if (opcodeID == op_sub) {
|
---|
801 | __ subl_rr(X86::edx, X86::eax);
|
---|
802 | addSlowCase(__ jo());
|
---|
803 | signExtend32ToPtr(X86::eax, X86::eax);
|
---|
804 | emitFastArithReTagImmediate(X86::eax, X86::eax);
|
---|
805 | } else {
|
---|
806 | ASSERT(opcodeID == op_mul);
|
---|
807 | // convert eax & edx from JSImmediates to ints, and check if either are zero
|
---|
808 | emitFastArithImmToInt(X86::edx);
|
---|
809 | Jump op1Zero = emitFastArithDeTagImmediateJumpIfZero(X86::eax);
|
---|
810 | __ testl_rr(X86::edx, X86::edx);
|
---|
811 | JmpSrc op2NonZero = __ jne();
|
---|
812 | op1Zero.link(this);
|
---|
813 | // if either input is zero, add the two together, and check if the result is < 0.
|
---|
814 | // If it is, we have a problem (N < 0), (N * 0) == -0, not representatble as a JSImmediate.
|
---|
815 | __ movl_rr(X86::eax, X86::ecx);
|
---|
816 | __ addl_rr(X86::edx, X86::ecx);
|
---|
817 | addSlowCase(__ js());
|
---|
818 | // Skip the above check if neither input is zero
|
---|
819 | __ linkJump(op2NonZero, __ label());
|
---|
820 | __ imull_rr(X86::edx, X86::eax);
|
---|
821 | addSlowCase(__ jo());
|
---|
822 | signExtend32ToPtr(X86::eax, X86::eax);
|
---|
823 | emitFastArithReTagImmediate(X86::eax, X86::eax);
|
---|
824 | }
|
---|
825 | emitPutVirtualRegister(dst);
|
---|
826 |
|
---|
827 | if (types.second().isReusable() && isSSE2Present()) {
|
---|
828 | __ linkJump(wasJSNumberCell2, __ label());
|
---|
829 | }
|
---|
830 | else if (types.first().isReusable() && isSSE2Present()) {
|
---|
831 | __ linkJump(wasJSNumberCell1, __ label());
|
---|
832 | }
|
---|
833 | }
|
---|
834 |
|
---|
835 | void JIT::compileBinaryArithOpSlowCase(OpcodeID opcodeID, Vector<SlowCaseEntry>::iterator& iter, unsigned dst, unsigned src1, unsigned src2, OperandTypes types)
|
---|
836 | {
|
---|
837 | linkSlowCase(iter);
|
---|
838 | if (types.second().isReusable() && isSSE2Present()) {
|
---|
839 | if (!types.first().definitelyIsNumber()) {
|
---|
840 | linkSlowCaseIfNotJSCell(iter, src1);
|
---|
841 | linkSlowCase(iter);
|
---|
842 | }
|
---|
843 | if (!types.second().definitelyIsNumber()) {
|
---|
844 | linkSlowCaseIfNotJSCell(iter, src2);
|
---|
845 | linkSlowCase(iter);
|
---|
846 | }
|
---|
847 | } else if (types.first().isReusable() && isSSE2Present()) {
|
---|
848 | if (!types.first().definitelyIsNumber()) {
|
---|
849 | linkSlowCaseIfNotJSCell(iter, src1);
|
---|
850 | linkSlowCase(iter);
|
---|
851 | }
|
---|
852 | if (!types.second().definitelyIsNumber()) {
|
---|
853 | linkSlowCaseIfNotJSCell(iter, src2);
|
---|
854 | linkSlowCase(iter);
|
---|
855 | }
|
---|
856 | }
|
---|
857 | linkSlowCase(iter);
|
---|
858 |
|
---|
859 | // additional entry point to handle -0 cases.
|
---|
860 | if (opcodeID == op_mul)
|
---|
861 | linkSlowCase(iter);
|
---|
862 |
|
---|
863 | emitPutJITStubArgFromVirtualRegister(src1, 1, X86::ecx);
|
---|
864 | emitPutJITStubArgFromVirtualRegister(src2, 2, X86::ecx);
|
---|
865 | if (opcodeID == op_add)
|
---|
866 | emitCTICall(JITStubs::cti_op_add);
|
---|
867 | else if (opcodeID == op_sub)
|
---|
868 | emitCTICall(JITStubs::cti_op_sub);
|
---|
869 | else {
|
---|
870 | ASSERT(opcodeID == op_mul);
|
---|
871 | emitCTICall(JITStubs::cti_op_mul);
|
---|
872 | }
|
---|
873 | emitPutVirtualRegister(dst);
|
---|
874 | }
|
---|
875 |
|
---|
876 | void JIT::compileFastArith_op_add(Instruction* currentInstruction)
|
---|
877 | {
|
---|
878 | unsigned result = currentInstruction[1].u.operand;
|
---|
879 | unsigned op1 = currentInstruction[2].u.operand;
|
---|
880 | unsigned op2 = currentInstruction[3].u.operand;
|
---|
881 |
|
---|
882 | if (isOperandConstantImmediateInt(op1)) {
|
---|
883 | emitGetVirtualRegister(op2, X86::eax);
|
---|
884 | emitJumpSlowCaseIfNotImmediateInteger(X86::eax);
|
---|
885 | addSlowCase(branchAdd32(Overflow, Imm32(getConstantOperandImmediateInt(op1) << JSImmediate::IntegerPayloadShift), X86::eax));
|
---|
886 | signExtend32ToPtr(X86::eax, X86::eax);
|
---|
887 | emitPutVirtualRegister(result);
|
---|
888 | } else if (isOperandConstantImmediateInt(op2)) {
|
---|
889 | emitGetVirtualRegister(op1, X86::eax);
|
---|
890 | emitJumpSlowCaseIfNotImmediateInteger(X86::eax);
|
---|
891 | addSlowCase(branchAdd32(Overflow, Imm32(getConstantOperandImmediateInt(op2) << JSImmediate::IntegerPayloadShift), X86::eax));
|
---|
892 | signExtend32ToPtr(X86::eax, X86::eax);
|
---|
893 | emitPutVirtualRegister(result);
|
---|
894 | } else {
|
---|
895 | OperandTypes types = OperandTypes::fromInt(currentInstruction[4].u.operand);
|
---|
896 | if (types.first().mightBeNumber() && types.second().mightBeNumber())
|
---|
897 | compileBinaryArithOp(op_add, result, op1, op2, OperandTypes::fromInt(currentInstruction[4].u.operand));
|
---|
898 | else {
|
---|
899 | emitPutJITStubArgFromVirtualRegister(op1, 1, X86::ecx);
|
---|
900 | emitPutJITStubArgFromVirtualRegister(op2, 2, X86::ecx);
|
---|
901 | emitCTICall(JITStubs::cti_op_add);
|
---|
902 | emitPutVirtualRegister(result);
|
---|
903 | }
|
---|
904 | }
|
---|
905 | }
|
---|
906 | void JIT::compileFastArithSlow_op_add(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
|
---|
907 | {
|
---|
908 | unsigned result = currentInstruction[1].u.operand;
|
---|
909 | unsigned op1 = currentInstruction[2].u.operand;
|
---|
910 | unsigned op2 = currentInstruction[3].u.operand;
|
---|
911 |
|
---|
912 | if (isOperandConstantImmediateInt(op1)) {
|
---|
913 | Jump notImm = getSlowCase(iter);
|
---|
914 | linkSlowCase(iter);
|
---|
915 | sub32(Imm32(getConstantOperandImmediateInt(op1) << JSImmediate::IntegerPayloadShift), X86::eax);
|
---|
916 | notImm.link(this);
|
---|
917 | emitPutJITStubArgFromVirtualRegister(op1, 1, X86::ecx);
|
---|
918 | emitPutJITStubArg(X86::eax, 2);
|
---|
919 | emitCTICall(JITStubs::cti_op_add);
|
---|
920 | emitPutVirtualRegister(result);
|
---|
921 | } else if (isOperandConstantImmediateInt(op2)) {
|
---|
922 | Jump notImm = getSlowCase(iter);
|
---|
923 | linkSlowCase(iter);
|
---|
924 | sub32(Imm32(getConstantOperandImmediateInt(op2) << JSImmediate::IntegerPayloadShift), X86::eax);
|
---|
925 | notImm.link(this);
|
---|
926 | emitPutJITStubArg(X86::eax, 1);
|
---|
927 | emitPutJITStubArgFromVirtualRegister(op2, 2, X86::ecx);
|
---|
928 | emitCTICall(JITStubs::cti_op_add);
|
---|
929 | emitPutVirtualRegister(result);
|
---|
930 | } else {
|
---|
931 | OperandTypes types = OperandTypes::fromInt(currentInstruction[4].u.operand);
|
---|
932 | ASSERT(types.first().mightBeNumber() && types.second().mightBeNumber());
|
---|
933 | compileBinaryArithOpSlowCase(op_add, iter, result, op1, op2, types);
|
---|
934 | }
|
---|
935 | }
|
---|
936 |
|
---|
937 | void JIT::compileFastArith_op_mul(Instruction* currentInstruction)
|
---|
938 | {
|
---|
939 | unsigned result = currentInstruction[1].u.operand;
|
---|
940 | unsigned op1 = currentInstruction[2].u.operand;
|
---|
941 | unsigned op2 = currentInstruction[3].u.operand;
|
---|
942 |
|
---|
943 | // For now, only plant a fast int case if the constant operand is greater than zero.
|
---|
944 | int32_t value;
|
---|
945 | if (isOperandConstantImmediateInt(op1) && ((value = getConstantOperandImmediateInt(op1)) > 0)) {
|
---|
946 | emitGetVirtualRegister(op2, X86::eax);
|
---|
947 | emitJumpSlowCaseIfNotImmediateInteger(X86::eax);
|
---|
948 | emitFastArithDeTagImmediate(X86::eax);
|
---|
949 | addSlowCase(branchMul32(Overflow, Imm32(value), X86::eax, X86::eax));
|
---|
950 | signExtend32ToPtr(X86::eax, X86::eax);
|
---|
951 | emitFastArithReTagImmediate(X86::eax, X86::eax);
|
---|
952 | emitPutVirtualRegister(result);
|
---|
953 | } else if (isOperandConstantImmediateInt(op2) && ((value = getConstantOperandImmediateInt(op2)) > 0)) {
|
---|
954 | emitGetVirtualRegister(op1, X86::eax);
|
---|
955 | emitJumpSlowCaseIfNotImmediateInteger(X86::eax);
|
---|
956 | emitFastArithDeTagImmediate(X86::eax);
|
---|
957 | addSlowCase(branchMul32(Overflow, Imm32(value), X86::eax, X86::eax));
|
---|
958 | signExtend32ToPtr(X86::eax, X86::eax);
|
---|
959 | emitFastArithReTagImmediate(X86::eax, X86::eax);
|
---|
960 | emitPutVirtualRegister(result);
|
---|
961 | } else
|
---|
962 | compileBinaryArithOp(op_mul, result, op1, op2, OperandTypes::fromInt(currentInstruction[4].u.operand));
|
---|
963 | }
|
---|
964 | void JIT::compileFastArithSlow_op_mul(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
|
---|
965 | {
|
---|
966 | unsigned result = currentInstruction[1].u.operand;
|
---|
967 | unsigned op1 = currentInstruction[2].u.operand;
|
---|
968 | unsigned op2 = currentInstruction[3].u.operand;
|
---|
969 |
|
---|
970 | if ((isOperandConstantImmediateInt(op1) && (getConstantOperandImmediateInt(op1) > 0))
|
---|
971 | || (isOperandConstantImmediateInt(op2) && (getConstantOperandImmediateInt(op2) > 0))) {
|
---|
972 | linkSlowCase(iter);
|
---|
973 | linkSlowCase(iter);
|
---|
974 | // There is an extra slow case for (op1 * -N) or (-N * op2), to check for 0 since this should produce a result of -0.
|
---|
975 | emitPutJITStubArgFromVirtualRegister(op1, 1, X86::ecx);
|
---|
976 | emitPutJITStubArgFromVirtualRegister(op2, 2, X86::ecx);
|
---|
977 | emitCTICall(JITStubs::cti_op_mul);
|
---|
978 | emitPutVirtualRegister(result);
|
---|
979 | } else
|
---|
980 | compileBinaryArithOpSlowCase(op_mul, iter, result, op1, op2, OperandTypes::fromInt(currentInstruction[4].u.operand));
|
---|
981 | }
|
---|
982 |
|
---|
983 | void JIT::compileFastArith_op_sub(Instruction* currentInstruction)
|
---|
984 | {
|
---|
985 | compileBinaryArithOp(op_sub, currentInstruction[1].u.operand, currentInstruction[2].u.operand, currentInstruction[3].u.operand, OperandTypes::fromInt(currentInstruction[4].u.operand));
|
---|
986 | }
|
---|
987 | void JIT::compileFastArithSlow_op_sub(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
|
---|
988 | {
|
---|
989 | compileBinaryArithOpSlowCase(op_sub, iter, currentInstruction[1].u.operand, currentInstruction[2].u.operand, currentInstruction[3].u.operand, OperandTypes::fromInt(currentInstruction[4].u.operand));
|
---|
990 | }
|
---|
991 |
|
---|
992 | #endif
|
---|
993 |
|
---|
994 | } // namespace JSC
|
---|
995 |
|
---|
996 | #endif // ENABLE(JIT)
|
---|