Coverage Report

Created: 2026-10-17 06:50

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
184k
#define get_intermediate_bits(bitdepth_max) 4
41
// Output in interval [-5132, 9212], fits in int16_t as is
42
10.1M
#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
62.5k
{
55
682k
    do {
56
682k
        pixel_copy(dst, src, w);
57
58
682k
        dst += dst_stride;
59
682k
        src += src_stride;
60
682k
    } while (--h);
61
62.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
3.90k
{
67
3.90k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
68
55.7k
    do {
69
1.38M
        for (int x = 0; x < w; x++)
70
1.32M
            tmp[x] = (src[x] << intermediate_bits) - PREP_BIAS;
71
72
55.7k
        tmp += w;
73
55.7k
        src += src_stride;
74
55.7k
    } while (--h);
75
3.90k
}
76
77
#define FILTER_8TAP(src, x, F, stride) \
78
24.2M
    (F[0] * src[x + -3 * stride] + \
79
24.2M
     F[1] * src[x + -2 * stride] + \
80
24.2M
     F[2] * src[x + -1 * stride] + \
81
24.2M
     F[3] * src[x + +0 * stride] + \
82
24.2M
     F[4] * src[x + +1 * stride] + \
83
24.2M
     F[5] * src[x + +2 * stride] + \
84
24.2M
     F[6] * src[x + +3 * stride] + \
85
24.2M
     F[7] * src[x + +4 * stride])
86
87
#define FILTER_8TAP2(src, x, F) \
88
18.3M
    (F[0] * src[0][x] + \
89
18.3M
     F[1] * src[1][x] + \
90
18.3M
     F[2] * src[2][x] + \
91
18.3M
     F[3] * src[3][x] + \
92
18.3M
     F[4] * src[4][x] + \
93
18.3M
     F[5] * src[5][x] + \
94
18.3M
     F[6] * src[6][x] + \
95
18.3M
     F[7] * src[7][x])
96
97
#define DAV1D_FILTER_8TAP_RND(src, x, F, stride, sh) \
98
23.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
939k
    ((FILTER_8TAP(src, x, F, stride) + (rnd)) >> (sh))
102
103
#define DAV1D_FILTER_8TAP_RND3(src, x, F, sh) \
104
18.3M
    ((FILTER_8TAP2(src, x, F) + ((1 << (sh)) >> 1)) >> (sh))
105
106
#define DAV1D_FILTER_8TAP_CLIP(src, x, F, stride, sh) \
107
2.56M
    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
939k
    iclip_pixel(DAV1D_FILTER_8TAP_RND2(src, x, F, stride, rnd, sh))
111
112
#define DAV1D_FILTER_8TAP_CLIP3(src, x, F, sh) \
113
14.0M
    iclip_pixel(DAV1D_FILTER_8TAP_RND3(src, x, F, sh))
114
115
#define GET_H_FILTER(mx) \
116
16.4M
    const int8_t *const fh = !(mx) ? NULL : w > 4 ? \
117
15.2M
        dav1d_mc_subpel_filters[filter_type & 3][(mx) - 1] : \
118
15.2M
        dav1d_mc_subpel_filters[3 + (filter_type & 1)][(mx) - 1]
119
120
#define GET_V_FILTER(my) \
121
574k
    const int8_t *const fv = !(my) ? NULL : h > 4 ? \
122
377k
        dav1d_mc_subpel_filters[filter_type >> 2][(my) - 1] : \
123
377k
        dav1d_mc_subpel_filters[3 + ((filter_type >> 2) & 1)][(my) - 1]
124
125
#define GET_FILTERS() \
126
81.9k
    GET_H_FILTER(mx); \
127
81.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
72.3k
{
135
72.3k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
136
72.3k
    const int intermediate_rnd = 32 + ((1 << (6 - intermediate_bits)) >> 1);
137
138
72.3k
    GET_FILTERS();
139
72.3k
    dst_stride = PXSTRIDE(dst_stride);
140
72.3k
    src_stride = PXSTRIDE(src_stride);
141
142
72.3k
    if (fh) {
143
16.9k
        if (fv) {
144
9.92k
            int tmp_h = h + 7;
145
9.92k
            int16_t mid[128 * 135], *mid_ptr = mid;
146
147
9.92k
            src -= src_stride * 3;
148
159k
            do {
149
2.37M
                for (int x = 0; x < w; x++)
150
2.21M
                    mid_ptr[x] = DAV1D_FILTER_8TAP_RND(src, x, fh, 1,
151
159k
                                                       6 - intermediate_bits);
152
153
159k
                mid_ptr += 128;
154
159k
                src += src_stride;
155
159k
            } while (--tmp_h);
156
157
9.92k
            mid_ptr = mid + 128 * 3;
158
90.2k
            do {
159
1.68M
                for (int x = 0; x < w; x++)
160
1.59M
                    dst[x] = DAV1D_FILTER_8TAP_CLIP(mid_ptr, x, fv, 128,
161
90.2k
                                                    6 + intermediate_bits);
162
163
90.2k
                mid_ptr += 128;
164
90.2k
                dst += dst_stride;
165
90.2k
            } while (--h);
166
9.92k
        } else {
167
57.0k
            do {
168
996k
                for (int x = 0; x < w; x++) {
169
939k
                    dst[x] = DAV1D_FILTER_8TAP_CLIP2(src, x, fh, 1,
170
939k
                                                     intermediate_rnd, 6);
171
939k
                }
172
173
57.0k
                dst += dst_stride;
174
57.0k
                src += src_stride;
175
57.0k
            } while (--h);
176
7.05k
        }
177
55.3k
    } else if (fv) {
178
64.2k
        do {
179
1.03M
            for (int x = 0; x < w; x++)
180
966k
                dst[x] = DAV1D_FILTER_8TAP_CLIP(src, x, fv, src_stride, 6);
181
182
64.2k
            dst += dst_stride;
183
64.2k
            src += src_stride;
184
64.2k
        } while (--h);
185
5.97k
    } else
186
49.4k
        put_c(dst, dst_stride, src, src_stride, w, h);
187
72.3k
}
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
26.2k
{
196
26.2k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
197
26.2k
    const int intermediate_rnd = (1 << intermediate_bits) >> 1;
198
26.2k
    int16_t mid[128 * 8];
199
26.2k
    int16_t *mid_ptrs[8];
200
26.2k
    int in_y = -8;
201
26.2k
    src_stride = PXSTRIDE(src_stride);
202
203
236k
    for (int i = 0; i < 8; i++)
204
209k
        mid_ptrs[i] = &mid[128 * i];
205
206
26.2k
    src -= src_stride * 3;
207
208
413k
    for (int y = 0; y < h; y++) {
209
386k
        int x;
210
386k
        int src_y = my >> 10;
211
386k
        GET_V_FILTER((my & 0x3ff) >> 6);
212
213
827k
        while (in_y < src_y) {
214
440k
            int imx = mx, ioff = 0;
215
440k
            int16_t *mid_ptr = mid_ptrs[0];
216
217
3.52M
            for (int i = 0; i < 7; i++)
218
3.08M
                mid_ptrs[i] = mid_ptrs[i + 1];
219
440k
            mid_ptrs[7] = mid_ptr;
220
221
12.5M
            for (x = 0; x < w; x++) {
222
12.1M
                GET_H_FILTER(imx >> 6);
223
12.1M
                mid_ptr[x] = fh ? DAV1D_FILTER_8TAP_RND(src, ioff, fh, 1,
224
12.1M
                                                        6 - intermediate_bits) :
225
12.1M
                                  src[ioff] << intermediate_bits;
226
12.1M
                imx += dx;
227
12.1M
                ioff += imx >> 10;
228
12.1M
                imx &= 0x3ff;
229
12.1M
            }
230
231
440k
            src += src_stride;
232
440k
            in_y++;
233
440k
        }
234
235
17.0M
        for (x = 0; x < w; x++)
236
16.6M
            dst[x] = fv ? DAV1D_FILTER_8TAP_CLIP3(mid_ptrs, x, fv,
237
16.6M
                                                  6 + intermediate_bits) :
238
16.6M
                          iclip_pixel((mid_ptrs[3][x] + intermediate_rnd) >>
239
2.60M
                                              intermediate_bits);
240
241
386k
        my += dy;
242
386k
        dst += PXSTRIDE(dst_stride);
243
386k
    }
244
26.2k
}
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
9.62k
{
251
9.62k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
252
9.62k
    GET_FILTERS();
253
9.62k
    src_stride = PXSTRIDE(src_stride);
254
255
9.62k
    if (fh) {
256
5.02k
        if (fv) {
257
3.41k
            int tmp_h = h + 7;
258
3.41k
            int16_t mid[128 * 135], *mid_ptr = mid;
259
260
3.41k
            src -= src_stride * 3;
261
62.3k
            do {
262
1.23M
                for (int x = 0; x < w; x++)
263
1.16M
                    mid_ptr[x] = DAV1D_FILTER_8TAP_RND(src, x, fh, 1,
264
62.3k
                                                       6 - intermediate_bits);
265
266
62.3k
                mid_ptr += 128;
267
62.3k
                src += src_stride;
268
62.3k
            } while (--tmp_h);
269
270
3.41k
            mid_ptr = mid + 128 * 3;
271
38.4k
            do {
272
933k
                for (int x = 0; x < w; x++) {
273
895k
                    int t = DAV1D_FILTER_8TAP_RND(mid_ptr, x, fv, 128, 6) -
274
895k
                                  PREP_BIAS;
275
895k
                    assert(t >= INT16_MIN && t <= INT16_MAX);
276
895k
                    tmp[x] = t;
277
895k
                }
278
279
38.4k
                mid_ptr += 128;
280
38.4k
                tmp += w;
281
38.4k
            } while (--h);
282
3.41k
        } else {
283
22.7k
            do {
284
628k
                for (int x = 0; x < w; x++)
285
605k
                    tmp[x] = DAV1D_FILTER_8TAP_RND(src, x, fh, 1,
286
605k
                                                   6 - intermediate_bits) -
287
605k
                             PREP_BIAS;
288
289
22.7k
                tmp += w;
290
22.7k
                src += src_stride;
291
22.7k
            } while (--h);
292
1.60k
        }
293
5.02k
    } else if (fv) {
294
25.9k
        do {
295
645k
            for (int x = 0; x < w; x++)
296
619k
                tmp[x] = DAV1D_FILTER_8TAP_RND(src, x, fv, src_stride,
297
619k
                                               6 - intermediate_bits) -
298
619k
                         PREP_BIAS;
299
300
25.9k
            tmp += w;
301
25.9k
            src += src_stride;
302
25.9k
        } while (--h);
303
1.70k
    } else
304
2.90k
        prep_c(tmp, src, src_stride, w, h HIGHBD_TAIL_SUFFIX);
305
9.62k
}
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
4.93k
{
313
4.93k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
314
4.93k
    int16_t mid[128 * 8];
315
4.93k
    int16_t *mid_ptrs[8];
316
4.93k
    int in_y = -8;
317
4.93k
    src_stride = PXSTRIDE(src_stride);
318
319
44.3k
    for (int i = 0; i < 8; i++)
320
39.4k
        mid_ptrs[i] = &mid[128 * i];
321
322
4.93k
    src -= src_stride * 3;
323
324
110k
    for (int y = 0; y < h; y++) {
325
105k
        int x;
326
105k
        int src_y = my >> 10;
327
105k
        GET_V_FILTER((my & 0x3ff) >> 6);
328
329
208k
        while (in_y < src_y) {
330
103k
            int imx = mx, ioff = 0;
331
103k
            int16_t *mid_ptr = mid_ptrs[0];
332
333
825k
            for (int i = 0; i < 7; i++)
334
722k
                mid_ptrs[i] = mid_ptrs[i + 1];
335
103k
            mid_ptrs[7] = mid_ptr;
336
337
4.28M
            for (x = 0; x < w; x++) {
338
4.18M
                GET_H_FILTER(imx >> 6);
339
4.18M
                mid_ptr[x] = fh ? DAV1D_FILTER_8TAP_RND(src, ioff, fh, 1,
340
4.18M
                                                        6 - intermediate_bits) :
341
4.18M
                                  src[ioff] << intermediate_bits;
342
4.18M
                imx += dx;
343
4.18M
                ioff += imx >> 10;
344
4.18M
                imx &= 0x3ff;
345
4.18M
            }
346
347
103k
            src += src_stride;
348
103k
            in_y++;
349
103k
        }
350
351
4.97M
        for (x = 0; x < w; x++)
352
4.86M
            tmp[x] = (fv ? DAV1D_FILTER_8TAP_RND3(mid_ptrs, x, fv, 6)
353
4.86M
                         : mid_ptrs[3][x]) - PREP_BIAS;
354
355
105k
        my += dy;
356
105k
        tmp += w;
357
105k
    }
358
4.93k
}
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
72.3k
                                HIGHBD_DECL_SUFFIX) \
