Linux PARISC architecture development
 help / color / mirror / Atom feed
* [parisc-linux] bitops.h: fls(unsigned long )
@ 2004-08-23 18:50 Joel Soete
       [not found] ` <412135A8000049BB@ocpmta3.freegates.net>
  0 siblings, 1 reply; 4+ messages in thread
From: Joel Soete @ 2004-08-23 18:50 UTC (permalink / raw)
  To: parisc-linux

Hi all,

As promised (a year ago now; shame on me :( ), here is a first draft of fls(unsigned long) thanks to help of "Michael S. Zick":
--- linux-2.6.8.1-pa7/include/asm-parisc/bitops.h.Orig  2004-08-15 20:27:42.000000000 +0200
+++ linux-2.6.8.1-pa7/include/asm-parisc/bitops.h       2004-08-23 17:09:12.190000000 +0200
@@ -273,31 +273,38 @@
   * fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
   */

-static __inline__ int fls(int x)
+static __inline__ int fls(unsigned long x)
  {
-       int ret;
-       if (!x)
-               return 0;
+       unsigned long ret;

         __asm__(
-       "       ldi             1,%1\n"
-       "       extru,<>        %0,15,16,%%r0\n"
-       "       zdep,TR         %0,15,16,%0\n"          /* xxxx0000 */
-       "       addi            16,%1,%1\n"
-       "       extru,<>        %0,7,8,%%r0\n"
-       "       zdep,TR         %0,23,24,%0\n"          /* xx000000 */
-       "       addi            8,%1,%1\n"
-       "       extru,<>        %0,3,4,%%r0\n"
-       "       zdep,TR         %0,27,28,%0\n"          /* x0000000 */
-       "       addi            4,%1,%1\n"
-       "       extru,<>        %0,1,2,%%r0\n"
-       "       zdep,TR         %0,29,30,%0\n"          /* y0000000 (y&3 = 0) */
-       "       addi            2,%1,%1\n"
-       "       extru,=         %0,0,1,%%r0\n"
-       "       addi            1,%1,%1\n"              /* if y & 8, add 1 */
+#ifdef __LP64__
+               " ldi           64,%1\n"
+               " extrd,u,*=    %0,31,32,%%r0\n"
+               " extrd,u,*TR   %0,31,32,%0\n"  /* move top 32-bits down */
+               " addi          -32,%1,%1\n"
+#else
+               " ldi           32,%1\n"
+#endif
+               " extru,=       %0,15,16,%%r0\n"
+               " extru,TR      %0,15,16,%0\n"  /* xxxx0000 -> 0000xxxx */
+               " addi          -16,%1,%1\n"
+               " extru,=       %0,23,8,%%r0\n"
+               " extru,TR      %0,23,8,%0\n"   /* 0000xx00 -> 000000xx */
+               " addi          -8,%1,%1\n"
+               " extru,=       %0,27,4,%%r0\n"
+               " extru,TR      %0,27,4,%0\n"   /* 000000x0 -> 0000000x */
+               " addi          -4,%1,%1\n"
+               " extru,=       %0,29,2,%%r0\n"
+               " extru,TR      %0,29,2,%0\n"   /* 0000000y, 1100b -> 0011b */
+               " addi          -2,%1,%1\n"
+               " extru,=       %0,30,1,%%r0\n"
+               " extru,TR      %0,30,1,%0\n"   /* 0000000z, 10b -> 01b */
+               " addi          -1,%1,%1\n"
+               " extru,<>      %0,31,1,%%r0\n" /* check last bit */
+               " addi          -1,%1,%1\n"
                 : "+r" (x), "=r" (ret) );

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [parisc-linux] bitops.h: fls(unsigned long )
       [not found] ` <412135A8000049BB@ocpmta3.freegates.net>
@ 2004-08-24 16:45   ` Carlos O'Donell
       [not found]     ` <412135A800004CFE@ocpmta3.freegates.net>
  0 siblings, 1 reply; 4+ messages in thread
