Coverage Report

Created: 2026-05-30 06:06

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
313k
#define get_intermediate_bits(bitdepth_max) 4
41
// Output in interval [-5132, 9212], fits in int16_t as is
42
22.9M
#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
184k
{
55
2.05M
    do {
56
2.05M
        pixel_copy(dst, src, w);
57
58
2.05M
        dst += dst_stride;
59
2.05M
        src += src_stride;
60
2.05M
    } while (--h);
61
184k
}
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
4.60k
{
67
4.60k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
68
117k
    do {
69
5.35M
        for (int x = 0; x < w; x++)
70
5.24M
            tmp[x] = (src[x] << intermediate_bits) - PREP_BIAS;
71
72
117k
        tmp += w;
73
117k
        src += src_stride;
74
117k
    } while (--h);
75
4.60k
}
76
77
#define FILTER_8TAP(src, x, F, stride) \
78
26.9M
    (F[0] * src[x + -3 * stride] + \
79
26.9M
     F[1] * src[x + -2 * stride] + \
80
26.9M
     F[2] * src[x + -1 * stride] + \
81
26.9M
     F[3] * src[x + +0 * stride] + \
82
26.9M
     F[4] * src[x + +1 * stride] + \
83
26.9M
     F[5] * src[x + +2 * stride] + \
84
26.9M
     F[6] * src[x + +3 * stride] + \
85
26.9M
     F[7] * src[x + +4 * stride])
86
87
#define FILTER_8TAP2(src, x, F) \
88
5.07M
    (F[0] * src[0][x] + \
89
5.07M
     F[1] * src[1][x] + \
90
5.07M
     F[2] * src[2][x] + \
91
5.07M
     F[3] * src[3][x] + \
92
5.07M
     F[4] * src[4][x] + \
93
5.07M
     F[5] * src[5][x] + \
94
5.07M
     F[6] * src[6][x] + \
95
5.07M
     F[7] * src[7][x])
