Coverage Report

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