[FFmpeg-devel,V3] swscale/ppc/yuv2rgb_altivec: Fixes compiler bug - replace vec_lvsl/vec_perm with vec_xl

Submitted by ckerchne on Aug. 12, 2019, 3:44 p.m.

Details

Message ID c3e6b6b833bbf832253cf6093e69a98e@linux.vnet.ibm.com
State New
Headers show

Commit Message

ckerchne Aug. 12, 2019, 3:44 p.m.
A bug exist with the gcc compilers for Power in versions 6.x and 7.x 
(verified with 6.3 and 7.4). It was fixed in version 8.x (verified with 
8.3). I was using a Power 9 ppc64le machine for building and testing.

It appears the compiler is generating the wrong code for little endian 
machines for the vec_lvsl/vec_perm instruction combos in some cases. If 
these instructions are replaced with vec_xl, the problem goes away for 
all versions of the compilers (plus it is a bit faster).

Fixes #7124 and can be reproduced within the docker by following the 
instructions within the ticket.

https://trac.ffmpeg.org/ticket/7124

Comments

Lauri Kasanen Aug. 24, 2019, 5:25 p.m.
Hi,

This change uses VSX code in a function marked Altivec, aka it makes it
not work on pre-power7 (macs, etc). As such I would've NAK'd it.

- Lauri
Carl Eugen Hoyos Aug. 24, 2019, 5:35 p.m.
Am Sa., 24. Aug. 2019 um 19:25 Uhr schrieb Lauri Kasanen <cand@gmx.com>:
>
> Hi,
>
> This change uses VSX code in a function marked Altivec, aka it makes it
> not work on pre-power7 (macs, etc). As such I would've NAK'd it.

Please send a patch.

Atm, I only have access to power7 and newer.

Carl Eugen

Patch hide | download patch | download mbox

diff --git a/libswscale/ppc/yuv2rgb_altivec.c b/libswscale/ppc/yuv2rgb_altivec.c
index c1e2852adb..536545293d 100644
--- a/libswscale/ppc/yuv2rgb_altivec.c
+++ b/libswscale/ppc/yuv2rgb_altivec.c
@@ -305,9 +305,6 @@  static int altivec_ ## name(SwsContext *c, const unsigned char **in,          \
     vector signed short R1, G1, B1;                                           \
     vector unsigned char R, G, B;                                             \
                                                                               \
-    const vector unsigned char *y1ivP, *y2ivP, *uivP, *vivP;                  \
-    vector unsigned char align_perm;                                          \
-                                                                              \
     vector signed short lCY       = c->CY;                                    \
     vector signed short lOY       = c->OY;                                    \
     vector signed short lCRV      = c->CRV;                                   \
@@ -338,26 +335,13 @@  static int altivec_ ## name(SwsContext *c, const unsigned char **in,          \
         vec_dstst(oute, (0x02000002 | (((w * 3 + 32) / 32) << 16)), 1);       \
                                                                               \
         for (j = 0; j < w / 16; j++) {                                        \
-            y1ivP = (const vector unsigned char *) y1i;                       \
-            y2ivP = (const vector unsigned char *) y2i;                       \
-            uivP  = (const vector unsigned char *) ui;                        \
-            vivP  = (const vector unsigned char *) vi;                        \
-                                                                              \
-            align_perm = vec_lvsl(0, y1i);                                    \
-            y0 = (vector unsigned char)                                       \
-                     vec_perm(y1ivP[0], y1ivP[1], align_perm);                \
+            y0 = vec_xl(0, y1i);                                              \
                                                                               \
-            align_perm = vec_lvsl(0, y2i);                                    \
-            y1 = (vector unsigned char)                                       \
-                     vec_perm(y2ivP[0], y2ivP[1], align_perm);                \
+            y1 = vec_xl(0, y2i);                                              \
                                                                               \
-            align_perm = vec_lvsl(0, ui);                                     \
-            u = (vector signed char)                                          \
-                    vec_perm(uivP[0], uivP[1], align_perm);                   \
+            u = (vector signed char) vec_xl(0, ui);                           \
                                                                               \
-            align_perm = vec_lvsl(0, vi);                                     \
-            v = (vector signed char)                                          \
-                    vec_perm(vivP[0], vivP[1], align_perm);                   \
+            v = (vector signed char) vec_xl(0, vi);                           \
                                                                               \
             u = (vector signed char)                                          \
                     vec_sub(u,                                                \