Mercurial > libavcodec.hg
comparison vp56.h @ 12031:5578dcdf030c libavcodec
Optimize vp56 arithmetic decoder
Negate "bits" to eliminate a negate in cache refilling.
author | darkshikari |
---|---|
date | Wed, 30 Jun 2010 23:15:25 +0000 |
parents | 934968bd410d |
children | 572c81b3be19 |
comparison
equal
deleted
inserted
replaced
12030:22da8afd75a5 | 12031:5578dcdf030c |
---|---|
46 typedef int (*VP56ParseHeader)(VP56Context *s, const uint8_t *buf, | 46 typedef int (*VP56ParseHeader)(VP56Context *s, const uint8_t *buf, |
47 int buf_size, int *golden_frame); | 47 int buf_size, int *golden_frame); |
48 | 48 |
49 typedef struct { | 49 typedef struct { |
50 int high; | 50 int high; |
51 int bits; | 51 int bits; /* Stored negated (i.e. negative "bits" is a positive number of bits left) |
52 * in order to eliminate a negate in cache refilling */ | |
52 const uint8_t *buffer; | 53 const uint8_t *buffer; |
53 const uint8_t *end; | 54 const uint8_t *end; |
54 unsigned long code_word; | 55 unsigned long code_word; |
55 } VP56RangeCoder; | 56 } VP56RangeCoder; |
56 | 57 |
183 | 184 |
184 static inline void vp56_init_range_decoder(VP56RangeCoder *c, | 185 static inline void vp56_init_range_decoder(VP56RangeCoder *c, |
185 const uint8_t *buf, int buf_size) | 186 const uint8_t *buf, int buf_size) |
186 { | 187 { |
187 c->high = 255; | 188 c->high = 255; |
188 c->bits = 8; | 189 c->bits = -8; |
189 c->buffer = buf; | 190 c->buffer = buf; |
190 c->end = buf + buf_size; | 191 c->end = buf + buf_size; |
191 c->code_word = bytestream_get_be16(&c->buffer); | 192 c->code_word = bytestream_get_be16(&c->buffer); |
192 } | 193 } |
193 | 194 |
207 | 208 |
208 /* normalize */ | 209 /* normalize */ |
209 shift = ff_h264_norm_shift[c->high] - 1; | 210 shift = ff_h264_norm_shift[c->high] - 1; |
210 c->high <<= shift; | 211 c->high <<= shift; |
211 c->code_word <<= shift; | 212 c->code_word <<= shift; |
212 c->bits -= shift; | 213 c->bits += shift; |
213 if(c->bits <= 0 && c->buffer < c->end) { | 214 if(c->bits >= 0 && c->buffer < c->end) { |
214 c->code_word |= *c->buffer++ << -c->bits; | 215 c->code_word |= *c->buffer++ << c->bits; |
215 c->bits += 8; | 216 c->bits -= 8; |
216 } | 217 } |
217 return bit; | 218 return bit; |
218 } | 219 } |
219 | 220 |
220 static inline int vp56_rac_get(VP56RangeCoder *c) | 221 static inline int vp56_rac_get(VP56RangeCoder *c) |
230 c->high = low << 1; | 231 c->high = low << 1; |
231 } | 232 } |
232 | 233 |
233 /* normalize */ | 234 /* normalize */ |
234 c->code_word <<= 1; | 235 c->code_word <<= 1; |
235 if (--c->bits == 0 && c->buffer < c->end) { | 236 if (++c->bits == 0 && c->buffer < c->end) { |
236 c->bits = 8; | 237 c->bits = -8; |
237 c->code_word |= *c->buffer++; | 238 c->code_word |= *c->buffer++; |
238 } | 239 } |
239 return bit; | 240 return bit; |
240 } | 241 } |
241 | 242 |