swscale: consistent names for arch-specific acceleration functions
[libav.git] / libswscale / ppc / yuv2yuv_altivec.c
CommitLineData
0e5d31b1 1/*
511cf612 2 * AltiVec-enhanced yuv-to-yuv conversion routines.
0e5d31b1
RB
3 *
4 * Copyright (C) 2004 Romain Dolbeau <romain@dolbeau.org>
5 * based on the equivalent C code in swscale.c
6 *
7 * This file is part of Libav.
8 *
9 * Libav is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * Libav is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with Libav; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24#include <inttypes.h>
04217de4 25
0e5d31b1
RB
26#include "config.h"
27#include "libswscale/swscale.h"
28#include "libswscale/swscale_internal.h"
29#include "libavutil/cpu.h"
30
c2503d9c
DB
31#if HAVE_ALTIVEC
32
04217de4 33static int yv12toyuy2_unscaled_altivec(SwsContext *c, const uint8_t *src[],
0e5d31b1 34 int srcStride[], int srcSliceY,
04217de4 35 int srcSliceH, uint8_t *dstParam[],
0e5d31b1
RB
36 int dstStride_a[])
37{
04217de4
DB
38 uint8_t *dst = dstParam[0] + dstStride_a[0] * srcSliceY;
39 // yv12toyuy2(src[0], src[1], src[2], dst, c->srcW, srcSliceH,
40 // srcStride[0], srcStride[1], dstStride[0]);
41 const uint8_t *ysrc = src[0];
42 const uint8_t *usrc = src[1];
43 const uint8_t *vsrc = src[2];
44 const int width = c->srcW;
45 const int height = srcSliceH;
46 const int lumStride = srcStride[0];
0e5d31b1 47 const int chromStride = srcStride[1];
04217de4 48 const int dstStride = dstStride_a[0];
0e5d31b1 49 const vector unsigned char yperm = vec_lvsl(0, ysrc);
04217de4 50 const int vertLumPerChroma = 2;
0e5d31b1
RB
51 register unsigned int y;
52
53 /* This code assumes:
04217de4
DB
54 *
55 * 1) dst is 16 bytes-aligned
56 * 2) dstStride is a multiple of 16
57 * 3) width is a multiple of 16
58 * 4) lum & chrom stride are multiples of 8
59 */
0e5d31b1 60
04217de4 61 for (y = 0; y < height; y++) {
0e5d31b1 62 int i;
04217de4
DB
63 for (i = 0; i < width - 31; i += 32) {
64 const unsigned int j = i >> 1;
65 vector unsigned char v_yA = vec_ld(i, ysrc);
66 vector unsigned char v_yB = vec_ld(i + 16, ysrc);
67 vector unsigned char v_yC = vec_ld(i + 32, ysrc);
68 vector unsigned char v_y1 = vec_perm(v_yA, v_yB, yperm);
69 vector unsigned char v_y2 = vec_perm(v_yB, v_yC, yperm);
70 vector unsigned char v_uA = vec_ld(j, usrc);
71 vector unsigned char v_uB = vec_ld(j + 16, usrc);
72 vector unsigned char v_u = vec_perm(v_uA, v_uB, vec_lvsl(j, usrc));
73 vector unsigned char v_vA = vec_ld(j, vsrc);
74 vector unsigned char v_vB = vec_ld(j + 16, vsrc);
75 vector unsigned char v_v = vec_perm(v_vA, v_vB, vec_lvsl(j, vsrc));
76 vector unsigned char v_uv_a = vec_mergeh(v_u, v_v);
77 vector unsigned char v_uv_b = vec_mergel(v_u, v_v);
0e5d31b1
RB
78 vector unsigned char v_yuy2_0 = vec_mergeh(v_y1, v_uv_a);
79 vector unsigned char v_yuy2_1 = vec_mergel(v_y1, v_uv_a);
80 vector unsigned char v_yuy2_2 = vec_mergeh(v_y2, v_uv_b);
81 vector unsigned char v_yuy2_3 = vec_mergel(v_y2, v_uv_b);
82 vec_st(v_yuy2_0, (i << 1), dst);
83 vec_st(v_yuy2_1, (i << 1) + 16, dst);
84 vec_st(v_yuy2_2, (i << 1) + 32, dst);
85 vec_st(v_yuy2_3, (i << 1) + 48, dst);
86 }
87 if (i < width) {
04217de4
DB
88 const unsigned int j = i >> 1;
89 vector unsigned char v_y1 = vec_ld(i, ysrc);
90 vector unsigned char v_u = vec_ld(j, usrc);
91 vector unsigned char v_v = vec_ld(j, vsrc);
92 vector unsigned char v_uv_a = vec_mergeh(v_u, v_v);
0e5d31b1
RB
93 vector unsigned char v_yuy2_0 = vec_mergeh(v_y1, v_uv_a);
94 vector unsigned char v_yuy2_1 = vec_mergel(v_y1, v_uv_a);
95 vec_st(v_yuy2_0, (i << 1), dst);
96 vec_st(v_yuy2_1, (i << 1) + 16, dst);
97 }
04217de4 98 if ((y & (vertLumPerChroma - 1)) == vertLumPerChroma - 1) {
0e5d31b1
RB
99 usrc += chromStride;
100 vsrc += chromStride;
101 }
102 ysrc += lumStride;
04217de4 103 dst += dstStride;
0e5d31b1
RB
104 }
105
106 return srcSliceH;
107}
108
04217de4 109static int yv12touyvy_unscaled_altivec(SwsContext *c, const uint8_t *src[],
0e5d31b1 110 int srcStride[], int srcSliceY,
04217de4 111 int srcSliceH, uint8_t *dstParam[],
0e5d31b1
RB
112 int dstStride_a[])
113{
04217de4
DB
114 uint8_t *dst = dstParam[0] + dstStride_a[0] * srcSliceY;
115 // yv12toyuy2(src[0], src[1], src[2], dst, c->srcW, srcSliceH,
116 // srcStride[0], srcStride[1], dstStride[0]);
117 const uint8_t *ysrc = src[0];
118 const uint8_t *usrc = src[1];
119 const uint8_t *vsrc = src[2];
120 const int width = c->srcW;
121 const int height = srcSliceH;
122 const int lumStride = srcStride[0];
123 const int chromStride = srcStride[1];
124 const int dstStride = dstStride_a[0];
125 const int vertLumPerChroma = 2;
0e5d31b1
RB
126 const vector unsigned char yperm = vec_lvsl(0, ysrc);
127 register unsigned int y;
128
129 /* This code assumes:
04217de4
DB
130 *
131 * 1) dst is 16 bytes-aligned
132 * 2) dstStride is a multiple of 16
133 * 3) width is a multiple of 16
134 * 4) lum & chrom stride are multiples of 8
135 */
0e5d31b1 136
04217de4 137 for (y = 0; y < height; y++) {
0e5d31b1 138 int i;
04217de4
DB
139 for (i = 0; i < width - 31; i += 32) {
140 const unsigned int j = i >> 1;
141 vector unsigned char v_yA = vec_ld(i, ysrc);
142 vector unsigned char v_yB = vec_ld(i + 16, ysrc);
143 vector unsigned char v_yC = vec_ld(i + 32, ysrc);
144 vector unsigned char v_y1 = vec_perm(v_yA, v_yB, yperm);
145 vector unsigned char v_y2 = vec_perm(v_yB, v_yC, yperm);
146 vector unsigned char v_uA = vec_ld(j, usrc);
147 vector unsigned char v_uB = vec_ld(j + 16, usrc);
148 vector unsigned char v_u = vec_perm(v_uA, v_uB, vec_lvsl(j, usrc));
149 vector unsigned char v_vA = vec_ld(j, vsrc);
150 vector unsigned char v_vB = vec_ld(j + 16, vsrc);
151 vector unsigned char v_v = vec_perm(v_vA, v_vB, vec_lvsl(j, vsrc));
152 vector unsigned char v_uv_a = vec_mergeh(v_u, v_v);
153 vector unsigned char v_uv_b = vec_mergel(v_u, v_v);
0e5d31b1
RB
154 vector unsigned char v_uyvy_0 = vec_mergeh(v_uv_a, v_y1);
155 vector unsigned char v_uyvy_1 = vec_mergel(v_uv_a, v_y1);
156 vector unsigned char v_uyvy_2 = vec_mergeh(v_uv_b, v_y2);
157 vector unsigned char v_uyvy_3 = vec_mergel(v_uv_b, v_y2);
158 vec_st(v_uyvy_0, (i << 1), dst);
159 vec_st(v_uyvy_1, (i << 1) + 16, dst);
160 vec_st(v_uyvy_2, (i << 1) + 32, dst);
161 vec_st(v_uyvy_3, (i << 1) + 48, dst);
162 }
163 if (i < width) {
04217de4
DB
164 const unsigned int j = i >> 1;
165 vector unsigned char v_y1 = vec_ld(i, ysrc);
166 vector unsigned char v_u = vec_ld(j, usrc);
167 vector unsigned char v_v = vec_ld(j, vsrc);
168 vector unsigned char v_uv_a = vec_mergeh(v_u, v_v);
0e5d31b1
RB
169 vector unsigned char v_uyvy_0 = vec_mergeh(v_uv_a, v_y1);
170 vector unsigned char v_uyvy_1 = vec_mergel(v_uv_a, v_y1);
171 vec_st(v_uyvy_0, (i << 1), dst);
172 vec_st(v_uyvy_1, (i << 1) + 16, dst);
173 }
04217de4 174 if ((y & (vertLumPerChroma - 1)) == vertLumPerChroma - 1) {
0e5d31b1
RB
175 usrc += chromStride;
176 vsrc += chromStride;
177 }
178 ysrc += lumStride;
04217de4 179 dst += dstStride;
0e5d31b1
RB
180 }
181 return srcSliceH;
182}
183
c2503d9c
DB
184#endif /* HAVE_ALTIVEC */
185
3aa682f2 186void ff_get_unscaled_swscale_ppc(SwsContext *c)
0e5d31b1 187{
c2503d9c 188#if HAVE_ALTIVEC
0e5d31b1 189 if ((av_get_cpu_flags() & AV_CPU_FLAG_ALTIVEC) && !(c->srcW & 15) &&
716d413c
AK
190 !(c->flags & SWS_BITEXACT) && c->srcFormat == AV_PIX_FMT_YUV420P) {
191 enum AVPixelFormat dstFormat = c->dstFormat;
0e5d31b1
RB
192
193 // unscaled YV12 -> packed YUV, we want speed
716d413c 194 if (dstFormat == AV_PIX_FMT_YUYV422)
04217de4 195 c->swScale = yv12toyuy2_unscaled_altivec;
716d413c 196 else if (dstFormat == AV_PIX_FMT_UYVY422)
04217de4 197 c->swScale = yv12touyvy_unscaled_altivec;
0e5d31b1 198 }
c2503d9c 199#endif /* HAVE_ALTIVEC */
0e5d31b1 200}