Skip to content

Commit

Permalink
bitmap: make bitmap_{get,set}_value8() use bitmap_{read,write}()
Browse files Browse the repository at this point in the history
Now that we have generic bitmap_read() and bitmap_write(), which are
inline and try to take care of non-bound-crossing and aligned cases
to keep them optimized, collapse bitmap_{get,set}_value8() into
simple wrappers around the former ones.
bloat-o-meter shows no difference in vmlinux and -2 bytes for
gpio-pca953x.ko, which says the code doesn't get optimized worse.

Suggested-by: Yury Norov <yury.norov@gmail.com>
Signed-off-by: Alexander Lobakin <aleksander.lobakin@intel.com>
  • Loading branch information
alobakin committed Nov 6, 2023
1 parent 154a341 commit 66808fb
Showing 1 changed file with 5 additions and 33 deletions.
38 changes: 5 additions & 33 deletions include/linux/bitmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -572,39 +572,6 @@ static inline void bitmap_from_u64(unsigned long *dst, u64 mask)
bitmap_from_arr64(dst, &mask, 64);
}

/**
* bitmap_get_value8 - get an 8-bit value within a memory region
* @map: address to the bitmap memory region
* @start: bit offset of the 8-bit value; must be a multiple of 8
*
* Returns the 8-bit value located at the @start bit offset within the @src
* memory region.
*/
static inline unsigned long bitmap_get_value8(const unsigned long *map,
unsigned long start)
{
const size_t index = BIT_WORD(start);
const unsigned long offset = start % BITS_PER_LONG;

return (map[index] >> offset) & 0xFF;
}

/**
* bitmap_set_value8 - set an 8-bit value within a memory region
* @map: address to the bitmap memory region
* @value: the 8-bit value; values wider than 8 bits may clobber bitmap
* @start: bit offset of the 8-bit value; must be a multiple of 8
*/
static inline void bitmap_set_value8(unsigned long *map, unsigned long value,
unsigned long start)
{
const size_t index = BIT_WORD(start);
const unsigned long offset = start % BITS_PER_LONG;

map[index] &= ~(0xFFUL << offset);
map[index] |= value << offset;
}

/**
* bitmap_read - read a value of n-bits from the memory region
* @map: address to the bitmap memory region
Expand Down Expand Up @@ -678,6 +645,11 @@ static inline void bitmap_write(unsigned long *map, unsigned long value,
map[index + 1] |= (value >> space);
}

#define bitmap_get_value8(map, start) \
bitmap_read(map, start, BITS_PER_BYTE)
#define bitmap_set_value8(map, value, start) \
bitmap_write(map, value, start, BITS_PER_BYTE)

#endif /* __ASSEMBLY__ */

#endif /* __LINUX_BITMAP_H */

0 comments on commit 66808fb

Please sign in to comment.