hotspot/src/share/vm/opto/regmask.hpp
author trims
Thu, 27 May 2010 19:08:38 -0700
changeset 5547 f4b087cbb361
parent 1 489c9b5090e2
child 7397 5b173b4ca846
permissions -rw-r--r--
6941466: Oracle rebranding changes for Hotspot repositories Summary: Change all the Sun copyrights to Oracle copyright Reviewed-by: ohair
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
     2
 * Copyright (c) 1997, 2006, 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
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
// Some fun naming (textual) substitutions:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
// RegMask::get_low_elem() ==> RegMask::find_first_elem()
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
// RegMask::Special        ==> RegMask::Empty
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
// RegMask::_flags         ==> RegMask::is_AllStack()
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
// RegMask::operator<<=()  ==> RegMask::Insert()
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
// RegMask::operator>>=()  ==> RegMask::Remove()
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
// RegMask::Union()        ==> RegMask::OR
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// RegMask::Inter()        ==> RegMask::AND
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// OptoRegister::RegName   ==> OptoReg::Name
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// OptoReg::stack0()       ==> _last_Mach_Reg  or ZERO in core version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
// numregs in chaitin      ==> proper degree in chaitin
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
//-------------Non-zero bit search methods used by RegMask---------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
// Find lowest 1, or return 32 if empty
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
int find_lowest_bit( uint32 mask );
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
// Find highest 1, or return 32 if empty
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
int find_hihghest_bit( uint32 mask );
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
//------------------------------RegMask----------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
// The ADL file describes how to print the machine-specific registers, as well
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
// as any notion of register classes.  We provide a register mask, which is
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
// just a collection of Register numbers.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
// The ADLC defines 2 macros, RM_SIZE and FORALL_BODY.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
// RM_SIZE is the size of a register mask in words.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
// FORALL_BODY replicates a BODY macro once per word in the register mask.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
// The usage is somewhat clumsy and limited to the regmask.[h,c]pp files.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
// However, it means the ADLC can redefine the unroll macro and all loops
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
// over register masks will be unrolled by the correct amount.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
class RegMask VALUE_OBJ_CLASS_SPEC {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  union {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
    double _dummy_force_double_alignment[RM_SIZE>>1];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
    // Array of Register Mask bits.  This array is large enough to cover
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
    // all the machine registers and all parameters that need to be passed
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
    // on the stack (stack registers) up to some interesting limit.  Methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    // that need more parameters will NOT be compiled.  On Intel, the limit
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
    // is something like 90+ parameters.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
    int _A[RM_SIZE];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  enum {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    _WordBits    = BitsPerInt,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
    _LogWordBits = LogBitsPerInt,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    _RM_SIZE     = RM_SIZE   // local constant, imported, then hidden by #undef
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  enum { CHUNK_SIZE = RM_SIZE*_WordBits };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  // SlotsPerLong is 2, since slots are 32 bits and longs are 64 bits.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  // Also, consider the maximum alignment size for a normally allocated
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  // value.  Since we allocate register pairs but not register quads (at
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  // present), this alignment is SlotsPerLong (== 2).  A normally
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  // aligned allocated register is either a single register, or a pair
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  // of adjacent registers, the lower-numbered being even.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  // See also is_aligned_Pairs() below, and the padding added before
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  // Matcher::_new_SP to keep allocated pairs aligned properly.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  // If we ever go to quad-word allocations, SlotsPerQuad will become
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  // the controlling alignment constraint.  Note that this alignment
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  // requirement is internal to the allocator, and independent of any
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  // particular platform.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  enum { SlotsPerLong = 2 };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  // A constructor only used by the ADLC output.  All mask fields are filled
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  // in directly.  Calls to this look something like RM(1,2,3,4);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  RegMask(
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
#   define BODY(I) int a##I,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
    FORALL_BODY
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
#   undef BODY
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
    int dummy = 0 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
#   define BODY(I) _A[I] = a##I;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    FORALL_BODY
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
#   undef BODY
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  // Handy copying constructor
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  RegMask( RegMask *rm ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
#   define BODY(I) _A[I] = rm->_A[I];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
    FORALL_BODY
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
#   undef BODY
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  // Construct an empty mask
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  RegMask( ) { Clear(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  // Construct a mask with a single bit
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  RegMask( OptoReg::Name reg ) { Clear(); Insert(reg); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  // Check for register being in mask
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  int Member( OptoReg::Name reg ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    assert( reg < CHUNK_SIZE, "" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
    return _A[reg>>_LogWordBits] & (1<<(reg&(_WordBits-1)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  // The last bit in the register mask indicates that the mask should repeat
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  // indefinitely with ONE bits.  Returns TRUE if mask is infinite or
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  // unbounded in size.  Returns FALSE if mask is finite size.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  int is_AllStack() const { return _A[RM_SIZE-1] >> (_WordBits-1); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  // Work around an -xO3 optimization problme in WS6U1. The old way:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  //   void set_AllStack() { _A[RM_SIZE-1] |= (1<<(_WordBits-1)); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  // will cause _A[RM_SIZE-1] to be clobbered, not updated when set_AllStack()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  // follows an Insert() loop, like the one found in init_spill_mask(). Using
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  // Insert() instead works because the index into _A in computed instead of
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  // constant.  See bug 4665841.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  void set_AllStack() { Insert(OptoReg::Name(CHUNK_SIZE-1)); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  // Test for being a not-empty mask.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  int is_NotEmpty( ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
    int tmp = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
#   define BODY(I) tmp |= _A[I];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
    FORALL_BODY
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
#   undef BODY
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
    return tmp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  // Find lowest-numbered register from mask, or BAD if mask is empty.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  OptoReg::Name find_first_elem() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
    int base, bits;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
#   define BODY(I) if( (bits = _A[I]) != 0 ) base = I<<_LogWordBits; else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
    FORALL_BODY
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
#   undef BODY
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
      { base = OptoReg::Bad; bits = 1<<0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
    return OptoReg::Name(base + find_lowest_bit(bits));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  // Get highest-numbered register from mask, or BAD if mask is empty.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  OptoReg::Name find_last_elem() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
    int base, bits;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
#   define BODY(I) if( (bits = _A[RM_SIZE-1-I]) != 0 ) base = (RM_SIZE-1-I)<<_LogWordBits; else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
    FORALL_BODY
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
#   undef BODY
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
      { base = OptoReg::Bad; bits = 1<<0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
    return OptoReg::Name(base + find_hihghest_bit(bits));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  // Find the lowest-numbered register pair in the mask.  Return the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  // HIGHEST register number in the pair, or BAD if no pairs.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  // Assert that the mask contains only bit pairs.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  OptoReg::Name find_first_pair() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  // Clear out partial bits; leave only aligned adjacent bit pairs.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  void ClearToPairs();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  // Smear out partial bits; leave only aligned adjacent bit pairs.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  void SmearToPairs();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  // Verify that the mask contains only aligned adjacent bit pairs
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  void VerifyPairs() const { assert( is_aligned_Pairs(), "mask is not aligned, adjacent pairs" ); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  // Test that the mask contains only aligned adjacent bit pairs
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  bool is_aligned_Pairs() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  // mask is a pair of misaligned registers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  bool is_misaligned_Pair() const { return Size()==2 && !is_aligned_Pairs();}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  // Test for single register
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  int is_bound1() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  // Test for a single adjacent pair
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  int is_bound2() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  // Fast overlap test.  Non-zero if any registers in common.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  int overlap( const RegMask &rm ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
    return
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
#   define BODY(I) (_A[I] & rm._A[I]) |
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
    FORALL_BODY
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
#   undef BODY
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
    0 ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
  // Special test for register pressure based splitting
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  // UP means register only, Register plus stack, or stack only is DOWN
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  bool is_UP() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  // Clear a register mask
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  void Clear( ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
#   define BODY(I) _A[I] = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
    FORALL_BODY
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
#   undef BODY
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  // Fill a register mask with 1's
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  void Set_All( ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
#   define BODY(I) _A[I] = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
    FORALL_BODY
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
#   undef BODY
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  // Insert register into mask
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  void Insert( OptoReg::Name reg ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
    assert( reg < CHUNK_SIZE, "" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
    _A[reg>>_LogWordBits] |= (1<<(reg&(_WordBits-1)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  // Remove register from mask
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  void Remove( OptoReg::Name reg ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
    assert( reg < CHUNK_SIZE, "" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
    _A[reg>>_LogWordBits] &= ~(1<<(reg&(_WordBits-1)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  // OR 'rm' into 'this'
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
  void OR( const RegMask &rm ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
#   define BODY(I) this->_A[I] |= rm._A[I];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
    FORALL_BODY
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
#   undef BODY
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  // AND 'rm' into 'this'
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  void AND( const RegMask &rm ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
#   define BODY(I) this->_A[I] &= rm._A[I];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
    FORALL_BODY
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
#   undef BODY
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  // Subtract 'rm' from 'this'
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
  void SUBTRACT( const RegMask &rm ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
#   define BODY(I) _A[I] &= ~rm._A[I];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
    FORALL_BODY
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
#   undef BODY
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
  // Compute size of register mask: number of bits
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
  uint Size() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  void print() const { dump(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  void dump() const;            // Print a mask
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
  static const RegMask Empty;   // Common empty mask
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
  static bool can_represent(OptoReg::Name reg) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
    // NOTE: -1 in computation reflects the usage of the last
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
    //       bit of the regmask as an infinite stack flag.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
    return (int)reg < (int)(CHUNK_SIZE-1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
// Do not use this constant directly in client code!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
#undef RM_SIZE