From: Ian Abbott <abbotti@mev.co.uk> Date: 2011-07-07 11:19:14
Reduce the number of variables modified by the loop in do_csum() by 1,
which seems like a good idea. On Nios II (a RISC CPU with 3-operand
instruction set) it reduces the loop from 7 to 6 instructions, including
the conditional branch.
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
---
lib/checksum.c | 13 +++++--------
1 files changed, 5 insertions(+), 8 deletions(-)
@@ -49,7 +49,7 @@ static inline unsigned short from32to16(unsigned int x)staticunsignedintdo_csum(constunsignedchar*buff,intlen){-intodd,count;+intodd;unsignedintresult=0;if(len<=0)
@@ -64,25 +64,22 @@ static unsigned int do_csum(const unsigned char *buff, int len)len--;buff++;}-count=len>>1;/* nr of 16-bit words.. */-if(count){+if(len>=2){if(2&(unsignedlong)buff){result+=*(unsignedshort*)buff;-count--;len-=2;buff+=2;}-count>>=1;/* nr of 32-bit words.. */-if(count){+if(len>=4){+constunsignedchar*end=buff+((unsigned)len&~3);unsignedintcarry=0;do{unsignedintw=*(unsignedint*)buff;-count--;buff+=4;result+=carry;result+=w;carry=(w>result);-}while(count);+}while(buff<end);result+=carry;result=(result&0xffff)+(result>>16);}
Reduce the number of variables modified by the loop in do_csum() by 1,
which seems like a good idea. On Nios II (a RISC CPU with 3-operand
instruction set) it reduces the loop from 7 to 6 instructions, including
the conditional branch.
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
I think you'll overshoot past the end of the buffer when there are
trailing bytes to handle.
The whole reason we need the count variable is to handle those
kinds of cases.
Reduce the number of variables modified by the loop in do_csum() by 1,
which seems like a good idea. On Nios II (a RISC CPU with 3-operand
instruction set) it reduces the loop from 7 to 6 instructions, including
the conditional branch.
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
I think you'll overshoot past the end of the buffer when there are
trailing bytes to handle.
The whole reason we need the count variable is to handle those
kinds of cases.
I don't think it does. That's what the & ~3 was for.
--
-=( Ian Abbott @ MEV Ltd. E-mail: [off-list ref] )=-
-=( Tel: +44 (0)161 477 1898 FAX: +44 (0)161 718 3587 )=-
Reduce the number of variables modified by the loop in do_csum() by 1,
which seems like a good idea. On Nios II (a RISC CPU with 3-operand
instruction set) it reduces the loop from 7 to 6 instructions, including
the conditional branch.
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
I think you'll overshoot past the end of the buffer when there are
trailing bytes to handle.
The whole reason we need the count variable is to handle those
kinds of cases.
I don't think it does. That's what the & ~3 was for.
Reduce the number of variables modified by the loop in do_csum() by 1,
which seems like a good idea. On Nios II (a RISC CPU with 3-operand
instruction set) it reduces the loop from 7 to 6 instructions, including
the conditional branch.
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
I think you'll overshoot past the end of the buffer when there are
trailing bytes to handle.
The whole reason we need the count variable is to handle those
kinds of cases.
I don't think it does. That's what the & ~3 was for.