Coverage Report

Created: 2026-09-02 06:43

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
5.04M
#define get_intermediate_bits(bitdepth_max) 4
41
// Output in interval [-5132, 9212], fits in int16_t as is
42
403M
#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.13M
{
55
17.2M
    do {
56
17.2M
        pixel_copy(dst, src, w);
57
58
17.2M
        dst += dst_stride;
59
17.2M
        src += src_stride;
60
17.2M
    } while (--h);
61
1.13M
}
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
158k
{
67
158k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
68
4.12M
    do {
69
128M
        for (int x = 0; x < w; x++)
70
124M
            tmp[x] = (src[x] << intermediate_bits) - PREP_BIAS;
71
72
4.12M
        tmp += w;
73
4.12M
        src += src_stride;
74
4.12M
    } while (--h);
75
158k
}
76
77
#define FILTER_8TAP(src, x, F, stride) \
78
658M
    (F[0] * src[x + -3 * stride] + \
79
658M
     F[1] * src[x + -2 * stride] + \
80
658M
     F[2] * src[x + -1 * stride] + \
81
658M
     F[3] * src[x + +0 * stride] + \
82
658M
     F[4] * src[x + +1 * stride] + \
83
658M
     F[5] * src[x + +2 * stride] + \
84
658M
     F[6] * src[x + +3 * stride] + \
85
658M
     F[7] * src[x + +4 * stride])
86
87
#define FILTER_8TAP2(src, x, F) \
88
528M
    (F[0] * src[0][x] + \
89
528M
     F[1] * src[1][x] + \
90
528M
     F[2] * src[2][x] + \
91
528M
     F[3] * src[3][x] + \
92
528M
     F[4] * src[4][x] + \
93
528M
     F[5] * src[5][x] + \
94
528M
     F[6] * src[6][x] + \
95
528M
     F[7] * src[7][x])
96
97
#define DAV1D_FILTER_8TAP_RND(src, x, F, stride, sh) \
98
634M
    ((FILTER_8TAP(src, x, F, stride) + ((1 << (sh)) >> 1)) >> (sh))
99
100
#define DAV1D_FILTER_8TAP_RND2(src, x, F, stride, rnd, sh) \
101
23.6M
    ((FILTER_8TAP(src, x, F, stride) + (rnd)) >> (sh))
102
103
#define DAV1D_FILTER_8TAP_RND3(src, x, F, sh) \
104
528M
    ((FILTER_8TAP2(src, x, F) + ((1 << (sh)) >> 1)) >> (sh))
105
106
#define DAV1D_FILTER_8TAP_CLIP(src, x, F, stride, sh) \
107
53.3M
    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
23.6M
    iclip_pixel(DAV1D_FILTER_8TAP_RND2(src, x, F, stride, rnd, sh))
111
112
#define DAV1D_FILTER_8TAP_CLIP3(src, x, F, sh) \
113
353M
    iclip_pixel(DAV1D_FILTER_8TAP_RND3(src, x, F, sh))
114
115
#define GET_H_FILTER(mx) \
116
500M
    const int8_t *const fh = !(mx) ? NULL : w > 4 ? \
117
466M
        dav1d_mc_subpel_filters[filter_type & 3][(mx) - 1] : \
118
466M
        dav1d_mc_subpel_filters[3 + (filter_type & 1)][(mx) - 1]
119
120
#define GET_V_FILTER(my) \
121
26.0M
    const int8_t *const fv = !(my) ? NULL : h > 4 ? \
122
23.0M
        dav1d_mc_subpel_filters[filter_type >> 2][(my) - 1] : \
123
23.0M
        dav1d_mc_subpel_filters[3 + ((filter_type >> 2) & 1)][(my) - 1]
124
125
#define GET_FILTERS() \
126
1.11M
    GET_H_FILTER(mx); \
127
1.11M
    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
872k
{
135
872k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
136
872k
    const int intermediate_rnd = 32 + ((1 << (6 - intermediate_bits)) >> 1);
137
138
872k
    GET_FILTERS();
139
872k
    dst_stride = PXSTRIDE(dst_stride);
140
872k
    src_stride = PXSTRIDE(src_stride);
141
142
872k
    if (fh) {
143
255k
        if (fv) {
144
172k
            int tmp_h = h + 7;
145
172k
            int16_t mid[128 * 135], *mid_ptr = mid;
146
147
172k
            src -= src_stride * 3;
148
2.96M
            do {
149
48.4M
                for (int x = 0; x < w; x++)
150
45.5M
                    mid_ptr[x] = DAV1D_FILTER_8TAP_RND(src, x, fh, 1,
151
2.96M
                                                       6 - intermediate_bits);
152
153
2.96M
                mid_ptr += 128;
154
2.96M
                src += src_stride;
155
2.96M
            } while (--tmp_h);
156
157
172k
            mid_ptr = mid + 128 * 3;
158
1.74M
            do {
159
35.3M
                for (int x = 0; x < w; x++)
160
33.5M
                    dst[x] = DAV1D_FILTER_8TAP_CLIP(mid_ptr, x, fv, 128,
161
1.74M
                                                    6 + intermediate_bits);
162
163
1.74M
                mid_ptr += 128;
164
1.74M
                dst += dst_stride;
165
1.74M
            } while (--h);
166
172k
        } else {
167
898k
            do {
168
24.5M
                for (int x = 0; x < w; x++) {
169
23.6M
                    dst[x] = DAV1D_FILTER_8TAP_CLIP2(src, x, fh, 1,
170
23.6M
                                                     intermediate_rnd, 6);
171
23.6M
                }
172
173
898k
                dst += dst_stride;
174
898k
                src += src_stride;
175
898k
            } while (--h);
176
82.6k
        }
177
617k
    } else if (fv) {
178
1.00M
        do {
179
20.8M
            for (int x = 0; x < w; x++)
180
19.8M
                dst[x] = DAV1D_FILTER_8TAP_CLIP(src, x, fv, src_stride, 6);
181
182
1.00M
            dst += dst_stride;
183
1.00M
            src += src_stride;
184
1.00M
        } while (--h);
185
112k
    } else
186
504k
        put_c(dst, dst_stride, src, src_stride, w, h);
187
872k
}
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.38M
{
196
1.38M
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
197
1.38M
    const int intermediate_rnd = (1 << intermediate_bits) >> 1;
198
1.38M
    int16_t mid[128 * 8];
199
1.38M
    int16_t *mid_ptrs[8];
200
1.38M
    int in_y = -8;
201
1.38M
    src_stride = PXSTRIDE(src_stride);
202
203
12.5M
    for (int i = 0; i < 8; i++)
204
11.1M
        mid_ptrs[i] = &mid[128 * i];
205
206
1.38M
    src -= src_stride * 3;
207
208
19.2M
    for (int y = 0; y < h; y++) {
209
17.8M
        int x;
210
17.8M
        int src_y = my >> 10;
211
17.8M
        GET_V_FILTER((my & 0x3ff) >> 6);
212
213
37.3M
        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
364M
            for (x = 0; x < w; x++) {
222
345M
                GET_H_FILTER(imx >> 6);
223
345M
                mid_ptr[x] = fh ? DAV1D_FILTER_8TAP_RND(src, ioff, fh, 1,
224
345M
                                                        6 - intermediate_bits) :
225
345M
                                  src[ioff] << intermediate_bits;
226
345M
                imx += dx;
227
345M
                ioff += imx >> 10;
228
345M
                imx &= 0x3ff;
229
345M
            }
230
231
19.4M
            src += src_stride;
232
19.4M
            in_y++;
233
19.4M
        }
234
235
405M
        for (x = 0; x < w; x++)
236
387M
            dst[x] = fv ? DAV1D_FILTER_8TAP_CLIP3(mid_ptrs, x, fv,
237
387M
                                                  6 + intermediate_bits) :
238
387M
                          iclip_pixel((mid_ptrs[3][x] + intermediate_rnd) >>
239
33.8M
                                              intermediate_bits);
240
241
17.8M
        my += dy;
242
17.8M
        dst += PXSTRIDE(dst_stride);
243
17.8M
    }
