Messages in this thread | | | Date | Mon, 2 Feb 2015 11:13:44 -0800 | Subject | Re: [PATCH] lib/int_sqrt.c: Optimize square root function | From | Linus Torvalds <> |
| |
On Mon, Feb 2, 2015 at 11:00 AM, Linus Torvalds <torvalds@linux-foundation.org> wrote: > > (I'm also not entirely sure what uses int_sqrt() that ends up being so > performance-critical, so it would be good to document that too, since > that probably also matters for the "what's the normal argument range" > question..)
... it's also not entirely clear that we need a whole new loop. We might just instead start off with a better guess for 'm' using some calculation that might be doable with a single conditional move instruction instead of a loop. Because I suspect that the inevitable branch misprediction of a new loop is likely as expensive as a few iterations through the core one.
IOW, instead of
m = 1UL << (BITS_PER_LONG - 2);
perhaps something like
m = 1UL << (BITS_PER_LONG/2- 2); if (m < x) m <<= BITS_PER_LONG/2;
(assuming gcc can change that code into a "cmov") might cut down the "lots of empty loops" case in half for small values of 'x'.
There's probably some other better cheap initial guess value estimator.
Linus
| |