📄 dsp_mmx.c
字号:
/******************************************************************** * * * THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. * * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * * * * THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2003 * * by the Xiph.Org Foundation http://www.xiph.org/ * * * ******************************************************************** function: last mod: $Id: dsp_mmx.c 11582 2006-06-16 10:57:19Z msmith $ ********************************************************************/#include <stdlib.h>#include "codec_internal.h"#include "dsp.h"static const __attribute__ ((aligned(8),used)) ogg_int64_t V128 = 0x0080008000800080LL;#define DSP_OP_AVG(a,b) ((((int)(a)) + ((int)(b)))/2)#define DSP_OP_DIFF(a,b) (((int)(a)) - ((int)(b)))#define DSP_OP_ABS_DIFF(a,b) abs((((int)(a)) - ((int)(b))))static void sub8x8__mmx (unsigned char *FiltPtr, unsigned char *ReconPtr, ogg_int16_t *DctInputPtr, ogg_uint32_t PixelsPerLine, ogg_uint32_t ReconPixelsPerLine) { __asm__ __volatile__ ( " .balign 16 \n\t" " pxor %%mm7, %%mm7 \n\t" ".rept 8 \n\t" " movq (%0), %%mm0 \n\t" /* mm0 = FiltPtr */ " movq (%1), %%mm1 \n\t" /* mm1 = ReconPtr */ " movq %%mm0, %%mm2 \n\t" /* dup to prepare for up conversion */ " movq %%mm1, %%mm3 \n\t" /* dup to prepare for up conversion */ /* convert from UINT8 to INT16 */ " punpcklbw %%mm7, %%mm0 \n\t" /* mm0 = INT16(FiltPtr) */ " punpcklbw %%mm7, %%mm1 \n\t" /* mm1 = INT16(ReconPtr) */ " punpckhbw %%mm7, %%mm2 \n\t" /* mm2 = INT16(FiltPtr) */ " punpckhbw %%mm7, %%mm3 \n\t" /* mm3 = INT16(ReconPtr) */ /* start calculation */ " psubw %%mm1, %%mm0 \n\t" /* mm0 = FiltPtr - ReconPtr */ " psubw %%mm3, %%mm2 \n\t" /* mm2 = FiltPtr - ReconPtr */ " movq %%mm0, (%2) \n\t" /* write answer out */ " movq %%mm2, 8(%2) \n\t" /* write answer out */ /* Increment pointers */ " add $16, %2 \n\t" " add %3, %0 \n\t" " add %4, %1 \n\t" ".endr \n\t" : "+r" (FiltPtr), "+r" (ReconPtr), "+r" (DctInputPtr) : "m" (PixelsPerLine), "m" (ReconPixelsPerLine) : "memory" );}static void sub8x8_128__mmx (unsigned char *FiltPtr, ogg_int16_t *DctInputPtr, ogg_uint32_t PixelsPerLine) { __asm__ __volatile__ ( " .balign 16 \n\t" " pxor %%mm7, %%mm7 \n\t" " movq %[V128], %%mm1 \n\t" ".rept 8 \n\t" " movq (%0), %%mm0 \n\t" /* mm0 = FiltPtr */ " movq %%mm0, %%mm2 \n\t" /* dup to prepare for up conversion */ /* convert from UINT8 to INT16 */ " punpcklbw %%mm7, %%mm0 \n\t" /* mm0 = INT16(FiltPtr) */ " punpckhbw %%mm7, %%mm2 \n\t" /* mm2 = INT16(FiltPtr) */ /* start calculation */ " psubw %%mm1, %%mm0 \n\t" /* mm0 = FiltPtr - 128 */ " psubw %%mm1, %%mm2 \n\t" /* mm2 = FiltPtr - 128 */ " movq %%mm0, (%1) \n\t" /* write answer out */ " movq %%mm2, 8(%1) \n\t" /* write answer out */ /* Increment pointers */ " add $16, %1 \n\t" " add %2, %0 \n\t" ".endr \n\t" : "+r" (FiltPtr), "+r" (DctInputPtr) : "m" (PixelsPerLine), [V128] "m" (V128) : "memory" );}static void sub8x8avg2__mmx (unsigned char *FiltPtr, unsigned char *ReconPtr1, unsigned char *ReconPtr2, ogg_int16_t *DctInputPtr, ogg_uint32_t PixelsPerLine, ogg_uint32_t ReconPixelsPerLine) { __asm__ __volatile__ ( " .balign 16 \n\t" " pxor %%mm7, %%mm7 \n\t" ".rept 8 \n\t" " movq (%0), %%mm0 \n\t" /* mm0 = FiltPtr */ " movq (%1), %%mm1 \n\t" /* mm1 = ReconPtr1 */ " movq (%2), %%mm4 \n\t" /* mm1 = ReconPtr2 */ " movq %%mm0, %%mm2 \n\t" /* dup to prepare for up conversion */ " movq %%mm1, %%mm3 \n\t" /* dup to prepare for up conversion */ " movq %%mm4, %%mm5 \n\t" /* dup to prepare for up conversion */ /* convert from UINT8 to INT16 */ " punpcklbw %%mm7, %%mm0 \n\t" /* mm0 = INT16(FiltPtr) */ " punpcklbw %%mm7, %%mm1 \n\t" /* mm1 = INT16(ReconPtr1) */ " punpcklbw %%mm7, %%mm4 \n\t" /* mm1 = INT16(ReconPtr2) */ " punpckhbw %%mm7, %%mm2 \n\t" /* mm2 = INT16(FiltPtr) */ " punpckhbw %%mm7, %%mm3 \n\t" /* mm3 = INT16(ReconPtr1) */ " punpckhbw %%mm7, %%mm5 \n\t" /* mm3 = INT16(ReconPtr2) */ /* average ReconPtr1 and ReconPtr2 */ " paddw %%mm4, %%mm1 \n\t" /* mm1 = ReconPtr1 + ReconPtr2 */ " paddw %%mm5, %%mm3 \n\t" /* mm3 = ReconPtr1 + ReconPtr2 */ " psrlw $1, %%mm1 \n\t" /* mm1 = (ReconPtr1 + ReconPtr2) / 2 */ " psrlw $1, %%mm3 \n\t" /* mm3 = (ReconPtr1 + ReconPtr2) / 2 */ " psubw %%mm1, %%mm0 \n\t" /* mm0 = FiltPtr - ((ReconPtr1 + ReconPtr2) / 2) */ " psubw %%mm3, %%mm2 \n\t" /* mm2 = FiltPtr - ((ReconPtr1 + ReconPtr2) / 2) */ " movq %%mm0, (%3) \n\t" /* write answer out */ " movq %%mm2, 8(%3) \n\t" /* write answer out */ /* Increment pointers */ " add $16, %3 \n\t" " add %4, %0 \n\t" " add %5, %1 \n\t" " add %5, %2 \n\t" ".endr \n\t" : "+r" (FiltPtr), "+r" (ReconPtr1), "+r" (ReconPtr2), "+r" (DctInputPtr) : "m" (PixelsPerLine), "m" (ReconPixelsPerLine) : "memory" );}static ogg_uint32_t row_sad8__mmx (unsigned char *Src1, unsigned char *Src2){ ogg_uint32_t MaxSad; __asm__ __volatile__ ( " .balign 16 \n\t" " pxor %%mm6, %%mm6 \n\t" /* zero out mm6 for unpack */ " pxor %%mm7, %%mm7 \n\t" /* zero out mm7 for unpack */ " movq (%1), %%mm0 \n\t" /* take 8 bytes */ " movq (%2), %%mm1 \n\t" " movq %%mm0, %%mm2 \n\t" " psubusb %%mm1, %%mm0 \n\t" /* A - B */ " psubusb %%mm2, %%mm1 \n\t" /* B - A */ " por %%mm1, %%mm0 \n\t" /* and or gives abs difference */ " movq %%mm0, %%mm1 \n\t" " punpcklbw %%mm6, %%mm0 \n\t" /* ; unpack low four bytes to higher precision */ " punpckhbw %%mm7, %%mm1 \n\t" /* ; unpack high four bytes to higher precision */ " movq %%mm0, %%mm2 \n\t" " movq %%mm1, %%mm3 \n\t" " psrlq $32, %%mm2 \n\t" /* fold and add */ " psrlq $32, %%mm3 \n\t" " paddw %%mm2, %%mm0 \n\t" " paddw %%mm3, %%mm1 \n\t" " movq %%mm0, %%mm2 \n\t" " movq %%mm1, %%mm3 \n\t" " psrlq $16, %%mm2 \n\t" " psrlq $16, %%mm3 \n\t" " paddw %%mm2, %%mm0 \n\t" " paddw %%mm3, %%mm1 \n\t" " psubusw %%mm0, %%mm1 \n\t" " paddw %%mm0, %%mm1 \n\t" /* mm1 = max(mm1, mm0) */ " movd %%mm1, %0 \n\t" " andl $0xffff, %0 \n\t" : "=m" (MaxSad), "+r" (Src1), "+r" (Src2) : : "memory" ); return MaxSad;}static ogg_uint32_t col_sad8x8__mmx (unsigned char *Src1, unsigned char *Src2, ogg_uint32_t stride){ ogg_uint32_t MaxSad; __asm__ __volatile__ ( " .balign 16 \n\t" " pxor %%mm3, %%mm3 \n\t" /* zero out mm3 for unpack */ " pxor %%mm4, %%mm4 \n\t" /* mm4 low sum */ " pxor %%mm5, %%mm5 \n\t" /* mm5 high sum */ " pxor %%mm6, %%mm6 \n\t" /* mm6 low sum */ " pxor %%mm7, %%mm7 \n\t" /* mm7 high sum */ " mov $4, %%edi \n\t" /* 4 rows */ "1: \n\t" " movq (%1), %%mm0 \n\t" /* take 8 bytes */ " movq (%2), %%mm1 \n\t" /* take 8 bytes */ " movq %%mm0, %%mm2 \n\t" " psubusb %%mm1, %%mm0 \n\t" /* A - B */ " psubusb %%mm2, %%mm1 \n\t" /* B - A */ " por %%mm1, %%mm0 \n\t" /* and or gives abs difference */ " movq %%mm0, %%mm1 \n\t" " punpcklbw %%mm3, %%mm0 \n\t" /* unpack to higher precision for accumulation */ " paddw %%mm0, %%mm4 \n\t" /* accumulate difference... */ " punpckhbw %%mm3, %%mm1 \n\t" /* unpack high four bytes to higher precision */ " paddw %%mm1, %%mm5 \n\t" /* accumulate difference... */ " add %3, %1 \n\t" /* Inc pointer into the new data */ " add %3, %2 \n\t" /* Inc pointer into the new data */ " dec %%edi \n\t" " jnz 1b \n\t" " mov $4, %%edi \n\t" /* 4 rows */ "2: \n\t" " movq (%1), %%mm0 \n\t" /* take 8 bytes */ " movq (%2), %%mm1 \n\t" /* take 8 bytes */ " movq %%mm0, %%mm2 \n\t" " psubusb %%mm1, %%mm0 \n\t" /* A - B */ " psubusb %%mm2, %%mm1 \n\t" /* B - A */ " por %%mm1, %%mm0 \n\t" /* and or gives abs difference */ " movq %%mm0, %%mm1 \n\t" " punpcklbw %%mm3, %%mm0 \n\t" /* unpack to higher precision for accumulation */ " paddw %%mm0, %%mm6 \n\t" /* accumulate difference... */ " punpckhbw %%mm3, %%mm1 \n\t" /* unpack high four bytes to higher precision */ " paddw %%mm1, %%mm7 \n\t" /* accumulate difference... */ " add %3, %1 \n\t" /* Inc pointer into the new data */ " add %3, %2 \n\t" /* Inc pointer into the new data */ " dec %%edi \n\t" " jnz 2b \n\t" " psubusw %%mm6, %%mm7 \n\t" " paddw %%mm6, %%mm7 \n\t" /* mm7 = max(mm7, mm6) */ " psubusw %%mm4, %%mm5 \n\t" " paddw %%mm4, %%mm5 \n\t" /* mm5 = max(mm5, mm4) */ " psubusw %%mm5, %%mm7 \n\t" " paddw %%mm5, %%mm7 \n\t" /* mm7 = max(mm5, mm7) */ " movq %%mm7, %%mm6 \n\t" " psrlq $32, %%mm6 \n\t" " psubusw %%mm6, %%mm7 \n\t" " paddw %%mm6, %%mm7 \n\t" /* mm7 = max(mm5, mm7) */ " movq %%mm7, %%mm6 \n\t" " psrlq $16, %%mm6 \n\t" " psubusw %%mm6, %%mm7 \n\t" " paddw %%mm6, %%mm7 \n\t" /* mm7 = max(mm5, mm7) */ " movd %%mm7, %0 \n\t" " andl $0xffff, %0 \n\t" : "=r" (MaxSad), "+r" (Src1), "+r" (Src2) : "r" (stride) : "memory", "edi" ); return MaxSad;}static ogg_uint32_t sad8x8__mmx (unsigned char *ptr1, ogg_uint32_t stride1, unsigned char *ptr2, ogg_uint32_t stride2){ ogg_uint32_t DiffVal; __asm__ __volatile__ ( " .balign 16 \n\t" " pxor %%mm6, %%mm6 \n\t" /* zero out mm6 for unpack */ " pxor %%mm7, %%mm7 \n\t" /* mm7 contains the result */ ".rept 8 \n\t" " movq (%1), %%mm0 \n\t" /* take 8 bytes */ " movq (%2), %%mm1 \n\t" " movq %%mm0, %%mm2 \n\t" " psubusb %%mm1, %%mm0 \n\t" /* A - B */ " psubusb %%mm2, %%mm1 \n\t" /* B - A */ " por %%mm1, %%mm0 \n\t" /* and or gives abs difference */ " movq %%mm0, %%mm1 \n\t" " punpcklbw %%mm6, %%mm0 \n\t" /* unpack to higher precision for accumulation */ " paddw %%mm0, %%mm7 \n\t" /* accumulate difference... */ " punpckhbw %%mm6, %%mm1 \n\t" /* unpack high four bytes to higher precision */ " add %3, %1 \n\t" /* Inc pointer into the new data */ " paddw %%mm1, %%mm7 \n\t" /* accumulate difference... */ " add %4, %2 \n\t" /* Inc pointer into ref data */ ".endr \n\t" " movq %%mm7, %%mm0 \n\t" " psrlq $32, %%mm7 \n\t" " paddw %%mm0, %%mm7 \n\t" " movq %%mm7, %%mm0 \n\t" " psrlq $16, %%mm7 \n\t" " paddw %%mm0, %%mm7 \n\t" " movd %%mm7, %0 \n\t" " andl $0xffff, %0 \n\t" : "=m" (DiffVal), "+r" (ptr1), "+r" (ptr2)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -