aboutsummaryrefslogtreecommitdiffstats
path: root/lib/bitmap.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/bitmap.c')
-rw-r--r--lib/bitmap.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/lib/bitmap.c b/lib/bitmap.c
index d8f0c094b18e..47fe6441562c 100644
--- a/lib/bitmap.c
+++ b/lib/bitmap.c
@@ -1214,3 +1214,59 @@ void bitmap_copy_le(unsigned long *dst, const unsigned long *src, unsigned int n
1214} 1214}
1215EXPORT_SYMBOL(bitmap_copy_le); 1215EXPORT_SYMBOL(bitmap_copy_le);
1216#endif 1216#endif
1217
1218#if BITS_PER_LONG == 64
1219/**
1220 * bitmap_from_arr32 - copy the contents of u32 array of bits to bitmap
1221 * @bitmap: array of unsigned longs, the destination bitmap
1222 * @buf: array of u32 (in host byte order), the source bitmap
1223 * @nbits: number of bits in @bitmap
1224 */
1225void bitmap_from_arr32(unsigned long *bitmap, const u32 *buf,
1226 unsigned int nbits)
1227{
1228 unsigned int i, halfwords;
1229
1230 if (!nbits)
1231 return;
1232
1233 halfwords = DIV_ROUND_UP(nbits, 32);
1234 for (i = 0; i < halfwords; i++) {
1235 bitmap[i/2] = (unsigned long) buf[i];
1236 if (++i < halfwords)
1237 bitmap[i/2] |= ((unsigned long) buf[i]) << 32;
1238 }
1239
1240 /* Clear tail bits in last word beyond nbits. */
1241 if (nbits % BITS_PER_LONG)
1242 bitmap[(halfwords - 1) / 2] &= BITMAP_LAST_WORD_MASK(nbits);
1243}
1244EXPORT_SYMBOL(bitmap_from_arr32);
1245
1246/**
1247 * bitmap_to_arr32 - copy the contents of bitmap to a u32 array of bits
1248 * @buf: array of u32 (in host byte order), the dest bitmap
1249 * @bitmap: array of unsigned longs, the source bitmap
1250 * @nbits: number of bits in @bitmap
1251 */
1252void bitmap_to_arr32(u32 *buf, const unsigned long *bitmap, unsigned int nbits)
1253{
1254 unsigned int i, halfwords;
1255
1256 if (!nbits)
1257 return;
1258
1259 halfwords = DIV_ROUND_UP(nbits, 32);
1260 for (i = 0; i < halfwords; i++) {
1261 buf[i] = (u32) (bitmap[i/2] & UINT_MAX);
1262 if (++i < halfwords)
1263 buf[i] = (u32) (bitmap[i/2] >> 32);
1264 }
1265
1266 /* Clear tail bits in last element of array beyond nbits. */
1267 if (nbits % BITS_PER_LONG)
1268 buf[halfwords - 1] &= (u32) (UINT_MAX >> ((-nbits) & 31));
1269}
1270EXPORT_SYMBOL(bitmap_to_arr32);
1271
1272#endif