Coverage Report

Created: 2026-06-10 06:56

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
294k
#define get_intermediate_bits(bitdepth_max) 4
41
// Output in interval [-5132, 9212], fits in int16_t as is
42
21.6M
#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
168k
{
55
1.97M
    do {
56
1.97M
        pixel_copy(dst, src, w);
57
58
1.97M
        dst += dst_stride;
59
1.97M
        src += src_stride;
60
1.97M
    } while (--h);
61
168k
}
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
5.32k
{
67
5.32k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
68
129k
    do {
69
5.62M
        for (int x = 0; x < w; x++)
70
5.49M
            tmp[x] = (src[x] << intermediate_bits) - PREP_BIAS;
71
72
129k
        tmp += w;
73
129k
        src += src_stride;
74
129k
    } while (--h);
75
5.32k
}
76
77
#define FILTER_8TAP(src, x, F, stride) \
78
27.5M
    (F[0] * src[x + -3 * stride] + \
79
27.5M
     F[1] * src[x + -2 * stride] + \
80
27.5M
     F[2] * src[x + -1 * stride] + \
81
27.5M
     F[3] * src[x + +0 * stride] + \
82
27.5M
     F[4] * src[x + +1 * stride] + \
83
27.5M
     F[5] * src[x + +2 * stride] + \
84
27.5M
     F[6] * src[x + +3 * stride] + \
85
27.5M
     F[7] * src[x + +4 * stride])
86
87
#define FILTER_8TAP2(src, x, F) \
88
5.87M
    (F[0] * src[0][x] + \
89
5.87M
     F[1] * src[1][x] + \
90
5.87M
     F[2] * src[2][x] + \
91
5.87M
     F[3] * src[3][x] + \
92
5.87M
     F[4] * src[4][x] + \
93
5.87M
     F[5] * src[5][x] + \
94
5.87M
     F[6] * src[6][x] + \
95
5.87M
     F[7] * src[7][x])
96
97
#define DAV1D_FILTER_8TAP_RND(src, x, F, stride, sh) \
98
26.2M
    ((FILTER_8TAP(src, x, F, stride) + ((1 << (sh)) >> 1)) >> (sh))
99
100
#define DAV1D_FILTER_8TAP_RND2(src, x, F, stride, rnd, sh) \
101
1.28M
    ((FILTER_8TAP(src, x, F, stride) + (rnd)) >> (sh))
102
103
#define DAV1D_FILTER_8TAP_RND3(src, x, F, sh) \
104
5.87M
    ((FILTER_8TAP2(src, x, F) + ((1 << (sh)) >> 1)) >> (sh))
105
106
#define DAV1D_FILTER_8TAP_CLIP(src, x, F, stride, sh) \
107
2.74M
    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
1.28M
    iclip_pixel(DAV1D_FILTER_8TAP_RND2(src, x, F, stride, rnd, sh))
111
112
#define DAV1D_FILTER_8TAP_CLIP3(src, x, F, sh) \
113
3.75M
    iclip_pixel(DAV1D_FILTER_8TAP_RND3(src, x, F, sh))
114
115
#define GET_H_FILTER(mx) \
116
11.7M
    const int8_t *const fh = !(mx) ? NULL : w > 4 ? \
117
10.9M
        dav1d_mc_subpel_filters[filter_type & 3][(mx) - 1] : \
118
10.9M
        dav1d_mc_subpel_filters[3 + (filter_type & 1)][(mx) - 1]
119
120
#define GET_V_FILTER(my) \
121
410k
    const int8_t *const fv = !(my) ? NULL : h > 4 ? \
122
190k
        dav1d_mc_subpel_filters[filter_type >> 2][(my) - 1] : \
123
190k
        dav1d_mc_subpel_filters[3 + ((filter_type >> 2) & 1)][(my) - 1]
124
125
#define GET_FILTERS() \
126
49.1k
    GET_H_FILTER(mx); \
127
49.1k
    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
