]> git.sesse.net Git - ffmpeg/blob - libavcodec/mips/cabac.h
Include attributes.h directly
[ffmpeg] / libavcodec / mips / cabac.h
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 "libavutil/attributes.h"
28 #include "libavcodec/cabac.h"
29 #include "libavutil/mips/asmdefs.h"
30 #include "config.h"
31
32 #define get_cabac_inline get_cabac_inline_mips
33 static av_always_inline int get_cabac_inline_mips(CABACContext *c,
34                                              uint8_t * const state){
35     mips_reg tmp0, tmp1, tmp2, bit;
36
37     __asm__ volatile (
38         "lbu          %[bit],        0(%[state])                   \n\t"
39         "and          %[tmp0],       %[c_range],     0xC0          \n\t"
40         PTR_ADDU     "%[tmp0],       %[tmp0],        %[tmp0]       \n\t"
41         PTR_ADDU     "%[tmp0],       %[tmp0],        %[tables]     \n\t"
42         PTR_ADDU     "%[tmp0],       %[tmp0],        %[bit]        \n\t"
43         /* tmp1: RangeLPS */
44         "lbu          %[tmp1],       %[lps_off](%[tmp0])           \n\t"
45
46         PTR_SUBU     "%[c_range],    %[c_range],     %[tmp1]       \n\t"
47         PTR_SLL      "%[tmp0],       %[c_range],     0x11          \n\t"
48         PTR_SUBU     "%[tmp0],       %[tmp0],        %[c_low]      \n\t"
49
50         /* tmp2: lps_mask */
51         PTR_SRA      "%[tmp2],       %[tmp0],        0x1F          \n\t"
52         /* If tmp0 < 0, lps_mask ==  0xffffffff*/
53         /* If tmp0 >= 0, lps_mask ==  0x00000000*/
54         "beqz         %[tmp2],       1f                            \n\t"
55         PTR_SLL      "%[tmp0],       %[c_range],     0x11          \n\t"
56         PTR_SUBU     "%[c_low],      %[c_low],       %[tmp0]       \n\t"
57         PTR_SUBU     "%[tmp0],       %[tmp1],        %[c_range]    \n\t"
58         PTR_ADDU     "%[c_range],    %[c_range],     %[tmp0]       \n\t"
59         "xor          %[bit],        %[bit],         %[tmp2]       \n\t"
60
61         "1:                                                        \n\t"
62         /* tmp1: *state */
63         PTR_ADDU     "%[tmp0],       %[tables],      %[bit]        \n\t"
64         "lbu          %[tmp1],       %[mlps_off](%[tmp0])          \n\t"
65         /* tmp2: lps_mask */
66         PTR_ADDU     "%[tmp0],       %[tables],      %[c_range]    \n\t"
67         "lbu          %[tmp2],       %[norm_off](%[tmp0])          \n\t"
68
69         "sb           %[tmp1],       0(%[state])                   \n\t"
70         "and          %[bit],        %[bit],         0x01          \n\t"
71         PTR_SLL      "%[c_range],    %[c_range],     %[tmp2]       \n\t"
72         PTR_SLL      "%[c_low],      %[c_low],       %[tmp2]       \n\t"
73
74         "and          %[tmp0],       %[c_low],       %[cabac_mask] \n\t"
75         "bnez         %[tmp0],       1f                            \n\t"
76         PTR_ADDIU    "%[tmp0],       %[c_low],       -0x01         \n\t"
77         "xor          %[tmp0],       %[c_low],       %[tmp0]       \n\t"
78         PTR_SRA      "%[tmp0],       %[tmp0],        0x0f          \n\t"
79         PTR_ADDU     "%[tmp0],       %[tmp0],        %[tables]     \n\t"
80         "lbu          %[tmp2],       %[norm_off](%[tmp0])          \n\t"
81 #if CABAC_BITS == 16
82         "lbu          %[tmp0],       0(%[c_bytestream])            \n\t"
83         "lbu          %[tmp1],       1(%[c_bytestream])            \n\t"
84         PTR_SLL      "%[tmp0],       %[tmp0],        0x09          \n\t"
85         PTR_SLL      "%[tmp1],       %[tmp1],        0x01          \n\t"
86         PTR_ADDU     "%[tmp0],       %[tmp0],        %[tmp1]       \n\t"
87 #else
88         "lbu          %[tmp0],       0(%[c_bytestream])            \n\t"
89         PTR_SLL      "%[tmp0],       %[tmp0],        0x01          \n\t"
90 #endif
91         PTR_SUBU     "%[tmp0],       %[tmp0],        %[cabac_mask] \n\t"
92
93         "li           %[tmp1],       0x07                          \n\t"
94         PTR_SUBU     "%[tmp1],       %[tmp1],        %[tmp2]       \n\t"
95         PTR_SLL      "%[tmp0],       %[tmp0],        %[tmp1]       \n\t"
96         PTR_ADDU     "%[c_low],      %[c_low],       %[tmp0]       \n\t"
97
98 #if !UNCHECKED_BITSTREAM_READER
99         "bge          %[c_bytestream], %[c_bytestream_end], 1f     \n\t"
100 #endif
101         PTR_ADDIU    "%[c_bytestream], %[c_bytestream],     0X02   \n\t"
102         "1:                                                        \n\t"
103     : [bit]"=&r"(bit), [tmp0]"=&r"(tmp0), [tmp1]"=&r"(tmp1), [tmp2]"=&r"(tmp2),
104       [c_range]"+&r"(c->range), [c_low]"+&r"(c->low),
105       [c_bytestream]"+&r"(c->bytestream)
106     : [state]"r"(state), [tables]"r"(ff_h264_cabac_tables),
107 #if !UNCHECKED_BITSTREAM_READER
108       [c_bytestream_end]"r"(c->bytestream_end),
109 #endif
110       [lps_off]"i"(H264_LPS_RANGE_OFFSET),
111       [mlps_off]"i"(H264_MLPS_STATE_OFFSET + 128),
112       [norm_off]"i"(H264_NORM_SHIFT_OFFSET),
113       [cabac_mask]"r"(CABAC_MASK)
114     : "memory"
115     );
116
117     return bit;
118 }
119
120 #endif /* AVCODEC_MIPS_CABAC_H */