00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "config.h"
00024 #if HAVE_ALTIVEC_H
00025 #include <altivec.h>
00026 #endif
00027 #include "libavcodec/dsputil.h"
00028 #include "util_altivec.h"
00029 #include "types_altivec.h"
00030 #include "dsputil_altivec.h"
00031
00032 static int sad16_x2_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
00033 {
00034 int i;
00035 int s;
00036 const vector unsigned char zero = (const vector unsigned char)vec_splat_u8(0);
00037 vector unsigned char perm1 = vec_lvsl(0, pix2);
00038 vector unsigned char perm2 = vec_add(perm1, vec_splat_u8(1));
00039 vector unsigned char pix2l, pix2r;
00040 vector unsigned char pix1v, pix2v, pix2iv, avgv, t5;
00041 vector unsigned int sad;
00042 vector signed int sumdiffs;
00043
00044 s = 0;
00045 sad = (vector unsigned int)vec_splat_u32(0);
00046 for (i = 0; i < h; i++) {
00047
00048
00049
00050 pix1v = vec_ld( 0, pix1);
00051 pix2l = vec_ld( 0, pix2);
00052 pix2r = vec_ld(16, pix2);
00053 pix2v = vec_perm(pix2l, pix2r, perm1);
00054 pix2iv = vec_perm(pix2l, pix2r, perm2);
00055
00056
00057 avgv = vec_avg(pix2v, pix2iv);
00058
00059
00060 t5 = vec_sub(vec_max(pix1v, avgv), vec_min(pix1v, avgv));
00061
00062
00063 sad = vec_sum4s(t5, sad);
00064
00065 pix1 += line_size;
00066 pix2 += line_size;
00067 }
00068
00069 sumdiffs = vec_sums((vector signed int) sad, (vector signed int) zero);
00070 sumdiffs = vec_splat(sumdiffs, 3);
00071 vec_ste(sumdiffs, 0, &s);
00072
00073 return s;
00074 }
00075
00076 static int sad16_y2_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
00077 {
00078 int i;
00079 int s;
00080 const vector unsigned char zero = (const vector unsigned char)vec_splat_u8(0);
00081 vector unsigned char perm = vec_lvsl(0, pix2);
00082 vector unsigned char pix2l, pix2r;
00083 vector unsigned char pix1v, pix2v, pix3v, avgv, t5;
00084 vector unsigned int sad;
00085 vector signed int sumdiffs;
00086 uint8_t *pix3 = pix2 + line_size;
00087
00088 s = 0;
00089 sad = (vector unsigned int)vec_splat_u32(0);
00090
00091
00092
00093
00094
00095
00096
00097
00098 pix2l = vec_ld( 0, pix2);
00099 pix2r = vec_ld(15, pix2);
00100 pix2v = vec_perm(pix2l, pix2r, perm);
00101
00102 for (i = 0; i < h; i++) {
00103
00104
00105
00106 pix1v = vec_ld(0, pix1);
00107
00108 pix2l = vec_ld( 0, pix3);
00109 pix2r = vec_ld(15, pix3);
00110 pix3v = vec_perm(pix2l, pix2r, perm);
00111
00112
00113 avgv = vec_avg(pix2v, pix3v);
00114
00115
00116 t5 = vec_sub(vec_max(pix1v, avgv), vec_min(pix1v, avgv));
00117
00118
00119 sad = vec_sum4s(t5, sad);
00120
00121 pix1 += line_size;
00122 pix2v = pix3v;
00123 pix3 += line_size;
00124
00125 }
00126
00127
00128 sumdiffs = vec_sums((vector signed int) sad, (vector signed int) zero);
00129 sumdiffs = vec_splat(sumdiffs, 3);
00130 vec_ste(sumdiffs, 0, &s);
00131 return s;
00132 }
00133
00134 static int sad16_xy2_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
00135 {
00136 int i;
00137 int s;
00138 uint8_t *pix3 = pix2 + line_size;
00139 const vector unsigned char zero = (const vector unsigned char)vec_splat_u8(0);
00140 const vector unsigned short two = (const vector unsigned short)vec_splat_u16(2);
00141 vector unsigned char avgv, t5;
00142 vector unsigned char perm1 = vec_lvsl(0, pix2);
00143 vector unsigned char perm2 = vec_add(perm1, vec_splat_u8(1));
00144 vector unsigned char pix2l, pix2r;
00145 vector unsigned char pix1v, pix2v, pix3v, pix2iv, pix3iv;
00146 vector unsigned short pix2lv, pix2hv, pix2ilv, pix2ihv;
00147 vector unsigned short pix3lv, pix3hv, pix3ilv, pix3ihv;
00148 vector unsigned short avghv, avglv;
00149 vector unsigned short t1, t2, t3, t4;
00150 vector unsigned int sad;
00151 vector signed int sumdiffs;
00152
00153 sad = (vector unsigned int)vec_splat_u32(0);
00154
00155 s = 0;
00156
00157
00158
00159
00160
00161
00162
00163
00164 pix2l = vec_ld( 0, pix2);
00165 pix2r = vec_ld(16, pix2);
00166 pix2v = vec_perm(pix2l, pix2r, perm1);
00167 pix2iv = vec_perm(pix2l, pix2r, perm2);
00168
00169 pix2hv = (vector unsigned short) vec_mergeh(zero, pix2v);
00170 pix2lv = (vector unsigned short) vec_mergel(zero, pix2v);
00171 pix2ihv = (vector unsigned short) vec_mergeh(zero, pix2iv);
00172 pix2ilv = (vector unsigned short) vec_mergel(zero, pix2iv);
00173 t1 = vec_add(pix2hv, pix2ihv);
00174 t2 = vec_add(pix2lv, pix2ilv);
00175
00176 for (i = 0; i < h; i++) {
00177
00178
00179
00180 pix1v = vec_ld(0, pix1);
00181
00182 pix2l = vec_ld( 0, pix3);
00183 pix2r = vec_ld(16, pix3);
00184 pix3v = vec_perm(pix2l, pix2r, perm1);
00185 pix3iv = vec_perm(pix2l, pix2r, perm2);
00186
00187
00188
00189
00190
00191
00192
00193
00194 pix3hv = (vector unsigned short) vec_mergeh(zero, pix3v);
00195 pix3lv = (vector unsigned short) vec_mergel(zero, pix3v);
00196 pix3ihv = (vector unsigned short) vec_mergeh(zero, pix3iv);
00197 pix3ilv = (vector unsigned short) vec_mergel(zero, pix3iv);
00198
00199
00200 t3 = vec_add(pix3hv, pix3ihv);
00201 t4 = vec_add(pix3lv, pix3ilv);
00202
00203 avghv = vec_sr(vec_add(vec_add(t1, t3), two), two);
00204 avglv = vec_sr(vec_add(vec_add(t2, t4), two), two);
00205
00206
00207 avgv = vec_pack(avghv, avglv);
00208
00209
00210 t5 = vec_sub(vec_max(pix1v, avgv), vec_min(pix1v, avgv));
00211
00212
00213 sad = vec_sum4s(t5, sad);
00214
00215 pix1 += line_size;
00216 pix3 += line_size;
00217
00218 t1 = t3;
00219 t2 = t4;
00220 }
00221
00222 sumdiffs = vec_sums((vector signed int) sad, (vector signed int) zero);
00223 sumdiffs = vec_splat(sumdiffs, 3);
00224 vec_ste(sumdiffs, 0, &s);
00225
00226 return s;
00227 }
00228
00229 static int sad16_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
00230 {
00231 int i;
00232 int s;
00233 const vector unsigned int zero = (const vector unsigned int)vec_splat_u32(0);
00234 vector unsigned char perm = vec_lvsl(0, pix2);
00235 vector unsigned char t1, t2, t3,t4, t5;
00236 vector unsigned int sad;
00237 vector signed int sumdiffs;
00238
00239 sad = (vector unsigned int)vec_splat_u32(0);
00240
00241
00242 for (i = 0; i < h; i++) {
00243
00244 vector unsigned char pix2l = vec_ld( 0, pix2);
00245 vector unsigned char pix2r = vec_ld(15, pix2);
00246 t1 = vec_ld(0, pix1);
00247 t2 = vec_perm(pix2l, pix2r, perm);
00248
00249
00250 t3 = vec_max(t1, t2);
00251 t4 = vec_min(t1, t2);
00252 t5 = vec_sub(t3, t4);
00253
00254
00255 sad = vec_sum4s(t5, sad);
00256
00257 pix1 += line_size;
00258 pix2 += line_size;
00259 }
00260
00261
00262 sumdiffs = vec_sums((vector signed int) sad, (vector signed int) zero);
00263 sumdiffs = vec_splat(sumdiffs, 3);
00264 vec_ste(sumdiffs, 0, &s);
00265
00266 return s;
00267 }
00268
00269 static int sad8_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
00270 {
00271 int i;
00272 int s;
00273 const vector unsigned int zero = (const vector unsigned int)vec_splat_u32(0);
00274 const vector unsigned char permclear = (vector unsigned char){255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0};
00275 vector unsigned char perm1 = vec_lvsl(0, pix1);
00276 vector unsigned char perm2 = vec_lvsl(0, pix2);
00277 vector unsigned char t1, t2, t3,t4, t5;
00278 vector unsigned int sad;
00279 vector signed int sumdiffs;
00280
00281 sad = (vector unsigned int)vec_splat_u32(0);
00282
00283 for (i = 0; i < h; i++) {
00284
00285
00286
00287 vector unsigned char pix1l = vec_ld( 0, pix1);
00288 vector unsigned char pix1r = vec_ld(15, pix1);
00289 vector unsigned char pix2l = vec_ld( 0, pix2);
00290 vector unsigned char pix2r = vec_ld(15, pix2);
00291 t1 = vec_and(vec_perm(pix1l, pix1r, perm1), permclear);
00292 t2 = vec_and(vec_perm(pix2l, pix2r, perm2), permclear);
00293
00294
00295 t3 = vec_max(t1, t2);
00296 t4 = vec_min(t1, t2);
00297 t5 = vec_sub(t3, t4);
00298
00299
00300 sad = vec_sum4s(t5, sad);
00301
00302 pix1 += line_size;
00303 pix2 += line_size;
00304 }
00305
00306
00307 sumdiffs = vec_sums((vector signed int) sad, (vector signed int) zero);
00308 sumdiffs = vec_splat(sumdiffs, 3);
00309 vec_ste(sumdiffs, 0, &s);
00310
00311 return s;
00312 }
00313
00314 static int pix_norm1_altivec(uint8_t *pix, int line_size)
00315 {
00316 int i;
00317 int s;
00318 const vector unsigned int zero = (const vector unsigned int)vec_splat_u32(0);
00319 vector unsigned char perm = vec_lvsl(0, pix);
00320 vector unsigned char pixv;
00321 vector unsigned int sv;
00322 vector signed int sum;
00323
00324 sv = (vector unsigned int)vec_splat_u32(0);
00325
00326 s = 0;
00327 for (i = 0; i < 16; i++) {
00328
00329 vector unsigned char pixl = vec_ld( 0, pix);
00330 vector unsigned char pixr = vec_ld(15, pix);
00331 pixv = vec_perm(pixl, pixr, perm);
00332
00333
00334 sv = vec_msum(pixv, pixv, sv);
00335
00336 pix += line_size;
00337 }
00338
00339 sum = vec_sums((vector signed int) sv, (vector signed int) zero);
00340 sum = vec_splat(sum, 3);
00341 vec_ste(sum, 0, &s);
00342
00343 return s;
00344 }
00345
00351 static int sse8_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
00352 {
00353 int i;
00354 int s;
00355 const vector unsigned int zero = (const vector unsigned int)vec_splat_u32(0);
00356 const vector unsigned char permclear = (vector unsigned char){255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0};
00357 vector unsigned char perm1 = vec_lvsl(0, pix1);
00358 vector unsigned char perm2 = vec_lvsl(0, pix2);
00359 vector unsigned char t1, t2, t3,t4, t5;
00360 vector unsigned int sum;
00361 vector signed int sumsqr;
00362
00363 sum = (vector unsigned int)vec_splat_u32(0);
00364
00365 for (i = 0; i < h; i++) {
00366
00367
00368
00369 vector unsigned char pix1l = vec_ld( 0, pix1);
00370 vector unsigned char pix1r = vec_ld(15, pix1);
00371 vector unsigned char pix2l = vec_ld( 0, pix2);
00372 vector unsigned char pix2r = vec_ld(15, pix2);
00373 t1 = vec_and(vec_perm(pix1l, pix1r, perm1), permclear);
00374 t2 = vec_and(vec_perm(pix2l, pix2r, perm2), permclear);
00375
00376
00377
00378
00379
00380 t3 = vec_max(t1, t2);
00381 t4 = vec_min(t1, t2);
00382 t5 = vec_sub(t3, t4);
00383
00384
00385 sum = vec_msum(t5, t5, sum);
00386
00387 pix1 += line_size;
00388 pix2 += line_size;
00389 }
00390
00391
00392 sumsqr = vec_sums((vector signed int) sum, (vector signed int) zero);
00393 sumsqr = vec_splat(sumsqr, 3);
00394 vec_ste(sumsqr, 0, &s);
00395
00396 return s;
00397 }
00398
00404 static int sse16_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
00405 {
00406 int i;
00407 int s;
00408 const vector unsigned int zero = (const vector unsigned int)vec_splat_u32(0);
00409 vector unsigned char perm = vec_lvsl(0, pix2);
00410 vector unsigned char t1, t2, t3,t4, t5;
00411 vector unsigned int sum;
00412 vector signed int sumsqr;
00413
00414 sum = (vector unsigned int)vec_splat_u32(0);
00415
00416 for (i = 0; i < h; i++) {
00417
00418 vector unsigned char pix2l = vec_ld( 0, pix2);
00419 vector unsigned char pix2r = vec_ld(15, pix2);
00420 t1 = vec_ld(0, pix1);
00421 t2 = vec_perm(pix2l, pix2r, perm);
00422
00423
00424
00425
00426
00427 t3 = vec_max(t1, t2);
00428 t4 = vec_min(t1, t2);
00429 t5 = vec_sub(t3, t4);
00430
00431
00432 sum = vec_msum(t5, t5, sum);
00433
00434 pix1 += line_size;
00435 pix2 += line_size;
00436 }
00437
00438
00439 sumsqr = vec_sums((vector signed int) sum, (vector signed int) zero);
00440 sumsqr = vec_splat(sumsqr, 3);
00441 vec_ste(sumsqr, 0, &s);
00442
00443 return s;
00444 }
00445
00446 static int pix_sum_altivec(uint8_t * pix, int line_size)
00447 {
00448 const vector unsigned int zero = (const vector unsigned int)vec_splat_u32(0);
00449 vector unsigned char perm = vec_lvsl(0, pix);
00450 vector unsigned char t1;
00451 vector unsigned int sad;
00452 vector signed int sumdiffs;
00453
00454 int i;
00455 int s;
00456
00457 sad = (vector unsigned int)vec_splat_u32(0);
00458
00459 for (i = 0; i < 16; i++) {
00460
00461 vector unsigned char pixl = vec_ld( 0, pix);
00462 vector unsigned char pixr = vec_ld(15, pix);
00463 t1 = vec_perm(pixl, pixr, perm);
00464
00465
00466 sad = vec_sum4s(t1, sad);
00467
00468 pix += line_size;
00469 }
00470
00471
00472 sumdiffs = vec_sums((vector signed int) sad, (vector signed int) zero);
00473 sumdiffs = vec_splat(sumdiffs, 3);
00474 vec_ste(sumdiffs, 0, &s);
00475
00476 return s;
00477 }
00478
00479 static void get_pixels_altivec(DCTELEM *restrict block, const uint8_t *pixels, int line_size)
00480 {
00481 int i;
00482 vector unsigned char perm = vec_lvsl(0, pixels);
00483 vector unsigned char bytes;
00484 const vector unsigned char zero = (const vector unsigned char)vec_splat_u8(0);
00485 vector signed short shorts;
00486
00487 for (i = 0; i < 8; i++) {
00488
00489
00490
00491 vector unsigned char pixl = vec_ld( 0, pixels);
00492 vector unsigned char pixr = vec_ld(15, pixels);
00493 bytes = vec_perm(pixl, pixr, perm);
00494
00495
00496 shorts = (vector signed short)vec_mergeh(zero, bytes);
00497
00498
00499 vec_st(shorts, i*16, (vector signed short*)block);
00500
00501 pixels += line_size;
00502 }
00503 }
00504
00505 static void diff_pixels_altivec(DCTELEM *restrict block, const uint8_t *s1,
00506 const uint8_t *s2, int stride)
00507 {
00508 int i;
00509 vector unsigned char perm1 = vec_lvsl(0, s1);
00510 vector unsigned char perm2 = vec_lvsl(0, s2);
00511 vector unsigned char bytes, pixl, pixr;
00512 const vector unsigned char zero = (const vector unsigned char)vec_splat_u8(0);
00513 vector signed short shorts1, shorts2;
00514
00515 for (i = 0; i < 4; i++) {
00516
00517
00518
00519 pixl = vec_ld( 0, s1);
00520 pixr = vec_ld(15, s1);
00521 bytes = vec_perm(pixl, pixr, perm1);
00522
00523
00524 shorts1 = (vector signed short)vec_mergeh(zero, bytes);
00525
00526
00527 pixl = vec_ld( 0, s2);
00528 pixr = vec_ld(15, s2);
00529 bytes = vec_perm(pixl, pixr, perm2);
00530
00531
00532 shorts2 = (vector signed short)vec_mergeh(zero, bytes);
00533
00534
00535 shorts1 = vec_sub(shorts1, shorts2);
00536
00537
00538 vec_st(shorts1, 0, (vector signed short*)block);
00539
00540 s1 += stride;
00541 s2 += stride;
00542 block += 8;
00543
00544
00545
00546
00547
00548
00549
00550
00551 pixl = vec_ld( 0, s1);
00552 pixr = vec_ld(15, s1);
00553 bytes = vec_perm(pixl, pixr, perm1);
00554
00555
00556 shorts1 = (vector signed short)vec_mergeh(zero, bytes);
00557
00558
00559 pixl = vec_ld( 0, s2);
00560 pixr = vec_ld(15, s2);
00561 bytes = vec_perm(pixl, pixr, perm2);
00562
00563
00564 shorts2 = (vector signed short)vec_mergeh(zero, bytes);
00565
00566
00567 shorts1 = vec_sub(shorts1, shorts2);
00568
00569
00570 vec_st(shorts1, 0, (vector signed short*)block);
00571
00572 s1 += stride;
00573 s2 += stride;
00574 block += 8;
00575 }
00576 }
00577
00578
00579 static void clear_block_altivec(DCTELEM *block) {
00580 LOAD_ZERO;
00581 vec_st(zero_s16v, 0, block);
00582 vec_st(zero_s16v, 16, block);
00583 vec_st(zero_s16v, 32, block);
00584 vec_st(zero_s16v, 48, block);
00585 vec_st(zero_s16v, 64, block);
00586 vec_st(zero_s16v, 80, block);
00587 vec_st(zero_s16v, 96, block);
00588 vec_st(zero_s16v, 112, block);
00589 }
00590
00591
00592 static void add_bytes_altivec(uint8_t *dst, uint8_t *src, int w) {
00593 register int i;
00594 register vector unsigned char vdst, vsrc;
00595
00596
00597 for (i = 0 ; (i + 15) < w ; i+=16) {
00598 vdst = vec_ld(i, (unsigned char*)dst);
00599 vsrc = vec_ld(i, (unsigned char*)src);
00600 vdst = vec_add(vsrc, vdst);
00601 vec_st(vdst, i, (unsigned char*)dst);
00602 }
00603
00604 for (; (i < w) ; i++) {
00605 dst[i] = src[i];
00606 }
00607 }
00608
00609
00610 void ff_put_pixels16_altivec(uint8_t *block, const uint8_t *pixels, int line_size, int h)
00611 {
00612 register vector unsigned char pixelsv1, pixelsv2;
00613 register vector unsigned char pixelsv1B, pixelsv2B;
00614 register vector unsigned char pixelsv1C, pixelsv2C;
00615 register vector unsigned char pixelsv1D, pixelsv2D;
00616
00617 register vector unsigned char perm = vec_lvsl(0, pixels);
00618 int i;
00619 register int line_size_2 = line_size << 1;
00620 register int line_size_3 = line_size + line_size_2;
00621 register int line_size_4 = line_size << 2;
00622
00623
00624
00625
00626
00627
00628 for (i = 0; i < h; i += 4) {
00629 pixelsv1 = vec_ld( 0, pixels);
00630 pixelsv2 = vec_ld(15, pixels);
00631 pixelsv1B = vec_ld(line_size, pixels);
00632 pixelsv2B = vec_ld(15 + line_size, pixels);
00633 pixelsv1C = vec_ld(line_size_2, pixels);
00634 pixelsv2C = vec_ld(15 + line_size_2, pixels);
00635 pixelsv1D = vec_ld(line_size_3, pixels);
00636 pixelsv2D = vec_ld(15 + line_size_3, pixels);
00637 vec_st(vec_perm(pixelsv1, pixelsv2, perm),
00638 0, (unsigned char*)block);
00639 vec_st(vec_perm(pixelsv1B, pixelsv2B, perm),
00640 line_size, (unsigned char*)block);
00641 vec_st(vec_perm(pixelsv1C, pixelsv2C, perm),
00642 line_size_2, (unsigned char*)block);
00643 vec_st(vec_perm(pixelsv1D, pixelsv2D, perm),
00644 line_size_3, (unsigned char*)block);
00645 pixels+=line_size_4;
00646 block +=line_size_4;
00647 }
00648 }
00649
00650
00651 #define op_avg(a,b) a = ( ((a)|(b)) - ((((a)^(b))&0xFEFEFEFEUL)>>1) )
00652 void ff_avg_pixels16_altivec(uint8_t *block, const uint8_t *pixels, int line_size, int h)
00653 {
00654 register vector unsigned char pixelsv1, pixelsv2, pixelsv, blockv;
00655 register vector unsigned char perm = vec_lvsl(0, pixels);
00656 int i;
00657
00658 for (i = 0; i < h; i++) {
00659 pixelsv1 = vec_ld( 0, pixels);
00660 pixelsv2 = vec_ld(16,pixels);
00661 blockv = vec_ld(0, block);
00662 pixelsv = vec_perm(pixelsv1, pixelsv2, perm);
00663 blockv = vec_avg(blockv,pixelsv);
00664 vec_st(blockv, 0, (unsigned char*)block);
00665 pixels+=line_size;
00666 block +=line_size;
00667 }
00668 }
00669
00670
00671 static void avg_pixels8_altivec(uint8_t * block, const uint8_t * pixels, int line_size, int h)
00672 {
00673 register vector unsigned char pixelsv1, pixelsv2, pixelsv, blockv;
00674 int i;
00675
00676 for (i = 0; i < h; i++) {
00677
00678
00679 int rightside = ((unsigned long)block & 0x0000000F);
00680
00681 blockv = vec_ld(0, block);
00682 pixelsv1 = vec_ld( 0, pixels);
00683 pixelsv2 = vec_ld(16, pixels);
00684 pixelsv = vec_perm(pixelsv1, pixelsv2, vec_lvsl(0, pixels));
00685
00686 if (rightside) {
00687 pixelsv = vec_perm(blockv, pixelsv, vcprm(0,1,s0,s1));
00688 } else {
00689 pixelsv = vec_perm(blockv, pixelsv, vcprm(s0,s1,2,3));
00690 }
00691
00692 blockv = vec_avg(blockv, pixelsv);
00693
00694 vec_st(blockv, 0, block);
00695
00696 pixels += line_size;
00697 block += line_size;
00698 }
00699 }
00700
00701
00702 static void put_pixels8_xy2_altivec(uint8_t *block, const uint8_t *pixels, int line_size, int h)
00703 {
00704 register int i;
00705 register vector unsigned char pixelsv1, pixelsv2, pixelsavg;
00706 register vector unsigned char blockv, temp1, temp2;
00707 register vector unsigned short pixelssum1, pixelssum2, temp3;
00708 register const vector unsigned char vczero = (const vector unsigned char)vec_splat_u8(0);
00709 register const vector unsigned short vctwo = (const vector unsigned short)vec_splat_u16(2);
00710
00711 temp1 = vec_ld(0, pixels);
00712 temp2 = vec_ld(16, pixels);
00713 pixelsv1 = vec_perm(temp1, temp2, vec_lvsl(0, pixels));
00714 if ((((unsigned long)pixels) & 0x0000000F) == 0x0000000F) {
00715 pixelsv2 = temp2;
00716 } else {
00717 pixelsv2 = vec_perm(temp1, temp2, vec_lvsl(1, pixels));
00718 }
00719 pixelsv1 = vec_mergeh(vczero, pixelsv1);
00720 pixelsv2 = vec_mergeh(vczero, pixelsv2);
00721 pixelssum1 = vec_add((vector unsigned short)pixelsv1,
00722 (vector unsigned short)pixelsv2);
00723 pixelssum1 = vec_add(pixelssum1, vctwo);
00724
00725 for (i = 0; i < h ; i++) {
00726 int rightside = ((unsigned long)block & 0x0000000F);
00727 blockv = vec_ld(0, block);
00728
00729 temp1 = vec_ld(line_size, pixels);
00730 temp2 = vec_ld(line_size + 16, pixels);
00731 pixelsv1 = vec_perm(temp1, temp2, vec_lvsl(line_size, pixels));
00732 if (((((unsigned long)pixels) + line_size) & 0x0000000F) == 0x0000000F) {
00733 pixelsv2 = temp2;
00734 } else {
00735 pixelsv2 = vec_perm(temp1, temp2, vec_lvsl(line_size + 1, pixels));
00736 }
00737
00738 pixelsv1 = vec_mergeh(vczero, pixelsv1);
00739 pixelsv2 = vec_mergeh(vczero, pixelsv2);
00740 pixelssum2 = vec_add((vector unsigned short)pixelsv1,
00741 (vector unsigned short)pixelsv2);
00742 temp3 = vec_add(pixelssum1, pixelssum2);
00743 temp3 = vec_sra(temp3, vctwo);
00744 pixelssum1 = vec_add(pixelssum2, vctwo);
00745 pixelsavg = vec_packsu(temp3, (vector unsigned short) vczero);
00746
00747 if (rightside) {
00748 blockv = vec_perm(blockv, pixelsavg, vcprm(0, 1, s0, s1));
00749 } else {
00750 blockv = vec_perm(blockv, pixelsavg, vcprm(s0, s1, 2, 3));
00751 }
00752
00753 vec_st(blockv, 0, block);
00754
00755 block += line_size;
00756 pixels += line_size;
00757 }
00758 }
00759
00760
00761 static void put_no_rnd_pixels8_xy2_altivec(uint8_t *block, const uint8_t *pixels, int line_size, int h)
00762 {
00763 register int i;
00764 register vector unsigned char pixelsv1, pixelsv2, pixelsavg;
00765 register vector unsigned char blockv, temp1, temp2;
00766 register vector unsigned short pixelssum1, pixelssum2, temp3;
00767 register const vector unsigned char vczero = (const vector unsigned char)vec_splat_u8(0);
00768 register const vector unsigned short vcone = (const vector unsigned short)vec_splat_u16(1);
00769 register const vector unsigned short vctwo = (const vector unsigned short)vec_splat_u16(2);
00770
00771 temp1 = vec_ld(0, pixels);
00772 temp2 = vec_ld(16, pixels);
00773 pixelsv1 = vec_perm(temp1, temp2, vec_lvsl(0, pixels));
00774 if ((((unsigned long)pixels) & 0x0000000F) == 0x0000000F) {
00775 pixelsv2 = temp2;
00776 } else {
00777 pixelsv2 = vec_perm(temp1, temp2, vec_lvsl(1, pixels));
00778 }
00779 pixelsv1 = vec_mergeh(vczero, pixelsv1);
00780 pixelsv2 = vec_mergeh(vczero, pixelsv2);
00781 pixelssum1 = vec_add((vector unsigned short)pixelsv1,
00782 (vector unsigned short)pixelsv2);
00783 pixelssum1 = vec_add(pixelssum1, vcone);
00784
00785 for (i = 0; i < h ; i++) {
00786 int rightside = ((unsigned long)block & 0x0000000F);
00787 blockv = vec_ld(0, block);
00788
00789 temp1 = vec_ld(line_size, pixels);
00790 temp2 = vec_ld(line_size + 16, pixels);
00791 pixelsv1 = vec_perm(temp1, temp2, vec_lvsl(line_size, pixels));
00792 if (((((unsigned long)pixels) + line_size) & 0x0000000F) == 0x0000000F) {
00793 pixelsv2 = temp2;
00794 } else {
00795 pixelsv2 = vec_perm(temp1, temp2, vec_lvsl(line_size + 1, pixels));
00796 }
00797
00798 pixelsv1 = vec_mergeh(vczero, pixelsv1);
00799 pixelsv2 = vec_mergeh(vczero, pixelsv2);
00800 pixelssum2 = vec_add((vector unsigned short)pixelsv1,
00801 (vector unsigned short)pixelsv2);
00802 temp3 = vec_add(pixelssum1, pixelssum2);
00803 temp3 = vec_sra(temp3, vctwo);
00804 pixelssum1 = vec_add(pixelssum2, vcone);
00805 pixelsavg = vec_packsu(temp3, (vector unsigned short) vczero);
00806
00807 if (rightside) {
00808 blockv = vec_perm(blockv, pixelsavg, vcprm(0, 1, s0, s1));
00809 } else {
00810 blockv = vec_perm(blockv, pixelsavg, vcprm(s0, s1, 2, 3));
00811 }
00812
00813 vec_st(blockv, 0, block);
00814
00815 block += line_size;
00816 pixels += line_size;
00817 }
00818 }
00819
00820
00821 static void put_pixels16_xy2_altivec(uint8_t * block, const uint8_t * pixels, int line_size, int h)
00822 {
00823 register int i;
00824 register vector unsigned char pixelsv1, pixelsv2, pixelsv3, pixelsv4;
00825 register vector unsigned char blockv, temp1, temp2;
00826 register vector unsigned short temp3, temp4,
00827 pixelssum1, pixelssum2, pixelssum3, pixelssum4;
00828 register const vector unsigned char vczero = (const vector unsigned char)vec_splat_u8(0);
00829 register const vector unsigned short vctwo = (const vector unsigned short)vec_splat_u16(2);
00830
00831 temp1 = vec_ld(0, pixels);
00832 temp2 = vec_ld(16, pixels);
00833 pixelsv1 = vec_perm(temp1, temp2, vec_lvsl(0, pixels));
00834 if ((((unsigned long)pixels) & 0x0000000F) == 0x0000000F) {
00835 pixelsv2 = temp2;
00836 } else {
00837 pixelsv2 = vec_perm(temp1, temp2, vec_lvsl(1, pixels));
00838 }
00839 pixelsv3 = vec_mergel(vczero, pixelsv1);
00840 pixelsv4 = vec_mergel(vczero, pixelsv2);
00841 pixelsv1 = vec_mergeh(vczero, pixelsv1);
00842 pixelsv2 = vec_mergeh(vczero, pixelsv2);
00843 pixelssum3 = vec_add((vector unsigned short)pixelsv3,
00844 (vector unsigned short)pixelsv4);
00845 pixelssum3 = vec_add(pixelssum3, vctwo);
00846 pixelssum1 = vec_add((vector unsigned short)pixelsv1,
00847 (vector unsigned short)pixelsv2);
00848 pixelssum1 = vec_add(pixelssum1, vctwo);
00849
00850 for (i = 0; i < h ; i++) {
00851 blockv = vec_ld(0, block);
00852
00853 temp1 = vec_ld(line_size, pixels);
00854 temp2 = vec_ld(line_size + 16, pixels);
00855 pixelsv1 = vec_perm(temp1, temp2, vec_lvsl(line_size, pixels));
00856 if (((((unsigned long)pixels) + line_size) & 0x0000000F) == 0x0000000F) {
00857 pixelsv2 = temp2;
00858 } else {
00859 pixelsv2 = vec_perm(temp1, temp2, vec_lvsl(line_size + 1, pixels));
00860 }
00861
00862 pixelsv3 = vec_mergel(vczero, pixelsv1);
00863 pixelsv4 = vec_mergel(vczero, pixelsv2);
00864 pixelsv1 = vec_mergeh(vczero, pixelsv1);
00865 pixelsv2 = vec_mergeh(vczero, pixelsv2);
00866
00867 pixelssum4 = vec_add((vector unsigned short)pixelsv3,
00868 (vector unsigned short)pixelsv4);
00869 pixelssum2 = vec_add((vector unsigned short)pixelsv1,
00870 (vector unsigned short)pixelsv2);
00871 temp4 = vec_add(pixelssum3, pixelssum4);
00872 temp4 = vec_sra(temp4, vctwo);
00873 temp3 = vec_add(pixelssum1, pixelssum2);
00874 temp3 = vec_sra(temp3, vctwo);
00875
00876 pixelssum3 = vec_add(pixelssum4, vctwo);
00877 pixelssum1 = vec_add(pixelssum2, vctwo);
00878
00879 blockv = vec_packsu(temp3, temp4);
00880
00881 vec_st(blockv, 0, block);
00882
00883 block += line_size;
00884 pixels += line_size;
00885 }
00886 }
00887
00888
00889 static void put_no_rnd_pixels16_xy2_altivec(uint8_t * block, const uint8_t * pixels, int line_size, int h)
00890 {
00891 register int i;
00892 register vector unsigned char pixelsv1, pixelsv2, pixelsv3, pixelsv4;
00893 register vector unsigned char blockv, temp1, temp2;
00894 register vector unsigned short temp3, temp4,
00895 pixelssum1, pixelssum2, pixelssum3, pixelssum4;
00896 register const vector unsigned char vczero = (const vector unsigned char)vec_splat_u8(0);
00897 register const vector unsigned short vcone = (const vector unsigned short)vec_splat_u16(1);
00898 register const vector unsigned short vctwo = (const vector unsigned short)vec_splat_u16(2);
00899
00900 temp1 = vec_ld(0, pixels);
00901 temp2 = vec_ld(16, pixels);
00902 pixelsv1 = vec_perm(temp1, temp2, vec_lvsl(0, pixels));
00903 if ((((unsigned long)pixels) & 0x0000000F) == 0x0000000F) {
00904 pixelsv2 = temp2;
00905 } else {
00906 pixelsv2 = vec_perm(temp1, temp2, vec_lvsl(1, pixels));
00907 }
00908 pixelsv3 = vec_mergel(vczero, pixelsv1);
00909 pixelsv4 = vec_mergel(vczero, pixelsv2);
00910 pixelsv1 = vec_mergeh(vczero, pixelsv1);
00911 pixelsv2 = vec_mergeh(vczero, pixelsv2);
00912 pixelssum3 = vec_add((vector unsigned short)pixelsv3,
00913 (vector unsigned short)pixelsv4);
00914 pixelssum3 = vec_add(pixelssum3, vcone);
00915 pixelssum1 = vec_add((vector unsigned short)pixelsv1,
00916 (vector unsigned short)pixelsv2);
00917 pixelssum1 = vec_add(pixelssum1, vcone);
00918
00919 for (i = 0; i < h ; i++) {
00920 blockv = vec_ld(0, block);
00921
00922 temp1 = vec_ld(line_size, pixels);
00923 temp2 = vec_ld(line_size + 16, pixels);
00924 pixelsv1 = vec_perm(temp1, temp2, vec_lvsl(line_size, pixels));
00925 if (((((unsigned long)pixels) + line_size) & 0x0000000F) == 0x0000000F) {
00926 pixelsv2 = temp2;
00927 } else {
00928 pixelsv2 = vec_perm(temp1, temp2, vec_lvsl(line_size + 1, pixels));
00929 }
00930
00931 pixelsv3 = vec_mergel(vczero, pixelsv1);
00932 pixelsv4 = vec_mergel(vczero, pixelsv2);
00933 pixelsv1 = vec_mergeh(vczero, pixelsv1);
00934 pixelsv2 = vec_mergeh(vczero, pixelsv2);
00935
00936 pixelssum4 = vec_add((vector unsigned short)pixelsv3,
00937 (vector unsigned short)pixelsv4);
00938 pixelssum2 = vec_add((vector unsigned short)pixelsv1,
00939 (vector unsigned short)pixelsv2);
00940 temp4 = vec_add(pixelssum3, pixelssum4);
00941 temp4 = vec_sra(temp4, vctwo);
00942 temp3 = vec_add(pixelssum1, pixelssum2);
00943 temp3 = vec_sra(temp3, vctwo);
00944
00945 pixelssum3 = vec_add(pixelssum4, vcone);
00946 pixelssum1 = vec_add(pixelssum2, vcone);
00947
00948 blockv = vec_packsu(temp3, temp4);
00949
00950 vec_st(blockv, 0, block);
00951
00952 block += line_size;
00953 pixels += line_size;
00954 }
00955 }
00956
00957 static int hadamard8_diff8x8_altivec( void *s, uint8_t *dst, uint8_t *src, int stride, int h){
00958 int sum;
00959 register const vector unsigned char vzero =
00960 (const vector unsigned char)vec_splat_u8(0);
00961 register vector signed short temp0, temp1, temp2, temp3, temp4,
00962 temp5, temp6, temp7;
00963 {
00964 register const vector signed short vprod1 =(const vector signed short)
00965 { 1,-1, 1,-1, 1,-1, 1,-1 };
00966 register const vector signed short vprod2 =(const vector signed short)
00967 { 1, 1,-1,-1, 1, 1,-1,-1 };
00968 register const vector signed short vprod3 =(const vector signed short)
00969 { 1, 1, 1, 1,-1,-1,-1,-1 };
00970 register const vector unsigned char perm1 = (const vector unsigned char)
00971 {0x02, 0x03, 0x00, 0x01, 0x06, 0x07, 0x04, 0x05,
00972 0x0A, 0x0B, 0x08, 0x09, 0x0E, 0x0F, 0x0C, 0x0D};
00973 register const vector unsigned char perm2 = (const vector unsigned char)
00974 {0x04, 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03,
00975 0x0C, 0x0D, 0x0E, 0x0F, 0x08, 0x09, 0x0A, 0x0B};
00976 register const vector unsigned char perm3 = (const vector unsigned char)
00977 {0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
00978 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
00979
00980 #define ONEITERBUTTERFLY(i, res) \
00981 { \
00982 register vector unsigned char src1, src2, srcO; \
00983 register vector unsigned char dst1, dst2, dstO; \
00984 register vector signed short srcV, dstV; \
00985 register vector signed short but0, but1, but2, op1, op2, op3; \
00986 src1 = vec_ld(stride * i, src); \
00987 src2 = vec_ld((stride * i) + 15, src); \
00988 srcO = vec_perm(src1, src2, vec_lvsl(stride * i, src)); \
00989 dst1 = vec_ld(stride * i, dst); \
00990 dst2 = vec_ld((stride * i) + 15, dst); \
00991 dstO = vec_perm(dst1, dst2, vec_lvsl(stride * i, dst)); \
00992 \
00993 \
00994 srcV = (vector signed short)vec_mergeh((vector signed char)vzero, \
00995 (vector signed char)srcO); \
00996 dstV = (vector signed short)vec_mergeh((vector signed char)vzero, \
00997 (vector signed char)dstO); \
00998 \
00999 but0 = vec_sub(srcV, dstV); \
01000 op1 = vec_perm(but0, but0, perm1); \
01001 but1 = vec_mladd(but0, vprod1, op1); \
01002 op2 = vec_perm(but1, but1, perm2); \
01003 but2 = vec_mladd(but1, vprod2, op2); \
01004 op3 = vec_perm(but2, but2, perm3); \
01005 res = vec_mladd(but2, vprod3, op3); \
01006 }
01007 ONEITERBUTTERFLY(0, temp0);
01008 ONEITERBUTTERFLY(1, temp1);
01009 ONEITERBUTTERFLY(2, temp2);
01010 ONEITERBUTTERFLY(3, temp3);
01011 ONEITERBUTTERFLY(4, temp4);
01012 ONEITERBUTTERFLY(5, temp5);
01013 ONEITERBUTTERFLY(6, temp6);
01014 ONEITERBUTTERFLY(7, temp7);
01015 }
01016 #undef ONEITERBUTTERFLY
01017 {
01018 register vector signed int vsum;
01019 register vector signed short line0 = vec_add(temp0, temp1);
01020 register vector signed short line1 = vec_sub(temp0, temp1);
01021 register vector signed short line2 = vec_add(temp2, temp3);
01022 register vector signed short line3 = vec_sub(temp2, temp3);
01023 register vector signed short line4 = vec_add(temp4, temp5);
01024 register vector signed short line5 = vec_sub(temp4, temp5);
01025 register vector signed short line6 = vec_add(temp6, temp7);
01026 register vector signed short line7 = vec_sub(temp6, temp7);
01027
01028 register vector signed short line0B = vec_add(line0, line2);
01029 register vector signed short line2B = vec_sub(line0, line2);
01030 register vector signed short line1B = vec_add(line1, line3);
01031 register vector signed short line3B = vec_sub(line1, line3);
01032 register vector signed short line4B = vec_add(line4, line6);
01033 register vector signed short line6B = vec_sub(line4, line6);
01034 register vector signed short line5B = vec_add(line5, line7);
01035 register vector signed short line7B = vec_sub(line5, line7);
01036
01037 register vector signed short line0C = vec_add(line0B, line4B);
01038 register vector signed short line4C = vec_sub(line0B, line4B);
01039 register vector signed short line1C = vec_add(line1B, line5B);
01040 register vector signed short line5C = vec_sub(line1B, line5B);
01041 register vector signed short line2C = vec_add(line2B, line6B);
01042 register vector signed short line6C = vec_sub(line2B, line6B);
01043 register vector signed short line3C = vec_add(line3B, line7B);
01044 register vector signed short line7C = vec_sub(line3B, line7B);
01045
01046 vsum = vec_sum4s(vec_abs(line0C), vec_splat_s32(0));
01047 vsum = vec_sum4s(vec_abs(line1C), vsum);
01048 vsum = vec_sum4s(vec_abs(line2C), vsum);
01049 vsum = vec_sum4s(vec_abs(line3C), vsum);
01050 vsum = vec_sum4s(vec_abs(line4C), vsum);
01051 vsum = vec_sum4s(vec_abs(line5C), vsum);
01052 vsum = vec_sum4s(vec_abs(line6C), vsum);
01053 vsum = vec_sum4s(vec_abs(line7C), vsum);
01054 vsum = vec_sums(vsum, (vector signed int)vzero);
01055 vsum = vec_splat(vsum, 3);
01056 vec_ste(vsum, 0, &sum);
01057 }
01058 return sum;
01059 }
01060
01061
01062
01063
01064
01065
01066
01067
01068
01069
01070
01071
01072
01073
01074
01075
01076
01077
01078
01079
01080 static int hadamard8_diff16x8_altivec( void *s, uint8_t *dst, uint8_t *src, int stride, int h) {
01081 int sum;
01082 register vector signed short
01083 temp0 __asm__ ("v0"),
01084 temp1 __asm__ ("v1"),
01085 temp2 __asm__ ("v2"),
01086 temp3 __asm__ ("v3"),
01087 temp4 __asm__ ("v4"),
01088 temp5 __asm__ ("v5"),
01089 temp6 __asm__ ("v6"),
01090 temp7 __asm__ ("v7");
01091 register vector signed short
01092 temp0S __asm__ ("v8"),
01093 temp1S __asm__ ("v9"),
01094 temp2S __asm__ ("v10"),
01095 temp3S __asm__ ("v11"),
01096 temp4S __asm__ ("v12"),
01097 temp5S __asm__ ("v13"),
01098 temp6S __asm__ ("v14"),
01099 temp7S __asm__ ("v15");
01100 register const vector unsigned char vzero __asm__ ("v31") =
01101 (const vector unsigned char)vec_splat_u8(0);
01102 {
01103 register const vector signed short vprod1 __asm__ ("v16") =
01104 (const vector signed short){ 1,-1, 1,-1, 1,-1, 1,-1 };
01105 register const vector signed short vprod2 __asm__ ("v17") =
01106 (const vector signed short){ 1, 1,-1,-1, 1, 1,-1,-1 };
01107 register const vector signed short vprod3 __asm__ ("v18") =
01108 (const vector signed short){ 1, 1, 1, 1,-1,-1,-1,-1 };
01109 register const vector unsigned char perm1 __asm__ ("v19") =
01110 (const vector unsigned char)
01111 {0x02, 0x03, 0x00, 0x01, 0x06, 0x07, 0x04, 0x05,
01112 0x0A, 0x0B, 0x08, 0x09, 0x0E, 0x0F, 0x0C, 0x0D};
01113 register const vector unsigned char perm2 __asm__ ("v20") =
01114 (const vector unsigned char)
01115 {0x04, 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03,
01116 0x0C, 0x0D, 0x0E, 0x0F, 0x08, 0x09, 0x0A, 0x0B};
01117 register const vector unsigned char perm3 __asm__ ("v21") =
01118 (const vector unsigned char)
01119 {0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
01120 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
01121
01122 #define ONEITERBUTTERFLY(i, res1, res2) \
01123 { \
01124 register vector unsigned char src1 __asm__ ("v22"), \
01125 src2 __asm__ ("v23"), \
01126 dst1 __asm__ ("v24"), \
01127 dst2 __asm__ ("v25"), \
01128 srcO __asm__ ("v22"), \
01129 dstO __asm__ ("v23"); \
01130 \
01131 register vector signed short srcV __asm__ ("v24"), \
01132 dstV __asm__ ("v25"), \
01133 srcW __asm__ ("v26"), \
01134 dstW __asm__ ("v27"), \
01135 but0 __asm__ ("v28"), \
01136 but0S __asm__ ("v29"), \
01137 op1 __asm__ ("v30"), \
01138 but1 __asm__ ("v22"), \
01139 op1S __asm__ ("v23"), \
01140 but1S __asm__ ("v24"), \
01141 op2 __asm__ ("v25"), \
01142 but2 __asm__ ("v26"), \
01143 op2S __asm__ ("v27"), \
01144 but2S __asm__ ("v28"), \
01145 op3 __asm__ ("v29"), \
01146 op3S __asm__ ("v30"); \
01147 \
01148 src1 = vec_ld(stride * i, src); \
01149 src2 = vec_ld((stride * i) + 16, src); \
01150 srcO = vec_perm(src1, src2, vec_lvsl(stride * i, src)); \
01151 dst1 = vec_ld(stride * i, dst); \
01152 dst2 = vec_ld((stride * i) + 16, dst); \
01153 dstO = vec_perm(dst1, dst2, vec_lvsl(stride * i, dst)); \
01154 \
01155 srcV = (vector signed short)vec_mergeh((vector signed char)vzero, \
01156 (vector signed char)srcO); \
01157 dstV = (vector signed short)vec_mergeh((vector signed char)vzero, \
01158 (vector signed char)dstO); \
01159 srcW = (vector signed short)vec_mergel((vector signed char)vzero, \
01160 (vector signed char)srcO); \
01161 dstW = (vector signed short)vec_mergel((vector signed char)vzero, \
01162 (vector signed char)dstO); \
01163 \
01164 but0 = vec_sub(srcV, dstV); \
01165 but0S = vec_sub(srcW, dstW); \
01166 op1 = vec_perm(but0, but0, perm1); \
01167 but1 = vec_mladd(but0, vprod1, op1); \
01168 op1S = vec_perm(but0S, but0S, perm1); \
01169 but1S = vec_mladd(but0S, vprod1, op1S); \
01170 op2 = vec_perm(but1, but1, perm2); \
01171 but2 = vec_mladd(but1, vprod2, op2); \
01172 op2S = vec_perm(but1S, but1S, perm2); \
01173 but2S = vec_mladd(but1S, vprod2, op2S); \
01174 op3 = vec_perm(but2, but2, perm3); \
01175 res1 = vec_mladd(but2, vprod3, op3); \
01176 op3S = vec_perm(but2S, but2S, perm3); \
01177 res2 = vec_mladd(but2S, vprod3, op3S); \
01178 }
01179 ONEITERBUTTERFLY(0, temp0, temp0S);
01180 ONEITERBUTTERFLY(1, temp1, temp1S);
01181 ONEITERBUTTERFLY(2, temp2, temp2S);
01182 ONEITERBUTTERFLY(3, temp3, temp3S);
01183 ONEITERBUTTERFLY(4, temp4, temp4S);
01184 ONEITERBUTTERFLY(5, temp5, temp5S);
01185 ONEITERBUTTERFLY(6, temp6, temp6S);
01186 ONEITERBUTTERFLY(7, temp7, temp7S);
01187 }
01188 #undef ONEITERBUTTERFLY
01189 {
01190 register vector signed int vsum;
01191 register vector signed short line0S, line1S, line2S, line3S, line4S,
01192 line5S, line6S, line7S, line0BS,line2BS,
01193 line1BS,line3BS,line4BS,line6BS,line5BS,
01194 line7BS,line0CS,line4CS,line1CS,line5CS,
01195 line2CS,line6CS,line3CS,line7CS;
01196
01197 register vector signed short line0 = vec_add(temp0, temp1);
01198 register vector signed short line1 = vec_sub(temp0, temp1);
01199 register vector signed short line2 = vec_add(temp2, temp3);
01200 register vector signed short line3 = vec_sub(temp2, temp3);
01201 register vector signed short line4 = vec_add(temp4, temp5);
01202 register vector signed short line5 = vec_sub(temp4, temp5);
01203 register vector signed short line6 = vec_add(temp6, temp7);
01204 register vector signed short line7 = vec_sub(temp6, temp7);
01205
01206 register vector signed short line0B = vec_add(line0, line2);
01207 register vector signed short line2B = vec_sub(line0, line2);
01208 register vector signed short line1B = vec_add(line1, line3);
01209 register vector signed short line3B = vec_sub(line1, line3);
01210 register vector signed short line4B = vec_add(line4, line6);
01211 register vector signed short line6B = vec_sub(line4, line6);
01212 register vector signed short line5B = vec_add(line5, line7);
01213 register vector signed short line7B = vec_sub(line5, line7);
01214
01215 register vector signed short line0C = vec_add(line0B, line4B);
01216 register vector signed short line4C = vec_sub(line0B, line4B);
01217 register vector signed short line1C = vec_add(line1B, line5B);
01218 register vector signed short line5C = vec_sub(line1B, line5B);
01219 register vector signed short line2C = vec_add(line2B, line6B);
01220 register vector signed short line6C = vec_sub(line2B, line6B);
01221 register vector signed short line3C = vec_add(line3B, line7B);
01222 register vector signed short line7C = vec_sub(line3B, line7B);
01223
01224 vsum = vec_sum4s(vec_abs(line0C), vec_splat_s32(0));
01225 vsum = vec_sum4s(vec_abs(line1C), vsum);
01226 vsum = vec_sum4s(vec_abs(line2C), vsum);
01227 vsum = vec_sum4s(vec_abs(line3C), vsum);
01228 vsum = vec_sum4s(vec_abs(line4C), vsum);
01229 vsum = vec_sum4s(vec_abs(line5C), vsum);
01230 vsum = vec_sum4s(vec_abs(line6C), vsum);
01231 vsum = vec_sum4s(vec_abs(line7C), vsum);
01232
01233 line0S = vec_add(temp0S, temp1S);
01234 line1S = vec_sub(temp0S, temp1S);
01235 line2S = vec_add(temp2S, temp3S);
01236 line3S = vec_sub(temp2S, temp3S);
01237 line4S = vec_add(temp4S, temp5S);
01238 line5S = vec_sub(temp4S, temp5S);
01239 line6S = vec_add(temp6S, temp7S);
01240 line7S = vec_sub(temp6S, temp7S);
01241
01242 line0BS = vec_add(line0S, line2S);
01243 line2BS = vec_sub(line0S, line2S);
01244 line1BS = vec_add(line1S, line3S);
01245 line3BS = vec_sub(line1S, line3S);
01246 line4BS = vec_add(line4S, line6S);
01247 line6BS = vec_sub(line4S, line6S);
01248 line5BS = vec_add(line5S, line7S);
01249 line7BS = vec_sub(line5S, line7S);
01250
01251 line0CS = vec_add(line0BS, line4BS);
01252 line4CS = vec_sub(line0BS, line4BS);
01253 line1CS = vec_add(line1BS, line5BS);
01254 line5CS = vec_sub(line1BS, line5BS);
01255 line2CS = vec_add(line2BS, line6BS);
01256 line6CS = vec_sub(line2BS, line6BS);
01257 line3CS = vec_add(line3BS, line7BS);
01258 line7CS = vec_sub(line3BS, line7BS);
01259
01260 vsum = vec_sum4s(vec_abs(line0CS), vsum);
01261 vsum = vec_sum4s(vec_abs(line1CS), vsum);
01262 vsum = vec_sum4s(vec_abs(line2CS), vsum);
01263 vsum = vec_sum4s(vec_abs(line3CS), vsum);
01264 vsum = vec_sum4s(vec_abs(line4CS), vsum);
01265 vsum = vec_sum4s(vec_abs(line5CS), vsum);
01266 vsum = vec_sum4s(vec_abs(line6CS), vsum);
01267 vsum = vec_sum4s(vec_abs(line7CS), vsum);
01268 vsum = vec_sums(vsum, (vector signed int)vzero);
01269 vsum = vec_splat(vsum, 3);
01270 vec_ste(vsum, 0, &sum);
01271 }
01272 return sum;
01273 }
01274
01275 static int hadamard8_diff16_altivec( void *s, uint8_t *dst, uint8_t *src, int stride, int h){
01276 int score;
01277 score = hadamard8_diff16x8_altivec(s, dst, src, stride, 8);
01278 if (h==16) {
01279 dst += 8*stride;
01280 src += 8*stride;
01281 score += hadamard8_diff16x8_altivec(s, dst, src, stride, 8);
01282 }
01283 return score;
01284 }
01285
01286 static void vorbis_inverse_coupling_altivec(float *mag, float *ang,
01287 int blocksize)
01288 {
01289 int i;
01290 vector float m, a;
01291 vector bool int t0, t1;
01292 const vector unsigned int v_31 =
01293 vec_add(vec_add(vec_splat_u32(15),vec_splat_u32(15)),vec_splat_u32(1));
01294 for (i = 0; i < blocksize; i += 4) {
01295 m = vec_ld(0, mag+i);
01296 a = vec_ld(0, ang+i);
01297 t0 = vec_cmple(m, (vector float)vec_splat_u32(0));
01298 t1 = vec_cmple(a, (vector float)vec_splat_u32(0));
01299 a = vec_xor(a, (vector float) vec_sl((vector unsigned int)t0, v_31));
01300 t0 = (vector bool int)vec_and(a, t1);
01301 t1 = (vector bool int)vec_andc(a, t1);
01302 a = vec_sub(m, (vector float)t1);
01303 m = vec_add(m, (vector float)t0);
01304 vec_stl(a, 0, ang+i);
01305 vec_stl(m, 0, mag+i);
01306 }
01307 }
01308
01309
01310 static void avg_pixels8_xy2_altivec(uint8_t *block, const uint8_t *pixels, int line_size, int h)
01311 {
01312 register int i;
01313 register vector unsigned char pixelsv1, pixelsv2, pixelsavg;
01314 register vector unsigned char blockv, temp1, temp2, blocktemp;
01315 register vector unsigned short pixelssum1, pixelssum2, temp3;
01316
01317 register const vector unsigned char vczero = (const vector unsigned char)
01318 vec_splat_u8(0);
01319 register const vector unsigned short vctwo = (const vector unsigned short)
01320 vec_splat_u16(2);
01321
01322 temp1 = vec_ld(0, pixels);
01323 temp2 = vec_ld(16, pixels);
01324 pixelsv1 = vec_perm(temp1, temp2, vec_lvsl(0, pixels));
01325 if ((((unsigned long)pixels) & 0x0000000F) == 0x0000000F) {
01326 pixelsv2 = temp2;
01327 } else {
01328 pixelsv2 = vec_perm(temp1, temp2, vec_lvsl(1, pixels));
01329 }
01330 pixelsv1 = vec_mergeh(vczero, pixelsv1);
01331 pixelsv2 = vec_mergeh(vczero, pixelsv2);
01332 pixelssum1 = vec_add((vector unsigned short)pixelsv1,
01333 (vector unsigned short)pixelsv2);
01334 pixelssum1 = vec_add(pixelssum1, vctwo);
01335
01336 for (i = 0; i < h ; i++) {
01337 int rightside = ((unsigned long)block & 0x0000000F);
01338 blockv = vec_ld(0, block);
01339
01340 temp1 = vec_ld(line_size, pixels);
01341 temp2 = vec_ld(line_size + 16, pixels);
01342 pixelsv1 = vec_perm(temp1, temp2, vec_lvsl(line_size, pixels));
01343 if (((((unsigned long)pixels) + line_size) & 0x0000000F) == 0x0000000F) {
01344 pixelsv2 = temp2;
01345 } else {
01346 pixelsv2 = vec_perm(temp1, temp2, vec_lvsl(line_size + 1, pixels));
01347 }
01348
01349 pixelsv1 = vec_mergeh(vczero, pixelsv1);
01350 pixelsv2 = vec_mergeh(vczero, pixelsv2);
01351 pixelssum2 = vec_add((vector unsigned short)pixelsv1,
01352 (vector unsigned short)pixelsv2);
01353 temp3 = vec_add(pixelssum1, pixelssum2);
01354 temp3 = vec_sra(temp3, vctwo);
01355 pixelssum1 = vec_add(pixelssum2, vctwo);
01356 pixelsavg = vec_packsu(temp3, (vector unsigned short) vczero);
01357
01358 if (rightside) {
01359 blocktemp = vec_perm(blockv, pixelsavg, vcprm(0, 1, s0, s1));
01360 } else {
01361 blocktemp = vec_perm(blockv, pixelsavg, vcprm(s0, s1, 2, 3));
01362 }
01363
01364 blockv = vec_avg(blocktemp, blockv);
01365 vec_st(blockv, 0, block);
01366
01367 block += line_size;
01368 pixels += line_size;
01369 }
01370 }
01371
01372 void ff_dsputil_init_altivec(DSPContext* c, AVCodecContext *avctx)
01373 {
01374 const int high_bit_depth = avctx->bits_per_raw_sample > 8;
01375
01376 c->pix_abs[0][1] = sad16_x2_altivec;
01377 c->pix_abs[0][2] = sad16_y2_altivec;
01378 c->pix_abs[0][3] = sad16_xy2_altivec;
01379 c->pix_abs[0][0] = sad16_altivec;
01380 c->pix_abs[1][0] = sad8_altivec;
01381 c->sad[0]= sad16_altivec;
01382 c->sad[1]= sad8_altivec;
01383 c->pix_norm1 = pix_norm1_altivec;
01384 c->sse[1]= sse8_altivec;
01385 c->sse[0]= sse16_altivec;
01386 c->pix_sum = pix_sum_altivec;
01387 c->diff_pixels = diff_pixels_altivec;
01388 c->add_bytes= add_bytes_altivec;
01389 if (!high_bit_depth) {
01390 c->get_pixels = get_pixels_altivec;
01391 c->clear_block = clear_block_altivec;
01392 c->put_pixels_tab[0][0] = ff_put_pixels16_altivec;
01393
01394 c->put_no_rnd_pixels_tab[0][0] = ff_put_pixels16_altivec;
01395 c->avg_pixels_tab[0][0] = ff_avg_pixels16_altivec;
01396 c->avg_pixels_tab[1][0] = avg_pixels8_altivec;
01397 c->avg_pixels_tab[1][3] = avg_pixels8_xy2_altivec;
01398 c->put_pixels_tab[1][3] = put_pixels8_xy2_altivec;
01399 c->put_no_rnd_pixels_tab[1][3] = put_no_rnd_pixels8_xy2_altivec;
01400 c->put_pixels_tab[0][3] = put_pixels16_xy2_altivec;
01401 c->put_no_rnd_pixels_tab[0][3] = put_no_rnd_pixels16_xy2_altivec;
01402 }
01403
01404 c->hadamard8_diff[0] = hadamard8_diff16_altivec;
01405 c->hadamard8_diff[1] = hadamard8_diff8x8_altivec;
01406 if (CONFIG_VORBIS_DECODER)
01407 c->vorbis_inverse_coupling = vorbis_inverse_coupling_altivec;
01408 }