lkml.org 
[lkml]   [2007]   [Mar]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    Date
    From
    Subject[PATCH] tcp_cubic: use 32 bit math
    The basic calculation has to be done in 32 bits to avoid
    doing 64 bit divide by 3. The value x is only 22bits max
    so only need full 64 bits only for x^2.

    Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org>

    ---
    net/ipv4/tcp_cubic.c | 8 ++++----
    1 file changed, 4 insertions(+), 4 deletions(-)

    --- net-2.6.22.orig/net/ipv4/tcp_cubic.c 2007-03-07 15:51:37.000000000 -0800
    +++ net-2.6.22/net/ipv4/tcp_cubic.c 2007-03-07 17:06:02.000000000 -0800
    @@ -96,7 +96,7 @@
    */
    static u32 cubic_root(u64 a)
    {
    - u64 x;
    + u32 x;

    /* Initial estimate is based on:
    * cbrt(x) = exp(log(x) / 3)
    @@ -104,9 +104,9 @@
    x = 1u << (fls64(a)/3);

    /* converges to 32 bits in 3 iterations */
    - x = (2 * x + div64_64(a, x*x)) / 3;
    - x = (2 * x + div64_64(a, x*x)) / 3;
    - x = (2 * x + div64_64(a, x*x)) / 3;
    + x = (2 * x + (u32)div64_64(a, (u64)x*(u64)x)) / 3;
    + x = (2 * x + (u32)div64_64(a, (u64)x*(u64)x)) / 3;
    + x = (2 * x + (u32)div64_64(a, (u64)x*(u64)x)) / 3;

    return x;
    }
    -
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/
    \
     
     \ /
      Last update: 2007-03-08 02:15    [W:0.021 / U:31.524 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site