2010-12-12 19:59:10 +02:00
|
|
|
/*
|
2011-07-04 01:47:10 +03:00
|
|
|
* Copyright (C) 2009 Loren Merritt <lorenm@u.washignton.edu>
|
|
|
|
*
|
2010-12-12 19:59:10 +02:00
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
2011-07-05 02:46:03 +03:00
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
2011-07-04 01:47:10 +03:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2010-12-12 19:59:10 +02:00
|
|
|
*
|
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2011-07-04 01:47:10 +03:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2010-12-12 19:59:10 +02:00
|
|
|
*
|
2011-07-04 01:47:10 +03:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2011-07-05 02:46:03 +03:00
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
2011-07-04 01:47:10 +03:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2010-12-12 19:59:10 +02:00
|
|
|
*/
|
|
|
|
|
2012-07-01 14:51:30 +03:00
|
|
|
#include "libavutil/attributes.h"
|
2010-12-12 19:59:10 +02:00
|
|
|
#include "libavutil/cpu.h"
|
2012-08-06 16:49:32 +03:00
|
|
|
#include "libavutil/mem.h"
|
2012-08-08 15:51:52 +03:00
|
|
|
#include "libavutil/x86/asm.h"
|
2010-12-12 19:59:10 +02:00
|
|
|
#include "libavfilter/gradfun.h"
|
|
|
|
|
2012-07-22 03:03:12 +03:00
|
|
|
#if HAVE_INLINE_ASM
|
|
|
|
|
2010-12-12 19:59:10 +02:00
|
|
|
DECLARE_ALIGNED(16, static const uint16_t, pw_7f)[8] = {0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F};
|
|
|
|
DECLARE_ALIGNED(16, static const uint16_t, pw_ff)[8] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
|
|
|
|
|
2012-08-28 15:53:33 +03:00
|
|
|
#if HAVE_MMXEXT_INLINE
|
2012-11-01 14:53:19 +03:00
|
|
|
static void gradfun_filter_line_mmxext(uint8_t *dst, const uint8_t *src, const uint16_t *dc,
|
2012-07-08 20:56:10 +03:00
|
|
|
int width, int thresh,
|
|
|
|
const uint16_t *dithers)
|
2010-12-12 19:59:10 +02:00
|
|
|
{
|
|
|
|
intptr_t x;
|
|
|
|
if (width & 3) {
|
|
|
|
x = width & ~3;
|
|
|
|
ff_gradfun_filter_line_c(dst + x, src + x, dc + x / 2, width - x, thresh, dithers);
|
|
|
|
width = x;
|
|
|
|
}
|
|
|
|
x = -width;
|
|
|
|
__asm__ volatile(
|
|
|
|
"movd %4, %%mm5 \n"
|
|
|
|
"pxor %%mm7, %%mm7 \n"
|
|
|
|
"pshufw $0, %%mm5, %%mm5 \n"
|
|
|
|
"movq %6, %%mm6 \n"
|
|
|
|
"movq %5, %%mm4 \n"
|
|
|
|
"1: \n"
|
|
|
|
"movd (%2,%0), %%mm0 \n"
|
|
|
|
"movd (%3,%0), %%mm1 \n"
|
|
|
|
"punpcklbw %%mm7, %%mm0 \n"
|
|
|
|
"punpcklwd %%mm1, %%mm1 \n"
|
|
|
|
"psllw $7, %%mm0 \n"
|
|
|
|
"pxor %%mm2, %%mm2 \n"
|
|
|
|
"psubw %%mm0, %%mm1 \n" // delta = dc - pix
|
|
|
|
"psubw %%mm1, %%mm2 \n"
|
|
|
|
"pmaxsw %%mm1, %%mm2 \n"
|
|
|
|
"pmulhuw %%mm5, %%mm2 \n" // m = abs(delta) * thresh >> 16
|
|
|
|
"psubw %%mm6, %%mm2 \n"
|
|
|
|
"pminsw %%mm7, %%mm2 \n" // m = -max(0, 127-m)
|
|
|
|
"pmullw %%mm2, %%mm2 \n"
|
|
|
|
"paddw %%mm4, %%mm0 \n" // pix += dither
|
|
|
|
"pmulhw %%mm2, %%mm1 \n"
|
|
|
|
"psllw $2, %%mm1 \n" // m = m*m*delta >> 14
|
|
|
|
"paddw %%mm1, %%mm0 \n" // pix += m
|
|
|
|
"psraw $7, %%mm0 \n"
|
|
|
|
"packuswb %%mm0, %%mm0 \n"
|
|
|
|
"movd %%mm0, (%1,%0) \n" // dst = clip(pix>>7)
|
|
|
|
"add $4, %0 \n"
|
|
|
|
"jl 1b \n"
|
|
|
|
"emms \n"
|
|
|
|
:"+r"(x)
|
|
|
|
:"r"(dst+width), "r"(src+width), "r"(dc+width/2),
|
|
|
|
"rm"(thresh), "m"(*dithers), "m"(*pw_7f)
|
|
|
|
:"memory"
|
|
|
|
);
|
2012-07-03 00:49:54 +03:00
|
|
|
}
|
2012-07-01 14:51:30 +03:00
|
|
|
#endif
|
2010-12-12 19:59:10 +02:00
|
|
|
|
2012-08-28 15:53:33 +03:00
|
|
|
#if HAVE_SSSE3_INLINE
|
2012-07-02 22:19:41 +03:00
|
|
|
static void gradfun_filter_line_ssse3(uint8_t *dst, const uint8_t *src, const uint16_t *dc, int width, int thresh, const uint16_t *dithers)
|
2012-07-01 14:51:30 +03:00
|
|
|
{
|
2010-12-12 19:59:10 +02:00
|
|
|
intptr_t x;
|
|
|
|
if (width & 7) {
|
|
|
|
// could be 10% faster if I somehow eliminated this
|
|
|
|
x = width & ~7;
|
|
|
|
ff_gradfun_filter_line_c(dst + x, src + x, dc + x / 2, width - x, thresh, dithers);
|
|
|
|
width = x;
|
|
|
|
}
|
|
|
|
x = -width;
|
|
|
|
__asm__ volatile(
|
|
|
|
"movd %4, %%xmm5 \n"
|
|
|
|
"pxor %%xmm7, %%xmm7 \n"
|
|
|
|
"pshuflw $0,%%xmm5, %%xmm5 \n"
|
|
|
|
"movdqa %6, %%xmm6 \n"
|
|
|
|
"punpcklqdq %%xmm5, %%xmm5 \n"
|
|
|
|
"movdqa %5, %%xmm4 \n"
|
|
|
|
"1: \n"
|
|
|
|
"movq (%2,%0), %%xmm0 \n"
|
|
|
|
"movq (%3,%0), %%xmm1 \n"
|
|
|
|
"punpcklbw %%xmm7, %%xmm0 \n"
|
|
|
|
"punpcklwd %%xmm1, %%xmm1 \n"
|
|
|
|
"psllw $7, %%xmm0 \n"
|
|
|
|
"psubw %%xmm0, %%xmm1 \n" // delta = dc - pix
|
|
|
|
"pabsw %%xmm1, %%xmm2 \n"
|
|
|
|
"pmulhuw %%xmm5, %%xmm2 \n" // m = abs(delta) * thresh >> 16
|
|
|
|
"psubw %%xmm6, %%xmm2 \n"
|
|
|
|
"pminsw %%xmm7, %%xmm2 \n" // m = -max(0, 127-m)
|
|
|
|
"pmullw %%xmm2, %%xmm2 \n"
|
|
|
|
"psllw $1, %%xmm2 \n"
|
|
|
|
"paddw %%xmm4, %%xmm0 \n" // pix += dither
|
|
|
|
"pmulhrsw %%xmm2, %%xmm1 \n" // m = m*m*delta >> 14
|
|
|
|
"paddw %%xmm1, %%xmm0 \n" // pix += m
|
|
|
|
"psraw $7, %%xmm0 \n"
|
|
|
|
"packuswb %%xmm0, %%xmm0 \n"
|
|
|
|
"movq %%xmm0, (%1,%0) \n" // dst = clip(pix>>7)
|
|
|
|
"add $8, %0 \n"
|
|
|
|
"jl 1b \n"
|
|
|
|
:"+&r"(x)
|
|
|
|
:"r"(dst+width), "r"(src+width), "r"(dc+width/2),
|
|
|
|
"rm"(thresh), "m"(*dithers), "m"(*pw_7f)
|
|
|
|
:"memory"
|
|
|
|
);
|
2012-07-03 00:49:54 +03:00
|
|
|
}
|
2012-08-28 15:53:33 +03:00
|
|
|
#endif /* HAVE_SSSE3_INLINE */
|
2010-12-12 19:59:10 +02:00
|
|
|
|
2012-08-28 15:53:33 +03:00
|
|
|
#if HAVE_SSE2_INLINE
|
2012-07-02 22:19:41 +03:00
|
|
|
static void gradfun_blur_line_sse2(uint16_t *dc, uint16_t *buf, const uint16_t *buf1, const uint8_t *src, int src_linesize, int width)
|
2012-07-01 14:51:30 +03:00
|
|
|
{
|
2010-12-12 19:59:10 +02:00
|
|
|
#define BLURV(load)\
|
|
|
|
intptr_t x = -2*width;\
|
|
|
|
__asm__ volatile(\
|
|
|
|
"movdqa %6, %%xmm7 \n"\
|
|
|
|
"1: \n"\
|
|
|
|
load" (%4,%0), %%xmm0 \n"\
|
|
|
|
load" (%5,%0), %%xmm1 \n"\
|
|
|
|
"movdqa %%xmm0, %%xmm2 \n"\
|
|
|
|
"movdqa %%xmm1, %%xmm3 \n"\
|
|
|
|
"psrlw $8, %%xmm0 \n"\
|
|
|
|
"psrlw $8, %%xmm1 \n"\
|
|
|
|
"pand %%xmm7, %%xmm2 \n"\
|
|
|
|
"pand %%xmm7, %%xmm3 \n"\
|
|
|
|
"paddw %%xmm1, %%xmm0 \n"\
|
|
|
|
"paddw %%xmm3, %%xmm2 \n"\
|
|
|
|
"paddw %%xmm2, %%xmm0 \n"\
|
|
|
|
"paddw (%2,%0), %%xmm0 \n"\
|
|
|
|
"movdqa (%1,%0), %%xmm1 \n"\
|
|
|
|
"movdqa %%xmm0, (%1,%0) \n"\
|
|
|
|
"psubw %%xmm1, %%xmm0 \n"\
|
|
|
|
"movdqa %%xmm0, (%3,%0) \n"\
|
|
|
|
"add $16, %0 \n"\
|
|
|
|
"jl 1b \n"\
|
|
|
|
:"+&r"(x)\
|
|
|
|
:"r"(buf+width),\
|
|
|
|
"r"(buf1+width),\
|
|
|
|
"r"(dc+width),\
|
|
|
|
"r"(src+width*2),\
|
|
|
|
"r"(src+width*2+src_linesize),\
|
|
|
|
"m"(*pw_ff)\
|
|
|
|
:"memory"\
|
|
|
|
);
|
|
|
|
if (((intptr_t) src | src_linesize) & 15) {
|
|
|
|
BLURV("movdqu");
|
|
|
|
} else {
|
|
|
|
BLURV("movdqa");
|
|
|
|
}
|
2012-07-03 00:49:54 +03:00
|
|
|
}
|
2012-08-28 15:53:33 +03:00
|
|
|
#endif /* HAVE_SSE2_INLINE */
|
2012-07-01 14:51:30 +03:00
|
|
|
|
2012-07-22 03:03:12 +03:00
|
|
|
#endif /* HAVE_INLINE_ASM */
|
|
|
|
|
2012-07-01 14:51:30 +03:00
|
|
|
av_cold void ff_gradfun_init_x86(GradFunContext *gf)
|
|
|
|
{
|
|
|
|
int cpu_flags = av_get_cpu_flags();
|
|
|
|
|
2012-08-28 15:53:33 +03:00
|
|
|
#if HAVE_MMXEXT_INLINE
|
2012-07-08 19:42:12 +03:00
|
|
|
if (cpu_flags & AV_CPU_FLAG_MMXEXT)
|
2012-07-08 20:56:10 +03:00
|
|
|
gf->filter_line = gradfun_filter_line_mmxext;
|
2012-07-03 01:04:04 +03:00
|
|
|
#endif
|
2012-08-28 15:53:33 +03:00
|
|
|
#if HAVE_SSSE3_INLINE
|
2012-07-03 01:04:04 +03:00
|
|
|
if (cpu_flags & AV_CPU_FLAG_SSSE3)
|
2012-07-01 14:51:30 +03:00
|
|
|
gf->filter_line = gradfun_filter_line_ssse3;
|
2012-07-03 01:04:04 +03:00
|
|
|
#endif
|
2012-08-28 15:53:33 +03:00
|
|
|
#if HAVE_SSE2_INLINE
|
2012-07-03 01:04:04 +03:00
|
|
|
if (cpu_flags & AV_CPU_FLAG_SSE2)
|
2012-07-01 14:51:30 +03:00
|
|
|
gf->blur_line = gradfun_blur_line_sse2;
|
2012-07-03 01:04:04 +03:00
|
|
|
#endif
|
2010-12-12 19:59:10 +02:00
|
|
|
}
|