[FFmpeg-devel] Resubmit patch02 - Fwd: [patch 4/4] Fix bug for POWERLE: libswscale/ppc/swscale_altivec.c

Michael Niedermayer michaelni at gmx.at
Mon Nov 10 16:13:38 CET 2014


On Mon, Nov 10, 2014 at 05:03:22PM +0800, rongyan wrote:
> Hi,
> New patch please find in the attachment. There are two patches to re-submit, this is the second.
> The fate test result is here:
>  
>  Rong Yan
>   
> 
>  
> 
>  ------------------ 原始邮件 ------------------
>   发件人: "Tony Lin";<linzhaolover at gmail.com>;
>  发送时间: 2014年11月10日(星期一) 中午11:32
>  收件人: "rongyan"<rongyan236 at foxmail.com>; 
>  
>  主题: Fwd: [FFmpeg-devel] [patch 4/4] Fix bug for POWERLE: libswscale/ppc/swscale_altivec.c
> 
>  
> 
>  
>  Forwarded conversation
> Subject: [FFmpeg-devel] [patch 4/4] Fix bug for POWERLE: libswscale/ppc/swscale_altivec.c
> ------------------------
> 
> From: rongyan <rongyan236 at foxmail.com>
> Date: 2014-11-07 17:43 GMT+08:00
> To: ffmpeg-devel <ffmpeg-devel at ffmpeg.org>
> 
> 
> Hi,
> There are 4 patches presented to fix bugs for POWER8 little endian. I will send 4 patches in 4 different email. This is the fourth.
> 
> It fixed the function hScale_altivec_real(), yuv2planeX_16_altivec(), yuv2planeX_8().
> 
> The fate test result on POWER BE and POWER LE after merge these 4 patches are attached here to facilitate the review:
> 
>  The passed test cases change from 1679/2182 to 2010/2236.
> 
> 
> 
> 
>  Rong Yan
> 
> 
>  ------------------
>    The world has enough for everyone's need, but not enough for everyone's greed.
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> 
> ----------
> From: Michael Niedermayer <michaelni at gmx.at>
> Date: 2014-11-08 1:54 GMT+08:00
> To: FFmpeg development discussions and patches <ffmpeg-devel at ffmpeg.org>
> 
> 
>  
> >  swscale_altivec.c |  142 +++++++++++++++++++-----------------------------------
> >  1 file changed, 50 insertions(+), 92 deletions(-)
> > 0c364d48e08b7df42bee5e269fe46b2d7be0f4b9  0004-libswscale-ppc-swscale_altivec.c-fix-hScale_altivec_.patch
> > From 9ec626726d1cc30db54390ee81f52cfe53ebeedf Mon Sep 17 00:00:00 2001
> > From: Rong Yan <rongyan236 at gmail.com>
> > Date: Fri, 7 Nov 2014 09:09:09 +0000
> > Subject: [PATCH 4/4] libswscale/ppc/swscale_altivec.c : fix
> >  hScale_altivec_real() yuv2planeX_16_altivec() yuv2planeX_8() for POWER LE
> >
> > ---
> >  libswscale/ppc/swscale_altivec.c | 142 ++++++++++++++-------------------------
> >  1 file changed, 50 insertions(+), 92 deletions(-)
> >
> > diff --git a/libswscale/ppc/swscale_altivec.c b/libswscale/ppc/swscale_altivec.c
> > index 86f40ab..1673b8b 100644
> > --- a/libswscale/ppc/swscale_altivec.c
> > +++ b/libswscale/ppc/swscale_altivec.c
> > @@ -29,20 +29,30 @@
> >  #include "libavutil/attributes.h"
> >  #include "libavutil/cpu.h"
> >  #include "yuv2rgb_altivec.h"
> > +#include "libavutil/ppc/util_altivec.h"
> >
> >  #if HAVE_ALTIVEC
> >  #define vzero vec_splat_s32(0)
> >
> > -#define yuv2planeX_8(d1, d2, l1, src, x, perm, filter) do {     \
> > -        vector signed short l2  = vec_ld(((x) << 1) + 16, src); \
> > -        vector signed short ls  = vec_perm(l1, l2, perm);       \
> > -        vector signed int   i1  = vec_mule(filter, ls);         \
> > -        vector signed int   i2  = vec_mulo(filter, ls);         \
> > -        vector signed int   vf1 = vec_mergeh(i1, i2);           \
> > -        vector signed int   vf2 = vec_mergel(i1, i2);           \
> > -        d1 = vec_add(d1, vf1);                                  \
> > -        d2 = vec_add(d2, vf2);                                  \
> > -        l1 = l2;                                                \
> > +#if HAVE_BIGENDIAN
> > +#define  GET_VF(a, b) {\
> > +        a = vec_mergeh(i1, i2);\
> > +        b = vec_mergel(i1, i2);\
> > +    }
> > +#else
> > +#define  GET_VF(a, b) {\
> > +        a = vec_mergel(i2, i1);\
> > +        b = vec_mergeh(i2, i1);\
> > +    }
> > +#endif
> > +
> > +#define yuv2planeX_8(d1, d2, l1, src, x, filter) do {\
> > +        vector signed int   i1  = vec_mule(filter, l1);\
> > +        vector signed int   i2  = vec_mulo(filter, l1);\
> > +        vector signed int   vf1, vf2;\
> > +        GET_VF(vf1, vf2);\
> > +        d1 = vec_add(d1, vf1);\
> > +        d2 = vec_add(d2, vf2);\
> >      } while (0)
> >
> >  static void yuv2planeX_16_altivec(const int16_t *filter, int filterSize,
> 
> > @@ -66,16 +76,13 @@ static void yuv2planeX_16_altivec(const int16_t *filter, int filterSize,
> >      vo4 = vec_ld(48, val);
> >
> >      for (j = 0; j < filterSize; j++) {
> > -        vector signed short l1, vLumFilter = vec_ld(j << 1, filter);
> > -        vector unsigned char perm, perm0 = vec_lvsl(j << 1, filter);
> > -        vLumFilter = vec_perm(vLumFilter, vLumFilter, perm0);
> > +        vector signed short l1, l2;
> > +        vector signed short vLumFilter = (vector signed short)unaligned_load(j << 1, filter);
> >          vLumFilter = vec_splat(vLumFilter, 0); // lumFilter[j] is loaded 8 times in vLumFilter
> > -
> > -        perm = vec_lvsl(x << 1, src[j]);
> > -        l1   = vec_ld(x << 1, src[j]);
> > -
> > -        yuv2planeX_8(vo1, vo2, l1, src[j], x,     perm, vLumFilter);
> > -        yuv2planeX_8(vo3, vo4, l1, src[j], x + 8, perm, vLumFilter);
> > +        l1  = (vector signed short)unaligned_load(x << 1, src[j]);
> > +        l2  = (vector signed short)unaligned_load(((x) << 1) + 16, src[j]);
> > +        yuv2planeX_8(vo1, vo2, l1, src[j], x, vLumFilter);
> > +        yuv2planeX_8(vo3, vo4, l2, src[j], x + 8, vLumFilter);
> >      }
> 
> i belive this uses more vec_ld() on big endian than before.
> i counted 4 before and 6 after the change
> this would likely slow big endian down
> 
> [...]
> 
> --
> Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
> 
> Into a blind darkness they enter who follow after the Ignorance,
> they as if into a greater darkness enter who devote themselves
> to the Knowledge alone. -- Isha Upanishad
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


>  swscale_altivec.c |  163 +++++++++++++++++++++++++-----------------------------
>  1 file changed, 77 insertions(+), 86 deletions(-)
> faf64846206b6d93a709b40f9e229a2329285ede  0002-libswscale-ppc-swscale_altivec.c-fix-hScale_altivec_.patch
> From 68a7c25b17cce4e473ddb458e7dfc93a58d4a560 Mon Sep 17 00:00:00 2001
> From: Rong Yan <rongyan236 at gmail.com>
> Date: Mon, 10 Nov 2014 08:42:10 +0000
> Subject: [PATCH 2/2] libswscale/ppc/swscale_altivec.c : fix
>  hScale_altivec_real() yuv2planeX_16_altivec() yuv2planeX_8() add marcos
>  GET_LS() GET_VF() for POWER LE
> 
> ---
>  libswscale/ppc/swscale_altivec.c | 163 ++++++++++++++++++---------------------
>  1 file changed, 77 insertions(+), 86 deletions(-)
> 
> diff --git a/libswscale/ppc/swscale_altivec.c b/libswscale/ppc/swscale_altivec.c
> index 86f40ab..390c4bb 100644
> --- a/libswscale/ppc/swscale_altivec.c
> +++ b/libswscale/ppc/swscale_altivec.c
> @@ -29,22 +29,62 @@
>  #include "libavutil/attributes.h"
>  #include "libavutil/cpu.h"
>  #include "yuv2rgb_altivec.h"
> +#include "libavutil/ppc/util_altivec.h"
>  
>  #if HAVE_ALTIVEC
>  #define vzero vec_splat_s32(0)
>  
> +#if HAVE_BIGENDIAN
> +#define  GET_LS(a,b,c,s) {\
> +        vector signed short l2  = vec_ld(((b) << 1) + 16, s); \
> +        ls  = vec_perm(a, l2, c);\
> +        a = l2;\
> +    }
> +#define  GET_VF(a, b) {\
> +        a = vec_mergeh(i1, i2);\
> +        b = vec_mergel(i1, i2);\
> +    }
> +#else
> +#define  GET_LS(a,b,c,s) {\
> +        ls  = a;       \
> +        a = vec_vsx_ld(((b) << 1)  + 16, s);\
> +    }

