lib/bitmap: Introduce bitmap_scatter() and bitmap_gather() helpers
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Thu, 7 Mar 2024 11:39:06 +0000 (12:39 +0100)
committerDavid S. Miller <davem@davemloft.net>
Mon, 11 Mar 2024 09:36:11 +0000 (09:36 +0000)
commitde5f84338970815b9fdd3497a975fb572d11e0b5
treef1f9f5775bfe78fe22d2403e6ba31044f1261ce2
parent796992282cb046939cbbcbd0051e804095304fa4
lib/bitmap: Introduce bitmap_scatter() and bitmap_gather() helpers

These helpers scatters or gathers a bitmap with the help of the mask
position bits parameter.

bitmap_scatter() does the following:
  src:  0000000001011010
                  ||||||
           +------+|||||
           |  +----+||||
           |  |+----+|||
           |  ||   +-+||
           |  ||   |  ||
  mask: ...v..vv...v..vv
        ...0..11...0..10
  dst:  0000001100000010

and bitmap_gather() performs this one:
   mask: ...v..vv...v..vv
   src:  0000001100000010
            ^  ^^   ^   0
            |  ||   |  10
            |  ||   > 010
            |  |+--> 1010
            |  +--> 11010
            +----> 011010
   dst:  0000000000011010

bitmap_gather() can the seen as the reverse bitmap_scatter() operation.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/lkml/20230926052007.3917389-3-andriy.shevchenko@linux.intel.com/
Co-developed-by: Herve Codina <herve.codina@bootlin.com>
Signed-off-by: Herve Codina <herve.codina@bootlin.com>
Acked-by: Yury Norov <yury.norov@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/linux/bitmap.h
lib/test_bitmap.c