lwip-devel
[Top][All Lists]
Advanced

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

[lwip-devel] Checksum optimizations


From: Bill Auerbach
Subject: [lwip-devel] Checksum optimizations
Date: Mon, 25 Feb 2008 13:10:00 -0500

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?  Wouldn’t this be slightly more efficient?

 

    if ((acc >> 16) != 0) {

      acc = (acc & 0xffffUL) + 1;

    }

 

This is true because LWIP_CHKSUM returns a u16_t and at most the one preceding add to acc can carry a 1.  Additionally:

 

u16_t

inet_chksum(void *dataptr, u16_t len)

{

  u32_t acc;

 

  acc = LWIP_CHKSUM(dataptr, len);

  while ((acc >> 16) != 0) {

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

  }

  return (u16_t)~(acc & 0xffff);

}

 

Can be:

 

u16_t

inet_chksum(void *dataptr, u16_t len)

{

  u32_t acc;

 

  acc = LWIP_CHKSUM(dataptr, len);

  return (u16_t)~(acc & 0xffff);

}

 

Because LWIP_CHKSUM returns a u16_t and thus the while loop can never execute.

 

Bill


reply via email to

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