1 /* Functions to support general ended bitmaps.
2 Copyright (C) 1997-2018 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
22 #include "coretypes.h"
26 /* Memory allocation statistics purpose instance. */
27 mem_alloc_description
<bitmap_usage
> bitmap_mem_desc
;
29 static bitmap_element
*bitmap_tree_listify_from (bitmap
, bitmap_element
*);
31 /* Register new bitmap. */
33 bitmap_register (bitmap b MEM_STAT_DECL
)
35 bitmap_mem_desc
.register_descriptor (b
, BITMAP_ORIGIN
, false
39 /* Account the overhead. */
41 register_overhead (bitmap b
, size_t amount
)
43 if (bitmap_mem_desc
.contains_descriptor_for_instance (b
))
44 bitmap_mem_desc
.register_instance_overhead (amount
, b
);
48 bitmap_element bitmap_zero_bits
; /* An element of all zero bits. */
49 bitmap_obstack bitmap_default_obstack
; /* The default bitmap obstack. */
50 static int bitmap_default_obstack_depth
;
51 static GTY((deletable
)) bitmap_element
*bitmap_ggc_free
; /* Freelist of
55 /* Bitmap memory management. */
57 /* Add ELT to the appropriate freelist. */
59 bitmap_elem_to_freelist (bitmap head
, bitmap_element
*elt
)
61 bitmap_obstack
*bit_obstack
= head
->obstack
;
63 if (GATHER_STATISTICS
)
64 register_overhead (head
, -((int)sizeof (bitmap_element
)));
70 elt
->prev
= bit_obstack
->elements
;
71 bit_obstack
->elements
= elt
;
75 elt
->prev
= bitmap_ggc_free
;
76 bitmap_ggc_free
= elt
;
80 /* Allocate a bitmap element. The bits are cleared, but nothing else is. */
82 static inline bitmap_element
*
83 bitmap_element_allocate (bitmap head
)
85 bitmap_element
*element
;
86 bitmap_obstack
*bit_obstack
= head
->obstack
;
90 element
= bit_obstack
->elements
;
93 /* Use up the inner list first before looking at the next
94 element of the outer list. */
97 bit_obstack
->elements
= element
->next
;
98 bit_obstack
->elements
->prev
= element
->prev
;
101 /* Inner list was just a singleton. */
102 bit_obstack
->elements
= element
->prev
;
104 element
= XOBNEW (&bit_obstack
->obstack
, bitmap_element
);
108 element
= bitmap_ggc_free
;
110 /* Use up the inner list first before looking at the next
111 element of the outer list. */
114 bitmap_ggc_free
= element
->next
;
115 bitmap_ggc_free
->prev
= element
->prev
;
118 /* Inner list was just a singleton. */
119 bitmap_ggc_free
= element
->prev
;
121 element
= ggc_alloc
<bitmap_element
> ();
124 if (GATHER_STATISTICS
)
125 register_overhead (head
, sizeof (bitmap_element
));
127 memset (element
->bits
, 0, sizeof (element
->bits
));
132 /* Remove ELT and all following elements from bitmap HEAD.
133 Put the released elements in the freelist for HEAD. */
136 bitmap_elt_clear_from (bitmap head
, bitmap_element
*elt
)
138 bitmap_element
*prev
;
139 bitmap_obstack
*bit_obstack
= head
->obstack
;
145 elt
= bitmap_tree_listify_from (head
, elt
);
147 if (GATHER_STATISTICS
)
150 for (prev
= elt
; prev
; prev
= prev
->next
)
152 register_overhead (head
, -sizeof (bitmap_element
) * n
);
159 if (head
->current
->indx
> prev
->indx
)
161 head
->current
= prev
;
162 head
->indx
= prev
->indx
;
168 head
->current
= NULL
;
172 /* Put the entire list onto the freelist in one operation. */
175 elt
->prev
= bit_obstack
->elements
;
176 bit_obstack
->elements
= elt
;
180 elt
->prev
= bitmap_ggc_free
;
181 bitmap_ggc_free
= elt
;
185 /* Linked-list view of bitmaps.
187 In this representation, the bitmap elements form a double-linked list
188 with elements sorted by increasing index. */
190 /* Link the bitmap element into the current bitmap linked list. */
193 bitmap_list_link_element (bitmap head
, bitmap_element
*element
)
195 unsigned int indx
= element
->indx
;
198 gcc_checking_assert (!head
->tree_form
);
200 /* If this is the first and only element, set it in. */
201 if (head
->first
== 0)
203 element
->next
= element
->prev
= 0;
204 head
->first
= element
;
207 /* If this index is less than that of the current element, it goes someplace
208 before the current element. */
209 else if (indx
< head
->indx
)
211 for (ptr
= head
->current
;
212 ptr
->prev
!= 0 && ptr
->prev
->indx
> indx
;
217 ptr
->prev
->next
= element
;
219 head
->first
= element
;
221 element
->prev
= ptr
->prev
;
226 /* Otherwise, it must go someplace after the current element. */
229 for (ptr
= head
->current
;
230 ptr
->next
!= 0 && ptr
->next
->indx
< indx
;
235 ptr
->next
->prev
= element
;
237 element
->next
= ptr
->next
;
242 /* Set up so this is the first element searched. */
243 head
->current
= element
;
247 /* Unlink the bitmap element from the current bitmap linked list,
248 and return it to the freelist. */
251 bitmap_list_unlink_element (bitmap head
, bitmap_element
*element
)
253 bitmap_element
*next
= element
->next
;
254 bitmap_element
*prev
= element
->prev
;
256 gcc_checking_assert (!head
->tree_form
);
264 if (head
->first
== element
)
267 /* Since the first thing we try is to insert before current,
268 make current the next entry in preference to the previous. */
269 if (head
->current
== element
)
271 head
->current
= next
!= 0 ? next
: prev
;
273 head
->indx
= head
->current
->indx
;
278 bitmap_elem_to_freelist (head
, element
);
281 /* Insert a new uninitialized element into bitmap HEAD after element
282 ELT. If ELT is NULL, insert the element at the start. Return the
285 static bitmap_element
*
286 bitmap_list_insert_element_after (bitmap head
,
287 bitmap_element
*elt
, unsigned int indx
)
289 bitmap_element
*node
= bitmap_element_allocate (head
);
292 gcc_checking_assert (!head
->tree_form
);
298 head
->current
= node
;
301 node
->next
= head
->first
;
303 node
->next
->prev
= node
;
309 gcc_checking_assert (head
->current
);
310 node
->next
= elt
->next
;
312 node
->next
->prev
= node
;
319 /* Return the element for INDX, or NULL if the element doesn't exist.
320 Update the `current' field even if we can't find an element that
321 would hold the bitmap's bit to make eventual allocation
324 static inline bitmap_element
*
325 bitmap_list_find_element (bitmap head
, unsigned int indx
)
327 bitmap_element
*element
;
329 if (head
->current
== NULL
330 || head
->indx
== indx
)
331 return head
->current
;
333 if (head
->current
== head
->first
334 && head
->first
->next
== NULL
)
337 /* Usage can be NULL due to allocated bitmaps for which we do not
338 call initialize function. */
339 bitmap_usage
*usage
= NULL
;
340 if (GATHER_STATISTICS
)
341 usage
= bitmap_mem_desc
.get_descriptor_for_instance (head
);
343 /* This bitmap has more than one element, and we're going to look
344 through the elements list. Count that as a search. */
345 if (GATHER_STATISTICS
&& usage
)
346 usage
->m_nsearches
++;
348 if (head
->indx
< indx
)
349 /* INDX is beyond head->indx. Search from head->current
351 for (element
= head
->current
;
352 element
->next
!= 0 && element
->indx
< indx
;
353 element
= element
->next
)
355 if (GATHER_STATISTICS
&& usage
)
356 usage
->m_search_iter
++;
359 else if (head
->indx
/ 2 < indx
)
360 /* INDX is less than head->indx and closer to head->indx than to
361 0. Search from head->current backward. */
362 for (element
= head
->current
;
363 element
->prev
!= 0 && element
->indx
> indx
;
364 element
= element
->prev
)
366 if (GATHER_STATISTICS
&& usage
)
367 usage
->m_search_iter
++;
371 /* INDX is less than head->indx and closer to 0 than to
372 head->indx. Search from head->first forward. */
373 for (element
= head
->first
;
374 element
->next
!= 0 && element
->indx
< indx
;
375 element
= element
->next
)
377 if (GATHER_STATISTICS
&& usage
)
378 usage
->m_search_iter
++;
381 /* `element' is the nearest to the one we want. If it's not the one we
382 want, the one we want doesn't exist. */
383 gcc_checking_assert (element
!= NULL
);
384 head
->current
= element
;
385 head
->indx
= element
->indx
;
386 if (element
->indx
!= indx
)
392 /* Splay-tree view of bitmaps.
394 This is an almost one-to-one the implementatin of the simple top-down
395 splay tree in Sleator and Tarjan's "Self-adjusting Binary Search Trees".
396 It is probably not the most efficient form of splay trees, but it should
397 be good enough to experiment with this idea of bitmaps-as-trees.
399 For all functions below, the variable or function argument "t" is a node
400 in the tree, and "e" is a temporary or new node in the tree. The rest
401 is sufficiently straigh-forward (and very well explained in the paper)
402 that comment would only clutter things. */
405 bitmap_tree_link_left (bitmap_element
* &t
, bitmap_element
* &l
)
413 bitmap_tree_link_right (bitmap_element
* &t
, bitmap_element
* &r
)
421 bitmap_tree_rotate_left (bitmap_element
* &t
)
423 bitmap_element
*e
= t
->next
;
424 t
->next
= t
->next
->prev
;
430 bitmap_tree_rotate_right (bitmap_element
* &t
)
432 bitmap_element
*e
= t
->prev
;
433 t
->prev
= t
->prev
->next
;
438 static bitmap_element
*
439 bitmap_tree_splay (bitmap head
, bitmap_element
*t
, unsigned int indx
)
441 bitmap_element N
, *l
, *r
;
446 bitmap_usage
*usage
= NULL
;
447 if (GATHER_STATISTICS
)
448 usage
= bitmap_mem_desc
.get_descriptor_for_instance (head
);
450 N
.prev
= N
.next
= NULL
;
453 while (indx
!= t
->indx
)
455 if (GATHER_STATISTICS
&& usage
)
456 usage
->m_search_iter
++;
460 if (t
->prev
!= NULL
&& indx
< t
->prev
->indx
)
461 bitmap_tree_rotate_right (t
);
464 bitmap_tree_link_right (t
, r
);
466 else if (indx
> t
->indx
)
468 if (t
->next
!= NULL
&& indx
> t
->next
->indx
)
469 bitmap_tree_rotate_left (t
);
472 bitmap_tree_link_left (t
, l
);
483 /* Link bitmap element E into the current bitmap splay tree. */
486 bitmap_tree_link_element (bitmap head
, bitmap_element
*e
)
488 if (head
->first
== NULL
)
489 e
->prev
= e
->next
= NULL
;
492 bitmap_element
*t
= bitmap_tree_splay (head
, head
->first
, e
->indx
);
493 if (e
->indx
< t
->indx
)
499 else if (e
->indx
> t
->indx
)
510 head
->indx
= e
->indx
;
513 /* Unlink bitmap element E from the current bitmap splay tree,
514 and return it to the freelist. */
517 bitmap_tree_unlink_element (bitmap head
, bitmap_element
*e
)
519 bitmap_element
*t
= bitmap_tree_splay (head
, head
->first
, e
->indx
);
521 gcc_checking_assert (t
== e
);
527 t
= bitmap_tree_splay (head
, e
->prev
, e
->indx
);
532 head
->indx
= (t
!= NULL
) ? t
->indx
: 0;
534 bitmap_elem_to_freelist (head
, e
);
537 /* Return the element for INDX, or NULL if the element doesn't exist. */
539 static inline bitmap_element
*
540 bitmap_tree_find_element (bitmap head
, unsigned int indx
)
542 if (head
->current
== NULL
543 || head
->indx
== indx
)
544 return head
->current
;
546 /* Usage can be NULL due to allocated bitmaps for which we do not
547 call initialize function. */
548 bitmap_usage
*usage
= NULL
;
549 if (GATHER_STATISTICS
)
550 usage
= bitmap_mem_desc
.get_descriptor_for_instance (head
);
552 /* This bitmap has more than one element, and we're going to look
553 through the elements list. Count that as a search. */
554 if (GATHER_STATISTICS
&& usage
)
555 usage
->m_nsearches
++;
557 bitmap_element
*element
= bitmap_tree_splay (head
, head
->first
, indx
);
558 gcc_checking_assert (element
!= NULL
);
559 head
->first
= element
;
560 head
->current
= element
;
561 head
->indx
= element
->indx
;
562 if (element
->indx
!= indx
)
567 /* Converting bitmap views from linked-list to tree and vice versa. */
569 /* Splice element E and all elements with a larger index from
570 bitmap HEAD, convert the spliced elements to the linked-list
571 view, and return the head of the list (which should be E again), */
573 static bitmap_element
*
574 bitmap_tree_listify_from (bitmap head
, bitmap_element
*e
)
576 bitmap_element
*t
, *erb
;
578 /* Detach the right branch from E (all elements with indx > E->indx),
579 and splay E to the root. */
582 t
= bitmap_tree_splay (head
, head
->first
, e
->indx
);
583 gcc_checking_assert (t
== e
);
585 /* Because E has no right branch, and we rotated it to the root,
586 the left branch is the new root. */
590 head
->indx
= (t
!= NULL
) ? t
->indx
: 0;
592 /* Detach the tree from E, and re-attach the right branch of E. */
596 /* The tree is now valid again. Now we need to "un-tree" E.
597 It is imperative that a non-recursive implementation is used
598 for this, because splay trees have a worst case depth of O(N)
599 for a tree with N nodes. A recursive implementation could
600 result in a stack overflow for a sufficiently large, unbalanced
603 auto_vec
<bitmap_element
*, 32> stack
;
604 auto_vec
<bitmap_element
*, 32> sorted_elements
;
605 bitmap_element
*n
= e
;
615 if (stack
.is_empty ())
619 sorted_elements
.safe_push (n
);
623 gcc_assert (sorted_elements
[0] == e
);
625 bitmap_element
*prev
= NULL
;
627 FOR_EACH_VEC_ELT (sorted_elements
, ix
, n
)
639 /* Convert bitmap HEAD from splay-tree view to linked-list view. */
642 bitmap_list_view (bitmap head
)
646 gcc_assert (head
->tree_form
);
652 bitmap_tree_rotate_right (ptr
);
654 head
->first
= bitmap_tree_listify_from (head
, ptr
);
657 head
->tree_form
= false;
660 /* Convert bitmap HEAD from linked-list view to splay-tree view.
661 This is simply a matter of dropping the prev or next pointers
662 and setting the tree_form flag. The tree will balance itself
663 if and when it is used. */
666 bitmap_tree_view (bitmap head
)
670 gcc_assert (! head
->tree_form
);
679 head
->tree_form
= true;
682 /* Clear a bitmap by freeing all its elements. */
685 bitmap_clear (bitmap head
)
687 if (head
->first
== NULL
)
691 bitmap_element
*e
, *t
;
692 for (e
= head
->first
; e
->prev
; e
= e
->prev
)
693 /* Loop to find the element with the smallest index. */ ;
694 t
= bitmap_tree_splay (head
, head
->first
, e
->indx
);
695 gcc_checking_assert (t
== e
);
698 bitmap_elt_clear_from (head
, head
->first
);
701 /* Initialize a bitmap obstack. If BIT_OBSTACK is NULL, initialize
702 the default bitmap obstack. */
705 bitmap_obstack_initialize (bitmap_obstack
*bit_obstack
)
709 if (bitmap_default_obstack_depth
++)
711 bit_obstack
= &bitmap_default_obstack
;
714 #if !defined(__GNUC__) || (__GNUC__ < 2)
715 #define __alignof__(type) 0
718 bit_obstack
->elements
= NULL
;
719 bit_obstack
->heads
= NULL
;
720 obstack_specify_allocation (&bit_obstack
->obstack
, OBSTACK_CHUNK_SIZE
,
721 __alignof__ (bitmap_element
),
726 /* Release the memory from a bitmap obstack. If BIT_OBSTACK is NULL,
727 release the default bitmap obstack. */
730 bitmap_obstack_release (bitmap_obstack
*bit_obstack
)
734 if (--bitmap_default_obstack_depth
)
736 gcc_assert (bitmap_default_obstack_depth
> 0);
739 bit_obstack
= &bitmap_default_obstack
;
742 bit_obstack
->elements
= NULL
;
743 bit_obstack
->heads
= NULL
;
744 obstack_free (&bit_obstack
->obstack
, NULL
);
747 /* Create a new bitmap on an obstack. If BIT_OBSTACK is NULL, create
748 it on the default bitmap obstack. */
751 bitmap_alloc (bitmap_obstack
*bit_obstack MEM_STAT_DECL
)
756 bit_obstack
= &bitmap_default_obstack
;
757 map
= bit_obstack
->heads
;
759 bit_obstack
->heads
= (struct bitmap_head
*) map
->first
;
761 map
= XOBNEW (&bit_obstack
->obstack
, bitmap_head
);
762 bitmap_initialize (map
, bit_obstack PASS_MEM_STAT
);
764 if (GATHER_STATISTICS
)
765 register_overhead (map
, sizeof (bitmap_head
));
770 /* Create a new GCd bitmap. */
773 bitmap_gc_alloc (ALONE_MEM_STAT_DECL
)
777 map
= ggc_alloc
<bitmap_head
> ();
778 bitmap_initialize (map
, NULL PASS_MEM_STAT
);
780 if (GATHER_STATISTICS
)
781 register_overhead (map
, sizeof (bitmap_head
));
786 /* Release an obstack allocated bitmap. */
789 bitmap_obstack_free (bitmap map
)
794 map
->first
= (bitmap_element
*) map
->obstack
->heads
;
796 if (GATHER_STATISTICS
)
797 register_overhead (map
, -((int)sizeof (bitmap_head
)));
799 map
->obstack
->heads
= map
;
804 /* Return nonzero if all bits in an element are zero. */
807 bitmap_element_zerop (const bitmap_element
*element
)
809 #if BITMAP_ELEMENT_WORDS == 2
810 return (element
->bits
[0] | element
->bits
[1]) == 0;
814 for (i
= 0; i
< BITMAP_ELEMENT_WORDS
; i
++)
815 if (element
->bits
[i
] != 0)
822 /* Copy a bitmap to another bitmap. */
825 bitmap_copy (bitmap to
, const_bitmap from
)
827 const bitmap_element
*from_ptr
;
828 bitmap_element
*to_ptr
= 0;
830 gcc_checking_assert (!to
->tree_form
&& !from
->tree_form
);
834 /* Copy elements in forward direction one at a time. */
835 for (from_ptr
= from
->first
; from_ptr
; from_ptr
= from_ptr
->next
)
837 bitmap_element
*to_elt
= bitmap_element_allocate (to
);
839 to_elt
->indx
= from_ptr
->indx
;
840 memcpy (to_elt
->bits
, from_ptr
->bits
, sizeof (to_elt
->bits
));
842 /* Here we have a special case of bitmap_list_link_element,
843 for the case where we know the links are being entered
847 to
->first
= to
->current
= to_elt
;
848 to
->indx
= from_ptr
->indx
;
849 to_elt
->next
= to_elt
->prev
= 0;
853 to_elt
->prev
= to_ptr
;
855 to_ptr
->next
= to_elt
;
862 /* Move a bitmap to another bitmap. */
865 bitmap_move (bitmap to
, bitmap from
)
867 gcc_assert (to
->obstack
== from
->obstack
);
873 if (GATHER_STATISTICS
)
876 for (bitmap_element
*e
= to
->first
; e
; e
= e
->next
)
877 sz
+= sizeof (bitmap_element
);
878 register_overhead (to
, sz
);
879 register_overhead (from
, -sz
);
883 /* Clear a single bit in a bitmap. Return true if the bit changed. */
886 bitmap_clear_bit (bitmap head
, int bit
)
888 unsigned int indx
= bit
/ BITMAP_ELEMENT_ALL_BITS
;
891 if (!head
->tree_form
)
892 ptr
= bitmap_list_find_element (head
, indx
);
894 ptr
= bitmap_tree_find_element (head
, indx
);
897 unsigned bit_num
= bit
% BITMAP_WORD_BITS
;
898 unsigned word_num
= bit
/ BITMAP_WORD_BITS
% BITMAP_ELEMENT_WORDS
;
899 BITMAP_WORD bit_val
= ((BITMAP_WORD
) 1) << bit_num
;
900 bool res
= (ptr
->bits
[word_num
] & bit_val
) != 0;
903 ptr
->bits
[word_num
] &= ~bit_val
;
904 /* If we cleared the entire word, free up the element. */
905 if (!ptr
->bits
[word_num
]
906 && bitmap_element_zerop (ptr
))
908 if (!head
->tree_form
)
909 bitmap_list_unlink_element (head
, ptr
);
911 bitmap_tree_unlink_element (head
, ptr
);
921 /* Set a single bit in a bitmap. Return true if the bit changed. */
924 bitmap_set_bit (bitmap head
, int bit
)
926 unsigned indx
= bit
/ BITMAP_ELEMENT_ALL_BITS
;
928 if (!head
->tree_form
)
929 ptr
= bitmap_list_find_element (head
, indx
);
931 ptr
= bitmap_tree_find_element (head
, indx
);
932 unsigned word_num
= bit
/ BITMAP_WORD_BITS
% BITMAP_ELEMENT_WORDS
;
933 unsigned bit_num
= bit
% BITMAP_WORD_BITS
;
934 BITMAP_WORD bit_val
= ((BITMAP_WORD
) 1) << bit_num
;
938 bool res
= (ptr
->bits
[word_num
] & bit_val
) == 0;
940 ptr
->bits
[word_num
] |= bit_val
;
944 ptr
= bitmap_element_allocate (head
);
945 ptr
->indx
= bit
/ BITMAP_ELEMENT_ALL_BITS
;
946 ptr
->bits
[word_num
] = bit_val
;
947 if (!head
->tree_form
)
948 bitmap_list_link_element (head
, ptr
);
950 bitmap_tree_link_element (head
, ptr
);
954 /* Return whether a bit is set within a bitmap. */
957 bitmap_bit_p (bitmap head
, int bit
)
959 unsigned int indx
= bit
/ BITMAP_ELEMENT_ALL_BITS
;
964 if (!head
->tree_form
)
965 ptr
= bitmap_list_find_element (head
, indx
);
967 ptr
= bitmap_tree_find_element (head
, indx
);
971 bit_num
= bit
% BITMAP_WORD_BITS
;
972 word_num
= bit
/ BITMAP_WORD_BITS
% BITMAP_ELEMENT_WORDS
;
974 return (ptr
->bits
[word_num
] >> bit_num
) & 1;
977 #if GCC_VERSION < 3400
978 /* Table of number of set bits in a character, indexed by value of char. */
979 static const unsigned char popcount_table
[] =
981 0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,
982 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
983 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
984 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
985 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
986 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
987 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
988 3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,4,5,5,6,5,6,6,7,5,6,6,7,6,7,7,8,
992 bitmap_popcount (BITMAP_WORD a
)
994 unsigned long ret
= 0;
997 /* Just do this the table way for now */
998 for (i
= 0; i
< BITMAP_WORD_BITS
; i
+= 8)
999 ret
+= popcount_table
[(a
>> i
) & 0xff];
1004 /* Count and return the number of bits set in the bitmap word BITS. */
1005 static unsigned long
1006 bitmap_count_bits_in_word (const BITMAP_WORD
*bits
)
1008 unsigned long count
= 0;
1010 for (unsigned ix
= 0; ix
!= BITMAP_ELEMENT_WORDS
; ix
++)
1012 #if GCC_VERSION >= 3400
1013 /* Note that popcountl matches BITMAP_WORD in type, so the actual size
1014 of BITMAP_WORD is not material. */
1015 count
+= __builtin_popcountl (bits
[ix
]);
1017 count
+= bitmap_popcount (bits
[ix
]);
1023 /* Count the number of bits set in the bitmap, and return it. */
1026 bitmap_count_bits (const_bitmap a
)
1028 unsigned long count
= 0;
1029 const bitmap_element
*elt
;
1031 gcc_checking_assert (!a
->tree_form
);
1032 for (elt
= a
->first
; elt
; elt
= elt
->next
)
1033 count
+= bitmap_count_bits_in_word (elt
->bits
);
1038 /* Count the number of unique bits set in A and B and return it. */
1041 bitmap_count_unique_bits (const_bitmap a
, const_bitmap b
)
1043 unsigned long count
= 0;
1044 const bitmap_element
*elt_a
, *elt_b
;
1046 for (elt_a
= a
->first
, elt_b
= b
->first
; elt_a
&& elt_b
; )
1048 /* If we're at different indices, then count all the bits
1049 in the lower element. If we're at the same index, then
1050 count the bits in the IOR of the two elements. */
1051 if (elt_a
->indx
< elt_b
->indx
)
1053 count
+= bitmap_count_bits_in_word (elt_a
->bits
);
1054 elt_a
= elt_a
->next
;
1056 else if (elt_b
->indx
< elt_a
->indx
)
1058 count
+= bitmap_count_bits_in_word (elt_b
->bits
);
1059 elt_b
= elt_b
->next
;
1063 BITMAP_WORD bits
[BITMAP_ELEMENT_WORDS
];
1064 for (unsigned ix
= 0; ix
!= BITMAP_ELEMENT_WORDS
; ix
++)
1065 bits
[ix
] = elt_a
->bits
[ix
] | elt_b
->bits
[ix
];
1066 count
+= bitmap_count_bits_in_word (bits
);
1067 elt_a
= elt_a
->next
;
1068 elt_b
= elt_b
->next
;
1074 /* Return true if the bitmap has a single bit set. Otherwise return
1078 bitmap_single_bit_set_p (const_bitmap a
)
1080 unsigned long count
= 0;
1081 const bitmap_element
*elt
;
1084 if (bitmap_empty_p (a
))
1089 /* As there are no completely empty bitmap elements, a second one
1090 means we have more than one bit set. */
1091 if (elt
->next
!= NULL
1092 && (!a
->tree_form
|| elt
->prev
!= NULL
))
1095 for (ix
= 0; ix
!= BITMAP_ELEMENT_WORDS
; ix
++)
1097 #if GCC_VERSION >= 3400
1098 /* Note that popcountl matches BITMAP_WORD in type, so the actual size
1099 of BITMAP_WORD is not material. */
1100 count
+= __builtin_popcountl (elt
->bits
[ix
]);
1102 count
+= bitmap_popcount (elt
->bits
[ix
]);
1112 /* Return the bit number of the first set bit in the bitmap. The
1113 bitmap must be non-empty. */
1116 bitmap_first_set_bit (const_bitmap a
)
1118 const bitmap_element
*elt
= a
->first
;
1123 gcc_checking_assert (elt
);
1129 bit_no
= elt
->indx
* BITMAP_ELEMENT_ALL_BITS
;
1130 for (ix
= 0; ix
!= BITMAP_ELEMENT_WORDS
; ix
++)
1132 word
= elt
->bits
[ix
];
1138 bit_no
+= ix
* BITMAP_WORD_BITS
;
1140 #if GCC_VERSION >= 3004
1141 gcc_assert (sizeof (long) == sizeof (word
));
1142 bit_no
+= __builtin_ctzl (word
);
1144 /* Binary search for the first set bit. */
1145 #if BITMAP_WORD_BITS > 64
1146 #error "Fill out the table."
1148 #if BITMAP_WORD_BITS > 32
1149 if (!(word
& 0xffffffff))
1150 word
>>= 32, bit_no
+= 32;
1152 if (!(word
& 0xffff))
1153 word
>>= 16, bit_no
+= 16;
1155 word
>>= 8, bit_no
+= 8;
1157 word
>>= 4, bit_no
+= 4;
1159 word
>>= 2, bit_no
+= 2;
1161 word
>>= 1, bit_no
+= 1;
1163 gcc_checking_assert (word
& 1);
1168 /* Return the bit number of the first set bit in the bitmap. The
1169 bitmap must be non-empty. */
1172 bitmap_last_set_bit (const_bitmap a
)
1174 const bitmap_element
*elt
;
1182 elt
= a
->current
? a
->current
: a
->first
;
1183 gcc_checking_assert (elt
);
1188 bit_no
= elt
->indx
* BITMAP_ELEMENT_ALL_BITS
;
1189 for (ix
= BITMAP_ELEMENT_WORDS
- 1; ix
>= 1; ix
--)
1191 word
= elt
->bits
[ix
];
1195 gcc_assert (elt
->bits
[ix
] != 0);
1197 bit_no
+= ix
* BITMAP_WORD_BITS
;
1198 #if GCC_VERSION >= 3004
1199 gcc_assert (sizeof (long) == sizeof (word
));
1200 bit_no
+= BITMAP_WORD_BITS
- __builtin_clzl (word
) - 1;
1202 /* Hopefully this is a twos-complement host... */
1203 BITMAP_WORD x
= word
;
1209 #if BITMAP_WORD_BITS > 32
1212 bit_no
+= bitmap_popcount (x
) - 1;
1222 bitmap_and (bitmap dst
, const_bitmap a
, const_bitmap b
)
1224 bitmap_element
*dst_elt
= dst
->first
;
1225 const bitmap_element
*a_elt
= a
->first
;
1226 const bitmap_element
*b_elt
= b
->first
;
1227 bitmap_element
*dst_prev
= NULL
;
1229 gcc_checking_assert (!dst
->tree_form
&& !a
->tree_form
&& !b
->tree_form
);
1230 gcc_assert (dst
!= a
&& dst
!= b
);
1234 bitmap_copy (dst
, a
);
1238 while (a_elt
&& b_elt
)
1240 if (a_elt
->indx
< b_elt
->indx
)
1241 a_elt
= a_elt
->next
;
1242 else if (b_elt
->indx
< a_elt
->indx
)
1243 b_elt
= b_elt
->next
;
1246 /* Matching elts, generate A & B. */
1248 BITMAP_WORD ior
= 0;
1251 dst_elt
= bitmap_list_insert_element_after (dst
, dst_prev
,
1254 dst_elt
->indx
= a_elt
->indx
;
1255 for (ix
= 0; ix
< BITMAP_ELEMENT_WORDS
; ix
++)
1257 BITMAP_WORD r
= a_elt
->bits
[ix
] & b_elt
->bits
[ix
];
1259 dst_elt
->bits
[ix
] = r
;
1265 dst_elt
= dst_elt
->next
;
1267 a_elt
= a_elt
->next
;
1268 b_elt
= b_elt
->next
;
1271 /* Ensure that dst->current is valid. */
1272 dst
->current
= dst
->first
;
1273 bitmap_elt_clear_from (dst
, dst_elt
);
1274 gcc_checking_assert (!dst
->current
== !dst
->first
);
1276 dst
->indx
= dst
->current
->indx
;
1279 /* A &= B. Return true if A changed. */
1282 bitmap_and_into (bitmap a
, const_bitmap b
)
1284 bitmap_element
*a_elt
= a
->first
;
1285 const bitmap_element
*b_elt
= b
->first
;
1286 bitmap_element
*next
;
1287 bool changed
= false;
1289 gcc_checking_assert (!a
->tree_form
&& !b
->tree_form
);
1294 while (a_elt
&& b_elt
)
1296 if (a_elt
->indx
< b_elt
->indx
)
1299 bitmap_list_unlink_element (a
, a_elt
);
1303 else if (b_elt
->indx
< a_elt
->indx
)
1304 b_elt
= b_elt
->next
;
1307 /* Matching elts, generate A &= B. */
1309 BITMAP_WORD ior
= 0;
1311 for (ix
= 0; ix
< BITMAP_ELEMENT_WORDS
; ix
++)
1313 BITMAP_WORD r
= a_elt
->bits
[ix
] & b_elt
->bits
[ix
];
1314 if (a_elt
->bits
[ix
] != r
)
1316 a_elt
->bits
[ix
] = r
;
1321 bitmap_list_unlink_element (a
, a_elt
);
1323 b_elt
= b_elt
->next
;
1330 bitmap_elt_clear_from (a
, a_elt
);
1333 gcc_checking_assert (!a
->current
== !a
->first
1334 && (!a
->current
|| a
->indx
== a
->current
->indx
));
1340 /* Insert an element equal to SRC_ELT after DST_PREV, overwriting DST_ELT
1341 if non-NULL. CHANGED is true if the destination bitmap had already been
1342 changed; the new value of CHANGED is returned. */
1345 bitmap_elt_copy (bitmap dst
, bitmap_element
*dst_elt
, bitmap_element
*dst_prev
,
1346 const bitmap_element
*src_elt
, bool changed
)
1348 if (!changed
&& dst_elt
&& dst_elt
->indx
== src_elt
->indx
)
1352 for (ix
= 0; ix
< BITMAP_ELEMENT_WORDS
; ix
++)
1353 if (src_elt
->bits
[ix
] != dst_elt
->bits
[ix
])
1355 dst_elt
->bits
[ix
] = src_elt
->bits
[ix
];
1363 dst_elt
= bitmap_list_insert_element_after (dst
, dst_prev
,
1366 dst_elt
->indx
= src_elt
->indx
;
1367 memcpy (dst_elt
->bits
, src_elt
->bits
, sizeof (dst_elt
->bits
));
1377 bitmap_and_compl (bitmap dst
, const_bitmap a
, const_bitmap b
)
1379 bitmap_element
*dst_elt
= dst
->first
;
1380 const bitmap_element
*a_elt
= a
->first
;
1381 const bitmap_element
*b_elt
= b
->first
;
1382 bitmap_element
*dst_prev
= NULL
;
1383 bitmap_element
**dst_prev_pnext
= &dst
->first
;
1384 bool changed
= false;
1386 gcc_checking_assert (!dst
->tree_form
&& !a
->tree_form
&& !b
->tree_form
);
1387 gcc_assert (dst
!= a
&& dst
!= b
);
1391 changed
= !bitmap_empty_p (dst
);
1398 while (b_elt
&& b_elt
->indx
< a_elt
->indx
)
1399 b_elt
= b_elt
->next
;
1401 if (!b_elt
|| b_elt
->indx
> a_elt
->indx
)
1403 changed
= bitmap_elt_copy (dst
, dst_elt
, dst_prev
, a_elt
, changed
);
1404 dst_prev
= *dst_prev_pnext
;
1405 dst_prev_pnext
= &dst_prev
->next
;
1406 dst_elt
= *dst_prev_pnext
;
1407 a_elt
= a_elt
->next
;
1412 /* Matching elts, generate A & ~B. */
1414 BITMAP_WORD ior
= 0;
1416 if (!changed
&& dst_elt
&& dst_elt
->indx
== a_elt
->indx
)
1418 for (ix
= 0; ix
< BITMAP_ELEMENT_WORDS
; ix
++)
1420 BITMAP_WORD r
= a_elt
->bits
[ix
] & ~b_elt
->bits
[ix
];
1422 if (dst_elt
->bits
[ix
] != r
)
1425 dst_elt
->bits
[ix
] = r
;
1433 if (!dst_elt
|| dst_elt
->indx
> a_elt
->indx
)
1435 dst_elt
= bitmap_list_insert_element_after (dst
, dst_prev
,
1441 dst_elt
->indx
= a_elt
->indx
;
1442 new_element
= false;
1445 for (ix
= 0; ix
< BITMAP_ELEMENT_WORDS
; ix
++)
1447 BITMAP_WORD r
= a_elt
->bits
[ix
] & ~b_elt
->bits
[ix
];
1449 dst_elt
->bits
[ix
] = r
;
1457 changed
|= !new_element
;
1458 bitmap_list_unlink_element (dst
, dst_elt
);
1459 dst_elt
= *dst_prev_pnext
;
1465 dst_prev
= *dst_prev_pnext
;
1466 dst_prev_pnext
= &dst_prev
->next
;
1467 dst_elt
= *dst_prev_pnext
;
1469 a_elt
= a_elt
->next
;
1470 b_elt
= b_elt
->next
;
1474 /* Ensure that dst->current is valid. */
1475 dst
->current
= dst
->first
;
1480 bitmap_elt_clear_from (dst
, dst_elt
);
1482 gcc_checking_assert (!dst
->current
== !dst
->first
);
1484 dst
->indx
= dst
->current
->indx
;
1489 /* A &= ~B. Returns true if A changes */
1492 bitmap_and_compl_into (bitmap a
, const_bitmap b
)
1494 bitmap_element
*a_elt
= a
->first
;
1495 const bitmap_element
*b_elt
= b
->first
;
1496 bitmap_element
*next
;
1497 BITMAP_WORD changed
= 0;
1499 gcc_checking_assert (!a
->tree_form
&& !b
->tree_form
);
1503 if (bitmap_empty_p (a
))
1512 while (a_elt
&& b_elt
)
1514 if (a_elt
->indx
< b_elt
->indx
)
1515 a_elt
= a_elt
->next
;
1516 else if (b_elt
->indx
< a_elt
->indx
)
1517 b_elt
= b_elt
->next
;
1520 /* Matching elts, generate A &= ~B. */
1522 BITMAP_WORD ior
= 0;
1524 for (ix
= 0; ix
< BITMAP_ELEMENT_WORDS
; ix
++)
1526 BITMAP_WORD cleared
= a_elt
->bits
[ix
] & b_elt
->bits
[ix
];
1527 BITMAP_WORD r
= a_elt
->bits
[ix
] ^ cleared
;
1529 a_elt
->bits
[ix
] = r
;
1535 bitmap_list_unlink_element (a
, a_elt
);
1537 b_elt
= b_elt
->next
;
1540 gcc_checking_assert (!a
->current
== !a
->first
1541 && (!a
->current
|| a
->indx
== a
->current
->indx
));
1542 return changed
!= 0;
1545 /* Set COUNT bits from START in HEAD. */
1547 bitmap_set_range (bitmap head
, unsigned int start
, unsigned int count
)
1549 unsigned int first_index
, end_bit_plus1
, last_index
;
1550 bitmap_element
*elt
, *elt_prev
;
1553 gcc_checking_assert (!head
->tree_form
);
1560 bitmap_set_bit (head
, start
);
1564 first_index
= start
/ BITMAP_ELEMENT_ALL_BITS
;
1565 end_bit_plus1
= start
+ count
;
1566 last_index
= (end_bit_plus1
- 1) / BITMAP_ELEMENT_ALL_BITS
;
1567 elt
= bitmap_list_find_element (head
, first_index
);
1569 /* If bitmap_list_find_element returns zero, the current is the closest block
1570 to the result. Otherwise, just use bitmap_element_allocate to
1571 ensure ELT is set; in the loop below, ELT == NULL means "insert
1572 at the end of the bitmap". */
1575 elt
= bitmap_element_allocate (head
);
1576 elt
->indx
= first_index
;
1577 bitmap_list_link_element (head
, elt
);
1580 gcc_checking_assert (elt
->indx
== first_index
);
1581 elt_prev
= elt
->prev
;
1582 for (i
= first_index
; i
<= last_index
; i
++)
1584 unsigned elt_start_bit
= i
* BITMAP_ELEMENT_ALL_BITS
;
1585 unsigned elt_end_bit_plus1
= elt_start_bit
+ BITMAP_ELEMENT_ALL_BITS
;
1587 unsigned int first_word_to_mod
;
1588 BITMAP_WORD first_mask
;
1589 unsigned int last_word_to_mod
;
1590 BITMAP_WORD last_mask
;
1593 if (!elt
|| elt
->indx
!= i
)
1594 elt
= bitmap_list_insert_element_after (head
, elt_prev
, i
);
1596 if (elt_start_bit
<= start
)
1598 /* The first bit to turn on is somewhere inside this
1600 first_word_to_mod
= (start
- elt_start_bit
) / BITMAP_WORD_BITS
;
1602 /* This mask should have 1s in all bits >= start position. */
1604 (((BITMAP_WORD
) 1) << ((start
% BITMAP_WORD_BITS
))) - 1;
1605 first_mask
= ~first_mask
;
1609 /* The first bit to turn on is below this start of this elt. */
1610 first_word_to_mod
= 0;
1611 first_mask
= ~(BITMAP_WORD
) 0;
1614 if (elt_end_bit_plus1
<= end_bit_plus1
)
1616 /* The last bit to turn on is beyond this elt. */
1617 last_word_to_mod
= BITMAP_ELEMENT_WORDS
- 1;
1618 last_mask
= ~(BITMAP_WORD
) 0;
1622 /* The last bit to turn on is inside to this elt. */
1624 (end_bit_plus1
- elt_start_bit
) / BITMAP_WORD_BITS
;
1626 /* The last mask should have 1s below the end bit. */
1628 (((BITMAP_WORD
) 1) << ((end_bit_plus1
% BITMAP_WORD_BITS
))) - 1;
1631 if (first_word_to_mod
== last_word_to_mod
)
1633 BITMAP_WORD mask
= first_mask
& last_mask
;
1634 elt
->bits
[first_word_to_mod
] |= mask
;
1638 elt
->bits
[first_word_to_mod
] |= first_mask
;
1639 if (BITMAP_ELEMENT_WORDS
> 2)
1640 for (ix
= first_word_to_mod
+ 1; ix
< last_word_to_mod
; ix
++)
1641 elt
->bits
[ix
] = ~(BITMAP_WORD
) 0;
1642 elt
->bits
[last_word_to_mod
] |= last_mask
;
1649 head
->current
= elt
? elt
: elt_prev
;
1650 head
->indx
= head
->current
->indx
;
1653 /* Clear COUNT bits from START in HEAD. */
1655 bitmap_clear_range (bitmap head
, unsigned int start
, unsigned int count
)
1657 unsigned int first_index
, end_bit_plus1
, last_index
;
1658 bitmap_element
*elt
;
1660 gcc_checking_assert (!head
->tree_form
);
1667 bitmap_clear_bit (head
, start
);
1671 first_index
= start
/ BITMAP_ELEMENT_ALL_BITS
;
1672 end_bit_plus1
= start
+ count
;
1673 last_index
= (end_bit_plus1
- 1) / BITMAP_ELEMENT_ALL_BITS
;
1674 elt
= bitmap_list_find_element (head
, first_index
);
1676 /* If bitmap_list_find_element returns zero, the current is the closest block
1677 to the result. If the current is less than first index, find the
1678 next one. Otherwise, just set elt to be current. */
1683 if (head
->indx
< first_index
)
1685 elt
= head
->current
->next
;
1690 elt
= head
->current
;
1696 while (elt
&& (elt
->indx
<= last_index
))
1698 bitmap_element
* next_elt
= elt
->next
;
1699 unsigned elt_start_bit
= (elt
->indx
) * BITMAP_ELEMENT_ALL_BITS
;
1700 unsigned elt_end_bit_plus1
= elt_start_bit
+ BITMAP_ELEMENT_ALL_BITS
;
1703 if (elt_start_bit
>= start
&& elt_end_bit_plus1
<= end_bit_plus1
)
1704 /* Get rid of the entire elt and go to the next one. */
1705 bitmap_list_unlink_element (head
, elt
);
1708 /* Going to have to knock out some bits in this elt. */
1709 unsigned int first_word_to_mod
;
1710 BITMAP_WORD first_mask
;
1711 unsigned int last_word_to_mod
;
1712 BITMAP_WORD last_mask
;
1716 if (elt_start_bit
<= start
)
1718 /* The first bit to turn off is somewhere inside this
1720 first_word_to_mod
= (start
- elt_start_bit
) / BITMAP_WORD_BITS
;
1722 /* This mask should have 1s in all bits >= start position. */
1724 (((BITMAP_WORD
) 1) << ((start
% BITMAP_WORD_BITS
))) - 1;
1725 first_mask
= ~first_mask
;
1729 /* The first bit to turn off is below this start of this elt. */
1730 first_word_to_mod
= 0;
1732 first_mask
= ~first_mask
;
1735 if (elt_end_bit_plus1
<= end_bit_plus1
)
1737 /* The last bit to turn off is beyond this elt. */
1738 last_word_to_mod
= BITMAP_ELEMENT_WORDS
- 1;
1740 last_mask
= ~last_mask
;
1744 /* The last bit to turn off is inside to this elt. */
1746 (end_bit_plus1
- elt_start_bit
) / BITMAP_WORD_BITS
;
1748 /* The last mask should have 1s below the end bit. */
1750 (((BITMAP_WORD
) 1) << (((end_bit_plus1
) % BITMAP_WORD_BITS
))) - 1;
1754 if (first_word_to_mod
== last_word_to_mod
)
1756 BITMAP_WORD mask
= first_mask
& last_mask
;
1757 elt
->bits
[first_word_to_mod
] &= ~mask
;
1761 elt
->bits
[first_word_to_mod
] &= ~first_mask
;
1762 if (BITMAP_ELEMENT_WORDS
> 2)
1763 for (i
= first_word_to_mod
+ 1; i
< last_word_to_mod
; i
++)
1765 elt
->bits
[last_word_to_mod
] &= ~last_mask
;
1767 for (i
= 0; i
< BITMAP_ELEMENT_WORDS
; i
++)
1773 /* Check to see if there are any bits left. */
1775 bitmap_list_unlink_element (head
, elt
);
1782 head
->current
= elt
;
1783 head
->indx
= head
->current
->indx
;
1790 bitmap_compl_and_into (bitmap a
, const_bitmap b
)
1792 bitmap_element
*a_elt
= a
->first
;
1793 const bitmap_element
*b_elt
= b
->first
;
1794 bitmap_element
*a_prev
= NULL
;
1795 bitmap_element
*next
;
1797 gcc_checking_assert (!a
->tree_form
&& !b
->tree_form
);
1798 gcc_assert (a
!= b
);
1800 if (bitmap_empty_p (a
))
1805 if (bitmap_empty_p (b
))
1811 while (a_elt
|| b_elt
)
1813 if (!b_elt
|| (a_elt
&& a_elt
->indx
< b_elt
->indx
))
1815 /* A is before B. Remove A */
1817 a_prev
= a_elt
->prev
;
1818 bitmap_list_unlink_element (a
, a_elt
);
1821 else if (!a_elt
|| b_elt
->indx
< a_elt
->indx
)
1823 /* B is before A. Copy B. */
1824 next
= bitmap_list_insert_element_after (a
, a_prev
, b_elt
->indx
);
1825 memcpy (next
->bits
, b_elt
->bits
, sizeof (next
->bits
));
1827 b_elt
= b_elt
->next
;
1831 /* Matching elts, generate A = ~A & B. */
1833 BITMAP_WORD ior
= 0;
1835 for (ix
= 0; ix
< BITMAP_ELEMENT_WORDS
; ix
++)
1837 BITMAP_WORD cleared
= a_elt
->bits
[ix
] & b_elt
->bits
[ix
];
1838 BITMAP_WORD r
= b_elt
->bits
[ix
] ^ cleared
;
1840 a_elt
->bits
[ix
] = r
;
1845 bitmap_list_unlink_element (a
, a_elt
);
1849 b_elt
= b_elt
->next
;
1852 gcc_checking_assert (!a
->current
== !a
->first
1853 && (!a
->current
|| a
->indx
== a
->current
->indx
));
1858 /* Insert an element corresponding to A_ELT | B_ELT after DST_PREV,
1859 overwriting DST_ELT if non-NULL. CHANGED is true if the destination bitmap
1860 had already been changed; the new value of CHANGED is returned. */
1863 bitmap_elt_ior (bitmap dst
, bitmap_element
*dst_elt
, bitmap_element
*dst_prev
,
1864 const bitmap_element
*a_elt
, const bitmap_element
*b_elt
,
1867 gcc_assert (a_elt
|| b_elt
);
1869 if (a_elt
&& b_elt
&& a_elt
->indx
== b_elt
->indx
)
1871 /* Matching elts, generate A | B. */
1874 if (!changed
&& dst_elt
&& dst_elt
->indx
== a_elt
->indx
)
1876 for (ix
= 0; ix
< BITMAP_ELEMENT_WORDS
; ix
++)
1878 BITMAP_WORD r
= a_elt
->bits
[ix
] | b_elt
->bits
[ix
];
1879 if (r
!= dst_elt
->bits
[ix
])
1881 dst_elt
->bits
[ix
] = r
;
1890 dst_elt
= bitmap_list_insert_element_after (dst
, dst_prev
,
1893 dst_elt
->indx
= a_elt
->indx
;
1894 for (ix
= 0; ix
< BITMAP_ELEMENT_WORDS
; ix
++)
1896 BITMAP_WORD r
= a_elt
->bits
[ix
] | b_elt
->bits
[ix
];
1897 dst_elt
->bits
[ix
] = r
;
1903 /* Copy a single element. */
1904 const bitmap_element
*src
;
1906 if (!b_elt
|| (a_elt
&& a_elt
->indx
< b_elt
->indx
))
1911 gcc_checking_assert (src
);
1912 changed
= bitmap_elt_copy (dst
, dst_elt
, dst_prev
, src
, changed
);
1918 /* DST = A | B. Return true if DST changes. */
1921 bitmap_ior (bitmap dst
, const_bitmap a
, const_bitmap b
)
1923 bitmap_element
*dst_elt
= dst
->first
;
1924 const bitmap_element
*a_elt
= a
->first
;
1925 const bitmap_element
*b_elt
= b
->first
;
1926 bitmap_element
*dst_prev
= NULL
;
1927 bitmap_element
**dst_prev_pnext
= &dst
->first
;
1928 bool changed
= false;
1930 gcc_checking_assert (!dst
->tree_form
&& !a
->tree_form
&& !b
->tree_form
);
1931 gcc_assert (dst
!= a
&& dst
!= b
);
1933 while (a_elt
|| b_elt
)
1935 changed
= bitmap_elt_ior (dst
, dst_elt
, dst_prev
, a_elt
, b_elt
, changed
);
1937 if (a_elt
&& b_elt
&& a_elt
->indx
== b_elt
->indx
)
1939 a_elt
= a_elt
->next
;
1940 b_elt
= b_elt
->next
;
1944 if (a_elt
&& (!b_elt
|| a_elt
->indx
<= b_elt
->indx
))
1945 a_elt
= a_elt
->next
;
1946 else if (b_elt
&& (!a_elt
|| b_elt
->indx
<= a_elt
->indx
))
1947 b_elt
= b_elt
->next
;
1950 dst_prev
= *dst_prev_pnext
;
1951 dst_prev_pnext
= &dst_prev
->next
;
1952 dst_elt
= *dst_prev_pnext
;
1958 /* Ensure that dst->current is valid. */
1959 dst
->current
= dst
->first
;
1960 bitmap_elt_clear_from (dst
, dst_elt
);
1962 gcc_checking_assert (!dst
->current
== !dst
->first
);
1964 dst
->indx
= dst
->current
->indx
;
1968 /* A |= B. Return true if A changes. */
1971 bitmap_ior_into (bitmap a
, const_bitmap b
)
1973 bitmap_element
*a_elt
= a
->first
;
1974 const bitmap_element
*b_elt
= b
->first
;
1975 bitmap_element
*a_prev
= NULL
;
1976 bitmap_element
**a_prev_pnext
= &a
->first
;
1977 bool changed
= false;
1979 gcc_checking_assert (!a
->tree_form
&& !b
->tree_form
);
1985 /* If A lags behind B, just advance it. */
1986 if (!a_elt
|| a_elt
->indx
== b_elt
->indx
)
1988 changed
= bitmap_elt_ior (a
, a_elt
, a_prev
, a_elt
, b_elt
, changed
);
1989 b_elt
= b_elt
->next
;
1991 else if (a_elt
->indx
> b_elt
->indx
)
1993 changed
= bitmap_elt_copy (a
, NULL
, a_prev
, b_elt
, changed
);
1994 b_elt
= b_elt
->next
;
1997 a_prev
= *a_prev_pnext
;
1998 a_prev_pnext
= &a_prev
->next
;
1999 a_elt
= *a_prev_pnext
;
2002 gcc_checking_assert (!a
->current
== !a
->first
);
2004 a
->indx
= a
->current
->indx
;
2011 bitmap_xor (bitmap dst
, const_bitmap a
, const_bitmap b
)
2013 bitmap_element
*dst_elt
= dst
->first
;
2014 const bitmap_element
*a_elt
= a
->first
;
2015 const bitmap_element
*b_elt
= b
->first
;
2016 bitmap_element
*dst_prev
= NULL
;
2018 gcc_checking_assert (!dst
->tree_form
&& !a
->tree_form
&& !b
->tree_form
);
2019 gcc_assert (dst
!= a
&& dst
!= b
);
2027 while (a_elt
|| b_elt
)
2029 if (a_elt
&& b_elt
&& a_elt
->indx
== b_elt
->indx
)
2031 /* Matching elts, generate A ^ B. */
2033 BITMAP_WORD ior
= 0;
2036 dst_elt
= bitmap_list_insert_element_after (dst
, dst_prev
,
2039 dst_elt
->indx
= a_elt
->indx
;
2040 for (ix
= 0; ix
< BITMAP_ELEMENT_WORDS
; ix
++)
2042 BITMAP_WORD r
= a_elt
->bits
[ix
] ^ b_elt
->bits
[ix
];
2045 dst_elt
->bits
[ix
] = r
;
2047 a_elt
= a_elt
->next
;
2048 b_elt
= b_elt
->next
;
2052 dst_elt
= dst_elt
->next
;
2057 /* Copy a single element. */
2058 const bitmap_element
*src
;
2060 if (!b_elt
|| (a_elt
&& a_elt
->indx
< b_elt
->indx
))
2063 a_elt
= a_elt
->next
;
2068 b_elt
= b_elt
->next
;
2072 dst_elt
= bitmap_list_insert_element_after (dst
, dst_prev
,
2075 dst_elt
->indx
= src
->indx
;
2076 memcpy (dst_elt
->bits
, src
->bits
, sizeof (dst_elt
->bits
));
2078 dst_elt
= dst_elt
->next
;
2081 /* Ensure that dst->current is valid. */
2082 dst
->current
= dst
->first
;
2083 bitmap_elt_clear_from (dst
, dst_elt
);
2084 gcc_checking_assert (!dst
->current
== !dst
->first
);
2086 dst
->indx
= dst
->current
->indx
;
2092 bitmap_xor_into (bitmap a
, const_bitmap b
)
2094 bitmap_element
*a_elt
= a
->first
;
2095 const bitmap_element
*b_elt
= b
->first
;
2096 bitmap_element
*a_prev
= NULL
;
2098 gcc_checking_assert (!a
->tree_form
&& !b
->tree_form
);
2108 if (!a_elt
|| b_elt
->indx
< a_elt
->indx
)
2111 bitmap_element
*dst
= bitmap_list_insert_element_after (a
, a_prev
,
2113 memcpy (dst
->bits
, b_elt
->bits
, sizeof (dst
->bits
));
2115 b_elt
= b_elt
->next
;
2117 else if (a_elt
->indx
< b_elt
->indx
)
2120 a_elt
= a_elt
->next
;
2124 /* Matching elts, generate A ^= B. */
2126 BITMAP_WORD ior
= 0;
2127 bitmap_element
*next
= a_elt
->next
;
2129 for (ix
= 0; ix
< BITMAP_ELEMENT_WORDS
; ix
++)
2131 BITMAP_WORD r
= a_elt
->bits
[ix
] ^ b_elt
->bits
[ix
];
2134 a_elt
->bits
[ix
] = r
;
2136 b_elt
= b_elt
->next
;
2140 bitmap_list_unlink_element (a
, a_elt
);
2144 gcc_checking_assert (!a
->current
== !a
->first
);
2146 a
->indx
= a
->current
->indx
;
2149 /* Return true if two bitmaps are identical.
2150 We do not bother with a check for pointer equality, as that never
2151 occurs in practice. */
2154 bitmap_equal_p (const_bitmap a
, const_bitmap b
)
2156 const bitmap_element
*a_elt
;
2157 const bitmap_element
*b_elt
;
2160 gcc_checking_assert (!a
->tree_form
&& !b
->tree_form
);
2162 for (a_elt
= a
->first
, b_elt
= b
->first
;
2164 a_elt
= a_elt
->next
, b_elt
= b_elt
->next
)
2166 if (a_elt
->indx
!= b_elt
->indx
)
2168 for (ix
= 0; ix
< BITMAP_ELEMENT_WORDS
; ix
++)
2169 if (a_elt
->bits
[ix
] != b_elt
->bits
[ix
])
2172 return !a_elt
&& !b_elt
;
2175 /* Return true if A AND B is not empty. */
2178 bitmap_intersect_p (const_bitmap a
, const_bitmap b
)
2180 const bitmap_element
*a_elt
;
2181 const bitmap_element
*b_elt
;
2184 gcc_checking_assert (!a
->tree_form
&& !b
->tree_form
);
2186 for (a_elt
= a
->first
, b_elt
= b
->first
;
2189 if (a_elt
->indx
< b_elt
->indx
)
2190 a_elt
= a_elt
->next
;
2191 else if (b_elt
->indx
< a_elt
->indx
)
2192 b_elt
= b_elt
->next
;
2195 for (ix
= 0; ix
< BITMAP_ELEMENT_WORDS
; ix
++)
2196 if (a_elt
->bits
[ix
] & b_elt
->bits
[ix
])
2198 a_elt
= a_elt
->next
;
2199 b_elt
= b_elt
->next
;
2205 /* Return true if A AND NOT B is not empty. */
2208 bitmap_intersect_compl_p (const_bitmap a
, const_bitmap b
)
2210 const bitmap_element
*a_elt
;
2211 const bitmap_element
*b_elt
;
2214 gcc_checking_assert (!a
->tree_form
&& !b
->tree_form
);
2216 for (a_elt
= a
->first
, b_elt
= b
->first
;
2219 if (a_elt
->indx
< b_elt
->indx
)
2221 else if (b_elt
->indx
< a_elt
->indx
)
2222 b_elt
= b_elt
->next
;
2225 for (ix
= 0; ix
< BITMAP_ELEMENT_WORDS
; ix
++)
2226 if (a_elt
->bits
[ix
] & ~b_elt
->bits
[ix
])
2228 a_elt
= a_elt
->next
;
2229 b_elt
= b_elt
->next
;
2232 return a_elt
!= NULL
;
2236 /* DST = A | (FROM1 & ~FROM2). Return true if DST changes. */
2239 bitmap_ior_and_compl (bitmap dst
, const_bitmap a
, const_bitmap b
, const_bitmap kill
)
2241 bool changed
= false;
2243 bitmap_element
*dst_elt
= dst
->first
;
2244 const bitmap_element
*a_elt
= a
->first
;
2245 const bitmap_element
*b_elt
= b
->first
;
2246 const bitmap_element
*kill_elt
= kill
->first
;
2247 bitmap_element
*dst_prev
= NULL
;
2248 bitmap_element
**dst_prev_pnext
= &dst
->first
;
2250 gcc_checking_assert (!dst
->tree_form
&& !a
->tree_form
&& !b
->tree_form
2251 && !kill
->tree_form
);
2252 gcc_assert (dst
!= a
&& dst
!= b
&& dst
!= kill
);
2254 /* Special cases. We don't bother checking for bitmap_equal_p (b, kill). */
2255 if (b
== kill
|| bitmap_empty_p (b
))
2257 changed
= !bitmap_equal_p (dst
, a
);
2259 bitmap_copy (dst
, a
);
2262 if (bitmap_empty_p (kill
))
2263 return bitmap_ior (dst
, a
, b
);
2264 if (bitmap_empty_p (a
))
2265 return bitmap_and_compl (dst
, b
, kill
);
2267 while (a_elt
|| b_elt
)
2269 bool new_element
= false;
2272 while (kill_elt
&& kill_elt
->indx
< b_elt
->indx
)
2273 kill_elt
= kill_elt
->next
;
2275 if (b_elt
&& kill_elt
&& kill_elt
->indx
== b_elt
->indx
2276 && (!a_elt
|| a_elt
->indx
>= b_elt
->indx
))
2278 bitmap_element tmp_elt
;
2281 BITMAP_WORD ior
= 0;
2282 tmp_elt
.indx
= b_elt
->indx
;
2283 for (ix
= 0; ix
< BITMAP_ELEMENT_WORDS
; ix
++)
2285 BITMAP_WORD r
= b_elt
->bits
[ix
] & ~kill_elt
->bits
[ix
];
2287 tmp_elt
.bits
[ix
] = r
;
2292 changed
= bitmap_elt_ior (dst
, dst_elt
, dst_prev
,
2293 a_elt
, &tmp_elt
, changed
);
2295 if (a_elt
&& a_elt
->indx
== b_elt
->indx
)
2296 a_elt
= a_elt
->next
;
2299 b_elt
= b_elt
->next
;
2300 kill_elt
= kill_elt
->next
;
2304 changed
= bitmap_elt_ior (dst
, dst_elt
, dst_prev
,
2305 a_elt
, b_elt
, changed
);
2308 if (a_elt
&& b_elt
&& a_elt
->indx
== b_elt
->indx
)
2310 a_elt
= a_elt
->next
;
2311 b_elt
= b_elt
->next
;
2315 if (a_elt
&& (!b_elt
|| a_elt
->indx
<= b_elt
->indx
))
2316 a_elt
= a_elt
->next
;
2317 else if (b_elt
&& (!a_elt
|| b_elt
->indx
<= a_elt
->indx
))
2318 b_elt
= b_elt
->next
;
2324 dst_prev
= *dst_prev_pnext
;
2325 dst_prev_pnext
= &dst_prev
->next
;
2326 dst_elt
= *dst_prev_pnext
;
2333 /* Ensure that dst->current is valid. */
2334 dst
->current
= dst
->first
;
2335 bitmap_elt_clear_from (dst
, dst_elt
);
2337 gcc_checking_assert (!dst
->current
== !dst
->first
);
2339 dst
->indx
= dst
->current
->indx
;
2344 /* A |= (B & ~C). Return true if A changes. */
2347 bitmap_ior_and_compl_into (bitmap a
, const_bitmap b
, const_bitmap c
)
2352 gcc_checking_assert (!a
->tree_form
&& !b
->tree_form
&& !c
->tree_form
);
2354 bitmap_initialize (&tmp
, &bitmap_default_obstack
);
2355 bitmap_and_compl (&tmp
, b
, c
);
2356 changed
= bitmap_ior_into (a
, &tmp
);
2357 bitmap_clear (&tmp
);
2362 /* A |= (B & C). Return true if A changes. */
2365 bitmap_ior_and_into (bitmap a
, const_bitmap b
, const_bitmap c
)
2367 bitmap_element
*a_elt
= a
->first
;
2368 const bitmap_element
*b_elt
= b
->first
;
2369 const bitmap_element
*c_elt
= c
->first
;
2370 bitmap_element and_elt
;
2371 bitmap_element
*a_prev
= NULL
;
2372 bitmap_element
**a_prev_pnext
= &a
->first
;
2373 bool changed
= false;
2376 gcc_checking_assert (!a
->tree_form
&& !b
->tree_form
&& !c
->tree_form
);
2379 return bitmap_ior_into (a
, b
);
2380 if (bitmap_empty_p (b
) || bitmap_empty_p (c
))
2384 while (b_elt
&& c_elt
)
2386 BITMAP_WORD overall
;
2388 /* Find a common item of B and C. */
2389 while (b_elt
->indx
!= c_elt
->indx
)
2391 if (b_elt
->indx
< c_elt
->indx
)
2393 b_elt
= b_elt
->next
;
2399 c_elt
= c_elt
->next
;
2406 and_elt
.indx
= b_elt
->indx
;
2407 for (ix
= 0; ix
< BITMAP_ELEMENT_WORDS
; ix
++)
2409 and_elt
.bits
[ix
] = b_elt
->bits
[ix
] & c_elt
->bits
[ix
];
2410 overall
|= and_elt
.bits
[ix
];
2413 b_elt
= b_elt
->next
;
2414 c_elt
= c_elt
->next
;
2418 /* Now find a place to insert AND_ELT. */
2421 ix
= a_elt
? a_elt
->indx
: and_elt
.indx
;
2422 if (ix
== and_elt
.indx
)
2423 changed
= bitmap_elt_ior (a
, a_elt
, a_prev
, a_elt
, &and_elt
, changed
);
2424 else if (ix
> and_elt
.indx
)
2425 changed
= bitmap_elt_copy (a
, NULL
, a_prev
, &and_elt
, changed
);
2427 a_prev
= *a_prev_pnext
;
2428 a_prev_pnext
= &a_prev
->next
;
2429 a_elt
= *a_prev_pnext
;
2431 /* If A lagged behind B/C, we advanced it so loop once more. */
2433 while (ix
< and_elt
.indx
);
2437 gcc_checking_assert (!a
->current
== !a
->first
);
2439 a
->indx
= a
->current
->indx
;
2443 /* Compute hash of bitmap (for purposes of hashing). */
2446 bitmap_hash (const_bitmap head
)
2448 const bitmap_element
*ptr
;
2449 BITMAP_WORD hash
= 0;
2452 gcc_checking_assert (!head
->tree_form
);
2454 for (ptr
= head
->first
; ptr
; ptr
= ptr
->next
)
2457 for (ix
= 0; ix
!= BITMAP_ELEMENT_WORDS
; ix
++)
2458 hash
^= ptr
->bits
[ix
];
2460 return (hashval_t
)hash
;
2464 /* Function to obtain a vector of bitmap elements in bit order from
2465 HEAD in tree view. */
2468 bitmap_tree_to_vec (vec
<bitmap_element
*> &elts
, const_bitmap head
)
2470 gcc_checking_assert (head
->tree_form
);
2471 auto_vec
<bitmap_element
*, 32> stack
;
2472 bitmap_element
*e
= head
->first
;
2477 stack
.safe_push (e
);
2480 if (stack
.is_empty ())
2489 /* Debugging function to print out the contents of a bitmap element. */
2492 debug_bitmap_elt_file (FILE *file
, const bitmap_element
*ptr
)
2494 unsigned int i
, j
, col
= 26;
2496 fprintf (file
, "\t" HOST_PTR_PRINTF
" next = " HOST_PTR_PRINTF
2497 " prev = " HOST_PTR_PRINTF
" indx = %u\n\t\tbits = {",
2498 (const void*) ptr
, (const void*) ptr
->next
,
2499 (const void*) ptr
->prev
, ptr
->indx
);
2501 for (i
= 0; i
< BITMAP_ELEMENT_WORDS
; i
++)
2502 for (j
= 0; j
< BITMAP_WORD_BITS
; j
++)
2503 if ((ptr
->bits
[i
] >> j
) & 1)
2507 fprintf (file
, "\n\t\t\t");
2511 fprintf (file
, " %u", (ptr
->indx
* BITMAP_ELEMENT_ALL_BITS
2512 + i
* BITMAP_WORD_BITS
+ j
));
2516 fprintf (file
, " }\n");
2519 /* Debugging function to print out the contents of a bitmap. */
2522 debug_bitmap_file (FILE *file
, const_bitmap head
)
2524 const bitmap_element
*ptr
;
2526 fprintf (file
, "\nfirst = " HOST_PTR_PRINTF
2527 " current = " HOST_PTR_PRINTF
" indx = %u\n",
2528 (void *) head
->first
, (void *) head
->current
, head
->indx
);
2530 if (head
->tree_form
)
2532 auto_vec
<bitmap_element
*, 32> elts
;
2533 bitmap_tree_to_vec (elts
, head
);
2534 for (unsigned i
= 0; i
< elts
.length (); ++i
)
2535 debug_bitmap_elt_file (file
, elts
[i
]);
2538 for (ptr
= head
->first
; ptr
; ptr
= ptr
->next
)
2539 debug_bitmap_elt_file (file
, ptr
);
2542 /* Function to be called from the debugger to print the contents
2546 debug_bitmap (const_bitmap head
)
2548 debug_bitmap_file (stderr
, head
);
2551 /* Function to print out the contents of a bitmap. Unlike debug_bitmap_file,
2552 it does not print anything but the bits. */
2555 bitmap_print (FILE *file
, const_bitmap head
, const char *prefix
,
2558 const char *comma
= "";
2561 fputs (prefix
, file
);
2562 if (head
->tree_form
)
2564 auto_vec
<bitmap_element
*, 32> elts
;
2565 bitmap_tree_to_vec (elts
, head
);
2566 for (i
= 0; i
< elts
.length (); ++i
)
2567 for (unsigned ix
= 0; ix
!= BITMAP_ELEMENT_WORDS
; ++ix
)
2569 BITMAP_WORD word
= elts
[i
]->bits
[ix
];
2570 for (unsigned bit
= 0; bit
!= BITMAP_WORD_BITS
; ++bit
)
2571 if (word
& ((BITMAP_WORD
)1 << bit
))
2573 fprintf (file
, "%s%d", comma
,
2574 (bit
+ BITMAP_WORD_BITS
* ix
2575 + elts
[i
]->indx
* BITMAP_ELEMENT_ALL_BITS
));
2583 EXECUTE_IF_SET_IN_BITMAP (head
, 0, i
, bi
)
2585 fprintf (file
, "%s%d", comma
, i
);
2589 fputs (suffix
, file
);
2592 /* Output per-bitmap memory usage statistics. */
2594 dump_bitmap_statistics (void)
2596 if (!GATHER_STATISTICS
)
2599 bitmap_mem_desc
.dump (BITMAP_ORIGIN
);
2603 debug (const bitmap_head
&ref
)
2605 dump_bitmap (stderr
, &ref
);
2609 debug (const bitmap_head
*ptr
)
2614 fprintf (stderr
, "<nil>\n");
2618 bitmap_head::dump ()
2625 namespace selftest
{
2627 /* Selftests for bitmaps. */
2629 /* Freshly-created bitmaps ought to be empty. */
2634 bitmap b
= bitmap_gc_alloc ();
2635 ASSERT_TRUE (bitmap_empty_p (b
));
2638 /* Verify bitmap_set_range. */
2643 bitmap b
= bitmap_gc_alloc ();
2644 ASSERT_TRUE (bitmap_empty_p (b
));
2646 bitmap_set_range (b
, 7, 5);
2647 ASSERT_FALSE (bitmap_empty_p (b
));
2648 ASSERT_EQ (5, bitmap_count_bits (b
));
2650 /* Verify bitmap_bit_p at the boundaries. */
2651 ASSERT_FALSE (bitmap_bit_p (b
, 6));
2652 ASSERT_TRUE (bitmap_bit_p (b
, 7));
2653 ASSERT_TRUE (bitmap_bit_p (b
, 11));
2654 ASSERT_FALSE (bitmap_bit_p (b
, 12));
2657 /* Verify splitting a range into two pieces using bitmap_clear_bit. */
2660 test_clear_bit_in_middle ()
2662 bitmap b
= bitmap_gc_alloc ();
2664 /* Set b to [100..200]. */
2665 bitmap_set_range (b
, 100, 100);
2666 ASSERT_EQ (100, bitmap_count_bits (b
));
2668 /* Clear a bit in the middle. */
2669 bool changed
= bitmap_clear_bit (b
, 150);
2670 ASSERT_TRUE (changed
);
2671 ASSERT_EQ (99, bitmap_count_bits (b
));
2672 ASSERT_TRUE (bitmap_bit_p (b
, 149));
2673 ASSERT_FALSE (bitmap_bit_p (b
, 150));
2674 ASSERT_TRUE (bitmap_bit_p (b
, 151));
2677 /* Verify bitmap_copy. */
2682 bitmap src
= bitmap_gc_alloc ();
2683 bitmap_set_range (src
, 40, 10);
2685 bitmap dst
= bitmap_gc_alloc ();
2686 ASSERT_FALSE (bitmap_equal_p (src
, dst
));
2687 bitmap_copy (dst
, src
);
2688 ASSERT_TRUE (bitmap_equal_p (src
, dst
));
2690 /* Verify that we can make them unequal again... */
2691 bitmap_set_range (src
, 70, 5);
2692 ASSERT_FALSE (bitmap_equal_p (src
, dst
));
2694 /* ...and that changing src after the copy didn't affect
2696 ASSERT_FALSE (bitmap_bit_p (dst
, 70));
2699 /* Verify bitmap_single_bit_set_p. */
2702 test_bitmap_single_bit_set_p ()
2704 bitmap b
= bitmap_gc_alloc ();
2706 ASSERT_FALSE (bitmap_single_bit_set_p (b
));
2708 bitmap_set_range (b
, 42, 1);
2709 ASSERT_TRUE (bitmap_single_bit_set_p (b
));
2710 ASSERT_EQ (42, bitmap_first_set_bit (b
));
2712 bitmap_set_range (b
, 1066, 1);
2713 ASSERT_FALSE (bitmap_single_bit_set_p (b
));
2714 ASSERT_EQ (42, bitmap_first_set_bit (b
));
2716 bitmap_clear_range (b
, 0, 100);
2717 ASSERT_TRUE (bitmap_single_bit_set_p (b
));
2718 ASSERT_EQ (1066, bitmap_first_set_bit (b
));
2721 /* Run all of the selftests within this file. */
2728 test_clear_bit_in_middle ();
2730 test_bitmap_single_bit_set_p ();
2733 } // namespace selftest
2734 #endif /* CHECKING_P */
2736 #include "gt-bitmap.h"