244
1.38M
}
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
243k
{
251
243k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
252
243k
    GET_FILTERS();
253
243k
    src_stride = PXSTRIDE(src_stride);
254
255
243k
    if (fh) {
256
75.3k
        if (fv) {
257
52.4k
            int tmp_h = h + 7;
258
52.4k
            int16_t mid[128 * 135], *mid_ptr = mid;
259
260
52.4k
            src -= src_stride * 3;
261
1.25M
            do {
262
25.0M
                for (int x = 0; x < w; x++)
263
23.8M
                    mid_ptr[x] = DAV1D_FILTER_8TAP_RND(src, x, fh, 1,
264
1.25M
                                                       6 - intermediate_bits);
265
266
1.25M
                mid_ptr += 128;
267
1.25M
                src += src_stride;
268
1.25M
            } while (--tmp_h);
269
270
52.4k
            mid_ptr = mid + 128 * 3;
271
887k
            do {
272
20.3M
                for (int x = 0; x < w; x++) {
273
19.4M
                    int t = DAV1D_FILTER_8TAP_RND(mid_ptr, x, fv, 128, 6) -
274
19.4M
                                  PREP_BIAS;
275
19.4M
                    assert(t >= INT16_MIN && t <= INT16_MAX);
276
19.4M
                    tmp[x] = t;
277
19.4M
                }
278
279
887k
                mid_ptr += 128;
280
887k
                tmp += w;
281
887k
            } while (--h);
282
52.4k
        } else {
283
513k
            do {
284
19.0M
                for (int x = 0; x < w; x++)
285
18.5M
                    tmp[x] = DAV1D_FILTER_8TAP_RND(src, x, fh, 1,
286
18.5M
                                                   6 - intermediate_bits) -
287
18.5M
                             PREP_BIAS;
288
289
513k
                tmp += w;
290
513k
                src += src_stride;
291
513k
            } while (--h);
292
22.8k
        }
293
168k
    } else if (fv) {
294
344k
        do {
295
8.03M
            for (int x = 0; x < w; x++)
296
7.69M
                tmp[x] = DAV1D_FILTER_8TAP_RND(src, x, fv, src_stride,
297
7.69M
                                               6 - intermediate_bits) -
298
7.69M
                         PREP_BIAS;
299
300
344k
            tmp += w;
301
344k
            src += src_stride;
302
344k
        } while (--h);
303
21.6k
    } else
304
146k
        prep_c(tmp, src, src_stride, w, h HIGHBD_TAIL_SUFFIX);
305
243k
}
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
351k
{
313
351k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
314
351k
    int16_t mid[128 * 8];
315
351k
    int16_t *mid_ptrs[8];
316
351k
    int in_y = -8;
317
351k
    src_stride = PXSTRIDE(src_stride);
318
319
3.15M
    for (int i = 0; i < 8; i++)
320
2.80M
        mid_ptrs[i] = &mid[128 * i];
321
322
351k
    src -= src_stride * 3;
323
324
7.40M
    for (int y = 0; y < h; y++) {
325
7.05M
        int x;
326
7.05M
        int src_y = my >> 10;
327
7.05M
        GET_V_FILTER((my & 0x3ff) >> 6);
328
329
13.1M
        while (in_y < src_y) {
330
6.11M
            int imx = mx, ioff = 0;
331
6.11M
            int16_t *mid_ptr = mid_ptrs[0];
332
333
48.9M
            for (int i = 0; i < 7; i++)
334
42.8M
                mid_ptrs[i] = mid_ptrs[i + 1];
335
6.11M
            mid_ptrs[7] = mid_ptr;
336
337
160M
            for (x = 0; x < w; x++) {
338
154M
                GET_H_FILTER(imx >> 6);
339
154M
                mid_ptr[x] = fh ? DAV1D_FILTER_8TAP_RND(src, ioff, fh, 1,
340
154M
                                                        6 - intermediate_bits) :
341
154M
                                  src[ioff] << intermediate_bits;
342
154M
                imx += dx;
343
154M
                ioff += imx >> 10;
344
154M
                imx &= 0x3ff;
345
154M
            }
346
347
6.11M
            src += src_stride;
348
6.11M
            in_y++;
349
6.11M
        }
350
351
211M
        for (x = 0; x < w; x++)
352
204M
            tmp[x] = (fv ? DAV1D_FILTER_8TAP_RND3(mid_ptrs, x, fv, 6)
353
204M
                         : mid_ptrs[3][x]) - PREP_BIAS;
354
355
7.05M
        my += dy;
356
7.05M
        tmp += w;
357
7.05M
    }
358
351k
}
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
873k
                                HIGHBD_DECL_SUFFIX) \
368
873k
{ \
369
873k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
873k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
873k
} \
mc_tmpl.c:put_8tap_regular_c
Line
Count
Source
367
345k
                                HIGHBD_DECL_SUFFIX) \