40.2k
{
135
40.2k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
136
40.2k
    const int intermediate_rnd = 32 + ((1 << (6 - intermediate_bits)) >> 1);
137
138
40.2k
    GET_FILTERS();
139
40.2k
    dst_stride = PXSTRIDE(dst_stride);
140
40.2k
    src_stride = PXSTRIDE(src_stride);
141
142
40.2k
    if (fh) {
143
8.60k
        if (fv) {
144
5.34k
            int tmp_h = h + 7;
145
5.34k
            int16_t mid[128 * 135], *mid_ptr = mid;
146
147
5.34k
            src -= src_stride * 3;
148
110k
            do {
149
2.64M
                for (int x = 0; x < w; x++)
150
2.53M
                    mid_ptr[x] = DAV1D_FILTER_8TAP_RND(src, x, fh, 1,
151
110k
                                                       6 - intermediate_bits);
152
153
110k
                mid_ptr += 128;
154
110k
                src += src_stride;
155
110k
            } while (--tmp_h);
156
157
5.34k
            mid_ptr = mid + 128 * 3;
158
73.5k
            do {
159
2.13M
                for (int x = 0; x < w; x++)
160
2.06M
                    dst[x] = DAV1D_FILTER_8TAP_CLIP(mid_ptr, x, fv, 128,
161
73.5k
                                                    6 + intermediate_bits);
162
163
73.5k
                mid_ptr += 128;
164
73.5k
                dst += dst_stride;
165
73.5k
            } while (--h);
166
5.34k
        } else {
167
40.8k
            do {
168
1.32M
                for (int x = 0; x < w; x++) {
169
1.28M
                    dst[x] = DAV1D_FILTER_8TAP_CLIP2(src, x, fh, 1,
170
1.28M
                                                     intermediate_rnd, 6);
171
1.28M
                }
172
173
40.8k
                dst += dst_stride;
174
40.8k
                src += src_stride;
175
40.8k
            } while (--h);
176
3.26k
        }
177
31.6k
    } else if (fv) {
178
32.4k
        do {
179
712k
            for (int x = 0; x < w; x++)
180
680k
                dst[x] = DAV1D_FILTER_8TAP_CLIP(src, x, fv, src_stride, 6);
181
182
32.4k
            dst += dst_stride;
183
32.4k
            src += src_stride;
184
32.4k
        } while (--h);
185
2.69k
    } else
186
28.9k
        put_c(dst, dst_stride, src, src_stride, w, h);
187
40.2k
}
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
15.4k
{
196
15.4k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
197
15.4k
    const int intermediate_rnd = (1 << intermediate_bits) >> 1;
198
15.4k
    int16_t mid[128 * 8];
199
15.4k
    int16_t *mid_ptrs[8];
200
15.4k
    int in_y = -8;
201
15.4k
    src_stride = PXSTRIDE(src_stride);
202
203
138k
    for (int i = 0; i < 8; i++)
204
123k
        mid_ptrs[i] = &mid[128 * i];
205
206
15.4k
    src -= src_stride * 3;
207
208
251k
    for (int y = 0; y < h; y++) {
209
236k
        int x;
210
236k
        int src_y = my >> 10;
211
236k
        GET_V_FILTER((my & 0x3ff) >> 6);
212
213
543k
        while (in_y < src_y) {
214
307k
            int imx = mx, ioff = 0;
215
307k
            int16_t *mid_ptr = mid_ptrs[0];
216
217
2.45M
            for (int i = 0; i < 7; i++)
218
2.15M
                mid_ptrs[i] = mid_ptrs[i + 1];
219
307k
            mid_ptrs[7] = mid_ptr;
220
221
7.72M
            for (x = 0; x < w; x++) {
222
7.42M
                GET_H_FILTER(imx >> 6);
223
7.42M
                mid_ptr[x] = fh ? DAV1D_FILTER_8TAP_RND(src, ioff, fh, 1,
224
7.42M
                                                        6 - intermediate_bits) :
225
7.42M
                                  src[ioff] << intermediate_bits;
226
7.42M
                imx += dx;
227
7.42M
                ioff += imx >> 10;
228
7.42M
                imx &= 0x3ff;
229
7.42M
            }
230
231
307k
            src += src_stride;
232
307k
            in_y++;
233
307k
        }
234
235
6.62M
        for (x = 0; x < w; x++)
236
6.38M
            dst[x] = fv ? DAV1D_FILTER_8TAP_CLIP3(mid_ptrs, x, fv,
237
6.38M
                                                  6 + intermediate_bits) :
238
6.38M
                          iclip_pixel((mid_ptrs[3][x] + intermediate_rnd) >>
239
2.63M
                                              intermediate_bits);
240
241
236k
        my += dy;
242
236k
        dst += PXSTRIDE(dst_stride);
243
236k
    }
244
15.4k
}
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
8.98k
{
251
8.98k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
252
8.98k
    GET_FILTERS();
253
8.98k
    src_stride = PXSTRIDE(src_stride);
254
255
8.98k
    if (fh) {
256
4.41k
        if (fv) {
257
2.35k
            int tmp_h = h + 7;
258
2.35k
            int16_t mid[128 * 135], *mid_ptr = mid;
259
260
2.35k
            src -= src_stride * 3;
261
81.3k
            do {
262
2.97M
                for (int x = 0; x < w; x++)
263
2.89M
                    mid_ptr[x] = DAV1D_FILTER_8TAP_RND(src, x, fh, 1,
264
81.3k
                                                       6 - intermediate_bits);
265
266
81.3k
                mid_ptr += 128;
267
81.3k
                src += src_stride;
268
81.3k
            } while (--tmp_h);
269
270
2.35k
            mid_ptr = mid + 128 * 3;
271
64.9k
            do {
272
2.63M
                for (int x = 0; x < w; x++) {
273
2.56M
                    int t = DAV1D_FILTER_8TAP_RND(mid_ptr, x, fv, 128, 6) -
274
2.56M
                                  PREP_BIAS;
275
2.56M
                    assert(t >= INT16_MIN && t <= INT16_MAX);
276
2.56M
                    tmp[x] = t;
277
2.56M
                }
278
279
64.9k
                mid_ptr += 128;
280
64.9k
                tmp += w;
281
64.9k
            } while (--h);
282
2.35k
        } else {
283
65.3k
            do {
284
3.32M
                for (int x = 0; x < w; x++)
285
3.25M
                    tmp[x] = DAV1D_FILTER_8TAP_RND(src, x, fh, 1,
286
3.25M
                                                   6 - intermediate_bits) -
287
3.25M
                             PREP_BIAS;
288
289
65.3k
                tmp += w;
290
65.3k
                src += src_stride;
291
65.3k
            } while (--h);
292
2.05k
        }
293
4.56k
    } else if (fv) {
294
33.8k
        do {
295
1.28M
            for (int x = 0; x < w; x++)
296
1.24M
                tmp[x] = DAV1D_FILTER_8TAP_RND(src, x, fv, src_stride,
297
1.24M
                                               6 - intermediate_bits) -
298
1.24M
                         PREP_BIAS;
299
300
33.8k
            tmp += w;
301
33.8k
            src += src_stride;
302
33.8k
        } while (--h);
303
1.29k
    } else
304
3.27k
        prep_c(tmp, src, src_stride, w, h HIGHBD_TAIL_SUFFIX);
305
8.98k
}
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
4.77k
{
313
4.77k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
314
4.77k
    int16_t mid[128 * 8];
315
4.77k
    int16_t *mid_ptrs[8];
316
4.77k
    int in_y = -8;
317
4.77k
    src_stride = PXSTRIDE(src_stride);
318
319
43.0k
    for (int i = 0; i < 8; i++)
320
38.2k
        mid_ptrs[i] = &mid[128 * i];
321
322
4.77k
    src -= src_stride * 3;
323
324
129k
    for (int y = 0; y < h; y++) {
325
124k
        int x;
326
124k
        int src_y = my >> 10;
327
124k
        GET_V_FILTER((my & 0x3ff) >> 6);
328
329
275k
        while (in_y < src_y) {
330
150k
            int imx = mx, ioff = 0;
331
150k
            int16_t *mid_ptr = mid_ptrs[0];
332
333
1.20M
            for (int i = 0; i < 7; i++)
334
1.05M
                mid_ptrs[i] = mid_ptrs[i + 1];
335
150k
            mid_ptrs[7] = mid_ptr;
336
337
4.45M
            for (x = 0; x < w; x++) {
338
4.30M
                GET_H_FILTER(imx >> 6);
339
4.30M
                mid_ptr[x] = fh ? DAV1D_FILTER_8TAP_RND(src, ioff, fh, 1,
340
4.30M
                                                        6 - intermediate_bits) :
341
4.30M
                                  src[ioff] << intermediate_bits;
342
4.30M
                imx += dx;
343
4.30M
                ioff += imx >> 10;
344
4.30M
                imx &= 0x3ff;
345
4.30M
            }
346
347
150k
            src += src_stride;
348
150k
            in_y++;
349
150k
        }
350
351
4.19M
        for (x = 0; x < w; x++)
352
4.07M
            tmp[x] = (fv ? DAV1D_FILTER_8TAP_RND3(mid_ptrs, x, fv, 6)
353
4.07M
                         : mid_ptrs[3][x]) - PREP_BIAS;
354
355
124k
        my += dy;
356
124k
        tmp += w;
357
124k
    }
358
4.77k
}
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
40.2k
                                HIGHBD_DECL_SUFFIX) \
