21 #ifndef AVCODEC_X86_CABAC_H
22 #define AVCODEC_X86_CABAC_H
32 #ifdef BROKEN_RELOCATIONS
33 #define TABLES_ARG , "r"(tables)
36 #define BRANCHLESS_GET_CABAC_UPDATE(ret, retq, low, range, tmp) \
37 "cmp "low" , "tmp" \n\t"\
38 "cmova %%ecx , "range" \n\t"\
39 "sbb %%rcx , %%rcx \n\t"\
40 "and %%ecx , "tmp" \n\t"\
41 "xor %%rcx , "retq" \n\t"\
42 "sub "tmp" , "low" \n\t"
44 #define BRANCHLESS_GET_CABAC_UPDATE(ret, retq, low, range, tmp) \
46 "sub "low" , "tmp" \n\t"\
47 "sar $31 , "tmp" \n\t"\
48 "sub %%ecx , "range" \n\t"\
49 "and "tmp" , "range" \n\t"\
50 "add %%ecx , "range" \n\t"\
51 "shl $17 , %%ecx \n\t"\
52 "and "tmp" , %%ecx \n\t"\
53 "sub %%ecx , "low" \n\t"\
54 "xor "tmp" , "ret" \n\t"\
55 "movslq "ret" , "retq" \n\t"
58 #define BRANCHLESS_GET_CABAC(ret, retq, statep, low, lowword, range, rangeq, tmp, tmpbyte, byte, end, norm_off, lps_off, mlps_off, tables) \
59 "movzbl "statep" , "ret" \n\t"\
60 "mov "range" , "tmp" \n\t"\
61 "and $0xC0 , "range" \n\t"\
62 "lea ("ret", "range", 2), %%ecx \n\t"\
63 "movzbl "lps_off"("tables", %%rcx), "range" \n\t"\
64 "sub "range" , "tmp" \n\t"\
65 "mov "tmp" , %%ecx \n\t"\
66 "shl $17 , "tmp" \n\t"\
67 BRANCHLESS_GET_CABAC_UPDATE(ret, retq, low, range, tmp) \
68 "movzbl "norm_off"("tables", "rangeq"), %%ecx \n\t"\
69 "shl %%cl , "range" \n\t"\
70 "movzbl "mlps_off"+128("tables", "retq"), "tmp" \n\t"\
71 "shl %%cl , "low" \n\t"\
72 "mov "tmpbyte" , "statep" \n\t"\
73 "test "lowword" , "lowword" \n\t"\
75 "mov "byte" , %%"REG_c" \n\t"\
76 "add"OPSIZE" $2 , "byte" \n\t"\
77 "movzwl (%%"REG_c") , "tmp" \n\t"\
78 "lea -1("low") , %%ecx \n\t"\
79 "xor "low" , %%ecx \n\t"\
80 "shr $15 , %%ecx \n\t"\
82 "shr $15 , "tmp" \n\t"\
83 "movzbl "norm_off"("tables", %%rcx), %%ecx \n\t"\
84 "sub $0xFFFF , "tmp" \n\t"\
86 "add $7 , %%ecx \n\t"\
87 "shl %%cl , "tmp" \n\t"\
88 "add "tmp" , "low" \n\t"\
96 #define BRANCHLESS_GET_CABAC_UPDATE(ret, low, range, tmp)\
97 "mov "tmp" , %%ecx \n\t"\
98 "shl $17 , "tmp" \n\t"\
99 "cmp "low" , "tmp" \n\t"\
100 "cmova %%ecx , "range" \n\t"\
101 "sbb %%ecx , %%ecx \n\t"\
102 "and %%ecx , "tmp" \n\t"\
103 "xor %%ecx , "ret" \n\t"\
104 "sub "tmp" , "low" \n\t"
106 #define BRANCHLESS_GET_CABAC_UPDATE(ret, low, range, tmp)\
107 "mov "tmp" , %%ecx \n\t"\
108 "shl $17 , "tmp" \n\t"\
109 "sub "low" , "tmp" \n\t"\
110 "sar $31 , "tmp" \n\t" \
111 "sub %%ecx , "range" \n\t" \
112 "and "tmp" , "range" \n\t" \
113 "add %%ecx , "range" \n\t" \
114 "shl $17 , %%ecx \n\t"\
115 "and "tmp" , %%ecx \n\t"\
116 "sub %%ecx , "low" \n\t"\
117 "xor "tmp" , "ret" \n\t"
120 #define BRANCHLESS_GET_CABAC(ret, retq, statep, low, lowword, range, rangeq, tmp, tmpbyte, byte, end, norm_off, lps_off, mlps_off, tables) \
121 "movzbl "statep" , "ret" \n\t"\
122 "mov "range" , "tmp" \n\t"\
123 "and $0xC0 , "range" \n\t"\
124 "movzbl "MANGLE(ff_h264_cabac_tables)"+"lps_off"("ret", "range", 2), "range" \n\t"\
125 "sub "range" , "tmp" \n\t"\
126 BRANCHLESS_GET_CABAC_UPDATE(ret, low, range, tmp) \
127 "movzbl "MANGLE(ff_h264_cabac_tables)"+"norm_off"("range"), %%ecx \n\t"\
128 "shl %%cl , "range" \n\t"\
129 "movzbl "MANGLE(ff_h264_cabac_tables)"+"mlps_off"+128("ret"), "tmp" \n\t"\
130 "shl %%cl , "low" \n\t"\
131 "mov "tmpbyte" , "statep" \n\t"\
132 "test "lowword" , "lowword" \n\t"\
134 "mov "byte" , %%"REG_c" \n\t"\
135 "add"OPSIZE" $2 , "byte" \n\t"\
136 "movzwl (%%"REG_c") , "tmp" \n\t"\
137 "lea -1("low") , %%ecx \n\t"\
138 "xor "low" , %%ecx \n\t"\
139 "shr $15 , %%ecx \n\t"\
141 "shr $15 , "tmp" \n\t"\
142 "movzbl "MANGLE(ff_h264_cabac_tables)"+"norm_off"(%%ecx), %%ecx \n\t"\
143 "sub $0xFFFF , "tmp" \n\t"\
145 "add $7 , %%ecx \n\t"\
146 "shl %%cl , "tmp" \n\t"\
147 "add "tmp" , "low" \n\t"\
153 #if HAVE_7REGS && !(defined(__i386) && defined(__clang__) && (__clang_major__<2 || (__clang_major__==2 && __clang_minor__<10)))\
154 && !(defined(__i386) && !defined(__clang__) && defined(__llvm__) && __GNUC__==4 && __GNUC_MINOR__==2 && __GNUC_PATCHLEVEL__<=1)
155 #define get_cabac_inline get_cabac_inline_x86
160 #ifdef BROKEN_RELOCATIONS
170 BRANCHLESS_GET_CABAC(
"%0",
"%q0",
"(%4)",
"%1",
"%w1",
171 "%2",
"%q2",
"%3",
"%b3",
172 "%c6(%5)",
"%c7(%5)",
177 :
"=&r"(bit),
"=&r"(
c->low),
"=&r"(
c->range),
"=&q"(tmp)
182 ,
"1"(
c->low),
"2"(
c->range)
189 #define get_cabac_bypass_sign get_cabac_bypass_sign_x86
194 "movl %c6(%2), %k1 \n\t"
195 "movl %c3(%2), %%eax \n\t"
197 "add %%eax, %%eax \n\t"
198 "sub %k1, %%eax \n\t"
200 "and %%edx, %k1 \n\t"
201 "add %k1, %%eax \n\t"
202 "xor %%edx, %%ecx \n\t"
203 "sub %%edx, %%ecx \n\t"
204 "test %%ax, %%ax \n\t"
206 "mov %c4(%2), %1 \n\t"
207 "subl $0xFFFF, %%eax \n\t"
208 "movzwl (%1), %%edx \n\t"
210 "shrl $15, %%edx \n\t"
212 "addl %%edx, %%eax \n\t"
213 "mov %1, %c4(%2) \n\t"
215 "movl %%eax, %c3(%2) \n\t"
217 :
"+c"(val),
"=&r"(tmp)
223 :
"%eax",
"%edx",
"memory"