Coverage Report

Created: 2026-09-01 06:57

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
4.86M
#define get_intermediate_bits(bitdepth_max) 4
41
// Output in interval [-5132, 9212], fits in int16_t as is
42
417M
#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
1.05M
{
55
16.2M
    do {
56
16.2M
        pixel_copy(dst, src, w);
57
58
16.2M
        dst += dst_stride;
59
16.2M
        src += src_stride;
60
16.2M
    } while (--h);
61
1.05M
}
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
155k
{
67
155k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
68
4.14M
    do {
69
132M
        for (int x = 0; x < w; x++)
70
127M
            tmp[x] = (src[x] << intermediate_bits) - PREP_BIAS;
71
72
4.14M
        tmp += w;
73
4.14M
        src += src_stride;
74
4.14M
    } while (--h);
75
155k
}
76
77
#define FILTER_8TAP(src, x, F, stride) \
78
685M
    (F[0] * src[x + -3 * stride] + \
79
685M
     F[1] * src[x + -2 * stride] + \
80
685M
     F[2] * src[x + -1 * stride] + \
81
685M
     F[3] * src[x + +0 * stride] + \
82
685M
     F[4] * src[x + +1 * stride] + \
83
685M
     F[5] * src[x + +2 * stride] + \
84
685M
     F[6] * src[x + +3 * stride] + \
85
685M
     F[7] * src[x + +4 * stride])
86
87
#define FILTER_8TAP2(src, x, F) \
88
539M
    (F[0] * src[0][x] + \
89
539M
     F[1] * src[1][x] + \
90
539M
     F[2] * src[2][x] + \
91
539M
     F[3] * src[3][x] + \
92
539M
     F[4] * src[4][x] + \
93
539M
     F[5] * src[5][x] + \
94
539M
     F[6] * src[6][x] + \
95
539M
     F[7] * src[7][x])
96
97
#define DAV1D_FILTER_8TAP_RND(src, x, F, stride, sh) \
98
661M
    ((FILTER_8TAP(src, x, F, stride) + ((1 << (sh)) >> 1)) >> (sh))
99
100
#define DAV1D_FILTER_8TAP_RND2(src, x, F, stride, rnd, sh) \
101
24.3M
    ((FILTER_8TAP(src, x, F, stride) + (rnd)) >> (sh))
102
103
#define DAV1D_FILTER_8TAP_RND3(src, x, F, sh) \
104
539M
    ((FILTER_8TAP2(src, x, F) + ((1 << (sh)) >> 1)) >> (sh))
105
106
#define DAV1D_FILTER_8TAP_CLIP(src, x, F, stride, sh) \
107
55.5M
    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
24.3M
    iclip_pixel(DAV1D_FILTER_8TAP_RND2(src, x, F, stride, rnd, sh))
111
112
#define DAV1D_FILTER_8TAP_CLIP3(src, x, F, sh) \
113
362M
    iclip_pixel(DAV1D_FILTER_8TAP_RND3(src, x, F, sh))
114
115
#define GET_H_FILTER(mx) \
116
519M
    const int8_t *const fh = !(mx) ? NULL : w > 4 ? \
117
483M
        dav1d_mc_subpel_filters[filter_type & 3][(mx) - 1] : \
118
483M
        dav1d_mc_subpel_filters[3 + (filter_type & 1)][(mx) - 1]
119
120
#define GET_V_FILTER(my) \
121
26.3M
    const int8_t *const fv = !(my) ? NULL : h > 4 ? \
122
23.1M
        dav1d_mc_subpel_filters[filter_type >> 2][(my) - 1] : \
123
23.1M
        dav1d_mc_subpel_filters[3 + ((filter_type >> 2) & 1)][(my) - 1]
124
125
#define GET_FILTERS() \
126
1.09M
    GET_H_FILTER(mx); \
127
1.09M
    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
