From patchwork Fri Sep 11 13:19:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zhang X-Patchwork-Id: 77398 Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 1708AA04B7; Fri, 11 Sep 2020 15:18:10 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 13E8B1C19C; Fri, 11 Sep 2020 15:16:23 +0200 (CEST) Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by dpdk.org (Postfix) with ESMTP id E396A1C114 for ; Fri, 11 Sep 2020 15:16:16 +0200 (CEST) IronPort-SDR: uwBK/YH8zb56QFlsl02yeExQadWi80E4gtpIjkwfoOSGjc9iGEbeDWsXqbPjO6ao5F6wKDUXfr 8vp888gaG/zA== X-IronPort-AV: E=McAfee;i="6000,8403,9740"; a="146482185" X-IronPort-AV: E=Sophos;i="5.76,415,1592895600"; d="scan'208";a="146482185" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Sep 2020 06:16:16 -0700 IronPort-SDR: AA4B6Xg+1ZsiVJIGv3oLAn+EpgjhEDOAZM0+HzKQ1GR/xo8GZ4kgsg0EKxSqUeNqrpCwNzjOFZ wNxUpI8IWXaQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.76,415,1592895600"; d="scan'208";a="342296535" Received: from dpdk51.sh.intel.com ([10.67.111.82]) by FMSMGA003.fm.intel.com with ESMTP; 11 Sep 2020 06:16:15 -0700 From: Qi Zhang To: ferruh.yigit@intel.com Cc: dev@dpdk.org, Qi Zhang , Bruce Allan Date: Fri, 11 Sep 2020 21:19:25 +0800 Message-Id: <20200911131954.15999-12-qi.z.zhang@intel.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20200911131954.15999-1-qi.z.zhang@intel.com> References: <20200907112826.48493-1-qi.z.zhang@intel.com> <20200911131954.15999-1-qi.z.zhang@intel.com> Subject: [dpdk-dev] [PATCH v2 11/40] net/ice/base: introduce and use bitmap hamming weight API X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Introduce ice_bitmap_hweight() and use it instead of open-coding that functionality. Signed-off-by: Bruce Allan Signed-off-by: Qi Zhang Acked-by: Qiming Yang --- drivers/net/ice/base/ice_bitops.h | 23 +++++++++++++++++++++++ drivers/net/ice/base/ice_switch.c | 11 +---------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/drivers/net/ice/base/ice_bitops.h b/drivers/net/ice/base/ice_bitops.h index 8352b5dd7..a56d55455 100644 --- a/drivers/net/ice/base/ice_bitops.h +++ b/drivers/net/ice/base/ice_bitops.h @@ -395,6 +395,29 @@ ice_bitmap_set(ice_bitmap_t *dst, u16 pos, u16 num_bits) } /** + * ice_bitmap_hweight - hamming weight of bitmap + * @bm: bitmap pointer + * @size: size of bitmap (in bits) + * + * This function determines the number of set bits in a bitmap. + * Note that this function assumes it is operating on a bitmap declared using + * ice_declare_bitmap. + */ +static inline int +ice_bitmap_hweight(ice_bitmap_t *bm, u16 size) +{ + int count = 0; + u16 bit = 0; + + while (size > (bit = ice_find_next_bit(bm, size, bit))) { + count++; + bit++; + } + + return count; +} + +/** * ice_cmp_bitmaps - compares two bitmaps. * @bmp1: the bitmap to compare * @bmp2: the bitmap to compare with bmp1 diff --git a/drivers/net/ice/base/ice_switch.c b/drivers/net/ice/base/ice_switch.c index 41ebfedc6..ecb411714 100644 --- a/drivers/net/ice/base/ice_switch.c +++ b/drivers/net/ice/base/ice_switch.c @@ -5932,7 +5932,6 @@ ice_find_free_recp_res_idx(struct ice_hw *hw, const ice_bitmap_t *profiles, ice_declare_bitmap(possible_idx, ICE_MAX_FV_WORDS); ice_declare_bitmap(recipes, ICE_MAX_NUM_RECIPES); ice_declare_bitmap(used_idx, ICE_MAX_FV_WORDS); - u16 count = 0; u16 bit; ice_zero_bitmap(possible_idx, ICE_MAX_FV_WORDS); @@ -5971,15 +5970,7 @@ ice_find_free_recp_res_idx(struct ice_hw *hw, const ice_bitmap_t *profiles, ice_xor_bitmap(free_idx, used_idx, possible_idx, ICE_MAX_FV_WORDS); /* return number of free indexes */ - count = 0; - bit = 0; - while (ICE_MAX_FV_WORDS > - (bit = ice_find_next_bit(free_idx, ICE_MAX_FV_WORDS, bit))) { - count++; - bit++; - } - - return count; + return (u16)ice_bitmap_hweight(free_idx, ICE_MAX_FV_WORDS); } /**