Hi, all I have a question about the func static u16 ipsum_calc_block(u16 *x, unsigned len, u16 sum) I guess we dont need the first len >>= 1 i know we want to move 32 bits at one time, so second len >>= 1 can do it. The first one is redundant. static u16 ipsum_calc_block(u16 *x, unsigned len, u16 sum) { int rest; u32 tmp, *xx; ASSERT(!(len % 2)); if (!len) return sum; len >>= 1; if ((unsigned long) x & 2) /* Align to 32-bit boundary, use x's address */ { sum = add16(sum, *x++); len--; } rest = len & 1; len >>= 1; tmp = 0; xx = (u32 *) x; while (len) { tmp = add32(tmp, *xx++); len--; } sum = add16(sum, add16(tmp & 0xffff, tmp >> 16U)); if (rest) sum = add16(sum, *(u16 *) xx); return sum; }
Hi!
I have a question about the func static u16 ipsum_calc_block(u16 *x, unsigned len, u16 sum)
I guess we dont need the first len >>= 1 i know we want to move 32 bits at one time, so second len >>= 1 can do it. The first one is redundant.
len >>= 1; if ((unsigned long) x & 2) /* Align to 32-bit boundary, use x's address */ { sum = add16(sum, *x++); len--; } rest = len & 1; len >>= 1;
The first one isn't redundant, but the code could be rewritten to avoid it: if (...) { ... len -= 2; } rest = len & 2; len >>= 2; But this optimization probably doesn't matter since the checksum function setup is not time critical, at least when compared with the checksumming loop a few lines below. Have a nice fortnight -- Martin `MJ' Mares <mj@ucw.cz> http://atrey.karlin.mff.cuni.cz/~mj/ Faculty of Math and Physics, Charles University, Prague, Czech Rep., Earth It's God. No, not Richard Stallman, not Linus Torvalds, but God.
participants (2)
-
Martin Mares -
Zheng Yuan {ZYUAN1}