96
97
#define DAV1D_FILTER_8TAP_RND(src, x, F, stride, sh) \
98
25.4M
    ((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.58M
    ((FILTER_8TAP(src, x, F, stride) + (rnd)) >> (sh))
102
103
#define DAV1D_FILTER_8TAP_RND3(src, x, F, sh) \
104
5.07M
    ((FILTER_8TAP2(src, x, F) + ((1 << (sh)) >> 1)) >> (sh))
105
106
#define DAV1D_FILTER_8TAP_CLIP(src, x, F, stride, sh) \
107
3.46M
    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.58M
    iclip_pixel(DAV1D_FILTER_8TAP_RND2(src, x, F, stride, rnd, sh))
111
112
#define DAV1D_FILTER_8TAP_CLIP3(src, x, F, sh) \
113
2.11M
    iclip_pixel(DAV1D_FILTER_8TAP_RND3(src, x, F, sh))
114
115
#define GET_H_FILTER(mx) \
116
10.7M
    const int8_t *const fh = !(mx) ? NULL : w > 4 ? \
117
9.98M
        dav1d_mc_subpel_filters[filter_type & 3][(mx) - 1] : \
118
9.98M
        dav1d_mc_subpel_filters[3 + (filter_type & 1)][(mx) - 1]
119
120
#define GET_V_FILTER(my) \
121
381k
    const int8_t *const fv = !(my) ? NULL : h > 4 ? \
122
155k
        dav1d_mc_subpel_filters[filter_type >> 2][(my) - 1] : \
123
155k
        dav1d_mc_subpel_filters[3 + ((filter_type >> 2) & 1)][(my) - 1]
124
125
#define GET_FILTERS() \
126
60.7k
    GET_H_FILTER(mx); \
127
60.7k
    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
53.2k
{
135
53.2k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
136
53.2k
    const int intermediate_rnd = 32 + ((1 << (6 - intermediate_bits)) >> 1);
137
138
53.2k
    GET_FILTERS();
139
53.2k
    dst_stride = PXSTRIDE(dst_stride);
140
53.2k
    src_stride = PXSTRIDE(src_stride);
141
142
53.2k
    if (fh) {
143
11.3k
        if (fv) {
144
6.99k
            int tmp_h = h + 7;
145
6.99k
            int16_t mid[128 * 135], *mid_ptr = mid;
146
147
6.99k
            src -= src_stride * 3;
148
142k
            do {
149
3.27M
                for (int x = 0; x < w; x++)
150
3.13M
                    mid_ptr[x] = DAV1D_FILTER_8TAP_RND(src, x, fh, 1,
151
142k
                                                       6 - intermediate_bits);
152
153
142k
                mid_ptr += 128;
154
142k
                src += src_stride;
155
142k
            } while (--tmp_h);
156
157
6.99k
            mid_ptr = mid + 128 * 3;
158
93.2k
            do {
159
2.57M
                for (int x = 0; x < w; x++)
160
2.47M
                    dst[x] = DAV1D_FILTER_8TAP_CLIP(mid_ptr, x, fv, 128,
161
93.2k
                                                    6 + intermediate_bits);
162
163
93.2k
                mid_ptr += 128;
164
93.2k
                dst += dst_stride;
165
93.2k
            } while (--h);
166
6.99k
        } else {
167
53.5k
            do {
168
1.64M
                for (int x = 0; x < w; x++) {
169
1.58M
                    dst[x] = DAV1D_FILTER_8TAP_CLIP2(src, x, fh, 1,
170
1.58M
                                                     intermediate_rnd, 6);
171
1.58M
                }
172
173
53.5k
                dst += dst_stride;
174
53.5k
                src += src_stride;
175
53.5k
            } while (--h);
176
4.39k
        }
177
41.8k
    } else if (fv) {
178
35.0k
        do {
179
1.02M
            for (int x = 0; x < w; x++)
180
989k
                dst[x] = DAV1D_FILTER_8TAP_CLIP(src, x, fv, src_stride, 6);
181
182
35.0k
            dst += dst_stride;
183
35.0k
            src += src_stride;
184
35.0k
        } while (--h);
185
2.55k
    } else
186
39.3k
        put_c(dst, dst_stride, src, src_stride, w, h);
187
53.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
11.4k
{
196
11.4k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
197
11.4k
    const int intermediate_rnd = (1 << intermediate_bits) >> 1;
198
11.4k
    int16_t mid[128 * 8];
199
11.4k
    int16_t *mid_ptrs[8];
200
11.4k
    int in_y = -8;
201
11.4k
    src_stride = PXSTRIDE(src_stride);
202
203
102k
    for (int i = 0; i < 8; i++)
204
91.5k
        mid_ptrs[i] = &mid[128 * i];
205
206
11.4k
    src -= src_stride * 3;
207
208
184k
    for (int y = 0; y < h; y++) {
209
173k
        int x;
210
173k
        int src_y = my >> 10;
211
173k
        GET_V_FILTER((my & 0x3ff) >> 6);
212
213
414k
        while (in_y < src_y) {
214
240k
            int imx = mx, ioff = 0;
215
240k
            int16_t *mid_ptr = mid_ptrs[0];
216
217
1.92M
            for (int i = 0; i < 7; i++)
218
1.68M
                mid_ptrs[i] = mid_ptrs[i + 1];
219
240k
            mid_ptrs[7] = mid_ptr;
220
221
5.12M
            for (x = 0; x < w; x++) {
222
4.88M
                GET_H_FILTER(imx >> 6);
223
4.88M
                mid_ptr[x] = fh ? DAV1D_FILTER_8TAP_RND(src, ioff, fh, 1,
224
4.88M
                                                        6 - intermediate_bits) :
225
4.88M
                                  src[ioff] << intermediate_bits;
226
4.88M
                imx += dx;
227
4.88M
                ioff += imx >> 10;
228
4.88M
                imx &= 0x3ff;
229
4.88M
            }
230
231
240k
            src += src_stride;
232
240k
            in_y++;
233
240k
        }
234
235
4.62M
        for (x = 0; x < w; x++)
236
4.45M
            dst[x] = fv ? DAV1D_FILTER_8TAP_CLIP3(mid_ptrs, x, fv,
237
4.45M
                                                  6 + intermediate_bits) :
238
4.45M
                          iclip_pixel((mid_ptrs[3][x] + intermediate_rnd) >>
239
2.34M
                                              intermediate_bits);
240
241
173k
        my += dy;
242
173k
        dst += PXSTRIDE(dst_stride);
243
173k
    }
244
11.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
7.45k
{
251
7.45k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
252
7.45k
    GET_FILTERS();
253
7.45k
    src_stride = PXSTRIDE(src_stride);
254
255
7.45k
    if (fh) {
256
4.11k
        if (fv) {
257
2.38k
            int tmp_h = h + 7;
258
2.38k
            int16_t mid[128 * 135], *mid_ptr = mid;
259
260
2.38k
            src -= src_stride * 3;
261
78.0k
            do {
262
2.53M
                for (int x = 0; x < w; x++)
263
2.45M
                    mid_ptr[x] = DAV1D_FILTER_8TAP_RND(src, x, fh, 1,
264
78.0k
                                                       6 - intermediate_bits);
265
266
78.0k
                mid_ptr += 128;
267
78.0k
                src += src_stride;
268
78.0k
            } while (--tmp_h);
269
270
2.38k
            mid_ptr = mid + 128 * 3;
271
61.3k
            do {
272
2.21M
                for (int x = 0; x < w; x++) {
273
2.15M
                    int t = DAV1D_FILTER_8TAP_RND(mid_ptr, x, fv, 128, 6) -
274
2.15M
                                  PREP_BIAS;
275
2.15M
                    assert(t >= INT16_MIN && t <= INT16_MAX);
276
2.15M
                    tmp[x] = t;
277
2.15M
                }
278
279
61.3k
                mid_ptr += 128;
280
61.3k
                tmp += w;
281
61.3k
            } while (--h);
282
2.38k
        } else {
283
57.4k
            do {
284
2.96M
                for (int x = 0; x < w; x++)
285
2.90M
                    tmp[x] = DAV1D_FILTER_8TAP_RND(src, x, fh, 1,
286
2.90M
                                                   6 - intermediate_bits) -
287
2.90M
                             PREP_BIAS;
288
289
57.4k
                tmp += w;
290
57.4k
                src += src_stride;
291
57.4k
            } while (--h);
292
1.72k
        }
293
4.11k
    } else if (fv) {
294
28.1k
        do {
295
1.35M
            for (int x = 0; x < w; x++)
296
1.32M
                tmp[x] = DAV1D_FILTER_8TAP_RND(src, x, fv, src_stride,
297
1.32M
                                               6 - intermediate_bits) -
298
1.32M
                         PREP_BIAS;
299
300
28.1k
            tmp += w;
301
28.1k
            src += src_stride;
302
28.1k
        } while (--h);
303
890
    } else
304
2.45k
        prep_c(tmp, src, src_stride, w, h HIGHBD_TAIL_SUFFIX);
305
7.45k
}
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.96k
{
313
4.96k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
314
4.96k
    int16_t mid[128 * 8];
315
4.96k
    int16_t *mid_ptrs[8];
316
4.96k
    int in_y = -8;
317
4.96k
    src_stride = PXSTRIDE(src_stride);
318
319
44.6k
    for (int i = 0; i < 8; i++)
320
39.6k
        mid_ptrs[i] = &mid[128 * i];
321
322
4.96k
    src -= src_stride * 3;
323
324
152k
    for (int y = 0; y < h; y++) {
325
147k
        int x;
326
147k
        int src_y = my >> 10;
327
147k
        GET_V_FILTER((my & 0x3ff) >> 6);
328
329
324k
        while (in_y < src_y) {
330
177k
            int imx = mx, ioff = 0;
331
177k
            int16_t *mid_ptr = mid_ptrs[0];
332
333
1.41M
            for (int i = 0; i < 7; i++)
334
1.24M
                mid_ptrs[i] = mid_ptrs[i + 1];
335
177k
            mid_ptrs[7] = mid_ptr;
336
337
5.95M
            for (x = 0; x < w; x++) {
338
5.77M
                GET_H_FILTER(imx >> 6);
339
5.77M
                mid_ptr[x] = fh ? DAV1D_FILTER_8TAP_RND(src, ioff, fh, 1,
340
5.77M
                                                        6 - intermediate_bits) :
341
5.77M
                                  src[ioff] << intermediate_bits;
342
5.77M
                imx += dx;
343
5.77M
                ioff += imx >> 10;
344
5.77M
                imx &= 0x3ff;
345
5.77M
            }
346
347
177k
            src += src_stride;
348
177k
            in_y++;
349
177k
        }
350
351
5.51M
        for (x = 0; x < w; x++)
352
5.36M
            tmp[x] = (fv ? DAV1D_FILTER_8TAP_RND3(mid_ptrs, x, fv, 6)
353
5.36M
                         : mid_ptrs[3][x]) - PREP_BIAS;
354
355
147k
        my += dy;
356
147k
        tmp += w;
357
147k
    }
358
4.96k
}
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
53.2k
                                HIGHBD_DECL_SUFFIX) \
368
53.2k
{ \
369
53.2k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
53.2k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
53.2k
} \
mc_tmpl.c:put_8tap_regular_c
Line
Count
Source
367
29.4k
                                HIGHBD_DECL_SUFFIX) \
368
29.4k
{ \
369
29.4k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
29.4k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
29.4k
} \
mc_tmpl.c:put_8tap_regular_smooth_c
Line
Count
Source
367
831
                                HIGHBD_DECL_SUFFIX) \
368
831
{ \
369
831
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
831
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
831
} \
mc_tmpl.c:put_8tap_regular_sharp_c
Line
Count
Source
367
265
                                HIGHBD_DECL_SUFFIX) \
