Coverage Report

Created: 2026-10-17 06:52

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
2.05M
#define get_intermediate_bits(bitdepth_max) 4
41
// Output in interval [-5132, 9212], fits in int16_t as is
42
136M
#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
613k
{
55
8.84M
    do {
56
8.84M
        pixel_copy(dst, src, w);
57
58
8.84M
        dst += dst_stride;
59
8.84M
        src += src_stride;
60
8.84M
    } while (--h);
61
613k
}
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
97.4k
{
67
97.4k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
68
2.23M
    do {
69
56.2M
        for (int x = 0; x < w; x++)
70
54.0M
            tmp[x] = (src[x] << intermediate_bits) - PREP_BIAS;
71
72
2.23M
        tmp += w;
73
2.23M
        src += src_stride;
74
2.23M
    } while (--h);
75
97.4k
}
76
77
#define FILTER_8TAP(src, x, F, stride) \
78
257M
    (F[0] * src[x + -3 * stride] + \
79
257M
     F[1] * src[x + -2 * stride] + \
80
257M
     F[2] * src[x + -1 * stride] + \
81
257M
     F[3] * src[x + +0 * stride] + \
82
257M
     F[4] * src[x + +1 * stride] + \
83
257M
     F[5] * src[x + +2 * stride] + \
84
257M
     F[6] * src[x + +3 * stride] + \
85
257M
     F[7] * src[x + +4 * stride])
86
87
#define FILTER_8TAP2(src, x, F) \
88
87.0M
    (F[0] * src[0][x] + \
89
87.0M
     F[1] * src[1][x] + \
90
87.0M
     F[2] * src[2][x] + \
91
87.0M
     F[3] * src[3][x] + \
92
87.0M
     F[4] * src[4][x] + \
93
87.0M
     F[5] * src[5][x] + \
94
87.0M
     F[6] * src[6][x] + \
95
87.0M
     F[7] * src[7][x])
96
97
#define DAV1D_FILTER_8TAP_RND(src, x, F, stride, sh) \
98
243M
    ((FILTER_8TAP(src, x, F, stride) + ((1 << (sh)) >> 1)) >> (sh))
99
100
#define DAV1D_FILTER_8TAP_RND2(src, x, F, stride, rnd, sh) \
101
14.5M
    ((FILTER_8TAP(src, x, F, stride) + (rnd)) >> (sh))
102
103
#define DAV1D_FILTER_8TAP_RND3(src, x, F, sh) \
104
87.0M
    ((FILTER_8TAP2(src, x, F) + ((1 << (sh)) >> 1)) >> (sh))
105
106
#define DAV1D_FILTER_8TAP_CLIP(src, x, F, stride, sh) \
107
42.4M
    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
14.5M
    iclip_pixel(DAV1D_FILTER_8TAP_RND2(src, x, F, stride, rnd, sh))
111
112
#define DAV1D_FILTER_8TAP_CLIP3(src, x, F, sh) \
113
60.6M
    iclip_pixel(DAV1D_FILTER_8TAP_RND3(src, x, F, sh))
114
115
#define GET_H_FILTER(mx) \
116
131M
    const int8_t *const fh = !(mx) ? NULL : w > 4 ? \
117
121M
        dav1d_mc_subpel_filters[filter_type & 3][(mx) - 1] : \
118
121M
        dav1d_mc_subpel_filters[3 + (filter_type & 1)][(mx) - 1]
119
120
#define GET_V_FILTER(my) \
121
4.97M
    const int8_t *const fv = !(my) ? NULL : h > 4 ? \
122
3.38M
        dav1d_mc_subpel_filters[filter_type >> 2][(my) - 1] : \
123
3.38M
        dav1d_mc_subpel_filters[3 + ((filter_type >> 2) & 1)][(my) - 1]
124
125
#define GET_FILTERS() \
126
861k
    GET_H_FILTER(mx); \
127
861k
    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