368
345k
{ \
369
345k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
345k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
345k
} \
mc_tmpl.c:put_8tap_regular_smooth_c
Line
Count
Source
367
14.1k
                                HIGHBD_DECL_SUFFIX) \
368
14.1k
{ \
369
14.1k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
14.1k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
14.1k
} \
mc_tmpl.c:put_8tap_regular_sharp_c
Line
Count
Source
367
2.82k
                                HIGHBD_DECL_SUFFIX) \
368
2.82k
{ \
369
2.82k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
2.82k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
2.82k
} \
mc_tmpl.c:put_8tap_sharp_regular_c
Line
Count
Source
367
3.59k
                                HIGHBD_DECL_SUFFIX) \
368
3.59k
{ \
369
3.59k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
3.59k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
3.59k
} \
mc_tmpl.c:put_8tap_sharp_smooth_c
Line
Count
Source
367
1.57k
                                HIGHBD_DECL_SUFFIX) \
368
1.57k
{ \
369
1.57k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
1.57k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
1.57k
} \
mc_tmpl.c:put_8tap_sharp_c
Line
Count
Source
367
53.0k
                                HIGHBD_DECL_SUFFIX) \
368
53.0k
{ \
369
53.0k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
53.0k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
53.0k
} \
mc_tmpl.c:put_8tap_smooth_regular_c
Line
Count
Source
367
11.1k
                                HIGHBD_DECL_SUFFIX) \
368
11.1k
{ \
369
11.1k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
11.1k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
11.1k
} \
mc_tmpl.c:put_8tap_smooth_c
Line
Count
Source
367
439k
                                HIGHBD_DECL_SUFFIX) \
368
439k
{ \
369
439k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
439k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
439k
} \
mc_tmpl.c:put_8tap_smooth_sharp_c
Line
Count
Source
367
2.05k
                                HIGHBD_DECL_SUFFIX) \
368
2.05k
{ \
369
2.05k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
2.05k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
2.05k
} \
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.38M
                                       HIGHBD_DECL_SUFFIX) \
380
1.38M
{ \
381
1.38M
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
1.38M
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
1.38M
} \
mc_tmpl.c:put_8tap_regular_scaled_c
Line
Count
Source
379
1.02M
                                       HIGHBD_DECL_SUFFIX) \
380
1.02M
{ \
381
1.02M
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
1.02M
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
1.02M
} \
mc_tmpl.c:put_8tap_regular_smooth_scaled_c
Line
Count
Source
379
61.6k
                                       HIGHBD_DECL_SUFFIX) \
380
61.6k
{ \
381
61.6k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
61.6k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
61.6k
} \
mc_tmpl.c:put_8tap_regular_sharp_scaled_c
Line
Count
Source
379
17.7k
                                       HIGHBD_DECL_SUFFIX) \
380
17.7k
{ \
381
17.7k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
17.7k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
17.7k
} \
mc_tmpl.c:put_8tap_sharp_regular_scaled_c
Line
Count
Source
379
19.8k
                                       HIGHBD_DECL_SUFFIX) \
380
19.8k
{ \
381
19.8k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
19.8k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
19.8k
} \
mc_tmpl.c:put_8tap_sharp_smooth_scaled_c
Line
Count
Source
379
4.40k
                                       HIGHBD_DECL_SUFFIX) \
380
4.40k
{ \
381
4.40k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
4.40k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
4.40k
} \
mc_tmpl.c:put_8tap_sharp_scaled_c
Line
Count
Source
379
78.0k
                                       HIGHBD_DECL_SUFFIX) \
380
78.0k
{ \
381
78.0k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
78.0k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
78.0k
} \
mc_tmpl.c:put_8tap_smooth_regular_scaled_c
Line
Count
Source
379
65.8k
                                       HIGHBD_DECL_SUFFIX) \
380
65.8k
{ \
381
65.8k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
65.8k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
65.8k
} \
mc_tmpl.c:put_8tap_smooth_scaled_c
Line
Count
Source
379
115k
                                       HIGHBD_DECL_SUFFIX) \
380
115k
{ \
381
115k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
115k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
115k
} \
mc_tmpl.c:put_8tap_smooth_sharp_scaled_c
Line
Count
Source
379
4.59k
                                       HIGHBD_DECL_SUFFIX) \
380
4.59k
{ \
381
4.59k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
4.59k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
4.59k
} \
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
243k
                                 HIGHBD_DECL_SUFFIX) \
390
243k
{ \
391
243k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
243k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
243k
} \
mc_tmpl.c:prep_8tap_regular_c
Line
Count
Source
389
80.2k
                                 HIGHBD_DECL_SUFFIX) \
390
80.2k
{ \
391
80.2k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
80.2k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
80.2k
} \
mc_tmpl.c:prep_8tap_regular_smooth_c
Line
Count
Source
389
2.54k
                                 HIGHBD_DECL_SUFFIX) \
390
2.54k
{ \
391
2.54k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
2.54k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
2.54k
} \
mc_tmpl.c:prep_8tap_regular_sharp_c
Line
Count
Source
389
4.84k
                                 HIGHBD_DECL_SUFFIX) \
390
4.84k
{ \
391
4.84k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
4.84k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
4.84k
} \
mc_tmpl.c:prep_8tap_sharp_regular_c
Line
Count
Source
389
8.83k
                                 HIGHBD_DECL_SUFFIX) \
390
8.83k
{ \
391
8.83k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
8.83k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
8.83k
} \
mc_tmpl.c:prep_8tap_sharp_smooth_c
Line
Count
Source
389
2.80k
                                 HIGHBD_DECL_SUFFIX) \
390
2.80k
{ \
391
2.80k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
2.80k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
2.80k
} \
mc_tmpl.c:prep_8tap_sharp_c
Line
Count
Source
389
34.5k
                                 HIGHBD_DECL_SUFFIX) \
390
34.5k
{ \
391
34.5k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
34.5k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
34.5k
} \
mc_tmpl.c:prep_8tap_smooth_regular_c
Line
Count
Source
389
2.78k
                                 HIGHBD_DECL_SUFFIX) \
390
2.78k
{ \
391
2.78k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
2.78k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
2.78k
} \
mc_tmpl.c:prep_8tap_smooth_c
Line
Count
Source
389
104k
                                 HIGHBD_DECL_SUFFIX) \
390
104k
{ \
391
104k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
104k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
104k
} \
mc_tmpl.c:prep_8tap_smooth_sharp_c
Line
Count
Source
389
2.25k
                                 HIGHBD_DECL_SUFFIX) \
