/* Count the number of contiguous bits set in the bitmap starting with bit start_bit. Size is the size of the bitmap in words.  */
int xfs_contig_bits(uint *map, uint size, uint start_bit)
/* Count the number of contiguous bits set in the bitmap starting with bit start_bit. Size is the size of the bitmap in words.  */
int xfs_contig_bits(uint *map, uint size, uint start_bit)
{
	uint * p = ((unsigned int *) map) + (start_bit >> BIT_TO_WORD_SHIFT);
	uint result = 0;
	uint tmp;
	size <<= BIT_TO_WORD_SHIFT;
	ASSERT(start_bit < size);
	size -= start_bit & ~(NBWORD - 1);
	start_bit &= (NBWORD - 1);
	if (start_bit) {
		tmp = *p++;
		tmp |= (~0U >> (NBWORD-start_bit));
		if (tmp != ~0U)
			goto found;
		result += NBWORD;
		size -= NBWORD;
	}
	while (size) {
		if ((tmp = *p++) != ~0U)
			goto found;
		result += NBWORD;
		size -= NBWORD;
	}
	return result - start_bit;
found:
	return result + ffz(tmp) - start_bit;
}