src/share/vm/opto/regmask.cpp

changeset 3882
8c92982cbbc4
parent 2708
1d1603768966
child 4478
a7114d3d712e
     1.1 --- a/src/share/vm/opto/regmask.cpp	Thu Jun 14 14:59:52 2012 -0700
     1.2 +++ b/src/share/vm/opto/regmask.cpp	Fri Jun 15 01:25:19 2012 -0700
     1.3 @@ -1,5 +1,5 @@
     1.4  /*
     1.5 - * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
     1.6 + * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
     1.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.8   *
     1.9   * This code is free software; you can redistribute it and/or modify it
    1.10 @@ -129,11 +129,34 @@
    1.11    0
    1.12  );
    1.13  
    1.14 +//=============================================================================
    1.15 +bool RegMask::is_vector(uint ireg) {
    1.16 +  return (ireg == Op_VecS || ireg == Op_VecD || ireg == Op_VecX || ireg == Op_VecY);
    1.17 +}
    1.18 +
    1.19 +int RegMask::num_registers(uint ireg) {
    1.20 +    switch(ireg) {
    1.21 +      case Op_VecY:
    1.22 +        return 8;
    1.23 +      case Op_VecX:
    1.24 +        return 4;
    1.25 +      case Op_VecD:
    1.26 +      case Op_RegD:
    1.27 +      case Op_RegL:
    1.28 +#ifdef _LP64
    1.29 +      case Op_RegP:
    1.30 +#endif
    1.31 +        return 2;
    1.32 +    }
    1.33 +    // Op_VecS and the rest ideal registers.
    1.34 +    return 1;
    1.35 +}
    1.36 +
    1.37  //------------------------------find_first_pair--------------------------------
    1.38  // Find the lowest-numbered register pair in the mask.  Return the
    1.39  // HIGHEST register number in the pair, or BAD if no pairs.
    1.40  OptoReg::Name RegMask::find_first_pair() const {
    1.41 -  VerifyPairs();
    1.42 +  verify_pairs();
    1.43    for( int i = 0; i < RM_SIZE; i++ ) {
    1.44      if( _A[i] ) {               // Found some bits
    1.45        int bit = _A[i] & -_A[i]; // Extract low bit
    1.46 @@ -146,30 +169,30 @@
    1.47  
    1.48  //------------------------------ClearToPairs-----------------------------------
    1.49  // Clear out partial bits; leave only bit pairs
    1.50 -void RegMask::ClearToPairs() {
    1.51 +void RegMask::clear_to_pairs() {
    1.52    for( int i = 0; i < RM_SIZE; i++ ) {
    1.53      int bits = _A[i];
    1.54      bits &= ((bits & 0x55555555)<<1); // 1 hi-bit set for each pair
    1.55      bits |= (bits>>1);          // Smear 1 hi-bit into a pair
    1.56      _A[i] = bits;
    1.57    }
    1.58 -  VerifyPairs();
    1.59 +  verify_pairs();
    1.60  }
    1.61  
    1.62  //------------------------------SmearToPairs-----------------------------------
    1.63  // Smear out partial bits; leave only bit pairs
    1.64 -void RegMask::SmearToPairs() {
    1.65 +void RegMask::smear_to_pairs() {
    1.66    for( int i = 0; i < RM_SIZE; i++ ) {
    1.67      int bits = _A[i];
    1.68      bits |= ((bits & 0x55555555)<<1); // Smear lo bit hi per pair
    1.69      bits |= ((bits & 0xAAAAAAAA)>>1); // Smear hi bit lo per pair
    1.70      _A[i] = bits;
    1.71    }
    1.72 -  VerifyPairs();
    1.73 +  verify_pairs();
    1.74  }
    1.75  
    1.76  //------------------------------is_aligned_pairs-------------------------------
    1.77 -bool RegMask::is_aligned_Pairs() const {
    1.78 +bool RegMask::is_aligned_pairs() const {
    1.79    // Assert that the register mask contains only bit pairs.
    1.80    for( int i = 0; i < RM_SIZE; i++ ) {
    1.81      int bits = _A[i];
    1.82 @@ -204,7 +227,7 @@
    1.83  
    1.84  //------------------------------is_bound2--------------------------------------
    1.85  // Return TRUE if the mask contains an adjacent pair of bits and no other bits.
    1.86 -int RegMask::is_bound2() const {
    1.87 +int RegMask::is_bound_pair() const {
    1.88    if( is_AllStack() ) return false;
    1.89  
    1.90    int bit = -1;                 // Set to hold the one bit allowed
    1.91 @@ -226,6 +249,132 @@
    1.92    return true;
    1.93  }
    1.94  
    1.95 +static int low_bits[3] = { 0x55555555, 0x11111111, 0x01010101 };
    1.96 +//------------------------------find_first_set---------------------------------
    1.97 +// Find the lowest-numbered register set in the mask.  Return the
    1.98 +// HIGHEST register number in the set, or BAD if no sets.
    1.99 +// Works also for size 1.
   1.100 +OptoReg::Name RegMask::find_first_set(int size) const {
   1.101 +  verify_sets(size);
   1.102 +  for (int i = 0; i < RM_SIZE; i++) {
   1.103 +    if (_A[i]) {                // Found some bits
   1.104 +      int bit = _A[i] & -_A[i]; // Extract low bit
   1.105 +      // Convert to bit number, return hi bit in pair
   1.106 +      return OptoReg::Name((i<<_LogWordBits)+find_lowest_bit(bit)+(size-1));
   1.107 +    }
   1.108 +  }
   1.109 +  return OptoReg::Bad;
   1.110 +}
   1.111 +
   1.112 +//------------------------------clear_to_sets----------------------------------
   1.113 +// Clear out partial bits; leave only aligned adjacent bit pairs
   1.114 +void RegMask::clear_to_sets(int size) {
   1.115 +  if (size == 1) return;
   1.116 +  assert(2 <= size && size <= 8, "update low bits table");
   1.117 +  assert(is_power_of_2(size), "sanity");
   1.118 +  int low_bits_mask = low_bits[size>>2];
   1.119 +  for (int i = 0; i < RM_SIZE; i++) {
   1.120 +    int bits = _A[i];
   1.121 +    int sets = (bits & low_bits_mask);
   1.122 +    for (int j = 1; j < size; j++) {
   1.123 +      sets = (bits & (sets<<1)); // filter bits which produce whole sets
   1.124 +    }
   1.125 +    sets |= (sets>>1);           // Smear 1 hi-bit into a set
   1.126 +    if (size > 2) {
   1.127 +      sets |= (sets>>2);         // Smear 2 hi-bits into a set
   1.128 +      if (size > 4) {
   1.129 +        sets |= (sets>>4);       // Smear 4 hi-bits into a set
   1.130 +      }
   1.131 +    }
   1.132 +    _A[i] = sets;
   1.133 +  }
   1.134 +  verify_sets(size);
   1.135 +}
   1.136 +
   1.137 +//------------------------------smear_to_sets----------------------------------
   1.138 +// Smear out partial bits to aligned adjacent bit sets
   1.139 +void RegMask::smear_to_sets(int size) {
   1.140 +  if (size == 1) return;
   1.141 +  assert(2 <= size && size <= 8, "update low bits table");
   1.142 +  assert(is_power_of_2(size), "sanity");
   1.143 +  int low_bits_mask = low_bits[size>>2];
   1.144 +  for (int i = 0; i < RM_SIZE; i++) {
   1.145 +    int bits = _A[i];
   1.146 +    int sets = 0;
   1.147 +    for (int j = 0; j < size; j++) {
   1.148 +      sets |= (bits & low_bits_mask);  // collect partial bits
   1.149 +      bits  = bits>>1;
   1.150 +    }
   1.151 +    sets |= (sets<<1);           // Smear 1 lo-bit  into a set
   1.152 +    if (size > 2) {
   1.153 +      sets |= (sets<<2);         // Smear 2 lo-bits into a set
   1.154 +      if (size > 4) {
   1.155 +        sets |= (sets<<4);       // Smear 4 lo-bits into a set
   1.156 +      }
   1.157 +    }
   1.158 +    _A[i] = sets;
   1.159 +  }
   1.160 +  verify_sets(size);
   1.161 +}
   1.162 +
   1.163 +//------------------------------is_aligned_set--------------------------------
   1.164 +bool RegMask::is_aligned_sets(int size) const {
   1.165 +  if (size == 1) return true;
   1.166 +  assert(2 <= size && size <= 8, "update low bits table");
   1.167 +  assert(is_power_of_2(size), "sanity");
   1.168 +  int low_bits_mask = low_bits[size>>2];
   1.169 +  // Assert that the register mask contains only bit sets.
   1.170 +  for (int i = 0; i < RM_SIZE; i++) {
   1.171 +    int bits = _A[i];
   1.172 +    while (bits) {              // Check bits for pairing
   1.173 +      int bit = bits & -bits;   // Extract low bit
   1.174 +      // Low bit is not odd means its mis-aligned.
   1.175 +      if ((bit & low_bits_mask) == 0) return false;
   1.176 +      // Do extra work since (bit << size) may overflow.
   1.177 +      int hi_bit = bit << (size-1); // high bit
   1.178 +      int set = hi_bit + ((hi_bit-1) & ~(bit-1));
   1.179 +      // Check for aligned adjacent bits in this set
   1.180 +      if ((bits & set) != set) return false;
   1.181 +      bits -= set;  // Remove this set
   1.182 +    }
   1.183 +  }
   1.184 +  return true;
   1.185 +}
   1.186 +
   1.187 +//------------------------------is_bound_set-----------------------------------
   1.188 +// Return TRUE if the mask contains one adjacent set of bits and no other bits.
   1.189 +// Works also for size 1.
   1.190 +int RegMask::is_bound_set(int size) const {
   1.191 +  if( is_AllStack() ) return false;
   1.192 +  assert(1 <= size && size <= 8, "update low bits table");
   1.193 +  int bit = -1;                 // Set to hold the one bit allowed
   1.194 +  for (int i = 0; i < RM_SIZE; i++) {
   1.195 +    if (_A[i] ) {               // Found some bits
   1.196 +      if (bit != -1)
   1.197 +       return false;            // Already had bits, so fail
   1.198 +      bit = _A[i] & -_A[i];     // Extract 1 bit from mask
   1.199 +      int hi_bit = bit << (size-1); // high bit
   1.200 +      if (hi_bit != 0) {        // Bit set stays in same word?
   1.201 +        int set = hi_bit + ((hi_bit-1) & ~(bit-1));
   1.202 +        if (set != _A[i])
   1.203 +          return false;         // Require adjacent bit set and no more bits
   1.204 +      } else {                  // Else its a split-set case
   1.205 +        if (((-1) & ~(bit-1)) != _A[i])
   1.206 +          return false;         // Found many bits, so fail
   1.207 +        i++;                    // Skip iteration forward and check high part
   1.208 +        assert(size <= 8, "update next code");
   1.209 +        // The lower 24 bits should be 0 since it is split case and size <= 8.
   1.210 +        int set = bit>>24;
   1.211 +        set = set & -set; // Remove sign extension.
   1.212 +        set = (((set << size) - 1) >> 8);
   1.213 +        if (_A[i] != set) return false; // Require 1 lo bit in next word
   1.214 +      }
   1.215 +    }
   1.216 +  }
   1.217 +  // True for both the empty mask and for a bit set
   1.218 +  return true;
   1.219 +}
   1.220 +
   1.221  //------------------------------is_UP------------------------------------------
   1.222  // UP means register only, Register plus stack, or stack only is DOWN
   1.223  bool RegMask::is_UP() const {

mercurial