From mboxrd@z Thu Jan 1 00:00:00 1970 From: William Breathitt Gray Subject: Re: [PATCH v12 01/11] bitops: Introduce the for_each_set_clump8 macro Date: Tue, 26 Mar 2019 12:14:22 +0900 Message-ID: <20190326031422.GB3356@icarus> References: <9afc30a574ce3e6a86b51dd522146a1d2156dedd.1553494625.git.vilhelm.gray@gmail.com> <20190325093854.jzkkwaksxi7zvtrg@wunner.de> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Return-path: Content-Disposition: inline In-Reply-To: <20190325093854.jzkkwaksxi7zvtrg@wunner.de> Sender: linux-kernel-owner@vger.kernel.org To: Lukas Wunner Cc: linus.walleij@linaro.org, bgolaszewski@baylibre.com, akpm@linux-foundation.org, linux-gpio@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, andriy.shevchenko@linux.intel.com, linux@rasmusvillemoes.dk, yamada.masahiro@socionext.com, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org, geert@linux-m68k.org, preid@electromag.com.au, Andy Shevchenko , Arnd Bergmann List-Id: linux-gpio@vger.kernel.org On Mon, Mar 25, 2019 at 10:38:54AM +0100, Lukas Wunner wrote: > On Mon, Mar 25, 2019 at 03:22:23PM +0900, William Breathitt Gray wrote: > > +/** > > + * find_next_clump8 - find next 8-bit clump with set bits in a memory region > > + * @clump: location to store copy of found clump > > + * @addr: address to base the search on > > + * @offset: bit offset at which to start searching > > + * @size: bitmap size in number of bits > > + * > > + * Returns the bit offset for the next set clump; the found clump value is > > + * copied to the location pointed by @clump. If no bits are set, returns @size. > > + */ > > +unsigned int find_next_clump8(unsigned long *const clump, > > + const unsigned long *const addr, > > + unsigned int offset, const unsigned int size) > > +{ > > + for (; offset < size; offset += 8) { > > + *clump = bitmap_get_value8(addr, size, offset); > > + if (!*clump) > > + continue; > > + > > + return offset; > > + } > > + > > + return size; > > +} > > +EXPORT_SYMBOL(find_next_clump8); > > Just use find_first_bit() / find_next_bit() to use optimized arch-specific > bitops instead of open-coding the iteration over the bitmap. > > See max3191x_get_multiple() for an example. > > Thanks, > > Lukas Is this the sort of implementation you had in mind: offset = find_next_bit(addr, size, offset); if (offset == size) return size; offset -= offset % 8; *clump = bitmap_get_value8(addr, size, offset); return offset; Yes, this does seem more efficient to leverage the existing find_next_bit function. Should the offset and size parameters be redefined as unsigned long to match the find_first_bit/find_next_bit function parameters? William Breathitt Gray