Coverage Report

Created: 2026-06-15 06:24

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
291k
#define get_intermediate_bits(bitdepth_max) 4
41
// Output in interval [-5132, 9212], fits in int16_t as is
42
19.2M
#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
34.6k
{
55
530k
    do {
56
530k
        pixel_copy(dst, src, w);
57
58
530k
        dst += dst_stride;
59
530k
        src += src_stride;
60
530k
    } while (--h);
61
34.6k
}
62
63
static NOINLINE void
64
prep_c(int16_t *tmp, const pixel *src, const ptrdiff_t src_stride,
65
       const int w, int h HIGHBD_DECL_SUFFIX)
66
8.55k
{
67
8.55k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
68
117k
    do {
69
2.09M
        for (int x = 0; x < w; x++)
70
1.97M
            tmp[x] = (src[x] << intermediate_bits) - PREP_BIAS;
71
72
117k
        tmp += w;
73
117k
        src += src_stride;
74
117k
    } while (--h);
75
8.55k
}
76
77
#define FILTER_8TAP(src, x, F, stride) \
78
25.0M
    (F[0] * src[x + -3 * stride] + \
79
25.0M
     F[1] * src[x + -2 * stride] + \
80
25.0M
     F[2] * src[x + -1 * stride] + \
81
25.0M
     F[3] * src[x + +0 * stride] + \
82
25.0M
     F[4] * src[x + +1 * stride] + \
83
25.0M
     F[5] * src[x + +2 * stride] + \
84
25.0M
     F[6] * src[x + +3 * stride] + \
85
25.0M
     F[7] * src[x + +4 * stride])
86
87
#define FILTER_8TAP2(src, x, F) \
88
26.2M
    (F[0] * src[0][x] + \
89
26.2M
     F[1] * src[1][x] + \
90
26.2M
     F[2] * src[2][x] + \
91
26.2M
     F[3] * src[3][x] + \
92
26.2M
     F[4] * src[4][x] + \
93
26.2M
     F[5] * src[5][x] + \
94
26.2M
     F[6] * src[6][x] + \
95
26.2M
     F[7] * src[7][x])
96
97
#define DAV1D_FILTER_8TAP_RND(src, x, F, stride, sh) \
98
24.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
844k
    ((FILTER_8TAP(src, x, F, stride) + (rnd)) >> (sh))
102
103
#define DAV1D_FILTER_8TAP_RND3(src, x, F, sh) \
104
26.2M
    ((FILTER_8TAP2(src, x, F) + ((1 << (sh)) >> 1)) >> (sh))
105
106
#define DAV1D_FILTER_8TAP_CLIP(src, x, F, stride, sh) \
107
3.01M
    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
844k
    iclip_pixel(DAV1D_FILTER_8TAP_RND2(src, x, F, stride, rnd, sh))
111
112
#define DAV1D_FILTER_8TAP_CLIP3(src, x, F, sh) \
113
15.8M
    iclip_pixel(DAV1D_FILTER_8TAP_RND3(src, x, F, sh))
114
115
#define GET_H_FILTER(mx) \
116
16.7M
    const int8_t *const fh = !(mx) ? NULL : w > 4 ? \
117
15.0M
        dav1d_mc_subpel_filters[filter_type & 3][(mx) - 1] : \
118
15.0M
        dav1d_mc_subpel_filters[3 + (filter_type & 1)][(mx) - 1]
119
120
#define GET_V_FILTER(my) \
121
1.37M
    const int8_t *const fv = !(my) ? NULL : h > 4 ? \
122
1.25M
        dav1d_mc_subpel_filters[filter_type >> 2][(my) - 1] : \
123
1.25M
        dav1d_mc_subpel_filters[3 + ((filter_type >> 2) & 1)][(my) - 1]
124
125
#define GET_FILTERS() \
126
63.0k
    GET_H_FILTER(mx); \
127
63.0k
    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
46.6k
{
135
46.6k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
136
46.6k
    const int intermediate_rnd = 32 + ((1 << (6 - intermediate_bits)) >> 1);
137
138
46.6k
    GET_FILTERS();
139
46.6k
    dst_stride = PXSTRIDE(dst_stride);
140
46.6k
    src_stride = PXSTRIDE(src_stride);
141
142
46.6k
    if (fh) {
143
22.3k
        if (fv) {
144
14.4k
            int tmp_h = h + 7;
145
14.4k
            int16_t mid[128 * 135], *mid_ptr = mid;
146
147
14.4k
            src -= src_stride * 3;
148
252k
            do {
149
3.00M
                for (int x = 0; x < w; x++)
150
2.74M
                    mid_ptr[x] = DAV1D_FILTER_8TAP_RND(src, x, fh, 1,
151
252k
                                                       6 - intermediate_bits);
152
153
252k
                mid_ptr += 128;
154
252k
                src += src_stride;
155
252k
            } while (--tmp_h);
156
157
14.4k
            mid_ptr = mid + 128 * 3;
158
151k
            do {
159
2.04M
                for (int x = 0; x < w; x++)
160
1.89M
                    dst[x] = DAV1D_FILTER_8TAP_CLIP(mid_ptr, x, fv, 128,
161
151k
                                                    6 + intermediate_bits);
162
163
151k
                mid_ptr += 128;
164
151k
                dst += dst_stride;
165
151k
            } while (--h);
166
14.4k
        } else {
167
78.5k
            do {
168
923k
                for (int x = 0; x < w; x++) {
169
844k
                    dst[x] = DAV1D_FILTER_8TAP_CLIP2(src, x, fh, 1,
170
844k
                                                     intermediate_rnd, 6);
171
844k
                }
172
173
78.5k
                dst += dst_stride;
174
78.5k
                src += src_stride;
175
78.5k
            } while (--h);
176
7.91k
        }
177
24.3k
    } else if (fv) {
178
82.7k
        do {
179
1.20M
            for (int x = 0; x < w; x++)
180
1.11M
                dst[x] = DAV1D_FILTER_8TAP_CLIP(src, x, fv, src_stride, 6);
181
182
82.7k
            dst += dst_stride;
183
82.7k
            src += src_stride;
184
82.7k
        } while (--h);
185
7.75k
    } else
186
16.5k
        put_c(dst, dst_stride, src, src_stride, w, h);
187
46.6k
}
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
62.5k
{
196
62.5k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
197
62.5k
    const int intermediate_rnd = (1 << intermediate_bits) >> 1;
198
62.5k
    int16_t mid[128 * 8];
199
62.5k
    int16_t *mid_ptrs[8];
200
62.5k
    int in_y = -8;
201
62.5k
    src_stride = PXSTRIDE(src_stride);
202
203
563k
    for (int i = 0; i < 8; i++)
204
500k
        mid_ptrs[i] = &mid[128 * i];
205
206
62.5k
    src -= src_stride * 3;
207
208
883k
    for (int y = 0; y < h; y++) {
209
820k
        int x;
210
820k
        int src_y = my >> 10;
211
820k
        GET_V_FILTER((my & 0x3ff) >> 6);
212
213
1.54M
        while (in_y < src_y) {
214
722k
            int imx = mx, ioff = 0;
215
722k
            int16_t *mid_ptr = mid_ptrs[0];
216
217
5.77M
            for (int i = 0; i < 7; i++)
218
5.05M
                mid_ptrs[i] = mid_ptrs[i + 1];
219
722k
            mid_ptrs[7] = mid_ptr;
220
221
11.0M
            for (x = 0; x < w; x++) {
222
10.3M
                GET_H_FILTER(imx >> 6);
223
10.3M
                mid_ptr[x] = fh ? DAV1D_FILTER_8TAP_RND(src, ioff, fh, 1,
224
10.3M
                                                        6 - intermediate_bits) :
225
10.3M
                                  src[ioff] << intermediate_bits;
226
10.3M
                imx += dx;
227
10.3M
                ioff += imx >> 10;
228
10.3M
                imx &= 0x3ff;
229
10.3M
            }
230
231
722k
            src += src_stride;
232
722k
            in_y++;
233
722k
        }
234
235
17.9M
        for (x = 0; x < w; x++)
236
17.1M
            dst[x] = fv ? DAV1D_FILTER_8TAP_CLIP3(mid_ptrs, x, fv,
237
17.1M
                                                  6 + intermediate_bits) :
238
17.1M
                          iclip_pixel((mid_ptrs[3][x] + intermediate_rnd) >>
239
1.29M
                                              intermediate_bits);
240
241
820k
        my += dy;
242
820k
        dst += PXSTRIDE(dst_stride);
243
820k
    }
244
62.5k
}
245
246
static NOINLINE void
247
prep_8tap_c(int16_t *tmp, const pixel *src, ptrdiff_t src_stride,
248
            const int w, int h, const int mx, const int my,
249
            const int filter_type HIGHBD_DECL_SUFFIX)
