question about func in Checksum.c
Zheng Yuan {ZYUAN1}
zyuan1 at cig.mot.com
Tue Mar 6 16:41:25 CET 2001
Hi, all
I have a question about the func static u16 ipsum_calc_block(u16 *x,
unsigned len, u16 sum)
I guess we dont need the first len >>= 1 i know we want to move 32 bits at
one time, so second len >>= 1 can do it. The first one is redundant.
static u16 ipsum_calc_block(u16 *x, unsigned len, u16 sum) {
int rest;
u32 tmp, *xx;
ASSERT(!(len % 2));
if (!len)
return sum;
len >>= 1;
if ((unsigned long) x & 2) /* Align to 32-bit boundary, use x's address
*/
{
sum = add16(sum, *x++);
len--;
}
rest = len & 1;
len >>= 1;
tmp = 0;
xx = (u32 *) x;
while (len)
{
tmp = add32(tmp, *xx++);
len--;
}
sum = add16(sum, add16(tmp & 0xffff, tmp >> 16U));
if (rest)
sum = add16(sum, *(u16 *) xx);
return sum;
}
More information about the Bird-users
mailing list