ChecksumImpl.mesa
Copyright Ó 1987, 1988, 1991 by Xerox Corporation. All rights reserved.
For Portable Cedar
Carl Hauser, January 14, 1988 5:34:38 pm PST
Russ Atkinson (RRA) July 18, 1988 2:41:12 pm PDT
DIRECTORY
Basics USING [LongNumber],
Checksum;
ChecksumImpl: CEDAR PROGRAM
EXPORTS Checksum
~ BEGIN OPEN Checksum;
The following, and ComputeChecksumInline in the interface must compute exactly the same thing. Currently they do it by being exactly the same code.
ComputeChecksum: PUBLIC PROC [
cs: CARD16 ¬ 0, nHalfWords: CARDINAL, p: POINTER, offset: CARDINAL ¬ 0]
RETURNS [checksum: CARD16] ~ TRUSTED {
RawHalfwords: TYPE = RECORD [PACKED SEQUENCE COMPUTED CARDINAL OF CARD16];
phw: POINTER TO RawHalfwords ¬ LOOPHOLE[p];
FOR i: CARDINAL IN [offset..nHalfWords+offset) DO
cs ← ((cs ONESADD p^) LEFTROTATE 1)
t: Basics.LongNumber ¬ [lc[cs + phw[i]]];
t.lc ¬ (t.lo + t.hi)*2;
t.lc ¬ t.lo + t.hi;
cs ¬ t.lo;
ENDLOOP;
IF cs = CARD16.LAST THEN cs ¬ 0;
RETURN [cs];
};
END.
Carl Hauser, January 14, 1988 5:32:50 pm PST
A new implementation for 32 bit machines