From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752237AbeEOUfW (ORCPT ); Tue, 15 May 2018 16:35:22 -0400 Received: from mail.bootlin.com ([62.4.15.54]:45636 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751333AbeEOUfV (ORCPT ); Tue, 15 May 2018 16:35:21 -0400 Date: Tue, 15 May 2018 22:35:16 +0200 From: Boris Brezillon To: Andy Shevchenko Cc: jagdish.gediya@nxp.com, Masahiro Yamada , Jane Wan , Linux Kernel Mailing List , Richard Weinberger , Marek Vasut , ties.bos@nokia.com, prabhakar.kushwaha@nxp.com, "open list:MEMORY TECHNOLOGY..." , Shreeya Patel , Miquel Raynal , Brian Norris , Shawn Guo , David Woodhouse Subject: Re: [PATCH v5 2/2] mtd: rawnand: use bit-wise majority to recover the contents of ONFI parameter Message-ID: <20180515223516.16e907b3@bbrezillon> In-Reply-To: References: <1525920400-11392-1-git-send-email-Jane.Wan@nokia.com> <20180510140311.02805561@bbrezillon> <20180515093525.051856dd@bbrezillon> <20180515100304.3daa7929@bbrezillon> X-Mailer: Claws Mail 3.15.0-dirty (GTK+ 2.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 15 May 2018 23:23:02 +0300 Andy Shevchenko wrote: > On Tue, May 15, 2018 at 11:03 AM, Boris Brezillon > wrote: > > On Tue, 15 May 2018 10:46:00 +0300 > > Andy Shevchenko wrote: > > > >> On Tue, May 15, 2018 at 10:35 AM, Boris Brezillon > >> wrote: > >> > On Mon, 14 May 2018 20:54:36 +0300 > >> > Andy Shevchenko wrote: > > >> >> > for (k = 0; k < nbufs; k++) { > >> >> > const u8 *srcbuf = srcbufs[j]; > >> >> > > >> >> > if (srcbuf[i] & BIT(k)) > >> >> > m++; > >> >> > } > >> >> > >> >> ...which is effectively hweightXX(). > >> > > >> > No it's not. > >> > >> I don't see how "not". In the loop everithing except m and k are > >> invariants. What did I miss? > > > > We're not counting the number of bits set in an uXX var, but the number > > of set bits at the same position in different buffers. > > ...on big picture. The excerpt above is hweight() against srcbuf[i]. > > Let's rewrite it like this: > > const u8 *srcbuf = srcbufs[j]; > > for (k = 0; k < nbufs; k++) { > if (srcbuf[i] & BIT(k)) I made a mistake in my code sample, it's if (srcbuf[i] & BIT(j)) If you look at v6, you'll see it's been fixed by Jane. > m++; > } > > ...and now it looks obvious: > > m += hweight...(srcbuf[i]) > > _If_ nbufs is power of two we may use primitive helper. >