All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Syed Nayyar Waris <syednwaris@gmail.com>
Cc: linus.walleij@linaro.org, akpm@linux-foundation.org,
	vilhelm.gray@gmail.com, arnd@arndb.de,
	linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v11 1/4] bitops: Introduce the for_each_set_clump macro
Date: Tue, 6 Oct 2020 14:27:45 +0300	[thread overview]
Message-ID: <20201006112745.GG4077@smile.fi.intel.com> (raw)
In-Reply-To: <33de236870f7d3cf56a55d747e4574cdd2b9686a.1601974764.git.syednwaris@gmail.com>

On Tue, Oct 06, 2020 at 02:52:16PM +0530, Syed Nayyar Waris wrote:
> This macro iterates for each 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_value() and bitmap_set_value() functions are introduced to
> respectively get and set a value of n-bits in a bitmap memory region.
> The n-bits can have any size less than or equal to BITS_PER_LONG.
> Moreover, during setting value of n-bit in bitmap, if a situation arise
> that the width of next n-bit is exceeding the word boundary, then it
> will divide itself such that some portion of it is stored in that word,
> while the remaining portion is stored in the next higher word. Similar
> situation occurs while retrieving the value from bitmap.

...

> @@ -75,7 +75,11 @@
>   *  bitmap_from_arr32(dst, buf, nbits)          Copy nbits from u32[] buf to dst
>   *  bitmap_to_arr32(buf, src, nbits)            Copy nbits from buf to u32[] dst
>   *  bitmap_get_value8(map, start)               Get 8bit value from map at start
> + *  bitmap_get_value(map, start, nbits)		Get bit value of size
> + *						'nbits' from map at start
>   *  bitmap_set_value8(map, value, start)        Set 8bit value to map at start
> + *  bitmap_set_value(map, value, start, nbits)	Set bit value of size 'nbits'
> + *						of map at start

Formatting here is done with solely spaces, no TABs.

...

> +/**
> + * bitmap_get_value - get a value of n-bits from the memory region
> + * @map: address to the bitmap memory region
> + * @start: bit offset of the n-bit value
> + * @nbits: size of value in bits (must be between 1 and BITS_PER_LONG inclusive).


> + *	nbits less than 1 or more than BITS_PER_LONG causes undefined behaviour.

Please, detach this from field description and move to a main description.

> + *
> + * Returns value of nbits located at the @start bit offset within the @map
> + * memory region.
> + */

...

> +		return (map[index] >> offset) & GENMASK(nbits - 1, 0);

Have you considered to use rather BIT{_ULL}(nbits) - 1?
It maybe better for code generation.

...

> +/**
> + * bitmap_set_value - set n-bit value within a memory region
> + * @map: address to the bitmap memory region
> + * @value: value of nbits
> + * @start: bit offset of the n-bit value
> + * @nbits: size of value in bits (must be between 1 and BITS_PER_LONG inclusive).

> + *	nbits less than 1 or more than BITS_PER_LONG causes undefined behaviour.

Please, detach this from field description and move to a main description.

> + */

...

> +	value &= GENMASK(nbits - 1, 0);

Ditto.

> +		map[index] &= ~(GENMASK(nbits + offset - 1, offset));

Last time I checked such GENMASK) use, it gave a lot of code when
GENMASK(nbits - 1, 0) << offset works much better, but see also above.

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2020-10-06 11:26 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-06  9:20 [PATCH v11 0/4] Introduce the for_each_set_clump macro Syed Nayyar Waris
2020-10-06  9:20 ` Syed Nayyar Waris
2020-10-06  9:22 ` [PATCH v11 1/4] bitops: " Syed Nayyar Waris
2020-10-06 11:27   ` Andy Shevchenko [this message]
2020-10-15 22:53     ` Syed Nayyar Waris
2020-10-16  9:17       ` Andy Shevchenko
2020-10-16 11:45         ` Syed Nayyar Waris
2020-10-06  9:23 ` [PATCH v11 2/4] lib/test_bitmap.c: Add for_each_set_clump test cases Syed Nayyar Waris
2020-10-06 19:48   ` kernel test robot
2020-10-06  9:24 ` [PATCH v11 3/4] gpio: thunderx: Utilize for_each_set_clump macro Syed Nayyar Waris
2020-10-06  9:26 ` [PATCH v11 4/4] gpio: xilinx: Utilize generic bitmap_get_value and _set_value Syed Nayyar Waris
2020-10-06  9:26   ` Syed Nayyar Waris
2020-10-07  8:38 ` [PATCH v11 0/4] Introduce the for_each_set_clump macro Linus Walleij
2020-10-07  8:38   ` Linus Walleij
2020-10-23 13:20   ` Syed Nayyar Waris
2020-10-23 13:20     ` Syed Nayyar Waris

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201006112745.GG4077@smile.fi.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@arndb.de \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=syednwaris@gmail.com \
    --cc=vilhelm.gray@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.