250
16.4k
{
251
16.4k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
252
16.4k
    GET_FILTERS();
253
16.4k
    src_stride = PXSTRIDE(src_stride);
254
255
16.4k
    if (fh) {
256
7.95k
        if (fv) {
257
5.05k
            int tmp_h = h + 7;
258
5.05k
            int16_t mid[128 * 135], *mid_ptr = mid;
259
260
5.05k
            src -= src_stride * 3;
261
110k
            do {
262
1.57M
                for (int x = 0; x < w; x++)
263
1.46M
                    mid_ptr[x] = DAV1D_FILTER_8TAP_RND(src, x, fh, 1,
264
110k
                                                       6 - intermediate_bits);
265
266
110k
                mid_ptr += 128;
267
110k
                src += src_stride;
268
110k
            } while (--tmp_h);
269
270
5.05k
            mid_ptr = mid + 128 * 3;
271
75.5k
            do {
272
1.16M
                for (int x = 0; x < w; x++) {
273
1.09M
                    int t = DAV1D_FILTER_8TAP_RND(mid_ptr, x, fv, 128, 6) -
274
1.09M
                                  PREP_BIAS;
275
1.09M
                    assert(t >= INT16_MIN && t <= INT16_MAX);
276
1.09M
                    tmp[x] = t;
277
1.09M
                }
278
279
75.5k
                mid_ptr += 128;
280
75.5k
                tmp += w;
281
75.5k
            } while (--h);
282
5.05k
        } else {
283
42.1k
            do {
284
573k
                for (int x = 0; x < w; x++)
285
531k
                    tmp[x] = DAV1D_FILTER_8TAP_RND(src, x, fh, 1,
286
531k
                                                   6 - intermediate_bits) -
287
531k
                             PREP_BIAS;
288
289
42.1k
                tmp += w;
290
42.1k
                src += src_stride;
291
42.1k
            } while (--h);
292
2.90k
        }
293
8.46k
    } else if (fv) {
294
31.4k
        do {
295
375k
            for (int x = 0; x < w; x++)
296
344k
                tmp[x] = DAV1D_FILTER_8TAP_RND(src, x, fv, src_stride,
297
344k
                                               6 - intermediate_bits) -
298
344k
                         PREP_BIAS;
299
300
31.4k
            tmp += w;
301
31.4k
            src += src_stride;
302
31.4k
        } while (--h);
303
2.46k
    } else
304
6.00k
        prep_c(tmp, src, src_stride, w, h HIGHBD_TAIL_SUFFIX);
305
16.4k
}
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
23.5k
{
313
23.5k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
314
23.5k
    int16_t mid[128 * 8];
315
23.5k
    int16_t *mid_ptrs[8];
316
23.5k
    int in_y = -8;
317
23.5k
    src_stride = PXSTRIDE(src_stride);
318
319
211k
    for (int i = 0; i < 8; i++)
320
188k
        mid_ptrs[i] = &mid[128 * i];
321
322
23.5k
    src -= src_stride * 3;
323
324
519k
    for (int y = 0; y < h; y++) {
325
495k
        int x;
326
495k
        int src_y = my >> 10;
327
495k
        GET_V_FILTER((my & 0x3ff) >> 6);
328
329
823k
        while (in_y < src_y) {
330
327k
            int imx = mx, ioff = 0;
331
327k
            int16_t *mid_ptr = mid_ptrs[0];
332
333
2.62M
            for (int i = 0; i < 7; i++)
334
2.29M
                mid_ptrs[i] = mid_ptrs[i + 1];
335
327k
            mid_ptrs[7] = mid_ptr;
336
337
6.63M
            for (x = 0; x < w; x++) {
338
6.30M
                GET_H_FILTER(imx >> 6);
339
6.30M
                mid_ptr[x] = fh ? DAV1D_FILTER_8TAP_RND(src, ioff, fh, 1,
340
6.30M
                                                        6 - intermediate_bits) :
341
6.30M
                                  src[ioff] << intermediate_bits;
342
6.30M
                imx += dx;
343
6.30M
                ioff += imx >> 10;
344
6.30M
                imx &= 0x3ff;
345
6.30M
            }
346
347
327k
            src += src_stride;
348
327k
            in_y++;
349
327k
        }
350
351
11.9M
        for (x = 0; x < w; x++)
352
11.4M
            tmp[x] = (fv ? DAV1D_FILTER_8TAP_RND3(mid_ptrs, x, fv, 6)
353
11.4M
                         : mid_ptrs[3][x]) - PREP_BIAS;
354
355
495k
        my += dy;
356
495k
        tmp += w;
357
495k
    }
358
23.5k
}
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
46.6k
                                HIGHBD_DECL_SUFFIX) \
