+#define SBITMAP_SET_SIZE(N) (((N) + SBITMAP_ELT_BITS - 1) / SBITMAP_ELT_BITS)
+#define SBITMAP_SIZE_BYTES(BITMAP) ((BITMAP)->size * sizeof (SBITMAP_ELT_TYPE))
+
+/* Test if bit number bitno in the bitmap is set. */
+#define TEST_BIT(BITMAP, BITNO) \
+((BITMAP)->elms [(BITNO) / SBITMAP_ELT_BITS] >> (BITNO) % SBITMAP_ELT_BITS & 1)
+
+/* Set bit number BITNO in the sbitmap MAP. Updates population count
+ if this bitmap has one. */
+
+static inline void
+SET_BIT (sbitmap map, unsigned int bitno)
+{
+ if (map->popcount)
+ {
+ bool oldbit;
+ oldbit = TEST_BIT (map, bitno);
+ if (!oldbit)
+ map->popcount[bitno / SBITMAP_ELT_BITS]++;
+ }
+ map->elms[bitno / SBITMAP_ELT_BITS]
+ |= (SBITMAP_ELT_TYPE) 1 << (bitno) % SBITMAP_ELT_BITS;
+}
+
+
+
+/* Reset bit number BITNO in the sbitmap MAP. Updates population
+ count if this bitmap has one. */
+
+static inline void
+RESET_BIT (sbitmap map, unsigned int bitno)
+{
+ if (map->popcount)
+ {
+ bool oldbit;
+ oldbit = TEST_BIT (map, bitno);
+ if (oldbit)
+ map->popcount[bitno / SBITMAP_ELT_BITS]--;
+ }
+ map->elms[bitno / SBITMAP_ELT_BITS]
+ &= ~((SBITMAP_ELT_TYPE) 1 << (bitno) % SBITMAP_ELT_BITS);
+}
+
+/* The iterator for sbitmap. */
+typedef struct {
+ /* The pointer to the first word of the bitmap. */
+ const SBITMAP_ELT_TYPE *ptr;
+
+ /* The size of the bitmap. */
+ unsigned int size;
+
+ /* The current word index. */
+ unsigned int word_num;
+
+ /* The current bit index (not modulo SBITMAP_ELT_BITS). */
+ unsigned int bit_num;
+
+ /* The words currently visited. */
+ SBITMAP_ELT_TYPE word;
+} sbitmap_iterator;
+
+/* Initialize the iterator I with sbitmap BMP and the initial index
+ MIN. */
+
+static inline void
+sbitmap_iter_init (sbitmap_iterator *i, const_sbitmap bmp, unsigned int min)
+{
+ i->word_num = min / (unsigned int) SBITMAP_ELT_BITS;
+ i->bit_num = min;
+ i->size = bmp->size;
+ i->ptr = bmp->elms;