Coverage Report

Created: 2026-10-28 06:18

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/dav1d/src/mc_tmpl.c
Line
Count
Source
1
/*
2
 * Copyright © 2018, VideoLAN and dav1d authors
3
 * Copyright © 2018, Two Orioles, LLC
4
 * All rights reserved.
5
 *
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions are met:
8
 *
9
 * 1. Redistributions of source code must retain the above copyright notice, this
10
 *    list of conditions and the following disclaimer.
11
 *
12
 * 2. Redistributions in binary form must reproduce the above copyright notice,
13
 *    this list of conditions and the following disclaimer in the documentation
14
 *    and/or other materials provided with the distribution.
15
 *
16
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
 */
27
28
#include "config.h"
29
30
#include <stdlib.h>
31
#include <string.h>
32
33
#include "common/attributes.h"
34
#include "common/intops.h"
35
36
#include "src/mc.h"
37
#include "src/tables.h"
38
39
#if BITDEPTH == 8
40
1.10M
#define get_intermediate_bits(bitdepth_max) 4
41
// Output in interval [-5132, 9212], fits in int16_t as is
42
28.9M
#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
389k
{
55
5.85M
    do {
56
5.85M
        pixel_copy(dst, src, w);
57
58
5.85M
        dst += dst_stride;
59
5.85M
        src += src_stride;
60
5.85M
    } while (--h);
61
389k
}
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
11.2k
{
67
11.2k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
68
199k
    do {
69
6.01M
        for (int x = 0; x < w; x++)
70
5.82M
            tmp[x] = (src[x] << intermediate_bits) - PREP_BIAS;
71
72
199k
        tmp += w;
73
199k
        src += src_stride;
74
199k
    } while (--h);
75
11.2k
}
76
77
#define FILTER_8TAP(src, x, F, stride) \
78
44.6M
    (F[0] * src[x + -3 * stride] + \
79
44.6M
     F[1] * src[x + -2 * stride] + \
80
44.6M
     F[2] * src[x + -1 * stride] + \
81
44.6M
     F[3] * src[x + +0 * stride] + \
82
44.6M
     F[4] * src[x + +1 * stride] + \
83
44.6M
     F[5] * src[x + +2 * stride] + \
84
44.6M
     F[6] * src[x + +3 * stride] + \
85
44.6M
     F[7] * src[x + +4 * stride])
86
87
#define FILTER_8TAP2(src, x, F) \
88
29.0M
    (F[0] * src[0][x] + \
89
29.0M
     F[1] * src[1][x] + \
90
29.0M
     F[2] * src[2][x] + \
91
29.0M
     F[3] * src[3][x] + \
92
29.0M
     F[4] * src[4][x] + \
93
29.0M
     F[5] * src[5][x] + \
94
29.0M
     F[6] * src[6][x] + \
95
29.0M
     F[7] * src[7][x])
96
97
#define DAV1D_FILTER_8TAP_RND(src, x, F, stride, sh) \
98
41.2M
    ((FILTER_8TAP(src, x, F, stride) + ((1 << (sh)) >> 1)) >> (sh))
99
100
#define DAV1D_FILTER_8TAP_RND2(src, x, F, stride, rnd, sh) \
101
3.44M
    ((FILTER_8TAP(src, x, F, stride) + (rnd)) >> (sh))
102
103
#define DAV1D_FILTER_8TAP_RND3(src, x, F, sh) \
104
29.0M
    ((FILTER_8TAP2(src, x, F) + ((1 << (sh)) >> 1)) >> (sh))
105
106
#define DAV1D_FILTER_8TAP_CLIP(src, x, F, stride, sh) \
107
8.38M
    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
3.44M
    iclip_pixel(DAV1D_FILTER_8TAP_RND2(src, x, F, stride, rnd, sh))
111
112
#define DAV1D_FILTER_8TAP_CLIP3(src, x, F, sh) \
113
18.3M
    iclip_pixel(DAV1D_FILTER_8TAP_RND3(src, x, F, sh))
114
115
#define GET_H_FILTER(mx) \
116
21.0M
    const int8_t *const fh = !(mx) ? NULL : w > 4 ? \
117
19.1M
        dav1d_mc_subpel_filters[filter_type & 3][(mx) - 1] : \
118
19.1M
        dav1d_mc_subpel_filters[3 + (filter_type & 1)][(mx) - 1]
119
120
#define GET_V_FILTER(my) \
121
1.05M
    const int8_t *const fv = !(my) ? NULL : h > 4 ? \
122
931k
        dav1d_mc_subpel_filters[filter_type >> 2][(my) - 1] : \
123
931k
        dav1d_mc_subpel_filters[3 + ((filter_type >> 2) & 1)][(my) - 1]
124
125
#define GET_FILTERS() \
126
64.6k
    GET_H_FILTER(mx); \
127
64.6k
    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
