Coverage Report

Created: 2026-09-13 06:34

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/dav1d/src/mc_tmpl.c
Line
Count
Source
1
/*
2
 * Copyright © 2018, VideoLAN and dav1d authors
3
 * Copyright © 2018, Two Orioles, LLC
4
 * All rights reserved.
5
 *
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions are met:
8
 *
9
 * 1. Redistributions of source code must retain the above copyright notice, this
10
 *    list of conditions and the following disclaimer.
11
 *
12
 * 2. Redistributions in binary form must reproduce the above copyright notice,
13
 *    this list of conditions and the following disclaimer in the documentation
14
 *    and/or other materials provided with the distribution.
15
 *
16
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
 */
27
28
#include "config.h"
29
30
#include <stdlib.h>
31
#include <string.h>
32
33
#include "common/attributes.h"
34
#include "common/intops.h"
35
36
#include "src/mc.h"
37
#include "src/tables.h"
38
39
#if BITDEPTH == 8
40
1.88M
#define get_intermediate_bits(bitdepth_max) 4
41
// Output in interval [-5132, 9212], fits in int16_t as is
42
293M
#define PREP_BIAS 0
43
#else
44
// 4 for 10 bits/component, 2 for 12 bits/component
45
#define get_intermediate_bits(bitdepth_max) (14 - bitdepth_from_max(bitdepth_max))
46
// Output in interval [-20588, 36956] (10-bit), [-20602, 36983] (12-bit)
47
// Subtract a bias to ensure the output fits in int16_t
48
#define PREP_BIAS 8192
49
#endif
50
51
static NOINLINE void
52
put_c(pixel *dst, const ptrdiff_t dst_stride,
53
      const pixel *src, const ptrdiff_t src_stride, const int w, int h)
54
307k
{
55
6.39M
    do {
56
6.39M
        pixel_copy(dst, src, w);
57
58
6.39M
        dst += dst_stride;
59
6.39M
        src += src_stride;
60
6.39M
    } while (--h);
61
307k
}
62
63
static NOINLINE void
64
prep_c(int16_t *tmp, const pixel *src, const ptrdiff_t src_stride,
65
       const int w, int h HIGHBD_DECL_SUFFIX)
66
116k
{
67
116k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
68
3.86M
    do {
69
152M
        for (int x = 0; x < w; x++)
70
148M
            tmp[x] = (src[x] << intermediate_bits) - PREP_BIAS;
71
72
3.86M
        tmp += w;
73
3.86M
        src += src_stride;
74
3.86M
    } while (--h);
75
116k
}
76
77
#define FILTER_8TAP(src, x, F, stride) \
78
294M
    (F[0] * src[x + -3 * stride] + \
79
294M
     F[1] * src[x + -2 * stride] + \
80
294M
     F[2] * src[x + -1 * stride] + \
81
294M
     F[3] * src[x + +0 * stride] + \
82
294M
     F[4] * src[x + +1 * stride] + \
83
294M
     F[5] * src[x + +2 * stride] + \
84
294M
     F[6] * src[x + +3 * stride] + \
85
294M
     F[7] * src[x + +4 * stride])
86
87
#define FILTER_8TAP2(src, x, F) \
88
274M
    (F[0] * src[0][x] + \
89
274M
     F[1] * src[1][x] + \
90
274M
     F[2] * src[2][x] + \
91
274M
     F[3] * src[3][x] + \
92
274M
     F[4] * src[4][x] + \
93
274M
     F[5] * src[5][x] + \
94
274M
     F[6] * src[6][x] + \
95
274M
     F[7] * src[7][x])
96
97
#define DAV1D_FILTER_8TAP_RND(src, x, F, stride, sh) \
98
262M
    ((FILTER_8TAP(src, x, F, stride) + ((1 << (sh)) >> 1)) >> (sh))
99
100
#define DAV1D_FILTER_8TAP_RND2(src, x, F, stride, rnd, sh) \
101
31.3M
    ((FILTER_8TAP(src, x, F, stride) + (rnd)) >> (sh))
102
103
#define DAV1D_FILTER_8TAP_RND3(src, x, F, sh) \
104
274M
    ((FILTER_8TAP2(src, x, F) + ((1 << (sh)) >> 1)) >> (sh))
105
106
#define DAV1D_FILTER_8TAP_CLIP(src, x, F, stride, sh) \
107
28.0M
    iclip_pixel(DAV1D_FILTER_8TAP_RND(src, x, F, stride, sh))
108
109
#define DAV1D_FILTER_8TAP_CLIP2(src, x, F, stride, rnd, sh) \
110
31.3M
    iclip_pixel(DAV1D_FILTER_8TAP_RND2(src, x, F, stride, rnd, sh))
111
112
#define DAV1D_FILTER_8TAP_CLIP3(src, x, F, sh) \
113
180M
    iclip_pixel(DAV1D_FILTER_8TAP_RND3(src, x, F, sh))
114
115
#define GET_H_FILTER(mx) \
116
198M
    const int8_t *const fh = !(mx) ? NULL : w > 4 ? \
117
181M
        dav1d_mc_subpel_filters[filter_type & 3][(mx) - 1] : \
118
181M
        dav1d_mc_subpel_filters[3 + (filter_type & 1)][(mx) - 1]
119
120
#define GET_V_FILTER(my) \
121
10.3M
    const int8_t *const fv = !(my) ? NULL : h > 4 ? \
122
8.98M
        dav1d_mc_subpel_filters[filter_type >> 2][(my) - 1] : \
123
8.98M
        dav1d_mc_subpel_filters[3 + ((filter_type >> 2) & 1)][(my) - 1]
124
125
#define GET_FILTERS() \
126
546k
    GET_H_FILTER(mx); \
127
546k
    GET_V_FILTER(my)
128
129
static NOINLINE void
130
put_8tap_c(pixel *dst, ptrdiff_t dst_stride,
131
           const pixel *src, ptrdiff_t src_stride,
132
           const int w, int h, const int mx, const int my,
133
           const int filter_type HIGHBD_DECL_SUFFIX)
134
388k
{
135
388k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
136
388k
    const int intermediate_rnd = 32 + ((1 << (6 - intermediate_bits)) >> 1);
137
138
388k
    GET_FILTERS();
139
388k
    dst_stride = PXSTRIDE(dst_stride);
140
388k
    src_stride = PXSTRIDE(src_stride);
141
142
388k
    if (fh) {
143
136k
        if (fv) {
144
75.6k
            int tmp_h = h + 7;
145
75.6k
            int16_t mid[128 * 135], *mid_ptr = mid;
146
147
75.6k
            src -= src_stride * 3;
148
1.22M
            do {
149
20.7M
                for (int x = 0; x < w; x++)
150
19.5M
                    mid_ptr[x] = DAV1D_FILTER_8TAP_RND(src, x, fh, 1,
151
1.22M
                                                       6 - intermediate_bits);
152
153
1.22M
                mid_ptr += 128;
154
1.22M
                src += src_stride;
155
1.22M
            } while (--tmp_h);
156
157
75.6k
            mid_ptr = mid + 128 * 3;
158
694k
            do {
159
15.8M
                for (int x = 0; x < w; x++)
160
15.1M
                    dst[x] = DAV1D_FILTER_8TAP_CLIP(mid_ptr, x, fv, 128,
161
694k
                                                    6 + intermediate_bits);
162
163
694k
                mid_ptr += 128;
164
694k
                dst += dst_stride;
165
694k
            } while (--h);
166
75.6k
        } else {
167
760k
            do {
168
32.1M
                for (int x = 0; x < w; x++) {
169
31.3M
                    dst[x] = DAV1D_FILTER_8TAP_CLIP2(src, x, fh, 1,
170
31.3M
                                                     intermediate_rnd, 6);
171
31.3M
                }
172
173
760k
                dst += dst_stride;
174
760k
                src += src_stride;
175
760k
            } while (--h);
176
60.5k
        }
177
252k
    } else if (fv) {
178
550k
        do {
179
13.5M
            for (int x = 0; x < w; x++)
180
12.9M
                dst[x] = DAV1D_FILTER_8TAP_CLIP(src, x, fv, src_stride, 6);
181
182
550k
            dst += dst_stride;
183
550k
            src += src_stride;
184
550k
        } while (--h);
185
53.8k
    } else
186
198k
        put_c(dst, dst_stride, src, src_stride, w, h);
187
388k
}
188
189
static NOINLINE void
190
put_8tap_scaled_c(pixel *dst, const ptrdiff_t dst_stride,
191
                  const pixel *src, ptrdiff_t src_stride,
192
                  const int w, int h, const int mx, int my,
193
                  const int dx, const int dy, const int filter_type
194
                  HIGHBD_DECL_SUFFIX)
