From: Ivo van Doorn <ivdoorn@gmail.com>
To: linux-wireless@vger.kernel.org
Cc: rt2400-devel@lists.sourceforge.net
Subject: ffs() compile-time
Date: Thu, 29 May 2008 15:55:53 +0200 [thread overview]
Message-ID: <200805291555.53673.IvDoorn@gmail.com> (raw)
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
reply other threads:[~2008-05-29 13:51 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200805291555.53673.IvDoorn@gmail.com \
--to=ivdoorn@gmail.com \
--cc=linux-wireless@vger.kernel.org \
--cc=rt2400-devel@lists.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.