704k
{
135
704k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
136
704k
    const int intermediate_rnd = 32 + ((1 << (6 - intermediate_bits)) >> 1);
137
138
704k
    GET_FILTERS();
139
704k
    dst_stride = PXSTRIDE(dst_stride);
140
704k
    src_stride = PXSTRIDE(src_stride);
141
142
704k
    if (fh) {
143
157k
        if (fv) {
144
107k
            int tmp_h = h + 7;
145
107k
            int16_t mid[128 * 135], *mid_ptr = mid;
146
147
107k
            src -= src_stride * 3;
148
2.09M
            do {
149
35.1M
                for (int x = 0; x < w; x++)
150
33.0M
                    mid_ptr[x] = DAV1D_FILTER_8TAP_RND(src, x, fh, 1,
151
2.09M
                                                       6 - intermediate_bits);
152
153
2.09M
                mid_ptr += 128;
154
2.09M
                src += src_stride;
155
2.09M
            } while (--tmp_h);
156
157
107k
            mid_ptr = mid + 128 * 3;
158
1.34M
            do {
159
26.5M
                for (int x = 0; x < w; x++)
160
25.2M
                    dst[x] = DAV1D_FILTER_8TAP_CLIP(mid_ptr, x, fv, 128,
161
1.34M
                                                    6 + intermediate_bits);
162
163
1.34M
                mid_ptr += 128;
164
1.34M
                dst += dst_stride;
165
1.34M
            } while (--h);
166
107k
        } else {
167
660k
            do {
168
15.2M
                for (int x = 0; x < w; x++) {
169
14.5M
                    dst[x] = DAV1D_FILTER_8TAP_CLIP2(src, x, fh, 1,
170
14.5M
                                                     intermediate_rnd, 6);
171
14.5M
                }
172
173
660k
                dst += dst_stride;
174
660k
                src += src_stride;
175
660k
            } while (--h);
176
50.1k
        }
177
547k
    } else if (fv) {
178
665k
        do {
179
17.8M
            for (int x = 0; x < w; x++)
180
17.1M
                dst[x] = DAV1D_FILTER_8TAP_CLIP(src, x, fv, src_stride, 6);
181
182
665k
            dst += dst_stride;
183
665k
            src += src_stride;
184
665k
        } while (--h);
185
63.6k
    } else
186
483k
        put_c(dst, dst_stride, src, src_stride, w, h);
187
704k
}
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
269k
{
196
269k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
197
269k
    const int intermediate_rnd = (1 << intermediate_bits) >> 1;
198
269k
    int16_t mid[128 * 8];
199
269k
    int16_t *mid_ptrs[8];
200
269k
    int in_y = -8;
201
269k
    src_stride = PXSTRIDE(src_stride);
202
203
2.42M
    for (int i = 0; i < 8; i++)
204
2.15M
        mid_ptrs[i] = &mid[128 * i];
205
206
269k
    src -= src_stride * 3;
207
208
3.23M
    for (int y = 0; y < h; y++) {
209
2.96M
        int x;
210
2.96M
        int src_y = my >> 10;
211
2.96M
        GET_V_FILTER((my & 0x3ff) >> 6);
212
213
7.43M
        while (in_y < src_y) {
214
4.46M
            int imx = mx, ioff = 0;
215
4.46M
            int16_t *mid_ptr = mid_ptrs[0];
216
217
35.7M
            for (int i = 0; i < 7; i++)
218
31.2M
                mid_ptrs[i] = mid_ptrs[i + 1];
219
4.46M
            mid_ptrs[7] = mid_ptr;
220
221
93.0M
            for (x = 0; x < w; x++) {
222
88.5M
                GET_H_FILTER(imx >> 6);
223
88.5M
                mid_ptr[x] = fh ? DAV1D_FILTER_8TAP_RND(src, ioff, fh, 1,
224
88.5M
                                                        6 - intermediate_bits) :
225
88.5M
                                  src[ioff] << intermediate_bits;
226
88.5M
                imx += dx;
227
88.5M
                ioff += imx >> 10;
228
88.5M
                imx &= 0x3ff;
229
88.5M
            }
230
231
4.46M
            src += src_stride;
232
4.46M
            in_y++;
233
4.46M
        }
234
235
76.1M
        for (x = 0; x < w; x++)
236
73.2M
            dst[x] = fv ? DAV1D_FILTER_8TAP_CLIP3(mid_ptrs, x, fv,
237
73.2M
                                                  6 + intermediate_bits) :
238
73.2M
                          iclip_pixel((mid_ptrs[3][x] + intermediate_rnd) >>
239
12.5M
                                              intermediate_bits);
240
241
2.96M
        my += dy;
242
2.96M
        dst += PXSTRIDE(dst_stride);
243
2.96M
    }
244
269k
}
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
156k
{
251
156k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
252
156k
    GET_FILTERS();
253
156k
    src_stride = PXSTRIDE(src_stride);
254
255
156k
    if (fh) {
256
53.7k
        if (fv) {
257
43.0k
            int tmp_h = h + 7;
258
43.0k
            int16_t mid[128 * 135], *mid_ptr = mid;
259
260
43.0k
            src -= src_stride * 3;
261
1.06M
            do {
262
21.0M
                for (int x = 0; x < w; x++)
263
19.9M
                    mid_ptr[x] = DAV1D_FILTER_8TAP_RND(src, x, fh, 1,
264
1.06M
                                                       6 - intermediate_bits);
265
266
1.06M
                mid_ptr += 128;
267
1.06M
                src += src_stride;
268
1.06M
            } while (--tmp_h);
269
270
43.0k
            mid_ptr = mid + 128 * 3;
271
769k
            do {
272
17.4M
                for (int x = 0; x < w; x++) {
273
16.6M
                    int t = DAV1D_FILTER_8TAP_RND(mid_ptr, x, fv, 128, 6) -
274
16.6M
                                  PREP_BIAS;
275
16.6M
                    assert(t >= INT16_MIN && t <= INT16_MAX);
276
16.6M
                    tmp[x] = t;
277
16.6M
                }
278
279
769k
                mid_ptr += 128;
280
769k
                tmp += w;
281
769k
            } while (--h);
282
43.0k
        } else {
283
167k
            do {
284
3.59M
                for (int x = 0; x < w; x++)
285
3.43M
                    tmp[x] = DAV1D_FILTER_8TAP_RND(src, x, fh, 1,
286
3.43M
                                                   6 - intermediate_bits) -
287
3.43M
                             PREP_BIAS;
288
289
167k
                tmp += w;
290
167k
                src += src_stride;
291
167k
            } while (--h);
292
10.7k
        }
293
102k
    } else if (fv) {
294
246k
        do {
295
6.79M
            for (int x = 0; x < w; x++)
296
6.55M
                tmp[x] = DAV1D_FILTER_8TAP_RND(src, x, fv, src_stride,
297
6.55M
                                               6 - intermediate_bits) -
298
6.55M
                         PREP_BIAS;
299
300
246k
            tmp += w;
301
246k
            src += src_stride;
302
246k
        } while (--h);
303
11.3k
    } else
304
91.4k
        prep_c(tmp, src, src_stride, w, h HIGHBD_TAIL_SUFFIX);
305
156k
}
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
62.2k
{
313
62.2k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
314
62.2k
    int16_t mid[128 * 8];
315
62.2k
    int16_t *mid_ptrs[8];
316
62.2k
    int in_y = -8;
317
62.2k
    src_stride = PXSTRIDE(src_stride);
318
319
559k
    for (int i = 0; i < 8; i++)
320
497k
        mid_ptrs[i] = &mid[128 * i];
321
322
62.2k
    src -= src_stride * 3;
323
324
1.20M
    for (int y = 0; y < h; y++) {
325
1.14M
        int x;
326
1.14M
        int src_y = my >> 10;
327
1.14M
        GET_V_FILTER((my & 0x3ff) >> 6);
328
329
2.50M
        while (in_y < src_y) {
330
1.36M
            int imx = mx, ioff = 0;
331
1.36M
            int16_t *mid_ptr = mid_ptrs[0];
332
333
10.9M
            for (int i = 0; i < 7; i++)
334
9.53M
                mid_ptrs[i] = mid_ptrs[i + 1];
335
1.36M
            mid_ptrs[7] = mid_ptr;
336
337
42.9M
            for (x = 0; x < w; x++) {
338
41.5M
                GET_H_FILTER(imx >> 6);
339
41.5M
                mid_ptr[x] = fh ? DAV1D_FILTER_8TAP_RND(src, ioff, fh, 1,
340
41.5M
                                                        6 - intermediate_bits) :
341
41.5M
                                  src[ioff] << intermediate_bits;
342
41.5M
                imx += dx;
343
41.5M
                ioff += imx >> 10;
344
41.5M
                imx &= 0x3ff;
345
41.5M
            }
346
347
1.36M
            src += src_stride;
348
1.36M
            in_y++;
349
1.36M
        }
350
351
41.0M
        for (x = 0; x < w; x++)
352
39.9M
            tmp[x] = (fv ? DAV1D_FILTER_8TAP_RND3(mid_ptrs, x, fv, 6)
353
39.9M
                         : mid_ptrs[3][x]) - PREP_BIAS;
354
355
1.14M
        my += dy;
356
1.14M
        tmp += w;
357
1.14M
    }
358
62.2k
}
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
704k
                                HIGHBD_DECL_SUFFIX) \