195
383k
{
196
383k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
197
383k
    const int intermediate_rnd = (1 << intermediate_bits) >> 1;
198
383k
    int16_t mid[128 * 8];
199
383k
    int16_t *mid_ptrs[8];
200
383k
    int in_y = -8;
201
383k
    src_stride = PXSTRIDE(src_stride);
202
203
3.44M
    for (int i = 0; i < 8; i++)
204
3.06M
        mid_ptrs[i] = &mid[128 * i];
205
206
383k
    src -= src_stride * 3;
207
208
6.18M
    for (int y = 0; y < h; y++) {
209
5.80M
        int x;
210
5.80M
        int src_y = my >> 10;
211
5.80M
        GET_V_FILTER((my & 0x3ff) >> 6);
212
213
10.9M
        while (in_y < src_y) {
214
5.15M
            int imx = mx, ioff = 0;
215
5.15M
            int16_t *mid_ptr = mid_ptrs[0];
216
217
41.2M
            for (int i = 0; i < 7; i++)
218
36.0M
                mid_ptrs[i] = mid_ptrs[i + 1];
219
5.15M
            mid_ptrs[7] = mid_ptr;
220
221
122M
            for (x = 0; x < w; x++) {
222
117M
                GET_H_FILTER(imx >> 6);
223
117M
                mid_ptr[x] = fh ? DAV1D_FILTER_8TAP_RND(src, ioff, fh, 1,
224
117M
                                                        6 - intermediate_bits) :
225
117M
                                  src[ioff] << intermediate_bits;
226
117M
                imx += dx;
227
117M
                ioff += imx >> 10;
228
117M
                imx &= 0x3ff;
229
117M
            }
230
231
5.15M
            src += src_stride;
232
5.15M
            in_y++;
233
5.15M
        }
234
235
209M
        for (x = 0; x < w; x++)
236
203M
            dst[x] = fv ? DAV1D_FILTER_8TAP_CLIP3(mid_ptrs, x, fv,
237
203M
                                                  6 + intermediate_bits) :
238
203M
                          iclip_pixel((mid_ptrs[3][x] + intermediate_rnd) >>
239
23.1M
                                              intermediate_bits);
240
241
5.80M
        my += dy;
242
5.80M
        dst += PXSTRIDE(dst_stride);
243
5.80M
    }
244
383k
}
245
246
static NOINLINE void
247
prep_8tap_c(int16_t *tmp, const pixel *src, ptrdiff_t src_stride,
248
            const int w, int h, const int mx, const int my,
249
            const int filter_type HIGHBD_DECL_SUFFIX)
250
158k
{
251
158k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
252
158k
    GET_FILTERS();
253
158k
    src_stride = PXSTRIDE(src_stride);
254
255
158k
    if (fh) {
256
27.9k
        if (fv) {
257
13.7k
            int tmp_h = h + 7;
258
13.7k
            int16_t mid[128 * 135], *mid_ptr = mid;
259
260
13.7k
            src -= src_stride * 3;
261
280k
            do {
262
6.21M
                for (int x = 0; x < w; x++)
263
5.93M
                    mid_ptr[x] = DAV1D_FILTER_8TAP_RND(src, x, fh, 1,
264
280k
                                                       6 - intermediate_bits);
265
266
280k
                mid_ptr += 128;
267
280k
                src += src_stride;
268
280k
            } while (--tmp_h);
269
270
13.7k
            mid_ptr = mid + 128 * 3;
271
187k
            do {
272
5.13M
                for (int x = 0; x < w; x++) {
273
4.95M
                    int t = DAV1D_FILTER_8TAP_RND(mid_ptr, x, fv, 128, 6) -
274
4.95M
                                  PREP_BIAS;
275
4.95M
                    assert(t >= INT16_MIN && t <= INT16_MAX);
276
4.95M
                    tmp[x] = t;
277
4.95M
                }
278
279
187k
                mid_ptr += 128;
280
187k
                tmp += w;
281
187k
            } while (--h);
282
14.1k
        } else {
283
388k
            do {
284
15.9M
                for (int x = 0; x < w; x++)
285
15.5M
                    tmp[x] = DAV1D_FILTER_8TAP_RND(src, x, fh, 1,
286
15.5M
                                                   6 - intermediate_bits) -
287
15.5M
                             PREP_BIAS;
288
289
388k
                tmp += w;
290
388k
                src += src_stride;
291
388k
            } while (--h);
292
14.1k
        }
293
130k
    } else if (fv) {
294
307k
        do {
295
7.24M
            for (int x = 0; x < w; x++)
296
6.93M
                tmp[x] = DAV1D_FILTER_8TAP_RND(src, x, fv, src_stride,
297
6.93M
                                               6 - intermediate_bits) -
298
6.93M
                         PREP_BIAS;
299
300
307k
            tmp += w;
301
307k
            src += src_stride;
302
307k
        } while (--h);
303
16.5k
    } else
304
113k
        prep_c(tmp, src, src_stride, w, h HIGHBD_TAIL_SUFFIX);
305
158k
}
306
307
static NOINLINE void
308
prep_8tap_scaled_c(int16_t *tmp, const pixel *src, ptrdiff_t src_stride,
309
                   const int w, int h, const int mx, int my,
310
                   const int dx, const int dy, const int filter_type
311
                   HIGHBD_DECL_SUFFIX)
312
222k
{
313
222k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
314
222k
    int16_t mid[128 * 8];
315
222k
    int16_t *mid_ptrs[8];
316
222k
    int in_y = -8;
317
222k
    src_stride = PXSTRIDE(src_stride);
318
319
2.00M
    for (int i = 0; i < 8; i++)
320
1.77M
        mid_ptrs[i] = &mid[128 * i];
321
322
222k
    src -= src_stride * 3;
323
324
4.20M
    for (int y = 0; y < h; y++) {
325
3.97M
        int x;
326
3.97M
        int src_y = my >> 10;
327
3.97M
        GET_V_FILTER((my & 0x3ff) >> 6);
328
329
7.46M
        while (in_y < src_y) {
330
3.48M
            int imx = mx, ioff = 0;
331
3.48M
            int16_t *mid_ptr = mid_ptrs[0];
332
333
27.8M
            for (int i = 0; i < 7; i++)
334
24.3M
                mid_ptrs[i] = mid_ptrs[i + 1];
335
3.48M
            mid_ptrs[7] = mid_ptr;
336
337
83.2M
            for (x = 0; x < w; x++) {
338
79.8M
                GET_H_FILTER(imx >> 6);
339
79.8M
                mid_ptr[x] = fh ? DAV1D_FILTER_8TAP_RND(src, ioff, fh, 1,
340
79.8M
                                                        6 - intermediate_bits) :
341
79.8M
                                  src[ioff] << intermediate_bits;
342
79.8M
                imx += dx;
343
79.8M
                ioff += imx >> 10;
344
79.8M
                imx &= 0x3ff;
345
79.8M
            }
346
347
3.48M
            src += src_stride;
348
3.48M
            in_y++;
349
3.48M
        }
350
351
111M
        for (x = 0; x < w; x++)
352
107M
            tmp[x] = (fv ? DAV1D_FILTER_8TAP_RND3(mid_ptrs, x, fv, 6)
353
107M
                         : mid_ptrs[3][x]) - PREP_BIAS;
354
355
3.97M
        my += dy;
356
3.97M
        tmp += w;
357
3.97M
    }
358
222k
}
359
360
#define filter_fns(type, type_h, type_v) \
361
static void put_8tap_##type##_c(pixel *const dst, \
362
                                const ptrdiff_t dst_stride, \
363
                                const pixel *const src, \
364
                                const ptrdiff_t src_stride, \
365
                                const int w, const int h, \
366
                                const int mx, const int my \
367
388k
                                HIGHBD_DECL_SUFFIX) \
368
388k
{ \
369
388k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
388k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
388k
} \
mc_tmpl.c:put_8tap_regular_c
Line
Count
Source
367
268k
                                HIGHBD_DECL_SUFFIX) \
368
268k
{ \
369
268k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
268k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
268k
} \
mc_tmpl.c:put_8tap_regular_smooth_c
Line
Count
Source
367
7.50k
                                HIGHBD_DECL_SUFFIX) \
368
7.50k
{ \
369
7.50k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
7.50k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
7.50k
} \
mc_tmpl.c:put_8tap_regular_sharp_c
Line
Count
Source
367
726
                                HIGHBD_DECL_SUFFIX) \
368
726
{ \
369
726
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
726
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
726
} \
mc_tmpl.c:put_8tap_sharp_regular_c
Line
Count
Source
367
690
                                HIGHBD_DECL_SUFFIX) \
368
690
{ \
369
690
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
690
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
690
} \
mc_tmpl.c:put_8tap_sharp_smooth_c
Line
Count
Source
367
247
                                HIGHBD_DECL_SUFFIX) \
368
247
{ \
369
247
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
247
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
247
} \
mc_tmpl.c:put_8tap_sharp_c
Line
Count
Source
367
1.84k
                                HIGHBD_DECL_SUFFIX) \
368
1.84k
{ \
369
1.84k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
1.84k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
1.84k
} \
mc_tmpl.c:put_8tap_smooth_regular_c
Line
Count
Source
367
3.68k
                                HIGHBD_DECL_SUFFIX) \
368
3.68k
{ \
369
3.68k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
3.68k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
3.68k
} \
mc_tmpl.c:put_8tap_smooth_c
Line
Count
Source
367
104k
                                HIGHBD_DECL_SUFFIX) \
368
104k
{ \
369
104k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
104k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
104k
} \
mc_tmpl.c:put_8tap_smooth_sharp_c
Line
Count
Source
367
704
                                HIGHBD_DECL_SUFFIX) \
368
704
{ \
369
704
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
704
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
704
} \
372
static void put_8tap_##type##_scaled_c(pixel *const dst, \
373
                                       const ptrdiff_t dst_stride, \
374
                                       const pixel *const src, \
375
                                       const ptrdiff_t src_stride, \
376
                                       const int w, const int h, \
377
                                       const int mx, const int my, \
378
                                       const int dx, const int dy \
379
383k
                                       HIGHBD_DECL_SUFFIX) \
380
383k
{ \
381
383k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
383k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
383k
} \
mc_tmpl.c:put_8tap_regular_scaled_c
Line
Count
Source
379
286k
                                       HIGHBD_DECL_SUFFIX) \
380
286k
{ \
381
286k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
286k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
286k
} \
mc_tmpl.c:put_8tap_regular_smooth_scaled_c
Line
Count
Source
379
26.6k
                                       HIGHBD_DECL_SUFFIX) \
380
26.6k
{ \
381
26.6k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
26.6k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
26.6k
} \
mc_tmpl.c:put_8tap_regular_sharp_scaled_c
Line
Count
Source
379
4.10k
                                       HIGHBD_DECL_SUFFIX) \
380
4.10k
{ \
381
4.10k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
4.10k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
4.10k
} \
mc_tmpl.c:put_8tap_sharp_regular_scaled_c
Line
Count
Source
379
10.5k
                                       HIGHBD_DECL_SUFFIX) \
380
10.5k
{ \
381
10.5k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
10.5k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
10.5k
} \
mc_tmpl.c:put_8tap_sharp_smooth_scaled_c
Line
Count
Source
379
2.42k
                                       HIGHBD_DECL_SUFFIX) \
380
2.42k
{ \
381
2.42k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
2.42k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
2.42k
} \
mc_tmpl.c:put_8tap_sharp_scaled_c
Line
Count
Source
379
4.82k
                                       HIGHBD_DECL_SUFFIX) \
380
4.82k
{ \
381
4.82k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
4.82k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
4.82k
} \
mc_tmpl.c:put_8tap_smooth_regular_scaled_c
Line
Count
Source
379
33.4k
                                       HIGHBD_DECL_SUFFIX) \
380
33.4k
{ \
381
33.4k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
33.4k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
33.4k
} \
mc_tmpl.c:put_8tap_smooth_scaled_c
Line
Count
Source
379
12.2k
                                       HIGHBD_DECL_SUFFIX) \
380
12.2k
{ \
381
12.2k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
12.2k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
12.2k
} \
mc_tmpl.c:put_8tap_smooth_sharp_scaled_c
Line
Count
Source
379
2.39k
                                       HIGHBD_DECL_SUFFIX) \
380
2.39k
{ \
381
2.39k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
2.39k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
2.39k
} \
384
static void prep_8tap_##type##_c(int16_t *const tmp, \
385
                                 const pixel *const src, \
386
                                 const ptrdiff_t src_stride, \
387
                                 const int w, const int h, \
388
                                 const int mx, const int my \
389
158k
                                 HIGHBD_DECL_SUFFIX) \
390
158k
{ \
391
158k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
158k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
158k
} \
mc_tmpl.c:prep_8tap_regular_c
Line
Count
Source
389
104k
                                 HIGHBD_DECL_SUFFIX) \
390
104k
{ \
391
104k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
104k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
104k
} \
mc_tmpl.c:prep_8tap_regular_smooth_c
Line
Count
Source
389
1.00k
                                 HIGHBD_DECL_SUFFIX) \
390
1.00k
{ \
391
1.00k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
1.00k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
1.00k
} \
mc_tmpl.c:prep_8tap_regular_sharp_c
Line
Count
Source
389
1.94k
                                 HIGHBD_DECL_SUFFIX) \
390
1.94k
{ \
391
1.94k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
1.94k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
1.94k
} \
mc_tmpl.c:prep_8tap_sharp_regular_c
Line
Count
Source
389
1.47k
                                 HIGHBD_DECL_SUFFIX) \
390
1.47k
{ \
391
1.47k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
1.47k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
1.47k
} \
mc_tmpl.c:prep_8tap_sharp_smooth_c
Line
Count
Source
389
839
                                 HIGHBD_DECL_SUFFIX) \
390
839
{ \
391
839
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
839
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
839
} \
mc_tmpl.c:prep_8tap_sharp_c
Line
Count
Source
389
2.50k
                                 HIGHBD_DECL_SUFFIX) \
390
2.50k
{ \
391
2.50k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
2.50k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
2.50k
} \
mc_tmpl.c:prep_8tap_smooth_regular_c
Line
Count
Source
389
1.18k
                                 HIGHBD_DECL_SUFFIX) \
390
1.18k
{ \
391
1.18k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
1.18k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
1.18k
} \
mc_tmpl.c:prep_8tap_smooth_c
Line
Count
Source
389
43.6k
                                 HIGHBD_DECL_SUFFIX) \
390
43.6k
{ \
391
43.6k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
43.6k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
43.6k
} \
mc_tmpl.c:prep_8tap_smooth_sharp_c
Line
Count
Source
389
884
                                 HIGHBD_DECL_SUFFIX) \
390
884
{ \
391
884
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
884
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
884
} \
394
static void prep_8tap_##type##_scaled_c(int16_t *const tmp, \
395
                                        const pixel *const src, \
396
                                        const ptrdiff_t src_stride, \
397
                                        const int w, const int h, \
398
                                        const int mx, const int my, \
399
                                        const int dx, const int dy \
400
222k
                                        HIGHBD_DECL_SUFFIX) \
401
222k
{ \
402
222k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
222k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
222k
}
mc_tmpl.c:prep_8tap_regular_scaled_c
Line
Count
Source
400
128k
                                        HIGHBD_DECL_SUFFIX) \
