bitmap.h (bitmap_iterator): Remove word_bit and bit fields.
* bitmap.h (bitmap_iterator): Remove word_bit and bit fields. Rename others. (bmp_iter_common_next_1, bmp_iter_single_next_1, bmp_iter_single_init, bmp_iter_end_p, bmp_iter_single_next, bmp_iter_and_not_next_1, bmp_iter_and_not_init, bmp_iter_and_not_next, bmp_iter_and_next_1, bmp_iter_and_init, bmp_iter_and_next): Remove. (bmp_iter_set_init, bmp_iter_and_init, bmp_iter_and_compl_init, bmp_iter_next, bmp_iter_set, bmp_iter_and, bmp_iter_and_compl): New. (EXECUTE_IF_SET_IN_BITMAP, EXECUTE_IF_AND_IN_BITMAP, EXECUTE_IF_AND_COMPL_IN_BITMAP): Adjust. From-SVN: r90055
This commit is contained in:
parent
67299d9127
commit
e90ea8cbc4
@ -1,5 +1,18 @@
|
||||
2004-11-04 Nathan Sidwell <nathan@codesourcery.com>
|
||||
|
||||
* bitmap.h (bitmap_iterator): Remove word_bit and bit
|
||||
fields. Rename others.
|
||||
(bmp_iter_common_next_1, bmp_iter_single_next_1,
|
||||
bmp_iter_single_init, bmp_iter_end_p, bmp_iter_single_next,
|
||||
bmp_iter_and_not_next_1, bmp_iter_and_not_init,
|
||||
bmp_iter_and_not_next, bmp_iter_and_next_1, bmp_iter_and_init,
|
||||
bmp_iter_and_next): Remove.
|
||||
(bmp_iter_set_init, bmp_iter_and_init, bmp_iter_and_compl_init,
|
||||
bmp_iter_next, bmp_iter_set, bmp_iter_and, bmp_iter_and_compl):
|
||||
New.
|
||||
(EXECUTE_IF_SET_IN_BITMAP, EXECUTE_IF_AND_IN_BITMAP,
|
||||
EXECUTE_IF_AND_COMPL_IN_BITMAP): Adjust.
|
||||
|
||||
* bitmap.h (bitmap_a_or_b, bitmap_a_and_b): Remove.
|
||||
* df.c (dataflow_set_a_op_b): Use bitmap_and, bitmap_ior,
|
||||
bitmap_and_into, bitmap_ior_into as appropriate.
|
||||
|
652
gcc/bitmap.h
652
gcc/bitmap.h
@ -184,421 +184,387 @@ do { \
|
||||
|
||||
typedef struct
|
||||
{
|
||||
/* Actual elements in the bitmaps. */
|
||||
bitmap_element *ptr1, *ptr2;
|
||||
|
||||
/* Position of an actual word in the elements. */
|
||||
unsigned word;
|
||||
|
||||
/* Position of a bit corresponding to the start of word. */
|
||||
unsigned word_bit;
|
||||
|
||||
/* Position of the actual bit. */
|
||||
unsigned bit;
|
||||
/* Pointer to the current bitmap element. */
|
||||
bitmap_element *elt1;
|
||||
|
||||
/* Pointer to 2nd bitmap element when two are involved. */
|
||||
bitmap_element *elt2;
|
||||
|
||||
/* Word within the current element. */
|
||||
unsigned word_no;
|
||||
|
||||
/* Contents of the actually processed word. When finding next bit
|
||||
it is shifted right, so that the actual bit is always the least
|
||||
significant bit of ACTUAL. */
|
||||
BITMAP_WORD actual;
|
||||
BITMAP_WORD bits;
|
||||
} bitmap_iterator;
|
||||
|
||||
/* Moves the iterator BI to the first set bit on or after the current
|
||||
position in bitmap and returns the bit if available. The bit is
|
||||
found in ACTUAL field only. */
|
||||
/* Initialize a single bitmap iterator. START_BIT is the first bit to
|
||||
iterate from. */
|
||||
|
||||
static inline unsigned
|
||||
bmp_iter_common_next_1 (bitmap_iterator *bi)
|
||||
static inline void
|
||||
bmp_iter_set_init (bitmap_iterator *bi, bitmap map,
|
||||
unsigned start_bit, unsigned *bit_no)
|
||||
{
|
||||
while (!(bi->actual & 1))
|
||||
{
|
||||
bi->actual >>= 1;
|
||||
bi->bit++;
|
||||
}
|
||||
|
||||
return bi->bit;
|
||||
}
|
||||
|
||||
/* Moves the iterator BI to the first set bit on or after the current
|
||||
position in bitmap and returns the bit if available. */
|
||||
|
||||
static inline unsigned
|
||||
bmp_iter_single_next_1 (bitmap_iterator *bi)
|
||||
{
|
||||
if (bi->actual)
|
||||
return bmp_iter_common_next_1 (bi);
|
||||
|
||||
bi->word++;
|
||||
bi->word_bit += BITMAP_WORD_BITS;
|
||||
bi->elt1 = map->first;
|
||||
bi->elt2 = NULL;
|
||||
|
||||
/* Advance elt1 until it is not before the block containing start_bit. */
|
||||
while (1)
|
||||
{
|
||||
for (;
|
||||
bi->word < BITMAP_ELEMENT_WORDS;
|
||||
bi->word++, bi->word_bit += BITMAP_WORD_BITS)
|
||||
if (!bi->elt1)
|
||||
{
|
||||
bi->actual = bi->ptr1->bits[bi->word];
|
||||
if (bi->actual)
|
||||
{
|
||||
bi->bit = bi->word_bit;
|
||||
return bmp_iter_common_next_1 (bi);
|
||||
}
|
||||
bi->elt1 = &bitmap_zero_bits;
|
||||
break;
|
||||
}
|
||||
|
||||
bi->ptr1 = bi->ptr1->next;
|
||||
if (!bi->ptr1)
|
||||
return 0;
|
||||
|
||||
bi->word = 0;
|
||||
bi->word_bit = bi->ptr1->indx * BITMAP_ELEMENT_ALL_BITS;
|
||||
|
||||
if (bi->elt1->indx >= start_bit / BITMAP_ELEMENT_ALL_BITS)
|
||||
break;
|
||||
bi->elt1 = bi->elt1->next;
|
||||
}
|
||||
|
||||
/* We might have gone past the start bit, so reinitialize it. */
|
||||
if (bi->elt1->indx != start_bit / BITMAP_ELEMENT_ALL_BITS)
|
||||
start_bit = bi->elt1->indx * BITMAP_ELEMENT_ALL_BITS;
|
||||
|
||||
/* Initialize for what is now start_bit. */
|
||||
bi->word_no = start_bit / BITMAP_WORD_BITS % BITMAP_ELEMENT_WORDS;
|
||||
bi->bits = bi->elt1->bits[bi->word_no];
|
||||
bi->bits >>= start_bit % BITMAP_WORD_BITS;
|
||||
|
||||
/* If this word is zero, we must make sure we're not pointing at the
|
||||
first bit, otherwise our incrementing to the next word boundary
|
||||
will fail. It won't matter if this increment moves us into the
|
||||
next word. */
|
||||
start_bit += !bi->bits;
|
||||
|
||||
*bit_no = start_bit;
|
||||
}
|
||||
|
||||
/* Initializes a bitmap iterator BI for looping over bits of bitmap
|
||||
BMP, starting with bit MIN. Returns the first bit of BMP greater
|
||||
or equal to MIN if there is any. */
|
||||
/* Initialize an iterator to iterate over the intersection of two
|
||||
bitmaps. START_BIT is the bit to commence from. */
|
||||
|
||||
static inline unsigned
|
||||
bmp_iter_single_init (bitmap_iterator *bi, bitmap bmp, unsigned min)
|
||||
static inline void
|
||||
bmp_iter_and_init (bitmap_iterator *bi, bitmap map1, bitmap map2,
|
||||
unsigned start_bit, unsigned *bit_no)
|
||||
{
|
||||
unsigned indx = min / BITMAP_ELEMENT_ALL_BITS;
|
||||
bi->elt1 = map1->first;
|
||||
bi->elt2 = map2->first;
|
||||
|
||||
for (bi->ptr1 = bmp->first;
|
||||
bi->ptr1 && bi->ptr1->indx < indx;
|
||||
bi->ptr1 = bi->ptr1->next)
|
||||
continue;
|
||||
|
||||
if (!bi->ptr1)
|
||||
/* Advance elt1 until it is not before the block containing
|
||||
start_bit. */
|
||||
while (1)
|
||||
{
|
||||
/* To avoid warnings. */
|
||||
bi->word = 0;
|
||||
bi->bit = 0;
|
||||
bi->word_bit = 0;
|
||||
bi->actual = 0;
|
||||
bi->ptr2 = NULL;
|
||||
return 0;
|
||||
if (!bi->elt1)
|
||||
{
|
||||
bi->elt2 = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
if (bi->elt1->indx >= start_bit / BITMAP_ELEMENT_ALL_BITS)
|
||||
break;
|
||||
bi->elt1 = bi->elt1->next;
|
||||
}
|
||||
|
||||
/* Advance elt2 until it is not before elt1. */
|
||||
while (1)
|
||||
{
|
||||
if (!bi->elt2)
|
||||
{
|
||||
bi->elt1 = bi->elt2 = &bitmap_zero_bits;
|
||||
break;
|
||||
}
|
||||
|
||||
if (bi->elt2->indx >= bi->elt1->indx)
|
||||
break;
|
||||
bi->elt2 = bi->elt2->next;
|
||||
}
|
||||
|
||||
if (bi->ptr1->indx == indx)
|
||||
/* If we're at the same index, then we have some intersecting bits. */
|
||||
if (bi->elt1->indx == bi->elt2->indx)
|
||||
{
|
||||
unsigned bit_in_elt = min - BITMAP_ELEMENT_ALL_BITS * indx;
|
||||
unsigned word_in_elt = bit_in_elt / BITMAP_WORD_BITS;
|
||||
unsigned bit_in_word = bit_in_elt % BITMAP_WORD_BITS;
|
||||
|
||||
bi->word = word_in_elt;
|
||||
bi->word_bit = min - bit_in_word;
|
||||
bi->bit = min;
|
||||
bi->actual = bi->ptr1->bits[word_in_elt] >> bit_in_word;
|
||||
/* We might have advanced beyond the start_bit, so reinitialize
|
||||
for that. */
|
||||
if (bi->elt1->indx != start_bit / BITMAP_ELEMENT_ALL_BITS)
|
||||
start_bit = bi->elt1->indx * BITMAP_ELEMENT_ALL_BITS;
|
||||
|
||||
bi->word_no = start_bit / BITMAP_WORD_BITS % BITMAP_ELEMENT_WORDS;
|
||||
bi->bits = bi->elt1->bits[bi->word_no] & bi->elt2->bits[bi->word_no];
|
||||
bi->bits >>= start_bit % BITMAP_WORD_BITS;
|
||||
}
|
||||
else
|
||||
{
|
||||
bi->word = 0;
|
||||
bi->bit = bi->ptr1->indx * BITMAP_ELEMENT_ALL_BITS;
|
||||
bi->word_bit = bi->bit;
|
||||
bi->actual = bi->ptr1->bits[0];
|
||||
/* Otherwise we must immediately advance elt1, so initialize for
|
||||
that. */
|
||||
bi->word_no = BITMAP_ELEMENT_WORDS - 1;
|
||||
bi->bits = 0;
|
||||
}
|
||||
|
||||
return bmp_iter_single_next_1 (bi);
|
||||
|
||||
/* If this word is zero, we must make sure we're not pointing at the
|
||||
first bit, otherwise our incrementing to the next word boundary
|
||||
will fail. It won't matter if this increment moves us into the
|
||||
next word. */
|
||||
start_bit += !bi->bits;
|
||||
|
||||
*bit_no = start_bit;
|
||||
}
|
||||
|
||||
/* Returns true if all elements of the bitmap referred to by iterator BI
|
||||
were processed. */
|
||||
/* Initialize an iterator to iterate over the bits in MAP1 & ~MAP2.
|
||||
*/
|
||||
|
||||
static inline void
|
||||
bmp_iter_and_compl_init (bitmap_iterator *bi, bitmap map1, bitmap map2,
|
||||
unsigned start_bit, unsigned *bit_no)
|
||||
{
|
||||
bi->elt1 = map1->first;
|
||||
bi->elt2 = map2->first;
|
||||
|
||||
/* Advance elt1 until it is not before the block containing start_bit. */
|
||||
while (1)
|
||||
{
|
||||
if (!bi->elt1)
|
||||
{
|
||||
bi->elt1 = &bitmap_zero_bits;
|
||||
break;
|
||||
}
|
||||
|
||||
if (bi->elt1->indx >= start_bit / BITMAP_ELEMENT_ALL_BITS)
|
||||
break;
|
||||
bi->elt1 = bi->elt1->next;
|
||||
}
|
||||
|
||||
/* Advance elt2 until it is not before elt1. */
|
||||
while (bi->elt2 && bi->elt2->indx < bi->elt1->indx)
|
||||
bi->elt2 = bi->elt2->next;
|
||||
|
||||
/* We might have advanced beyond the start_bit, so reinitialize for
|
||||
that. */
|
||||
if (bi->elt1->indx != start_bit / BITMAP_ELEMENT_ALL_BITS)
|
||||
start_bit = bi->elt1->indx * BITMAP_ELEMENT_ALL_BITS;
|
||||
|
||||
bi->word_no = start_bit / BITMAP_WORD_BITS % BITMAP_ELEMENT_WORDS;
|
||||
bi->bits = bi->elt1->bits[bi->word_no];
|
||||
if (bi->elt2 && bi->elt1->indx == bi->elt2->indx)
|
||||
bi->bits &= ~bi->elt2->bits[bi->word_no];
|
||||
bi->bits >>= start_bit % BITMAP_WORD_BITS;
|
||||
|
||||
/* If this word is zero, we must make sure we're not pointing at the
|
||||
first bit, otherwise our incrementing to the next word boundary
|
||||
will fail. It won't matter if this increment moves us into the
|
||||
next word. */
|
||||
start_bit += !bi->bits;
|
||||
|
||||
*bit_no = start_bit;
|
||||
}
|
||||
|
||||
/* Advance to the next bit in BI. We don't advance to the next
|
||||
non-zero bit yet. */
|
||||
|
||||
static inline void
|
||||
bmp_iter_next (bitmap_iterator *bi, unsigned *bit_no)
|
||||
{
|
||||
bi->bits >>= 1;
|
||||
*bit_no += 1;
|
||||
}
|
||||
|
||||
/* Advance to the next non-zero bit of a single bitmap, we will have
|
||||
already advanced past the just iterated bit. Return true if there
|
||||
is a bit to iterate. */
|
||||
|
||||
static inline bool
|
||||
bmp_iter_end_p (const bitmap_iterator *bi)
|
||||
bmp_iter_set (bitmap_iterator *bi, unsigned *bit_no)
|
||||
{
|
||||
return bi->ptr1 == NULL;
|
||||
}
|
||||
/* If our current word is non-zero, it contains the bit we want. */
|
||||
if (bi->bits)
|
||||
{
|
||||
next_bit:
|
||||
while (!(bi->bits & 1))
|
||||
{
|
||||
bi->bits >>= 1;
|
||||
*bit_no += 1;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Moves the iterator BI to the next bit of bitmap and returns the bit
|
||||
if available. */
|
||||
|
||||
static inline unsigned
|
||||
bmp_iter_single_next (bitmap_iterator *bi)
|
||||
{
|
||||
bi->bit++;
|
||||
bi->actual >>= 1;
|
||||
return bmp_iter_single_next_1 (bi);
|
||||
}
|
||||
|
||||
/* Loop over all bits in BITMAP, starting with MIN and setting BITNUM to
|
||||
the bit number. ITER is a bitmap iterator. */
|
||||
|
||||
#define EXECUTE_IF_SET_IN_BITMAP(BITMAP, MIN, BITNUM, ITER) \
|
||||
for ((BITNUM) = bmp_iter_single_init (&(ITER), (BITMAP), (MIN)); \
|
||||
!bmp_iter_end_p (&(ITER)); \
|
||||
(BITNUM) = bmp_iter_single_next (&(ITER)))
|
||||
|
||||
/* Moves the iterator BI to the first set bit on or after the current
|
||||
position in difference of bitmaps and returns the bit if available. */
|
||||
|
||||
static inline unsigned
|
||||
bmp_iter_and_not_next_1 (bitmap_iterator *bi)
|
||||
{
|
||||
if (bi->actual)
|
||||
return bmp_iter_common_next_1 (bi);
|
||||
|
||||
bi->word++;
|
||||
bi->word_bit += BITMAP_WORD_BITS;
|
||||
/* Round up to the word boundary. We might have just iterated past
|
||||
the end of the last word, hence the -1. It is not possible for
|
||||
bit_no to point at the beginning of the now last word. */
|
||||
*bit_no = ((*bit_no + BITMAP_WORD_BITS - 1)
|
||||
/ BITMAP_WORD_BITS * BITMAP_WORD_BITS);
|
||||
bi->word_no++;
|
||||
|
||||
while (1)
|
||||
{
|
||||
bitmap_element *snd;
|
||||
|
||||
if (bi->ptr2 && bi->ptr2->indx == bi->ptr1->indx)
|
||||
snd = bi->ptr2;
|
||||
else
|
||||
snd = &bitmap_zero_bits;
|
||||
|
||||
for (;
|
||||
bi->word < BITMAP_ELEMENT_WORDS;
|
||||
bi->word++, bi->word_bit += BITMAP_WORD_BITS)
|
||||
/* Find the next non-zero word in this elt. */
|
||||
while (bi->word_no != BITMAP_ELEMENT_WORDS)
|
||||
{
|
||||
bi->actual = (bi->ptr1->bits[bi->word]
|
||||
& ~snd->bits[bi->word]);
|
||||
if (bi->actual)
|
||||
{
|
||||
bi->bit = bi->word_bit;
|
||||
return bmp_iter_common_next_1 (bi);
|
||||
}
|
||||
bi->bits = bi->elt1->bits[bi->word_no];
|
||||
if (bi->bits)
|
||||
goto next_bit;
|
||||
*bit_no += BITMAP_WORD_BITS;
|
||||
bi->word_no++;
|
||||
}
|
||||
|
||||
bi->ptr1 = bi->ptr1->next;
|
||||
if (!bi->ptr1)
|
||||
return 0;
|
||||
|
||||
while (bi->ptr2
|
||||
&& bi->ptr2->indx < bi->ptr1->indx)
|
||||
bi->ptr2 = bi->ptr2->next;
|
||||
|
||||
bi->word = 0;
|
||||
bi->word_bit = bi->ptr1->indx * BITMAP_ELEMENT_ALL_BITS;
|
||||
|
||||
/* Advance to the next element. */
|
||||
bi->elt1 = bi->elt1->next;
|
||||
if (!bi->elt1)
|
||||
return false;
|
||||
*bit_no = bi->elt1->indx * BITMAP_ELEMENT_ALL_BITS;
|
||||
bi->word_no = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Initializes a bitmap iterator BI for looping over bits of bitmap
|
||||
BMP1 &~ BMP2, starting with bit MIN. Returns the first bit of
|
||||
BMP1 &~ BMP2 greater or equal to MIN if there is any. */
|
||||
/* Advance to the next non-zero bit of an intersecting pair of
|
||||
bitmaps. We will have alreadt advanced past the just iterated bit.
|
||||
Return true if there is a bit to iterate. */
|
||||
|
||||
static inline unsigned
|
||||
bmp_iter_and_not_init (bitmap_iterator *bi, bitmap bmp1, bitmap bmp2,
|
||||
unsigned min)
|
||||
static inline bool
|
||||
bmp_iter_and (bitmap_iterator *bi, unsigned *bit_no)
|
||||
{
|
||||
unsigned indx = min / BITMAP_ELEMENT_ALL_BITS;
|
||||
|
||||
for (bi->ptr1 = bmp1->first;
|
||||
bi->ptr1 && bi->ptr1->indx < indx;
|
||||
bi->ptr1 = bi->ptr1->next)
|
||||
continue;
|
||||
|
||||
if (!bi->ptr1)
|
||||
/* If our current word is non-zero, it contains the bit we want. */
|
||||
if (bi->bits)
|
||||
{
|
||||
/* To avoid warnings. */
|
||||
bi->word = 0;
|
||||
bi->bit = 0;
|
||||
bi->word_bit = 0;
|
||||
bi->actual = 0;
|
||||
bi->ptr2 = NULL;
|
||||
return 0;
|
||||
next_bit:
|
||||
while (!(bi->bits & 1))
|
||||
{
|
||||
bi->bits >>= 1;
|
||||
*bit_no += 1;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
for (bi->ptr2 = bmp2->first;
|
||||
bi->ptr2 && bi->ptr2->indx < bi->ptr1->indx;
|
||||
bi->ptr2 = bi->ptr2->next)
|
||||
continue;
|
||||
|
||||
if (bi->ptr1->indx == indx)
|
||||
{
|
||||
unsigned bit_in_elt = min - BITMAP_ELEMENT_ALL_BITS * indx;
|
||||
unsigned word_in_elt = bit_in_elt / BITMAP_WORD_BITS;
|
||||
unsigned bit_in_word = bit_in_elt % BITMAP_WORD_BITS;
|
||||
|
||||
bi->word = word_in_elt;
|
||||
bi->word_bit = min - bit_in_word;
|
||||
bi->bit = min;
|
||||
|
||||
if (bi->ptr2 && bi->ptr2->indx == indx)
|
||||
bi->actual = (bi->ptr1->bits[word_in_elt]
|
||||
& ~bi->ptr2->bits[word_in_elt]) >> bit_in_word;
|
||||
else
|
||||
bi->actual = bi->ptr1->bits[word_in_elt] >> bit_in_word;
|
||||
}
|
||||
else
|
||||
{
|
||||
bi->word = 0;
|
||||
bi->bit = bi->ptr1->indx * BITMAP_ELEMENT_ALL_BITS;
|
||||
bi->word_bit = bi->bit;
|
||||
|
||||
if (bi->ptr2 && bi->ptr2->indx == bi->ptr1->indx)
|
||||
bi->actual = (bi->ptr1->bits[0] & ~bi->ptr2->bits[0]);
|
||||
else
|
||||
bi->actual = bi->ptr1->bits[0];
|
||||
}
|
||||
|
||||
return bmp_iter_and_not_next_1 (bi);
|
||||
}
|
||||
|
||||
/* Moves the iterator BI to the next bit of difference of bitmaps and returns
|
||||
the bit if available. */
|
||||
|
||||
static inline unsigned
|
||||
bmp_iter_and_not_next (bitmap_iterator *bi)
|
||||
{
|
||||
bi->bit++;
|
||||
bi->actual >>= 1;
|
||||
return bmp_iter_and_not_next_1 (bi);
|
||||
}
|
||||
|
||||
/* Loop over all bits in BMP1 and BMP2, starting with MIN, setting
|
||||
BITNUM to the bit number for all bits that are set in the first bitmap
|
||||
and not set in the second. ITER is a bitmap iterator. */
|
||||
|
||||
#define EXECUTE_IF_AND_COMPL_IN_BITMAP(BMP1, BMP2, MIN, BITNUM, ITER) \
|
||||
for ((BITNUM) = bmp_iter_and_not_init (&(ITER), (BMP1), (BMP2), (MIN)); \
|
||||
!bmp_iter_end_p (&(ITER)); \
|
||||
(BITNUM) = bmp_iter_and_not_next (&(ITER)))
|
||||
|
||||
/* Moves the iterator BI to the first set bit on or after the current
|
||||
position in intersection of bitmaps and returns the bit if available. */
|
||||
|
||||
static inline unsigned
|
||||
bmp_iter_and_next_1 (bitmap_iterator *bi)
|
||||
{
|
||||
if (bi->actual)
|
||||
return bmp_iter_common_next_1 (bi);
|
||||
|
||||
bi->word++;
|
||||
bi->word_bit += BITMAP_WORD_BITS;
|
||||
|
||||
/* Round up to the word boundary. We might have just iterated past
|
||||
the end of the last word, hence the -1. It is not possible for
|
||||
bit_no to point at the beginning of the now last word. */
|
||||
*bit_no = ((*bit_no + BITMAP_WORD_BITS - 1)
|
||||
/ BITMAP_WORD_BITS * BITMAP_WORD_BITS);
|
||||
bi->word_no++;
|
||||
|
||||
while (1)
|
||||
{
|
||||
for (;
|
||||
bi->word < BITMAP_ELEMENT_WORDS;
|
||||
bi->word++, bi->word_bit += BITMAP_WORD_BITS)
|
||||
/* Find the next non-zero word in this elt. */
|
||||
while (bi->word_no != BITMAP_ELEMENT_WORDS)
|
||||
{
|
||||
bi->actual = (bi->ptr1->bits[bi->word]
|
||||
& bi->ptr2->bits[bi->word]);
|
||||
if (bi->actual)
|
||||
{
|
||||
bi->bit = bi->word_bit;
|
||||
return bmp_iter_common_next_1 (bi);
|
||||
}
|
||||
bi->bits = bi->elt1->bits[bi->word_no] & bi->elt2->bits[bi->word_no];
|
||||
if (bi->bits)
|
||||
goto next_bit;
|
||||
*bit_no += BITMAP_WORD_BITS;
|
||||
bi->word_no++;
|
||||
}
|
||||
|
||||
|
||||
/* Advance to the next identical element. */
|
||||
do
|
||||
{
|
||||
bi->ptr1 = bi->ptr1->next;
|
||||
if (!bi->ptr1)
|
||||
return 0;
|
||||
|
||||
while (bi->ptr2->indx < bi->ptr1->indx)
|
||||
/* Advance elt1 while it is less than elt2. We always want
|
||||
to advance one elt. */
|
||||
do
|
||||
{
|
||||
bi->ptr2 = bi->ptr2->next;
|
||||
if (!bi->ptr2)
|
||||
{
|
||||
bi->ptr1 = NULL;
|
||||
return 0;
|
||||
}
|
||||
bi->elt1 = bi->elt1->next;
|
||||
if (!bi->elt1)
|
||||
return false;
|
||||
}
|
||||
while (bi->elt1->indx < bi->elt2->indx);
|
||||
|
||||
/* Advance elt2 to be no less than elt1. This might not
|
||||
advance. */
|
||||
while (bi->elt2->indx < bi->elt1->indx)
|
||||
{
|
||||
bi->elt2 = bi->elt2->next;
|
||||
if (!bi->elt2)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
while (bi->ptr1->indx != bi->ptr2->indx);
|
||||
|
||||
bi->word = 0;
|
||||
bi->word_bit = bi->ptr1->indx * BITMAP_ELEMENT_ALL_BITS;
|
||||
while (bi->elt1->indx != bi->elt2->indx);
|
||||
|
||||
*bit_no = bi->elt1->indx * BITMAP_ELEMENT_ALL_BITS;
|
||||
bi->word_no = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Initializes a bitmap iterator BI for looping over bits of bitmap
|
||||
BMP1 & BMP2, starting with bit MIN. Returns the first bit of
|
||||
BMP1 & BMP2 greater or equal to MIN if there is any. */
|
||||
/* Advance to the next non-zero bit in the intersection of
|
||||
complemented bitmaps. We will have already advanced past the just
|
||||
iterated bit. */
|
||||
|
||||
static inline unsigned
|
||||
bmp_iter_and_init (bitmap_iterator *bi, bitmap bmp1, bitmap bmp2,
|
||||
unsigned min)
|
||||
static inline bool
|
||||
bmp_iter_and_compl (bitmap_iterator *bi, unsigned *bit_no)
|
||||
{
|
||||
unsigned indx = min / BITMAP_ELEMENT_ALL_BITS;
|
||||
/* If our current word is non-zero, it contains the bit we want. */
|
||||
if (bi->bits)
|
||||
{
|
||||
next_bit:
|
||||
while (!(bi->bits & 1))
|
||||
{
|
||||
bi->bits >>= 1;
|
||||
*bit_no += 1;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
for (bi->ptr1 = bmp1->first;
|
||||
bi->ptr1 && bi->ptr1->indx < indx;
|
||||
bi->ptr1 = bi->ptr1->next)
|
||||
continue;
|
||||
|
||||
if (!bi->ptr1)
|
||||
goto empty;
|
||||
|
||||
bi->ptr2 = bmp2->first;
|
||||
if (!bi->ptr2)
|
||||
goto empty;
|
||||
/* Round up to the word boundary. We might have just iterated past
|
||||
the end of the last word, hence the -1. It is not possible for
|
||||
bit_no to point at the beginning of the now last word. */
|
||||
*bit_no = ((*bit_no + BITMAP_WORD_BITS - 1)
|
||||
/ BITMAP_WORD_BITS * BITMAP_WORD_BITS);
|
||||
bi->word_no++;
|
||||
|
||||
while (1)
|
||||
{
|
||||
while (bi->ptr2->indx < bi->ptr1->indx)
|
||||
/* Find the next non-zero word in this elt. */
|
||||
while (bi->word_no != BITMAP_ELEMENT_WORDS)
|
||||
{
|
||||
bi->ptr2 = bi->ptr2->next;
|
||||
if (!bi->ptr2)
|
||||
goto empty;
|
||||
bi->bits = bi->elt1->bits[bi->word_no];
|
||||
if (bi->elt2 && bi->elt2->indx == bi->elt1->indx)
|
||||
bi->bits &= ~bi->elt2->bits[bi->word_no];
|
||||
if (bi->bits)
|
||||
goto next_bit;
|
||||
*bit_no += BITMAP_WORD_BITS;
|
||||
bi->word_no++;
|
||||
}
|
||||
|
||||
/* Advance to the next element of elt1. */
|
||||
bi->elt1 = bi->elt1->next;
|
||||
if (!bi->elt1)
|
||||
return false;
|
||||
|
||||
if (bi->ptr1->indx == bi->ptr2->indx)
|
||||
break;
|
||||
|
||||
bi->ptr1 = bi->ptr1->next;
|
||||
if (!bi->ptr1)
|
||||
goto empty;
|
||||
/* Advance elt2 until it is no less than elt1. */
|
||||
while (bi->elt2 && bi->elt2->indx < bi->elt1->indx)
|
||||
bi->elt2 = bi->elt2->next;
|
||||
|
||||
*bit_no = bi->elt1->indx * BITMAP_ELEMENT_ALL_BITS;
|
||||
bi->word_no = 0;
|
||||
}
|
||||
|
||||
if (bi->ptr1->indx == indx)
|
||||
{
|
||||
unsigned bit_in_elt = min - BITMAP_ELEMENT_ALL_BITS * indx;
|
||||
unsigned word_in_elt = bit_in_elt / BITMAP_WORD_BITS;
|
||||
unsigned bit_in_word = bit_in_elt % BITMAP_WORD_BITS;
|
||||
|
||||
bi->word = word_in_elt;
|
||||
bi->word_bit = min - bit_in_word;
|
||||
bi->bit = min;
|
||||
|
||||
bi->actual = (bi->ptr1->bits[word_in_elt]
|
||||
& bi->ptr2->bits[word_in_elt]) >> bit_in_word;
|
||||
}
|
||||
else
|
||||
{
|
||||
bi->word = 0;
|
||||
bi->bit = bi->ptr1->indx * BITMAP_ELEMENT_ALL_BITS;
|
||||
bi->word_bit = bi->bit;
|
||||
|
||||
bi->actual = (bi->ptr1->bits[0] & bi->ptr2->bits[0]);
|
||||
}
|
||||
|
||||
return bmp_iter_and_next_1 (bi);
|
||||
|
||||
empty:
|
||||
/* To avoid warnings. */
|
||||
bi->word = 0;
|
||||
bi->bit = 0;
|
||||
bi->word_bit = 0;
|
||||
bi->actual = 0;
|
||||
bi->ptr1 = NULL;
|
||||
bi->ptr2 = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Moves the iterator BI to the next bit of intersection of bitmaps and returns
|
||||
the bit if available. */
|
||||
/* Loop over all bits set in BITMAP, starting with MIN and setting
|
||||
BITNUM to the bit number. ITER is a bitmap iterator. BITNUM
|
||||
should be treated as a read-only variable as it contains loop
|
||||
state. */
|
||||
|
||||
static inline unsigned
|
||||
bmp_iter_and_next (bitmap_iterator *bi)
|
||||
{
|
||||
bi->bit++;
|
||||
bi->actual >>= 1;
|
||||
return bmp_iter_and_next_1 (bi);
|
||||
}
|
||||
#define EXECUTE_IF_SET_IN_BITMAP(BITMAP, MIN, BITNUM, ITER) \
|
||||
for (bmp_iter_set_init (&(ITER), (BITMAP), (MIN), &(BITNUM)); \
|
||||
bmp_iter_set (&(ITER), &(BITNUM)); \
|
||||
bmp_iter_next (&(ITER), &(BITNUM)))
|
||||
|
||||
/* Loop over all bits in BMP1 and BMP2, starting with MIN, setting
|
||||
BITNUM to the bit number for all bits that are set in both bitmaps.
|
||||
ITER is a bitmap iterator. */
|
||||
/* Loop over all the bits set in BITMAP1 & BITMAP2, starting with MIN
|
||||
and setting BITNUM to the bit number. ITER is a bitmap iterator.
|
||||
BITNUM should be treated as a read-only variable as it contains
|
||||
loop state. */
|
||||
|
||||
#define EXECUTE_IF_AND_IN_BITMAP(BMP1, BMP2, MIN, BITNUM, ITER) \
|
||||
for ((BITNUM) = bmp_iter_and_init (&(ITER), (BMP1), (BMP2), (MIN)); \
|
||||
!bmp_iter_end_p (&(ITER)); \
|
||||
(BITNUM) = bmp_iter_and_next (&(ITER)))
|
||||
#define EXECUTE_IF_AND_IN_BITMAP(BITMAP1, BITMAP2, MIN, BITNUM, ITER) \
|
||||
for (bmp_iter_and_init (&(ITER), (BITMAP1), (BITMAP2), (MIN), \
|
||||
&(BITNUM)); \
|
||||
bmp_iter_and (&(ITER), &(BITNUM)); \
|
||||
bmp_iter_next (&(ITER), &(BITNUM)))
|
||||
|
||||
/* Loop over all the bits set in BITMAP1 & ~BITMAP2, starting with MIN
|
||||
and setting BITNUM to the bit number. ITER is a bitmap iterator.
|
||||
BITNUM should be treated as a read-only variable as it contains
|
||||
loop state. */
|
||||
|
||||
#define EXECUTE_IF_AND_COMPL_IN_BITMAP(BITMAP1, BITMAP2, MIN, BITNUM, ITER) \
|
||||
for (bmp_iter_and_compl_init (&(ITER), (BITMAP1), (BITMAP2), (MIN), \
|
||||
&(BITNUM)); \
|
||||
bmp_iter_and_compl (&(ITER), &(BITNUM)); \
|
||||
bmp_iter_next (&(ITER), &(BITNUM)))
|
||||
|
||||
#endif /* GCC_BITMAP_H */
|
||||
|
Loading…
Reference in New Issue
Block a user