1 /*****************************************************************************
2 * predict.c: ppc intra prediction
3 *****************************************************************************
4 * Copyright (C) 2007-2010 x264 project
6 * Authors: Guillaume Poirier <gpoirier@mplayerhq.hu>
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.
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.
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.
22 * This program is also available under a commercial proprietary license.
23 * For more information, contact us at licensing@x264.com.
24 *****************************************************************************/
26 #include "common/common.h"
29 #include "ppccommon.h"
31 #if !X264_HIGH_BIT_DEPTH
32 static void predict_8x8c_p_altivec( uint8_t *src )
36 for( int i = 0; i < 4; i++ )
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] );
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;
47 vec_s16_u i00_u, b_u, c_u;
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);
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);
63 for( int i = 0; i < 8; ++i )
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]);
69 add_i0_b_0v = vec_adds(add_i0_b_0v, c_v);
75 /****************************************************************************
76 * 16x16 prediction for intra luma block
77 ****************************************************************************/
79 static void predict_16x16_p_altivec( uint8_t *src )
83 for( int i = 1; i <= 8; i++ )
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] );
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;
94 vec_s16_u i00_u, b_u, c_u;
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);
109 for( int y = 0; y < 16; y++ )
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]);
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);
121 #define PREDICT_16x16_DC_ALTIVEC(v) \
122 for( int i = 0; i < 16; i += 2) \
125 vec_st(v, FDEC_STRIDE, src); \
126 src += FDEC_STRIDE*2; \
129 static void predict_16x16_dc_altivec( uint8_t *src )
133 for( int i = 0; i < 16; i++ )
135 dc += src[-1 + i * FDEC_STRIDE];
136 dc += src[i - FDEC_STRIDE];
138 vec_u8_u v ; v.s[0] = (( dc + 16 ) >> 5);
139 vec_u8_t bc_v = vec_splat(v.v, 0);
141 PREDICT_16x16_DC_ALTIVEC(bc_v);
144 static void predict_16x16_dc_left_altivec( uint8_t *src )
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);
153 PREDICT_16x16_DC_ALTIVEC(bc_v);
156 static void predict_16x16_dc_top_altivec( uint8_t *src )
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);
165 PREDICT_16x16_DC_ALTIVEC(bc_v);
168 static void predict_16x16_dc_128_altivec( uint8_t *src )
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);
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);
177 static void predict_16x16_h_altivec( uint8_t *src )
179 for( int i = 0; i < 16; i++ )
181 vec_u8_t v = vec_ld(-1, src);
182 vec_u8_t v_v = vec_splat(v, 15);
189 static void predict_16x16_v_altivec( uint8_t *src )
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];
197 for( int i = 0; i < 16; i++ )
199 vec_st(v.v, 0, (uint32_t*)src);
203 #endif // !X264_HIGH_BIT_DEPTH
206 /****************************************************************************
207 * Exported functions:
208 ****************************************************************************/
209 void x264_predict_16x16_init_altivec( x264_predict_t pf[7] )
211 #if !X264_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 // !X264_HIGH_BIT_DEPTH
222 void x264_predict_8x8c_init_altivec( x264_predict_t pf[7] )
224 #if !X264_HIGH_BIT_DEPTH
225 pf[I_PRED_CHROMA_P] = predict_8x8c_p_altivec;
226 #endif // !X264_HIGH_BIT_DEPTH