368
704k
{ \
369
704k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
704k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
704k
} \
mc_tmpl.c:put_8tap_regular_c
Line
Count
Source
367
194k
                                HIGHBD_DECL_SUFFIX) \
368
194k
{ \
369
194k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
194k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
194k
} \
mc_tmpl.c:put_8tap_regular_smooth_c
Line
Count
Source
367
3.74k
                                HIGHBD_DECL_SUFFIX) \
368
3.74k
{ \
369
3.74k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
3.74k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
3.74k
} \
mc_tmpl.c:put_8tap_regular_sharp_c
Line
Count
Source
367
987
                                HIGHBD_DECL_SUFFIX) \
368
987
{ \
369
987
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
987
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
987
} \
mc_tmpl.c:put_8tap_sharp_regular_c
Line
Count
Source
367
1.24k
                                HIGHBD_DECL_SUFFIX) \
368
1.24k
{ \
369
1.24k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
1.24k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
1.24k
} \
mc_tmpl.c:put_8tap_sharp_smooth_c
Line
Count
Source
367
640
                                HIGHBD_DECL_SUFFIX) \
368
640
{ \
369
640
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
640
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
640
} \
mc_tmpl.c:put_8tap_sharp_c
Line
Count
Source
367
52.2k
                                HIGHBD_DECL_SUFFIX) \
368
52.2k
{ \
369
52.2k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
52.2k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
52.2k
} \
mc_tmpl.c:put_8tap_smooth_regular_c
Line
Count
Source
367
2.64k
                                HIGHBD_DECL_SUFFIX) \
368
2.64k
{ \
369
2.64k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
2.64k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
2.64k
} \
mc_tmpl.c:put_8tap_smooth_c
Line
Count
Source
367
447k
                                HIGHBD_DECL_SUFFIX) \
368
447k
{ \
369
447k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
447k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
447k
} \
mc_tmpl.c:put_8tap_smooth_sharp_c
Line
Count
Source
367
791
                                HIGHBD_DECL_SUFFIX) \
368
791
{ \
369
791
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
791
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
791
} \
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
269k
                                       HIGHBD_DECL_SUFFIX) \
380
269k
{ \
381
269k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
269k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
269k
} \
mc_tmpl.c:put_8tap_regular_scaled_c
Line
Count
Source
379
195k
                                       HIGHBD_DECL_SUFFIX) \
380
195k
{ \
381
195k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
195k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
195k
} \
mc_tmpl.c:put_8tap_regular_smooth_scaled_c
Line
Count
Source
379
9.70k
                                       HIGHBD_DECL_SUFFIX) \
380
9.70k
{ \
381
9.70k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
9.70k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
9.70k
} \
mc_tmpl.c:put_8tap_regular_sharp_scaled_c
Line
Count
Source
379
909
                                       HIGHBD_DECL_SUFFIX) \
380
909
{ \
381
909
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
909
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
909
} \
mc_tmpl.c:put_8tap_sharp_regular_scaled_c
Line
Count
Source
379
2.10k
                                       HIGHBD_DECL_SUFFIX) \
380
2.10k
{ \
381
2.10k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
2.10k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
2.10k
} \
mc_tmpl.c:put_8tap_sharp_smooth_scaled_c
Line
Count
Source
379
701
                                       HIGHBD_DECL_SUFFIX) \
380
701
{ \
381
701
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
701
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
701
} \
mc_tmpl.c:put_8tap_sharp_scaled_c
Line
Count
Source
379
22.8k
                                       HIGHBD_DECL_SUFFIX) \
380
22.8k
{ \
381
22.8k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
22.8k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
22.8k
} \
mc_tmpl.c:put_8tap_smooth_regular_scaled_c
Line
Count
Source
379
12.5k
                                       HIGHBD_DECL_SUFFIX) \
380
12.5k
{ \
381
12.5k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
12.5k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
12.5k
} \
mc_tmpl.c:put_8tap_smooth_scaled_c
Line
Count
Source
379
24.8k
                                       HIGHBD_DECL_SUFFIX) \
380
24.8k
{ \
381
24.8k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
24.8k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
24.8k
} \
mc_tmpl.c:put_8tap_smooth_sharp_scaled_c
Line
Count
Source
379
890
                                       HIGHBD_DECL_SUFFIX) \
380
890
{ \
381
890
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
890
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
890
} \
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
156k
                                 HIGHBD_DECL_SUFFIX) \
390
156k
{ \
391
156k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
156k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
156k
} \
mc_tmpl.c:prep_8tap_regular_c
Line
Count
Source
389
31.5k
                                 HIGHBD_DECL_SUFFIX) \
390
31.5k
{ \
391
31.5k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
31.5k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
31.5k
} \
mc_tmpl.c:prep_8tap_regular_smooth_c
Line
Count
Source
389
679
                                 HIGHBD_DECL_SUFFIX) \
390
679
{ \
391
679
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
679
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
679
} \
mc_tmpl.c:prep_8tap_regular_sharp_c
Line
Count
Source
389
1.06k
                                 HIGHBD_DECL_SUFFIX) \
390
1.06k
{ \
391
1.06k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
1.06k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
1.06k
} \
mc_tmpl.c:prep_8tap_sharp_regular_c
Line
Count
Source
389
2.87k
                                 HIGHBD_DECL_SUFFIX) \
390
2.87k
{ \
391
2.87k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
2.87k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
2.87k
} \
mc_tmpl.c:prep_8tap_sharp_smooth_c
Line
Count
Source
389
1.49k
                                 HIGHBD_DECL_SUFFIX) \
390
1.49k
{ \
391
1.49k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
1.49k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
1.49k
} \
mc_tmpl.c:prep_8tap_sharp_c
Line
Count
Source
389
22.5k
                                 HIGHBD_DECL_SUFFIX) \
390
22.5k
{ \
391
22.5k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
22.5k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
22.5k
} \
mc_tmpl.c:prep_8tap_smooth_regular_c
Line
Count
Source
389
1.11k
                                 HIGHBD_DECL_SUFFIX) \
390
1.11k
{ \
391
1.11k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
1.11k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
1.11k
} \
mc_tmpl.c:prep_8tap_smooth_c
Line
Count
Source
389
94.3k
                                 HIGHBD_DECL_SUFFIX) \
390
94.3k
{ \
391
94.3k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
94.3k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
94.3k
} \
mc_tmpl.c:prep_8tap_smooth_sharp_c
Line
Count
Source
389
834
                                 HIGHBD_DECL_SUFFIX) \
390
834
{ \
391
834
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
834
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
834
} \
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
62.2k
                                        HIGHBD_DECL_SUFFIX) \
401
62.2k
{ \
402
62.2k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
62.2k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
62.2k
}
mc_tmpl.c:prep_8tap_regular_scaled_c
Line
Count
Source
400
18.1k
                                        HIGHBD_DECL_SUFFIX) \
