From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.tuxdriver.com (charlotte.tuxdriver.com [70.61.120.58]) by dpdk.org (Postfix) with ESMTP id ADE8F6896 for ; Sat, 13 Dec 2014 11:39:35 +0100 (CET) Received: from rrcs-70-60-224-114.midsouth.biz.rr.com ([70.60.224.114] helo=localhost) by smtp.tuxdriver.com with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.63) (envelope-from ) id 1Xzk6c-0000et-PL; Sat, 13 Dec 2014 05:39:25 -0500 Date: Sat, 13 Dec 2014 05:39:21 -0500 From: Neil Horman To: r k Message-ID: <20141213103921.GA1162@localhost.localdomain> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) X-Spam-Score: -2.9 (--) X-Spam-Status: No Cc: "dev@dpdk.org" Subject: Re: [dpdk-dev] [PATCH] Minor fixes in rte_common.h file. X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 13 Dec 2014 10:39:36 -0000 On Fri, Dec 12, 2014 at 03:04:34PM -0800, r k wrote: > Subject: [PATCH] Minor fixes in rte_common.h file. > > Fix rte_is_power_of_2 since 0 is not. > Avoid branching instructions in RTE_MAX and RTE_MIN. > > Signed-off-by: Ravi Kerur > --- > lib/librte_eal/common/include/rte_common.h | 6 +++--- > lib/librte_pmd_e1000/igb_pf.c | 4 ++-- > lib/librte_pmd_ixgbe/ixgbe_pf.c | 4 ++-- > 3 files changed, 7 insertions(+), 7 deletions(-) > > diff --git a/lib/librte_eal/common/include/rte_common.h > b/lib/librte_eal/common/include/rte_common.h > index 921b91f..e163f35 100644 > --- a/lib/librte_eal/common/include/rte_common.h > +++ b/lib/librte_eal/common/include/rte_common.h > @@ -203,7 +203,7 @@ extern int RTE_BUILD_BUG_ON_detected_error; static > inline int rte_is_power_of_2(uint32_t n) { > - return ((n-1) & n) == 0; > + return n && !(n & (n - 1)); > } > > /** > @@ -259,7 +259,7 @@ rte_align64pow2(uint64_t v) #define RTE_MIN(a, b) ({ \ > typeof (a) _a = (a); \ > typeof (b) _b = (b); \ > - _a < _b ? _a : _b; \ > + _b ^ ((_a ^ _b) & -(_a < _b)); \ Are you sure this is actually faster than the branch version? What about using a cmov instead? > }) > > /** > @@ -268,7 +268,7 @@ rte_align64pow2(uint64_t v) #define RTE_MAX(a, b) ({ \ > typeof (a) _a = (a); \ > typeof (b) _b = (b); \ > - _a > _b ? _a : _b; \ > + _a ^ ((_a ^ _b) & -(_a < _b)); \ Same as above > }) > > /*********** Other general functions / macros ********/ diff --git > a/lib/librte_pmd_e1000/igb_pf.c b/lib/librte_pmd_e1000/igb_pf.c index > bc3816a..546499c 100644 > --- a/lib/librte_pmd_e1000/igb_pf.c > +++ b/lib/librte_pmd_e1000/igb_pf.c > @@ -321,11 +321,11 @@ igb_vf_set_mac_addr(struct rte_eth_dev *dev, uint32_t > vf, uint32_t *msgbuf) static int igb_vf_set_multicast(struct rte_eth_dev > *dev, __rte_unused uint32_t vf, uint32_t *msgbuf) { > - int i; > + int16_t i; > uint32_t vector_bit; > uint32_t vector_reg; > uint32_t mta_reg; > - int entries = (msgbuf[0] & E1000_VT_MSGINFO_MASK) >> > + int32_t entries = (msgbuf[0] & E1000_VT_MSGINFO_MASK) >> > E1000_VT_MSGINFO_SHIFT; NAK, this has nothing to do with the included changelog > uint16_t *hash_list = (uint16_t *)&msgbuf[1]; > struct e1000_hw *hw = > E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private); > diff --git a/lib/librte_pmd_ixgbe/ixgbe_pf.c > b/lib/librte_pmd_ixgbe/ixgbe_pf.c index 51da1fd..426caf9 100644 > --- a/lib/librte_pmd_ixgbe/ixgbe_pf.c > +++ b/lib/librte_pmd_ixgbe/ixgbe_pf.c > @@ -390,7 +390,7 @@ ixgbe_vf_set_multicast(struct rte_eth_dev *dev, > __rte_unused uint32_t vf, uint32 > struct ixgbe_hw *hw = > IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private); > struct ixgbe_vf_info *vfinfo = > *(IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private)); > - int nb_entries = (msgbuf[0] & IXGBE_VT_MSGINFO_MASK) >> > + int32_t nb_entries = (msgbuf[0] & IXGBE_VT_MSGINFO_MASK) >> > IXGBE_VT_MSGINFO_SHIFT; ditto > uint16_t *hash_list = (uint16_t *)&msgbuf[1]; > uint32_t mta_idx; > @@ -399,7 +399,7 @@ ixgbe_vf_set_multicast(struct rte_eth_dev *dev, > __rte_unused uint32_t vf, uint32 > const uint32_t IXGBE_MTA_BIT_SHIFT = 5; > const uint32_t IXGBE_MTA_BIT_MASK = (0x1 << IXGBE_MTA_BIT_SHIFT) - > 1; > uint32_t reg_val; > - int i; > + int16_t i; ditto > > /* only so many hash values supported */ > nb_entries = RTE_MIN(nb_entries, IXGBE_MAX_VF_MC_ENTRIES); > -- > 1.9.1 >