src/share/vm/opto/regmask.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File 7119644 Sdiff src/share/vm/opto

src/share/vm/opto/regmask.cpp

Print this page


   1 /*
   2  * Copyright (c) 1997, 2011, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


 112   switch( r ) {
 113   case Special: tty->print("r---");   break;
 114   case Bad:     tty->print("rBAD");   break;
 115   default:
 116     if( r < _last_Mach_Reg ) tty->print(Matcher::regName[r]);
 117     else tty->print("rS%d",r);
 118     break;
 119   }
 120 }
 121 #endif
 122 
 123 
 124 //=============================================================================
 125 const RegMask RegMask::Empty(
 126 # define BODY(I) 0,
 127   FORALL_BODY
 128 # undef BODY
 129   0
 130 );
 131 























 132 //------------------------------find_first_pair--------------------------------
 133 // Find the lowest-numbered register pair in the mask.  Return the
 134 // HIGHEST register number in the pair, or BAD if no pairs.
 135 OptoReg::Name RegMask::find_first_pair() const {
 136   VerifyPairs();
 137   for( int i = 0; i < RM_SIZE; i++ ) {
 138     if( _A[i] ) {               // Found some bits
 139       int bit = _A[i] & -_A[i]; // Extract low bit
 140       // Convert to bit number, return hi bit in pair
 141       return OptoReg::Name((i<<_LogWordBits)+find_lowest_bit(bit)+1);
 142     }
 143   }
 144   return OptoReg::Bad;
 145 }
 146 
 147 //------------------------------ClearToPairs-----------------------------------
 148 // Clear out partial bits; leave only bit pairs
 149 void RegMask::ClearToPairs() {
 150   for( int i = 0; i < RM_SIZE; i++ ) {
 151     int bits = _A[i];
 152     bits &= ((bits & 0x55555555)<<1); // 1 hi-bit set for each pair
 153     bits |= (bits>>1);          // Smear 1 hi-bit into a pair
 154     _A[i] = bits;
 155   }
 156   VerifyPairs();
 157 }
 158 
 159 //------------------------------SmearToPairs-----------------------------------
 160 // Smear out partial bits; leave only bit pairs
 161 void RegMask::SmearToPairs() {
 162   for( int i = 0; i < RM_SIZE; i++ ) {
 163     int bits = _A[i];
 164     bits |= ((bits & 0x55555555)<<1); // Smear lo bit hi per pair
 165     bits |= ((bits & 0xAAAAAAAA)>>1); // Smear hi bit lo per pair
 166     _A[i] = bits;
 167   }
 168   VerifyPairs();
 169 }
 170 
 171 //------------------------------is_aligned_pairs-------------------------------
 172 bool RegMask::is_aligned_Pairs() const {
 173   // Assert that the register mask contains only bit pairs.
 174   for( int i = 0; i < RM_SIZE; i++ ) {
 175     int bits = _A[i];
 176     while( bits ) {             // Check bits for pairing
 177       int bit = bits & -bits;   // Extract low bit
 178       // Low bit is not odd means its mis-aligned.
 179       if( (bit & 0x55555555) == 0 ) return false;
 180       bits -= bit;              // Remove bit from mask
 181       // Check for aligned adjacent bit
 182       if( (bits & (bit<<1)) == 0 ) return false;
 183       bits -= (bit<<1);         // Remove other halve of pair
 184     }
 185   }
 186   return true;
 187 }
 188 
 189 //------------------------------is_bound1--------------------------------------
 190 // Return TRUE if the mask contains a single bit
 191 int RegMask::is_bound1() const {
 192   if( is_AllStack() ) return false;
 193   int bit = -1;                 // Set to hold the one bit allowed
 194   for( int i = 0; i < RM_SIZE; i++ ) {
 195     if( _A[i] ) {               // Found some bits
 196       if( bit != -1 ) return false; // Already had bits, so fail
 197       bit = _A[i] & -_A[i];     // Extract 1 bit from mask
 198       if( bit != _A[i] ) return false; // Found many bits, so fail
 199     }
 200   }
 201   // True for both the empty mask and for a single bit
 202   return true;
 203 }
 204 
 205 //------------------------------is_bound2--------------------------------------
 206 // Return TRUE if the mask contains an adjacent pair of bits and no other bits.
 207 int RegMask::is_bound2() const {
 208   if( is_AllStack() ) return false;
 209 
 210   int bit = -1;                 // Set to hold the one bit allowed
 211   for( int i = 0; i < RM_SIZE; i++ ) {
 212     if( _A[i] ) {               // Found some bits
 213       if( bit != -1 ) return false; // Already had bits, so fail
 214       bit = _A[i] & -(_A[i]);   // Extract 1 bit from mask
 215       if( (bit << 1) != 0 ) {   // Bit pair stays in same word?
 216         if( (bit | (bit<<1)) != _A[i] )
 217           return false;         // Require adjacent bit pair and no more bits
 218       } else {                  // Else its a split-pair case
 219         if( bit != _A[i] ) return false; // Found many bits, so fail
 220         i++;                    // Skip iteration forward
 221         if( _A[i] != 1 ) return false; // Require 1 lo bit in next word
 222       }
 223     }
 224   }
 225   // True for both the empty mask and for a bit pair
 226   return true;
 227 }






























































































































 228 
 229 //------------------------------is_UP------------------------------------------
 230 // UP means register only, Register plus stack, or stack only is DOWN
 231 bool RegMask::is_UP() const {
 232   // Quick common case check for DOWN (any stack slot is legal)
 233   if( is_AllStack() )
 234     return false;
 235   // Slower check for any stack bits set (also DOWN)
 236   if( overlap(Matcher::STACK_ONLY_mask) )
 237     return false;
 238   // Not DOWN, so must be UP
 239   return true;
 240 }
 241 
 242 //------------------------------Size-------------------------------------------
 243 // Compute size of register mask in bits
 244 uint RegMask::Size() const {
 245   extern uint8 bitsInByte[256];
 246   uint sum = 0;
 247   for( int i = 0; i < RM_SIZE; i++ )


   1 /*
   2  * Copyright (c) 1997, 2012, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


 112   switch( r ) {
 113   case Special: tty->print("r---");   break;
 114   case Bad:     tty->print("rBAD");   break;
 115   default:
 116     if( r < _last_Mach_Reg ) tty->print(Matcher::regName[r]);
 117     else tty->print("rS%d",r);
 118     break;
 119   }
 120 }
 121 #endif
 122 
 123 
 124 //=============================================================================
 125 const RegMask RegMask::Empty(
 126 # define BODY(I) 0,
 127   FORALL_BODY
 128 # undef BODY
 129   0
 130 );
 131 
 132 //=============================================================================
 133 bool RegMask::is_vector(uint ireg) {
 134   return (ireg == Op_VecS || ireg == Op_VecD || ireg == Op_VecX || ireg == Op_VecY);
 135 }
 136 
 137 int RegMask::num_registers(uint ireg) {
 138     switch(ireg) {
 139       case Op_VecY:
 140         return 8;
 141       case Op_VecX:
 142         return 4;
 143       case Op_VecD:
 144       case Op_RegD:
 145       case Op_RegL:
 146 #ifdef _LP64
 147       case Op_RegP:
 148 #endif
 149         return 2;
 150     }
 151     // Op_VecS and the rest ideal registers.
 152     return 1;
 153 }
 154 
 155 //------------------------------find_first_pair--------------------------------
 156 // Find the lowest-numbered register pair in the mask.  Return the
 157 // HIGHEST register number in the pair, or BAD if no pairs.
 158 OptoReg::Name RegMask::find_first_pair() const {
 159   verify_pairs();
 160   for( int i = 0; i < RM_SIZE; i++ ) {
 161     if( _A[i] ) {               // Found some bits
 162       int bit = _A[i] & -_A[i]; // Extract low bit
 163       // Convert to bit number, return hi bit in pair
 164       return OptoReg::Name((i<<_LogWordBits)+find_lowest_bit(bit)+1);
 165     }
 166   }
 167   return OptoReg::Bad;
 168 }
 169 
 170 //------------------------------ClearToPairs-----------------------------------
 171 // Clear out partial bits; leave only bit pairs
 172 void RegMask::clear_to_pairs() {
 173   for( int i = 0; i < RM_SIZE; i++ ) {
 174     int bits = _A[i];
 175     bits &= ((bits & 0x55555555)<<1); // 1 hi-bit set for each pair
 176     bits |= (bits>>1);          // Smear 1 hi-bit into a pair
 177     _A[i] = bits;
 178   }
 179   verify_pairs();
 180 }
 181 
 182 //------------------------------SmearToPairs-----------------------------------
 183 // Smear out partial bits; leave only bit pairs
 184 void RegMask::smear_to_pairs() {
 185   for( int i = 0; i < RM_SIZE; i++ ) {
 186     int bits = _A[i];
 187     bits |= ((bits & 0x55555555)<<1); // Smear lo bit hi per pair
 188     bits |= ((bits & 0xAAAAAAAA)>>1); // Smear hi bit lo per pair
 189     _A[i] = bits;
 190   }
 191   verify_pairs();
 192 }
 193 
 194 //------------------------------is_aligned_pairs-------------------------------
 195 bool RegMask::is_aligned_pairs() const {
 196   // Assert that the register mask contains only bit pairs.
 197   for( int i = 0; i < RM_SIZE; i++ ) {
 198     int bits = _A[i];
 199     while( bits ) {             // Check bits for pairing
 200       int bit = bits & -bits;   // Extract low bit
 201       // Low bit is not odd means its mis-aligned.
 202       if( (bit & 0x55555555) == 0 ) return false;
 203       bits -= bit;              // Remove bit from mask
 204       // Check for aligned adjacent bit
 205       if( (bits & (bit<<1)) == 0 ) return false;
 206       bits -= (bit<<1);         // Remove other halve of pair
 207     }
 208   }
 209   return true;
 210 }
 211 
 212 //------------------------------is_bound1--------------------------------------
 213 // Return TRUE if the mask contains a single bit
 214 int RegMask::is_bound1() const {
 215   if( is_AllStack() ) return false;
 216   int bit = -1;                 // Set to hold the one bit allowed
 217   for( int i = 0; i < RM_SIZE; i++ ) {
 218     if( _A[i] ) {               // Found some bits
 219       if( bit != -1 ) return false; // Already had bits, so fail
 220       bit = _A[i] & -_A[i];     // Extract 1 bit from mask
 221       if( bit != _A[i] ) return false; // Found many bits, so fail
 222     }
 223   }
 224   // True for both the empty mask and for a single bit
 225   return true;
 226 }
 227 
 228 //------------------------------is_bound2--------------------------------------
 229 // Return TRUE if the mask contains an adjacent pair of bits and no other bits.
 230 int RegMask::is_bound_pair() const {
 231   if( is_AllStack() ) return false;
 232 
 233   int bit = -1;                 // Set to hold the one bit allowed
 234   for( int i = 0; i < RM_SIZE; i++ ) {
 235     if( _A[i] ) {               // Found some bits
 236       if( bit != -1 ) return false; // Already had bits, so fail
 237       bit = _A[i] & -(_A[i]);   // Extract 1 bit from mask
 238       if( (bit << 1) != 0 ) {   // Bit pair stays in same word?
 239         if( (bit | (bit<<1)) != _A[i] )
 240           return false;         // Require adjacent bit pair and no more bits
 241       } else {                  // Else its a split-pair case
 242         if( bit != _A[i] ) return false; // Found many bits, so fail
 243         i++;                    // Skip iteration forward
 244         if( _A[i] != 1 ) return false; // Require 1 lo bit in next word
 245       }
 246     }
 247   }
 248   // True for both the empty mask and for a bit pair
 249   return true;
 250 }
 251 
 252 static int low_bits[3] = { 0x55555555, 0x11111111, 0x01010101 };
 253 //------------------------------find_first_set---------------------------------
 254 // Find the lowest-numbered register set in the mask.  Return the
 255 // HIGHEST register number in the set, or BAD if no sets.
 256 // Works also for size 1.
 257 OptoReg::Name RegMask::find_first_set(int size) const {
 258   verify_sets(size);
 259   for (int i = 0; i < RM_SIZE; i++) {
 260     if (_A[i]) {                // Found some bits
 261       int bit = _A[i] & -_A[i]; // Extract low bit
 262       // Convert to bit number, return hi bit in pair
 263       return OptoReg::Name((i<<_LogWordBits)+find_lowest_bit(bit)+(size-1));
 264     }
 265   }
 266   return OptoReg::Bad;
 267 }
 268 
 269 //------------------------------clear_to_sets----------------------------------
 270 // Clear out partial bits; leave only aligned adjacent bit pairs
 271 void RegMask::clear_to_sets(int size) {
 272   if (size == 1) return;
 273   assert(2 <= size && size <= 8, "update low bits table");
 274   assert(is_power_of_2(size), "sanity");
 275   int low_bits_mask = low_bits[size>>2];
 276   for (int i = 0; i < RM_SIZE; i++) {
 277     int bits = _A[i];
 278     int sets = (bits & low_bits_mask);
 279     for (int j = 1; j < size; j++) {
 280       sets = (bits & (sets<<1)); // filter bits which produce whole sets
 281     }
 282     sets |= (sets>>1);           // Smear 1 hi-bit into a set
 283     if (size > 2) {
 284       sets |= (sets>>2);         // Smear 2 hi-bits into a set
 285       if (size > 4) {
 286         sets |= (sets>>4);       // Smear 4 hi-bits into a set
 287       }
 288     }
 289     _A[i] = sets;
 290   }
 291   verify_sets(size);
 292 }
 293 
 294 //------------------------------smear_to_sets----------------------------------
 295 // Smear out partial bits to aligned adjacent bit sets
 296 void RegMask::smear_to_sets(int size) {
 297   if (size == 1) return;
 298   assert(2 <= size && size <= 8, "update low bits table");
 299   assert(is_power_of_2(size), "sanity");
 300   int low_bits_mask = low_bits[size>>2];
 301   for (int i = 0; i < RM_SIZE; i++) {
 302     int bits = _A[i];
 303     int sets = 0;
 304     for (int j = 0; j < size; j++) {
 305       sets |= (bits & low_bits_mask);  // collect partial bits
 306       bits  = bits>>1;
 307     }
 308     sets |= (sets<<1);           // Smear 1 lo-bit  into a set
 309     if (size > 2) {
 310       sets |= (sets<<2);         // Smear 2 lo-bits into a set
 311       if (size > 4) {
 312         sets |= (sets<<4);       // Smear 4 lo-bits into a set
 313       }
 314     }
 315     _A[i] = sets;
 316   }
 317   verify_sets(size);
 318 }
 319 
 320 //------------------------------is_aligned_set--------------------------------
 321 bool RegMask::is_aligned_sets(int size) const {
 322   if (size == 1) return true;
 323   assert(2 <= size && size <= 8, "update low bits table");
 324   assert(is_power_of_2(size), "sanity");
 325   int low_bits_mask = low_bits[size>>2];
 326   // Assert that the register mask contains only bit sets.
 327   for (int i = 0; i < RM_SIZE; i++) {
 328     int bits = _A[i];
 329     while (bits) {              // Check bits for pairing
 330       int bit = bits & -bits;   // Extract low bit
 331       // Low bit is not odd means its mis-aligned.
 332       if ((bit & low_bits_mask) == 0) return false;
 333       // Do extra work since (bit << size) may overflow.
 334       int hi_bit = bit << (size-1); // high bit
 335       int set = hi_bit + ((hi_bit-1) & ~(bit-1));
 336       // Check for aligned adjacent bits in this set
 337       if ((bits & set) != set) return false;
 338       bits -= set;  // Remove this set
 339     }
 340   }
 341   return true;
 342 }
 343 
 344 //------------------------------is_bound_set-----------------------------------
 345 // Return TRUE if the mask contains one adjacent set of bits and no other bits.
 346 // Works also for size 1.
 347 int RegMask::is_bound_set(int size) const {
 348   if( is_AllStack() ) return false;
 349   assert(1 <= size && size <= 8, "update low bits table");
 350   int bit = -1;                 // Set to hold the one bit allowed
 351   for (int i = 0; i < RM_SIZE; i++) {
 352     if (_A[i] ) {               // Found some bits
 353       if (bit != -1)
 354        return false;            // Already had bits, so fail
 355       bit = _A[i] & -_A[i];     // Extract 1 bit from mask
 356       int hi_bit = bit << (size-1); // high bit
 357       if (hi_bit != 0) {        // Bit set stays in same word?
 358         int set = hi_bit + ((hi_bit-1) & ~(bit-1));      
 359         if (set != _A[i])
 360           return false;         // Require adjacent bit set and no more bits
 361       } else {                  // Else its a split-set case
 362         if (((-1) & ~(bit-1)) != _A[i])
 363           return false;         // Found many bits, so fail
 364         i++;                    // Skip iteration forward and check high part
 365         assert(size <= 8, "update next code");
 366         // The lower 24 bits should be 0 since it is split case and size <= 8.
 367         int set = bit>>24;
 368         set = set & -set; // Remove sign extension.
 369         set = (((set << size) - 1) >> 8);
 370         if (_A[i] != set) return false; // Require 1 lo bit in next word
 371       }
 372     }
 373   }
 374   // True for both the empty mask and for a bit set
 375   return true;
 376 }
 377 
 378 //------------------------------is_UP------------------------------------------
 379 // UP means register only, Register plus stack, or stack only is DOWN
 380 bool RegMask::is_UP() const {
 381   // Quick common case check for DOWN (any stack slot is legal)
 382   if( is_AllStack() )
 383     return false;
 384   // Slower check for any stack bits set (also DOWN)
 385   if( overlap(Matcher::STACK_ONLY_mask) )
 386     return false;
 387   // Not DOWN, so must be UP
 388   return true;
 389 }
 390 
 391 //------------------------------Size-------------------------------------------
 392 // Compute size of register mask in bits
 393 uint RegMask::Size() const {
 394   extern uint8 bitsInByte[256];
 395   uint sum = 0;
 396   for( int i = 0; i < RM_SIZE; i++ )


src/share/vm/opto/regmask.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File