368
265
{ \
369
265
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
265
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
265
} \
mc_tmpl.c:put_8tap_sharp_regular_c
Line
Count
Source
367
285
                                HIGHBD_DECL_SUFFIX) \
368
285
{ \
369
285
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
285
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
285
} \
mc_tmpl.c:put_8tap_sharp_smooth_c
Line
Count
Source
367
166
                                HIGHBD_DECL_SUFFIX) \
368
166
{ \
369
166
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
166
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
166
} \
mc_tmpl.c:put_8tap_sharp_c
Line
Count
Source
367
8.90k
                                HIGHBD_DECL_SUFFIX) \
368
8.90k
{ \
369
8.90k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
8.90k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
8.90k
} \
mc_tmpl.c:put_8tap_smooth_regular_c
Line
Count
Source
367
1.20k
                                HIGHBD_DECL_SUFFIX) \
368
1.20k
{ \
369
1.20k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
1.20k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
1.20k
} \
mc_tmpl.c:put_8tap_smooth_c
Line
Count
Source
367
11.9k
                                HIGHBD_DECL_SUFFIX) \
368
11.9k
{ \
369
11.9k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
11.9k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
11.9k
} \
mc_tmpl.c:put_8tap_smooth_sharp_c
Line
Count
Source
367
186
                                HIGHBD_DECL_SUFFIX) \
368
186
{ \
369
186
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
186
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
186
} \
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
11.4k
                                       HIGHBD_DECL_SUFFIX) \
380
11.4k
{ \
381
11.4k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
11.4k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
11.4k
} \
mc_tmpl.c:put_8tap_regular_scaled_c
Line
Count
Source
379
4.46k
                                       HIGHBD_DECL_SUFFIX) \
380
4.46k
{ \
381
4.46k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
4.46k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
4.46k
} \
mc_tmpl.c:put_8tap_regular_smooth_scaled_c
Line
Count
Source
379
295
                                       HIGHBD_DECL_SUFFIX) \
380
295
{ \
381
295
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
295
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
295
} \
mc_tmpl.c:put_8tap_regular_sharp_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_regular_scaled_c
Line
Count
Source
379
180
                                       HIGHBD_DECL_SUFFIX) \
380
180
{ \
381
180
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
180
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
180
} \
mc_tmpl.c:put_8tap_sharp_smooth_scaled_c
Line
Count
Source
379
106
                                       HIGHBD_DECL_SUFFIX) \
380
106
{ \
381
106
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
106
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
106
} \
mc_tmpl.c:put_8tap_sharp_scaled_c
Line
Count
Source
379
1.39k
                                       HIGHBD_DECL_SUFFIX) \
380
1.39k
{ \
381
1.39k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
1.39k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
1.39k
} \
mc_tmpl.c:put_8tap_smooth_regular_scaled_c
Line
Count
Source
379
317
                                       HIGHBD_DECL_SUFFIX) \
380
317
{ \
381
317
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
317
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
317
} \
mc_tmpl.c:put_8tap_smooth_scaled_c
Line
Count
Source
379
4.25k
                                       HIGHBD_DECL_SUFFIX) \
380
4.25k
{ \
381
4.25k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
4.25k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
4.25k
} \
mc_tmpl.c:put_8tap_smooth_sharp_scaled_c
Line
Count
Source
379
212
                                       HIGHBD_DECL_SUFFIX) \
380
212
{ \
381
212
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
212
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
212
} \
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
7.45k
                                 HIGHBD_DECL_SUFFIX) \
390
7.45k
{ \
391
7.45k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
7.45k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
7.45k
} \
mc_tmpl.c:prep_8tap_regular_c
Line
Count
Source
389
2.57k
                                 HIGHBD_DECL_SUFFIX) \
390
2.57k
{ \
391
2.57k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
2.57k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
2.57k
} \
mc_tmpl.c:prep_8tap_regular_smooth_c
Line
Count
Source
389
305
                                 HIGHBD_DECL_SUFFIX) \
390
305
{ \
391
305
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
305
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
305
} \
mc_tmpl.c:prep_8tap_regular_sharp_c
Line
Count
Source
389
433
                                 HIGHBD_DECL_SUFFIX) \
390
433
{ \
391
433
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
433
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
433
} \
mc_tmpl.c:prep_8tap_sharp_regular_c
Line
Count
Source
389
689
                                 HIGHBD_DECL_SUFFIX) \
390
689
{ \
391
689
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
689
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
689
} \
mc_tmpl.c:prep_8tap_sharp_smooth_c
Line
Count
Source
389
179
                                 HIGHBD_DECL_SUFFIX) \
390
179
{ \
391
179
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
179
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
179
} \
mc_tmpl.c:prep_8tap_sharp_c
Line
Count
Source
389
1.43k
                                 HIGHBD_DECL_SUFFIX) \
390
1.43k
{ \
391
1.43k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
1.43k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
1.43k
} \
mc_tmpl.c:prep_8tap_smooth_regular_c
Line
Count
Source
389
590
                                 HIGHBD_DECL_SUFFIX) \
