Coverage Report

Created: 2026-08-31 06:22

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.71M
#define get_intermediate_bits(bitdepth_max) 4
41
// Output in interval [-5132, 9212], fits in int16_t as is
42
370M
#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.1M
    do {
56
16.1M
        pixel_copy(dst, src, w);
57
58
16.1M
        dst += dst_stride;
59
16.1M
        src += src_stride;
60
16.1M
    } 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
144k
{
67
144k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
68
3.67M
    do {
69
112M
        for (int x = 0; x < w; x++)
70
109M
            tmp[x] = (src[x] << intermediate_bits) - PREP_BIAS;
71
72
3.67M
        tmp += w;
73
3.67M
        src += src_stride;
74
3.67M
    } while (--h);
75
144k
}
76
77
#define FILTER_8TAP(src, x, F, stride) \
78
627M
    (F[0] * src[x + -3 * stride] + \
79
627M
     F[1] * src[x + -2 * stride] + \
80
627M
     F[2] * src[x + -1 * stride] + \
81
627M
     F[3] * src[x + +0 * stride] + \
82
627M
     F[4] * src[x + +1 * stride] + \
83
627M
     F[5] * src[x + +2 * stride] + \
84
627M
     F[6] * src[x + +3 * stride] + \
85
627M
     F[7] * src[x + +4 * stride])
86
87
#define FILTER_8TAP2(src, x, F) \
88
486M
    (F[0] * src[0][x] + \
89
486M
     F[1] * src[1][x] + \
90
486M
     F[2] * src[2][x] + \
91
486M
     F[3] * src[3][x] + \
92
486M
     F[4] * src[4][x] + \
93
486M
     F[5] * src[5][x] + \
94
486M
     F[6] * src[6][x] + \
95
486M
     F[7] * src[7][x])
96
97
#define DAV1D_FILTER_8TAP_RND(src, x, F, stride, sh) \
98
606M
    ((FILTER_8TAP(src, x, F, stride) + ((1 << (sh)) >> 1)) >> (sh))
99
100
#define DAV1D_FILTER_8TAP_RND2(src, x, F, stride, rnd, sh) \
101
21.0M
    ((FILTER_8TAP(src, x, F, stride) + (rnd)) >> (sh))
102
103
#define DAV1D_FILTER_8TAP_RND3(src, x, F, sh) \
104
486M
    ((FILTER_8TAP2(src, x, F) + ((1 << (sh)) >> 1)) >> (sh))
105
106
#define DAV1D_FILTER_8TAP_CLIP(src, x, F, stride, sh) \
107
53.1M
    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
21.0M
    iclip_pixel(DAV1D_FILTER_8TAP_RND2(src, x, F, stride, rnd, sh))
111
112
#define DAV1D_FILTER_8TAP_CLIP3(src, x, F, sh) \
113
327M
    iclip_pixel(DAV1D_FILTER_8TAP_RND3(src, x, F, sh))
114
115
#define GET_H_FILTER(mx) \
116
474M
    const int8_t *const fh = !(mx) ? NULL : w > 4 ? \
117
440M
        dav1d_mc_subpel_filters[filter_type & 3][(mx) - 1] : \
118
440M
        dav1d_mc_subpel_filters[3 + (filter_type & 1)][(mx) - 1]
119
120
#define GET_V_FILTER(my) \
121
23.6M
    const int8_t *const fv = !(my) ? NULL : h > 4 ? \
122
20.6M
        dav1d_mc_subpel_filters[filter_type >> 2][(my) - 1] : \
123
20.6M
        dav1d_mc_subpel_filters[3 + ((filter_type >> 2) & 1)][(my) - 1]
124
125
#define GET_FILTERS() \
126
1.07M
    GET_H_FILTER(mx); \
127
1.07M
    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