401
128k
{ \
402
128k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
128k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
128k
}
mc_tmpl.c:prep_8tap_regular_smooth_scaled_c
Line
Count
Source
400
8.83k
                                        HIGHBD_DECL_SUFFIX) \
401
8.83k
{ \
402
8.83k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
8.83k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
8.83k
}
mc_tmpl.c:prep_8tap_regular_sharp_scaled_c
Line
Count
Source
400
11.2k
                                        HIGHBD_DECL_SUFFIX) \
401
11.2k
{ \
402
11.2k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
11.2k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
11.2k
}
mc_tmpl.c:prep_8tap_sharp_regular_scaled_c
Line
Count
Source
400
26.8k
                                        HIGHBD_DECL_SUFFIX) \
401
26.8k
{ \
402
26.8k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
26.8k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
26.8k
}
mc_tmpl.c:prep_8tap_sharp_smooth_scaled_c
Line
Count
Source
400
3.99k
                                        HIGHBD_DECL_SUFFIX) \
401
3.99k
{ \
402
3.99k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
3.99k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
3.99k
}
mc_tmpl.c:prep_8tap_sharp_scaled_c
Line
Count
Source
400
8.89k
                                        HIGHBD_DECL_SUFFIX) \
401
8.89k
{ \
402
8.89k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
8.89k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
8.89k
}
mc_tmpl.c:prep_8tap_smooth_regular_scaled_c
Line
Count
Source
400
21.1k
                                        HIGHBD_DECL_SUFFIX) \
401
21.1k
{ \
402
21.1k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
21.1k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
21.1k
}
mc_tmpl.c:prep_8tap_smooth_scaled_c
Line
Count
Source
400
5.22k
                                        HIGHBD_DECL_SUFFIX) \
401
5.22k
{ \
402
5.22k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
5.22k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
5.22k
}
mc_tmpl.c:prep_8tap_smooth_sharp_scaled_c
Line
Count
Source
400
7.13k
                                        HIGHBD_DECL_SUFFIX) \
401
7.13k
{ \
402
7.13k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
7.13k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
7.13k
}
405
406
filter_fns(regular,        DAV1D_FILTER_8TAP_REGULAR, DAV1D_FILTER_8TAP_REGULAR)
407
filter_fns(regular_sharp,  DAV1D_FILTER_8TAP_REGULAR, DAV1D_FILTER_8TAP_SHARP)
408
filter_fns(regular_smooth, DAV1D_FILTER_8TAP_REGULAR, DAV1D_FILTER_8TAP_SMOOTH)
409
filter_fns(smooth,         DAV1D_FILTER_8TAP_SMOOTH,  DAV1D_FILTER_8TAP_SMOOTH)
410
filter_fns(smooth_regular, DAV1D_FILTER_8TAP_SMOOTH,  DAV1D_FILTER_8TAP_REGULAR)
411
filter_fns(smooth_sharp,   DAV1D_FILTER_8TAP_SMOOTH,  DAV1D_FILTER_8TAP_SHARP)
412
filter_fns(sharp,          DAV1D_FILTER_8TAP_SHARP,   DAV1D_FILTER_8TAP_SHARP)
413
filter_fns(sharp_regular,  DAV1D_FILTER_8TAP_SHARP,   DAV1D_FILTER_8TAP_REGULAR)
414
filter_fns(sharp_smooth,   DAV1D_FILTER_8TAP_SHARP,   DAV1D_FILTER_8TAP_SMOOTH)
415
416
#define FILTER_BILIN(src, x, mxy, stride) \
417
39.2M
    (16 * src[x] + ((mxy) * (src[x + stride] - src[x])))
418
419
#define FILTER_BILIN_RND(src, x, mxy, stride, sh) \
420
39.2M
    ((FILTER_BILIN(src, x, mxy, stride) + ((1 << (sh)) >> 1)) >> (sh))
421
422
#define FILTER_BILIN_CLIP(src, x, mxy, stride, sh) \
423
2.25M
    iclip_pixel(FILTER_BILIN_RND(src, x, mxy, stride, sh))
424
425
#define FILTER_BILIN2(src1, src2, x, mxy) \
426
30.0M
    (16 * src1[x] + ((mxy) * (src2[x] - src1[x])))
427
428
#define FILTER_BILIN_RND2(src1, src2, x, mxy, sh) \
429
30.0M
    ((FILTER_BILIN2(src1, src2, x, mxy) + ((1 << (sh)) >> 1)) >> (sh))
430
431
#define FILTER_BILIN_CLIP2(src1, src2, x, mxy, sh) \
432
23.5M
    iclip_pixel(FILTER_BILIN_RND2(src1, src2, x, mxy, sh))
433
434
static void put_bilin_c(pixel *dst, ptrdiff_t dst_stride,
435
                        const pixel *src, ptrdiff_t src_stride,
436
                        const int w, int h, const int mx, const int my
437
                        HIGHBD_DECL_SUFFIX)
438
138k
{
439
138k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
440
138k
    const int intermediate_rnd = (1 << intermediate_bits) >> 1;
441
138k
    dst_stride = PXSTRIDE(dst_stride);
442
138k
    src_stride = PXSTRIDE(src_stride);
443
444
138k
    if (mx) {
445
19.9k
        if (my) {
446
8.75k
            int16_t mid[128 * 129], *mid_ptr = mid;
447
8.75k
            int tmp_h = h + 1;
448
449
78.1k
            do {
450
1.28M
                for (int x = 0; x < w; x++)
451
1.20M
                    mid_ptr[x] = FILTER_BILIN_RND(src, x, mx, 1,
452
78.1k
                                                  4 - intermediate_bits);
453
454
78.1k
                mid_ptr += 128;
455
78.1k
                src += src_stride;
456
78.1k
            } while (--tmp_h);
457
458
8.75k
            mid_ptr = mid;
459
69.3k
            do {
460
1.20M
                for (int x = 0; x < w; x++)
461
1.13M
                    dst[x] = FILTER_BILIN_CLIP(mid_ptr, x, my, 128,
462
69.3k
                                               4 + intermediate_bits);
463
464
69.3k
                mid_ptr += 128;
465
69.3k
                dst += dst_stride;
466
69.3k
            } while (--h);
467
11.2k
        } else {
468
133k
            do {
469
4.03M
                for (int x = 0; x < w; x++) {
470
3.90M
                    const int px = FILTER_BILIN_RND(src, x, mx, 1,
471
3.90M
                                                    4 - intermediate_bits);
472
3.90M
                    dst[x] = iclip_pixel((px + intermediate_rnd) >> intermediate_bits);
473
3.90M
                }
474
475
133k
                dst += dst_stride;
476
133k
                src += src_stride;
477
133k
            } while (--h);
478
11.2k
        }
479
118k
    } else if (my) {
480
74.3k
        do {
481
1.20M
            for (int x = 0; x < w; x++)
482
1.12M
                dst[x] = FILTER_BILIN_CLIP(src, x, my, src_stride, 4);
483
484
74.3k
            dst += dst_stride;
485
74.3k
            src += src_stride;
486
74.3k
        } while (--h);
487
9.55k
    } else
488
109k
        put_c(dst, dst_stride, src, src_stride, w, h);
489
138k
}
490
491
static void put_bilin_scaled_c(pixel *dst, ptrdiff_t dst_stride,
492
                               const pixel *src, ptrdiff_t src_stride,
493
                               const int w, int h, const int mx, int my,
494
                               const int dx, const int dy
495
                               HIGHBD_DECL_SUFFIX)
