* [PATCH] atheros/atlx: Simplify bit manipulations
@ 2015-01-23 11:06 Rasmus Villemoes
2015-01-23 20:26 ` Francois Romieu
2015-01-25 7:35 ` David Miller
0 siblings, 2 replies; 3+ messages in thread
From: Rasmus Villemoes @ 2015-01-23 11:06 UTC (permalink / raw)
To: Jay Cliburn, Chris Snook; +Cc: Rasmus Villemoes, netdev, linux-kernel
The code 'if (foo & X) foo &= ~X;' is semantically equivalent to
simply 'foo &= ~X;', but gcc generates about four instructions for the
former, one for the latter. Similarly, if X consists of a single bit,
'if (!(foo & X)) X |= X;' can be replaced by 'foo |= X;'.
In the atl2 case, gcc does know how to merge the new adjacent
operations, so altogether this gives a nice little code size
reduction of about 80 bytes.
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
drivers/net/ethernet/atheros/atlx/atl1.c | 3 +--
drivers/net/ethernet/atheros/atlx/atl2.c | 12 ++++--------
2 files changed, 5 insertions(+), 10 deletions(-)
diff --git a/drivers/net/ethernet/atheros/atlx/atl1.c b/drivers/net/ethernet/atheros/atlx/atl1.c
index 2c8f398aeda9..d9d61d6e8386 100644
--- a/drivers/net/ethernet/atheros/atlx/atl1.c
+++ b/drivers/net/ethernet/atheros/atlx/atl1.c
@@ -1667,8 +1667,7 @@ static void atl1_via_workaround(struct atl1_adapter *adapter)
unsigned long value;
value = ioread16(adapter->hw.hw_addr + PCI_COMMAND);
- if (value & PCI_COMMAND_INTX_DISABLE)
- value &= ~PCI_COMMAND_INTX_DISABLE;
+ value &= ~PCI_COMMAND_INTX_DISABLE;
iowrite32(value, adapter->hw.hw_addr + PCI_COMMAND);
}
diff --git a/drivers/net/ethernet/atheros/atlx/atl2.c b/drivers/net/ethernet/atheros/atlx/atl2.c
index 84a09e8ddd9c..46d1b959daa8 100644
--- a/drivers/net/ethernet/atheros/atlx/atl2.c
+++ b/drivers/net/ethernet/atheros/atlx/atl2.c
@@ -1278,14 +1278,10 @@ static void atl2_setup_pcicmd(struct pci_dev *pdev)
pci_read_config_word(pdev, PCI_COMMAND, &cmd);
- if (cmd & PCI_COMMAND_INTX_DISABLE)
- cmd &= ~PCI_COMMAND_INTX_DISABLE;
- if (cmd & PCI_COMMAND_IO)
- cmd &= ~PCI_COMMAND_IO;
- if (0 == (cmd & PCI_COMMAND_MEMORY))
- cmd |= PCI_COMMAND_MEMORY;
- if (0 == (cmd & PCI_COMMAND_MASTER))
- cmd |= PCI_COMMAND_MASTER;
+ cmd &= ~PCI_COMMAND_INTX_DISABLE;
+ cmd &= ~PCI_COMMAND_IO;
+ cmd |= PCI_COMMAND_MEMORY;
+ cmd |= PCI_COMMAND_MASTER;
pci_write_config_word(pdev, PCI_COMMAND, cmd);
/*
--
2.1.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] atheros/atlx: Simplify bit manipulations
2015-01-23 11:06 [PATCH] atheros/atlx: Simplify bit manipulations Rasmus Villemoes
@ 2015-01-23 20:26 ` Francois Romieu
2015-01-25 7:35 ` David Miller
1 sibling, 0 replies; 3+ messages in thread
From: Francois Romieu @ 2015-01-23 20:26 UTC (permalink / raw)
To: Rasmus Villemoes; +Cc: Jay Cliburn, Chris Snook, netdev, linux-kernel
Rasmus Villemoes <linux@rasmusvillemoes.dk> :
[...]
> diff --git a/drivers/net/ethernet/atheros/atlx/atl2.c b/drivers/net/ethernet/atheros/atlx/atl2.c
> index 84a09e8ddd9c..46d1b959daa8 100644
> --- a/drivers/net/ethernet/atheros/atlx/atl2.c
> +++ b/drivers/net/ethernet/atheros/atlx/atl2.c
> @@ -1278,14 +1278,10 @@ static void atl2_setup_pcicmd(struct pci_dev *pdev)
>
> pci_read_config_word(pdev, PCI_COMMAND, &cmd);
>
> - if (cmd & PCI_COMMAND_INTX_DISABLE)
> - cmd &= ~PCI_COMMAND_INTX_DISABLE;
> - if (cmd & PCI_COMMAND_IO)
> - cmd &= ~PCI_COMMAND_IO;
> - if (0 == (cmd & PCI_COMMAND_MEMORY))
> - cmd |= PCI_COMMAND_MEMORY;
> - if (0 == (cmd & PCI_COMMAND_MASTER))
> - cmd |= PCI_COMMAND_MASTER;
> + cmd &= ~PCI_COMMAND_INTX_DISABLE;
> + cmd &= ~PCI_COMMAND_IO;
> + cmd |= PCI_COMMAND_MEMORY;
> + cmd |= PCI_COMMAND_MASTER;
> pci_write_config_word(pdev, PCI_COMMAND, cmd);
Mostly open-coded pci_set_master, pci_enable_device_mem and pci_intx.
I'd suggest to ignore the PCI_COMMAND_IO bit at all then use the standard
pci helpers.
--
Ueimor
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] atheros/atlx: Simplify bit manipulations
2015-01-23 11:06 [PATCH] atheros/atlx: Simplify bit manipulations Rasmus Villemoes
2015-01-23 20:26 ` Francois Romieu
@ 2015-01-25 7:35 ` David Miller
1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2015-01-25 7:35 UTC (permalink / raw)
To: linux; +Cc: jcliburn, chris.snook, netdev, linux-kernel
From: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Date: Fri, 23 Jan 2015 12:06:52 +0100
> The code 'if (foo & X) foo &= ~X;' is semantically equivalent to
> simply 'foo &= ~X;', but gcc generates about four instructions for the
> former, one for the latter. Similarly, if X consists of a single bit,
> 'if (!(foo & X)) X |= X;' can be replaced by 'foo |= X;'.
>
> In the atl2 case, gcc does know how to merge the new adjacent
> operations, so altogether this gives a nice little code size
> reduction of about 80 bytes.
>
> Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
I agree with the feedback given that these open-coded sequences should
be replaced with the appropriate PCI helpers instead of edited
further.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-01-25 7:35 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-23 11:06 [PATCH] atheros/atlx: Simplify bit manipulations Rasmus Villemoes
2015-01-23 20:26 ` Francois Romieu
2015-01-25 7:35 ` 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.