/* Copyright 1984 by the Massachusetts Institute of Technology
 *
 * This routine computes the 16 bit ones complement checksum of an
 * array of words.
 *
 * Calling Sequence:
 * word	buf[];
 * int	nwords;
 * int	resid;
 * int	check;
 *
 * check = cksum(&buf, nwords, resid);
 *
 * Note: The actual checksum sent in the packet is
 * generally the complement of the number returned.
 * This (and the resid argument) are included so that
 * scatter/gather operations may be used on packets.
 */

.text

.globl	_cksum

_cksum:
	.word	0
	movl	4(ap),r2
	movl	8(ap),r1
	movl	12(ap),r0

1:	addw2	(r2)+,r0
	adwc	$0,r0
	sobgtr	r1,1b

	cvtwl	r0,r0
	ret


/* This routine updates a 1's complement checksum. Its arguments
 * are the old checksum and the difference between the new buffer
 * and the old one; for example, if one modifies a single word,
 * the value passed is (new-old).
 *
 * Calling sequence:
 *
 * int	diff, ocheck, ncheck;
 *
 * ncheck = acksum(diff, ocheck);
 */

.globl	_acksum

_acksum:
	.word	0
	addw3	4(ap),8(ap),r0
	adwc	$0,r0
	cvtwl	r0,r0
	ret
