() 10l
[libav.git] / libavcodec / ppc / gcc_fixes.h
CommitLineData
a9a07762
MN
1/*
2 * gcc fixes for altivec.
115329f1 3 * Used to workaround broken gcc (FSF gcc-3 pre gcc-3.3)
a9a07762 4 * and to stay somewhat compatible with Darwin.
04d7f601
DB
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
a9a07762
MN
19 */
20
21#ifndef _GCC_FIXES_
22#define _GCC_FIXES_
23
24#ifdef HAVE_ALTIVEC_H
25#include <altivec.h>
26#endif
27
28#ifdef CONFIG_DARWIN
aab34ca0
MN
29# ifndef __MWERKS__
30# define AVV(x...) (x)
31# else
32# define AVV
33# endif
a01e08ee 34#define REG_v(a) asm ( #a )
a9a07762 35#else
a01e08ee 36
a9a07762 37#define AVV(x...) {x}
a01e08ee
LB
38
39#if (__GNUC__ < 4)
a01e08ee 40# define REG_v(a)
fd925db3
LB
41#else
42# define REG_v(a) asm ( #a )
a01e08ee
LB
43#endif
44
115329f1 45#if (__GNUC__ * 100 + __GNUC_MINOR__ < 303)
a9a07762
MN
46
47/* This code was provided to me by Bartosch Pixa
48 * as a separate header file (broken_mergel.h).
49 * thanks to lu_zero for the workaround.
50 *
51 * See this mail for more information:
52 * http://gcc.gnu.org/ml/gcc/2003-04/msg00967.html
53 */
54
782b80d9 55static inline vector signed char ff_vmrglb (vector signed char const A,
bb270c08 56 vector signed char const B)
a9a07762
MN
57{
58 static const vector unsigned char lowbyte = {
bb270c08
DB
59 0x08, 0x18, 0x09, 0x19, 0x0a, 0x1a, 0x0b, 0x1b,
60 0x0c, 0x1c, 0x0d, 0x1d, 0x0e, 0x1e, 0x0f, 0x1f
a9a07762
MN
61 };
62 return vec_perm (A, B, lowbyte);
63}
64
782b80d9 65static inline vector signed short ff_vmrglh (vector signed short const A,
bb270c08 66 vector signed short const B)
a9a07762
MN
67{
68 static const vector unsigned char lowhalf = {
bb270c08
DB
69 0x08, 0x09, 0x18, 0x19, 0x0a, 0x0b, 0x1a, 0x1b,
70 0x0c, 0x0d, 0x1c, 0x1d, 0x0e, 0x0f, 0x1e, 0x1f
a9a07762
MN
71 };
72 return vec_perm (A, B, lowhalf);
73}
74
782b80d9 75static inline vector signed int ff_vmrglw (vector signed int const A,
bb270c08 76 vector signed int const B)
a9a07762
MN
77{
78 static const vector unsigned char lowword = {
bb270c08
DB
79 0x08, 0x09, 0x0a, 0x0b, 0x18, 0x19, 0x1a, 0x1b,
80 0x0c, 0x0d, 0x0e, 0x0f, 0x1c, 0x1d, 0x1e, 0x1f
a9a07762
MN
81 };
82 return vec_perm (A, B, lowword);
83}
115329f1
DB
84/*#define ff_vmrglb ff_vmrglb
85#define ff_vmrglh ff_vmrglh
86#define ff_vmrglw ff_vmrglw
a9a07762
MN
87*/
88#undef vec_mergel
89
90#define vec_mergel(a1, a2) \
91__ch (__bin_args_eq (vector signed char, (a1), vector signed char, (a2)), \
782b80d9 92 ((vector signed char) ff_vmrglb ((vector signed char) (a1), (vector signed char) (a2))), \
a9a07762 93__ch (__bin_args_eq (vector unsigned char, (a1), vector unsigned char, (a2)), \
782b80d9 94 ((vector unsigned char) ff_vmrglb ((vector signed char) (a1), (vector signed char) (a2))), \
a9a07762 95__ch (__bin_args_eq (vector signed short, (a1), vector signed short, (a2)), \
782b80d9 96 ((vector signed short) ff_vmrglh ((vector signed short) (a1), (vector signed short) (a2))), \
a9a07762 97__ch (__bin_args_eq (vector unsigned short, (a1), vector unsigned short, (a2)), \
782b80d9 98 ((vector unsigned short) ff_vmrglh ((vector signed short) (a1), (vector signed short) (a2))), \
a9a07762 99__ch (__bin_args_eq (vector float, (a1), vector float, (a2)), \
782b80d9 100 ((vector float) ff_vmrglw ((vector signed int) (a1), (vector signed int) (a2))), \
a9a07762 101__ch (__bin_args_eq (vector signed int, (a1), vector signed int, (a2)), \
782b80d9 102 ((vector signed int) ff_vmrglw ((vector signed int) (a1), (vector signed int) (a2))), \
a9a07762 103__ch (__bin_args_eq (vector unsigned int, (a1), vector unsigned int, (a2)), \
782b80d9 104 ((vector unsigned int) ff_vmrglw ((vector signed int) (a1), (vector signed int) (a2))), \
a9a07762
MN
105 __altivec_link_error_invalid_argument ())))))))
106
107#endif
108
109#endif /* CONFIG_DARWIN */
110
aab34ca0
MN
111#ifndef __MWERKS__
112#define const_vector const vector
113#else
114#define const_vector vector
115#endif
116
a9a07762 117#endif /* _GCC_FIXES_ */