[RESEND PATCH v4 0/8] Introduce the for_each_set_clump macro

2018-10-01 Thread William Breathitt Gray
This is a resend of v4 in hopes of getting some more ACKS and a few more
eyes on this patchset.

Changes in v4:
  - Fix bitmap_set arguments (last parameter is nbits not endbit)

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 
represents the current 4-bit group:

Example:1011 1110  
First loop: 1011 1110  
Second loop:1011   
Third loop:  1110  

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.19.0



[RESEND PATCH v4 0/8] Introduce the for_each_set_clump macro

2018-10-01 Thread William Breathitt Gray
This is a resend of v4 in hopes of getting some more ACKS and a few more
eyes on this patchset.

Changes in v4:
  - Fix bitmap_set arguments (last parameter is nbits not endbit)

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 
represents the current 4-bit group:

Example:1011 1110  
First loop: 1011 1110  
Second loop:1011   
Third loop:  1110  

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.19.0



Re: [PATCH v4 0/8] Introduce the for_each_set_clump macro

2018-09-10 Thread Andy Shevchenko
On Mon, Sep 10, 2018 at 09:54:47AM +0200, Linus Walleij wrote:
> On Wed, Sep 5, 2018 at 5:04 PM William Breathitt Gray
>  wrote:
> > On Wed, May 16, 2018 at 04:03:51PM +0200, Linus Walleij wrote:
> > >On Tue, May 15, 2018 at 6:22 PM, William Breathitt Gray
> > > wrote:
> > >
> > >> 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 
> > >> represents the current 4-bit group:
> > >>
> > >> Example:1011 1110  
> > >> First loop: 1011 1110  
> > >> Second loop:1011   
> > >> Third loop:  1110  
> > >>
> > >> 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.
> > >
> > >I must say I'm impressed. Very nice arithmetics going on there.
> > >
> > >If I can get some ACK for the bitops patch I'd be happy to merge
> > >it all through the GPIO tree. The users are pretty clear cut.
> > >
> > >BTW: if I could, I would pull out Donald Knuth's "The Art of Computer
> > >Programming vol 4A" chapter 7.1.3 "Bitwise Tricks and Techniques"
> > >to see what he has to say about the subject, but I don't have
> > >that book as it turns out.
> > >
> > >Yours,
> > >Linus Walleij
> >
> > Hi Linus,
> >
> > I'd like to get this patchset merged, but I'm aware that we haven't yet
> > received additional ACKs in the past couple months. Are there any
> > changes you would like made, or should I resubmit this patchset with
> > additional CCs in the hopes of some ACKs for the bitops patch?
> 
> It seems Andy wanted some time and he had ~4 months now
> so either he forgot it or has way too much to do.

Sorry, indeed, it got piled under huge backlog I have.

> 
> I would say send this patch to Andrew Morton (the bitops patches)
> so he can decide on it. He has the right bird's eye view on this
> kind of things.

Agreed, and please add Rasmus as well.


-- 
With Best Regards,
Andy Shevchenko




Re: [PATCH v4 0/8] Introduce the for_each_set_clump macro

2018-09-10 Thread Andy Shevchenko
On Mon, Sep 10, 2018 at 09:54:47AM +0200, Linus Walleij wrote:
> On Wed, Sep 5, 2018 at 5:04 PM William Breathitt Gray
>  wrote:
> > On Wed, May 16, 2018 at 04:03:51PM +0200, Linus Walleij wrote:
> > >On Tue, May 15, 2018 at 6:22 PM, William Breathitt Gray
> > > wrote:
> > >
> > >> 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 
> > >> represents the current 4-bit group:
> > >>
> > >> Example:1011 1110  
> > >> First loop: 1011 1110  
> > >> Second loop:1011   
> > >> Third loop:  1110  
> > >>
> > >> 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.
> > >
> > >I must say I'm impressed. Very nice arithmetics going on there.
> > >
> > >If I can get some ACK for the bitops patch I'd be happy to merge
> > >it all through the GPIO tree. The users are pretty clear cut.
> > >
> > >BTW: if I could, I would pull out Donald Knuth's "The Art of Computer
> > >Programming vol 4A" chapter 7.1.3 "Bitwise Tricks and Techniques"
> > >to see what he has to say about the subject, but I don't have
> > >that book as it turns out.
> > >
> > >Yours,
> > >Linus Walleij
> >
> > Hi Linus,
> >
> > I'd like to get this patchset merged, but I'm aware that we haven't yet
> > received additional ACKs in the past couple months. Are there any
> > changes you would like made, or should I resubmit this patchset with
> > additional CCs in the hopes of some ACKs for the bitops patch?
> 
> It seems Andy wanted some time and he had ~4 months now
> so either he forgot it or has way too much to do.

