FFmpeg
Loading...
Searching...
No Matches
vp3dsp_altivec.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2009 David Conrad
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg 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.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg 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 FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include <string.h>
22
23#include "config.h"
24
27
28#include "libavcodec/vp3dsp.h"
29
30#include "vp3dsp_altivec.h"
31
32static const vec_s16 constants =
33 {0, 64277, 60547, 54491, 46341, 36410, 25080, 12785};
34#if HAVE_BIGENDIAN
35static const vec_u8 interleave_high =
36 {0, 1, 16, 17, 4, 5, 20, 21, 8, 9, 24, 25, 12, 13, 28, 29};
37#else
38static const vec_u8 interleave_high =
39 {2, 3, 18, 19, 6, 7, 22, 23, 10, 11, 26, 27, 14, 15, 30, 31};
40#endif
41
42#define IDCT_START \
43 vec_s16 A, B, C, D, Ad, Bd, Cd, Dd, E, F, G, H;\
44 vec_s16 Ed, Gd, Add, Bdd, Fd, Hd;\
45 vec_s16 eight = vec_splat_s16(8);\
46 vec_u16 four = vec_splat_u16(4);\
47\
48 vec_s16 C1 = vec_splat(constants, 1);\
49 vec_s16 C2 = vec_splat(constants, 2);\
50 vec_s16 C3 = vec_splat(constants, 3);\
51 vec_s16 C4 = vec_splat(constants, 4);\
52 vec_s16 C5 = vec_splat(constants, 5);\
53 vec_s16 C6 = vec_splat(constants, 6);\
54 vec_s16 C7 = vec_splat(constants, 7);\
55\
56 vec_s16 b0 = vec_ld(0x00, block);\
57 vec_s16 b1 = vec_ld(0x10, block);\
58 vec_s16 b2 = vec_ld(0x20, block);\
59 vec_s16 b3 = vec_ld(0x30, block);\
60 vec_s16 b4 = vec_ld(0x40, block);\
61 vec_s16 b5 = vec_ld(0x50, block);\
62 vec_s16 b6 = vec_ld(0x60, block);\
63 vec_s16 b7 = vec_ld(0x70, block);
64
65// these functions do (a*C)>>16
66// things are tricky because a is signed, but C unsigned.
67// M15 is used if C fits in 15 bit unsigned (C6,C7)
68// M16 is used if C requires 16 bits unsigned
69static inline vec_s16 M15(vec_s16 a, vec_s16 C)
70{
71 return (vec_s16)vec_perm(vec_mule(a,C), vec_mulo(a,C), interleave_high);
72}
73static inline vec_s16 M16(vec_s16 a, vec_s16 C)
74{
75 return vec_add(a, M15(a, C));
76}
77
78#define IDCT_1D(ADD, SHIFT)\
79 A = vec_add(M16(b1, C1), M15(b7, C7));\
80 B = vec_sub(M15(b1, C7), M16(b7, C1));\
81 C = vec_add(M16(b3, C3), M16(b5, C5));\
82 D = vec_sub(M16(b5, C3), M16(b3, C5));\
83\
84 Ad = M16(vec_sub(A, C), C4);\
85 Bd = M16(vec_sub(B, D), C4);\
86\
87 Cd = vec_add(A, C);\
88 Dd = vec_add(B, D);\
89\
90 E = ADD(M16(vec_add(b0, b4), C4));\
91 F = ADD(M16(vec_sub(b0, b4), C4));\
92\
93 G = vec_add(M16(b2, C2), M15(b6, C6));\
94 H = vec_sub(M15(b2, C6), M16(b6, C2));\
95\
96 Ed = vec_sub(E, G);\
97 Gd = vec_add(E, G);\
98\
99 Add = vec_add(F, Ad);\
100 Bdd = vec_sub(Bd, H);\
101\
102 Fd = vec_sub(F, Ad);\
103 Hd = vec_add(Bd, H);\
104\
105 b0 = SHIFT(vec_add(Gd, Cd));\
106 b7 = SHIFT(vec_sub(Gd, Cd));\
107\
108 b1 = SHIFT(vec_add(Add, Hd));\
109 b2 = SHIFT(vec_sub(Add, Hd));\
110\
111 b3 = SHIFT(vec_add(Ed, Dd));\
112 b4 = SHIFT(vec_sub(Ed, Dd));\
113\
114 b5 = SHIFT(vec_add(Fd, Bdd));\
115 b6 = SHIFT(vec_sub(Fd, Bdd));
116
117#define NOP(a) a
118#define ADD8(a) vec_add(a, eight)
119#define SHIFT4(a) vec_sra(a, four)
120
121static void vp3_idct_put_altivec(uint8_t *dst, ptrdiff_t stride, int16_t block[64])
122{
123 vec_u8 t;
125
126 // pixels are signed; so add 128*16 in addition to the normal 8
127 vec_s16 v2048 = vec_sl(vec_splat_s16(1), vec_splat_u16(11));
128 eight = vec_add(eight, v2048);
129
130 IDCT_1D(NOP, NOP)
131 TRANSPOSE8(b0, b1, b2, b3, b4, b5, b6, b7);
133
134#define PUT(a)\
135 t = vec_packsu(a, a);\
136 vec_ste((vec_u32)t, 0, (unsigned int *)dst);\
137 vec_ste((vec_u32)t, 4, (unsigned int *)dst);
138
139 PUT(b0) dst += stride;
140 PUT(b1) dst += stride;
141 PUT(b2) dst += stride;
142 PUT(b3) dst += stride;
143 PUT(b4) dst += stride;
144 PUT(b5) dst += stride;
145 PUT(b6) dst += stride;
146 PUT(b7)
147 memset(block, 0, sizeof(*block) * 64);
148}
149
150static void vp3_idct_add_altivec(uint8_t *dst, ptrdiff_t stride, int16_t block[64])
151{
152 LOAD_ZERO;
153 vec_u8 t, vdst;
154 vec_s16 vdst_16;
155 vec_u8 vdst_mask = vec_mergeh(vec_splat_u8(-1), vec_lvsl(0, dst));
156
158
159 IDCT_1D(NOP, NOP)
160 TRANSPOSE8(b0, b1, b2, b3, b4, b5, b6, b7);
162
163#if HAVE_BIGENDIAN
164#define GET_VDST16\
165 vdst = vec_ld(0, dst);\
166 vdst_16 = (vec_s16)vec_perm(vdst, zero_u8v, vdst_mask);
167#else
168#define GET_VDST16\
169 vdst = vec_vsx_ld(0,dst);\
170 vdst_16 = (vec_s16)vec_mergeh(vdst, zero_u8v);
171#endif
172
173#define ADD(a)\
174 GET_VDST16;\
175 vdst_16 = vec_adds(a, vdst_16);\
176 t = vec_packsu(vdst_16, vdst_16);\
177 vec_ste((vec_u32)t, 0, (unsigned int *)dst);\
178 vec_ste((vec_u32)t, 4, (unsigned int *)dst);
179
180 ADD(b0) dst += stride;
181 ADD(b1) dst += stride;
182 ADD(b2) dst += stride;
183 ADD(b3) dst += stride;
184 ADD(b4) dst += stride;
185 ADD(b5) dst += stride;
186 ADD(b6) dst += stride;
187 ADD(b7)
188 memset(block, 0, sizeof(*block) * 64);
189}
190
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:97
static int16_t block[64]
Definition dct.c:125
int a
static const vec_s16 constants[5]
#define C
Macro definitions for various function/variable attributes.
#define av_cold
Definition attributes.h:117
#define stride
Contains misc utility macros and inline functions.
#define vec_s16
#define vec_u8
#define LOAD_ZERO
static double b1(void *priv, double x, double y)
Definition vf_xfade.c:2041
static double b2(void *priv, double x, double y)
Definition vf_xfade.c:2042
static double b3(void *priv, double x, double y)
Definition vf_xfade.c:2043
static double b0(void *priv, double x, double y)
Definition vf_xfade.c:2040
static vec_s16 M16(vec_s16 a, vec_s16 C)
static void vp3_idct_add_altivec(uint8_t *dst, ptrdiff_t stride, int16_t block[64])
#define NOP(a)
#define IDCT_1D(ADD, SHIFT)
#define SHIFT4(a)
static const vec_u8 interleave_high
#define ADD8(a)
static void vp3_idct_put_altivec(uint8_t *dst, ptrdiff_t stride, int16_t block[64])
static vec_s16 M15(vec_s16 a, vec_s16 C)
#define PUT(a)
#define IDCT_START
av_cold void ff_vp3dsp_init_altivec(VP3DSPContext *c)
#define ADD(a)
static double c[64]