FFmpeg
Loading...
Searching...
No Matches
me_cmp_altivec.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2002 Brian Foley
3 * Copyright (c) 2002 Dieter Shirley
4 * Copyright (c) 2003-2004 Romain Dolbeau <romain@dolbeau.org>
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23#include "config.h"
24
27
28#include "libavcodec/avcodec.h"
30#include "libavcodec/me_cmp.h"
31
32#include "me_cmp_altivec.h"
33
34#if HAVE_BIGENDIAN
35#define GET_PERM(per1, per2, pix) {\
36 per1 = vec_lvsl(0, pix);\
37 per2 = vec_add(per1, vec_splat_u8(1));\
38}
39#define LOAD_PIX(v, iv, pix, per1, per2) {\
40 vector unsigned char pix2l = vec_ld(0, pix);\
41 vector unsigned char pix2r = vec_ld(16, pix);\
42 v = vec_perm(pix2l, pix2r, per1);\
43 iv = vec_perm(pix2l, pix2r, per2);\
44}
45#else
46#define GET_PERM(per1, per2, pix) {}
47#define LOAD_PIX(v, iv, pix, per1, per2) {\
48 v = vec_vsx_ld(0, pix);\
49 iv = vec_vsx_ld(1, pix);\
50}
51#endif
52static int sad16_x2_altivec(MPVEncContext *v, const uint8_t *pix1, const uint8_t *pix2,
53 ptrdiff_t stride, int h)
54{
55 int i;
56 int __attribute__((aligned(16))) s = 0;
57 const vector unsigned char zero =
58 (const vector unsigned char) vec_splat_u8(0);
59 vector unsigned int sad = (vector unsigned int) vec_splat_u32(0);
60 vector signed int sumdiffs;
61 vector unsigned char perm1, perm2, pix2v, pix2iv;
62
63 GET_PERM(perm1, perm2, pix2);
64 for (i = 0; i < h; i++) {
65 /* Read unaligned pixels into our vectors. The vectors are as follows:
66 * pix1v: pix1[0] - pix1[15]
67 * pix2v: pix2[0] - pix2[15] pix2iv: pix2[1] - pix2[16] */
68 vector unsigned char pix1v = vec_ld(0, pix1);
69 LOAD_PIX(pix2v, pix2iv, pix2, perm1, perm2);
70
71 /* Calculate the average vector. */
72 vector unsigned char avgv = vec_avg(pix2v, pix2iv);
73
74 /* Calculate a sum of abs differences vector. */
75 vector unsigned char t5 = vec_sub(vec_max(pix1v, avgv),
76 vec_min(pix1v, avgv));
77
78 /* Add each 4 pixel group together and put 4 results into sad. */
79 sad = vec_sum4s(t5, sad);
80
81 pix1 += stride;
82 pix2 += stride;
83 }
84 /* Sum up the four partial sums, and put the result into s. */
85 sumdiffs = vec_sums((vector signed int) sad, (vector signed int) zero);
86 sumdiffs = vec_splat(sumdiffs, 3);
87 vec_ste(sumdiffs, 0, &s);
88
89 return s;
90}
91
92static int sad16_y2_altivec(MPVEncContext *v, const uint8_t *pix1, const uint8_t *pix2,
93 ptrdiff_t stride, int h)
94{
95 int i;
96 int __attribute__((aligned(16))) s = 0;
97 const vector unsigned char zero =
98 (const vector unsigned char) vec_splat_u8(0);
99 vector unsigned char pix1v, pix3v, avgv, t5;
100 vector unsigned int sad = (vector unsigned int) vec_splat_u32(0);
101 vector signed int sumdiffs;
102
103 const uint8_t *pix3 = pix2 + stride;
104
105 /* Due to the fact that pix3 = pix2 + stride, the pix3 of one
106 * iteration becomes pix2 in the next iteration. We can use this
107 * fact to avoid a potentially expensive unaligned read, each
108 * time around the loop.
109 * Read unaligned pixels into our vectors. The vectors are as follows:
110 * pix2v: pix2[0] - pix2[15]
111 * Split the pixel vectors into shorts. */
112 vector unsigned char pix2v = VEC_LD(0, pix2);
113
114 for (i = 0; i < h; i++) {
115 /* Read unaligned pixels into our vectors. The vectors are as follows:
116 * pix1v: pix1[0] - pix1[15]
117 * pix3v: pix3[0] - pix3[15] */
118 pix1v = vec_ld(0, pix1);
119 pix3v = VEC_LD(0, pix3);
120
121 /* Calculate the average vector. */
122 avgv = vec_avg(pix2v, pix3v);
123
124 /* Calculate a sum of abs differences vector. */
125 t5 = vec_sub(vec_max(pix1v, avgv), vec_min(pix1v, avgv));
126
127 /* Add each 4 pixel group together and put 4 results into sad. */
128 sad = vec_sum4s(t5, sad);
129
130 pix1 += stride;
131 pix2v = pix3v;
132 pix3 += stride;
133 }
134
135 /* Sum up the four partial sums, and put the result into s. */
136 sumdiffs = vec_sums((vector signed int) sad, (vector signed int) zero);
137 sumdiffs = vec_splat(sumdiffs, 3);
138 vec_ste(sumdiffs, 0, &s);
139 return s;
140}
141
142static int sad16_xy2_altivec(MPVEncContext *v, const uint8_t *pix1, const uint8_t *pix2,
143 ptrdiff_t stride, int h)
144{
145 int i;
146 int __attribute__((aligned(16))) s = 0;
147 const uint8_t *pix3 = pix2 + stride;
148 const vector unsigned char zero =
149 (const vector unsigned char) vec_splat_u8(0);
150 const vector unsigned short two =
151 (const vector unsigned short) vec_splat_u16(2);
152 vector unsigned char avgv, t5;
153 vector unsigned char pix1v, pix3v, pix3iv;
154 vector unsigned short pix3lv, pix3hv, pix3ilv, pix3ihv;
155 vector unsigned short avghv, avglv;
156 vector unsigned int sad = (vector unsigned int) vec_splat_u32(0);
157 vector signed int sumdiffs;
158 vector unsigned char perm1, perm2, pix2v, pix2iv;
159 GET_PERM(perm1, perm2, pix2);
160
161 /* Due to the fact that pix3 = pix2 + stride, the pix3 of one
162 * iteration becomes pix2 in the next iteration. We can use this
163 * fact to avoid a potentially expensive unaligned read, as well
164 * as some splitting, and vector addition each time around the loop.
165 * Read unaligned pixels into our vectors. The vectors are as follows:
166 * pix2v: pix2[0] - pix2[15] pix2iv: pix2[1] - pix2[16]
167 * Split the pixel vectors into shorts. */
168 LOAD_PIX(pix2v, pix2iv, pix2, perm1, perm2);
169 vector unsigned short pix2hv =
170 (vector unsigned short) VEC_MERGEH(zero, pix2v);
171 vector unsigned short pix2lv =
172 (vector unsigned short) VEC_MERGEL(zero, pix2v);
173 vector unsigned short pix2ihv =
174 (vector unsigned short) VEC_MERGEH(zero, pix2iv);
175 vector unsigned short pix2ilv =
176 (vector unsigned short) VEC_MERGEL(zero, pix2iv);
177
178 vector unsigned short t1 = vec_add(pix2hv, pix2ihv);
179 vector unsigned short t2 = vec_add(pix2lv, pix2ilv);
180 vector unsigned short t3, t4;
181
182 for (i = 0; i < h; i++) {
183 /* Read unaligned pixels into our vectors. The vectors are as follows:
184 * pix1v: pix1[0] - pix1[15]
185 * pix3v: pix3[0] - pix3[15] pix3iv: pix3[1] - pix3[16] */
186 pix1v = vec_ld(0, pix1);
187 LOAD_PIX(pix3v, pix3iv, pix3, perm1, perm2);
188
189 /* Note that AltiVec does have vec_avg, but this works on vector pairs
190 * and rounds up. We could do avg(avg(a, b), avg(c, d)), but the
191 * rounding would mean that, for example, avg(3, 0, 0, 1) = 2, when
192 * it should be 1. Instead, we have to split the pixel vectors into
193 * vectors of shorts and do the averaging by hand. */
194
195 /* Split the pixel vectors into shorts. */
196 pix3hv = (vector unsigned short) VEC_MERGEH(zero, pix3v);
197 pix3lv = (vector unsigned short) VEC_MERGEL(zero, pix3v);
198 pix3ihv = (vector unsigned short) VEC_MERGEH(zero, pix3iv);
199 pix3ilv = (vector unsigned short) VEC_MERGEL(zero, pix3iv);
200
201 /* Do the averaging on them. */
202 t3 = vec_add(pix3hv, pix3ihv);
203 t4 = vec_add(pix3lv, pix3ilv);
204
205 avghv = vec_sr(vec_add(vec_add(t1, t3), two), two);
206 avglv = vec_sr(vec_add(vec_add(t2, t4), two), two);
207
208 /* Pack the shorts back into a result. */
209 avgv = vec_pack(avghv, avglv);
210
211 /* Calculate a sum of abs differences vector. */
212 t5 = vec_sub(vec_max(pix1v, avgv), vec_min(pix1v, avgv));
213
214 /* Add each 4 pixel group together and put 4 results into sad. */
215 sad = vec_sum4s(t5, sad);
216
217 pix1 += stride;
218 pix3 += stride;
219 /* Transfer the calculated values for pix3 into pix2. */
220 t1 = t3;
221 t2 = t4;
222 }
223 /* Sum up the four partial sums, and put the result into s. */
224 sumdiffs = vec_sums((vector signed int) sad, (vector signed int) zero);
225 sumdiffs = vec_splat(sumdiffs, 3);
226 vec_ste(sumdiffs, 0, &s);
227
228 return s;
229}
230
231static int sad16_altivec(MPVEncContext *v, const uint8_t *pix1, const uint8_t *pix2,
232 ptrdiff_t stride, int h)
233{
234 int i;
235 int __attribute__((aligned(16))) s;
236 const vector unsigned int zero =
237 (const vector unsigned int) vec_splat_u32(0);
238 vector unsigned int sad = (vector unsigned int) vec_splat_u32(0);
239 vector signed int sumdiffs;
240
241 for (i = 0; i < h; i++) {
242 /* Read potentially unaligned pixels into t1 and t2. */
243 vector unsigned char t1 =vec_ld(0, pix1);
244 vector unsigned char t2 = VEC_LD(0, pix2);
245
246 /* Calculate a sum of abs differences vector. */
247 vector unsigned char t3 = vec_max(t1, t2);
248 vector unsigned char t4 = vec_min(t1, t2);
249 vector unsigned char t5 = vec_sub(t3, t4);
250
251 /* Add each 4 pixel group together and put 4 results into sad. */
252 sad = vec_sum4s(t5, sad);
253
254 pix1 += stride;
255 pix2 += stride;
256 }
257
258 /* Sum up the four partial sums, and put the result into s. */
259 sumdiffs = vec_sums((vector signed int) sad, (vector signed int) zero);
260 sumdiffs = vec_splat(sumdiffs, 3);
261 vec_ste(sumdiffs, 0, &s);
262
263 return s;
264}
265
266static int sad8_altivec(MPVEncContext *v, const uint8_t *pix1, const uint8_t *pix2,
267 ptrdiff_t stride, int h)
268{
269 int i;
270 int __attribute__((aligned(16))) s;
271 const vector unsigned int zero =
272 (const vector unsigned int) vec_splat_u32(0);
273 const vector unsigned char permclear =
274 (vector unsigned char)
275 { 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0 };
276 vector unsigned int sad = (vector unsigned int) vec_splat_u32(0);
277 vector signed int sumdiffs;
278
279 for (i = 0; i < h; i++) {
280 /* Read potentially unaligned pixels into t1 and t2.
281 * Since we're reading 16 pixels, and actually only want 8,
282 * mask out the last 8 pixels. The 0s don't change the sum. */
283 vector unsigned char pix1l = VEC_LD(0, pix1);
284 vector unsigned char pix2l = VEC_LD(0, pix2);
285 vector unsigned char t1 = vec_and(pix1l, permclear);
286 vector unsigned char t2 = vec_and(pix2l, permclear);
287
288 /* Calculate a sum of abs differences vector. */
289 vector unsigned char t3 = vec_max(t1, t2);
290 vector unsigned char t4 = vec_min(t1, t2);
291 vector unsigned char t5 = vec_sub(t3, t4);
292
293 /* Add each 4 pixel group together and put 4 results into sad. */
294 sad = vec_sum4s(t5, sad);
295
296 pix1 += stride;
297 pix2 += stride;
298 }
299
300 /* Sum up the four partial sums, and put the result into s. */
301 sumdiffs = vec_sums((vector signed int) sad, (vector signed int) zero);
302 sumdiffs = vec_splat(sumdiffs, 3);
303 vec_ste(sumdiffs, 0, &s);
304
305 return s;
306}
307
308/* Sum of Squared Errors for an 8x8 block, AltiVec-enhanced.
309 * It's the sad8_altivec code above w/ squaring added. */
310static int sse8_altivec(MPVEncContext *v, const uint8_t *pix1, const uint8_t *pix2,
311 ptrdiff_t stride, int h)
312{
313 int i;
314 int __attribute__((aligned(16))) s;
315 const vector unsigned int zero =
316 (const vector unsigned int) vec_splat_u32(0);
317 const vector unsigned char permclear =
318 (vector unsigned char)
319 { 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0 };
320 vector unsigned int sum = (vector unsigned int) vec_splat_u32(0);
321 vector signed int sumsqr;
322
323 for (i = 0; i < h; i++) {
324 /* Read potentially unaligned pixels into t1 and t2.
325 * Since we're reading 16 pixels, and actually only want 8,
326 * mask out the last 8 pixels. The 0s don't change the sum. */
327 vector unsigned char t1 = vec_and(VEC_LD(0, pix1), permclear);
328 vector unsigned char t2 = vec_and(VEC_LD(0, pix2), permclear);
329
330 /* Since we want to use unsigned chars, we can take advantage
331 * of the fact that abs(a - b) ^ 2 = (a - b) ^ 2. */
332
333 /* Calculate abs differences vector. */
334 vector unsigned char t3 = vec_max(t1, t2);
335 vector unsigned char t4 = vec_min(t1, t2);
336 vector unsigned char t5 = vec_sub(t3, t4);
337
338 /* Square the values and add them to our sum. */
339 sum = vec_msum(t5, t5, sum);
340
341 pix1 += stride;
342 pix2 += stride;
343 }
344
345 /* Sum up the four partial sums, and put the result into s. */
346 sumsqr = vec_sums((vector signed int) sum, (vector signed int) zero);
347 sumsqr = vec_splat(sumsqr, 3);
348 vec_ste(sumsqr, 0, &s);
349
350 return s;
351}
352
353/* Sum of Squared Errors for a 16x16 block, AltiVec-enhanced.
354 * It's the sad16_altivec code above w/ squaring added. */
355static int sse16_altivec(MPVEncContext *v, const uint8_t *pix1, const uint8_t *pix2,
356 ptrdiff_t stride, int h)
357{
358 int i;
359 int __attribute__((aligned(16))) s;
360 const vector unsigned int zero =
361 (const vector unsigned int) vec_splat_u32(0);
362 vector unsigned int sum = (vector unsigned int) vec_splat_u32(0);
363 vector signed int sumsqr;
364
365 for (i = 0; i < h; i++) {
366 /* Read potentially unaligned pixels into t1 and t2. */
367 vector unsigned char t1 = vec_ld(0, pix1);
368 vector unsigned char t2 = VEC_LD(0, pix2);
369
370 /* Since we want to use unsigned chars, we can take advantage
371 * of the fact that abs(a - b) ^ 2 = (a - b) ^ 2. */
372
373 /* Calculate abs differences vector. */
374 vector unsigned char t3 = vec_max(t1, t2);
375 vector unsigned char t4 = vec_min(t1, t2);
376 vector unsigned char t5 = vec_sub(t3, t4);
377
378 /* Square the values and add them to our sum. */
379 sum = vec_msum(t5, t5, sum);
380
381 pix1 += stride;
382 pix2 += stride;
383 }
384
385 /* Sum up the four partial sums, and put the result into s. */
386 sumsqr = vec_sums((vector signed int) sum, (vector signed int) zero);
387 sumsqr = vec_splat(sumsqr, 3);
388
389 vec_ste(sumsqr, 0, &s);
390 return s;
391}
392
393static int hadamard8_diff8x8_altivec(MPVEncContext *s, const uint8_t *dst,
394 const uint8_t *src, ptrdiff_t stride, int h)
395{
396 int __attribute__((aligned(16))) sum;
397 register const vector unsigned char vzero =
398 (const vector unsigned char) vec_splat_u8(0);
399 register vector signed short temp0, temp1, temp2, temp3, temp4,
400 temp5, temp6, temp7;
401 {
402 register const vector signed short vprod1 =
403 (const vector signed short) { 1, -1, 1, -1, 1, -1, 1, -1 };
404 register const vector signed short vprod2 =
405 (const vector signed short) { 1, 1, -1, -1, 1, 1, -1, -1 };
406 register const vector signed short vprod3 =
407 (const vector signed short) { 1, 1, 1, 1, -1, -1, -1, -1 };
408 register const vector unsigned char perm1 =
409 (const vector unsigned char)
410 { 0x02, 0x03, 0x00, 0x01, 0x06, 0x07, 0x04, 0x05,
411 0x0A, 0x0B, 0x08, 0x09, 0x0E, 0x0F, 0x0C, 0x0D };
412 register const vector unsigned char perm2 =
413 (const vector unsigned char)
414 { 0x04, 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03,
415 0x0C, 0x0D, 0x0E, 0x0F, 0x08, 0x09, 0x0A, 0x0B };
416 register const vector unsigned char perm3 =
417 (const vector unsigned char)
418 { 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
419 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 };
420
421
422#define ONEITERBUTTERFLY(i, res) \
423 { \
424 register vector unsigned char srcO = unaligned_load(stride * i, src); \
425 register vector unsigned char dstO = unaligned_load(stride * i, dst);\
426 \
427 /* Promote the unsigned chars to signed shorts. */ \
428 /* We're in the 8x8 function, we only care for the first 8. */ \
429 register vector signed short srcV = \
430 (vector signed short) VEC_MERGEH((vector signed char) vzero, \
431 (vector signed char) srcO); \
432 register vector signed short dstV = \
433 (vector signed short) VEC_MERGEH((vector signed char) vzero, \
434 (vector signed char) dstO); \
435 \
436 /* subtractions inside the first butterfly */ \
437 register vector signed short but0 = vec_sub(srcV, dstV); \
438 register vector signed short op1 = vec_perm(but0, but0, perm1); \
439 register vector signed short but1 = vec_mladd(but0, vprod1, op1); \
440 register vector signed short op2 = vec_perm(but1, but1, perm2); \
441 register vector signed short but2 = vec_mladd(but1, vprod2, op2); \
442 register vector signed short op3 = vec_perm(but2, but2, perm3); \
443 res = vec_mladd(but2, vprod3, op3); \
444 }
445
446 ONEITERBUTTERFLY(0, temp0);
447 ONEITERBUTTERFLY(1, temp1);
448 ONEITERBUTTERFLY(2, temp2);
449 ONEITERBUTTERFLY(3, temp3);
450 ONEITERBUTTERFLY(4, temp4);
451 ONEITERBUTTERFLY(5, temp5);
452 ONEITERBUTTERFLY(6, temp6);
453 ONEITERBUTTERFLY(7, temp7);
454 }
455#undef ONEITERBUTTERFLY
456 {
457 register vector signed int vsum;
458 register vector signed short line0 = vec_add(temp0, temp1);
459 register vector signed short line1 = vec_sub(temp0, temp1);
460 register vector signed short line2 = vec_add(temp2, temp3);
461 register vector signed short line3 = vec_sub(temp2, temp3);
462 register vector signed short line4 = vec_add(temp4, temp5);
463 register vector signed short line5 = vec_sub(temp4, temp5);
464 register vector signed short line6 = vec_add(temp6, temp7);
465 register vector signed short line7 = vec_sub(temp6, temp7);
466
467 register vector signed short line0B = vec_add(line0, line2);
468 register vector signed short line2B = vec_sub(line0, line2);
469 register vector signed short line1B = vec_add(line1, line3);
470 register vector signed short line3B = vec_sub(line1, line3);
471 register vector signed short line4B = vec_add(line4, line6);
472 register vector signed short line6B = vec_sub(line4, line6);
473 register vector signed short line5B = vec_add(line5, line7);
474 register vector signed short line7B = vec_sub(line5, line7);
475
476 register vector signed short line0C = vec_add(line0B, line4B);
477 register vector signed short line4C = vec_sub(line0B, line4B);
478 register vector signed short line1C = vec_add(line1B, line5B);
479 register vector signed short line5C = vec_sub(line1B, line5B);
480 register vector signed short line2C = vec_add(line2B, line6B);
481 register vector signed short line6C = vec_sub(line2B, line6B);
482 register vector signed short line3C = vec_add(line3B, line7B);
483 register vector signed short line7C = vec_sub(line3B, line7B);
484
485 vsum = vec_sum4s(vec_abs(line0C), vec_splat_s32(0));
486 vsum = vec_sum4s(vec_abs(line1C), vsum);
487 vsum = vec_sum4s(vec_abs(line2C), vsum);
488 vsum = vec_sum4s(vec_abs(line3C), vsum);
489 vsum = vec_sum4s(vec_abs(line4C), vsum);
490 vsum = vec_sum4s(vec_abs(line5C), vsum);
491 vsum = vec_sum4s(vec_abs(line6C), vsum);
492 vsum = vec_sum4s(vec_abs(line7C), vsum);
493 vsum = vec_sums(vsum, (vector signed int) vzero);
494 vsum = vec_splat(vsum, 3);
495
496 vec_ste(vsum, 0, &sum);
497 }
498 return sum;
499}
500
501/*
502 * 16x8 works with 16 elements; it can avoid replicating loads, and
503 * gives the compiler more room for scheduling. It's only used from
504 * inside hadamard8_diff16_altivec.
505 *
506 * Unfortunately, it seems gcc-3.3 is a bit dumb, and the compiled code has
507 * a LOT of spill code, it seems gcc (unlike xlc) cannot keep everything in
508 * registers by itself. The following code includes hand-made register
509 * allocation. It's not clean, but on a 7450 the resulting code is much faster
510 * (best case falls from 700+ cycles to 550).
511 *
512 * xlc doesn't add spill code, but it doesn't know how to schedule for the
513 * 7450, and its code isn't much faster than gcc-3.3 on the 7450 (but uses
514 * 25% fewer instructions...)
515 *
516 * On the 970, the hand-made RA is still a win (around 690 vs. around 780),
517 * but xlc goes to around 660 on the regular C code...
518 */
519static int hadamard8_diff16x8_altivec(MPVEncContext *s, const uint8_t *dst,
520 const uint8_t *src, ptrdiff_t stride, int h)
521{
522 int __attribute__((aligned(16))) sum;
523 register vector signed short
524 temp0 __asm__ ("v0"),
525 temp1 __asm__ ("v1"),
526 temp2 __asm__ ("v2"),
527 temp3 __asm__ ("v3"),
528 temp4 __asm__ ("v4"),
529 temp5 __asm__ ("v5"),
530 temp6 __asm__ ("v6"),
531 temp7 __asm__ ("v7");
532 register vector signed short
533 temp0S __asm__ ("v8"),
534 temp1S __asm__ ("v9"),
535 temp2S __asm__ ("v10"),
536 temp3S __asm__ ("v11"),
537 temp4S __asm__ ("v12"),
538 temp5S __asm__ ("v13"),
539 temp6S __asm__ ("v14"),
540 temp7S __asm__ ("v15");
541 register const vector unsigned char vzero __asm__ ("v31") =
542 (const vector unsigned char) vec_splat_u8(0);
543 {
544 register const vector signed short vprod1 __asm__ ("v16") =
545 (const vector signed short) { 1, -1, 1, -1, 1, -1, 1, -1 };
546
547 register const vector signed short vprod2 __asm__ ("v17") =
548 (const vector signed short) { 1, 1, -1, -1, 1, 1, -1, -1 };
549
550 register const vector signed short vprod3 __asm__ ("v18") =
551 (const vector signed short) { 1, 1, 1, 1, -1, -1, -1, -1 };
552
553 register const vector unsigned char perm1 __asm__ ("v19") =
554 (const vector unsigned char)
555 { 0x02, 0x03, 0x00, 0x01, 0x06, 0x07, 0x04, 0x05,
556 0x0A, 0x0B, 0x08, 0x09, 0x0E, 0x0F, 0x0C, 0x0D };
557
558 register const vector unsigned char perm2 __asm__ ("v20") =
559 (const vector unsigned char)
560 { 0x04, 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03,
561 0x0C, 0x0D, 0x0E, 0x0F, 0x08, 0x09, 0x0A, 0x0B };
562
563 register const vector unsigned char perm3 __asm__ ("v21") =
564 (const vector unsigned char)
565 { 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
566 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 };
567
568#define ONEITERBUTTERFLY(i, res1, res2) \
569 { \
570 register vector unsigned char srcO __asm__ ("v22") = \
571 unaligned_load(stride * i, src); \
572 register vector unsigned char dstO __asm__ ("v23") = \
573 unaligned_load(stride * i, dst);\
574 \
575 /* Promote the unsigned chars to signed shorts. */ \
576 register vector signed short srcV __asm__ ("v24") = \
577 (vector signed short) VEC_MERGEH((vector signed char) vzero, \
578 (vector signed char) srcO); \
579 register vector signed short dstV __asm__ ("v25") = \
580 (vector signed short) VEC_MERGEH((vector signed char) vzero, \
581 (vector signed char) dstO); \
582 register vector signed short srcW __asm__ ("v26") = \
583 (vector signed short) VEC_MERGEL((vector signed char) vzero, \
584 (vector signed char) srcO); \
585 register vector signed short dstW __asm__ ("v27") = \
586 (vector signed short) VEC_MERGEL((vector signed char) vzero, \
587 (vector signed char) dstO); \
588 \
589 /* subtractions inside the first butterfly */ \
590 register vector signed short but0 __asm__ ("v28") = \
591 vec_sub(srcV, dstV); \
592 register vector signed short but0S __asm__ ("v29") = \
593 vec_sub(srcW, dstW); \
594 register vector signed short op1 __asm__ ("v30") = \
595 vec_perm(but0, but0, perm1); \
596 register vector signed short but1 __asm__ ("v22") = \
597 vec_mladd(but0, vprod1, op1); \
598 register vector signed short op1S __asm__ ("v23") = \
599 vec_perm(but0S, but0S, perm1); \
600 register vector signed short but1S __asm__ ("v24") = \
601 vec_mladd(but0S, vprod1, op1S); \
602 register vector signed short op2 __asm__ ("v25") = \
603 vec_perm(but1, but1, perm2); \
604 register vector signed short but2 __asm__ ("v26") = \
605 vec_mladd(but1, vprod2, op2); \
606 register vector signed short op2S __asm__ ("v27") = \
607 vec_perm(but1S, but1S, perm2); \
608 register vector signed short but2S __asm__ ("v28") = \
609 vec_mladd(but1S, vprod2, op2S); \
610 register vector signed short op3 __asm__ ("v29") = \
611 vec_perm(but2, but2, perm3); \
612 register vector signed short op3S __asm__ ("v30") = \
613 vec_perm(but2S, but2S, perm3); \
614 res1 = vec_mladd(but2, vprod3, op3); \
615 res2 = vec_mladd(but2S, vprod3, op3S); \
616 }
617
618 ONEITERBUTTERFLY(0, temp0, temp0S);
619 ONEITERBUTTERFLY(1, temp1, temp1S);
620 ONEITERBUTTERFLY(2, temp2, temp2S);
621 ONEITERBUTTERFLY(3, temp3, temp3S);
622 ONEITERBUTTERFLY(4, temp4, temp4S);
623 ONEITERBUTTERFLY(5, temp5, temp5S);
624 ONEITERBUTTERFLY(6, temp6, temp6S);
625 ONEITERBUTTERFLY(7, temp7, temp7S);
626 }
627#undef ONEITERBUTTERFLY
628 {
629 register vector signed int vsum;
630
631 register vector signed short line0 = vec_add(temp0, temp1);
632 register vector signed short line1 = vec_sub(temp0, temp1);
633 register vector signed short line2 = vec_add(temp2, temp3);
634 register vector signed short line3 = vec_sub(temp2, temp3);
635 register vector signed short line4 = vec_add(temp4, temp5);
636 register vector signed short line5 = vec_sub(temp4, temp5);
637 register vector signed short line6 = vec_add(temp6, temp7);
638 register vector signed short line7 = vec_sub(temp6, temp7);
639
640 register vector signed short line0B = vec_add(line0, line2);
641 register vector signed short line2B = vec_sub(line0, line2);
642 register vector signed short line1B = vec_add(line1, line3);
643 register vector signed short line3B = vec_sub(line1, line3);
644 register vector signed short line4B = vec_add(line4, line6);
645 register vector signed short line6B = vec_sub(line4, line6);
646 register vector signed short line5B = vec_add(line5, line7);
647 register vector signed short line7B = vec_sub(line5, line7);
648
649 register vector signed short line0C = vec_add(line0B, line4B);
650 register vector signed short line4C = vec_sub(line0B, line4B);
651 register vector signed short line1C = vec_add(line1B, line5B);
652 register vector signed short line5C = vec_sub(line1B, line5B);
653 register vector signed short line2C = vec_add(line2B, line6B);
654 register vector signed short line6C = vec_sub(line2B, line6B);
655 register vector signed short line3C = vec_add(line3B, line7B);
656 register vector signed short line7C = vec_sub(line3B, line7B);
657
658 register vector signed short line0S = vec_add(temp0S, temp1S);
659 register vector signed short line1S = vec_sub(temp0S, temp1S);
660 register vector signed short line2S = vec_add(temp2S, temp3S);
661 register vector signed short line3S = vec_sub(temp2S, temp3S);
662 register vector signed short line4S = vec_add(temp4S, temp5S);
663 register vector signed short line5S = vec_sub(temp4S, temp5S);
664 register vector signed short line6S = vec_add(temp6S, temp7S);
665 register vector signed short line7S = vec_sub(temp6S, temp7S);
666
667 register vector signed short line0BS = vec_add(line0S, line2S);
668 register vector signed short line2BS = vec_sub(line0S, line2S);
669 register vector signed short line1BS = vec_add(line1S, line3S);
670 register vector signed short line3BS = vec_sub(line1S, line3S);
671 register vector signed short line4BS = vec_add(line4S, line6S);
672 register vector signed short line6BS = vec_sub(line4S, line6S);
673 register vector signed short line5BS = vec_add(line5S, line7S);
674 register vector signed short line7BS = vec_sub(line5S, line7S);
675
676 register vector signed short line0CS = vec_add(line0BS, line4BS);
677 register vector signed short line4CS = vec_sub(line0BS, line4BS);
678 register vector signed short line1CS = vec_add(line1BS, line5BS);
679 register vector signed short line5CS = vec_sub(line1BS, line5BS);
680 register vector signed short line2CS = vec_add(line2BS, line6BS);
681 register vector signed short line6CS = vec_sub(line2BS, line6BS);
682 register vector signed short line3CS = vec_add(line3BS, line7BS);
683 register vector signed short line7CS = vec_sub(line3BS, line7BS);
684
685 vsum = vec_sum4s(vec_abs(line0C), vec_splat_s32(0));
686 vsum = vec_sum4s(vec_abs(line1C), vsum);
687 vsum = vec_sum4s(vec_abs(line2C), vsum);
688 vsum = vec_sum4s(vec_abs(line3C), vsum);
689 vsum = vec_sum4s(vec_abs(line4C), vsum);
690 vsum = vec_sum4s(vec_abs(line5C), vsum);
691 vsum = vec_sum4s(vec_abs(line6C), vsum);
692 vsum = vec_sum4s(vec_abs(line7C), vsum);
693
694 vsum = vec_sum4s(vec_abs(line0CS), vsum);
695 vsum = vec_sum4s(vec_abs(line1CS), vsum);
696 vsum = vec_sum4s(vec_abs(line2CS), vsum);
697 vsum = vec_sum4s(vec_abs(line3CS), vsum);
698 vsum = vec_sum4s(vec_abs(line4CS), vsum);
699 vsum = vec_sum4s(vec_abs(line5CS), vsum);
700 vsum = vec_sum4s(vec_abs(line6CS), vsum);
701 vsum = vec_sum4s(vec_abs(line7CS), vsum);
702 vsum = vec_sums(vsum, (vector signed int) vzero);
703 vsum = vec_splat(vsum, 3);
704
705 vec_ste(vsum, 0, &sum);
706 }
707 return sum;
708}
709
710static int hadamard8_diff16_altivec(MPVEncContext *s, const uint8_t *dst,
711 const uint8_t *src, ptrdiff_t stride, int h)
712{
713 int score = hadamard8_diff16x8_altivec(s, dst, src, stride, 8);
714
715 if (h == 16) {
716 dst += 8 * stride;
717 src += 8 * stride;
718 score += hadamard8_diff16x8_altivec(s, dst, src, stride, 8);
719 }
720 return score;
721}
722
724{
725 c->pix_abs[0][1] = sad16_x2_altivec;
726 c->pix_abs[0][2] = sad16_y2_altivec;
727 c->pix_abs[0][3] = sad16_xy2_altivec;
728 c->pix_abs[0][0] = sad16_altivec;
729 c->pix_abs[1][0] = sad8_altivec;
730
731 c->sad[0] = sad16_altivec;
732 c->sad[1] = sad8_altivec;
733 c->sse[0] = sse16_altivec;
734 c->sse[1] = sse8_altivec;
735
736 c->hadamard8_diff[0] = hadamard8_diff16_altivec;
737 c->hadamard8_diff[1] = hadamard8_diff8x8_altivec;
738}
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:97
__asm__(".macro parse_r var r\n\t" "\\var = -1\n\t" _IFC_REG(0) _IFC_REG(1) _IFC_REG(2) _IFC_REG(3) _IFC_REG(4) _IFC_REG(5) _IFC_REG(6) _IFC_REG(7) _IFC_REG(8) _IFC_REG(9) _IFC_REG(10) _IFC_REG(11) _IFC_REG(12) _IFC_REG(13) _IFC_REG(14) _IFC_REG(15) _IFC_REG(16) _IFC_REG(17) _IFC_REG(18) _IFC_REG(19) _IFC_REG(20) _IFC_REG(21) _IFC_REG(22) _IFC_REG(23) _IFC_REG(24) _IFC_REG(25) _IFC_REG(26) _IFC_REG(27) _IFC_REG(28) _IFC_REG(29) _IFC_REG(30) _IFC_REG(31) ".iflt \\var\n\t" ".error \"Unable to parse register name \\r\"\n\t" ".endif\n\t" ".endm")
Libavcodec external API header.
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define s(width, name)
Definition cbs_vp9.c:198
static int zero(InterplayACMContext *s, unsigned ind, unsigned col)
Macro definitions for various function/variable attributes.
#define av_cold
Definition attributes.h:117
static int sse16_altivec(MPVEncContext *v, const uint8_t *pix1, const uint8_t *pix2, ptrdiff_t stride, int h)
#define LOAD_PIX(v, iv, pix, per1, per2)
static int sad8_altivec(MPVEncContext *v, const uint8_t *pix1, const uint8_t *pix2, ptrdiff_t stride, int h)
#define ONEITERBUTTERFLY(i, res)
static int hadamard8_diff16_altivec(MPVEncContext *s, const uint8_t *dst, const uint8_t *src, ptrdiff_t stride, int h)
static int hadamard8_diff8x8_altivec(MPVEncContext *s, const uint8_t *dst, const uint8_t *src, ptrdiff_t stride, int h)
static int sad16_altivec(MPVEncContext *v, const uint8_t *pix1, const uint8_t *pix2, ptrdiff_t stride, int h)
static int sse8_altivec(MPVEncContext *v, const uint8_t *pix1, const uint8_t *pix2, ptrdiff_t stride, int h)
static int hadamard8_diff16x8_altivec(MPVEncContext *s, const uint8_t *dst, const uint8_t *src, ptrdiff_t stride, int h)
av_cold void ff_me_cmp_init_altivec(MECmpContext *c, AVCodecContext *avctx)
static int sad16_xy2_altivec(MPVEncContext *v, const uint8_t *pix1, const uint8_t *pix2, ptrdiff_t stride, int h)
static int sad16_y2_altivec(MPVEncContext *v, const uint8_t *pix1, const uint8_t *pix2, ptrdiff_t stride, int h)
static int sad16_x2_altivec(MPVEncContext *v, const uint8_t *pix1, const uint8_t *pix2, ptrdiff_t stride, int h)
#define GET_PERM(per1, per2, pix)
mpegvideo header.
main external API structure.
Definition avcodec.h:443
#define stride
#define vzero
Definition swscale_vsx.c:35
#define src
Definition vp8dsp.c:248
Contains misc utility macros and inline functions.
static double c[64]