From: Carlos O'Donell @ 2004-08-24 16:45 UTC (permalink / raw)
  To: Joel Soete; +Cc: parisc-linux

On Tue, Aug 24, 2004 at 02:51:59PM +0200, Joel Soete wrote:
> Hi all,
> 
> Sorry for this auto-reply but I just reboot with success my N4k (smp 64bit
> kernel 2.6.8.1-pa7) with this patch and all works fine :)
> 
> If Ok for everybody can somebody ci for me (no cvs access :) )?

Do you have a 32-bit test program that shows this code works?

I'm one for writing a small test to verify that the code is doing what
the specification says it should.

c.

_______________________________________________
parisc-linux mailing list
parisc-linux@lists.parisc-linux.org
http://lists.parisc-linux.org/mailman/listinfo/parisc-linux

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [parisc-linux] bitops.h: fls(unsigned long )
       [not found] <20040824172230.GA16196@parcelfarce.linux.theplanet.co.uk>
@ 2004-08-25  6:41 ` Joel Soete
  0 siblings, 0 replies; 4+ messages in thread
From: Joel Soete @ 2004-08-25  6:41 UTC (permalink / raw)
  To: Matthew Wilcox; +Cc: parisc-linux


> On Tue, Aug 24, 2004 at 02:51:59PM +0200, Joel Soete wrote:
> > Sorry for this auto-reply but I just reboot with success my N4k (smp
64bit
> > kernel 2.6.8.1-pa7) with this patch and all works fine :)
> > 
> > If Ok for everybody can somebody ci for me (no cvs access :) )?
> 
> > > -static __inline__ int fls(int x)
> > > +static __inline__ int fls(unsigned long x)
> 
> This is absolutely not OK.  fls is prototyped to have an int parameter,=

> not an unsigned long.  Why do you want to do this, anyway?
> 
Oops: the original idea was to propose the equivalence of  __ffs(unsingne=
d
long). 

My bad.

Anyway it's tested fully ok and if we need it later, it's at least availa=
ble
in the list ;)

Thanks for advise,
    Joel

-------------------------------------------------------------------------=
--
Tiscali ADSL LIGHT, 19,95 EUR/mois pendant 6 mois, c'est le moment de fai=
re
le pas!
http://reg.tiscali.be/default.asp?lg=3Dfr




_______________________________________________
parisc-linux mailing list
parisc-linux@lists.parisc-linux.org
http://lists.parisc-linux.org/mailman/listinfo/parisc-linux

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [parisc-linux] bitops.h: fls(unsigned long )
       [not found]     ` <412135A800004CFE@ocpmta3.freegates.net>
@ 2004-08-25 20:10       ` Carlos O'Donell
  0 siblings, 0 replies; 4+ messages in thread
From: Carlos O'Donell @ 2004-08-25 20:10 UTC (permalink / raw)
  To: Joel Soete; +Cc: parisc-linux

On Tue, Aug 24, 2004 at 07:06:02PM +0200, Joel Soete wrote:
> And even a 64bit (using jejb 64bit lib :), just don't inline fls (if inline
> it does a segfault when finish)):
> 
> See attachment:
> bitops-tc3.c

Thanks! I'll check this out in 5 days, I'm very busy right now. If it
looks to work I'll check the test into out userspace test area.

Then I'll look at the kernel stuff.

c.

_______________________________________________
parisc-linux mailing list
parisc-linux@lists.parisc-linux.org
http://lists.parisc-linux.org/mailman/listinfo/parisc-linux

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2004-08-25 20:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-08-23 18:50 [parisc-linux] bitops.h: fls(unsigned long ) Joel Soete
     [not found] ` <412135A8000049BB@ocpmta3.freegates.net>
2004-08-24 16:45   ` Carlos O'Donell
     [not found]     ` <412135A800004CFE@ocpmta3.freegates.net>
2004-08-25 20:10       ` Carlos O'Donell
     [not found] <20040824172230.GA16196@parcelfarce.linux.theplanet.co.uk>
2004-08-25  6:41 ` Joel Soete

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox