Coverage Report

Created: 2026-06-15 06:25

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
1.52M
#define get_intermediate_bits(bitdepth_max) 4
41
// Output in interval [-5132, 9212], fits in int16_t as is
42
145M
#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
473k
{
55
8.25M
    do {
56
8.25M
        pixel_copy(dst, src, w);
57
58
8.25M
        dst += dst_stride;
59
8.25M
        src += src_stride;
60
8.25M
    } while (--h);
61
473k
}
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
56.8k
{
67
56.8k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
68
1.72M
    do {
69
69.9M
        for (int x = 0; x < w; x++)
70
68.1M
            tmp[x] = (src[x] << intermediate_bits) - PREP_BIAS;
71
72
1.72M
        tmp += w;
73
1.72M
        src += src_stride;
74
1.72M
    } while (--h);
75
56.8k
}
76
77
#define FILTER_8TAP(src, x, F, stride) \
78
203M
    (F[0] * src[x + -3 * stride] + \
79
203M
     F[1] * src[x + -2 * stride] + \
80
203M
     F[2] * src[x + -1 * stride] + \
81
203M
     F[3] * src[x + +0 * stride] + \
82
203M
     F[4] * src[x + +1 * stride] + \
83
203M
     F[5] * src[x + +2 * stride] + \
84
203M
     F[6] * src[x + +3 * stride] + \
85
203M
     F[7] * src[x + +4 * stride])
86
87
#define FILTER_8TAP2(src, x, F) \
88
136M
    (F[0] * src[0][x] + \
89
136M
     F[1] * src[1][x] + \
90
136M
     F[2] * src[2][x] + \
91
136M
     F[3] * src[3][x] + \
92
136M
     F[4] * src[4][x] + \
93
136M
     F[5] * src[5][x] + \
94
136M
     F[6] * src[6][x] + \
95
136M
     F[7] * src[7][x])
96
97
#define DAV1D_FILTER_8TAP_RND(src, x, F, stride, sh) \
98
182M
    ((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.1M
    ((FILTER_8TAP(src, x, F, stride) + (rnd)) >> (sh))
102
103
#define DAV1D_FILTER_8TAP_RND3(src, x, F, sh) \
104
136M
    ((FILTER_8TAP2(src, x, F) + ((1 << (sh)) >> 1)) >> (sh))
105
106
#define DAV1D_FILTER_8TAP_CLIP(src, x, F, stride, sh) \
107
38.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.1M
    iclip_pixel(DAV1D_FILTER_8TAP_RND2(src, x, F, stride, rnd, sh))
111
112
#define DAV1D_FILTER_8TAP_CLIP3(src, x, F, sh) \
113
100M
    iclip_pixel(DAV1D_FILTER_8TAP_RND3(src, x, F, sh))
114
115
#define GET_H_FILTER(mx) \
116
89.4M
    const int8_t *const fh = !(mx) ? NULL : w > 4 ? \
117
80.7M
        dav1d_mc_subpel_filters[filter_type & 3][(mx) - 1] : \
118
80.7M
        dav1d_mc_subpel_filters[3 + (filter_type & 1)][(mx) - 1]
119
120
#define GET_V_FILTER(my) \
121
4.42M
    const int8_t *const fv = !(my) ? NULL : h > 4 ? \
122
3.58M
        dav1d_mc_subpel_filters[filter_type >> 2][(my) - 1] : \
123
3.58M
        dav1d_mc_subpel_filters[3 + ((filter_type >> 2) & 1)][(my) - 1]
124
125
#define GET_FILTERS() \
126
449k
    GET_H_FILTER(mx); \
127
449k
    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
365k
{
135
365k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
136
365k
    const int intermediate_rnd = 32 + ((1 << (6 - intermediate_bits)) >> 1);
137
138
365k
    GET_FILTERS();
139
365k
    dst_stride = PXSTRIDE(dst_stride);
140
365k
    src_stride = PXSTRIDE(src_stride);
141
142
365k
    if (fh) {
143
124k
        if (fv) {
144
66.0k
            int tmp_h = h + 7;
145
66.0k
            int16_t mid[128 * 135], *mid_ptr = mid;
146
147
66.0k
            src -= src_stride * 3;
148
1.33M
            do {
149
36.3M
                for (int x = 0; x < w; x++)
150
35.0M
                    mid_ptr[x] = DAV1D_FILTER_8TAP_RND(src, x, fh, 1,
151
1.33M
                                                       6 - intermediate_bits);
152
153
1.33M
                mid_ptr += 128;
154
1.33M
                src += src_stride;
155
1.33M
            } while (--tmp_h);
156
157
66.0k
            mid_ptr = mid + 128 * 3;
158
899k
            do {
159
28.4M
                for (int x = 0; x < w; x++)
160
27.5M
                    dst[x] = DAV1D_FILTER_8TAP_CLIP(mid_ptr, x, fv, 128,
161
899k
                                                    6 + intermediate_bits);
162
163
899k
                mid_ptr += 128;
164
899k
                dst += dst_stride;
165
899k
            } while (--h);
166
66.0k
        } else {
167
725k
            do {
168
21.8M
                for (int x = 0; x < w; x++) {
169
21.1M
                    dst[x] = DAV1D_FILTER_8TAP_CLIP2(src, x, fh, 1,
170
21.1M
                                                     intermediate_rnd, 6);
171
21.1M
                }
172
173
725k
                dst += dst_stride;
174
725k
                src += src_stride;
175
725k
            } while (--h);
176
58.3k
        }
177
240k
    } else if (fv) {
178
401k
        do {
179
10.9M
            for (int x = 0; x < w; x++)
180
10.5M
                dst[x] = DAV1D_FILTER_8TAP_CLIP(src, x, fv, src_stride, 6);
181
182
401k
            dst += dst_stride;
183
401k
            src += src_stride;
184
401k
        } while (--h);
185
34.5k
    } else
186
206k
        put_c(dst, dst_stride, src, src_stride, w, h);
187
365k
}
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
142k
{
196
142k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
197
142k
    const int intermediate_rnd = (1 << intermediate_bits) >> 1;
198
142k
    int16_t mid[128 * 8];
199
142k
    int16_t *mid_ptrs[8];
200
142k
    int in_y = -8;
201
142k
    src_stride = PXSTRIDE(src_stride);
202
203
1.27M
    for (int i = 0; i < 8; i++)
204
1.13M
        mid_ptrs[i] = &mid[128 * i];
205
206
142k
    src -= src_stride * 3;
207
208
2.91M
    for (int y = 0; y < h; y++) {
209
2.77M
        int x;
210
2.77M
        int src_y = my >> 10;
211
2.77M
        GET_V_FILTER((my & 0x3ff) >> 6);
212
213
4.93M
        while (in_y < src_y) {
214
2.16M
            int imx = mx, ioff = 0;
215
2.16M
            int16_t *mid_ptr = mid_ptrs[0];
216
217
17.2M
            for (int i = 0; i < 7; i++)
218
15.1M
                mid_ptrs[i] = mid_ptrs[i + 1];
219
2.16M
            mid_ptrs[7] = mid_ptr;
220
221
68.2M
            for (x = 0; x < w; x++) {
222
66.0M
                GET_H_FILTER(imx >> 6);
223
66.0M
                mid_ptr[x] = fh ? DAV1D_FILTER_8TAP_RND(src, ioff, fh, 1,
224
66.0M
                                                        6 - intermediate_bits) :
225
66.0M
                                  src[ioff] << intermediate_bits;
226
66.0M
                imx += dx;
227
66.0M
                ioff += imx >> 10;
228
66.0M
                imx &= 0x3ff;
229
66.0M
            }
230
231
2.16M
            src += src_stride;
232
2.16M
            in_y++;
233
2.16M
        }
234
235
115M
        for (x = 0; x < w; x++)
236
113M
            dst[x] = fv ? DAV1D_FILTER_8TAP_CLIP3(mid_ptrs, x, fv,
237
113M
                                                  6 + intermediate_bits) :
238
113M
                          iclip_pixel((mid_ptrs[3][x] + intermediate_rnd) >>
239
12.7M
                                              intermediate_bits);
240
241
2.77M
        my += dy;
242
2.77M
        dst += PXSTRIDE(dst_stride);
243
2.77M
    }
244
142k
}
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
84.4k
{
251
84.4k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
252
84.4k
    GET_FILTERS();
253
84.4k
    src_stride = PXSTRIDE(src_stride);
254
255
84.4k
    if (fh) {
256
26.3k
        if (fv) {
257
16.0k
            int tmp_h = h + 7;
258
16.0k
            int16_t mid[128 * 135], *mid_ptr = mid;
259
260
16.0k
            src -= src_stride * 3;
261
372k
            do {
262
8.76M
                for (int x = 0; x < w; x++)
263
8.39M
                    mid_ptr[x] = DAV1D_FILTER_8TAP_RND(src, x, fh, 1,
264
372k
                                                       6 - intermediate_bits);
265
266
372k
                mid_ptr += 128;
267
372k
                src += src_stride;
268
372k
            } while (--tmp_h);
269
270
16.0k
            mid_ptr = mid + 128 * 3;
271
260k
            do {
272
7.16M
                for (int x = 0; x < w; x++) {
273
6.90M
                    int t = DAV1D_FILTER_8TAP_RND(mid_ptr, x, fv, 128, 6) -
274
6.90M
                                  PREP_BIAS;
275
6.90M
                    assert(t >= INT16_MIN && t <= INT16_MAX);
276
6.90M
                    tmp[x] = t;
277
6.90M
                }
278
279
260k
                mid_ptr += 128;
280
260k
                tmp += w;
281
260k
            } while (--h);
282
16.0k
        } else {
283
227k
            do {
284
8.14M
                for (int x = 0; x < w; x++)
285
7.92M
                    tmp[x] = DAV1D_FILTER_8TAP_RND(src, x, fh, 1,
286
7.92M
                                                   6 - intermediate_bits) -
287
7.92M
                             PREP_BIAS;
288
289
227k
                tmp += w;
290
227k
                src += src_stride;
291
227k
            } while (--h);
292
10.3k
        }
293
58.0k
    } else if (fv) {
294
182k
        do {
295
5.63M
            for (int x = 0; x < w; x++)
296
5.45M
                tmp[x] = DAV1D_FILTER_8TAP_RND(src, x, fv, src_stride,
297
5.45M
                                               6 - intermediate_bits) -
298
5.45M
                         PREP_BIAS;
299
300
182k
            tmp += w;
301
182k
            src += src_stride;
302
182k
        } while (--h);
303
9.36k
    } else
304
48.6k
        prep_c(tmp, src, src_stride, w, h HIGHBD_TAIL_SUFFIX);
305
84.4k
}
306
307
static NOINLINE void
308
prep_8tap_scaled_c(int16_t *tmp, const pixel *src, ptrdiff_t src_stride,
309
                   const int w, int h, const int mx, int my,
310
                   const int dx, const int dy, const int filter_type
311
                   HIGHBD_DECL_SUFFIX)
312
46.4k
{
313
46.4k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
314
46.4k
    int16_t mid[128 * 8];
315
46.4k
    int16_t *mid_ptrs[8];
316
46.4k
    int in_y = -8;
317
46.4k
    src_stride = PXSTRIDE(src_stride);
318
319
418k
    for (int i = 0; i < 8; i++)
320
371k
        mid_ptrs[i] = &mid[128 * i];
321
322
46.4k
    src -= src_stride * 3;
323
324
1.24M
    for (int y = 0; y < h; y++) {
325
1.19M
        int x;
326
1.19M
        int src_y = my >> 10;
327
1.19M
        GET_V_FILTER((my & 0x3ff) >> 6);
328
329
2.01M
        while (in_y < src_y) {
330
816k
            int imx = mx, ioff = 0;
331
816k
            int16_t *mid_ptr = mid_ptrs[0];
332
333
6.53M
            for (int i = 0; i < 7; i++)
334
5.71M
                mid_ptrs[i] = mid_ptrs[i + 1];
335
816k
            mid_ptrs[7] = mid_ptr;
336
337
23.7M
            for (x = 0; x < w; x++) {
338
22.9M
                GET_H_FILTER(imx >> 6);
339
22.9M
                mid_ptr[x] = fh ? DAV1D_FILTER_8TAP_RND(src, ioff, fh, 1,
340
22.9M
                                                        6 - intermediate_bits) :
341
22.9M
                                  src[ioff] << intermediate_bits;
342
22.9M
                imx += dx;
343
22.9M
                ioff += imx >> 10;
344
22.9M
                imx &= 0x3ff;
345
22.9M
            }
346
347
816k
            src += src_stride;
348
816k
            in_y++;
349
816k
        }
350
351
42.7M
        for (x = 0; x < w; x++)
352
41.5M
            tmp[x] = (fv ? DAV1D_FILTER_8TAP_RND3(mid_ptrs, x, fv, 6)
353
41.5M
                         : mid_ptrs[3][x]) - PREP_BIAS;
354
355
1.19M
        my += dy;
356
1.19M
        tmp += w;
357
1.19M
    }
358
46.4k
}
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
365k
                                HIGHBD_DECL_SUFFIX) \
368
365k
{ \
369
365k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
365k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
365k
} \
mc_tmpl.c:put_8tap_regular_c
Line
Count
Source
367
280k
                                HIGHBD_DECL_SUFFIX) \
