[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <1defaf580702091246i1f49a787g482e25817517d7ed@mail.gmail.com>
Date: Fri, 9 Feb 2007 21:46:33 +0100
From: "Haavard Skinnemoen" <hskinnemoen@...il.com>
To: "Pavel Pisa" <pisa@....felk.cvut.cz>
Cc: "Russell King - ARM Linux" <linux@....linux.org.uk>,
linux-kernel@...r.kernel.org,
"Sascha Hauer" <s.hauer@...gutronix.de>,
"Pierre Ossman" <drzeus@...eus.cx>
Subject: Re: Coding style question
On 2/9/07, Pavel Pisa <pisa@....felk.cvut.cz> 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 majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists