FFmpeg
vpx_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_VPX_ARITH_H
22 #define AVCODEC_ARM_VPX_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 vpx_rac_get_prob vp56_rac_get_prob_armv6
43 static inline int vp56_rac_get_prob_armv6(VPXRangeCoder *c, int pr)
44 {
45  unsigned shift = ff_vpx_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 vpx_rac_get_prob_branchy vp56_rac_get_prob_branchy_armv6
80 static inline int vp56_rac_get_prob_branchy_armv6(VPXRangeCoder *c, int pr)
81 {
82  unsigned shift = ff_vpx_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_VPX_ARITH_H */
A
#define A(x)
Definition: vpx_arith.h:28
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
high
int high
Definition: dovi_rpuenc.c:38
VPXRangeCoder
Definition: vpx_rac.h:35
bit
#define bit(string, value)
Definition: cbs_mpeg2.c:56
T
#define T(x)
Definition: vpx_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
ff_vpx_norm_shift
const uint8_t ff_vpx_norm_shift[256]
Definition: vpx_rac.c:27
shift
static int shift(int a, int b)
Definition: bonk.c:261
__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")
U
#define U(x)
Definition: vpx_arith.h:37
L
#define L(x)
Definition: vpx_arith.h:36