368
280k
{ \
369
280k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
280k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
280k
} \
mc_tmpl.c:put_8tap_regular_smooth_c
Line
Count
Source
367
9.51k
                                HIGHBD_DECL_SUFFIX) \
368
9.51k
{ \
369
9.51k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
9.51k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
9.51k
} \
mc_tmpl.c:put_8tap_regular_sharp_c
Line
Count
Source
367
1.61k
                                HIGHBD_DECL_SUFFIX) \
368
1.61k
{ \
369
1.61k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
1.61k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
1.61k
} \
mc_tmpl.c:put_8tap_sharp_regular_c
Line
Count
Source
367
1.16k
                                HIGHBD_DECL_SUFFIX) \
368
1.16k
{ \
369
1.16k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
1.16k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
1.16k
} \
mc_tmpl.c:put_8tap_sharp_smooth_c
Line
Count
Source
367
862
                                HIGHBD_DECL_SUFFIX) \
368
862
{ \
369
862
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
862
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
862
} \
mc_tmpl.c:put_8tap_sharp_c
Line
Count
Source
367
16.9k
                                HIGHBD_DECL_SUFFIX) \
368
16.9k
{ \
369
16.9k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
16.9k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
16.9k
} \
mc_tmpl.c:put_8tap_smooth_regular_c
Line
Count
Source
367
6.39k
                                HIGHBD_DECL_SUFFIX) \
368
6.39k
{ \
369
6.39k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
6.39k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
6.39k
} \
mc_tmpl.c:put_8tap_smooth_c
Line
Count
Source
367
47.7k
                                HIGHBD_DECL_SUFFIX) \
368
47.7k
{ \
369
47.7k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
47.7k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
47.7k
} \
mc_tmpl.c:put_8tap_smooth_sharp_c
Line
Count
Source
367
1.01k
                                HIGHBD_DECL_SUFFIX) \
368
1.01k
{ \
369
1.01k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
1.01k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
1.01k
} \
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
142k
                                       HIGHBD_DECL_SUFFIX) \
380
142k
{ \
381
142k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
142k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
142k
} \
mc_tmpl.c:put_8tap_regular_scaled_c
Line
Count
Source
379
82.1k
                                       HIGHBD_DECL_SUFFIX) \
380
82.1k
{ \
381
82.1k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
82.1k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
82.1k
} \
mc_tmpl.c:put_8tap_regular_smooth_scaled_c
Line
Count
Source
379
3.13k
                                       HIGHBD_DECL_SUFFIX) \
380
3.13k
{ \
381
3.13k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
3.13k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
3.13k
} \
mc_tmpl.c:put_8tap_regular_sharp_scaled_c
Line
Count
Source
379
928
                                       HIGHBD_DECL_SUFFIX) \
380
928
{ \
381
928
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
928
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
928
} \
mc_tmpl.c:put_8tap_sharp_regular_scaled_c
Line
Count
Source
379
1.12k
                                       HIGHBD_DECL_SUFFIX) \
380
1.12k
{ \
381
1.12k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
1.12k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
1.12k
} \
mc_tmpl.c:put_8tap_sharp_smooth_scaled_c
Line
Count
Source
379
748
                                       HIGHBD_DECL_SUFFIX) \
380
748
{ \
381
748
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
748
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
748
} \
mc_tmpl.c:put_8tap_sharp_scaled_c
Line
Count
Source
379
16.6k
                                       HIGHBD_DECL_SUFFIX) \
380
16.6k
{ \
381
16.6k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
16.6k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
16.6k
} \
mc_tmpl.c:put_8tap_smooth_regular_scaled_c
Line
Count
Source
379
3.67k
                                       HIGHBD_DECL_SUFFIX) \
380
3.67k
{ \
381
3.67k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
3.67k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
3.67k
} \
mc_tmpl.c:put_8tap_smooth_scaled_c
Line
Count
Source
379
32.9k
                                       HIGHBD_DECL_SUFFIX) \
380
32.9k
{ \
381
32.9k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
32.9k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
32.9k
} \
mc_tmpl.c:put_8tap_smooth_sharp_scaled_c
Line
Count
Source
379
764
                                       HIGHBD_DECL_SUFFIX) \
380
764
{ \
381
764
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
764
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
764
} \
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
84.4k
                                 HIGHBD_DECL_SUFFIX) \
390
84.4k
{ \
391
84.4k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
84.4k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
84.4k
} \
mc_tmpl.c:prep_8tap_regular_c
Line
Count
Source
389
40.8k
                                 HIGHBD_DECL_SUFFIX) \
390
40.8k
{ \
391
40.8k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
40.8k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
40.8k
} \
mc_tmpl.c:prep_8tap_regular_smooth_c
Line
Count
Source
389
1.14k
                                 HIGHBD_DECL_SUFFIX) \
390
1.14k
{ \
391
1.14k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
1.14k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
1.14k
} \
mc_tmpl.c:prep_8tap_regular_sharp_c
Line
Count
Source
389
2.14k
                                 HIGHBD_DECL_SUFFIX) \
390
2.14k
{ \
391
2.14k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
2.14k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
2.14k
} \
mc_tmpl.c:prep_8tap_sharp_regular_c
Line
Count
Source
389
3.18k
                                 HIGHBD_DECL_SUFFIX) \
390
3.18k
{ \
391
3.18k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
3.18k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
3.18k
} \
mc_tmpl.c:prep_8tap_sharp_smooth_c
Line
Count
Source
389
1.76k
                                 HIGHBD_DECL_SUFFIX) \
390
1.76k
{ \
391
1.76k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
1.76k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
1.76k
} \
mc_tmpl.c:prep_8tap_sharp_c
Line
Count
Source
389
8.73k
                                 HIGHBD_DECL_SUFFIX) \
390
8.73k
{ \
391
8.73k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
8.73k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
8.73k
} \
mc_tmpl.c:prep_8tap_smooth_regular_c
Line
Count
Source
389
1.98k
                                 HIGHBD_DECL_SUFFIX) \
390
1.98k
{ \
391
1.98k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
1.98k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
1.98k
} \
mc_tmpl.c:prep_8tap_smooth_c
Line
Count
Source
389
23.2k
                                 HIGHBD_DECL_SUFFIX) \
390
23.2k
{ \
391
23.2k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
23.2k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
23.2k
} \
mc_tmpl.c:prep_8tap_smooth_sharp_c
Line
Count
Source
389
1.38k
                                 HIGHBD_DECL_SUFFIX) \
390
1.38k
{ \
391
1.38k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
1.38k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
1.38k
} \
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
46.4k
                                        HIGHBD_DECL_SUFFIX) \
401
46.4k
{ \
402
46.4k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
46.4k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
46.4k
}
mc_tmpl.c:prep_8tap_regular_scaled_c
Line
Count
Source
400
19.9k
                                        HIGHBD_DECL_SUFFIX) \
