Commit 1cfb18f66f for ffmpeg

commit 1cfb18f66fa1553855ac328859429ef348af4799
Author: Kacper Michajłow <kasper93@gmail.com>
Date:   Mon Oct 26 14:38:37 2026 +0100

    swscale/ppc: set up the coefficient banks outside the AltiVec code

    ff_sws_init_altivec_bufs() and ff_sws_free_altivec_bufs() run for every
    context on every CPU and fill the banks with plain C. Keep the bank
    pointers in SwsInternal as pointers to arrays of 8 int16_t, which need
    no AltiVec header, and move the two functions to a file without AltiVec
    code.

    Signed-off-by: Kacper Michajłow <kasper93@gmail.com>

diff --git a/libswscale/ppc/Makefile b/libswscale/ppc/Makefile
index 0a31a3025b..7d28e71bd2 100644
--- a/libswscale/ppc/Makefile
+++ b/libswscale/ppc/Makefile
@@ -1,4 +1,5 @@
 OBJS += ppc/swscale_altivec.o                                           \
+        ppc/yuv2rgb.o                                                   \
         ppc/yuv2rgb_altivec.o                                           \
         ppc/yuv2yuv_altivec.o                                           \
         ppc/swscale_vsx.o
diff --git a/libswscale/ppc/yuv2rgb.c b/libswscale/ppc/yuv2rgb.c
new file mode 100644
index 0000000000..a4735b734f
--- /dev/null
+++ b/libswscale/ppc/yuv2rgb.c
@@ -0,0 +1,57 @@
+/*
+ * 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 "config.h"
+
+#include "libavutil/attributes.h"
+#include "libavutil/error.h"
+#include "libavutil/mem.h"
+
+#include "libswscale/swscale_internal.h"
+
+#if HAVE_ALTIVEC
+av_cold int ff_sws_init_altivec_bufs(SwsInternal *c)
+{
+    const SwsContext *const sws = &c->opts;
+
+    c->vYCoeffsBank = av_malloc_array(sws->dst_h, c->vLumFilterSize * sizeof(*c->vYCoeffsBank));
+    c->vCCoeffsBank = av_malloc_array(c->chrDstH, c->vChrFilterSize * sizeof(*c->vCCoeffsBank));
+    if (!c->vYCoeffsBank || !c->vCCoeffsBank)
+        return AVERROR(ENOMEM);
+
+    for (int i = 0; i < c->vLumFilterSize * sws->dst_h; ++i) {
+        short *p = (short *)&c->vYCoeffsBank[i];
+        for (int j = 0; j < 8; ++j)
+            p[j] = c->vLumFilter[i];
+    }
+
+    for (int i = 0; i < c->vChrFilterSize * c->chrDstH; ++i) {
+        short *p = (short *)&c->vCCoeffsBank[i];
+        for (int j = 0; j < 8; ++j)
+            p[j] = c->vChrFilter[i];
+    }
+
+    return 0;
+}
+
+av_cold void ff_sws_free_altivec_bufs(SwsInternal *c)
+{
+    av_freep(&c->vYCoeffsBank);
+    av_freep(&c->vCCoeffsBank);
+}
+#endif /* HAVE_ALTIVEC */
diff --git a/libswscale/ppc/yuv2rgb_altivec.c b/libswscale/ppc/yuv2rgb_altivec.c
index 1038896ca7..7822ff102a 100644
--- a/libswscale/ppc/yuv2rgb_altivec.c
+++ b/libswscale/ppc/yuv2rgb_altivec.c
@@ -96,8 +96,6 @@
 #include "libswscale/swscale_internal.h"
 #include "libavutil/attributes.h"
 #include "libavutil/cpu.h"
-#include "libavutil/error.h"
-#include "libavutil/mem.h"
 #include "libavutil/mem_internal.h"
 #include "libavutil/pixdesc.h"
 #include "yuv2rgb_altivec.h"
