]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/mathops.h
mpegvideo_enc: only allocate output packet when we know there will be output
[ffmpeg] / libavcodec / mathops.h
index 547bc1aa4f7f433b8157b05523b0b9945789cdd4..d6eb98ddac586f39c0b489a3cd2e62c488ba9b98 100644 (file)
@@ -23,6 +23,7 @@
 #define AVCODEC_MATHOPS_H
 
 #include "libavutil/common.h"
+#include "config.h"
 
 #if   ARCH_ARM
 #   include "arm/mathops.h"
 
 /* generic implementation */
 
+#ifndef MUL64
+#   define MUL64(a,b) ((int64_t)(a) * (int64_t)(b))
+#endif
+
 #ifndef MULL
-#   define MULL(a,b,s) (((int64_t)(a) * (int64_t)(b)) >> (s))
+#   define MULL(a,b,s) (MUL64(a, b) >> (s))
 #endif
 
 #ifndef MULH
-//gcc 3.4 creates an incredibly bloated mess out of this
-//#    define MULH(a,b) (((int64_t)(a) * (int64_t)(b))>>32)
-
 static av_always_inline int MULH(int a, int b){
-    return ((int64_t)(a) * (int64_t)(b))>>32;
+    return MUL64(a, b) >> 32;
 }
 #endif
 
@@ -59,10 +61,6 @@ static av_always_inline unsigned UMULH(unsigned a, unsigned b){
 }
 #endif
 
-#ifndef MUL64
-#   define MUL64(a,b) ((int64_t)(a) * (int64_t)(b))
-#endif
-
 #ifndef MAC64
 #   define MAC64(d, a, b) ((d) += MUL64(a, b))
 #endif
@@ -118,7 +116,9 @@ static inline av_const int mid_pred(int a, int b, int c)
 #ifndef sign_extend
 static inline av_const int sign_extend(int val, unsigned bits)
 {
-    return (val << ((8 * sizeof(int)) - bits)) >> ((8 * sizeof(int)) - bits);
+    unsigned shift = 8 * sizeof(int) - bits;
+    union { unsigned u; int s; } v = { (unsigned) val << shift };
+    return v.s >> shift;
 }
 #endif
 
@@ -179,4 +179,3 @@ if ((y) < (x)) {\
 #endif
 
 #endif /* AVCODEC_MATHOPS_H */
-