1 /*****************************************************************************
2 * mc.c: h264 encoder library (Motion Compensation)
3 *****************************************************************************
4 * Copyright (C) 2003-2008 x264 project
6 * Authors: Eric Petit <eric.petit@lapsus.org>
7 * Guillaume Poirier <gpoirier@mplayerhq.hu>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program 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
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
22 *****************************************************************************/
31 #include "common/common.h"
32 #include "common/mc.h"
34 #include "ppccommon.h"
36 typedef void (*pf_mc_t)( uint8_t *src, int i_src,
37 uint8_t *dst, int i_dst, int i_height );
40 static const int hpel_ref0[16] = {0,1,1,1,0,1,1,1,2,3,3,3,0,1,1,1};
41 static const int hpel_ref1[16] = {0,0,0,0,2,2,3,2,2,2,3,2,2,2,3,2};
44 static inline int x264_tapfilter( uint8_t *pix, int i_pix_next )
46 return pix[-2*i_pix_next] - 5*pix[-1*i_pix_next] + 20*(pix[0] +
47 pix[1*i_pix_next]) - 5*pix[ 2*i_pix_next] +
50 static inline int x264_tapfilter1( uint8_t *pix )
52 return pix[-2] - 5*pix[-1] + 20*(pix[0] + pix[1]) - 5*pix[ 2] +
57 static inline void x264_pixel_avg2_w4_altivec( uint8_t *dst, int i_dst,
58 uint8_t *src1, int i_src1,
59 uint8_t *src2, int i_height )
61 for( int y = 0; y < i_height; y++ )
63 for( int x = 0; x < 4; x++ )
64 dst[x] = ( src1[x] + src2[x] + 1 ) >> 1;
71 static inline void x264_pixel_avg2_w8_altivec( uint8_t *dst, int i_dst,
72 uint8_t *src1, int i_src1,
73 uint8_t *src2, int i_height )
75 vec_u8_t src1v, src2v;
78 PREP_LOAD_SRC( src1 );
79 PREP_LOAD_SRC( src2 );
81 for( int y = 0; y < i_height; y++ )
83 VEC_LOAD( src1, src1v, 8, vec_u8_t, src1 );
84 VEC_LOAD( src2, src2v, 8, vec_u8_t, src2 );
85 src1v = vec_avg( src1v, src2v );
86 VEC_STORE8( src1v, dst );
94 static inline void x264_pixel_avg2_w16_altivec( uint8_t *dst, int i_dst,
95 uint8_t *src1, int i_src1,
96 uint8_t *src2, int i_height )
98 vec_u8_t src1v, src2v;
100 PREP_LOAD_SRC( src1 );
101 PREP_LOAD_SRC( src2 );
103 for( int y = 0; y < i_height; y++ )
105 VEC_LOAD( src1, src1v, 16, vec_u8_t, src1 );
106 VEC_LOAD( src2, src2v, 16, vec_u8_t, src2 );
107 src1v = vec_avg( src1v, src2v );
108 vec_st(src1v, 0, dst);
116 static inline void x264_pixel_avg2_w20_altivec( uint8_t *dst, int i_dst,
117 uint8_t *src1, int i_src1,
118 uint8_t *src2, int i_height )
120 x264_pixel_avg2_w16_altivec(dst, i_dst, src1, i_src1, src2, i_height);
121 x264_pixel_avg2_w4_altivec(dst+16, i_dst, src1+16, i_src1, src2+16, i_height);
124 /* mc_copy: plain c */
126 #define MC_COPY( name, a ) \
127 static void name( uint8_t *dst, int i_dst, \
128 uint8_t *src, int i_src, int i_height ) \
131 for( y = 0; y < i_height; y++ ) \
133 memcpy( dst, src, a ); \
138 MC_COPY( x264_mc_copy_w4_altivec, 4 )
139 MC_COPY( x264_mc_copy_w8_altivec, 8 )
141 static void x264_mc_copy_w16_altivec( uint8_t *dst, int i_dst,
142 uint8_t *src, int i_src, int i_height )
146 PREP_LOAD_SRC( src );
148 for( int y = 0; y < i_height; y++)
150 VEC_LOAD( src, cpyV, 16, vec_u8_t, src );
151 vec_st(cpyV, 0, dst);
159 static void x264_mc_copy_w16_aligned_altivec( uint8_t *dst, int i_dst,
160 uint8_t *src, int i_src, int i_height )
162 for( int y = 0; y < i_height; ++y)
164 vec_u8_t cpyV = vec_ld( 0, src);
165 vec_st(cpyV, 0, dst);
173 static void mc_luma_altivec( uint8_t *dst, int i_dst_stride,
174 uint8_t *src[4], int i_src_stride,
176 int i_width, int i_height, const x264_weight_t *weight )
178 int qpel_idx = ((mvy&3)<<2) + (mvx&3);
179 int offset = (mvy>>2)*i_src_stride + (mvx>>2);
180 uint8_t *src1 = src[hpel_ref0[qpel_idx]] + offset + ((mvy&3) == 3) * i_src_stride;
181 if( qpel_idx & 5 ) /* qpel interpolation needed */
183 uint8_t *src2 = src[hpel_ref1[qpel_idx]] + offset + ((mvx&3) == 3);
188 x264_pixel_avg2_w4_altivec( dst, i_dst_stride, src1, i_src_stride, src2, i_height );
191 x264_pixel_avg2_w8_altivec( dst, i_dst_stride, src1, i_src_stride, src2, i_height );
195 x264_pixel_avg2_w16_altivec( dst, i_dst_stride, src1, i_src_stride, src2, i_height );
197 if( weight->weightfn )
198 weight->weightfn[i_width>>2]( dst, i_dst_stride, dst, i_dst_stride, weight, i_height );
200 else if( weight->weightfn )
201 weight->weightfn[i_width>>2]( dst, i_dst_stride, src1, i_src_stride, weight, i_height );
207 x264_mc_copy_w4_altivec( dst, i_dst_stride, src1, i_src_stride, i_height );
210 x264_mc_copy_w8_altivec( dst, i_dst_stride, src1, i_src_stride, i_height );
213 x264_mc_copy_w16_altivec( dst, i_dst_stride, src1, i_src_stride, i_height );
221 static uint8_t *get_ref_altivec( uint8_t *dst, int *i_dst_stride,
222 uint8_t *src[4], int i_src_stride,
224 int i_width, int i_height, const x264_weight_t *weight )
226 int qpel_idx = ((mvy&3)<<2) + (mvx&3);
227 int offset = (mvy>>2)*i_src_stride + (mvx>>2);
228 uint8_t *src1 = src[hpel_ref0[qpel_idx]] + offset + ((mvy&3) == 3) * i_src_stride;
229 if( qpel_idx & 5 ) /* qpel interpolation needed */
231 uint8_t *src2 = src[hpel_ref1[qpel_idx]] + offset + ((mvx&3) == 3);
235 x264_pixel_avg2_w4_altivec( dst, *i_dst_stride, src1, i_src_stride, src2, i_height );
238 x264_pixel_avg2_w8_altivec( dst, *i_dst_stride, src1, i_src_stride, src2, i_height );
243 x264_pixel_avg2_w16_altivec( dst, *i_dst_stride, src1, i_src_stride, src2, i_height );
246 x264_pixel_avg2_w20_altivec( dst, *i_dst_stride, src1, i_src_stride, src2, i_height );
249 if( weight->weightfn )
250 weight->weightfn[i_width>>2]( dst, *i_dst_stride, dst, *i_dst_stride, weight, i_height );
253 else if( weight->weightfn )
255 weight->weightfn[i_width>>2]( dst, *i_dst_stride, src1, i_src_stride, weight, i_height );
260 *i_dst_stride = i_src_stride;
265 static void mc_chroma_2xh( uint8_t *dst, int i_dst_stride,
266 uint8_t *src, int i_src_stride,
274 int cA = (8-d8x)*(8-d8y);
275 int cB = d8x *(8-d8y);
276 int cC = (8-d8x)*d8y;
279 src += (mvy >> 3) * i_src_stride + (mvx >> 3);
280 srcp = &src[i_src_stride];
282 for( int y = 0; y < i_height; y++ )
284 dst[0] = ( cA*src[0] + cB*src[0+1] + cC*srcp[0] + cD*srcp[0+1] + 32 ) >> 6;
285 dst[1] = ( cA*src[1] + cB*src[1+1] + cC*srcp[1] + cD*srcp[1+1] + 32 ) >> 6;
288 srcp += i_src_stride;
294 #define DO_PROCESS_W4( a ) \
295 dstv_16A = vec_mladd( src##a##v_16A, coeff##a##v, dstv_16A ); \
296 dstv_16B = vec_mladd( src##a##v_16B, coeff##a##v, dstv_16B )
298 static void mc_chroma_altivec_4xh( uint8_t *dst, int i_dst_stride,
299 uint8_t *src, int i_src_stride,
304 int d8x = mvx & 0x07;
305 int d8y = mvy & 0x07;
307 ALIGNED_16( uint16_t coeff[4] );
308 coeff[0] = (8-d8x)*(8-d8y);
309 coeff[1] = d8x *(8-d8y);
310 coeff[2] = (8-d8x)*d8y;
313 src += (mvy >> 3) * i_src_stride + (mvx >> 3);
314 srcp = &src[i_src_stride];
318 PREP_LOAD_SRC( src );
319 vec_u16_t coeff0v, coeff1v, coeff2v, coeff3v;
320 vec_u8_t src2v_8A, dstv_8A;
321 vec_u8_t src2v_8B, dstv_8B;
322 vec_u16_t src0v_16A, src1v_16A, src2v_16A, src3v_16A, dstv_16A;
323 vec_u16_t src0v_16B, src1v_16B, src2v_16B, src3v_16B, dstv_16B;
324 vec_u16_t shiftv, k32v;
326 coeff0v = vec_ld( 0, coeff );
327 coeff3v = vec_splat( coeff0v, 3 );
328 coeff2v = vec_splat( coeff0v, 2 );
329 coeff1v = vec_splat( coeff0v, 1 );
330 coeff0v = vec_splat( coeff0v, 0 );
331 k32v = vec_sl( vec_splat_u16( 1 ), vec_splat_u16( 5 ) );
332 shiftv = vec_splat_u16( 6 );
334 VEC_LOAD( src, src2v_8B, 5, vec_u8_t, src );
335 src2v_16B = vec_u8_to_u16( src2v_8B );
336 src3v_16B = vec_sld( src2v_16B, src2v_16B, 2 );
338 for( int y = 0; y < i_height; y += 2 )
340 src0v_16A = src2v_16B;
341 src1v_16A = src3v_16B;
343 VEC_LOAD_G( srcp, src2v_8A, 5, vec_u8_t );
344 srcp += i_src_stride;
345 VEC_LOAD_G( srcp, src2v_8B, 5, vec_u8_t );
346 srcp += i_src_stride;
347 src2v_16A = vec_u8_to_u16( src2v_8A );
348 src2v_16B = vec_u8_to_u16( src2v_8B );
349 src3v_16A = vec_sld( src2v_16A, src2v_16A, 2 );
350 src3v_16B = vec_sld( src2v_16B, src2v_16B, 2 );
352 src0v_16B = src2v_16A;
353 src1v_16B = src3v_16A;
355 dstv_16A = dstv_16B = k32v;
361 dstv_16A = vec_sr( dstv_16A, shiftv );
362 dstv_16B = vec_sr( dstv_16B, shiftv );
363 dstv_8A = vec_u16_to_u8( dstv_16A );
364 dstv_8B = vec_u16_to_u8( dstv_16B );
365 vec_ste( vec_splat( (vec_u32_t) dstv_8A, 0 ), 0, (uint32_t*) dst );
367 vec_ste( vec_splat( (vec_u32_t) dstv_8B, 0 ), 0, (uint32_t*) dst );
372 #define DO_PROCESS_W8( a ) \
373 src##a##v_16A = vec_u8_to_u16( src##a##v_8A ); \
374 src##a##v_16B = vec_u8_to_u16( src##a##v_8B ); \
375 dstv_16A = vec_mladd( src##a##v_16A, coeff##a##v, dstv_16A ); \
376 dstv_16B = vec_mladd( src##a##v_16B, coeff##a##v, dstv_16B )
378 static void mc_chroma_altivec_8xh( uint8_t *dst, int i_dst_stride,
379 uint8_t *src, int i_src_stride,
384 int d8x = mvx & 0x07;
385 int d8y = mvy & 0x07;
387 ALIGNED_16( uint16_t coeff[4] );
388 coeff[0] = (8-d8x)*(8-d8y);
389 coeff[1] = d8x *(8-d8y);
390 coeff[2] = (8-d8x)*d8y;
393 src += (mvy >> 3) * i_src_stride + (mvx >> 3);
394 srcp = &src[i_src_stride];
398 PREP_LOAD_SRC( src );
400 vec_u16_t coeff0v, coeff1v, coeff2v, coeff3v;
401 vec_u8_t src0v_8A, src1v_8A, src2v_8A, src3v_8A, dstv_8A;
402 vec_u8_t src0v_8B, src1v_8B, src2v_8B, src3v_8B, dstv_8B;
403 vec_u16_t src0v_16A, src1v_16A, src2v_16A, src3v_16A, dstv_16A;
404 vec_u16_t src0v_16B, src1v_16B, src2v_16B, src3v_16B, dstv_16B;
405 vec_u16_t shiftv, k32v;
407 coeff0v = vec_ld( 0, coeff );
408 coeff3v = vec_splat( coeff0v, 3 );
409 coeff2v = vec_splat( coeff0v, 2 );
410 coeff1v = vec_splat( coeff0v, 1 );
411 coeff0v = vec_splat( coeff0v, 0 );
412 k32v = vec_sl( vec_splat_u16( 1 ), vec_splat_u16( 5 ) );
413 shiftv = vec_splat_u16( 6 );
415 VEC_LOAD( src, src2v_8B, 9, vec_u8_t, src );
416 src3v_8B = vec_sld( src2v_8B, src2v_8B, 1 );
418 for( int y = 0; y < i_height; y+=2 )
423 VEC_LOAD_G( srcp, src2v_8A, 9, vec_u8_t );
424 srcp += i_src_stride;
425 VEC_LOAD_G( srcp, src2v_8B, 9, vec_u8_t );
426 srcp += i_src_stride;
427 src3v_8A = vec_sld( src2v_8A, src2v_8A, 1 );
428 src3v_8B = vec_sld( src2v_8B, src2v_8B, 1 );
432 dstv_16A = dstv_16B = k32v;
438 dstv_16A = vec_sr( dstv_16A, shiftv );
439 dstv_16B = vec_sr( dstv_16B, shiftv );
440 dstv_8A = vec_u16_to_u8( dstv_16A );
441 dstv_8B = vec_u16_to_u8( dstv_16B );
442 VEC_STORE8( dstv_8A, dst );
444 VEC_STORE8( dstv_8B, dst );
449 static void mc_chroma_altivec( uint8_t *dst, int i_dst_stride,
450 uint8_t *src, int i_src_stride,
452 int i_width, int i_height )
455 mc_chroma_altivec_8xh( dst, i_dst_stride, src, i_src_stride,
456 mvx, mvy, i_height );
457 else if( i_width == 4 )
458 mc_chroma_altivec_4xh( dst, i_dst_stride, src, i_src_stride,
459 mvx, mvy, i_height );
461 mc_chroma_2xh( dst, i_dst_stride, src, i_src_stride,
462 mvx, mvy, i_height );
465 #define HPEL_FILTER_1( t1v, t2v, t3v, t4v, t5v, t6v ) \
467 t1v = vec_add( t1v, t6v ); \
468 t2v = vec_add( t2v, t5v ); \
469 t3v = vec_add( t3v, t4v ); \
471 t1v = vec_sub( t1v, t2v ); /* (a-b) */ \
472 t2v = vec_sub( t2v, t3v ); /* (b-c) */ \
473 t2v = vec_sl( t2v, twov ); /* (b-c)*4 */ \
474 t1v = vec_sub( t1v, t2v ); /* a-5*b+4*c */ \
475 t3v = vec_sl( t3v, fourv ); /* 16*c */ \
476 t1v = vec_add( t1v, t3v ); /* a-5*b+20*c */ \
479 #define HPEL_FILTER_2( t1v, t2v, t3v, t4v, t5v, t6v ) \
481 t1v = vec_add( t1v, t6v ); \
482 t2v = vec_add( t2v, t5v ); \
483 t3v = vec_add( t3v, t4v ); \
485 t1v = vec_sub( t1v, t2v ); /* (a-b) */ \
486 t1v = vec_sra( t1v, twov ); /* (a-b)/4 */ \
487 t1v = vec_sub( t1v, t2v ); /* (a-b)/4-b */ \
488 t1v = vec_add( t1v, t3v ); /* (a-b)/4-b+c */ \
489 t1v = vec_sra( t1v, twov ); /* ((a-b)/4-b+c)/4 */ \
490 t1v = vec_add( t1v, t3v ); /* ((a-b)/4-b+c)/4+c = (a-5*b+20*c)/16 */ \
493 #define HPEL_FILTER_HORIZONTAL() \
495 VEC_LOAD_G( &src[x- 2+i_stride*y], src1v, 16, vec_u8_t); \
496 VEC_LOAD_G( &src[x+14+i_stride*y], src6v, 16, vec_u8_t); \
498 src2v = vec_sld( src1v, src6v, 1 ); \
499 src3v = vec_sld( src1v, src6v, 2 ); \
500 src4v = vec_sld( src1v, src6v, 3 ); \
501 src5v = vec_sld( src1v, src6v, 4 ); \
502 src6v = vec_sld( src1v, src6v, 5 ); \
504 temp1v = vec_u8_to_s16_h( src1v ); \
505 temp2v = vec_u8_to_s16_h( src2v ); \
506 temp3v = vec_u8_to_s16_h( src3v ); \
507 temp4v = vec_u8_to_s16_h( src4v ); \
508 temp5v = vec_u8_to_s16_h( src5v ); \
509 temp6v = vec_u8_to_s16_h( src6v ); \
511 HPEL_FILTER_1( temp1v, temp2v, temp3v, \
512 temp4v, temp5v, temp6v ); \
514 dest1v = vec_add( temp1v, sixteenv ); \
515 dest1v = vec_sra( dest1v, fivev ); \
517 temp1v = vec_u8_to_s16_l( src1v ); \
518 temp2v = vec_u8_to_s16_l( src2v ); \
519 temp3v = vec_u8_to_s16_l( src3v ); \
520 temp4v = vec_u8_to_s16_l( src4v ); \
521 temp5v = vec_u8_to_s16_l( src5v ); \
522 temp6v = vec_u8_to_s16_l( src6v ); \
524 HPEL_FILTER_1( temp1v, temp2v, temp3v, \
525 temp4v, temp5v, temp6v ); \
527 dest2v = vec_add( temp1v, sixteenv ); \
528 dest2v = vec_sra( dest2v, fivev ); \
530 destv = vec_packsu( dest1v, dest2v ); \
532 VEC_STORE16( destv, &dsth[x+i_stride*y], dsth ); \
535 #define HPEL_FILTER_VERTICAL() \
537 VEC_LOAD( &src[x+i_stride*(y-2)], src1v, 16, vec_u8_t, src ); \
538 VEC_LOAD( &src[x+i_stride*(y-1)], src2v, 16, vec_u8_t, src ); \
539 VEC_LOAD( &src[x+i_stride*(y-0)], src3v, 16, vec_u8_t, src ); \
540 VEC_LOAD( &src[x+i_stride*(y+1)], src4v, 16, vec_u8_t, src ); \
541 VEC_LOAD( &src[x+i_stride*(y+2)], src5v, 16, vec_u8_t, src ); \
542 VEC_LOAD( &src[x+i_stride*(y+3)], src6v, 16, vec_u8_t, src ); \
544 temp1v = vec_u8_to_s16_h( src1v ); \
545 temp2v = vec_u8_to_s16_h( src2v ); \
546 temp3v = vec_u8_to_s16_h( src3v ); \
547 temp4v = vec_u8_to_s16_h( src4v ); \
548 temp5v = vec_u8_to_s16_h( src5v ); \
549 temp6v = vec_u8_to_s16_h( src6v ); \
551 HPEL_FILTER_1( temp1v, temp2v, temp3v, \
552 temp4v, temp5v, temp6v ); \
554 dest1v = vec_add( temp1v, sixteenv ); \
555 dest1v = vec_sra( dest1v, fivev ); \
557 temp4v = vec_u8_to_s16_l( src1v ); \
558 temp5v = vec_u8_to_s16_l( src2v ); \
559 temp6v = vec_u8_to_s16_l( src3v ); \
560 temp7v = vec_u8_to_s16_l( src4v ); \
561 temp8v = vec_u8_to_s16_l( src5v ); \
562 temp9v = vec_u8_to_s16_l( src6v ); \
564 HPEL_FILTER_1( temp4v, temp5v, temp6v, \
565 temp7v, temp8v, temp9v ); \
567 dest2v = vec_add( temp4v, sixteenv ); \
568 dest2v = vec_sra( dest2v, fivev ); \
570 destv = vec_packsu( dest1v, dest2v ); \
572 VEC_STORE16( destv, &dstv[x+i_stride*y], dsth ); \
575 #define HPEL_FILTER_CENTRAL() \
577 temp1v = vec_sld( tempav, tempbv, 12 ); \
578 temp2v = vec_sld( tempav, tempbv, 14 ); \
580 temp4v = vec_sld( tempbv, tempcv, 2 ); \
581 temp5v = vec_sld( tempbv, tempcv, 4 ); \
582 temp6v = vec_sld( tempbv, tempcv, 6 ); \
584 HPEL_FILTER_2( temp1v, temp2v, temp3v, \
585 temp4v, temp5v, temp6v ); \
587 dest1v = vec_add( temp1v, thirtytwov ); \
588 dest1v = vec_sra( dest1v, sixv ); \
590 temp1v = vec_sld( tempbv, tempcv, 12 ); \
591 temp2v = vec_sld( tempbv, tempcv, 14 ); \
593 temp4v = vec_sld( tempcv, tempdv, 2 ); \
594 temp5v = vec_sld( tempcv, tempdv, 4 ); \
595 temp6v = vec_sld( tempcv, tempdv, 6 ); \
597 HPEL_FILTER_2( temp1v, temp2v, temp3v, \
598 temp4v, temp5v, temp6v ); \
600 dest2v = vec_add( temp1v, thirtytwov ); \
601 dest2v = vec_sra( dest2v, sixv ); \
603 destv = vec_packsu( dest1v, dest2v ); \
605 VEC_STORE16( destv, &dstc[x-16+i_stride*y], dsth ); \
608 void x264_hpel_filter_altivec( uint8_t *dsth, uint8_t *dstv, uint8_t *dstc, uint8_t *src,
609 int i_stride, int i_width, int i_height, int16_t *buf )
612 vec_u8_t src1v, src2v, src3v, src4v, src5v, src6v;
613 vec_s16_t dest1v, dest2v;
614 vec_s16_t temp1v, temp2v, temp3v, temp4v, temp5v, temp6v, temp7v, temp8v, temp9v;
615 vec_s16_t tempav, tempbv, tempcv, tempdv, tempev;
620 PREP_STORE16_DST( dsth );
623 vec_u16_t twov, fourv, fivev, sixv;
624 vec_s16_t sixteenv, thirtytwov;
628 twov = vec_splat( temp_u.v, 0 );
630 fourv = vec_splat( temp_u.v, 0 );
632 fivev = vec_splat( temp_u.v, 0 );
634 sixv = vec_splat( temp_u.v, 0 );
636 sixteenv = (vec_s16_t)vec_splat( temp_u.v, 0 );
638 thirtytwov = (vec_s16_t)vec_splat( temp_u.v, 0 );
640 for( int y = 0; y < i_height; y++ )
644 /* horizontal_filter */
645 HPEL_FILTER_HORIZONTAL();
647 /* vertical_filter */
648 HPEL_FILTER_VERTICAL();
653 tempcv = vec_splat( temp1v, 0 ); /* first only */
657 for( x = 16; x < i_width; x+=16 )
659 /* horizontal_filter */
660 HPEL_FILTER_HORIZONTAL();
662 /* vertical_filter */
663 HPEL_FILTER_VERTICAL();
672 HPEL_FILTER_CENTRAL();
675 /* Partial vertical filter */
676 VEC_LOAD_PARTIAL( &src[x+i_stride*(y-2)], src1v, 16, vec_u8_t, src );
677 VEC_LOAD_PARTIAL( &src[x+i_stride*(y-1)], src2v, 16, vec_u8_t, src );
678 VEC_LOAD_PARTIAL( &src[x+i_stride*(y-0)], src3v, 16, vec_u8_t, src );
679 VEC_LOAD_PARTIAL( &src[x+i_stride*(y+1)], src4v, 16, vec_u8_t, src );
680 VEC_LOAD_PARTIAL( &src[x+i_stride*(y+2)], src5v, 16, vec_u8_t, src );
681 VEC_LOAD_PARTIAL( &src[x+i_stride*(y+3)], src6v, 16, vec_u8_t, src );
683 temp1v = vec_u8_to_s16_h( src1v );
684 temp2v = vec_u8_to_s16_h( src2v );
685 temp3v = vec_u8_to_s16_h( src3v );
686 temp4v = vec_u8_to_s16_h( src4v );
687 temp5v = vec_u8_to_s16_h( src5v );
688 temp6v = vec_u8_to_s16_h( src6v );
690 HPEL_FILTER_1( temp1v, temp2v, temp3v, temp4v, temp5v, temp6v );
697 /* tempev is not used */
699 HPEL_FILTER_CENTRAL();
703 static void frame_init_lowres_core_altivec( uint8_t *src0, uint8_t *dst0, uint8_t *dsth, uint8_t *dstv, uint8_t *dstc,
704 int src_stride, int dst_stride, int width, int height )
707 int end = (width & 15);
708 vec_u8_t src0v, src1v, src2v;
709 vec_u8_t lv, hv, src1p1v;
710 vec_u8_t avg0v, avg1v, avghv, avghp1v, avgleftv, avgrightv;
711 static const vec_u8_t inverse_bridge_shuffle = CV(0x00, 0x02, 0x04, 0x06, 0x08, 0x0A, 0x0C, 0x0E, 0x10, 0x12, 0x14, 0x16, 0x18, 0x1A, 0x1C, 0x1E );
713 for( int y = 0; y < height; y++ )
716 uint8_t *src1 = src0+src_stride;
717 uint8_t *src2 = src1+src_stride;
719 src0v = vec_ld(0, src0);
720 src1v = vec_ld(0, src1);
721 src2v = vec_ld(0, src2);
723 avg0v = vec_avg(src0v, src1v);
724 avg1v = vec_avg(src1v, src2v);
726 for( x = 0; x < w; x++ )
728 lv = vec_ld(16*(x*2+1), src0);
729 src1v = vec_ld(16*(x*2+1), src1);
730 avghv = vec_avg(lv, src1v);
732 lv = vec_ld(16*(x*2+2), src0);
733 src1p1v = vec_ld(16*(x*2+2), src1);
734 avghp1v = vec_avg(lv, src1p1v);
736 avgleftv = vec_avg(vec_sld(avg0v, avghv, 1), avg0v);
737 avgrightv = vec_avg(vec_sld(avghv, avghp1v, 1), avghv);
739 vec_st(vec_perm(avgleftv, avgrightv, inverse_bridge_shuffle), 16*x, dst0);
740 vec_st((vec_u8_t)vec_pack((vec_u16_t)avgleftv,(vec_u16_t)avgrightv), 16*x, dsth);
744 hv = vec_ld(16*(x*2+1), src2);
745 avghv = vec_avg(src1v, hv);
747 hv = vec_ld(16*(x*2+2), src2);
748 avghp1v = vec_avg(src1p1v, hv);
750 avgleftv = vec_avg(vec_sld(avg1v, avghv, 1), avg1v);
751 avgrightv = vec_avg(vec_sld(avghv, avghp1v, 1), avghv);
753 vec_st(vec_perm(avgleftv, avgrightv, inverse_bridge_shuffle), 16*x, dstv);
754 vec_st((vec_u8_t)vec_pack((vec_u16_t)avgleftv,(vec_u16_t)avgrightv), 16*x, dstc);
761 lv = vec_ld(16*(x*2+1), src0);
762 src1v = vec_ld(16*(x*2+1), src1);
763 avghv = vec_avg(lv, src1v);
765 lv = vec_ld(16*(x*2+1), src2);
766 avghp1v = vec_avg(src1v, lv);
768 avgleftv = vec_avg(vec_sld(avg0v, avghv, 1), avg0v);
769 avgrightv = vec_avg(vec_sld(avg1v, avghp1v, 1), avg1v);
771 lv = vec_perm(avgleftv, avgrightv, inverse_bridge_shuffle);
772 hv = (vec_u8_t)vec_pack((vec_u16_t)avgleftv,(vec_u16_t)avgrightv);
774 vec_ste((vec_u32_t)lv,16*x,(uint32_t*)dst0);
775 vec_ste((vec_u32_t)lv,16*x+4,(uint32_t*)dst0);
776 vec_ste((vec_u32_t)hv,16*x,(uint32_t*)dsth);
777 vec_ste((vec_u32_t)hv,16*x+4,(uint32_t*)dsth);
779 lv = vec_sld(lv, lv, 8);
780 hv = vec_sld(hv, hv, 8);
782 vec_ste((vec_u32_t)lv,16*x,(uint32_t*)dstv);
783 vec_ste((vec_u32_t)lv,16*x+4,(uint32_t*)dstv);
784 vec_ste((vec_u32_t)hv,16*x,(uint32_t*)dstc);
785 vec_ste((vec_u32_t)hv,16*x+4,(uint32_t*)dstc);
788 src0 += src_stride*2;
796 void x264_mc_altivec_init( x264_mc_functions_t *pf )
798 pf->mc_luma = mc_luma_altivec;
799 pf->get_ref = get_ref_altivec;
800 pf->mc_chroma = mc_chroma_altivec;
802 pf->copy_16x16_unaligned = x264_mc_copy_w16_altivec;
803 pf->copy[PIXEL_16x16] = x264_mc_copy_w16_aligned_altivec;
805 pf->hpel_filter = x264_hpel_filter_altivec;
806 pf->frame_init_lowres_core = frame_init_lowres_core_altivec;