390
590
{ \
391
590
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
590
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
590
} \
mc_tmpl.c:prep_8tap_smooth_c
Line
Count
Source
389
1.00k
                                 HIGHBD_DECL_SUFFIX) \
390
1.00k
{ \
391
1.00k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
1.00k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
1.00k
} \
mc_tmpl.c:prep_8tap_smooth_sharp_c
Line
Count
Source
389
251
                                 HIGHBD_DECL_SUFFIX) \
390
251
{ \
391
251
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
251
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
251
} \
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.96k
                                        HIGHBD_DECL_SUFFIX) \
401
4.96k
{ \
402
4.96k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
4.96k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
4.96k
}
mc_tmpl.c:prep_8tap_regular_scaled_c
Line
Count
Source
400
1.42k
                                        HIGHBD_DECL_SUFFIX) \
401
1.42k
{ \
402
1.42k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
1.42k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
1.42k
}
mc_tmpl.c:prep_8tap_regular_smooth_scaled_c
Line
Count
Source
400
255
                                        HIGHBD_DECL_SUFFIX) \
401
255
{ \
402
255
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
255
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
255
}
mc_tmpl.c:prep_8tap_regular_sharp_scaled_c
Line
Count
Source
400
357
                                        HIGHBD_DECL_SUFFIX) \
401
357
{ \
402
357
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
357
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
357
}
mc_tmpl.c:prep_8tap_sharp_regular_scaled_c
Line
Count
Source
400
328
                                        HIGHBD_DECL_SUFFIX) \
401
328
{ \
402
328
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
328
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
328
}
mc_tmpl.c:prep_8tap_sharp_smooth_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_sharp_scaled_c
Line
Count
Source
400
468
                                        HIGHBD_DECL_SUFFIX) \
401
468
{ \
402
468
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
468
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
468
}
mc_tmpl.c:prep_8tap_smooth_regular_scaled_c
Line
Count
Source
400
290
                                        HIGHBD_DECL_SUFFIX) \
401
290
{ \
402
290
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
290
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
290
}
mc_tmpl.c:prep_8tap_smooth_scaled_c
Line
Count
Source
400
1.37k
                                        HIGHBD_DECL_SUFFIX) \
401
1.37k
{ \
402
1.37k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
1.37k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
1.37k
}
mc_tmpl.c:prep_8tap_smooth_sharp_scaled_c
Line
Count
Source
400
200
                                        HIGHBD_DECL_SUFFIX) \
401
200
{ \
402
200
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
200
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
200
}
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
10.5M
    (16 * src[x] + ((mxy) * (src[x + stride] - src[x])))
418
419
#define FILTER_BILIN_RND(src, x, mxy, stride, sh) \
420
10.5M
    ((FILTER_BILIN(src, x, mxy, stride) + ((1 << (sh)) >> 1)) >> (sh))
421
422
#define FILTER_BILIN_CLIP(src, x, mxy, stride, sh) \
423
1.64M
    iclip_pixel(FILTER_BILIN_RND(src, x, mxy, stride, sh))
424
425
#define FILTER_BILIN2(src1, src2, x, mxy) \
426
1.03M
    (16 * src1[x] + ((mxy) * (src2[x] - src1[x])))
427
428
#define FILTER_BILIN_RND2(src1, src2, x, mxy, sh) \
429
1.03M
    ((FILTER_BILIN2(src1, src2, x, mxy) + ((1 << (sh)) >> 1)) >> (sh))
430
431
#define FILTER_BILIN_CLIP2(src1, src2, x, mxy, sh) \
432
636k
    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
