- u_long count;
- int i;
- boolean_t is_set;
- bitmap_offset_t start;
- bitmap_offset_t end;
-
- start = bitmap_offset(start_bit);
- end = bitmap_offset(start_bit + bit_count);
-
- is_set = (map[start.byte] & bit(start.bit)) ? TRUE : FALSE;
- count = 0;
-
- if (start.byte < end.byte) {
- u_long n_bytes;
-
- if (start.bit) { /* try to align to a byte */
- for (i = start.bit; i < NBBY; i++) {
- boolean_t this_is_set;
+ uint32_t count;
+ int i;
+ boolean_t is_set;
+ bitmap_offset_t start;
+ bitmap_offset_t end;
+
+ start = bitmap_offset(start_bit);
+ end = bitmap_offset(start_bit + bit_count);
+
+ is_set = (map[start.byte] & bit(start.bit)) ? TRUE : FALSE;
+ count = 0;
+
+ if (start.byte < end.byte) {
+ uint64_t n_bytes;
+
+ if (start.bit) { /* try to align to a byte */
+ for (i = start.bit; i < NBBY; i++) {
+ boolean_t this_is_set;
+
+ this_is_set = (map[start.byte] & bit(i)) ? TRUE : FALSE;
+ if (this_is_set != is_set) {
+ goto done; /* found bit that was different, we're done */
+ }
+ count++;
+ }
+ start.bit = 0; /* made it to the next byte */
+ start.byte++;
+ if (start.byte == end.byte) {
+ goto end; /* no more bytes, check for any leftover bits */
+ }
+ }
+ /* calculate how many bytes are left in the range */
+ n_bytes = end.byte - start.byte;
+
+ /* check for 4 bytes of the same bits */
+ while (n_bytes >= sizeof(uint32_t)) {
+ uint32_t * valPtr = (uint32_t *)(map + start.byte);
+ if ((is_set && *valPtr == UINT32_ALL_ONES)
+ || (!is_set && *valPtr == 0)) {
+ count += sizeof(*valPtr) * NBBY;
+ start.byte += sizeof(*valPtr);
+ n_bytes -= sizeof(*valPtr);
+ } else {
+ break; /* bits differ */
+ }
+ }
+ /* check for 2 bytes of the same bits */
+ if (n_bytes >= sizeof(u_short)) {
+ u_short * valPtr = (u_short *)(map + start.byte);
+
+ if ((is_set && *valPtr == USHORT_ALL_ONES)
+ || (!is_set && (*valPtr == 0))) {
+ count += sizeof(*valPtr) * NBBY;
+ start.byte += sizeof(*valPtr);
+ n_bytes -= sizeof(*valPtr);
+ }
+ }