848k
{
135
848k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
136
848k
    const int intermediate_rnd = 32 + ((1 << (6 - intermediate_bits)) >> 1);
137
138
848k
    GET_FILTERS();
139
848k
    dst_stride = PXSTRIDE(dst_stride);
140
848k
    src_stride = PXSTRIDE(src_stride);
141
142
848k
    if (fh) {
143
249k
        if (fv) {
144
169k
            int tmp_h = h + 7;
145
169k
            int16_t mid[128 * 135], *mid_ptr = mid;
146
147
169k
            src -= src_stride * 3;
148
2.92M
            do {
149
49.2M
                for (int x = 0; x < w; x++)
150
46.3M
                    mid_ptr[x] = DAV1D_FILTER_8TAP_RND(src, x, fh, 1,
151
2.92M
                                                       6 - intermediate_bits);
152
153
2.92M
                mid_ptr += 128;
154
2.92M
                src += src_stride;
155
2.92M
            } while (--tmp_h);
156
157
169k
            mid_ptr = mid + 128 * 3;
158
1.72M
            do {
159
35.4M
                for (int x = 0; x < w; x++)
160
33.7M
                    dst[x] = DAV1D_FILTER_8TAP_CLIP(mid_ptr, x, fv, 128,
161
1.72M
                                                    6 + intermediate_bits);
162
163
1.72M
                mid_ptr += 128;
164
1.72M
                dst += dst_stride;
165
1.72M
            } while (--h);
166
169k
        } else {
167
806k
            do {
168
21.8M
                for (int x = 0; x < w; x++) {
169
21.0M
                    dst[x] = DAV1D_FILTER_8TAP_CLIP2(src, x, fh, 1,
170
21.0M
                                                     intermediate_rnd, 6);
171
21.0M
                }
172
173
806k
                dst += dst_stride;
174
806k
                src += src_stride;
175
806k
            } while (--h);
176
79.8k
        }
177
598k
    } else if (fv) {
178
972k
        do {
179
20.3M
            for (int x = 0; x < w; x++)
180
19.3M
                dst[x] = DAV1D_FILTER_8TAP_CLIP(src, x, fv, src_stride, 6);
181
182
972k
            dst += dst_stride;
183
972k
            src += src_stride;
184
972k
        } while (--h);
185
107k
    } else
186
491k
        put_c(dst, dst_stride, src, src_stride, w, h);
187
848k
}
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.23M
{
196
1.23M
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
197
1.23M
    const int intermediate_rnd = (1 << intermediate_bits) >> 1;
198
1.23M
    int16_t mid[128 * 8];
199
1.23M
    int16_t *mid_ptrs[8];
200
1.23M
    int in_y = -8;
201
1.23M
    src_stride = PXSTRIDE(src_stride);
202
203
11.0M
    for (int i = 0; i < 8; i++)
204
9.85M
        mid_ptrs[i] = &mid[128 * i];
205
206
1.23M
    src -= src_stride * 3;
207
208
17.2M
    for (int y = 0; y < h; y++) {
209
16.0M
        int x;
210
16.0M
        int src_y = my >> 10;
211
16.0M
        GET_V_FILTER((my & 0x3ff) >> 6);
212
213
33.6M
        while (in_y < src_y) {
214
17.5M
            int imx = mx, ioff = 0;
215
17.5M
            int16_t *mid_ptr = mid_ptrs[0];
216
217
140M
            for (int i = 0; i < 7; i++)
218
123M
                mid_ptrs[i] = mid_ptrs[i + 1];
219
17.5M
            mid_ptrs[7] = mid_ptr;
220
221
342M
            for (x = 0; x < w; x++) {
222
325M
                GET_H_FILTER(imx >> 6);
223
325M
                mid_ptr[x] = fh ? DAV1D_FILTER_8TAP_RND(src, ioff, fh, 1,
224
325M
                                                        6 - intermediate_bits) :
225
325M
                                  src[ioff] << intermediate_bits;
226
325M
                imx += dx;
227
325M
                ioff += imx >> 10;
228
325M
                imx &= 0x3ff;
229
325M
            }
230
231
17.5M
            src += src_stride;
232
17.5M
            in_y++;
233
17.5M
        }
234
235
374M
        for (x = 0; x < w; x++)
236
358M
            dst[x] = fv ? DAV1D_FILTER_8TAP_CLIP3(mid_ptrs, x, fv,
237
358M
                                                  6 + intermediate_bits) :
238
358M
                          iclip_pixel((mid_ptrs[3][x] + intermediate_rnd) >>
239
31.1M
                                              intermediate_bits);
240
241
16.0M
        my += dy;
242
16.0M
        dst += PXSTRIDE(dst_stride);
243
16.0M
    }
244
1.23M
}
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
223k
{
251
223k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
252
223k
    GET_FILTERS();
253
223k
    src_stride = PXSTRIDE(src_stride);
254
255
223k
    if (fh) {
256
72.0k
        if (fv) {
257
49.9k
            int tmp_h = h + 7;
258
49.9k
            int16_t mid[128 * 135], *mid_ptr = mid;
259
260
49.9k
            src -= src_stride * 3;
261
1.19M
            do {
262
24.0M
                for (int x = 0; x < w; x++)
263
22.9M
                    mid_ptr[x] = DAV1D_FILTER_8TAP_RND(src, x, fh, 1,
264
1.19M
                                                       6 - intermediate_bits);
265
266
1.19M
                mid_ptr += 128;
267
1.19M
                src += src_stride;
268
1.19M
            } while (--tmp_h);
269
270
49.9k
            mid_ptr = mid + 128 * 3;
271
847k
            do {
272
19.5M
                for (int x = 0; x < w; x++) {
273
18.6M
                    int t = DAV1D_FILTER_8TAP_RND(mid_ptr, x, fv, 128, 6) -
274
18.6M
                                  PREP_BIAS;
275
18.6M
                    assert(t >= INT16_MIN && t <= INT16_MAX);
276
18.6M
                    tmp[x] = t;
277
18.6M
                }
278
279
847k
                mid_ptr += 128;
280
847k
                tmp += w;
281
847k
            } while (--h);
282
49.9k
        } else {
283
500k
            do {
284
17.9M
                for (int x = 0; x < w; x++)
285
17.4M
                    tmp[x] = DAV1D_FILTER_8TAP_RND(src, x, fh, 1,
286
17.4M
                                                   6 - intermediate_bits) -
287
17.4M
                             PREP_BIAS;
288
289
500k
                tmp += w;
290
500k
                src += src_stride;
291
500k
            } while (--h);
292
22.1k
        }
293
151k
    } else if (fv) {
294
305k
        do {
295
7.17M
            for (int x = 0; x < w; x++)
296
6.86M
                tmp[x] = DAV1D_FILTER_8TAP_RND(src, x, fv, src_stride,
297
6.86M
                                               6 - intermediate_bits) -
298
6.86M
                         PREP_BIAS;
299
300
305k
            tmp += w;
301
305k
            src += src_stride;
302
305k
        } while (--h);
303
18.7k
    } else
304
132k
        prep_c(tmp, src, src_stride, w, h HIGHBD_TAIL_SUFFIX);
305
223k
}
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
321k
{
313
321k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
314
321k
    int16_t mid[128 * 8];
315
321k
    int16_t *mid_ptrs[8];
316
321k
    int in_y = -8;
317
321k
    src_stride = PXSTRIDE(src_stride);
318
319
2.89M
    for (int i = 0; i < 8; i++)
320
2.57M
        mid_ptrs[i] = &mid[128 * i];
321
322
321k
    src -= src_stride * 3;
323
324
6.79M
    for (int y = 0; y < h; y++) {
325
6.47M
        int x;
326
6.47M
        int src_y = my >> 10;
327
6.47M
        GET_V_FILTER((my & 0x3ff) >> 6);
328
329
12.2M
        while (in_y < src_y) {
330
5.73M
            int imx = mx, ioff = 0;
331
5.73M
            int16_t *mid_ptr = mid_ptrs[0];
332
333
45.9M
            for (int i = 0; i < 7; i++)
334
40.1M
                mid_ptrs[i] = mid_ptrs[i + 1];
335
5.73M
            mid_ptrs[7] = mid_ptr;
336
337
153M
            for (x = 0; x < w; x++) {
338
148M
                GET_H_FILTER(imx >> 6);
339
148M
                mid_ptr[x] = fh ? DAV1D_FILTER_8TAP_RND(src, ioff, fh, 1,
340
148M
                                                        6 - intermediate_bits) :
341
148M
                                  src[ioff] << intermediate_bits;
342
148M
                imx += dx;
343
148M
                ioff += imx >> 10;
344
148M
                imx &= 0x3ff;
345
148M
            }
346
347
5.73M
            src += src_stride;
348
5.73M
            in_y++;
349
5.73M
        }
350
351
196M
        for (x = 0; x < w; x++)
352
189M
            tmp[x] = (fv ? DAV1D_FILTER_8TAP_RND3(mid_ptrs, x, fv, 6)
353
189M
                         : mid_ptrs[3][x]) - PREP_BIAS;
354
355
6.47M
        my += dy;
356
6.47M
        tmp += w;
357
6.47M
    }
358
321k
}
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
848k
                                HIGHBD_DECL_SUFFIX) \
