[FFmpeg-devel] [PATCH] replace hardcoded offset of CABACContext.bytestream with "m" operand

Mans Rullgard mans
Mon Mar 17 22:01:20 CET 2008


---
 libavcodec/cabac.h |   54 ++++++++++++++++++++++-----------------------------
 1 files changed, 23 insertions(+), 31 deletions(-)

diff --git a/libavcodec/cabac.h b/libavcodec/cabac.h
index ea2ee3e..7bb7ede 100644
--- a/libavcodec/cabac.h
+++ b/libavcodec/cabac.h
@@ -374,15 +374,6 @@ static av_always_inline int get_cabac_inline(CABACContext *c, uint8_t * const st
     //FIXME gcc generates duplicate load/stores for c->low and c->range
 #define LOW          "0"
 #define RANGE        "4"
-#ifdef ARCH_X86_64
-#define BYTESTART   "16"
-#define BYTE        "24"
-#define BYTEEND     "32"
-#else
-#define BYTESTART   "12"
-#define BYTE        "16"
-#define BYTEEND     "20"
-#endif
 #if defined(ARCH_X86) && defined(HAVE_7REGS) && defined(HAVE_EBX_AVAILABLE) && !defined(BROKEN_RELOCATIONS)
     int bit;
 
@@ -419,14 +410,14 @@ static av_always_inline int get_cabac_inline(CABACContext *c, uint8_t * const st
 //eax:state ebx:low, edx:range, esi:RangeLPS
         "test %%bx, %%bx                        \n\t"
         " jnz 2f                                \n\t"
-        "mov  "BYTE     "(%2), %%"REG_S"        \n\t"
+        "mov  %3, %%"REG_S"                     \n\t"
         "subl $0xFFFF, %%ebx                    \n\t"
         "movzwl (%%"REG_S"), %%ecx              \n\t"
         "bswap %%ecx                            \n\t"
         "shrl $15, %%ecx                        \n\t"
         "add  $2, %%"REG_S"                     \n\t"
         "addl %%ecx, %%ebx                      \n\t"
-        "mov  %%"REG_S", "BYTE    "(%2)         \n\t"
+        "mov  %%"REG_S", %3                     \n\t"
         "jmp 2f                                 \n\t"
         "1:                                     \n\t"
 //eax:state ebx:low, edx:range, esi:RangeLPS
@@ -441,13 +432,13 @@ static av_always_inline int get_cabac_inline(CABACContext *c, uint8_t * const st
         "test %%bx, %%bx                        \n\t"
         " jnz 2f                                \n\t"
 
-        "mov  "BYTE     "(%2), %%"REG_c"        \n\t"
+        "mov  %3, %%"REG_c"                     \n\t"
         "movzwl (%%"REG_c"), %%esi              \n\t"
         "bswap %%esi                            \n\t"
         "shrl $15, %%esi                        \n\t"
         "subl $0xFFFF, %%esi                    \n\t"
         "add  $2, %%"REG_c"                     \n\t"
-        "mov  %%"REG_c", "BYTE    "(%2)         \n\t"
+        "mov  %%"REG_c", %3                     \n\t"
 
         "leal -1(%%ebx), %%ecx                  \n\t"
         "xorl %%ebx, %%ecx                      \n\t"
@@ -462,7 +453,7 @@ static av_always_inline int get_cabac_inline(CABACContext *c, uint8_t * const st
         "movl %%edx, "RANGE    "(%2)            \n\t"
         "movl %%ebx, "LOW      "(%2)            \n\t"
         :"=&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
-        :"r"(state), "r"(c)
+        :"r"(state), "r"(c), "m"(c->bytestream)
         : "%"REG_c, "%ebx", "%edx", "%"REG_S, "memory"
     );
     bit&=1;
@@ -495,7 +486,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, bytestream) \
         "movzbl "statep"    , "ret"                                     \n\t"\
         "mov    "range"     , "tmp"                                     \n\t"\
         "and    $0xC0       , "range"                                   \n\t"\
@@ -509,13 +500,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   "bytestream" , %%"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"   , "bytestream"                              \n\t"\
         "lea    -1("low")   , %%ecx                                     \n\t"\
         "xor    "low"       , %%ecx                                     \n\t"\
         "shr    $15         , %%ecx                                     \n\t"\
@@ -529,12 +520,12 @@ static av_always_inline int get_cabac_inline(CABACContext *c, uint8_t * const st
     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")
+        BRANCHLESS_GET_CABAC("%0", "%2", "(%1)", "%%ebx", "%%bx", "%%esi", "%%edx", "%%dl", "%3")
         "movl %%esi, "RANGE    "(%2)            \n\t"
         "movl %%ebx, "LOW      "(%2)            \n\t"
 
         :"=&a"(bit)
-        :"r"(state), "r"(c)
+        :"r"(state), "r"(c), "m"(c->bytestream)
         : "%"REG_c, "%ebx", "%edx", "%esi", "memory"
     );
     bit&=1;
@@ -604,19 +595,19 @@ static int get_cabac_bypass(CABACContext *c){
         "add %%ebx, %%eax                       \n\t"
         "test %%ax, %%ax                        \n\t"
         " jnz 1f                                \n\t"
-        "movl "BYTE     "(%1), %%"REG_b"        \n\t"
+        "movl %2, %%"REG_b"                     \n\t"
         "subl $0xFFFF, %%eax                    \n\t"
         "movzwl (%%"REG_b"), %%ecx              \n\t"
         "bswap %%ecx                            \n\t"
         "shrl $15, %%ecx                        \n\t"
         "addl $2, %%"REG_b"                     \n\t"
         "addl %%ecx, %%eax                      \n\t"
-        "movl %%"REG_b", "BYTE     "(%1)        \n\t"
+        "movl %%"REG_b", %2                     \n\t"
         "1:                                     \n\t"
         "movl %%eax, "LOW      "(%1)            \n\t"
 
         :"=&d"(bit)
-        :"r"(c)
+        :"r"(c), "m"(c->bytestream)
         : "%eax", "%"REG_b, "%ecx", "memory"
     );
     return bit+1;
@@ -653,19 +644,19 @@ 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  %2, %%"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", %2                     \n\t"
         "1:                                     \n\t"
         "movl %%eax, "LOW      "(%1)            \n\t"
 
         :"+c"(val)
-        :"r"(c)
+        :"r"(c), "m"(c->bytestream)
         : "%eax", "%"REG_b, "%edx", "memory"
     );
     return val;
