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. */
27 /* This file implements expandable bitsets. These bitsets can be of
28 arbitrary length and are more efficient than arrays of bits for
31 Empty elements are represented by a NULL pointer in the table of
32 element pointers. An alternative is to point to a special zero
33 element. Similarly, we could represent an all 1's element with
34 another special ones element pointer.
36 Bitsets are commonly empty so we need to ensure that this special
37 case is fast. A zero bitset is indicated when cdata is 0. This is
38 conservative since cdata may be non zero and the bitset may still
41 The bitset cache can be disabled either by setting cindex to
42 some large number or by setting csize to 0. Here
43 we use the former approach since cindex needs to be updated whenever
48 /* Number of words to use for each element. */
50 #ifndef EBITSET_ELT_WORDS
51 #define EBITSET_ELT_WORDS 2
54 /* Number of bits stored in each element. */
55 #define EBITSET_ELT_BITS \
56 ((unsigned) (EBITSET_ELT_WORDS * BITSET_WORD_BITS))
58 /* Ebitset element. We use an array of bits. */
59 typedef struct ebitset_elt_struct
63 bitset_word words
[EBITSET_ELT_WORDS
]; /* Bits that are set. */
64 struct ebitset_elt_struct
*next
;
71 typedef ebitset_elt
*ebitset_elts
;
73 /* Head of ebitset linked list. */
74 typedef struct ebitset_struct
76 unsigned int size
; /* Number of elements. */
77 ebitset_elts
*elts
; /* Expanding array of pointers to elements. */
82 /* Number of elements to initially allocate. */
84 #ifndef EBITSET_INITIAL_SIZE
85 #define EBITSET_INITIAL_SIZE 2
88 /* Minimum number of elements to grow table. */
90 #ifndef EBITSET_GROW_SIZE
91 #define EBITSET_GROW_SIZE 4
96 struct bbitset_struct b
;
97 struct ebitset_struct e
;
100 enum ebitset_find_mode
101 { EBITSET_FIND
, EBITSET_CREATE
, EBITSET_SUBST
};
103 static ebitset_elt ebitset_zero_elts
[1]; /* Elements of all zero bits. */
105 /* Obstack to allocate bitset elements from. */
106 static struct obstack ebitset_obstack
;
107 static int ebitset_obstack_init
= 0;
108 static ebitset_elt
*ebitset_free_list
; /* Free list of bitset elements. */
110 static void ebitset_elts_grow
PARAMS ((bitset
, unsigned int));
111 static ebitset_elt
*ebitset_elt_alloc
PARAMS ((void));
112 static ebitset_elt
*ebitset_elt_calloc
PARAMS ((void));
113 static void ebitset_elt_add
PARAMS ((bitset
, ebitset_elt
*, unsigned int));
114 static void ebitset_elt_remove
PARAMS ((bitset
, unsigned int));
115 static void ebitset_elt_free
PARAMS ((ebitset_elt
*));
116 static ebitset_elt
*ebitset_elt_find
PARAMS ((bitset
, bitset_windex
,
117 enum ebitset_find_mode
));
118 static ebitset_elt
*ebitset_elt_last
PARAMS ((bitset
));
119 static int ebitset_elt_zero_p
PARAMS ((ebitset_elt
*));
121 static int ebitset_weed
PARAMS ((bitset
));
122 static void ebitset_zero
PARAMS ((bitset
));
123 static int ebitset_equal_p
PARAMS ((bitset
, bitset
));
124 static void ebitset_copy
PARAMS ((bitset
, bitset
));
125 static int ebitset_copy_compare
PARAMS ((bitset
, bitset
));
126 static void ebitset_set
PARAMS ((bitset
, bitset_bindex
));
127 static void ebitset_reset
PARAMS ((bitset
, bitset_bindex
));
128 static int ebitset_test
PARAMS ((bitset
, bitset_bindex
));
129 static int ebitset_size
PARAMS ((bitset
));
130 static int ebitset_op1
PARAMS ((bitset
, enum bitset_ops
));
131 static int ebitset_op2
PARAMS ((bitset
, bitset
, enum bitset_ops
));
132 static int ebitset_op3
PARAMS ((bitset
, bitset
, bitset
, enum bitset_ops
));
133 static int ebitset_list
PARAMS ((bitset
, bitset_bindex
*, bitset_bindex
,
135 static int ebitset_reverse_list
136 PARAMS ((bitset
, bitset_bindex
*, bitset_bindex
, bitset_bindex
*));
137 static void ebitset_free
PARAMS ((bitset
));
139 #define EBITSET_ELTS(BSET) ((BSET)->e.elts)
140 #define EBITSET_SIZE(BSET) ((BSET)->e.size)
142 #define EBITSET_NEXT(ELT) ((ELT)->u.next)
143 #define EBITSET_WORDS(ELT) ((ELT)->u.words)
145 /* Disable bitset cache and mark BSET as being zero. */
146 #define EBITSET_OP_ZERO_SET(BSET) ((BSET)->b.cindex = BITSET_INDEX_MAX, \
149 #define EBITSET_CACHE_DISABLE(BSET) ((BSET)->b.cindex = BITSET_INDEX_MAX)
151 /* Disable bitset cache and mark BSET as being possibly non-zero. */
152 #define EBITSET_NONZERO_SET(BSET) \
153 (EBITSET_CACHE_DISABLE (BSET), (BSET)->b.cdata = (bitset_word *)~0)
155 /* A conservative estimate of whether the bitset is zero.
156 This is non-zero only if we know for sure that the bitset is zero. */
157 #define EBITSET_OP_ZERO_P(BSET) ((BSET)->b.cdata == 0)
159 /* Enable cache to point to element with table index EINDEX.
160 The element must exist. */
161 #define EBITSET_CACHE_SET(BSET, EINDEX) \
162 ((BSET)->b.cindex = (EINDEX) * EBITSET_ELT_WORDS, \
163 (BSET)->b.cdata = EBITSET_WORDS (EBITSET_ELTS (BSET) [EINDEX]))
166 /* Grow the expandable table for BSET by SIZE elements. */
168 ebitset_elts_grow (bset
, size
)
172 unsigned int oldsize
;
173 unsigned int newsize
;
175 oldsize
= EBITSET_SIZE (bset
);
176 newsize
= oldsize
+ size
;
178 EBITSET_ELTS (bset
) = xrealloc (EBITSET_ELTS (bset
),
179 newsize
* sizeof (ebitset_elt
*));
180 EBITSET_SIZE (bset
) = newsize
;
182 memset (EBITSET_ELTS (bset
) + oldsize
, 0, size
* sizeof (ebitset_elt
*));
186 /* Allocate a ebitset element. The bits are not cleared. */
187 static inline ebitset_elt
*
192 if (ebitset_free_list
!= 0)
194 elt
= ebitset_free_list
;
195 ebitset_free_list
= EBITSET_NEXT (elt
);
199 /* We can't use gcc_obstack_init to initialize the obstack since
200 print-rtl.c now calls bitset functions, and bitset is linked
201 into the gen* functions. */
202 if (!ebitset_obstack_init
)
204 ebitset_obstack_init
= 1;
206 /* Let particular systems override the size of a chunk. */
208 #ifndef OBSTACK_CHUNK_SIZE
209 #define OBSTACK_CHUNK_SIZE 0
212 /* Let them override the alloc and free routines too. */
214 #ifndef OBSTACK_CHUNK_ALLOC
215 #define OBSTACK_CHUNK_ALLOC xmalloc
218 #ifndef OBSTACK_CHUNK_FREE
219 #define OBSTACK_CHUNK_FREE free
222 #if !defined(__GNUC__) || (__GNUC__ < 2)
223 #define __alignof__(type) 0
226 obstack_specify_allocation (&ebitset_obstack
, OBSTACK_CHUNK_SIZE
,
227 __alignof__ (ebitset_elt
),
228 (void *(*)PARAMS ((long)))
230 (void (*)PARAMS ((void *)))
234 /* Perhaps we should add a number of new elements to the free
236 elt
= (ebitset_elt
*) obstack_alloc (&ebitset_obstack
,
237 sizeof (ebitset_elt
));
244 /* Allocate a ebitset element. The bits are not cleared. */
245 static inline ebitset_elt
*
246 ebitset_elt_calloc ()
250 elt
= ebitset_elt_alloc ();
251 memset (EBITSET_WORDS (elt
), 0, sizeof (EBITSET_WORDS (elt
)));
257 ebitset_elt_free (elt
)
260 EBITSET_NEXT (elt
) = ebitset_free_list
;
261 ebitset_free_list
= elt
;
265 /* Remove element with index EINDEX from bitset BSET. */
267 ebitset_elt_remove (bset
, eindex
)
274 elts
= EBITSET_ELTS (bset
);
279 ebitset_elt_free (elt
);
283 /* Add ELT into elts at index EINDEX of bitset BSET. */
285 ebitset_elt_add (bset
, elt
, eindex
)
292 elts
= EBITSET_ELTS (bset
);
293 /* Assume that the elts entry not allocated. */
298 /* Return nonzero if all bits in an element are zero. */
300 ebitset_elt_zero_p (elt
)
305 for (i
= 0; i
< EBITSET_ELT_WORDS
; i
++)
306 if (EBITSET_WORDS (elt
)[i
])
314 ebitset_elt_find (bset
, index
, mode
)
317 enum ebitset_find_mode mode
;
324 eindex
= index
/ EBITSET_ELT_WORDS
;
326 elts
= EBITSET_ELTS (bset
);
327 size
= EBITSET_SIZE (bset
);
333 if ((elt
= elts
[eindex
]))
335 if (EBITSET_WORDS (elt
) == bset
->b
.cdata
)
338 EBITSET_CACHE_SET (bset
, eindex
);
343 /* The element could not be found. */
355 extra
= eindex
- size
+ 1;
357 /* We need to expand the table by EXTRA elements. It may be
358 better with large bitsets to grow the number of
359 elements by some fraction of the current size otherwise
360 we can spend a lot of time slowly increasing the size of the
362 if (extra
< EBITSET_GROW_SIZE
)
363 extra
= EBITSET_GROW_SIZE
;
365 ebitset_elts_grow (bset
, extra
);
368 /* Create a new element. */
369 elt
= ebitset_elt_calloc ();
370 ebitset_elt_add (bset
, elt
, eindex
);
371 EBITSET_CACHE_SET (bset
, eindex
);
375 return &ebitset_zero_elts
[0];
383 static inline ebitset_elt
*
384 ebitset_elt_last (bset
)
389 elts
= EBITSET_ELTS (bset
);
391 /* Assume that have at least one element in elts. */
392 return elts
[EBITSET_SIZE (bset
) - 1];
396 /* Weed out the zero elements from the elts. */
405 if (EBITSET_OP_ZERO_P (bset
))
408 elts
= EBITSET_ELTS (bset
);
410 for (j
= 0; j
< EBITSET_SIZE (bset
); j
++)
412 ebitset_elt
*elt
= elts
[j
];
416 if (elt
&& ebitset_elt_zero_p (elt
))
418 ebitset_elt_remove (bset
, j
);
429 /* All the bits are zero. We could shrink the elts.
430 For now just mark BSET as known to be zero. */
431 EBITSET_OP_ZERO_SET (bset
);
434 EBITSET_NONZERO_SET (bset
);
440 /* Set all bits in the bitset to zero. */
448 if (EBITSET_OP_ZERO_P (bset
))
451 elts
= EBITSET_ELTS (bset
);
452 for (j
= 0; j
< EBITSET_SIZE (bset
); j
++)
454 ebitset_elt
*elt
= elts
[j
];
457 ebitset_elt_remove (bset
, j
);
460 /* All the bits are zero. We could shrink the elts.
461 For now just mark BSET as known to be zero. */
462 EBITSET_OP_ZERO_SET (bset
);
467 ebitset_equal_p (dst
, src
)
481 if (EBITSET_SIZE (src
) != EBITSET_SIZE (dst
))
484 selts
= EBITSET_ELTS (src
);
485 delts
= EBITSET_ELTS (dst
);
487 for (j
= 0; j
< EBITSET_SIZE (src
); j
++)
490 ebitset_elt
*selt
= selts
[j
];
491 ebitset_elt
*delt
= delts
[j
];
495 if ((selt
&& !delt
) || (!selt
&& delt
))
498 for (i
= 0; i
< EBITSET_ELT_WORDS
; i
++)
499 if (EBITSET_WORDS (selt
)[i
] != EBITSET_WORDS (delt
)[i
])
506 /* Copy bits from bitset SRC to bitset DST. */
508 ebitset_copy (dst
, src
)
521 if (EBITSET_SIZE (dst
) < EBITSET_SIZE (src
))
522 ebitset_elts_grow (dst
, EBITSET_SIZE (src
) - EBITSET_SIZE (dst
));
524 selts
= EBITSET_ELTS (src
);
525 delts
= EBITSET_ELTS (dst
);
526 for (j
= 0; j
< EBITSET_SIZE (src
); j
++)
528 ebitset_elt
*selt
= selts
[j
];
534 tmp
= ebitset_elt_alloc ();
536 memcpy (EBITSET_WORDS (tmp
), EBITSET_WORDS (selt
),
537 sizeof (EBITSET_WORDS (selt
)));
540 EBITSET_NONZERO_SET (dst
);
544 /* Copy bits from bitset SRC to bitset DST. Return non-zero if
545 bitsets different. */
547 ebitset_copy_compare (dst
, src
)
554 if (EBITSET_OP_ZERO_P (dst
))
556 ebitset_copy (dst
, src
);
557 return !EBITSET_OP_ZERO_P (src
);
560 if (ebitset_equal_p (dst
, src
))
563 ebitset_copy (dst
, src
);
568 /* Return size in bits of bitset SRC. */
573 /* Return current size of bitset in bits. */
574 return EBITSET_SIZE (src
) * EBITSET_ELT_BITS
;
578 /* Set bit BITNO in bitset DST. */
580 ebitset_set (dst
, bitno
)
584 bitset_windex index
= bitno
/ BITSET_WORD_BITS
;
586 ebitset_elt_find (dst
, index
, EBITSET_CREATE
);
588 dst
->b
.cdata
[index
- dst
->b
.cindex
] |= (1 << (bitno
% BITSET_WORD_BITS
));
592 /* Reset bit BITNO in bitset DST. */
594 ebitset_reset (dst
, bitno
)
598 bitset_windex index
= bitno
/ BITSET_WORD_BITS
;
600 if (!ebitset_elt_find (dst
, index
, EBITSET_FIND
))
603 dst
->b
.cdata
[index
- dst
->b
.cindex
] &= ~(1 << (bitno
% BITSET_WORD_BITS
));
605 /* If all the data is zero, perhaps we should remove it now...
606 However, there could be a good chance that the element will be needed
611 /* Test bit BITNO in bitset SRC. */
613 ebitset_test (src
, bitno
)
617 bitset_windex index
= bitno
/ BITSET_WORD_BITS
;
619 if (!ebitset_elt_find (src
, index
, EBITSET_FIND
))
623 cdata
[index
- src
->b
.cindex
] >> (bitno
% BITSET_WORD_BITS
)) & 1;
632 free (EBITSET_ELTS (bset
));
636 /* Find list of up to NUM bits set in BSET starting from and including
637 *NEXT and store in array LIST. Return with actual number of bits
638 found and with *NEXT indicating where search stopped. */
640 ebitset_reverse_list (bset
, list
, num
, next
)
646 bitset_bindex n_bits
;
648 bitset_bindex rbitno
;
650 bitset_bindex bitoff
;
653 bitset_windex windex
;
659 if (EBITSET_OP_ZERO_P (bset
))
662 size
= EBITSET_SIZE (bset
);
663 n_bits
= size
* EBITSET_ELT_BITS
;
666 if (rbitno
>= n_bits
)
669 elts
= EBITSET_ELTS (bset
);
671 bitno
= n_bits
- (rbitno
+ 1);
673 index
= bitno
/ BITSET_WORD_BITS
;
674 eindex
= bitno
/ EBITSET_ELT_BITS
;
675 windex
= index
- eindex
* EBITSET_ELT_WORDS
;
677 /* If num is 1, we could speed things up with a binary search
678 of the word of interest. */
681 bitcnt
= bitno
% BITSET_WORD_BITS
;
682 bitoff
= index
* BITSET_WORD_BITS
;
684 for (; eindex
!= ~0U; eindex
--)
693 srcp
= EBITSET_WORDS (elt
);
695 for (; windex
!= ~0U; windex
--, bitoff
-= BITSET_WORD_BITS
,
696 bitcnt
= BITSET_WORD_BITS
- 1)
698 word
= srcp
[windex
] << (BITSET_WORD_BITS
- 1 - bitcnt
);
700 for (; word
; bitcnt
--)
702 if (word
& BITSET_MSB
)
704 list
[count
++] = bitoff
+ bitcnt
;
707 *next
= n_bits
- (bitoff
+ bitcnt
);
715 windex
= EBITSET_ELT_WORDS
;
718 *next
= n_bits
- (bitoff
+ 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
)
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 windex
;
760 bitset_word
*srcp
= EBITSET_WORDS (elt
);
762 index
= bitno
/ BITSET_WORD_BITS
;
763 windex
= eindex
/ EBITSET_ELT_WORDS
;
765 for (; (index
- windex
) < EBITSET_ELT_WORDS
; index
++)
767 word
= srcp
[index
- windex
] >> (bitno
% BITSET_WORD_BITS
);
769 for (; word
; bitno
++)
773 list
[count
++] = bitno
;
782 bitno
= (index
+ 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
++)
803 srcp
= EBITSET_WORDS (elt
);
804 index
= eindex
* EBITSET_ELT_WORDS
;
806 if ((count
+ EBITSET_ELT_BITS
) < num
)
808 /* The coast is clear, plant boot! */
810 for (i
= 0; i
< EBITSET_ELT_WORDS
; i
++, index
++)
812 bitno
= index
* BITSET_WORD_BITS
;
817 if (!(word
& 0xffff))
827 for (; word
; bitno
++)
830 list
[count
++] = bitno
;
838 /* Tread more carefully since we need to check
839 if array overflows. */
841 for (i
= 0; i
< EBITSET_ELT_WORDS
; i
++, index
++)
843 bitno
= index
* BITSET_WORD_BITS
;
845 for (word
= srcp
[i
]; word
; bitno
++)
849 list
[count
++] = bitno
;
868 ebitset_op1 (dst
, op
)
882 for (j
= 0; j
< EBITSET_SIZE (dst
); j
++)
884 /* Create new elements if they cannot be found. Perhaps
885 we should just add pointers to a ones element. */
887 ebitset_elt_find (dst
, j
* EBITSET_ELT_WORDS
, EBITSET_CREATE
);
888 memset (EBITSET_WORDS (elt
), ~0, sizeof (EBITSET_WORDS (elt
)));
892 case BITSET_OP_EMPTY_P
:
893 return !ebitset_weed (dst
);
899 EBITSET_NONZERO_SET (dst
);
905 ebitset_op2 (dst
, src
, op
)
918 ebitset_copy (dst
, src
);
922 for (j
= 0; j
< EBITSET_SIZE (src
); j
++)
924 /* Create new elements for dst if they cannot be found
925 or substitute zero elements if src elements not found. */
927 ebitset_elt_find (dst
, j
* EBITSET_ELT_WORDS
, EBITSET_SUBST
);
929 ebitset_elt_find (dst
, j
* EBITSET_ELT_WORDS
, EBITSET_CREATE
);
931 for (i
= 0; i
< EBITSET_ELT_WORDS
; i
++)
932 EBITSET_WORDS (delt
)[i
] = ~EBITSET_WORDS (selt
)[i
];
936 /* Return 1 if DST == SRC. */
937 case BITSET_OP_EQUAL_P
:
938 return ebitset_equal_p (dst
, src
);
940 /* Return 1 if DST == DST | SRC. */
941 case BITSET_OP_SUBSET_P
:
948 selts
= EBITSET_ELTS (src
);
949 delts
= EBITSET_ELTS (dst
);
951 ssize
= EBITSET_SIZE (src
);
952 dsize
= EBITSET_SIZE (dst
);
954 for (j
= 0; j
< ssize
; j
++)
959 selt
= j
< ssize
? selts
[j
] : 0;
960 delt
= j
< dsize
? delts
[j
] : 0;
966 selt
= &ebitset_zero_elts
[0];
968 delt
= &ebitset_zero_elts
[0];
970 for (i
= 0; i
< EBITSET_ELT_WORDS
; i
++)
971 if (EBITSET_WORDS (delt
)[i
]
972 != (EBITSET_WORDS (selt
)[i
] | EBITSET_WORDS (delt
)[i
]))
979 /* Return 1 if DST & SRC == 0. */
980 case BITSET_OP_DISJOINT_P
:
987 selts
= EBITSET_ELTS (src
);
988 delts
= EBITSET_ELTS (dst
);
990 ssize
= EBITSET_SIZE (src
);
991 dsize
= EBITSET_SIZE (dst
);
993 for (j
= 0; j
< ssize
; j
++)
998 selt
= j
< ssize
? selts
[j
] : 0;
999 delt
= j
< dsize
? delts
[j
] : 0;
1005 selt
= &ebitset_zero_elts
[0];
1007 delt
= &ebitset_zero_elts
[0];
1009 for (i
= 0; i
< EBITSET_ELT_WORDS
; i
++)
1010 if ((EBITSET_WORDS (selt
)[i
] & EBITSET_WORDS (delt
)[i
]))
1021 EBITSET_NONZERO_SET (dst
);
1027 ebitset_op3 (dst
, src1
, src2
, op
)
1033 bitset_windex ssize1
;
1034 bitset_windex ssize2
;
1035 bitset_windex dsize
;
1037 ebitset_elts
*selts1
;
1038 ebitset_elts
*selts2
;
1039 ebitset_elts
*delts
;
1047 /* Fast track common, simple cases. */
1048 if (EBITSET_OP_ZERO_P (src2
))
1050 if (op
== BITSET_OP_AND
)
1053 changed
= EBITSET_OP_ZERO_P (dst
);
1057 else if (op
== BITSET_OP_ANDN
|| op
== BITSET_OP_OR
1058 || op
== BITSET_OP_XOR
)
1060 return ebitset_copy_compare (dst
, src1
);
1063 else if (EBITSET_OP_ZERO_P (src1
))
1065 if (op
== BITSET_OP_AND
|| op
== BITSET_OP_ANDN
)
1068 changed
= EBITSET_OP_ZERO_P (dst
);
1072 else if (op
== BITSET_OP_OR
|| op
== BITSET_OP_XOR
)
1074 return ebitset_copy_compare (dst
, src2
);
1078 ssize1
= EBITSET_SIZE (src1
);
1079 ssize2
= EBITSET_SIZE (src2
);
1080 dsize
= EBITSET_SIZE (dst
);
1086 ebitset_elts_grow (dst
, size
- dsize
);
1088 selts1
= EBITSET_ELTS (src1
);
1089 selts2
= EBITSET_ELTS (src2
);
1090 delts
= EBITSET_ELTS (dst
);
1092 for (j
= 0; j
< size
; j
++)
1098 selt1
= j
< ssize1
? selts1
[j
] : 0;
1099 selt2
= j
< ssize2
? selts2
[j
] : 0;
1100 delt
= j
< dsize
? delts
[j
] : 0;
1102 if (!selt1
&& !selt2
)
1107 ebitset_elt_remove (dst
, j
);
1113 selt1
= &ebitset_zero_elts
[0];
1115 selt2
= &ebitset_zero_elts
[0];
1117 delt
= ebitset_elt_calloc ();
1121 srcp1
= EBITSET_WORDS (selt1
);
1122 srcp2
= EBITSET_WORDS (selt2
);
1123 dstp
= EBITSET_WORDS (delt
);
1127 for (i
= 0; i
< EBITSET_ELT_WORDS
; i
++, dstp
++)
1129 bitset_word tmp
= *srcp1
++ | *srcp2
++;
1140 for (i
= 0; i
< EBITSET_ELT_WORDS
; i
++, dstp
++)
1142 bitset_word tmp
= *srcp1
++ & *srcp2
++;
1153 for (i
= 0; i
< EBITSET_ELT_WORDS
; i
++, dstp
++)
1155 bitset_word tmp
= *srcp1
++ ^ *srcp2
++;
1165 case BITSET_OP_ANDN
:
1166 for (i
= 0; i
< EBITSET_ELT_WORDS
; i
++, dstp
++)
1168 bitset_word tmp
= *srcp1
++ & ~(*srcp2
++);
1179 for (i
= 0; i
< EBITSET_ELT_WORDS
; i
++, dstp
++)
1181 bitset_word tmp
= *srcp1
++ | ~(*srcp2
++);
1195 if (!ebitset_elt_zero_p (delt
))
1197 ebitset_elt_add (dst
, delt
, j
);
1201 ebitset_elt_free (delt
);
1205 /* If we have elements of DST left over, free them all. */
1206 for (; j
< dsize
; j
++)
1215 ebitset_elt_remove (dst
, j
);
1218 EBITSET_NONZERO_SET (dst
);
1223 /* Vector of operations for linked-list bitsets. */
1224 struct bitset_ops_struct ebitset_ops
= {
1234 ebitset_reverse_list
,
1240 /* Return size of initial structure. */
1242 ebitset_bytes (n_bits
)
1243 bitset_bindex n_bits ATTRIBUTE_UNUSED
;
1245 return sizeof (struct bitset_struct
);
1249 /* Initialize a bitset. */
1252 ebitset_init (bset
, n_bits
)
1254 bitset_bindex n_bits
;
1258 bset
->b
.ops
= &ebitset_ops
;
1260 bset
->b
.csize
= EBITSET_ELT_WORDS
;
1262 EBITSET_OP_ZERO_SET (bset
);
1264 size
= n_bits
? (n_bits
+ EBITSET_ELT_BITS
- 1) / EBITSET_ELT_BITS
1265 : EBITSET_INITIAL_SIZE
;
1267 EBITSET_SIZE (bset
) = 0;
1268 EBITSET_ELTS (bset
) = 0;
1269 ebitset_elts_grow (bset
, size
);
1276 ebitset_release_memory ()
1278 ebitset_free_list
= 0;
1279 if (ebitset_obstack_init
)
1281 ebitset_obstack_init
= 0;
1282 obstack_free (&ebitset_obstack
, NULL
);