0
|
1 /*
|
|
2 * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 *
|
|
5 * This code is free software; you can redistribute it and/or modify it
|
|
6 * under the terms of the GNU General Public License version 2 only, as
|
|
7 * published by the Free Software Foundation.
|
|
8 *
|
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 * version 2 for more details (a copy is included in the LICENSE file that
|
|
13 * accompanied this code).
|
|
14 *
|
|
15 * You should have received a copy of the GNU General Public License version
|
|
16 * 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 *
|
|
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
20 * CA 95054 USA or visit www.sun.com if you need additional information or
|
|
21 * have any questions.
|
|
22 *
|
|
23 */
|
|
24
|
|
25 #include "incls/_precompiled.incl"
|
|
26 #include "incls/_regmask.cpp.incl"
|
|
27
|
|
28 #define RM_SIZE _RM_SIZE /* a constant private to the class RegMask */
|
|
29
|
|
30 //-------------Non-zero bit search methods used by RegMask---------------------
|
|
31 // Find lowest 1, or return 32 if empty
|
|
32 int find_lowest_bit( uint32 mask ) {
|
|
33 int n = 0;
|
|
34 if( (mask & 0xffff) == 0 ) {
|
|
35 mask >>= 16;
|
|
36 n += 16;
|
|
37 }
|
|
38 if( (mask & 0xff) == 0 ) {
|
|
39 mask >>= 8;
|
|
40 n += 8;
|
|
41 }
|
|
42 if( (mask & 0xf) == 0 ) {
|
|
43 mask >>= 4;
|
|
44 n += 4;
|
|
45 }
|
|
46 if( (mask & 0x3) == 0 ) {
|
|
47 mask >>= 2;
|
|
48 n += 2;
|
|
49 }
|
|
50 if( (mask & 0x1) == 0 ) {
|
|
51 mask >>= 1;
|
|
52 n += 1;
|
|
53 }
|
|
54 if( mask == 0 ) {
|
|
55 n = 32;
|
|
56 }
|
|
57 return n;
|
|
58 }
|
|
59
|
|
60 // Find highest 1, or return 32 if empty
|
|
61 int find_hihghest_bit( uint32 mask ) {
|
|
62 int n = 0;
|
|
63 if( mask > 0xffff ) {
|
|
64 mask >>= 16;
|
|
65 n += 16;
|
|
66 }
|
|
67 if( mask > 0xff ) {
|
|
68 mask >>= 8;
|
|
69 n += 8;
|
|
70 }
|
|
71 if( mask > 0xf ) {
|
|
72 mask >>= 4;
|
|
73 n += 4;
|
|
74 }
|
|
75 if( mask > 0x3 ) {
|
|
76 mask >>= 2;
|
|
77 n += 2;
|
|
78 }
|
|
79 if( mask > 0x1 ) {
|
|
80 mask >>= 1;
|
|
81 n += 1;
|
|
82 }
|
|
83 if( mask == 0 ) {
|
|
84 n = 32;
|
|
85 }
|
|
86 return n;
|
|
87 }
|
|
88
|
|
89 //------------------------------dump-------------------------------------------
|
|
90
|
|
91 #ifndef PRODUCT
|
|
92 void OptoReg::dump( int r ) {
|
|
93 switch( r ) {
|
|
94 case Special: tty->print("r---"); break;
|
|
95 case Bad: tty->print("rBAD"); break;
|
|
96 default:
|
|
97 if( r < _last_Mach_Reg ) tty->print(Matcher::regName[r]);
|
|
98 else tty->print("rS%d",r);
|
|
99 break;
|
|
100 }
|
|
101 }
|
|
102 #endif
|
|
103
|
|
104
|
|
105 //=============================================================================
|
|
106 const RegMask RegMask::Empty(
|
|
107 # define BODY(I) 0,
|
|
108 FORALL_BODY
|
|
109 # undef BODY
|
|
110 0
|
|
111 );
|
|
112
|
|
113 //------------------------------find_first_pair--------------------------------
|
|
114 // Find the lowest-numbered register pair in the mask. Return the
|
|
115 // HIGHEST register number in the pair, or BAD if no pairs.
|
|
116 OptoReg::Name RegMask::find_first_pair() const {
|
|
117 VerifyPairs();
|
|
118 for( int i = 0; i < RM_SIZE; i++ ) {
|
|
119 if( _A[i] ) { // Found some bits
|
|
120 int bit = _A[i] & -_A[i]; // Extract low bit
|
|
121 // Convert to bit number, return hi bit in pair
|
|
122 return OptoReg::Name((i<<_LogWordBits)+find_lowest_bit(bit)+1);
|
|
123 }
|
|
124 }
|
|
125 return OptoReg::Bad;
|
|
126 }
|
|
127
|
|
128 //------------------------------ClearToPairs-----------------------------------
|
|
129 // Clear out partial bits; leave only bit pairs
|
|
130 void RegMask::ClearToPairs() {
|
|
131 for( int i = 0; i < RM_SIZE; i++ ) {
|
|
132 int bits = _A[i];
|
|
133 bits &= ((bits & 0x55555555)<<1); // 1 hi-bit set for each pair
|
|
134 bits |= (bits>>1); // Smear 1 hi-bit into a pair
|
|
135 _A[i] = bits;
|
|
136 }
|
|
137 VerifyPairs();
|
|
138 }
|
|
139
|
|
140 //------------------------------SmearToPairs-----------------------------------
|
|
141 // Smear out partial bits; leave only bit pairs
|
|
142 void RegMask::SmearToPairs() {
|
|
143 for( int i = 0; i < RM_SIZE; i++ ) {
|
|
144 int bits = _A[i];
|
|
145 bits |= ((bits & 0x55555555)<<1); // Smear lo bit hi per pair
|
|
146 bits |= ((bits & 0xAAAAAAAA)>>1); // Smear hi bit lo per pair
|
|
147 _A[i] = bits;
|
|
148 }
|
|
149 VerifyPairs();
|
|
150 }
|
|
151
|
|
152 //------------------------------is_aligned_pairs-------------------------------
|
|
153 bool RegMask::is_aligned_Pairs() const {
|
|
154 // Assert that the register mask contains only bit pairs.
|
|
155 for( int i = 0; i < RM_SIZE; i++ ) {
|
|
156 int bits = _A[i];
|
|
157 while( bits ) { // Check bits for pairing
|
|
158 int bit = bits & -bits; // Extract low bit
|
|
159 // Low bit is not odd means its mis-aligned.
|
|
160 if( (bit & 0x55555555) == 0 ) return false;
|
|
161 bits -= bit; // Remove bit from mask
|
|
162 // Check for aligned adjacent bit
|
|
163 if( (bits & (bit<<1)) == 0 ) return false;
|
|
164 bits -= (bit<<1); // Remove other halve of pair
|
|
165 }
|
|
166 }
|
|
167 return true;
|
|
168 }
|
|
169
|
|
170 //------------------------------is_bound1--------------------------------------
|
|
171 // Return TRUE if the mask contains a single bit
|
|
172 int RegMask::is_bound1() const {
|
|
173 if( is_AllStack() ) return false;
|
|
174 int bit = -1; // Set to hold the one bit allowed
|
|
175 for( int i = 0; i < RM_SIZE; i++ ) {
|
|
176 if( _A[i] ) { // Found some bits
|
|
177 if( bit != -1 ) return false; // Already had bits, so fail
|
|
178 bit = _A[i] & -_A[i]; // Extract 1 bit from mask
|
|
179 if( bit != _A[i] ) return false; // Found many bits, so fail
|
|
180 }
|
|
181 }
|
|
182 // True for both the empty mask and for a single bit
|
|
183 return true;
|
|
184 }
|
|
185
|
|
186 //------------------------------is_bound2--------------------------------------
|
|
187 // Return TRUE if the mask contains an adjacent pair of bits and no other bits.
|
|
188 int RegMask::is_bound2() const {
|
|
189 if( is_AllStack() ) return false;
|
|
190
|
|
191 int bit = -1; // Set to hold the one bit allowed
|
|
192 for( int i = 0; i < RM_SIZE; i++ ) {
|
|
193 if( _A[i] ) { // Found some bits
|
|
194 if( bit != -1 ) return false; // Already had bits, so fail
|
|
195 bit = _A[i] & -(_A[i]); // Extract 1 bit from mask
|
|
196 if( (bit << 1) != 0 ) { // Bit pair stays in same word?
|
|
197 if( (bit | (bit<<1)) != _A[i] )
|
|
198 return false; // Require adjacent bit pair and no more bits
|
|
199 } else { // Else its a split-pair case
|
|
200 if( bit != _A[i] ) return false; // Found many bits, so fail
|
|
201 i++; // Skip iteration forward
|
|
202 if( _A[i] != 1 ) return false; // Require 1 lo bit in next word
|
|
203 }
|
|
204 }
|
|
205 }
|
|
206 // True for both the empty mask and for a bit pair
|
|
207 return true;
|
|
208 }
|
|
209
|
|
210 //------------------------------is_UP------------------------------------------
|
|
211 // UP means register only, Register plus stack, or stack only is DOWN
|
|
212 bool RegMask::is_UP() const {
|
|
213 // Quick common case check for DOWN (any stack slot is legal)
|
|
214 if( is_AllStack() )
|
|
215 return false;
|
|
216 // Slower check for any stack bits set (also DOWN)
|
|
217 if( overlap(Matcher::STACK_ONLY_mask) )
|
|
218 return false;
|
|
219 // Not DOWN, so must be UP
|
|
220 return true;
|
|
221 }
|
|
222
|
|
223 //------------------------------Size-------------------------------------------
|
|
224 // Compute size of register mask in bits
|
|
225 uint RegMask::Size() const {
|
|
226 extern uint8 bitsInByte[256];
|
|
227 uint sum = 0;
|
|
228 for( int i = 0; i < RM_SIZE; i++ )
|
|
229 sum +=
|
|
230 bitsInByte[(_A[i]>>24) & 0xff] +
|
|
231 bitsInByte[(_A[i]>>16) & 0xff] +
|
|
232 bitsInByte[(_A[i]>> 8) & 0xff] +
|
|
233 bitsInByte[ _A[i] & 0xff];
|
|
234 return sum;
|
|
235 }
|
|
236
|
|
237 #ifndef PRODUCT
|
|
238 //------------------------------print------------------------------------------
|
|
239 void RegMask::dump( ) const {
|
|
240 tty->print("[");
|
|
241 RegMask rm = *this; // Structure copy into local temp
|
|
242
|
|
243 OptoReg::Name start = rm.find_first_elem(); // Get a register
|
|
244 if( OptoReg::is_valid(start) ) { // Check for empty mask
|
|
245 rm.Remove(start); // Yank from mask
|
|
246 OptoReg::dump(start); // Print register
|
|
247 OptoReg::Name last = start;
|
|
248
|
|
249 // Now I have printed an initial register.
|
|
250 // Print adjacent registers as "rX-rZ" instead of "rX,rY,rZ".
|
|
251 // Begin looping over the remaining registers.
|
|
252 while( 1 ) { //
|
|
253 OptoReg::Name reg = rm.find_first_elem(); // Get a register
|
|
254 if( !OptoReg::is_valid(reg) )
|
|
255 break; // Empty mask, end loop
|
|
256 rm.Remove(reg); // Yank from mask
|
|
257
|
|
258 if( last+1 == reg ) { // See if they are adjacent
|
|
259 // Adjacent registers just collect into long runs, no printing.
|
|
260 last = reg;
|
|
261 } else { // Ending some kind of run
|
|
262 if( start == last ) { // 1-register run; no special printing
|
|
263 } else if( start+1 == last ) {
|
|
264 tty->print(","); // 2-register run; print as "rX,rY"
|
|
265 OptoReg::dump(last);
|
|
266 } else { // Multi-register run; print as "rX-rZ"
|
|
267 tty->print("-");
|
|
268 OptoReg::dump(last);
|
|
269 }
|
|
270 tty->print(","); // Seperate start of new run
|
|
271 start = last = reg; // Start a new register run
|
|
272 OptoReg::dump(start); // Print register
|
|
273 } // End of if ending a register run or not
|
|
274 } // End of while regmask not empty
|
|
275
|
|
276 if( start == last ) { // 1-register run; no special printing
|
|
277 } else if( start+1 == last ) {
|
|
278 tty->print(","); // 2-register run; print as "rX,rY"
|
|
279 OptoReg::dump(last);
|
|
280 } else { // Multi-register run; print as "rX-rZ"
|
|
281 tty->print("-");
|
|
282 OptoReg::dump(last);
|
|
283 }
|
|
284 if( rm.is_AllStack() ) tty->print("...");
|
|
285 }
|
|
286 tty->print("]");
|
|
287 }
|
|
288 #endif
|