comparison vp56.h @ 12385:d0b25641338b libavcodec

VP5/6/8: ~7% faster arithmetic decoding Grab from the bitstream in 16-bit chunks instead of 8-bit chunks. TODO: grab in 32-bit chunks on 64-bit systems.
author darkshikari
date Thu, 12 Aug 2010 01:11:32 +0000
parents 7c54834209f6
children
comparison
equal deleted inserted replaced
12384:e1ef713061ce 12385:d0b25641338b
192 192
193 c->high <<= shift; 193 c->high <<= shift;
194 code_word <<= shift; 194 code_word <<= shift;
195 bits += shift; 195 bits += shift;
196 if(bits >= 0 && c->buffer < c->end) { 196 if(bits >= 0 && c->buffer < c->end) {
197 code_word |= *c->buffer++ << bits; 197 code_word |= bytestream_get_be16(&c->buffer) << bits;
198 bits -= 8; 198 bits -= 16;
199 } 199 }
200 c->bits = bits; 200 c->bits = bits;
201 return code_word; 201 return code_word;
202 } 202 }
203 203
209 #define vp56_rac_get_prob vp56_rac_get_prob 209 #define vp56_rac_get_prob vp56_rac_get_prob
210 static av_always_inline int vp56_rac_get_prob(VP56RangeCoder *c, uint8_t prob) 210 static av_always_inline int vp56_rac_get_prob(VP56RangeCoder *c, uint8_t prob)
211 { 211 {
212 unsigned int code_word = vp56_rac_renorm(c); 212 unsigned int code_word = vp56_rac_renorm(c);
213 unsigned int low = 1 + (((c->high - 1) * prob) >> 8); 213 unsigned int low = 1 + (((c->high - 1) * prob) >> 8);
214 unsigned int low_shift = low << 8; 214 unsigned int low_shift = low << 16;
215 int bit = code_word >= low_shift; 215 int bit = code_word >= low_shift;
216 216
217 c->high = bit ? c->high - low : low; 217 c->high = bit ? c->high - low : low;
218 c->code_word = bit ? code_word - low_shift : code_word; 218 c->code_word = bit ? code_word - low_shift : code_word;
219 219
224 // branchy variant, to be used where there's a branch based on the bit decoded 224 // branchy variant, to be used where there's a branch based on the bit decoded
225 static av_always_inline int vp56_rac_get_prob_branchy(VP56RangeCoder *c, int prob) 225 static av_always_inline int vp56_rac_get_prob_branchy(VP56RangeCoder *c, int prob)
226 { 226 {
227 unsigned long code_word = vp56_rac_renorm(c); 227 unsigned long code_word = vp56_rac_renorm(c);
228 unsigned low = 1 + (((c->high - 1) * prob) >> 8); 228 unsigned low = 1 + (((c->high - 1) * prob) >> 8);
229 unsigned low_shift = low << 8; 229 unsigned low_shift = low << 16;
230 230
231 if (code_word >= low_shift) { 231 if (code_word >= low_shift) {
232 c->high -= low; 232 c->high -= low;
233 c->code_word = code_word - low_shift; 233 c->code_word = code_word - low_shift;
234 return 1; 234 return 1;
242 static av_always_inline int vp56_rac_get(VP56RangeCoder *c) 242 static av_always_inline int vp56_rac_get(VP56RangeCoder *c)
243 { 243 {
244 unsigned int code_word = vp56_rac_renorm(c); 244 unsigned int code_word = vp56_rac_renorm(c);
245 /* equiprobable */ 245 /* equiprobable */
246 int low = (c->high + 1) >> 1; 246 int low = (c->high + 1) >> 1;
247 unsigned int low_shift = low << 8; 247 unsigned int low_shift = low << 16;
248 int bit = code_word >= low_shift; 248 int bit = code_word >= low_shift;
249 if (bit) { 249 if (bit) {
250 c->high -= low; 250 c->high -= low;
251 code_word -= low_shift; 251 code_word -= low_shift;
252 } else { 252 } else {