Commit 0ff93477 authored by Michael Niedermayer's avatar Michael Niedermayer

optimization

Originally committed as revision 3249 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent 4c99f2cd
......@@ -129,6 +129,14 @@ typedef unsigned int uint_fast16_t;
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);
......
......@@ -1630,30 +1630,12 @@ void ff_h263_encode_motion(MpegEncContext * s, int val, int f_code)
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 @@ static int h263_decode_motion(MpegEncContext * s, int pred, int f_code)
/* 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)
......
......@@ -696,7 +696,7 @@ void mpeg1_encode_mb(MpegEncContext *s,
// 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 @@ static void mpeg1_encode_motion(MpegEncContext *s, int val, int f_or_b_code)
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 @@ static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred)
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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment