Re: [PATCH] Remove some divide instructions

From: Linus Torvalds
Date: Wed Oct 27 2004 - 11:42:31 EST




On Wed, 27 Oct 2004, Zachary Amsden wrote:
>
> I noticed several 64-bit divides for HZ/USER_HZ, and also the fact that
> HZ == USER_HZ on many architectures (or if you play with scaling it ;).
> Since do_div is macroized to optimized assembler on many platforms, we
> emit long divides for divide by one. This could be extended further to
> recognize other power of two divides, but I don't think the complexity
> of the macros would be justified. I also didn't feel it was worthwhile
> to optimize this for non-constant divides; if you feel otherwise, please
> extend.

Can you test out the trivial extension, which is to allow any power-of-two
constant, and just leave it as a divide in those cases (and let the
compiler turn it into a 64-bit shift)?

It's very easy to test for powers of two: !((x) & ((x)-1)) does it for
everything but zero, and zero in this case is an error anyway.

Linus
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/