Coverage Report

Created: 2026-07-16 06:31

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
448k
#define get_intermediate_bits(bitdepth_max) 4
41
// Output in interval [-5132, 9212], fits in int16_t as is
42
29.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
47.5k
{
55
755k
    do {
56
755k
        pixel_copy(dst, src, w);
57
58
755k
        dst += dst_stride;
59
755k
        src += src_stride;
60
755k
    } while (--h);
61
47.5k
}
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
8.13k
{
67
8.13k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
68
121k
    do {
69
2.79M
        for (int x = 0; x < w; x++)
70
2.67M
            tmp[x] = (src[x] << intermediate_bits) - PREP_BIAS;
71
72
121k
        tmp += w;
73
121k
        src += src_stride;
74
121k
    } while (--h);
75
8.13k
}
76
77
#define FILTER_8TAP(src, x, F, stride) \
78
39.4M
    (F[0] * src[x + -3 * stride] + \
79
39.4M
     F[1] * src[x + -2 * stride] + \
80
39.4M
     F[2] * src[x + -1 * stride] + \
81
39.4M
     F[3] * src[x + +0 * stride] + \
82
39.4M
     F[4] * src[x + +1 * stride] + \
83
39.4M
     F[5] * src[x + +2 * stride] + \
84
39.4M
     F[6] * src[x + +3 * stride] + \
85
39.4M
     F[7] * src[x + +4 * stride])
86
87
#define FILTER_8TAP2(src, x, F) \
88
41.4M
    (F[0] * src[0][x] + \
89
41.4M
     F[1] * src[1][x] + \
90
41.4M
     F[2] * src[2][x] + \
91
41.4M
     F[3] * src[3][x] + \
92
41.4M
     F[4] * src[4][x] + \
93
41.4M
     F[5] * src[5][x] + \
94
41.4M
     F[6] * src[6][x] + \
95
41.4M
     F[7] * src[7][x])
96
97
#define DAV1D_FILTER_8TAP_RND(src, x, F, stride, sh) \
98
38.3M
    ((FILTER_8TAP(src, x, F, stride) + ((1 << (sh)) >> 1)) >> (sh))
99
100
#define DAV1D_FILTER_8TAP_RND2(src, x, F, stride, rnd, sh) \
101
1.10M
    ((FILTER_8TAP(src, x, F, stride) + (rnd)) >> (sh))
102
103
#define DAV1D_FILTER_8TAP_RND3(src, x, F, sh) \
104
41.4M
    ((FILTER_8TAP2(src, x, F) + ((1 << (sh)) >> 1)) >> (sh))
105
106
#define DAV1D_FILTER_8TAP_CLIP(src, x, F, stride, sh) \
107
5.11M
    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
1.10M
    iclip_pixel(DAV1D_FILTER_8TAP_RND2(src, x, F, stride, rnd, sh))
111
112
#define DAV1D_FILTER_8TAP_CLIP3(src, x, F, sh) \
113
24.3M
    iclip_pixel(DAV1D_FILTER_8TAP_RND3(src, x, F, sh))
114
115
#define GET_H_FILTER(mx) \
116
24.6M
    const int8_t *const fh = !(mx) ? NULL : w > 4 ? \
117
22.7M
        dav1d_mc_subpel_filters[filter_type & 3][(mx) - 1] : \
118
22.7M
        dav1d_mc_subpel_filters[3 + (filter_type & 1)][(mx) - 1]
119
120
#define GET_V_FILTER(my) \
121
2.37M
    const int8_t *const fv = !(my) ? NULL : h > 4 ? \
122
2.16M
        dav1d_mc_subpel_filters[filter_type >> 2][(my) - 1] : \
123
2.16M
        dav1d_mc_subpel_filters[3 + ((filter_type >> 2) & 1)][(my) - 1]
124
125
#define GET_FILTERS() \
126
84.9k
    GET_H_FILTER(mx); \
127
84.9k
    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