850k
{
135
850k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
136
850k
    const int intermediate_rnd = 32 + ((1 << (6 - intermediate_bits)) >> 1);
137
138
850k
    GET_FILTERS();
139
850k
    dst_stride = PXSTRIDE(dst_stride);
140
850k
    src_stride = PXSTRIDE(src_stride);
141
142
850k
    if (fh) {
143
259k
        if (fv) {
144
174k
            int tmp_h = h + 7;
145
174k
            int16_t mid[128 * 135], *mid_ptr = mid;
146
147
174k
            src -= src_stride * 3;
148
2.98M
            do {
149
48.9M
                for (int x = 0; x < w; x++)
150
45.9M
                    mid_ptr[x] = DAV1D_FILTER_8TAP_RND(src, x, fh, 1,
151
2.98M
                                                       6 - intermediate_bits);
152
153
2.98M
                mid_ptr += 128;
154
2.98M
                src += src_stride;
155
2.98M
            } while (--tmp_h);
156
157
174k
            mid_ptr = mid + 128 * 3;
158
1.78M
            do {
159
36.7M
                for (int x = 0; x < w; x++)
160
35.0M
                    dst[x] = DAV1D_FILTER_8TAP_CLIP(mid_ptr, x, fv, 128,
161
1.78M
                                                    6 + intermediate_bits);
162
163
1.78M
                mid_ptr += 128;
164
1.78M
                dst += dst_stride;
165
1.78M
            } while (--h);
166
174k
        } else {
167
897k
            do {
168
25.2M
                for (int x = 0; x < w; x++) {
169
24.3M
                    dst[x] = DAV1D_FILTER_8TAP_CLIP2(src, x, fh, 1,
170
24.3M
                                                     intermediate_rnd, 6);
171
24.3M
                }
172
173
897k
                dst += dst_stride;
174
897k
                src += src_stride;
175
897k
            } while (--h);
176
84.4k
        }
177
591k
    } else if (fv) {
178
1.02M
        do {
179
21.5M
            for (int x = 0; x < w; x++)
180
20.5M
                dst[x] = DAV1D_FILTER_8TAP_CLIP(src, x, fv, src_stride, 6);
181
182
1.02M
            dst += dst_stride;
183
1.02M
            src += src_stride;
184
1.02M
        } while (--h);
185
114k
    } else
186
476k
        put_c(dst, dst_stride, src, src_stride, w, h);
187
850k
}
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
1.36M
{
196
1.36M
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
197
1.36M
    const int intermediate_rnd = (1 << intermediate_bits) >> 1;
198
1.36M
    int16_t mid[128 * 8];
199
1.36M
    int16_t *mid_ptrs[8];
200
1.36M
    int in_y = -8;
201
1.36M
    src_stride = PXSTRIDE(src_stride);
202
203
12.3M
    for (int i = 0; i < 8; i++)
204
10.9M
        mid_ptrs[i] = &mid[128 * i];
205
206
1.36M
    src -= src_stride * 3;
207
208
19.3M
    for (int y = 0; y < h; y++) {
209
17.9M
        int x;
210
17.9M
        int src_y = my >> 10;
211
17.9M
        GET_V_FILTER((my & 0x3ff) >> 6);
212
213
37.4M
        while (in_y < src_y) {
214
19.4M
            int imx = mx, ioff = 0;
215
19.4M
            int16_t *mid_ptr = mid_ptrs[0];
216
217
155M
            for (int i = 0; i < 7; i++)
218
136M
                mid_ptrs[i] = mid_ptrs[i + 1];
219
19.4M
            mid_ptrs[7] = mid_ptr;
220
221
372M
            for (x = 0; x < w; x++) {
222
353M
                GET_H_FILTER(imx >> 6);
223
353M
                mid_ptr[x] = fh ? DAV1D_FILTER_8TAP_RND(src, ioff, fh, 1,
224
353M
                                                        6 - intermediate_bits) :
225
353M
                                  src[ioff] << intermediate_bits;
226
353M
                imx += dx;
227
353M
                ioff += imx >> 10;
228
353M
                imx &= 0x3ff;
229
353M
            }
230
231
19.4M
            src += src_stride;
232
19.4M
            in_y++;
233
19.4M
        }
234
235
418M
        for (x = 0; x < w; x++)
236
400M
            dst[x] = fv ? DAV1D_FILTER_8TAP_CLIP3(mid_ptrs, x, fv,
237
400M
                                                  6 + intermediate_bits) :
238
400M
                          iclip_pixel((mid_ptrs[3][x] + intermediate_rnd) >>
239
37.7M
                                              intermediate_bits);
240
241
17.9M
        my += dy;
242
17.9M
        dst += PXSTRIDE(dst_stride);
243
17.9M
    }
244
1.36M
}
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
245k
{
251
245k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
252
245k
    GET_FILTERS();
253
245k
    src_stride = PXSTRIDE(src_stride);
254
255
245k
    if (fh) {
256
79.9k
        if (fv) {
257
55.8k
            int tmp_h = h + 7;
258
55.8k
            int16_t mid[128 * 135], *mid_ptr = mid;
259
260
55.8k
            src -= src_stride * 3;
261
1.36M
            do {
262
27.3M
                for (int x = 0; x < w; x++)
263
26.0M
                    mid_ptr[x] = DAV1D_FILTER_8TAP_RND(src, x, fh, 1,
264
1.36M
                                                       6 - intermediate_bits);
265
266
1.36M
                mid_ptr += 128;
267
1.36M
                src += src_stride;
268
1.36M
            } while (--tmp_h);
269
270
55.8k
            mid_ptr = mid + 128 * 3;
271
972k
            do {
272
22.2M
                for (int x = 0; x < w; x++) {
273
21.3M
                    int t = DAV1D_FILTER_8TAP_RND(mid_ptr, x, fv, 128, 6) -
274
21.3M
                                  PREP_BIAS;
275
21.3M
                    assert(t >= INT16_MIN && t <= INT16_MAX);
276
21.3M
                    tmp[x] = t;
277
21.3M
                }
278
279
972k
                mid_ptr += 128;
280
972k
                tmp += w;
281
972k
            } while (--h);
282
55.8k
        } else {
283
594k
            do {
284
21.6M
                for (int x = 0; x < w; x++)
285
21.0M
                    tmp[x] = DAV1D_FILTER_8TAP_RND(src, x, fh, 1,
286
21.0M
                                                   6 - intermediate_bits) -
287
21.0M
                             PREP_BIAS;
288
289
594k
                tmp += w;
290
594k
                src += src_stride;
291
594k
            } while (--h);
292
24.1k
        }
293
165k
    } else if (fv) {
294
344k
        do {
295
8.05M
            for (int x = 0; x < w; x++)
296
7.71M
                tmp[x] = DAV1D_FILTER_8TAP_RND(src, x, fv, src_stride,
297
7.71M
                                               6 - intermediate_bits) -
298
7.71M
                         PREP_BIAS;
299
300
344k
            tmp += w;
301
344k
            src += src_stride;
302
344k
        } while (--h);
303
21.1k
    } else
304
144k
        prep_c(tmp, src, src_stride, w, h HIGHBD_TAIL_SUFFIX);
305
245k
}
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
361k
{
313
361k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
314
361k
    int16_t mid[128 * 8];
315
361k
    int16_t *mid_ptrs[8];
316
361k
    int in_y = -8;
317
361k
    src_stride = PXSTRIDE(src_stride);
318
319
3.25M
    for (int i = 0; i < 8; i++)
320
2.89M
        mid_ptrs[i] = &mid[128 * i];
321
322
361k
    src -= src_stride * 3;
323
324
7.59M
    for (int y = 0; y < h; y++) {
325
7.23M
        int x;
326
7.23M
        int src_y = my >> 10;
327
7.23M
        GET_V_FILTER((my & 0x3ff) >> 6);
328
329
13.5M
        while (in_y < src_y) {
330
6.34M
            int imx = mx, ioff = 0;
331
6.34M
            int16_t *mid_ptr = mid_ptrs[0];
332
333
50.7M
            for (int i = 0; i < 7; i++)
334
44.4M
                mid_ptrs[i] = mid_ptrs[i + 1];
335
6.34M
            mid_ptrs[7] = mid_ptr;
336
337
171M
            for (x = 0; x < w; x++) {
338
165M
                GET_H_FILTER(imx >> 6);
339
165M
                mid_ptr[x] = fh ? DAV1D_FILTER_8TAP_RND(src, ioff, fh, 1,
340
165M
                                                        6 - intermediate_bits) :
341
165M
                                  src[ioff] << intermediate_bits;
342
165M
                imx += dx;
343
165M
                ioff += imx >> 10;
344
165M
                imx &= 0x3ff;
345
165M
            }
346
347
6.34M
            src += src_stride;
348
6.34M
            in_y++;
349
6.34M
        }
350
351
218M
        for (x = 0; x < w; x++)
352
211M
            tmp[x] = (fv ? DAV1D_FILTER_8TAP_RND3(mid_ptrs, x, fv, 6)
353
211M
                         : mid_ptrs[3][x]) - PREP_BIAS;
354
355
7.23M
        my += dy;
356
7.23M
        tmp += w;
357
7.23M
    }
358
361k
}
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
850k
                                HIGHBD_DECL_SUFFIX) \
368
850k
{ \
369
850k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
850k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
850k
} \
mc_tmpl.c:put_8tap_regular_c
Line
Count
Source
367
343k
                                HIGHBD_DECL_SUFFIX) \
