FFmpeg
cabac.h
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #ifndef AVCODEC_ARM_CABAC_H
20 #define AVCODEC_ARM_CABAC_H
21 
22 #include "config.h"
23 #if HAVE_ARMV6T2_INLINE
24 
25 #include "libavutil/attributes.h"
26 #include "libavutil/internal.h"
27 #include "libavcodec/cabac.h"
28 
29 #define get_cabac_inline get_cabac_inline_arm
30 static av_always_inline int get_cabac_inline_arm(CABACContext *c,
31  uint8_t *const state)
32 {
33  int bit;
34  void *reg_b, *reg_c, *tmp;
35 
36  __asm__ volatile(
37  "ldrb %[bit] , [%[state]] \n\t"
38  "add %[r_b] , %[tables] , %[lps_off] \n\t"
39  "mov %[tmp] , %[range] \n\t"
40  "and %[range] , %[range] , #0xC0 \n\t"
41  "add %[r_b] , %[r_b] , %[bit] \n\t"
42  "ldrb %[range] , [%[r_b], %[range], lsl #1] \n\t"
43  "add %[r_b] , %[tables] , %[norm_off] \n\t"
44  "sub %[r_c] , %[tmp] , %[range] \n\t"
45  "lsl %[tmp] , %[r_c] , #17 \n\t"
46  "cmp %[tmp] , %[low] \n\t"
47  "it gt \n\t"
48  "movgt %[range] , %[r_c] \n\t"
49  "itt cc \n\t"
50  "mvncc %[bit] , %[bit] \n\t"
51  "subcc %[low] , %[low] , %[tmp] \n\t"
52  "add %[r_c] , %[tables] , %[mlps_off] \n\t"
53  "ldrb %[tmp] , [%[r_b], %[range]] \n\t"
54  "ldrb %[r_b] , [%[r_c], %[bit]] \n\t"
55  "lsl %[low] , %[low] , %[tmp] \n\t"
56  "lsl %[range] , %[range] , %[tmp] \n\t"
57  "uxth %[r_c] , %[low] \n\t"
58  "strb %[r_b] , [%[state]] \n\t"
59  "tst %[r_c] , %[r_c] \n\t"
60  "bne 2f \n\t"
61  "ldr %[r_c] , [%[c], %[byte]] \n\t"
62 #if UNCHECKED_BITSTREAM_READER
63  "ldrh %[tmp] , [%[r_c]] \n\t"
64  "add %[r_c] , %[r_c] , #2 \n\t"
65  "str %[r_c] , [%[c], %[byte]] \n\t"
66 #else
67  "ldr %[r_b] , [%[c], %[end]] \n\t"
68  "ldrh %[tmp] , [%[r_c]] \n\t"
69  "cmp %[r_c] , %[r_b] \n\t"
70  "itt lt \n\t"
71  "addlt %[r_c] , %[r_c] , #2 \n\t"
72  "strlt %[r_c] , [%[c], %[byte]] \n\t"
73 #endif
74  "sub %[r_c] , %[low] , #1 \n\t"
75  "add %[r_b] , %[tables] , %[norm_off] \n\t"
76  "eor %[r_c] , %[low] , %[r_c] \n\t"
77  "rev %[tmp] , %[tmp] \n\t"
78  "lsr %[r_c] , %[r_c] , #15 \n\t"
79  "lsr %[tmp] , %[tmp] , #15 \n\t"
80  "ldrb %[r_c] , [%[r_b], %[r_c]] \n\t"
81  "movw %[r_b] , #0xFFFF \n\t"
82  "sub %[tmp] , %[tmp] , %[r_b] \n\t"
83  "rsb %[r_c] , %[r_c] , #7 \n\t"
84  "lsl %[tmp] , %[tmp] , %[r_c] \n\t"
85  "add %[low] , %[low] , %[tmp] \n\t"
86  "2: \n\t"
87  : [bit]"=&r"(bit),
88  [low]"+&r"(c->low),
89  [range]"+&r"(c->range),
90  [r_b]"=&r"(reg_b),
91  [r_c]"=&r"(reg_c),
92  [tmp]"=&r"(tmp)
93  : [c]"r"(c),
94  [state]"r"(state),
96  [byte]"M"(offsetof(CABACContext, bytestream)),
97  [end]"M"(offsetof(CABACContext, bytestream_end)),
98  [norm_off]"I"(H264_NORM_SHIFT_OFFSET),
99  [lps_off]"I"(H264_LPS_RANGE_OFFSET),
100  [mlps_off]"I"(H264_MLPS_STATE_OFFSET + 128)
101  : "memory", "cc"
102  );
103 
104  return bit & 1;
105 }
106 #endif /* HAVE_ARMV6T2_INLINE */
107 
108 #endif /* AVCODEC_ARM_CABAC_H */
cabac.h
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
bit
#define bit(string, value)
Definition: cbs_mpeg2.c:56
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]
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
range
enum AVColorRange range
Definition: mediacodec_wrapper.c:2594
attributes.h
internal.h
av_always_inline
#define av_always_inline
Definition: attributes.h:49
state
static struct @465 state
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")
r_b
#define r_b
H264_MLPS_STATE_OFFSET
#define H264_MLPS_STATE_OFFSET
Definition: cabac.h:35
CABACContext
Definition: cabac.h:41