368
72.3k
{ \
369
72.3k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
72.3k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
72.3k
} \
mc_tmpl.c:put_8tap_regular_c
Line
Count
Source
367
26.1k
                                HIGHBD_DECL_SUFFIX) \
368
26.1k
{ \
369
26.1k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
26.1k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
26.1k
} \
mc_tmpl.c:put_8tap_regular_smooth_c
Line
Count
Source
367
2.29k
                                HIGHBD_DECL_SUFFIX) \
368
2.29k
{ \
369
2.29k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
2.29k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
2.29k
} \
mc_tmpl.c:put_8tap_regular_sharp_c
Line
Count
Source
367
301
                                HIGHBD_DECL_SUFFIX) \
368
301
{ \
369
301
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
301
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
301
} \
mc_tmpl.c:put_8tap_sharp_regular_c
Line
Count
Source
367
297
                                HIGHBD_DECL_SUFFIX) \
368
297
{ \
369
297
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
297
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
297
} \
mc_tmpl.c:put_8tap_sharp_smooth_c
Line
Count
Source
367
140
                                HIGHBD_DECL_SUFFIX) \
368
140
{ \
369
140
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
140
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
140
} \
mc_tmpl.c:put_8tap_sharp_c
Line
Count
Source
367
38.7k
                                HIGHBD_DECL_SUFFIX) \
