Coverage Report

Created: 2026-07-30 06:25

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.38M
#define get_intermediate_bits(bitdepth_max) 4
41
// Output in interval [-5132, 9212], fits in int16_t as is
42
140M
#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
215k
{
55
4.64M
    do {
56
4.64M
        pixel_copy(dst, src, w);
57
58
4.64M
        dst += dst_stride;
59
4.64M
        src += src_stride;
60
4.64M
    } while (--h);
61
215k
}
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
50.7k
{
67
50.7k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
68
1.48M
    do {
69
56.7M
        for (int x = 0; x < w; x++)
70
55.2M
            tmp[x] = (src[x] << intermediate_bits) - PREP_BIAS;
71
72
1.48M
        tmp += w;
73
1.48M
        src += src_stride;
74
1.48M
    } while (--h);
75
50.7k
}
76
77
#define FILTER_8TAP(src, x, F, stride) \
78
282M
    (F[0] * src[x + -3 * stride] + \
79
282M
     F[1] * src[x + -2 * stride] + \
80
282M
     F[2] * src[x + -1 * stride] + \
81
282M
     F[3] * src[x + +0 * stride] + \
82
282M
     F[4] * src[x + +1 * stride] + \
83
282M
     F[5] * src[x + +2 * stride] + \
84
282M
     F[6] * src[x + +3 * stride] + \
85
282M
     F[7] * src[x + +4 * stride])
86
87
#define FILTER_8TAP2(src, x, F) \
88
266M
    (F[0] * src[0][x] + \
89
266M
     F[1] * src[1][x] + \
90
266M
     F[2] * src[2][x] + \
91
266M
     F[3] * src[3][x] + \
92
266M
     F[4] * src[4][x] + \
93
266M
     F[5] * src[5][x] + \
94
266M
     F[6] * src[6][x] + \
95
266M
     F[7] * src[7][x])
96
97
#define DAV1D_FILTER_8TAP_RND(src, x, F, stride, sh) \
98
261M
    ((FILTER_8TAP(src, x, F, stride) + ((1 << (sh)) >> 1)) >> (sh))
99
100
#define DAV1D_FILTER_8TAP_RND2(src, x, F, stride, rnd, sh) \
101
20.8M
    ((FILTER_8TAP(src, x, F, stride) + (rnd)) >> (sh))
102
103
#define DAV1D_FILTER_8TAP_RND3(src, x, F, sh) \
104
266M
    ((FILTER_8TAP2(src, x, F) + ((1 << (sh)) >> 1)) >> (sh))
105
106
#define DAV1D_FILTER_8TAP_CLIP(src, x, F, stride, sh) \
107
25.7M
    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
20.8M
    iclip_pixel(DAV1D_FILTER_8TAP_RND2(src, x, F, stride, rnd, sh))
111
112
#define DAV1D_FILTER_8TAP_CLIP3(src, x, F, sh) \
113
210M
    iclip_pixel(DAV1D_FILTER_8TAP_RND3(src, x, F, sh))
114
115
#define GET_H_FILTER(mx) \
116
204M
    const int8_t *const fh = !(mx) ? NULL : w > 4 ? \
117
190M
        dav1d_mc_subpel_filters[filter_type & 3][(mx) - 1] : \
118
190M
        dav1d_mc_subpel_filters[3 + (filter_type & 1)][(mx) - 1]
119
120
#define GET_V_FILTER(my) \
121
10.4M
    const int8_t *const fv = !(my) ? NULL : h > 4 ? \
122
9.41M
        dav1d_mc_subpel_filters[filter_type >> 2][(my) - 1] : \
123
9.41M
        dav1d_mc_subpel_filters[3 + ((filter_type >> 2) & 1)][(my) - 1]
124
125
#define GET_FILTERS() \
126
350k
    GET_H_FILTER(mx); \
127
350k
    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
