annotate libavcodec/mathops.h @ 9:ea1ba68cf0ed

update to match api changes + add sscc produced source
author Nina Engelhardt <nengel@mailbox.tu-berlin.de>
date Wed, 05 Jun 2013 14:43:26 +0200
parents
children
rev   line source
nengel@2 1 /*
nengel@2 2 * simple math operations
nengel@2 3 * Copyright (c) 2001, 2002 Fabrice Bellard
nengel@2 4 * Copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at> et al
nengel@2 5 *
nengel@2 6 * This file is part of FFmpeg.
nengel@2 7 *
nengel@2 8 * FFmpeg is free software; you can redistribute it and/or
nengel@2 9 * modify it under the terms of the GNU Lesser General Public
nengel@2 10 * License as published by the Free Software Foundation; either
nengel@2 11 * version 2.1 of the License, or (at your option) any later version.
nengel@2 12 *
nengel@2 13 * FFmpeg is distributed in the hope that it will be useful,
nengel@2 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nengel@2 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
nengel@2 16 * Lesser General Public License for more details.
nengel@2 17 *
nengel@2 18 * You should have received a copy of the GNU Lesser General Public
nengel@2 19 * License along with FFmpeg; if not, write to the Free Software
nengel@2 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
nengel@2 21 */
nengel@2 22 #ifndef AVCODEC_MATHOPS_H
nengel@2 23 #define AVCODEC_MATHOPS_H
nengel@2 24
nengel@2 25 #include "libavutil/common.h"
nengel@2 26 #include "libavutil/internal.h"
nengel@2 27
nengel@2 28 #if ARCH_ARM
nengel@2 29 # include "arm/mathops.h"
nengel@2 30 #elif ARCH_PPC
nengel@2 31 # include "ppc/mathops.h"
nengel@2 32 #elif ARCH_X86
nengel@2 33 # include "x86/mathops.h"
nengel@2 34 #endif
nengel@2 35
nengel@2 36 /* generic implementation */
nengel@2 37
nengel@2 38 #ifndef MULL
nengel@2 39 # define MULL(a,b,s) (((int64_t)(a) * (int64_t)(b)) >> (s))
nengel@2 40 #endif
nengel@2 41
nengel@2 42 #ifndef MULH
nengel@2 43 //gcc 3.4 creates an incredibly bloated mess out of this
nengel@2 44 //# define MULH(a,b) (((int64_t)(a) * (int64_t)(b))>>32)
nengel@2 45
nengel@2 46 static av_always_inline int MULH(int a, int b){
nengel@2 47 return ((int64_t)(a) * (int64_t)(b))>>32;
nengel@2 48 }
nengel@2 49 #endif
nengel@2 50
nengel@2 51 #ifndef UMULH
nengel@2 52 static av_always_inline unsigned UMULH(unsigned a, unsigned b){
nengel@2 53 return ((uint64_t)(a) * (uint64_t)(b))>>32;
nengel@2 54 }
nengel@2 55 #endif
nengel@2 56
nengel@2 57 #ifndef MUL64
nengel@2 58 # define MUL64(a,b) ((int64_t)(a) * (int64_t)(b))
nengel@2 59 #endif
nengel@2 60
nengel@2 61 #ifndef MAC64
nengel@2 62 # define MAC64(d, a, b) ((d) += MUL64(a, b))
nengel@2 63 #endif
nengel@2 64
nengel@2 65 #ifndef MLS64
nengel@2 66 # define MLS64(d, a, b) ((d) -= MUL64(a, b))
nengel@2 67 #endif
nengel@2 68
nengel@2 69 /* signed 16x16 -> 32 multiply add accumulate */
nengel@2 70 #ifndef MAC16
nengel@2 71 # define MAC16(rt, ra, rb) rt += (ra) * (rb)
nengel@2 72 #endif
nengel@2 73
nengel@2 74 /* signed 16x16 -> 32 multiply */
nengel@2 75 #ifndef MUL16
nengel@2 76 # define MUL16(ra, rb) ((ra) * (rb))
nengel@2 77 #endif
nengel@2 78
nengel@2 79 #ifndef MLS16
nengel@2 80 # define MLS16(rt, ra, rb) ((rt) -= (ra) * (rb))
nengel@2 81 #endif
nengel@2 82
nengel@2 83 /* median of 3 */
nengel@2 84 #ifndef mid_pred
nengel@2 85 #define mid_pred mid_pred
nengel@2 86 static inline av_const int mid_pred(int a, int b, int c)
nengel@2 87 {
nengel@2 88 #if 0
nengel@2 89 int t= (a-b)&((a-b)>>31);
nengel@2 90 a-=t;
nengel@2 91 b+=t;
nengel@2 92 b-= (b-c)&((b-c)>>31);
nengel@2 93 b+= (a-b)&((a-b)>>31);
nengel@2 94
nengel@2 95 return b;
nengel@2 96 #else
nengel@2 97 if(a>b){
nengel@2 98 if(c>b){
nengel@2 99 if(c>a) b=a;
nengel@2 100 else b=c;
nengel@2 101 }
nengel@2 102 }else{
nengel@2 103 if(b>c){
nengel@2 104 if(c>a) b=c;
nengel@2 105 else b=a;
nengel@2 106 }
nengel@2 107 }
nengel@2 108 return b;
nengel@2 109 #endif
nengel@2 110 }
nengel@2 111 #endif
nengel@2 112
nengel@2 113 #ifndef sign_extend
nengel@2 114 static inline av_const int sign_extend(int val, unsigned bits)
nengel@2 115 {
nengel@2 116 return (val << (INT_BIT - bits)) >> (INT_BIT - bits);
nengel@2 117 }
nengel@2 118 #endif
nengel@2 119
nengel@2 120 #ifndef zero_extend
nengel@2 121 static inline av_const unsigned zero_extend(unsigned val, unsigned bits)
nengel@2 122 {
nengel@2 123 return (val << (INT_BIT - bits)) >> (INT_BIT - bits);
nengel@2 124 }
nengel@2 125 #endif
nengel@2 126
nengel@2 127 #ifndef COPY3_IF_LT
nengel@2 128 #define COPY3_IF_LT(x, y, a, b, c, d)\
nengel@2 129 if ((y) < (x)) {\
nengel@2 130 (x) = (y);\
nengel@2 131 (a) = (b);\
nengel@2 132 (c) = (d);\
nengel@2 133 }
nengel@2 134 #endif
nengel@2 135
nengel@2 136 #ifndef NEG_SSR32
nengel@2 137 # define NEG_SSR32(a,s) ((( int32_t)(a))>>(32-(s)))
nengel@2 138 #endif
nengel@2 139
nengel@2 140 #ifndef NEG_USR32
nengel@2 141 # define NEG_USR32(a,s) (((uint32_t)(a))>>(32-(s)))
nengel@2 142 #endif
nengel@2 143
nengel@2 144 #endif /* AVCODEC_MATHOPS_H */
nengel@2 145