]> git.sesse.net Git - x264/blob - common/arm/mc-c.c
MBAFF: Add extra data to the deblock strength structure
[x264] / common / arm / mc-c.c
1 /*****************************************************************************
2  * mc-c.c: arm motion compensation
3  *****************************************************************************
4  * Copyright (C) 2009-2011 x264 project
5  *
6  * Authors: David Conrad <lessen42@gmail.com>
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 "mc.h"
28
29 void x264_prefetch_ref_arm( uint8_t *, int, int );
30 void x264_prefetch_fenc_arm( uint8_t *, int, uint8_t *, int, int );
31
32 void *x264_memcpy_aligned_neon( void * dst, const void * src, size_t n );
33 void x264_memzero_aligned_neon( void *dst, int n );
34
35 void x264_pixel_avg_16x16_neon( uint8_t *, int, uint8_t *, int, uint8_t *, int, int );
36 void x264_pixel_avg_16x8_neon( uint8_t *, int, uint8_t *, int, uint8_t *, int, int );
37 void x264_pixel_avg_8x16_neon( uint8_t *, int, uint8_t *, int, uint8_t *, int, int );
38 void x264_pixel_avg_8x8_neon( uint8_t *, int, uint8_t *, int, uint8_t *, int, int );
39 void x264_pixel_avg_8x4_neon( uint8_t *, int, uint8_t *, int, uint8_t *, int, int );
40 void x264_pixel_avg_4x8_neon( uint8_t *, int, uint8_t *, int, uint8_t *, int, int );
41 void x264_pixel_avg_4x4_neon( uint8_t *, int, uint8_t *, int, uint8_t *, int, int );
42 void x264_pixel_avg_4x2_neon( uint8_t *, int, uint8_t *, int, uint8_t *, int, int );
43
44 void x264_pixel_avg2_w4_neon( uint8_t *, int, uint8_t *, int, uint8_t *, int );
45 void x264_pixel_avg2_w8_neon( uint8_t *, int, uint8_t *, int, uint8_t *, int );
46 void x264_pixel_avg2_w16_neon( uint8_t *, int, uint8_t *, int, uint8_t *, int );
47 void x264_pixel_avg2_w20_neon( uint8_t *, int, uint8_t *, int, uint8_t *, int );
48
49 #define MC_WEIGHT(func)\
50 void x264_mc_weight_w20##func##_neon( uint8_t *, int, uint8_t *, int, const x264_weight_t *, int );\
51 void x264_mc_weight_w16##func##_neon( uint8_t *, int, uint8_t *, int, const x264_weight_t *, int );\
52 void x264_mc_weight_w8##func##_neon( uint8_t *, int, uint8_t *, int, const x264_weight_t *, int );\
53 void x264_mc_weight_w4##func##_neon( uint8_t *, int, uint8_t *, int, const x264_weight_t *, int );\
54 \
55 static void (* const x264_mc##func##_wtab_neon[6])( uint8_t *, int, uint8_t *, int, const x264_weight_t *, int ) =\
56 {\
57     x264_mc_weight_w4##func##_neon,\
58     x264_mc_weight_w4##func##_neon,\
59     x264_mc_weight_w8##func##_neon,\
60     x264_mc_weight_w16##func##_neon,\
61     x264_mc_weight_w16##func##_neon,\
62     x264_mc_weight_w20##func##_neon,\
63 };
64
65 MC_WEIGHT()
66 MC_WEIGHT(_nodenom)
67 MC_WEIGHT(_offsetadd)
68 MC_WEIGHT(_offsetsub)
69
70 void x264_mc_copy_w4_neon( uint8_t *, int, uint8_t *, int, int );
71 void x264_mc_copy_w8_neon( uint8_t *, int, uint8_t *, int, int );
72 void x264_mc_copy_w16_neon( uint8_t *, int, uint8_t *, int, int );
73 void x264_mc_copy_w16_aligned_neon( uint8_t *, int, uint8_t *, int, int );
74
75 void x264_mc_chroma_neon( uint8_t *, int, uint8_t *, int, int, int, int, int );
76 void x264_frame_init_lowres_core_neon( uint8_t *, uint8_t *, uint8_t *, uint8_t *, uint8_t *, int, int, int, int);
77
78 void x264_hpel_filter_v_neon( uint8_t *, uint8_t *, int16_t *, int, int );
79 void x264_hpel_filter_c_neon( uint8_t *, int16_t *, int );
80 void x264_hpel_filter_h_neon( uint8_t *, uint8_t *, int );
81
82 #if !HIGH_BIT_DEPTH
83 static void x264_weight_cache_neon( x264_t *h, x264_weight_t *w )
84 {
85     if( w->i_scale == 1<<w->i_denom )
86     {
87         if( w->i_offset < 0 )
88         {
89             w->weightfn = x264_mc_offsetsub_wtab_neon;
90             w->cachea[0] = -w->i_offset;
91         }
92         else
93         {
94             w->weightfn = x264_mc_offsetadd_wtab_neon;
95             w->cachea[0] = w->i_offset;
96         }
97     }
98     else if( !w->i_denom )
99         w->weightfn = x264_mc_nodenom_wtab_neon;
100     else
101         w->weightfn = x264_mc_wtab_neon;
102 }
103
104 static void (* const x264_pixel_avg_wtab_neon[6])( uint8_t *, int, uint8_t *, int, uint8_t *, int ) =
105 {
106     NULL,
107     x264_pixel_avg2_w4_neon,
108     x264_pixel_avg2_w8_neon,
109     x264_pixel_avg2_w16_neon,   // no slower than w12, so no point in a separate function
110     x264_pixel_avg2_w16_neon,
111     x264_pixel_avg2_w20_neon,
112 };
113
114 static void (* const x264_mc_copy_wtab_neon[5])( uint8_t *, int, uint8_t *, int, int ) =
115 {
116     NULL,
117     x264_mc_copy_w4_neon,
118     x264_mc_copy_w8_neon,
119     NULL,
120     x264_mc_copy_w16_neon,
121 };
122
123 static const uint8_t hpel_ref0[16] = {0,1,1,1,0,1,1,1,2,3,3,3,0,1,1,1};
124 static const uint8_t hpel_ref1[16] = {0,0,0,0,2,2,3,2,2,2,3,2,2,2,3,2};
125
126 static void mc_luma_neon( uint8_t *dst,    int i_dst_stride,
127                           uint8_t *src[4], int i_src_stride,
128                           int mvx, int mvy,
129                           int i_width, int i_height, const x264_weight_t *weight )
130 {
131     int qpel_idx = ((mvy&3)<<2) + (mvx&3);
132     int offset = (mvy>>2)*i_src_stride + (mvx>>2);
133     uint8_t *src1 = src[hpel_ref0[qpel_idx]] + offset;
134     if ( (mvy&3) == 3 )             // explict if() to force conditional add
135         src1 += i_src_stride;
136
137     if( qpel_idx & 5 ) /* qpel interpolation needed */
138     {
139         uint8_t *src2 = src[hpel_ref1[qpel_idx]] + offset + ((mvx&3) == 3);
140         x264_pixel_avg_wtab_neon[i_width>>2](
141                 dst, i_dst_stride, src1, i_src_stride,
142                 src2, i_height );
143         if( weight->weightfn )
144             weight->weightfn[i_width>>2]( dst, i_dst_stride, dst, i_dst_stride, weight, i_height );
145     }
146     else if( weight->weightfn )
147         weight->weightfn[i_width>>2]( dst, i_dst_stride, src1, i_src_stride, weight, i_height );
148     else
149         x264_mc_copy_wtab_neon[i_width>>2]( dst, i_dst_stride, src1, i_src_stride, i_height );
150 }
151
152 static uint8_t *get_ref_neon( uint8_t *dst,   int *i_dst_stride,
153                               uint8_t *src[4], int i_src_stride,
154                               int mvx, int mvy,
155                               int i_width, int i_height, const x264_weight_t *weight )
156 {
157     int qpel_idx = ((mvy&3)<<2) + (mvx&3);
158     int offset = (mvy>>2)*i_src_stride + (mvx>>2);
159     uint8_t *src1 = src[hpel_ref0[qpel_idx]] + offset;
160     if ( (mvy&3) == 3 )             // explict if() to force conditional add
161         src1 += i_src_stride;
162
163     if( qpel_idx & 5 ) /* qpel interpolation needed */
164     {
165         uint8_t *src2 = src[hpel_ref1[qpel_idx]] + offset + ((mvx&3) == 3);
166         x264_pixel_avg_wtab_neon[i_width>>2](
167                 dst, *i_dst_stride, src1, i_src_stride,
168                 src2, i_height );
169         if( weight->weightfn )
170             weight->weightfn[i_width>>2]( dst, *i_dst_stride, dst, *i_dst_stride, weight, i_height );
171         return dst;
172     }
173     else if( weight->weightfn )
174     {
175         weight->weightfn[i_width>>2]( dst, *i_dst_stride, src1, i_src_stride, weight, i_height );
176         return dst;
177     }
178     else
179     {
180         *i_dst_stride = i_src_stride;
181         return src1;
182     }
183 }
184
185 static void hpel_filter_neon( uint8_t *dsth, uint8_t *dstv, uint8_t *dstc, uint8_t *src,
186                               int stride, int width, int height, int16_t *buf )
187 {
188     int realign = (intptr_t)src & 15;
189     src -= realign;
190     dstv -= realign;
191     dstc -= realign;
192     dsth -= realign;
193     width += realign;
194     while( height-- )
195     {
196         x264_hpel_filter_v_neon( dstv, src, buf+8, stride, width );
197         x264_hpel_filter_c_neon( dstc, buf+8, width );
198         x264_hpel_filter_h_neon( dsth, src, width );
199         dsth += stride;
200         dstv += stride;
201         dstc += stride;
202         src  += stride;
203     }
204 }
205 #endif // !HIGH_BIT_DEPTH
206
207 void x264_mc_init_arm( int cpu, x264_mc_functions_t *pf )
208 {
209     if( !(cpu&X264_CPU_ARMV6) )
210         return;
211
212 #if !HIGH_BIT_DEPTH
213     pf->prefetch_fenc = x264_prefetch_fenc_arm;
214     pf->prefetch_ref  = x264_prefetch_ref_arm;
215 #endif // !HIGH_BIT_DEPTH
216
217     if( !(cpu&X264_CPU_NEON) )
218         return;
219
220 #if !HIGH_BIT_DEPTH
221     pf->copy_16x16_unaligned = x264_mc_copy_w16_neon;
222     pf->copy[PIXEL_16x16] = x264_mc_copy_w16_aligned_neon;
223     pf->copy[PIXEL_8x8]   = x264_mc_copy_w8_neon;
224     pf->copy[PIXEL_4x4]   = x264_mc_copy_w4_neon;
225
226     pf->avg[PIXEL_16x16] = x264_pixel_avg_16x16_neon;
227     pf->avg[PIXEL_16x8]  = x264_pixel_avg_16x8_neon;
228     pf->avg[PIXEL_8x16]  = x264_pixel_avg_8x16_neon;
229     pf->avg[PIXEL_8x8]   = x264_pixel_avg_8x8_neon;
230     pf->avg[PIXEL_8x4]   = x264_pixel_avg_8x4_neon;
231     pf->avg[PIXEL_4x8]   = x264_pixel_avg_4x8_neon;
232     pf->avg[PIXEL_4x4]   = x264_pixel_avg_4x4_neon;
233     pf->avg[PIXEL_4x2]   = x264_pixel_avg_4x2_neon;
234
235     pf->weight    = x264_mc_wtab_neon;
236     pf->offsetadd = x264_mc_offsetadd_wtab_neon;
237     pf->offsetsub = x264_mc_offsetsub_wtab_neon;
238     pf->weight_cache = x264_weight_cache_neon;
239
240 //  pf->mc_chroma = x264_mc_chroma_neon;
241     pf->mc_luma = mc_luma_neon;
242     pf->get_ref = get_ref_neon;
243     pf->hpel_filter = hpel_filter_neon;
244     pf->frame_init_lowres_core = x264_frame_init_lowres_core_neon;
245 #endif // !HIGH_BIT_DEPTH
246
247 // Apple's gcc stupidly cannot align stack variables, and ALIGNED_ARRAY can't work on structs
248 #ifndef SYS_MACOSX
249     pf->memcpy_aligned  = x264_memcpy_aligned_neon;
250 #endif
251     pf->memzero_aligned = x264_memzero_aligned_neon;
252 }