Coverage Report

Created: 2026-09-07 06:44

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