[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ZLU7mkhUiDQodaw1@smile.fi.intel.com>
Date: Mon, 17 Jul 2023 16:01:14 +0300
From: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
To: Alexander Potapenko <glider@...gle.com>
Cc: catalin.marinas@....com, will@...nel.org, pcc@...gle.com,
andreyknvl@...il.com, linux@...musvillemoes.dk,
yury.norov@...il.com, linux-kernel@...r.kernel.org,
linux-arm-kernel@...ts.infradead.org, eugenis@...gle.com,
syednwaris@...il.com, william.gray@...aro.org,
Arnd Bergmann <arnd@...db.de>
Subject: Re: [PATCH v3 1/5] lib/bitmap: add bitmap_{set,get}_value()
On Mon, Jul 17, 2023 at 01:37:04PM +0200, Alexander Potapenko wrote:
> The two new functions allow setting/getting values of length up to
> BITS_PER_LONG bits at arbitrary position in the bitmap.
>
> The code was taken from "bitops: Introduce the for_each_set_clump macro"
> by Syed Nayyar Waris with a couple of minor changes:
Since changes are minor, please make sure that the authorship is kept
untouched.
> - instead of using roundup(), which adds an unnecessary dependency
> on <linux/math.h>, we calculate space as BITS_PER_LONG-offset;
> - indentation is reduced by not using else-clauses (suggested by
> checkpatch for bitmap_get_value())
> Cc: Arnd Bergmann <arnd@...db.de>
You can use --cc to `git send-email` instead of polluting the commit message.
> Signed-off-by: Syed Nayyar Waris <syednwaris@...il.com>
> Signed-off-by: William Breathitt Gray <william.gray@...aro.org>
> Link: https://lore.kernel.org/lkml/fe12eedf3666f4af5138de0e70b67a07c7f40338.1592224129.git.syednwaris@gmail.com/
> Suggested-by: Yury Norov <yury.norov@...il.com>
> Signed-off-by: Alexander Potapenko <glider@...gle.com>
With above, I think you can also add Co-developed-by (as the changes were
made).
...
> +static inline void bitmap_set_value(unsigned long *map,
> + unsigned long value,
> + unsigned long start, unsigned long nbits)
> +{
> + const size_t index = BIT_WORD(start);
> + const unsigned long offset = start % BITS_PER_LONG;
> + const unsigned long space = BITS_PER_LONG - offset;
> +
> + value &= GENMASK(nbits - 1, 0);
> +
> + if (space >= nbits) {
> + map[index] &= ~(GENMASK(nbits + offset - 1, offset));
I remember that this construction may bring horrible code on some architectures
with some version(s) of the compiler (*).
To fix that I found an easy refactoring:
map[index] &= ~(GENMASK(nbits, 0) << offset));
(*) don't remember the actual versions, though, but anyway...
> + map[index] |= value << offset;
> + return;
> + }
> + map[index] &= ~BITMAP_FIRST_WORD_MASK(start);
> + map[index] |= value << offset;
> + map[index + 1] &= ~BITMAP_LAST_WORD_MASK(start + nbits);
> + map[index + 1] |= (value >> space);
> +}
--
With Best Regards,
Andy Shevchenko
Powered by blists - more mailing lists