390
2.25k
{ \
391
2.25k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
2.25k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
2.25k
} \
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
351k
                                        HIGHBD_DECL_SUFFIX) \
401
351k
{ \
402
351k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
351k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
351k
}
mc_tmpl.c:prep_8tap_regular_scaled_c
Line
Count
Source
400
140k
                                        HIGHBD_DECL_SUFFIX) \
401
140k
{ \
402
140k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
140k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
140k
}
mc_tmpl.c:prep_8tap_regular_smooth_scaled_c
Line
Count
Source
400
16.4k
                                        HIGHBD_DECL_SUFFIX) \
401
16.4k
{ \
402
16.4k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
16.4k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
16.4k
}
mc_tmpl.c:prep_8tap_regular_sharp_scaled_c
Line
Count
Source
400
20.9k
                                        HIGHBD_DECL_SUFFIX) \
401
20.9k
{ \
402
20.9k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
20.9k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
20.9k
}
mc_tmpl.c:prep_8tap_sharp_regular_scaled_c
Line
Count
Source
400
45.0k
                                        HIGHBD_DECL_SUFFIX) \
401
45.0k
{ \
402
45.0k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
45.0k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
45.0k
}
mc_tmpl.c:prep_8tap_sharp_smooth_scaled_c
Line
Count
Source
400
8.95k
                                        HIGHBD_DECL_SUFFIX) \
401
8.95k
{ \
402
8.95k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
8.95k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
8.95k
}
mc_tmpl.c:prep_8tap_sharp_scaled_c
Line
Count
Source
400
36.9k
                                        HIGHBD_DECL_SUFFIX) \
401
36.9k
{ \
402
36.9k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
36.9k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
36.9k
}
mc_tmpl.c:prep_8tap_smooth_regular_scaled_c
Line
Count
Source
400
27.2k
                                        HIGHBD_DECL_SUFFIX) \
401
27.2k
{ \
402
27.2k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
27.2k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
27.2k
}
mc_tmpl.c:prep_8tap_smooth_scaled_c
Line
Count
Source
400
47.8k
                                        HIGHBD_DECL_SUFFIX) \
401
47.8k
{ \
402
47.8k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
47.8k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
47.8k
}
mc_tmpl.c:prep_8tap_smooth_sharp_scaled_c
Line
Count
Source
400
7.15k
                                        HIGHBD_DECL_SUFFIX) \
401
7.15k
{ \
402
7.15k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
7.15k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
7.15k
}
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
113M
    (16 * src[x] + ((mxy) * (src[x + stride] - src[x])))
418
419
#define FILTER_BILIN_RND(src, x, mxy, stride, sh) \
420
113M
    ((FILTER_BILIN(src, x, mxy, stride) + ((1 << (sh)) >> 1)) >> (sh))
421
422
#define FILTER_BILIN_CLIP(src, x, mxy, stride, sh) \
423
26.5M
    iclip_pixel(FILTER_BILIN_RND(src, x, mxy, stride, sh))
424
425
#define FILTER_BILIN2(src1, src2, x, mxy) \
426
43.4M
    (16 * src1[x] + ((mxy) * (src2[x] - src1[x])))
427
428
#define FILTER_BILIN_RND2(src1, src2, x, mxy, sh) \
429
43.4M
    ((FILTER_BILIN2(src1, src2, x, mxy) + ((1 << (sh)) >> 1)) >> (sh))
430
431
#define FILTER_BILIN_CLIP2(src1, src2, x, mxy, sh) \
432
33.8M
    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