150k
{
439
150k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
440
150k
    const int intermediate_rnd = (1 << intermediate_bits) >> 1;
441
150k
    dst_stride = PXSTRIDE(dst_stride);
442
150k
    src_stride = PXSTRIDE(src_stride);
443
444
150k
    if (mx) {
445
2.84k
        if (my) {
446
1.50k
            int16_t mid[128 * 129], *mid_ptr = mid;
447
1.50k
            int tmp_h = h + 1;
448
449
26.3k
            do {
450
947k
                for (int x = 0; x < w; x++)
451
921k
                    mid_ptr[x] = FILTER_BILIN_RND(src, x, mx, 1,
452
26.3k
                                                  4 - intermediate_bits);
453
454
26.3k
                mid_ptr += 128;
455
26.3k
                src += src_stride;
456
26.3k
            } while (--tmp_h);
457
458
1.50k
            mid_ptr = mid;
459
24.8k
            do {
460
922k
                for (int x = 0; x < w; x++)
461
897k
                    dst[x] = FILTER_BILIN_CLIP(mid_ptr, x, my, 128,
462
24.8k
                                               4 + intermediate_bits);
463
464
24.8k
                mid_ptr += 128;
465
24.8k
                dst += dst_stride;
466
24.8k
            } while (--h);
467
1.50k
        } else {
468
24.3k
            do {
469
971k
                for (int x = 0; x < w; x++) {
470
947k
                    const int px = FILTER_BILIN_RND(src, x, mx, 1,
471
947k
                                                    4 - intermediate_bits);
472
947k
                    dst[x] = iclip_pixel((px + intermediate_rnd) >> intermediate_bits);
473
947k
                }
474
475
24.3k
                dst += dst_stride;
476
24.3k
                src += src_stride;
477
24.3k
            } while (--h);
478
1.33k
        }
479
147k
    } else if (my) {
480
23.3k
        do {
481
767k
            for (int x = 0; x < w; x++)
482
743k
                dst[x] = FILTER_BILIN_CLIP(src, x, my, src_stride, 4);
483
484
23.3k
            dst += dst_stride;
485
23.3k
            src += src_stride;
486
23.3k
        } while (--h);
487
1.74k
    } else
488
145k
        put_c(dst, dst_stride, src, src_stride, w, h);
489
150k
}
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
2.52k
{
497
2.52k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
498
2.52k
    int16_t mid[128 * 2];
499
2.52k
    int in_y = -2;
500
501
33.1k
    do {
502
33.1k
        int x;
503
33.1k
        int y = my >> 10;
504
33.1k
        int16_t *mid1 = &mid[(y & 1) * 128];
505
33.1k
        int16_t *mid2 = &mid[((y + 1) & 1) * 128];
506
33.1k
        int dmy = my & 0x3ff;
507
508
67.4k
        while (in_y < y) {
509
34.2k
            int imx = mx, ioff = 0;
510
34.2k
            int16_t *mid_ptr = &mid[(in_y & 1) * 128];
511
512
668k
            for (x = 0; x < w; x++) {
513
634k
                mid_ptr[x] = FILTER_BILIN_RND(src, ioff, imx >> 6, 1,
514
634k
                                              4 - intermediate_bits);
515
634k
                imx += dx;
516
634k
                ioff += imx >> 10;
517
634k
                imx &= 0x3ff;
518
634k
            }
519
520
34.2k
            src += PXSTRIDE(src_stride);
521
34.2k
            in_y++;
522
34.2k
        }
523
524
670k
        for (x = 0; x < w; x++)
525
636k
            dst[x] = FILTER_BILIN_CLIP2(mid1, mid2, x, dmy >> 6,
526
33.1k
                                       4 + intermediate_bits);
527
528
33.1k
        my += dy;
529
33.1k
        dst += PXSTRIDE(dst_stride);
530
33.1k
    } while (--h);
531
2.52k
}
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
5.16k
{
538
5.16k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
539
5.16k
    src_stride = PXSTRIDE(src_stride);
540
541
5.16k
    if (mx) {
542
2.48k
        if (my) {
543
1.09k
            int16_t mid[128 * 129], *mid_ptr = mid;
544
1.09k
            int tmp_h = h + 1;
545
546
37.3k
            do {
547
1.69M
                for (int x = 0; x < w; x++)
548
1.65M
                    mid_ptr[x] = FILTER_BILIN_RND(src, x, mx, 1,
549
37.3k
                                                  4 - intermediate_bits);
550
551
37.3k
                mid_ptr += 128;
552
37.3k
                src += src_stride;
553
37.3k
            } while (--tmp_h);
554
555
1.09k
            mid_ptr = mid;
556
36.2k
            do {
557
1.66M
                for (int x = 0; x < w; x++)
558
1.62M
                    tmp[x] = FILTER_BILIN_RND(mid_ptr, x, my, 128, 4) -
559
1.62M
                             PREP_BIAS;
560
561
36.2k
                mid_ptr += 128;
562
36.2k
                tmp += w;
563
36.2k
            } while (--h);
564
1.38k
        } else {
565
40.9k
            do {
566
2.02M
                for (int x = 0; x < w; x++)
567
1.98M
                    tmp[x] = FILTER_BILIN_RND(src, x, mx, 1,
568
1.98M
                                              4 - intermediate_bits) -
569
1.98M
                             PREP_BIAS;
570
571
40.9k
                tmp += w;
572
40.9k
                src += src_stride;
573
40.9k
            } while (--h);
574
1.38k
        }
575
2.67k
    } else if (my) {
576
15.9k
        do {
577
772k
            for (int x = 0; x < w; x++)
578
757k
                tmp[x] = FILTER_BILIN_RND(src, x, my, src_stride,
579
757k
                                          4 - intermediate_bits) - PREP_BIAS;
580
581
15.9k
            tmp += w;
582
15.9k
            src += src_stride;
583
15.9k
        } while (--h);
584
525
    } else
585
2.15k
        prep_c(tmp, src, src_stride, w, h HIGHBD_TAIL_SUFFIX);
586
5.16k
}
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
904
{
593
904
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
594
904
    int16_t mid[128 * 2];
595
904
    int in_y = -2;
596
597
13.5k
    do {
598
13.5k
        int x;
599
13.5k
        int y = my >> 10;
600
13.5k
        int16_t *mid1 = &mid[(y & 1) * 128];
601
13.5k
        int16_t *mid2 = &mid[((y + 1) & 1) * 128];
602
13.5k
        int dmy = my & 0x3ff;
603
604
26.7k
        while (in_y < y) {
605
13.2k
            int imx = mx, ioff = 0;
606
13.2k
            int16_t *mid_ptr = &mid[(in_y & 1) * 128];
607
608
378k
            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
13.2k
            src += PXSTRIDE(src_stride);
617
13.2k
            in_y++;
618
13.2k
        }
619
620
409k
        for (x = 0; x < w; x++)
621
395k
            tmp[x] = FILTER_BILIN_RND2(mid1, mid2, x, dmy >> 6, 4) - PREP_BIAS;
622
623
13.5k
        my += dy;
624
13.5k
        tmp += w;
625
13.5k
    } while (--h);
626
904
}
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.90k
{
632
6.90k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
633
6.90k
    const int sh = intermediate_bits + 1;
634
6.90k
    const int rnd = (1 << intermediate_bits) + PREP_BIAS * 2;
635
207k
    do {
636
9.40M
        for (int x = 0; x < w; x++)
637
9.19M
            dst[x] = iclip_pixel((tmp1[x] + tmp2[x] + rnd) >> sh);
638
639
207k
        tmp1 += w;
640
207k
        tmp2 += w;
641
207k
        dst += PXSTRIDE(dst_stride);
642
207k
    } while (--h);
643
6.90k
}
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
813
{
649
813
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
650
813
    const int sh = intermediate_bits + 4;
651
813
    const int rnd = (8 << intermediate_bits) + PREP_BIAS * 16;
652
15.7k
    do {
653
443k
        for (int x = 0; x < w; x++)
654
427k
            dst[x] = iclip_pixel((tmp1[x] * weight +
655
427k
                                  tmp2[x] * (16 - weight) + rnd) >> sh);
656
657
15.7k
        tmp1 += w;
658
15.7k
        tmp2 += w;
659
15.7k
        dst += PXSTRIDE(dst_stride);
660
15.7k
    } while (--h);
661
813
}
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.39k
{
667
1.39k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
668
1.39k
    const int sh = intermediate_bits + 6;
669
1.39k
    const int rnd = (32 << intermediate_bits) + PREP_BIAS * 64;
670
30.1k
    do {
671
1.01M
        for (int x = 0; x < w; x++)
672
988k
            dst[x] = iclip_pixel((tmp1[x] * mask[x] +
673
988k
                                  tmp2[x] * (64 - mask[x]) + rnd) >> sh);
674
675
30.1k
        tmp1 += w;
676
30.1k
        tmp2 += w;
677
30.1k
        mask += w;
678
30.1k
        dst += PXSTRIDE(dst_stride);
679
30.1k
    } while (--h);
680
1.39k
}
681
682
2.07M
#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
3.10k
{
686
34.8k
    do {
687
513k
        for (int x = 0; x < w; x++) {
688
478k
            dst[x] = blend_px(dst[x], tmp[x], mask[x]);
689
478k
        }
690
34.8k
        dst += PXSTRIDE(dst_stride);
691
34.8k
        tmp += w;
692
34.8k
        mask += w;
693
34.8k
    } while (--h);
694
3.10k
}
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.0k
{
699
10.0k
    const uint8_t *const mask = &dav1d_obmc_masks[w];
700
128k
    do {
701
1.03M
        for (int x = 0; x < (w * 3) >> 2; x++) {
702
911k
            dst[x] = blend_px(dst[x], tmp[x], mask[x]);
703
911k
        }
704
128k
        dst += PXSTRIDE(dst_stride);
705
128k
        tmp += w;
706
128k
    } while (--h);
707
10.0k
}
708
709
static void blend_h_c(pixel *dst, const ptrdiff_t dst_stride, const pixel *tmp,
710
                      const int w, int h)