401
19.9k
{ \
402
19.9k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
19.9k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
19.9k
}
mc_tmpl.c:prep_8tap_regular_smooth_scaled_c
Line
Count
Source
400
892
                                        HIGHBD_DECL_SUFFIX) \
401
892
{ \
402
892
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
892
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
892
}
mc_tmpl.c:prep_8tap_regular_sharp_scaled_c
Line
Count
Source
400
3.47k
                                        HIGHBD_DECL_SUFFIX) \
401
3.47k
{ \
402
3.47k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
3.47k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
3.47k
}
mc_tmpl.c:prep_8tap_sharp_regular_scaled_c
Line
Count
Source
400
2.50k
                                        HIGHBD_DECL_SUFFIX) \
401
2.50k
{ \
402
2.50k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
2.50k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
2.50k
}
mc_tmpl.c:prep_8tap_sharp_smooth_scaled_c
Line
Count
Source
400
1.32k
                                        HIGHBD_DECL_SUFFIX) \
401
1.32k
{ \
402
1.32k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
1.32k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
1.32k
}
mc_tmpl.c:prep_8tap_sharp_scaled_c
Line
Count
Source
400
4.16k
                                        HIGHBD_DECL_SUFFIX) \
401
4.16k
{ \
402
4.16k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
4.16k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
4.16k
}
mc_tmpl.c:prep_8tap_smooth_regular_scaled_c
Line
Count
Source
400
1.45k
                                        HIGHBD_DECL_SUFFIX) \
401
1.45k
{ \
402
1.45k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
1.45k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
1.45k
}
mc_tmpl.c:prep_8tap_smooth_scaled_c
Line
Count
Source
400
11.7k
                                        HIGHBD_DECL_SUFFIX) \
401
11.7k
{ \
402
11.7k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
11.7k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
11.7k
}
mc_tmpl.c:prep_8tap_smooth_sharp_scaled_c
Line
Count
Source
400
1.03k
                                        HIGHBD_DECL_SUFFIX) \
401
1.03k
{ \
402
1.03k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
1.03k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
1.03k
}
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
49.1M
    (16 * src[x] + ((mxy) * (src[x + stride] - src[x])))
418
419
#define FILTER_BILIN_RND(src, x, mxy, stride, sh) \
420
49.1M
    ((FILTER_BILIN(src, x, mxy, stride) + ((1 << (sh)) >> 1)) >> (sh))
421
422
#define FILTER_BILIN_CLIP(src, x, mxy, stride, sh) \
423
5.84M
    iclip_pixel(FILTER_BILIN_RND(src, x, mxy, stride, sh))
424
425
#define FILTER_BILIN2(src1, src2, x, mxy) \
426
24.8M
    (16 * src1[x] + ((mxy) * (src2[x] - src1[x])))
427
428
#define FILTER_BILIN_RND2(src1, src2, x, mxy, sh) \
429
24.8M
    ((FILTER_BILIN2(src1, src2, x, mxy) + ((1 << (sh)) >> 1)) >> (sh))
430
431
#define FILTER_BILIN_CLIP2(src1, src2, x, mxy, sh) \
432
21.3M
    iclip_pixel(FILTER_BILIN_RND2(src1, src2, x, mxy, sh))
433
434
static void put_bilin_c(pixel *dst, ptrdiff_t dst_stride,
435
                        const pixel *src, ptrdiff_t src_stride,
436
                        const int w, int h, const int mx, const int my
437
                        HIGHBD_DECL_SUFFIX)
438
331k
{
439
331k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
440
331k
    const int intermediate_rnd = (1 << intermediate_bits) >> 1;
441
331k
    dst_stride = PXSTRIDE(dst_stride);
442
331k
    src_stride = PXSTRIDE(src_stride);
443
444
331k
    if (mx) {
445
44.6k
        if (my) {
446
22.9k
            int16_t mid[128 * 129], *mid_ptr = mid;
447
22.9k
            int tmp_h = h + 1;
448
449
204k
            do {
450
3.15M
                for (int x = 0; x < w; x++)
451
2.95M
                    mid_ptr[x] = FILTER_BILIN_RND(src, x, mx, 1,
452
204k
                                                  4 - intermediate_bits);
453
454
204k
                mid_ptr += 128;
455
204k
                src += src_stride;
456
204k
            } while (--tmp_h);
457
458
22.9k
            mid_ptr = mid;
459
181k
            do {
460
2.94M
                for (int x = 0; x < w; x++)
461
2.76M
                    dst[x] = FILTER_BILIN_CLIP(mid_ptr, x, my, 128,
462
181k
                                               4 + intermediate_bits);
463
464
181k
                mid_ptr += 128;
465
181k
                dst += dst_stride;
466
181k
            } while (--h);
467
22.9k
        } else {
468
288k
            do {
469
10.1M
                for (int x = 0; x < w; x++) {
470
9.84M
                    const int px = FILTER_BILIN_RND(src, x, mx, 1,
471
9.84M
                                                    4 - intermediate_bits);
472
9.84M
                    dst[x] = iclip_pixel((px + intermediate_rnd) >> intermediate_bits);
473
9.84M
                }
474
475
288k
                dst += dst_stride;
476
288k
                src += src_stride;
477
288k
            } while (--h);
478
21.6k
        }
479
286k
    } else if (my) {
480
167k
        do {
481
3.24M
            for (int x = 0; x < w; x++)
482
3.08M
                dst[x] = FILTER_BILIN_CLIP(src, x, my, src_stride, 4);
483
484
167k
            dst += dst_stride;
485
167k
            src += src_stride;
486
167k
        } while (--h);
487
19.7k
    } else
488
266k
        put_c(dst, dst_stride, src, src_stride, w, h);
489
331k
}
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
66.0k
{
497
66.0k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
498
66.0k
    int16_t mid[128 * 2];
499
66.0k
    int in_y = -2;
500
501
877k
    do {
502
877k
        int x;
503
877k
        int y = my >> 10;
504
877k
        int16_t *mid1 = &mid[(y & 1) * 128];
505
877k
        int16_t *mid2 = &mid[((y + 1) & 1) * 128];
506
877k
        int dmy = my & 0x3ff;
507
508
1.57M
        while (in_y < y) {
509
698k
            int imx = mx, ioff = 0;
510
698k
            int16_t *mid_ptr = &mid[(in_y & 1) * 128];
511
512
17.1M
            for (x = 0; x < w; x++) {
513
16.4M
                mid_ptr[x] = FILTER_BILIN_RND(src, ioff, imx >> 6, 1,
514
16.4M
                                              4 - intermediate_bits);
515
16.4M
                imx += dx;
516
16.4M
                ioff += imx >> 10;
517
16.4M
                imx &= 0x3ff;
518
16.4M
            }
519
520
698k
            src += PXSTRIDE(src_stride);
521
698k
            in_y++;
522
698k
        }
523
524
22.1M
        for (x = 0; x < w; x++)
525
21.3M
            dst[x] = FILTER_BILIN_CLIP2(mid1, mid2, x, dmy >> 6,
526
877k
                                       4 + intermediate_bits);
527
528
877k
        my += dy;
529
877k
        dst += PXSTRIDE(dst_stride);
530
877k
    } while (--h);
531
66.0k
}
532
533
static void prep_bilin_c(int16_t *tmp,
534
                         const pixel *src, ptrdiff_t src_stride,
535
                         const int w, int h, const int mx, const int my
536
                         HIGHBD_DECL_SUFFIX)
