[U-Boot] [PATCH 2/3] Add generic bit operations

Wolfgang Denk wd at denx.de
Thu Jun 4 13:58:03 CEST 2009


Dear Daniel Mack,

In message <20090604114818.GH26688 at buzzloop.caiaq.de> you 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.

But it is not a generic operation. The notion of "bit number" is a
generic concept, but here we have a machine dependent implementation
that sails under the name "asm-generic/bitops.h".

But it is NOT generic.

> > Let's get rid of this stuff, it is confusing.
> 
> Hmm, and how?

Just don't use it. Use masks instead of bit numbers.

What's wrong with using 0x00008000 instead of BIT(15) (which would be
0x00010000 on 32 bit Power systems).

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Prof:        So the American government went to IBM to come up with a
             data encryption standard and they came up with ...
Student:     EBCDIC!


More information about the U-Boot mailing list