Herbert Xu <[EMAIL PROTECTED]> writes:

> But your code differs significantly from Stephen's version.
> However, if it is correct it does look like a good improvement.
> 
> So please write a simple test program.  It can't that bad since
> there are only 65536 values to test :)

I think the code is simple enough to see immediately that it should
calculate the same checksum.  But I have written a short test program
to show this and tested it on i686 (gcc-4.2.2) and powerpc (gcc-3.4.5)
without optimization and with -O6.

BTW, shouldn't unsigned long be replaced by unsigned int to avoid
64-bit operations one some platforms?

urs


#include <stdio.h>

unsigned long f1(unsigned long sum)
{
    sum <<= 1;
    if (sum & 0x10000) {
        sum++;
        sum &= 0xffff;
    }
    return sum;
}

unsigned long f2(unsigned long sum)
{
    sum = ((sum & 0x8000)>>15) | ((sum & 0x7fff)<<1);
    return sum;
}

int main()
{
    unsigned long s;

    for (s = 0; s < 65536; s++) {
        if (f1(s) != f2(s) || f1(s) > 65535)
            printf("%ld\n", s);
    }
    return 0;
}
-
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to