[prev in list] [next in list] [prev in thread] [next in thread] 

List:       bird-users
Subject:    Re: question about func in Checksum.c
From:       Martin Mares <mj () ucw ! cz>
Date:       2001-03-06 23:39:00
[Download RAW message or body]

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

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic