Coverage Report

Created: 2026-07-30 06:22

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.06M
#define get_intermediate_bits(bitdepth_max) 4
41
// Output in interval [-5132, 9212], fits in int16_t as is
42
71.5M
#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
326k
{
55
4.93M
    do {
56
4.93M
        pixel_copy(dst, src, w);
57
58
4.93M
        dst += dst_stride;
59
4.93M
        src += src_stride;
60
4.93M
    } while (--h);
61
326k
}
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
62.9k
{
67
62.9k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
68
1.08M
    do {
69
25.9M
        for (int x = 0; x < w; x++)
70
24.8M
            tmp[x] = (src[x] << intermediate_bits) - PREP_BIAS;
71
72
1.08M
        tmp += w;
73
1.08M
        src += src_stride;
74
1.08M
    } while (--h);
75
62.9k
}
76
77
#define FILTER_8TAP(src, x, F, stride) \
78
136M
    (F[0] * src[x + -3 * stride] + \
79
136M
     F[1] * src[x + -2 * stride] + \
80
136M
     F[2] * src[x + -1 * stride] + \
81
136M
     F[3] * src[x + +0 * stride] + \
82
136M
     F[4] * src[x + +1 * stride] + \
83
136M
     F[5] * src[x + +2 * stride] + \
84
136M
     F[6] * src[x + +3 * stride] + \
85
136M
     F[7] * src[x + +4 * stride])
86
87
#define FILTER_8TAP2(src, x, F) \
88
64.5M
    (F[0] * src[0][x] + \
89
64.5M
     F[1] * src[1][x] + \
90
64.5M
     F[2] * src[2][x] + \
91
64.5M
     F[3] * src[3][x] + \
92
64.5M
     F[4] * src[4][x] + \
93
64.5M
     F[5] * src[5][x] + \
94
64.5M
     F[6] * src[6][x] + \
95
64.5M
     F[7] * src[7][x])
96
97
#define DAV1D_FILTER_8TAP_RND(src, x, F, stride, sh) \
98
133M
    ((FILTER_8TAP(src, x, F, stride) + ((1 << (sh)) >> 1)) >> (sh))
99
100
#define DAV1D_FILTER_8TAP_RND2(src, x, F, stride, rnd, sh) \
101
2.77M
    ((FILTER_8TAP(src, x, F, stride) + (rnd)) >> (sh))
102
103
#define DAV1D_FILTER_8TAP_RND3(src, x, F, sh) \
104
64.5M
    ((FILTER_8TAP2(src, x, F) + ((1 << (sh)) >> 1)) >> (sh))
105
106
#define DAV1D_FILTER_8TAP_CLIP(src, x, F, stride, sh) \
107
7.14M
    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
2.77M
    iclip_pixel(DAV1D_FILTER_8TAP_RND2(src, x, F, stride, rnd, sh))
111
112
#define DAV1D_FILTER_8TAP_CLIP3(src, x, F, sh) \
113
41.0M
    iclip_pixel(DAV1D_FILTER_8TAP_RND3(src, x, F, sh))
114
115
#define GET_H_FILTER(mx) \
116
114M
    const int8_t *const fh = !(mx) ? NULL : w > 4 ? \
117
106M
        dav1d_mc_subpel_filters[filter_type & 3][(mx) - 1] : \
118
106M
        dav1d_mc_subpel_filters[3 + (filter_type & 1)][(mx) - 1]
119
120
#define GET_V_FILTER(my) \
121
3.39M
    const int8_t *const fv = !(my) ? NULL : h > 4 ? \
122
2.37M
        dav1d_mc_subpel_filters[filter_type >> 2][(my) - 1] : \
123
2.37M
        dav1d_mc_subpel_filters[3 + ((filter_type >> 2) & 1)][(my) - 1]
124
125
#define GET_FILTERS() \
126
358k
    GET_H_FILTER(mx); \
127
358k
    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