496
8.83k
{
497
8.83k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
498
8.83k
    int16_t mid[128 * 2];
499
8.83k
    int in_y = -2;
500
501
328k
    do {
502
328k
        int x;
503
328k
        int y = my >> 10;
504
328k
        int16_t *mid1 = &mid[(y & 1) * 128];
505
328k
        int16_t *mid2 = &mid[((y + 1) & 1) * 128];
506
328k
        int dmy = my & 0x3ff;
507
508
585k
        while (in_y < y) {
509
257k
            int imx = mx, ioff = 0;
510
257k
            int16_t *mid_ptr = &mid[(in_y & 1) * 128];
511
512
24.8M
            for (x = 0; x < w; x++) {
513
24.6M
                mid_ptr[x] = FILTER_BILIN_RND(src, ioff, imx >> 6, 1,
514
24.6M
                                              4 - intermediate_bits);
515
24.6M
                imx += dx;
516
24.6M
                ioff += imx >> 10;
517
24.6M
                imx &= 0x3ff;
518
24.6M
            }
519
520
257k
            src += PXSTRIDE(src_stride);
521
257k
            in_y++;
522
257k
        }
523
524
23.8M
        for (x = 0; x < w; x++)
525
23.5M
            dst[x] = FILTER_BILIN_CLIP2(mid1, mid2, x, dmy >> 6,
526
328k
                                       4 + intermediate_bits);
527
528
328k
        my += dy;
529
328k
        dst += PXSTRIDE(dst_stride);
530
328k
    } while (--h);
531
8.83k
}
532
533
static void prep_bilin_c(int16_t *tmp,
534
                         const pixel *src, ptrdiff_t src_stride,
535
                         const int w, int h, const int mx, const int my
536
                         HIGHBD_DECL_SUFFIX)
537
7.09k
{
538
7.09k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
539
7.09k
    src_stride = PXSTRIDE(src_stride);
540
541
7.09k
    if (mx) {
542
2.53k
        if (my) {
543
1.35k
            int16_t mid[128 * 129], *mid_ptr = mid;
544
1.35k
            int tmp_h = h + 1;
545
546
15.9k
            do {
547
412k
                for (int x = 0; x < w; x++)
548
396k
                    mid_ptr[x] = FILTER_BILIN_RND(src, x, mx, 1,
549
15.9k
                                                  4 - intermediate_bits);
550
551
15.9k
                mid_ptr += 128;
552
15.9k
                src += src_stride;
553
15.9k
            } while (--tmp_h);
554
555
1.35k
            mid_ptr = mid;
556
14.5k
            do {
557
398k
                for (int x = 0; x < w; x++)
558
383k
                    tmp[x] = FILTER_BILIN_RND(mid_ptr, x, my, 128, 4) -
559
383k
                             PREP_BIAS;
560
561
14.5k
                mid_ptr += 128;
562
14.5k
                tmp += w;
563
14.5k
            } while (--h);
564
1.35k
        } else {
565
15.0k
            do {
566
472k
                for (int x = 0; x < w; x++)
567
457k
                    tmp[x] = FILTER_BILIN_RND(src, x, mx, 1,
568
457k
                                              4 - intermediate_bits) -
569
457k
                             PREP_BIAS;
570
571
15.0k
                tmp += w;
572
15.0k
                src += src_stride;
573
15.0k
            } while (--h);
574
1.17k
        }
575
4.56k
    } else if (my) {
576
21.2k
        do {
577
586k
            for (int x = 0; x < w; x++)
578
565k
                tmp[x] = FILTER_BILIN_RND(src, x, my, src_stride,
579
565k
                                          4 - intermediate_bits) - PREP_BIAS;
580
581
21.2k
            tmp += w;
582
21.2k
            src += src_stride;
583
21.2k
        } while (--h);
584
1.72k
    } else
585
2.83k
        prep_c(tmp, src, src_stride, w, h HIGHBD_TAIL_SUFFIX);
586
7.09k
}
587
588
static void prep_bilin_scaled_c(int16_t *tmp,
589
                                const pixel *src, ptrdiff_t src_stride,
590
                                const int w, int h, const int mx, int my,
591
                                const int dx, const int dy HIGHBD_DECL_SUFFIX)
592
5.85k
{
593
5.85k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
594
5.85k
    int16_t mid[128 * 2];
595
5.85k
    int in_y = -2;
596
597
116k
    do {
598
116k
        int x;
599
116k
        int y = my >> 10;
600
116k
        int16_t *mid1 = &mid[(y & 1) * 128];
601
116k
        int16_t *mid2 = &mid[((y + 1) & 1) * 128];
602
116k
        int dmy = my & 0x3ff;
603
604
210k
        while (in_y < y) {
605
93.6k
            int imx = mx, ioff = 0;
606
93.6k
            int16_t *mid_ptr = &mid[(in_y & 1) * 128];
607
608
5.52M
            for (x = 0; x < w; x++) {
609
5.43M
                mid_ptr[x] = FILTER_BILIN_RND(src, ioff, imx >> 6, 1,
610
5.43M
                                              4 - intermediate_bits);
611
5.43M
                imx += dx;
612
5.43M
                ioff += imx >> 10;
613
5.43M
                imx &= 0x3ff;
614
5.43M
            }
615
616
93.6k
            src += PXSTRIDE(src_stride);
617
93.6k
            in_y++;
618
93.6k
        }
619
620
6.62M
        for (x = 0; x < w; x++)
621
6.50M
            tmp[x] = FILTER_BILIN_RND2(mid1, mid2, x, dmy >> 6, 4) - PREP_BIAS;
622
623
116k
        my += dy;
624
116k
        tmp += w;
625
116k
    } while (--h);
626
5.85k
}
627
628
static void avg_c(pixel *dst, const ptrdiff_t dst_stride,
629
                  const int16_t *tmp1, const int16_t *tmp2, const int w, int h
630
                  HIGHBD_DECL_SUFFIX)
631
135k
{
632
135k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
633
135k
    const int sh = intermediate_bits + 1;
634
135k
    const int rnd = (1 << intermediate_bits) + PREP_BIAS * 2;
635
2.83M
    do {
636
87.5M
        for (int x = 0; x < w; x++)
637
84.7M
            dst[x] = iclip_pixel((tmp1[x] + tmp2[x] + rnd) >> sh);
638
639
2.83M
        tmp1 += w;
640
2.83M
        tmp2 += w;
641
2.83M
        dst += PXSTRIDE(dst_stride);
642
2.83M
    } while (--h);
643
135k
}
644
645
static void w_avg_c(pixel *dst, const ptrdiff_t dst_stride,
646
                    const int16_t *tmp1, const int16_t *tmp2, const int w, int h,
647
                    const int weight HIGHBD_DECL_SUFFIX)
648
23.7k
{
649
23.7k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
650
23.7k
    const int sh = intermediate_bits + 4;
651
23.7k
    const int rnd = (8 << intermediate_bits) + PREP_BIAS * 16;
652
612k
    do {
653
22.2M
        for (int x = 0; x < w; x++)
654
21.6M
            dst[x] = iclip_pixel((tmp1[x] * weight +
655
21.6M
                                  tmp2[x] * (16 - weight) + rnd) >> sh);
656
657
612k
        tmp1 += w;
658
612k
        tmp2 += w;
659
612k
        dst += PXSTRIDE(dst_stride);
660
612k
    } while (--h);
661
23.7k
}
662
663
static void mask_c(pixel *dst, const ptrdiff_t dst_stride,
664
                   const int16_t *tmp1, const int16_t *tmp2, const int w, int h,
665
                   const uint8_t *mask HIGHBD_DECL_SUFFIX)
666
32.9k
{
667
32.9k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
668
32.9k
    const int sh = intermediate_bits + 6;
669
32.9k
    const int rnd = (32 << intermediate_bits) + PREP_BIAS * 64;
670
684k
    do {
671
21.7M
        for (int x = 0; x < w; x++)
672
21.1M
            dst[x] = iclip_pixel((tmp1[x] * mask[x] +
673
21.1M
                                  tmp2[x] * (64 - mask[x]) + rnd) >> sh);
674
675
684k
        tmp1 += w;
676
684k
        tmp2 += w;
677
684k
        mask += w;
678
684k
        dst += PXSTRIDE(dst_stride);
679
684k
    } while (--h);
680
32.9k
}
681
682
15.3M
#define blend_px(a, b, m) (((a * (64 - m) + b * m) + 32) >> 6)
683
static void blend_c(pixel *dst, const ptrdiff_t dst_stride, const pixel *tmp,
684
                    const int w, int h, const uint8_t *mask)