368
46.6k
{ \
369
46.6k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
46.6k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
46.6k
} \
mc_tmpl.c:put_8tap_regular_c
Line
Count
Source
367
27.2k
                                HIGHBD_DECL_SUFFIX) \
368
27.2k
{ \
369
27.2k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
27.2k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
27.2k
} \
mc_tmpl.c:put_8tap_regular_smooth_c
Line
Count
Source
367
3.46k
                                HIGHBD_DECL_SUFFIX) \
368
3.46k
{ \
369
3.46k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
3.46k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
3.46k
} \
mc_tmpl.c:put_8tap_regular_sharp_c
Line
Count
Source
367
831
                                HIGHBD_DECL_SUFFIX) \
368
831
{ \
369
831
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
831
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
831
} \
mc_tmpl.c:put_8tap_sharp_regular_c
Line
Count
Source
367
579
                                HIGHBD_DECL_SUFFIX) \
368
579
{ \
369
579
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
579
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
579
} \
mc_tmpl.c:put_8tap_sharp_smooth_c
Line
Count
Source
367
236
                                HIGHBD_DECL_SUFFIX) \
368
236
{ \
369
236
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
236
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
236
} \
mc_tmpl.c:put_8tap_sharp_c
Line
Count
Source
367
4.12k
                                HIGHBD_DECL_SUFFIX) \
368
4.12k
{ \
369
4.12k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
4.12k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
4.12k
} \
mc_tmpl.c:put_8tap_smooth_regular_c
Line
Count
Source
367
2.32k
                                HIGHBD_DECL_SUFFIX) \
368
2.32k
{ \
369
2.32k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
2.32k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
2.32k
} \
mc_tmpl.c:put_8tap_smooth_c
Line
Count
Source
367
7.29k
                                HIGHBD_DECL_SUFFIX) \
368
7.29k
{ \
369
7.29k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
7.29k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
7.29k
} \
mc_tmpl.c:put_8tap_smooth_sharp_c
Line
Count
Source
367
531
                                HIGHBD_DECL_SUFFIX) \
368
531
{ \
369
531
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
531
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
531
} \
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
62.5k
                                       HIGHBD_DECL_SUFFIX) \
380
62.5k
{ \
381
62.5k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
62.5k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
62.5k
} \
mc_tmpl.c:put_8tap_regular_scaled_c
Line
Count
Source
379
34.2k
                                       HIGHBD_DECL_SUFFIX) \
380
34.2k
{ \
381
34.2k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
34.2k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
34.2k
} \
mc_tmpl.c:put_8tap_regular_smooth_scaled_c
Line
Count
Source
379
1.81k
                                       HIGHBD_DECL_SUFFIX) \
380
1.81k
{ \
381
1.81k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
1.81k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
1.81k
} \
mc_tmpl.c:put_8tap_regular_sharp_scaled_c
Line
Count
Source
379
290
                                       HIGHBD_DECL_SUFFIX) \
380
290
{ \
381
290
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
290
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
290
} \
mc_tmpl.c:put_8tap_sharp_regular_scaled_c
Line
Count
Source
379
687
                                       HIGHBD_DECL_SUFFIX) \
380
687
{ \
381
687
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
687
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
687
} \
mc_tmpl.c:put_8tap_sharp_smooth_scaled_c
Line
Count
Source
379
496
                                       HIGHBD_DECL_SUFFIX) \
380
496
{ \
381
496
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
496
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
496
} \
mc_tmpl.c:put_8tap_sharp_scaled_c
Line
Count
Source
379
13.5k
                                       HIGHBD_DECL_SUFFIX) \
380
13.5k
{ \
381
13.5k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
13.5k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
13.5k
} \
mc_tmpl.c:put_8tap_smooth_regular_scaled_c
Line
Count
Source
379
1.28k
                                       HIGHBD_DECL_SUFFIX) \
380
1.28k
{ \
381
1.28k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
1.28k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
1.28k
} \
mc_tmpl.c:put_8tap_smooth_scaled_c
Line
Count
Source
379
10.0k
                                       HIGHBD_DECL_SUFFIX) \
380
10.0k
{ \
381
10.0k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
10.0k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
10.0k
} \
mc_tmpl.c:put_8tap_smooth_sharp_scaled_c
Line
Count
Source
379
214
                                       HIGHBD_DECL_SUFFIX) \
380
214
{ \
381
214
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
214
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
214
} \
384
static void prep_8tap_##type##_c(int16_t *const tmp, \
385
                                 const pixel *const src, \
386
                                 const ptrdiff_t src_stride, \
387
                                 const int w, const int h, \
388
                                 const int mx, const int my \
389
16.4k
                                 HIGHBD_DECL_SUFFIX) \
390
16.4k
{ \
391
16.4k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
16.4k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
16.4k
} \
mc_tmpl.c:prep_8tap_regular_c
Line
Count
Source
389
6.45k
                                 HIGHBD_DECL_SUFFIX) \
390
6.45k
{ \
391
6.45k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
6.45k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
6.45k
} \
mc_tmpl.c:prep_8tap_regular_smooth_c
Line
Count
Source
389
325
                                 HIGHBD_DECL_SUFFIX) \
390
325
{ \
391
325
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
325
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
325
} \
mc_tmpl.c:prep_8tap_regular_sharp_c
Line
Count
Source
389
864
                                 HIGHBD_DECL_SUFFIX) \
390
864
{ \
391
864
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
864
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
864
} \
mc_tmpl.c:prep_8tap_sharp_regular_c
Line
Count
Source
389
1.27k
                                 HIGHBD_DECL_SUFFIX) \
390
1.27k
{ \
391
1.27k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
1.27k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
1.27k
} \
mc_tmpl.c:prep_8tap_sharp_smooth_c
Line
Count
Source
389
697
                                 HIGHBD_DECL_SUFFIX) \
390
697
{ \
391
697
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
697
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
697
} \
mc_tmpl.c:prep_8tap_sharp_c
Line
Count
Source
389
2.37k
                                 HIGHBD_DECL_SUFFIX) \
390
2.37k
{ \
391
2.37k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
2.37k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
2.37k
} \
mc_tmpl.c:prep_8tap_smooth_regular_c
Line
Count
Source
389
764
                                 HIGHBD_DECL_SUFFIX) \
390
764
{ \
391
764
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
764
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
764
} \
mc_tmpl.c:prep_8tap_smooth_c
Line
Count
Source
389
3.00k
                                 HIGHBD_DECL_SUFFIX) \
390
3.00k
{ \
391
3.00k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
3.00k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
3.00k
} \
mc_tmpl.c:prep_8tap_smooth_sharp_c
Line
Count
Source
389
676
                                 HIGHBD_DECL_SUFFIX) \
390
676
{ \
391
676
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
676
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
676
} \
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
23.5k
                                        HIGHBD_DECL_SUFFIX) \
401
23.5k
{ \
402
23.5k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
23.5k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
23.5k
}
mc_tmpl.c:prep_8tap_regular_scaled_c
Line
Count
Source
400
10.9k
                                        HIGHBD_DECL_SUFFIX) \
401
10.9k
{ \
402
10.9k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
10.9k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
10.9k
}
mc_tmpl.c:prep_8tap_regular_smooth_scaled_c
Line
Count
Source
400
256
                                        HIGHBD_DECL_SUFFIX) \
401
256
{ \
402
256
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
256
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
256
}
mc_tmpl.c:prep_8tap_regular_sharp_scaled_c
Line
Count
Source
400
727
                                        HIGHBD_DECL_SUFFIX) \
401
727
{ \
402
727
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
727
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
727
}
mc_tmpl.c:prep_8tap_sharp_regular_scaled_c
Line
Count
Source
400
1.55k
                                        HIGHBD_DECL_SUFFIX) \
401
1.55k
{ \
402
1.55k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
1.55k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
1.55k
}
mc_tmpl.c:prep_8tap_sharp_smooth_scaled_c
Line
Count
Source
400
709
                                        HIGHBD_DECL_SUFFIX) \
401
709
{ \
402
709
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
709
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
709
}
mc_tmpl.c:prep_8tap_sharp_scaled_c
Line
Count
Source
400
1.72k
                                        HIGHBD_DECL_SUFFIX) \
401
1.72k
{ \
402
1.72k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
1.72k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
1.72k
}
mc_tmpl.c:prep_8tap_smooth_regular_scaled_c
Line
Count
Source
400
674
                                        HIGHBD_DECL_SUFFIX) \
401
674
{ \
402
674
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
674
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
674
}
mc_tmpl.c:prep_8tap_smooth_scaled_c
Line
Count
Source
400
6.29k
                                        HIGHBD_DECL_SUFFIX) \
401
6.29k
{ \
402
6.29k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
6.29k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
6.29k
}
mc_tmpl.c:prep_8tap_smooth_sharp_scaled_c
Line
Count
Source
400
672
                                        HIGHBD_DECL_SUFFIX) \
401
672
{ \
402
672
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
672
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
672
}
405
406
filter_fns(regular,        DAV1D_FILTER_8TAP_REGULAR, DAV1D_FILTER_8TAP_REGULAR)
407
filter_fns(regular_sharp,  DAV1D_FILTER_8TAP_REGULAR, DAV1D_FILTER_8TAP_SHARP)
408
filter_fns(regular_smooth, DAV1D_FILTER_8TAP_REGULAR, DAV1D_FILTER_8TAP_SMOOTH)
409
filter_fns(smooth,         DAV1D_FILTER_8TAP_SMOOTH,  DAV1D_FILTER_8TAP_SMOOTH)
410
filter_fns(smooth_regular, DAV1D_FILTER_8TAP_SMOOTH,  DAV1D_FILTER_8TAP_REGULAR)
411
filter_fns(smooth_sharp,   DAV1D_FILTER_8TAP_SMOOTH,  DAV1D_FILTER_8TAP_SHARP)
412
filter_fns(sharp,          DAV1D_FILTER_8TAP_SHARP,   DAV1D_FILTER_8TAP_SHARP)
413
filter_fns(sharp_regular,  DAV1D_FILTER_8TAP_SHARP,   DAV1D_FILTER_8TAP_REGULAR)
414
filter_fns(sharp_smooth,   DAV1D_FILTER_8TAP_SHARP,   DAV1D_FILTER_8TAP_SMOOTH)
415
416
#define FILTER_BILIN(src, x, mxy, stride) \
417
6.59M
    (16 * src[x] + ((mxy) * (src[x + stride] - src[x])))
418
419
#define FILTER_BILIN_RND(src, x, mxy, stride, sh) \
420
6.59M
    ((FILTER_BILIN(src, x, mxy, stride) + ((1 << (sh)) >> 1)) >> (sh))
421
422
#define FILTER_BILIN_CLIP(src, x, mxy, stride, sh) \
423
1.21M
    iclip_pixel(FILTER_BILIN_RND(src, x, mxy, stride, sh))
424
425
#define FILTER_BILIN2(src1, src2, x, mxy) \
426
7.44M
    (16 * src1[x] + ((mxy) * (src2[x] - src1[x])))
427
428
#define FILTER_BILIN_RND2(src1, src2, x, mxy, sh) \
429
7.44M
    ((FILTER_BILIN2(src1, src2, x, mxy) + ((1 << (sh)) >> 1)) >> (sh))
430
431
#define FILTER_BILIN_CLIP2(src1, src2, x, mxy, sh) \
432
5.33M
    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
27.5k
{
439
27.5k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
440
27.5k
    const int intermediate_rnd = (1 << intermediate_bits) >> 1;
441
27.5k
    dst_stride = PXSTRIDE(dst_stride);
442
27.5k
    src_stride = PXSTRIDE(src_stride);
443
444
27.5k
    if (mx) {
445
6.33k
        if (my) {
446
4.10k
            int16_t mid[128 * 129], *mid_ptr = mid;
447
4.10k
            int tmp_h = h + 1;
448
449
41.7k
            do {
450
665k
                for (int x = 0; x < w; x++)
451
624k
                    mid_ptr[x] = FILTER_BILIN_RND(src, x, mx, 1,
452
41.7k
                                                  4 - intermediate_bits);
453
454
41.7k
                mid_ptr += 128;
455
41.7k
                src += src_stride;
456
41.7k
            } while (--tmp_h);
457
458
4.10k
            mid_ptr = mid;
459
37.8k
            do {
460
633k
                for (int x = 0; x < w; x++)
461
596k
                    dst[x] = FILTER_BILIN_CLIP(mid_ptr, x, my, 128,
462
37.8k
                                               4 + intermediate_bits);
463
464
37.8k
                mid_ptr += 128;
465
37.8k
                dst += dst_stride;
466
37.8k
            } while (--h);
467
4.10k
        } else {
468
17.6k
            do {
469
339k
                for (int x = 0; x < w; x++) {
470
321k
                    const int px = FILTER_BILIN_RND(src, x, mx, 1,
471
321k
                                                    4 - intermediate_bits);
472
321k
                    dst[x] = iclip_pixel((px + intermediate_rnd) >> intermediate_bits);
473
321k
                }
474
475
17.6k
                dst += dst_stride;
476
17.6k
                src += src_stride;
477
17.6k
            } while (--h);
478
2.23k
        }
479
21.1k
    } else if (my) {
480
28.7k
        do {
481
648k
            for (int x = 0; x < w; x++)
482
619k
                dst[x] = FILTER_BILIN_CLIP(src, x, my, src_stride, 4);
483
484
28.7k
            dst += dst_stride;
485
28.7k
            src += src_stride;
486
28.7k
        } while (--h);
487
3.06k
    } else
488
18.1k
        put_c(dst, dst_stride, src, src_stride, w, h);
489
27.5k
}
490
491
static void put_bilin_scaled_c(pixel *dst, ptrdiff_t dst_stride,
492
                               const pixel *src, ptrdiff_t src_stride,
493
                               const int w, int h, const int mx, int my,
494
                               const int dx, const int dy
495
                               HIGHBD_DECL_SUFFIX)