276k
{
135
276k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
136
276k
    const int intermediate_rnd = 32 + ((1 << (6 - intermediate_bits)) >> 1);
137
138
276k
    GET_FILTERS();
139
276k
    dst_stride = PXSTRIDE(dst_stride);
140
276k
    src_stride = PXSTRIDE(src_stride);
141
142
276k
    if (fh) {
143
111k
        if (fv) {
144
64.7k
            int tmp_h = h + 7;
145
64.7k
            int16_t mid[128 * 135], *mid_ptr = mid;
146
147
64.7k
            src -= src_stride * 3;
148
1.17M
            do {
149
26.5M
                for (int x = 0; x < w; x++)
150
25.3M
                    mid_ptr[x] = DAV1D_FILTER_8TAP_RND(src, x, fh, 1,
151
1.17M
                                                       6 - intermediate_bits);
152
153
1.17M
                mid_ptr += 128;
154
1.17M
                src += src_stride;
155
1.17M
            } while (--tmp_h);
156
157
64.7k
            mid_ptr = mid + 128 * 3;
158
691k
            do {
159
17.7M
                for (int x = 0; x < w; x++)
160
17.1M
                    dst[x] = DAV1D_FILTER_8TAP_CLIP(mid_ptr, x, fv, 128,
161
691k
                                                    6 + intermediate_bits);
162
163
691k
                mid_ptr += 128;
164
691k
                dst += dst_stride;
165
691k
            } while (--h);
166
64.7k
        } else {
167
574k
            do {
168
21.3M
                for (int x = 0; x < w; x++) {
169
20.8M
                    dst[x] = DAV1D_FILTER_8TAP_CLIP2(src, x, fh, 1,
170
20.8M
                                                     intermediate_rnd, 6);
171
20.8M
                }
172
173
574k
                dst += dst_stride;
174
574k
                src += src_stride;
175
574k
            } while (--h);
176
47.1k
        }
177
164k
    } else if (fv) {
178
357k
        do {
179
9.05M
            for (int x = 0; x < w; x++)
180
8.69M
                dst[x] = DAV1D_FILTER_8TAP_CLIP(src, x, fv, src_stride, 6);
181
182
357k
            dst += dst_stride;
183
357k
            src += src_stride;
184
357k
        } while (--h);
185
36.0k
    } else
186
128k
        put_c(dst, dst_stride, src, src_stride, w, h);
187
276k
}
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
536k
{
196
536k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
197
536k
    const int intermediate_rnd = (1 << intermediate_bits) >> 1;
198
536k
    int16_t mid[128 * 8];
199
536k
    int16_t *mid_ptrs[8];
200
536k
    int in_y = -8;
201
536k
    src_stride = PXSTRIDE(src_stride);
202
203
4.82M
    for (int i = 0; i < 8; i++)
204
4.28M
        mid_ptrs[i] = &mid[128 * i];
205
206
536k
    src -= src_stride * 3;
207
208
8.78M
    for (int y = 0; y < h; y++) {
209
8.24M
        int x;
210
8.24M
        int src_y = my >> 10;
211
8.24M
        GET_V_FILTER((my & 0x3ff) >> 6);
212
213
15.8M
        while (in_y < src_y) {
214
7.55M
            int imx = mx, ioff = 0;
215
7.55M
            int16_t *mid_ptr = mid_ptrs[0];
216
217
60.4M
            for (int i = 0; i < 7; i++)
218
52.9M
                mid_ptrs[i] = mid_ptrs[i + 1];
219
7.55M
            mid_ptrs[7] = mid_ptr;
220
221
172M
            for (x = 0; x < w; x++) {
222
164M
                GET_H_FILTER(imx >> 6);
223
164M
                mid_ptr[x] = fh ? DAV1D_FILTER_8TAP_RND(src, ioff, fh, 1,
224
164M
                                                        6 - intermediate_bits) :
225
164M
                                  src[ioff] << intermediate_bits;
226
164M
                imx += dx;
227
164M
                ioff += imx >> 10;
228
164M
                imx &= 0x3ff;
229
164M
            }
230
231
7.55M
            src += src_stride;
232
7.55M
            in_y++;
233
7.55M
        }
234
235
236M
        for (x = 0; x < w; x++)
236
228M
            dst[x] = fv ? DAV1D_FILTER_8TAP_CLIP3(mid_ptrs, x, fv,
237
228M
                                                  6 + intermediate_bits) :
238
228M
                          iclip_pixel((mid_ptrs[3][x] + intermediate_rnd) >>
239
18.4M
                                              intermediate_bits);
240
241
8.24M
        my += dy;
242
8.24M
        dst += PXSTRIDE(dst_stride);
243
8.24M
    }
244
536k
}
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
74.5k
{
251
74.5k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
252
74.5k
    GET_FILTERS();
253
74.5k
    src_stride = PXSTRIDE(src_stride);
254
255
74.5k
    if (fh) {
256
19.8k
        if (fv) {
257
13.3k
            int tmp_h = h + 7;
258
13.3k
            int16_t mid[128 * 135], *mid_ptr = mid;
259
260
13.3k
            src -= src_stride * 3;
261
267k
            do {
262
6.07M
                for (int x = 0; x < w; x++)
263
5.80M
                    mid_ptr[x] = DAV1D_FILTER_8TAP_RND(src, x, fh, 1,
264
267k
                                                       6 - intermediate_bits);
265
266
267k
                mid_ptr += 128;
267
267k
                src += src_stride;
268
267k
            } while (--tmp_h);
269
270
13.3k
            mid_ptr = mid + 128 * 3;
271
174k
            do {
272
4.67M
                for (int x = 0; x < w; x++) {
273
4.50M
                    int t = DAV1D_FILTER_8TAP_RND(mid_ptr, x, fv, 128, 6) -
274
4.50M
                                  PREP_BIAS;
275
4.50M
                    assert(t >= INT16_MIN && t <= INT16_MAX);
276
4.50M
                    tmp[x] = t;
277
4.50M
                }
278
279
174k
                mid_ptr += 128;
280
174k
                tmp += w;
281
174k
            } while (--h);
282
13.3k
        } else {
283
123k
            do {
284
4.34M
                for (int x = 0; x < w; x++)
285
4.22M
                    tmp[x] = DAV1D_FILTER_8TAP_RND(src, x, fh, 1,
286
4.22M
                                                   6 - intermediate_bits) -
287
4.22M
                             PREP_BIAS;
288
289
123k
                tmp += w;
290
123k
                src += src_stride;
291
123k
            } while (--h);
292
6.47k
        }
293
54.7k
    } else if (fv) {
294
161k
        do {
295
5.08M
            for (int x = 0; x < w; x++)
296
4.92M
                tmp[x] = DAV1D_FILTER_8TAP_RND(src, x, fv, src_stride,
297
4.92M
                                               6 - intermediate_bits) -
298
4.92M
                         PREP_BIAS;
299
300
161k
            tmp += w;
301
161k
            src += src_stride;
302
161k
        } while (--h);
303
7.92k
    } else
304
46.8k
        prep_c(tmp, src, src_stride, w, h HIGHBD_TAIL_SUFFIX);
305
74.5k
}
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
50.5k
{
313
50.5k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
314
50.5k
    int16_t mid[128 * 8];
315
50.5k
    int16_t *mid_ptrs[8];
316
50.5k
    int in_y = -8;
317
50.5k
    src_stride = PXSTRIDE(src_stride);
318
319
454k
    for (int i = 0; i < 8; i++)
320
404k
        mid_ptrs[i] = &mid[128 * i];
321
322
50.5k
    src -= src_stride * 3;
323
324
1.86M
    for (int y = 0; y < h; y++) {
325
1.81M
        int x;
326
1.81M
        int src_y = my >> 10;
327
1.81M
        GET_V_FILTER((my & 0x3ff) >> 6);
328
329
3.01M
        while (in_y < src_y) {
330
1.20M
            int imx = mx, ioff = 0;
331
1.20M
            int16_t *mid_ptr = mid_ptrs[0];
332
333
9.61M
            for (int i = 0; i < 7; i++)
334
8.41M
                mid_ptrs[i] = mid_ptrs[i + 1];
335
1.20M
            mid_ptrs[7] = mid_ptr;
336
337
40.6M
            for (x = 0; x < w; x++) {
338
39.4M
                GET_H_FILTER(imx >> 6);
339
39.4M
                mid_ptr[x] = fh ? DAV1D_FILTER_8TAP_RND(src, ioff, fh, 1,
340
39.4M
                                                        6 - intermediate_bits) :
341
39.4M
                                  src[ioff] << intermediate_bits;
342
39.4M
                imx += dx;
343
39.4M
                ioff += imx >> 10;
344
39.4M
                imx &= 0x3ff;
345
39.4M
            }
346
347
1.20M
            src += src_stride;
348
1.20M
            in_y++;
349
1.20M
        }
350
351
64.3M
        for (x = 0; x < w; x++)
352
62.5M
            tmp[x] = (fv ? DAV1D_FILTER_8TAP_RND3(mid_ptrs, x, fv, 6)
353
62.5M
                         : mid_ptrs[3][x]) - PREP_BIAS;
354
355
1.81M
        my += dy;
356
1.81M
        tmp += w;
357
1.81M
    }
358
50.5k
}
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
276k
                                HIGHBD_DECL_SUFFIX) \
