1 /*****************************************************************************
2 * mc-c.c: h264 encoder library (Motion Compensation)
3 *****************************************************************************
4 * Copyright (C) 2009 x264 project
6 * Authors: David Conrad <lessen42@gmail.com>
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.
21 *****************************************************************************/
23 #include "common/common.h"
26 void x264_prefetch_ref_arm( uint8_t *, int, int );
27 void x264_prefetch_fenc_arm( uint8_t *, int, uint8_t *, int, int );
29 void *x264_memcpy_aligned_neon( void * dst, const void * src, size_t n );
30 void x264_memzero_aligned_neon( void *dst, int n );
32 void x264_pixel_avg_16x16_neon( uint8_t *, int, uint8_t *, int, uint8_t *, int, int );
33 void x264_pixel_avg_16x8_neon( uint8_t *, int, uint8_t *, int, uint8_t *, int, int );
34 void x264_pixel_avg_8x16_neon( uint8_t *, int, uint8_t *, int, uint8_t *, int, int );
35 void x264_pixel_avg_8x8_neon( uint8_t *, int, uint8_t *, int, uint8_t *, int, int );
36 void x264_pixel_avg_8x4_neon( uint8_t *, int, uint8_t *, int, uint8_t *, int, int );
37 void x264_pixel_avg_4x8_neon( uint8_t *, int, uint8_t *, int, uint8_t *, int, int );
38 void x264_pixel_avg_4x4_neon( uint8_t *, int, uint8_t *, int, uint8_t *, int, int );
39 void x264_pixel_avg_4x2_neon( uint8_t *, int, uint8_t *, int, uint8_t *, int, int );
41 void x264_pixel_avg2_w4_neon( uint8_t *, int, uint8_t *, int, uint8_t *, int );
42 void x264_pixel_avg2_w8_neon( uint8_t *, int, uint8_t *, int, uint8_t *, int );
43 void x264_pixel_avg2_w16_neon( uint8_t *, int, uint8_t *, int, uint8_t *, int );
44 void x264_pixel_avg2_w20_neon( uint8_t *, int, uint8_t *, int, uint8_t *, int );
46 void x264_mc_copy_w4_neon( uint8_t *, int, uint8_t *, int, int );
47 void x264_mc_copy_w8_neon( uint8_t *, int, uint8_t *, int, int );
48 void x264_mc_copy_w16_neon( uint8_t *, int, uint8_t *, int, int );
49 void x264_mc_copy_w16_aligned_neon( uint8_t *, int, uint8_t *, int, int );
51 void x264_mc_chroma_neon( uint8_t *, int, uint8_t *, int, int, int, int, int );
52 void x264_frame_init_lowres_core_neon( uint8_t *, uint8_t *, uint8_t *, uint8_t *, uint8_t *, int, int, int, int);
54 static void (* const x264_pixel_avg_wtab_neon[6])( uint8_t *, int, uint8_t *, int, uint8_t *, int ) =
57 x264_pixel_avg2_w4_neon,
58 x264_pixel_avg2_w8_neon,
59 x264_pixel_avg2_w16_neon, // no slower than w12, so no point in a separate function
60 x264_pixel_avg2_w16_neon,
61 x264_pixel_avg2_w20_neon,
64 static void (* const x264_mc_copy_wtab_neon[5])( uint8_t *, int, uint8_t *, int, int ) =
70 x264_mc_copy_w16_neon,
73 static const int hpel_ref0[16] = {0,1,1,1,0,1,1,1,2,3,3,3,0,1,1,1};
74 static const int hpel_ref1[16] = {0,0,0,0,2,2,3,2,2,2,3,2,2,2,3,2};
76 static void mc_luma_neon( uint8_t *dst, int i_dst_stride,
77 uint8_t *src[4], int i_src_stride,
79 int i_width, int i_height, const x264_weight_t *weight )
81 int qpel_idx = ((mvy&3)<<2) + (mvx&3);
82 int offset = (mvy>>2)*i_src_stride + (mvx>>2);
83 uint8_t *src1 = src[hpel_ref0[qpel_idx]] + offset;
84 if ( (mvy&3) == 3 ) // explict if() to force conditional add
87 if( qpel_idx & 5 ) /* qpel interpolation needed */
89 uint8_t *src2 = src[hpel_ref1[qpel_idx]] + offset + ((mvx&3) == 3);
90 x264_pixel_avg_wtab_neon[i_width>>2](
91 dst, i_dst_stride, src1, i_src_stride,
93 if( weight->weightfn )
94 weight->weightfn[i_width>>2]( dst, i_dst_stride, dst, i_dst_stride, weight, i_height );
96 else if( weight->weightfn )
97 weight->weightfn[i_width>>2]( dst, i_dst_stride, src1, i_src_stride, weight, i_height );
99 x264_mc_copy_wtab_neon[i_width>>2]( dst, i_dst_stride, src1, i_src_stride, i_height );
102 static uint8_t *get_ref_neon( uint8_t *dst, int *i_dst_stride,
103 uint8_t *src[4], int i_src_stride,
105 int i_width, int i_height, const x264_weight_t *weight )
107 int qpel_idx = ((mvy&3)<<2) + (mvx&3);
108 int offset = (mvy>>2)*i_src_stride + (mvx>>2);
109 uint8_t *src1 = src[hpel_ref0[qpel_idx]] + offset;
110 if ( (mvy&3) == 3 ) // explict if() to force conditional add
111 src1 += i_src_stride;
113 if( qpel_idx & 5 ) /* qpel interpolation needed */
115 uint8_t *src2 = src[hpel_ref1[qpel_idx]] + offset + ((mvx&3) == 3);
116 x264_pixel_avg_wtab_neon[i_width>>2](
117 dst, *i_dst_stride, src1, i_src_stride,
119 if( weight->weightfn )
120 weight->weightfn[i_width>>2]( dst, *i_dst_stride, dst, *i_dst_stride, weight, i_height );
123 else if( weight->weightfn )
125 weight->weightfn[i_width>>2]( dst, *i_dst_stride, src1, i_src_stride, weight, i_height );
130 *i_dst_stride = i_src_stride;
135 void x264_hpel_filter_v_neon( uint8_t *, uint8_t *, int16_t *, int, int );
136 void x264_hpel_filter_c_neon( uint8_t *, int16_t *, int );
137 void x264_hpel_filter_h_neon( uint8_t *, uint8_t *, int );
139 static void hpel_filter_neon( uint8_t *dsth, uint8_t *dstv, uint8_t *dstc, uint8_t *src,
140 int stride, int width, int height, int16_t *buf )
142 int realign = (intptr_t)src & 15;
150 x264_hpel_filter_v_neon( dstv, src, buf+8, stride, width );
151 x264_hpel_filter_c_neon( dstc, buf+8, width );
152 x264_hpel_filter_h_neon( dsth, src, width );
160 void x264_mc_init_arm( int cpu, x264_mc_functions_t *pf )
162 if( !(cpu&X264_CPU_ARMV6) )
165 pf->prefetch_fenc = x264_prefetch_fenc_arm;
166 pf->prefetch_ref = x264_prefetch_ref_arm;
168 if( !(cpu&X264_CPU_NEON) )
171 pf->copy_16x16_unaligned = x264_mc_copy_w16_neon;
172 pf->copy[PIXEL_16x16] = x264_mc_copy_w16_aligned_neon;
173 pf->copy[PIXEL_8x8] = x264_mc_copy_w8_neon;
174 pf->copy[PIXEL_4x4] = x264_mc_copy_w4_neon;
176 pf->avg[PIXEL_16x16] = x264_pixel_avg_16x16_neon;
177 pf->avg[PIXEL_16x8] = x264_pixel_avg_16x8_neon;
178 pf->avg[PIXEL_8x16] = x264_pixel_avg_8x16_neon;
179 pf->avg[PIXEL_8x8] = x264_pixel_avg_8x8_neon;
180 pf->avg[PIXEL_8x4] = x264_pixel_avg_8x4_neon;
181 pf->avg[PIXEL_4x8] = x264_pixel_avg_4x8_neon;
182 pf->avg[PIXEL_4x4] = x264_pixel_avg_4x4_neon;
183 pf->avg[PIXEL_4x2] = x264_pixel_avg_4x2_neon;
185 pf->memcpy_aligned = x264_memcpy_aligned_neon;
186 pf->memzero_aligned = x264_memzero_aligned_neon;
188 pf->mc_chroma = x264_mc_chroma_neon;
189 pf->mc_luma = mc_luma_neon;
190 pf->get_ref = get_ref_neon;
191 pf->hpel_filter = hpel_filter_neon;
192 pf->frame_init_lowres_core = x264_frame_init_lowres_core_neon;