From 795c3c1c2a4f5d4d2ef9025583a21ab400439fa6 Mon Sep 17 00:00:00 2001 From: Guillaume Poirier Date: Sun, 9 Dec 2007 15:50:52 +0000 Subject: [PATCH] adds AliVec implementation of predict_16x16_p() over 4x faster than C version git-svn-id: svn://svn.videolan.org/x264/trunk@710 df754926-b1dd-0310-bc7b-ec298dee348c --- Makefile | 3 +- common/ppc/ppccommon.h | 5 +++ common/ppc/predict.c | 90 ++++++++++++++++++++++++++++++++++++++++++ common/ppc/predict.h | 28 +++++++++++++ common/predict.c | 10 +++++ 5 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 common/ppc/predict.c create mode 100644 common/ppc/predict.h diff --git a/Makefile b/Makefile index e0c6f107..63338e8f 100644 --- a/Makefile +++ b/Makefile @@ -48,7 +48,8 @@ endif # AltiVec optims ifeq ($(ARCH),PPC) ALTIVECSRC += common/ppc/mc.c common/ppc/pixel.c common/ppc/dct.c \ - common/ppc/quant.c common/ppc/deblock.c + common/ppc/quant.c common/ppc/deblock.c \ + common/ppc/predict.c SRCS += $(ALTIVECSRC) $(ALTIVECSRC:%.c=%.o): CFLAGS += $(ALTIVECFLAGS) endif diff --git a/common/ppc/ppccommon.h b/common/ppc/ppccommon.h index a4cb9e36..d3c691b9 100644 --- a/common/ppc/ppccommon.h +++ b/common/ppc/ppccommon.h @@ -50,6 +50,11 @@ typedef union { vector unsigned short v; } vect_ushort_u; +typedef union { + signed short s[8]; + vector signed short v; +} vect_sshort_u; + /*********************************************************************** * Null vector **********************************************************************/ diff --git a/common/ppc/predict.c b/common/ppc/predict.c new file mode 100644 index 00000000..5616e8a2 --- /dev/null +++ b/common/ppc/predict.c @@ -0,0 +1,90 @@ +/***************************************************************************** + * predict.c: h264 encoder + ***************************************************************************** + * Copyright (C) 2007 Guillaume POIRIER + * + * Authors: Guillaume POIRIER + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. + *****************************************************************************/ + +#ifdef SYS_LINUX +#include +#endif + +#include "common/common.h" +#include "common/clip1.h" +#include "predict.h" +#include "pixel.h" +#include "ppccommon.h" + +static void predict_16x16_p_altivec( uint8_t *src ) +{ + int16_t a, b, c, i; + int H = 0; + int V = 0; + int16_t i00; + + for( i = 1; i <= 8; i++ ) + { + H += i * ( src[7+i - FDEC_STRIDE ] - src[7-i - FDEC_STRIDE ] ); + V += i * ( src[(7+i)*FDEC_STRIDE -1] - src[(7-i)*FDEC_STRIDE -1] ); + } + + a = 16 * ( src[15*FDEC_STRIDE -1] + src[15 - FDEC_STRIDE] ); + b = ( 5 * H + 32 ) >> 6; + c = ( 5 * V + 32 ) >> 6; + i00 = a - b * 7 - c * 7 + 16; + + vect_sshort_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_s16_t b8_v = vec_sl(b_v, vec_splat_u16(3)); + 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); + vec_s16_t add_i0_b_8v = vec_adds(b8_v, add_i0_b_0v); + + int y; + + for( y = 0; y < 16; y++ ) + { + vec_s16_t shift_0_v = vec_sra(add_i0_b_0v, val5_v); + vec_s16_t shift_8_v = vec_sra(add_i0_b_8v, val5_v); + 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); + } +} + +/**************************************************************************** + * Exported functions: + ****************************************************************************/ +void x264_predict_16x16_init_altivec( x264_predict_t pf[7] ) +{ + pf[I_PRED_16x16_P] = predict_16x16_p_altivec; +} diff --git a/common/ppc/predict.h b/common/ppc/predict.h new file mode 100644 index 00000000..d78d0169 --- /dev/null +++ b/common/ppc/predict.h @@ -0,0 +1,28 @@ +/***************************************************************************** + * predict.h: h264 encoder library + ***************************************************************************** + * Copyright (C) 2007 Guillaume POIRIER + * + * Authors: Guillaume POIRIER + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. + *****************************************************************************/ + +#ifndef _ALTIVEC_PREDICT_H +#define _ALTIVEC_PREDICT_H 1 + +void x264_predict_16x16_init_altivec ( x264_predict_t pf[7] ); + +#endif // _ALTIVEC_PREDICT_H diff --git a/common/predict.c b/common/predict.c index 870508c4..1c5b5a97 100644 --- a/common/predict.c +++ b/common/predict.c @@ -34,6 +34,9 @@ #ifdef HAVE_MMX # include "i386/predict.h" #endif +#ifdef ARCH_PPC +# include "ppc/predict.h" +#endif /**************************************************************************** * 16x16 prediction for intra luma block @@ -849,6 +852,13 @@ void x264_predict_16x16_init( int cpu, x264_predict_t pf[7] ) x264_predict_16x16_init_mmxext( pf ); } #endif + +#ifdef ARCH_PPC + if( cpu&X264_CPU_ALTIVEC ) + { + x264_predict_16x16_init_altivec( pf ); + } +#endif } void x264_predict_8x8c_init( int cpu, x264_predict_t pf[7] ) -- 2.47.3