255k
{
135
255k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
136
255k
    const int intermediate_rnd = 32 + ((1 << (6 - intermediate_bits)) >> 1);
137
138
255k
    GET_FILTERS();
139
255k
    dst_stride = PXSTRIDE(dst_stride);
140
255k
    src_stride = PXSTRIDE(src_stride);
141
142
255k
    if (fh) {
143
85.2k
        if (fv) {
144
47.2k
            int tmp_h = h + 7;
145
47.2k
            int16_t mid[128 * 135], *mid_ptr = mid;
146
147
47.2k
            src -= src_stride * 3;
148
672k
            do {
149
7.86M
                for (int x = 0; x < w; x++)
150
7.19M
                    mid_ptr[x] = DAV1D_FILTER_8TAP_RND(src, x, fh, 1,
151
672k
                                                       6 - intermediate_bits);
152
153
672k
                mid_ptr += 128;
154
672k
                src += src_stride;
155
672k
            } while (--tmp_h);
156
157
47.2k
            mid_ptr = mid + 128 * 3;
158
342k
            do {
159
5.14M
                for (int x = 0; x < w; x++)
160
4.80M
                    dst[x] = DAV1D_FILTER_8TAP_CLIP(mid_ptr, x, fv, 128,
161
342k
                                                    6 + intermediate_bits);
162
163
342k
                mid_ptr += 128;
164
342k
                dst += dst_stride;
165
342k
            } while (--h);
166
47.2k
        } else {
167
266k
            do {
168
3.04M
                for (int x = 0; x < w; x++) {
169
2.77M
                    dst[x] = DAV1D_FILTER_8TAP_CLIP2(src, x, fh, 1,
170
2.77M
                                                     intermediate_rnd, 6);
171
2.77M
                }
172
173
266k
                dst += dst_stride;
174
266k
                src += src_stride;
175
266k
            } while (--h);
176
37.9k
        }
177
170k
    } else if (fv) {
178
186k
        do {
179
2.52M
            for (int x = 0; x < w; x++)
180
2.33M
                dst[x] = DAV1D_FILTER_8TAP_CLIP(src, x, fv, src_stride, 6);
181
182
186k
            dst += dst_stride;
183
186k
            src += src_stride;
184
186k
        } while (--h);
185
24.3k
    } else
186
146k
        put_c(dst, dst_stride, src, src_stride, w, h);
187
255k
}
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
181k
{
196
181k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
197
181k
    const int intermediate_rnd = (1 << intermediate_bits) >> 1;
198
181k
    int16_t mid[128 * 8];
199
181k
    int16_t *mid_ptrs[8];
200
181k
    int in_y = -8;
201
181k
    src_stride = PXSTRIDE(src_stride);
202
203
1.63M
    for (int i = 0; i < 8; i++)
204
1.45M
        mid_ptrs[i] = &mid[128 * i];
205
206
181k
    src -= src_stride * 3;
207
208
2.17M
    for (int y = 0; y < h; y++) {
209
1.99M
        int x;
210
1.99M
        int src_y = my >> 10;
211
1.99M
        GET_V_FILTER((my & 0x3ff) >> 6);
212
213
5.21M
        while (in_y < src_y) {
214
3.22M
            int imx = mx, ioff = 0;
215
3.22M
            int16_t *mid_ptr = mid_ptrs[0];
216
217
25.8M
            for (int i = 0; i < 7; i++)
218
22.6M
                mid_ptrs[i] = mid_ptrs[i + 1];
219
3.22M
            mid_ptrs[7] = mid_ptr;
220
221
77.4M
            for (x = 0; x < w; x++) {
222
74.1M
                GET_H_FILTER(imx >> 6);
223
74.1M
                mid_ptr[x] = fh ? DAV1D_FILTER_8TAP_RND(src, ioff, fh, 1,
224
74.1M
                                                        6 - intermediate_bits) :
225
74.1M
                                  src[ioff] << intermediate_bits;
226
74.1M
                imx += dx;
227
74.1M
                ioff += imx >> 10;
228
74.1M
                imx &= 0x3ff;
229
74.1M
            }
230
231
3.22M
            src += src_stride;
232
3.22M
            in_y++;
233
3.22M
        }
234
235
53.7M
        for (x = 0; x < w; x++)
236
51.7M
            dst[x] = fv ? DAV1D_FILTER_8TAP_CLIP3(mid_ptrs, x, fv,
237
51.7M
                                                  6 + intermediate_bits) :
238
51.7M
                          iclip_pixel((mid_ptrs[3][x] + intermediate_rnd) >>
239
10.7M
                                              intermediate_bits);
240
241
1.99M
        my += dy;
242
1.99M
        dst += PXSTRIDE(dst_stride);
243
1.99M
    }
244
181k
}
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
102k
{
251
102k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
252
102k
    GET_FILTERS();
253
102k
    src_stride = PXSTRIDE(src_stride);
254
255
102k
    if (fh) {
256
35.7k
        if (fv) {
257
24.0k
            int tmp_h = h + 7;
258
24.0k
            int16_t mid[128 * 135], *mid_ptr = mid;
259
260
24.0k
            src -= src_stride * 3;
261
418k
            do {
262
6.15M
                for (int x = 0; x < w; x++)
263
5.73M
                    mid_ptr[x] = DAV1D_FILTER_8TAP_RND(src, x, fh, 1,
264
418k
                                                       6 - intermediate_bits);
265
266
418k
                mid_ptr += 128;
267
418k
                src += src_stride;
268
418k
            } while (--tmp_h);
269
270
24.0k
            mid_ptr = mid + 128 * 3;
271
251k
            do {
272
4.41M
                for (int x = 0; x < w; x++) {
273
4.16M
                    int t = DAV1D_FILTER_8TAP_RND(mid_ptr, x, fv, 128, 6) -
274
4.16M
                                  PREP_BIAS;
275
4.16M
                    assert(t >= INT16_MIN && t <= INT16_MAX);
276
4.16M
                    tmp[x] = t;
277
4.16M
                }
278
279
251k
                mid_ptr += 128;
280
251k
                tmp += w;
281
251k
            } while (--h);
282
24.0k
        } else {
283
121k
            do {
284
2.12M
                for (int x = 0; x < w; x++)
285
2.00M
                    tmp[x] = DAV1D_FILTER_8TAP_RND(src, x, fh, 1,
286
2.00M
                                                   6 - intermediate_bits) -
287
2.00M
                             PREP_BIAS;
288
289
121k
                tmp += w;
290
121k
                src += src_stride;
291
121k
            } while (--h);
292
11.7k
        }
293
66.7k
    } else if (fv) {
294
90.7k
        do {
295
1.56M
            for (int x = 0; x < w; x++)
296
1.47M
                tmp[x] = DAV1D_FILTER_8TAP_RND(src, x, fv, src_stride,
297
1.47M
                                               6 - intermediate_bits) -
298
1.47M
                         PREP_BIAS;
299
300
90.7k
            tmp += w;
301
90.7k
            src += src_stride;
302
90.7k
        } while (--h);
303
6.46k
    } else
304
60.2k
        prep_c(tmp, src, src_stride, w, h HIGHBD_TAIL_SUFFIX);
305
102k
}
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
68.4k
{
313
68.4k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
314
68.4k
    int16_t mid[128 * 8];
315
68.4k
    int16_t *mid_ptrs[8];
316
68.4k
    int in_y = -8;
317
68.4k
    src_stride = PXSTRIDE(src_stride);
318
319
615k
    for (int i = 0; i < 8; i++)
320
547k
        mid_ptrs[i] = &mid[128 * i];
321
322
68.4k
    src -= src_stride * 3;
323
324
1.11M
    for (int y = 0; y < h; y++) {
325
1.04M
        int x;
326
1.04M
        int src_y = my >> 10;
327
1.04M
        GET_V_FILTER((my & 0x3ff) >> 6);
328
329
2.48M
        while (in_y < src_y) {
330
1.43M
            int imx = mx, ioff = 0;
331
1.43M
            int16_t *mid_ptr = mid_ptrs[0];
332
333
11.4M
            for (int i = 0; i < 7; i++)
334
10.0M
                mid_ptrs[i] = mid_ptrs[i + 1];
335
1.43M
            mid_ptrs[7] = mid_ptr;
336
337
41.6M
            for (x = 0; x < w; x++) {
338
40.1M
                GET_H_FILTER(imx >> 6);
339
40.1M
                mid_ptr[x] = fh ? DAV1D_FILTER_8TAP_RND(src, ioff, fh, 1,
340
40.1M
                                                        6 - intermediate_bits) :
341
40.1M
                                  src[ioff] << intermediate_bits;
342
40.1M
                imx += dx;
343
40.1M
                ioff += imx >> 10;
344
40.1M
                imx &= 0x3ff;
345
40.1M
            }
346
347
1.43M
            src += src_stride;
348
1.43M
            in_y++;
349
1.43M
        }
350
351
34.8M
        for (x = 0; x < w; x++)
352
33.8M
            tmp[x] = (fv ? DAV1D_FILTER_8TAP_RND3(mid_ptrs, x, fv, 6)
353
33.8M
                         : mid_ptrs[3][x]) - PREP_BIAS;
354
355
1.04M
        my += dy;
356
1.04M
        tmp += w;
357
1.04M
    }
358
68.4k
}
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
255k
                                HIGHBD_DECL_SUFFIX) \
368
255k
{ \
369
255k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
255k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
255k
} \
mc_tmpl.c:put_8tap_regular_c
Line
Count
Source
367
108k
                                HIGHBD_DECL_SUFFIX) \
368
108k
{ \
369
108k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
108k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
108k
} \
mc_tmpl.c:put_8tap_regular_smooth_c
Line
Count
Source
367
5.98k
                                HIGHBD_DECL_SUFFIX) \
368
5.98k
{ \
369
5.98k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
5.98k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
5.98k
} \
mc_tmpl.c:put_8tap_regular_sharp_c
Line
Count
Source
367
865
                                HIGHBD_DECL_SUFFIX) \
368
865
{ \
369
865
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
865
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
865
} \
mc_tmpl.c:put_8tap_sharp_regular_c
Line
Count
Source
367
1.33k
                                HIGHBD_DECL_SUFFIX) \
368
1.33k
{ \
369
1.33k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
1.33k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
1.33k
} \
mc_tmpl.c:put_8tap_sharp_smooth_c
Line
Count
Source
367
521
                                HIGHBD_DECL_SUFFIX) \
368
521
{ \
369
521
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
521
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
521
} \
mc_tmpl.c:put_8tap_sharp_c
Line
Count
Source
367
19.0k
                                HIGHBD_DECL_SUFFIX) \
368
19.0k
{ \
369
19.0k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
19.0k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
19.0k
} \
mc_tmpl.c:put_8tap_smooth_regular_c
Line
Count
Source
367
9.79k
                                HIGHBD_DECL_SUFFIX) \
368
9.79k
{ \
369
9.79k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
9.79k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
9.79k
} \
mc_tmpl.c:put_8tap_smooth_c
Line
Count
Source
367
109k
                                HIGHBD_DECL_SUFFIX) \
368
109k
{ \
369
109k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
109k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
109k
} \
mc_tmpl.c:put_8tap_smooth_sharp_c
Line
Count
Source
367
173
                                HIGHBD_DECL_SUFFIX) \
368
173
{ \
369
173
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
173
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
173
} \
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
181k
                                       HIGHBD_DECL_SUFFIX) \
380
181k
{ \
381
181k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
181k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
181k
} \
mc_tmpl.c:put_8tap_regular_scaled_c
Line
Count
Source
379
123k
                                       HIGHBD_DECL_SUFFIX) \
380
123k
{ \
381
123k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
123k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
123k
} \
mc_tmpl.c:put_8tap_regular_smooth_scaled_c
Line
Count
Source
379
5.27k
                                       HIGHBD_DECL_SUFFIX) \
380
5.27k
{ \
381
5.27k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
5.27k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
5.27k
} \
mc_tmpl.c:put_8tap_regular_sharp_scaled_c
Line
Count
Source
379
881
                                       HIGHBD_DECL_SUFFIX) \
380
881
{ \
381
881
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
881
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
881
} \
mc_tmpl.c:put_8tap_sharp_regular_scaled_c
Line
Count
Source
379
1.26k
                                       HIGHBD_DECL_SUFFIX) \
380
1.26k
{ \
381
1.26k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
1.26k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
1.26k
} \
mc_tmpl.c:put_8tap_sharp_smooth_scaled_c
Line
Count
Source
379
818
                                       HIGHBD_DECL_SUFFIX) \
380
818
{ \
381
818
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
818
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
818
} \
mc_tmpl.c:put_8tap_sharp_scaled_c
Line
Count
Source
379
14.1k
                                       HIGHBD_DECL_SUFFIX) \
380
14.1k
{ \
381
14.1k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
14.1k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
14.1k
} \
mc_tmpl.c:put_8tap_smooth_regular_scaled_c
Line
Count
Source
379
6.49k
                                       HIGHBD_DECL_SUFFIX) \
380
6.49k
{ \
381
6.49k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
6.49k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
6.49k
} \
mc_tmpl.c:put_8tap_smooth_scaled_c
Line
Count
Source
379
28.3k
                                       HIGHBD_DECL_SUFFIX) \
380
28.3k
{ \
381
28.3k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
28.3k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
28.3k
} \
mc_tmpl.c:put_8tap_smooth_sharp_scaled_c
Line
Count
Source
379
618
                                       HIGHBD_DECL_SUFFIX) \
380
618
{ \
381
618
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
618
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
618
} \
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
102k
                                 HIGHBD_DECL_SUFFIX) \
390
102k
{ \
391
102k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
102k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
102k
} \
mc_tmpl.c:prep_8tap_regular_c
Line
Count
Source
389
29.3k
                                 HIGHBD_DECL_SUFFIX) \
390
29.3k
{ \
391
29.3k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
29.3k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
29.3k
} \
mc_tmpl.c:prep_8tap_regular_smooth_c
Line
Count
Source
389
1.29k
                                 HIGHBD_DECL_SUFFIX) \
390
1.29k
{ \
391
1.29k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
1.29k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
1.29k
} \
mc_tmpl.c:prep_8tap_regular_sharp_c
Line
Count
Source
389
2.89k
                                 HIGHBD_DECL_SUFFIX) \
390
2.89k
{ \
391
2.89k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
2.89k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
2.89k
} \
mc_tmpl.c:prep_8tap_sharp_regular_c
Line
Count
Source
389
3.27k
                                 HIGHBD_DECL_SUFFIX) \
390
3.27k
{ \
391
3.27k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
3.27k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
3.27k
} \
mc_tmpl.c:prep_8tap_sharp_smooth_c
Line
Count
Source
389
609
                                 HIGHBD_DECL_SUFFIX) \
390
609
{ \
391
609
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
609
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
609
} \
mc_tmpl.c:prep_8tap_sharp_c
Line
Count
Source
389
16.5k
                                 HIGHBD_DECL_SUFFIX) \
390
16.5k
{ \
391
16.5k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
16.5k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
16.5k
} \
mc_tmpl.c:prep_8tap_smooth_regular_c
Line
Count
Source
389
1.41k
                                 HIGHBD_DECL_SUFFIX) \
390
1.41k
{ \
391
1.41k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
1.41k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
1.41k
} \
mc_tmpl.c:prep_8tap_smooth_c
Line
Count
Source
389
46.2k
                                 HIGHBD_DECL_SUFFIX) \