@@ -119,7 +117,6 @@ typedef struct SwsInternalAltivec {
     vector signed short   CGV;
     vector signed short   OY;
     vector unsigned short CSHIFT;
-    vector signed short  *vYCoeffsBank, *vCCoeffsBank;
 } SwsInternalAltivec;
 // Check that the sizes of the types match.
 // Note that given that SwsInternal is always allocated via av_malloc,
@@ -685,8 +682,6 @@ static av_always_inline void yuv2packedX_altivec(SwsInternal *c,
                                                  int dstW, int dstY,
                                                  enum AVPixelFormat target)
 {
-    SwsInternalAltivec *const a = sws_internal_altivec(c);
-
     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;
@@ -700,8 +695,8 @@ static av_always_inline void yuv2packedX_altivec(SwsInternal *c,

     vector signed short *YCoeffs, *CCoeffs;

-    YCoeffs = a->vYCoeffsBank + dstY * lumFilterSize;
-    CCoeffs = a->vCCoeffsBank + dstY * chrFilterSize;
+    YCoeffs = (vector signed short *)(c->vYCoeffsBank + dstY * lumFilterSize);
+    CCoeffs = (vector signed short *)(c->vCCoeffsBank + dstY * chrFilterSize);

     out = (vector unsigned char *) dest;

@@ -905,36 +900,4 @@ 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);
-
-av_cold int ff_sws_init_altivec_bufs(SwsInternal *c)
-{
-    const SwsContext *const sws = &c->opts;
-    SwsInternalAltivec *const a = sws_internal_altivec(c);
-
-    a->vYCoeffsBank = av_malloc_array(sws->dst_h, c->vLumFilterSize * sizeof(*a->vYCoeffsBank));
-    a->vCCoeffsBank = av_malloc_array(c->chrDstH, c->vChrFilterSize * sizeof(*a->vCCoeffsBank));
-    if (!a->vYCoeffsBank || !a->vCCoeffsBank)
-        return AVERROR(ENOMEM);
-
-    for (int i = 0; i < c->vLumFilterSize * sws->dst_h; ++i) {
-        short *p = (short *)&a->vYCoeffsBank[i];
-        for (int j = 0; j < 8; ++j)
-            p[j] = c->vLumFilter[i];
-    }
-
-    for (int i = 0; i < c->vChrFilterSize * c->chrDstH; ++i) {
-        short *p = (short *)&a->vCCoeffsBank[i];
-        for (int j = 0; j < 8; ++j)
-            p[j] = c->vChrFilter[i];
-    }
-
-    return 0;
-}
-
-av_cold void ff_sws_free_altivec_bufs(SwsInternal *c)
-{
-    SwsInternalAltivec *const a = sws_internal_altivec(c);
-    av_freep(&a->vYCoeffsBank);
-    av_freep(&a->vCCoeffsBank);
-}
 #endif /* HAVE_ALTIVEC */
diff --git a/libswscale/swscale_internal.h b/libswscale/swscale_internal.h
index dd296f30d1..78b4d6bfd3 100644
--- a/libswscale/swscale_internal.h
+++ b/libswscale/swscale_internal.h
@@ -41,7 +41,7 @@
 #include "libavutil/half2float.h"

 #if HAVE_ALTIVEC
-#define SWSINTERNAL_ADDITIONAL_ASM_SIZE (7*16 + 2*8 + /* alignment */ 16)
+#define SWSINTERNAL_ADDITIONAL_ASM_SIZE (7*16 + /* alignment */ 16)
 #endif
 #ifndef SWSINTERNAL_ADDITIONAL_ASM_SIZE
 #define SWSINTERNAL_ADDITIONAL_ASM_SIZE 0
@@ -550,6 +550,10 @@ struct SwsInternal {

     const uint8_t *chrDither8, *lumDither8;

+#if HAVE_ALTIVEC
+    int16_t (*vYCoeffsBank)[8], (*vCCoeffsBank)[8];
+#endif
+
     int use_mmx_vfilter;

     SwsColorFunc  xyz12Torgb48;