PR #21164 opened by Sean McGovern (sean_mcg)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21164
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21164.patch

refs: #20832


>From aa5fa0212b371e8fdb00005ec8c12dd346c8e567 Mon Sep 17 00:00:00 2001
From: Sean McGovern <[email protected]>
Date: Sat, 1 Feb 2025 06:24:56 -0500
Subject: [PATCH] libswscale: deprecate big-endian AltiVec acceleration

refs: #20832
---
 Changelog                        |   1 +
 libswscale/ppc/Makefile          |   5 +-
 libswscale/ppc/swscale_altivec.c | 285 ----------
 libswscale/ppc/yuv2rgb_altivec.c | 874 -------------------------------
 libswscale/ppc/yuv2yuv_altivec.c | 204 --------
 libswscale/swscale.c             |   2 +-
 libswscale/swscale_internal.h    |   2 +
 libswscale/utils.c               |   3 +-
 libswscale/version.h             |   2 +-
 9 files changed, 7 insertions(+), 1371 deletions(-)
 delete mode 100644 libswscale/ppc/swscale_altivec.c
 delete mode 100644 libswscale/ppc/yuv2rgb_altivec.c
 delete mode 100644 libswscale/ppc/yuv2yuv_altivec.c

diff --git a/Changelog b/Changelog
index ef72af1e93..8f44c53a3d 100644
--- a/Changelog
+++ b/Changelog
@@ -16,6 +16,7 @@ version <next>:
 - Rockchip H.264/HEVC hardware encoder
 - Add vf_scale_d3d12 filter
 
+- remove big-endian AltiVec acceleration
 
 version 8.0:
 - Whisper filter