931k
{
439
931k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
440
931k
    const int intermediate_rnd = (1 << intermediate_bits) >> 1;
441
931k
    dst_stride = PXSTRIDE(dst_stride);
442
931k
    src_stride = PXSTRIDE(src_stride);
443
444
931k
    if (mx) {
445
210k
        if (my) {
446
109k
            int16_t mid[128 * 129], *mid_ptr = mid;
447
109k
            int tmp_h = h + 1;
448
449
1.00M
            do {
450
15.8M
                for (int x = 0; x < w; x++)
451
14.8M
                    mid_ptr[x] = FILTER_BILIN_RND(src, x, mx, 1,
452
1.00M
                                                  4 - intermediate_bits);
453
454
1.00M
                mid_ptr += 128;
455
1.00M
                src += src_stride;
456
1.00M
            } while (--tmp_h);
457
458
109k
            mid_ptr = mid;
459
895k
            do {
460
14.8M
                for (int x = 0; x < w; x++)
461
13.9M
                    dst[x] = FILTER_BILIN_CLIP(mid_ptr, x, my, 128,
462
895k
                                               4 + intermediate_bits);
463
464
895k
                mid_ptr += 128;
465
895k
                dst += dst_stride;
466
895k
            } while (--h);
467
109k
        } else {
468
1.00M
            do {
469
24.4M
                for (int x = 0; x < w; x++) {
470
23.4M
                    const int px = FILTER_BILIN_RND(src, x, mx, 1,
471
23.4M
                                                    4 - intermediate_bits);
472
23.4M
                    dst[x] = iclip_pixel((px + intermediate_rnd) >> intermediate_bits);
473
23.4M
                }
474
475
1.00M
                dst += dst_stride;
476
1.00M
                src += src_stride;
477
1.00M
            } while (--h);
478
100k
        }
479
721k
    } else if (my) {
480
782k
        do {
481
13.4M
            for (int x = 0; x < w; x++)
482
12.6M
                dst[x] = FILTER_BILIN_CLIP(src, x, my, src_stride, 4);
483
484
782k
            dst += dst_stride;
485
782k
            src += src_stride;
486
782k
        } while (--h);
487
94.0k
    } else
488
627k
        put_c(dst, dst_stride, src, src_stride, w, h);
489
931k
}
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
74.3k
{
497
74.3k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
498
74.3k
    int16_t mid[128 * 2];
499
74.3k
    int in_y = -2;
500
501
1.11M
    do {
502
1.11M
        int x;
503
1.11M
        int y = my >> 10;
504
1.11M
        int16_t *mid1 = &mid[(y & 1) * 128];
505
1.11M
        int16_t *mid2 = &mid[((y + 1) & 1) * 128];
506
1.11M
        int dmy = my & 0x3ff;
507
508
1.79M
        while (in_y < y) {
509
679k
            int imx = mx, ioff = 0;
510
679k
            int16_t *mid_ptr = &mid[(in_y & 1) * 128];
511
512
29.6M
            for (x = 0; x < w; x++) {
513
29.0M
                mid_ptr[x] = FILTER_BILIN_RND(src, ioff, imx >> 6, 1,
514
29.0M
                                              4 - intermediate_bits);
515
29.0M
                imx += dx;
516
29.0M
                ioff += imx >> 10;
517
29.0M
                imx &= 0x3ff;
518
29.0M
            }
519
520
679k
            src += PXSTRIDE(src_stride);
521
679k
            in_y++;
522
679k
        }
523
524
34.9M
        for (x = 0; x < w; x++)
525
33.8M
            dst[x] = FILTER_BILIN_CLIP2(mid1, mid2, x, dmy >> 6,
526
1.11M
                                       4 + intermediate_bits);
527
528
1.11M
        my += dy;
529
1.11M
        dst += PXSTRIDE(dst_stride);
530
1.11M
    } while (--h);
531
74.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
40.3k
{
538
40.3k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
539
40.3k
    src_stride = PXSTRIDE(src_stride);
540
541
40.3k
    if (mx) {
542
21.5k
        if (my) {
543
14.1k
            int16_t mid[128 * 129], *mid_ptr = mid;
544
14.1k
            int tmp_h = h + 1;
545
546
217k
            do {
547
4.22M
                for (int x = 0; x < w; x++)
548
4.00M
                    mid_ptr[x] = FILTER_BILIN_RND(src, x, mx, 1,
549
217k
                                                  4 - intermediate_bits);
550
551
217k
                mid_ptr += 128;
552
217k
                src += src_stride;
553
217k
            } while (--tmp_h);
554
555
14.1k
            mid_ptr = mid;
556
206k
            do {
557
4.10M
                for (int x = 0; x < w; x++)
558
3.89M
                    tmp[x] = FILTER_BILIN_RND(mid_ptr, x, my, 128, 4) -
559
3.89M
                             PREP_BIAS;
560
561
206k
                mid_ptr += 128;
562
206k
                tmp += w;
563
206k
            } while (--h);
564
14.1k
        } else {
565
128k
            do {
566
2.76M
                for (int x = 0; x < w; x++)
567
2.63M
                    tmp[x] = FILTER_BILIN_RND(src, x, mx, 1,
568
2.63M
                                              4 - intermediate_bits) -
569
2.63M
                             PREP_BIAS;
570
571
128k
                tmp += w;
572
128k
                src += src_stride;
573
128k
            } while (--h);
574
7.39k
        }
575
21.5k
    } else if (my) {
576
118k
        do {
577
2.65M
            for (int x = 0; x < w; x++)
578
2.53M
                tmp[x] = FILTER_BILIN_RND(src, x, my, src_stride,
579
2.53M
                                          4 - intermediate_bits) - PREP_BIAS;
580
581
118k
            tmp += w;
582
118k
            src += src_stride;
583
118k
        } while (--h);
584
6.83k
    } else
585
11.9k
        prep_c(tmp, src, src_stride, w, h HIGHBD_TAIL_SUFFIX);
586
40.3k
}
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.2k
{
593
15.2k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
594
15.2k
    int16_t mid[128 * 2];
595
15.2k
    int in_y = -2;
596
597
302k
    do {
598
302k
        int x;
599
302k
        int y = my >> 10;
600
302k
        int16_t *mid1 = &mid[(y & 1) * 128];
601
302k
        int16_t *mid2 = &mid[((y + 1) & 1) * 128];
602
302k
        int dmy = my & 0x3ff;
603
604
472k
        while (in_y < y) {
605
170k
            int imx = mx, ioff = 0;
606
170k
            int16_t *mid_ptr = &mid[(in_y & 1) * 128];
607
608
6.32M
            for (x = 0; x < w; x++) {
609
6.15M
                mid_ptr[x] = FILTER_BILIN_RND(src, ioff, imx >> 6, 1,
610
6.15M
                                              4 - intermediate_bits);
611
6.15M
                imx += dx;
612
6.15M
                ioff += imx >> 10;
613
6.15M
                imx &= 0x3ff;
614
6.15M
            }
615
616
170k
            src += PXSTRIDE(src_stride);
617
170k
            in_y++;
618
170k
        }
619
620
9.88M
        for (x = 0; x < w; x++)
621
9.58M
            tmp[x] = FILTER_BILIN_RND2(mid1, mid2, x, dmy >> 6, 4) - PREP_BIAS;
622
623
302k
        my += dy;
624
302k
        tmp += w;
625
302k
    } while (--h);
626
15.2k
}
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
252k
{
632
252k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
633
252k
    const int sh = intermediate_bits + 1;
634
252k
    const int rnd = (1 << intermediate_bits) + PREP_BIAS * 2;
635
5.28M
    do {
636
149M
        for (int x = 0; x < w; x++)
637
144M
            dst[x] = iclip_pixel((tmp1[x] + tmp2[x] + rnd) >> sh);
638
639
5.28M
        tmp1 += w;
640
5.28M
        tmp2 += w;
641
5.28M
        dst += PXSTRIDE(dst_stride);
642
5.28M
    } while (--h);
643
252k
}
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
32.2k
{
649
32.2k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
650
32.2k
    const int sh = intermediate_bits + 4;
651
32.2k
    const int rnd = (8 << intermediate_bits) + PREP_BIAS * 16;
652
492k
    do {
653
13.7M
        for (int x = 0; x < w; x++)
654
13.2M
            dst[x] = iclip_pixel((tmp1[x] * weight +
655
13.2M
                                  tmp2[x] * (16 - weight) + rnd) >> sh);
656
657
492k
        tmp1 += w;
658
492k
        tmp2 += w;
659
492k
        dst += PXSTRIDE(dst_stride);
660
492k
    } while (--h);
661
32.2k
}
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
36.5k
{
667
36.5k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
668
36.5k
    const int sh = intermediate_bits + 6;
669
36.5k
    const int rnd = (32 << intermediate_bits) + PREP_BIAS * 64;
670
750k
    do {
671
22.0M
        for (int x = 0; x < w; x++)
672
21.3M
            dst[x] = iclip_pixel((tmp1[x] * mask[x] +
673
21.3M
                                  tmp2[x] * (64 - mask[x]) + rnd) >> sh);
674
675
750k
        tmp1 += w;
676
750k
        tmp2 += w;
677
750k
        mask += w;
678
750k
        dst += PXSTRIDE(dst_stride);
679
750k
    } while (--h);
680
36.5k
}
681
682
59.1M
#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
87.0k
{
686
966k
    do {
687
14.7M
        for (int x = 0; x < w; x++) {
688
13.7M
            dst[x] = blend_px(dst[x], tmp[x], mask[x]);
689
13.7M
        }
690
966k
        dst += PXSTRIDE(dst_stride);
691
966k
        tmp += w;
692
966k
        mask += w;
693
966k
    } while (--h);
694
87.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
284k
{
699
284k
    const uint8_t *const mask = &dav1d_obmc_masks[w];
700
3.83M
    do {
701
27.7M
        for (int x = 0; x < (w * 3) >> 2; x++) {
702
23.9M
            dst[x] = blend_px(dst[x], tmp[x], mask[x]);
703
23.9M
        }
704
3.83M
        dst += PXSTRIDE(dst_stride);
705
3.83M
        tmp += w;
706
3.83M
    } while (--h);
707
284k
}
708
709
static void blend_h_c(pixel *dst, const ptrdiff_t dst_stride, const pixel *tmp,
710
                      const int w, int h)
711
283k
{
712
283k
    const uint8_t *mask = &dav1d_obmc_masks[h];
713
283k
    h = (h * 3) >> 2;
714
1.58M
    do {
715
1.58M
        const int m = *mask++;
716
23.0M
        for (int x = 0; x < w; x++) {
717
21.4M
            dst[x] = blend_px(dst[x], tmp[x], m);
718
21.4M
        }
719
1.58M
        dst += PXSTRIDE(dst_stride);
720
1.58M
        tmp += w;
721
1.58M
    } while (--h);
722
283k
}
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
12.9k
{
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
12.9k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
732
12.9k
    const int bitdepth = bitdepth_from_max(bitdepth_max);
733
12.9k
    const int sh = intermediate_bits + 6;
734
12.9k
    const int rnd = (32 << intermediate_bits) + PREP_BIAS * 64;
735
12.9k
    const int mask_sh = bitdepth + intermediate_bits - 4;
736
12.9k
    const int mask_rnd = 1 << (mask_sh - 5);
737
512k
    do {
738
15.3M
        for (int x = 0; x < w; x++) {
739
14.8M
            const int tmpdiff = tmp1[x] - tmp2[x];
740
14.8M
            const int m = imin(38 + ((abs(tmpdiff) + mask_rnd) >> mask_sh), 64);
741
14.8M
            dst[x] = iclip_pixel((tmpdiff * m + tmp2[x] * 64 + rnd) >> sh);
742
743
14.8M
            if (ss_hor) {
744
6.16M
                x++;
745
746
6.16M
                const int tmpdiff = tmp1[x] - tmp2[x];
747
6.16M
                const int n = imin(38 + ((abs(tmpdiff) + mask_rnd) >> mask_sh), 64);
748
6.16M
                dst[x] = iclip_pixel((tmpdiff * n + tmp2[x] * 64 + rnd) >> sh);
749
750
6.16M
                if (h & ss_ver) {
751
2.70M
                    mask[x >> 1] = (m + n + mask[x >> 1] + 2 - sign) >> 2;
752
3.45M
                } else if (ss_ver) {
753
2.70M
                    mask[x >> 1] = m + n;
754
2.70M
                } else {
755
744k
                    mask[x >> 1] = (m + n + 1 - sign) >> 1;
756
744k
                }
757
8.72M
            } else {
758
8.72M
                mask[x] = m;
759
8.72M
            }
760
14.8M
        }
761
762
512k
        tmp1 += w;
763
512k
        tmp2 += w;
764
512k
        dst += PXSTRIDE(dst_stride);
765
512k
        if (!ss_ver || (h & 1)) mask += w >> ss_hor;
766
512k
    } while (--h);
767
12.9k
}
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
12.9k
                             const int sign HIGHBD_DECL_SUFFIX) \
774
12.9k
{ \
775
12.9k
    w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver \
776
12.9k
             HIGHBD_TAIL_SUFFIX); \
777
12.9k
}
mc_tmpl.c:w_mask_444_c
Line
Count
Source
773
5.16k
                             const int sign HIGHBD_DECL_SUFFIX) \
