diff options
author | Mans Rullgard <mans@mansr.com> | 2011-06-20 01:54:32 +0100 |
---|---|---|
committer | Mans Rullgard <mans@mansr.com> | 2011-06-20 22:36:30 +0100 |
commit | 6b712acc0e4face7e913fbffd03123fc24672654 (patch) | |
tree | 254fb29f91e7b0a1c5fc5e348fa09d414102a607 | |
parent | 34ee43fc0fa7f40a280f4f93a3c6aa5bf7a2704b (diff) | |
download | ffmpeg-6b712acc0e4face7e913fbffd03123fc24672654.tar.gz |
x86: cabac: remove hardcoded struct offsets from inline asm
Signed-off-by: Mans Rullgard <mans@mansr.com>
-rw-r--r-- | libavcodec/cabac.h | 47 | ||||
-rw-r--r-- | libavcodec/x86/h264_i386.h | 34 |
2 files changed, 41 insertions, 40 deletions
diff --git a/libavcodec/cabac.h b/libavcodec/cabac.h index 0993eb80b3..67a332eba8 100644 --- a/libavcodec/cabac.h +++ b/libavcodec/cabac.h @@ -27,6 +27,8 @@ #ifndef AVCODEC_CABAC_H #define AVCODEC_CABAC_H +#include <stddef.h> + #include "put_bits.h" //#undef NDEBUG @@ -307,17 +309,6 @@ static inline void renorm_cabac_decoder_once(CABACContext *c){ static av_always_inline int get_cabac_inline(CABACContext *c, uint8_t * const state){ //FIXME gcc generates duplicate load/stores for c->low and c->range -#define LOW "0" -#define RANGE "4" -#if ARCH_X86_64 -#define BYTESTART "16" -#define BYTE "24" -#define BYTEEND "32" -#else -#define BYTESTART "12" -#define BYTE "16" -#define BYTEEND "20" -#endif #if ARCH_X86 && HAVE_7REGS && HAVE_EBX_AVAILABLE && !defined(BROKEN_RELOCATIONS) int bit; @@ -347,7 +338,7 @@ static av_always_inline int get_cabac_inline(CABACContext *c, uint8_t * const st #endif /* HAVE_FAST_CMOV */ -#define BRANCHLESS_GET_CABAC(ret, cabac, statep, low, lowword, range, tmp, tmpbyte)\ +#define BRANCHLESS_GET_CABAC(ret, cabac, statep, low, lowword, range, tmp, tmpbyte, byte) \ "movzbl "statep" , "ret" \n\t"\ "mov "range" , "tmp" \n\t"\ "and $0xC0 , "range" \n\t"\ @@ -361,13 +352,13 @@ static av_always_inline int get_cabac_inline(CABACContext *c, uint8_t * const st "shl %%cl , "low" \n\t"\ "test "lowword" , "lowword" \n\t"\ " jnz 1f \n\t"\ - "mov "BYTE"("cabac"), %%"REG_c" \n\t"\ + "mov "byte"("cabac"), %%"REG_c" \n\t"\ "movzwl (%%"REG_c") , "tmp" \n\t"\ "bswap "tmp" \n\t"\ "shr $15 , "tmp" \n\t"\ "sub $0xFFFF , "tmp" \n\t"\ "add $2 , %%"REG_c" \n\t"\ - "mov %%"REG_c" , "BYTE "("cabac") \n\t"\ + "mov %%"REG_c" , "byte "("cabac") \n\t"\ "lea -1("low") , %%ecx \n\t"\ "xor "low" , %%ecx \n\t"\ "shr $15 , %%ecx \n\t"\ @@ -379,14 +370,16 @@ static av_always_inline int get_cabac_inline(CABACContext *c, uint8_t * const st "1: \n\t" __asm__ volatile( - "movl "RANGE "(%2), %%esi \n\t" - "movl "LOW "(%2), %%ebx \n\t" - BRANCHLESS_GET_CABAC("%0", "%2", "(%1)", "%%ebx", "%%bx", "%%esi", "%%edx", "%%dl") - "movl %%esi, "RANGE "(%2) \n\t" - "movl %%ebx, "LOW "(%2) \n\t" + "movl %a3(%2), %%esi \n\t" + "movl %a4(%2), %%ebx \n\t" + BRANCHLESS_GET_CABAC("%0", "%2", "(%1)", "%%ebx", "%%bx", "%%esi", "%%edx", "%%dl", "%a5") + "movl %%esi, %a3(%2) \n\t" + "movl %%ebx, %a4(%2) \n\t" :"=&a"(bit) - :"r"(state), "r"(c) + :"r"(state), "r"(c), + "i"(offsetof(CABACContext, range)), "i"(offsetof(CABACContext, low)), + "i"(offsetof(CABACContext, bytestream)) : "%"REG_c, "%ebx", "%edx", "%esi", "memory" ); bit&=1; @@ -442,8 +435,8 @@ static int av_unused get_cabac_bypass(CABACContext *c){ static av_always_inline int get_cabac_bypass_sign(CABACContext *c, int val){ #if ARCH_X86 && HAVE_EBX_AVAILABLE __asm__ volatile( - "movl "RANGE "(%1), %%ebx \n\t" - "movl "LOW "(%1), %%eax \n\t" + "movl %a2(%1), %%ebx \n\t" + "movl %a3(%1), %%eax \n\t" "shl $17, %%ebx \n\t" "add %%eax, %%eax \n\t" "sub %%ebx, %%eax \n\t" @@ -454,19 +447,21 @@ static av_always_inline int get_cabac_bypass_sign(CABACContext *c, int val){ "sub %%edx, %%ecx \n\t" "test %%ax, %%ax \n\t" " jnz 1f \n\t" - "mov "BYTE "(%1), %%"REG_b" \n\t" + "mov %a4(%1), %%"REG_b" \n\t" "subl $0xFFFF, %%eax \n\t" "movzwl (%%"REG_b"), %%edx \n\t" "bswap %%edx \n\t" "shrl $15, %%edx \n\t" "add $2, %%"REG_b" \n\t" "addl %%edx, %%eax \n\t" - "mov %%"REG_b", "BYTE "(%1) \n\t" + "mov %%"REG_b", %a4(%1) \n\t" "1: \n\t" - "movl %%eax, "LOW "(%1) \n\t" + "movl %%eax, %a3(%1) \n\t" :"+c"(val) - :"r"(c) + :"r"(c), + "i"(offsetof(CABACContext, range)), "i"(offsetof(CABACContext, low)), + "i"(offsetof(CABACContext, bytestream)) : "%eax", "%"REG_b, "%edx", "memory" ); return val; diff --git a/libavcodec/x86/h264_i386.h b/libavcodec/x86/h264_i386.h index e2dffe1e46..b6c225a2f1 100644 --- a/libavcodec/x86/h264_i386.h +++ b/libavcodec/x86/h264_i386.h @@ -29,6 +29,8 @@ #ifndef AVCODEC_X86_H264_I386_H #define AVCODEC_X86_H264_I386_H +#include <stddef.h> + #include "libavcodec/cabac.h" //FIXME use some macros to avoid duplicating get_cabac (cannot be done yet @@ -42,20 +44,20 @@ static int decode_significance_x86(CABACContext *c, int max_coeff, int minusindex= 4-(int)index; int coeff_count; __asm__ volatile( - "movl "RANGE "(%3), %%esi \n\t" - "movl "LOW "(%3), %%ebx \n\t" + "movl %a8(%3), %%esi \n\t" + "movl %a9(%3), %%ebx \n\t" "2: \n\t" BRANCHLESS_GET_CABAC("%%edx", "%3", "(%1)", "%%ebx", - "%%bx", "%%esi", "%%eax", "%%al") + "%%bx", "%%esi", "%%eax", "%%al", "%a10") "test $1, %%edx \n\t" " jz 3f \n\t" "add %7, %1 \n\t" BRANCHLESS_GET_CABAC("%%edx", "%3", "(%1)", "%%ebx", - "%%bx", "%%esi", "%%eax", "%%al") + "%%bx", "%%esi", "%%eax", "%%al", "%a10") "sub %7, %1 \n\t" "mov %2, %%"REG_a" \n\t" @@ -81,10 +83,12 @@ static int decode_significance_x86(CABACContext *c, int max_coeff, "add %6, %%eax \n\t" "shr $2, %%eax \n\t" - "movl %%esi, "RANGE "(%3) \n\t" - "movl %%ebx, "LOW "(%3) \n\t" + "movl %%esi, %a8(%3) \n\t" + "movl %%ebx, %a9(%3) \n\t" :"=&a"(coeff_count), "+r"(significant_coeff_ctx_base), "+m"(index) - :"r"(c), "m"(minusstart), "m"(end), "m"(minusindex), "m"(last_off) + :"r"(c), "m"(minusstart), "m"(end), "m"(minusindex), "m"(last_off), + "i"(offsetof(CABACContext, range)), "i"(offsetof(CABACContext, low)), + "i"(offsetof(CABACContext, bytestream)) : "%"REG_c, "%ebx", "%edx", "%esi", "memory" ); return coeff_count; @@ -97,8 +101,8 @@ static int decode_significance_8x8_x86(CABACContext *c, int coeff_count; x86_reg last=0; __asm__ volatile( - "movl "RANGE "(%3), %%esi \n\t" - "movl "LOW "(%3), %%ebx \n\t" + "movl %a8(%3), %%esi \n\t" + "movl %a9(%3), %%ebx \n\t" "mov %1, %%"REG_D" \n\t" "2: \n\t" @@ -108,7 +112,7 @@ static int decode_significance_8x8_x86(CABACContext *c, "add %5, %%"REG_D" \n\t" BRANCHLESS_GET_CABAC("%%edx", "%3", "(%%"REG_D")", "%%ebx", - "%%bx", "%%esi", "%%eax", "%%al") + "%%bx", "%%esi", "%%eax", "%%al", "%a10") "mov %1, %%edi \n\t" "test $1, %%edx \n\t" @@ -119,7 +123,7 @@ static int decode_significance_8x8_x86(CABACContext *c, "add %7, %%"REG_D" \n\t" BRANCHLESS_GET_CABAC("%%edx", "%3", "(%%"REG_D")", "%%ebx", - "%%bx", "%%esi", "%%eax", "%%al") + "%%bx", "%%esi", "%%eax", "%%al", "%a10") "mov %2, %%"REG_a" \n\t" "mov %1, %%edi \n\t" @@ -142,10 +146,12 @@ static int decode_significance_8x8_x86(CABACContext *c, "addl %4, %%eax \n\t" "shr $2, %%eax \n\t" - "movl %%esi, "RANGE "(%3) \n\t" - "movl %%ebx, "LOW "(%3) \n\t" + "movl %%esi, %a8(%3) \n\t" + "movl %%ebx, %a9(%3) \n\t" :"=&a"(coeff_count),"+m"(last), "+m"(index) - :"r"(c), "m"(minusindex), "m"(significant_coeff_ctx_base), "m"(sig_off), "m"(last_off) + :"r"(c), "m"(minusindex), "m"(significant_coeff_ctx_base), "m"(sig_off), "m"(last_off), + "i"(offsetof(CABACContext, range)), "i"(offsetof(CABACContext, low)), + "i"(offsetof(CABACContext, bytestream)) : "%"REG_c, "%ebx", "%edx", "%esi", "%"REG_D, "memory" ); return coeff_count; |