711
8.92k
{
712
8.92k
    const uint8_t *mask = &dav1d_obmc_masks[h];
713
8.92k
    h = (h * 3) >> 2;
714
43.2k
    do {
715
43.2k
        const int m = *mask++;
716
731k
        for (int x = 0; x < w; x++) {
717
688k
            dst[x] = blend_px(dst[x], tmp[x], m);
718
688k
        }
719
43.2k
        dst += PXSTRIDE(dst_stride);
720
43.2k
        tmp += w;
721
43.2k
    } while (--h);
722
8.92k
}
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
457
{
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
457
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
732
457
    const int bitdepth = bitdepth_from_max(bitdepth_max);
733
457
    const int sh = intermediate_bits + 6;
734
457
    const int rnd = (32 << intermediate_bits) + PREP_BIAS * 64;
735
457
    const int mask_sh = bitdepth + intermediate_bits - 4;
736
457
    const int mask_rnd = 1 << (mask_sh - 5);
737
17.4k
    do {
738
750k
        for (int x = 0; x < w; x++) {
739
732k
            const int tmpdiff = tmp1[x] - tmp2[x];
740
732k
            const int m = imin(38 + ((abs(tmpdiff) + mask_rnd) >> mask_sh), 64);
741
732k
            dst[x] = iclip_pixel((tmpdiff * m + tmp2[x] * 64 + rnd) >> sh);
742
743
732k
            if (ss_hor) {
744
125k
                x++;
745
746
125k
                const int tmpdiff = tmp1[x] - tmp2[x];
747
125k
                const int n = imin(38 + ((abs(tmpdiff) + mask_rnd) >> mask_sh), 64);
748
125k
                dst[x] = iclip_pixel((tmpdiff * n + tmp2[x] * 64 + rnd) >> sh);
749
750
125k
                if (h & ss_ver) {
751
61.1k
                    mask[x >> 1] = (m + n + mask[x >> 1] + 2 - sign) >> 2;
752
64.5k
                } else if (ss_ver) {
753
61.1k
                    mask[x >> 1] = m + n;
754
61.1k
                } else {
755
3.32k
                    mask[x >> 1] = (m + n + 1 - sign) >> 1;
756
3.32k
                }
757
606k
            } else {
758
606k
                mask[x] = m;
759
606k
            }
760
732k
        }
761
762
17.4k
        tmp1 += w;
763
17.4k
        tmp2 += w;
764
17.4k
        dst += PXSTRIDE(dst_stride);
765
17.4k
        if (!ss_ver || (h & 1)) mask += w >> ss_hor;
766
17.4k
    } while (--h);
767
457
}
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
457
                             const int sign HIGHBD_DECL_SUFFIX) \
774
457
{ \
775
457
    w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver \
776
457
             HIGHBD_TAIL_SUFFIX); \
777
457
}
mc_tmpl.c:w_mask_444_c
Line
Count
Source
773
235
                             const int sign HIGHBD_DECL_SUFFIX) \
774
235
{ \
775
235
    w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver \
776
235
             HIGHBD_TAIL_SUFFIX); \
777
235
}
mc_tmpl.c:w_mask_422_c
Line
Count
Source
773
29
                             const int sign HIGHBD_DECL_SUFFIX) \
774
29
{ \
775
29
    w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver \
776
29
             HIGHBD_TAIL_SUFFIX); \
777
29
}
mc_tmpl.c:w_mask_420_c
Line
Count
Source
773
193
                             const int sign HIGHBD_DECL_SUFFIX) \
774
193
{ \
775
193
    w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver \
776
193
             HIGHBD_TAIL_SUFFIX); \
777
193
}
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
11.7M
    ((F[0] * src[x - 3 * stride] + \
787
11.7M
      F[1] * src[x - 2 * stride] + \
788
11.7M
      F[2] * src[x - 1 * stride] + \
789
11.7M
      F[3] * src[x + 0 * stride] + \
790
11.7M
      F[4] * src[x + 1 * stride] + \
791
11.7M
      F[5] * src[x + 2 * stride] + \
792
11.7M
      F[6] * src[x + 3 * stride] + \
793
11.7M
      F[7] * src[x + 4 * stride] + \
794
11.7M
      ((1 << (sh)) >> 1)) >> (sh))
795
796
#define FILTER_WARP_CLIP(src, x, F, stride, sh) \
797
2.89M
    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