685
20.5k
{
686
235k
    do {
687
3.37M
        for (int x = 0; x < w; x++) {
688
3.13M
            dst[x] = blend_px(dst[x], tmp[x], mask[x]);
689
3.13M
        }
690
235k
        dst += PXSTRIDE(dst_stride);
691
235k
        tmp += w;
692
235k
        mask += w;
693
235k
    } while (--h);
694
20.5k
}
695
696
static void blend_v_c(pixel *dst, const ptrdiff_t dst_stride, const pixel *tmp,
697
                      const int w, int h)
698
85.4k
{
699
85.4k
    const uint8_t *const mask = &dav1d_obmc_masks[w];
700
1.03M
    do {
701
7.59M
        for (int x = 0; x < (w * 3) >> 2; x++) {
702
6.56M
            dst[x] = blend_px(dst[x], tmp[x], mask[x]);
703
6.56M
        }
704
1.03M
        dst += PXSTRIDE(dst_stride);
705
1.03M
        tmp += w;
706
1.03M
    } while (--h);
707
85.4k
}
708
709
static void blend_h_c(pixel *dst, const ptrdiff_t dst_stride, const pixel *tmp,
710
                      const int w, int h)
711
84.8k
{
712
84.8k
    const uint8_t *mask = &dav1d_obmc_masks[h];
713
84.8k
    h = (h * 3) >> 2;
714
409k
    do {
715
409k
        const int m = *mask++;
716
6.06M
        for (int x = 0; x < w; x++) {
717
5.65M
            dst[x] = blend_px(dst[x], tmp[x], m);
718
5.65M
        }
719
409k
        dst += PXSTRIDE(dst_stride);
720
409k
        tmp += w;
721
409k
    } while (--h);
722
84.8k
}
723
724
static void w_mask_c(pixel *dst, const ptrdiff_t dst_stride,
725
                     const int16_t *tmp1, const int16_t *tmp2, const int w, int h,
726
                     uint8_t *mask, const int sign,
727
                     const int ss_hor, const int ss_ver HIGHBD_DECL_SUFFIX)
728
8.71k
{
729
    // store mask at 2x2 resolution, i.e. store 2x1 sum for even rows,
730
    // and then load this intermediate to calculate final value for odd rows
731
8.71k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
732
8.71k
    const int bitdepth = bitdepth_from_max(bitdepth_max);
733
8.71k
    const int sh = intermediate_bits + 6;
734
8.71k
    const int rnd = (32 << intermediate_bits) + PREP_BIAS * 64;
735
8.71k
    const int mask_sh = bitdepth + intermediate_bits - 4;
736
8.71k
    const int mask_rnd = 1 << (mask_sh - 5);
737
374k
    do {
738
13.2M
        for (int x = 0; x < w; x++) {
739
12.8M
            const int tmpdiff = tmp1[x] - tmp2[x];
740
12.8M
            const int m = imin(38 + ((abs(tmpdiff) + mask_rnd) >> mask_sh), 64);
741
12.8M
            dst[x] = iclip_pixel((tmpdiff * m + tmp2[x] * 64 + rnd) >> sh);
742
743
12.8M
            if (ss_hor) {
744
5.29M
                x++;
745
746
5.29M
                const int tmpdiff = tmp1[x] - tmp2[x];
747
5.29M
                const int n = imin(38 + ((abs(tmpdiff) + mask_rnd) >> mask_sh), 64);
748
5.29M
                dst[x] = iclip_pixel((tmpdiff * n + tmp2[x] * 64 + rnd) >> sh);
749
750
5.29M
                if (h & ss_ver) {
751
2.55M
                    mask[x >> 1] = (m + n + mask[x >> 1] + 2 - sign) >> 2;
752
2.74M
                } else if (ss_ver) {
753
2.55M
                    mask[x >> 1] = m + n;
754
2.55M
                } else {
755
186k
                    mask[x >> 1] = (m + n + 1 - sign) >> 1;
756
186k
                }
757
7.58M
            } else {
758
7.58M
                mask[x] = m;
759
7.58M
            }
760
12.8M
        }
761
762
374k
        tmp1 += w;
763
374k
        tmp2 += w;
764
374k
        dst += PXSTRIDE(dst_stride);
765
374k
        if (!ss_ver || (h & 1)) mask += w >> ss_hor;
766
374k
    } while (--h);
767
8.71k
}
768
769
#define w_mask_fns(ssn, ss_hor, ss_ver) \
770
static void w_mask_##ssn##_c(pixel *const dst, const ptrdiff_t dst_stride, \
771
                             const int16_t *const tmp1, const int16_t *const tmp2, \
772
                             const int w, const int h, uint8_t *mask, \
773
8.71k
                             const int sign HIGHBD_DECL_SUFFIX) \
774
8.71k
{ \
775
8.71k
    w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver \
776
8.71k
             HIGHBD_TAIL_SUFFIX); \
777
8.71k
}
mc_tmpl.c:w_mask_444_c
Line
Count
Source
773
5.33k
                             const int sign HIGHBD_DECL_SUFFIX) \
774
5.33k
{ \
775
5.33k
    w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver \
776
5.33k
             HIGHBD_TAIL_SUFFIX); \
777
5.33k
}
mc_tmpl.c:w_mask_422_c
Line
Count
Source
773
196
                             const int sign HIGHBD_DECL_SUFFIX) \
774
196
{ \
775
196
    w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver \
776
196
             HIGHBD_TAIL_SUFFIX); \
777
196
}
mc_tmpl.c:w_mask_420_c
Line
Count
Source
773
3.18k
                             const int sign HIGHBD_DECL_SUFFIX) \
774
3.18k
{ \
775
3.18k
    w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver \
776
3.18k
             HIGHBD_TAIL_SUFFIX); \
777
3.18k
}
778
779
w_mask_fns(444, 0, 0);
780
w_mask_fns(422, 1, 0);
781
w_mask_fns(420, 1, 1);
782
783
#undef w_mask_fns
784
785
#define FILTER_WARP_RND(src, x, F, stride, sh) \
786
41.5M
    ((F[0] * src[x - 3 * stride] + \
787
41.5M
      F[1] * src[x - 2 * stride] + \
788
41.5M
      F[2] * src[x - 1 * stride] + \
789
41.5M
      F[3] * src[x + 0 * stride] + \
790
41.5M
      F[4] * src[x + 1 * stride] + \
791
41.5M
      F[5] * src[x + 2 * stride] + \
792
41.5M
      F[6] * src[x + 3 * stride] + \
793
41.5M
      F[7] * src[x + 4 * stride] + \
794
41.5M
      ((1 << (sh)) >> 1)) >> (sh))
795
796
#define FILTER_WARP_CLIP(src, x, F, stride, sh) \
797
12.1M
    iclip_pixel(FILTER_WARP_RND(src, x, F, stride, sh))
798
799
static void warp_affine_8x8_c(pixel *dst, const ptrdiff_t dst_stride,
800
                              const pixel *src, const ptrdiff_t src_stride,
801
                              const int16_t *const abcd, int mx, int my
802
                              HIGHBD_DECL_SUFFIX)