368
38.7k
{ \
369
38.7k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
38.7k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
38.7k
} \
mc_tmpl.c:put_8tap_smooth_regular_c
Line
Count
Source
367
1.06k
                                HIGHBD_DECL_SUFFIX) \
368
1.06k
{ \
369
1.06k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
1.06k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
1.06k
} \
mc_tmpl.c:put_8tap_smooth_c
Line
Count
Source
367
3.16k
                                HIGHBD_DECL_SUFFIX) \
368
3.16k
{ \
369
3.16k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
3.16k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
3.16k
} \
mc_tmpl.c:put_8tap_smooth_sharp_c
Line
Count
Source
367
187
                                HIGHBD_DECL_SUFFIX) \
368
187
{ \
369
187
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
187
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
187
} \
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
26.2k
                                       HIGHBD_DECL_SUFFIX) \
380
26.2k
{ \
381
26.2k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
26.2k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
26.2k
} \
mc_tmpl.c:put_8tap_regular_scaled_c
Line
Count
Source
379
20.4k
                                       HIGHBD_DECL_SUFFIX) \
380
20.4k
{ \
381
20.4k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
20.4k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
20.4k
} \
mc_tmpl.c:put_8tap_regular_smooth_scaled_c
Line
Count
Source
379
372
                                       HIGHBD_DECL_SUFFIX) \
380
372
{ \
381
372
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
372
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
372
} \
mc_tmpl.c:put_8tap_regular_sharp_scaled_c
Line
Count
Source
379
194
                                       HIGHBD_DECL_SUFFIX) \
380
194
{ \
381
194
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
194
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
194
} \
mc_tmpl.c:put_8tap_sharp_regular_scaled_c
Line
Count
Source
379
285
                                       HIGHBD_DECL_SUFFIX) \
380
285
{ \
381
285
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
285
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
285
} \
mc_tmpl.c:put_8tap_sharp_smooth_scaled_c
Line
Count
Source
379
56
                                       HIGHBD_DECL_SUFFIX) \
380
56
{ \
381
56
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
56
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
56
} \
mc_tmpl.c:put_8tap_sharp_scaled_c
Line
Count
Source
379
3.58k
                                       HIGHBD_DECL_SUFFIX) \
380
3.58k
{ \
381
3.58k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
3.58k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
3.58k
} \
mc_tmpl.c:put_8tap_smooth_regular_scaled_c
Line
Count
Source
379
499
                                       HIGHBD_DECL_SUFFIX) \
380
499
{ \
381
499
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
499
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
499
} \
mc_tmpl.c:put_8tap_smooth_scaled_c
Line
Count
Source
379
680
                                       HIGHBD_DECL_SUFFIX) \
380
680
{ \
381
680
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
680
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
680
} \
mc_tmpl.c:put_8tap_smooth_sharp_scaled_c
Line
Count
Source
379
145
                                       HIGHBD_DECL_SUFFIX) \
380
145
{ \
381
145
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
145
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
145
} \
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
9.62k
                                 HIGHBD_DECL_SUFFIX) \
390
9.62k
{ \
391
9.62k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
9.62k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
9.62k
} \
mc_tmpl.c:prep_8tap_regular_c
Line
Count
Source
389
2.90k
                                 HIGHBD_DECL_SUFFIX) \
390
2.90k
{ \
391
2.90k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
2.90k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
2.90k
} \
mc_tmpl.c:prep_8tap_regular_smooth_c
Line
Count
Source
389
411
                                 HIGHBD_DECL_SUFFIX) \
390
411
{ \
391
411
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
411
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
411
} \
mc_tmpl.c:prep_8tap_regular_sharp_c
Line
Count
Source
389
490
                                 HIGHBD_DECL_SUFFIX) \
390
490
{ \
391
490
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
490
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
490
} \
mc_tmpl.c:prep_8tap_sharp_regular_c
Line
Count
Source
389
801
                                 HIGHBD_DECL_SUFFIX) \
390
801
{ \
391
801
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
801
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
801
} \
mc_tmpl.c:prep_8tap_sharp_smooth_c
Line
Count
Source
389
333
                                 HIGHBD_DECL_SUFFIX) \
390
333
{ \
391
333
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
333
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
333
} \
mc_tmpl.c:prep_8tap_sharp_c
Line
Count
Source
389
3.87k
                                 HIGHBD_DECL_SUFFIX) \
390
3.87k
{ \
391
3.87k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
3.87k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
3.87k
} \
mc_tmpl.c:prep_8tap_smooth_regular_c
Line
Count
Source
389
347
                                 HIGHBD_DECL_SUFFIX) \
390
347
{ \
391
347
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
347
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
347
} \
mc_tmpl.c:prep_8tap_smooth_c
Line
Count
Source
389
294
                                 HIGHBD_DECL_SUFFIX) \