368
848k
{ \
369
848k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
848k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
848k
} \
mc_tmpl.c:put_8tap_regular_c
Line
Count
Source
367
329k
                                HIGHBD_DECL_SUFFIX) \
368
329k
{ \
369
329k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
329k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
329k
} \
mc_tmpl.c:put_8tap_regular_smooth_c
Line
Count
Source
367
13.5k
                                HIGHBD_DECL_SUFFIX) \
368
13.5k
{ \
369
13.5k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
13.5k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
13.5k
} \
mc_tmpl.c:put_8tap_regular_sharp_c
Line
Count
Source
367
3.28k
                                HIGHBD_DECL_SUFFIX) \
368
3.28k
{ \
369
3.28k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
3.28k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
3.28k
} \
mc_tmpl.c:put_8tap_sharp_regular_c
Line
Count
Source
367
3.38k
                                HIGHBD_DECL_SUFFIX) \
368
3.38k
{ \
369
3.38k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
3.38k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
3.38k
} \
mc_tmpl.c:put_8tap_sharp_smooth_c
Line
Count
Source
367
1.59k
                                HIGHBD_DECL_SUFFIX) \
368
1.59k
{ \
369
1.59k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
1.59k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
1.59k
} \
mc_tmpl.c:put_8tap_sharp_c
Line
Count
Source
367
54.8k
                                HIGHBD_DECL_SUFFIX) \
368
54.8k
{ \
369
54.8k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
54.8k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
54.8k
} \
mc_tmpl.c:put_8tap_smooth_regular_c
Line
Count
Source
367
11.4k
                                HIGHBD_DECL_SUFFIX) \
368
11.4k
{ \
369
11.4k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
11.4k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
11.4k
} \
mc_tmpl.c:put_8tap_smooth_c
Line
Count
Source
367
429k
                                HIGHBD_DECL_SUFFIX) \
368
429k
{ \
369
429k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
429k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
429k
} \
mc_tmpl.c:put_8tap_smooth_sharp_c
Line
Count
Source
367
1.48k
                                HIGHBD_DECL_SUFFIX) \
368
1.48k
{ \
369
1.48k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
1.48k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
1.48k
} \
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.23M
                                       HIGHBD_DECL_SUFFIX) \
380
1.23M
{ \
381
1.23M
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
1.23M
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
1.23M
} \
mc_tmpl.c:put_8tap_regular_scaled_c
Line
Count
Source
379
928k
                                       HIGHBD_DECL_SUFFIX) \
380
928k
{ \
381
928k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
928k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
928k
} \
mc_tmpl.c:put_8tap_regular_smooth_scaled_c
Line
Count
Source
379
54.0k
                                       HIGHBD_DECL_SUFFIX) \
380
54.0k
{ \
381
54.0k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
54.0k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
54.0k
} \
mc_tmpl.c:put_8tap_regular_sharp_scaled_c
Line
Count
Source
379
11.1k
                                       HIGHBD_DECL_SUFFIX) \
380
11.1k
{ \
381
11.1k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
11.1k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
11.1k
} \
mc_tmpl.c:put_8tap_sharp_regular_scaled_c
Line
Count
Source
379
15.7k
                                       HIGHBD_DECL_SUFFIX) \
380
15.7k
{ \
381
15.7k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
15.7k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
15.7k
} \
mc_tmpl.c:put_8tap_sharp_smooth_scaled_c
Line
Count
Source
379
4.11k
                                       HIGHBD_DECL_SUFFIX) \
380
4.11k
{ \
381
4.11k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
4.11k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
4.11k
} \
mc_tmpl.c:put_8tap_sharp_scaled_c
Line
Count
Source
379
67.8k
                                       HIGHBD_DECL_SUFFIX) \
380
67.8k
{ \
381
67.8k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
67.8k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
67.8k
} \
mc_tmpl.c:put_8tap_smooth_regular_scaled_c
Line
Count
Source
379
64.3k
                                       HIGHBD_DECL_SUFFIX) \
380
64.3k
{ \
381
64.3k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
64.3k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
64.3k
} \
mc_tmpl.c:put_8tap_smooth_scaled_c
Line
Count
Source
379
82.9k
                                       HIGHBD_DECL_SUFFIX) \
380
82.9k
{ \
381
82.9k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
82.9k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
82.9k
} \
mc_tmpl.c:put_8tap_smooth_sharp_scaled_c
Line
Count
Source
379
4.06k
                                       HIGHBD_DECL_SUFFIX) \
380
4.06k
{ \
381
4.06k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
4.06k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
4.06k
} \
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
223k
                                 HIGHBD_DECL_SUFFIX) \
390
223k
{ \
391
223k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
223k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
223k
} \
mc_tmpl.c:prep_8tap_regular_c
Line
Count
Source
389
66.8k
                                 HIGHBD_DECL_SUFFIX) \
390
66.8k
{ \
391
66.8k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
66.8k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
66.8k
} \
mc_tmpl.c:prep_8tap_regular_smooth_c
Line
Count
Source
389
1.99k
                                 HIGHBD_DECL_SUFFIX) \
390
1.99k
{ \
391
1.99k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
1.99k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
1.99k
} \
mc_tmpl.c:prep_8tap_regular_sharp_c
Line
Count
Source
389
5.18k
                                 HIGHBD_DECL_SUFFIX) \
390
5.18k
{ \
391
5.18k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
5.18k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
5.18k
} \
mc_tmpl.c:prep_8tap_sharp_regular_c
Line
Count
Source
389
8.59k
                                 HIGHBD_DECL_SUFFIX) \
390
8.59k
{ \
391
8.59k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
8.59k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
8.59k
} \
mc_tmpl.c:prep_8tap_sharp_smooth_c
Line
Count
Source
389
2.77k
                                 HIGHBD_DECL_SUFFIX) \
390
2.77k
{ \
391
2.77k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
2.77k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
2.77k
} \
mc_tmpl.c:prep_8tap_sharp_c
Line
Count
Source
389
37.4k
                                 HIGHBD_DECL_SUFFIX) \
390
37.4k
{ \
391
37.4k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
37.4k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
37.4k
} \
mc_tmpl.c:prep_8tap_smooth_regular_c
Line
Count
Source
389
2.56k
                                 HIGHBD_DECL_SUFFIX) \
390
2.56k
{ \
391
2.56k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
2.56k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
2.56k
} \
mc_tmpl.c:prep_8tap_smooth_c
Line
Count
Source
389
95.9k
                                 HIGHBD_DECL_SUFFIX) \
