Re: Checksums (was Re: Ping, checksum algorithm?)


Phil R. Karn (thumper!karn@faline.bellcore.com)
24 Mar 88 07:07:53 GMT


Thanks for an excellent tutorial on checksumming. Some additional notes:

The Internet checksum algorithm has an interesting property that is very
useful when working on little-endian machines: the sum of the
byte-swapped words is equal to the byte-swapped sum of the words. In
other words, there is no need to byteswap each word on a little-endian
machine before summing it; you can sum the words in machine order and
then byteswap the result.

If you write an "assist" routine in assembler you can exploit the "add with
carry" instruction found in many machines. E.g., on the 808x family, you
can accumulate a sum as follows:

doit: lodsw
        adc dx,ax
        loop doit

(once you've set everything up, of course). This can speed up
checksumming enormously on 16-bit machines like the PC since the long
(32-bit) arithmetic you would normally use to accumulate the carries is
much slower. The actual code I use goes further, in that I unwound the
loop and used "Duff's Device" to handle blocks that are not integral
multiples of the loop length.

Phil



This archive was generated by hypermail 2.0b3 on Thu Mar 09 2000 - 14:41:32 GMT