From: David Howells <dhowells@redhat.com>
To: Andrew Morton <akpm@osdl.org>
Cc: torvalds@osdl.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Permit inode & dentry hash tables to be allocated > MAX_ORDER size [try #3]
Date: Mon, 14 Jun 2004 12:41:01 +0100 [thread overview]
Message-ID: <19095.1087213261@redhat.com> (raw)
In-Reply-To: <20040614040417.29e7497b.akpm@osdl.org>
> > > What's the attribute((pure)) for?
> >
> > It tells gcc that the function's result only depends on its arguments... it
> > makes no references at all to external data. It's like __attribute__((const))
> > but stronger. This means that gcc can generate code that caches the result.
Actually... I'm wrong about that. I've got "pure" and "const" the wrong way
around... Perhaps I need to go and read the gcc manual too:-)
> Of course, but we could use it in zillions of places and we don't. Does it
> actually help?
Well... it could. It certainly doesn't hurt. Actually, it's probably
irrelevant on inline functions as the compiler can look inside of those.
> > > The other four or five implementations of log2() use ffx(~n).
> >
I presume this should be ffz() not ffx().
> > Yes... but ffs() and ffz() take int args, not long args. I suspect that
> > shouldn't matter (that would require the hash table to be calculated at 4Gig
> > buckets in size or greater to be a problem), but why take the chance when we
> > can avoid it easily?
>
> No, ffz() takes an unsigned long argument.
So it does. However, ffz(~n) is not equivalent to log2(n). This can be
demonstrated by this little test program:
#include <stdio.h>
#include <stdlib.h>
static __inline__ unsigned long ffz(unsigned long word)
{
__asm__("bsfl %1,%0"
:"=r" (word)
:"r" (~word));
return word;
}
int main(int argc, char *argv[])
{
for (argv++; *argv; argv++)
printf("%lu\n", ffz(~strtoul(*argv, NULL, 0)));
return 0;
}
dhowells>/tmp/ffz 0x10
4
dhowells>/tmp/ffz 0x8
3
dhowells>/tmp/ffz 0x1f
0
This is not entirely correct; the third answer should be 4 too. The bit scan
occurs in the wrong direction.
David
prev parent reply other threads:[~2004-06-14 11:41 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-06-11 10:44 [PATCH] Permit inode & dentry hash tables to be allocated > MAX_ORDER size David Howells
2004-06-11 10:48 ` Andrew Morton
2004-06-11 11:12 ` David Howells
2004-06-11 22:04 ` Andrew Morton
2004-06-11 23:03 ` Martin J. Bligh
2004-06-11 23:19 ` Andrew Morton
2004-06-11 23:18 ` Martin J. Bligh
2004-06-11 23:30 ` Andrew Morton
2004-06-12 12:45 ` Andy Whitcroft
2004-06-13 16:09 ` Linus Torvalds
2004-06-11 14:21 ` [PATCH] Permit inode & dentry hash tables to be allocated > MAX_ORDER size [#2] David Howells
2004-06-11 22:01 ` Andrew Morton
2004-06-14 10:47 ` [PATCH] Permit inode & dentry hash tables to be allocated > MAX_ORDER size [try #3] David Howells
2004-06-14 11:04 ` Andrew Morton
2004-06-14 11:41 ` David Howells [this message]
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=19095.1087213261@redhat.com \
--to=dhowells@redhat.com \
--cc=akpm@osdl.org \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@osdl.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox