diff options
author | Stephen Hemminger <shemminger@linux-foundation.org> | 2007-03-25 23:21:15 -0400 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2007-04-26 01:23:47 -0400 |
commit | c5f5877c043ca471c3a607fa2c864848b19bc49a (patch) | |
tree | b28d6cf22a0fc96f86a5c07a1b64cd8a2d3c7668 /net | |
parent | 8570419fb7be0af84085ac8f13307392a748482c (diff) |
[TCP] tcp_cubic: faster cube root
The Newton-Raphson method is quadratically convergent so
only a small fixed number of steps are necessary.
Therefore it is faster to unroll the loop. Since div64_64 is no longer
inline it won't cause code explosion.
Also fixes a bug that can occur if x^2 was bigger than 32 bits.
Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r-- | net/ipv4/tcp_cubic.c | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/net/ipv4/tcp_cubic.c b/net/ipv4/tcp_cubic.c index 6f08adbda54e..0e6cdfeb207a 100644 --- a/net/ipv4/tcp_cubic.c +++ b/net/ipv4/tcp_cubic.c | |||
@@ -96,23 +96,17 @@ static void bictcp_init(struct sock *sk) | |||
96 | */ | 96 | */ |
97 | static u32 cubic_root(u64 a) | 97 | static u32 cubic_root(u64 a) |
98 | { | 98 | { |
99 | u32 x, x1; | 99 | u32 x; |
100 | 100 | ||
101 | /* Initial estimate is based on: | 101 | /* Initial estimate is based on: |
102 | * cbrt(x) = exp(log(x) / 3) | 102 | * cbrt(x) = exp(log(x) / 3) |
103 | */ | 103 | */ |
104 | x = 1u << (fls64(a)/3); | 104 | x = 1u << (fls64(a)/3); |
105 | 105 | ||
106 | /* | 106 | /* converges to 32 bits in 3 iterations */ |
107 | * Iteration based on: | 107 | x = (2 * x + (u32)div64_64(a, (u64)x*(u64)x)) / 3; |
108 | * 2 | 108 | x = (2 * x + (u32)div64_64(a, (u64)x*(u64)x)) / 3; |
109 | * x = ( 2 * x + a / x ) / 3 | 109 | x = (2 * x + (u32)div64_64(a, (u64)x*(u64)x)) / 3; |
110 | * k+1 k k | ||
111 | */ | ||
112 | do { | ||
113 | x1 = x; | ||
114 | x = (2 * x + (uint32_t) div64_64(a, x*x)) / 3; | ||
115 | } while (abs(x1 - x) > 1); | ||
116 | 110 | ||
117 | return x; | 111 | return x; |
118 | } | 112 | } |