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, cabac, 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, cabac, 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, cabac, 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, cabac, statep, low, lowword, \
00061 range, tmp) \
00062 "movzbl " MANGLE(ff_h264_norm_shift) "("range"), %%ecx \n\t"\
00063 "shl %%cl , "range" \n\t"\
00064 "movzbl "MANGLE(ff_h264_mlps_state)"+128("ret"), "tmp" \n\t"\
00065 "shl %%cl , "low" \n\t"\
00066 "mov "tmpbyte" , "statep" \n\t"\
00067 "test "lowword" , "lowword" \n\t"\
00068 " jnz 1f \n\t"\
00069 "mov "byte"("cabac"), %%"REG_c" \n\t"\
00070 "add"OPSIZE" $2 , "byte "("cabac") \n\t"\
00071 "movzwl (%%"REG_c") , "tmp" \n\t"\
00072 "lea -1("low") , %%ecx \n\t"\
00073 "xor "low" , %%ecx \n\t"\
00074 "shr $15 , %%ecx \n\t"\
00075 "bswap "tmp" \n\t"\
00076 "shr $15 , "tmp" \n\t"\
00077 "movzbl " MANGLE(ff_h264_norm_shift) "(%%ecx), %%ecx \n\t"\
00078 "sub $0xFFFF , "tmp" \n\t"\
00079 "neg %%ecx \n\t"\
00080 "add $7 , %%ecx \n\t"\
00081 "shl %%cl , "tmp" \n\t"\
00082 "add "tmp" , "low" \n\t"\
00083 "1: \n\t"
00084
00085 #if HAVE_7REGS && !defined(BROKEN_RELOCATIONS)
00086 #define get_cabac_inline get_cabac_inline_x86
00087 static av_always_inline int get_cabac_inline_x86(CABACContext *c,
00088 uint8_t *const state)
00089 {
00090 int bit, low, range, tmp;
00091
00092 __asm__ volatile(
00093 "movl %a6(%5), %2 \n\t"
00094 "movl %a7(%5), %1 \n\t"
00095 BRANCHLESS_GET_CABAC("%0", "%5", "(%4)", "%1", "%w1", "%2",
00096 "%3", "%b3", "%a8")
00097 "movl %2, %a6(%5) \n\t"
00098 "movl %1, %a7(%5) \n\t"
00099
00100 :"=&r"(bit), "=&r"(low), "=&r"(range), "=&q"(tmp)
00101 :"r"(state), "r"(c),
00102 "i"(offsetof(CABACContext, range)), "i"(offsetof(CABACContext, low)),
00103 "i"(offsetof(CABACContext, bytestream))
00104 : "%"REG_c, "memory"
00105 );
00106 return bit & 1;
00107 }
00108 #endif
00109
00110 #define get_cabac_bypass_sign get_cabac_bypass_sign_x86
00111 static av_always_inline int get_cabac_bypass_sign_x86(CABACContext *c, int val)
00112 {
00113 x86_reg tmp;
00114 __asm__ volatile(
00115 "movl %a3(%2), %k1 \n\t"
00116 "movl %a4(%2), %%eax \n\t"
00117 "shl $17, %k1 \n\t"
00118 "add %%eax, %%eax \n\t"
00119 "sub %k1, %%eax \n\t"
00120 "cltd \n\t"
00121 "and %%edx, %k1 \n\t"
00122 "add %k1, %%eax \n\t"
00123 "xor %%edx, %%ecx \n\t"
00124 "sub %%edx, %%ecx \n\t"
00125 "test %%ax, %%ax \n\t"
00126 " jnz 1f \n\t"
00127 "mov %a5(%2), %1 \n\t"
00128 "subl $0xFFFF, %%eax \n\t"
00129 "movzwl (%1), %%edx \n\t"
00130 "bswap %%edx \n\t"
00131 "shrl $15, %%edx \n\t"
00132 "add $2, %1 \n\t"
00133 "addl %%edx, %%eax \n\t"
00134 "mov %1, %a5(%2) \n\t"
00135 "1: \n\t"
00136 "movl %%eax, %a4(%2) \n\t"
00137
00138 :"+c"(val), "=&r"(tmp)
00139 :"r"(c),
00140 "i"(offsetof(CABACContext, range)), "i"(offsetof(CABACContext, low)),
00141 "i"(offsetof(CABACContext, bytestream))
00142 : "%eax", "%edx", "memory"
00143 );
00144 return val;
00145 }
00146
00147 #endif