changeset 2093:82816cad0e29 libavcodec

optimization
author michael
date Fri, 25 Jun 2004 14:11:44 +0000
parents 58b6b0ce1c20
children 9c29987380e4
files common.h h263.c mpeg12.c
diffstat 3 files changed, 18 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/common.h	Thu Jun 24 22:13:44 2004 +0000
+++ b/common.h	Fri Jun 25 14:11:44 2004 +0000
@@ -129,6 +129,14 @@
 typedef unsigned int  uint_fast32_t;
 #endif
 
+#ifndef INT_BIT
+#    if INT_MAX == INT64_MAX
+#        define INT_BIT 64
+#    else
+#        define INT_BIT 32
+#    endif
+#endif
+
 #if defined(CONFIG_OS2) || defined(CONFIG_SUNOS)
 static inline float floorf(float f) { 
     return floor(f); 
--- a/h263.c	Thu Jun 24 22:13:44 2004 +0000
+++ b/h263.c	Fri Jun 25 14:11:44 2004 +0000
@@ -1630,30 +1630,12 @@
         bit_size = f_code - 1;
         range = 1 << bit_size;
         /* modulo encoding */
-        l = range * 32;
-#if 1
-        val+= l;
-        val&= 2*l-1;
-        val-= l;
+        l= INT_BIT - 6 - bit_size;
+        val = (val<<l)>>l;
         sign = val>>31;
         val= (val^sign)-sign;
         sign&=1;
-#else
-        if (val < -l) {
-            val += 2*l;
-        } else if (val >= l) {
-            val -= 2*l;
-        }
-
-        assert(val>=-l && val<l);
-
-        if (val >= 0) {
-            sign = 0;
-        } else {
-            val = -val;
-            sign = 1;
-        }
-#endif
+
         val--;
         code = (val >> bit_size) + 1;
         bits = val & (range - 1);
@@ -4375,8 +4357,8 @@
 
     /* modulo decoding */
     if (!s->h263_long_vectors) {
-        l = 1 << (f_code + 4);
-        val = ((val + l)&(l*2-1)) - l;
+        l = INT_BIT - 5 - f_code;
+        val = (val<<l)>>l;
     } else {
         /* horrible h263 long vector mode */
         if (pred < -31 && val < -63)
--- a/mpeg12.c	Thu Jun 24 22:13:44 2004 +0000
+++ b/mpeg12.c	Fri Jun 25 14:11:44 2004 +0000
@@ -696,7 +696,7 @@
 // RAL: Parameter added: f_or_b_code
 static void mpeg1_encode_motion(MpegEncContext *s, int val, int f_or_b_code)
 {
-    int code, bit_size, l, m, bits, range, sign;
+    int code, bit_size, l, bits, range, sign;
 
     if (val == 0) {
         /* zero vector */
@@ -708,13 +708,8 @@
         bit_size = f_or_b_code - 1;
         range = 1 << bit_size;
         /* modulo encoding */
-        l = 16 * range;
-        m = 2 * l;
-        if (val < -l) {
-            val += m;
-        } else if (val >= l) {
-            val -= m;
-        }
+        l= INT_BIT - 5 - bit_size;
+        val= (val<<l)>>l;
 
         if (val >= 0) {
             val--;
@@ -1411,8 +1406,8 @@
     val += pred;
     
     /* modulo decoding */
-    l = 1 << (shift+4);
-    val = ((val + l)&(l*2-1)) - l;
+    l= INT_BIT - 5 - shift;
+    val = (val<<l)>>l;
     return val;
 }