Re: [PATCH v1 1/2] bitmap: Use constants and macros from bits.h

From: Andy Shevchenko
Date: Fri Aug 18 2023 - 04:51:36 EST


On Fri, Aug 18, 2023 at 08:28:21AM +0200, Rasmus Villemoes wrote:
> On 17/08/2023 18.54, Andy Shevchenko wrote:

> > #ifdef __LITTLE_ENDIAN
> > -#define BITMAP_MEM_ALIGNMENT 8
> > +#define BITMAP_MEM_ALIGNMENT BITS_PER_BYTE
> > #else
> > -#define BITMAP_MEM_ALIGNMENT (8 * sizeof(unsigned long))
> > +#define BITMAP_MEM_ALIGNMENT BITS_PER_LONG
> > #endif
> > #define BITMAP_MEM_MASK (BITMAP_MEM_ALIGNMENT - 1)

What about this chunk? Does it worth to be updated?

...

> > - return !memcmp(src1, src2, nbits / 8);
> > + return !memcmp(src1, src2, BITS_TO_BYTES(nbits));
>
> Please no. Currently, I can verify the arithmetic directly. Using such a
> "helper" I'd have to know whether it just does /8 or if it's more like
> the bitmap_words() thing which rounds up to a whole number of words. And
> BITS_PER_BYTE (and similarly CHAR_BITS) really is, IMO, much less
> readable than 8.

Okay, thank you for the comment!

--
With Best Regards,
Andy Shevchenko