653378d5bc0e74f6c505e085ccec1390e4ed9d57
[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 /* The Apple assembler shipped w/ gcc-3.3 knows about DCBZL, previous assemblers don't
17 We assume here that the Darwin GCC is from Apple.... */
18 #if (__GNUC__ * 100 + __GNUC_MINOR__ < 303)
19 #define NO_DCBZL
20 #endif
21 #else
22 #define AVV(x...) {x}
23 /* I don't think any non-Apple assembler knows about DCBZL */
24 #define NO_DCBZL
25 #if (__GNUC__ * 100 + __GNUC_MINOR__ < 303)
26
27 /* This code was provided to me by Bartosch Pixa
28 * as a separate header file (broken_mergel.h).
29 * thanks to lu_zero for the workaround.
30 *
31 * See this mail for more information:
32 * http://gcc.gnu.org/ml/gcc/2003-04/msg00967.html
33 */
34
35 static inline vector signed char my_vmrglb (vector signed char const A,
36 vector signed char const B)
37 {
38 static const vector unsigned char lowbyte = {
39 0x08, 0x18, 0x09, 0x19, 0x0a, 0x1a, 0x0b, 0x1b,
40 0x0c, 0x1c, 0x0d, 0x1d, 0x0e, 0x1e, 0x0f, 0x1f
41 };
42 return vec_perm (A, B, lowbyte);
43 }
44
45 static inline vector signed short my_vmrglh (vector signed short const A,
46 vector signed short const B)
47 {
48 static const vector unsigned char lowhalf = {
49 0x08, 0x09, 0x18, 0x19, 0x0a, 0x0b, 0x1a, 0x1b,
50 0x0c, 0x0d, 0x1c, 0x1d, 0x0e, 0x0f, 0x1e, 0x1f
51 };
52 return vec_perm (A, B, lowhalf);
53 }
54
55 static inline vector signed int my_vmrglw (vector signed int const A,
56 vector signed int const B)
57 {
58 static const vector unsigned char lowword = {
59 0x08, 0x09, 0x0a, 0x0b, 0x18, 0x19, 0x1a, 0x1b,
60 0x0c, 0x0d, 0x0e, 0x0f, 0x1c, 0x1d, 0x1e, 0x1f
61 };
62 return vec_perm (A, B, lowword);
63 }
64 /*#define my_vmrglb my_vmrglb
65 #define my_vmrglh my_vmrglh
66 #define my_vmrglw my_vmrglw
67 */
68 #undef vec_mergel
69
70 #define vec_mergel(a1, a2) \
71 __ch (__bin_args_eq (vector signed char, (a1), vector signed char, (a2)), \
72 ((vector signed char) my_vmrglb ((vector signed char) (a1), (vector signed char) (a2))), \
73 __ch (__bin_args_eq (vector unsigned char, (a1), vector unsigned char, (a2)), \
74 ((vector unsigned char) my_vmrglb ((vector signed char) (a1), (vector signed char) (a2))), \
75 __ch (__bin_args_eq (vector signed short, (a1), vector signed short, (a2)), \
76 ((vector signed short) my_vmrglh ((vector signed short) (a1), (vector signed short) (a2))), \
77 __ch (__bin_args_eq (vector unsigned short, (a1), vector unsigned short, (a2)), \
78 ((vector unsigned short) my_vmrglh ((vector signed short) (a1), (vector signed short) (a2))), \
79 __ch (__bin_args_eq (vector float, (a1), vector float, (a2)), \
80 ((vector float) my_vmrglw ((vector signed int) (a1), (vector signed int) (a2))), \
81 __ch (__bin_args_eq (vector signed int, (a1), vector signed int, (a2)), \
82 ((vector signed int) my_vmrglw ((vector signed int) (a1), (vector signed int) (a2))), \
83 __ch (__bin_args_eq (vector unsigned int, (a1), vector unsigned int, (a2)), \
84 ((vector unsigned int) my_vmrglw ((vector signed int) (a1), (vector signed int) (a2))), \
85 __altivec_link_error_invalid_argument ())))))))
86
87 #endif
88
89 #endif /* CONFIG_DARWIN */
90
91 #endif /* _GCC_FIXES_ */