368
276k
{ \
369
276k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
276k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
276k
} \
mc_tmpl.c:put_8tap_regular_c
Line
Count
Source
367
190k
                                HIGHBD_DECL_SUFFIX) \
368
190k
{ \
369
190k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
190k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
190k
} \
mc_tmpl.c:put_8tap_regular_smooth_c
Line
Count
Source
367
5.95k
                                HIGHBD_DECL_SUFFIX) \
368
5.95k
{ \
369
5.95k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
5.95k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
5.95k
} \
mc_tmpl.c:put_8tap_regular_sharp_c
Line
Count
Source
367
727
                                HIGHBD_DECL_SUFFIX) \
368
727
{ \
369
727
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
727
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
727
} \
mc_tmpl.c:put_8tap_sharp_regular_c
Line
Count
Source
367
492
                                HIGHBD_DECL_SUFFIX) \
368
492
{ \
369
492
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
492
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
492
} \
mc_tmpl.c:put_8tap_sharp_smooth_c
Line
Count
Source
367
302
                                HIGHBD_DECL_SUFFIX) \
368
302
{ \
369
302
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
302
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
302
} \
mc_tmpl.c:put_8tap_sharp_c
Line
Count
Source
367
23.3k
                                HIGHBD_DECL_SUFFIX) \
368
23.3k
{ \
369
23.3k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
23.3k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
23.3k
} \
mc_tmpl.c:put_8tap_smooth_regular_c
Line
Count
Source
367
5.91k
                                HIGHBD_DECL_SUFFIX) \
368
5.91k
{ \
369
5.91k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
5.91k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
5.91k
} \
mc_tmpl.c:put_8tap_smooth_c
Line
Count
Source
367
48.7k
                                HIGHBD_DECL_SUFFIX) \
368
48.7k
{ \
369
48.7k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
48.7k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
48.7k
} \
mc_tmpl.c:put_8tap_smooth_sharp_c
Line
Count
Source
367
378
                                HIGHBD_DECL_SUFFIX) \
368
378
{ \
369
378
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
378
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
378
} \
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
536k
                                       HIGHBD_DECL_SUFFIX) \
380
536k
{ \
381
536k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
536k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
536k
} \
mc_tmpl.c:put_8tap_regular_scaled_c
Line
Count
Source
379
372k
                                       HIGHBD_DECL_SUFFIX) \
380
372k
{ \
381
372k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
372k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
372k
} \
mc_tmpl.c:put_8tap_regular_smooth_scaled_c
Line
Count
Source
379
10.6k
                                       HIGHBD_DECL_SUFFIX) \
380
10.6k
{ \
381
10.6k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
10.6k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
10.6k
} \
mc_tmpl.c:put_8tap_regular_sharp_scaled_c
Line
Count
Source
379
978
                                       HIGHBD_DECL_SUFFIX) \
380
978
{ \
381
978
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
978
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
978
} \
mc_tmpl.c:put_8tap_sharp_regular_scaled_c
Line
Count
Source
379
1.56k
                                       HIGHBD_DECL_SUFFIX) \
380
1.56k
{ \
381
1.56k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
1.56k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
1.56k
} \
mc_tmpl.c:put_8tap_sharp_smooth_scaled_c
Line
Count
Source
379
380
                                       HIGHBD_DECL_SUFFIX) \
380
380
{ \
381
380
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
380
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
380
} \
mc_tmpl.c:put_8tap_sharp_scaled_c
Line
Count
Source
379
27.7k
                                       HIGHBD_DECL_SUFFIX) \
380
27.7k
{ \
381
27.7k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
27.7k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
27.7k
} \
mc_tmpl.c:put_8tap_smooth_regular_scaled_c
Line
Count
Source
379
5.77k
                                       HIGHBD_DECL_SUFFIX) \
380
5.77k
{ \
381
5.77k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
5.77k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
5.77k
} \
mc_tmpl.c:put_8tap_smooth_scaled_c
Line
Count
Source
379
115k
                                       HIGHBD_DECL_SUFFIX) \
380
115k
{ \
381
115k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
115k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
115k
} \
mc_tmpl.c:put_8tap_smooth_sharp_scaled_c
Line
Count
Source
379
504
                                       HIGHBD_DECL_SUFFIX) \
380
504
{ \
381
504
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
504
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
504
} \
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
74.5k
                                 HIGHBD_DECL_SUFFIX) \
390
74.5k
{ \
391
74.5k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
74.5k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
74.5k
} \
mc_tmpl.c:prep_8tap_regular_c
Line
Count
Source
389
34.1k
                                 HIGHBD_DECL_SUFFIX) \
390
34.1k
{ \
391
34.1k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
34.1k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
34.1k
} \
mc_tmpl.c:prep_8tap_regular_smooth_c
Line
Count
Source
389
1.48k
                                 HIGHBD_DECL_SUFFIX) \
390
1.48k
{ \
391
1.48k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
1.48k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
1.48k
} \
mc_tmpl.c:prep_8tap_regular_sharp_c
Line
Count
Source
389
1.56k
                                 HIGHBD_DECL_SUFFIX) \
390
1.56k
{ \
391
1.56k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
1.56k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
1.56k
} \
mc_tmpl.c:prep_8tap_sharp_regular_c
Line
Count
Source
389
1.70k
                                 HIGHBD_DECL_SUFFIX) \
390
1.70k
{ \
391
1.70k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
1.70k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
1.70k
} \
mc_tmpl.c:prep_8tap_sharp_smooth_c
Line
Count
Source
389
867
                                 HIGHBD_DECL_SUFFIX) \
390
867
{ \
391
867
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
867
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
867
} \
mc_tmpl.c:prep_8tap_sharp_c
Line
Count
Source
389
11.8k
                                 HIGHBD_DECL_SUFFIX) \
390
11.8k
{ \
391
11.8k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
11.8k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
11.8k
} \
mc_tmpl.c:prep_8tap_smooth_regular_c
Line
Count
Source
389
1.48k
                                 HIGHBD_DECL_SUFFIX) \
390
1.48k
{ \
391
1.48k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
1.48k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
1.48k
} \
mc_tmpl.c:prep_8tap_smooth_c
Line
Count
Source
389
20.0k
                                 HIGHBD_DECL_SUFFIX) \
390
20.0k
{ \
391
20.0k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
20.0k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
20.0k
} \
mc_tmpl.c:prep_8tap_smooth_sharp_c
Line
Count
Source
389
1.45k
                                 HIGHBD_DECL_SUFFIX) \
