Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp4088332img; Tue, 26 Mar 2019 02:46:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqykgxHnNa2jwa2Jvn+tP+xWtx+auBXTGQO8auoqm7OLaUDz19/2veUBUSV55XBTGOVSVnOJ X-Received: by 2002:a17:902:1002:: with SMTP id b2mr29248672pla.248.1553593573359; Tue, 26 Mar 2019 02:46:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553593573; cv=none; d=google.com; s=arc-20160816; b=iArh8oOZ8oQnVs5rC28A3fmhuz/BtGbgKtVnO+vDpfLvNK1Cnpt1vjO2thyWcaY5wN 5b4Br170KLhBMqw981sAAPjucWTlXilL4slxxae+wNzlIMg2Uk7zBv3GrL2QHzHoFQWI EOKJd/M6cnxZcoTBHefb31a+SKP7hUTWMH6klYDa+IZRj7Dx5V43QSAXfUMvdAqi2zo5 Q9M1m46sDm43m8xFUVG7bnK+I+pgc0siHA/gqLl+TzDRREPDm397G6/NnW71lt6JUHHU YFVHb2Z/5T5OCdyLKqq5MbZcjYkxCScqvVJky8B36RgjlwRDB2zTxu+7LjTilILD38T9 JHxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=fBtl7moYb9v/7cuSoFyThbd4yEtZ7gRvYIg/Qb2OWVc=; b=BqfxIdui//42djA08ixBV4rM3tgnB7LGZNqQgNMAfmJ9o6fiGGH344ohnKPfGo3MUa Oeew2S702/yA5mn9XMYrX9uYmrkxYbfCt8BRSjsZaW02zH27ykqvKyOusKaZB1rntEzM bamR/z3c4KIuS6ZFnrwM2xNvcYHWQRzkTyHZ92+zubck/CXez5mMyMixH0pAk3lHTA25 6++lmTnHWS44F0IoyOwBDyX2g1S4BtK77bEyl1O0j1I9BgCS5CM2OgPlOq+3X8Bp490a X/PWrOZNaVUAeo8Z6JOAJH/aa/ziOE3Q1N8ofeYSCFYMvArbbJStbaDMCsarO+QX6pmw VPWA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z8si6703792pfi.214.2019.03.26.02.45.58; Tue, 26 Mar 2019 02:46:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731163AbfCZJns (ORCPT + 99 others); Tue, 26 Mar 2019 05:43:48 -0400 Received: from bmailout1.hostsharing.net ([83.223.95.100]:48909 "EHLO bmailout1.hostsharing.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726111AbfCZJns (ORCPT ); Tue, 26 Mar 2019 05:43:48 -0400 Received: from h08.hostsharing.net (h08.hostsharing.net [83.223.95.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "*.hostsharing.net", Issuer "COMODO RSA Domain Validation Secure Server CA" (not verified)) by bmailout1.hostsharing.net (Postfix) with ESMTPS id 6E90D30000CE8; Tue, 26 Mar 2019 10:43:45 +0100 (CET) Received: by h08.hostsharing.net (Postfix, from userid 100393) id 43E411D601; Tue, 26 Mar 2019 10:43:45 +0100 (CET) Date: Tue, 26 Mar 2019 10:43:45 +0100 From: Lukas Wunner To: William Breathitt Gray 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 Subject: Re: [PATCH v12 01/11] bitops: Introduce the for_each_set_clump8 macro Message-ID: <20190326094345.v7l7xjvfs2scbvbv@wunner.de> References: <9afc30a574ce3e6a86b51dd522146a1d2156dedd.1553494625.git.vilhelm.gray@gmail.com> <20190325093854.jzkkwaksxi7zvtrg@wunner.de> <20190326031422.GB3356@icarus> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190326031422.GB3356@icarus> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 26, 2019 at 12:14:22PM +0900, William Breathitt Gray wrote: > 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. > > 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; Almost. I'd use round_down() instead of "offset -= offset % 8". Then it's just a single cheap logical and operation at runtime. I'd try to avoid copying around the clump value and use a pointer to u8 instead. I don't understand the calculations in bitmap_get_value8() at all. Why is it so complicated, does it allow passing in a start value that's not a multiple of 8? Do you really need that? I imagine a simplification is possible if that assumption can be made (and is spelled out in the kerneldoc). > Should the offset and size parameters be redefined as unsigned long to > match the find_first_bit/find_next_bit function parameters? Yes, probably. It's just the CPU's native length anyway. Thanks, Lukas