Sorry, indeed, it got piled under huge backlog I have.

> 
> I would say send this patch to Andrew Morton (the bitops patches)
> so he can decide on it. He has the right bird's eye view on this
> kind of things.

Agreed, and please add Rasmus as well.


-- 
With Best Regards,
Andy Shevchenko




Re: [PATCH v4 0/8] Introduce the for_each_set_clump macro

2018-09-10 Thread Linus Walleij
On Wed, Sep 5, 2018 at 5:04 PM William Breathitt Gray
 wrote:
> On Wed, May 16, 2018 at 04:03:51PM +0200, Linus Walleij wrote:
> >On Tue, May 15, 2018 at 6:22 PM, William Breathitt Gray
> > wrote:
> >
> >> 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 
> >> represents the current 4-bit group:
> >>
> >> Example:1011 1110  
> >> First loop: 1011 1110  
> >> Second loop:1011   
> >> Third loop:  1110  
> >>
> >> 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.
> >
> >I must say I'm impressed. Very nice arithmetics going on there.
> >
> >If I can get some ACK for the bitops patch I'd be happy to merge
> >it all through the GPIO tree. The users are pretty clear cut.
> >
> >BTW: if I could, I would pull out Donald Knuth's "The Art of Computer
> >Programming vol 4A" chapter 7.1.3 "Bitwise Tricks and Techniques"
> >to see what he has to say about the subject, but I don't have
> >that book as it turns out.
> >
> >Yours,
> >Linus Walleij
>
> Hi Linus,
>
> I'd like to get this patchset merged, but I'm aware that we haven't yet
> received additional ACKs in the past couple months. Are there any
> changes you would like made, or should I resubmit this patchset with
> additional CCs in the hopes of some ACKs for the bitops patch?

It seems Andy wanted some time and he had ~4 months now
so either he forgot it or has way too much to do.

I would say send this patch to Andrew Morton (the bitops patches)
so he can decide on it. He has the right bird's eye view on this
kind of things.

Yours,
Linus Walleij


Re: [PATCH v4 0/8] Introduce the for_each_set_clump macro

2018-09-10 Thread Linus Walleij
On Wed, Sep 5, 2018 at 5:04 PM William Breathitt Gray
 wrote:
> On Wed, May 16, 2018 at 04:03:51PM +0200, Linus Walleij wrote:
> >On Tue, May 15, 2018 at 6:22 PM, William Breathitt Gray
> > wrote:
> >
> >> 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 
> >> represents the current 4-bit group:
> >>
> >> Example:1011 1110  
> >> First loop: 1011 1110  
> >> Second loop:1011   
> >> Third loop:  1110  
> >>
> >> 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.
> >
> >I must say I'm impressed. Very nice arithmetics going on there.
> >
> >If I can get some ACK for the bitops patch I'd be happy to merge
> >it all through the GPIO tree. The users are pretty clear cut.
> >
> >BTW: if I could, I would pull out Donald Knuth's "The Art of Computer
> >Programming vol 4A" chapter 7.1.3 "Bitwise Tricks and Techniques"
> >to see what he has to say about the subject, but I don't have
> >that book as it turns out.
> >
> >Yours,
> >Linus Walleij
>
> Hi Linus,
>
> I'd like to get this patchset merged, but I'm aware that we haven't yet
> received additional ACKs in the past couple months. Are there any
> changes you would like made, or should I resubmit this patchset with
> additional CCs in the hopes of some ACKs for the bitops patch?

It seems Andy wanted some time and he had ~4 months now
so either he forgot it or has way too much to do.

I would say send this patch to Andrew Morton (the bitops patches)
so he can decide on it. He has the right bird's eye view on this
kind of things.

Yours,
Linus Walleij


Re: [PATCH v4 0/8] Introduce the for_each_set_clump macro

2018-09-05 Thread William Breathitt Gray
On Wed, May 16, 2018 at 04:03:51PM +0200, Linus Walleij wrote:
>On Tue, May 15, 2018 at 6:22 PM, William Breathitt Gray
> wrote:
>
>> 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 
>> represents the current 4-bit group:
>>
>> Example:1011 1110  
>> First loop: 1011 1110  
>> Second loop:1011   
>> Third loop:  1110  
>>
>> 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.
>
>I must say I'm impressed. Very nice arithmetics going on there.
>
>If I can get some ACK for the bitops patch I'd be happy to merge
>it all through the GPIO tree. The users are pretty clear cut.
>
>BTW: if I could, I would pull out Donald Knuth's "The Art of Computer
>Programming vol 4A" chapter 7.1.3 "Bitwise Tricks and Techniques"
>to see what he has to say about the subject, but I don't have
>that book as it turns out.
>
>Yours,
>Linus Walleij

Hi Linus,