368
343k
{ \
369
343k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
343k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
343k
} \
mc_tmpl.c:put_8tap_regular_smooth_c
Line
Count
Source
367
14.5k
                                HIGHBD_DECL_SUFFIX) \
368
14.5k
{ \
369
14.5k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
14.5k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
14.5k
} \
mc_tmpl.c:put_8tap_regular_sharp_c
Line
Count
Source
367
3.52k
                                HIGHBD_DECL_SUFFIX) \
368
3.52k
{ \
369
3.52k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
3.52k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
3.52k
} \
mc_tmpl.c:put_8tap_sharp_regular_c
Line
Count
Source
367
3.69k
                                HIGHBD_DECL_SUFFIX) \
368
3.69k
{ \
369
3.69k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
3.69k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
3.69k
} \
mc_tmpl.c:put_8tap_sharp_smooth_c
Line
Count
Source
367
1.75k
                                HIGHBD_DECL_SUFFIX) \
368
1.75k
{ \
369
1.75k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
1.75k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
1.75k
} \
mc_tmpl.c:put_8tap_sharp_c
Line
Count
Source
367
54.2k
                                HIGHBD_DECL_SUFFIX) \
368
54.2k
{ \
369
54.2k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
54.2k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
54.2k
} \
mc_tmpl.c:put_8tap_smooth_regular_c
Line
Count
Source
367
11.3k
                                HIGHBD_DECL_SUFFIX) \
368
11.3k
{ \
369
11.3k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
11.3k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
11.3k
} \
mc_tmpl.c:put_8tap_smooth_c
Line
Count
Source
367
416k
                                HIGHBD_DECL_SUFFIX) \
368
416k
{ \
369
416k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
416k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
416k
} \
mc_tmpl.c:put_8tap_smooth_sharp_c
Line
Count
Source
367
1.50k
                                HIGHBD_DECL_SUFFIX) \
368
1.50k
{ \
369
1.50k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
1.50k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
1.50k
} \
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
1.36M
                                       HIGHBD_DECL_SUFFIX) \
380
1.36M
{ \
381
1.36M
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
1.36M
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
1.36M
} \
mc_tmpl.c:put_8tap_regular_scaled_c
Line
Count
Source
379
1.01M
                                       HIGHBD_DECL_SUFFIX) \
380
1.01M
{ \
381
1.01M
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
1.01M
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
1.01M
} \
mc_tmpl.c:put_8tap_regular_smooth_scaled_c
Line
Count
Source
379
62.7k
                                       HIGHBD_DECL_SUFFIX) \
380
62.7k
{ \
381
62.7k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
62.7k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
62.7k
} \
mc_tmpl.c:put_8tap_regular_sharp_scaled_c
Line
Count
Source
379
14.1k
                                       HIGHBD_DECL_SUFFIX) \
380
14.1k
{ \
381
14.1k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
14.1k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
14.1k
} \
mc_tmpl.c:put_8tap_sharp_regular_scaled_c
Line
Count
Source
379
18.4k
                                       HIGHBD_DECL_SUFFIX) \
380
18.4k
{ \
381
18.4k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
18.4k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
18.4k
} \
mc_tmpl.c:put_8tap_sharp_smooth_scaled_c
Line
Count
Source
379
4.13k
                                       HIGHBD_DECL_SUFFIX) \
380
4.13k
{ \
381
4.13k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
4.13k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
4.13k
} \
mc_tmpl.c:put_8tap_sharp_scaled_c
Line
Count
Source
379
68.5k
                                       HIGHBD_DECL_SUFFIX) \
380
68.5k
{ \
381
68.5k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
68.5k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
68.5k
} \
mc_tmpl.c:put_8tap_smooth_regular_scaled_c
Line
Count
Source
379
63.9k
                                       HIGHBD_DECL_SUFFIX) \
380
63.9k
{ \
381
63.9k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
63.9k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
63.9k
} \
mc_tmpl.c:put_8tap_smooth_scaled_c
Line
Count
Source
379
112k
                                       HIGHBD_DECL_SUFFIX) \
380
112k
{ \
381
112k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
112k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
112k
} \
mc_tmpl.c:put_8tap_smooth_sharp_scaled_c
Line
Count
Source
379
4.29k
                                       HIGHBD_DECL_SUFFIX) \
380
4.29k
{ \
381
4.29k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
4.29k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
4.29k
} \
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
245k
                                 HIGHBD_DECL_SUFFIX) \
390
245k
{ \
391
245k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
245k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
245k
} \
mc_tmpl.c:prep_8tap_regular_c
Line
Count
Source
389
76.5k
                                 HIGHBD_DECL_SUFFIX) \
390
76.5k
{ \
391
76.5k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
76.5k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
76.5k
} \
mc_tmpl.c:prep_8tap_regular_smooth_c
Line
Count
Source
389
2.52k
                                 HIGHBD_DECL_SUFFIX) \
390
2.52k
{ \
391
2.52k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
2.52k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
2.52k
} \
mc_tmpl.c:prep_8tap_regular_sharp_c
Line
Count
Source
389
4.78k
                                 HIGHBD_DECL_SUFFIX) \
390
4.78k
{ \
391
4.78k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
4.78k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
4.78k
} \
mc_tmpl.c:prep_8tap_sharp_regular_c
Line
Count
Source
389
8.37k
                                 HIGHBD_DECL_SUFFIX) \
390
8.37k
{ \
391
8.37k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
8.37k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
8.37k
} \
mc_tmpl.c:prep_8tap_sharp_smooth_c
Line
Count
Source
389
2.75k
                                 HIGHBD_DECL_SUFFIX) \
390
2.75k
{ \
391
2.75k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
2.75k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
2.75k
} \
mc_tmpl.c:prep_8tap_sharp_c
Line
Count
Source
389
38.5k
                                 HIGHBD_DECL_SUFFIX) \
390
38.5k
{ \
391
38.5k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
38.5k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
38.5k
} \
mc_tmpl.c:prep_8tap_smooth_regular_c
Line
Count
Source
389
2.53k
                                 HIGHBD_DECL_SUFFIX) \
390
2.53k
{ \
391
2.53k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
2.53k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
2.53k
} \
mc_tmpl.c:prep_8tap_smooth_c
Line
Count
Source
389
107k
                                 HIGHBD_DECL_SUFFIX) \
390
107k
{ \
391
107k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
107k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
107k
} \
mc_tmpl.c:prep_8tap_smooth_sharp_c
Line
Count
Source
389
2.08k
                                 HIGHBD_DECL_SUFFIX) \
