mirror of
https://forge.sourceware.org/marek/gcc.git
synced 2026-02-22 03:47:02 -05:00
sbitmap: Add bitmap_all_bits_in_range_p function
This patch adds the `bitmap_all_bits_in_range_p` function in sbitmap, which checks if all the bits in a range are set. Helper function `bitmap_bit_in_range_p` has also been added, in order to be used by `bitmap_all_bits_in_range_p` and `bitmap_any_bit_in_range_p`. When the function's `any_inverted` parameter is true, the function checks if any of the bits in the range is unset, otherwise it checks if any of them is set. Function `bitmap_any_bit_in_range_p` has been updated to call `bitmap_bit_in_range_p` with the `any_inverted` parameter set to false, retaining its previous functionality. Function `bitmap_all_bits_in_range_p` calls `bitmap_bit_in_range_p` with `any_inverted` set to true and returns the negation of the result, i.e. true if all the bits in the range are set. gcc/ChangeLog: * sbitmap.cc (bitmap_any_bit_in_range_p): Call and return the result of `bitmap_bit_in_range_p` with the `any_inverted` parameter set to false. (bitmap_bit_in_range_p): New function. (bitmap_all_bits_in_range_p): New function. * sbitmap.h (bitmap_all_bits_in_range_p): New function.
This commit is contained in:
committed by
Philipp Tomsich
parent
a6ebf1ee80
commit
764ea9ea3e
@@ -326,12 +326,13 @@ bitmap_set_range (sbitmap bmap, unsigned int start, unsigned int count)
|
||||
bmap->elms[start_word] |= mask;
|
||||
}
|
||||
|
||||
/* Return TRUE if any bit between START and END inclusive is set within
|
||||
the simple bitmap BMAP. Return FALSE otherwise. */
|
||||
/* Helper function for bitmap_any_bit_in_range_p and
|
||||
bitmap_all_bits_in_range_p. If ANY_INVERTED is true, the function checks
|
||||
if any bit in the range is unset. */
|
||||
|
||||
bool
|
||||
bitmap_any_bit_in_range_p (const_sbitmap bmap, unsigned int start,
|
||||
unsigned int end)
|
||||
static bool
|
||||
bitmap_bit_in_range_p (const_sbitmap bmap, unsigned int start,
|
||||
unsigned int end, bool any_inverted)
|
||||
{
|
||||
gcc_checking_assert (start <= end);
|
||||
bitmap_check_index (bmap, end);
|
||||
@@ -351,7 +352,8 @@ bitmap_any_bit_in_range_p (const_sbitmap bmap, unsigned int start,
|
||||
|
||||
SBITMAP_ELT_TYPE low_mask = ((SBITMAP_ELT_TYPE)1 << start_bitno) - 1;
|
||||
SBITMAP_ELT_TYPE mask = high_mask - low_mask;
|
||||
if (bmap->elms[start_word] & mask)
|
||||
const SBITMAP_ELT_TYPE expected_partial = any_inverted ? mask : 0;
|
||||
if ((bmap->elms[start_word] & mask) != expected_partial)
|
||||
return true;
|
||||
start_word++;
|
||||
}
|
||||
@@ -361,9 +363,10 @@ bitmap_any_bit_in_range_p (const_sbitmap bmap, unsigned int start,
|
||||
|
||||
/* Now test words at a time until we hit a partial word. */
|
||||
unsigned int nwords = (end_word - start_word);
|
||||
const SBITMAP_ELT_TYPE expected = any_inverted ? ~(SBITMAP_ELT_TYPE)0 : 0;
|
||||
while (nwords)
|
||||
{
|
||||
if (bmap->elms[start_word])
|
||||
if (bmap->elms[start_word] != expected)
|
||||
return true;
|
||||
start_word++;
|
||||
nwords--;
|
||||
@@ -373,7 +376,28 @@ bitmap_any_bit_in_range_p (const_sbitmap bmap, unsigned int start,
|
||||
SBITMAP_ELT_TYPE mask = ~(SBITMAP_ELT_TYPE)0;
|
||||
if (end_bitno + 1 < SBITMAP_ELT_BITS)
|
||||
mask = ((SBITMAP_ELT_TYPE)1 << (end_bitno + 1)) - 1;
|
||||
return (bmap->elms[start_word] & mask) != 0;
|
||||
const SBITMAP_ELT_TYPE expected_partial = any_inverted ? mask : 0;
|
||||
return (bmap->elms[start_word] & mask) != expected_partial;
|
||||
}
|
||||
|
||||
/* Return TRUE if all bits between START and END inclusive are set within
|
||||
the simple bitmap BMAP. Return FALSE otherwise. */
|
||||
|
||||
bool
|
||||
bitmap_all_bits_in_range_p (const_sbitmap bmap, unsigned int start,
|
||||
unsigned int end)
|
||||
{
|
||||
return !bitmap_bit_in_range_p (bmap, start, end, true);
|
||||
}
|
||||
|
||||
/* Return TRUE if any bit between START and END inclusive is set within
|
||||
the simple bitmap BMAP. Return FALSE otherwise. */
|
||||
|
||||
bool
|
||||
bitmap_any_bit_in_range_p (const_sbitmap bmap, unsigned int start,
|
||||
unsigned int end)
|
||||
{
|
||||
return bitmap_bit_in_range_p (bmap, start, end, false);
|
||||
}
|
||||
|
||||
#if GCC_VERSION < 3400
|
||||
|
||||
@@ -289,6 +289,8 @@ extern bool bitmap_xor (sbitmap, const_sbitmap, const_sbitmap);
|
||||
extern bool bitmap_subset_p (const_sbitmap, const_sbitmap);
|
||||
extern bool bitmap_any_bit_in_range_p (const_sbitmap, unsigned int,
|
||||
unsigned int);
|
||||
extern bool bitmap_all_bits_in_range_p (const_sbitmap, unsigned int,
|
||||
unsigned int);
|
||||
|
||||
extern int bitmap_first_set_bit (const_sbitmap);
|
||||
extern int bitmap_last_set_bit (const_sbitmap);
|
||||
|
||||
Reference in New Issue
Block a user