390
95.9k
{ \
391
95.9k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
95.9k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
95.9k
} \
mc_tmpl.c:prep_8tap_smooth_sharp_c
Line
Count
Source
389
2.23k
                                 HIGHBD_DECL_SUFFIX) \
390
2.23k
{ \
391
2.23k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
2.23k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
2.23k
} \
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
321k
                                        HIGHBD_DECL_SUFFIX) \
401
321k
{ \
402
321k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
321k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
321k
}
mc_tmpl.c:prep_8tap_regular_scaled_c
Line
Count
Source
400
128k
                                        HIGHBD_DECL_SUFFIX) \
401
128k
{ \
402
128k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
128k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
128k
}
mc_tmpl.c:prep_8tap_regular_smooth_scaled_c
Line
Count
Source
400
14.6k
                                        HIGHBD_DECL_SUFFIX) \
401
14.6k
{ \
402
14.6k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
14.6k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
14.6k
}
mc_tmpl.c:prep_8tap_regular_sharp_scaled_c
Line
Count
Source
400
16.0k
                                        HIGHBD_DECL_SUFFIX) \
401
16.0k
{ \
402
16.0k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
16.0k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
16.0k
}
mc_tmpl.c:prep_8tap_sharp_regular_scaled_c
Line
Count
Source
400
44.9k
                                        HIGHBD_DECL_SUFFIX) \
401
44.9k
{ \
402
44.9k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
44.9k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
44.9k
}
mc_tmpl.c:prep_8tap_sharp_smooth_scaled_c
Line
Count
Source
400
7.79k
                                        HIGHBD_DECL_SUFFIX) \
401
7.79k
{ \
402
7.79k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
7.79k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
7.79k
}
mc_tmpl.c:prep_8tap_sharp_scaled_c
Line
Count
Source
400
31.6k
                                        HIGHBD_DECL_SUFFIX) \
401
31.6k
{ \
402
31.6k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
31.6k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
31.6k
}
mc_tmpl.c:prep_8tap_smooth_regular_scaled_c
Line
Count
Source
400
26.7k
                                        HIGHBD_DECL_SUFFIX) \
401
26.7k
{ \
402
26.7k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
26.7k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
26.7k
}
mc_tmpl.c:prep_8tap_smooth_scaled_c
Line
Count
Source
400
44.1k
                                        HIGHBD_DECL_SUFFIX) \
401
44.1k
{ \
402
44.1k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
44.1k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
44.1k
}
mc_tmpl.c:prep_8tap_smooth_sharp_scaled_c
Line
Count
Source
400
6.51k
                                        HIGHBD_DECL_SUFFIX) \
401
6.51k
{ \
402
6.51k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
6.51k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
6.51k
}
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
91.8M
    (16 * src[x] + ((mxy) * (src[x + stride] - src[x])))
418
419
#define FILTER_BILIN_RND(src, x, mxy, stride, sh) \
420
91.8M
    ((FILTER_BILIN(src, x, mxy, stride) + ((1 << (sh)) >> 1)) >> (sh))
421
422
#define FILTER_BILIN_CLIP(src, x, mxy, stride, sh) \
423
21.6M
    iclip_pixel(FILTER_BILIN_RND(src, x, mxy, stride, sh))
424
425
#define FILTER_BILIN2(src1, src2, x, mxy) \
426
38.7M
    (16 * src1[x] + ((mxy) * (src2[x] - src1[x])))
427
428
#define FILTER_BILIN_RND2(src1, src2, x, mxy, sh) \
429
38.7M
    ((FILTER_BILIN2(src1, src2, x, mxy) + ((1 << (sh)) >> 1)) >> (sh))
430
431
#define FILTER_BILIN_CLIP2(src1, src2, x, mxy, sh) \
432
30.2M
    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
