]> git.sesse.net Git - x264/blob - common/ppc/predict.c
Update file headers throughout x264
[x264] / common / ppc / predict.c
1 /*****************************************************************************
2  * predict.c: h264 encoder
3  *****************************************************************************
4  * Copyright (C) 2007-2008 Guillaume Poirier <gpoirier@mplayerhq.hu>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111, USA.
19  *****************************************************************************/
20
21 #ifdef SYS_LINUX
22 #include <altivec.h>
23 #endif
24
25 #include "common/common.h"
26 #include "predict.h"
27 #include "pixel.h"
28 #include "ppccommon.h"
29
30 static void predict_16x16_p_altivec( uint8_t *src )
31 {
32     int16_t a, b, c, i;
33     int H = 0;
34     int V = 0;
35     int16_t i00;
36
37     for( i = 1; i <= 8; i++ )
38     {
39         H += i * ( src[7+i - FDEC_STRIDE ]  - src[7-i - FDEC_STRIDE ] );
40         V += i * ( src[(7+i)*FDEC_STRIDE -1] - src[(7-i)*FDEC_STRIDE -1] );
41     }
42
43     a = 16 * ( src[15*FDEC_STRIDE -1] + src[15 - FDEC_STRIDE] );
44     b = ( 5 * H + 32 ) >> 6;
45     c = ( 5 * V + 32 ) >> 6;
46     i00 = a - b * 7 - c * 7 + 16;
47
48     vect_sshort_u i00_u, b_u, c_u;
49     i00_u.s[0] = i00;
50     b_u.s[0]   = b;
51     c_u.s[0]   = c;
52
53     vec_u16_t val5_v = vec_splat_u16(5);
54     vec_s16_t i00_v, b_v, c_v;
55     i00_v = vec_splat(i00_u.v, 0);
56     b_v = vec_splat(b_u.v, 0);
57     c_v = vec_splat(c_u.v, 0);
58     vec_s16_t induc_v  = (vec_s16_t) CV(0,  1,  2,  3,  4,  5,  6,  7);
59     vec_s16_t b8_v = vec_sl(b_v, vec_splat_u16(3));
60     vec_s32_t mule_b_v = vec_mule(induc_v, b_v);
61     vec_s32_t mulo_b_v = vec_mulo(induc_v, b_v);
62     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));
63     vec_s16_t add_i0_b_0v = vec_adds(i00_v, mul_b_induc0_v);
64     vec_s16_t add_i0_b_8v = vec_adds(b8_v, add_i0_b_0v);
65
66     int y;
67
68     for( y = 0; y < 16; y++ )
69     {
70         vec_s16_t shift_0_v = vec_sra(add_i0_b_0v, val5_v);
71         vec_s16_t shift_8_v = vec_sra(add_i0_b_8v, val5_v);
72         vec_u8_t com_sat_v = vec_packsu(shift_0_v, shift_8_v);
73         vec_st( com_sat_v, 0, &src[0]);
74         src += FDEC_STRIDE;
75         i00 += c;
76         add_i0_b_0v = vec_adds(add_i0_b_0v, c_v);
77         add_i0_b_8v = vec_adds(add_i0_b_8v, c_v);
78     }
79 }
80
81 /****************************************************************************
82  * Exported functions:
83  ****************************************************************************/
84 void x264_predict_16x16_init_altivec( x264_predict_t pf[7] )
85 {
86     pf[I_PRED_16x16_P]       = predict_16x16_p_altivec;
87 }