comparison crc.c @ 993:f8db9a2bae05 libavutil

Add av_ prefix to bswap macros
author mru
date Sat, 10 Jul 2010 22:12:30 +0000
parents a13125b5be3a
children
comparison
equal deleted inserted replaced
992:a13125b5be3a 993:f8db9a2bae05
47 * exponent of the corresponding polynomial (both for poly and 47 * exponent of the corresponding polynomial (both for poly and
48 * actual CRC). 48 * actual CRC).
49 * If 0, you must swap the CRC parameter and the result of av_crc 49 * If 0, you must swap the CRC parameter and the result of av_crc
50 * if you need the standard representation (can be simplified in 50 * if you need the standard representation (can be simplified in
51 * most cases to e.g. bswap16): 51 * most cases to e.g. bswap16):
52 * bswap_32(crc << (32-bits)) 52 * av_bswap32(crc << (32-bits))
53 * @param bits number of bits for the CRC 53 * @param bits number of bits for the CRC
54 * @param poly generator polynomial without the x**bits coefficient, in the 54 * @param poly generator polynomial without the x**bits coefficient, in the
55 * representation as specified by le 55 * representation as specified by le
56 * @param ctx_size size of ctx in bytes 56 * @param ctx_size size of ctx in bytes
57 * @return <0 on failure 57 * @return <0 on failure
71 c = (c>>1)^(poly & (-(c&1))); 71 c = (c>>1)^(poly & (-(c&1)));
72 ctx[i] = c; 72 ctx[i] = c;
73 } else { 73 } else {
74 for (c = i << 24, j = 0; j < 8; j++) 74 for (c = i << 24, j = 0; j < 8; j++)
75 c = (c<<1) ^ ((poly<<(32-bits)) & (((int32_t)c)>>31) ); 75 c = (c<<1) ^ ((poly<<(32-bits)) & (((int32_t)c)>>31) );
76 ctx[i] = bswap_32(c); 76 ctx[i] = av_bswap32(c);
77 } 77 }
78 } 78 }
79 ctx[256]=1; 79 ctx[256]=1;
80 #if !CONFIG_SMALL 80 #if !CONFIG_SMALL
81 if(ctx_size >= sizeof(AVCRC)*1024) 81 if(ctx_size >= sizeof(AVCRC)*1024)
119 if(!ctx[256]) { 119 if(!ctx[256]) {
120 while(((intptr_t) buffer & 3) && buffer < end) 120 while(((intptr_t) buffer & 3) && buffer < end)
121 crc = ctx[((uint8_t)crc) ^ *buffer++] ^ (crc >> 8); 121 crc = ctx[((uint8_t)crc) ^ *buffer++] ^ (crc >> 8);
122 122
123 while(buffer<end-3){ 123 while(buffer<end-3){
124 crc ^= le2ne_32(*(const uint32_t*)buffer); buffer+=4; 124 crc ^= av_le2ne32(*(const uint32_t*)buffer); buffer+=4;
125 crc = ctx[3*256 + ( crc &0xFF)] 125 crc = ctx[3*256 + ( crc &0xFF)]
126 ^ctx[2*256 + ((crc>>8 )&0xFF)] 126 ^ctx[2*256 + ((crc>>8 )&0xFF)]
127 ^ctx[1*256 + ((crc>>16)&0xFF)] 127 ^ctx[1*256 + ((crc>>16)&0xFF)]
128 ^ctx[0*256 + ((crc>>24) )]; 128 ^ctx[0*256 + ((crc>>24) )];
129 } 129 }