390
1.45k
{ \
391
1.45k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
1.45k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
1.45k
} \
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
50.5k
                                        HIGHBD_DECL_SUFFIX) \
401
50.5k
{ \
402
50.5k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
50.5k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
50.5k
}
mc_tmpl.c:prep_8tap_regular_scaled_c
Line
Count
Source
400
11.1k
                                        HIGHBD_DECL_SUFFIX) \
401
11.1k
{ \
402
11.1k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
11.1k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
11.1k
}
mc_tmpl.c:prep_8tap_regular_smooth_scaled_c
Line
Count
Source
400
1.04k
                                        HIGHBD_DECL_SUFFIX) \
401
1.04k
{ \
402
1.04k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
1.04k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
1.04k
}
mc_tmpl.c:prep_8tap_regular_sharp_scaled_c
Line
Count
Source
400
1.88k
                                        HIGHBD_DECL_SUFFIX) \
401
1.88k
{ \
402
1.88k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
1.88k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
1.88k
}
mc_tmpl.c:prep_8tap_sharp_regular_scaled_c
Line
Count
Source
400
3.38k
                                        HIGHBD_DECL_SUFFIX) \
401
3.38k
{ \
402
3.38k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
3.38k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
3.38k
}
mc_tmpl.c:prep_8tap_sharp_smooth_scaled_c
Line
Count
Source
400
835
                                        HIGHBD_DECL_SUFFIX) \
401
835
{ \
402
835
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
835
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
835
}
mc_tmpl.c:prep_8tap_sharp_scaled_c
Line
Count
Source
400
14.7k
                                        HIGHBD_DECL_SUFFIX) \
401
14.7k
{ \
402
14.7k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
14.7k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
14.7k
}
mc_tmpl.c:prep_8tap_smooth_regular_scaled_c
Line
Count
Source
400
2.23k
                                        HIGHBD_DECL_SUFFIX) \
401
2.23k
{ \
402
2.23k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
2.23k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
2.23k
}
mc_tmpl.c:prep_8tap_smooth_scaled_c
Line
Count
Source
400
14.3k
                                        HIGHBD_DECL_SUFFIX) \
401
14.3k
{ \
402
14.3k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
14.3k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
14.3k
}
mc_tmpl.c:prep_8tap_smooth_sharp_scaled_c
Line
Count
Source
400
929
                                        HIGHBD_DECL_SUFFIX) \
401
929
{ \
402
929
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
929
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
929
}
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
29.9M
    (16 * src[x] + ((mxy) * (src[x + stride] - src[x])))
418
419
#define FILTER_BILIN_RND(src, x, mxy, stride, sh) \
420
29.9M
    ((FILTER_BILIN(src, x, mxy, stride) + ((1 << (sh)) >> 1)) >> (sh))
421
422
#define FILTER_BILIN_CLIP(src, x, mxy, stride, sh) \
423
4.00M
    iclip_pixel(FILTER_BILIN_RND(src, x, mxy, stride, sh))
424
425
#define FILTER_BILIN2(src1, src2, x, mxy) \
426
14.9M
    (16 * src1[x] + ((mxy) * (src2[x] - src1[x])))
427
428
#define FILTER_BILIN_RND2(src1, src2, x, mxy, sh) \
429
14.9M
    ((FILTER_BILIN2(src1, src2, x, mxy) + ((1 << (sh)) >> 1)) >> (sh))
430
431
#define FILTER_BILIN_CLIP2(src1, src2, x, mxy, sh) \
432
11.7M
    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
