[MPlayer-dev-eng] altivec fixes for pre5

Guido Guenther agx at sigxcpu.org
Sat Jul 31 17:43:00 CEST 2004


Hi,
the attached patch gets make mplayer pre5 build again on linux-powerpc.
I've moved gcc_fixes.h to osdep/ since several subdirs can make use of it.
Please apply.
Cheers,
 -- Guido
-------------- next part --------------
--- postproc/swscale_internal.h.orig	2004-07-31 14:18:42.225819568 +0200
+++ postproc/swscale_internal.h	2004-07-31 14:19:30.003556248 +0200
@@ -19,6 +19,10 @@
 #ifndef SWSCALE_INTERNAL_H
 #define SWSCALE_INTERNAL_H
 
+#ifdef HAVE_ALTIVEC
+#include <altivec.h>
+#endif
+
 #include "../mp_msg.h"
 
 #define MSG_WARN(args...) mp_msg(MSGT_SWS,MSGL_WARN, ##args )
--- postproc/yuv2rgb_altivec.c.orig	2004-07-31 15:50:19.101167496 +0200
+++ postproc/yuv2rgb_altivec.c	2004-07-31 16:33:08.293590880 +0200
@@ -72,6 +72,7 @@
 #include "swscale_internal.h"
 #include "../mangle.h"
 #include "../libvo/img_format.h" //FIXME try to reduce dependency of such stuff
+#include <osdep/gcc_fixes.h>
 
 #undef PROFILE_THE_BEAST
 #undef INC_SCALING
@@ -118,13 +119,13 @@
 */
 static
 const vector unsigned char
