]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/h264pred_template.c
lavc: move SANE_NB_CHANNELS to internal.h and use it in the PCM decoders
[ffmpeg] / libavcodec / h264pred_template.c
index 4bd26e289249ae5d22476e5e0e7c6968ce859366..8ae13b0df7898ac03919566c4ee60acedf9dcef8 100644 (file)
  */
 
 #include "mathops.h"
-#include "dsputil.h"
 
-#define BIT_DEPTH 8
+#include "bit_depth_template.c"
 
-#define pixel uint8_t
-#define pixel4 uint32_t
-#define dctcoef DCTELEM
-
-#define INIT_CLIP uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
-#define CLIP(a) cm[a]
-#define FUNC(a) a
-#define FUNCC(a) a ## _c
-#define PIXEL_SPLAT_X4(x) ((x)*0x01010101U)
-#define AV_WN4P  AV_WN32
-#define AV_WN4PA AV_WN32A
-
-static void FUNCC(pred4x4_vertical)(uint8_t *_src, const uint8_t *topright, int _stride){
+static void FUNCC(pred4x4_vertical)(uint8_t *_src, const uint8_t *topright,
+                                    ptrdiff_t _stride)
+{
     pixel *src = (pixel*)_src;
     int stride = _stride/sizeof(pixel);
-    const pixel4 a= ((pixel4*)(src-stride))[0];
-    ((pixel4*)(src+0*stride))[0]= a;
-    ((pixel4*)(src+1*stride))[0]= a;
-    ((pixel4*)(src+2*stride))[0]= a;
-    ((pixel4*)(src+3*stride))[0]= a;
+    const pixel4 a= AV_RN4PA(src-stride);
+
+    AV_WN4PA(src+0*stride, a);
+    AV_WN4PA(src+1*stride, a);
+    AV_WN4PA(src+2*stride, a);
+    AV_WN4PA(src+3*stride, a);
 }
 
-static void FUNCC(pred4x4_horizontal)(uint8_t *_src, const uint8_t *topright, int _stride){
+static void FUNCC(pred4x4_horizontal)(uint8_t *_src, const uint8_t *topright,
+                                      ptrdiff_t _stride)
+{
     pixel *src = (pixel*)_src;
     int stride = _stride/sizeof(pixel);
-    ((pixel4*)(src+0*stride))[0]= PIXEL_SPLAT_X4(src[-1+0*stride]);
-    ((pixel4*)(src+1*stride))[0]= PIXEL_SPLAT_X4(src[-1+1*stride]);
-    ((pixel4*)(src+2*stride))[0]= PIXEL_SPLAT_X4(src[-1+2*stride]);
-    ((pixel4*)(src+3*stride))[0]= PIXEL_SPLAT_X4(src[-1+3*stride]);
+    AV_WN4PA(src+0*stride, PIXEL_SPLAT_X4(src[-1+0*stride]));
+    AV_WN4PA(src+1*stride, PIXEL_SPLAT_X4(src[-1+1*stride]));
+    AV_WN4PA(src+2*stride, PIXEL_SPLAT_X4(src[-1+2*stride]));
+    AV_WN4PA(src+3*stride, PIXEL_SPLAT_X4(src[-1+3*stride]));
 }
 
-static void FUNCC(pred4x4_dc)(uint8_t *_src, const uint8_t *topright, int _stride){
+static void FUNCC(pred4x4_dc)(uint8_t *_src, const uint8_t *topright,
+                              ptrdiff_t _stride)
+{
     pixel *src = (pixel*)_src;
     int stride = _stride/sizeof(pixel);
     const int dc= (  src[-stride] + src[1-stride] + src[2-stride] + src[3-stride]
                    + src[-1+0*stride] + src[-1+1*stride] + src[-1+2*stride] + src[-1+3*stride] + 4) >>3;
+    const pixel4 a = PIXEL_SPLAT_X4(dc);
 
-    ((pixel4*)(src+0*stride))[0]=
-    ((pixel4*)(src+1*stride))[0]=
-    ((pixel4*)(src+2*stride))[0]=
-    ((pixel4*)(src+3*stride))[0]= PIXEL_SPLAT_X4(dc);
+    AV_WN4PA(src+0*stride, a);
+    AV_WN4PA(src+1*stride, a);
+    AV_WN4PA(src+2*stride, a);
+    AV_WN4PA(src+3*stride, a);
 }
 
-static void FUNCC(pred4x4_left_dc)(uint8_t *_src, const uint8_t *topright, int _stride){
+static void FUNCC(pred4x4_left_dc)(uint8_t *_src, const uint8_t *topright,
+                                   ptrdiff_t _stride)
+{
     pixel *src = (pixel*)_src;
     int stride = _stride/sizeof(pixel);
     const int dc= (  src[-1+0*stride] + src[-1+1*stride] + src[-1+2*stride] + src[-1+3*stride] + 2) >>2;
+    const pixel4 a = PIXEL_SPLAT_X4(dc);
 
-    ((pixel4*)(src+0*stride))[0]=
-    ((pixel4*)(src+1*stride))[0]=
-    ((pixel4*)(src+2*stride))[0]=
-    ((pixel4*)(src+3*stride))[0]= PIXEL_SPLAT_X4(dc);
+    AV_WN4PA(src+0*stride, a);
+    AV_WN4PA(src+1*stride, a);
+    AV_WN4PA(src+2*stride, a);
+    AV_WN4PA(src+3*stride, a);
 }
 
-static void FUNCC(pred4x4_top_dc)(uint8_t *_src, const uint8_t *topright, int _stride){
+static void FUNCC(pred4x4_top_dc)(uint8_t *_src, const uint8_t *topright,
+                                  ptrdiff_t _stride)
+{
     pixel *src = (pixel*)_src;
     int stride = _stride/sizeof(pixel);
     const int dc= (  src[-stride] + src[1-stride] + src[2-stride] + src[3-stride] + 2) >>2;
+    const pixel4 a = PIXEL_SPLAT_X4(dc);
 
-    ((pixel4*)(src+0*stride))[0]=
-    ((pixel4*)(src+1*stride))[0]=
-    ((pixel4*)(src+2*stride))[0]=
-    ((pixel4*)(src+3*stride))[0]= PIXEL_SPLAT_X4(dc);
+    AV_WN4PA(src+0*stride, a);
+    AV_WN4PA(src+1*stride, a);
+    AV_WN4PA(src+2*stride, a);
+    AV_WN4PA(src+3*stride, a);
 }
 
-static void FUNCC(pred4x4_128_dc)(uint8_t *_src, const uint8_t *topright, int _stride){
+static void FUNCC(pred4x4_128_dc)(uint8_t *_src, const uint8_t *topright,
+                                  ptrdiff_t _stride)
+{
     pixel *src = (pixel*)_src;
     int stride = _stride/sizeof(pixel);
-    ((pixel4*)(src+0*stride))[0]=
-    ((pixel4*)(src+1*stride))[0]=
-    ((pixel4*)(src+2*stride))[0]=
-    ((pixel4*)(src+3*stride))[0]= PIXEL_SPLAT_X4(1<<(BIT_DEPTH-1));
+    const pixel4 a = PIXEL_SPLAT_X4(1<<(BIT_DEPTH-1));
+
+    AV_WN4PA(src+0*stride, a);
+    AV_WN4PA(src+1*stride, a);
+    AV_WN4PA(src+2*stride, a);
+    AV_WN4PA(src+3*stride, a);
 }
 
-static void FUNCC(pred4x4_127_dc)(uint8_t *_src, const uint8_t *topright, int _stride){
+static void FUNCC(pred4x4_127_dc)(uint8_t *_src, const uint8_t *topright,
+                                  ptrdiff_t _stride)
+{
     pixel *src = (pixel*)_src;
     int stride = _stride/sizeof(pixel);
-    ((pixel4*)(src+0*stride))[0]=
-    ((pixel4*)(src+1*stride))[0]=
-    ((pixel4*)(src+2*stride))[0]=
-    ((pixel4*)(src+3*stride))[0]= PIXEL_SPLAT_X4((1<<(BIT_DEPTH-1))-1);
+    const pixel4 a = PIXEL_SPLAT_X4((1<<(BIT_DEPTH-1))-1);
+
+    AV_WN4PA(src+0*stride, a);
+    AV_WN4PA(src+1*stride, a);
+    AV_WN4PA(src+2*stride, a);
+    AV_WN4PA(src+3*stride, a);
 }
 
-static void FUNCC(pred4x4_129_dc)(uint8_t *_src, const uint8_t *topright, int _stride){
+static void FUNCC(pred4x4_129_dc)(uint8_t *_src, const uint8_t *topright,
+                                  ptrdiff_t _stride)
+{
     pixel *src = (pixel*)_src;
     int stride = _stride/sizeof(pixel);
-    ((pixel4*)(src+0*stride))[0]=
-    ((pixel4*)(src+1*stride))[0]=
-    ((pixel4*)(src+2*stride))[0]=
-    ((pixel4*)(src+3*stride))[0]= PIXEL_SPLAT_X4((1<<(BIT_DEPTH-1))+1);
+    const pixel4 a = PIXEL_SPLAT_X4((1<<(BIT_DEPTH-1))+1);
+
+    AV_WN4PA(src+0*stride, a);
+    AV_WN4PA(src+1*stride, a);
+    AV_WN4PA(src+2*stride, a);
+    AV_WN4PA(src+3*stride, a);
 }
 
 
 #define LOAD_TOP_RIGHT_EDGE\
-    const int av_unused t4= topright[0];\
-    const int av_unused t5= topright[1];\
-    const int av_unused t6= topright[2];\
-    const int av_unused t7= topright[3];\
+    const unsigned av_unused t4 = topright[0];\
+    const unsigned av_unused t5 = topright[1];\
+    const unsigned av_unused t6 = topright[2];\
+    const unsigned av_unused t7 = topright[3];\
 
 #define LOAD_DOWN_LEFT_EDGE\
-    const int av_unused l4= src[-1+4*stride];\
-    const int av_unused l5= src[-1+5*stride];\
-    const int av_unused l6= src[-1+6*stride];\
-    const int av_unused l7= src[-1+7*stride];\
+    const unsigned av_unused l4 = src[-1+4*stride];\
+    const unsigned av_unused l5 = src[-1+5*stride];\
+    const unsigned av_unused l6 = src[-1+6*stride];\
+    const unsigned av_unused l7 = src[-1+7*stride];\
 
 #define LOAD_LEFT_EDGE\
-    const int av_unused l0= src[-1+0*stride];\
-    const int av_unused l1= src[-1+1*stride];\
-    const int av_unused l2= src[-1+2*stride];\
-    const int av_unused l3= src[-1+3*stride];\
+    const unsigned av_unused l0 = src[-1+0*stride];\
+    const unsigned av_unused l1 = src[-1+1*stride];\
+    const unsigned av_unused l2 = src[-1+2*stride];\
+    const unsigned av_unused l3 = src[-1+3*stride];\
 
 #define LOAD_TOP_EDGE\
-    const int av_unused t0= src[ 0-1*stride];\
-    const int av_unused t1= src[ 1-1*stride];\
-    const int av_unused t2= src[ 2-1*stride];\
-    const int av_unused t3= src[ 3-1*stride];\
+    const unsigned av_unused t0 = src[ 0-1*stride];\
+    const unsigned av_unused t1 = src[ 1-1*stride];\
+    const unsigned av_unused t2 = src[ 2-1*stride];\
+    const unsigned av_unused t3 = src[ 3-1*stride];\
 
-static void FUNCC(pred4x4_down_right)(uint8_t *_src, const uint8_t *topright, int _stride){
+static void FUNCC(pred4x4_down_right)(uint8_t *_src, const uint8_t *topright,
+                                      ptrdiff_t _stride)
+{
     pixel *src = (pixel*)_src;
     int stride = _stride/sizeof(pixel);
     const int lt= src[-1-1*stride];
@@ -172,7 +187,9 @@ static void FUNCC(pred4x4_down_right)(uint8_t *_src, const uint8_t *topright, in
     src[3+0*stride]=(t1 + 2*t2 + t3 + 2)>>2;
 }
 
-static void FUNCC(pred4x4_down_left)(uint8_t *_src, const uint8_t *_topright, int _stride){
+static void FUNCC(pred4x4_down_left)(uint8_t *_src, const uint8_t *_topright,
+                                     ptrdiff_t _stride)
+{
     pixel *src = (pixel*)_src;
     const pixel *topright = (const pixel*)_topright;
     int stride = _stride/sizeof(pixel);
@@ -198,7 +215,10 @@ static void FUNCC(pred4x4_down_left)(uint8_t *_src, const uint8_t *_topright, in
     src[3+3*stride]=(t6 + 3*t7 + 2)>>2;
 }
 
-static void FUNCC(pred4x4_vertical_right)(uint8_t *_src, const uint8_t *topright, int _stride){
+static void FUNCC(pred4x4_vertical_right)(uint8_t *_src,
+                                          const uint8_t *topright,
+                                          ptrdiff_t _stride)
+{
     pixel *src = (pixel*)_src;
     int stride = _stride/sizeof(pixel);
     const int lt= src[-1-1*stride];
@@ -223,7 +243,10 @@ static void FUNCC(pred4x4_vertical_right)(uint8_t *_src, const uint8_t *topright
     src[0+3*stride]=(l0 + 2*l1 + l2 + 2)>>2;
 }
 
-static void FUNCC(pred4x4_vertical_left)(uint8_t *_src, const uint8_t *_topright, int _stride){
+static void FUNCC(pred4x4_vertical_left)(uint8_t *_src,
+                                         const uint8_t *_topright,
+                                         ptrdiff_t _stride)
+{
     pixel *src = (pixel*)_src;
     const pixel *topright = (const pixel*)_topright;
     int stride = _stride/sizeof(pixel);
@@ -248,7 +271,9 @@ static void FUNCC(pred4x4_vertical_left)(uint8_t *_src, const uint8_t *_topright
     src[3+3*stride]=(t4 + 2*t5 + t6 + 2)>>2;
 }
 
-static void FUNCC(pred4x4_horizontal_up)(uint8_t *_src, const uint8_t *topright, int _stride){
+static void FUNCC(pred4x4_horizontal_up)(uint8_t *_src, const uint8_t *topright,
+                                         ptrdiff_t _stride)
+{
     pixel *src = (pixel*)_src;
     int stride = _stride/sizeof(pixel);
     LOAD_LEFT_EDGE
@@ -271,7 +296,10 @@ static void FUNCC(pred4x4_horizontal_up)(uint8_t *_src, const uint8_t *topright,
     src[3+3*stride]=l3;
 }
 
-static void FUNCC(pred4x4_horizontal_down)(uint8_t *_src, const uint8_t *topright, int _stride){
+static void FUNCC(pred4x4_horizontal_down)(uint8_t *_src,
+                                           const uint8_t *topright,
+                                           ptrdiff_t _stride)
+{
     pixel *src = (pixel*)_src;
     int stride = _stride/sizeof(pixel);
     const int lt= src[-1-1*stride];
@@ -296,46 +324,51 @@ static void FUNCC(pred4x4_horizontal_down)(uint8_t *_src, const uint8_t *toprigh
     src[1+3*stride]=(l1 + 2*l2 + l3 + 2)>>2;
 }
 
-static void FUNCC(pred16x16_vertical)(uint8_t *_src, int _stride){
+static void FUNCC(pred16x16_vertical)(uint8_t *_src, ptrdiff_t _stride)
+{
     int i;
     pixel *src = (pixel*)_src;
     int stride = _stride/sizeof(pixel);
-    const pixel4 a = ((pixel4*)(src-stride))[0];
-    const pixel4 b = ((pixel4*)(src-stride))[1];
-    const pixel4 c = ((pixel4*)(src-stride))[2];
-    const pixel4 d = ((pixel4*)(src-stride))[3];
+    const pixel4 a = AV_RN4PA(((pixel4*)(src-stride))+0);
+    const pixel4 b = AV_RN4PA(((pixel4*)(src-stride))+1);
+    const pixel4 c = AV_RN4PA(((pixel4*)(src-stride))+2);
+    const pixel4 d = AV_RN4PA(((pixel4*)(src-stride))+3);
 
     for(i=0; i<16; i++){
-        ((pixel4*)(src+i*stride))[0] = a;
-        ((pixel4*)(src+i*stride))[1] = b;
-        ((pixel4*)(src+i*stride))[2] = c;
-        ((pixel4*)(src+i*stride))[3] = d;
+        AV_WN4PA(((pixel4*)(src+i*stride))+0, a);
+        AV_WN4PA(((pixel4*)(src+i*stride))+1, b);
+        AV_WN4PA(((pixel4*)(src+i*stride))+2, c);
+        AV_WN4PA(((pixel4*)(src+i*stride))+3, d);
     }
 }
 
-static void FUNCC(pred16x16_horizontal)(uint8_t *_src, int stride){
+static void FUNCC(pred16x16_horizontal)(uint8_t *_src, ptrdiff_t stride)
+{
     int i;
     pixel *src = (pixel*)_src;
     stride /= sizeof(pixel);
 
     for(i=0; i<16; i++){
-        ((pixel4*)(src+i*stride))[0] =
-        ((pixel4*)(src+i*stride))[1] =
-        ((pixel4*)(src+i*stride))[2] =
-        ((pixel4*)(src+i*stride))[3] = PIXEL_SPLAT_X4(src[-1+i*stride]);
+        const pixel4 a = PIXEL_SPLAT_X4(src[-1+i*stride]);
+
+        AV_WN4PA(((pixel4*)(src+i*stride))+0, a);
+        AV_WN4PA(((pixel4*)(src+i*stride))+1, a);
+        AV_WN4PA(((pixel4*)(src+i*stride))+2, a);
+        AV_WN4PA(((pixel4*)(src+i*stride))+3, a);
     }
 }
 
 #define PREDICT_16x16_DC(v)\
     for(i=0; i<16; i++){\
-        AV_WN4P(src+ 0, v);\
-        AV_WN4P(src+ 4, v);\
-        AV_WN4P(src+ 8, v);\
-        AV_WN4P(src+12, v);\
+        AV_WN4PA(src+ 0, v);\
+        AV_WN4PA(src+ 4, v);\
+        AV_WN4PA(src+ 8, v);\
+        AV_WN4PA(src+12, v);\
         src += stride;\
     }
 
-static void FUNCC(pred16x16_dc)(uint8_t *_src, int stride){
+static void FUNCC(pred16x16_dc)(uint8_t *_src, ptrdiff_t stride)
+{
     int i, dc=0;
     pixel *src = (pixel*)_src;
     pixel4 dcsplat;
@@ -353,7 +386,8 @@ static void FUNCC(pred16x16_dc)(uint8_t *_src, int stride){
     PREDICT_16x16_DC(dcsplat);
 }
 
-static void FUNCC(pred16x16_left_dc)(uint8_t *_src, int stride){
+static void FUNCC(pred16x16_left_dc)(uint8_t *_src, ptrdiff_t stride)
+{
     int i, dc=0;
     pixel *src = (pixel*)_src;
     pixel4 dcsplat;
@@ -367,7 +401,8 @@ static void FUNCC(pred16x16_left_dc)(uint8_t *_src, int stride){
     PREDICT_16x16_DC(dcsplat);
 }
 
-static void FUNCC(pred16x16_top_dc)(uint8_t *_src, int stride){
+static void FUNCC(pred16x16_top_dc)(uint8_t *_src, ptrdiff_t stride)
+{
     int i, dc=0;
     pixel *src = (pixel*)_src;
     pixel4 dcsplat;
@@ -382,18 +417,23 @@ static void FUNCC(pred16x16_top_dc)(uint8_t *_src, int stride){
 }
 
 #define PRED16x16_X(n, v) \
-static void FUNCC(pred16x16_##n##_dc)(uint8_t *_src, int stride){\
+static void FUNCC(pred16x16_##n##_dc)(uint8_t *_src, ptrdiff_t stride)\
+{\
     int i;\
     pixel *src = (pixel*)_src;\
     stride /= sizeof(pixel);\
     PREDICT_16x16_DC(PIXEL_SPLAT_X4(v));\
 }
 
-PRED16x16_X(127, (1<<(BIT_DEPTH-1))-1);
-PRED16x16_X(128, (1<<(BIT_DEPTH-1))+0);
-PRED16x16_X(129, (1<<(BIT_DEPTH-1))+1);
+PRED16x16_X(127, (1<<(BIT_DEPTH-1))-1)
+PRED16x16_X(128, (1<<(BIT_DEPTH-1))+0)
+PRED16x16_X(129, (1<<(BIT_DEPTH-1))+1)
 
-static inline void FUNCC(pred16x16_plane_compat)(uint8_t *_src, int _stride, const int svq3, const int rv40){
+static inline void FUNCC(pred16x16_plane_compat)(uint8_t *_src,
+                                                 ptrdiff_t _stride,
+                                                 const int svq3,
+                                                 const int rv40)
+{
   int i, j, k;
   int a;
   INIT_CLIP
@@ -438,50 +478,89 @@ static inline void FUNCC(pred16x16_plane_compat)(uint8_t *_src, int _stride, con
   }
 }
 
-static void FUNCC(pred16x16_plane)(uint8_t *src, int stride){
+static void FUNCC(pred16x16_plane)(uint8_t *src, ptrdiff_t stride)
+{
     FUNCC(pred16x16_plane_compat)(src, stride, 0, 0);
 }
 
-static void FUNCC(pred8x8_vertical)(uint8_t *_src, int _stride){
+static void FUNCC(pred8x8_vertical)(uint8_t *_src, ptrdiff_t _stride)
+{
     int i;
     pixel *src = (pixel*)_src;
     int stride = _stride/sizeof(pixel);
-    const pixel4 a= ((pixel4*)(src-stride))[0];
-    const pixel4 b= ((pixel4*)(src-stride))[1];
+    const pixel4 a= AV_RN4PA(((pixel4*)(src-stride))+0);
+    const pixel4 b= AV_RN4PA(((pixel4*)(src-stride))+1);
 
     for(i=0; i<8; i++){
-        ((pixel4*)(src+i*stride))[0]= a;
-        ((pixel4*)(src+i*stride))[1]= b;
+        AV_WN4PA(((pixel4*)(src+i*stride))+0, a);
+        AV_WN4PA(((pixel4*)(src+i*stride))+1, b);
     }
 }
 
-static void FUNCC(pred8x8_horizontal)(uint8_t *_src, int stride){
+static void FUNCC(pred8x16_vertical)(uint8_t *_src, ptrdiff_t _stride)
+{
+    int i;
+    pixel *src = (pixel*)_src;
+    int stride = _stride>>(sizeof(pixel)-1);
+    const pixel4 a= AV_RN4PA(((pixel4*)(src-stride))+0);
+    const pixel4 b= AV_RN4PA(((pixel4*)(src-stride))+1);
+
+    for(i=0; i<16; i++){
+        AV_WN4PA(((pixel4*)(src+i*stride))+0, a);
+        AV_WN4PA(((pixel4*)(src+i*stride))+1, b);
+    }
+}
+
+static void FUNCC(pred8x8_horizontal)(uint8_t *_src, ptrdiff_t stride)
+{
     int i;
     pixel *src = (pixel*)_src;
     stride /= sizeof(pixel);
 
     for(i=0; i<8; i++){
-        ((pixel4*)(src+i*stride))[0]=
-        ((pixel4*)(src+i*stride))[1]= PIXEL_SPLAT_X4(src[-1+i*stride]);
+        const pixel4 a = PIXEL_SPLAT_X4(src[-1+i*stride]);
+        AV_WN4PA(((pixel4*)(src+i*stride))+0, a);
+        AV_WN4PA(((pixel4*)(src+i*stride))+1, a);
+    }
+}
+
+static void FUNCC(pred8x16_horizontal)(uint8_t *_src, ptrdiff_t stride)
+{
+    int i;
+    pixel *src = (pixel*)_src;
+    stride >>= sizeof(pixel)-1;
+    for(i=0; i<16; i++){
+        const pixel4 a = PIXEL_SPLAT_X4(src[-1+i*stride]);
+        AV_WN4PA(((pixel4*)(src+i*stride))+0, a);
+        AV_WN4PA(((pixel4*)(src+i*stride))+1, a);
     }
 }
 
 #define PRED8x8_X(n, v)\
-static void FUNCC(pred8x8_##n##_dc)(uint8_t *_src, int stride){\
+static void FUNCC(pred8x8_##n##_dc)(uint8_t *_src, ptrdiff_t stride)\
+{\
     int i;\
+    const pixel4 a = PIXEL_SPLAT_X4(v);\
     pixel *src = (pixel*)_src;\
     stride /= sizeof(pixel);\
     for(i=0; i<8; i++){\
-        ((pixel4*)(src+i*stride))[0]=\
-        ((pixel4*)(src+i*stride))[1]= PIXEL_SPLAT_X4(v);\
+        AV_WN4PA(((pixel4*)(src+i*stride))+0, a);\
+        AV_WN4PA(((pixel4*)(src+i*stride))+1, a);\
     }\
 }
 
-PRED8x8_X(127, (1<<(BIT_DEPTH-1))-1);
-PRED8x8_X(128, (1<<(BIT_DEPTH-1))+0);
-PRED8x8_X(129, (1<<(BIT_DEPTH-1))+1);
+PRED8x8_X(127, (1<<(BIT_DEPTH-1))-1)
+PRED8x8_X(128, (1<<(BIT_DEPTH-1))+0)
+PRED8x8_X(129, (1<<(BIT_DEPTH-1))+1)
+
+static void FUNCC(pred8x16_128_dc)(uint8_t *_src, ptrdiff_t stride)
+{
+    FUNCC(pred8x8_128_dc)(_src, stride);
+    FUNCC(pred8x8_128_dc)(_src+8*stride, stride);
+}
 
-static void FUNCC(pred8x8_left_dc)(uint8_t *_src, int stride){
+static void FUNCC(pred8x8_left_dc)(uint8_t *_src, ptrdiff_t stride)
+{
     int i;
     int dc0, dc2;
     pixel4 dc0splat, dc2splat;
@@ -497,16 +576,23 @@ static void FUNCC(pred8x8_left_dc)(uint8_t *_src, int stride){
     dc2splat = PIXEL_SPLAT_X4((dc2 + 2)>>2);
 
     for(i=0; i<4; i++){
-        ((pixel4*)(src+i*stride))[0]=
-        ((pixel4*)(src+i*stride))[1]= dc0splat;
+        AV_WN4PA(((pixel4*)(src+i*stride))+0, dc0splat);
+        AV_WN4PA(((pixel4*)(src+i*stride))+1, dc0splat);
     }
     for(i=4; i<8; i++){
-        ((pixel4*)(src+i*stride))[0]=
-        ((pixel4*)(src+i*stride))[1]= dc2splat;
+        AV_WN4PA(((pixel4*)(src+i*stride))+0, dc2splat);
+        AV_WN4PA(((pixel4*)(src+i*stride))+1, dc2splat);
     }
 }
 
-static void FUNCC(pred8x8_top_dc)(uint8_t *_src, int stride){
+static void FUNCC(pred8x16_left_dc)(uint8_t *_src, ptrdiff_t stride)
+{
+    FUNCC(pred8x8_left_dc)(_src, stride);
+    FUNCC(pred8x8_left_dc)(_src+8*stride, stride);
+}
+
+static void FUNCC(pred8x8_top_dc)(uint8_t *_src, ptrdiff_t stride)
+{
     int i;
     int dc0, dc1;
     pixel4 dc0splat, dc1splat;
@@ -522,16 +608,39 @@ static void FUNCC(pred8x8_top_dc)(uint8_t *_src, int stride){
     dc1splat = PIXEL_SPLAT_X4((dc1 + 2)>>2);
 
     for(i=0; i<4; i++){
-        ((pixel4*)(src+i*stride))[0]= dc0splat;
-        ((pixel4*)(src+i*stride))[1]= dc1splat;
+        AV_WN4PA(((pixel4*)(src+i*stride))+0, dc0splat);
+        AV_WN4PA(((pixel4*)(src+i*stride))+1, dc1splat);
     }
     for(i=4; i<8; i++){
-        ((pixel4*)(src+i*stride))[0]= dc0splat;
-        ((pixel4*)(src+i*stride))[1]= dc1splat;
+        AV_WN4PA(((pixel4*)(src+i*stride))+0, dc0splat);
+        AV_WN4PA(((pixel4*)(src+i*stride))+1, dc1splat);
+    }
+}
+
+static void FUNCC(pred8x16_top_dc)(uint8_t *_src, ptrdiff_t stride)
+{
+    int i;
+    int dc0, dc1;
+    pixel4 dc0splat, dc1splat;
+    pixel *src = (pixel*)_src;
+    stride >>= sizeof(pixel)-1;
+
+    dc0=dc1=0;
+    for(i=0;i<4; i++){
+        dc0+= src[i-stride];
+        dc1+= src[4+i-stride];
+    }
+    dc0splat = PIXEL_SPLAT_X4((dc0 + 2)>>2);
+    dc1splat = PIXEL_SPLAT_X4((dc1 + 2)>>2);
+
+    for(i=0; i<16; i++){
+        AV_WN4PA(((pixel4*)(src+i*stride))+0, dc0splat);
+        AV_WN4PA(((pixel4*)(src+i*stride))+1, dc1splat);
     }
 }
 
-static void FUNCC(pred8x8_dc)(uint8_t *_src, int stride){
+static void FUNCC(pred8x8_dc)(uint8_t *_src, ptrdiff_t stride)
+{
     int i;
     int dc0, dc1, dc2;
     pixel4 dc0splat, dc1splat, dc2splat, dc3splat;
@@ -550,39 +659,112 @@ static void FUNCC(pred8x8_dc)(uint8_t *_src, int stride){
     dc3splat = PIXEL_SPLAT_X4((dc1 + dc2 + 4)>>3);
 
     for(i=0; i<4; i++){
-        ((pixel4*)(src+i*stride))[0]= dc0splat;
-        ((pixel4*)(src+i*stride))[1]= dc1splat;
+        AV_WN4PA(((pixel4*)(src+i*stride))+0, dc0splat);
+        AV_WN4PA(((pixel4*)(src+i*stride))+1, dc1splat);
     }
     for(i=4; i<8; i++){
-        ((pixel4*)(src+i*stride))[0]= dc2splat;
-        ((pixel4*)(src+i*stride))[1]= dc3splat;
+        AV_WN4PA(((pixel4*)(src+i*stride))+0, dc2splat);
+        AV_WN4PA(((pixel4*)(src+i*stride))+1, dc3splat);
     }
 }
 
-//the following 4 function should not be optimized!
-static void FUNC(pred8x8_mad_cow_dc_l0t)(uint8_t *src, int stride){
+static void FUNCC(pred8x16_dc)(uint8_t *_src, ptrdiff_t stride)
+{
+    int i;
+    int dc0, dc1, dc2, dc3, dc4;
+    pixel4 dc0splat, dc1splat, dc2splat, dc3splat, dc4splat, dc5splat, dc6splat, dc7splat;
+    pixel *src = (pixel*)_src;
+    stride >>= sizeof(pixel)-1;
+
+    dc0=dc1=dc2=dc3=dc4=0;
+    for(i=0;i<4; i++){
+        dc0+= src[-1+i*stride] + src[i-stride];
+        dc1+= src[4+i-stride];
+        dc2+= src[-1+(i+4)*stride];
+        dc3+= src[-1+(i+8)*stride];
+        dc4+= src[-1+(i+12)*stride];
+    }
+    dc0splat = PIXEL_SPLAT_X4((dc0 + 4)>>3);
+    dc1splat = PIXEL_SPLAT_X4((dc1 + 2)>>2);
+    dc2splat = PIXEL_SPLAT_X4((dc2 + 2)>>2);
+    dc3splat = PIXEL_SPLAT_X4((dc1 + dc2 + 4)>>3);
+    dc4splat = PIXEL_SPLAT_X4((dc3 + 2)>>2);
+    dc5splat = PIXEL_SPLAT_X4((dc1 + dc3 + 4)>>3);
+    dc6splat = PIXEL_SPLAT_X4((dc4 + 2)>>2);
+    dc7splat = PIXEL_SPLAT_X4((dc1 + dc4 + 4)>>3);
+
+    for(i=0; i<4; i++){
+        AV_WN4PA(((pixel4*)(src+i*stride))+0, dc0splat);
+        AV_WN4PA(((pixel4*)(src+i*stride))+1, dc1splat);
+    }
+    for(i=4; i<8; i++){
+        AV_WN4PA(((pixel4*)(src+i*stride))+0, dc2splat);
+        AV_WN4PA(((pixel4*)(src+i*stride))+1, dc3splat);
+    }
+    for(i=8; i<12; i++){
+        AV_WN4PA(((pixel4*)(src+i*stride))+0, dc4splat);
+        AV_WN4PA(((pixel4*)(src+i*stride))+1, dc5splat);
+    }
+    for(i=12; i<16; i++){
+        AV_WN4PA(((pixel4*)(src+i*stride))+0, dc6splat);
+        AV_WN4PA(((pixel4*)(src+i*stride))+1, dc7splat);
+    }
+}
+
+static void FUNC(pred8x8_mad_cow_dc_l0t)(uint8_t *src, ptrdiff_t stride)
+{
     FUNCC(pred8x8_top_dc)(src, stride);
     FUNCC(pred4x4_dc)(src, NULL, stride);
 }
 
-static void FUNC(pred8x8_mad_cow_dc_0lt)(uint8_t *src, int stride){
+static void FUNC(pred8x16_mad_cow_dc_l0t)(uint8_t *src, ptrdiff_t stride)
+{
+    FUNCC(pred8x16_top_dc)(src, stride);
+    FUNCC(pred4x4_dc)(src, NULL, stride);
+}
+
+static void FUNC(pred8x8_mad_cow_dc_0lt)(uint8_t *src, ptrdiff_t stride)
+{
     FUNCC(pred8x8_dc)(src, stride);
     FUNCC(pred4x4_top_dc)(src, NULL, stride);
 }
 
-static void FUNC(pred8x8_mad_cow_dc_l00)(uint8_t *src, int stride){
+static void FUNC(pred8x16_mad_cow_dc_0lt)(uint8_t *src, ptrdiff_t stride)
+{
+    FUNCC(pred8x16_dc)(src, stride);
+    FUNCC(pred4x4_top_dc)(src, NULL, stride);
+}
+
+static void FUNC(pred8x8_mad_cow_dc_l00)(uint8_t *src, ptrdiff_t stride)
+{
     FUNCC(pred8x8_left_dc)(src, stride);
     FUNCC(pred4x4_128_dc)(src + 4*stride                  , NULL, stride);
     FUNCC(pred4x4_128_dc)(src + 4*stride + 4*sizeof(pixel), NULL, stride);
 }
 
-static void FUNC(pred8x8_mad_cow_dc_0l0)(uint8_t *src, int stride){
+static void FUNC(pred8x16_mad_cow_dc_l00)(uint8_t *src, ptrdiff_t stride)
+{
+    FUNCC(pred8x16_left_dc)(src, stride);
+    FUNCC(pred4x4_128_dc)(src + 4*stride                  , NULL, stride);
+    FUNCC(pred4x4_128_dc)(src + 4*stride + 4*sizeof(pixel), NULL, stride);
+}
+
+static void FUNC(pred8x8_mad_cow_dc_0l0)(uint8_t *src, ptrdiff_t stride)
+{
     FUNCC(pred8x8_left_dc)(src, stride);
     FUNCC(pred4x4_128_dc)(src                  , NULL, stride);
     FUNCC(pred4x4_128_dc)(src + 4*sizeof(pixel), NULL, stride);
 }
 
-static void FUNCC(pred8x8_plane)(uint8_t *_src, int _stride){
+static void FUNC(pred8x16_mad_cow_dc_0l0)(uint8_t *src, ptrdiff_t stride)
+{
+    FUNCC(pred8x16_left_dc)(src, stride);
+    FUNCC(pred4x4_128_dc)(src                  , NULL, stride);
+    FUNCC(pred4x4_128_dc)(src + 4*sizeof(pixel), NULL, stride);
+}
+
+static void FUNCC(pred8x8_plane)(uint8_t *_src, ptrdiff_t _stride)
+{
   int j, k;
   int a;
   INIT_CLIP
@@ -617,6 +799,48 @@ static void FUNCC(pred8x8_plane)(uint8_t *_src, int _stride){
   }
 }
 
+static void FUNCC(pred8x16_plane)(uint8_t *_src, ptrdiff_t _stride)
+{
+  int j, k;
+  int a;
+  INIT_CLIP
+  pixel *src = (pixel*)_src;
+  int stride = _stride>>(sizeof(pixel)-1);
+  const pixel * const src0 = src +3-stride;
+  const pixel *       src1 = src +8*stride-1;
+  const pixel *       src2 = src1-2*stride;    // == src+6*stride-1;
+  int H = src0[1] - src0[-1];
+  int V = src1[0] - src2[ 0];
+
+  for (k = 2; k <= 4; ++k) {
+      src1 += stride; src2 -= stride;
+      H += k*(src0[k] - src0[-k]);
+      V += k*(src1[0] - src2[ 0]);
+  }
+  for (; k <= 8; ++k) {
+      src1 += stride; src2 -= stride;
+      V += k*(src1[0] - src2[0]);
+  }
+
+  H = (17*H+16) >> 5;
+  V = (5*V+32) >> 6;
+
+  a = 16*(src1[0] + src2[8] + 1) - 7*V - 3*H;
+  for(j=16; j>0; --j) {
+    int b = a;
+    a += V;
+    src[0] = CLIP((b    ) >> 5);
+    src[1] = CLIP((b+  H) >> 5);
+    src[2] = CLIP((b+2*H) >> 5);
+    src[3] = CLIP((b+3*H) >> 5);
+    src[4] = CLIP((b+4*H) >> 5);
+    src[5] = CLIP((b+5*H) >> 5);
+    src[6] = CLIP((b+6*H) >> 5);
+    src[7] = CLIP((b+7*H) >> 5);
+    src += stride;
+  }
+}
+
 #define SRC(x,y) src[(x)+(y)*stride]
 #define PL(y) \
     const int l##y = (SRC(-1,y-1) + 2*SRC(-1,y) + SRC(-1,y+1) + 2) >> 2;
@@ -650,19 +874,21 @@ static void FUNCC(pred8x8_plane)(uint8_t *_src, int _stride){
 #define PREDICT_8x8_DC(v) \
     int y; \
     for( y = 0; y < 8; y++ ) { \
-        ((pixel4*)src)[0] = \
-        ((pixel4*)src)[1] = v; \
+        AV_WN4PA(((pixel4*)src)+0, v); \
+        AV_WN4PA(((pixel4*)src)+1, v); \
         src += stride; \
     }
 
-static void FUNCC(pred8x8l_128_dc)(uint8_t *_src, int has_topleft, int has_topright, int _stride)
+static void FUNCC(pred8x8l_128_dc)(uint8_t *_src, int has_topleft,
+                                   int has_topright, ptrdiff_t _stride)
 {
     pixel *src = (pixel*)_src;
     int stride = _stride/sizeof(pixel);
 
     PREDICT_8x8_DC(PIXEL_SPLAT_X4(1<<(BIT_DEPTH-1)));
 }
-static void FUNCC(pred8x8l_left_dc)(uint8_t *_src, int has_topleft, int has_topright, int _stride)
+static void FUNCC(pred8x8l_left_dc)(uint8_t *_src, int has_topleft,
+                                    int has_topright, ptrdiff_t _stride)
 {
     pixel *src = (pixel*)_src;
     int stride = _stride/sizeof(pixel);
@@ -671,7 +897,8 @@ static void FUNCC(pred8x8l_left_dc)(uint8_t *_src, int has_topleft, int has_topr
     const pixel4 dc = PIXEL_SPLAT_X4((l0+l1+l2+l3+l4+l5+l6+l7+4) >> 3);
     PREDICT_8x8_DC(dc);
 }
-static void FUNCC(pred8x8l_top_dc)(uint8_t *_src, int has_topleft, int has_topright, int _stride)
+static void FUNCC(pred8x8l_top_dc)(uint8_t *_src, int has_topleft,
+                                   int has_topright, ptrdiff_t _stride)
 {
     pixel *src = (pixel*)_src;
     int stride = _stride/sizeof(pixel);
@@ -680,7 +907,8 @@ static void FUNCC(pred8x8l_top_dc)(uint8_t *_src, int has_topleft, int has_topri
     const pixel4 dc = PIXEL_SPLAT_X4((t0+t1+t2+t3+t4+t5+t6+t7+4) >> 3);
     PREDICT_8x8_DC(dc);
 }
-static void FUNCC(pred8x8l_dc)(uint8_t *_src, int has_topleft, int has_topright, int _stride)
+static void FUNCC(pred8x8l_dc)(uint8_t *_src, int has_topleft,
+                               int has_topright, ptrdiff_t _stride)
 {
     pixel *src = (pixel*)_src;
     int stride = _stride/sizeof(pixel);
@@ -691,22 +919,27 @@ static void FUNCC(pred8x8l_dc)(uint8_t *_src, int has_topleft, int has_topright,
                                      +t0+t1+t2+t3+t4+t5+t6+t7+8) >> 4);
     PREDICT_8x8_DC(dc);
 }
-static void FUNCC(pred8x8l_horizontal)(uint8_t *_src, int has_topleft, int has_topright, int _stride)
+static void FUNCC(pred8x8l_horizontal)(uint8_t *_src, int has_topleft,
+                                       int has_topright, ptrdiff_t _stride)
 {
     pixel *src = (pixel*)_src;
     int stride = _stride/sizeof(pixel);
+    pixel4 a;
 
     PREDICT_8x8_LOAD_LEFT;
-#define ROW(y) ((pixel4*)(src+y*stride))[0] =\
-               ((pixel4*)(src+y*stride))[1] = PIXEL_SPLAT_X4(l##y)
+#define ROW(y) a = PIXEL_SPLAT_X4(l##y); \
+               AV_WN4PA(src+y*stride, a); \
+               AV_WN4PA(src+y*stride+4, a);
     ROW(0); ROW(1); ROW(2); ROW(3); ROW(4); ROW(5); ROW(6); ROW(7);
 #undef ROW
 }
-static void FUNCC(pred8x8l_vertical)(uint8_t *_src, int has_topleft, int has_topright, int _stride)
+static void FUNCC(pred8x8l_vertical)(uint8_t *_src, int has_topleft,
+                                     int has_topright, ptrdiff_t _stride)
 {
     int y;
     pixel *src = (pixel*)_src;
     int stride = _stride/sizeof(pixel);
+    pixel4 a, b;
 
     PREDICT_8x8_LOAD_TOP;
     src[0] = t0;
@@ -717,12 +950,15 @@ static void FUNCC(pred8x8l_vertical)(uint8_t *_src, int has_topleft, int has_top
     src[5] = t5;
     src[6] = t6;
     src[7] = t7;
+    a = AV_RN4PA(((pixel4*)src)+0);
+    b = AV_RN4PA(((pixel4*)src)+1);
     for( y = 1; y < 8; y++ ) {
-        ((pixel4*)(src+y*stride))[0] = ((pixel4*)src)[0];
-        ((pixel4*)(src+y*stride))[1] = ((pixel4*)src)[1];
+        AV_WN4PA(((pixel4*)(src+y*stride))+0, a);
+        AV_WN4PA(((pixel4*)(src+y*stride))+1, b);
     }
 }
-static void FUNCC(pred8x8l_down_left)(uint8_t *_src, int has_topleft, int has_topright, int _stride)
+static void FUNCC(pred8x8l_down_left)(uint8_t *_src, int has_topleft,
+                                      int has_topright, ptrdiff_t _stride)
 {
     pixel *src = (pixel*)_src;
     int stride = _stride/sizeof(pixel);
@@ -744,7 +980,8 @@ static void FUNCC(pred8x8l_down_left)(uint8_t *_src, int has_topleft, int has_to
     SRC(6,7)=SRC(7,6)= (t13 + 2*t14 + t15 + 2) >> 2;
     SRC(7,7)= (t14 + 3*t15 + 2) >> 2;
 }
-static void FUNCC(pred8x8l_down_right)(uint8_t *_src, int has_topleft, int has_topright, int _stride)
+static void FUNCC(pred8x8l_down_right)(uint8_t *_src, int has_topleft,
+                                       int has_topright, ptrdiff_t _stride)
 {
     pixel *src = (pixel*)_src;
     int stride = _stride/sizeof(pixel);
@@ -767,7 +1004,8 @@ static void FUNCC(pred8x8l_down_right)(uint8_t *_src, int has_topleft, int has_t
     SRC(6,0)=SRC(7,1)= (t4 + 2*t5 + t6 + 2) >> 2;
     SRC(7,0)= (t5 + 2*t6 + t7 + 2) >> 2;
 }
-static void FUNCC(pred8x8l_vertical_right)(uint8_t *_src, int has_topleft, int has_topright, int _stride)
+static void FUNCC(pred8x8l_vertical_right)(uint8_t *_src, int has_topleft,
+                                           int has_topright, ptrdiff_t _stride)
 {
     pixel *src = (pixel*)_src;
     int stride = _stride/sizeof(pixel);
@@ -797,7 +1035,8 @@ static void FUNCC(pred8x8l_vertical_right)(uint8_t *_src, int has_topleft, int h
     SRC(7,1)= (t5 + 2*t6 + t7 + 2) >> 2;
     SRC(7,0)= (t6 + t7 + 1) >> 1;
 }
-static void FUNCC(pred8x8l_horizontal_down)(uint8_t *_src, int has_topleft, int has_topright, int _stride)
+static void FUNCC(pred8x8l_horizontal_down)(uint8_t *_src, int has_topleft,
+                                            int has_topright, ptrdiff_t _stride)
 {
     pixel *src = (pixel*)_src;
     int stride = _stride/sizeof(pixel);
@@ -827,7 +1066,8 @@ static void FUNCC(pred8x8l_horizontal_down)(uint8_t *_src, int has_topleft, int
     SRC(6,0)= (t5 + 2*t4 + t3 + 2) >> 2;
     SRC(7,0)= (t6 + 2*t5 + t4 + 2) >> 2;
 }
-static void FUNCC(pred8x8l_vertical_left)(uint8_t *_src, int has_topleft, int has_topright, int _stride)
+static void FUNCC(pred8x8l_vertical_left)(uint8_t *_src, int has_topleft,
+                                          int has_topright, ptrdiff_t _stride)
 {
     pixel *src = (pixel*)_src;
     int stride = _stride/sizeof(pixel);
@@ -856,7 +1096,8 @@ static void FUNCC(pred8x8l_vertical_left)(uint8_t *_src, int has_topleft, int ha
     SRC(7,6)= (t10 + t11 + 1) >> 1;
     SRC(7,7)= (t10 + 2*t11 + t12 + 2) >> 2;
 }
-static void FUNCC(pred8x8l_horizontal_up)(uint8_t *_src, int has_topleft, int has_topright, int _stride)
+static void FUNCC(pred8x8l_horizontal_up)(uint8_t *_src, int has_topleft,
+                                          int has_topright, ptrdiff_t _stride)
 {
     pixel *src = (pixel*)_src;
     int stride = _stride/sizeof(pixel);
@@ -890,7 +1131,9 @@ static void FUNCC(pred8x8l_horizontal_up)(uint8_t *_src, int has_topleft, int ha
 #undef PL
 #undef SRC
 
-static void FUNCC(pred4x4_vertical_add)(uint8_t *_pix, const DCTELEM *_block, int stride){
+static void FUNCC(pred4x4_vertical_add)(uint8_t *_pix, const DCTELEM *_block,
+                                        ptrdiff_t stride)
+{
     int i;
     pixel *pix = (pixel*)_pix;
     const dctcoef *block = (const dctcoef*)_block;
@@ -907,7 +1150,9 @@ static void FUNCC(pred4x4_vertical_add)(uint8_t *_pix, const DCTELEM *_block, in
     }
 }
 
-static void FUNCC(pred4x4_horizontal_add)(uint8_t *_pix, const DCTELEM *_block, int stride){
+static void FUNCC(pred4x4_horizontal_add)(uint8_t *_pix, const DCTELEM *_block,
+                                          ptrdiff_t stride)
+{
     int i;
     pixel *pix = (pixel*)_pix;
     const dctcoef *block = (const dctcoef*)_block;
@@ -923,7 +1168,9 @@ static void FUNCC(pred4x4_horizontal_add)(uint8_t *_pix, const DCTELEM *_block,
     }
 }
 
-static void FUNCC(pred8x8l_vertical_add)(uint8_t *_pix, const DCTELEM *_block, int stride){
+static void FUNCC(pred8x8l_vertical_add)(uint8_t *_pix, const DCTELEM *_block,
+                                         ptrdiff_t stride)
+{
     int i;
     pixel *pix = (pixel*)_pix;
     const dctcoef *block = (const dctcoef*)_block;
@@ -944,7 +1191,9 @@ static void FUNCC(pred8x8l_vertical_add)(uint8_t *_pix, const DCTELEM *_block, i
     }
 }
 
-static void FUNCC(pred8x8l_horizontal_add)(uint8_t *_pix, const DCTELEM *_block, int stride){
+static void FUNCC(pred8x8l_horizontal_add)(uint8_t *_pix, const DCTELEM *_block,
+                                           ptrdiff_t stride)
+{
     int i;
     pixel *pix = (pixel*)_pix;
     const dctcoef *block = (const dctcoef*)_block;
@@ -964,26 +1213,59 @@ static void FUNCC(pred8x8l_horizontal_add)(uint8_t *_pix, const DCTELEM *_block,
     }
 }
 
-static void FUNCC(pred16x16_vertical_add)(uint8_t *pix, const int *block_offset, const DCTELEM *block, int stride){
+static void FUNCC(pred16x16_vertical_add)(uint8_t *pix, const int *block_offset,
+                                          const DCTELEM *block,
+                                          ptrdiff_t stride)
+{
     int i;
     for(i=0; i<16; i++)
         FUNCC(pred4x4_vertical_add)(pix + block_offset[i], block + i*16*sizeof(pixel), stride);
 }
 
-static void FUNCC(pred16x16_horizontal_add)(uint8_t *pix, const int *block_offset, const DCTELEM *block, int stride){
+static void FUNCC(pred16x16_horizontal_add)(uint8_t *pix,
+                                            const int *block_offset,
+                                            const DCTELEM *block,
+                                            ptrdiff_t stride)
+{
     int i;
     for(i=0; i<16; i++)
         FUNCC(pred4x4_horizontal_add)(pix + block_offset[i], block + i*16*sizeof(pixel), stride);
 }
 
-static void FUNCC(pred8x8_vertical_add)(uint8_t *pix, const int *block_offset, const DCTELEM *block, int stride){
+static void FUNCC(pred8x8_vertical_add)(uint8_t *pix, const int *block_offset,
+                                        const DCTELEM *block, ptrdiff_t stride)
+{
+    int i;
+    for(i=0; i<4; i++)
+        FUNCC(pred4x4_vertical_add)(pix + block_offset[i], block + i*16*sizeof(pixel), stride);
+}
+
+static void FUNCC(pred8x16_vertical_add)(uint8_t *pix, const int *block_offset,
+                                         const DCTELEM *block, ptrdiff_t stride)
+{
     int i;
     for(i=0; i<4; i++)
         FUNCC(pred4x4_vertical_add)(pix + block_offset[i], block + i*16*sizeof(pixel), stride);
+    for(i=4; i<8; i++)
+        FUNCC(pred4x4_vertical_add)(pix + block_offset[i+4], block + i*16*sizeof(pixel), stride);
+}
+
+static void FUNCC(pred8x8_horizontal_add)(uint8_t *pix, const int *block_offset,
+                                          const DCTELEM *block,
+                                          ptrdiff_t stride)
+{
+    int i;
+    for(i=0; i<4; i++)
+        FUNCC(pred4x4_horizontal_add)(pix + block_offset[i], block + i*16*sizeof(pixel), stride);
 }
 
-static void FUNCC(pred8x8_horizontal_add)(uint8_t *pix, const int *block_offset, const DCTELEM *block, int stride){
+static void FUNCC(pred8x16_horizontal_add)(uint8_t *pix,
+                                           const int *block_offset,
+                                           const DCTELEM *block, ptrdiff_t stride)
+{
     int i;
     for(i=0; i<4; i++)
         FUNCC(pred4x4_horizontal_add)(pix + block_offset[i], block + i*16*sizeof(pixel), stride);
+    for(i=4; i<8; i++)
+        FUNCC(pred4x4_horizontal_add)(pix + block_offset[i+4], block + i*16*sizeof(pixel), stride);
 }