On 4/30/2014 4:24 PM, koeppea wrote:
> In src/ec_checksum.c:
>
>>  #endif
>>
>> -   while(csum >> 16)
>> -      csum = (csum >> 16) + (csum & 0xffff);
>> +   csum = (csum >> 16) + (csum & 0xffff);
>> +   csum += (csum >> 16);
>
> Isn't
>
> while(csum  >>  16)
>        csum  =  (csum  >>  16)  +  (csum  &  0xffff);
>
> something different than
>
>     csum  =  (csum  >>  16)  +  (csum  &  0xffff);
>     csum  +=  (csum  >>  16);
>
> assuming /csum/ is > 2*16?

Functionally equivalent. Coming from algebra, adding any two n-bit 
integers will give a result no larger than what can be represented in a 
(n+1)-bit integer.

The first operation

csum  =  (csum  >>  16)  +  (csum  &  0xffff);

may result in a carry into the 16th bit (0 indexing...). Adding a one to 
the result that just carried will not result in a carry.

In the simple case of 8-bit integers,

0xff + 0xff = 0x1fe (carry indicated by the 8th bit)

Then when we shift and accumulate,

0xfe + 0x01 = 0xff

.