390
2.08k
{ \
391
2.08k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
2.08k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
2.08k
} \
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
361k
                                        HIGHBD_DECL_SUFFIX) \
401
361k
{ \
402
361k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
361k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
361k
}
mc_tmpl.c:prep_8tap_regular_scaled_c
Line
Count
Source
400
147k
                                        HIGHBD_DECL_SUFFIX) \
401
147k
{ \
402
147k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
147k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
147k
}
mc_tmpl.c:prep_8tap_regular_smooth_scaled_c
Line
Count
Source
400
17.3k
                                        HIGHBD_DECL_SUFFIX) \
401
17.3k
{ \
402
17.3k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
17.3k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
17.3k
}
mc_tmpl.c:prep_8tap_regular_sharp_scaled_c
Line
Count
Source
400
21.5k
                                        HIGHBD_DECL_SUFFIX) \
401
21.5k
{ \
402
21.5k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
21.5k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
21.5k
}
mc_tmpl.c:prep_8tap_sharp_regular_scaled_c
Line
Count
Source
400
48.8k
                                        HIGHBD_DECL_SUFFIX) \
401
48.8k
{ \
402
48.8k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
48.8k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
48.8k
}
mc_tmpl.c:prep_8tap_sharp_smooth_scaled_c
Line
Count
Source
400
8.51k
                                        HIGHBD_DECL_SUFFIX) \
401
8.51k
{ \
402
8.51k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
8.51k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
8.51k
}
mc_tmpl.c:prep_8tap_sharp_scaled_c
Line
Count
Source
400
35.0k
                                        HIGHBD_DECL_SUFFIX) \
401
35.0k
{ \
402
35.0k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
35.0k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
35.0k
}
mc_tmpl.c:prep_8tap_smooth_regular_scaled_c
Line
Count
Source
400
28.5k
                                        HIGHBD_DECL_SUFFIX) \
401
28.5k
{ \
402
28.5k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
28.5k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
28.5k
}
mc_tmpl.c:prep_8tap_smooth_scaled_c
Line
Count
Source
400
47.2k
                                        HIGHBD_DECL_SUFFIX) \
401
47.2k
{ \
402
47.2k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
47.2k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
47.2k
}
mc_tmpl.c:prep_8tap_smooth_sharp_scaled_c
Line
Count
Source
400
7.19k
                                        HIGHBD_DECL_SUFFIX) \
401
7.19k
{ \
402
7.19k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
7.19k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
7.19k
}
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
97.4M
    (16 * src[x] + ((mxy) * (src[x + stride] - src[x])))
418
419
#define FILTER_BILIN_RND(src, x, mxy, stride, sh) \
420
97.4M
    ((FILTER_BILIN(src, x, mxy, stride) + ((1 << (sh)) >> 1)) >> (sh))
421
422
#define FILTER_BILIN_CLIP(src, x, mxy, stride, sh) \
423
22.2M
    iclip_pixel(FILTER_BILIN_RND(src, x, mxy, stride, sh))
424
425
#define FILTER_BILIN2(src1, src2, x, mxy) \
426
41.1M
    (16 * src1[x] + ((mxy) * (src2[x] - src1[x])))
427
428
#define FILTER_BILIN_RND2(src1, src2, x, mxy, sh) \
429
41.1M
    ((FILTER_BILIN2(src1, src2, x, mxy) + ((1 << (sh)) >> 1)) >> (sh))
430
431
#define FILTER_BILIN_CLIP2(src1, src2, x, mxy, sh) \
432
32.3M
    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