401
18.1k
{ \
402
18.1k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
18.1k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
18.1k
}
mc_tmpl.c:prep_8tap_regular_smooth_scaled_c
Line
Count
Source
400
1.62k
                                        HIGHBD_DECL_SUFFIX) \
401
1.62k
{ \
402
1.62k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
1.62k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
1.62k
}
mc_tmpl.c:prep_8tap_regular_sharp_scaled_c
Line
Count
Source
400
2.78k
                                        HIGHBD_DECL_SUFFIX) \
401
2.78k
{ \
402
2.78k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
2.78k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
2.78k
}
mc_tmpl.c:prep_8tap_sharp_regular_scaled_c
Line
Count
Source
400
7.85k
                                        HIGHBD_DECL_SUFFIX) \
401
7.85k
{ \
402
7.85k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
7.85k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
7.85k
}
mc_tmpl.c:prep_8tap_sharp_smooth_scaled_c
Line
Count
Source
400
1.43k
                                        HIGHBD_DECL_SUFFIX) \
401
1.43k
{ \
402
1.43k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
1.43k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
1.43k
}
mc_tmpl.c:prep_8tap_sharp_scaled_c
Line
Count
Source
400
6.00k
                                        HIGHBD_DECL_SUFFIX) \
401
6.00k
{ \
402
6.00k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
6.00k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
6.00k
}
mc_tmpl.c:prep_8tap_smooth_regular_scaled_c
Line
Count
Source
400
4.01k
                                        HIGHBD_DECL_SUFFIX) \
401
4.01k
{ \
402
4.01k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
4.01k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
4.01k
}
mc_tmpl.c:prep_8tap_smooth_scaled_c
Line
Count
Source
400
18.7k
                                        HIGHBD_DECL_SUFFIX) \
401
18.7k
{ \
402
18.7k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
18.7k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
18.7k
}
mc_tmpl.c:prep_8tap_smooth_sharp_scaled_c
Line
Count
Source
400
1.56k
                                        HIGHBD_DECL_SUFFIX) \
401
1.56k
{ \
402
1.56k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
1.56k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
1.56k
}
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
12.8M
    (16 * src[x] + ((mxy) * (src[x + stride] - src[x])))
418
419
#define FILTER_BILIN_RND(src, x, mxy, stride, sh) \
420
12.8M
    ((FILTER_BILIN(src, x, mxy, stride) + ((1 << (sh)) >> 1)) >> (sh))
421
422
#define FILTER_BILIN_CLIP(src, x, mxy, stride, sh) \
423
1.53M
    iclip_pixel(FILTER_BILIN_RND(src, x, mxy, stride, sh))
424
425
#define FILTER_BILIN2(src1, src2, x, mxy) \
426
4.21M
    (16 * src1[x] + ((mxy) * (src2[x] - src1[x])))
427
428
#define FILTER_BILIN_RND2(src1, src2, x, mxy, sh) \
429
4.21M
    ((FILTER_BILIN2(src1, src2, x, mxy) + ((1 << (sh)) >> 1)) >> (sh))
430
431
#define FILTER_BILIN_CLIP2(src1, src2, x, mxy, sh) \
432
3.46M
    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
