summaryrefslogtreecommitdiffstats
path: root/media/libvpx/libvpx/vpx_dsp/arm/highbd_subpel_variance_neon.c
blob: 683df5797ab11aa447b3ed0d7622946480f1a888 (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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
/*
 *  Copyright (c) 2023 The WebM project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#include <arm_neon.h>
#include <assert.h>

#include "./vpx_dsp_rtcd.h"
#include "./vpx_config.h"

#include "vpx/vpx_integer.h"
#include "vpx_dsp/arm/mem_neon.h"

// The bilinear filters look like this:
//
// {{ 128,  0 }, { 112, 16 }, { 96, 32 }, { 80,  48 },
//  {  64, 64 }, {  48, 80 }, { 32, 96 }, { 16, 112 }}
//
// We can factor out the highest common multiple, such that the sum of both
// weights will be 8 instead of 128. The benefits of this are two-fold:
//
// 1) We can infer the filter values from the filter_offset parameter in the
// bilinear filter functions below - we don't have to actually load the values
// from memory:
// f0 = 8 - filter_offset
// f1 = filter_offset
//
// 2) Scaling the pixel values by 8, instead of 128 enables us to operate on
// 16-bit data types at all times, rather than widening out to 32-bit and
// requiring double the number of data processing instructions. (12-bit * 8 =
// 15-bit.)

// Process a block exactly 4 wide and any height.
static void highbd_var_filter_block2d_bil_w4(const uint16_t *src_ptr,
                                             uint16_t *dst_ptr, int src_stride,
                                             int pixel_step, int dst_height,
                                             int filter_offset) {
  const uint16x4_t f0 = vdup_n_u16(8 - filter_offset);
  const uint16x4_t f1 = vdup_n_u16(filter_offset);

  int i = dst_height;
  do {
    uint16x4_t s0 = load_unaligned_u16(src_ptr);
    uint16x4_t s1 = load_unaligned_u16(src_ptr + pixel_step);

    uint16x4_t blend = vmul_u16(s0, f0);
    blend = vmla_u16(blend, s1, f1);
    blend = vrshr_n_u16(blend, 3);

    vst1_u16(dst_ptr, blend);

    src_ptr += src_stride;
    dst_ptr += 4;
  } while (--i != 0);
}

// Process a block which is a multiple of 8 and any height.
static void highbd_var_filter_block2d_bil_large(const uint16_t *src_ptr,
                                                uint16_t *dst_ptr,
                                                int src_stride, int pixel_step,
                                                int dst_width, int dst_height,
                                                int filter_offset) {
  const uint16x8_t f0 = vdupq_n_u16(8 - filter_offset);
  const uint16x8_t f1 = vdupq_n_u16(filter_offset);

  int i = dst_height;
  do {
    int j = 0;
    do {
      uint16x8_t s0 = vld1q_u16(src_ptr + j);
      uint16x8_t s1 = vld1q_u16(src_ptr + j + pixel_step);

      uint16x8_t blend = vmulq_u16(s0, f0);
      blend = vmlaq_u16(blend, s1, f1);
      blend = vrshrq_n_u16(blend, 3);

      vst1q_u16(dst_ptr + j, blend);

      j += 8;
    } while (j < dst_width);

    src_ptr += src_stride;
    dst_ptr += dst_width;
  } while (--i != 0);
}

static void highbd_var_filter_block2d_bil_w8(const uint16_t *src_ptr,
                                             uint16_t *dst_ptr, int src_stride,
                                             int pixel_step, int dst_height,
                                             int filter_offset) {
  highbd_var_filter_block2d_bil_large(src_ptr, dst_ptr, src_stride, pixel_step,
                                      8, dst_height, filter_offset);
}
static void highbd_var_filter_block2d_bil_w16(const uint16_t *src_ptr,
                                              uint16_t *dst_ptr, int src_stride,
                                              int pixel_step, int dst_height,
                                              int filter_offset) {
  highbd_var_filter_block2d_bil_large(src_ptr, dst_ptr, src_stride, pixel_step,
                                      16, dst_height, filter_offset);
}
static void highbd_var_filter_block2d_bil_w32(const uint16_t *src_ptr,
                                              uint16_t *dst_ptr, int src_stride,
                                              int pixel_step, int dst_height,
                                              int filter_offset) {
  highbd_var_filter_block2d_bil_large(src_ptr, dst_ptr, src_stride, pixel_step,
                                      32, dst_height, filter_offset);
}
static void highbd_var_filter_block2d_bil_w64(const uint16_t *src_ptr,
                                              uint16_t *dst_ptr, int src_stride,
                                              int pixel_step, int dst_height,
                                              int filter_offset) {
  highbd_var_filter_block2d_bil_large(src_ptr, dst_ptr, src_stride, pixel_step,
                                      64, dst_height, filter_offset);
}

static void highbd_var_filter_block2d_avg(const uint16_t *src_ptr,
                                          uint16_t *dst_ptr, int src_stride,
                                          int pixel_step, int dst_width,
                                          int dst_height) {
  int i = dst_height;

  // We only specialize on the filter values for large block sizes (>= 16x16.)
  assert(dst_width >= 16 && dst_width % 16 == 0);

  do {
    int j = 0;
    do {
      uint16x8_t s0 = vld1q_u16(src_ptr + j);
      uint16x8_t s1 = vld1q_u16(src_ptr + j + pixel_step);
      uint16x8_t avg = vrhaddq_u16(s0, s1);
      vst1q_u16(dst_ptr + j, avg);

      j += 8;
    } while (j < dst_width);

    src_ptr += src_stride;
    dst_ptr += dst_width;
  } while (--i != 0);
}

#define HBD_SUBPEL_VARIANCE_WXH_NEON(bitdepth, w, h)                           \
  unsigned int vpx_highbd_##bitdepth##_sub_pixel_variance##w##x##h##_neon(     \
      const uint8_t *src, int src_stride, int xoffset, int yoffset,            \
      const uint8_t *ref, int ref_stride, uint32_t *sse) {                     \
    uint16_t tmp0[w * (h + 1)];                                                \
    uint16_t tmp1[w * h];                                                      \
    uint16_t *src_ptr = CONVERT_TO_SHORTPTR(src);                              \
                                                                               \
    highbd_var_filter_block2d_bil_w##w(src_ptr, tmp0, src_stride, 1, (h + 1),  \
                                       xoffset);                               \
    highbd_var_filter_block2d_bil_w##w(tmp0, tmp1, w, w, h, yoffset);          \
                                                                               \
    return vpx_highbd_##bitdepth##_variance##w##x##h(CONVERT_TO_BYTEPTR(tmp1), \
                                                     w, ref, ref_stride, sse); \
  }

#define HBD_SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON(bitdepth, w, h)               \
  unsigned int vpx_highbd_##bitdepth##_sub_pixel_variance##w##x##h##_neon(     \
      const uint8_t *src, int src_stride, int xoffset, int yoffset,            \
      const uint8_t *ref, int ref_stride, unsigned int *sse) {                 \
    uint16_t *src_ptr = CONVERT_TO_SHORTPTR(src);                              \
                                                                               \
    if (xoffset == 0) {                                                        \
      if (yoffset == 0) {                                                      \
        return vpx_highbd_##bitdepth##_variance##w##x##h##_neon(               \
            CONVERT_TO_BYTEPTR(src_ptr), src_stride, ref, ref_stride, sse);    \
      } else if (yoffset == 4) {                                               \
        uint16_t tmp[w * h];                                                   \
        highbd_var_filter_block2d_avg(src_ptr, tmp, src_stride, src_stride, w, \
                                      h);                                      \
        return vpx_highbd_##bitdepth##_variance##w##x##h##_neon(               \
            CONVERT_TO_BYTEPTR(tmp), w, ref, ref_stride, sse);                 \
      } else {                                                                 \
        uint16_t tmp[w * h];                                                   \
        highbd_var_filter_block2d_bil_w##w(src_ptr, tmp, src_stride,           \
                                           src_stride, h, yoffset);            \
        return vpx_highbd_##bitdepth##_variance##w##x##h##_neon(               \
            CONVERT_TO_BYTEPTR(tmp), w, ref, ref_stride, sse);                 \
      }                                                                        \
    } else if (xoffset == 4) {                                                 \
      uint16_t tmp0[w * (h + 1)];                                              \
      if (yoffset == 0) {                                                      \
        highbd_var_filter_block2d_avg(src_ptr, tmp0, src_stride, 1, w, h);     \
        return vpx_highbd_##bitdepth##_variance##w##x##h##_neon(               \
            CONVERT_TO_BYTEPTR(tmp0), w, ref, ref_stride, sse);                \
      } else if (yoffset == 4) {                                               \
        uint16_t tmp1[w * (h + 1)];                                            \
        highbd_var_filter_block2d_avg(src_ptr, tmp0, src_stride, 1, w,         \
                                      (h + 1));                                \
        highbd_var_filter_block2d_avg(tmp0, tmp1, w, w, w, h);                 \
        return vpx_highbd_##bitdepth##_variance##w##x##h##_neon(               \
            CONVERT_TO_BYTEPTR(tmp1), w, ref, ref_stride, sse);                \
      } else {                                                                 \
        uint16_t tmp1[w * (h + 1)];                                            \
        highbd_var_filter_block2d_avg(src_ptr, tmp0, src_stride, 1, w,         \
                                      (h + 1));                                \
        highbd_var_filter_block2d_bil_w##w(tmp0, tmp1, w, w, h, yoffset);      \
        return vpx_highbd_##bitdepth##_variance##w##x##h##_neon(               \
            CONVERT_TO_BYTEPTR(tmp1), w, ref, ref_stride, sse);                \
      }                                                                        \
    } else {                                                                   \
      uint16_t tmp0[w * (h + 1)];                                              \
      if (yoffset == 0) {                                                      \
        highbd_var_filter_block2d_bil_w##w(src_ptr, tmp0, src_stride, 1, h,    \
                                           xoffset);                           \
        return vpx_highbd_##bitdepth##_variance##w##x##h##_neon(               \
            CONVERT_TO_BYTEPTR(tmp0), w, ref, ref_stride, sse);                \
      } else if (yoffset == 4) {                                               \
        uint16_t tmp1[w * h];                                                  \
        highbd_var_filter_block2d_bil_w##w(src_ptr, tmp0, src_stride, 1,       \
                                           (h + 1), xoffset);                  \
        highbd_var_filter_block2d_avg(tmp0, tmp1, w, w, w, h);                 \
        return vpx_highbd_##bitdepth##_variance##w##x##h##_neon(               \
            CONVERT_TO_BYTEPTR(tmp1), w, ref, ref_stride, sse);                \
      } else {                                                                 \
        uint16_t tmp1[w * h];                                                  \
        highbd_var_filter_block2d_bil_w##w(src_ptr, tmp0, src_stride, 1,       \
                                           (h + 1), xoffset);                  \
        highbd_var_filter_block2d_bil_w##w(tmp0, tmp1, w, w, h, yoffset);      \
        return vpx_highbd_##bitdepth##_variance##w##x##h##_neon(               \
            CONVERT_TO_BYTEPTR(tmp1), w, ref, ref_stride, sse);                \
      }                                                                        \
    }                                                                          \
  }

// 8-bit
HBD_SUBPEL_VARIANCE_WXH_NEON(8, 4, 4)
HBD_SUBPEL_VARIANCE_WXH_NEON(8, 4, 8)

HBD_SUBPEL_VARIANCE_WXH_NEON(8, 8, 4)
HBD_SUBPEL_VARIANCE_WXH_NEON(8, 8, 8)
HBD_SUBPEL_VARIANCE_WXH_NEON(8, 8, 16)

HBD_SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON(8, 16, 8)
HBD_SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON(8, 16, 16)
HBD_SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON(8, 16, 32)

HBD_SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON(8, 32, 16)
HBD_SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON(8, 32, 32)
HBD_SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON(8, 32, 64)

HBD_SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON(8, 64, 32)
HBD_SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON(8, 64, 64)

// 10-bit
HBD_SUBPEL_VARIANCE_WXH_NEON(10, 4, 4)
HBD_SUBPEL_VARIANCE_WXH_NEON(10, 4, 8)

HBD_SUBPEL_VARIANCE_WXH_NEON(10, 8, 4)
HBD_SUBPEL_VARIANCE_WXH_NEON(10, 8, 8)
HBD_SUBPEL_VARIANCE_WXH_NEON(10, 8, 16)

HBD_SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON(10, 16, 8)
HBD_SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON(10, 16, 16)
HBD_SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON(10, 16, 32)

HBD_SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON(10, 32, 16)
HBD_SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON(10, 32, 32)
HBD_SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON(10, 32, 64)

HBD_SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON(10, 64, 32)
HBD_SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON(10, 64, 64)

// 12-bit
HBD_SUBPEL_VARIANCE_WXH_NEON(12, 4, 4)
HBD_SUBPEL_VARIANCE_WXH_NEON(12, 4, 8)

HBD_SUBPEL_VARIANCE_WXH_NEON(12, 8, 4)
HBD_SUBPEL_VARIANCE_WXH_NEON(12, 8, 8)
HBD_SUBPEL_VARIANCE_WXH_NEON(12, 8, 16)

HBD_SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON(12, 16, 8)
HBD_SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON(12, 16, 16)
HBD_SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON(12, 16, 32)

HBD_SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON(12, 32, 16)
HBD_SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON(12, 32, 32)
HBD_SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON(12, 32, 64)

HBD_SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON(12, 64, 32)
HBD_SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON(12, 64, 64)

// Combine bilinear filter with vpx_highbd_comp_avg_pred for blocks having
// width 4.
static void highbd_avg_pred_var_filter_block2d_bil_w4(
    const uint16_t *src_ptr, uint16_t *dst_ptr, int src_stride, int pixel_step,
    int dst_height, int filter_offset, const uint16_t *second_pred) {
  const uint16x4_t f0 = vdup_n_u16(8 - filter_offset);
  const uint16x4_t f1 = vdup_n_u16(filter_offset);

  int i = dst_height;
  do {
    uint16x4_t s0 = load_unaligned_u16(src_ptr);
    uint16x4_t s1 = load_unaligned_u16(src_ptr + pixel_step);
    uint16x4_t p = vld1_u16(second_pred);

    uint16x4_t blend = vmul_u16(s0, f0);
    blend = vmla_u16(blend, s1, f1);
    blend = vrshr_n_u16(blend, 3);

    vst1_u16(dst_ptr, vrhadd_u16(blend, p));

    src_ptr += src_stride;
    dst_ptr += 4;
    second_pred += 4;
  } while (--i != 0);
}

// Combine bilinear filter with vpx_highbd_comp_avg_pred for large blocks.
static void highbd_avg_pred_var_filter_block2d_bil_large(
    const uint16_t *src_ptr, uint16_t *dst_ptr, int src_stride, int pixel_step,
    int dst_width, int dst_height, int filter_offset,
    const uint16_t *second_pred) {
  const uint16x8_t f0 = vdupq_n_u16(8 - filter_offset);
  const uint16x8_t f1 = vdupq_n_u16(filter_offset);

  int i = dst_height;
  do {
    int j = 0;
    do {
      uint16x8_t s0 = vld1q_u16(src_ptr + j);
      uint16x8_t s1 = vld1q_u16(src_ptr + j + pixel_step);
      uint16x8_t p = vld1q_u16(second_pred);

      uint16x8_t blend = vmulq_u16(s0, f0);
      blend = vmlaq_u16(blend, s1, f1);
      blend = vrshrq_n_u16(blend, 3);

      vst1q_u16(dst_ptr + j, vrhaddq_u16(blend, p));

      j += 8;
      second_pred += 8;
    } while (j < dst_width);

    src_ptr += src_stride;
    dst_ptr += dst_width;
  } while (--i != 0);
}

static void highbd_avg_pred_var_filter_block2d_bil_w8(
    const uint16_t *src_ptr, uint16_t *dst_ptr, int src_stride, int pixel_step,
    int dst_height, int filter_offset, const uint16_t *second_pred) {
  highbd_avg_pred_var_filter_block2d_bil_large(src_ptr, dst_ptr, src_stride,
                                               pixel_step, 8, dst_height,
                                               filter_offset, second_pred);
}
static void highbd_avg_pred_var_filter_block2d_bil_w16(
    const uint16_t *src_ptr, uint16_t *dst_ptr, int src_stride, int pixel_step,
    int dst_height, int filter_offset, const uint16_t *second_pred) {
  highbd_avg_pred_var_filter_block2d_bil_large(src_ptr, dst_ptr, src_stride,
                                               pixel_step, 16, dst_height,
                                               filter_offset, second_pred);
}
static void highbd_avg_pred_var_filter_block2d_bil_w32(
    const uint16_t *src_ptr, uint16_t *dst_ptr, int src_stride, int pixel_step,
    int dst_height, int filter_offset, const uint16_t *second_pred) {
  highbd_avg_pred_var_filter_block2d_bil_large(src_ptr, dst_ptr, src_stride,
                                               pixel_step, 32, dst_height,
                                               filter_offset, second_pred);
}
static void highbd_avg_pred_var_filter_block2d_bil_w64(
    const uint16_t *src_ptr, uint16_t *dst_ptr, int src_stride, int pixel_step,
    int dst_height, int filter_offset, const uint16_t *second_pred) {
  highbd_avg_pred_var_filter_block2d_bil_large(src_ptr, dst_ptr, src_stride,
                                               pixel_step, 64, dst_height,
                                               filter_offset, second_pred);
}

// Combine averaging subpel filter with vpx_highbd_comp_avg_pred.
static void highbd_avg_pred_var_filter_block2d_avg(
    const uint16_t *src_ptr, uint16_t *dst_ptr, int src_stride, int pixel_step,
    int dst_width, int dst_height, const uint16_t *second_pred) {
  int i = dst_height;

  // We only specialize on the filter values for large block sizes (>= 16x16.)
  assert(dst_width >= 16 && dst_width % 16 == 0);

  do {
    int j = 0;
    do {
      uint16x8_t s0 = vld1q_u16(src_ptr + j);
      uint16x8_t s1 = vld1q_u16(src_ptr + j + pixel_step);
      uint16x8_t avg = vrhaddq_u16(s0, s1);

      uint16x8_t p = vld1q_u16(second_pred);
      avg = vrhaddq_u16(avg, p);

      vst1q_u16(dst_ptr + j, avg);

      j += 8;
      second_pred += 8;
    } while (j < dst_width);

    src_ptr += src_stride;
    dst_ptr += dst_width;
  } while (--i != 0);
}

// Implementation of vpx_highbd_comp_avg_pred for blocks having width >= 16.
static void highbd_avg_pred(const uint16_t *src_ptr, uint16_t *dst_ptr,
                            int src_stride, int dst_width, int dst_height,
                            const uint16_t *second_pred) {
  int i = dst_height;

  // We only specialize on the filter values for large block sizes (>= 16x16.)
  assert(dst_width >= 16 && dst_width % 16 == 0);

  do {
    int j = 0;
    do {
      uint16x8_t s = vld1q_u16(src_ptr + j);
      uint16x8_t p = vld1q_u16(second_pred);

      uint16x8_t avg = vrhaddq_u16(s, p);

      vst1q_u16(dst_ptr + j, avg);

      j += 8;
      second_pred += 8;
    } while (j < dst_width);

    src_ptr += src_stride;
    dst_ptr += dst_width;
  } while (--i != 0);
}

#define HBD_SUBPEL_AVG_VARIANCE_WXH_NEON(bitdepth, w, h)                      \
  uint32_t vpx_highbd_##bitdepth##_sub_pixel_avg_variance##w##x##h##_neon(    \
      const uint8_t *src, int src_stride, int xoffset, int yoffset,           \
      const uint8_t *ref, int ref_stride, uint32_t *sse,                      \
      const uint8_t *second_pred) {                                           \
    uint16_t tmp0[w * (h + 1)];                                               \
    uint16_t tmp1[w * h];                                                     \
    uint16_t *src_ptr = CONVERT_TO_SHORTPTR(src);                             \
                                                                              \
    highbd_var_filter_block2d_bil_w##w(src_ptr, tmp0, src_stride, 1, (h + 1), \
                                       xoffset);                              \
    highbd_avg_pred_var_filter_block2d_bil_w##w(                              \
        tmp0, tmp1, w, w, h, yoffset, CONVERT_TO_SHORTPTR(second_pred));      \
                                                                              \
    return vpx_highbd_##bitdepth##_variance##w##x##h##_neon(                  \
        CONVERT_TO_BYTEPTR(tmp1), w, ref, ref_stride, sse);                   \
  }

#define HBD_SPECIALIZED_SUBPEL_AVG_VARIANCE_WXH_NEON(bitdepth, w, h)           \
  unsigned int vpx_highbd_##bitdepth##_sub_pixel_avg_variance##w##x##h##_neon( \
      const uint8_t *src, int source_stride, int xoffset, int yoffset,         \
      const uint8_t *ref, int ref_stride, unsigned int *sse,                   \
      const uint8_t *second_pred) {                                            \
    uint16_t *src_ptr = CONVERT_TO_SHORTPTR(src);                              \
                                                                               \
    if (xoffset == 0) {                                                        \
      uint16_t tmp[w * h];                                                     \
      if (yoffset == 0) {                                                      \
        highbd_avg_pred(src_ptr, tmp, source_stride, w, h,                     \
                        CONVERT_TO_SHORTPTR(second_pred));                     \
        return vpx_highbd_##bitdepth##_variance##w##x##h##_neon(               \
            CONVERT_TO_BYTEPTR(tmp), w, ref, ref_stride, sse);                 \
      } else if (yoffset == 4) {                                               \
        highbd_avg_pred_var_filter_block2d_avg(                                \
            src_ptr, tmp, source_stride, source_stride, w, h,                  \
            CONVERT_TO_SHORTPTR(second_pred));                                 \
        return vpx_highbd_##bitdepth##_variance##w##x##h##_neon(               \
            CONVERT_TO_BYTEPTR(tmp), w, ref, ref_stride, sse);                 \
      } else {                                                                 \
        highbd_avg_pred_var_filter_block2d_bil_w##w(                           \
            src_ptr, tmp, source_stride, source_stride, h, yoffset,            \
            CONVERT_TO_SHORTPTR(second_pred));                                 \
        return vpx_highbd_##bitdepth##_variance##w##x##h##_neon(               \
            CONVERT_TO_BYTEPTR(tmp), w, ref, ref_stride, sse);                 \
      }                                                                        \
    } else if (xoffset == 4) {                                                 \
      uint16_t tmp0[w * (h + 1)];                                              \
      if (yoffset == 0) {                                                      \
        highbd_avg_pred_var_filter_block2d_avg(                                \
            src_ptr, tmp0, source_stride, 1, w, h,                             \
            CONVERT_TO_SHORTPTR(second_pred));                                 \
        return vpx_highbd_##bitdepth##_variance##w##x##h##_neon(               \
            CONVERT_TO_BYTEPTR(tmp0), w, ref, ref_stride, sse);                \
      } else if (yoffset == 4) {                                               \
        uint16_t tmp1[w * (h + 1)];                                            \
        highbd_var_filter_block2d_avg(src_ptr, tmp0, source_stride, 1, w,      \
                                      (h + 1));                                \
        highbd_avg_pred_var_filter_block2d_avg(                                \
            tmp0, tmp1, w, w, w, h, CONVERT_TO_SHORTPTR(second_pred));         \
        return vpx_highbd_##bitdepth##_variance##w##x##h##_neon(               \
            CONVERT_TO_BYTEPTR(tmp1), w, ref, ref_stride, sse);                \
      } else {                                                                 \
        uint16_t tmp1[w * (h + 1)];                                            \
        highbd_var_filter_block2d_avg(src_ptr, tmp0, source_stride, 1, w,      \
                                      (h + 1));                                \
        highbd_avg_pred_var_filter_block2d_bil_w##w(                           \
            tmp0, tmp1, w, w, h, yoffset, CONVERT_TO_SHORTPTR(second_pred));   \
        return vpx_highbd_##bitdepth##_variance##w##x##h##_neon(               \
            CONVERT_TO_BYTEPTR(tmp1), w, ref, ref_stride, sse);                \
      }                                                                        \
    } else {                                                                   \
      uint16_t tmp0[w * (h + 1)];                                              \
      if (yoffset == 0) {                                                      \
        highbd_avg_pred_var_filter_block2d_bil_w##w(                           \
            src_ptr, tmp0, source_stride, 1, h, xoffset,                       \
            CONVERT_TO_SHORTPTR(second_pred));                                 \
        return vpx_highbd_##bitdepth##_variance##w##x##h##_neon(               \
            CONVERT_TO_BYTEPTR(tmp0), w, ref, ref_stride, sse);                \
      } else if (yoffset == 4) {                                               \
        uint16_t tmp1[w * h];                                                  \
        highbd_var_filter_block2d_bil_w##w(src_ptr, tmp0, source_stride, 1,    \
                                           (h + 1), xoffset);                  \
        highbd_avg_pred_var_filter_block2d_avg(                                \
            tmp0, tmp1, w, w, w, h, CONVERT_TO_SHORTPTR(second_pred));         \
        return vpx_highbd_##bitdepth##_variance##w##x##h##_neon(               \
            CONVERT_TO_BYTEPTR(tmp1), w, ref, ref_stride, sse);                \
      } else {                                                                 \
        uint16_t tmp1[w * h];                                                  \
        highbd_var_filter_block2d_bil_w##w(src_ptr, tmp0, source_stride, 1,    \
                                           (h + 1), xoffset);                  \
        highbd_avg_pred_var_filter_block2d_bil_w##w(                           \
            tmp0, tmp1, w, w, h, yoffset, CONVERT_TO_SHORTPTR(second_pred));   \
        return vpx_highbd_##bitdepth##_variance##w##x##h##_neon(               \
            CONVERT_TO_BYTEPTR(tmp1), w, ref, ref_stride, sse);                \
      }                                                                        \
    }                                                                          \
  }

// 8-bit
HBD_SUBPEL_AVG_VARIANCE_WXH_NEON(8, 4, 4)
HBD_SUBPEL_AVG_VARIANCE_WXH_NEON(8, 4, 8)

HBD_SUBPEL_AVG_VARIANCE_WXH_NEON(8, 8, 4)
HBD_SUBPEL_AVG_VARIANCE_WXH_NEON(8, 8, 8)
HBD_SUBPEL_AVG_VARIANCE_WXH_NEON(8, 8, 16)

HBD_SPECIALIZED_SUBPEL_AVG_VARIANCE_WXH_NEON(8, 16, 8)
HBD_SPECIALIZED_SUBPEL_AVG_VARIANCE_WXH_NEON(8, 16, 16)
HBD_SPECIALIZED_SUBPEL_AVG_VARIANCE_WXH_NEON(8, 16, 32)

HBD_SPECIALIZED_SUBPEL_AVG_VARIANCE_WXH_NEON(8, 32, 16)
HBD_SPECIALIZED_SUBPEL_AVG_VARIANCE_WXH_NEON(8, 32, 32)
HBD_SPECIALIZED_SUBPEL_AVG_VARIANCE_WXH_NEON(8, 32, 64)

HBD_SPECIALIZED_SUBPEL_AVG_VARIANCE_WXH_NEON(8, 64, 32)
HBD_SPECIALIZED_SUBPEL_AVG_VARIANCE_WXH_NEON(8, 64, 64)

// 10-bit
HBD_SUBPEL_AVG_VARIANCE_WXH_NEON(10, 4, 4)
HBD_SUBPEL_AVG_VARIANCE_WXH_NEON(10, 4, 8)

HBD_SUBPEL_AVG_VARIANCE_WXH_NEON(10, 8, 4)
HBD_SUBPEL_AVG_VARIANCE_WXH_NEON(10, 8, 8)
HBD_SUBPEL_AVG_VARIANCE_WXH_NEON(10, 8, 16)

HBD_SPECIALIZED_SUBPEL_AVG_VARIANCE_WXH_NEON(10, 16, 8)
HBD_SPECIALIZED_SUBPEL_AVG_VARIANCE_WXH_NEON(10, 16, 16)
HBD_SPECIALIZED_SUBPEL_AVG_VARIANCE_WXH_NEON(10, 16, 32)

HBD_SPECIALIZED_SUBPEL_AVG_VARIANCE_WXH_NEON(10, 32, 16)
HBD_SPECIALIZED_SUBPEL_AVG_VARIANCE_WXH_NEON(10, 32, 32)
HBD_SPECIALIZED_SUBPEL_AVG_VARIANCE_WXH_NEON(10, 32, 64)

HBD_SPECIALIZED_SUBPEL_AVG_VARIANCE_WXH_NEON(10, 64, 32)
HBD_SPECIALIZED_SUBPEL_AVG_VARIANCE_WXH_NEON(10, 64, 64)

// 12-bit
HBD_SUBPEL_AVG_VARIANCE_WXH_NEON(12, 4, 4)
HBD_SUBPEL_AVG_VARIANCE_WXH_NEON(12, 4, 8)

HBD_SUBPEL_AVG_VARIANCE_WXH_NEON(12, 8, 4)
HBD_SUBPEL_AVG_VARIANCE_WXH_NEON(12, 8, 8)
HBD_SUBPEL_AVG_VARIANCE_WXH_NEON(12, 8, 16)

HBD_SPECIALIZED_SUBPEL_AVG_VARIANCE_WXH_NEON(12, 16, 8)
HBD_SPECIALIZED_SUBPEL_AVG_VARIANCE_WXH_NEON(12, 16, 16)
HBD_SPECIALIZED_SUBPEL_AVG_VARIANCE_WXH_NEON(12, 16, 32)

HBD_SPECIALIZED_SUBPEL_AVG_VARIANCE_WXH_NEON(12, 32, 16)
HBD_SPECIALIZED_SUBPEL_AVG_VARIANCE_WXH_NEON(12, 32, 32)
HBD_SPECIALIZED_SUBPEL_AVG_VARIANCE_WXH_NEON(12, 32, 64)

HBD_SPECIALIZED_SUBPEL_AVG_VARIANCE_WXH_NEON(12, 64, 32)
HBD_SPECIALIZED_SUBPEL_AVG_VARIANCE_WXH_NEON(12, 64, 64)