hotspot/src/share/vm/libadt/vectset.cpp
author ascarpino
Wed, 19 Oct 2016 10:49:52 -0700
changeset 41589 e638cce63968
parent 38022 342a29d198d8
permissions -rw-r--r--
8167591: Add MD5 to signed JAR restrictions Reviewed-by: mullan, jnimeh
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
13963
e5b53c306fb5 7197424: update copyright year to match last edit in jdk8 hotspot repository
mikael
parents: 13195
diff changeset
     2
 * Copyright (c) 1997, 2012, 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 "libadt/vectset.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
#include "memory/allocation.inline.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
// Vector Sets - An Abstract Data Type
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
// BitsInByte is a lookup table which tells the number of bits that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
// are in the looked-up number.  It is very useful in VectorSet_Size.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
38022
342a29d198d8 8149488: Incorrect declaration of bitsInByte in regmask.cpp.
rraghavan
parents: 24425
diff changeset
    34
uint8_t bitsInByte[BITS_IN_BYTE_ARRAY_SIZE] = {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
//------------------------------VectorSet--------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
// Create a new, empty Set.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
VectorSet::VectorSet(Arena *arena) : Set(arena) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  size = 2;                     // Small initial size
24425
53764d2358f9 8041415: remove port.{cpp,hpp} files
zgu
parents: 13963
diff changeset
    57
  data = (uint32_t *)_set_arena->Amalloc(size*sizeof(uint32_t));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  data[0] = 0;                  // No elements
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  data[1] = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
//------------------------------Construct--------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
Set &VectorSet_Construct(Arena *arena)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  return *(new VectorSet(arena));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
//------------------------------operator=--------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
Set &VectorSet::operator = (const Set &set)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  if( &set == this ) return *this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  FREE_FAST(data);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  // The cast is a virtual function that checks that "set" is a VectorSet.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  slamin(*(set.asVectorSet()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  return *this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
//------------------------------slamin-----------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
// Initialize one set with another.  No regard is made to the existing Set.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
void VectorSet::slamin(const VectorSet& s)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  size = s.size;                // Use new size
24425
53764d2358f9 8041415: remove port.{cpp,hpp} files
zgu
parents: 13963
diff changeset
    83
  data = (uint32_t*)s._set_arena->Amalloc(size*sizeof(uint32_t)); // Make array of required size
53764d2358f9 8041415: remove port.{cpp,hpp} files
zgu
parents: 13963
diff changeset
    84
  memcpy( data, s.data, size*sizeof(uint32_t) ); // Fill the array
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
//------------------------------grow-------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
// Expand the existing set to a bigger size
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
void VectorSet::grow( uint newsize )
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  newsize = (newsize+31) >> 5;  // Convert to longwords
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  uint x = size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  while( x < newsize ) x <<= 1;
24425
53764d2358f9 8041415: remove port.{cpp,hpp} files
zgu
parents: 13963
diff changeset
    94
  data = (uint32_t *)_set_arena->Arealloc(data, size*sizeof(uint32_t), x*sizeof(uint32_t));
53764d2358f9 8041415: remove port.{cpp,hpp} files
zgu
parents: 13963
diff changeset
    95
  memset((char *)(data + size), 0, (x - size)*sizeof(uint32_t));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  size = x;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
//------------------------------operator<<=------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
// Insert a member into an existing Set.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
Set &VectorSet::operator <<= (uint elem)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  register uint word = elem >> 5;            // Get the longword offset
24425
53764d2358f9 8041415: remove port.{cpp,hpp} files
zgu
parents: 13963
diff changeset
   104
  register uint32_t mask = 1L << (elem & 31);  // Get bit mask
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  if( word >= size )            // Need to grow set?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    grow(elem+1);               // Then grow it
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  data[word] |= mask;           // Set new bit
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  return *this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
//------------------------------operator>>=------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
// Delete a member from an existing Set.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
Set &VectorSet::operator >>= (uint elem)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  register uint word = elem >> 5; // Get the longword offset
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  if( word >= size )              // Beyond the last?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
    return *this;                 // Then it's clear & return clear
24425
53764d2358f9 8041415: remove port.{cpp,hpp} files
zgu
parents: 13963
diff changeset
   119
  register uint32_t mask = 1L << (elem & 31);     // Get bit mask
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  data[word] &= ~mask;            // Clear bit
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  return *this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
//------------------------------operator&=-------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
// Intersect one set into another.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
VectorSet &VectorSet::operator &= (const VectorSet &s)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  // NOTE: The intersection is never any larger than the smallest set.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  if( s.size < size ) size = s.size; // Get smaller size
24425
53764d2358f9 8041415: remove port.{cpp,hpp} files
zgu
parents: 13963
diff changeset
   130
  register uint32_t *u1 = data;   // Pointer to the destination data
53764d2358f9 8041415: remove port.{cpp,hpp} files
zgu
parents: 13963
diff changeset
   131
  register uint32_t *u2 = s.data; // Pointer to the source data
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  for( uint i=0; i<size; i++)   // For data in set
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
    *u1++ &= *u2++;             // Copy and AND longwords
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  return *this;                 // Return set
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
//------------------------------operator&=-------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
Set &VectorSet::operator &= (const Set &set)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  // The cast is a virtual function that checks that "set" is a VectorSet.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  return (*this) &= *(set.asVectorSet());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
//------------------------------operator|=-------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
// Union one set into another.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
VectorSet &VectorSet::operator |= (const VectorSet &s)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  // This many words must be unioned
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  register uint cnt = ((size<s.size)?size:s.size);
24425
53764d2358f9 8041415: remove port.{cpp,hpp} files
zgu
parents: 13963
diff changeset
   150
  register uint32_t *u1 = data;   // Pointer to the destination data
53764d2358f9 8041415: remove port.{cpp,hpp} files
zgu
parents: 13963
diff changeset
   151
  register uint32_t *u2 = s.data; // Pointer to the source data
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  for( uint i=0; i<cnt; i++)    // Copy and OR the two sets
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
    *u1++ |= *u2++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  if( size < s.size ) {         // Is set 2 larger than set 1?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
    // Extend result by larger set
24425
53764d2358f9 8041415: remove port.{cpp,hpp} files
zgu
parents: 13963
diff changeset
   156
    grow(s.size*sizeof(uint32_t)*8);
53764d2358f9 8041415: remove port.{cpp,hpp} files
zgu
parents: 13963
diff changeset
   157
    memcpy(&data[cnt], u2, (s.size - cnt)*sizeof(uint32_t));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  return *this;                 // Return result set
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
//------------------------------operator|=-------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
Set &VectorSet::operator |= (const Set &set)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  // The cast is a virtual function that checks that "set" is a VectorSet.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  return (*this) |= *(set.asVectorSet());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
//------------------------------operator-=-------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
// Difference one set from another.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
VectorSet &VectorSet::operator -= (const VectorSet &s)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  // This many words must be unioned
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  register uint cnt = ((size<s.size)?size:s.size);
24425
53764d2358f9 8041415: remove port.{cpp,hpp} files
zgu
parents: 13963
diff changeset
   175
  register uint32_t *u1 = data;   // Pointer to the destination data
53764d2358f9 8041415: remove port.{cpp,hpp} files
zgu
parents: 13963
diff changeset
   176
  register uint32_t *u2 = s.data; // Pointer to the source data
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  for( uint i=0; i<cnt; i++ )   // For data in set
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
    *u1++ &= ~(*u2++);          // A <-- A & ~B  with longwords
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  return *this;                 // Return new set
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
//------------------------------operator-=-------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
Set &VectorSet::operator -= (const Set &set)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  // The cast is a virtual function that checks that "set" is a VectorSet.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  return (*this) -= *(set.asVectorSet());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
//------------------------------compare----------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
// Compute 2 booleans: bits in A not B, bits in B not A.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
// Return X0 --  A is not a subset of B
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
//        X1 --  A is a subset of B
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
//        0X --  B is not a subset of A
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
//        1X --  B is a subset of A
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
int VectorSet::compare (const VectorSet &s) const
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
{
24425
53764d2358f9 8041415: remove port.{cpp,hpp} files
zgu
parents: 13963
diff changeset
   197
  register uint32_t *u1 = data;   // Pointer to the destination data
53764d2358f9 8041415: remove port.{cpp,hpp} files
zgu
parents: 13963
diff changeset
   198
  register uint32_t *u2 = s.data; // Pointer to the source data
53764d2358f9 8041415: remove port.{cpp,hpp} files
zgu
parents: 13963
diff changeset
   199
  register uint32_t AnotB = 0, BnotA = 0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  // This many words must be unioned
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  register uint cnt = ((size<s.size)?size:s.size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  // Get bits for both sets
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  uint i;                       // Exit value of loop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  for( i=0; i<cnt; i++ ) {      // For data in BOTH sets
24425
53764d2358f9 8041415: remove port.{cpp,hpp} files
zgu
parents: 13963
diff changeset
   206
    register uint32_t A = *u1++;  // Data from one guy
53764d2358f9 8041415: remove port.{cpp,hpp} files
zgu
parents: 13963
diff changeset
   207
    register uint32_t B = *u2++;  // Data from other guy
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
    AnotB |= (A & ~B);          // Compute bits in A not B
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
    BnotA |= (B & ~A);          // Compute bits in B not A
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  // Get bits from bigger set
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  if( size < s.size ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
    for( ; i<s.size; i++ )      // For data in larger set
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
      BnotA |= *u2++;           // These bits are in B not A
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
    for( ; i<size; i++ )        // For data in larger set
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
      AnotB |= *u1++;           // These bits are in A not B
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  // Set & return boolean flags
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  return ((!BnotA)<<1) + (!AnotB);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
//------------------------------operator==-------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
// Test for set equality
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
int VectorSet::operator == (const VectorSet &s) const
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  return compare(s) == 3;       // TRUE if A and B are mutual subsets
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
//------------------------------operator==-------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
int VectorSet::operator == (const Set &set) const
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
  // The cast is a virtual function that checks that "set" is a VectorSet.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
  return (*this) == *(set.asVectorSet());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
//------------------------------disjoint---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
// Check for sets being disjoint.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
int VectorSet::disjoint(const Set &set) const
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  // The cast is a virtual function that checks that "set" is a VectorSet.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  const VectorSet &s = *(set.asVectorSet());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
  // NOTE: The intersection is never any larger than the smallest set.
7408
c04a5c989f26 7003125: precompiled.hpp is included when precompiled headers are not used
stefank
parents: 7397
diff changeset
   247
  register uint small_size = ((size<s.size)?size:s.size);
24425
53764d2358f9 8041415: remove port.{cpp,hpp} files
zgu
parents: 13963
diff changeset
   248
  register uint32_t *u1 = data;        // Pointer to the destination data
53764d2358f9 8041415: remove port.{cpp,hpp} files
zgu
parents: 13963
diff changeset
   249
  register uint32_t *u2 = s.data;      // Pointer to the source data
7408
c04a5c989f26 7003125: precompiled.hpp is included when precompiled headers are not used
stefank
parents: 7397
diff changeset
   250
  for( uint i=0; i<small_size; i++)  // For data in set
c04a5c989f26 7003125: precompiled.hpp is included when precompiled headers are not used
stefank
parents: 7397
diff changeset
   251
    if( *u1++ & *u2++ )              // If any elements in common
c04a5c989f26 7003125: precompiled.hpp is included when precompiled headers are not used
stefank
parents: 7397
diff changeset
   252
      return 0;                      // Then not disjoint
c04a5c989f26 7003125: precompiled.hpp is included when precompiled headers are not used
stefank
parents: 7397
diff changeset
   253
  return 1;                          // Else disjoint
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
//------------------------------operator<--------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
// Test for strict subset
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
int VectorSet::operator < (const VectorSet &s) const
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
  return compare(s) == 1;       // A subset B, B not subset A
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
//------------------------------operator<--------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
int VectorSet::operator < (const Set &set) const
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
  // The cast is a virtual function that checks that "set" is a VectorSet.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
  return (*this) < *(set.asVectorSet());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
//------------------------------operator<=-------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
// Test for subset
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
int VectorSet::operator <= (const VectorSet &s) const
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
  return compare(s) & 1;        // A subset B
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
//------------------------------operator<=-------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
int VectorSet::operator <= (const Set &set) const
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
  // The cast is a virtual function that checks that "set" is a VectorSet.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
  return (*this) <= *(set.asVectorSet());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
//------------------------------operator[]-------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
// Test for membership.  A Zero/Non-Zero value is returned!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
int VectorSet::operator[](uint elem) const
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
  register uint word = elem >> 5; // Get the longword offset
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
  if( word >= size )              // Beyond the last?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
    return 0;                     // Then it's clear
24425
53764d2358f9 8041415: remove port.{cpp,hpp} files
zgu
parents: 13963
diff changeset
   291
  register uint32_t mask = 1L << (elem & 31);  // Get bit mask
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
  return ((data[word] & mask))!=0;           // Return the sense of the bit
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
//------------------------------getelem----------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
// Get any element from the set.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
uint VectorSet::getelem(void) const
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
  uint i;                       // Exit value of loop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
  for( i=0; i<size; i++ )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
    if( data[i] )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
      break;
24425
53764d2358f9 8041415: remove port.{cpp,hpp} files
zgu
parents: 13963
diff changeset
   303
  uint32_t word = data[i];
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
  int j;                        // Exit value of loop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
  for( j= -1; word; j++, word>>=1 );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
  return (i<<5)+j;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
//------------------------------Clear------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
// Clear a set
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
void VectorSet::Clear(void)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
  if( size > 100 ) {            // Reclaim storage only if huge
24425
53764d2358f9 8041415: remove port.{cpp,hpp} files
zgu
parents: 13963
diff changeset
   314
    FREE_RESOURCE_ARRAY(uint32_t,data,size);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
    size = 2;                   // Small initial size
24425
53764d2358f9 8041415: remove port.{cpp,hpp} files
zgu
parents: 13963
diff changeset
   316
    data = NEW_RESOURCE_ARRAY(uint32_t,size);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
  }
24425
53764d2358f9 8041415: remove port.{cpp,hpp} files
zgu
parents: 13963
diff changeset
   318
  memset( data, 0, size*sizeof(uint32_t) );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
//------------------------------Size-------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
// Return number of elements in a Set
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
uint VectorSet::Size(void) const
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
  uint sum = 0;                 // Cumulative size so far.
24425
53764d2358f9 8041415: remove port.{cpp,hpp} files
zgu
parents: 13963
diff changeset
   326
  uint8_t* currByte = (uint8_t*) data;
53764d2358f9 8041415: remove port.{cpp,hpp} files
zgu
parents: 13963
diff changeset
   327
  for( uint32_t i = 0; i < (size<<2); i++) // While have bytes to process
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
    sum += bitsInByte[*currByte++];      // Add bits in current byte to size.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
  return sum;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
//------------------------------Sort-------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
// Sort the elements for the next forall statement
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
void VectorSet::Sort(void)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
//------------------------------hash-------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
int VectorSet::hash() const
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
{
24425
53764d2358f9 8041415: remove port.{cpp,hpp} files
zgu
parents: 13963
diff changeset
   341
  uint32_t _xor = 0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
  uint lim = ((size<4)?size:4);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
  for( uint i = 0; i < lim; i++ )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
    _xor ^= data[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
  return (int)_xor;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
10975
446510be531a 7105611: Set::print() is broken
kvn
parents: 8319
diff changeset
   348
//------------------------------iterate----------------------------------------
446510be531a 7105611: Set::print() is broken
kvn
parents: 8319
diff changeset
   349
// Used by Set::print().
446510be531a 7105611: Set::print() is broken
kvn
parents: 8319
diff changeset
   350
class VSetI_ : public SetI_ {
446510be531a 7105611: Set::print() is broken
kvn
parents: 8319
diff changeset
   351
  VectorSetI vsi;
446510be531a 7105611: Set::print() is broken
kvn
parents: 8319
diff changeset
   352
public:
446510be531a 7105611: Set::print() is broken
kvn
parents: 8319
diff changeset
   353
  VSetI_( const VectorSet *vset, uint &elem ) : vsi(vset) { elem = vsi.elem; }
446510be531a 7105611: Set::print() is broken
kvn
parents: 8319
diff changeset
   354
446510be531a 7105611: Set::print() is broken
kvn
parents: 8319
diff changeset
   355
  uint next(void) { ++vsi; return vsi.elem; }
446510be531a 7105611: Set::print() is broken
kvn
parents: 8319
diff changeset
   356
  int  test(void) { return vsi.test(); }
446510be531a 7105611: Set::print() is broken
kvn
parents: 8319
diff changeset
   357
};
446510be531a 7105611: Set::print() is broken
kvn
parents: 8319
diff changeset
   358
446510be531a 7105611: Set::print() is broken
kvn
parents: 8319
diff changeset
   359
SetI_ *VectorSet::iterate(uint &elem) const {
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 10975
diff changeset
   360
  return new(ResourceObj::C_HEAP, mtInternal) VSetI_(this, elem);
10975
446510be531a 7105611: Set::print() is broken
kvn
parents: 8319
diff changeset
   361
}
446510be531a 7105611: Set::print() is broken
kvn
parents: 8319
diff changeset
   362
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
//------------------------------next-------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
// Find and return the next element of a vector set, or return garbage and
8319
aedb3bd871bc 7013538: Java memory leak with escape analysis
kvn
parents: 7408
diff changeset
   366
// make "VectorSetI::test()" fail.
aedb3bd871bc 7013538: Java memory leak with escape analysis
kvn
parents: 7408
diff changeset
   367
uint VectorSetI::next(void)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
  j++;                          // Next element in word
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
  mask = (mask & max_jint) << 1;// Next bit in word
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
  do {                          // Do While still have words
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
    while( mask ) {             // While have bits in word
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
      if( s->data[i] & mask ) { // If found a bit
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
        return (i<<5)+j;        // Return the bit address
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
      j++;                      // Skip to next bit
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
      mask = (mask & max_jint) << 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
    j = 0;                      // No more bits in word; setup for next word
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
    mask = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
    for( i++; (i<s->size) && (!s->data[i]); i++ ); // Skip to non-zero word
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
  } while( i<s->size );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
  return max_juint;             // No element, iterated them all
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
}