• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021, 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 <assert.h>
13 #include <emmintrin.h>  // SSE2
14 #include <tmmintrin.h>
15 
16 #include "config/aom_config.h"
17 #include "config/aom_dsp_rtcd.h"
18 #include "config/av1_rtcd.h"
19 
20 #include "aom_dsp/x86/synonyms.h"
21 
compute_dist_wtd_avg(__m128i * p0,__m128i * p1,const __m128i * w,const __m128i * r,void * const result)22 static INLINE void compute_dist_wtd_avg(__m128i *p0, __m128i *p1,
23                                         const __m128i *w, const __m128i *r,
24                                         void *const result) {
25   __m128i p_lo = _mm_unpacklo_epi8(*p0, *p1);
26   __m128i mult_lo = _mm_maddubs_epi16(p_lo, *w);
27   __m128i round_lo = _mm_add_epi16(mult_lo, *r);
28   __m128i shift_lo = _mm_srai_epi16(round_lo, DIST_PRECISION_BITS);
29 
30   __m128i p_hi = _mm_unpackhi_epi8(*p0, *p1);
31   __m128i mult_hi = _mm_maddubs_epi16(p_hi, *w);
32   __m128i round_hi = _mm_add_epi16(mult_hi, *r);
33   __m128i shift_hi = _mm_srai_epi16(round_hi, DIST_PRECISION_BITS);
34 
35   xx_storeu_128(result, _mm_packus_epi16(shift_lo, shift_hi));
36 }
37 
aom_dist_wtd_comp_avg_upsampled_pred_ssse3(MACROBLOCKD * xd,const struct AV1Common * const cm,int mi_row,int mi_col,const MV * const mv,uint8_t * comp_pred,const uint8_t * pred,int width,int height,int subpel_x_q3,int subpel_y_q3,const uint8_t * ref,int ref_stride,const DIST_WTD_COMP_PARAMS * jcp_param,int subpel_search)38 void aom_dist_wtd_comp_avg_upsampled_pred_ssse3(
39     MACROBLOCKD *xd, const struct AV1Common *const cm, int mi_row, int mi_col,
40     const MV *const mv, uint8_t *comp_pred, const uint8_t *pred, int width,
41     int height, int subpel_x_q3, int subpel_y_q3, const uint8_t *ref,
42     int ref_stride, const DIST_WTD_COMP_PARAMS *jcp_param, int subpel_search) {
43   int n;
44   int i;
45   aom_upsampled_pred(xd, cm, mi_row, mi_col, mv, comp_pred, width, height,
46                      subpel_x_q3, subpel_y_q3, ref, ref_stride, subpel_search);
47   /*The total number of pixels must be a multiple of 16 (e.g., 4x4).*/
48   assert(!(width * height & 15));
49   n = width * height >> 4;
50 
51   const int8_t w0 = (int8_t)jcp_param->fwd_offset;
52   const int8_t w1 = (int8_t)jcp_param->bck_offset;
53   const __m128i w = _mm_set_epi8(w1, w0, w1, w0, w1, w0, w1, w0, w1, w0, w1, w0,
54                                  w1, w0, w1, w0);
55   const int16_t round = (int16_t)((1 << DIST_PRECISION_BITS) >> 1);
56   const __m128i r = _mm_set1_epi16(round);
57 
58   for (i = 0; i < n; i++) {
59     __m128i p0 = xx_loadu_128(comp_pred);
60     __m128i p1 = xx_loadu_128(pred);
61 
62     compute_dist_wtd_avg(&p0, &p1, &w, &r, comp_pred);
63 
64     comp_pred += 16;
65     pred += 16;
66   }
67 }
68