42.5k
{
135
42.5k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
136
42.5k
    const int intermediate_rnd = 32 + ((1 << (6 - intermediate_bits)) >> 1);
137
138
42.5k
    GET_FILTERS();
139
42.5k
    dst_stride = PXSTRIDE(dst_stride);
140
42.5k
    src_stride = PXSTRIDE(src_stride);
141
142
42.5k
    if (fh) {
143
21.0k
        if (fv) {
144
15.1k
            int tmp_h = h + 7;
145
15.1k
            int16_t mid[128 * 135], *mid_ptr = mid;
146
147
15.1k
            src -= src_stride * 3;
148
270k
            do {
149
5.46M
                for (int x = 0; x < w; x++)
150
5.19M
                    mid_ptr[x] = DAV1D_FILTER_8TAP_RND(src, x, fh, 1,
151
270k
                                                       6 - intermediate_bits);
152
153
270k
                mid_ptr += 128;
154
270k
                src += src_stride;
155
270k
            } while (--tmp_h);
156
157
15.1k
            mid_ptr = mid + 128 * 3;
158
165k
            do {
159
4.22M
                for (int x = 0; x < w; x++)
160
4.06M
                    dst[x] = DAV1D_FILTER_8TAP_CLIP(mid_ptr, x, fv, 128,
161
165k
                                                    6 + intermediate_bits);
162
163
165k
                mid_ptr += 128;
164
165k
                dst += dst_stride;
165
165k
            } while (--h);
166
15.1k
        } else {
167
101k
            do {
168
3.54M
                for (int x = 0; x < w; x++) {
169
3.44M
                    dst[x] = DAV1D_FILTER_8TAP_CLIP2(src, x, fh, 1,
170
3.44M
                                                     intermediate_rnd, 6);
171
3.44M
                }
172
173
101k
                dst += dst_stride;
174
101k
                src += src_stride;
175
101k
            } while (--h);
176
5.82k
        }
177
21.5k
    } else if (fv) {
178
111k
        do {
179
4.44M
            for (int x = 0; x < w; x++)
180
4.32M
                dst[x] = DAV1D_FILTER_8TAP_CLIP(src, x, fv, src_stride, 6);
181
182
111k
            dst += dst_stride;
183
111k
            src += src_stride;
184
111k
        } while (--h);
185
6.30k
    } else
186
15.2k
        put_c(dst, dst_stride, src, src_stride, w, h);
187
42.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
45.3k
{
196
45.3k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
197
45.3k
    const int intermediate_rnd = (1 << intermediate_bits) >> 1;
198
45.3k
    int16_t mid[128 * 8];
199
45.3k
    int16_t *mid_ptrs[8];
200
45.3k
    int in_y = -8;
201
45.3k
    src_stride = PXSTRIDE(src_stride);
202
203
408k
    for (int i = 0; i < 8; i++)
204
362k
        mid_ptrs[i] = &mid[128 * i];
205
206
45.3k
    src -= src_stride * 3;
207
208
684k
    for (int y = 0; y < h; y++) {
209
639k
        int x;
210
639k
        int src_y = my >> 10;
211
639k
        GET_V_FILTER((my & 0x3ff) >> 6);
212
213
1.31M
        while (in_y < src_y) {
214
671k
            int imx = mx, ioff = 0;
215
671k
            int16_t *mid_ptr = mid_ptrs[0];
216
217
5.36M
            for (int i = 0; i < 7; i++)
218
4.69M
                mid_ptrs[i] = mid_ptrs[i + 1];
219
671k
            mid_ptrs[7] = mid_ptr;
220
221
14.8M
            for (x = 0; x < w; x++) {
222
14.2M
                GET_H_FILTER(imx >> 6);
223
14.2M
                mid_ptr[x] = fh ? DAV1D_FILTER_8TAP_RND(src, ioff, fh, 1,
224
14.2M
                                                        6 - intermediate_bits) :
225
14.2M
                                  src[ioff] << intermediate_bits;
226
14.2M
                imx += dx;
227
14.2M
                ioff += imx >> 10;
228
14.2M
                imx &= 0x3ff;
229
14.2M
            }
230
231
671k
            src += src_stride;
232
671k
            in_y++;
233
671k
        }
234
235
21.9M
        for (x = 0; x < w; x++)
236
21.2M
            dst[x] = fv ? DAV1D_FILTER_8TAP_CLIP3(mid_ptrs, x, fv,
237
21.2M
                                                  6 + intermediate_bits) :
238
21.2M
                          iclip_pixel((mid_ptrs[3][x] + intermediate_rnd) >>
239
2.92M
                                              intermediate_bits);
240
241
639k
        my += dy;
242
639k
        dst += PXSTRIDE(dst_stride);
243
639k
    }
244
45.3k
}
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
22.0k
{
251
22.0k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
252
22.0k
    GET_FILTERS();
253
22.0k
    src_stride = PXSTRIDE(src_stride);
254
255
22.0k
    if (fh) {
256
8.95k
        if (fv) {
257
6.12k
            int tmp_h = h + 7;
258
6.12k
            int16_t mid[128 * 135], *mid_ptr = mid;
259
260
6.12k
            src -= src_stride * 3;
261
138k
            do {
262
3.29M
                for (int x = 0; x < w; x++)
263
3.15M
                    mid_ptr[x] = DAV1D_FILTER_8TAP_RND(src, x, fh, 1,
264
138k
                                                       6 - intermediate_bits);
265
266
138k
                mid_ptr += 128;
267
138k
                src += src_stride;
268
138k
            } while (--tmp_h);
269
270
6.12k
            mid_ptr = mid + 128 * 3;
271
95.5k
            do {
272
2.59M
                for (int x = 0; x < w; x++) {
273
2.49M
                    int t = DAV1D_FILTER_8TAP_RND(mid_ptr, x, fv, 128, 6) -
274
2.49M
                                  PREP_BIAS;
275
2.49M
                    assert(t >= INT16_MIN && t <= INT16_MAX);
276
2.49M
                    tmp[x] = t;
277
2.49M
                }
278
279
95.5k
                mid_ptr += 128;
280
95.5k
                tmp += w;
281
95.5k
            } while (--h);
282
6.12k
        } else {
283
58.6k
            do {
284
1.36M
                for (int x = 0; x < w; x++)
285
1.30M
                    tmp[x] = DAV1D_FILTER_8TAP_RND(src, x, fh, 1,
286
1.30M
                                                   6 - intermediate_bits) -
287
1.30M
                             PREP_BIAS;
288
289
58.6k
                tmp += w;
290
58.6k
                src += src_stride;
291
58.6k
            } while (--h);
292
2.83k
        }
293
13.1k
    } else if (fv) {
294
69.3k
        do {
295
1.61M
            for (int x = 0; x < w; x++)
296
1.54M
                tmp[x] = DAV1D_FILTER_8TAP_RND(src, x, fv, src_stride,
297
1.54M
                                               6 - intermediate_bits) -
298
1.54M
                         PREP_BIAS;
299
300
69.3k
            tmp += w;
301
69.3k
            src += src_stride;
302
69.3k
        } while (--h);
303
3.31k
    } else
304
9.82k
        prep_c(tmp, src, src_stride, w, h HIGHBD_TAIL_SUFFIX);
305
22.0k
}
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
16.7k
{
313
16.7k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
314
16.7k
    int16_t mid[128 * 8];
315
16.7k
    int16_t *mid_ptrs[8];
316
16.7k
    int in_y = -8;
317
16.7k
    src_stride = PXSTRIDE(src_stride);
318
319
150k
    for (int i = 0; i < 8; i++)
320
133k
        mid_ptrs[i] = &mid[128 * i];
321
322
16.7k
    src -= src_stride * 3;
323
324
370k
    for (int y = 0; y < h; y++) {
325
353k
        int x;
326
353k
        int src_y = my >> 10;
327
353k
        GET_V_FILTER((my & 0x3ff) >> 6);
328
329
647k
        while (in_y < src_y) {
330
294k
            int imx = mx, ioff = 0;
331
294k
            int16_t *mid_ptr = mid_ptrs[0];
332
333
2.35M
            for (int i = 0; i < 7; i++)
334
2.06M
                mid_ptrs[i] = mid_ptrs[i + 1];
335
294k
            mid_ptrs[7] = mid_ptr;
336
337
7.02M
            for (x = 0; x < w; x++) {
338
6.72M
                GET_H_FILTER(imx >> 6);
339
6.72M
                mid_ptr[x] = fh ? DAV1D_FILTER_8TAP_RND(src, ioff, fh, 1,
340
6.72M
                                                        6 - intermediate_bits) :
341
6.72M
                                  src[ioff] << intermediate_bits;
342
6.72M
                imx += dx;
343
6.72M
                ioff += imx >> 10;
344
6.72M
                imx &= 0x3ff;
345
6.72M
            }
346
347
294k
            src += src_stride;
348
294k
            in_y++;
349
294k
        }
350
351
12.2M
        for (x = 0; x < w; x++)
352
11.8M
            tmp[x] = (fv ? DAV1D_FILTER_8TAP_RND3(mid_ptrs, x, fv, 6)
353
11.8M
                         : mid_ptrs[3][x]) - PREP_BIAS;
354
355
353k
        my += dy;
356
353k
        tmp += w;
357
353k
    }
358
16.7k
}
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
42.5k
                                HIGHBD_DECL_SUFFIX) \