> +#define  GET_VF(a, b) {\
> +        a = vec_mergel(i2, i1);\
> +        b = vec_mergeh(i2, i1);\
> +    }

i1 and i2 should be passed into the macro as well
for example

GET_VF(a, b, i1, i2)


[...]
> @@ -177,19 +201,12 @@ static void hScale_altivec_real(SwsContext *c, int16_t *dst, int dstW,
>              for (i = 0; i < dstW; i++) {
>                  register int srcPos = filterPos[i];
>  
> -                vector unsigned char src_v0 = vec_ld(srcPos, src);
> -                vector unsigned char src_v1, src_vF;
> +                vector unsigned char src_vF = unaligned_load(srcPos, src);
>                  vector signed short src_v, filter_v;
>                  vector signed int val_v, val_s;
> -                if ((((uintptr_t)src + srcPos) % 16) > 8) {
> -                    src_v1 = vec_ld(srcPos + 16, src);
> -                }
> -                src_vF = vec_perm(src_v0, src_v1, vec_lvsl(srcPos, src));
> -
>                  src_v = // vec_unpackh sign-extends...
> -                        (vector signed short)(vec_mergeh((vector unsigned char)vzero, src_vF));
> -                filter_v = vec_ld(i << 4, filter);
> -                // the 4 above is 3 (filterSize == 8) + 1 (sizeof(short) == 2)
> +                        (vector signed short)(VEC_MERGEH((vector unsigned char)vzero, src_vF));
> +                filter_v = (vector signed short)unaligned_load(i << 4, filter);
>  
>                  val_v = vec_msums(src_v, filter_v, (vector signed int)vzero);
>                  val_s = vec_sums(val_v, vzero);

the removed code does up to 3 vec_ld() on big endian, the added code
does 4 vec_ld()


> @@ -202,25 +219,21 @@ static void hScale_altivec_real(SwsContext *c, int16_t *dst, int dstW,
>              for (i = 0; i < dstW; i++) {
>                  register int srcPos = filterPos[i];
>  
> -                vector unsigned char src_v0 = vec_ld(srcPos, src);
> -                vector unsigned char src_v1 = vec_ld(srcPos + 16, src);
> -                vector unsigned char src_vF = vec_perm(src_v0, src_v1, vec_lvsl(srcPos, src));
> -
> +                vector unsigned char src_vF = unaligned_load(srcPos, src);
>                  vector signed short src_vA = // vec_unpackh sign-extends...
> -                                             (vector signed short)(vec_mergeh((vector unsigned char)vzero, src_vF));
> +                                             (vector signed short)(VEC_MERGEH((vector unsigned char)vzero, src_vF));
>                  vector signed short src_vB = // vec_unpackh sign-extends...
> -                                             (vector signed short)(vec_mergel((vector unsigned char)vzero, src_vF));
> +                                             (vector signed short)(VEC_MERGEL((vector unsigned char)vzero, src_vF));
>  
> -                vector signed short filter_v0 = vec_ld(i << 5, filter);
> -                vector signed short filter_v1 = vec_ld((i << 5) + 16, filter);
> -                // the 5 above are 4 (filterSize == 16) + 1 (sizeof(short) == 2)
> +                vector signed short filter_v0 = (vector signed short)unaligned_load(i << 5, filter);
> +                vector signed short filter_v1 = (vector signed short)unaligned_load((i << 5) + 16, filter);
>  
>                  vector signed int val_acc = vec_msums(src_vA, filter_v0, (vector signed int)vzero);
>                  vector signed int val_v   = vec_msums(src_vB, filter_v1, val_acc);
>  
>                  vector signed int val_s = vec_sums(val_v, vzero);
>  
> -                vec_st(val_s, 0, tempo);
> +                VEC_ST(val_s, 0, tempo);
>                  dst[i] = FFMIN(tempo[3] >> 7, (1 << 15) - 1);
>              }

the removed code does 3 vec_ld() the added code does 6 vec_ld() on
big endian

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Its not that you shouldnt use gotos but rather that you should write
readable code and code with gotos often but not always is less readable
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20141110/6e97edc6/attachment.asc>


More information about the ffmpeg-devel mailing list