optimization

Originally committed as revision 3249 to svn://svn.ffmpeg.org/ffmpeg/trunk
pull/126/head
Michael Niedermayer 21 years ago
parent 4c99f2cdbe
commit 0ff93477be
  1. 8
      libavcodec/common.h
  2. 26
      libavcodec/h263.c
  3. 15
      libavcodec/mpeg12.c

@ -129,6 +129,14 @@ typedef unsigned int uint_fast16_t;
typedef unsigned int uint_fast32_t; typedef unsigned int uint_fast32_t;
#endif #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) #if defined(CONFIG_OS2) || defined(CONFIG_SUNOS)
static inline float floorf(float f) { static inline float floorf(float f) {
return floor(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; bit_size = f_code - 1;
range = 1 << bit_size; range = 1 << bit_size;
/* modulo encoding */ /* modulo encoding */
l = range * 32; l= INT_BIT - 6 - bit_size;
#if 1 val = (val<<l)>>l;
val+= l;
val&= 2*l-1;
val-= l;
sign = val>>31; sign = val>>31;
val= (val^sign)-sign; val= (val^sign)-sign;
sign&=1; 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--; val--;
code = (val >> bit_size) + 1; code = (val >> bit_size) + 1;
bits = val & (range - 1); bits = val & (range - 1);
@ -4375,8 +4357,8 @@ static int h263_decode_motion(MpegEncContext * s, int pred, int f_code)
/* modulo decoding */ /* modulo decoding */
if (!s->h263_long_vectors) { if (!s->h263_long_vectors) {
l = 1 << (f_code + 4); l = INT_BIT - 5 - f_code;
val = ((val + l)&(l*2-1)) - l; val = (val<<l)>>l;
} else { } else {
/* horrible h263 long vector mode */ /* horrible h263 long vector mode */
if (pred < -31 && val < -63) if (pred < -31 && val < -63)

@ -696,7 +696,7 @@ void mpeg1_encode_mb(MpegEncContext *s,
// RAL: Parameter added: f_or_b_code // RAL: Parameter added: f_or_b_code
static void mpeg1_encode_motion(MpegEncContext *s, int val, int 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) { if (val == 0) {
/* zero vector */ /* 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; bit_size = f_or_b_code - 1;
range = 1 << bit_size; range = 1 << bit_size;
/* modulo encoding */ /* modulo encoding */
l = 16 * range; l= INT_BIT - 5 - bit_size;
m = 2 * l; val= (val<<l)>>l;
if (val < -l) {
val += m;
} else if (val >= l) {
val -= m;
}
if (val >= 0) { if (val >= 0) {
val--; val--;
@ -1411,8 +1406,8 @@ static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred)
val += pred; val += pred;
/* modulo decoding */ /* modulo decoding */
l = 1 << (shift+4); l= INT_BIT - 5 - shift;
val = ((val + l)&(l*2-1)) - l; val = (val<<l)>>l;
return val; return val;
} }

Loading…
Cancel
Save