774
5.16k
{ \
775
5.16k
    w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver \
776
5.16k
             HIGHBD_TAIL_SUFFIX); \
777
5.16k
}
mc_tmpl.c:w_mask_422_c
Line
Count
Source
773
1.21k
                             const int sign HIGHBD_DECL_SUFFIX) \
774
1.21k
{ \
775
1.21k
    w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver \
776
1.21k
             HIGHBD_TAIL_SUFFIX); \
777
1.21k
}
mc_tmpl.c:w_mask_420_c
Line
Count
Source
773
6.59k
                             const int sign HIGHBD_DECL_SUFFIX) \
774
6.59k
{ \
775
6.59k
    w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver \
776
6.59k
             HIGHBD_TAIL_SUFFIX); \
777
6.59k
}
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
106M
    ((F[0] * src[x - 3 * stride] + \
787
106M
      F[1] * src[x - 2 * stride] + \
788
106M
      F[2] * src[x - 1 * stride] + \
789
106M
      F[3] * src[x + 0 * stride] + \
790
106M
      F[4] * src[x + 1 * stride] + \
791
106M
      F[5] * src[x + 2 * stride] + \
792
106M
      F[6] * src[x + 3 * stride] + \
793
106M
      F[7] * src[x + 4 * stride] + \
794
106M
      ((1 << (sh)) >> 1)) >> (sh))
795
796
#define FILTER_WARP_CLIP(src, x, F, stride, sh) \
797
24.3M
    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
