Linux IIO development
 help / color / mirror / Atom feed
From: David Laight <David.Laight@ACULAB.COM>
To: 'Andy Shevchenko' <andriy.shevchenko@linux.intel.com>
Cc: "linux-iio@vger.kernel.org" <linux-iio@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Peter Rosin <peda@axentia.se>,
	Jonathan Cameron <jic23@kernel.org>,
	Lars-Peter Clausen <lars@metafoo.de>
Subject: RE: [PATCH v1 1/4] iio: afe: rescale: Don't use ^ for booleans
Date: Fri, 6 Dec 2024 20:13:46 +0000	[thread overview]
Message-ID: <2a7a87267feb4c35ad9ef493236b6035@AcuMS.aculab.com> (raw)
In-Reply-To: <Z1MWBsCJsTHsqNey@smile.fi.intel.com>

From: 'Andy Shevchenko'
> Sent: 06 December 2024 15:20
...
> ...
> 
> > >  		 * If only one of the rescaler elements or the schan scale is
> > >  		 * negative, the combined scale is negative.
> > >  		 */
> > > -		if (neg ^ ((rescale->numerator < 0) ^ (rescale->denominator < 0))) {
> > > +		if (neg != (rescale->numerator < 0 || rescale->denominator < 0)) {
> >
> > That is wrong, the || would also need to be !=.
> 
> Why do you think so? Maybe it's comment(s) that is(are) wrong?

The old code certainly negates for each of them - so you can get the double
and triple negative cases.
So believe the code not the comment.
> 
> > Which will all generate real pile of horrid code.
> > (I think the x86 version will stun you.)
> 
> I think your remark is based on something, can you show the output to elaborate
> what exactly becomes horrible in this case?

Ok it isn't quite as bad as I thought because all the compilers will use xor
for the equality test on sign bits. See https://www.godbolt.org/z/qxz5KPcTh
So changing ^ to != makes no difference at all.

But f3() shows the sort of thing that can happen.
Sometimes made worse because the x86 SETcc instruction only set 8bit registers.
(Odd since they got added for the 386)

	David

> 
> > I'm guessing that somewhere there is a:
> > 	neg = value < 0;
> 
> Nope.
> 
> > Provided all the values are the same size (eg int/s32), in which case:
> > 	neg = value;
> > ...
> > 	if ((neg ^ rescale->numerator ^ rescale->denominator) < 0)
> > will be the desired test.
> 
> --
> With Best Regards,
> Andy Shevchenko
> 

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


  reply	other threads:[~2024-12-06 20:14 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-04  1:33 [PATCH v1 0/4] iio: afe: rescale: A few cleanups Andy Shevchenko
2024-12-04  1:33 ` [PATCH v1 1/4] iio: afe: rescale: Don't use ^ for booleans Andy Shevchenko
2024-12-06 13:24   ` David Laight
2024-12-06 15:19     ` 'Andy Shevchenko'
2024-12-06 20:13       ` David Laight [this message]
2024-12-06 22:27         ` Peter Rosin
2024-12-04  1:33 ` [PATCH v1 2/4] iio: afe: rescale: Don't use ULL(1) << x instead of BIT(x) Andy Shevchenko
2024-12-04  1:33 ` [PATCH v1 3/4] iio: afe: rescale: Re-use generic struct s32_fract Andy Shevchenko
2024-12-04 11:11   ` kernel test robot
2024-12-04 11:32   ` kernel test robot
2024-12-04  1:33 ` [PATCH v1 4/4] iio: afe: rescale: Don't use "proxy" headers Andy Shevchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2a7a87267feb4c35ad9ef493236b6035@AcuMS.aculab.com \
    --to=david.laight@aculab.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peda@axentia.se \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox