Re: [PATCH v4 1/5] lib/bitmap: add bitmap_{set,get}_value()
From: Andy Shevchenko
Date: Fri Aug 04 2023 - 16:05:37 EST
On Fri, Aug 04, 2023 at 12:55:01PM -0700, Yury Norov wrote:
> On Fri, Aug 04, 2023 at 06:07:00PM +0200, Alexander Potapenko wrote:
> > > > ~BITMAP_FIRST_WORD_MASK(start));
> > >
> > > As I said, ~BITMAP_FIRST_WORD_MASK() is the same as BITMAP_LAST_WORD_MASK()
> > > and vise-versa.
> >
> > Surprisingly, ~BITMAP_FIRST_WORD_MASK() generates better code than
> > BITMAP_LAST_WORD_MASK().
>
> Wow... If that's consistent across different compilers/arches, we'd
> just drop the latter. Thanks for pointing that. I'll check.
It might be...
...
> > map[index] &= (fit ? (~(GENMASK(nbits - 1, 0) << offset)) :
> > ~BITMAP_FIRST_WORD_MASK(start));
...that both parts of ternary are using negation. So compiler may use negation
only once. (Haven't looked at the assembly.)
--
With Best Regards,
Andy Shevchenko