368
40.2k
{ \
369
40.2k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
40.2k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
40.2k
} \
mc_tmpl.c:put_8tap_regular_c
Line
Count
Source
367
23.9k
                                HIGHBD_DECL_SUFFIX) \
368
23.9k
{ \
369
23.9k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
23.9k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
23.9k
} \
mc_tmpl.c:put_8tap_regular_smooth_c
Line
Count
Source
367
586
                                HIGHBD_DECL_SUFFIX) \
368
586
{ \
369
586
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
586
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
586
} \
mc_tmpl.c:put_8tap_regular_sharp_c
Line
Count
Source
367
348
                                HIGHBD_DECL_SUFFIX) \
368
348
{ \
369
348
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
348
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
348
} \
mc_tmpl.c:put_8tap_sharp_regular_c
Line
Count
Source
367
267
                                HIGHBD_DECL_SUFFIX) \
368
267
{ \
369
267
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
267
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
267
} \
mc_tmpl.c:put_8tap_sharp_smooth_c
Line
Count
Source
367
135
                                HIGHBD_DECL_SUFFIX) \
368
135
{ \
369
135
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
135
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
135
} \
mc_tmpl.c:put_8tap_sharp_c
Line
Count
Source
367
6.90k
                                HIGHBD_DECL_SUFFIX) \
368
6.90k
{ \
369
6.90k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
6.90k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
6.90k
} \
mc_tmpl.c:put_8tap_smooth_regular_c
Line
Count
Source
367
923
                                HIGHBD_DECL_SUFFIX) \
368
923
{ \
369
923
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
923
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
923
} \
mc_tmpl.c:put_8tap_smooth_c
Line
Count
Source
367
6.80k
                                HIGHBD_DECL_SUFFIX) \
368
6.80k
{ \
369
6.80k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
6.80k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
6.80k
} \
mc_tmpl.c:put_8tap_smooth_sharp_c
Line
Count
Source
367
246
                                HIGHBD_DECL_SUFFIX) \
368
246
{ \
369
246
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
246
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
246
} \
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
15.4k
                                       HIGHBD_DECL_SUFFIX) \
380
15.4k
{ \
381
15.4k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
15.4k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
15.4k
} \
mc_tmpl.c:put_8tap_regular_scaled_c
Line
Count
Source
379
8.30k
                                       HIGHBD_DECL_SUFFIX) \
380
8.30k
{ \
381
8.30k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
8.30k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
8.30k
} \
mc_tmpl.c:put_8tap_regular_smooth_scaled_c
Line
Count
Source
379
243
                                       HIGHBD_DECL_SUFFIX) \
380
243
{ \
381
243
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
243
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
243
} \
mc_tmpl.c:put_8tap_regular_sharp_scaled_c
Line
Count
Source
379
188
                                       HIGHBD_DECL_SUFFIX) \
380
188
{ \
381
188
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
188
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
188
} \
mc_tmpl.c:put_8tap_sharp_regular_scaled_c
Line
Count
Source
379
214
                                       HIGHBD_DECL_SUFFIX) \
380
214
{ \
381
214
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
214
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
214
} \
mc_tmpl.c:put_8tap_sharp_smooth_scaled_c
Line
Count
Source
379
89
                                       HIGHBD_DECL_SUFFIX) \
380
89
{ \
381
89
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
89
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
89
} \
mc_tmpl.c:put_8tap_sharp_scaled_c
Line
Count
Source
379
1.80k
                                       HIGHBD_DECL_SUFFIX) \
380
1.80k
{ \
381
1.80k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
1.80k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
1.80k
} \
mc_tmpl.c:put_8tap_smooth_regular_scaled_c
Line
Count
Source
379
383
                                       HIGHBD_DECL_SUFFIX) \
380
383
{ \
381
383
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
383
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
383
} \
mc_tmpl.c:put_8tap_smooth_scaled_c
Line
Count
Source
379
3.75k
                                       HIGHBD_DECL_SUFFIX) \
380
3.75k
{ \
381
3.75k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
3.75k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
3.75k
} \
mc_tmpl.c:put_8tap_smooth_sharp_scaled_c
Line
Count
Source
379
445
                                       HIGHBD_DECL_SUFFIX) \
380
445
{ \
381
445
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
445
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
445
} \
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
8.98k
                                 HIGHBD_DECL_SUFFIX) \
390
8.98k
{ \
391
8.98k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
8.98k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
8.98k
} \
mc_tmpl.c:prep_8tap_regular_c
Line
Count
Source
389
2.96k
                                 HIGHBD_DECL_SUFFIX) \
390
2.96k
{ \
391
2.96k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
2.96k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
2.96k
} \
mc_tmpl.c:prep_8tap_regular_smooth_c
Line
Count
Source
389
344
                                 HIGHBD_DECL_SUFFIX) \
390
344
{ \
391
344
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
344
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
344
} \
mc_tmpl.c:prep_8tap_regular_sharp_c
Line
Count
Source
389
407
                                 HIGHBD_DECL_SUFFIX) \
390
407
{ \
391
407
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
407
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
407
} \
mc_tmpl.c:prep_8tap_sharp_regular_c
Line
Count
Source
389
691
                                 HIGHBD_DECL_SUFFIX) \
390
691
{ \
391
691
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
691
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
691
} \
mc_tmpl.c:prep_8tap_sharp_smooth_c
Line
Count
Source
389
259
                                 HIGHBD_DECL_SUFFIX) \
390
259
{ \
391
259
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
259
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
259
} \
mc_tmpl.c:prep_8tap_sharp_c
Line
Count
Source
389
2.25k
                                 HIGHBD_DECL_SUFFIX) \
390
2.25k
{ \
391
2.25k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
2.25k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
2.25k
} \
mc_tmpl.c:prep_8tap_smooth_regular_c
Line
Count
Source
389
427
                                 HIGHBD_DECL_SUFFIX) \
390
427
{ \
391
427
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
427
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
427
} \
mc_tmpl.c:prep_8tap_smooth_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
} \
mc_tmpl.c:prep_8tap_smooth_sharp_c
Line
Count
Source
389
257
                                 HIGHBD_DECL_SUFFIX) \
390
257
{ \
391
257
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
257
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
257
} \
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
4.77k
                                        HIGHBD_DECL_SUFFIX) \
