]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/kern/bits.h
xnu-7195.101.1.tar.gz
[apple/xnu.git] / osfmk / kern / bits.h
index 89012eb5a2be5eaa1fa2dc681e360ba005428015..045ed96217f18ec6ee1d41285d87e1dccab03930 100644 (file)
@@ -312,9 +312,17 @@ bitmap_first(bitmap_t *map, uint nbits)
 inline static void
 bitmap_not(bitmap_t *out, const bitmap_t *in, uint nbits)
 {
-       for (uint i = 0; i <= bitmap_index(nbits - 1); i++) {
+       uint i;
+
+       for (i = 0; i < bitmap_index(nbits - 1); i++) {
                out[i] = ~in[i];
        }
+
+       uint nbits_complete = i * 64;
+
+       if (nbits > nbits_complete) {
+               out[i] = ~in[i] & mask(nbits - nbits_complete);
+       }
 }
 
 inline static void
@@ -328,9 +336,17 @@ bitmap_and(bitmap_t *out, const bitmap_t *in1, const bitmap_t *in2, uint nbits)
 inline static void
 bitmap_and_not(bitmap_t *out, const bitmap_t *in1, const bitmap_t *in2, uint nbits)
 {
-       for (uint i = 0; i <= bitmap_index(nbits - 1); i++) {
+       uint i;
+
+       for (i = 0; i < bitmap_index(nbits - 1); i++) {
                out[i] = in1[i] & ~in2[i];
        }
+
+       uint nbits_complete = i * 64;
+
+       if (nbits > nbits_complete) {
+               out[i] = (in1[i] & ~in2[i]) & mask(nbits - nbits_complete);
+       }
 }
 
 inline static bool