1 /* Functions to support expandable 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 /* This file implements expandable bitsets. These bitsets can be of
29 arbitrary length and are more efficient than arrays of bits for
32 Empty elements are represented by a NULL pointer in the table of
33 element pointers. An alternative is to point to a special zero
34 element. Similarly, we could represent an all 1's element with
35 another special ones element pointer.
37 Bitsets are commonly empty so we need to ensure that this special
38 case is fast. A zero bitset is indicated when cdata is 0. This is
39 conservative since cdata may be non zero and the bitset may still
42 The bitset cache can be disabled either by setting cindex to
43 some large number or by setting csize to 0. Here
44 we use the former approach since cindex needs to be updated whenever
49 /* Number of words to use for each element. */
51 #ifndef EBITSET_ELT_WORDS
52 #define EBITSET_ELT_WORDS 2
55 /* Number of bits stored in each element. */
56 #define EBITSET_ELT_BITS \
57 ((unsigned) (EBITSET_ELT_WORDS * BITSET_WORD_BITS))
59 /* Ebitset element. We use an array of bits. */
60 typedef struct ebitset_elt_struct
64 bitset_word words
[EBITSET_ELT_WORDS
]; /* Bits that are set. */
65 struct ebitset_elt_struct
*next
;
72 typedef ebitset_elt
*ebitset_elts
;
74 /* Head of ebitset linked list. */
75 typedef struct ebitset_struct
77 unsigned int size
; /* Number of elements. */
78 ebitset_elts
*elts
; /* Expanding array of pointers to elements. */
83 /* Number of elements to initially allocate. */
85 #ifndef EBITSET_INITIAL_SIZE
86 #define EBITSET_INITIAL_SIZE 2
89 /* Minimum number of elements to grow table. */
91 #ifndef EBITSET_GROW_SIZE
92 #define EBITSET_GROW_SIZE 4
97 struct bbitset_struct b
;
98 struct ebitset_struct e
;
101 enum ebitset_find_mode
102 { EBITSET_FIND
, EBITSET_CREATE
, EBITSET_SUBST
};
104 static ebitset_elt ebitset_zero_elts
[1]; /* Elements of all zero bits. */
106 /* Obstack to allocate bitset elements from. */
107 static struct obstack ebitset_obstack
;
108 static int ebitset_obstack_init
= 0;
109 static ebitset_elt
*ebitset_free_list
; /* Free list of bitset elements. */
111 static void ebitset_elts_grow
PARAMS ((bitset
, unsigned int));
112 static ebitset_elt
*ebitset_elt_alloc
PARAMS ((void));
113 static ebitset_elt
*ebitset_elt_calloc
PARAMS ((void));
114 static void ebitset_elt_add
PARAMS ((bitset
, ebitset_elt
*, unsigned int));
115 static void ebitset_elt_remove
PARAMS ((bitset
, unsigned int));
116 static void ebitset_elt_free
PARAMS ((ebitset_elt
*));
117 static ebitset_elt
*ebitset_elt_find
PARAMS ((bitset
, bitset_windex
,
118 enum ebitset_find_mode
));
119 static ebitset_elt
*ebitset_elt_last
PARAMS ((bitset
));
120 static int ebitset_elt_zero_p
PARAMS ((ebitset_elt
*));
122 static int ebitset_weed
PARAMS ((bitset
));
123 static void ebitset_zero
PARAMS ((bitset
));
124 static int ebitset_equal_p
PARAMS ((bitset
, bitset
));
125 static void ebitset_copy
PARAMS ((bitset
, bitset
));
126 static int ebitset_copy_compare
PARAMS ((bitset
, bitset
));
127 static void ebitset_set
PARAMS ((bitset
, bitset_bindex
));
128 static void ebitset_reset
PARAMS ((bitset
, bitset_bindex
));
129 static int ebitset_test
PARAMS ((bitset
, bitset_bindex
));
130 static int ebitset_size
PARAMS ((bitset
));
131 static int ebitset_op1
PARAMS ((bitset
, enum bitset_ops
));
132 static int ebitset_op2
PARAMS ((bitset
, bitset
, enum bitset_ops
));
133 static int ebitset_op3
PARAMS ((bitset
, bitset
, bitset
, enum bitset_ops
));
134 static int ebitset_list
PARAMS ((bitset
, bitset_bindex
*, bitset_bindex
,
136 static int ebitset_reverse_list
137 PARAMS ((bitset
, bitset_bindex
*, bitset_bindex
, bitset_bindex
*));
138 static void ebitset_free
PARAMS ((bitset
));
140 #define EBITSET_ELTS(BSET) ((BSET)->e.elts)
141 #define EBITSET_SIZE(BSET) ((BSET)->e.size)
143 #define EBITSET_NEXT(ELT) ((ELT)->u.next)
144 #define EBITSET_WORDS(ELT) ((ELT)->u.words)
146 /* Disable bitset cache and mark BSET as being zero. */
147 #define EBITSET_OP_ZERO_SET(BSET) ((BSET)->b.cindex = BITSET_INDEX_MAX, \
150 #define EBITSET_CACHE_DISABLE(BSET) ((BSET)->b.cindex = BITSET_INDEX_MAX)
152 /* Disable bitset cache and mark BSET as being possibly non-zero. */
153 #define EBITSET_NONZERO_SET(BSET) \
154 (EBITSET_CACHE_DISABLE (BSET), (BSET)->b.cdata = (bitset_word *)~0)
156 /* A conservative estimate of whether the bitset is zero.
157 This is non-zero only if we know for sure that the bitset is zero. */
158 #define EBITSET_OP_ZERO_P(BSET) ((BSET)->b.cdata == 0)
160 /* Enable cache to point to element with table index EINDEX.
161 The element must exist. */
162 #define EBITSET_CACHE_SET(BSET, EINDEX) \
163 ((BSET)->b.cindex = (EINDEX) * EBITSET_ELT_WORDS, \
164 (BSET)->b.cdata = EBITSET_WORDS (EBITSET_ELTS (BSET) [EINDEX]))
167 /* Grow the expandable table for BSET by SIZE elements. */
169 ebitset_elts_grow (bset
, size
)
173 unsigned int oldsize
;
174 unsigned int newsize
;
176 oldsize
= EBITSET_SIZE (bset
);
177 newsize
= oldsize
+ size
;
179 EBITSET_ELTS (bset
) = xrealloc (EBITSET_ELTS (bset
),
180 newsize
* sizeof (ebitset_elt
*));
181 EBITSET_SIZE (bset
) = newsize
;
183 memset (EBITSET_ELTS (bset
) + oldsize
, 0, size
* sizeof (ebitset_elt
*));
187 /* Allocate a ebitset element. The bits are not cleared. */
188 static inline ebitset_elt
*
193 if (ebitset_free_list
!= 0)
195 elt
= ebitset_free_list
;
196 ebitset_free_list
= EBITSET_NEXT (elt
);
200 /* We can't use gcc_obstack_init to initialize the obstack since
201 print-rtl.c now calls bitset functions, and bitset is linked
202 into the gen* functions. */
203 if (!ebitset_obstack_init
)
205 ebitset_obstack_init
= 1;
207 /* Let particular systems override the size of a chunk. */
209 #ifndef OBSTACK_CHUNK_SIZE
210 #define OBSTACK_CHUNK_SIZE 0
213 /* Let them override the alloc and free routines too. */
215 #ifndef OBSTACK_CHUNK_ALLOC
216 #define OBSTACK_CHUNK_ALLOC xmalloc
219 #ifndef OBSTACK_CHUNK_FREE
220 #define OBSTACK_CHUNK_FREE free
223 #if !defined(__GNUC__) || (__GNUC__ < 2)
224 #define __alignof__(type) 0
227 obstack_specify_allocation (&ebitset_obstack
, OBSTACK_CHUNK_SIZE
,
228 __alignof__ (ebitset_elt
),
229 (void *(*)PARAMS ((long)))
231 (void (*)PARAMS ((void *)))
235 /* Perhaps we should add a number of new elements to the free
237 elt
= (ebitset_elt
*) obstack_alloc (&ebitset_obstack
,
238 sizeof (ebitset_elt
));
245 /* Allocate a ebitset element. The bits are not cleared. */
246 static inline ebitset_elt
*
247 ebitset_elt_calloc ()
251 elt
= ebitset_elt_alloc ();
252 memset (EBITSET_WORDS (elt
), 0, sizeof (EBITSET_WORDS (elt
)));
258 ebitset_elt_free (elt
)
261 EBITSET_NEXT (elt
) = ebitset_free_list
;
262 ebitset_free_list
= elt
;
266 /* Remove element with index EINDEX from bitset BSET. */
268 ebitset_elt_remove (bset
, eindex
)
275 elts
= EBITSET_ELTS (bset
);
280 ebitset_elt_free (elt
);
284 /* Add ELT into elts at index EINDEX of bitset BSET. */
286 ebitset_elt_add (bset
, elt
, eindex
)
293 elts
= EBITSET_ELTS (bset
);
294 /* Assume that the elts entry not allocated. */
299 /* Return nonzero if all bits in an element are zero. */
301 ebitset_elt_zero_p (elt
)
306 for (i
= 0; i
< EBITSET_ELT_WORDS
; i
++)
307 if (EBITSET_WORDS (elt
)[i
])
315 ebitset_elt_find (bset
, windex
, mode
)
317 bitset_windex windex
;
318 enum ebitset_find_mode mode
;
325 eindex
= windex
/ EBITSET_ELT_WORDS
;
327 elts
= EBITSET_ELTS (bset
);
328 size
= EBITSET_SIZE (bset
);
332 if ((elt
= elts
[eindex
]))
334 if (EBITSET_WORDS (elt
) == bset
->b
.cdata
)
337 EBITSET_CACHE_SET (bset
, eindex
);
342 /* The element could not be found. */
354 extra
= eindex
- size
+ 1;
356 /* We need to expand the table by EXTRA elements. It may be
357 better with large bitsets to grow the number of
358 elements by some fraction of the current size otherwise
359 we can spend a lot of time slowly increasing the size of the
361 if (extra
< EBITSET_GROW_SIZE
)
362 extra
= EBITSET_GROW_SIZE
;
364 ebitset_elts_grow (bset
, extra
);
367 /* Create a new element. */
368 elt
= ebitset_elt_calloc ();
369 ebitset_elt_add (bset
, elt
, eindex
);
370 EBITSET_CACHE_SET (bset
, eindex
);
374 return &ebitset_zero_elts
[0];
382 static inline ebitset_elt
*
383 ebitset_elt_last (bset
)
388 elts
= EBITSET_ELTS (bset
);
390 /* Assume that have at least one element in elts. */
391 return elts
[EBITSET_SIZE (bset
) - 1];
395 /* Weed out the zero elements from the elts. */
404 if (EBITSET_OP_ZERO_P (bset
))
407 elts
= EBITSET_ELTS (bset
);
409 for (j
= 0; j
< EBITSET_SIZE (bset
); j
++)
411 ebitset_elt
*elt
= elts
[j
];
415 if (elt
&& ebitset_elt_zero_p (elt
))
417 ebitset_elt_remove (bset
, j
);
428 /* All the bits are zero. We could shrink the elts.
429 For now just mark BSET as known to be zero. */
430 EBITSET_OP_ZERO_SET (bset
);
433 EBITSET_NONZERO_SET (bset
);
439 /* Set all bits in the bitset to zero. */
447 if (EBITSET_OP_ZERO_P (bset
))
450 elts
= EBITSET_ELTS (bset
);
451 for (j
= 0; j
< EBITSET_SIZE (bset
); j
++)
453 ebitset_elt
*elt
= elts
[j
];
456 ebitset_elt_remove (bset
, j
);
459 /* All the bits are zero. We could shrink the elts.
460 For now just mark BSET as known to be zero. */
461 EBITSET_OP_ZERO_SET (bset
);
466 ebitset_equal_p (dst
, src
)
480 if (EBITSET_SIZE (src
) != EBITSET_SIZE (dst
))
483 selts
= EBITSET_ELTS (src
);
484 delts
= EBITSET_ELTS (dst
);
486 for (j
= 0; j
< EBITSET_SIZE (src
); j
++)
489 ebitset_elt
*selt
= selts
[j
];
490 ebitset_elt
*delt
= delts
[j
];
494 if ((selt
&& !delt
) || (!selt
&& delt
))
497 for (i
= 0; i
< EBITSET_ELT_WORDS
; i
++)
498 if (EBITSET_WORDS (selt
)[i
] != EBITSET_WORDS (delt
)[i
])
505 /* Copy bits from bitset SRC to bitset DST. */
507 ebitset_copy (dst
, src
)
520 if (EBITSET_SIZE (dst
) < EBITSET_SIZE (src
))
521 ebitset_elts_grow (dst
, EBITSET_SIZE (src
) - EBITSET_SIZE (dst
));
523 selts
= EBITSET_ELTS (src
);
524 delts
= EBITSET_ELTS (dst
);
525 for (j
= 0; j
< EBITSET_SIZE (src
); j
++)
527 ebitset_elt
*selt
= selts
[j
];
533 tmp
= ebitset_elt_alloc ();
535 memcpy (EBITSET_WORDS (tmp
), EBITSET_WORDS (selt
),
536 sizeof (EBITSET_WORDS (selt
)));
539 EBITSET_NONZERO_SET (dst
);
543 /* Copy bits from bitset SRC to bitset DST. Return non-zero if
544 bitsets different. */
546 ebitset_copy_compare (dst
, src
)
553 if (EBITSET_OP_ZERO_P (dst
))
555 ebitset_copy (dst
, src
);
556 return !EBITSET_OP_ZERO_P (src
);
559 if (ebitset_equal_p (dst
, src
))
562 ebitset_copy (dst
, src
);
567 /* Return size in bits of bitset SRC. */
572 /* Return current size of bitset in bits. */
573 return EBITSET_SIZE (src
) * EBITSET_ELT_BITS
;
577 /* Set bit BITNO in bitset DST. */
579 ebitset_set (dst
, bitno
)
583 bitset_windex windex
= bitno
/ BITSET_WORD_BITS
;
585 ebitset_elt_find (dst
, windex
, EBITSET_CREATE
);
587 dst
->b
.cdata
[windex
- dst
->b
.cindex
] |= (1 << (bitno
% BITSET_WORD_BITS
));
591 /* Reset bit BITNO in bitset DST. */
593 ebitset_reset (dst
, bitno
)
597 bitset_windex windex
= bitno
/ BITSET_WORD_BITS
;
599 if (!ebitset_elt_find (dst
, windex
, EBITSET_FIND
))
602 dst
->b
.cdata
[windex
- dst
->b
.cindex
] &= ~(1 << (bitno
% BITSET_WORD_BITS
));
604 /* If all the data is zero, perhaps we should remove it now...
605 However, there is a good chance that the element will be needed
610 /* Test bit BITNO in bitset SRC. */
612 ebitset_test (src
, bitno
)
616 bitset_windex windex
= bitno
/ BITSET_WORD_BITS
;
618 if (!ebitset_elt_find (src
, windex
, EBITSET_FIND
))
622 cdata
[windex
- src
->b
.cindex
] >> (bitno
% BITSET_WORD_BITS
)) & 1;
631 free (EBITSET_ELTS (bset
));
635 /* Find list of up to NUM bits set in BSET starting from and including
636 *NEXT and store in array LIST. Return with actual number of bits
637 found and with *NEXT indicating where search stopped. */
639 ebitset_reverse_list (bset
, list
, num
, next
)
645 bitset_bindex n_bits
;
647 bitset_bindex rbitno
;
649 bitset_bindex boffset
;
650 bitset_windex windex
;
652 bitset_windex woffset
;
658 if (EBITSET_OP_ZERO_P (bset
))
661 size
= EBITSET_SIZE (bset
);
662 n_bits
= size
* EBITSET_ELT_BITS
;
665 if (rbitno
>= n_bits
)
668 elts
= EBITSET_ELTS (bset
);
670 bitno
= n_bits
- (rbitno
+ 1);
672 windex
= bitno
/ BITSET_WORD_BITS
;
673 eindex
= bitno
/ EBITSET_ELT_BITS
;
674 woffset
= windex
- eindex
* EBITSET_ELT_WORDS
;
676 /* If num is 1, we could speed things up with a binary search
677 of the word of interest. */
680 bcount
= bitno
% BITSET_WORD_BITS
;
681 boffset
= windex
* BITSET_WORD_BITS
;
683 for (; eindex
!= ~0U;
684 boffset
= eindex
* EBITSET_ELT_BITS
- BITSET_WORD_BITS
, eindex
--)
693 srcp
= EBITSET_WORDS (elt
);
695 for (; woffset
!= ~0U; woffset
--, boffset
-= BITSET_WORD_BITS
,
696 bcount
= BITSET_WORD_BITS
- 1)
698 word
= srcp
[woffset
] << (BITSET_WORD_BITS
- 1 - bcount
);
700 for (; word
; bcount
--)
702 if (word
& BITSET_MSB
)
704 list
[count
++] = boffset
+ bcount
;
707 *next
= n_bits
- (boffset
+ bcount
);
715 woffset
= EBITSET_ELT_WORDS
;
718 *next
= n_bits
- (boffset
+ 1);
723 /* Find list of up to NUM bits set in BSET starting from and including
724 *NEXT and store in array LIST. Return with actual number of bits
725 found and with *NEXT indicating where search stopped. */
727 ebitset_list (bset
, list
, num
, next
)
734 bitset_windex windex
;
742 if (EBITSET_OP_ZERO_P (bset
))
748 elts
= EBITSET_ELTS (bset
);
749 size
= EBITSET_SIZE (bset
);
750 eindex
= bitno
/ EBITSET_ELT_BITS
;
752 if (bitno
% EBITSET_ELT_BITS
)
754 /* We need to start within an element. This is not very common. */
759 bitset_windex woffset
;
760 bitset_word
*srcp
= EBITSET_WORDS (elt
);
762 windex
= bitno
/ BITSET_WORD_BITS
;
763 woffset
= eindex
/ EBITSET_ELT_WORDS
;
765 for (; (windex
- woffset
) < EBITSET_ELT_WORDS
; windex
++)
767 word
= srcp
[windex
- woffset
] >> (bitno
% BITSET_WORD_BITS
);
769 for (; word
; bitno
++)
773 list
[count
++] = bitno
;
782 bitno
= (windex
+ 1) * BITSET_WORD_BITS
;
786 /* Skip to next element. */
790 /* If num is 1, we could speed things up with a binary search
791 of the word of interest. */
793 for (; eindex
< size
; eindex
++)
802 srcp
= EBITSET_WORDS (elt
);
803 windex
= eindex
* EBITSET_ELT_WORDS
;
805 if ((count
+ EBITSET_ELT_BITS
) < num
)
807 /* The coast is clear, plant boot! */
809 for (i
= 0; i
< EBITSET_ELT_WORDS
; i
++, windex
++)
811 bitno
= windex
* BITSET_WORD_BITS
;
816 if (!(word
& 0xffff))
826 for (; word
; bitno
++)
829 list
[count
++] = bitno
;
837 /* Tread more carefully since we need to check
838 if array overflows. */
840 for (i
= 0; i
< EBITSET_ELT_WORDS
; i
++, windex
++)
842 bitno
= windex
* BITSET_WORD_BITS
;
844 for (word
= srcp
[i
]; word
; bitno
++)
848 list
[count
++] = bitno
;
867 ebitset_op1 (dst
, op
)
881 for (j
= 0; j
< EBITSET_SIZE (dst
); j
++)
883 /* Create new elements if they cannot be found. Perhaps
884 we should just add pointers to a ones element. */
886 ebitset_elt_find (dst
, j
* EBITSET_ELT_WORDS
, EBITSET_CREATE
);
887 memset (EBITSET_WORDS (elt
), ~0, sizeof (EBITSET_WORDS (elt
)));
891 case BITSET_OP_EMPTY_P
:
892 return !ebitset_weed (dst
);
898 EBITSET_NONZERO_SET (dst
);
904 ebitset_op2 (dst
, src
, op
)
917 ebitset_copy (dst
, src
);
921 for (j
= 0; j
< EBITSET_SIZE (src
); j
++)
923 /* Create new elements for dst if they cannot be found
924 or substitute zero elements if src elements not found. */
926 ebitset_elt_find (dst
, j
* EBITSET_ELT_WORDS
, EBITSET_SUBST
);
928 ebitset_elt_find (dst
, j
* EBITSET_ELT_WORDS
, EBITSET_CREATE
);
930 for (i
= 0; i
< EBITSET_ELT_WORDS
; i
++)
931 EBITSET_WORDS (delt
)[i
] = ~EBITSET_WORDS (selt
)[i
];
935 /* Return 1 if DST == SRC. */
936 case BITSET_OP_EQUAL_P
:
937 return ebitset_equal_p (dst
, src
);
939 /* Return 1 if DST == DST | SRC. */
940 case BITSET_OP_SUBSET_P
:
947 selts
= EBITSET_ELTS (src
);
948 delts
= EBITSET_ELTS (dst
);
950 ssize
= EBITSET_SIZE (src
);
951 dsize
= EBITSET_SIZE (dst
);
953 for (j
= 0; j
< ssize
; j
++)
955 selt
= j
< ssize
? selts
[j
] : 0;
956 delt
= j
< dsize
? delts
[j
] : 0;
962 selt
= &ebitset_zero_elts
[0];
964 delt
= &ebitset_zero_elts
[0];
966 for (i
= 0; i
< EBITSET_ELT_WORDS
; i
++)
967 if (EBITSET_WORDS (delt
)[i
]
968 != (EBITSET_WORDS (selt
)[i
] | EBITSET_WORDS (delt
)[i
]))
975 /* Return 1 if DST & SRC == 0. */
976 case BITSET_OP_DISJOINT_P
:
983 selts
= EBITSET_ELTS (src
);
984 delts
= EBITSET_ELTS (dst
);
986 ssize
= EBITSET_SIZE (src
);
987 dsize
= EBITSET_SIZE (dst
);
989 for (j
= 0; j
< ssize
; j
++)
991 selt
= j
< ssize
? selts
[j
] : 0;
992 delt
= j
< dsize
? delts
[j
] : 0;
997 for (i
= 0; i
< EBITSET_ELT_WORDS
; i
++)
998 if ((EBITSET_WORDS (selt
)[i
] & EBITSET_WORDS (delt
)[i
]))
1009 EBITSET_NONZERO_SET (dst
);
1015 ebitset_op3 (dst
, src1
, src2
, op
)
1021 bitset_windex ssize1
;
1022 bitset_windex ssize2
;
1023 bitset_windex dsize
;
1025 ebitset_elts
*selts1
;
1026 ebitset_elts
*selts2
;
1027 ebitset_elts
*delts
;
1035 /* Fast track common, simple cases. */
1036 if (EBITSET_OP_ZERO_P (src2
))
1038 if (op
== BITSET_OP_AND
)
1041 changed
= EBITSET_OP_ZERO_P (dst
);
1045 else if (op
== BITSET_OP_ANDN
|| op
== BITSET_OP_OR
1046 || op
== BITSET_OP_XOR
)
1048 return ebitset_copy_compare (dst
, src1
);
1051 else if (EBITSET_OP_ZERO_P (src1
))
1053 if (op
== BITSET_OP_AND
|| op
== BITSET_OP_ANDN
)
1056 changed
= EBITSET_OP_ZERO_P (dst
);
1060 else if (op
== BITSET_OP_OR
|| op
== BITSET_OP_XOR
)
1062 return ebitset_copy_compare (dst
, src2
);
1066 ssize1
= EBITSET_SIZE (src1
);
1067 ssize2
= EBITSET_SIZE (src2
);
1068 dsize
= EBITSET_SIZE (dst
);
1074 ebitset_elts_grow (dst
, size
- dsize
);
1076 selts1
= EBITSET_ELTS (src1
);
1077 selts2
= EBITSET_ELTS (src2
);
1078 delts
= EBITSET_ELTS (dst
);
1080 for (j
= 0; j
< size
; j
++)
1086 selt1
= j
< ssize1
? selts1
[j
] : 0;
1087 selt2
= j
< ssize2
? selts2
[j
] : 0;
1088 delt
= j
< dsize
? delts
[j
] : 0;
1090 if (!selt1
&& !selt2
)
1095 ebitset_elt_remove (dst
, j
);
1101 selt1
= &ebitset_zero_elts
[0];
1103 selt2
= &ebitset_zero_elts
[0];
1105 delt
= ebitset_elt_calloc ();
1109 srcp1
= EBITSET_WORDS (selt1
);
1110 srcp2
= EBITSET_WORDS (selt2
);
1111 dstp
= EBITSET_WORDS (delt
);
1115 for (i
= 0; i
< EBITSET_ELT_WORDS
; i
++, dstp
++)
1117 bitset_word tmp
= *srcp1
++ | *srcp2
++;
1128 for (i
= 0; i
< EBITSET_ELT_WORDS
; i
++, dstp
++)
1130 bitset_word tmp
= *srcp1
++ & *srcp2
++;
1141 for (i
= 0; i
< EBITSET_ELT_WORDS
; i
++, dstp
++)
1143 bitset_word tmp
= *srcp1
++ ^ *srcp2
++;
1153 case BITSET_OP_ANDN
:
1154 for (i
= 0; i
< EBITSET_ELT_WORDS
; i
++, dstp
++)
1156 bitset_word tmp
= *srcp1
++ & ~(*srcp2
++);
1170 if (!ebitset_elt_zero_p (delt
))
1172 ebitset_elt_add (dst
, delt
, j
);
1176 ebitset_elt_free (delt
);
1180 /* If we have elements of DST left over, free them all. */
1181 for (; j
< dsize
; j
++)
1190 ebitset_elt_remove (dst
, j
);
1193 EBITSET_NONZERO_SET (dst
);
1198 /* Vector of operations for linked-list bitsets. */
1199 struct bitset_ops_struct ebitset_ops
= {
1209 ebitset_reverse_list
,
1215 /* Return size of initial structure. */
1217 ebitset_bytes (n_bits
)
1218 bitset_bindex n_bits ATTRIBUTE_UNUSED
;
1220 return sizeof (struct bitset_struct
);
1224 /* Initialize a bitset. */
1227 ebitset_init (bset
, n_bits
)
1229 bitset_bindex n_bits
;
1233 bset
->b
.ops
= &ebitset_ops
;
1235 bset
->b
.csize
= EBITSET_ELT_WORDS
;
1237 EBITSET_OP_ZERO_SET (bset
);
1239 size
= n_bits
? (n_bits
+ EBITSET_ELT_BITS
- 1) / EBITSET_ELT_BITS
1240 : EBITSET_INITIAL_SIZE
;
1242 EBITSET_SIZE (bset
) = 0;
1243 EBITSET_ELTS (bset
) = 0;
1244 ebitset_elts_grow (bset
, size
);
1251 ebitset_release_memory ()
1253 ebitset_free_list
= 0;
1254 if (ebitset_obstack_init
)
1256 ebitset_obstack_init
= 0;
1257 obstack_free (&ebitset_obstack
, NULL
);