diff --git a/libswscale/ppc/Makefile b/libswscale/ppc/Makefile
index 0a31a3025b..edbf1f6f81 100644
--- a/libswscale/ppc/Makefile
+++ b/libswscale/ppc/Makefile
@@ -1,4 +1 @@
-OBJS += ppc/swscale_altivec.o                                           \
-        ppc/yuv2rgb_altivec.o                                           \
-        ppc/yuv2yuv_altivec.o                                           \
-        ppc/swscale_vsx.o
+OBJS += ppc/swscale_vsx.o
diff --git a/libswscale/ppc/swscale_altivec.c b/libswscale/ppc/swscale_altivec.c
deleted file mode 100644
index 3112c6cb71..0000000000
--- a/libswscale/ppc/swscale_altivec.c
+++ /dev/null
@@ -1,285 +0,0 @@
-/*
- * AltiVec-enhanced yuv2yuvX
- *
- * Copyright (C) 2004 Romain Dolbeau <[email protected]>
- * based on the equivalent C code in swscale.c
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * 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.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * 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
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#include <inttypes.h>
-
-#include "config.h"
-#include "libswscale/swscale.h"
-#include "libswscale/swscale_internal.h"
-#include "libavutil/attributes.h"
-#include "libavutil/cpu.h"
-#include "libavutil/intfloat.h"
-#include "yuv2rgb_altivec.h"
-#include "libavutil/ppc/util_altivec.h"
-
-#if HAVE_ALTIVEC
-#if HAVE_BIGENDIAN
-#define vzero vec_splat_s32(0)
-
-#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 yuv2planeX_8(d1, d2, l1, src, x, perm, filter) do {\
-        vector signed short ls;\
-        vector signed int   vf1, vf2, i1, i2;\
-        GET_LS(l1, x, perm, src);\
-        i1  = vec_mule(filter, ls);\
-        i2  = vec_mulo(filter, ls);\
-        vf1 = vec_mergeh(i1, i2);\
-        vf2 = vec_mergel(i1, i2);\
-        d1 = vec_add(d1, vf1);\
-        d2 = vec_add(d2, vf2);\
-    } while (0)
-
-#define LOAD_FILTER(vf,f) {\
-        vector unsigned char perm0 = vec_lvsl(joffset, f);\
-        vf = vec_ld(joffset, f);\
-        vf = vec_perm(vf, vf, perm0);\
-}
-#define LOAD_L1(ll1,s,p){\
-        p = vec_lvsl(xoffset, s);\
-        ll1   = vec_ld(xoffset, s);\
-}
-
-// The 3 above is 2 (filterSize == 4) + 1 (sizeof(short) == 2).
-
-// The neat trick: We only care for half the elements,
-// high or low depending on (i<<3)%16 (it's 0 or 8 here),
-// and we're going to use vec_mule, so we choose
-// carefully how to "unpack" the elements into the even slots.
-#define GET_VF4(a, vf, f) {\
-    vf = vec_ld(a<< 3, f);\
-    if ((a << 3) % 16)\
-        vf = vec_mergel(vf, (vector signed short)vzero);\
-    else\
-        vf = vec_mergeh(vf, (vector signed short)vzero);\
-}
-#define FIRST_LOAD(sv, pos, s, per) {\
-    sv = vec_ld(pos, s);\
-    per = vec_lvsl(pos, s);\
-}
-#define UPDATE_PTR(s0, d0, s1, d1) {\
-    d0 = s0;\
-    d1 = s1;\
-}
-#define LOAD_SRCV(pos, a, s, per, v0, v1, vf) {\
-    v1 = vec_ld(pos + a + 16, s);\
-    vf = vec_perm(v0, v1, per);\
-}
-#define LOAD_SRCV8(pos, a, s, per, v0, v1, vf) {\
-    if ((((uintptr_t)s + pos) % 16) > 8) {\
-        v1 = vec_ld(pos + a + 16, s);\
-    }\
-    vf = vec_perm(v0, src_v1, per);\
-}
-#define GET_VFD(a, b, f, vf0, vf1, per, vf, off) {\
-    vf1 = vec_ld((a * 2 * filterSize) + (b * 2) + 16 + off, f);\
-    vf  = vec_perm(vf0, vf1, per);\
-}
-
-#define FUNC(name) name ## _altivec
-#include "swscale_ppc_template.c"
-#undef FUNC
-
-#undef vzero
-
-#endif /* HAVE_BIGENDIAN */
-
-#define SHIFT  3
-
-#define get_pixel(val, bias, signedness) \
-    (bias + av_clip_ ## signedness ## 16(val >> shift))
-
-static void
-yuv2plane1_float_u(const int32_t *src, float *dest, int dstW, int start)
-{
-    static const int shift = 3;
-    static const float float_mult = 1.0f / 65535.0f;
-    int i, val;
-    uint16_t val_uint;
-
-    for (i = start; i < dstW; ++i){
-        val = src[i] + (1 << (shift - 1));
-        val_uint = get_pixel(val, 0, uint);
-        dest[i] = float_mult * (float)val_uint;
-    }
-}
-
-static void
-yuv2plane1_float_bswap_u(const int32_t *src, uint32_t *dest, int dstW, int 
start)
-{
-    static const int shift = 3;
-    static const float float_mult = 1.0f / 65535.0f;
-    int i, val;
-    uint16_t val_uint;
-
-    for (i = start; i < dstW; ++i){
-        val = src[i] + (1 << (shift - 1));
-        val_uint = get_pixel(val, 0, uint);
-        dest[i] = av_bswap32(av_float2int(float_mult * (float)val_uint));
-    }
-}
-
-static void yuv2plane1_float_altivec(const int32_t *src, float *dest, int dstW)
-{
-    const int dst_u = -(uintptr_t)dest & 3;
-    const int add = (1 << (SHIFT - 1));
-    const int clip = (1 << 16) - 1;
-    const float fmult = 1.0f / 65535.0f;
-    const vec_u32 vadd = (vec_u32) {add, add, add, add};
-    const vec_u32 vshift = (vec_u32) vec_splat_u32(SHIFT);
-    const vec_u32 vlargest = (vec_u32) {clip, clip, clip, clip};
-    const vec_f vmul = (vec_f) {fmult, fmult, fmult, fmult};
-    const vec_f vzero = (vec_f) {0, 0, 0, 0};
-    vec_u32 v;
-    vec_f vd;
-    int i;
-
-    yuv2plane1_float_u(src, dest, dst_u, 0);
-
-    for (i = dst_u; i < dstW - 3; i += 4) {
-        v = vec_ld(0, (const uint32_t *) &src[i]);
-        v = vec_add(v, vadd);
-        v = vec_sr(v, vshift);
-        v = vec_min(v, vlargest);
-
-        vd = vec_ctf(v, 0);
-        vd = vec_madd(vd, vmul, vzero);
-
-        vec_st(vd, 0, &dest[i]);
-    }
-
-    yuv2plane1_float_u(src, dest, dstW, i);
-}
-
-static void yuv2plane1_float_bswap_altivec(const int32_t *src, uint32_t *dest, 
int dstW)
-{
-    const int dst_u = -(uintptr_t)dest & 3;
-    const int add = (1 << (SHIFT - 1));
-    const int clip = (1 << 16) - 1;
-    const float fmult = 1.0f / 65535.0f;
-    const vec_u32 vadd = (vec_u32) {add, add, add, add};
-    const vec_u32 vshift = (vec_u32) vec_splat_u32(SHIFT);
-    const vec_u32 vlargest = (vec_u32) {clip, clip, clip, clip};
-    const vec_f vmul = (vec_f) {fmult, fmult, fmult, fmult};
-    const vec_f vzero = (vec_f) {0, 0, 0, 0};
-    const vec_u32 vswapbig = (vec_u32) {16, 16, 16, 16};
-    const vec_u16 vswapsmall = vec_splat_u16(8);
-    vec_u32 v;
-    vec_f vd;
-    int i;
-
-    yuv2plane1_float_bswap_u(src, dest, dst_u, 0);
-
-    for (i = dst_u; i < dstW - 3; i += 4) {
-        v = vec_ld(0, (const uint32_t *) &src[i]);
-        v = vec_add(v, vadd);
-        v = vec_sr(v, vshift);
-        v = vec_min(v, vlargest);
-
-        vd = vec_ctf(v, 0);
-        vd = vec_madd(vd, vmul, vzero);
-
-        vd = (vec_f) vec_rl((vec_u32) vd, vswapbig);
-        vd = (vec_f) vec_rl((vec_u16) vd, vswapsmall);
-
-        vec_st(vd, 0, (float *) &dest[i]);
-    }
-
-    yuv2plane1_float_bswap_u(src, dest, dstW, i);
-}
-
-#define yuv2plane1_float(template, dest_type, BE_LE) \
-static void yuv2plane1_float ## BE_LE ## _altivec(const int16_t *src, uint8_t 
*dest, \
-                                                  int dstW, \
-                                                  const uint8_t *dither, int 
offset) \
-{ \
-    template((const int32_t *)src, (dest_type *)dest, dstW); \
-}
-
-#if HAVE_BIGENDIAN
-yuv2plane1_float(yuv2plane1_float_altivec,       float,    BE)
-yuv2plane1_float(yuv2plane1_float_bswap_altivec, uint32_t, LE)
-#else
-yuv2plane1_float(yuv2plane1_float_altivec,       float,    LE)
-yuv2plane1_float(yuv2plane1_float_bswap_altivec, uint32_t, BE)
-#endif
-
-#endif /* HAVE_ALTIVEC */
-
-av_cold void ff_sws_init_swscale_ppc(SwsInternal *c)
-{
-#if HAVE_ALTIVEC
-    enum AVPixelFormat dstFormat = c->opts.dst_format;
-
-    if (!(av_get_cpu_flags() & AV_CPU_FLAG_ALTIVEC))
-        return;
-
-#if HAVE_BIGENDIAN
-    if (c->srcBpc == 8 && c->dstBpc <= 14) {
-        c->hyScale = c->hcScale = hScale_real_altivec;
-    }
-    if (!is16BPS(dstFormat) && !isNBPS(dstFormat) && 
!isSemiPlanarYUV(dstFormat) && !isDataInHighBits(dstFormat) &&
-        dstFormat != AV_PIX_FMT_GRAYF32BE && dstFormat != AV_PIX_FMT_GRAYF32LE 
&&
-        !c->needAlpha) {
-        c->yuv2planeX = yuv2planeX_altivec;
-    }
-#endif
-
-    if (dstFormat == AV_PIX_FMT_GRAYF32BE) {
-        c->yuv2plane1 = yuv2plane1_floatBE_altivec;
-    } else if (dstFormat == AV_PIX_FMT_GRAYF32LE) {
-        c->yuv2plane1 = yuv2plane1_floatLE_altivec;
-    }
-
-    /* The following list of supported dstFormat values should
-     * match what's found in the body of ff_yuv2packedX_altivec() */
-    if (!(c->opts.flags & (SWS_BITEXACT | SWS_FULL_CHR_H_INT)) && 
!c->needAlpha) {
-        switch (c->opts.dst_format) {
-        case AV_PIX_FMT_ABGR:
-            c->yuv2packedX = ff_yuv2abgr_X_altivec;
-            break;
-        case AV_PIX_FMT_BGRA:
-            c->yuv2packedX = ff_yuv2bgra_X_altivec;
-            break;
-        case AV_PIX_FMT_ARGB:
-            c->yuv2packedX = ff_yuv2argb_X_altivec;
-            break;
-        case AV_PIX_FMT_RGBA:
-            c->yuv2packedX = ff_yuv2rgba_X_altivec;
-            break;
-        case AV_PIX_FMT_BGR24:
-            c->yuv2packedX = ff_yuv2bgr24_X_altivec;
-            break;
-        case AV_PIX_FMT_RGB24:
-            c->yuv2packedX = ff_yuv2rgb24_X_altivec;
-            break;
-        }
-    }
-#endif /* HAVE_ALTIVEC */
-
-    ff_sws_init_swscale_vsx(c);
-}
diff --git a/libswscale/ppc/yuv2rgb_altivec.c b/libswscale/ppc/yuv2rgb_altivec.c
deleted file mode 100644
index a6b6650e02..0000000000
--- a/libswscale/ppc/yuv2rgb_altivec.c
+++ /dev/null
@@ -1,874 +0,0 @@
-/*
- * AltiVec acceleration for colorspace conversion
- *
- * copyright (C) 2004 Marc Hoffman <[email protected]>
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * 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.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * 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
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/*
- * Convert I420 YV12 to RGB in various formats,
- * it rejects images that are not in 420 formats,
- * it rejects images that don't have widths of multiples of 16,
- * it rejects images that don't have heights of multiples of 2.
- * Reject defers to C simulation code.
- *
- * Lots of optimizations to be done here.
- *
- * 1. Need to fix saturation code. I just couldn't get it to fly with packs
- * and adds, so we currently use max/min to clip.
- *
- * 2. The inefficient use of chroma loading needs a bit of brushing up.
- *
- * 3. Analysis of pipeline stalls needs to be done. Use shark to identify
- * pipeline stalls.
- *
- *
- * MODIFIED to calculate coeffs from currently selected color space.
- * MODIFIED core to be a macro where you specify the output format.
- * ADDED UYVY conversion which is never called due to some thing in swscale.
- * CORRECTED algorithm selection to be strict on input formats.
- * ADDED runtime detection of AltiVec.
- *
- * ADDED altivec_yuv2packedX vertical scl + RGB converter
- *
- * March 27,2004
- * PERFORMANCE ANALYSIS
- *
- * The C version uses 25% of the processor or ~250Mips for D1 video rawvideo
- * used as test.
- * The AltiVec version uses 10% of the processor or ~100Mips for D1 video
- * same sequence.
- *
- * 720 * 480 * 30  ~10MPS
- *
- * so we have roughly 10 clocks per pixel. This is too high, something has
- * to be wrong.
- *
- * OPTIMIZED clip codes to utilize vec_max and vec_packs removing the
- * need for vec_min.
- *
- * OPTIMIZED DST OUTPUT cache/DMA controls. We are pretty much guaranteed to
- * have the input video frame, it was just decompressed so it probably resides
- * in L1 caches. However, we are creating the output video stream. This needs
- * to use the DSTST instruction to optimize for the cache. We couple this with
- * the fact that we are not going to be visiting the input buffer again so we
- * mark it Least Recently Used. This shaves 25% of the processor cycles off.
- *
- * Now memcpy is the largest mips consumer in the system, probably due
- * to the inefficient X11 stuff.
- *
- * GL libraries seem to be very slow on this machine 1.33Ghz PB running
- * Jaguar, this is not the case for my 1Ghz PB.  I thought it might be
- * a versioning issue, however I have libGL.1.2.dylib for both
- * machines. (We need to figure this out now.)
- *
- * GL2 libraries work now with patch for RGB32.
- *
- * NOTE: quartz vo driver ARGB32_to_RGB24 consumes 30% of the processor.
- *
- * Integrated luma prescaling adjustment for saturation/contrast/brightness
- * adjustment.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <inttypes.h>
-
-#include "config.h"
-#include "libswscale/rgb2rgb.h"
-#include "libswscale/swscale.h"
-#include "libswscale/swscale_internal.h"
-#include "libavutil/attributes.h"
-#include "libavutil/cpu.h"
-#include "libavutil/mem_internal.h"
-#include "libavutil/pixdesc.h"
-#include "yuv2rgb_altivec.h"
-
-#if HAVE_ALTIVEC
-
-#undef PROFILE_THE_BEAST
-#undef INC_SCALING
-
-typedef unsigned char ubyte;
-typedef signed char   sbyte;
-
-/* RGB interleaver, 16 planar pels 8-bit samples per channel in
- * homogeneous vector registers x0,x1,x2 are interleaved with the
- * following technique:
- *
- *    o0 = vec_mergeh(x0, x1);
- *    o1 = vec_perm(o0, x2, perm_rgb_0);
- *    o2 = vec_perm(o0, x2, perm_rgb_1);
- *    o3 = vec_mergel(x0, x1);
- *    o4 = vec_perm(o3, o2, perm_rgb_2);
- *    o5 = vec_perm(o3, o2, perm_rgb_3);
- *
- * perm_rgb_0:   o0(RG).h v1(B) --> o1*
- *            0   1  2   3   4
- *           rgbr|gbrg|brgb|rgbr
- *           0010 0100 1001 0010
- *           0102 3145 2673 894A
- *
- * perm_rgb_1:   o0(RG).h v1(B) --> o2
- *            0   1  2   3   4
- *           gbrg|brgb|bbbb|bbbb
- *           0100 1001 1111 1111
- *           B5CD 6EF7 89AB CDEF
- *
- * perm_rgb_2:   o3(RG).l o2(rgbB.l) --> o4*
- *            0   1  2   3   4
- *           gbrg|brgb|rgbr|gbrg
- *           1111 1111 0010 0100
- *           89AB CDEF 0182 3945
- *
- * perm_rgb_2:   o3(RG).l o2(rgbB.l) ---> o5*
- *            0   1  2   3   4
- *           brgb|rgbr|gbrg|brgb
- *           1001 0010 0100 1001
- *           a67b 89cA BdCD eEFf
- */
-static const vector unsigned char
-    perm_rgb_0 = { 0x00, 0x01, 0x10, 0x02, 0x03, 0x11, 0x04, 0x05,
-                   0x12, 0x06, 0x07, 0x13, 0x08, 0x09, 0x14, 0x0a },
-    perm_rgb_1 = { 0x0b, 0x15, 0x0c, 0x0d, 0x16, 0x0e, 0x0f, 0x17,
-                   0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f },
-    perm_rgb_2 = { 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
-                   0x00, 0x01, 0x18, 0x02, 0x03, 0x19, 0x04, 0x05 },
-    perm_rgb_3 = { 0x1a, 0x06, 0x07, 0x1b, 0x08, 0x09, 0x1c, 0x0a,
-                   0x0b, 0x1d, 0x0c, 0x0d, 0x1e, 0x0e, 0x0f, 0x1f };
-
-#define vec_merge3(x2, x1, x0, y0, y1, y2)     \
-    do {                                       \
-        __typeof__(x0) o0, o2, o3;             \
-        o0 = vec_mergeh(x0, x1);               \
-        y0 = vec_perm(o0, x2, perm_rgb_0);     \
-        o2 = vec_perm(o0, x2, perm_rgb_1);     \
-        o3 = vec_mergel(x0, x1);               \
-        y1 = vec_perm(o3, o2, perm_rgb_2);     \
-        y2 = vec_perm(o3, o2, perm_rgb_3);     \
-    } while (0)
-
-#define vec_mstbgr24(x0, x1, x2, ptr)          \
-    do {                                       \
-        __typeof__(x0) _0, _1, _2;             \
-        vec_merge3(x0, x1, x2, _0, _1, _2);    \
-        vec_st(_0, 0, ptr++);                  \
-        vec_st(_1, 0, ptr++);                  \
-        vec_st(_2, 0, ptr++);                  \
-    } while (0)
-
-#define vec_mstrgb24(x0, x1, x2, ptr)          \
-    do {                                       \
-        __typeof__(x0) _0, _1, _2;             \
-        vec_merge3(x2, x1, x0, _0, _1, _2);    \
-        vec_st(_0, 0, ptr++);                  \
-        vec_st(_1, 0, ptr++);                  \
-        vec_st(_2, 0, ptr++);                  \
-    } while (0)
-
-/* pack the pixels in rgb0 format
- * msb R
- * lsb 0
- */
-#define vec_mstrgb32(T, x0, x1, x2, x3, ptr)                            \
-    do {                                                                \
-        T _0, _1, _2, _3;                                               \
-        _0 = vec_mergeh(x0, x1);                                        \
-        _1 = vec_mergeh(x2, x3);                                        \
-        _2 = (T) vec_mergeh((vector unsigned short) _0,                 \
-                            (vector unsigned short) _1);                \
-        _3 = (T) vec_mergel((vector unsigned short) _0,                 \
-                            (vector unsigned short) _1);                \
-        vec_st(_2, 0 * 16, (T *) ptr);                                  \
-        vec_st(_3, 1 * 16, (T *) ptr);                                  \
-        _0 = vec_mergel(x0, x1);                                        \
-        _1 = vec_mergel(x2, x3);                                        \
-        _2 = (T) vec_mergeh((vector unsigned short) _0,                 \
-                            (vector unsigned short) _1);                \
-        _3 = (T) vec_mergel((vector unsigned short) _0,                 \
-                            (vector unsigned short) _1);                \
-        vec_st(_2, 2 * 16, (T *) ptr);                                  \
-        vec_st(_3, 3 * 16, (T *) ptr);                                  \
-        ptr += 4;                                                       \
-    } while (0)
-
-/*
- * 1     0       1.4021   | | Y |
- * 1    -0.3441 -0.7142   |x| Cb|
- * 1     1.7718  0        | | Cr|
- *
- *
- * Y:      [-128 127]
- * Cb/Cr : [-128 127]
- *
- * typical YUV conversion works on Y: 0-255 this version has been
- * optimized for JPEG decoding.
- */
-
-#if HAVE_BIGENDIAN
-#define vec_unh(x)                                                      \
-    (vector signed short)                                               \
-        vec_perm(x, (__typeof__(x)) { 0 },                              \
-                 ((vector unsigned char) {                              \
-                     0x10, 0x00, 0x10, 0x01, 0x10, 0x02, 0x10, 0x03,    \
-                     0x10, 0x04, 0x10, 0x05, 0x10, 0x06, 0x10, 0x07 }))
-
-#define vec_unl(x)                                                      \
-    (vector signed short)                                               \
-        vec_perm(x, (__typeof__(x)) { 0 },                              \
-                 ((vector unsigned char) {                              \
-                     0x10, 0x08, 0x10, 0x09, 0x10, 0x0A, 0x10, 0x0B,    \
-                     0x10, 0x0C, 0x10, 0x0D, 0x10, 0x0E, 0x10, 0x0F }))
-#else
-#define vec_unh(x)(vector signed short) vec_mergeh(x,(__typeof__(x)) { 0 })
-#define vec_unl(x)(vector signed short) vec_mergel(x,(__typeof__(x)) { 0 })
-#endif
-
-#define vec_clip_s16(x)                                                 \
-    vec_max(vec_min(x, ((vector signed short) {                         \
-                    235, 235, 235, 235, 235, 235, 235, 235 })),         \
-            ((vector signed short) { 16, 16, 16, 16, 16, 16, 16, 16 }))
-
-#define vec_packclp(x, y)                                               \
-    (vector unsigned char)                                              \
-        vec_packs((vector unsigned short)                               \
-                      vec_max(x, ((vector signed short) { 0 })),        \
-                  (vector unsigned short)                               \
-                      vec_max(y, ((vector signed short) { 0 })))
-
-static inline void cvtyuvtoRGB(SwsInternal *c, vector signed short Y,
-                               vector signed short U, vector signed short V,
-                               vector signed short *R, vector signed short *G,
-                               vector signed short *B)
-{
-    vector signed short vx, ux, uvx;
-
-    Y = vec_mradds(Y, c->CY, c->OY);
-    U = vec_sub(U, (vector signed short)
-                       vec_splat((vector signed short) { 128 }, 0));
-    V = vec_sub(V, (vector signed short)
-                       vec_splat((vector signed short) { 128 }, 0));
-
-    // ux  = (CBU * (u << c->CSHIFT) + 0x4000) >> 15;
-    ux = vec_sl(U, c->CSHIFT);
-    *B = vec_mradds(ux, c->CBU, Y);
-
-    // vx  = (CRV * (v << c->CSHIFT) + 0x4000) >> 15;
-    vx = vec_sl(V, c->CSHIFT);
-    *R = vec_mradds(vx, c->CRV, Y);
-
-    // uvx = ((CGU * u) + (CGV * v)) >> 15;
-    uvx = vec_mradds(U, c->CGU, Y);
-    *G  = vec_mradds(V, c->CGV, uvx);
-}
-
-/*
- * 
------------------------------------------------------------------------------
- * CS converters
- * 
------------------------------------------------------------------------------
- */
-
-#if !HAVE_VEC_XL
-static inline vector unsigned char vec_xl(signed long long offset, const ubyte 
*addr)
-{
-    const vector unsigned char *v_addr = (const vector unsigned char *) (addr 
+ offset);
-    vector unsigned char align_perm = vec_lvsl(offset, addr);
-
-    return (vector unsigned char) vec_perm(v_addr[0], v_addr[1], align_perm);
-}
-#endif /* !HAVE_VEC_XL */
-
-#define DEFCSP420_CVT(name, out_pixels)                                       \
-static int altivec_ ## name(SwsInternal *c, const unsigned char *const *in,   \
-                            const int *instrides, int srcSliceY, int 
srcSliceH,   \
-                            unsigned char *const *oplanes, const int 
*outstrides) \
-{                                                                             \
-    int w = c->opts.src_w;                                                    \
-    int h = srcSliceH;                                                        \
-    int i, j;                                                                 \
-    int instrides_scl[3];                                                     \
-    vector unsigned char y0, y1;                                              \
-                                                                              \
-    vector signed char u, v;                                                  \
-                                                                              \
-    vector signed short Y0, Y1, Y2, Y3;                                       \
-    vector signed short U, V;                                                 \
-    vector signed short vx, ux, uvx;                                          \
-    vector signed short vx0, ux0, uvx0;                                       \
-    vector signed short vx1, ux1, uvx1;                                       \
-    vector signed short R0, G0, B0;                                           \
-    vector signed short R1, G1, B1;                                           \
-    vector unsigned char R, G, B;                                             \
-                                                                              \
-    vector signed short lCY       = c->CY;                                    \
-    vector signed short lOY       = c->OY;                                    \
-    vector signed short lCRV      = c->CRV;                                   \
-    vector signed short lCBU      = c->CBU;                                   \
-    vector signed short lCGU      = c->CGU;                                   \
-    vector signed short lCGV      = c->CGV;                                   \
-    vector unsigned short lCSHIFT = c->CSHIFT;                                \
-                                                                              \
-    const ubyte *y1i = in[0];                                                 \
-    const ubyte *y2i = in[0] + instrides[0];                                  \
-    const ubyte *ui  = in[1];                                                 \
-    const ubyte *vi  = in[2];                                                 \
-                                                                              \
-    vector unsigned char *oute, *outo;                                        \
-                                                                              \
-    /* loop moves y{1, 2}i by w */                                            \
-    instrides_scl[0] = instrides[0] * 2 - w;                                  \
-    /* loop moves ui by w / 2 */                                              \
-    instrides_scl[1] = instrides[1] - w / 2;                                  \
-    /* loop moves vi by w / 2 */                                              \
-    instrides_scl[2] = instrides[2] - w / 2;                                  \
-                                                                              \
-    for (i = 0; i < h / 2; i++) {                                             \
-        oute = (vector unsigned char *)(oplanes[0] + outstrides[0] *          \
-                                        (srcSliceY + i * 2));                 \
-        outo = oute + (outstrides[0] >> 4);                                   \
-        vec_dstst(outo, (0x02000002 | (((w * 3 + 32) / 32) << 16)), 0);       \
-        vec_dstst(oute, (0x02000002 | (((w * 3 + 32) / 32) << 16)), 1);       \
-                                                                              \
-        for (j = 0; j < w / 16; j++) {                                        \
-            y0 = vec_xl(0, y1i);                                              \
-                                                                              \
-            y1 = vec_xl(0, y2i);                                              \
-                                                                              \
-            u = (vector signed char) vec_xl(0, ui);                           \
-                                                                              \
-            v = (vector signed char) vec_xl(0, vi);                           \
-                                                                              \
-            u = (vector signed char)                                          \
-                    vec_sub(u,                                                \
-                            (vector signed char)                              \
-                                vec_splat((vector signed char) { 128 }, 0));  \
-            v = (vector signed char)                                          \
-                    vec_sub(v,                                                \
-                            (vector signed char)                              \
-                                vec_splat((vector signed char) { 128 }, 0));  \
-                                                                              \
-            U = vec_unpackh(u);                                               \
-            V = vec_unpackh(v);                                               \
-                                                                              \
-            Y0 = vec_unh(y0);                                                 \
-            Y1 = vec_unl(y0);                                                 \
-            Y2 = vec_unh(y1);                                                 \
-            Y3 = vec_unl(y1);                                                 \
-                                                                              \
-            Y0 = vec_mradds(Y0, lCY, lOY);                                    \
-            Y1 = vec_mradds(Y1, lCY, lOY);                                    \
-            Y2 = vec_mradds(Y2, lCY, lOY);                                    \
-            Y3 = vec_mradds(Y3, lCY, lOY);                                    \
-                                                                              \
-            /* ux  = (CBU * (u << CSHIFT) + 0x4000) >> 15 */                  \
-            ux  = vec_sl(U, lCSHIFT);                                         \
-            ux  = vec_mradds(ux, lCBU, (vector signed short) { 0 });          \
-            ux0 = vec_mergeh(ux, ux);                                         \
-            ux1 = vec_mergel(ux, ux);                                         \
-                                                                              \
-            /* vx  = (CRV * (v << CSHIFT) + 0x4000) >> 15; */                 \
-            vx  = vec_sl(V, lCSHIFT);                                         \
-            vx  = vec_mradds(vx, lCRV, (vector signed short) { 0 });          \
-            vx0 = vec_mergeh(vx, vx);                                         \
-            vx1 = vec_mergel(vx, vx);                                         \
-                                                                              \
-            /* uvx = ((CGU * u) + (CGV * v)) >> 15 */                         \
-            uvx  = vec_mradds(U, lCGU, (vector signed short) { 0 });          \
-            uvx  = vec_mradds(V, lCGV, uvx);                                  \
-            uvx0 = vec_mergeh(uvx, uvx);                                      \
-            uvx1 = vec_mergel(uvx, uvx);                                      \
-                                                                              \
-            R0 = vec_add(Y0, vx0);                                            \
-            G0 = vec_add(Y0, uvx0);                                           \
-            B0 = vec_add(Y0, ux0);                                            \
-            R1 = vec_add(Y1, vx1);                                            \
-            G1 = vec_add(Y1, uvx1);                                           \
-            B1 = vec_add(Y1, ux1);                                            \
-                                                                              \
-            R = vec_packclp(R0, R1);                                          \
-            G = vec_packclp(G0, G1);                                          \
-            B = vec_packclp(B0, B1);                                          \
-                                                                              \
-            out_pixels(R, G, B, oute);                                        \
-                                                                              \
-            R0 = vec_add(Y2, vx0);                                            \
-            G0 = vec_add(Y2, uvx0);                                           \
-            B0 = vec_add(Y2, ux0);                                            \
-            R1 = vec_add(Y3, vx1);                                            \
-            G1 = vec_add(Y3, uvx1);                                           \
-            B1 = vec_add(Y3, ux1);                                            \
-            R  = vec_packclp(R0, R1);                                         \
-            G  = vec_packclp(G0, G1);                                         \
-            B  = vec_packclp(B0, B1);                                         \
-                                                                              \
-                                                                              \
-            out_pixels(R, G, B, outo);                                        \
-                                                                              \
-            y1i += 16;                                                        \
-            y2i += 16;                                                        \
-            ui  += 8;                                                         \
-            vi  += 8;                                                         \
-        }                                                                     \
-                                                                              \
-        ui  += instrides_scl[1];                                              \
-        vi  += instrides_scl[2];                                              \
-        y1i += instrides_scl[0];                                              \
-        y2i += instrides_scl[0];                                              \
-    }                                                                         \
-    return srcSliceH;                                                         \
-}
-
-#define out_abgr(a, b, c, ptr)                                          \
-    vec_mstrgb32(__typeof__(a), ((__typeof__(a)) vec_splat((__typeof__(a)){ 
255 }, 0)), c, b, a, ptr)
-#define out_bgra(a, b, c, ptr)                                          \
-    vec_mstrgb32(__typeof__(a), c, b, a, ((__typeof__(a)) 
vec_splat((__typeof__(a)){ 255 }, 0)), ptr)
-#define out_rgba(a, b, c, ptr)                                          \
-    vec_mstrgb32(__typeof__(a), a, b, c, ((__typeof__(a)) 
vec_splat((__typeof__(a)){ 255 }, 0)), ptr)
-#define out_argb(a, b, c, ptr)                                          \
-    vec_mstrgb32(__typeof__(a), ((__typeof__(a)) vec_splat((__typeof__(a)){ 
255 }, 0)), a, b, c, ptr)
-#define out_rgb24(a, b, c, ptr) vec_mstrgb24(a, b, c, ptr)
-#define out_bgr24(a, b, c, ptr) vec_mstbgr24(a, b, c, ptr)
-
-DEFCSP420_CVT(yuv2_abgr,  out_abgr)
-DEFCSP420_CVT(yuv2_bgra,  out_bgra)
-DEFCSP420_CVT(yuv2_rgba,  out_rgba)
-DEFCSP420_CVT(yuv2_argb,  out_argb)
-DEFCSP420_CVT(yuv2_rgb24, out_rgb24)
-DEFCSP420_CVT(yuv2_bgr24, out_bgr24)
-
-// uyvy|uyvy|uyvy|uyvy
-// 0123 4567 89ab cdef
-static const vector unsigned char
-    demux_u = { 0x10, 0x00, 0x10, 0x00,
-                0x10, 0x04, 0x10, 0x04,
-                0x10, 0x08, 0x10, 0x08,
-                0x10, 0x0c, 0x10, 0x0c },
-    demux_v = { 0x10, 0x02, 0x10, 0x02,
-                0x10, 0x06, 0x10, 0x06,
-                0x10, 0x0A, 0x10, 0x0A,
-                0x10, 0x0E, 0x10, 0x0E },
-    demux_y = { 0x10, 0x01, 0x10, 0x03,
-                0x10, 0x05, 0x10, 0x07,
-                0x10, 0x09, 0x10, 0x0B,
-                0x10, 0x0D, 0x10, 0x0F };
-
-/*
- * this is so I can play live CCIR raw video
- */
-static int altivec_uyvy_rgb32(SwsInternal *c, const unsigned char *const *in,
-                              const int *instrides, int srcSliceY, int 
srcSliceH,
-                              unsigned char *const *oplanes, const int 
*outstrides)
-{
-    int w = c->opts.src_w;
-    int h = srcSliceH;
-    int i, j;
-    vector unsigned char uyvy;
-    vector signed short Y, U, V;
-    vector signed short R0, G0, B0, R1, G1, B1;
-    vector unsigned char R, G, B;
-    vector unsigned char *out;
-    const ubyte *img;
-
-    img = in[0];
-    out = (vector unsigned char *) (oplanes[0] + srcSliceY * outstrides[0]);
-
-    for (i = 0; i < h; i++)
-        for (j = 0; j < w / 16; j++) {
-            uyvy = vec_ld(0, img);
-
-            U = (vector signed short)
-                    vec_perm(uyvy, (vector unsigned char) { 0 }, demux_u);
-            V = (vector signed short)
-                    vec_perm(uyvy, (vector unsigned char) { 0 }, demux_v);
-            Y = (vector signed short)
-                    vec_perm(uyvy, (vector unsigned char) { 0 }, demux_y);
-
-            cvtyuvtoRGB(c, Y, U, V, &R0, &G0, &B0);
-
-            uyvy = vec_ld(16, img);
-
-            U = (vector signed short)
-                    vec_perm(uyvy, (vector unsigned char) { 0 }, demux_u);
-            V = (vector signed short)
-                    vec_perm(uyvy, (vector unsigned char) { 0 }, demux_v);
-            Y = (vector signed short)
-                    vec_perm(uyvy, (vector unsigned char) { 0 }, demux_y);
-
-            cvtyuvtoRGB(c, Y, U, V, &R1, &G1, &B1);
-
-            R = vec_packclp(R0, R1);
-            G = vec_packclp(G0, G1);
-            B = vec_packclp(B0, B1);
-
-            // vec_mstbgr24 (R,G,B, out);
-            out_rgba(R, G, B, out);
-
-            img += 32;
-        }
-    return srcSliceH;
-}
-
-#endif /* HAVE_ALTIVEC */
-
-/* Ok currently the acceleration routine only supports
- * inputs of widths a multiple of 16
- * and heights a multiple 2
- *
- * So we just fall back to the C codes for this.
- */
-av_cold SwsFunc ff_yuv2rgb_init_ppc(SwsInternal *c)
-{
-#if HAVE_ALTIVEC
-    if (!(av_get_cpu_flags() & AV_CPU_FLAG_ALTIVEC))
-        return NULL;
-
-    /*
-     * and this seems not to matter too much I tried a bunch of
-     * videos with abnormal widths and MPlayer crashes elsewhere.
-     * mplayer -vo x11 -rawvideo on:w=350:h=240 raw-350x240.eyuv
-     * boom with X11 bad match.
-     *
-     */
-    if ((c->opts.src_w & 0xf) != 0)
-        return NULL;
-
-    switch (c->opts.src_format) {
-    case AV_PIX_FMT_YUV410P:
-    case AV_PIX_FMT_YUV420P:
-    /*case IMGFMT_CLPL:        ??? */
-    case AV_PIX_FMT_GRAY8:
-    case AV_PIX_FMT_NV12:
-    case AV_PIX_FMT_NV21:
-        if ((c->opts.src_h & 0x1) != 0)
-            return NULL;
-
-/*
- * The below accelerations for YUV2RGB are known broken.
- * See: 'fate-checkasm-sw_yuv2rgb' with --enable-altivec
- * They are disabled for the moment, until such time as
- * they can be repaired.
- */
-#if 0
-        switch (c->opts.dst_format) {
-        case AV_PIX_FMT_RGB24:
-            av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space RGB24\n");
-            return altivec_yuv2_rgb24;
-        case AV_PIX_FMT_BGR24:
-            av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space BGR24\n");
-            return altivec_yuv2_bgr24;
-        case AV_PIX_FMT_ARGB:
-            av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space ARGB\n");
-            return altivec_yuv2_argb;
-        case AV_PIX_FMT_ABGR:
-            av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space ABGR\n");
-            return altivec_yuv2_abgr;
-        case AV_PIX_FMT_RGBA:
-            av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space RGBA\n");
-            return altivec_yuv2_rgba;
-        case AV_PIX_FMT_BGRA:
-            av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space BGRA\n");
-            return altivec_yuv2_bgra;
-        default: return NULL;
-        }
-#endif /* disabled YUV2RGB acceleration */
-        break;
-
-    case AV_PIX_FMT_UYVY422:
-        switch (c->opts.dst_format) {
-        case AV_PIX_FMT_BGR32:
-            av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space UYVY -> RGB32\n");
-            return altivec_uyvy_rgb32;
-        default: return NULL;
-        }
-        break;
-    }
-#endif /* HAVE_ALTIVEC */
-
-    return NULL;
-}
-
-av_cold void ff_yuv2rgb_init_tables_ppc(SwsInternal *c,
-                                        const int inv_table[4],
-                                        int brightness,
-                                        int contrast,
-                                        int saturation)
-{
-#if HAVE_ALTIVEC
-    union {
-        DECLARE_ALIGNED(16, signed short, tmp)[8];
-        vector signed short vec;
-    } buf;
-
-    if (!(av_get_cpu_flags() & AV_CPU_FLAG_ALTIVEC))
-        return;
-
-    buf.tmp[0] = ((0xffffLL) * contrast >> 8) >> 9;                            
   // cy
-    buf.tmp[1] = -256 * brightness;                                            
   // oy
-    buf.tmp[2] =   (inv_table[0] >> 3) * (contrast >> 16) * (saturation >> 
16);   // crv
-    buf.tmp[3] =   (inv_table[1] >> 3) * (contrast >> 16) * (saturation >> 
16);   // cbu
-    buf.tmp[4] = -((inv_table[2] >> 1) * (contrast >> 16) * (saturation >> 
16));  // cgu
-    buf.tmp[5] = -((inv_table[3] >> 1) * (contrast >> 16) * (saturation >> 
16));  // cgv
-
-    c->CSHIFT = (vector unsigned short) vec_splat_u16(2);
-    c->CY     = vec_splat((vector signed short) buf.vec, 0);
-    c->OY     = vec_splat((vector signed short) buf.vec, 1);
-    c->CRV    = vec_splat((vector signed short) buf.vec, 2);
-    c->CBU    = vec_splat((vector signed short) buf.vec, 3);
-    c->CGU    = vec_splat((vector signed short) buf.vec, 4);
-    c->CGV    = vec_splat((vector signed short) buf.vec, 5);
-    return;
-#endif /* HAVE_ALTIVEC */
-}
-
-#if HAVE_ALTIVEC
-
-static av_always_inline void yuv2packedX_altivec(SwsInternal *c,
-                                                 const int16_t *lumFilter,
-                                                 const int16_t **lumSrc,
-                                                 int lumFilterSize,
-                                                 const int16_t *chrFilter,
-                                                 const int16_t **chrUSrc,
-                                                 const int16_t **chrVSrc,
-                                                 int chrFilterSize,
-                                                 const int16_t **alpSrc,
-                                                 uint8_t *dest,
-                                                 int dstW, int dstY,
-                                                 enum AVPixelFormat target)
-{
-    int i, j;
-    vector signed short X, X0, X1, Y0, U0, V0, Y1, U1, V1, U, V;
-    vector signed short R0, G0, B0, R1, G1, B1;
-
-    vector unsigned char R, G, B;
-    vector unsigned char *out, *nout;
-
-    vector signed short RND   = vec_splat_s16(1 << 3);
-    vector unsigned short SCL = vec_splat_u16(4);
-    DECLARE_ALIGNED(16, unsigned int, scratch)[16];
-
-    vector signed short *YCoeffs, *CCoeffs;
-
-    YCoeffs = c->vYCoeffsBank + dstY * lumFilterSize;
-    CCoeffs = c->vCCoeffsBank + dstY * chrFilterSize;
-
-    out = (vector unsigned char *) dest;
-
-    for (i = 0; i < dstW; i += 16) {
-        Y0 = RND;
-        Y1 = RND;
-        /* extract 16 coeffs from lumSrc */
-        for (j = 0; j < lumFilterSize; j++) {
-            X0 = vec_ld(0, &lumSrc[j][i]);
-            X1 = vec_ld(16, &lumSrc[j][i]);
-            Y0 = vec_mradds(X0, YCoeffs[j], Y0);
-            Y1 = vec_mradds(X1, YCoeffs[j], Y1);
-        }
-
-        U = RND;
-        V = RND;
-        /* extract 8 coeffs from U,V */
-        for (j = 0; j < chrFilterSize; j++) {
-            X = vec_ld(0, &chrUSrc[j][i / 2]);
-            U = vec_mradds(X, CCoeffs[j], U);
-            X = vec_ld(0, &chrVSrc[j][i / 2]);
-            V = vec_mradds(X, CCoeffs[j], V);
-        }
-
-        /* scale and clip signals */
-        Y0 = vec_sra(Y0, SCL);
-        Y1 = vec_sra(Y1, SCL);
-        U  = vec_sra(U, SCL);
-        V  = vec_sra(V, SCL);
-
-        Y0 = vec_clip_s16(Y0);
-        Y1 = vec_clip_s16(Y1);
-        U  = vec_clip_s16(U);
-        V  = vec_clip_s16(V);
-
-        /* now we have
-         * Y0 = y0 y1 y2 y3 y4 y5 y6 y7    Y1 = y8 y9 y10 y11 y12 y13 y14 y15
-         * U  = u0 u1 u2 u3 u4 u5 u6 u7    V  = v0 v1 v2 v3 v4 v5 v6 v7
-         *
-         * Y0 = y0 y1 y2 y3 y4 y5 y6 y7    Y1 = y8 y9 y10 y11 y12 y13 y14 y15
-         * U0 = u0 u0 u1 u1 u2 u2 u3 u3    U1 = u4 u4 u5 u5 u6 u6 u7 u7
-         * V0 = v0 v0 v1 v1 v2 v2 v3 v3    V1 = v4 v4 v5 v5 v6 v6 v7 v7
-         */
-
-        U0 = vec_mergeh(U, U);
-        V0 = vec_mergeh(V, V);
-
-        U1 = vec_mergel(U, U);
-        V1 = vec_mergel(V, V);
-
-        cvtyuvtoRGB(c, Y0, U0, V0, &R0, &G0, &B0);
-        cvtyuvtoRGB(c, Y1, U1, V1, &R1, &G1, &B1);
-
-        R = vec_packclp(R0, R1);
-        G = vec_packclp(G0, G1);
-        B = vec_packclp(B0, B1);
-
-        switch (target) {
-        case AV_PIX_FMT_ABGR:
-            out_abgr(R, G, B, out);
-            break;
-        case AV_PIX_FMT_BGRA:
-            out_bgra(R, G, B, out);
-            break;
-        case AV_PIX_FMT_RGBA:
-            out_rgba(R, G, B, out);
-            break;
-        case AV_PIX_FMT_ARGB:
-            out_argb(R, G, B, out);
-            break;
-        case AV_PIX_FMT_RGB24:
-            out_rgb24(R, G, B, out);
-            break;
-        case AV_PIX_FMT_BGR24:
-            out_bgr24(R, G, B, out);
-            break;
-        default:
-        {
-            /* If this is reached, the caller should have called yuv2packedXinC
-             * instead. */
-            static int printed_error_message;
-            if (!printed_error_message) {
-                av_log(c, AV_LOG_ERROR,
-                       "altivec_yuv2packedX doesn't support %s output\n",
-                       av_get_pix_fmt_name(c->opts.dst_format));
-                printed_error_message = 1;
-            }
-            return;
-        }
-        }
-    }
-
-    if (i < dstW) {
-        i -= 16;
-
-        Y0 = RND;
-        Y1 = RND;
-        /* extract 16 coeffs from lumSrc */
-        for (j = 0; j < lumFilterSize; j++) {
-            X0 = vec_ld(0, &lumSrc[j][i]);
-            X1 = vec_ld(16, &lumSrc[j][i]);
-            Y0 = vec_mradds(X0, YCoeffs[j], Y0);
-            Y1 = vec_mradds(X1, YCoeffs[j], Y1);
-        }
-
-        U = RND;
-        V = RND;
-        /* extract 8 coeffs from U,V */
-        for (j = 0; j < chrFilterSize; j++) {
-            X = vec_ld(0, &chrUSrc[j][i / 2]);
-            U = vec_mradds(X, CCoeffs[j], U);
-            X = vec_ld(0, &chrVSrc[j][i / 2]);
-            V = vec_mradds(X, CCoeffs[j], V);
-        }
-
-        /* scale and clip signals */
-        Y0 = vec_sra(Y0, SCL);
-        Y1 = vec_sra(Y1, SCL);
-        U  = vec_sra(U, SCL);
-        V  = vec_sra(V, SCL);
-
-        Y0 = vec_clip_s16(Y0);
-        Y1 = vec_clip_s16(Y1);
-        U  = vec_clip_s16(U);
-        V  = vec_clip_s16(V);
-
-        /* now we have
-         * Y0 = y0 y1 y2 y3 y4 y5 y6 y7    Y1 = y8 y9 y10 y11 y12 y13 y14 y15
-         * U  = u0 u1 u2 u3 u4 u5 u6 u7    V  = v0 v1 v2 v3 v4 v5 v6 v7
-         *
-         * Y0 = y0 y1 y2 y3 y4 y5 y6 y7    Y1 = y8 y9 y10 y11 y12 y13 y14 y15
-         * U0 = u0 u0 u1 u1 u2 u2 u3 u3    U1 = u4 u4 u5 u5 u6 u6 u7 u7
-         * V0 = v0 v0 v1 v1 v2 v2 v3 v3    V1 = v4 v4 v5 v5 v6 v6 v7 v7
-         */
-
-        U0 = vec_mergeh(U, U);
-        V0 = vec_mergeh(V, V);
-
-        U1 = vec_mergel(U, U);
-        V1 = vec_mergel(V, V);
-
-        cvtyuvtoRGB(c, Y0, U0, V0, &R0, &G0, &B0);
-        cvtyuvtoRGB(c, Y1, U1, V1, &R1, &G1, &B1);
-
-        R = vec_packclp(R0, R1);
-        G = vec_packclp(G0, G1);
-        B = vec_packclp(B0, B1);
-
-        nout = (vector unsigned char *) scratch;
-        switch (target) {
-        case AV_PIX_FMT_ABGR:
-            out_abgr(R, G, B, nout);
-            break;
-        case AV_PIX_FMT_BGRA:
-            out_bgra(R, G, B, nout);
-            break;
-        case AV_PIX_FMT_RGBA:
-            out_rgba(R, G, B, nout);
-            break;
-        case AV_PIX_FMT_ARGB:
-            out_argb(R, G, B, nout);
-            break;
-        case AV_PIX_FMT_RGB24:
-            out_rgb24(R, G, B, nout);
-            break;
-        case AV_PIX_FMT_BGR24:
-            out_bgr24(R, G, B, nout);
-            break;
-        default:
-            /* Unreachable, I think. */
-            av_log(c, AV_LOG_ERROR,
-                   "altivec_yuv2packedX doesn't support %s output\n",
-                   av_get_pix_fmt_name(c->opts.dst_format));
-            return;
-        }
-
-        memcpy(&((uint32_t *) dest)[i], scratch, (dstW - i) / 4);
-    }
-}
-
-#define YUV2PACKEDX_WRAPPER(suffix, pixfmt)                             \
-void ff_yuv2 ## suffix ## _X_altivec(SwsInternal *c,                    \
-                                     const int16_t *lumFilter,          \
-                                     const int16_t **lumSrc,            \
-                                     int lumFilterSize,                 \
-                                     const int16_t *chrFilter,          \
-                                     const int16_t **chrUSrc,           \
-                                     const int16_t **chrVSrc,           \
-                                     int chrFilterSize,                 \
-                                     const int16_t **alpSrc,            \
-                                     uint8_t *dest, int dstW, int dstY) \
-{                                                                       \
-    yuv2packedX_altivec(c, lumFilter, lumSrc, lumFilterSize,            \
-                        chrFilter, chrUSrc, chrVSrc,                    \
-                        chrFilterSize, alpSrc,                          \
-                        dest, dstW, dstY, pixfmt);                      \
-}
-
-YUV2PACKEDX_WRAPPER(abgr,  AV_PIX_FMT_ABGR);
-YUV2PACKEDX_WRAPPER(bgra,  AV_PIX_FMT_BGRA);
-YUV2PACKEDX_WRAPPER(argb,  AV_PIX_FMT_ARGB);
-YUV2PACKEDX_WRAPPER(rgba,  AV_PIX_FMT_RGBA);
-YUV2PACKEDX_WRAPPER(rgb24, AV_PIX_FMT_RGB24);
-YUV2PACKEDX_WRAPPER(bgr24, AV_PIX_FMT_BGR24);
-
-#endif /* HAVE_ALTIVEC */
diff --git a/libswscale/ppc/yuv2yuv_altivec.c b/libswscale/ppc/yuv2yuv_altivec.c
deleted file mode 100644
index 7884c38d69..0000000000
--- a/libswscale/ppc/yuv2yuv_altivec.c
+++ /dev/null
@@ -1,204 +0,0 @@
-/*
- * AltiVec-enhanced yuv-to-yuv conversion routines.
- *
- * Copyright (C) 2004 Romain Dolbeau <[email protected]>
- * based on the equivalent C code in swscale.c
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * 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.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * 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
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#include <inttypes.h>
-
-#include "config.h"
-#include "libavutil/attributes.h"
-#include "libavutil/cpu.h"
-#include "libswscale/swscale.h"
-#include "libswscale/swscale_internal.h"
-
-#if HAVE_ALTIVEC
-
-static int yv12toyuy2_unscaled_altivec(SwsInternal *c, const uint8_t *const 
src[],
-                                       const int srcStride[], int srcSliceY,
-                                       int srcSliceH, uint8_t *const 
dstParam[],
-                                       const int dstStride_a[])
-{
-    uint8_t *dst = dstParam[0] + dstStride_a[0] * srcSliceY;
-    // yv12toyuy2(src[0], src[1], src[2], dst, c->opts.src_w, srcSliceH,
-    //            srcStride[0], srcStride[1], dstStride[0]);
-    const uint8_t *ysrc   = src[0];
-    const uint8_t *usrc   = src[1];
-    const uint8_t *vsrc   = src[2];
-    const int width       = c->opts.src_w;
-    const int height      = srcSliceH;
-    const int lumStride   = srcStride[0];
-    const int chromStride = srcStride[1];
-    const int dstStride   = dstStride_a[0];
-    const vector unsigned char yperm = vec_lvsl(0, ysrc);
-    const int vertLumPerChroma       = 2;
-    register unsigned int y;
-
-    /* This code assumes:
-     *
-     * 1) dst is 16 bytes-aligned
-     * 2) dstStride is a multiple of 16
-     * 3) width is a multiple of 16
-     * 4) lum & chrom stride are multiples of 8
-     */
-
-    for (y = 0; y < height; y++) {
-        int i;
-        for (i = 0; i < width - 31; i += 32) {
-            const unsigned int j          = i >> 1;
-            vector unsigned char v_yA     = vec_ld(i, ysrc);
-            vector unsigned char v_yB     = vec_ld(i + 16, ysrc);
-            vector unsigned char v_yC     = vec_ld(i + 32, ysrc);
-            vector unsigned char v_y1     = vec_perm(v_yA, v_yB, yperm);
-            vector unsigned char v_y2     = vec_perm(v_yB, v_yC, yperm);
-            vector unsigned char v_uA     = vec_ld(j, usrc);
-            vector unsigned char v_uB     = vec_ld(j + 16, usrc);
-            vector unsigned char v_u      = vec_perm(v_uA, v_uB, vec_lvsl(j, 
usrc));
-            vector unsigned char v_vA     = vec_ld(j, vsrc);
-            vector unsigned char v_vB     = vec_ld(j + 16, vsrc);
-            vector unsigned char v_v      = vec_perm(v_vA, v_vB, vec_lvsl(j, 
vsrc));
-            vector unsigned char v_uv_a   = vec_mergeh(v_u, v_v);
-            vector unsigned char v_uv_b   = vec_mergel(v_u, v_v);
-            vector unsigned char v_yuy2_0 = vec_mergeh(v_y1, v_uv_a);
-            vector unsigned char v_yuy2_1 = vec_mergel(v_y1, v_uv_a);
-            vector unsigned char v_yuy2_2 = vec_mergeh(v_y2, v_uv_b);
-            vector unsigned char v_yuy2_3 = vec_mergel(v_y2, v_uv_b);
-            vec_st(v_yuy2_0, (i << 1), dst);
-            vec_st(v_yuy2_1, (i << 1) + 16, dst);
-            vec_st(v_yuy2_2, (i << 1) + 32, dst);
-            vec_st(v_yuy2_3, (i << 1) + 48, dst);
-        }
-        if (i < width) {
-            const unsigned int j          = i >> 1;
-            vector unsigned char v_y1     = vec_ld(i, ysrc);
-            vector unsigned char v_u      = vec_ld(j, usrc);
-            vector unsigned char v_v      = vec_ld(j, vsrc);
-            vector unsigned char v_uv_a   = vec_mergeh(v_u, v_v);
-            vector unsigned char v_yuy2_0 = vec_mergeh(v_y1, v_uv_a);
-            vector unsigned char v_yuy2_1 = vec_mergel(v_y1, v_uv_a);
-            vec_st(v_yuy2_0, (i << 1), dst);
-            vec_st(v_yuy2_1, (i << 1) + 16, dst);
-        }
-        if ((y & (vertLumPerChroma - 1)) == vertLumPerChroma - 1) {
-            usrc += chromStride;
-            vsrc += chromStride;
-        }
-        ysrc += lumStride;
-        dst  += dstStride;
-    }
-
-    return srcSliceH;
-}
-
-static int yv12touyvy_unscaled_altivec(SwsInternal *c, const uint8_t *const 
src[],
-                                       const int srcStride[], int srcSliceY,
-                                       int srcSliceH, uint8_t *const 
dstParam[],
-                                       const int dstStride_a[])
-{
-    uint8_t *dst = dstParam[0] + dstStride_a[0] * srcSliceY;
-    // yv12toyuy2(src[0], src[1], src[2], dst, c->opts.src_w, srcSliceH,
-    //            srcStride[0], srcStride[1], dstStride[0]);
-    const uint8_t *ysrc              = src[0];
-    const uint8_t *usrc              = src[1];
-    const uint8_t *vsrc              = src[2];
-    const int width                  = c->opts.src_w;
-    const int height                 = srcSliceH;
-    const int lumStride              = srcStride[0];
-    const int chromStride            = srcStride[1];
-    const int dstStride              = dstStride_a[0];
-    const int vertLumPerChroma       = 2;
-    const vector unsigned char yperm = vec_lvsl(0, ysrc);
-    register unsigned int y;
-
-    /* This code assumes:
-     *
-     * 1) dst is 16 bytes-aligned
-     * 2) dstStride is a multiple of 16
-     * 3) width is a multiple of 16
-     * 4) lum & chrom stride are multiples of 8
-     */
-
-    for (y = 0; y < height; y++) {
-        int i;
-        for (i = 0; i < width - 31; i += 32) {
-            const unsigned int j          = i >> 1;
-            vector unsigned char v_yA     = vec_ld(i, ysrc);
-            vector unsigned char v_yB     = vec_ld(i + 16, ysrc);
-            vector unsigned char v_yC     = vec_ld(i + 32, ysrc);
-            vector unsigned char v_y1     = vec_perm(v_yA, v_yB, yperm);
-            vector unsigned char v_y2     = vec_perm(v_yB, v_yC, yperm);
-            vector unsigned char v_uA     = vec_ld(j, usrc);
-            vector unsigned char v_uB     = vec_ld(j + 16, usrc);
-            vector unsigned char v_u      = vec_perm(v_uA, v_uB, vec_lvsl(j, 
usrc));
-            vector unsigned char v_vA     = vec_ld(j, vsrc);
-            vector unsigned char v_vB     = vec_ld(j + 16, vsrc);
-            vector unsigned char v_v      = vec_perm(v_vA, v_vB, vec_lvsl(j, 
vsrc));
-            vector unsigned char v_uv_a   = vec_mergeh(v_u, v_v);
-            vector unsigned char v_uv_b   = vec_mergel(v_u, v_v);
-            vector unsigned char v_uyvy_0 = vec_mergeh(v_uv_a, v_y1);
-            vector unsigned char v_uyvy_1 = vec_mergel(v_uv_a, v_y1);
-            vector unsigned char v_uyvy_2 = vec_mergeh(v_uv_b, v_y2);
-            vector unsigned char v_uyvy_3 = vec_mergel(v_uv_b, v_y2);
-            vec_st(v_uyvy_0, (i << 1), dst);
-            vec_st(v_uyvy_1, (i << 1) + 16, dst);
-            vec_st(v_uyvy_2, (i << 1) + 32, dst);
-            vec_st(v_uyvy_3, (i << 1) + 48, dst);
-        }
-        if (i < width) {
-            const unsigned int j          = i >> 1;
-            vector unsigned char v_y1     = vec_ld(i, ysrc);
-            vector unsigned char v_u      = vec_ld(j, usrc);
-            vector unsigned char v_v      = vec_ld(j, vsrc);
-            vector unsigned char v_uv_a   = vec_mergeh(v_u, v_v);
-            vector unsigned char v_uyvy_0 = vec_mergeh(v_uv_a, v_y1);
-            vector unsigned char v_uyvy_1 = vec_mergel(v_uv_a, v_y1);
-            vec_st(v_uyvy_0, (i << 1), dst);
-            vec_st(v_uyvy_1, (i << 1) + 16, dst);
-        }
-        if ((y & (vertLumPerChroma - 1)) == vertLumPerChroma - 1) {
-            usrc += chromStride;
-            vsrc += chromStride;
-        }
-        ysrc += lumStride;
-        dst  += dstStride;
-    }
-    return srcSliceH;
-}
-
-#endif /* HAVE_ALTIVEC */
-
-av_cold void ff_get_unscaled_swscale_ppc(SwsInternal *c)
-{
-#if HAVE_ALTIVEC
-    if (!(av_get_cpu_flags() & AV_CPU_FLAG_ALTIVEC))
-        return;
-
-    if (!(c->opts.src_w & 15) && !(c->opts.flags & SWS_BITEXACT) &&
-        c->opts.src_format == AV_PIX_FMT_YUV420P) {
-        enum AVPixelFormat dstFormat = c->opts.dst_format;
-
-        // unscaled YV12 -> packed YUV, we want speed
-        if (dstFormat == AV_PIX_FMT_YUYV422)
-            c->convert_unscaled = yv12toyuy2_unscaled_altivec;
-        else if (dstFormat == AV_PIX_FMT_UYVY422)
-            c->convert_unscaled = yv12touyvy_unscaled_altivec;
-    }
-#endif /* HAVE_ALTIVEC */
-}
diff --git a/libswscale/swscale.c b/libswscale/swscale.c
index 96df4ed3f4..69c3795cce 100644
--- a/libswscale/swscale.c
+++ b/libswscale/swscale.c
@@ -695,7 +695,7 @@ void ff_sws_init_scale(SwsInternal *c)
 {
     sws_init_swscale(c);
 
-#if ARCH_PPC
+#if ARCH_PPC && !HAVE_BIGENDIAN
     ff_sws_init_swscale_ppc(c);
 #elif ARCH_X86
     ff_sws_init_swscale_x86(c);
diff --git a/libswscale/swscale_internal.h b/libswscale/swscale_internal.h
index 5c58272664..3d85233cb4 100644
--- a/libswscale/swscale_internal.h
+++ b/libswscale/swscale_internal.h
@@ -69,6 +69,8 @@
 
 #define RETCODE_USE_CASCADE -12345
 
+#define SWS_ACCEL_BE_ALTIVEC (AV_HAVE_BIGENDIAN && LIBSWSCALE_VERSION_MAJOR < 
10)
+
 typedef struct SwsInternal SwsInternal;
 
 static inline SwsInternal *sws_internal(const SwsContext *sws)