147k
{
439
147k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
440
147k
    const int intermediate_rnd = (1 << intermediate_bits) >> 1;
441
147k
    dst_stride = PXSTRIDE(dst_stride);
442
147k
    src_stride = PXSTRIDE(src_stride);
443
444
147k
    if (mx) {
445
12.5k
        if (my) {
446
7.51k
            int16_t mid[128 * 129], *mid_ptr = mid;
447
7.51k
            int tmp_h = h + 1;
448
449
75.7k
            do {
450
1.01M
                for (int x = 0; x < w; x++)
451
935k
                    mid_ptr[x] = FILTER_BILIN_RND(src, x, mx, 1,
452
75.7k
                                                  4 - intermediate_bits);
453
454
75.7k
                mid_ptr += 128;
455
75.7k
                src += src_stride;
456
75.7k
            } while (--tmp_h);
457
458
7.51k
            mid_ptr = mid;
459
68.3k
            do {
460
953k
                for (int x = 0; x < w; x++)
461
885k
                    dst[x] = FILTER_BILIN_CLIP(mid_ptr, x, my, 128,
462
68.3k
                                               4 + intermediate_bits);
463
464
68.3k
                mid_ptr += 128;
465
68.3k
                dst += dst_stride;
466
68.3k
            } while (--h);
467
7.51k
        } else {
468
39.1k
            do {
469
475k
                for (int x = 0; x < w; x++) {
470
436k
                    const int px = FILTER_BILIN_RND(src, x, mx, 1,
471
436k
                                                    4 - intermediate_bits);
472
436k
                    dst[x] = iclip_pixel((px + intermediate_rnd) >> intermediate_bits);
473
436k
                }
474
475
39.1k
                dst += dst_stride;
476
39.1k
                src += src_stride;
477
39.1k
            } while (--h);
478
5.04k
        }
479
135k
    } else if (my) {
480
39.4k
        do {
481
688k
            for (int x = 0; x < w; x++)
482
649k
                dst[x] = FILTER_BILIN_CLIP(src, x, my, src_stride, 4);
483
484
39.4k
            dst += dst_stride;
485
39.4k
            src += src_stride;
486
39.4k
        } while (--h);
487
5.01k
    } else
488
130k
        put_c(dst, dst_stride, src, src_stride, w, h);
489
147k
}
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
15.4k
{
497
15.4k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
498
15.4k
    int16_t mid[128 * 2];
499
15.4k
    int in_y = -2;
500
501
193k
    do {
502
193k
        int x;
503
193k
        int y = my >> 10;
504
193k
        int16_t *mid1 = &mid[(y & 1) * 128];
505
193k
        int16_t *mid2 = &mid[((y + 1) & 1) * 128];
506
193k
        int dmy = my & 0x3ff;
507
508
405k
        while (in_y < y) {
509
211k
            int imx = mx, ioff = 0;
510
211k
            int16_t *mid_ptr = &mid[(in_y & 1) * 128];
511
512
4.07M
            for (x = 0; x < w; x++) {
513
3.86M
                mid_ptr[x] = FILTER_BILIN_RND(src, ioff, imx >> 6, 1,
514
3.86M
                                              4 - intermediate_bits);
515
3.86M
                imx += dx;
516
3.86M
                ioff += imx >> 10;
517
3.86M
                imx &= 0x3ff;
518
3.86M
            }
519
520
211k
            src += PXSTRIDE(src_stride);
521
211k
            in_y++;
522
211k
        }
523
524
3.66M
        for (x = 0; x < w; x++)
525
3.46M
            dst[x] = FILTER_BILIN_CLIP2(mid1, mid2, x, dmy >> 6,
526
193k
                                       4 + intermediate_bits);
527
528
193k
        my += dy;
529
193k
        dst += PXSTRIDE(dst_stride);
530
193k
    } while (--h);
531
15.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
13.8k
{
538
13.8k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
539
13.8k
    src_stride = PXSTRIDE(src_stride);
540
541
13.8k
    if (mx) {
542
6.48k
        if (my) {
543
4.56k
            int16_t mid[128 * 129], *mid_ptr = mid;
544
4.56k
            int tmp_h = h + 1;
545
546
85.1k
            do {
547
2.12M
                for (int x = 0; x < w; x++)
548
2.03M
                    mid_ptr[x] = FILTER_BILIN_RND(src, x, mx, 1,
549
85.1k
                                                  4 - intermediate_bits);
550
551
85.1k
                mid_ptr += 128;
552
85.1k
                src += src_stride;
553
85.1k
            } while (--tmp_h);
554
555
4.56k
            mid_ptr = mid;
556
84.4k
            do {
557
2.15M
                for (int x = 0; x < w; x++)
558
2.07M
                    tmp[x] = FILTER_BILIN_RND(mid_ptr, x, my, 128, 4) -
559
2.07M
                             PREP_BIAS;
560
561
84.4k
                mid_ptr += 128;
562
84.4k
                tmp += w;
563
84.4k
            } while (--h);
564
4.56k
        } else {
565
32.7k
            do {
566
532k
                for (int x = 0; x < w; x++)
567
500k
                    tmp[x] = FILTER_BILIN_RND(src, x, mx, 1,
568
500k
                                              4 - intermediate_bits) -
569
500k
                             PREP_BIAS;
570
571
32.7k
                tmp += w;
572
32.7k
                src += src_stride;
573
32.7k
            } while (--h);
574
1.92k
        }
575
7.39k
    } else if (my) {
576
31.8k
        do {
577
834k
            for (int x = 0; x < w; x++)
578
802k
                tmp[x] = FILTER_BILIN_RND(src, x, my, src_stride,
579
802k
                                          4 - intermediate_bits) - PREP_BIAS;
580
581
31.8k
            tmp += w;
582
31.8k
            src += src_stride;
583
31.8k
        } while (--h);
584
1.39k
    } else
585
6.00k
        prep_c(tmp, src, src_stride, w, h HIGHBD_TAIL_SUFFIX);
586
13.8k
}
587
588
static void prep_bilin_scaled_c(int16_t *tmp,
589
                                const pixel *src, ptrdiff_t src_stride,
590
                                const int w, int h, const int mx, int my,
591
                                const int dx, const int dy HIGHBD_DECL_SUFFIX)
592
2.45k
{
593
2.45k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
594
2.45k
    int16_t mid[128 * 2];
595
2.45k
    int in_y = -2;
596
597
38.7k
    do {
598
38.7k
        int x;
599
38.7k
        int y = my >> 10;
600
38.7k
        int16_t *mid1 = &mid[(y & 1) * 128];
601
38.7k
        int16_t *mid2 = &mid[((y + 1) & 1) * 128];
602
38.7k
        int dmy = my & 0x3ff;
603
604
74.8k
        while (in_y < y) {
605
36.1k
            int imx = mx, ioff = 0;
606
36.1k
            int16_t *mid_ptr = &mid[(in_y & 1) * 128];
607
608
742k
            for (x = 0; x < w; x++) {
609
706k
                mid_ptr[x] = FILTER_BILIN_RND(src, ioff, imx >> 6, 1,
610
706k
                                              4 - intermediate_bits);
611
706k
                imx += dx;
612
706k
                ioff += imx >> 10;
613
706k
                imx &= 0x3ff;
614
706k
            }
615
616
36.1k
            src += PXSTRIDE(src_stride);
617
36.1k
            in_y++;
618
36.1k
        }
619
620
784k
        for (x = 0; x < w; x++)
621
745k
            tmp[x] = FILTER_BILIN_RND2(mid1, mid2, x, dmy >> 6, 4) - PREP_BIAS;
622
623
38.7k
        my += dy;
624
38.7k
        tmp += w;
625
38.7k
    } while (--h);
626
2.45k
}
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
83.3k
{
632
83.3k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
633
83.3k
    const int sh = intermediate_bits + 1;
634
83.3k
    const int rnd = (1 << intermediate_bits) + PREP_BIAS * 2;
635
1.84M
    do {
636
50.3M
        for (int x = 0; x < w; x++)
637
48.4M
            dst[x] = iclip_pixel((tmp1[x] + tmp2[x] + rnd) >> sh);
638
639
1.84M
        tmp1 += w;
640
1.84M
        tmp2 += w;
641
1.84M
        dst += PXSTRIDE(dst_stride);
642
1.84M
    } while (--h);
643
83.3k
}
644
645
static void w_avg_c(pixel *dst, const ptrdiff_t dst_stride,
646
                    const int16_t *tmp1, const int16_t *tmp2, const int w, int h,
647
                    const int weight HIGHBD_DECL_SUFFIX)
648
16.4k
{
649
16.4k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
650
16.4k
    const int sh = intermediate_bits + 4;
651
16.4k
    const int rnd = (8 << intermediate_bits) + PREP_BIAS * 16;
652
233k
    do {
653
4.99M
        for (int x = 0; x < w; x++)
654
4.76M
            dst[x] = iclip_pixel((tmp1[x] * weight +
655
4.76M
                                  tmp2[x] * (16 - weight) + rnd) >> sh);
656
657
233k
        tmp1 += w;
658
233k
        tmp2 += w;
659
233k
        dst += PXSTRIDE(dst_stride);
660
233k
    } while (--h);
661
16.4k
}
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
17.4k
{
667
17.4k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
668
17.4k
    const int sh = intermediate_bits + 6;
669
17.4k
    const int rnd = (32 << intermediate_bits) + PREP_BIAS * 64;
670
272k
    do {
671
5.44M
        for (int x = 0; x < w; x++)
672
5.17M
            dst[x] = iclip_pixel((tmp1[x] * mask[x] +
673
5.17M
                                  tmp2[x] * (64 - mask[x]) + rnd) >> sh);
674
675
272k
        tmp1 += w;
676
272k
        tmp2 += w;
677
272k
        mask += w;
678
272k
        dst += PXSTRIDE(dst_stride);
679
272k
    } while (--h);
680
17.4k
}
681
682
16.0M
#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
20.9k
{
686
212k
    do {
687
2.93M
        for (int x = 0; x < w; x++) {
688
2.72M
            dst[x] = blend_px(dst[x], tmp[x], mask[x]);
689
2.72M
        }
690
212k
        dst += PXSTRIDE(dst_stride);
691
212k
        tmp += w;
692
212k
        mask += w;
693
212k
    } while (--h);
694
20.9k
}
695
696
static void blend_v_c(pixel *dst, const ptrdiff_t dst_stride, const pixel *tmp,
697
                      const int w, int h)
698
67.5k
{
699
67.5k
    const uint8_t *const mask = &dav1d_obmc_masks[w];
700
805k
    do {
701
5.22M
        for (int x = 0; x < (w * 3) >> 2; x++) {
702
4.42M
            dst[x] = blend_px(dst[x], tmp[x], mask[x]);
703
4.42M
        }
704
805k
        dst += PXSTRIDE(dst_stride);
705
805k
        tmp += w;
706
805k
    } while (--h);
707
67.5k
}
708
709
static void blend_h_c(pixel *dst, const ptrdiff_t dst_stride, const pixel *tmp,
710
                      const int w, int h)
711
114k
{
712
114k
    const uint8_t *mask = &dav1d_obmc_masks[h];
713
114k
    h = (h * 3) >> 2;
714
740k
    do {
715
740k
        const int m = *mask++;
716
9.62M
        for (int x = 0; x < w; x++) {
717
8.88M
            dst[x] = blend_px(dst[x], tmp[x], m);
718
8.88M
        }
719
740k
        dst += PXSTRIDE(dst_stride);
720
740k
        tmp += w;
721
740k
    } while (--h);
722
114k
}
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
5.91k
{
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
5.91k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
732
5.91k
    const int bitdepth = bitdepth_from_max(bitdepth_max);
733
5.91k
    const int sh = intermediate_bits + 6;
734
5.91k
    const int rnd = (32 << intermediate_bits) + PREP_BIAS * 64;
735
5.91k
    const int mask_sh = bitdepth + intermediate_bits - 4;
736
5.91k
    const int mask_rnd = 1 << (mask_sh - 5);
737
229k
    do {
738
7.37M
        for (int x = 0; x < w; x++) {
739
7.14M
            const int tmpdiff = tmp1[x] - tmp2[x];
740
7.14M
            const int m = imin(38 + ((abs(tmpdiff) + mask_rnd) >> mask_sh), 64);
741
7.14M
            dst[x] = iclip_pixel((tmpdiff * m + tmp2[x] * 64 + rnd) >> sh);
742
743
7.14M
            if (ss_hor) {
744
2.13M
                x++;
745
746
2.13M
                const int tmpdiff = tmp1[x] - tmp2[x];
747
2.13M
                const int n = imin(38 + ((abs(tmpdiff) + mask_rnd) >> mask_sh), 64);
748
2.13M
                dst[x] = iclip_pixel((tmpdiff * n + tmp2[x] * 64 + rnd) >> sh);
749
750
2.13M
                if (h & ss_ver) {
751
834k
                    mask[x >> 1] = (m + n + mask[x >> 1] + 2 - sign) >> 2;
752
1.29M
                } else if (ss_ver) {
753
834k
                    mask[x >> 1] = m + n;
754
834k
                } else {
755
463k
                    mask[x >> 1] = (m + n + 1 - sign) >> 1;
756
463k
                }
757
5.00M
            } else {
758
5.00M
                mask[x] = m;
759
5.00M
            }
760
7.14M
        }
761
762
229k
        tmp1 += w;
763
229k
        tmp2 += w;
764
229k
        dst += PXSTRIDE(dst_stride);
765
229k
        if (!ss_ver || (h & 1)) mask += w >> ss_hor;
766
229k
    } while (--h);
767
5.91k
}
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
5.91k
                             const int sign HIGHBD_DECL_SUFFIX) \
