21#ifndef AVCODEC_X86_CABAC_H
22#define AVCODEC_X86_CABAC_H
32#if (defined(__i386) && defined(__clang__) && (__clang_major__<2 || (__clang_major__==2 && __clang_minor__<10)))\
33 || ( !defined(__clang__) && defined(__llvm__) && __GNUC__==4 && __GNUC_MINOR__==2 && __GNUC_PATCHLEVEL__<=1)\
34 || (defined(__INTEL_COMPILER) && defined(_MSC_VER))
35# define BROKEN_COMPILER 1
37# define BROKEN_COMPILER 0
42#ifndef UNCHECKED_BITSTREAM_READER
43#define UNCHECKED_BITSTREAM_READER !CONFIG_SAFE_BITSTREAM_READER
46#if UNCHECKED_BITSTREAM_READER
47#define END_CHECK(end) ""
49#define END_CHECK(end) \
50 "cmp "end" , %%"FF_REG_c" \n\t"\
54#ifdef BROKEN_RELOCATIONS
55#define TABLES_ARG , "r"(tables)
58#define BRANCHLESS_GET_CABAC_UPDATE(ret, retq, low, range, tmp) \
59 "cmp "low" , "tmp" \n\t"\
60 "cmova %%ecx , "range" \n\t"\
61 "sbb %%rcx , %%rcx \n\t"\
62 "and %%ecx , "tmp" \n\t"\
63 "xor %%rcx , "retq" \n\t"\
64 "sub "tmp" , "low" \n\t"
66#define BRANCHLESS_GET_CABAC_UPDATE(ret, retq, low, range, tmp) \
68 "sub "low" , "tmp" \n\t"\
69 "sar $31 , "tmp" \n\t"\
70 "sub %%ecx , "range" \n\t"\
71 "and "tmp" , "range" \n\t"\
72 "add %%ecx , "range" \n\t"\
73 "shl $17 , %%ecx \n\t"\
74 "and "tmp" , %%ecx \n\t"\
75 "sub %%ecx , "low" \n\t"\
76 "xor "tmp" , "ret" \n\t"\
77 "movslq "ret" , "retq" \n\t"
82#define BRANCHLESS_GET_CABAC_RENORM(range, rangeq, norm_off, tables) \
83 "lzcnt "range" , %%ecx \n\t"\
84 "sub $23 , %%ecx \n\t"
85#define BRANCHLESS_GET_CABAC_REFILL(low, tmp, norm_off, tables) \
86 "movzwl (%%"FF_REG_c") , "tmp" \n\t"\
87 "tzcnt "low" , %%ecx \n\t"\
89 "shr $15 , "tmp" \n\t"\
90 "sub $16 , %%ecx \n\t"\
91 "sub $0xFFFF , "tmp" \n\t"\
92 "shl %%cl , "tmp" \n\t"\
93 "add "tmp" , "low" \n\t"
95#define BRANCHLESS_GET_CABAC_RENORM(range, rangeq, norm_off, tables) \
96 "movzbl "norm_off"("tables", "rangeq"), %%ecx \n\t"
97#define BRANCHLESS_GET_CABAC_REFILL(low, tmp, norm_off, tables) \
98 "movzwl (%%"FF_REG_c") , "tmp" \n\t"\
99 "lea -1("low") , %%ecx \n\t"\
100 "xor "low" , %%ecx \n\t"\
101 "shr $15 , %%ecx \n\t"\
103 "shr $15 , "tmp" \n\t"\
104 "movzbl "norm_off"("tables", %%rcx), %%ecx \n\t"\
105 "sub $0xFFFF , "tmp" \n\t"\
107 "add $7 , %%ecx \n\t"\
108 "shl %%cl , "tmp" \n\t"\
109 "add "tmp" , "low" \n\t"
112#define BRANCHLESS_GET_CABAC(ret, retq, statep, low, lowword, range, rangeq, tmp, tmpbyte, byte, end, norm_off, lps_off, mlps_off, tables) \
113 "movzbl "statep" , "ret" \n\t"\
114 "mov "range" , "tmp" \n\t"\
115 "and $0xC0 , "range" \n\t"\
116 "lea ("ret", "range", 2), %%ecx \n\t"\
117 "movzbl "lps_off"("tables", %%rcx), "range" \n\t"\
118 "sub "range" , "tmp" \n\t"\
119 "mov "tmp" , %%ecx \n\t"\
120 "shl $17 , "tmp" \n\t"\
121 BRANCHLESS_GET_CABAC_UPDATE(ret, retq, low, range, tmp) \
122 BRANCHLESS_GET_CABAC_RENORM(range, rangeq, norm_off, tables) \
123 "shl %%cl , "range" \n\t"\
124 "movzbl "mlps_off"+128("tables", "retq"), "tmp" \n\t"\
125 "shl %%cl , "low" \n\t"\
126 "mov "tmpbyte" , "statep" \n\t"\
127 "test "lowword" , "lowword" \n\t"\
129 "mov "byte" , %%"FF_REG_c" \n\t"\
131 "add"FF_OPSIZE" $2 , "byte" \n\t"\
133 BRANCHLESS_GET_CABAC_REFILL(low, tmp, norm_off, tables) \
137#define TABLES_ARG NAMED_CONSTRAINTS_ARRAY_ADD(ff_h264_cabac_tables)
141#define BRANCHLESS_GET_CABAC_UPDATE(ret, low, range, tmp)\
142 "mov "tmp" , %%ecx \n\t"\
143 "shl $17 , "tmp" \n\t"\
144 "cmp "low" , "tmp" \n\t"\
145 "cmova %%ecx , "range" \n\t"\
146 "sbb %%ecx , %%ecx \n\t"\
147 "and %%ecx , "tmp" \n\t"\
148 "xor %%ecx , "ret" \n\t"\
149 "sub "tmp" , "low" \n\t"
151#define BRANCHLESS_GET_CABAC_UPDATE(ret, low, range, tmp)\
152 "mov "tmp" , %%ecx \n\t"\
153 "shl $17 , "tmp" \n\t"\
154 "sub "low" , "tmp" \n\t"\
155 "sar $31 , "tmp" \n\t" \
156 "sub %%ecx , "range" \n\t" \
157 "and "tmp" , "range" \n\t" \
158 "add %%ecx , "range" \n\t" \
159 "shl $17 , %%ecx \n\t"\
160 "and "tmp" , %%ecx \n\t"\
161 "sub %%ecx , "low" \n\t"\
162 "xor "tmp" , "ret" \n\t"
166#define BRANCHLESS_GET_CABAC_RENORM(range, rangeq, norm_off, tables) \
167 "lzcnt "range" , %%ecx \n\t"\
168 "sub $23 , %%ecx \n\t"
169#define BRANCHLESS_GET_CABAC_REFILL(low, tmp, norm_off, tables) \
170 "movzwl (%%"FF_REG_c") , "tmp" \n\t"\
171 "tzcnt "low" , %%ecx \n\t"\
173 "shr $15 , "tmp" \n\t"\
174 "sub $16 , %%ecx \n\t"\
175 "sub $0xFFFF , "tmp" \n\t"\
176 "shl %%cl , "tmp" \n\t"\
177 "add "tmp" , "low" \n\t"
179#define BRANCHLESS_GET_CABAC_RENORM(range, rangeq, norm_off, tables) \
180 "movzbl "MANGLE(ff_h264_cabac_tables)"+"norm_off"("range"), %%ecx \n\t"
181#define BRANCHLESS_GET_CABAC_REFILL(low, tmp, norm_off, tables) \
182 "movzwl (%%"FF_REG_c") , "tmp" \n\t"\
183 "lea -1("low") , %%ecx \n\t"\
184 "xor "low" , %%ecx \n\t"\
185 "shr $15 , %%ecx \n\t"\
187 "shr $15 , "tmp" \n\t"\
188 "movzbl "MANGLE(ff_h264_cabac_tables)"+"norm_off"(%%ecx), %%ecx \n\t"\
189 "sub $0xFFFF , "tmp" \n\t"\
191 "add $7 , %%ecx \n\t"\
192 "shl %%cl , "tmp" \n\t"\
193 "add "tmp" , "low" \n\t"
196#define BRANCHLESS_GET_CABAC(ret, retq, statep, low, lowword, range, rangeq, tmp, tmpbyte, byte, end, norm_off, lps_off, mlps_off, tables) \
197 "movzbl "statep" , "ret" \n\t"\
198 "mov "range" , "tmp" \n\t"\
199 "and $0xC0 , "range" \n\t"\
200 "movzbl "MANGLE(ff_h264_cabac_tables)"+"lps_off"("ret", "range", 2), "range" \n\t"\
201 "sub "range" , "tmp" \n\t"\
202 BRANCHLESS_GET_CABAC_UPDATE(ret, low, range, tmp) \
203 BRANCHLESS_GET_CABAC_RENORM(range, rangeq, norm_off, tables) \
204 "shl %%cl , "range" \n\t"\
205 "movzbl "MANGLE(ff_h264_cabac_tables)"+"mlps_off"+128("ret"), "tmp" \n\t"\
206 "shl %%cl , "low" \n\t"\
207 "mov "tmpbyte" , "statep" \n\t"\
208 "test "lowword" , "lowword" \n\t"\
210 "mov "byte" , %%"FF_REG_c" \n\t"\
212 "add"FF_OPSIZE" $2 , "byte" \n\t"\
214 BRANCHLESS_GET_CABAC_REFILL(low, tmp, norm_off, tables) \
219#if HAVE_X86_7REGS && !BROKEN_COMPILER
220#define get_cabac_inline get_cabac_inline_x86
230#ifdef BROKEN_RELOCATIONS
241 BRANCHLESS_GET_CABAC(
"%0",
"%q0",
"(%4)",
"%1",
"%w1",
242 "%2",
"%q2",
"%3",
"%b3",
243 "%c6(%5)",
"%c7(%5)",
248 :
"=&r"(
bit),
"=&r"(
c->low),
"=&r"(
c->range),
"=&q"(
tmp)
253 ,
"1"(
c->low),
"2"(
c->range)
254 :
"%"FF_REG_c,
"memory"
261#define get_cabac_bypass_sign get_cabac_bypass_sign_x86
266 "movl %c6(%2), %k1 \n\t"
267 "movl %c3(%2), %%eax \n\t"
269 "add %%eax, %%eax \n\t"
270 "sub %k1, %%eax \n\t"
272 "and %%edx, %k1 \n\t"
273 "add %k1, %%eax \n\t"
274 "xor %%edx, %%ecx \n\t"
275 "sub %%edx, %%ecx \n\t"
276 "test %%ax, %%ax \n\t"
278 "mov %c4(%2), %1 \n\t"
279 "subl $0xFFFF, %%eax \n\t"
280 "movzwl (%1), %%edx \n\t"
282 "shrl $15, %%edx \n\t"
283#if UNCHECKED_BITSTREAM_READER
285 "addl %%edx, %%eax \n\t"
286 "mov %1, %c4(%2) \n\t"
288 "addl %%edx, %%eax \n\t"
289 "cmp %c5(%2), %1 \n\t"
291 "add"FF_OPSIZE
" $2, %c4(%2) \n\t"
294 "movl %%eax, %c3(%2) \n\t"
302 :
"%eax",
"%edx",
"memory"
307#define get_cabac_bypass get_cabac_bypass_x86
313 "movl %c6(%2), %k1 \n\t"
314 "movl %c3(%2), %%eax \n\t"
316 "add %%eax, %%eax \n\t"
317 "sub %k1, %%eax \n\t"
319 "and %%edx, %k1 \n\t"
320 "add %k1, %%eax \n\t"
322 "test %%ax, %%ax \n\t"
324 "mov %c4(%2), %1 \n\t"
325 "subl $0xFFFF, %%eax \n\t"
326 "movzwl (%1), %%ecx \n\t"
328 "shrl $15, %%ecx \n\t"
329 "addl %%ecx, %%eax \n\t"
330 "cmp %c5(%2), %1 \n\t"
332 "add"FF_OPSIZE
" $2, %c4(%2) \n\t"
334 "movl %%eax, %c3(%2) \n\t"
336 :
"=&d"(res),
"=&r"(
tmp)
342 :
"%eax",
"%ecx",
"memory"
static double val(void *priv, double ch)
#define NAMED_CONSTRAINTS_ARRAY(...)
__asm__(".macro parse_r var r\n\t" "\\var = -1\n\t" _IFC_REG(0) _IFC_REG(1) _IFC_REG(2) _IFC_REG(3) _IFC_REG(4) _IFC_REG(5) _IFC_REG(6) _IFC_REG(7) _IFC_REG(8) _IFC_REG(9) _IFC_REG(10) _IFC_REG(11) _IFC_REG(12) _IFC_REG(13) _IFC_REG(14) _IFC_REG(15) _IFC_REG(16) _IFC_REG(17) _IFC_REG(18) _IFC_REG(19) _IFC_REG(20) _IFC_REG(21) _IFC_REG(22) _IFC_REG(23) _IFC_REG(24) _IFC_REG(25) _IFC_REG(26) _IFC_REG(27) _IFC_REG(28) _IFC_REG(29) _IFC_REG(30) _IFC_REG(31) ".iflt \\var\n\t" ".error \"Unable to parse register name \\r\"\n\t" ".endif\n\t" ".endm")
Context Adaptive Binary Arithmetic Coder.
#define H264_LPS_RANGE_OFFSET
#define H264_MLPS_STATE_OFFSET
#define H264_NORM_SHIFT_OFFSET
const uint8_t ff_h264_cabac_tables[512+4 *2 *64+4 *64+63]
#define bit(string, value)
static struct @346255127015250356166251341105367306144006377143 state
Macro definitions for various function/variable attributes.
Utility Preprocessor macros.
static const uint8_t *const tables[]