summaryrefslogtreecommitdiffstats
path: root/third_party/aom/aom_dsp/x86/highbd_intrapred_avx2.c
blob: 41b55c98520dd43761bcc0fcd0a96f5f5a706afe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/*
 * Copyright (c) 2017, Alliance for Open Media. All rights reserved
 *
 * This source code is subject to the terms of the BSD 2 Clause License and
 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
 * was not distributed with this source code in the LICENSE file, you can
 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
 * Media Patent License 1.0 was not distributed with this source code in the
 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
 */

#include <immintrin.h>

#include "./aom_dsp_rtcd.h"

// -----------------------------------------------------------------------------
// D45E_PRED
/*
; ------------------------------------------
; input: x, y, z, result
;
; trick from pascal
; (x+2y+z+2)>>2 can be calculated as:
; result = avg(x,z)
; result -= xor(x,z) & 1
; result = avg(result,y)
; ------------------------------------------
*/
static INLINE __m256i avg3_epu16(const __m256i *x, const __m256i *y,
                                 const __m256i *z) {
  const __m256i one = _mm256_set1_epi16(1);
  const __m256i a = _mm256_avg_epu16(*x, *z);
  const __m256i b =
      _mm256_subs_epu16(a, _mm256_and_si256(_mm256_xor_si256(*x, *z), one));
  return _mm256_avg_epu16(b, *y);
}

static INLINE void d45e_w16(const __m256i *a0, const __m256i *a1,
                            const __m256i *a2, uint16_t **dst,
                            ptrdiff_t stride) {
  const __m256i y = avg3_epu16(a0, a1, a2);
  _mm256_storeu_si256((__m256i *)*dst, y);
  *dst += stride;
}

void aom_highbd_d45e_predictor_16x8_avx2(uint16_t *dst, ptrdiff_t stride,
                                         const uint16_t *above,
                                         const uint16_t *left, int bd) {
  (void)left;
  (void)bd;
  __m256i x0 = _mm256_loadu_si256((const __m256i *)above);
  __m256i x1 = _mm256_loadu_si256((const __m256i *)(above + 1));
  __m256i x2 = _mm256_loadu_si256((const __m256i *)(above + 2));

  d45e_w16(&x0, &x1, &x2, &dst, stride);

  int i = 3;
  do {
    x0 = _mm256_loadu_si256((const __m256i *)(above + i++));
    d45e_w16(&x1, &x2, &x0, &dst, stride);

    x1 = _mm256_loadu_si256((const __m256i *)(above + i++));
    d45e_w16(&x2, &x0, &x1, &dst, stride);

    x2 = _mm256_loadu_si256((const __m256i *)(above + i++));
    d45e_w16(&x0, &x1, &x2, &dst, stride);
  } while (i < 9);

  x0 = _mm256_loadu_si256((const __m256i *)(above + 9));
  x0 = _mm256_insert_epi16(x0, above[23], 15);
  const __m256i y = avg3_epu16(&x1, &x2, &x0);
  _mm256_storeu_si256((__m256i *)dst, y);
}

void aom_highbd_d45e_predictor_16x16_avx2(uint16_t *dst, ptrdiff_t stride,
                                          const uint16_t *above,
                                          const uint16_t *left, int bd) {
  (void)left;
  (void)bd;
  __m256i x0 = _mm256_loadu_si256((const __m256i *)above);
  __m256i x1 = _mm256_loadu_si256((const __m256i *)(above + 1));
  __m256i x2 = _mm256_loadu_si256((const __m256i *)(above + 2));

  d45e_w16(&x0, &x1, &x2, &dst, stride);

  int i = 3;
  do {
    x0 = _mm256_loadu_si256((const __m256i *)(above + i++));
    d45e_w16(&x1, &x2, &x0, &dst, stride);

    x1 = _mm256_loadu_si256((const __m256i *)(above + i++));
    d45e_w16(&x2, &x0, &x1, &dst, stride);

    x2 = _mm256_loadu_si256((const __m256i *)(above + i++));
    d45e_w16(&x0, &x1, &x2, &dst, stride);
  } while (i < 15);

  x0 = _mm256_loadu_si256((const __m256i *)(above + 15));
  d45e_w16(&x1, &x2, &x0, &dst, stride);

  x1 = _mm256_loadu_si256((const __m256i *)(above + 16));
  d45e_w16(&x2, &x0, &x1, &dst, stride);

  x2 = _mm256_loadu_si256((const __m256i *)(above + 17));
  x2 = _mm256_insert_epi16(x2, above[31], 15);
  const __m256i y = avg3_epu16(&x0, &x1, &x2);
  _mm256_storeu_si256((__m256i *)dst, y);
}

void aom_highbd_d45e_predictor_16x32_avx2(uint16_t *dst, ptrdiff_t stride,
                                          const uint16_t *above,
                                          const uint16_t *left, int bd) {
  (void)left;
  (void)bd;
  __m256i x0 = _mm256_loadu_si256((const __m256i *)above);
  __m256i x1 = _mm256_loadu_si256((const __m256i *)(above + 1));
  __m256i x2 = _mm256_loadu_si256((const __m256i *)(above + 2));

  d45e_w16(&x0, &x1, &x2, &dst, stride);

  int i = 3;
  do {
    x0 = _mm256_loadu_si256((const __m256i *)(above + i++));
    d45e_w16(&x1, &x2, &x0, &dst, stride);

    x1 = _mm256_loadu_si256((const __m256i *)(above + i++));
    d45e_w16(&x2, &x0, &x1, &dst, stride);

    x2 = _mm256_loadu_si256((const __m256i *)(above + i++));
    d45e_w16(&x0, &x1, &x2, &dst, stride);
  } while (i < 33);

  x0 = _mm256_loadu_si256((const __m256i *)(above + 33));
  x0 = _mm256_insert_epi16(x0, above[47], 15);
  const __m256i y = avg3_epu16(&x1, &x2, &x0);
  _mm256_storeu_si256((__m256i *)dst, y);
}