774
5.91k
{ \
775
5.91k
    w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver \
776
5.91k
             HIGHBD_TAIL_SUFFIX); \
777
5.91k
}
mc_tmpl.c:w_mask_444_c
Line
Count
Source
773
2.05k
                             const int sign HIGHBD_DECL_SUFFIX) \
774
2.05k
{ \
775
2.05k
    w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver \
776
2.05k
             HIGHBD_TAIL_SUFFIX); \
777
2.05k
}
mc_tmpl.c:w_mask_422_c
Line
Count
Source
773
668
                             const int sign HIGHBD_DECL_SUFFIX) \
774
668
{ \
775
668
    w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver \
776
668
             HIGHBD_TAIL_SUFFIX); \
777
668
}
mc_tmpl.c:w_mask_420_c
Line
Count
Source
773
3.20k
                             const int sign HIGHBD_DECL_SUFFIX) \
774
3.20k
{ \
775
3.20k
    w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver \
776
3.20k
             HIGHBD_TAIL_SUFFIX); \
777
3.20k
}
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
80.1M
    ((F[0] * src[x - 3 * stride] + \
787
80.1M
      F[1] * src[x - 2 * stride] + \
788
80.1M
      F[2] * src[x - 1 * stride] + \
789
80.1M
      F[3] * src[x + 0 * stride] + \
790
80.1M
      F[4] * src[x + 1 * stride] + \
791
80.1M
      F[5] * src[x + 2 * stride] + \
792
80.1M
      F[6] * src[x + 3 * stride] + \
793
80.1M
      F[7] * src[x + 4 * stride] + \
794
80.1M
      ((1 << (sh)) >> 1)) >> (sh))
795
796
#define FILTER_WARP_CLIP(src, x, F, stride, sh) \
797
15.9M
    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
