Go to the documentation of this file.
25 #ifndef AVCODEC_LOONGARCH_CABAC_H
26 #define AVCODEC_LOONGARCH_CABAC_H
31 #define GET_CABAC_LOONGARCH_UNCBSR \
32 "ld.bu %[bit], %[state], 0x0 \n\t" \
33 "andi %[tmp0], %[c_range], 0xC0 \n\t" \
34 "slli.d %[tmp0], %[tmp0], 0x01 \n\t" \
35 "add.d %[tmp0], %[tmp0], %[tables] \n\t" \
36 "add.d %[tmp0], %[tmp0], %[bit] \n\t" \
38 "ld.bu %[tmp1], %[tmp0], %[lps_off] \n\t" \
40 "sub.d %[c_range], %[c_range], %[tmp1] \n\t" \
41 "slli.d %[tmp0], %[c_range], 0x11 \n\t" \
42 "bge %[tmp0], %[c_low], 1f \n\t" \
43 "move %[c_range], %[tmp1] \n\t" \
44 "nor %[bit], %[bit], %[bit] \n\t" \
45 "sub.d %[c_low], %[c_low], %[tmp0] \n\t" \
49 "add.d %[tmp0], %[tables], %[bit] \n\t" \
50 "ld.bu %[tmp1], %[tmp0], %[mlps_off] \n\t" \
52 "add.d %[tmp0], %[tables], %[c_range] \n\t" \
53 "ld.bu %[tmp2], %[tmp0], %[norm_off] \n\t" \
55 "andi %[bit], %[bit], 0x01 \n\t" \
56 "st.b %[tmp1], %[state], 0x0 \n\t" \
57 "sll.d %[c_range], %[c_range], %[tmp2] \n\t" \
58 "sll.d %[c_low], %[c_low], %[tmp2] \n\t" \
60 "and %[tmp1], %[c_low], %[cabac_mask] \n\t" \
61 "bnez %[tmp1], 1f \n\t" \
62 "ld.hu %[tmp1], %[c_bytestream], 0x0 \n\t" \
63 "ctz.d %[tmp0], %[c_low] \n\t" \
64 "addi.d %[tmp2], %[tmp0], -16 \n\t" \
65 "revb.2h %[tmp0], %[tmp1] \n\t" \
66 "slli.d %[tmp0], %[tmp0], 0x01 \n\t" \
67 "sub.d %[tmp0], %[tmp0], %[cabac_mask] \n\t" \
68 "sll.d %[tmp0], %[tmp0], %[tmp2] \n\t" \
69 "add.d %[c_low], %[c_low], %[tmp0] \n\t" \
70 "addi.d %[c_bytestream], %[c_bytestream], 0x02 \n\t" \
73 #define GET_CABAC_LOONGARCH \
74 "ld.bu %[bit], %[state], 0x0 \n\t" \
75 "andi %[tmp0], %[c_range], 0xC0 \n\t" \
76 "slli.d %[tmp0], %[tmp0], 0x01 \n\t" \
77 "add.d %[tmp0], %[tmp0], %[tables] \n\t" \
78 "add.d %[tmp0], %[tmp0], %[bit] \n\t" \
80 "ld.bu %[tmp1], %[tmp0], %[lps_off] \n\t" \
82 "sub.d %[c_range], %[c_range], %[tmp1] \n\t" \
83 "slli.d %[tmp0], %[c_range], 0x11 \n\t" \
84 "bge %[tmp0], %[c_low], 1f \n\t" \
85 "move %[c_range], %[tmp1] \n\t" \
86 "nor %[bit], %[bit], %[bit] \n\t" \
87 "sub.d %[c_low], %[c_low], %[tmp0] \n\t" \
91 "add.d %[tmp0], %[tables], %[bit] \n\t" \
92 "ld.bu %[tmp1], %[tmp0], %[mlps_off] \n\t" \
94 "add.d %[tmp0], %[tables], %[c_range] \n\t" \
95 "ld.bu %[tmp2], %[tmp0], %[norm_off] \n\t" \
97 "andi %[bit], %[bit], 0x01 \n\t" \
98 "st.b %[tmp1], %[state], 0x0 \n\t" \
99 "sll.d %[c_range], %[c_range], %[tmp2] \n\t" \
100 "sll.d %[c_low], %[c_low], %[tmp2] \n\t" \
102 "and %[tmp1], %[c_low], %[cabac_mask] \n\t" \
103 "bnez %[tmp1], 1f \n\t" \
104 "ld.hu %[tmp1], %[c_bytestream], 0x0 \n\t" \
105 "ctz.d %[tmp0], %[c_low] \n\t" \
106 "addi.d %[tmp2], %[tmp0], -16 \n\t" \
107 "revb.2h %[tmp0], %[tmp1] \n\t" \
108 "slli.d %[tmp0], %[tmp0], 0x01 \n\t" \
109 "sub.d %[tmp0], %[tmp0], %[cabac_mask] \n\t" \
110 "sll.d %[tmp0], %[tmp0], %[tmp2] \n\t" \
112 "add.d %[c_low], %[c_low], %[tmp0] \n\t" \
114 "slt %[tmp0], %[c_bytestream], %[c_bytestream_end] \n\t" \
115 "add.d %[c_bytestream], %[c_bytestream], %[tmp0] \n\t" \
116 "add.d %[c_bytestream], %[c_bytestream], %[tmp0] \n\t" \
119 #define get_cabac_inline get_cabac_inline_loongarch
123 int64_t tmp0, tmp1, tmp2,
bit;
126 #if UNCHECKED_BITSTREAM_READER
131 : [
bit]
"=&r"(
bit), [tmp0]
"=&r"(tmp0), [tmp1]
"=&r"(tmp1), [tmp2]
"=&r"(tmp2),
132 [c_range]
"+&r"(
c->range), [c_low]
"+&r"(
c->low),
133 [c_bytestream]
"+&r"(
c->bytestream)
136 [c_bytestream_end]
"r"(
c->bytestream_end),
148 #define get_cabac_bypass get_cabac_bypass_loongarch
151 int64_t tmp0, tmp1, tmp2;
154 "slli.d %[c_low], %[c_low], 0x01 \n\t"
155 "and %[tmp0], %[c_low], %[cabac_mask] \n\t"
156 "bnez %[tmp0], 1f \n\t"
157 "ld.hu %[tmp1], %[c_bytestream], 0x0 \n\t"
158 #if UNCHECKED_BITSTREAM_READER
159 "addi.d %[c_bytestream], %[c_bytestream], 0x02 \n\t"
161 "slt %[tmp0], %[c_bytestream], %[c_bytestream_end] \n\t"
162 "add.d %[c_bytestream], %[c_bytestream], %[tmp0] \n\t"
163 "add.d %[c_bytestream], %[c_bytestream], %[tmp0] \n\t"
165 "revb.2h %[tmp1], %[tmp1] \n\t"
166 "slli.d %[tmp1], %[tmp1], 0x01 \n\t"
167 "sub.d %[tmp1], %[tmp1], %[cabac_mask] \n\t"
168 "add.d %[c_low], %[c_low], %[tmp1] \n\t"
170 "slli.d %[tmp1], %[c_range], 0x11 \n\t"
171 "slt %[tmp0], %[c_low], %[tmp1] \n\t"
172 "sub.d %[tmp1], %[c_low], %[tmp1] \n\t"
173 "masknez %[tmp2], %[one], %[tmp0] \n\t"
174 "maskeqz %[res], %[res], %[tmp0] \n\t"
175 "or %[res], %[res], %[tmp2] \n\t"
176 "masknez %[tmp2], %[tmp1], %[tmp0] \n\t"
177 "maskeqz %[c_low], %[c_low], %[tmp0] \n\t"
178 "or %[c_low], %[c_low], %[tmp2] \n\t"
179 : [tmp0]
"=&r"(tmp0), [tmp1]
"=&r"(tmp1), [tmp2]
"=&r"(tmp2),
180 [c_range]
"+&r"(
c->range), [c_low]
"+&r"(
c->low),
181 [c_bytestream]
"+&r"(
c->bytestream), [res]
"+&r"(res)
183 #if !UNCHECKED_BITSTREAM_READER
184 [c_bytestream_end]
"r"(
c->bytestream_end),
192 #define get_cabac_bypass_sign get_cabac_bypass_sign_loongarch
199 "slli.d %[c_low], %[c_low], 0x01 \n\t"
200 "and %[tmp0], %[c_low], %[cabac_mask] \n\t"
201 "bnez %[tmp0], 1f \n\t"
202 "ld.hu %[tmp1], %[c_bytestream], 0x0 \n\t"
203 #if UNCHECKED_BITSTREAM_READER
204 "addi.d %[c_bytestream], %[c_bytestream], 0x02 \n\t"
206 "slt %[tmp0], %[c_bytestream], %[c_bytestream_end] \n\t"
207 "add.d %[c_bytestream], %[c_bytestream], %[tmp0] \n\t"
208 "add.d %[c_bytestream], %[c_bytestream], %[tmp0] \n\t"
210 "revb.2h %[tmp1], %[tmp1] \n\t"
211 "slli.d %[tmp1], %[tmp1], 0x01 \n\t"
212 "sub.d %[tmp1], %[tmp1], %[cabac_mask] \n\t"
213 "add.d %[c_low], %[c_low], %[tmp1] \n\t"
215 "slli.d %[tmp1], %[c_range], 0x11 \n\t"
216 "slt %[tmp0], %[c_low], %[tmp1] \n\t"
217 "sub.d %[tmp1], %[c_low], %[tmp1] \n\t"
218 "masknez %[tmp1], %[tmp1], %[tmp0] \n\t"
219 "maskeqz %[c_low], %[c_low], %[tmp0] \n\t"
220 "or %[c_low], %[c_low], %[tmp1] \n\t"
221 "sub.d %[tmp1], %[zero], %[res] \n\t"
222 "maskeqz %[tmp1], %[tmp1], %[tmp0] \n\t"
223 "masknez %[res], %[res], %[tmp0] \n\t"
224 "or %[res], %[res], %[tmp1] \n\t"
225 : [tmp0]
"=&r"(tmp0), [tmp1]
"=&r"(tmp1), [res]
"+&r"(res),
226 [c_range]
"+&r"(
c->range), [c_low]
"+&r"(
c->low),
227 [c_bytestream]
"+&r"(
c->bytestream)
230 [c_bytestream_end]
"r"(
c->bytestream_end),
#define GET_CABAC_LOONGARCH_UNCBSR
static av_always_inline int get_cabac_inline_loongarch(CABACContext *c, uint8_t *const state)
#define bit(string, value)
Writing a table generator This documentation is preliminary Parts of the API are not good and should be changed Basic concepts A table generator consists of two *_tablegen c and *_tablegen h The h file will provide the variable declarations and initialization code for the tables
static double val(void *priv, double ch)
const uint8_t ff_h264_cabac_tables[512+4 *2 *64+4 *64+63]
#define GET_CABAC_LOONGARCH
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
#define H264_LPS_RANGE_OFFSET
static av_always_inline int get_cabac_bypass_loongarch(CABACContext *c)
#define H264_NORM_SHIFT_OFFSET
__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")
static av_always_inline int get_cabac_bypass_sign_loongarch(CABACContext *c, int val)
#define UNCHECKED_BITSTREAM_READER
#define H264_MLPS_STATE_OFFSET