summaryrefslogtreecommitdiffstats
path: root/third_party/aom/av1/common/arm/highbd_reconinter_neon.c
blob: da7f6c57d0fd4ca2ffe41e39c43b30dacaac120a (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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
/*
 *
 * Copyright (c) 2023, 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 <arm_neon.h>
#include <assert.h>
#include <stdbool.h>

#include "aom_dsp/arm/mem_neon.h"
#include "aom_dsp/blend.h"
#include "aom_ports/mem.h"
#include "config/av1_rtcd.h"

static INLINE void diffwtd_mask_highbd_neon(uint8_t *mask, bool inverse,
                                            const uint16_t *src0,
                                            int src0_stride,
                                            const uint16_t *src1,
                                            int src1_stride, int h, int w,
                                            const unsigned int bd) {
  assert(DIFF_FACTOR > 0);
  uint8x16_t max_alpha = vdupq_n_u8(AOM_BLEND_A64_MAX_ALPHA);
  uint8x16_t mask_base = vdupq_n_u8(38);
  uint8x16_t mask_diff = vdupq_n_u8(AOM_BLEND_A64_MAX_ALPHA - 38);

  if (bd == 8) {
    if (w >= 16) {
      do {
        uint8_t *mask_ptr = mask;
        const uint16_t *src0_ptr = src0;
        const uint16_t *src1_ptr = src1;
        int width = w;
        do {
          uint16x8_t s0_lo = vld1q_u16(src0_ptr);
          uint16x8_t s0_hi = vld1q_u16(src0_ptr + 8);
          uint16x8_t s1_lo = vld1q_u16(src1_ptr);
          uint16x8_t s1_hi = vld1q_u16(src1_ptr + 8);

          uint16x8_t diff_lo_u16 = vabdq_u16(s0_lo, s1_lo);
          uint16x8_t diff_hi_u16 = vabdq_u16(s0_hi, s1_hi);
          uint8x8_t diff_lo_u8 = vshrn_n_u16(diff_lo_u16, DIFF_FACTOR_LOG2);
          uint8x8_t diff_hi_u8 = vshrn_n_u16(diff_hi_u16, DIFF_FACTOR_LOG2);
          uint8x16_t diff = vcombine_u8(diff_lo_u8, diff_hi_u8);

          uint8x16_t m;
          if (inverse) {
            m = vqsubq_u8(mask_diff, diff);
          } else {
            m = vminq_u8(vaddq_u8(diff, mask_base), max_alpha);
          }

          vst1q_u8(mask_ptr, m);

          src0_ptr += 16;
          src1_ptr += 16;
          mask_ptr += 16;
          width -= 16;
        } while (width != 0);
        mask += w;
        src0 += src0_stride;
        src1 += src1_stride;
      } while (--h != 0);
    } else if (w == 8) {
      do {
        uint8_t *mask_ptr = mask;
        const uint16_t *src0_ptr = src0;
        const uint16_t *src1_ptr = src1;
        int width = w;
        do {
          uint16x8_t s0 = vld1q_u16(src0_ptr);
          uint16x8_t s1 = vld1q_u16(src1_ptr);

          uint16x8_t diff_u16 = vabdq_u16(s0, s1);
          uint8x8_t diff_u8 = vshrn_n_u16(diff_u16, DIFF_FACTOR_LOG2);
          uint8x8_t m;
          if (inverse) {
            m = vqsub_u8(vget_low_u8(mask_diff), diff_u8);
          } else {
            m = vmin_u8(vadd_u8(diff_u8, vget_low_u8(mask_base)),
                        vget_low_u8(max_alpha));
          }

          vst1_u8(mask_ptr, m);

          src0_ptr += 8;
          src1_ptr += 8;
          mask_ptr += 8;
          width -= 8;
        } while (width != 0);
        mask += w;
        src0 += src0_stride;
        src1 += src1_stride;
      } while (--h != 0);
    } else if (w == 4) {
      do {
        uint16x8_t s0 = load_unaligned_u16_4x2(src0, src0_stride);
        uint16x8_t s1 = load_unaligned_u16_4x2(src1, src1_stride);

        uint16x8_t diff_u16 = vabdq_u16(s0, s1);
        uint8x8_t diff_u8 = vshrn_n_u16(diff_u16, DIFF_FACTOR_LOG2);
        uint8x8_t m;
        if (inverse) {
          m = vqsub_u8(vget_low_u8(mask_diff), diff_u8);
        } else {
          m = vmin_u8(vadd_u8(diff_u8, vget_low_u8(mask_base)),
                      vget_low_u8(max_alpha));
        }

        store_u8x4_strided_x2(mask, w, m);

        src0 += 2 * src0_stride;
        src1 += 2 * src1_stride;
        mask += 2 * w;
        h -= 2;
      } while (h != 0);
    }
  } else if (bd == 10) {
    if (w >= 16) {
      do {
        uint8_t *mask_ptr = mask;
        const uint16_t *src0_ptr = src0;
        const uint16_t *src1_ptr = src1;
        int width = w;
        do {
          uint16x8_t s0_lo = vld1q_u16(src0_ptr);
          uint16x8_t s0_hi = vld1q_u16(src0_ptr + 8);
          uint16x8_t s1_lo = vld1q_u16(src1_ptr);
          uint16x8_t s1_hi = vld1q_u16(src1_ptr + 8);

          uint16x8_t diff_lo_u16 = vabdq_u16(s0_lo, s1_lo);
          uint16x8_t diff_hi_u16 = vabdq_u16(s0_hi, s1_hi);
          uint8x8_t diff_lo_u8 = vshrn_n_u16(diff_lo_u16, 2 + DIFF_FACTOR_LOG2);
          uint8x8_t diff_hi_u8 = vshrn_n_u16(diff_hi_u16, 2 + DIFF_FACTOR_LOG2);
          uint8x16_t diff = vcombine_u8(diff_lo_u8, diff_hi_u8);

          uint8x16_t m;
          if (inverse) {
            m = vqsubq_u8(mask_diff, diff);
          } else {
            m = vminq_u8(vaddq_u8(diff, mask_base), max_alpha);
          }

          vst1q_u8(mask_ptr, m);

          src0_ptr += 16;
          src1_ptr += 16;
          mask_ptr += 16;
          width -= 16;
        } while (width != 0);
        mask += w;
        src0 += src0_stride;
        src1 += src1_stride;
      } while (--h != 0);
    } else if (w == 8) {
      do {
        uint8_t *mask_ptr = mask;
        const uint16_t *src0_ptr = src0;
        const uint16_t *src1_ptr = src1;
        int width = w;
        do {
          uint16x8_t s0 = vld1q_u16(src0_ptr);
          uint16x8_t s1 = vld1q_u16(src1_ptr);

          uint16x8_t diff_u16 = vabdq_u16(s0, s1);
          uint8x8_t diff_u8 = vshrn_n_u16(diff_u16, 2 + DIFF_FACTOR_LOG2);
          uint8x8_t m;
          if (inverse) {
            m = vqsub_u8(vget_low_u8(mask_diff), diff_u8);
          } else {
            m = vmin_u8(vadd_u8(diff_u8, vget_low_u8(mask_base)),
                        vget_low_u8(max_alpha));
          }

          vst1_u8(mask_ptr, m);

          src0_ptr += 8;
          src1_ptr += 8;
          mask_ptr += 8;
          width -= 8;
        } while (width != 0);
        mask += w;
        src0 += src0_stride;
        src1 += src1_stride;
      } while (--h != 0);
    } else if (w == 4) {
      do {
        uint16x8_t s0 = load_unaligned_u16_4x2(src0, src0_stride);
        uint16x8_t s1 = load_unaligned_u16_4x2(src1, src1_stride);

        uint16x8_t diff_u16 = vabdq_u16(s0, s1);
        uint8x8_t diff_u8 = vshrn_n_u16(diff_u16, 2 + DIFF_FACTOR_LOG2);
        uint8x8_t m;
        if (inverse) {
          m = vqsub_u8(vget_low_u8(mask_diff), diff_u8);
        } else {
          m = vmin_u8(vadd_u8(diff_u8, vget_low_u8(mask_base)),
                      vget_low_u8(max_alpha));
        }

        store_u8x4_strided_x2(mask, w, m);

        src0 += 2 * src0_stride;
        src1 += 2 * src1_stride;
        mask += 2 * w;
        h -= 2;
      } while (h != 0);
    }
  } else {
    assert(bd == 12);
    if (w >= 16) {
      do {
        uint8_t *mask_ptr = mask;
        const uint16_t *src0_ptr = src0;
        const uint16_t *src1_ptr = src1;
        int width = w;
        do {
          uint16x8_t s0_lo = vld1q_u16(src0_ptr);
          uint16x8_t s0_hi = vld1q_u16(src0_ptr + 8);
          uint16x8_t s1_lo = vld1q_u16(src1_ptr);
          uint16x8_t s1_hi = vld1q_u16(src1_ptr + 8);

          uint16x8_t diff_lo_u16 = vabdq_u16(s0_lo, s1_lo);
          uint16x8_t diff_hi_u16 = vabdq_u16(s0_hi, s1_hi);
          uint8x8_t diff_lo_u8 = vshrn_n_u16(diff_lo_u16, 4 + DIFF_FACTOR_LOG2);
          uint8x8_t diff_hi_u8 = vshrn_n_u16(diff_hi_u16, 4 + DIFF_FACTOR_LOG2);
          uint8x16_t diff = vcombine_u8(diff_lo_u8, diff_hi_u8);

          uint8x16_t m;
          if (inverse) {
            m = vqsubq_u8(mask_diff, diff);
          } else {
            m = vminq_u8(vaddq_u8(diff, mask_base), max_alpha);
          }

          vst1q_u8(mask_ptr, m);

          src0_ptr += 16;
          src1_ptr += 16;
          mask_ptr += 16;
          width -= 16;
        } while (width != 0);
        mask += w;
        src0 += src0_stride;
        src1 += src1_stride;
      } while (--h != 0);
    } else if (w == 8) {
      do {
        uint8_t *mask_ptr = mask;
        const uint16_t *src0_ptr = src0;
        const uint16_t *src1_ptr = src1;
        int width = w;
        do {
          uint16x8_t s0 = vld1q_u16(src0_ptr);
          uint16x8_t s1 = vld1q_u16(src1_ptr);

          uint16x8_t diff_u16 = vabdq_u16(s0, s1);
          uint8x8_t diff_u8 = vshrn_n_u16(diff_u16, 4 + DIFF_FACTOR_LOG2);
          uint8x8_t m;
          if (inverse) {
            m = vqsub_u8(vget_low_u8(mask_diff), diff_u8);
          } else {
            m = vmin_u8(vadd_u8(diff_u8, vget_low_u8(mask_base)),
                        vget_low_u8(max_alpha));
          }

          vst1_u8(mask_ptr, m);

          src0_ptr += 8;
          src1_ptr += 8;
          mask_ptr += 8;
          width -= 8;
        } while (width != 0);
        mask += w;
        src0 += src0_stride;
        src1 += src1_stride;
      } while (--h != 0);
    } else if (w == 4) {
      do {
        uint16x8_t s0 = load_unaligned_u16_4x2(src0, src0_stride);
        uint16x8_t s1 = load_unaligned_u16_4x2(src1, src1_stride);

        uint16x8_t diff_u16 = vabdq_u16(s0, s1);
        uint8x8_t diff_u8 = vshrn_n_u16(diff_u16, 4 + DIFF_FACTOR_LOG2);
        uint8x8_t m;
        if (inverse) {
          m = vqsub_u8(vget_low_u8(mask_diff), diff_u8);
        } else {
          m = vmin_u8(vadd_u8(diff_u8, vget_low_u8(mask_base)),
                      vget_low_u8(max_alpha));
        }

        store_u8x4_strided_x2(mask, w, m);

        src0 += 2 * src0_stride;
        src1 += 2 * src1_stride;
        mask += 2 * w;
        h -= 2;
      } while (h != 0);
    }
  }
}

void av1_build_compound_diffwtd_mask_highbd_neon(
    uint8_t *mask, DIFFWTD_MASK_TYPE mask_type, const uint8_t *src0,
    int src0_stride, const uint8_t *src1, int src1_stride, int h, int w,
    int bd) {
  assert(h % 4 == 0);
  assert(w % 4 == 0);
  assert(mask_type == DIFFWTD_38_INV || mask_type == DIFFWTD_38);

  if (mask_type == DIFFWTD_38) {
    diffwtd_mask_highbd_neon(mask, /*inverse=*/false, CONVERT_TO_SHORTPTR(src0),
                             src0_stride, CONVERT_TO_SHORTPTR(src1),
                             src1_stride, h, w, bd);
  } else {  // mask_type == DIFFWTD_38_INV
    diffwtd_mask_highbd_neon(mask, /*inverse=*/true, CONVERT_TO_SHORTPTR(src0),
                             src0_stride, CONVERT_TO_SHORTPTR(src1),
                             src1_stride, h, w, bd);
  }
}