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