[Codel] fp sqrt vis int sqrt?

Eric Dumazet eric.dumazet at gmail.com
Sat May 5 04:14:12 EDT 2012


On Fri, 2012-05-04 at 21:16 +0200, Eric Dumazet wrote:
> On Fri, 2012-05-04 at 12:04 -0700, Dave Taht wrote:
> 
> > Late this evening I'll have time to incorporate the progress so far
> > today (thx for the cleanups and help!!!) and I'll try to get another
> > patch out late tonight. Unless you beat me to it.
> > 
> 
> I am not planning to send a patch in a near future, its 9h15pm here in
> France, and TGIF.
> 
> 

Oh well, this is obvious, just use the following and be done :

/* return interval/sqrt(x) with good precision
 */
u32 int_sqrt_div(u32 _interval, unsigned long x)
{
	u64 interval = _interval;

	/* scale for maximum precision */
	while (x < (1UL << (BITS_PER_LONG - 2))) {
		x <<= 2;
		interval <<= 1;
	}
	do_div(interval, int_sqrt(x));
	return (u32)interval;
}

Doing the scaling before calling int_sqrt() makes int_sqrt() faster,
since we avoid the initial scaling on 'one'

	one = 1UL << (BITS_PER_LONG - 2);
	while (one > op)
		one >>= 2;

Always sleep a bit, its good.






More information about the Codel mailing list