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 static unsigned alloc_descriptor_max_uid
= 1;
40 gcc_assert (b
->alloc_descriptor
== 0);
41 b
->alloc_descriptor
= alloc_descriptor_max_uid
++;
43 bitmap_mem_desc
.register_descriptor (b
->get_descriptor (), BITMAP_ORIGIN
,
44 false FINAL_PASS_MEM_STAT
);
47 /* Account the overhead. */
49 register_overhead (bitmap b
, size_t amount
)
51 unsigned *d
= b
->get_descriptor ();
52 if (bitmap_mem_desc
.contains_descriptor_for_instance (d
))
53 bitmap_mem_desc
.register_instance_overhead (amount
, d
);
56 /* Release the overhead. */
58 release_overhead (bitmap b
, size_t amount
, bool remove_from_map
)
60 unsigned *d
= b
->get_descriptor ();
61 if (bitmap_mem_desc
.contains_descriptor_for_instance (d
))
62 bitmap_mem_desc
.release_instance_overhead (d
, amount
, remove_from_map
);
67 bitmap_element bitmap_zero_bits
; /* An element of all zero bits. */
68 bitmap_obstack bitmap_default_obstack
; /* The default bitmap obstack. */
69 static int bitmap_default_obstack_depth
;
70 static GTY((deletable
)) bitmap_element
*bitmap_ggc_free
; /* Freelist of
74 /* Bitmap memory management. */
76 /* Add ELT to the appropriate freelist. */
78 bitmap_elem_to_freelist (bitmap head
, bitmap_element
*elt
)
80 bitmap_obstack
*bit_obstack
= head
->obstack
;
82 if (GATHER_STATISTICS
)
83 release_overhead (head
, sizeof (bitmap_element
), false);
89 elt
->prev
= bit_obstack
->elements
;
90 bit_obstack
->elements
= elt
;
94 elt
->prev
= bitmap_ggc_free
;
95 bitmap_ggc_free
= elt
;
99 /* Allocate a bitmap element. The bits are cleared, but nothing else is. */
101 static inline bitmap_element
*
102 bitmap_element_allocate (bitmap head
)
104 bitmap_element
*element
;
105 bitmap_obstack
*bit_obstack
= head
->obstack
;
109 element
= bit_obstack
->elements
;
112 /* Use up the inner list first before looking at the next
113 element of the outer list. */
116 bit_obstack
->elements
= element
->next
;
117 bit_obstack
->elements
->prev
= element
->prev
;
120 /* Inner list was just a singleton. */
121 bit_obstack
->elements
= element
->prev
;
123 element
= XOBNEW (&bit_obstack
->obstack
, bitmap_element
);
127 element
= bitmap_ggc_free
;
129 /* Use up the inner list first before looking at the next
130 element of the outer list. */
133 bitmap_ggc_free
= element
->next
;
134 bitmap_ggc_free
->prev
= element
->prev
;
137 /* Inner list was just a singleton. */
138 bitmap_ggc_free
= element
->prev
;
140 element
= ggc_alloc
<bitmap_element
> ();
143 if (GATHER_STATISTICS
)
144 register_overhead (head
, sizeof (bitmap_element
));
146 memset (element
->bits
, 0, sizeof (element
->bits
));
151 /* Remove ELT and all following elements from bitmap HEAD.
152 Put the released elements in the freelist for HEAD. */
155 bitmap_elt_clear_from (bitmap head
, bitmap_element
*elt
)
157 bitmap_element
*prev
;
158 bitmap_obstack
*bit_obstack
= head
->obstack
;
164 elt
= bitmap_tree_listify_from (head
, elt
);
166 if (GATHER_STATISTICS
)
169 for (prev
= elt
; prev
; prev
= prev
->next
)
171 release_overhead (head
, sizeof (bitmap_element
) * n
, false);
178 if (head
->current
->indx
> prev
->indx
)
180 head
->current
= prev
;
181 head
->indx
= prev
->indx
;
187 head
->current
= NULL
;
191 /* Put the entire list onto the freelist in one operation. */
194 elt
->prev
= bit_obstack
->elements
;
195 bit_obstack
->elements
= elt
;
199 elt
->prev
= bitmap_ggc_free
;
200 bitmap_ggc_free
= elt
;
204 /* Linked-list view of bitmaps.
206 In this representation, the bitmap elements form a double-linked list
207 with elements sorted by increasing index. */
209 /* Link the bitmap element into the current bitmap linked list. */
212 bitmap_list_link_element (bitmap head
, bitmap_element
*element
)
214 unsigned int indx
= element
->indx
;
217 gcc_checking_assert (!head
->tree_form
);
219 /* If this is the first and only element, set it in. */
220 if (head
->first
== 0)
222 element
->next
= element
->prev
= 0;
223 head
->first
= element
;
226 /* If this index is less than that of the current element, it goes someplace
227 before the current element. */
228 else if (indx
< head
->indx
)
230 for (ptr
= head
->current
;
231 ptr
->prev
!= 0 && ptr
->prev
->indx
> indx
;
236 ptr
->prev
->next
= element
;
238 head
->first
= element
;
240 element
->prev
= ptr
->prev
;
245 /* Otherwise, it must go someplace after the current element. */
248 for (ptr
= head
->current
;
249 ptr
->next
!= 0 && ptr
->next
->indx
< indx
;
254 ptr
->next
->prev
= element
;
256 element
->next
= ptr
->next
;
261 /* Set up so this is the first element searched. */
262 head
->current
= element
;
266 /* Unlink the bitmap element from the current bitmap linked list,
267 and return it to the freelist. */
270 bitmap_list_unlink_element (bitmap head
, bitmap_element
*element
)
272 bitmap_element
*next
= element
->next
;
273 bitmap_element
*prev
= element
->prev
;
275 gcc_checking_assert (!head
->tree_form
);
283 if (head
->first
== element
)
286 /* Since the first thing we try is to insert before current,
287 make current the next entry in preference to the previous. */
288 if (head
->current
== element
)
290 head
->current
= next
!= 0 ? next
: prev
;
292 head
->indx
= head
->current
->indx
;
297 bitmap_elem_to_freelist (head
, element
);
300 /* Insert a new uninitialized element into bitmap HEAD after element
301 ELT. If ELT is NULL, insert the element at the start. Return the
304 static bitmap_element
*
305 bitmap_list_insert_element_after (bitmap head
,
306 bitmap_element
*elt
, unsigned int indx
)
308 bitmap_element
*node
= bitmap_element_allocate (head
);
311 gcc_checking_assert (!head
->tree_form
);
317 head
->current
= node
;
320 node
->next
= head
->first
;
322 node
->next
->prev
= node
;
328 gcc_checking_assert (head
->current
);
329 node
->next
= elt
->next
;
331 node
->next
->prev
= node
;
338 /* Return the element for INDX, or NULL if the element doesn't exist.
339 Update the `current' field even if we can't find an element that
340 would hold the bitmap's bit to make eventual allocation
343 static inline bitmap_element
*
344 bitmap_list_find_element (bitmap head
, unsigned int indx
)
346 bitmap_element
*element
;
348 if (head
->current
== NULL
349 || head
->indx
== indx
)
350 return head
->current
;
352 if (head
->current
== head
->first
353 && head
->first
->next
== NULL
)
356 /* Usage can be NULL due to allocated bitmaps for which we do not
357 call initialize function. */
358 bitmap_usage
*usage
= NULL
;
359 if (GATHER_STATISTICS
)
360 usage
= bitmap_mem_desc
.get_descriptor_for_instance (head
);
362 /* This bitmap has more than one element, and we're going to look
363 through the elements list. Count that as a search. */
364 if (GATHER_STATISTICS
&& usage
)
365 usage
->m_nsearches
++;
367 if (head
->indx
< indx
)
368 /* INDX is beyond head->indx. Search from head->current
370 for (element
= head
->current
;
371 element
->next
!= 0 && element
->indx
< indx
;
372 element
= element
->next
)
374 if (GATHER_STATISTICS
&& usage
)
375 usage
->m_search_iter
++;
378 else if (head
->indx
/ 2 < indx
)
379 /* INDX is less than head->indx and closer to head->indx than to
380 0. Search from head->current backward. */
381 for (element
= head
->current
;
382 element
->prev
!= 0 && element
->indx
> indx
;
383 element
= element
->prev
)
385 if (GATHER_STATISTICS
&& usage
)
386 usage
->m_search_iter
++;
390 /* INDX is less than head->indx and closer to 0 than to
391 head->indx. Search from head->first forward. */
392 for (element
= head
->first
;
393 element
->next
!= 0 && element
->indx
< indx
;
394 element
= element
->next
)
396 if (GATHER_STATISTICS
&& usage
)
397 usage
->m_search_iter
++;
400 /* `element' is the nearest to the one we want. If it's not the one we
401 want, the one we want doesn't exist. */
402 gcc_checking_assert (element
!= NULL
);
403 head
->current
= element
;
404 head
->indx
= element
->indx
;
405 if (element
->indx
!= indx
)
411 /* Splay-tree view of bitmaps.
413 This is an almost one-to-one the implementatin of the simple top-down
414 splay tree in Sleator and Tarjan's "Self-adjusting Binary Search Trees".
415 It is probably not the most efficient form of splay trees, but it should
416 be good enough to experiment with this idea of bitmaps-as-trees.
418 For all functions below, the variable or function argument "t" is a node
419 in the tree, and "e" is a temporary or new node in the tree. The rest
420 is sufficiently straigh-forward (and very well explained in the paper)
421 that comment would only clutter things. */
424 bitmap_tree_link_left (bitmap_element
* &t
, bitmap_element
* &l
)
432 bitmap_tree_link_right (bitmap_element
* &t
, bitmap_element
* &r
)
440 bitmap_tree_rotate_left (bitmap_element
* &t
)
442 bitmap_element
*e
= t
->next
;
443 t
->next
= t
->next
->prev
;
449 bitmap_tree_rotate_right (bitmap_element
* &t
)
451 bitmap_element
*e
= t
->prev
;
452 t
->prev
= t
->prev
->next
;
457 static bitmap_element
*
458 bitmap_tree_splay (bitmap head
, bitmap_element
*t
, unsigned int indx
)
460 bitmap_element N
, *l
, *r
;
465 bitmap_usage
*usage
= NULL
;
466 if (GATHER_STATISTICS
)
467 usage
= bitmap_mem_desc
.get_descriptor_for_instance (head
);
469 N
.prev
= N
.next
= NULL
;
472 while (indx
!= t
->indx
)
474 if (GATHER_STATISTICS
&& usage
)
475 usage
->m_search_iter
++;
479 if (t
->prev
!= NULL
&& indx
< t
->prev
->indx
)
480 bitmap_tree_rotate_right (t
);
483 bitmap_tree_link_right (t
, r
);
485 else if (indx
> t
->indx
)
487 if (t
->next
!= NULL
&& indx
> t
->next
->indx
)
488 bitmap_tree_rotate_left (t
);
491 bitmap_tree_link_left (t
, l
);
502 /* Link bitmap element E into the current bitmap splay tree. */
505 bitmap_tree_link_element (bitmap head
, bitmap_element
*e
)
507 if (head
->first
== NULL
)
508 e
->prev
= e
->next
= NULL
;
511 bitmap_element
*t
= bitmap_tree_splay (head
, head
->first
, e
->indx
);
512 if (e
->indx
< t
->indx
)
518 else if (e
->indx
> t
->indx
)
529 head
->indx
= e
->indx
;
532 /* Unlink bitmap element E from the current bitmap splay tree,
533 and return it to the freelist. */
536 bitmap_tree_unlink_element (bitmap head
, bitmap_element
*e
)
538 bitmap_element
*t
= bitmap_tree_splay (head
, head
->first
, e
->indx
);
540 gcc_checking_assert (t
== e
);
546 t
= bitmap_tree_splay (head
, e
->prev
, e
->indx
);
551 head
->indx
= (t
!= NULL
) ? t
->indx
: 0;
553 bitmap_elem_to_freelist (head
, e
);
556 /* Return the element for INDX, or NULL if the element doesn't exist. */
558 static inline bitmap_element
*
559 bitmap_tree_find_element (bitmap head
, unsigned int indx
)
561 if (head
->current
== NULL
562 || head
->indx
== indx
)
563 return head
->current
;
565 /* Usage can be NULL due to allocated bitmaps for which we do not
566 call initialize function. */
567 bitmap_usage
*usage
= NULL
;
568 if (GATHER_STATISTICS
)
569 usage
= bitmap_mem_desc
.get_descriptor_for_instance (head
);
571 /* This bitmap has more than one element, and we're going to look
572 through the elements list. Count that as a search. */
573 if (GATHER_STATISTICS
&& usage
)
574 usage
->m_nsearches
++;
576 bitmap_element
*element
= bitmap_tree_splay (head
, head
->first
, indx
);
577 gcc_checking_assert (element
!= NULL
);
578 head
->first
= element
;
579 head
->current
= element
;
580 head
->indx
= element
->indx
;
581 if (element
->indx
!= indx
)
586 /* Converting bitmap views from linked-list to tree and vice versa. */
588 /* Splice element E and all elements with a larger index from
589 bitmap HEAD, convert the spliced elements to the linked-list
590 view, and return the head of the list (which should be E again), */
592 static bitmap_element
*
593 bitmap_tree_listify_from (bitmap head
, bitmap_element
*e
)
595 bitmap_element
*t
, *erb
;
597 /* Detach the right branch from E (all elements with indx > E->indx),
598 and splay E to the root. */
601 t
= bitmap_tree_splay (head
, head
->first
, e
->indx
);
602 gcc_checking_assert (t
== e
);
604 /* Because E has no right branch, and we rotated it to the root,
605 the left branch is the new root. */
609 head
->indx
= (t
!= NULL
) ? t
->indx
: 0;
611 /* Detach the tree from E, and re-attach the right branch of E. */
615 /* The tree is now valid again. Now we need to "un-tree" E.
616 It is imperative that a non-recursive implementation is used
617 for this, because splay trees have a worst case depth of O(N)
618 for a tree with N nodes. A recursive implementation could
619 result in a stack overflow for a sufficiently large, unbalanced
622 auto_vec
<bitmap_element
*, 32> stack
;
623 auto_vec
<bitmap_element
*, 32> sorted_elements
;
624 bitmap_element
*n
= e
;
634 if (stack
.is_empty ())
638 sorted_elements
.safe_push (n
);
642 gcc_assert (sorted_elements
[0] == e
);
644 bitmap_element
*prev
= NULL
;
646 FOR_EACH_VEC_ELT (sorted_elements
, ix
, n
)
658 /* Convert bitmap HEAD from splay-tree view to linked-list view. */
661 bitmap_list_view (bitmap head
)
665 gcc_assert (head
->tree_form
);
671 bitmap_tree_rotate_right (ptr
);
673 head
->first
= bitmap_tree_listify_from (head
, ptr
);
676 head
->tree_form
= false;
679 /* Convert bitmap HEAD from linked-list view to splay-tree view.
680 This is simply a matter of dropping the prev or next pointers
681 and setting the tree_form flag. The tree will balance itself
682 if and when it is used. */
685 bitmap_tree_view (bitmap head
)
689 gcc_assert (! head
->tree_form
);
698 head
->tree_form
= true;
701 /* Clear a bitmap by freeing all its elements. */
704 bitmap_clear (bitmap head
)
706 if (head
->first
== NULL
)
710 bitmap_element
*e
, *t
;
711 for (e
= head
->first
; e
->prev
; e
= e
->prev
)
712 /* Loop to find the element with the smallest index. */ ;
713 t
= bitmap_tree_splay (head
, head
->first
, e
->indx
);
714 gcc_checking_assert (t
== e
);
717 bitmap_elt_clear_from (head
, head
->first
);
720 /* Initialize a bitmap obstack. If BIT_OBSTACK is NULL, initialize
721 the default bitmap obstack. */
724 bitmap_obstack_initialize (bitmap_obstack
*bit_obstack
)
728 if (bitmap_default_obstack_depth
++)
730 bit_obstack
= &bitmap_default_obstack
;
733 #if !defined(__GNUC__) || (__GNUC__ < 2)
734 #define __alignof__(type) 0
737 bit_obstack
->elements
= NULL
;
738 bit_obstack
->heads
= NULL
;
739 obstack_specify_allocation (&bit_obstack
->obstack
, OBSTACK_CHUNK_SIZE
,
740 __alignof__ (bitmap_element
),
745 /* Release the memory from a bitmap obstack. If BIT_OBSTACK is NULL,
746 release the default bitmap obstack. */
749 bitmap_obstack_release (bitmap_obstack
*bit_obstack
)
753 if (--bitmap_default_obstack_depth
)
755 gcc_assert (bitmap_default_obstack_depth
> 0);
758 bit_obstack
= &bitmap_default_obstack
;
761 bit_obstack
->elements
= NULL
;
762 bit_obstack
->heads
= NULL
;
763 obstack_free (&bit_obstack
->obstack
, NULL
);
766 /* Create a new bitmap on an obstack. If BIT_OBSTACK is NULL, create
767 it on the default bitmap obstack. */
770 bitmap_alloc (bitmap_obstack
*bit_obstack MEM_STAT_DECL
)
775 bit_obstack
= &bitmap_default_obstack
;
776 map
= bit_obstack
->heads
;
778 bit_obstack
->heads
= (struct bitmap_head
*) map
->first
;
780 map
= XOBNEW (&bit_obstack
->obstack
, bitmap_head
);
781 bitmap_initialize (map
, bit_obstack PASS_MEM_STAT
);
783 if (GATHER_STATISTICS
)
784 register_overhead (map
, sizeof (bitmap_head
));
789 /* Create a new GCd bitmap. */
792 bitmap_gc_alloc (ALONE_MEM_STAT_DECL
)
796 map
= ggc_alloc
<bitmap_head
> ();
797 bitmap_initialize (map
, NULL PASS_MEM_STAT
);
799 if (GATHER_STATISTICS
)
800 register_overhead (map
, sizeof (bitmap_head
));
805 /* Release an obstack allocated bitmap. */
808 bitmap_obstack_free (bitmap map
)
813 map
->first
= (bitmap_element
*) map
->obstack
->heads
;
815 if (GATHER_STATISTICS
)
816 release_overhead (map
, sizeof (bitmap_head
), true);
818 map
->obstack
->heads
= map
;
823 /* Return nonzero if all bits in an element are zero. */
826 bitmap_element_zerop (const bitmap_element
*element
)
828 #if BITMAP_ELEMENT_WORDS == 2
829 return (element
->bits
[0] | element
->bits
[1]) == 0;
833 for (i
= 0; i
< BITMAP_ELEMENT_WORDS
; i
++)
834 if (element
->bits
[i
] != 0)
841 /* Copy a bitmap to another bitmap. */
844 bitmap_copy (bitmap to
, const_bitmap from
)
846 const bitmap_element
*from_ptr
;
847 bitmap_element
*to_ptr
= 0;
849 gcc_checking_assert (!to
->tree_form
&& !from
->tree_form
);
853 /* Copy elements in forward direction one at a time. */
854 for (from_ptr
= from
->first
; from_ptr
; from_ptr
= from_ptr
->next
)
856 bitmap_element
*to_elt
= bitmap_element_allocate (to
);
858 to_elt
->indx
= from_ptr
->indx
;
859 memcpy (to_elt
->bits
, from_ptr
->bits
, sizeof (to_elt
->bits
));
861 /* Here we have a special case of bitmap_list_link_element,
862 for the case where we know the links are being entered
866 to
->first
= to
->current
= to_elt
;
867 to
->indx
= from_ptr
->indx
;
868 to_elt
->next
= to_elt
->prev
= 0;
872 to_elt
->prev
= to_ptr
;
874 to_ptr
->next
= to_elt
;
881 /* Move a bitmap to another bitmap. */
884 bitmap_move (bitmap to
, bitmap from
)
886 gcc_assert (to
->obstack
== from
->obstack
);
891 if (GATHER_STATISTICS
)
893 for (bitmap_element
*e
= to
->first
; e
; e
= e
->next
)
894 sz
+= sizeof (bitmap_element
);
895 register_overhead (to
, sz
);
900 if (GATHER_STATISTICS
)
901 release_overhead (from
, sz
, false);
904 /* Clear a single bit in a bitmap. Return true if the bit changed. */
907 bitmap_clear_bit (bitmap head
, int bit
)
909 unsigned int indx
= bit
/ BITMAP_ELEMENT_ALL_BITS
;
912 if (!head
->tree_form
)
913 ptr
= bitmap_list_find_element (head
, indx
);
915 ptr
= bitmap_tree_find_element (head
, indx
);
918 unsigned bit_num
= bit
% BITMAP_WORD_BITS
;
919 unsigned word_num
= bit
/ BITMAP_WORD_BITS
% BITMAP_ELEMENT_WORDS
;
920 BITMAP_WORD bit_val
= ((BITMAP_WORD
) 1) << bit_num
;
921 bool res
= (ptr
->bits
[word_num
] & bit_val
) != 0;
924 ptr
->bits
[word_num
] &= ~bit_val
;
925 /* If we cleared the entire word, free up the element. */
926 if (!ptr
->bits
[word_num
]
927 && bitmap_element_zerop (ptr
))
929 if (!head
->tree_form
)
930 bitmap_list_unlink_element (head
, ptr
);
932 bitmap_tree_unlink_element (head
, ptr
);
942 /* Set a single bit in a bitmap. Return true if the bit changed. */
945 bitmap_set_bit (bitmap head
, int bit
)
947 unsigned indx
= bit
/ BITMAP_ELEMENT_ALL_BITS
;
949 if (!head
->tree_form
)
950 ptr
= bitmap_list_find_element (head
, indx
);
952 ptr
= bitmap_tree_find_element (head
, indx
);
953 unsigned word_num
= bit
/ BITMAP_WORD_BITS
% BITMAP_ELEMENT_WORDS
;
954 unsigned bit_num
= bit
% BITMAP_WORD_BITS
;
955 BITMAP_WORD bit_val
= ((BITMAP_WORD
) 1) << bit_num
;
959 bool res
= (ptr
->bits
[word_num
] & bit_val
) == 0;
961 ptr
->bits
[word_num
] |= bit_val
;
965 ptr
= bitmap_element_allocate (head
);
966 ptr
->indx
= bit
/ BITMAP_ELEMENT_ALL_BITS
;
967 ptr
->bits
[word_num
] = bit_val
;
968 if (!head
->tree_form
)
969 bitmap_list_link_element (head
, ptr
);
971 bitmap_tree_link_element (head
, ptr
);
975 /* Return whether a bit is set within a bitmap. */
978 bitmap_bit_p (bitmap head
, int bit
)
980 unsigned int indx
= bit
/ BITMAP_ELEMENT_ALL_BITS
;
985 if (!head
->tree_form
)
986 ptr
= bitmap_list_find_element (head
, indx
);
988 ptr
= bitmap_tree_find_element (head
, indx
);
992 bit_num
= bit
% BITMAP_WORD_BITS
;
993 word_num
= bit
/ BITMAP_WORD_BITS
% BITMAP_ELEMENT_WORDS
;
995 return (ptr
->bits
[word_num
] >> bit_num
) & 1;
998 #if GCC_VERSION < 3400
999 /* Table of number of set bits in a character, indexed by value of char. */
1000 static const unsigned char popcount_table
[] =
1002 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,
1003 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,
1004 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,
1005 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,
1006 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,
1007 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,
1008 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,
1009 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,
1012 static unsigned long
1013 bitmap_popcount (BITMAP_WORD a
)
1015 unsigned long ret
= 0;
1018 /* Just do this the table way for now */
1019 for (i
= 0; i
< BITMAP_WORD_BITS
; i
+= 8)
1020 ret
+= popcount_table
[(a
>> i
) & 0xff];
1025 /* Count and return the number of bits set in the bitmap word BITS. */
1026 static unsigned long
1027 bitmap_count_bits_in_word (const BITMAP_WORD
*bits
)
1029 unsigned long count
= 0;
1031 for (unsigned ix
= 0; ix
!= BITMAP_ELEMENT_WORDS
; ix
++)
1033 #if GCC_VERSION >= 3400
1034 /* Note that popcountl matches BITMAP_WORD in type, so the actual size
1035 of BITMAP_WORD is not material. */
1036 count
+= __builtin_popcountl (bits
[ix
]);
1038 count
+= bitmap_popcount (bits
[ix
]);
1044 /* Count the number of bits set in the bitmap, and return it. */
1047 bitmap_count_bits (const_bitmap a
)
1049 unsigned long count
= 0;
1050 const bitmap_element
*elt
;
1052 gcc_checking_assert (!a
->tree_form
);
1053 for (elt
= a
->first
; elt
; elt
= elt
->next
)
1054 count
+= bitmap_count_bits_in_word (elt
->bits
);
1059 /* Count the number of unique bits set in A and B and return it. */
1062 bitmap_count_unique_bits (const_bitmap a
, const_bitmap b
)
1064 unsigned long count
= 0;
1065 const bitmap_element
*elt_a
, *elt_b
;
1067 for (elt_a
= a
->first
, elt_b
= b
->first
; elt_a
&& elt_b
; )
1069 /* If we're at different indices, then count all the bits
1070 in the lower element. If we're at the same index, then
1071 count the bits in the IOR of the two elements. */
1072 if (elt_a
->indx
< elt_b
->indx
)
1074 count
+= bitmap_count_bits_in_word (elt_a
->bits
);
1075 elt_a
= elt_a
->next
;
1077 else if (elt_b
->indx
< elt_a
->indx
)
1079 count
+= bitmap_count_bits_in_word (elt_b
->bits
);
1080 elt_b
= elt_b
->next
;
1084 BITMAP_WORD bits
[BITMAP_ELEMENT_WORDS
];
1085 for (unsigned ix
= 0; ix
!= BITMAP_ELEMENT_WORDS
; ix
++)
1086 bits
[ix
] = elt_a
->bits
[ix
] | elt_b
->bits
[ix
];
1087 count
+= bitmap_count_bits_in_word (bits
);
1088 elt_a
= elt_a
->next
;
1089 elt_b
= elt_b
->next
;
1095 /* Return true if the bitmap has a single bit set. Otherwise return
1099 bitmap_single_bit_set_p (const_bitmap a
)
1101 unsigned long count
= 0;
1102 const bitmap_element
*elt
;
1105 if (bitmap_empty_p (a
))
1110 /* As there are no completely empty bitmap elements, a second one
1111 means we have more than one bit set. */
1112 if (elt
->next
!= NULL
1113 && (!a
->tree_form
|| elt
->prev
!= NULL
))
1116 for (ix
= 0; ix
!= BITMAP_ELEMENT_WORDS
; ix
++)
1118 #if GCC_VERSION >= 3400
1119 /* Note that popcountl matches BITMAP_WORD in type, so the actual size
1120 of BITMAP_WORD is not material. */
1121 count
+= __builtin_popcountl (elt
->bits
[ix
]);
1123 count
+= bitmap_popcount (elt
->bits
[ix
]);
1133 /* Return the bit number of the first set bit in the bitmap. The
1134 bitmap must be non-empty. */
1137 bitmap_first_set_bit (const_bitmap a
)
1139 const bitmap_element
*elt
= a
->first
;
1144 gcc_checking_assert (elt
);
1150 bit_no
= elt
->indx
* BITMAP_ELEMENT_ALL_BITS
;
1151 for (ix
= 0; ix
!= BITMAP_ELEMENT_WORDS
; ix
++)
1153 word
= elt
->bits
[ix
];
1159 bit_no
+= ix
* BITMAP_WORD_BITS
;
1161 #if GCC_VERSION >= 3004
1162 gcc_assert (sizeof (long) == sizeof (word
));
1163 bit_no
+= __builtin_ctzl (word
);
1165 /* Binary search for the first set bit. */
1166 #if BITMAP_WORD_BITS > 64
1167 #error "Fill out the table."
1169 #if BITMAP_WORD_BITS > 32
1170 if (!(word
& 0xffffffff))
1171 word
>>= 32, bit_no
+= 32;
1173 if (!(word
& 0xffff))
1174 word
>>= 16, bit_no
+= 16;
1176 word
>>= 8, bit_no
+= 8;
1178 word
>>= 4, bit_no
+= 4;
1180 word
>>= 2, bit_no
+= 2;
1182 word
>>= 1, bit_no
+= 1;
1184 gcc_checking_assert (word
& 1);
1189 /* Return the bit number of the first set bit in the bitmap. The
1190 bitmap must be non-empty. */
1193 bitmap_last_set_bit (const_bitmap a
)
1195 const bitmap_element
*elt
;
1203 elt
= a
->current
? a
->current
: a
->first
;
1204 gcc_checking_assert (elt
);
1209 bit_no
= elt
->indx
* BITMAP_ELEMENT_ALL_BITS
;
1210 for (ix
= BITMAP_ELEMENT_WORDS
- 1; ix
>= 1; ix
--)
1212 word
= elt
->bits
[ix
];
1216 gcc_assert (elt
->bits
[ix
] != 0);
1218 bit_no
+= ix
* BITMAP_WORD_BITS
;
1219 #if GCC_VERSION >= 3004
1220 gcc_assert (sizeof (long) == sizeof (word
));
1221 bit_no
+= BITMAP_WORD_BITS
- __builtin_clzl (word
) - 1;
1223 /* Hopefully this is a twos-complement host... */
1224 BITMAP_WORD x
= word
;
1230 #if BITMAP_WORD_BITS > 32
1233 bit_no
+= bitmap_popcount (x
) - 1;
1243 bitmap_and (bitmap dst
, const_bitmap a
, const_bitmap b
)
1245 bitmap_element
*dst_elt
= dst
->first
;
1246 const bitmap_element
*a_elt
= a
->first
;
1247 const bitmap_element
*b_elt
= b
->first
;
1248 bitmap_element
*dst_prev
= NULL
;
1250 gcc_checking_assert (!dst
->tree_form
&& !a
->tree_form
&& !b
->tree_form
);
1251 gcc_assert (dst
!= a
&& dst
!= b
);
1255 bitmap_copy (dst
, a
);
1259 while (a_elt
&& b_elt
)
1261 if (a_elt
->indx
< b_elt
->indx
)
1262 a_elt
= a_elt
->next
;
1263 else if (b_elt
->indx
< a_elt
->indx
)
1264 b_elt
= b_elt
->next
;
1267 /* Matching elts, generate A & B. */
1269 BITMAP_WORD ior
= 0;
1272 dst_elt
= bitmap_list_insert_element_after (dst
, dst_prev
,
1275 dst_elt
->indx
= a_elt
->indx
;
1276 for (ix
= 0; ix
< BITMAP_ELEMENT_WORDS
; ix
++)
1278 BITMAP_WORD r
= a_elt
->bits
[ix
] & b_elt
->bits
[ix
];
1280 dst_elt
->bits
[ix
] = r
;
1286 dst_elt
= dst_elt
->next
;
1288 a_elt
= a_elt
->next
;
1289 b_elt
= b_elt
->next
;
1292 /* Ensure that dst->current is valid. */
1293 dst
->current
= dst
->first
;
1294 bitmap_elt_clear_from (dst
, dst_elt
);
1295 gcc_checking_assert (!dst
->current
== !dst
->first
);
1297 dst
->indx
= dst
->current
->indx
;
1300 /* A &= B. Return true if A changed. */
1303 bitmap_and_into (bitmap a
, const_bitmap b
)
1305 bitmap_element
*a_elt
= a
->first
;
1306 const bitmap_element
*b_elt
= b
->first
;
1307 bitmap_element
*next
;
1308 bool changed
= false;
1310 gcc_checking_assert (!a
->tree_form
&& !b
->tree_form
);
1315 while (a_elt
&& b_elt
)
1317 if (a_elt
->indx
< b_elt
->indx
)
1320 bitmap_list_unlink_element (a
, a_elt
);
1324 else if (b_elt
->indx
< a_elt
->indx
)
1325 b_elt
= b_elt
->next
;
1328 /* Matching elts, generate A &= B. */
1330 BITMAP_WORD ior
= 0;
1332 for (ix
= 0; ix
< BITMAP_ELEMENT_WORDS
; ix
++)
1334 BITMAP_WORD r
= a_elt
->bits
[ix
] & b_elt
->bits
[ix
];
1335 if (a_elt
->bits
[ix
] != r
)
1337 a_elt
->bits
[ix
] = r
;
1342 bitmap_list_unlink_element (a
, a_elt
);
1344 b_elt
= b_elt
->next
;
1351 bitmap_elt_clear_from (a
, a_elt
);
1354 gcc_checking_assert (!a
->current
== !a
->first
1355 && (!a
->current
|| a
->indx
== a
->current
->indx
));
1361 /* Insert an element equal to SRC_ELT after DST_PREV, overwriting DST_ELT
1362 if non-NULL. CHANGED is true if the destination bitmap had already been
1363 changed; the new value of CHANGED is returned. */
1366 bitmap_elt_copy (bitmap dst
, bitmap_element
*dst_elt
, bitmap_element
*dst_prev
,
1367 const bitmap_element
*src_elt
, bool changed
)
1369 if (!changed
&& dst_elt
&& dst_elt
->indx
== src_elt
->indx
)
1373 for (ix
= 0; ix
< BITMAP_ELEMENT_WORDS
; ix
++)
1374 if (src_elt
->bits
[ix
] != dst_elt
->bits
[ix
])
1376 dst_elt
->bits
[ix
] = src_elt
->bits
[ix
];
1384 dst_elt
= bitmap_list_insert_element_after (dst
, dst_prev
,
1387 dst_elt
->indx
= src_elt
->indx
;
1388 memcpy (dst_elt
->bits
, src_elt
->bits
, sizeof (dst_elt
->bits
));
1398 bitmap_and_compl (bitmap dst
, const_bitmap a
, const_bitmap b
)
1400 bitmap_element
*dst_elt
= dst
->first
;
1401 const bitmap_element
*a_elt
= a
->first
;
1402 const bitmap_element
*b_elt
= b
->first
;
1403 bitmap_element
*dst_prev
= NULL
;
1404 bitmap_element
**dst_prev_pnext
= &dst
->first
;
1405 bool changed
= false;
1407 gcc_checking_assert (!dst
->tree_form
&& !a
->tree_form
&& !b
->tree_form
);
1408 gcc_assert (dst
!= a
&& dst
!= b
);
1412 changed
= !bitmap_empty_p (dst
);
1419 while (b_elt
&& b_elt
->indx
< a_elt
->indx
)
1420 b_elt
= b_elt
->next
;
1422 if (!b_elt
|| b_elt
->indx
> a_elt
->indx
)
1424 changed
= bitmap_elt_copy (dst
, dst_elt
, dst_prev
, a_elt
, changed
);
1425 dst_prev
= *dst_prev_pnext
;
1426 dst_prev_pnext
= &dst_prev
->next
;
1427 dst_elt
= *dst_prev_pnext
;
1428 a_elt
= a_elt
->next
;
1433 /* Matching elts, generate A & ~B. */
1435 BITMAP_WORD ior
= 0;
1437 if (!changed
&& dst_elt
&& dst_elt
->indx
== a_elt
->indx
)
1439 for (ix
= 0; ix
< BITMAP_ELEMENT_WORDS
; ix
++)
1441 BITMAP_WORD r
= a_elt
->bits
[ix
] & ~b_elt
->bits
[ix
];
1443 if (dst_elt
->bits
[ix
] != r
)
1446 dst_elt
->bits
[ix
] = r
;
1454 if (!dst_elt
|| dst_elt
->indx
> a_elt
->indx
)
1456 dst_elt
= bitmap_list_insert_element_after (dst
, dst_prev
,
1462 dst_elt
->indx
= a_elt
->indx
;
1463 new_element
= false;
1466 for (ix
= 0; ix
< BITMAP_ELEMENT_WORDS
; ix
++)
1468 BITMAP_WORD r
= a_elt
->bits
[ix
] & ~b_elt
->bits
[ix
];
1470 dst_elt
->bits
[ix
] = r
;
1478 changed
|= !new_element
;
1479 bitmap_list_unlink_element (dst
, dst_elt
);
1480 dst_elt
= *dst_prev_pnext
;
1486 dst_prev
= *dst_prev_pnext
;
1487 dst_prev_pnext
= &dst_prev
->next
;
1488 dst_elt
= *dst_prev_pnext
;
1490 a_elt
= a_elt
->next
;
1491 b_elt
= b_elt
->next
;
1495 /* Ensure that dst->current is valid. */
1496 dst
->current
= dst
->first
;
1501 bitmap_elt_clear_from (dst
, dst_elt
);
1503 gcc_checking_assert (!dst
->current
== !dst
->first
);
1505 dst
->indx
= dst
->current
->indx
;
1510 /* A &= ~B. Returns true if A changes */
1513 bitmap_and_compl_into (bitmap a
, const_bitmap b
)
1515 bitmap_element
*a_elt
= a
->first
;
1516 const bitmap_element
*b_elt
= b
->first
;
1517 bitmap_element
*next
;
1518 BITMAP_WORD changed
= 0;
1520 gcc_checking_assert (!a
->tree_form
&& !b
->tree_form
);
1524 if (bitmap_empty_p (a
))
1533 while (a_elt
&& b_elt
)
1535 if (a_elt
->indx
< b_elt
->indx
)
1536 a_elt
= a_elt
->next
;
1537 else if (b_elt
->indx
< a_elt
->indx
)
1538 b_elt
= b_elt
->next
;
1541 /* Matching elts, generate A &= ~B. */
1543 BITMAP_WORD ior
= 0;
1545 for (ix
= 0; ix
< BITMAP_ELEMENT_WORDS
; ix
++)
1547 BITMAP_WORD cleared
= a_elt
->bits
[ix
] & b_elt
->bits
[ix
];
1548 BITMAP_WORD r
= a_elt
->bits
[ix
] ^ cleared
;
1550 a_elt
->bits
[ix
] = r
;
1556 bitmap_list_unlink_element (a
, a_elt
);
1558 b_elt
= b_elt
->next
;
1561 gcc_checking_assert (!a
->current
== !a
->first
1562 && (!a
->current
|| a
->indx
== a
->current
->indx
));
1563 return changed
!= 0;
1566 /* Set COUNT bits from START in HEAD. */
1568 bitmap_set_range (bitmap head
, unsigned int start
, unsigned int count
)
1570 unsigned int first_index
, end_bit_plus1
, last_index
;
1571 bitmap_element
*elt
, *elt_prev
;
1574 gcc_checking_assert (!head
->tree_form
);
1581 bitmap_set_bit (head
, start
);
1585 first_index
= start
/ BITMAP_ELEMENT_ALL_BITS
;
1586 end_bit_plus1
= start
+ count
;
1587 last_index
= (end_bit_plus1
- 1) / BITMAP_ELEMENT_ALL_BITS
;
1588 elt
= bitmap_list_find_element (head
, first_index
);
1590 /* If bitmap_list_find_element returns zero, the current is the closest block
1591 to the result. Otherwise, just use bitmap_element_allocate to
1592 ensure ELT is set; in the loop below, ELT == NULL means "insert
1593 at the end of the bitmap". */
1596 elt
= bitmap_element_allocate (head
);
1597 elt
->indx
= first_index
;
1598 bitmap_list_link_element (head
, elt
);
1601 gcc_checking_assert (elt
->indx
== first_index
);
1602 elt_prev
= elt
->prev
;
1603 for (i
= first_index
; i
<= last_index
; i
++)
1605 unsigned elt_start_bit
= i
* BITMAP_ELEMENT_ALL_BITS
;
1606 unsigned elt_end_bit_plus1
= elt_start_bit
+ BITMAP_ELEMENT_ALL_BITS
;
1608 unsigned int first_word_to_mod
;
1609 BITMAP_WORD first_mask
;
1610 unsigned int last_word_to_mod
;
1611 BITMAP_WORD last_mask
;
1614 if (!elt
|| elt
->indx
!= i
)
1615 elt
= bitmap_list_insert_element_after (head
, elt_prev
, i
);
1617 if (elt_start_bit
<= start
)
1619 /* The first bit to turn on is somewhere inside this
1621 first_word_to_mod
= (start
- elt_start_bit
) / BITMAP_WORD_BITS
;
1623 /* This mask should have 1s in all bits >= start position. */
1625 (((BITMAP_WORD
) 1) << ((start
% BITMAP_WORD_BITS
))) - 1;
1626 first_mask
= ~first_mask
;
1630 /* The first bit to turn on is below this start of this elt. */
1631 first_word_to_mod
= 0;
1632 first_mask
= ~(BITMAP_WORD
) 0;
1635 if (elt_end_bit_plus1
<= end_bit_plus1
)
1637 /* The last bit to turn on is beyond this elt. */
1638 last_word_to_mod
= BITMAP_ELEMENT_WORDS
- 1;
1639 last_mask
= ~(BITMAP_WORD
) 0;
1643 /* The last bit to turn on is inside to this elt. */
1645 (end_bit_plus1
- elt_start_bit
) / BITMAP_WORD_BITS
;
1647 /* The last mask should have 1s below the end bit. */
1649 (((BITMAP_WORD
) 1) << ((end_bit_plus1
% BITMAP_WORD_BITS
))) - 1;
1652 if (first_word_to_mod
== last_word_to_mod
)
1654 BITMAP_WORD mask
= first_mask
& last_mask
;
1655 elt
->bits
[first_word_to_mod
] |= mask
;
1659 elt
->bits
[first_word_to_mod
] |= first_mask
;
1660 if (BITMAP_ELEMENT_WORDS
> 2)
1661 for (ix
= first_word_to_mod
+ 1; ix
< last_word_to_mod
; ix
++)
1662 elt
->bits
[ix
] = ~(BITMAP_WORD
) 0;
1663 elt
->bits
[last_word_to_mod
] |= last_mask
;
1670 head
->current
= elt
? elt
: elt_prev
;
1671 head
->indx
= head
->current
->indx
;
1674 /* Clear COUNT bits from START in HEAD. */
1676 bitmap_clear_range (bitmap head
, unsigned int start
, unsigned int count
)
1678 unsigned int first_index
, end_bit_plus1
, last_index
;
1679 bitmap_element
*elt
;
1681 gcc_checking_assert (!head
->tree_form
);
1688 bitmap_clear_bit (head
, start
);
1692 first_index
= start
/ BITMAP_ELEMENT_ALL_BITS
;
1693 end_bit_plus1
= start
+ count
;
1694 last_index
= (end_bit_plus1
- 1) / BITMAP_ELEMENT_ALL_BITS
;
1695 elt
= bitmap_list_find_element (head
, first_index
);
1697 /* If bitmap_list_find_element returns zero, the current is the closest block
1698 to the result. If the current is less than first index, find the
1699 next one. Otherwise, just set elt to be current. */
1704 if (head
->indx
< first_index
)
1706 elt
= head
->current
->next
;
1711 elt
= head
->current
;
1717 while (elt
&& (elt
->indx
<= last_index
))
1719 bitmap_element
* next_elt
= elt
->next
;
1720 unsigned elt_start_bit
= (elt
->indx
) * BITMAP_ELEMENT_ALL_BITS
;
1721 unsigned elt_end_bit_plus1
= elt_start_bit
+ BITMAP_ELEMENT_ALL_BITS
;
1724 if (elt_start_bit
>= start
&& elt_end_bit_plus1
<= end_bit_plus1
)
1725 /* Get rid of the entire elt and go to the next one. */
1726 bitmap_list_unlink_element (head
, elt
);
1729 /* Going to have to knock out some bits in this elt. */
1730 unsigned int first_word_to_mod
;
1731 BITMAP_WORD first_mask
;
1732 unsigned int last_word_to_mod
;
1733 BITMAP_WORD last_mask
;
1737 if (elt_start_bit
<= start
)
1739 /* The first bit to turn off is somewhere inside this
1741 first_word_to_mod
= (start
- elt_start_bit
) / BITMAP_WORD_BITS
;
1743 /* This mask should have 1s in all bits >= start position. */
1745 (((BITMAP_WORD
) 1) << ((start
% BITMAP_WORD_BITS
))) - 1;
1746 first_mask
= ~first_mask
;
1750 /* The first bit to turn off is below this start of this elt. */
1751 first_word_to_mod
= 0;
1753 first_mask
= ~first_mask
;
1756 if (elt_end_bit_plus1
<= end_bit_plus1
)
1758 /* The last bit to turn off is beyond this elt. */
1759 last_word_to_mod
= BITMAP_ELEMENT_WORDS
- 1;
1761 last_mask
= ~last_mask
;
1765 /* The last bit to turn off is inside to this elt. */
1767 (end_bit_plus1
- elt_start_bit
) / BITMAP_WORD_BITS
;
1769 /* The last mask should have 1s below the end bit. */
1771 (((BITMAP_WORD
) 1) << (((end_bit_plus1
) % BITMAP_WORD_BITS
))) - 1;
1775 if (first_word_to_mod
== last_word_to_mod
)
1777 BITMAP_WORD mask
= first_mask
& last_mask
;
1778 elt
->bits
[first_word_to_mod
] &= ~mask
;
1782 elt
->bits
[first_word_to_mod
] &= ~first_mask
;
1783 if (BITMAP_ELEMENT_WORDS
> 2)
1784 for (i
= first_word_to_mod
+ 1; i
< last_word_to_mod
; i
++)
1786 elt
->bits
[last_word_to_mod
] &= ~last_mask
;
1788 for (i
= 0; i
< BITMAP_ELEMENT_WORDS
; i
++)
1794 /* Check to see if there are any bits left. */
1796 bitmap_list_unlink_element (head
, elt
);
1803 head
->current
= elt
;
1804 head
->indx
= head
->current
->indx
;
1811 bitmap_compl_and_into (bitmap a
, const_bitmap b
)
1813 bitmap_element
*a_elt
= a
->first
;
1814 const bitmap_element
*b_elt
= b
->first
;
1815 bitmap_element
*a_prev
= NULL
;
1816 bitmap_element
*next
;
1818 gcc_checking_assert (!a
->tree_form
&& !b
->tree_form
);
1819 gcc_assert (a
!= b
);
1821 if (bitmap_empty_p (a
))
1826 if (bitmap_empty_p (b
))
1832 while (a_elt
|| b_elt
)
1834 if (!b_elt
|| (a_elt
&& a_elt
->indx
< b_elt
->indx
))
1836 /* A is before B. Remove A */
1838 a_prev
= a_elt
->prev
;
1839 bitmap_list_unlink_element (a
, a_elt
);
1842 else if (!a_elt
|| b_elt
->indx
< a_elt
->indx
)
1844 /* B is before A. Copy B. */
1845 next
= bitmap_list_insert_element_after (a
, a_prev
, b_elt
->indx
);
1846 memcpy (next
->bits
, b_elt
->bits
, sizeof (next
->bits
));
1848 b_elt
= b_elt
->next
;
1852 /* Matching elts, generate A = ~A & B. */
1854 BITMAP_WORD ior
= 0;
1856 for (ix
= 0; ix
< BITMAP_ELEMENT_WORDS
; ix
++)
1858 BITMAP_WORD cleared
= a_elt
->bits
[ix
] & b_elt
->bits
[ix
];
1859 BITMAP_WORD r
= b_elt
->bits
[ix
] ^ cleared
;
1861 a_elt
->bits
[ix
] = r
;
1866 bitmap_list_unlink_element (a
, a_elt
);
1870 b_elt
= b_elt
->next
;
1873 gcc_checking_assert (!a
->current
== !a
->first
1874 && (!a
->current
|| a
->indx
== a
->current
->indx
));
1879 /* Insert an element corresponding to A_ELT | B_ELT after DST_PREV,
1880 overwriting DST_ELT if non-NULL. CHANGED is true if the destination bitmap
1881 had already been changed; the new value of CHANGED is returned. */
1884 bitmap_elt_ior (bitmap dst
, bitmap_element
*dst_elt
, bitmap_element
*dst_prev
,
1885 const bitmap_element
*a_elt
, const bitmap_element
*b_elt
,
1888 gcc_assert (a_elt
|| b_elt
);
1890 if (a_elt
&& b_elt
&& a_elt
->indx
== b_elt
->indx
)
1892 /* Matching elts, generate A | B. */
1895 if (!changed
&& dst_elt
&& dst_elt
->indx
== a_elt
->indx
)
1897 for (ix
= 0; ix
< BITMAP_ELEMENT_WORDS
; ix
++)
1899 BITMAP_WORD r
= a_elt
->bits
[ix
] | b_elt
->bits
[ix
];
1900 if (r
!= dst_elt
->bits
[ix
])
1902 dst_elt
->bits
[ix
] = r
;
1911 dst_elt
= bitmap_list_insert_element_after (dst
, dst_prev
,
1914 dst_elt
->indx
= a_elt
->indx
;
1915 for (ix
= 0; ix
< BITMAP_ELEMENT_WORDS
; ix
++)
1917 BITMAP_WORD r
= a_elt
->bits
[ix
] | b_elt
->bits
[ix
];
1918 dst_elt
->bits
[ix
] = r
;
1924 /* Copy a single element. */
1925 const bitmap_element
*src
;
1927 if (!b_elt
|| (a_elt
&& a_elt
->indx
< b_elt
->indx
))
1932 gcc_checking_assert (src
);
1933 changed
= bitmap_elt_copy (dst
, dst_elt
, dst_prev
, src
, changed
);
1939 /* DST = A | B. Return true if DST changes. */
1942 bitmap_ior (bitmap dst
, const_bitmap a
, const_bitmap b
)
1944 bitmap_element
*dst_elt
= dst
->first
;
1945 const bitmap_element
*a_elt
= a
->first
;
1946 const bitmap_element
*b_elt
= b
->first
;
1947 bitmap_element
*dst_prev
= NULL
;
1948 bitmap_element
**dst_prev_pnext
= &dst
->first
;
1949 bool changed
= false;
1951 gcc_checking_assert (!dst
->tree_form
&& !a
->tree_form
&& !b
->tree_form
);
1952 gcc_assert (dst
!= a
&& dst
!= b
);
1954 while (a_elt
|| b_elt
)
1956 changed
= bitmap_elt_ior (dst
, dst_elt
, dst_prev
, a_elt
, b_elt
, changed
);
1958 if (a_elt
&& b_elt
&& a_elt
->indx
== b_elt
->indx
)
1960 a_elt
= a_elt
->next
;
1961 b_elt
= b_elt
->next
;
1965 if (a_elt
&& (!b_elt
|| a_elt
->indx
<= b_elt
->indx
))
1966 a_elt
= a_elt
->next
;
1967 else if (b_elt
&& (!a_elt
|| b_elt
->indx
<= a_elt
->indx
))
1968 b_elt
= b_elt
->next
;
1971 dst_prev
= *dst_prev_pnext
;
1972 dst_prev_pnext
= &dst_prev
->next
;
1973 dst_elt
= *dst_prev_pnext
;
1979 /* Ensure that dst->current is valid. */
1980 dst
->current
= dst
->first
;
1981 bitmap_elt_clear_from (dst
, dst_elt
);
1983 gcc_checking_assert (!dst
->current
== !dst
->first
);
1985 dst
->indx
= dst
->current
->indx
;
1989 /* A |= B. Return true if A changes. */
1992 bitmap_ior_into (bitmap a
, const_bitmap b
)
1994 bitmap_element
*a_elt
= a
->first
;
1995 const bitmap_element
*b_elt
= b
->first
;
1996 bitmap_element
*a_prev
= NULL
;
1997 bitmap_element
**a_prev_pnext
= &a
->first
;
1998 bool changed
= false;
2000 gcc_checking_assert (!a
->tree_form
&& !b
->tree_form
);
2006 /* If A lags behind B, just advance it. */
2007 if (!a_elt
|| a_elt
->indx
== b_elt
->indx
)
2009 changed
= bitmap_elt_ior (a
, a_elt
, a_prev
, a_elt
, b_elt
, changed
);
2010 b_elt
= b_elt
->next
;
2012 else if (a_elt
->indx
> b_elt
->indx
)
2014 changed
= bitmap_elt_copy (a
, NULL
, a_prev
, b_elt
, changed
);
2015 b_elt
= b_elt
->next
;
2018 a_prev
= *a_prev_pnext
;
2019 a_prev_pnext
= &a_prev
->next
;
2020 a_elt
= *a_prev_pnext
;
2023 gcc_checking_assert (!a
->current
== !a
->first
);
2025 a
->indx
= a
->current
->indx
;
2032 bitmap_xor (bitmap dst
, const_bitmap a
, const_bitmap b
)
2034 bitmap_element
*dst_elt
= dst
->first
;
2035 const bitmap_element
*a_elt
= a
->first
;
2036 const bitmap_element
*b_elt
= b
->first
;
2037 bitmap_element
*dst_prev
= NULL
;
2039 gcc_checking_assert (!dst
->tree_form
&& !a
->tree_form
&& !b
->tree_form
);
2040 gcc_assert (dst
!= a
&& dst
!= b
);
2048 while (a_elt
|| b_elt
)
2050 if (a_elt
&& b_elt
&& a_elt
->indx
== b_elt
->indx
)
2052 /* Matching elts, generate A ^ B. */
2054 BITMAP_WORD ior
= 0;
2057 dst_elt
= bitmap_list_insert_element_after (dst
, dst_prev
,
2060 dst_elt
->indx
= a_elt
->indx
;
2061 for (ix
= 0; ix
< BITMAP_ELEMENT_WORDS
; ix
++)
2063 BITMAP_WORD r
= a_elt
->bits
[ix
] ^ b_elt
->bits
[ix
];
2066 dst_elt
->bits
[ix
] = r
;
2068 a_elt
= a_elt
->next
;
2069 b_elt
= b_elt
->next
;
2073 dst_elt
= dst_elt
->next
;
2078 /* Copy a single element. */
2079 const bitmap_element
*src
;
2081 if (!b_elt
|| (a_elt
&& a_elt
->indx
< b_elt
->indx
))
2084 a_elt
= a_elt
->next
;
2089 b_elt
= b_elt
->next
;
2093 dst_elt
= bitmap_list_insert_element_after (dst
, dst_prev
,
2096 dst_elt
->indx
= src
->indx
;
2097 memcpy (dst_elt
->bits
, src
->bits
, sizeof (dst_elt
->bits
));
2099 dst_elt
= dst_elt
->next
;
2102 /* Ensure that dst->current is valid. */
2103 dst
->current
= dst
->first
;
2104 bitmap_elt_clear_from (dst
, dst_elt
);
2105 gcc_checking_assert (!dst
->current
== !dst
->first
);
2107 dst
->indx
= dst
->current
->indx
;
2113 bitmap_xor_into (bitmap a
, const_bitmap b
)
2115 bitmap_element
*a_elt
= a
->first
;
2116 const bitmap_element
*b_elt
= b
->first
;
2117 bitmap_element
*a_prev
= NULL
;
2119 gcc_checking_assert (!a
->tree_form
&& !b
->tree_form
);
2129 if (!a_elt
|| b_elt
->indx
< a_elt
->indx
)
2132 bitmap_element
*dst
= bitmap_list_insert_element_after (a
, a_prev
,
2134 memcpy (dst
->bits
, b_elt
->bits
, sizeof (dst
->bits
));
2136 b_elt
= b_elt
->next
;
2138 else if (a_elt
->indx
< b_elt
->indx
)
2141 a_elt
= a_elt
->next
;
2145 /* Matching elts, generate A ^= B. */
2147 BITMAP_WORD ior
= 0;
2148 bitmap_element
*next
= a_elt
->next
;
2150 for (ix
= 0; ix
< BITMAP_ELEMENT_WORDS
; ix
++)
2152 BITMAP_WORD r
= a_elt
->bits
[ix
] ^ b_elt
->bits
[ix
];
2155 a_elt
->bits
[ix
] = r
;
2157 b_elt
= b_elt
->next
;
2161 bitmap_list_unlink_element (a
, a_elt
);
2165 gcc_checking_assert (!a
->current
== !a
->first
);
2167 a
->indx
= a
->current
->indx
;
2170 /* Return true if two bitmaps are identical.
2171 We do not bother with a check for pointer equality, as that never
2172 occurs in practice. */
2175 bitmap_equal_p (const_bitmap a
, const_bitmap b
)
2177 const bitmap_element
*a_elt
;
2178 const bitmap_element
*b_elt
;
2181 gcc_checking_assert (!a
->tree_form
&& !b
->tree_form
);
2183 for (a_elt
= a
->first
, b_elt
= b
->first
;
2185 a_elt
= a_elt
->next
, b_elt
= b_elt
->next
)
2187 if (a_elt
->indx
!= b_elt
->indx
)
2189 for (ix
= 0; ix
< BITMAP_ELEMENT_WORDS
; ix
++)
2190 if (a_elt
->bits
[ix
] != b_elt
->bits
[ix
])
2193 return !a_elt
&& !b_elt
;
2196 /* Return true if A AND B is not empty. */
2199 bitmap_intersect_p (const_bitmap a
, const_bitmap b
)
2201 const bitmap_element
*a_elt
;
2202 const bitmap_element
*b_elt
;
2205 gcc_checking_assert (!a
->tree_form
&& !b
->tree_form
);
2207 for (a_elt
= a
->first
, b_elt
= b
->first
;
2210 if (a_elt
->indx
< b_elt
->indx
)
2211 a_elt
= a_elt
->next
;
2212 else if (b_elt
->indx
< a_elt
->indx
)
2213 b_elt
= b_elt
->next
;
2216 for (ix
= 0; ix
< BITMAP_ELEMENT_WORDS
; ix
++)
2217 if (a_elt
->bits
[ix
] & b_elt
->bits
[ix
])
2219 a_elt
= a_elt
->next
;
2220 b_elt
= b_elt
->next
;
2226 /* Return true if A AND NOT B is not empty. */
2229 bitmap_intersect_compl_p (const_bitmap a
, const_bitmap b
)
2231 const bitmap_element
*a_elt
;
2232 const bitmap_element
*b_elt
;
2235 gcc_checking_assert (!a
->tree_form
&& !b
->tree_form
);
2237 for (a_elt
= a
->first
, b_elt
= b
->first
;
2240 if (a_elt
->indx
< b_elt
->indx
)
2242 else if (b_elt
->indx
< a_elt
->indx
)
2243 b_elt
= b_elt
->next
;
2246 for (ix
= 0; ix
< BITMAP_ELEMENT_WORDS
; ix
++)
2247 if (a_elt
->bits
[ix
] & ~b_elt
->bits
[ix
])
2249 a_elt
= a_elt
->next
;
2250 b_elt
= b_elt
->next
;
2253 return a_elt
!= NULL
;
2257 /* DST = A | (FROM1 & ~FROM2). Return true if DST changes. */
2260 bitmap_ior_and_compl (bitmap dst
, const_bitmap a
, const_bitmap b
, const_bitmap kill
)
2262 bool changed
= false;
2264 bitmap_element
*dst_elt
= dst
->first
;
2265 const bitmap_element
*a_elt
= a
->first
;
2266 const bitmap_element
*b_elt
= b
->first
;
2267 const bitmap_element
*kill_elt
= kill
->first
;
2268 bitmap_element
*dst_prev
= NULL
;
2269 bitmap_element
**dst_prev_pnext
= &dst
->first
;
2271 gcc_checking_assert (!dst
->tree_form
&& !a
->tree_form
&& !b
->tree_form
2272 && !kill
->tree_form
);
2273 gcc_assert (dst
!= a
&& dst
!= b
&& dst
!= kill
);
2275 /* Special cases. We don't bother checking for bitmap_equal_p (b, kill). */
2276 if (b
== kill
|| bitmap_empty_p (b
))
2278 changed
= !bitmap_equal_p (dst
, a
);
2280 bitmap_copy (dst
, a
);
2283 if (bitmap_empty_p (kill
))
2284 return bitmap_ior (dst
, a
, b
);
2285 if (bitmap_empty_p (a
))
2286 return bitmap_and_compl (dst
, b
, kill
);
2288 while (a_elt
|| b_elt
)
2290 bool new_element
= false;
2293 while (kill_elt
&& kill_elt
->indx
< b_elt
->indx
)
2294 kill_elt
= kill_elt
->next
;
2296 if (b_elt
&& kill_elt
&& kill_elt
->indx
== b_elt
->indx
2297 && (!a_elt
|| a_elt
->indx
>= b_elt
->indx
))
2299 bitmap_element tmp_elt
;
2302 BITMAP_WORD ior
= 0;
2303 tmp_elt
.indx
= b_elt
->indx
;
2304 for (ix
= 0; ix
< BITMAP_ELEMENT_WORDS
; ix
++)
2306 BITMAP_WORD r
= b_elt
->bits
[ix
] & ~kill_elt
->bits
[ix
];
2308 tmp_elt
.bits
[ix
] = r
;
2313 changed
= bitmap_elt_ior (dst
, dst_elt
, dst_prev
,
2314 a_elt
, &tmp_elt
, changed
);
2316 if (a_elt
&& a_elt
->indx
== b_elt
->indx
)
2317 a_elt
= a_elt
->next
;
2320 b_elt
= b_elt
->next
;
2321 kill_elt
= kill_elt
->next
;
2325 changed
= bitmap_elt_ior (dst
, dst_elt
, dst_prev
,
2326 a_elt
, b_elt
, changed
);
2329 if (a_elt
&& b_elt
&& a_elt
->indx
== b_elt
->indx
)
2331 a_elt
= a_elt
->next
;
2332 b_elt
= b_elt
->next
;
2336 if (a_elt
&& (!b_elt
|| a_elt
->indx
<= b_elt
->indx
))
2337 a_elt
= a_elt
->next
;
2338 else if (b_elt
&& (!a_elt
|| b_elt
->indx
<= a_elt
->indx
))
2339 b_elt
= b_elt
->next
;
2345 dst_prev
= *dst_prev_pnext
;
2346 dst_prev_pnext
= &dst_prev
->next
;
2347 dst_elt
= *dst_prev_pnext
;
2354 /* Ensure that dst->current is valid. */
2355 dst
->current
= dst
->first
;
2356 bitmap_elt_clear_from (dst
, dst_elt
);
2358 gcc_checking_assert (!dst
->current
== !dst
->first
);
2360 dst
->indx
= dst
->current
->indx
;
2365 /* A |= (B & ~C). Return true if A changes. */
2368 bitmap_ior_and_compl_into (bitmap a
, const_bitmap b
, const_bitmap c
)
2373 gcc_checking_assert (!a
->tree_form
&& !b
->tree_form
&& !c
->tree_form
);
2375 bitmap_initialize (&tmp
, &bitmap_default_obstack
);
2376 bitmap_and_compl (&tmp
, b
, c
);
2377 changed
= bitmap_ior_into (a
, &tmp
);
2378 bitmap_clear (&tmp
);
2383 /* A |= (B & C). Return true if A changes. */
2386 bitmap_ior_and_into (bitmap a
, const_bitmap b
, const_bitmap c
)
2388 bitmap_element
*a_elt
= a
->first
;
2389 const bitmap_element
*b_elt
= b
->first
;
2390 const bitmap_element
*c_elt
= c
->first
;
2391 bitmap_element and_elt
;
2392 bitmap_element
*a_prev
= NULL
;
2393 bitmap_element
**a_prev_pnext
= &a
->first
;
2394 bool changed
= false;
2397 gcc_checking_assert (!a
->tree_form
&& !b
->tree_form
&& !c
->tree_form
);
2400 return bitmap_ior_into (a
, b
);
2401 if (bitmap_empty_p (b
) || bitmap_empty_p (c
))
2405 while (b_elt
&& c_elt
)
2407 BITMAP_WORD overall
;
2409 /* Find a common item of B and C. */
2410 while (b_elt
->indx
!= c_elt
->indx
)
2412 if (b_elt
->indx
< c_elt
->indx
)
2414 b_elt
= b_elt
->next
;
2420 c_elt
= c_elt
->next
;
2427 and_elt
.indx
= b_elt
->indx
;
2428 for (ix
= 0; ix
< BITMAP_ELEMENT_WORDS
; ix
++)
2430 and_elt
.bits
[ix
] = b_elt
->bits
[ix
] & c_elt
->bits
[ix
];
2431 overall
|= and_elt
.bits
[ix
];
2434 b_elt
= b_elt
->next
;
2435 c_elt
= c_elt
->next
;
2439 /* Now find a place to insert AND_ELT. */
2442 ix
= a_elt
? a_elt
->indx
: and_elt
.indx
;
2443 if (ix
== and_elt
.indx
)
2444 changed
= bitmap_elt_ior (a
, a_elt
, a_prev
, a_elt
, &and_elt
, changed
);
2445 else if (ix
> and_elt
.indx
)
2446 changed
= bitmap_elt_copy (a
, NULL
, a_prev
, &and_elt
, changed
);
2448 a_prev
= *a_prev_pnext
;
2449 a_prev_pnext
= &a_prev
->next
;
2450 a_elt
= *a_prev_pnext
;
2452 /* If A lagged behind B/C, we advanced it so loop once more. */
2454 while (ix
< and_elt
.indx
);
2458 gcc_checking_assert (!a
->current
== !a
->first
);
2460 a
->indx
= a
->current
->indx
;
2464 /* Compute hash of bitmap (for purposes of hashing). */
2467 bitmap_hash (const_bitmap head
)
2469 const bitmap_element
*ptr
;
2470 BITMAP_WORD hash
= 0;
2473 gcc_checking_assert (!head
->tree_form
);
2475 for (ptr
= head
->first
; ptr
; ptr
= ptr
->next
)
2478 for (ix
= 0; ix
!= BITMAP_ELEMENT_WORDS
; ix
++)
2479 hash
^= ptr
->bits
[ix
];
2481 return (hashval_t
)hash
;
2485 /* Function to obtain a vector of bitmap elements in bit order from
2486 HEAD in tree view. */
2489 bitmap_tree_to_vec (vec
<bitmap_element
*> &elts
, const_bitmap head
)
2491 gcc_checking_assert (head
->tree_form
);
2492 auto_vec
<bitmap_element
*, 32> stack
;
2493 bitmap_element
*e
= head
->first
;
2498 stack
.safe_push (e
);
2501 if (stack
.is_empty ())
2510 /* Debugging function to print out the contents of a bitmap element. */
2513 debug_bitmap_elt_file (FILE *file
, const bitmap_element
*ptr
)
2515 unsigned int i
, j
, col
= 26;
2517 fprintf (file
, "\t" HOST_PTR_PRINTF
" next = " HOST_PTR_PRINTF
2518 " prev = " HOST_PTR_PRINTF
" indx = %u\n\t\tbits = {",
2519 (const void*) ptr
, (const void*) ptr
->next
,
2520 (const void*) ptr
->prev
, ptr
->indx
);
2522 for (i
= 0; i
< BITMAP_ELEMENT_WORDS
; i
++)
2523 for (j
= 0; j
< BITMAP_WORD_BITS
; j
++)
2524 if ((ptr
->bits
[i
] >> j
) & 1)
2528 fprintf (file
, "\n\t\t\t");
2532 fprintf (file
, " %u", (ptr
->indx
* BITMAP_ELEMENT_ALL_BITS
2533 + i
* BITMAP_WORD_BITS
+ j
));
2537 fprintf (file
, " }\n");
2540 /* Debugging function to print out the contents of a bitmap. */
2543 debug_bitmap_file (FILE *file
, const_bitmap head
)
2545 const bitmap_element
*ptr
;
2547 fprintf (file
, "\nfirst = " HOST_PTR_PRINTF
2548 " current = " HOST_PTR_PRINTF
" indx = %u\n",
2549 (void *) head
->first
, (void *) head
->current
, head
->indx
);
2551 if (head
->tree_form
)
2553 auto_vec
<bitmap_element
*, 32> elts
;
2554 bitmap_tree_to_vec (elts
, head
);
2555 for (unsigned i
= 0; i
< elts
.length (); ++i
)
2556 debug_bitmap_elt_file (file
, elts
[i
]);
2559 for (ptr
= head
->first
; ptr
; ptr
= ptr
->next
)
2560 debug_bitmap_elt_file (file
, ptr
);
2563 /* Function to be called from the debugger to print the contents
2567 debug_bitmap (const_bitmap head
)
2569 debug_bitmap_file (stderr
, head
);
2572 /* Function to print out the contents of a bitmap. Unlike debug_bitmap_file,
2573 it does not print anything but the bits. */
2576 bitmap_print (FILE *file
, const_bitmap head
, const char *prefix
,
2579 const char *comma
= "";
2582 fputs (prefix
, file
);
2583 if (head
->tree_form
)
2585 auto_vec
<bitmap_element
*, 32> elts
;
2586 bitmap_tree_to_vec (elts
, head
);
2587 for (i
= 0; i
< elts
.length (); ++i
)
2588 for (unsigned ix
= 0; ix
!= BITMAP_ELEMENT_WORDS
; ++ix
)
2590 BITMAP_WORD word
= elts
[i
]->bits
[ix
];
2591 for (unsigned bit
= 0; bit
!= BITMAP_WORD_BITS
; ++bit
)
2592 if (word
& ((BITMAP_WORD
)1 << bit
))
2594 fprintf (file
, "%s%d", comma
,
2595 (bit
+ BITMAP_WORD_BITS
* ix
2596 + elts
[i
]->indx
* BITMAP_ELEMENT_ALL_BITS
));
2604 EXECUTE_IF_SET_IN_BITMAP (head
, 0, i
, bi
)
2606 fprintf (file
, "%s%d", comma
, i
);
2610 fputs (suffix
, file
);
2613 /* Output per-bitmap memory usage statistics. */
2615 dump_bitmap_statistics (void)
2617 if (!GATHER_STATISTICS
)
2620 bitmap_mem_desc
.dump (BITMAP_ORIGIN
);
2624 debug (const bitmap_head
&ref
)
2626 dump_bitmap (stderr
, &ref
);
2630 debug (const bitmap_head
*ptr
)
2635 fprintf (stderr
, "<nil>\n");
2639 bitmap_head::dump ()
2646 namespace selftest
{
2648 /* Selftests for bitmaps. */
2650 /* Freshly-created bitmaps ought to be empty. */
2655 bitmap b
= bitmap_gc_alloc ();
2656 ASSERT_TRUE (bitmap_empty_p (b
));
2659 /* Verify bitmap_set_range. */
2664 bitmap b
= bitmap_gc_alloc ();
2665 ASSERT_TRUE (bitmap_empty_p (b
));
2667 bitmap_set_range (b
, 7, 5);
2668 ASSERT_FALSE (bitmap_empty_p (b
));
2669 ASSERT_EQ (5, bitmap_count_bits (b
));
2671 /* Verify bitmap_bit_p at the boundaries. */
2672 ASSERT_FALSE (bitmap_bit_p (b
, 6));
2673 ASSERT_TRUE (bitmap_bit_p (b
, 7));
2674 ASSERT_TRUE (bitmap_bit_p (b
, 11));
2675 ASSERT_FALSE (bitmap_bit_p (b
, 12));
2678 /* Verify splitting a range into two pieces using bitmap_clear_bit. */
2681 test_clear_bit_in_middle ()
2683 bitmap b
= bitmap_gc_alloc ();
2685 /* Set b to [100..200]. */
2686 bitmap_set_range (b
, 100, 100);
2687 ASSERT_EQ (100, bitmap_count_bits (b
));
2689 /* Clear a bit in the middle. */
2690 bool changed
= bitmap_clear_bit (b
, 150);
2691 ASSERT_TRUE (changed
);
2692 ASSERT_EQ (99, bitmap_count_bits (b
));
2693 ASSERT_TRUE (bitmap_bit_p (b
, 149));
2694 ASSERT_FALSE (bitmap_bit_p (b
, 150));
2695 ASSERT_TRUE (bitmap_bit_p (b
, 151));
2698 /* Verify bitmap_copy. */
2703 bitmap src
= bitmap_gc_alloc ();
2704 bitmap_set_range (src
, 40, 10);
2706 bitmap dst
= bitmap_gc_alloc ();
2707 ASSERT_FALSE (bitmap_equal_p (src
, dst
));
2708 bitmap_copy (dst
, src
);
2709 ASSERT_TRUE (bitmap_equal_p (src
, dst
));
2711 /* Verify that we can make them unequal again... */
2712 bitmap_set_range (src
, 70, 5);
2713 ASSERT_FALSE (bitmap_equal_p (src
, dst
));
2715 /* ...and that changing src after the copy didn't affect
2717 ASSERT_FALSE (bitmap_bit_p (dst
, 70));
2720 /* Verify bitmap_single_bit_set_p. */
2723 test_bitmap_single_bit_set_p ()
2725 bitmap b
= bitmap_gc_alloc ();
2727 ASSERT_FALSE (bitmap_single_bit_set_p (b
));
2729 bitmap_set_range (b
, 42, 1);
2730 ASSERT_TRUE (bitmap_single_bit_set_p (b
));
2731 ASSERT_EQ (42, bitmap_first_set_bit (b
));
2733 bitmap_set_range (b
, 1066, 1);
2734 ASSERT_FALSE (bitmap_single_bit_set_p (b
));
2735 ASSERT_EQ (42, bitmap_first_set_bit (b
));
2737 bitmap_clear_range (b
, 0, 100);
2738 ASSERT_TRUE (bitmap_single_bit_set_p (b
));
2739 ASSERT_EQ (1066, bitmap_first_set_bit (b
));
2742 /* Run all of the selftests within this file. */
2749 test_clear_bit_in_middle ();
2751 test_bitmap_single_bit_set_p ();
2754 } // namespace selftest
2755 #endif /* CHECKING_P */
2757 #include "gt-bitmap.h"