390
294
{ \
391
294
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
294
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
294
} \
mc_tmpl.c:prep_8tap_smooth_sharp_c
Line
Count
Source
389
170
                                 HIGHBD_DECL_SUFFIX) \
390
170
{ \
391
170
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
170
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
170
} \
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
4.93k
                                        HIGHBD_DECL_SUFFIX) \
401
4.93k
{ \
402
4.93k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
4.93k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
4.93k
}
mc_tmpl.c:prep_8tap_regular_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_smooth_scaled_c
Line
Count
Source
400
148
                                        HIGHBD_DECL_SUFFIX) \
401
148
{ \
402
148
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
148
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
148
}
mc_tmpl.c:prep_8tap_regular_sharp_scaled_c
Line
Count
Source
400
260
                                        HIGHBD_DECL_SUFFIX) \
401
260
{ \
402
260
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
260
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
260
}
mc_tmpl.c:prep_8tap_sharp_regular_scaled_c
Line
Count
Source
400
454
                                        HIGHBD_DECL_SUFFIX) \
401
454
{ \
402
454
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
454
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
454
}
mc_tmpl.c:prep_8tap_sharp_smooth_scaled_c
Line
Count
Source
400
114
                                        HIGHBD_DECL_SUFFIX) \
401
114
{ \
402
114
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
114
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
114
}
mc_tmpl.c:prep_8tap_sharp_scaled_c
Line
Count
Source
400
759
                                        HIGHBD_DECL_SUFFIX) \
401
759
{ \
402
759
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
759
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
759
}
mc_tmpl.c:prep_8tap_smooth_regular_scaled_c
Line
Count
Source
400
162
                                        HIGHBD_DECL_SUFFIX) \
401
162
{ \
402
162
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
162
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
162
}
mc_tmpl.c:prep_8tap_smooth_scaled_c
Line
Count
Source
400
617
                                        HIGHBD_DECL_SUFFIX) \
401
617
{ \
402
617
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
617
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
617
}
mc_tmpl.c:prep_8tap_smooth_sharp_scaled_c
Line
Count
Source
400
104
                                        HIGHBD_DECL_SUFFIX) \
401
104
{ \
402
104
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
104
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
104
}
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
4.26M
    (16 * src[x] + ((mxy) * (src[x + stride] - src[x])))
418
419
#define FILTER_BILIN_RND(src, x, mxy, stride, sh) \
420
4.26M
    ((FILTER_BILIN(src, x, mxy, stride) + ((1 << (sh)) >> 1)) >> (sh))
421
422
#define FILTER_BILIN_CLIP(src, x, mxy, stride, sh) \
423
583k
    iclip_pixel(FILTER_BILIN_RND(src, x, mxy, stride, sh))
424
425
#define FILTER_BILIN2(src1, src2, x, mxy) \
426
3.81M
    (16 * src1[x] + ((mxy) * (src2[x] - src1[x])))
427
428
#define FILTER_BILIN_RND2(src1, src2, x, mxy, sh) \
429
3.81M
    ((FILTER_BILIN2(src1, src2, x, mxy) + ((1 << (sh)) >> 1)) >> (sh))
430
431
#define FILTER_BILIN_CLIP2(src1, src2, x, mxy, sh) \
432
2.86M
    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
