Received: by 2002:a25:5b86:0:0:0:0:0 with SMTP id p128csp1103823ybb; Thu, 28 Mar 2019 20:04:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqxuu9IAJIiHlvFtgqVGfKS8llvv8odtyTjaVRcjFxyOPTdBW6rwi+5jCQHga2PHmf4P5FsM X-Received: by 2002:a62:4754:: with SMTP id u81mr45389588pfa.66.1553828660574; Thu, 28 Mar 2019 20:04:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553828660; cv=none; d=google.com; s=arc-20160816; b=08WWTeUiuftsSk4O1i1N1IdeQehhdWT7d+XJfu2SrBqyHsqFVecTdG+OTfzJ9owQvI I6YJ4wQxnCnuXRQdogp09fZ4X4d1+4y5l5GKzNV8+4M49jQxQoTl7MREEejQARte1LFM nVRiVqRaYOOEZq3YXLzw9UU4DRNe2ZqoaEM2QUkKpfO0QA/nZq1UdAocgBRrvpuFDqmh RDHKoJq6YX8Tqp+rw6M+iFrTmEamI/FKOTJgyWjOq/31l7QuYFI/ngWGqdXDxFfXJDAu lvygtYHRAoH8TJ3+0DbS4MmXcEN+VMLH/d93cixGXlHv4SXD6LpgmjTdSrvCHeT8f+VG RnXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=K34goq+zf1vvl+0PBwq115Mp4iHOPY/zupPfI+vUQAE=; b=Pd23WlQ3slIRG/qWfGoUI1DTsezRyYN6wxw9jYYrwN+u5jgil5NZau9XVrVakoYQyh IDAxxOZorYOli3JUuFz9sHwgR6fG2sJURHS7nIch07aCUCWrOm8+/iPSPY6CCT/S4MJ9 KWBAjJyx+Plsfz53Qlqg2xRVkv2sxyoq8aXINPeA9yuK7Dn/XmKvmc1mTlVTHq00tBo2 dGZ+Xlyd+heHwoidXSBfKMXtOdaL35+smKXyV2fHnQOmznVpih3woHdoCVTRmmawNOet K6adBgJK6BuDne9rYhvaZ2dSP1/5IG+LlOmaPvy5XoPwSIFYNQikHEW6BXBKA8wVrQjE KFhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=V5Efa6TN; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y1si839386plb.276.2019.03.28.20.04.04; Thu, 28 Mar 2019 20:04:20 -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=@gmail.com header.s=20161025 header.b=V5Efa6TN; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728664AbfC2DDO (ORCPT + 99 others); Thu, 28 Mar 2019 23:03:14 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:43574 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727654AbfC2DDN (ORCPT ); Thu, 28 Mar 2019 23:03:13 -0400 Received: by mail-pg1-f193.google.com with SMTP id z9so468739pgu.10; Thu, 28 Mar 2019 20:03:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=K34goq+zf1vvl+0PBwq115Mp4iHOPY/zupPfI+vUQAE=; b=V5Efa6TNudb05BAu+jsft37SCTSyK3Nz05lSgABhwTr9dPRAszIcUwdt+nYaBN1YUq nnkABvG5YB0g+mbL+H4YOeXLTLMWVfra7pf9w1hi3tgYPFOqdXEq4YgMudGJ6RXlcPIn 5c+GFggYuTno7DCS2U+hdFm9EvEUaH7glYeCT87Mm6zWAm+wbuFqKOQp8QmPPHFR3Etw 83TK9UyeSc17lP/TJB+beQzngcxHo6eJ/qlRplHyCLTz7Z2R419iblqcXAX+iG+2EMiy KqpBpTbVsPCTTxQ0ISWh3jNC/Q2NdMlQjPmN3vqJPH4nLlS4MCIiDiRrUSZCGIkMxsuG EE/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=K34goq+zf1vvl+0PBwq115Mp4iHOPY/zupPfI+vUQAE=; b=OPwCsBF6ZRRiL8yWh+kJOu4XxOa8Mng/Y+oZ+xOCTdO3Rom20ZjKK3aV8JlYt6cDeX 8PaxaDNKi3R0iqESOfweoO68bocXl1dm7AeCuZQdD6wOO9I2cuELgL3Y713QbKXAeheq YCl/b6iCqlciwMORRpbbivtTtw36SAzPagkX1snlUrNkv5Tt08RebBaJ59XA6ZtQz1p+ 5Dmi7bmUVicckvTdmb8CYGJtZiM3eJ5NiJ/jgmtxePOwP9s4gvfDQ/b4pO+ogNjTMNZy d4khGkIGyR2DZG8K8r+z3b5gcFduS1GVzypGXRESWWcQandyoGb+9yPeiAgwLDULgP0g ESlA== X-Gm-Message-State: APjAAAW68uWQSanCSxmZTbZOVXbgjQwxVA4kHQqW/Hjut16kx/ndc4Gy b/GRPB5O50y7PbxmH4LhaGE= X-Received: by 2002:a65:4542:: with SMTP id x2mr42882493pgr.65.1553828592563; Thu, 28 Mar 2019 20:03:12 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:ba2:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id x9sm730532pfn.60.2019.03.28.20.03.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Mar 2019 20:03:11 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Cc: 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, lukas@wunner.de, William Breathitt Gray , Andy Shevchenko , Arnd Bergmann Subject: [PATCH v14 01/11] bitops: Introduce the for_each_set_clump8 macro Date: Fri, 29 Mar 2019 12:04:08 +0900 Message-Id: <1cc8b30bb3954ca2a0961ffb0a2eed8a005ed670.1553828158.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Suggested-by: Lukas Wunner Cc: Arnd Bergmann Cc: Andrew Morton Cc: Linus Walleij Acked-by: Andy Shevchenko Signed-off-by: William Breathitt Gray --- include/asm-generic/bitops/find.h | 61 +++++++++++++++++++++++++++++++ include/linux/bitops.h | 5 +++ 2 files changed, 66 insertions(+) diff --git a/include/asm-generic/bitops/find.h b/include/asm-generic/bitops/find.h index 8a1ee10014de..45aa6d718cbd 100644 --- a/include/asm-generic/bitops/find.h +++ b/include/asm-generic/bitops/find.h @@ -80,4 +80,65 @@ extern unsigned long find_first_zero_bit(const unsigned long *addr, #endif /* CONFIG_GENERIC_FIND_FIRST_BIT */ +/** + * bitmap_get_value8 - get an 8-bit value within a memory region + * @addr: address to the bitmap memory region + * @start: bit offset of the 8-bit value; must be a multiple of 8 + * + * Returns the 8-bit value located at the @start bit offset within the @addr + * memory region. + */ +static inline unsigned long bitmap_get_value8(const unsigned long *addr, + unsigned long start) +{ + const size_t index = BIT_WORD(start); + const unsigned long offset = start % BITS_PER_LONG; + + return (addr[index] >> offset) & 0xFF; +} + +/** + * bitmap_set_value8 - set an 8-bit value within a memory region + * @addr: address to the bitmap memory region + * @value: the 8-bit value; values wider than 8 bits may clobber bitmap + * @start: bit offset of the 8-bit value; must be a multiple of 8 + */ +static inline void bitmap_set_value8(unsigned long *addr, unsigned long value, + unsigned long start) +{ + const size_t index = BIT_WORD(start); + const unsigned long offset = start % BITS_PER_LONG; + + addr[index] &= ~(0xFF << offset); + addr[index] |= value << offset; +} + +/** + * 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 + * @size: bitmap size in number of bits + * @offset: bit offset at which to start searching + * + * 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. + */ +static inline unsigned long find_next_clump8(unsigned long *clump, + const unsigned long *addr, + unsigned long size, + unsigned long offset) +{ + offset = find_next_bit(addr, size, offset); + if (offset == size) + return size; + + offset = round_down(offset, 8); + *clump = bitmap_get_value8(addr, offset); + + return offset; +} + +#define find_first_clump8(clump, bits, size) \ + find_next_clump8((clump), (bits), (size), 0) + #endif /*_ASM_GENERIC_BITOPS_FIND_H_ */ diff --git a/include/linux/bitops.h b/include/linux/bitops.h index 602af23b98c7..1d9b5efb9bd4 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), (size), (start) + 8)) + static inline int get_bitmask_order(unsigned int count) { int order; -- 2.21.0