45.3k
{
804
45.3k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
805
45.3k
    int16_t mid[15 * 8], *mid_ptr = mid;
806
807
45.3k
    src -= 3 * PXSTRIDE(src_stride);
808
725k
    for (int y = 0; y < 15; y++, mx += abcd[1]) {
809
6.11M
        for (int x = 0, tmx = mx; x < 8; x++, tmx += abcd[0]) {
810
5.43M
            const int8_t *const filter =
811
5.43M
                dav1d_mc_warp_filter[64 + ((tmx + 512) >> 10)];
812
813
5.43M
            mid_ptr[x] = FILTER_WARP_RND(src, x, filter, 1,
814
5.43M
                                         7 - intermediate_bits);
815
5.43M
        }
816
679k
        src += PXSTRIDE(src_stride);
817
679k
        mid_ptr += 8;
818
679k
    }
819
820
45.3k
    mid_ptr = &mid[3 * 8];
821
407k
    for (int y = 0; y < 8; y++, my += abcd[3]) {
822
3.25M
        for (int x = 0, tmy = my; x < 8; x++, tmy += abcd[2]) {
823
2.89M
            const int8_t *const filter =
824
2.89M
                dav1d_mc_warp_filter[64 + ((tmy + 512) >> 10)];
825
826
2.89M
            dst[x] = FILTER_WARP_CLIP(mid_ptr, x, filter, 8,
827
2.89M
                                      7 + intermediate_bits);
828
2.89M
        }
829
362k
        mid_ptr += 8;
830
362k
        dst += PXSTRIDE(dst_stride);
831
362k
    }
832
45.3k
}
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
18.3k
{
839
18.3k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
840
18.3k
    int16_t mid[15 * 8], *mid_ptr = mid;
841
842
18.3k
    src -= 3 * PXSTRIDE(src_stride);
843
293k
    for (int y = 0; y < 15; y++, mx += abcd[1]) {
844
2.47M
        for (int x = 0, tmx = mx; x < 8; x++, tmx += abcd[0]) {
845
2.20M
            const int8_t *const filter =
846
2.20M
                dav1d_mc_warp_filter[64 + ((tmx + 512) >> 10)];
847
848
2.20M
            mid_ptr[x] = FILTER_WARP_RND(src, x, filter, 1,
849
2.20M
                                         7 - intermediate_bits);
850
2.20M
        }
851
275k
        src += PXSTRIDE(src_stride);
852
275k
        mid_ptr += 8;
853
275k
    }
854
855
18.3k
    mid_ptr = &mid[3 * 8];
856
165k
    for (int y = 0; y < 8; y++, my += abcd[3]) {
857
1.32M
        for (int x = 0, tmy = my; x < 8; x++, tmy += abcd[2]) {
858
1.17M
            const int8_t *const filter =
859
1.17M
                dav1d_mc_warp_filter[64 + ((tmy + 512) >> 10)];
860
861
1.17M
            tmp[x] = FILTER_WARP_RND(mid_ptr, x, filter, 8, 7) - PREP_BIAS;
862
1.17M
        }
863
146k
        mid_ptr += 8;
864
146k
        tmp += tmp_stride;
865
146k
    }
866
18.3k
}
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
121k
{
874
    // find offset in reference of visible block to copy
875
121k
    ref += iclip((int) y, 0, (int) ih - 1) * PXSTRIDE(ref_stride) +
876
121k
           iclip((int) x, 0, (int) iw - 1);
877
878
    // number of pixels to extend (left, right, top, bottom)
879
121k
    const int left_ext = iclip((int) -x, 0, (int) bw - 1);
880
121k
    const int right_ext = iclip((int) (x + bw - iw), 0, (int) bw - 1);
881
121k
    assert(left_ext + right_ext < bw);
882
121k
    const int top_ext = iclip((int) -y, 0, (int) bh - 1);
883
121k
    const int bottom_ext = iclip((int) (y + bh - ih), 0, (int) bh - 1);
884
121k
    assert(top_ext + bottom_ext < bh);
885
886
    // copy visible portion first
887
121k
    pixel *blk = dst + top_ext * PXSTRIDE(dst_stride);
888
121k
    const int center_w = (int) (bw - left_ext - right_ext);
889
121k
    const int center_h = (int) (bh - top_ext - bottom_ext);
890
1.84M
    for (int y = 0; y < center_h; y++) {
891
1.72M
        pixel_copy(blk + left_ext, ref, center_w);
892
        // extend left edge for this line
893
1.72M
        if (left_ext)
894
215k
            pixel_set(blk, blk[left_ext], left_ext);
895
        // extend right edge for this line
896
1.72M
        if (right_ext)
897
1.22M
            pixel_set(blk + left_ext + center_w, blk[left_ext + center_w - 1],
898
1.22M
                      right_ext);
899
1.72M
        ref += PXSTRIDE(ref_stride);
900
1.72M
        blk += PXSTRIDE(dst_stride);
901
1.72M
    }
902
903
    // copy top
904
121k
    blk = dst + top_ext * PXSTRIDE(dst_stride);
905
339k
    for (int y = 0; y < top_ext; y++) {
906
217k
        pixel_copy(dst, blk, bw);
907
217k
        dst += PXSTRIDE(dst_stride);
908
217k
    }
909
910
    // copy bottom
911
121k
    dst += center_h * PXSTRIDE(dst_stride);
912
897k
    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
121k
}
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
13.2k
{
923
507k
    do {
924
507k
        int mx = mx0, src_x = -1;
925
46.0M
        for (int x = 0; x < dst_w; x++) {
926
45.5M
            const int8_t *const F = dav1d_resize_filter[mx >> 8];
927
45.5M
            dst[x] = iclip_pixel((-(F[0] * src[iclip(src_x - 3, 0, src_w - 1)] +
928
45.5M
                                    F[1] * src[iclip(src_x - 2, 0, src_w - 1)] +
929
45.5M
                                    F[2] * src[iclip(src_x - 1, 0, src_w - 1)] +
930
45.5M
                                    F[3] * src[iclip(src_x + 0, 0, src_w - 1)] +
931
45.5M
                                    F[4] * src[iclip(src_x + 1, 0, src_w - 1)] +
932
45.5M
                                    F[5] * src[iclip(src_x + 2, 0, src_w - 1)] +
933
45.5M
                                    F[6] * src[iclip(src_x + 3, 0, src_w - 1)] +
934
45.5M
                                    F[7] * src[iclip(src_x + 4, 0, src_w - 1)]) +
935
45.5M
                                  64) >> 7);
936
45.5M
            mx += dx;
937
45.5M
            src_x += mx >> 14;
938
45.5M
            mx &= 0x3fff;
939
45.5M
        }
940
941
507k
        dst += PXSTRIDE(dst_stride);
942
507k
        src += PXSTRIDE(src_stride);
943
507k
    } while (--h);
944
13.2k
}
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
15.8k
COLD void bitfn(dav1d_mc_dsp_init)(Dav1dMCDSPContext *const c) {
961
158k
#define init_mc_fns(type, name) do { \
962
158k
    c->mc        [type] = put_##name##_c; \
963
158k
    c->mc_scaled [type] = put_##name##_scaled_c; \
964
158k
    c->mct       [type] = prep_##name##_c; \
965
158k
    c->mct_scaled[type] = prep_##name##_scaled_c; \
966
158k
} while (0)
967
968
15.8k
    init_mc_fns(FILTER_2D_8TAP_REGULAR,        8tap_regular);
