FFmpeg
cabac.h
Go to the documentation of this file.
1 /*
2  * Loongson SIMD optimized h264chroma
3  *
4  * Copyright (c) 2018 Loongson Technology Corporation Limited
5  * Copyright (c) 2018 Shiyou Yin <yinshiyou-hf@loongson.cn>
6  *
7  * This file is part of FFmpeg.
8  *
9  * FFmpeg is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * FFmpeg is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with FFmpeg; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  */
23 
24 #ifndef AVCODEC_MIPS_CABAC_H
25 #define AVCODEC_MIPS_CABAC_H
26 
27 #include "libavcodec/cabac.h"
28 #include "libavutil/mips/asmdefs.h"
29 #include "config.h"
30 
31 #define get_cabac_inline get_cabac_inline_mips
33  uint8_t * const state){
34  mips_reg tmp0, tmp1, tmp2, bit;
35 
36  __asm__ volatile (
37  "lbu %[bit], 0(%[state]) \n\t"
38  "and %[tmp0], %[c_range], 0xC0 \n\t"
39  PTR_ADDU "%[tmp0], %[tmp0], %[tmp0] \n\t"
40  PTR_ADDU "%[tmp0], %[tmp0], %[tables] \n\t"
41  PTR_ADDU "%[tmp0], %[tmp0], %[bit] \n\t"
42  /* tmp1: RangeLPS */
43  "lbu %[tmp1], %[lps_off](%[tmp0]) \n\t"
44 
45  PTR_SUBU "%[c_range], %[c_range], %[tmp1] \n\t"
46  PTR_SLL "%[tmp0], %[c_range], 0x11 \n\t"
47  PTR_SUBU "%[tmp0], %[tmp0], %[c_low] \n\t"
48 
49  /* tmp2: lps_mask */
50  PTR_SRA "%[tmp2], %[tmp0], 0x1F \n\t"
51  /* If tmp0 < 0, lps_mask == 0xffffffff*/
52  /* If tmp0 >= 0, lps_mask == 0x00000000*/
53  "beqz %[tmp2], 1f \n\t"
54  PTR_SLL "%[tmp0], %[c_range], 0x11 \n\t"
55  PTR_SUBU "%[c_low], %[c_low], %[tmp0] \n\t"
56  PTR_SUBU "%[tmp0], %[tmp1], %[c_range] \n\t"
57  PTR_ADDU "%[c_range], %[c_range], %[tmp0] \n\t"
58  "xor %[bit], %[bit], %[tmp2] \n\t"
59 
60  "1: \n\t"
61  /* tmp1: *state */
62  PTR_ADDU "%[tmp0], %[tables], %[bit] \n\t"
63  "lbu %[tmp1], %[mlps_off](%[tmp0]) \n\t"
64  /* tmp2: lps_mask */
65  PTR_ADDU "%[tmp0], %[tables], %[c_range] \n\t"
66  "lbu %[tmp2], %[norm_off](%[tmp0]) \n\t"
67 
68  "sb %[tmp1], 0(%[state]) \n\t"
69  "and %[bit], %[bit], 0x01 \n\t"
70  PTR_SLL "%[c_range], %[c_range], %[tmp2] \n\t"
71  PTR_SLL "%[c_low], %[c_low], %[tmp2] \n\t"
72 
73  "and %[tmp0], %[c_low], %[cabac_mask] \n\t"
74  "bnez %[tmp0], 1f \n\t"
75  PTR_ADDIU "%[tmp0], %[c_low], -0x01 \n\t"
76  "xor %[tmp0], %[c_low], %[tmp0] \n\t"
77  PTR_SRA "%[tmp0], %[tmp0], 0x0f \n\t"
78  PTR_ADDU "%[tmp0], %[tmp0], %[tables] \n\t"
79  "lbu %[tmp2], %[norm_off](%[tmp0]) \n\t"
80 #if CABAC_BITS == 16
81  "lbu %[tmp0], 0(%[c_bytestream]) \n\t"
82  "lbu %[tmp1], 1(%[c_bytestream]) \n\t"
83  PTR_SLL "%[tmp0], %[tmp0], 0x09 \n\t"
84  PTR_SLL "%[tmp1], %[tmp1], 0x01 \n\t"
85  PTR_ADDU "%[tmp0], %[tmp0], %[tmp1] \n\t"
86 #else
87  "lbu %[tmp0], 0(%[c_bytestream]) \n\t"
88  PTR_SLL "%[tmp0], %[tmp0], 0x01 \n\t"
89 #endif
90  PTR_SUBU "%[tmp0], %[tmp0], %[cabac_mask] \n\t"
91 
92  "li %[tmp1], 0x07 \n\t"
93  PTR_SUBU "%[tmp1], %[tmp1], %[tmp2] \n\t"
94  PTR_SLL "%[tmp0], %[tmp0], %[tmp1] \n\t"
95  PTR_ADDU "%[c_low], %[c_low], %[tmp0] \n\t"
96 
97 #if !UNCHECKED_BITSTREAM_READER
98  "bge %[c_bytestream], %[c_bytestream_end], 1f \n\t"
99 #endif
100  PTR_ADDIU "%[c_bytestream], %[c_bytestream], 0X02 \n\t"
101  "1: \n\t"
102  : [bit]"=&r"(bit), [tmp0]"=&r"(tmp0), [tmp1]"=&r"(tmp1), [tmp2]"=&r"(tmp2),
103  [c_range]"+&r"(c->range), [c_low]"+&r"(c->low),
104  [c_bytestream]"+&r"(c->bytestream)
105  : [state]"r"(state), [tables]"r"(ff_h264_cabac_tables),
107  [c_bytestream_end]"r"(c->bytestream_end),
108 #endif
109  [lps_off]"i"(H264_LPS_RANGE_OFFSET),
110  [mlps_off]"i"(H264_MLPS_STATE_OFFSET + 128),
111  [norm_off]"i"(H264_NORM_SHIFT_OFFSET),
112  [cabac_mask]"r"(CABAC_MASK)
113  : "memory"
114  );
115 
116  return bit;
117 }
118 
119 #endif /* AVCODEC_MIPS_CABAC_H */
cabac.h
PTR_SLL
#define PTR_SLL
Definition: asmdefs.h:55
state
static struct @321 state
asmdefs.h
mips_reg
#define mips_reg
Definition: asmdefs.h:44
bit
#define bit(string, value)
Definition: cbs_mpeg2.c:58
tables
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
Definition: tablegen.txt:10
ff_h264_cabac_tables
const uint8_t ff_h264_cabac_tables[512+4 *2 *64+4 *64+63]
CABAC_MASK
#define CABAC_MASK
Definition: cabac.h:39
c
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
Definition: undefined.txt:32
H264_LPS_RANGE_OFFSET
#define H264_LPS_RANGE_OFFSET
Definition: cabac.h:34
PTR_SUBU
#define PTR_SUBU
Definition: asmdefs.h:50
av_always_inline
#define av_always_inline
Definition: attributes.h:49
uint8_t
uint8_t
Definition: audio_convert.c:194
H264_NORM_SHIFT_OFFSET
#define H264_NORM_SHIFT_OFFSET
Definition: cabac.h:33
__asm__
__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")
PTR_ADDU
#define PTR_ADDU
Definition: asmdefs.h:47
get_cabac_inline_mips
static av_always_inline int get_cabac_inline_mips(CABACContext *c, uint8_t *const state)
Definition: cabac.h:32
UNCHECKED_BITSTREAM_READER
#define UNCHECKED_BITSTREAM_READER
Definition: cabac_functions.h:37
PTR_ADDIU
#define PTR_ADDIU
Definition: asmdefs.h:48
H264_MLPS_STATE_OFFSET
#define H264_MLPS_STATE_OFFSET
Definition: cabac.h:35
CABACContext
Definition: cabac.h:41
PTR_SRA
#define PTR_SRA
Definition: asmdefs.h:53