question about func in Checksum.c

Martin Mares mj at ucw.cz
Wed Mar 7 00:39:00 CET 2001


Hi!

> 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.
> 
>   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;

The first one isn't redundant, but the code could be rewritten to avoid
it:

	if (...)
	  {
	    ...
	    len -= 2;
	  }
	rest = len & 2;
	len >>= 2;

But this optimization probably doesn't matter since the checksum function
setup is not time critical, at least when compared with the checksumming
loop a few lines below.

				Have a nice fortnight
-- 
Martin `MJ' Mares   <mj at ucw.cz>   http://atrey.karlin.mff.cuni.cz/~mj/
Faculty of Math and Physics, Charles University, Prague, Czech Rep., Earth
It's God. No, not Richard Stallman, not Linus Torvalds, but God.



More information about the Bird-users mailing list