[PATCH 2/3] ice: use bitmap_weighted_xor() in ice_find_free_recp_res_idx()

Yury Norov (NVIDIA) posted 3 patches 1 month, 2 weeks ago
[PATCH 2/3] ice: use bitmap_weighted_xor() in ice_find_free_recp_res_idx()
Posted by Yury Norov (NVIDIA) 1 month, 2 weeks ago
Use the right helper and save one bitmaps traverse. 

Signed-off-by: Yury Norov (NVIDIA) <yury.norov@gmail.com>
---
 drivers/net/ethernet/intel/ice/ice_switch.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/intel/ice/ice_switch.c b/drivers/net/ethernet/intel/ice/ice_switch.c
index 84848f0123e7..903417477929 100644
--- a/drivers/net/ethernet/intel/ice/ice_switch.c
+++ b/drivers/net/ethernet/intel/ice/ice_switch.c
@@ -4984,10 +4984,8 @@ ice_find_free_recp_res_idx(struct ice_hw *hw, const unsigned long *profiles,
 			  hw->switch_info->recp_list[bit].res_idxs,
 			  ICE_MAX_FV_WORDS);
 
-	bitmap_xor(free_idx, used_idx, possible_idx, ICE_MAX_FV_WORDS);
-
 	/* return number of free indexes */
-	return (u16)bitmap_weight(free_idx, ICE_MAX_FV_WORDS);
+	return (u16)bitmap_weighted_xor(free_idx, used_idx, possible_idx, ICE_MAX_FV_WORDS);
 }
 
 /**
-- 
2.43.0
Re: [PATCH 2/3] ice: use bitmap_weighted_xor() in ice_find_free_recp_res_idx()
Posted by David Laight 1 month, 2 weeks ago
On Tue, 23 Dec 2025 11:23:01 -0500
"Yury Norov (NVIDIA)" <yury.norov@gmail.com> wrote:

> Use the right helper and save one bitmaps traverse. 

It makes no difference here.
The bitmap has 48 entries and is just a single 'long' on 64bit.
It is also already in a very slow path that has iterated all the
'set' bit of two bitmaps.

The code is also pretty convoluted and confusing already.
One of the other bitmaps has 64 entries, recoding using u64 would
make it a bit more readable.

Doing the 'weight' here is also just optimising for failure.

Oh, and using u8 and u16 for function parameters, return values and
maths requires extra instructions and is usually a bad idea.

	Dvaid

> 
> Signed-off-by: Yury Norov (NVIDIA) <yury.norov@gmail.com>
> ---
>  drivers/net/ethernet/intel/ice/ice_switch.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/drivers/net/ethernet/intel/ice/ice_switch.c b/drivers/net/ethernet/intel/ice/ice_switch.c
> index 84848f0123e7..903417477929 100644
> --- a/drivers/net/ethernet/intel/ice/ice_switch.c
> +++ b/drivers/net/ethernet/intel/ice/ice_switch.c
> @@ -4984,10 +4984,8 @@ ice_find_free_recp_res_idx(struct ice_hw *hw, const unsigned long *profiles,
>  			  hw->switch_info->recp_list[bit].res_idxs,
>  			  ICE_MAX_FV_WORDS);
>  
> -	bitmap_xor(free_idx, used_idx, possible_idx, ICE_MAX_FV_WORDS);
> -
>  	/* return number of free indexes */
> -	return (u16)bitmap_weight(free_idx, ICE_MAX_FV_WORDS);
> +	return (u16)bitmap_weighted_xor(free_idx, used_idx, possible_idx, ICE_MAX_FV_WORDS);
>  }
>  
>  /**