142k
{
439
142k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
440
142k
    const int intermediate_rnd = (1 << intermediate_bits) >> 1;
441
142k
    dst_stride = PXSTRIDE(dst_stride);
442
142k
    src_stride = PXSTRIDE(src_stride);
443
444
142k
    if (mx) {
445
40.4k
        if (my) {
446
22.8k
            int16_t mid[128 * 129], *mid_ptr = mid;
447
22.8k
            int tmp_h = h + 1;
448
449
201k
            do {
450
2.77M
                for (int x = 0; x < w; x++)
451
2.57M
                    mid_ptr[x] = FILTER_BILIN_RND(src, x, mx, 1,
452
201k
                                                  4 - intermediate_bits);
453
454
201k
                mid_ptr += 128;
455
201k
                src += src_stride;
456
201k
            } while (--tmp_h);
457
458
22.8k
            mid_ptr = mid;
459
178k
            do {
460
2.54M
                for (int x = 0; x < w; x++)
461
2.36M
                    dst[x] = FILTER_BILIN_CLIP(mid_ptr, x, my, 128,
462
178k
                                               4 + intermediate_bits);
463
464
178k
                mid_ptr += 128;
465
178k
                dst += dst_stride;
466
178k
            } while (--h);
467
22.8k
        } else {
468
209k
            do {
469
6.39M
                for (int x = 0; x < w; x++) {
470
6.18M
                    const int px = FILTER_BILIN_RND(src, x, mx, 1,
471
6.18M
                                                    4 - intermediate_bits);
472
6.18M
                    dst[x] = iclip_pixel((px + intermediate_rnd) >> intermediate_bits);
473
6.18M
                }
474
475
209k
                dst += dst_stride;
476
209k
                src += src_stride;
477
209k
            } while (--h);
478
17.5k
        }
479
102k
    } else if (my) {
480
114k
        do {
481
1.75M
            for (int x = 0; x < w; x++)
482
1.64M
                dst[x] = FILTER_BILIN_CLIP(src, x, my, src_stride, 4);
483
484
114k
            dst += dst_stride;
485
114k
            src += src_stride;
486
114k
        } while (--h);
487
14.3k
    } else
488
87.7k
        put_c(dst, dst_stride, src, src_stride, w, h);
489
142k
}
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
24.6k
{
497
24.6k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
498
24.6k
    int16_t mid[128 * 2];
499
24.6k
    int in_y = -2;
500
501
313k
    do {
502
313k
        int x;
503
313k
        int y = my >> 10;
504
313k
        int16_t *mid1 = &mid[(y & 1) * 128];
505
313k
        int16_t *mid2 = &mid[((y + 1) & 1) * 128];
506
313k
        int dmy = my & 0x3ff;
507
508
472k
        while (in_y < y) {
509
158k
            int imx = mx, ioff = 0;
510
158k
            int16_t *mid_ptr = &mid[(in_y & 1) * 128];
511
512
8.61M
            for (x = 0; x < w; x++) {
513
8.45M
                mid_ptr[x] = FILTER_BILIN_RND(src, ioff, imx >> 6, 1,
514
8.45M
                                              4 - intermediate_bits);
515
8.45M
                imx += dx;
516
8.45M
                ioff += imx >> 10;
517
8.45M
                imx &= 0x3ff;
518
8.45M
            }
519
520
158k
            src += PXSTRIDE(src_stride);
521
158k
            in_y++;
522
158k
        }
523
524
12.0M
        for (x = 0; x < w; x++)
525
11.7M
            dst[x] = FILTER_BILIN_CLIP2(mid1, mid2, x, dmy >> 6,
526
313k
                                       4 + intermediate_bits);
527
528
313k
        my += dy;
529
313k
        dst += PXSTRIDE(dst_stride);
530
313k
    } while (--h);
531
24.6k
}
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
17.5k
{
538
17.5k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
539
17.5k
    src_stride = PXSTRIDE(src_stride);
540
541
17.5k
    if (mx) {
542
11.0k
        if (my) {
543
8.59k
            int16_t mid[128 * 129], *mid_ptr = mid;
544
8.59k
            int tmp_h = h + 1;
545
546
104k
            do {
547
2.28M
                for (int x = 0; x < w; x++)
548
2.18M
                    mid_ptr[x] = FILTER_BILIN_RND(src, x, mx, 1,
549
104k
                                                  4 - intermediate_bits);
550
551
104k
                mid_ptr += 128;
552
104k
                src += src_stride;
553
104k
            } while (--tmp_h);
554
555
8.59k
            mid_ptr = mid;
556
95.9k
            do {
557
2.15M
                for (int x = 0; x < w; x++)
558
2.05M
                    tmp[x] = FILTER_BILIN_RND(mid_ptr, x, my, 128, 4) -
559
2.05M
                             PREP_BIAS;
560
561
95.9k
                mid_ptr += 128;
562
95.9k
                tmp += w;
563
95.9k
            } while (--h);
564
8.59k
        } else {
565
35.4k
            do {
566
729k
                for (int x = 0; x < w; x++)
567
693k
                    tmp[x] = FILTER_BILIN_RND(src, x, mx, 1,
568
693k
                                              4 - intermediate_bits) -
569
693k
                             PREP_BIAS;
570
571
35.4k
                tmp += w;
572
35.4k
                src += src_stride;
573
35.4k
            } while (--h);
574
2.48k
        }
575
11.0k
    } else if (my) {
576
40.2k
        do {
577
1.21M
            for (int x = 0; x < w; x++)
578
1.17M
                tmp[x] = FILTER_BILIN_RND(src, x, my, src_stride,
579
1.17M
                                          4 - intermediate_bits) - PREP_BIAS;
580
581
40.2k
            tmp += w;
582
40.2k
            src += src_stride;
583
40.2k
        } while (--h);
584
2.56k
    } else
585
3.91k
        prep_c(tmp, src, src_stride, w, h HIGHBD_TAIL_SUFFIX);
586
17.5k
}
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
2.61k
{
593
2.61k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
594
2.61k
    int16_t mid[128 * 2];
595
2.61k
    int in_y = -2;
596
597
52.8k
    do {
598
52.8k
        int x;
599
52.8k
        int y = my >> 10;
600
52.8k
        int16_t *mid1 = &mid[(y & 1) * 128];
601
52.8k
        int16_t *mid2 = &mid[((y + 1) & 1) * 128];
602
52.8k
        int dmy = my & 0x3ff;
603
604
95.3k
        while (in_y < y) {
605
42.5k
            int imx = mx, ioff = 0;
606
42.5k
            int16_t *mid_ptr = &mid[(in_y & 1) * 128];
607
608
2.63M
            for (x = 0; x < w; x++) {
609
2.58M
                mid_ptr[x] = FILTER_BILIN_RND(src, ioff, imx >> 6, 1,
610
2.58M
                                              4 - intermediate_bits);
611
2.58M
                imx += dx;
612
2.58M
                ioff += imx >> 10;
613
2.58M
                imx &= 0x3ff;
614
2.58M
            }
615
616
42.5k
            src += PXSTRIDE(src_stride);
617
42.5k
            in_y++;
618
42.5k
        }
619
620
3.27M
        for (x = 0; x < w; x++)
621
3.22M
            tmp[x] = FILTER_BILIN_RND2(mid1, mid2, x, dmy >> 6, 4) - PREP_BIAS;
622
623
52.8k
        my += dy;
624
52.8k
        tmp += w;
625
52.8k
    } while (--h);
626
2.61k
}
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
61.4k
{
632
61.4k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
633
61.4k
    const int sh = intermediate_bits + 1;
634
61.4k
    const int rnd = (1 << intermediate_bits) + PREP_BIAS * 2;
635
1.55M
    do {
636
51.2M
        for (int x = 0; x < w; x++)
637
49.6M
            dst[x] = iclip_pixel((tmp1[x] + tmp2[x] + rnd) >> sh);
638
639
1.55M
        tmp1 += w;
640
1.55M
        tmp2 += w;
641
1.55M
        dst += PXSTRIDE(dst_stride);
642
1.55M
    } while (--h);
643
61.4k
}
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
4.79k
{
649
4.79k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
650
4.79k
    const int sh = intermediate_bits + 4;
651
4.79k
    const int rnd = (8 << intermediate_bits) + PREP_BIAS * 16;
652
166k
    do {
653
7.71M
        for (int x = 0; x < w; x++)
654
7.55M
            dst[x] = iclip_pixel((tmp1[x] * weight +
655
7.55M
                                  tmp2[x] * (16 - weight) + rnd) >> sh);
656
657
166k
        tmp1 += w;
658
166k
        tmp2 += w;
659
166k
        dst += PXSTRIDE(dst_stride);
660
166k
    } while (--h);
661
4.79k
}
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
8.44k
{
667
8.44k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
668
8.44k
    const int sh = intermediate_bits + 6;
669
8.44k
    const int rnd = (32 << intermediate_bits) + PREP_BIAS * 64;
670
179k
    do {
671
5.98M
        for (int x = 0; x < w; x++)
672
5.80M
            dst[x] = iclip_pixel((tmp1[x] * mask[x] +
673
5.80M
                                  tmp2[x] * (64 - mask[x]) + rnd) >> sh);
674
675
179k
        tmp1 += w;
676
179k
        tmp2 += w;
677
179k
        mask += w;
678
179k
        dst += PXSTRIDE(dst_stride);
679
179k
    } while (--h);
680
8.44k
}
681
682
24.4M
#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
26.2k
{
686
327k
    do {
687
5.29M
        for (int x = 0; x < w; x++) {
688
4.96M
            dst[x] = blend_px(dst[x], tmp[x], mask[x]);
689
4.96M
        }
690
327k
        dst += PXSTRIDE(dst_stride);
691
327k
        tmp += w;
692
327k
        mask += w;
693
327k
    } while (--h);
694
26.2k
}
695
696
static void blend_v_c(pixel *dst, const ptrdiff_t dst_stride, const pixel *tmp,
697
                      const int w, int h)