809k
{
439
809k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
440
809k
    const int intermediate_rnd = (1 << intermediate_bits) >> 1;
441
809k
    dst_stride = PXSTRIDE(dst_stride);
442
809k
    src_stride = PXSTRIDE(src_stride);
443
444
809k
    if (mx) {
445
171k
        if (my) {
446
90.9k
            int16_t mid[128 * 129], *mid_ptr = mid;
447
90.9k
            int tmp_h = h + 1;
448
449
846k
            do {
450
13.5M
                for (int x = 0; x < w; x++)
451
12.7M
                    mid_ptr[x] = FILTER_BILIN_RND(src, x, mx, 1,
452
846k
                                                  4 - intermediate_bits);
453
454
846k
                mid_ptr += 128;
455
846k
                src += src_stride;
456
846k
            } while (--tmp_h);
457
458
90.9k
            mid_ptr = mid;
459
756k
            do {
460
12.6M
                for (int x = 0; x < w; x++)
461
11.9M
                    dst[x] = FILTER_BILIN_CLIP(mid_ptr, x, my, 128,
462
756k
                                               4 + intermediate_bits);
463
464
756k
                mid_ptr += 128;
465
756k
                dst += dst_stride;
466
756k
            } while (--h);
467
90.9k
        } else {
468
802k
            do {
469
19.0M
                for (int x = 0; x < w; x++) {
470
18.2M
                    const int px = FILTER_BILIN_RND(src, x, mx, 1,
471
18.2M
                                                    4 - intermediate_bits);
472
18.2M
                    dst[x] = iclip_pixel((px + intermediate_rnd) >> intermediate_bits);
473
18.2M
                }
474
475
802k
                dst += dst_stride;
476
802k
                src += src_stride;
477
802k
            } while (--h);
478
80.8k
        }
479
638k
    } else if (my) {
480
613k
        do {
481
10.3M
            for (int x = 0; x < w; x++)
482
9.75M
                dst[x] = FILTER_BILIN_CLIP(src, x, my, src_stride, 4);
483
484
613k
            dst += dst_stride;
485
613k
            src += src_stride;
486
613k
        } while (--h);
487
73.9k
    } else
488
564k
        put_c(dst, dst_stride, src, src_stride, w, h);
489
809k
}
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
79.8k
{
497
79.8k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
498
79.8k
    int16_t mid[128 * 2];
499
79.8k
    int in_y = -2;
500
501
1.12M
    do {
502
1.12M
        int x;
503
1.12M
        int y = my >> 10;
504
1.12M
        int16_t *mid1 = &mid[(y & 1) * 128];
505
1.12M
        int16_t *mid2 = &mid[((y + 1) & 1) * 128];
506
1.12M
        int dmy = my & 0x3ff;
507
508
1.76M
        while (in_y < y) {
509
638k
            int imx = mx, ioff = 0;
510
638k
            int16_t *mid_ptr = &mid[(in_y & 1) * 128];
511
512
22.0M
            for (x = 0; x < w; x++) {
513
21.3M
                mid_ptr[x] = FILTER_BILIN_RND(src, ioff, imx >> 6, 1,
514
21.3M
                                              4 - intermediate_bits);
515
21.3M
                imx += dx;
516
21.3M
                ioff += imx >> 10;
517
21.3M
                imx &= 0x3ff;
518
21.3M
            }
519
520
638k
            src += PXSTRIDE(src_stride);
521
638k
            in_y++;
522
638k
        }
523
524
31.3M
        for (x = 0; x < w; x++)
525
30.2M
            dst[x] = FILTER_BILIN_CLIP2(mid1, mid2, x, dmy >> 6,
526
1.12M
                                       4 + intermediate_bits);
527
528
1.12M
        my += dy;
529
1.12M
        dst += PXSTRIDE(dst_stride);
530
1.12M
    } while (--h);
531
79.8k
}
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
38.1k
{
538
38.1k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
539
38.1k
    src_stride = PXSTRIDE(src_stride);
540
541
38.1k
    if (mx) {
542
20.5k
        if (my) {
543
13.2k
            int16_t mid[128 * 129], *mid_ptr = mid;
544
13.2k
            int tmp_h = h + 1;
545
546
206k
            do {
547
4.16M
                for (int x = 0; x < w; x++)
548
3.95M
                    mid_ptr[x] = FILTER_BILIN_RND(src, x, mx, 1,
549
206k
                                                  4 - intermediate_bits);
550
551
206k
                mid_ptr += 128;
552
206k
                src += src_stride;
553
206k
            } while (--tmp_h);
554
555
13.2k
            mid_ptr = mid;
556
195k
            do {
557
4.05M
                for (int x = 0; x < w; x++)
558
3.86M
                    tmp[x] = FILTER_BILIN_RND(mid_ptr, x, my, 128, 4) -
559
3.86M
                             PREP_BIAS;
560
561
195k
                mid_ptr += 128;
562
195k
                tmp += w;
563
195k
            } while (--h);
564
13.2k
        } else {
565
123k
            do {
566
2.67M
                for (int x = 0; x < w; x++)
567
2.55M
                    tmp[x] = FILTER_BILIN_RND(src, x, mx, 1,
568
2.55M
                                              4 - intermediate_bits) -
569
2.55M
                             PREP_BIAS;
570
571
123k
                tmp += w;
572
123k
                src += src_stride;
573
123k
            } while (--h);
574
7.27k
        }
575
20.5k
    } else if (my) {
576
110k
        do {
577
2.31M
            for (int x = 0; x < w; x++)
578
2.20M
                tmp[x] = FILTER_BILIN_RND(src, x, my, src_stride,
579
2.20M
                                          4 - intermediate_bits) - PREP_BIAS;
580
581
110k
            tmp += w;
582
110k
            src += src_stride;
583
110k
        } while (--h);
584
6.40k
    } else
585
11.2k
        prep_c(tmp, src, src_stride, w, h HIGHBD_TAIL_SUFFIX);
586
38.1k
}
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.0k
{
593
15.0k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
594
15.0k
    int16_t mid[128 * 2];
595
15.0k
    int in_y = -2;
596
597
297k
    do {
598
297k
        int x;
599
297k
        int y = my >> 10;
600
297k
        int16_t *mid1 = &mid[(y & 1) * 128];
601
297k
        int16_t *mid2 = &mid[((y + 1) & 1) * 128];
602
297k
        int dmy = my & 0x3ff;
603
604
461k
        while (in_y < y) {
605
163k
            int imx = mx, ioff = 0;
606
163k
            int16_t *mid_ptr = &mid[(in_y & 1) * 128];
607
608
5.38M
            for (x = 0; x < w; x++) {
609
5.22M
                mid_ptr[x] = FILTER_BILIN_RND(src, ioff, imx >> 6, 1,
610
5.22M
                                              4 - intermediate_bits);
611
5.22M
                imx += dx;
612
5.22M
                ioff += imx >> 10;
613
5.22M
                imx &= 0x3ff;
614
5.22M
            }
615
616
163k
            src += PXSTRIDE(src_stride);
617
163k
            in_y++;
618
163k
        }
619
620
8.86M
        for (x = 0; x < w; x++)
621
8.57M
            tmp[x] = FILTER_BILIN_RND2(mid1, mid2, x, dmy >> 6, 4) - PREP_BIAS;
622
623
297k
        my += dy;
624
297k
        tmp += w;
625
297k
    } while (--h);
626
15.0k
}
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
232k
{
632
232k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
633
232k
    const int sh = intermediate_bits + 1;
634
232k
    const int rnd = (1 << intermediate_bits) + PREP_BIAS * 2;
635
4.87M
    do {
636
137M
        for (int x = 0; x < w; x++)
637
132M
            dst[x] = iclip_pixel((tmp1[x] + tmp2[x] + rnd) >> sh);
638
639
4.87M
        tmp1 += w;
640
4.87M
        tmp2 += w;
641
4.87M
        dst += PXSTRIDE(dst_stride);
642
4.87M
    } while (--h);
643
232k
}
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
29.8k
{
649
29.8k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
650
29.8k
    const int sh = intermediate_bits + 4;
651
29.8k
    const int rnd = (8 << intermediate_bits) + PREP_BIAS * 16;
652
435k
    do {
653
11.9M
        for (int x = 0; x < w; x++)
654
11.5M
            dst[x] = iclip_pixel((tmp1[x] * weight +
655
11.5M
                                  tmp2[x] * (16 - weight) + rnd) >> sh);
656
657
435k
        tmp1 += w;
658
435k
        tmp2 += w;
659
435k
        dst += PXSTRIDE(dst_stride);
660
435k
    } while (--h);
661
29.8k
}
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
34.5k
{
667
34.5k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
668
34.5k
    const int sh = intermediate_bits + 6;
669
34.5k
    const int rnd = (32 << intermediate_bits) + PREP_BIAS * 64;
670
683k
    do {
671
19.5M
        for (int x = 0; x < w; x++)
672
18.9M
            dst[x] = iclip_pixel((tmp1[x] * mask[x] +
673
18.9M
                                  tmp2[x] * (64 - mask[x]) + rnd) >> sh);
674
675
683k
        tmp1 += w;
676
683k
        tmp2 += w;
677
683k
        mask += w;
678
683k
        dst += PXSTRIDE(dst_stride);
679
683k
    } while (--h);
680
34.5k
}
681
682
53.9M
#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
77.4k
{
686
860k
    do {
687
13.1M
        for (int x = 0; x < w; x++) {
688
12.3M
            dst[x] = blend_px(dst[x], tmp[x], mask[x]);
689
12.3M
        }
690
860k
        dst += PXSTRIDE(dst_stride);
691
860k
        tmp += w;
692
860k
        mask += w;
693
860k
    } while (--h);
694
77.4k
}
695
696
static void blend_v_c(pixel *dst, const ptrdiff_t dst_stride, const pixel *tmp,
697
                      const int w, int h)
