From 0fe869a199552d004205cbd4de72c7da2c04d923 Mon Sep 17 00:00:00 2001
From: user <user@localhost>
Date: Tue, 3 Feb 2026 07:09:50 +0100
Subject: [PATCH 1/2] ppc: fix sad_x4 init and adjust chroma shift

---
 common/ppc/mc.c    | 18 ++++++++++++------
 common/ppc/pixel.c |  1 +
 2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/common/ppc/mc.c b/common/ppc/mc.c
index 87482ea6..972f6a93 100644
--- a/common/ppc/mc.c
+++ b/common/ppc/mc.c
@@ -429,6 +429,12 @@ static void mc_chroma_2xh( uint8_t *dstu, uint8_t *dstv, intptr_t i_dst_stride,
 #define VSLD(a,b,n) vec_sld(b,a,16-n)
 #endif
 
+#ifdef WORDS_BIGENDIAN
+#define VSLD_CHROMA(a,b,n) vec_sld(a,b,n)
+#else
+#define VSLD_CHROMA(a,b,n) vec_sld(a,b,n)
+#endif
+
 #ifndef __POWER9_VECTOR__
 #define STORE4_ALIGNED(d, s) vec_ste( (vec_u32_t)s, 0, (uint32_t*) d )
 #define STORE2_UNALIGNED(d, s) vec_ste( vec_splat( (vec_u16_t)s, 0 ), 0, (uint16_t*)d )
@@ -478,7 +484,7 @@ static void mc_chroma_4xh_altivec( uint8_t *dstu, uint8_t *dstv, intptr_t i_dst_
 
     src2v_8 = vec_vsx_ld( 0, src );
     src2v_16 = vec_u8_to_u16( src2v_8 );
-    src3v_16 = vec_u8_to_u16( VSLD( src2v_8, src2v_8, 2 ) );
+    src3v_16 = vec_u8_to_u16( VSLD_CHROMA( src2v_8, src2v_8, 2 ) );
 
     for( int y = 0; y < i_height; y += 2 )
     {
@@ -486,7 +492,7 @@ static void mc_chroma_4xh_altivec( uint8_t *dstu, uint8_t *dstv, intptr_t i_dst_
         src1v_16 = src3v_16;
         src2v_8 = vec_vsx_ld( 0, srcp );
         src2v_16 = vec_u8_to_u16( src2v_8 );
-        src3v_16 = vec_u8_to_u16( VSLD( src2v_8, src2v_8, 2 ) );
+        src3v_16 = vec_u8_to_u16( VSLD_CHROMA( src2v_8, src2v_8, 2 ) );
 
         dstv16 = vec_mladd( coeff0v, src0v_16, k32v );
         dstv16 = vec_mladd( coeff1v, src1v_16, dstv16 );
@@ -508,7 +514,7 @@ static void mc_chroma_4xh_altivec( uint8_t *dstu, uint8_t *dstv, intptr_t i_dst_
         src1v_16 = src3v_16;
         src2v_8 = vec_vsx_ld( 0, srcp );
         src2v_16 = vec_u8_to_u16( src2v_8 );
-        src3v_16 = vec_u8_to_u16( VSLD( src2v_8, src2v_8, 2 ) );
+        src3v_16 = vec_u8_to_u16( VSLD_CHROMA( src2v_8, src2v_8, 2 ) );
 
         dstv16 = vec_mladd( coeff0v, src0v_16, k32v );
         dstv16 = vec_mladd( coeff1v, src1v_16, dstv16 );
@@ -571,7 +577,7 @@ static void mc_chroma_8xh_altivec( uint8_t *dstu, uint8_t *dstv, intptr_t i_dst_
 
     src2v_8 = vec_vsx_ld( 0, src );
     src3v_8 = vec_vsx_ld( 16, src );
-    src3v_8 = VSLD( src2v_8, src3v_8, 2 );
+    src3v_8 = VSLD_CHROMA( src2v_8, src3v_8, 2 );
 
     for( int y = 0; y < i_height; y += 2 )
     {
@@ -580,7 +586,7 @@ static void mc_chroma_8xh_altivec( uint8_t *dstu, uint8_t *dstv, intptr_t i_dst_
         src2v_8 = vec_vsx_ld( 0, srcp );
         src3v_8 = vec_vsx_ld( 16, srcp );
 
-        src3v_8 = VSLD( src2v_8, src3v_8, 2 );
+        src3v_8 = VSLD_CHROMA( src2v_8, src3v_8, 2 );
 
         src0v_16h = vec_u8_to_u16_h( src0v_8 );
         src0v_16l = vec_u8_to_u16_l( src0v_8 );
@@ -618,7 +624,7 @@ static void mc_chroma_8xh_altivec( uint8_t *dstu, uint8_t *dstv, intptr_t i_dst_
         src2v_8 = vec_vsx_ld( 0, srcp );
         src3v_8 = vec_vsx_ld( 16, srcp );
 
-        src3v_8 = VSLD( src2v_8, src3v_8, 2 );
+        src3v_8 = VSLD_CHROMA( src2v_8, src3v_8, 2 );
 
         src0v_16h = vec_u8_to_u16_h( src0v_8 );
         src0v_16l = vec_u8_to_u16_l( src0v_8 );
diff --git a/common/ppc/pixel.c b/common/ppc/pixel.c
index 3d4de59f..37cf52af 100644
--- a/common/ppc/pixel.c
+++ b/common/ppc/pixel.c
@@ -981,6 +981,7 @@ static void name( uint8_t *fenc,
     sum0v = vec_splat_s32( 0 );                                                       \
     sum1v = vec_splat_s32( 0 );                                                       \
     sum2v = vec_splat_s32( 0 );                                                       \
+    sum3v = vec_splat_s32( 0 );                                                       \
                                                                                       \
     for( int y = 0; y < ly; y++ )                                                     \
     {                                                                                 \
-- 
GitLab


From c59c96c91c11bf84a5ecb34a56e2b649a8a4fc80 Mon Sep 17 00:00:00 2001
From: user <user@localhost>
Date: Tue, 3 Feb 2026 07:36:22 +0100
Subject: [PATCH 2/2] Fix altivec chroma coeff and shift on LE

---
 common/ppc/mc.c | 38 +++++++++++++++++---------------------
 1 file changed, 17 insertions(+), 21 deletions(-)

diff --git a/common/ppc/mc.c b/common/ppc/mc.c
index 972f6a93..e4dbd619 100644
--- a/common/ppc/mc.c
+++ b/common/ppc/mc.c
@@ -432,7 +432,7 @@ static void mc_chroma_2xh( uint8_t *dstu, uint8_t *dstv, intptr_t i_dst_stride,
 #ifdef WORDS_BIGENDIAN
 #define VSLD_CHROMA(a,b,n) vec_sld(a,b,n)
 #else
-#define VSLD_CHROMA(a,b,n) vec_sld(a,b,n)
+#define VSLD_CHROMA(a,b,n) vec_sld(b,a,16-n)
 #endif
 
 #ifndef __POWER9_VECTOR__
@@ -451,11 +451,10 @@ static void mc_chroma_4xh_altivec( uint8_t *dstu, uint8_t *dstv, intptr_t i_dst_
     int d8x = mvx & 0x07;
     int d8y = mvy & 0x07;
 
-    ALIGNED_16( uint16_t coeff[4] );
-    coeff[0] = (8-d8x)*(8-d8y);
-    coeff[1] = d8x    *(8-d8y);
-    coeff[2] = (8-d8x)*d8y;
-    coeff[3] = d8x    *d8y;
+    uint16_t coeff0 = (uint16_t)( (8-d8x)*(8-d8y) );
+    uint16_t coeff1 = (uint16_t)( d8x    *(8-d8y) );
+    uint16_t coeff2 = (uint16_t)( (8-d8x)*d8y );
+    uint16_t coeff3 = (uint16_t)( d8x    *d8y );
 
     src += (mvy >> 3) * i_src_stride + (mvx >> 3)*2;
     srcp = &src[i_src_stride];
@@ -474,11 +473,10 @@ static void mc_chroma_4xh_altivec( uint8_t *dstu, uint8_t *dstv, intptr_t i_dst_
     static const vec_u8_t perm1v = CV(2,6,10,14,2,6,10,14,2,6,10,14,2,6,10,14);
 #endif
 
-    coeff0v = vec_ld( 0, coeff );
-    coeff3v = vec_splat( coeff0v, 3 );
-    coeff2v = vec_splat( coeff0v, 2 );
-    coeff1v = vec_splat( coeff0v, 1 );
-    coeff0v = vec_splat( coeff0v, 0 );
+    coeff0v = vec_splats( coeff0 );
+    coeff1v = vec_splats( coeff1 );
+    coeff2v = vec_splats( coeff2 );
+    coeff3v = vec_splats( coeff3 );
     k32v    = vec_sl( vec_splat_u16( 1 ), vec_splat_u16( 5 ) );
     shiftv  = vec_splat_u16( 6 );
 
@@ -542,11 +540,10 @@ static void mc_chroma_8xh_altivec( uint8_t *dstu, uint8_t *dstv, intptr_t i_dst_
     int d8x = mvx & 0x07;
     int d8y = mvy & 0x07;
 
-    ALIGNED_16( uint16_t coeff[4] );
-    coeff[0] = (8-d8x)*(8-d8y);
-    coeff[1] = d8x    *(8-d8y);
-    coeff[2] = (8-d8x)*d8y;
-    coeff[3] = d8x    *d8y;
+    uint16_t coeff0 = (uint16_t)( (8-d8x)*(8-d8y) );
+    uint16_t coeff1 = (uint16_t)( d8x    *(8-d8y) );
+    uint16_t coeff2 = (uint16_t)( (8-d8x)*d8y );
+    uint16_t coeff3 = (uint16_t)( d8x    *d8y );
 
     src += (mvy >> 3) * i_src_stride + (mvx >> 3)*2;
     srcp = &src[i_src_stride];
@@ -559,11 +556,10 @@ static void mc_chroma_8xh_altivec( uint8_t *dstu, uint8_t *dstv, intptr_t i_dst_
     vec_u16_t   src0v_16l, src1v_16l, src2v_16l, src3v_16l, dstv_16l;
     vec_u16_t   shiftv, k32v;
 
-    coeff0v = vec_ld( 0, coeff );
-    coeff3v = vec_splat( coeff0v, 3 );
-    coeff2v = vec_splat( coeff0v, 2 );
-    coeff1v = vec_splat( coeff0v, 1 );
-    coeff0v = vec_splat( coeff0v, 0 );
+    coeff0v = vec_splats( coeff0 );
+    coeff1v = vec_splats( coeff1 );
+    coeff2v = vec_splats( coeff2 );
+    coeff3v = vec_splats( coeff3 );
     k32v    = vec_sl( vec_splat_u16( 1 ), vec_splat_u16( 5 ) );
     shiftv  = vec_splat_u16( 6 );
 
-- 
GitLab

