2 * Copyright (C) 2012, 2013 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 TempRegisterSet_h
27 #define TempRegisterSet_h
38 class TempRegisterSet
{
45 TempRegisterSet(const RegisterSet
&);
49 setBit(GPRInfo::toIndex(reg
));
52 void set(JSValueRegs regs
)
54 if (regs
.tagGPR() != InvalidGPRReg
)
56 set(regs
.payloadGPR());
59 void setGPRByIndex(unsigned index
)
61 ASSERT(index
< GPRInfo::numberOfRegisters
);
65 void clear(GPRReg reg
)
67 clearBit(GPRInfo::toIndex(reg
));
70 bool get(GPRReg reg
) const
72 return getBit(GPRInfo::toIndex(reg
));
75 bool getGPRByIndex(unsigned index
) const
77 ASSERT(index
< GPRInfo::numberOfRegisters
);
81 // Return the index'th free GPR.
82 GPRReg
getFreeGPR(unsigned index
= 0) const
84 for (unsigned i
= GPRInfo::numberOfRegisters
; i
--;) {
85 if (!getGPRByIndex(i
) && !index
--)
86 return GPRInfo::toRegister(i
);
93 setBit(GPRInfo::numberOfRegisters
+ FPRInfo::toIndex(reg
));
96 void setFPRByIndex(unsigned index
)
98 ASSERT(index
< FPRInfo::numberOfRegisters
);
99 setBit(GPRInfo::numberOfRegisters
+ index
);
102 void clear(FPRReg reg
)
104 clearBit(GPRInfo::numberOfRegisters
+ FPRInfo::toIndex(reg
));
107 bool get(FPRReg reg
) const
109 return getBit(GPRInfo::numberOfRegisters
+ FPRInfo::toIndex(reg
));
112 bool getFPRByIndex(unsigned index
) const
114 ASSERT(index
< FPRInfo::numberOfRegisters
);
115 return getBit(GPRInfo::numberOfRegisters
+ index
);
118 template<typename BankInfo
>
119 void setByIndex(unsigned index
)
121 set(BankInfo::toRegister(index
));
124 template<typename BankInfo
>
125 bool getByIndex(unsigned index
)
127 return get(BankInfo::toRegister(index
));
130 unsigned numberOfSetGPRs() const
133 for (unsigned i
= GPRInfo::numberOfRegisters
; i
--;) {
141 unsigned numberOfSetFPRs() const
144 for (unsigned i
= FPRInfo::numberOfRegisters
; i
--;) {
145 if (!getBit(GPRInfo::numberOfRegisters
+ i
))
152 unsigned numberOfSetRegisters() const
155 for (unsigned i
= totalNumberOfRegisters
; i
--;) {
166 for (unsigned i
= numberOfBytesInTempRegisterSet
; i
--;)
170 void setBit(unsigned i
)
172 ASSERT(i
< totalNumberOfRegisters
);
173 m_set
[i
>> 3] |= (1 << (i
& 7));
176 void clearBit(unsigned i
)
178 ASSERT(i
< totalNumberOfRegisters
);
179 m_set
[i
>> 3] &= ~(1 << (i
& 7));
182 bool getBit(unsigned i
) const
184 ASSERT(i
< totalNumberOfRegisters
);
185 return !!(m_set
[i
>> 3] & (1 << (i
& 7)));
188 static const unsigned totalNumberOfRegisters
=
189 GPRInfo::numberOfRegisters
+ FPRInfo::numberOfRegisters
;
191 static const unsigned numberOfBytesInTempRegisterSet
=
192 (totalNumberOfRegisters
+ 7) >> 3;
194 uint8_t m_set
[numberOfBytesInTempRegisterSet
];
199 #else // ENABLE(JIT) -> so if JIT is disabled
203 // Define TempRegisterSet to something, to make it easier to refer to this type in code that
204 // make be compiled when the JIT is disabled.
206 struct TempRegisterSet
{ };
210 #endif // ENABLE(JIT)
212 #endif // TempRegisterSet_h