401
4.77k
{ \
402
4.77k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
4.77k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
4.77k
}
mc_tmpl.c:prep_8tap_regular_scaled_c
Line
Count
Source
400
1.13k
                                        HIGHBD_DECL_SUFFIX) \
401
1.13k
{ \
402
1.13k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
1.13k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
1.13k
}
mc_tmpl.c:prep_8tap_regular_smooth_scaled_c
Line
Count
Source
400
243
                                        HIGHBD_DECL_SUFFIX) \
401
243
{ \
402
243
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
243
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
243
}
mc_tmpl.c:prep_8tap_regular_sharp_scaled_c
Line
Count
Source
400
254
                                        HIGHBD_DECL_SUFFIX) \
401
254
{ \
402
254
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
254
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
254
}
mc_tmpl.c:prep_8tap_sharp_regular_scaled_c
Line
Count
Source
400
286
                                        HIGHBD_DECL_SUFFIX) \
401
286
{ \
402
286
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
286
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
286
}
mc_tmpl.c:prep_8tap_sharp_smooth_scaled_c
Line
Count
Source
400
240
                                        HIGHBD_DECL_SUFFIX) \
401
240
{ \
402
240
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
240
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
240
}
mc_tmpl.c:prep_8tap_sharp_scaled_c
Line
Count
Source
400
925
                                        HIGHBD_DECL_SUFFIX) \
401
925
{ \
402
925
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
925
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
925
}
mc_tmpl.c:prep_8tap_smooth_regular_scaled_c
Line
Count
Source
400
273
                                        HIGHBD_DECL_SUFFIX) \
401
273
{ \
402
273
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
273
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
273
}
mc_tmpl.c:prep_8tap_smooth_scaled_c
Line
Count
Source
400
1.26k
                                        HIGHBD_DECL_SUFFIX) \
401
1.26k
{ \
402
1.26k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
1.26k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
1.26k
}
mc_tmpl.c:prep_8tap_smooth_sharp_scaled_c
Line
Count
Source
400
164
                                        HIGHBD_DECL_SUFFIX) \
401
164
{ \
402
164
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
164
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
164
}
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
18.2M
    (16 * src[x] + ((mxy) * (src[x + stride] - src[x])))
418
419
#define FILTER_BILIN_RND(src, x, mxy, stride, sh) \
420
18.2M
    ((FILTER_BILIN(src, x, mxy, stride) + ((1 << (sh)) >> 1)) >> (sh))
421
422
#define FILTER_BILIN_CLIP(src, x, mxy, stride, sh) \
423
1.02M
    iclip_pixel(FILTER_BILIN_RND(src, x, mxy, stride, sh))
424
425
#define FILTER_BILIN2(src1, src2, x, mxy) \
426
7.21M
    (16 * src1[x] + ((mxy) * (src2[x] - src1[x])))
427
428
#define FILTER_BILIN_RND2(src1, src2, x, mxy, sh) \
429
7.21M
    ((FILTER_BILIN2(src1, src2, x, mxy) + ((1 << (sh)) >> 1)) >> (sh))
430
431
#define FILTER_BILIN_CLIP2(src1, src2, x, mxy, sh) \
432
6.82M
    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
