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. */
27 /* This file implements linked-list bitsets. These bitsets can be of
28 arbitrary length and are more efficient than arrays of bits for
31 Usually if all the bits in an element are zero we remove the element
32 from the list. However, a side effect of the bit caching is that we
33 do not always notice when an element becomes zero. Hence the
34 lbitset_weed function which removes zero elements. */
37 /* Number of words to use for each element. The larger the value the
38 greater the size of the cache and the shorter the time to find a given bit
39 but the more memory wasted for sparse bitsets and the longer the time
40 to search for set bits. */
42 #ifndef LBITSET_ELT_WORDS
43 #define LBITSET_ELT_WORDS 2
46 typedef bitset_word lbitset_word
;
48 #define LBITSET_WORD_BITS BITSET_WORD_BITS
50 /* Number of bits stored in each element. */
51 #define LBITSET_ELT_BITS \
52 ((unsigned) (LBITSET_ELT_WORDS * LBITSET_WORD_BITS))
54 /* Lbitset element. We use an array of bits for each element.
55 These are linked together in a doubly-linked list. */
56 typedef struct lbitset_elt_struct
58 struct lbitset_elt_struct
*next
; /* Next element. */
59 struct lbitset_elt_struct
*prev
; /* Previous element. */
60 bitset_windex index
; /* bitno / BITSET_WORD_BITS. */
61 bitset_word words
[LBITSET_ELT_WORDS
]; /* Bits that are set. */
66 /* Head of lbitset linked list. */
67 typedef struct lbitset_struct
69 lbitset_elt
*head
; /* First element in linked list. */
70 lbitset_elt
*tail
; /* Last element in linked list. */
77 struct bbitset_struct b
;
78 struct lbitset_struct l
;
82 enum lbitset_find_mode
83 { LBITSET_FIND
, LBITSET_CREATE
, LBITSET_SUBST
};
85 static lbitset_elt lbitset_zero_elts
[3]; /* Elements of all zero bits. */
87 /* Obstack to allocate bitset elements from. */
88 static struct obstack lbitset_obstack
;
89 static int lbitset_obstack_init
= 0;
90 static lbitset_elt
*lbitset_free_list
; /* Free list of bitset elements. */
92 static lbitset_elt
*lbitset_elt_alloc
PARAMS ((void));
93 static lbitset_elt
*lbitset_elt_calloc
PARAMS ((void));
94 static void lbitset_elt_link
PARAMS ((bitset
, lbitset_elt
*));
95 static void lbitset_elt_unlink
PARAMS ((bitset
, lbitset_elt
*));
96 static void lbitset_elt_free
PARAMS ((lbitset_elt
*));
97 static lbitset_elt
*lbitset_elt_find
PARAMS ((bitset
, bitset_windex
,
98 enum lbitset_find_mode
));
99 static int lbitset_elt_zero_p
PARAMS ((lbitset_elt
*));
101 static void lbitset_prune
PARAMS ((bitset
, lbitset_elt
*));
102 static void lbitset_weed
PARAMS ((bitset
));
103 static void lbitset_zero
PARAMS ((bitset
));
104 static int lbitset_equal_p
PARAMS ((bitset
, bitset
));
105 static void lbitset_copy
PARAMS ((bitset
, bitset
));
106 static int lbitset_copy_compare
PARAMS ((bitset
, bitset
));
107 static void lbitset_set
PARAMS ((bitset
, bitset_bindex
));
108 static void lbitset_reset
PARAMS ((bitset
, bitset_bindex
));
109 static int lbitset_test
PARAMS ((bitset
, bitset_bindex
));
110 static int lbitset_size
PARAMS ((bitset
));
111 static int lbitset_op1
PARAMS ((bitset
, enum bitset_ops
));
112 static int lbitset_op2
PARAMS ((bitset
, bitset
, enum bitset_ops
));
113 static int lbitset_op3
PARAMS ((bitset
, bitset
, bitset
, enum bitset_ops
));
114 static int lbitset_list
PARAMS ((bitset
, bitset_bindex
*, bitset_bindex
,
116 static int lbitset_reverse_list
117 PARAMS ((bitset
, bitset_bindex
*, bitset_bindex
, bitset_bindex
*));
118 static void lbitset_free
PARAMS ((bitset
));
121 #define LBITSET_CURRENT1(X) (lbitset_elt *)((char *)(X) + ((char *)&(((lbitset_elt *)(X))->next) - (char *)&(((lbitset_elt *)(X))->words)))
123 #define LBITSET_CURRENT(X) LBITSET_CURRENT1((X)->b.cdata)
125 #define LBITSET_HEAD(X) ((X)->l.head)
126 #define LBITSET_TAIL(X) ((X)->l.tail)
128 /* Allocate a lbitset element. The bits are not cleared. */
129 static inline lbitset_elt
*
134 if (lbitset_free_list
!= 0)
136 elt
= lbitset_free_list
;
137 lbitset_free_list
= elt
->next
;
141 /* We can't use gcc_obstack_init to initialize the obstack since
142 print-rtl.c now calls bitset functions, and bitset is linked
143 into the gen* functions. */
144 if (!lbitset_obstack_init
)
146 lbitset_obstack_init
= 1;
148 /* Let particular systems override the size of a chunk. */
150 #ifndef OBSTACK_CHUNK_SIZE
151 #define OBSTACK_CHUNK_SIZE 0
154 /* Let them override the alloc and free routines too. */
156 #ifndef OBSTACK_CHUNK_ALLOC
157 #define OBSTACK_CHUNK_ALLOC xmalloc
160 #ifndef OBSTACK_CHUNK_FREE
161 #define OBSTACK_CHUNK_FREE free
164 #if !defined(__GNUC__) || (__GNUC__ < 2)
165 #define __alignof__(type) 0
168 obstack_specify_allocation (&lbitset_obstack
, OBSTACK_CHUNK_SIZE
,
169 __alignof__ (lbitset_elt
),
170 (void *(*)PARAMS ((long)))
172 (void (*)PARAMS ((void *)))
176 /* Perhaps we should add a number of new elements to the free
178 elt
= (lbitset_elt
*) obstack_alloc (&lbitset_obstack
,
179 sizeof (lbitset_elt
));
186 /* Allocate a lbitset element. The bits are not cleared. */
187 static inline lbitset_elt
*
188 lbitset_elt_calloc ()
192 elt
= lbitset_elt_alloc ();
193 memset (elt
->words
, 0, sizeof (elt
->words
));
199 lbitset_elt_free (elt
)
202 elt
->next
= lbitset_free_list
;
203 lbitset_free_list
= elt
;
207 /* Unlink element ELT from bitset BSET. */
209 lbitset_elt_unlink (bset
, elt
)
213 lbitset_elt
*next
= elt
->next
;
214 lbitset_elt
*prev
= elt
->prev
;
222 if (LBITSET_HEAD (bset
) == elt
)
223 LBITSET_HEAD (bset
) = next
;
224 if (LBITSET_TAIL (bset
) == elt
)
225 LBITSET_TAIL (bset
) = prev
;
227 /* Update cache pointer. Since the first thing we try is to insert
228 before current, make current the next entry in preference to the
230 if (LBITSET_CURRENT (bset
) == elt
)
234 bset
->b
.cdata
= next
->words
;
235 bset
->b
.cindex
= next
->index
;
239 bset
->b
.cdata
= prev
->words
;
240 bset
->b
.cindex
= prev
->index
;
249 lbitset_elt_free (elt
);
253 /* Cut the chain of bitset BSET before element ELT and free the
256 lbitset_prune (bset
, elt
)
267 LBITSET_TAIL (bset
) = elt
->prev
;
268 bset
->b
.cdata
= elt
->prev
->words
;
269 bset
->b
.cindex
= elt
->prev
->index
;
274 LBITSET_HEAD (bset
) = 0;
275 LBITSET_TAIL (bset
) = 0;
280 for (; elt
; elt
= next
)
283 lbitset_elt_free (elt
);
288 /* Return nonzero if all bits in an element are zero. */
290 lbitset_elt_zero_p (elt
)
295 for (i
= 0; i
< LBITSET_ELT_WORDS
; i
++)
303 /* Link the bitset element into the current bitset linked list. */
305 lbitset_elt_link (bset
, elt
)
309 bitset_windex index
= elt
->index
;
311 lbitset_elt
*current
;
314 current
= LBITSET_CURRENT (bset
);
316 current
= LBITSET_HEAD (bset
);
318 /* If this is the first and only element, add it in. */
319 if (LBITSET_HEAD (bset
) == 0)
321 elt
->next
= elt
->prev
= 0;
322 LBITSET_HEAD (bset
) = elt
;
323 LBITSET_TAIL (bset
) = elt
;
326 /* If this index is less than that of the current element, it goes
327 somewhere before the current element. */
328 else if (index
< bset
->b
.cindex
)
331 ptr
->prev
&& ptr
->prev
->index
> index
; ptr
= ptr
->prev
)
335 ptr
->prev
->next
= elt
;
337 LBITSET_HEAD (bset
) = elt
;
339 elt
->prev
= ptr
->prev
;
344 /* Otherwise, it must go somewhere after the current element. */
348 ptr
->next
&& ptr
->next
->index
< index
; ptr
= ptr
->next
)
352 ptr
->next
->prev
= elt
;
354 LBITSET_TAIL (bset
) = elt
;
356 elt
->next
= ptr
->next
;
361 /* Set up so this is the first element searched. */
362 bset
->b
.cindex
= index
;
363 bset
->b
.csize
= LBITSET_ELT_WORDS
;
364 bset
->b
.cdata
= elt
->words
;
369 lbitset_elt_find (bset
, index
, mode
)
372 enum lbitset_find_mode mode
;
375 lbitset_elt
*current
;
379 current
= LBITSET_CURRENT (bset
);
380 /* Check if element is the cached element. */
381 if ((index
- bset
->b
.cindex
) < bset
->b
.csize
)
386 current
= LBITSET_HEAD (bset
);
391 if (index
< bset
->b
.cindex
)
394 elt
->prev
&& elt
->index
> index
; elt
= elt
->prev
)
400 elt
->next
&& (elt
->index
+ LBITSET_ELT_WORDS
- 1) < index
;
405 /* `element' is the nearest to the one we want. If it's not the one
406 we want, the one we want does not exist. */
407 if (elt
&& (index
- elt
->index
) < LBITSET_ELT_WORDS
)
409 bset
->b
.cindex
= elt
->index
;
410 bset
->b
.csize
= LBITSET_ELT_WORDS
;
411 bset
->b
.cdata
= elt
->words
;
422 index
= (index
/ (unsigned) LBITSET_ELT_WORDS
) * LBITSET_ELT_WORDS
;
424 elt
= lbitset_elt_calloc ();
426 lbitset_elt_link (bset
, elt
);
430 return &lbitset_zero_elts
[0];
438 /* Weed out the zero elements from the list. */
446 for (elt
= LBITSET_HEAD (bset
); elt
; elt
= next
)
449 if (lbitset_elt_zero_p (elt
))
450 lbitset_elt_unlink (bset
, elt
);
455 /* Set all bits in the bitset to zero. */
462 head
= LBITSET_HEAD (bset
);
466 /* Clear a bitset by freeing the linked list at the head element. */
467 lbitset_prune (bset
, head
);
472 lbitset_equal_p (dst
, src
)
485 for (selt
= LBITSET_HEAD (src
), delt
= LBITSET_HEAD (dst
);
486 selt
&& delt
; selt
= selt
->next
, delt
= delt
->next
)
488 if (selt
->index
!= delt
->index
)
491 for (j
= 0; j
< LBITSET_ELT_WORDS
; j
++)
492 if (delt
->words
[j
] != selt
->words
[j
])
495 return !selt
&& !delt
;
499 /* Copy bits from bitset SRC to bitset DST. */
501 lbitset_copy (dst
, src
)
515 head
= LBITSET_HEAD (src
);
520 for (elt
= head
; elt
; elt
= elt
->next
)
522 tmp
= lbitset_elt_alloc ();
523 tmp
->index
= elt
->index
;
529 LBITSET_HEAD (dst
) = tmp
;
532 memcpy (tmp
->words
, elt
->words
, sizeof (elt
->words
));
534 LBITSET_TAIL (dst
) = tmp
;
536 dst
->b
.csize
= LBITSET_ELT_WORDS
;
537 dst
->b
.cdata
= LBITSET_HEAD (dst
)->words
;
538 dst
->b
.cindex
= LBITSET_HEAD (dst
)->index
;
542 /* Copy bits from bitset SRC to bitset DST. Return non-zero if
543 bitsets different. */
545 lbitset_copy_compare (dst
, src
)
552 if (!LBITSET_HEAD (dst
))
554 lbitset_copy (dst
, src
);
555 return LBITSET_HEAD (src
) != 0;
558 if (lbitset_equal_p (dst
, src
))
561 lbitset_copy (dst
, src
);
566 /* Return size in bits of bitset SRC. */
573 elt
= LBITSET_TAIL (src
);
577 /* Return current size of bitset in bits. */
578 return (elt
->index
+ LBITSET_ELT_WORDS
) * BITSET_WORD_BITS
;
582 /* Set bit BITNO in bitset DST. */
584 lbitset_set (dst
, bitno
)
588 bitset_windex index
= bitno
/ BITSET_WORD_BITS
;
590 lbitset_elt_find (dst
, index
, LBITSET_CREATE
);
592 dst
->b
.cdata
[index
- dst
->b
.cindex
] |= (1 << (bitno
% BITSET_WORD_BITS
));
596 /* Reset bit BITNO in bitset DST. */
598 lbitset_reset (dst
, bitno
)
602 bitset_windex index
= bitno
/ BITSET_WORD_BITS
;
604 if (!lbitset_elt_find (dst
, index
, LBITSET_FIND
))
607 dst
->b
.cdata
[index
- dst
->b
.cindex
] &= ~(1 << (bitno
% BITSET_WORD_BITS
));
609 /* If all the data is zero, perhaps we should unlink it now... */
613 /* Test bit BITNO in bitset SRC. */
615 lbitset_test (src
, bitno
)
619 bitset_windex index
= bitno
/ BITSET_WORD_BITS
;
621 if (!lbitset_elt_find (src
, index
, LBITSET_FIND
))
625 cdata
[index
- src
->b
.cindex
] >> (bitno
% BITSET_WORD_BITS
)) & 1;
637 /* Find list of up to NUM bits set in BSET starting from and including
638 *NEXT and store in array LIST. Return with actual number of bits
639 found and with *NEXT indicating where search stopped. */
641 lbitset_reverse_list (bset
, list
, num
, next
)
647 bitset_bindex rbitno
;
650 bitset_bindex bitoff
;
655 bitset_bindex n_bits
;
657 elt
= LBITSET_TAIL (bset
);
661 n_bits
= (elt
->index
+ LBITSET_ELT_WORDS
) * BITSET_WORD_BITS
;
664 if (rbitno
>= n_bits
)
667 bitno
= n_bits
- (rbitno
+ 1);
669 index
= bitno
/ BITSET_WORD_BITS
;
671 /* Skip back to starting element. */
672 for (; elt
&& elt
->index
> index
; elt
= elt
->prev
)
678 /* If num is 1, we could speed things up with a binary search
679 of the word of interest. */
682 bitcnt
= bitno
% BITSET_WORD_BITS
;
683 bitoff
= index
* BITSET_WORD_BITS
;
687 bitset_word
*srcp
= elt
->words
;
689 for (; (index
- elt
->index
) < LBITSET_ELT_WORDS
;
690 index
--, bitoff
-= BITSET_WORD_BITS
,
691 bitcnt
= BITSET_WORD_BITS
- 1)
694 srcp
[index
- elt
->index
] << (BITSET_WORD_BITS
- 1 - bitcnt
);
696 for (; word
; bitcnt
--)
698 if (word
& BITSET_MSB
)
700 list
[count
++] = bitoff
+ bitcnt
;
703 *next
= n_bits
- (bitoff
+ bitcnt
);
714 index
= elt
->index
+ LBITSET_ELT_WORDS
- 1;
715 bitoff
= index
* BITSET_WORD_BITS
;
719 *next
= n_bits
- (bitoff
+ 1);
724 /* Find list of up to NUM bits set in BSET starting from and including
725 *NEXT and store in array LIST. Return with actual number of bits
726 found and with *NEXT indicating where search stopped. */
728 lbitset_list (bset
, list
, num
, next
)
741 head
= LBITSET_HEAD (bset
);
750 /* This is the most common case. */
752 /* Start with the first element. */
755 bitno
= index
* BITSET_WORD_BITS
;
759 index
= bitno
/ BITSET_WORD_BITS
;
761 /* Skip to starting element. */
763 elt
&& (elt
->index
+ LBITSET_ELT_WORDS
- 1) < index
;
770 if (index
< elt
->index
)
773 bitno
= index
* BITSET_WORD_BITS
;
777 bitset_word
*srcp
= elt
->words
;
779 /* We are starting within an element. */
781 for (; (index
- elt
->index
) < LBITSET_ELT_WORDS
; index
++)
783 word
= srcp
[index
- elt
->index
] >> (bitno
% BITSET_WORD_BITS
);
785 for (; word
; bitno
++)
789 list
[count
++] = bitno
;
798 bitno
= (index
+ 1) * BITSET_WORD_BITS
;
805 bitno
= index
* BITSET_WORD_BITS
;
811 /* If num is 1, we could speed things up with a binary search
812 of the word of interest. */
817 bitset_word
*srcp
= elt
->words
;
819 if ((count
+ LBITSET_ELT_BITS
) < num
)
821 /* The coast is clear, plant boot! */
823 #if LBITSET_ELT_WORDS == 2
827 if (!(word
& 0xffff))
837 for (; word
; bitno
++)
840 list
[count
++] = bitno
;
845 bitno
= index
* BITSET_WORD_BITS
;
850 if (!(word
& 0xffff))
855 for (; word
; bitno
++)
858 list
[count
++] = bitno
;
863 bitno
= index
* BITSET_WORD_BITS
;
865 for (i
= 0; i
< LBITSET_ELT_WORDS
; i
++)
870 if (!(word
& 0xffff))
880 for (; word
; bitno
++)
883 list
[count
++] = bitno
;
888 bitno
= index
* BITSET_WORD_BITS
;
894 /* Tread more carefully since we need to check
895 if array overflows. */
897 for (i
= 0; i
< LBITSET_ELT_WORDS
; i
++)
899 for (word
= srcp
[i
]; word
; bitno
++)
903 list
[count
++] = bitno
;
913 bitno
= index
* BITSET_WORD_BITS
;
921 bitno
= index
* BITSET_WORD_BITS
;
931 lbitset_op1 (dst
, op
)
946 /* This is a decidedly unfriendly operation for a linked list
948 elt
= LBITSET_TAIL (dst
);
949 /* Ignore empty set. */
954 for (i
= 0; i
< index
; i
+= LBITSET_ELT_WORDS
)
956 /* Create new elements if they cannot be found. */
957 elt
= lbitset_elt_find (dst
, i
, LBITSET_CREATE
);
958 memset (elt
->words
, ~0, sizeof (elt
->words
));
962 case BITSET_OP_EMPTY_P
:
964 if (LBITSET_HEAD (dst
))
977 lbitset_op2 (dst
, src
, op
)
992 lbitset_copy (dst
, src
);
996 /* This is another unfriendly operation for a linked list
998 elt
= LBITSET_TAIL (dst
);
999 /* Ignore empty set. */
1004 for (i
= 0; i
< index
; i
+= LBITSET_ELT_WORDS
)
1006 /* Create new elements for dst if they cannot be found
1007 or substitute zero elements if src elements not found. */
1008 selt
= lbitset_elt_find (dst
, i
, LBITSET_SUBST
);
1009 delt
= lbitset_elt_find (dst
, i
, LBITSET_CREATE
);
1011 for (j
= 0; j
< LBITSET_ELT_WORDS
; j
++)
1012 delt
->words
[j
] = ~selt
->words
[j
];
1017 /* Return 1 if DST == SRC. */
1018 case BITSET_OP_EQUAL_P
:
1019 return lbitset_equal_p (dst
, src
);
1022 /* Return 1 if DST == DST | SRC. */
1023 case BITSET_OP_SUBSET_P
:
1024 for (selt
= LBITSET_HEAD (src
), delt
= LBITSET_HEAD (dst
);
1025 selt
|| delt
; selt
= selt
->next
, delt
= delt
->next
)
1028 selt
= &lbitset_zero_elts
[0];
1030 delt
= &lbitset_zero_elts
[0];
1031 else if (selt
->index
!= delt
->index
)
1033 if (selt
->index
< delt
->index
)
1035 lbitset_zero_elts
[2].next
= delt
;
1036 delt
= &lbitset_zero_elts
[2];
1040 lbitset_zero_elts
[1].next
= selt
;
1041 selt
= &lbitset_zero_elts
[1];
1045 for (j
= 0; j
< LBITSET_ELT_WORDS
; j
++)
1046 if (delt
->words
[j
] != (selt
->words
[j
] | delt
->words
[j
]))
1051 /* Return 1 if DST & SRC == 0. */
1052 case BITSET_OP_DISJOINT_P
:
1053 for (selt
= LBITSET_HEAD (src
), delt
= LBITSET_HEAD (dst
);
1054 selt
&& delt
; selt
= selt
->next
, delt
= delt
->next
)
1056 if (selt
->index
!= delt
->index
)
1058 if (selt
->index
< delt
->index
)
1060 lbitset_zero_elts
[2].next
= delt
;
1061 delt
= &lbitset_zero_elts
[2];
1065 lbitset_zero_elts
[1].next
= selt
;
1066 selt
= &lbitset_zero_elts
[1];
1070 for (j
= 0; j
< LBITSET_ELT_WORDS
; j
++)
1071 if (selt
->words
[j
] & delt
->words
[j
])
1085 lbitset_op3 (dst
, src1
, src2
, op
)
1091 lbitset_elt
*selt1
= LBITSET_HEAD (src1
);
1092 lbitset_elt
*selt2
= LBITSET_HEAD (src2
);
1093 lbitset_elt
*delt
= LBITSET_HEAD (dst
);
1094 bitset_windex index1
;
1095 bitset_windex index2
;
1096 bitset_windex index
;
1106 /* Fast track common, simple cases. */
1109 if (op
== BITSET_OP_AND
)
1112 changed
= !LBITSET_HEAD (dst
);
1116 else if (op
== BITSET_OP_ANDN
|| op
== BITSET_OP_OR
1117 || op
== BITSET_OP_XOR
)
1119 return lbitset_copy_compare (dst
, src1
);
1124 if (op
== BITSET_OP_AND
|| op
== BITSET_OP_ANDN
)
1127 changed
= !LBITSET_HEAD (dst
);
1131 else if (op
== BITSET_OP_OR
|| op
== BITSET_OP_XOR
)
1133 return lbitset_copy_compare (dst
, src2
);
1137 LBITSET_HEAD (dst
) = 0;
1140 index1
= (selt1
) ? selt1
->index
: BITSET_INDEX_MAX
;
1141 index2
= (selt2
) ? selt2
->index
: BITSET_INDEX_MAX
;
1143 while (selt1
|| selt2
)
1145 /* Figure out whether we need to substitute zero elements for
1147 if (index1
== index2
)
1152 selt1
= selt1
->next
;
1153 index1
= (selt1
) ? selt1
->index
: BITSET_INDEX_MAX
;
1154 selt2
= selt2
->next
;
1155 index2
= (selt2
) ? selt2
->index
: BITSET_INDEX_MAX
;
1157 else if (index1
< index2
)
1161 stmp2
= &lbitset_zero_elts
[0];
1162 selt1
= selt1
->next
;
1163 index1
= (selt1
) ? selt1
->index
: BITSET_INDEX_MAX
;
1168 stmp1
= &lbitset_zero_elts
[0];
1170 selt2
= selt2
->next
;
1171 index2
= (selt2
) ? selt2
->index
: BITSET_INDEX_MAX
;
1174 /* Find the appropriate element from DST. Begin by discarding
1175 elements that we've skipped. */
1176 while (delt
&& delt
->index
< index
)
1181 lbitset_elt_free (dtmp
);
1183 if (delt
&& delt
->index
== index
)
1189 dtmp
= lbitset_elt_calloc ();
1191 /* Do the operation, and if any bits are set, link it into the
1193 srcp1
= stmp1
->words
;
1194 srcp2
= stmp2
->words
;
1199 for (i
= 0; i
< LBITSET_ELT_WORDS
; i
++, dstp
++)
1201 bitset_word tmp
= *srcp1
++ | *srcp2
++;
1212 for (i
= 0; i
< LBITSET_ELT_WORDS
; i
++, dstp
++)
1214 bitset_word tmp
= *srcp1
++ & *srcp2
++;
1225 for (i
= 0; i
< LBITSET_ELT_WORDS
; i
++, dstp
++)
1227 bitset_word tmp
= *srcp1
++ ^ *srcp2
++;
1237 case BITSET_OP_ANDN
:
1238 for (i
= 0; i
< LBITSET_ELT_WORDS
; i
++, dstp
++)
1240 bitset_word tmp
= *srcp1
++ & ~(*srcp2
++);
1251 for (i
= 0; i
< LBITSET_ELT_WORDS
; i
++, dstp
++)
1253 bitset_word tmp
= *srcp1
++ | ~(*srcp2
++);
1267 if (!lbitset_elt_zero_p (dtmp
))
1269 dtmp
->index
= index
;
1270 /* Perhaps this could be optimised... */
1271 lbitset_elt_link (dst
, dtmp
);
1275 lbitset_elt_free (dtmp
);
1279 /* If we have elements of DST left over, free them all. */
1283 lbitset_prune (dst
, delt
);
1290 /* Vector of operations for linked-list bitsets. */
1291 struct bitset_ops_struct lbitset_ops
= {
1301 lbitset_reverse_list
,
1307 /* Return size of initial structure. */
1309 lbitset_bytes (n_bits
)
1310 bitset_bindex n_bits ATTRIBUTE_UNUSED
;
1312 return sizeof (struct bitset_struct
);
1316 /* Initialize a bitset. */
1319 lbitset_init (bset
, n_bits
)
1321 bitset_bindex n_bits ATTRIBUTE_UNUSED
;
1323 bset
->b
.ops
= &lbitset_ops
;
1329 lbitset_release_memory ()
1331 lbitset_free_list
= 0;
1332 if (lbitset_obstack_init
)
1334 lbitset_obstack_init
= 0;
1335 obstack_free (&lbitset_obstack
, NULL
);