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

Graeme Russ
2011-06-15T12:42:55Z

On 15/06/11 22:04, Wolfgang Denk wrote:
> Dear Aneesh V,
>
> In message <4DF89102.9040508@ti.com> you wrote:
>>
>> Will you accept something like this?
>>
>> a_val = (reg & a_mask) >> a_shift;
>
> Yes, of course (that's what seems most natural to me).
>

Me too - The code is obvious - the desired value is being masked out of a
larger composite value and then shifted right to bit 0

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 */

AND'ing with a_mask is required to prevent accidental clobbering when a_val
is out-of-range. May give undesirable results by setting an illegal a_val,
but@least you don't clobber unrelated bit fields

Regards,

Graeme