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 || (defined(__INTEL_COMPILER) && defined(_MSC_VER))
33 # define BROKEN_COMPILER 1
35 # define BROKEN_COMPILER 0
40 #ifndef UNCHECKED_BITSTREAM_READER
41 #define UNCHECKED_BITSTREAM_READER !CONFIG_SAFE_BITSTREAM_READER
44 #if UNCHECKED_BITSTREAM_READER
45 #define END_CHECK(end) ""
47 #define END_CHECK(end) \
48 "cmp "end" , %%"REG_c" \n\t"\
52 #ifdef BROKEN_RELOCATIONS
53 #define TABLES_ARG , "r"(tables)
56 #define BRANCHLESS_GET_CABAC_UPDATE(ret, retq, low, range, tmp) \
57 "cmp "low" , "tmp" \n\t"\
58 "cmova %%ecx , "range" \n\t"\
59 "sbb %%rcx , %%rcx \n\t"\
60 "and %%ecx , "tmp" \n\t"\
61 "xor %%rcx , "retq" \n\t"\
62 "sub "tmp" , "low" \n\t"
64 #define BRANCHLESS_GET_CABAC_UPDATE(ret, retq, low, range, tmp) \
66 "sub "low" , "tmp" \n\t"\
67 "sar $31 , "tmp" \n\t"\
68 "sub %%ecx , "range" \n\t"\
69 "and "tmp" , "range" \n\t"\
70 "add %%ecx , "range" \n\t"\
71 "shl $17 , %%ecx \n\t"\
72 "and "tmp" , %%ecx \n\t"\
73 "sub %%ecx , "low" \n\t"\
74 "xor "tmp" , "ret" \n\t"\
75 "movslq "ret" , "retq" \n\t"
78 #define BRANCHLESS_GET_CABAC(ret, retq, statep, low, lowword, range, rangeq, tmp, tmpbyte, byte, end, norm_off, lps_off, mlps_off, tables) \
79 "movzbl "statep" , "ret" \n\t"\
80 "mov "range" , "tmp" \n\t"\
81 "and $0xC0 , "range" \n\t"\
82 "lea ("ret", "range", 2), %%ecx \n\t"\
83 "movzbl "lps_off"("tables", %%rcx), "range" \n\t"\
84 "sub "range" , "tmp" \n\t"\
85 "mov "tmp" , %%ecx \n\t"\
86 "shl $17 , "tmp" \n\t"\
87 BRANCHLESS_GET_CABAC_UPDATE(ret, retq, low, range, tmp) \
88 "movzbl "norm_off"("tables", "rangeq"), %%ecx \n\t"\
89 "shl %%cl , "range" \n\t"\
90 "movzbl "mlps_off"+128("tables", "retq"), "tmp" \n\t"\
91 "shl %%cl , "low" \n\t"\
92 "mov "tmpbyte" , "statep" \n\t"\
93 "test "lowword" , "lowword" \n\t"\
95 "mov "byte" , %%"REG_c" \n\t"\
97 "add"OPSIZE" $2 , "byte" \n\t"\
99 "movzwl (%%"REG_c") , "tmp" \n\t"\
100 "lea -1("low") , %%ecx \n\t"\
101 "xor "low" , %%ecx \n\t"\
102 "shr $15 , %%ecx \n\t"\
104 "shr $15 , "tmp" \n\t"\
105 "movzbl "norm_off"("tables", %%rcx), %%ecx \n\t"\
106 "sub $0xFFFF , "tmp" \n\t"\
108 "add $7 , %%ecx \n\t"\
109 "shl %%cl , "tmp" \n\t"\
110 "add "tmp" , "low" \n\t"\
114 #define TABLES_ARG NAMED_CONSTRAINTS_ARRAY_ADD(ff_h264_cabac_tables)
118 #define BRANCHLESS_GET_CABAC_UPDATE(ret, low, range, tmp)\
119 "mov "tmp" , %%ecx \n\t"\
120 "shl $17 , "tmp" \n\t"\
121 "cmp "low" , "tmp" \n\t"\
122 "cmova %%ecx , "range" \n\t"\
123 "sbb %%ecx , %%ecx \n\t"\
124 "and %%ecx , "tmp" \n\t"\
125 "xor %%ecx , "ret" \n\t"\
126 "sub "tmp" , "low" \n\t"
128 #define BRANCHLESS_GET_CABAC_UPDATE(ret, low, range, tmp)\
129 "mov "tmp" , %%ecx \n\t"\
130 "shl $17 , "tmp" \n\t"\
131 "sub "low" , "tmp" \n\t"\
132 "sar $31 , "tmp" \n\t" \
133 "sub %%ecx , "range" \n\t" \
134 "and "tmp" , "range" \n\t" \
135 "add %%ecx , "range" \n\t" \
136 "shl $17 , %%ecx \n\t"\
137 "and "tmp" , %%ecx \n\t"\
138 "sub %%ecx , "low" \n\t"\
139 "xor "tmp" , "ret" \n\t"
142 #define BRANCHLESS_GET_CABAC(ret, retq, statep, low, lowword, range, rangeq, tmp, tmpbyte, byte, end, norm_off, lps_off, mlps_off, tables) \
143 "movzbl "statep" , "ret" \n\t"\
144 "mov "range" , "tmp" \n\t"\
145 "and $0xC0 , "range" \n\t"\
146 "movzbl "MANGLE(ff_h264_cabac_tables)"+"lps_off"("ret", "range", 2), "range" \n\t"\
147 "sub "range" , "tmp" \n\t"\
148 BRANCHLESS_GET_CABAC_UPDATE(ret, low, range, tmp) \
149 "movzbl "MANGLE(ff_h264_cabac_tables)"+"norm_off"("range"), %%ecx \n\t"\
150 "shl %%cl , "range" \n\t"\
151 "movzbl "MANGLE(ff_h264_cabac_tables)"+"mlps_off"+128("ret"), "tmp" \n\t"\
152 "shl %%cl , "low" \n\t"\
153 "mov "tmpbyte" , "statep" \n\t"\
154 "test "lowword" , "lowword" \n\t"\
156 "mov "byte" , %%"REG_c" \n\t"\
158 "add"OPSIZE" $2 , "byte" \n\t"\
160 "movzwl (%%"REG_c") , "tmp" \n\t"\
161 "lea -1("low") , %%ecx \n\t"\
162 "xor "low" , %%ecx \n\t"\
163 "shr $15 , %%ecx \n\t"\
165 "shr $15 , "tmp" \n\t"\
166 "movzbl "MANGLE(ff_h264_cabac_tables)"+"norm_off"(%%ecx), %%ecx \n\t"\
167 "sub $0xFFFF , "tmp" \n\t"\
169 "add $7 , %%ecx \n\t"\
170 "shl %%cl , "tmp" \n\t"\
171 "add "tmp" , "low" \n\t"\
176 #if HAVE_7REGS && !BROKEN_COMPILER
177 #define get_cabac_inline get_cabac_inline_x86
182 #ifdef BROKEN_RELOCATIONS
193 BRANCHLESS_GET_CABAC(
"%0",
"%q0",
"(%4)",
"%1",
"%w1",
194 "%2",
"%q2",
"%3",
"%b3",
195 "%c6(%5)",
"%c7(%5)",
200 :
"=&r"(bit),
"=&r"(c->
low),
"=&r"(c->
range),
"=&q"(tmp)
201 :
"r"(
state),
"r"(c),
213 #define get_cabac_bypass_sign get_cabac_bypass_sign_x86
218 "movl %c6(%2), %k1 \n\t"
219 "movl %c3(%2), %%eax \n\t"
221 "add %%eax, %%eax \n\t"
222 "sub %k1, %%eax \n\t"
224 "and %%edx, %k1 \n\t"
225 "add %k1, %%eax \n\t"
226 "xor %%edx, %%ecx \n\t"
227 "sub %%edx, %%ecx \n\t"
228 "test %%ax, %%ax \n\t"
230 "mov %c4(%2), %1 \n\t"
231 "subl $0xFFFF, %%eax \n\t"
232 "movzwl (%1), %%edx \n\t"
234 "shrl $15, %%edx \n\t"
235 #if UNCHECKED_BITSTREAM_READER
237 "addl %%edx, %%eax \n\t"
238 "mov %1, %c4(%2) \n\t"
240 "addl %%edx, %%eax \n\t"
241 "cmp %c5(%2), %1 \n\t"
243 "add"OPSIZE
" $2, %c4(%2) \n\t"
246 "movl %%eax, %c3(%2) \n\t"
248 :
"+c"(
val),
"=&r"(tmp)
254 :
"%eax",
"%edx",
"memory"
259 #define get_cabac_bypass get_cabac_bypass_x86
265 "movl %c6(%2), %k1 \n\t"
266 "movl %c3(%2), %%eax \n\t"
268 "add %%eax, %%eax \n\t"
269 "sub %k1, %%eax \n\t"
271 "and %%edx, %k1 \n\t"
272 "add %k1, %%eax \n\t"
274 "test %%ax, %%ax \n\t"
276 "mov %c4(%2), %1 \n\t"
277 "subl $0xFFFF, %%eax \n\t"
278 "movzwl (%1), %%ecx \n\t"
280 "shrl $15, %%ecx \n\t"
281 "addl %%ecx, %%eax \n\t"
282 "cmp %c5(%2), %1 \n\t"
284 "add"OPSIZE
" $2, %c4(%2) \n\t"
286 "movl %%eax, %c3(%2) \n\t"
288 :
"=&d"(res),
"=&r"(tmp)
294 :
"%eax",
"%ecx",
"memory"
const char const char void * val
#define NAMED_CONSTRAINTS_ARRAY(...)
Macro definitions for various function/variable attributes.
Utility Preprocessor macros.
static const uint8_t *const tables[]
#define H264_MLPS_STATE_OFFSET
#define H264_NORM_SHIFT_OFFSET
const uint8_t ff_h264_cabac_tables[512+4 *2 *64+4 *64+63]
Context Adaptive Binary Arithmetic Coder.
#define H264_LPS_RANGE_OFFSET