368
42.5k
{ \
369
42.5k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
42.5k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
42.5k
} \
mc_tmpl.c:put_8tap_regular_c
Line
Count
Source
367
16.5k
                                HIGHBD_DECL_SUFFIX) \
368
16.5k
{ \
369
16.5k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
16.5k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
16.5k
} \
mc_tmpl.c:put_8tap_regular_smooth_c
Line
Count
Source
367
1.40k
                                HIGHBD_DECL_SUFFIX) \
368
1.40k
{ \
369
1.40k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
1.40k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
1.40k
} \
mc_tmpl.c:put_8tap_regular_sharp_c
Line
Count
Source
367
466
                                HIGHBD_DECL_SUFFIX) \
368
466
{ \
369
466
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
466
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
466
} \
mc_tmpl.c:put_8tap_sharp_regular_c
Line
Count
Source
367
614
                                HIGHBD_DECL_SUFFIX) \
368
614
{ \
369
614
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
614
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
614
} \
mc_tmpl.c:put_8tap_sharp_smooth_c
Line
Count
Source
367
239
                                HIGHBD_DECL_SUFFIX) \
368
239
{ \
369
239
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
239
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
239
} \
mc_tmpl.c:put_8tap_sharp_c
Line
Count
Source
367
11.4k
                                HIGHBD_DECL_SUFFIX) \
368
11.4k
{ \
369
11.4k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
11.4k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
11.4k
} \
mc_tmpl.c:put_8tap_smooth_regular_c
Line
Count
Source
367
1.31k
                                HIGHBD_DECL_SUFFIX) \
368
1.31k
{ \
369
1.31k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
1.31k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
1.31k
} \
mc_tmpl.c:put_8tap_smooth_c
Line
Count
Source
367
10.2k
                                HIGHBD_DECL_SUFFIX) \
368
10.2k
{ \
369
10.2k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
10.2k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
10.2k
} \
mc_tmpl.c:put_8tap_smooth_sharp_c
Line
Count
Source
367
382
                                HIGHBD_DECL_SUFFIX) \
368
382
{ \
369
382
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
382
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
382
} \
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
45.3k
                                       HIGHBD_DECL_SUFFIX) \
380
45.3k
{ \
381
45.3k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
45.3k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
45.3k
} \
mc_tmpl.c:put_8tap_regular_scaled_c
Line
Count
Source
379
35.2k
                                       HIGHBD_DECL_SUFFIX) \
380
35.2k
{ \
381
35.2k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
35.2k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
35.2k
} \
mc_tmpl.c:put_8tap_regular_smooth_scaled_c
Line
Count
Source
379
703
                                       HIGHBD_DECL_SUFFIX) \
380
703
{ \
381
703
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
703
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
703
} \
mc_tmpl.c:put_8tap_regular_sharp_scaled_c
Line
Count
Source
379
195
                                       HIGHBD_DECL_SUFFIX) \
380
195
{ \
381
195
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
195
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
195
} \
mc_tmpl.c:put_8tap_sharp_regular_scaled_c
Line
Count
Source
379
111
                                       HIGHBD_DECL_SUFFIX) \
380
111
{ \
381
111
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
111
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
111
} \
mc_tmpl.c:put_8tap_sharp_smooth_scaled_c
Line
Count
Source
379
120
                                       HIGHBD_DECL_SUFFIX) \
380
120
{ \
381
120
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
120
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
120
} \
mc_tmpl.c:put_8tap_sharp_scaled_c
Line
Count
Source
379
1.58k
                                       HIGHBD_DECL_SUFFIX) \
380
1.58k
{ \
381
1.58k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
1.58k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
1.58k
} \
mc_tmpl.c:put_8tap_smooth_regular_scaled_c
Line
Count
Source
379
902
                                       HIGHBD_DECL_SUFFIX) \
380
902
{ \
381
902
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
902
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
902
} \
mc_tmpl.c:put_8tap_smooth_scaled_c
Line
Count
Source
379
6.19k
                                       HIGHBD_DECL_SUFFIX) \
380
6.19k
{ \
381
6.19k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
6.19k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
6.19k
} \
mc_tmpl.c:put_8tap_smooth_sharp_scaled_c
Line
Count
Source
379
324
                                       HIGHBD_DECL_SUFFIX) \
380
324
{ \
381
324
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
324
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
324
} \
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
22.0k
                                 HIGHBD_DECL_SUFFIX) \
390
22.0k
{ \
391
22.0k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
22.0k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
22.0k
} \
mc_tmpl.c:prep_8tap_regular_c
Line
Count
Source
389
11.6k
                                 HIGHBD_DECL_SUFFIX) \
390
11.6k
{ \
391
11.6k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
11.6k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
11.6k
} \
mc_tmpl.c:prep_8tap_regular_smooth_c
Line
Count
Source
389
1.17k
                                 HIGHBD_DECL_SUFFIX) \
390
1.17k
{ \
391
1.17k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
1.17k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
1.17k
} \
mc_tmpl.c:prep_8tap_regular_sharp_c
Line
Count
Source
389
842
                                 HIGHBD_DECL_SUFFIX) \
390
842
{ \
391
842
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
842
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
842
} \
mc_tmpl.c:prep_8tap_sharp_regular_c
Line
Count
Source
389
1.14k
                                 HIGHBD_DECL_SUFFIX) \
390
1.14k
{ \
391
1.14k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
1.14k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
1.14k
} \
mc_tmpl.c:prep_8tap_sharp_smooth_c
Line
Count
Source
389
467
                                 HIGHBD_DECL_SUFFIX) \
390
467
{ \
391
467
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
467
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
467
} \
mc_tmpl.c:prep_8tap_sharp_c
Line
Count
Source
389
3.08k
                                 HIGHBD_DECL_SUFFIX) \
