2 * Alpha optimized DSP utils
3 * Copyright (c) 2002 Falk Hueffner <falk@debian.org>
5 * This file is part of FFmpeg.
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "dsputil_alpha.h"
25 static inline uint64_t avg2(uint64_t a, uint64_t b)
27 return (a | b) - (((a ^ b) & BYTE_VEC(0xfe)) >> 1);
30 static inline uint64_t avg4(uint64_t l1, uint64_t l2, uint64_t l3, uint64_t l4)
32 uint64_t r1 = ((l1 & ~BYTE_VEC(0x03)) >> 2)
33 + ((l2 & ~BYTE_VEC(0x03)) >> 2)
34 + ((l3 & ~BYTE_VEC(0x03)) >> 2)
35 + ((l4 & ~BYTE_VEC(0x03)) >> 2);
36 uint64_t r2 = (( (l1 & BYTE_VEC(0x03))
37 + (l2 & BYTE_VEC(0x03))
38 + (l3 & BYTE_VEC(0x03))
39 + (l4 & BYTE_VEC(0x03))
40 + BYTE_VEC(0x02)) >> 2) & BYTE_VEC(0x03);
44 int pix_abs8x8_mvi(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
48 if ((size_t) pix2 & 0x7) {
49 /* works only when pix2 is actually unaligned */
50 do { /* do 8 pixel a time */
55 result += perr(p1, p2);
66 result += perr(p1, p2);
76 #if 0 /* now done in assembly */
77 int pix_abs16x16_mvi(uint8_t *pix1, uint8_t *pix2, int line_size)
82 if ((size_t) pix2 & 0x7) {
83 /* works only when pix2 is actually unaligned */
84 do { /* do 16 pixel a time */
85 uint64_t p1_l, p1_r, p2_l, p2_r;
91 p2_l = extql(ldq_u(pix2), pix2) | extqh(t, pix2);
92 p2_r = extql(t, pix2) | extqh(ldq_u(pix2 + 16), pix2);
96 result += perr(p1_l, p2_l)
101 uint64_t p1_l, p1_r, p2_l, p2_r;
104 p1_r = ldq(pix1 + 8);
106 p2_r = ldq(pix2 + 8);
110 result += perr(p1_l, p2_l)
119 int pix_abs16x16_x2_mvi(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
122 uint64_t disalign = (size_t) pix2 & 0x7;
127 uint64_t p1_l, p1_r, p2_l, p2_r;
131 p1_r = ldq(pix1 + 8);
134 p2_l = avg2(l, (l >> 8) | ((uint64_t) r << 56));
135 p2_r = avg2(r, (r >> 8) | ((uint64_t) pix2[16] << 56));
139 result += perr(p1_l, p2_l)
144 /* |.......l|lllllllr|rrrrrrr*|
145 This case is special because disalign1 would be 8, which
146 gets treated as 0 by extqh. At least it is a bit faster
149 uint64_t p1_l, p1_r, p2_l, p2_r;
153 p1_r = ldq(pix1 + 8);
156 r = ldq_u(pix2 + 16);
157 p2_l = avg2(extql(l, disalign) | extqh(m, disalign), m);
158 p2_r = avg2(extql(m, disalign) | extqh(r, disalign), r);
162 result += perr(p1_l, p2_l)
168 uint64_t disalign1 = disalign + 1;
169 uint64_t p1_l, p1_r, p2_l, p2_r;
173 p1_r = ldq(pix1 + 8);
176 r = ldq_u(pix2 + 16);
177 p2_l = avg2(extql(l, disalign) | extqh(m, disalign),
178 extql(l, disalign1) | extqh(m, disalign1));
179 p2_r = avg2(extql(m, disalign) | extqh(r, disalign),
180 extql(m, disalign1) | extqh(r, disalign1));
184 result += perr(p1_l, p2_l)
192 int pix_abs16x16_y2_mvi(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
196 if ((size_t) pix2 & 0x7) {
197 uint64_t t, p2_l, p2_r;
199 p2_l = extql(ldq_u(pix2), pix2) | extqh(t, pix2);
200 p2_r = extql(t, pix2) | extqh(ldq_u(pix2 + 16), pix2);
203 uint64_t p1_l, p1_r, np2_l, np2_r;
207 p1_r = ldq(pix1 + 8);
210 np2_l = extql(ldq_u(pix2), pix2) | extqh(t, pix2);
211 np2_r = extql(t, pix2) | extqh(ldq_u(pix2 + 16), pix2);
213 result += perr(p1_l, avg2(p2_l, np2_l))
214 + perr(p1_r, avg2(p2_r, np2_r));
224 p2_r = ldq(pix2 + 8);
226 uint64_t p1_l, p1_r, np2_l, np2_r;
229 p1_r = ldq(pix1 + 8);
232 np2_r = ldq(pix2 + 8);
234 result += perr(p1_l, avg2(p2_l, np2_l))
235 + perr(p1_r, avg2(p2_r, np2_r));
245 int pix_abs16x16_xy2_mvi(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
250 uint64_t p2_l, p2_r, p2_x;
253 p1_r = ldq(pix1 + 8);
255 if ((size_t) pix2 & 0x7) { /* could be optimized a lot */
257 p2_r = uldq(pix2 + 8);
258 p2_x = (uint64_t) pix2[16] << 56;
261 p2_r = ldq(pix2 + 8);
262 p2_x = ldq(pix2 + 16) << 56;
266 uint64_t np1_l, np1_r;
267 uint64_t np2_l, np2_r, np2_x;
273 np1_r = ldq(pix1 + 8);
275 if ((size_t) pix2 & 0x7) { /* could be optimized a lot */
277 np2_r = uldq(pix2 + 8);
278 np2_x = (uint64_t) pix2[16] << 56;
281 np2_r = ldq(pix2 + 8);
282 np2_x = ldq(pix2 + 16) << 56;
286 avg4( p2_l, ( p2_l >> 8) | ((uint64_t) p2_r << 56),
287 np2_l, (np2_l >> 8) | ((uint64_t) np2_r << 56)))
289 avg4( p2_r, ( p2_r >> 8) | ((uint64_t) p2_x),
290 np2_r, (np2_r >> 8) | ((uint64_t) np2_x)));