changeset 236:4a090f1da60a libavcodec

optimize mpeg1_encode_block() (makeing some constant arrays global, merging put_bits(), ...)
author michaelni
date Wed, 13 Feb 2002 04:19:10 +0000
parents 41f0ef2cd942
children 75123d30f862
files mpeg12.c mpeg12data.h
diffstat 2 files changed, 40 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/mpeg12.c	Tue Feb 12 22:43:26 2002 +0000
+++ b/mpeg12.c	Wed Feb 13 04:19:10 2002 +0000
@@ -52,7 +52,8 @@
 static void put_header(MpegEncContext *s, int header)
 {
     align_put_bits(&s->pb);
-    put_bits(&s->pb, 32, header);
+    put_bits(&s->pb, 16, header>>16);
+    put_bits(&s->pb, 16, header&0xFFFF);
 }
 
 /* put sequence header if needed */
@@ -183,11 +184,18 @@
 
 void mpeg1_encode_picture_header(MpegEncContext *s, int picture_number)
 {
-    static int done;
+    static int done=0;
 
     if (!done) {
+	int i;
         done = 1;
         init_rl(&rl_mpeg1);
+	
+	for(i=0; i<64; i++)
+	{
+		mpeg1_max_level[0][i]= rl_mpeg1.max_level[0][i];
+		mpeg1_index_run[0][i]= rl_mpeg1.index_run[0][i];
+	}
     }
     mpeg1_encode_sequence_header(s);
 
@@ -347,7 +355,7 @@
 {
     int alevel, level, last_non_zero, dc, diff, i, j, run, last_index, sign;
     int code, component;
-    RLTable *rl = &rl_mpeg1;
+//    RLTable *rl = &rl_mpeg1;
 
     last_index = s->block_last_index[n];
 
@@ -376,6 +384,7 @@
 
     /* now quantify & encode AC coefs */
     last_non_zero = i - 1;
+
     for(;i<=last_index;i++) {
         j = zigzag_direct[i];
         level = block[j];
@@ -387,17 +396,38 @@
         /* encode using VLC */
         if (level != 0) {
             run = i - last_non_zero - 1;
+#ifdef ARCH_X86
+            asm volatile(
+		"movl %2, %1		\n\t"
+		"movl %1, %0		\n\t"
+		"addl %1, %1		\n\t"
+		"sbbl %1, %1		\n\t"
+		"xorl %1, %0		\n\t"
+		"subl %1, %0		\n\t"
+		"andl $1, %1		\n\t"
+		: "=&r" (alevel), "=&r" (sign)
+		: "g" (level)
+	    );
+#else
             sign = 0;
             alevel = level;
             if (alevel < 0) {
 		sign = 1;
                 alevel = -alevel;
 	    }
-            code = get_rl_index(rl, 0, run, alevel);
-            put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
-            if (code != rl->n) {
-                put_bits(&s->pb, 1, sign);
+#endif
+//            code = get_rl_index(rl, 0, run, alevel);
+            if (alevel > mpeg1_max_level[0][run])
+                code= 111; /*rl->n*/
+            else
+                code= mpeg1_index_run[0][run] + alevel - 1;
+
+            if (code < 111 /* rl->n */) {
+	    	/* store the vlc & sign at once */
+                put_bits(&s->pb, mpeg1_vlc[code][1]+1, (mpeg1_vlc[code][0]<<1) + sign);
             } else {
+		/* escape seems to be pretty rare <5% so i dont optimize it */
+                put_bits(&s->pb, mpeg1_vlc[111/*rl->n*/][1], mpeg1_vlc[111/*rl->n*/][0]);
                 /* escape: only clip in this case */
                 put_bits(&s->pb, 6, run);
                 if (alevel < 128) {
--- a/mpeg12data.h	Tue Feb 12 22:43:26 2002 +0000
+++ b/mpeg12data.h	Wed Feb 13 04:19:10 2002 +0000
@@ -161,6 +161,9 @@
  25, 26, 27, 28, 29, 30, 31,
 };
 
+static UINT8 mpeg1_index_run[2][64];
+static INT8 mpeg1_max_level[2][64];
+
 static RLTable rl_mpeg1 = {
     111,
     111,