[U-Boot] [PATCH v3 02/10] armv7: add miscellaneous utility macros

Graeme Russ graeme.russ at gmail.com
Thu Jun 16 13:07:53 CEST 2011


On 15/06/11 22:51, Wolfgang Denk wrote:
> Dear Graeme Russ,
> 
> In message <4DF8A8CF.5000308 at gmail.com> you wrote:
>>
>> And to set the value then you have:
>>
>> 	reg &= ~a_mask;				/* Clear a_val */
>> 	reg |= (a_val << a_shift) & a_mask;	/* Set new a_val */
> 
> This could be done using
> 
> 	clrsetbits_le32(&reg, a_mask, a_val << a_shift);

Not quite:

	clrsetbits_le32(&reg, a_mask, (a_val << a_shift) & a_mask);

is equivalent except that, as already pointed out, clrsetbits and friends:

 a) Are not portable because only ARM and PPC define them which makes
    them, by definition, non-standard
 b) Each invocation results in a read barrier plus a write barrier
 c) If the hardware register is sensitive to partial updates (i.e. requires
    all bit-fields to be updated in on operation) this requires a read into
    a local variable, calls to clrsetbits against that variable and finally
    a write-back - Lots of memory barriers

I know I'm going over old ground, and it's not that I am against
clrsetbits, it's just good to know the limitations up-front. So remember,
clrsetbits is not platform independent, prevents the compiler from
optimising and will most likely impose a performance hit

Regards,

Graeme





More information about the U-Boot mailing list