lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Tue, 23 Nov 2021 15:43:19 +0200
From:   'Andy Shevchenko' <andriy.shevchenko@...ux.intel.com>
To:     David Laight <David.Laight@...lab.com>
Cc:     "'Vaittinen, Matti'" <Matti.Vaittinen@...rohmeurope.com>,
        Matti Vaittinen <mazziesaccount@...il.com>,
        Liam Girdwood <lgirdwood@...il.com>,
        Mark Brown <broonie@...nel.org>,
        Jiri Kosina <trivial@...nel.org>,
        Andrew Morton <akpm@...ux-foundation.org>,
        Yury Norov <yury.norov@...il.com>,
        Kumar Kartikeya Dwivedi <memxor@...il.com>,
        Rasmus Villemoes <linux@...musvillemoes.dk>,
        Geert Uytterhoeven <geert+renesas@...der.be>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH 1/4] bitops: Add single_bit_set()

On Tue, Nov 23, 2021 at 10:58:44AM +0000, David Laight wrote:
> From: Andy Shevchenko
> > On Tue, Nov 23, 2021 at 10:42:45AM +0000, David Laight wrote:
> > > From: Vaittinen, Matti
> > > > Sent: 22 November 2021 13:19
> > > > On 11/22/21 14:57, Andy Shevchenko wrote:
> > > > > On Mon, Nov 22, 2021 at 12:42:21PM +0000, Vaittinen, Matti wrote:
> > > > >> On 11/22/21 13:28, Andy Shevchenko wrote:
> > > > >>> On Mon, Nov 22, 2021 at 01:03:25PM +0200, Matti Vaittinen wrote:
> > > > >
> > > > > What do you mean by this?
> > > > >
> > > > > hweight() will return you the number of the non-zero elements in the set.
> > > >
> > > > Exactly. The function I added did only check if given set of bits had
> > > > only one bit set.
> > >
> > > Checking for exactly one bit can use the (x & (x - 1)) check on
> > > non-zero values - which may even be better on some cpus with a
> > > popcnt instruction.
> > 
> > In the discussed case the value pretty much can be 0, meaning you have
> > to add an additional test which I believe diminishes all efforts for
> > the is_power_of_2() call.
> 
> I wouldn't have thought so.
> Code would be:
> 	if (!scan_for_non_zero())
> 		return 0;
> 	if (!is_power_of_2())
> 		return 0;
> 	return scan_for_non_zero() ? 0 : 1;
> 
> Hand-crafting asm you'd actually check for (x - 1) generating
> carry in the initial scan.

Have you done any benchmarks? Can we see them?

> The latency of popcnt it worse than arithmetic on a lot of x86 cpu.

Ditto.


-- 
With Best Regards,
Andy Shevchenko


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