390
46.2k
{ \
391
46.2k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
46.2k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
46.2k
} \
mc_tmpl.c:prep_8tap_smooth_sharp_c
Line
Count
Source
389
860
                                 HIGHBD_DECL_SUFFIX) \
390
860
{ \
391
860
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
860
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
860
} \
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
68.4k
                                        HIGHBD_DECL_SUFFIX) \
401
68.4k
{ \
402
68.4k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
68.4k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
68.4k
}
mc_tmpl.c:prep_8tap_regular_scaled_c
Line
Count
Source
400
12.6k
                                        HIGHBD_DECL_SUFFIX) \
401
12.6k
{ \
402
12.6k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
12.6k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
12.6k
}
mc_tmpl.c:prep_8tap_regular_smooth_scaled_c
Line
Count
Source
400
1.18k
                                        HIGHBD_DECL_SUFFIX) \
401
1.18k
{ \
402
1.18k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
1.18k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
1.18k
}
mc_tmpl.c:prep_8tap_regular_sharp_scaled_c
Line
Count
Source
400
2.01k
                                        HIGHBD_DECL_SUFFIX) \
401
2.01k
{ \
402
2.01k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
2.01k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
2.01k
}
mc_tmpl.c:prep_8tap_sharp_regular_scaled_c
Line
Count
Source
400
2.76k
                                        HIGHBD_DECL_SUFFIX) \
401
2.76k
{ \
402
2.76k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
2.76k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
2.76k
}
mc_tmpl.c:prep_8tap_sharp_smooth_scaled_c
Line
Count
Source
400
1.02k
                                        HIGHBD_DECL_SUFFIX) \
401
1.02k
{ \
402
1.02k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
1.02k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
1.02k
}
mc_tmpl.c:prep_8tap_sharp_scaled_c
Line
Count
Source
400
3.17k
                                        HIGHBD_DECL_SUFFIX) \
401
3.17k
{ \
402
3.17k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
3.17k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
3.17k
}
mc_tmpl.c:prep_8tap_smooth_regular_scaled_c
Line
Count
Source
400
2.65k
                                        HIGHBD_DECL_SUFFIX) \
401
2.65k
{ \
402
2.65k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
2.65k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
2.65k
}
mc_tmpl.c:prep_8tap_smooth_scaled_c
Line
Count
Source
400
41.8k
                                        HIGHBD_DECL_SUFFIX) \
401
41.8k
{ \
402
41.8k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
41.8k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
41.8k
}
mc_tmpl.c:prep_8tap_smooth_sharp_scaled_c
Line
Count
Source
400
1.09k
                                        HIGHBD_DECL_SUFFIX) \
401
1.09k
{ \
402
1.09k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
1.09k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
1.09k
}
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
16.8M
    (16 * src[x] + ((mxy) * (src[x + stride] - src[x])))
418
419
#define FILTER_BILIN_RND(src, x, mxy, stride, sh) \
420
16.8M
    ((FILTER_BILIN(src, x, mxy, stride) + ((1 << (sh)) >> 1)) >> (sh))
421
422
#define FILTER_BILIN_CLIP(src, x, mxy, stride, sh) \
423
1.99M
    iclip_pixel(FILTER_BILIN_RND(src, x, mxy, stride, sh))
424
425
#define FILTER_BILIN2(src1, src2, x, mxy) \
426
7.72M
    (16 * src1[x] + ((mxy) * (src2[x] - src1[x])))
427
428
#define FILTER_BILIN_RND2(src1, src2, x, mxy, sh) \
429
7.72M
    ((FILTER_BILIN2(src1, src2, x, mxy) + ((1 << (sh)) >> 1)) >> (sh))
430
431
#define FILTER_BILIN_CLIP2(src1, src2, x, mxy, sh) \
432
6.55M
    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
