linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 28/31] iio: gyro: use parity32 in adxrs450.c
       [not found] <1458788612-4367-1-git-send-email-zhaoxiu.zeng@gmail.com>
@ 2016-03-27  7:42 ` zhaoxiu.zeng
  2016-03-28  8:35   ` Jonathan Cameron
  0 siblings, 1 reply; 3+ messages in thread
From: zhaoxiu.zeng @ 2016-03-27  7:42 UTC (permalink / raw)
  To: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
	Hartmut Knaack, Peter Meerwald
  Cc: linux-kernel, linux-iio

From: Zeng Zhaoxiu <zhaoxiu.zeng@gmail.com>

Signed-off-by: Zeng Zhaoxiu <zhaoxiu.zeng@gmail.com>
---
 drivers/iio/gyro/adxrs450.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/iio/gyro/adxrs450.c b/drivers/iio/gyro/adxrs450.c
index a330d42..f1f19fc20 100644
--- a/drivers/iio/gyro/adxrs450.c
+++ b/drivers/iio/gyro/adxrs450.c
@@ -108,9 +108,7 @@ static int adxrs450_spi_read_reg_16(struct iio_dev *indio_dev,
 
 	mutex_lock(&st->buf_lock);
 	tx = ADXRS450_READ_DATA | (reg_address << 17);
-
-	if (!(hweight32(tx) & 1))
-		tx |= ADXRS450_P;
+	tx |= !parity32(tx) * ADXRS450_P;
 
 	st->tx = cpu_to_be32(tx);
 	ret = spi_sync_transfer(st->us, xfers, ARRAY_SIZE(xfers));
@@ -144,9 +142,7 @@ static int adxrs450_spi_write_reg_16(struct iio_dev *indio_dev,
 
 	mutex_lock(&st->buf_lock);
 	tx = ADXRS450_WRITE_DATA | (reg_address << 17) | (val << 1);
-
-	if (!(hweight32(tx) & 1))
-		tx |= ADXRS450_P;
+	tx |= !parity32(tx) * ADXRS450_P;
 
 	st->tx = cpu_to_be32(tx);
 	ret = spi_write(st->us, &st->tx, sizeof(st->tx));
-- 
2.5.5


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

* Re: [PATCH 28/31] iio: gyro: use parity32 in adxrs450.c
  2016-03-27  7:42 ` [PATCH 28/31] iio: gyro: use parity32 in adxrs450.c zhaoxiu.zeng
@ 2016-03-28  8:35   ` Jonathan Cameron
  2016-03-28  8:50     ` Lars-Peter Clausen
  0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Cameron @ 2016-03-28  8:35 UTC (permalink / raw)
  To: zhaoxiu.zeng, Lars-Peter Clausen, Michael Hennerich,
	Hartmut Knaack, Peter Meerwald
  Cc: linux-kernel, linux-iio

On 27/03/16 08:42, zhaoxiu.zeng wrote:
> From: Zeng Zhaoxiu <zhaoxiu.zeng@gmail.com>
> 
> Signed-off-by: Zeng Zhaoxiu <zhaoxiu.zeng@gmail.com>
Interesting.  Whilst obviously correct I wonder if this obscures the
intent of the code a little. Lars, what do you think?

Jonathan
> ---
>  drivers/iio/gyro/adxrs450.c | 8 ++------
>  1 file changed, 2 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/iio/gyro/adxrs450.c b/drivers/iio/gyro/adxrs450.c
> index a330d42..f1f19fc20 100644
> --- a/drivers/iio/gyro/adxrs450.c
> +++ b/drivers/iio/gyro/adxrs450.c
> @@ -108,9 +108,7 @@ static int adxrs450_spi_read_reg_16(struct iio_dev *indio_dev,
>  
>  	mutex_lock(&st->buf_lock);
>  	tx = ADXRS450_READ_DATA | (reg_address << 17);
> -
> -	if (!(hweight32(tx) & 1))
> -		tx |= ADXRS450_P;
> +	tx |= !parity32(tx) * ADXRS450_P;
>  
>  	st->tx = cpu_to_be32(tx);
>  	ret = spi_sync_transfer(st->us, xfers, ARRAY_SIZE(xfers));
> @@ -144,9 +142,7 @@ static int adxrs450_spi_write_reg_16(struct iio_dev *indio_dev,
>  
>  	mutex_lock(&st->buf_lock);
>  	tx = ADXRS450_WRITE_DATA | (reg_address << 17) | (val << 1);
> -
> -	if (!(hweight32(tx) & 1))
> -		tx |= ADXRS450_P;
> +	tx |= !parity32(tx) * ADXRS450_P;
>  
>  	st->tx = cpu_to_be32(tx);
>  	ret = spi_write(st->us, &st->tx, sizeof(st->tx));
> 


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

* Re: [PATCH 28/31] iio: gyro: use parity32 in adxrs450.c
  2016-03-28  8:35   ` Jonathan Cameron
@ 2016-03-28  8:50     ` Lars-Peter Clausen
  0 siblings, 0 replies; 3+ messages in thread
From: Lars-Peter Clausen @ 2016-03-28  8:50 UTC (permalink / raw)
  To: Jonathan Cameron, zhaoxiu.zeng, Michael Hennerich, Hartmut Knaack,
	Peter Meerwald
  Cc: linux-kernel, linux-iio

On 03/28/2016 10:35 AM, Jonathan Cameron wrote:
> On 27/03/16 08:42, zhaoxiu.zeng wrote:
>> From: Zeng Zhaoxiu <zhaoxiu.zeng@gmail.com>
>>
>> Signed-off-by: Zeng Zhaoxiu <zhaoxiu.zeng@gmail.com>
> Interesting.  Whilst obviously correct I wonder if this obscures the
> intent of the code a little. Lars, what do you think?

The parity function is newly introduced in this series and can be more
efficient that  just hw_weight() & 1 on certain architectures. Since the
result is the same using it is certainly an improvement. But ...

[...]
>> -	if (!(hweight32(tx) & 1))
>> -		tx |= ADXRS450_P;
>> +	tx |= !parity32(tx) * ADXRS450_P;

... this should still be

if (!parity32(tx))
	tx |= ADXRS450_P;

Otherwise it's a bit too much obfuscated for my taste. Just leave it to the
compiler to optimize it as it sees it fit.

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

end of thread, other threads:[~2016-03-28  8:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <1458788612-4367-1-git-send-email-zhaoxiu.zeng@gmail.com>
2016-03-27  7:42 ` [PATCH 28/31] iio: gyro: use parity32 in adxrs450.c zhaoxiu.zeng
2016-03-28  8:35   ` Jonathan Cameron
2016-03-28  8:50     ` Lars-Peter Clausen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).