[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ygfk5p7vvq7.fsf@janus.isnogud.escape.de>
Date: 28 Oct 2007 21:18:40 +0100
From: Urs Thuermann <urs.thuermann@....de>
To: Herbert Xu <herbert@...dor.apana.org.au>
Cc: joe@...ches.com (Joe Perches), davem@...emloft.net,
acme@...stprotocols.net, netdev@...r.kernel.org
Subject: Re: [PATCH] - trivial - Improve appletalk checksum calculation
Herbert Xu <herbert@...dor.apana.org.au> 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 majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Powered by blists - more mailing lists