496
23.3k
{
497
23.3k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
498
23.3k
    int16_t mid[128 * 2];
499
23.3k
    int in_y = -2;
500
501
263k
    do {
502
263k
        int x;
503
263k
        int y = my >> 10;
504
263k
        int16_t *mid1 = &mid[(y & 1) * 128];
505
263k
        int16_t *mid2 = &mid[((y + 1) & 1) * 128];
506
263k
        int dmy = my & 0x3ff;
507
508
365k
        while (in_y < y) {
509
102k
            int imx = mx, ioff = 0;
510
102k
            int16_t *mid_ptr = &mid[(in_y & 1) * 128];
511
512
2.19M
            for (x = 0; x < w; x++) {
513
2.09M
                mid_ptr[x] = FILTER_BILIN_RND(src, ioff, imx >> 6, 1,
514
2.09M
                                              4 - intermediate_bits);
515
2.09M
                imx += dx;
516
2.09M
                ioff += imx >> 10;
517
2.09M
                imx &= 0x3ff;
518
2.09M
            }
519
520
102k
            src += PXSTRIDE(src_stride);
521
102k
            in_y++;
522
102k
        }
523
524
5.60M
        for (x = 0; x < w; x++)
525
5.33M
            dst[x] = FILTER_BILIN_CLIP2(mid1, mid2, x, dmy >> 6,
526
263k
                                       4 + intermediate_bits);
527
528
263k
        my += dy;
529
263k
        dst += PXSTRIDE(dst_stride);
530
263k
    } while (--h);
531
23.3k
}
532
533
static void prep_bilin_c(int16_t *tmp,
534
                         const pixel *src, ptrdiff_t src_stride,
535
                         const int w, int h, const int mx, const int my
536
                         HIGHBD_DECL_SUFFIX)
537
7.42k
{
538
7.42k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
539
7.42k
    src_stride = PXSTRIDE(src_stride);
540
541
7.42k
    if (mx) {
542
3.42k
        if (my) {
543
2.27k
            int16_t mid[128 * 129], *mid_ptr = mid;
544
2.27k
            int tmp_h = h + 1;
545
546
27.9k
            do {
547
433k
                for (int x = 0; x < w; x++)
548
406k
                    mid_ptr[x] = FILTER_BILIN_RND(src, x, mx, 1,
549
27.9k
                                                  4 - intermediate_bits);
550
551
27.9k
                mid_ptr += 128;
552
27.9k
                src += src_stride;
553
27.9k
            } while (--tmp_h);
554
555
2.27k
            mid_ptr = mid;
556
25.6k
            do {
557
412k
                for (int x = 0; x < w; x++)
558
387k
                    tmp[x] = FILTER_BILIN_RND(mid_ptr, x, my, 128, 4) -
559
387k
                             PREP_BIAS;
560
561
25.6k
                mid_ptr += 128;
562
25.6k
                tmp += w;
563
25.6k
            } while (--h);
564
2.27k
        } else {
565
14.9k
            do {
566
377k
                for (int x = 0; x < w; x++)
567
362k
                    tmp[x] = FILTER_BILIN_RND(src, x, mx, 1,
568
362k
                                              4 - intermediate_bits) -
569
362k
                             PREP_BIAS;
570
571
14.9k
                tmp += w;
572
14.9k
                src += src_stride;
573
14.9k
            } while (--h);
574
1.15k
        }
575
3.99k
    } else if (my) {
576
14.5k
        do {
577
151k
            for (int x = 0; x < w; x++)
578
137k
                tmp[x] = FILTER_BILIN_RND(src, x, my, src_stride,
579
137k
                                          4 - intermediate_bits) - PREP_BIAS;
580
581
14.5k
            tmp += w;
582
14.5k
            src += src_stride;
583
14.5k
        } while (--h);
584
1.44k
    } else
585
2.54k
        prep_c(tmp, src, src_stride, w, h HIGHBD_TAIL_SUFFIX);
586
7.42k
}
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
3.88k
{
593
3.88k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
594
3.88k
    int16_t mid[128 * 2];
595
3.88k
    int in_y = -2;
596
597
76.7k
    do {
598
76.7k
        int x;
599
76.7k
        int y = my >> 10;
600
76.7k
        int16_t *mid1 = &mid[(y & 1) * 128];
601
76.7k
        int16_t *mid2 = &mid[((y + 1) & 1) * 128];
602
76.7k
        int dmy = my & 0x3ff;
603
604
109k
        while (in_y < y) {
605
32.8k
            int imx = mx, ioff = 0;
606
32.8k
            int16_t *mid_ptr = &mid[(in_y & 1) * 128];
607
608
1.08M
            for (x = 0; x < w; x++) {
609
1.05M
                mid_ptr[x] = FILTER_BILIN_RND(src, ioff, imx >> 6, 1,
610
1.05M
                                              4 - intermediate_bits);
611
1.05M
                imx += dx;
612
1.05M
                ioff += imx >> 10;
613
1.05M
                imx &= 0x3ff;
614
1.05M
            }
615
616
32.8k
            src += PXSTRIDE(src_stride);
617
32.8k
            in_y++;
618
32.8k
        }
619
620
2.18M
        for (x = 0; x < w; x++)
621
2.11M
            tmp[x] = FILTER_BILIN_RND2(mid1, mid2, x, dmy >> 6, 4) - PREP_BIAS;
622
623
76.7k
        my += dy;
624
76.7k
        tmp += w;
625
76.7k
    } while (--h);
626
3.88k
}
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
16.9k
{
632
16.9k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
633
16.9k
    const int sh = intermediate_bits + 1;
634
16.9k
    const int rnd = (1 << intermediate_bits) + PREP_BIAS * 2;
635
288k
    do {
636
6.54M
        for (int x = 0; x < w; x++)
637
6.25M
            dst[x] = iclip_pixel((tmp1[x] + tmp2[x] + rnd) >> sh);
638
639
288k
        tmp1 += w;
640
288k
        tmp2 += w;
641
288k
        dst += PXSTRIDE(dst_stride);
642
288k
    } while (--h);
643
16.9k
}
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
3.58k
{
649
3.58k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
650
3.58k
    const int sh = intermediate_bits + 4;
651
3.58k
    const int rnd = (8 << intermediate_bits) + PREP_BIAS * 16;
652
45.4k
    do {
653
699k
        for (int x = 0; x < w; x++)
654
654k
            dst[x] = iclip_pixel((tmp1[x] * weight +
655
654k
                                  tmp2[x] * (16 - weight) + rnd) >> sh);
656
657
45.4k
        tmp1 += w;
658
45.4k
        tmp2 += w;
659
45.4k
        dst += PXSTRIDE(dst_stride);
660
45.4k
    } while (--h);
661
3.58k
}
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.63k
{
667
3.63k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
668
3.63k
    const int sh = intermediate_bits + 6;
669
3.63k
    const int rnd = (32 << intermediate_bits) + PREP_BIAS * 64;
670
61.1k
    do {
671
1.19M
        for (int x = 0; x < w; x++)
672
1.13M
            dst[x] = iclip_pixel((tmp1[x] * mask[x] +
673
1.13M
                                  tmp2[x] * (64 - mask[x]) + rnd) >> sh);
674
675
61.1k
        tmp1 += w;
676
61.1k
        tmp2 += w;
677
61.1k
        mask += w;
678
61.1k
        dst += PXSTRIDE(dst_stride);
679
61.1k
    } while (--h);
680
3.63k
}
681
682
2.49M
#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
5.20k
{
686
60.5k
    do {
687
791k
        for (int x = 0; x < w; x++) {
688
730k
            dst[x] = blend_px(dst[x], tmp[x], mask[x]);
689
730k
        }
690
60.5k
        dst += PXSTRIDE(dst_stride);
691
60.5k
        tmp += w;
692
60.5k
        mask += w;
693
60.5k
    } while (--h);
694
5.20k
}
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.1k
{
699
10.1k
    const uint8_t *const mask = &dav1d_obmc_masks[w];
700
152k
    do {
701
916k
        for (int x = 0; x < (w * 3) >> 2; x++) {
702
764k
            dst[x] = blend_px(dst[x], tmp[x], mask[x]);
703
764k
        }
704
152k
        dst += PXSTRIDE(dst_stride);
705
152k
        tmp += w;
706
152k
    } while (--h);
707
10.1k
}
708
709
static void blend_h_c(pixel *dst, const ptrdiff_t dst_stride, const pixel *tmp,
710
                      const int w, int h)