537
25.9k
{
538
25.9k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
539
25.9k
    src_stride = PXSTRIDE(src_stride);
540
541
25.9k
    if (mx) {
542
13.8k
        if (my) {
543
9.57k
            int16_t mid[128 * 129], *mid_ptr = mid;
544
9.57k
            int tmp_h = h + 1;
545
546
133k
            do {
547
3.71M
                for (int x = 0; x < w; x++)
548
3.57M
                    mid_ptr[x] = FILTER_BILIN_RND(src, x, mx, 1,
549
133k
                                                  4 - intermediate_bits);
550
551
133k
                mid_ptr += 128;
552
133k
                src += src_stride;
553
133k
            } while (--tmp_h);
554
555
9.57k
            mid_ptr = mid;
556
124k
            do {
557
3.56M
                for (int x = 0; x < w; x++)
558
3.44M
                    tmp[x] = FILTER_BILIN_RND(mid_ptr, x, my, 128, 4) -
559
3.44M
                             PREP_BIAS;
560
561
124k
                mid_ptr += 128;
562
124k
                tmp += w;
563
124k
            } while (--h);
564
9.57k
        } else {
565
78.0k
            do {
566
2.79M
                for (int x = 0; x < w; x++)
567
2.72M
                    tmp[x] = FILTER_BILIN_RND(src, x, mx, 1,
568
2.72M
                                              4 - intermediate_bits) -
569
2.72M
                             PREP_BIAS;
570
571
78.0k
                tmp += w;
572
78.0k
                src += src_stride;
573
78.0k
            } while (--h);
574
4.30k
        }
575
13.8k
    } else if (my) {
576
63.5k
        do {
577
2.17M
            for (int x = 0; x < w; x++)
578
2.10M
                tmp[x] = FILTER_BILIN_RND(src, x, my, src_stride,
579
2.10M
                                          4 - intermediate_bits) - PREP_BIAS;
580
581
63.5k
            tmp += w;
582
63.5k
            src += src_stride;
583
63.5k
        } while (--h);
584
3.96k
    } else
585
8.14k
        prep_c(tmp, src, src_stride, w, h HIGHBD_TAIL_SUFFIX);
586
25.9k
}
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
5.92k
{
593
5.92k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
594
5.92k
    int16_t mid[128 * 2];
595
5.92k
    int in_y = -2;
596
597
111k
    do {
598
111k
        int x;
599
111k
        int y = my >> 10;
600
111k
        int16_t *mid1 = &mid[(y & 1) * 128];
601
111k
        int16_t *mid2 = &mid[((y + 1) & 1) * 128];
602
111k
        int dmy = my & 0x3ff;
603
604
172k
        while (in_y < y) {
605
60.9k
            int imx = mx, ioff = 0;
606
60.9k
            int16_t *mid_ptr = &mid[(in_y & 1) * 128];
607
608
2.24M
            for (x = 0; x < w; x++) {
609
2.17M
                mid_ptr[x] = FILTER_BILIN_RND(src, ioff, imx >> 6, 1,
610
2.17M
                                              4 - intermediate_bits);
611
2.17M
                imx += dx;
612
2.17M
                ioff += imx >> 10;
613
2.17M
                imx &= 0x3ff;
614
2.17M
            }
615
616
60.9k
            src += PXSTRIDE(src_stride);
617
60.9k
            in_y++;
618
60.9k
        }
619
620
3.68M
        for (x = 0; x < w; x++)
621
3.57M
            tmp[x] = FILTER_BILIN_RND2(mid1, mid2, x, dmy >> 6, 4) - PREP_BIAS;
622
623
111k
        my += dy;
624
111k
        tmp += w;
625
111k
    } while (--h);
626
5.92k
}
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
61.4k
{
632
61.4k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
633
61.4k
    const int sh = intermediate_bits + 1;
634
61.4k
    const int rnd = (1 << intermediate_bits) + PREP_BIAS * 2;
635
1.30M
    do {
636
44.8M
        for (int x = 0; x < w; x++)
637
43.5M
            dst[x] = iclip_pixel((tmp1[x] + tmp2[x] + rnd) >> sh);
638
639
1.30M
        tmp1 += w;
640
1.30M
        tmp2 += w;
641
1.30M
        dst += PXSTRIDE(dst_stride);
642
1.30M
    } while (--h);
643
61.4k
}
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
8.44k
{
649
8.44k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
650
8.44k
    const int sh = intermediate_bits + 4;
651
8.44k
    const int rnd = (8 << intermediate_bits) + PREP_BIAS * 16;
652
240k
    do {
653
9.98M
        for (int x = 0; x < w; x++)
654
9.74M
            dst[x] = iclip_pixel((tmp1[x] * weight +
655
9.74M
                                  tmp2[x] * (16 - weight) + rnd) >> sh);
656
657
240k
        tmp1 += w;
658
240k
        tmp2 += w;
659
240k
        dst += PXSTRIDE(dst_stride);
660
240k
    } while (--h);
661
8.44k
}
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
11.2k
{
667
11.2k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
668
11.2k
    const int sh = intermediate_bits + 6;
669
11.2k
    const int rnd = (32 << intermediate_bits) + PREP_BIAS * 64;
670
266k
    do {
671
8.63M
        for (int x = 0; x < w; x++)
672
8.37M
            dst[x] = iclip_pixel((tmp1[x] * mask[x] +
673
8.37M
                                  tmp2[x] * (64 - mask[x]) + rnd) >> sh);
674
675
266k
        tmp1 += w;
676
266k
        tmp2 += w;
677
266k
        mask += w;
678
266k
        dst += PXSTRIDE(dst_stride);
679
266k
    } while (--h);
680
11.2k
}
681
682
12.2M
#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
14.2k
{
686
156k
    do {
687
2.00M
        for (int x = 0; x < w; x++) {
688
1.84M
            dst[x] = blend_px(dst[x], tmp[x], mask[x]);
689
1.84M
        }
690
156k
        dst += PXSTRIDE(dst_stride);
691
156k
        tmp += w;
692
156k
        mask += w;
693
156k
    } while (--h);
694
14.2k
}
695
696
static void blend_v_c(pixel *dst, const ptrdiff_t dst_stride, const pixel *tmp,
697
                      const int w, int h)
