]> granicus.if.org Git - libx264/commitdiff
adds AliVec implementation of predict_16x16_p()
authorGuillaume Poirier <gpoirier@mplayerhq.hu>
Sun, 9 Dec 2007 15:50:52 +0000 (15:50 +0000)
committerGuillaume Poirier <gpoirier@mplayerhq.hu>
Sun, 9 Dec 2007 15:50:52 +0000 (15:50 +0000)
over 4x faster than C version

git-svn-id: svn://svn.videolan.org/x264/trunk@710 df754926-b1dd-0310-bc7b-ec298dee348c

Makefile
common/ppc/ppccommon.h
common/ppc/predict.c [new file with mode: 0644]
common/ppc/predict.h [new file with mode: 0644]
common/predict.c

index e0c6f107bd2d86f1e8651a31c41317fba0b05a13..63338e8fa2bec660d9e58f0d77a8a7e6b1b16960 100644 (file)
--- 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
index a4cb9e36a1f018e9b694912942ea04ab404fa5a5..d3c691b90b5e87f423e9095c591eb8109cb39fa2 100644 (file)
@@ -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 (file)
index 0000000..5616e8a
--- /dev/null
@@ -0,0 +1,90 @@
+/*****************************************************************************
+ * predict.c: h264 encoder
+ *****************************************************************************
+ * Copyright (C) 2007 Guillaume POIRIER
+ *
+ * Authors: Guillaume POIRIER <gpoirier CHEZ mplayerhq POIS hu>
+ *
+ * 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 <altivec.h>
+#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 (file)
index 0000000..d78d016
--- /dev/null
@@ -0,0 +1,28 @@
+/*****************************************************************************
+ * predict.h: h264 encoder library
+ *****************************************************************************
+ * Copyright (C) 2007 Guillaume POIRIER
+ *
+ * Authors: Guillaume POIRIER <gpoirier CHEZ mplayerhq POIS hu>
+ *
+ * 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
index 870508c488317f6607b87c1deb2362bbfe1a621b..1c5b5a97609d13cfbb722b2f28ef563fb56f6916 100644 (file)
@@ -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] )