711
13.1k
{
712
13.1k
    const uint8_t *mask = &dav1d_obmc_masks[h];
713
13.1k
    h = (h * 3) >> 2;
714
78.0k
    do {
715
78.0k
        const int m = *mask++;
716
1.07M
        for (int x = 0; x < w; x++) {
717
998k
            dst[x] = blend_px(dst[x], tmp[x], m);
718
998k
        }
719
78.0k
        dst += PXSTRIDE(dst_stride);
720
78.0k
        tmp += w;
721
78.0k
    } while (--h);
722
13.1k
}
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
2.01k
{
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
2.01k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
732
2.01k
    const int bitdepth = bitdepth_from_max(bitdepth_max);
733
2.01k
    const int sh = intermediate_bits + 6;
734
2.01k
    const int rnd = (32 << intermediate_bits) + PREP_BIAS * 64;
735
2.01k
    const int mask_sh = bitdepth + intermediate_bits - 4;
736
2.01k
    const int mask_rnd = 1 << (mask_sh - 5);
737
64.0k
    do {
738
1.52M
        for (int x = 0; x < w; x++) {
739
1.45M
            const int tmpdiff = tmp1[x] - tmp2[x];
740
1.45M
            const int m = imin(38 + ((abs(tmpdiff) + mask_rnd) >> mask_sh), 64);
741
1.45M
            dst[x] = iclip_pixel((tmpdiff * m + tmp2[x] * 64 + rnd) >> sh);
742
743
1.45M
            if (ss_hor) {
744
183k
                x++;
745
746
183k
                const int tmpdiff = tmp1[x] - tmp2[x];
747
183k
                const int n = imin(38 + ((abs(tmpdiff) + mask_rnd) >> mask_sh), 64);
748
183k
                dst[x] = iclip_pixel((tmpdiff * n + tmp2[x] * 64 + rnd) >> sh);
749
750
183k
                if (h & ss_ver) {
751
90.7k
                    mask[x >> 1] = (m + n + mask[x >> 1] + 2 - sign) >> 2;
752
93.1k
                } else if (ss_ver) {
753
90.7k
                    mask[x >> 1] = m + n;
754
90.7k
                } else {
755
2.33k
                    mask[x >> 1] = (m + n + 1 - sign) >> 1;
756
2.33k
                }
757
1.27M
            } else {
758
1.27M
                mask[x] = m;
759
1.27M
            }
760
1.45M
        }
761
762
64.0k
        tmp1 += w;
763
64.0k
        tmp2 += w;
764
64.0k
        dst += PXSTRIDE(dst_stride);
765
64.0k
        if (!ss_ver || (h & 1)) mask += w >> ss_hor;
766
64.0k
    } while (--h);
767
2.01k
}
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
2.01k
                             const int sign HIGHBD_DECL_SUFFIX) \
774
2.01k
{ \
775
2.01k
    w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver \
776
2.01k
             HIGHBD_TAIL_SUFFIX); \
777
2.01k
}
mc_tmpl.c:w_mask_444_c
Line
Count
Source
773
1.52k
                             const int sign HIGHBD_DECL_SUFFIX) \
774
1.52k
{ \
775
1.52k
    w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver \
776
1.52k
             HIGHBD_TAIL_SUFFIX); \
777
1.52k
}
mc_tmpl.c:w_mask_422_c
Line
Count
Source
773
49
                             const int sign HIGHBD_DECL_SUFFIX) \
774
49
{ \
775
49
    w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver \
776
49
             HIGHBD_TAIL_SUFFIX); \
777
49
}
mc_tmpl.c:w_mask_420_c
Line
Count
Source
773
441
                             const int sign HIGHBD_DECL_SUFFIX) \
