~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/lib/bitmap.c

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /tools/lib/bitmap.c (Version linux-6.12-rc7) and /tools/lib/bitmap.c (Version linux-5.10.229)


  1 // SPDX-License-Identifier: GPL-2.0-only            1 // SPDX-License-Identifier: GPL-2.0-only
  2 /*                                                  2 /*
  3  * From lib/bitmap.c                                3  * From lib/bitmap.c
  4  * Helper functions for bitmap.h.                   4  * Helper functions for bitmap.h.
  5  */                                                 5  */
  6 #include <linux/bitmap.h>                           6 #include <linux/bitmap.h>
  7                                                     7 
  8 unsigned int __bitmap_weight(const unsigned lo !!   8 int __bitmap_weight(const unsigned long *bitmap, int bits)
  9 {                                                   9 {
 10         unsigned int k, w = 0, lim = bits/BITS !!  10         int k, w = 0, lim = bits/BITS_PER_LONG;
 11                                                    11 
 12         for (k = 0; k < lim; k++)                  12         for (k = 0; k < lim; k++)
 13                 w += hweight_long(bitmap[k]);      13                 w += hweight_long(bitmap[k]);
 14                                                    14 
 15         if (bits % BITS_PER_LONG)                  15         if (bits % BITS_PER_LONG)
 16                 w += hweight_long(bitmap[k] &      16                 w += hweight_long(bitmap[k] & BITMAP_LAST_WORD_MASK(bits));
 17                                                    17 
 18         return w;                                  18         return w;
 19 }                                                  19 }
 20                                                    20 
 21 void __bitmap_or(unsigned long *dst, const uns     21 void __bitmap_or(unsigned long *dst, const unsigned long *bitmap1,
 22                  const unsigned long *bitmap2,     22                  const unsigned long *bitmap2, int bits)
 23 {                                                  23 {
 24         int k;                                     24         int k;
 25         int nr = BITS_TO_LONGS(bits);              25         int nr = BITS_TO_LONGS(bits);
 26                                                    26 
 27         for (k = 0; k < nr; k++)                   27         for (k = 0; k < nr; k++)
 28                 dst[k] = bitmap1[k] | bitmap2[     28                 dst[k] = bitmap1[k] | bitmap2[k];
 29 }                                                  29 }
 30                                                    30 
 31 size_t bitmap_scnprintf(unsigned long *bitmap, !!  31 size_t bitmap_scnprintf(unsigned long *bitmap, int nbits,
 32                         char *buf, size_t size     32                         char *buf, size_t size)
 33 {                                                  33 {
 34         /* current bit is 'cur', most recently     34         /* current bit is 'cur', most recently seen range is [rbot, rtop] */
 35         unsigned int cur, rbot, rtop;          !!  35         int cur, rbot, rtop;
 36         bool first = true;                         36         bool first = true;
 37         size_t ret = 0;                            37         size_t ret = 0;
 38                                                    38 
 39         rbot = cur = find_first_bit(bitmap, nb     39         rbot = cur = find_first_bit(bitmap, nbits);
 40         while (cur < nbits) {                      40         while (cur < nbits) {
 41                 rtop = cur;                        41                 rtop = cur;
 42                 cur = find_next_bit(bitmap, nb     42                 cur = find_next_bit(bitmap, nbits, cur + 1);
 43                 if (cur < nbits && cur <= rtop     43                 if (cur < nbits && cur <= rtop + 1)
 44                         continue;                  44                         continue;
 45                                                    45 
 46                 if (!first)                        46                 if (!first)
 47                         ret += scnprintf(buf +     47                         ret += scnprintf(buf + ret, size - ret, ",");
 48                                                    48 
 49                 first = false;                     49                 first = false;
 50                                                    50 
 51                 ret += scnprintf(buf + ret, si     51                 ret += scnprintf(buf + ret, size - ret, "%d", rbot);
 52                 if (rbot < rtop)                   52                 if (rbot < rtop)
 53                         ret += scnprintf(buf +     53                         ret += scnprintf(buf + ret, size - ret, "-%d", rtop);
 54                                                    54 
 55                 rbot = cur;                        55                 rbot = cur;
 56         }                                          56         }
 57         return ret;                                57         return ret;
 58 }                                                  58 }
 59                                                    59 
 60 bool __bitmap_and(unsigned long *dst, const un !!  60 int __bitmap_and(unsigned long *dst, const unsigned long *bitmap1,
 61                  const unsigned long *bitmap2,     61                  const unsigned long *bitmap2, unsigned int bits)
 62 {                                                  62 {
 63         unsigned int k;                            63         unsigned int k;
 64         unsigned int lim = bits/BITS_PER_LONG;     64         unsigned int lim = bits/BITS_PER_LONG;
 65         unsigned long result = 0;                  65         unsigned long result = 0;
 66                                                    66 
 67         for (k = 0; k < lim; k++)                  67         for (k = 0; k < lim; k++)
 68                 result |= (dst[k] = bitmap1[k]     68                 result |= (dst[k] = bitmap1[k] & bitmap2[k]);
 69         if (bits % BITS_PER_LONG)                  69         if (bits % BITS_PER_LONG)
 70                 result |= (dst[k] = bitmap1[k]     70                 result |= (dst[k] = bitmap1[k] & bitmap2[k] &
 71                            BITMAP_LAST_WORD_MA     71                            BITMAP_LAST_WORD_MASK(bits));
 72         return result != 0;                        72         return result != 0;
 73 }                                                  73 }
 74                                                    74 
 75 bool __bitmap_equal(const unsigned long *bitma !!  75 int __bitmap_equal(const unsigned long *bitmap1,
 76                     const unsigned long *bitma !!  76                 const unsigned long *bitmap2, unsigned int bits)
 77 {                                                  77 {
 78         unsigned int k, lim = bits/BITS_PER_LO     78         unsigned int k, lim = bits/BITS_PER_LONG;
 79         for (k = 0; k < lim; ++k)                  79         for (k = 0; k < lim; ++k)
 80                 if (bitmap1[k] != bitmap2[k])      80                 if (bitmap1[k] != bitmap2[k])
 81                         return false;          !!  81                         return 0;
 82                                                    82 
 83         if (bits % BITS_PER_LONG)                  83         if (bits % BITS_PER_LONG)
 84                 if ((bitmap1[k] ^ bitmap2[k])      84                 if ((bitmap1[k] ^ bitmap2[k]) & BITMAP_LAST_WORD_MASK(bits))
 85                         return false;          !!  85                         return 0;
 86                                                    86 
 87         return true;                           !!  87         return 1;
 88 }                                              << 
 89                                                << 
 90 bool __bitmap_intersects(const unsigned long * << 
 91                          const unsigned long * << 
 92 {                                              << 
 93         unsigned int k, lim = bits/BITS_PER_LO << 
 94         for (k = 0; k < lim; ++k)              << 
 95                 if (bitmap1[k] & bitmap2[k])   << 
 96                         return true;           << 
 97                                                << 
 98         if (bits % BITS_PER_LONG)              << 
 99                 if ((bitmap1[k] & bitmap2[k])  << 
100                         return true;           << 
101         return false;                          << 
102 }                                              << 
103                                                << 
104 void __bitmap_clear(unsigned long *map, unsign << 
105 {                                              << 
106         unsigned long *p = map + BIT_WORD(star << 
107         const unsigned int size = start + len; << 
108         int bits_to_clear = BITS_PER_LONG - (s << 
109         unsigned long mask_to_clear = BITMAP_F << 
110                                                << 
111         while (len - bits_to_clear >= 0) {     << 
112                 *p &= ~mask_to_clear;          << 
113                 len -= bits_to_clear;          << 
114                 bits_to_clear = BITS_PER_LONG; << 
115                 mask_to_clear = ~0UL;          << 
116                 p++;                           << 
117         }                                      << 
118         if (len) {                             << 
119                 mask_to_clear &= BITMAP_LAST_W << 
120                 *p &= ~mask_to_clear;          << 
121         }                                      << 
122 }                                                  88 }
123                                                    89 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php