From: Joel Soete <joel.soete@tiscali.be>
To: Grant Grundler <grundler@parisc-linux.org>,
Matthew Wilcox <willy@debian.org>,
parisc-linux@lists.parisc-linux.org
Subject: [parisc-linux] Re: [parisc-linux-cvs] Re: 2.6.0-test4-pa12 __fls()
Date: Sat, 06 Sep 2003 22:33:29 +0000 [thread overview]
Message-ID: <3F5A60B9.3050103@tiscali.be> (raw)
In-Reply-To: <3F5A4023.9070909@tiscali.be>
Hi Willy And Grant,
> On Fri, Sep 05, 2003 at 11:59:14PM -0600, Grant Grundler wrote:
> >/ > kudos to Joel Soete for mangling lamont's __ffs() to produce __fls().
/> >/ > Again, I added 64-bit support. Booted on a500.
/> >/ > Didn't test 32-bit but fls_test.c included in above URL works in user space.
/> >/ > (162 cycles per loop iteration, 00:29:01 to complete on 400Mhz PA8500).
/>
> Sorry, but it's clearly broken.
>
> >/ -#define fls(x) generic_fls(x)
/> >/ +static __inline__ unsigned long __fls(unsigned long x)
/> >/ +{
/> >/ + unsigned long ret;
/> >/ +
/> >/ + __asm__( " ldi 1,%1\n"
/> >/ +#if BITS_PER_LONG > 32
/> >/ + " extrd,u,*<> %0,63,32,%%r0\n"
/>
> if any of the bottom 32 bits are set ...
>
> >/ + " depd,*TR %0,31,32,%0\n"
/>
> move the bottom 32 bits up into the top 32 bits
>
> >/ + " addi 32,%1,%1\n"
/>
> otherwise add 32
>
> >/ +#endif
/>
> ... and then do things that can't see the top 32 bits.
hmm either I had to re-think the algo as you mentioned below
(so that to minimise the difference between 32 and 64 bits kernel)
or writing two distinct routine. (the 64 bits using depd,Z,*TR [...]
in place of 32 bits zdep
btw: is somebody knows how to compile with _hppa64-gcc_ shuch trivial loop
#include <stdio.h>
main()
{
unsigned long long i;
for (i=0; i<0xffffffffffffffffUL; i++) {
printf ("i = %#010x (%ll)\n", i);
}
}
(afair the problem if the call to printf() )
>
> >/ + " extru,<> %0,15,16,%%r0\n"
/> >/ + " zdep,TR %0,15,16,%0\n"
/> >/ + " addi 16,%1,%1\n"
/>
> think you could put in comments similar to the endian swapping? it makes
> the intent clearer to see.
My bad (in fact i was waiting some accept/reject comments before adding comment as pseudo_fls() was written)
> as far as i can tell, the basic principle
> here is..
>
> if (top N bits clear)
> shift N bits right
> else
> add N
>
> right?
Sorry, I trusted that pseudo_fls() in the mentionned message:
(http://lists.parisc-linux.org/pipermail/parisc-linux/2003-August/020628.html)
was enough ;)
>
> seems to me this whole thing should be done as
>
> if (any top N bits set)
> shift N bits left
> else
> subtract N
>
> >/ + " extru,<> %0,7,8,%%r19\n"
/>
> r19? That's not mentioned as being clobbered. I think you mean r0.
Yes a typo of mine (my bad sorry)
As i am in holidays, the pb is that I have no palinux box at my disposal to experiment another solution :(
Joel
PS: may i submit you an additional thought without any interest (may be):
the suggested code is "
+ return x ? (__ffs((unsigned long)x) + 1) : 0;
and if I refer to k&r book long is of 32bits lenght? (otc int is arch dependent)
But may be outdated by C99?
Thanks for additonal advise (and sorry for so much questions against so poor answers ;)
next parent reply other threads:[~2003-09-06 22:33 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <3F5A4023.9070909@tiscali.be>
2003-09-06 22:33 ` Joel Soete [this message]
2003-09-07 6:11 ` [parisc-linux] Re: [parisc-linux-cvs] Re: 2.6.0-test4-pa12 __fls() Randolph Chung
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=3F5A60B9.3050103@tiscali.be \
--to=joel.soete@tiscali.be \
--cc=grundler@parisc-linux.org \
--cc=parisc-linux@lists.parisc-linux.org \
--cc=willy@debian.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