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 /***********************************************************************
36  * Vector types
37  **********************************************************************/
38 #define vec_u8 vector unsigned char
39 #define vec_s8 vector signed char
40 #define vec_u16 vector unsigned short
41 #define vec_s16 vector signed short
42 #define vec_u32 vector unsigned int
43 #define vec_s32 vector signed int
44 #define vec_f vector float
45 
46 /***********************************************************************
47  * Null vector
48  **********************************************************************/
49 #define LOAD_ZERO const vec_u8 zerov = vec_splat_u8( 0 )
50 
51 #define zero_u8v (vec_u8) zerov
52 #define zero_s8v (vec_s8) zerov
53 #define zero_u16v (vec_u16) zerov
54 #define zero_s16v (vec_s16) zerov
55 #define zero_u32v (vec_u32) zerov
56 #define zero_s32v (vec_s32) zerov
57 
58 #if HAVE_ALTIVEC
59 
60 // used to build registers permutation vectors (vcprm)
61 // the 's' are for words in the _s_econd vector
62 #define WORD_0 0x00,0x01,0x02,0x03
63 #define WORD_1 0x04,0x05,0x06,0x07
64 #define WORD_2 0x08,0x09,0x0a,0x0b
65 #define WORD_3 0x0c,0x0d,0x0e,0x0f
66 #define WORD_s0 0x10,0x11,0x12,0x13
67 #define WORD_s1 0x14,0x15,0x16,0x17
68 #define WORD_s2 0x18,0x19,0x1a,0x1b
69 #define WORD_s3 0x1c,0x1d,0x1e,0x1f
70 #define vcprm(a,b,c,d) (const vec_u8){WORD_ ## a, WORD_ ## b, WORD_ ## c, WORD_ ## d}
71 
72 #define SWP_W2S0 0x02,0x03,0x00,0x01
73 #define SWP_W2S1 0x06,0x07,0x04,0x05
74 #define SWP_W2S2 0x0a,0x0b,0x08,0x09
75 #define SWP_W2S3 0x0e,0x0f,0x0c,0x0d
76 #define SWP_W2Ss0 0x12,0x13,0x10,0x11
77 #define SWP_W2Ss1 0x16,0x17,0x14,0x15
78 #define SWP_W2Ss2 0x1a,0x1b,0x18,0x19
79 #define SWP_W2Ss3 0x1e,0x1f,0x1c,0x1d
80 #define vcswapi2s(a,b,c,d) (const vector unsigned char){SWP_W2S ## a, SWP_W2S ## b, SWP_W2S ## c, SWP_W2S ## d}
81 
82 #define vcswapc() \
83  (const vector unsigned char){0x0f,0x0e,0x0d,0x0c,0x0b,0x0a,0x09,0x08,0x07,0x06,0x05,0x04,0x03,0x02,0x01,0x00}
84 
85 
86 // Transpose 8x8 matrix of 16-bit elements (in-place)
87 #define TRANSPOSE8(a,b,c,d,e,f,g,h) \
88 do { \
89  vec_s16 A1, B1, C1, D1, E1, F1, G1, H1; \
90  vec_s16 A2, B2, C2, D2, E2, F2, G2, H2; \
91  \
92  A1 = vec_mergeh (a, e); \
93  B1 = vec_mergel (a, e); \
94  C1 = vec_mergeh (b, f); \
95  D1 = vec_mergel (b, f); \
96  E1 = vec_mergeh (c, g); \
97  F1 = vec_mergel (c, g); \
98  G1 = vec_mergeh (d, h); \
99  H1 = vec_mergel (d, h); \
100  \
101  A2 = vec_mergeh (A1, E1); \
102  B2 = vec_mergel (A1, E1); \
103  C2 = vec_mergeh (B1, F1); \
104  D2 = vec_mergel (B1, F1); \
105  E2 = vec_mergeh (C1, G1); \
106  F2 = vec_mergel (C1, G1); \
107  G2 = vec_mergeh (D1, H1); \
108  H2 = vec_mergel (D1, H1); \
109  \
110  a = vec_mergeh (A2, E2); \
111  b = vec_mergel (A2, E2); \
112  c = vec_mergeh (B2, F2); \
113  d = vec_mergel (B2, F2); \
114  e = vec_mergeh (C2, G2); \
115  f = vec_mergel (C2, G2); \
116  g = vec_mergeh (D2, H2); \
117  h = vec_mergel (D2, H2); \
118 } while (0)
119 
120 
121 #if HAVE_BIGENDIAN
122 #define VEC_LD(offset,b) \
123  vec_perm(vec_ld(offset, b), vec_ld((offset)+15, b), vec_lvsl(offset, b))
124 #else
125 #define VEC_LD(offset,b) \
126  vec_vsx_ld(offset, b)
127 #endif
128 
129 /** @brief loads unaligned vector @a *src with offset @a offset
130  and returns it */
131 #if HAVE_BIGENDIAN
132 static inline vec_u8 unaligned_load(int offset, const uint8_t *src)
133 {
134  register vec_u8 first = vec_ld(offset, src);
135  register vec_u8 second = vec_ld(offset + 15, src);
136  register vec_u8 mask = vec_lvsl(offset, src);
137  return vec_perm(first, second, mask);
138 }
139 static inline vec_u8 load_with_perm_vec(int offset, const uint8_t *src, vec_u8 perm_vec)
140 {
141  vec_u8 a = vec_ld(offset, src);
142  vec_u8 b = vec_ld(offset + 15, src);
143  return vec_perm(a, b, perm_vec);
144 }
145 #else
146 #define unaligned_load(a,b) VEC_LD(a,b)
147 #define load_with_perm_vec(a,b,c) VEC_LD(a,b)
148 #endif
149 
150 
151 /**
152  * loads vector known misalignment
153  * @param perm_vec the align permute vector to combine the two loads from lvsl
154  */
155 
156 #define vec_unaligned_load(b) VEC_LD(0, b)
157 
158 #if HAVE_BIGENDIAN
159 #define VEC_MERGEH(a, b) vec_mergeh(a, b)
160 #define VEC_MERGEL(a, b) vec_mergel(a, b)
161 #else
162 #define VEC_MERGEH(a, b) vec_mergeh(b, a)
163 #define VEC_MERGEL(a, b) vec_mergel(b, a)
164 #endif
165 
166 #if HAVE_BIGENDIAN
167 #define VEC_ST(a,b,c) vec_st(a,b,c)
168 #else
169 #define VEC_ST(a,b,c) vec_vsx_st(a,b,c)
170 #endif
171 
172 #if HAVE_BIGENDIAN
173 #define VEC_SPLAT16(a,b) vec_splat((vec_s16)(a), b)
174 #else
175 #define VEC_SPLAT16(a,b) vec_splat((vec_s16)(vec_perm(a, a, vcswapi2s(0,1,2,3))), b)
176 #endif
177 
178 #if HAVE_BIGENDIAN
179 #define VEC_SLD16(a,b,c) vec_sld(a, b, c)
180 #else
181 #define VEC_SLD16(a,b,c) vec_sld(b, a, c)
182 #endif
183 
184 #endif /* HAVE_ALTIVEC */
185 
186 #if HAVE_VSX
187 #if HAVE_BIGENDIAN
188 #define vsx_ld_u8_s16(off, p) \
189  ((vec_s16)vec_mergeh((vec_u8)vec_splat_u8(0), \
190  (vec_u8)vec_vsx_ld((off), (p))))
191 #else
192 #define vsx_ld_u8_s16(off, p) \
193  ((vec_s16)vec_mergeh((vec_u8)vec_vsx_ld((off), (p)), \
194  (vec_u8)vec_splat_u8(0)))
195 #endif /* HAVE_BIGENDIAN */
196 #endif /* HAVE_VSX */
197 
198 #endif /* AVUTIL_PPC_UTIL_ALTIVEC_H */
const char * b
Definition: vf_curves.c:113
#define src
Definition: vp8dsp.c:254
uint8_t
static const uint16_t mask[17]
Definition: lzw.c:38
static const uint8_t offset[127][2]
Definition: vf_spp.c:92
#define vec_u8
Definition: util_altivec.h:38