[FFmpeg-devel] [PATCH 3/5] lavfi/gradfun: fix dithering in MMX code.
Clément Bœsch
ubitux at gmail.com
Tue Dec 11 01:21:58 CET 2012
On Fri, Dec 07, 2012 at 08:50:48AM +0100, Reimar Döffinger wrote:
> "Clément Bœsch" <ubitux at gmail.com> wrote:
>
> >Current dithering only use the first 4w instead of the whole 8 random
> >values.
>
> I think you should benchmark it, I suspect leaving the comparison in the middle instead of having the C version handle more pixels might be faster.
Yes indeed, with a width=719 it's indeed a little faster to add a
comparison in the middle.
Note: the dithers+4 is a little ugly, any suggestion welcome (and a later
commit to at least make it close to *dithers might be a good idea)
--
Clément B.
-------------- next part --------------
From a3905242dde6904e93c662a641b71e6ff285014a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= <ubitux at gmail.com>
Date: Fri, 7 Dec 2012 00:39:31 +0100
Subject: [PATCH 3/5] lavfi/gradfun: fix dithering in MMX code.
Current dithering only use the first 4w instead of the whole 8 random values.
---
libavfilter/x86/gradfun.c | 32 ++++++++++++++++++++++++++++++--
1 file changed, 30 insertions(+), 2 deletions(-)
diff --git a/libavfilter/x86/gradfun.c b/libavfilter/x86/gradfun.c
index 1ca5928..79c1fc8 100644
--- a/libavfilter/x86/gradfun.c
+++ b/libavfilter/x86/gradfun.c
@@ -23,6 +23,7 @@
#include "libavutil/mem.h"
#include "libavutil/x86/asm.h"
#include "libavfilter/gradfun.h"
+#include "libavutil/timer.h"
#if HAVE_INLINE_ASM
@@ -46,7 +47,9 @@ static void gradfun_filter_line_mmxext(uint8_t *dst, const uint8_t *src, const u
"pxor %%mm7, %%mm7 \n"
"pshufw $0, %%mm5, %%mm5 \n"
"movq %6, %%mm6 \n"
- "movq %5, %%mm4 \n"
+ "movq %5, %%mm3 \n"
+ "movq %7, %%mm4 \n"
+
"1: \n"
"movd (%2,%0), %%mm0 \n"
"movd (%3,%0), %%mm1 \n"
@@ -61,6 +64,29 @@ static void gradfun_filter_line_mmxext(uint8_t *dst, const uint8_t *src, const u
"psubw %%mm6, %%mm2 \n"
"pminsw %%mm7, %%mm2 \n" // m = -max(0, 127-m)
"pmullw %%mm2, %%mm2 \n"
+ "paddw %%mm3, %%mm0 \n" // pix += dither
+ "psllw $2, %%mm1 \n" // m = m*m*delta >> 14
+ "pmulhw %%mm2, %%mm1 \n"
+ "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"
+ "jnl 2f \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
"psllw $2, %%mm1 \n" // m = m*m*delta >> 14
"pmulhw %%mm2, %%mm1 \n"
@@ -70,10 +96,12 @@ static void gradfun_filter_line_mmxext(uint8_t *dst, const uint8_t *src, const u
"movd %%mm0, (%1,%0) \n" // dst = clip(pix>>7)
"add $4, %0 \n"
"jl 1b \n"
+
+ "2: \n"
"emms \n"
:"+r"(x)
:"r"(dst+width), "r"(src+width), "r"(dc+width/2),
- "rm"(thresh), "m"(*dithers), "m"(*pw_7f)
+ "rm"(thresh), "m"(*dithers), "m"(*pw_7f), "m"(*(dithers + 4))
:"memory"
);
}
--
1.8.0.1
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20121211/6d860de7/attachment.asc>
More information about the ffmpeg-devel
mailing list