lwip-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-devel] Checksum optimizations


From: Jonathan Larmour
Subject: Re: [lwip-devel] Checksum optimizations
Date: Mon, 10 Mar 2008 14:13:02 +0000
User-agent: Thunderbird 1.5.0.12 (X11/20070530)

David Empson wrote:
> Bill Auerbach wrote:
> 
>> In the inet_chksum.c code, there are 6 occurrences of:
>>
>>    while ((acc >> 16) != 0) {
>>      acc = (acc & 0xffffUL) + (acc >> 16);
>>    }
>>
>> Is it not true that the loop can run a maximum of once?
[David explains when it can run more]
>  
> The following code is correct in all situations:
>  
> if ((acc >> 16) != 0) {
>  acc = (acc & 0xffffUL) + (acc >> 16);
>  if ((acc >> 16) != 0) {
>   acc = (acc & 0xffffUL) + 1;
>  }
> }
>  
> The first 'if' could be omitted if there is a high probability that it
> will be true.

As Andrey Volkov hinted, the 'if' tests are probably expensive enough (and
addition/shift/mask cheap enough) that it would probably be better to just
have:

acc = (acc & 0xffffUL) + (acc >> 16);
acc = (acc & 0xffffUL) + (acc >> 16);

I'm not sure this will go into 1.3.0 at this point (even though it's
simple) so it's probably best to post a patch at
https://savannah.nongnu.org/patch/?func=additem&group=lwip so this is
picked up after 1.3.0.

Bill, care to do this?

Jifl
-- 
eCosCentric Limited      http://www.eCosCentric.com/     The eCos experts
 **  Visit us at ESC Silicon Valley <http://www.embedded.com/esc/sv>  **
 **  April 15-17 2008, Booth 3012, San Jose McEnery Convention Center **
Barnwell House, Barnwell Drive, Cambridge, UK.       Tel: +44 1223 245571
Registered in England and Wales: Reg No 4422071.
------["Si fractum non sit, noli id reficere"]------       Opinions==mine




reply via email to

[Prev in Thread] Current Thread [Next in Thread]