IP checksum code (was: Re: cvs commit: src/sys/dev/bge if_bge.c)

Alexander Leidinger netchild at FreeBSD.org
Tue Feb 7 01:34:42 PST 2006

Bruce Evans <bde at zeta.org.au> wrote:

> in_pseudo() handles both carry steps, but is fairly bogus.  Here is the
> i386 version:
> % static __inline u_short
> % in_pseudo(u_int sum, u_int b, u_int c)
> % {
> % 	/* __volatile is necessary because the condition codes are used. */
> % 	__asm __volatile ("addl %1, %0" : "+r" (sum) : "g" (b));
> % 	__asm __volatile ("adcl %1, %0" : "+r" (sum) : "g" (c));
> % 	__asm __volatile ("adcl $0, %0" : "+r" (sum));
> The asms here are mostly bogus, if not broken.

Andre got patches which port the completely rewritten version of the IP
checksum code from DragonFly to FreeBSD (an entry for this was part of a
previous version of the FreeBSD ideas list but was removed in the initial
commit of the list, since the item was already taken and done). According to
Matt's description in DragonFly this fixes some bugs (specially in the asm

AFAIK Andre told the submitter to have a look at it as part of his network
related work. IIRC: in the benchmarks I've seen, this patch also improves
the speed of the checksumming.


http://www.Leidinger.net  Alexander @ Leidinger.net: PGP ID = B0063FE7
http://www.FreeBSD.org     netchild @ FreeBSD.org  : PGP ID = 72077137
God said it, I believe it and that's all there is to it.

More information about the cvs-src mailing list