803
228k
{
804
228k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
805
228k
    int16_t mid[15 * 8], *mid_ptr = mid;
806
807
228k
    src -= 3 * PXSTRIDE(src_stride);
808
3.50M
    for (int y = 0; y < 15; y++, mx += abcd[1]) {
809
27.3M
        for (int x = 0, tmx = mx; x < 8; x++, tmx += abcd[0]) {
810
24.1M
            const int8_t *const filter =
811
24.1M
                dav1d_mc_warp_filter[64 + ((tmx + 512) >> 10)];
812
813
24.1M
            mid_ptr[x] = FILTER_WARP_RND(src, x, filter, 1,
814
24.1M
                                         7 - intermediate_bits);
815
24.1M
        }
816
3.27M
        src += PXSTRIDE(src_stride);
817
3.27M
        mid_ptr += 8;
818
3.27M
    }
819
820
228k
    mid_ptr = &mid[3 * 8];
821
1.99M
    for (int y = 0; y < 8; y++, my += abcd[3]) {
822
13.8M
        for (int x = 0, tmy = my; x < 8; x++, tmy += abcd[2]) {
823
12.1M
            const int8_t *const filter =
824
12.1M
                dav1d_mc_warp_filter[64 + ((tmy + 512) >> 10)];
825
826
12.1M
            dst[x] = FILTER_WARP_CLIP(mid_ptr, x, filter, 8,
827
12.1M
                                      7 + intermediate_bits);
828
12.1M
        }
829
1.76M
        mid_ptr += 8;
830
1.76M
        dst += PXSTRIDE(dst_stride);
831
1.76M
    }
832
228k
}
833
834
static void warp_affine_8x8t_c(int16_t *tmp, const ptrdiff_t tmp_stride,
835
                               const pixel *src, const ptrdiff_t src_stride,
836
                               const int16_t *const abcd, int mx, int my
837
                               HIGHBD_DECL_SUFFIX)
838
28.9k
{
839
28.9k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
840
28.9k
    int16_t mid[15 * 8], *mid_ptr = mid;
841
842
28.9k
    src -= 3 * PXSTRIDE(src_stride);
843
462k
    for (int y = 0; y < 15; y++, mx += abcd[1]) {
844
3.90M
        for (int x = 0, tmx = mx; x < 8; x++, tmx += abcd[0]) {
845
3.46M
            const int8_t *const filter =
846
3.46M
                dav1d_mc_warp_filter[64 + ((tmx + 512) >> 10)];
847
848
3.46M
            mid_ptr[x] = FILTER_WARP_RND(src, x, filter, 1,
849
3.46M
                                         7 - intermediate_bits);
850
3.46M
        }
851
434k
        src += PXSTRIDE(src_stride);
852
434k
        mid_ptr += 8;
853
434k
    }
854
855
28.9k
    mid_ptr = &mid[3 * 8];
856
260k
    for (int y = 0; y < 8; y++, my += abcd[3]) {
857
2.08M
        for (int x = 0, tmy = my; x < 8; x++, tmy += abcd[2]) {
858
1.85M
            const int8_t *const filter =
859
1.85M
                dav1d_mc_warp_filter[64 + ((tmy + 512) >> 10)];
860
861
1.85M
            tmp[x] = FILTER_WARP_RND(mid_ptr, x, filter, 8, 7) - PREP_BIAS;
862
1.85M
        }
863
231k
        mid_ptr += 8;
864
231k
        tmp += tmp_stride;
865
231k
    }
866
28.9k
}
867
868
static void emu_edge_c(const intptr_t bw, const intptr_t bh,
869
                       const intptr_t iw, const intptr_t ih,
870
                       const intptr_t x, const intptr_t y,
871
                       pixel *dst, const ptrdiff_t dst_stride,
872
                       const pixel *ref, const ptrdiff_t ref_stride)
873
990k
{
874
    // find offset in reference of visible block to copy
875
990k
    ref += iclip((int) y, 0, (int) ih - 1) * PXSTRIDE(ref_stride) +
876
990k
           iclip((int) x, 0, (int) iw - 1);
877
878
    // number of pixels to extend (left, right, top, bottom)
879
990k
    const int left_ext = iclip((int) -x, 0, (int) bw - 1);
880
990k
    const int right_ext = iclip((int) (x + bw - iw), 0, (int) bw - 1);
881
990k
    assert(left_ext + right_ext < bw);
882
990k
    const int top_ext = iclip((int) -y, 0, (int) bh - 1);
883
990k
    const int bottom_ext = iclip((int) (y + bh - ih), 0, (int) bh - 1);
884
990k
    assert(top_ext + bottom_ext < bh);
885
886
    // copy visible portion first
887
990k
    pixel *blk = dst + top_ext * PXSTRIDE(dst_stride);
888
990k
    const int center_w = (int) (bw - left_ext - right_ext);
889
990k
    const int center_h = (int) (bh - top_ext - bottom_ext);
890
14.3M
    for (int y = 0; y < center_h; y++) {
891
13.3M
        pixel_copy(blk + left_ext, ref, center_w);
892
        // extend left edge for this line
893
13.3M
        if (left_ext)
894
2.60M
            pixel_set(blk, blk[left_ext], left_ext);
895
        // extend right edge for this line
896
13.3M
        if (right_ext)
897
10.1M
            pixel_set(blk + left_ext + center_w, blk[left_ext + center_w - 1],
898
10.1M
                      right_ext);
899
13.3M
        ref += PXSTRIDE(ref_stride);
900
13.3M
        blk += PXSTRIDE(dst_stride);
901
13.3M
    }
902
903
    // copy top
904
990k
    blk = dst + top_ext * PXSTRIDE(dst_stride);
905
2.16M
    for (int y = 0; y < top_ext; y++) {
906
1.17M
        pixel_copy(dst, blk, bw);
907
1.17M
        dst += PXSTRIDE(dst_stride);
908
1.17M
    }
909
910
    // copy bottom
911
990k
    dst += center_h * PXSTRIDE(dst_stride);
912
6.01M
    for (int y = 0; y < bottom_ext; y++) {
913
5.02M
        pixel_copy(dst, &dst[-PXSTRIDE(dst_stride)], bw);
914
5.02M
        dst += PXSTRIDE(dst_stride);
915
5.02M
    }
916
990k
}
917
918
static void resize_c(pixel *dst, const ptrdiff_t dst_stride,
919
                     const pixel *src, const ptrdiff_t src_stride,
920
                     const int dst_w, int h, const int src_w,
921
                     const int dx, const int mx0 HIGHBD_DECL_SUFFIX)
922
55.1k
{
923
1.78M
    do {
924
1.78M
        int mx = mx0, src_x = -1;
925
327M
        for (int x = 0; x < dst_w; x++) {
926
325M
            const int8_t *const F = dav1d_resize_filter[mx >> 8];
927
325M
            dst[x] = iclip_pixel((-(F[0] * src[iclip(src_x - 3, 0, src_w - 1)] +
928
325M
                                    F[1] * src[iclip(src_x - 2, 0, src_w - 1)] +
929
325M
                                    F[2] * src[iclip(src_x - 1, 0, src_w - 1)] +
930
325M
                                    F[3] * src[iclip(src_x + 0, 0, src_w - 1)] +
931
325M
                                    F[4] * src[iclip(src_x + 1, 0, src_w - 1)] +
932
325M
                                    F[5] * src[iclip(src_x + 2, 0, src_w - 1)] +
933
325M
                                    F[6] * src[iclip(src_x + 3, 0, src_w - 1)] +
934
325M
                                    F[7] * src[iclip(src_x + 4, 0, src_w - 1)]) +
935
325M
                                  64) >> 7);
936
325M
            mx += dx;
937
325M
            src_x += mx >> 14;
938
325M
            mx &= 0x3fff;
939
325M
        }
940
941
1.78M
        dst += PXSTRIDE(dst_stride);
942
1.78M
        src += PXSTRIDE(src_stride);
943
1.78M
    } while (--h);
944
55.1k
}
945
946
#if HAVE_ASM
947
#if ARCH_AARCH64 || ARCH_ARM
948
#include "src/arm/mc.h"
949
#elif ARCH_LOONGARCH64
950
#include "src/loongarch/mc.h"
951
#elif ARCH_PPC64LE
952
#include "src/ppc/mc.h"
953
#elif ARCH_RISCV
954
#include "src/riscv/mc.h"
955
#elif ARCH_X86
956
#include "src/x86/mc.h"
957
#endif
958
#endif
959
960
21.1k
COLD void bitfn(dav1d_mc_dsp_init)(Dav1dMCDSPContext *const c) {
961
211k
#define init_mc_fns(type, name) do { \
962
211k
    c->mc        [type] = put_##name##_c; \
963
211k
    c->mc_scaled [type] = put_##name##_scaled_c; \
964
211k
    c->mct       [type] = prep_##name##_c; \
965
211k
    c->mct_scaled[type] = prep_##name##_scaled_c; \
966
211k
} while (0)
967
968
21.1k
    init_mc_fns(FILTER_2D_8TAP_REGULAR,        8tap_regular);