68.5k
{
135
68.5k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
136
68.5k
    const int intermediate_rnd = 32 + ((1 << (6 - intermediate_bits)) >> 1);
137
138
68.5k
    GET_FILTERS();
139
68.5k
    dst_stride = PXSTRIDE(dst_stride);
140
68.5k
    src_stride = PXSTRIDE(src_stride);
141
142
68.5k
    if (fh) {
143
33.7k
        if (fv) {
144
24.8k
            int tmp_h = h + 7;
145
24.8k
            int16_t mid[128 * 135], *mid_ptr = mid;
146
147
24.8k
            src -= src_stride * 3;
148
414k
            do {
149
5.65M
                for (int x = 0; x < w; x++)
150
5.24M
                    mid_ptr[x] = DAV1D_FILTER_8TAP_RND(src, x, fh, 1,
151
414k
                                                       6 - intermediate_bits);
152
153
414k
                mid_ptr += 128;
154
414k
                src += src_stride;
155
414k
            } while (--tmp_h);
156
157
24.8k
            mid_ptr = mid + 128 * 3;
158
240k
            do {
159
3.87M
                for (int x = 0; x < w; x++)
160
3.63M
                    dst[x] = DAV1D_FILTER_8TAP_CLIP(mid_ptr, x, fv, 128,
161
240k
                                                    6 + intermediate_bits);
162
163
240k
                mid_ptr += 128;
164
240k
                dst += dst_stride;
165
240k
            } while (--h);
166
24.8k
        } else {
167
87.5k
            do {
168
1.19M
                for (int x = 0; x < w; x++) {
169
1.10M
                    dst[x] = DAV1D_FILTER_8TAP_CLIP2(src, x, fh, 1,
170
1.10M
                                                     intermediate_rnd, 6);
171
1.10M
                }
172
173
87.5k
                dst += dst_stride;
174
87.5k
                src += src_stride;
175
87.5k
            } while (--h);
176
8.92k
        }
177
34.7k
    } else if (fv) {
178
92.2k
        do {
179
1.57M
            for (int x = 0; x < w; x++)
180
1.48M
                dst[x] = DAV1D_FILTER_8TAP_CLIP(src, x, fv, src_stride, 6);
181
182
92.2k
            dst += dst_stride;
183
92.2k
            src += src_stride;
184
92.2k
        } while (--h);
185
9.93k
    } else
186
24.8k
        put_c(dst, dst_stride, src, src_stride, w, h);
187
68.5k
}
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
120k
{
196
120k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
197
120k
    const int intermediate_rnd = (1 << intermediate_bits) >> 1;
198
120k
    int16_t mid[128 * 8];
199
120k
    int16_t *mid_ptrs[8];
200
120k
    int in_y = -8;
201
120k
    src_stride = PXSTRIDE(src_stride);
202
203
1.08M
    for (int i = 0; i < 8; i++)
204
965k
        mid_ptrs[i] = &mid[128 * i];
205
206
120k
    src -= src_stride * 3;
207
208
1.45M
    for (int y = 0; y < h; y++) {
209
1.33M
        int x;
210
1.33M
        int src_y = my >> 10;
211
1.33M
        GET_V_FILTER((my & 0x3ff) >> 6);
212
213
2.55M
        while (in_y < src_y) {
214
1.22M
            int imx = mx, ioff = 0;
215
1.22M
            int16_t *mid_ptr = mid_ptrs[0];
216
217
9.78M
            for (int i = 0; i < 7; i++)
218
8.55M
                mid_ptrs[i] = mid_ptrs[i + 1];
219
1.22M
            mid_ptrs[7] = mid_ptr;
220
221
16.6M
            for (x = 0; x < w; x++) {
222
15.4M
                GET_H_FILTER(imx >> 6);
223
15.4M
                mid_ptr[x] = fh ? DAV1D_FILTER_8TAP_RND(src, ioff, fh, 1,
224
15.4M
                                                        6 - intermediate_bits) :
225
15.4M
                                  src[ioff] << intermediate_bits;
226
15.4M
                imx += dx;
227
15.4M
                ioff += imx >> 10;
228
15.4M
                imx &= 0x3ff;
229
15.4M
            }
230
231
1.22M
            src += src_stride;
232
1.22M
            in_y++;
233
1.22M
        }
234
235
27.6M
        for (x = 0; x < w; x++)
236
26.2M
            dst[x] = fv ? DAV1D_FILTER_8TAP_CLIP3(mid_ptrs, x, fv,
237
26.2M
                                                  6 + intermediate_bits) :
238
26.2M
                          iclip_pixel((mid_ptrs[3][x] + intermediate_rnd) >>
239
1.91M
                                              intermediate_bits);
240
241
1.33M
        my += dy;
242
1.33M
        dst += PXSTRIDE(dst_stride);
243
1.33M
    }
244
120k
}
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
16.3k
{
251
16.3k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
252
16.3k
    GET_FILTERS();
253
16.3k
    src_stride = PXSTRIDE(src_stride);
254
255
16.3k
    if (fh) {
256
7.94k
        if (fv) {
257
4.86k
            int tmp_h = h + 7;
258
4.86k
            int16_t mid[128 * 135], *mid_ptr = mid;
259
260
4.86k
            src -= src_stride * 3;
261
112k
            do {
262
2.33M
                for (int x = 0; x < w; x++)
263
2.21M
                    mid_ptr[x] = DAV1D_FILTER_8TAP_RND(src, x, fh, 1,
264
112k
                                                       6 - intermediate_bits);
265
266
112k
                mid_ptr += 128;
267
112k
                src += src_stride;
268
112k
            } while (--tmp_h);
269
270
4.86k
            mid_ptr = mid + 128 * 3;
271
78.5k
            do {
272
1.88M
                for (int x = 0; x < w; x++) {
273
1.80M
                    int t = DAV1D_FILTER_8TAP_RND(mid_ptr, x, fv, 128, 6) -
274
1.80M
                                  PREP_BIAS;
275
1.80M
                    assert(t >= INT16_MIN && t <= INT16_MAX);
276
1.80M
                    tmp[x] = t;
277
1.80M
                }
278
279
78.5k
                mid_ptr += 128;
280
78.5k
                tmp += w;
281
78.5k
            } while (--h);
282
4.86k
        } else {
283
44.4k
            do {
284
764k
                for (int x = 0; x < w; x++)
285
719k
                    tmp[x] = DAV1D_FILTER_8TAP_RND(src, x, fh, 1,
286
719k
                                                   6 - intermediate_bits) -
287
719k
                             PREP_BIAS;
288
289
44.4k
                tmp += w;
290
44.4k
                src += src_stride;
291
44.4k
            } while (--h);
292
3.08k
        }
293
8.44k
    } else if (fv) {
294
41.6k
        do {
295
619k
            for (int x = 0; x < w; x++)
296
577k
                tmp[x] = DAV1D_FILTER_8TAP_RND(src, x, fv, src_stride,
297
577k
                                               6 - intermediate_bits) -
298
577k
                         PREP_BIAS;
299
300
41.6k
            tmp += w;
301
41.6k
            src += src_stride;
302
41.6k
        } while (--h);
303
3.17k
    } else
304
5.26k
        prep_c(tmp, src, src_stride, w, h HIGHBD_TAIL_SUFFIX);
305
16.3k
}
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
47.6k
{
313
47.6k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
314
47.6k
    int16_t mid[128 * 8];
315
47.6k
    int16_t *mid_ptrs[8];
316
47.6k
    int in_y = -8;
317
47.6k
    src_stride = PXSTRIDE(src_stride);
318
319
428k
    for (int i = 0; i < 8; i++)
320
381k
        mid_ptrs[i] = &mid[128 * i];
321
322
47.6k
    src -= src_stride * 3;
323
324
1.00M
    for (int y = 0; y < h; y++) {
325
956k
        int x;
326
956k
        int src_y = my >> 10;
327
956k
        GET_V_FILTER((my & 0x3ff) >> 6);
328
329
1.53M
        while (in_y < src_y) {
330
575k
            int imx = mx, ioff = 0;
331
575k
            int16_t *mid_ptr = mid_ptrs[0];
332
333
4.60M
            for (int i = 0; i < 7; i++)
334
4.03M
                mid_ptrs[i] = mid_ptrs[i + 1];
335
575k
            mid_ptrs[7] = mid_ptr;
336
337
9.67M
            for (x = 0; x < w; x++) {
338
9.10M
                GET_H_FILTER(imx >> 6);
339
9.10M
                mid_ptr[x] = fh ? DAV1D_FILTER_8TAP_RND(src, ioff, fh, 1,
340
9.10M
                                                        6 - intermediate_bits) :
341
9.10M
                                  src[ioff] << intermediate_bits;
342
9.10M
                imx += dx;
343
9.10M
                ioff += imx >> 10;
344
9.10M
                imx &= 0x3ff;
345
9.10M
            }
346
347
575k
            src += src_stride;
348
575k
            in_y++;
349
575k
        }
350
351
19.2M
        for (x = 0; x < w; x++)
352
18.3M
            tmp[x] = (fv ? DAV1D_FILTER_8TAP_RND3(mid_ptrs, x, fv, 6)
353
18.3M
                         : mid_ptrs[3][x]) - PREP_BIAS;
354
355
956k
        my += dy;
356
956k
        tmp += w;
357
956k
    }
358
47.6k
}
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
68.5k
                                HIGHBD_DECL_SUFFIX) \