838k
{
439
838k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
440
838k
    const int intermediate_rnd = (1 << intermediate_bits) >> 1;
441
838k
    dst_stride = PXSTRIDE(dst_stride);
442
838k
    src_stride = PXSTRIDE(src_stride);
443
444
838k
    if (mx) {
445
184k
        if (my) {
446
96.8k
            int16_t mid[128 * 129], *mid_ptr = mid;
447
96.8k
            int tmp_h = h + 1;
448
449
890k
            do {
450
13.9M
                for (int x = 0; x < w; x++)
451
13.0M
                    mid_ptr[x] = FILTER_BILIN_RND(src, x, mx, 1,
452
890k
                                                  4 - intermediate_bits);
453
454
890k
                mid_ptr += 128;
455
890k
                src += src_stride;
456
890k
            } while (--tmp_h);
457
458
96.8k
            mid_ptr = mid;
459
793k
            do {
460
13.0M
                for (int x = 0; x < w; x++)
461
12.2M
                    dst[x] = FILTER_BILIN_CLIP(mid_ptr, x, my, 128,
462
793k
                                               4 + intermediate_bits);
463
464
793k
                mid_ptr += 128;
465
793k
                dst += dst_stride;
466
793k
            } while (--h);
467
96.8k
        } else {
468
863k
            do {
469
20.6M
                for (int x = 0; x < w; x++) {
470
19.8M
                    const int px = FILTER_BILIN_RND(src, x, mx, 1,
471
19.8M
                                                    4 - intermediate_bits);
472
19.8M
                    dst[x] = iclip_pixel((px + intermediate_rnd) >> intermediate_bits);
473
19.8M
                }
474
475
863k
                dst += dst_stride;
476
863k
                src += src_stride;
477
863k
            } while (--h);
478
87.6k
        }
479
654k
    } else if (my) {
480
649k
        do {
481
10.6M
            for (int x = 0; x < w; x++)
482
10.0M
                dst[x] = FILTER_BILIN_CLIP(src, x, my, src_stride, 4);
483
484
649k
            dst += dst_stride;
485
649k
            src += src_stride;
486
649k
        } while (--h);
487
78.7k
    } else
488
575k
        put_c(dst, dst_stride, src, src_stride, w, h);
489
838k
}
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
73.0k
{
497
73.0k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
498
73.0k
    int16_t mid[128 * 2];
499
73.0k
    int in_y = -2;
500
501
1.06M
    do {
502
1.06M
        int x;
503
1.06M
        int y = my >> 10;
504
1.06M
        int16_t *mid1 = &mid[(y & 1) * 128];
505
1.06M
        int16_t *mid2 = &mid[((y + 1) & 1) * 128];
506
1.06M
        int dmy = my & 0x3ff;
507
508
1.71M
        while (in_y < y) {
509
650k
            int imx = mx, ioff = 0;
510
650k
            int16_t *mid_ptr = &mid[(in_y & 1) * 128];
511
512
24.1M
            for (x = 0; x < w; x++) {
513
23.4M
                mid_ptr[x] = FILTER_BILIN_RND(src, ioff, imx >> 6, 1,
514
23.4M
                                              4 - intermediate_bits);
515
23.4M
                imx += dx;
516
23.4M
                ioff += imx >> 10;
517
23.4M
                imx &= 0x3ff;
518
23.4M
            }
519
520
650k
            src += PXSTRIDE(src_stride);
521
650k
            in_y++;
522
650k
        }
523
524
33.3M
        for (x = 0; x < w; x++)
525
32.3M
            dst[x] = FILTER_BILIN_CLIP2(mid1, mid2, x, dmy >> 6,
526
1.06M
                                       4 + intermediate_bits);
527
528
1.06M
        my += dy;
529
1.06M
        dst += PXSTRIDE(dst_stride);
530
1.06M
    } while (--h);
531
73.0k
}
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
39.6k
{
538
39.6k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
539
39.6k
    src_stride = PXSTRIDE(src_stride);
540
541
39.6k
    if (mx) {
542
21.4k
        if (my) {
543
14.4k
            int16_t mid[128 * 129], *mid_ptr = mid;
544
14.4k
            int tmp_h = h + 1;
545
546
228k
            do {
547
4.54M
                for (int x = 0; x < w; x++)
548
4.31M
                    mid_ptr[x] = FILTER_BILIN_RND(src, x, mx, 1,
549
228k
                                                  4 - intermediate_bits);
550
551
228k
                mid_ptr += 128;
552
228k
                src += src_stride;
553
228k
            } while (--tmp_h);
554
555
14.4k
            mid_ptr = mid;
556
218k
            do {
557
4.45M
                for (int x = 0; x < w; x++)
558
4.24M
                    tmp[x] = FILTER_BILIN_RND(mid_ptr, x, my, 128, 4) -
559
4.24M
                             PREP_BIAS;
560
561
218k
                mid_ptr += 128;
562
218k
                tmp += w;
563
218k
            } while (--h);
564
14.4k
        } else {
565
118k
            do {
566
2.57M
                for (int x = 0; x < w; x++)
567
2.45M
                    tmp[x] = FILTER_BILIN_RND(src, x, mx, 1,
568
2.45M
                                              4 - intermediate_bits) -
569
2.45M
                             PREP_BIAS;
570
571
118k
                tmp += w;
572
118k
                src += src_stride;
573
118k
            } while (--h);
574
7.00k
        }
575
21.4k
    } else if (my) {
576
114k
        do {
577
2.64M
            for (int x = 0; x < w; x++)
578
2.52M
                tmp[x] = FILTER_BILIN_RND(src, x, my, src_stride,
579
2.52M
                                          4 - intermediate_bits) - PREP_BIAS;
580
581
114k
            tmp += w;
582
114k
            src += src_stride;
583
114k
        } while (--h);
584
6.41k
    } else
585
11.8k
        prep_c(tmp, src, src_stride, w, h HIGHBD_TAIL_SUFFIX);
586
39.6k
}
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
15.7k
{
593
15.7k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
594
15.7k
    int16_t mid[128 * 2];
595
15.7k
    int in_y = -2;
596
597
307k
    do {
598
307k
        int x;
599
307k
        int y = my >> 10;
600
307k
        int16_t *mid1 = &mid[(y & 1) * 128];
601
307k
        int16_t *mid2 = &mid[((y + 1) & 1) * 128];
602
307k
        int dmy = my & 0x3ff;
603
604
477k
        while (in_y < y) {
605
169k
            int imx = mx, ioff = 0;
606
169k
            int16_t *mid_ptr = &mid[(in_y & 1) * 128];
607
608
5.52M
            for (x = 0; x < w; x++) {
609
5.35M
                mid_ptr[x] = FILTER_BILIN_RND(src, ioff, imx >> 6, 1,
610
5.35M
                                              4 - intermediate_bits);
611
5.35M
                imx += dx;
612
5.35M
                ioff += imx >> 10;
613
5.35M
                imx &= 0x3ff;
614
5.35M
            }
615
616
169k
            src += PXSTRIDE(src_stride);
617
169k
            in_y++;
618
169k
        }
619
620
9.12M
        for (x = 0; x < w; x++)
621
8.81M
            tmp[x] = FILTER_BILIN_RND2(mid1, mid2, x, dmy >> 6, 4) - PREP_BIAS;
622
623
307k
        my += dy;
624
307k
        tmp += w;
625
307k
    } while (--h);
626
15.7k
}
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
257k
{
632
257k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
633
257k
    const int sh = intermediate_bits + 1;
634
257k
    const int rnd = (1 << intermediate_bits) + PREP_BIAS * 2;
635
5.40M
    do {
636
153M
        for (int x = 0; x < w; x++)
637
147M
            dst[x] = iclip_pixel((tmp1[x] + tmp2[x] + rnd) >> sh);
638
639
5.40M
        tmp1 += w;
640
5.40M
        tmp2 += w;
641
5.40M
        dst += PXSTRIDE(dst_stride);
642
5.40M
    } while (--h);
643
257k
}
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
31.3k
{
649
31.3k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
650
31.3k
    const int sh = intermediate_bits + 4;
651
31.3k
    const int rnd = (8 << intermediate_bits) + PREP_BIAS * 16;
652
472k
    do {
653
13.9M
        for (int x = 0; x < w; x++)
654
13.4M
            dst[x] = iclip_pixel((tmp1[x] * weight +
655
13.4M
                                  tmp2[x] * (16 - weight) + rnd) >> sh);
656
657
472k
        tmp1 += w;
658
472k
        tmp2 += w;
659
472k
        dst += PXSTRIDE(dst_stride);
660
472k
    } while (--h);
661
31.3k
}
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
37.6k
{
667
37.6k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
668
37.6k
    const int sh = intermediate_bits + 6;
669
37.6k
    const int rnd = (32 << intermediate_bits) + PREP_BIAS * 64;
670
819k
    do {
671
25.9M
        for (int x = 0; x < w; x++)
672
25.0M
            dst[x] = iclip_pixel((tmp1[x] * mask[x] +
673
25.0M
                                  tmp2[x] * (64 - mask[x]) + rnd) >> sh);
674
675
819k
        tmp1 += w;
676
819k
        tmp2 += w;
677
819k
        mask += w;
678
819k
        dst += PXSTRIDE(dst_stride);
679
819k
    } while (--h);
680
37.6k
}
681
682
57.6M
#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
83.0k
{
686
927k
    do {
687
14.2M
        for (int x = 0; x < w; x++) {
688
13.2M
            dst[x] = blend_px(dst[x], tmp[x], mask[x]);
689
13.2M
        }
690
927k
        dst += PXSTRIDE(dst_stride);
691
927k
        tmp += w;
692
927k
        mask += w;
693
927k
    } while (--h);
694
83.0k
}
695
696
static void blend_v_c(pixel *dst, const ptrdiff_t dst_stride, const pixel *tmp,
697
                      const int w, int h)