142k
{
439
142k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
440
142k
    const int intermediate_rnd = (1 << intermediate_bits) >> 1;
441
142k
    dst_stride = PXSTRIDE(dst_stride);
442
142k
    src_stride = PXSTRIDE(src_stride);
443
444
142k
    if (mx) {
445
2.08k
        if (my) {
446
1.16k
            int16_t mid[128 * 129], *mid_ptr = mid;
447
1.16k
            int tmp_h = h + 1;
448
449
19.2k
            do {
450
670k
                for (int x = 0; x < w; x++)
451
650k
                    mid_ptr[x] = FILTER_BILIN_RND(src, x, mx, 1,
452
19.2k
                                                  4 - intermediate_bits);
453
454
19.2k
                mid_ptr += 128;
455
19.2k
                src += src_stride;
456
19.2k
            } while (--tmp_h);
457
458
1.16k
            mid_ptr = mid;
459
18.0k
            do {
460
652k
                for (int x = 0; x < w; x++)
461
634k
                    dst[x] = FILTER_BILIN_CLIP(mid_ptr, x, my, 128,
462
18.0k
                                               4 + intermediate_bits);
463
464
18.0k
                mid_ptr += 128;
465
18.0k
                dst += dst_stride;
466
18.0k
            } while (--h);
467
1.16k
        } else {
468
13.7k
            do {
469
544k
                for (int x = 0; x < w; x++) {
470
530k
                    const int px = FILTER_BILIN_RND(src, x, mx, 1,
471
530k
                                                    4 - intermediate_bits);
472
530k
                    dst[x] = iclip_pixel((px + intermediate_rnd) >> intermediate_bits);
473
530k
                }
474
475
13.7k
                dst += dst_stride;
476
13.7k
                src += src_stride;
477
13.7k
            } while (--h);
478
922
        }
479
140k
    } else if (my) {
480
13.3k
        do {
481
408k
            for (int x = 0; x < w; x++)
482
395k
                dst[x] = FILTER_BILIN_CLIP(src, x, my, src_stride, 4);
483
484
13.3k
            dst += dst_stride;
485
13.3k
            src += src_stride;
486
13.3k
        } while (--h);
487
945
    } else
488
139k
        put_c(dst, dst_stride, src, src_stride, w, h);
489
142k
}
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
8.88k
{
497
8.88k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
498
8.88k
    int16_t mid[128 * 2];
499
8.88k
    int in_y = -2;
500
501
277k
    do {
502
277k
        int x;
503
277k
        int y = my >> 10;
504
277k
        int16_t *mid1 = &mid[(y & 1) * 128];
505
277k
        int16_t *mid2 = &mid[((y + 1) & 1) * 128];
506
277k
        int dmy = my & 0x3ff;
507
508
709k
        while (in_y < y) {
509
432k
            int imx = mx, ioff = 0;
510
432k
            int16_t *mid_ptr = &mid[(in_y & 1) * 128];
511
512
11.0M
            for (x = 0; x < w; x++) {
513
10.6M
                mid_ptr[x] = FILTER_BILIN_RND(src, ioff, imx >> 6, 1,
514
10.6M
                                              4 - intermediate_bits);
515
10.6M
                imx += dx;
516
10.6M
                ioff += imx >> 10;
517
10.6M
                imx &= 0x3ff;
518
10.6M
            }
519
520
432k
            src += PXSTRIDE(src_stride);
521
432k
            in_y++;
522
432k
        }
523
524
7.09M
        for (x = 0; x < w; x++)
525
6.82M
            dst[x] = FILTER_BILIN_CLIP2(mid1, mid2, x, dmy >> 6,
526
277k
                                       4 + intermediate_bits);
527
528
277k
        my += dy;
529
277k
        dst += PXSTRIDE(dst_stride);
530
277k
    } while (--h);
531
8.88k
}
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
4.96k
{
538
4.96k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
539
4.96k
    src_stride = PXSTRIDE(src_stride);
540
541
4.96k
    if (mx) {
542
2.34k
        if (my) {
543
1.13k
            int16_t mid[128 * 129], *mid_ptr = mid;
544
1.13k
            int tmp_h = h + 1;
545
546
28.7k
            do {
547
1.27M
                for (int x = 0; x < w; x++)
548
1.24M
                    mid_ptr[x] = FILTER_BILIN_RND(src, x, mx, 1,
549
28.7k
                                                  4 - intermediate_bits);
550
551
28.7k
                mid_ptr += 128;
552
28.7k
                src += src_stride;
553
28.7k
            } while (--tmp_h);
554
555
1.13k
            mid_ptr = mid;
556
27.5k
            do {
557
1.25M
                for (int x = 0; x < w; x++)
558
1.22M
                    tmp[x] = FILTER_BILIN_RND(mid_ptr, x, my, 128, 4) -
559
1.22M
                             PREP_BIAS;
560
561
27.5k
                mid_ptr += 128;
562
27.5k
                tmp += w;
563
27.5k
            } while (--h);
564
1.20k
        } else {
565
35.8k
            do {
566
1.77M
                for (int x = 0; x < w; x++)
567
1.74M
                    tmp[x] = FILTER_BILIN_RND(src, x, mx, 1,
568
1.74M
                                              4 - intermediate_bits) -
569
1.74M
                             PREP_BIAS;
570
571
35.8k
                tmp += w;
572
35.8k
                src += src_stride;
573
35.8k
            } while (--h);
574
1.20k
        }
575
2.61k
    } else if (my) {
576
16.4k
        do {
577
846k
            for (int x = 0; x < w; x++)
578
829k
                tmp[x] = FILTER_BILIN_RND(src, x, my, src_stride,
579
829k
                                          4 - intermediate_bits) - PREP_BIAS;
580
581
16.4k
            tmp += w;
582
16.4k
            src += src_stride;
583
16.4k
        } while (--h);
584
569
    } else
585
2.04k
        prep_c(tmp, src, src_stride, w, h HIGHBD_TAIL_SUFFIX);
586
4.96k
}
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
720
{
593
720
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
594
720
    int16_t mid[128 * 2];
595
720
    int in_y = -2;
596
597
12.7k
    do {
598
12.7k
        int x;
599
12.7k
        int y = my >> 10;
600
12.7k
        int16_t *mid1 = &mid[(y & 1) * 128];
601
12.7k
        int16_t *mid2 = &mid[((y + 1) & 1) * 128];
602
12.7k
        int dmy = my & 0x3ff;
603
604
23.6k
        while (in_y < y) {
605
10.9k
            int imx = mx, ioff = 0;
606
10.9k
            int16_t *mid_ptr = &mid[(in_y & 1) * 128];
607
608
375k
            for (x = 0; x < w; x++) {
609
364k
                mid_ptr[x] = FILTER_BILIN_RND(src, ioff, imx >> 6, 1,
610
364k
                                              4 - intermediate_bits);
611
364k
                imx += dx;
612
364k
                ioff += imx >> 10;
613
364k
                imx &= 0x3ff;
614
364k
            }
615
616
10.9k
            src += PXSTRIDE(src_stride);
617
10.9k
            in_y++;
618
10.9k
        }
619
620
406k
        for (x = 0; x < w; x++)
621
393k
            tmp[x] = FILTER_BILIN_RND2(mid1, mid2, x, dmy >> 6, 4) - PREP_BIAS;
622
623
12.7k
        my += dy;
624
12.7k
        tmp += w;
625
12.7k
    } while (--h);
626
720
}
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
6.73k
{
632
6.73k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
633
6.73k
    const int sh = intermediate_bits + 1;
634
6.73k
    const int rnd = (1 << intermediate_bits) + PREP_BIAS * 2;
635
179k
    do {
636
7.41M
        for (int x = 0; x < w; x++)
637
7.23M
            dst[x] = iclip_pixel((tmp1[x] + tmp2[x] + rnd) >> sh);
638
639
179k
        tmp1 += w;
640
179k
        tmp2 += w;
641
179k
        dst += PXSTRIDE(dst_stride);
642
179k
    } while (--h);
643
6.73k
}
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
980
{
649
980
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
650
980
    const int sh = intermediate_bits + 4;
651
980
    const int rnd = (8 << intermediate_bits) + PREP_BIAS * 16;
652
23.8k
    do {
653
1.02M
        for (int x = 0; x < w; x++)
654
1.00M
            dst[x] = iclip_pixel((tmp1[x] * weight +
655
1.00M
                                  tmp2[x] * (16 - weight) + rnd) >> sh);
656
657
23.8k
        tmp1 += w;
658
23.8k
        tmp2 += w;
659
23.8k
        dst += PXSTRIDE(dst_stride);
660
23.8k
    } while (--h);
661
980
}
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
1.70k
{
667
1.70k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
668
1.70k
    const int sh = intermediate_bits + 6;
669
1.70k
    const int rnd = (32 << intermediate_bits) + PREP_BIAS * 64;
670
38.3k
    do {
671
1.42M
        for (int x = 0; x < w; x++)
672
1.38M
            dst[x] = iclip_pixel((tmp1[x] * mask[x] +
673
1.38M
                                  tmp2[x] * (64 - mask[x]) + rnd) >> sh);
674
675
38.3k
        tmp1 += w;
676
38.3k
        tmp2 += w;
677
38.3k
        mask += w;
678
38.3k
        dst += PXSTRIDE(dst_stride);
679
38.3k
    } while (--h);
680
1.70k
}
681
682
2.32M
#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
2.92k
{
686
31.4k
    do {
687
451k
        for (int x = 0; x < w; x++) {
688
419k
            dst[x] = blend_px(dst[x], tmp[x], mask[x]);
689
419k
        }
690
31.4k
        dst += PXSTRIDE(dst_stride);
691
31.4k
        tmp += w;
692
31.4k
        mask += w;
693
31.4k
    } while (--h);
694
2.92k
}
695
696
static void blend_v_c(pixel *dst, const ptrdiff_t dst_stride, const pixel *tmp,
697
                      const int w, int h)