390
3.08k
{ \
391
3.08k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
3.08k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
3.08k
} \
mc_tmpl.c:prep_8tap_smooth_regular_c
Line
Count
Source
389
897
                                 HIGHBD_DECL_SUFFIX) \
390
897
{ \
391
897
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
897
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
897
} \
mc_tmpl.c:prep_8tap_smooth_c
Line
Count
Source
389
2.32k
                                 HIGHBD_DECL_SUFFIX) \
390
2.32k
{ \
391
2.32k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
2.32k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
2.32k
} \
mc_tmpl.c:prep_8tap_smooth_sharp_c
Line
Count
Source
389
517
                                 HIGHBD_DECL_SUFFIX) \
390
517
{ \
391
517
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
517
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
517
} \
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
16.7k
                                        HIGHBD_DECL_SUFFIX) \
401
16.7k
{ \
402
16.7k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
16.7k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
16.7k
}
mc_tmpl.c:prep_8tap_regular_scaled_c
Line
Count
Source
400
9.45k
                                        HIGHBD_DECL_SUFFIX) \
401
9.45k
{ \
402
9.45k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
9.45k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
9.45k
}
mc_tmpl.c:prep_8tap_regular_smooth_scaled_c
Line
Count
Source
400
203
                                        HIGHBD_DECL_SUFFIX) \
401
203
{ \
402
203
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
203
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
203
}
mc_tmpl.c:prep_8tap_regular_sharp_scaled_c
Line
Count
Source
400
181
                                        HIGHBD_DECL_SUFFIX) \
401
181
{ \
402
181
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
181
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
181
}
mc_tmpl.c:prep_8tap_sharp_regular_scaled_c
Line
Count
Source
400
405
                                        HIGHBD_DECL_SUFFIX) \
401
405
{ \
402
405
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
405
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
405
}
mc_tmpl.c:prep_8tap_sharp_smooth_scaled_c
Line
Count
Source
400
132
                                        HIGHBD_DECL_SUFFIX) \
401
132
{ \
402
132
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
132
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
132
}
mc_tmpl.c:prep_8tap_sharp_scaled_c
Line
Count
Source
400
1.51k
                                        HIGHBD_DECL_SUFFIX) \
401
1.51k
{ \
402
1.51k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
1.51k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
1.51k
}
mc_tmpl.c:prep_8tap_smooth_regular_scaled_c
Line
Count
Source
400
479
                                        HIGHBD_DECL_SUFFIX) \
401
479
{ \
402
479
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
479
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
479
}
mc_tmpl.c:prep_8tap_smooth_scaled_c
Line
Count
Source
400
4.19k
                                        HIGHBD_DECL_SUFFIX) \
401
4.19k
{ \
402
4.19k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
4.19k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
4.19k
}
mc_tmpl.c:prep_8tap_smooth_sharp_scaled_c
Line
Count
Source
400
160
                                        HIGHBD_DECL_SUFFIX) \
401
160
{ \
402
160
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
160
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
160
}
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
23.2M
    (16 * src[x] + ((mxy) * (src[x + stride] - src[x])))
418
419
#define FILTER_BILIN_RND(src, x, mxy, stride, sh) \
420
23.2M
    ((FILTER_BILIN(src, x, mxy, stride) + ((1 << (sh)) >> 1)) >> (sh))
421
422
#define FILTER_BILIN_CLIP(src, x, mxy, stride, sh) \
423
7.20M
    iclip_pixel(FILTER_BILIN_RND(src, x, mxy, stride, sh))
424
425
#define FILTER_BILIN2(src1, src2, x, mxy) \
426
4.40M
    (16 * src1[x] + ((mxy) * (src2[x] - src1[x])))
427
428
#define FILTER_BILIN_RND2(src1, src2, x, mxy, sh) \
429
4.40M
    ((FILTER_BILIN2(src1, src2, x, mxy) + ((1 << (sh)) >> 1)) >> (sh))
430
431
#define FILTER_BILIN_CLIP2(src1, src2, x, mxy, sh) \
432
2.53M
    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