-  perm_rgb_0 = (vector unsigned char)(0x00,0x01,0x10,0x02,0x03,0x11,0x04,0x05,
+  perm_rgb_0 = (const vector unsigned char)AVV(0x00,0x01,0x10,0x02,0x03,0x11,0x04,0x05,
 				      0x12,0x06,0x07,0x13,0x08,0x09,0x14,0x0a),
-  perm_rgb_1 = (vector unsigned char)(0x0b,0x15,0x0c,0x0d,0x16,0x0e,0x0f,0x17,
+  perm_rgb_1 = (const vector unsigned char)AVV(0x0b,0x15,0x0c,0x0d,0x16,0x0e,0x0f,0x17,
 				      0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f),
-  perm_rgb_2 = (vector unsigned char)(0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,
+  perm_rgb_2 = (const vector unsigned char)AVV(0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,
 				      0x00,0x01,0x18,0x02,0x03,0x19,0x04,0x05),
-  perm_rgb_3 = (vector unsigned char)(0x1a,0x06,0x07,0x1b,0x08,0x09,0x1c,0x0a,
+  perm_rgb_3 = (const vector unsigned char)AVV(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)    \
@@ -197,25 +198,25 @@
 
 #define vec_unh(x) \
   (vector signed short) \
-    vec_perm(x,(typeof(x))(0),\
-             (vector unsigned char)(0x10,0x00,0x10,0x01,0x10,0x02,0x10,0x03,\
+    vec_perm(x,(typeof(x))AVV(0),\
+             (vector unsigned char)AVV(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,\
+    vec_perm(x,(typeof(x))AVV(0),\
+             (vector unsigned char)AVV(0x10,0x08,0x10,0x09,0x10,0x0A,0x10,0x0B,\
                                     0x10,0x0C,0x10,0x0D,0x10,0x0E,0x10,0x0F))
 
 #define vec_clip(x) \
-  vec_max (vec_min (x, (typeof(x))(255)), (typeof(x))(0))
+  vec_max (vec_min (x, (typeof(x))AVV(255)), (typeof(x))AVV(0))
 
 #define vec_packclp_a(x,y) \
   (vector unsigned char)vec_pack (vec_clip (x), vec_clip (y))
 
 #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)))
+      ((vector unsigned short)vec_max (x,(vector signed short)AVV(0)), \
+       (vector unsigned short)vec_max (y,(vector signed short)AVV(0)))
 
 //#define out_pixels(a,b,c,ptr) vec_mstrgb32(typeof(a),((typeof (a))(0)),a,a,a,ptr)
 
@@ -228,8 +229,8 @@
 
   Y = vec_mradds (Y, c->CY, c->OY);
 
-  U = vec_sub (U,(vector signed short)(128));
-  V = vec_sub (V,(vector signed short)(128));
+  U = vec_sub (U,(vector signed short)AVV(128));
+  V = vec_sub (V,(vector signed short)AVV(128));
 
   //   ux  = (CBU*(u<<c->CSHIFT)+0x4000)>>15;
   ux = vec_sl (U, c->CSHIFT);
@@ -323,8 +324,8 @@
       align_perm = vec_lvsl (0, vi);					   \
       v = (vector signed char)vec_perm (vivP[0], vivP[1], align_perm);	   \
 									   \
-      u  = (vector signed char)vec_sub (u, (vector signed char)(128));	   \
-      v  = (vector signed char)vec_sub (v, (vector signed char)(128));	   \
+      u  = (vector signed char)vec_sub (u, (vector signed char)AVV(128));  \
+      v  = (vector signed char)vec_sub (v, (vector signed char)AVV(128));  \
       U  = vec_unpackh (u);						   \
       V  = vec_unpackh (v);						   \
 									   \
@@ -341,18 +342,18 @@
 									   \
 	/*   ux  = (CBU*(u<<CSHIFT)+0x4000)>>15 */			   \
 	ux = vec_sl (U, lCSHIFT);					   \
-	ux = vec_mradds (ux, lCBU, (vector signed short)(0));		   \
+	ux = vec_mradds (ux, lCBU, (vector signed short)AVV(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));		   \
+	vx = vec_mradds (vx, lCRV, (vector signed short)AVV(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 (U, lCGU, (vector signed short)AVV(0));	   \
 	uvx = vec_mradds (V, lCGV, uvx);				   \
 	uvx0 = vec_mergeh (uvx,uvx);					   \
 	uvx1 = vec_mergel (uvx,uvx);					   \
@@ -402,10 +403,10 @@
 }
 
 
-#define out_abgr(a,b,c,ptr)  vec_mstrgb32(typeof(a),((typeof (a))(0)),c,b,a,ptr)
-#define out_bgra(a,b,c,ptr)  vec_mstrgb32(typeof(a),c,b,a,((typeof (a))(0)),ptr)
-#define out_rgba(a,b,c,ptr)  vec_mstrgb32(typeof(a),a,b,c,((typeof (a))(0)),ptr)
-#define out_argb(a,b,c,ptr)  vec_mstrgb32(typeof(a),((typeof (a))(0)),a,b,c,ptr)
+#define out_abgr(a,b,c,ptr)  vec_mstrgb32(typeof(a),((typeof (a))AVV(0)),c,b,a,ptr)
+#define out_bgra(a,b,c,ptr)  vec_mstrgb32(typeof(a),c,b,a,((typeof (a))AVV(0)),ptr)
+#define out_rgba(a,b,c,ptr)  vec_mstrgb32(typeof(a),a,b,c,((typeof (a))AVV(0)),ptr)
+#define out_argb(a,b,c,ptr)  vec_mstrgb32(typeof(a),((typeof (a))AVV(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_mstrgb24(c,b,a,ptr)
 
@@ -421,15 +422,15 @@
 // 0123 4567 89ab cdef
 static
 const vector unsigned char
-  demux_u = (vector unsigned char)(0x10,0x00,0x10,0x00,
+  demux_u = (vector unsigned char)AVV(0x10,0x00,0x10,0x00,
 				   0x10,0x04,0x10,0x04,
 				   0x10,0x08,0x10,0x08,
 				   0x10,0x0c,0x10,0x0c),
-  demux_v = (vector unsigned char)(0x10,0x02,0x10,0x02,
+  demux_v = (vector unsigned char)AVV(0x10,0x02,0x10,0x02,
 				   0x10,0x06,0x10,0x06,
 				   0x10,0x0A,0x10,0x0A,
 				   0x10,0x0E,0x10,0x0E),
-  demux_y = (vector unsigned char)(0x10,0x01,0x10,0x03,
+  demux_y = (vector unsigned char)AVV(0x10,0x01,0x10,0x03,
 				   0x10,0x05,0x10,0x07,
 				   0x10,0x09,0x10,0x0B,
 				   0x10,0x0D,0x10,0x0F);
@@ -460,25 +461,25 @@
     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);
+	vec_perm (uyvy, (vector unsigned char)AVV(0), demux_u);
 
       V = (vector signed short)
-	vec_perm (uyvy, (vector unsigned char)(0), demux_v);
+	vec_perm (uyvy, (vector unsigned char)AVV(0), demux_v);
 
       Y = (vector signed short)
-	vec_perm (uyvy, (vector unsigned char)(0), demux_y);
+	vec_perm (uyvy, (vector unsigned char)AVV(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);
+	vec_perm (uyvy, (vector unsigned char)AVV(0), demux_u);
 
       V = (vector signed short)
-	vec_perm (uyvy, (vector unsigned char)(0), demux_v);
+	vec_perm (uyvy, (vector unsigned char)AVV(0), demux_v);
 
       Y = (vector signed short)
-	vec_perm (uyvy, (vector unsigned char)(0), demux_y);
+	vec_perm (uyvy, (vector unsigned char)AVV(0), demux_y);
 
       cvtyuvtoRGB (c, Y,U,V,&R1,&G1,&B1);
 
@@ -570,14 +571,14 @@
 {
 
   vector signed short
-    CY  = (vector signed short)(0x7fff),
-    CRV = (vector signed short)(22972),
-    CBU = (vector signed short)(29029),
-    CGU = (vector signed short)(-11276),
-    CGV = (vector signed short)(-23400),
+    CY  = (vector signed short)AVV(0x7fff),
+    CRV = (vector signed short)AVV(22972),
+    CBU = (vector signed short)AVV(29029),
+    CGU = (vector signed short)AVV(-11276),
+    CGV = (vector signed short)AVV(-23400),
     OY;
 
-  vector unsigned short CSHIFT = (vector unsigned short)(1);
+  vector unsigned short CSHIFT = (vector unsigned short)AVV(1);
 
   vector signed short Y0;
   int brightness = c->brightness,  contrast = c->contrast,  saturation = c->saturation;
@@ -643,7 +644,7 @@
   CGV = vec_lde (0, &tmp);
   CGV  = vec_splat (CGV, 0);
 
-  CSHIFT = (vector unsigned short)(2);
+  CSHIFT = (vector unsigned short)AVV(2);
 #if 1
   c->CSHIFT = CSHIFT;
   c->CY = CY;
@@ -679,8 +680,8 @@
 
   vector unsigned char R,G,B,pels[3];
   vector unsigned char *out,*nout;
-  vector signed short   RND = (vector signed short)(1<<3);
-  vector unsigned short SCL = (vector unsigned short)(4);
+  vector signed short   RND = (vector signed short)AVV(1<<3);
+  vector unsigned short SCL = (vector unsigned short)AVV(4);
   unsigned long scratch[16] __attribute__ ((aligned (16)));
 
   vector signed short *vYCoeffsBank, *vCCoeffsBank;
@@ -832,5 +833,3 @@
   if (vCCoeffsBank) free (vCCoeffsBank);
 
 }
-
-
--- libvo/vo_x11.c.orig	2004-07-31 17:35:34.284113760 +0200
+++ libvo/vo_x11.c	2004-07-31 17:35:40.638147800 +0200
@@ -46,6 +46,7 @@
 #include "../mp_msg.h"
 
 #ifdef HAVE_NEW_GUI
+#undef __vector
 #include "../Gui/interface.h"
 #include "../mplayer.h"
 #endif
--- /dev/null	2004-07-29 08:58:45.351578344 +0200
+++ osdep/gcc_fixes.h	2004-07-31 16:32:21.000000000 +0200
@@ -0,0 +1,94 @@
+/*
+ * gcc fixes for altivec.
+ * Used to workaround broken gcc (FSF gcc-3 pre gcc-3.3) 
+ * and to stay somewhat compatible with Darwin.
+ */
+
+#ifndef _GCC_FIXES_
+#define _GCC_FIXES_
+
+#ifdef HAVE_ALTIVEC_H
+#include <altivec.h>
+#endif
+
+#ifdef CONFIG_DARWIN
+# ifndef __MWERKS__
+#  define AVV(x...) (x)
+# else
+#  define AVV
+# endif
+#else
+#define AVV(x...) {x}
+#if (__GNUC__ * 100 + __GNUC_MINOR__ < 303)  
+
+/* This code was provided to me by Bartosch Pixa
+ * as a separate header file (broken_mergel.h).
+ * thanks to lu_zero for the workaround.
+ *
+ * See this mail for more information:
+ * http://gcc.gnu.org/ml/gcc/2003-04/msg00967.html
+ */
+
+static inline vector signed char ff_vmrglb (vector signed char const A,
+					  vector signed char const B)
+{
+    static const vector unsigned char lowbyte = {
+	0x08, 0x18, 0x09, 0x19, 0x0a, 0x1a, 0x0b,  0x1b,
+	0x0c, 0x1c, 0x0d, 0x1d, 0x0e, 0x1e, 0x0f, 0x1f
+    };
+    return vec_perm (A, B, lowbyte);
+}
+
+static inline vector signed short ff_vmrglh (vector signed short const A,
+					  vector signed short const B)
+{
+    static const vector unsigned char lowhalf = {
+    	0x08, 0x09, 0x18, 0x19, 0x0a, 0x0b, 0x1a, 0x1b,
+	0x0c, 0x0d, 0x1c, 0x1d, 0x0e, 0x0f, 0x1e, 0x1f
+    };
+    return vec_perm (A, B, lowhalf);
+}
+
+static inline vector signed int ff_vmrglw (vector signed int const A,
+					  vector signed int const B)
+{
+    static const vector unsigned char lowword = {
+    	0x08, 0x09, 0x0a, 0x0b, 0x18, 0x19, 0x1a, 0x1b,
+	0x0c, 0x0d, 0x0e, 0x0f, 0x1c, 0x1d, 0x1e, 0x1f
+    };
+    return vec_perm (A, B, lowword);
+}
+/*#define ff_vmrglb ff_vmrglb 
+#define ff_vmrglh ff_vmrglh 
+#define ff_vmrglw ff_vmrglw 
+*/
+#undef vec_mergel
+
+#define vec_mergel(a1, a2) \
+__ch (__bin_args_eq (vector signed char, (a1), vector signed char, (a2)), \
+      ((vector signed char) ff_vmrglb ((vector signed char) (a1), (vector signed char) (a2))), \
+__ch (__bin_args_eq (vector unsigned char, (a1), vector unsigned char, (a2)), \
+      ((vector unsigned char) ff_vmrglb ((vector signed char) (a1), (vector signed char) (a2))), \
+__ch (__bin_args_eq (vector signed short, (a1), vector signed short, (a2)), \
+      ((vector signed short) ff_vmrglh ((vector signed short) (a1), (vector signed short) (a2))), \
+__ch (__bin_args_eq (vector unsigned short, (a1), vector unsigned short, (a2)), \
+      ((vector unsigned short) ff_vmrglh ((vector signed short) (a1), (vector signed short) (a2))), \
+__ch (__bin_args_eq (vector float, (a1), vector float, (a2)), \
+      ((vector float) ff_vmrglw ((vector signed int) (a1), (vector signed int) (a2))), \
+__ch (__bin_args_eq (vector signed int, (a1), vector signed int, (a2)), \
+      ((vector signed int) ff_vmrglw ((vector signed int) (a1), (vector signed int) (a2))), \
+__ch (__bin_args_eq (vector unsigned int, (a1), vector unsigned int, (a2)), \
+      ((vector unsigned int) ff_vmrglw ((vector signed int) (a1), (vector signed int) (a2))), \
+    __altivec_link_error_invalid_argument ())))))))
+
+#endif
+
+#endif /* CONFIG_DARWIN */
+
+#ifndef __MWERKS__
+#define const_vector const vector
+#else
+#define const_vector vector
+#endif
+
+#endif /* _GCC_FIXES_ */
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/attachments/20040731/87b3d3ca/attachment.pgp>


More information about the MPlayer-dev-eng mailing list