698
257k
{
699
257k
    const uint8_t *const mask = &dav1d_obmc_masks[w];
700
3.45M
    do {
701
25.1M
        for (int x = 0; x < (w * 3) >> 2; x++) {
702
21.6M
            dst[x] = blend_px(dst[x], tmp[x], mask[x]);
703
21.6M
        }
704
3.45M
        dst += PXSTRIDE(dst_stride);
705
3.45M
        tmp += w;
706
3.45M
    } while (--h);
707
257k
}
708
709
static void blend_h_c(pixel *dst, const ptrdiff_t dst_stride, const pixel *tmp,
710
                      const int w, int h)
711
260k
{
712
260k
    const uint8_t *mask = &dav1d_obmc_masks[h];
713
260k
    h = (h * 3) >> 2;
714
1.46M
    do {
715
1.46M
        const int m = *mask++;
716
21.5M
        for (int x = 0; x < w; x++) {
717
20.0M
            dst[x] = blend_px(dst[x], tmp[x], m);
718
20.0M
        }
719
1.46M
        dst += PXSTRIDE(dst_stride);
720
1.46M
        tmp += w;
721
1.46M
    } while (--h);
722
260k
}
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.4k
{
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.4k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
732
12.4k
    const int bitdepth = bitdepth_from_max(bitdepth_max);
733
12.4k
    const int sh = intermediate_bits + 6;
734
12.4k
    const int rnd = (32 << intermediate_bits) + PREP_BIAS * 64;
735
12.4k
    const int mask_sh = bitdepth + intermediate_bits - 4;
736
12.4k
    const int mask_rnd = 1 << (mask_sh - 5);
737
472k
    do {
738
14.2M
        for (int x = 0; x < w; x++) {
739
13.8M
            const int tmpdiff = tmp1[x] - tmp2[x];
740
13.8M
            const int m = imin(38 + ((abs(tmpdiff) + mask_rnd) >> mask_sh), 64);
741
13.8M
            dst[x] = iclip_pixel((tmpdiff * m + tmp2[x] * 64 + rnd) >> sh);
742
743
13.8M
            if (ss_hor) {
744
5.35M
                x++;
745
746
5.35M
                const int tmpdiff = tmp1[x] - tmp2[x];
747
5.35M
                const int n = imin(38 + ((abs(tmpdiff) + mask_rnd) >> mask_sh), 64);
748
5.35M
                dst[x] = iclip_pixel((tmpdiff * n + tmp2[x] * 64 + rnd) >> sh);
749
750
5.35M
                if (h & ss_ver) {
751
2.30M
                    mask[x >> 1] = (m + n + mask[x >> 1] + 2 - sign) >> 2;
752
3.05M
                } else if (ss_ver) {
753
2.30M
                    mask[x >> 1] = m + n;
754
2.30M
                } else {
755
749k
                    mask[x >> 1] = (m + n + 1 - sign) >> 1;
756
749k
                }
757
8.45M
            } else {
758
8.45M
                mask[x] = m;
759
8.45M
            }
760
13.8M
        }
761
762
472k
        tmp1 += w;
763
472k
        tmp2 += w;
764
472k
        dst += PXSTRIDE(dst_stride);
765
472k
        if (!ss_ver || (h & 1)) mask += w >> ss_hor;
766
472k
    } while (--h);
767
12.4k
}
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.4k
                             const int sign HIGHBD_DECL_SUFFIX) \
774
12.4k
{ \
775
12.4k
    w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver \
776
12.4k
             HIGHBD_TAIL_SUFFIX); \
777
12.4k
}
mc_tmpl.c:w_mask_444_c
Line
Count
Source
773
4.80k
                             const int sign HIGHBD_DECL_SUFFIX) \
774
4.80k
{ \
775
4.80k
    w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver \
776
4.80k
             HIGHBD_TAIL_SUFFIX); \
777
4.80k
}
mc_tmpl.c:w_mask_422_c
Line
Count
Source
773
1.32k
                             const int sign HIGHBD_DECL_SUFFIX) \
774
1.32k
{ \
775
1.32k
    w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver \
776
1.32k
             HIGHBD_TAIL_SUFFIX); \
777
1.32k
}
mc_tmpl.c:w_mask_420_c
Line
Count
Source
773
6.28k
                             const int sign HIGHBD_DECL_SUFFIX) \
774
6.28k
{ \
775
6.28k
    w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver \
776
6.28k
             HIGHBD_TAIL_SUFFIX); \
777
6.28k
}
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
112M
    ((F[0] * src[x - 3 * stride] + \
787
112M
      F[1] * src[x - 2 * stride] + \
788
112M
      F[2] * src[x - 1 * stride] + \
789
112M
      F[3] * src[x + 0 * stride] + \
790
112M
      F[4] * src[x + 1 * stride] + \
791
112M
      F[5] * src[x + 2 * stride] + \
792
112M
      F[6] * src[x + 3 * stride] + \
793
112M
      F[7] * src[x + 4 * stride] + \
794
112M
      ((1 << (sh)) >> 1)) >> (sh))
795
796
#define FILTER_WARP_CLIP(src, x, F, stride, sh) \
797
24.6M
    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
526k
{
804
526k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
805
526k
    int16_t mid[15 * 8], *mid_ptr = mid;
806
807
526k
    src -= 3 * PXSTRIDE(src_stride);
808
8.04M
    for (int y = 0; y < 15; y++, mx += abcd[1]) {
809
65.3M
        for (int x = 0, tmx = mx; x < 8; x++, tmx += abcd[0]) {
810
57.8M
            const int8_t *const filter =
811
57.8M
                dav1d_mc_warp_filter[64 + ((tmx + 512) >> 10)];
812
813
57.8M
            mid_ptr[x] = FILTER_WARP_RND(src, x, filter, 1,
814
57.8M
                                         7 - intermediate_bits);
815
57.8M
        }
816
7.52M
        src += PXSTRIDE(src_stride);
817
7.52M
        mid_ptr += 8;
818
7.52M
    }
819
820
526k
    mid_ptr = &mid[3 * 8];
821
3.67M
    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.6M
            const int8_t *const filter =
824
24.6M
                dav1d_mc_warp_filter[64 + ((tmy + 512) >> 10)];
825
826
24.6M
            dst[x] = FILTER_WARP_CLIP(mid_ptr, x, filter, 8,
827
24.6M
                                      7 + intermediate_bits);
828
24.6M
        }
