changeset 702:2cff6fc37716 libavcodec

minor optimization of h263_encode_motion()
author michaelni
date Fri, 27 Sep 2002 15:38:54 +0000
parents 85b071dfc7e3
children 65f9e32225ba
files h263.c
diffstat 1 files changed, 13 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/h263.c	Fri Sep 27 10:27:57 2002 +0000
+++ b/h263.c	Fri Sep 27 15:38:54 2002 +0000
@@ -1079,7 +1079,7 @@
 
 static void h263_encode_motion(MpegEncContext * s, int val, int f_code)
 {
-    int range, l, m, bit_size, sign, code, bits;
+    int range, l, bit_size, sign, code, bits;
 
     if (val == 0) {
         /* zero vector */
@@ -1090,12 +1090,20 @@
         range = 1 << bit_size;
         /* modulo encoding */
         l = range * 32;
-        m = 2 * l;
+#if 1
+        val+= l;
+        val&= 2*l-1;
+        val-= l;
+        sign = val>>31;
+        val= (val^sign)-sign;
+        sign&=1;
+#else
         if (val < -l) {
-            val += m;
+            val += 2*l;
         } else if (val >= l) {
-            val -= m;
+            val -= 2*l;
         }
+
         assert(val>=-l && val<l);
 
         if (val >= 0) {
@@ -1104,6 +1112,7 @@
             val = -val;
             sign = 1;
         }
+#endif
         val--;
         code = (val >> bit_size) + 1;
         bits = val & (range - 1);