[U-Boot] [PATCH 2/3] Add generic bit operations
Daniel Mack
daniel at caiaq.de
Thu Jun 4 13:48:18 CEST 2009
On Thu, Jun 04, 2009 at 01:45:22PM +0200, Wolfgang Denk wrote:
> > +#define BIT(nr) (1UL << (nr))
> > +#define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG))
> > +#define BIT_WORD(nr) ((nr) / BITS_PER_LONG)
> > +#define BITS_PER_BYTE 8
> > +#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
>
> You see, this is plain wrong on PowerPC.
>
> On PowerPC, bit number 0 is the most significant bit, not the least
> significant one as you assume here. So using this well-intended code
> on a PowerPC system will most likely get you in trouble.
Well, the idea is to let those platforms use the generic operations that
do not bring their owm ones. The code above is not on use by PPC, so it
doesn't harm either.
> [And you cannot even use a generic definition for PowerPC, as some-
> thing like "#define BIT(nr) (0x80000000 >> (nr))" will only work on
> 32 bit systems but be wrong on 64 bit ones.]
That is why PPC implements that in its own fashion. Fair enough.
> Let's get rid of this stuff, it is confusing.
Hmm, and how?
Daniel
More information about the U-Boot
mailing list