774
441
{ \
775
441
    w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver \
776
441
             HIGHBD_TAIL_SUFFIX); \
777
441
}
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
8.31M
    ((F[0] * src[x - 3 * stride] + \
787
8.31M
      F[1] * src[x - 2 * stride] + \
788
8.31M
      F[2] * src[x - 1 * stride] + \
789
8.31M
      F[3] * src[x + 0 * stride] + \
790
8.31M
      F[4] * src[x + 1 * stride] + \
791
8.31M
      F[5] * src[x + 2 * stride] + \
792
8.31M
      F[6] * src[x + 3 * stride] + \
793
8.31M
      F[7] * src[x + 4 * stride] + \
794
8.31M
      ((1 << (sh)) >> 1)) >> (sh))
795
796
#define FILTER_WARP_CLIP(src, x, F, stride, sh) \
797
2.08M
    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
32.8k
{
804
32.8k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
805
32.8k
    int16_t mid[15 * 8], *mid_ptr = mid;
806
807
32.8k
    src -= 3 * PXSTRIDE(src_stride);
808
523k
    for (int y = 0; y < 15; y++, mx += abcd[1]) {
809
4.38M
        for (int x = 0, tmx = mx; x < 8; x++, tmx += abcd[0]) {
810
3.89M
            const int8_t *const filter =
811
3.89M
                dav1d_mc_warp_filter[64 + ((tmx + 512) >> 10)];
812
813
3.89M
            mid_ptr[x] = FILTER_WARP_RND(src, x, filter, 1,
814
3.89M
                                         7 - intermediate_bits);
815
3.89M
        }
816
490k
        src += PXSTRIDE(src_stride);
817
490k
        mid_ptr += 8;
818
490k
    }
819
820
32.8k
    mid_ptr = &mid[3 * 8];
821
294k
    for (int y = 0; y < 8; y++, my += abcd[3]) {
822
2.34M
        for (int x = 0, tmy = my; x < 8; x++, tmy += abcd[2]) {
823
2.08M
            const int8_t *const filter =
824
2.08M
                dav1d_mc_warp_filter[64 + ((tmy + 512) >> 10)];
825
826
2.08M
            dst[x] = FILTER_WARP_CLIP(mid_ptr, x, filter, 8,
827
2.08M
                                      7 + intermediate_bits);
828
2.08M
        }
829
262k
        mid_ptr += 8;
830
262k
        dst += PXSTRIDE(dst_stride);
831
262k
    }
832
32.8k
}
833
834
static void warp_affine_8x8t_c(int16_t *tmp, const ptrdiff_t tmp_stride,
835
                               const pixel *src, const ptrdiff_t src_stride,
836
                               const int16_t *const abcd, int mx, int my
837
                               HIGHBD_DECL_SUFFIX)
838
12.6k
{
839
12.6k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
840
12.6k
    int16_t mid[15 * 8], *mid_ptr = mid;
841
842
12.6k
    src -= 3 * PXSTRIDE(src_stride);
843
202k
    for (int y = 0; y < 15; y++, mx += abcd[1]) {
844
1.70M
        for (int x = 0, tmx = mx; x < 8; x++, tmx += abcd[0]) {
845
1.51M
            const int8_t *const filter =
846
1.51M
                dav1d_mc_warp_filter[64 + ((tmx + 512) >> 10)];
847
848
1.51M
            mid_ptr[x] = FILTER_WARP_RND(src, x, filter, 1,
849
1.51M
                                         7 - intermediate_bits);
850
1.51M
        }
851
189k
        src += PXSTRIDE(src_stride);
852
189k
        mid_ptr += 8;
853
189k
    }
854
855
12.6k
    mid_ptr = &mid[3 * 8];
856
113k
    for (int y = 0; y < 8; y++, my += abcd[3]) {
857
911k
        for (int x = 0, tmy = my; x < 8; x++, tmy += abcd[2]) {
858
810k
            const int8_t *const filter =
859
810k
                dav1d_mc_warp_filter[64 + ((tmy + 512) >> 10)];
860
861
810k
            tmp[x] = FILTER_WARP_RND(mid_ptr, x, filter, 8, 7) - PREP_BIAS;
862
810k
        }
863
101k
        mid_ptr += 8;
864
101k
        tmp += tmp_stride;
865
101k
    }
866
12.6k
}
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
222k
{
874
    // find offset in reference of visible block to copy
875
222k
    ref += iclip((int) y, 0, (int) ih - 1) * PXSTRIDE(ref_stride) +
876
222k
           iclip((int) x, 0, (int) iw - 1);
877
878
    // number of pixels to extend (left, right, top, bottom)
879
222k
    const int left_ext = iclip((int) -x, 0, (int) bw - 1);
880
222k
    const int right_ext = iclip((int) (x + bw - iw), 0, (int) bw - 1);
881
222k
    assert(left_ext + right_ext < bw);
882
222k
    const int top_ext = iclip((int) -y, 0, (int) bh - 1);
883
222k
    const int bottom_ext = iclip((int) (y + bh - ih), 0, (int) bh - 1);
884
222k
    assert(top_ext + bottom_ext < bh);
885
886
    // copy visible portion first
887
222k
    pixel *blk = dst + top_ext * PXSTRIDE(dst_stride);
888
222k
    const int center_w = (int) (bw - left_ext - right_ext);
889
222k
    const int center_h = (int) (bh - top_ext - bottom_ext);
890
2.35M
    for (int y = 0; y < center_h; y++) {
891
2.13M
        pixel_copy(blk + left_ext, ref, center_w);
892
        // extend left edge for this line
893
2.13M
        if (left_ext)
894
859k
            pixel_set(blk, blk[left_ext], left_ext);
895
        // extend right edge for this line
896
2.13M
        if (right_ext)
897
1.57M
            pixel_set(blk + left_ext + center_w, blk[left_ext + center_w - 1],
898
1.57M
                      right_ext);
899
2.13M
        ref += PXSTRIDE(ref_stride);
900
2.13M
        blk += PXSTRIDE(dst_stride);
901
2.13M
    }
902
903
    // copy top
904
222k
    blk = dst + top_ext * PXSTRIDE(dst_stride);
905
495k
    for (int y = 0; y < top_ext; y++) {
906
272k
        pixel_copy(dst, blk, bw);
907
272k
        dst += PXSTRIDE(dst_stride);
908
272k
    }
909
910
    // copy bottom
911
222k
    dst += center_h * PXSTRIDE(dst_stride);
912
921k
    for (int y = 0; y < bottom_ext; y++) {
913
698k
        pixel_copy(dst, &dst[-PXSTRIDE(dst_stride)], bw);
914
698k
        dst += PXSTRIDE(dst_stride);
915
698k
    }
916
222k
}
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
68.9k
{
923
3.19M
    do {
924
3.19M
        int mx = mx0, src_x = -1;
925
225M
        for (int x = 0; x < dst_w; x++) {
926
222M
            const int8_t *const F = dav1d_resize_filter[mx >> 8];
927
222M
            dst[x] = iclip_pixel((-(F[0] * src[iclip(src_x - 3, 0, src_w - 1)] +
928
222M
                                    F[1] * src[iclip(src_x - 2, 0, src_w - 1)] +
929
222M
                                    F[2] * src[iclip(src_x - 1, 0, src_w - 1)] +
930
222M
                                    F[3] * src[iclip(src_x + 0, 0, src_w - 1)] +
931
222M
                                    F[4] * src[iclip(src_x + 1, 0, src_w - 1)] +
932
222M
                                    F[5] * src[iclip(src_x + 2, 0, src_w - 1)] +
933
222M
                                    F[6] * src[iclip(src_x + 3, 0, src_w - 1)] +
934
222M
                                    F[7] * src[iclip(src_x + 4, 0, src_w - 1)]) +
935
222M
                                  64) >> 7);
936
222M
            mx += dx;
937
222M
            src_x += mx >> 14;
938
222M
            mx &= 0x3fff;
939
222M
        }
940
941
3.19M
        dst += PXSTRIDE(dst_stride);
942
3.19M
        src += PXSTRIDE(src_stride);
943
3.19M
    } while (--h);
944
68.9k
}
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
38.2k
COLD void bitfn(dav1d_mc_dsp_init)(Dav1dMCDSPContext *const c) {
961
382k
#define init_mc_fns(type, name) do { \
962
382k
    c->mc        [type] = put_##name##_c; \
963
382k
    c->mc_scaled [type] = put_##name##_scaled_c; \
964
382k
    c->mct       [type] = prep_##name##_c; \
965
382k
    c->mct_scaled[type] = prep_##name##_scaled_c; \
966
382k
} while (0)
967
968
38.2k
    init_mc_fns(FILTER_2D_8TAP_REGULAR,        8tap_regular);
