History

Merge remote-tracking branch 'qatar/master'

* qatar/master: (28 commits) Replace usages of av_get_bits_per_sample_fmt() with av_get_bytes_per_sample(). x86: cabac: fix register constraints for 32-bit mode cabac: move x86 asm to libavcodec/x86/cabac.h x86: h264: cast pointers to intptr_t rather than int x86: h264: remove hardcoded edi in decode_significance_8x8_x86() x86: h264: remove hardcoded esi in decode_significance[_8x8]_x86() x86: h264: remove hardcoded edx in decode_significance[_8x8]_x86() x86: h264: remove hardcoded eax in decode_significance[_8x8]_x86() x86: cabac: change 'a' constraint to 'r' in get_cabac_inline() x86: cabac: remove hardcoded esi in get_cabac_inline() x86: cabac: remove hardcoded edx in get_cabac_inline() x86: cabac: remove unused macro parameter x86: cabac: remove hardcoded ebx in inline asm x86: cabac: remove hardcoded struct offsets from inline asm cabac: remove inline asm under #if 0 cabac: remove BRANCHLESS_CABAC_DECODER switch cabac: remove #if 0 cascade under never-set #ifdef ARCH_X86_DISABLED document libswscale bump error_resilience: skip last-MV predictor step if MVs are not available. error_resilience: actually add counter when adding a MV predictor. ... Conflicts: Changelog libavcodec/error_resilience.c libavfilter/defaults.c libavfilter/vf_drawtext.c libswscale/swscale.h tests/ref/vsynth1/error tests/ref/vsynth2/error

Michael Niedermayer committed 15 years ago

Commit 6cbe8192 parents b37dfe1 e6c52ce21 files · +288 −435Browse files

Showing the changes to libavcodec (14 of 21 files). Show all

Unified · Split

14 files
  1. libavcodec/aacdec.c +1 −1
  2. libavcodec/ac3dec.c +1 −1
  3. libavcodec/alsdec.c +2 −2
  4. libavcodec/cabac.c +0 −8
  5. libavcodec/cabac.h +26 −335
  6. libavcodec/dca.c +1 −1
  7. libavcodec/error_resilience.c +4 −0
  8. libavcodec/h264.c +2 −0
  9. libavcodec/resample.c +2 −2
  10. libavcodec/utils.c +1 −1
  11. libavcodec/vmdav.c +1 −1
  12. libavcodec/vorbisdec.c +1 −1
  13. libavcodec/x86/cabac.h +148 −0
  14. libavcodec/x86/h264_i386.h +84 −69