969
21.1k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SMOOTH, 8tap_regular_smooth);
970
21.1k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SHARP,  8tap_regular_sharp);
971
21.1k
    init_mc_fns(FILTER_2D_8TAP_SHARP_REGULAR,  8tap_sharp_regular);
972
21.1k
    init_mc_fns(FILTER_2D_8TAP_SHARP_SMOOTH,   8tap_sharp_smooth);
973
21.1k
    init_mc_fns(FILTER_2D_8TAP_SHARP,          8tap_sharp);
974
21.1k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_REGULAR, 8tap_smooth_regular);
975
21.1k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH,         8tap_smooth);
976
21.1k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_SHARP,   8tap_smooth_sharp);
977
21.1k
    init_mc_fns(FILTER_2D_BILINEAR,            bilin);
978
979
21.1k
    c->avg      = avg_c;
980
21.1k
    c->w_avg    = w_avg_c;
981
21.1k
    c->mask     = mask_c;
982
21.1k
    c->blend    = blend_c;
983
21.1k
    c->blend_v  = blend_v_c;
984
21.1k
    c->blend_h  = blend_h_c;
985
21.1k
    c->w_mask[0] = w_mask_444_c;
986
21.1k
    c->w_mask[1] = w_mask_422_c;
987
21.1k
    c->w_mask[2] = w_mask_420_c;
988
21.1k
    c->warp8x8  = warp_affine_8x8_c;
989
21.1k
    c->warp8x8t = warp_affine_8x8t_c;
990
21.1k
    c->emu_edge = emu_edge_c;
991
21.1k
    c->resize   = resize_c;
992
993
#if HAVE_ASM
994
#if ARCH_AARCH64 || ARCH_ARM
995
    mc_dsp_init_arm(c);
996
#elif ARCH_LOONGARCH64
997
    mc_dsp_init_loongarch(c);
998
#elif ARCH_PPC64LE
999
    mc_dsp_init_ppc(c);
1000
#elif ARCH_RISCV
1001
    mc_dsp_init_riscv(c);
1002
#elif ARCH_X86
1003
    mc_dsp_init_x86(c);
1004
#endif
1005
#endif
1006
21.1k
}
dav1d_mc_dsp_init_8bpc
Line
Count
Source
960
9.81k
COLD void bitfn(dav1d_mc_dsp_init)(Dav1dMCDSPContext *const c) {
961
9.81k
#define init_mc_fns(type, name) do { \
962
9.81k
    c->mc        [type] = put_##name##_c; \
963
9.81k
    c->mc_scaled [type] = put_##name##_scaled_c; \
964
9.81k
    c->mct       [type] = prep_##name##_c; \
965
9.81k
    c->mct_scaled[type] = prep_##name##_scaled_c; \
966
9.81k
} while (0)
967
968
9.81k
    init_mc_fns(FILTER_2D_8TAP_REGULAR,        8tap_regular);
969
9.81k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SMOOTH, 8tap_regular_smooth);
970
9.81k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SHARP,  8tap_regular_sharp);
971
9.81k
    init_mc_fns(FILTER_2D_8TAP_SHARP_REGULAR,  8tap_sharp_regular);
972
9.81k
    init_mc_fns(FILTER_2D_8TAP_SHARP_SMOOTH,   8tap_sharp_smooth);
973
9.81k
    init_mc_fns(FILTER_2D_8TAP_SHARP,          8tap_sharp);
974
9.81k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_REGULAR, 8tap_smooth_regular);
975
9.81k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH,         8tap_smooth);
976
9.81k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_SHARP,   8tap_smooth_sharp);
977
9.81k
    init_mc_fns(FILTER_2D_BILINEAR,            bilin);
978
979
9.81k
    c->avg      = avg_c;
980
9.81k
    c->w_avg    = w_avg_c;
981
9.81k
    c->mask     = mask_c;
982
9.81k
    c->blend    = blend_c;
983
9.81k
    c->blend_v  = blend_v_c;
984
9.81k
    c->blend_h  = blend_h_c;
985
9.81k
    c->w_mask[0] = w_mask_444_c;
986
9.81k
    c->w_mask[1] = w_mask_422_c;
987
9.81k
    c->w_mask[2] = w_mask_420_c;
988
9.81k
    c->warp8x8  = warp_affine_8x8_c;
989
9.81k
    c->warp8x8t = warp_affine_8x8t_c;
990
9.81k
    c->emu_edge = emu_edge_c;
991
9.81k
    c->resize   = resize_c;
992
993
#if HAVE_ASM
994
#if ARCH_AARCH64 || ARCH_ARM
995
    mc_dsp_init_arm(c);
996
#elif ARCH_LOONGARCH64
997
    mc_dsp_init_loongarch(c);
998
#elif ARCH_PPC64LE
999
    mc_dsp_init_ppc(c);
1000
#elif ARCH_RISCV
1001
    mc_dsp_init_riscv(c);
1002
#elif ARCH_X86
1003
    mc_dsp_init_x86(c);
1004
#endif
1005
#endif
1006
9.81k
}
dav1d_mc_dsp_init_16bpc
Line
Count
Source
960
11.2k
COLD void bitfn(dav1d_mc_dsp_init)(Dav1dMCDSPContext *const c) {
961
11.2k
#define init_mc_fns(type, name) do { \
962
11.2k
    c->mc        [type] = put_##name##_c; \
963
11.2k
    c->mc_scaled [type] = put_##name##_scaled_c; \
964
11.2k
    c->mct       [type] = prep_##name##_c; \
965
11.2k
    c->mct_scaled[type] = prep_##name##_scaled_c; \
966
11.2k
} while (0)
967
968
11.2k
    init_mc_fns(FILTER_2D_8TAP_REGULAR,        8tap_regular);
969
11.2k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SMOOTH, 8tap_regular_smooth);
970
11.2k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SHARP,  8tap_regular_sharp);
971
11.2k
    init_mc_fns(FILTER_2D_8TAP_SHARP_REGULAR,  8tap_sharp_regular);
972
11.2k
    init_mc_fns(FILTER_2D_8TAP_SHARP_SMOOTH,   8tap_sharp_smooth);
973
11.2k
    init_mc_fns(FILTER_2D_8TAP_SHARP,          8tap_sharp);
974
11.2k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_REGULAR, 8tap_smooth_regular);
975
11.2k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH,         8tap_smooth);
976
11.2k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_SHARP,   8tap_smooth_sharp);
977
11.2k
    init_mc_fns(FILTER_2D_BILINEAR,            bilin);
978
979
11.2k
    c->avg      = avg_c;
980
11.2k
    c->w_avg    = w_avg_c;
981
11.2k
    c->mask     = mask_c;
982
11.2k
    c->blend    = blend_c;
983
11.2k
    c->blend_v  = blend_v_c;
984
11.2k
    c->blend_h  = blend_h_c;
985
11.2k
    c->w_mask[0] = w_mask_444_c;
986
11.2k
    c->w_mask[1] = w_mask_422_c;
987
11.2k
    c->w_mask[2] = w_mask_420_c;
988
11.2k
    c->warp8x8  = warp_affine_8x8_c;
989
11.2k
    c->warp8x8t = warp_affine_8x8t_c;
990
11.2k
    c->emu_edge = emu_edge_c;
991
11.2k
    c->resize   = resize_c;
992
993
#if HAVE_ASM
994
#if ARCH_AARCH64 || ARCH_ARM
995
    mc_dsp_init_arm(c);
996
#elif ARCH_LOONGARCH64
997
    mc_dsp_init_loongarch(c);
998
#elif ARCH_PPC64LE
999
    mc_dsp_init_ppc(c);
1000
#elif ARCH_RISCV
1001
    mc_dsp_init_riscv(c);
1002
#elif ARCH_X86
1003
    mc_dsp_init_x86(c);
1004
#endif
1005
#endif
1006
11.2k
}