2 Copyright (C) 1999-2012 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"
25 /* This suffices for roughly 99% of the hosts we run on, and the rest
26 don't have 256 bit integers. */
27 #if SBITMAP_ELT_BITS > 255
28 #error Need to increase size of datatype used for popcount
31 #if GCC_VERSION >= 3400
32 # if SBITMAP_ELT_BITS == HOST_BITS_PER_LONG
33 # define do_popcount(x) __builtin_popcountl(x)
34 # elif SBITMAP_ELT_BITS == HOST_BITS_PER_LONGLONG
35 # define do_popcount(x) __builtin_popcountll(x)
37 # error "internal error: sbitmap.h and hwint.h are inconsistent"
40 static unsigned long sbitmap_elt_popcount (SBITMAP_ELT_TYPE
);
41 # define do_popcount(x) sbitmap_elt_popcount((x))
44 typedef SBITMAP_ELT_TYPE
*sbitmap_ptr
;
45 typedef const SBITMAP_ELT_TYPE
*const_sbitmap_ptr
;
47 /* This macro controls debugging that is as expensive as the
48 operations it verifies. */
50 /* #define BITMAP_DEBUGGING */
51 #ifdef BITMAP_DEBUGGING
53 /* Verify the population count of sbitmap A matches the cached value,
54 if there is a cached value. */
57 sbitmap_verify_popcount (const_sbitmap a
)
60 unsigned int lastword
;
66 for (ix
= 0; ix
< lastword
; ix
++)
67 gcc_assert (a
->popcount
[ix
] == do_popcount (a
->elms
[ix
]));
71 /* Bitmap manipulation routines. */
73 /* Allocate a simple bitmap of N_ELMS bits. */
76 sbitmap_alloc (unsigned int n_elms
)
78 unsigned int bytes
, size
, amt
;
81 size
= SBITMAP_SET_SIZE (n_elms
);
82 bytes
= size
* sizeof (SBITMAP_ELT_TYPE
);
83 amt
= (sizeof (struct simple_bitmap_def
)
84 + bytes
- sizeof (SBITMAP_ELT_TYPE
));
85 bmap
= (sbitmap
) xmalloc (amt
);
86 bmap
->n_bits
= n_elms
;
88 bmap
->popcount
= NULL
;
92 /* Allocate a simple bitmap of N_ELMS bits, and a popcount array. */
95 sbitmap_alloc_with_popcount (unsigned int n_elms
)
97 sbitmap
const bmap
= sbitmap_alloc (n_elms
);
98 bmap
->popcount
= XNEWVEC (unsigned char, bmap
->size
);
102 /* Resize a simple bitmap BMAP to N_ELMS bits. If increasing the
103 size of BMAP, clear the new bits to zero if the DEF argument
104 is zero, and set them to one otherwise. */
107 sbitmap_resize (sbitmap bmap
, unsigned int n_elms
, int def
)
109 unsigned int bytes
, size
, amt
;
110 unsigned int last_bit
;
112 size
= SBITMAP_SET_SIZE (n_elms
);
113 bytes
= size
* sizeof (SBITMAP_ELT_TYPE
);
114 if (bytes
> SBITMAP_SIZE_BYTES (bmap
))
116 amt
= (sizeof (struct simple_bitmap_def
)
117 + bytes
- sizeof (SBITMAP_ELT_TYPE
));
118 bmap
= (sbitmap
) xrealloc (bmap
, amt
);
120 bmap
->popcount
= XRESIZEVEC (unsigned char, bmap
->popcount
, size
);
123 if (n_elms
> bmap
->n_bits
)
127 memset (bmap
->elms
+ bmap
->size
, -1,
128 bytes
- SBITMAP_SIZE_BYTES (bmap
));
130 /* Set the new bits if the original last element. */
131 last_bit
= bmap
->n_bits
% SBITMAP_ELT_BITS
;
133 bmap
->elms
[bmap
->size
- 1]
134 |= ~((SBITMAP_ELT_TYPE
)-1 >> (SBITMAP_ELT_BITS
- last_bit
));
136 /* Clear the unused bit in the new last element. */
137 last_bit
= n_elms
% SBITMAP_ELT_BITS
;
140 &= (SBITMAP_ELT_TYPE
)-1 >> (SBITMAP_ELT_BITS
- last_bit
);
144 memset (bmap
->elms
+ bmap
->size
, 0,
145 bytes
- SBITMAP_SIZE_BYTES (bmap
));
147 memset (bmap
->popcount
+ bmap
->size
, 0,
148 (size
* sizeof (unsigned char))
149 - (bmap
->size
* sizeof (unsigned char)));
153 else if (n_elms
< bmap
->n_bits
)
155 /* Clear the surplus bits in the last word. */
156 last_bit
= n_elms
% SBITMAP_ELT_BITS
;
160 &= (SBITMAP_ELT_TYPE
)-1 >> (SBITMAP_ELT_BITS
- last_bit
);
162 bmap
->popcount
[size
- 1] = do_popcount (bmap
->elms
[size
- 1]);
166 bmap
->n_bits
= n_elms
;
171 /* Re-allocate a simple bitmap of N_ELMS bits. New storage is uninitialized. */
174 sbitmap_realloc (sbitmap src
, unsigned int n_elms
)
176 unsigned int bytes
, size
, amt
;
179 size
= SBITMAP_SET_SIZE (n_elms
);
180 bytes
= size
* sizeof (SBITMAP_ELT_TYPE
);
181 amt
= (sizeof (struct simple_bitmap_def
)
182 + bytes
- sizeof (SBITMAP_ELT_TYPE
));
184 if (SBITMAP_SIZE_BYTES (src
) >= bytes
)
186 src
->n_bits
= n_elms
;
190 bmap
= (sbitmap
) xrealloc (src
, amt
);
191 bmap
->n_bits
= n_elms
;
196 /* Allocate a vector of N_VECS bitmaps of N_ELMS bits. */
199 sbitmap_vector_alloc (unsigned int n_vecs
, unsigned int n_elms
)
201 unsigned int i
, bytes
, offset
, elm_bytes
, size
, amt
, vector_bytes
;
202 sbitmap
*bitmap_vector
;
204 size
= SBITMAP_SET_SIZE (n_elms
);
205 bytes
= size
* sizeof (SBITMAP_ELT_TYPE
);
206 elm_bytes
= (sizeof (struct simple_bitmap_def
)
207 + bytes
- sizeof (SBITMAP_ELT_TYPE
));
208 vector_bytes
= n_vecs
* sizeof (sbitmap
*);
210 /* Round up `vector_bytes' to account for the alignment requirements
211 of an sbitmap. One could allocate the vector-table and set of sbitmaps
212 separately, but that requires maintaining two pointers or creating
213 a cover struct to hold both pointers (so our result is still just
214 one pointer). Neither is a bad idea, but this is simpler for now. */
216 /* Based on DEFAULT_ALIGNMENT computation in obstack.c. */
217 struct { char x
; SBITMAP_ELT_TYPE y
; } align
;
218 int alignment
= (char *) & align
.y
- & align
.x
;
219 vector_bytes
= (vector_bytes
+ alignment
- 1) & ~ (alignment
- 1);
222 amt
= vector_bytes
+ (n_vecs
* elm_bytes
);
223 bitmap_vector
= (sbitmap
*) xmalloc (amt
);
225 for (i
= 0, offset
= vector_bytes
; i
< n_vecs
; i
++, offset
+= elm_bytes
)
227 sbitmap b
= (sbitmap
) ((char *) bitmap_vector
+ offset
);
229 bitmap_vector
[i
] = b
;
235 return bitmap_vector
;
238 /* Copy sbitmap SRC to DST. */
241 bitmap_copy (sbitmap dst
, const_sbitmap src
)
243 memcpy (dst
->elms
, src
->elms
, sizeof (SBITMAP_ELT_TYPE
) * dst
->size
);
245 memcpy (dst
->popcount
, src
->popcount
, sizeof (unsigned char) * dst
->size
);
248 /* Copy the first N elements of sbitmap SRC to DST. */
251 bitmap_copy_n (sbitmap dst
, const_sbitmap src
, unsigned int n
)
253 memcpy (dst
->elms
, src
->elms
, sizeof (SBITMAP_ELT_TYPE
) * n
);
255 memcpy (dst
->popcount
, src
->popcount
, sizeof (unsigned char) * n
);
258 /* Determine if a == b. */
260 bitmap_equal_p (const_sbitmap a
, const_sbitmap b
)
262 return !memcmp (a
->elms
, b
->elms
, sizeof (SBITMAP_ELT_TYPE
) * a
->size
);
265 /* Return true if the bitmap is empty. */
268 bitmap_empty_p (const_sbitmap bmap
)
271 for (i
=0; i
<bmap
->size
; i
++)
278 /* Return false if any of the N bits are set in MAP starting at
282 bitmap_range_empty_p (const_sbitmap bmap
, unsigned int start
, unsigned int n
)
284 unsigned int i
= start
/ SBITMAP_ELT_BITS
;
285 SBITMAP_ELT_TYPE elm
;
286 unsigned int shift
= start
% SBITMAP_ELT_BITS
;
288 gcc_assert (bmap
->n_bits
>= start
+ n
);
293 if (shift
+ n
<= SBITMAP_ELT_BITS
)
295 /* The bits are totally contained in a single element. */
296 if (shift
+ n
< SBITMAP_ELT_BITS
)
297 elm
&= ((1 << n
) - 1);
304 n
-= SBITMAP_ELT_BITS
- shift
;
307 /* Deal with full elts. */
308 while (n
>= SBITMAP_ELT_BITS
)
313 n
-= SBITMAP_ELT_BITS
;
316 /* The leftover bits. */
320 elm
&= ((1 << n
) - 1);
329 /* Zero all elements in a bitmap. */
332 bitmap_clear (sbitmap bmap
)
334 memset (bmap
->elms
, 0, SBITMAP_SIZE_BYTES (bmap
));
336 memset (bmap
->popcount
, 0, bmap
->size
* sizeof (unsigned char));
339 /* Set all elements in a bitmap to ones. */
342 bitmap_ones (sbitmap bmap
)
344 unsigned int last_bit
;
346 memset (bmap
->elms
, -1, SBITMAP_SIZE_BYTES (bmap
));
348 memset (bmap
->popcount
, -1, bmap
->size
* sizeof (unsigned char));
350 last_bit
= bmap
->n_bits
% SBITMAP_ELT_BITS
;
353 bmap
->elms
[bmap
->size
- 1]
354 = (SBITMAP_ELT_TYPE
)-1 >> (SBITMAP_ELT_BITS
- last_bit
);
356 bmap
->popcount
[bmap
->size
- 1]
357 = do_popcount (bmap
->elms
[bmap
->size
- 1]);
361 /* Zero a vector of N_VECS bitmaps. */
364 bitmap_vector_clear (sbitmap
*bmap
, unsigned int n_vecs
)
368 for (i
= 0; i
< n_vecs
; i
++)
369 bitmap_clear (bmap
[i
]);
372 /* Set a vector of N_VECS bitmaps to ones. */
375 bitmap_vector_ones (sbitmap
*bmap
, unsigned int n_vecs
)
379 for (i
= 0; i
< n_vecs
; i
++)
380 bitmap_ones (bmap
[i
]);
383 /* Set DST to be A union (B - C).
385 Returns true if any change is made. */
388 bitmap_ior_and_compl (sbitmap dst
, const_sbitmap a
, const_sbitmap b
, const_sbitmap c
)
390 unsigned int i
, n
= dst
->size
;
391 sbitmap_ptr dstp
= dst
->elms
;
392 const_sbitmap_ptr ap
= a
->elms
;
393 const_sbitmap_ptr bp
= b
->elms
;
394 const_sbitmap_ptr cp
= c
->elms
;
395 SBITMAP_ELT_TYPE changed
= 0;
397 gcc_assert (!dst
->popcount
);
399 for (i
= 0; i
< n
; i
++)
401 const SBITMAP_ELT_TYPE tmp
= *ap
++ | (*bp
++ & ~*cp
++);
402 changed
|= *dstp
^ tmp
;
409 /* Set bitmap DST to the bitwise negation of the bitmap SRC. */
412 bitmap_not (sbitmap dst
, const_sbitmap src
)
414 unsigned int i
, n
= dst
->size
;
415 sbitmap_ptr dstp
= dst
->elms
;
416 const_sbitmap_ptr srcp
= src
->elms
;
417 unsigned int last_bit
;
419 gcc_assert (!dst
->popcount
);
421 for (i
= 0; i
< n
; i
++)
424 /* Zero all bits past n_bits, by ANDing dst with bitmap_ones. */
425 last_bit
= src
->n_bits
% SBITMAP_ELT_BITS
;
427 dst
->elms
[n
-1] = dst
->elms
[n
-1]
428 & ((SBITMAP_ELT_TYPE
)-1 >> (SBITMAP_ELT_BITS
- last_bit
));
431 /* Set the bits in DST to be the difference between the bits
432 in A and the bits in B. i.e. dst = a & (~b). */
435 bitmap_and_compl (sbitmap dst
, const_sbitmap a
, const_sbitmap b
)
437 unsigned int i
, dst_size
= dst
->size
;
438 unsigned int min_size
= dst
->size
;
439 sbitmap_ptr dstp
= dst
->elms
;
440 const_sbitmap_ptr ap
= a
->elms
;
441 const_sbitmap_ptr bp
= b
->elms
;
443 gcc_assert (!dst
->popcount
);
445 /* A should be at least as large as DEST, to have a defined source. */
446 gcc_assert (a
->size
>= dst_size
);
447 /* If minuend is smaller, we simply pretend it to be zero bits, i.e.
448 only copy the subtrahend into dest. */
449 if (b
->size
< min_size
)
451 for (i
= 0; i
< min_size
; i
++)
452 *dstp
++ = *ap
++ & (~*bp
++);
453 /* Now fill the rest of dest from A, if B was too short.
454 This makes sense only when destination and A differ. */
455 if (dst
!= a
&& i
!= dst_size
)
456 for (; i
< dst_size
; i
++)
460 /* Return true if there are any bits set in A are also set in B.
461 Return false otherwise. */
464 bitmap_intersect_p (const_sbitmap a
, const_sbitmap b
)
466 const_sbitmap_ptr ap
= a
->elms
;
467 const_sbitmap_ptr bp
= b
->elms
;
470 n
= MIN (a
->size
, b
->size
);
471 for (i
= 0; i
< n
; i
++)
472 if ((*ap
++ & *bp
++) != 0)
478 /* Set DST to be (A and B).
479 Return nonzero if any change is made. */
482 bitmap_and (sbitmap dst
, const_sbitmap a
, const_sbitmap b
)
484 unsigned int i
, n
= dst
->size
;
485 sbitmap_ptr dstp
= dst
->elms
;
486 const_sbitmap_ptr ap
= a
->elms
;
487 const_sbitmap_ptr bp
= b
->elms
;
488 bool has_popcount
= dst
->popcount
!= NULL
;
489 unsigned char *popcountp
= dst
->popcount
;
490 bool anychange
= false;
492 for (i
= 0; i
< n
; i
++)
494 const SBITMAP_ELT_TYPE tmp
= *ap
++ & *bp
++;
497 bool wordchanged
= (*dstp
^ tmp
) != 0;
500 *popcountp
= do_popcount (tmp
);
507 #ifdef BITMAP_DEBUGGING
509 sbitmap_verify_popcount (dst
);
514 /* Set DST to be (A xor B)).
515 Return nonzero if any change is made. */
518 bitmap_xor (sbitmap dst
, const_sbitmap a
, const_sbitmap b
)
520 unsigned int i
, n
= dst
->size
;
521 sbitmap_ptr dstp
= dst
->elms
;
522 const_sbitmap_ptr ap
= a
->elms
;
523 const_sbitmap_ptr bp
= b
->elms
;
524 bool has_popcount
= dst
->popcount
!= NULL
;
525 unsigned char *popcountp
= dst
->popcount
;
526 bool anychange
= false;
528 for (i
= 0; i
< n
; i
++)
530 const SBITMAP_ELT_TYPE tmp
= *ap
++ ^ *bp
++;
533 bool wordchanged
= (*dstp
^ tmp
) != 0;
536 *popcountp
= do_popcount (tmp
);
543 #ifdef BITMAP_DEBUGGING
545 sbitmap_verify_popcount (dst
);
550 /* Set DST to be (A or B)).
551 Return nonzero if any change is made. */
554 bitmap_ior (sbitmap dst
, const_sbitmap a
, const_sbitmap b
)
556 unsigned int i
, n
= dst
->size
;
557 sbitmap_ptr dstp
= dst
->elms
;
558 const_sbitmap_ptr ap
= a
->elms
;
559 const_sbitmap_ptr bp
= b
->elms
;
560 bool has_popcount
= dst
->popcount
!= NULL
;
561 unsigned char *popcountp
= dst
->popcount
;
562 bool anychange
= false;
564 for (i
= 0; i
< n
; i
++)
566 const SBITMAP_ELT_TYPE tmp
= *ap
++ | *bp
++;
569 bool wordchanged
= (*dstp
^ tmp
) != 0;
572 *popcountp
= do_popcount (tmp
);
579 #ifdef BITMAP_DEBUGGING
581 sbitmap_verify_popcount (dst
);
586 /* Return nonzero if A is a subset of B. */
589 bitmap_subset_p (const_sbitmap a
, const_sbitmap b
)
591 unsigned int i
, n
= a
->size
;
592 const_sbitmap_ptr ap
, bp
;
594 for (ap
= a
->elms
, bp
= b
->elms
, i
= 0; i
< n
; i
++, ap
++, bp
++)
595 if ((*ap
| *bp
) != *bp
)
601 /* Set DST to be (A or (B and C)).
602 Return nonzero if any change is made. */
605 bitmap_or_and (sbitmap dst
, const_sbitmap a
, const_sbitmap b
, const_sbitmap c
)
607 unsigned int i
, n
= dst
->size
;
608 sbitmap_ptr dstp
= dst
->elms
;
609 const_sbitmap_ptr ap
= a
->elms
;
610 const_sbitmap_ptr bp
= b
->elms
;
611 const_sbitmap_ptr cp
= c
->elms
;
612 SBITMAP_ELT_TYPE changed
= 0;
614 gcc_assert (!dst
->popcount
);
616 for (i
= 0; i
< n
; i
++)
618 const SBITMAP_ELT_TYPE tmp
= *ap
++ | (*bp
++ & *cp
++);
619 changed
|= *dstp
^ tmp
;
626 /* Set DST to be (A and (B or C)).
627 Return nonzero if any change is made. */
630 bitmap_and_or (sbitmap dst
, const_sbitmap a
, const_sbitmap b
, const_sbitmap c
)
632 unsigned int i
, n
= dst
->size
;
633 sbitmap_ptr dstp
= dst
->elms
;
634 const_sbitmap_ptr ap
= a
->elms
;
635 const_sbitmap_ptr bp
= b
->elms
;
636 const_sbitmap_ptr cp
= c
->elms
;
637 SBITMAP_ELT_TYPE changed
= 0;
639 gcc_assert (!dst
->popcount
);
641 for (i
= 0; i
< n
; i
++)
643 const SBITMAP_ELT_TYPE tmp
= *ap
++ & (*bp
++ | *cp
++);
644 changed
|= *dstp
^ tmp
;
651 /* Return number of first bit set in the bitmap, -1 if none. */
654 bitmap_first_set_bit (const_sbitmap bmap
)
657 sbitmap_iterator sbi
;
659 EXECUTE_IF_SET_IN_SBITMAP (bmap
, 0, n
, sbi
)
664 /* Return number of last bit set in the bitmap, -1 if none. */
667 bitmap_last_set_bit (const_sbitmap bmap
)
670 const SBITMAP_ELT_TYPE
*const ptr
= bmap
->elms
;
672 for (i
= bmap
->size
- 1; i
>= 0; i
--)
674 const SBITMAP_ELT_TYPE word
= ptr
[i
];
678 unsigned int index
= (i
+ 1) * SBITMAP_ELT_BITS
- 1;
679 SBITMAP_ELT_TYPE mask
680 = (SBITMAP_ELT_TYPE
) 1 << (SBITMAP_ELT_BITS
- 1);
684 if ((word
& mask
) != 0)
697 dump_bitmap (FILE *file
, const_sbitmap bmap
)
699 unsigned int i
, n
, j
;
700 unsigned int set_size
= bmap
->size
;
701 unsigned int total_bits
= bmap
->n_bits
;
704 for (i
= n
= 0; i
< set_size
&& n
< total_bits
; i
++)
705 for (j
= 0; j
< SBITMAP_ELT_BITS
&& n
< total_bits
; j
++, n
++)
707 if (n
!= 0 && n
% 10 == 0)
711 (bmap
->elms
[i
] & ((SBITMAP_ELT_TYPE
) 1 << j
)) != 0);
714 fprintf (file
, "\n");
718 dump_bitmap_file (FILE *file
, const_sbitmap bmap
)
722 fprintf (file
, "n_bits = %d, set = {", bmap
->n_bits
);
724 for (pos
= 30, i
= 0; i
< bmap
->n_bits
; i
++)
725 if (TEST_BIT (bmap
, i
))
729 fprintf (file
, "\n ");
733 fprintf (file
, "%d ", i
);
734 pos
+= 2 + (i
>= 10) + (i
>= 100) + (i
>= 1000);
737 fprintf (file
, "}\n");
741 debug_bitmap (const_sbitmap bmap
)
743 dump_bitmap_file (stderr
, bmap
);
747 dump_bitmap_vector (FILE *file
, const char *title
, const char *subtitle
,
748 sbitmap
*bmaps
, int n_maps
)
752 fprintf (file
, "%s\n", title
);
753 for (i
= 0; i
< n_maps
; i
++)
755 fprintf (file
, "%s %d\n", subtitle
, i
);
756 dump_bitmap (file
, bmaps
[i
]);
759 fprintf (file
, "\n");
762 #if GCC_VERSION < 3400
763 /* Table of number of set bits in a character, indexed by value of char. */
764 static const unsigned char popcount_table
[] =
766 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,
767 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,
768 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,
769 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,
770 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,
771 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,
772 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,
773 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,
776 /* Count the bits in an SBITMAP element A. */
779 sbitmap_elt_popcount (SBITMAP_ELT_TYPE a
)
781 unsigned long ret
= 0;
787 /* Just do this the table way for now */
788 for (i
= 0; i
< SBITMAP_ELT_BITS
; i
+= 8)
789 ret
+= popcount_table
[(a
>> i
) & 0xff];
794 /* Count the number of bits in SBITMAP a, up to bit MAXBIT. */
797 sbitmap_popcount (const_sbitmap a
, unsigned long maxbit
)
799 unsigned long count
= 0;
801 unsigned int lastword
;
806 if (maxbit
>= a
->n_bits
)
809 /* Count the bits in the full word. */
810 lastword
= MIN (a
->size
, SBITMAP_SET_SIZE (maxbit
+ 1) - 1);
811 for (ix
= 0; ix
< lastword
; ix
++)
815 count
+= a
->popcount
[ix
];
816 #ifdef BITMAP_DEBUGGING
817 gcc_assert (a
->popcount
[ix
] == do_popcount (a
->elms
[ix
]));
821 count
+= do_popcount (a
->elms
[ix
]);
824 /* Count the remaining bits. */
825 if (lastword
< a
->size
)
827 unsigned int bitindex
;
828 SBITMAP_ELT_TYPE theword
= a
->elms
[lastword
];
830 bitindex
= maxbit
% SBITMAP_ELT_BITS
;
833 theword
&= (SBITMAP_ELT_TYPE
)-1 >> (SBITMAP_ELT_BITS
- bitindex
);
834 count
+= do_popcount (theword
);