altivec gcc-3 fixes by (Magnus Damm <damm at opensource dot se>)
[libav.git] / libavcodec / ppc / gcc_fixes.h
1 /*
2 * gcc fixes for altivec.
3 * Used to workaround broken gcc (FSF gcc-3 pre gcc-3.3)
4 * and to stay somewhat compatible with Darwin.
5 */
6
7 #ifndef _GCC_FIXES_
8 #define _GCC_FIXES_
9
10 #ifdef HAVE_ALTIVEC_H
11 #include <altivec.h>
12 #endif
13
14 #ifdef CONFIG_DARWIN
15 #define AVV(x...) (x)
16 #else
17 #define AVV(x...) {x}
18
19 #if (__GNUC__ * 100 + __GNUC_MINOR__ < 303)
20
21 /* This code was provided to me by Bartosch Pixa
22 * as a separate header file (broken_mergel.h).
23 * thanks to lu_zero for the workaround.
24 *
25 * See this mail for more information:
26 * http://gcc.gnu.org/ml/gcc/2003-04/msg00967.html
27 */
28
29 static inline vector signed char my_vmrglb (vector signed char const A,
30 vector signed char const B)
31 {
32 static const vector unsigned char lowbyte = {
33 0x08, 0x18, 0x09, 0x19, 0x0a, 0x1a, 0x0b, 0x1b,
34 0x0c, 0x1c, 0x0d, 0x1d, 0x0e, 0x1e, 0x0f, 0x1f
35 };
36 return vec_perm (A, B, lowbyte);
37 }
38
39 static inline vector signed short my_vmrglh (vector signed short const A,
40 vector signed short const B)
41 {
42 static const vector unsigned char lowhalf = {
43 0x08, 0x09, 0x18, 0x19, 0x0a, 0x0b, 0x1a, 0x1b,
44 0x0c, 0x0d, 0x1c, 0x1d, 0x0e, 0x0f, 0x1e, 0x1f
45 };
46 return vec_perm (A, B, lowhalf);
47 }
48
49 static inline vector signed int my_vmrglw (vector signed int const A,
50 vector signed int const B)
51 {
52 static const vector unsigned char lowword = {
53 0x08, 0x09, 0x0a, 0x0b, 0x18, 0x19, 0x1a, 0x1b,
54 0x0c, 0x0d, 0x0e, 0x0f, 0x1c, 0x1d, 0x1e, 0x1f
55 };
56 return vec_perm (A, B, lowword);
57 }
58 /*#define my_vmrglb my_vmrglb
59 #define my_vmrglh my_vmrglh
60 #define my_vmrglw my_vmrglw
61 */
62 #undef vec_mergel
63
64 #define vec_mergel(a1, a2) \
65 __ch (__bin_args_eq (vector signed char, (a1), vector signed char, (a2)), \
66 ((vector signed char) my_vmrglb ((vector signed char) (a1), (vector signed char) (a2))), \
67 __ch (__bin_args_eq (vector unsigned char, (a1), vector unsigned char, (a2)), \
68 ((vector unsigned char) my_vmrglb ((vector signed char) (a1), (vector signed char) (a2))), \
69 __ch (__bin_args_eq (vector signed short, (a1), vector signed short, (a2)), \
70 ((vector signed short) my_vmrglh ((vector signed short) (a1), (vector signed short) (a2))), \
71 __ch (__bin_args_eq (vector unsigned short, (a1), vector unsigned short, (a2)), \
72 ((vector unsigned short) my_vmrglh ((vector signed short) (a1), (vector signed short) (a2))), \
73 __ch (__bin_args_eq (vector float, (a1), vector float, (a2)), \
74 ((vector float) my_vmrglw ((vector signed int) (a1), (vector signed int) (a2))), \
75 __ch (__bin_args_eq (vector signed int, (a1), vector signed int, (a2)), \
76 ((vector signed int) my_vmrglw ((vector signed int) (a1), (vector signed int) (a2))), \
77 __ch (__bin_args_eq (vector unsigned int, (a1), vector unsigned int, (a2)), \
78 ((vector unsigned int) my_vmrglw ((vector signed int) (a1), (vector signed int) (a2))), \
79 __altivec_link_error_invalid_argument ())))))))
80
81 #endif
82
83 #endif /* CONFIG_DARWIN */
84
85 #endif /* _GCC_FIXES_ */