]> git.sesse.net Git - x264/blob - common/ppc/predict.c
Bump dates to 2016
[x264] / common / ppc / predict.c
1 /*****************************************************************************
2  * predict.c: ppc intra prediction
3  *****************************************************************************
4  * Copyright (C) 2007-2016 x264 project
5  *
6  * Authors: Guillaume Poirier <gpoirier@mplayerhq.hu>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111, USA.
21  *
22  * This program is also available under a commercial proprietary license.
23  * For more information, contact us at licensing@x264.com.
24  *****************************************************************************/
25
26 #include "common/common.h"
27 #include "predict.h"
28 #include "pixel.h"
29 #include "ppccommon.h"
30
31 #if !HIGH_BIT_DEPTH
32 static void predict_8x8c_p_altivec( uint8_t *src )
33 {
34     int H = 0, V = 0;
35
36     for( int i = 0; i < 4; i++ )
37     {
38         H += ( i + 1 ) * ( src[4+i - FDEC_STRIDE] - src[2 - i -FDEC_STRIDE] );
39         V += ( i + 1 ) * ( src[-1 +(i+4)*FDEC_STRIDE] - src[-1+(2-i)*FDEC_STRIDE] );
40     }
41
42     int a = 16 * ( src[-1+7*FDEC_STRIDE] + src[7 - FDEC_STRIDE] );
43     int b = ( 17 * H + 16 ) >> 5;
44     int c = ( 17 * V + 16 ) >> 5;
45     int i00 = a -3*b -3*c + 16;
46
47     vec_s16_u i00_u, b_u, c_u;
48     i00_u.s[0] = i00;
49     b_u.s[0]   = b;
50     c_u.s[0]   = c;
51
52     vec_u16_t val5_v = vec_splat_u16(5);
53     vec_s16_t i00_v, b_v, c_v;
54     i00_v = vec_splat(i00_u.v, 0);
55     b_v = vec_splat(b_u.v, 0);
56     c_v = vec_splat(c_u.v, 0);
57
58     vec_s16_t induc_v  = (vec_s16_t) CV(0, 1, 2, 3, 4, 5, 6, 7);
59     vec_s16_t add_i0_b_0v = vec_mladd(induc_v, b_v, i00_v);
60
61     PREP_STORE8;
62
63     for( int i = 0; i < 8; ++i )
64     {
65         vec_s16_t shift_0_v = vec_sra(add_i0_b_0v, val5_v);
66         vec_u8_t com_sat_v = vec_packsu(shift_0_v, shift_0_v);
67         VEC_STORE8(com_sat_v, &src[0]);
68         src += FDEC_STRIDE;
69         add_i0_b_0v = vec_adds(add_i0_b_0v, c_v);
70
71     }
72 }
73
74
75 /****************************************************************************
76  * 16x16 prediction for intra luma block
77  ****************************************************************************/
78
79 static void predict_16x16_p_altivec( uint8_t *src )
80 {
81     int H = 0, V = 0;
82
83     for( int i = 1; i <= 8; i++ )
84     {
85         H += i * ( src[7+i - FDEC_STRIDE ]  - src[7-i - FDEC_STRIDE ] );
86         V += i * ( src[(7+i)*FDEC_STRIDE -1] - src[(7-i)*FDEC_STRIDE -1] );
87     }
88
89     int a = 16 * ( src[15*FDEC_STRIDE -1] + src[15 - FDEC_STRIDE] );
90     int b = ( 5 * H + 32 ) >> 6;
91     int c = ( 5 * V + 32 ) >> 6;
92     int i00 = a - b * 7 - c * 7 + 16;
93
94     vec_s16_u i00_u, b_u, c_u;
95     i00_u.s[0] = i00;
96     b_u.s[0]   = b;
97     c_u.s[0]   = c;
98
99     vec_u16_t val5_v = vec_splat_u16(5);
100     vec_s16_t i00_v, b_v, c_v;
101     i00_v = vec_splat(i00_u.v, 0);
102     b_v = vec_splat(b_u.v, 0);
103     c_v = vec_splat(c_u.v, 0);
104     vec_s16_t induc_v  = (vec_s16_t) CV(0,  1,  2,  3,  4,  5,  6,  7);
105     vec_s16_t b8_v = vec_sl(b_v, vec_splat_u16(3));
106     vec_s16_t add_i0_b_0v = vec_mladd(induc_v, b_v, i00_v);
107     vec_s16_t add_i0_b_8v = vec_adds(b8_v, add_i0_b_0v);
108
109     for( int y = 0; y < 16; y++ )
110     {
111         vec_s16_t shift_0_v = vec_sra(add_i0_b_0v, val5_v);
112         vec_s16_t shift_8_v = vec_sra(add_i0_b_8v, val5_v);
113         vec_u8_t com_sat_v = vec_packsu(shift_0_v, shift_8_v);
114         vec_st( com_sat_v, 0, &src[0]);
115         src += FDEC_STRIDE;
116         add_i0_b_0v = vec_adds(add_i0_b_0v, c_v);
117         add_i0_b_8v = vec_adds(add_i0_b_8v, c_v);
118     }
119 }
120
121 #define PREDICT_16x16_DC_ALTIVEC(v) \
122 for( int i = 0; i < 16; i += 2)     \
123 {                                   \
124     vec_st(v, 0, src);              \
125     vec_st(v, FDEC_STRIDE, src);    \
126     src += FDEC_STRIDE*2;           \
127 }
128
129 static void predict_16x16_dc_altivec( uint8_t *src )
130 {
131     uint32_t dc = 0;
132
133     for( int i = 0; i < 16; i++ )
134     {
135         dc += src[-1 + i * FDEC_STRIDE];
136         dc += src[i - FDEC_STRIDE];
137     }
138     vec_u8_u v ; v.s[0] = (( dc + 16 ) >> 5);
139     vec_u8_t bc_v = vec_splat(v.v, 0);
140
141     PREDICT_16x16_DC_ALTIVEC(bc_v);
142 }
143
144 static void predict_16x16_dc_left_altivec( uint8_t *src )
145 {
146     uint32_t dc = 0;
147
148     for( int i = 0; i < 16; i++ )
149         dc += src[-1 + i * FDEC_STRIDE];
150     vec_u8_u v ; v.s[0] = (( dc + 8 ) >> 4);
151     vec_u8_t bc_v = vec_splat(v.v, 0);
152
153     PREDICT_16x16_DC_ALTIVEC(bc_v);
154 }
155
156 static void predict_16x16_dc_top_altivec( uint8_t *src )
157 {
158     uint32_t dc = 0;
159
160     for( int i = 0; i < 16; i++ )
161         dc += src[i - FDEC_STRIDE];
162     vec_u8_u v ; v.s[0] = (( dc + 8 ) >> 4);
163     vec_u8_t bc_v = vec_splat(v.v, 0);
164
165     PREDICT_16x16_DC_ALTIVEC(bc_v);
166 }
167
168 static void predict_16x16_dc_128_altivec( uint8_t *src )
169 {
170     /* test if generating the constant is faster than loading it.
171     vector unsigned int bc_v = (vector unsigned int)CV(0x80808080, 0x80808080, 0x80808080, 0x80808080);
172     */
173     vec_u8_t bc_v = vec_vslb((vec_u8_t)vec_splat_u8(1),(vec_u8_t)vec_splat_u8(7));
174     PREDICT_16x16_DC_ALTIVEC(bc_v);
175 }
176
177 static void predict_16x16_h_altivec( uint8_t *src )
178 {
179     for( int i = 0; i < 16; i++ )
180     {
181         vec_u8_t v = vec_ld(-1, src);
182         vec_u8_t v_v = vec_splat(v, 15);
183         vec_st(v_v, 0, src);
184
185         src += FDEC_STRIDE;
186     }
187 }
188
189 static void predict_16x16_v_altivec( uint8_t *src )
190 {
191     vec_u32_u v;
192     v.s[0] = *(uint32_t*)&src[ 0-FDEC_STRIDE];
193     v.s[1] = *(uint32_t*)&src[ 4-FDEC_STRIDE];
194     v.s[2] = *(uint32_t*)&src[ 8-FDEC_STRIDE];
195     v.s[3] = *(uint32_t*)&src[12-FDEC_STRIDE];
196
197     for( int i = 0; i < 16; i++ )
198     {
199         vec_st(v.v, 0, (uint32_t*)src);
200         src += FDEC_STRIDE;
201     }
202 }
203 #endif // !HIGH_BIT_DEPTH
204
205
206 /****************************************************************************
207  * Exported functions:
208  ****************************************************************************/
209 void x264_predict_16x16_init_altivec( x264_predict_t pf[7] )
210 {
211 #if !HIGH_BIT_DEPTH
212     pf[I_PRED_16x16_V ]      = predict_16x16_v_altivec;
213     pf[I_PRED_16x16_H ]      = predict_16x16_h_altivec;
214     pf[I_PRED_16x16_DC]      = predict_16x16_dc_altivec;
215     pf[I_PRED_16x16_P ]      = predict_16x16_p_altivec;
216     pf[I_PRED_16x16_DC_LEFT] = predict_16x16_dc_left_altivec;
217     pf[I_PRED_16x16_DC_TOP ] = predict_16x16_dc_top_altivec;
218     pf[I_PRED_16x16_DC_128 ] = predict_16x16_dc_128_altivec;
219 #endif // !HIGH_BIT_DEPTH
220 }
221
222 void x264_predict_8x8c_init_altivec( x264_predict_t pf[7] )
223 {
224 #if !HIGH_BIT_DEPTH
225     pf[I_PRED_CHROMA_P]       = predict_8x8c_p_altivec;
226 #endif // !HIGH_BIT_DEPTH
227 }