1 | /*
|
---|
2 | * Copyright (C) 2015-2019 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 "JITRightShiftGenerator.h"
|
---|
28 |
|
---|
29 | #if ENABLE(JIT)
|
---|
30 |
|
---|
31 | namespace JSC {
|
---|
32 |
|
---|
33 | void JITRightShiftGenerator::generateFastPath(CCallHelpers& jit)
|
---|
34 | {
|
---|
35 | ASSERT(m_scratchGPR != InvalidGPRReg);
|
---|
36 | ASSERT(m_scratchGPR != m_left.payloadGPR());
|
---|
37 | ASSERT(m_scratchGPR != m_right.payloadGPR());
|
---|
38 | #if USE(JSVALUE32_64)
|
---|
39 | ASSERT(m_scratchGPR != m_left.tagGPR());
|
---|
40 | ASSERT(m_scratchGPR != m_right.tagGPR());
|
---|
41 | #endif
|
---|
42 |
|
---|
43 | ASSERT(!m_leftOperand.isConstInt32() || !m_rightOperand.isConstInt32());
|
---|
44 |
|
---|
45 | m_didEmitFastPath = true;
|
---|
46 |
|
---|
47 | if (m_rightOperand.isConstInt32()) {
|
---|
48 | // Try to do (intVar >> intConstant).
|
---|
49 | CCallHelpers::Jump notInt = jit.branchIfNotInt32(m_left);
|
---|
50 |
|
---|
51 | jit.moveValueRegs(m_left, m_result);
|
---|
52 | int32_t shiftAmount = m_rightOperand.asConstInt32() & 0x1f;
|
---|
53 | if (shiftAmount) {
|
---|
54 | if (m_shiftType == SignedShift)
|
---|
55 | jit.rshift32(CCallHelpers::Imm32(shiftAmount), m_result.payloadGPR());
|
---|
56 | else
|
---|
57 | jit.urshift32(CCallHelpers::Imm32(shiftAmount), m_result.payloadGPR());
|
---|
58 | #if USE(JSVALUE64)
|
---|
59 | jit.or64(GPRInfo::numberTagRegister, m_result.payloadGPR());
|
---|
60 | #endif
|
---|
61 | }
|
---|
62 |
|
---|
63 | if (jit.supportsFloatingPointTruncate()) {
|
---|
64 | m_endJumpList.append(jit.jump()); // Terminate the above case before emitting more code.
|
---|
65 |
|
---|
66 | // Try to do (doubleVar >> intConstant).
|
---|
67 | notInt.link(&jit);
|
---|
68 |
|
---|
69 | m_slowPathJumpList.append(jit.branchIfNotNumber(m_left, m_scratchGPR));
|
---|
70 |
|
---|
71 | jit.unboxDoubleNonDestructive(m_left, m_leftFPR, m_scratchGPR);
|
---|
72 | #if CPU(ARM64)
|
---|
73 | if (MacroAssemblerARM64::supportsDoubleToInt32ConversionUsingJavaScriptSemantics())
|
---|
74 | jit.convertDoubleToInt32UsingJavaScriptSemantics(m_leftFPR, m_scratchGPR);
|
---|
75 | else
|
---|
76 | #endif
|
---|
77 | {
|
---|
78 | m_slowPathJumpList.append(jit.branchTruncateDoubleToInt32(m_leftFPR, m_scratchGPR));
|
---|
79 | }
|
---|
80 |
|
---|
81 | if (shiftAmount) {
|
---|
82 | if (m_shiftType == SignedShift)
|
---|
83 | jit.rshift32(CCallHelpers::Imm32(shiftAmount), m_scratchGPR);
|
---|
84 | else
|
---|
85 | jit.urshift32(CCallHelpers::Imm32(shiftAmount), m_scratchGPR);
|
---|
86 | }
|
---|
87 | jit.boxInt32(m_scratchGPR, m_result);
|
---|
88 |
|
---|
89 | } else
|
---|
90 | m_slowPathJumpList.append(notInt);
|
---|
91 |
|
---|
92 | } else {
|
---|
93 | // Try to do (intConstant >> intVar) or (intVar >> intVar).
|
---|
94 | m_slowPathJumpList.append(jit.branchIfNotInt32(m_right));
|
---|
95 |
|
---|
96 | GPRReg rightOperandGPR = m_right.payloadGPR();
|
---|
97 | if (rightOperandGPR == m_result.payloadGPR())
|
---|
98 | rightOperandGPR = m_scratchGPR;
|
---|
99 |
|
---|
100 | CCallHelpers::Jump leftNotInt;
|
---|
101 | if (m_leftOperand.isConstInt32()) {
|
---|
102 | jit.move(m_right.payloadGPR(), rightOperandGPR);
|
---|
103 | #if USE(JSVALUE32_64)
|
---|
104 | jit.move(m_right.tagGPR(), m_result.tagGPR());
|
---|
105 | #endif
|
---|
106 | jit.move(CCallHelpers::Imm32(m_leftOperand.asConstInt32()), m_result.payloadGPR());
|
---|
107 | } else {
|
---|
108 | leftNotInt = jit.branchIfNotInt32(m_left);
|
---|
109 | jit.move(m_right.payloadGPR(), rightOperandGPR);
|
---|
110 | jit.moveValueRegs(m_left, m_result);
|
---|
111 | }
|
---|
112 |
|
---|
113 | if (m_shiftType == SignedShift)
|
---|
114 | jit.rshift32(rightOperandGPR, m_result.payloadGPR());
|
---|
115 | else
|
---|
116 | jit.urshift32(rightOperandGPR, m_result.payloadGPR());
|
---|
117 | #if USE(JSVALUE64)
|
---|
118 | jit.or64(GPRInfo::numberTagRegister, m_result.payloadGPR());
|
---|
119 | #endif
|
---|
120 | if (m_leftOperand.isConstInt32())
|
---|
121 | return;
|
---|
122 |
|
---|
123 | if (jit.supportsFloatingPointTruncate()) {
|
---|
124 | m_endJumpList.append(jit.jump()); // Terminate the above case before emitting more code.
|
---|
125 |
|
---|
126 | // Try to do (doubleVar >> intVar).
|
---|
127 | leftNotInt.link(&jit);
|
---|
128 |
|
---|
129 | m_slowPathJumpList.append(jit.branchIfNotNumber(m_left, m_scratchGPR));
|
---|
130 | jit.unboxDoubleNonDestructive(m_left, m_leftFPR, m_scratchGPR);
|
---|
131 | #if CPU(ARM64)
|
---|
132 | if (MacroAssemblerARM64::supportsDoubleToInt32ConversionUsingJavaScriptSemantics())
|
---|
133 | jit.convertDoubleToInt32UsingJavaScriptSemantics(m_leftFPR, m_scratchGPR);
|
---|
134 | else
|
---|
135 | #endif
|
---|
136 | {
|
---|
137 | m_slowPathJumpList.append(jit.branchTruncateDoubleToInt32(m_leftFPR, m_scratchGPR));
|
---|
138 | }
|
---|
139 |
|
---|
140 | if (m_shiftType == SignedShift)
|
---|
141 | jit.rshift32(m_right.payloadGPR(), m_scratchGPR);
|
---|
142 | else
|
---|
143 | jit.urshift32(m_right.payloadGPR(), m_scratchGPR);
|
---|
144 | jit.boxInt32(m_scratchGPR, m_result);
|
---|
145 |
|
---|
146 | } else
|
---|
147 | m_slowPathJumpList.append(leftNotInt);
|
---|
148 | }
|
---|
149 | }
|
---|
150 |
|
---|
151 | } // namespace JSC
|
---|
152 |
|
---|
153 | #endif // ENABLE(JIT)
|
---|