]> rtime.felk.cvut.cz Git - frescor/ffmpeg.git/commitdiff
Replace bytecopy with the equivalent but faster av_memcpy_backptr.
authorreimar <reimar@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
Fri, 17 Apr 2009 17:46:10 +0000 (17:46 +0000)
committerreimar <reimar@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
Fri, 17 Apr 2009 17:46:10 +0000 (17:46 +0000)
Ca. 10% faster xan_unpack on x86_64 decoding of SC_32-part.MVE

git-svn-id: file:///var/local/repositories/ffmpeg/trunk@18572 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b

libavcodec/xan.c

index 36e944fdb1a4d54ced040f0b0f0aff5037acee4b..66b2ddf6cb242456b9d1ff58c902b03767fb12a3 100644 (file)
@@ -35,6 +35,8 @@
 
 #include "libavutil/intreadwrite.h"
 #include "avcodec.h"
+// for av_memcpy_backptr
+#include "libavutil/lzo.h"
 
 typedef struct XanContext {
 
@@ -76,26 +78,13 @@ static av_cold int xan_decode_init(AVCodecContext *avctx)
     s->buffer1_size = avctx->width * avctx->height;
     s->buffer1 = av_malloc(s->buffer1_size);
     s->buffer2_size = avctx->width * avctx->height;
-    s->buffer2 = av_malloc(s->buffer2_size);
+    s->buffer2 = av_malloc(s->buffer2_size + 12);
     if (!s->buffer1 || !s->buffer2)
         return -1;
 
     return 0;
 }
 
-/* This function is used in lieu of memcpy(). This decoder cannot use
- * memcpy because the memory locations often overlap and
- * memcpy doesn't like that; it's not uncommon, for example, for
- * dest = src+1, to turn byte A into  pattern AAAAAAAA.
- * This was originally repz movsb in Intel x86 ASM. */
-static inline void bytecopy(unsigned char *dest, const unsigned char *src, int count)
-{
-    int i;
-
-    for (i = 0; i < count; i++)
-        dest[i] = src[i];
-}
-
 static int xan_huffman_decode(unsigned char *dest, const unsigned char *src,
     int dest_len)
 {
@@ -130,6 +119,11 @@ static int xan_huffman_decode(unsigned char *dest, const unsigned char *src,
     return 0;
 }
 
+/**
+ * unpack simple compression
+ *
+ * @param dest destination buffer of dest_len, must be sufficiently padded for av_memcpy_backptr
+ */
 static void xan_unpack(unsigned char *dest, const unsigned char *src, int dest_len)
 {
     unsigned char opcode;
@@ -153,7 +147,7 @@ static void xan_unpack(unsigned char *dest, const unsigned char *src, int dest_l
             size = ((opcode & 0x1c) >> 2) + 3;
             if (dest + size > dest_end)
                 return;
-            bytecopy (dest, dest - (((opcode & 0x60) << 3) + offset + 1), size);
+            av_memcpy_backptr(dest, ((opcode & 0x60) << 3) + offset + 1, size);
             dest += size;
 
         } else if ( (opcode & 0x40) == 0 ) {
@@ -169,7 +163,7 @@ static void xan_unpack(unsigned char *dest, const unsigned char *src, int dest_l
             size = (opcode & 0x3f) + 4;
             if (dest + size > dest_end)
                 return;
-            bytecopy (dest, dest - (((byte1 & 0x3f) << 8) + byte2 + 1), size);
+            av_memcpy_backptr(dest, ((byte1 & 0x3f) << 8) + byte2 + 1, size);
             dest += size;
 
         } else if ( (opcode & 0x20) == 0 ) {
@@ -186,8 +180,8 @@ static void xan_unpack(unsigned char *dest, const unsigned char *src, int dest_l
             size = byte3 + 5 + ((opcode & 0xc) << 6);
             if (dest + size > dest_end)
                 return;
-            bytecopy (dest,
-                dest - ((((opcode & 0x10) >> 4) << 0x10) + 1 + (byte1 << 8) + byte2),
+            av_memcpy_backptr(dest,
+                (((opcode & 0x10) >> 4) << 0x10) + 1 + (byte1 << 8) + byte2,
                 size);
             dest += size;
         } else {