472k
{
804
472k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
805
472k
    int16_t mid[15 * 8], *mid_ptr = mid;
806
807
472k
    src -= 3 * PXSTRIDE(src_stride);
808
7.31M
    for (int y = 0; y < 15; y++, mx += abcd[1]) {
809
59.9M
        for (int x = 0, tmx = mx; x < 8; x++, tmx += abcd[0]) {
810
53.0M
            const int8_t *const filter =
811
53.0M
                dav1d_mc_warp_filter[64 + ((tmx + 512) >> 10)];
812
813
53.0M
            mid_ptr[x] = FILTER_WARP_RND(src, x, filter, 1,
814
53.0M
                                         7 - intermediate_bits);
815
53.0M
        }
816
6.84M
        src += PXSTRIDE(src_stride);
817
6.84M
        mid_ptr += 8;
818
6.84M
    }
819
820
472k
    mid_ptr = &mid[3 * 8];
821
3.57M
    for (int y = 0; y < 8; y++, my += abcd[3]) {
822
27.4M
        for (int x = 0, tmy = my; x < 8; x++, tmy += abcd[2]) {
823
24.3M
            const int8_t *const filter =
824
24.3M
                dav1d_mc_warp_filter[64 + ((tmy + 512) >> 10)];
825
826
24.3M
            dst[x] = FILTER_WARP_CLIP(mid_ptr, x, filter, 8,
827
24.3M
                                      7 + intermediate_bits);
828
24.3M
        }
829
3.09M
        mid_ptr += 8;
830
3.09M
        dst += PXSTRIDE(dst_stride);
831
3.09M
    }
832
472k
}
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
156k
{
839
156k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
840
156k
    int16_t mid[15 * 8], *mid_ptr = mid;
841
842
156k
    src -= 3 * PXSTRIDE(src_stride);
843
2.49M
    for (int y = 0; y < 15; y++, mx += abcd[1]) {
844
21.0M
        for (int x = 0, tmx = mx; x < 8; x++, tmx += abcd[0]) {
845
18.6M
            const int8_t *const filter =
846
18.6M
                dav1d_mc_warp_filter[64 + ((tmx + 512) >> 10)];
847
848
18.6M
            mid_ptr[x] = FILTER_WARP_RND(src, x, filter, 1,
849
18.6M
                                         7 - intermediate_bits);
850
18.6M
        }
851
2.33M
        src += PXSTRIDE(src_stride);
852
2.33M
        mid_ptr += 8;
853
2.33M
    }
854
855
156k
    mid_ptr = &mid[3 * 8];
856
1.40M
    for (int y = 0; y < 8; y++, my += abcd[3]) {
857
11.2M
        for (int x = 0, tmy = my; x < 8; x++, tmy += abcd[2]) {
858
10.0M
            const int8_t *const filter =
859
10.0M
                dav1d_mc_warp_filter[64 + ((tmy + 512) >> 10)];
860
861
10.0M
            tmp[x] = FILTER_WARP_RND(mid_ptr, x, filter, 8, 7) - PREP_BIAS;
862
10.0M
        }
863
1.25M
        mid_ptr += 8;
864
1.25M
        tmp += tmp_stride;
865
1.25M
    }
866
156k
}
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.49M
{
874
    // find offset in reference of visible block to copy
875
2.49M
    ref += iclip((int) y, 0, (int) ih - 1) * PXSTRIDE(ref_stride) +
876
2.49M
           iclip((int) x, 0, (int) iw - 1);
877
878
    // number of pixels to extend (left, right, top, bottom)
879
2.49M
    const int left_ext = iclip((int) -x, 0, (int) bw - 1);
880
2.49M
    const int right_ext = iclip((int) (x + bw - iw), 0, (int) bw - 1);
881
2.49M
    assert(left_ext + right_ext < bw);
882
2.49M
    const int top_ext = iclip((int) -y, 0, (int) bh - 1);
883
2.49M
    const int bottom_ext = iclip((int) (y + bh - ih), 0, (int) bh - 1);
884
2.49M
    assert(top_ext + bottom_ext < bh);
885
886
    // copy visible portion first
887
2.49M
    pixel *blk = dst + top_ext * PXSTRIDE(dst_stride);
888
2.49M
    const int center_w = (int) (bw - left_ext - right_ext);
889
2.49M
    const int center_h = (int) (bh - top_ext - bottom_ext);
890
34.0M
    for (int y = 0; y < center_h; y++) {
891
31.5M
        pixel_copy(blk + left_ext, ref, center_w);
892
        // extend left edge for this line
893
31.5M
        if (left_ext)
894
7.65M
            pixel_set(blk, blk[left_ext], left_ext);
895
        // extend right edge for this line
896
31.5M
        if (right_ext)
897
23.0M
            pixel_set(blk + left_ext + center_w, blk[left_ext + center_w - 1],
898
23.0M
                      right_ext);
899
31.5M
        ref += PXSTRIDE(ref_stride);
900
31.5M
        blk += PXSTRIDE(dst_stride);
901
31.5M
    }
902
903
    // copy top
904
2.49M
    blk = dst + top_ext * PXSTRIDE(dst_stride);
905
6.10M
    for (int y = 0; y < top_ext; y++) {
906
3.60M
        pixel_copy(dst, blk, bw);
907
3.60M
        dst += PXSTRIDE(dst_stride);
908
3.60M
    }
909
910
    // copy bottom
911
2.49M
    dst += center_h * PXSTRIDE(dst_stride);
912
10.6M
    for (int y = 0; y < bottom_ext; y++) {
913
8.12M
        pixel_copy(dst, &dst[-PXSTRIDE(dst_stride)], bw);
914
8.12M
        dst += PXSTRIDE(dst_stride);
915
8.12M
    }
916
2.49M
}
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
251k
{
923
8.17M
    do {
924
8.17M
        int mx = mx0, src_x = -1;
925
712M
        for (int x = 0; x < dst_w; x++) {
926
704M
            const int8_t *const F = dav1d_resize_filter[mx >> 8];
927
704M
            dst[x] = iclip_pixel((-(F[0] * src[iclip(src_x - 3, 0, src_w - 1)] +
928
704M
                                    F[1] * src[iclip(src_x - 2, 0, src_w - 1)] +
929
704M
                                    F[2] * src[iclip(src_x - 1, 0, src_w - 1)] +
930
704M
                                    F[3] * src[iclip(src_x + 0, 0, src_w - 1)] +
931
704M
                                    F[4] * src[iclip(src_x + 1, 0, src_w - 1)] +
932
704M
                                    F[5] * src[iclip(src_x + 2, 0, src_w - 1)] +
933
704M
                                    F[6] * src[iclip(src_x + 3, 0, src_w - 1)] +
934
704M
                                    F[7] * src[iclip(src_x + 4, 0, src_w - 1)]) +
935
704M
                                  64) >> 7);
936
704M
            mx += dx;
937
704M
            src_x += mx >> 14;
938
704M
            mx &= 0x3fff;
939
704M
        }
940
941
8.17M
        dst += PXSTRIDE(dst_stride);
942
8.17M
        src += PXSTRIDE(src_stride);
943
8.17M
    } while (--h);
944
251k
}
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
78.8k
COLD void bitfn(dav1d_mc_dsp_init)(Dav1dMCDSPContext *const c) {
961
788k
#define init_mc_fns(type, name) do { \
962
788k
    c->mc        [type] = put_##name##_c; \
963
788k
    c->mc_scaled [type] = put_##name##_scaled_c; \
964
788k
    c->mct       [type] = prep_##name##_c; \
965
788k
    c->mct_scaled[type] = prep_##name##_scaled_c; \
966
788k
} while (0)
967
968
78.8k
    init_mc_fns(FILTER_2D_8TAP_REGULAR,        8tap_regular);
