2 * Copyright (C) 2012 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
26 #ifndef DFGRegisterSet_h
27 #define DFGRegisterSet_h
29 #include <wtf/Platform.h>
33 #include "DFGFPRInfo.h"
34 #include "DFGGPRInfo.h"
35 #include <wtf/Bitmap.h>
37 namespace JSC
{ namespace DFG
{
39 static const unsigned totalNumberOfRegisters
=
40 GPRInfo::numberOfRegisters
+ FPRInfo::numberOfRegisters
;
42 static const unsigned numberOfBytesInRegisterSet
=
43 (totalNumberOfRegisters
+ 7) >> 3;
45 typedef uint8_t RegisterSetPOD
[numberOfBytesInRegisterSet
];
51 for (unsigned i
= numberOfBytesInRegisterSet
; i
--;)
55 RegisterSet(const RegisterSetPOD
& other
)
57 for (unsigned i
= numberOfBytesInRegisterSet
; i
--;)
61 const RegisterSetPOD
& asPOD() const { return m_set
; }
63 void copyInfo(RegisterSetPOD
& other
) const
65 for (unsigned i
= numberOfBytesInRegisterSet
; i
--;)
71 setBit(GPRInfo::toIndex(reg
));
74 void setGPRByIndex(unsigned index
)
76 ASSERT(index
< GPRInfo::numberOfRegisters
);
80 void clear(GPRReg reg
)
82 clearBit(GPRInfo::toIndex(reg
));
85 bool get(GPRReg reg
) const
87 return getBit(GPRInfo::toIndex(reg
));
90 bool getGPRByIndex(unsigned index
) const
92 ASSERT(index
< GPRInfo::numberOfRegisters
);
96 // Return the index'th free GPR.
97 GPRReg
getFreeGPR(unsigned index
= 0) const
99 for (unsigned i
= GPRInfo::numberOfRegisters
; i
--;) {
100 if (!getGPRByIndex(i
) && !index
--)
101 return GPRInfo::toRegister(i
);
103 return InvalidGPRReg
;
108 setBit(GPRInfo::numberOfRegisters
+ FPRInfo::toIndex(reg
));
111 void setFPRByIndex(unsigned index
)
113 ASSERT(index
< FPRInfo::numberOfRegisters
);
114 setBit(GPRInfo::numberOfRegisters
+ index
);
117 void clear(FPRReg reg
)
119 clearBit(GPRInfo::numberOfRegisters
+ FPRInfo::toIndex(reg
));
122 bool get(FPRReg reg
) const
124 return getBit(GPRInfo::numberOfRegisters
+ FPRInfo::toIndex(reg
));
127 bool getFPRByIndex(unsigned index
) const
129 ASSERT(index
< FPRInfo::numberOfRegisters
);
130 return getBit(GPRInfo::numberOfRegisters
+ index
);
133 template<typename BankInfo
>
134 void setByIndex(unsigned index
)
136 set(BankInfo::toRegister(index
));
139 template<typename BankInfo
>
140 bool getByIndex(unsigned index
)
142 return get(BankInfo::toRegister(index
));
145 unsigned numberOfSetGPRs() const
148 for (unsigned i
= GPRInfo::numberOfRegisters
; i
--;) {
156 unsigned numberOfSetFPRs() const
159 for (unsigned i
= FPRInfo::numberOfRegisters
; i
--;) {
160 if (!getBit(GPRInfo::numberOfRegisters
+ i
))
167 unsigned numberOfSetRegisters() const
170 for (unsigned i
= totalNumberOfRegisters
; i
--;) {
179 void setBit(unsigned i
)
181 ASSERT(i
< totalNumberOfRegisters
);
182 m_set
[i
>> 3] |= (1 << (i
& 7));
185 void clearBit(unsigned i
)
187 ASSERT(i
< totalNumberOfRegisters
);
188 m_set
[i
>> 3] &= ~(1 << (i
& 7));
191 bool getBit(unsigned i
) const
193 ASSERT(i
< totalNumberOfRegisters
);
194 return !!(m_set
[i
>> 3] & (1 << (i
& 7)));
197 RegisterSetPOD m_set
;
200 } } // namespace JSC::DFG
202 #else // ENABLE(DFG_JIT) -> so if DFG is disabled
204 namespace JSC
{ namespace DFG
{
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.
210 struct RegisterSetPOD
{ };
212 } } // namespace JSC::DFG
214 #endif // ENABLE(DFG_JIT)
216 #endif // DFGRegisterSet_h