Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83; site umcp-cs.UUCP Path: utzoo!linus!philabs!seismo!rlgvax!cvl!umcp-cs!chris From: chris@umcp-cs.UUCP Newsgroups: net.bugs.uucp Subject: Re: Bug in pk0.c on 32 bit machines Message-ID: <674@umcp-cs.UUCP> Date: Sat, 9-Jul-83 21:10:02 EDT Article-I.D.: umcp-cs.674 Posted: Sat Jul 9 21:10:02 1983 Date-Received: Sun, 10-Jul-83 04:53:32 EDT References: <113@felix.UUCP> Organization: Univ. of Maryland, Computer Science Dept. Lines: 54 Yeah, that checksum routine (shall we say) sucks. I did a profile of our (slightly modified) 4.1BSD uucico on our CVL connection, which is a 9600 baud hardwired link. Uucico was spending most of its time in system calls, namely read, write, and any directory-touching calls, but chksum() was the top user-level CPU eater. No wonder: it uses "register unsigned short"s, which (on VAXen) means unsigned shorts. This is ridiculously expensive, so I rewrote it. Here's what I've got now; this has been working for about a month with no trouble. It gets turned into much nicer code, especially after optimization. # if vax /* * Vax-specific checksum generator, same checksum as portable version * but faster. NOTE: ASSUMES n < 65535 * 14 June 1983 * Chris Torek * University of Maryland */ chksum (s, n) register char *s; register n; { register sum, x; register unsigned t; sum = -1; x = 0; do { /* Rotate left, copying bit 15 to bit 0 */ if (sum & 0x8000) sum <<= 1, sum++; else sum <<= 1; sum &= 0xffff; /* Switch to unsigned short */ t = sum; sum = (sum + (*s++ & 0377)) & 0xffff; x += sum ^ n; if ((unsigned)sum <= t) /* (unsigned) not necessary */ sum ^= x; /* but doesn't hurt */ } while (--n > 0); return (int) (short) sum; } # else (not vax) [ original routine, elided due to licensing ] # endif (vax) -- UUCP: {seismo,allegra,brl-bmd}!umcp-cs!chris CSNet: chris@umcp-cs ARPA: chris.umcp-cs@UDel-Relay