537k
{
439
537k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
440
537k
    const int intermediate_rnd = (1 << intermediate_bits) >> 1;
441
537k
    dst_stride = PXSTRIDE(dst_stride);
442
537k
    src_stride = PXSTRIDE(src_stride);
443
444
537k
    if (mx) {
445
104k
        if (my) {
446
43.7k
            int16_t mid[128 * 129], *mid_ptr = mid;
447
43.7k
            int tmp_h = h + 1;
448
449
326k
            do {
450
3.71M
                for (int x = 0; x < w; x++)
451
3.38M
                    mid_ptr[x] = FILTER_BILIN_RND(src, x, mx, 1,
452
326k
                                                  4 - intermediate_bits);
453
454
326k
                mid_ptr += 128;
455
326k
                src += src_stride;
456
326k
            } while (--tmp_h);
457
458
43.7k
            mid_ptr = mid;
459
283k
            do {
460
3.35M
                for (int x = 0; x < w; x++)
461
3.07M
                    dst[x] = FILTER_BILIN_CLIP(mid_ptr, x, my, 128,
462
283k
                                               4 + intermediate_bits);
463
464
283k
                mid_ptr += 128;
465
283k
                dst += dst_stride;
466
283k
            } while (--h);
467
60.4k
        } else {
468
476k
            do {
469
7.35M
                for (int x = 0; x < w; x++) {
470
6.88M
                    const int px = FILTER_BILIN_RND(src, x, mx, 1,
471
6.88M
                                                    4 - intermediate_bits);
472
6.88M
                    dst[x] = iclip_pixel((px + intermediate_rnd) >> intermediate_bits);
473
6.88M
                }
474
475
476k
                dst += dst_stride;
476
476k
                src += src_stride;
477
476k
            } while (--h);
478
60.4k
        }
479
433k
    } else if (my) {
480
421k
        do {
481
4.55M
            for (int x = 0; x < w; x++)
482
4.13M
                dst[x] = FILTER_BILIN_CLIP(src, x, my, src_stride, 4);
483
484
421k
            dst += dst_stride;
485
421k
            src += src_stride;
486
421k
        } while (--h);
487
59.5k
    } else
488
373k
        put_c(dst, dst_stride, src, src_stride, w, h);
489
537k
}
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
13.4k
{
497
13.4k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
498
13.4k
    int16_t mid[128 * 2];
499
13.4k
    int in_y = -2;
500
501
148k
    do {
502
148k
        int x;
503
148k
        int y = my >> 10;
504
148k
        int16_t *mid1 = &mid[(y & 1) * 128];
505
148k
        int16_t *mid2 = &mid[((y + 1) & 1) * 128];
506
148k
        int dmy = my & 0x3ff;
507
508
220k
        while (in_y < y) {
509
71.7k
            int imx = mx, ioff = 0;
510
71.7k
            int16_t *mid_ptr = &mid[(in_y & 1) * 128];
511
512
1.43M
            for (x = 0; x < w; x++) {
513
1.35M
                mid_ptr[x] = FILTER_BILIN_RND(src, ioff, imx >> 6, 1,
514
1.35M
                                              4 - intermediate_bits);
515
1.35M
                imx += dx;
516
1.35M
                ioff += imx >> 10;
517
1.35M
                imx &= 0x3ff;
518
1.35M
            }
519
520
71.7k
            src += PXSTRIDE(src_stride);
521
71.7k
            in_y++;
522
71.7k
        }
523
524
2.68M
        for (x = 0; x < w; x++)
525
2.53M
            dst[x] = FILTER_BILIN_CLIP2(mid1, mid2, x, dmy >> 6,
526
148k
                                       4 + intermediate_bits);
527
528
148k
        my += dy;
529
148k
        dst += PXSTRIDE(dst_stride);
530
148k
    } while (--h);
531
13.4k
}
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.60k
{
538
3.60k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
539
3.60k
    src_stride = PXSTRIDE(src_stride);
540
541
3.60k
    if (mx) {
542
1.40k
        if (my) {
543
948
            int16_t mid[128 * 129], *mid_ptr = mid;
544
948
            int tmp_h = h + 1;
545
546
23.2k
            do {
547
1.21M
                for (int x = 0; x < w; x++)
548
1.19M
                    mid_ptr[x] = FILTER_BILIN_RND(src, x, mx, 1,
549
23.2k
                                                  4 - intermediate_bits);
550
551
23.2k
                mid_ptr += 128;
552
23.2k
                src += src_stride;
553
23.2k
            } while (--tmp_h);
554
555
948
            mid_ptr = mid;
556
22.3k
            do {
557
1.19M
                for (int x = 0; x < w; x++)
558
1.17M
                    tmp[x] = FILTER_BILIN_RND(mid_ptr, x, my, 128, 4) -
559
1.17M
                             PREP_BIAS;
560
561
22.3k
                mid_ptr += 128;
562
22.3k
                tmp += w;
563
22.3k
            } while (--h);
564
948
        } else {
565
11.0k
            do {
566
624k
                for (int x = 0; x < w; x++)
567
613k
                    tmp[x] = FILTER_BILIN_RND(src, x, mx, 1,
568
613k
                                              4 - intermediate_bits) -
569
613k
                             PREP_BIAS;
570
571
11.0k
                tmp += w;
572
11.0k
                src += src_stride;
573
11.0k
            } while (--h);
574
452
        }
575
2.20k
    } else if (my) {
576
16.2k
        do {
577
623k
            for (int x = 0; x < w; x++)
578
607k
                tmp[x] = FILTER_BILIN_RND(src, x, my, src_stride,
579
607k
                                          4 - intermediate_bits) - PREP_BIAS;
580
581
16.2k
            tmp += w;
582
16.2k
            src += src_stride;
583
16.2k
        } while (--h);
584
827
    } else
585
1.38k
        prep_c(tmp, src, src_stride, w, h HIGHBD_TAIL_SUFFIX);
586
3.60k
}
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
8.82k
{
593
8.82k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
594
8.82k
    int16_t mid[128 * 2];
595
8.82k
    int in_y = -2;
596
597
117k
    do {
598
117k
        int x;
599
117k
        int y = my >> 10;
600
117k
        int16_t *mid1 = &mid[(y & 1) * 128];
601
117k
        int16_t *mid2 = &mid[((y + 1) & 1) * 128];
602
117k
        int dmy = my & 0x3ff;
603
604
169k
        while (in_y < y) {
605
51.3k
            int imx = mx, ioff = 0;
606
51.3k
            int16_t *mid_ptr = &mid[(in_y & 1) * 128];
607
608
890k
            for (x = 0; x < w; x++) {
609
839k
                mid_ptr[x] = FILTER_BILIN_RND(src, ioff, imx >> 6, 1,
610
839k
                                              4 - intermediate_bits);
611
839k
                imx += dx;
612
839k
                ioff += imx >> 10;
613
839k
                imx &= 0x3ff;
614
839k
            }
615
616
51.3k
            src += PXSTRIDE(src_stride);
617
51.3k
            in_y++;
618
51.3k
        }
619
620
1.98M
        for (x = 0; x < w; x++)
621
1.86M
            tmp[x] = FILTER_BILIN_RND2(mid1, mid2, x, dmy >> 6, 4) - PREP_BIAS;
622
623
117k
        my += dy;
624
117k
        tmp += w;
625
117k
    } while (--h);
626
8.82k
}
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
20.5k
{
632
20.5k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
633
20.5k
    const int sh = intermediate_bits + 1;
634
20.5k
    const int rnd = (1 << intermediate_bits) + PREP_BIAS * 2;
635
361k
    do {
636
10.2M
        for (int x = 0; x < w; x++)
637
9.92M
            dst[x] = iclip_pixel((tmp1[x] + tmp2[x] + rnd) >> sh);
638
639
361k
        tmp1 += w;
640
361k
        tmp2 += w;
641
361k
        dst += PXSTRIDE(dst_stride);
642
361k
    } while (--h);
643
20.5k
}
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
855
{
649
855
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
650
855
    const int sh = intermediate_bits + 4;
651
855
    const int rnd = (8 << intermediate_bits) + PREP_BIAS * 16;
652
30.8k
    do {
653
1.90M
        for (int x = 0; x < w; x++)
654
1.87M
            dst[x] = iclip_pixel((tmp1[x] * weight +
655
1.87M
                                  tmp2[x] * (16 - weight) + rnd) >> sh);
656
657
30.8k
        tmp1 += w;
658
30.8k
        tmp2 += w;
659
30.8k
        dst += PXSTRIDE(dst_stride);
660
30.8k
    } while (--h);
661
855
}
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
3.31k
{
667
3.31k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
668
3.31k
    const int sh = intermediate_bits + 6;
669
3.31k
    const int rnd = (32 << intermediate_bits) + PREP_BIAS * 64;
670
53.9k
    do {
671
1.16M
        for (int x = 0; x < w; x++)
672
1.11M
            dst[x] = iclip_pixel((tmp1[x] * mask[x] +
673
1.11M
                                  tmp2[x] * (64 - mask[x]) + rnd) >> sh);
674
675
53.9k
        tmp1 += w;
676
53.9k
        tmp2 += w;
677
53.9k
        mask += w;
678
53.9k
        dst += PXSTRIDE(dst_stride);
679
53.9k
    } while (--h);
680
3.31k
}
681
682
1.91M
#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
4.58k
{
686
52.6k
    do {
687
799k
        for (int x = 0; x < w; x++) {
688
746k
            dst[x] = blend_px(dst[x], tmp[x], mask[x]);
689
746k
        }
690
52.6k
        dst += PXSTRIDE(dst_stride);
691
52.6k
        tmp += w;
692
52.6k
        mask += w;
693
52.6k
    } while (--h);
694
4.58k
}
695
696
static void blend_v_c(pixel *dst, const ptrdiff_t dst_stride, const pixel *tmp,
697
                      const int w, int h)