969
78.8k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SMOOTH, 8tap_regular_smooth);
970
78.8k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SHARP,  8tap_regular_sharp);
971
78.8k
    init_mc_fns(FILTER_2D_8TAP_SHARP_REGULAR,  8tap_sharp_regular);
972
78.8k
    init_mc_fns(FILTER_2D_8TAP_SHARP_SMOOTH,   8tap_sharp_smooth);
973
78.8k
    init_mc_fns(FILTER_2D_8TAP_SHARP,          8tap_sharp);
974
78.8k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_REGULAR, 8tap_smooth_regular);
975
78.8k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH,         8tap_smooth);
976
78.8k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_SHARP,   8tap_smooth_sharp);
977
78.8k
    init_mc_fns(FILTER_2D_BILINEAR,            bilin);
978
979
78.8k
    c->avg      = avg_c;
980
78.8k
    c->w_avg    = w_avg_c;
981
78.8k
    c->mask     = mask_c;
982
78.8k
    c->blend    = blend_c;
983
78.8k
    c->blend_v  = blend_v_c;
984
78.8k
    c->blend_h  = blend_h_c;
985
78.8k
    c->w_mask[0] = w_mask_444_c;
986
78.8k
    c->w_mask[1] = w_mask_422_c;
987
78.8k
    c->w_mask[2] = w_mask_420_c;
988
78.8k
    c->warp8x8  = warp_affine_8x8_c;
989
78.8k
    c->warp8x8t = warp_affine_8x8t_c;
990
78.8k
    c->emu_edge = emu_edge_c;
991
78.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
78.8k
}
dav1d_mc_dsp_init_8bpc
Line
Count
Source
960
35.6k
COLD void bitfn(dav1d_mc_dsp_init)(Dav1dMCDSPContext *const c) {
961
35.6k
#define init_mc_fns(type, name) do { \
962
35.6k
    c->mc        [type] = put_##name##_c; \
963
35.6k
    c->mc_scaled [type] = put_##name##_scaled_c; \
964
35.6k
    c->mct       [type] = prep_##name##_c; \
965
35.6k
    c->mct_scaled[type] = prep_##name##_scaled_c; \
966
35.6k
} while (0)
967
968
35.6k
    init_mc_fns(FILTER_2D_8TAP_REGULAR,        8tap_regular);
969
35.6k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SMOOTH, 8tap_regular_smooth);
970
35.6k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SHARP,  8tap_regular_sharp);
971
35.6k
    init_mc_fns(FILTER_2D_8TAP_SHARP_REGULAR,  8tap_sharp_regular);
972
35.6k
    init_mc_fns(FILTER_2D_8TAP_SHARP_SMOOTH,   8tap_sharp_smooth);
973
35.6k
    init_mc_fns(FILTER_2D_8TAP_SHARP,          8tap_sharp);
974
35.6k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_REGULAR, 8tap_smooth_regular);
975
35.6k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH,         8tap_smooth);
976
35.6k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_SHARP,   8tap_smooth_sharp);
977
35.6k
    init_mc_fns(FILTER_2D_BILINEAR,            bilin);
978
979
35.6k
    c->avg      = avg_c;
980
35.6k
    c->w_avg    = w_avg_c;
981
35.6k
    c->mask     = mask_c;
982
35.6k
    c->blend    = blend_c;
983
35.6k
    c->blend_v  = blend_v_c;
984
35.6k
    c->blend_h  = blend_h_c;
985
35.6k
    c->w_mask[0] = w_mask_444_c;
986
35.6k
    c->w_mask[1] = w_mask_422_c;
987
35.6k
    c->w_mask[2] = w_mask_420_c;
988
35.6k
    c->warp8x8  = warp_affine_8x8_c;
989
35.6k
    c->warp8x8t = warp_affine_8x8t_c;
990
35.6k
    c->emu_edge = emu_edge_c;
991
35.6k
    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.6k
}
dav1d_mc_dsp_init_16bpc
Line
Count
Source
960
43.1k
COLD void bitfn(dav1d_mc_dsp_init)(Dav1dMCDSPContext *const c) {
961
43.1k
#define init_mc_fns(type, name) do { \
962
43.1k
    c->mc        [type] = put_##name##_c; \
963
43.1k
    c->mc_scaled [type] = put_##name##_scaled_c; \
964
43.1k
    c->mct       [type] = prep_##name##_c; \
965
43.1k
    c->mct_scaled[type] = prep_##name##_scaled_c; \
966
43.1k
} while (0)
967
968
43.1k
    init_mc_fns(FILTER_2D_8TAP_REGULAR,        8tap_regular);
969
43.1k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SMOOTH, 8tap_regular_smooth);
970
43.1k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SHARP,  8tap_regular_sharp);
971
43.1k
    init_mc_fns(FILTER_2D_8TAP_SHARP_REGULAR,  8tap_sharp_regular);
972
43.1k
    init_mc_fns(FILTER_2D_8TAP_SHARP_SMOOTH,   8tap_sharp_smooth);
973
43.1k
    init_mc_fns(FILTER_2D_8TAP_SHARP,          8tap_sharp);
974
43.1k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_REGULAR, 8tap_smooth_regular);
975
43.1k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH,         8tap_smooth);
976
43.1k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_SHARP,   8tap_smooth_sharp);
977
43.1k
    init_mc_fns(FILTER_2D_BILINEAR,            bilin);
978
979
43.1k
    c->avg      = avg_c;
980
43.1k
    c->w_avg    = w_avg_c;
981
43.1k
    c->mask     = mask_c;
982
43.1k
    c->blend    = blend_c;
983
43.1k
    c->blend_v  = blend_v_c;
984
43.1k
    c->blend_h  = blend_h_c;
985
43.1k
    c->w_mask[0] = w_mask_444_c;
986
43.1k
    c->w_mask[1] = w_mask_422_c;
987
43.1k
    c->w_mask[2] = w_mask_420_c;
988
43.1k
    c->warp8x8  = warp_affine_8x8_c;
989
43.1k
    c->warp8x8t = warp_affine_8x8t_c;
990
43.1k
    c->emu_edge = emu_edge_c;
991
43.1k
    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
43.1k
}