reconinter_enc_neon.c (10629B)
1 /* 2 * Copyright (c) 2023, Alliance for Open Media. All rights reserved. 3 * 4 * This source code is subject to the terms of the BSD 2 Clause License and 5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License 6 * was not distributed with this source code in the LICENSE file, you can 7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open 8 * Media Patent License 1.0 was not distributed with this source code in the 9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent. 10 */ 11 12 #include <arm_neon.h> 13 #include <assert.h> 14 15 #include "config/aom_config.h" 16 #include "config/aom_dsp_rtcd.h" 17 18 #include "aom_dsp/arm/mem_neon.h" 19 20 #include "av1/encoder/reconinter_enc.h" 21 22 void aom_upsampled_pred_neon(MACROBLOCKD *xd, const AV1_COMMON *const cm, 23 int mi_row, int mi_col, const MV *const mv, 24 uint8_t *comp_pred, int width, int height, 25 int subpel_x_q3, int subpel_y_q3, 26 const uint8_t *ref, int ref_stride, 27 int subpel_search) { 28 // expect xd == NULL only in tests 29 if (xd != NULL) { 30 const MB_MODE_INFO *mi = xd->mi[0]; 31 const int ref_num = 0; 32 const int is_intrabc = is_intrabc_block(mi); 33 const struct scale_factors *const sf = 34 is_intrabc ? &cm->sf_identity : xd->block_ref_scale_factors[ref_num]; 35 const int is_scaled = av1_is_scaled(sf); 36 37 if (is_scaled) { 38 int plane = 0; 39 const int mi_x = mi_col * MI_SIZE; 40 const int mi_y = mi_row * MI_SIZE; 41 const struct macroblockd_plane *const pd = &xd->plane[plane]; 42 const struct buf_2d *const dst_buf = &pd->dst; 43 const struct buf_2d *const pre_buf = 44 is_intrabc ? dst_buf : &pd->pre[ref_num]; 45 46 InterPredParams inter_pred_params; 47 inter_pred_params.conv_params = get_conv_params(0, plane, xd->bd); 48 const int_interpfilters filters = 49 av1_broadcast_interp_filter(EIGHTTAP_REGULAR); 50 av1_init_inter_params( 51 &inter_pred_params, width, height, mi_y >> pd->subsampling_y, 52 mi_x >> pd->subsampling_x, pd->subsampling_x, pd->subsampling_y, 53 xd->bd, is_cur_buf_hbd(xd), is_intrabc, sf, pre_buf, filters); 54 av1_enc_build_one_inter_predictor(comp_pred, width, mv, 55 &inter_pred_params); 56 return; 57 } 58 } 59 60 const InterpFilterParams *filter_params = av1_get_filter(subpel_search); 61 62 if (!subpel_x_q3 && !subpel_y_q3) { 63 if (width > 8) { 64 assert(width % 16 == 0); 65 int i = height; 66 do { 67 int j = 0; 68 do { 69 uint8x16_t r = vld1q_u8(ref + j); 70 vst1q_u8(comp_pred + j, r); 71 j += 16; 72 } while (j < width); 73 ref += ref_stride; 74 comp_pred += width; 75 } while (--i != 0); 76 } else if (width == 8) { 77 int i = height; 78 do { 79 uint8x8_t r = vld1_u8(ref); 80 vst1_u8(comp_pred, r); 81 ref += ref_stride; 82 comp_pred += width; 83 } while (--i != 0); 84 } else { 85 assert(width == 4); 86 int i = height / 2; 87 do { 88 uint8x8_t r = load_unaligned_u8(ref, ref_stride); 89 vst1_u8(comp_pred, r); 90 ref += 2 * ref_stride; 91 comp_pred += 2 * width; 92 } while (--i != 0); 93 } 94 } else if (!subpel_y_q3) { 95 const int16_t *const filter_x = 96 av1_get_interp_filter_subpel_kernel(filter_params, subpel_x_q3 << 1); 97 aom_convolve8_horiz(ref, ref_stride, comp_pred, width, filter_x, 16, NULL, 98 -1, width, height); 99 } else if (!subpel_x_q3) { 100 const int16_t *const filter_y = 101 av1_get_interp_filter_subpel_kernel(filter_params, subpel_y_q3 << 1); 102 aom_convolve8_vert(ref, ref_stride, comp_pred, width, NULL, -1, filter_y, 103 16, width, height); 104 } else { 105 DECLARE_ALIGNED(16, uint8_t, 106 im_block[((MAX_SB_SIZE * 2 + 16) + 16) * MAX_SB_SIZE]); 107 108 const int16_t *const filter_x = 109 av1_get_interp_filter_subpel_kernel(filter_params, subpel_x_q3 << 1); 110 const int16_t *const filter_y = 111 av1_get_interp_filter_subpel_kernel(filter_params, subpel_y_q3 << 1); 112 113 const int im_stride = MAX_SB_SIZE; 114 const int im_height = (((height - 1) * 8 + subpel_y_q3) >> 3) + SUBPEL_TAPS; 115 116 const int ref_vert_offset = ref_stride * ((SUBPEL_TAPS >> 1) - 1); 117 const int im_vert_offset = im_stride * ((filter_params->taps >> 1) - 1); 118 119 assert(im_height <= (MAX_SB_SIZE * 2 + 16) + 16); 120 aom_convolve8_horiz(ref - ref_vert_offset, ref_stride, im_block, 121 MAX_SB_SIZE, filter_x, 16, NULL, -1, width, im_height); 122 aom_convolve8_vert(im_block + im_vert_offset, MAX_SB_SIZE, comp_pred, width, 123 NULL, -1, filter_y, 16, width, height); 124 } 125 } 126 127 void aom_comp_avg_upsampled_pred_neon(MACROBLOCKD *xd, 128 const AV1_COMMON *const cm, int mi_row, 129 int mi_col, const MV *const mv, 130 uint8_t *comp_pred, const uint8_t *pred, 131 int width, int height, int subpel_x_q3, 132 int subpel_y_q3, const uint8_t *ref, 133 int ref_stride, int subpel_search) { 134 aom_upsampled_pred_neon(xd, cm, mi_row, mi_col, mv, comp_pred, width, height, 135 subpel_x_q3, subpel_y_q3, ref, ref_stride, 136 subpel_search); 137 138 aom_comp_avg_pred_neon(comp_pred, pred, width, height, comp_pred, width); 139 } 140 141 #if CONFIG_AV1_HIGHBITDEPTH 142 void aom_highbd_upsampled_pred_neon(MACROBLOCKD *xd, 143 const struct AV1Common *const cm, 144 int mi_row, int mi_col, const MV *const mv, 145 uint8_t *comp_pred8, int width, int height, 146 int subpel_x_q3, int subpel_y_q3, 147 const uint8_t *ref8, int ref_stride, int bd, 148 int subpel_search) { 149 // expect xd == NULL only in tests 150 if (xd != NULL) { 151 const MB_MODE_INFO *mi = xd->mi[0]; 152 const int ref_num = 0; 153 const int is_intrabc = is_intrabc_block(mi); 154 const struct scale_factors *const sf = 155 is_intrabc ? &cm->sf_identity : xd->block_ref_scale_factors[ref_num]; 156 const int is_scaled = av1_is_scaled(sf); 157 158 if (is_scaled) { 159 int plane = 0; 160 const int mi_x = mi_col * MI_SIZE; 161 const int mi_y = mi_row * MI_SIZE; 162 const struct macroblockd_plane *const pd = &xd->plane[plane]; 163 const struct buf_2d *const dst_buf = &pd->dst; 164 const struct buf_2d *const pre_buf = 165 is_intrabc ? dst_buf : &pd->pre[ref_num]; 166 167 InterPredParams inter_pred_params; 168 inter_pred_params.conv_params = get_conv_params(0, plane, xd->bd); 169 const int_interpfilters filters = 170 av1_broadcast_interp_filter(EIGHTTAP_REGULAR); 171 av1_init_inter_params( 172 &inter_pred_params, width, height, mi_y >> pd->subsampling_y, 173 mi_x >> pd->subsampling_x, pd->subsampling_x, pd->subsampling_y, 174 xd->bd, is_cur_buf_hbd(xd), is_intrabc, sf, pre_buf, filters); 175 av1_enc_build_one_inter_predictor(comp_pred8, width, mv, 176 &inter_pred_params); 177 return; 178 } 179 } 180 181 const InterpFilterParams *filter = av1_get_filter(subpel_search); 182 183 if (!subpel_x_q3 && !subpel_y_q3) { 184 const uint16_t *ref = CONVERT_TO_SHORTPTR(ref8); 185 uint16_t *comp_pred = CONVERT_TO_SHORTPTR(comp_pred8); 186 if (width > 4) { 187 assert(width % 8 == 0); 188 int i = height; 189 do { 190 int j = 0; 191 do { 192 uint16x8_t r = vld1q_u16(ref + j); 193 vst1q_u16(comp_pred + j, r); 194 j += 8; 195 } while (j < width); 196 ref += ref_stride; 197 comp_pred += width; 198 } while (--i != 0); 199 } else if (width == 4) { 200 int i = height; 201 do { 202 uint16x4_t r = vld1_u16(ref); 203 vst1_u16(comp_pred, r); 204 ref += ref_stride; 205 comp_pred += width; 206 } while (--i != 0); 207 } else { 208 assert(width == 2); 209 int i = height / 2; 210 do { 211 uint16x4_t r = load_u16_2x2(ref, ref_stride); 212 store_u16x2_strided_x2(comp_pred, width, r); 213 ref += 2 * ref_stride; 214 comp_pred += 2 * width; 215 } while (--i != 0); 216 } 217 } else if (!subpel_y_q3) { 218 const int16_t *const kernel = 219 av1_get_interp_filter_subpel_kernel(filter, subpel_x_q3 << 1); 220 aom_highbd_convolve8_horiz_neon(ref8, ref_stride, comp_pred8, width, kernel, 221 16, NULL, -1, width, height, bd); 222 } else if (!subpel_x_q3) { 223 const int16_t *const kernel = 224 av1_get_interp_filter_subpel_kernel(filter, subpel_y_q3 << 1); 225 aom_highbd_convolve8_vert_neon(ref8, ref_stride, comp_pred8, width, NULL, 226 -1, kernel, 16, width, height, bd); 227 } else { 228 DECLARE_ALIGNED(16, uint16_t, 229 temp[((MAX_SB_SIZE + 16) + 16) * MAX_SB_SIZE]); 230 const int16_t *const kernel_x = 231 av1_get_interp_filter_subpel_kernel(filter, subpel_x_q3 << 1); 232 const int16_t *const kernel_y = 233 av1_get_interp_filter_subpel_kernel(filter, subpel_y_q3 << 1); 234 const int intermediate_height = 235 (((height - 1) * 8 + subpel_y_q3) >> 3) + filter->taps; 236 assert(intermediate_height <= (MAX_SB_SIZE * 2 + 16) + 16); 237 aom_highbd_convolve8_horiz_neon( 238 ref8 - ref_stride * ((filter->taps >> 1) - 1), ref_stride, 239 CONVERT_TO_BYTEPTR(temp), MAX_SB_SIZE, kernel_x, 16, NULL, -1, width, 240 intermediate_height, bd); 241 aom_highbd_convolve8_vert_neon( 242 CONVERT_TO_BYTEPTR(temp + MAX_SB_SIZE * ((filter->taps >> 1) - 1)), 243 MAX_SB_SIZE, comp_pred8, width, NULL, -1, kernel_y, 16, width, height, 244 bd); 245 } 246 } 247 248 void aom_highbd_comp_avg_upsampled_pred_neon( 249 MACROBLOCKD *xd, const struct AV1Common *const cm, int mi_row, int mi_col, 250 const MV *const mv, uint8_t *comp_pred8, const uint8_t *pred8, int width, 251 int height, int subpel_x_q3, int subpel_y_q3, const uint8_t *ref8, 252 int ref_stride, int bd, int subpel_search) { 253 aom_highbd_upsampled_pred_neon(xd, cm, mi_row, mi_col, mv, comp_pred8, width, 254 height, subpel_x_q3, subpel_y_q3, ref8, 255 ref_stride, bd, subpel_search); 256 257 aom_highbd_comp_avg_pred_neon(comp_pred8, pred8, width, height, comp_pred8, 258 width); 259 } 260 261 #endif // CONFIG_AV1_HIGHBITDEPTH