[Ffmpeg-devel] [patch] move av_xiphlacing in avutil

Michael Niedermayer michaelni
Fri Nov 25 02:01:56 CET 2005


Hi

On Fri, Nov 25, 2005 at 01:41:38AM +0100, Michael Niedermayer wrote:
> Hi
> 
> On Thu, Nov 24, 2005 at 09:38:46PM +0100, Jindrich Makovicka wrote:
> [...]
> > >
> > >hmm, cant the table and start_crc be modified so that the ctx->le case is 
> > >always useable?
> > >
> > 
> > I am not sure, I'll try to look at other implementations.
> 
> try the following (warning, hand edited so wont apply)
> 
> @@ -34,7 +72,7 @@
>  	for (i = 0; i < 256; i++) {
>  	    for (c = i << (bits-8), j = 0; j < 8; j++)
>  		c = (c & (1<<(bits-1))) ? (c<<1)^poly : (c<<1);
> -		     ctx->tab[i] = c & ctx->mask;
> +		     ctx->tab[i] = bswap_32(c << (32-bits));
>  	}
>      }
>  
> @@ -49,20 +87,21 @@
>      if (ctx->bits <= 8) {
>  	for (i = 0; i < length; i++)
>  	    start_crc = ctx->tab[((uint8_t)start_crc) ^ *buffer++];
> -    } else if (ctx->le) {
> -	for (i = 0; i < length; i++)
> -	    start_crc = ctx->tab[((uint8_t)start_crc) ^ *buffer++] ^ (start_crc >> 8);
>      } else {
>  	for (i = 0; i < length; i++)
> -	    start_crc = ctx->tab[(uint8_t)(start_crc>>(ctx->bits-8)) ^ *buffer++] ^ (start_crc << 8);
> -    }
> +	    start_crc = ctx->tab[((uint8_t)start_crc) ^ *buffer++] ^ (start_crc >> 8);
> -    return(start_crc & ctx->mask);
> +    }
> +    if(!ctx->le)
> +        start_crc= bswap_32(start_crc<<(32-ctx->bits));
> +    return start_crc;
>  }
>  
>  void av_crc_init()

furthermore, replace the single 256 element LUT with 4 256 element tables
where table 0 equals the current and

for (i = 0; i < 256; i++) {
    for(j=0; j<3; j++)
        ctx->tab[j+1][i]= (ctx->tab[j][i]>>8) ^ ctx->tab[0][ ctx->tab[j][i]&0xFF ];
}

uint32_t av_crc(AVCRC *ctx, uint32_t start_crc, uint8_t *buffer, size_t length)
{
    uint8_t *end= buffer+length;

    while(buffer<end-3){
        start_crc ^= le2me_32(*(uint32_t*)buffer); buffer+=4;
        start_crc =  ctx->tab[3][ start_crc     &0xFF]
                    ^ctx->tab[2][(start_crc>>8 )&0xFF]
                    ^ctx->tab[1][(start_crc>>16)&0xFF]
                    ^ctx->tab[0][(start_crc>>24)     ];
    }
    while(buffer<end)
        start_crc = ctx->tab[0][((uint8_t)start_crc) ^ *buffer++] ^ (start_crc >> 8);

[...]
-- 
Michael





More information about the ffmpeg-devel mailing list