diff mbox series

[v2,09/13] bitmap: make bitmap_{get,set}_value8() use bitmap_{read,write}()

Message ID 20231016165247.14212-10-aleksander.lobakin@intel.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series ip_tunnel: convert __be16 tunnel flags to bitmaps | expand

Checks

Context Check Description
bpf/vmtest-bpf-PR fail merge-conflict
netdev/tree_selection success Guessing tree name failed - patch did not apply, async

Commit Message

Alexander Lobakin Oct. 16, 2023, 4:52 p.m. UTC
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>
---
 include/linux/bitmap.h | 38 +++++---------------------------------
 1 file changed, 5 insertions(+), 33 deletions(-)

Comments

Yury Norov Oct. 16, 2023, 5:48 p.m. UTC | #1
On Mon, Oct 16, 2023 at 06:52:43PM +0200, Alexander Lobakin wrote:
> 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.

That's just amazing!

bloat-o-meter itself doesn't say on optimization, but in this case
I think that BITS_PER_BYTE passed at compile time allows to generate
just as good code with the generic bitmap_write/read().

Acked-by: Yury Norov <yury.norov@gmail.com>

> Suggested-by: Yury Norov <yury.norov@gmail.com>
> Signed-off-by: Alexander Lobakin <aleksander.lobakin@intel.com>
> ---
>  include/linux/bitmap.h | 38 +++++---------------------------------
>  1 file changed, 5 insertions(+), 33 deletions(-)
> 
> diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h
> index 2020cb534ed7..c2680f67bc4e 100644
> --- a/include/linux/bitmap.h
> +++ b/include/linux/bitmap.h
> @@ -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
> @@ -676,6 +643,11 @@ static inline void bitmap_write(unsigned long *map,
>  	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 */
> -- 
> 2.41.0
diff mbox series

Patch

diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h
index 2020cb534ed7..c2680f67bc4e 100644
--- a/include/linux/bitmap.h
+++ b/include/linux/bitmap.h
@@ -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
@@ -676,6 +643,11 @@  static inline void bitmap_write(unsigned long *map,
 	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 */