1 /* Functions to support link list 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 linked-list bitsets. These bitsets can be of
29 arbitrary length and are more efficient than arrays of bits for
32 Usually if all the bits in an element are zero we remove the element
33 from the list. However, a side effect of the bit caching is that we
34 do not always notice when an element becomes zero. Hence the
35 lbitset_weed function which removes zero elements. */
38 /* Number of words to use for each element. The larger the value the
39 greater the size of the cache and the shorter the time to find a given bit
40 but the more memory wasted for sparse bitsets and the longer the time
41 to search for set bits. */
43 #ifndef LBITSET_ELT_WORDS
44 #define LBITSET_ELT_WORDS 2
47 typedef bitset_word lbitset_word
;
49 #define LBITSET_WORD_BITS BITSET_WORD_BITS
51 /* Number of bits stored in each element. */
52 #define LBITSET_ELT_BITS \
53 ((unsigned) (LBITSET_ELT_WORDS * LBITSET_WORD_BITS))
55 /* Lbitset element. We use an array of bits for each element.
56 These are linked together in a doubly-linked list. */
57 typedef struct lbitset_elt_struct
59 struct lbitset_elt_struct
*next
; /* Next element. */
60 struct lbitset_elt_struct
*prev
; /* Previous element. */
61 bitset_windex index
; /* bitno / BITSET_WORD_BITS. */
62 bitset_word words
[LBITSET_ELT_WORDS
]; /* Bits that are set. */
67 /* Head of lbitset linked list. */
68 typedef struct lbitset_struct
70 lbitset_elt
*head
; /* First element in linked list. */
71 lbitset_elt
*tail
; /* Last element in linked list. */
78 struct bbitset_struct b
;
79 struct lbitset_struct l
;
83 enum lbitset_find_mode
84 { LBITSET_FIND
, LBITSET_CREATE
, LBITSET_SUBST
};
86 static lbitset_elt lbitset_zero_elts
[3]; /* Elements of all zero bits. */
88 /* Obstack to allocate bitset elements from. */
89 static struct obstack lbitset_obstack
;
90 static int lbitset_obstack_init
= 0;
91 static lbitset_elt
*lbitset_free_list
; /* Free list of bitset elements. */
93 static lbitset_elt
*lbitset_elt_alloc
PARAMS ((void));
94 static lbitset_elt
*lbitset_elt_calloc
PARAMS ((void));
95 static void lbitset_elt_link
PARAMS ((bitset
, lbitset_elt
*));
96 static void lbitset_elt_unlink
PARAMS ((bitset
, lbitset_elt
*));
97 static void lbitset_elt_free
PARAMS ((lbitset_elt
*));
98 static lbitset_elt
*lbitset_elt_find
PARAMS ((bitset
, bitset_windex
,
99 enum lbitset_find_mode
));
100 static int lbitset_elt_zero_p
PARAMS ((lbitset_elt
*));
102 static void lbitset_prune
PARAMS ((bitset
, lbitset_elt
*));
103 static void lbitset_weed
PARAMS ((bitset
));
104 static void lbitset_zero
PARAMS ((bitset
));
105 static int lbitset_equal_p
PARAMS ((bitset
, bitset
));
106 static void lbitset_copy
PARAMS ((bitset
, bitset
));
107 static int lbitset_copy_compare
PARAMS ((bitset
, bitset
));
108 static void lbitset_set
PARAMS ((bitset
, bitset_bindex
));
109 static void lbitset_reset
PARAMS ((bitset
, bitset_bindex
));
110 static int lbitset_test
PARAMS ((bitset
, bitset_bindex
));
111 static int lbitset_size
PARAMS ((bitset
));
112 static int lbitset_op1
PARAMS ((bitset
, enum bitset_ops
));
113 static int lbitset_op2
PARAMS ((bitset
, bitset
, enum bitset_ops
));
114 static int lbitset_op3
PARAMS ((bitset
, bitset
, bitset
, enum bitset_ops
));
115 static int lbitset_list
PARAMS ((bitset
, bitset_bindex
*, bitset_bindex
,
117 static int lbitset_reverse_list
118 PARAMS ((bitset
, bitset_bindex
*, bitset_bindex
, bitset_bindex
*));
119 static void lbitset_free
PARAMS ((bitset
));
122 #define LBITSET_CURRENT1(X) (lbitset_elt *)((char *)(X) + ((char *)&(((lbitset_elt *)(X))->next) - (char *)&(((lbitset_elt *)(X))->words)))
124 #define LBITSET_CURRENT(X) LBITSET_CURRENT1((X)->b.cdata)
126 #define LBITSET_HEAD(X) ((X)->l.head)
127 #define LBITSET_TAIL(X) ((X)->l.tail)
129 /* Allocate a lbitset element. The bits are not cleared. */
130 static inline lbitset_elt
*
135 if (lbitset_free_list
!= 0)
137 elt
= lbitset_free_list
;
138 lbitset_free_list
= elt
->next
;
142 /* We can't use gcc_obstack_init to initialize the obstack since
143 print-rtl.c now calls bitset functions, and bitset is linked
144 into the gen* functions. */
145 if (!lbitset_obstack_init
)
147 lbitset_obstack_init
= 1;
149 /* Let particular systems override the size of a chunk. */
151 #ifndef OBSTACK_CHUNK_SIZE
152 #define OBSTACK_CHUNK_SIZE 0
155 /* Let them override the alloc and free routines too. */
157 #ifndef OBSTACK_CHUNK_ALLOC
158 #define OBSTACK_CHUNK_ALLOC xmalloc
161 #ifndef OBSTACK_CHUNK_FREE
162 #define OBSTACK_CHUNK_FREE free
165 #if !defined(__GNUC__) || (__GNUC__ < 2)
166 #define __alignof__(type) 0
169 obstack_specify_allocation (&lbitset_obstack
, OBSTACK_CHUNK_SIZE
,
170 __alignof__ (lbitset_elt
),
171 (void *(*)PARAMS ((long)))
173 (void (*)PARAMS ((void *)))
177 /* Perhaps we should add a number of new elements to the free
179 elt
= (lbitset_elt
*) obstack_alloc (&lbitset_obstack
,
180 sizeof (lbitset_elt
));
187 /* Allocate a lbitset element. The bits are not cleared. */
188 static inline lbitset_elt
*
189 lbitset_elt_calloc ()
193 elt
= lbitset_elt_alloc ();
194 memset (elt
->words
, 0, sizeof (elt
->words
));
200 lbitset_elt_free (elt
)
203 elt
->next
= lbitset_free_list
;
204 lbitset_free_list
= elt
;
208 /* Unlink element ELT from bitset BSET. */
210 lbitset_elt_unlink (bset
, elt
)
214 lbitset_elt
*next
= elt
->next
;
215 lbitset_elt
*prev
= elt
->prev
;
223 if (LBITSET_HEAD (bset
) == elt
)
224 LBITSET_HEAD (bset
) = next
;
225 if (LBITSET_TAIL (bset
) == elt
)
226 LBITSET_TAIL (bset
) = prev
;
228 /* Update cache pointer. Since the first thing we try is to insert
229 before current, make current the next entry in preference to the
231 if (LBITSET_CURRENT (bset
) == elt
)
235 bset
->b
.cdata
= next
->words
;
236 bset
->b
.cindex
= next
->index
;
240 bset
->b
.cdata
= prev
->words
;
241 bset
->b
.cindex
= prev
->index
;
250 lbitset_elt_free (elt
);
254 /* Cut the chain of bitset BSET before element ELT and free the
257 lbitset_prune (bset
, elt
)
268 LBITSET_TAIL (bset
) = elt
->prev
;
269 bset
->b
.cdata
= elt
->prev
->words
;
270 bset
->b
.cindex
= elt
->prev
->index
;
275 LBITSET_HEAD (bset
) = 0;
276 LBITSET_TAIL (bset
) = 0;
281 for (; elt
; elt
= next
)
284 lbitset_elt_free (elt
);
289 /* Return nonzero if all bits in an element are zero. */
291 lbitset_elt_zero_p (elt
)
296 for (i
= 0; i
< LBITSET_ELT_WORDS
; i
++)
304 /* Link the bitset element into the current bitset linked list. */
306 lbitset_elt_link (bset
, elt
)
310 bitset_windex windex
= elt
->index
;
312 lbitset_elt
*current
;
315 current
= LBITSET_CURRENT (bset
);
317 current
= LBITSET_HEAD (bset
);
319 /* If this is the first and only element, add it in. */
320 if (LBITSET_HEAD (bset
) == 0)
322 elt
->next
= elt
->prev
= 0;
323 LBITSET_HEAD (bset
) = elt
;
324 LBITSET_TAIL (bset
) = elt
;
327 /* If this index is less than that of the current element, it goes
328 somewhere before the current element. */
329 else if (windex
< bset
->b
.cindex
)
332 ptr
->prev
&& ptr
->prev
->index
> windex
; ptr
= ptr
->prev
)
336 ptr
->prev
->next
= elt
;
338 LBITSET_HEAD (bset
) = elt
;
340 elt
->prev
= ptr
->prev
;
345 /* Otherwise, it must go somewhere after the current element. */
349 ptr
->next
&& ptr
->next
->index
< windex
; ptr
= ptr
->next
)
353 ptr
->next
->prev
= elt
;
355 LBITSET_TAIL (bset
) = elt
;
357 elt
->next
= ptr
->next
;
362 /* Set up so this is the first element searched. */
363 bset
->b
.cindex
= windex
;
364 bset
->b
.csize
= LBITSET_ELT_WORDS
;
365 bset
->b
.cdata
= elt
->words
;
370 lbitset_elt_find (bset
, windex
, mode
)
372 bitset_windex windex
;
373 enum lbitset_find_mode mode
;
376 lbitset_elt
*current
;
380 current
= LBITSET_CURRENT (bset
);
381 /* Check if element is the cached element. */
382 if ((windex
- bset
->b
.cindex
) < bset
->b
.csize
)
387 current
= LBITSET_HEAD (bset
);
392 if (windex
< bset
->b
.cindex
)
395 elt
->prev
&& elt
->index
> windex
; elt
= elt
->prev
)
401 elt
->next
&& (elt
->index
+ LBITSET_ELT_WORDS
- 1) < windex
;
406 /* `element' is the nearest to the one we want. If it's not the one
407 we want, the one we want does not exist. */
408 if (elt
&& (windex
- elt
->index
) < LBITSET_ELT_WORDS
)
410 bset
->b
.cindex
= elt
->index
;
411 bset
->b
.csize
= LBITSET_ELT_WORDS
;
412 bset
->b
.cdata
= elt
->words
;
423 windex
= (windex
/ (unsigned) LBITSET_ELT_WORDS
) * LBITSET_ELT_WORDS
;
425 elt
= lbitset_elt_calloc ();
427 lbitset_elt_link (bset
, elt
);
431 return &lbitset_zero_elts
[0];
439 /* Weed out the zero elements from the list. */
447 for (elt
= LBITSET_HEAD (bset
); elt
; elt
= next
)
450 if (lbitset_elt_zero_p (elt
))
451 lbitset_elt_unlink (bset
, elt
);
456 /* Set all bits in the bitset to zero. */
463 head
= LBITSET_HEAD (bset
);
467 /* Clear a bitset by freeing the linked list at the head element. */
468 lbitset_prune (bset
, head
);
473 lbitset_equal_p (dst
, src
)
486 for (selt
= LBITSET_HEAD (src
), delt
= LBITSET_HEAD (dst
);
487 selt
&& delt
; selt
= selt
->next
, delt
= delt
->next
)
489 if (selt
->index
!= delt
->index
)
492 for (j
= 0; j
< LBITSET_ELT_WORDS
; j
++)
493 if (delt
->words
[j
] != selt
->words
[j
])
496 return !selt
&& !delt
;
500 /* Copy bits from bitset SRC to bitset DST. */
502 lbitset_copy (dst
, src
)
516 head
= LBITSET_HEAD (src
);
521 for (elt
= head
; elt
; elt
= elt
->next
)
523 tmp
= lbitset_elt_alloc ();
524 tmp
->index
= elt
->index
;
530 LBITSET_HEAD (dst
) = tmp
;
533 memcpy (tmp
->words
, elt
->words
, sizeof (elt
->words
));
535 LBITSET_TAIL (dst
) = tmp
;
537 dst
->b
.csize
= LBITSET_ELT_WORDS
;
538 dst
->b
.cdata
= LBITSET_HEAD (dst
)->words
;
539 dst
->b
.cindex
= LBITSET_HEAD (dst
)->index
;
543 /* Copy bits from bitset SRC to bitset DST. Return non-zero if
544 bitsets different. */
546 lbitset_copy_compare (dst
, src
)
553 if (!LBITSET_HEAD (dst
))
555 lbitset_copy (dst
, src
);
556 return LBITSET_HEAD (src
) != 0;
559 if (lbitset_equal_p (dst
, src
))
562 lbitset_copy (dst
, src
);
567 /* Return size in bits of bitset SRC. */
574 elt
= LBITSET_TAIL (src
);
578 /* Return current size of bitset in bits. */
579 return (elt
->index
+ LBITSET_ELT_WORDS
) * BITSET_WORD_BITS
;
583 /* Set bit BITNO in bitset DST. */
585 lbitset_set (dst
, bitno
)
589 bitset_windex windex
= bitno
/ BITSET_WORD_BITS
;
591 lbitset_elt_find (dst
, windex
, LBITSET_CREATE
);
593 dst
->b
.cdata
[windex
- dst
->b
.cindex
] |= (1 << (bitno
% BITSET_WORD_BITS
));
597 /* Reset bit BITNO in bitset DST. */
599 lbitset_reset (dst
, bitno
)
603 bitset_windex windex
= bitno
/ BITSET_WORD_BITS
;
605 if (!lbitset_elt_find (dst
, windex
, LBITSET_FIND
))
608 dst
->b
.cdata
[windex
- dst
->b
.cindex
] &= ~(1 << (bitno
% BITSET_WORD_BITS
));
610 /* If all the data is zero, perhaps we should unlink it now... */
614 /* Test bit BITNO in bitset SRC. */
616 lbitset_test (src
, bitno
)
620 bitset_windex windex
= bitno
/ BITSET_WORD_BITS
;
622 if (!lbitset_elt_find (src
, windex
, LBITSET_FIND
))
625 return (src
->b
.cdata
[windex
- src
->b
.cindex
]
626 >> (bitno
% BITSET_WORD_BITS
)) & 1;
638 /* Find list of up to NUM bits set in BSET starting from and including
639 *NEXT and store in array LIST. Return with actual number of bits
640 found and with *NEXT indicating where search stopped. */
642 lbitset_reverse_list (bset
, list
, num
, next
)
648 bitset_bindex rbitno
;
651 bitset_bindex boffset
;
652 bitset_windex windex
;
656 bitset_bindex n_bits
;
658 elt
= LBITSET_TAIL (bset
);
662 n_bits
= (elt
->index
+ LBITSET_ELT_WORDS
) * BITSET_WORD_BITS
;
665 if (rbitno
>= n_bits
)
668 bitno
= n_bits
- (rbitno
+ 1);
670 windex
= bitno
/ BITSET_WORD_BITS
;
672 /* Skip back to starting element. */
673 for (; elt
&& elt
->index
> windex
; elt
= elt
->prev
)
679 /* If num is 1, we could speed things up with a binary search
680 of the word of interest. */
683 bcount
= bitno
% BITSET_WORD_BITS
;
684 boffset
= windex
* BITSET_WORD_BITS
;
688 bitset_word
*srcp
= elt
->words
;
690 for (; (windex
- elt
->index
) < LBITSET_ELT_WORDS
;
691 windex
--, boffset
-= BITSET_WORD_BITS
,
692 bcount
= BITSET_WORD_BITS
- 1)
695 srcp
[windex
- elt
->index
] << (BITSET_WORD_BITS
- 1 - bcount
);
697 for (; word
; bcount
--)
699 if (word
& BITSET_MSB
)
701 list
[count
++] = boffset
+ bcount
;
704 *next
= n_bits
- (boffset
+ bcount
);
715 windex
= elt
->index
+ LBITSET_ELT_WORDS
- 1;
716 boffset
= windex
* BITSET_WORD_BITS
;
720 *next
= n_bits
- (boffset
+ 1);
725 /* Find list of up to NUM bits set in BSET starting from and including
726 *NEXT and store in array LIST. Return with actual number of bits
727 found and with *NEXT indicating where search stopped. */
729 lbitset_list (bset
, list
, num
, next
)
736 bitset_windex windex
;
742 head
= LBITSET_HEAD (bset
);
751 /* This is the most common case. */
753 /* Start with the first element. */
756 bitno
= windex
* BITSET_WORD_BITS
;
760 windex
= bitno
/ BITSET_WORD_BITS
;
762 /* Skip to starting element. */
764 elt
&& (elt
->index
+ LBITSET_ELT_WORDS
- 1) < windex
;
771 if (windex
< elt
->index
)
774 bitno
= windex
* BITSET_WORD_BITS
;
778 bitset_word
*srcp
= elt
->words
;
780 /* We are starting within an element. */
782 for (; (windex
- elt
->index
) < LBITSET_ELT_WORDS
; windex
++)
784 word
= srcp
[windex
- elt
->index
] >> (bitno
% BITSET_WORD_BITS
);
786 for (; word
; bitno
++)
790 list
[count
++] = bitno
;
799 bitno
= (windex
+ 1) * BITSET_WORD_BITS
;
806 bitno
= windex
* BITSET_WORD_BITS
;
812 /* If num is 1, we could speed things up with a binary search
813 of the word of interest. */
818 bitset_word
*srcp
= elt
->words
;
820 if ((count
+ LBITSET_ELT_BITS
) < num
)
822 /* The coast is clear, plant boot! */
824 #if LBITSET_ELT_WORDS == 2
828 if (!(word
& 0xffff))
838 for (; word
; bitno
++)
841 list
[count
++] = bitno
;
846 bitno
= windex
* BITSET_WORD_BITS
;
851 if (!(word
& 0xffff))
856 for (; word
; bitno
++)
859 list
[count
++] = bitno
;
864 bitno
= windex
* BITSET_WORD_BITS
;
866 for (i
= 0; i
< LBITSET_ELT_WORDS
; i
++)
871 if (!(word
& 0xffff))
881 for (; word
; bitno
++)
884 list
[count
++] = bitno
;
889 bitno
= windex
* BITSET_WORD_BITS
;
895 /* Tread more carefully since we need to check
896 if array overflows. */
898 for (i
= 0; i
< LBITSET_ELT_WORDS
; i
++)
900 for (word
= srcp
[i
]; word
; bitno
++)
904 list
[count
++] = bitno
;
914 bitno
= windex
* BITSET_WORD_BITS
;
922 bitno
= windex
* BITSET_WORD_BITS
;
932 lbitset_op1 (dst
, op
)
937 bitset_windex windex
;
947 /* This is a decidedly unfriendly operation for a linked list
949 elt
= LBITSET_TAIL (dst
);
950 /* Ignore empty set. */
955 for (i
= 0; i
< windex
; i
+= LBITSET_ELT_WORDS
)
957 /* Create new elements if they cannot be found. */
958 elt
= lbitset_elt_find (dst
, i
, LBITSET_CREATE
);
959 memset (elt
->words
, ~0, sizeof (elt
->words
));
963 case BITSET_OP_EMPTY_P
:
965 if (LBITSET_HEAD (dst
))
978 lbitset_op2 (dst
, src
, op
)
988 bitset_windex windex
;
993 lbitset_copy (dst
, src
);
997 /* This is another unfriendly operation for a linked list
999 elt
= LBITSET_TAIL (dst
);
1000 /* Ignore empty set. */
1004 windex
= elt
->index
;
1005 for (i
= 0; i
< windex
; i
+= LBITSET_ELT_WORDS
)
1007 /* Create new elements for dst if they cannot be found
1008 or substitute zero elements if src elements not found. */
1009 selt
= lbitset_elt_find (dst
, i
, LBITSET_SUBST
);
1010 delt
= lbitset_elt_find (dst
, i
, LBITSET_CREATE
);
1012 for (j
= 0; j
< LBITSET_ELT_WORDS
; j
++)
1013 delt
->words
[j
] = ~selt
->words
[j
];
1018 /* Return 1 if DST == SRC. */
1019 case BITSET_OP_EQUAL_P
:
1020 return lbitset_equal_p (dst
, src
);
1023 /* Return 1 if DST == DST | SRC. */
1024 case BITSET_OP_SUBSET_P
:
1025 for (selt
= LBITSET_HEAD (src
), delt
= LBITSET_HEAD (dst
);
1026 selt
|| delt
; selt
= selt
->next
, delt
= delt
->next
)
1029 selt
= &lbitset_zero_elts
[0];
1031 delt
= &lbitset_zero_elts
[0];
1032 else if (selt
->index
!= delt
->index
)
1034 if (selt
->index
< delt
->index
)
1036 lbitset_zero_elts
[2].next
= delt
;
1037 delt
= &lbitset_zero_elts
[2];
1041 lbitset_zero_elts
[1].next
= selt
;
1042 selt
= &lbitset_zero_elts
[1];
1046 for (j
= 0; j
< LBITSET_ELT_WORDS
; j
++)
1047 if (delt
->words
[j
] != (selt
->words
[j
] | delt
->words
[j
]))
1052 /* Return 1 if DST & SRC == 0. */
1053 case BITSET_OP_DISJOINT_P
:
1054 for (selt
= LBITSET_HEAD (src
), delt
= LBITSET_HEAD (dst
);
1055 selt
&& delt
; selt
= selt
->next
, delt
= delt
->next
)
1057 if (selt
->index
!= delt
->index
)
1059 if (selt
->index
< delt
->index
)
1061 lbitset_zero_elts
[2].next
= delt
;
1062 delt
= &lbitset_zero_elts
[2];
1066 lbitset_zero_elts
[1].next
= selt
;
1067 selt
= &lbitset_zero_elts
[1];
1069 /* Since the elements are different, there is no
1070 intersection of these elements. */
1074 for (j
= 0; j
< LBITSET_ELT_WORDS
; j
++)
1075 if (selt
->words
[j
] & delt
->words
[j
])
1089 lbitset_op3 (dst
, src1
, src2
, op
)
1095 lbitset_elt
*selt1
= LBITSET_HEAD (src1
);
1096 lbitset_elt
*selt2
= LBITSET_HEAD (src2
);
1097 lbitset_elt
*delt
= LBITSET_HEAD (dst
);
1098 bitset_windex windex1
;
1099 bitset_windex windex2
;
1100 bitset_windex windex
;
1110 /* Fast track common, simple cases. */
1113 if (op
== BITSET_OP_AND
)
1116 changed
= !LBITSET_HEAD (dst
);
1120 else if (op
== BITSET_OP_ANDN
|| op
== BITSET_OP_OR
1121 || op
== BITSET_OP_XOR
)
1123 return lbitset_copy_compare (dst
, src1
);
1128 if (op
== BITSET_OP_AND
|| op
== BITSET_OP_ANDN
)
1131 changed
= !LBITSET_HEAD (dst
);
1135 else if (op
== BITSET_OP_OR
|| op
== BITSET_OP_XOR
)
1137 return lbitset_copy_compare (dst
, src2
);
1141 LBITSET_HEAD (dst
) = 0;
1144 windex1
= (selt1
) ? selt1
->index
: BITSET_INDEX_MAX
;
1145 windex2
= (selt2
) ? selt2
->index
: BITSET_INDEX_MAX
;
1147 while (selt1
|| selt2
)
1149 /* Figure out whether we need to substitute zero elements for
1151 if (windex1
== windex2
)
1156 selt1
= selt1
->next
;
1157 windex1
= (selt1
) ? selt1
->index
: BITSET_INDEX_MAX
;
1158 selt2
= selt2
->next
;
1159 windex2
= (selt2
) ? selt2
->index
: BITSET_INDEX_MAX
;
1161 else if (windex1
< windex2
)
1165 stmp2
= &lbitset_zero_elts
[0];
1166 selt1
= selt1
->next
;
1167 windex1
= (selt1
) ? selt1
->index
: BITSET_INDEX_MAX
;
1172 stmp1
= &lbitset_zero_elts
[0];
1174 selt2
= selt2
->next
;
1175 windex2
= (selt2
) ? selt2
->index
: BITSET_INDEX_MAX
;
1178 /* Find the appropriate element from DST. Begin by discarding
1179 elements that we've skipped. */
1180 while (delt
&& delt
->index
< windex
)
1185 lbitset_elt_free (dtmp
);
1187 if (delt
&& delt
->index
== windex
)
1193 dtmp
= lbitset_elt_calloc ();
1195 /* Do the operation, and if any bits are set, link it into the
1197 srcp1
= stmp1
->words
;
1198 srcp2
= stmp2
->words
;
1203 for (i
= 0; i
< LBITSET_ELT_WORDS
; i
++, dstp
++)
1205 bitset_word tmp
= *srcp1
++ | *srcp2
++;
1216 for (i
= 0; i
< LBITSET_ELT_WORDS
; i
++, dstp
++)
1218 bitset_word tmp
= *srcp1
++ & *srcp2
++;
1229 for (i
= 0; i
< LBITSET_ELT_WORDS
; i
++, dstp
++)
1231 bitset_word tmp
= *srcp1
++ ^ *srcp2
++;
1241 case BITSET_OP_ANDN
:
1242 for (i
= 0; i
< LBITSET_ELT_WORDS
; i
++, dstp
++)
1244 bitset_word tmp
= *srcp1
++ & ~(*srcp2
++);
1258 if (!lbitset_elt_zero_p (dtmp
))
1260 dtmp
->index
= windex
;
1261 /* Perhaps this could be optimised... */
1262 lbitset_elt_link (dst
, dtmp
);
1266 lbitset_elt_free (dtmp
);
1270 /* If we have elements of DST left over, free them all. */
1274 lbitset_prune (dst
, delt
);
1281 /* Vector of operations for linked-list bitsets. */
1282 struct bitset_ops_struct lbitset_ops
= {
1292 lbitset_reverse_list
,
1298 /* Return size of initial structure. */
1300 lbitset_bytes (n_bits
)
1301 bitset_bindex n_bits ATTRIBUTE_UNUSED
;
1303 return sizeof (struct bitset_struct
);
1307 /* Initialize a bitset. */
1310 lbitset_init (bset
, n_bits
)
1312 bitset_bindex n_bits ATTRIBUTE_UNUSED
;
1314 bset
->b
.ops
= &lbitset_ops
;
1320 lbitset_release_memory ()
1322 lbitset_free_list
= 0;
1323 if (lbitset_obstack_init
)
1325 lbitset_obstack_init
= 0;
1326 obstack_free (&lbitset_obstack
, NULL
);