Coverage Report

Created: 2026-08-14 06:18

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/aom/av1/common/x86/jnt_convolve_avx2.c
Line
Count
Source
1
/*
2
 * Copyright (c) 2018, 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 <emmintrin.h>
13
#include <immintrin.h>
14
15
#include "config/av1_rtcd.h"
16
17
#include "aom_dsp/aom_dsp_common.h"
18
#include "aom_dsp/aom_filter.h"
19
#include "aom_dsp/x86/convolve_avx2.h"
20
#include "aom_dsp/x86/convolve_common_intrin.h"
21
#include "aom_dsp/x86/convolve_sse4_1.h"
22
#include "aom_dsp/x86/mem_sse2.h"
23
#include "aom_dsp/x86/synonyms_avx2.h"
24
25
#include "av1/common/convolve.h"
26
27
2.11M
static inline __m256i unpack_weights_avx2(ConvolveParams *conv_params) {
28
2.11M
  const int w0 = conv_params->fwd_offset;
29
2.11M
  const int w1 = conv_params->bck_offset;
30
2.11M
  const __m256i wt0 = _mm256_set1_epi16((int16_t)w0);
31
2.11M
  const __m256i wt1 = _mm256_set1_epi16((int16_t)w1);
32
2.11M
  const __m256i wt = _mm256_unpacklo_epi16(wt0, wt1);
33
2.11M
  return wt;
34
2.11M
}
35
36
9.94M
static inline __m256i load_line2_avx2(const void *a, const void *b) {
37
9.94M
  return _mm256_permute2x128_si256(
38
9.94M
      _mm256_castsi128_si256(_mm_loadu_si128((__m128i *)a)),
39
9.94M
      _mm256_castsi128_si256(_mm_loadu_si128((__m128i *)b)), 0x20);
40
9.94M
}
41
42
void av1_dist_wtd_convolve_x_avx2(const uint8_t *src, int src_stride,
43
                                  uint8_t *dst0, int dst_stride0, int w, int h,
44
                                  const InterpFilterParams *filter_params_x,
45
                                  const int subpel_x_qn,
46
98.9k
                                  ConvolveParams *conv_params) {
47
98.9k
  CONV_BUF_TYPE *dst = conv_params->dst;
48
98.9k
  int dst_stride = conv_params->dst_stride;
49
98.9k
  const int bd = 8;
50
98.9k
  int i, j, is_horiz_4tap = 0;
51
98.9k
  const int bits = FILTER_BITS - conv_params->round_1;
52
98.9k
  const __m256i wt = unpack_weights_avx2(conv_params);
53
98.9k
  const int do_average = conv_params->do_average;
54
98.9k
  const int use_dist_wtd_comp_avg = conv_params->use_dist_wtd_comp_avg;
55
98.9k
  const int offset_0 =
56
98.9k
      bd + 2 * FILTER_BITS - conv_params->round_0 - conv_params->round_1;
57
98.9k
  const int offset = (1 << offset_0) + (1 << (offset_0 - 1));
58
98.9k
  const __m256i offset_const = _mm256_set1_epi16(offset);
59
98.9k
  const int rounding_shift =
60
98.9k
      2 * FILTER_BITS - conv_params->round_0 - conv_params->round_1;
61
98.9k
  const __m256i rounding_const = _mm256_set1_epi16((1 << rounding_shift) >> 1);
62
63
98.9k
  assert(bits >= 0);
64
98.9k
  assert(conv_params->round_0 > 0);
65
66
98.9k
  const __m256i round_const =
67
98.9k
      _mm256_set1_epi16((1 << (conv_params->round_0 - 1)) >> 1);
68
98.9k
  const __m128i round_shift = _mm_cvtsi32_si128(conv_params->round_0 - 1);
69
70
98.9k
  __m256i filt[4], coeffs[4];
71
72
98.9k
  filt[0] = _mm256_load_si256((__m256i const *)filt_global_avx2);
73
98.9k
  filt[1] = _mm256_load_si256((__m256i const *)(filt_global_avx2 + 32));
74
75
98.9k
  prepare_coeffs_lowbd(filter_params_x, subpel_x_qn, coeffs);
76
77
  // Condition for checking valid horz_filt taps
78
98.9k
  if (!(_mm256_extract_epi32(_mm256_or_si256(coeffs[0], coeffs[3]), 0)))
79
45.2k
    is_horiz_4tap = 1;
80
81
  // horz_filt as 4 tap
82
98.9k
  if (is_horiz_4tap) {
83
45.2k
    const int fo_horiz = 1;
84
45.2k
    const uint8_t *const src_ptr = src - fo_horiz;
85
318k
    for (i = 0; i < h; i += 2) {
86
273k
      const uint8_t *src_data = src_ptr + i * src_stride;
87
273k
      CONV_BUF_TYPE *dst_data = dst + i * dst_stride;
88
1.42M
      for (j = 0; j < w; j += 8) {
89
1.15M
        const __m256i data =
90
1.15M
            load_line2_avx2(&src_data[j], &src_data[j + src_stride]);
91
92
1.15M
        __m256i res = convolve_lowbd_x_4tap(data, coeffs + 1, filt);
93
1.15M
        res = _mm256_sra_epi16(_mm256_add_epi16(res, round_const), round_shift);
94
1.15M
        res = _mm256_slli_epi16(res, bits);
95
96
1.15M
        const __m256i res_unsigned = _mm256_add_epi16(res, offset_const);
97
98
        // Accumulate values into the destination buffer
99
1.15M
        if (do_average) {
100
422k
          const __m256i data_ref_0 =
101
422k
              load_line2_avx2(&dst_data[j], &dst_data[j + dst_stride]);
102
422k
          const __m256i comp_avg_res =
103
422k
              comp_avg(&data_ref_0, &res_unsigned, &wt, use_dist_wtd_comp_avg);
104
105
422k
          const __m256i round_result = convolve_rounding(
106
422k
              &comp_avg_res, &offset_const, &rounding_const, rounding_shift);
107
108
422k
          const __m256i res_8 = _mm256_packus_epi16(round_result, round_result);
109
422k
          const __m128i res_0 = _mm256_castsi256_si128(res_8);
110
422k
          const __m128i res_1 = _mm256_extracti128_si256(res_8, 1);
111
112
422k
          if (w > 4) {
113
392k
            _mm_storel_epi64((__m128i *)(&dst0[i * dst_stride0 + j]), res_0);
114
392k
            _mm_storel_epi64(
115
392k
                (__m128i *)((&dst0[i * dst_stride0 + j + dst_stride0])), res_1);
116
392k
          } else {
117
30.1k
            *(int *)(&dst0[i * dst_stride0 + j]) = _mm_cvtsi128_si32(res_0);
118
30.1k
            *(int *)(&dst0[i * dst_stride0 + j + dst_stride0]) =
119
30.1k
                _mm_cvtsi128_si32(res_1);
120
30.1k
          }
121
729k
        } else {
122
729k
          const __m128i res_0 = _mm256_castsi256_si128(res_unsigned);
123
729k
          _mm_store_si128((__m128i *)(&dst[i * dst_stride + j]), res_0);
124
125
729k
          const __m128i res_1 = _mm256_extracti128_si256(res_unsigned, 1);
126
729k
          _mm_store_si128((__m128i *)(&dst[i * dst_stride + j + dst_stride]),
127
729k
                          res_1);
128
729k
        }
129
1.15M
      }
130
273k
    }
131
53.6k
  } else {
132
53.6k
    const int fo_horiz = filter_params_x->taps / 2 - 1;
133
53.6k
    const uint8_t *const src_ptr = src - fo_horiz;
134
135
53.6k
    filt[2] = _mm256_load_si256((__m256i const *)(filt_global_avx2 + 32 * 2));
136
53.6k
    filt[3] = _mm256_load_si256((__m256i const *)(filt_global_avx2 + 32 * 3));
137
483k
    for (i = 0; i < h; i += 2) {
138
430k
      const uint8_t *src_data = src_ptr + i * src_stride;
139
430k
      CONV_BUF_TYPE *dst_data = dst + i * dst_stride;
140
2.38M
      for (j = 0; j < w; j += 8) {
141
1.95M
        const __m256i data =
142
1.95M
            load_line2_avx2(&src_data[j], &src_data[j + src_stride]);
143
144
1.95M
        __m256i res = convolve_lowbd_x(data, coeffs, filt);
145
146
1.95M
        res = _mm256_sra_epi16(_mm256_add_epi16(res, round_const), round_shift);
147
148
1.95M
        res = _mm256_slli_epi16(res, bits);
149
150
1.95M
        const __m256i res_unsigned = _mm256_add_epi16(res, offset_const);
151
152
        // Accumulate values into the destination buffer
153
1.95M
        if (do_average) {
154
823k
          const __m256i data_ref_0 =
155
823k
              load_line2_avx2(&dst_data[j], &dst_data[j + dst_stride]);
156
823k
          const __m256i comp_avg_res =
157
823k
              comp_avg(&data_ref_0, &res_unsigned, &wt, use_dist_wtd_comp_avg);
158
159
823k
          const __m256i round_result = convolve_rounding(
160
823k
              &comp_avg_res, &offset_const, &rounding_const, rounding_shift);
161
162
823k
          const __m256i res_8 = _mm256_packus_epi16(round_result, round_result);
163
823k
          const __m128i res_0 = _mm256_castsi256_si128(res_8);
164
823k
          const __m128i res_1 = _mm256_extracti128_si256(res_8, 1);
165
166
823k
          if (w > 4) {
167
823k
            _mm_storel_epi64((__m128i *)(&dst0[i * dst_stride0 + j]), res_0);
168
823k
            _mm_storel_epi64(
169
823k
                (__m128i *)((&dst0[i * dst_stride0 + j + dst_stride0])), res_1);
170
823k
          } else {
171
7
            *(int *)(&dst0[i * dst_stride0 + j]) = _mm_cvtsi128_si32(res_0);
172
7
            *(int *)(&dst0[i * dst_stride0 + j + dst_stride0]) =
173
7
                _mm_cvtsi128_si32(res_1);
174
7
          }
175
1.13M
        } else {
176
1.13M
          const __m128i res_0 = _mm256_castsi256_si128(res_unsigned);
177
1.13M
          _mm_store_si128((__m128i *)(&dst[i * dst_stride + j]), res_0);
178
179
1.13M
          const __m128i res_1 = _mm256_extracti128_si256(res_unsigned, 1);
180
1.13M
          _mm_store_si128((__m128i *)(&dst[i * dst_stride + j + dst_stride]),
181
1.13M
                          res_1);
182
1.13M
        }
183
1.95M
      }
184
430k
    }
185
53.6k
  }
186
98.9k
}
187
188
void av1_dist_wtd_convolve_y_avx2(const uint8_t *src, int src_stride,
189
                                  uint8_t *dst0, int dst_stride0, int w, int h,
190
                                  const InterpFilterParams *filter_params_y,
191
                                  const int subpel_y_qn,
192
70.4k
                                  ConvolveParams *conv_params) {
193
70.4k
  CONV_BUF_TYPE *dst = conv_params->dst;
194
70.4k
  int dst_stride = conv_params->dst_stride;
195
70.4k
  const int bd = 8;
196
70.4k
  int i, j, is_vert_4tap = 0;
197
  // +1 to compensate for dividing the filter coeffs by 2
198
70.4k
  const int left_shift = FILTER_BITS - conv_params->round_0 + 1;
199
70.4k
  const __m256i round_const =
200
70.4k
      _mm256_set1_epi32((1 << conv_params->round_1) >> 1);
201
70.4k
  const __m128i round_shift = _mm_cvtsi32_si128(conv_params->round_1);
202
70.4k
  const __m256i wt = unpack_weights_avx2(conv_params);
203
70.4k
  const int do_average = conv_params->do_average;
204
70.4k
  const int use_dist_wtd_comp_avg = conv_params->use_dist_wtd_comp_avg;
205
70.4k
  const int offset_0 =
206
70.4k
      bd + 2 * FILTER_BITS - conv_params->round_0 - conv_params->round_1;
207
70.4k
  const int offset = (1 << offset_0) + (1 << (offset_0 - 1));
208
70.4k
  const __m256i offset_const = _mm256_set1_epi16(offset);
209
70.4k
  const int offset_1 = (1 << (bd + FILTER_BITS - 2));
210
70.4k
  const __m256i offset_const_1 = _mm256_set1_epi16(offset_1);
211
70.4k
  const __m256i offset_const_2 = _mm256_set1_epi16((1 << offset_0));
212
70.4k
  const int rounding_shift =
213
70.4k
      2 * FILTER_BITS - conv_params->round_0 - conv_params->round_1;
214
70.4k
  const __m256i rounding_const = _mm256_set1_epi16((1 << rounding_shift) >> 1);
215
70.4k
  const __m256i zero = _mm256_setzero_si256();
216
70.4k
  __m256i coeffs[4], s[8];
217
218
70.4k
  assert((FILTER_BITS - conv_params->round_0) >= 0);
219
220
70.4k
  prepare_coeffs_lowbd(filter_params_y, subpel_y_qn, coeffs);
221
222
  // Condition for checking valid vert_filt taps
223
70.4k
  if (!(_mm256_extract_epi32(_mm256_or_si256(coeffs[0], coeffs[3]), 0)))
224
38.3k
    is_vert_4tap = 1;
225
226
70.4k
  if (is_vert_4tap) {
227
38.3k
    const int fo_vert = 1;
228
38.3k
    const uint8_t *const src_ptr = src - fo_vert * src_stride;
229
79.4k
    for (j = 0; j < w; j += 16) {
230
41.0k
      const uint8_t *data = &src_ptr[j];
231
41.0k
      __m256i src4;
232
      // Load lines a and b. Line a to lower 128, line b to upper 128
233
41.0k
      {
234
41.0k
        __m256i src_ab[4];
235
41.0k
        __m256i src_a[5];
236
41.0k
        src_a[0] = _mm256_castsi128_si256(_mm_loadu_si128((__m128i *)data));
237
205k
        for (int kk = 0; kk < 4; ++kk) {
238
164k
          data += src_stride;
239
164k
          src_a[kk + 1] =
240
164k
              _mm256_castsi128_si256(_mm_loadu_si128((__m128i *)data));
241
164k
          src_ab[kk] =
242
164k
              _mm256_permute2x128_si256(src_a[kk], src_a[kk + 1], 0x20);
243
164k
        }
244
41.0k
        src4 = src_a[4];
245
41.0k
        s[0] = _mm256_unpacklo_epi8(src_ab[0], src_ab[1]);
246
41.0k
        s[1] = _mm256_unpacklo_epi8(src_ab[2], src_ab[3]);
247
248
41.0k
        s[3] = _mm256_unpackhi_epi8(src_ab[0], src_ab[1]);
249
41.0k
        s[4] = _mm256_unpackhi_epi8(src_ab[2], src_ab[3]);
250
41.0k
      }
251
252
266k
      for (i = 0; i < h; i += 2) {
253
225k
        data = &src_ptr[(i + 5) * src_stride + j];
254
225k
        const __m256i src5 =
255
225k
            _mm256_castsi128_si256(_mm_loadu_si128((__m128i *)data));
256
225k
        const __m256i src_45a = _mm256_permute2x128_si256(src4, src5, 0x20);
257
258
225k
        src4 = _mm256_castsi128_si256(
259
225k
            _mm_loadu_si128((__m128i *)(data + src_stride)));
260
225k
        const __m256i src_56a = _mm256_permute2x128_si256(src5, src4, 0x20);
261
262
225k
        s[2] = _mm256_unpacklo_epi8(src_45a, src_56a);
263
225k
        s[5] = _mm256_unpackhi_epi8(src_45a, src_56a);
264
265
225k
        __m256i res_lo = convolve_lowbd_4tap(s, coeffs + 1);
266
267
225k
        res_lo = _mm256_add_epi16(res_lo, offset_const_1);
268
269
225k
        const __m256i res_lo_0_32b = _mm256_unpacklo_epi16(res_lo, zero);
270
225k
        const __m256i res_lo_0_shift =
271
225k
            _mm256_slli_epi32(res_lo_0_32b, left_shift);
272
225k
        const __m256i res_lo_0_round = _mm256_sra_epi32(
273
225k
            _mm256_add_epi32(res_lo_0_shift, round_const), round_shift);
274
275
225k
        const __m256i res_lo_1_32b = _mm256_unpackhi_epi16(res_lo, zero);
276
225k
        const __m256i res_lo_1_shift =
277
225k
            _mm256_slli_epi32(res_lo_1_32b, left_shift);
278
225k
        const __m256i res_lo_1_round = _mm256_sra_epi32(
279
225k
            _mm256_add_epi32(res_lo_1_shift, round_const), round_shift);
280
281
225k
        const __m256i res_lo_round =
282
225k
            _mm256_packs_epi32(res_lo_0_round, res_lo_1_round);
283
284
225k
        const __m256i res_lo_unsigned =
285
225k
            _mm256_add_epi16(res_lo_round, offset_const_2);
286
287
225k
        if (w - j < 16) {
288
92.6k
          if (do_average) {
289
37.7k
            const __m256i data_ref_0 =
290
37.7k
                load_line2_avx2(&dst[i * dst_stride + j],
291
37.7k
                                &dst[i * dst_stride + j + dst_stride]);
292
37.7k
            const __m256i comp_avg_res = comp_avg(&data_ref_0, &res_lo_unsigned,
293
37.7k
                                                  &wt, use_dist_wtd_comp_avg);
294
295
37.7k
            const __m256i round_result = convolve_rounding(
296
37.7k
                &comp_avg_res, &offset_const, &rounding_const, rounding_shift);
297
298
37.7k
            const __m256i res_8 =
299
37.7k
                _mm256_packus_epi16(round_result, round_result);
300
37.7k
            const __m128i res_0 = _mm256_castsi256_si128(res_8);
301
37.7k
            const __m128i res_1 = _mm256_extracti128_si256(res_8, 1);
302
303
37.7k
            if (w - j > 4) {
304
20.3k
              _mm_storel_epi64((__m128i *)(&dst0[i * dst_stride0 + j]), res_0);
305
20.3k
              _mm_storel_epi64(
306
20.3k
                  (__m128i *)((&dst0[i * dst_stride0 + j + dst_stride0])),
307
20.3k
                  res_1);
308
20.3k
            } else {
309
17.3k
              *(int *)(&dst0[i * dst_stride0 + j]) = _mm_cvtsi128_si32(res_0);
310
17.3k
              *(int *)(&dst0[i * dst_stride0 + j + dst_stride0]) =
311
17.3k
                  _mm_cvtsi128_si32(res_1);
312
17.3k
            }
313
54.9k
          } else {
314
54.9k
            const __m128i res_0 = _mm256_castsi256_si128(res_lo_unsigned);
315
54.9k
            _mm_store_si128((__m128i *)(&dst[i * dst_stride + j]), res_0);
316
317
54.9k
            const __m128i res_1 = _mm256_extracti128_si256(res_lo_unsigned, 1);
318
54.9k
            _mm_store_si128((__m128i *)(&dst[i * dst_stride + j + dst_stride]),
319
54.9k
                            res_1);
320
54.9k
          }
321
133k
        } else {
322
133k
          __m256i res_hi = convolve_lowbd_4tap(s + 3, coeffs + 1);
323
324
133k
          res_hi = _mm256_add_epi16(res_hi, offset_const_1);
325
326
133k
          const __m256i res_hi_0_32b = _mm256_unpacklo_epi16(res_hi, zero);
327
133k
          const __m256i res_hi_0_shift =
328
133k
              _mm256_slli_epi32(res_hi_0_32b, left_shift);
329
133k
          const __m256i res_hi_0_round = _mm256_sra_epi32(
330
133k
              _mm256_add_epi32(res_hi_0_shift, round_const), round_shift);
331
332
133k
          const __m256i res_hi_1_32b = _mm256_unpackhi_epi16(res_hi, zero);
333
133k
          const __m256i res_hi_1_shift =
334
133k
              _mm256_slli_epi32(res_hi_1_32b, left_shift);
335
133k
          const __m256i res_hi_1_round = _mm256_sra_epi32(
336
133k
              _mm256_add_epi32(res_hi_1_shift, round_const), round_shift);
337
338
133k
          const __m256i res_hi_round =
339
133k
              _mm256_packs_epi32(res_hi_0_round, res_hi_1_round);
340
341
133k
          const __m256i res_hi_unsigned =
342
133k
              _mm256_add_epi16(res_hi_round, offset_const_2);
343
344
133k
          if (do_average) {
345
57.6k
            const __m256i data_ref_0_lo =
346
57.6k
                load_line2_avx2(&dst[i * dst_stride + j],
347
57.6k
                                &dst[i * dst_stride + j + dst_stride]);
348
349
57.6k
            const __m256i data_ref_0_hi =
350
57.6k
                load_line2_avx2(&dst[i * dst_stride + j + 8],
351
57.6k
                                &dst[i * dst_stride + j + 8 + dst_stride]);
352
353
57.6k
            const __m256i comp_avg_res_lo = comp_avg(
354
57.6k
                &data_ref_0_lo, &res_lo_unsigned, &wt, use_dist_wtd_comp_avg);
355
356
57.6k
            const __m256i comp_avg_res_hi = comp_avg(
357
57.6k
                &data_ref_0_hi, &res_hi_unsigned, &wt, use_dist_wtd_comp_avg);
358
359
57.6k
            const __m256i round_result_lo =
360
57.6k
                convolve_rounding(&comp_avg_res_lo, &offset_const,
361
57.6k
                                  &rounding_const, rounding_shift);
362
363
57.6k
            const __m256i round_result_hi =
364
57.6k
                convolve_rounding(&comp_avg_res_hi, &offset_const,
365
57.6k
                                  &rounding_const, rounding_shift);
366
367
57.6k
            const __m256i res_8 =
368
57.6k
                _mm256_packus_epi16(round_result_lo, round_result_hi);
369
57.6k
            const __m128i res_0 = _mm256_castsi256_si128(res_8);
370
57.6k
            const __m128i res_1 = _mm256_extracti128_si256(res_8, 1);
371
372
57.6k
            _mm_store_si128((__m128i *)(&dst0[i * dst_stride0 + j]), res_0);
373
57.6k
            _mm_store_si128(
374
57.6k
                (__m128i *)((&dst0[i * dst_stride0 + j + dst_stride0])), res_1);
375
376
75.5k
          } else {
377
75.5k
            const __m128i res_lo_0 = _mm256_castsi256_si128(res_lo_unsigned);
378
75.5k
            _mm_store_si128((__m128i *)(&dst[i * dst_stride + j]), res_lo_0);
379
380
75.5k
            const __m128i res_lo_1 =
381
75.5k
                _mm256_extracti128_si256(res_lo_unsigned, 1);
382
75.5k
            _mm_store_si128((__m128i *)(&dst[i * dst_stride + j + dst_stride]),
383
75.5k
                            res_lo_1);
384
385
75.5k
            const __m128i res_hi_0 = _mm256_castsi256_si128(res_hi_unsigned);
386
75.5k
            _mm_store_si128((__m128i *)(&dst[i * dst_stride + j + 8]),
387
75.5k
                            res_hi_0);
388
389
75.5k
            const __m128i res_hi_1 =
390
75.5k
                _mm256_extracti128_si256(res_hi_unsigned, 1);
391
75.5k
            _mm_store_si128(
392
75.5k
                (__m128i *)(&dst[i * dst_stride + j + 8 + dst_stride]),
393
75.5k
                res_hi_1);
394
75.5k
          }
395
133k
        }
396
225k
        s[0] = s[1];
397
225k
        s[1] = s[2];
398
399
225k
        s[3] = s[4];
400
225k
        s[4] = s[5];
401
225k
      }
402
41.0k
    }
403
38.3k
  } else {
404
32.0k
    const int fo_vert = filter_params_y->taps / 2 - 1;
405
32.0k
    const uint8_t *const src_ptr = src - fo_vert * src_stride;
406
75.5k
    for (j = 0; j < w; j += 16) {
407
43.4k
      const uint8_t *data = &src_ptr[j];
408
43.4k
      __m256i src6;
409
      // Load lines a and b. Line a to lower 128, line b to upper 128
410
43.4k
      {
411
43.4k
        __m256i src_ab[7];
412
43.4k
        __m256i src_a[7];
413
43.4k
        src_a[0] = _mm256_castsi128_si256(_mm_loadu_si128((__m128i *)data));
414
304k
        for (int kk = 0; kk < 6; ++kk) {
415
260k
          data += src_stride;
416
260k
          src_a[kk + 1] =
417
260k
              _mm256_castsi128_si256(_mm_loadu_si128((__m128i *)data));
418
260k
          src_ab[kk] =
419
260k
              _mm256_permute2x128_si256(src_a[kk], src_a[kk + 1], 0x20);
420
260k
        }
421
43.4k
        src6 = src_a[6];
422
43.4k
        s[0] = _mm256_unpacklo_epi8(src_ab[0], src_ab[1]);
423
43.4k
        s[1] = _mm256_unpacklo_epi8(src_ab[2], src_ab[3]);
424
43.4k
        s[2] = _mm256_unpacklo_epi8(src_ab[4], src_ab[5]);
425
43.4k
        s[4] = _mm256_unpackhi_epi8(src_ab[0], src_ab[1]);
426
43.4k
        s[5] = _mm256_unpackhi_epi8(src_ab[2], src_ab[3]);
427
43.4k
        s[6] = _mm256_unpackhi_epi8(src_ab[4], src_ab[5]);
428
43.4k
      }
429
430
538k
      for (i = 0; i < h; i += 2) {
431
495k
        data = &src_ptr[(i + 7) * src_stride + j];
432
495k
        const __m256i src7 =
433
495k
            _mm256_castsi128_si256(_mm_loadu_si128((__m128i *)data));
434
495k
        const __m256i src_67a = _mm256_permute2x128_si256(src6, src7, 0x20);
435
436
495k
        src6 = _mm256_castsi128_si256(
437
495k
            _mm_loadu_si128((__m128i *)(data + src_stride)));
438
495k
        const __m256i src_78a = _mm256_permute2x128_si256(src7, src6, 0x20);
439
440
495k
        s[3] = _mm256_unpacklo_epi8(src_67a, src_78a);
441
495k
        s[7] = _mm256_unpackhi_epi8(src_67a, src_78a);
442
443
495k
        __m256i res_lo = convolve_lowbd(s, coeffs);
444
445
495k
        res_lo = _mm256_add_epi16(res_lo, offset_const_1);
446
447
495k
        const __m256i res_lo_0_32b = _mm256_unpacklo_epi16(res_lo, zero);
448
495k
        const __m256i res_lo_0_shift =
449
495k
            _mm256_slli_epi32(res_lo_0_32b, left_shift);
450
495k
        const __m256i res_lo_0_round = _mm256_sra_epi32(
451
495k
            _mm256_add_epi32(res_lo_0_shift, round_const), round_shift);
452
453
495k
        const __m256i res_lo_1_32b = _mm256_unpackhi_epi16(res_lo, zero);
454
495k
        const __m256i res_lo_1_shift =
455
495k
            _mm256_slli_epi32(res_lo_1_32b, left_shift);
456
495k
        const __m256i res_lo_1_round = _mm256_sra_epi32(
457
495k
            _mm256_add_epi32(res_lo_1_shift, round_const), round_shift);
458
459
495k
        const __m256i res_lo_round =
460
495k
            _mm256_packs_epi32(res_lo_0_round, res_lo_1_round);
461
462
495k
        const __m256i res_lo_unsigned =
463
495k
            _mm256_add_epi16(res_lo_round, offset_const_2);
464
465
495k
        if (w - j < 16) {
466
93.2k
          if (do_average) {
467
40.3k
            const __m256i data_ref_0 =
468
40.3k
                load_line2_avx2(&dst[i * dst_stride + j],
469
40.3k
                                &dst[i * dst_stride + j + dst_stride]);
470
40.3k
            const __m256i comp_avg_res = comp_avg(&data_ref_0, &res_lo_unsigned,
471
40.3k
                                                  &wt, use_dist_wtd_comp_avg);
472
473
40.3k
            const __m256i round_result = convolve_rounding(
474
40.3k
                &comp_avg_res, &offset_const, &rounding_const, rounding_shift);
475
476
40.3k
            const __m256i res_8 =
477
40.3k
                _mm256_packus_epi16(round_result, round_result);
478
40.3k
            const __m128i res_0 = _mm256_castsi256_si128(res_8);
479
40.3k
            const __m128i res_1 = _mm256_extracti128_si256(res_8, 1);
480
481
40.3k
            if (w - j > 4) {
482
30.6k
              _mm_storel_epi64((__m128i *)(&dst0[i * dst_stride0 + j]), res_0);
483
30.6k
              _mm_storel_epi64(
484
30.6k
                  (__m128i *)((&dst0[i * dst_stride0 + j + dst_stride0])),
485
30.6k
                  res_1);
486
30.6k
            } else {
487
9.72k
              *(int *)(&dst0[i * dst_stride0 + j]) = _mm_cvtsi128_si32(res_0);
488
9.72k
              *(int *)(&dst0[i * dst_stride0 + j + dst_stride0]) =
489
9.72k
                  _mm_cvtsi128_si32(res_1);
490
9.72k
            }
491
52.9k
          } else {
492
52.9k
            const __m128i res_0 = _mm256_castsi256_si128(res_lo_unsigned);
493
52.9k
            _mm_store_si128((__m128i *)(&dst[i * dst_stride + j]), res_0);
494
495
52.9k
            const __m128i res_1 = _mm256_extracti128_si256(res_lo_unsigned, 1);
496
52.9k
            _mm_store_si128((__m128i *)(&dst[i * dst_stride + j + dst_stride]),
497
52.9k
                            res_1);
498
52.9k
          }
499
402k
        } else {
500
402k
          __m256i res_hi = convolve_lowbd(s + 4, coeffs);
501
502
402k
          res_hi = _mm256_add_epi16(res_hi, offset_const_1);
503
504
402k
          const __m256i res_hi_0_32b = _mm256_unpacklo_epi16(res_hi, zero);
505
402k
          const __m256i res_hi_0_shift =
506
402k
              _mm256_slli_epi32(res_hi_0_32b, left_shift);
507
402k
          const __m256i res_hi_0_round = _mm256_sra_epi32(
508
402k
              _mm256_add_epi32(res_hi_0_shift, round_const), round_shift);
509
510
402k
          const __m256i res_hi_1_32b = _mm256_unpackhi_epi16(res_hi, zero);
511
402k
          const __m256i res_hi_1_shift =
512
402k
              _mm256_slli_epi32(res_hi_1_32b, left_shift);
513
402k
          const __m256i res_hi_1_round = _mm256_sra_epi32(
514
402k
              _mm256_add_epi32(res_hi_1_shift, round_const), round_shift);
515
516
402k
          const __m256i res_hi_round =
517
402k
              _mm256_packs_epi32(res_hi_0_round, res_hi_1_round);
518
519
402k
          const __m256i res_hi_unsigned =
520
402k
              _mm256_add_epi16(res_hi_round, offset_const_2);
521
522
402k
          if (do_average) {
523
157k
            const __m256i data_ref_0_lo =
524
157k
                load_line2_avx2(&dst[i * dst_stride + j],
525
157k
                                &dst[i * dst_stride + j + dst_stride]);
526
527
157k
            const __m256i data_ref_0_hi =
528
157k
                load_line2_avx2(&dst[i * dst_stride + j + 8],
529
157k
                                &dst[i * dst_stride + j + 8 + dst_stride]);
530
531
157k
            const __m256i comp_avg_res_lo = comp_avg(
532
157k
                &data_ref_0_lo, &res_lo_unsigned, &wt, use_dist_wtd_comp_avg);
533
534
157k
            const __m256i comp_avg_res_hi = comp_avg(
535
157k
                &data_ref_0_hi, &res_hi_unsigned, &wt, use_dist_wtd_comp_avg);
536
537
157k
            const __m256i round_result_lo =
538
157k
                convolve_rounding(&comp_avg_res_lo, &offset_const,
539
157k
                                  &rounding_const, rounding_shift);
540
541
157k
            const __m256i round_result_hi =
542
157k
                convolve_rounding(&comp_avg_res_hi, &offset_const,
543
157k
                                  &rounding_const, rounding_shift);
544
545
157k
            const __m256i res_8 =
546
157k
                _mm256_packus_epi16(round_result_lo, round_result_hi);
547
157k
            const __m128i res_0 = _mm256_castsi256_si128(res_8);
548
157k
            const __m128i res_1 = _mm256_extracti128_si256(res_8, 1);
549
550
157k
            _mm_store_si128((__m128i *)(&dst0[i * dst_stride0 + j]), res_0);
551
157k
            _mm_store_si128(
552
157k
                (__m128i *)((&dst0[i * dst_stride0 + j + dst_stride0])), res_1);
553
554
244k
          } else {
555
244k
            const __m128i res_lo_0 = _mm256_castsi256_si128(res_lo_unsigned);
556
244k
            _mm_store_si128((__m128i *)(&dst[i * dst_stride + j]), res_lo_0);
557
558
244k
            const __m128i res_lo_1 =
559
244k
                _mm256_extracti128_si256(res_lo_unsigned, 1);
560
244k
            _mm_store_si128((__m128i *)(&dst[i * dst_stride + j + dst_stride]),
561
244k
                            res_lo_1);
562
563
244k
            const __m128i res_hi_0 = _mm256_castsi256_si128(res_hi_unsigned);
564
244k
            _mm_store_si128((__m128i *)(&dst[i * dst_stride + j + 8]),
565
244k
                            res_hi_0);
566
567
244k
            const __m128i res_hi_1 =
568
244k
                _mm256_extracti128_si256(res_hi_unsigned, 1);
569
244k
            _mm_store_si128(
570
244k
                (__m128i *)(&dst[i * dst_stride + j + 8 + dst_stride]),
571
244k
                res_hi_1);
572
244k
          }
573
402k
        }
574
495k
        s[0] = s[1];
575
495k
        s[1] = s[2];
576
495k
        s[2] = s[3];
577
578
495k
        s[4] = s[5];
579
495k
        s[5] = s[6];
580
495k
        s[6] = s[7];
581
495k
      }
582
43.4k
    }
583
32.0k
  }
584
70.4k
}
585
586
#define JNT_CONVOLVE_2D_VERTICAL_FILTER_4TAP(last_4, mode)                     \
587
111k
  do {                                                                         \
588
111k
    __m256i s0_reg =                                                           \
589
111k
        _mm256_loadu_si256((__m256i *)(im_block + 0 * im_stride));             \
590
111k
    __m256i s2_reg =                                                           \
591
111k
        _mm256_loadu_si256((__m256i *)(im_block + 2 * im_stride));             \
592
111k
    __m256i s4_init =                                                          \
593
111k
        _mm256_loadu_si256((__m256i *)(im_block + 4 * im_stride));             \
594
111k
    __m256i s1_reg = _mm256_permute2x128_si256(s0_reg, s2_reg, 0x21);          \
595
111k
    __m256i s3_reg = _mm256_permute2x128_si256(s2_reg, s4_init, 0x21);         \
596
111k
    __m256i s0 = _mm256_unpacklo_epi16(s0_reg, s1_reg);                        \
597
111k
    __m256i s1 = _mm256_unpacklo_epi16(s2_reg, s3_reg);                        \
598
111k
    __m256i s3 = _mm256_setzero_si256();                                       \
599
111k
    __m256i s4 = _mm256_setzero_si256();                                       \
600
111k
    if (!(last_4)) {                                                           \
601
74.7k
      s3 = _mm256_unpackhi_epi16(s0_reg, s1_reg);                              \
602
74.7k
      s4 = _mm256_unpackhi_epi16(s2_reg, s3_reg);                              \
603
74.7k
    }                                                                          \
604
839k
    for (i = 0; i < h; i += 2) {                                               \
605
728k
      const int16_t *data = &im_block[i * im_stride];                          \
606
728k
                                                                               \
607
728k
      const __m256i s4_reg =                                                   \
608
728k
          _mm256_loadu_si256((__m256i *)(data + 4 * im_stride));               \
609
728k
      const __m256i s5_reg =                                                   \
610
728k
          _mm256_loadu_si256((__m256i *)(data + 5 * im_stride));               \
611
728k
                                                                               \
612
728k
      __m256i s2 = _mm256_unpacklo_epi16(s4_reg, s5_reg);                      \
613
728k
                                                                               \
614
728k
      const __m256i res_a_1 = _mm256_madd_epi16(s0, coeffs_y[1]);              \
615
728k
      const __m256i res_a_2 = _mm256_madd_epi16(s1, coeffs_y[2]);              \
616
728k
      const __m256i res_a = _mm256_add_epi32(res_a_1, res_a_2);                \
617
728k
      const __m256i res_a_round =                                              \
618
728k
          _mm256_srai_epi32(_mm256_add_epi32(res_a, round_offset_const_v), 7); \
619
728k
                                                                               \
620
728k
      __m256i res_unsigned;                                                    \
621
728k
      if (last_4) {                                                            \
622
89.4k
        res_unsigned = _mm256_packus_epi32(res_a_round, res_a_round);          \
623
638k
      } else {                                                                 \
624
638k
        __m256i s5 = _mm256_unpackhi_epi16(s4_reg, s5_reg);                    \
625
638k
        const __m256i res_b_1 = _mm256_madd_epi16(s3, coeffs_y[1]);            \
626
638k
        const __m256i res_b_2 = _mm256_madd_epi16(s4, coeffs_y[2]);            \
627
638k
        const __m256i res_b = _mm256_add_epi32(res_b_1, res_b_2);              \
628
638k
        const __m256i res_b_round = _mm256_srai_epi32(                         \
629
638k
            _mm256_add_epi32(res_b, round_offset_const_v), 7);                 \
630
638k
        res_unsigned = _mm256_packus_epi32(res_a_round, res_b_round);          \
631
638k
        s3 = s4;                                                               \
632
638k
        s4 = s5;                                                               \
633
638k
      }                                                                        \
634
728k
      s0 = s1;                                                                 \
635
728k
      s1 = s2;                                                                 \
636
728k
                                                                               \
637
728k
      if (mode == 0) {                                                         \
638
128k
        const __m256i comp_const = _mm256_set1_epi32(-16 * offset + 128);      \
639
128k
        const __m256i wt = unpack_weights_avx2(conv_params);                   \
640
128k
        __m256i round_result;                                                  \
641
128k
        const __m256i data_ref_0 = load_line2_avx2(                            \
642
128k
            &dst[i * dst_stride + j], &dst[i * dst_stride + j + dst_stride]);  \
643
128k
        const __m256i data_lo =                                                \
644
128k
            _mm256_unpacklo_epi16(data_ref_0, res_unsigned);                   \
645
128k
        const __m256i wt_res_lo = _mm256_madd_epi16(data_lo, wt);              \
646
128k
        const __m256i fused_lo =                                               \
647
128k
            _mm256_srai_epi32(_mm256_add_epi32(wt_res_lo, comp_const), 8);     \
648
128k
        if (last_4) {                                                          \
649
18.4k
          round_result = _mm256_packs_epi32(fused_lo, fused_lo);               \
650
110k
        } else {                                                               \
651
110k
          const __m256i data_hi =                                              \
652
110k
              _mm256_unpackhi_epi16(data_ref_0, res_unsigned);                 \
653
110k
          const __m256i wt_res_hi = _mm256_madd_epi16(data_hi, wt);            \
654
110k
          const __m256i fused_hi =                                             \
655
110k
              _mm256_srai_epi32(_mm256_add_epi32(wt_res_hi, comp_const), 8);   \
656
110k
          round_result = _mm256_packs_epi32(fused_lo, fused_hi);               \
657
110k
        }                                                                      \
658
128k
        const __m256i res_8 = _mm256_packus_epi16(round_result, round_result); \
659
128k
        const __m128i res_0 = _mm256_castsi256_si128(res_8);                   \
660
128k
        const __m128i res_1 = _mm256_extracti128_si256(res_8, 1);              \
661
128k
        if (last_4) {                                                          \
662
18.4k
          *(int *)(&dst0[i * dst_stride0 + j]) = _mm_cvtsi128_si32(res_0);     \
663
18.4k
          *(int *)(&dst0[i * dst_stride0 + j + dst_stride0]) =                 \
664
18.4k
              _mm_cvtsi128_si32(res_1);                                        \
665
110k
        } else {                                                               \
666
110k
          _mm_storel_epi64((__m128i *)(&dst0[i * dst_stride0 + j]), res_0);    \
667
110k
          _mm_storel_epi64(                                                    \
668
110k
              (__m128i *)((&dst0[i * dst_stride0 + j + dst_stride0])), res_1); \
669
110k
        }                                                                      \
670
599k
      } else if (mode == 1) {                                                  \
671
166k
        const int rounding_shift =                                             \
672
166k
            2 * FILTER_BITS - conv_params->round_0 - conv_params->round_1;     \
673
166k
        const __m256i offset_const = _mm256_set1_epi16(offset);                \
674
166k
        const __m256i rounding_const =                                         \
675
166k
            _mm256_set1_epi16((1 << rounding_shift) >> 1);                     \
676
166k
        const __m256i data_ref_0 = load_line2_avx2(                            \
677
166k
            &dst[i * dst_stride + j], &dst[i * dst_stride + j + dst_stride]);  \
678
166k
        const __m256i wt_res = _mm256_add_epi16(data_ref_0, res_unsigned);     \
679
166k
        const __m256i comp_avg_res = _mm256_srai_epi16(wt_res, 1);             \
680
166k
        const __m256i res_signed =                                             \
681
166k
            _mm256_sub_epi16(comp_avg_res, offset_const);                      \
682
166k
        const __m256i round_result = _mm256_srai_epi16(                        \
683
166k
            _mm256_add_epi16(res_signed, rounding_const), 4);                  \
684
166k
        const __m256i res_8 = _mm256_packus_epi16(round_result, round_result); \
685
166k
        const __m128i res_0 = _mm256_castsi256_si128(res_8);                   \
686
166k
        const __m128i res_1 = _mm256_extracti128_si256(res_8, 1);              \
687
166k
        if (last_4) {                                                          \
688
19.7k
          *(int *)(&dst0[i * dst_stride0 + j]) = _mm_cvtsi128_si32(res_0);     \
689
19.7k
          *(int *)(&dst0[i * dst_stride0 + j + dst_stride0]) =                 \
690
19.7k
              _mm_cvtsi128_si32(res_1);                                        \
691
146k
        } else {                                                               \
692
146k
          _mm_storel_epi64((__m128i *)(&dst0[i * dst_stride0 + j]), res_0);    \
693
146k
          _mm_storel_epi64(                                                    \
694
146k
              (__m128i *)((&dst0[i * dst_stride0 + j + dst_stride0])), res_1); \
695
146k
        }                                                                      \
696
433k
      } else {                                                                 \
697
433k
        const __m128i res_0 = _mm256_castsi256_si128(res_unsigned);            \
698
433k
        _mm_store_si128((__m128i *)(&dst[i * dst_stride + j]), res_0);         \
699
433k
        const __m128i res_1 = _mm256_extracti128_si256(res_unsigned, 1);       \
700
433k
        _mm_store_si128((__m128i *)(&dst[i * dst_stride + j + dst_stride]),    \
701
433k
                        res_1);                                                \
702
433k
      }                                                                        \
703
728k
    }                                                                          \
704
111k
  } while (0)
705
706
void av1_dist_wtd_convolve_2d_avx2(const uint8_t *src, int src_stride,
707
                                   uint8_t *dst0, int dst_stride0, int w, int h,
708
                                   const InterpFilterParams *filter_params_x,
709
                                   const InterpFilterParams *filter_params_y,
710
                                   const int subpel_x_qn, const int subpel_y_qn,
711
172k
                                   ConvolveParams *conv_params) {
712
172k
  CONV_BUF_TYPE *dst = conv_params->dst;
713
172k
  int dst_stride = conv_params->dst_stride;
714
172k
  const int bd = 8;
715
716
172k
  DECLARE_ALIGNED(32, int16_t, im_block[(MAX_SB_SIZE + MAX_FILTER_TAP) * 8]);
717
718
172k
  int im_stride = 8;
719
172k
  int i, is_horiz_4tap = 0, is_vert_4tap = 0;
720
172k
  const int do_average = conv_params->do_average;
721
172k
  const int use_dist_wtd_comp_avg = conv_params->use_dist_wtd_comp_avg;
722
172k
  const int offset_0 =
723
172k
      bd + 2 * FILTER_BITS - conv_params->round_0 - conv_params->round_1;
724
172k
  const int offset = (1 << offset_0) + (1 << (offset_0 - 1));
725
726
172k
  assert(conv_params->round_0 > 0);
727
728
172k
  const __m256i round_const_h = _mm256_set1_epi16(
729
172k
      ((1 << (conv_params->round_0 - 1)) >> 1) + (1 << (bd + FILTER_BITS - 2)));
730
172k
  const int round_const_v_val =
731
172k
      ((1 << conv_params->round_1) >> 1) -
732
172k
      (1 << (bd + 2 * FILTER_BITS - conv_params->round_0 - 1));
733
172k
  const __m256i round_const_v = _mm256_set1_epi32(round_const_v_val);
734
172k
  const __m256i round_offset_const_v =
735
172k
      _mm256_set1_epi32(round_const_v_val + (offset << 7));
736
737
172k
  DECLARE_ALIGNED(32, __m256i, filt[4]);
738
172k
  DECLARE_ALIGNED(32, __m256i, coeffs_x[4]);
739
172k
  DECLARE_ALIGNED(32, __m256i, coeffs_y[4]);
740
741
172k
  filt[0] = _mm256_load_si256((__m256i const *)filt_global_avx2);
742
172k
  filt[1] = _mm256_load_si256((__m256i const *)(filt_global_avx2 + 32));
743
744
172k
  prepare_coeffs_lowbd(filter_params_x, subpel_x_qn, coeffs_x);
745
172k
  prepare_coeffs(filter_params_y, subpel_y_qn, coeffs_y);
746
747
  // Condition for checking valid horz_filt taps
748
172k
  if (!(_mm256_extract_epi32(_mm256_or_si256(coeffs_x[0], coeffs_x[3]), 0)))
749
73.6k
    is_horiz_4tap = 1;
750
751
  // Condition for checking valid vert_filt taps
752
172k
  if (!(_mm256_extract_epi32(_mm256_or_si256(coeffs_y[0], coeffs_y[3]), 0)))
753
82.8k
    is_vert_4tap = 1;
754
755
172k
  if (is_horiz_4tap && is_vert_4tap) {
756
57.9k
    int im_h = h + 4;
757
57.9k
    const int fo_vert = 1;
758
57.9k
    const int fo_horiz = 1;
759
57.9k
    const uint8_t *const src_ptr = src - fo_vert * src_stride - fo_horiz;
760
57.9k
    if (w > 4) {
761
58.7k
      for (int j = 0; j < w; j += 8) {
762
37.7k
        JNT_CONVOLVE_HORIZONTAL_FILTER(src_ptr + j, convolve_lowbd_x_4tap,
763
37.7k
                                       coeffs_x + 1);
764
37.7k
        if (do_average) {
765
16.0k
          if (use_dist_wtd_comp_avg) {
766
6.55k
            JNT_CONVOLVE_2D_VERTICAL_FILTER_4TAP(0, 0);
767
9.52k
          } else {
768
9.52k
            JNT_CONVOLVE_2D_VERTICAL_FILTER_4TAP(0, 1);
769
9.52k
          }
770
21.7k
        } else {
771
21.7k
          JNT_CONVOLVE_2D_VERTICAL_FILTER_4TAP(0, 2);
772
21.7k
        }
773
37.7k
      }
774
36.9k
    } else {
775
36.9k
      const int j = 0;
776
36.9k
      JNT_CONVOLVE_HORIZONTAL_FILTER(src_ptr, convolve_lowbd_x_4tap,
777
36.9k
                                     coeffs_x + 1);
778
36.9k
      if (do_average) {
779
15.8k
        if (use_dist_wtd_comp_avg) {
780
8.01k
          JNT_CONVOLVE_2D_VERTICAL_FILTER_4TAP(1, 0);
781
8.01k
        } else {
782
7.81k
          JNT_CONVOLVE_2D_VERTICAL_FILTER_4TAP(1, 1);
783
7.81k
        }
784
21.1k
      } else {
785
21.1k
        JNT_CONVOLVE_2D_VERTICAL_FILTER_4TAP(1, 2);
786
21.1k
      }
787
36.9k
    }
788
114k
  } else if (is_horiz_4tap) {
789
15.6k
    int im_h = h + 8;
790
15.6k
    const int fo_vert = filter_params_y->taps / 2 - 1;
791
15.6k
    const int fo_horiz = 1;
792
15.6k
    const uint8_t *const src_ptr = src - fo_vert * src_stride - fo_horiz;
793
15.6k
    const __m256i wt = unpack_weights_avx2(conv_params);
794
15.6k
    const __m256i offset_const = _mm256_set1_epi16(offset);
795
15.6k
    const int rounding_shift =
796
15.6k
        2 * FILTER_BITS - conv_params->round_0 - conv_params->round_1;
797
15.6k
    const __m256i rounding_const =
798
15.6k
        _mm256_set1_epi16((1 << rounding_shift) >> 1);
799
34.4k
    for (int j = 0; j < w; j += 8) {
800
18.7k
      JNT_CONVOLVE_HORIZONTAL_FILTER(src_ptr + j, convolve_lowbd_x_4tap,
801
18.7k
                                     coeffs_x + 1);
802
18.7k
      JNT_CONVOLVE_VERTICAL_FILTER_8TAP;
803
18.7k
    }
804
98.9k
  } else if (is_vert_4tap) {
805
24.9k
    int im_h = h + 4;
806
24.9k
    const int fo_vert = 1;
807
24.9k
    const int fo_horiz = filter_params_x->taps / 2 - 1;
808
24.9k
    const uint8_t *const src_ptr = src - fo_vert * src_stride - fo_horiz;
809
810
24.9k
    filt[2] = _mm256_load_si256((__m256i const *)(filt_global_avx2 + 32 * 2));
811
24.9k
    filt[3] = _mm256_load_si256((__m256i const *)(filt_global_avx2 + 32 * 3));
812
813
61.9k
    for (int j = 0; j < w; j += 8) {
814
36.9k
      JNT_CONVOLVE_HORIZONTAL_FILTER(src_ptr + j, convolve_lowbd_x, coeffs_x);
815
36.9k
      if (do_average) {
816
15.6k
        if (use_dist_wtd_comp_avg) {
817
6.76k
          JNT_CONVOLVE_2D_VERTICAL_FILTER_4TAP((w - j <= 4), 0);
818
8.88k
        } else {
819
8.88k
          JNT_CONVOLVE_2D_VERTICAL_FILTER_4TAP((w - j <= 4), 1);
820
8.88k
        }
821
21.3k
      } else {
822
21.3k
        JNT_CONVOLVE_2D_VERTICAL_FILTER_4TAP((w - j <= 4), 2);
823
21.3k
      }
824
36.9k
    }
825
74.0k
  } else {
826
74.0k
    int im_h = h + 8;
827
74.0k
    const int fo_vert = filter_params_y->taps / 2 - 1;
828
74.0k
    const int fo_horiz = filter_params_x->taps / 2 - 1;
829
74.0k
    const uint8_t *const src_ptr = src - fo_vert * src_stride - fo_horiz;
830
74.0k
    const __m256i wt = unpack_weights_avx2(conv_params);
831
74.0k
    const __m256i offset_const = _mm256_set1_epi16(offset);
832
74.0k
    const int rounding_shift =
833
74.0k
        2 * FILTER_BITS - conv_params->round_0 - conv_params->round_1;
834
74.0k
    const __m256i rounding_const =
835
74.0k
        _mm256_set1_epi16((1 << rounding_shift) >> 1);
836
837
74.0k
    filt[2] = _mm256_load_si256((__m256i const *)(filt_global_avx2 + 32 * 2));
838
74.0k
    filt[3] = _mm256_load_si256((__m256i const *)(filt_global_avx2 + 32 * 3));
839
840
247k
    for (int j = 0; j < w; j += 8) {
841
173k
      JNT_CONVOLVE_HORIZONTAL_FILTER(src_ptr + j, convolve_lowbd_x, coeffs_x);
842
843
173k
      JNT_CONVOLVE_VERTICAL_FILTER_8TAP;
844
173k
    }
845
74.0k
  }
846
172k
}
847
#undef JNT_CONVOLVE_2D_VERTICAL_FILTER_4TAP
848
849
#define DO_NO_AVG_2D_COPY_4X16(r0, c0, r1, c1, r2, c2, r3, c3)          \
850
72.5M
  do {                                                                  \
851
72.5M
    src_0 = _mm256_cvtepu8_epi16(                                       \
852
72.5M
        _mm_loadu_si128((__m128i *)(&src[r0 * src_stride + c0])));      \
853
72.5M
    src_1 = _mm256_cvtepu8_epi16(                                       \
854
72.5M
        _mm_loadu_si128((__m128i *)(&src[r1 * src_stride + c1])));      \
855
72.5M
    src_2 = _mm256_cvtepu8_epi16(                                       \
856
72.5M
        _mm_loadu_si128((__m128i *)(&src[r2 * src_stride + c2])));      \
857
72.5M
    src_3 = _mm256_cvtepu8_epi16(                                       \
858
72.5M
        _mm_loadu_si128((__m128i *)(&src[r3 * src_stride + c3])));      \
859
72.5M
                                                                        \
860
72.5M
    src_0 = _mm256_slli_epi16(src_0, LEFT_SHIFT);                       \
861
72.5M
    src_1 = _mm256_slli_epi16(src_1, LEFT_SHIFT);                       \
862
72.5M
    src_2 = _mm256_slli_epi16(src_2, LEFT_SHIFT);                       \
863
72.5M
    src_3 = _mm256_slli_epi16(src_3, LEFT_SHIFT);                       \
864
72.5M
                                                                        \
865
72.5M
    src_0 = _mm256_add_epi16(src_0, offset_const);                      \
866
72.5M
    src_1 = _mm256_add_epi16(src_1, offset_const);                      \
867
72.5M
    src_2 = _mm256_add_epi16(src_2, offset_const);                      \
868
72.5M
    src_3 = _mm256_add_epi16(src_3, offset_const);                      \
869
72.5M
                                                                        \
870
72.5M
    _mm256_store_si256((__m256i *)(&dst[r0 * dst_stride + c0]), src_0); \
871
72.5M
    _mm256_store_si256((__m256i *)(&dst[r1 * dst_stride + c1]), src_1); \
872
72.5M
    _mm256_store_si256((__m256i *)(&dst[r2 * dst_stride + c2]), src_2); \
873
72.5M
    _mm256_store_si256((__m256i *)(&dst[r3 * dst_stride + c3]), src_3); \
874
72.5M
  } while (0)
875
876
579M
#define LEFT_SHIFT (2 * FILTER_BITS - 3 - 7)
877
static inline void av1_dist_wtd_convolve_2d_no_avg_copy_avx2(
878
    const uint8_t *src, int src_stride, CONV_BUF_TYPE *dst, int dst_stride,
879
931k
    int w, int h, const __m256i offset_const) {
880
931k
  int i = h;
881
931k
  if (w >= 16) {
882
761k
    __m256i src_0, src_1, src_2, src_3;
883
761k
    if (w == 128) {
884
19.1M
      do {
885
19.1M
        DO_NO_AVG_2D_COPY_4X16(0, 0, 0, 16, 0, 32, 0, 48);
886
19.1M
        DO_NO_AVG_2D_COPY_4X16(0, 64, 0, 80, 0, 96, 0, 112);
887
19.1M
        src += 1 * src_stride;
888
19.1M
        dst += 1 * dst_stride;
889
19.1M
        i -= 1;
890
19.1M
      } while (i);
891
611k
    } else if (w == 64) {
892
28.8M
      do {
893
28.8M
        DO_NO_AVG_2D_COPY_4X16(0, 0, 0, 16, 0, 32, 0, 48);
894
28.8M
        src += 1 * src_stride;
895
28.8M
        dst += 1 * dst_stride;
896
28.8M
        i -= 1;
897
28.8M
      } while (i);
898
378k
    } else if (w == 32) {
899
5.03M
      do {
900
5.03M
        DO_NO_AVG_2D_COPY_4X16(0, 0, 1, 0, 0, 16, 1, 16);
901
5.03M
        src += 2 * src_stride;
902
5.03M
        dst += 2 * dst_stride;
903
5.03M
        i -= 2;
904
5.03M
      } while (i);
905
172k
    } else if (w == 16) {
906
289k
      do {
907
289k
        DO_NO_AVG_2D_COPY_4X16(0, 0, 1, 0, 2, 0, 3, 0);
908
289k
        src += 4 * src_stride;
909
289k
        dst += 4 * dst_stride;
910
289k
        i -= 4;
911
289k
      } while (i);
912
63.1k
    }
913
761k
  } else {
914
169k
    const __m256i zero = _mm256_setzero_si256();
915
421k
    do {
916
421k
      const __m128i src_row_0 =
917
421k
          _mm_loadl_epi64((__m128i *)(&src[0 * src_stride]));
918
421k
      const __m128i src_row_1 =
919
421k
          _mm_loadl_epi64((__m128i *)(&src[1 * src_stride]));
920
421k
      const __m128i src_row_2 =
921
421k
          _mm_loadl_epi64((__m128i *)(&src[2 * src_stride]));
922
421k
      const __m128i src_row_3 =
923
421k
          _mm_loadl_epi64((__m128i *)(&src[3 * src_stride]));
924
925
421k
      __m256i src_10 = _mm256_insertf128_si256(
926
421k
          _mm256_castsi128_si256(src_row_0), src_row_1, 1);
927
421k
      __m256i src_32 = _mm256_insertf128_si256(
928
421k
          _mm256_castsi128_si256(src_row_2), src_row_3, 1);
929
930
421k
      src_10 = _mm256_unpacklo_epi8(src_10, zero);
931
421k
      src_32 = _mm256_unpacklo_epi8(src_32, zero);
932
933
421k
      src_10 = _mm256_slli_epi16(src_10, LEFT_SHIFT);
934
421k
      src_32 = _mm256_slli_epi16(src_32, LEFT_SHIFT);
935
936
421k
      src_10 = _mm256_add_epi16(src_10, offset_const);
937
421k
      src_32 = _mm256_add_epi16(src_32, offset_const);
938
939
      // Accumulate values into the destination buffer
940
421k
      _mm_store_si128((__m128i *)(&dst[0 * dst_stride]),
941
421k
                      _mm256_castsi256_si128(src_10));
942
421k
      _mm_store_si128((__m128i *)(&dst[1 * dst_stride]),
943
421k
                      _mm256_extracti128_si256(src_10, 1));
944
421k
      _mm_store_si128((__m128i *)(&dst[2 * dst_stride]),
945
421k
                      _mm256_castsi256_si128(src_32));
946
421k
      _mm_store_si128((__m128i *)(&dst[3 * dst_stride]),
947
421k
                      _mm256_extracti128_si256(src_32, 1));
948
949
421k
      src += 4 * src_stride;
950
421k
      dst += 4 * dst_stride;
951
421k
      i -= 4;
952
421k
    } while (i);
953
169k
  }
954
931k
}
955
956
#define DO_AVG_2D_COPY_4X16(USE_DIST_WEIGHTED, r0, c0, r1, c1, r2, c2, r3, c3) \
957
72.0M
  do {                                                                         \
958
72.0M
    src_0 = _mm256_cvtepu8_epi16(                                              \
959
72.0M
        _mm_loadu_si128((__m128i *)(&src[r0 * src_stride + c0])));             \
960
72.0M
    src_1 = _mm256_cvtepu8_epi16(                                              \
961
72.0M
        _mm_loadu_si128((__m128i *)(&src[r1 * src_stride + c1])));             \
962
72.0M
    src_2 = _mm256_cvtepu8_epi16(                                              \
963
72.0M
        _mm_loadu_si128((__m128i *)(&src[r2 * src_stride + c2])));             \
964
72.0M
    src_3 = _mm256_cvtepu8_epi16(                                              \
965
72.0M
        _mm_loadu_si128((__m128i *)(&src[r3 * src_stride + c3])));             \
966
72.0M
                                                                               \
967
72.0M
    src_0 = _mm256_slli_epi16(src_0, LEFT_SHIFT);                              \
968
72.0M
    src_1 = _mm256_slli_epi16(src_1, LEFT_SHIFT);                              \
969
72.0M
    src_2 = _mm256_slli_epi16(src_2, LEFT_SHIFT);                              \
970
72.0M
    src_3 = _mm256_slli_epi16(src_3, LEFT_SHIFT);                              \
971
72.0M
    src_0 = _mm256_add_epi16(src_0, offset_const);                             \
972
72.0M
    src_1 = _mm256_add_epi16(src_1, offset_const);                             \
973
72.0M
    src_2 = _mm256_add_epi16(src_2, offset_const);                             \
974
72.0M
    src_3 = _mm256_add_epi16(src_3, offset_const);                             \
975
72.0M
                                                                               \
976
72.0M
    ref_0 = _mm256_loadu_si256((__m256i *)(&dst[r0 * dst_stride + c0]));       \
977
72.0M
    ref_1 = _mm256_loadu_si256((__m256i *)(&dst[r1 * dst_stride + c1]));       \
978
72.0M
    ref_2 = _mm256_loadu_si256((__m256i *)(&dst[r2 * dst_stride + c2]));       \
979
72.0M
    ref_3 = _mm256_loadu_si256((__m256i *)(&dst[r3 * dst_stride + c3]));       \
980
72.0M
                                                                               \
981
72.0M
    res_0 = comp_avg(&ref_0, &src_0, &wt, USE_DIST_WEIGHTED);                  \
982
72.0M
    res_1 = comp_avg(&ref_1, &src_1, &wt, USE_DIST_WEIGHTED);                  \
983
72.0M
    res_2 = comp_avg(&ref_2, &src_2, &wt, USE_DIST_WEIGHTED);                  \
984
72.0M
    res_3 = comp_avg(&ref_3, &src_3, &wt, USE_DIST_WEIGHTED);                  \
985
72.0M
                                                                               \
986
72.0M
    res_0 = convolve_rounding(&res_0, &offset_const, &rounding_const,          \
987
72.0M
                              rounding_shift);                                 \
988
72.0M
    res_1 = convolve_rounding(&res_1, &offset_const, &rounding_const,          \
989
72.0M
                              rounding_shift);                                 \
990
72.0M
    res_2 = convolve_rounding(&res_2, &offset_const, &rounding_const,          \
991
72.0M
                              rounding_shift);                                 \
992
72.0M
    res_3 = convolve_rounding(&res_3, &offset_const, &rounding_const,          \
993
72.0M
                              rounding_shift);                                 \
994
72.0M
                                                                               \
995
72.0M
    res_10 = _mm256_packus_epi16(res_0, res_1);                                \
996
72.0M
    res_32 = _mm256_packus_epi16(res_2, res_3);                                \
997
72.0M
    res_10 = _mm256_permute4x64_epi64(res_10, 0xD8);                           \
998
72.0M
    res_32 = _mm256_permute4x64_epi64(res_32, 0xD8);                           \
999
72.0M
                                                                               \
1000
72.0M
    _mm_store_si128((__m128i *)(&dst0[r0 * dst_stride0 + c0]),                 \
1001
72.0M
                    _mm256_castsi256_si128(res_10));                           \
1002
72.0M
    _mm_store_si128((__m128i *)(&dst0[r1 * dst_stride0 + c1]),                 \
1003
72.0M
                    _mm256_extracti128_si256(res_10, 1));                      \
1004
72.0M
    _mm_store_si128((__m128i *)(&dst0[r2 * dst_stride0 + c2]),                 \
1005
72.0M
                    _mm256_castsi256_si128(res_32));                           \
1006
72.0M
    _mm_store_si128((__m128i *)(&dst0[r3 * dst_stride0 + c3]),                 \
1007
72.0M
                    _mm256_extracti128_si256(res_32, 1));                      \
1008
72.0M
  } while (0)
1009
1010
#define DO_AVG_2D_COPY(USE_DIST_WEIGHTED)                                     \
1011
799k
  int i = h;                                                                  \
1012
799k
  if (w >= 16) {                                                              \
1013
715k
    __m256i src_0, src_1, src_2, src_3;                                       \
1014
715k
    __m256i ref_0, ref_1, ref_2, ref_3;                                       \
1015
715k
    __m256i res_0, res_1, res_2, res_3;                                       \
1016
715k
    __m256i res_10, res_32;                                                   \
1017
715k
    if (w == 128) {                                                           \
1018
19.1M
      do {                                                                    \
1019
19.1M
        DO_AVG_2D_COPY_4X16(USE_DIST_WEIGHTED, 0, 0, 0, 16, 0, 32, 0, 48);    \
1020
19.1M
        DO_AVG_2D_COPY_4X16(USE_DIST_WEIGHTED, 0, 64, 0, 80, 0, 96, 0, 112);  \
1021
19.1M
        i -= 1;                                                               \
1022
19.1M
        src += 1 * src_stride;                                                \
1023
19.1M
        dst += 1 * dst_stride;                                                \
1024
19.1M
        dst0 += 1 * dst_stride0;                                              \
1025
19.1M
      } while (i);                                                            \
1026
566k
    } else if (w == 64) {                                                     \
1027
28.7M
      do {                                                                    \
1028
28.7M
        DO_AVG_2D_COPY_4X16(USE_DIST_WEIGHTED, 0, 0, 0, 16, 0, 32, 0, 48);    \
1029
28.7M
                                                                              \
1030
28.7M
        i -= 1;                                                               \
1031
28.7M
        src += 1 * src_stride;                                                \
1032
28.7M
        dst += 1 * dst_stride;                                                \
1033
28.7M
        dst0 += 1 * dst_stride0;                                              \
1034
28.7M
      } while (i);                                                            \
1035
375k
    } else if (w == 32) {                                                     \
1036
4.90M
      do {                                                                    \
1037
4.90M
        DO_AVG_2D_COPY_4X16(USE_DIST_WEIGHTED, 0, 0, 1, 0, 0, 16, 1, 16);     \
1038
4.90M
                                                                              \
1039
4.90M
        i -= 2;                                                               \
1040
4.90M
        src += 2 * src_stride;                                                \
1041
4.90M
        dst += 2 * dst_stride;                                                \
1042
4.90M
        dst0 += 2 * dst_stride0;                                              \
1043
4.90M
      } while (i);                                                            \
1044
161k
    } else {                                                                  \
1045
28.9k
      assert(w == 16);                                                        \
1046
124k
      do {                                                                    \
1047
124k
        DO_AVG_2D_COPY_4X16(USE_DIST_WEIGHTED, 0, 0, 1, 0, 2, 0, 3, 0);       \
1048
124k
                                                                              \
1049
124k
        i -= 4;                                                               \
1050
124k
        src += 4 * src_stride;                                                \
1051
124k
        dst += 4 * dst_stride;                                                \
1052
124k
        dst0 += 4 * dst_stride0;                                              \
1053
124k
      } while (i);                                                            \
1054
31.3k
    }                                                                         \
1055
715k
  } else if (w == 8) {                                                        \
1056
136k
    do {                                                                      \
1057
136k
      const __m128i src_0 =                                                   \
1058
136k
          _mm_loadl_epi64((__m128i *)(&src[0 * src_stride]));                 \
1059
136k
      const __m128i src_1 =                                                   \
1060
136k
          _mm_loadl_epi64((__m128i *)(&src[1 * src_stride]));                 \
1061
136k
      const __m128i src_2 =                                                   \
1062
136k
          _mm_loadl_epi64((__m128i *)(&src[2 * src_stride]));                 \
1063
136k
      const __m128i src_3 =                                                   \
1064
136k
          _mm_loadl_epi64((__m128i *)(&src[3 * src_stride]));                 \
1065
136k
      __m256i src_10 =                                                        \
1066
136k
          _mm256_insertf128_si256(_mm256_castsi128_si256(src_0), src_1, 1);   \
1067
136k
      __m256i src_32 =                                                        \
1068
136k
          _mm256_insertf128_si256(_mm256_castsi128_si256(src_2), src_3, 1);   \
1069
136k
                                                                              \
1070
136k
      src_10 = _mm256_unpacklo_epi8(src_10, zero);                            \
1071
136k
      src_32 = _mm256_unpacklo_epi8(src_32, zero);                            \
1072
136k
                                                                              \
1073
136k
      src_10 = _mm256_slli_epi16(src_10, LEFT_SHIFT);                         \
1074
136k
      src_32 = _mm256_slli_epi16(src_32, LEFT_SHIFT);                         \
1075
136k
                                                                              \
1076
136k
      src_10 = _mm256_add_epi16(src_10, offset_const);                        \
1077
136k
      src_32 = _mm256_add_epi16(src_32, offset_const);                        \
1078
136k
                                                                              \
1079
136k
      const __m256i ref_10 =                                                  \
1080
136k
          load_line2_avx2(&dst[0 * dst_stride], &dst[1 * dst_stride]);        \
1081
136k
      const __m256i ref_32 =                                                  \
1082
136k
          load_line2_avx2(&dst[2 * dst_stride], &dst[3 * dst_stride]);        \
1083
136k
      __m256i res_10 = comp_avg(&ref_10, &src_10, &wt, USE_DIST_WEIGHTED);    \
1084
136k
      __m256i res_32 = comp_avg(&ref_32, &src_32, &wt, USE_DIST_WEIGHTED);    \
1085
136k
                                                                              \
1086
136k
      res_10 = convolve_rounding(&res_10, &offset_const, &rounding_const,     \
1087
136k
                                 rounding_shift);                             \
1088
136k
      res_32 = convolve_rounding(&res_32, &offset_const, &rounding_const,     \
1089
136k
                                 rounding_shift);                             \
1090
136k
                                                                              \
1091
136k
      __m256i res = _mm256_packus_epi16(res_10, res_32);                      \
1092
136k
      const __m128i res_20 = _mm256_castsi256_si128(res);                     \
1093
136k
      const __m128i res_31 = _mm256_extracti128_si256(res, 1);                \
1094
136k
                                                                              \
1095
136k
      _mm_storel_epi64((__m128i *)(&dst0[0 * dst_stride0]), res_20);          \
1096
136k
      _mm_storel_epi64((__m128i *)((&dst0[1 * dst_stride0])), res_31);        \
1097
136k
      _mm_storeh_epi64((__m128i *)(&dst0[2 * dst_stride0]), res_20);          \
1098
136k
      _mm_storeh_epi64((__m128i *)((&dst0[3 * dst_stride0])), res_31);        \
1099
136k
      i -= 4;                                                                 \
1100
136k
      src += 4 * src_stride;                                                  \
1101
136k
      dst += 4 * dst_stride;                                                  \
1102
136k
      dst0 += 4 * dst_stride0;                                                \
1103
136k
    } while (i);                                                              \
1104
50.1k
  } else {                                                                    \
1105
33.7k
    assert(w == 4);                                                           \
1106
52.7k
    do {                                                                      \
1107
52.7k
      __m256i src_3210_8bit =                                                 \
1108
52.7k
          _mm256_setr_epi32(loadu_int32(src + 0 * src_stride),                \
1109
52.7k
                            loadu_int32(src + 1 * src_stride), 0, 0,          \
1110
52.7k
                            loadu_int32(src + 2 * src_stride),                \
1111
52.7k
                            loadu_int32(src + 3 * src_stride), 0, 0);         \
1112
52.7k
                                                                              \
1113
52.7k
      __m256i src_3210 = _mm256_unpacklo_epi8(src_3210_8bit, zero);           \
1114
52.7k
      src_3210 = _mm256_slli_epi16(src_3210, LEFT_SHIFT);                     \
1115
52.7k
      src_3210 = _mm256_add_epi16(src_3210, offset_const);                    \
1116
52.7k
                                                                              \
1117
52.7k
      __m256i ref_3210 =                                                      \
1118
52.7k
          _mm256_setr_epi64x(*(int64_t *)(dst + 0 * dst_stride),              \
1119
52.7k
                             *(int64_t *)(dst + 1 * dst_stride),              \
1120
52.7k
                             *(int64_t *)(dst + 2 * dst_stride),              \
1121
52.7k
                             *(int64_t *)(dst + 3 * dst_stride));             \
1122
52.7k
      __m256i res_3210 =                                                      \
1123
52.7k
          comp_avg(&ref_3210, &src_3210, &wt, USE_DIST_WEIGHTED);             \
1124
52.7k
                                                                              \
1125
52.7k
      res_3210 = convolve_rounding(&res_3210, &offset_const, &rounding_const, \
1126
52.7k
                                   rounding_shift);                           \
1127
52.7k
                                                                              \
1128
52.7k
      res_3210 = _mm256_packus_epi16(res_3210, res_3210);                     \
1129
52.7k
      const __m128i res_10 = _mm256_castsi256_si128(res_3210);                \
1130
52.7k
      const __m128i res_32 = _mm256_extracti128_si256(res_3210, 1);           \
1131
52.7k
                                                                              \
1132
52.7k
      *(int *)(&dst0[0 * dst_stride0]) = _mm_cvtsi128_si32(res_10);           \
1133
52.7k
      *(int *)(&dst0[2 * dst_stride0]) = _mm_cvtsi128_si32(res_32);           \
1134
52.7k
      *(int *)(&dst0[1 * dst_stride0]) = _mm_extract_epi32(res_10, 1);        \
1135
52.7k
      *(int *)(&dst0[3 * dst_stride0]) = _mm_extract_epi32(res_32, 1);        \
1136
52.7k
      i -= 4;                                                                 \
1137
52.7k
      src += 4 * src_stride;                                                  \
1138
52.7k
      dst += 4 * dst_stride;                                                  \
1139
52.7k
      dst0 += 4 * dst_stride0;                                                \
1140
52.7k
    } while (i);                                                              \
1141
33.7k
  }
1142
1143
void av1_dist_wtd_convolve_2d_copy_avx2(const uint8_t *src, int src_stride,
1144
                                        uint8_t *dst0, int dst_stride0, int w,
1145
1.72M
                                        int h, ConvolveParams *conv_params) {
1146
1.72M
  const int bd = 8;
1147
1.72M
  CONV_BUF_TYPE *dst = conv_params->dst;
1148
1.72M
  int dst_stride = conv_params->dst_stride;
1149
1.72M
  assert(conv_params->round_0 == 3);
1150
1.72M
  assert(conv_params->round_1 == 7);
1151
1.72M
  assert(w % 4 == 0);
1152
1.72M
  assert(h % 4 == 0);
1153
1154
1.72M
  const int do_average = conv_params->do_average;
1155
1.72M
  const int use_dist_wtd_comp_avg = conv_params->use_dist_wtd_comp_avg;
1156
1.72M
  const __m256i wt = unpack_weights_avx2(conv_params);
1157
1.72M
  const __m256i zero = _mm256_setzero_si256();
1158
1159
1.72M
  const int offset_0 =
1160
1.72M
      bd + 2 * FILTER_BITS - conv_params->round_0 - conv_params->round_1;
1161
1.72M
  const int offset = (1 << offset_0) + (1 << (offset_0 - 1));
1162
1.72M
  const __m256i offset_const = _mm256_set1_epi16(offset);
1163
1.72M
  const int rounding_shift =
1164
1.72M
      2 * FILTER_BITS - conv_params->round_0 - conv_params->round_1;
1165
1.72M
  const __m256i rounding_const = _mm256_set1_epi16((1 << rounding_shift) >> 1);
1166
1167
1.72M
  if (do_average) {
1168
799k
    if (use_dist_wtd_comp_avg) {
1169
63.6k
      DO_AVG_2D_COPY(1)
1170
735k
    } else {
1171
735k
      DO_AVG_2D_COPY(0)
1172
735k
    }
1173
926k
  } else {
1174
926k
    av1_dist_wtd_convolve_2d_no_avg_copy_avx2(src, src_stride, dst, dst_stride,
1175
926k
                                              w, h, offset_const);
1176
926k
  }
1177
1.72M
}
1178
#undef LEFT_SHIFT