21 #ifndef AVCODEC_X86_CABAC_H 
   22 #define AVCODEC_X86_CABAC_H 
   30 #if   (defined(__i386) && defined(__clang__) && (__clang_major__<2 || (__clang_major__==2 && __clang_minor__<10)))\ 
   31    || (                  !defined(__clang__) && defined(__llvm__) && __GNUC__==4 && __GNUC_MINOR__==2 && __GNUC_PATCHLEVEL__<=1) 
   32 #       define BROKEN_COMPILER 1 
   34 #       define BROKEN_COMPILER 0 
   39 #ifdef BROKEN_RELOCATIONS 
   40 #define TABLES_ARG , "r"(tables) 
   43 #define BRANCHLESS_GET_CABAC_UPDATE(ret, retq, low, range, tmp) \ 
   44         "cmp    "low"       , "tmp"                        \n\t"\ 
   45         "cmova  %%ecx       , "range"                      \n\t"\ 
   46         "sbb    %%rcx       , %%rcx                        \n\t"\ 
   47         "and    %%ecx       , "tmp"                        \n\t"\ 
   48         "xor    %%rcx       , "retq"                       \n\t"\ 
   49         "sub    "tmp"       , "low"                        \n\t" 
   51 #define BRANCHLESS_GET_CABAC_UPDATE(ret, retq, low, range, tmp) \ 
   53         "sub    "low"       , "tmp"                        \n\t"\ 
   54         "sar    $31         , "tmp"                        \n\t"\ 
   55         "sub    %%ecx       , "range"                      \n\t"\ 
   56         "and    "tmp"       , "range"                      \n\t"\ 
   57         "add    %%ecx       , "range"                      \n\t"\ 
   58         "shl    $17         , %%ecx                        \n\t"\ 
   59         "and    "tmp"       , %%ecx                        \n\t"\ 
   60         "sub    %%ecx       , "low"                        \n\t"\ 
   61         "xor    "tmp"       , "ret"                        \n\t"\ 
   62         "movslq "ret"       , "retq"                       \n\t" 
   65 #define BRANCHLESS_GET_CABAC(ret, retq, statep, low, lowword, range, rangeq, tmp, tmpbyte, byte, end, norm_off, lps_off, mlps_off, tables) \ 
   66         "movzbl "statep"    , "ret"                                     \n\t"\ 
   67         "mov    "range"     , "tmp"                                     \n\t"\ 
   68         "and    $0xC0       , "range"                                   \n\t"\ 
   69         "lea    ("ret", "range", 2), %%ecx                              \n\t"\ 
   70         "movzbl "lps_off"("tables", %%rcx), "range"                     \n\t"\ 
   71         "sub    "range"     , "tmp"                                     \n\t"\ 
   72         "mov    "tmp"       , %%ecx                                     \n\t"\ 
   73         "shl    $17         , "tmp"                                     \n\t"\ 
   74         BRANCHLESS_GET_CABAC_UPDATE(ret, retq, low, range, tmp)              \ 
   75         "movzbl "norm_off"("tables", "rangeq"), %%ecx                   \n\t"\ 
   76         "shl    %%cl        , "range"                                   \n\t"\ 
   77         "movzbl "mlps_off"+128("tables", "retq"), "tmp"                 \n\t"\ 
   78         "shl    %%cl        , "low"                                     \n\t"\ 
   79         "mov    "tmpbyte"   , "statep"                                  \n\t"\ 
   80         "test   "lowword"   , "lowword"                                 \n\t"\ 
   82         "mov    "byte"      , %%"REG_c"                                 \n\t"\ 
   83         "add"OPSIZE" $2     , "byte"                                    \n\t"\ 
   84         "movzwl (%%"REG_c") , "tmp"                                     \n\t"\ 
   85         "lea    -1("low")   , %%ecx                                     \n\t"\ 
   86         "xor    "low"       , %%ecx                                     \n\t"\ 
   87         "shr    $15         , %%ecx                                     \n\t"\ 
   89         "shr    $15         , "tmp"                                     \n\t"\ 
   90         "movzbl "norm_off"("tables", %%rcx), %%ecx                      \n\t"\ 
   91         "sub    $0xFFFF     , "tmp"                                     \n\t"\ 
   93         "add    $7          , %%ecx                                     \n\t"\ 
   94         "shl    %%cl        , "tmp"                                     \n\t"\ 
   95         "add    "tmp"       , "low"                                     \n\t"\ 
  103 #define BRANCHLESS_GET_CABAC_UPDATE(ret, low, range, tmp)\ 
  104         "mov    "tmp"       , %%ecx     \n\t"\ 
  105         "shl    $17         , "tmp"     \n\t"\ 
  106         "cmp    "low"       , "tmp"     \n\t"\ 
  107         "cmova  %%ecx       , "range"   \n\t"\ 
  108         "sbb    %%ecx       , %%ecx     \n\t"\ 
  109         "and    %%ecx       , "tmp"     \n\t"\ 
  110         "xor    %%ecx       , "ret"     \n\t"\ 
  111         "sub    "tmp"       , "low"     \n\t" 
  113 #define BRANCHLESS_GET_CABAC_UPDATE(ret, low, range, tmp)\ 
  114         "mov    "tmp"       , %%ecx     \n\t"\ 
  115         "shl    $17         , "tmp"     \n\t"\ 
  116         "sub    "low"       , "tmp"     \n\t"\ 
  117         "sar    $31         , "tmp"     \n\t" \ 
  118         "sub    %%ecx       , "range"   \n\t" \ 
  119         "and    "tmp"       , "range"   \n\t" \ 
  120         "add    %%ecx       , "range"   \n\t" \ 
  121         "shl    $17         , %%ecx     \n\t"\ 
  122         "and    "tmp"       , %%ecx     \n\t"\ 
  123         "sub    %%ecx       , "low"     \n\t"\ 
  124         "xor    "tmp"       , "ret"     \n\t" 
  127 #define BRANCHLESS_GET_CABAC(ret, retq, statep, low, lowword, range, rangeq, tmp, tmpbyte, byte, end, norm_off, lps_off, mlps_off, tables) \ 
  128         "movzbl "statep"    , "ret"                                     \n\t"\ 
  129         "mov    "range"     , "tmp"                                     \n\t"\ 
  130         "and    $0xC0       , "range"                                   \n\t"\ 
  131         "movzbl "MANGLE(ff_h264_cabac_tables)"+"lps_off"("ret", "range", 2), "range" \n\t"\ 
  132         "sub    "range"     , "tmp"                                     \n\t"\ 
  133         BRANCHLESS_GET_CABAC_UPDATE(ret, low, range, tmp)                    \ 
  134         "movzbl "MANGLE(ff_h264_cabac_tables)"+"norm_off"("range"), %%ecx    \n\t"\ 
  135         "shl    %%cl        , "range"                                   \n\t"\ 
  136         "movzbl "MANGLE(ff_h264_cabac_tables)"+"mlps_off"+128("ret"), "tmp"  \n\t"\ 
  137         "shl    %%cl        , "low"                                     \n\t"\ 
  138         "mov    "tmpbyte"   , "statep"                                  \n\t"\ 
  139         "test   "lowword"   , "lowword"                                 \n\t"\ 
  141         "mov    "byte"      , %%"REG_c"                                 \n\t"\ 
  142         "add"OPSIZE" $2     , "byte"                                    \n\t"\ 
  143         "movzwl (%%"REG_c")     , "tmp"                                 \n\t"\ 
  144         "lea    -1("low")   , %%ecx                                     \n\t"\ 
  145         "xor    "low"       , %%ecx                                     \n\t"\ 
  146         "shr    $15         , %%ecx                                     \n\t"\ 
  148         "shr    $15         , "tmp"                                     \n\t"\ 
  149         "movzbl "MANGLE(ff_h264_cabac_tables)"+"norm_off"(%%ecx), %%ecx \n\t"\ 
  150         "sub    $0xFFFF     , "tmp"                                     \n\t"\ 
  152         "add    $7          , %%ecx                                     \n\t"\ 
  153         "shl    %%cl        , "tmp"                                     \n\t"\ 
  154         "add    "tmp"       , "low"                                     \n\t"\ 
  159 #if HAVE_7REGS && !BROKEN_COMPILER 
  160 #define get_cabac_inline get_cabac_inline_x86 
  165 #ifdef BROKEN_RELOCATIONS 
  175         BRANCHLESS_GET_CABAC(
"%0", 
"%q0", 
"(%4)", 
"%1", 
"%w1",
 
  176                              "%2", 
"%q2", 
"%3", 
"%b3",
 
  177                              "%c6(%5)", 
"%c7(%5)",
 
  182         : 
"=&r"(bit), 
"=&r"(c->
low), 
"=&r"(c->
range), 
"=&q"(tmp)
 
  183         : 
"r"(
state), 
"r"(c),
 
  194 #define get_cabac_bypass_sign get_cabac_bypass_sign_x86 
  199         "movl        %c6(%2), %k1       \n\t" 
  200         "movl        %c3(%2), %%eax     \n\t" 
  202         "add           %%eax, %%eax     \n\t" 
  203         "sub             %k1, %%eax     \n\t" 
  205         "and           %%edx, %k1       \n\t" 
  206         "add             %k1, %%eax     \n\t" 
  207         "xor           %%edx, %%ecx     \n\t" 
  208         "sub           %%edx, %%ecx     \n\t" 
  209         "test           %%ax, %%ax      \n\t" 
  211         "mov         %c4(%2), %1        \n\t" 
  212         "subl        $0xFFFF, %%eax     \n\t" 
  213         "movzwl         (%1), %%edx     \n\t" 
  215         "shrl            $15, %%edx     \n\t" 
  217         "addl          %%edx, %%eax     \n\t" 
  218         "mov              %1, %c4(%2)   \n\t" 
  220         "movl          %%eax, %c3(%2)   \n\t" 
  222         : 
"+c"(
val), 
"=&r"(tmp)
 
  228         : 
"%eax", 
"%edx", 
"memory" 
  234 #define get_cabac_bypass get_cabac_bypass_x86 
  240         "movl        %c6(%2), %k1       \n\t" 
  241         "movl        %c3(%2), %%eax     \n\t" 
  243         "add           %%eax, %%eax     \n\t" 
  244         "sub             %k1, %%eax     \n\t" 
  246         "and           %%edx, %k1       \n\t" 
  247         "add             %k1, %%eax     \n\t" 
  249         "test           %%ax, %%ax      \n\t" 
  251         "mov         %c4(%2), %1        \n\t" 
  252         "subl        $0xFFFF, %%eax     \n\t" 
  253         "movzwl         (%1), %%ecx     \n\t" 
  255         "shrl            $15, %%ecx     \n\t" 
  256         "addl          %%ecx, %%eax     \n\t" 
  257         "cmp         %c5(%2), %1        \n\t" 
  259         "add"OPSIZE
"      $2, %c4(%2)   \n\t" 
  261         "movl          %%eax, %c3(%2)   \n\t" 
  263         : 
"=&d"(
res), 
"=&r"(tmp)
 
  269         : 
"%eax", 
"%ecx", 
"memory"