predict.c
上传用户:hjq518
上传日期:2021-12-09
资源大小:5084k
文件大小:24k
源码类别:

Audio

开发平台:

Visual C++

  1. /*****************************************************************************
  2.  * predict.c: h264 encoder
  3.  *****************************************************************************
  4.  * Copyright (C) 2003-2008 x264 project
  5.  *
  6.  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
  7.  *          Loren Merritt <lorenm@u.washington.edu>
  8.  *          Jason Garrett-Glaser <darkshikari@gmail.com>
  9.  *
  10.  * This program is free software; you can redistribute it and/or modify
  11.  * it under the terms of the GNU General Public License as published by
  12.  * the Free Software Foundation; either version 2 of the License, or
  13.  * (at your option) any later version.
  14.  *
  15.  * This program is distributed in the hope that it will be useful,
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.  * GNU General Public License for more details.
  19.  *
  20.  * You should have received a copy of the GNU General Public License
  21.  * along with this program; if not, write to the Free Software
  22.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111, USA.
  23.  *****************************************************************************/
  24. /* predict4x4 are inspired from ffmpeg h264 decoder */
  25. #include "common.h"
  26. #ifdef HAVE_MMX
  27. #   include "x86/predict.h"
  28. #endif
  29. #ifdef ARCH_PPC
  30. #   include "ppc/predict.h"
  31. #endif
  32. /****************************************************************************
  33.  * 16x16 prediction for intra luma block
  34.  ****************************************************************************/
  35. #define PREDICT_16x16_DC(v) 
  36.     for( i = 0; i < 16; i++ )
  37.     {
  38.         uint32_t *p = (uint32_t*)src;
  39.         *p++ = v;
  40.         *p++ = v;
  41.         *p++ = v;
  42.         *p++ = v;
  43.         src += FDEC_STRIDE;
  44.     }
  45. static void predict_16x16_dc( uint8_t *src )
  46. {
  47.     uint32_t dc = 0;
  48.     int i;
  49.     for( i = 0; i < 16; i++ )
  50.     {
  51.         dc += src[-1 + i * FDEC_STRIDE];
  52.         dc += src[i - FDEC_STRIDE];
  53.     }
  54.     dc = (( dc + 16 ) >> 5) * 0x01010101;
  55.     PREDICT_16x16_DC(dc);
  56. }
  57. static void predict_16x16_dc_left( uint8_t *src )
  58. {
  59.     uint32_t dc = 0;
  60.     int i;
  61.     for( i = 0; i < 16; i++ )
  62.     {
  63.         dc += src[-1 + i * FDEC_STRIDE];
  64.     }
  65.     dc = (( dc + 8 ) >> 4) * 0x01010101;
  66.     PREDICT_16x16_DC(dc);
  67. }
  68. static void predict_16x16_dc_top( uint8_t *src )
  69. {
  70.     uint32_t dc = 0;
  71.     int i;
  72.     for( i = 0; i < 16; i++ )
  73.     {
  74.         dc += src[i - FDEC_STRIDE];
  75.     }
  76.     dc = (( dc + 8 ) >> 4) * 0x01010101;
  77.     PREDICT_16x16_DC(dc);
  78. }
  79. static void predict_16x16_dc_128( uint8_t *src )
  80. {
  81.     int i;
  82.     PREDICT_16x16_DC(0x80808080);
  83. }
  84. static void predict_16x16_h( uint8_t *src )
  85. {
  86.     int i;
  87.     for( i = 0; i < 16; i++ )
  88.     {
  89.         const uint32_t v = 0x01010101 * src[-1];
  90.         uint32_t *p = (uint32_t*)src;
  91.         *p++ = v;
  92.         *p++ = v;
  93.         *p++ = v;
  94.         *p++ = v;
  95.         src += FDEC_STRIDE;
  96.     }
  97. }
  98. static void predict_16x16_v( uint8_t *src )
  99. {
  100.     uint32_t v0 = *(uint32_t*)&src[ 0-FDEC_STRIDE];
  101.     uint32_t v1 = *(uint32_t*)&src[ 4-FDEC_STRIDE];
  102.     uint32_t v2 = *(uint32_t*)&src[ 8-FDEC_STRIDE];
  103.     uint32_t v3 = *(uint32_t*)&src[12-FDEC_STRIDE];
  104.     int i;
  105.     for( i = 0; i < 16; i++ )
  106.     {
  107.         uint32_t *p = (uint32_t*)src;
  108.         *p++ = v0;
  109.         *p++ = v1;
  110.         *p++ = v2;
  111.         *p++ = v3;
  112.         src += FDEC_STRIDE;
  113.     }
  114. }
  115. static void predict_16x16_p( uint8_t *src )
  116. {
  117.     int x, y, i;
  118.     int a, b, c;
  119.     int H = 0;
  120.     int V = 0;
  121.     int i00;
  122.     /* calculate H and V */
  123.     for( i = 0; i <= 7; i++ )
  124.     {
  125.         H += ( i + 1 ) * ( src[ 8 + i - FDEC_STRIDE ] - src[6 -i -FDEC_STRIDE] );
  126.         V += ( i + 1 ) * ( src[-1 + (8+i)*FDEC_STRIDE] - src[-1 + (6-i)*FDEC_STRIDE] );
  127.     }
  128.     a = 16 * ( src[-1 + 15*FDEC_STRIDE] + src[15 - FDEC_STRIDE] );
  129.     b = ( 5 * H + 32 ) >> 6;
  130.     c = ( 5 * V + 32 ) >> 6;
  131.     i00 = a - b * 7 - c * 7 + 16;
  132.     for( y = 0; y < 16; y++ )
  133.     {
  134.         int pix = i00;
  135.         for( x = 0; x < 16; x++ )
  136.         {
  137.             src[x] = x264_clip_uint8( pix>>5 );
  138.             pix += b;
  139.         }
  140.         src += FDEC_STRIDE;
  141.         i00 += c;
  142.     }
  143. }
  144. /****************************************************************************
  145.  * 8x8 prediction for intra chroma block
  146.  ****************************************************************************/
  147. static void predict_8x8c_dc_128( uint8_t *src )
  148. {
  149.     int y;
  150.     for( y = 0; y < 8; y++ )
  151.     {
  152.         uint32_t *p = (uint32_t*)src;
  153.         *p++ = 0x80808080;
  154.         *p++ = 0x80808080;
  155.         src += FDEC_STRIDE;
  156.     }
  157. }
  158. static void predict_8x8c_dc_left( uint8_t *src )
  159. {
  160.     int y;
  161.     uint32_t dc0 = 0, dc1 = 0;
  162.     for( y = 0; y < 4; y++ )
  163.     {
  164.         dc0 += src[y * FDEC_STRIDE     - 1];
  165.         dc1 += src[(y+4) * FDEC_STRIDE - 1];
  166.     }
  167.     dc0 = (( dc0 + 2 ) >> 2)*0x01010101;
  168.     dc1 = (( dc1 + 2 ) >> 2)*0x01010101;
  169.     for( y = 0; y < 4; y++ )
  170.     {
  171.         uint32_t *p = (uint32_t*)src;
  172.         *p++ = dc0;
  173.         *p++ = dc0;
  174.         src += FDEC_STRIDE;
  175.     }
  176.     for( y = 0; y < 4; y++ )
  177.     {
  178.         uint32_t *p = (uint32_t*)src;
  179.         *p++ = dc1;
  180.         *p++ = dc1;
  181.         src += FDEC_STRIDE;
  182.     }
  183. }
  184. static void predict_8x8c_dc_top( uint8_t *src )
  185. {
  186.     int y, x;
  187.     uint32_t dc0 = 0, dc1 = 0;
  188.     for( x = 0; x < 4; x++ )
  189.     {
  190.         dc0 += src[x     - FDEC_STRIDE];
  191.         dc1 += src[x + 4 - FDEC_STRIDE];
  192.     }
  193.     dc0 = (( dc0 + 2 ) >> 2)*0x01010101;
  194.     dc1 = (( dc1 + 2 ) >> 2)*0x01010101;
  195.     for( y = 0; y < 8; y++ )
  196.     {
  197.         uint32_t *p = (uint32_t*)src;
  198.         *p++ = dc0;
  199.         *p++ = dc1;
  200.         src += FDEC_STRIDE;
  201.     }
  202. }
  203. static void predict_8x8c_dc( uint8_t *src )
  204. {
  205.     int y;
  206.     int s0 = 0, s1 = 0, s2 = 0, s3 = 0;
  207.     uint32_t dc0, dc1, dc2, dc3;
  208.     int i;
  209.     /*
  210.           s0 s1
  211.        s2
  212.        s3
  213.     */
  214.     for( i = 0; i < 4; i++ )
  215.     {
  216.         s0 += src[i - FDEC_STRIDE];
  217.         s1 += src[i + 4 - FDEC_STRIDE];
  218.         s2 += src[-1 + i * FDEC_STRIDE];
  219.         s3 += src[-1 + (i+4)*FDEC_STRIDE];
  220.     }
  221.     /*
  222.        dc0 dc1
  223.        dc2 dc3
  224.      */
  225.     dc0 = (( s0 + s2 + 4 ) >> 3)*0x01010101;
  226.     dc1 = (( s1 + 2 ) >> 2)*0x01010101;
  227.     dc2 = (( s3 + 2 ) >> 2)*0x01010101;
  228.     dc3 = (( s1 + s3 + 4 ) >> 3)*0x01010101;
  229.     for( y = 0; y < 4; y++ )
  230.     {
  231.         uint32_t *p = (uint32_t*)src;
  232.         *p++ = dc0;
  233.         *p++ = dc1;
  234.         src += FDEC_STRIDE;
  235.     }
  236.     for( y = 0; y < 4; y++ )
  237.     {
  238.         uint32_t *p = (uint32_t*)src;
  239.         *p++ = dc2;
  240.         *p++ = dc3;
  241.         src += FDEC_STRIDE;
  242.     }
  243. }
  244. static void predict_8x8c_h( uint8_t *src )
  245. {
  246.     int i;
  247.     for( i = 0; i < 8; i++ )
  248.     {
  249.         uint32_t v = 0x01010101 * src[-1];
  250.         uint32_t *p = (uint32_t*)src;
  251.         *p++ = v;
  252.         *p++ = v;
  253.         src += FDEC_STRIDE;
  254.     }
  255. }
  256. static void predict_8x8c_v( uint8_t *src )
  257. {
  258.     uint32_t v0 = *(uint32_t*)&src[0-FDEC_STRIDE];
  259.     uint32_t v1 = *(uint32_t*)&src[4-FDEC_STRIDE];
  260.     int i;
  261.     for( i = 0; i < 8; i++ )
  262.     {
  263.         uint32_t *p = (uint32_t*)src;
  264.         *p++ = v0;
  265.         *p++ = v1;
  266.         src += FDEC_STRIDE;
  267.     }
  268. }
  269. static void predict_8x8c_p( uint8_t *src )
  270. {
  271.     int i;
  272.     int x,y;
  273.     int a, b, c;
  274.     int H = 0;
  275.     int V = 0;
  276.     int i00;
  277.     for( i = 0; i < 4; i++ )
  278.     {
  279.         H += ( i + 1 ) * ( src[4+i - FDEC_STRIDE] - src[2 - i -FDEC_STRIDE] );
  280.         V += ( i + 1 ) * ( src[-1 +(i+4)*FDEC_STRIDE] - src[-1+(2-i)*FDEC_STRIDE] );
  281.     }
  282.     a = 16 * ( src[-1+7*FDEC_STRIDE] + src[7 - FDEC_STRIDE] );
  283.     b = ( 17 * H + 16 ) >> 5;
  284.     c = ( 17 * V + 16 ) >> 5;
  285.     i00 = a -3*b -3*c + 16;
  286.     for( y = 0; y < 8; y++ )
  287.     {
  288.         int pix = i00;
  289.         for( x = 0; x < 8; x++ )
  290.         {
  291.             src[x] = x264_clip_uint8( pix>>5 );
  292.             pix += b;
  293.         }
  294.         src += FDEC_STRIDE;
  295.         i00 += c;
  296.     }
  297. }
  298. /****************************************************************************
  299.  * 4x4 prediction for intra luma block
  300.  ****************************************************************************/
  301. #define SRC(x,y) src[(x)+(y)*FDEC_STRIDE]
  302. #define SRC32(x,y) *(uint32_t*)&SRC(x,y)
  303. #define PREDICT_4x4_DC(v)
  304.     SRC32(0,0) = SRC32(0,1) = SRC32(0,2) = SRC32(0,3) = v;
  305. static void predict_4x4_dc_128( uint8_t *src )
  306. {
  307.     PREDICT_4x4_DC(0x80808080);
  308. }
  309. static void predict_4x4_dc_left( uint8_t *src )
  310. {
  311.     uint32_t dc = ((SRC(-1,0) + SRC(-1,1) + SRC(-1,2) + SRC(-1,3) + 2) >> 2) * 0x01010101;
  312.     PREDICT_4x4_DC(dc);
  313. }
  314. static void predict_4x4_dc_top( uint8_t *src )
  315. {
  316.     uint32_t dc = ((SRC(0,-1) + SRC(1,-1) + SRC(2,-1) + SRC(3,-1) + 2) >> 2) * 0x01010101;
  317.     PREDICT_4x4_DC(dc);
  318. }
  319. static void predict_4x4_dc( uint8_t *src )
  320. {
  321.     uint32_t dc = ((SRC(-1,0) + SRC(-1,1) + SRC(-1,2) + SRC(-1,3) +
  322.                     SRC(0,-1) + SRC(1,-1) + SRC(2,-1) + SRC(3,-1) + 4) >> 3) * 0x01010101;
  323.     PREDICT_4x4_DC(dc);
  324. }
  325. static void predict_4x4_h( uint8_t *src )
  326. {
  327.     SRC32(0,0) = SRC(-1,0) * 0x01010101;
  328.     SRC32(0,1) = SRC(-1,1) * 0x01010101;
  329.     SRC32(0,2) = SRC(-1,2) * 0x01010101;
  330.     SRC32(0,3) = SRC(-1,3) * 0x01010101;
  331. }
  332. static void predict_4x4_v( uint8_t *src )
  333. {
  334.     PREDICT_4x4_DC(SRC32(0,-1));
  335. }
  336. #define PREDICT_4x4_LOAD_LEFT
  337.     const int l0 = SRC(-1,0);
  338.     const int l1 = SRC(-1,1);
  339.     const int l2 = SRC(-1,2);
  340.     UNUSED const int l3 = SRC(-1,3);
  341. #define PREDICT_4x4_LOAD_TOP
  342.     const int t0 = SRC(0,-1);
  343.     const int t1 = SRC(1,-1);
  344.     const int t2 = SRC(2,-1);
  345.     UNUSED const int t3 = SRC(3,-1);
  346. #define PREDICT_4x4_LOAD_TOP_RIGHT
  347.     const int t4 = SRC(4,-1);
  348.     const int t5 = SRC(5,-1);
  349.     const int t6 = SRC(6,-1);
  350.     UNUSED const int t7 = SRC(7,-1);
  351. #define F1(a,b)   (((a)+(b)+1)>>1)
  352. #define F2(a,b,c) (((a)+2*(b)+(c)+2)>>2)
  353. static void predict_4x4_ddl( uint8_t *src )
  354. {
  355.     PREDICT_4x4_LOAD_TOP
  356.     PREDICT_4x4_LOAD_TOP_RIGHT
  357.     SRC(0,0)= F2(t0,t1,t2);
  358.     SRC(1,0)=SRC(0,1)= F2(t1,t2,t3);
  359.     SRC(2,0)=SRC(1,1)=SRC(0,2)= F2(t2,t3,t4);
  360.     SRC(3,0)=SRC(2,1)=SRC(1,2)=SRC(0,3)= F2(t3,t4,t5);
  361.     SRC(3,1)=SRC(2,2)=SRC(1,3)= F2(t4,t5,t6);
  362.     SRC(3,2)=SRC(2,3)= F2(t5,t6,t7);
  363.     SRC(3,3)= F2(t6,t7,t7);
  364. }
  365. static void predict_4x4_ddr( uint8_t *src )
  366. {
  367.     const int lt = SRC(-1,-1);
  368.     PREDICT_4x4_LOAD_LEFT
  369.     PREDICT_4x4_LOAD_TOP
  370.     SRC(3,0)= F2(t3,t2,t1);
  371.     SRC(2,0)=SRC(3,1)= F2(t2,t1,t0);
  372.     SRC(1,0)=SRC(2,1)=SRC(3,2)= F2(t1,t0,lt);
  373.     SRC(0,0)=SRC(1,1)=SRC(2,2)=SRC(3,3)= F2(t0,lt,l0);
  374.     SRC(0,1)=SRC(1,2)=SRC(2,3)= F2(lt,l0,l1);
  375.     SRC(0,2)=SRC(1,3)= F2(l0,l1,l2);
  376.     SRC(0,3)= F2(l1,l2,l3);
  377. }
  378. static void predict_4x4_vr( uint8_t *src )
  379. {
  380.     const int lt = SRC(-1,-1);
  381.     PREDICT_4x4_LOAD_LEFT
  382.     PREDICT_4x4_LOAD_TOP
  383.     SRC(0,3)= F2(l2,l1,l0);
  384.     SRC(0,2)= F2(l1,l0,lt);
  385.     SRC(0,1)=SRC(1,3)= F2(l0,lt,t0);
  386.     SRC(0,0)=SRC(1,2)= F1(lt,t0);
  387.     SRC(1,1)=SRC(2,3)= F2(lt,t0,t1);
  388.     SRC(1,0)=SRC(2,2)= F1(t0,t1);
  389.     SRC(2,1)=SRC(3,3)= F2(t0,t1,t2);
  390.     SRC(2,0)=SRC(3,2)= F1(t1,t2);
  391.     SRC(3,1)= F2(t1,t2,t3);
  392.     SRC(3,0)= F1(t2,t3);
  393. }
  394. static void predict_4x4_hd( uint8_t *src )
  395. {
  396.     const int lt= SRC(-1,-1);
  397.     PREDICT_4x4_LOAD_LEFT
  398.     PREDICT_4x4_LOAD_TOP
  399.     SRC(0,3)= F1(l2,l3);
  400.     SRC(1,3)= F2(l1,l2,l3);
  401.     SRC(0,2)=SRC(2,3)= F1(l1,l2);
  402.     SRC(1,2)=SRC(3,3)= F2(l0,l1,l2);
  403.     SRC(0,1)=SRC(2,2)= F1(l0,l1);
  404.     SRC(1,1)=SRC(3,2)= F2(lt,l0,l1);
  405.     SRC(0,0)=SRC(2,1)= F1(lt,l0);
  406.     SRC(1,0)=SRC(3,1)= F2(t0,lt,l0);
  407.     SRC(2,0)= F2(t1,t0,lt);
  408.     SRC(3,0)= F2(t2,t1,t0);
  409. }
  410. static void predict_4x4_vl( uint8_t *src )
  411. {
  412.     PREDICT_4x4_LOAD_TOP
  413.     PREDICT_4x4_LOAD_TOP_RIGHT
  414.     SRC(0,0)= F1(t0,t1);
  415.     SRC(0,1)= F2(t0,t1,t2);
  416.     SRC(1,0)=SRC(0,2)= F1(t1,t2);
  417.     SRC(1,1)=SRC(0,3)= F2(t1,t2,t3);
  418.     SRC(2,0)=SRC(1,2)= F1(t2,t3);
  419.     SRC(2,1)=SRC(1,3)= F2(t2,t3,t4);
  420.     SRC(3,0)=SRC(2,2)= F1(t3,t4);
  421.     SRC(3,1)=SRC(2,3)= F2(t3,t4,t5);
  422.     SRC(3,2)= F1(t4,t5);
  423.     SRC(3,3)= F2(t4,t5,t6);
  424. }
  425. static void predict_4x4_hu( uint8_t *src )
  426. {
  427.     PREDICT_4x4_LOAD_LEFT
  428.     SRC(0,0)= F1(l0,l1);
  429.     SRC(1,0)= F2(l0,l1,l2);
  430.     SRC(2,0)=SRC(0,1)= F1(l1,l2);
  431.     SRC(3,0)=SRC(1,1)= F2(l1,l2,l3);
  432.     SRC(2,1)=SRC(0,2)= F1(l2,l3);
  433.     SRC(3,1)=SRC(1,2)= F2(l2,l3,l3);
  434.     SRC(3,2)=SRC(1,3)=SRC(0,3)=
  435.     SRC(2,2)=SRC(2,3)=SRC(3,3)= l3;
  436. }
  437. /****************************************************************************
  438.  * 8x8 prediction for intra luma block
  439.  ****************************************************************************/
  440. #define PL(y) 
  441.     edge[14-y] = F2(SRC(-1,y-1), SRC(-1,y), SRC(-1,y+1));
  442. #define PT(x) 
  443.     edge[16+x] = F2(SRC(x-1,-1), SRC(x,-1), SRC(x+1,-1));
  444. void x264_predict_8x8_filter( uint8_t *src, uint8_t edge[33], int i_neighbor, int i_filters )
  445. {
  446.     /* edge[7..14] = l7..l0
  447.      * edge[15] = lt
  448.      * edge[16..31] = t0 .. t15
  449.      * edge[32] = t15 */
  450.     int have_lt = i_neighbor & MB_TOPLEFT;
  451.     if( i_filters & MB_LEFT )
  452.     {
  453.         edge[15] = (SRC(-1,0) + 2*SRC(-1,-1) + SRC(0,-1) + 2) >> 2;
  454.         edge[14] = ((have_lt ? SRC(-1,-1) : SRC(-1,0))
  455.                     + 2*SRC(-1,0) + SRC(-1,1) + 2) >> 2;
  456.         PL(1) PL(2) PL(3) PL(4) PL(5) PL(6)
  457.         edge[7] = (SRC(-1,6) + 3*SRC(-1,7) + 2) >> 2;
  458.     }
  459.     if( i_filters & MB_TOP )
  460.     {
  461.         int have_tr = i_neighbor & MB_TOPRIGHT;
  462.         edge[16] = ((have_lt ? SRC(-1,-1) : SRC(0,-1))
  463.                     + 2*SRC(0,-1) + SRC(1,-1) + 2) >> 2;
  464.         PT(1) PT(2) PT(3) PT(4) PT(5) PT(6)
  465.         edge[23] = ((have_tr ? SRC(8,-1) : SRC(7,-1))
  466.                     + 2*SRC(7,-1) + SRC(6,-1) + 2) >> 2;
  467.         if( i_filters & MB_TOPRIGHT )
  468.         {
  469.             if( have_tr )
  470.             {
  471.                 PT(8) PT(9) PT(10) PT(11) PT(12) PT(13) PT(14)
  472.                 edge[31] =
  473.                 edge[32] = (SRC(14,-1) + 3*SRC(15,-1) + 2) >> 2;
  474.             }
  475.             else
  476.             {
  477.                 *(uint64_t*)(edge+24) = SRC(7,-1) * 0x0101010101010101ULL;
  478.                 edge[32] = SRC(7,-1);
  479.             }
  480.         }
  481.     }
  482. }
  483. #undef PL
  484. #undef PT
  485. #define PL(y) 
  486.     UNUSED const int l##y = edge[14-y];
  487. #define PT(x) 
  488.     UNUSED const int t##x = edge[16+x];
  489. #define PREDICT_8x8_LOAD_TOPLEFT 
  490.     const int lt = edge[15];
  491. #define PREDICT_8x8_LOAD_LEFT 
  492.     PL(0) PL(1) PL(2) PL(3) PL(4) PL(5) PL(6) PL(7)
  493. #define PREDICT_8x8_LOAD_TOP 
  494.     PT(0) PT(1) PT(2) PT(3) PT(4) PT(5) PT(6) PT(7)
  495. #define PREDICT_8x8_LOAD_TOPRIGHT 
  496.     PT(8) PT(9) PT(10) PT(11) PT(12) PT(13) PT(14) PT(15)
  497. #define PREDICT_8x8_DC(v) 
  498.     int y; 
  499.     for( y = 0; y < 8; y++ ) { 
  500.         ((uint32_t*)src)[0] = 
  501.         ((uint32_t*)src)[1] = v; 
  502.         src += FDEC_STRIDE; 
  503.     }
  504. /* SIMD is much faster than C for all of these except HU and HD. */
  505. static void predict_8x8_dc_128( uint8_t *src, uint8_t edge[33] )
  506. {
  507.     PREDICT_8x8_DC(0x80808080);
  508. }
  509. static void predict_8x8_dc_left( uint8_t *src, uint8_t edge[33] )
  510. {
  511.     PREDICT_8x8_LOAD_LEFT
  512.     const uint32_t dc = ((l0+l1+l2+l3+l4+l5+l6+l7+4) >> 3) * 0x01010101;
  513.     PREDICT_8x8_DC(dc);
  514. }
  515. static void predict_8x8_dc_top( uint8_t *src, uint8_t edge[33] )
  516. {
  517.     PREDICT_8x8_LOAD_TOP
  518.     const uint32_t dc = ((t0+t1+t2+t3+t4+t5+t6+t7+4) >> 3) * 0x01010101;
  519.     PREDICT_8x8_DC(dc);
  520. }
  521. static void predict_8x8_dc( uint8_t *src, uint8_t edge[33] )
  522. {
  523.     PREDICT_8x8_LOAD_LEFT
  524.     PREDICT_8x8_LOAD_TOP
  525.     const uint32_t dc = ((l0+l1+l2+l3+l4+l5+l6+l7
  526.                          +t0+t1+t2+t3+t4+t5+t6+t7+8) >> 4) * 0x01010101;
  527.     PREDICT_8x8_DC(dc);
  528. }
  529. static void predict_8x8_h( uint8_t *src, uint8_t edge[33] )
  530. {
  531.     PREDICT_8x8_LOAD_LEFT
  532. #define ROW(y) ((uint32_t*)(src+y*FDEC_STRIDE))[0] =
  533.                ((uint32_t*)(src+y*FDEC_STRIDE))[1] = 0x01010101U * l##y
  534.     ROW(0); ROW(1); ROW(2); ROW(3); ROW(4); ROW(5); ROW(6); ROW(7);
  535. #undef ROW
  536. }
  537. static void predict_8x8_v( uint8_t *src, uint8_t edge[33] )
  538. {
  539.     const uint64_t top = *(uint64_t*)(edge+16);
  540.     int y;
  541.     for( y = 0; y < 8; y++ )
  542.         *(uint64_t*)(src+y*FDEC_STRIDE) = top;
  543. }
  544. static void predict_8x8_ddl( uint8_t *src, uint8_t edge[33] )
  545. {
  546.     PREDICT_8x8_LOAD_TOP
  547.     PREDICT_8x8_LOAD_TOPRIGHT
  548.     SRC(0,0)= F2(t0,t1,t2);
  549.     SRC(0,1)=SRC(1,0)= F2(t1,t2,t3);
  550.     SRC(0,2)=SRC(1,1)=SRC(2,0)= F2(t2,t3,t4);
  551.     SRC(0,3)=SRC(1,2)=SRC(2,1)=SRC(3,0)= F2(t3,t4,t5);
  552.     SRC(0,4)=SRC(1,3)=SRC(2,2)=SRC(3,1)=SRC(4,0)= F2(t4,t5,t6);
  553.     SRC(0,5)=SRC(1,4)=SRC(2,3)=SRC(3,2)=SRC(4,1)=SRC(5,0)= F2(t5,t6,t7);
  554.     SRC(0,6)=SRC(1,5)=SRC(2,4)=SRC(3,3)=SRC(4,2)=SRC(5,1)=SRC(6,0)= F2(t6,t7,t8);
  555.     SRC(0,7)=SRC(1,6)=SRC(2,5)=SRC(3,4)=SRC(4,3)=SRC(5,2)=SRC(6,1)=SRC(7,0)= F2(t7,t8,t9);
  556.     SRC(1,7)=SRC(2,6)=SRC(3,5)=SRC(4,4)=SRC(5,3)=SRC(6,2)=SRC(7,1)= F2(t8,t9,t10);
  557.     SRC(2,7)=SRC(3,6)=SRC(4,5)=SRC(5,4)=SRC(6,3)=SRC(7,2)= F2(t9,t10,t11);
  558.     SRC(3,7)=SRC(4,6)=SRC(5,5)=SRC(6,4)=SRC(7,3)= F2(t10,t11,t12);
  559.     SRC(4,7)=SRC(5,6)=SRC(6,5)=SRC(7,4)= F2(t11,t12,t13);
  560.     SRC(5,7)=SRC(6,6)=SRC(7,5)= F2(t12,t13,t14);
  561.     SRC(6,7)=SRC(7,6)= F2(t13,t14,t15);
  562.     SRC(7,7)= F2(t14,t15,t15);
  563. }
  564. static void predict_8x8_ddr( uint8_t *src, uint8_t edge[33] )
  565. {
  566.     PREDICT_8x8_LOAD_TOP
  567.     PREDICT_8x8_LOAD_LEFT
  568.     PREDICT_8x8_LOAD_TOPLEFT
  569.     SRC(0,7)= F2(l7,l6,l5);
  570.     SRC(0,6)=SRC(1,7)= F2(l6,l5,l4);
  571.     SRC(0,5)=SRC(1,6)=SRC(2,7)= F2(l5,l4,l3);
  572.     SRC(0,4)=SRC(1,5)=SRC(2,6)=SRC(3,7)= F2(l4,l3,l2);
  573.     SRC(0,3)=SRC(1,4)=SRC(2,5)=SRC(3,6)=SRC(4,7)= F2(l3,l2,l1);
  574.     SRC(0,2)=SRC(1,3)=SRC(2,4)=SRC(3,5)=SRC(4,6)=SRC(5,7)= F2(l2,l1,l0);
  575.     SRC(0,1)=SRC(1,2)=SRC(2,3)=SRC(3,4)=SRC(4,5)=SRC(5,6)=SRC(6,7)= F2(l1,l0,lt);
  576.     SRC(0,0)=SRC(1,1)=SRC(2,2)=SRC(3,3)=SRC(4,4)=SRC(5,5)=SRC(6,6)=SRC(7,7)= F2(l0,lt,t0);
  577.     SRC(1,0)=SRC(2,1)=SRC(3,2)=SRC(4,3)=SRC(5,4)=SRC(6,5)=SRC(7,6)= F2(lt,t0,t1);
  578.     SRC(2,0)=SRC(3,1)=SRC(4,2)=SRC(5,3)=SRC(6,4)=SRC(7,5)= F2(t0,t1,t2);
  579.     SRC(3,0)=SRC(4,1)=SRC(5,2)=SRC(6,3)=SRC(7,4)= F2(t1,t2,t3);
  580.     SRC(4,0)=SRC(5,1)=SRC(6,2)=SRC(7,3)= F2(t2,t3,t4);
  581.     SRC(5,0)=SRC(6,1)=SRC(7,2)= F2(t3,t4,t5);
  582.     SRC(6,0)=SRC(7,1)= F2(t4,t5,t6);
  583.     SRC(7,0)= F2(t5,t6,t7);
  584. }
  585. static void predict_8x8_vr( uint8_t *src, uint8_t edge[33] )
  586. {
  587.     PREDICT_8x8_LOAD_TOP
  588.     PREDICT_8x8_LOAD_LEFT
  589.     PREDICT_8x8_LOAD_TOPLEFT
  590.     SRC(0,6)= F2(l5,l4,l3);
  591.     SRC(0,7)= F2(l6,l5,l4);
  592.     SRC(0,4)=SRC(1,6)= F2(l3,l2,l1);
  593.     SRC(0,5)=SRC(1,7)= F2(l4,l3,l2);
  594.     SRC(0,2)=SRC(1,4)=SRC(2,6)= F2(l1,l0,lt);
  595.     SRC(0,3)=SRC(1,5)=SRC(2,7)= F2(l2,l1,l0);
  596.     SRC(0,1)=SRC(1,3)=SRC(2,5)=SRC(3,7)= F2(l0,lt,t0);
  597.     SRC(0,0)=SRC(1,2)=SRC(2,4)=SRC(3,6)= F1(lt,t0);
  598.     SRC(1,1)=SRC(2,3)=SRC(3,5)=SRC(4,7)= F2(lt,t0,t1);
  599.     SRC(1,0)=SRC(2,2)=SRC(3,4)=SRC(4,6)= F1(t0,t1);
  600.     SRC(2,1)=SRC(3,3)=SRC(4,5)=SRC(5,7)= F2(t0,t1,t2);
  601.     SRC(2,0)=SRC(3,2)=SRC(4,4)=SRC(5,6)= F1(t1,t2);
  602.     SRC(3,1)=SRC(4,3)=SRC(5,5)=SRC(6,7)= F2(t1,t2,t3);
  603.     SRC(3,0)=SRC(4,2)=SRC(5,4)=SRC(6,6)= F1(t2,t3);
  604.     SRC(4,1)=SRC(5,3)=SRC(6,5)=SRC(7,7)= F2(t2,t3,t4);
  605.     SRC(4,0)=SRC(5,2)=SRC(6,4)=SRC(7,6)= F1(t3,t4);
  606.     SRC(5,1)=SRC(6,3)=SRC(7,5)= F2(t3,t4,t5);
  607.     SRC(5,0)=SRC(6,2)=SRC(7,4)= F1(t4,t5);
  608.     SRC(6,1)=SRC(7,3)= F2(t4,t5,t6);
  609.     SRC(6,0)=SRC(7,2)= F1(t5,t6);
  610.     SRC(7,1)= F2(t5,t6,t7);
  611.     SRC(7,0)= F1(t6,t7);
  612. }
  613. static void predict_8x8_hd( uint8_t *src, uint8_t edge[33] )
  614. {
  615.     PREDICT_8x8_LOAD_TOP
  616.     PREDICT_8x8_LOAD_LEFT
  617.     PREDICT_8x8_LOAD_TOPLEFT
  618.     int p1 = pack8to16(F1(l6,l7), F2(l5,l6,l7));
  619.     int p2 = pack8to16(F1(l5,l6), F2(l4,l5,l6));
  620.     int p3 = pack8to16(F1(l4,l5), F2(l3,l4,l5));
  621.     int p4 = pack8to16(F1(l3,l4), F2(l2,l3,l4));
  622.     int p5 = pack8to16(F1(l2,l3), F2(l1,l2,l3));
  623.     int p6 = pack8to16(F1(l1,l2), F2(l0,l1,l2));
  624.     int p7 = pack8to16(F1(l0,l1), F2(lt,l0,l1));
  625.     int p8 = pack8to16(F1(lt,l0), F2(l0,lt,t0));
  626.     int p9 = pack8to16(F2(t1,t0,lt), F2(t2,t1,t0));
  627.     int p10 = pack8to16(F2(t3,t2,t1), F2(t4,t3,t2));
  628.     int p11 = pack8to16(F2(t5,t4,t3), F2(t6,t5,t4));
  629.     SRC32(0,7)= pack16to32(p1,p2);
  630.     SRC32(0,6)= pack16to32(p2,p3);
  631.     SRC32(4,7)=SRC32(0,5)= pack16to32(p3,p4);
  632.     SRC32(4,6)=SRC32(0,4)= pack16to32(p4,p5);
  633.     SRC32(4,5)=SRC32(0,3)= pack16to32(p5,p6);
  634.     SRC32(4,4)=SRC32(0,2)= pack16to32(p6,p7);
  635.     SRC32(4,3)=SRC32(0,1)= pack16to32(p7,p8);
  636.     SRC32(4,2)=SRC32(0,0)= pack16to32(p8,p9);
  637.     SRC32(4,1)= pack16to32(p9,p10);
  638.     SRC32(4,0)= pack16to32(p10,p11);
  639. }
  640. static void predict_8x8_vl( uint8_t *src, uint8_t edge[33] )
  641. {
  642.     PREDICT_8x8_LOAD_TOP
  643.     PREDICT_8x8_LOAD_TOPRIGHT
  644.     SRC(0,0)= F1(t0,t1);
  645.     SRC(0,1)= F2(t0,t1,t2);
  646.     SRC(0,2)=SRC(1,0)= F1(t1,t2);
  647.     SRC(0,3)=SRC(1,1)= F2(t1,t2,t3);
  648.     SRC(0,4)=SRC(1,2)=SRC(2,0)= F1(t2,t3);
  649.     SRC(0,5)=SRC(1,3)=SRC(2,1)= F2(t2,t3,t4);
  650.     SRC(0,6)=SRC(1,4)=SRC(2,2)=SRC(3,0)= F1(t3,t4);
  651.     SRC(0,7)=SRC(1,5)=SRC(2,3)=SRC(3,1)= F2(t3,t4,t5);
  652.     SRC(1,6)=SRC(2,4)=SRC(3,2)=SRC(4,0)= F1(t4,t5);
  653.     SRC(1,7)=SRC(2,5)=SRC(3,3)=SRC(4,1)= F2(t4,t5,t6);
  654.     SRC(2,6)=SRC(3,4)=SRC(4,2)=SRC(5,0)= F1(t5,t6);
  655.     SRC(2,7)=SRC(3,5)=SRC(4,3)=SRC(5,1)= F2(t5,t6,t7);
  656.     SRC(3,6)=SRC(4,4)=SRC(5,2)=SRC(6,0)= F1(t6,t7);
  657.     SRC(3,7)=SRC(4,5)=SRC(5,3)=SRC(6,1)= F2(t6,t7,t8);
  658.     SRC(4,6)=SRC(5,4)=SRC(6,2)=SRC(7,0)= F1(t7,t8);
  659.     SRC(4,7)=SRC(5,5)=SRC(6,3)=SRC(7,1)= F2(t7,t8,t9);
  660.     SRC(5,6)=SRC(6,4)=SRC(7,2)= F1(t8,t9);
  661.     SRC(5,7)=SRC(6,5)=SRC(7,3)= F2(t8,t9,t10);
  662.     SRC(6,6)=SRC(7,4)= F1(t9,t10);
  663.     SRC(6,7)=SRC(7,5)= F2(t9,t10,t11);
  664.     SRC(7,6)= F1(t10,t11);
  665.     SRC(7,7)= F2(t10,t11,t12);
  666. }
  667. static void predict_8x8_hu( uint8_t *src, uint8_t edge[33] )
  668. {
  669.     PREDICT_8x8_LOAD_LEFT
  670.     int p1 = pack8to16(F1(l0,l1), F2(l0,l1,l2));
  671.     int p2 = pack8to16(F1(l1,l2), F2(l1,l2,l3));
  672.     int p3 = pack8to16(F1(l2,l3), F2(l2,l3,l4));
  673.     int p4 = pack8to16(F1(l3,l4), F2(l3,l4,l5));
  674.     int p5 = pack8to16(F1(l4,l5), F2(l4,l5,l6));
  675.     int p6 = pack8to16(F1(l5,l6), F2(l5,l6,l7));
  676.     int p7 = pack8to16(F1(l6,l7), F2(l6,l7,l7));
  677.     int p8 = pack8to16(l7,l7);
  678.     SRC32(0,0)= pack16to32(p1,p2);
  679.     SRC32(0,1)= pack16to32(p2,p3);
  680.     SRC32(4,0)=SRC32(0,2)= pack16to32(p3,p4);
  681.     SRC32(4,1)=SRC32(0,3)= pack16to32(p4,p5);
  682.     SRC32(4,2)=SRC32(0,4)= pack16to32(p5,p6);
  683.     SRC32(4,3)=SRC32(0,5)= pack16to32(p6,p7);
  684.     SRC32(4,4)=SRC32(0,6)= pack16to32(p7,p8);
  685.     SRC32(4,5)=SRC32(4,6)= SRC32(0,7) = SRC32(4,7) = pack16to32(p8,p8);
  686. }
  687. /****************************************************************************
  688.  * Exported functions:
  689.  ****************************************************************************/
  690. void x264_predict_16x16_init( int cpu, x264_predict_t pf[7] )
  691. {
  692.     pf[I_PRED_16x16_V ]     = predict_16x16_v;
  693.     pf[I_PRED_16x16_H ]     = predict_16x16_h;
  694.     pf[I_PRED_16x16_DC]     = predict_16x16_dc;
  695.     pf[I_PRED_16x16_P ]     = predict_16x16_p;
  696.     pf[I_PRED_16x16_DC_LEFT]= predict_16x16_dc_left;
  697.     pf[I_PRED_16x16_DC_TOP ]= predict_16x16_dc_top;
  698.     pf[I_PRED_16x16_DC_128 ]= predict_16x16_dc_128;
  699. #ifdef HAVE_MMX
  700.     x264_predict_16x16_init_mmx( cpu, pf );
  701. #endif
  702. #ifdef ARCH_PPC
  703.     if( cpu&X264_CPU_ALTIVEC )
  704.     {
  705.         x264_predict_16x16_init_altivec( pf );
  706.     }
  707. #endif
  708. }
  709. void x264_predict_8x8c_init( int cpu, x264_predict_t pf[7] )
  710. {
  711.     pf[I_PRED_CHROMA_V ]     = predict_8x8c_v;
  712.     pf[I_PRED_CHROMA_H ]     = predict_8x8c_h;
  713.     pf[I_PRED_CHROMA_DC]     = predict_8x8c_dc;
  714.     pf[I_PRED_CHROMA_P ]     = predict_8x8c_p;
  715.     pf[I_PRED_CHROMA_DC_LEFT]= predict_8x8c_dc_left;
  716.     pf[I_PRED_CHROMA_DC_TOP ]= predict_8x8c_dc_top;
  717.     pf[I_PRED_CHROMA_DC_128 ]= predict_8x8c_dc_128;
  718. #ifdef HAVE_MMX
  719.     x264_predict_8x8c_init_mmx( cpu, pf );
  720. #endif
  721. }
  722. void x264_predict_8x8_init( int cpu, x264_predict8x8_t pf[12] )
  723. {
  724.     pf[I_PRED_8x8_V]      = predict_8x8_v;
  725.     pf[I_PRED_8x8_H]      = predict_8x8_h;
  726.     pf[I_PRED_8x8_DC]     = predict_8x8_dc;
  727.     pf[I_PRED_8x8_DDL]    = predict_8x8_ddl;
  728.     pf[I_PRED_8x8_DDR]    = predict_8x8_ddr;
  729.     pf[I_PRED_8x8_VR]     = predict_8x8_vr;
  730.     pf[I_PRED_8x8_HD]     = predict_8x8_hd;
  731.     pf[I_PRED_8x8_VL]     = predict_8x8_vl;
  732.     pf[I_PRED_8x8_HU]     = predict_8x8_hu;
  733.     pf[I_PRED_8x8_DC_LEFT]= predict_8x8_dc_left;
  734.     pf[I_PRED_8x8_DC_TOP] = predict_8x8_dc_top;
  735.     pf[I_PRED_8x8_DC_128] = predict_8x8_dc_128;
  736. #ifdef HAVE_MMX
  737.     x264_predict_8x8_init_mmx( cpu, pf );
  738. #endif
  739. }
  740. void x264_predict_4x4_init( int cpu, x264_predict_t pf[12] )
  741. {
  742.     pf[I_PRED_4x4_V]      = predict_4x4_v;
  743.     pf[I_PRED_4x4_H]      = predict_4x4_h;
  744.     pf[I_PRED_4x4_DC]     = predict_4x4_dc;
  745.     pf[I_PRED_4x4_DDL]    = predict_4x4_ddl;
  746.     pf[I_PRED_4x4_DDR]    = predict_4x4_ddr;
  747.     pf[I_PRED_4x4_VR]     = predict_4x4_vr;
  748.     pf[I_PRED_4x4_HD]     = predict_4x4_hd;
  749.     pf[I_PRED_4x4_VL]     = predict_4x4_vl;
  750.     pf[I_PRED_4x4_HU]     = predict_4x4_hu;
  751.     pf[I_PRED_4x4_DC_LEFT]= predict_4x4_dc_left;
  752.     pf[I_PRED_4x4_DC_TOP] = predict_4x4_dc_top;
  753.     pf[I_PRED_4x4_DC_128] = predict_4x4_dc_128;
  754. #ifdef HAVE_MMX
  755.     x264_predict_4x4_init_mmx( cpu, pf );
  756. #endif
  757. }