698
279k
{
699
279k
    const uint8_t *const mask = &dav1d_obmc_masks[w];
700
3.73M
    do {
701
27.2M
        for (int x = 0; x < (w * 3) >> 2; x++) {
702
23.4M
            dst[x] = blend_px(dst[x], tmp[x], mask[x]);
703
23.4M
        }
704
3.73M
        dst += PXSTRIDE(dst_stride);
705
3.73M
        tmp += w;
706
3.73M
    } while (--h);
707
279k
}
708
709
static void blend_h_c(pixel *dst, const ptrdiff_t dst_stride, const pixel *tmp,
710
                      const int w, int h)
711
274k
{
712
274k
    const uint8_t *mask = &dav1d_obmc_masks[h];
713
274k
    h = (h * 3) >> 2;
714
1.52M
    do {
715
1.52M
        const int m = *mask++;
716
22.4M
        for (int x = 0; x < w; x++) {
717
20.9M
            dst[x] = blend_px(dst[x], tmp[x], m);
718
20.9M
        }
719
1.52M
        dst += PXSTRIDE(dst_stride);
720
1.52M
        tmp += w;
721
1.52M
    } while (--h);
722
274k
}
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
13.5k
{
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
13.5k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
732
13.5k
    const int bitdepth = bitdepth_from_max(bitdepth_max);
733
13.5k
    const int sh = intermediate_bits + 6;
734
13.5k
    const int rnd = (32 << intermediate_bits) + PREP_BIAS * 64;
735
13.5k
    const int mask_sh = bitdepth + intermediate_bits - 4;
736
13.5k
    const int mask_rnd = 1 << (mask_sh - 5);
737
559k
    do {
738
17.7M
        for (int x = 0; x < w; x++) {
739
17.2M
            const int tmpdiff = tmp1[x] - tmp2[x];
740
17.2M
            const int m = imin(38 + ((abs(tmpdiff) + mask_rnd) >> mask_sh), 64);
741
17.2M
            dst[x] = iclip_pixel((tmpdiff * m + tmp2[x] * 64 + rnd) >> sh);
742
743
17.2M
            if (ss_hor) {
744
7.11M
                x++;
745
746
7.11M
                const int tmpdiff = tmp1[x] - tmp2[x];
747
7.11M
                const int n = imin(38 + ((abs(tmpdiff) + mask_rnd) >> mask_sh), 64);
748
7.11M
                dst[x] = iclip_pixel((tmpdiff * n + tmp2[x] * 64 + rnd) >> sh);
749
750
7.11M
                if (h & ss_ver) {
751
2.96M
                    mask[x >> 1] = (m + n + mask[x >> 1] + 2 - sign) >> 2;
752
4.14M
                } else if (ss_ver) {
753
2.96M
                    mask[x >> 1] = m + n;
754
2.96M
                } else {
755
1.18M
                    mask[x >> 1] = (m + n + 1 - sign) >> 1;
756
1.18M
                }
757
10.1M
            } else {
758
10.1M
                mask[x] = m;
759
10.1M
            }
760
17.2M
        }
761
762
559k
        tmp1 += w;
763
559k
        tmp2 += w;
764
559k
        dst += PXSTRIDE(dst_stride);
765
559k
        if (!ss_ver || (h & 1)) mask += w >> ss_hor;
766
559k
    } while (--h);
767
13.5k
}
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
13.5k
                             const int sign HIGHBD_DECL_SUFFIX) \
774
13.5k
{ \
775
13.5k
    w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver \
776
13.5k
             HIGHBD_TAIL_SUFFIX); \
777
13.5k
}
mc_tmpl.c:w_mask_444_c
Line
Count
Source
773
5.06k
                             const int sign HIGHBD_DECL_SUFFIX) \
774
5.06k
{ \
775
5.06k
    w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver \
776
5.06k
             HIGHBD_TAIL_SUFFIX); \
777
5.06k
}
mc_tmpl.c:w_mask_422_c
Line
Count
Source
773
1.60k
                             const int sign HIGHBD_DECL_SUFFIX) \
774
1.60k
{ \
775
1.60k
    w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver \
776
1.60k
             HIGHBD_TAIL_SUFFIX); \
777
1.60k
}
mc_tmpl.c:w_mask_420_c
Line
Count
Source
773
6.83k
                             const int sign HIGHBD_DECL_SUFFIX) \
774
6.83k
{ \
775
6.83k
    w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver \
776
6.83k
             HIGHBD_TAIL_SUFFIX); \
777
6.83k
}
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
100M
    ((F[0] * src[x - 3 * stride] + \
787
100M
      F[1] * src[x - 2 * stride] + \
788
100M
      F[2] * src[x - 1 * stride] + \
789
100M
      F[3] * src[x + 0 * stride] + \
790
100M
      F[4] * src[x + 1 * stride] + \
791
100M
      F[5] * src[x + 2 * stride] + \
792
100M
      F[6] * src[x + 3 * stride] + \
793
100M
      F[7] * src[x + 4 * stride] + \
794
100M
      ((1 << (sh)) >> 1)) >> (sh))
795
796
#define FILTER_WARP_CLIP(src, x, F, stride, sh) \
797
24.5M
    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
