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

Re: crc32() optimization



Something like that should do it, thanks.

       Jocke
> joakim.tjernlund@xxxxxxx.se said:
> >  Yup. I like the inline version. It will be more efficient for all
> > those constant length's crc32 calls in JFFS2. One could have both and
> > test  a compile time for a constant length and inline in those cases,
> > but  then you really need the #pragma thing, which seems to be
> > nonexistent.
> 
> That's what 'extern inline' is for, isn't it?
> 
> Or maybe if the compiler won't make the decision at the right threshold:
> 
> extern uint32_t __crc32(uint32_t, unsigned char *, int);
> 
> static inline uint32_t crc32(uint32_t val, unsigned char *s, int len)
> {
> if (__builtin_constant_p(len)) {
> switch(len) {
> case 10: val = crc32_table[(val ^ *s++) & 0xff] ^ (val >> 8);
> case 9: val = crc32_table[(val ^ *s++) & 0xff] ^ (val >> 8);
> case 8: val = crc32_table[(val ^ *s++) & 0xff] ^ (val >> 8);
> case 7: val = crc32_table[(val ^ *s++) & 0xff] ^ (val >> 8);
> case 6: val = crc32_table[(val ^ *s++) & 0xff] ^ (val >> 8);
> case 5: val = crc32_table[(val ^ *s++) & 0xff] ^ (val >> 8);
> case 4: val = crc32_table[(val ^ *s++) & 0xff] ^ (val >> 8);
> case 3: val = crc32_table[(val ^ *s++) & 0xff] ^ (val >> 8);
> case 2: val = crc32_table[(val ^ *s++) & 0xff] ^ (val >> 8);
> case 1: val = crc32_table[(val ^ *s++) & 0xff] ^ (val >> 8);
> case 0: return val;
> 
> default:
> ;
> }
> }
> return __crc32(t, crc, len);
> }
> 
> 
> --
> dwmw2
> 


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