On 15/06/11 22:51, Wolfgang Denk wrote:
> Dear Graeme Russ,
> 
> In message <4df8a8cf.5000...@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



_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Reply via email to