All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: William Breathitt Gray <vilhelm.gray@gmail.com>
Cc: linus.walleij@linaro.org, akpm@linux-foundation.org,
	linux-gpio@vger.kernel.org, linux-arch@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux@rasmusvillemoes.dk,
	yamada.masahiro@socionext.com, bgolaszewski@baylibre.com,
	linux-arm-kernel@lists.infradead.org,
	Arnd Bergmann <arnd@arndb.de>
Subject: Re: [PATCH v10 01/10] bitops: Introduce the for_each_set_clump8 macro
Date: Fri, 22 Mar 2019 20:22:44 +0200	[thread overview]
Message-ID: <20190322182244.GZ9224@smile.fi.intel.com> (raw)
In-Reply-To: <0e4d352418252d480dfc7d529604819f8ff88d9c.1552566113.git.vilhelm.gray@gmail.com>

On Thu, Mar 14, 2019 at 09:30:02PM +0900, William Breathitt Gray wrote:
> 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.

> +void bitmap_set_value8(unsigned long *const bitmap, const unsigned int size,
> +		       const unsigned long value, const unsigned int start)
> +{
> +	const size_t index = BIT_WORD(start);
> +	const unsigned int offset = start % BITS_PER_LONG;
> +	const unsigned int low_width = (offset + 8 > BITS_PER_LONG) ?
> +				       BITS_PER_LONG - offset : 8;

> +	const unsigned long low_mask = GENMASK(offset + low_width - 1, offset);

I think

	unsigned long low_mask = GENMASK(low_width - 1, 0) << offset;

will generate better code.

> +	const unsigned int high_width = 8 - low_width;
> +	const unsigned long high_mask = GENMASK(high_width - 1, 0);
> +
> +	/* set lower portion */
> +	bitmap[index] &= ~low_mask;
> +	bitmap[index] |= value << offset;
> +
> +	/* set higher portion if space available in bitmap */
> +	if (high_width && start + 8 <= size) {
> +		bitmap[index + 1] &= ~high_mask;
> +		bitmap[index + 1] |= value >> low_width;
> +	}
> +}
> +EXPORT_SYMBOL(bitmap_set_value8);

-- 
With Best Regards,
Andy Shevchenko

WARNING: multiple messages have this Message-ID (diff)
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: William Breathitt Gray <vilhelm.gray@gmail.com>
Cc: linux-arch@vger.kernel.org, Arnd Bergmann <arnd@arndb.de>,
	yamada.masahiro@socionext.com, linus.walleij@linaro.org,
	linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org,
	linux-gpio@vger.kernel.org, bgolaszewski@baylibre.com,
	akpm@linux-foundation.org, linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH v10 01/10] bitops: Introduce the for_each_set_clump8 macro
Date: Fri, 22 Mar 2019 20:22:44 +0200	[thread overview]
Message-ID: <20190322182244.GZ9224@smile.fi.intel.com> (raw)
In-Reply-To: <0e4d352418252d480dfc7d529604819f8ff88d9c.1552566113.git.vilhelm.gray@gmail.com>

On Thu, Mar 14, 2019 at 09:30:02PM +0900, William Breathitt Gray wrote:
> 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.

> +void bitmap_set_value8(unsigned long *const bitmap, const unsigned int size,
> +		       const unsigned long value, const unsigned int start)
> +{
> +	const size_t index = BIT_WORD(start);
> +	const unsigned int offset = start % BITS_PER_LONG;
> +	const unsigned int low_width = (offset + 8 > BITS_PER_LONG) ?
> +				       BITS_PER_LONG - offset : 8;

> +	const unsigned long low_mask = GENMASK(offset + low_width - 1, offset);

I think

	unsigned long low_mask = GENMASK(low_width - 1, 0) << offset;

will generate better code.

> +	const unsigned int high_width = 8 - low_width;
> +	const unsigned long high_mask = GENMASK(high_width - 1, 0);
> +
> +	/* set lower portion */
> +	bitmap[index] &= ~low_mask;
> +	bitmap[index] |= value << offset;
> +
> +	/* set higher portion if space available in bitmap */
> +	if (high_width && start + 8 <= size) {
> +		bitmap[index + 1] &= ~high_mask;
> +		bitmap[index + 1] |= value >> low_width;
> +	}
> +}
> +EXPORT_SYMBOL(bitmap_set_value8);

