On 19 May 2012 11:02, Blue Swirl <blauwir...@gmail.com> wrote:
>> +static inline uint32_t field(uint32_t val, int start, int length)
>> +{
>> +    val >>= start;
>> +    val &= ~(~0 << length);
>> +    return val;
>> +}
>
> Nice function, maybe I could use it in Sparc as well if generalized (later).

We should totally have something like this in our generic bitops
header file. I've previously worked on a codebase that used something
similar consistently, and it's much easier to read than code which
does inline mask-and-shift code.

We probably want a 64 bit variant (or maybe we can just work
on uint64_t and trust the compiler to throw away the top halves
in the 32 bit case?)

-- PMM

Reply via email to