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"
80 #define BRANCHLESS_GET_CABAC(ret, retq, statep, low, lowword, range, rangeq, tmp, tmpbyte, byte, end, norm_off, lps_off, mlps_off, tables) \
81 "movzbl "statep" , "ret" \n\t"\
82 "mov "range" , "tmp" \n\t"\
83 "and $0xC0 , "range" \n\t"\
84 "lea ("ret", "range", 2), %%ecx \n\t"\
85 "movzbl "lps_off"("tables", %%rcx), "range" \n\t"\
86 "sub "range" , "tmp" \n\t"\
87 "mov "tmp" , %%ecx \n\t"\
88 "shl $17 , "tmp" \n\t"\
89 BRANCHLESS_GET_CABAC_UPDATE(ret, retq, low, range, tmp) \
90 "movzbl "norm_off"("tables", "rangeq"), %%ecx \n\t"\
91 "shl %%cl , "range" \n\t"\
92 "movzbl "mlps_off"+128("tables", "retq"), "tmp" \n\t"\
93 "shl %%cl , "low" \n\t"\
94 "mov "tmpbyte" , "statep" \n\t"\
95 "test "lowword" , "lowword" \n\t"\
97 "mov "byte" , %%"FF_REG_c" \n\t"\
99 "add"FF_OPSIZE" $2 , "byte" \n\t"\
101 "movzwl (%%"FF_REG_c") , "tmp" \n\t"\
102 "lea -1("low") , %%ecx \n\t"\
103 "xor "low" , %%ecx \n\t"\
104 "shr $15 , %%ecx \n\t"\
106 "shr $15 , "tmp" \n\t"\
107 "movzbl "norm_off"("tables", %%rcx), %%ecx \n\t"\
108 "sub $0xFFFF , "tmp" \n\t"\
110 "add $7 , %%ecx \n\t"\
111 "shl %%cl , "tmp" \n\t"\
112 "add "tmp" , "low" \n\t"\
116 #define TABLES_ARG NAMED_CONSTRAINTS_ARRAY_ADD(ff_h264_cabac_tables)
120 #define BRANCHLESS_GET_CABAC_UPDATE(ret, low, range, tmp)\
121 "mov "tmp" , %%ecx \n\t"\
122 "shl $17 , "tmp" \n\t"\
123 "cmp "low" , "tmp" \n\t"\
124 "cmova %%ecx , "range" \n\t"\
125 "sbb %%ecx , %%ecx \n\t"\
126 "and %%ecx , "tmp" \n\t"\
127 "xor %%ecx , "ret" \n\t"\
128 "sub "tmp" , "low" \n\t"
130 #define BRANCHLESS_GET_CABAC_UPDATE(ret, low, range, tmp)\
131 "mov "tmp" , %%ecx \n\t"\
132 "shl $17 , "tmp" \n\t"\
133 "sub "low" , "tmp" \n\t"\
134 "sar $31 , "tmp" \n\t"
\
135 "sub %%ecx , "range" \n\t"
\
136 "and "tmp" , "range" \n\t"
\
137 "add %%ecx , "range" \n\t"
\
138 "shl $17 , %%ecx \n\t"\
139 "and "tmp" , %%ecx \n\t"\
140 "sub %%ecx , "low" \n\t"\
141 "xor "tmp" , "ret" \n\t"
144 #define BRANCHLESS_GET_CABAC(ret, retq, statep, low, lowword, range, rangeq, tmp, tmpbyte, byte, end, norm_off, lps_off, mlps_off, tables) \
145 "movzbl "statep" , "ret" \n\t"\
146 "mov "range" , "tmp" \n\t"\
147 "and $0xC0 , "range" \n\t"\
148 "movzbl "MANGLE(ff_h264_cabac_tables)"+"lps_off"("ret", "range", 2), "range" \n\t"\
149 "sub "range" , "tmp" \n\t"\
150 BRANCHLESS_GET_CABAC_UPDATE(ret, low, range, tmp) \
151 "movzbl "MANGLE(ff_h264_cabac_tables)"+"norm_off"("range"), %%ecx \n\t"\
152 "shl %%cl , "range" \n\t"\
153 "movzbl "MANGLE(ff_h264_cabac_tables)"+"mlps_off"+128("ret"), "tmp" \n\t"\
154 "shl %%cl , "low" \n\t"\
155 "mov "tmpbyte" , "statep" \n\t"\
156 "test "lowword" , "lowword" \n\t"\
158 "mov "byte" , %%"FF_REG_c" \n\t"\
160 "add"FF_OPSIZE" $2 , "byte" \n\t"\
162 "movzwl (%%"FF_REG_c") , "tmp" \n\t"\
163 "lea -1("low") , %%ecx \n\t"\
164 "xor "low" , %%ecx \n\t"\
165 "shr $15 , %%ecx \n\t"\
167 "shr $15 , "tmp" \n\t"\
168 "movzbl "MANGLE(ff_h264_cabac_tables)"+"norm_off"(%%ecx), %%ecx \n\t"\
169 "sub $0xFFFF , "tmp" \n\t"\
171 "add $7 , %%ecx \n\t"\
172 "shl %%cl , "tmp" \n\t"\
173 "add "tmp" , "low" \n\t"\
178 #if HAVE_7REGS && !BROKEN_COMPILER
179 #define get_cabac_inline get_cabac_inline_x86
184 #ifdef BROKEN_RELOCATIONS
195 BRANCHLESS_GET_CABAC(
"%0",
"%q0",
"(%4)",
"%1",
"%w1",
196 "%2",
"%q2",
"%3",
"%b3",
197 "%c6(%5)",
"%c7(%5)",
202 :
"=&r"(
bit),
"=&r"(
c->low),
"=&r"(
c->range),
"=&q"(
tmp)
207 ,
"1"(
c->low),
"2"(
c->range)
208 :
"%"FF_REG_c,
"memory"
215 #define get_cabac_bypass_sign get_cabac_bypass_sign_x86
220 "movl %c6(%2), %k1 \n\t"
221 "movl %c3(%2), %%eax \n\t"
223 "add %%eax, %%eax \n\t"
224 "sub %k1, %%eax \n\t"
226 "and %%edx, %k1 \n\t"
227 "add %k1, %%eax \n\t"
228 "xor %%edx, %%ecx \n\t"
229 "sub %%edx, %%ecx \n\t"
230 "test %%ax, %%ax \n\t"
232 "mov %c4(%2), %1 \n\t"
233 "subl $0xFFFF, %%eax \n\t"
234 "movzwl (%1), %%edx \n\t"
236 "shrl $15, %%edx \n\t"
237 #if UNCHECKED_BITSTREAM_READER
239 "addl %%edx, %%eax \n\t"
240 "mov %1, %c4(%2) \n\t"
242 "addl %%edx, %%eax \n\t"
243 "cmp %c5(%2), %1 \n\t"
245 "add"FF_OPSIZE
" $2, %c4(%2) \n\t"
248 "movl %%eax, %c3(%2) \n\t"
256 :
"%eax",
"%edx",
"memory"
261 #define get_cabac_bypass get_cabac_bypass_x86
267 "movl %c6(%2), %k1 \n\t"
268 "movl %c3(%2), %%eax \n\t"
270 "add %%eax, %%eax \n\t"
271 "sub %k1, %%eax \n\t"
273 "and %%edx, %k1 \n\t"
274 "add %k1, %%eax \n\t"
276 "test %%ax, %%ax \n\t"
278 "mov %c4(%2), %1 \n\t"
279 "subl $0xFFFF, %%eax \n\t"
280 "movzwl (%1), %%ecx \n\t"
282 "shrl $15, %%ecx \n\t"
283 "addl %%ecx, %%eax \n\t"
284 "cmp %c5(%2), %1 \n\t"
286 "add"FF_OPSIZE
" $2, %c4(%2) \n\t"
288 "movl %%eax, %c3(%2) \n\t"
290 :
"=&d"(res),
"=&r"(
tmp)
296 :
"%eax",
"%ecx",
"memory"
static double val(void *priv, double ch)
__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")
Macro definitions for various function/variable attributes.
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)
#define NAMED_CONSTRAINTS_ARRAY(...)
Utility Preprocessor macros.
static const uint8_t *const tables[]