192k
{
439
192k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
440
192k
    const int intermediate_rnd = (1 << intermediate_bits) >> 1;
441
192k
    dst_stride = PXSTRIDE(dst_stride);
442
192k
    src_stride = PXSTRIDE(src_stride);
443
444
192k
    if (mx) {
445
10.1k
        if (my) {
446
5.90k
            int16_t mid[128 * 129], *mid_ptr = mid;
447
5.90k
            int tmp_h = h + 1;
448
449
55.9k
            do {
450
1.15M
                for (int x = 0; x < w; x++)
451
1.10M
                    mid_ptr[x] = FILTER_BILIN_RND(src, x, mx, 1,
452
55.9k
                                                  4 - intermediate_bits);
453
454
55.9k
                mid_ptr += 128;
455
55.9k
                src += src_stride;
456
55.9k
            } while (--tmp_h);
457
458
5.90k
            mid_ptr = mid;
459
49.9k
            do {
460
1.10M
                for (int x = 0; x < w; x++)
461
1.05M
                    dst[x] = FILTER_BILIN_CLIP(mid_ptr, x, my, 128,
462
49.9k
                                               4 + intermediate_bits);
463
464
49.9k
                mid_ptr += 128;
465
49.9k
                dst += dst_stride;
466
49.9k
            } while (--h);
467
5.90k
        } else {
468
39.3k
            do {
469
1.02M
                for (int x = 0; x < w; x++) {
470
984k
                    const int px = FILTER_BILIN_RND(src, x, mx, 1,
471
984k
                                                    4 - intermediate_bits);
472
984k
                    dst[x] = iclip_pixel((px + intermediate_rnd) >> intermediate_bits);
473
984k
                }
474
475
39.3k
                dst += dst_stride;
476
39.3k
                src += src_stride;
477
39.3k
            } while (--h);
478
4.20k
        }
479
182k
    } else if (my) {
480
28.1k
        do {
481
968k
            for (int x = 0; x < w; x++)
482
940k
                dst[x] = FILTER_BILIN_CLIP(src, x, my, src_stride, 4);
483
484
28.1k
            dst += dst_stride;
485
28.1k
            src += src_stride;
486
28.1k
        } while (--h);
487
2.23k
    } else
488
179k
        put_c(dst, dst_stride, src, src_stride, w, h);
489
192k
}
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
18.0k
{
497
18.0k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
498
18.0k
    int16_t mid[128 * 2];
499
18.0k
    int in_y = -2;
500
501
342k
    do {
502
342k
        int x;
503
342k
        int y = my >> 10;
504
342k
        int16_t *mid1 = &mid[(y & 1) * 128];
505
342k
        int16_t *mid2 = &mid[((y + 1) & 1) * 128];
506
342k
        int dmy = my & 0x3ff;
507
508
763k
        while (in_y < y) {
509
421k
            int imx = mx, ioff = 0;
510
421k
            int16_t *mid_ptr = &mid[(in_y & 1) * 128];
511
512
8.72M
            for (x = 0; x < w; x++) {
513
8.30M
                mid_ptr[x] = FILTER_BILIN_RND(src, ioff, imx >> 6, 1,
514
8.30M
                                              4 - intermediate_bits);
515
8.30M
                imx += dx;
516
8.30M
                ioff += imx >> 10;
517
8.30M
                imx &= 0x3ff;
518
8.30M
            }
519
520
421k
            src += PXSTRIDE(src_stride);
521
421k
            in_y++;
522
421k
        }
523
524
6.89M
        for (x = 0; x < w; x++)
525
6.55M
            dst[x] = FILTER_BILIN_CLIP2(mid1, mid2, x, dmy >> 6,
526
342k
                                       4 + intermediate_bits);
527
528
342k
        my += dy;
529
342k
        dst += PXSTRIDE(dst_stride);
530
342k
    } while (--h);
531
18.0k
}
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
9.80k
{
538
9.80k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
539
9.80k
    src_stride = PXSTRIDE(src_stride);
540
541
9.80k
    if (mx) {
542
5.82k
        if (my) {
543
3.97k
            int16_t mid[128 * 129], *mid_ptr = mid;
544
3.97k
            int tmp_h = h + 1;
545
546
65.0k
            do {
547
1.09M
                for (int x = 0; x < w; x++)
548
1.03M
                    mid_ptr[x] = FILTER_BILIN_RND(src, x, mx, 1,
549
65.0k
                                                  4 - intermediate_bits);
550
551
65.0k
                mid_ptr += 128;
552
65.0k
                src += src_stride;
553
65.0k
            } while (--tmp_h);
554
555
3.97k
            mid_ptr = mid;
556
62.7k
            do {
557
1.06M
                for (int x = 0; x < w; x++)
558
1.00M
                    tmp[x] = FILTER_BILIN_RND(mid_ptr, x, my, 128, 4) -
559
1.00M
                             PREP_BIAS;
560
561
62.7k
                mid_ptr += 128;
562
62.7k
                tmp += w;
563
62.7k
            } while (--h);
564
3.97k
        } else {
565
36.0k
            do {
566
987k
                for (int x = 0; x < w; x++)
567
951k
                    tmp[x] = FILTER_BILIN_RND(src, x, mx, 1,
568
951k
                                              4 - intermediate_bits) -
569
951k
                             PREP_BIAS;
570
571
36.0k
                tmp += w;
572
36.0k
                src += src_stride;
573
36.0k
            } while (--h);
574
1.85k
        }
575
5.82k
    } else if (my) {
576
20.9k
        do {
577
415k
            for (int x = 0; x < w; x++)
578
394k
                tmp[x] = FILTER_BILIN_RND(src, x, my, src_stride,
579
394k
                                          4 - intermediate_bits) - PREP_BIAS;
580
581
20.9k
            tmp += w;
582
20.9k
            src += src_stride;
583
20.9k
        } while (--h);
584
1.36k
    } else
585
2.61k
        prep_c(tmp, src, src_stride, w, h HIGHBD_TAIL_SUFFIX);
586
9.80k
}
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
1.86k
{
593
1.86k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
594
1.86k
    int16_t mid[128 * 2];
595
1.86k
    int in_y = -2;
596
597
38.1k
    do {
598
38.1k
        int x;
599
38.1k
        int y = my >> 10;
600
38.1k
        int16_t *mid1 = &mid[(y & 1) * 128];
601
38.1k
        int16_t *mid2 = &mid[((y + 1) & 1) * 128];
602
38.1k
        int dmy = my & 0x3ff;
603
604
71.6k
        while (in_y < y) {
605
33.5k
            int imx = mx, ioff = 0;
606
33.5k
            int16_t *mid_ptr = &mid[(in_y & 1) * 128];
607
608
1.07M
            for (x = 0; x < w; x++) {
609
1.04M
                mid_ptr[x] = FILTER_BILIN_RND(src, ioff, imx >> 6, 1,
610
1.04M
                                              4 - intermediate_bits);
611
1.04M
                imx += dx;
612
1.04M
                ioff += imx >> 10;
613
1.04M
                imx &= 0x3ff;
614
1.04M
            }
615
616
33.5k
            src += PXSTRIDE(src_stride);
617
33.5k
            in_y++;
618
33.5k
        }
619
620
1.20M
        for (x = 0; x < w; x++)
621
1.16M
            tmp[x] = FILTER_BILIN_RND2(mid1, mid2, x, dmy >> 6, 4) - PREP_BIAS;
622
623
38.1k
        my += dy;
624
38.1k
        tmp += w;
625
38.1k
    } while (--h);
626
1.86k
}
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
48.3k
{
632
48.3k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
633
48.3k
    const int sh = intermediate_bits + 1;
634
48.3k
    const int rnd = (1 << intermediate_bits) + PREP_BIAS * 2;
635
807k
    do {
636
22.2M
        for (int x = 0; x < w; x++)
637
21.4M
            dst[x] = iclip_pixel((tmp1[x] + tmp2[x] + rnd) >> sh);
638
639
807k
        tmp1 += w;
640
807k
        tmp2 += w;
641
807k
        dst += PXSTRIDE(dst_stride);
642
807k
    } while (--h);
643
48.3k
}
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.0k
{
649
23.0k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
650
23.0k
    const int sh = intermediate_bits + 4;
651
23.0k
    const int rnd = (8 << intermediate_bits) + PREP_BIAS * 16;
652
262k
    do {
653
5.25M
        for (int x = 0; x < w; x++)
654
4.99M
            dst[x] = iclip_pixel((tmp1[x] * weight +
655
4.99M
                                  tmp2[x] * (16 - weight) + rnd) >> sh);
656
657
262k
        tmp1 += w;
658
262k
        tmp2 += w;
659
262k
        dst += PXSTRIDE(dst_stride);
660
262k
    } while (--h);
661
23.0k
}
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
16.7k
{
667
16.7k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
668
16.7k
    const int sh = intermediate_bits + 6;
669
16.7k
    const int rnd = (32 << intermediate_bits) + PREP_BIAS * 64;
670
197k
    do {
671
3.82M
        for (int x = 0; x < w; x++)
672
3.62M
            dst[x] = iclip_pixel((tmp1[x] * mask[x] +
673
3.62M
                                  tmp2[x] * (64 - mask[x]) + rnd) >> sh);
674
675
197k
        tmp1 += w;
676
197k
        tmp2 += w;
677
197k
        mask += w;
678
197k
        dst += PXSTRIDE(dst_stride);
679
197k
    } while (--h);
680
16.7k
}
681
682
7.19M
#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
19.5k
{
686
175k
    do {
687
1.90M
        for (int x = 0; x < w; x++) {
688
1.72M
            dst[x] = blend_px(dst[x], tmp[x], mask[x]);
689
1.72M
        }
690
175k
        dst += PXSTRIDE(dst_stride);
691
175k
        tmp += w;
692
175k
        mask += w;
693
175k
    } while (--h);
694
19.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
41.5k
{
699
41.5k
    const uint8_t *const mask = &dav1d_obmc_masks[w];
700
512k
    do {
701
3.22M
        for (int x = 0; x < (w * 3) >> 2; x++) {
702
2.71M
            dst[x] = blend_px(dst[x], tmp[x], mask[x]);
703
2.71M
        }
704
512k
        dst += PXSTRIDE(dst_stride);
705
512k
        tmp += w;
706
512k
    } while (--h);
707
41.5k
}
708
709
static void blend_h_c(pixel *dst, const ptrdiff_t dst_stride, const pixel *tmp,
710
                      const int w, int h)
711
36.0k
{
712
36.0k
    const uint8_t *mask = &dav1d_obmc_masks[h];
713
36.0k
    h = (h * 3) >> 2;
714
200k
    do {
715
200k
        const int m = *mask++;
716
2.95M
        for (int x = 0; x < w; x++) {
717
2.75M
            dst[x] = blend_px(dst[x], tmp[x], m);
718
2.75M
        }
719
200k
        dst += PXSTRIDE(dst_stride);
720
200k
        tmp += w;
721
200k
    } while (--h);
722
36.0k
}
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
4.81k
{
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
4.81k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
732
4.81k
    const int bitdepth = bitdepth_from_max(bitdepth_max);
733
4.81k
    const int sh = intermediate_bits + 6;
734
4.81k
    const int rnd = (32 << intermediate_bits) + PREP_BIAS * 64;
735
4.81k
    const int mask_sh = bitdepth + intermediate_bits - 4;
736
4.81k
    const int mask_rnd = 1 << (mask_sh - 5);
737
144k
    do {
738
3.48M
        for (int x = 0; x < w; x++) {
739
3.34M
            const int tmpdiff = tmp1[x] - tmp2[x];
740
3.34M
            const int m = imin(38 + ((abs(tmpdiff) + mask_rnd) >> mask_sh), 64);
741
3.34M
            dst[x] = iclip_pixel((tmpdiff * m + tmp2[x] * 64 + rnd) >> sh);
742
743
3.34M
            if (ss_hor) {
744
2.48M
                x++;
745
746
2.48M
                const int tmpdiff = tmp1[x] - tmp2[x];
747
2.48M
                const int n = imin(38 + ((abs(tmpdiff) + mask_rnd) >> mask_sh), 64);
748
2.48M
                dst[x] = iclip_pixel((tmpdiff * n + tmp2[x] * 64 + rnd) >> sh);
749
750
2.48M
                if (h & ss_ver) {
751
1.23M
                    mask[x >> 1] = (m + n + mask[x >> 1] + 2 - sign) >> 2;
752
1.24M
                } else if (ss_ver) {
753
1.23M
                    mask[x >> 1] = m + n;
754
1.23M
                } else {
755
13.5k
                    mask[x >> 1] = (m + n + 1 - sign) >> 1;
756
13.5k
                }
757
2.48M
            } else {
758
864k
                mask[x] = m;
759
864k
            }
760
3.34M
        }
761
762
144k
        tmp1 += w;
763
144k
        tmp2 += w;
764
144k
        dst += PXSTRIDE(dst_stride);
765
144k
        if (!ss_ver || (h & 1)) mask += w >> ss_hor;
766
144k
    } while (--h);
767
4.81k
}
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
4.81k
                             const int sign HIGHBD_DECL_SUFFIX) \