698
65.3k
{
699
65.3k
    const uint8_t *const mask = &dav1d_obmc_masks[w];
700
879k
    do {
701
6.94M
        for (int x = 0; x < (w * 3) >> 2; x++) {
702
6.06M
            dst[x] = blend_px(dst[x], tmp[x], mask[x]);
703
6.06M
        }
704
879k
        dst += PXSTRIDE(dst_stride);
705
879k
        tmp += w;
706
879k
    } while (--h);
707
65.3k
}
708
709
static void blend_h_c(pixel *dst, const ptrdiff_t dst_stride, const pixel *tmp,
710
                      const int w, int h)
711
62.1k
{
712
62.1k
    const uint8_t *mask = &dav1d_obmc_masks[h];
713
62.1k
    h = (h * 3) >> 2;
714
297k
    do {
715
297k
        const int m = *mask++;
716
4.68M
        for (int x = 0; x < w; x++) {
717
4.38M
            dst[x] = blend_px(dst[x], tmp[x], m);
718
4.38M
        }
719
297k
        dst += PXSTRIDE(dst_stride);
720
297k
        tmp += w;
721
297k
    } while (--h);
722
62.1k
}
723
724
static void w_mask_c(pixel *dst, const ptrdiff_t dst_stride,
725
                     const int16_t *tmp1, const int16_t *tmp2, const int w, int h,
726
                     uint8_t *mask, const int sign,
727
                     const int ss_hor, const int ss_ver HIGHBD_DECL_SUFFIX)
728
4.84k
{
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
4.84k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
732
4.84k
    const int bitdepth = bitdepth_from_max(bitdepth_max);
733
4.84k
    const int sh = intermediate_bits + 6;
734
4.84k
    const int rnd = (32 << intermediate_bits) + PREP_BIAS * 64;
735
4.84k
    const int mask_sh = bitdepth + intermediate_bits - 4;
736
4.84k
    const int mask_rnd = 1 << (mask_sh - 5);
737
238k
    do {
738
8.40M
        for (int x = 0; x < w; x++) {
739
8.16M
            const int tmpdiff = tmp1[x] - tmp2[x];
740
8.16M
            const int m = imin(38 + ((abs(tmpdiff) + mask_rnd) >> mask_sh), 64);
741
8.16M
            dst[x] = iclip_pixel((tmpdiff * m + tmp2[x] * 64 + rnd) >> sh);
742
743
8.16M
            if (ss_hor) {
744
2.67M
                x++;
745
746
2.67M
                const int tmpdiff = tmp1[x] - tmp2[x];
747
2.67M
                const int n = imin(38 + ((abs(tmpdiff) + mask_rnd) >> mask_sh), 64);
748
2.67M
                dst[x] = iclip_pixel((tmpdiff * n + tmp2[x] * 64 + rnd) >> sh);
749
750
2.67M
                if (h & ss_ver) {
751
1.33M
                    mask[x >> 1] = (m + n + mask[x >> 1] + 2 - sign) >> 2;
752
1.34M
                } else if (ss_ver) {
753
1.33M
                    mask[x >> 1] = m + n;
754
1.33M
                } else {
755
9.75k
                    mask[x >> 1] = (m + n + 1 - sign) >> 1;
756
9.75k
                }
757
5.48M
            } else {
758
5.48M
                mask[x] = m;
759
5.48M
            }
760
8.16M
        }
761
762
238k
        tmp1 += w;
763
238k
        tmp2 += w;
764
238k
        dst += PXSTRIDE(dst_stride);
765
238k
        if (!ss_ver || (h & 1)) mask += w >> ss_hor;
766
238k
    } while (--h);
767
4.84k
}
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
4.84k
                             const int sign HIGHBD_DECL_SUFFIX) \
774
4.84k
{ \
775
4.84k
    w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver \
776
4.84k
             HIGHBD_TAIL_SUFFIX); \
777
4.84k
}
mc_tmpl.c:w_mask_444_c
Line
Count
Source
773
2.74k
                             const int sign HIGHBD_DECL_SUFFIX) \
774
2.74k
{ \
775
2.74k
    w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver \
776
2.74k
             HIGHBD_TAIL_SUFFIX); \
777
2.74k
}
mc_tmpl.c:w_mask_422_c
Line
Count
Source
773
210
                             const int sign HIGHBD_DECL_SUFFIX) \
774
210
{ \
775
210
    w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver \
776
210
             HIGHBD_TAIL_SUFFIX); \
777
210
}
mc_tmpl.c:w_mask_420_c
Line
Count
Source
773
1.88k
                             const int sign HIGHBD_DECL_SUFFIX) \
774
1.88k
{ \
775
1.88k
    w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver \
776
1.88k
             HIGHBD_TAIL_SUFFIX); \
777
1.88k
}
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
55.9M
    ((F[0] * src[x - 3 * stride] + \
787
55.9M
      F[1] * src[x - 2 * stride] + \
788
55.9M
      F[2] * src[x - 1 * stride] + \
789
55.9M
      F[3] * src[x + 0 * stride] + \
790
55.9M
      F[4] * src[x + 1 * stride] + \
791
55.9M
      F[5] * src[x + 2 * stride] + \
792
55.9M
      F[6] * src[x + 3 * stride] + \
793
55.9M
      F[7] * src[x + 4 * stride] + \
794
55.9M
      ((1 << (sh)) >> 1)) >> (sh))
795
796
#define FILTER_WARP_CLIP(src, x, F, stride, sh) \
797
16.1M
    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