17.0k
{
439
17.0k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
440
17.0k
    const int intermediate_rnd = (1 << intermediate_bits) >> 1;
441
17.0k
    dst_stride = PXSTRIDE(dst_stride);
442
17.0k
    src_stride = PXSTRIDE(src_stride);
443
444
17.0k
    if (mx) {
445
3.30k
        if (my) {
446
2.64k
            int16_t mid[128 * 129], *mid_ptr = mid;
447
2.64k
            int tmp_h = h + 1;
448
449
25.9k
            do {
450
567k
                for (int x = 0; x < w; x++)
451
541k
                    mid_ptr[x] = FILTER_BILIN_RND(src, x, mx, 1,
452
25.9k
                                                  4 - intermediate_bits);
453
454
25.9k
                mid_ptr += 128;
455
25.9k
                src += src_stride;
456
25.9k
            } while (--tmp_h);
457
458
2.64k
            mid_ptr = mid;
459
23.3k
            do {
460
539k
                for (int x = 0; x < w; x++)
461
516k
                    dst[x] = FILTER_BILIN_CLIP(mid_ptr, x, my, 128,
462
23.3k
                                               4 + intermediate_bits);
463
464
23.3k
                mid_ptr += 128;
465
23.3k
                dst += dst_stride;
466
23.3k
            } while (--h);
467
2.64k
        } else {
468
6.12k
            do {
469
130k
                for (int x = 0; x < w; x++) {
470
124k
                    const int px = FILTER_BILIN_RND(src, x, mx, 1,
471
124k
                                                    4 - intermediate_bits);
472
124k
                    dst[x] = iclip_pixel((px + intermediate_rnd) >> intermediate_bits);
473
124k
                }
474
475
6.12k
                dst += dst_stride;
476
6.12k
                src += src_stride;
477
6.12k
            } while (--h);
478
659
        }
479
13.7k
    } else if (my) {
480
5.73k
        do {
481
72.6k
            for (int x = 0; x < w; x++)
482
66.9k
                dst[x] = FILTER_BILIN_CLIP(src, x, my, src_stride, 4);
483
484
5.73k
            dst += dst_stride;
485
5.73k
            src += src_stride;
486
5.73k
        } while (--h);
487
671
    } else
488
13.0k
        put_c(dst, dst_stride, src, src_stride, w, h);
489
17.0k
}
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
7.03k
{
497
7.03k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
498
7.03k
    int16_t mid[128 * 2];
499
7.03k
    int in_y = -2;
500
501
88.0k
    do {
502
88.0k
        int x;
503
88.0k
        int y = my >> 10;
504
88.0k
        int16_t *mid1 = &mid[(y & 1) * 128];
505
88.0k
        int16_t *mid2 = &mid[((y + 1) & 1) * 128];
506
88.0k
        int dmy = my & 0x3ff;
507
508
148k
        while (in_y < y) {
509
60.3k
            int imx = mx, ioff = 0;
510
60.3k
            int16_t *mid_ptr = &mid[(in_y & 1) * 128];
511
512
1.75M
            for (x = 0; x < w; x++) {
513
1.69M
                mid_ptr[x] = FILTER_BILIN_RND(src, ioff, imx >> 6, 1,
514
1.69M
                                              4 - intermediate_bits);
515
1.69M
                imx += dx;
516
1.69M
                ioff += imx >> 10;
517
1.69M
                imx &= 0x3ff;
518
1.69M
            }
519
520
60.3k
            src += PXSTRIDE(src_stride);
521
60.3k
            in_y++;
522
60.3k
        }
523
524
2.95M
        for (x = 0; x < w; x++)
525
2.86M
            dst[x] = FILTER_BILIN_CLIP2(mid1, mid2, x, dmy >> 6,
526
88.0k
                                       4 + intermediate_bits);
527
528
88.0k
        my += dy;
529
88.0k
        dst += PXSTRIDE(dst_stride);
530
88.0k
    } while (--h);
531
7.03k
}
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
3.12k
{
538
3.12k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
539
3.12k
    src_stride = PXSTRIDE(src_stride);
540
541
3.12k
    if (mx) {
542
1.60k
        if (my) {
543
1.01k
            int16_t mid[128 * 129], *mid_ptr = mid;
544
1.01k
            int tmp_h = h + 1;
545
546
14.5k
            do {
547
306k
                for (int x = 0; x < w; x++)
548
291k
                    mid_ptr[x] = FILTER_BILIN_RND(src, x, mx, 1,
549
14.5k
                                                  4 - intermediate_bits);
550
551
14.5k
                mid_ptr += 128;
552
14.5k
                src += src_stride;
553
14.5k
            } while (--tmp_h);
554
555
1.01k
            mid_ptr = mid;
556
13.5k
            do {
557
294k
                for (int x = 0; x < w; x++)
558
281k
                    tmp[x] = FILTER_BILIN_RND(mid_ptr, x, my, 128, 4) -
559
281k
                             PREP_BIAS;
560
561
13.5k
                mid_ptr += 128;
562
13.5k
                tmp += w;
563
13.5k
            } while (--h);
564
1.01k
        } else {
565
10.0k
            do {
566
269k
                for (int x = 0; x < w; x++)
567
259k
                    tmp[x] = FILTER_BILIN_RND(src, x, mx, 1,
568
259k
                                              4 - intermediate_bits) -
569
259k
                             PREP_BIAS;
570
571
10.0k
                tmp += w;
572
10.0k
                src += src_stride;
573
10.0k
            } while (--h);
574
587
        }
575
1.60k
    } else if (my) {
576
7.68k
        do {
577
82.7k
            for (int x = 0; x < w; x++)
578
75.1k
                tmp[x] = FILTER_BILIN_RND(src, x, my, src_stride,
579
75.1k
                                          4 - intermediate_bits) - PREP_BIAS;
580
581
7.68k
            tmp += w;
582
7.68k
            src += src_stride;
583
7.68k
        } while (--h);
584
516
    } else
585
1.00k
        prep_c(tmp, src, src_stride, w, h HIGHBD_TAIL_SUFFIX);
586
3.12k
}
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.54k
{
593
1.54k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
594
1.54k
    int16_t mid[128 * 2];
595
1.54k
    int in_y = -2;
596
597
32.2k
    do {
598
32.2k
        int x;
599
32.2k
        int y = my >> 10;
600
32.2k
        int16_t *mid1 = &mid[(y & 1) * 128];
601
32.2k
        int16_t *mid2 = &mid[((y + 1) & 1) * 128];
602
32.2k
        int dmy = my & 0x3ff;
603
604
42.6k
        while (in_y < y) {
605
10.3k
            int imx = mx, ioff = 0;
606
10.3k
            int16_t *mid_ptr = &mid[(in_y & 1) * 128];
607
608
426k
            for (x = 0; x < w; x++) {
609
415k
                mid_ptr[x] = FILTER_BILIN_RND(src, ioff, imx >> 6, 1,
610
415k
                                              4 - intermediate_bits);
611
415k
                imx += dx;
612
415k
                ioff += imx >> 10;
613
415k
                imx &= 0x3ff;
614
415k
            }
615
616
10.3k
            src += PXSTRIDE(src_stride);
617
10.3k
            in_y++;
618
10.3k
        }
619
620
982k
        for (x = 0; x < w; x++)
621
949k
            tmp[x] = FILTER_BILIN_RND2(mid1, mid2, x, dmy >> 6, 4) - PREP_BIAS;
622
623
32.2k
        my += dy;
624
32.2k
        tmp += w;
625
32.2k
    } while (--h);
626
1.54k
}
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
6.96k
{
632
6.96k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
633
6.96k
    const int sh = intermediate_bits + 1;
634
6.96k
    const int rnd = (1 << intermediate_bits) + PREP_BIAS * 2;
635
118k
    do {
636
3.89M
        for (int x = 0; x < w; x++)
637
3.77M
            dst[x] = iclip_pixel((tmp1[x] + tmp2[x] + rnd) >> sh);
638
639
118k
        tmp1 += w;
640
118k
        tmp2 += w;
641
118k
        dst += PXSTRIDE(dst_stride);
642
118k
    } while (--h);
643
6.96k
}
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
940
{
649
940
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
650
940
    const int sh = intermediate_bits + 4;
651
940
    const int rnd = (8 << intermediate_bits) + PREP_BIAS * 16;
652
9.75k
    do {
653
114k
        for (int x = 0; x < w; x++)
654
104k
            dst[x] = iclip_pixel((tmp1[x] * weight +
655
104k
                                  tmp2[x] * (16 - weight) + rnd) >> sh);
656
657
9.75k
        tmp1 += w;
658
9.75k
        tmp2 += w;
659
9.75k
        dst += PXSTRIDE(dst_stride);
660
9.75k
    } while (--h);
661
940
}
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
1.41k
{
667
1.41k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
668
1.41k
    const int sh = intermediate_bits + 6;
669
1.41k
    const int rnd = (32 << intermediate_bits) + PREP_BIAS * 64;
670
17.4k
    do {
671
379k
        for (int x = 0; x < w; x++)
672
361k
            dst[x] = iclip_pixel((tmp1[x] * mask[x] +
673
361k
                                  tmp2[x] * (64 - mask[x]) + rnd) >> sh);
674
675
17.4k
        tmp1 += w;
676
17.4k
        tmp2 += w;
677
17.4k
        mask += w;
678
17.4k
        dst += PXSTRIDE(dst_stride);
679
17.4k
    } while (--h);
680
1.41k
}
681
682
1.88M
#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
3.35k
{
686
37.0k
    do {
687
514k
        for (int x = 0; x < w; x++) {
688
477k
            dst[x] = blend_px(dst[x], tmp[x], mask[x]);
689
477k
        }
690
37.0k
        dst += PXSTRIDE(dst_stride);
691
37.0k
        tmp += w;
692
37.0k
        mask += w;
693
37.0k
    } while (--h);
694
3.35k
}
695
696
static void blend_v_c(pixel *dst, const ptrdiff_t dst_stride, const pixel *tmp,
697
                      const int w, int h)
