]> git.sesse.net Git - x264/blobdiff - common/predict.c
aarch64: Fix coeff_level_run* macros with LLVM's assembler
[x264] / common / predict.c
index fa71b6e630fcb1dadc5db4ca0ea6abae937773d0..c0f2a0becc1f8084d79011295f59d1702d104393 100644 (file)
@@ -1,11 +1,12 @@
 /*****************************************************************************
- * predict.c: h264 encoder
+ * predict.c: intra prediction
  *****************************************************************************
- * Copyright (C) 2003-2008 x264 project
+ * Copyright (C) 2003-2015 x264 project
  *
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
  *          Loren Merritt <lorenm@u.washington.edu>
  *          Fiona Glaser <fiona@x264.com>
+ *          Henrik Gramner <henrik@gramner.com>
  *
  * 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
@@ -20,6 +21,9 @@
  * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02111, USA.
+ *
+ * This program is also available under a commercial proprietary license.
+ * For more information, contact us at licensing@x264.com.
  *****************************************************************************/
 
 /* predict4x4 are inspired from ffmpeg h264 decoder */
 #if ARCH_ARM
 #   include "arm/predict.h"
 #endif
+#if ARCH_AARCH64
+#   include "aarch64/predict.h"
+#endif
+#if ARCH_MIPS
+#   include "mips/predict.h"
+#endif
 
 /****************************************************************************
  * 16x16 prediction for intra luma block
@@ -116,7 +126,7 @@ void x264_predict_16x16_v_c( pixel *src )
         src += FDEC_STRIDE;
     }
 }
-static void x264_predict_16x16_p_c( pixel *src )
+void x264_predict_16x16_p_c( pixel *src )
 {
     int H = 0, V = 0;
 
@@ -148,7 +158,7 @@ static void x264_predict_16x16_p_c( pixel *src )
 
 
 /****************************************************************************
- * 8x8 prediction for intra chroma block
+ * 8x8 prediction for intra chroma block (4:2:0)
  ****************************************************************************/
 
 static void x264_predict_8x8c_dc_128_c( pixel *src )
@@ -266,7 +276,7 @@ void x264_predict_8x8c_v_c( pixel *src )
         src += FDEC_STRIDE;
     }
 }
-static void x264_predict_8x8c_p_c( pixel *src )
+void x264_predict_8x8c_p_c( pixel *src )
 {
     int H = 0, V = 0;
 
@@ -294,6 +304,167 @@ static void x264_predict_8x8c_p_c( pixel *src )
     }
 }
 