368
68.5k
{ \
369
68.5k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
68.5k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
68.5k
} \
mc_tmpl.c:put_8tap_regular_c
Line
Count
Source
367
49.1k
                                HIGHBD_DECL_SUFFIX) \
368
49.1k
{ \
369
49.1k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
49.1k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
49.1k
} \
mc_tmpl.c:put_8tap_regular_smooth_c
Line
Count
Source
367
2.22k
                                HIGHBD_DECL_SUFFIX) \
368
2.22k
{ \
369
2.22k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
2.22k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
2.22k
} \
mc_tmpl.c:put_8tap_regular_sharp_c
Line
Count
Source
367
561
                                HIGHBD_DECL_SUFFIX) \
368
561
{ \
369
561
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
561
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
561
} \
mc_tmpl.c:put_8tap_sharp_regular_c
Line
Count
Source
367
718
                                HIGHBD_DECL_SUFFIX) \
368
718
{ \
369
718
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
718
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
718
} \
mc_tmpl.c:put_8tap_sharp_smooth_c
Line
Count
Source
367
337
                                HIGHBD_DECL_SUFFIX) \
368
337
{ \
369
337
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
337
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
337
} \
mc_tmpl.c:put_8tap_sharp_c
Line
Count
Source
367
6.43k
                                HIGHBD_DECL_SUFFIX) \
368
6.43k
{ \
369
6.43k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
6.43k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
6.43k
} \
mc_tmpl.c:put_8tap_smooth_regular_c
Line
Count
Source
367
2.21k
                                HIGHBD_DECL_SUFFIX) \
368
2.21k
{ \
369
2.21k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
2.21k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
2.21k
} \
mc_tmpl.c:put_8tap_smooth_c
Line
Count
Source
367
6.43k
                                HIGHBD_DECL_SUFFIX) \
368
6.43k
{ \
369
6.43k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
6.43k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
6.43k
} \
mc_tmpl.c:put_8tap_smooth_sharp_c
Line
Count
Source
367
468
                                HIGHBD_DECL_SUFFIX) \
368
468
{ \
369
468
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
468
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
468
} \
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
120k
                                       HIGHBD_DECL_SUFFIX) \
380
120k
{ \
381
120k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
120k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
120k
} \
mc_tmpl.c:put_8tap_regular_scaled_c
Line
Count
Source
379
84.6k
                                       HIGHBD_DECL_SUFFIX) \
380
84.6k
{ \
381
84.6k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
84.6k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
84.6k
} \
mc_tmpl.c:put_8tap_regular_smooth_scaled_c
Line
Count
Source
379
3.99k
                                       HIGHBD_DECL_SUFFIX) \
380
3.99k
{ \
381
3.99k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
3.99k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
3.99k
} \
mc_tmpl.c:put_8tap_regular_sharp_scaled_c
Line
Count
Source
379
1.62k
                                       HIGHBD_DECL_SUFFIX) \
380
1.62k
{ \
381
1.62k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
1.62k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
1.62k
} \
mc_tmpl.c:put_8tap_sharp_regular_scaled_c
Line
Count
Source
379
2.05k
                                       HIGHBD_DECL_SUFFIX) \
380
2.05k
{ \
381
2.05k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
2.05k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
2.05k
} \
mc_tmpl.c:put_8tap_sharp_smooth_scaled_c
Line
Count
Source
379
817
                                       HIGHBD_DECL_SUFFIX) \
380
817
{ \
381
817
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
817
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
817
} \
mc_tmpl.c:put_8tap_sharp_scaled_c
Line
Count
Source
379
14.0k
                                       HIGHBD_DECL_SUFFIX) \
380
14.0k
{ \
381
14.0k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
14.0k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
14.0k
} \
mc_tmpl.c:put_8tap_smooth_regular_scaled_c
Line
Count
Source
379
6.47k
                                       HIGHBD_DECL_SUFFIX) \
380
6.47k
{ \
381
6.47k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
6.47k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
6.47k
} \
mc_tmpl.c:put_8tap_smooth_scaled_c
Line
Count
Source
379
6.22k
                                       HIGHBD_DECL_SUFFIX) \
380
6.22k
{ \
381
6.22k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
6.22k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
6.22k
} \
mc_tmpl.c:put_8tap_smooth_sharp_scaled_c
Line
Count
Source
379
831
                                       HIGHBD_DECL_SUFFIX) \
380
831
{ \
381
831
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
831
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
831
} \
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
16.3k
                                 HIGHBD_DECL_SUFFIX) \
390
16.3k
{ \
391
16.3k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
16.3k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
16.3k
} \
mc_tmpl.c:prep_8tap_regular_c
Line
Count
Source
389
7.53k
                                 HIGHBD_DECL_SUFFIX) \
390
7.53k
{ \
391
7.53k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
7.53k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
7.53k
} \
mc_tmpl.c:prep_8tap_regular_smooth_c
Line
Count
Source
389
397
                                 HIGHBD_DECL_SUFFIX) \
390
397
{ \
391
397
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
397
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
397
} \
mc_tmpl.c:prep_8tap_regular_sharp_c
Line
Count
Source
389
624
                                 HIGHBD_DECL_SUFFIX) \
390
624
{ \
391
624
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
624
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
624
} \
mc_tmpl.c:prep_8tap_sharp_regular_c
Line
Count
Source
389
1.49k
                                 HIGHBD_DECL_SUFFIX) \
390
1.49k
{ \
391
1.49k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
1.49k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
1.49k
} \
mc_tmpl.c:prep_8tap_sharp_smooth_c
Line
Count
Source
389
701
                                 HIGHBD_DECL_SUFFIX) \
390
701
{ \
391
701
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
701
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
701
} \
mc_tmpl.c:prep_8tap_sharp_c
Line
Count
Source
389
2.26k
                                 HIGHBD_DECL_SUFFIX) \
390
2.26k
{ \
391
2.26k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
2.26k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
2.26k
} \
mc_tmpl.c:prep_8tap_smooth_regular_c
Line
Count
Source
389
642
                                 HIGHBD_DECL_SUFFIX) \
390
642
{ \
391
642
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
642
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
642
} \
mc_tmpl.c:prep_8tap_smooth_c
Line
Count
Source
389
2.45k
                                 HIGHBD_DECL_SUFFIX) \
