lwip-users
[Top][All Lists]
Advanced

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

Re: [lwip-users] RE:Re: Checksum problem with lwip_chksum()


From: Jim Gibbons
Subject: Re: [lwip-users] RE:Re: Checksum problem with lwip_chksum()
Date: Fri, 03 Sep 2004 15:18:28 -0700
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.1) Gecko/20040707

Perhaps it might be wise to move lwip_chksum into sys_arch.c? 

If that were done, then the chksum could be implemented in a manner appropriate to the CPU and compiler in question.  Since the algorithm operates on all the data in all tcp and udp packets, speed is a pretty important consideration.

Chris WIlliams wrote:
We all have our own way of coding. This is my routine at the moment.

I can't tell if this is faster of slower than John Taylors. If people
find this of use, could it be included properly?

Good luck.

static u16_t
lwip_chksum(void *dataptr, int len)
{
  u32_t acc = 0;
        unsigned char *dp = (unsigned char *)dataptr;
        int half_len;

        for(half_len = len / 2;half_len;half_len--){
                acc += ((u16_t)*dp++) << 8;
                acc += *dp++;
        }
        if(len & 1){
                acc += ((u16_t)*dp++) << 8;
        }

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

  if ((acc & 0xffff0000L) != 0) {
         acc = (acc >> 16) + (acc & 0xffffUL);
  }
  return (u16_t)acc;
}

  

--
E-mail signature
Jim Gibbons
address@hidden
Gibbons and Associates, Inc.
TEL: (408) 984-1441
900 Lafayette, Suite 704, Santa Clara, CA
FAX: (408) 247-6395



reply via email to

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