[Ffmpeg-devel] [PATCH] simple internal lzo decoder

Reimar Döffinger Reimar.Doeffinger
Sat Jan 14 14:07:30 CET 2006


Hello,
On Thu, Jan 12, 2006 at 03:49:10PM +0100, Reimar at mplayerhq.hu wrote:
> On Wed, Jan 11, 2006 at 12:09:58AM +0100, Michael Niedermayer wrote:
> > btw, hows the speed of it compared to liblzo?
> 
> Actually, no idea, didn't check it (speed was not any consideration at
> all).

I tested the speed, these are the values (+patch refers to the attached
patch, that helps gcc being a bit less stupid. If there are no
objections I will apply it tomorrow):

each 10MB uncompressed, looped 100 times,
user time of time command, median of three runs,
compiled with -O3 (gcc 3.4.4),
run on Athlon 64 3200+ at 800 MHz in 64 bit mode

liblzo lzo.c (lzo.c + patch)

only zeros, 56325B comp:
8.89s 9.15s 8.48s

nwnmod, 2675408B comp:
6.68s 12.32s 7.98s

/dev/urandom, 10527740B comp:
4.31s 7.55s 4.18s

But as I usually manage to screw something up when benchmarking things,
take these with a grain of salt :-)

Greetings,
Reimar D?ffinger
-------------- next part --------------
Index: libavcodec/lzo.c
===================================================================
RCS file: /cvsroot/ffmpeg/ffmpeg/libavcodec/lzo.c,v
retrieving revision 1.3
diff -u -r1.3 lzo.c
--- libavcodec/lzo.c	14 Jan 2006 12:55:20 -0000	1.3
+++ libavcodec/lzo.c	14 Jan 2006 13:01:36 -0000
@@ -21,8 +21,7 @@
 
 typedef struct LZOContext {
     uint8_t *in, *in_end;
-    uint8_t *out, *out_end;
-    int out_size;
+    uint8_t *out_start, *out, *out_end;
     int error;
 } LZOContext;
 
@@ -57,17 +56,21 @@
  * \param cnt number of bytes to copy, must be > 0
  */
 static inline void copy(LZOContext *c, int cnt) {
-    if (c->in + cnt > c->in_end) {
-        cnt = c->in_end - c->in;
+    register uint8_t *in_ptr = c->in;
+    register uint8_t *out_ptr = c->out;
+    if (in_ptr + cnt > c->in_end) {
+        cnt = c->in_end - in_ptr;
         c->error |= LZO_INPUT_DEPLETED;
     }
-    if (c->out + cnt > c->out_end) {
-        cnt = c->out_end - c->out;
+    if (out_ptr + cnt > c->out_end) {
+        cnt = c->out_end - out_ptr;
         c->error |= LZO_OUTPUT_FULL;
     }
     do {
-        *c->out++ = *c->in++;
+        *out_ptr++ = *in_ptr++;
     } while (--cnt);
+    c->in = in_ptr;
+    c->out = out_ptr;
 }
 
 /**
@@ -78,17 +81,19 @@
  * cnt > back is valid, this will copy the bytes we just copied.
  */
 static inline void copy_backptr(LZOContext *c, int back, int cnt) {
-    if (c->out - back < c->out_end - c->out_size) {
+    register uint8_t *out_ptr = c->out;
+    if (out_ptr - back < c->out_start) {
         c->error |= LZO_INVALID_BACKPTR;
         return;
     }
-    if (c->out + cnt > c->out_end) {
-        cnt = c->out_end - c->out;
+    if (out_ptr + cnt > c->out_end) {
+        cnt = c->out_end - out_ptr;
         c->error |= LZO_OUTPUT_FULL;
     }
     do {
-        *c->out++ = c->out[-back];
+        *out_ptr++ = out_ptr[-back];
     } while (--cnt);
+    c->out = out_ptr;
 }
 
 /**
@@ -105,9 +110,8 @@
     LZOContext c;
     c.in = in;
     c.in_end = in + *inlen;
-    c.out = out;
+    c.out = c.out_start = out;
     c.out_end = out + * outlen;
-    c.out_size = *outlen;
     c.error = 0;
     x = get_byte(&c);
     if (x > 17) {



More information about the ffmpeg-devel mailing list