698
10.1k
{
699
10.1k
    const uint8_t *const mask = &dav1d_obmc_masks[w];
700
201k
    do {
701
1.50M
        for (int x = 0; x < (w * 3) >> 2; x++) {
702
1.30M
            dst[x] = blend_px(dst[x], tmp[x], mask[x]);
703
1.30M
        }
704
201k
        dst += PXSTRIDE(dst_stride);
705
201k
        tmp += w;
706
201k
    } while (--h);
707
10.1k
}
708
709
static void blend_h_c(pixel *dst, const ptrdiff_t dst_stride, const pixel *tmp,
710
                      const int w, int h)
711
7.93k
{
712
7.93k
    const uint8_t *mask = &dav1d_obmc_masks[h];
713
7.93k
    h = (h * 3) >> 2;
714
42.2k
    do {
715
42.2k
        const int m = *mask++;
716
646k
        for (int x = 0; x < w; x++) {
717
603k
            dst[x] = blend_px(dst[x], tmp[x], m);
718
603k
        }
719
42.2k
        dst += PXSTRIDE(dst_stride);
720
42.2k
        tmp += w;
721
42.2k
    } while (--h);
722
7.93k
}
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
618
{
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
618
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
732
618
    const int bitdepth = bitdepth_from_max(bitdepth_max);
733
618
    const int sh = intermediate_bits + 6;
734
618
    const int rnd = (32 << intermediate_bits) + PREP_BIAS * 64;
735
618
    const int mask_sh = bitdepth + intermediate_bits - 4;
736
618
    const int mask_rnd = 1 << (mask_sh - 5);
737
23.7k
    do {
738
1.09M
        for (int x = 0; x < w; x++) {
739
1.07M
            const int tmpdiff = tmp1[x] - tmp2[x];
740
1.07M
            const int m = imin(38 + ((abs(tmpdiff) + mask_rnd) >> mask_sh), 64);
741
1.07M
            dst[x] = iclip_pixel((tmpdiff * m + tmp2[x] * 64 + rnd) >> sh);
742
743
1.07M
            if (ss_hor) {
744
136k
                x++;
745
746
136k
                const int tmpdiff = tmp1[x] - tmp2[x];
747
136k
                const int n = imin(38 + ((abs(tmpdiff) + mask_rnd) >> mask_sh), 64);
748
136k
                dst[x] = iclip_pixel((tmpdiff * n + tmp2[x] * 64 + rnd) >> sh);
749
750
136k
                if (h & ss_ver) {
751
62.9k
                    mask[x >> 1] = (m + n + mask[x >> 1] + 2 - sign) >> 2;
752
73.3k
                } else if (ss_ver) {
753
62.9k
                    mask[x >> 1] = m + n;
754
62.9k
                } else {
755
10.3k
                    mask[x >> 1] = (m + n + 1 - sign) >> 1;
756
10.3k
                }
757
935k
            } else {
758
935k
                mask[x] = m;
759
935k
            }
760
1.07M
        }
761
762
23.7k
        tmp1 += w;
763
23.7k
        tmp2 += w;
764
23.7k
        dst += PXSTRIDE(dst_stride);
765
23.7k
        if (!ss_ver || (h & 1)) mask += w >> ss_hor;
766
23.7k
    } while (--h);
767
618
}
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
618
                             const int sign HIGHBD_DECL_SUFFIX) \
774
618
{ \
775
618
    w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver \
776
618
             HIGHBD_TAIL_SUFFIX); \
777
618
}
mc_tmpl.c:w_mask_444_c
Line
Count
Source
773
359
                             const int sign HIGHBD_DECL_SUFFIX) \
774
359
{ \
775
359
    w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver \
776
359
             HIGHBD_TAIL_SUFFIX); \
777
359
}
mc_tmpl.c:w_mask_422_c
Line
Count
Source
773
54
                             const int sign HIGHBD_DECL_SUFFIX) \
774
54
{ \
775
54
    w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver \
776
54
             HIGHBD_TAIL_SUFFIX); \
777
54
}
mc_tmpl.c:w_mask_420_c
Line
Count
Source
773
205
                             const int sign HIGHBD_DECL_SUFFIX) \
774
205
{ \
775
205
    w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver \
776
205
             HIGHBD_TAIL_SUFFIX); \
777
205
}
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
9.75M
    ((F[0] * src[x - 3 * stride] + \
787
9.75M
      F[1] * src[x - 2 * stride] + \
788
9.75M
      F[2] * src[x - 1 * stride] + \
789
9.75M
      F[3] * src[x + 0 * stride] + \
790
9.75M
      F[4] * src[x + 1 * stride] + \
791
9.75M
      F[5] * src[x + 2 * stride] + \
792
9.75M
      F[6] * src[x + 3 * stride] + \
793
9.75M
      F[7] * src[x + 4 * stride] + \
794
9.75M
      ((1 << (sh)) >> 1)) >> (sh))
795
796
#define FILTER_WARP_CLIP(src, x, F, stride, sh) \
797
2.57M
    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
40.4k
{
804
40.4k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
805
40.4k
    int16_t mid[15 * 8], *mid_ptr = mid;
806
807
40.4k
    src -= 3 * PXSTRIDE(src_stride);
808
643k
    for (int y = 0; y < 15; y++, mx += abcd[1]) {
809
5.41M
        for (int x = 0, tmx = mx; x < 8; x++, tmx += abcd[0]) {
810
4.80M
            const int8_t *const filter =
811
4.80M
                dav1d_mc_warp_filter[64 + ((tmx + 512) >> 10)];
812
813
4.80M
            mid_ptr[x] = FILTER_WARP_RND(src, x, filter, 1,
814
4.80M
                                         7 - intermediate_bits);
815
4.80M
        }
816
602k
        src += PXSTRIDE(src_stride);
817
602k
        mid_ptr += 8;
818
602k
    }
819
820
40.4k
    mid_ptr = &mid[3 * 8];
821
362k
    for (int y = 0; y < 8; y++, my += abcd[3]) {
822
2.89M
        for (int x = 0, tmy = my; x < 8; x++, tmy += abcd[2]) {
823
2.57M
            const int8_t *const filter =
824
2.57M
                dav1d_mc_warp_filter[64 + ((tmy + 512) >> 10)];
825
826
2.57M
            dst[x] = FILTER_WARP_CLIP(mid_ptr, x, filter, 8,
827
2.57M
                                      7 + intermediate_bits);
828
2.57M
        }
829
322k
        mid_ptr += 8;
830
322k
        dst += PXSTRIDE(dst_stride);
831
322k
    }
832
40.4k
}
833
834
static void warp_affine_8x8t_c(int16_t *tmp, const ptrdiff_t tmp_stride,
835
                               const pixel *src, const ptrdiff_t src_stride,
836
                               const int16_t *const abcd, int mx, int my
837
                               HIGHBD_DECL_SUFFIX)