390
2.45k
{ \
391
2.45k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
2.45k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
2.45k
} \
mc_tmpl.c:prep_8tap_smooth_sharp_c
Line
Count
Source
389
277
                                 HIGHBD_DECL_SUFFIX) \
390
277
{ \
391
277
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
277
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
277
} \
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
47.6k
                                        HIGHBD_DECL_SUFFIX) \
401
47.6k
{ \
402
47.6k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
47.6k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
47.6k
}
mc_tmpl.c:prep_8tap_regular_scaled_c
Line
Count
Source
400
20.7k
                                        HIGHBD_DECL_SUFFIX) \
401
20.7k
{ \
402
20.7k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
20.7k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
20.7k
}
mc_tmpl.c:prep_8tap_regular_smooth_scaled_c
Line
Count
Source
400
2.31k
                                        HIGHBD_DECL_SUFFIX) \
401
2.31k
{ \
402
2.31k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
2.31k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
2.31k
}
mc_tmpl.c:prep_8tap_regular_sharp_scaled_c
Line
Count
Source
400
4.21k
                                        HIGHBD_DECL_SUFFIX) \
401
4.21k
{ \
402
4.21k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
4.21k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
4.21k
}
mc_tmpl.c:prep_8tap_sharp_regular_scaled_c
Line
Count
Source
400
5.15k
                                        HIGHBD_DECL_SUFFIX) \
401
5.15k
{ \
402
5.15k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
5.15k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
5.15k
}
mc_tmpl.c:prep_8tap_sharp_smooth_scaled_c
Line
Count
Source
400
1.56k
                                        HIGHBD_DECL_SUFFIX) \
401
1.56k
{ \
402
1.56k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
1.56k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
1.56k
}
mc_tmpl.c:prep_8tap_sharp_scaled_c
Line
Count
Source
400
5.37k
                                        HIGHBD_DECL_SUFFIX) \
401
5.37k
{ \
402
5.37k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
5.37k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
5.37k
}
mc_tmpl.c:prep_8tap_smooth_regular_scaled_c
Line
Count
Source
400
4.30k
                                        HIGHBD_DECL_SUFFIX) \
401
4.30k
{ \
402
4.30k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
4.30k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
4.30k
}
mc_tmpl.c:prep_8tap_smooth_scaled_c
Line
Count
Source
400
2.57k
                                        HIGHBD_DECL_SUFFIX) \
401
2.57k
{ \
402
2.57k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
2.57k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
2.57k
}
mc_tmpl.c:prep_8tap_smooth_sharp_scaled_c
Line
Count
Source
400
1.40k
                                        HIGHBD_DECL_SUFFIX) \
401
1.40k
{ \
402
1.40k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
1.40k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
1.40k
}
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
6.27M
    (16 * src[x] + ((mxy) * (src[x + stride] - src[x])))
418
419
#define FILTER_BILIN_RND(src, x, mxy, stride, sh) \
420
6.27M
    ((FILTER_BILIN(src, x, mxy, stride) + ((1 << (sh)) >> 1)) >> (sh))
421
422
#define FILTER_BILIN_CLIP(src, x, mxy, stride, sh) \
423
1.28M
    iclip_pixel(FILTER_BILIN_RND(src, x, mxy, stride, sh))
424
425
#define FILTER_BILIN2(src1, src2, x, mxy) \
426
8.91M
    (16 * src1[x] + ((mxy) * (src2[x] - src1[x])))
427
428
#define FILTER_BILIN_RND2(src1, src2, x, mxy, sh) \
429
8.91M
    ((FILTER_BILIN2(src1, src2, x, mxy) + ((1 << (sh)) >> 1)) >> (sh))
430
431
#define FILTER_BILIN_CLIP2(src1, src2, x, mxy, sh) \
432
5.23M
    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
