FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
util_altivec.h
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 /**
20  * @file
21  * Contains misc utility macros and inline functions
22  */
23 
24 #ifndef AVUTIL_PPC_UTIL_ALTIVEC_H
25 #define AVUTIL_PPC_UTIL_ALTIVEC_H
26 
27 #include <stdint.h>
28 
29 #include "config.h"
30 
31 #if HAVE_ALTIVEC_H
32 #include <altivec.h>
33 #endif
34 
35 #include "types_altivec.h"
36 
37 #if HAVE_ALTIVEC
38 
39 // used to build registers permutation vectors (vcprm)
40 // the 's' are for words in the _s_econd vector
41 #define WORD_0 0x00,0x01,0x02,0x03
42 #define WORD_1 0x04,0x05,0x06,0x07
43 #define WORD_2 0x08,0x09,0x0a,0x0b
44 #define WORD_3 0x0c,0x0d,0x0e,0x0f
45 #define WORD_s0 0x10,0x11,0x12,0x13
46 #define WORD_s1 0x14,0x15,0x16,0x17
47 #define WORD_s2 0x18,0x19,0x1a,0x1b
48 #define WORD_s3 0x1c,0x1d,0x1e,0x1f
49 #define vcprm(a,b,c,d) (const vector unsigned char){WORD_ ## a, WORD_ ## b, WORD_ ## c, WORD_ ## d}
50 
51 #define SWP_W2S0 0x02,0x03,0x00,0x01
52 #define SWP_W2S1 0x06,0x07,0x04,0x05
53 #define SWP_W2S2 0x0a,0x0b,0x08,0x09
54 #define SWP_W2S3 0x0e,0x0f,0x0c,0x0d
55 #define SWP_W2Ss0 0x12,0x13,0x10,0x11
56 #define SWP_W2Ss1 0x16,0x17,0x14,0x15
57 #define SWP_W2Ss2 0x1a,0x1b,0x18,0x19
58 #define SWP_W2Ss3 0x1e,0x1f,0x1c,0x1d
59 #define vcswapi2s(a,b,c,d) (const vector unsigned char){SWP_W2S ## a, SWP_W2S ## b, SWP_W2S ## c, SWP_W2S ## d}
60 
61 #define vcswapc() \
62  (const vector unsigned char){0x0f,0x0e,0x0d,0x0c,0x0b,0x0a,0x09,0x08,0x07,0x06,0x05,0x04,0x03,0x02,0x01,0x00}
63 
64 
65 // Transpose 8x8 matrix of 16-bit elements (in-place)
66 #define TRANSPOSE8(a,b,c,d,e,f,g,h) \
67 do { \
68  vector signed short A1, B1, C1, D1, E1, F1, G1, H1; \
69  vector signed short A2, B2, C2, D2, E2, F2, G2, H2; \
70  \
71  A1 = vec_mergeh (a, e); \
72  B1 = vec_mergel (a, e); \
73  C1 = vec_mergeh (b, f); \
74  D1 = vec_mergel (b, f); \
75  E1 = vec_mergeh (c, g); \
76  F1 = vec_mergel (c, g); \
77  G1 = vec_mergeh (d, h); \
78  H1 = vec_mergel (d, h); \
79  \
80  A2 = vec_mergeh (A1, E1); \
81  B2 = vec_mergel (A1, E1); \
82  C2 = vec_mergeh (B1, F1); \
83  D2 = vec_mergel (B1, F1); \
84  E2 = vec_mergeh (C1, G1); \
85  F2 = vec_mergel (C1, G1); \
86  G2 = vec_mergeh (D1, H1); \
87  H2 = vec_mergel (D1, H1); \
88  \
89  a = vec_mergeh (A2, E2); \
90  b = vec_mergel (A2, E2); \
91  c = vec_mergeh (B2, F2); \
92  d = vec_mergel (B2, F2); \
93  e = vec_mergeh (C2, G2); \
94  f = vec_mergel (C2, G2); \
95  g = vec_mergeh (D2, H2); \
96  h = vec_mergel (D2, H2); \
97 } while (0)
98 
99 
100 #if HAVE_BIGENDIAN
101 #define VEC_LD(offset,b) \
102  vec_perm(vec_ld(offset, b), vec_ld((offset)+15, b), vec_lvsl(offset, b))
103 #else
104 #define VEC_LD(offset,b) \
105  vec_vsx_ld(offset, b)
106 #endif
107 
108 /** @brief loads unaligned vector @a *src with offset @a offset
109  and returns it */
110 #if HAVE_BIGENDIAN
111 static inline vector unsigned char unaligned_load(int offset, const uint8_t *src)
112 {
113  register vector unsigned char first = vec_ld(offset, src);
114  register vector unsigned char second = vec_ld(offset+15, src);
115  register vector unsigned char mask = vec_lvsl(offset, src);
116  return vec_perm(first, second, mask);
117 }
118 static inline vec_u8 load_with_perm_vec(int offset, const uint8_t *src, vec_u8 perm_vec)
119 {
120  vec_u8 a = vec_ld(offset, src);
121  vec_u8 b = vec_ld(offset+15, src);
122  return vec_perm(a, b, perm_vec);
123 }
124 #else
125 #define unaligned_load(a,b) VEC_LD(a,b)
126 #define load_with_perm_vec(a,b,c) VEC_LD(a,b)
127 #endif
128 
129 
130 /**
131  * loads vector known misalignment
132  * @param perm_vec the align permute vector to combine the two loads from lvsl
133  */
134 
135 #define vec_unaligned_load(b) VEC_LD(0, b)
136 
137 #if HAVE_BIGENDIAN
138 #define VEC_MERGEH(a, b) vec_mergeh(a, b)
139 #define VEC_MERGEL(a, b) vec_mergel(a, b)
140 #else
141 #define VEC_MERGEH(a, b) vec_mergeh(b, a)
142 #define VEC_MERGEL(a, b) vec_mergel(b, a)
143 #endif
144 
145 #if HAVE_BIGENDIAN
146 #define VEC_ST(a,b,c) vec_st(a,b,c)
147 #else
148 #define VEC_ST(a,b,c) vec_vsx_st(a,b,c)
149 #endif
150 
151 #if HAVE_BIGENDIAN
152 #define VEC_SPLAT16(a,b) vec_splat((vec_s16)(a), b)
153 #else
154 #define VEC_SPLAT16(a,b) vec_splat((vec_s16)(vec_perm(a, a, vcswapi2s(0,1,2,3))), b)
155 #endif
156 
157 #if HAVE_BIGENDIAN
158 #define VEC_SLD16(a,b,c) vec_sld(a, b, c)
159 #else
160 #define VEC_SLD16(a,b,c) vec_sld(b, a, c)
161 #endif
162 
163 #endif /* HAVE_ALTIVEC */
164 
165 #endif /* AVUTIL_PPC_UTIL_ALTIVEC_H */