829
3.15M
        mid_ptr += 8;
830
3.15M
        dst += PXSTRIDE(dst_stride);
831
3.15M
    }
832
526k
}
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
165k
{
839
165k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
840
165k
    int16_t mid[15 * 8], *mid_ptr = mid;
841
842
165k
    src -= 3 * PXSTRIDE(src_stride);
843
2.64M
    for (int y = 0; y < 15; y++, mx += abcd[1]) {
844
22.3M
        for (int x = 0, tmx = mx; x < 8; x++, tmx += abcd[0]) {
845
19.8M
            const int8_t *const filter =
846
19.8M
                dav1d_mc_warp_filter[64 + ((tmx + 512) >> 10)];
847
848
19.8M
            mid_ptr[x] = FILTER_WARP_RND(src, x, filter, 1,
849
19.8M
                                         7 - intermediate_bits);
850
19.8M
        }
851
2.48M
        src += PXSTRIDE(src_stride);
852
2.48M
        mid_ptr += 8;
853
2.48M
    }
854
855
165k
    mid_ptr = &mid[3 * 8];
856
1.49M
    for (int y = 0; y < 8; y++, my += abcd[3]) {
857
11.9M
        for (int x = 0, tmy = my; x < 8; x++, tmy += abcd[2]) {
858
10.5M
            const int8_t *const filter =
859
10.5M
                dav1d_mc_warp_filter[64 + ((tmy + 512) >> 10)];
860
861
10.5M
            tmp[x] = FILTER_WARP_RND(mid_ptr, x, filter, 8, 7) - PREP_BIAS;
862
10.5M
        }
863
1.32M
        mid_ptr += 8;
864
1.32M
        tmp += tmp_stride;
865
1.32M
    }
866
165k
}
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.46M
{
874
    // find offset in reference of visible block to copy
875
2.46M
    ref += iclip((int) y, 0, (int) ih - 1) * PXSTRIDE(ref_stride) +
876
2.46M
           iclip((int) x, 0, (int) iw - 1);
877
878
    // number of pixels to extend (left, right, top, bottom)
879
2.46M
    const int left_ext = iclip((int) -x, 0, (int) bw - 1);
880
2.46M
    const int right_ext = iclip((int) (x + bw - iw), 0, (int) bw - 1);
881
2.46M
    assert(left_ext + right_ext < bw);
882
2.46M
    const int top_ext = iclip((int) -y, 0, (int) bh - 1);
883
2.46M
    const int bottom_ext = iclip((int) (y + bh - ih), 0, (int) bh - 1);
884
2.46M
    assert(top_ext + bottom_ext < bh);
885
886
    // copy visible portion first
887
2.46M
    pixel *blk = dst + top_ext * PXSTRIDE(dst_stride);
888
2.46M
    const int center_w = (int) (bw - left_ext - right_ext);
889
2.46M
    const int center_h = (int) (bh - top_ext - bottom_ext);
890
33.5M
    for (int y = 0; y < center_h; y++) {
891
31.1M
        pixel_copy(blk + left_ext, ref, center_w);
892
        // extend left edge for this line
893
31.1M
        if (left_ext)
894
7.58M
            pixel_set(blk, blk[left_ext], left_ext);
895
        // extend right edge for this line
896
31.1M
        if (right_ext)
897
23.1M
            pixel_set(blk + left_ext + center_w, blk[left_ext + center_w - 1],
898
23.1M
                      right_ext);
899
31.1M
        ref += PXSTRIDE(ref_stride);
900
31.1M
        blk += PXSTRIDE(dst_stride);
901
31.1M
    }
902
903
    // copy top
904
2.46M
    blk = dst + top_ext * PXSTRIDE(dst_stride);
905
5.88M
    for (int y = 0; y < top_ext; y++) {
906
3.41M
        pixel_copy(dst, blk, bw);
907
3.41M
        dst += PXSTRIDE(dst_stride);
908
3.41M
    }
909
910
    // copy bottom
911
2.46M
    dst += center_h * PXSTRIDE(dst_stride);
912
10.6M
    for (int y = 0; y < bottom_ext; y++) {
913
8.14M
        pixel_copy(dst, &dst[-PXSTRIDE(dst_stride)], bw);
914
8.14M
        dst += PXSTRIDE(dst_stride);
915
8.14M
    }
916
2.46M
}
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
236k
{
923
7.60M
    do {
924
7.60M
        int mx = mx0, src_x = -1;
925
673M
        for (int x = 0; x < dst_w; x++) {
926
665M
            const int8_t *const F = dav1d_resize_filter[mx >> 8];
927
665M
            dst[x] = iclip_pixel((-(F[0] * src[iclip(src_x - 3, 0, src_w - 1)] +
928
665M
                                    F[1] * src[iclip(src_x - 2, 0, src_w - 1)] +
929
665M
                                    F[2] * src[iclip(src_x - 1, 0, src_w - 1)] +
930
665M
                                    F[3] * src[iclip(src_x + 0, 0, src_w - 1)] +
931
665M
                                    F[4] * src[iclip(src_x + 1, 0, src_w - 1)] +
932
665M
                                    F[5] * src[iclip(src_x + 2, 0, src_w - 1)] +
933
665M
                                    F[6] * src[iclip(src_x + 3, 0, src_w - 1)] +
934
665M
                                    F[7] * src[iclip(src_x + 4, 0, src_w - 1)]) +
935
665M
                                  64) >> 7);
936
665M
            mx += dx;
937
665M
            src_x += mx >> 14;
938
665M
            mx &= 0x3fff;
939
665M
        }
940
941
7.60M
        dst += PXSTRIDE(dst_stride);
942
7.60M
        src += PXSTRIDE(src_stride);
943
7.60M
    } while (--h);
944
236k
}
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
74.6k
COLD void bitfn(dav1d_mc_dsp_init)(Dav1dMCDSPContext *const c) {
961
746k
#define init_mc_fns(type, name) do { \
962
746k
    c->mc        [type] = put_##name##_c; \
963
746k
    c->mc_scaled [type] = put_##name##_scaled_c; \
964
746k
    c->mct       [type] = prep_##name##_c; \
965
746k
    c->mct_scaled[type] = prep_##name##_scaled_c; \
966
746k
} while (0)
967
968
74.6k
    init_mc_fns(FILTER_2D_8TAP_REGULAR,        8tap_regular);
