FFmpeg
vp56_arith.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2010 Mans Rullgard <mans@mansr.com>
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #ifndef AVCODEC_ARM_VP56_ARITH_H
22 #define AVCODEC_ARM_VP56_ARITH_H
23 
24 #if CONFIG_THUMB
25 # define A(x)
26 # define T(x) x
27 #else
28 # define A(x) x
29 # define T(x)
30 #endif
31 
32 #if CONFIG_THUMB || defined __clang__
33 # define L(x)
34 # define U(x) x
35 #else
36 # define L(x) x
37 # define U(x)
38 #endif
39 
40 #if HAVE_ARMV6_INLINE
41 
42 #define vp56_rac_get_prob vp56_rac_get_prob_armv6
43 static inline int vp56_rac_get_prob_armv6(VP56RangeCoder *c, int pr)
44 {
45  unsigned shift = ff_vp56_norm_shift[c->high];
46  unsigned code_word = c->code_word << shift;
47  unsigned high = c->high << shift;
48  unsigned bit;
49 
50  __asm__ ("adds %3, %3, %0 \n"
51  "itt cs \n"
52  "cmpcs %7, %4 \n"
53  L("ldrcsh %2, [%4], #2 \n")
54  U("ldrhcs %2, [%4], #2 \n")
55  "rsb %0, %6, #256 \n"
56  "smlabb %0, %5, %6, %0 \n"
57  T("itttt cs \n")
58  "rev16cs %2, %2 \n"
59  T("lslcs %2, %2, %3 \n")
60  T("orrcs %1, %1, %2 \n")
61  A("orrcs %1, %1, %2, lsl %3 \n")
62  "subcs %3, %3, #16 \n"
63  "lsr %0, %0, #8 \n"
64  "cmp %1, %0, lsl #16 \n"
65  "ittte ge \n"
66  "subge %1, %1, %0, lsl #16 \n"
67  "subge %0, %5, %0 \n"
68  "movge %2, #1 \n"
69  "movlt %2, #0 \n"
70  : "=&r"(c->high), "=&r"(c->code_word), "=&r"(bit),
71  "+&r"(c->bits), "+&r"(c->buffer)
72  : "r"(high), "r"(pr), "r"(c->end - 1),
73  "0"(shift), "1"(code_word)
74  : "cc");
75 
76  return bit;
77 }
78 
79 #define vp56_rac_get_prob_branchy vp56_rac_get_prob_branchy_armv6
80 static inline int vp56_rac_get_prob_branchy_armv6(VP56RangeCoder *c, int pr)
81 {
82  unsigned shift = ff_vp56_norm_shift[c->high];
83  unsigned code_word = c->code_word << shift;
84  unsigned high = c->high << shift;
85  unsigned low;
86  unsigned tmp;
87 
88  __asm__ ("adds %3, %3, %0 \n"
89  "itt cs \n"
90  "cmpcs %7, %4 \n"
91  L("ldrcsh %2, [%4], #2 \n")
92  U("ldrhcs %2, [%4], #2 \n")
93  "rsb %0, %6, #256 \n"
94  "smlabb %0, %5, %6, %0 \n"
95  T("itttt cs \n")
96  "rev16cs %2, %2 \n"
97  T("lslcs %2, %2, %3 \n")
98  T("orrcs %1, %1, %2 \n")
99  A("orrcs %1, %1, %2, lsl %3 \n")
100  "subcs %3, %3, #16 \n"
101  "lsr %0, %0, #8 \n"
102  "lsl %2, %0, #16 \n"
103  : "=&r"(low), "+&r"(code_word), "=&r"(tmp),
104  "+&r"(c->bits), "+&r"(c->buffer)
105  : "r"(high), "r"(pr), "r"(c->end - 1), "0"(shift)
106  : "cc");
107 
108  if (code_word >= tmp) {
109  c->high = high - low;
110  c->code_word = code_word - tmp;
111  return 1;
112  }
113 
114  c->high = low;
115  c->code_word = code_word;
116  return 0;
117 }
118 
119 #endif
120 
121 #endif /* AVCODEC_ARM_VP56_ARITH_H */
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:26
bit
#define bit(string, value)
Definition: cbs_mpeg2.c:58
A
#define A(x)
Definition: vp56_arith.h:28
U
#define U(x)
Definition: vp56_arith.h:37
T
#define T(x)
Definition: vp56_arith.h:29
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
L
#define L(x)
Definition: vp56_arith.h:36
VP56RangeCoder
Definition: vp56.h:85
shift
static int shift(int a, int b)
Definition: sonic.c:82
ff_vp56_norm_shift
const uint8_t ff_vp56_norm_shift[256]
vp56 specific range coder implementation
Definition: vp56rac.c:25