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