From patchwork Fri Mar 29 03:04:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 10876237 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D34561669 for ; Fri, 29 Mar 2019 03:03:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B94F02909E for ; Fri, 29 Mar 2019 03:03:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ADA40290A2; Fri, 29 Mar 2019 03:03:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 49E2C2909E for ; Fri, 29 Mar 2019 03:03:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=PTBWLxK3JkdnZXrWCRMQaL69IpxnSv926xa+6EYuhJU=; b=mYNS08oOUxwV5d lJaEi4Er9ntRC5wXlnvDBK19BnZ2l+Fcc6Gmx+0xEy/kktwRsk3dYgnDNTJTENhcY/8cd3kd77j5Z BpsYHvI1t7NCRWKRj3WYPlIXn2kBx1ZSZkTHpbyzrNwtRLZKiZpU4iwWB0N3xY3CeGxiwBNOR0GNF /VFTVNDzV7DylN0LDMlksYwULqRfHmiLc2ycj6IcxU4HSjkQXanAq9mncUqFxrrUi5YFr1bXyO10l tbQYixVubwHxEGZAlanCSuGwaFW/GkmkiSjOhI+XB2yT3a8pPrB0xMZ6XJ/tiAIwFUk/ntd8qdjEM 39jPUiMoQmyUk+INXeMg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h9hnZ-0001mM-Oz; Fri, 29 Mar 2019 03:03:17 +0000 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h9hnV-0001hn-GG for linux-arm-kernel@lists.infradead.org; Fri, 29 Mar 2019 03:03:16 +0000 Received: by mail-pf1-x443.google.com with SMTP id c207so329993pfc.7 for ; Thu, 28 Mar 2019 20:03:13 -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=PTEO2MPp0YfuZchAm3KxdzbCbv89iIQtbwdTgbFeejFSIhIwm7QZAGW0QQfRzi5pN0 1zUluCBZYMKU5Si0GTo3GxralD3xs3ibR2gXJ97ToGeah4+B6DYwhvqLBbJ1SQ70iGiO JPgIMHDhc6Ba4joiBKVQ6NQEsR29RnFy69gDkClh/VlhbgmwcX5zNM/yYKTjM03RNdxS WVUBsgVwHN0SqH8IMtjKMLK18SECpnYfORqYY+00+HfZXNVtHcvRfjKqkOnR++oENNGG 5XLP+HAJ/EmGbGZtheq1FOs0WsCk/cSQ+BWAL00yhFABOiSArH/ke2nSrp/IjnlfeGX7 qbuQ== X-Gm-Message-State: APjAAAV4BE4OxwYWZkCnjqlDK9bgLvRe+Qe7A3KwOXVYKj/IOIxdUi1e OpEbYLVE3lR6l+LHVn1xXL4= X-Google-Smtp-Source: APXvYqyMfQEASrbwMcf+1MYodXZ4CyjTM5wNZZ2aZtGMR/8wEoFz1iHj6gTxqTHYRgJfKOFim8ijag== 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 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190328_200313_812397_8D11B041 X-CRM114-Status: GOOD ( 13.67 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, preid@electromag.com.au, Arnd Bergmann , yamada.masahiro@socionext.com, linux-pm@vger.kernel.org, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org, William Breathitt Gray , linux-gpio@vger.kernel.org, Andy Shevchenko , lukas@wunner.de, geert@linux-m68k.org, akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Linus Walleij --- 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;