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

Simon Glass sjg at chromium.org
Wed Jun 15 17:19:06 CEST 2011


On Tue, Jun 14, 2011 at 11:54 AM, Wolfgang Denk <wd at denx.de> wrote:
> Dear Simon Glass,
>
> In message <BANLkTingFroRJD3w7RwqZu80KoTfoV0bmQ at mail.gmail.com> you wrote:
>>
>> > Looking closer, the "FIELD_VAL" macro alone will probably not suffice,
>> > as you need both shift directions, like that:
>> >
>> >        #define FIELD_SHIFT     16
>> >        #define FIELD_MASK      0xF
>> >
>> >
>> >        #define FIELD_BITS(x) (x << 16)
>> >        #define FIELD_MASK FIELD_BITS(0xF)
>> >        #define FIELD_VAL(x) ((x & FIELD_MASK) >> 16)
>>
>> Hi Wolfgang,
>>
>> I think you have FIELD_MASK being two meanings: the un-shifted or
>> 'raw' mask, and the shifted mask. So perhaps:
>
> My intention was to have only the real mask, i. e. what you need to
> apply to the register data (in your language the shifted mask).
>
>>         #define FIELD_SHIFT     16
>>         #define FIELD_RAWMASK      0xF
>
> This is never really needed - you only use it once.
>
>> When you have a lot of these definitions in a row you have mentally
>> check the bit width of the mask:
>
> Yes, this is one of the disadvantages of thinking in bit fields and
> one reason why I never write code like that.
>
> I mentioned this before - I consider it error prone [like most other
> "clever" tricks that "make life easy" and allow you to stop thinking].
>
>> Is the above correct, or do fields overlap or not cover fully?
>
> All this is possible.  There may be overlapping definitions, and there
> may be reserved bits that need special handling.
>
> There may even be bits that cannot simply be re-writeen as we read
> them, but that must always be written as zeroes or ones.
>
> I never claimed that these "bit field" juggling was a clever idea.
> It works for some cases, and causes major pita for others.

Hi Wolfgang,

Yes I agree, but  I think you might have missed both my points.

Regards,
Simon

>
>
> 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
> In an organization, each person rises to the level of his own  incom-
> petency                                         - The Peter Principle
>


More information about the U-Boot mailing list