basic_prediction_mmx.c
资源名称:VC++视频传输.rar [点击查看]
上传用户:hxb_1234
上传日期:2010-03-30
资源大小:8328k
文件大小:15k
源码类别:
VC书籍
开发平台:
Visual C++
- /**************************************************************************
- * *
- * This code has been developed by Eugene Kuznetsov. This software is an *
- * implementation of a part of one or more MPEG-4 Video tools as *
- * specified in ISO/IEC 14496-2 standard. Those intending to use this *
- * software module in hardware or software products are advised that its *
- * use may infringe existing patents or copyrights, and any such use *
- * would be at such party's own risk. The original developer of this *
- * software module and his/her company, and subsequent editors and their *
- * companies (including Project Mayo), will have no liability for use of *
- * this software or modifications or derivatives thereof. *
- * *
- * Project Mayo gives users of the Codec a license to this software *
- * module or modifications thereof for use in hardware or software *
- * products claiming conformance to the MPEG-4 Video Standard as *
- * described in the Open DivX license. *
- * *
- * The complete Open DivX license can be found at *
- * http://www.projectmayo.com/opendivx/license.php *
- * *
- **************************************************************************/
- /**
- * Copyright (C) 2001 - Project Mayo
- *
- * Eugene Kuznetsov
- *
- * DivX Advanced Research Center <darc@projectmayo.com>
- *
- **/
- #include "basic_prediction.h"
- // Purpose: specialized basic motion compensation routines
- void CopyBlock(unsigned char * Src, unsigned char * Dst, int Stride)
- {
- int dy;
- long *lpSrc = (long *) Src;
- long *lpDst = (long *) Dst;
- int lpStride = Stride >> 2;
- for (dy = 0; dy < 8; dy++) {
- lpDst[0] = lpSrc[0];
- lpDst[1] = lpSrc[1];
- lpSrc += lpStride;
- lpDst += lpStride;
- }
- }
- #define CopyBlockHorLoop
- "movb (%%esi), %%aln"
- "incl %%esin"
- "movb (%%esi), %%cln"
- "addl %%ecx, %%eaxn"
- "incl %%eaxn"
- "shrl $1, %%eaxn"
- "movb %%al, (%%edi)n"
- "incl %%edin"
- // input: esi
- // output: edi
- // modifies: eax, ebx, edx
- #define CopyBlockHorLoopFast
- "movl (%%esi), %%edxn"
- "movl 1(%%esi), %%ebxn"
- "movl %%edx, %%eaxn"
- "xorl %%ebx, %%edxn"
- "shrl $1, %%edxn"
- "adcl %%ebx, %%eaxn"
- "rcrl $1, %%eaxn"
- "andl $0x808080, %%edxn"
- "addl %%edx, %%eaxn"
- "movl %%eax, (%%edi)n"
- "addl $4, %%esin"
- "addl $4, %%edin"
- #define CopyBlockVerLoopFast
- "movl (%%esi), %%edxn"
- "movl (%%esi,%%ecx), %%ebxn"
- "movl %%edx, %%eaxn"
- "xorl %%ebx, %%edxn"
- "shrl $1, %%edxn"
- "adcl %%ebx, %%eaxn"
- "rcrl $1, %%eaxn"
- "andl $0x808080, %%edxn"
- "addl %%edx, %%eaxn"
- "movl %%eax, (%%edi)n"
- "addl $4, %%esin"
- "addl $4, %%edin"
- #define CopyBlockHorLoopRound
- "movb (%%esi), %%aln"
- "incl %%esin"
- "movb (%%esi), %%cln"
- "addl %%ecx, %%eaxn"
- "shrl $1, %%eaxn"
- "movb %%al, (%%edi)n"
- "incl %%edin"
- #define CopyBlockVerLoop
- "movb (%%esi), %%aln"
- "movb (%%esi,%%ebx), %%cln"
- "addl %%ecx, %%eaxn"
- "incl %%eaxn"
- "shrl $1, %%eaxn"
- "movb %%al, (%%edi)n"
- "incl %%esin"
- "incl %%edin"
- #define CopyBlockVerLoopRound
- "movb (%%esi), %%aln"
- "movb (%%esi,%%ebx), %%cln"
- "addl %%ecx, %%eaxn"
- "shrl $1, %%eaxn"
- "movb %%al, (%%edi)n"
- "incl %%esin"
- "incl %%edin"
- #define CopyBlockHorVerLoop(STEP)
- "movb " #STEP "(%%esi), %%aln"
- "movb " #STEP "+1(%%esi), %%cln"
- "addl %%ecx, %%eaxn"
- "movb " #STEP "(%%esi, %%ebx), %%cln"
- "addl %%ecx, %%eaxn"
- "movb " #STEP "+1(%%esi, %%ebx), %%cln"
- "addl %%ecx, %%eaxn"
- "addl $2, %%eaxn"
- "shrl $2, %%eaxn"
- "movb %%al, " #STEP "(%%edi)n"
- #define CopyBlockHorVerLoopRound(STEP)
- "movb " #STEP "(%%esi), %%aln"
- "movb " #STEP "+1(%%esi), %%cln"
- "addl %%ecx, %%eaxn"
- "movb " #STEP "(%%esi, %%ebx), %%cln"
- "addl %%ecx, %%eaxn"
- "movb " #STEP "+1(%%esi, %%ebx), %%cln"
- "addl %%ecx, %%eaxn"
- "incl %%eaxn"
- "shrl $2, %%eaxn"
- "movb %%al, " #STEP "(%%edi)n"
- /**/
- void CopyBlockHor(unsigned char * Src, unsigned char * Dst, int Stride)
- {
- __asm__ (
- "movl %2, %%esin"
- "movl %3, %%edin"
- "pushl %%ebxn"
- "1:n"
- "pushl %%edxn"
- CopyBlockHorLoopFast
- CopyBlockHorLoopFast
- "popl %%edxn"
- "addl %%ecx, %%esin"
- "addl %%ecx, %%edin"
- "decl %%edxn"
- "jnz 1bn"
- "popl %%ebxn"
- :
- : "c"(Stride-8), "d"(8), "g" (Src), "g"(Dst)
- : "esi", "edi"
- );
- }
- void CopyBlockVer(unsigned char * Src, unsigned char * Dst, int Stride)
- {
- __asm__ (
- "movl %2, %%esin"
- "movl %3, %%edin"
- "pushl %%ebxn"
- "1:n"
- "pushl %%edxn"
- CopyBlockVerLoopFast
- CopyBlockVerLoopFast
- "popl %%edxn"
- "addl %%ecx, %%esin"
- "subl $8, %%esin"
- "addl %%ecx, %%edin"
- "subl $8, %%edin"
- "decl %%edxn"
- "jnz 1bn"
- "popl %%ebxn"
- :
- : "c"(Stride), "d"(8), "g" (Src), "g"(Dst)
- : "esi", "edi"
- );
- }
- /*
- void CopyBlockHor(unsigned char * Src, unsigned char * Dst, int Stride)
- {
- __asm__ (
- "pushl %%ebxn"
- "movl %1, %%ebxn"
- "movl %4, %%esin"
- "movl %5, %%edin"
- "1:n"
- CopyBlockHorLoop
- CopyBlockHorLoop
- CopyBlockHorLoop
- CopyBlockHorLoop
- CopyBlockHorLoop
- CopyBlockHorLoop
- CopyBlockHorLoop
- CopyBlockHorLoop
- "addl %%ebx, %%esin"
- "addl %%ebx, %%edin"
- "decl %%edxn"
- "jnz 1bn"
- "popl %%ebxn"
- :
- : "a"(0), "g"(Stride-8), "c"(0), "d"(8), "g" (Src), "g"(Dst)
- );
- }
- */
- void CopyBlockHorRound(unsigned char * Src, unsigned char * Dst, int Stride)
- {
- __asm__ (
- "movl %1, %%eaxn"
- "movl %4, %%esin"
- "movl %5, %%edin"
- "pushl %%ebxn"
- "movl %%eax, %%ebxn"
- "xorl %%eax, %%eaxn"
- "1:n"
- CopyBlockHorLoopRound
- CopyBlockHorLoopRound
- CopyBlockHorLoopRound
- CopyBlockHorLoopRound
- CopyBlockHorLoopRound
- CopyBlockHorLoopRound
- CopyBlockHorLoopRound
- CopyBlockHorLoopRound
- "addl %%ebx, %%esin"
- "addl %%ebx, %%edin"
- "decl %%edxn"
- "jnz 1bn"
- "popl %%ebxn"
- :
- : "a"(0), "g"(Stride-8), "c"(0), "d"(8), "g" (Src), "g"(Dst)
- : "esi", "edi"
- );
- }
- /**/
- /*
- void CopyBlockVer(unsigned char * Src, unsigned char * Dst, int Stride)
- {
- __asm__ (
- "pushl %%ebxn"
- "movl %1, %%ebxn"
- "movl %4, %%esin"
- "movl %5, %%edin"
- "1:n"
- CopyBlockVerLoop
- CopyBlockVerLoop
- CopyBlockVerLoop
- CopyBlockVerLoop
- CopyBlockVerLoop
- CopyBlockVerLoop
- CopyBlockVerLoop
- CopyBlockVerLoop
- "addl %%ebx, %%esin"
- "subl $8, %%esin"
- "addl %%ebx, %%edin"
- "subl $8, %%edin"
- "decl %%edxn"
- "jnz 1bn"
- "popl %%ebxn"
- :
- : "a"(0), "g"(Stride), "c"(0), "d"(8), "g" (Src), "g"(Dst)
- );
- }
- */
- /**/
- void CopyBlockVerRound(unsigned char * Src, unsigned char * Dst, int Stride)
- {
- __asm__ (
- "movl %1, %%eaxn"
- "movl %4, %%esin"
- "movl %5, %%edin"
- "pushl %%ebxn"
- "movl %%eax, %%ebxn"
- "xorl %%eax, %%eaxn"
- "1:n"
- CopyBlockVerLoopRound
- CopyBlockVerLoopRound
- CopyBlockVerLoopRound
- CopyBlockVerLoopRound
- CopyBlockVerLoopRound
- CopyBlockVerLoopRound
- CopyBlockVerLoopRound
- CopyBlockVerLoopRound
- "addl %%ebx, %%esin"
- "subl $8, %%esin"
- "addl %%ebx, %%edin"
- "subl $8, %%edin"
- "decl %%edxn"
- "jnz 1bn"
- "popl %%ebxn"
- :
- : "a"(0), "g"(Stride), "c"(0), "d"(8), "g" (Src), "g"(Dst)
- : "esi", "edi"
- );
- }/**/
- void CopyBlockHorVer(unsigned char * Src, unsigned char * Dst, int Stride)
- {
- int dy, dx;
- for (dy = 0; dy < 8; dy++) {
- for (dx = 0; dx < 8; dx++) {
- Dst[dx] = (Src[dx] + Src[dx+1] +
- Src[dx+Stride] + Src[dx+Stride+1] +2) >> 2; // horver interpolation with rounding
- }
- Src += Stride;
- Dst += Stride;
- }
- }
- /**/
- void CopyBlockHorVerRound(unsigned char * Src, unsigned char * Dst, int Stride)
- {
- int dy, dx;
- for (dy = 0; dy < 8; dy++) {
- for (dx = 0; dx < 8; dx++) {
- Dst[dx] = (Src[dx] + Src[dx+1] +
- Src[dx+Stride] + Src[dx+Stride+1] +1) >> 2; // horver interpolation with rounding
- }
- Src += Stride;
- Dst += Stride;
- }
- }
- /** *** **/
- void CopyMBlock(unsigned char * Src, unsigned char * Dst, int Stride)
- {
- __asm__
- (
- "movl %0, %%eaxn"
- "movl %2, %%esin"
- "movl %3, %%edin"
- "pushl %%ebxn"
- "movl %%eax, %%ebxn"
- "1:n"
- "movl (%%esi), %%eaxn"
- "movl %%eax, (%%edi)n"
- "addl $4, %%esin"
- "addl $4, %%edin"
- "movl (%%esi), %%eaxn"
- "movl %%eax, (%%edi)n"
- "addl $4, %%esin"
- "addl $4, %%edin"
- "movl (%%esi), %%eaxn"
- "movl %%eax, (%%edi)n"
- "addl $4, %%esin"
- "addl $4, %%edin"
- "movl (%%esi), %%eaxn"
- "movl %%eax, (%%edi)n"
- "addl %%ebx, %%esin"
- "addl %%ebx, %%edin"
- "decl %%edxn"
- "jnz 1bn"
- "popl %%ebxn"
- :
- : "g"(Stride-12), "d"(16), "g" (Src), "g" (Dst)
- : "esi", "edi"
- );
- }
- /**/
- void CopyMBlockHor(unsigned char * Src, unsigned char * Dst, int Stride)
- {
- __asm__ (
- "movl %2, %%esin"
- "movl %3, %%edin"
- "pushl %%ebxn"
- "1:n"
- "pushl %%edxn"
- CopyBlockHorLoopFast
- CopyBlockHorLoopFast
- CopyBlockHorLoopFast
- CopyBlockHorLoopFast
- "popl %%edxn"
- "addl %%ecx, %%esin"
- "addl %%ecx, %%edin"
- "decl %%edxn"
- "jnz 1bn"
- "popl %%ebxn"
- :
- : "c"(Stride-16), "d"(16), "g" (Src), "g"(Dst)
- : "esi", "edi"
- );
- }
- void CopyMBlockVer(unsigned char * Src, unsigned char * Dst, int Stride)
- {
- __asm__ (
- "movl %2, %%esin"
- "movl %3, %%edin"
- "pushl %%ebxn"
- "1:n"
- "pushl %%edxn"
- CopyBlockVerLoopFast
- CopyBlockVerLoopFast
- CopyBlockVerLoopFast
- CopyBlockVerLoopFast
- "popl %%edxn"
- "addl %%ecx, %%esin"
- "subl $16, %%esin"
- "addl %%ecx, %%edin"
- "subl $16, %%edin"
- "decl %%edxn"
- "jnz 1bn"
- "popl %%ebxn"
- :
- : "c"(Stride), "d"(16), "g" (Src), "g"(Dst)
- : "esi", "edi"
- );
- }
- /*
- void CopyMBlockHor(unsigned char * Src, unsigned char * Dst, int Stride)
- {
- __asm__ (
- "pushl %%ebxn"
- "movl %1, %%ebxn"
- "movl %4, %%esin"
- "movl %5, %%edin"
- "1:n"
- CopyBlockHorLoop
- CopyBlockHorLoop
- CopyBlockHorLoop
- CopyBlockHorLoop
- CopyBlockHorLoop
- CopyBlockHorLoop
- CopyBlockHorLoop
- CopyBlockHorLoop
- CopyBlockHorLoop
- CopyBlockHorLoop
- CopyBlockHorLoop
- CopyBlockHorLoop
- CopyBlockHorLoop
- CopyBlockHorLoop
- CopyBlockHorLoop
- CopyBlockHorLoop
- "addl %%ebx, %%esin"
- "addl %%ebx, %%edin"
- "decl %%edxn"
- "jnz 1bn"
- "popl %%ebxn"
- :
- : "a"(0), "g"(Stride-16), "c"(0), "d"(16), "g" (Src), "g"(Dst)
- );
- }
- */
- /*
- void CopyMBlockVer(unsigned char * Src, unsigned char * Dst, int Stride)
- {
- __asm__ (
- "pushl %%ebxn"
- "movl %1, %%ebxn"
- "movl %4, %%esin"
- "movl %5, %%edin"
- "1:n"
- CopyBlockVerLoop
- CopyBlockVerLoop
- CopyBlockVerLoop
- CopyBlockVerLoop
- CopyBlockVerLoop
- CopyBlockVerLoop
- CopyBlockVerLoop
- CopyBlockVerLoop
- CopyBlockVerLoop
- CopyBlockVerLoop
- CopyBlockVerLoop
- CopyBlockVerLoop
- CopyBlockVerLoop
- CopyBlockVerLoop
- CopyBlockVerLoop
- CopyBlockVerLoop
- "addl %%ebx, %%esin"
- "subl $16, %%esin"
- "addl %%ebx, %%edin"
- "subl $16, %%edin"
- "decl %%edxn"
- "jnz 1bn"
- "popl %%ebxn"
- :
- : "a"(0), "g"(Stride), "c"(0), "d"(16), "g" (Src), "g"(Dst)
- );
- }
- */
- void CopyMBlockHorRound(unsigned char * Src, unsigned char * Dst, int Stride)
- {
- __asm__ (
- "movl %1, %%eaxn"
- "movl %4, %%esin"
- "movl %5, %%edin"
- "pushl %%ebxn"
- "movl %%eax, %%ebxn"
- "xorl %%eax, %%eaxn"
- "1:n"
- CopyBlockHorLoopRound
- CopyBlockHorLoopRound
- CopyBlockHorLoopRound
- CopyBlockHorLoopRound
- CopyBlockHorLoopRound
- CopyBlockHorLoopRound
- CopyBlockHorLoopRound
- CopyBlockHorLoopRound
- CopyBlockHorLoopRound
- CopyBlockHorLoopRound
- CopyBlockHorLoopRound
- CopyBlockHorLoopRound
- CopyBlockHorLoopRound
- CopyBlockHorLoopRound
- CopyBlockHorLoopRound
- CopyBlockHorLoopRound
- "addl %%ebx, %%esin"
- "addl %%ebx, %%edin"
- "decl %%edxn"
- "jnz 1bn"
- "popl %%ebxn"
- :
- : "a"(0), "g"(Stride-16), "c"(0), "d"(16), "g" (Src), "g"(Dst)
- : "esi", "edi"
- );
- }
- void CopyMBlockVerRound(unsigned char * Src, unsigned char * Dst, int Stride)
- {
- __asm__ (
- "movl %1, %%eaxn"
- "movl %4, %%esin"
- "movl %5, %%edin"
- "pushl %%ebxn"
- "movl %%eax, %%ebxn"
- "xorl %%eax, %%eaxn"
- "1:n"
- CopyBlockVerLoopRound
- CopyBlockVerLoopRound
- CopyBlockVerLoopRound
- CopyBlockVerLoopRound
- CopyBlockVerLoopRound
- CopyBlockVerLoopRound
- CopyBlockVerLoopRound
- CopyBlockVerLoopRound
- CopyBlockVerLoopRound
- CopyBlockVerLoopRound
- CopyBlockVerLoopRound
- CopyBlockVerLoopRound
- CopyBlockVerLoopRound
- CopyBlockVerLoopRound
- CopyBlockVerLoopRound
- CopyBlockVerLoopRound
- "addl %%ebx, %%esin"
- "subl $16, %%esin"
- "addl %%ebx, %%edin"
- "subl $16, %%edin"
- "decl %%edxn"
- "jnz 1bn"
- "popl %%ebxn"
- :
- : "a"(0), "g"(Stride), "c"(0), "d"(16), "g" (Src), "g"(Dst)
- : "esi", "edi"
- );
- }
- /**/
- void CopyMBlockHorVer(unsigned char * Src, unsigned char * Dst, int Stride)
- {
- __asm__
- (
- "movl %1, %%eaxn"
- "movl %4, %%esin"
- "movl %5, %%edin"
- "pushl %%ebxn"
- "movl %%eax, %%ebxn"
- "xorl %%eax, %%eaxn"
- "1:n"
- CopyBlockHorVerLoop(0)
- CopyBlockHorVerLoop(1)
- CopyBlockHorVerLoop(2)
- CopyBlockHorVerLoop(3)
- CopyBlockHorVerLoop(4)
- CopyBlockHorVerLoop(5)
- CopyBlockHorVerLoop(6)
- CopyBlockHorVerLoop(7)
- CopyBlockHorVerLoop(8)
- CopyBlockHorVerLoop(9)
- CopyBlockHorVerLoop(10)
- CopyBlockHorVerLoop(11)
- CopyBlockHorVerLoop(12)
- CopyBlockHorVerLoop(13)
- CopyBlockHorVerLoop(14)
- CopyBlockHorVerLoop(15)
- "addl %%ebx, %%esin"
- "addl %%ebx, %%edin"
- "decl %%edxn"
- "jnz 1bn"
- "popl %%ebxn"
- :
- : "a"(0), "g"(Stride), "c" (0), "d" (16), "g" (Src), "g" (Dst)
- : "esi", "edi"
- );
- }
- void CopyMBlockHorVerRound(unsigned char * Src, unsigned char * Dst, int Stride)
- {
- __asm__
- (
- "movl %1, %%eaxn"
- "movl %4, %%esin"
- "movl %5, %%edin"
- "pushl %%ebxn"
- "movl %%eax, %%ebxn"
- "xorl %%eax, %%eaxn"
- "1:n"
- CopyBlockHorVerLoopRound(0)
- CopyBlockHorVerLoopRound(1)
- CopyBlockHorVerLoopRound(2)
- CopyBlockHorVerLoopRound(3)
- CopyBlockHorVerLoopRound(4)
- CopyBlockHorVerLoopRound(5)
- CopyBlockHorVerLoopRound(6)
- CopyBlockHorVerLoopRound(7)
- CopyBlockHorVerLoopRound(8)
- CopyBlockHorVerLoopRound(9)
- CopyBlockHorVerLoopRound(10)
- CopyBlockHorVerLoopRound(11)
- CopyBlockHorVerLoopRound(12)
- CopyBlockHorVerLoopRound(13)
- CopyBlockHorVerLoopRound(14)
- CopyBlockHorVerLoopRound(15)
- "addl %%ebx, %%esin"
- "addl %%ebx, %%edin"
- "decl %%edxn"
- "jnz 1bn"
- "popl %%ebxn"
- :
- : "a"(0), "g"(Stride), "c" (0), "d" (16), "g" (Src), "g" (Dst)
- : "esi", "edi"
- );
- }