Mercurial > libavcodec.hg
comparison vp56.h @ 12256:6e6c92d36c4b libavcodec
Inline asm for VP56 arith coder
This is a lot more reliable to get cmov rather than trying to trick gcc into
generating it, useful since it's 2% faster overall.
Patch by Eli Friedman <eli.friedman at gmail>
author | conrad |
---|---|
date | Fri, 23 Jul 2010 21:46:30 +0000 |
parents | 112b3a0db187 |
children | d8364962cc4a |
comparison
equal
deleted
inserted
replaced
12255:7db147ea02c4 | 12256:6e6c92d36c4b |
---|---|
206 } | 206 } |
207 c->bits = bits; | 207 c->bits = bits; |
208 return code_word; | 208 return code_word; |
209 } | 209 } |
210 | 210 |
211 #if ARCH_X86 | |
212 #include "x86/vp56_arith.h" | |
213 #endif | |
214 | |
215 #ifndef vp56_rac_get_prob | |
216 #define vp56_rac_get_prob vp56_rac_get_prob | |
211 static inline int vp56_rac_get_prob(VP56RangeCoder *c, uint8_t prob) | 217 static inline int vp56_rac_get_prob(VP56RangeCoder *c, uint8_t prob) |
212 { | 218 { |
213 /* Don't put c->high in a local variable; if we do that, gcc gets | |
214 * the stupids and turns the code below into a branch again. */ | |
215 unsigned int code_word = vp56_rac_renorm(c); | 219 unsigned int code_word = vp56_rac_renorm(c); |
216 unsigned int low = 1 + (((c->high - 1) * prob) >> 8); | 220 unsigned int low = 1 + (((c->high - 1) * prob) >> 8); |
217 unsigned int low_shift = low << 8; | 221 unsigned int low_shift = low << 8; |
218 int bit = code_word >= low_shift; | 222 int bit = code_word >= low_shift; |
219 | 223 |
220 /* Incantation to convince GCC to turn these into conditional moves | |
221 * instead of branches -- faster, as this branch is basically | |
222 * unpredictable. */ | |
223 c->high = bit ? c->high - low : low; | 224 c->high = bit ? c->high - low : low; |
224 c->code_word = bit ? code_word - low_shift : code_word; | 225 c->code_word = bit ? code_word - low_shift : code_word; |
225 | 226 |
226 return bit; | 227 return bit; |
227 } | 228 } |
229 #endif | |
228 | 230 |
229 // branchy variant, to be used where there's a branch based on the bit decoded | 231 // branchy variant, to be used where there's a branch based on the bit decoded |
230 static av_always_inline int vp56_rac_get_prob_branchy(VP56RangeCoder *c, int prob) | 232 static av_always_inline int vp56_rac_get_prob_branchy(VP56RangeCoder *c, int prob) |
231 { | 233 { |
232 unsigned long code_word = vp56_rac_renorm(c); | 234 unsigned long code_word = vp56_rac_renorm(c); |