1 /* Functions to support efficient bitsets.
2 Copyright (C) 2002 Free Software Foundation, Inc.
3 Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz).
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
28 # define DMALLOC_FUNC_CHECK
30 # endif /* WITH_DMALLOC */
32 /* This file implements linked-list bitsets. These bitsets can be of
33 arbitrary length and are more efficient than arrays of bits for
36 Usually if all the bits in an element are zero we remove the element
37 from the list. However, a side effect of the bit caching is that we
38 do not always notice when an element becomes zero. Hence the
39 ebitset_weed function which removes zero elements.
41 Empty elements are represented by a NULL pointer in the table of
42 element pointers. An alternative is to point to a special zero
43 element. Similarly, we could represent an all 1's element with
44 another special ones element pointer.
46 Bitsets are commonly empty so we need to ensure that this special
47 case is fast. A zero bitset is indicated when cdata is 0. This is
48 conservative since cdata may be non zero and the bitset may still
51 The bitset cache can be disabled either by setting cindex to
52 some large number or by setting csize to 0. Here
53 we use the former approach since cindex needs to be updated whenever
57 /* Number of elements to initially allocate. */
58 #ifndef EBITSET_INITIAL_SIZE
59 #define EBITSET_INITIAL_SIZE 2
62 /* Minimum number of elements to grow table. */
63 #ifndef EBITSET_GROW_SIZE
64 #define EBITSET_GROW_SIZE 4
68 enum ebitset_find_mode
{EBITSET_FIND
, EBITSET_CREATE
, EBITSET_SUBST
};
70 static ebitset_elt ebitset_zero_elts
[1]; /* Elements of all zero bits. */
72 /* Obstack to allocate bitset elements from. */
73 static struct obstack ebitset_obstack
;
74 static int ebitset_obstack_init
= 0;
75 static ebitset_elt
*ebitset_free_list
; /* Free list of bitset elements. */
77 static void ebitset_elts_grow
PARAMS ((bitset
, unsigned int));
78 static ebitset_elt
*ebitset_elt_alloc
PARAMS ((void));
79 static ebitset_elt
*ebitset_elt_calloc
PARAMS ((void));
80 static void ebitset_elt_add
PARAMS ((bitset
, ebitset_elt
*, unsigned int));
81 static void ebitset_elt_remove
PARAMS ((bitset
, unsigned int));
82 static void ebitset_elt_free
PARAMS ((ebitset_elt
*));
83 static ebitset_elt
*ebitset_elt_find
PARAMS ((bitset
, bitset_windex
,
84 enum ebitset_find_mode
));
85 static ebitset_elt
*ebitset_elt_last
PARAMS ((bitset
));
86 static int ebitset_elt_zero_p
PARAMS ((ebitset_elt
*));
88 static int ebitset_weed
PARAMS ((bitset
));
89 static void ebitset_zero
PARAMS((bitset
));
90 static int ebitset_equal_p
PARAMS((bitset
, bitset
));
91 static void ebitset_copy
PARAMS((bitset
, bitset
));
92 static int ebitset_copy_compare
PARAMS((bitset
, bitset
));
93 static void ebitset_set
PARAMS((bitset
, bitset_bindex
));
94 static void ebitset_reset
PARAMS((bitset
, bitset_bindex
));
95 static int ebitset_test
PARAMS((bitset
, bitset_bindex
));
96 static int ebitset_size
PARAMS((bitset
));
97 static int ebitset_op1
PARAMS((bitset
, enum bitset_ops
));
98 static int ebitset_op2
PARAMS((bitset
, bitset
, enum bitset_ops
));
99 static int ebitset_op3
PARAMS((bitset
, bitset
, bitset
, enum bitset_ops
));
100 static int ebitset_op4
PARAMS((bitset
, bitset
, bitset
, bitset
,
102 static int ebitset_list
PARAMS((bitset
, bitset_bindex
*, bitset_bindex
,
104 static int ebitset_reverse_list
PARAMS((bitset
, bitset_bindex
*, bitset_bindex
,
106 static void ebitset_free
PARAMS((bitset
));
109 #define EBITSET_ELTS(BSET) ((BSET)->u.e.elts)
110 #define EBITSET_SIZE(BSET) ((BSET)->u.e.size)
112 #define EBITSET_NEXT(ELT) ((ELT)->u.next)
113 #define EBITSET_WORDS(ELT) ((ELT)->u.words)
115 /* Disable bitset cache and mark BSET as being zero. */
116 #define EBITSET_ZERO_SET(BSET) ((BSET)->cindex = BITSET_INDEX_MAX, \
119 #define EBITSET_CACHE_DISABLE(BSET) ((BSET)->cindex = BITSET_INDEX_MAX)
121 /* Disable bitset cache and mark BSET as being possibly non-zero. */
122 #define EBITSET_NONZERO_SET(BSET) \
123 (EBITSET_CACHE_DISABLE (BSET), (BSET)->cdata = (bitset_word *)~0)
125 /* A conservative estimate of whether the bitset is zero.
126 This is non-zero only if we know for sure that the bitset is zero. */
127 #define EBITSET_ZERO_P(BSET) ((BSET)->cdata == 0)
129 /* Enable cache to point to element with table index EINDEX.
130 The element must exist. */
131 #define EBITSET_CACHE_SET(BSET, EINDEX) \
132 ((BSET)->cindex = (EINDEX) * EBITSET_ELT_WORDS, \
133 (BSET)->cdata = EBITSET_WORDS (EBITSET_ELTS (BSET) [EINDEX]))
136 /* Grow the expandable table for BSET by SIZE elements. */
138 ebitset_elts_grow (bset
, size
)
142 unsigned int oldsize
;
143 unsigned int newsize
;
145 oldsize
= EBITSET_SIZE (bset
);
146 newsize
= oldsize
+ size
;
148 EBITSET_ELTS (bset
) = xrealloc (EBITSET_ELTS (bset
),
149 newsize
* sizeof (ebitset_elt
*));
150 EBITSET_SIZE (bset
) = newsize
;
152 memset (EBITSET_ELTS (bset
) + oldsize
, 0, size
* sizeof (ebitset_elt
*));
156 /* Allocate a ebitset element. The bits are not cleared. */
157 static inline ebitset_elt
*
162 if (ebitset_free_list
!= 0)
164 elt
= ebitset_free_list
;
165 ebitset_free_list
= EBITSET_NEXT (elt
);
169 /* We can't use gcc_obstack_init to initialize the obstack since
170 print-rtl.c now calls bitset functions, and bitset is linked
171 into the gen* functions. */
172 if (!ebitset_obstack_init
)
174 ebitset_obstack_init
= 1;
176 /* Let particular systems override the size of a chunk. */
177 #ifndef OBSTACK_CHUNK_SIZE
178 #define OBSTACK_CHUNK_SIZE 0
180 /* Let them override the alloc and free routines too. */
181 #ifndef OBSTACK_CHUNK_ALLOC
182 #define OBSTACK_CHUNK_ALLOC xmalloc
184 #ifndef OBSTACK_CHUNK_FREE
185 #define OBSTACK_CHUNK_FREE free
188 #if !defined(__GNUC__) || (__GNUC__ < 2)
189 #define __alignof__(type) 0
192 obstack_specify_allocation (&ebitset_obstack
, OBSTACK_CHUNK_SIZE
,
193 __alignof__ (ebitset_elt
),
194 (void *(*) PARAMS ((long))) OBSTACK_CHUNK_ALLOC
,
195 (void (*) PARAMS ((void *))) OBSTACK_CHUNK_FREE
);
198 /* Perhaps we should add a number of new elements to the free
200 elt
= (ebitset_elt
*) obstack_alloc (&ebitset_obstack
,
201 sizeof (ebitset_elt
));
208 /* Allocate a ebitset element. The bits are not cleared. */
209 static inline ebitset_elt
*
210 ebitset_elt_calloc ()
214 elt
= ebitset_elt_alloc ();
215 memset (EBITSET_WORDS (elt
), 0, sizeof (EBITSET_WORDS (elt
)));
221 ebitset_elt_free (elt
)
224 EBITSET_NEXT (elt
) = ebitset_free_list
;
225 ebitset_free_list
= elt
;
229 /* Remove element with index EINDEX from bitset BSET. */
231 ebitset_elt_remove (bset
, eindex
)
238 elts
= EBITSET_ELTS (bset
);
243 ebitset_elt_free (elt
);
247 /* Add ELT into elts at index EINDEX of bitset BSET. */
249 ebitset_elt_add (bset
, elt
, eindex
)
256 elts
= EBITSET_ELTS (bset
);
257 /* Assume that the elts entry not allocated. */
262 /* Return nonzero if all bits in an element are zero. */
264 ebitset_elt_zero_p (elt
)
269 for (i
= 0; i
< EBITSET_ELT_WORDS
; i
++)
270 if (EBITSET_WORDS (elt
)[i
])
278 ebitset_elt_find (bset
, index
, mode
)
281 enum ebitset_find_mode mode
;
288 eindex
= index
/ EBITSET_ELT_WORDS
;
290 elts
= EBITSET_ELTS (bset
);
291 size
= EBITSET_SIZE (bset
);
297 if ((elt
= elts
[eindex
]))
299 if (EBITSET_WORDS (elt
) == bset
->cdata
)
302 EBITSET_CACHE_SET (bset
, eindex
);
307 /* The element could not be found. */
319 extra
= eindex
- size
+ 1;
321 /* We need to expand the table by EXTRA elements. It may be
322 better with large bitsets to grow the number of
323 elements by some fraction of the current size otherwise
324 we can spend a lot of time slowly increasing the size of the
326 if (extra
< EBITSET_GROW_SIZE
)
327 extra
= EBITSET_GROW_SIZE
;
329 ebitset_elts_grow (bset
, extra
);
332 /* Create a new element. */
333 elt
= ebitset_elt_calloc ();
334 ebitset_elt_add (bset
, elt
, eindex
);
335 EBITSET_CACHE_SET (bset
, eindex
);
339 return &ebitset_zero_elts
[0];
347 static inline ebitset_elt
*
348 ebitset_elt_last (bset
)
353 elts
= EBITSET_ELTS (bset
);
355 /* Assume that have at least one element in elts. */
356 return elts
[EBITSET_SIZE (bset
) - 1];
360 /* Weed out the zero elements from the elts. */
369 if (EBITSET_ZERO_P (bset
))
372 elts
= EBITSET_ELTS (bset
);
374 for (j
= 0; j
< EBITSET_SIZE (bset
); j
++)
376 ebitset_elt
*elt
= elts
[j
];
380 if (elt
&& ebitset_elt_zero_p (elt
))
382 ebitset_elt_remove (bset
, j
);
393 /* All the bits are zero. We could shrink the elts.
394 For now just mark BSET as known to be zero. */
395 EBITSET_ZERO_SET (bset
);
398 EBITSET_NONZERO_SET (bset
);
404 /* Set all bits in the bitset to zero. */
412 if (EBITSET_ZERO_P (bset
))
415 elts
= EBITSET_ELTS (bset
);
416 for (j
= 0; j
< EBITSET_SIZE (bset
); j
++)
418 ebitset_elt
*elt
= elts
[j
];
421 ebitset_elt_remove (bset
, j
);
424 /* All the bits are zero. We could shrink the elts.
425 For now just mark BSET as known to be zero. */
426 EBITSET_ZERO_SET (bset
);
431 ebitset_equal_p (dst
, src
)
445 if (EBITSET_SIZE (src
) != EBITSET_SIZE (dst
))
448 selts
= EBITSET_ELTS (src
);
449 delts
= EBITSET_ELTS (dst
);
451 for (j
= 0; j
< EBITSET_SIZE (src
); j
++)
454 ebitset_elt
*selt
= selts
[j
];
455 ebitset_elt
*delt
= delts
[j
];
457 if (! selt
&& ! delt
)
459 if ((selt
&& ! delt
) || (!selt
&& delt
))
462 for (i
= 0; i
< EBITSET_ELT_WORDS
; i
++)
463 if (EBITSET_WORDS (selt
)[i
] != EBITSET_WORDS (delt
)[i
])
470 /* Copy bits from bitset SRC to bitset DST. */
472 ebitset_copy (dst
, src
)
485 if (EBITSET_SIZE (dst
) < EBITSET_SIZE (src
))
486 ebitset_elts_grow (dst
, EBITSET_SIZE (src
) - EBITSET_SIZE (dst
));
488 selts
= EBITSET_ELTS (src
);
489 delts
= EBITSET_ELTS (dst
);
490 for (j
= 0; j
< EBITSET_SIZE (src
); j
++)
492 ebitset_elt
*selt
= selts
[j
];
498 tmp
= ebitset_elt_alloc ();
500 memcpy (EBITSET_WORDS (tmp
), EBITSET_WORDS (selt
),
501 sizeof (EBITSET_WORDS (selt
)));
504 EBITSET_NONZERO_SET (dst
);
508 /* Copy bits from bitset SRC to bitset DST. Return non-zero if
509 bitsets different. */
511 ebitset_copy_compare (dst
, src
)
518 if (EBITSET_ZERO_P (dst
))
520 ebitset_copy (dst
, src
);
521 return ! EBITSET_ZERO_P (src
);
524 if (ebitset_equal_p (dst
, src
))
527 ebitset_copy (dst
, src
);
532 /* Return size in bits of bitset SRC. */
537 /* Return current size of bitset in bits. */
538 return EBITSET_SIZE (src
) * EBITSET_ELT_BITS
;
542 /* Set bit BITNO in bitset DST. */
544 ebitset_set (dst
, bitno
)
548 bitset_windex index
= bitno
/ BITSET_WORD_BITS
;
550 ebitset_elt_find (dst
, index
, EBITSET_CREATE
);
552 dst
->cdata
[index
- dst
->cindex
] |= (1 << (bitno
% BITSET_WORD_BITS
));
556 /* Reset bit BITNO in bitset DST. */
558 ebitset_reset (dst
, bitno
)
562 bitset_windex index
= bitno
/ BITSET_WORD_BITS
;
564 if (!ebitset_elt_find (dst
, index
, EBITSET_FIND
))
567 dst
->cdata
[index
- dst
->cindex
] &= ~(1 << (bitno
% BITSET_WORD_BITS
));
569 /* If all the data is zero, perhaps we should remove it now...
570 However, there could be a good chance that the element will be needed
575 /* Test bit BITNO in bitset SRC. */
577 ebitset_test (src
, bitno
)
581 bitset_windex index
= bitno
/ BITSET_WORD_BITS
;
583 if (!ebitset_elt_find (src
, index
, EBITSET_FIND
))
586 return (src
->cdata
[index
- src
->cindex
] >> (bitno
% BITSET_WORD_BITS
)) & 1;
595 free (EBITSET_ELTS (bset
));
599 /* Find list of up to NUM bits set in BSET starting from and including
600 *NEXT and store in array LIST. Return with actual number of bits
601 found and with *NEXT indicating where search stopped. */
603 ebitset_reverse_list (bset
, list
, num
, next
)
609 bitset_bindex n_bits
;
611 bitset_bindex rbitno
;
613 bitset_bindex bitoff
;
616 bitset_windex windex
;
622 if (EBITSET_ZERO_P (bset
))
625 size
= EBITSET_SIZE (bset
);
626 n_bits
= size
* EBITSET_ELT_BITS
;
629 if (rbitno
>= n_bits
)
632 elts
= EBITSET_ELTS (bset
);
634 bitno
= n_bits
- (rbitno
+ 1);
636 index
= bitno
/ BITSET_WORD_BITS
;
637 eindex
= bitno
/ EBITSET_ELT_BITS
;
638 windex
= index
- eindex
* EBITSET_ELT_WORDS
;
640 /* If num is 1, we could speed things up with a binary search
641 of the word of interest. */
644 bitcnt
= bitno
% BITSET_WORD_BITS
;
645 bitoff
= index
* BITSET_WORD_BITS
;
647 for (; eindex
!= ~0U; eindex
--)
656 srcp
= EBITSET_WORDS (elt
);
658 for (; windex
!= ~0U; windex
--, bitoff
-= BITSET_WORD_BITS
,
659 bitcnt
= BITSET_WORD_BITS
- 1)
661 word
= srcp
[windex
] << (BITSET_WORD_BITS
- 1 - bitcnt
);
663 for (; word
; bitcnt
--)
665 if (word
& BITSET_MSB
)
667 list
[count
++] = bitoff
+ bitcnt
;
670 *next
= n_bits
- (bitoff
+ bitcnt
);
678 windex
= EBITSET_ELT_WORDS
;
681 *next
= n_bits
- (bitoff
+ 1);
686 /* Find list of up to NUM bits set in BSET starting from and including
687 *NEXT and store in array LIST. Return with actual number of bits
688 found and with *NEXT indicating where search stopped. */
690 ebitset_list (bset
, list
, num
, next
)
705 if (EBITSET_ZERO_P (bset
))
711 elts
= EBITSET_ELTS (bset
);
712 size
= EBITSET_SIZE (bset
);
713 eindex
= bitno
/ EBITSET_ELT_BITS
;
715 if (bitno
% EBITSET_ELT_BITS
)
717 /* We need to start within an element. This is not very common. */
722 bitset_windex windex
;
723 bitset_word
*srcp
= EBITSET_WORDS (elt
);
725 index
= bitno
/ BITSET_WORD_BITS
;
726 windex
= eindex
/ EBITSET_ELT_WORDS
;
728 for (; (index
- windex
) < EBITSET_ELT_WORDS
; index
++)
730 word
= srcp
[index
- windex
] >> (bitno
% BITSET_WORD_BITS
);
732 for (; word
; bitno
++)
736 list
[count
++] = bitno
;
745 bitno
= (index
+ 1) * BITSET_WORD_BITS
;
749 /* Skip to next element. */
753 /* If num is 1, we could speed things up with a binary search
754 of the word of interest. */
756 for (; eindex
< size
; eindex
++)
766 srcp
= EBITSET_WORDS (elt
);
767 index
= eindex
* EBITSET_ELT_WORDS
;
769 if ((count
+ EBITSET_ELT_BITS
) < num
)
771 /* The coast is clear, plant boot! */
773 for (i
= 0; i
< EBITSET_ELT_WORDS
; i
++, index
++)
775 bitno
= index
* BITSET_WORD_BITS
;
780 if (! (word
& 0xffff))
790 for (; word
; bitno
++)
793 list
[count
++] = bitno
;
801 /* Tread more carefully since we need to check
802 if array overflows. */
804 for (i
= 0; i
< EBITSET_ELT_WORDS
; i
++, index
++)
806 bitno
= index
* BITSET_WORD_BITS
;
808 for (word
= srcp
[i
]; word
; bitno
++)
812 list
[count
++] = bitno
;
831 ebitset_op1 (dst
, op
)
845 for (j
= 0; j
< EBITSET_SIZE (dst
); j
++)
847 /* Create new elements if they cannot be found. Perhaps
848 we should just add pointers to a ones element. */
849 elt
= ebitset_elt_find (dst
, j
* EBITSET_ELT_WORDS
, EBITSET_CREATE
);
850 memset (EBITSET_WORDS (elt
), ~0, sizeof (EBITSET_WORDS (elt
)));
855 return ! ebitset_weed (dst
);
861 EBITSET_NONZERO_SET (dst
);
867 ebitset_op2 (dst
, src
, op
)
880 ebitset_copy (dst
, src
);
884 for (j
= 0; j
< EBITSET_SIZE (src
); j
++)
886 /* Create new elements for dst if they cannot be found
887 or substitute zero elements if src elements not found. */
888 selt
= ebitset_elt_find (dst
, j
* EBITSET_ELT_WORDS
, EBITSET_SUBST
);
889 delt
= ebitset_elt_find (dst
, j
* EBITSET_ELT_WORDS
, EBITSET_CREATE
);
891 for (i
= 0; i
< EBITSET_ELT_WORDS
; i
++)
892 EBITSET_WORDS (delt
)[i
] = ~EBITSET_WORDS (selt
)[i
];
897 return ebitset_equal_p (dst
, src
);
899 /* Return 1 if DST == DST | SRC. */
900 case BITSET_SUBSET_P
:
907 selts
= EBITSET_ELTS (src
);
908 delts
= EBITSET_ELTS (dst
);
910 ssize
= EBITSET_SIZE (src
);
911 dsize
= EBITSET_SIZE (dst
);
913 for (j
= 0; j
< ssize
; j
++)
918 selt
= j
< ssize
? selts
[j
] : 0;
919 delt
= j
< dsize
? delts
[j
] : 0;
921 if (! selt
&& ! delt
)
925 selt
= &ebitset_zero_elts
[0];
927 delt
= &ebitset_zero_elts
[0];
929 for (i
= 0; i
< EBITSET_ELT_WORDS
; i
++)
930 if (EBITSET_WORDS (delt
)[i
]
931 != (EBITSET_WORDS (selt
)[i
] | EBITSET_WORDS (delt
)[i
]))
942 EBITSET_NONZERO_SET (dst
);
948 ebitset_op3 (dst
, src1
, src2
, op
)
954 bitset_windex ssize1
;
955 bitset_windex ssize2
;
958 ebitset_elts
*selts1
;
959 ebitset_elts
*selts2
;
968 /* Fast track common, simple cases. */
969 if (EBITSET_ZERO_P (src2
))
971 if (op
== BITSET_AND
)
974 changed
= EBITSET_ZERO_P (dst
);
978 else if (op
== BITSET_ANDN
|| op
== BITSET_OR
|| op
== BITSET_XOR
)
980 return ebitset_copy_compare (dst
, src1
);
983 else if (EBITSET_ZERO_P (src1
))
985 if (op
== BITSET_AND
|| op
== BITSET_ANDN
)
988 changed
= EBITSET_ZERO_P (dst
);
992 else if (op
== BITSET_OR
|| op
== BITSET_XOR
)
994 return ebitset_copy_compare (dst
, src2
);
998 ssize1
= EBITSET_SIZE (src1
);
999 ssize2
= EBITSET_SIZE (src2
);
1000 dsize
= EBITSET_SIZE (dst
);
1006 ebitset_elts_grow (dst
, size
- dsize
);
1008 selts1
= EBITSET_ELTS (src1
);
1009 selts2
= EBITSET_ELTS (src2
);
1010 delts
= EBITSET_ELTS (dst
);
1012 for (j
= 0; j
< size
; j
++)
1018 selt1
= j
< ssize1
? selts1
[j
] : 0;
1019 selt2
= j
< ssize2
? selts2
[j
] : 0;
1020 delt
= j
< dsize
? delts
[j
] : 0;
1022 if (! selt1
&& ! selt2
)
1027 ebitset_elt_remove (dst
, j
);
1033 selt1
= &ebitset_zero_elts
[0];
1035 selt2
= &ebitset_zero_elts
[0];
1037 delt
= ebitset_elt_calloc ();
1041 srcp1
= EBITSET_WORDS (selt1
);
1042 srcp2
= EBITSET_WORDS (selt2
);
1043 dstp
= EBITSET_WORDS (delt
);
1047 for (i
= 0; i
< EBITSET_ELT_WORDS
; i
++, dstp
++)
1049 bitset_word tmp
= *srcp1
++ | *srcp2
++;
1060 for (i
= 0; i
< EBITSET_ELT_WORDS
; i
++, dstp
++)
1062 bitset_word tmp
= *srcp1
++ & *srcp2
++;
1073 for (i
= 0; i
< EBITSET_ELT_WORDS
; i
++, dstp
++)
1075 bitset_word tmp
= *srcp1
++ ^ *srcp2
++;
1086 for (i
= 0; i
< EBITSET_ELT_WORDS
; i
++, dstp
++)
1088 bitset_word tmp
= *srcp1
++ & ~(*srcp2
++);
1099 for (i
= 0; i
< EBITSET_ELT_WORDS
; i
++, dstp
++)
1101 bitset_word tmp
= *srcp1
++ | ~(*srcp2
++);
1115 if (! ebitset_elt_zero_p (delt
))
1117 ebitset_elt_add (dst
, delt
, j
);
1121 ebitset_elt_free (delt
);
1125 /* If we have elements of DST left over, free them all. */
1126 for (; j
< dsize
; j
++)
1135 ebitset_elt_remove (dst
, j
);
1138 EBITSET_NONZERO_SET (dst
);
1144 ebitset_op4 (dst
, src1
, src2
, src3
, op
)
1154 tmp
= bitset_create (BITSET_LIST
, 0);
1159 bitset_or (tmp
, src1
, src2
);
1160 changed
= bitset_and (dst
, src3
, tmp
);
1164 bitset_and (tmp
, src1
, src2
);
1165 changed
= bitset_or (dst
, src3
, tmp
);
1168 case BITSET_ANDN_OR
:
1169 bitset_andn (tmp
, src1
, src2
);
1170 changed
= bitset_or (dst
, src3
, tmp
);
1178 EBITSET_NONZERO_SET (dst
);
1183 /* Vector of operations for linked-list bitsets. */
1184 struct bitset_ops_struct ebitset_ops
=
1195 ebitset_reverse_list
,
1201 /* Return size of initial structure. */
1203 ebitset_bytes (n_bits
)
1204 bitset_bindex n_bits ATTRIBUTE_UNUSED
;
1206 return sizeof (struct bitset_struct
);
1210 /* Initialize a bitset. */
1213 ebitset_init (bset
, n_bits
)
1215 bitset_bindex n_bits
;
1219 bset
->ops
= &ebitset_ops
;
1221 bset
->csize
= EBITSET_ELT_WORDS
;
1223 EBITSET_ZERO_SET (bset
);
1225 size
= n_bits
? (n_bits
+ EBITSET_ELT_BITS
- 1) / EBITSET_ELT_BITS
1226 : EBITSET_INITIAL_SIZE
;
1228 EBITSET_SIZE (bset
) = 0;
1229 EBITSET_ELTS (bset
) = 0;
1230 ebitset_elts_grow (bset
, size
);
1237 ebitset_release_memory ()
1239 ebitset_free_list
= 0;
1240 if (ebitset_obstack_init
)
1242 ebitset_obstack_init
= 0;
1243 obstack_free (&ebitset_obstack
, NULL
);