On 2/9/07, Pavel Pisa <[EMAIL PROTECTED]> wrote:
#define __val2mfld(mask,val) (((mask)&~((mask)<<1))*(val)&(mask)) #define __mfld2val(mask,val) (((val)&(mask))/((mask)&~((mask)<<1)))
Looks a bit similar to the style I tend to use a lot: /* Bit manipulation macros */ #define MACB_BIT(name) \ (1 << MACB_##name##_OFFSET) #define MACB_BF(name,value) \ (((value) & ((1 << MACB_##name##_SIZE) - 1)) \ << MACB_##name##_OFFSET) #define MACB_BFEXT(name,value)\ (((value) >> MACB_##name##_OFFSET) \ & ((1 << MACB_##name##_SIZE) - 1)) #define MACB_BFINS(name,value,old) \ (((old) & ~(((1 << MACB_##name##_SIZE) - 1) \ << MACB_##name##_OFFSET)) \ | MACB_BF(name,value)) where BF stands for bitfield, EXT for extract and INS for insert. The macros are butt ugly, but code using them is hopefully quite easy to read (I'm of course not qualified to judge code I wrote myself.) The somewhat excessive pasting ensures that if you ever switch the name and value arguments, the compiler will let you know. Example usage: macb_writel(bp, REG, MACB_BF(FIELD, value)); regval = macb_readl(bp, REG); value = MACB_BFEXT(FIELD, regval); Haavard - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/