From: Arnaldo Carvalho de Melo <acme@conectiva.com.br>
To: Stephen Hemminger <shemminger@osdl.org>
Cc: Joe Perches <joe@perches.com>, netdev@oss.sgi.com
Subject: Re: [IPX]: Fix checksum computation.
Date: Fri, 31 Oct 2003 23:13:01 -0200 [thread overview]
Message-ID: <20031101011301.GW3705@conectiva.com.br> (raw)
In-Reply-To: <20031031163843.6bcf4ca4.shemminger@osdl.org>
Em Fri, Oct 31, 2003 at 04:38:43PM -0800, Stephen Hemminger escreveu:
>
> Okay, here is the standard: (Inside Appletalk)
>
> > The DDP checksum is provided to detect errors caused by faulty operation (such as memor
> > data bus errors) within routers on the internet. Implementers of DDP should treat generati
> > the checksum as an optional feature. The 16-bit DDP checksum is computed as follows:
> > CkSum := 0 ;
> > FOR each datagram byte starting with the byte immediately following th
> > Checksum field
> > REPEAT the following algorithm:
> > CkSum := CkSum + byte; (unsigned addition)
> > Rotate CkSum left one bit, rotating the most significant bit in
> > least significant bit;
> > IF, at the end, CkSum = 0 THEN
> > CkSum := $FFFF (all ones).
> > Reception of a datagram with CkSum equal to 0 implies that a checksum is not performed.
>
>
> Here is the old loop:
>
> while (len--) {
> sum += *data;
> sum <<=1;
> if (sum & 0x10000) {
> sum++;
> sum &= 0xffff;
> }
> data++;
> }
>
> My buggy loop is:
>
> while (len--) {
> sum += *data++;
> sum <<= 1;
> sum = ((sum >> 16) + sum) & 0xFFFF;
> }
>
> The problem is the carry from the first addition needs to be dropped
> not folded back (like IP).
>
> Corrected fast code is:
>
> while (len--) {
> sum += *data++;
> sum <<= 1;
> sum = (((sum & 0x10000) >> 16) + sum) & 0xffff;
> }
>
> At least it is correct on the standalone random data test, and the
> new code is 30% faster for the cached memory case (13.7 clks/byte vs 18 clks/byte).
Testing...
next prev parent reply other threads:[~2003-11-01 1:13 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <200310312006.h9VK62Hh005910@hera.kernel.org>
2003-10-31 21:24 ` [IPX]: Fix checksum computation Joe Perches
2003-10-31 21:23 ` David S. Miller
2003-10-31 21:34 ` Arnaldo Carvalho de Melo
2003-10-31 21:50 ` Joe Perches
2003-10-31 21:53 ` David S. Miller
2003-10-31 22:21 ` Stephen Hemminger
2003-10-31 22:46 ` Arnaldo Carvalho de Melo
2003-11-01 0:25 ` David S. Miller
2003-10-31 21:56 ` Arnaldo Carvalho de Melo
2003-10-31 23:29 ` Mark Huth
2003-11-01 0:31 ` Joe Perches
2003-11-01 0:31 ` David S. Miller
2003-10-31 21:31 ` Arnaldo Carvalho de Melo
2003-11-01 0:38 ` Stephen Hemminger
2003-11-01 1:13 ` Arnaldo Carvalho de Melo [this message]
2003-11-01 1:19 ` Arnaldo Carvalho de Melo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20031101011301.GW3705@conectiva.com.br \
--to=acme@conectiva.com.br \
--cc=joe@perches.com \
--cc=netdev@oss.sgi.com \
--cc=shemminger@osdl.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).