1 /* Functions to support general ended bitmaps.
2 Copyright (C) 1997-2019 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 zero-initialized bitmap obstack used for default initialization
31 bitmap_obstack
bitmap_head::crashme
;
33 static bitmap_element
*bitmap_tree_listify_from (bitmap
, bitmap_element
*);
35 /* Register new bitmap. */
37 bitmap_register (bitmap b MEM_STAT_DECL
)
39 bitmap_mem_desc
.register_descriptor (b
, BITMAP_ORIGIN
, false
43 /* Account the overhead. */
45 register_overhead (bitmap b
, size_t amount
)
47 if (bitmap_mem_desc
.contains_descriptor_for_instance (b
))
48 bitmap_mem_desc
.register_instance_overhead (amount
, b
);
52 bitmap_element bitmap_zero_bits
; /* An element of all zero bits. */
53 bitmap_obstack bitmap_default_obstack
; /* The default bitmap obstack. */
54 static int bitmap_default_obstack_depth
;
55 static GTY((deletable
)) bitmap_element
*bitmap_ggc_free
; /* Freelist of
59 /* Bitmap memory management. */
61 /* Add ELT to the appropriate freelist. */
63 bitmap_elem_to_freelist (bitmap head
, bitmap_element
*elt
)
65 bitmap_obstack
*bit_obstack
= head
->obstack
;
67 if (GATHER_STATISTICS
)
68 register_overhead (head
, -((int)sizeof (bitmap_element
)));
74 elt
->prev
= bit_obstack
->elements
;
75 bit_obstack
->elements
= elt
;
79 elt
->prev
= bitmap_ggc_free
;
80 bitmap_ggc_free
= elt
;
84 /* Allocate a bitmap element. The bits are cleared, but nothing else is. */
86 static inline bitmap_element
*
87 bitmap_element_allocate (bitmap head
)
89 bitmap_element
*element
;
90 bitmap_obstack
*bit_obstack
= head
->obstack
;
94 element
= bit_obstack
->elements
;
97 /* Use up the inner list first before looking at the next
98 element of the outer list. */
101 bit_obstack
->elements
= element
->next
;
102 bit_obstack
->elements
->prev
= element
->prev
;
105 /* Inner list was just a singleton. */
106 bit_obstack
->elements
= element
->prev
;
108 element
= XOBNEW (&bit_obstack
->obstack
, bitmap_element
);
112 element
= bitmap_ggc_free
;
114 /* Use up the inner list first before looking at the next
115 element of the outer list. */
118 bitmap_ggc_free
= element
->next
;
119 bitmap_ggc_free
->prev
= element
->prev
;
122 /* Inner list was just a singleton. */
123 bitmap_ggc_free
= element
->prev
;
125 element
= ggc_alloc
<bitmap_element
> ();
128 if (GATHER_STATISTICS
)
129 register_overhead (head
, sizeof (bitmap_element
));
131 memset (element
->bits
, 0, sizeof (element
->bits
));
136 /* Remove ELT and all following elements from bitmap HEAD.
137 Put the released elements in the freelist for HEAD. */
140 bitmap_elt_clear_from (bitmap head
, bitmap_element
*elt
)
142 bitmap_element
*prev
;
143 bitmap_obstack
*bit_obstack
= head
->obstack
;
149 elt
= bitmap_tree_listify_from (head
, elt
);
151 if (GATHER_STATISTICS
)
154 for (prev
= elt
; prev
; prev
= prev
->next
)
156 register_overhead (head
, -sizeof (bitmap_element
) * n
);
163 if (head
->current
->indx
> prev
->indx
)
165 head
->current
= prev
;
166 head
->indx
= prev
->indx
;
172 head
->current
= NULL
;
176 /* Put the entire list onto the freelist in one operation. */
179 elt
->prev
= bit_obstack
->elements
;
180 bit_obstack
->elements
= elt
;
184 elt
->prev
= bitmap_ggc_free
;
185 bitmap_ggc_free
= elt
;
189 /* Linked-list view of bitmaps.
191 In this representation, the bitmap elements form a double-linked list
192 with elements sorted by increasing index. */
194 /* Link the bitmap element into the current bitmap linked list. */
197 bitmap_list_link_element (bitmap head
, bitmap_element
*element
)
199 unsigned int indx
= element
->indx
;
202 gcc_checking_assert (!head
->tree_form
);
204 /* If this is the first and only element, set it in. */
205 if (head
->first
== 0)
207 element
->next
= element
->prev
= 0;
208 head
->first
= element
;
211 /* If this index is less than that of the current element, it goes someplace
212 before the current element. */
213 else if (indx
< head
->indx
)
215 for (ptr
= head
->current
;
216 ptr
->prev
!= 0 && ptr
->prev
->indx
> indx
;
221 ptr
->prev
->next
= element
;
223 head
->first
= element
;
225 element
->prev
= ptr
->prev
;
230 /* Otherwise, it must go someplace after the current element. */
233 for (ptr
= head
->current
;
234 ptr
->next
!= 0 && ptr
->next
->indx
< indx
;
239 ptr
->next
->prev
= element
;
241 element
->next
= ptr
->next
;
246 /* Set up so this is the first element searched. */
247 head
->current
= element
;
251 /* Unlink the bitmap element from the current bitmap linked list,
252 and return it to the freelist. */
255 bitmap_list_unlink_element (bitmap head
, bitmap_element
*element
)
257 bitmap_element
*next
= element
->next
;
258 bitmap_element
*prev
= element
->prev
;
260 gcc_checking_assert (!head
->tree_form
);
268 if (head
->first
== element
)
271 /* Since the first thing we try is to insert before current,
272 make current the next entry in preference to the previous. */
273 if (head
->current
== element
)
275 head
->current
= next
!= 0 ? next
: prev
;
277 head
->indx
= head
->current
->indx
;
282 bitmap_elem_to_freelist (head
, element
);
285 /* Insert a new uninitialized element into bitmap HEAD after element
286 ELT. If ELT is NULL, insert the element at the start. Return the
289 static bitmap_element
*
290 bitmap_list_insert_element_after (bitmap head
,
291 bitmap_element
*elt
, unsigned int indx
)
293 bitmap_element
*node
= bitmap_element_allocate (head
);
296 gcc_checking_assert (!head
->tree_form
);
302 head
->current
= node
;
305 node
->next
= head
->first
;
307 node
->next
->prev
= node
;
313 gcc_checking_assert (head
->current
);
314 node
->next
= elt
->next
;
316 node
->next
->prev
= node
;
323 /* Return the element for INDX, or NULL if the element doesn't exist.
324 Update the `current' field even if we can't find an element that
325 would hold the bitmap's bit to make eventual allocation
328 static inline bitmap_element
*
329 bitmap_list_find_element (bitmap head
, unsigned int indx
)
331 bitmap_element
*element
;
333 if (head
->current
== NULL
334 || head
->indx
== indx
)
335 return head
->current
;
337 if (head
->current
== head
->first
338 && head
->first
->next
== NULL
)
341 /* Usage can be NULL due to allocated bitmaps for which we do not
342 call initialize function. */
343 bitmap_usage
*usage
= NULL
;
344 if (GATHER_STATISTICS
)
345 usage
= bitmap_mem_desc
.get_descriptor_for_instance (head
);
347 /* This bitmap has more than one element, and we're going to look
348 through the elements list. Count that as a search. */
349 if (GATHER_STATISTICS
&& usage
)
350 usage
->m_nsearches
++;
352 if (head
->indx
< indx
)
353 /* INDX is beyond head->indx. Search from head->current
355 for (element
= head
->current
;
356 element
->next
!= 0 && element
->indx
< indx
;
357 element
= element
->next
)
359 if (GATHER_STATISTICS
&& usage
)
360 usage
->m_search_iter
++;
363 else if (head
->indx
/ 2 < indx
)
364 /* INDX is less than head->indx and closer to head->indx than to
365 0. Search from head->current backward. */
366 for (element
= head
->current
;
367 element
->prev
!= 0 && element
->indx
> indx
;
368 element
= element
->prev
)
370 if (GATHER_STATISTICS
&& usage
)
371 usage
->m_search_iter
++;
375 /* INDX is less than head->indx and closer to 0 than to
376 head->indx. Search from head->first forward. */
377 for (element
= head
->first
;
378 element
->next
!= 0 && element
->indx
< indx
;
379 element
= element
->next
)
381 if (GATHER_STATISTICS
&& usage
)
382 usage
->m_search_iter
++;
385 /* `element' is the nearest to the one we want. If it's not the one we
386 want, the one we want doesn't exist. */
387 gcc_checking_assert (element
!= NULL
);
388 head
->current
= element
;
389 head
->indx
= element
->indx
;
390 if (element
->indx
!= indx
)
396 /* Splay-tree view of bitmaps.
398 This is an almost one-to-one the implementatin of the simple top-down
399 splay tree in Sleator and Tarjan's "Self-adjusting Binary Search Trees".
400 It is probably not the most efficient form of splay trees, but it should
401 be good enough to experiment with this idea of bitmaps-as-trees.
403 For all functions below, the variable or function argument "t" is a node
404 in the tree, and "e" is a temporary or new node in the tree. The rest
405 is sufficiently straigh-forward (and very well explained in the paper)
406 that comment would only clutter things. */
409 bitmap_tree_link_left (bitmap_element
* &t
, bitmap_element
* &l
)
417 bitmap_tree_link_right (bitmap_element
* &t
, bitmap_element
* &r
)
425 bitmap_tree_rotate_left (bitmap_element
* &t
)
427 bitmap_element
*e
= t
->next
;
428 t
->next
= t
->next
->prev
;
434 bitmap_tree_rotate_right (bitmap_element
* &t
)
436 bitmap_element
*e
= t
->prev
;
437 t
->prev
= t
->prev
->next
;
442 static bitmap_element
*
443 bitmap_tree_splay (bitmap head
, bitmap_element
*t
, unsigned int indx
)
445 bitmap_element N
, *l
, *r
;
450 bitmap_usage
*usage
= NULL
;
451 if (GATHER_STATISTICS
)
452 usage
= bitmap_mem_desc
.get_descriptor_for_instance (head
);
454 N
.prev
= N
.next
= NULL
;
457 while (indx
!= t
->indx
)
459 if (GATHER_STATISTICS
&& usage
)
460 usage
->m_search_iter
++;
464 if (t
->prev
!= NULL
&& indx
< t
->prev
->indx
)
465 bitmap_tree_rotate_right (t
);
468 bitmap_tree_link_right (t
, r
);
470 else if (indx
> t
->indx
)
472 if (t
->next
!= NULL
&& indx
> t
->next
->indx
)
473 bitmap_tree_rotate_left (t
);
476 bitmap_tree_link_left (t
, l
);
487 /* Link bitmap element E into the current bitmap splay tree. */
490 bitmap_tree_link_element (bitmap head
, bitmap_element
*e
)
492 if (head
->first
== NULL
)
493 e
->prev
= e
->next
= NULL
;
496 bitmap_element
*t
= bitmap_tree_splay (head
, head
->first
, e
->indx
);
497 if (e
->indx
< t
->indx
)
503 else if (e
->indx
> t
->indx
)
514 head
->indx
= e
->indx
;
517 /* Unlink bitmap element E from the current bitmap splay tree,
518 and return it to the freelist. */
521 bitmap_tree_unlink_element (bitmap head
, bitmap_element
*e
)
523 bitmap_element
*t
= bitmap_tree_splay (head
, head
->first
, e
->indx
);
525 gcc_checking_assert (t
== e
);
531 t
= bitmap_tree_splay (head
, e
->prev
, e
->indx
);
536 head
->indx
= (t
!= NULL
) ? t
->indx
: 0;
538 bitmap_elem_to_freelist (head
, e
);
541 /* Return the element for INDX, or NULL if the element doesn't exist. */
543 static inline bitmap_element
*
544 bitmap_tree_find_element (bitmap head
, unsigned int indx
)
546 if (head
->current
== NULL
547 || head
->indx
== indx
)
548 return head
->current
;
550 /* Usage can be NULL due to allocated bitmaps for which we do not
551 call initialize function. */
552 bitmap_usage
*usage
= NULL
;
553 if (GATHER_STATISTICS
)
554 usage
= bitmap_mem_desc
.get_descriptor_for_instance (head
);
556 /* This bitmap has more than one element, and we're going to look
557 through the elements list. Count that as a search. */
558 if (GATHER_STATISTICS
&& usage
)
559 usage
->m_nsearches
++;
561 bitmap_element
*element
= bitmap_tree_splay (head
, head
->first
, indx
);
562 gcc_checking_assert (element
!= NULL
);
563 head
->first
= element
;
564 head
->current
= element
;
565 head
->indx
= element
->indx
;
566 if (element
->indx
!= indx
)
571 /* Converting bitmap views from linked-list to tree and vice versa. */
573 /* Splice element E and all elements with a larger index from
574 bitmap HEAD, convert the spliced elements to the linked-list
575 view, and return the head of the list (which should be E again), */
577 static bitmap_element
*
578 bitmap_tree_listify_from (bitmap head
, bitmap_element
*e
)
580 bitmap_element
*t
, *erb
;
582 /* Detach the right branch from E (all elements with indx > E->indx),
583 and splay E to the root. */
586 t
= bitmap_tree_splay (head
, head
->first
, e
->indx
);
587 gcc_checking_assert (t
== e
);
589 /* Because E has no right branch, and we rotated it to the root,
590 the left branch is the new root. */
594 head
->indx
= (t
!= NULL
) ? t
->indx
: 0;
596 /* Detach the tree from E, and re-attach the right branch of E. */
600 /* The tree is now valid again. Now we need to "un-tree" E.
601 It is imperative that a non-recursive implementation is used
602 for this, because splay trees have a worst case depth of O(N)
603 for a tree with N nodes. A recursive implementation could
604 result in a stack overflow for a sufficiently large, unbalanced
607 auto_vec
<bitmap_element
*, 32> stack
;
608 auto_vec
<bitmap_element
*, 32> sorted_elements
;
609 bitmap_element
*n
= e
;
619 if (stack
.is_empty ())
623 sorted_elements
.safe_push (n
);
627 gcc_assert (sorted_elements
[0] == e
);
629 bitmap_element
*prev
= NULL
;
631 FOR_EACH_VEC_ELT (sorted_elements
, ix
, n
)
643 /* Convert bitmap HEAD from splay-tree view to linked-list view. */
646 bitmap_list_view (bitmap head
)
650 gcc_assert (head
->tree_form
);
656 bitmap_tree_rotate_right (ptr
);
658 head
->first
= bitmap_tree_listify_from (head
, ptr
);
661 head
->tree_form
= false;
664 /* Convert bitmap HEAD from linked-list view to splay-tree view.
665 This is simply a matter of dropping the prev or next pointers
666 and setting the tree_form flag. The tree will balance itself
667 if and when it is used. */
670 bitmap_tree_view (bitmap head
)
674 gcc_assert (! head
->tree_form
);
683 head
->tree_form
= true;
686 /* Clear a bitmap by freeing all its elements. */
689 bitmap_clear (bitmap head
)
691 if (head
->first
== NULL
)
695 bitmap_element
*e
, *t
;
696 for (e
= head
->first
; e
->prev
; e
= e
->prev
)
697 /* Loop to find the element with the smallest index. */ ;
698 t
= bitmap_tree_splay (head
, head
->first
, e
->indx
);
699 gcc_checking_assert (t
== e
);
702 bitmap_elt_clear_from (head
, head
->first
);
705 /* Initialize a bitmap obstack. If BIT_OBSTACK is NULL, initialize
706 the default bitmap obstack. */
709 bitmap_obstack_initialize (bitmap_obstack
*bit_obstack
)
713 if (bitmap_default_obstack_depth
++)
715 bit_obstack
= &bitmap_default_obstack
;
718 #if !defined(__GNUC__) || (__GNUC__ < 2)
719 #define __alignof__(type) 0
722 bit_obstack
->elements
= NULL
;
723 bit_obstack
->heads
= NULL
;
724 obstack_specify_allocation (&bit_obstack
->obstack
, OBSTACK_CHUNK_SIZE
,
725 __alignof__ (bitmap_element
),
730 /* Release the memory from a bitmap obstack. If BIT_OBSTACK is NULL,
731 release the default bitmap obstack. */
734 bitmap_obstack_release (bitmap_obstack
*bit_obstack
)
738 if (--bitmap_default_obstack_depth
)
740 gcc_assert (bitmap_default_obstack_depth
> 0);
743 bit_obstack
= &bitmap_default_obstack
;
746 bit_obstack
->elements
= NULL
;
747 bit_obstack
->heads
= NULL
;
748 obstack_free (&bit_obstack
->obstack
, NULL
);
751 /* Create a new bitmap on an obstack. If BIT_OBSTACK is NULL, create
752 it on the default bitmap obstack. */
755 bitmap_alloc (bitmap_obstack
*bit_obstack MEM_STAT_DECL
)
760 bit_obstack
= &bitmap_default_obstack
;
761 map
= bit_obstack
->heads
;
763 bit_obstack
->heads
= (struct bitmap_head
*) map
->first
;
765 map
= XOBNEW (&bit_obstack
->obstack
, bitmap_head
);
766 bitmap_initialize (map
, bit_obstack PASS_MEM_STAT
);
768 if (GATHER_STATISTICS
)
769 register_overhead (map
, sizeof (bitmap_head
));
774 /* Create a new GCd bitmap. */
777 bitmap_gc_alloc (ALONE_MEM_STAT_DECL
)
781 map
= ggc_alloc
<bitmap_head
> ();
782 bitmap_initialize (map
, NULL PASS_MEM_STAT
);
784 if (GATHER_STATISTICS
)
785 register_overhead (map
, sizeof (bitmap_head
));
790 /* Release an obstack allocated bitmap. */
793 bitmap_obstack_free (bitmap map
)
798 map
->first
= (bitmap_element
*) map
->obstack
->heads
;
800 if (GATHER_STATISTICS
)
801 register_overhead (map
, -((int)sizeof (bitmap_head
)));
803 map
->obstack
->heads
= map
;
808 /* Return nonzero if all bits in an element are zero. */
811 bitmap_element_zerop (const bitmap_element
*element
)
813 #if BITMAP_ELEMENT_WORDS == 2
814 return (element
->bits
[0] | element
->bits
[1]) == 0;
818 for (i
= 0; i
< BITMAP_ELEMENT_WORDS
; i
++)
819 if (element
->bits
[i
] != 0)
826 /* Copy a bitmap to another bitmap. */
829 bitmap_copy (bitmap to
, const_bitmap from
)
831 const bitmap_element
*from_ptr
;
832 bitmap_element
*to_ptr
= 0;
834 gcc_checking_assert (!to
->tree_form
&& !from
->tree_form
);
838 /* Copy elements in forward direction one at a time. */
839 for (from_ptr
= from
->first
; from_ptr
; from_ptr
= from_ptr
->next
)
841 bitmap_element
*to_elt
= bitmap_element_allocate (to
);
843 to_elt
->indx
= from_ptr
->indx
;
844 memcpy (to_elt
->bits
, from_ptr
->bits
, sizeof (to_elt
->bits
));
846 /* Here we have a special case of bitmap_list_link_element,
847 for the case where we know the links are being entered
851 to
->first
= to
->current
= to_elt
;
852 to
->indx
= from_ptr
->indx
;
853 to_elt
->next
= to_elt
->prev
= 0;
857 to_elt
->prev
= to_ptr
;
859 to_ptr
->next
= to_elt
;
866 /* Move a bitmap to another bitmap. */
869 bitmap_move (bitmap to
, bitmap from
)
871 gcc_assert (to
->obstack
== from
->obstack
);
877 if (GATHER_STATISTICS
)
880 for (bitmap_element
*e
= to
->first
; e
; e
= e
->next
)
881 sz
+= sizeof (bitmap_element
);
882 register_overhead (to
, sz
);
883 register_overhead (from
, -sz
);
887 /* Clear a single bit in a bitmap. Return true if the bit changed. */
890 bitmap_clear_bit (bitmap head
, int bit
)
892 unsigned int indx
= bit
/ BITMAP_ELEMENT_ALL_BITS
;
895 if (!head
->tree_form
)
896 ptr
= bitmap_list_find_element (head
, indx
);
898 ptr
= bitmap_tree_find_element (head
, indx
);
901 unsigned bit_num
= bit
% BITMAP_WORD_BITS
;
902 unsigned word_num
= bit
/ BITMAP_WORD_BITS
% BITMAP_ELEMENT_WORDS
;
903 BITMAP_WORD bit_val
= ((BITMAP_WORD
) 1) << bit_num
;
904 bool res
= (ptr
->bits
[word_num
] & bit_val
) != 0;
907 ptr
->bits
[word_num
] &= ~bit_val
;
908 /* If we cleared the entire word, free up the element. */
909 if (!ptr
->bits
[word_num
]
910 && bitmap_element_zerop (ptr
))
912 if (!head
->tree_form
)
913 bitmap_list_unlink_element (head
, ptr
);
915 bitmap_tree_unlink_element (head
, ptr
);
925 /* Set a single bit in a bitmap. Return true if the bit changed. */
928 bitmap_set_bit (bitmap head
, int bit
)
930 unsigned indx
= bit
/ BITMAP_ELEMENT_ALL_BITS
;
932 if (!head
->tree_form
)
933 ptr
= bitmap_list_find_element (head
, indx
);
935 ptr
= bitmap_tree_find_element (head
, indx
);
936 unsigned word_num
= bit
/ BITMAP_WORD_BITS
% BITMAP_ELEMENT_WORDS
;
937 unsigned bit_num
= bit
% BITMAP_WORD_BITS
;
938 BITMAP_WORD bit_val
= ((BITMAP_WORD
) 1) << bit_num
;
942 bool res
= (ptr
->bits
[word_num
] & bit_val
) == 0;
944 ptr
->bits
[word_num
] |= bit_val
;
948 ptr
= bitmap_element_allocate (head
);
949 ptr
->indx
= bit
/ BITMAP_ELEMENT_ALL_BITS
;
950 ptr
->bits
[word_num
] = bit_val
;
951 if (!head
->tree_form
)
952 bitmap_list_link_element (head
, ptr
);
954 bitmap_tree_link_element (head
, ptr
);
958 /* Return whether a bit is set within a bitmap. */
961 bitmap_bit_p (bitmap head
, int bit
)
963 unsigned int indx
= bit
/ BITMAP_ELEMENT_ALL_BITS
;
968 if (!head
->tree_form
)
969 ptr
= bitmap_list_find_element (head
, indx
);
971 ptr
= bitmap_tree_find_element (head
, indx
);
975 bit_num
= bit
% BITMAP_WORD_BITS
;
976 word_num
= bit
/ BITMAP_WORD_BITS
% BITMAP_ELEMENT_WORDS
;
978 return (ptr
->bits
[word_num
] >> bit_num
) & 1;
981 #if GCC_VERSION < 3400
982 /* Table of number of set bits in a character, indexed by value of char. */
983 static const unsigned char popcount_table
[] =
985 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,
986 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,
987 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,
988 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,
989 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,
990 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,
991 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,
992 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,
996 bitmap_popcount (BITMAP_WORD a
)
998 unsigned long ret
= 0;
1001 /* Just do this the table way for now */
1002 for (i
= 0; i
< BITMAP_WORD_BITS
; i
+= 8)
1003 ret
+= popcount_table
[(a
>> i
) & 0xff];
1008 /* Count and return the number of bits set in the bitmap word BITS. */
1009 static unsigned long
1010 bitmap_count_bits_in_word (const BITMAP_WORD
*bits
)
1012 unsigned long count
= 0;
1014 for (unsigned ix
= 0; ix
!= BITMAP_ELEMENT_WORDS
; ix
++)
1016 #if GCC_VERSION >= 3400
1017 /* Note that popcountl matches BITMAP_WORD in type, so the actual size
1018 of BITMAP_WORD is not material. */
1019 count
+= __builtin_popcountl (bits
[ix
]);
1021 count
+= bitmap_popcount (bits
[ix
]);
1027 /* Count the number of bits set in the bitmap, and return it. */
1030 bitmap_count_bits (const_bitmap a
)
1032 unsigned long count
= 0;
1033 const bitmap_element
*elt
;
1035 gcc_checking_assert (!a
->tree_form
);
1036 for (elt
= a
->first
; elt
; elt
= elt
->next
)
1037 count
+= bitmap_count_bits_in_word (elt
->bits
);
1042 /* Count the number of unique bits set in A and B and return it. */
1045 bitmap_count_unique_bits (const_bitmap a
, const_bitmap b
)
1047 unsigned long count
= 0;
1048 const bitmap_element
*elt_a
, *elt_b
;
1050 for (elt_a
= a
->first
, elt_b
= b
->first
; elt_a
&& elt_b
; )
1052 /* If we're at different indices, then count all the bits
1053 in the lower element. If we're at the same index, then
1054 count the bits in the IOR of the two elements. */
1055 if (elt_a
->indx
< elt_b
->indx
)
1057 count
+= bitmap_count_bits_in_word (elt_a
->bits
);
1058 elt_a
= elt_a
->next
;
1060 else if (elt_b
->indx
< elt_a
->indx
)
1062 count
+= bitmap_count_bits_in_word (elt_b
->bits
);
1063 elt_b
= elt_b
->next
;
1067 BITMAP_WORD bits
[BITMAP_ELEMENT_WORDS
];
1068 for (unsigned ix
= 0; ix
!= BITMAP_ELEMENT_WORDS
; ix
++)
1069 bits
[ix
] = elt_a
->bits
[ix
] | elt_b
->bits
[ix
];
1070 count
+= bitmap_count_bits_in_word (bits
);
1071 elt_a
= elt_a
->next
;
1072 elt_b
= elt_b
->next
;
1078 /* Return true if the bitmap has a single bit set. Otherwise return
1082 bitmap_single_bit_set_p (const_bitmap a
)
1084 unsigned long count
= 0;
1085 const bitmap_element
*elt
;
1088 if (bitmap_empty_p (a
))
1093 /* As there are no completely empty bitmap elements, a second one
1094 means we have more than one bit set. */
1095 if (elt
->next
!= NULL
1096 && (!a
->tree_form
|| elt
->prev
!= NULL
))
1099 for (ix
= 0; ix
!= BITMAP_ELEMENT_WORDS
; ix
++)
1101 #if GCC_VERSION >= 3400
1102 /* Note that popcountl matches BITMAP_WORD in type, so the actual size
1103 of BITMAP_WORD is not material. */
1104 count
+= __builtin_popcountl (elt
->bits
[ix
]);
1106 count
+= bitmap_popcount (elt
->bits
[ix
]);
1116 /* Return the bit number of the first set bit in the bitmap. The
1117 bitmap must be non-empty. */
1120 bitmap_first_set_bit (const_bitmap a
)
1122 const bitmap_element
*elt
= a
->first
;
1127 gcc_checking_assert (elt
);
1133 bit_no
= elt
->indx
* BITMAP_ELEMENT_ALL_BITS
;
1134 for (ix
= 0; ix
!= BITMAP_ELEMENT_WORDS
; ix
++)
1136 word
= elt
->bits
[ix
];
1142 bit_no
+= ix
* BITMAP_WORD_BITS
;
1144 #if GCC_VERSION >= 3004
1145 gcc_assert (sizeof (long) == sizeof (word
));
1146 bit_no
+= __builtin_ctzl (word
);
1148 /* Binary search for the first set bit. */
1149 #if BITMAP_WORD_BITS > 64
1150 #error "Fill out the table."
1152 #if BITMAP_WORD_BITS > 32
1153 if (!(word
& 0xffffffff))
1154 word
>>= 32, bit_no
+= 32;
1156 if (!(word
& 0xffff))
1157 word
>>= 16, bit_no
+= 16;
1159 word
>>= 8, bit_no
+= 8;
1161 word
>>= 4, bit_no
+= 4;
1163 word
>>= 2, bit_no
+= 2;
1165 word
>>= 1, bit_no
+= 1;
1167 gcc_checking_assert (word
& 1);
1172 /* Return the bit number of the first set bit in the bitmap. The
1173 bitmap must be non-empty. */
1176 bitmap_last_set_bit (const_bitmap a
)
1178 const bitmap_element
*elt
;
1186 elt
= a
->current
? a
->current
: a
->first
;
1187 gcc_checking_assert (elt
);
1192 bit_no
= elt
->indx
* BITMAP_ELEMENT_ALL_BITS
;
1193 for (ix
= BITMAP_ELEMENT_WORDS
- 1; ix
>= 1; ix
--)
1195 word
= elt
->bits
[ix
];
1199 gcc_assert (elt
->bits
[ix
] != 0);
1201 bit_no
+= ix
* BITMAP_WORD_BITS
;
1202 #if GCC_VERSION >= 3004
1203 gcc_assert (sizeof (long) == sizeof (word
));
1204 bit_no
+= BITMAP_WORD_BITS
- __builtin_clzl (word
) - 1;
1206 /* Hopefully this is a twos-complement host... */
1207 BITMAP_WORD x
= word
;
1213 #if BITMAP_WORD_BITS > 32
1216 bit_no
+= bitmap_popcount (x
) - 1;
1226 bitmap_and (bitmap dst
, const_bitmap a
, const_bitmap b
)
1228 bitmap_element
*dst_elt
= dst
->first
;
1229 const bitmap_element
*a_elt
= a
->first
;
1230 const bitmap_element
*b_elt
= b
->first
;
1231 bitmap_element
*dst_prev
= NULL
;
1233 gcc_checking_assert (!dst
->tree_form
&& !a
->tree_form
&& !b
->tree_form
);
1234 gcc_assert (dst
!= a
&& dst
!= b
);
1238 bitmap_copy (dst
, a
);
1242 while (a_elt
&& b_elt
)
1244 if (a_elt
->indx
< b_elt
->indx
)
1245 a_elt
= a_elt
->next
;
1246 else if (b_elt
->indx
< a_elt
->indx
)
1247 b_elt
= b_elt
->next
;
1250 /* Matching elts, generate A & B. */
1252 BITMAP_WORD ior
= 0;
1255 dst_elt
= bitmap_list_insert_element_after (dst
, dst_prev
,
1258 dst_elt
->indx
= a_elt
->indx
;
1259 for (ix
= 0; ix
< BITMAP_ELEMENT_WORDS
; ix
++)
1261 BITMAP_WORD r
= a_elt
->bits
[ix
] & b_elt
->bits
[ix
];
1263 dst_elt
->bits
[ix
] = r
;
1269 dst_elt
= dst_elt
->next
;
1271 a_elt
= a_elt
->next
;
1272 b_elt
= b_elt
->next
;
1275 /* Ensure that dst->current is valid. */
1276 dst
->current
= dst
->first
;
1277 bitmap_elt_clear_from (dst
, dst_elt
);
1278 gcc_checking_assert (!dst
->current
== !dst
->first
);
1280 dst
->indx
= dst
->current
->indx
;
1283 /* A &= B. Return true if A changed. */
1286 bitmap_and_into (bitmap a
, const_bitmap b
)
1288 bitmap_element
*a_elt
= a
->first
;
1289 const bitmap_element
*b_elt
= b
->first
;
1290 bitmap_element
*next
;
1291 bool changed
= false;
1293 gcc_checking_assert (!a
->tree_form
&& !b
->tree_form
);
1298 while (a_elt
&& b_elt
)
1300 if (a_elt
->indx
< b_elt
->indx
)
1303 bitmap_list_unlink_element (a
, a_elt
);
1307 else if (b_elt
->indx
< a_elt
->indx
)
1308 b_elt
= b_elt
->next
;
1311 /* Matching elts, generate A &= B. */
1313 BITMAP_WORD ior
= 0;
1315 for (ix
= 0; ix
< BITMAP_ELEMENT_WORDS
; ix
++)
1317 BITMAP_WORD r
= a_elt
->bits
[ix
] & b_elt
->bits
[ix
];
1318 if (a_elt
->bits
[ix
] != r
)
1320 a_elt
->bits
[ix
] = r
;
1325 bitmap_list_unlink_element (a
, a_elt
);
1327 b_elt
= b_elt
->next
;
1334 bitmap_elt_clear_from (a
, a_elt
);
1337 gcc_checking_assert (!a
->current
== !a
->first
1338 && (!a
->current
|| a
->indx
== a
->current
->indx
));
1344 /* Insert an element equal to SRC_ELT after DST_PREV, overwriting DST_ELT
1345 if non-NULL. CHANGED is true if the destination bitmap had already been
1346 changed; the new value of CHANGED is returned. */
1349 bitmap_elt_copy (bitmap dst
, bitmap_element
*dst_elt
, bitmap_element
*dst_prev
,
1350 const bitmap_element
*src_elt
, bool changed
)
1352 if (!changed
&& dst_elt
&& dst_elt
->indx
== src_elt
->indx
)
1356 for (ix
= 0; ix
< BITMAP_ELEMENT_WORDS
; ix
++)
1357 if (src_elt
->bits
[ix
] != dst_elt
->bits
[ix
])
1359 dst_elt
->bits
[ix
] = src_elt
->bits
[ix
];
1367 dst_elt
= bitmap_list_insert_element_after (dst
, dst_prev
,
1370 dst_elt
->indx
= src_elt
->indx
;
1371 memcpy (dst_elt
->bits
, src_elt
->bits
, sizeof (dst_elt
->bits
));
1381 bitmap_and_compl (bitmap dst
, const_bitmap a
, const_bitmap b
)
1383 bitmap_element
*dst_elt
= dst
->first
;
1384 const bitmap_element
*a_elt
= a
->first
;
1385 const bitmap_element
*b_elt
= b
->first
;
1386 bitmap_element
*dst_prev
= NULL
;
1387 bitmap_element
**dst_prev_pnext
= &dst
->first
;
1388 bool changed
= false;
1390 gcc_checking_assert (!dst
->tree_form
&& !a
->tree_form
&& !b
->tree_form
);
1391 gcc_assert (dst
!= a
&& dst
!= b
);
1395 changed
= !bitmap_empty_p (dst
);
1402 while (b_elt
&& b_elt
->indx
< a_elt
->indx
)
1403 b_elt
= b_elt
->next
;
1405 if (!b_elt
|| b_elt
->indx
> a_elt
->indx
)
1407 changed
= bitmap_elt_copy (dst
, dst_elt
, dst_prev
, a_elt
, changed
);
1408 dst_prev
= *dst_prev_pnext
;
1409 dst_prev_pnext
= &dst_prev
->next
;
1410 dst_elt
= *dst_prev_pnext
;
1411 a_elt
= a_elt
->next
;
1416 /* Matching elts, generate A & ~B. */
1418 BITMAP_WORD ior
= 0;
1420 if (!changed
&& dst_elt
&& dst_elt
->indx
== a_elt
->indx
)
1422 for (ix
= 0; ix
< BITMAP_ELEMENT_WORDS
; ix
++)
1424 BITMAP_WORD r
= a_elt
->bits
[ix
] & ~b_elt
->bits
[ix
];
1426 if (dst_elt
->bits
[ix
] != r
)
1429 dst_elt
->bits
[ix
] = r
;
1437 if (!dst_elt
|| dst_elt
->indx
> a_elt
->indx
)
1439 dst_elt
= bitmap_list_insert_element_after (dst
, dst_prev
,
1445 dst_elt
->indx
= a_elt
->indx
;
1446 new_element
= false;
1449 for (ix
= 0; ix
< BITMAP_ELEMENT_WORDS
; ix
++)
1451 BITMAP_WORD r
= a_elt
->bits
[ix
] & ~b_elt
->bits
[ix
];
1453 dst_elt
->bits
[ix
] = r
;
1461 changed
|= !new_element
;
1462 bitmap_list_unlink_element (dst
, dst_elt
);
1463 dst_elt
= *dst_prev_pnext
;
1469 dst_prev
= *dst_prev_pnext
;
1470 dst_prev_pnext
= &dst_prev
->next
;
1471 dst_elt
= *dst_prev_pnext
;
1473 a_elt
= a_elt
->next
;
1474 b_elt
= b_elt
->next
;
1478 /* Ensure that dst->current is valid. */
1479 dst
->current
= dst
->first
;
1484 bitmap_elt_clear_from (dst
, dst_elt
);
1486 gcc_checking_assert (!dst
->current
== !dst
->first
);
1488 dst
->indx
= dst
->current
->indx
;
1493 /* A &= ~B. Returns true if A changes */
1496 bitmap_and_compl_into (bitmap a
, const_bitmap b
)
1498 bitmap_element
*a_elt
= a
->first
;
1499 const bitmap_element
*b_elt
= b
->first
;
1500 bitmap_element
*next
;
1501 BITMAP_WORD changed
= 0;
1503 gcc_checking_assert (!a
->tree_form
&& !b
->tree_form
);
1507 if (bitmap_empty_p (a
))
1516 while (a_elt
&& b_elt
)
1518 if (a_elt
->indx
< b_elt
->indx
)
1519 a_elt
= a_elt
->next
;
1520 else if (b_elt
->indx
< a_elt
->indx
)
1521 b_elt
= b_elt
->next
;
1524 /* Matching elts, generate A &= ~B. */
1526 BITMAP_WORD ior
= 0;
1528 for (ix
= 0; ix
< BITMAP_ELEMENT_WORDS
; ix
++)
1530 BITMAP_WORD cleared
= a_elt
->bits
[ix
] & b_elt
->bits
[ix
];
1531 BITMAP_WORD r
= a_elt
->bits
[ix
] ^ cleared
;
1533 a_elt
->bits
[ix
] = r
;
1539 bitmap_list_unlink_element (a
, a_elt
);
1541 b_elt
= b_elt
->next
;
1544 gcc_checking_assert (!a
->current
== !a
->first
1545 && (!a
->current
|| a
->indx
== a
->current
->indx
));
1546 return changed
!= 0;
1549 /* Set COUNT bits from START in HEAD. */
1551 bitmap_set_range (bitmap head
, unsigned int start
, unsigned int count
)
1553 unsigned int first_index
, end_bit_plus1
, last_index
;
1554 bitmap_element
*elt
, *elt_prev
;
1557 gcc_checking_assert (!head
->tree_form
);
1564 bitmap_set_bit (head
, start
);
1568 first_index
= start
/ BITMAP_ELEMENT_ALL_BITS
;
1569 end_bit_plus1
= start
+ count
;
1570 last_index
= (end_bit_plus1
- 1) / BITMAP_ELEMENT_ALL_BITS
;
1571 elt
= bitmap_list_find_element (head
, first_index
);
1573 /* If bitmap_list_find_element returns zero, the current is the closest block
1574 to the result. Otherwise, just use bitmap_element_allocate to
1575 ensure ELT is set; in the loop below, ELT == NULL means "insert
1576 at the end of the bitmap". */
1579 elt
= bitmap_element_allocate (head
);
1580 elt
->indx
= first_index
;
1581 bitmap_list_link_element (head
, elt
);
1584 gcc_checking_assert (elt
->indx
== first_index
);
1585 elt_prev
= elt
->prev
;
1586 for (i
= first_index
; i
<= last_index
; i
++)
1588 unsigned elt_start_bit
= i
* BITMAP_ELEMENT_ALL_BITS
;
1589 unsigned elt_end_bit_plus1
= elt_start_bit
+ BITMAP_ELEMENT_ALL_BITS
;
1591 unsigned int first_word_to_mod
;
1592 BITMAP_WORD first_mask
;
1593 unsigned int last_word_to_mod
;
1594 BITMAP_WORD last_mask
;
1597 if (!elt
|| elt
->indx
!= i
)
1598 elt
= bitmap_list_insert_element_after (head
, elt_prev
, i
);
1600 if (elt_start_bit
<= start
)
1602 /* The first bit to turn on is somewhere inside this
1604 first_word_to_mod
= (start
- elt_start_bit
) / BITMAP_WORD_BITS
;
1606 /* This mask should have 1s in all bits >= start position. */
1608 (((BITMAP_WORD
) 1) << ((start
% BITMAP_WORD_BITS
))) - 1;
1609 first_mask
= ~first_mask
;
1613 /* The first bit to turn on is below this start of this elt. */
1614 first_word_to_mod
= 0;
1615 first_mask
= ~(BITMAP_WORD
) 0;
1618 if (elt_end_bit_plus1
<= end_bit_plus1
)
1620 /* The last bit to turn on is beyond this elt. */
1621 last_word_to_mod
= BITMAP_ELEMENT_WORDS
- 1;
1622 last_mask
= ~(BITMAP_WORD
) 0;
1626 /* The last bit to turn on is inside to this elt. */
1628 (end_bit_plus1
- elt_start_bit
) / BITMAP_WORD_BITS
;
1630 /* The last mask should have 1s below the end bit. */
1632 (((BITMAP_WORD
) 1) << ((end_bit_plus1
% BITMAP_WORD_BITS
))) - 1;
1635 if (first_word_to_mod
== last_word_to_mod
)
1637 BITMAP_WORD mask
= first_mask
& last_mask
;
1638 elt
->bits
[first_word_to_mod
] |= mask
;
1642 elt
->bits
[first_word_to_mod
] |= first_mask
;
1643 if (BITMAP_ELEMENT_WORDS
> 2)
1644 for (ix
= first_word_to_mod
+ 1; ix
< last_word_to_mod
; ix
++)
1645 elt
->bits
[ix
] = ~(BITMAP_WORD
) 0;
1646 elt
->bits
[last_word_to_mod
] |= last_mask
;
1653 head
->current
= elt
? elt
: elt_prev
;
1654 head
->indx
= head
->current
->indx
;
1657 /* Clear COUNT bits from START in HEAD. */
1659 bitmap_clear_range (bitmap head
, unsigned int start
, unsigned int count
)
1661 unsigned int first_index
, end_bit_plus1
, last_index
;
1662 bitmap_element
*elt
;
1664 gcc_checking_assert (!head
->tree_form
);
1671 bitmap_clear_bit (head
, start
);
1675 first_index
= start
/ BITMAP_ELEMENT_ALL_BITS
;
1676 end_bit_plus1
= start
+ count
;
1677 last_index
= (end_bit_plus1
- 1) / BITMAP_ELEMENT_ALL_BITS
;
1678 elt
= bitmap_list_find_element (head
, first_index
);
1680 /* If bitmap_list_find_element returns zero, the current is the closest block
1681 to the result. If the current is less than first index, find the
1682 next one. Otherwise, just set elt to be current. */
1687 if (head
->indx
< first_index
)
1689 elt
= head
->current
->next
;
1694 elt
= head
->current
;
1700 while (elt
&& (elt
->indx
<= last_index
))
1702 bitmap_element
* next_elt
= elt
->next
;
1703 unsigned elt_start_bit
= (elt
->indx
) * BITMAP_ELEMENT_ALL_BITS
;
1704 unsigned elt_end_bit_plus1
= elt_start_bit
+ BITMAP_ELEMENT_ALL_BITS
;
1707 if (elt_start_bit
>= start
&& elt_end_bit_plus1
<= end_bit_plus1
)
1708 /* Get rid of the entire elt and go to the next one. */
1709 bitmap_list_unlink_element (head
, elt
);
1712 /* Going to have to knock out some bits in this elt. */
1713 unsigned int first_word_to_mod
;
1714 BITMAP_WORD first_mask
;
1715 unsigned int last_word_to_mod
;
1716 BITMAP_WORD last_mask
;
1720 if (elt_start_bit
<= start
)
1722 /* The first bit to turn off is somewhere inside this
1724 first_word_to_mod
= (start
- elt_start_bit
) / BITMAP_WORD_BITS
;
1726 /* This mask should have 1s in all bits >= start position. */
1728 (((BITMAP_WORD
) 1) << ((start
% BITMAP_WORD_BITS
))) - 1;
1729 first_mask
= ~first_mask
;
1733 /* The first bit to turn off is below this start of this elt. */
1734 first_word_to_mod
= 0;
1736 first_mask
= ~first_mask
;
1739 if (elt_end_bit_plus1
<= end_bit_plus1
)
1741 /* The last bit to turn off is beyond this elt. */
1742 last_word_to_mod
= BITMAP_ELEMENT_WORDS
- 1;
1744 last_mask
= ~last_mask
;
1748 /* The last bit to turn off is inside to this elt. */
1750 (end_bit_plus1
- elt_start_bit
) / BITMAP_WORD_BITS
;
1752 /* The last mask should have 1s below the end bit. */
1754 (((BITMAP_WORD
) 1) << (((end_bit_plus1
) % BITMAP_WORD_BITS
))) - 1;
1758 if (first_word_to_mod
== last_word_to_mod
)
1760 BITMAP_WORD mask
= first_mask
& last_mask
;
1761 elt
->bits
[first_word_to_mod
] &= ~mask
;
1765 elt
->bits
[first_word_to_mod
] &= ~first_mask
;
1766 if (BITMAP_ELEMENT_WORDS
> 2)
1767 for (i
= first_word_to_mod
+ 1; i
< last_word_to_mod
; i
++)
1769 elt
->bits
[last_word_to_mod
] &= ~last_mask
;
1771 for (i
= 0; i
< BITMAP_ELEMENT_WORDS
; i
++)
1777 /* Check to see if there are any bits left. */
1779 bitmap_list_unlink_element (head
, elt
);
1786 head
->current
= elt
;
1787 head
->indx
= head
->current
->indx
;
1794 bitmap_compl_and_into (bitmap a
, const_bitmap b
)
1796 bitmap_element
*a_elt
= a
->first
;
1797 const bitmap_element
*b_elt
= b
->first
;
1798 bitmap_element
*a_prev
= NULL
;
1799 bitmap_element
*next
;
1801 gcc_checking_assert (!a
->tree_form
&& !b
->tree_form
);
1802 gcc_assert (a
!= b
);
1804 if (bitmap_empty_p (a
))
1809 if (bitmap_empty_p (b
))
1815 while (a_elt
|| b_elt
)
1817 if (!b_elt
|| (a_elt
&& a_elt
->indx
< b_elt
->indx
))
1819 /* A is before B. Remove A */
1821 a_prev
= a_elt
->prev
;
1822 bitmap_list_unlink_element (a
, a_elt
);
1825 else if (!a_elt
|| b_elt
->indx
< a_elt
->indx
)
1827 /* B is before A. Copy B. */
1828 next
= bitmap_list_insert_element_after (a
, a_prev
, b_elt
->indx
);
1829 memcpy (next
->bits
, b_elt
->bits
, sizeof (next
->bits
));
1831 b_elt
= b_elt
->next
;
1835 /* Matching elts, generate A = ~A & B. */
1837 BITMAP_WORD ior
= 0;
1839 for (ix
= 0; ix
< BITMAP_ELEMENT_WORDS
; ix
++)
1841 BITMAP_WORD cleared
= a_elt
->bits
[ix
] & b_elt
->bits
[ix
];
1842 BITMAP_WORD r
= b_elt
->bits
[ix
] ^ cleared
;
1844 a_elt
->bits
[ix
] = r
;
1849 bitmap_list_unlink_element (a
, a_elt
);
1853 b_elt
= b_elt
->next
;
1856 gcc_checking_assert (!a
->current
== !a
->first
1857 && (!a
->current
|| a
->indx
== a
->current
->indx
));
1862 /* Insert an element corresponding to A_ELT | B_ELT after DST_PREV,
1863 overwriting DST_ELT if non-NULL. CHANGED is true if the destination bitmap
1864 had already been changed; the new value of CHANGED is returned. */
1867 bitmap_elt_ior (bitmap dst
, bitmap_element
*dst_elt
, bitmap_element
*dst_prev
,
1868 const bitmap_element
*a_elt
, const bitmap_element
*b_elt
,
1871 gcc_assert (a_elt
|| b_elt
);
1873 if (a_elt
&& b_elt
&& a_elt
->indx
== b_elt
->indx
)
1875 /* Matching elts, generate A | B. */
1878 if (!changed
&& dst_elt
&& dst_elt
->indx
== a_elt
->indx
)
1880 for (ix
= 0; ix
< BITMAP_ELEMENT_WORDS
; ix
++)
1882 BITMAP_WORD r
= a_elt
->bits
[ix
] | b_elt
->bits
[ix
];
1883 if (r
!= dst_elt
->bits
[ix
])
1885 dst_elt
->bits
[ix
] = r
;
1894 dst_elt
= bitmap_list_insert_element_after (dst
, dst_prev
,
1897 dst_elt
->indx
= a_elt
->indx
;
1898 for (ix
= 0; ix
< BITMAP_ELEMENT_WORDS
; ix
++)
1900 BITMAP_WORD r
= a_elt
->bits
[ix
] | b_elt
->bits
[ix
];
1901 dst_elt
->bits
[ix
] = r
;
1907 /* Copy a single element. */
1908 const bitmap_element
*src
;
1910 if (!b_elt
|| (a_elt
&& a_elt
->indx
< b_elt
->indx
))
1915 gcc_checking_assert (src
);
1916 changed
= bitmap_elt_copy (dst
, dst_elt
, dst_prev
, src
, changed
);
1922 /* DST = A | B. Return true if DST changes. */
1925 bitmap_ior (bitmap dst
, const_bitmap a
, const_bitmap b
)
1927 bitmap_element
*dst_elt
= dst
->first
;
1928 const bitmap_element
*a_elt
= a
->first
;
1929 const bitmap_element
*b_elt
= b
->first
;
1930 bitmap_element
*dst_prev
= NULL
;
1931 bitmap_element
**dst_prev_pnext
= &dst
->first
;
1932 bool changed
= false;
1934 gcc_checking_assert (!dst
->tree_form
&& !a
->tree_form
&& !b
->tree_form
);
1935 gcc_assert (dst
!= a
&& dst
!= b
);
1937 while (a_elt
|| b_elt
)
1939 changed
= bitmap_elt_ior (dst
, dst_elt
, dst_prev
, a_elt
, b_elt
, changed
);
1941 if (a_elt
&& b_elt
&& a_elt
->indx
== b_elt
->indx
)
1943 a_elt
= a_elt
->next
;
1944 b_elt
= b_elt
->next
;
1948 if (a_elt
&& (!b_elt
|| a_elt
->indx
<= b_elt
->indx
))
1949 a_elt
= a_elt
->next
;
1950 else if (b_elt
&& (!a_elt
|| b_elt
->indx
<= a_elt
->indx
))
1951 b_elt
= b_elt
->next
;
1954 dst_prev
= *dst_prev_pnext
;
1955 dst_prev_pnext
= &dst_prev
->next
;
1956 dst_elt
= *dst_prev_pnext
;
1962 /* Ensure that dst->current is valid. */
1963 dst
->current
= dst
->first
;
1964 bitmap_elt_clear_from (dst
, dst_elt
);
1966 gcc_checking_assert (!dst
->current
== !dst
->first
);
1968 dst
->indx
= dst
->current
->indx
;
1972 /* A |= B. Return true if A changes. */
1975 bitmap_ior_into (bitmap a
, const_bitmap b
)
1977 bitmap_element
*a_elt
= a
->first
;
1978 const bitmap_element
*b_elt
= b
->first
;
1979 bitmap_element
*a_prev
= NULL
;
1980 bitmap_element
**a_prev_pnext
= &a
->first
;
1981 bool changed
= false;
1983 gcc_checking_assert (!a
->tree_form
&& !b
->tree_form
);
1989 /* If A lags behind B, just advance it. */
1990 if (!a_elt
|| a_elt
->indx
== b_elt
->indx
)
1992 changed
= bitmap_elt_ior (a
, a_elt
, a_prev
, a_elt
, b_elt
, changed
);
1993 b_elt
= b_elt
->next
;
1995 else if (a_elt
->indx
> b_elt
->indx
)
1997 changed
= bitmap_elt_copy (a
, NULL
, a_prev
, b_elt
, changed
);
1998 b_elt
= b_elt
->next
;
2001 a_prev
= *a_prev_pnext
;
2002 a_prev_pnext
= &a_prev
->next
;
2003 a_elt
= *a_prev_pnext
;
2006 gcc_checking_assert (!a
->current
== !a
->first
);
2008 a
->indx
= a
->current
->indx
;
2015 bitmap_xor (bitmap dst
, const_bitmap a
, const_bitmap b
)
2017 bitmap_element
*dst_elt
= dst
->first
;
2018 const bitmap_element
*a_elt
= a
->first
;
2019 const bitmap_element
*b_elt
= b
->first
;
2020 bitmap_element
*dst_prev
= NULL
;
2022 gcc_checking_assert (!dst
->tree_form
&& !a
->tree_form
&& !b
->tree_form
);
2023 gcc_assert (dst
!= a
&& dst
!= b
);
2031 while (a_elt
|| b_elt
)
2033 if (a_elt
&& b_elt
&& a_elt
->indx
== b_elt
->indx
)
2035 /* Matching elts, generate A ^ B. */
2037 BITMAP_WORD ior
= 0;
2040 dst_elt
= bitmap_list_insert_element_after (dst
, dst_prev
,
2043 dst_elt
->indx
= a_elt
->indx
;
2044 for (ix
= 0; ix
< BITMAP_ELEMENT_WORDS
; ix
++)
2046 BITMAP_WORD r
= a_elt
->bits
[ix
] ^ b_elt
->bits
[ix
];
2049 dst_elt
->bits
[ix
] = r
;
2051 a_elt
= a_elt
->next
;
2052 b_elt
= b_elt
->next
;
2056 dst_elt
= dst_elt
->next
;
2061 /* Copy a single element. */
2062 const bitmap_element
*src
;
2064 if (!b_elt
|| (a_elt
&& a_elt
->indx
< b_elt
->indx
))
2067 a_elt
= a_elt
->next
;
2072 b_elt
= b_elt
->next
;
2076 dst_elt
= bitmap_list_insert_element_after (dst
, dst_prev
,
2079 dst_elt
->indx
= src
->indx
;
2080 memcpy (dst_elt
->bits
, src
->bits
, sizeof (dst_elt
->bits
));
2082 dst_elt
= dst_elt
->next
;
2085 /* Ensure that dst->current is valid. */
2086 dst
->current
= dst
->first
;
2087 bitmap_elt_clear_from (dst
, dst_elt
);
2088 gcc_checking_assert (!dst
->current
== !dst
->first
);
2090 dst
->indx
= dst
->current
->indx
;
2096 bitmap_xor_into (bitmap a
, const_bitmap b
)
2098 bitmap_element
*a_elt
= a
->first
;
2099 const bitmap_element
*b_elt
= b
->first
;
2100 bitmap_element
*a_prev
= NULL
;
2102 gcc_checking_assert (!a
->tree_form
&& !b
->tree_form
);
2112 if (!a_elt
|| b_elt
->indx
< a_elt
->indx
)
2115 bitmap_element
*dst
= bitmap_list_insert_element_after (a
, a_prev
,
2117 memcpy (dst
->bits
, b_elt
->bits
, sizeof (dst
->bits
));
2119 b_elt
= b_elt
->next
;
2121 else if (a_elt
->indx
< b_elt
->indx
)
2124 a_elt
= a_elt
->next
;
2128 /* Matching elts, generate A ^= B. */
2130 BITMAP_WORD ior
= 0;
2131 bitmap_element
*next
= a_elt
->next
;
2133 for (ix
= 0; ix
< BITMAP_ELEMENT_WORDS
; ix
++)
2135 BITMAP_WORD r
= a_elt
->bits
[ix
] ^ b_elt
->bits
[ix
];
2138 a_elt
->bits
[ix
] = r
;
2140 b_elt
= b_elt
->next
;
2144 bitmap_list_unlink_element (a
, a_elt
);
2148 gcc_checking_assert (!a
->current
== !a
->first
);
2150 a
->indx
= a
->current
->indx
;
2153 /* Return true if two bitmaps are identical.
2154 We do not bother with a check for pointer equality, as that never
2155 occurs in practice. */
2158 bitmap_equal_p (const_bitmap a
, const_bitmap b
)
2160 const bitmap_element
*a_elt
;
2161 const bitmap_element
*b_elt
;
2164 gcc_checking_assert (!a
->tree_form
&& !b
->tree_form
);
2166 for (a_elt
= a
->first
, b_elt
= b
->first
;
2168 a_elt
= a_elt
->next
, b_elt
= b_elt
->next
)
2170 if (a_elt
->indx
!= b_elt
->indx
)
2172 for (ix
= 0; ix
< BITMAP_ELEMENT_WORDS
; ix
++)
2173 if (a_elt
->bits
[ix
] != b_elt
->bits
[ix
])
2176 return !a_elt
&& !b_elt
;
2179 /* Return true if A AND B is not empty. */
2182 bitmap_intersect_p (const_bitmap a
, const_bitmap b
)
2184 const bitmap_element
*a_elt
;
2185 const bitmap_element
*b_elt
;
2188 gcc_checking_assert (!a
->tree_form
&& !b
->tree_form
);
2190 for (a_elt
= a
->first
, b_elt
= b
->first
;
2193 if (a_elt
->indx
< b_elt
->indx
)
2194 a_elt
= a_elt
->next
;
2195 else if (b_elt
->indx
< a_elt
->indx
)
2196 b_elt
= b_elt
->next
;
2199 for (ix
= 0; ix
< BITMAP_ELEMENT_WORDS
; ix
++)
2200 if (a_elt
->bits
[ix
] & b_elt
->bits
[ix
])
2202 a_elt
= a_elt
->next
;
2203 b_elt
= b_elt
->next
;
2209 /* Return true if A AND NOT B is not empty. */
2212 bitmap_intersect_compl_p (const_bitmap a
, const_bitmap b
)
2214 const bitmap_element
*a_elt
;
2215 const bitmap_element
*b_elt
;
2218 gcc_checking_assert (!a
->tree_form
&& !b
->tree_form
);
2220 for (a_elt
= a
->first
, b_elt
= b
->first
;
2223 if (a_elt
->indx
< b_elt
->indx
)
2225 else if (b_elt
->indx
< a_elt
->indx
)
2226 b_elt
= b_elt
->next
;
2229 for (ix
= 0; ix
< BITMAP_ELEMENT_WORDS
; ix
++)
2230 if (a_elt
->bits
[ix
] & ~b_elt
->bits
[ix
])
2232 a_elt
= a_elt
->next
;
2233 b_elt
= b_elt
->next
;
2236 return a_elt
!= NULL
;
2240 /* DST = A | (FROM1 & ~FROM2). Return true if DST changes. */
2243 bitmap_ior_and_compl (bitmap dst
, const_bitmap a
, const_bitmap b
, const_bitmap kill
)
2245 bool changed
= false;
2247 bitmap_element
*dst_elt
= dst
->first
;
2248 const bitmap_element
*a_elt
= a
->first
;
2249 const bitmap_element
*b_elt
= b
->first
;
2250 const bitmap_element
*kill_elt
= kill
->first
;
2251 bitmap_element
*dst_prev
= NULL
;
2252 bitmap_element
**dst_prev_pnext
= &dst
->first
;
2254 gcc_checking_assert (!dst
->tree_form
&& !a
->tree_form
&& !b
->tree_form
2255 && !kill
->tree_form
);
2256 gcc_assert (dst
!= a
&& dst
!= b
&& dst
!= kill
);
2258 /* Special cases. We don't bother checking for bitmap_equal_p (b, kill). */
2259 if (b
== kill
|| bitmap_empty_p (b
))
2261 changed
= !bitmap_equal_p (dst
, a
);
2263 bitmap_copy (dst
, a
);
2266 if (bitmap_empty_p (kill
))
2267 return bitmap_ior (dst
, a
, b
);
2268 if (bitmap_empty_p (a
))
2269 return bitmap_and_compl (dst
, b
, kill
);
2271 while (a_elt
|| b_elt
)
2273 bool new_element
= false;
2276 while (kill_elt
&& kill_elt
->indx
< b_elt
->indx
)
2277 kill_elt
= kill_elt
->next
;
2279 if (b_elt
&& kill_elt
&& kill_elt
->indx
== b_elt
->indx
2280 && (!a_elt
|| a_elt
->indx
>= b_elt
->indx
))
2282 bitmap_element tmp_elt
;
2285 BITMAP_WORD ior
= 0;
2286 tmp_elt
.indx
= b_elt
->indx
;
2287 for (ix
= 0; ix
< BITMAP_ELEMENT_WORDS
; ix
++)
2289 BITMAP_WORD r
= b_elt
->bits
[ix
] & ~kill_elt
->bits
[ix
];
2291 tmp_elt
.bits
[ix
] = r
;
2296 changed
= bitmap_elt_ior (dst
, dst_elt
, dst_prev
,
2297 a_elt
, &tmp_elt
, changed
);
2299 if (a_elt
&& a_elt
->indx
== b_elt
->indx
)
2300 a_elt
= a_elt
->next
;
2303 b_elt
= b_elt
->next
;
2304 kill_elt
= kill_elt
->next
;
2308 changed
= bitmap_elt_ior (dst
, dst_elt
, dst_prev
,
2309 a_elt
, b_elt
, changed
);
2312 if (a_elt
&& b_elt
&& a_elt
->indx
== b_elt
->indx
)
2314 a_elt
= a_elt
->next
;
2315 b_elt
= b_elt
->next
;
2319 if (a_elt
&& (!b_elt
|| a_elt
->indx
<= b_elt
->indx
))
2320 a_elt
= a_elt
->next
;
2321 else if (b_elt
&& (!a_elt
|| b_elt
->indx
<= a_elt
->indx
))
2322 b_elt
= b_elt
->next
;
2328 dst_prev
= *dst_prev_pnext
;
2329 dst_prev_pnext
= &dst_prev
->next
;
2330 dst_elt
= *dst_prev_pnext
;
2337 /* Ensure that dst->current is valid. */
2338 dst
->current
= dst
->first
;
2339 bitmap_elt_clear_from (dst
, dst_elt
);
2341 gcc_checking_assert (!dst
->current
== !dst
->first
);
2343 dst
->indx
= dst
->current
->indx
;
2348 /* A |= (B & ~C). Return true if A changes. */
2351 bitmap_ior_and_compl_into (bitmap a
, const_bitmap b
, const_bitmap c
)
2356 gcc_checking_assert (!a
->tree_form
&& !b
->tree_form
&& !c
->tree_form
);
2358 bitmap_initialize (&tmp
, &bitmap_default_obstack
);
2359 bitmap_and_compl (&tmp
, b
, c
);
2360 changed
= bitmap_ior_into (a
, &tmp
);
2361 bitmap_clear (&tmp
);
2366 /* A |= (B & C). Return true if A changes. */
2369 bitmap_ior_and_into (bitmap a
, const_bitmap b
, const_bitmap c
)
2371 bitmap_element
*a_elt
= a
->first
;
2372 const bitmap_element
*b_elt
= b
->first
;
2373 const bitmap_element
*c_elt
= c
->first
;
2374 bitmap_element and_elt
;
2375 bitmap_element
*a_prev
= NULL
;
2376 bitmap_element
**a_prev_pnext
= &a
->first
;
2377 bool changed
= false;
2380 gcc_checking_assert (!a
->tree_form
&& !b
->tree_form
&& !c
->tree_form
);
2383 return bitmap_ior_into (a
, b
);
2384 if (bitmap_empty_p (b
) || bitmap_empty_p (c
))
2388 while (b_elt
&& c_elt
)
2390 BITMAP_WORD overall
;
2392 /* Find a common item of B and C. */
2393 while (b_elt
->indx
!= c_elt
->indx
)
2395 if (b_elt
->indx
< c_elt
->indx
)
2397 b_elt
= b_elt
->next
;
2403 c_elt
= c_elt
->next
;
2410 and_elt
.indx
= b_elt
->indx
;
2411 for (ix
= 0; ix
< BITMAP_ELEMENT_WORDS
; ix
++)
2413 and_elt
.bits
[ix
] = b_elt
->bits
[ix
] & c_elt
->bits
[ix
];
2414 overall
|= and_elt
.bits
[ix
];
2417 b_elt
= b_elt
->next
;
2418 c_elt
= c_elt
->next
;
2422 /* Now find a place to insert AND_ELT. */
2425 ix
= a_elt
? a_elt
->indx
: and_elt
.indx
;
2426 if (ix
== and_elt
.indx
)
2427 changed
= bitmap_elt_ior (a
, a_elt
, a_prev
, a_elt
, &and_elt
, changed
);
2428 else if (ix
> and_elt
.indx
)
2429 changed
= bitmap_elt_copy (a
, NULL
, a_prev
, &and_elt
, changed
);
2431 a_prev
= *a_prev_pnext
;
2432 a_prev_pnext
= &a_prev
->next
;
2433 a_elt
= *a_prev_pnext
;
2435 /* If A lagged behind B/C, we advanced it so loop once more. */
2437 while (ix
< and_elt
.indx
);
2441 gcc_checking_assert (!a
->current
== !a
->first
);
2443 a
->indx
= a
->current
->indx
;
2447 /* Compute hash of bitmap (for purposes of hashing). */
2450 bitmap_hash (const_bitmap head
)
2452 const bitmap_element
*ptr
;
2453 BITMAP_WORD hash
= 0;
2456 gcc_checking_assert (!head
->tree_form
);
2458 for (ptr
= head
->first
; ptr
; ptr
= ptr
->next
)
2461 for (ix
= 0; ix
!= BITMAP_ELEMENT_WORDS
; ix
++)
2462 hash
^= ptr
->bits
[ix
];
2464 return (hashval_t
)hash
;
2468 /* Function to obtain a vector of bitmap elements in bit order from
2469 HEAD in tree view. */
2472 bitmap_tree_to_vec (vec
<bitmap_element
*> &elts
, const_bitmap head
)
2474 gcc_checking_assert (head
->tree_form
);
2475 auto_vec
<bitmap_element
*, 32> stack
;
2476 bitmap_element
*e
= head
->first
;
2481 stack
.safe_push (e
);
2484 if (stack
.is_empty ())
2493 /* Debugging function to print out the contents of a bitmap element. */
2496 debug_bitmap_elt_file (FILE *file
, const bitmap_element
*ptr
)
2498 unsigned int i
, j
, col
= 26;
2500 fprintf (file
, "\t" HOST_PTR_PRINTF
" next = " HOST_PTR_PRINTF
2501 " prev = " HOST_PTR_PRINTF
" indx = %u\n\t\tbits = {",
2502 (const void*) ptr
, (const void*) ptr
->next
,
2503 (const void*) ptr
->prev
, ptr
->indx
);
2505 for (i
= 0; i
< BITMAP_ELEMENT_WORDS
; i
++)
2506 for (j
= 0; j
< BITMAP_WORD_BITS
; j
++)
2507 if ((ptr
->bits
[i
] >> j
) & 1)
2511 fprintf (file
, "\n\t\t\t");
2515 fprintf (file
, " %u", (ptr
->indx
* BITMAP_ELEMENT_ALL_BITS
2516 + i
* BITMAP_WORD_BITS
+ j
));
2520 fprintf (file
, " }\n");
2523 /* Debugging function to print out the contents of a bitmap. */
2526 debug_bitmap_file (FILE *file
, const_bitmap head
)
2528 const bitmap_element
*ptr
;
2530 fprintf (file
, "\nfirst = " HOST_PTR_PRINTF
2531 " current = " HOST_PTR_PRINTF
" indx = %u\n",
2532 (void *) head
->first
, (void *) head
->current
, head
->indx
);
2534 if (head
->tree_form
)
2536 auto_vec
<bitmap_element
*, 32> elts
;
2537 bitmap_tree_to_vec (elts
, head
);
2538 for (unsigned i
= 0; i
< elts
.length (); ++i
)
2539 debug_bitmap_elt_file (file
, elts
[i
]);
2542 for (ptr
= head
->first
; ptr
; ptr
= ptr
->next
)
2543 debug_bitmap_elt_file (file
, ptr
);
2546 /* Function to be called from the debugger to print the contents
2550 debug_bitmap (const_bitmap head
)
2552 debug_bitmap_file (stderr
, head
);
2555 /* Function to print out the contents of a bitmap. Unlike debug_bitmap_file,
2556 it does not print anything but the bits. */
2559 bitmap_print (FILE *file
, const_bitmap head
, const char *prefix
,
2562 const char *comma
= "";
2565 fputs (prefix
, file
);
2566 if (head
->tree_form
)
2568 auto_vec
<bitmap_element
*, 32> elts
;
2569 bitmap_tree_to_vec (elts
, head
);
2570 for (i
= 0; i
< elts
.length (); ++i
)
2571 for (unsigned ix
= 0; ix
!= BITMAP_ELEMENT_WORDS
; ++ix
)
2573 BITMAP_WORD word
= elts
[i
]->bits
[ix
];
2574 for (unsigned bit
= 0; bit
!= BITMAP_WORD_BITS
; ++bit
)
2575 if (word
& ((BITMAP_WORD
)1 << bit
))
2577 fprintf (file
, "%s%d", comma
,
2578 (bit
+ BITMAP_WORD_BITS
* ix
2579 + elts
[i
]->indx
* BITMAP_ELEMENT_ALL_BITS
));
2587 EXECUTE_IF_SET_IN_BITMAP (head
, 0, i
, bi
)
2589 fprintf (file
, "%s%d", comma
, i
);
2593 fputs (suffix
, file
);
2596 /* Output per-bitmap memory usage statistics. */
2598 dump_bitmap_statistics (void)
2600 if (!GATHER_STATISTICS
)
2603 bitmap_mem_desc
.dump (BITMAP_ORIGIN
);
2607 debug (const bitmap_head
&ref
)
2609 dump_bitmap (stderr
, &ref
);
2613 debug (const bitmap_head
*ptr
)
2618 fprintf (stderr
, "<nil>\n");
2622 bitmap_head::dump ()
2629 namespace selftest
{
2631 /* Selftests for bitmaps. */
2633 /* Freshly-created bitmaps ought to be empty. */
2638 bitmap b
= bitmap_gc_alloc ();
2639 ASSERT_TRUE (bitmap_empty_p (b
));
2642 /* Verify bitmap_set_range. */
2647 bitmap b
= bitmap_gc_alloc ();
2648 ASSERT_TRUE (bitmap_empty_p (b
));
2650 bitmap_set_range (b
, 7, 5);
2651 ASSERT_FALSE (bitmap_empty_p (b
));
2652 ASSERT_EQ (5, bitmap_count_bits (b
));
2654 /* Verify bitmap_bit_p at the boundaries. */
2655 ASSERT_FALSE (bitmap_bit_p (b
, 6));
2656 ASSERT_TRUE (bitmap_bit_p (b
, 7));
2657 ASSERT_TRUE (bitmap_bit_p (b
, 11));
2658 ASSERT_FALSE (bitmap_bit_p (b
, 12));
2661 /* Verify splitting a range into two pieces using bitmap_clear_bit. */
2664 test_clear_bit_in_middle ()
2666 bitmap b
= bitmap_gc_alloc ();
2668 /* Set b to [100..200]. */
2669 bitmap_set_range (b
, 100, 100);
2670 ASSERT_EQ (100, bitmap_count_bits (b
));
2672 /* Clear a bit in the middle. */
2673 bool changed
= bitmap_clear_bit (b
, 150);
2674 ASSERT_TRUE (changed
);
2675 ASSERT_EQ (99, bitmap_count_bits (b
));
2676 ASSERT_TRUE (bitmap_bit_p (b
, 149));
2677 ASSERT_FALSE (bitmap_bit_p (b
, 150));
2678 ASSERT_TRUE (bitmap_bit_p (b
, 151));
2681 /* Verify bitmap_copy. */
2686 bitmap src
= bitmap_gc_alloc ();
2687 bitmap_set_range (src
, 40, 10);
2689 bitmap dst
= bitmap_gc_alloc ();
2690 ASSERT_FALSE (bitmap_equal_p (src
, dst
));
2691 bitmap_copy (dst
, src
);
2692 ASSERT_TRUE (bitmap_equal_p (src
, dst
));
2694 /* Verify that we can make them unequal again... */
2695 bitmap_set_range (src
, 70, 5);
2696 ASSERT_FALSE (bitmap_equal_p (src
, dst
));
2698 /* ...and that changing src after the copy didn't affect
2700 ASSERT_FALSE (bitmap_bit_p (dst
, 70));
2703 /* Verify bitmap_single_bit_set_p. */
2706 test_bitmap_single_bit_set_p ()
2708 bitmap b
= bitmap_gc_alloc ();
2710 ASSERT_FALSE (bitmap_single_bit_set_p (b
));
2712 bitmap_set_range (b
, 42, 1);
2713 ASSERT_TRUE (bitmap_single_bit_set_p (b
));
2714 ASSERT_EQ (42, bitmap_first_set_bit (b
));
2716 bitmap_set_range (b
, 1066, 1);
2717 ASSERT_FALSE (bitmap_single_bit_set_p (b
));
2718 ASSERT_EQ (42, bitmap_first_set_bit (b
));
2720 bitmap_clear_range (b
, 0, 100);
2721 ASSERT_TRUE (bitmap_single_bit_set_p (b
));
2722 ASSERT_EQ (1066, bitmap_first_set_bit (b
));
2725 /* Run all of the selftests within this file. */
2732 test_clear_bit_in_middle ();
2734 test_bitmap_single_bit_set_p ();
2737 } // namespace selftest
2738 #endif /* CHECKING_P */
2740 #include "gt-bitmap.h"