[lkml]   [1996]   [Nov]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
    SubjectRe: IP Checksumming

    > I.e. the fastest possible C code can process 16 bits in each iteration,
    > if running on a 32-bit cpu, 32 bits on a 64-bit cpu.


    > If you have conditionally executed opcodes, or a conditional move, then
    > you can gain back the full register width, i.e. you can do something
    > like this efficiently:

    You can also do this if you have some kind of "set conditional" operation.

    > unsigned long data[];
    > ...

    > unsigned long sum, new_sum;
    > for (i = sum = 0; i < len; i++) {
    > new_sum = sum + data[i];
    > if (new_sum < sum) /* Did we get carry/overflow from the add? */
    > new_sum++;
    > sum = new_sum;

    Here you have a if and it is one one which by my guess branch prediction
    like on a PentiumPro/R10000K etc. will perform pretty bad. Move conditional
    is an operation which is not available on many CPUs, some have it only for
    floating point yet again other implement it only in new versions of their
    CPU architectures.

    csum += data[i];
    carry = (csum < data[i]);
    csum += carry;

    does not need branches or other pipeline killers at all on most CPUs.
    In fact on MIPS this even makes really nice code which takes four
    cycles per 4 bytes on 32 bit CPUs or four cycles per 8 bytes on R4000
    (64 bit) CPUs, R5000/R10000 should be able to do this in 2 cycles.

    No hardware carry flag or assembler needed, pretty fast and portable.


     \ /
      Last update: 2005-03-22 13:38    [W:0.020 / U:0.908 seconds]
    ©2003-2017 Jasper Spaans. hosted at Digital OceanAdvertise on this site