838
12.9k
{
839
12.9k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
840
12.9k
    int16_t mid[15 * 8], *mid_ptr = mid;
841
842
12.9k
    src -= 3 * PXSTRIDE(src_stride);
843
206k
    for (int y = 0; y < 15; y++, mx += abcd[1]) {
844
1.74M
        for (int x = 0, tmx = mx; x < 8; x++, tmx += abcd[0]) {
845
1.54M
            const int8_t *const filter =
846
1.54M
                dav1d_mc_warp_filter[64 + ((tmx + 512) >> 10)];
847
848
1.54M
            mid_ptr[x] = FILTER_WARP_RND(src, x, filter, 1,
849
1.54M
                                         7 - intermediate_bits);
850
1.54M
        }
851
193k
        src += PXSTRIDE(src_stride);
852
193k
        mid_ptr += 8;
853
193k
    }
854
855
12.9k
    mid_ptr = &mid[3 * 8];
856
116k
    for (int y = 0; y < 8; y++, my += abcd[3]) {
857
929k
        for (int x = 0, tmy = my; x < 8; x++, tmy += abcd[2]) {
858
825k
            const int8_t *const filter =
859
825k
                dav1d_mc_warp_filter[64 + ((tmy + 512) >> 10)];
860
861
825k
            tmp[x] = FILTER_WARP_RND(mid_ptr, x, filter, 8, 7) - PREP_BIAS;
862
825k
        }
863
103k
        mid_ptr += 8;
864
103k
        tmp += tmp_stride;
865
103k
    }
866
12.9k
}
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
122k
{
874
    // find offset in reference of visible block to copy
875
122k
    ref += iclip((int) y, 0, (int) ih - 1) * PXSTRIDE(ref_stride) +
876
122k
           iclip((int) x, 0, (int) iw - 1);
877
878
    // number of pixels to extend (left, right, top, bottom)
879
122k
    const int left_ext = iclip((int) -x, 0, (int) bw - 1);
880
122k
    const int right_ext = iclip((int) (x + bw - iw), 0, (int) bw - 1);
881
122k
    assert(left_ext + right_ext < bw);
882
122k
    const int top_ext = iclip((int) -y, 0, (int) bh - 1);
883
122k
    const int bottom_ext = iclip((int) (y + bh - ih), 0, (int) bh - 1);
884
122k
    assert(top_ext + bottom_ext < bh);
885
886
    // copy visible portion first
887
122k
    pixel *blk = dst + top_ext * PXSTRIDE(dst_stride);
888
122k
    const int center_w = (int) (bw - left_ext - right_ext);
889
122k
    const int center_h = (int) (bh - top_ext - bottom_ext);
890
2.20M
    for (int y = 0; y < center_h; y++) {
891
2.08M
        pixel_copy(blk + left_ext, ref, center_w);
892
        // extend left edge for this line
893
2.08M
        if (left_ext)
894
255k
            pixel_set(blk, blk[left_ext], left_ext);
895
        // extend right edge for this line
896
2.08M
        if (right_ext)
897
1.28M
            pixel_set(blk + left_ext + center_w, blk[left_ext + center_w - 1],
898
1.28M
                      right_ext);
899
2.08M
        ref += PXSTRIDE(ref_stride);
900
2.08M
        blk += PXSTRIDE(dst_stride);
901
2.08M
    }
902
903
    // copy top
904
122k
    blk = dst + top_ext * PXSTRIDE(dst_stride);
905
324k
    for (int y = 0; y < top_ext; y++) {
906
201k
        pixel_copy(dst, blk, bw);
907
201k
        dst += PXSTRIDE(dst_stride);
908
201k
    }
909
910
    // copy bottom
911
122k
    dst += center_h * PXSTRIDE(dst_stride);
912
898k
    for (int y = 0; y < bottom_ext; y++) {
913
775k
        pixel_copy(dst, &dst[-PXSTRIDE(dst_stride)], bw);
914
775k
        dst += PXSTRIDE(dst_stride);
915
775k
    }
916
122k
}
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
24.8k
{
923
949k
    do {
924
949k
        int mx = mx0, src_x = -1;
925
110M
        for (int x = 0; x < dst_w; x++) {
926
109M
            const int8_t *const F = dav1d_resize_filter[mx >> 8];
927
109M
            dst[x] = iclip_pixel((-(F[0] * src[iclip(src_x - 3, 0, src_w - 1)] +
928
109M
                                    F[1] * src[iclip(src_x - 2, 0, src_w - 1)] +
929
109M
                                    F[2] * src[iclip(src_x - 1, 0, src_w - 1)] +
930
109M
                                    F[3] * src[iclip(src_x + 0, 0, src_w - 1)] +
931
109M
                                    F[4] * src[iclip(src_x + 1, 0, src_w - 1)] +
932
109M
                                    F[5] * src[iclip(src_x + 2, 0, src_w - 1)] +
933
109M
                                    F[6] * src[iclip(src_x + 3, 0, src_w - 1)] +
934
109M
                                    F[7] * src[iclip(src_x + 4, 0, src_w - 1)]) +
935
109M
                                  64) >> 7);
936
109M
            mx += dx;
937
109M
            src_x += mx >> 14;
938
109M
            mx &= 0x3fff;
939
109M
        }
940
941
949k
        dst += PXSTRIDE(dst_stride);
942
949k
        src += PXSTRIDE(src_stride);
943
949k
    } while (--h);
944
24.8k
}
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
18.2k
COLD void bitfn(dav1d_mc_dsp_init)(Dav1dMCDSPContext *const c) {
961
182k
#define init_mc_fns(type, name) do { \
962
182k
    c->mc        [type] = put_##name##_c; \
963
182k
    c->mc_scaled [type] = put_##name##_scaled_c; \
964
182k
    c->mct       [type] = prep_##name##_c; \
965
182k
    c->mct_scaled[type] = prep_##name##_scaled_c; \
966
182k
} while (0)
967
968
18.2k
    init_mc_fns(FILTER_2D_8TAP_REGULAR,        8tap_regular);
969
18.2k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SMOOTH, 8tap_regular_smooth);
970
18.2k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SHARP,  8tap_regular_sharp);
971
18.2k
    init_mc_fns(FILTER_2D_8TAP_SHARP_REGULAR,  8tap_sharp_regular);