969
74.6k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SMOOTH, 8tap_regular_smooth);
970
74.6k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SHARP,  8tap_regular_sharp);
971
74.6k
    init_mc_fns(FILTER_2D_8TAP_SHARP_REGULAR,  8tap_sharp_regular);
972
74.6k
    init_mc_fns(FILTER_2D_8TAP_SHARP_SMOOTH,   8tap_sharp_smooth);
973
74.6k
    init_mc_fns(FILTER_2D_8TAP_SHARP,          8tap_sharp);
974
74.6k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_REGULAR, 8tap_smooth_regular);
975
74.6k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH,         8tap_smooth);
976
74.6k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_SHARP,   8tap_smooth_sharp);
977
74.6k
    init_mc_fns(FILTER_2D_BILINEAR,            bilin);
978
979
74.6k
    c->avg      = avg_c;
980
74.6k
    c->w_avg    = w_avg_c;
981
74.6k
    c->mask     = mask_c;
982
74.6k
    c->blend    = blend_c;
983
74.6k
    c->blend_v  = blend_v_c;
984
74.6k
    c->blend_h  = blend_h_c;
985
74.6k
    c->w_mask[0] = w_mask_444_c;
986
74.6k
    c->w_mask[1] = w_mask_422_c;
987
74.6k
    c->w_mask[2] = w_mask_420_c;
988
74.6k
    c->warp8x8  = warp_affine_8x8_c;
989
74.6k
    c->warp8x8t = warp_affine_8x8t_c;
990
74.6k
    c->emu_edge = emu_edge_c;
991
74.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
74.6k
}
dav1d_mc_dsp_init_8bpc
Line
Count
Source
960
34.0k
COLD void bitfn(dav1d_mc_dsp_init)(Dav1dMCDSPContext *const c) {
961
34.0k
#define init_mc_fns(type, name) do { \
962
34.0k
    c->mc        [type] = put_##name##_c; \
963
34.0k
    c->mc_scaled [type] = put_##name##_scaled_c; \
964
34.0k
    c->mct       [type] = prep_##name##_c; \
965
34.0k
    c->mct_scaled[type] = prep_##name##_scaled_c; \
966
34.0k
} while (0)
967
968
34.0k
    init_mc_fns(FILTER_2D_8TAP_REGULAR,        8tap_regular);
969
34.0k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SMOOTH, 8tap_regular_smooth);
970
34.0k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SHARP,  8tap_regular_sharp);
971
34.0k
    init_mc_fns(FILTER_2D_8TAP_SHARP_REGULAR,  8tap_sharp_regular);
972
34.0k
    init_mc_fns(FILTER_2D_8TAP_SHARP_SMOOTH,   8tap_sharp_smooth);
973
34.0k
    init_mc_fns(FILTER_2D_8TAP_SHARP,          8tap_sharp);
974
34.0k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_REGULAR, 8tap_smooth_regular);
975
34.0k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH,         8tap_smooth);
976
34.0k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_SHARP,   8tap_smooth_sharp);
977
34.0k
    init_mc_fns(FILTER_2D_BILINEAR,            bilin);
978
979
34.0k
    c->avg      = avg_c;
980
34.0k
    c->w_avg    = w_avg_c;
981
34.0k
    c->mask     = mask_c;
982
34.0k
    c->blend    = blend_c;
983
34.0k
    c->blend_v  = blend_v_c;
984
34.0k
    c->blend_h  = blend_h_c;
985
34.0k
    c->w_mask[0] = w_mask_444_c;
986
34.0k
    c->w_mask[1] = w_mask_422_c;
987
34.0k
    c->w_mask[2] = w_mask_420_c;
988
34.0k
    c->warp8x8  = warp_affine_8x8_c;
989
34.0k
    c->warp8x8t = warp_affine_8x8t_c;
990
34.0k
    c->emu_edge = emu_edge_c;
991
34.0k
    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
34.0k
}
dav1d_mc_dsp_init_16bpc
Line
Count
Source
960
40.5k
COLD void bitfn(dav1d_mc_dsp_init)(Dav1dMCDSPContext *const c) {
961
40.5k
#define init_mc_fns(type, name) do { \
962
40.5k
    c->mc        [type] = put_##name##_c; \
963
40.5k
    c->mc_scaled [type] = put_##name##_scaled_c; \
964
40.5k
    c->mct       [type] = prep_##name##_c; \
965
40.5k
    c->mct_scaled[type] = prep_##name##_scaled_c; \
966
40.5k
} while (0)
967
968
40.5k
    init_mc_fns(FILTER_2D_8TAP_REGULAR,        8tap_regular);
969
40.5k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SMOOTH, 8tap_regular_smooth);
970
40.5k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SHARP,  8tap_regular_sharp);
971
40.5k
    init_mc_fns(FILTER_2D_8TAP_SHARP_REGULAR,  8tap_sharp_regular);
972
40.5k
    init_mc_fns(FILTER_2D_8TAP_SHARP_SMOOTH,   8tap_sharp_smooth);
973
40.5k
    init_mc_fns(FILTER_2D_8TAP_SHARP,          8tap_sharp);
974
40.5k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_REGULAR, 8tap_smooth_regular);
975
40.5k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH,         8tap_smooth);
976
40.5k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_SHARP,   8tap_smooth_sharp);
977
40.5k
    init_mc_fns(FILTER_2D_BILINEAR,            bilin);
978
979
40.5k
    c->avg      = avg_c;
980
40.5k
    c->w_avg    = w_avg_c;
981
40.5k
    c->mask     = mask_c;
982
40.5k
    c->blend    = blend_c;
983
40.5k
    c->blend_v  = blend_v_c;
984
40.5k
    c->blend_h  = blend_h_c;
985
40.5k
    c->w_mask[0] = w_mask_444_c;
986
40.5k
    c->w_mask[1] = w_mask_422_c;
987
40.5k
    c->w_mask[2] = w_mask_420_c;
988
40.5k
    c->warp8x8  = warp_affine_8x8_c;
989
40.5k
    c->warp8x8t = warp_affine_8x8t_c;
990
40.5k
    c->emu_edge = emu_edge_c;
991
40.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
40.5k
}