diff --git a/libswscale/utils.c b/libswscale/utils.c
index 8f8789b24d..8c2d4d7d29 100644
--- a/libswscale/utils.c
+++ b/libswscale/utils.c
@@ -548,7 +548,6 @@ static av_cold int initFilter(int16_t **outFilter, int32_t 
**filterPos,
     }
 
     // Note the +1 is for the MMX scaler which reads over the end
-    /* align at 16 for AltiVec (needed by hScale_altivec_real) */
     if (!FF_ALLOCZ_TYPED_ARRAY(*outFilter, *outFilterSize * (dstW + 3)))
         goto nomem;
 
@@ -980,7 +979,7 @@ int sws_setColorspaceDetails(SwsContext *sws, const int 
inv_table[4],
                                  contrast, saturation);
         // FIXME factorize
 
-#if ARCH_PPC
+#if ARCH_PPC && !HAVE_BIGENDIAN
         ff_yuv2rgb_init_tables_ppc(c, inv_table, brightness,
                                    contrast, saturation);
 #endif
diff --git a/libswscale/version.h b/libswscale/version.h
index 51eb013a29..9de77f8777 100644
--- a/libswscale/version.h
+++ b/libswscale/version.h
@@ -29,7 +29,7 @@
 #include "version_major.h"
 
 #define LIBSWSCALE_VERSION_MINOR   3
-#define LIBSWSCALE_VERSION_MICRO 100
+#define LIBSWSCALE_VERSION_MICRO 101
 
 #define LIBSWSCALE_VERSION_INT  AV_VERSION_INT(LIBSWSCALE_VERSION_MAJOR, \
                                                LIBSWSCALE_VERSION_MINOR, \
-- 
2.49.1

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to