+/****************************************************************************
+ * 8x16 prediction for intra chroma block (4:2:2)
+ ****************************************************************************/
+
+static void x264_predict_8x16c_dc_128_c( pixel *src )
+{
+    for( int y = 0; y < 16; y++ )
+    {
+        MPIXEL_X4( src+0 ) = PIXEL_SPLAT_X4( 1 << (BIT_DEPTH-1) );
+        MPIXEL_X4( src+4 ) = PIXEL_SPLAT_X4( 1 << (BIT_DEPTH-1) );
+        src += FDEC_STRIDE;
+    }
+}
+static void x264_predict_8x16c_dc_left_c( pixel *src )
+{
+    for( int i = 0; i < 4; i++ )
+    {
+        int dc = 0;
+
+        for( int y = 0; y < 4; y++ )
+            dc += src[y*FDEC_STRIDE - 1];
+
+        pixel4 dcsplat = PIXEL_SPLAT_X4( (dc + 2) >> 2 );
+
+        for( int y = 0; y < 4; y++ )
+        {
+            MPIXEL_X4( src+0 ) = dcsplat;
+            MPIXEL_X4( src+4 ) = dcsplat;
+            src += FDEC_STRIDE;
+        }
+    }
+}
+static void x264_predict_8x16c_dc_top_c( pixel *src )
+{
+    int dc0 = 0, dc1 = 0;
+
+    for(int  x = 0; x < 4; x++ )
+    {
+        dc0 += src[x     - FDEC_STRIDE];
+        dc1 += src[x + 4 - FDEC_STRIDE];
+    }
+    pixel4 dc0splat = PIXEL_SPLAT_X4( ( dc0 + 2 ) >> 2 );
+    pixel4 dc1splat = PIXEL_SPLAT_X4( ( dc1 + 2 ) >> 2 );
+
+    for( int y = 0; y < 16; y++ )
+    {
+        MPIXEL_X4( src+0 ) = dc0splat;
+        MPIXEL_X4( src+4 ) = dc1splat;
+        src += FDEC_STRIDE;
+    }
+}
+void x264_predict_8x16c_dc_c( pixel *src )
+{
+    int s0 = 0, s1 = 0, s2 = 0, s3 = 0, s4 = 0, s5 = 0;
+
+    /*
+          s0 s1
+       s2
+       s3
+       s4
+       s5
+    */
+    for( int i = 0; i < 4; i++ )
+    {
+        s0 += src[i+0 - FDEC_STRIDE];
+        s1 += src[i+4 - FDEC_STRIDE];
+        s2 += src[-1 + (i+0)  * FDEC_STRIDE];
+        s3 += src[-1 + (i+4)  * FDEC_STRIDE];
+        s4 += src[-1 + (i+8)  * FDEC_STRIDE];
+        s5 += src[-1 + (i+12) * FDEC_STRIDE];
+    }
+    /*
+       dc0 dc1
+       dc2 dc3
+       dc4 dc5
+       dc6 dc7
+    */
+    pixel4 dc0 = PIXEL_SPLAT_X4( ( s0 + s2 + 4 ) >> 3 );
+    pixel4 dc1 = PIXEL_SPLAT_X4( ( s1 + 2 ) >> 2 );
+    pixel4 dc2 = PIXEL_SPLAT_X4( ( s3 + 2 ) >> 2 );
+    pixel4 dc3 = PIXEL_SPLAT_X4( ( s1 + s3 + 4 ) >> 3 );
+    pixel4 dc4 = PIXEL_SPLAT_X4( ( s4 + 2 ) >> 2 );
+    pixel4 dc5 = PIXEL_SPLAT_X4( ( s1 + s4 + 4 ) >> 3 );
+    pixel4 dc6 = PIXEL_SPLAT_X4( ( s5 + 2 ) >> 2 );
+    pixel4 dc7 = PIXEL_SPLAT_X4( ( s1 + s5 + 4 ) >> 3 );
+
+    for( int y = 0; y < 4; y++ )
+    {
+        MPIXEL_X4( src+0 ) = dc0;
+        MPIXEL_X4( src+4 ) = dc1;
+        src += FDEC_STRIDE;
+    }
+    for( int y = 0; y < 4; y++ )
+    {
+        MPIXEL_X4( src+0 ) = dc2;
+        MPIXEL_X4( src+4 ) = dc3;
+        src += FDEC_STRIDE;
+    }
+    for( int y = 0; y < 4; y++ )
+    {
+        MPIXEL_X4( src+0 ) = dc4;
+        MPIXEL_X4( src+4 ) = dc5;
+        src += FDEC_STRIDE;
+    }
+    for( int y = 0; y < 4; y++ )
+    {
+        MPIXEL_X4( src+0 ) = dc6;
+        MPIXEL_X4( src+4 ) = dc7;
+        src += FDEC_STRIDE;
+    }
+}
+void x264_predict_8x16c_h_c( pixel *src )
+{
+    for( int i = 0; i < 16; i++ )
+    {
+        pixel4 v = PIXEL_SPLAT_X4( src[-1] );
+        MPIXEL_X4( src+0 ) = v;
+        MPIXEL_X4( src+4 ) = v;
+        src += FDEC_STRIDE;
+    }
+}
+void x264_predict_8x16c_v_c( pixel *src )
+{
+    pixel4 v0 = MPIXEL_X4( src+0-FDEC_STRIDE );
+    pixel4 v1 = MPIXEL_X4( src+4-FDEC_STRIDE );
+
+    for( int i = 0; i < 16; i++ )
+    {
+        MPIXEL_X4( src+0 ) = v0;
+        MPIXEL_X4( src+4 ) = v1;
+        src += FDEC_STRIDE;
+    }
+}
+void x264_predict_8x16c_p_c( pixel *src )
+{
+    int H = 0;
+    int V = 0;
+
+    for( int i = 0; i < 4; i++ )
+        H += ( i + 1 ) * ( src[4 + i - FDEC_STRIDE] - src[2 - i - FDEC_STRIDE] );
+    for( int i = 0; i < 8; i++ )
+        V += ( i + 1 ) * ( src[-1 + (i+8)*FDEC_STRIDE] - src[-1 + (6-i)*FDEC_STRIDE] );
+
+    int a = 16 * ( src[-1 + 15*FDEC_STRIDE] + src[7 - FDEC_STRIDE] );
+    int b = ( 17 * H + 16 ) >> 5;
+    int c = ( 5 * V + 32 ) >> 6;
+    int i00 = a -3*b -7*c + 16;
+
+    for( int y = 0; y < 16; y++ )
+    {
+        int pix = i00;
+        for( int x = 0; x < 8; x++ )
+        {
+            src[x] = x264_clip_pixel( pix>>5 );
+            pix += b;
+        }
+        src += FDEC_STRIDE;
+        i00 += c;
+    }
+}
+
 /****************************************************************************
  * 4x4 prediction for intra luma block
  ****************************************************************************/