269k
{
804
269k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
805
269k
    int16_t mid[15 * 8], *mid_ptr = mid;
806
807
269k
    src -= 3 * PXSTRIDE(src_stride);
808
4.23M
    for (int y = 0; y < 15; y++, mx += abcd[1]) {
809
34.9M
        for (int x = 0, tmx = mx; x < 8; x++, tmx += abcd[0]) {
810
30.9M
            const int8_t *const filter =
811
30.9M
                dav1d_mc_warp_filter[64 + ((tmx + 512) >> 10)];
812
813
30.9M
            mid_ptr[x] = FILTER_WARP_RND(src, x, filter, 1,
814
30.9M
                                         7 - intermediate_bits);
815
30.9M
        }
816
3.96M
        src += PXSTRIDE(src_stride);
817
3.96M
        mid_ptr += 8;
818
3.96M
    }
819
820
269k
    mid_ptr = &mid[3 * 8];
821
2.28M
    for (int y = 0; y < 8; y++, my += abcd[3]) {
822
17.9M
        for (int x = 0, tmy = my; x < 8; x++, tmy += abcd[2]) {
823
15.9M
            const int8_t *const filter =
824
15.9M
                dav1d_mc_warp_filter[64 + ((tmy + 512) >> 10)];
825
826
15.9M
            dst[x] = FILTER_WARP_CLIP(mid_ptr, x, filter, 8,
827
15.9M
                                      7 + intermediate_bits);
828
15.9M
        }
829
2.01M
        mid_ptr += 8;
830
2.01M
        dst += PXSTRIDE(dst_stride);
831
2.01M
    }
832
269k
}
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
189k
{
839
189k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
840
189k
    int16_t mid[15 * 8], *mid_ptr = mid;
841
842
189k
    src -= 3 * PXSTRIDE(src_stride);
843
2.96M
    for (int y = 0; y < 15; y++, mx += abcd[1]) {
844
24.2M
        for (int x = 0, tmx = mx; x < 8; x++, tmx += abcd[0]) {
845
21.5M
            const int8_t *const filter =
846
21.5M
                dav1d_mc_warp_filter[64 + ((tmx + 512) >> 10)];
847
848
21.5M
            mid_ptr[x] = FILTER_WARP_RND(src, x, filter, 1,
849
21.5M
                                         7 - intermediate_bits);
850
21.5M
        }
851
2.77M
        src += PXSTRIDE(src_stride);
852
2.77M
        mid_ptr += 8;
853
2.77M
    }
854
855
189k
    mid_ptr = &mid[3 * 8];
856
1.69M
    for (int y = 0; y < 8; y++, my += abcd[3]) {
857
13.2M
        for (int x = 0, tmy = my; x < 8; x++, tmy += abcd[2]) {
858
11.7M
            const int8_t *const filter =
859
11.7M
                dav1d_mc_warp_filter[64 + ((tmy + 512) >> 10)];
860
861
11.7M
            tmp[x] = FILTER_WARP_RND(mid_ptr, x, filter, 8, 7) - PREP_BIAS;
862
11.7M
        }
863
1.50M
        mid_ptr += 8;
864
1.50M
        tmp += tmp_stride;
865
1.50M
    }
866
189k
}
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
1.51M
{
874
    // find offset in reference of visible block to copy
875
1.51M
    ref += iclip((int) y, 0, (int) ih - 1) * PXSTRIDE(ref_stride) +
876
1.51M
           iclip((int) x, 0, (int) iw - 1);
877
878
    // number of pixels to extend (left, right, top, bottom)
879
1.51M
    const int left_ext = iclip((int) -x, 0, (int) bw - 1);
880
1.51M
    const int right_ext = iclip((int) (x + bw - iw), 0, (int) bw - 1);
881
1.51M
    assert(left_ext + right_ext < bw);
882
1.51M
    const int top_ext = iclip((int) -y, 0, (int) bh - 1);
883
1.51M
    const int bottom_ext = iclip((int) (y + bh - ih), 0, (int) bh - 1);
884
1.51M
    assert(top_ext + bottom_ext < bh);
885
886
    // copy visible portion first
887
1.51M
    pixel *blk = dst + top_ext * PXSTRIDE(dst_stride);
888
1.51M
    const int center_w = (int) (bw - left_ext - right_ext);
889
1.51M
    const int center_h = (int) (bh - top_ext - bottom_ext);
890
23.2M
    for (int y = 0; y < center_h; y++) {
891
21.7M
        pixel_copy(blk + left_ext, ref, center_w);
892
        // extend left edge for this line
893
21.7M
        if (left_ext)
894
5.60M
            pixel_set(blk, blk[left_ext], left_ext);
895
        // extend right edge for this line
896
21.7M
        if (right_ext)
897
18.2M
            pixel_set(blk + left_ext + center_w, blk[left_ext + center_w - 1],
898
18.2M
                      right_ext);
899
21.7M
        ref += PXSTRIDE(ref_stride);
900
21.7M
        blk += PXSTRIDE(dst_stride);
901
21.7M
    }
902
903
    // copy top
904
1.51M
    blk = dst + top_ext * PXSTRIDE(dst_stride);
905
2.83M
    for (int y = 0; y < top_ext; y++) {
906
1.31M
        pixel_copy(dst, blk, bw);
907
1.31M
        dst += PXSTRIDE(dst_stride);
908
1.31M
    }
909
910
    // copy bottom
911
1.51M
    dst += center_h * PXSTRIDE(dst_stride);
912
5.28M
    for (int y = 0; y < bottom_ext; y++) {
913
3.76M
        pixel_copy(dst, &dst[-PXSTRIDE(dst_stride)], bw);
914
3.76M
        dst += PXSTRIDE(dst_stride);
915
3.76M
    }
916
1.51M
}
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
103k
{
923
3.48M
    do {
924
3.48M
        int mx = mx0, src_x = -1;
925
177M
        for (int x = 0; x < dst_w; x++) {
926
173M
            const int8_t *const F = dav1d_resize_filter[mx >> 8];
927
173M
            dst[x] = iclip_pixel((-(F[0] * src[iclip(src_x - 3, 0, src_w - 1)] +
928
173M
                                    F[1] * src[iclip(src_x - 2, 0, src_w - 1)] +
929
173M
                                    F[2] * src[iclip(src_x - 1, 0, src_w - 1)] +
930
173M
                                    F[3] * src[iclip(src_x + 0, 0, src_w - 1)] +
931
173M
                                    F[4] * src[iclip(src_x + 1, 0, src_w - 1)] +
932
173M
                                    F[5] * src[iclip(src_x + 2, 0, src_w - 1)] +
933
173M
                                    F[6] * src[iclip(src_x + 3, 0, src_w - 1)] +
934
173M
                                    F[7] * src[iclip(src_x + 4, 0, src_w - 1)]) +
935
173M
                                  64) >> 7);
936
173M
            mx += dx;
937
173M
            src_x += mx >> 14;
938
173M
            mx &= 0x3fff;
939
173M
        }
940
941
3.48M
        dst += PXSTRIDE(dst_stride);
942
3.48M
        src += PXSTRIDE(src_stride);
943
3.48M
    } while (--h);
944
103k
}
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
30.8k
COLD void bitfn(dav1d_mc_dsp_init)(Dav1dMCDSPContext *const c) {
961
308k
#define init_mc_fns(type, name) do { \
962
308k
    c->mc        [type] = put_##name##_c; \
963
308k
    c->mc_scaled [type] = put_##name##_scaled_c; \
964
308k
    c->mct       [type] = prep_##name##_c; \
965
308k
    c->mct_scaled[type] = prep_##name##_scaled_c; \
966
308k
} while (0)
967
968
30.8k
    init_mc_fns(FILTER_2D_8TAP_REGULAR,        8tap_regular);