698
115k
{
699
115k
    const uint8_t *const mask = &dav1d_obmc_masks[w];
700
1.54M
    do {
701
12.6M
        for (int x = 0; x < (w * 3) >> 2; x++) {
702
11.1M
            dst[x] = blend_px(dst[x], tmp[x], mask[x]);
703
11.1M
        }
704
1.54M
        dst += PXSTRIDE(dst_stride);
705
1.54M
        tmp += w;
706
1.54M
    } while (--h);
707
115k
}
708
709
static void blend_h_c(pixel *dst, const ptrdiff_t dst_stride, const pixel *tmp,
710
                      const int w, int h)
711
103k
{
712
103k
    const uint8_t *mask = &dav1d_obmc_masks[h];
713
103k
    h = (h * 3) >> 2;
714
540k
    do {
715
540k
        const int m = *mask++;
716
8.92M
        for (int x = 0; x < w; x++) {
717
8.38M
            dst[x] = blend_px(dst[x], tmp[x], m);
718
8.38M
        }
719
540k
        dst += PXSTRIDE(dst_stride);
720
540k
        tmp += w;
721
540k
    } while (--h);
722
103k
}
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
2.63k
{
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
2.63k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
732
2.63k
    const int bitdepth = bitdepth_from_max(bitdepth_max);
733
2.63k
    const int sh = intermediate_bits + 6;
734
2.63k
    const int rnd = (32 << intermediate_bits) + PREP_BIAS * 64;
735
2.63k
    const int mask_sh = bitdepth + intermediate_bits - 4;
736
2.63k
    const int mask_rnd = 1 << (mask_sh - 5);
737
128k
    do {
738
4.32M
        for (int x = 0; x < w; x++) {
739
4.20M
            const int tmpdiff = tmp1[x] - tmp2[x];
740
4.20M
            const int m = imin(38 + ((abs(tmpdiff) + mask_rnd) >> mask_sh), 64);
741
4.20M
            dst[x] = iclip_pixel((tmpdiff * m + tmp2[x] * 64 + rnd) >> sh);
742
743
4.20M
            if (ss_hor) {
744
2.21M
                x++;
745
746
2.21M
                const int tmpdiff = tmp1[x] - tmp2[x];
747
2.21M
                const int n = imin(38 + ((abs(tmpdiff) + mask_rnd) >> mask_sh), 64);
748
2.21M
                dst[x] = iclip_pixel((tmpdiff * n + tmp2[x] * 64 + rnd) >> sh);
749
750
2.21M
                if (h & ss_ver) {
751
1.13M
                    mask[x >> 1] = (m + n + mask[x >> 1] + 2 - sign) >> 2;
752
1.13M
                } else if (ss_ver) {
753
1.11M
                    mask[x >> 1] = m + n;
754
18.4E
                } else {
755
18.4E
                    mask[x >> 1] = (m + n + 1 - sign) >> 1;
756
18.4E
                }
757
2.21M
            } else {
758
1.98M
                mask[x] = m;
759
1.98M
            }
760
4.20M
        }
761
762
128k
        tmp1 += w;
763
128k
        tmp2 += w;
764
128k
        dst += PXSTRIDE(dst_stride);
765
128k
        if (!ss_ver || (h & 1)) mask += w >> ss_hor;
766
128k
    } while (--h);
767
2.63k
}
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
2.63k
                             const int sign HIGHBD_DECL_SUFFIX) \
774
2.63k
{ \
775
2.63k
    w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver \
776
2.63k
             HIGHBD_TAIL_SUFFIX); \
777
2.63k
}
mc_tmpl.c:w_mask_444_c
Line
Count
Source
773
988
                             const int sign HIGHBD_DECL_SUFFIX) \
774
988
{ \
775
988
    w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver \
776
988
             HIGHBD_TAIL_SUFFIX); \
777
988
}
mc_tmpl.c:w_mask_422_c
Line
Count
Source
773
98
                             const int sign HIGHBD_DECL_SUFFIX) \
774
98
{ \
775
98
    w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver \
776
98
             HIGHBD_TAIL_SUFFIX); \
777
98
}
mc_tmpl.c:w_mask_420_c
Line
Count
Source
773
1.54k
                             const int sign HIGHBD_DECL_SUFFIX) \
774
1.54k
{ \
775
1.54k
    w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver \
776
1.54k
             HIGHBD_TAIL_SUFFIX); \
777
1.54k
}
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
23.9M
    ((F[0] * src[x - 3 * stride] + \
787
23.9M
      F[1] * src[x - 2 * stride] + \
788
23.9M
      F[2] * src[x - 1 * stride] + \
789
23.9M
      F[3] * src[x + 0 * stride] + \
790
23.9M
      F[4] * src[x + 1 * stride] + \
791
23.9M
      F[5] * src[x + 2 * stride] + \
792
23.9M
      F[6] * src[x + 3 * stride] + \
793
23.9M
      F[7] * src[x + 4 * stride] + \
794
23.9M
      ((1 << (sh)) >> 1)) >> (sh))
795
796
#define FILTER_WARP_CLIP(src, x, F, stride, sh) \
797
6.25M
    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
