Coverage Report

Created: 2026-08-14 06:18

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/aom/aom_dsp/x86/intrapred_avx2.c
Line
Count
Source
1
/*
2
 * Copyright (c) 2017, 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 <immintrin.h>
13
14
#include "config/av1_rtcd.h"
15
#include "aom_dsp/x86/intrapred_x86.h"
16
#include "aom_dsp/x86/intrapred_utils.h"
17
#include "aom_dsp/x86/lpf_common_sse2.h"
18
19
287k
static inline __m256i dc_sum_64(const uint8_t *ref) {
20
287k
  const __m256i x0 = _mm256_loadu_si256((const __m256i *)ref);
21
287k
  const __m256i x1 = _mm256_loadu_si256((const __m256i *)(ref + 32));
22
287k
  const __m256i zero = _mm256_setzero_si256();
23
287k
  __m256i y0 = _mm256_sad_epu8(x0, zero);
24
287k
  __m256i y1 = _mm256_sad_epu8(x1, zero);
25
287k
  y0 = _mm256_add_epi64(y0, y1);
26
287k
  __m256i u0 = _mm256_permute2x128_si256(y0, y0, 1);
27
287k
  y0 = _mm256_add_epi64(u0, y0);
28
287k
  u0 = _mm256_unpackhi_epi64(y0, y0);
29
287k
  return _mm256_add_epi16(y0, u0);
30
287k
}
31
32
2.17M
static inline __m256i dc_sum_32(const uint8_t *ref) {
33
2.17M
  const __m256i x = _mm256_loadu_si256((const __m256i *)ref);
34
2.17M
  const __m256i zero = _mm256_setzero_si256();
35
2.17M
  __m256i y = _mm256_sad_epu8(x, zero);
36
2.17M
  __m256i u = _mm256_permute2x128_si256(y, y, 1);
37
2.17M
  y = _mm256_add_epi64(u, y);
38
2.17M
  u = _mm256_unpackhi_epi64(y, y);
39
2.17M
  return _mm256_add_epi16(y, u);
40
2.17M
}
41
42
static inline void row_store_32xh(const __m256i *r, int height, uint8_t *dst,
43
1.40M
                                  ptrdiff_t stride) {
44
44.4M
  for (int i = 0; i < height; ++i) {
45
43.0M
    _mm256_storeu_si256((__m256i *)dst, *r);
46
43.0M
    dst += stride;
47
43.0M
  }
48
1.40M
}
49
50
static inline void row_store_32x2xh(const __m256i *r0, const __m256i *r1,
51
                                    int height, uint8_t *dst,
52
3.61k
                                    ptrdiff_t stride) {
53
170k
  for (int i = 0; i < height; ++i) {
54
166k
    _mm256_storeu_si256((__m256i *)dst, *r0);
55
166k
    _mm256_storeu_si256((__m256i *)(dst + 32), *r1);
56
166k
    dst += stride;
57
166k
  }
58
3.61k
}
59
60
static inline void row_store_64xh(const __m256i *r, int height, uint8_t *dst,
61
201k
                                  ptrdiff_t stride) {
62
10.4M
  for (int i = 0; i < height; ++i) {
63
10.2M
    _mm256_storeu_si256((__m256i *)dst, *r);
64
10.2M
    _mm256_storeu_si256((__m256i *)(dst + 32), *r);
65
10.2M
    dst += stride;
66
10.2M
  }
67
201k
}
68
69
#if CONFIG_AV1_HIGHBITDEPTH
70
static DECLARE_ALIGNED(16, uint8_t, HighbdLoadMaskx[8][16]) = {
71
  { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
72
  { 0, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 },
73
  { 0, 1, 0, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 },
74
  { 0, 1, 0, 1, 0, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
75
  { 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 2, 3, 4, 5, 6, 7 },
76
  { 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 2, 3, 4, 5 },
77
  { 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 2, 3 },
78
  { 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 },
79
};
80
81
static DECLARE_ALIGNED(16, uint8_t, HighbdEvenOddMaskx4[4][16]) = {
82
  { 0, 1, 4, 5, 8, 9, 12, 13, 2, 3, 6, 7, 10, 11, 14, 15 },
83
  { 0, 1, 2, 3, 6, 7, 10, 11, 14, 15, 4, 5, 8, 9, 12, 13 },
84
  { 0, 1, 0, 1, 4, 5, 8, 9, 12, 13, 0, 1, 6, 7, 10, 11 },
85
  { 0, 1, 0, 1, 0, 1, 6, 7, 10, 11, 14, 15, 0, 1, 8, 9 }
86
};
87
88
static DECLARE_ALIGNED(16, uint8_t, HighbdEvenOddMaskx[8][32]) = {
89
  { 0, 1, 4, 5, 8,  9,  12, 13, 16, 17, 20, 21, 24, 25, 28, 29,
90
    2, 3, 6, 7, 10, 11, 14, 15, 18, 19, 22, 23, 26, 27, 30, 31 },
91
  { 0, 1, 2, 3, 6, 7, 10, 11, 14, 15, 18, 19, 22, 23, 26, 27,
92
    0, 1, 4, 5, 8, 9, 12, 13, 16, 17, 20, 21, 24, 25, 28, 29 },
93
  { 0, 1, 0, 1, 4, 5, 8,  9,  12, 13, 16, 17, 20, 21, 24, 25,
94
    0, 1, 0, 1, 6, 7, 10, 11, 14, 15, 18, 19, 22, 23, 26, 27 },
95
  { 0, 1, 0, 1, 0, 1, 6, 7, 10, 11, 14, 15, 18, 19, 22, 23,
96
    0, 1, 0, 1, 0, 1, 8, 9, 12, 13, 16, 17, 20, 21, 24, 25 },
97
  { 0, 1, 0, 1, 0, 1, 0, 1, 8,  9,  12, 13, 16, 17, 20, 21,
98
    0, 1, 0, 1, 0, 1, 0, 1, 10, 11, 14, 15, 18, 19, 22, 23 },
99
  { 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 10, 11, 14, 15, 18, 19,
100
    0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 12, 13, 16, 17, 20, 21 },
101
  { 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 12, 13, 16, 17,
102
    0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 14, 15, 18, 19 },
103
  { 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 14, 15,
104
    0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 16, 17 }
105
};
106
107
static DECLARE_ALIGNED(32, uint16_t, HighbdBaseMask[17][16]) = {
108
  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
109
  { 0xffff, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
110
  { 0xffff, 0xffff, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
111
  { 0xffff, 0xffff, 0xffff, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
112
  { 0xffff, 0xffff, 0xffff, 0xffff, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
113
  { 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
114
  { 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0, 0, 0, 0, 0, 0, 0, 0, 0,
115
    0 },
116
  { 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0, 0, 0, 0, 0, 0, 0,
117
    0, 0 },
118
  { 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0, 0, 0, 0,
119
    0, 0, 0, 0 },
120
  { 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0,
121
    0, 0, 0, 0, 0, 0 },
122
  { 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
123
    0xffff, 0, 0, 0, 0, 0, 0 },
124
  { 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
125
    0xffff, 0xffff, 0, 0, 0, 0, 0 },
126
  { 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
127
    0xffff, 0xffff, 0xffff, 0, 0, 0, 0 },
128
  { 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
129
    0xffff, 0xffff, 0xffff, 0xffff, 0, 0, 0 },
130
  { 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
131
    0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0, 0 },
132
  { 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
133
    0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0 },
134
  { 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
135
    0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff }
136
};
137
138
#if !CONFIG_REALTIME_ONLY || CONFIG_AV1_DECODER
139
69.5k
static inline void highbd_transpose16x4_8x8_sse2(__m128i *x, __m128i *d) {
140
69.5k
  __m128i r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, r15;
141
142
69.5k
  r0 = _mm_unpacklo_epi16(x[0], x[1]);
143
69.5k
  r1 = _mm_unpacklo_epi16(x[2], x[3]);
144
69.5k
  r2 = _mm_unpacklo_epi16(x[4], x[5]);
145
69.5k
  r3 = _mm_unpacklo_epi16(x[6], x[7]);
146
147
69.5k
  r4 = _mm_unpacklo_epi16(x[8], x[9]);
148
69.5k
  r5 = _mm_unpacklo_epi16(x[10], x[11]);
149
69.5k
  r6 = _mm_unpacklo_epi16(x[12], x[13]);
150
69.5k
  r7 = _mm_unpacklo_epi16(x[14], x[15]);
151
152
69.5k
  r8 = _mm_unpacklo_epi32(r0, r1);
153
69.5k
  r9 = _mm_unpackhi_epi32(r0, r1);
154
69.5k
  r10 = _mm_unpacklo_epi32(r2, r3);
155
69.5k
  r11 = _mm_unpackhi_epi32(r2, r3);
156
157
69.5k
  r12 = _mm_unpacklo_epi32(r4, r5);
158
69.5k
  r13 = _mm_unpackhi_epi32(r4, r5);
159
69.5k
  r14 = _mm_unpacklo_epi32(r6, r7);
160
69.5k
  r15 = _mm_unpackhi_epi32(r6, r7);
161
162
69.5k
  r0 = _mm_unpacklo_epi64(r8, r9);
163
69.5k
  r1 = _mm_unpackhi_epi64(r8, r9);
164
69.5k
  r2 = _mm_unpacklo_epi64(r10, r11);
165
69.5k
  r3 = _mm_unpackhi_epi64(r10, r11);
166
167
69.5k
  r4 = _mm_unpacklo_epi64(r12, r13);
168
69.5k
  r5 = _mm_unpackhi_epi64(r12, r13);
169
69.5k
  r6 = _mm_unpacklo_epi64(r14, r15);
170
69.5k
  r7 = _mm_unpackhi_epi64(r14, r15);
171
172
69.5k
  d[0] = _mm_unpacklo_epi64(r0, r2);
173
69.5k
  d[1] = _mm_unpacklo_epi64(r4, r6);
174
69.5k
  d[2] = _mm_unpacklo_epi64(r1, r3);
175
69.5k
  d[3] = _mm_unpacklo_epi64(r5, r7);
176
177
69.5k
  d[4] = _mm_unpackhi_epi64(r0, r2);
178
69.5k
  d[5] = _mm_unpackhi_epi64(r4, r6);
179
69.5k
  d[6] = _mm_unpackhi_epi64(r1, r3);
180
69.5k
  d[7] = _mm_unpackhi_epi64(r5, r7);
181
69.5k
}
182
183
26.8k
static inline void highbd_transpose4x16_avx2(__m256i *x, __m256i *d) {
184
26.8k
  __m256i w0, w1, w2, w3, ww0, ww1;
185
186
26.8k
  w0 = _mm256_unpacklo_epi16(x[0], x[1]);  // 00 10 01 11 02 12 03 13
187
26.8k
  w1 = _mm256_unpacklo_epi16(x[2], x[3]);  // 20 30 21 31 22 32 23 33
188
26.8k
  w2 = _mm256_unpackhi_epi16(x[0], x[1]);  // 40 50 41 51 42 52 43 53
189
26.8k
  w3 = _mm256_unpackhi_epi16(x[2], x[3]);  // 60 70 61 71 62 72 63 73
190
191
26.8k
  ww0 = _mm256_unpacklo_epi32(w0, w1);  // 00 10 20 30 01 11 21 31
192
26.8k
  ww1 = _mm256_unpacklo_epi32(w2, w3);  // 40 50 60 70 41 51 61 71
193
194
26.8k
  d[0] = _mm256_unpacklo_epi64(ww0, ww1);  // 00 10 20 30 40 50 60 70
195
26.8k
  d[1] = _mm256_unpackhi_epi64(ww0, ww1);  // 01 11 21 31 41 51 61 71
196
197
26.8k
  ww0 = _mm256_unpackhi_epi32(w0, w1);  // 02 12 22 32 03 13 23 33
198
26.8k
  ww1 = _mm256_unpackhi_epi32(w2, w3);  // 42 52 62 72 43 53 63 73
199
200
26.8k
  d[2] = _mm256_unpacklo_epi64(ww0, ww1);  // 02 12 22 32 42 52 62 72
201
26.8k
  d[3] = _mm256_unpackhi_epi64(ww0, ww1);  // 03 13 23 33 43 53 63 73
202
26.8k
}
203
#endif  // !CONFIG_REALTIME_ONLY || CONFIG_AV1_DECODER
204
205
187k
static inline void highbd_transpose8x16_16x8_avx2(__m256i *x, __m256i *d) {
206
187k
  __m256i w0, w1, w2, w3, ww0, ww1;
207
208
187k
  w0 = _mm256_unpacklo_epi16(x[0], x[1]);  // 00 10 01 11 02 12 03 13
209
187k
  w1 = _mm256_unpacklo_epi16(x[2], x[3]);  // 20 30 21 31 22 32 23 33
210
187k
  w2 = _mm256_unpacklo_epi16(x[4], x[5]);  // 40 50 41 51 42 52 43 53
211
187k
  w3 = _mm256_unpacklo_epi16(x[6], x[7]);  // 60 70 61 71 62 72 63 73
212
213
187k
  ww0 = _mm256_unpacklo_epi32(w0, w1);  // 00 10 20 30 01 11 21 31
214
187k
  ww1 = _mm256_unpacklo_epi32(w2, w3);  // 40 50 60 70 41 51 61 71
215
216
187k
  d[0] = _mm256_unpacklo_epi64(ww0, ww1);  // 00 10 20 30 40 50 60 70
217
187k
  d[1] = _mm256_unpackhi_epi64(ww0, ww1);  // 01 11 21 31 41 51 61 71
218
219
187k
  ww0 = _mm256_unpackhi_epi32(w0, w1);  // 02 12 22 32 03 13 23 33
220
187k
  ww1 = _mm256_unpackhi_epi32(w2, w3);  // 42 52 62 72 43 53 63 73
221
222
187k
  d[2] = _mm256_unpacklo_epi64(ww0, ww1);  // 02 12 22 32 42 52 62 72
223
187k
  d[3] = _mm256_unpackhi_epi64(ww0, ww1);  // 03 13 23 33 43 53 63 73
224
225
187k
  w0 = _mm256_unpackhi_epi16(x[0], x[1]);  // 04 14 05 15 06 16 07 17
226
187k
  w1 = _mm256_unpackhi_epi16(x[2], x[3]);  // 24 34 25 35 26 36 27 37
227
187k
  w2 = _mm256_unpackhi_epi16(x[4], x[5]);  // 44 54 45 55 46 56 47 57
228
187k
  w3 = _mm256_unpackhi_epi16(x[6], x[7]);  // 64 74 65 75 66 76 67 77
229
230
187k
  ww0 = _mm256_unpacklo_epi32(w0, w1);  // 04 14 24 34 05 15 25 35
231
187k
  ww1 = _mm256_unpacklo_epi32(w2, w3);  // 44 54 64 74 45 55 65 75
232
233
187k
  d[4] = _mm256_unpacklo_epi64(ww0, ww1);  // 04 14 24 34 44 54 64 74
234
187k
  d[5] = _mm256_unpackhi_epi64(ww0, ww1);  // 05 15 25 35 45 55 65 75
235
236
187k
  ww0 = _mm256_unpackhi_epi32(w0, w1);  // 06 16 26 36 07 17 27 37
237
187k
  ww1 = _mm256_unpackhi_epi32(w2, w3);  // 46 56 66 76 47 57 67 77
238
239
187k
  d[6] = _mm256_unpacklo_epi64(ww0, ww1);  // 06 16 26 36 46 56 66 76
240
187k
  d[7] = _mm256_unpackhi_epi64(ww0, ww1);  // 07 17 27 37 47 57 67 77
241
187k
}
242
243
1.10M
static inline void highbd_transpose16x16_avx2(__m256i *x, __m256i *d) {
244
1.10M
  __m256i w0, w1, w2, w3, ww0, ww1;
245
1.10M
  __m256i dd[16];
246
1.10M
  w0 = _mm256_unpacklo_epi16(x[0], x[1]);
247
1.10M
  w1 = _mm256_unpacklo_epi16(x[2], x[3]);
248
1.10M
  w2 = _mm256_unpacklo_epi16(x[4], x[5]);
249
1.10M
  w3 = _mm256_unpacklo_epi16(x[6], x[7]);
250
251
1.10M
  ww0 = _mm256_unpacklo_epi32(w0, w1);  //
252
1.10M
  ww1 = _mm256_unpacklo_epi32(w2, w3);  //
253
254
1.10M
  dd[0] = _mm256_unpacklo_epi64(ww0, ww1);
255
1.10M
  dd[1] = _mm256_unpackhi_epi64(ww0, ww1);
256
257
1.10M
  ww0 = _mm256_unpackhi_epi32(w0, w1);  //
258
1.10M
  ww1 = _mm256_unpackhi_epi32(w2, w3);  //
259
260
1.10M
  dd[2] = _mm256_unpacklo_epi64(ww0, ww1);
261
1.10M
  dd[3] = _mm256_unpackhi_epi64(ww0, ww1);
262
263
1.10M
  w0 = _mm256_unpackhi_epi16(x[0], x[1]);
264
1.10M
  w1 = _mm256_unpackhi_epi16(x[2], x[3]);
265
1.10M
  w2 = _mm256_unpackhi_epi16(x[4], x[5]);
266
1.10M
  w3 = _mm256_unpackhi_epi16(x[6], x[7]);
267
268
1.10M
  ww0 = _mm256_unpacklo_epi32(w0, w1);  //
269
1.10M
  ww1 = _mm256_unpacklo_epi32(w2, w3);  //
270
271
1.10M
  dd[4] = _mm256_unpacklo_epi64(ww0, ww1);
272
1.10M
  dd[5] = _mm256_unpackhi_epi64(ww0, ww1);
273
274
1.10M
  ww0 = _mm256_unpackhi_epi32(w0, w1);  //
275
1.10M
  ww1 = _mm256_unpackhi_epi32(w2, w3);  //
276
277
1.10M
  dd[6] = _mm256_unpacklo_epi64(ww0, ww1);
278
1.10M
  dd[7] = _mm256_unpackhi_epi64(ww0, ww1);
279
280
1.10M
  w0 = _mm256_unpacklo_epi16(x[8], x[9]);
281
1.10M
  w1 = _mm256_unpacklo_epi16(x[10], x[11]);
282
1.10M
  w2 = _mm256_unpacklo_epi16(x[12], x[13]);
283
1.10M
  w3 = _mm256_unpacklo_epi16(x[14], x[15]);
284
285
1.10M
  ww0 = _mm256_unpacklo_epi32(w0, w1);
286
1.10M
  ww1 = _mm256_unpacklo_epi32(w2, w3);
287
288
1.10M
  dd[8] = _mm256_unpacklo_epi64(ww0, ww1);
289
1.10M
  dd[9] = _mm256_unpackhi_epi64(ww0, ww1);
290
291
1.10M
  ww0 = _mm256_unpackhi_epi32(w0, w1);
292
1.10M
  ww1 = _mm256_unpackhi_epi32(w2, w3);
293
294
1.10M
  dd[10] = _mm256_unpacklo_epi64(ww0, ww1);
295
1.10M
  dd[11] = _mm256_unpackhi_epi64(ww0, ww1);
296
297
1.10M
  w0 = _mm256_unpackhi_epi16(x[8], x[9]);
298
1.10M
  w1 = _mm256_unpackhi_epi16(x[10], x[11]);
299
1.10M
  w2 = _mm256_unpackhi_epi16(x[12], x[13]);
300
1.10M
  w3 = _mm256_unpackhi_epi16(x[14], x[15]);
301
302
1.10M
  ww0 = _mm256_unpacklo_epi32(w0, w1);
303
1.10M
  ww1 = _mm256_unpacklo_epi32(w2, w3);
304
305
1.10M
  dd[12] = _mm256_unpacklo_epi64(ww0, ww1);
306
1.10M
  dd[13] = _mm256_unpackhi_epi64(ww0, ww1);
307
308
1.10M
  ww0 = _mm256_unpackhi_epi32(w0, w1);
309
1.10M
  ww1 = _mm256_unpackhi_epi32(w2, w3);
310
311
1.10M
  dd[14] = _mm256_unpacklo_epi64(ww0, ww1);
312
1.10M
  dd[15] = _mm256_unpackhi_epi64(ww0, ww1);
313
314
9.90M
  for (int i = 0; i < 8; i++) {
315
8.80M
    d[i] = _mm256_insertf128_si256(dd[i], _mm256_castsi256_si128(dd[i + 8]), 1);
316
8.80M
    d[i + 8] = _mm256_insertf128_si256(dd[i + 8],
317
8.80M
                                       _mm256_extracti128_si256(dd[i], 1), 0);
318
8.80M
  }
319
1.10M
}
320
#endif  // CONFIG_AV1_HIGHBITDEPTH
321
322
void aom_dc_predictor_32x32_avx2(uint8_t *dst, ptrdiff_t stride,
323
958k
                                 const uint8_t *above, const uint8_t *left) {
324
958k
  const __m256i sum_above = dc_sum_32(above);
325
958k
  __m256i sum_left = dc_sum_32(left);
326
958k
  sum_left = _mm256_add_epi16(sum_left, sum_above);
327
958k
  const __m256i thirtytwo = _mm256_set1_epi16(32);
328
958k
  sum_left = _mm256_add_epi16(sum_left, thirtytwo);
329
958k
  sum_left = _mm256_srai_epi16(sum_left, 6);
330
958k
  const __m256i zero = _mm256_setzero_si256();
331
958k
  __m256i row = _mm256_shuffle_epi8(sum_left, zero);
332
958k
  row_store_32xh(&row, 32, dst, stride);
333
958k
}
334
335
void aom_dc_top_predictor_32x32_avx2(uint8_t *dst, ptrdiff_t stride,
336
                                     const uint8_t *above,
337
91.2k
                                     const uint8_t *left) {
338
91.2k
  __m256i sum = dc_sum_32(above);
339
91.2k
  (void)left;
340
341
91.2k
  const __m256i sixteen = _mm256_set1_epi16(16);
342
91.2k
  sum = _mm256_add_epi16(sum, sixteen);
343
91.2k
  sum = _mm256_srai_epi16(sum, 5);
344
91.2k
  const __m256i zero = _mm256_setzero_si256();
345
91.2k
  __m256i row = _mm256_shuffle_epi8(sum, zero);
346
91.2k
  row_store_32xh(&row, 32, dst, stride);
347
91.2k
}
348
349
void aom_dc_left_predictor_32x32_avx2(uint8_t *dst, ptrdiff_t stride,
350
                                      const uint8_t *above,
351
141k
                                      const uint8_t *left) {
352
141k
  __m256i sum = dc_sum_32(left);
353
141k
  (void)above;
354
355
141k
  const __m256i sixteen = _mm256_set1_epi16(16);
356
141k
  sum = _mm256_add_epi16(sum, sixteen);
357
141k
  sum = _mm256_srai_epi16(sum, 5);
358
141k
  const __m256i zero = _mm256_setzero_si256();
359
141k
  __m256i row = _mm256_shuffle_epi8(sum, zero);
360
141k
  row_store_32xh(&row, 32, dst, stride);
361
141k
}
362
363
void aom_dc_128_predictor_32x32_avx2(uint8_t *dst, ptrdiff_t stride,
364
                                     const uint8_t *above,
365
32.3k
                                     const uint8_t *left) {
366
32.3k
  (void)above;
367
32.3k
  (void)left;
368
32.3k
  const __m256i row = _mm256_set1_epi8((int8_t)0x80);
369
32.3k
  row_store_32xh(&row, 32, dst, stride);
370
32.3k
}
371
372
void aom_v_predictor_32x32_avx2(uint8_t *dst, ptrdiff_t stride,
373
29.2k
                                const uint8_t *above, const uint8_t *left) {
374
29.2k
  const __m256i row = _mm256_loadu_si256((const __m256i *)above);
375
29.2k
  (void)left;
376
29.2k
  row_store_32xh(&row, 32, dst, stride);
377
29.2k
}
378
379
// There are 32 rows togeter. This function does line:
380
// 0,1,2,3, and 16,17,18,19. The next call would do
381
// 4,5,6,7, and 20,21,22,23. So 4 times of calling
382
// would finish 32 rows.
383
static inline void h_predictor_32x8line(const __m256i *row, uint8_t *dst,
384
452k
                                        ptrdiff_t stride) {
385
452k
  __m256i t[4];
386
452k
  __m256i m = _mm256_setzero_si256();
387
452k
  const __m256i inc = _mm256_set1_epi8(4);
388
452k
  int i;
389
390
2.26M
  for (i = 0; i < 4; i++) {
391
1.80M
    t[i] = _mm256_shuffle_epi8(*row, m);
392
1.80M
    __m256i r0 = _mm256_permute2x128_si256(t[i], t[i], 0);
393
1.80M
    __m256i r1 = _mm256_permute2x128_si256(t[i], t[i], 0x11);
394
1.80M
    _mm256_storeu_si256((__m256i *)dst, r0);
395
1.80M
    _mm256_storeu_si256((__m256i *)(dst + (stride << 4)), r1);
396
1.80M
    dst += stride;
397
1.80M
    m = _mm256_add_epi8(m, inc);
398
1.80M
  }
399
452k
}
400
401
void aom_h_predictor_32x32_avx2(uint8_t *dst, ptrdiff_t stride,
402
113k
                                const uint8_t *above, const uint8_t *left) {
403
113k
  (void)above;
404
113k
  const __m256i left_col = _mm256_loadu_si256((__m256i const *)left);
405
406
113k
  __m256i u = _mm256_unpacklo_epi8(left_col, left_col);
407
408
113k
  __m256i v = _mm256_unpacklo_epi8(u, u);
409
113k
  h_predictor_32x8line(&v, dst, stride);
410
113k
  dst += stride << 2;
411
412
113k
  v = _mm256_unpackhi_epi8(u, u);
413
113k
  h_predictor_32x8line(&v, dst, stride);
414
113k
  dst += stride << 2;
415
416
113k
  u = _mm256_unpackhi_epi8(left_col, left_col);
417
418
113k
  v = _mm256_unpacklo_epi8(u, u);
419
113k
  h_predictor_32x8line(&v, dst, stride);
420
113k
  dst += stride << 2;
421
422
113k
  v = _mm256_unpackhi_epi8(u, u);
423
113k
  h_predictor_32x8line(&v, dst, stride);
424
113k
}
425
426
// -----------------------------------------------------------------------------
427
// Rectangle
428
void aom_dc_predictor_32x16_avx2(uint8_t *dst, ptrdiff_t stride,
429
115k
                                 const uint8_t *above, const uint8_t *left) {
430
115k
  const __m128i top_sum = dc_sum_32_sse2(above);
431
115k
  __m128i left_sum = dc_sum_16_sse2(left);
432
115k
  left_sum = _mm_add_epi16(top_sum, left_sum);
433
115k
  uint16_t sum = (uint16_t)_mm_cvtsi128_si32(left_sum);
434
115k
  sum += 24;
435
115k
  sum /= 48;
436
115k
  const __m256i row = _mm256_set1_epi8((int8_t)sum);
437
115k
  row_store_32xh(&row, 16, dst, stride);
438
115k
}
439
440
void aom_dc_predictor_32x64_avx2(uint8_t *dst, ptrdiff_t stride,
441
8.10k
                                 const uint8_t *above, const uint8_t *left) {
442
8.10k
  const __m256i sum_above = dc_sum_32(above);
443
8.10k
  __m256i sum_left = dc_sum_64(left);
444
8.10k
  sum_left = _mm256_add_epi16(sum_left, sum_above);
445
8.10k
  uint16_t sum = (uint16_t)_mm_cvtsi128_si32(_mm256_castsi256_si128(sum_left));
446
8.10k
  sum += 48;
447
8.10k
  sum /= 96;
448
8.10k
  const __m256i row = _mm256_set1_epi8((int8_t)sum);
449
8.10k
  row_store_32xh(&row, 64, dst, stride);
450
8.10k
}
451
452
void aom_dc_predictor_64x64_avx2(uint8_t *dst, ptrdiff_t stride,
453
91.6k
                                 const uint8_t *above, const uint8_t *left) {
454
91.6k
  const __m256i sum_above = dc_sum_64(above);
455
91.6k
  __m256i sum_left = dc_sum_64(left);
456
91.6k
  sum_left = _mm256_add_epi16(sum_left, sum_above);
457
91.6k
  uint16_t sum = (uint16_t)_mm_cvtsi128_si32(_mm256_castsi256_si128(sum_left));
458
91.6k
  sum += 64;
459
91.6k
  sum /= 128;
460
91.6k
  const __m256i row = _mm256_set1_epi8((int8_t)sum);
461
91.6k
  row_store_64xh(&row, 64, dst, stride);
462
91.6k
}
463
464
void aom_dc_predictor_64x32_avx2(uint8_t *dst, ptrdiff_t stride,
465
13.0k
                                 const uint8_t *above, const uint8_t *left) {
466
13.0k
  const __m256i sum_above = dc_sum_64(above);
467
13.0k
  __m256i sum_left = dc_sum_32(left);
468
13.0k
  sum_left = _mm256_add_epi16(sum_left, sum_above);
469
13.0k
  uint16_t sum = (uint16_t)_mm_cvtsi128_si32(_mm256_castsi256_si128(sum_left));
470
13.0k
  sum += 48;
471
13.0k
  sum /= 96;
472
13.0k
  const __m256i row = _mm256_set1_epi8((int8_t)sum);
473
13.0k
  row_store_64xh(&row, 32, dst, stride);
474
13.0k
}
475
476
#if !CONFIG_REALTIME_ONLY || CONFIG_AV1_DECODER
477
void aom_dc_predictor_64x16_avx2(uint8_t *dst, ptrdiff_t stride,
478
40.5k
                                 const uint8_t *above, const uint8_t *left) {
479
40.5k
  const __m256i sum_above = dc_sum_64(above);
480
40.5k
  __m256i sum_left = _mm256_castsi128_si256(dc_sum_16_sse2(left));
481
40.5k
  sum_left = _mm256_add_epi16(sum_left, sum_above);
482
40.5k
  uint16_t sum = (uint16_t)_mm_cvtsi128_si32(_mm256_castsi256_si128(sum_left));
483
40.5k
  sum += 40;
484
40.5k
  sum /= 80;
485
40.5k
  const __m256i row = _mm256_set1_epi8((int8_t)sum);
486
40.5k
  row_store_64xh(&row, 16, dst, stride);
487
40.5k
}
488
#endif  // !CONFIG_REALTIME_ONLY || CONFIG_AV1_DECODER
489
490
void aom_dc_top_predictor_32x16_avx2(uint8_t *dst, ptrdiff_t stride,
491
                                     const uint8_t *above,
492
8.28k
                                     const uint8_t *left) {
493
8.28k
  __m256i sum = dc_sum_32(above);
494
8.28k
  (void)left;
495
496
8.28k
  const __m256i sixteen = _mm256_set1_epi16(16);
497
8.28k
  sum = _mm256_add_epi16(sum, sixteen);
498
8.28k
  sum = _mm256_srai_epi16(sum, 5);
499
8.28k
  const __m256i zero = _mm256_setzero_si256();
500
8.28k
  __m256i row = _mm256_shuffle_epi8(sum, zero);
501
8.28k
  row_store_32xh(&row, 16, dst, stride);
502
8.28k
}
503
504
void aom_dc_top_predictor_32x64_avx2(uint8_t *dst, ptrdiff_t stride,
505
                                     const uint8_t *above,
506
850
                                     const uint8_t *left) {
507
850
  __m256i sum = dc_sum_32(above);
508
850
  (void)left;
509
510
850
  const __m256i sixteen = _mm256_set1_epi16(16);
511
850
  sum = _mm256_add_epi16(sum, sixteen);
512
850
  sum = _mm256_srai_epi16(sum, 5);
513
850
  const __m256i zero = _mm256_setzero_si256();
514
850
  __m256i row = _mm256_shuffle_epi8(sum, zero);
515
850
  row_store_32xh(&row, 64, dst, stride);
516
850
}
517
518
void aom_dc_top_predictor_64x64_avx2(uint8_t *dst, ptrdiff_t stride,
519
                                     const uint8_t *above,
520
15.7k
                                     const uint8_t *left) {
521
15.7k
  __m256i sum = dc_sum_64(above);
522
15.7k
  (void)left;
523
524
15.7k
  const __m256i thirtytwo = _mm256_set1_epi16(32);
525
15.7k
  sum = _mm256_add_epi16(sum, thirtytwo);
526
15.7k
  sum = _mm256_srai_epi16(sum, 6);
527
15.7k
  const __m256i zero = _mm256_setzero_si256();
528
15.7k
  __m256i row = _mm256_shuffle_epi8(sum, zero);
529
15.7k
  row_store_64xh(&row, 64, dst, stride);
530
15.7k
}
531
532
void aom_dc_top_predictor_64x32_avx2(uint8_t *dst, ptrdiff_t stride,
533
                                     const uint8_t *above,
534
1.01k
                                     const uint8_t *left) {
535
1.01k
  __m256i sum = dc_sum_64(above);
536
1.01k
  (void)left;
537
538
1.01k
  const __m256i thirtytwo = _mm256_set1_epi16(32);
539
1.01k
  sum = _mm256_add_epi16(sum, thirtytwo);
540
1.01k
  sum = _mm256_srai_epi16(sum, 6);
541
1.01k
  const __m256i zero = _mm256_setzero_si256();
542
1.01k
  __m256i row = _mm256_shuffle_epi8(sum, zero);
543
1.01k
  row_store_64xh(&row, 32, dst, stride);
544
1.01k
}
545
546
#if !CONFIG_REALTIME_ONLY || CONFIG_AV1_DECODER
547
void aom_dc_top_predictor_64x16_avx2(uint8_t *dst, ptrdiff_t stride,
548
                                     const uint8_t *above,
549
1.84k
                                     const uint8_t *left) {
550
1.84k
  __m256i sum = dc_sum_64(above);
551
1.84k
  (void)left;
552
553
1.84k
  const __m256i thirtytwo = _mm256_set1_epi16(32);
554
1.84k
  sum = _mm256_add_epi16(sum, thirtytwo);
555
1.84k
  sum = _mm256_srai_epi16(sum, 6);
556
1.84k
  const __m256i zero = _mm256_setzero_si256();
557
1.84k
  __m256i row = _mm256_shuffle_epi8(sum, zero);
558
1.84k
  row_store_64xh(&row, 16, dst, stride);
559
1.84k
}
560
#endif  // !CONFIG_REALTIME_ONLY || CONFIG_AV1_DECODER
561
562
void aom_dc_left_predictor_32x16_avx2(uint8_t *dst, ptrdiff_t stride,
563
                                      const uint8_t *above,
564
6.45k
                                      const uint8_t *left) {
565
6.45k
  __m128i sum = dc_sum_16_sse2(left);
566
6.45k
  (void)above;
567
568
6.45k
  const __m128i eight = _mm_set1_epi16(8);
569
6.45k
  sum = _mm_add_epi16(sum, eight);
570
6.45k
  sum = _mm_srai_epi16(sum, 4);
571
6.45k
  const __m128i zero = _mm_setzero_si128();
572
6.45k
  const __m128i r = _mm_shuffle_epi8(sum, zero);
573
6.45k
  const __m256i row = _mm256_inserti128_si256(_mm256_castsi128_si256(r), r, 1);
574
6.45k
  row_store_32xh(&row, 16, dst, stride);
575
6.45k
}
576
577
void aom_dc_left_predictor_32x64_avx2(uint8_t *dst, ptrdiff_t stride,
578
                                      const uint8_t *above,
579
1.35k
                                      const uint8_t *left) {
580
1.35k
  __m256i sum = dc_sum_64(left);
581
1.35k
  (void)above;
582
583
1.35k
  const __m256i thirtytwo = _mm256_set1_epi16(32);
584
1.35k
  sum = _mm256_add_epi16(sum, thirtytwo);
585
1.35k
  sum = _mm256_srai_epi16(sum, 6);
586
1.35k
  const __m256i zero = _mm256_setzero_si256();
587
1.35k
  __m256i row = _mm256_shuffle_epi8(sum, zero);
588
1.35k
  row_store_32xh(&row, 64, dst, stride);
589
1.35k
}
590
591
void aom_dc_left_predictor_64x64_avx2(uint8_t *dst, ptrdiff_t stride,
592
                                      const uint8_t *above,
593
22.1k
                                      const uint8_t *left) {
594
22.1k
  __m256i sum = dc_sum_64(left);
595
22.1k
  (void)above;
596
597
22.1k
  const __m256i thirtytwo = _mm256_set1_epi16(32);
598
22.1k
  sum = _mm256_add_epi16(sum, thirtytwo);
599
22.1k
  sum = _mm256_srai_epi16(sum, 6);
600
22.1k
  const __m256i zero = _mm256_setzero_si256();
601
22.1k
  __m256i row = _mm256_shuffle_epi8(sum, zero);
602
22.1k
  row_store_64xh(&row, 64, dst, stride);
603
22.1k
}
604
605
void aom_dc_left_predictor_64x32_avx2(uint8_t *dst, ptrdiff_t stride,
606
                                      const uint8_t *above,
607
889
                                      const uint8_t *left) {
608
889
  __m256i sum = dc_sum_32(left);
609
889
  (void)above;
610
611
889
  const __m256i sixteen = _mm256_set1_epi16(16);
612
889
  sum = _mm256_add_epi16(sum, sixteen);
613
889
  sum = _mm256_srai_epi16(sum, 5);
614
889
  const __m256i zero = _mm256_setzero_si256();
615
889
  __m256i row = _mm256_shuffle_epi8(sum, zero);
616
889
  row_store_64xh(&row, 32, dst, stride);
617
889
}
618
619
#if !CONFIG_REALTIME_ONLY || CONFIG_AV1_DECODER
620
void aom_dc_left_predictor_64x16_avx2(uint8_t *dst, ptrdiff_t stride,
621
                                      const uint8_t *above,
622
338
                                      const uint8_t *left) {
623
338
  __m128i sum = dc_sum_16_sse2(left);
624
338
  (void)above;
625
626
338
  const __m128i eight = _mm_set1_epi16(8);
627
338
  sum = _mm_add_epi16(sum, eight);
628
338
  sum = _mm_srai_epi16(sum, 4);
629
338
  const __m128i zero = _mm_setzero_si128();
630
338
  const __m128i r = _mm_shuffle_epi8(sum, zero);
631
338
  const __m256i row = _mm256_inserti128_si256(_mm256_castsi128_si256(r), r, 1);
632
338
  row_store_64xh(&row, 16, dst, stride);
633
338
}
634
#endif  // !CONFIG_REALTIME_ONLY || CONFIG_AV1_DECODER
635
636
void aom_dc_128_predictor_32x16_avx2(uint8_t *dst, ptrdiff_t stride,
637
                                     const uint8_t *above,
638
3.73k
                                     const uint8_t *left) {
639
3.73k
  (void)above;
640
3.73k
  (void)left;
641
3.73k
  const __m256i row = _mm256_set1_epi8((int8_t)0x80);
642
3.73k
  row_store_32xh(&row, 16, dst, stride);
643
3.73k
}
644
645
void aom_dc_128_predictor_32x64_avx2(uint8_t *dst, ptrdiff_t stride,
646
                                     const uint8_t *above,
647
331
                                     const uint8_t *left) {
648
331
  (void)above;
649
331
  (void)left;
650
331
  const __m256i row = _mm256_set1_epi8((int8_t)0x80);
651
331
  row_store_32xh(&row, 64, dst, stride);
652
331
}
653
654
void aom_dc_128_predictor_64x64_avx2(uint8_t *dst, ptrdiff_t stride,
655
                                     const uint8_t *above,
656
9.91k
                                     const uint8_t *left) {
657
9.91k
  (void)above;
658
9.91k
  (void)left;
659
9.91k
  const __m256i row = _mm256_set1_epi8((int8_t)0x80);
660
9.91k
  row_store_64xh(&row, 64, dst, stride);
661
9.91k
}
662
663
void aom_dc_128_predictor_64x32_avx2(uint8_t *dst, ptrdiff_t stride,
664
                                     const uint8_t *above,
665
3.05k
                                     const uint8_t *left) {
666
3.05k
  (void)above;
667
3.05k
  (void)left;
668
3.05k
  const __m256i row = _mm256_set1_epi8((int8_t)0x80);
669
3.05k
  row_store_64xh(&row, 32, dst, stride);
670
3.05k
}
671
672
#if !CONFIG_REALTIME_ONLY || CONFIG_AV1_DECODER
673
void aom_dc_128_predictor_64x16_avx2(uint8_t *dst, ptrdiff_t stride,
674
                                     const uint8_t *above,
675
885
                                     const uint8_t *left) {
676
885
  (void)above;
677
885
  (void)left;
678
885
  const __m256i row = _mm256_set1_epi8((int8_t)0x80);
679
885
  row_store_64xh(&row, 16, dst, stride);
680
885
}
681
#endif  // !CONFIG_REALTIME_ONLY || CONFIG_AV1_DECODER
682
683
void aom_v_predictor_32x16_avx2(uint8_t *dst, ptrdiff_t stride,
684
7.57k
                                const uint8_t *above, const uint8_t *left) {
685
7.57k
  const __m256i row = _mm256_loadu_si256((const __m256i *)above);
686
7.57k
  (void)left;
687
7.57k
  row_store_32xh(&row, 16, dst, stride);
688
7.57k
}
689
690
void aom_v_predictor_32x64_avx2(uint8_t *dst, ptrdiff_t stride,
691
522
                                const uint8_t *above, const uint8_t *left) {
692
522
  const __m256i row = _mm256_loadu_si256((const __m256i *)above);
693
522
  (void)left;
694
522
  row_store_32xh(&row, 64, dst, stride);
695
522
}
696
697
void aom_v_predictor_64x64_avx2(uint8_t *dst, ptrdiff_t stride,
698
2.03k
                                const uint8_t *above, const uint8_t *left) {
699
2.03k
  const __m256i row0 = _mm256_loadu_si256((const __m256i *)above);
700
2.03k
  const __m256i row1 = _mm256_loadu_si256((const __m256i *)(above + 32));
701
2.03k
  (void)left;
702
2.03k
  row_store_32x2xh(&row0, &row1, 64, dst, stride);
703
2.03k
}
704
705
void aom_v_predictor_64x32_avx2(uint8_t *dst, ptrdiff_t stride,
706
693
                                const uint8_t *above, const uint8_t *left) {
707
693
  const __m256i row0 = _mm256_loadu_si256((const __m256i *)above);
708
693
  const __m256i row1 = _mm256_loadu_si256((const __m256i *)(above + 32));
709
693
  (void)left;
710
693
  row_store_32x2xh(&row0, &row1, 32, dst, stride);
711
693
}
712
713
#if !CONFIG_REALTIME_ONLY || CONFIG_AV1_DECODER
714
void aom_v_predictor_64x16_avx2(uint8_t *dst, ptrdiff_t stride,
715
884
                                const uint8_t *above, const uint8_t *left) {
716
884
  const __m256i row0 = _mm256_loadu_si256((const __m256i *)above);
717
884
  const __m256i row1 = _mm256_loadu_si256((const __m256i *)(above + 32));
718
884
  (void)left;
719
884
  row_store_32x2xh(&row0, &row1, 16, dst, stride);
720
884
}
721
#endif  // !CONFIG_REALTIME_ONLY || CONFIG_AV1_DECODER
722
723
// -----------------------------------------------------------------------------
724
// PAETH_PRED
725
726
// Return 16 16-bit pixels in one row (__m256i)
727
static inline __m256i paeth_pred(const __m256i *left, const __m256i *top,
728
99.6M
                                 const __m256i *topleft) {
729
99.6M
  const __m256i base =
730
99.6M
      _mm256_sub_epi16(_mm256_add_epi16(*top, *left), *topleft);
731
732
99.6M
  __m256i pl = _mm256_abs_epi16(_mm256_sub_epi16(base, *left));
733
99.6M
  __m256i pt = _mm256_abs_epi16(_mm256_sub_epi16(base, *top));
734
99.6M
  __m256i ptl = _mm256_abs_epi16(_mm256_sub_epi16(base, *topleft));
735
736
99.6M
  __m256i mask1 = _mm256_cmpgt_epi16(pl, pt);
737
99.6M
  mask1 = _mm256_or_si256(mask1, _mm256_cmpgt_epi16(pl, ptl));
738
99.6M
  __m256i mask2 = _mm256_cmpgt_epi16(pt, ptl);
739
740
99.6M
  pl = _mm256_andnot_si256(mask1, *left);
741
742
99.6M
  ptl = _mm256_and_si256(mask2, *topleft);
743
99.6M
  pt = _mm256_andnot_si256(mask2, *top);
744
99.6M
  pt = _mm256_or_si256(pt, ptl);
745
99.6M
  pt = _mm256_and_si256(mask1, pt);
746
747
99.6M
  return _mm256_or_si256(pt, pl);
748
99.6M
}
749
750
// Return 16 8-bit pixels in one row (__m128i)
751
static inline __m128i paeth_16x1_pred(const __m256i *left, const __m256i *top,
752
98.8M
                                      const __m256i *topleft) {
753
98.8M
  const __m256i p0 = paeth_pred(left, top, topleft);
754
98.8M
  const __m256i p1 = _mm256_permute4x64_epi64(p0, 0xe);
755
98.8M
  const __m256i p = _mm256_packus_epi16(p0, p1);
756
98.8M
  return _mm256_castsi256_si128(p);
757
98.8M
}
758
759
2.73M
static inline __m256i get_top_vector(const uint8_t *above) {
760
2.73M
  const __m128i x = _mm_load_si128((const __m128i *)above);
761
2.73M
  const __m128i zero = _mm_setzero_si128();
762
2.73M
  const __m128i t0 = _mm_unpacklo_epi8(x, zero);
763
2.73M
  const __m128i t1 = _mm_unpackhi_epi8(x, zero);
764
2.73M
  return _mm256_inserti128_si256(_mm256_castsi128_si256(t0), t1, 1);
765
2.73M
}
766
767
void aom_paeth_predictor_16x8_avx2(uint8_t *dst, ptrdiff_t stride,
768
79.1k
                                   const uint8_t *above, const uint8_t *left) {
769
79.1k
  __m128i x = _mm_loadl_epi64((const __m128i *)left);
770
79.1k
  const __m256i l = _mm256_inserti128_si256(_mm256_castsi128_si256(x), x, 1);
771
79.1k
  const __m256i tl16 = _mm256_set1_epi16((int16_t)above[-1]);
772
79.1k
  __m256i rep = _mm256_set1_epi16((short)0x8000);
773
79.1k
  const __m256i one = _mm256_set1_epi16(1);
774
79.1k
  const __m256i top = get_top_vector(above);
775
776
79.1k
  int i;
777
712k
  for (i = 0; i < 8; ++i) {
778
632k
    const __m256i l16 = _mm256_shuffle_epi8(l, rep);
779
632k
    const __m128i row = paeth_16x1_pred(&l16, &top, &tl16);
780
781
632k
    _mm_store_si128((__m128i *)dst, row);
782
632k
    dst += stride;
783
632k
    rep = _mm256_add_epi16(rep, one);
784
632k
  }
785
79.1k
}
786
787
5.16M
static inline __m256i get_left_vector(const uint8_t *left) {
788
5.16M
  const __m128i x = _mm_load_si128((const __m128i *)left);
789
5.16M
  return _mm256_inserti128_si256(_mm256_castsi128_si256(x), x, 1);
790
5.16M
}
791
792
void aom_paeth_predictor_16x16_avx2(uint8_t *dst, ptrdiff_t stride,
793
87.0k
                                    const uint8_t *above, const uint8_t *left) {
794
87.0k
  const __m256i l = get_left_vector(left);
795
87.0k
  const __m256i tl16 = _mm256_set1_epi16((int16_t)above[-1]);
796
87.0k
  __m256i rep = _mm256_set1_epi16((short)0x8000);
797
87.0k
  const __m256i one = _mm256_set1_epi16(1);
798
87.0k
  const __m256i top = get_top_vector(above);
799
800
87.0k
  int i;
801
1.48M
  for (i = 0; i < 16; ++i) {
802
1.39M
    const __m256i l16 = _mm256_shuffle_epi8(l, rep);
803
1.39M
    const __m128i row = paeth_16x1_pred(&l16, &top, &tl16);
804
805
1.39M
    _mm_store_si128((__m128i *)dst, row);
806
1.39M
    dst += stride;
807
1.39M
    rep = _mm256_add_epi16(rep, one);
808
1.39M
  }
809
87.0k
}
810
811
void aom_paeth_predictor_16x32_avx2(uint8_t *dst, ptrdiff_t stride,
812
1.44M
                                    const uint8_t *above, const uint8_t *left) {
813
1.44M
  __m256i l = get_left_vector(left);
814
1.44M
  const __m256i tl16 = _mm256_set1_epi16((int16_t)above[-1]);
815
1.44M
  __m256i rep = _mm256_set1_epi16((short)0x8000);
816
1.44M
  const __m256i one = _mm256_set1_epi16(1);
817
1.44M
  const __m256i top = get_top_vector(above);
818
819
1.44M
  int i;
820
24.5M
  for (i = 0; i < 16; ++i) {
821
23.0M
    const __m256i l16 = _mm256_shuffle_epi8(l, rep);
822
23.0M
    const __m128i row = paeth_16x1_pred(&l16, &top, &tl16);
823
824
23.0M
    _mm_store_si128((__m128i *)dst, row);
825
23.0M
    dst += stride;
826
23.0M
    rep = _mm256_add_epi16(rep, one);
827
23.0M
  }
828
829
1.44M
  l = get_left_vector(left + 16);
830
1.44M
  rep = _mm256_set1_epi16((short)0x8000);
831
24.5M
  for (i = 0; i < 16; ++i) {
832
23.0M
    const __m256i l16 = _mm256_shuffle_epi8(l, rep);
833
23.0M
    const __m128i row = paeth_16x1_pred(&l16, &top, &tl16);
834
835
23.0M
    _mm_store_si128((__m128i *)dst, row);
836
23.0M
    dst += stride;
837
23.0M
    rep = _mm256_add_epi16(rep, one);
838
23.0M
  }
839
1.44M
}
840
841
#if !CONFIG_REALTIME_ONLY || CONFIG_AV1_DECODER
842
void aom_paeth_predictor_16x64_avx2(uint8_t *dst, ptrdiff_t stride,
843
362k
                                    const uint8_t *above, const uint8_t *left) {
844
362k
  const __m256i tl16 = _mm256_set1_epi16((int16_t)above[-1]);
845
362k
  const __m256i one = _mm256_set1_epi16(1);
846
362k
  const __m256i top = get_top_vector(above);
847
848
1.81M
  for (int j = 0; j < 4; ++j) {
849
1.44M
    const __m256i l = get_left_vector(left + j * 16);
850
1.44M
    __m256i rep = _mm256_set1_epi16((short)0x8000);
851
24.6M
    for (int i = 0; i < 16; ++i) {
852
23.1M
      const __m256i l16 = _mm256_shuffle_epi8(l, rep);
853
23.1M
      const __m128i row = paeth_16x1_pred(&l16, &top, &tl16);
854
855
23.1M
      _mm_store_si128((__m128i *)dst, row);
856
23.1M
      dst += stride;
857
23.1M
      rep = _mm256_add_epi16(rep, one);
858
23.1M
    }
859
1.44M
  }
860
362k
}
861
#endif  // !CONFIG_REALTIME_ONLY || CONFIG_AV1_DECODER
862
863
// Return 32 8-bit pixels in one row (__m256i)
864
static inline __m256i paeth_32x1_pred(const __m256i *left, const __m256i *top0,
865
                                      const __m256i *top1,
866
431k
                                      const __m256i *topleft) {
867
431k
  __m256i p0 = paeth_pred(left, top0, topleft);
868
431k
  __m256i p1 = _mm256_permute4x64_epi64(p0, 0xe);
869
431k
  const __m256i x0 = _mm256_packus_epi16(p0, p1);
870
871
431k
  p0 = paeth_pred(left, top1, topleft);
872
431k
  p1 = _mm256_permute4x64_epi64(p0, 0xe);
873
431k
  const __m256i x1 = _mm256_packus_epi16(p0, p1);
874
875
431k
  return _mm256_permute2x128_si256(x0, x1, 0x20);
876
431k
}
877
878
void aom_paeth_predictor_32x16_avx2(uint8_t *dst, ptrdiff_t stride,
879
26.9k
                                    const uint8_t *above, const uint8_t *left) {
880
26.9k
  const __m256i l = get_left_vector(left);
881
26.9k
  const __m256i t0 = get_top_vector(above);
882
26.9k
  const __m256i t1 = get_top_vector(above + 16);
883
26.9k
  const __m256i tl = _mm256_set1_epi16((int16_t)above[-1]);
884
26.9k
  __m256i rep = _mm256_set1_epi16((short)0x8000);
885
26.9k
  const __m256i one = _mm256_set1_epi16(1);
886
887
26.9k
  int i;
888
457k
  for (i = 0; i < 16; ++i) {
889
431k
    const __m256i l16 = _mm256_shuffle_epi8(l, rep);
890
891
431k
    const __m256i r = paeth_32x1_pred(&l16, &t0, &t1, &tl);
892
893
431k
    _mm256_storeu_si256((__m256i *)dst, r);
894
895
431k
    dst += stride;
896
431k
    rep = _mm256_add_epi16(rep, one);
897
431k
  }
898
26.9k
}
899
900
void aom_paeth_predictor_32x32_avx2(uint8_t *dst, ptrdiff_t stride,
901
250k
                                    const uint8_t *above, const uint8_t *left) {
902
250k
  __m256i l = get_left_vector(left);
903
250k
  const __m256i t0 = get_top_vector(above);
904
250k
  const __m256i t1 = get_top_vector(above + 16);
905
250k
  const __m256i tl = _mm256_set1_epi16((int16_t)above[-1]);
906
250k
  __m256i rep = _mm256_set1_epi16((short)0x8000);
907
250k
  const __m256i one = _mm256_set1_epi16(1);
908
909
250k
  int i;
910
4.25M
  for (i = 0; i < 16; ++i) {
911
4.00M
    const __m256i l16 = _mm256_shuffle_epi8(l, rep);
912
913
4.00M
    const __m128i r0 = paeth_16x1_pred(&l16, &t0, &tl);
914
4.00M
    const __m128i r1 = paeth_16x1_pred(&l16, &t1, &tl);
915
916
4.00M
    _mm_store_si128((__m128i *)dst, r0);
917
4.00M
    _mm_store_si128((__m128i *)(dst + 16), r1);
918
919
4.00M
    dst += stride;
920
4.00M
    rep = _mm256_add_epi16(rep, one);
921
4.00M
  }
922
923
250k
  l = get_left_vector(left + 16);
924
250k
  rep = _mm256_set1_epi16((short)0x8000);
925
4.25M
  for (i = 0; i < 16; ++i) {
926
4.00M
    const __m256i l16 = _mm256_shuffle_epi8(l, rep);
927
928
4.00M
    const __m128i r0 = paeth_16x1_pred(&l16, &t0, &tl);
929
4.00M
    const __m128i r1 = paeth_16x1_pred(&l16, &t1, &tl);
930
931
4.00M
    _mm_store_si128((__m128i *)dst, r0);
932
4.00M
    _mm_store_si128((__m128i *)(dst + 16), r1);
933
934
4.00M
    dst += stride;
935
4.00M
    rep = _mm256_add_epi16(rep, one);
936
4.00M
  }
937
250k
}
938
939
void aom_paeth_predictor_32x64_avx2(uint8_t *dst, ptrdiff_t stride,
940
19.4k
                                    const uint8_t *above, const uint8_t *left) {
941
19.4k
  const __m256i t0 = get_top_vector(above);
942
19.4k
  const __m256i t1 = get_top_vector(above + 16);
943
19.4k
  const __m256i tl = _mm256_set1_epi16((int16_t)above[-1]);
944
19.4k
  const __m256i one = _mm256_set1_epi16(1);
945
946
19.4k
  int i, j;
947
97.2k
  for (j = 0; j < 4; ++j) {
948
77.8k
    const __m256i l = get_left_vector(left + j * 16);
949
77.8k
    __m256i rep = _mm256_set1_epi16((short)0x8000);
950
1.32M
    for (i = 0; i < 16; ++i) {
951
1.24M
      const __m256i l16 = _mm256_shuffle_epi8(l, rep);
952
953
1.24M
      const __m128i r0 = paeth_16x1_pred(&l16, &t0, &tl);
954
1.24M
      const __m128i r1 = paeth_16x1_pred(&l16, &t1, &tl);
955
956
1.24M
      _mm_store_si128((__m128i *)dst, r0);
957
1.24M
      _mm_store_si128((__m128i *)(dst + 16), r1);
958
959
1.24M
      dst += stride;
960
1.24M
      rep = _mm256_add_epi16(rep, one);
961
1.24M
    }
962
77.8k
  }
963
19.4k
}
964
965
void aom_paeth_predictor_64x32_avx2(uint8_t *dst, ptrdiff_t stride,
966
6.11k
                                    const uint8_t *above, const uint8_t *left) {
967
6.11k
  const __m256i t0 = get_top_vector(above);
968
6.11k
  const __m256i t1 = get_top_vector(above + 16);
969
6.11k
  const __m256i t2 = get_top_vector(above + 32);
970
6.11k
  const __m256i t3 = get_top_vector(above + 48);
971
6.11k
  const __m256i tl = _mm256_set1_epi16((int16_t)above[-1]);
972
6.11k
  const __m256i one = _mm256_set1_epi16(1);
973
974
6.11k
  int i, j;
975
18.3k
  for (j = 0; j < 2; ++j) {
976
12.2k
    const __m256i l = get_left_vector(left + j * 16);
977
12.2k
    __m256i rep = _mm256_set1_epi16((short)0x8000);
978
207k
    for (i = 0; i < 16; ++i) {
979
195k
      const __m256i l16 = _mm256_shuffle_epi8(l, rep);
980
981
195k
      const __m128i r0 = paeth_16x1_pred(&l16, &t0, &tl);
982
195k
      const __m128i r1 = paeth_16x1_pred(&l16, &t1, &tl);
983
195k
      const __m128i r2 = paeth_16x1_pred(&l16, &t2, &tl);
984
195k
      const __m128i r3 = paeth_16x1_pred(&l16, &t3, &tl);
985
986
195k
      _mm_store_si128((__m128i *)dst, r0);
987
195k
      _mm_store_si128((__m128i *)(dst + 16), r1);
988
195k
      _mm_store_si128((__m128i *)(dst + 32), r2);
989
195k
      _mm_store_si128((__m128i *)(dst + 48), r3);
990
991
195k
      dst += stride;
992
195k
      rep = _mm256_add_epi16(rep, one);
993
195k
    }
994
12.2k
  }
995
6.11k
}
996
997
void aom_paeth_predictor_64x64_avx2(uint8_t *dst, ptrdiff_t stride,
998
30.2k
                                    const uint8_t *above, const uint8_t *left) {
999
30.2k
  const __m256i t0 = get_top_vector(above);
1000
30.2k
  const __m256i t1 = get_top_vector(above + 16);
1001
30.2k
  const __m256i t2 = get_top_vector(above + 32);
1002
30.2k
  const __m256i t3 = get_top_vector(above + 48);
1003
30.2k
  const __m256i tl = _mm256_set1_epi16((int16_t)above[-1]);
1004
30.2k
  const __m256i one = _mm256_set1_epi16(1);
1005
1006
30.2k
  int i, j;
1007
151k
  for (j = 0; j < 4; ++j) {
1008
120k
    const __m256i l = get_left_vector(left + j * 16);
1009
120k
    __m256i rep = _mm256_set1_epi16((short)0x8000);
1010
2.05M
    for (i = 0; i < 16; ++i) {
1011
1.93M
      const __m256i l16 = _mm256_shuffle_epi8(l, rep);
1012
1013
1.93M
      const __m128i r0 = paeth_16x1_pred(&l16, &t0, &tl);
1014
1.93M
      const __m128i r1 = paeth_16x1_pred(&l16, &t1, &tl);
1015
1.93M
      const __m128i r2 = paeth_16x1_pred(&l16, &t2, &tl);
1016
1.93M
      const __m128i r3 = paeth_16x1_pred(&l16, &t3, &tl);
1017
1018
1.93M
      _mm_store_si128((__m128i *)dst, r0);
1019
1.93M
      _mm_store_si128((__m128i *)(dst + 16), r1);
1020
1.93M
      _mm_store_si128((__m128i *)(dst + 32), r2);
1021
1.93M
      _mm_store_si128((__m128i *)(dst + 48), r3);
1022
1023
1.93M
      dst += stride;
1024
1.93M
      rep = _mm256_add_epi16(rep, one);
1025
1.93M
    }
1026
120k
  }
1027
30.2k
}
1028
1029
#if !CONFIG_REALTIME_ONLY || CONFIG_AV1_DECODER
1030
void aom_paeth_predictor_64x16_avx2(uint8_t *dst, ptrdiff_t stride,
1031
7.13k
                                    const uint8_t *above, const uint8_t *left) {
1032
7.13k
  const __m256i t0 = get_top_vector(above);
1033
7.13k
  const __m256i t1 = get_top_vector(above + 16);
1034
7.13k
  const __m256i t2 = get_top_vector(above + 32);
1035
7.13k
  const __m256i t3 = get_top_vector(above + 48);
1036
7.13k
  const __m256i tl = _mm256_set1_epi16((int16_t)above[-1]);
1037
7.13k
  const __m256i one = _mm256_set1_epi16(1);
1038
1039
7.13k
  int i;
1040
7.13k
  const __m256i l = get_left_vector(left);
1041
7.13k
  __m256i rep = _mm256_set1_epi16((short)0x8000);
1042
121k
  for (i = 0; i < 16; ++i) {
1043
114k
    const __m256i l16 = _mm256_shuffle_epi8(l, rep);
1044
1045
114k
    const __m128i r0 = paeth_16x1_pred(&l16, &t0, &tl);
1046
114k
    const __m128i r1 = paeth_16x1_pred(&l16, &t1, &tl);
1047
114k
    const __m128i r2 = paeth_16x1_pred(&l16, &t2, &tl);
1048
114k
    const __m128i r3 = paeth_16x1_pred(&l16, &t3, &tl);
1049
1050
114k
    _mm_store_si128((__m128i *)dst, r0);
1051
114k
    _mm_store_si128((__m128i *)(dst + 16), r1);
1052
114k
    _mm_store_si128((__m128i *)(dst + 32), r2);
1053
114k
    _mm_store_si128((__m128i *)(dst + 48), r3);
1054
1055
114k
    dst += stride;
1056
114k
    rep = _mm256_add_epi16(rep, one);
1057
114k
  }
1058
7.13k
}
1059
#endif  // !CONFIG_REALTIME_ONLY || CONFIG_AV1_DECODER
1060
1061
#if CONFIG_AV1_HIGHBITDEPTH
1062
1063
static AOM_FORCE_INLINE void highbd_dr_prediction_z1_4xN_internal_avx2(
1064
392k
    int N, __m128i *dst, const uint16_t *above, int upsample_above, int dx) {
1065
392k
  const int frac_bits = 6 - upsample_above;
1066
392k
  const int max_base_x = ((N + 4) - 1) << upsample_above;
1067
1068
392k
  assert(dx > 0);
1069
  // pre-filter above pixels
1070
  // store in temp buffers:
1071
  //   above[x] * 32 + 16
1072
  //   above[x+1] - above[x]
1073
  // final pixels will be calculated as:
1074
  //   (above[x] * 32 + 16 + (above[x+1] - above[x]) * shift) >> 5
1075
392k
  __m256i a0, a1, a32, a16;
1076
392k
  __m256i diff, c3f;
1077
392k
  __m128i a_mbase_x, max_base_x128, base_inc128, mask128;
1078
392k
  __m128i a0_128, a1_128;
1079
392k
  a16 = _mm256_set1_epi16(16);
1080
392k
  a_mbase_x = _mm_set1_epi16(above[max_base_x]);
1081
392k
  max_base_x128 = _mm_set1_epi16(max_base_x);
1082
392k
  c3f = _mm256_set1_epi16(0x3f);
1083
1084
392k
  int x = dx;
1085
3.12M
  for (int r = 0; r < N; r++) {
1086
2.74M
    __m256i b, res, shift;
1087
2.74M
    __m128i res1;
1088
1089
2.74M
    int base = x >> frac_bits;
1090
2.74M
    if (base >= max_base_x) {
1091
10.2k
      for (int i = r; i < N; ++i) {
1092
5.82k
        dst[i] = a_mbase_x;  // save 4 values
1093
5.82k
      }
1094
4.38k
      return;
1095
4.38k
    }
1096
1097
2.73M
    a0_128 = _mm_loadu_si128((__m128i *)(above + base));
1098
2.73M
    a1_128 = _mm_loadu_si128((__m128i *)(above + base + 1));
1099
1100
2.73M
    if (upsample_above) {
1101
955k
      a0_128 = _mm_shuffle_epi8(a0_128, *(__m128i *)HighbdEvenOddMaskx4[0]);
1102
955k
      a1_128 = _mm_srli_si128(a0_128, 8);
1103
1104
955k
      base_inc128 = _mm_setr_epi16(base, base + 2, base + 4, base + 6, base + 8,
1105
955k
                                   base + 10, base + 12, base + 14);
1106
955k
      shift = _mm256_srli_epi16(
1107
955k
          _mm256_and_si256(
1108
955k
              _mm256_slli_epi16(_mm256_set1_epi16(x), upsample_above),
1109
955k
              _mm256_set1_epi16(0x3f)),
1110
955k
          1);
1111
1.78M
    } else {
1112
1.78M
      base_inc128 = _mm_setr_epi16(base, base + 1, base + 2, base + 3, base + 4,
1113
1.78M
                                   base + 5, base + 6, base + 7);
1114
1.78M
      shift = _mm256_srli_epi16(_mm256_and_si256(_mm256_set1_epi16(x), c3f), 1);
1115
1.78M
    }
1116
2.73M
    a0 = _mm256_castsi128_si256(a0_128);
1117
2.73M
    a1 = _mm256_castsi128_si256(a1_128);
1118
2.73M
    diff = _mm256_sub_epi16(a1, a0);   // a[x+1] - a[x]
1119
2.73M
    a32 = _mm256_slli_epi16(a0, 5);    // a[x] * 32
1120
2.73M
    a32 = _mm256_add_epi16(a32, a16);  // a[x] * 32 + 16
1121
1122
2.73M
    b = _mm256_mullo_epi16(diff, shift);
1123
2.73M
    res = _mm256_add_epi16(a32, b);
1124
2.73M
    res = _mm256_srli_epi16(res, 5);
1125
2.73M
    res1 = _mm256_castsi256_si128(res);
1126
1127
2.73M
    mask128 = _mm_cmpgt_epi16(max_base_x128, base_inc128);
1128
2.73M
    dst[r] = _mm_blendv_epi8(a_mbase_x, res1, mask128);
1129
2.73M
    x += dx;
1130
2.73M
  }
1131
392k
}
1132
1133
static AOM_FORCE_INLINE void highbd_dr_prediction_32bit_z1_4xN_internal_avx2(
1134
96.2k
    int N, __m128i *dst, const uint16_t *above, int upsample_above, int dx) {
1135
96.2k
  const int frac_bits = 6 - upsample_above;
1136
96.2k
  const int max_base_x = ((N + 4) - 1) << upsample_above;
1137
1138
96.2k
  assert(dx > 0);
1139
  // pre-filter above pixels
1140
  // store in temp buffers:
1141
  //   above[x] * 32 + 16
1142
  //   above[x+1] - above[x]
1143
  // final pixels will be calculated as:
1144
  //   (above[x] * 32 + 16 + (above[x+1] - above[x]) * shift) >> 5
1145
96.2k
  __m256i a0, a1, a32, a16;
1146
96.2k
  __m256i diff;
1147
96.2k
  __m128i a_mbase_x, max_base_x128, base_inc128, mask128;
1148
1149
96.2k
  a16 = _mm256_set1_epi32(16);
1150
96.2k
  a_mbase_x = _mm_set1_epi16(above[max_base_x]);
1151
96.2k
  max_base_x128 = _mm_set1_epi32(max_base_x);
1152
1153
96.2k
  int x = dx;
1154
811k
  for (int r = 0; r < N; r++) {
1155
716k
    __m256i b, res, shift;
1156
716k
    __m128i res1;
1157
1158
716k
    int base = x >> frac_bits;
1159
716k
    if (base >= max_base_x) {
1160
3.29k
      for (int i = r; i < N; ++i) {
1161
2.31k
        dst[i] = a_mbase_x;  // save 4 values
1162
2.31k
      }
1163
981
      return;
1164
981
    }
1165
1166
715k
    a0 = _mm256_cvtepu16_epi32(_mm_loadu_si128((__m128i *)(above + base)));
1167
715k
    a1 = _mm256_cvtepu16_epi32(_mm_loadu_si128((__m128i *)(above + base + 1)));
1168
1169
715k
    if (upsample_above) {
1170
169k
      a0 = _mm256_permutevar8x32_epi32(
1171
169k
          a0, _mm256_set_epi32(7, 5, 3, 1, 6, 4, 2, 0));
1172
169k
      a1 = _mm256_castsi128_si256(_mm256_extracti128_si256(a0, 1));
1173
169k
      base_inc128 = _mm_setr_epi32(base, base + 2, base + 4, base + 6);
1174
169k
      shift = _mm256_srli_epi32(
1175
169k
          _mm256_and_si256(
1176
169k
              _mm256_slli_epi32(_mm256_set1_epi32(x), upsample_above),
1177
169k
              _mm256_set1_epi32(0x3f)),
1178
169k
          1);
1179
546k
    } else {
1180
546k
      base_inc128 = _mm_setr_epi32(base, base + 1, base + 2, base + 3);
1181
546k
      shift = _mm256_srli_epi32(
1182
546k
          _mm256_and_si256(_mm256_set1_epi32(x), _mm256_set1_epi32(0x3f)), 1);
1183
546k
    }
1184
1185
715k
    diff = _mm256_sub_epi32(a1, a0);   // a[x+1] - a[x]
1186
715k
    a32 = _mm256_slli_epi32(a0, 5);    // a[x] * 32
1187
715k
    a32 = _mm256_add_epi32(a32, a16);  // a[x] * 32 + 16
1188
1189
715k
    b = _mm256_mullo_epi32(diff, shift);
1190
715k
    res = _mm256_add_epi32(a32, b);
1191
715k
    res = _mm256_srli_epi32(res, 5);
1192
1193
715k
    res1 = _mm256_castsi256_si128(res);
1194
715k
    res1 = _mm_packus_epi32(res1, res1);
1195
1196
715k
    mask128 = _mm_cmpgt_epi32(max_base_x128, base_inc128);
1197
715k
    mask128 = _mm_packs_epi32(mask128, mask128);  // goto 16 bit
1198
715k
    dst[r] = _mm_blendv_epi8(a_mbase_x, res1, mask128);
1199
715k
    x += dx;
1200
715k
  }
1201
96.2k
}
1202
1203
static void highbd_dr_prediction_z1_4xN_avx2(int N, uint16_t *dst,
1204
                                             ptrdiff_t stride,
1205
                                             const uint16_t *above,
1206
                                             int upsample_above, int dx,
1207
190k
                                             int bd) {
1208
190k
  __m128i dstvec[16];
1209
190k
  if (bd < 12) {
1210
145k
    highbd_dr_prediction_z1_4xN_internal_avx2(N, dstvec, above, upsample_above,
1211
145k
                                              dx);
1212
145k
  } else {
1213
44.8k
    highbd_dr_prediction_32bit_z1_4xN_internal_avx2(N, dstvec, above,
1214
44.8k
                                                    upsample_above, dx);
1215
44.8k
  }
1216
1.39M
  for (int i = 0; i < N; i++) {
1217
1.20M
    _mm_storel_epi64((__m128i *)(dst + stride * i), dstvec[i]);
1218
1.20M
  }
1219
190k
}
1220
1221
static AOM_FORCE_INLINE void highbd_dr_prediction_32bit_z1_8xN_internal_avx2(
1222
123k
    int N, __m128i *dst, const uint16_t *above, int upsample_above, int dx) {
1223
123k
  const int frac_bits = 6 - upsample_above;
1224
123k
  const int max_base_x = ((8 + N) - 1) << upsample_above;
1225
1226
123k
  assert(dx > 0);
1227
  // pre-filter above pixels
1228
  // store in temp buffers:
1229
  //   above[x] * 32 + 16
1230
  //   above[x+1] - above[x]
1231
  // final pixels will be calculated as:
1232
  //   (above[x] * 32 + 16 + (above[x+1] - above[x]) * shift) >> 5
1233
123k
  __m256i a0, a1, a0_1, a1_1, a32, a16;
1234
123k
  __m256i a_mbase_x, diff, max_base_x256, base_inc256, mask256;
1235
1236
123k
  a16 = _mm256_set1_epi32(16);
1237
123k
  a_mbase_x = _mm256_set1_epi16(above[max_base_x]);
1238
123k
  max_base_x256 = _mm256_set1_epi32(max_base_x);
1239
1240
123k
  int x = dx;
1241
1.44M
  for (int r = 0; r < N; r++) {
1242
1.31M
    __m256i b, res, res1, shift;
1243
1244
1.31M
    int base = x >> frac_bits;
1245
1.31M
    if (base >= max_base_x) {
1246
3.09k
      for (int i = r; i < N; ++i) {
1247
2.27k
        dst[i] = _mm256_castsi256_si128(a_mbase_x);  // save 8 values
1248
2.27k
      }
1249
827
      return;
1250
827
    }
1251
1252
1.31M
    a0 = _mm256_cvtepu16_epi32(_mm_loadu_si128((__m128i *)(above + base)));
1253
1.31M
    a1 = _mm256_cvtepu16_epi32(_mm_loadu_si128((__m128i *)(above + base + 1)));
1254
1255
1.31M
    if (upsample_above) {
1256
259k
      a0 = _mm256_permutevar8x32_epi32(
1257
259k
          a0, _mm256_set_epi32(7, 5, 3, 1, 6, 4, 2, 0));
1258
259k
      a1 = _mm256_castsi128_si256(_mm256_extracti128_si256(a0, 1));
1259
1260
259k
      a0_1 =
1261
259k
          _mm256_cvtepu16_epi32(_mm_loadu_si128((__m128i *)(above + base + 8)));
1262
259k
      a0_1 = _mm256_permutevar8x32_epi32(
1263
259k
          a0_1, _mm256_set_epi32(7, 5, 3, 1, 6, 4, 2, 0));
1264
259k
      a1_1 = _mm256_castsi128_si256(_mm256_extracti128_si256(a0_1, 1));
1265
1266
259k
      a0 = _mm256_inserti128_si256(a0, _mm256_castsi256_si128(a0_1), 1);
1267
259k
      a1 = _mm256_inserti128_si256(a1, _mm256_castsi256_si128(a1_1), 1);
1268
259k
      base_inc256 =
1269
259k
          _mm256_setr_epi32(base, base + 2, base + 4, base + 6, base + 8,
1270
259k
                            base + 10, base + 12, base + 14);
1271
259k
      shift = _mm256_srli_epi32(
1272
259k
          _mm256_and_si256(
1273
259k
              _mm256_slli_epi32(_mm256_set1_epi32(x), upsample_above),
1274
259k
              _mm256_set1_epi32(0x3f)),
1275
259k
          1);
1276
1.05M
    } else {
1277
1.05M
      base_inc256 = _mm256_setr_epi32(base, base + 1, base + 2, base + 3,
1278
1.05M
                                      base + 4, base + 5, base + 6, base + 7);
1279
1.05M
      shift = _mm256_srli_epi32(
1280
1.05M
          _mm256_and_si256(_mm256_set1_epi32(x), _mm256_set1_epi32(0x3f)), 1);
1281
1.05M
    }
1282
1283
1.31M
    diff = _mm256_sub_epi32(a1, a0);   // a[x+1] - a[x]
1284
1.31M
    a32 = _mm256_slli_epi32(a0, 5);    // a[x] * 32
1285
1.31M
    a32 = _mm256_add_epi32(a32, a16);  // a[x] * 32 + 16
1286
1287
1.31M
    b = _mm256_mullo_epi32(diff, shift);
1288
1.31M
    res = _mm256_add_epi32(a32, b);
1289
1.31M
    res = _mm256_srli_epi32(res, 5);
1290
1291
1.31M
    res1 = _mm256_packus_epi32(
1292
1.31M
        res, _mm256_castsi128_si256(_mm256_extracti128_si256(res, 1)));
1293
1294
1.31M
    mask256 = _mm256_cmpgt_epi32(max_base_x256, base_inc256);
1295
1.31M
    mask256 = _mm256_packs_epi32(
1296
1.31M
        mask256, _mm256_castsi128_si256(
1297
1.31M
                     _mm256_extracti128_si256(mask256, 1)));  // goto 16 bit
1298
1.31M
    res1 = _mm256_blendv_epi8(a_mbase_x, res1, mask256);
1299
1.31M
    dst[r] = _mm256_castsi256_si128(res1);
1300
1.31M
    x += dx;
1301
1.31M
  }
1302
123k
}
1303
1304
static AOM_FORCE_INLINE void highbd_dr_prediction_z1_8xN_internal_avx2(
1305
411k
    int N, __m128i *dst, const uint16_t *above, int upsample_above, int dx) {
1306
411k
  const int frac_bits = 6 - upsample_above;
1307
411k
  const int max_base_x = ((8 + N) - 1) << upsample_above;
1308
1309
411k
  assert(dx > 0);
1310
  // pre-filter above pixels
1311
  // store in temp buffers:
1312
  //   above[x] * 32 + 16
1313
  //   above[x+1] - above[x]
1314
  // final pixels will be calculated as:
1315
  //   (above[x] * 32 + 16 + (above[x+1] - above[x]) * shift) >> 5
1316
411k
  __m256i a0, a1, a32, a16, c3f;
1317
411k
  __m256i a_mbase_x, diff, max_base_x256, base_inc256, mask256;
1318
411k
  __m128i a0_x128, a1_x128;
1319
1320
411k
  a16 = _mm256_set1_epi16(16);
1321
411k
  a_mbase_x = _mm256_set1_epi16(above[max_base_x]);
1322
411k
  max_base_x256 = _mm256_set1_epi16(max_base_x);
1323
411k
  c3f = _mm256_set1_epi16(0x3f);
1324
1325
411k
  int x = dx;
1326
5.64M
  for (int r = 0; r < N; r++) {
1327
5.23M
    __m256i b, res, res1, shift;
1328
1329
5.23M
    int base = x >> frac_bits;
1330
5.23M
    if (base >= max_base_x) {
1331
7.02k
      for (int i = r; i < N; ++i) {
1332
5.03k
        dst[i] = _mm256_castsi256_si128(a_mbase_x);  // save 8 values
1333
5.03k
      }
1334
1.99k
      return;
1335
1.99k
    }
1336
1337
5.23M
    a0_x128 = _mm_loadu_si128((__m128i *)(above + base));
1338
5.23M
    if (upsample_above) {
1339
1.12M
      __m128i mask, atmp0, atmp1, atmp2, atmp3;
1340
1.12M
      a1_x128 = _mm_loadu_si128((__m128i *)(above + base + 8));
1341
1.12M
      atmp0 = _mm_shuffle_epi8(a0_x128, *(__m128i *)HighbdEvenOddMaskx[0]);
1342
1.12M
      atmp1 = _mm_shuffle_epi8(a1_x128, *(__m128i *)HighbdEvenOddMaskx[0]);
1343
1.12M
      atmp2 =
1344
1.12M
          _mm_shuffle_epi8(a0_x128, *(__m128i *)(HighbdEvenOddMaskx[0] + 16));
1345
1.12M
      atmp3 =
1346
1.12M
          _mm_shuffle_epi8(a1_x128, *(__m128i *)(HighbdEvenOddMaskx[0] + 16));
1347
1.12M
      mask =
1348
1.12M
          _mm_cmpgt_epi8(*(__m128i *)HighbdEvenOddMaskx[0], _mm_set1_epi8(15));
1349
1.12M
      a0_x128 = _mm_blendv_epi8(atmp0, atmp1, mask);
1350
1.12M
      mask = _mm_cmpgt_epi8(*(__m128i *)(HighbdEvenOddMaskx[0] + 16),
1351
1.12M
                            _mm_set1_epi8(15));
1352
1.12M
      a1_x128 = _mm_blendv_epi8(atmp2, atmp3, mask);
1353
1354
1.12M
      base_inc256 = _mm256_setr_epi16(base, base + 2, base + 4, base + 6,
1355
1.12M
                                      base + 8, base + 10, base + 12, base + 14,
1356
1.12M
                                      0, 0, 0, 0, 0, 0, 0, 0);
1357
1.12M
      shift = _mm256_srli_epi16(
1358
1.12M
          _mm256_and_si256(
1359
1.12M
              _mm256_slli_epi16(_mm256_set1_epi16(x), upsample_above), c3f),
1360
1.12M
          1);
1361
4.11M
    } else {
1362
4.11M
      a1_x128 = _mm_loadu_si128((__m128i *)(above + base + 1));
1363
4.11M
      base_inc256 = _mm256_setr_epi16(base, base + 1, base + 2, base + 3,
1364
4.11M
                                      base + 4, base + 5, base + 6, base + 7, 0,
1365
4.11M
                                      0, 0, 0, 0, 0, 0, 0);
1366
4.11M
      shift = _mm256_srli_epi16(_mm256_and_si256(_mm256_set1_epi16(x), c3f), 1);
1367
4.11M
    }
1368
5.23M
    a0 = _mm256_castsi128_si256(a0_x128);
1369
5.23M
    a1 = _mm256_castsi128_si256(a1_x128);
1370
1371
5.23M
    diff = _mm256_sub_epi16(a1, a0);   // a[x+1] - a[x]
1372
5.23M
    a32 = _mm256_slli_epi16(a0, 5);    // a[x] * 32
1373
5.23M
    a32 = _mm256_add_epi16(a32, a16);  // a[x] * 32 + 16
1374
1375
5.23M
    b = _mm256_mullo_epi16(diff, shift);
1376
5.23M
    res = _mm256_add_epi16(a32, b);
1377
5.23M
    res = _mm256_srli_epi16(res, 5);
1378
1379
5.23M
    mask256 = _mm256_cmpgt_epi16(max_base_x256, base_inc256);
1380
5.23M
    res1 = _mm256_blendv_epi8(a_mbase_x, res, mask256);
1381
5.23M
    dst[r] = _mm256_castsi256_si128(res1);
1382
5.23M
    x += dx;
1383
5.23M
  }
1384
411k
}
1385
1386
static void highbd_dr_prediction_z1_8xN_avx2(int N, uint16_t *dst,
1387
                                             ptrdiff_t stride,
1388
                                             const uint16_t *above,
1389
                                             int upsample_above, int dx,
1390
225k
                                             int bd) {
1391
225k
  __m128i dstvec[32];
1392
225k
  if (bd < 12) {
1393
168k
    highbd_dr_prediction_z1_8xN_internal_avx2(N, dstvec, above, upsample_above,
1394
168k
                                              dx);
1395
168k
  } else {
1396
56.6k
    highbd_dr_prediction_32bit_z1_8xN_internal_avx2(N, dstvec, above,
1397
56.6k
                                                    upsample_above, dx);
1398
56.6k
  }
1399
2.43M
  for (int i = 0; i < N; i++) {
1400
2.20M
    _mm_storeu_si128((__m128i *)(dst + stride * i), dstvec[i]);
1401
2.20M
  }
1402
225k
}
1403
1404
static AOM_FORCE_INLINE void highbd_dr_prediction_32bit_z1_16xN_internal_avx2(
1405
84.7k
    int N, __m256i *dstvec, const uint16_t *above, int upsample_above, int dx) {
1406
  // here upsample_above is 0 by design of av1_use_intra_edge_upsample
1407
84.7k
  (void)upsample_above;
1408
84.7k
  const int frac_bits = 6;
1409
84.7k
  const int max_base_x = ((16 + N) - 1);
1410
1411
  // pre-filter above pixels
1412
  // store in temp buffers:
1413
  //   above[x] * 32 + 16
1414
  //   above[x+1] - above[x]
1415
  // final pixels will be calculated as:
1416
  //   (above[x] * 32 + 16 + (above[x+1] - above[x]) * shift) >> 5
1417
84.7k
  __m256i a0, a0_1, a1, a1_1, a32, a16;
1418
84.7k
  __m256i a_mbase_x, diff, max_base_x256, base_inc256, mask256;
1419
1420
84.7k
  a16 = _mm256_set1_epi32(16);
1421
84.7k
  a_mbase_x = _mm256_set1_epi16(above[max_base_x]);
1422
84.7k
  max_base_x256 = _mm256_set1_epi16(max_base_x);
1423
1424
84.7k
  int x = dx;
1425
1.04M
  for (int r = 0; r < N; r++) {
1426
961k
    __m256i b, res[2], res1;
1427
1428
961k
    int base = x >> frac_bits;
1429
961k
    if (base >= max_base_x) {
1430
1.38k
      for (int i = r; i < N; ++i) {
1431
1.17k
        dstvec[i] = a_mbase_x;  // save 16 values
1432
1.17k
      }
1433
218
      return;
1434
218
    }
1435
960k
    __m256i shift = _mm256_srli_epi32(
1436
960k
        _mm256_and_si256(_mm256_set1_epi32(x), _mm256_set1_epi32(0x3f)), 1);
1437
1438
960k
    a0 = _mm256_cvtepu16_epi32(_mm_loadu_si128((__m128i *)(above + base)));
1439
960k
    a1 = _mm256_cvtepu16_epi32(_mm_loadu_si128((__m128i *)(above + base + 1)));
1440
1441
960k
    diff = _mm256_sub_epi32(a1, a0);   // a[x+1] - a[x]
1442
960k
    a32 = _mm256_slli_epi32(a0, 5);    // a[x] * 32
1443
960k
    a32 = _mm256_add_epi32(a32, a16);  // a[x] * 32 + 16
1444
960k
    b = _mm256_mullo_epi32(diff, shift);
1445
1446
960k
    res[0] = _mm256_add_epi32(a32, b);
1447
960k
    res[0] = _mm256_srli_epi32(res[0], 5);
1448
960k
    res[0] = _mm256_packus_epi32(
1449
960k
        res[0], _mm256_castsi128_si256(_mm256_extracti128_si256(res[0], 1)));
1450
1451
960k
    int mdif = max_base_x - base;
1452
960k
    if (mdif > 8) {
1453
958k
      a0_1 =
1454
958k
          _mm256_cvtepu16_epi32(_mm_loadu_si128((__m128i *)(above + base + 8)));
1455
958k
      a1_1 =
1456
958k
          _mm256_cvtepu16_epi32(_mm_loadu_si128((__m128i *)(above + base + 9)));
1457
1458
958k
      diff = _mm256_sub_epi32(a1_1, a0_1);  // a[x+1] - a[x]
1459
958k
      a32 = _mm256_slli_epi32(a0_1, 5);     // a[x] * 32
1460
958k
      a32 = _mm256_add_epi32(a32, a16);     // a[x] * 32 + 16
1461
958k
      b = _mm256_mullo_epi32(diff, shift);
1462
1463
958k
      res[1] = _mm256_add_epi32(a32, b);
1464
958k
      res[1] = _mm256_srli_epi32(res[1], 5);
1465
958k
      res[1] = _mm256_packus_epi32(
1466
958k
          res[1], _mm256_castsi128_si256(_mm256_extracti128_si256(res[1], 1)));
1467
958k
    } else {
1468
2.69k
      res[1] = a_mbase_x;
1469
2.69k
    }
1470
960k
    res1 = _mm256_inserti128_si256(res[0], _mm256_castsi256_si128(res[1]),
1471
960k
                                   1);  // 16 16bit values
1472
1473
960k
    base_inc256 = _mm256_setr_epi16(base, base + 1, base + 2, base + 3,
1474
960k
                                    base + 4, base + 5, base + 6, base + 7,
1475
960k
                                    base + 8, base + 9, base + 10, base + 11,
1476
960k
                                    base + 12, base + 13, base + 14, base + 15);
1477
960k
    mask256 = _mm256_cmpgt_epi16(max_base_x256, base_inc256);
1478
960k
    dstvec[r] = _mm256_blendv_epi8(a_mbase_x, res1, mask256);
1479
960k
    x += dx;
1480
960k
  }
1481
84.7k
}
1482
1483
static AOM_FORCE_INLINE void highbd_dr_prediction_z1_16xN_internal_avx2(
1484
351k
    int N, __m256i *dstvec, const uint16_t *above, int upsample_above, int dx) {
1485
  // here upsample_above is 0 by design of av1_use_intra_edge_upsample
1486
351k
  (void)upsample_above;
1487
351k
  const int frac_bits = 6;
1488
351k
  const int max_base_x = ((16 + N) - 1);
1489
1490
  // pre-filter above pixels
1491
  // store in temp buffers:
1492
  //   above[x] * 32 + 16
1493
  //   above[x+1] - above[x]
1494
  // final pixels will be calculated as:
1495
  //   (above[x] * 32 + 16 + (above[x+1] - above[x]) * shift) >> 5
1496
351k
  __m256i a0, a1, a32, a16, c3f;
1497
351k
  __m256i a_mbase_x, diff, max_base_x256, base_inc256, mask256;
1498
1499
351k
  a16 = _mm256_set1_epi16(16);
1500
351k
  a_mbase_x = _mm256_set1_epi16(above[max_base_x]);
1501
351k
  max_base_x256 = _mm256_set1_epi16(max_base_x);
1502
351k
  c3f = _mm256_set1_epi16(0x3f);
1503
1504
351k
  int x = dx;
1505
6.79M
  for (int r = 0; r < N; r++) {
1506
6.44M
    __m256i b, res;
1507
1508
6.44M
    int base = x >> frac_bits;
1509
6.44M
    if (base >= max_base_x) {
1510
3.70k
      for (int i = r; i < N; ++i) {
1511
2.88k
        dstvec[i] = a_mbase_x;  // save 16 values
1512
2.88k
      }
1513
824
      return;
1514
824
    }
1515
6.44M
    __m256i shift =
1516
6.44M
        _mm256_srli_epi16(_mm256_and_si256(_mm256_set1_epi16(x), c3f), 1);
1517
1518
6.44M
    a0 = _mm256_loadu_si256((__m256i *)(above + base));
1519
6.44M
    a1 = _mm256_loadu_si256((__m256i *)(above + base + 1));
1520
1521
6.44M
    diff = _mm256_sub_epi16(a1, a0);   // a[x+1] - a[x]
1522
6.44M
    a32 = _mm256_slli_epi16(a0, 5);    // a[x] * 32
1523
6.44M
    a32 = _mm256_add_epi16(a32, a16);  // a[x] * 32 + 16
1524
6.44M
    b = _mm256_mullo_epi16(diff, shift);
1525
1526
6.44M
    res = _mm256_add_epi16(a32, b);
1527
6.44M
    res = _mm256_srli_epi16(res, 5);  // 16 16bit values
1528
1529
6.44M
    base_inc256 = _mm256_setr_epi16(base, base + 1, base + 2, base + 3,
1530
6.44M
                                    base + 4, base + 5, base + 6, base + 7,
1531
6.44M
                                    base + 8, base + 9, base + 10, base + 11,
1532
6.44M
                                    base + 12, base + 13, base + 14, base + 15);
1533
6.44M
    mask256 = _mm256_cmpgt_epi16(max_base_x256, base_inc256);
1534
6.44M
    dstvec[r] = _mm256_blendv_epi8(a_mbase_x, res, mask256);
1535
6.44M
    x += dx;
1536
6.44M
  }
1537
351k
}
1538
1539
static void highbd_dr_prediction_z1_16xN_avx2(int N, uint16_t *dst,
1540
                                              ptrdiff_t stride,
1541
                                              const uint16_t *above,
1542
                                              int upsample_above, int dx,
1543
201k
                                              int bd) {
1544
201k
  __m256i dstvec[64];
1545
201k
  if (bd < 12) {
1546
154k
    highbd_dr_prediction_z1_16xN_internal_avx2(N, dstvec, above, upsample_above,
1547
154k
                                               dx);
1548
154k
  } else {
1549
47.5k
    highbd_dr_prediction_32bit_z1_16xN_internal_avx2(N, dstvec, above,
1550
47.5k
                                                     upsample_above, dx);
1551
47.5k
  }
1552
3.01M
  for (int i = 0; i < N; i++) {
1553
2.80M
    _mm256_storeu_si256((__m256i *)(dst + stride * i), dstvec[i]);
1554
2.80M
  }
1555
201k
}
1556
1557
static AOM_FORCE_INLINE void highbd_dr_prediction_32bit_z1_32xN_internal_avx2(
1558
20.6k
    int N, __m256i *dstvec, const uint16_t *above, int upsample_above, int dx) {
1559
  // here upsample_above is 0 by design of av1_use_intra_edge_upsample
1560
20.6k
  (void)upsample_above;
1561
20.6k
  const int frac_bits = 6;
1562
20.6k
  const int max_base_x = ((32 + N) - 1);
1563
1564
  // pre-filter above pixels
1565
  // store in temp buffers:
1566
  //   above[x] * 32 + 16
1567
  //   above[x+1] - above[x]
1568
  // final pixels will be calculated as:
1569
  //   (above[x] * 32 + 16 + (above[x+1] - above[x]) * shift) >> 5
1570
20.6k
  __m256i a0, a0_1, a1, a1_1, a32, a16, c3f;
1571
20.6k
  __m256i a_mbase_x, diff, max_base_x256, base_inc256, mask256;
1572
1573
20.6k
  a16 = _mm256_set1_epi32(16);
1574
20.6k
  a_mbase_x = _mm256_set1_epi16(above[max_base_x]);
1575
20.6k
  max_base_x256 = _mm256_set1_epi16(max_base_x);
1576
20.6k
  c3f = _mm256_set1_epi16(0x3f);
1577
1578
20.6k
  int x = dx;
1579
491k
  for (int r = 0; r < N; r++) {
1580
470k
    __m256i b, res[2], res1;
1581
1582
470k
    int base = x >> frac_bits;
1583
470k
    if (base >= max_base_x) {
1584
0
      for (int i = r; i < N; ++i) {
1585
0
        dstvec[i] = a_mbase_x;  // save 32 values
1586
0
        dstvec[i + N] = a_mbase_x;
1587
0
      }
1588
0
      return;
1589
0
    }
1590
1591
470k
    __m256i shift =
1592
470k
        _mm256_srli_epi32(_mm256_and_si256(_mm256_set1_epi32(x), c3f), 1);
1593
1594
1.41M
    for (int j = 0; j < 32; j += 16) {
1595
940k
      int mdif = max_base_x - (base + j);
1596
940k
      if (mdif <= 0) {
1597
715
        res1 = a_mbase_x;
1598
940k
      } else {
1599
940k
        a0 = _mm256_cvtepu16_epi32(
1600
940k
            _mm_loadu_si128((__m128i *)(above + base + j)));
1601
940k
        a1 = _mm256_cvtepu16_epi32(
1602
940k
            _mm_loadu_si128((__m128i *)(above + base + 1 + j)));
1603
1604
940k
        diff = _mm256_sub_epi32(a1, a0);   // a[x+1] - a[x]
1605
940k
        a32 = _mm256_slli_epi32(a0, 5);    // a[x] * 32
1606
940k
        a32 = _mm256_add_epi32(a32, a16);  // a[x] * 32 + 16
1607
940k
        b = _mm256_mullo_epi32(diff, shift);
1608
1609
940k
        res[0] = _mm256_add_epi32(a32, b);
1610
940k
        res[0] = _mm256_srli_epi32(res[0], 5);
1611
940k
        res[0] = _mm256_packus_epi32(
1612
940k
            res[0],
1613
940k
            _mm256_castsi128_si256(_mm256_extracti128_si256(res[0], 1)));
1614
940k
        if (mdif > 8) {
1615
935k
          a0_1 = _mm256_cvtepu16_epi32(
1616
935k
              _mm_loadu_si128((__m128i *)(above + base + 8 + j)));
1617
935k
          a1_1 = _mm256_cvtepu16_epi32(
1618
935k
              _mm_loadu_si128((__m128i *)(above + base + 9 + j)));
1619
1620
935k
          diff = _mm256_sub_epi32(a1_1, a0_1);  // a[x+1] - a[x]
1621
935k
          a32 = _mm256_slli_epi32(a0_1, 5);     // a[x] * 32
1622
935k
          a32 = _mm256_add_epi32(a32, a16);     // a[x] * 32 + 16
1623
935k
          b = _mm256_mullo_epi32(diff, shift);
1624
1625
935k
          res[1] = _mm256_add_epi32(a32, b);
1626
935k
          res[1] = _mm256_srli_epi32(res[1], 5);
1627
935k
          res[1] = _mm256_packus_epi32(
1628
935k
              res[1],
1629
935k
              _mm256_castsi128_si256(_mm256_extracti128_si256(res[1], 1)));
1630
935k
        } else {
1631
4.46k
          res[1] = a_mbase_x;
1632
4.46k
        }
1633
940k
        res1 = _mm256_inserti128_si256(res[0], _mm256_castsi256_si128(res[1]),
1634
940k
                                       1);  // 16 16bit values
1635
940k
        base_inc256 = _mm256_setr_epi16(
1636
940k
            base + j, base + j + 1, base + j + 2, base + j + 3, base + j + 4,
1637
940k
            base + j + 5, base + j + 6, base + j + 7, base + j + 8,
1638
940k
            base + j + 9, base + j + 10, base + j + 11, base + j + 12,
1639
940k
            base + j + 13, base + j + 14, base + j + 15);
1640
1641
940k
        mask256 = _mm256_cmpgt_epi16(max_base_x256, base_inc256);
1642
940k
        res1 = _mm256_blendv_epi8(a_mbase_x, res1, mask256);
1643
940k
      }
1644
940k
      if (!j) {
1645
470k
        dstvec[r] = res1;
1646
470k
      } else {
1647
470k
        dstvec[r + N] = res1;
1648
470k
      }
1649
940k
    }
1650
470k
    x += dx;
1651
470k
  }
1652
20.6k
}
1653
1654
static AOM_FORCE_INLINE void highbd_dr_prediction_z1_32xN_internal_avx2(
1655
205k
    int N, __m256i *dstvec, const uint16_t *above, int upsample_above, int dx) {
1656
  // here upsample_above is 0 by design of av1_use_intra_edge_upsample
1657
205k
  (void)upsample_above;
1658
205k
  const int frac_bits = 6;
1659
205k
  const int max_base_x = ((32 + N) - 1);
1660
1661
  // pre-filter above pixels
1662
  // store in temp buffers:
1663
  //   above[x] * 32 + 16
1664
  //   above[x+1] - above[x]
1665
  // final pixels will be calculated as:
1666
  //   (above[x] * 32 + 16 + (above[x+1] - above[x]) * shift) >> 5
1667
205k
  __m256i a0, a1, a32, a16, c3f;
1668
205k
  __m256i a_mbase_x, diff, max_base_x256, base_inc256, mask256;
1669
1670
205k
  a16 = _mm256_set1_epi16(16);
1671
205k
  a_mbase_x = _mm256_set1_epi16(above[max_base_x]);
1672
205k
  max_base_x256 = _mm256_set1_epi16(max_base_x);
1673
205k
  c3f = _mm256_set1_epi16(0x3f);
1674
1675
205k
  int x = dx;
1676
5.60M
  for (int r = 0; r < N; r++) {
1677
5.39M
    __m256i b, res;
1678
1679
5.39M
    int base = x >> frac_bits;
1680
5.39M
    if (base >= max_base_x) {
1681
0
      for (int i = r; i < N; ++i) {
1682
0
        dstvec[i] = a_mbase_x;  // save 32 values
1683
0
        dstvec[i + N] = a_mbase_x;
1684
0
      }
1685
0
      return;
1686
0
    }
1687
1688
5.39M
    __m256i shift =
1689
5.39M
        _mm256_srli_epi16(_mm256_and_si256(_mm256_set1_epi16(x), c3f), 1);
1690
1691
16.1M
    for (int j = 0; j < 32; j += 16) {
1692
10.7M
      int mdif = max_base_x - (base + j);
1693
10.7M
      if (mdif <= 0) {
1694
930
        res = a_mbase_x;
1695
10.7M
      } else {
1696
10.7M
        a0 = _mm256_loadu_si256((__m256i *)(above + base + j));
1697
10.7M
        a1 = _mm256_loadu_si256((__m256i *)(above + base + 1 + j));
1698
1699
10.7M
        diff = _mm256_sub_epi16(a1, a0);   // a[x+1] - a[x]
1700
10.7M
        a32 = _mm256_slli_epi16(a0, 5);    // a[x] * 32
1701
10.7M
        a32 = _mm256_add_epi16(a32, a16);  // a[x] * 32 + 16
1702
10.7M
        b = _mm256_mullo_epi16(diff, shift);
1703
1704
10.7M
        res = _mm256_add_epi16(a32, b);
1705
10.7M
        res = _mm256_srli_epi16(res, 5);
1706
1707
10.7M
        base_inc256 = _mm256_setr_epi16(
1708
10.7M
            base + j, base + j + 1, base + j + 2, base + j + 3, base + j + 4,
1709
10.7M
            base + j + 5, base + j + 6, base + j + 7, base + j + 8,
1710
10.7M
            base + j + 9, base + j + 10, base + j + 11, base + j + 12,
1711
10.7M
            base + j + 13, base + j + 14, base + j + 15);
1712
1713
10.7M
        mask256 = _mm256_cmpgt_epi16(max_base_x256, base_inc256);
1714
10.7M
        res = _mm256_blendv_epi8(a_mbase_x, res, mask256);
1715
10.7M
      }
1716
10.7M
      if (!j) {
1717
5.39M
        dstvec[r] = res;
1718
5.39M
      } else {
1719
5.39M
        dstvec[r + N] = res;
1720
5.39M
      }
1721
10.7M
    }
1722
5.39M
    x += dx;
1723
5.39M
  }
1724
205k
}
1725
1726
static void highbd_dr_prediction_z1_32xN_avx2(int N, uint16_t *dst,
1727
                                              ptrdiff_t stride,
1728
                                              const uint16_t *above,
1729
                                              int upsample_above, int dx,
1730
93.1k
                                              int bd) {
1731
93.1k
  __m256i dstvec[128];
1732
93.1k
  if (bd < 12) {
1733
82.7k
    highbd_dr_prediction_z1_32xN_internal_avx2(N, dstvec, above, upsample_above,
1734
82.7k
                                               dx);
1735
82.7k
  } else {
1736
10.3k
    highbd_dr_prediction_32bit_z1_32xN_internal_avx2(N, dstvec, above,
1737
10.3k
                                                     upsample_above, dx);
1738
10.3k
  }
1739
2.53M
  for (int i = 0; i < N; i++) {
1740
2.43M
    _mm256_storeu_si256((__m256i *)(dst + stride * i), dstvec[i]);
1741
2.43M
    _mm256_storeu_si256((__m256i *)(dst + stride * i + 16), dstvec[i + N]);
1742
2.43M
  }
1743
93.1k
}
1744
1745
static void highbd_dr_prediction_32bit_z1_64xN_avx2(int N, uint16_t *dst,
1746
                                                    ptrdiff_t stride,
1747
                                                    const uint16_t *above,
1748
                                                    int upsample_above,
1749
15.5k
                                                    int dx) {
1750
  // here upsample_above is 0 by design of av1_use_intra_edge_upsample
1751
15.5k
  (void)upsample_above;
1752
15.5k
  const int frac_bits = 6;
1753
15.5k
  const int max_base_x = ((64 + N) - 1);
1754
1755
  // pre-filter above pixels
1756
  // store in temp buffers:
1757
  //   above[x] * 32 + 16
1758
  //   above[x+1] - above[x]
1759
  // final pixels will be calculated as:
1760
  //   (above[x] * 32 + 16 + (above[x+1] - above[x]) * shift) >> 5
1761
15.5k
  __m256i a0, a0_1, a1, a1_1, a32, a16;
1762
15.5k
  __m256i a_mbase_x, diff, max_base_x256, base_inc256, mask256;
1763
1764
15.5k
  a16 = _mm256_set1_epi32(16);
1765
15.5k
  a_mbase_x = _mm256_set1_epi16(above[max_base_x]);
1766
15.5k
  max_base_x256 = _mm256_set1_epi16(max_base_x);
1767
1768
15.5k
  int x = dx;
1769
929k
  for (int r = 0; r < N; r++, dst += stride) {
1770
914k
    __m256i b, res[2], res1;
1771
1772
914k
    int base = x >> frac_bits;
1773
914k
    if (base >= max_base_x) {
1774
0
      for (int i = r; i < N; ++i) {
1775
0
        _mm256_storeu_si256((__m256i *)dst, a_mbase_x);  // save 32 values
1776
0
        _mm256_storeu_si256((__m256i *)(dst + 16), a_mbase_x);
1777
0
        _mm256_storeu_si256((__m256i *)(dst + 32), a_mbase_x);
1778
0
        _mm256_storeu_si256((__m256i *)(dst + 48), a_mbase_x);
1779
0
        dst += stride;
1780
0
      }
1781
0
      return;
1782
0
    }
1783
1784
914k
    __m256i shift = _mm256_srli_epi32(
1785
914k
        _mm256_and_si256(_mm256_set1_epi32(x), _mm256_set1_epi32(0x3f)), 1);
1786
1787
914k
    __m128i a0_128, a0_1_128, a1_128, a1_1_128;
1788
4.57M
    for (int j = 0; j < 64; j += 16) {
1789
3.65M
      int mdif = max_base_x - (base + j);
1790
3.65M
      if (mdif <= 0) {
1791
3.76k
        _mm256_storeu_si256((__m256i *)(dst + j), a_mbase_x);
1792
3.65M
      } else {
1793
3.65M
        a0_128 = _mm_loadu_si128((__m128i *)(above + base + j));
1794
3.65M
        a1_128 = _mm_loadu_si128((__m128i *)(above + base + 1 + j));
1795
3.65M
        a0 = _mm256_cvtepu16_epi32(a0_128);
1796
3.65M
        a1 = _mm256_cvtepu16_epi32(a1_128);
1797
1798
3.65M
        diff = _mm256_sub_epi32(a1, a0);   // a[x+1] - a[x]
1799
3.65M
        a32 = _mm256_slli_epi32(a0, 5);    // a[x] * 32
1800
3.65M
        a32 = _mm256_add_epi32(a32, a16);  // a[x] * 32 + 16
1801
3.65M
        b = _mm256_mullo_epi32(diff, shift);
1802
1803
3.65M
        res[0] = _mm256_add_epi32(a32, b);
1804
3.65M
        res[0] = _mm256_srli_epi32(res[0], 5);
1805
3.65M
        res[0] = _mm256_packus_epi32(
1806
3.65M
            res[0],
1807
3.65M
            _mm256_castsi128_si256(_mm256_extracti128_si256(res[0], 1)));
1808
3.65M
        if (mdif > 8) {
1809
3.64M
          a0_1_128 = _mm_loadu_si128((__m128i *)(above + base + 8 + j));
1810
3.64M
          a1_1_128 = _mm_loadu_si128((__m128i *)(above + base + 9 + j));
1811
3.64M
          a0_1 = _mm256_cvtepu16_epi32(a0_1_128);
1812
3.64M
          a1_1 = _mm256_cvtepu16_epi32(a1_1_128);
1813
1814
3.64M
          diff = _mm256_sub_epi32(a1_1, a0_1);  // a[x+1] - a[x]
1815
3.64M
          a32 = _mm256_slli_epi32(a0_1, 5);     // a[x] * 32
1816
3.64M
          a32 = _mm256_add_epi32(a32, a16);     // a[x] * 32 + 16
1817
3.64M
          b = _mm256_mullo_epi32(diff, shift);
1818
1819
3.64M
          res[1] = _mm256_add_epi32(a32, b);
1820
3.64M
          res[1] = _mm256_srli_epi32(res[1], 5);
1821
3.64M
          res[1] = _mm256_packus_epi32(
1822
3.64M
              res[1],
1823
3.64M
              _mm256_castsi128_si256(_mm256_extracti128_si256(res[1], 1)));
1824
3.64M
        } else {
1825
6.71k
          res[1] = a_mbase_x;
1826
6.71k
        }
1827
3.65M
        res1 = _mm256_inserti128_si256(res[0], _mm256_castsi256_si128(res[1]),
1828
3.65M
                                       1);  // 16 16bit values
1829
3.65M
        base_inc256 = _mm256_setr_epi16(
1830
3.65M
            base + j, base + j + 1, base + j + 2, base + j + 3, base + j + 4,
1831
3.65M
            base + j + 5, base + j + 6, base + j + 7, base + j + 8,
1832
3.65M
            base + j + 9, base + j + 10, base + j + 11, base + j + 12,
1833
3.65M
            base + j + 13, base + j + 14, base + j + 15);
1834
1835
3.65M
        mask256 = _mm256_cmpgt_epi16(max_base_x256, base_inc256);
1836
3.65M
        res1 = _mm256_blendv_epi8(a_mbase_x, res1, mask256);
1837
3.65M
        _mm256_storeu_si256((__m256i *)(dst + j), res1);
1838
3.65M
      }
1839
3.65M
    }
1840
914k
    x += dx;
1841
914k
  }
1842
15.5k
}
1843
1844
static void highbd_dr_prediction_z1_64xN_avx2(int N, uint16_t *dst,
1845
                                              ptrdiff_t stride,
1846
                                              const uint16_t *above,
1847
42.4k
                                              int upsample_above, int dx) {
1848
  // here upsample_above is 0 by design of av1_use_intra_edge_upsample
1849
42.4k
  (void)upsample_above;
1850
42.4k
  const int frac_bits = 6;
1851
42.4k
  const int max_base_x = ((64 + N) - 1);
1852
1853
  // pre-filter above pixels
1854
  // store in temp buffers:
1855
  //   above[x] * 32 + 16
1856
  //   above[x+1] - above[x]
1857
  // final pixels will be calculated as:
1858
  //   (above[x] * 32 + 16 + (above[x+1] - above[x]) * shift) >> 5
1859
42.4k
  __m256i a0, a1, a32, a16, c3f;
1860
42.4k
  __m256i a_mbase_x, diff, max_base_x256, base_inc256, mask256;
1861
1862
42.4k
  a16 = _mm256_set1_epi16(16);
1863
42.4k
  a_mbase_x = _mm256_set1_epi16(above[max_base_x]);
1864
42.4k
  max_base_x256 = _mm256_set1_epi16(max_base_x);
1865
42.4k
  c3f = _mm256_set1_epi16(0x3f);
1866
1867
42.4k
  int x = dx;
1868
2.16M
  for (int r = 0; r < N; r++, dst += stride) {
1869
2.12M
    __m256i b, res;
1870
1871
2.12M
    int base = x >> frac_bits;
1872
2.12M
    if (base >= max_base_x) {
1873
0
      for (int i = r; i < N; ++i) {
1874
0
        _mm256_storeu_si256((__m256i *)dst, a_mbase_x);  // save 32 values
1875
0
        _mm256_storeu_si256((__m256i *)(dst + 16), a_mbase_x);
1876
0
        _mm256_storeu_si256((__m256i *)(dst + 32), a_mbase_x);
1877
0
        _mm256_storeu_si256((__m256i *)(dst + 48), a_mbase_x);
1878
0
        dst += stride;
1879
0
      }
1880
0
      return;
1881
0
    }
1882
1883
2.12M
    __m256i shift =
1884
2.12M
        _mm256_srli_epi16(_mm256_and_si256(_mm256_set1_epi16(x), c3f), 1);
1885
1886
10.6M
    for (int j = 0; j < 64; j += 16) {
1887
8.50M
      int mdif = max_base_x - (base + j);
1888
8.50M
      if (mdif <= 0) {
1889
3.55k
        _mm256_storeu_si256((__m256i *)(dst + j), a_mbase_x);
1890
8.49M
      } else {
1891
8.49M
        a0 = _mm256_loadu_si256((__m256i *)(above + base + j));
1892
8.49M
        a1 = _mm256_loadu_si256((__m256i *)(above + base + 1 + j));
1893
1894
8.49M
        diff = _mm256_sub_epi16(a1, a0);   // a[x+1] - a[x]
1895
8.49M
        a32 = _mm256_slli_epi16(a0, 5);    // a[x] * 32
1896
8.49M
        a32 = _mm256_add_epi16(a32, a16);  // a[x] * 32 + 16
1897
8.49M
        b = _mm256_mullo_epi16(diff, shift);
1898
1899
8.49M
        res = _mm256_add_epi16(a32, b);
1900
8.49M
        res = _mm256_srli_epi16(res, 5);
1901
1902
8.49M
        base_inc256 = _mm256_setr_epi16(
1903
8.49M
            base + j, base + j + 1, base + j + 2, base + j + 3, base + j + 4,
1904
8.49M
            base + j + 5, base + j + 6, base + j + 7, base + j + 8,
1905
8.49M
            base + j + 9, base + j + 10, base + j + 11, base + j + 12,
1906
8.49M
            base + j + 13, base + j + 14, base + j + 15);
1907
1908
8.49M
        mask256 = _mm256_cmpgt_epi16(max_base_x256, base_inc256);
1909
8.49M
        res = _mm256_blendv_epi8(a_mbase_x, res, mask256);
1910
8.49M
        _mm256_storeu_si256((__m256i *)(dst + j), res);  // 16 16bit values
1911
8.49M
      }
1912
8.50M
    }
1913
2.12M
    x += dx;
1914
2.12M
  }
1915
42.4k
}
1916
1917
// Directional prediction, zone 1: 0 < angle < 90
1918
void av1_highbd_dr_prediction_z1_avx2(uint16_t *dst, ptrdiff_t stride, int bw,
1919
                                      int bh, const uint16_t *above,
1920
                                      const uint16_t *left, int upsample_above,
1921
730k
                                      int dx, int dy, int bd) {
1922
730k
  (void)left;
1923
730k
  (void)dy;
1924
1925
730k
  switch (bw) {
1926
190k
    case 4:
1927
190k
      highbd_dr_prediction_z1_4xN_avx2(bh, dst, stride, above, upsample_above,
1928
190k
                                       dx, bd);
1929
190k
      break;
1930
225k
    case 8:
1931
225k
      highbd_dr_prediction_z1_8xN_avx2(bh, dst, stride, above, upsample_above,
1932
225k
                                       dx, bd);
1933
225k
      break;
1934
201k
    case 16:
1935
201k
      highbd_dr_prediction_z1_16xN_avx2(bh, dst, stride, above, upsample_above,
1936
201k
                                        dx, bd);
1937
201k
      break;
1938
89.4k
    case 32:
1939
89.4k
      highbd_dr_prediction_z1_32xN_avx2(bh, dst, stride, above, upsample_above,
1940
89.4k
                                        dx, bd);
1941
89.4k
      break;
1942
23.7k
    case 64:
1943
23.7k
      if (bd < 12) {
1944
12.6k
        highbd_dr_prediction_z1_64xN_avx2(bh, dst, stride, above,
1945
12.6k
                                          upsample_above, dx);
1946
12.6k
      } else {
1947
11.1k
        highbd_dr_prediction_32bit_z1_64xN_avx2(bh, dst, stride, above,
1948
11.1k
                                                upsample_above, dx);
1949
11.1k
      }
1950
23.7k
      break;
1951
0
    default: break;
1952
730k
  }
1953
730k
  return;
1954
730k
}
1955
1956
static void highbd_transpose_TX_16X16(const uint16_t *src, ptrdiff_t pitchSrc,
1957
484k
                                      uint16_t *dst, ptrdiff_t pitchDst) {
1958
484k
  __m256i r[16];
1959
484k
  __m256i d[16];
1960
8.24M
  for (int j = 0; j < 16; j++) {
1961
7.75M
    r[j] = _mm256_loadu_si256((__m256i *)(src + j * pitchSrc));
1962
7.75M
  }
1963
484k
  highbd_transpose16x16_avx2(r, d);
1964
8.24M
  for (int j = 0; j < 16; j++) {
1965
7.75M
    _mm256_storeu_si256((__m256i *)(dst + j * pitchDst), d[j]);
1966
7.75M
  }
1967
484k
}
1968
1969
static void highbd_transpose(const uint16_t *src, ptrdiff_t pitchSrc,
1970
                             uint16_t *dst, ptrdiff_t pitchDst, int width,
1971
37.8k
                             int height) {
1972
181k
  for (int j = 0; j < height; j += 16)
1973
628k
    for (int i = 0; i < width; i += 16)
1974
484k
      highbd_transpose_TX_16X16(src + i * pitchSrc + j, pitchSrc,
1975
484k
                                dst + j * pitchDst + i, pitchDst);
1976
37.8k
}
1977
1978
static void highbd_dr_prediction_32bit_z2_Nx4_avx2(
1979
    int N, uint16_t *dst, ptrdiff_t stride, const uint16_t *above,
1980
    const uint16_t *left, int upsample_above, int upsample_left, int dx,
1981
98.8k
    int dy) {
1982
98.8k
  const int min_base_x = -(1 << upsample_above);
1983
98.8k
  const int min_base_y = -(1 << upsample_left);
1984
98.8k
  const int frac_bits_x = 6 - upsample_above;
1985
98.8k
  const int frac_bits_y = 6 - upsample_left;
1986
1987
98.8k
  assert(dx > 0);
1988
  // pre-filter above pixels
1989
  // store in temp buffers:
1990
  //   above[x] * 32 + 16
1991
  //   above[x+1] - above[x]
1992
  // final pixels will be calculated as:
1993
  //   (above[x] * 32 + 16 + (above[x+1] - above[x]) * shift) >> 5
1994
98.8k
  __m256i a0_x, a1_x, a32, a16;
1995
98.8k
  __m256i diff;
1996
98.8k
  __m128i c3f, min_base_y128;
1997
1998
98.8k
  a16 = _mm256_set1_epi32(16);
1999
98.8k
  c3f = _mm_set1_epi32(0x3f);
2000
98.8k
  min_base_y128 = _mm_set1_epi32(min_base_y);
2001
2002
670k
  for (int r = 0; r < N; r++) {
2003
572k
    __m256i b, res, shift;
2004
572k
    __m128i resx, resy, resxy;
2005
572k
    __m128i a0_x128, a1_x128;
2006
572k
    int y = r + 1;
2007
572k
    int base_x = (-y * dx) >> frac_bits_x;
2008
572k
    int base_shift = 0;
2009
572k
    if (base_x < (min_base_x - 1)) {
2010
423k
      base_shift = (min_base_x - base_x - 1) >> upsample_above;
2011
423k
    }
2012
572k
    int base_min_diff =
2013
572k
        (min_base_x - base_x + upsample_above) >> upsample_above;
2014
572k
    if (base_min_diff > 4) {
2015
328k
      base_min_diff = 4;
2016
328k
    } else {
2017
243k
      if (base_min_diff < 0) base_min_diff = 0;
2018
243k
    }
2019
2020
572k
    if (base_shift > 3) {
2021
328k
      a0_x = _mm256_setzero_si256();
2022
328k
      a1_x = _mm256_setzero_si256();
2023
328k
      shift = _mm256_setzero_si256();
2024
328k
    } else {
2025
243k
      a0_x128 = _mm_loadu_si128((__m128i *)(above + base_x + base_shift));
2026
243k
      if (upsample_above) {
2027
76.3k
        a0_x128 = _mm_shuffle_epi8(a0_x128,
2028
76.3k
                                   *(__m128i *)HighbdEvenOddMaskx4[base_shift]);
2029
76.3k
        a1_x128 = _mm_srli_si128(a0_x128, 8);
2030
2031
76.3k
        shift = _mm256_castsi128_si256(_mm_srli_epi32(
2032
76.3k
            _mm_and_si128(
2033
76.3k
                _mm_slli_epi32(
2034
76.3k
                    _mm_setr_epi32(-y * dx, (1 << 6) - y * dx,
2035
76.3k
                                   (2 << 6) - y * dx, (3 << 6) - y * dx),
2036
76.3k
                    upsample_above),
2037
76.3k
                c3f),
2038
76.3k
            1));
2039
166k
      } else {
2040
166k
        a0_x128 =
2041
166k
            _mm_shuffle_epi8(a0_x128, *(__m128i *)HighbdLoadMaskx[base_shift]);
2042
166k
        a1_x128 = _mm_srli_si128(a0_x128, 2);
2043
2044
166k
        shift = _mm256_castsi128_si256(_mm_srli_epi32(
2045
166k
            _mm_and_si128(_mm_setr_epi32(-y * dx, (1 << 6) - y * dx,
2046
166k
                                         (2 << 6) - y * dx, (3 << 6) - y * dx),
2047
166k
                          c3f),
2048
166k
            1));
2049
166k
      }
2050
243k
      a0_x = _mm256_cvtepu16_epi32(a0_x128);
2051
243k
      a1_x = _mm256_cvtepu16_epi32(a1_x128);
2052
243k
    }
2053
    // y calc
2054
572k
    __m128i a0_y, a1_y, shifty;
2055
572k
    if (base_x < min_base_x) {
2056
466k
      __m128i r6, c1234, dy128, y_c128, base_y_c128, mask128;
2057
466k
      DECLARE_ALIGNED(32, int, base_y_c[4]);
2058
466k
      r6 = _mm_set1_epi32(r << 6);
2059
466k
      dy128 = _mm_set1_epi32(dy);
2060
466k
      c1234 = _mm_setr_epi32(1, 2, 3, 4);
2061
466k
      y_c128 = _mm_sub_epi32(r6, _mm_mullo_epi32(c1234, dy128));
2062
466k
      base_y_c128 = _mm_srai_epi32(y_c128, frac_bits_y);
2063
466k
      mask128 = _mm_cmpgt_epi32(min_base_y128, base_y_c128);
2064
466k
      base_y_c128 = _mm_andnot_si128(mask128, base_y_c128);
2065
466k
      _mm_store_si128((__m128i *)base_y_c, base_y_c128);
2066
2067
466k
      a0_y = _mm_setr_epi32(left[base_y_c[0]], left[base_y_c[1]],
2068
466k
                            left[base_y_c[2]], left[base_y_c[3]]);
2069
466k
      a1_y = _mm_setr_epi32(left[base_y_c[0] + 1], left[base_y_c[1] + 1],
2070
466k
                            left[base_y_c[2] + 1], left[base_y_c[3] + 1]);
2071
2072
466k
      if (upsample_left) {
2073
84.9k
        shifty = _mm_srli_epi32(
2074
84.9k
            _mm_and_si128(_mm_slli_epi32(y_c128, upsample_left), c3f), 1);
2075
381k
      } else {
2076
381k
        shifty = _mm_srli_epi32(_mm_and_si128(y_c128, c3f), 1);
2077
381k
      }
2078
466k
      a0_x = _mm256_inserti128_si256(a0_x, a0_y, 1);
2079
466k
      a1_x = _mm256_inserti128_si256(a1_x, a1_y, 1);
2080
466k
      shift = _mm256_inserti128_si256(shift, shifty, 1);
2081
466k
    }
2082
2083
572k
    diff = _mm256_sub_epi32(a1_x, a0_x);  // a[x+1] - a[x]
2084
572k
    a32 = _mm256_slli_epi32(a0_x, 5);     // a[x] * 32
2085
572k
    a32 = _mm256_add_epi32(a32, a16);     // a[x] * 32 + 16
2086
2087
572k
    b = _mm256_mullo_epi32(diff, shift);
2088
572k
    res = _mm256_add_epi32(a32, b);
2089
572k
    res = _mm256_srli_epi32(res, 5);
2090
2091
572k
    resx = _mm256_castsi256_si128(res);
2092
572k
    resx = _mm_packus_epi32(resx, resx);
2093
2094
572k
    resy = _mm256_extracti128_si256(res, 1);
2095
572k
    resy = _mm_packus_epi32(resy, resy);
2096
2097
572k
    resxy =
2098
572k
        _mm_blendv_epi8(resx, resy, *(__m128i *)HighbdBaseMask[base_min_diff]);
2099
572k
    _mm_storel_epi64((__m128i *)(dst), resxy);
2100
572k
    dst += stride;
2101
572k
  }
2102
98.8k
}
2103
2104
static void highbd_dr_prediction_z2_Nx4_avx2(
2105
    int N, uint16_t *dst, ptrdiff_t stride, const uint16_t *above,
2106
    const uint16_t *left, int upsample_above, int upsample_left, int dx,
2107
178k
    int dy) {
2108
178k
  const int min_base_x = -(1 << upsample_above);
2109
178k
  const int min_base_y = -(1 << upsample_left);
2110
178k
  const int frac_bits_x = 6 - upsample_above;
2111
178k
  const int frac_bits_y = 6 - upsample_left;
2112
2113
178k
  assert(dx > 0);
2114
  // pre-filter above pixels
2115
  // store in temp buffers:
2116
  //   above[x] * 32 + 16
2117
  //   above[x+1] - above[x]
2118
  // final pixels will be calculated as:
2119
  //   (above[x] * 32 + 16 + (above[x+1] - above[x]) * shift) >> 5
2120
178k
  __m256i a0_x, a1_x, a32, a16;
2121
178k
  __m256i diff;
2122
178k
  __m128i c3f, min_base_y128;
2123
2124
178k
  a16 = _mm256_set1_epi16(16);
2125
178k
  c3f = _mm_set1_epi16(0x3f);
2126
178k
  min_base_y128 = _mm_set1_epi16(min_base_y);
2127
2128
1.39M
  for (int r = 0; r < N; r++) {
2129
1.21M
    __m256i b, res, shift;
2130
1.21M
    __m128i resx, resy, resxy;
2131
1.21M
    __m128i a0_x128, a1_x128;
2132
1.21M
    int y = r + 1;
2133
1.21M
    int base_x = (-y * dx) >> frac_bits_x;
2134
1.21M
    int base_shift = 0;
2135
1.21M
    if (base_x < (min_base_x - 1)) {
2136
867k
      base_shift = (min_base_x - base_x - 1) >> upsample_above;
2137
867k
    }
2138
1.21M
    int base_min_diff =
2139
1.21M
        (min_base_x - base_x + upsample_above) >> upsample_above;
2140
1.21M
    if (base_min_diff > 4) {
2141
560k
      base_min_diff = 4;
2142
658k
    } else {
2143
658k
      if (base_min_diff < 0) base_min_diff = 0;
2144
658k
    }
2145
2146
1.21M
    if (base_shift > 3) {
2147
560k
      a0_x = _mm256_setzero_si256();
2148
560k
      a1_x = _mm256_setzero_si256();
2149
560k
      shift = _mm256_setzero_si256();
2150
658k
    } else {
2151
658k
      a0_x128 = _mm_loadu_si128((__m128i *)(above + base_x + base_shift));
2152
658k
      if (upsample_above) {
2153
233k
        a0_x128 = _mm_shuffle_epi8(a0_x128,
2154
233k
                                   *(__m128i *)HighbdEvenOddMaskx4[base_shift]);
2155
233k
        a1_x128 = _mm_srli_si128(a0_x128, 8);
2156
2157
233k
        shift = _mm256_castsi128_si256(_mm_srli_epi16(
2158
233k
            _mm_and_si128(
2159
233k
                _mm_slli_epi16(_mm_setr_epi16(-y * dx, (1 << 6) - y * dx,
2160
233k
                                              (2 << 6) - y * dx,
2161
233k
                                              (3 << 6) - y * dx, 0, 0, 0, 0),
2162
233k
                               upsample_above),
2163
233k
                c3f),
2164
233k
            1));
2165
424k
      } else {
2166
424k
        a0_x128 =
2167
424k
            _mm_shuffle_epi8(a0_x128, *(__m128i *)HighbdLoadMaskx[base_shift]);
2168
424k
        a1_x128 = _mm_srli_si128(a0_x128, 2);
2169
2170
424k
        shift = _mm256_castsi128_si256(_mm_srli_epi16(
2171
424k
            _mm_and_si128(
2172
424k
                _mm_setr_epi16(-y * dx, (1 << 6) - y * dx, (2 << 6) - y * dx,
2173
424k
                               (3 << 6) - y * dx, 0, 0, 0, 0),
2174
424k
                c3f),
2175
424k
            1));
2176
424k
      }
2177
658k
      a0_x = _mm256_castsi128_si256(a0_x128);
2178
658k
      a1_x = _mm256_castsi128_si256(a1_x128);
2179
658k
    }
2180
    // y calc
2181
1.21M
    __m128i a0_y, a1_y, shifty;
2182
1.21M
    if (base_x < min_base_x) {
2183
998k
      __m128i r6, c1234, dy128, y_c128, base_y_c128, mask128;
2184
998k
      DECLARE_ALIGNED(32, int16_t, base_y_c[8]);
2185
998k
      r6 = _mm_set1_epi16(r << 6);
2186
998k
      dy128 = _mm_set1_epi16(dy);
2187
998k
      c1234 = _mm_setr_epi16(1, 2, 3, 4, 0, 0, 0, 0);
2188
998k
      y_c128 = _mm_sub_epi16(r6, _mm_mullo_epi16(c1234, dy128));
2189
998k
      base_y_c128 = _mm_srai_epi16(y_c128, frac_bits_y);
2190
998k
      mask128 = _mm_cmpgt_epi16(min_base_y128, base_y_c128);
2191
998k
      base_y_c128 = _mm_andnot_si128(mask128, base_y_c128);
2192
998k
      _mm_store_si128((__m128i *)base_y_c, base_y_c128);
2193
2194
998k
      a0_y = _mm_setr_epi16(left[base_y_c[0]], left[base_y_c[1]],
2195
998k
                            left[base_y_c[2]], left[base_y_c[3]], 0, 0, 0, 0);
2196
998k
      a1_y = _mm_setr_epi16(left[base_y_c[0] + 1], left[base_y_c[1] + 1],
2197
998k
                            left[base_y_c[2] + 1], left[base_y_c[3] + 1], 0, 0,
2198
998k
                            0, 0);
2199
2200
998k
      if (upsample_left) {
2201
291k
        shifty = _mm_srli_epi16(
2202
291k
            _mm_and_si128(_mm_slli_epi16(y_c128, upsample_left), c3f), 1);
2203
707k
      } else {
2204
707k
        shifty = _mm_srli_epi16(_mm_and_si128(y_c128, c3f), 1);
2205
707k
      }
2206
998k
      a0_x = _mm256_inserti128_si256(a0_x, a0_y, 1);
2207
998k
      a1_x = _mm256_inserti128_si256(a1_x, a1_y, 1);
2208
998k
      shift = _mm256_inserti128_si256(shift, shifty, 1);
2209
998k
    }
2210
2211
1.21M
    diff = _mm256_sub_epi16(a1_x, a0_x);  // a[x+1] - a[x]
2212
1.21M
    a32 = _mm256_slli_epi16(a0_x, 5);     // a[x] * 32
2213
1.21M
    a32 = _mm256_add_epi16(a32, a16);     // a[x] * 32 + 16
2214
2215
1.21M
    b = _mm256_mullo_epi16(diff, shift);
2216
1.21M
    res = _mm256_add_epi16(a32, b);
2217
1.21M
    res = _mm256_srli_epi16(res, 5);
2218
2219
1.21M
    resx = _mm256_castsi256_si128(res);
2220
1.21M
    resy = _mm256_extracti128_si256(res, 1);
2221
1.21M
    resxy =
2222
1.21M
        _mm_blendv_epi8(resx, resy, *(__m128i *)HighbdBaseMask[base_min_diff]);
2223
1.21M
    _mm_storel_epi64((__m128i *)(dst), resxy);
2224
1.21M
    dst += stride;
2225
1.21M
  }
2226
178k
}
2227
2228
static void highbd_dr_prediction_32bit_z2_Nx8_avx2(
2229
    int N, uint16_t *dst, ptrdiff_t stride, const uint16_t *above,
2230
    const uint16_t *left, int upsample_above, int upsample_left, int dx,
2231
89.2k
    int dy) {
2232
89.2k
  const int min_base_x = -(1 << upsample_above);
2233
89.2k
  const int min_base_y = -(1 << upsample_left);
2234
89.2k
  const int frac_bits_x = 6 - upsample_above;
2235
89.2k
  const int frac_bits_y = 6 - upsample_left;
2236
2237
  // pre-filter above pixels
2238
  // store in temp buffers:
2239
  //   above[x] * 32 + 16
2240
  //   above[x+1] - above[x]
2241
  // final pixels will be calculated as:
2242
  //   (above[x] * 32 + 16 + (above[x+1] - above[x]) * shift) >> 5
2243
89.2k
  __m256i a0_x, a1_x, a0_y, a1_y, a32, a16, c3f, min_base_y256;
2244
89.2k
  __m256i diff;
2245
89.2k
  __m128i a0_x128, a1_x128;
2246
2247
89.2k
  a16 = _mm256_set1_epi32(16);
2248
89.2k
  c3f = _mm256_set1_epi32(0x3f);
2249
89.2k
  min_base_y256 = _mm256_set1_epi32(min_base_y);
2250
2251
969k
  for (int r = 0; r < N; r++) {
2252
880k
    __m256i b, res, shift;
2253
880k
    __m128i resx, resy, resxy;
2254
880k
    int y = r + 1;
2255
880k
    int base_x = (-y * dx) >> frac_bits_x;
2256
880k
    int base_shift = 0;
2257
880k
    if (base_x < (min_base_x - 1)) {
2258
678k
      base_shift = (min_base_x - base_x - 1) >> upsample_above;
2259
678k
    }
2260
880k
    int base_min_diff =
2261
880k
        (min_base_x - base_x + upsample_above) >> upsample_above;
2262
880k
    if (base_min_diff > 8) {
2263
417k
      base_min_diff = 8;
2264
462k
    } else {
2265
462k
      if (base_min_diff < 0) base_min_diff = 0;
2266
462k
    }
2267
2268
880k
    if (base_shift > 7) {
2269
417k
      resx = _mm_setzero_si128();
2270
462k
    } else {
2271
462k
      a0_x128 = _mm_loadu_si128((__m128i *)(above + base_x + base_shift));
2272
462k
      if (upsample_above) {
2273
64.4k
        __m128i mask, atmp0, atmp1, atmp2, atmp3;
2274
64.4k
        a1_x128 = _mm_loadu_si128((__m128i *)(above + base_x + 8 + base_shift));
2275
64.4k
        atmp0 = _mm_shuffle_epi8(a0_x128,
2276
64.4k
                                 *(__m128i *)HighbdEvenOddMaskx[base_shift]);
2277
64.4k
        atmp1 = _mm_shuffle_epi8(a1_x128,
2278
64.4k
                                 *(__m128i *)HighbdEvenOddMaskx[base_shift]);
2279
64.4k
        atmp2 = _mm_shuffle_epi8(
2280
64.4k
            a0_x128, *(__m128i *)(HighbdEvenOddMaskx[base_shift] + 16));
2281
64.4k
        atmp3 = _mm_shuffle_epi8(
2282
64.4k
            a1_x128, *(__m128i *)(HighbdEvenOddMaskx[base_shift] + 16));
2283
64.4k
        mask = _mm_cmpgt_epi8(*(__m128i *)HighbdEvenOddMaskx[base_shift],
2284
64.4k
                              _mm_set1_epi8(15));
2285
64.4k
        a0_x128 = _mm_blendv_epi8(atmp0, atmp1, mask);
2286
64.4k
        mask = _mm_cmpgt_epi8(*(__m128i *)(HighbdEvenOddMaskx[base_shift] + 16),
2287
64.4k
                              _mm_set1_epi8(15));
2288
64.4k
        a1_x128 = _mm_blendv_epi8(atmp2, atmp3, mask);
2289
64.4k
        shift = _mm256_srli_epi32(
2290
64.4k
            _mm256_and_si256(
2291
64.4k
                _mm256_slli_epi32(
2292
64.4k
                    _mm256_setr_epi32(-y * dx, (1 << 6) - y * dx,
2293
64.4k
                                      (2 << 6) - y * dx, (3 << 6) - y * dx,
2294
64.4k
                                      (4 << 6) - y * dx, (5 << 6) - y * dx,
2295
64.4k
                                      (6 << 6) - y * dx, (7 << 6) - y * dx),
2296
64.4k
                    upsample_above),
2297
64.4k
                c3f),
2298
64.4k
            1);
2299
398k
      } else {
2300
398k
        a1_x128 = _mm_loadu_si128((__m128i *)(above + base_x + 1 + base_shift));
2301
398k
        a0_x128 =
2302
398k
            _mm_shuffle_epi8(a0_x128, *(__m128i *)HighbdLoadMaskx[base_shift]);
2303
398k
        a1_x128 =
2304
398k
            _mm_shuffle_epi8(a1_x128, *(__m128i *)HighbdLoadMaskx[base_shift]);
2305
2306
398k
        shift = _mm256_srli_epi32(
2307
398k
            _mm256_and_si256(
2308
398k
                _mm256_setr_epi32(-y * dx, (1 << 6) - y * dx, (2 << 6) - y * dx,
2309
398k
                                  (3 << 6) - y * dx, (4 << 6) - y * dx,
2310
398k
                                  (5 << 6) - y * dx, (6 << 6) - y * dx,
2311
398k
                                  (7 << 6) - y * dx),
2312
398k
                c3f),
2313
398k
            1);
2314
398k
      }
2315
462k
      a0_x = _mm256_cvtepu16_epi32(a0_x128);
2316
462k
      a1_x = _mm256_cvtepu16_epi32(a1_x128);
2317
2318
462k
      diff = _mm256_sub_epi32(a1_x, a0_x);  // a[x+1] - a[x]
2319
462k
      a32 = _mm256_slli_epi32(a0_x, 5);     // a[x] * 32
2320
462k
      a32 = _mm256_add_epi32(a32, a16);     // a[x] * 32 + 16
2321
2322
462k
      b = _mm256_mullo_epi32(diff, shift);
2323
462k
      res = _mm256_add_epi32(a32, b);
2324
462k
      res = _mm256_srli_epi32(res, 5);
2325
2326
462k
      resx = _mm256_castsi256_si128(_mm256_packus_epi32(
2327
462k
          res, _mm256_castsi128_si256(_mm256_extracti128_si256(res, 1))));
2328
462k
    }
2329
    // y calc
2330
880k
    if (base_x < min_base_x) {
2331
751k
      DECLARE_ALIGNED(32, int, base_y_c[8]);
2332
751k
      __m256i r6, c256, dy256, y_c256, base_y_c256, mask256;
2333
751k
      r6 = _mm256_set1_epi32(r << 6);
2334
751k
      dy256 = _mm256_set1_epi32(dy);
2335
751k
      c256 = _mm256_setr_epi32(1, 2, 3, 4, 5, 6, 7, 8);
2336
751k
      y_c256 = _mm256_sub_epi32(r6, _mm256_mullo_epi32(c256, dy256));
2337
751k
      base_y_c256 = _mm256_srai_epi32(y_c256, frac_bits_y);
2338
751k
      mask256 = _mm256_cmpgt_epi32(min_base_y256, base_y_c256);
2339
751k
      base_y_c256 = _mm256_andnot_si256(mask256, base_y_c256);
2340
751k
      _mm256_store_si256((__m256i *)base_y_c, base_y_c256);
2341
2342
751k
      a0_y = _mm256_cvtepu16_epi32(_mm_setr_epi16(
2343
751k
          left[base_y_c[0]], left[base_y_c[1]], left[base_y_c[2]],
2344
751k
          left[base_y_c[3]], left[base_y_c[4]], left[base_y_c[5]],
2345
751k
          left[base_y_c[6]], left[base_y_c[7]]));
2346
751k
      a1_y = _mm256_cvtepu16_epi32(_mm_setr_epi16(
2347
751k
          left[base_y_c[0] + 1], left[base_y_c[1] + 1], left[base_y_c[2] + 1],
2348
751k
          left[base_y_c[3] + 1], left[base_y_c[4] + 1], left[base_y_c[5] + 1],
2349
751k
          left[base_y_c[6] + 1], left[base_y_c[7] + 1]));
2350
2351
751k
      if (upsample_left) {
2352
85.1k
        shift = _mm256_srli_epi32(
2353
85.1k
            _mm256_and_si256(_mm256_slli_epi32((y_c256), upsample_left), c3f),
2354
85.1k
            1);
2355
666k
      } else {
2356
666k
        shift = _mm256_srli_epi32(_mm256_and_si256(y_c256, c3f), 1);
2357
666k
      }
2358
751k
      diff = _mm256_sub_epi32(a1_y, a0_y);  // a[x+1] - a[x]
2359
751k
      a32 = _mm256_slli_epi32(a0_y, 5);     // a[x] * 32
2360
751k
      a32 = _mm256_add_epi32(a32, a16);     // a[x] * 32 + 16
2361
2362
751k
      b = _mm256_mullo_epi32(diff, shift);
2363
751k
      res = _mm256_add_epi32(a32, b);
2364
751k
      res = _mm256_srli_epi32(res, 5);
2365
2366
751k
      resy = _mm256_castsi256_si128(_mm256_packus_epi32(
2367
751k
          res, _mm256_castsi128_si256(_mm256_extracti128_si256(res, 1))));
2368
751k
    } else {
2369
128k
      resy = resx;
2370
128k
    }
2371
880k
    resxy =
2372
880k
        _mm_blendv_epi8(resx, resy, *(__m128i *)HighbdBaseMask[base_min_diff]);
2373
880k
    _mm_storeu_si128((__m128i *)(dst), resxy);
2374
880k
    dst += stride;
2375
880k
  }
2376
89.2k
}
2377
2378
static void highbd_dr_prediction_z2_Nx8_avx2(
2379
    int N, uint16_t *dst, ptrdiff_t stride, const uint16_t *above,
2380
    const uint16_t *left, int upsample_above, int upsample_left, int dx,
2381
297k
    int dy) {
2382
297k
  const int min_base_x = -(1 << upsample_above);
2383
297k
  const int min_base_y = -(1 << upsample_left);
2384
297k
  const int frac_bits_x = 6 - upsample_above;
2385
297k
  const int frac_bits_y = 6 - upsample_left;
2386
2387
  // pre-filter above pixels
2388
  // store in temp buffers:
2389
  //   above[x] * 32 + 16
2390
  //   above[x+1] - above[x]
2391
  // final pixels will be calculated as:
2392
  //   (above[x] * 32 + 16 + (above[x+1] - above[x]) * shift) >> 5
2393
297k
  __m128i c3f, min_base_y128;
2394
297k
  __m256i a0_x, a1_x, diff, a32, a16;
2395
297k
  __m128i a0_x128, a1_x128;
2396
2397
297k
  a16 = _mm256_set1_epi16(16);
2398
297k
  c3f = _mm_set1_epi16(0x3f);
2399
297k
  min_base_y128 = _mm_set1_epi16(min_base_y);
2400
2401
3.24M
  for (int r = 0; r < N; r++) {
2402
2.94M
    __m256i b, res, shift;
2403
2.94M
    __m128i resx, resy, resxy;
2404
2.94M
    int y = r + 1;
2405
2.94M
    int base_x = (-y * dx) >> frac_bits_x;
2406
2.94M
    int base_shift = 0;
2407
2.94M
    if (base_x < (min_base_x - 1)) {
2408
2.17M
      base_shift = (min_base_x - base_x - 1) >> upsample_above;
2409
2.17M
    }
2410
2.94M
    int base_min_diff =
2411
2.94M
        (min_base_x - base_x + upsample_above) >> upsample_above;
2412
2.94M
    if (base_min_diff > 8) {
2413
1.28M
      base_min_diff = 8;
2414
1.66M
    } else {
2415
1.66M
      if (base_min_diff < 0) base_min_diff = 0;
2416
1.66M
    }
2417
2418
2.94M
    if (base_shift > 7) {
2419
1.28M
      a0_x = _mm256_setzero_si256();
2420
1.28M
      a1_x = _mm256_setzero_si256();
2421
1.28M
      shift = _mm256_setzero_si256();
2422
1.66M
    } else {
2423
1.66M
      a0_x128 = _mm_loadu_si128((__m128i *)(above + base_x + base_shift));
2424
1.66M
      if (upsample_above) {
2425
453k
        __m128i mask, atmp0, atmp1, atmp2, atmp3;
2426
453k
        a1_x128 = _mm_loadu_si128((__m128i *)(above + base_x + 8 + base_shift));
2427
453k
        atmp0 = _mm_shuffle_epi8(a0_x128,
2428
453k
                                 *(__m128i *)HighbdEvenOddMaskx[base_shift]);
2429
453k
        atmp1 = _mm_shuffle_epi8(a1_x128,
2430
453k
                                 *(__m128i *)HighbdEvenOddMaskx[base_shift]);
2431
453k
        atmp2 = _mm_shuffle_epi8(
2432
453k
            a0_x128, *(__m128i *)(HighbdEvenOddMaskx[base_shift] + 16));
2433
453k
        atmp3 = _mm_shuffle_epi8(
2434
453k
            a1_x128, *(__m128i *)(HighbdEvenOddMaskx[base_shift] + 16));
2435
453k
        mask = _mm_cmpgt_epi8(*(__m128i *)HighbdEvenOddMaskx[base_shift],
2436
453k
                              _mm_set1_epi8(15));
2437
453k
        a0_x128 = _mm_blendv_epi8(atmp0, atmp1, mask);
2438
453k
        mask = _mm_cmpgt_epi8(*(__m128i *)(HighbdEvenOddMaskx[base_shift] + 16),
2439
453k
                              _mm_set1_epi8(15));
2440
453k
        a1_x128 = _mm_blendv_epi8(atmp2, atmp3, mask);
2441
2442
453k
        shift = _mm256_castsi128_si256(_mm_srli_epi16(
2443
453k
            _mm_and_si128(
2444
453k
                _mm_slli_epi16(
2445
453k
                    _mm_setr_epi16(-y * dx, (1 << 6) - y * dx,
2446
453k
                                   (2 << 6) - y * dx, (3 << 6) - y * dx,
2447
453k
                                   (4 << 6) - y * dx, (5 << 6) - y * dx,
2448
453k
                                   (6 << 6) - y * dx, (7 << 6) - y * dx),
2449
453k
                    upsample_above),
2450
453k
                c3f),
2451
453k
            1));
2452
1.21M
      } else {
2453
1.21M
        a1_x128 = _mm_loadu_si128((__m128i *)(above + base_x + 1 + base_shift));
2454
1.21M
        a0_x128 =
2455
1.21M
            _mm_shuffle_epi8(a0_x128, *(__m128i *)HighbdLoadMaskx[base_shift]);
2456
1.21M
        a1_x128 =
2457
1.21M
            _mm_shuffle_epi8(a1_x128, *(__m128i *)HighbdLoadMaskx[base_shift]);
2458
2459
1.21M
        shift = _mm256_castsi128_si256(_mm_srli_epi16(
2460
1.21M
            _mm_and_si128(_mm_setr_epi16(-y * dx, (1 << 6) - y * dx,
2461
1.21M
                                         (2 << 6) - y * dx, (3 << 6) - y * dx,
2462
1.21M
                                         (4 << 6) - y * dx, (5 << 6) - y * dx,
2463
1.21M
                                         (6 << 6) - y * dx, (7 << 6) - y * dx),
2464
1.21M
                          c3f),
2465
1.21M
            1));
2466
1.21M
      }
2467
1.66M
      a0_x = _mm256_castsi128_si256(a0_x128);
2468
1.66M
      a1_x = _mm256_castsi128_si256(a1_x128);
2469
1.66M
    }
2470
2471
    // y calc
2472
2.94M
    __m128i a0_y, a1_y, shifty;
2473
2.94M
    if (base_x < min_base_x) {
2474
2.44M
      DECLARE_ALIGNED(32, int16_t, base_y_c[8]);
2475
2.44M
      __m128i r6, c1234, dy128, y_c128, base_y_c128, mask128;
2476
2.44M
      r6 = _mm_set1_epi16(r << 6);
2477
2.44M
      dy128 = _mm_set1_epi16(dy);
2478
2.44M
      c1234 = _mm_setr_epi16(1, 2, 3, 4, 5, 6, 7, 8);
2479
2.44M
      y_c128 = _mm_sub_epi16(r6, _mm_mullo_epi16(c1234, dy128));
2480
2.44M
      base_y_c128 = _mm_srai_epi16(y_c128, frac_bits_y);
2481
2.44M
      mask128 = _mm_cmpgt_epi16(min_base_y128, base_y_c128);
2482
2.44M
      base_y_c128 = _mm_andnot_si128(mask128, base_y_c128);
2483
2.44M
      _mm_store_si128((__m128i *)base_y_c, base_y_c128);
2484
2485
2.44M
      a0_y = _mm_setr_epi16(left[base_y_c[0]], left[base_y_c[1]],
2486
2.44M
                            left[base_y_c[2]], left[base_y_c[3]],
2487
2.44M
                            left[base_y_c[4]], left[base_y_c[5]],
2488
2.44M
                            left[base_y_c[6]], left[base_y_c[7]]);
2489
2.44M
      a1_y = _mm_setr_epi16(left[base_y_c[0] + 1], left[base_y_c[1] + 1],
2490
2.44M
                            left[base_y_c[2] + 1], left[base_y_c[3] + 1],
2491
2.44M
                            left[base_y_c[4] + 1], left[base_y_c[5] + 1],
2492
2.44M
                            left[base_y_c[6] + 1], left[base_y_c[7] + 1]);
2493
2494
2.44M
      if (upsample_left) {
2495
573k
        shifty = _mm_srli_epi16(
2496
573k
            _mm_and_si128(_mm_slli_epi16((y_c128), upsample_left), c3f), 1);
2497
1.87M
      } else {
2498
1.87M
        shifty = _mm_srli_epi16(_mm_and_si128(y_c128, c3f), 1);
2499
1.87M
      }
2500
2.44M
      a0_x = _mm256_inserti128_si256(a0_x, a0_y, 1);
2501
2.44M
      a1_x = _mm256_inserti128_si256(a1_x, a1_y, 1);
2502
2.44M
      shift = _mm256_inserti128_si256(shift, shifty, 1);
2503
2.44M
    }
2504
2505
2.94M
    diff = _mm256_sub_epi16(a1_x, a0_x);  // a[x+1] - a[x]
2506
2.94M
    a32 = _mm256_slli_epi16(a0_x, 5);     // a[x] * 32
2507
2.94M
    a32 = _mm256_add_epi16(a32, a16);     // a[x] * 32 + 16
2508
2509
2.94M
    b = _mm256_mullo_epi16(diff, shift);
2510
2.94M
    res = _mm256_add_epi16(a32, b);
2511
2.94M
    res = _mm256_srli_epi16(res, 5);
2512
2513
2.94M
    resx = _mm256_castsi256_si128(res);
2514
2.94M
    resy = _mm256_extracti128_si256(res, 1);
2515
2516
2.94M
    resxy =
2517
2.94M
        _mm_blendv_epi8(resx, resy, *(__m128i *)HighbdBaseMask[base_min_diff]);
2518
2.94M
    _mm_storeu_si128((__m128i *)(dst), resxy);
2519
2.94M
    dst += stride;
2520
2.94M
  }
2521
297k
}
2522
2523
static void highbd_dr_prediction_32bit_z2_HxW_avx2(
2524
    int H, int W, uint16_t *dst, ptrdiff_t stride, const uint16_t *above,
2525
    const uint16_t *left, int upsample_above, int upsample_left, int dx,
2526
85.0k
    int dy) {
2527
  // here upsample_above and upsample_left are 0 by design of
2528
  // av1_use_intra_edge_upsample
2529
85.0k
  const int min_base_x = -1;
2530
85.0k
  const int min_base_y = -1;
2531
85.0k
  (void)upsample_above;
2532
85.0k
  (void)upsample_left;
2533
85.0k
  const int frac_bits_x = 6;
2534
85.0k
  const int frac_bits_y = 6;
2535
2536
  // pre-filter above pixels
2537
  // store in temp buffers:
2538
  //   above[x] * 32 + 16
2539
  //   above[x+1] - above[x]
2540
  // final pixels will be calculated as:
2541
  //   (above[x] * 32 + 16 + (above[x+1] - above[x]) * shift) >> 5
2542
85.0k
  __m256i a0_x, a1_x, a0_y, a1_y, a32, a0_1_x, a1_1_x, a16, c1;
2543
85.0k
  __m256i diff, min_base_y256, c3f, dy256, c1234, c0123, c8;
2544
85.0k
  __m128i a0_x128, a1_x128, a0_1_x128, a1_1_x128;
2545
85.0k
  DECLARE_ALIGNED(32, int, base_y_c[16]);
2546
2547
85.0k
  a16 = _mm256_set1_epi32(16);
2548
85.0k
  c1 = _mm256_srli_epi32(a16, 4);
2549
85.0k
  c8 = _mm256_srli_epi32(a16, 1);
2550
85.0k
  min_base_y256 = _mm256_set1_epi32(min_base_y);
2551
85.0k
  c3f = _mm256_set1_epi32(0x3f);
2552
85.0k
  dy256 = _mm256_set1_epi32(dy);
2553
85.0k
  c0123 = _mm256_setr_epi32(0, 1, 2, 3, 4, 5, 6, 7);
2554
85.0k
  c1234 = _mm256_add_epi32(c0123, c1);
2555
2556
1.55M
  for (int r = 0; r < H; r++) {
2557
1.47M
    __m256i b, res, shift, ydx;
2558
1.47M
    __m256i resx[2], resy[2];
2559
1.47M
    __m256i resxy, j256, r6;
2560
4.89M
    for (int j = 0; j < W; j += 16) {
2561
3.41M
      j256 = _mm256_set1_epi32(j);
2562
3.41M
      int y = r + 1;
2563
3.41M
      ydx = _mm256_set1_epi32(y * dx);
2564
2565
3.41M
      int base_x = ((j << 6) - y * dx) >> frac_bits_x;
2566
3.41M
      int base_shift = 0;
2567
3.41M
      if ((base_x) < (min_base_x - 1)) {
2568
2.18M
        base_shift = (min_base_x - base_x - 1);
2569
2.18M
      }
2570
3.41M
      int base_min_diff = (min_base_x - base_x);
2571
3.41M
      if (base_min_diff > 16) {
2572
1.45M
        base_min_diff = 16;
2573
1.96M
      } else {
2574
1.96M
        if (base_min_diff < 0) base_min_diff = 0;
2575
1.96M
      }
2576
2577
3.41M
      if (base_shift > 7) {
2578
1.74M
        resx[0] = _mm256_setzero_si256();
2579
1.74M
      } else {
2580
1.67M
        a0_x128 = _mm_loadu_si128((__m128i *)(above + base_x + base_shift));
2581
1.67M
        a1_x128 = _mm_loadu_si128((__m128i *)(above + base_x + base_shift + 1));
2582
1.67M
        a0_x128 =
2583
1.67M
            _mm_shuffle_epi8(a0_x128, *(__m128i *)HighbdLoadMaskx[base_shift]);
2584
1.67M
        a1_x128 =
2585
1.67M
            _mm_shuffle_epi8(a1_x128, *(__m128i *)HighbdLoadMaskx[base_shift]);
2586
2587
1.67M
        a0_x = _mm256_cvtepu16_epi32(a0_x128);
2588
1.67M
        a1_x = _mm256_cvtepu16_epi32(a1_x128);
2589
2590
1.67M
        r6 = _mm256_slli_epi32(_mm256_add_epi32(c0123, j256), 6);
2591
1.67M
        shift = _mm256_srli_epi32(
2592
1.67M
            _mm256_and_si256(_mm256_sub_epi32(r6, ydx), c3f), 1);
2593
2594
1.67M
        diff = _mm256_sub_epi32(a1_x, a0_x);  // a[x+1] - a[x]
2595
1.67M
        a32 = _mm256_slli_epi32(a0_x, 5);     // a[x] * 32
2596
1.67M
        a32 = _mm256_add_epi32(a32, a16);     // a[x] * 32 + 16
2597
2598
1.67M
        b = _mm256_mullo_epi32(diff, shift);
2599
1.67M
        res = _mm256_add_epi32(a32, b);
2600
1.67M
        res = _mm256_srli_epi32(res, 5);
2601
2602
1.67M
        resx[0] = _mm256_packus_epi32(
2603
1.67M
            res, _mm256_castsi128_si256(_mm256_extracti128_si256(res, 1)));
2604
1.67M
      }
2605
3.41M
      int base_shift8 = 0;
2606
3.41M
      if ((base_x + 8) < (min_base_x - 1)) {
2607
1.70M
        base_shift8 = (min_base_x - (base_x + 8) - 1);
2608
1.70M
      }
2609
3.41M
      if (base_shift8 > 7) {
2610
1.45M
        resx[1] = _mm256_setzero_si256();
2611
1.96M
      } else {
2612
1.96M
        a0_1_x128 =
2613
1.96M
            _mm_loadu_si128((__m128i *)(above + base_x + base_shift8 + 8));
2614
1.96M
        a1_1_x128 =
2615
1.96M
            _mm_loadu_si128((__m128i *)(above + base_x + base_shift8 + 9));
2616
1.96M
        a0_1_x128 = _mm_shuffle_epi8(a0_1_x128,
2617
1.96M
                                     *(__m128i *)HighbdLoadMaskx[base_shift8]);
2618
1.96M
        a1_1_x128 = _mm_shuffle_epi8(a1_1_x128,
2619
1.96M
                                     *(__m128i *)HighbdLoadMaskx[base_shift8]);
2620
2621
1.96M
        a0_1_x = _mm256_cvtepu16_epi32(a0_1_x128);
2622
1.96M
        a1_1_x = _mm256_cvtepu16_epi32(a1_1_x128);
2623
2624
1.96M
        r6 = _mm256_slli_epi32(
2625
1.96M
            _mm256_add_epi32(c0123, _mm256_add_epi32(j256, c8)), 6);
2626
1.96M
        shift = _mm256_srli_epi32(
2627
1.96M
            _mm256_and_si256(_mm256_sub_epi32(r6, ydx), c3f), 1);
2628
2629
1.96M
        diff = _mm256_sub_epi32(a1_1_x, a0_1_x);  // a[x+1] - a[x]
2630
1.96M
        a32 = _mm256_slli_epi32(a0_1_x, 5);       // a[x] * 32
2631
1.96M
        a32 = _mm256_add_epi32(a32, a16);         // a[x] * 32 + 16
2632
1.96M
        b = _mm256_mullo_epi32(diff, shift);
2633
2634
1.96M
        resx[1] = _mm256_add_epi32(a32, b);
2635
1.96M
        resx[1] = _mm256_srli_epi32(resx[1], 5);
2636
1.96M
        resx[1] = _mm256_packus_epi32(
2637
1.96M
            resx[1],
2638
1.96M
            _mm256_castsi128_si256(_mm256_extracti128_si256(resx[1], 1)));
2639
1.96M
      }
2640
3.41M
      resx[0] =
2641
3.41M
          _mm256_inserti128_si256(resx[0], _mm256_castsi256_si128(resx[1]),
2642
3.41M
                                  1);  // 16 16bit values
2643
2644
      // y calc
2645
3.41M
      resy[0] = _mm256_setzero_si256();
2646
3.41M
      if ((base_x < min_base_x)) {
2647
2.29M
        __m256i c256, y_c256, y_c_1_256, base_y_c256, mask256;
2648
2.29M
        r6 = _mm256_set1_epi32(r << 6);
2649
2.29M
        c256 = _mm256_add_epi32(j256, c1234);
2650
2.29M
        y_c256 = _mm256_sub_epi32(r6, _mm256_mullo_epi32(c256, dy256));
2651
2.29M
        base_y_c256 = _mm256_srai_epi32(y_c256, frac_bits_y);
2652
2.29M
        mask256 = _mm256_cmpgt_epi32(min_base_y256, base_y_c256);
2653
2.29M
        base_y_c256 = _mm256_andnot_si256(mask256, base_y_c256);
2654
2.29M
        _mm256_store_si256((__m256i *)base_y_c, base_y_c256);
2655
2.29M
        c256 = _mm256_add_epi32(c256, c8);
2656
2.29M
        y_c_1_256 = _mm256_sub_epi32(r6, _mm256_mullo_epi32(c256, dy256));
2657
2.29M
        base_y_c256 = _mm256_srai_epi32(y_c_1_256, frac_bits_y);
2658
2.29M
        mask256 = _mm256_cmpgt_epi32(min_base_y256, base_y_c256);
2659
2.29M
        base_y_c256 = _mm256_andnot_si256(mask256, base_y_c256);
2660
2.29M
        _mm256_store_si256((__m256i *)(base_y_c + 8), base_y_c256);
2661
2662
2.29M
        a0_y = _mm256_cvtepu16_epi32(_mm_setr_epi16(
2663
2.29M
            left[base_y_c[0]], left[base_y_c[1]], left[base_y_c[2]],
2664
2.29M
            left[base_y_c[3]], left[base_y_c[4]], left[base_y_c[5]],
2665
2.29M
            left[base_y_c[6]], left[base_y_c[7]]));
2666
2.29M
        a1_y = _mm256_cvtepu16_epi32(_mm_setr_epi16(
2667
2.29M
            left[base_y_c[0] + 1], left[base_y_c[1] + 1], left[base_y_c[2] + 1],
2668
2.29M
            left[base_y_c[3] + 1], left[base_y_c[4] + 1], left[base_y_c[5] + 1],
2669
2.29M
            left[base_y_c[6] + 1], left[base_y_c[7] + 1]));
2670
2671
2.29M
        shift = _mm256_srli_epi32(_mm256_and_si256(y_c256, c3f), 1);
2672
2673
2.29M
        diff = _mm256_sub_epi32(a1_y, a0_y);  // a[x+1] - a[x]
2674
2.29M
        a32 = _mm256_slli_epi32(a0_y, 5);     // a[x] * 32
2675
2.29M
        a32 = _mm256_add_epi32(a32, a16);     // a[x] * 32 + 16
2676
2677
2.29M
        b = _mm256_mullo_epi32(diff, shift);
2678
2.29M
        res = _mm256_add_epi32(a32, b);
2679
2.29M
        res = _mm256_srli_epi32(res, 5);
2680
2681
2.29M
        resy[0] = _mm256_packus_epi32(
2682
2.29M
            res, _mm256_castsi128_si256(_mm256_extracti128_si256(res, 1)));
2683
2684
2.29M
        a0_y = _mm256_cvtepu16_epi32(_mm_setr_epi16(
2685
2.29M
            left[base_y_c[8]], left[base_y_c[9]], left[base_y_c[10]],
2686
2.29M
            left[base_y_c[11]], left[base_y_c[12]], left[base_y_c[13]],
2687
2.29M
            left[base_y_c[14]], left[base_y_c[15]]));
2688
2.29M
        a1_y = _mm256_cvtepu16_epi32(
2689
2.29M
            _mm_setr_epi16(left[base_y_c[8] + 1], left[base_y_c[9] + 1],
2690
2.29M
                           left[base_y_c[10] + 1], left[base_y_c[11] + 1],
2691
2.29M
                           left[base_y_c[12] + 1], left[base_y_c[13] + 1],
2692
2.29M
                           left[base_y_c[14] + 1], left[base_y_c[15] + 1]));
2693
2.29M
        shift = _mm256_srli_epi32(_mm256_and_si256(y_c_1_256, c3f), 1);
2694
2695
2.29M
        diff = _mm256_sub_epi32(a1_y, a0_y);  // a[x+1] - a[x]
2696
2.29M
        a32 = _mm256_slli_epi32(a0_y, 5);     // a[x] * 32
2697
2.29M
        a32 = _mm256_add_epi32(a32, a16);     // a[x] * 32 + 16
2698
2699
2.29M
        b = _mm256_mullo_epi32(diff, shift);
2700
2.29M
        res = _mm256_add_epi32(a32, b);
2701
2.29M
        res = _mm256_srli_epi32(res, 5);
2702
2703
2.29M
        resy[1] = _mm256_packus_epi32(
2704
2.29M
            res, _mm256_castsi128_si256(_mm256_extracti128_si256(res, 1)));
2705
2706
2.29M
        resy[0] =
2707
2.29M
            _mm256_inserti128_si256(resy[0], _mm256_castsi256_si128(resy[1]),
2708
2.29M
                                    1);  // 16 16bit values
2709
2.29M
      }
2710
2711
3.41M
      resxy = _mm256_blendv_epi8(resx[0], resy[0],
2712
3.41M
                                 *(__m256i *)HighbdBaseMask[base_min_diff]);
2713
3.41M
      _mm256_storeu_si256((__m256i *)(dst + j), resxy);
2714
3.41M
    }  // for j
2715
1.47M
    dst += stride;
2716
1.47M
  }
2717
85.0k
}
2718
2719
static void highbd_dr_prediction_z2_HxW_avx2(
2720
    int H, int W, uint16_t *dst, ptrdiff_t stride, const uint16_t *above,
2721
    const uint16_t *left, int upsample_above, int upsample_left, int dx,
2722
512k
    int dy) {
2723
  // here upsample_above and upsample_left are 0 by design of
2724
  // av1_use_intra_edge_upsample
2725
512k
  const int min_base_x = -1;
2726
512k
  const int min_base_y = -1;
2727
512k
  (void)upsample_above;
2728
512k
  (void)upsample_left;
2729
512k
  const int frac_bits_x = 6;
2730
512k
  const int frac_bits_y = 6;
2731
2732
  // pre-filter above pixels
2733
  // store in temp buffers:
2734
  //   above[x] * 32 + 16
2735
  //   above[x+1] - above[x]
2736
  // final pixels will be calculated as:
2737
  //   (above[x] * 32 + 16 + (above[x+1] - above[x]) * shift) >> 5
2738
512k
  __m256i a0_x, a1_x, a32, a16, c3f, c1;
2739
512k
  __m256i diff, min_base_y256, dy256, c1234, c0123;
2740
512k
  DECLARE_ALIGNED(32, int16_t, base_y_c[16]);
2741
2742
512k
  a16 = _mm256_set1_epi16(16);
2743
512k
  c1 = _mm256_srli_epi16(a16, 4);
2744
512k
  min_base_y256 = _mm256_set1_epi16(min_base_y);
2745
512k
  c3f = _mm256_set1_epi16(0x3f);
2746
512k
  dy256 = _mm256_set1_epi16(dy);
2747
512k
  c0123 =
2748
512k
      _mm256_setr_epi16(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
2749
512k
  c1234 = _mm256_add_epi16(c0123, c1);
2750
2751
10.0M
  for (int r = 0; r < H; r++) {
2752
9.55M
    __m256i b, res, shift;
2753
9.55M
    __m256i resx, resy, ydx;
2754
9.55M
    __m256i resxy, j256, r6;
2755
9.55M
    __m128i a0_x128, a1_x128, a0_1_x128, a1_1_x128;
2756
9.55M
    int y = r + 1;
2757
9.55M
    ydx = _mm256_set1_epi16((short)(y * dx));
2758
2759
26.1M
    for (int j = 0; j < W; j += 16) {
2760
16.5M
      j256 = _mm256_set1_epi16(j);
2761
16.5M
      int base_x = ((j << 6) - y * dx) >> frac_bits_x;
2762
16.5M
      int base_shift = 0;
2763
16.5M
      if ((base_x) < (min_base_x - 1)) {
2764
12.2M
        base_shift = (min_base_x - (base_x)-1);
2765
12.2M
      }
2766
16.5M
      int base_min_diff = (min_base_x - base_x);
2767
16.5M
      if (base_min_diff > 16) {
2768
8.98M
        base_min_diff = 16;
2769
8.98M
      } else {
2770
7.61M
        if (base_min_diff < 0) base_min_diff = 0;
2771
7.61M
      }
2772
2773
16.5M
      if (base_shift < 8) {
2774
6.34M
        a0_x128 = _mm_loadu_si128((__m128i *)(above + base_x + base_shift));
2775
6.34M
        a1_x128 = _mm_loadu_si128((__m128i *)(above + base_x + base_shift + 1));
2776
6.34M
        a0_x128 =
2777
6.34M
            _mm_shuffle_epi8(a0_x128, *(__m128i *)HighbdLoadMaskx[base_shift]);
2778
6.34M
        a1_x128 =
2779
6.34M
            _mm_shuffle_epi8(a1_x128, *(__m128i *)HighbdLoadMaskx[base_shift]);
2780
2781
6.34M
        a0_x = _mm256_castsi128_si256(a0_x128);
2782
6.34M
        a1_x = _mm256_castsi128_si256(a1_x128);
2783
10.2M
      } else {
2784
10.2M
        a0_x = _mm256_setzero_si256();
2785
10.2M
        a1_x = _mm256_setzero_si256();
2786
10.2M
      }
2787
2788
16.5M
      int base_shift1 = 0;
2789
16.5M
      if (base_shift > 8) {
2790
10.0M
        base_shift1 = base_shift - 8;
2791
10.0M
      }
2792
16.5M
      if (base_shift1 < 8) {
2793
7.61M
        a0_1_x128 =
2794
7.61M
            _mm_loadu_si128((__m128i *)(above + base_x + base_shift1 + 8));
2795
7.61M
        a1_1_x128 =
2796
7.61M
            _mm_loadu_si128((__m128i *)(above + base_x + base_shift1 + 9));
2797
7.61M
        a0_1_x128 = _mm_shuffle_epi8(a0_1_x128,
2798
7.61M
                                     *(__m128i *)HighbdLoadMaskx[base_shift1]);
2799
7.61M
        a1_1_x128 = _mm_shuffle_epi8(a1_1_x128,
2800
7.61M
                                     *(__m128i *)HighbdLoadMaskx[base_shift1]);
2801
2802
7.61M
        a0_x = _mm256_inserti128_si256(a0_x, a0_1_x128, 1);
2803
7.61M
        a1_x = _mm256_inserti128_si256(a1_x, a1_1_x128, 1);
2804
7.61M
      }
2805
16.5M
      r6 = _mm256_slli_epi16(_mm256_add_epi16(c0123, j256), 6);
2806
16.5M
      shift = _mm256_srli_epi16(
2807
16.5M
          _mm256_and_si256(_mm256_sub_epi16(r6, ydx), c3f), 1);
2808
2809
16.5M
      diff = _mm256_sub_epi16(a1_x, a0_x);  // a[x+1] - a[x]
2810
16.5M
      a32 = _mm256_slli_epi16(a0_x, 5);     // a[x] * 32
2811
16.5M
      a32 = _mm256_add_epi16(a32, a16);     // a[x] * 32 + 16
2812
2813
16.5M
      b = _mm256_mullo_epi16(diff, shift);
2814
16.5M
      res = _mm256_add_epi16(a32, b);
2815
16.5M
      resx = _mm256_srli_epi16(res, 5);  // 16 16-bit values
2816
2817
      // y calc
2818
16.5M
      resy = _mm256_setzero_si256();
2819
16.5M
      __m256i a0_y, a1_y, shifty;
2820
16.5M
      if ((base_x < min_base_x)) {
2821
12.9M
        __m256i c256, y_c256, base_y_c256, mask256, mul16;
2822
12.9M
        r6 = _mm256_set1_epi16(r << 6);
2823
12.9M
        c256 = _mm256_add_epi16(j256, c1234);
2824
12.9M
        mul16 = _mm256_min_epu16(_mm256_mullo_epi16(c256, dy256),
2825
12.9M
                                 _mm256_srli_epi16(min_base_y256, 1));
2826
12.9M
        y_c256 = _mm256_sub_epi16(r6, mul16);
2827
12.9M
        base_y_c256 = _mm256_srai_epi16(y_c256, frac_bits_y);
2828
12.9M
        mask256 = _mm256_cmpgt_epi16(min_base_y256, base_y_c256);
2829
12.9M
        base_y_c256 = _mm256_andnot_si256(mask256, base_y_c256);
2830
12.9M
        _mm256_store_si256((__m256i *)base_y_c, base_y_c256);
2831
2832
12.9M
        a0_y = _mm256_setr_epi16(
2833
12.9M
            left[base_y_c[0]], left[base_y_c[1]], left[base_y_c[2]],
2834
12.9M
            left[base_y_c[3]], left[base_y_c[4]], left[base_y_c[5]],
2835
12.9M
            left[base_y_c[6]], left[base_y_c[7]], left[base_y_c[8]],
2836
12.9M
            left[base_y_c[9]], left[base_y_c[10]], left[base_y_c[11]],
2837
12.9M
            left[base_y_c[12]], left[base_y_c[13]], left[base_y_c[14]],
2838
12.9M
            left[base_y_c[15]]);
2839
12.9M
        base_y_c256 = _mm256_add_epi16(base_y_c256, c1);
2840
12.9M
        _mm256_store_si256((__m256i *)base_y_c, base_y_c256);
2841
2842
12.9M
        a1_y = _mm256_setr_epi16(
2843
12.9M
            left[base_y_c[0]], left[base_y_c[1]], left[base_y_c[2]],
2844
12.9M
            left[base_y_c[3]], left[base_y_c[4]], left[base_y_c[5]],
2845
12.9M
            left[base_y_c[6]], left[base_y_c[7]], left[base_y_c[8]],
2846
12.9M
            left[base_y_c[9]], left[base_y_c[10]], left[base_y_c[11]],
2847
12.9M
            left[base_y_c[12]], left[base_y_c[13]], left[base_y_c[14]],
2848
12.9M
            left[base_y_c[15]]);
2849
2850
12.9M
        shifty = _mm256_srli_epi16(_mm256_and_si256(y_c256, c3f), 1);
2851
2852
12.9M
        diff = _mm256_sub_epi16(a1_y, a0_y);  // a[x+1] - a[x]
2853
12.9M
        a32 = _mm256_slli_epi16(a0_y, 5);     // a[x] * 32
2854
12.9M
        a32 = _mm256_add_epi16(a32, a16);     // a[x] * 32 + 16
2855
2856
12.9M
        b = _mm256_mullo_epi16(diff, shifty);
2857
12.9M
        res = _mm256_add_epi16(a32, b);
2858
12.9M
        resy = _mm256_srli_epi16(res, 5);
2859
12.9M
      }
2860
2861
16.5M
      resxy = _mm256_blendv_epi8(resx, resy,
2862
16.5M
                                 *(__m256i *)HighbdBaseMask[base_min_diff]);
2863
16.5M
      _mm256_storeu_si256((__m256i *)(dst + j), resxy);
2864
16.5M
    }  // for j
2865
9.55M
    dst += stride;
2866
9.55M
  }
2867
512k
}
2868
2869
// Directional prediction, zone 2: 90 < angle < 180
2870
void av1_highbd_dr_prediction_z2_avx2(uint16_t *dst, ptrdiff_t stride, int bw,
2871
                                      int bh, const uint16_t *above,
2872
                                      const uint16_t *left, int upsample_above,
2873
                                      int upsample_left, int dx, int dy,
2874
1.26M
                                      int bd) {
2875
1.26M
  (void)bd;
2876
1.26M
  assert(dx > 0);
2877
1.26M
  assert(dy > 0);
2878
1.26M
  switch (bw) {
2879
276k
    case 4:
2880
276k
      if (bd < 12) {
2881
178k
        highbd_dr_prediction_z2_Nx4_avx2(bh, dst, stride, above, left,
2882
178k
                                         upsample_above, upsample_left, dx, dy);
2883
178k
      } else {
2884
98.8k
        highbd_dr_prediction_32bit_z2_Nx4_avx2(bh, dst, stride, above, left,
2885
98.8k
                                               upsample_above, upsample_left,
2886
98.8k
                                               dx, dy);
2887
98.8k
      }
2888
276k
      break;
2889
387k
    case 8:
2890
387k
      if (bd < 12) {
2891
297k
        highbd_dr_prediction_z2_Nx8_avx2(bh, dst, stride, above, left,
2892
297k
                                         upsample_above, upsample_left, dx, dy);
2893
297k
      } else {
2894
89.2k
        highbd_dr_prediction_32bit_z2_Nx8_avx2(bh, dst, stride, above, left,
2895
89.2k
                                               upsample_above, upsample_left,
2896
89.2k
                                               dx, dy);
2897
89.2k
      }
2898
387k
      break;
2899
597k
    default:
2900
597k
      if (bd < 12) {
2901
512k
        highbd_dr_prediction_z2_HxW_avx2(bh, bw, dst, stride, above, left,
2902
512k
                                         upsample_above, upsample_left, dx, dy);
2903
512k
      } else {
2904
85.0k
        highbd_dr_prediction_32bit_z2_HxW_avx2(bh, bw, dst, stride, above, left,
2905
85.0k
                                               upsample_above, upsample_left,
2906
85.0k
                                               dx, dy);
2907
85.0k
      }
2908
597k
      break;
2909
1.26M
  }
2910
1.26M
}
2911
2912
//  Directional prediction, zone 3 functions
2913
static void highbd_dr_prediction_z3_4x4_avx2(uint16_t *dst, ptrdiff_t stride,
2914
                                             const uint16_t *left,
2915
                                             int upsample_left, int dy,
2916
171k
                                             int bd) {
2917
171k
  __m128i dstvec[4], d[4];
2918
171k
  if (bd < 12) {
2919
144k
    highbd_dr_prediction_z1_4xN_internal_avx2(4, dstvec, left, upsample_left,
2920
144k
                                              dy);
2921
144k
  } else {
2922
26.9k
    highbd_dr_prediction_32bit_z1_4xN_internal_avx2(4, dstvec, left,
2923
26.9k
                                                    upsample_left, dy);
2924
26.9k
  }
2925
171k
  highbd_transpose4x8_8x4_low_sse2(&dstvec[0], &dstvec[1], &dstvec[2],
2926
171k
                                   &dstvec[3], &d[0], &d[1], &d[2], &d[3]);
2927
171k
  _mm_storel_epi64((__m128i *)(dst + 0 * stride), d[0]);
2928
171k
  _mm_storel_epi64((__m128i *)(dst + 1 * stride), d[1]);
2929
171k
  _mm_storel_epi64((__m128i *)(dst + 2 * stride), d[2]);
2930
171k
  _mm_storel_epi64((__m128i *)(dst + 3 * stride), d[3]);
2931
171k
  return;
2932
171k
}
2933
2934
static void highbd_dr_prediction_z3_8x8_avx2(uint16_t *dst, ptrdiff_t stride,
2935
                                             const uint16_t *left,
2936
                                             int upsample_left, int dy,
2937
156k
                                             int bd) {
2938
156k
  __m128i dstvec[8], d[8];
2939
156k
  if (bd < 12) {
2940
116k
    highbd_dr_prediction_z1_8xN_internal_avx2(8, dstvec, left, upsample_left,
2941
116k
                                              dy);
2942
116k
  } else {
2943
39.9k
    highbd_dr_prediction_32bit_z1_8xN_internal_avx2(8, dstvec, left,
2944
39.9k
                                                    upsample_left, dy);
2945
39.9k
  }
2946
156k
  highbd_transpose8x8_sse2(&dstvec[0], &dstvec[1], &dstvec[2], &dstvec[3],
2947
156k
                           &dstvec[4], &dstvec[5], &dstvec[6], &dstvec[7],
2948
156k
                           &d[0], &d[1], &d[2], &d[3], &d[4], &d[5], &d[6],
2949
156k
                           &d[7]);
2950
1.40M
  for (int i = 0; i < 8; i++) {
2951
1.25M
    _mm_storeu_si128((__m128i *)(dst + i * stride), d[i]);
2952
1.25M
  }
2953
156k
}
2954
2955
static void highbd_dr_prediction_z3_4x8_avx2(uint16_t *dst, ptrdiff_t stride,
2956
                                             const uint16_t *left,
2957
                                             int upsample_left, int dy,
2958
26.9k
                                             int bd) {
2959
26.9k
  __m128i dstvec[4], d[8];
2960
26.9k
  if (bd < 12) {
2961
22.1k
    highbd_dr_prediction_z1_8xN_internal_avx2(4, dstvec, left, upsample_left,
2962
22.1k
                                              dy);
2963
22.1k
  } else {
2964
4.85k
    highbd_dr_prediction_32bit_z1_8xN_internal_avx2(4, dstvec, left,
2965
4.85k
                                                    upsample_left, dy);
2966
4.85k
  }
2967
2968
26.9k
  highbd_transpose4x8_8x4_sse2(&dstvec[0], &dstvec[1], &dstvec[2], &dstvec[3],
2969
26.9k
                               &d[0], &d[1], &d[2], &d[3], &d[4], &d[5], &d[6],
2970
26.9k
                               &d[7]);
2971
242k
  for (int i = 0; i < 8; i++) {
2972
215k
    _mm_storel_epi64((__m128i *)(dst + i * stride), d[i]);
2973
215k
  }
2974
26.9k
}
2975
2976
static void highbd_dr_prediction_z3_8x4_avx2(uint16_t *dst, ptrdiff_t stride,
2977
                                             const uint16_t *left,
2978
                                             int upsample_left, int dy,
2979
57.4k
                                             int bd) {
2980
57.4k
  __m128i dstvec[8], d[4];
2981
57.4k
  if (bd < 12) {
2982
46.5k
    highbd_dr_prediction_z1_4xN_internal_avx2(8, dstvec, left, upsample_left,
2983
46.5k
                                              dy);
2984
46.5k
  } else {
2985
10.9k
    highbd_dr_prediction_32bit_z1_4xN_internal_avx2(8, dstvec, left,
2986
10.9k
                                                    upsample_left, dy);
2987
10.9k
  }
2988
2989
57.4k
  highbd_transpose8x8_low_sse2(&dstvec[0], &dstvec[1], &dstvec[2], &dstvec[3],
2990
57.4k
                               &dstvec[4], &dstvec[5], &dstvec[6], &dstvec[7],
2991
57.4k
                               &d[0], &d[1], &d[2], &d[3]);
2992
57.4k
  _mm_storeu_si128((__m128i *)(dst + 0 * stride), d[0]);
2993
57.4k
  _mm_storeu_si128((__m128i *)(dst + 1 * stride), d[1]);
2994
57.4k
  _mm_storeu_si128((__m128i *)(dst + 2 * stride), d[2]);
2995
57.4k
  _mm_storeu_si128((__m128i *)(dst + 3 * stride), d[3]);
2996
57.4k
}
2997
2998
static void highbd_dr_prediction_z3_8x16_avx2(uint16_t *dst, ptrdiff_t stride,
2999
                                              const uint16_t *left,
3000
                                              int upsample_left, int dy,
3001
40.3k
                                              int bd) {
3002
40.3k
  __m256i dstvec[8], d[8];
3003
40.3k
  if (bd < 12) {
3004
29.3k
    highbd_dr_prediction_z1_16xN_internal_avx2(8, dstvec, left, upsample_left,
3005
29.3k
                                               dy);
3006
29.3k
  } else {
3007
11.0k
    highbd_dr_prediction_32bit_z1_16xN_internal_avx2(8, dstvec, left,
3008
11.0k
                                                     upsample_left, dy);
3009
11.0k
  }
3010
40.3k
  highbd_transpose8x16_16x8_avx2(dstvec, d);
3011
363k
  for (int i = 0; i < 8; i++) {
3012
322k
    _mm_storeu_si128((__m128i *)(dst + i * stride),
3013
322k
                     _mm256_castsi256_si128(d[i]));
3014
322k
  }
3015
363k
  for (int i = 8; i < 16; i++) {
3016
322k
    _mm_storeu_si128((__m128i *)(dst + i * stride),
3017
322k
                     _mm256_extracti128_si256(d[i - 8], 1));
3018
322k
  }
3019
40.3k
}
3020
3021
static void highbd_dr_prediction_z3_16x8_avx2(uint16_t *dst, ptrdiff_t stride,
3022
                                              const uint16_t *left,
3023
                                              int upsample_left, int dy,
3024
65.8k
                                              int bd) {
3025
65.8k
  __m128i dstvec[16], d[16];
3026
65.8k
  if (bd < 12) {
3027
48.7k
    highbd_dr_prediction_z1_8xN_internal_avx2(16, dstvec, left, upsample_left,
3028
48.7k
                                              dy);
3029
48.7k
  } else {
3030
17.0k
    highbd_dr_prediction_32bit_z1_8xN_internal_avx2(16, dstvec, left,
3031
17.0k
                                                    upsample_left, dy);
3032
17.0k
  }
3033
197k
  for (int i = 0; i < 16; i += 8) {
3034
131k
    highbd_transpose8x8_sse2(&dstvec[0 + i], &dstvec[1 + i], &dstvec[2 + i],
3035
131k
                             &dstvec[3 + i], &dstvec[4 + i], &dstvec[5 + i],
3036
131k
                             &dstvec[6 + i], &dstvec[7 + i], &d[0 + i],
3037
131k
                             &d[1 + i], &d[2 + i], &d[3 + i], &d[4 + i],
3038
131k
                             &d[5 + i], &d[6 + i], &d[7 + i]);
3039
131k
  }
3040
592k
  for (int i = 0; i < 8; i++) {
3041
526k
    _mm_storeu_si128((__m128i *)(dst + i * stride), d[i]);
3042
526k
    _mm_storeu_si128((__m128i *)(dst + i * stride + 8), d[i + 8]);
3043
526k
  }
3044
65.8k
}
3045
3046
#if !CONFIG_REALTIME_ONLY || CONFIG_AV1_DECODER
3047
static void highbd_dr_prediction_z3_4x16_avx2(uint16_t *dst, ptrdiff_t stride,
3048
                                              const uint16_t *left,
3049
                                              int upsample_left, int dy,
3050
26.8k
                                              int bd) {
3051
26.8k
  __m256i dstvec[4], d[4], d1;
3052
26.8k
  if (bd < 12) {
3053
16.8k
    highbd_dr_prediction_z1_16xN_internal_avx2(4, dstvec, left, upsample_left,
3054
16.8k
                                               dy);
3055
16.8k
  } else {
3056
9.98k
    highbd_dr_prediction_32bit_z1_16xN_internal_avx2(4, dstvec, left,
3057
9.98k
                                                     upsample_left, dy);
3058
9.98k
  }
3059
26.8k
  highbd_transpose4x16_avx2(dstvec, d);
3060
134k
  for (int i = 0; i < 4; i++) {
3061
107k
    _mm_storel_epi64((__m128i *)(dst + i * stride),
3062
107k
                     _mm256_castsi256_si128(d[i]));
3063
107k
    d1 = _mm256_bsrli_epi128(d[i], 8);
3064
107k
    _mm_storel_epi64((__m128i *)(dst + (i + 4) * stride),
3065
107k
                     _mm256_castsi256_si128(d1));
3066
107k
    _mm_storel_epi64((__m128i *)(dst + (i + 8) * stride),
3067
107k
                     _mm256_extracti128_si256(d[i], 1));
3068
107k
    _mm_storel_epi64((__m128i *)(dst + (i + 12) * stride),
3069
107k
                     _mm256_extracti128_si256(d1, 1));
3070
107k
  }
3071
26.8k
}
3072
3073
static void highbd_dr_prediction_z3_16x4_avx2(uint16_t *dst, ptrdiff_t stride,
3074
                                              const uint16_t *left,
3075
                                              int upsample_left, int dy,
3076
69.5k
                                              int bd) {
3077
69.5k
  __m128i dstvec[16], d[8];
3078
69.5k
  if (bd < 12) {
3079
56.0k
    highbd_dr_prediction_z1_4xN_internal_avx2(16, dstvec, left, upsample_left,
3080
56.0k
                                              dy);
3081
56.0k
  } else {
3082
13.5k
    highbd_dr_prediction_32bit_z1_4xN_internal_avx2(16, dstvec, left,
3083
13.5k
                                                    upsample_left, dy);
3084
13.5k
  }
3085
69.5k
  highbd_transpose16x4_8x8_sse2(dstvec, d);
3086
3087
69.5k
  _mm_storeu_si128((__m128i *)(dst + 0 * stride), d[0]);
3088
69.5k
  _mm_storeu_si128((__m128i *)(dst + 0 * stride + 8), d[1]);
3089
69.5k
  _mm_storeu_si128((__m128i *)(dst + 1 * stride), d[2]);
3090
69.5k
  _mm_storeu_si128((__m128i *)(dst + 1 * stride + 8), d[3]);
3091
69.5k
  _mm_storeu_si128((__m128i *)(dst + 2 * stride), d[4]);
3092
69.5k
  _mm_storeu_si128((__m128i *)(dst + 2 * stride + 8), d[5]);
3093
69.5k
  _mm_storeu_si128((__m128i *)(dst + 3 * stride), d[6]);
3094
69.5k
  _mm_storeu_si128((__m128i *)(dst + 3 * stride + 8), d[7]);
3095
69.5k
}
3096
3097
static void highbd_dr_prediction_z3_8x32_avx2(uint16_t *dst, ptrdiff_t stride,
3098
                                              const uint16_t *left,
3099
                                              int upsample_left, int dy,
3100
15.0k
                                              int bd) {
3101
15.0k
  __m256i dstvec[16], d[16];
3102
15.0k
  if (bd < 12) {
3103
12.5k
    highbd_dr_prediction_z1_32xN_internal_avx2(8, dstvec, left, upsample_left,
3104
12.5k
                                               dy);
3105
12.5k
  } else {
3106
2.48k
    highbd_dr_prediction_32bit_z1_32xN_internal_avx2(8, dstvec, left,
3107
2.48k
                                                     upsample_left, dy);
3108
2.48k
  }
3109
3110
45.2k
  for (int i = 0; i < 16; i += 8) {
3111
30.1k
    highbd_transpose8x16_16x8_avx2(dstvec + i, d + i);
3112
30.1k
  }
3113
3114
135k
  for (int i = 0; i < 8; i++) {
3115
120k
    _mm_storeu_si128((__m128i *)(dst + i * stride),
3116
120k
                     _mm256_castsi256_si128(d[i]));
3117
120k
  }
3118
135k
  for (int i = 0; i < 8; i++) {
3119
120k
    _mm_storeu_si128((__m128i *)(dst + (i + 8) * stride),
3120
120k
                     _mm256_extracti128_si256(d[i], 1));
3121
120k
  }
3122
135k
  for (int i = 8; i < 16; i++) {
3123
120k
    _mm_storeu_si128((__m128i *)(dst + (i + 8) * stride),
3124
120k
                     _mm256_castsi256_si128(d[i]));
3125
120k
  }
3126
135k
  for (int i = 8; i < 16; i++) {
3127
120k
    _mm_storeu_si128((__m128i *)(dst + (i + 16) * stride),
3128
120k
                     _mm256_extracti128_si256(d[i], 1));
3129
120k
  }
3130
15.0k
}
3131
3132
static void highbd_dr_prediction_z3_32x8_avx2(uint16_t *dst, ptrdiff_t stride,
3133
                                              const uint16_t *left,
3134
                                              int upsample_left, int dy,
3135
60.5k
                                              int bd) {
3136
60.5k
  __m128i dstvec[32], d[32];
3137
60.5k
  if (bd < 12) {
3138
55.1k
    highbd_dr_prediction_z1_8xN_internal_avx2(32, dstvec, left, upsample_left,
3139
55.1k
                                              dy);
3140
55.1k
  } else {
3141
5.41k
    highbd_dr_prediction_32bit_z1_8xN_internal_avx2(32, dstvec, left,
3142
5.41k
                                                    upsample_left, dy);
3143
5.41k
  }
3144
3145
302k
  for (int i = 0; i < 32; i += 8) {
3146
242k
    highbd_transpose8x8_sse2(&dstvec[0 + i], &dstvec[1 + i], &dstvec[2 + i],
3147
242k
                             &dstvec[3 + i], &dstvec[4 + i], &dstvec[5 + i],
3148
242k
                             &dstvec[6 + i], &dstvec[7 + i], &d[0 + i],
3149
242k
                             &d[1 + i], &d[2 + i], &d[3 + i], &d[4 + i],
3150
242k
                             &d[5 + i], &d[6 + i], &d[7 + i]);
3151
242k
  }
3152
545k
  for (int i = 0; i < 8; i++) {
3153
484k
    _mm_storeu_si128((__m128i *)(dst + i * stride), d[i]);
3154
484k
    _mm_storeu_si128((__m128i *)(dst + i * stride + 8), d[i + 8]);
3155
484k
    _mm_storeu_si128((__m128i *)(dst + i * stride + 16), d[i + 16]);
3156
484k
    _mm_storeu_si128((__m128i *)(dst + i * stride + 24), d[i + 24]);
3157
484k
  }
3158
60.5k
}
3159
#endif  // !CONFIG_REALTIME_ONLY || CONFIG_AV1_DECODER
3160
3161
static void highbd_dr_prediction_z3_16x16_avx2(uint16_t *dst, ptrdiff_t stride,
3162
                                               const uint16_t *left,
3163
                                               int upsample_left, int dy,
3164
117k
                                               int bd) {
3165
117k
  __m256i dstvec[16], d[16];
3166
117k
  if (bd < 12) {
3167
103k
    highbd_dr_prediction_z1_16xN_internal_avx2(16, dstvec, left, upsample_left,
3168
103k
                                               dy);
3169
103k
  } else {
3170
13.2k
    highbd_dr_prediction_32bit_z1_16xN_internal_avx2(16, dstvec, left,
3171
13.2k
                                                     upsample_left, dy);
3172
13.2k
  }
3173
3174
117k
  highbd_transpose16x16_avx2(dstvec, d);
3175
3176
1.99M
  for (int i = 0; i < 16; i++) {
3177
1.87M
    _mm256_storeu_si256((__m256i *)(dst + i * stride), d[i]);
3178
1.87M
  }
3179
117k
}
3180
3181
static void highbd_dr_prediction_z3_32x32_avx2(uint16_t *dst, ptrdiff_t stride,
3182
                                               const uint16_t *left,
3183
                                               int upsample_left, int dy,
3184
88.8k
                                               int bd) {
3185
88.8k
  __m256i dstvec[64], d[16];
3186
88.8k
  if (bd < 12) {
3187
83.2k
    highbd_dr_prediction_z1_32xN_internal_avx2(32, dstvec, left, upsample_left,
3188
83.2k
                                               dy);
3189
83.2k
  } else {
3190
5.60k
    highbd_dr_prediction_32bit_z1_32xN_internal_avx2(32, dstvec, left,
3191
5.60k
                                                     upsample_left, dy);
3192
5.60k
  }
3193
88.8k
  highbd_transpose16x16_avx2(dstvec, d);
3194
1.51M
  for (int j = 0; j < 16; j++) {
3195
1.42M
    _mm256_storeu_si256((__m256i *)(dst + j * stride), d[j]);
3196
1.42M
  }
3197
88.8k
  highbd_transpose16x16_avx2(dstvec + 16, d);
3198
1.51M
  for (int j = 0; j < 16; j++) {
3199
1.42M
    _mm256_storeu_si256((__m256i *)(dst + j * stride + 16), d[j]);
3200
1.42M
  }
3201
88.8k
  highbd_transpose16x16_avx2(dstvec + 32, d);
3202
1.51M
  for (int j = 0; j < 16; j++) {
3203
1.42M
    _mm256_storeu_si256((__m256i *)(dst + (j + 16) * stride), d[j]);
3204
1.42M
  }
3205
88.8k
  highbd_transpose16x16_avx2(dstvec + 48, d);
3206
1.51M
  for (int j = 0; j < 16; j++) {
3207
1.42M
    _mm256_storeu_si256((__m256i *)(dst + (j + 16) * stride + 16), d[j]);
3208
1.42M
  }
3209
88.8k
}
3210
3211
static void highbd_dr_prediction_z3_64x64_avx2(uint16_t *dst, ptrdiff_t stride,
3212
                                               const uint16_t *left,
3213
                                               int upsample_left, int dy,
3214
25.7k
                                               int bd) {
3215
25.7k
  DECLARE_ALIGNED(16, uint16_t, dstT[64 * 64]);
3216
25.7k
  if (bd < 12) {
3217
22.3k
    highbd_dr_prediction_z1_64xN_avx2(64, dstT, 64, left, upsample_left, dy);
3218
22.3k
  } else {
3219
3.47k
    highbd_dr_prediction_32bit_z1_64xN_avx2(64, dstT, 64, left, upsample_left,
3220
3.47k
                                            dy);
3221
3.47k
  }
3222
25.7k
  highbd_transpose(dstT, 64, dst, stride, 64, 64);
3223
25.7k
}
3224
3225
static void highbd_dr_prediction_z3_16x32_avx2(uint16_t *dst, ptrdiff_t stride,
3226
                                               const uint16_t *left,
3227
                                               int upsample_left, int dy,
3228
29.1k
                                               int bd) {
3229
29.1k
  __m256i dstvec[32], d[32];
3230
29.1k
  if (bd < 12) {
3231
26.9k
    highbd_dr_prediction_z1_32xN_internal_avx2(16, dstvec, left, upsample_left,
3232
26.9k
                                               dy);
3233
26.9k
  } else {
3234
2.22k
    highbd_dr_prediction_32bit_z1_32xN_internal_avx2(16, dstvec, left,
3235
2.22k
                                                     upsample_left, dy);
3236
2.22k
  }
3237
145k
  for (int i = 0; i < 32; i += 8) {
3238
116k
    highbd_transpose8x16_16x8_avx2(dstvec + i, d + i);
3239
116k
  }
3240
  // store
3241
87.5k
  for (int j = 0; j < 32; j += 16) {
3242
525k
    for (int i = 0; i < 8; i++) {
3243
466k
      _mm_storeu_si128((__m128i *)(dst + (i + j) * stride),
3244
466k
                       _mm256_castsi256_si128(d[(i + j)]));
3245
466k
    }
3246
525k
    for (int i = 0; i < 8; i++) {
3247
466k
      _mm_storeu_si128((__m128i *)(dst + (i + j) * stride + 8),
3248
466k
                       _mm256_castsi256_si128(d[(i + j) + 8]));
3249
466k
    }
3250
525k
    for (int i = 8; i < 16; i++) {
3251
466k
      _mm256_storeu_si256(
3252
466k
          (__m256i *)(dst + (i + j) * stride),
3253
466k
          _mm256_inserti128_si256(
3254
466k
              d[(i + j)], _mm256_extracti128_si256(d[(i + j) - 8], 1), 0));
3255
466k
    }
3256
58.3k
  }
3257
29.1k
}
3258
3259
static void highbd_dr_prediction_z3_32x16_avx2(uint16_t *dst, ptrdiff_t stride,
3260
                                               const uint16_t *left,
3261
                                               int upsample_left, int dy,
3262
29.1k
                                               int bd) {
3263
29.1k
  __m256i dstvec[32], d[16];
3264
29.1k
  if (bd < 12) {
3265
26.9k
    highbd_dr_prediction_z1_16xN_internal_avx2(32, dstvec, left, upsample_left,
3266
26.9k
                                               dy);
3267
26.9k
  } else {
3268
2.20k
    highbd_dr_prediction_32bit_z1_16xN_internal_avx2(32, dstvec, left,
3269
2.20k
                                                     upsample_left, dy);
3270
2.20k
  }
3271
87.4k
  for (int i = 0; i < 32; i += 16) {
3272
58.3k
    highbd_transpose16x16_avx2((dstvec + i), d);
3273
991k
    for (int j = 0; j < 16; j++) {
3274
932k
      _mm256_storeu_si256((__m256i *)(dst + j * stride + i), d[j]);
3275
932k
    }
3276
58.3k
  }
3277
29.1k
}
3278
3279
static void highbd_dr_prediction_z3_32x64_avx2(uint16_t *dst, ptrdiff_t stride,
3280
                                               const uint16_t *left,
3281
                                               int upsample_left, int dy,
3282
2.35k
                                               int bd) {
3283
2.35k
  uint16_t dstT[64 * 32];
3284
2.35k
  if (bd < 12) {
3285
2.06k
    highbd_dr_prediction_z1_64xN_avx2(32, dstT, 64, left, upsample_left, dy);
3286
2.06k
  } else {
3287
291
    highbd_dr_prediction_32bit_z1_64xN_avx2(32, dstT, 64, left, upsample_left,
3288
291
                                            dy);
3289
291
  }
3290
2.35k
  highbd_transpose(dstT, 64, dst, stride, 32, 64);
3291
2.35k
}
3292
3293
static void highbd_dr_prediction_z3_64x32_avx2(uint16_t *dst, ptrdiff_t stride,
3294
                                               const uint16_t *left,
3295
                                               int upsample_left, int dy,
3296
3.65k
                                               int bd) {
3297
3.65k
  DECLARE_ALIGNED(16, uint16_t, dstT[32 * 64]);
3298
3.65k
  highbd_dr_prediction_z1_32xN_avx2(64, dstT, 32, left, upsample_left, dy, bd);
3299
3.65k
  highbd_transpose(dstT, 32, dst, stride, 64, 32);
3300
3.65k
  return;
3301
3.65k
}
3302
3303
#if !CONFIG_REALTIME_ONLY || CONFIG_AV1_DECODER
3304
static void highbd_dr_prediction_z3_16x64_avx2(uint16_t *dst, ptrdiff_t stride,
3305
                                               const uint16_t *left,
3306
                                               int upsample_left, int dy,
3307
6.00k
                                               int bd) {
3308
6.00k
  DECLARE_ALIGNED(16, uint16_t, dstT[64 * 16]);
3309
6.00k
  if (bd < 12) {
3310
5.37k
    highbd_dr_prediction_z1_64xN_avx2(16, dstT, 64, left, upsample_left, dy);
3311
5.37k
  } else {
3312
629
    highbd_dr_prediction_32bit_z1_64xN_avx2(16, dstT, 64, left, upsample_left,
3313
629
                                            dy);
3314
629
  }
3315
6.00k
  highbd_transpose(dstT, 64, dst, stride, 16, 64);
3316
6.00k
}
3317
3318
static void highbd_dr_prediction_z3_64x16_avx2(uint16_t *dst, ptrdiff_t stride,
3319
                                               const uint16_t *left,
3320
                                               int upsample_left, int dy,
3321
21.2k
                                               int bd) {
3322
21.2k
  __m256i dstvec[64], d[16];
3323
21.2k
  if (bd < 12) {
3324
20.5k
    highbd_dr_prediction_z1_16xN_internal_avx2(64, dstvec, left, upsample_left,
3325
20.5k
                                               dy);
3326
20.5k
  } else {
3327
718
    highbd_dr_prediction_32bit_z1_16xN_internal_avx2(64, dstvec, left,
3328
718
                                                     upsample_left, dy);
3329
718
  }
3330
106k
  for (int i = 0; i < 64; i += 16) {
3331
84.8k
    highbd_transpose16x16_avx2((dstvec + i), d);
3332
1.44M
    for (int j = 0; j < 16; j++) {
3333
1.35M
      _mm256_storeu_si256((__m256i *)(dst + j * stride + i), d[j]);
3334
1.35M
    }
3335
84.8k
  }
3336
21.2k
}
3337
#endif  // !CONFIG_REALTIME_ONLY || CONFIG_AV1_DECODER
3338
3339
void av1_highbd_dr_prediction_z3_avx2(uint16_t *dst, ptrdiff_t stride, int bw,
3340
                                      int bh, const uint16_t *above,
3341
                                      const uint16_t *left, int upsample_left,
3342
1.01M
                                      int dx, int dy, int bd) {
3343
1.01M
  (void)above;
3344
1.01M
  (void)dx;
3345
3346
1.01M
  assert(dx == 1);
3347
1.01M
  assert(dy > 0);
3348
1.01M
  if (bw == bh) {
3349
559k
    switch (bw) {
3350
171k
      case 4:
3351
171k
        highbd_dr_prediction_z3_4x4_avx2(dst, stride, left, upsample_left, dy,
3352
171k
                                         bd);
3353
171k
        break;
3354
156k
      case 8:
3355
156k
        highbd_dr_prediction_z3_8x8_avx2(dst, stride, left, upsample_left, dy,
3356
156k
                                         bd);
3357
156k
        break;
3358
117k
      case 16:
3359
117k
        highbd_dr_prediction_z3_16x16_avx2(dst, stride, left, upsample_left, dy,
3360
117k
                                           bd);
3361
117k
        break;
3362
88.8k
      case 32:
3363
88.8k
        highbd_dr_prediction_z3_32x32_avx2(dst, stride, left, upsample_left, dy,
3364
88.8k
                                           bd);
3365
88.8k
        break;
3366
25.7k
      case 64:
3367
25.7k
        highbd_dr_prediction_z3_64x64_avx2(dst, stride, left, upsample_left, dy,
3368
25.7k
                                           bd);
3369
25.7k
        break;
3370
559k
    }
3371
559k
  } else {
3372
454k
    if (bw < bh) {
3373
146k
      if (bw + bw == bh) {
3374
98.8k
        switch (bw) {
3375
26.9k
          case 4:
3376
26.9k
            highbd_dr_prediction_z3_4x8_avx2(dst, stride, left, upsample_left,
3377
26.9k
                                             dy, bd);
3378
26.9k
            break;
3379
40.3k
          case 8:
3380
40.3k
            highbd_dr_prediction_z3_8x16_avx2(dst, stride, left, upsample_left,
3381
40.3k
                                              dy, bd);
3382
40.3k
            break;
3383
29.1k
          case 16:
3384
29.1k
            highbd_dr_prediction_z3_16x32_avx2(dst, stride, left, upsample_left,
3385
29.1k
                                               dy, bd);
3386
29.1k
            break;
3387
2.35k
          case 32:
3388
2.35k
            highbd_dr_prediction_z3_32x64_avx2(dst, stride, left, upsample_left,
3389
2.35k
                                               dy, bd);
3390
2.35k
            break;
3391
98.8k
        }
3392
98.8k
      } else {
3393
47.9k
        switch (bw) {
3394
0
#if !CONFIG_REALTIME_ONLY || CONFIG_AV1_DECODER
3395
26.8k
          case 4:
3396
26.8k
            highbd_dr_prediction_z3_4x16_avx2(dst, stride, left, upsample_left,
3397
26.8k
                                              dy, bd);
3398
26.8k
            break;
3399
15.0k
          case 8:
3400
15.0k
            highbd_dr_prediction_z3_8x32_avx2(dst, stride, left, upsample_left,
3401
15.0k
                                              dy, bd);
3402
15.0k
            break;
3403
6.00k
          case 16:
3404
6.00k
            highbd_dr_prediction_z3_16x64_avx2(dst, stride, left, upsample_left,
3405
6.00k
                                               dy, bd);
3406
6.00k
            break;
3407
47.9k
#endif  // !CONFIG_REALTIME_ONLY || CONFIG_AV1_DECODER
3408
47.9k
        }
3409
47.9k
      }
3410
307k
    } else {
3411
307k
      if (bh + bh == bw) {
3412
156k
        switch (bh) {
3413
57.4k
          case 4:
3414
57.4k
            highbd_dr_prediction_z3_8x4_avx2(dst, stride, left, upsample_left,
3415
57.4k
                                             dy, bd);
3416
57.4k
            break;
3417
65.8k
          case 8:
3418
65.8k
            highbd_dr_prediction_z3_16x8_avx2(dst, stride, left, upsample_left,
3419
65.8k
                                              dy, bd);
3420
65.8k
            break;
3421
29.1k
          case 16:
3422
29.1k
            highbd_dr_prediction_z3_32x16_avx2(dst, stride, left, upsample_left,
3423
29.1k
                                               dy, bd);
3424
29.1k
            break;
3425
3.65k
          case 32:
3426
3.65k
            highbd_dr_prediction_z3_64x32_avx2(dst, stride, left, upsample_left,
3427
3.65k
                                               dy, bd);
3428
3.65k
            break;
3429
156k
        }
3430
156k
      } else {
3431
151k
        switch (bh) {
3432
0
#if !CONFIG_REALTIME_ONLY || CONFIG_AV1_DECODER
3433
69.5k
          case 4:
3434
69.5k
            highbd_dr_prediction_z3_16x4_avx2(dst, stride, left, upsample_left,
3435
69.5k
                                              dy, bd);
3436
69.5k
            break;
3437
60.5k
          case 8:
3438
60.5k
            highbd_dr_prediction_z3_32x8_avx2(dst, stride, left, upsample_left,
3439
60.5k
                                              dy, bd);
3440
60.5k
            break;
3441
21.2k
          case 16:
3442
21.2k
            highbd_dr_prediction_z3_64x16_avx2(dst, stride, left, upsample_left,
3443
21.2k
                                               dy, bd);
3444
21.2k
            break;
3445
151k
#endif  // !CONFIG_REALTIME_ONLY || CONFIG_AV1_DECODER
3446
151k
        }
3447
151k
      }
3448
307k
    }
3449
454k
  }
3450
1.01M
  return;
3451
1.01M
}
3452
#endif  // CONFIG_AV1_HIGHBITDEPTH
3453
3454
// Low bit depth functions
3455
static DECLARE_ALIGNED(32, uint8_t, BaseMask[33][32]) = {
3456
  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3457
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
3458
  { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3459
    0,    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
3460
  { 0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3461
    0,    0,    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
3462
  { 0xff, 0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3463
    0,    0,    0,    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
3464
  { 0xff, 0xff, 0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3465
    0,    0,    0,    0,    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
3466
  { 0xff, 0xff, 0xff, 0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3467
    0,    0,    0,    0,    0,    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
3468
  { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3469
    0,    0,    0,    0,    0,    0,    0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
3470
  { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3471
    0,    0,    0,    0,    0,    0,    0,    0, 0, 0, 0, 0, 0, 0, 0, 0 },
3472
  { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0,
3473
    0,    0,    0,    0,    0,    0,    0,    0,    0, 0, 0, 0, 0, 0, 0, 0 },
3474
  { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0, 0, 0, 0, 0, 0, 0,
3475
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0, 0, 0, 0, 0, 0, 0 },
3476
  { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0,
3477
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
3478
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0 },
3479
  { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3480
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
3481
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0 },
3482
  { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3483
    0xff, 0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
3484
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0 },
3485
  { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3486
    0xff, 0xff, 0,    0,    0,    0,    0,    0,    0,    0,    0,
3487
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0 },
3488
  { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3489
    0xff, 0xff, 0xff, 0,    0,    0,    0,    0,    0,    0,    0,
3490
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0 },
3491
  { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3492
    0xff, 0xff, 0xff, 0xff, 0,    0,    0,    0,    0,    0,    0,
3493
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0 },
3494
  { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3495
    0xff, 0xff, 0xff, 0xff, 0xff, 0,    0,    0,    0,    0,    0,
3496
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0 },
3497
  { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3498
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0,    0,    0,    0,    0,
3499
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0 },
3500
  { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3501
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0,    0,    0,    0,
3502
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0 },
3503
  { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3504
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0,    0,    0,
3505
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0 },
3506
  { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3507
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0,    0,
3508
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0 },
3509
  { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3510
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0,
3511
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0 },
3512
  { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3513
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3514
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0 },
3515
  { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3516
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3517
    0xff, 0,    0,    0,    0,    0,    0,    0,    0,    0 },
3518
  { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3519
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3520
    0xff, 0xff, 0,    0,    0,    0,    0,    0,    0,    0 },
3521
  { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3522
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3523
    0xff, 0xff, 0xff, 0,    0,    0,    0,    0,    0,    0 },
3524
  { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3525
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3526
    0xff, 0xff, 0xff, 0xff, 0,    0,    0,    0,    0,    0 },
3527
  { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3528
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3529
    0xff, 0xff, 0xff, 0xff, 0xff, 0,    0,    0,    0,    0 },
3530
  { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3531
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3532
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0,    0,    0,    0 },
3533
  { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3534
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3535
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0,    0,    0 },
3536
  { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3537
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3538
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0,    0 },
3539
  { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3540
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3541
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0 },
3542
  { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3543
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3544
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
3545
};
3546
3547
/* clang-format on */
3548
static AOM_FORCE_INLINE void dr_prediction_z1_HxW_internal_avx2(
3549
    int H, int W, __m128i *dst, const uint8_t *above, int upsample_above,
3550
872k
    int dx) {
3551
872k
  const int frac_bits = 6 - upsample_above;
3552
872k
  const int max_base_x = ((W + H) - 1) << upsample_above;
3553
3554
872k
  assert(dx > 0);
3555
  // pre-filter above pixels
3556
  // store in temp buffers:
3557
  //   above[x] * 32 + 16
3558
  //   above[x+1] - above[x]
3559
  // final pixels will be calculated as:
3560
  //   (above[x] * 32 + 16 + (above[x+1] - above[x]) * shift) >> 5
3561
872k
  __m256i a0, a1, a32, a16;
3562
872k
  __m256i diff, c3f;
3563
872k
  __m128i a_mbase_x;
3564
3565
872k
  a16 = _mm256_set1_epi16(16);
3566
872k
  a_mbase_x = _mm_set1_epi8((int8_t)above[max_base_x]);
3567
872k
  c3f = _mm256_set1_epi16(0x3f);
3568
3569
872k
  int x = dx;
3570
11.3M
  for (int r = 0; r < W; r++) {
3571
10.4M
    __m256i b, res, shift;
3572
10.4M
    __m128i res1, a0_128, a1_128;
3573
3574
10.4M
    int base = x >> frac_bits;
3575
10.4M
    int base_max_diff = (max_base_x - base) >> upsample_above;
3576
10.4M
    if (base_max_diff <= 0) {
3577
15.5k
      for (int i = r; i < W; ++i) {
3578
10.7k
        dst[i] = a_mbase_x;  // save 4 values
3579
10.7k
      }
3580
4.77k
      return;
3581
4.77k
    }
3582
10.4M
    if (base_max_diff > H) base_max_diff = H;
3583
10.4M
    a0_128 = _mm_loadu_si128((__m128i *)(above + base));
3584
10.4M
    a1_128 = _mm_loadu_si128((__m128i *)(above + base + 1));
3585
3586
10.4M
    if (upsample_above) {
3587
1.53M
      a0_128 = _mm_shuffle_epi8(a0_128, *(__m128i *)EvenOddMaskx[0]);
3588
1.53M
      a1_128 = _mm_srli_si128(a0_128, 8);
3589
3590
1.53M
      shift = _mm256_srli_epi16(
3591
1.53M
          _mm256_and_si256(
3592
1.53M
              _mm256_slli_epi16(_mm256_set1_epi16(x), upsample_above), c3f),
3593
1.53M
          1);
3594
8.90M
    } else {
3595
8.90M
      shift = _mm256_srli_epi16(_mm256_and_si256(_mm256_set1_epi16(x), c3f), 1);
3596
8.90M
    }
3597
10.4M
    a0 = _mm256_cvtepu8_epi16(a0_128);
3598
10.4M
    a1 = _mm256_cvtepu8_epi16(a1_128);
3599
3600
10.4M
    diff = _mm256_sub_epi16(a1, a0);   // a[x+1] - a[x]
3601
10.4M
    a32 = _mm256_slli_epi16(a0, 5);    // a[x] * 32
3602
10.4M
    a32 = _mm256_add_epi16(a32, a16);  // a[x] * 32 + 16
3603
3604
10.4M
    b = _mm256_mullo_epi16(diff, shift);
3605
10.4M
    res = _mm256_add_epi16(a32, b);
3606
10.4M
    res = _mm256_srli_epi16(res, 5);
3607
3608
10.4M
    res = _mm256_packus_epi16(
3609
10.4M
        res, _mm256_castsi128_si256(
3610
10.4M
                 _mm256_extracti128_si256(res, 1)));  // goto 8 bit
3611
10.4M
    res1 = _mm256_castsi256_si128(res);               // 16 8bit values
3612
3613
10.4M
    dst[r] =
3614
10.4M
        _mm_blendv_epi8(a_mbase_x, res1, *(__m128i *)BaseMask[base_max_diff]);
3615
10.4M
    x += dx;
3616
10.4M
  }
3617
872k
}
3618
3619
static void dr_prediction_z1_4xN_avx2(int N, uint8_t *dst, ptrdiff_t stride,
3620
                                      const uint8_t *above, int upsample_above,
3621
138k
                                      int dx) {
3622
138k
  __m128i dstvec[16];
3623
3624
138k
  dr_prediction_z1_HxW_internal_avx2(4, N, dstvec, above, upsample_above, dx);
3625
917k
  for (int i = 0; i < N; i++) {
3626
778k
    *(int *)(dst + stride * i) = _mm_cvtsi128_si32(dstvec[i]);
3627
778k
  }
3628
138k
}
3629
3630
static void dr_prediction_z1_8xN_avx2(int N, uint8_t *dst, ptrdiff_t stride,
3631
                                      const uint8_t *above, int upsample_above,
3632
111k
                                      int dx) {
3633
111k
  __m128i dstvec[32];
3634
3635
111k
  dr_prediction_z1_HxW_internal_avx2(8, N, dstvec, above, upsample_above, dx);
3636
1.26M
  for (int i = 0; i < N; i++) {
3637
1.15M
    _mm_storel_epi64((__m128i *)(dst + stride * i), dstvec[i]);
3638
1.15M
  }
3639
111k
}
3640
3641
static void dr_prediction_z1_16xN_avx2(int N, uint8_t *dst, ptrdiff_t stride,
3642
                                       const uint8_t *above, int upsample_above,
3643
110k
                                       int dx) {
3644
110k
  __m128i dstvec[64];
3645
3646
110k
  dr_prediction_z1_HxW_internal_avx2(16, N, dstvec, above, upsample_above, dx);
3647
1.70M
  for (int i = 0; i < N; i++) {
3648
1.59M
    _mm_storeu_si128((__m128i *)(dst + stride * i), dstvec[i]);
3649
1.59M
  }
3650
110k
}
3651
3652
static AOM_FORCE_INLINE void dr_prediction_z1_32xN_internal_avx2(
3653
164k
    int N, __m256i *dstvec, const uint8_t *above, int upsample_above, int dx) {
3654
  // here upsample_above is 0 by design of av1_use_intra_edge_upsample
3655
164k
  (void)upsample_above;
3656
164k
  const int frac_bits = 6;
3657
164k
  const int max_base_x = ((32 + N) - 1);
3658
3659
  // pre-filter above pixels
3660
  // store in temp buffers:
3661
  //   above[x] * 32 + 16
3662
  //   above[x+1] - above[x]
3663
  // final pixels will be calculated as:
3664
  //   (above[x] * 32 + 16 + (above[x+1] - above[x]) * shift) >> 5
3665
164k
  __m256i a0, a1, a32, a16;
3666
164k
  __m256i a_mbase_x, diff, c3f;
3667
3668
164k
  a16 = _mm256_set1_epi16(16);
3669
164k
  a_mbase_x = _mm256_set1_epi8((int8_t)above[max_base_x]);
3670
164k
  c3f = _mm256_set1_epi16(0x3f);
3671
3672
164k
  int x = dx;
3673
4.61M
  for (int r = 0; r < N; r++) {
3674
4.45M
    __m256i b, res, res16[2];
3675
4.45M
    __m128i a0_128, a1_128;
3676
3677
4.45M
    int base = x >> frac_bits;
3678
4.45M
    int base_max_diff = (max_base_x - base);
3679
4.45M
    if (base_max_diff <= 0) {
3680
0
      for (int i = r; i < N; ++i) {
3681
0
        dstvec[i] = a_mbase_x;  // save 32 values
3682
0
      }
3683
0
      return;
3684
0
    }
3685
4.45M
    if (base_max_diff > 32) base_max_diff = 32;
3686
4.45M
    __m256i shift =
3687
4.45M
        _mm256_srli_epi16(_mm256_and_si256(_mm256_set1_epi16(x), c3f), 1);
3688
3689
13.3M
    for (int j = 0, jj = 0; j < 32; j += 16, jj++) {
3690
8.90M
      int mdiff = base_max_diff - j;
3691
8.90M
      if (mdiff <= 0) {
3692
785
        res16[jj] = a_mbase_x;
3693
8.90M
      } else {
3694
8.90M
        a0_128 = _mm_loadu_si128((__m128i *)(above + base + j));
3695
8.90M
        a1_128 = _mm_loadu_si128((__m128i *)(above + base + j + 1));
3696
8.90M
        a0 = _mm256_cvtepu8_epi16(a0_128);
3697
8.90M
        a1 = _mm256_cvtepu8_epi16(a1_128);
3698
3699
8.90M
        diff = _mm256_sub_epi16(a1, a0);   // a[x+1] - a[x]
3700
8.90M
        a32 = _mm256_slli_epi16(a0, 5);    // a[x] * 32
3701
8.90M
        a32 = _mm256_add_epi16(a32, a16);  // a[x] * 32 + 16
3702
8.90M
        b = _mm256_mullo_epi16(diff, shift);
3703
3704
8.90M
        res = _mm256_add_epi16(a32, b);
3705
8.90M
        res = _mm256_srli_epi16(res, 5);
3706
8.90M
        res16[jj] = _mm256_packus_epi16(
3707
8.90M
            res, _mm256_castsi128_si256(
3708
8.90M
                     _mm256_extracti128_si256(res, 1)));  // 16 8bit values
3709
8.90M
      }
3710
8.90M
    }
3711
4.45M
    res16[1] =
3712
4.45M
        _mm256_inserti128_si256(res16[0], _mm256_castsi256_si128(res16[1]),
3713
4.45M
                                1);  // 32 8bit values
3714
3715
4.45M
    dstvec[r] = _mm256_blendv_epi8(
3716
4.45M
        a_mbase_x, res16[1],
3717
4.45M
        *(__m256i *)BaseMask[base_max_diff]);  // 32 8bit values
3718
4.45M
    x += dx;
3719
4.45M
  }
3720
164k
}
3721
3722
static void dr_prediction_z1_32xN_avx2(int N, uint8_t *dst, ptrdiff_t stride,
3723
                                       const uint8_t *above, int upsample_above,
3724
65.5k
                                       int dx) {
3725
65.5k
  __m256i dstvec[64];
3726
65.5k
  dr_prediction_z1_32xN_internal_avx2(N, dstvec, above, upsample_above, dx);
3727
1.89M
  for (int i = 0; i < N; i++) {
3728
1.82M
    _mm256_storeu_si256((__m256i *)(dst + stride * i), dstvec[i]);
3729
1.82M
  }
3730
65.5k
}
3731
3732
static void dr_prediction_z1_64xN_avx2(int N, uint8_t *dst, ptrdiff_t stride,
3733
                                       const uint8_t *above, int upsample_above,
3734
37.6k
                                       int dx) {
3735
  // here upsample_above is 0 by design of av1_use_intra_edge_upsample
3736
37.6k
  (void)upsample_above;
3737
37.6k
  const int frac_bits = 6;
3738
37.6k
  const int max_base_x = ((64 + N) - 1);
3739
3740
  // pre-filter above pixels
3741
  // store in temp buffers:
3742
  //   above[x] * 32 + 16
3743
  //   above[x+1] - above[x]
3744
  // final pixels will be calculated as:
3745
  //   (above[x] * 32 + 16 + (above[x+1] - above[x]) * shift) >> 5
3746
37.6k
  __m256i a0, a1, a32, a16;
3747
37.6k
  __m256i a_mbase_x, diff, c3f;
3748
37.6k
  __m128i max_base_x128, base_inc128, mask128;
3749
3750
37.6k
  a16 = _mm256_set1_epi16(16);
3751
37.6k
  a_mbase_x = _mm256_set1_epi8((int8_t)above[max_base_x]);
3752
37.6k
  max_base_x128 = _mm_set1_epi8(max_base_x);
3753
37.6k
  c3f = _mm256_set1_epi16(0x3f);
3754
3755
37.6k
  int x = dx;
3756
1.99M
  for (int r = 0; r < N; r++, dst += stride) {
3757
1.95M
    __m256i b, res;
3758
1.95M
    int base = x >> frac_bits;
3759
1.95M
    if (base >= max_base_x) {
3760
0
      for (int i = r; i < N; ++i) {
3761
0
        _mm256_storeu_si256((__m256i *)dst, a_mbase_x);  // save 32 values
3762
0
        _mm256_storeu_si256((__m256i *)(dst + 32), a_mbase_x);
3763
0
        dst += stride;
3764
0
      }
3765
0
      return;
3766
0
    }
3767
3768
1.95M
    __m256i shift =
3769
1.95M
        _mm256_srli_epi16(_mm256_and_si256(_mm256_set1_epi16(x), c3f), 1);
3770
3771
1.95M
    __m128i a0_128, a1_128, res128;
3772
9.76M
    for (int j = 0; j < 64; j += 16) {
3773
7.81M
      int mdif = max_base_x - (base + j);
3774
7.81M
      if (mdif <= 0) {
3775
2.66k
        _mm_storeu_si128((__m128i *)(dst + j),
3776
2.66k
                         _mm256_castsi256_si128(a_mbase_x));
3777
7.80M
      } else {
3778
7.80M
        a0_128 = _mm_loadu_si128((__m128i *)(above + base + j));
3779
7.80M
        a1_128 = _mm_loadu_si128((__m128i *)(above + base + 1 + j));
3780
7.80M
        a0 = _mm256_cvtepu8_epi16(a0_128);
3781
7.80M
        a1 = _mm256_cvtepu8_epi16(a1_128);
3782
3783
7.80M
        diff = _mm256_sub_epi16(a1, a0);   // a[x+1] - a[x]
3784
7.80M
        a32 = _mm256_slli_epi16(a0, 5);    // a[x] * 32
3785
7.80M
        a32 = _mm256_add_epi16(a32, a16);  // a[x] * 32 + 16
3786
7.80M
        b = _mm256_mullo_epi16(diff, shift);
3787
3788
7.80M
        res = _mm256_add_epi16(a32, b);
3789
7.80M
        res = _mm256_srli_epi16(res, 5);
3790
7.80M
        res = _mm256_packus_epi16(
3791
7.80M
            res, _mm256_castsi128_si256(
3792
7.80M
                     _mm256_extracti128_si256(res, 1)));  // 16 8bit values
3793
3794
7.80M
        base_inc128 =
3795
7.80M
            _mm_setr_epi8((int8_t)(base + j), (int8_t)(base + j + 1),
3796
7.80M
                          (int8_t)(base + j + 2), (int8_t)(base + j + 3),
3797
7.80M
                          (int8_t)(base + j + 4), (int8_t)(base + j + 5),
3798
7.80M
                          (int8_t)(base + j + 6), (int8_t)(base + j + 7),
3799
7.80M
                          (int8_t)(base + j + 8), (int8_t)(base + j + 9),
3800
7.80M
                          (int8_t)(base + j + 10), (int8_t)(base + j + 11),
3801
7.80M
                          (int8_t)(base + j + 12), (int8_t)(base + j + 13),
3802
7.80M
                          (int8_t)(base + j + 14), (int8_t)(base + j + 15));
3803
3804
7.80M
        mask128 = _mm_cmpgt_epi8(_mm_subs_epu8(max_base_x128, base_inc128),
3805
7.80M
                                 _mm_setzero_si128());
3806
7.80M
        res128 = _mm_blendv_epi8(_mm256_castsi256_si128(a_mbase_x),
3807
7.80M
                                 _mm256_castsi256_si128(res), mask128);
3808
7.80M
        _mm_storeu_si128((__m128i *)(dst + j), res128);
3809
7.80M
      }
3810
7.81M
    }
3811
1.95M
    x += dx;
3812
1.95M
  }
3813
37.6k
}
3814
3815
// Directional prediction, zone 1: 0 < angle < 90
3816
void av1_dr_prediction_z1_avx2(uint8_t *dst, ptrdiff_t stride, int bw, int bh,
3817
                               const uint8_t *above, const uint8_t *left,
3818
435k
                               int upsample_above, int dx, int dy) {
3819
435k
  (void)left;
3820
435k
  (void)dy;
3821
435k
  switch (bw) {
3822
138k
    case 4:
3823
138k
      dr_prediction_z1_4xN_avx2(bh, dst, stride, above, upsample_above, dx);
3824
138k
      break;
3825
111k
    case 8:
3826
111k
      dr_prediction_z1_8xN_avx2(bh, dst, stride, above, upsample_above, dx);
3827
111k
      break;
3828
110k
    case 16:
3829
110k
      dr_prediction_z1_16xN_avx2(bh, dst, stride, above, upsample_above, dx);
3830
110k
      break;
3831
62.8k
    case 32:
3832
62.8k
      dr_prediction_z1_32xN_avx2(bh, dst, stride, above, upsample_above, dx);
3833
62.8k
      break;
3834
12.2k
    case 64:
3835
12.2k
      dr_prediction_z1_64xN_avx2(bh, dst, stride, above, upsample_above, dx);
3836
12.2k
      break;
3837
0
    default: break;
3838
435k
  }
3839
435k
  return;
3840
435k
}
3841
3842
static void dr_prediction_z2_Nx4_avx2(int N, uint8_t *dst, ptrdiff_t stride,
3843
                                      const uint8_t *above, const uint8_t *left,
3844
                                      int upsample_above, int upsample_left,
3845
254k
                                      int dx, int dy) {
3846
254k
  const int min_base_x = -(1 << upsample_above);
3847
254k
  const int min_base_y = -(1 << upsample_left);
3848
254k
  const int frac_bits_x = 6 - upsample_above;
3849
254k
  const int frac_bits_y = 6 - upsample_left;
3850
3851
254k
  assert(dx > 0);
3852
  // pre-filter above pixels
3853
  // store in temp buffers:
3854
  //   above[x] * 32 + 16
3855
  //   above[x+1] - above[x]
3856
  // final pixels will be calculated as:
3857
  //   (above[x] * 32 + 16 + (above[x+1] - above[x]) * shift) >> 5
3858
254k
  __m128i a0_x, a1_x, a32, a16, diff;
3859
254k
  __m128i c3f, min_base_y128, c1234, dy128;
3860
3861
254k
  a16 = _mm_set1_epi16(16);
3862
254k
  c3f = _mm_set1_epi16(0x3f);
3863
254k
  min_base_y128 = _mm_set1_epi16(min_base_y);
3864
254k
  c1234 = _mm_setr_epi16(0, 1, 2, 3, 4, 0, 0, 0);
3865
254k
  dy128 = _mm_set1_epi16(dy);
3866
3867
1.79M
  for (int r = 0; r < N; r++) {
3868
1.53M
    __m128i b, res, shift, r6, ydx;
3869
1.53M
    __m128i resx, resy, resxy;
3870
1.53M
    __m128i a0_x128, a1_x128;
3871
1.53M
    int y = r + 1;
3872
1.53M
    int base_x = (-y * dx) >> frac_bits_x;
3873
1.53M
    int base_shift = 0;
3874
1.53M
    if (base_x < (min_base_x - 1)) {
3875
1.21M
      base_shift = (min_base_x - base_x - 1) >> upsample_above;
3876
1.21M
    }
3877
1.53M
    int base_min_diff =
3878
1.53M
        (min_base_x - base_x + upsample_above) >> upsample_above;
3879
1.53M
    if (base_min_diff > 4) {
3880
843k
      base_min_diff = 4;
3881
843k
    } else {
3882
696k
      if (base_min_diff < 0) base_min_diff = 0;
3883
696k
    }
3884
3885
1.53M
    if (base_shift > 3) {
3886
843k
      a0_x = _mm_setzero_si128();
3887
843k
      a1_x = _mm_setzero_si128();
3888
843k
      shift = _mm_setzero_si128();
3889
843k
    } else {
3890
696k
      a0_x128 = _mm_loadu_si128((__m128i *)(above + base_x + base_shift));
3891
696k
      ydx = _mm_set1_epi16(y * dx);
3892
696k
      r6 = _mm_slli_epi16(c1234, 6);
3893
3894
696k
      if (upsample_above) {
3895
206k
        a0_x128 =
3896
206k
            _mm_shuffle_epi8(a0_x128, *(__m128i *)EvenOddMaskx[base_shift]);
3897
206k
        a1_x128 = _mm_srli_si128(a0_x128, 8);
3898
3899
206k
        shift = _mm_srli_epi16(
3900
206k
            _mm_and_si128(
3901
206k
                _mm_slli_epi16(_mm_sub_epi16(r6, ydx), upsample_above), c3f),
3902
206k
            1);
3903
489k
      } else {
3904
489k
        a0_x128 = _mm_shuffle_epi8(a0_x128, *(__m128i *)LoadMaskx[base_shift]);
3905
489k
        a1_x128 = _mm_srli_si128(a0_x128, 1);
3906
3907
489k
        shift = _mm_srli_epi16(_mm_and_si128(_mm_sub_epi16(r6, ydx), c3f), 1);
3908
489k
      }
3909
696k
      a0_x = _mm_cvtepu8_epi16(a0_x128);
3910
696k
      a1_x = _mm_cvtepu8_epi16(a1_x128);
3911
696k
    }
3912
    // y calc
3913
1.53M
    __m128i a0_y, a1_y, shifty;
3914
1.53M
    if (base_x < min_base_x) {
3915
1.35M
      DECLARE_ALIGNED(32, int16_t, base_y_c[8]);
3916
1.35M
      __m128i y_c128, base_y_c128, mask128, c1234_;
3917
1.35M
      c1234_ = _mm_srli_si128(c1234, 2);
3918
1.35M
      r6 = _mm_set1_epi16(r << 6);
3919
1.35M
      y_c128 = _mm_sub_epi16(r6, _mm_mullo_epi16(c1234_, dy128));
3920
1.35M
      base_y_c128 = _mm_srai_epi16(y_c128, frac_bits_y);
3921
1.35M
      mask128 = _mm_cmpgt_epi16(min_base_y128, base_y_c128);
3922
1.35M
      base_y_c128 = _mm_andnot_si128(mask128, base_y_c128);
3923
1.35M
      _mm_store_si128((__m128i *)base_y_c, base_y_c128);
3924
3925
1.35M
      a0_y = _mm_setr_epi16(left[base_y_c[0]], left[base_y_c[1]],
3926
1.35M
                            left[base_y_c[2]], left[base_y_c[3]], 0, 0, 0, 0);
3927
1.35M
      base_y_c128 = _mm_add_epi16(base_y_c128, _mm_srli_epi16(a16, 4));
3928
1.35M
      _mm_store_si128((__m128i *)base_y_c, base_y_c128);
3929
1.35M
      a1_y = _mm_setr_epi16(left[base_y_c[0]], left[base_y_c[1]],
3930
1.35M
                            left[base_y_c[2]], left[base_y_c[3]], 0, 0, 0, 0);
3931
3932
1.35M
      if (upsample_left) {
3933
662k
        shifty = _mm_srli_epi16(
3934
662k
            _mm_and_si128(_mm_slli_epi16(y_c128, upsample_left), c3f), 1);
3935
688k
      } else {
3936
688k
        shifty = _mm_srli_epi16(_mm_and_si128(y_c128, c3f), 1);
3937
688k
      }
3938
1.35M
      a0_x = _mm_unpacklo_epi64(a0_x, a0_y);
3939
1.35M
      a1_x = _mm_unpacklo_epi64(a1_x, a1_y);
3940
1.35M
      shift = _mm_unpacklo_epi64(shift, shifty);
3941
1.35M
    }
3942
3943
1.53M
    diff = _mm_sub_epi16(a1_x, a0_x);  // a[x+1] - a[x]
3944
1.53M
    a32 = _mm_slli_epi16(a0_x, 5);     // a[x] * 32
3945
1.53M
    a32 = _mm_add_epi16(a32, a16);     // a[x] * 32 + 16
3946
3947
1.53M
    b = _mm_mullo_epi16(diff, shift);
3948
1.53M
    res = _mm_add_epi16(a32, b);
3949
1.53M
    res = _mm_srli_epi16(res, 5);
3950
3951
1.53M
    resx = _mm_packus_epi16(res, res);
3952
1.53M
    resy = _mm_srli_si128(resx, 4);
3953
3954
1.53M
    resxy = _mm_blendv_epi8(resx, resy, *(__m128i *)BaseMask[base_min_diff]);
3955
1.53M
    *(int *)(dst) = _mm_cvtsi128_si32(resxy);
3956
1.53M
    dst += stride;
3957
1.53M
  }
3958
254k
}
3959
3960
static void dr_prediction_z2_Nx8_avx2(int N, uint8_t *dst, ptrdiff_t stride,
3961
                                      const uint8_t *above, const uint8_t *left,
3962
                                      int upsample_above, int upsample_left,
3963
243k
                                      int dx, int dy) {
3964
243k
  const int min_base_x = -(1 << upsample_above);
3965
243k
  const int min_base_y = -(1 << upsample_left);
3966
243k
  const int frac_bits_x = 6 - upsample_above;
3967
243k
  const int frac_bits_y = 6 - upsample_left;
3968
3969
  // pre-filter above pixels
3970
  // store in temp buffers:
3971
  //   above[x] * 32 + 16
3972
  //   above[x+1] - above[x]
3973
  // final pixels will be calculated as:
3974
  //   (above[x] * 32 + 16 + (above[x+1] - above[x]) * shift) >> 5
3975
243k
  __m256i diff, a32, a16;
3976
243k
  __m256i a0_x, a1_x;
3977
243k
  __m128i a0_x128, a1_x128, min_base_y128, c3f;
3978
243k
  __m128i c1234, dy128;
3979
3980
243k
  a16 = _mm256_set1_epi16(16);
3981
243k
  c3f = _mm_set1_epi16(0x3f);
3982
243k
  min_base_y128 = _mm_set1_epi16(min_base_y);
3983
243k
  dy128 = _mm_set1_epi16(dy);
3984
243k
  c1234 = _mm_setr_epi16(1, 2, 3, 4, 5, 6, 7, 8);
3985
3986
2.49M
  for (int r = 0; r < N; r++) {
3987
2.25M
    __m256i b, res, shift;
3988
2.25M
    __m128i resx, resy, resxy, r6, ydx;
3989
3990
2.25M
    int y = r + 1;
3991
2.25M
    int base_x = (-y * dx) >> frac_bits_x;
3992
2.25M
    int base_shift = 0;
3993
2.25M
    if (base_x < (min_base_x - 1)) {
3994
1.74M
      base_shift = (min_base_x - base_x - 1) >> upsample_above;
3995
1.74M
    }
3996
2.25M
    int base_min_diff =
3997
2.25M
        (min_base_x - base_x + upsample_above) >> upsample_above;
3998
2.25M
    if (base_min_diff > 8) {
3999
1.04M
      base_min_diff = 8;
4000
1.20M
    } else {
4001
1.20M
      if (base_min_diff < 0) base_min_diff = 0;
4002
1.20M
    }
4003
4004
2.25M
    if (base_shift > 7) {
4005
1.04M
      a0_x = _mm256_setzero_si256();
4006
1.04M
      a1_x = _mm256_setzero_si256();
4007
1.04M
      shift = _mm256_setzero_si256();
4008
1.20M
    } else {
4009
1.20M
      a0_x128 = _mm_loadu_si128((__m128i *)(above + base_x + base_shift));
4010
1.20M
      ydx = _mm_set1_epi16(y * dx);
4011
1.20M
      r6 = _mm_slli_epi16(_mm_srli_si128(c1234, 2), 6);
4012
1.20M
      if (upsample_above) {
4013
363k
        a0_x128 =
4014
363k
            _mm_shuffle_epi8(a0_x128, *(__m128i *)EvenOddMaskx[base_shift]);
4015
363k
        a1_x128 = _mm_srli_si128(a0_x128, 8);
4016
4017
363k
        shift = _mm256_castsi128_si256(_mm_srli_epi16(
4018
363k
            _mm_and_si128(
4019
363k
                _mm_slli_epi16(_mm_sub_epi16(r6, ydx), upsample_above), c3f),
4020
363k
            1));
4021
845k
      } else {
4022
845k
        a1_x128 = _mm_srli_si128(a0_x128, 1);
4023
845k
        a0_x128 = _mm_shuffle_epi8(a0_x128, *(__m128i *)LoadMaskx[base_shift]);
4024
845k
        a1_x128 = _mm_shuffle_epi8(a1_x128, *(__m128i *)LoadMaskx[base_shift]);
4025
4026
845k
        shift = _mm256_castsi128_si256(
4027
845k
            _mm_srli_epi16(_mm_and_si128(_mm_sub_epi16(r6, ydx), c3f), 1));
4028
845k
      }
4029
1.20M
      a0_x = _mm256_castsi128_si256(_mm_cvtepu8_epi16(a0_x128));
4030
1.20M
      a1_x = _mm256_castsi128_si256(_mm_cvtepu8_epi16(a1_x128));
4031
1.20M
    }
4032
4033
    // y calc
4034
2.25M
    __m128i a0_y, a1_y, shifty;
4035
2.25M
    if (base_x < min_base_x) {
4036
1.92M
      DECLARE_ALIGNED(32, int16_t, base_y_c[16]);
4037
1.92M
      __m128i y_c128, base_y_c128, mask128;
4038
1.92M
      r6 = _mm_set1_epi16(r << 6);
4039
1.92M
      y_c128 = _mm_sub_epi16(r6, _mm_mullo_epi16(c1234, dy128));
4040
1.92M
      base_y_c128 = _mm_srai_epi16(y_c128, frac_bits_y);
4041
1.92M
      mask128 = _mm_cmpgt_epi16(min_base_y128, base_y_c128);
4042
1.92M
      base_y_c128 = _mm_andnot_si128(mask128, base_y_c128);
4043
1.92M
      _mm_store_si128((__m128i *)base_y_c, base_y_c128);
4044
4045
1.92M
      a0_y = _mm_setr_epi16(left[base_y_c[0]], left[base_y_c[1]],
4046
1.92M
                            left[base_y_c[2]], left[base_y_c[3]],
4047
1.92M
                            left[base_y_c[4]], left[base_y_c[5]],
4048
1.92M
                            left[base_y_c[6]], left[base_y_c[7]]);
4049
1.92M
      base_y_c128 = _mm_add_epi16(
4050
1.92M
          base_y_c128, _mm_srli_epi16(_mm256_castsi256_si128(a16), 4));
4051
1.92M
      _mm_store_si128((__m128i *)base_y_c, base_y_c128);
4052
4053
1.92M
      a1_y = _mm_setr_epi16(left[base_y_c[0]], left[base_y_c[1]],
4054
1.92M
                            left[base_y_c[2]], left[base_y_c[3]],
4055
1.92M
                            left[base_y_c[4]], left[base_y_c[5]],
4056
1.92M
                            left[base_y_c[6]], left[base_y_c[7]]);
4057
4058
1.92M
      if (upsample_left) {
4059
563k
        shifty = _mm_srli_epi16(
4060
563k
            _mm_and_si128(_mm_slli_epi16(y_c128, upsample_left), c3f), 1);
4061
1.36M
      } else {
4062
1.36M
        shifty = _mm_srli_epi16(_mm_and_si128(y_c128, c3f), 1);
4063
1.36M
      }
4064
4065
1.92M
      a0_x = _mm256_inserti128_si256(a0_x, a0_y, 1);
4066
1.92M
      a1_x = _mm256_inserti128_si256(a1_x, a1_y, 1);
4067
1.92M
      shift = _mm256_inserti128_si256(shift, shifty, 1);
4068
1.92M
    }
4069
4070
2.25M
    diff = _mm256_sub_epi16(a1_x, a0_x);  // a[x+1] - a[x]
4071
2.25M
    a32 = _mm256_slli_epi16(a0_x, 5);     // a[x] * 32
4072
2.25M
    a32 = _mm256_add_epi16(a32, a16);     // a[x] * 32 + 16
4073
4074
2.25M
    b = _mm256_mullo_epi16(diff, shift);
4075
2.25M
    res = _mm256_add_epi16(a32, b);
4076
2.25M
    res = _mm256_srli_epi16(res, 5);
4077
4078
2.25M
    resx = _mm_packus_epi16(_mm256_castsi256_si128(res),
4079
2.25M
                            _mm256_castsi256_si128(res));
4080
2.25M
    resy = _mm256_extracti128_si256(res, 1);
4081
2.25M
    resy = _mm_packus_epi16(resy, resy);
4082
4083
2.25M
    resxy = _mm_blendv_epi8(resx, resy, *(__m128i *)BaseMask[base_min_diff]);
4084
2.25M
    _mm_storel_epi64((__m128i *)(dst), resxy);
4085
2.25M
    dst += stride;
4086
2.25M
  }
4087
243k
}
4088
4089
static void dr_prediction_z2_HxW_avx2(int H, int W, uint8_t *dst,
4090
                                      ptrdiff_t stride, const uint8_t *above,
4091
                                      const uint8_t *left, int upsample_above,
4092
401k
                                      int upsample_left, int dx, int dy) {
4093
  // here upsample_above and upsample_left are 0 by design of
4094
  // av1_use_intra_edge_upsample
4095
401k
  const int min_base_x = -1;
4096
401k
  const int min_base_y = -1;
4097
401k
  (void)upsample_above;
4098
401k
  (void)upsample_left;
4099
401k
  const int frac_bits_x = 6;
4100
401k
  const int frac_bits_y = 6;
4101
4102
401k
  __m256i a0_x, a1_x, a0_y, a1_y, a32, a16, c1234, c0123;
4103
401k
  __m256i diff, min_base_y256, c3f, shifty, dy256, c1;
4104
401k
  __m128i a0_x128, a1_x128;
4105
4106
401k
  DECLARE_ALIGNED(32, int16_t, base_y_c[16]);
4107
401k
  a16 = _mm256_set1_epi16(16);
4108
401k
  c1 = _mm256_srli_epi16(a16, 4);
4109
401k
  min_base_y256 = _mm256_set1_epi16(min_base_y);
4110
401k
  c3f = _mm256_set1_epi16(0x3f);
4111
401k
  dy256 = _mm256_set1_epi16(dy);
4112
401k
  c0123 =
4113
401k
      _mm256_setr_epi16(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
4114
401k
  c1234 = _mm256_add_epi16(c0123, c1);
4115
4116
7.95M
  for (int r = 0; r < H; r++) {
4117
7.55M
    __m256i b, res, shift, j256, r6, ydx;
4118
7.55M
    __m128i resx, resy;
4119
7.55M
    __m128i resxy;
4120
7.55M
    int y = r + 1;
4121
7.55M
    ydx = _mm256_set1_epi16((int16_t)(y * dx));
4122
4123
7.55M
    int base_x = (-y * dx) >> frac_bits_x;
4124
21.0M
    for (int j = 0; j < W; j += 16) {
4125
13.5M
      j256 = _mm256_set1_epi16(j);
4126
13.5M
      int base_shift = 0;
4127
13.5M
      if ((base_x + j) < (min_base_x - 1)) {
4128
9.88M
        base_shift = (min_base_x - (base_x + j) - 1);
4129
9.88M
      }
4130
13.5M
      int base_min_diff = (min_base_x - base_x - j);
4131
13.5M
      if (base_min_diff > 16) {
4132
6.97M
        base_min_diff = 16;
4133
6.97M
      } else {
4134
6.55M
        if (base_min_diff < 0) base_min_diff = 0;
4135
6.55M
      }
4136
4137
13.5M
      if (base_shift < 16) {
4138
6.55M
        a0_x128 = _mm_loadu_si128((__m128i *)(above + base_x + base_shift + j));
4139
6.55M
        a1_x128 =
4140
6.55M
            _mm_loadu_si128((__m128i *)(above + base_x + base_shift + 1 + j));
4141
6.55M
        a0_x128 = _mm_shuffle_epi8(a0_x128, *(__m128i *)LoadMaskx[base_shift]);
4142
6.55M
        a1_x128 = _mm_shuffle_epi8(a1_x128, *(__m128i *)LoadMaskx[base_shift]);
4143
4144
6.55M
        a0_x = _mm256_cvtepu8_epi16(a0_x128);
4145
6.55M
        a1_x = _mm256_cvtepu8_epi16(a1_x128);
4146
4147
6.55M
        r6 = _mm256_slli_epi16(_mm256_add_epi16(c0123, j256), 6);
4148
6.55M
        shift = _mm256_srli_epi16(
4149
6.55M
            _mm256_and_si256(_mm256_sub_epi16(r6, ydx), c3f), 1);
4150
4151
6.55M
        diff = _mm256_sub_epi16(a1_x, a0_x);  // a[x+1] - a[x]
4152
6.55M
        a32 = _mm256_slli_epi16(a0_x, 5);     // a[x] * 32
4153
6.55M
        a32 = _mm256_add_epi16(a32, a16);     // a[x] * 32 + 16
4154
4155
6.55M
        b = _mm256_mullo_epi16(diff, shift);
4156
6.55M
        res = _mm256_add_epi16(a32, b);
4157
6.55M
        res = _mm256_srli_epi16(res, 5);  // 16 16-bit values
4158
6.55M
        resx = _mm256_castsi256_si128(_mm256_packus_epi16(
4159
6.55M
            res, _mm256_castsi128_si256(_mm256_extracti128_si256(res, 1))));
4160
6.97M
      } else {
4161
6.97M
        resx = _mm_setzero_si128();
4162
6.97M
      }
4163
4164
      // y calc
4165
13.5M
      if (base_x < min_base_x) {
4166
12.5M
        __m256i c256, y_c256, base_y_c256, mask256, mul16;
4167
12.5M
        r6 = _mm256_set1_epi16(r << 6);
4168
12.5M
        c256 = _mm256_add_epi16(j256, c1234);
4169
12.5M
        mul16 = _mm256_min_epu16(_mm256_mullo_epi16(c256, dy256),
4170
12.5M
                                 _mm256_srli_epi16(min_base_y256, 1));
4171
12.5M
        y_c256 = _mm256_sub_epi16(r6, mul16);
4172
4173
12.5M
        base_y_c256 = _mm256_srai_epi16(y_c256, frac_bits_y);
4174
12.5M
        mask256 = _mm256_cmpgt_epi16(min_base_y256, base_y_c256);
4175
4176
12.5M
        base_y_c256 = _mm256_blendv_epi8(base_y_c256, min_base_y256, mask256);
4177
12.5M
        int16_t min_y = (int16_t)_mm_extract_epi16(
4178
12.5M
            _mm256_extracti128_si256(base_y_c256, 1), 7);
4179
12.5M
        int16_t max_y =
4180
12.5M
            (int16_t)_mm_extract_epi16(_mm256_castsi256_si128(base_y_c256), 0);
4181
12.5M
        int16_t offset_diff = max_y - min_y;
4182
4183
12.5M
        if (offset_diff < 16) {
4184
11.8M
          __m256i min_y256 = _mm256_set1_epi16(min_y);
4185
4186
11.8M
          __m256i base_y_offset = _mm256_sub_epi16(base_y_c256, min_y256);
4187
11.8M
          __m128i base_y_offset128 =
4188
11.8M
              _mm_packs_epi16(_mm256_extracti128_si256(base_y_offset, 0),
4189
11.8M
                              _mm256_extracti128_si256(base_y_offset, 1));
4190
4191
11.8M
          __m128i a0_y128 = _mm_maskload_epi32(
4192
11.8M
              (int *)(left + min_y), *(__m128i *)LoadMaskz2[offset_diff / 4]);
4193
11.8M
          __m128i a1_y128 =
4194
11.8M
              _mm_maskload_epi32((int *)(left + min_y + 1),
4195
11.8M
                                 *(__m128i *)LoadMaskz2[offset_diff / 4]);
4196
11.8M
          a0_y128 = _mm_shuffle_epi8(a0_y128, base_y_offset128);
4197
11.8M
          a1_y128 = _mm_shuffle_epi8(a1_y128, base_y_offset128);
4198
11.8M
          a0_y = _mm256_cvtepu8_epi16(a0_y128);
4199
11.8M
          a1_y = _mm256_cvtepu8_epi16(a1_y128);
4200
11.8M
        } else {
4201
733k
          base_y_c256 = _mm256_andnot_si256(mask256, base_y_c256);
4202
733k
          _mm256_store_si256((__m256i *)base_y_c, base_y_c256);
4203
4204
733k
          a0_y = _mm256_setr_epi16(
4205
733k
              left[base_y_c[0]], left[base_y_c[1]], left[base_y_c[2]],
4206
733k
              left[base_y_c[3]], left[base_y_c[4]], left[base_y_c[5]],
4207
733k
              left[base_y_c[6]], left[base_y_c[7]], left[base_y_c[8]],
4208
733k
              left[base_y_c[9]], left[base_y_c[10]], left[base_y_c[11]],
4209
733k
              left[base_y_c[12]], left[base_y_c[13]], left[base_y_c[14]],
4210
733k
              left[base_y_c[15]]);
4211
733k
          base_y_c256 = _mm256_add_epi16(base_y_c256, c1);
4212
733k
          _mm256_store_si256((__m256i *)base_y_c, base_y_c256);
4213
4214
733k
          a1_y = _mm256_setr_epi16(
4215
733k
              left[base_y_c[0]], left[base_y_c[1]], left[base_y_c[2]],
4216
733k
              left[base_y_c[3]], left[base_y_c[4]], left[base_y_c[5]],
4217
733k
              left[base_y_c[6]], left[base_y_c[7]], left[base_y_c[8]],
4218
733k
              left[base_y_c[9]], left[base_y_c[10]], left[base_y_c[11]],
4219
733k
              left[base_y_c[12]], left[base_y_c[13]], left[base_y_c[14]],
4220
733k
              left[base_y_c[15]]);
4221
733k
        }
4222
12.5M
        shifty = _mm256_srli_epi16(_mm256_and_si256(y_c256, c3f), 1);
4223
4224
12.5M
        diff = _mm256_sub_epi16(a1_y, a0_y);  // a[x+1] - a[x]
4225
12.5M
        a32 = _mm256_slli_epi16(a0_y, 5);     // a[x] * 32
4226
12.5M
        a32 = _mm256_add_epi16(a32, a16);     // a[x] * 32 + 16
4227
4228
12.5M
        b = _mm256_mullo_epi16(diff, shifty);
4229
12.5M
        res = _mm256_add_epi16(a32, b);
4230
12.5M
        res = _mm256_srli_epi16(res, 5);  // 16 16-bit values
4231
12.5M
        resy = _mm256_castsi256_si128(_mm256_packus_epi16(
4232
12.5M
            res, _mm256_castsi128_si256(_mm256_extracti128_si256(res, 1))));
4233
12.5M
      } else {
4234
961k
        resy = _mm_setzero_si128();
4235
961k
      }
4236
13.5M
      resxy = _mm_blendv_epi8(resx, resy, *(__m128i *)BaseMask[base_min_diff]);
4237
13.5M
      _mm_storeu_si128((__m128i *)(dst + j), resxy);
4238
13.5M
    }  // for j
4239
7.55M
    dst += stride;
4240
7.55M
  }
4241
401k
}
4242
4243
// Directional prediction, zone 2: 90 < angle < 180
4244
void av1_dr_prediction_z2_avx2(uint8_t *dst, ptrdiff_t stride, int bw, int bh,
4245
                               const uint8_t *above, const uint8_t *left,
4246
                               int upsample_above, int upsample_left, int dx,
4247
898k
                               int dy) {
4248
898k
  assert(dx > 0);
4249
898k
  assert(dy > 0);
4250
898k
  switch (bw) {
4251
254k
    case 4:
4252
254k
      dr_prediction_z2_Nx4_avx2(bh, dst, stride, above, left, upsample_above,
4253
254k
                                upsample_left, dx, dy);
4254
254k
      break;
4255
243k
    case 8:
4256
243k
      dr_prediction_z2_Nx8_avx2(bh, dst, stride, above, left, upsample_above,
4257
243k
                                upsample_left, dx, dy);
4258
243k
      break;
4259
401k
    default:
4260
401k
      dr_prediction_z2_HxW_avx2(bh, bw, dst, stride, above, left,
4261
401k
                                upsample_above, upsample_left, dx, dy);
4262
401k
      break;
4263
898k
  }
4264
898k
  return;
4265
898k
}
4266
4267
// z3 functions
4268
169k
static inline void transpose16x32_avx2(__m256i *x, __m256i *d) {
4269
169k
  __m256i w0, w1, w2, w3, w4, w5, w6, w7, w8, w9;
4270
169k
  __m256i w10, w11, w12, w13, w14, w15;
4271
4272
169k
  w0 = _mm256_unpacklo_epi8(x[0], x[1]);
4273
169k
  w1 = _mm256_unpacklo_epi8(x[2], x[3]);
4274
169k
  w2 = _mm256_unpacklo_epi8(x[4], x[5]);
4275
169k
  w3 = _mm256_unpacklo_epi8(x[6], x[7]);
4276
4277
169k
  w8 = _mm256_unpacklo_epi8(x[8], x[9]);
4278
169k
  w9 = _mm256_unpacklo_epi8(x[10], x[11]);
4279
169k
  w10 = _mm256_unpacklo_epi8(x[12], x[13]);
4280
169k
  w11 = _mm256_unpacklo_epi8(x[14], x[15]);
4281
4282
169k
  w4 = _mm256_unpacklo_epi16(w0, w1);
4283
169k
  w5 = _mm256_unpacklo_epi16(w2, w3);
4284
169k
  w12 = _mm256_unpacklo_epi16(w8, w9);
4285
169k
  w13 = _mm256_unpacklo_epi16(w10, w11);
4286
4287
169k
  w6 = _mm256_unpacklo_epi32(w4, w5);
4288
169k
  w7 = _mm256_unpackhi_epi32(w4, w5);
4289
169k
  w14 = _mm256_unpacklo_epi32(w12, w13);
4290
169k
  w15 = _mm256_unpackhi_epi32(w12, w13);
4291
4292
  // Store first 4-line result
4293
169k
  d[0] = _mm256_unpacklo_epi64(w6, w14);
4294
169k
  d[1] = _mm256_unpackhi_epi64(w6, w14);
4295
169k
  d[2] = _mm256_unpacklo_epi64(w7, w15);
4296
169k
  d[3] = _mm256_unpackhi_epi64(w7, w15);
4297
4298
169k
  w4 = _mm256_unpackhi_epi16(w0, w1);
4299
169k
  w5 = _mm256_unpackhi_epi16(w2, w3);
4300
169k
  w12 = _mm256_unpackhi_epi16(w8, w9);
4301
169k
  w13 = _mm256_unpackhi_epi16(w10, w11);
4302
4303
169k
  w6 = _mm256_unpacklo_epi32(w4, w5);
4304
169k
  w7 = _mm256_unpackhi_epi32(w4, w5);
4305
169k
  w14 = _mm256_unpacklo_epi32(w12, w13);
4306
169k
  w15 = _mm256_unpackhi_epi32(w12, w13);
4307
4308
  // Store second 4-line result
4309
169k
  d[4] = _mm256_unpacklo_epi64(w6, w14);
4310
169k
  d[5] = _mm256_unpackhi_epi64(w6, w14);
4311
169k
  d[6] = _mm256_unpacklo_epi64(w7, w15);
4312
169k
  d[7] = _mm256_unpackhi_epi64(w7, w15);
4313
4314
  // upper half
4315
169k
  w0 = _mm256_unpackhi_epi8(x[0], x[1]);
4316
169k
  w1 = _mm256_unpackhi_epi8(x[2], x[3]);
4317
169k
  w2 = _mm256_unpackhi_epi8(x[4], x[5]);
4318
169k
  w3 = _mm256_unpackhi_epi8(x[6], x[7]);
4319
4320
169k
  w8 = _mm256_unpackhi_epi8(x[8], x[9]);
4321
169k
  w9 = _mm256_unpackhi_epi8(x[10], x[11]);
4322
169k
  w10 = _mm256_unpackhi_epi8(x[12], x[13]);
4323
169k
  w11 = _mm256_unpackhi_epi8(x[14], x[15]);
4324
4325
169k
  w4 = _mm256_unpacklo_epi16(w0, w1);
4326
169k
  w5 = _mm256_unpacklo_epi16(w2, w3);
4327
169k
  w12 = _mm256_unpacklo_epi16(w8, w9);
4328
169k
  w13 = _mm256_unpacklo_epi16(w10, w11);
4329
4330
169k
  w6 = _mm256_unpacklo_epi32(w4, w5);
4331
169k
  w7 = _mm256_unpackhi_epi32(w4, w5);
4332
169k
  w14 = _mm256_unpacklo_epi32(w12, w13);
4333
169k
  w15 = _mm256_unpackhi_epi32(w12, w13);
4334
4335
  // Store first 4-line result
4336
169k
  d[8] = _mm256_unpacklo_epi64(w6, w14);
4337
169k
  d[9] = _mm256_unpackhi_epi64(w6, w14);
4338
169k
  d[10] = _mm256_unpacklo_epi64(w7, w15);
4339
169k
  d[11] = _mm256_unpackhi_epi64(w7, w15);
4340
4341
169k
  w4 = _mm256_unpackhi_epi16(w0, w1);
4342
169k
  w5 = _mm256_unpackhi_epi16(w2, w3);
4343
169k
  w12 = _mm256_unpackhi_epi16(w8, w9);
4344
169k
  w13 = _mm256_unpackhi_epi16(w10, w11);
4345
4346
169k
  w6 = _mm256_unpacklo_epi32(w4, w5);
4347
169k
  w7 = _mm256_unpackhi_epi32(w4, w5);
4348
169k
  w14 = _mm256_unpacklo_epi32(w12, w13);
4349
169k
  w15 = _mm256_unpackhi_epi32(w12, w13);
4350
4351
  // Store second 4-line result
4352
169k
  d[12] = _mm256_unpacklo_epi64(w6, w14);
4353
169k
  d[13] = _mm256_unpackhi_epi64(w6, w14);
4354
169k
  d[14] = _mm256_unpacklo_epi64(w7, w15);
4355
169k
  d[15] = _mm256_unpackhi_epi64(w7, w15);
4356
169k
}
4357
4358
static void dr_prediction_z3_4x4_avx2(uint8_t *dst, ptrdiff_t stride,
4359
                                      const uint8_t *left, int upsample_left,
4360
85.9k
                                      int dy) {
4361
85.9k
  __m128i dstvec[4], d[4];
4362
4363
85.9k
  dr_prediction_z1_HxW_internal_avx2(4, 4, dstvec, left, upsample_left, dy);
4364
85.9k
  transpose4x8_8x4_low_sse2(&dstvec[0], &dstvec[1], &dstvec[2], &dstvec[3],
4365
85.9k
                            &d[0], &d[1], &d[2], &d[3]);
4366
4367
85.9k
  *(int *)(dst + stride * 0) = _mm_cvtsi128_si32(d[0]);
4368
85.9k
  *(int *)(dst + stride * 1) = _mm_cvtsi128_si32(d[1]);
4369
85.9k
  *(int *)(dst + stride * 2) = _mm_cvtsi128_si32(d[2]);
4370
85.9k
  *(int *)(dst + stride * 3) = _mm_cvtsi128_si32(d[3]);
4371
85.9k
  return;
4372
85.9k
}
4373
4374
static void dr_prediction_z3_8x8_avx2(uint8_t *dst, ptrdiff_t stride,
4375
                                      const uint8_t *left, int upsample_left,
4376
86.1k
                                      int dy) {
4377
86.1k
  __m128i dstvec[8], d[8];
4378
4379
86.1k
  dr_prediction_z1_HxW_internal_avx2(8, 8, dstvec, left, upsample_left, dy);
4380
86.1k
  transpose8x8_sse2(&dstvec[0], &dstvec[1], &dstvec[2], &dstvec[3], &dstvec[4],
4381
86.1k
                    &dstvec[5], &dstvec[6], &dstvec[7], &d[0], &d[1], &d[2],
4382
86.1k
                    &d[3]);
4383
4384
86.1k
  _mm_storel_epi64((__m128i *)(dst + 0 * stride), d[0]);
4385
86.1k
  _mm_storel_epi64((__m128i *)(dst + 1 * stride), _mm_srli_si128(d[0], 8));
4386
86.1k
  _mm_storel_epi64((__m128i *)(dst + 2 * stride), d[1]);
4387
86.1k
  _mm_storel_epi64((__m128i *)(dst + 3 * stride), _mm_srli_si128(d[1], 8));
4388
86.1k
  _mm_storel_epi64((__m128i *)(dst + 4 * stride), d[2]);
4389
86.1k
  _mm_storel_epi64((__m128i *)(dst + 5 * stride), _mm_srli_si128(d[2], 8));
4390
86.1k
  _mm_storel_epi64((__m128i *)(dst + 6 * stride), d[3]);
4391
86.1k
  _mm_storel_epi64((__m128i *)(dst + 7 * stride), _mm_srli_si128(d[3], 8));
4392
86.1k
}
4393
4394
static void dr_prediction_z3_4x8_avx2(uint8_t *dst, ptrdiff_t stride,
4395
                                      const uint8_t *left, int upsample_left,
4396
21.5k
                                      int dy) {
4397
21.5k
  __m128i dstvec[4], d[8];
4398
4399
21.5k
  dr_prediction_z1_HxW_internal_avx2(8, 4, dstvec, left, upsample_left, dy);
4400
21.5k
  transpose4x8_8x4_sse2(&dstvec[0], &dstvec[1], &dstvec[2], &dstvec[3], &d[0],
4401
21.5k
                        &d[1], &d[2], &d[3], &d[4], &d[5], &d[6], &d[7]);
4402
194k
  for (int i = 0; i < 8; i++) {
4403
172k
    *(int *)(dst + stride * i) = _mm_cvtsi128_si32(d[i]);
4404
172k
  }
4405
21.5k
}
4406
4407
static void dr_prediction_z3_8x4_avx2(uint8_t *dst, ptrdiff_t stride,
4408
                                      const uint8_t *left, int upsample_left,
4409
37.6k
                                      int dy) {
4410
37.6k
  __m128i dstvec[8], d[4];
4411
4412
37.6k
  dr_prediction_z1_HxW_internal_avx2(4, 8, dstvec, left, upsample_left, dy);
4413
37.6k
  transpose8x8_low_sse2(&dstvec[0], &dstvec[1], &dstvec[2], &dstvec[3],
4414
37.6k
                        &dstvec[4], &dstvec[5], &dstvec[6], &dstvec[7], &d[0],
4415
37.6k
                        &d[1], &d[2], &d[3]);
4416
37.6k
  _mm_storel_epi64((__m128i *)(dst + 0 * stride), d[0]);
4417
37.6k
  _mm_storel_epi64((__m128i *)(dst + 1 * stride), d[1]);
4418
37.6k
  _mm_storel_epi64((__m128i *)(dst + 2 * stride), d[2]);
4419
37.6k
  _mm_storel_epi64((__m128i *)(dst + 3 * stride), d[3]);
4420
37.6k
}
4421
4422
static void dr_prediction_z3_8x16_avx2(uint8_t *dst, ptrdiff_t stride,
4423
                                       const uint8_t *left, int upsample_left,
4424
22.9k
                                       int dy) {
4425
22.9k
  __m128i dstvec[8], d[8];
4426
4427
22.9k
  dr_prediction_z1_HxW_internal_avx2(16, 8, dstvec, left, upsample_left, dy);
4428
22.9k
  transpose8x16_16x8_sse2(dstvec, dstvec + 1, dstvec + 2, dstvec + 3,
4429
22.9k
                          dstvec + 4, dstvec + 5, dstvec + 6, dstvec + 7, d,
4430
22.9k
                          d + 1, d + 2, d + 3, d + 4, d + 5, d + 6, d + 7);
4431
206k
  for (int i = 0; i < 8; i++) {
4432
183k
    _mm_storel_epi64((__m128i *)(dst + i * stride), d[i]);
4433
183k
    _mm_storel_epi64((__m128i *)(dst + (i + 8) * stride),
4434
183k
                     _mm_srli_si128(d[i], 8));
4435
183k
  }
4436
22.9k
}
4437
4438
static void dr_prediction_z3_16x8_avx2(uint8_t *dst, ptrdiff_t stride,
4439
                                       const uint8_t *left, int upsample_left,
4440
44.2k
                                       int dy) {
4441
44.2k
  __m128i dstvec[16], d[16];
4442
4443
44.2k
  dr_prediction_z1_HxW_internal_avx2(8, 16, dstvec, left, upsample_left, dy);
4444
44.2k
  transpose16x8_8x16_sse2(
4445
44.2k
      &dstvec[0], &dstvec[1], &dstvec[2], &dstvec[3], &dstvec[4], &dstvec[5],
4446
44.2k
      &dstvec[6], &dstvec[7], &dstvec[8], &dstvec[9], &dstvec[10], &dstvec[11],
4447
44.2k
      &dstvec[12], &dstvec[13], &dstvec[14], &dstvec[15], &d[0], &d[1], &d[2],
4448
44.2k
      &d[3], &d[4], &d[5], &d[6], &d[7]);
4449
4450
398k
  for (int i = 0; i < 8; i++) {
4451
353k
    _mm_storeu_si128((__m128i *)(dst + i * stride), d[i]);
4452
353k
  }
4453
44.2k
}
4454
4455
#if !CONFIG_REALTIME_ONLY || CONFIG_AV1_DECODER
4456
static void dr_prediction_z3_4x16_avx2(uint8_t *dst, ptrdiff_t stride,
4457
                                       const uint8_t *left, int upsample_left,
4458
16.9k
                                       int dy) {
4459
16.9k
  __m128i dstvec[4], d[16];
4460
4461
16.9k
  dr_prediction_z1_HxW_internal_avx2(16, 4, dstvec, left, upsample_left, dy);
4462
16.9k
  transpose4x16_sse2(dstvec, d);
4463
287k
  for (int i = 0; i < 16; i++) {
4464
270k
    *(int *)(dst + stride * i) = _mm_cvtsi128_si32(d[i]);
4465
270k
  }
4466
16.9k
}
4467
4468
static void dr_prediction_z3_16x4_avx2(uint8_t *dst, ptrdiff_t stride,
4469
                                       const uint8_t *left, int upsample_left,
4470
55.2k
                                       int dy) {
4471
55.2k
  __m128i dstvec[16], d[8];
4472
4473
55.2k
  dr_prediction_z1_HxW_internal_avx2(4, 16, dstvec, left, upsample_left, dy);
4474
276k
  for (int i = 4; i < 8; i++) {
4475
220k
    d[i] = _mm_setzero_si128();
4476
220k
  }
4477
55.2k
  transpose16x8_8x16_sse2(
4478
55.2k
      &dstvec[0], &dstvec[1], &dstvec[2], &dstvec[3], &dstvec[4], &dstvec[5],
4479
55.2k
      &dstvec[6], &dstvec[7], &dstvec[8], &dstvec[9], &dstvec[10], &dstvec[11],
4480
55.2k
      &dstvec[12], &dstvec[13], &dstvec[14], &dstvec[15], &d[0], &d[1], &d[2],
4481
55.2k
      &d[3], &d[4], &d[5], &d[6], &d[7]);
4482
4483
276k
  for (int i = 0; i < 4; i++) {
4484
220k
    _mm_storeu_si128((__m128i *)(dst + i * stride), d[i]);
4485
220k
  }
4486
55.2k
}
4487
4488
static void dr_prediction_z3_8x32_avx2(uint8_t *dst, ptrdiff_t stride,
4489
                                       const uint8_t *left, int upsample_left,
4490
9.90k
                                       int dy) {
4491
9.90k
  __m256i dstvec[16], d[16];
4492
4493
9.90k
  dr_prediction_z1_32xN_internal_avx2(8, dstvec, left, upsample_left, dy);
4494
89.1k
  for (int i = 8; i < 16; i++) {
4495
79.2k
    dstvec[i] = _mm256_setzero_si256();
4496
79.2k
  }
4497
9.90k
  transpose16x32_avx2(dstvec, d);
4498
4499
168k
  for (int i = 0; i < 16; i++) {
4500
158k
    _mm_storel_epi64((__m128i *)(dst + i * stride),
4501
158k
                     _mm256_castsi256_si128(d[i]));
4502
158k
  }
4503
168k
  for (int i = 0; i < 16; i++) {
4504
158k
    _mm_storel_epi64((__m128i *)(dst + (i + 16) * stride),
4505
158k
                     _mm256_extracti128_si256(d[i], 1));
4506
158k
  }
4507
9.90k
}
4508
4509
static void dr_prediction_z3_32x8_avx2(uint8_t *dst, ptrdiff_t stride,
4510
                                       const uint8_t *left, int upsample_left,
4511
37.9k
                                       int dy) {
4512
37.9k
  __m128i dstvec[32], d[16];
4513
4514
37.9k
  dr_prediction_z1_HxW_internal_avx2(8, 32, dstvec, left, upsample_left, dy);
4515
4516
37.9k
  transpose16x8_8x16_sse2(
4517
37.9k
      &dstvec[0], &dstvec[1], &dstvec[2], &dstvec[3], &dstvec[4], &dstvec[5],
4518
37.9k
      &dstvec[6], &dstvec[7], &dstvec[8], &dstvec[9], &dstvec[10], &dstvec[11],
4519
37.9k
      &dstvec[12], &dstvec[13], &dstvec[14], &dstvec[15], &d[0], &d[1], &d[2],
4520
37.9k
      &d[3], &d[4], &d[5], &d[6], &d[7]);
4521
37.9k
  transpose16x8_8x16_sse2(
4522
37.9k
      &dstvec[0 + 16], &dstvec[1 + 16], &dstvec[2 + 16], &dstvec[3 + 16],
4523
37.9k
      &dstvec[4 + 16], &dstvec[5 + 16], &dstvec[6 + 16], &dstvec[7 + 16],
4524
37.9k
      &dstvec[8 + 16], &dstvec[9 + 16], &dstvec[10 + 16], &dstvec[11 + 16],
4525
37.9k
      &dstvec[12 + 16], &dstvec[13 + 16], &dstvec[14 + 16], &dstvec[15 + 16],
4526
37.9k
      &d[0 + 8], &d[1 + 8], &d[2 + 8], &d[3 + 8], &d[4 + 8], &d[5 + 8],
4527
37.9k
      &d[6 + 8], &d[7 + 8]);
4528
4529
341k
  for (int i = 0; i < 8; i++) {
4530
303k
    _mm_storeu_si128((__m128i *)(dst + i * stride), d[i]);
4531
303k
    _mm_storeu_si128((__m128i *)(dst + i * stride + 16), d[i + 8]);
4532
303k
  }
4533
37.9k
}
4534
#endif  // !CONFIG_REALTIME_ONLY || CONFIG_AV1_DECODER
4535
4536
static void dr_prediction_z3_16x16_avx2(uint8_t *dst, ptrdiff_t stride,
4537
                                        const uint8_t *left, int upsample_left,
4538
76.5k
                                        int dy) {
4539
76.5k
  __m128i dstvec[16], d[16];
4540
4541
76.5k
  dr_prediction_z1_HxW_internal_avx2(16, 16, dstvec, left, upsample_left, dy);
4542
76.5k
  transpose16x16_sse2(dstvec, d);
4543
4544
1.30M
  for (int i = 0; i < 16; i++) {
4545
1.22M
    _mm_storeu_si128((__m128i *)(dst + i * stride), d[i]);
4546
1.22M
  }
4547
76.5k
}
4548
4549
static void dr_prediction_z3_32x32_avx2(uint8_t *dst, ptrdiff_t stride,
4550
                                        const uint8_t *left, int upsample_left,
4551
69.8k
                                        int dy) {
4552
69.8k
  __m256i dstvec[32], d[32];
4553
4554
69.8k
  dr_prediction_z1_32xN_internal_avx2(32, dstvec, left, upsample_left, dy);
4555
69.8k
  transpose16x32_avx2(dstvec, d);
4556
69.8k
  transpose16x32_avx2(dstvec + 16, d + 16);
4557
1.18M
  for (int j = 0; j < 16; j++) {
4558
1.11M
    _mm_storeu_si128((__m128i *)(dst + j * stride),
4559
1.11M
                     _mm256_castsi256_si128(d[j]));
4560
1.11M
    _mm_storeu_si128((__m128i *)(dst + j * stride + 16),
4561
1.11M
                     _mm256_castsi256_si128(d[j + 16]));
4562
1.11M
  }
4563
1.18M
  for (int j = 0; j < 16; j++) {
4564
1.11M
    _mm_storeu_si128((__m128i *)(dst + (j + 16) * stride),
4565
1.11M
                     _mm256_extracti128_si256(d[j], 1));
4566
1.11M
    _mm_storeu_si128((__m128i *)(dst + (j + 16) * stride + 16),
4567
1.11M
                     _mm256_extracti128_si256(d[j + 16], 1));
4568
1.11M
  }
4569
69.8k
}
4570
4571
static void dr_prediction_z3_64x64_avx2(uint8_t *dst, ptrdiff_t stride,
4572
                                        const uint8_t *left, int upsample_left,
4573
19.2k
                                        int dy) {
4574
19.2k
  DECLARE_ALIGNED(16, uint8_t, dstT[64 * 64]);
4575
19.2k
  dr_prediction_z1_64xN_avx2(64, dstT, 64, left, upsample_left, dy);
4576
19.2k
  transpose(dstT, 64, dst, stride, 64, 64);
4577
19.2k
}
4578
4579
static void dr_prediction_z3_16x32_avx2(uint8_t *dst, ptrdiff_t stride,
4580
                                        const uint8_t *left, int upsample_left,
4581
19.5k
                                        int dy) {
4582
19.5k
  __m256i dstvec[16], d[16];
4583
4584
19.5k
  dr_prediction_z1_32xN_internal_avx2(16, dstvec, left, upsample_left, dy);
4585
19.5k
  transpose16x32_avx2(dstvec, d);
4586
  // store
4587
331k
  for (int j = 0; j < 16; j++) {
4588
312k
    _mm_storeu_si128((__m128i *)(dst + j * stride),
4589
312k
                     _mm256_castsi256_si128(d[j]));
4590
312k
    _mm_storeu_si128((__m128i *)(dst + (j + 16) * stride),
4591
312k
                     _mm256_extracti128_si256(d[j], 1));
4592
312k
  }
4593
19.5k
}
4594
4595
static void dr_prediction_z3_32x16_avx2(uint8_t *dst, ptrdiff_t stride,
4596
                                        const uint8_t *left, int upsample_left,
4597
15.8k
                                        int dy) {
4598
15.8k
  __m128i dstvec[32], d[16];
4599
4600
15.8k
  dr_prediction_z1_HxW_internal_avx2(16, 32, dstvec, left, upsample_left, dy);
4601
47.5k
  for (int i = 0; i < 32; i += 16) {
4602
31.6k
    transpose16x16_sse2((dstvec + i), d);
4603
538k
    for (int j = 0; j < 16; j++) {
4604
507k
      _mm_storeu_si128((__m128i *)(dst + j * stride + i), d[j]);
4605
507k
    }
4606
31.6k
  }
4607
15.8k
}
4608
4609
static void dr_prediction_z3_32x64_avx2(uint8_t *dst, ptrdiff_t stride,
4610
                                        const uint8_t *left, int upsample_left,
4611
1.62k
                                        int dy) {
4612
1.62k
  uint8_t dstT[64 * 32];
4613
1.62k
  dr_prediction_z1_64xN_avx2(32, dstT, 64, left, upsample_left, dy);
4614
1.62k
  transpose(dstT, 64, dst, stride, 32, 64);
4615
1.62k
}
4616
4617
static void dr_prediction_z3_64x32_avx2(uint8_t *dst, ptrdiff_t stride,
4618
                                        const uint8_t *left, int upsample_left,
4619
2.63k
                                        int dy) {
4620
2.63k
  uint8_t dstT[32 * 64];
4621
2.63k
  dr_prediction_z1_32xN_avx2(64, dstT, 32, left, upsample_left, dy);
4622
2.63k
  transpose(dstT, 32, dst, stride, 64, 32);
4623
2.63k
  return;
4624
2.63k
}
4625
4626
#if !CONFIG_REALTIME_ONLY || CONFIG_AV1_DECODER
4627
static void dr_prediction_z3_16x64_avx2(uint8_t *dst, ptrdiff_t stride,
4628
                                        const uint8_t *left, int upsample_left,
4629
4.46k
                                        int dy) {
4630
4.46k
  uint8_t dstT[64 * 16];
4631
4.46k
  dr_prediction_z1_64xN_avx2(16, dstT, 64, left, upsample_left, dy);
4632
4.46k
  transpose(dstT, 64, dst, stride, 16, 64);
4633
4.46k
}
4634
4635
static void dr_prediction_z3_64x16_avx2(uint8_t *dst, ptrdiff_t stride,
4636
                                        const uint8_t *left, int upsample_left,
4637
11.2k
                                        int dy) {
4638
11.2k
  __m128i dstvec[64], d[16];
4639
4640
11.2k
  dr_prediction_z1_HxW_internal_avx2(16, 64, dstvec, left, upsample_left, dy);
4641
56.3k
  for (int i = 0; i < 64; i += 16) {
4642
45.0k
    transpose16x16_sse2((dstvec + i), d);
4643
766k
    for (int j = 0; j < 16; j++) {
4644
721k
      _mm_storeu_si128((__m128i *)(dst + j * stride + i), d[j]);
4645
721k
    }
4646
45.0k
  }
4647
11.2k
}
4648
#endif  // !CONFIG_REALTIME_ONLY || CONFIG_AV1_DECODER
4649
4650
void av1_dr_prediction_z3_avx2(uint8_t *dst, ptrdiff_t stride, int bw, int bh,
4651
                               const uint8_t *above, const uint8_t *left,
4652
639k
                               int upsample_left, int dx, int dy) {
4653
639k
  (void)above;
4654
639k
  (void)dx;
4655
639k
  assert(dx == 1);
4656
639k
  assert(dy > 0);
4657
4658
639k
  if (bw == bh) {
4659
337k
    switch (bw) {
4660
85.9k
      case 4:
4661
85.9k
        dr_prediction_z3_4x4_avx2(dst, stride, left, upsample_left, dy);
4662
85.9k
        break;
4663
86.1k
      case 8:
4664
86.1k
        dr_prediction_z3_8x8_avx2(dst, stride, left, upsample_left, dy);
4665
86.1k
        break;
4666
76.5k
      case 16:
4667
76.5k
        dr_prediction_z3_16x16_avx2(dst, stride, left, upsample_left, dy);
4668
76.5k
        break;
4669
69.8k
      case 32:
4670
69.8k
        dr_prediction_z3_32x32_avx2(dst, stride, left, upsample_left, dy);
4671
69.8k
        break;
4672
19.2k
      case 64:
4673
19.2k
        dr_prediction_z3_64x64_avx2(dst, stride, left, upsample_left, dy);
4674
19.2k
        break;
4675
337k
    }
4676
337k
  } else {
4677
301k
    if (bw < bh) {
4678
96.9k
      if (bw + bw == bh) {
4679
65.6k
        switch (bw) {
4680
21.5k
          case 4:
4681
21.5k
            dr_prediction_z3_4x8_avx2(dst, stride, left, upsample_left, dy);
4682
21.5k
            break;
4683
22.9k
          case 8:
4684
22.9k
            dr_prediction_z3_8x16_avx2(dst, stride, left, upsample_left, dy);
4685
22.9k
            break;
4686
19.5k
          case 16:
4687
19.5k
            dr_prediction_z3_16x32_avx2(dst, stride, left, upsample_left, dy);
4688
19.5k
            break;
4689
1.62k
          case 32:
4690
1.62k
            dr_prediction_z3_32x64_avx2(dst, stride, left, upsample_left, dy);
4691
1.62k
            break;
4692
65.6k
        }
4693
65.6k
      } else {
4694
31.2k
        switch (bw) {
4695
0
#if !CONFIG_REALTIME_ONLY || CONFIG_AV1_DECODER
4696
16.9k
          case 4:
4697
16.9k
            dr_prediction_z3_4x16_avx2(dst, stride, left, upsample_left, dy);
4698
16.9k
            break;
4699
9.90k
          case 8:
4700
9.90k
            dr_prediction_z3_8x32_avx2(dst, stride, left, upsample_left, dy);
4701
9.90k
            break;
4702
4.46k
          case 16:
4703
4.46k
            dr_prediction_z3_16x64_avx2(dst, stride, left, upsample_left, dy);
4704
4.46k
            break;
4705
31.2k
#endif  // !CONFIG_REALTIME_ONLY || CONFIG_AV1_DECODER
4706
31.2k
        }
4707
31.2k
      }
4708
204k
    } else {
4709
204k
      if (bh + bh == bw) {
4710
100k
        switch (bh) {
4711
37.6k
          case 4:
4712
37.6k
            dr_prediction_z3_8x4_avx2(dst, stride, left, upsample_left, dy);
4713
37.6k
            break;
4714
44.2k
          case 8:
4715
44.2k
            dr_prediction_z3_16x8_avx2(dst, stride, left, upsample_left, dy);
4716
44.2k
            break;
4717
15.8k
          case 16:
4718
15.8k
            dr_prediction_z3_32x16_avx2(dst, stride, left, upsample_left, dy);
4719
15.8k
            break;
4720
2.63k
          case 32:
4721
2.63k
            dr_prediction_z3_64x32_avx2(dst, stride, left, upsample_left, dy);
4722
2.63k
            break;
4723
100k
        }
4724
104k
      } else {
4725
104k
        switch (bh) {
4726
0
#if !CONFIG_REALTIME_ONLY || CONFIG_AV1_DECODER
4727
55.2k
          case 4:
4728
55.2k
            dr_prediction_z3_16x4_avx2(dst, stride, left, upsample_left, dy);
4729
55.2k
            break;
4730
37.9k
          case 8:
4731
37.9k
            dr_prediction_z3_32x8_avx2(dst, stride, left, upsample_left, dy);
4732
37.9k
            break;
4733
11.2k
          case 16:
4734
11.2k
            dr_prediction_z3_64x16_avx2(dst, stride, left, upsample_left, dy);
4735
11.2k
            break;
4736
104k
#endif  // !CONFIG_REALTIME_ONLY || CONFIG_AV1_DECODER
4737
104k
        }
4738
104k
      }
4739
204k
    }
4740
301k
  }
4741
639k
}