aboutsummaryrefslogtreecommitdiff
path: root/vpx_dsp/arm/highbd_sad4d_neon.c
blob: a6684b0534d71c5a0db1ba4f231b14877aa2191c (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
/*
 *  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 "./vpx_config.h"
#include "./vpx_dsp_rtcd.h"

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

static INLINE void highbd_sad4xhx4d_neon(const uint8_t *src_ptr, int src_stride,
                                         const uint8_t *const ref_ptr[4],
                                         int ref_stride, uint32_t res[4],
                                         int h) {
  const uint16_t *src16_ptr = CONVERT_TO_SHORTPTR(src_ptr);
  const uint16_t *ref16_ptr0 = CONVERT_TO_SHORTPTR(ref_ptr[0]);
  const uint16_t *ref16_ptr1 = CONVERT_TO_SHORTPTR(ref_ptr[1]);
  const uint16_t *ref16_ptr2 = CONVERT_TO_SHORTPTR(ref_ptr[2]);
  const uint16_t *ref16_ptr3 = CONVERT_TO_SHORTPTR(ref_ptr[3]);

  uint32x4_t sum[4] = { vdupq_n_u32(0), vdupq_n_u32(0), vdupq_n_u32(0),
                        vdupq_n_u32(0) };

  int i = 0;
  do {
    uint16x4_t s = vld1_u16(src16_ptr + i * src_stride);
    uint16x4_t r0 = vld1_u16(ref16_ptr0 + i * ref_stride);
    uint16x4_t r1 = vld1_u16(ref16_ptr1 + i * ref_stride);
    uint16x4_t r2 = vld1_u16(ref16_ptr2 + i * ref_stride);
    uint16x4_t r3 = vld1_u16(ref16_ptr3 + i * ref_stride);

    sum[0] = vabal_u16(sum[0], s, r0);
    sum[1] = vabal_u16(sum[1], s, r1);
    sum[2] = vabal_u16(sum[2], s, r2);
    sum[3] = vabal_u16(sum[3], s, r3);

  } while (++i < h);

  vst1q_u32(res, horizontal_add_4d_uint32x4(sum));
}

static INLINE void highbd_sad8xhx4d_neon(const uint8_t *src_ptr, int src_stride,
                                         const uint8_t *const ref_ptr[4],
                                         int ref_stride, uint32_t res[4],
                                         int h) {
  const uint16_t *src16_ptr = CONVERT_TO_SHORTPTR(src_ptr);
  const uint16_t *ref16_ptr0 = CONVERT_TO_SHORTPTR(ref_ptr[0]);
  const uint16_t *ref16_ptr1 = CONVERT_TO_SHORTPTR(ref_ptr[1]);
  const uint16_t *ref16_ptr2 = CONVERT_TO_SHORTPTR(ref_ptr[2]);
  const uint16_t *ref16_ptr3 = CONVERT_TO_SHORTPTR(ref_ptr[3]);

  uint16x8_t sum[4] = { vdupq_n_u16(0), vdupq_n_u16(0), vdupq_n_u16(0),
                        vdupq_n_u16(0) };
  uint32x4_t sum_u32[4];

  int i = 0;
  do {
    uint16x8_t s = vld1q_u16(src16_ptr + i * src_stride);

    sum[0] = vabaq_u16(sum[0], s, vld1q_u16(ref16_ptr0 + i * ref_stride));
    sum[1] = vabaq_u16(sum[1], s, vld1q_u16(ref16_ptr1 + i * ref_stride));
    sum[2] = vabaq_u16(sum[2], s, vld1q_u16(ref16_ptr2 + i * ref_stride));
    sum[3] = vabaq_u16(sum[3], s, vld1q_u16(ref16_ptr3 + i * ref_stride));

  } while (++i < h);

  sum_u32[0] = vpaddlq_u16(sum[0]);
  sum_u32[1] = vpaddlq_u16(sum[1]);
  sum_u32[2] = vpaddlq_u16(sum[2]);
  sum_u32[3] = vpaddlq_u16(sum[3]);
  vst1q_u32(res, horizontal_add_4d_uint32x4(sum_u32));
}

static INLINE void sad8_neon(uint16x8_t src, uint16x8_t ref,
                             uint32x4_t *const sad_sum) {
  uint16x8_t abs_diff = vabdq_u16(src, ref);
  *sad_sum = vpadalq_u16(*sad_sum, abs_diff);
}

static INLINE void highbd_sad16xhx4d_neon(const uint8_t *src_ptr,
                                          int src_stride,
                                          const uint8_t *const ref_ptr[4],
                                          int ref_stride, uint32_t res[4],
                                          int h) {
  const uint16_t *src16_ptr = CONVERT_TO_SHORTPTR(src_ptr);
  const uint16_t *ref16_ptr0 = CONVERT_TO_SHORTPTR(ref_ptr[0]);
  const uint16_t *ref16_ptr1 = CONVERT_TO_SHORTPTR(ref_ptr[1]);
  const uint16_t *ref16_ptr2 = CONVERT_TO_SHORTPTR(ref_ptr[2]);
  const uint16_t *ref16_ptr3 = CONVERT_TO_SHORTPTR(ref_ptr[3]);

  uint32x4_t sum_lo[4] = { vdupq_n_u32(0), vdupq_n_u32(0), vdupq_n_u32(0),
                           vdupq_n_u32(0) };
  uint32x4_t sum_hi[4] = { vdupq_n_u32(0), vdupq_n_u32(0), vdupq_n_u32(0),
                           vdupq_n_u32(0) };
  uint32x4_t sum[4];

  int i = 0;
  do {
    uint16x8_t s0, s1;

    s0 = vld1q_u16(src16_ptr + i * src_stride);
    sad8_neon(s0, vld1q_u16(ref16_ptr0 + i * ref_stride), &sum_lo[0]);
    sad8_neon(s0, vld1q_u16(ref16_ptr1 + i * ref_stride), &sum_lo[1]);
    sad8_neon(s0, vld1q_u16(ref16_ptr2 + i * ref_stride), &sum_lo[2]);
    sad8_neon(s0, vld1q_u16(ref16_ptr3 + i * ref_stride), &sum_lo[3]);

    s1 = vld1q_u16(src16_ptr + i * src_stride + 8);
    sad8_neon(s1, vld1q_u16(ref16_ptr0 + i * ref_stride + 8), &sum_hi[0]);
    sad8_neon(s1, vld1q_u16(ref16_ptr1 + i * ref_stride + 8), &sum_hi[1]);
    sad8_neon(s1, vld1q_u16(ref16_ptr2 + i * ref_stride + 8), &sum_hi[2]);
    sad8_neon(s1, vld1q_u16(ref16_ptr3 + i * ref_stride + 8), &sum_hi[3]);

  } while (++i < h);

  sum[0] = vaddq_u32(sum_lo[0], sum_hi[0]);
  sum[1] = vaddq_u32(sum_lo[1], sum_hi[1]);
  sum[2] = vaddq_u32(sum_lo[2], sum_hi[2]);
  sum[3] = vaddq_u32(sum_lo[3], sum_hi[3]);

  vst1q_u32(res, horizontal_add_4d_uint32x4(sum));
}

static INLINE void highbd_sadwxhx4d_neon(const uint8_t *src_ptr, int src_stride,
                                         const uint8_t *const ref_ptr[4],
                                         int ref_stride, uint32_t res[4], int w,
                                         int h) {
  const uint16_t *src16_ptr = CONVERT_TO_SHORTPTR(src_ptr);
  const uint16_t *ref16_ptr0 = CONVERT_TO_SHORTPTR(ref_ptr[0]);
  const uint16_t *ref16_ptr1 = CONVERT_TO_SHORTPTR(ref_ptr[1]);
  const uint16_t *ref16_ptr2 = CONVERT_TO_SHORTPTR(ref_ptr[2]);
  const uint16_t *ref16_ptr3 = CONVERT_TO_SHORTPTR(ref_ptr[3]);

  uint32x4_t sum_lo[4] = { vdupq_n_u32(0), vdupq_n_u32(0), vdupq_n_u32(0),
                           vdupq_n_u32(0) };
  uint32x4_t sum_hi[4] = { vdupq_n_u32(0), vdupq_n_u32(0), vdupq_n_u32(0),
                           vdupq_n_u32(0) };
  uint32x4_t sum[4];

  int i = 0;
  do {
    int j = 0;
    do {
      uint16x8_t s0, s1, s2, s3;

      s0 = vld1q_u16(src16_ptr + i * src_stride + j);
      sad8_neon(s0, vld1q_u16(ref16_ptr0 + i * ref_stride + j), &sum_lo[0]);
      sad8_neon(s0, vld1q_u16(ref16_ptr1 + i * ref_stride + j), &sum_lo[1]);
      sad8_neon(s0, vld1q_u16(ref16_ptr2 + i * ref_stride + j), &sum_lo[2]);
      sad8_neon(s0, vld1q_u16(ref16_ptr3 + i * ref_stride + j), &sum_lo[3]);

      s1 = vld1q_u16(src16_ptr + i * src_stride + j + 8);
      sad8_neon(s1, vld1q_u16(ref16_ptr0 + i * ref_stride + j + 8), &sum_hi[0]);
      sad8_neon(s1, vld1q_u16(ref16_ptr1 + i * ref_stride + j + 8), &sum_hi[1]);
      sad8_neon(s1, vld1q_u16(ref16_ptr2 + i * ref_stride + j + 8), &sum_hi[2]);
      sad8_neon(s1, vld1q_u16(ref16_ptr3 + i * ref_stride + j + 8), &sum_hi[3]);

      s2 = vld1q_u16(src16_ptr + i * src_stride + j + 16);
      sad8_neon(s2, vld1q_u16(ref16_ptr0 + i * ref_stride + j + 16),
                &sum_lo[0]);
      sad8_neon(s2, vld1q_u16(ref16_ptr1 + i * ref_stride + j + 16),
                &sum_lo[1]);
      sad8_neon(s2, vld1q_u16(ref16_ptr2 + i * ref_stride + j + 16),
                &sum_lo[2]);
      sad8_neon(s2, vld1q_u16(ref16_ptr3 + i * ref_stride + j + 16),
                &sum_lo[3]);

      s3 = vld1q_u16(src16_ptr + i * src_stride + j + 24);
      sad8_neon(s3, vld1q_u16(ref16_ptr0 + i * ref_stride + j + 24),
                &sum_hi[0]);
      sad8_neon(s3, vld1q_u16(ref16_ptr1 + i * ref_stride + j + 24),
                &sum_hi[1]);
      sad8_neon(s3, vld1q_u16(ref16_ptr2 + i * ref_stride + j + 24),
                &sum_hi[2]);
      sad8_neon(s3, vld1q_u16(ref16_ptr3 + i * ref_stride + j + 24),
                &sum_hi[3]);

      j += 32;
    } while (j < w);

  } while (++i < h);

  sum[0] = vaddq_u32(sum_lo[0], sum_hi[0]);
  sum[1] = vaddq_u32(sum_lo[1], sum_hi[1]);
  sum[2] = vaddq_u32(sum_lo[2], sum_hi[2]);
  sum[3] = vaddq_u32(sum_lo[3], sum_hi[3]);

  vst1q_u32(res, horizontal_add_4d_uint32x4(sum));
}

static INLINE void highbd_sad64xhx4d_neon(const uint8_t *src_ptr,
                                          int src_stride,
                                          const uint8_t *const ref_ptr[4],
                                          int ref_stride, uint32_t res[4],
                                          int h) {
  highbd_sadwxhx4d_neon(src_ptr, src_stride, ref_ptr, ref_stride, res, 64, h);
}

static INLINE void highbd_sad32xhx4d_neon(const uint8_t *src_ptr,
                                          int src_stride,
                                          const uint8_t *const ref_ptr[4],
                                          int ref_stride, uint32_t res[4],
                                          int h) {
  highbd_sadwxhx4d_neon(src_ptr, src_stride, ref_ptr, ref_stride, res, 32, h);
}

#define HBD_SAD_WXH_4D_NEON(w, h)                                            \
  void vpx_highbd_sad##w##x##h##x4d_neon(                                    \
      const uint8_t *src, int src_stride, const uint8_t *const ref_array[4], \
      int ref_stride, uint32_t sad_array[4]) {                               \
    highbd_sad##w##xhx4d_neon(src, src_stride, ref_array, ref_stride,        \
                              sad_array, (h));                               \
  }

HBD_SAD_WXH_4D_NEON(4, 4)
HBD_SAD_WXH_4D_NEON(4, 8)

HBD_SAD_WXH_4D_NEON(8, 4)
HBD_SAD_WXH_4D_NEON(8, 8)
HBD_SAD_WXH_4D_NEON(8, 16)

HBD_SAD_WXH_4D_NEON(16, 8)
HBD_SAD_WXH_4D_NEON(16, 16)
HBD_SAD_WXH_4D_NEON(16, 32)

HBD_SAD_WXH_4D_NEON(32, 16)
HBD_SAD_WXH_4D_NEON(32, 32)
HBD_SAD_WXH_4D_NEON(32, 64)

HBD_SAD_WXH_4D_NEON(64, 32)
HBD_SAD_WXH_4D_NEON(64, 64)

#undef HBD_SAD_WXH_4D_NEON

#define HBD_SAD_SKIP_WXH_4D_NEON(w, h)                                        \
  void vpx_highbd_sad_skip_##w##x##h##x4d_neon(                               \
      const uint8_t *src, int src_stride, const uint8_t *const ref_array[4],  \
      int ref_stride, uint32_t sad_array[4]) {                                \
    highbd_sad##w##xhx4d_neon(src, 2 * src_stride, ref_array, 2 * ref_stride, \
                              sad_array, ((h) >> 1));                         \
    sad_array[0] <<= 1;                                                       \
    sad_array[1] <<= 1;                                                       \
    sad_array[2] <<= 1;                                                       \
    sad_array[3] <<= 1;                                                       \
  }

HBD_SAD_SKIP_WXH_4D_NEON(4, 4)
HBD_SAD_SKIP_WXH_4D_NEON(4, 8)

HBD_SAD_SKIP_WXH_4D_NEON(8, 4)
HBD_SAD_SKIP_WXH_4D_NEON(8, 8)
HBD_SAD_SKIP_WXH_4D_NEON(8, 16)

HBD_SAD_SKIP_WXH_4D_NEON(16, 8)
HBD_SAD_SKIP_WXH_4D_NEON(16, 16)
HBD_SAD_SKIP_WXH_4D_NEON(16, 32)

HBD_SAD_SKIP_WXH_4D_NEON(32, 16)
HBD_SAD_SKIP_WXH_4D_NEON(32, 32)
HBD_SAD_SKIP_WXH_4D_NEON(32, 64)

HBD_SAD_SKIP_WXH_4D_NEON(64, 32)
HBD_SAD_SKIP_WXH_4D_NEON(64, 64)

#undef HBD_SAD_SKIP_WXH_4D_NEON