1 /*
2 * simple math operations
3 * Copyright (c) 2001, 2002 Fabrice Bellard
4 * Copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at> et al
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22 #ifndef AVCODEC_MATHOPS_H
23 #define AVCODEC_MATHOPS_H
24
25 #include <stdint.h>
26
29 #include "config.h"
30
31 #define MAX_NEG_CROP 1024
32
39
40 #if ARCH_ARM
42 #elif ARCH_MIPS
44 #elif ARCH_PPC
46 #elif ARCH_X86
48 #endif
49
50 /* generic implementation */
51
52 #ifndef MUL64
53 # define MUL64(a,b) ((int64_t)(a) * (int64_t)(b))
54 #endif
55
56 #ifndef MULL
57 # define MULL(a,b,s) (MUL64(a, b) >> (s))
58 #endif
59
60 #ifndef MULH
63 }
64 #endif
65
66 #ifndef UMULH
68 return ((uint64_t)(
a) * (uint64_t)(
b))>>32;
69 }
70 #endif
71
72 #ifndef MAC64
73 # define MAC64(d, a, b) ((d) += MUL64(a, b))
74 #endif
75
76 #ifndef MLS64
77 # define MLS64(d, a, b) ((d) -= MUL64(a, b))
78 #endif
79
80 /* signed 16x16 -> 32 multiply add accumulate */
81 #ifndef MAC16
82 # define MAC16(rt, ra, rb) rt += (ra) * (rb)
83 #endif
84
85 /* signed 16x16 -> 32 multiply */
86 #ifndef MUL16
87 # define MUL16(ra, rb) ((ra) * (rb))
88 #endif
89
90 #ifndef MLS16
91 # define MLS16(rt, ra, rb) ((rt) -= (ra) * (rb))
92 #endif
93
94 /* median of 3 */
95 #ifndef mid_pred
96 #define mid_pred mid_pred
98 {
103 }
104 }else{
108 }
109 }
111 }
112 #endif
113
114 #ifndef median4
115 #define median4 median4
117 {
121 } else {
124 }
125 }
126 #endif
127
128 #define FF_SIGNBIT(x) ((x) >> CHAR_BIT * sizeof(x) - 1)
129
130 #ifndef sign_extend
132 {
134 union {
unsigned u;
int s; } v = { (unsigned)
val <<
shift };
136 }
137 #endif
138
139 #ifndef sign_extend64
141 {
145 }
146 #endif
147
148 #ifndef zero_extend
150 {
151 return (
val << ((8 *
sizeof(
int)) -
bits)) >> ((8 *
sizeof(int)) -
bits);
152 }
153 #endif
154
155 #ifndef COPY3_IF_LT
156 #define COPY3_IF_LT(x, y, a, b, c, d)\
157 if ((y) < (x)) {\
158 (x) = (y);\
159 (a) = (b);\
160 (c) = (d);\
161 }
162 #endif
163
164 #ifndef MASK_ABS
165 #define MASK_ABS(mask, level) do { \
166 mask = level >> 31; \
167 level = (level ^ mask) - mask; \
168 } while (0)
169 #endif
170
171 #ifndef NEG_SSR32
172 # define NEG_SSR32(a,s) ((( int32_t)(a))>>(32-(s)))
173 #endif
174
175 #ifndef NEG_USR32
176 # define NEG_USR32(a,s) (((uint32_t)(a))>>(32-(s)))
177 #endif
178
179 #if HAVE_BIGENDIAN
180 # ifndef PACK_2U8
181 # define PACK_2U8(a,b) (((a) << 8) | (b))
182 # endif
183 # ifndef PACK_4U8
184 # define PACK_4U8(a,b,c,d) (((a) << 24) | ((b) << 16) | ((c) << 8) | (d))
185 # endif
186 # ifndef PACK_2U16
187 # define PACK_2U16(a,b) (((a) << 16) | (b))
188 # endif
189 #else
190 # ifndef PACK_2U8
191 # define PACK_2U8(a,b) (((b) << 8) | (a))
192 # endif
193 # ifndef PACK_4U2
194 # define PACK_4U8(a,b,c,d) (((d) << 24) | ((c) << 16) | ((b) << 8) | (a))
195 # endif
196 # ifndef PACK_2U16
197 # define PACK_2U16(a,b) (((b) << 16) | (a))
198 # endif
199 #endif
200
201 #ifndef PACK_2S8
202 # define PACK_2S8(a,b) PACK_2U8((a)&255, (b)&255)
203 #endif
204 #ifndef PACK_4S8
205 # define PACK_4S8(a,b,c,d) PACK_4U8((a)&255, (b)&255, (c)&255, (d)&255)
206 #endif
207 #ifndef PACK_2S16
208 # define PACK_2S16(a,b) PACK_2U16((a)&0xffff, (b)&0xffff)
209 #endif
210
211 #ifndef FASTDIV
212 # define FASTDIV(a,b) ((uint32_t)((((uint64_t)a) * ff_inverse[b]) >> 32))
213 #endif /* FASTDIV */
214
215 #ifndef ff_sqrt
216 #define ff_sqrt ff_sqrt
218 {
220
223 #if !CONFIG_SMALL
226 #endif
227 else {
229 unsigned int c =
a >> (
s + 2);
232 }
233
234 return b - (
a <
b *
b);
235 }
236 #endif
237
239 {
241 }
242
244 {
245 union {
246 uint8_t u8;
247 int8_t s8;
251 }
252
253 #endif /* AVCODEC_MATHOPS_H */