Le 13/01/2011 13:05, Aneesh V a écrit : >>> What I need is something like below: >>> >>> #define get_bit_field(nr, start, mask)\ >>> (((nr) & (mask)) >> (start)) >>> >>> #define set_bit_field(nr, start, mask, val)\ >>> (nr) = ((nr) & ~(mask)) | (((val) << (start)) & (mask)) >>> >>> Can these go in a generic header? If so, can I add them to >>> "include/linux/bitops.h" >> >> After some more thought, I am wondering if a *generic* field setting and >> getting macro is really useful. So far everyone is fine with at most >> defining field-specific macros. > > Is it going to be easy if you have many fields to deal with?
I don't see how the generic macros ease anything. Instead of defining say #define get_field_F(x) ((x >> F_start) & F_mask) #define set_field_F(x,v) { x = (x ~ F_mask ) | (v << F_start) } You'd have #define get_field_F(x) get_bit_field(x, F_start, F_mask) #define set_field_F(x,v) set_bit_field(x, F_start, F_mask, v); Which does not seem to bring any simplicity to me. > However, I agree that the above may be specific to our needs. > > What may be of more generic interest may be something like this with > the mask automatically generated: > #define get_bit_field(nr, start, end) > #define set_bit_field(nr, start, end, val) > > However, in our case I am already given the mask and start position for > each field (automatically generated from hw database). So, I prefer the > former versions. > > If that doesn't look useful for generic use I will put them in > OMAP specific headers. > > Best regards, > Aneesh Amicalement, -- Albert. _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot