Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp771699imm; Tue, 15 May 2018 08:58:37 -0700 (PDT) X-Google-Smtp-Source: AB8JxZp7XrjL/GvppJ3lLRdrGDYSIZ41tQPMkSnZ/R0f1MCAEasipM0EiLJMkb6lJXWktD73Puyq X-Received: by 2002:a17:902:7582:: with SMTP id j2-v6mr15022523pll.65.1526399917145; Tue, 15 May 2018 08:58:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526399917; cv=none; d=google.com; s=arc-20160816; b=awUPBEaieJopthUkJwxQaez32LlfedxF5rfpRUuxL21gVftJDoxdZEAfYZly8J28Ze TVKnX1PktuAM8rnGteIMA9DRWJ1+drLUlMGzM9ce2qUMuFFCU/uRhzpuaJ0M7pLQ1kfU 58QP8kAZUdekaAd4BLpuir7ZjpfMFYSi2N5MkpuTjvLtxterW8N+xE9+tmAe5dsVpx/Q pwII8Qe2lgs5lANxew7ULifw55Kvit1JlvzRccz2bICmZbc45KaNdWhBvnum4ipfy8Wr QSbkzobsDNuKNSfdHJwF0chsNPMh/IM654L6cIevtWRh15UXl0bYJMd23u7ogxOpHU9/ kDQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=myfotCDk7qrZHeyzFiNEHnhLpVuK/IJt3EG4qTgb4BU=; b=tjswIUOR6JAfrVdFeXBRcHstvBQaAekGOzBa/wbEHn33QL+i7vI3mp30xBAeNX/iMw 380CN+JIoa55Lj23lSQ/+X2unG3Re3kalgDNGAULaXBq4oXwF5h2tlGGd+6tBdm/AMfn 2IoVXhXpqsDLBsLVlurHETXrj+zd1J4kGQVO95lAoe0tJ2IUd1pocOWmGH0DKT/5kMRb tZucq/ZaCdtATkldknGW7Fbq5lk2Frhqd+jjDhSreb1/iSdXO8wRyjgdg6S/aSqVqwm/ V5rAle7rF30GV9YZonW+5rJpxQ2m3IUeTWK63QbiCKklkbdj/+m/JZWkJTx9pKBxidgq Su6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Smul1/t+; 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 u14-v6si339900pfa.84.2018.05.15.08.58.22; Tue, 15 May 2018 08:58:37 -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=Smul1/t+; 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 S1753211AbeEOPto (ORCPT + 99 others); Tue, 15 May 2018 11:49:44 -0400 Received: from mail-yw0-f196.google.com ([209.85.161.196]:35389 "EHLO mail-yw0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751333AbeEOPtl (ORCPT ); Tue, 15 May 2018 11:49:41 -0400 Received: by mail-yw0-f196.google.com with SMTP id m8-v6so209015ywd.2; Tue, 15 May 2018 08:49:41 -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; bh=myfotCDk7qrZHeyzFiNEHnhLpVuK/IJt3EG4qTgb4BU=; b=Smul1/t+4vlD0uFcvHN44h+TpPg/fSksOqoLXpn6XBb1ULmdPdlBkgERHT3JUVvIos b8AjAE1TJucXoou3YNu8cyUdTWUNou7lKK2gajm2/zmdxd/63NPhgZBbgD1Qt4J/ikv+ 0gxyDiXQrmf6PsLi5dpAcCYhU0o5q4Sovg+9E5osBvpwtQLQKRAXEaJFhfbKj9Urb9in RgnDbsDYW8PE19uLRMmB3VLNb4qEoqVtjRNe43Bp02BUR8x+0OcKrfVdqWhSEdUK9vq+ 3XmOlLkxwDPbNQ636lmqELnckug/X3X3ilgj5F3EJvCaAv1jdRHd1zkIdZFs1uFEz+QM UtJg== 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; bh=myfotCDk7qrZHeyzFiNEHnhLpVuK/IJt3EG4qTgb4BU=; b=dFPYpXwuZIMs0KtdU7kIb9Ynu/3Ec5Qw6N7+2jnFcgiukc2NBT4LUKBKPsZsCbMvLY y3wJwFu5C4h7dHPEYcGlhOk+ElgzRKTRcChrO6KVFmRfXD5nGeJbTT/a244YoLE6aoFr o/S2ME127hHPC1bfQaMejf+Ct+gTW0ezQB1KoQqIHg4XoFIVYDb9bgFG2yjReb8HKTHl /fKwG+rOO/41gVgIleVNG+RR9m1gb8ceFZRKt3P5aPDYabGX7D2nw4/wx1Fcl1B4WiZm oiGnU5QWI6Zp46DHWp863gRHB+gpdfpBcSgRpj08hf2bkR+f5BDr/Mc5FCBTB0EQqeXB 0SJw== X-Gm-Message-State: ALKqPweBeVDm24vGHqFsMqWun+6EEuzEqICNWiGfAIp2Xc3uM8HCVyDa QZJqwIrmUKIaBUqY4Rqoig4oUg== X-Received: by 2002:a0d:e446:: with SMTP id n67-v6mr6555186ywe.362.1526399380751; Tue, 15 May 2018 08:49:40 -0700 (PDT) Received: from localhost ([72.188.97.40]) by smtp.gmail.com with ESMTPSA id x9-v6sm107257ywl.108.2018.05.15.08.49.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 15 May 2018 08:49:40 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org Cc: linux-gpio@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, William Breathitt Gray Subject: [PATCH v3 0/8] Introduce the for_each_set_clump macro Date: Tue, 15 May 2018 11:49:34 -0400 Message-Id: X-Mailer: git-send-email 2.17.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Changes in v3: - Replace "port word" nomenclature with "clump" - Add test cases for for_each_set_clump in lib/test_bitmap.c - Move kernel-doc comment for find_next_clump above C definition While adding GPIO get_multiple/set_multiple callback support for various drivers, I noticed a pattern of looping manifesting that would be useful standardized as a macro. This patchset introduces the for_each_set_clump macro and utilizes it in several GPIO drivers. The for_each_set_clump macro facilitates a for-loop syntax that iterates over entire groups of set bits at a time. For example, suppose you would like to iterate over a 16-bit integer 4 bits at a time, skipping over 4-bit groups with no set bit, where XXXX represents the current 4-bit group: Example: 1011 1110 0000 1111 First loop: 1011 1110 0000 XXXX Second loop: 1011 XXXX 0000 1111 Third loop: XXXX 1110 0000 1111 Each iteration of the loop returns the next 4-bit group that has at least one set bit. The for_each_set_clump macro has six parameters: * clump: set to current clump index for the iteration * index: set to current bitmap word index for the iteration * offset: bits offset of the found clump in the bitmap word * bits: bitmap to search within * size: bitmap size in number of clumps * clump_size: clump size in number of bits The clump_size argument can be an arbitrary number of bits and is not required to be a multiple of 2. This patchset was rebased on top of the following three commits: * commit aaf96e51de11 ("gpio: pci-idio-16: Fix port memory offset for get_multiple callback") * commit 304440aa96c6 ("gpio: pcie-idio-24: Fix port memory offset for get_multiple/set_multiple callbacks") * commit e026646c178d ("gpio: pcie-idio-24: Fix off-by-one error in get_multiple loop") When I implemented the test_for_each_set_clump function, I used bitmap_set to set the expected bitmap for the test. This method of setting bits only segments at a time was rather tedious and error-prone; is there a better way to accomplish what I did (set a bitmap after a DECLARE_BITMAP)? William Breathitt Gray William Breathitt Gray (8): bitops: Introduce the for_each_set_clump macro lib/test_bitmap.c: Add for_each_set_clump test cases gpio: 104-dio-48e: Utilize for_each_set_clump macro gpio: 104-idi-48: Utilize for_each_set_clump macro gpio: gpio-mm: Utilize for_each_set_clump macro gpio: ws16c48: Utilize for_each_set_clump macro gpio: pci-idio-16: Utilize for_each_set_clump macro gpio: pcie-idio-24: Utilize for_each_set_clump macro drivers/gpio/gpio-104-dio-48e.c | 67 +++++--------------- drivers/gpio/gpio-104-idi-48.c | 32 ++-------- drivers/gpio/gpio-gpio-mm.c | 67 +++++--------------- drivers/gpio/gpio-pci-idio-16.c | 67 ++++++-------------- drivers/gpio/gpio-pcie-idio-24.c | 102 +++++++++++------------------- drivers/gpio/gpio-ws16c48.c | 66 +++++-------------- include/asm-generic/bitops/find.h | 9 +++ include/linux/bitops.h | 7 ++ lib/find_bit.c | 40 ++++++++++++ lib/test_bitmap.c | 71 +++++++++++++++++++++ 10 files changed, 236 insertions(+), 292 deletions(-) -- 2.17.0