]>
Commit | Line | Data |
---|---|---|
93a37866 A |
1 | /* |
2 | * Copyright (C) 2012 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 | #ifndef DFGRegisterSet_h | |
27 | #define DFGRegisterSet_h | |
28 | ||
29 | #include <wtf/Platform.h> | |
30 | ||
31 | #if ENABLE(DFG_JIT) | |
32 | ||
33 | #include "DFGFPRInfo.h" | |
34 | #include "DFGGPRInfo.h" | |
35 | #include <wtf/Bitmap.h> | |
36 | ||
37 | namespace JSC { namespace DFG { | |
38 | ||
39 | static const unsigned totalNumberOfRegisters = | |
40 | GPRInfo::numberOfRegisters + FPRInfo::numberOfRegisters; | |
41 | ||
42 | static const unsigned numberOfBytesInRegisterSet = | |
43 | (totalNumberOfRegisters + 7) >> 3; | |
44 | ||
45 | typedef uint8_t RegisterSetPOD[numberOfBytesInRegisterSet]; | |
46 | ||
47 | class RegisterSet { | |
48 | public: | |
49 | RegisterSet() | |
50 | { | |
51 | for (unsigned i = numberOfBytesInRegisterSet; i--;) | |
52 | m_set[i] = 0; | |
53 | } | |
54 | ||
55 | RegisterSet(const RegisterSetPOD& other) | |
56 | { | |
57 | for (unsigned i = numberOfBytesInRegisterSet; i--;) | |
58 | m_set[i] = other[i]; | |
59 | } | |
60 | ||
61 | const RegisterSetPOD& asPOD() const { return m_set; } | |
62 | ||
63 | void copyInfo(RegisterSetPOD& other) const | |
64 | { | |
65 | for (unsigned i = numberOfBytesInRegisterSet; i--;) | |
66 | other[i] = m_set[i]; | |
67 | } | |
68 | ||
69 | void set(GPRReg reg) | |
70 | { | |
71 | setBit(GPRInfo::toIndex(reg)); | |
72 | } | |
73 | ||
74 | void setGPRByIndex(unsigned index) | |
75 | { | |
76 | ASSERT(index < GPRInfo::numberOfRegisters); | |
77 | setBit(index); | |
78 | } | |
79 | ||
80 | void clear(GPRReg reg) | |
81 | { | |
82 | clearBit(GPRInfo::toIndex(reg)); | |
83 | } | |
84 | ||
85 | bool get(GPRReg reg) const | |
86 | { | |
87 | return getBit(GPRInfo::toIndex(reg)); | |
88 | } | |
89 | ||
90 | bool getGPRByIndex(unsigned index) const | |
91 | { | |
92 | ASSERT(index < GPRInfo::numberOfRegisters); | |
93 | return getBit(index); | |
94 | } | |
95 | ||
96 | // Return the index'th free GPR. | |
97 | GPRReg getFreeGPR(unsigned index = 0) const | |
98 | { | |
99 | for (unsigned i = GPRInfo::numberOfRegisters; i--;) { | |
100 | if (!getGPRByIndex(i) && !index--) | |
101 | return GPRInfo::toRegister(i); | |
102 | } | |
103 | return InvalidGPRReg; | |
104 | } | |
105 | ||
106 | void set(FPRReg reg) | |
107 | { | |
108 | setBit(GPRInfo::numberOfRegisters + FPRInfo::toIndex(reg)); | |
109 | } | |
110 | ||
111 | void setFPRByIndex(unsigned index) | |
112 | { | |
113 | ASSERT(index < FPRInfo::numberOfRegisters); | |
114 | setBit(GPRInfo::numberOfRegisters + index); | |
115 | } | |
116 | ||
117 | void clear(FPRReg reg) | |
118 | { | |
119 | clearBit(GPRInfo::numberOfRegisters + FPRInfo::toIndex(reg)); | |
120 | } | |
121 | ||
122 | bool get(FPRReg reg) const | |
123 | { | |
124 | return getBit(GPRInfo::numberOfRegisters + FPRInfo::toIndex(reg)); | |
125 | } | |
126 | ||
127 | bool getFPRByIndex(unsigned index) const | |
128 | { | |
129 | ASSERT(index < FPRInfo::numberOfRegisters); | |
130 | return getBit(GPRInfo::numberOfRegisters + index); | |
131 | } | |
132 | ||
133 | template<typename BankInfo> | |
134 | void setByIndex(unsigned index) | |
135 | { | |
136 | set(BankInfo::toRegister(index)); | |
137 | } | |
138 | ||
139 | template<typename BankInfo> | |
140 | bool getByIndex(unsigned index) | |
141 | { | |
142 | return get(BankInfo::toRegister(index)); | |
143 | } | |
144 | ||
145 | unsigned numberOfSetGPRs() const | |
146 | { | |
147 | unsigned result = 0; | |
148 | for (unsigned i = GPRInfo::numberOfRegisters; i--;) { | |
149 | if (!getBit(i)) | |
150 | continue; | |
151 | result++; | |
152 | } | |
153 | return result; | |
154 | } | |
155 | ||
156 | unsigned numberOfSetFPRs() const | |
157 | { | |
158 | unsigned result = 0; | |
159 | for (unsigned i = FPRInfo::numberOfRegisters; i--;) { | |
160 | if (!getBit(GPRInfo::numberOfRegisters + i)) | |
161 | continue; | |
162 | result++; | |
163 | } | |
164 | return result; | |
165 | } | |
166 | ||
167 | unsigned numberOfSetRegisters() const | |
168 | { | |
169 | unsigned result = 0; | |
170 | for (unsigned i = totalNumberOfRegisters; i--;) { | |
171 | if (!getBit(i)) | |
172 | continue; | |
173 | result++; | |
174 | } | |
175 | return result; | |
176 | } | |
177 | ||
178 | private: | |
179 | void setBit(unsigned i) | |
180 | { | |
181 | ASSERT(i < totalNumberOfRegisters); | |
182 | m_set[i >> 3] |= (1 << (i & 7)); | |
183 | } | |
184 | ||
185 | void clearBit(unsigned i) | |
186 | { | |
187 | ASSERT(i < totalNumberOfRegisters); | |
188 | m_set[i >> 3] &= ~(1 << (i & 7)); | |
189 | } | |
190 | ||
191 | bool getBit(unsigned i) const | |
192 | { | |
193 | ASSERT(i < totalNumberOfRegisters); | |
194 | return !!(m_set[i >> 3] & (1 << (i & 7))); | |
195 | } | |
196 | ||
197 | RegisterSetPOD m_set; | |
198 | }; | |
199 | ||
200 | } } // namespace JSC::DFG | |
201 | ||
202 | #else // ENABLE(DFG_JIT) -> so if DFG is disabled | |
203 | ||
204 | namespace JSC { namespace DFG { | |
205 | ||
206 | // Define RegisterSetPOD to something that is a POD, but is otherwise useless, | |
207 | // to make it easier to refer to this type in code that may be compiled when | |
208 | // the DFG is disabled. | |
209 | ||
210 | struct RegisterSetPOD { }; | |
211 | ||
212 | } } // namespace JSC::DFG | |
213 | ||
214 | #endif // ENABLE(DFG_JIT) | |
215 | ||
216 | #endif // DFGRegisterSet_h | |
217 |