00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef AVCODEC_X86_CABAC_H
00022 #define AVCODEC_X86_CABAC_H
00023
00024 #include "libavcodec/cabac.h"
00025 #include "libavutil/attributes.h"
00026 #include "libavutil/x86_cpu.h"
00027 #include "config.h"
00028
00029 #if HAVE_FAST_CMOV
00030 #define BRANCHLESS_GET_CABAC_UPDATE(ret, statep, low, lowword, range, tmp)\
00031 "mov "tmp" , %%ecx \n\t"\
00032 "shl $17 , "tmp" \n\t"\
00033 "cmp "low" , "tmp" \n\t"\
00034 "cmova %%ecx , "range" \n\t"\
00035 "sbb %%ecx , %%ecx \n\t"\
00036 "and %%ecx , "tmp" \n\t"\
00037 "xor %%ecx , "ret" \n\t"\
00038 "sub "tmp" , "low" \n\t"
00039 #else
00040 #define BRANCHLESS_GET_CABAC_UPDATE(ret, statep, low, lowword, range, tmp)\
00041 "mov "tmp" , %%ecx \n\t"\
00042 "shl $17 , "tmp" \n\t"\
00043 "sub "low" , "tmp" \n\t"\
00044 "sar $31 , "tmp" \n\t" \
00045 "sub %%ecx , "range" \n\t" \
00046 "and "tmp" , "range" \n\t" \
00047 "add %%ecx , "range" \n\t" \
00048 "shl $17 , %%ecx \n\t"\
00049 "and "tmp" , %%ecx \n\t"\
00050 "sub %%ecx , "low" \n\t"\
00051 "xor "tmp" , "ret" \n\t"
00052 #endif
00053
00054 #define BRANCHLESS_GET_CABAC(ret, statep, low, lowword, range, tmp, tmpbyte, byte) \
00055 "movzbl "statep" , "ret" \n\t"\
00056 "mov "range" , "tmp" \n\t"\
00057 "and $0xC0 , "range" \n\t"\
00058 "movzbl "MANGLE(ff_h264_lps_range)"("ret", "range", 2), "range" \n\t"\
00059 "sub "range" , "tmp" \n\t"\
00060 BRANCHLESS_GET_CABAC_UPDATE(ret, statep, low, lowword, range, tmp) \
00061 "movzbl " MANGLE(ff_h264_norm_shift) "("range"), %%ecx \n\t"\
00062 "shl %%cl , "range" \n\t"\
00063 "movzbl "MANGLE(ff_h264_mlps_state)"+128("ret"), "tmp" \n\t"\
00064 "shl %%cl , "low" \n\t"\
00065 "mov "tmpbyte" , "statep" \n\t"\
00066 "test "lowword" , "lowword" \n\t"\
00067 " jnz 1f \n\t"\
00068 "mov "byte" , %%"REG_c" \n\t"\
00069 "add"OPSIZE" $2 , "byte" \n\t"\
00070 "movzwl (%%"REG_c") , "tmp" \n\t"\
00071 "lea -1("low") , %%ecx \n\t"\
00072 "xor "low" , %%ecx \n\t"\
00073 "shr $15 , %%ecx \n\t"\
00074 "bswap "tmp" \n\t"\
00075 "shr $15 , "tmp" \n\t"\
00076 "movzbl " MANGLE(ff_h264_norm_shift) "(%%ecx), %%ecx \n\t"\
00077 "sub $0xFFFF , "tmp" \n\t"\
00078 "neg %%ecx \n\t"\
00079 "add $7 , %%ecx \n\t"\
00080 "shl %%cl , "tmp" \n\t"\
00081 "add "tmp" , "low" \n\t"\
00082 "1: \n\t"
00083
00084
00085 #if HAVE_7REGS && !defined(BROKEN_RELOCATIONS) && !(defined(__i386) && defined(__clang__) && (__clang_major__<2 || (__clang_major__==2 && __clang_minor__<10)))\
00086 && !(defined(__i386) && !defined(__clang__) && defined(__llvm__) && __GNUC__==4 && __GNUC_MINOR__==2 && __GNUC_PATCHLEVEL__<=1)
00087 #define get_cabac_inline get_cabac_inline_x86
00088 static av_always_inline int get_cabac_inline_x86(CABACContext *c,
00089 uint8_t *const state)
00090 {
00091 int bit, tmp;
00092
00093 __asm__ volatile(
00094 BRANCHLESS_GET_CABAC("%0", "(%5)", "%1", "%w1", "%2",
00095 "%3", "%b3", "%4")
00096 :"=&r"(bit), "+&r"(c->low), "+&r"(c->range), "=&q"(tmp),
00097 "+m"(c->bytestream)
00098 :"r"(state)
00099 : "%"REG_c, "memory"
00100 );
00101 return bit & 1;
00102 }
00103 #endif
00104
00105 #define get_cabac_bypass_sign get_cabac_bypass_sign_x86
00106 static av_always_inline int get_cabac_bypass_sign_x86(CABACContext *c, int val)
00107 {
00108 x86_reg tmp;
00109 __asm__ volatile(
00110 "movl %a5(%2), %k1 \n\t"
00111 "movl %a3(%2), %%eax \n\t"
00112 "shl $17, %k1 \n\t"
00113 "add %%eax, %%eax \n\t"
00114 "sub %k1, %%eax \n\t"
00115 "cltd \n\t"
00116 "and %%edx, %k1 \n\t"
00117 "add %k1, %%eax \n\t"
00118 "xor %%edx, %%ecx \n\t"
00119 "sub %%edx, %%ecx \n\t"
00120 "test %%ax, %%ax \n\t"
00121 " jnz 1f \n\t"
00122 "mov %a4(%2), %1 \n\t"
00123 "subl $0xFFFF, %%eax \n\t"
00124 "movzwl (%1), %%edx \n\t"
00125 "bswap %%edx \n\t"
00126 "shrl $15, %%edx \n\t"
00127 "add $2, %1 \n\t"
00128 "addl %%edx, %%eax \n\t"
00129 "mov %1, %a4(%2) \n\t"
00130 "1: \n\t"
00131 "movl %%eax, %a3(%2) \n\t"
00132
00133 : "+c"(val), "=&r"(tmp)
00134 : "r"(c),
00135 "i"(offsetof(CABACContext, low)),
00136 "i"(offsetof(CABACContext, bytestream)),
00137 "i"(offsetof(CABACContext, range))
00138 : "%eax", "%edx", "memory"
00139 );
00140 return val;
00141 }
00142
00143 #endif