On Mon, 17 Dec 2001, Ralf Baechle wrote:
> CVSROOT: /home/pub/cvs
> Module name: linux
> Changes by: ralf@oss.sgi.com 01/12/17 11:34:59
>
> Modified files:
> include/asm-mips64: Tag: linux_2_4 bitops.h
> include/asm-mips: Tag: linux_2_4 bitops.h
>
> Log message:
> Rewrite ffz(). Now compiles into code without any branches.
Depending on your compiler. Gcc seems to be smarter than GreenHills here :-)
--- /tmp/bitops.h Tue Dec 18 10:41:30 2001
+++ include/asm-mips/bitops.h Tue Dec 18 10:41:40 2001
@@ -679,17 +679,16 @@
*/
static inline unsigned long ffz(unsigned long word)
{
- unsigned long k;
+ int b = 0, s;
word = ~word;
- k = 31;
- if (word & 0x0000ffffUL) { k -= 16; word <<= 16; }
- if (word & 0x00ff0000UL) { k -= 8; word <<= 8; }
- if (word & 0x0f000000UL) { k -= 4; word <<= 4; }
- if (word & 0x30000000UL) { k -= 2; word <<= 2; }
- if (word & 0x40000000UL) { k -= 1; }
+ s = 16; if (word >> 16 == 0) s = 0; b += s; word >>= s;
+ s = 8; if (word >> 8 == 0) s = 0; b += s; word >>= s;
+ s = 4; if (word >> 4 == 0) s = 0; b += s; word >>= s;
+ s = 2; if (word >> 2 == 0) s = 0; b += s; word >>= s;
+ s = 1; if (word >> 1 == 0) s = 0; b += s;
- return k;
+ return b;
}
Would you mind changing the indentation? Unconditionally executed code on the
same line as conditionally executed code can be confusing...
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
|