774
4.81k
{ \
775
4.81k
    w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver \
776
4.81k
             HIGHBD_TAIL_SUFFIX); \
777
4.81k
}
mc_tmpl.c:w_mask_444_c
Line
Count
Source
773
631
                             const int sign HIGHBD_DECL_SUFFIX) \
774
631
{ \
775
631
    w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver \
776
631
             HIGHBD_TAIL_SUFFIX); \
777
631
}
mc_tmpl.c:w_mask_422_c
Line
Count
Source
773
123
                             const int sign HIGHBD_DECL_SUFFIX) \
774
123
{ \
775
123
    w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver \
776
123
             HIGHBD_TAIL_SUFFIX); \
777
123
}
mc_tmpl.c:w_mask_420_c
Line
Count
Source
773
4.06k
                             const int sign HIGHBD_DECL_SUFFIX) \
774
4.06k
{ \
775
4.06k
    w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver \
776
4.06k
             HIGHBD_TAIL_SUFFIX); \
777
4.06k
}
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
15.0M
    ((F[0] * src[x - 3 * stride] + \
787
15.0M
      F[1] * src[x - 2 * stride] + \
788
15.0M
      F[2] * src[x - 1 * stride] + \
789
15.0M
      F[3] * src[x + 0 * stride] + \
790
15.0M
      F[4] * src[x + 1 * stride] + \
791
15.0M
      F[5] * src[x + 2 * stride] + \
792
15.0M
      F[6] * src[x + 3 * stride] + \
793
15.0M
      F[7] * src[x + 4 * stride] + \
794
15.0M
      ((1 << (sh)) >> 1)) >> (sh))
795
796
#define FILTER_WARP_CLIP(src, x, F, stride, sh) \
797
3.62M
    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
