Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp1716165imc; Mon, 11 Mar 2019 22:05:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqy3FpF5dv6Jycs+eteH4yC2fS6KLj19uFluNHhQZ2mP6uVZkcwkkgFQwx71KbB2SiY8sNo2 X-Received: by 2002:a63:1354:: with SMTP id 20mr7618346pgt.198.1552367121965; Mon, 11 Mar 2019 22:05:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552367121; cv=none; d=google.com; s=arc-20160816; b=bBqj2g4fyzMsYx4qIaVy+cCR1+vBk6EmbcPRiH2xovf7DPUagE6I/vQQKc2o8sWguY sGIhpGHaoXd/aqDZaoNI5RXocFSajuqEnHRpV/WLyqVS46IfLrFP217ny4YXazmJAhS3 8suQEqxZA6k48k6Q38HJntC+17G/K8PMuPIhEFBU7Wgk67GTmTYNMS+sQtV6FY5hUWdy ScJSzsdx6ahNINJX+v7+GMThqvyBYaJ/j0W3GVX6qUD6K1rqxYLObK2Q8BRoqc/PxhPU cLuisrF+GV9Ys9F8W1ooM+H2rT2k++UmrldX0zWWgZFnRdYVrPjwxTI3giC/NUMkwH/y LW/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature:dkim-filter; bh=PE8NgoRngZX0cVJ/0gzSXtKWk8b5vFFX7m/LbUwLHwQ=; b=D7ACmLSs8wM2SnBuHDxcKXKoH1zqXN+ZRgUcl5KQDpcp57DGOr2qcUn2EkFq1rjEWf leQhc3xtEi15bV2o34dIHSLsZwke1H2ufsd6RRvcNo4BuVT6h2wwbCDIwsj31sLu1qHl bKDRQ0FXThqLwkwyn6MjD8fC0OzRF1s8PoF/7SI7A2VvDzi/UxO/SyF+8IAyx/LYfDML kO5g6UgV45OBUXemIH9PhFAUowzZ+OcXRHfFirQRqDNNMyrPBIf9/8MO7p2D3RvrJArQ jscKhNQVgphT4bbs/5Ee6gehmDWy5cJhiMdtylvCHPICOn/Gv/BX8PUQMXI04ukp76uy +eTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=K4mXtMWM; 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 h22si6485173pgv.533.2019.03.11.22.05.06; Mon, 11 Mar 2019 22:05:21 -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; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=K4mXtMWM; 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 S1727093AbfCLFEV (ORCPT + 99 others); Tue, 12 Mar 2019 01:04:21 -0400 Received: from conssluserg-01.nifty.com ([210.131.2.80]:44628 "EHLO conssluserg-01.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725792AbfCLFEU (ORCPT ); Tue, 12 Mar 2019 01:04:20 -0400 Received: from mail-vs1-f48.google.com (mail-vs1-f48.google.com [209.85.217.48]) (authenticated) by conssluserg-01.nifty.com with ESMTP id x2C540vB021135; Tue, 12 Mar 2019 14:04:01 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conssluserg-01.nifty.com x2C540vB021135 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1552367041; bh=PE8NgoRngZX0cVJ/0gzSXtKWk8b5vFFX7m/LbUwLHwQ=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=K4mXtMWMFMUnRzrLl4eQlNdrD2tmZBsf1rsmkdCqgSkrOmXFhrk0nzuls5ehs/bQ3 yQq6ksbDKgQQjr98xEqqibhbw3fMFHykB2I9Bbp+qzozP+RTBYnmTOzrLNxyaQQooB fWQIi1pDrFmV5YNJbke+3bDYdgcZfOQZ3wua8xYdl07icy0+MXGOXL0EfsgWJbPu3j qPm0NVw1Jv2KLRsJGF6XL+hg/H4s0MENaR/NBtHEwAdufXB2MFblk+ZTrXlb9gQAxm qzxsLaLI3y5zerBr/CFFXQUAHkQ2MbvnKvW/NpFovKfSJYF/ANg4S/hz72r9LKEx2z GDF8yCPtRzVUA== X-Nifty-SrcIP: [209.85.217.48] Received: by mail-vs1-f48.google.com with SMTP id y19so836212vsc.4; Mon, 11 Mar 2019 22:04:01 -0700 (PDT) X-Gm-Message-State: APjAAAUT7S9g2MgBb2CdNgaO3yj02MP/A1V86Sz05wOx5DJYzXwtHp0W L7SOshRYvSSnjExD6XDVzTF9EcwRXRwyEMwtCnE= X-Received: by 2002:a67:7c04:: with SMTP id x4mr19143493vsc.155.1552367040187; Mon, 11 Mar 2019 22:04:00 -0700 (PDT) MIME-Version: 1.0 References: <12b3a364ac7fc32194fa6f55911dd800aca92a56.1551598603.git.vilhelm.gray@gmail.com> In-Reply-To: <12b3a364ac7fc32194fa6f55911dd800aca92a56.1551598603.git.vilhelm.gray@gmail.com> From: Masahiro Yamada Date: Tue, 12 Mar 2019 14:03:24 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v9 1/9] bitops: Introduce the for_each_set_clump8 macro To: William Breathitt Gray Cc: Linus Walleij , Andrew Morton , "open list:GPIO SUBSYSTEM" , linux-arch , Linux Kernel Mailing List , Andy Shevchenko , Rasmus Villemoes , bgolaszewski@baylibre.com, linux-arm-kernel , Andy Shevchenko , Arnd Bergmann Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Mar 3, 2019 at 4:48 PM William Breathitt Gray wrote: > > This macro iterates for each 8-bit group of bits (clump) with set bits, > within a bitmap memory region. For each iteration, "start" is set to the > bit offset of the found clump, while the respective clump value is > stored to the location pointed by "clump". Additionally, the > bitmap_get_value8 and bitmap_set_value8 functions are introduced to > respectively get and set an 8-bit value in a bitmap memory region. > > Suggested-by: Andy Shevchenko > Suggested-by: Rasmus Villemoes > Cc: Arnd Bergmann > Cc: Andrew Morton > Reviewed-by: Andy Shevchenko > Reviewed-by: Linus Walleij > Signed-off-by: William Breathitt Gray > --- > include/asm-generic/bitops/find.h | 14 ++++++ > include/linux/bitops.h | 5 ++ > lib/find_bit.c | 81 +++++++++++++++++++++++++++++++ > 3 files changed, 100 insertions(+) > > diff --git a/include/asm-generic/bitops/find.h b/include/asm-generic/bitops/find.h > index 8a1ee10014de..9a76adff59c6 100644 > --- a/include/asm-generic/bitops/find.h > +++ b/include/asm-generic/bitops/find.h > @@ -80,4 +80,18 @@ extern unsigned long find_first_zero_bit(const unsigned long *addr, > > #endif /* CONFIG_GENERIC_FIND_FIRST_BIT */ > > +unsigned long bitmap_get_value8(const unsigned long *const bitmap, > + const unsigned int size, > + const unsigned int start); > + > +void bitmap_set_value8(unsigned long *const bitmap, const unsigned int size, > + const unsigned long value, const unsigned int start); > + > +unsigned int find_next_clump8(unsigned long *const clump, > + const unsigned long *const addr, > + unsigned int offset, const unsigned int size); > + > +#define find_first_clump8(clump, bits, size) \ > + find_next_clump8((clump), (bits), 0, (size)) > + > #endif /*_ASM_GENERIC_BITOPS_FIND_H_ */ > diff --git a/include/linux/bitops.h b/include/linux/bitops.h > index 705f7c442691..61c10f20079e 100644 > --- a/include/linux/bitops.h > +++ b/include/linux/bitops.h > @@ -40,6 +40,11 @@ extern unsigned long __sw_hweight64(__u64 w); > (bit) < (size); \ > (bit) = find_next_zero_bit((addr), (size), (bit) + 1)) > > +#define for_each_set_clump8(start, clump, bits, size) \ > + for ((start) = find_first_clump8(&(clump), (bits), (size)); \ > + (start) < (size); \ > + (start) = find_next_clump8(&(clump), (bits), (start) + 8, (size))) > + > static inline int get_bitmask_order(unsigned int count) > { > int order; > diff --git a/lib/find_bit.c b/lib/find_bit.c > index ee3df93ba69a..c2af1f013ea2 100644 > --- a/lib/find_bit.c > +++ b/lib/find_bit.c > @@ -218,3 +218,84 @@ EXPORT_SYMBOL(find_next_bit_le); > #endif > > #endif /* __BIG_ENDIAN */ > + > +/** > + * bitmap_get_value8 - get an 8-bit value within a memory region > + * @bitmap: address to the bitmap memory region > + * @size: bitmap size in number of bits > + * @start: bit offset of the 8-bit value > + * > + * Returns the 8-bit value located at the @start bit offset within the @bitmap > + * memory region. > + */ > +unsigned long bitmap_get_value8(const unsigned long *const bitmap, > + const unsigned int size, > + const unsigned int start) The comment says this function returns '8-bit value'. The return type should be 'u8' instead of 'unsigned long', then. Same for other helpers. > +{ > + const size_t index = BIT_WORD(start); > + const unsigned int offset = start % BITS_PER_LONG; > + const unsigned int low_width = (offset + 8 > BITS_PER_LONG) ? > + BITS_PER_LONG - offset : 8; > + const unsigned long low = bitmap[index] >> offset; > + const unsigned long high = (low_width < 8 && start + 8 <= size) ? > + bitmap[index + 1] << low_width : 0; I do not know if we have a usecase where the 'start' is not multiple of 8, though. -- Best Regards Masahiro Yamada