969
38.2k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SMOOTH, 8tap_regular_smooth);
970
38.2k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SHARP,  8tap_regular_sharp);
971
38.2k
    init_mc_fns(FILTER_2D_8TAP_SHARP_REGULAR,  8tap_sharp_regular);
972
38.2k
    init_mc_fns(FILTER_2D_8TAP_SHARP_SMOOTH,   8tap_sharp_smooth);
973
38.2k
    init_mc_fns(FILTER_2D_8TAP_SHARP,          8tap_sharp);
974
38.2k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_REGULAR, 8tap_smooth_regular);
975
38.2k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH,         8tap_smooth);
976
38.2k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_SHARP,   8tap_smooth_sharp);
977
38.2k
    init_mc_fns(FILTER_2D_BILINEAR,            bilin);
978
979
38.2k
    c->avg      = avg_c;
980
38.2k
    c->w_avg    = w_avg_c;
981
38.2k
    c->mask     = mask_c;
982
38.2k
    c->blend    = blend_c;
983
38.2k
    c->blend_v  = blend_v_c;
984
38.2k
    c->blend_h  = blend_h_c;
985
38.2k
    c->w_mask[0] = w_mask_444_c;
986
38.2k
    c->w_mask[1] = w_mask_422_c;
987
38.2k
    c->w_mask[2] = w_mask_420_c;
988
38.2k
    c->warp8x8  = warp_affine_8x8_c;
989
38.2k
    c->warp8x8t = warp_affine_8x8t_c;
990
38.2k
    c->emu_edge = emu_edge_c;
991
38.2k
    c->resize   = resize_c;
992
993
#if HAVE_ASM
994
#if ARCH_AARCH64 || ARCH_ARM
995
    mc_dsp_init_arm(c);
996
#elif ARCH_LOONGARCH64
997
    mc_dsp_init_loongarch(c);
998
#elif ARCH_PPC64LE
999
    mc_dsp_init_ppc(c);
1000
#elif ARCH_RISCV
1001
    mc_dsp_init_riscv(c);
1002
#elif ARCH_X86
1003
    mc_dsp_init_x86(c);
1004
#endif
1005
#endif
1006
38.2k
}
dav1d_mc_dsp_init_8bpc
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
}
dav1d_mc_dsp_init_16bpc
Line
Count
Source
960
21.8k
COLD void bitfn(dav1d_mc_dsp_init)(Dav1dMCDSPContext *const c) {
961
21.8k
#define init_mc_fns(type, name) do { \
962
21.8k
    c->mc        [type] = put_##name##_c; \
963
21.8k
    c->mc_scaled [type] = put_##name##_scaled_c; \
964
21.8k
    c->mct       [type] = prep_##name##_c; \
965
21.8k
    c->mct_scaled[type] = prep_##name##_scaled_c; \
966
21.8k
} while (0)
967
968
21.8k
    init_mc_fns(FILTER_2D_8TAP_REGULAR,        8tap_regular);
969
21.8k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SMOOTH, 8tap_regular_smooth);
970
21.8k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SHARP,  8tap_regular_sharp);
971
21.8k
    init_mc_fns(FILTER_2D_8TAP_SHARP_REGULAR,  8tap_sharp_regular);
972
21.8k
    init_mc_fns(FILTER_2D_8TAP_SHARP_SMOOTH,   8tap_sharp_smooth);
973
21.8k
    init_mc_fns(FILTER_2D_8TAP_SHARP,          8tap_sharp);
974
21.8k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_REGULAR, 8tap_smooth_regular);
975
21.8k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH,         8tap_smooth);
976
21.8k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_SHARP,   8tap_smooth_sharp);
977
21.8k
    init_mc_fns(FILTER_2D_BILINEAR,            bilin);
978
979
21.8k
    c->avg      = avg_c;
980
21.8k
    c->w_avg    = w_avg_c;
981
21.8k
    c->mask     = mask_c;
982
21.8k
    c->blend    = blend_c;
983
21.8k
    c->blend_v  = blend_v_c;
984
21.8k
    c->blend_h  = blend_h_c;
985
21.8k
    c->w_mask[0] = w_mask_444_c;
986
21.8k
    c->w_mask[1] = w_mask_422_c;
987
21.8k
    c->w_mask[2] = w_mask_420_c;
988
21.8k
    c->warp8x8  = warp_affine_8x8_c;
989
21.8k
    c->warp8x8t = warp_affine_8x8t_c;
990
21.8k
    c->emu_edge = emu_edge_c;
991
21.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
21.8k
}