56.8k
{
804
56.8k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
805
56.8k
    int16_t mid[15 * 8], *mid_ptr = mid;
806
807
56.8k
    src -= 3 * PXSTRIDE(src_stride);
808
907k
    for (int y = 0; y < 15; y++, mx += abcd[1]) {
809
7.64M
        for (int x = 0, tmx = mx; x < 8; x++, tmx += abcd[0]) {
810
6.79M
            const int8_t *const filter =
811
6.79M
                dav1d_mc_warp_filter[64 + ((tmx + 512) >> 10)];
812
813
6.79M
            mid_ptr[x] = FILTER_WARP_RND(src, x, filter, 1,
814
6.79M
                                         7 - intermediate_bits);
815
6.79M
        }
816
850k
        src += PXSTRIDE(src_stride);
817
850k
        mid_ptr += 8;
818
850k
    }
819
820
56.8k
    mid_ptr = &mid[3 * 8];
821
510k
    for (int y = 0; y < 8; y++, my += abcd[3]) {
822
4.07M
        for (int x = 0, tmy = my; x < 8; x++, tmy += abcd[2]) {
823
3.62M
            const int8_t *const filter =
824
3.62M
                dav1d_mc_warp_filter[64 + ((tmy + 512) >> 10)];
825
826
3.62M
            dst[x] = FILTER_WARP_CLIP(mid_ptr, x, filter, 8,
827
3.62M
                                      7 + intermediate_bits);
828
3.62M
        }
829
453k
        mid_ptr += 8;
830
453k
        dst += PXSTRIDE(dst_stride);
831
453k
    }
832
56.8k
}
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
25.2k
{
839
25.2k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
840
25.2k
    int16_t mid[15 * 8], *mid_ptr = mid;
841
842
25.2k
    src -= 3 * PXSTRIDE(src_stride);
843
403k
    for (int y = 0; y < 15; y++, mx += abcd[1]) {
844
3.40M
        for (int x = 0, tmx = mx; x < 8; x++, tmx += abcd[0]) {
845
3.02M
            const int8_t *const filter =
846
3.02M
                dav1d_mc_warp_filter[64 + ((tmx + 512) >> 10)];
847
848
3.02M
            mid_ptr[x] = FILTER_WARP_RND(src, x, filter, 1,
849
3.02M
                                         7 - intermediate_bits);
850
3.02M
        }
851
378k
        src += PXSTRIDE(src_stride);
852
378k
        mid_ptr += 8;
853
378k
    }
854
855
25.2k
    mid_ptr = &mid[3 * 8];
856
227k
    for (int y = 0; y < 8; y++, my += abcd[3]) {
857
1.81M
        for (int x = 0, tmy = my; x < 8; x++, tmy += abcd[2]) {
858
1.61M
            const int8_t *const filter =
859
1.61M
                dav1d_mc_warp_filter[64 + ((tmy + 512) >> 10)];
860
861
1.61M
            tmp[x] = FILTER_WARP_RND(mid_ptr, x, filter, 8, 7) - PREP_BIAS;
862
1.61M
        }
863
201k
        mid_ptr += 8;
864
201k
        tmp += tmp_stride;
865
201k
    }
866
25.2k
}
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
646k
{
874
    // find offset in reference of visible block to copy
875
646k
    ref += iclip((int) y, 0, (int) ih - 1) * PXSTRIDE(ref_stride) +
876
646k
           iclip((int) x, 0, (int) iw - 1);
877
878
    // number of pixels to extend (left, right, top, bottom)
879
646k
    const int left_ext = iclip((int) -x, 0, (int) bw - 1);
880
646k
    const int right_ext = iclip((int) (x + bw - iw), 0, (int) bw - 1);
881
646k
    assert(left_ext + right_ext < bw);
882
646k
    const int top_ext = iclip((int) -y, 0, (int) bh - 1);
883
646k
    const int bottom_ext = iclip((int) (y + bh - ih), 0, (int) bh - 1);
884
646k
    assert(top_ext + bottom_ext < bh);
885
886
    // copy visible portion first
887
646k
    pixel *blk = dst + top_ext * PXSTRIDE(dst_stride);
888
646k
    const int center_w = (int) (bw - left_ext - right_ext);
889
646k
    const int center_h = (int) (bh - top_ext - bottom_ext);
890
8.59M
    for (int y = 0; y < center_h; y++) {
891
7.94M
        pixel_copy(blk + left_ext, ref, center_w);
892
        // extend left edge for this line
893
7.94M
        if (left_ext)
894
2.06M
            pixel_set(blk, blk[left_ext], left_ext);
895
        // extend right edge for this line
896
7.94M
        if (right_ext)
897
5.99M
            pixel_set(blk + left_ext + center_w, blk[left_ext + center_w - 1],
898
5.99M
                      right_ext);
899
7.94M
        ref += PXSTRIDE(ref_stride);
900
7.94M
        blk += PXSTRIDE(dst_stride);
901
7.94M
    }
902
903
    // copy top
904
646k
    blk = dst + top_ext * PXSTRIDE(dst_stride);
905
1.63M
    for (int y = 0; y < top_ext; y++) {
906
993k
        pixel_copy(dst, blk, bw);
907
993k
        dst += PXSTRIDE(dst_stride);
908
993k
    }
909
910
    // copy bottom
911
646k
    dst += center_h * PXSTRIDE(dst_stride);
912
3.55M
    for (int y = 0; y < bottom_ext; y++) {
913
2.90M
        pixel_copy(dst, &dst[-PXSTRIDE(dst_stride)], bw);
914
2.90M
        dst += PXSTRIDE(dst_stride);
915
2.90M
    }
916
646k
}
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
111k
{
923
3.71M
    do {
924
3.71M
        int mx = mx0, src_x = -1;
925
181M
        for (int x = 0; x < dst_w; x++) {
926
178M
            const int8_t *const F = dav1d_resize_filter[mx >> 8];
927
178M
            dst[x] = iclip_pixel((-(F[0] * src[iclip(src_x - 3, 0, src_w - 1)] +
928
178M
                                    F[1] * src[iclip(src_x - 2, 0, src_w - 1)] +
929
178M
                                    F[2] * src[iclip(src_x - 1, 0, src_w - 1)] +
930
178M
                                    F[3] * src[iclip(src_x + 0, 0, src_w - 1)] +
931
178M
                                    F[4] * src[iclip(src_x + 1, 0, src_w - 1)] +
932
178M
                                    F[5] * src[iclip(src_x + 2, 0, src_w - 1)] +
933
178M
                                    F[6] * src[iclip(src_x + 3, 0, src_w - 1)] +
934
178M
                                    F[7] * src[iclip(src_x + 4, 0, src_w - 1)]) +
935
178M
                                  64) >> 7);
936
178M
            mx += dx;
937
178M
            src_x += mx >> 14;
938
178M
            mx &= 0x3fff;
939
178M
        }
940
941
3.71M
        dst += PXSTRIDE(dst_stride);
942
3.71M
        src += PXSTRIDE(src_stride);
943
3.71M
    } while (--h);
944
111k
}
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
26.2k
COLD void bitfn(dav1d_mc_dsp_init)(Dav1dMCDSPContext *const c) {
961
262k
#define init_mc_fns(type, name) do { \
962
262k
    c->mc        [type] = put_##name##_c; \
963
262k
    c->mc_scaled [type] = put_##name##_scaled_c; \
964
262k
    c->mct       [type] = prep_##name##_c; \
965
262k
    c->mct_scaled[type] = prep_##name##_scaled_c; \
966
262k
} while (0)
967
968
26.2k
    init_mc_fns(FILTER_2D_8TAP_REGULAR,        8tap_regular);