417k
{
804
417k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
805
417k
    int16_t mid[15 * 8], *mid_ptr = mid;
806
807
417k
    src -= 3 * PXSTRIDE(src_stride);
808
6.52M
    for (int y = 0; y < 15; y++, mx += abcd[1]) {
809
52.8M
        for (int x = 0, tmx = mx; x < 8; x++, tmx += abcd[0]) {
810
46.7M
            const int8_t *const filter =
811
46.7M
                dav1d_mc_warp_filter[64 + ((tmx + 512) >> 10)];
812
813
46.7M
            mid_ptr[x] = FILTER_WARP_RND(src, x, filter, 1,
814
46.7M
                                         7 - intermediate_bits);
815
46.7M
        }
816
6.10M
        src += PXSTRIDE(src_stride);
817
6.10M
        mid_ptr += 8;
818
6.10M
    }
819
820
417k
    mid_ptr = &mid[3 * 8];
821
3.69M
    for (int y = 0; y < 8; y++, my += abcd[3]) {
822
27.7M
        for (int x = 0, tmy = my; x < 8; x++, tmy += abcd[2]) {
823
24.5M
            const int8_t *const filter =
824
24.5M
                dav1d_mc_warp_filter[64 + ((tmy + 512) >> 10)];
825
826
24.5M
            dst[x] = FILTER_WARP_CLIP(mid_ptr, x, filter, 8,
827
24.5M
                                      7 + intermediate_bits);
828
24.5M
        }
829
3.27M
        mid_ptr += 8;
830
3.27M
        dst += PXSTRIDE(dst_stride);
831
3.27M
    }
832
417k
}
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
161k
{
839
161k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
840
161k
    int16_t mid[15 * 8], *mid_ptr = mid;
841
842
161k
    src -= 3 * PXSTRIDE(src_stride);
843
2.58M
    for (int y = 0; y < 15; y++, mx += abcd[1]) {
844
21.7M
        for (int x = 0, tmx = mx; x < 8; x++, tmx += abcd[0]) {
845
19.2M
            const int8_t *const filter =
846
19.2M
                dav1d_mc_warp_filter[64 + ((tmx + 512) >> 10)];
847
848
19.2M
            mid_ptr[x] = FILTER_WARP_RND(src, x, filter, 1,
849
19.2M
                                         7 - intermediate_bits);
850
19.2M
        }
851
2.42M
        src += PXSTRIDE(src_stride);
852
2.42M
        mid_ptr += 8;
853
2.42M
    }
854
855
161k
    mid_ptr = &mid[3 * 8];
856
1.45M
    for (int y = 0; y < 8; y++, my += abcd[3]) {
857
11.6M
        for (int x = 0, tmy = my; x < 8; x++, tmy += abcd[2]) {
858
10.3M
            const int8_t *const filter =
859
10.3M
                dav1d_mc_warp_filter[64 + ((tmy + 512) >> 10)];
860
861
10.3M
            tmp[x] = FILTER_WARP_RND(mid_ptr, x, filter, 8, 7) - PREP_BIAS;
862
10.3M
        }
863
1.29M
        mid_ptr += 8;
864
1.29M
        tmp += tmp_stride;
865
1.29M
    }
866
161k
}
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
2.47M
{
874
    // find offset in reference of visible block to copy
875
2.47M
    ref += iclip((int) y, 0, (int) ih - 1) * PXSTRIDE(ref_stride) +
876
2.47M
           iclip((int) x, 0, (int) iw - 1);
877
878
    // number of pixels to extend (left, right, top, bottom)
879
2.47M
    const int left_ext = iclip((int) -x, 0, (int) bw - 1);
880
2.47M
    const int right_ext = iclip((int) (x + bw - iw), 0, (int) bw - 1);
881
2.47M
    assert(left_ext + right_ext < bw);
882
2.47M
    const int top_ext = iclip((int) -y, 0, (int) bh - 1);
883
2.47M
    const int bottom_ext = iclip((int) (y + bh - ih), 0, (int) bh - 1);
884
2.47M
    assert(top_ext + bottom_ext < bh);
885
886
    // copy visible portion first
887
2.47M
    pixel *blk = dst + top_ext * PXSTRIDE(dst_stride);
888
2.47M
    const int center_w = (int) (bw - left_ext - right_ext);
889
2.47M
    const int center_h = (int) (bh - top_ext - bottom_ext);
890
33.6M
    for (int y = 0; y < center_h; y++) {
891
31.2M
        pixel_copy(blk + left_ext, ref, center_w);
892
        // extend left edge for this line
893
31.2M
        if (left_ext)
894
7.64M
            pixel_set(blk, blk[left_ext], left_ext);
895
        // extend right edge for this line
896
31.2M
        if (right_ext)
897
22.7M
            pixel_set(blk + left_ext + center_w, blk[left_ext + center_w - 1],
898
22.7M
                      right_ext);
899
31.2M
        ref += PXSTRIDE(ref_stride);
900
31.2M
        blk += PXSTRIDE(dst_stride);
901
31.2M
    }
902
903
    // copy top
904
2.47M
    blk = dst + top_ext * PXSTRIDE(dst_stride);
905
6.02M
    for (int y = 0; y < top_ext; y++) {
906
3.54M
        pixel_copy(dst, blk, bw);
907
3.54M
        dst += PXSTRIDE(dst_stride);
908
3.54M
    }
909
910
    // copy bottom
911
2.47M
    dst += center_h * PXSTRIDE(dst_stride);
912
10.7M
    for (int y = 0; y < bottom_ext; y++) {
913
8.25M
        pixel_copy(dst, &dst[-PXSTRIDE(dst_stride)], bw);
914
8.25M
        dst += PXSTRIDE(dst_stride);
915
8.25M
    }
916
2.47M
}
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
245k
{
923
8.27M
    do {
924
8.27M
        int mx = mx0, src_x = -1;
925
708M
        for (int x = 0; x < dst_w; x++) {
926
700M
            const int8_t *const F = dav1d_resize_filter[mx >> 8];
927
700M
            dst[x] = iclip_pixel((-(F[0] * src[iclip(src_x - 3, 0, src_w - 1)] +
928
700M
                                    F[1] * src[iclip(src_x - 2, 0, src_w - 1)] +
929
700M
                                    F[2] * src[iclip(src_x - 1, 0, src_w - 1)] +
930
700M
                                    F[3] * src[iclip(src_x + 0, 0, src_w - 1)] +
931
700M
                                    F[4] * src[iclip(src_x + 1, 0, src_w - 1)] +
932
700M
                                    F[5] * src[iclip(src_x + 2, 0, src_w - 1)] +
933
700M
                                    F[6] * src[iclip(src_x + 3, 0, src_w - 1)] +
934
700M
                                    F[7] * src[iclip(src_x + 4, 0, src_w - 1)]) +
935
700M
                                  64) >> 7);
936
700M
            mx += dx;
937
700M
            src_x += mx >> 14;
938
700M
            mx &= 0x3fff;
939
700M
        }
940
941
8.27M
        dst += PXSTRIDE(dst_stride);
942
8.27M
        src += PXSTRIDE(src_stride);
943
8.27M
    } while (--h);
944
245k
}
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
77.8k
COLD void bitfn(dav1d_mc_dsp_init)(Dav1dMCDSPContext *const c) {
961
778k
#define init_mc_fns(type, name) do { \
962
778k
    c->mc        [type] = put_##name##_c; \
963
778k
    c->mc_scaled [type] = put_##name##_scaled_c; \
964
778k
    c->mct       [type] = prep_##name##_c; \
965
778k
    c->mct_scaled[type] = prep_##name##_scaled_c; \
966
778k
} while (0)
967
968
77.8k
    init_mc_fns(FILTER_2D_8TAP_REGULAR,        8tap_regular);