@@ -699,12 +690,12 @@ static int decode_significance_x86(CABACContext *c, int max_coeff, uint8_t *sign
 
         "2:                                     \n\t"
 
-        BRANCHLESS_GET_CABAC("%%edx", "%3", "(%1)", "%%ebx", "%%bx", "%%esi", "%%eax", "%%al")
+        BRANCHLESS_GET_CABAC("%%edx", "%3", "(%1)", "%%ebx", "%%bx", "%%esi", "%%eax", "%%al", "%7")
 
         "test $1, %%edx                         \n\t"
         " jz 3f                                 \n\t"
 
-        BRANCHLESS_GET_CABAC("%%edx", "%3", "61(%1)", "%%ebx", "%%bx", "%%esi", "%%eax", "%%al")
+        BRANCHLESS_GET_CABAC("%%edx", "%3", "61(%1)", "%%ebx", "%%bx", "%%esi", "%%eax", "%%al", "%7")
 
         "mov  %2, %%"REG_a"                     \n\t"
         "movl %4, %%ecx                         \n\t"
@@ -732,7 +723,8 @@ static int decode_significance_x86(CABACContext *c, int max_coeff, uint8_t *sign
         "movl %%esi, "RANGE    "(%3)            \n\t"
         "movl %%ebx, "LOW      "(%3)            \n\t"
         :"=&a"(coeff_count), "+r"(significant_coeff_ctx_base), "+m"(index)
-        :"r"(c), "m"(minusstart), "m"(end), "m"(minusindex)
+        :"r"(c), "m"(minusstart), "m"(end), "m"(minusindex),
+         "m"(c->bytestream)
         : "%"REG_c, "%ebx", "%edx", "%esi", "memory"
     );
     return coeff_count;
@@ -753,7 +745,7 @@ static int decode_significance_8x8_x86(CABACContext *c, uint8_t *significant_coe
         "movzbl (%%"REG_a", %%"REG_D"), %%edi   \n\t"
         "add %5, %%"REG_D"                      \n\t"
 
-        BRANCHLESS_GET_CABAC("%%edx", "%3", "(%%"REG_D")", "%%ebx", "%%bx", "%%esi", "%%eax", "%%al")
+        BRANCHLESS_GET_CABAC("%%edx", "%3", "(%%"REG_D")", "%%ebx", "%%bx", "%%esi", "%%eax", "%%al", "%7")
 
         "mov %1, %%edi                          \n\t"
         "test $1, %%edx                         \n\t"
@@ -762,7 +754,7 @@ static int decode_significance_8x8_x86(CABACContext *c, uint8_t *significant_coe
         "movzbl "MANGLE(last_coeff_flag_offset_8x8)"(%%edi), %%edi\n\t"
         "add %5, %%"REG_D"                      \n\t"
 
-        BRANCHLESS_GET_CABAC("%%edx", "%3", "15(%%"REG_D")", "%%ebx", "%%bx", "%%esi", "%%eax", "%%al")
+        BRANCHLESS_GET_CABAC("%%edx", "%3", "15(%%"REG_D")", "%%ebx", "%%bx", "%%esi", "%%eax", "%%al", "%7")
 
         "mov %2, %%"REG_a"                      \n\t"
         "mov %1, %%edi                          \n\t"
@@ -788,7 +780,7 @@ static int decode_significance_8x8_x86(CABACContext *c, uint8_t *significant_coe
         "movl %%esi, "RANGE    "(%3)            \n\t"
         "movl %%ebx, "LOW      "(%3)            \n\t"
         :"=&a"(coeff_count),"+m"(last), "+m"(index)
-        :"r"(c), "m"(minusindex), "m"(significant_coeff_ctx_base), "m"(sig_off)
+        :"r"(c), "m"(minusindex), "m"(significant_coeff_ctx_base), "m"(sig_off), "m"(c->bytestream)
         : "%"REG_c, "%ebx", "%edx", "%esi", "%"REG_D, "memory"
     );
     return coeff_count;
-- 
1.5.4.3





More information about the ffmpeg-devel mailing list