109k
{
804
109k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
805
109k
    int16_t mid[15 * 8], *mid_ptr = mid;
806
807
109k
    src -= 3 * PXSTRIDE(src_stride);
808
1.70M
    for (int y = 0; y < 15; y++, mx += abcd[1]) {
809
14.2M
        for (int x = 0, tmx = mx; x < 8; x++, tmx += abcd[0]) {
810
12.6M
            const int8_t *const filter =
811
12.6M
                dav1d_mc_warp_filter[64 + ((tmx + 512) >> 10)];
812
813
12.6M
            mid_ptr[x] = FILTER_WARP_RND(src, x, filter, 1,
814
12.6M
                                         7 - intermediate_bits);
815
12.6M
        }
816
1.60M
        src += PXSTRIDE(src_stride);
817
1.60M
        mid_ptr += 8;
818
1.60M
    }
819
820
109k
    mid_ptr = &mid[3 * 8];
821
896k
    for (int y = 0; y < 8; y++, my += abcd[3]) {
822
7.03M
        for (int x = 0, tmy = my; x < 8; x++, tmy += abcd[2]) {
823
6.25M
            const int8_t *const filter =
824
6.25M
                dav1d_mc_warp_filter[64 + ((tmy + 512) >> 10)];
825
826
6.25M
            dst[x] = FILTER_WARP_CLIP(mid_ptr, x, filter, 8,
827
6.25M
                                      7 + intermediate_bits);
828
6.25M
        }
829
786k
        mid_ptr += 8;
830
786k
        dst += PXSTRIDE(dst_stride);
831
786k
    }
832
109k
}
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
27.1k
{
839
27.1k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
840
27.1k
    int16_t mid[15 * 8], *mid_ptr = mid;
841
842
27.1k
    src -= 3 * PXSTRIDE(src_stride);
843
433k
    for (int y = 0; y < 15; y++, mx += abcd[1]) {
844
3.65M
        for (int x = 0, tmx = mx; x < 8; x++, tmx += abcd[0]) {
845
3.25M
            const int8_t *const filter =
846
3.25M
                dav1d_mc_warp_filter[64 + ((tmx + 512) >> 10)];
847
848
3.25M
            mid_ptr[x] = FILTER_WARP_RND(src, x, filter, 1,
849
3.25M
                                         7 - intermediate_bits);
850
3.25M
        }
851
406k
        src += PXSTRIDE(src_stride);
852
406k
        mid_ptr += 8;
853
406k
    }
854
855
27.1k
    mid_ptr = &mid[3 * 8];
856
243k
    for (int y = 0; y < 8; y++, my += abcd[3]) {
857
1.95M
        for (int x = 0, tmy = my; x < 8; x++, tmy += abcd[2]) {
858
1.73M
            const int8_t *const filter =
859
1.73M
                dav1d_mc_warp_filter[64 + ((tmy + 512) >> 10)];
860
861
1.73M
            tmp[x] = FILTER_WARP_RND(mid_ptr, x, filter, 8, 7) - PREP_BIAS;
862
1.73M
        }
863
216k
        mid_ptr += 8;
864
216k
        tmp += tmp_stride;
865
216k
    }
866
27.1k
}
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
632k
{
874
    // find offset in reference of visible block to copy
875
632k
    ref += iclip((int) y, 0, (int) ih - 1) * PXSTRIDE(ref_stride) +
876
632k
           iclip((int) x, 0, (int) iw - 1);
877
878
    // number of pixels to extend (left, right, top, bottom)
879
632k
    const int left_ext = iclip((int) -x, 0, (int) bw - 1);
880
632k
    const int right_ext = iclip((int) (x + bw - iw), 0, (int) bw - 1);
881
632k
    assert(left_ext + right_ext < bw);
882
632k
    const int top_ext = iclip((int) -y, 0, (int) bh - 1);
883
632k
    const int bottom_ext = iclip((int) (y + bh - ih), 0, (int) bh - 1);
884
632k
    assert(top_ext + bottom_ext < bh);
885
886
    // copy visible portion first
887
632k
    pixel *blk = dst + top_ext * PXSTRIDE(dst_stride);
888
632k
    const int center_w = (int) (bw - left_ext - right_ext);
889
632k
    const int center_h = (int) (bh - top_ext - bottom_ext);
890
7.93M
    for (int y = 0; y < center_h; y++) {
891
7.30M
        pixel_copy(blk + left_ext, ref, center_w);
892
        // extend left edge for this line
893
7.30M
        if (left_ext)
894
1.26M
            pixel_set(blk, blk[left_ext], left_ext);
895
        // extend right edge for this line
896
7.30M
        if (right_ext)
897
4.25M
            pixel_set(blk + left_ext + center_w, blk[left_ext + center_w - 1],
898
4.25M
                      right_ext);
899
7.30M
        ref += PXSTRIDE(ref_stride);
900
7.30M
        blk += PXSTRIDE(dst_stride);
901
7.30M
    }
902
903
    // copy top
904
632k
    blk = dst + top_ext * PXSTRIDE(dst_stride);
905
1.97M
    for (int y = 0; y < top_ext; y++) {
906
1.34M
        pixel_copy(dst, blk, bw);
907
1.34M
        dst += PXSTRIDE(dst_stride);
908
1.34M
    }
909
910
    // copy bottom
911
632k
    dst += center_h * PXSTRIDE(dst_stride);
912
4.38M
    for (int y = 0; y < bottom_ext; y++) {
913
3.75M
        pixel_copy(dst, &dst[-PXSTRIDE(dst_stride)], bw);
914
3.75M
        dst += PXSTRIDE(dst_stride);
915
3.75M
    }
916
632k
}
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
99.8k
{
923
2.73M
    do {
924
2.73M
        int mx = mx0, src_x = -1;
925
364M
        for (int x = 0; x < dst_w; x++) {
926
361M
            const int8_t *const F = dav1d_resize_filter[mx >> 8];
927
361M
            dst[x] = iclip_pixel((-(F[0] * src[iclip(src_x - 3, 0, src_w - 1)] +
928
361M
                                    F[1] * src[iclip(src_x - 2, 0, src_w - 1)] +
929
361M
                                    F[2] * src[iclip(src_x - 1, 0, src_w - 1)] +
930
361M
                                    F[3] * src[iclip(src_x + 0, 0, src_w - 1)] +
931
361M
                                    F[4] * src[iclip(src_x + 1, 0, src_w - 1)] +
932
361M
                                    F[5] * src[iclip(src_x + 2, 0, src_w - 1)] +
933
361M
                                    F[6] * src[iclip(src_x + 3, 0, src_w - 1)] +
934
361M
                                    F[7] * src[iclip(src_x + 4, 0, src_w - 1)]) +
935
361M
                                  64) >> 7);
936
361M
            mx += dx;
937
361M
            src_x += mx >> 14;
938
361M
            mx &= 0x3fff;
939
361M
        }
940
941
2.73M
        dst += PXSTRIDE(dst_stride);
942
2.73M
        src += PXSTRIDE(src_stride);
943
2.73M
    } while (--h);
944
99.8k
}
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
17.0k
COLD void bitfn(dav1d_mc_dsp_init)(Dav1dMCDSPContext *const c) {
961
170k
#define init_mc_fns(type, name) do { \
962
170k
    c->mc        [type] = put_##name##_c; \
963
170k
    c->mc_scaled [type] = put_##name##_scaled_c; \
964
170k
    c->mct       [type] = prep_##name##_c; \
965
170k
    c->mct_scaled[type] = prep_##name##_scaled_c; \
966
170k
} while (0)
967
968
17.0k
    init_mc_fns(FILTER_2D_8TAP_REGULAR,        8tap_regular);
