> uint16 calcCRC(register uint16 crc,
>                register const uint8 *ptr,
>                register uint16 count)
> {
>   int i;
>     
>   do {
>     i = 8;
>     crc = crc ^ (uint16)*ptr++ << 8;
> 
>     do {
>       if ((int16)crc < 0)               // if (crc & 0x8000)
>         crc = crc << 1 ^ 0x1021;
>       else
>         crc = crc << 1;
>     } while (--i);
>   } while (--count);
> 
>   return crc;
> }

The inner loop is one of those places where a spot of assembly can
really simplify things.  instead of

>       if ((int16)crc < 0)               // if (crc & 0x8000)
>         crc = crc << 1 ^ 0x1021;
>       else
>         crc = crc << 1;

you can do:

        asm("add %0,%0\n\t"
            "jnc 1f\n\t"
            "xor %1,%0\n"
            "1:"
            : "+r" (crc) : "g" (0x1021));

Reply via email to