969
30.8k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SMOOTH, 8tap_regular_smooth);
970
30.8k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SHARP,  8tap_regular_sharp);
971
30.8k
    init_mc_fns(FILTER_2D_8TAP_SHARP_REGULAR,  8tap_sharp_regular);
972
30.8k
    init_mc_fns(FILTER_2D_8TAP_SHARP_SMOOTH,   8tap_sharp_smooth);
973
30.8k
    init_mc_fns(FILTER_2D_8TAP_SHARP,          8tap_sharp);
974
30.8k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_REGULAR, 8tap_smooth_regular);
975
30.8k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH,         8tap_smooth);
976
30.8k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_SHARP,   8tap_smooth_sharp);
977
30.8k
    init_mc_fns(FILTER_2D_BILINEAR,            bilin);
978
979
30.8k
    c->avg      = avg_c;
980
30.8k
    c->w_avg    = w_avg_c;
981
30.8k
    c->mask     = mask_c;
982
30.8k
    c->blend    = blend_c;
983
30.8k
    c->blend_v  = blend_v_c;
984
30.8k
    c->blend_h  = blend_h_c;
985
30.8k
    c->w_mask[0] = w_mask_444_c;
986
30.8k
    c->w_mask[1] = w_mask_422_c;
987
30.8k
    c->w_mask[2] = w_mask_420_c;
988
30.8k
    c->warp8x8  = warp_affine_8x8_c;
989
30.8k
    c->warp8x8t = warp_affine_8x8t_c;
990
30.8k
    c->emu_edge = emu_edge_c;
991
30.8k
    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
30.8k
}
dav1d_mc_dsp_init_8bpc
Line
Count
Source
960
14.4k
COLD void bitfn(dav1d_mc_dsp_init)(Dav1dMCDSPContext *const c) {
961
14.4k
#define init_mc_fns(type, name) do { \
962
14.4k
    c->mc        [type] = put_##name##_c; \
963
14.4k
    c->mc_scaled [type] = put_##name##_scaled_c; \
964
14.4k
    c->mct       [type] = prep_##name##_c; \
965
14.4k
    c->mct_scaled[type] = prep_##name##_scaled_c; \
966
14.4k
} while (0)
967
968
14.4k
    init_mc_fns(FILTER_2D_8TAP_REGULAR,        8tap_regular);
969
14.4k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SMOOTH, 8tap_regular_smooth);
970
14.4k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SHARP,  8tap_regular_sharp);
971
14.4k
    init_mc_fns(FILTER_2D_8TAP_SHARP_REGULAR,  8tap_sharp_regular);
972
14.4k
    init_mc_fns(FILTER_2D_8TAP_SHARP_SMOOTH,   8tap_sharp_smooth);
973
14.4k
    init_mc_fns(FILTER_2D_8TAP_SHARP,          8tap_sharp);
974
14.4k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_REGULAR, 8tap_smooth_regular);
975
14.4k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH,         8tap_smooth);
976
14.4k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_SHARP,   8tap_smooth_sharp);
977
14.4k
    init_mc_fns(FILTER_2D_BILINEAR,            bilin);
978
979
14.4k
    c->avg      = avg_c;
980
14.4k
    c->w_avg    = w_avg_c;
981
14.4k
    c->mask     = mask_c;
982
14.4k
    c->blend    = blend_c;
983
14.4k
    c->blend_v  = blend_v_c;
984
14.4k
    c->blend_h  = blend_h_c;
985
14.4k
    c->w_mask[0] = w_mask_444_c;
986
14.4k
    c->w_mask[1] = w_mask_422_c;
987
14.4k
    c->w_mask[2] = w_mask_420_c;
988
14.4k
    c->warp8x8  = warp_affine_8x8_c;
989
14.4k
    c->warp8x8t = warp_affine_8x8t_c;
990
14.4k
    c->emu_edge = emu_edge_c;
991
14.4k
    c->resize   = resize_c;
992
993
#if HAVE_ASM
994
#if ARCH_AARCH64 || ARCH_ARM
995
    mc_dsp_init_arm(c);
996
#elif ARCH_LOONGARCH64
997
    mc_dsp_init_loongarch(c);
998
#elif ARCH_PPC64LE
999
    mc_dsp_init_ppc(c);
1000
#elif ARCH_RISCV
1001
    mc_dsp_init_riscv(c);
1002
#elif ARCH_X86
1003
    mc_dsp_init_x86(c);
1004
#endif
1005
#endif
1006
14.4k
}
dav1d_mc_dsp_init_16bpc
Line
Count
Source
960
16.4k
COLD void bitfn(dav1d_mc_dsp_init)(Dav1dMCDSPContext *const c) {
961
16.4k
#define init_mc_fns(type, name) do { \
962
16.4k
    c->mc        [type] = put_##name##_c; \
963
16.4k
    c->mc_scaled [type] = put_##name##_scaled_c; \
964
16.4k
    c->mct       [type] = prep_##name##_c; \
965
16.4k
    c->mct_scaled[type] = prep_##name##_scaled_c; \
966
16.4k
} while (0)
967
968
16.4k
    init_mc_fns(FILTER_2D_8TAP_REGULAR,        8tap_regular);
969
16.4k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SMOOTH, 8tap_regular_smooth);
970
16.4k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SHARP,  8tap_regular_sharp);
971
16.4k
    init_mc_fns(FILTER_2D_8TAP_SHARP_REGULAR,  8tap_sharp_regular);
972
16.4k
    init_mc_fns(FILTER_2D_8TAP_SHARP_SMOOTH,   8tap_sharp_smooth);
973
16.4k
    init_mc_fns(FILTER_2D_8TAP_SHARP,          8tap_sharp);
974
16.4k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_REGULAR, 8tap_smooth_regular);
975
16.4k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH,         8tap_smooth);
976
16.4k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_SHARP,   8tap_smooth_sharp);
977
16.4k
    init_mc_fns(FILTER_2D_BILINEAR,            bilin);
978
979
16.4k
    c->avg      = avg_c;
980
16.4k
    c->w_avg    = w_avg_c;
981
16.4k
    c->mask     = mask_c;
982
16.4k
    c->blend    = blend_c;
983
16.4k
    c->blend_v  = blend_v_c;
984
16.4k
    c->blend_h  = blend_h_c;
985
16.4k
    c->w_mask[0] = w_mask_444_c;
986
16.4k
    c->w_mask[1] = w_mask_422_c;
987
16.4k
    c->w_mask[2] = w_mask_420_c;
988
16.4k
    c->warp8x8  = warp_affine_8x8_c;
989
16.4k
    c->warp8x8t = warp_affine_8x8t_c;
990
16.4k
    c->emu_edge = emu_edge_c;
991
16.4k
    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
16.4k
}