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 # define BROKEN_COMPILER 1
34 # define BROKEN_COMPILER 0
39 #ifndef UNCHECKED_BITSTREAM_READER
40 #define UNCHECKED_BITSTREAM_READER !CONFIG_SAFE_BITSTREAM_READER
43 #if UNCHECKED_BITSTREAM_READER
44 #define END_CHECK(end) ""
46 #define END_CHECK(end) \
47 "cmp "end" , %%"REG_c" \n\t"\
51 #ifdef BROKEN_RELOCATIONS
52 #define TABLES_ARG , "r"(tables)
55 #define BRANCHLESS_GET_CABAC_UPDATE(ret, retq, low, range, tmp) \
56 "cmp "low" , "tmp" \n\t"\
57 "cmova %%ecx , "range" \n\t"\
58 "sbb %%rcx , %%rcx \n\t"\
59 "and %%ecx , "tmp" \n\t"\
60 "xor %%rcx , "retq" \n\t"\
61 "sub "tmp" , "low" \n\t"
63 #define BRANCHLESS_GET_CABAC_UPDATE(ret, retq, low, range, tmp) \
65 "sub "low" , "tmp" \n\t"\
66 "sar $31 , "tmp" \n\t"\
67 "sub %%ecx , "range" \n\t"\
68 "and "tmp" , "range" \n\t"\
69 "add %%ecx , "range" \n\t"\
70 "shl $17 , %%ecx \n\t"\
71 "and "tmp" , %%ecx \n\t"\
72 "sub %%ecx , "low" \n\t"\
73 "xor "tmp" , "ret" \n\t"\
74 "movslq "ret" , "retq" \n\t"
77 #define BRANCHLESS_GET_CABAC(ret, retq, statep, low, lowword, range, rangeq, tmp, tmpbyte, byte, end, norm_off, lps_off, mlps_off, tables) \
78 "movzbl "statep" , "ret" \n\t"\
79 "mov "range" , "tmp" \n\t"\
80 "and $0xC0 , "range" \n\t"\
81 "lea ("ret", "range", 2), %%ecx \n\t"\
82 "movzbl "lps_off"("tables", %%rcx), "range" \n\t"\
83 "sub "range" , "tmp" \n\t"\
84 "mov "tmp" , %%ecx \n\t"\
85 "shl $17 , "tmp" \n\t"\
86 BRANCHLESS_GET_CABAC_UPDATE(ret, retq, low, range, tmp) \
87 "movzbl "norm_off"("tables", "rangeq"), %%ecx \n\t"\
88 "shl %%cl , "range" \n\t"\
89 "movzbl "mlps_off"+128("tables", "retq"), "tmp" \n\t"\
90 "shl %%cl , "low" \n\t"\
91 "mov "tmpbyte" , "statep" \n\t"\
92 "test "lowword" , "lowword" \n\t"\
94 "mov "byte" , %%"REG_c" \n\t"\
96 "add"OPSIZE" $2 , "byte" \n\t"\
98 "movzwl (%%"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"\
117 #define BRANCHLESS_GET_CABAC_UPDATE(ret, low, range, tmp)\
118 "mov "tmp" , %%ecx \n\t"\
119 "shl $17 , "tmp" \n\t"\
120 "cmp "low" , "tmp" \n\t"\
121 "cmova %%ecx , "range" \n\t"\
122 "sbb %%ecx , %%ecx \n\t"\
123 "and %%ecx , "tmp" \n\t"\
124 "xor %%ecx , "ret" \n\t"\
125 "sub "tmp" , "low" \n\t"
127 #define BRANCHLESS_GET_CABAC_UPDATE(ret, low, range, tmp)\
128 "mov "tmp" , %%ecx \n\t"\
129 "shl $17 , "tmp" \n\t"\
130 "sub "low" , "tmp" \n\t"\
131 "sar $31 , "tmp" \n\t" \
132 "sub %%ecx , "range" \n\t" \
133 "and "tmp" , "range" \n\t" \
134 "add %%ecx , "range" \n\t" \
135 "shl $17 , %%ecx \n\t"\
136 "and "tmp" , %%ecx \n\t"\
137 "sub %%ecx , "low" \n\t"\
138 "xor "tmp" , "ret" \n\t"
141 #define BRANCHLESS_GET_CABAC(ret, retq, statep, low, lowword, range, rangeq, tmp, tmpbyte, byte, end, norm_off, lps_off, mlps_off, tables) \
142 "movzbl "statep" , "ret" \n\t"\
143 "mov "range" , "tmp" \n\t"\
144 "and $0xC0 , "range" \n\t"\
145 "movzbl "MANGLE(ff_h264_cabac_tables)"+"lps_off"("ret", "range", 2), "range" \n\t"\
146 "sub "range" , "tmp" \n\t"\
147 BRANCHLESS_GET_CABAC_UPDATE(ret, low, range, tmp) \
148 "movzbl "MANGLE(ff_h264_cabac_tables)"+"norm_off"("range"), %%ecx \n\t"\
149 "shl %%cl , "range" \n\t"\
150 "movzbl "MANGLE(ff_h264_cabac_tables)"+"mlps_off"+128("ret"), "tmp" \n\t"\
151 "shl %%cl , "low" \n\t"\
152 "mov "tmpbyte" , "statep" \n\t"\
153 "test "lowword" , "lowword" \n\t"\
155 "mov "byte" , %%"REG_c" \n\t"\
157 "add"OPSIZE" $2 , "byte" \n\t"\
159 "movzwl (%%"REG_c") , "tmp" \n\t"\
160 "lea -1("low") , %%ecx \n\t"\
161 "xor "low" , %%ecx \n\t"\
162 "shr $15 , %%ecx \n\t"\
164 "shr $15 , "tmp" \n\t"\
165 "movzbl "MANGLE(ff_h264_cabac_tables)"+"norm_off"(%%ecx), %%ecx \n\t"\
166 "sub $0xFFFF , "tmp" \n\t"\
168 "add $7 , %%ecx \n\t"\
169 "shl %%cl , "tmp" \n\t"\
170 "add "tmp" , "low" \n\t"\
175 #if HAVE_7REGS && !BROKEN_COMPILER
176 #define get_cabac_inline get_cabac_inline_x86
181 #ifdef BROKEN_RELOCATIONS
191 BRANCHLESS_GET_CABAC(
"%0",
"%q0",
"(%4)",
"%1",
"%w1",
192 "%2",
"%q2",
"%3",
"%b3",
193 "%c6(%5)",
"%c7(%5)",
198 :
"=&r"(bit),
"=&r"(c->
low),
"=&r"(c->
range),
"=&q"(tmp)
199 :
"r"(
state),
"r"(c),
211 #define get_cabac_bypass_sign get_cabac_bypass_sign_x86
216 "movl %c6(%2), %k1 \n\t"
217 "movl %c3(%2), %%eax \n\t"
219 "add %%eax, %%eax \n\t"
220 "sub %k1, %%eax \n\t"
222 "and %%edx, %k1 \n\t"
223 "add %k1, %%eax \n\t"
224 "xor %%edx, %%ecx \n\t"
225 "sub %%edx, %%ecx \n\t"
226 "test %%ax, %%ax \n\t"
228 "mov %c4(%2), %1 \n\t"
229 "subl $0xFFFF, %%eax \n\t"
230 "movzwl (%1), %%edx \n\t"
232 "shrl $15, %%edx \n\t"
233 #if UNCHECKED_BITSTREAM_READER
235 "addl %%edx, %%eax \n\t"
236 "mov %1, %c4(%2) \n\t"
238 "addl %%edx, %%eax \n\t"
239 "cmp %c5(%2), %1 \n\t"
241 "add"OPSIZE
" $2, %c4(%2) \n\t"
244 "movl %%eax, %c3(%2) \n\t"
246 :
"+c"(
val),
"=&r"(tmp)
252 :
"%eax",
"%edx",
"memory"
257 #define get_cabac_bypass get_cabac_bypass_x86
263 "movl %c6(%2), %k1 \n\t"
264 "movl %c3(%2), %%eax \n\t"
266 "add %%eax, %%eax \n\t"
267 "sub %k1, %%eax \n\t"
269 "and %%edx, %k1 \n\t"
270 "add %k1, %%eax \n\t"
272 "test %%ax, %%ax \n\t"
274 "mov %c4(%2), %1 \n\t"
275 "subl $0xFFFF, %%eax \n\t"
276 "movzwl (%1), %%ecx \n\t"
278 "shrl $15, %%ecx \n\t"
279 "addl %%ecx, %%eax \n\t"
280 "cmp %c5(%2), %1 \n\t"
282 "add"OPSIZE
" $2, %c4(%2) \n\t"
284 "movl %%eax, %c3(%2) \n\t"
286 :
"=&d"(
res),
"=&r"(tmp)
292 :
"%eax",
"%ecx",
"memory"