Coverage Report

Created: 2026-07-14 07:20

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