Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
52867 views
1
/*****************************************************************************
2
* mc-c.c: arm motion compensation
3
*****************************************************************************
4
* Copyright (C) 2009-2016 x264 project
5
*
6
* Authors: David Conrad <[email protected]>
7
* Janne Grunau <[email protected]>
8
*
9
* This program is free software; you can redistribute it and/or modify
10
* it under the terms of the GNU General Public License as published by
11
* the Free Software Foundation; either version 2 of the License, or
12
* (at your option) any later version.
13
*
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
18
*
19
* You should have received a copy of the GNU General Public License
20
* along with this program; if not, write to the Free Software
21
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
22
*
23
* This program is also available under a commercial proprietary license.
24
* For more information, contact us at [email protected].
25
*****************************************************************************/
26
27
#include "common/common.h"
28
#include "mc.h"
29
30
void x264_prefetch_ref_arm( uint8_t *, intptr_t, int );
31
void x264_prefetch_fenc_arm( uint8_t *, intptr_t, uint8_t *, intptr_t, int );
32
33
void *x264_memcpy_aligned_neon( void *dst, const void *src, size_t n );
34
void x264_memzero_aligned_neon( void *dst, size_t n );
35
36
void x264_pixel_avg_16x16_neon( uint8_t *, intptr_t, uint8_t *, intptr_t, uint8_t *, intptr_t, int );
37
void x264_pixel_avg_16x8_neon ( uint8_t *, intptr_t, uint8_t *, intptr_t, uint8_t *, intptr_t, int );
38
void x264_pixel_avg_8x16_neon ( uint8_t *, intptr_t, uint8_t *, intptr_t, uint8_t *, intptr_t, int );
39
void x264_pixel_avg_8x8_neon ( uint8_t *, intptr_t, uint8_t *, intptr_t, uint8_t *, intptr_t, int );
40
void x264_pixel_avg_8x4_neon ( uint8_t *, intptr_t, uint8_t *, intptr_t, uint8_t *, intptr_t, int );
41
void x264_pixel_avg_4x16_neon ( uint8_t *, intptr_t, uint8_t *, intptr_t, uint8_t *, intptr_t, int );
42
void x264_pixel_avg_4x8_neon ( uint8_t *, intptr_t, uint8_t *, intptr_t, uint8_t *, intptr_t, int );
43
void x264_pixel_avg_4x4_neon ( uint8_t *, intptr_t, uint8_t *, intptr_t, uint8_t *, intptr_t, int );
44
void x264_pixel_avg_4x2_neon ( uint8_t *, intptr_t, uint8_t *, intptr_t, uint8_t *, intptr_t, int );
45
46
void x264_pixel_avg2_w4_neon ( uint8_t *, intptr_t, uint8_t *, intptr_t, uint8_t *, int );
47
void x264_pixel_avg2_w8_neon ( uint8_t *, intptr_t, uint8_t *, intptr_t, uint8_t *, int );
48
void x264_pixel_avg2_w16_neon( uint8_t *, intptr_t, uint8_t *, intptr_t, uint8_t *, int );
49
void x264_pixel_avg2_w20_neon( uint8_t *, intptr_t, uint8_t *, intptr_t, uint8_t *, int );
50
51
void x264_plane_copy_neon( pixel *dst, intptr_t i_dst,
52
pixel *src, intptr_t i_src, int w, int h );
53
void x264_plane_copy_deinterleave_neon( pixel *dstu, intptr_t i_dstu,
54
pixel *dstv, intptr_t i_dstv,
55
pixel *src, intptr_t i_src, int w, int h );
56
void x264_plane_copy_deinterleave_rgb_neon( pixel *dsta, intptr_t i_dsta,
57
pixel *dstb, intptr_t i_dstb,
58
pixel *dstc, intptr_t i_dstc,
59
pixel *src, intptr_t i_src, int pw, int w, int h );
60
void x264_plane_copy_interleave_neon( pixel *dst, intptr_t i_dst,
61
pixel *srcu, intptr_t i_srcu,
62
pixel *srcv, intptr_t i_srcv, int w, int h );
63
void x264_plane_copy_swap_neon( pixel *dst, intptr_t i_dst,
64
pixel *src, intptr_t i_src, int w, int h );
65
66
void x264_store_interleave_chroma_neon( pixel *dst, intptr_t i_dst, pixel *srcu, pixel *srcv, int height );
67
void x264_load_deinterleave_chroma_fdec_neon( pixel *dst, pixel *src, intptr_t i_src, int height );
68
void x264_load_deinterleave_chroma_fenc_neon( pixel *dst, pixel *src, intptr_t i_src, int height );
69
70
#if !HIGH_BIT_DEPTH
71
#define MC_WEIGHT(func)\
72
void x264_mc_weight_w20##func##_neon( uint8_t *, intptr_t, uint8_t *, intptr_t, const x264_weight_t *, int );\
73
void x264_mc_weight_w16##func##_neon( uint8_t *, intptr_t, uint8_t *, intptr_t, const x264_weight_t *, int );\
74
void x264_mc_weight_w8##func##_neon ( uint8_t *, intptr_t, uint8_t *, intptr_t, const x264_weight_t *, int );\
75
void x264_mc_weight_w4##func##_neon ( uint8_t *, intptr_t, uint8_t *, intptr_t, const x264_weight_t *, int );\
76
\
77
static weight_fn_t x264_mc##func##_wtab_neon[6] =\
78
{\
79
x264_mc_weight_w4##func##_neon,\
80
x264_mc_weight_w4##func##_neon,\
81
x264_mc_weight_w8##func##_neon,\
82
x264_mc_weight_w16##func##_neon,\
83
x264_mc_weight_w16##func##_neon,\
84
x264_mc_weight_w20##func##_neon,\
85
};
86
87
MC_WEIGHT()
88
MC_WEIGHT(_nodenom)
89
MC_WEIGHT(_offsetadd)
90
MC_WEIGHT(_offsetsub)
91
#endif
92
93
void x264_mc_copy_w4_neon ( uint8_t *, intptr_t, uint8_t *, intptr_t, int );
94
void x264_mc_copy_w8_neon ( uint8_t *, intptr_t, uint8_t *, intptr_t, int );
95
void x264_mc_copy_w16_neon( uint8_t *, intptr_t, uint8_t *, intptr_t, int );
96
void x264_mc_copy_w16_aligned_neon( uint8_t *, intptr_t, uint8_t *, intptr_t, int );
97
98
void x264_mc_chroma_neon( uint8_t *, uint8_t *, intptr_t, uint8_t *, intptr_t, int, int, int, int );
99
void x264_frame_init_lowres_core_neon( uint8_t *, uint8_t *, uint8_t *, uint8_t *, uint8_t *, intptr_t, intptr_t, int, int );
100
101
void x264_hpel_filter_v_neon( uint8_t *, uint8_t *, int16_t *, intptr_t, int );
102
void x264_hpel_filter_c_neon( uint8_t *, int16_t *, int );
103
void x264_hpel_filter_h_neon( uint8_t *, uint8_t *, int );
104
105
void integral_init4h_neon( uint16_t *, uint8_t *, intptr_t );
106
void integral_init4v_neon( uint16_t *, uint16_t *, intptr_t );
107
void integral_init8h_neon( uint16_t *, uint8_t *, intptr_t );
108
void integral_init8v_neon( uint16_t *, intptr_t );
109
110
void x264_mbtree_propagate_cost_neon( int16_t *, uint16_t *, uint16_t *, uint16_t *, uint16_t *, float *, int );
111
112
#if !HIGH_BIT_DEPTH
113
static void x264_weight_cache_neon( x264_t *h, x264_weight_t *w )
114
{
115
if( w->i_scale == 1<<w->i_denom )
116
{
117
if( w->i_offset < 0 )
118
{
119
w->weightfn = x264_mc_offsetsub_wtab_neon;
120
w->cachea[0] = -w->i_offset;
121
}
122
else
123
{
124
w->weightfn = x264_mc_offsetadd_wtab_neon;
125
w->cachea[0] = w->i_offset;
126
}
127
}
128
else if( !w->i_denom )
129
w->weightfn = x264_mc_nodenom_wtab_neon;
130
else
131
w->weightfn = x264_mc_wtab_neon;
132
}
133
134
static void (* const x264_pixel_avg_wtab_neon[6])( uint8_t *, intptr_t, uint8_t *, intptr_t, uint8_t *, int ) =
135
{
136
NULL,
137
x264_pixel_avg2_w4_neon,
138
x264_pixel_avg2_w8_neon,
139
x264_pixel_avg2_w16_neon, // no slower than w12, so no point in a separate function
140
x264_pixel_avg2_w16_neon,
141
x264_pixel_avg2_w20_neon,
142
};
143
144
static void (* const x264_mc_copy_wtab_neon[5])( uint8_t *, intptr_t, uint8_t *, intptr_t, int ) =
145
{
146
NULL,
147
x264_mc_copy_w4_neon,
148
x264_mc_copy_w8_neon,
149
NULL,
150
x264_mc_copy_w16_neon,
151
};
152
153
static void mc_luma_neon( uint8_t *dst, intptr_t i_dst_stride,
154
uint8_t *src[4], intptr_t i_src_stride,
155
int mvx, int mvy,
156
int i_width, int i_height, const x264_weight_t *weight )
157
{
158
int qpel_idx = ((mvy&3)<<2) + (mvx&3);
159
intptr_t offset = (mvy>>2)*i_src_stride + (mvx>>2);
160
uint8_t *src1 = src[x264_hpel_ref0[qpel_idx]] + offset;
161
if ( (mvy&3) == 3 ) // explict if() to force conditional add
162
src1 += i_src_stride;
163
164
if( qpel_idx & 5 ) /* qpel interpolation needed */
165
{
166
uint8_t *src2 = src[x264_hpel_ref1[qpel_idx]] + offset + ((mvx&3) == 3);
167
x264_pixel_avg_wtab_neon[i_width>>2](
168
dst, i_dst_stride, src1, i_src_stride,
169
src2, i_height );
170
if( weight->weightfn )
171
weight->weightfn[i_width>>2]( dst, i_dst_stride, dst, i_dst_stride, weight, i_height );
172
}
173
else if( weight->weightfn )
174
weight->weightfn[i_width>>2]( dst, i_dst_stride, src1, i_src_stride, weight, i_height );
175
else
176
x264_mc_copy_wtab_neon[i_width>>2]( dst, i_dst_stride, src1, i_src_stride, i_height );
177
}
178
179
static uint8_t *get_ref_neon( uint8_t *dst, intptr_t *i_dst_stride,
180
uint8_t *src[4], intptr_t i_src_stride,
181
int mvx, int mvy,
182
int i_width, int i_height, const x264_weight_t *weight )
183
{
184
int qpel_idx = ((mvy&3)<<2) + (mvx&3);
185
intptr_t offset = (mvy>>2)*i_src_stride + (mvx>>2);
186
uint8_t *src1 = src[x264_hpel_ref0[qpel_idx]] + offset;
187
if ( (mvy&3) == 3 ) // explict if() to force conditional add
188
src1 += i_src_stride;
189
190
if( qpel_idx & 5 ) /* qpel interpolation needed */
191
{
192
uint8_t *src2 = src[x264_hpel_ref1[qpel_idx]] + offset + ((mvx&3) == 3);
193
x264_pixel_avg_wtab_neon[i_width>>2](
194
dst, *i_dst_stride, src1, i_src_stride,
195
src2, i_height );
196
if( weight->weightfn )
197
weight->weightfn[i_width>>2]( dst, *i_dst_stride, dst, *i_dst_stride, weight, i_height );
198
return dst;
199
}
200
else if( weight->weightfn )
201
{
202
weight->weightfn[i_width>>2]( dst, *i_dst_stride, src1, i_src_stride, weight, i_height );
203
return dst;
204
}
205
else
206
{
207
*i_dst_stride = i_src_stride;
208
return src1;
209
}
210
}
211
212
static void hpel_filter_neon( uint8_t *dsth, uint8_t *dstv, uint8_t *dstc, uint8_t *src,
213
intptr_t stride, int width, int height, int16_t *buf )
214
{
215
intptr_t realign = (intptr_t)src & 15;
216
src -= realign;
217
dstv -= realign;
218
dstc -= realign;
219
dsth -= realign;
220
width += realign;
221
while( height-- )
222
{
223
x264_hpel_filter_v_neon( dstv, src, buf+8, stride, width );
224
x264_hpel_filter_c_neon( dstc, buf+8, width );
225
x264_hpel_filter_h_neon( dsth, src, width );
226
dsth += stride;
227
dstv += stride;
228
dstc += stride;
229
src += stride;
230
}
231
}
232
#endif // !HIGH_BIT_DEPTH
233
234
PROPAGATE_LIST(neon)
235
236
void x264_mc_init_arm( int cpu, x264_mc_functions_t *pf )
237
{
238
if( !(cpu&X264_CPU_ARMV6) )
239
return;
240
241
#if !HIGH_BIT_DEPTH
242
pf->prefetch_fenc_420 = x264_prefetch_fenc_arm;
243
pf->prefetch_fenc_422 = x264_prefetch_fenc_arm; /* FIXME */
244
pf->prefetch_ref = x264_prefetch_ref_arm;
245
#endif // !HIGH_BIT_DEPTH
246
247
if( !(cpu&X264_CPU_NEON) )
248
return;
249
250
#if !HIGH_BIT_DEPTH
251
pf->copy_16x16_unaligned = x264_mc_copy_w16_neon;
252
pf->copy[PIXEL_16x16] = x264_mc_copy_w16_aligned_neon;
253
pf->copy[PIXEL_8x8] = x264_mc_copy_w8_neon;
254
pf->copy[PIXEL_4x4] = x264_mc_copy_w4_neon;
255
256
pf->plane_copy = x264_plane_copy_neon;
257
pf->plane_copy_deinterleave = x264_plane_copy_deinterleave_neon;
258
pf->plane_copy_deinterleave_rgb = x264_plane_copy_deinterleave_rgb_neon;
259
pf->plane_copy_interleave = x264_plane_copy_interleave_neon;
260
pf->plane_copy_swap = x264_plane_copy_swap_neon;
261
262
pf->store_interleave_chroma = x264_store_interleave_chroma_neon;
263
pf->load_deinterleave_chroma_fdec = x264_load_deinterleave_chroma_fdec_neon;
264
pf->load_deinterleave_chroma_fenc = x264_load_deinterleave_chroma_fenc_neon;
265
266
pf->avg[PIXEL_16x16] = x264_pixel_avg_16x16_neon;
267
pf->avg[PIXEL_16x8] = x264_pixel_avg_16x8_neon;
268
pf->avg[PIXEL_8x16] = x264_pixel_avg_8x16_neon;
269
pf->avg[PIXEL_8x8] = x264_pixel_avg_8x8_neon;
270
pf->avg[PIXEL_8x4] = x264_pixel_avg_8x4_neon;
271
pf->avg[PIXEL_4x16] = x264_pixel_avg_4x16_neon;
272
pf->avg[PIXEL_4x8] = x264_pixel_avg_4x8_neon;
273
pf->avg[PIXEL_4x4] = x264_pixel_avg_4x4_neon;
274
pf->avg[PIXEL_4x2] = x264_pixel_avg_4x2_neon;
275
276
pf->weight = x264_mc_wtab_neon;
277
pf->offsetadd = x264_mc_offsetadd_wtab_neon;
278
pf->offsetsub = x264_mc_offsetsub_wtab_neon;
279
pf->weight_cache = x264_weight_cache_neon;
280
281
pf->mc_chroma = x264_mc_chroma_neon;
282
pf->mc_luma = mc_luma_neon;
283
pf->get_ref = get_ref_neon;
284
pf->hpel_filter = hpel_filter_neon;
285
pf->frame_init_lowres_core = x264_frame_init_lowres_core_neon;
286
287
pf->integral_init4h = integral_init4h_neon;
288
pf->integral_init8h = integral_init8h_neon;
289
pf->integral_init4v = integral_init4v_neon;
290
pf->integral_init8v = integral_init8v_neon;
291
292
pf->mbtree_propagate_cost = x264_mbtree_propagate_cost_neon;
293
pf->mbtree_propagate_list = x264_mbtree_propagate_list_neon;
294
#endif // !HIGH_BIT_DEPTH
295
296
// Apple's gcc stupidly cannot align stack variables, and ALIGNED_ARRAY can't work on structs
297
#ifndef SYS_MACOSX
298
pf->memcpy_aligned = x264_memcpy_aligned_neon;
299
#endif
300
pf->memzero_aligned = x264_memzero_aligned_neon;
301
}
302
303