969
17.0k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SMOOTH, 8tap_regular_smooth);
970
17.0k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SHARP,  8tap_regular_sharp);
971
17.0k
    init_mc_fns(FILTER_2D_8TAP_SHARP_REGULAR,  8tap_sharp_regular);
972
17.0k
    init_mc_fns(FILTER_2D_8TAP_SHARP_SMOOTH,   8tap_sharp_smooth);
973
17.0k
    init_mc_fns(FILTER_2D_8TAP_SHARP,          8tap_sharp);
974
17.0k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_REGULAR, 8tap_smooth_regular);
975
17.0k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH,         8tap_smooth);
976
17.0k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_SHARP,   8tap_smooth_sharp);
977
17.0k
    init_mc_fns(FILTER_2D_BILINEAR,            bilin);
978
979
17.0k
    c->avg      = avg_c;
980
17.0k
    c->w_avg    = w_avg_c;
981
17.0k
    c->mask     = mask_c;
982
17.0k
    c->blend    = blend_c;
983
17.0k
    c->blend_v  = blend_v_c;
984
17.0k
    c->blend_h  = blend_h_c;
985
17.0k
    c->w_mask[0] = w_mask_444_c;
986
17.0k
    c->w_mask[1] = w_mask_422_c;
987
17.0k
    c->w_mask[2] = w_mask_420_c;
988
17.0k
    c->warp8x8  = warp_affine_8x8_c;
989
17.0k
    c->warp8x8t = warp_affine_8x8t_c;
990
17.0k
    c->emu_edge = emu_edge_c;
991
17.0k
    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
17.0k
}
dav1d_mc_dsp_init_8bpc
Line
Count
Source
960
8.07k
COLD void bitfn(dav1d_mc_dsp_init)(Dav1dMCDSPContext *const c) {
961
8.07k
#define init_mc_fns(type, name) do { \
962
8.07k
    c->mc        [type] = put_##name##_c; \
963
8.07k
    c->mc_scaled [type] = put_##name##_scaled_c; \
964
8.07k
    c->mct       [type] = prep_##name##_c; \
965
8.07k
    c->mct_scaled[type] = prep_##name##_scaled_c; \
966
8.07k
} while (0)
967
968
8.07k
    init_mc_fns(FILTER_2D_8TAP_REGULAR,        8tap_regular);
969
8.07k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SMOOTH, 8tap_regular_smooth);
970
8.07k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SHARP,  8tap_regular_sharp);
971
8.07k
    init_mc_fns(FILTER_2D_8TAP_SHARP_REGULAR,  8tap_sharp_regular);
972
8.07k
    init_mc_fns(FILTER_2D_8TAP_SHARP_SMOOTH,   8tap_sharp_smooth);
973
8.07k
    init_mc_fns(FILTER_2D_8TAP_SHARP,          8tap_sharp);
974
8.07k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_REGULAR, 8tap_smooth_regular);
975
8.07k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH,         8tap_smooth);
976
8.07k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_SHARP,   8tap_smooth_sharp);
977
8.07k
    init_mc_fns(FILTER_2D_BILINEAR,            bilin);
978
979
8.07k
    c->avg      = avg_c;
980
8.07k
    c->w_avg    = w_avg_c;
981
8.07k
    c->mask     = mask_c;
982
8.07k
    c->blend    = blend_c;
983
8.07k
    c->blend_v  = blend_v_c;
984
8.07k
    c->blend_h  = blend_h_c;
985
8.07k
    c->w_mask[0] = w_mask_444_c;
986
8.07k
    c->w_mask[1] = w_mask_422_c;
987
8.07k
    c->w_mask[2] = w_mask_420_c;
988
8.07k
    c->warp8x8  = warp_affine_8x8_c;
989
8.07k
    c->warp8x8t = warp_affine_8x8t_c;
990
8.07k
    c->emu_edge = emu_edge_c;
991
8.07k
    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
8.07k
}
dav1d_mc_dsp_init_16bpc
Line
Count
Source
960
8.94k
COLD void bitfn(dav1d_mc_dsp_init)(Dav1dMCDSPContext *const c) {
961
8.94k
#define init_mc_fns(type, name) do { \
962
8.94k
    c->mc        [type] = put_##name##_c; \
963
8.94k
    c->mc_scaled [type] = put_##name##_scaled_c; \
964
8.94k
    c->mct       [type] = prep_##name##_c; \
965
8.94k
    c->mct_scaled[type] = prep_##name##_scaled_c; \
966
8.94k
} while (0)
967
968
8.94k
    init_mc_fns(FILTER_2D_8TAP_REGULAR,        8tap_regular);
969
8.94k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SMOOTH, 8tap_regular_smooth);
970
8.94k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SHARP,  8tap_regular_sharp);
971
8.94k
    init_mc_fns(FILTER_2D_8TAP_SHARP_REGULAR,  8tap_sharp_regular);
972
8.94k
    init_mc_fns(FILTER_2D_8TAP_SHARP_SMOOTH,   8tap_sharp_smooth);
973
8.94k
    init_mc_fns(FILTER_2D_8TAP_SHARP,          8tap_sharp);
974
8.94k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_REGULAR, 8tap_smooth_regular);
975
8.94k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH,         8tap_smooth);
976
8.94k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_SHARP,   8tap_smooth_sharp);
977
8.94k
    init_mc_fns(FILTER_2D_BILINEAR,            bilin);
978
979
8.94k
    c->avg      = avg_c;
980
8.94k
    c->w_avg    = w_avg_c;
981
8.94k
    c->mask     = mask_c;
982
8.94k
    c->blend    = blend_c;
983
8.94k
    c->blend_v  = blend_v_c;
984
8.94k
    c->blend_h  = blend_h_c;
985
8.94k
    c->w_mask[0] = w_mask_444_c;
986
8.94k
    c->w_mask[1] = w_mask_422_c;
987
8.94k
    c->w_mask[2] = w_mask_420_c;
988
8.94k
    c->warp8x8  = warp_affine_8x8_c;
989
8.94k
    c->warp8x8t = warp_affine_8x8t_c;
990
8.94k
    c->emu_edge = emu_edge_c;
991
8.94k
    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
8.94k
}