Re: patch parport/bitops

Alexander Kjeldaas (astor@guardian.no)
Sun, 26 Apr 1998 21:18:48 +0200


> diff -u -r -N linux-2.1.97-orig/include/asm-ppc/bitops.h linux/include/asm-ppc/bitops.h
> --- linux-2.1.97-orig/include/asm-ppc/bitops.h Sat Aug 16 18:51:09 1997
> +++ linux/include/asm-ppc/bitops.h Wed Apr 22 09:29:09 1998
> @@ -97,6 +97,70 @@
> }
>
> /*
> + * ffs: find first bit set. This is defined the same way as
> + * the libc and compiler builtin ffs routines, therefore
> + * differs in spirit from the above ffz (man ffs).
> + */
> +
> +extern __inline__ int ffs(int x)
> +{
[...]

On the PowerPC there is an instruction called 'cntlzw' - count leading
zeros word which does the above.

something like the following, but take it with a grain of salt since
I've never done any PowerPC programming before and I don't have a
machine to test this on.

extern __inline__ int ffs(int x)
{
int result;
asm ("cntlzw %0,%1" : "=r" (result) : "r" (x));
return 32 - result; /* IBM backwards ordering of bits */
}

astor

-- 
 Alexander Kjeldaas, Guardian Networks AS, Trondheim, Norway
 http://www.guardian.no/

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu