2005-05-25 08:05:41 +00:00
|
|
|
/*
|
2005-10-27 06:45:29 +00:00
|
|
|
* Copyright (c) 2005 Zoltan Hidvegi <hzoli -a- hzoli -d- com>,
|
|
|
|
* Loren Merritt
|
2005-05-25 08:05:41 +00:00
|
|
|
*
|
2006-10-07 15:30:46 +00:00
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
2005-05-25 08:05:41 +00:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2006-10-07 15:30:46 +00:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2005-05-25 08:05:41 +00:00
|
|
|
*
|
2006-10-07 15:30:46 +00:00
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
2005-05-25 08:05:41 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2006-10-07 15:30:46 +00:00
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
2006-01-12 22:43:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2005-05-25 08:05:41 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* MMX optimized version of (put|avg)_h264_chroma_mc8.
|
2005-10-27 06:45:29 +00:00
|
|
|
* H264_CHROMA_MC8_TMPL must be defined to the desired function name
|
|
|
|
* H264_CHROMA_OP must be defined to empty for put and pavgb/pavgusb for avg
|
|
|
|
* H264_CHROMA_MC8_MV0 must be defined to a (put|avg)_pixels8 function
|
2005-05-25 08:05:41 +00:00
|
|
|
*/
|
|
|
|
static void H264_CHROMA_MC8_TMPL(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y)
|
|
|
|
{
|
2006-02-05 13:35:17 +00:00
|
|
|
DECLARE_ALIGNED_8(uint64_t, AA);
|
|
|
|
DECLARE_ALIGNED_8(uint64_t, DD);
|
2005-05-25 08:05:41 +00:00
|
|
|
int i;
|
|
|
|
|
2005-10-27 06:45:29 +00:00
|
|
|
if(y==0 && x==0) {
|
|
|
|
/* no filter needed */
|
|
|
|
H264_CHROMA_MC8_MV0(dst, src, stride, h);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-05-25 08:05:41 +00:00
|
|
|
assert(x<8 && y<8 && x>=0 && y>=0);
|
|
|
|
|
2006-03-25 08:41:14 +00:00
|
|
|
if(y==0 || x==0)
|
2005-10-27 06:45:29 +00:00
|
|
|
{
|
2006-03-25 08:41:14 +00:00
|
|
|
/* 1 dimensional filter only */
|
|
|
|
const int dxy = x ? 1 : stride;
|
|
|
|
|
|
|
|
asm volatile(
|
|
|
|
"movd %0, %%mm5\n\t"
|
|
|
|
"movq %1, %%mm4\n\t"
|
|
|
|
"punpcklwd %%mm5, %%mm5\n\t"
|
|
|
|
"punpckldq %%mm5, %%mm5\n\t" /* mm5 = B = x */
|
|
|
|
"movq %%mm4, %%mm6\n\t"
|
|
|
|
"pxor %%mm7, %%mm7\n\t"
|
|
|
|
"psubw %%mm5, %%mm4\n\t" /* mm4 = A = 8-x */
|
|
|
|
"psrlw $1, %%mm6\n\t" /* mm6 = 4 */
|
|
|
|
:: "rm"(x+y), "m"(ff_pw_8));
|
2005-10-27 06:45:29 +00:00
|
|
|
|
|
|
|
for(i=0; i<h; i++) {
|
|
|
|
asm volatile(
|
|
|
|
/* mm0 = src[0..7], mm1 = src[1..8] */
|
|
|
|
"movq %0, %%mm0\n\t"
|
2006-03-25 08:41:14 +00:00
|
|
|
"movq %1, %%mm2\n\t"
|
|
|
|
:: "m"(src[0]), "m"(src[dxy]));
|
2005-10-27 06:45:29 +00:00
|
|
|
|
|
|
|
asm volatile(
|
2006-03-25 08:41:14 +00:00
|
|
|
/* [mm0,mm1] = A * src[0..7] */
|
|
|
|
/* [mm2,mm3] = B * src[1..8] */
|
|
|
|
"movq %%mm0, %%mm1\n\t"
|
|
|
|
"movq %%mm2, %%mm3\n\t"
|
2005-10-27 06:45:29 +00:00
|
|
|
"punpcklbw %%mm7, %%mm0\n\t"
|
|
|
|
"punpckhbw %%mm7, %%mm1\n\t"
|
2006-03-25 08:41:14 +00:00
|
|
|
"punpcklbw %%mm7, %%mm2\n\t"
|
|
|
|
"punpckhbw %%mm7, %%mm3\n\t"
|
|
|
|
"pmullw %%mm4, %%mm0\n\t"
|
|
|
|
"pmullw %%mm4, %%mm1\n\t"
|
|
|
|
"pmullw %%mm5, %%mm2\n\t"
|
|
|
|
"pmullw %%mm5, %%mm3\n\t"
|
|
|
|
|
|
|
|
/* dst[0..7] = (A * src[0..7] + B * src[1..8] + 4) >> 3 */
|
|
|
|
"paddw %%mm6, %%mm0\n\t"
|
|
|
|
"paddw %%mm6, %%mm1\n\t"
|
|
|
|
"paddw %%mm2, %%mm0\n\t"
|
|
|
|
"paddw %%mm3, %%mm1\n\t"
|
|
|
|
"psrlw $3, %%mm0\n\t"
|
|
|
|
"psrlw $3, %%mm1\n\t"
|
|
|
|
"packuswb %%mm1, %%mm0\n\t"
|
|
|
|
H264_CHROMA_OP(%0, %%mm0)
|
|
|
|
"movq %%mm0, %0\n\t"
|
|
|
|
: "=m" (dst[0]));
|
2005-10-27 06:45:29 +00:00
|
|
|
|
|
|
|
src += stride;
|
|
|
|
dst += stride;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* general case, bilinear */
|
|
|
|
asm volatile("movd %2, %%mm4\n\t"
|
|
|
|
"movd %3, %%mm6\n\t"
|
2005-05-25 08:05:41 +00:00
|
|
|
"punpcklwd %%mm4, %%mm4\n\t"
|
|
|
|
"punpcklwd %%mm6, %%mm6\n\t"
|
|
|
|
"punpckldq %%mm4, %%mm4\n\t" /* mm4 = x words */
|
|
|
|
"punpckldq %%mm6, %%mm6\n\t" /* mm6 = y words */
|
|
|
|
"movq %%mm4, %%mm5\n\t"
|
|
|
|
"pmullw %%mm6, %%mm4\n\t" /* mm4 = x * y */
|
|
|
|
"psllw $3, %%mm5\n\t"
|
|
|
|
"psllw $3, %%mm6\n\t"
|
|
|
|
"movq %%mm5, %%mm7\n\t"
|
|
|
|
"paddw %%mm6, %%mm7\n\t"
|
2005-10-27 06:45:29 +00:00
|
|
|
"movq %%mm4, %1\n\t" /* DD = x * y */
|
2005-05-25 08:05:41 +00:00
|
|
|
"psubw %%mm4, %%mm5\n\t" /* mm5 = B = 8x - xy */
|
|
|
|
"psubw %%mm4, %%mm6\n\t" /* mm6 = C = 8y - xy */
|
2005-10-27 06:45:29 +00:00
|
|
|
"paddw %4, %%mm4\n\t"
|
2005-05-25 08:05:41 +00:00
|
|
|
"psubw %%mm7, %%mm4\n\t" /* mm4 = A = xy - (8x+8y) + 64 */
|
|
|
|
"pxor %%mm7, %%mm7\n\t"
|
2005-10-27 06:45:29 +00:00
|
|
|
"movq %%mm4, %0\n\t"
|
|
|
|
: "=m" (AA), "=m" (DD) : "rm" (x), "rm" (y), "m" (ff_pw_64));
|
2005-05-25 08:05:41 +00:00
|
|
|
|
|
|
|
asm volatile(
|
|
|
|
/* mm0 = src[0..7], mm1 = src[1..8] */
|
2005-10-27 06:45:29 +00:00
|
|
|
"movq %0, %%mm0\n\t"
|
|
|
|
"movq %1, %%mm1\n\t"
|
|
|
|
: : "m" (src[0]), "m" (src[1]));
|
2005-05-25 08:05:41 +00:00
|
|
|
|
|
|
|
for(i=0; i<h; i++) {
|
2006-03-25 08:41:14 +00:00
|
|
|
src += stride;
|
|
|
|
|
2005-05-25 08:05:41 +00:00
|
|
|
asm volatile(
|
2006-03-25 08:41:14 +00:00
|
|
|
/* mm2 = A * src[0..3] + B * src[1..4] */
|
|
|
|
/* mm3 = A * src[4..7] + B * src[5..8] */
|
2005-05-25 08:05:41 +00:00
|
|
|
"movq %%mm0, %%mm2\n\t"
|
2006-03-25 08:41:14 +00:00
|
|
|
"movq %%mm1, %%mm3\n\t"
|
|
|
|
"punpckhbw %%mm7, %%mm0\n\t"
|
|
|
|
"punpcklbw %%mm7, %%mm1\n\t"
|
2005-05-25 08:05:41 +00:00
|
|
|
"punpcklbw %%mm7, %%mm2\n\t"
|
|
|
|
"punpckhbw %%mm7, %%mm3\n\t"
|
2006-03-25 08:41:14 +00:00
|
|
|
"pmullw %0, %%mm0\n\t"
|
|
|
|
"pmullw %0, %%mm2\n\t"
|
|
|
|
"pmullw %%mm5, %%mm1\n\t"
|
|
|
|
"pmullw %%mm5, %%mm3\n\t"
|
|
|
|
"paddw %%mm1, %%mm2\n\t"
|
|
|
|
"paddw %%mm0, %%mm3\n\t"
|
|
|
|
: : "m" (AA));
|
2005-05-25 08:05:41 +00:00
|
|
|
|
2006-03-25 08:41:14 +00:00
|
|
|
asm volatile(
|
|
|
|
/* [mm2,mm3] += C * src[0..7] */
|
|
|
|
"movq %0, %%mm0\n\t"
|
|
|
|
"movq %%mm0, %%mm1\n\t"
|
2005-05-25 08:05:41 +00:00
|
|
|
"punpcklbw %%mm7, %%mm0\n\t"
|
|
|
|
"punpckhbw %%mm7, %%mm1\n\t"
|
2006-03-25 08:41:14 +00:00
|
|
|
"pmullw %%mm6, %%mm0\n\t"
|
|
|
|
"pmullw %%mm6, %%mm1\n\t"
|
2005-05-25 08:05:41 +00:00
|
|
|
"paddw %%mm0, %%mm2\n\t"
|
|
|
|
"paddw %%mm1, %%mm3\n\t"
|
2006-03-25 08:41:14 +00:00
|
|
|
: : "m" (src[0]));
|
2005-05-25 08:05:41 +00:00
|
|
|
|
|
|
|
asm volatile(
|
2006-03-25 08:41:14 +00:00
|
|
|
/* [mm2,mm3] += D * src[1..8] */
|
2005-10-27 06:45:29 +00:00
|
|
|
"movq %1, %%mm1\n\t"
|
2006-03-25 08:41:14 +00:00
|
|
|
"movq %%mm1, %%mm0\n\t"
|
2005-05-25 08:05:41 +00:00
|
|
|
"movq %%mm1, %%mm4\n\t"
|
2006-03-25 08:41:14 +00:00
|
|
|
"punpcklbw %%mm7, %%mm0\n\t"
|
2005-05-25 08:05:41 +00:00
|
|
|
"punpckhbw %%mm7, %%mm4\n\t"
|
2006-03-25 08:41:14 +00:00
|
|
|
"pmullw %2, %%mm0\n\t"
|
|
|
|
"pmullw %2, %%mm4\n\t"
|
|
|
|
"paddw %%mm0, %%mm2\n\t"
|
2005-05-25 08:05:41 +00:00
|
|
|
"paddw %%mm4, %%mm3\n\t"
|
2006-03-25 08:41:14 +00:00
|
|
|
"movq %0, %%mm0\n\t"
|
|
|
|
: : "m" (src[0]), "m" (src[1]), "m" (DD));
|
2005-05-25 08:05:41 +00:00
|
|
|
|
|
|
|
asm volatile(
|
2006-03-25 08:41:14 +00:00
|
|
|
/* dst[0..7] = ([mm2,mm3] + 32) >> 6 */
|
2005-05-25 08:05:41 +00:00
|
|
|
"paddw %1, %%mm2\n\t"
|
|
|
|
"paddw %1, %%mm3\n\t"
|
|
|
|
"psrlw $6, %%mm2\n\t"
|
|
|
|
"psrlw $6, %%mm3\n\t"
|
|
|
|
"packuswb %%mm3, %%mm2\n\t"
|
|
|
|
H264_CHROMA_OP(%0, %%mm2)
|
|
|
|
"movq %%mm2, %0\n\t"
|
2005-06-02 20:45:35 +00:00
|
|
|
: "=m" (dst[0]) : "m" (ff_pw_32));
|
2005-05-25 08:05:41 +00:00
|
|
|
dst+= stride;
|
|
|
|
}
|
|
|
|
}
|
2005-10-27 06:45:29 +00:00
|
|
|
|
2006-03-22 22:05:00 +00:00
|
|
|
static void H264_CHROMA_MC4_TMPL(uint8_t *dst/*align 4*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y)
|
2005-10-27 06:45:29 +00:00
|
|
|
{
|
|
|
|
asm volatile(
|
2007-02-17 23:43:02 +00:00
|
|
|
"pxor %%mm7, %%mm7 \n\t"
|
|
|
|
"movd %5, %%mm2 \n\t"
|
|
|
|
"movd %6, %%mm3 \n\t"
|
2007-02-22 00:04:36 +00:00
|
|
|
"movq "MANGLE(ff_pw_8)", %%mm4\n\t"
|
|
|
|
"movq "MANGLE(ff_pw_8)", %%mm5\n\t"
|
2007-02-17 23:43:02 +00:00
|
|
|
"punpcklwd %%mm2, %%mm2 \n\t"
|
|
|
|
"punpcklwd %%mm3, %%mm3 \n\t"
|
|
|
|
"punpcklwd %%mm2, %%mm2 \n\t"
|
|
|
|
"punpcklwd %%mm3, %%mm3 \n\t"
|
|
|
|
"psubw %%mm2, %%mm4 \n\t"
|
|
|
|
"psubw %%mm3, %%mm5 \n\t"
|
2005-10-27 06:45:29 +00:00
|
|
|
|
2007-02-17 23:43:02 +00:00
|
|
|
"movd (%1), %%mm0 \n\t"
|
|
|
|
"movd 1(%1), %%mm6 \n\t"
|
|
|
|
"add %3, %1 \n\t"
|
|
|
|
"punpcklbw %%mm7, %%mm0 \n\t"
|
|
|
|
"punpcklbw %%mm7, %%mm6 \n\t"
|
|
|
|
"pmullw %%mm4, %%mm0 \n\t"
|
|
|
|
"pmullw %%mm2, %%mm6 \n\t"
|
|
|
|
"paddw %%mm0, %%mm6 \n\t"
|
2005-10-27 06:45:29 +00:00
|
|
|
|
2007-02-17 23:43:02 +00:00
|
|
|
"1: \n\t"
|
|
|
|
"movd (%1), %%mm0 \n\t"
|
|
|
|
"movd 1(%1), %%mm1 \n\t"
|
|
|
|
"add %3, %1 \n\t"
|
|
|
|
"punpcklbw %%mm7, %%mm0 \n\t"
|
|
|
|
"punpcklbw %%mm7, %%mm1 \n\t"
|
|
|
|
"pmullw %%mm4, %%mm0 \n\t"
|
|
|
|
"pmullw %%mm2, %%mm1 \n\t"
|
|
|
|
"paddw %%mm0, %%mm1 \n\t"
|
|
|
|
"movq %%mm1, %%mm0 \n\t"
|
|
|
|
"pmullw %%mm5, %%mm6 \n\t"
|
|
|
|
"pmullw %%mm3, %%mm1 \n\t"
|
2007-02-23 15:44:56 +00:00
|
|
|
"paddw %4, %%mm6 \n\t"
|
2007-02-17 23:43:02 +00:00
|
|
|
"paddw %%mm6, %%mm1 \n\t"
|
|
|
|
"psrlw $6, %%mm1 \n\t"
|
|
|
|
"packuswb %%mm1, %%mm1 \n\t"
|
|
|
|
H264_CHROMA_OP4((%0), %%mm1, %%mm6)
|
|
|
|
"movd %%mm1, (%0) \n\t"
|
|
|
|
"add %3, %0 \n\t"
|
|
|
|
"movd (%1), %%mm6 \n\t"
|
|
|
|
"movd 1(%1), %%mm1 \n\t"
|
|
|
|
"add %3, %1 \n\t"
|
|
|
|
"punpcklbw %%mm7, %%mm6 \n\t"
|
|
|
|
"punpcklbw %%mm7, %%mm1 \n\t"
|
|
|
|
"pmullw %%mm4, %%mm6 \n\t"
|
|
|
|
"pmullw %%mm2, %%mm1 \n\t"
|
|
|
|
"paddw %%mm6, %%mm1 \n\t"
|
|
|
|
"movq %%mm1, %%mm6 \n\t"
|
|
|
|
"pmullw %%mm5, %%mm0 \n\t"
|
|
|
|
"pmullw %%mm3, %%mm1 \n\t"
|
2007-02-23 15:44:56 +00:00
|
|
|
"paddw %4, %%mm0 \n\t"
|
2007-02-17 23:43:02 +00:00
|
|
|
"paddw %%mm0, %%mm1 \n\t"
|
|
|
|
"psrlw $6, %%mm1 \n\t"
|
|
|
|
"packuswb %%mm1, %%mm1 \n\t"
|
|
|
|
H264_CHROMA_OP4((%0), %%mm1, %%mm0)
|
|
|
|
"movd %%mm1, (%0) \n\t"
|
|
|
|
"add %3, %0 \n\t"
|
|
|
|
"sub $2, %2 \n\t"
|
|
|
|
"jnz 1b \n\t"
|
|
|
|
: "+r"(dst), "+r"(src), "+r"(h)
|
2007-02-22 00:04:36 +00:00
|
|
|
: "r"((long)stride), "m"(ff_pw_32), "m"(x), "m"(y)
|
2007-02-17 23:43:02 +00:00
|
|
|
);
|
2005-10-27 06:45:29 +00:00
|
|
|
}
|
2006-03-22 22:05:00 +00:00
|
|
|
|
|
|
|
#ifdef H264_CHROMA_MC2_TMPL
|
2007-06-16 14:51:57 +00:00
|
|
|
static void H264_CHROMA_MC2_TMPL(uint8_t *dst/*align 2*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y)
|
2006-03-22 22:05:00 +00:00
|
|
|
{
|
2007-02-09 12:37:38 +00:00
|
|
|
int tmp = ((1<<16)-1)*x + 8;
|
|
|
|
int CD= tmp*y;
|
|
|
|
int AB= (tmp<<3) - CD;
|
2006-03-22 22:05:00 +00:00
|
|
|
asm volatile(
|
|
|
|
/* mm5 = {A,B,A,B} */
|
|
|
|
/* mm6 = {C,D,C,D} */
|
|
|
|
"movd %0, %%mm5\n\t"
|
|
|
|
"movd %1, %%mm6\n\t"
|
|
|
|
"punpckldq %%mm5, %%mm5\n\t"
|
|
|
|
"punpckldq %%mm6, %%mm6\n\t"
|
|
|
|
"pxor %%mm7, %%mm7\n\t"
|
|
|
|
/* mm0 = src[0,1,1,2] */
|
2007-02-23 15:03:30 +00:00
|
|
|
"movd %2, %%mm2\n\t"
|
|
|
|
"punpcklbw %%mm7, %%mm2\n\t"
|
|
|
|
"pshufw $0x94, %%mm2, %%mm2\n\t"
|
2007-02-09 12:24:22 +00:00
|
|
|
:: "r"(AB), "r"(CD), "m"(src[0]));
|
2006-03-22 22:05:00 +00:00
|
|
|
|
|
|
|
|
2007-02-09 12:24:22 +00:00
|
|
|
asm volatile(
|
|
|
|
"1:\n\t"
|
2007-02-10 13:33:08 +00:00
|
|
|
"add %4, %1\n\t"
|
2007-02-09 12:24:22 +00:00
|
|
|
/* mm1 = A * src[0,1] + B * src[1,2] */
|
2007-02-23 15:03:30 +00:00
|
|
|
"movq %%mm2, %%mm1\n\t"
|
2007-02-09 12:24:22 +00:00
|
|
|
"pmaddwd %%mm5, %%mm1\n\t"
|
|
|
|
/* mm0 = src[0,1,1,2] */
|
|
|
|
"movd (%1), %%mm0\n\t"
|
|
|
|
"punpcklbw %%mm7, %%mm0\n\t"
|
|
|
|
"pshufw $0x94, %%mm0, %%mm0\n\t"
|
|
|
|
/* mm1 += C * src[0,1] + D * src[1,2] */
|
|
|
|
"movq %%mm0, %%mm2\n\t"
|
2007-02-23 15:03:30 +00:00
|
|
|
"pmaddwd %%mm6, %%mm0\n\t"
|
2007-02-23 15:28:35 +00:00
|
|
|
"paddw %3, %%mm1\n\t"
|
2007-02-23 15:03:30 +00:00
|
|
|
"paddw %%mm0, %%mm1\n\t"
|
2007-02-09 12:24:22 +00:00
|
|
|
/* dst[0,1] = pack((mm1 + 32) >> 6) */
|
|
|
|
"psrlw $6, %%mm1\n\t"
|
|
|
|
"packssdw %%mm7, %%mm1\n\t"
|
|
|
|
"packuswb %%mm7, %%mm1\n\t"
|
|
|
|
H264_CHROMA_OP4((%0), %%mm1, %%mm3)
|
2007-02-23 14:29:13 +00:00
|
|
|
"movd %%mm1, %%esi\n\t"
|
|
|
|
"movw %%si, (%0)\n\t"
|
2007-02-10 03:56:49 +00:00
|
|
|
"add %4, %0\n\t"
|
|
|
|
"sub $1, %2\n\t"
|
2007-02-09 12:24:22 +00:00
|
|
|
"jnz 1b\n\t"
|
2007-02-23 14:29:13 +00:00
|
|
|
: "+r" (dst), "+r"(src), "+r"(h)
|
2007-06-16 14:51:57 +00:00
|
|
|
: "m" (ff_pw_32), "r"((long)stride)
|
2007-02-23 14:29:13 +00:00
|
|
|
: "%esi");
|
2006-03-22 22:05:00 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|