I'd like to get this patchset merged, but I'm aware that we haven't yet
received additional ACKs in the past couple months. Are there any
changes you would like made, or should I resubmit this patchset with
additional CCs in the hopes of some ACKs for the bitops patch?

Sincerely,

William Breathitt Gray


Re: [PATCH v4 0/8] Introduce the for_each_set_clump macro

2018-09-05 Thread William Breathitt Gray
On Wed, May 16, 2018 at 04:03:51PM +0200, Linus Walleij wrote:
>On Tue, May 15, 2018 at 6:22 PM, William Breathitt Gray
> wrote:
>
>> 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 
>> represents the current 4-bit group:
>>
>> Example:1011 1110  
>> First loop: 1011 1110  
>> Second loop:1011   
>> Third loop:  1110  
>>
>> 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.
>
>I must say I'm impressed. Very nice arithmetics going on there.
>
>If I can get some ACK for the bitops patch I'd be happy to merge
>it all through the GPIO tree. The users are pretty clear cut.
>
>BTW: if I could, I would pull out Donald Knuth's "The Art of Computer
>Programming vol 4A" chapter 7.1.3 "Bitwise Tricks and Techniques"
>to see what he has to say about the subject, but I don't have
>that book as it turns out.
>
>Yours,
>Linus Walleij

Hi Linus,

I'd like to get this patchset merged, but I'm aware that we haven't yet
received additional ACKs in the past couple months. Are there any
changes you would like made, or should I resubmit this patchset with
additional CCs in the hopes of some ACKs for the bitops patch?

Sincerely,

William Breathitt Gray


Re: [PATCH v4 0/8] Introduce the for_each_set_clump macro

2018-06-16 Thread William Breathitt Gray
On Wed, May 16, 2018 at 11:08:28PM +0300, Andy Shevchenko wrote:
>On Wed, May 16, 2018 at 5:03 PM, Linus Walleij  
>wrote:
>> On Tue, May 15, 2018 at 6:22 PM, William Breathitt Gray
>>  wrote:
>>
>>> 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 
>>> represents the current 4-bit group:
>>>
>>> Example:1011 1110  
>>> First loop: 1011 1110  
>>> Second loop:1011   
>>> Third loop:  1110  
>>>
>>> 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.
>>
>> I must say I'm impressed. Very nice arithmetics going on there.
>>
>> If I can get some ACK for the bitops patch I'd be happy to merge
>> it all through the GPIO tree. The users are pretty clear cut.
>
>Give me also some time to go through proposed API, I think it might
>have needed more alignment with existing find_* and for_* helpers.

Hi Andy,

Are there any additional changes you would like me to make before this
patchset is merged through the GPIO tree?

William Breathitt Gray

>
>> BTW: if I could, I would pull out Donald Knuth's "The Art of Computer
>> Programming vol 4A" chapter 7.1.3 "Bitwise Tricks and Techniques"
>> to see what he has to say about the subject, but I don't have
>> that book as it turns out.
>
>I can also add the Standford collection of bit algos here:
>
>https://graphics.stanford.edu/~seander/bithacks.html
>
>-- 
>With Best Regards,
>Andy Shevchenko


Re: [PATCH v4 0/8] Introduce the for_each_set_clump macro

2018-06-16 Thread William Breathitt Gray
On Wed, May 16, 2018 at 11:08:28PM +0300, Andy Shevchenko wrote:
>On Wed, May 16, 2018 at 5:03 PM, Linus Walleij  
>wrote:
>> On Tue, May 15, 2018 at 6:22 PM, William Breathitt Gray
>>  wrote:
>>
>>> 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 
>>> represents the current 4-bit group:
>>>
>>> Example:1011 1110  
>>> First loop: 1011 1110  
>>> Second loop:1011   
>>> Third loop:  1110  
>>>
>>> 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.
>>
>> I must say I'm impressed. Very nice arithmetics going on there.
>>
>> If I can get some ACK for the bitops patch I'd be happy to merge
>> it all through the GPIO tree. The users are pretty clear cut.
>
>Give me also some time to go through proposed API, I think it might
>have needed more alignment with existing find_* and for_* helpers.

Hi Andy,

Are there any additional changes you would like me to make before this
patchset is merged through the GPIO tree?

William Breathitt Gray

>
>> BTW: if I could, I would pull out Donald Knuth's "The Art of Computer
>> Programming vol 4A" chapter 7.1.3 "Bitwise Tricks and Techniques"
>> to see what he has to say about the subject, but I don't have
>> that book as it turns out.
>
>I can also add the Standford collection of bit algos here:
>
>https://graphics.stanford.edu/~seander/bithacks.html
>
>-- 
>With Best Regards,
>Andy Shevchenko


Re: [PATCH v4 0/8] Introduce the for_each_set_clump macro

2018-05-16 Thread Andy Shevchenko
On Wed, May 16, 2018 at 5:03 PM, Linus Walleij  wrote:
> On Tue, May 15, 2018 at 6:22 PM, William Breathitt Gray
>  wrote:
>
>> 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 
>> represents the current 4-bit group:
>>
>> Example:1011 1110  
>> First loop: 1011 1110  
>> Second loop:1011   
>> Third loop:  1110  
>>
>> 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.
>
> I must say I'm impressed. Very nice arithmetics going on there.
>
> If I can get some ACK for the bitops patch I'd be happy to merge
> it all through the GPIO tree. The users are pretty clear cut.

Give me also some time to go through proposed API, I think it might
have needed more alignment with existing find_* and for_* helpers.

> BTW: if I could, I would pull out Donald Knuth's "The Art of Computer
> Programming vol 4A" chapter 7.1.3 "Bitwise Tricks and Techniques"
> to see what he has to say about the subject, but I don't have
> that book as it turns out.

I can also add the Standford collection of bit algos here:

https://graphics.stanford.edu/~seander/bithacks.html

-- 
With Best Regards,
Andy Shevchenko


Re: [PATCH v4 0/8] Introduce the for_each_set_clump macro

2018-05-16 Thread Andy Shevchenko
On Wed, May 16, 2018 at 5:03 PM, Linus Walleij  wrote:
> On Tue, May 15, 2018 at 6:22 PM, William Breathitt Gray
>  wrote:
>
>> 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 
>> represents the current 4-bit group:
>>
>> Example:1011 1110  
>> First loop: 1011 1110  
>> Second loop:1011   
>> Third loop:  1110  
>>
>> 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.
>
> I must say I'm impressed. Very nice arithmetics going on there.
>
> If I can get some ACK for the bitops patch I'd be happy to merge
> it all through the GPIO tree. The users are pretty clear cut.

Give me also some time to go through proposed API, I think it might
have needed more alignment with existing find_* and for_* helpers.

> BTW: if I could, I would pull out Donald Knuth's "The Art of Computer
> Programming vol 4A" chapter 7.1.3 "Bitwise Tricks and Techniques"
> to see what he has to say about the subject, but I don't have
> that book as it turns out.

I can also add the Standford collection of bit algos here:

https://graphics.stanford.edu/~seander/bithacks.html

-- 
With Best Regards,
Andy Shevchenko


Re: [PATCH v4 0/8] Introduce the for_each_set_clump macro

2018-05-16 Thread Linus Walleij
On Tue, May 15, 2018 at 6:22 PM, William Breathitt Gray
 wrote:

> 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 
> represents the current 4-bit group:
>
> Example:1011 1110  
> First loop: 1011 1110  
> Second loop:1011   
> Third loop:  1110  
>
> 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.

I must say I'm impressed. Very nice arithmetics going on there.

If I can get some ACK for the bitops patch I'd be happy to merge
it all through the GPIO tree. The users are pretty clear cut.

BTW: if I could, I would pull out Donald Knuth's "The Art of Computer
Programming vol 4A" chapter 7.1.3 "Bitwise Tricks and Techniques"
to see what he has to say about the subject, but I don't have
that book as it turns out.

Yours,
Linus Walleij


Re: [PATCH v4 0/8] Introduce the for_each_set_clump macro

2018-05-16 Thread Linus Walleij
On Tue, May 15, 2018 at 6:22 PM, William Breathitt Gray
 wrote:

> 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 
> represents the current 4-bit group:
>
> Example:1011 1110  
> First loop: 1011 1110  
> Second loop:1011   
> Third loop:  1110  
>
> 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.

I must say I'm impressed. Very nice arithmetics going on there.

If I can get some ACK for the bitops patch I'd be happy to merge
it all through the GPIO tree. The users are pretty clear cut.

BTW: if I could, I would pull out Donald Knuth's "The Art of Computer
Programming vol 4A" chapter 7.1.3 "Bitwise Tricks and Techniques"
to see what he has to say about the subject, but I don't have
that book as it turns out.

Yours,
Linus Walleij


[PATCH v4 0/8] Introduce the for_each_set_clump macro

2018-05-15 Thread William Breathitt Gray
Changes in v4:
  - Fix bitmap_set arguments (last parameter is nbits not endbit)

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 
represents the current 4-bit group:

Example:1011 1110  
First loop: 1011 1110  
Second loop:1011   
Third loop:  1110  

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



[PATCH v4 0/8] Introduce the for_each_set_clump macro

2018-05-15 Thread William Breathitt Gray
Changes in v4:
  - Fix bitmap_set arguments (last parameter is nbits not endbit)

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 
represents the current 4-bit group:

Example:1011 1110  
First loop: 1011 1110  
Second loop:1011   
Third loop:  1110  

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