969
26.2k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SMOOTH, 8tap_regular_smooth);
970
26.2k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SHARP,  8tap_regular_sharp);
971
26.2k
    init_mc_fns(FILTER_2D_8TAP_SHARP_REGULAR,  8tap_sharp_regular);
972
26.2k
    init_mc_fns(FILTER_2D_8TAP_SHARP_SMOOTH,   8tap_sharp_smooth);
973
26.2k
    init_mc_fns(FILTER_2D_8TAP_SHARP,          8tap_sharp);
974
26.2k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_REGULAR, 8tap_smooth_regular);
975
26.2k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH,         8tap_smooth);
976
26.2k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_SHARP,   8tap_smooth_sharp);
977
26.2k
    init_mc_fns(FILTER_2D_BILINEAR,            bilin);
978
979
26.2k
    c->avg      = avg_c;
980
26.2k
    c->w_avg    = w_avg_c;
981
26.2k
    c->mask     = mask_c;
982
26.2k
    c->blend    = blend_c;
983
26.2k
    c->blend_v  = blend_v_c;
984
26.2k
    c->blend_h  = blend_h_c;
985
26.2k
    c->w_mask[0] = w_mask_444_c;
986
26.2k
    c->w_mask[1] = w_mask_422_c;
987
26.2k
    c->w_mask[2] = w_mask_420_c;
988
26.2k
    c->warp8x8  = warp_affine_8x8_c;
989
26.2k
    c->warp8x8t = warp_affine_8x8t_c;
990
26.2k
    c->emu_edge = emu_edge_c;
991
26.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
26.2k
}
dav1d_mc_dsp_init_8bpc
Line
Count
Source
960
12.0k
COLD void bitfn(dav1d_mc_dsp_init)(Dav1dMCDSPContext *const c) {
961
12.0k
#define init_mc_fns(type, name) do { \
962
12.0k
    c->mc        [type] = put_##name##_c; \
963
12.0k
    c->mc_scaled [type] = put_##name##_scaled_c; \
964
12.0k
    c->mct       [type] = prep_##name##_c; \
965
12.0k
    c->mct_scaled[type] = prep_##name##_scaled_c; \
966
12.0k
} while (0)
967
968
12.0k
    init_mc_fns(FILTER_2D_8TAP_REGULAR,        8tap_regular);
969
12.0k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SMOOTH, 8tap_regular_smooth);
970
12.0k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SHARP,  8tap_regular_sharp);
971
12.0k
    init_mc_fns(FILTER_2D_8TAP_SHARP_REGULAR,  8tap_sharp_regular);
972
12.0k
    init_mc_fns(FILTER_2D_8TAP_SHARP_SMOOTH,   8tap_sharp_smooth);
973
12.0k
    init_mc_fns(FILTER_2D_8TAP_SHARP,          8tap_sharp);
974
12.0k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_REGULAR, 8tap_smooth_regular);
975
12.0k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH,         8tap_smooth);
976
12.0k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_SHARP,   8tap_smooth_sharp);
977
12.0k
    init_mc_fns(FILTER_2D_BILINEAR,            bilin);
978
979
12.0k
    c->avg      = avg_c;
980
12.0k
    c->w_avg    = w_avg_c;
981
12.0k
    c->mask     = mask_c;
982
12.0k
    c->blend    = blend_c;
983
12.0k
    c->blend_v  = blend_v_c;
984
12.0k
    c->blend_h  = blend_h_c;
985
12.0k
    c->w_mask[0] = w_mask_444_c;
986
12.0k
    c->w_mask[1] = w_mask_422_c;
987
12.0k
    c->w_mask[2] = w_mask_420_c;
988
12.0k
    c->warp8x8  = warp_affine_8x8_c;
989
12.0k
    c->warp8x8t = warp_affine_8x8t_c;
990
12.0k
    c->emu_edge = emu_edge_c;
991
12.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
12.0k
}
dav1d_mc_dsp_init_16bpc
Line
Count
Source
960
14.1k
COLD void bitfn(dav1d_mc_dsp_init)(Dav1dMCDSPContext *const c) {
961
14.1k
#define init_mc_fns(type, name) do { \
962
14.1k
    c->mc        [type] = put_##name##_c; \
963
14.1k
    c->mc_scaled [type] = put_##name##_scaled_c; \
964
14.1k
    c->mct       [type] = prep_##name##_c; \
965
14.1k
    c->mct_scaled[type] = prep_##name##_scaled_c; \
966
14.1k
} while (0)
967
968
14.1k
    init_mc_fns(FILTER_2D_8TAP_REGULAR,        8tap_regular);
969
14.1k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SMOOTH, 8tap_regular_smooth);
970
14.1k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SHARP,  8tap_regular_sharp);
971
14.1k
    init_mc_fns(FILTER_2D_8TAP_SHARP_REGULAR,  8tap_sharp_regular);
972
14.1k
    init_mc_fns(FILTER_2D_8TAP_SHARP_SMOOTH,   8tap_sharp_smooth);
973
14.1k
    init_mc_fns(FILTER_2D_8TAP_SHARP,          8tap_sharp);
974
14.1k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_REGULAR, 8tap_smooth_regular);
975
14.1k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH,         8tap_smooth);
976
14.1k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_SHARP,   8tap_smooth_sharp);
977
14.1k
    init_mc_fns(FILTER_2D_BILINEAR,            bilin);
978
979
14.1k
    c->avg      = avg_c;
980
14.1k
    c->w_avg    = w_avg_c;
981
14.1k
    c->mask     = mask_c;
982
14.1k
    c->blend    = blend_c;
983
14.1k
    c->blend_v  = blend_v_c;
984
14.1k
    c->blend_h  = blend_h_c;
985
14.1k
    c->w_mask[0] = w_mask_444_c;
986
14.1k
    c->w_mask[1] = w_mask_422_c;
987
14.1k
    c->w_mask[2] = w_mask_420_c;
988
14.1k
    c->warp8x8  = warp_affine_8x8_c;
989
14.1k
    c->warp8x8t = warp_affine_8x8t_c;
990
14.1k
    c->emu_edge = emu_edge_c;
991
14.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
14.1k
}