view libavcodec/mathops.h @ 2:897f711a7157

rearrange to work with autoconf
author Nina Engelhardt <nengel@mailbox.tu-berlin.de>
date Tue, 25 Sep 2012 15:55:33 +0200
parents
children
line source
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
25 #include "libavutil/common.h"
26 #include "libavutil/internal.h"
28 #if ARCH_ARM
29 # include "arm/mathops.h"
30 #elif ARCH_PPC
31 # include "ppc/mathops.h"
32 #elif ARCH_X86
33 # include "x86/mathops.h"
34 #endif
36 /* generic implementation */
38 #ifndef MULL
39 # define MULL(a,b,s) (((int64_t)(a) * (int64_t)(b)) >> (s))
40 #endif
42 #ifndef MULH
43 //gcc 3.4 creates an incredibly bloated mess out of this
44 //# define MULH(a,b) (((int64_t)(a) * (int64_t)(b))>>32)
46 static av_always_inline int MULH(int a, int b){
47 return ((int64_t)(a) * (int64_t)(b))>>32;
48 }
49 #endif
51 #ifndef UMULH
52 static av_always_inline unsigned UMULH(unsigned a, unsigned b){
53 return ((uint64_t)(a) * (uint64_t)(b))>>32;
54 }
55 #endif
57 #ifndef MUL64
58 # define MUL64(a,b) ((int64_t)(a) * (int64_t)(b))
59 #endif
61 #ifndef MAC64
62 # define MAC64(d, a, b) ((d) += MUL64(a, b))
63 #endif
65 #ifndef MLS64
66 # define MLS64(d, a, b) ((d) -= MUL64(a, b))
67 #endif
69 /* signed 16x16 -> 32 multiply add accumulate */
70 #ifndef MAC16
71 # define MAC16(rt, ra, rb) rt += (ra) * (rb)
72 #endif
74 /* signed 16x16 -> 32 multiply */
75 #ifndef MUL16
76 # define MUL16(ra, rb) ((ra) * (rb))
77 #endif
79 #ifndef MLS16
80 # define MLS16(rt, ra, rb) ((rt) -= (ra) * (rb))
81 #endif
83 /* median of 3 */
84 #ifndef mid_pred
85 #define mid_pred mid_pred
86 static inline av_const int mid_pred(int a, int b, int c)
87 {
88 #if 0
89 int t= (a-b)&((a-b)>>31);
90 a-=t;
91 b+=t;
92 b-= (b-c)&((b-c)>>31);
93 b+= (a-b)&((a-b)>>31);
95 return b;
96 #else
97 if(a>b){
98 if(c>b){
99 if(c>a) b=a;
100 else b=c;
101 }
102 }else{
103 if(b>c){
104 if(c>a) b=c;
105 else b=a;
106 }
107 }
108 return b;
109 #endif
110 }
111 #endif
113 #ifndef sign_extend
114 static inline av_const int sign_extend(int val, unsigned bits)
115 {
116 return (val << (INT_BIT - bits)) >> (INT_BIT - bits);
117 }
118 #endif
120 #ifndef zero_extend
121 static inline av_const unsigned zero_extend(unsigned val, unsigned bits)
122 {
123 return (val << (INT_BIT - bits)) >> (INT_BIT - bits);
124 }
125 #endif
127 #ifndef COPY3_IF_LT
128 #define COPY3_IF_LT(x, y, a, b, c, d)\
129 if ((y) < (x)) {\
130 (x) = (y);\
131 (a) = (b);\
132 (c) = (d);\
133 }
134 #endif
136 #ifndef NEG_SSR32
137 # define NEG_SSR32(a,s) ((( int32_t)(a))>>(32-(s)))
138 #endif
140 #ifndef NEG_USR32
141 # define NEG_USR32(a,s) (((uint32_t)(a))>>(32-(s)))
142 #endif
144 #endif /* AVCODEC_MATHOPS_H */