21#ifndef AVCODEC_X86_CABAC_H
22#define AVCODEC_X86_CABAC_H
32#if 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" , %%"FF_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"
80#define BRANCHLESS_GET_CABAC_RENORM(range, rangeq, norm_off, tables) \
81 "lzcnt "range" , %%ecx \n\t"\
82 "sub $23 , %%ecx \n\t"
83#define BRANCHLESS_GET_CABAC_REFILL(low, tmp, norm_off, tables) \
84 "movzwl (%%"FF_REG_c") , "tmp" \n\t"\
85 "tzcnt "low" , %%ecx \n\t"\
87 "shr $15 , "tmp" \n\t"\
88 "sub $16 , %%ecx \n\t"\
89 "sub $0xFFFF , "tmp" \n\t"\
90 "shl %%cl , "tmp" \n\t"\
91 "add "tmp" , "low" \n\t"
93#define BRANCHLESS_GET_CABAC_RENORM(range, rangeq, norm_off, tables) \
94 "movzbl "norm_off"("tables", "rangeq"), %%ecx \n\t"
95#define BRANCHLESS_GET_CABAC_REFILL(low, tmp, norm_off, tables) \
96 "movzwl (%%"FF_REG_c") , "tmp" \n\t"\
97 "lea -1("low") , %%ecx \n\t"\
98 "xor "low" , %%ecx \n\t"\
99 "shr $15 , %%ecx \n\t"\
101 "shr $15 , "tmp" \n\t"\
102 "movzbl "norm_off"("tables", %%rcx), %%ecx \n\t"\
103 "sub $0xFFFF , "tmp" \n\t"\
105 "add $7 , %%ecx \n\t"\
106 "shl %%cl , "tmp" \n\t"\
107 "add "tmp" , "low" \n\t"
110#define BRANCHLESS_GET_CABAC(ret, retq, statep, low, lowword, range, rangeq, tmp, tmpbyte, byte, end, norm_off, lps_off, mlps_off, tables) \
111 "movzbl "statep" , "ret" \n\t"\
112 "mov "range" , "tmp" \n\t"\
113 "and $0xC0 , "range" \n\t"\
114 "lea ("ret", "range", 2), %%ecx \n\t"\
115 "movzbl "lps_off"("tables", %%rcx), "range" \n\t"\
116 "sub "range" , "tmp" \n\t"\
117 "mov "tmp" , %%ecx \n\t"\
118 "shl $17 , "tmp" \n\t"\
119 BRANCHLESS_GET_CABAC_UPDATE(ret, retq, low, range, tmp) \
120 BRANCHLESS_GET_CABAC_RENORM(range, rangeq, norm_off, tables) \
121 "shl %%cl , "range" \n\t"\
122 "movzbl "mlps_off"+128("tables", "retq"), "tmp" \n\t"\
123 "shl %%cl , "low" \n\t"\
124 "mov "tmpbyte" , "statep" \n\t"\
125 "test "lowword" , "lowword" \n\t"\
127 "mov "byte" , %%"FF_REG_c" \n\t"\
129 "add"FF_OPSIZE" $2 , "byte" \n\t"\
131 BRANCHLESS_GET_CABAC_REFILL(low, tmp, norm_off, tables) \
135#define TABLES_ARG NAMED_CONSTRAINTS_ARRAY_ADD(ff_h264_cabac_tables)
139#define BRANCHLESS_GET_CABAC_UPDATE(ret, low, range, tmp)\
140 "mov "tmp" , %%ecx \n\t"\
141 "shl $17 , "tmp" \n\t"\
142 "cmp "low" , "tmp" \n\t"\
143 "cmova %%ecx , "range" \n\t"\
144 "sbb %%ecx , %%ecx \n\t"\
145 "and %%ecx , "tmp" \n\t"\
146 "xor %%ecx , "ret" \n\t"\
147 "sub "tmp" , "low" \n\t"
149#define BRANCHLESS_GET_CABAC_UPDATE(ret, low, range, tmp)\
150 "mov "tmp" , %%ecx \n\t"\
151 "shl $17 , "tmp" \n\t"\
152 "sub "low" , "tmp" \n\t"\
153 "sar $31 , "tmp" \n\t" \
154 "sub %%ecx , "range" \n\t" \
155 "and "tmp" , "range" \n\t" \
156 "add %%ecx , "range" \n\t" \
157 "shl $17 , %%ecx \n\t"\
158 "and "tmp" , %%ecx \n\t"\
159 "sub %%ecx , "low" \n\t"\
160 "xor "tmp" , "ret" \n\t"
164#define BRANCHLESS_GET_CABAC_RENORM(range, rangeq, norm_off, tables) \
165 "lzcnt "range" , %%ecx \n\t"\
166 "sub $23 , %%ecx \n\t"
167#define BRANCHLESS_GET_CABAC_REFILL(low, tmp, norm_off, tables) \
168 "movzwl (%%"FF_REG_c") , "tmp" \n\t"\
169 "tzcnt "low" , %%ecx \n\t"\
171 "shr $15 , "tmp" \n\t"\
172 "sub $16 , %%ecx \n\t"\
173 "sub $0xFFFF , "tmp" \n\t"\
174 "shl %%cl , "tmp" \n\t"\
175 "add "tmp" , "low" \n\t"
177#define BRANCHLESS_GET_CABAC_RENORM(range, rangeq, norm_off, tables) \
178 "movzbl "MANGLE(ff_h264_cabac_tables)"+"norm_off"("range"), %%ecx \n\t"
179#define BRANCHLESS_GET_CABAC_REFILL(low, tmp, norm_off, tables) \
180 "movzwl (%%"FF_REG_c") , "tmp" \n\t"\
181 "lea -1("low") , %%ecx \n\t"\
182 "xor "low" , %%ecx \n\t"\
183 "shr $15 , %%ecx \n\t"\
185 "shr $15 , "tmp" \n\t"\
186 "movzbl "MANGLE(ff_h264_cabac_tables)"+"norm_off"(%%ecx), %%ecx \n\t"\
187 "sub $0xFFFF , "tmp" \n\t"\
189 "add $7 , %%ecx \n\t"\
190 "shl %%cl , "tmp" \n\t"\
191 "add "tmp" , "low" \n\t"
194#define BRANCHLESS_GET_CABAC(ret, retq, statep, low, lowword, range, rangeq, tmp, tmpbyte, byte, end, norm_off, lps_off, mlps_off, tables) \
195 "movzbl "statep" , "ret" \n\t"\
196 "mov "range" , "tmp" \n\t"\
197 "and $0xC0 , "range" \n\t"\
198 "movzbl "MANGLE(ff_h264_cabac_tables)"+"lps_off"("ret", "range", 2), "range" \n\t"\
199 "sub "range" , "tmp" \n\t"\
200 BRANCHLESS_GET_CABAC_UPDATE(ret, low, range, tmp) \
201 BRANCHLESS_GET_CABAC_RENORM(range, rangeq, norm_off, tables) \
202 "shl %%cl , "range" \n\t"\
203 "movzbl "MANGLE(ff_h264_cabac_tables)"+"mlps_off"+128("ret"), "tmp" \n\t"\
204 "shl %%cl , "low" \n\t"\
205 "mov "tmpbyte" , "statep" \n\t"\
206 "test "lowword" , "lowword" \n\t"\
208 "mov "byte" , %%"FF_REG_c" \n\t"\
210 "add"FF_OPSIZE" $2 , "byte" \n\t"\
212 BRANCHLESS_GET_CABAC_REFILL(low, tmp, norm_off, tables) \
217#if HAVE_X86_7REGS && !BROKEN_COMPILER
218#define get_cabac_inline get_cabac_inline_x86
228#ifdef BROKEN_RELOCATIONS
239 BRANCHLESS_GET_CABAC(
"%0",
"%q0",
"(%4)",
"%1",
"%w1",
240 "%2",
"%q2",
"%3",
"%b3",
241 "%c6(%5)",
"%c7(%5)",
246 :
"=&r"(
bit),
"=&r"(
c->low),
"=&r"(
c->range),
"=&q"(
tmp)
251 ,
"1"(
c->low),
"2"(
c->range)
252 :
"%"FF_REG_c,
"memory"
259#define get_cabac_bypass_sign get_cabac_bypass_sign_x86
264 "movl %c6(%2), %k1 \n\t"
265 "movl %c3(%2), %%eax \n\t"
267 "add %%eax, %%eax \n\t"
268 "sub %k1, %%eax \n\t"
270 "and %%edx, %k1 \n\t"
271 "add %k1, %%eax \n\t"
272 "xor %%edx, %%ecx \n\t"
273 "sub %%edx, %%ecx \n\t"
274 "test %%ax, %%ax \n\t"
276 "mov %c4(%2), %1 \n\t"
277 "subl $0xFFFF, %%eax \n\t"
278 "movzwl (%1), %%edx \n\t"
280 "shrl $15, %%edx \n\t"
281#if UNCHECKED_BITSTREAM_READER
283 "addl %%edx, %%eax \n\t"
284 "mov %1, %c4(%2) \n\t"
286 "addl %%edx, %%eax \n\t"
287 "cmp %c5(%2), %1 \n\t"
289 "add"FF_OPSIZE
" $2, %c4(%2) \n\t"
292 "movl %%eax, %c3(%2) \n\t"
300 :
"%eax",
"%edx",
"memory"
305#define get_cabac_bypass get_cabac_bypass_x86
311 "movl %c6(%2), %k1 \n\t"
312 "movl %c3(%2), %%eax \n\t"
314 "add %%eax, %%eax \n\t"
315 "sub %k1, %%eax \n\t"
317 "and %%edx, %k1 \n\t"
318 "add %k1, %%eax \n\t"
320 "test %%ax, %%ax \n\t"
322 "mov %c4(%2), %1 \n\t"
323 "subl $0xFFFF, %%eax \n\t"
324 "movzwl (%1), %%ecx \n\t"
326 "shrl $15, %%ecx \n\t"
327 "addl %%ecx, %%eax \n\t"
328 "cmp %c5(%2), %1 \n\t"
330 "add"FF_OPSIZE
" $2, %c4(%2) \n\t"
332 "movl %%eax, %c3(%2) \n\t"
334 :
"=&d"(res),
"=&r"(
tmp)
340 :
"%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[]