698
10.7k
{
699
10.7k
    const uint8_t *const mask = &dav1d_obmc_masks[w];
700
116k
    do {
701
753k
        for (int x = 0; x < (w * 3) >> 2; x++) {
702
637k
            dst[x] = blend_px(dst[x], tmp[x], mask[x]);
703
637k
        }
704
116k
        dst += PXSTRIDE(dst_stride);
705
116k
        tmp += w;
706
116k
    } while (--h);
707
10.7k
}
708
709
static void blend_h_c(pixel *dst, const ptrdiff_t dst_stride, const pixel *tmp,
710
                      const int w, int h)
711
9.10k
{
712
9.10k
    const uint8_t *mask = &dav1d_obmc_masks[h];
713
9.10k
    h = (h * 3) >> 2;
714
44.0k
    do {
715
44.0k
        const int m = *mask++;
716
570k
        for (int x = 0; x < w; x++) {
717
526k
            dst[x] = blend_px(dst[x], tmp[x], m);
718
526k
        }
719
44.0k
        dst += PXSTRIDE(dst_stride);
720
44.0k
        tmp += w;
721
44.0k
    } while (--h);
722
9.10k
}
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
1.45k
{
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
1.45k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
732
1.45k
    const int bitdepth = bitdepth_from_max(bitdepth_max);
733
1.45k
    const int sh = intermediate_bits + 6;
734
1.45k
    const int rnd = (32 << intermediate_bits) + PREP_BIAS * 64;
735
1.45k
    const int mask_sh = bitdepth + intermediate_bits - 4;
736
1.45k
    const int mask_rnd = 1 << (mask_sh - 5);
737
40.9k
    do {
738
1.40M
        for (int x = 0; x < w; x++) {
739
1.36M
            const int tmpdiff = tmp1[x] - tmp2[x];
740
1.36M
            const int m = imin(38 + ((abs(tmpdiff) + mask_rnd) >> mask_sh), 64);
741
1.36M
            dst[x] = iclip_pixel((tmpdiff * m + tmp2[x] * 64 + rnd) >> sh);
742
743
1.36M
            if (ss_hor) {
744
212k
                x++;
745
746
212k
                const int tmpdiff = tmp1[x] - tmp2[x];
747
212k
                const int n = imin(38 + ((abs(tmpdiff) + mask_rnd) >> mask_sh), 64);
748
212k
                dst[x] = iclip_pixel((tmpdiff * n + tmp2[x] * 64 + rnd) >> sh);
749
750
212k
                if (h & ss_ver) {
751
93.7k
                    mask[x >> 1] = (m + n + mask[x >> 1] + 2 - sign) >> 2;
752
118k
                } else if (ss_ver) {
753
93.7k
                    mask[x >> 1] = m + n;
754
93.7k
                } else {
755
24.5k
                    mask[x >> 1] = (m + n + 1 - sign) >> 1;
756
24.5k
                }
757
1.15M
            } else {
758
1.15M
                mask[x] = m;
759
1.15M
            }
760
1.36M
        }
761
762
40.9k
        tmp1 += w;
763
40.9k
        tmp2 += w;
764
40.9k
        dst += PXSTRIDE(dst_stride);
765
40.9k
        if (!ss_ver || (h & 1)) mask += w >> ss_hor;
766
40.9k
    } while (--h);
767
1.45k
}
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
1.45k
                             const int sign HIGHBD_DECL_SUFFIX) \
774
1.45k
{ \
775
1.45k
    w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver \
776
1.45k
             HIGHBD_TAIL_SUFFIX); \
777
1.45k
}
mc_tmpl.c:w_mask_444_c
Line
Count
Source
773
1.07k
                             const int sign HIGHBD_DECL_SUFFIX) \
774
1.07k
{ \
775
1.07k
    w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver \
776
1.07k
             HIGHBD_TAIL_SUFFIX); \
777
1.07k
}
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
378
                             const int sign HIGHBD_DECL_SUFFIX) \
774
378
{ \
775
378
    w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver \
776
378
             HIGHBD_TAIL_SUFFIX); \
777
378
}
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
63.1M
    ((F[0] * src[x - 3 * stride] + \
787
63.1M
      F[1] * src[x - 2 * stride] + \
788
63.1M
      F[2] * src[x - 1 * stride] + \
789
63.1M
      F[3] * src[x + 0 * stride] + \
790
63.1M
      F[4] * src[x + 1 * stride] + \
791
63.1M
      F[5] * src[x + 2 * stride] + \
792
63.1M
      F[6] * src[x + 3 * stride] + \
793
63.1M
      F[7] * src[x + 4 * stride] + \
794
63.1M
      ((1 << (sh)) >> 1)) >> (sh))
795
796
#define FILTER_WARP_CLIP(src, x, F, stride, sh) \
797
20.8M
    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