-- 
With Best Regards,
Andy Shevchenko



_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2019-03-22 18:22 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-14 12:29 [PATCH v10 00/10] Introduce the for_each_set_clump8 macro William Breathitt Gray
2019-03-14 12:29 ` William Breathitt Gray
2019-03-14 12:30 ` [PATCH v10 01/10] bitops: " William Breathitt Gray
2019-03-14 12:30   ` William Breathitt Gray
2019-03-22 18:22   ` Andy Shevchenko [this message]
2019-03-22 18:22     ` Andy Shevchenko
2019-03-14 12:30 ` [PATCH v10 02/10] lib/test_bitmap.c: Add for_each_set_clump8 test cases William Breathitt Gray
2019-03-14 12:30   ` William Breathitt Gray
2019-03-14 12:30 ` [PATCH v10 03/10] gpio: 104-dio-48e: Utilize for_each_set_clump8 macro William Breathitt Gray
2019-03-14 12:30   ` William Breathitt Gray
2019-03-14 12:30 ` [PATCH v10 04/10] gpio: 104-idi-48: " William Breathitt Gray
2019-03-14 12:30   ` William Breathitt Gray
2019-03-14 12:31 ` [PATCH v10 05/10] gpio: gpio-mm: " William Breathitt Gray
2019-03-14 12:31   ` William Breathitt Gray
2019-03-14 12:31 ` [PATCH v10 06/10] gpio: ws16c48: " William Breathitt Gray
2019-03-14 12:31   ` William Breathitt Gray
2019-03-14 12:31 ` [PATCH v10 07/10] gpio: pci-idio-16: " William Breathitt Gray
2019-03-14 12:31   ` William Breathitt Gray
2019-03-14 12:32 ` [PATCH v10 08/10] gpio: pcie-idio-24: " William Breathitt Gray
2019-03-14 12:32   ` William Breathitt Gray
2019-03-14 12:32 ` [PATCH v10 09/10] gpio: uniphier: " William Breathitt Gray
2019-03-14 12:32   ` William Breathitt Gray
2019-03-14 12:53   ` William Breathitt Gray
2019-03-14 12:53     ` William Breathitt Gray
2019-03-14 12:32 ` [PATCH v10 10/10] thermal: intel: intel_soc_dts_iosf: " William Breathitt Gray
2019-03-14 12:32   ` William Breathitt Gray
2019-03-14 14:26   ` Andy Shevchenko
2019-03-14 14:26     ` Andy Shevchenko
2019-03-14 14:39     ` William Breathitt Gray
2019-03-14 14:39       ` William Breathitt Gray
2019-03-22 19:02   ` Andy Shevchenko
2019-03-22 19:02     ` Andy Shevchenko
2019-03-24  3:38     ` William Breathitt Gray
2019-03-24  3:38       ` William Breathitt Gray
2019-03-24 13:52       ` Andy Shevchenko
2019-03-24 13:52         ` Andy Shevchenko
2019-03-24 13:52         ` Andy Shevchenko
2019-03-22 19:12 ` [PATCH v10 00/10] Introduce the " Andy Shevchenko
2019-03-22 19:12   ` Andy Shevchenko
2019-03-24  4:08   ` William Breathitt Gray
2019-03-24  4:08     ` William Breathitt Gray
2019-03-24  4:08     ` William Breathitt Gray
2019-03-24  8:53     ` Geert Uytterhoeven
2019-03-24  8:53       ` Geert Uytterhoeven
2019-03-24 12:08     ` Andy Shevchenko
2019-03-24 12:08       ` Andy Shevchenko

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=20190322182244.GZ9224@smile.fi.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@arndb.de \
    --cc=bgolaszewski@baylibre.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=vilhelm.gray@gmail.com \
    --cc=yamada.masahiro@socionext.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.