969
15.8k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SMOOTH, 8tap_regular_smooth);
970
15.8k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SHARP,  8tap_regular_sharp);
971
15.8k
    init_mc_fns(FILTER_2D_8TAP_SHARP_REGULAR,  8tap_sharp_regular);
972
15.8k
    init_mc_fns(FILTER_2D_8TAP_SHARP_SMOOTH,   8tap_sharp_smooth);
973
15.8k
    init_mc_fns(FILTER_2D_8TAP_SHARP,          8tap_sharp);
974
15.8k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_REGULAR, 8tap_smooth_regular);
975
15.8k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH,         8tap_smooth);
976
15.8k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_SHARP,   8tap_smooth_sharp);
977
15.8k
    init_mc_fns(FILTER_2D_BILINEAR,            bilin);
978
979
15.8k
    c->avg      = avg_c;
980
15.8k
    c->w_avg    = w_avg_c;
981
15.8k
    c->mask     = mask_c;
982
15.8k
    c->blend    = blend_c;
983
15.8k
    c->blend_v  = blend_v_c;
984
15.8k
    c->blend_h  = blend_h_c;
985
15.8k
    c->w_mask[0] = w_mask_444_c;
986
15.8k
    c->w_mask[1] = w_mask_422_c;
987
15.8k
    c->w_mask[2] = w_mask_420_c;
988
15.8k
    c->warp8x8  = warp_affine_8x8_c;
989
15.8k
    c->warp8x8t = warp_affine_8x8t_c;
990
15.8k
    c->emu_edge = emu_edge_c;
991
15.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
15.8k
}
dav1d_mc_dsp_init_8bpc
Line
Count
Source
960
7.70k
COLD void bitfn(dav1d_mc_dsp_init)(Dav1dMCDSPContext *const c) {
961
7.70k
#define init_mc_fns(type, name) do { \
962
7.70k
    c->mc        [type] = put_##name##_c; \
963
7.70k
    c->mc_scaled [type] = put_##name##_scaled_c; \
964
7.70k
    c->mct       [type] = prep_##name##_c; \
965
7.70k
    c->mct_scaled[type] = prep_##name##_scaled_c; \
966
7.70k
} while (0)
967
968
7.70k
    init_mc_fns(FILTER_2D_8TAP_REGULAR,        8tap_regular);
969
7.70k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SMOOTH, 8tap_regular_smooth);
970
7.70k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SHARP,  8tap_regular_sharp);
971
7.70k
    init_mc_fns(FILTER_2D_8TAP_SHARP_REGULAR,  8tap_sharp_regular);
972
7.70k
    init_mc_fns(FILTER_2D_8TAP_SHARP_SMOOTH,   8tap_sharp_smooth);
973
7.70k
    init_mc_fns(FILTER_2D_8TAP_SHARP,          8tap_sharp);
974
7.70k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_REGULAR, 8tap_smooth_regular);
975
7.70k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH,         8tap_smooth);
976
7.70k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_SHARP,   8tap_smooth_sharp);
977
7.70k
    init_mc_fns(FILTER_2D_BILINEAR,            bilin);
978
979
7.70k
    c->avg      = avg_c;
980
7.70k
    c->w_avg    = w_avg_c;
981
7.70k
    c->mask     = mask_c;
982
7.70k
    c->blend    = blend_c;
983
7.70k
    c->blend_v  = blend_v_c;
984
7.70k
    c->blend_h  = blend_h_c;
985
7.70k
    c->w_mask[0] = w_mask_444_c;
986
7.70k
    c->w_mask[1] = w_mask_422_c;
987
7.70k
    c->w_mask[2] = w_mask_420_c;
988
7.70k
    c->warp8x8  = warp_affine_8x8_c;
989
7.70k
    c->warp8x8t = warp_affine_8x8t_c;
990
7.70k
    c->emu_edge = emu_edge_c;
991
7.70k
    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
7.70k
}
dav1d_mc_dsp_init_16bpc
Line
Count
Source
960
8.19k
COLD void bitfn(dav1d_mc_dsp_init)(Dav1dMCDSPContext *const c) {
961
8.19k
#define init_mc_fns(type, name) do { \
962
8.19k
    c->mc        [type] = put_##name##_c; \
963
8.19k
    c->mc_scaled [type] = put_##name##_scaled_c; \
964
8.19k
    c->mct       [type] = prep_##name##_c; \
965
8.19k
    c->mct_scaled[type] = prep_##name##_scaled_c; \
966
8.19k
} while (0)
967
968
8.19k
    init_mc_fns(FILTER_2D_8TAP_REGULAR,        8tap_regular);
969
8.19k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SMOOTH, 8tap_regular_smooth);
970
8.19k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SHARP,  8tap_regular_sharp);
971
8.19k
    init_mc_fns(FILTER_2D_8TAP_SHARP_REGULAR,  8tap_sharp_regular);
972
8.19k
    init_mc_fns(FILTER_2D_8TAP_SHARP_SMOOTH,   8tap_sharp_smooth);
973
8.19k
    init_mc_fns(FILTER_2D_8TAP_SHARP,          8tap_sharp);
974
8.19k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_REGULAR, 8tap_smooth_regular);
975
8.19k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH,         8tap_smooth);
976
8.19k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_SHARP,   8tap_smooth_sharp);
977
8.19k
    init_mc_fns(FILTER_2D_BILINEAR,            bilin);
978
979
8.19k
    c->avg      = avg_c;
980
8.19k
    c->w_avg    = w_avg_c;
981
8.19k
    c->mask     = mask_c;
982
8.19k
    c->blend    = blend_c;
983
8.19k
    c->blend_v  = blend_v_c;
984
8.19k
    c->blend_h  = blend_h_c;
985
8.19k
    c->w_mask[0] = w_mask_444_c;
986
8.19k
    c->w_mask[1] = w_mask_422_c;
987
8.19k
    c->w_mask[2] = w_mask_420_c;
988
8.19k
    c->warp8x8  = warp_affine_8x8_c;
989
8.19k
    c->warp8x8t = warp_affine_8x8t_c;
990
8.19k
    c->emu_edge = emu_edge_c;
991
8.19k
    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.19k
}