351k
{
804
351k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
805
351k
    int16_t mid[15 * 8], *mid_ptr = mid;
806
807
351k
    src -= 3 * PXSTRIDE(src_stride);
808
5.41M
    for (int y = 0; y < 15; y++, mx += abcd[1]) {
809
42.7M
        for (int x = 0, tmx = mx; x < 8; x++, tmx += abcd[0]) {
810
37.6M
            const int8_t *const filter =
811
37.6M
                dav1d_mc_warp_filter[64 + ((tmx + 512) >> 10)];
812
813
37.6M
            mid_ptr[x] = FILTER_WARP_RND(src, x, filter, 1,
814
37.6M
                                         7 - intermediate_bits);
815
37.6M
        }
816
5.06M
        src += PXSTRIDE(src_stride);
817
5.06M
        mid_ptr += 8;
818
5.06M
    }
819
820
351k
    mid_ptr = &mid[3 * 8];
821
3.10M
    for (int y = 0; y < 8; y++, my += abcd[3]) {
822
23.6M
        for (int x = 0, tmy = my; x < 8; x++, tmy += abcd[2]) {
823
20.8M
            const int8_t *const filter =
824
20.8M
                dav1d_mc_warp_filter[64 + ((tmy + 512) >> 10)];
825
826
20.8M
            dst[x] = FILTER_WARP_CLIP(mid_ptr, x, filter, 8,
827
20.8M
                                      7 + intermediate_bits);
828
20.8M
        }
829
2.75M
        mid_ptr += 8;
830
2.75M
        dst += PXSTRIDE(dst_stride);
831
2.75M
    }
832
351k
}
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
24.8k
{
839
24.8k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
840
24.8k
    int16_t mid[15 * 8], *mid_ptr = mid;
841
842
24.8k
    src -= 3 * PXSTRIDE(src_stride);
843
398k
    for (int y = 0; y < 15; y++, mx += abcd[1]) {
844
3.35M
        for (int x = 0, tmx = mx; x < 8; x++, tmx += abcd[0]) {
845
2.98M
            const int8_t *const filter =
846
2.98M
                dav1d_mc_warp_filter[64 + ((tmx + 512) >> 10)];
847
848
2.98M
            mid_ptr[x] = FILTER_WARP_RND(src, x, filter, 1,
849
2.98M
                                         7 - intermediate_bits);
850
2.98M
        }
851
373k
        src += PXSTRIDE(src_stride);
852
373k
        mid_ptr += 8;
853
373k
    }
854
855
24.8k
    mid_ptr = &mid[3 * 8];
856
223k
    for (int y = 0; y < 8; y++, my += abcd[3]) {
857
1.79M
        for (int x = 0, tmy = my; x < 8; x++, tmy += abcd[2]) {
858
1.59M
            const int8_t *const filter =
859
1.59M
                dav1d_mc_warp_filter[64 + ((tmy + 512) >> 10)];
860
861
1.59M
            tmp[x] = FILTER_WARP_RND(mid_ptr, x, filter, 8, 7) - PREP_BIAS;
862
1.59M
        }
863
199k
        mid_ptr += 8;
864
199k
        tmp += tmp_stride;
865
199k
    }
866
24.8k
}
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
306k
{
874
    // find offset in reference of visible block to copy
875
306k
    ref += iclip((int) y, 0, (int) ih - 1) * PXSTRIDE(ref_stride) +
876
306k
           iclip((int) x, 0, (int) iw - 1);
877
878
    // number of pixels to extend (left, right, top, bottom)
879
306k
    const int left_ext = iclip((int) -x, 0, (int) bw - 1);
880
306k
    const int right_ext = iclip((int) (x + bw - iw), 0, (int) bw - 1);
881
306k
    assert(left_ext + right_ext < bw);
882
306k
    const int top_ext = iclip((int) -y, 0, (int) bh - 1);
883
306k
    const int bottom_ext = iclip((int) (y + bh - ih), 0, (int) bh - 1);
884
306k
    assert(top_ext + bottom_ext < bh);
885
886
    // copy visible portion first
887
306k
    pixel *blk = dst + top_ext * PXSTRIDE(dst_stride);
888
306k
    const int center_w = (int) (bw - left_ext - right_ext);
889
306k
    const int center_h = (int) (bh - top_ext - bottom_ext);
890
4.88M
    for (int y = 0; y < center_h; y++) {
891
4.58M
        pixel_copy(blk + left_ext, ref, center_w);
892
        // extend left edge for this line
893
4.58M
        if (left_ext)
894
666k
            pixel_set(blk, blk[left_ext], left_ext);
895
        // extend right edge for this line
896
4.58M
        if (right_ext)
897
2.89M
            pixel_set(blk + left_ext + center_w, blk[left_ext + center_w - 1],
898
2.89M
                      right_ext);
899
4.58M
        ref += PXSTRIDE(ref_stride);
900
4.58M
        blk += PXSTRIDE(dst_stride);
901
4.58M
    }
902
903
    // copy top
904
306k
    blk = dst + top_ext * PXSTRIDE(dst_stride);
905
697k
    for (int y = 0; y < top_ext; y++) {
906
390k
        pixel_copy(dst, blk, bw);
907
390k
        dst += PXSTRIDE(dst_stride);
908
390k
    }
909
910
    // copy bottom
911
306k
    dst += center_h * PXSTRIDE(dst_stride);
912
1.22M
    for (int y = 0; y < bottom_ext; y++) {
913
916k
        pixel_copy(dst, &dst[-PXSTRIDE(dst_stride)], bw);
914
916k
        dst += PXSTRIDE(dst_stride);
915
916k
    }
916
306k
}
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
91.0k
{
923
2.68M
    do {
924
2.68M
        int mx = mx0, src_x = -1;
925
483M
        for (int x = 0; x < dst_w; x++) {
926
480M
            const int8_t *const F = dav1d_resize_filter[mx >> 8];
927
480M
            dst[x] = iclip_pixel((-(F[0] * src[iclip(src_x - 3, 0, src_w - 1)] +
928
480M
                                    F[1] * src[iclip(src_x - 2, 0, src_w - 1)] +
929
480M
                                    F[2] * src[iclip(src_x - 1, 0, src_w - 1)] +
930
480M
                                    F[3] * src[iclip(src_x + 0, 0, src_w - 1)] +
931
480M
                                    F[4] * src[iclip(src_x + 1, 0, src_w - 1)] +
932
480M
                                    F[5] * src[iclip(src_x + 2, 0, src_w - 1)] +
933
480M
                                    F[6] * src[iclip(src_x + 3, 0, src_w - 1)] +
934
480M
                                    F[7] * src[iclip(src_x + 4, 0, src_w - 1)]) +
935
480M
                                  64) >> 7);
936
480M
            mx += dx;
937
480M
            src_x += mx >> 14;
938
480M
            mx &= 0x3fff;
939
480M
        }
940
941
2.68M
        dst += PXSTRIDE(dst_stride);
942
2.68M
        src += PXSTRIDE(src_stride);
943
2.68M
    } while (--h);
944
91.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
15.7k
COLD void bitfn(dav1d_mc_dsp_init)(Dav1dMCDSPContext *const c) {
961
157k
#define init_mc_fns(type, name) do { \
962
157k
    c->mc        [type] = put_##name##_c; \
963
157k
    c->mc_scaled [type] = put_##name##_scaled_c; \
964
157k
    c->mct       [type] = prep_##name##_c; \
965
157k
    c->mct_scaled[type] = prep_##name##_scaled_c; \
966
157k
} while (0)
967
968
15.7k
    init_mc_fns(FILTER_2D_8TAP_REGULAR,        8tap_regular);
969
15.7k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SMOOTH, 8tap_regular_smooth);
970
15.7k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SHARP,  8tap_regular_sharp);
971
15.7k
    init_mc_fns(FILTER_2D_8TAP_SHARP_REGULAR,  8tap_sharp_regular);
