All of lore.kernel.org
 help / color / mirror / Atom feed
* [net-next] be2net: use shift instead of expensive divide
@ 2017-08-29  3:18 Zhang Shengju
  2017-08-29  3:44 ` Joe Perches
  2017-08-29  4:25 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Zhang Shengju @ 2017-08-29  3:18 UTC (permalink / raw)
  To: sathya.perla, ajit.khaparde, sriharsha.basavapatna, netdev

Replace shift instead of expensive divide.

Signed-off-by: Zhang Shengju <zhangshengju@cmss.chinamobile.com>
---
 drivers/net/ethernet/emulex/benet/be_main.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
index 319eee3..e06094f 100644
--- a/drivers/net/ethernet/emulex/benet/be_main.c
+++ b/drivers/net/ethernet/emulex/benet/be_main.c
@@ -2455,7 +2455,7 @@ static struct be_rx_compl_info *be_rx_compl_get(struct be_rx_obj *rxo)
 
 	/* For checking the valid bit it is Ok to use either definition as the
 	 * valid bit is at the same position in both v0 and v1 Rx compl */
-	if (compl->dw[offsetof(struct amap_eth_rx_compl_v1, valid) / 32] == 0)
+	if (compl->dw[offsetof(struct amap_eth_rx_compl_v1, valid) >> 5] == 0)
 		return NULL;
 
 	rmb();
@@ -2486,7 +2486,7 @@ static struct be_rx_compl_info *be_rx_compl_get(struct be_rx_obj *rxo)
 	}
 
 	/* As the compl has been parsed, reset it; we wont touch it again */
-	compl->dw[offsetof(struct amap_eth_rx_compl_v1, valid) / 32] = 0;
+	compl->dw[offsetof(struct amap_eth_rx_compl_v1, valid) >> 5] = 0;
 
 	queue_tail_inc(&rxo->cq);
 	return rxcp;
@@ -2590,7 +2590,7 @@ static struct be_tx_compl_info *be_tx_compl_get(struct be_tx_obj *txo)
 	struct be_tx_compl_info *txcp = &txo->txcp;
 	struct be_eth_tx_compl *compl = queue_tail_node(tx_cq);
 
-	if (compl->dw[offsetof(struct amap_eth_tx_compl, valid) / 32] == 0)
+	if (compl->dw[offsetof(struct amap_eth_tx_compl, valid) >> 5] == 0)
 		return NULL;
 
 	/* Ensure load ordering of valid bit dword and other dwords below */
@@ -2600,7 +2600,7 @@ static struct be_tx_compl_info *be_tx_compl_get(struct be_tx_obj *txo)
 	txcp->status = GET_TX_COMPL_BITS(status, compl);
 	txcp->end_index = GET_TX_COMPL_BITS(wrb_index, compl);
 
-	compl->dw[offsetof(struct amap_eth_tx_compl, valid) / 32] = 0;
+	compl->dw[offsetof(struct amap_eth_tx_compl, valid) >> 5] = 0;
 	queue_tail_inc(tx_cq);
 	return txcp;
 }
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [net-next] be2net: use shift instead of expensive divide
  2017-08-29  3:18 [net-next] be2net: use shift instead of expensive divide Zhang Shengju
@ 2017-08-29  3:44 ` Joe Perches
  2017-08-29  4:25 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: Joe Perches @ 2017-08-29  3:44 UTC (permalink / raw)
  To: Zhang Shengju, sathya.perla, ajit.khaparde,
	sriharsha.basavapatna, netdev

On Tue, 2017-08-29 at 11:18 +0800, Zhang Shengju wrote:
> Replace shift instead of expensive divide.

This change is mostly pointless.
Any half-way decent compiler should produce the same object.
gcc emits the same object with the old code.

The AMAP_GET_BITS macro uses the "offsetof(struct, member) / 32"
style too.

> diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
[]
> @@ -2455,7 +2455,7 @@ static struct be_rx_compl_info *be_rx_compl_get(struct be_rx_obj *rxo)
>  
>  	/* For checking the valid bit it is Ok to use either definition as the
>  	 * valid bit is at the same position in both v0 and v1 Rx compl */
> -	if (compl->dw[offsetof(struct amap_eth_rx_compl_v1, valid) / 32] == 0)
> +	if (compl->dw[offsetof(struct amap_eth_rx_compl_v1, valid) >> 5] == 0)

etc...

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [net-next] be2net: use shift instead of expensive divide
  2017-08-29  3:18 [net-next] be2net: use shift instead of expensive divide Zhang Shengju
  2017-08-29  3:44 ` Joe Perches
@ 2017-08-29  4:25 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2017-08-29  4:25 UTC (permalink / raw)
  To: zhangshengju; +Cc: sathya.perla, ajit.khaparde, sriharsha.basavapatna, netdev

From: Zhang Shengju <zhangshengju@cmss.chinamobile.com>
Date: Tue, 29 Aug 2017 11:18:39 +0800

> Replace shift instead of expensive divide.
> 
> Signed-off-by: Zhang Shengju <zhangshengju@cmss.chinamobile.com>

The divide is more easier to understand, and it costs the same
as a shift if the types are unsigned.

I'm not applying silly changes like this which actually make
the code worse off, sorry.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-08-29  4:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-29  3:18 [net-next] be2net: use shift instead of expensive divide Zhang Shengju
2017-08-29  3:44 ` Joe Perches
2017-08-29  4:25 ` David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.