698
15.2k
{
699
15.2k
    const uint8_t *const mask = &dav1d_obmc_masks[w];
700
137k
    do {
701
869k
        for (int x = 0; x < (w * 3) >> 2; x++) {
702
731k
            dst[x] = blend_px(dst[x], tmp[x], mask[x]);
703
731k
        }
704
137k
        dst += PXSTRIDE(dst_stride);
705
137k
        tmp += w;
706
137k
    } while (--h);
707
15.2k
}
708
709
static void blend_h_c(pixel *dst, const ptrdiff_t dst_stride, const pixel *tmp,
710
                      const int w, int h)
711
11.6k
{
712
11.6k
    const uint8_t *mask = &dav1d_obmc_masks[h];
713
11.6k
    h = (h * 3) >> 2;
714
53.8k
    do {
715
53.8k
        const int m = *mask++;
716
728k
        for (int x = 0; x < w; x++) {
717
674k
            dst[x] = blend_px(dst[x], tmp[x], m);
718
674k
        }
719
53.8k
        dst += PXSTRIDE(dst_stride);
720
53.8k
        tmp += w;
721
53.8k
    } while (--h);
722
11.6k
}
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
466
{
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
466
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
732
466
    const int bitdepth = bitdepth_from_max(bitdepth_max);
733
466
    const int sh = intermediate_bits + 6;
734
466
    const int rnd = (32 << intermediate_bits) + PREP_BIAS * 64;
735
466
    const int mask_sh = bitdepth + intermediate_bits - 4;
736
466
    const int mask_rnd = 1 << (mask_sh - 5);
737
14.6k
    do {
738
671k
        for (int x = 0; x < w; x++) {
739
657k
            const int tmpdiff = tmp1[x] - tmp2[x];
740
657k
            const int m = imin(38 + ((abs(tmpdiff) + mask_rnd) >> mask_sh), 64);
741
657k
            dst[x] = iclip_pixel((tmpdiff * m + tmp2[x] * 64 + rnd) >> sh);
742
743
657k
            if (ss_hor) {
744
169k
                x++;
745
746
169k
                const int tmpdiff = tmp1[x] - tmp2[x];
747
169k
                const int n = imin(38 + ((abs(tmpdiff) + mask_rnd) >> mask_sh), 64);
748
169k
                dst[x] = iclip_pixel((tmpdiff * n + tmp2[x] * 64 + rnd) >> sh);
749
750
169k
                if (h & ss_ver) {
751
80.7k
                    mask[x >> 1] = (m + n + mask[x >> 1] + 2 - sign) >> 2;
752
89.1k
                } else if (ss_ver) {
753
80.7k
                    mask[x >> 1] = m + n;
754
80.7k
                } else {
755
8.38k
                    mask[x >> 1] = (m + n + 1 - sign) >> 1;
756
8.38k
                }
757
487k
            } else {
758
487k
                mask[x] = m;
759
487k
            }
760
657k
        }
761
762
14.6k
        tmp1 += w;
763
14.6k
        tmp2 += w;
764
14.6k
        dst += PXSTRIDE(dst_stride);
765
14.6k
        if (!ss_ver || (h & 1)) mask += w >> ss_hor;
766
14.6k
    } while (--h);
767
466
}
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
466
                             const int sign HIGHBD_DECL_SUFFIX) \
774
466
{ \
775
466
    w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver \
776
466
             HIGHBD_TAIL_SUFFIX); \
777
466
}
mc_tmpl.c:w_mask_444_c
Line
Count
Source
773
210
                             const int sign HIGHBD_DECL_SUFFIX) \
774
210
{ \
775
210
    w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver \
776
210
             HIGHBD_TAIL_SUFFIX); \
777
210
}
mc_tmpl.c:w_mask_422_c
Line
Count
Source
773
6
                             const int sign HIGHBD_DECL_SUFFIX) \
774
6
{ \
775
6
    w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver \
776
6
             HIGHBD_TAIL_SUFFIX); \
777
6
}
mc_tmpl.c:w_mask_420_c
Line
Count
Source
773
250
                             const int sign HIGHBD_DECL_SUFFIX) \
774
250
{ \
775
250
    w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver \
776
250
             HIGHBD_TAIL_SUFFIX); \
777
250
}
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
5.29M
    ((F[0] * src[x - 3 * stride] + \
787
5.29M
      F[1] * src[x - 2 * stride] + \
788
5.29M
      F[2] * src[x - 1 * stride] + \
789
5.29M
      F[3] * src[x + 0 * stride] + \
790
5.29M
      F[4] * src[x + 1 * stride] + \
791
5.29M
      F[5] * src[x + 2 * stride] + \
792
5.29M
      F[6] * src[x + 3 * stride] + \
793
5.29M
      F[7] * src[x + 4 * stride] + \
794
5.29M
      ((1 << (sh)) >> 1)) >> (sh))
795
796
#define FILTER_WARP_CLIP(src, x, F, stride, sh) \
797
1.57M
    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