257k
{
804
257k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
805
257k
    int16_t mid[15 * 8], *mid_ptr = mid;
806
807
257k
    src -= 3 * PXSTRIDE(src_stride);
808
4.08M
    for (int y = 0; y < 15; y++, mx += abcd[1]) {
809
34.0M
        for (int x = 0, tmx = mx; x < 8; x++, tmx += abcd[0]) {
810
30.2M
            const int8_t *const filter =
811
30.2M
                dav1d_mc_warp_filter[64 + ((tmx + 512) >> 10)];
812
813
30.2M
            mid_ptr[x] = FILTER_WARP_RND(src, x, filter, 1,
814
30.2M
                                         7 - intermediate_bits);
815
30.2M
        }
816
3.83M
        src += PXSTRIDE(src_stride);
817
3.83M
        mid_ptr += 8;
818
3.83M
    }
819
820
257k
    mid_ptr = &mid[3 * 8];
821
2.30M
    for (int y = 0; y < 8; y++, my += abcd[3]) {
822
18.1M
        for (int x = 0, tmy = my; x < 8; x++, tmy += abcd[2]) {
823
16.1M
            const int8_t *const filter =
824
16.1M
                dav1d_mc_warp_filter[64 + ((tmy + 512) >> 10)];
825
826
16.1M
            dst[x] = FILTER_WARP_CLIP(mid_ptr, x, filter, 8,
827
16.1M
                                      7 + intermediate_bits);
828
16.1M
        }
829
2.04M
        mid_ptr += 8;
830
2.04M
        dst += PXSTRIDE(dst_stride);
831
2.04M
    }
832
257k
}
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
52.5k
{
839
52.5k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
840
52.5k
    int16_t mid[15 * 8], *mid_ptr = mid;
841
842
52.5k
    src -= 3 * PXSTRIDE(src_stride);
843
840k
    for (int y = 0; y < 15; y++, mx += abcd[1]) {
844
7.09M
        for (int x = 0, tmx = mx; x < 8; x++, tmx += abcd[0]) {
845
6.30M
            const int8_t *const filter =
846
6.30M
                dav1d_mc_warp_filter[64 + ((tmx + 512) >> 10)];
847
848
6.30M
            mid_ptr[x] = FILTER_WARP_RND(src, x, filter, 1,
849
6.30M
                                         7 - intermediate_bits);
850
6.30M
        }
851
788k
        src += PXSTRIDE(src_stride);
852
788k
        mid_ptr += 8;
853
788k
    }
854
855
52.5k
    mid_ptr = &mid[3 * 8];
856
472k
    for (int y = 0; y < 8; y++, my += abcd[3]) {
857
3.78M
        for (int x = 0, tmy = my; x < 8; x++, tmy += abcd[2]) {
858
3.36M
            const int8_t *const filter =
859
3.36M
                dav1d_mc_warp_filter[64 + ((tmy + 512) >> 10)];
860
861
3.36M
            tmp[x] = FILTER_WARP_RND(mid_ptr, x, filter, 8, 7) - PREP_BIAS;
862
3.36M
        }
863
420k
        mid_ptr += 8;
864
420k
        tmp += tmp_stride;
865
420k
    }
866
52.5k
}
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
826k
{
874
    // find offset in reference of visible block to copy
875
826k
    ref += iclip((int) y, 0, (int) ih - 1) * PXSTRIDE(ref_stride) +
876
826k
           iclip((int) x, 0, (int) iw - 1);
877
878
    // number of pixels to extend (left, right, top, bottom)
879
826k
    const int left_ext = iclip((int) -x, 0, (int) bw - 1);
880
826k
    const int right_ext = iclip((int) (x + bw - iw), 0, (int) bw - 1);
881
826k
    assert(left_ext + right_ext < bw);
882
826k
    const int top_ext = iclip((int) -y, 0, (int) bh - 1);
883
826k
    const int bottom_ext = iclip((int) (y + bh - ih), 0, (int) bh - 1);
884
826k
    assert(top_ext + bottom_ext < bh);
885
886
    // copy visible portion first
887
826k
    pixel *blk = dst + top_ext * PXSTRIDE(dst_stride);
888
826k
    const int center_w = (int) (bw - left_ext - right_ext);
889
826k
    const int center_h = (int) (bh - top_ext - bottom_ext);
890
10.7M
    for (int y = 0; y < center_h; y++) {
891
9.92M
        pixel_copy(blk + left_ext, ref, center_w);
892
        // extend left edge for this line
893
9.92M
        if (left_ext)
894
2.35M
            pixel_set(blk, blk[left_ext], left_ext);
895
        // extend right edge for this line
896
9.92M
        if (right_ext)
897
6.97M
            pixel_set(blk + left_ext + center_w, blk[left_ext + center_w - 1],
898
6.97M
                      right_ext);
899
9.92M
        ref += PXSTRIDE(ref_stride);
900
9.92M
        blk += PXSTRIDE(dst_stride);
901
9.92M
    }
902
903
    // copy top
904
826k
    blk = dst + top_ext * PXSTRIDE(dst_stride);
905
1.85M
    for (int y = 0; y < top_ext; y++) {
906
1.03M
        pixel_copy(dst, blk, bw);
907
1.03M
        dst += PXSTRIDE(dst_stride);
908
1.03M
    }
909
910
    // copy bottom
911
826k
    dst += center_h * PXSTRIDE(dst_stride);
912
5.99M
    for (int y = 0; y < bottom_ext; y++) {
913
5.16M
        pixel_copy(dst, &dst[-PXSTRIDE(dst_stride)], bw);
914
5.16M
        dst += PXSTRIDE(dst_stride);
915
5.16M
    }
916
826k
}
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
159k
{
923
6.29M
    do {
924
6.29M
        int mx = mx0, src_x = -1;
925
814M
        for (int x = 0; x < dst_w; x++) {
926
808M
            const int8_t *const F = dav1d_resize_filter[mx >> 8];
927
808M
            dst[x] = iclip_pixel((-(F[0] * src[iclip(src_x - 3, 0, src_w - 1)] +
928
808M
                                    F[1] * src[iclip(src_x - 2, 0, src_w - 1)] +
929
808M
                                    F[2] * src[iclip(src_x - 1, 0, src_w - 1)] +
930
808M
                                    F[3] * src[iclip(src_x + 0, 0, src_w - 1)] +
931
808M
                                    F[4] * src[iclip(src_x + 1, 0, src_w - 1)] +
932
808M
                                    F[5] * src[iclip(src_x + 2, 0, src_w - 1)] +
933
808M
                                    F[6] * src[iclip(src_x + 3, 0, src_w - 1)] +
934
808M
                                    F[7] * src[iclip(src_x + 4, 0, src_w - 1)]) +
935
808M
                                  64) >> 7);
936
808M
            mx += dx;
937
808M
            src_x += mx >> 14;
938
808M
            mx &= 0x3fff;
939
808M
        }
940
941
6.29M
        dst += PXSTRIDE(dst_stride);
942
6.29M
        src += PXSTRIDE(src_stride);
943
6.29M
    } while (--h);
944
159k
}
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
68.8k
COLD void bitfn(dav1d_mc_dsp_init)(Dav1dMCDSPContext *const c) {
961
688k
#define init_mc_fns(type, name) do { \
962
688k
    c->mc        [type] = put_##name##_c; \
963
688k
    c->mc_scaled [type] = put_##name##_scaled_c; \
964
688k
    c->mct       [type] = prep_##name##_c; \
965
688k
    c->mct_scaled[type] = prep_##name##_scaled_c; \
966
688k
} while (0)
967
968
68.8k
    init_mc_fns(FILTER_2D_8TAP_REGULAR,        8tap_regular);
