From: Matt Turner <mattst88@xxxxxxxxx> Search only the first 100 bits instead of 140, saving a couple instructions. Also use inline assembly to use cmov instructions instead of letting gcc emit multiple branches. The resulting code is about 6x faster. Thanks to Zack Weinberg and Uros Bizjak (GCC Bug 43691) for helping me identify problems with the inline assembly. Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx> Cc: Ingo Molnar <mingo@xxxxxxx> Cc: Richard Henderson <rth@xxxxxxxxxxx> Cc: Ivan Kokshaysky <ink@xxxxxxxxxxxxxxxxxxxx> Cc: linux-alpha@xxxxxxxxxxxxxxx Signed-off-by: Matt Turner <mattst88@xxxxxxxxx> --- arch/alpha/include/asm/bitops.h | 24 ++++++++++++------------ 1 files changed, 12 insertions(+), 12 deletions(-) diff --git a/arch/alpha/include/asm/bitops.h b/arch/alpha/include/asm/bitops.h index 15f3ae2..cfa7526 100644 --- a/arch/alpha/include/asm/bitops.h +++ b/arch/alpha/include/asm/bitops.h @@ -436,22 +436,22 @@ static inline unsigned int hweight8(unsigned int w) /* * Every architecture must define this function. It's the fastest - * way of searching a 140-bit bitmap where the first 100 bits are - * unlikely to be set. It's guaranteed that at least one of the 140 - * bits is set. + * way of searching a 100-bit bitmap. It's guaranteed that at least + * one of the 100 bits is cleared. */ static inline unsigned long -sched_find_first_bit(unsigned long b[3]) +sched_find_first_bit(const unsigned long b[2]) { - unsigned long b0 = b[0], b1 = b[1], b2 = b[2]; unsigned long ofs; - - ofs = (b1 ? 64 : 128); - b1 = (b1 ? b1 : b2); - ofs = (b0 ? 0 : ofs); - b0 = (b0 ? b0 : b1); - - return __ffs(b0) + ofs; + unsigned long output; + asm( + "cmoveq %0,64,%1 # ofs = (b[0] ? ofs : 64);\n" + "cmoveq %0,%2,%0 # temp = (b[0] ? b[0] : b[1]);\n" + "cttz %0,%0 # output = cttz(temp);\n " + : "=r" (output), "=r" (ofs) + : "r" (b[1]), "0" (b[0]), "1" (0) + ); + return output + ofs; } #include <asm-generic/bitops/ext2-non-atomic.h> -- 1.6.4.4 -- To unsubscribe from this list: send the line "unsubscribe linux-alpha" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html