libavcodec/aacdec.c+1−1
@@ -2179,7 +2179,7 @@ static int aac_decode_frame_int(AVCodecContext *avctx, void *data, · 2178 unmodified lines
21792179 }
21802180
21812181 data_size_tmp = samples * avctx->channels *
2182− (av_get_bits_per_sample_fmt(avctx->sample_fmt) / 8);
2182+ av_get_bytes_per_sample(avctx->sample_fmt);
21832183 if (*data_size < data_size_tmp) {
21842184 av_log(avctx, AV_LOG_ERROR,
21852185 "Output buffer too small (%d) or trying to output too many samples (%d) for this frame.\n",
libavcodec/ac3dec.c+1−1
@@ -1422,7 +1422,7 @@ static int ac3_decode_frame(AVCodecContext * avctx, void *data, int *data_size, · 1421 unmodified lines
14221422 }
14231423 }
14241424 *data_size = s->num_blocks * 256 * avctx->channels *
1425− (av_get_bits_per_sample_fmt(avctx->sample_fmt) / 8);
1425+ av_get_bytes_per_sample(avctx->sample_fmt);
14261426 return FFMIN(buf_size, s->frame_size);
14271427 }
14281428
libavcodec/alsdec.c+2−2
@@ -1450,7 +1450,7 @@ static int decode_frame(AVCodecContext *avctx, · 1449 unmodified lines
14501450
14511451 // check for size of decoded data
14521452 size = ctx->cur_frame_length * avctx->channels *
1453− (av_get_bits_per_sample_fmt(avctx->sample_fmt) >> 3);
1453+ av_get_bytes_per_sample(avctx->sample_fmt);
14541454
14551455 if (size > *data_size) {
14561456 av_log(avctx, AV_LOG_ERROR, "Decoded data exceeds buffer size.\n");
@@ -1714,7 +1714,7 @@ static av_cold int decode_init(AVCodecContext *avctx) · 257 unmodified lines
17141714 ctx->crc_buffer = av_malloc(sizeof(*ctx->crc_buffer) *
17151715 ctx->cur_frame_length *
17161716 avctx->channels *
1717− (av_get_bits_per_sample_fmt(avctx->sample_fmt) >> 3));
1717+ av_get_bytes_per_sample(avctx->sample_fmt));
17181718 if (!ctx->crc_buffer) {
17191719 av_log(avctx, AV_LOG_ERROR, "Allocating buffer memory failed.\n");
17201720 decode_end(avctx);
libavcodec/cabac.c+0−8
@@ -161,19 +161,11 @@ void ff_init_cabac_states(CABACContext *c){ · 160 unmodified lines
161161 ff_h264_mps_state[2*i+1]= 2*mps_state[i]+1;
162162
163163 if( i ){
164−#ifdef BRANCHLESS_CABAC_DECODER
165164 ff_h264_mlps_state[128-2*i-1]= 2*lps_state[i]+0;
166165 ff_h264_mlps_state[128-2*i-2]= 2*lps_state[i]+1;
167166 }else{
168167 ff_h264_mlps_state[128-2*i-1]= 1;
169168 ff_h264_mlps_state[128-2*i-2]= 0;
170−#else
171− ff_h264_lps_state[2*i+0]= 2*lps_state[i]+0;
172− ff_h264_lps_state[2*i+1]= 2*lps_state[i]+1;
173− }else{
174− ff_h264_lps_state[2*i+0]= 1;
175− ff_h264_lps_state[2*i+1]= 0;
176−#endif
177169 }
178170 }
179171 }
libavcodec/cabac.h+26−335
@@ -27,16 +27,15 @@ · 26 unmodified lines
2727 #ifndef AVCODEC_CABAC_H
2828 #define AVCODEC_CABAC_H
2929
30+#include <stddef.h>
31+
3032 #include "put_bits.h"
3133
3234 //#undef NDEBUG
3335 #include <assert.h>
34−#include "libavutil/x86_cpu.h"
3536
3637 #define CABAC_BITS 16
3738 #define CABAC_MASK ((1<<CABAC_BITS)-1)
38−#define BRANCHLESS_CABAC_DECODER 1
39−//#define ARCH_X86_DISABLED 1
4039
4140 typedef struct CABACContext{
4241 int low;
@@ -57,6 +56,9 @@ extern uint8_t ff_h264_mps_state[2*64]; ///< transIdxMPS · 14 unmodified lines
5756 extern uint8_t ff_h264_lps_state[2*64]; ///< transIdxLPS
5857 extern const uint8_t ff_h264_norm_shift[512];
5958
59+#if ARCH_X86
60+# include "x86/cabac.h"
61+#endif
6062
6163 void ff_init_cabac_encoder(CABACContext *c, uint8_t *buf, int buf_size);
6264 void ff_init_cabac_decoder(CABACContext *c, const uint8_t *buf, int buf_size);
@@ -270,26 +272,6 @@ static void refill(CABACContext *c){ · 207 unmodified lines
270272 c->bytestream+= CABAC_BITS/8;
271273 }
272274
273−#if ! ( ARCH_X86 && HAVE_7REGS && HAVE_EBX_AVAILABLE && !defined(BROKEN_RELOCATIONS) )
274−static void refill2(CABACContext *c){
275− int i, x;
276−
277− x= c->low ^ (c->low-1);
278− i= 7 - ff_h264_norm_shift[x>>(CABAC_BITS-1)];
279−
280− x= -CABAC_MASK;
281−
282−#if CABAC_BITS == 16
283− x+= (c->bytestream[0]<<9) + (c->bytestream[1]<<1);
284−#else
285− x+= c->bytestream[0]<<1;
286−#endif
287−
288− c->low += x<<i;
289− c->bytestream+= CABAC_BITS/8;
290−}
291−#endif
292−
293275 static inline void renorm_cabac_decoder(CABACContext *c){
294276 while(c->range < 0x100){
295277 c->range+= c->range;
@@ -300,267 +282,38 @@ static inline void renorm_cabac_decoder(CABACContext *c){ · 4 unmodified lines
300282 }
301283
302284 static inline void renorm_cabac_decoder_once(CABACContext *c){
303−#ifdef ARCH_X86_DISABLED
304− int temp;
305−#if 0
306− //P3:683 athlon:475
307− __asm__(
308− "lea -0x100(%0), %2 \n\t"
309− "shr $31, %2 \n\t" //FIXME 31->63 for x86-64
310− "shl %%cl, %0 \n\t"
311− "shl %%cl, %1 \n\t"
312− : "+r"(c->range), "+r"(c->low), "+c"(temp)
313− );
314−#elif 0
315− //P3:680 athlon:474
316− __asm__(
317− "cmp $0x100, %0 \n\t"
318− "setb %%cl \n\t" //FIXME 31->63 for x86-64
319− "shl %%cl, %0 \n\t"
320− "shl %%cl, %1 \n\t"
321− : "+r"(c->range), "+r"(c->low), "+c"(temp)
322− );
323−#elif 1
324− int temp2;
325− //P3:665 athlon:517
326− __asm__(
327− "lea -0x100(%0), %%eax \n\t"
328− "cltd \n\t"
329− "mov %0, %%eax \n\t"
330− "and %%edx, %0 \n\t"
331− "and %1, %%edx \n\t"
332− "add %%eax, %0 \n\t"
333− "add %%edx, %1 \n\t"
334− : "+r"(c->range), "+r"(c->low), "+a"(temp), "+d"(temp2)
335− );
336−#elif 0
337− int temp2;
338− //P3:673 athlon:509
339− __asm__(
340− "cmp $0x100, %0 \n\t"
341− "sbb %%edx, %%edx \n\t"
342− "mov %0, %%eax \n\t"
343− "and %%edx, %0 \n\t"
344− "and %1, %%edx \n\t"
345− "add %%eax, %0 \n\t"
346− "add %%edx, %1 \n\t"
347− : "+r"(c->range), "+r"(c->low), "+a"(temp), "+d"(temp2)
348− );
349−#else
350− int temp2;
351− //P3:677 athlon:511
352− __asm__(
353− "cmp $0x100, %0 \n\t"
354− "lea (%0, %0), %%eax \n\t"
355− "lea (%1, %1), %%edx \n\t"
356− "cmovb %%eax, %0 \n\t"
357− "cmovb %%edx, %1 \n\t"
358− : "+r"(c->range), "+r"(c->low), "+a"(temp), "+d"(temp2)
359− );
360−#endif
361−#else
362− //P3:675 athlon:476
363285 int shift= (uint32_t)(c->range - 0x100)>>31;
364286 c->range<<= shift;
365287 c->low <<= shift;
366−#endif
367288 if(!(c->low & CABAC_MASK))
368289 refill(c);
369290 }
370291
371−static av_always_inline int get_cabac_inline(CABACContext *c, uint8_t * const state){
372− //FIXME gcc generates duplicate load/stores for c->low and c->range
373−#define LOW "0"
374−#define RANGE "4"
375−#if ARCH_X86_64
376−#define BYTESTART "16"
377−#define BYTE "24"
378−#define BYTEEND "32"
379−#else
380−#define BYTESTART "12"
381−#define BYTE "16"
382−#define BYTEEND "20"
383−#endif
384−#if ARCH_X86 && HAVE_7REGS && HAVE_EBX_AVAILABLE && !defined(BROKEN_RELOCATIONS)
385− int bit;
386−
387−#ifndef BRANCHLESS_CABAC_DECODER
388− __asm__ volatile(
389− "movzbl (%1), %0 \n\t"
390− "movl "RANGE "(%2), %%ebx \n\t"
391− "movl "RANGE "(%2), %%edx \n\t"
392− "andl $0xC0, %%ebx \n\t"
393− "movzbl "MANGLE(ff_h264_lps_range)"(%0, %%ebx, 2), %%esi\n\t"
394− "movl "LOW "(%2), %%ebx \n\t"
395−//eax:state ebx:low, edx:range, esi:RangeLPS
396− "subl %%esi, %%edx \n\t"
397− "movl %%edx, %%ecx \n\t"
398− "shll $17, %%ecx \n\t"
399− "cmpl %%ecx, %%ebx \n\t"
400− " ja 1f \n\t"
292+#ifndef get_cabac_inline
293+static void refill2(CABACContext *c){
294+ int i, x;
401295
402−#if 1
403− //athlon:4067 P3:4110
404− "lea -0x100(%%edx), %%ecx \n\t"
405− "shr $31, %%ecx \n\t"
406− "shl %%cl, %%edx \n\t"
407− "shl %%cl, %%ebx \n\t"
296+ x= c->low ^ (c->low-1);
297+ i= 7 - ff_h264_norm_shift[x>>(CABAC_BITS-1)];
298+
299+ x= -CABAC_MASK;
300+
301+#if CABAC_BITS == 16
302+ x+= (c->bytestream[0]<<9) + (c->bytestream[1]<<1);
408303 #else
409− //athlon:4057 P3:4130
410− "cmp $0x100, %%edx \n\t" //FIXME avoidable
411− "setb %%cl \n\t"
412− "shl %%cl, %%edx \n\t"
413− "shl %%cl, %%ebx \n\t"
304+ x+= c->bytestream[0]<<1;
414305 #endif
415− "movzbl "MANGLE(ff_h264_mps_state)"(%0), %%ecx \n\t"
416− "movb %%cl, (%1) \n\t"
417−//eax:state ebx:low, edx:range, esi:RangeLPS
418− "test %%bx, %%bx \n\t"
419− " jnz 2f \n\t"
420− "mov "BYTE "(%2), %%"REG_S" \n\t"
421− "subl $0xFFFF, %%ebx \n\t"
422− "movzwl (%%"REG_S"), %%ecx \n\t"
423− "bswap %%ecx \n\t"
424− "shrl $15, %%ecx \n\t"
425− "add $2, %%"REG_S" \n\t"
426− "addl %%ecx, %%ebx \n\t"
427− "mov %%"REG_S", "BYTE "(%2) \n\t"
428− "jmp 2f \n\t"
429− "1: \n\t"
430−//eax:state ebx:low, edx:range, esi:RangeLPS
431− "subl %%ecx, %%ebx \n\t"
432− "movl %%esi, %%edx \n\t"
433− "movzbl " MANGLE(ff_h264_norm_shift) "(%%esi), %%ecx \n\t"
434− "shll %%cl, %%ebx \n\t"
435− "shll %%cl, %%edx \n\t"
436− "movzbl "MANGLE(ff_h264_lps_state)"(%0), %%ecx \n\t"
437− "movb %%cl, (%1) \n\t"
438− "add $1, %0 \n\t"
439− "test %%bx, %%bx \n\t"
440− " jnz 2f \n\t"
441−
442− "mov "BYTE "(%2), %%"REG_c" \n\t"
443− "movzwl (%%"REG_c"), %%esi \n\t"
444− "bswap %%esi \n\t"
445− "shrl $15, %%esi \n\t"
446− "subl $0xFFFF, %%esi \n\t"
447− "add $2, %%"REG_c" \n\t"
448− "mov %%"REG_c", "BYTE "(%2) \n\t"
449−
450− "leal -1(%%ebx), %%ecx \n\t"
451− "xorl %%ebx, %%ecx \n\t"
452− "shrl $15, %%ecx \n\t"
453− "movzbl " MANGLE(ff_h264_norm_shift) "(%%ecx), %%ecx \n\t"
454− "neg %%ecx \n\t"
455− "add $7, %%ecx \n\t"
456−
457− "shll %%cl , %%esi \n\t"
458− "addl %%esi, %%ebx \n\t"
459− "2: \n\t"
460− "movl %%edx, "RANGE "(%2) \n\t"
461− "movl %%ebx, "LOW "(%2) \n\t"
462− :"=&a"(bit) //FIXME this is fragile gcc either runs out of registers or miscompiles it (for example if "+a"(bit) or "+m"(*state) is used
463− :"r"(state), "r"(c)
464− : "%"REG_c, "%ebx", "%edx", "%"REG_S, "memory"
465− );
466− bit&=1;
467−#else /* BRANCHLESS_CABAC_DECODER */
468−
469−
470−#if HAVE_FAST_CMOV
471−#define BRANCHLESS_GET_CABAC_UPDATE(ret, cabac, statep, low, lowword, range, tmp, tmpbyte)\
472− "mov "tmp" , %%ecx \n\t"\
473− "shl $17 , "tmp" \n\t"\
474− "cmp "low" , "tmp" \n\t"\
475− "cmova %%ecx , "range" \n\t"\
476− "sbb %%ecx , %%ecx \n\t"\
477− "and %%ecx , "tmp" \n\t"\
478− "sub "tmp" , "low" \n\t"\
479− "xor %%ecx , "ret" \n\t"
480−#else /* HAVE_FAST_CMOV */
481−#define BRANCHLESS_GET_CABAC_UPDATE(ret, cabac, statep, low, lowword, range, tmp, tmpbyte)\
482− "mov "tmp" , %%ecx \n\t"\
483− "shl $17 , "tmp" \n\t"\
484− "sub "low" , "tmp" \n\t"\
485− "sar $31 , "tmp" \n\t" /*lps_mask*/\
486− "sub %%ecx , "range" \n\t" /*RangeLPS - range*/\
487− "and "tmp" , "range" \n\t" /*(RangeLPS - range)&lps_mask*/\
488− "add %%ecx , "range" \n\t" /*new range*/\
489− "shl $17 , %%ecx \n\t"\
490− "and "tmp" , %%ecx \n\t"\
491− "sub %%ecx , "low" \n\t"\
492− "xor "tmp" , "ret" \n\t"
493−#endif /* HAVE_FAST_CMOV */
494−
495−
496−#define BRANCHLESS_GET_CABAC(ret, cabac, statep, low, lowword, range, tmp, tmpbyte)\
497− "movzbl "statep" , "ret" \n\t"\
498− "mov "range" , "tmp" \n\t"\
499− "and $0xC0 , "range" \n\t"\
500− "movzbl "MANGLE(ff_h264_lps_range)"("ret", "range", 2), "range" \n\t"\
501− "sub "range" , "tmp" \n\t"\
502− BRANCHLESS_GET_CABAC_UPDATE(ret, cabac, statep, low, lowword, range, tmp, tmpbyte)\
503− "movzbl " MANGLE(ff_h264_norm_shift) "("range"), %%ecx \n\t"\
504− "shl %%cl , "range" \n\t"\
505− "movzbl "MANGLE(ff_h264_mlps_state)"+128("ret"), "tmp" \n\t"\
506− "mov "tmpbyte" , "statep" \n\t"\
507− "shl %%cl , "low" \n\t"\
508− "test "lowword" , "lowword" \n\t"\
509− " jnz 1f \n\t"\
510− "mov "BYTE"("cabac"), %%"REG_c" \n\t"\
511− "movzwl (%%"REG_c") , "tmp" \n\t"\
512− "bswap "tmp" \n\t"\
513− "shr $15 , "tmp" \n\t"\
514− "sub $0xFFFF , "tmp" \n\t"\
515− "add $2 , %%"REG_c" \n\t"\
516− "mov %%"REG_c" , "BYTE "("cabac") \n\t"\
517− "lea -1("low") , %%ecx \n\t"\
518− "xor "low" , %%ecx \n\t"\
519− "shr $15 , %%ecx \n\t"\
520− "movzbl " MANGLE(ff_h264_norm_shift) "(%%ecx), %%ecx \n\t"\
521− "neg %%ecx \n\t"\
522− "add $7 , %%ecx \n\t"\
523− "shl %%cl , "tmp" \n\t"\
524− "add "tmp" , "low" \n\t"\
525− "1: \n\t"
526−
527− __asm__ volatile(
528− "movl "RANGE "(%2), %%esi \n\t"
529− "movl "LOW "(%2), %%ebx \n\t"
530− BRANCHLESS_GET_CABAC("%0", "%2", "(%1)", "%%ebx", "%%bx", "%%esi", "%%edx", "%%dl")
531− "movl %%esi, "RANGE "(%2) \n\t"
532− "movl %%ebx, "LOW "(%2) \n\t"
533−
534− :"=&a"(bit)
535− :"r"(state), "r"(c)
536− : "%"REG_c, "%ebx", "%edx", "%esi", "memory"
537− );
538− bit&=1;
539−#endif /* BRANCHLESS_CABAC_DECODER */
540−#else /* ARCH_X86 && HAVE_7REGS && HAVE_EBX_AVAILABLE && !defined(BROKEN_RELOCATIONS) */
306+
307+ c->low += x<<i;
308+ c->bytestream+= CABAC_BITS/8;
309+}
310+
311+static av_always_inline int get_cabac_inline(CABACContext *c, uint8_t * const state){
541312 int s = *state;
542313 int RangeLPS= ff_h264_lps_range[2*(c->range&0xC0) + s];
543− int bit, lps_mask av_unused;
314+ int bit, lps_mask;
544315
545316 c->range -= RangeLPS;
546−#ifndef BRANCHLESS_CABAC_DECODER
547− if(c->low < (c->range<<(CABAC_BITS+1))){
548− bit= s&1;
549− *state= ff_h264_mps_state[s];
550− renorm_cabac_decoder_once(c);
551− }else{
552− bit= ff_h264_norm_shift[RangeLPS];
553− c->low -= (c->range<<(CABAC_BITS+1));
554− *state= ff_h264_lps_state[s];
555− c->range = RangeLPS<<bit;
556− c->low <<= bit;
557− bit= (s&1)^1;
558−
559− if(!(c->low & CABAC_MASK)){
560− refill2(c);
561− }
562− }
563−#else /* BRANCHLESS_CABAC_DECODER */
564317 lps_mask= ((c->range<<(CABAC_BITS+1)) - c->low)>>31;
565318
566319 c->low -= (c->range<<(CABAC_BITS+1)) & lps_mask;
@@ -575,10 +328,9 @@ static av_always_inline int get_cabac_inline(CABACContext *c, uint8_t * const st · 8 unmodified lines
575328 c->low <<= lps_mask;
576329 if(!(c->low & CABAC_MASK))
577330 refill2(c);
578−#endif /* BRANCHLESS_CABAC_DECODER */
579−#endif /* ARCH_X86 && HAVE_7REGS && HAVE_EBX_AVAILABLE && !defined(BROKEN_RELOCATIONS) */
580331 return bit;
581332 }
333+#endif
582334
583335 static int av_noinline av_unused get_cabac_noinline(CABACContext *c, uint8_t * const state){
584336 return get_cabac_inline(c,state);
@@ -589,36 +341,6 @@ static int av_unused get_cabac(CABACContext *c, uint8_t * const state){ · 4 unmodified lines
589341 }
590342
591343 static int av_unused get_cabac_bypass(CABACContext *c){
592−#if 0 //not faster
593− int bit;
594− __asm__ volatile(
595− "movl "RANGE "(%1), %%ebx \n\t"
596− "movl "LOW "(%1), %%eax \n\t"
597− "shl $17, %%ebx \n\t"
598− "add %%eax, %%eax \n\t"
599− "sub %%ebx, %%eax \n\t"
600− "cltd \n\t"
601− "and %%edx, %%ebx \n\t"
602− "add %%ebx, %%eax \n\t"
603− "test %%ax, %%ax \n\t"
604− " jnz 1f \n\t"
605− "movl "BYTE "(%1), %%"REG_b" \n\t"
606− "subl $0xFFFF, %%eax \n\t"
607− "movzwl (%%"REG_b"), %%ecx \n\t"
608− "bswap %%ecx \n\t"
609− "shrl $15, %%ecx \n\t"
610− "addl $2, %%"REG_b" \n\t"
611− "addl %%ecx, %%eax \n\t"
612− "movl %%"REG_b", "BYTE "(%1) \n\t"
613− "1: \n\t"
614− "movl %%eax, "LOW "(%1) \n\t"
615−
616− :"=&d"(bit)
617− :"r"(c)
618− : "%eax", "%"REG_b, "%ecx", "memory"
619− );
620− return bit+1;
621−#else
622344 int range;
623345 c->low += c->low;
624346
@@ -632,42 +354,11 @@ static int av_unused get_cabac_bypass(CABACContext *c){ · 7 unmodified lines
632354 c->low -= range;
633355 return 1;
634356 }
635−#endif
636357 }
637358
638359
360+#ifndef get_cabac_bypass_sign
639361 static av_always_inline int get_cabac_bypass_sign(CABACContext *c, int val){
640−#if ARCH_X86 && HAVE_EBX_AVAILABLE
641− __asm__ volatile(
642− "movl "RANGE "(%1), %%ebx \n\t"
643− "movl "LOW "(%1), %%eax \n\t"
644− "shl $17, %%ebx \n\t"
645− "add %%eax, %%eax \n\t"
646− "sub %%ebx, %%eax \n\t"
647− "cltd \n\t"
648− "and %%edx, %%ebx \n\t"
649− "add %%ebx, %%eax \n\t"
650− "xor %%edx, %%ecx \n\t"
651− "sub %%edx, %%ecx \n\t"
652− "test %%ax, %%ax \n\t"
653− " jnz 1f \n\t"
654− "mov "BYTE "(%1), %%"REG_b" \n\t"
655− "subl $0xFFFF, %%eax \n\t"
656− "movzwl (%%"REG_b"), %%edx \n\t"
657− "bswap %%edx \n\t"
658− "shrl $15, %%edx \n\t"
659− "add $2, %%"REG_b" \n\t"
660− "addl %%edx, %%eax \n\t"
661− "mov %%"REG_b", "BYTE "(%1) \n\t"
662− "1: \n\t"
663− "movl %%eax, "LOW "(%1) \n\t"
664−
665− :"+c"(val)
666− :"r"(c)
667− : "%eax", "%"REG_b, "%edx", "memory"
668− );
669− return val;
670−#else
671362 int range, mask;
672363 c->low += c->low;
673364
@@ -680,8 +371,8 @@ static av_always_inline int get_cabac_bypass_sign(CABACContext *c, int val){ · 6 unmodified lines
680371 range &= mask;
681372 c->low += range;
682373 return (val^mask)-mask;
683−#endif
684374 }
375+#endif
685376
686377 /**
687378 *
libavcodec/dca.c+1−1
@@ -1817,7 +1817,7 @@ static int dca_decode_frame(AVCodecContext * avctx, · 1816 unmodified lines
18171817 }
18181818
18191819 out_size = 256 / 8 * s->sample_blocks * channels *
1820− (av_get_bits_per_sample_fmt(avctx->sample_fmt) / 8);
1820+ av_get_bytes_per_sample(avctx->sample_fmt);
18211821 if (*data_size < out_size)
18221822 return -1;
18231823 *data_size = out_size;
libavcodec/error_resilience.c+4−0
@@ -542,6 +542,9 @@ skip_mean_and_median: · 541 unmodified lines
542542 ff_thread_await_progress((AVFrame *) s->last_picture_ptr,
543543 mb_y, 0);
544544 }
545+ if (!s->last_picture.motion_val[0] ||
546+ !s->last_picture.ref_index[0])
547+ goto skip_last_mv;
545548 prev_x = s->last_picture.motion_val[0][mot_index][0];
546549 prev_y = s->last_picture.motion_val[0][mot_index][1];
547550 prev_ref = s->last_picture.ref_index[0][4*mb_xy];
@@ -556,6 +559,7 @@ skip_mean_and_median: · 8 unmodified lines
556559 mv_predictor[pred_count][1]= prev_y;
557560 ref [pred_count] = prev_ref;
558561 pred_count++;
562+ skip_last_mv:
559563
560564 s->mv_dir = MV_DIR_FORWARD;
561565 s->mb_intra=0;
libavcodec/h264.c+2−0
@@ -3690,6 +3690,8 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size){ · 3689 unmodified lines
36903690 switch (hx->nal_unit_type) {
36913691 case NAL_SPS:
36923692 case NAL_PPS:
3693+ case NAL_IDR_SLICE:
3694+ case NAL_SLICE:
36933695 nals_needed = nal_index;
36943696 }
36953697 continue;
libavcodec/resample.c+2−2
@@ -239,8 +239,8 @@ ReSampleContext *av_audio_resample_init(int output_channels, int input_channels, · 238 unmodified lines
239239
240240 s->sample_fmt[0] = sample_fmt_in;
241241 s->sample_fmt[1] = sample_fmt_out;
242− s->sample_size[0] = av_get_bits_per_sample_fmt(s->sample_fmt[0]) >> 3;
243− s->sample_size[1] = av_get_bits_per_sample_fmt(s->sample_fmt[1]) >> 3;
242+ s->sample_size[0] = av_get_bytes_per_sample(s->sample_fmt[0]);
243+ s->sample_size[1] = av_get_bytes_per_sample(s->sample_fmt[1]);
244244
245245 if (s->sample_fmt[0] != AV_SAMPLE_FMT_S16) {
246246 if (!(s->convert_ctx[0] = av_audio_convert_alloc(AV_SAMPLE_FMT_S16, 1,
libavcodec/utils.c+1−1
@@ -1210,7 +1210,7 @@ int av_get_bits_per_sample(enum CodecID codec_id){ · 1209 unmodified lines
12101210
12111211 #if FF_API_OLD_SAMPLE_FMT
12121212 int av_get_bits_per_sample_format(enum AVSampleFormat sample_fmt) {
1213− return av_get_bits_per_sample_fmt(sample_fmt);
1213+ return av_get_bytes_per_sample(sample_fmt) << 3;
12141214 }
12151215 #endif
12161216
libavcodec/vmdav.c+1−1
@@ -450,7 +450,7 @@ static av_cold int vmdaudio_decode_init(AVCodecContext *avctx) · 449 unmodified lines
450450 avctx->sample_fmt = AV_SAMPLE_FMT_S16;
451451 else
452452 avctx->sample_fmt = AV_SAMPLE_FMT_U8;
453− s->out_bps = av_get_bits_per_sample_fmt(avctx->sample_fmt) >> 3;
453+ s->out_bps = av_get_bytes_per_sample(avctx->sample_fmt);
454454
455455 av_log(avctx, AV_LOG_DEBUG, "%d channels, %d bits/sample, "
456456 "block align = %d, sample rate = %d\n",
libavcodec/vorbisdec.c+1−1
@@ -1646,7 +1646,7 @@ static int vorbis_decode_frame(AVCodecContext *avccontext, · 1645 unmodified lines
16461646 vc->audio_channels);
16471647
16481648 *data_size = len * vc->audio_channels *
1649− (av_get_bits_per_sample_fmt(avccontext->sample_fmt) / 8);
1649+ av_get_bytes_per_sample(avccontext->sample_fmt);
16501650
16511651 return buf_size ;
16521652 }
libavcodec/x86/cabac.h+148−0
@@ -0,0 +1,148 @@
1+/*
2+ * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
3+ *
4+ * This file is part of Libav.
5+ *
6+ * Libav is free software; you can redistribute it and/or
7+ * modify it under the terms of the GNU Lesser General Public
8+ * License as published by the Free Software Foundation; either
9+ * version 2.1 of the License, or (at your option) any later version.
10+ *
11+ * Libav is distributed in the hope that it will be useful,
12+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+ * Lesser General Public License for more details.
15+ *
16+ * You should have received a copy of the GNU Lesser General Public
17+ * License along with Libav; if not, write to the Free Software
18+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19+ */
20+
21+#ifndef AVCODEC_X86_CABAC_H
22+#define AVCODEC_X86_CABAC_H
23+
24+#include "libavcodec/cabac.h"
25+#include "libavutil/attributes.h"
26+#include "libavutil/x86_cpu.h"
27+#include "config.h"
28+
29+#if HAVE_FAST_CMOV
30+#define BRANCHLESS_GET_CABAC_UPDATE(ret, cabac, statep, low, lowword, range, tmp)\
31+ "mov "tmp" , %%ecx \n\t"\
32+ "shl $17 , "tmp" \n\t"\
33+ "cmp "low" , "tmp" \n\t"\
34+ "cmova %%ecx , "range" \n\t"\
35+ "sbb %%ecx , %%ecx \n\t"\
36+ "and %%ecx , "tmp" \n\t"\
37+ "sub "tmp" , "low" \n\t"\
38+ "xor %%ecx , "ret" \n\t"
39+#else /* HAVE_FAST_CMOV */
40+#define BRANCHLESS_GET_CABAC_UPDATE(ret, cabac, statep, low, lowword, range, tmp)\
41+ "mov "tmp" , %%ecx \n\t"\
42+ "shl $17 , "tmp" \n\t"\
43+ "sub "low" , "tmp" \n\t"\
44+ "sar $31 , "tmp" \n\t" /*lps_mask*/\
45+ "sub %%ecx , "range" \n\t" /*RangeLPS - range*/\
46+ "and "tmp" , "range" \n\t" /*(RangeLPS - range)&lps_mask*/\
47+ "add %%ecx , "range" \n\t" /*new range*/\
48+ "shl $17 , %%ecx \n\t"\
49+ "and "tmp" , %%ecx \n\t"\
50+ "sub %%ecx , "low" \n\t"\
51+ "xor "tmp" , "ret" \n\t"
52+#endif /* HAVE_FAST_CMOV */
53+
54+#define BRANCHLESS_GET_CABAC(ret, cabac, statep, low, lowword, range, tmp, tmpbyte, byte) \
55+ "movzbl "statep" , "ret" \n\t"\
56+ "mov "range" , "tmp" \n\t"\
57+ "and $0xC0 , "range" \n\t"\
58+ "movzbl "MANGLE(ff_h264_lps_range)"("ret", "range", 2), "range" \n\t"\
59+ "sub "range" , "tmp" \n\t"\
60+ BRANCHLESS_GET_CABAC_UPDATE(ret, cabac, statep, low, lowword, \
61+ range, tmp) \
62+ "movzbl " MANGLE(ff_h264_norm_shift) "("range"), %%ecx \n\t"\
63+ "shl %%cl , "range" \n\t"\
64+ "movzbl "MANGLE(ff_h264_mlps_state)"+128("ret"), "tmp" \n\t"\
65+ "mov "tmpbyte" , "statep" \n\t"\
66+ "shl %%cl , "low" \n\t"\
67+ "test "lowword" , "lowword" \n\t"\
68+ " jnz 1f \n\t"\
69+ "mov "byte"("cabac"), %%"REG_c" \n\t"\
70+ "movzwl (%%"REG_c") , "tmp" \n\t"\
71+ "bswap "tmp" \n\t"\
72+ "shr $15 , "tmp" \n\t"\
73+ "sub $0xFFFF , "tmp" \n\t"\
74+ "add $2 , %%"REG_c" \n\t"\
75+ "mov %%"REG_c" , "byte "("cabac") \n\t"\
76+ "lea -1("low") , %%ecx \n\t"\
77+ "xor "low" , %%ecx \n\t"\
78+ "shr $15 , %%ecx \n\t"\
79+ "movzbl " MANGLE(ff_h264_norm_shift) "(%%ecx), %%ecx \n\t"\
80+ "neg %%ecx \n\t"\
81+ "add $7 , %%ecx \n\t"\
82+ "shl %%cl , "tmp" \n\t"\
83+ "add "tmp" , "low" \n\t"\
84+ "1: \n\t"
85+
86+#if ARCH_X86 && HAVE_7REGS && !defined(BROKEN_RELOCATIONS)
87+#define get_cabac_inline get_cabac_inline_x86
88+static av_always_inline int get_cabac_inline_x86(CABACContext *c,
89+ uint8_t *const state)
90+{
91+ int bit, low, range, tmp;
92+
93+ __asm__ volatile(
94+ "movl %a6(%5), %2 \n\t"
95+ "movl %a7(%5), %1 \n\t"
96+ BRANCHLESS_GET_CABAC("%0", "%5", "(%4)", "%1", "%w1", "%2",
97+ "%3", "%b3", "%a8")
98+ "movl %2, %a6(%5) \n\t"
99+ "movl %1, %a7(%5) \n\t"
100+
101+ :"=&r"(bit), "=&r"(low), "=&r"(range), "=&q"(tmp)
102+ :"r"(state), "r"(c),
103+ "i"(offsetof(CABACContext, range)), "i"(offsetof(CABACContext, low)),
104+ "i"(offsetof(CABACContext, bytestream))
105+ : "%"REG_c, "memory"
106+ );
107+ return bit & 1;
108+}
109+#endif /* ARCH_X86 && HAVE_7REGS && !defined(BROKEN_RELOCATIONS) */
110+
111+#define get_cabac_bypass_sign get_cabac_bypass_sign_x86
112+static av_always_inline int get_cabac_bypass_sign_x86(CABACContext *c, int val)
113+{
114+ x86_reg tmp;
115+ __asm__ volatile(
116+ "movl %a3(%2), %k1 \n\t"
117+ "movl %a4(%2), %%eax \n\t"
118+ "shl $17, %k1 \n\t"
119+ "add %%eax, %%eax \n\t"
120+ "sub %k1, %%eax \n\t"
121+ "cltd \n\t"
122+ "and %%edx, %k1 \n\t"
123+ "add %k1, %%eax \n\t"
124+ "xor %%edx, %%ecx \n\t"
125+ "sub %%edx, %%ecx \n\t"
126+ "test %%ax, %%ax \n\t"
127+ " jnz 1f \n\t"
128+ "mov %a5(%2), %1 \n\t"
129+ "subl $0xFFFF, %%eax \n\t"
130+ "movzwl (%1), %%edx \n\t"
131+ "bswap %%edx \n\t"
132+ "shrl $15, %%edx \n\t"
133+ "add $2, %1 \n\t"
134+ "addl %%edx, %%eax \n\t"
135+ "mov %1, %a5(%2) \n\t"
136+ "1: \n\t"
137+ "movl %%eax, %a4(%2) \n\t"
138+
139+ :"+c"(val), "=&r"(tmp)
140+ :"r"(c),
141+ "i"(offsetof(CABACContext, range)), "i"(offsetof(CABACContext, low)),
142+ "i"(offsetof(CABACContext, bytestream))
143+ : "%eax", "%edx", "memory"
144+ );
145+ return val;
146+}
147+
148+#endif /* AVCODEC_X86_CABAC_H */
libavcodec/x86/h264_i386.h+84−69
@@ -29,63 +29,72 @@ · 28 unmodified lines
2929 #ifndef AVCODEC_X86_H264_I386_H
3030 #define AVCODEC_X86_H264_I386_H
3131
32+#include <stddef.h>
33+
3234 #include "libavcodec/cabac.h"
35+#include "cabac.h"
3336
3437 //FIXME use some macros to avoid duplicating get_cabac (cannot be done yet
3538 //as that would make optimization work hard)
36−#if ARCH_X86 && HAVE_7REGS && HAVE_EBX_AVAILABLE && !defined(BROKEN_RELOCATIONS)
39+#if ARCH_X86 && HAVE_7REGS && !defined(BROKEN_RELOCATIONS)
3740 static int decode_significance_x86(CABACContext *c, int max_coeff,
3841 uint8_t *significant_coeff_ctx_base,
3942 int *index, x86_reg last_off){
4043 void *end= significant_coeff_ctx_base + max_coeff - 1;
41− int minusstart= -(int)significant_coeff_ctx_base;
42− int minusindex= 4-(int)index;
43− int coeff_count;
44+ int minusstart= -(intptr_t)significant_coeff_ctx_base;
45+ int minusindex= 4-(intptr_t)index;
46+ int bit;
47+ x86_reg coeff_count;
48+ int low;
49+ int range;
4450 __asm__ volatile(
45− "movl "RANGE "(%3), %%esi \n\t"
46− "movl "LOW "(%3), %%ebx \n\t"
51+ "movl %a11(%6), %5 \n\t"
52+ "movl %a12(%6), %3 \n\t"
4753
4854 "2: \n\t"
4955
50− BRANCHLESS_GET_CABAC("%%edx", "%3", "(%1)", "%%ebx",
51− "%%bx", "%%esi", "%%eax", "%%al")
56+ BRANCHLESS_GET_CABAC("%4", "%6", "(%1)", "%3",
57+ "%w3", "%5", "%k0", "%b0", "%a13")
5258
53− "test $1, %%edx \n\t"
59+ "test $1, %4 \n\t"
5460 " jz 3f \n\t"
55− "add %7, %1 \n\t"
61+ "add %10, %1 \n\t"
5662
57− BRANCHLESS_GET_CABAC("%%edx", "%3", "(%1)", "%%ebx",
58− "%%bx", "%%esi", "%%eax", "%%al")
63+ BRANCHLESS_GET_CABAC("%4", "%6", "(%1)", "%3",
64+ "%w3", "%5", "%k0", "%b0", "%a13")
5965
60− "sub %7, %1 \n\t"
61− "mov %2, %%"REG_a" \n\t"
62− "movl %4, %%ecx \n\t"
66+ "sub %10, %1 \n\t"
67+ "mov %2, %0 \n\t"
68+ "movl %7, %%ecx \n\t"
6369 "add %1, %%"REG_c" \n\t"
64− "movl %%ecx, (%%"REG_a") \n\t"
70+ "movl %%ecx, (%0) \n\t"
6571
66− "test $1, %%edx \n\t"
72+ "test $1, %4 \n\t"
6773 " jnz 4f \n\t"
6874
69− "add $4, %%"REG_a" \n\t"
70− "mov %%"REG_a", %2 \n\t"
75+ "add $4, %0 \n\t"
76+ "mov %0, %2 \n\t"
7177
7278 "3: \n\t"
7379 "add $1, %1 \n\t"
74− "cmp %5, %1 \n\t"
80+ "cmp %8, %1 \n\t"
7581 " jb 2b \n\t"
76− "mov %2, %%"REG_a" \n\t"
77− "movl %4, %%ecx \n\t"
82+ "mov %2, %0 \n\t"
83+ "movl %7, %%ecx \n\t"
7884 "add %1, %%"REG_c" \n\t"
79− "movl %%ecx, (%%"REG_a") \n\t"
85+ "movl %%ecx, (%0) \n\t"
8086 "4: \n\t"
81− "add %6, %%eax \n\t"
82− "shr $2, %%eax \n\t"
83−
84− "movl %%esi, "RANGE "(%3) \n\t"
85− "movl %%ebx, "LOW "(%3) \n\t"
86− :"=&a"(coeff_count), "+r"(significant_coeff_ctx_base), "+m"(index)
87− :"r"(c), "m"(minusstart), "m"(end), "m"(minusindex), "m"(last_off)
88− : "%"REG_c, "%ebx", "%edx", "%esi", "memory"
87+ "add %9, %k0 \n\t"
88+ "shr $2, %k0 \n\t"
89+
90+ "movl %5, %a11(%6) \n\t"
91+ "movl %3, %a12(%6) \n\t"
92+ :"=&q"(coeff_count), "+r"(significant_coeff_ctx_base), "+m"(index),
93+ "=&r"(low), "=&r"(bit), "=&r"(range)
94+ :"r"(c), "m"(minusstart), "m"(end), "m"(minusindex), "m"(last_off),
95+ "i"(offsetof(CABACContext, range)), "i"(offsetof(CABACContext, low)),
96+ "i"(offsetof(CABACContext, bytestream))
97+ : "%"REG_c, "memory"
8998 );
9099 return coeff_count;
91100 }
@@ -93,64 +102,70 @@ static int decode_significance_x86(CABACContext *c, int max_coeff, · 1 unmodified line
93102 static int decode_significance_8x8_x86(CABACContext *c,
94103 uint8_t *significant_coeff_ctx_base,
95104 int *index, x86_reg last_off, const uint8_t *sig_off){
96− int minusindex= 4-(int)index;
97− int coeff_count;
105+ int minusindex= 4-(intptr_t)index;
106+ int bit;
107+ x86_reg coeff_count;
108+ int low;
109+ int range;
98110 x86_reg last=0;
111+ x86_reg state;
99112 __asm__ volatile(
100− "movl "RANGE "(%3), %%esi \n\t"
101− "movl "LOW "(%3), %%ebx \n\t"
113+ "movl %a12(%7), %5 \n\t"
114+ "movl %a13(%7), %3 \n\t"
102115
103− "mov %1, %%"REG_D" \n\t"
116+ "mov %1, %6 \n\t"
104117 "2: \n\t"
105118
106− "mov %6, %%"REG_a" \n\t"
107− "movzbl (%%"REG_a", %%"REG_D"), %%edi \n\t"
108− "add %5, %%"REG_D" \n\t"
119+ "mov %10, %0 \n\t"
120+ "movzbl (%0, %6), %k6 \n\t"
121+ "add %9, %6 \n\t"
109122
110− BRANCHLESS_GET_CABAC("%%edx", "%3", "(%%"REG_D")", "%%ebx",
111− "%%bx", "%%esi", "%%eax", "%%al")
123+ BRANCHLESS_GET_CABAC("%4", "%7", "(%6)", "%3",
124+ "%w3", "%5", "%k0", "%b0", "%a14")
112125
113− "mov %1, %%edi \n\t"
114− "test $1, %%edx \n\t"
126+ "mov %1, %k6 \n\t"
127+ "test $1, %4 \n\t"
115128 " jz 3f \n\t"
116129
117− "movzbl "MANGLE(last_coeff_flag_offset_8x8)"(%%edi), %%edi\n\t"
118− "add %5, %%"REG_D" \n\t"
119− "add %7, %%"REG_D" \n\t"
130+ "movzbl "MANGLE(last_coeff_flag_offset_8x8)"(%k6), %k6\n\t"
131+ "add %9, %6 \n\t"
132+ "add %11, %6 \n\t"
120133
121− BRANCHLESS_GET_CABAC("%%edx", "%3", "(%%"REG_D")", "%%ebx",
122− "%%bx", "%%esi", "%%eax", "%%al")
134+ BRANCHLESS_GET_CABAC("%4", "%7", "(%6)", "%3",
135+ "%w3", "%5", "%k0", "%b0", "%a14")
123136
124− "mov %2, %%"REG_a" \n\t"
125− "mov %1, %%edi \n\t"
126− "movl %%edi, (%%"REG_a") \n\t"
137+ "mov %2, %0 \n\t"
138+ "mov %1, %k6 \n\t"
139+ "movl %k6, (%0) \n\t"
127140
128− "test $1, %%edx \n\t"
141+ "test $1, %4 \n\t"
129142 " jnz 4f \n\t"
130143
131− "add $4, %%"REG_a" \n\t"
132− "mov %%"REG_a", %2 \n\t"
144+ "add $4, %0 \n\t"
145+ "mov %0, %2 \n\t"
133146
134147 "3: \n\t"
135− "addl $1, %%edi \n\t"
136− "mov %%edi, %1 \n\t"
137− "cmpl $63, %%edi \n\t"
148+ "addl $1, %k6 \n\t"
149+ "mov %k6, %1 \n\t"
150+ "cmpl $63, %k6 \n\t"
138151 " jb 2b \n\t"
139− "mov %2, %%"REG_a" \n\t"
140− "movl %%edi, (%%"REG_a") \n\t"
152+ "mov %2, %0 \n\t"
153+ "movl %k6, (%0) \n\t"
141154 "4: \n\t"
142− "addl %4, %%eax \n\t"
143− "shr $2, %%eax \n\t"
144−
145− "movl %%esi, "RANGE "(%3) \n\t"
146− "movl %%ebx, "LOW "(%3) \n\t"
147− :"=&a"(coeff_count),"+m"(last), "+m"(index)
148− :"r"(c), "m"(minusindex), "m"(significant_coeff_ctx_base), "m"(sig_off), "m"(last_off)
149− : "%"REG_c, "%ebx", "%edx", "%esi", "%"REG_D, "memory"
155+ "addl %8, %k0 \n\t"
156+ "shr $2, %k0 \n\t"
157+
158+ "movl %5, %a12(%7) \n\t"
159+ "movl %3, %a13(%7) \n\t"
160+ :"=&q"(coeff_count),"+m"(last), "+m"(index), "=&r"(low), "=&r"(bit),
161+ "=&r"(range), "=&r"(state)
162+ :"r"(c), "m"(minusindex), "m"(significant_coeff_ctx_base), "m"(sig_off), "m"(last_off),
163+ "i"(offsetof(CABACContext, range)), "i"(offsetof(CABACContext, low)),
164+ "i"(offsetof(CABACContext, bytestream))
165+ : "%"REG_c, "memory"
150166 );
151167 return coeff_count;
152168 }
153−#endif /* ARCH_X86 && HAVE_7REGS && HAVE_EBX_AVAILABLE */
154− /* !defined(BROKEN_RELOCATIONS) */
169+#endif /* ARCH_X86 && HAVE_7REGS && !defined(BROKEN_RELOCATIONS) */
155170
156171 #endif /* AVCODEC_X86_H264_I386_H */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t