969
68.8k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SMOOTH, 8tap_regular_smooth);
970
68.8k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SHARP,  8tap_regular_sharp);
971
68.8k
    init_mc_fns(FILTER_2D_8TAP_SHARP_REGULAR,  8tap_sharp_regular);
972
68.8k
    init_mc_fns(FILTER_2D_8TAP_SHARP_SMOOTH,   8tap_sharp_smooth);
973
68.8k
    init_mc_fns(FILTER_2D_8TAP_SHARP,          8tap_sharp);
974
68.8k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_REGULAR, 8tap_smooth_regular);
975
68.8k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH,         8tap_smooth);
976
68.8k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_SHARP,   8tap_smooth_sharp);
977
68.8k
    init_mc_fns(FILTER_2D_BILINEAR,            bilin);
978
979
68.8k
    c->avg      = avg_c;
980
68.8k
    c->w_avg    = w_avg_c;
981
68.8k
    c->mask     = mask_c;
982
68.8k
    c->blend    = blend_c;
983
68.8k
    c->blend_v  = blend_v_c;
984
68.8k
    c->blend_h  = blend_h_c;
985
68.8k
    c->w_mask[0] = w_mask_444_c;
986
68.8k
    c->w_mask[1] = w_mask_422_c;
987
68.8k
    c->w_mask[2] = w_mask_420_c;
988
68.8k
    c->warp8x8  = warp_affine_8x8_c;
989
68.8k
    c->warp8x8t = warp_affine_8x8t_c;
990
68.8k
    c->emu_edge = emu_edge_c;
991
68.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
68.8k
}
dav1d_mc_dsp_init_8bpc
Line
Count
Source
960
30.8k
COLD void bitfn(dav1d_mc_dsp_init)(Dav1dMCDSPContext *const c) {
961
30.8k
#define init_mc_fns(type, name) do { \
962
30.8k
    c->mc        [type] = put_##name##_c; \
963
30.8k
    c->mc_scaled [type] = put_##name##_scaled_c; \
964
30.8k
    c->mct       [type] = prep_##name##_c; \
965
30.8k
    c->mct_scaled[type] = prep_##name##_scaled_c; \
966
30.8k
} while (0)
967
968
30.8k
    init_mc_fns(FILTER_2D_8TAP_REGULAR,        8tap_regular);
969
30.8k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SMOOTH, 8tap_regular_smooth);
970
30.8k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SHARP,  8tap_regular_sharp);
971
30.8k
    init_mc_fns(FILTER_2D_8TAP_SHARP_REGULAR,  8tap_sharp_regular);
972
30.8k
    init_mc_fns(FILTER_2D_8TAP_SHARP_SMOOTH,   8tap_sharp_smooth);
973
30.8k
    init_mc_fns(FILTER_2D_8TAP_SHARP,          8tap_sharp);
974
30.8k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_REGULAR, 8tap_smooth_regular);
975
30.8k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH,         8tap_smooth);
976
30.8k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_SHARP,   8tap_smooth_sharp);
977
30.8k
    init_mc_fns(FILTER_2D_BILINEAR,            bilin);
978
979
30.8k
    c->avg      = avg_c;
980
30.8k
    c->w_avg    = w_avg_c;
981
30.8k
    c->mask     = mask_c;
982
30.8k
    c->blend    = blend_c;
983
30.8k
    c->blend_v  = blend_v_c;
984
30.8k
    c->blend_h  = blend_h_c;
985
30.8k
    c->w_mask[0] = w_mask_444_c;
986
30.8k
    c->w_mask[1] = w_mask_422_c;
987
30.8k
    c->w_mask[2] = w_mask_420_c;
988
30.8k
    c->warp8x8  = warp_affine_8x8_c;
989
30.8k
    c->warp8x8t = warp_affine_8x8t_c;
990
30.8k
    c->emu_edge = emu_edge_c;
991
30.8k
    c->resize   = resize_c;
992
993
#if HAVE_ASM
994
#if ARCH_AARCH64 || ARCH_ARM
995
    mc_dsp_init_arm(c);
996
#elif ARCH_LOONGARCH64
997
    mc_dsp_init_loongarch(c);
998
#elif ARCH_PPC64LE
999
    mc_dsp_init_ppc(c);
1000
#elif ARCH_RISCV
1001
    mc_dsp_init_riscv(c);
1002
#elif ARCH_X86
1003
    mc_dsp_init_x86(c);
1004
#endif
1005
#endif
1006
30.8k
}
dav1d_mc_dsp_init_16bpc
Line
Count
Source
960
38.0k
COLD void bitfn(dav1d_mc_dsp_init)(Dav1dMCDSPContext *const c) {
961
38.0k
#define init_mc_fns(type, name) do { \
962
38.0k
    c->mc        [type] = put_##name##_c; \
963
38.0k
    c->mc_scaled [type] = put_##name##_scaled_c; \
964
38.0k
    c->mct       [type] = prep_##name##_c; \
965
38.0k
    c->mct_scaled[type] = prep_##name##_scaled_c; \
966
38.0k
} while (0)
967
968
38.0k
    init_mc_fns(FILTER_2D_8TAP_REGULAR,        8tap_regular);
969
38.0k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SMOOTH, 8tap_regular_smooth);
970
38.0k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SHARP,  8tap_regular_sharp);
971
38.0k
    init_mc_fns(FILTER_2D_8TAP_SHARP_REGULAR,  8tap_sharp_regular);
972
38.0k
    init_mc_fns(FILTER_2D_8TAP_SHARP_SMOOTH,   8tap_sharp_smooth);
973
38.0k
    init_mc_fns(FILTER_2D_8TAP_SHARP,          8tap_sharp);
974
38.0k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_REGULAR, 8tap_smooth_regular);
975
38.0k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH,         8tap_smooth);
976
38.0k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_SHARP,   8tap_smooth_sharp);
977
38.0k
    init_mc_fns(FILTER_2D_BILINEAR,            bilin);
978
979
38.0k
    c->avg      = avg_c;
980
38.0k
    c->w_avg    = w_avg_c;
981
38.0k
    c->mask     = mask_c;
982
38.0k
    c->blend    = blend_c;
983
38.0k
    c->blend_v  = blend_v_c;
984
38.0k
    c->blend_h  = blend_h_c;
985
38.0k
    c->w_mask[0] = w_mask_444_c;
986
38.0k
    c->w_mask[1] = w_mask_422_c;
987
38.0k
    c->w_mask[2] = w_mask_420_c;
988
38.0k
    c->warp8x8  = warp_affine_8x8_c;
989
38.0k
    c->warp8x8t = warp_affine_8x8t_c;
990
38.0k
    c->emu_edge = emu_edge_c;
991
38.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
38.0k
}