From 09e76c903d3419619ed326a4dd114369a55bdd6e Mon Sep 17 00:00:00 2001 From: Guillaume Poirier Date: Sun, 18 Jan 2009 22:44:14 +0100 Subject: [PATCH] Add AltiVec implementation of predict_8x8c_p. 2.6x faster than scalar C. --- common/ppc/predict.c | 56 +++++++++++++++++++++++++++++++++++++++++++- common/ppc/predict.h | 1 + common/predict.c | 7 ++++++ 3 files changed, 63 insertions(+), 1 deletion(-) diff --git a/common/ppc/predict.c b/common/ppc/predict.c index 589b00c8..9b38fbb6 100644 --- a/common/ppc/predict.c +++ b/common/ppc/predict.c @@ -23,6 +23,56 @@ #include "pixel.h" #include "ppccommon.h" +static void predict_8x8c_p_altivec( uint8_t *src ) +{ + int i; + int a, b, c; + int H = 0; + int V = 0; + int i00; + + for( i = 0; i < 4; i++ ) + { + H += ( i + 1 ) * ( src[4+i - FDEC_STRIDE] - src[2 - i -FDEC_STRIDE] ); + V += ( i + 1 ) * ( src[-1 +(i+4)*FDEC_STRIDE] - src[-1+(2-i)*FDEC_STRIDE] ); + } + + a = 16 * ( src[-1+7*FDEC_STRIDE] + src[7 - FDEC_STRIDE] ); + b = ( 17 * H + 16 ) >> 5; + c = ( 17 * V + 16 ) >> 5; + i00 = a -3*b -3*c + 16; + + vec_s16_u i00_u, b_u, c_u; + i00_u.s[0] = i00; + b_u.s[0] = b; + c_u.s[0] = c; + + vec_u16_t val5_v = vec_splat_u16(5); + vec_s16_t i00_v, b_v, c_v; + i00_v = vec_splat(i00_u.v, 0); + b_v = vec_splat(b_u.v, 0); + c_v = vec_splat(c_u.v, 0); + + vec_s16_t induc_v = (vec_s16_t) CV(0, 1, 2, 3, 4, 5, 6, 7); + vec_s32_t mule_b_v = vec_mule(induc_v, b_v); + vec_s32_t mulo_b_v = vec_mulo(induc_v, b_v); + vec_s16_t mul_b_induc0_v = vec_pack(vec_mergeh(mule_b_v, mulo_b_v), vec_mergel(mule_b_v, mulo_b_v)); + vec_s16_t add_i0_b_0v = vec_adds(i00_v, mul_b_induc0_v); + + PREP_STORE8; + + for( i = 0; i < 8; ++i ) + { + vec_s16_t shift_0_v = vec_sra(add_i0_b_0v, val5_v); + vec_u8_t com_sat_v = vec_packsu(shift_0_v, shift_0_v); + VEC_STORE8(com_sat_v, &src[0]); + src += FDEC_STRIDE; + add_i0_b_0v = vec_adds(add_i0_b_0v, c_v); + + } +} + + /**************************************************************************** * 16x16 prediction for intra luma block ****************************************************************************/ @@ -72,7 +122,6 @@ static void predict_16x16_p_altivec( uint8_t *src ) vec_u8_t com_sat_v = vec_packsu(shift_0_v, shift_8_v); vec_st( com_sat_v, 0, &src[0]); src += FDEC_STRIDE; - i00 += c; add_i0_b_0v = vec_adds(add_i0_b_0v, c_v); add_i0_b_8v = vec_adds(add_i0_b_8v, c_v); } @@ -187,3 +236,8 @@ void x264_predict_16x16_init_altivec( x264_predict_t pf[7] ) pf[I_PRED_16x16_DC_TOP ] = predict_16x16_dc_top_altivec; pf[I_PRED_16x16_DC_128 ] = predict_16x16_dc_128_altivec; } + +void x264_predict_8x8c_init_altivec( x264_predict_t pf[7] ) +{ + pf[I_PRED_CHROMA_P] = predict_8x8c_p_altivec; +} diff --git a/common/ppc/predict.h b/common/ppc/predict.h index 90863b81..29488aae 100644 --- a/common/ppc/predict.h +++ b/common/ppc/predict.h @@ -22,5 +22,6 @@ #define X264_PPC_PREDICT_H void x264_predict_16x16_init_altivec ( x264_predict_t pf[7] ); +void x264_predict_8x8c_init_altivec( x264_predict_t pf[7] ); #endif /* X264_PPC_PREDICT_H */ diff --git a/common/predict.c b/common/predict.c index 9a66ed92..4fd4f060 100644 --- a/common/predict.c +++ b/common/predict.c @@ -786,6 +786,13 @@ void x264_predict_8x8c_init( int cpu, x264_predict_t pf[7] ) #ifdef HAVE_MMX x264_predict_8x8c_init_mmx( cpu, pf ); #endif + +#ifdef ARCH_PPC + if( cpu&X264_CPU_ALTIVEC ) + { + x264_predict_8x8c_init_altivec( pf ); + } +#endif } void x264_predict_8x8_init( int cpu, x264_predict8x8_t pf[12] ) -- 2.47.3