[FFmpeg-devel] [PATCH] Use av_clip_uint8 in swscale.

Michael Niedermayer michaelni
Mon Aug 17 13:51:38 CEST 2009


On Sun, Aug 16, 2009 at 11:00:42PM -0300, Ramiro Polla wrote:
> On Sat, Aug 15, 2009 at 1:34 PM, Reimar
> D?ffinger<Reimar.Doeffinger at gmx.de> wrote:
> > On Sat, Aug 15, 2009 at 12:27:49PM -0300, Ramiro Polla wrote:
> >> diff --git a/swscale.c b/swscale.c
> >> index c513066..340acfc 100644
> >> --- a/swscale.c
> >> +++ b/swscale.c
> >> @@ -688,21 +688,12 @@ static inline void yuv2nv12XinC(const int16_t *lumFilter, const int16_t **lumSrc
> >>
> >> ?#define YSCALE_YUV_2_PACKEDX_C(type,alpha) \
> >> ? ? ? ? ?YSCALE_YUV_2_PACKEDX_NOCLIP_C(type,alpha)\
> >> - ? ? ? ?if ((Y1|Y2|U|V)&256)\
> >> - ? ? ? ?{\
> >> - ? ? ? ? ? ?if (Y1>255) ? Y1=255; \
> >> - ? ? ? ? ? ?else if (Y1<0)Y1=0; ? \
> >> - ? ? ? ? ? ?if (Y2>255) ? Y2=255; \
> >> - ? ? ? ? ? ?else if (Y2<0)Y2=0; ? \
> >> - ? ? ? ? ? ?if (U>255) ? ?U=255; ?\
> >> - ? ? ? ? ? ?else if (U<0) U=0; ? ?\
> >> - ? ? ? ? ? ?if (V>255) ? ?V=255; ?\
> >> - ? ? ? ? ? ?else if (V<0) V=0; ? ?\
> >> - ? ? ? ?}\
> >> - ? ? ? ?if (alpha && ((A1|A2)&256)){\
> >> - ? ? ? ? ? ?A1=av_clip_uint8(A1);\
> >> - ? ? ? ? ? ?A2=av_clip_uint8(A2);\
> >> - ? ? ? ?}
> >> + ? ? ? ?Y1 = av_clip_uint8(Y1); \
> >> + ? ? ? ?Y2 = av_clip_uint8(Y2); \
> >> + ? ? ? ?U ?= av_clip_uint8(U ); \
> >> + ? ? ? ?V ?= av_clip_uint8(V ); \
> >> + ? ? ? ?A1 = av_clip_uint8(A1); \
> >> + ? ? ? ?A2 = av_clip_uint8(A2); \
> >
> > This
> >
> >> - ? ? ? ? ? ?if ((u|v)&256){
> >> - ? ? ? ? ? ? ? ?if (u<0) ? ? ? ?u=0;
> >> - ? ? ? ? ? ? ? ?else if (u>255) u=255;
> >> - ? ? ? ? ? ? ? ?if (v<0) ? ? ? ?v=0;
> >> - ? ? ? ? ? ? ? ?else if (v>255) v=255;
> >> - ? ? ? ? ? ?}
> >> -
> >> - ? ? ? ? ? ?uDest[i]= u;
> >> - ? ? ? ? ? ?vDest[i]= v;
> >> + ? ? ? ? ? ?uDest[i]= av_clip_uint8((chrSrc[i ? ? ? ]+64)>>7);
> >> + ? ? ? ? ? ?vDest[i]= av_clip_uint8((chrSrc[i + VOFW]+64)>>7);
> >
> > And this need to be benchmarked (well, or at least have a look at the
> > generated code.
> > If clipping is very, very rare the original code might be faster.
> 
> Clipping seems to be very very rare. (I haven't come across any actually).
> In yuv2yuv1(), using av_clip_uint8_t() inside if (&256) makes the code
> go from ~38000 dezicycles to ~35000 dezicycles (weird since the
> condition is never met).

theres nothing weird, its gcc isnt it?
and you in thery should report such code pessimizations, not that i think
they would care beyond closing it once it by random chance works for one
revission of gcc

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Republics decline into democracies and democracies degenerate into
despotisms. -- Aristotle
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090817/ee312a40/attachment.pgp>



More information about the ffmpeg-devel mailing list