972
18.2k
    init_mc_fns(FILTER_2D_8TAP_SHARP_SMOOTH,   8tap_sharp_smooth);
973
18.2k
    init_mc_fns(FILTER_2D_8TAP_SHARP,          8tap_sharp);
974
18.2k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_REGULAR, 8tap_smooth_regular);
975
18.2k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH,         8tap_smooth);
976
18.2k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_SHARP,   8tap_smooth_sharp);
977
18.2k
    init_mc_fns(FILTER_2D_BILINEAR,            bilin);
978
979
18.2k
    c->avg      = avg_c;
980
18.2k
    c->w_avg    = w_avg_c;
981
18.2k
    c->mask     = mask_c;
982
18.2k
    c->blend    = blend_c;
983
18.2k
    c->blend_v  = blend_v_c;
984
18.2k
    c->blend_h  = blend_h_c;
985
18.2k
    c->w_mask[0] = w_mask_444_c;
986
18.2k
    c->w_mask[1] = w_mask_422_c;
987
18.2k
    c->w_mask[2] = w_mask_420_c;
988
18.2k
    c->warp8x8  = warp_affine_8x8_c;
989
18.2k
    c->warp8x8t = warp_affine_8x8t_c;
990
18.2k
    c->emu_edge = emu_edge_c;
991
18.2k
    c->resize   = resize_c;
992
993
#if HAVE_ASM
994
#if ARCH_AARCH64 || ARCH_ARM
995
    mc_dsp_init_arm(c);
996
#elif ARCH_LOONGARCH64
997
    mc_dsp_init_loongarch(c);
998
#elif ARCH_PPC64LE
999
    mc_dsp_init_ppc(c);
1000
#elif ARCH_RISCV
1001
    mc_dsp_init_riscv(c);
1002
#elif ARCH_X86
1003
    mc_dsp_init_x86(c);
1004
#endif
1005
#endif
1006
18.2k
}
dav1d_mc_dsp_init_8bpc
Line
Count
Source
960
8.36k
COLD void bitfn(dav1d_mc_dsp_init)(Dav1dMCDSPContext *const c) {
961
8.36k
#define init_mc_fns(type, name) do { \
962
8.36k
    c->mc        [type] = put_##name##_c; \
963
8.36k
    c->mc_scaled [type] = put_##name##_scaled_c; \
964
8.36k
    c->mct       [type] = prep_##name##_c; \
965
8.36k
    c->mct_scaled[type] = prep_##name##_scaled_c; \
966
8.36k
} while (0)
967
968
8.36k
    init_mc_fns(FILTER_2D_8TAP_REGULAR,        8tap_regular);
969
8.36k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SMOOTH, 8tap_regular_smooth);
970
8.36k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SHARP,  8tap_regular_sharp);
971
8.36k
    init_mc_fns(FILTER_2D_8TAP_SHARP_REGULAR,  8tap_sharp_regular);
972
8.36k
    init_mc_fns(FILTER_2D_8TAP_SHARP_SMOOTH,   8tap_sharp_smooth);
973
8.36k
    init_mc_fns(FILTER_2D_8TAP_SHARP,          8tap_sharp);
974
8.36k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_REGULAR, 8tap_smooth_regular);
975
8.36k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH,         8tap_smooth);
976
8.36k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_SHARP,   8tap_smooth_sharp);
977
8.36k
    init_mc_fns(FILTER_2D_BILINEAR,            bilin);
978
979
8.36k
    c->avg      = avg_c;
980
8.36k
    c->w_avg    = w_avg_c;
981
8.36k
    c->mask     = mask_c;
982
8.36k
    c->blend    = blend_c;
983
8.36k
    c->blend_v  = blend_v_c;
984
8.36k
    c->blend_h  = blend_h_c;
985
8.36k
    c->w_mask[0] = w_mask_444_c;
986
8.36k
    c->w_mask[1] = w_mask_422_c;
987
8.36k
    c->w_mask[2] = w_mask_420_c;
988
8.36k
    c->warp8x8  = warp_affine_8x8_c;
989
8.36k
    c->warp8x8t = warp_affine_8x8t_c;
990
8.36k
    c->emu_edge = emu_edge_c;
991
8.36k
    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
8.36k
}
dav1d_mc_dsp_init_16bpc
Line
Count
Source
960
9.88k
COLD void bitfn(dav1d_mc_dsp_init)(Dav1dMCDSPContext *const c) {
961
9.88k
#define init_mc_fns(type, name) do { \
962
9.88k
    c->mc        [type] = put_##name##_c; \
963
9.88k
    c->mc_scaled [type] = put_##name##_scaled_c; \
964
9.88k
    c->mct       [type] = prep_##name##_c; \
965
9.88k
    c->mct_scaled[type] = prep_##name##_scaled_c; \
966
9.88k
} while (0)
967
968
9.88k
    init_mc_fns(FILTER_2D_8TAP_REGULAR,        8tap_regular);
969
9.88k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SMOOTH, 8tap_regular_smooth);
970
9.88k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SHARP,  8tap_regular_sharp);
971
9.88k
    init_mc_fns(FILTER_2D_8TAP_SHARP_REGULAR,  8tap_sharp_regular);
972
9.88k
    init_mc_fns(FILTER_2D_8TAP_SHARP_SMOOTH,   8tap_sharp_smooth);
973
9.88k
    init_mc_fns(FILTER_2D_8TAP_SHARP,          8tap_sharp);
974
9.88k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_REGULAR, 8tap_smooth_regular);
975
9.88k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH,         8tap_smooth);
976
9.88k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_SHARP,   8tap_smooth_sharp);
977
9.88k
    init_mc_fns(FILTER_2D_BILINEAR,            bilin);
978
979
9.88k
    c->avg      = avg_c;
980
9.88k
    c->w_avg    = w_avg_c;
981
9.88k
    c->mask     = mask_c;
982
9.88k
    c->blend    = blend_c;
983
9.88k
    c->blend_v  = blend_v_c;
984
9.88k
    c->blend_h  = blend_h_c;
985
9.88k
    c->w_mask[0] = w_mask_444_c;
986
9.88k
    c->w_mask[1] = w_mask_422_c;
987
9.88k
    c->w_mask[2] = w_mask_420_c;
988
9.88k
    c->warp8x8  = warp_affine_8x8_c;
989
9.88k
    c->warp8x8t = warp_affine_8x8t_c;
990
9.88k
    c->emu_edge = emu_edge_c;
991
9.88k
    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
9.88k
}