]> err.no Git - linux-2.6/commitdiff
rt2x00: Make rt2x00_set/get_field macros
authorIvo van Doorn <IvDoorn@gmail.com>
Tue, 3 Jun 2008 18:29:43 +0000 (20:29 +0200)
committerJohn W. Linville <linville@tuxdriver.com>
Sat, 14 Jun 2008 16:17:55 +0000 (12:17 -0400)
The rt2x00_set_field functions are very often used,
but GCC is better able to optimize them when they
are macros instead of static inline functions.

After changing it to macro's each rt2x00 driver will
loose about ~3500 bytes in size.

Signed-off-by: Ivo van Doorn <IvDoorn@gmail.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
drivers/net/wireless/rt2x00/rt2x00reg.h

index b0d27edcc330ebc996f6b3e03dc23d51a0d5e7ec..c3f1202404d9a69ca59a599aa9018fbe787e2cb6 100644 (file)
@@ -198,46 +198,35 @@ struct rt2x00_field32 {
        };                                      \
 })
 
-static inline void rt2x00_set_field32(u32 *reg,
-                                     const struct rt2x00_field32 field,
-                                     const u32 value)
-{
-       *reg &= ~(field.bit_mask);
-       *reg |= (value << field.bit_offset) & field.bit_mask;
-}
-
-static inline u32 rt2x00_get_field32(const u32 reg,
-                                    const struct rt2x00_field32 field)
-{
-       return (reg & field.bit_mask) >> field.bit_offset;
-}
-
-static inline void rt2x00_set_field16(u16 *reg,
-                                     const struct rt2x00_field16 field,
-                                     const u16 value)
-{
-       *reg &= ~(field.bit_mask);
-       *reg |= (value << field.bit_offset) & field.bit_mask;
-}
-
-static inline u16 rt2x00_get_field16(const u16 reg,
-                                    const struct rt2x00_field16 field)
-{
-       return (reg & field.bit_mask) >> field.bit_offset;
-}
-
-static inline void rt2x00_set_field8(u8 *reg,
-                                    const struct rt2x00_field8 field,
-                                    const u8 value)
-{
-       *reg &= ~(field.bit_mask);
-       *reg |= (value << field.bit_offset) & field.bit_mask;
-}
-
-static inline u8 rt2x00_get_field8(const u8 reg,
-                                  const struct rt2x00_field8 field)
-{
-       return (reg & field.bit_mask) >> field.bit_offset;
-}
+#define SET_FIELD(__reg, __type, __field, __value)\
+({                                             \
+       typecheck(__type, __field);             \
+       *(__reg) &= ~((__field).bit_mask);      \
+       *(__reg) |= ((__value) <<               \
+           ((__field).bit_offset)) &           \
+           ((__field).bit_mask);               \
+})
+
+#define GET_FIELD(__reg, __type, __field)      \
+({                                             \
+       typecheck(__type, __field);             \
+       ((__reg) & ((__field).bit_mask)) >>     \
+           ((__field).bit_offset);             \
+})
+
+#define rt2x00_set_field32(__reg, __field, __value) \
+       SET_FIELD(__reg, struct rt2x00_field32, __field, __value)
+#define rt2x00_get_field32(__reg, __field) \
+       GET_FIELD(__reg, struct rt2x00_field32, __field)
+
+#define rt2x00_set_field16(__reg, __field, __value) \
+       SET_FIELD(__reg, struct rt2x00_field16, __field, __value)
+#define rt2x00_get_field16(__reg, __field) \
+       GET_FIELD(__reg, struct rt2x00_field16, __field)
+
+#define rt2x00_set_field8(__reg, __field, __value) \
+       SET_FIELD(__reg, struct rt2x00_field8, __field, __value)
+#define rt2x00_get_field8(__reg, __field) \
+       GET_FIELD(__reg, struct rt2x00_field8, __field)
 
 #endif /* RT2X00REG_H */