33.6k
{
439
33.6k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
440
33.6k
    const int intermediate_rnd = (1 << intermediate_bits) >> 1;
441
33.6k
    dst_stride = PXSTRIDE(dst_stride);
442
33.6k
    src_stride = PXSTRIDE(src_stride);
443
444
33.6k
    if (mx) {
445
8.23k
        if (my) {
446
5.43k
            int16_t mid[128 * 129], *mid_ptr = mid;
447
5.43k
            int tmp_h = h + 1;
448
449
50.1k
            do {
450
520k
                for (int x = 0; x < w; x++)
451
469k
                    mid_ptr[x] = FILTER_BILIN_RND(src, x, mx, 1,
452
50.1k
                                                  4 - intermediate_bits);
453
454
50.1k
                mid_ptr += 128;
455
50.1k
                src += src_stride;
456
50.1k
            } while (--tmp_h);
457
458
5.43k
            mid_ptr = mid;
459
44.7k
            do {
460
483k
                for (int x = 0; x < w; x++)
461
438k
                    dst[x] = FILTER_BILIN_CLIP(mid_ptr, x, my, 128,
462
44.7k
                                               4 + intermediate_bits);
463
464
44.7k
                mid_ptr += 128;
465
44.7k
                dst += dst_stride;
466
44.7k
            } while (--h);
467
5.43k
        } else {
468
24.4k
            do {
469
504k
                for (int x = 0; x < w; x++) {
470
480k
                    const int px = FILTER_BILIN_RND(src, x, mx, 1,
471
480k
                                                    4 - intermediate_bits);
472
480k
                    dst[x] = iclip_pixel((px + intermediate_rnd) >> intermediate_bits);
473
480k
                }
474
475
24.4k
                dst += dst_stride;
476
24.4k
                src += src_stride;
477
24.4k
            } while (--h);
478
2.80k
        }
479
25.3k
    } else if (my) {
480
30.0k
        do {
481
876k
            for (int x = 0; x < w; x++)
482
846k
                dst[x] = FILTER_BILIN_CLIP(src, x, my, src_stride, 4);
483
484
30.0k
            dst += dst_stride;
485
30.0k
            src += src_stride;
486
30.0k
        } while (--h);
487
2.69k
    } else
488
22.7k
        put_c(dst, dst_stride, src, src_stride, w, h);
489
33.6k
}
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
23.3k
{
497
23.3k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
498
23.3k
    int16_t mid[128 * 2];
499
23.3k
    int in_y = -2;
500
501
289k
    do {
502
289k
        int x;
503
289k
        int y = my >> 10;
504
289k
        int16_t *mid1 = &mid[(y & 1) * 128];
505
289k
        int16_t *mid2 = &mid[((y + 1) & 1) * 128];
506
289k
        int dmy = my & 0x3ff;
507
508
384k
        while (in_y < y) {
509
94.2k
            int imx = mx, ioff = 0;
510
94.2k
            int16_t *mid_ptr = &mid[(in_y & 1) * 128];
511
512
1.66M
            for (x = 0; x < w; x++) {
513
1.56M
                mid_ptr[x] = FILTER_BILIN_RND(src, ioff, imx >> 6, 1,
514
1.56M
                                              4 - intermediate_bits);
515
1.56M
                imx += dx;
516
1.56M
                ioff += imx >> 10;
517
1.56M
                imx &= 0x3ff;
518
1.56M
            }
519
520
94.2k
            src += PXSTRIDE(src_stride);
521
94.2k
            in_y++;
522
94.2k
        }
523
524
5.52M
        for (x = 0; x < w; x++)
525
5.23M
            dst[x] = FILTER_BILIN_CLIP2(mid1, mid2, x, dmy >> 6,
526
289k
                                       4 + intermediate_bits);
527
528
289k
        my += dy;
529
289k
        dst += PXSTRIDE(dst_stride);
530
289k
    } while (--h);
531
23.3k
}
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
8.48k
{
538
8.48k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
539
8.48k
    src_stride = PXSTRIDE(src_stride);
540
541
8.48k
    if (mx) {
542
4.02k
        if (my) {
543
2.77k
            int16_t mid[128 * 129], *mid_ptr = mid;
544
2.77k
            int tmp_h = h + 1;
545
546
31.1k
            do {
547
582k
                for (int x = 0; x < w; x++)
548
550k
                    mid_ptr[x] = FILTER_BILIN_RND(src, x, mx, 1,
549
31.1k
                                                  4 - intermediate_bits);
550
551
31.1k
                mid_ptr += 128;
552
31.1k
                src += src_stride;
553
31.1k
            } while (--tmp_h);
554
555
2.77k
            mid_ptr = mid;
556
28.3k
            do {
557
555k
                for (int x = 0; x < w; x++)
558
526k
                    tmp[x] = FILTER_BILIN_RND(mid_ptr, x, my, 128, 4) -
559
526k
                             PREP_BIAS;
560
561
28.3k
                mid_ptr += 128;
562
28.3k
                tmp += w;
563
28.3k
            } while (--h);
564
2.77k
        } else {
565
13.7k
            do {
566
298k
                for (int x = 0; x < w; x++)
567
285k
                    tmp[x] = FILTER_BILIN_RND(src, x, mx, 1,
568
285k
                                              4 - intermediate_bits) -
569
285k
                             PREP_BIAS;
570
571
13.7k
                tmp += w;
572
13.7k
                src += src_stride;
573
13.7k
            } while (--h);
574
1.25k
        }
575
4.46k
    } else if (my) {
576
15.7k
        do {
577
278k
            for (int x = 0; x < w; x++)
578
262k
                tmp[x] = FILTER_BILIN_RND(src, x, my, src_stride,
579
262k
                                          4 - intermediate_bits) - PREP_BIAS;
580
581
15.7k
            tmp += w;
582
15.7k
            src += src_stride;
583
15.7k
        } while (--h);
584
1.59k
    } else
585
2.86k
        prep_c(tmp, src, src_stride, w, h HIGHBD_TAIL_SUFFIX);
586
8.48k
}
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
7.53k
{
593
7.53k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
594
7.53k
    int16_t mid[128 * 2];
595
7.53k
    int in_y = -2;
596
597
153k
    do {
598
153k
        int x;
599
153k
        int y = my >> 10;
600
153k
        int16_t *mid1 = &mid[(y & 1) * 128];
601
153k
        int16_t *mid2 = &mid[((y + 1) & 1) * 128];
602
153k
        int dmy = my & 0x3ff;
603
604
194k
        while (in_y < y) {
605
41.1k
            int imx = mx, ioff = 0;
606
41.1k
            int16_t *mid_ptr = &mid[(in_y & 1) * 128];
607
608
888k
            for (x = 0; x < w; x++) {
609
847k
                mid_ptr[x] = FILTER_BILIN_RND(src, ioff, imx >> 6, 1,
610
847k
                                              4 - intermediate_bits);
611
847k
                imx += dx;
612
847k
                ioff += imx >> 10;
613
847k
                imx &= 0x3ff;
614
847k
            }
615
616
41.1k
            src += PXSTRIDE(src_stride);
617
41.1k
            in_y++;
618
41.1k
        }
619
620
3.83M
        for (x = 0; x < w; x++)
621
3.68M
            tmp[x] = FILTER_BILIN_RND2(mid1, mid2, x, dmy >> 6, 4) - PREP_BIAS;
622
623
153k
        my += dy;
624
153k
        tmp += w;
625
153k
    } while (--h);
626
7.53k
}
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
26.8k
{
632
26.8k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
633
26.8k
    const int sh = intermediate_bits + 1;
634
26.8k
    const int rnd = (1 << intermediate_bits) + PREP_BIAS * 2;
635
492k
    do {
636
10.6M
        for (int x = 0; x < w; x++)
637
10.1M
            dst[x] = iclip_pixel((tmp1[x] + tmp2[x] + rnd) >> sh);
638
639
492k
        tmp1 += w;
640
492k
        tmp2 += w;
641
492k
        dst += PXSTRIDE(dst_stride);
642
492k
    } while (--h);
643
26.8k
}
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
2.93k
{
649
2.93k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
650
2.93k
    const int sh = intermediate_bits + 4;
651
2.93k
    const int rnd = (8 << intermediate_bits) + PREP_BIAS * 16;
652
41.1k
    do {
653
710k
        for (int x = 0; x < w; x++)
654
669k
            dst[x] = iclip_pixel((tmp1[x] * weight +
655
669k
                                  tmp2[x] * (16 - weight) + rnd) >> sh);
656
657
41.1k
        tmp1 += w;
658
41.1k
        tmp2 += w;
659
41.1k
        dst += PXSTRIDE(dst_stride);
660
41.1k
    } while (--h);
661
2.93k
}
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
7.81k
{
667
7.81k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
668
7.81k
    const int sh = intermediate_bits + 6;
669
7.81k
    const int rnd = (32 << intermediate_bits) + PREP_BIAS * 64;
670
106k
    do {
671
1.54M
        for (int x = 0; x < w; x++)
672
1.43M
            dst[x] = iclip_pixel((tmp1[x] * mask[x] +
673
1.43M
                                  tmp2[x] * (64 - mask[x]) + rnd) >> sh);
674
675
106k
        tmp1 += w;
676
106k
        tmp2 += w;
677
106k
        mask += w;
678
106k
        dst += PXSTRIDE(dst_stride);
679
106k
    } while (--h);
680
7.81k
}
681
682
4.31M
#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
13.5k
{
686
120k
    do {
687
1.42M
        for (int x = 0; x < w; x++) {
688
1.30M
            dst[x] = blend_px(dst[x], tmp[x], mask[x]);
689
1.30M
        }
690
120k
        dst += PXSTRIDE(dst_stride);
691
120k
        tmp += w;
692
120k
        mask += w;
693
120k
    } while (--h);
694
13.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
23.0k
{
699
23.0k
    const uint8_t *const mask = &dav1d_obmc_masks[w];
700
262k
    do {
701
1.70M
        for (int x = 0; x < (w * 3) >> 2; x++) {
702
1.43M
            dst[x] = blend_px(dst[x], tmp[x], mask[x]);
703
1.43M
        }
704
262k
        dst += PXSTRIDE(dst_stride);
705
262k
        tmp += w;
706
262k
    } while (--h);
707
23.0k
}
708
709
static void blend_h_c(pixel *dst, const ptrdiff_t dst_stride, const pixel *tmp,
710
                      const int w, int h)
711
20.9k
{
712
20.9k
    const uint8_t *mask = &dav1d_obmc_masks[h];
713
20.9k
    h = (h * 3) >> 2;
714
113k
    do {
715
113k
        const int m = *mask++;
716
1.68M
        for (int x = 0; x < w; x++) {
717
1.57M
            dst[x] = blend_px(dst[x], tmp[x], m);
718
1.57M
        }
719
113k
        dst += PXSTRIDE(dst_stride);
720
113k
        tmp += w;
721
113k
    } while (--h);
722
20.9k
}
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
3.03k
{
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
3.03k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
732
3.03k
    const int bitdepth = bitdepth_from_max(bitdepth_max);
733
3.03k
    const int sh = intermediate_bits + 6;
734
3.03k
    const int rnd = (32 << intermediate_bits) + PREP_BIAS * 64;
735
3.03k
    const int mask_sh = bitdepth + intermediate_bits - 4;
736
3.03k
    const int mask_rnd = 1 << (mask_sh - 5);
737
97.1k
    do {
738
1.78M
        for (int x = 0; x < w; x++) {
739
1.69M
            const int tmpdiff = tmp1[x] - tmp2[x];
740
1.69M
            const int m = imin(38 + ((abs(tmpdiff) + mask_rnd) >> mask_sh), 64);
741
1.69M
            dst[x] = iclip_pixel((tmpdiff * m + tmp2[x] * 64 + rnd) >> sh);
742
743
1.69M
            if (ss_hor) {
744
816k
                x++;
745
746
816k
                const int tmpdiff = tmp1[x] - tmp2[x];
747
816k
                const int n = imin(38 + ((abs(tmpdiff) + mask_rnd) >> mask_sh), 64);
748
816k
                dst[x] = iclip_pixel((tmpdiff * n + tmp2[x] * 64 + rnd) >> sh);
749
750
816k
                if (h & ss_ver) {
751
397k
                    mask[x >> 1] = (m + n + mask[x >> 1] + 2 - sign) >> 2;
752
419k
                } else if (ss_ver) {
753
397k
                    mask[x >> 1] = m + n;
754
397k
                } else {
755
21.5k
                    mask[x >> 1] = (m + n + 1 - sign) >> 1;
756
21.5k
                }
757
876k
            } else {
758
876k
                mask[x] = m;
759
876k
            }
760
1.69M
        }
761
762
97.1k
        tmp1 += w;
763
97.1k
        tmp2 += w;
764
97.1k
        dst += PXSTRIDE(dst_stride);
765
97.1k
        if (!ss_ver || (h & 1)) mask += w >> ss_hor;
766
97.1k
    } while (--h);
767
3.03k
}
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
3.03k
                             const int sign HIGHBD_DECL_SUFFIX) \
774
3.03k
{ \
775
3.03k
    w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver \
776
3.03k
             HIGHBD_TAIL_SUFFIX); \
777
3.03k
}
mc_tmpl.c:w_mask_444_c
Line
Count
Source
773
1.08k
                             const int sign HIGHBD_DECL_SUFFIX) \
774
1.08k
{ \
775
1.08k
    w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver \
776
1.08k
             HIGHBD_TAIL_SUFFIX); \
777
1.08k
}
mc_tmpl.c:w_mask_422_c
Line
Count
Source
773
57
                             const int sign HIGHBD_DECL_SUFFIX) \
774
57
{ \
775
57
    w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver \
776
57
             HIGHBD_TAIL_SUFFIX); \
777
57
}
mc_tmpl.c:w_mask_420_c
Line
Count
Source
773
1.89k
                             const int sign HIGHBD_DECL_SUFFIX) \
774
1.89k
{ \
775
1.89k
    w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver \
776
1.89k
             HIGHBD_TAIL_SUFFIX); \
777
1.89k
}
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
13.4M
    ((F[0] * src[x - 3 * stride] + \
787
13.4M
      F[1] * src[x - 2 * stride] + \
788
13.4M
      F[2] * src[x - 1 * stride] + \
789
13.4M
      F[3] * src[x + 0 * stride] + \
790
13.4M
      F[4] * src[x + 1 * stride] + \
791
13.4M
      F[5] * src[x + 2 * stride] + \
792
13.4M
      F[6] * src[x + 3 * stride] + \
793
13.4M
      F[7] * src[x + 4 * stride] + \
794
13.4M
      ((1 << (sh)) >> 1)) >> (sh))
795
796
#define FILTER_WARP_CLIP(src, x, F, stride, sh) \
797
4.07M
    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
