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

Re: crc32() optimization




alan@xxxxxxx.uk said:
>  gcc does unrolling where appropriate 

Is it intelligent enough to combine byte loads into 32-bit loads though?

static inline uint32_t 
crc32(uint32_t val, const void *ss, int len)
{
	const unsigned char *s = ss;

	/* Align it */
        while (((unsigned long)s)&3 && --len >= 0)
                val = crc32_table[(val ^ *s++) & 0xff] ^ (val >> 8);

	while (len >= 4) {
		uint32_t dd = *(uint32_t *)s;
#ifdef __LITTLE_ENDIAN
                val = crc32_table[(val ^ dd) & 0xff] ^ (val >> 8);
                val = crc32_table[(val ^ (dd>>8)) & 0xff] ^ (val >> 8);
                val = crc32_table[(val ^ (dd>>16)) & 0xff] ^ (val >> 8);
                val = crc32_table[(val ^ (dd>>24)) & 0xff] ^ (val >> 8);
#else
                val = crc32_table[(val ^ (dd>>24)) & 0xff] ^ (val >> 8);
                val = crc32_table[(val ^ (dd>>16)) & 0xff] ^ (val >> 8);
                val = crc32_table[(val ^ (dd>>8)) & 0xff] ^ (val >> 8);
                val = crc32_table[(val ^ dd) & 0xff] ^ (val >> 8);
#endif
		s += 4;
		len -= 4;
	}
	/* And the last few bytes... */
        while (--len >= 0)
                val = crc32_table[(val ^ *s++) & 0xff] ^ (val >> 8);
        return val;
}

#endif


--
dwmw2



To unsubscribe from this list: send the line "unsubscribe jffs-dev" in
the body of a message to majordomo@xxxxxxx.com