* ffs() compile-time
@ 2008-05-29 13:55 Ivo van Doorn
0 siblings, 0 replies; only message in thread
From: Ivo van Doorn @ 2008-05-29 13:55 UTC (permalink / raw)
To: linux-wireless; +Cc: rt2400-devel
Hi,
In rt2x00 I define all registers through the FIELD32(__mask) defines,
which look like this:
struct rt2x00_field32 {
u32 bit_offset;
u32 bit_mask;
};
#define FIELD32(__mask)
({
BUILD_BUG_ON(!(__mask) ||
!is_valid_mask(__mask) ||
(__mask) != (u32)(__mask));
(struct rt2x00_field32) {
__ffs(__mask), (__mask)
};
})
As you see everywhere where a define which contains FIELD32() will
make a call to __ffs(). However this is suboptimal since the __mask which
is passed to __ffs() is a constant during compile time.
So it would be very nice when I can make use of a compile-time version of __ffs()
to make GCC find the first bit during compile-time this would increase performance
and help reduce the module size of each rt2x00 driver.
However I am a bit lost at what a proper solution would be, GCC provides
__builtin_ffs() but would that perform the compile-time calculation or not.
Another solution would be creating a macro like:
#define _COMPILE_FFS4(x)\
({ \
(x) & 0x1 ? 1 : \
(x) & 0x2 ? 2 : \
(x) & 0x4 ? 3 : \
(x) & 0x8 ? 4 : \
0; \
})
And have _COMPILE_FFS8, _COMPILE_FFS16 and _COMPILE_FFS32 use above macro.
But I am kind of hesitant about that macro as well, because it just doesn't feel right. :S
Any advice is welcome. :)
Thanks,
Ivo
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2008-05-29 13:51 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-05-29 13:55 ffs() compile-time Ivo van Doorn
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).