63.6k
{
804
63.6k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
805
63.6k
    int16_t mid[15 * 8], *mid_ptr = mid;
806
807
63.6k
    src -= 3 * PXSTRIDE(src_stride);
808
1.01M
    for (int y = 0; y < 15; y++, mx += abcd[1]) {
809
8.58M
        for (int x = 0, tmx = mx; x < 8; x++, tmx += abcd[0]) {
810
7.63M
            const int8_t *const filter =
811
7.63M
                dav1d_mc_warp_filter[64 + ((tmx + 512) >> 10)];
812
813
7.63M
            mid_ptr[x] = FILTER_WARP_RND(src, x, filter, 1,
814
7.63M
                                         7 - intermediate_bits);
815
7.63M
        }
816
954k
        src += PXSTRIDE(src_stride);
817
954k
        mid_ptr += 8;
818
954k
    }
819
820
63.6k
    mid_ptr = &mid[3 * 8];
821
572k
    for (int y = 0; y < 8; y++, my += abcd[3]) {
822
4.57M
        for (int x = 0, tmy = my; x < 8; x++, tmy += abcd[2]) {
823
4.07M
            const int8_t *const filter =
824
4.07M
                dav1d_mc_warp_filter[64 + ((tmy + 512) >> 10)];
825
826
4.07M
            dst[x] = FILTER_WARP_CLIP(mid_ptr, x, filter, 8,
827
4.07M
                                      7 + intermediate_bits);
828
4.07M
        }
829
508k
        mid_ptr += 8;
830
508k
        dst += PXSTRIDE(dst_stride);
831
508k
    }
832
63.6k
}
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
9.33k
{
839
9.33k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
840
9.33k
    int16_t mid[15 * 8], *mid_ptr = mid;
841
842
9.33k
    src -= 3 * PXSTRIDE(src_stride);
843
149k
    for (int y = 0; y < 15; y++, mx += abcd[1]) {
844
1.26M
        for (int x = 0, tmx = mx; x < 8; x++, tmx += abcd[0]) {
845
1.12M
            const int8_t *const filter =
846
1.12M
                dav1d_mc_warp_filter[64 + ((tmx + 512) >> 10)];
847
848
1.12M
            mid_ptr[x] = FILTER_WARP_RND(src, x, filter, 1,
849
1.12M
                                         7 - intermediate_bits);
850
1.12M
        }
851
140k
        src += PXSTRIDE(src_stride);
852
140k
        mid_ptr += 8;
853
140k
    }
854
855
9.33k
    mid_ptr = &mid[3 * 8];
856
84.0k
    for (int y = 0; y < 8; y++, my += abcd[3]) {
857
672k
        for (int x = 0, tmy = my; x < 8; x++, tmy += abcd[2]) {
858
597k
            const int8_t *const filter =
859
597k
                dav1d_mc_warp_filter[64 + ((tmy + 512) >> 10)];
860
861
597k
            tmp[x] = FILTER_WARP_RND(mid_ptr, x, filter, 8, 7) - PREP_BIAS;
862
597k
        }
863
74.7k
        mid_ptr += 8;
864
74.7k
        tmp += tmp_stride;
865
74.7k
    }
866
9.33k
}
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
311k
{
874
    // find offset in reference of visible block to copy
875
311k
    ref += iclip((int) y, 0, (int) ih - 1) * PXSTRIDE(ref_stride) +
876
311k
           iclip((int) x, 0, (int) iw - 1);
877
878
    // number of pixels to extend (left, right, top, bottom)
879
311k
    const int left_ext = iclip((int) -x, 0, (int) bw - 1);
880
311k
    const int right_ext = iclip((int) (x + bw - iw), 0, (int) bw - 1);
881
311k
    assert(left_ext + right_ext < bw);
882
311k
    const int top_ext = iclip((int) -y, 0, (int) bh - 1);
883
311k
    const int bottom_ext = iclip((int) (y + bh - ih), 0, (int) bh - 1);
884
311k
    assert(top_ext + bottom_ext < bh);
885
886
    // copy visible portion first
887
311k
    pixel *blk = dst + top_ext * PXSTRIDE(dst_stride);
888
311k
    const int center_w = (int) (bw - left_ext - right_ext);
889
311k
    const int center_h = (int) (bh - top_ext - bottom_ext);
890
3.27M
    for (int y = 0; y < center_h; y++) {
891
2.95M
        pixel_copy(blk + left_ext, ref, center_w);
892
        // extend left edge for this line
893
2.95M
        if (left_ext)
894
1.11M
            pixel_set(blk, blk[left_ext], left_ext);
895
        // extend right edge for this line
896
2.95M
        if (right_ext)
897
1.87M
            pixel_set(blk + left_ext + center_w, blk[left_ext + center_w - 1],
898
1.87M
                      right_ext);
899
2.95M
        ref += PXSTRIDE(ref_stride);
900
2.95M
        blk += PXSTRIDE(dst_stride);
901
2.95M
    }
902
903
    // copy top
904
311k
    blk = dst + top_ext * PXSTRIDE(dst_stride);
905
710k
    for (int y = 0; y < top_ext; y++) {
906
398k
        pixel_copy(dst, blk, bw);
907
398k
        dst += PXSTRIDE(dst_stride);
908
398k
    }
909
910
    // copy bottom
911
311k
    dst += center_h * PXSTRIDE(dst_stride);
912
1.01M
    for (int y = 0; y < bottom_ext; y++) {
913
702k
        pixel_copy(dst, &dst[-PXSTRIDE(dst_stride)], bw);
914
702k
        dst += PXSTRIDE(dst_stride);
915
702k
    }
916
311k
}
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
70.7k
{
923
2.90M
    do {
924
2.90M
        int mx = mx0, src_x = -1;
925
227M
        for (int x = 0; x < dst_w; x++) {
926
224M
            const int8_t *const F = dav1d_resize_filter[mx >> 8];
927
224M
            dst[x] = iclip_pixel((-(F[0] * src[iclip(src_x - 3, 0, src_w - 1)] +
928
224M
                                    F[1] * src[iclip(src_x - 2, 0, src_w - 1)] +
929
224M
                                    F[2] * src[iclip(src_x - 1, 0, src_w - 1)] +
930
224M
                                    F[3] * src[iclip(src_x + 0, 0, src_w - 1)] +
931
224M
                                    F[4] * src[iclip(src_x + 1, 0, src_w - 1)] +
932
224M
                                    F[5] * src[iclip(src_x + 2, 0, src_w - 1)] +
933
224M
                                    F[6] * src[iclip(src_x + 3, 0, src_w - 1)] +
934
224M
                                    F[7] * src[iclip(src_x + 4, 0, src_w - 1)]) +
935
224M
                                  64) >> 7);
936
224M
            mx += dx;
937
224M
            src_x += mx >> 14;
938
224M
            mx &= 0x3fff;
939
224M
        }
940
941
2.90M
        dst += PXSTRIDE(dst_stride);
942
2.90M
        src += PXSTRIDE(src_stride);
943
2.90M
    } while (--h);
944
70.7k
}
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
36.5k
COLD void bitfn(dav1d_mc_dsp_init)(Dav1dMCDSPContext *const c) {
961
365k
#define init_mc_fns(type, name) do { \
962
365k
    c->mc        [type] = put_##name##_c; \
963
365k
    c->mc_scaled [type] = put_##name##_scaled_c; \
964
365k
    c->mct       [type] = prep_##name##_c; \
965
365k
    c->mct_scaled[type] = prep_##name##_scaled_c; \
966
365k
} while (0)
967
968
36.5k
    init_mc_fns(FILTER_2D_8TAP_REGULAR,        8tap_regular);