24.7k
{
804
24.7k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
805
24.7k
    int16_t mid[15 * 8], *mid_ptr = mid;
806
807
24.7k
    src -= 3 * PXSTRIDE(src_stride);
808
394k
    for (int y = 0; y < 15; y++, mx += abcd[1]) {
809
3.33M
        for (int x = 0, tmx = mx; x < 8; x++, tmx += abcd[0]) {
810
2.95M
            const int8_t *const filter =
811
2.95M
                dav1d_mc_warp_filter[64 + ((tmx + 512) >> 10)];
812
813
2.95M
            mid_ptr[x] = FILTER_WARP_RND(src, x, filter, 1,
814
2.95M
                                         7 - intermediate_bits);
815
2.95M
        }
816
370k
        src += PXSTRIDE(src_stride);
817
370k
        mid_ptr += 8;
818
370k
    }
819
820
24.7k
    mid_ptr = &mid[3 * 8];
821
222k
    for (int y = 0; y < 8; y++, my += abcd[3]) {
822
1.77M
        for (int x = 0, tmy = my; x < 8; x++, tmy += abcd[2]) {
823
1.57M
            const int8_t *const filter =
824
1.57M
                dav1d_mc_warp_filter[64 + ((tmy + 512) >> 10)];
825
826
1.57M
            dst[x] = FILTER_WARP_CLIP(mid_ptr, x, filter, 8,
827
1.57M
                                      7 + intermediate_bits);
828
1.57M
        }
829
197k
        mid_ptr += 8;
830
197k
        dst += PXSTRIDE(dst_stride);
831
197k
    }
832
24.7k
}
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
4.09k
{
839
4.09k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
840
4.09k
    int16_t mid[15 * 8], *mid_ptr = mid;
841
842
4.09k
    src -= 3 * PXSTRIDE(src_stride);
843
65.5k
    for (int y = 0; y < 15; y++, mx += abcd[1]) {
844
553k
        for (int x = 0, tmx = mx; x < 8; x++, tmx += abcd[0]) {
845
491k
            const int8_t *const filter =
846
491k
                dav1d_mc_warp_filter[64 + ((tmx + 512) >> 10)];
847
848
491k
            mid_ptr[x] = FILTER_WARP_RND(src, x, filter, 1,
849
491k
                                         7 - intermediate_bits);
850
491k
        }
851
61.4k
        src += PXSTRIDE(src_stride);
852
61.4k
        mid_ptr += 8;
853
61.4k
    }
854
855
4.09k
    mid_ptr = &mid[3 * 8];
856
36.8k
    for (int y = 0; y < 8; y++, my += abcd[3]) {
857
294k
        for (int x = 0, tmy = my; x < 8; x++, tmy += abcd[2]) {
858
262k
            const int8_t *const filter =
859
262k
                dav1d_mc_warp_filter[64 + ((tmy + 512) >> 10)];
860
861
262k
            tmp[x] = FILTER_WARP_RND(mid_ptr, x, filter, 8, 7) - PREP_BIAS;
862
262k
        }
863
32.7k
        mid_ptr += 8;
864
32.7k
        tmp += tmp_stride;
865
32.7k
    }
866
4.09k
}
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
84.7k
{
874
    // find offset in reference of visible block to copy
875
84.7k
    ref += iclip((int) y, 0, (int) ih - 1) * PXSTRIDE(ref_stride) +
876
84.7k
           iclip((int) x, 0, (int) iw - 1);
877
878
    // number of pixels to extend (left, right, top, bottom)
879
84.7k
    const int left_ext = iclip((int) -x, 0, (int) bw - 1);
880
84.7k
    const int right_ext = iclip((int) (x + bw - iw), 0, (int) bw - 1);
881
84.7k
    assert(left_ext + right_ext < bw);
882
84.7k
    const int top_ext = iclip((int) -y, 0, (int) bh - 1);
883
84.7k
    const int bottom_ext = iclip((int) (y + bh - ih), 0, (int) bh - 1);
884
84.7k
    assert(top_ext + bottom_ext < bh);
885
886
    // copy visible portion first
887
84.7k
    pixel *blk = dst + top_ext * PXSTRIDE(dst_stride);
888
84.7k
    const int center_w = (int) (bw - left_ext - right_ext);
889
84.7k
    const int center_h = (int) (bh - top_ext - bottom_ext);
890
1.06M
    for (int y = 0; y < center_h; y++) {
891
977k
        pixel_copy(blk + left_ext, ref, center_w);
892
        // extend left edge for this line
893
977k
        if (left_ext)
894
222k
            pixel_set(blk, blk[left_ext], left_ext);
895
        // extend right edge for this line
896
977k
        if (right_ext)
897
522k
            pixel_set(blk + left_ext + center_w, blk[left_ext + center_w - 1],
898
522k
                      right_ext);
899
977k
        ref += PXSTRIDE(ref_stride);
900
977k
        blk += PXSTRIDE(dst_stride);
901
977k
    }
902
903
    // copy top
904
84.7k
    blk = dst + top_ext * PXSTRIDE(dst_stride);
905
167k
    for (int y = 0; y < top_ext; y++) {
906
82.9k
        pixel_copy(dst, blk, bw);
907
82.9k
        dst += PXSTRIDE(dst_stride);
908
82.9k
    }
909
910
    // copy bottom
911
84.7k
    dst += center_h * PXSTRIDE(dst_stride);
912
403k
    for (int y = 0; y < bottom_ext; y++) {
913
318k
        pixel_copy(dst, &dst[-PXSTRIDE(dst_stride)], bw);
914
318k
        dst += PXSTRIDE(dst_stride);
915
318k
    }
916
84.7k
}
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
40.0k
{
923
1.78M
    do {
924
1.78M
        int mx = mx0, src_x = -1;
925
200M
        for (int x = 0; x < dst_w; x++) {
926
198M
            const int8_t *const F = dav1d_resize_filter[mx >> 8];
927
198M
            dst[x] = iclip_pixel((-(F[0] * src[iclip(src_x - 3, 0, src_w - 1)] +
928
198M
                                    F[1] * src[iclip(src_x - 2, 0, src_w - 1)] +
929
198M
                                    F[2] * src[iclip(src_x - 1, 0, src_w - 1)] +
930
198M
                                    F[3] * src[iclip(src_x + 0, 0, src_w - 1)] +
931
198M
                                    F[4] * src[iclip(src_x + 1, 0, src_w - 1)] +
932
198M
                                    F[5] * src[iclip(src_x + 2, 0, src_w - 1)] +
933
198M
                                    F[6] * src[iclip(src_x + 3, 0, src_w - 1)] +
934
198M
                                    F[7] * src[iclip(src_x + 4, 0, src_w - 1)]) +
935
198M
                                  64) >> 7);
936
198M
            mx += dx;
937
198M
            src_x += mx >> 14;
938
198M
            mx &= 0x3fff;
939
198M
        }
940
941
1.78M
        dst += PXSTRIDE(dst_stride);
942
1.78M
        src += PXSTRIDE(src_stride);
943
1.78M
    } while (--h);
944
40.0k
}
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
7.52k
COLD void bitfn(dav1d_mc_dsp_init)(Dav1dMCDSPContext *const c) {
961
75.2k
#define init_mc_fns(type, name) do { \
962
75.2k
    c->mc        [type] = put_##name##_c; \
963
75.2k
    c->mc_scaled [type] = put_##name##_scaled_c; \
964
75.2k
    c->mct       [type] = prep_##name##_c; \
965
75.2k
    c->mct_scaled[type] = prep_##name##_scaled_c; \
966
75.2k
} while (0)
967
968
7.52k
    init_mc_fns(FILTER_2D_8TAP_REGULAR,        8tap_regular);