969
77.8k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SMOOTH, 8tap_regular_smooth);
970
77.8k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SHARP,  8tap_regular_sharp);
971
77.8k
    init_mc_fns(FILTER_2D_8TAP_SHARP_REGULAR,  8tap_sharp_regular);
972
77.8k
    init_mc_fns(FILTER_2D_8TAP_SHARP_SMOOTH,   8tap_sharp_smooth);
973
77.8k
    init_mc_fns(FILTER_2D_8TAP_SHARP,          8tap_sharp);
974
77.8k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_REGULAR, 8tap_smooth_regular);
975
77.8k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH,         8tap_smooth);
976
77.8k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_SHARP,   8tap_smooth_sharp);
977
77.8k
    init_mc_fns(FILTER_2D_BILINEAR,            bilin);
978
979
77.8k
    c->avg      = avg_c;
980
77.8k
    c->w_avg    = w_avg_c;
981
77.8k
    c->mask     = mask_c;
982
77.8k
    c->blend    = blend_c;
983
77.8k
    c->blend_v  = blend_v_c;
984
77.8k
    c->blend_h  = blend_h_c;
985
77.8k
    c->w_mask[0] = w_mask_444_c;
986
77.8k
    c->w_mask[1] = w_mask_422_c;
987
77.8k
    c->w_mask[2] = w_mask_420_c;
988
77.8k
    c->warp8x8  = warp_affine_8x8_c;
989
77.8k
    c->warp8x8t = warp_affine_8x8t_c;
990
77.8k
    c->emu_edge = emu_edge_c;
991
77.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
77.8k
}
dav1d_mc_dsp_init_8bpc
Line
Count
Source
960
35.3k
COLD void bitfn(dav1d_mc_dsp_init)(Dav1dMCDSPContext *const c) {
961
35.3k
#define init_mc_fns(type, name) do { \
962
35.3k
    c->mc        [type] = put_##name##_c; \
963
35.3k
    c->mc_scaled [type] = put_##name##_scaled_c; \
964
35.3k
    c->mct       [type] = prep_##name##_c; \
965
35.3k
    c->mct_scaled[type] = prep_##name##_scaled_c; \
966
35.3k
} while (0)
967
968
35.3k
    init_mc_fns(FILTER_2D_8TAP_REGULAR,        8tap_regular);
969
35.3k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SMOOTH, 8tap_regular_smooth);
970
35.3k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SHARP,  8tap_regular_sharp);
971
35.3k
    init_mc_fns(FILTER_2D_8TAP_SHARP_REGULAR,  8tap_sharp_regular);
972
35.3k
    init_mc_fns(FILTER_2D_8TAP_SHARP_SMOOTH,   8tap_sharp_smooth);
973
35.3k
    init_mc_fns(FILTER_2D_8TAP_SHARP,          8tap_sharp);
974
35.3k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_REGULAR, 8tap_smooth_regular);
975
35.3k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH,         8tap_smooth);
976
35.3k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_SHARP,   8tap_smooth_sharp);
977
35.3k
    init_mc_fns(FILTER_2D_BILINEAR,            bilin);
978
979
35.3k
    c->avg      = avg_c;
980
35.3k
    c->w_avg    = w_avg_c;
981
35.3k
    c->mask     = mask_c;
982
35.3k
    c->blend    = blend_c;
983
35.3k
    c->blend_v  = blend_v_c;
984
35.3k
    c->blend_h  = blend_h_c;
985
35.3k
    c->w_mask[0] = w_mask_444_c;
986
35.3k
    c->w_mask[1] = w_mask_422_c;
987
35.3k
    c->w_mask[2] = w_mask_420_c;
988
35.3k
    c->warp8x8  = warp_affine_8x8_c;
989
35.3k
    c->warp8x8t = warp_affine_8x8t_c;
990
35.3k
    c->emu_edge = emu_edge_c;
991
35.3k
    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
35.3k
}
dav1d_mc_dsp_init_16bpc
Line
Count
Source
960
42.5k
COLD void bitfn(dav1d_mc_dsp_init)(Dav1dMCDSPContext *const c) {
961
42.5k
#define init_mc_fns(type, name) do { \
962
42.5k
    c->mc        [type] = put_##name##_c; \
963
42.5k
    c->mc_scaled [type] = put_##name##_scaled_c; \
964
42.5k
    c->mct       [type] = prep_##name##_c; \
965
42.5k
    c->mct_scaled[type] = prep_##name##_scaled_c; \
966
42.5k
} while (0)
967
968
42.5k
    init_mc_fns(FILTER_2D_8TAP_REGULAR,        8tap_regular);
969
42.5k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SMOOTH, 8tap_regular_smooth);
970
42.5k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SHARP,  8tap_regular_sharp);
971
42.5k
    init_mc_fns(FILTER_2D_8TAP_SHARP_REGULAR,  8tap_sharp_regular);
972
42.5k
    init_mc_fns(FILTER_2D_8TAP_SHARP_SMOOTH,   8tap_sharp_smooth);
973
42.5k
    init_mc_fns(FILTER_2D_8TAP_SHARP,          8tap_sharp);
974
42.5k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_REGULAR, 8tap_smooth_regular);
975
42.5k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH,         8tap_smooth);
976
42.5k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_SHARP,   8tap_smooth_sharp);
977
42.5k
    init_mc_fns(FILTER_2D_BILINEAR,            bilin);
978
979
42.5k
    c->avg      = avg_c;
980
42.5k
    c->w_avg    = w_avg_c;
981
42.5k
    c->mask     = mask_c;
982
42.5k
    c->blend    = blend_c;
983
42.5k
    c->blend_v  = blend_v_c;
984
42.5k
    c->blend_h  = blend_h_c;
985
42.5k
    c->w_mask[0] = w_mask_444_c;
986
42.5k
    c->w_mask[1] = w_mask_422_c;
987
42.5k
    c->w_mask[2] = w_mask_420_c;
988
42.5k
    c->warp8x8  = warp_affine_8x8_c;
989
42.5k
    c->warp8x8t = warp_affine_8x8t_c;
990
42.5k
    c->emu_edge = emu_edge_c;
991
42.5k
    c->resize   = resize_c;
992
993
#if HAVE_ASM
994
#if ARCH_AARCH64 || ARCH_ARM
995
    mc_dsp_init_arm(c);
996
#elif ARCH_LOONGARCH64
997
    mc_dsp_init_loongarch(c);
998
#elif ARCH_PPC64LE
999
    mc_dsp_init_ppc(c);
1000
#elif ARCH_RISCV
1001
    mc_dsp_init_riscv(c);
1002
#elif ARCH_X86
1003
    mc_dsp_init_x86(c);
1004
#endif
1005
#endif
1006
42.5k
}