@@ -455,7 +626,7 @@ static void x264_predict_4x4_hu_c( pixel *src )
 #define PT(x) \
     edge[16+x] = F2(SRC(x-1,-1), SRC(x,-1), SRC(x+1,-1));
 
-static void x264_predict_8x8_filter_c( pixel *src, pixel edge[33], int i_neighbor, int i_filters )
+static void x264_predict_8x8_filter_c( pixel *src, pixel edge[36], int i_neighbor, int i_filters )
 {
     /* edge[7..14] = l7..l0
      * edge[15] = lt
@@ -469,6 +640,7 @@ static void x264_predict_8x8_filter_c( pixel *src, pixel edge[33], int i_neighbo
         edge[14] = ((have_lt ? SRC(-1,-1) : SRC(-1,0))
                  + 2*SRC(-1,0) + SRC(-1,1) + 2) >> 2;
         PL(1) PL(2) PL(3) PL(4) PL(5) PL(6)
+        edge[6] =
         edge[7] = (SRC(-1,6) + 3*SRC(-1,7) + 2) >> 2;
     }
 
@@ -522,30 +694,30 @@ static void x264_predict_8x8_filter_c( pixel *src, pixel edge[33], int i_neighbo
         src += FDEC_STRIDE; \
     }
 
-static void x264_predict_8x8_dc_128_c( pixel *src, pixel edge[33] )
+static void x264_predict_8x8_dc_128_c( pixel *src, pixel edge[36] )
 {
     PREDICT_8x8_DC( PIXEL_SPLAT_X4( 1 << (BIT_DEPTH-1) ) );
 }
-static void x264_predict_8x8_dc_left_c( pixel *src, pixel edge[33] )
+static void x264_predict_8x8_dc_left_c( pixel *src, pixel edge[36] )
 {
     PREDICT_8x8_LOAD_LEFT
     pixel4 dc = PIXEL_SPLAT_X4( (l0+l1+l2+l3+l4+l5+l6+l7+4) >> 3 );
     PREDICT_8x8_DC( dc );
 }
-static void x264_predict_8x8_dc_top_c( pixel *src, pixel edge[33] )
+static void x264_predict_8x8_dc_top_c( pixel *src, pixel edge[36] )
 {
     PREDICT_8x8_LOAD_TOP
     pixel4 dc = PIXEL_SPLAT_X4( (t0+t1+t2+t3+t4+t5+t6+t7+4) >> 3 );
     PREDICT_8x8_DC( dc );
 }
-void x264_predict_8x8_dc_c( pixel *src, pixel edge[33] )
+void x264_predict_8x8_dc_c( pixel *src, pixel edge[36] )
 {
     PREDICT_8x8_LOAD_LEFT
     PREDICT_8x8_LOAD_TOP
     pixel4 dc = PIXEL_SPLAT_X4( (l0+l1+l2+l3+l4+l5+l6+l7+t0+t1+t2+t3+t4+t5+t6+t7+8) >> 4 );
     PREDICT_8x8_DC( dc );
 }
-void x264_predict_8x8_h_c( pixel *src, pixel edge[33] )
+void x264_predict_8x8_h_c( pixel *src, pixel edge[36] )
 {
     PREDICT_8x8_LOAD_LEFT
 #define ROW(y) MPIXEL_X4( src+y*FDEC_STRIDE+0 ) =\
@@ -553,7 +725,7 @@ void x264_predict_8x8_h_c( pixel *src, pixel edge[33] )
     ROW(0); ROW(1); ROW(2); ROW(3); ROW(4); ROW(5); ROW(6); ROW(7);
 #undef ROW
 }
-void x264_predict_8x8_v_c( pixel *src, pixel edge[33] )
+void x264_predict_8x8_v_c( pixel *src, pixel edge[36] )
 {
     pixel4 top[2] = { MPIXEL_X4( edge+16 ),
                       MPIXEL_X4( edge+20 ) };
@@ -563,7 +735,7 @@ void x264_predict_8x8_v_c( pixel *src, pixel edge[33] )
         MPIXEL_X4( src+y*FDEC_STRIDE+4 ) = top[1];
     }
 }
-static void x264_predict_8x8_ddl_c( pixel *src, pixel edge[33] )
+static void x264_predict_8x8_ddl_c( pixel *src, pixel edge[36] )
 {
     PREDICT_8x8_LOAD_TOP
     PREDICT_8x8_LOAD_TOPRIGHT
@@ -583,7 +755,7 @@ static void x264_predict_8x8_ddl_c( pixel *src, pixel edge[33] )
     SRC(6,7)=SRC(7,6)= F2(t13,t14,t15);
     SRC(7,7)= F2(t14,t15,t15);
 }
-static void x264_predict_8x8_ddr_c( pixel *src, pixel edge[33] )
+static void x264_predict_8x8_ddr_c( pixel *src, pixel edge[36] )
 {
     PREDICT_8x8_LOAD_TOP
     PREDICT_8x8_LOAD_LEFT
@@ -605,7 +777,7 @@ static void x264_predict_8x8_ddr_c( pixel *src, pixel edge[33] )
     SRC(7,0)= F2(t5,t6,t7);
 
 }
-static void x264_predict_8x8_vr_c( pixel *src, pixel edge[33] )
+static void x264_predict_8x8_vr_c( pixel *src, pixel edge[36] )
 {
     PREDICT_8x8_LOAD_TOP
     PREDICT_8x8_LOAD_LEFT
@@ -633,7 +805,7 @@ static void x264_predict_8x8_vr_c( pixel *src, pixel edge[33] )
     SRC(7,1)= F2(t5,t6,t7);
     SRC(7,0)= F1(t6,t7);
 }
-static void x264_predict_8x8_hd_c( pixel *src, pixel edge[33] )
+static void x264_predict_8x8_hd_c( pixel *src, pixel edge[36] )
 {
     PREDICT_8x8_LOAD_TOP
     PREDICT_8x8_LOAD_LEFT
@@ -660,7 +832,7 @@ static void x264_predict_8x8_hd_c( pixel *src, pixel edge[33] )
     SRC_X4(4,1)= pack_pixel_2to4(p9,p10);
     SRC_X4(4,0)= pack_pixel_2to4(p10,p11);
 }
-static void x264_predict_8x8_vl_c( pixel *src, pixel edge[33] )
+static void x264_predict_8x8_vl_c( pixel *src, pixel edge[36] )
 {
     PREDICT_8x8_LOAD_TOP
     PREDICT_8x8_LOAD_TOPRIGHT
@@ -687,7 +859,7 @@ static void x264_predict_8x8_vl_c( pixel *src, pixel edge[33] )
     SRC(7,6)= F1(t10,t11);
     SRC(7,7)= F2(t10,t11,t12);
 }
-static void x264_predict_8x8_hu_c( pixel *src, pixel edge[33] )
+static void x264_predict_8x8_hu_c( pixel *src, pixel edge[36] )
 {
     PREDICT_8x8_LOAD_LEFT
     int p1 = pack_pixel_1to2(F1(l0,l1), F2(l0,l1,l2));
@@ -733,6 +905,25 @@ void x264_predict_16x16_init( int cpu, x264_predict_t pf[7] )
 #if HAVE_ARMV6
     x264_predict_16x16_init_arm( cpu, pf );
 #endif
+
+#if ARCH_AARCH64
+    x264_predict_16x16_init_aarch64( cpu, pf );
+#endif
+
+#if !HIGH_BIT_DEPTH
+#if HAVE_MSA
+    if( cpu&X264_CPU_MSA )
+    {
+        pf[I_PRED_16x16_V ]     = x264_intra_predict_vert_16x16_msa;
+        pf[I_PRED_16x16_H ]     = x264_intra_predict_hor_16x16_msa;
+        pf[I_PRED_16x16_DC]     = x264_intra_predict_dc_16x16_msa;
+        pf[I_PRED_16x16_P ]     = x264_intra_predict_plane_16x16_msa;
+        pf[I_PRED_16x16_DC_LEFT]= x264_intra_predict_dc_left_16x16_msa;
+        pf[I_PRED_16x16_DC_TOP ]= x264_intra_predict_dc_top_16x16_msa;
+        pf[I_PRED_16x16_DC_128 ]= x264_intra_predict_dc_128_16x16_msa;
+    }
+#endif
+#endif
 }
 
 void x264_predict_8x8c_init( int cpu, x264_predict_t pf[7] )
@@ -757,6 +948,38 @@ void x264_predict_8x8c_init( int cpu, x264_predict_t pf[7] )
 #if HAVE_ARMV6
     x264_predict_8x8c_init_arm( cpu, pf );
 #endif
+
+#if ARCH_AARCH64
+    x264_predict_8x8c_init_aarch64( cpu, pf );
+#endif
+
+#if !HIGH_BIT_DEPTH
+#if HAVE_MSA
+    if( cpu&X264_CPU_MSA )
+    {
+        pf[I_PRED_CHROMA_P ]     = x264_intra_predict_plane_8x8_msa;
+    }
+#endif
+#endif
+}
+
+void x264_predict_8x16c_init( int cpu, x264_predict_t pf[7] )
+{
+    pf[I_PRED_CHROMA_V ]     = x264_predict_8x16c_v_c;
+    pf[I_PRED_CHROMA_H ]     = x264_predict_8x16c_h_c;
+    pf[I_PRED_CHROMA_DC]     = x264_predict_8x16c_dc_c;
+    pf[I_PRED_CHROMA_P ]     = x264_predict_8x16c_p_c;
+    pf[I_PRED_CHROMA_DC_LEFT]= x264_predict_8x16c_dc_left_c;
+    pf[I_PRED_CHROMA_DC_TOP ]= x264_predict_8x16c_dc_top_c;
+    pf[I_PRED_CHROMA_DC_128 ]= x264_predict_8x16c_dc_128_c;
+
+#if HAVE_MMX
+    x264_predict_8x16c_init_mmx( cpu, pf );
+#endif
+
+#if ARCH_AARCH64
+    x264_predict_8x16c_init_aarch64( cpu, pf );
+#endif
 }
 
 void x264_predict_8x8_init( int cpu, x264_predict8x8_t pf[12], x264_predict_8x8_filter_t *predict_filter )
@@ -782,6 +1005,19 @@ void x264_predict_8x8_init( int cpu, x264_predict8x8_t pf[12], x264_predict_8x8_
 #if HAVE_ARMV6
     x264_predict_8x8_init_arm( cpu, pf, predict_filter );
 #endif
+
+#if ARCH_AARCH64
+    x264_predict_8x8_init_aarch64( cpu, pf, predict_filter );
+#endif
+
+#if !HIGH_BIT_DEPTH
+#if HAVE_MSA
+    if( cpu&X264_CPU_MSA )
+    {
+        pf[I_PRED_8x8_DDL]    = x264_intra_predict_ddl_8x8_msa;
+    }
+#endif
+#endif
 }
 
 void x264_predict_4x4_init( int cpu, x264_predict_t pf[12] )
@@ -806,5 +1042,9 @@ void x264_predict_4x4_init( int cpu, x264_predict_t pf[12] )
 #if HAVE_ARMV6
     x264_predict_4x4_init_arm( cpu, pf );
 #endif
+
+#if ARCH_AARCH64
+    x264_predict_4x4_init_aarch64( cpu, pf );
+#endif
 }