969
7.52k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SMOOTH, 8tap_regular_smooth);
970
7.52k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SHARP,  8tap_regular_sharp);
971
7.52k
    init_mc_fns(FILTER_2D_8TAP_SHARP_REGULAR,  8tap_sharp_regular);
972
7.52k
    init_mc_fns(FILTER_2D_8TAP_SHARP_SMOOTH,   8tap_sharp_smooth);
973
7.52k
    init_mc_fns(FILTER_2D_8TAP_SHARP,          8tap_sharp);
974
7.52k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_REGULAR, 8tap_smooth_regular);
975
7.52k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH,         8tap_smooth);
976
7.52k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_SHARP,   8tap_smooth_sharp);
977
7.52k
    init_mc_fns(FILTER_2D_BILINEAR,            bilin);
978
979
7.52k
    c->avg      = avg_c;
980
7.52k
    c->w_avg    = w_avg_c;
981
7.52k
    c->mask     = mask_c;
982
7.52k
    c->blend    = blend_c;
983
7.52k
    c->blend_v  = blend_v_c;
984
7.52k
    c->blend_h  = blend_h_c;
985
7.52k
    c->w_mask[0] = w_mask_444_c;
986
7.52k
    c->w_mask[1] = w_mask_422_c;
987
7.52k
    c->w_mask[2] = w_mask_420_c;
988
7.52k
    c->warp8x8  = warp_affine_8x8_c;
989
7.52k
    c->warp8x8t = warp_affine_8x8t_c;
990
7.52k
    c->emu_edge = emu_edge_c;
991
7.52k
    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
7.52k
}
dav1d_mc_dsp_init_8bpc
Line
Count
Source
960
3.48k
COLD void bitfn(dav1d_mc_dsp_init)(Dav1dMCDSPContext *const c) {
961
3.48k
#define init_mc_fns(type, name) do { \
962
3.48k
    c->mc        [type] = put_##name##_c; \
963
3.48k
    c->mc_scaled [type] = put_##name##_scaled_c; \
964
3.48k
    c->mct       [type] = prep_##name##_c; \
965
3.48k
    c->mct_scaled[type] = prep_##name##_scaled_c; \
966
3.48k
} while (0)
967
968
3.48k
    init_mc_fns(FILTER_2D_8TAP_REGULAR,        8tap_regular);
969
3.48k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SMOOTH, 8tap_regular_smooth);
970
3.48k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SHARP,  8tap_regular_sharp);
971
3.48k
    init_mc_fns(FILTER_2D_8TAP_SHARP_REGULAR,  8tap_sharp_regular);
972
3.48k
    init_mc_fns(FILTER_2D_8TAP_SHARP_SMOOTH,   8tap_sharp_smooth);
973
3.48k
    init_mc_fns(FILTER_2D_8TAP_SHARP,          8tap_sharp);
974
3.48k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_REGULAR, 8tap_smooth_regular);
975
3.48k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH,         8tap_smooth);
976
3.48k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_SHARP,   8tap_smooth_sharp);
977
3.48k
    init_mc_fns(FILTER_2D_BILINEAR,            bilin);
978
979
3.48k
    c->avg      = avg_c;
980
3.48k
    c->w_avg    = w_avg_c;
981
3.48k
    c->mask     = mask_c;
982
3.48k
    c->blend    = blend_c;
983
3.48k
    c->blend_v  = blend_v_c;
984
3.48k
    c->blend_h  = blend_h_c;
985
3.48k
    c->w_mask[0] = w_mask_444_c;
986
3.48k
    c->w_mask[1] = w_mask_422_c;
987
3.48k
    c->w_mask[2] = w_mask_420_c;
988
3.48k
    c->warp8x8  = warp_affine_8x8_c;
989
3.48k
    c->warp8x8t = warp_affine_8x8t_c;
990
3.48k
    c->emu_edge = emu_edge_c;
991
3.48k
    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
3.48k
}
dav1d_mc_dsp_init_16bpc
Line
Count
Source
960
4.04k
COLD void bitfn(dav1d_mc_dsp_init)(Dav1dMCDSPContext *const c) {
961
4.04k
#define init_mc_fns(type, name) do { \
962
4.04k
    c->mc        [type] = put_##name##_c; \
963
4.04k
    c->mc_scaled [type] = put_##name##_scaled_c; \
964
4.04k
    c->mct       [type] = prep_##name##_c; \
965
4.04k
    c->mct_scaled[type] = prep_##name##_scaled_c; \
966
4.04k
} while (0)
967
968
4.04k
    init_mc_fns(FILTER_2D_8TAP_REGULAR,        8tap_regular);
969
4.04k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SMOOTH, 8tap_regular_smooth);
970
4.04k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SHARP,  8tap_regular_sharp);
971
4.04k
    init_mc_fns(FILTER_2D_8TAP_SHARP_REGULAR,  8tap_sharp_regular);
972
4.04k
    init_mc_fns(FILTER_2D_8TAP_SHARP_SMOOTH,   8tap_sharp_smooth);
973
4.04k
    init_mc_fns(FILTER_2D_8TAP_SHARP,          8tap_sharp);
974
4.04k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_REGULAR, 8tap_smooth_regular);
975
4.04k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH,         8tap_smooth);
976
4.04k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_SHARP,   8tap_smooth_sharp);
977
4.04k
    init_mc_fns(FILTER_2D_BILINEAR,            bilin);
978
979
4.04k
    c->avg      = avg_c;
980
4.04k
    c->w_avg    = w_avg_c;
981
4.04k
    c->mask     = mask_c;
982
4.04k
    c->blend    = blend_c;
983
4.04k
    c->blend_v  = blend_v_c;
984
4.04k
    c->blend_h  = blend_h_c;
985
4.04k
    c->w_mask[0] = w_mask_444_c;
986
4.04k
    c->w_mask[1] = w_mask_422_c;
987
4.04k
    c->w_mask[2] = w_mask_420_c;
988
4.04k
    c->warp8x8  = warp_affine_8x8_c;
989
4.04k
    c->warp8x8t = warp_affine_8x8t_c;
990
4.04k
    c->emu_edge = emu_edge_c;
991
4.04k
    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
4.04k
}