void aom_highbd_d45e_predictor_32x16_avx2(uint16_t *dst, ptrdiff_t stride,
                                          const uint16_t *above,
                                          const uint16_t *left, int bd) {
  (void)left;
  (void)bd;
  __m256i x0 = _mm256_loadu_si256((const __m256i *)above);
  __m256i x1 = _mm256_loadu_si256((const __m256i *)(above + 1));
  __m256i x2 = _mm256_loadu_si256((const __m256i *)(above + 2));
  __m256i y0 = _mm256_loadu_si256((const __m256i *)(above + 16));
  __m256i y1 = _mm256_loadu_si256((const __m256i *)(above + 17));
  __m256i y2 = _mm256_loadu_si256((const __m256i *)(above + 18));

  uint16_t *dst1 = dst;
  uint16_t *dst2 = dst + 16;

  d45e_w16(&x0, &x1, &x2, &dst1, stride);
  d45e_w16(&y0, &y1, &y2, &dst2, stride);

  int i = 3;
  do {
    x0 = _mm256_loadu_si256((const __m256i *)(above + i));
    d45e_w16(&x1, &x2, &x0, &dst1, stride);
    y0 = _mm256_loadu_si256((const __m256i *)(above + 16 + i++));
    d45e_w16(&y1, &y2, &y0, &dst2, stride);

    x1 = _mm256_loadu_si256((const __m256i *)(above + i));
    d45e_w16(&x2, &x0, &x1, &dst1, stride);
    y1 = _mm256_loadu_si256((const __m256i *)(above + 16 + i++));
    d45e_w16(&y2, &y0, &y1, &dst2, stride);

    x2 = _mm256_loadu_si256((const __m256i *)(above + i));
    d45e_w16(&x0, &x1, &x2, &dst1, stride);
    y2 = _mm256_loadu_si256((const __m256i *)(above + 16 + i++));
    d45e_w16(&y0, &y1, &y2, &dst2, stride);
  } while (i < 15);

  x0 = _mm256_loadu_si256((const __m256i *)(above + 15));
  d45e_w16(&x1, &x2, &x0, &dst1, stride);
  y0 = _mm256_loadu_si256((const __m256i *)(above + 16 + 15));
  d45e_w16(&y1, &y2, &y0, &dst2, stride);

  x1 = _mm256_loadu_si256((const __m256i *)(above + 16));
  d45e_w16(&x2, &x0, &x1, &dst1, stride);
  y1 = _mm256_loadu_si256((const __m256i *)(above + 16 + 16));
  d45e_w16(&y2, &y0, &y1, &dst2, stride);

  x2 = _mm256_loadu_si256((const __m256i *)(above + 17));
  __m256i u = avg3_epu16(&x0, &x1, &x2);
  _mm256_storeu_si256((__m256i *)dst1, u);

  y2 = _mm256_loadu_si256((const __m256i *)(above + 16 + 17));
  y2 = _mm256_insert_epi16(y2, above[47], 15);
  u = avg3_epu16(&y0, &y1, &y2);
  _mm256_storeu_si256((__m256i *)dst2, u);
}

void aom_highbd_d45e_predictor_32x32_avx2(uint16_t *dst, ptrdiff_t stride,
                                          const uint16_t *above,
                                          const uint16_t *left, int bd) {
  (void)left;
  (void)bd;
  __m256i x0 = _mm256_loadu_si256((const __m256i *)above);
  __m256i x1 = _mm256_loadu_si256((const __m256i *)(above + 1));
  __m256i x2 = _mm256_loadu_si256((const __m256i *)(above + 2));
  __m256i y0 = _mm256_loadu_si256((const __m256i *)(above + 16));
  __m256i y1 = _mm256_loadu_si256((const __m256i *)(above + 17));
  __m256i y2 = _mm256_loadu_si256((const __m256i *)(above + 18));

  uint16_t *dst1 = dst;
  uint16_t *dst2 = dst + 16;

  d45e_w16(&x0, &x1, &x2, &dst1, stride);
  d45e_w16(&y0, &y1, &y2, &dst2, stride);

  int i = 3;
  do {
    x0 = _mm256_loadu_si256((const __m256i *)(above + i));
    d45e_w16(&x1, &x2, &x0, &dst1, stride);
    y0 = _mm256_loadu_si256((const __m256i *)(above + 16 + i++));
    d45e_w16(&y1, &y2, &y0, &dst2, stride);

    x1 = _mm256_loadu_si256((const __m256i *)(above + i));
    d45e_w16(&x2, &x0, &x1, &dst1, stride);
    y1 = _mm256_loadu_si256((const __m256i *)(above + 16 + i++));
    d45e_w16(&y2, &y0, &y1, &dst2, stride);

    x2 = _mm256_loadu_si256((const __m256i *)(above + i));
    d45e_w16(&x0, &x1, &x2, &dst1, stride);
    y2 = _mm256_loadu_si256((const __m256i *)(above + 16 + i++));
    d45e_w16(&y0, &y1, &y2, &dst2, stride);
  } while (i < 33);

  x0 = _mm256_loadu_si256((const __m256i *)(above + 33));
  __m256i u = avg3_epu16(&x1, &x2, &x0);
  _mm256_storeu_si256((__m256i *)dst1, u);

  y0 = _mm256_loadu_si256((const __m256i *)(above + 16 + 33));
  y0 = _mm256_insert_epi16(y0, above[63], 15);
  u = avg3_epu16(&y1, &y2, &y0);
  _mm256_storeu_si256((__m256i *)dst2, u);
}