969
36.5k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SMOOTH, 8tap_regular_smooth);
970
36.5k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SHARP,  8tap_regular_sharp);
971
36.5k
    init_mc_fns(FILTER_2D_8TAP_SHARP_REGULAR,  8tap_sharp_regular);
972
36.5k
    init_mc_fns(FILTER_2D_8TAP_SHARP_SMOOTH,   8tap_sharp_smooth);
973
36.5k
    init_mc_fns(FILTER_2D_8TAP_SHARP,          8tap_sharp);
974
36.5k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_REGULAR, 8tap_smooth_regular);
975
36.5k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH,         8tap_smooth);
976
36.5k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_SHARP,   8tap_smooth_sharp);
977
36.5k
    init_mc_fns(FILTER_2D_BILINEAR,            bilin);
978
979
36.5k
    c->avg      = avg_c;
980
36.5k
    c->w_avg    = w_avg_c;
981
36.5k
    c->mask     = mask_c;
982
36.5k
    c->blend    = blend_c;
983
36.5k
    c->blend_v  = blend_v_c;
984
36.5k
    c->blend_h  = blend_h_c;
985
36.5k
    c->w_mask[0] = w_mask_444_c;
986
36.5k
    c->w_mask[1] = w_mask_422_c;
987
36.5k
    c->w_mask[2] = w_mask_420_c;
988
36.5k
    c->warp8x8  = warp_affine_8x8_c;
989
36.5k
    c->warp8x8t = warp_affine_8x8t_c;
990
36.5k
    c->emu_edge = emu_edge_c;
991
36.5k
    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
36.5k
}
dav1d_mc_dsp_init_8bpc
Line
Count
Source
960
15.9k
COLD void bitfn(dav1d_mc_dsp_init)(Dav1dMCDSPContext *const c) {
961
15.9k
#define init_mc_fns(type, name) do { \
962
15.9k
    c->mc        [type] = put_##name##_c; \
963
15.9k
    c->mc_scaled [type] = put_##name##_scaled_c; \
964
15.9k
    c->mct       [type] = prep_##name##_c; \
965
15.9k
    c->mct_scaled[type] = prep_##name##_scaled_c; \
966
15.9k
} while (0)
967
968
15.9k
    init_mc_fns(FILTER_2D_8TAP_REGULAR,        8tap_regular);
969
15.9k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SMOOTH, 8tap_regular_smooth);
970
15.9k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SHARP,  8tap_regular_sharp);
971
15.9k
    init_mc_fns(FILTER_2D_8TAP_SHARP_REGULAR,  8tap_sharp_regular);
972
15.9k
    init_mc_fns(FILTER_2D_8TAP_SHARP_SMOOTH,   8tap_sharp_smooth);
973
15.9k
    init_mc_fns(FILTER_2D_8TAP_SHARP,          8tap_sharp);
974
15.9k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_REGULAR, 8tap_smooth_regular);
975
15.9k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH,         8tap_smooth);
976
15.9k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_SHARP,   8tap_smooth_sharp);
977
15.9k
    init_mc_fns(FILTER_2D_BILINEAR,            bilin);
978
979
15.9k
    c->avg      = avg_c;
980
15.9k
    c->w_avg    = w_avg_c;
981
15.9k
    c->mask     = mask_c;
982
15.9k
    c->blend    = blend_c;
983
15.9k
    c->blend_v  = blend_v_c;
984
15.9k
    c->blend_h  = blend_h_c;
985
15.9k
    c->w_mask[0] = w_mask_444_c;
986
15.9k
    c->w_mask[1] = w_mask_422_c;
987
15.9k
    c->w_mask[2] = w_mask_420_c;
988
15.9k
    c->warp8x8  = warp_affine_8x8_c;
989
15.9k
    c->warp8x8t = warp_affine_8x8t_c;
990
15.9k
    c->emu_edge = emu_edge_c;
991
15.9k
    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
15.9k
}
dav1d_mc_dsp_init_16bpc
Line
Count
Source
960
20.6k
COLD void bitfn(dav1d_mc_dsp_init)(Dav1dMCDSPContext *const c) {
961
20.6k
#define init_mc_fns(type, name) do { \
962
20.6k
    c->mc        [type] = put_##name##_c; \
963
20.6k
    c->mc_scaled [type] = put_##name##_scaled_c; \
964
20.6k
    c->mct       [type] = prep_##name##_c; \
965
20.6k
    c->mct_scaled[type] = prep_##name##_scaled_c; \
966
20.6k
} while (0)
967
968
20.6k
    init_mc_fns(FILTER_2D_8TAP_REGULAR,        8tap_regular);
969
20.6k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SMOOTH, 8tap_regular_smooth);
970
20.6k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SHARP,  8tap_regular_sharp);
971
20.6k
    init_mc_fns(FILTER_2D_8TAP_SHARP_REGULAR,  8tap_sharp_regular);
972
20.6k
    init_mc_fns(FILTER_2D_8TAP_SHARP_SMOOTH,   8tap_sharp_smooth);
973
20.6k
    init_mc_fns(FILTER_2D_8TAP_SHARP,          8tap_sharp);
974
20.6k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_REGULAR, 8tap_smooth_regular);
975
20.6k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH,         8tap_smooth);
976
20.6k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_SHARP,   8tap_smooth_sharp);
977
20.6k
    init_mc_fns(FILTER_2D_BILINEAR,            bilin);
978
979
20.6k
    c->avg      = avg_c;
980
20.6k
    c->w_avg    = w_avg_c;
981
20.6k
    c->mask     = mask_c;
982
20.6k
    c->blend    = blend_c;
983
20.6k
    c->blend_v  = blend_v_c;
984
20.6k
    c->blend_h  = blend_h_c;
985
20.6k
    c->w_mask[0] = w_mask_444_c;
986
20.6k
    c->w_mask[1] = w_mask_422_c;
987
20.6k
    c->w_mask[2] = w_mask_420_c;
988
20.6k
    c->warp8x8  = warp_affine_8x8_c;
989
20.6k
    c->warp8x8t = warp_affine_8x8t_c;
990
20.6k
    c->emu_edge = emu_edge_c;
991
20.6k
    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
20.6k
}