972
15.7k
    init_mc_fns(FILTER_2D_8TAP_SHARP_SMOOTH,   8tap_sharp_smooth);
973
15.7k
    init_mc_fns(FILTER_2D_8TAP_SHARP,          8tap_sharp);
974
15.7k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_REGULAR, 8tap_smooth_regular);
975
15.7k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH,         8tap_smooth);
976
15.7k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_SHARP,   8tap_smooth_sharp);
977
15.7k
    init_mc_fns(FILTER_2D_BILINEAR,            bilin);
978
979
15.7k
    c->avg      = avg_c;
980
15.7k
    c->w_avg    = w_avg_c;
981
15.7k
    c->mask     = mask_c;
982
15.7k
    c->blend    = blend_c;
983
15.7k
    c->blend_v  = blend_v_c;
984
15.7k
    c->blend_h  = blend_h_c;
985
15.7k
    c->w_mask[0] = w_mask_444_c;
986
15.7k
    c->w_mask[1] = w_mask_422_c;
987
15.7k
    c->w_mask[2] = w_mask_420_c;
988
15.7k
    c->warp8x8  = warp_affine_8x8_c;
989
15.7k
    c->warp8x8t = warp_affine_8x8t_c;
990
15.7k
    c->emu_edge = emu_edge_c;
991
15.7k
    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.7k
}
dav1d_mc_dsp_init_8bpc
Line
Count
Source
960
7.66k
COLD void bitfn(dav1d_mc_dsp_init)(Dav1dMCDSPContext *const c) {
961
7.66k
#define init_mc_fns(type, name) do { \
962
7.66k
    c->mc        [type] = put_##name##_c; \
963
7.66k
    c->mc_scaled [type] = put_##name##_scaled_c; \
964
7.66k
    c->mct       [type] = prep_##name##_c; \
965
7.66k
    c->mct_scaled[type] = prep_##name##_scaled_c; \
966
7.66k
} while (0)
967
968
7.66k
    init_mc_fns(FILTER_2D_8TAP_REGULAR,        8tap_regular);
969
7.66k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SMOOTH, 8tap_regular_smooth);
970
7.66k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SHARP,  8tap_regular_sharp);
971
7.66k
    init_mc_fns(FILTER_2D_8TAP_SHARP_REGULAR,  8tap_sharp_regular);
972
7.66k
    init_mc_fns(FILTER_2D_8TAP_SHARP_SMOOTH,   8tap_sharp_smooth);
973
7.66k
    init_mc_fns(FILTER_2D_8TAP_SHARP,          8tap_sharp);
974
7.66k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_REGULAR, 8tap_smooth_regular);
975
7.66k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH,         8tap_smooth);
976
7.66k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_SHARP,   8tap_smooth_sharp);
977
7.66k
    init_mc_fns(FILTER_2D_BILINEAR,            bilin);
978
979
7.66k
    c->avg      = avg_c;
980
7.66k
    c->w_avg    = w_avg_c;
981
7.66k
    c->mask     = mask_c;
982
7.66k
    c->blend    = blend_c;
983
7.66k
    c->blend_v  = blend_v_c;
984
7.66k
    c->blend_h  = blend_h_c;
985
7.66k
    c->w_mask[0] = w_mask_444_c;
986
7.66k
    c->w_mask[1] = w_mask_422_c;
987
7.66k
    c->w_mask[2] = w_mask_420_c;
988
7.66k
    c->warp8x8  = warp_affine_8x8_c;
989
7.66k
    c->warp8x8t = warp_affine_8x8t_c;
990
7.66k
    c->emu_edge = emu_edge_c;
991
7.66k
    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.66k
}
dav1d_mc_dsp_init_16bpc
Line
Count
Source
960
8.08k
COLD void bitfn(dav1d_mc_dsp_init)(Dav1dMCDSPContext *const c) {
961
8.08k
#define init_mc_fns(type, name) do { \
962
8.08k
    c->mc        [type] = put_##name##_c; \
963
8.08k
    c->mc_scaled [type] = put_##name##_scaled_c; \
964
8.08k
    c->mct       [type] = prep_##name##_c; \
965
8.08k
    c->mct_scaled[type] = prep_##name##_scaled_c; \
966
8.08k
} while (0)
967
968
8.08k
    init_mc_fns(FILTER_2D_8TAP_REGULAR,        8tap_regular);
969
8.08k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SMOOTH, 8tap_regular_smooth);
970
8.08k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SHARP,  8tap_regular_sharp);
971
8.08k
    init_mc_fns(FILTER_2D_8TAP_SHARP_REGULAR,  8tap_sharp_regular);
972
8.08k
    init_mc_fns(FILTER_2D_8TAP_SHARP_SMOOTH,   8tap_sharp_smooth);
973
8.08k
    init_mc_fns(FILTER_2D_8TAP_SHARP,          8tap_sharp);
974
8.08k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_REGULAR, 8tap_smooth_regular);
975
8.08k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH,         8tap_smooth);
976
8.08k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_SHARP,   8tap_smooth_sharp);
977
8.08k
    init_mc_fns(FILTER_2D_BILINEAR,            bilin);
978
979
8.08k
    c->avg      = avg_c;
980
8.08k
    c->w_avg    = w_avg_c;
981
8.08k
    c->mask     = mask_c;
982
8.08k
    c->blend    = blend_c;
983
8.08k
    c->blend_v  = blend_v_c;
984
8.08k
    c->blend_h  = blend_h_c;
985
8.08k
    c->w_mask[0] = w_mask_444_c;
986
8.08k
    c->w_mask[1] = w_mask_422_c;
987
8.08k
    c->w_mask[2] = w_mask_420_c;
988
8.08k
    c->warp8x8  = warp_affine_8x8_c;
989
8.08k
    c->warp8x8t = warp_affine_8x8t_c;
990
8.08k
    c->emu_edge = emu_edge_c;
991
8.08k
    c->resize   = resize_c;
992
993
#if HAVE_ASM
994
#if ARCH_AARCH64 || ARCH_ARM
995
    mc_dsp_init_arm(c);
996
#elif ARCH_LOONGARCH64
997
    mc_dsp_init_loongarch(c);
998
#elif ARCH_PPC64LE
999
    mc_dsp_init_ppc(c);
1000
#elif ARCH_RISCV
1001
    mc_dsp_init_riscv(c);
1002
#elif ARCH_X86
1003
    mc_dsp_init_x86(c);
1004
#endif
1005
#endif
1006
8.08k
}