Coverage Report

Created: 2026-12-01 06:50

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/dav1d/src/mc_tmpl.c
Line
Count
Source
1
/*
2
 * Copyright © 2018, VideoLAN and dav1d authors
3
 * Copyright © 2018, Two Orioles, LLC
4
 * All rights reserved.
5
 *
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions are met:
8
 *
9
 * 1. Redistributions of source code must retain the above copyright notice, this
10
 *    list of conditions and the following disclaimer.
11
 *
12
 * 2. Redistributions in binary form must reproduce the above copyright notice,
13
 *    this list of conditions and the following disclaimer in the documentation
14
 *    and/or other materials provided with the distribution.
15
 *
16
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
 */
27
28
#include "config.h"
29
30
#include <stdlib.h>
31
#include <string.h>
32
33
#include "common/attributes.h"
34
#include "common/intops.h"
35
36
#include "src/mc.h"
37
#include "src/tables.h"
38
39
#if BITDEPTH == 8
40
1.24M
#define get_intermediate_bits(bitdepth_max) 4
41
// Output in interval [-5132, 9212], fits in int16_t as is
42
133M
#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
92.1k
{
55
1.45M
    do {
56
1.45M
        pixel_copy(dst, src, w);
57
58
1.45M
        dst += dst_stride;
59
1.45M
        src += src_stride;
60
1.45M
    } while (--h);
61
92.1k
}
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
9.93k
{
67
9.93k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
68
145k
    do {
69
2.44M
        for (int x = 0; x < w; x++)
70
2.30M
            tmp[x] = (src[x] << intermediate_bits) - PREP_BIAS;
71
72
145k
        tmp += w;
73
145k
        src += src_stride;
74
145k
    } while (--h);
75
9.93k
}
76
77
#define FILTER_8TAP(src, x, F, stride) \
78
164M
    (F[0] * src[x + -3 * stride] + \
79
164M
     F[1] * src[x + -2 * stride] + \
80
164M
     F[2] * src[x + -1 * stride] + \
81
164M
     F[3] * src[x + +0 * stride] + \
82
164M
     F[4] * src[x + +1 * stride] + \
83
164M
     F[5] * src[x + +2 * stride] + \
84
164M
     F[6] * src[x + +3 * stride] + \
85
164M
     F[7] * src[x + +4 * stride])
86
87
#define FILTER_8TAP2(src, x, F) \
88
239M
    (F[0] * src[0][x] + \
89
239M
     F[1] * src[1][x] + \
90
239M
     F[2] * src[2][x] + \
91
239M
     F[3] * src[3][x] + \
92
239M
     F[4] * src[4][x] + \
93
239M
     F[5] * src[5][x] + \
94
239M
     F[6] * src[6][x] + \
95
239M
     F[7] * src[7][x])
96
97
#define DAV1D_FILTER_8TAP_RND(src, x, F, stride, sh) \
98
163M
    ((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.03M
    ((FILTER_8TAP(src, x, F, stride) + (rnd)) >> (sh))
102
103
#define DAV1D_FILTER_8TAP_RND3(src, x, F, sh) \
104
239M
    ((FILTER_8TAP2(src, x, F) + ((1 << (sh)) >> 1)) >> (sh))
105
106
#define DAV1D_FILTER_8TAP_CLIP(src, x, F, stride, sh) \
107
3.23M
    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.03M
    iclip_pixel(DAV1D_FILTER_8TAP_RND2(src, x, F, stride, rnd, sh))
111
112
#define DAV1D_FILTER_8TAP_CLIP3(src, x, F, sh) \
113
137M
    iclip_pixel(DAV1D_FILTER_8TAP_RND3(src, x, F, sh))
114
115
#define GET_H_FILTER(mx) \
116
163M
    const int8_t *const fh = !(mx) ? NULL : w > 4 ? \
117
153M
        dav1d_mc_subpel_filters[filter_type & 3][(mx) - 1] : \
118
153M
        dav1d_mc_subpel_filters[3 + (filter_type & 1)][(mx) - 1]
119
120
#define GET_V_FILTER(my) \
121
10.3M
    const int8_t *const fv = !(my) ? NULL : h > 4 ? \
122
9.47M
        dav1d_mc_subpel_filters[filter_type >> 2][(my) - 1] : \
123
9.47M
        dav1d_mc_subpel_filters[3 + ((filter_type >> 2) & 1)][(my) - 1]
124
125
#define GET_FILTERS() \
126
72.4k
    GET_H_FILTER(mx); \
127
72.4k
    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
52.7k
{
135
52.7k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
136
52.7k
    const int intermediate_rnd = 32 + ((1 << (6 - intermediate_bits)) >> 1);
137
138
52.7k
    GET_FILTERS();
139
52.7k
    dst_stride = PXSTRIDE(dst_stride);
140
52.7k
    src_stride = PXSTRIDE(src_stride);
141
142
52.7k
    if (fh) {
143
23.4k
        if (fv) {
144
15.2k
            int tmp_h = h + 7;
145
15.2k
            int16_t mid[128 * 135], *mid_ptr = mid;
146
147
15.2k
            src -= src_stride * 3;
148
232k
            do {
149
2.96M
                for (int x = 0; x < w; x++)
150
2.73M
                    mid_ptr[x] = DAV1D_FILTER_8TAP_RND(src, x, fh, 1,
151
232k
                                                       6 - intermediate_bits);
152
153
232k
                mid_ptr += 128;
154
232k
                src += src_stride;
155
232k
            } while (--tmp_h);
156
157
15.2k
            mid_ptr = mid + 128 * 3;
158
127k
            do {
159
2.03M
                for (int x = 0; x < w; x++)
160
1.90M
                    dst[x] = DAV1D_FILTER_8TAP_CLIP(mid_ptr, x, fv, 128,
161
127k
                                                    6 + intermediate_bits);
162
163
127k
                mid_ptr += 128;
164
127k
                dst += dst_stride;
165
127k
            } while (--h);
166
15.2k
        } else {
167
76.9k
            do {
168
1.11M
                for (int x = 0; x < w; x++) {
169
1.03M
                    dst[x] = DAV1D_FILTER_8TAP_CLIP2(src, x, fh, 1,
170
1.03M
                                                     intermediate_rnd, 6);
171
1.03M
                }
172
173
76.9k
                dst += dst_stride;
174
76.9k
                src += src_stride;
175
76.9k
            } while (--h);
176
8.17k
        }
177
29.3k
    } else if (fv) {
178
83.0k
        do {
179
1.41M
            for (int x = 0; x < w; x++)
180
1.32M
                dst[x] = DAV1D_FILTER_8TAP_CLIP(src, x, fv, src_stride, 6);
181
182
83.0k
            dst += dst_stride;
183
83.0k
            src += src_stride;
184
83.0k
        } while (--h);
185
9.10k
    } else
186
20.2k
        put_c(dst, dst_stride, src, src_stride, w, h);
187
52.7k
}
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
639k
{
196
639k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
197
639k
    const int intermediate_rnd = (1 << intermediate_bits) >> 1;
198
639k
    int16_t mid[128 * 8];
199
639k
    int16_t *mid_ptrs[8];
200
639k
    int in_y = -8;
201
639k
    src_stride = PXSTRIDE(src_stride);
202
203
5.75M
    for (int i = 0; i < 8; i++)
204
5.11M
        mid_ptrs[i] = &mid[128 * i];
205
206
639k
    src -= src_stride * 3;
207
208
7.11M
    for (int y = 0; y < h; y++) {
209
6.47M
        int x;
210
6.47M
        int src_y = my >> 10;
211
6.47M
        GET_V_FILTER((my & 0x3ff) >> 6);
212
213
13.8M
        while (in_y < src_y) {
214
7.41M
            int imx = mx, ioff = 0;
215
7.41M
            int16_t *mid_ptr = mid_ptrs[0];
216
217
59.3M
            for (int i = 0; i < 7; i++)
218
51.9M
                mid_ptrs[i] = mid_ptrs[i + 1];
219
7.41M
            mid_ptrs[7] = mid_ptr;
220
221
111M
            for (x = 0; x < w; x++) {
222
103M
                GET_H_FILTER(imx >> 6);
223
103M
                mid_ptr[x] = fh ? DAV1D_FILTER_8TAP_RND(src, ioff, fh, 1,
224
103M
                                                        6 - intermediate_bits) :
225
103M
                                  src[ioff] << intermediate_bits;
226
103M
                imx += dx;
227
103M
                ioff += imx >> 10;
228
103M
                imx &= 0x3ff;
229
103M
            }
230
231
7.41M
            src += src_stride;
232
7.41M
            in_y++;
233
7.41M
        }
234
235
156M
        for (x = 0; x < w; x++)
236
149M
            dst[x] = fv ? DAV1D_FILTER_8TAP_CLIP3(mid_ptrs, x, fv,
237
149M
                                                  6 + intermediate_bits) :
238
149M
                          iclip_pixel((mid_ptrs[3][x] + intermediate_rnd) >>
239
12.4M
                                              intermediate_bits);
240
241
6.47M
        my += dy;
242
6.47M
        dst += PXSTRIDE(dst_stride);
243
6.47M
    }
244
639k
}
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
19.7k
{
251
19.7k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
252
19.7k
    GET_FILTERS();
253
19.7k
    src_stride = PXSTRIDE(src_stride);
254
255
19.7k
    if (fh) {
256
9.28k
        if (fv) {
257
6.38k
            int tmp_h = h + 7;
258
6.38k
            int16_t mid[128 * 135], *mid_ptr = mid;
259
260
6.38k
            src -= src_stride * 3;
261
111k
            do {
262
1.77M
                for (int x = 0; x < w; x++)
263
1.66M
                    mid_ptr[x] = DAV1D_FILTER_8TAP_RND(src, x, fh, 1,
264
111k
                                                       6 - intermediate_bits);
265
266
111k
                mid_ptr += 128;
267
111k
                src += src_stride;
268
111k
            } while (--tmp_h);
269
270
6.38k
            mid_ptr = mid + 128 * 3;
271
66.8k
            do {
272
1.29M
                for (int x = 0; x < w; x++) {
273
1.22M
                    int t = DAV1D_FILTER_8TAP_RND(mid_ptr, x, fv, 128, 6) -
274
1.22M
                                  PREP_BIAS;
275
1.22M
                    assert(t >= INT16_MIN && t <= INT16_MAX);
276
1.22M
                    tmp[x] = t;
277
1.22M
                }
278
279
66.8k
                mid_ptr += 128;
280
66.8k
                tmp += w;
281
66.8k
            } while (--h);
282
6.38k
        } else {
283
44.1k
            do {
284
948k
                for (int x = 0; x < w; x++)
285
904k
                    tmp[x] = DAV1D_FILTER_8TAP_RND(src, x, fh, 1,
286
904k
                                                   6 - intermediate_bits) -
287
904k
                             PREP_BIAS;
288
289
44.1k
                tmp += w;
290
44.1k
                src += src_stride;
291
44.1k
            } while (--h);
292
2.89k
        }
293
10.4k
    } else if (fv) {
294
37.7k
        do {
295
517k
            for (int x = 0; x < w; x++)
296
479k
                tmp[x] = DAV1D_FILTER_8TAP_RND(src, x, fv, src_stride,
297
479k
                                               6 - intermediate_bits) -
298
479k
                         PREP_BIAS;
299
300
37.7k
            tmp += w;
301
37.7k
            src += src_stride;
302
37.7k
        } while (--h);
303
3.67k
    } else
304
6.77k
        prep_c(tmp, src, src_stride, w, h HIGHBD_TAIL_SUFFIX);
305
19.7k
}
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
219k
{
313
219k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
314
219k
    int16_t mid[128 * 8];
315
219k
    int16_t *mid_ptrs[8];
316
219k
    int in_y = -8;
317
219k
    src_stride = PXSTRIDE(src_stride);
318
319
1.97M
    for (int i = 0; i < 8; i++)
320
1.75M
        mid_ptrs[i] = &mid[128 * i];
321
322
219k
    src -= src_stride * 3;
323
324
4.00M
    for (int y = 0; y < h; y++) {
325
3.78M
        int x;
326
3.78M
        int src_y = my >> 10;
327
3.78M
        GET_V_FILTER((my & 0x3ff) >> 6);
328
329
6.84M
        while (in_y < src_y) {
330
3.05M
            int imx = mx, ioff = 0;
331
3.05M
            int16_t *mid_ptr = mid_ptrs[0];
332
333
24.4M
            for (int i = 0; i < 7; i++)
334
21.3M
                mid_ptrs[i] = mid_ptrs[i + 1];
335
3.05M
            mid_ptrs[7] = mid_ptr;
336
337
63.0M
            for (x = 0; x < w; x++) {
338
59.9M
                GET_H_FILTER(imx >> 6);
339
59.9M
                mid_ptr[x] = fh ? DAV1D_FILTER_8TAP_RND(src, ioff, fh, 1,
340
59.9M
                                                        6 - intermediate_bits) :
341
59.9M
                                  src[ioff] << intermediate_bits;
342
59.9M
                imx += dx;
343
59.9M
                ioff += imx >> 10;
344
59.9M
                imx &= 0x3ff;
345
59.9M
            }
346
347
3.05M
            src += src_stride;
348
3.05M
            in_y++;
349
3.05M
        }
350
351
113M
        for (x = 0; x < w; x++)
352
109M
            tmp[x] = (fv ? DAV1D_FILTER_8TAP_RND3(mid_ptrs, x, fv, 6)
353
109M
                         : mid_ptrs[3][x]) - PREP_BIAS;
354
355
3.78M
        my += dy;
356
3.78M
        tmp += w;
357
3.78M
    }
358
219k
}
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
52.7k
                                HIGHBD_DECL_SUFFIX) \
368
52.7k
{ \
369
52.7k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
52.7k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
52.7k
} \
mc_tmpl.c:put_8tap_regular_c
Line
Count
Source
367
37.3k
                                HIGHBD_DECL_SUFFIX) \
368
37.3k
{ \
369
37.3k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
37.3k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
37.3k
} \
mc_tmpl.c:put_8tap_regular_smooth_c
Line
Count
Source
367
1.33k
                                HIGHBD_DECL_SUFFIX) \
368
1.33k
{ \
369
1.33k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
1.33k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
1.33k
} \
mc_tmpl.c:put_8tap_regular_sharp_c
Line
Count
Source
367
230
                                HIGHBD_DECL_SUFFIX) \
368
230
{ \
369
230
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
230
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
230
} \
mc_tmpl.c:put_8tap_sharp_regular_c
Line
Count
Source
367
464
                                HIGHBD_DECL_SUFFIX) \
368
464
{ \
369
464
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
464
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
464
} \
mc_tmpl.c:put_8tap_sharp_smooth_c
Line
Count
Source
367
175
                                HIGHBD_DECL_SUFFIX) \
368
175
{ \
369
175
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
175
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
175
} \
mc_tmpl.c:put_8tap_sharp_c
Line
Count
Source
367
4.11k
                                HIGHBD_DECL_SUFFIX) \
368
4.11k
{ \
369
4.11k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
4.11k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
4.11k
} \
mc_tmpl.c:put_8tap_smooth_regular_c
Line
Count
Source
367
2.08k
                                HIGHBD_DECL_SUFFIX) \
368
2.08k
{ \
369
2.08k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
2.08k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
2.08k
} \
mc_tmpl.c:put_8tap_smooth_c
Line
Count
Source
367
6.76k
                                HIGHBD_DECL_SUFFIX) \
368
6.76k
{ \
369
6.76k
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
6.76k
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
6.76k
} \
mc_tmpl.c:put_8tap_smooth_sharp_c
Line
Count
Source
367
270
                                HIGHBD_DECL_SUFFIX) \
368
270
{ \
369
270
    put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
370
270
               type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
371
270
} \
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
639k
                                       HIGHBD_DECL_SUFFIX) \
380
639k
{ \
381
639k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
639k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
639k
} \
mc_tmpl.c:put_8tap_regular_scaled_c
Line
Count
Source
379
572k
                                       HIGHBD_DECL_SUFFIX) \
380
572k
{ \
381
572k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
572k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
572k
} \
mc_tmpl.c:put_8tap_regular_smooth_scaled_c
Line
Count
Source
379
10.5k
                                       HIGHBD_DECL_SUFFIX) \
380
10.5k
{ \
381
10.5k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
10.5k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
10.5k
} \
mc_tmpl.c:put_8tap_regular_sharp_scaled_c
Line
Count
Source
379
2.07k
                                       HIGHBD_DECL_SUFFIX) \
380
2.07k
{ \
381
2.07k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
2.07k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
2.07k
} \
mc_tmpl.c:put_8tap_sharp_regular_scaled_c
Line
Count
Source
379
4.83k
                                       HIGHBD_DECL_SUFFIX) \
380
4.83k
{ \
381
4.83k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
4.83k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
4.83k
} \
mc_tmpl.c:put_8tap_sharp_smooth_scaled_c
Line
Count
Source
379
1.27k
                                       HIGHBD_DECL_SUFFIX) \
380
1.27k
{ \
381
1.27k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
1.27k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
1.27k
} \
mc_tmpl.c:put_8tap_sharp_scaled_c
Line
Count
Source
379
12.9k
                                       HIGHBD_DECL_SUFFIX) \
380
12.9k
{ \
381
12.9k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
12.9k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
12.9k
} \
mc_tmpl.c:put_8tap_smooth_regular_scaled_c
Line
Count
Source
379
20.6k
                                       HIGHBD_DECL_SUFFIX) \
380
20.6k
{ \
381
20.6k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
20.6k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
20.6k
} \
mc_tmpl.c:put_8tap_smooth_scaled_c
Line
Count
Source
379
12.8k
                                       HIGHBD_DECL_SUFFIX) \
380
12.8k
{ \
381
12.8k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
12.8k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
12.8k
} \
mc_tmpl.c:put_8tap_smooth_sharp_scaled_c
Line
Count
Source
379
1.64k
                                       HIGHBD_DECL_SUFFIX) \
380
1.64k
{ \
381
1.64k
    put_8tap_scaled_c(dst, dst_stride, src, src_stride, w, h, mx, my, dx, dy, \
382
1.64k
                      type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
383
1.64k
} \
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
19.7k
                                 HIGHBD_DECL_SUFFIX) \
390
19.7k
{ \
391
19.7k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
19.7k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
19.7k
} \
mc_tmpl.c:prep_8tap_regular_c
Line
Count
Source
389
12.5k
                                 HIGHBD_DECL_SUFFIX) \
390
12.5k
{ \
391
12.5k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
12.5k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
12.5k
} \
mc_tmpl.c:prep_8tap_regular_smooth_c
Line
Count
Source
389
270
                                 HIGHBD_DECL_SUFFIX) \
390
270
{ \
391
270
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
270
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
270
} \
mc_tmpl.c:prep_8tap_regular_sharp_c
Line
Count
Source
389
424
                                 HIGHBD_DECL_SUFFIX) \
390
424
{ \
391
424
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
424
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
424
} \
mc_tmpl.c:prep_8tap_sharp_regular_c
Line
Count
Source
389
745
                                 HIGHBD_DECL_SUFFIX) \
390
745
{ \
391
745
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
745
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
745
} \
mc_tmpl.c:prep_8tap_sharp_smooth_c
Line
Count
Source
389
252
                                 HIGHBD_DECL_SUFFIX) \
390
252
{ \
391
252
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
252
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
252
} \
mc_tmpl.c:prep_8tap_sharp_c
Line
Count
Source
389
2.19k
                                 HIGHBD_DECL_SUFFIX) \
390
2.19k
{ \
391
2.19k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
2.19k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
2.19k
} \
mc_tmpl.c:prep_8tap_smooth_regular_c
Line
Count
Source
389
886
                                 HIGHBD_DECL_SUFFIX) \
390
886
{ \
391
886
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
886
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
886
} \
mc_tmpl.c:prep_8tap_smooth_c
Line
Count
Source
389
2.09k
                                 HIGHBD_DECL_SUFFIX) \
390
2.09k
{ \
391
2.09k
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
2.09k
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
2.09k
} \
mc_tmpl.c:prep_8tap_smooth_sharp_c
Line
Count
Source
389
357
                                 HIGHBD_DECL_SUFFIX) \
390
357
{ \
391
357
    prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
392
357
                type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
393
357
} \
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
219k
                                        HIGHBD_DECL_SUFFIX) \
401
219k
{ \
402
219k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
219k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
219k
}
mc_tmpl.c:prep_8tap_regular_scaled_c
Line
Count
Source
400
159k
                                        HIGHBD_DECL_SUFFIX) \
401
159k
{ \
402
159k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
159k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
159k
}
mc_tmpl.c:prep_8tap_regular_smooth_scaled_c
Line
Count
Source
400
4.75k
                                        HIGHBD_DECL_SUFFIX) \
401
4.75k
{ \
402
4.75k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
4.75k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
4.75k
}
mc_tmpl.c:prep_8tap_regular_sharp_scaled_c
Line
Count
Source
400
8.45k
                                        HIGHBD_DECL_SUFFIX) \
401
8.45k
{ \
402
8.45k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
8.45k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
8.45k
}
mc_tmpl.c:prep_8tap_sharp_regular_scaled_c
Line
Count
Source
400
14.4k
                                        HIGHBD_DECL_SUFFIX) \
401
14.4k
{ \
402
14.4k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
14.4k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
14.4k
}
mc_tmpl.c:prep_8tap_sharp_smooth_scaled_c
Line
Count
Source
400
2.10k
                                        HIGHBD_DECL_SUFFIX) \
401
2.10k
{ \
402
2.10k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
2.10k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
2.10k
}
mc_tmpl.c:prep_8tap_sharp_scaled_c
Line
Count
Source
400
11.0k
                                        HIGHBD_DECL_SUFFIX) \
401
11.0k
{ \
402
11.0k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
11.0k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
11.0k
}
mc_tmpl.c:prep_8tap_smooth_regular_scaled_c
Line
Count
Source
400
11.4k
                                        HIGHBD_DECL_SUFFIX) \
401
11.4k
{ \
402
11.4k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
11.4k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
11.4k
}
mc_tmpl.c:prep_8tap_smooth_scaled_c
Line
Count
Source
400
3.68k
                                        HIGHBD_DECL_SUFFIX) \
401
3.68k
{ \
402
3.68k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
3.68k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
3.68k
}
mc_tmpl.c:prep_8tap_smooth_sharp_scaled_c
Line
Count
Source
400
3.82k
                                        HIGHBD_DECL_SUFFIX) \
401
3.82k
{ \
402
3.82k
    prep_8tap_scaled_c(tmp, src, src_stride, w, h, mx, my, dx, dy, \
403
3.82k
                       type_h | (type_v << 2) HIGHBD_TAIL_SUFFIX); \
404
3.82k
}
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
15.0M
    (16 * src[x] + ((mxy) * (src[x + stride] - src[x])))
418
419
#define FILTER_BILIN_RND(src, x, mxy, stride, sh) \
420
15.0M
    ((FILTER_BILIN(src, x, mxy, stride) + ((1 << (sh)) >> 1)) >> (sh))
421
422
#define FILTER_BILIN_CLIP(src, x, mxy, stride, sh) \
423
2.74M
    iclip_pixel(FILTER_BILIN_RND(src, x, mxy, stride, sh))
424
425
#define FILTER_BILIN2(src1, src2, x, mxy) \
426
20.4M
    (16 * src1[x] + ((mxy) * (src2[x] - src1[x])))
427
428
#define FILTER_BILIN_RND2(src1, src2, x, mxy, sh) \
429
20.4M
    ((FILTER_BILIN2(src1, src2, x, mxy) + ((1 << (sh)) >> 1)) >> (sh))
430
431
#define FILTER_BILIN_CLIP2(src1, src2, x, mxy, sh) \
432
3.71M
    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
103k
{
439
103k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
440
103k
    const int intermediate_rnd = (1 << intermediate_bits) >> 1;
441
103k
    dst_stride = PXSTRIDE(dst_stride);
442
103k
    src_stride = PXSTRIDE(src_stride);
443
444
103k
    if (mx) {
445
21.8k
        if (my) {
446
10.8k
            int16_t mid[128 * 129], *mid_ptr = mid;
447
10.8k
            int tmp_h = h + 1;
448
449
93.6k
            do {
450
1.28M
                for (int x = 0; x < w; x++)
451
1.19M
                    mid_ptr[x] = FILTER_BILIN_RND(src, x, mx, 1,
452
93.6k
                                                  4 - intermediate_bits);
453
454
93.6k
                mid_ptr += 128;
455
93.6k
                src += src_stride;
456
93.6k
            } while (--tmp_h);
457
458
10.8k
            mid_ptr = mid;
459
82.7k
            do {
460
1.18M
                for (int x = 0; x < w; x++)
461
1.10M
                    dst[x] = FILTER_BILIN_CLIP(mid_ptr, x, my, 128,
462
82.7k
                                               4 + intermediate_bits);
463
464
82.7k
                mid_ptr += 128;
465
82.7k
                dst += dst_stride;
466
82.7k
            } while (--h);
467
11.0k
        } else {
468
102k
            do {
469
2.46M
                for (int x = 0; x < w; x++) {
470
2.36M
                    const int px = FILTER_BILIN_RND(src, x, mx, 1,
471
2.36M
                                                    4 - intermediate_bits);
472
2.36M
                    dst[x] = iclip_pixel((px + intermediate_rnd) >> intermediate_bits);
473
2.36M
                }
474
475
102k
                dst += dst_stride;
476
102k
                src += src_stride;
477
102k
            } while (--h);
478
11.0k
        }
479
81.6k
    } else if (my) {
480
87.7k
        do {
481
1.73M
            for (int x = 0; x < w; x++)
482
1.64M
                dst[x] = FILTER_BILIN_CLIP(src, x, my, src_stride, 4);
483
484
87.7k
            dst += dst_stride;
485
87.7k
            src += src_stride;
486
87.7k
        } while (--h);
487
9.79k
    } else
488
71.8k
        put_c(dst, dst_stride, src, src_stride, w, h);
489
103k
}
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
13.6k
{
497
13.6k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
498
13.6k
    int16_t mid[128 * 2];
499
13.6k
    int in_y = -2;
500
501
145k
    do {
502
145k
        int x;
503
145k
        int y = my >> 10;
504
145k
        int16_t *mid1 = &mid[(y & 1) * 128];
505
145k
        int16_t *mid2 = &mid[((y + 1) & 1) * 128];
506
145k
        int dmy = my & 0x3ff;
507
508
258k
        while (in_y < y) {
509
113k
            int imx = mx, ioff = 0;
510
113k
            int16_t *mid_ptr = &mid[(in_y & 1) * 128];
511
512
2.15M
            for (x = 0; x < w; x++) {
513
2.03M
                mid_ptr[x] = FILTER_BILIN_RND(src, ioff, imx >> 6, 1,
514
2.03M
                                              4 - intermediate_bits);
515
2.03M
                imx += dx;
516
2.03M
                ioff += imx >> 10;
517
2.03M
                imx &= 0x3ff;
518
2.03M
            }
519
520
113k
            src += PXSTRIDE(src_stride);
521
113k
            in_y++;
522
113k
        }
523
524
3.85M
        for (x = 0; x < w; x++)
525
3.71M
            dst[x] = FILTER_BILIN_CLIP2(mid1, mid2, x, dmy >> 6,
526
145k
                                       4 + intermediate_bits);
527
528
145k
        my += dy;
529
145k
        dst += PXSTRIDE(dst_stride);
530
145k
    } while (--h);
531
13.6k
}
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
10.8k
{
538
10.8k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
539
10.8k
    src_stride = PXSTRIDE(src_stride);
540
541
10.8k
    if (mx) {
542
5.37k
        if (my) {
543
3.93k
            int16_t mid[128 * 129], *mid_ptr = mid;
544
3.93k
            int tmp_h = h + 1;
545
546
46.9k
            do {
547
576k
                for (int x = 0; x < w; x++)
548
530k
                    mid_ptr[x] = FILTER_BILIN_RND(src, x, mx, 1,
549
46.9k
                                                  4 - intermediate_bits);
550
551
46.9k
                mid_ptr += 128;
552
46.9k
                src += src_stride;
553
46.9k
            } while (--tmp_h);
554
555
3.93k
            mid_ptr = mid;
556
42.9k
            do {
557
538k
                for (int x = 0; x < w; x++)
558
495k
                    tmp[x] = FILTER_BILIN_RND(mid_ptr, x, my, 128, 4) -
559
495k
                             PREP_BIAS;
560
561
42.9k
                mid_ptr += 128;
562
42.9k
                tmp += w;
563
42.9k
            } while (--h);
564
3.93k
        } else {
565
18.4k
            do {
566
411k
                for (int x = 0; x < w; x++)
567
392k
                    tmp[x] = FILTER_BILIN_RND(src, x, mx, 1,
568
392k
                                              4 - intermediate_bits) -
569
392k
                             PREP_BIAS;
570
571
18.4k
                tmp += w;
572
18.4k
                src += src_stride;
573
18.4k
            } while (--h);
574
1.44k
        }
575
5.44k
    } else if (my) {
576
21.8k
        do {
577
274k
            for (int x = 0; x < w; x++)
578
252k
                tmp[x] = FILTER_BILIN_RND(src, x, my, src_stride,
579
252k
                                          4 - intermediate_bits) - PREP_BIAS;
580
581
21.8k
            tmp += w;
582
21.8k
            src += src_stride;
583
21.8k
        } while (--h);
584
2.27k
    } else
585
3.16k
        prep_c(tmp, src, src_stride, w, h HIGHBD_TAIL_SUFFIX);
586
10.8k
}
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
8.34k
{
593
8.34k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
594
8.34k
    int16_t mid[128 * 2];
595
8.34k
    int in_y = -2;
596
597
230k
    do {
598
230k
        int x;
599
230k
        int y = my >> 10;
600
230k
        int16_t *mid1 = &mid[(y & 1) * 128];
601
230k
        int16_t *mid2 = &mid[((y + 1) & 1) * 128];
602
230k
        int dmy = my & 0x3ff;
603
604
340k
        while (in_y < y) {
605
109k
            int imx = mx, ioff = 0;
606
109k
            int16_t *mid_ptr = &mid[(in_y & 1) * 128];
607
608
5.10M
            for (x = 0; x < w; x++) {
609
4.99M
                mid_ptr[x] = FILTER_BILIN_RND(src, ioff, imx >> 6, 1,
610
4.99M
                                              4 - intermediate_bits);
611
4.99M
                imx += dx;
612
4.99M
                ioff += imx >> 10;
613
4.99M
                imx &= 0x3ff;
614
4.99M
            }
615
616
109k
            src += PXSTRIDE(src_stride);
617
109k
            in_y++;
618
109k
        }
619
620
17.0M
        for (x = 0; x < w; x++)
621
16.7M
            tmp[x] = FILTER_BILIN_RND2(mid1, mid2, x, dmy >> 6, 4) - PREP_BIAS;
622
623
230k
        my += dy;
624
230k
        tmp += w;
625
230k
    } while (--h);
626
8.34k
}
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
112k
{
632
112k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
633
112k
    const int sh = intermediate_bits + 1;
634
112k
    const int rnd = (1 << intermediate_bits) + PREP_BIAS * 2;
635
1.90M
    do {
636
59.2M
        for (int x = 0; x < w; x++)
637
57.3M
            dst[x] = iclip_pixel((tmp1[x] + tmp2[x] + rnd) >> sh);
638
639
1.90M
        tmp1 += w;
640
1.90M
        tmp2 += w;
641
1.90M
        dst += PXSTRIDE(dst_stride);
642
1.90M
    } while (--h);
643
112k
}
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
722
{
649
722
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
650
722
    const int sh = intermediate_bits + 4;
651
722
    const int rnd = (8 << intermediate_bits) + PREP_BIAS * 16;
652
13.3k
    do {
653
310k
        for (int x = 0; x < w; x++)
654
296k
            dst[x] = iclip_pixel((tmp1[x] * weight +
655
296k
                                  tmp2[x] * (16 - weight) + rnd) >> sh);
656
657
13.3k
        tmp1 += w;
658
13.3k
        tmp2 += w;
659
13.3k
        dst += PXSTRIDE(dst_stride);
660
13.3k
    } while (--h);
661
722
}
662
663
static void mask_c(pixel *dst, const ptrdiff_t dst_stride,
664
                   const int16_t *tmp1, const int16_t *tmp2, const int w, int h,
665
                   const uint8_t *mask HIGHBD_DECL_SUFFIX)
666
11.4k
{
667
11.4k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
668
11.4k
    const int sh = intermediate_bits + 6;
669
11.4k
    const int rnd = (32 << intermediate_bits) + PREP_BIAS * 64;
670
142k
    do {
671
2.91M
        for (int x = 0; x < w; x++)
672
2.76M
            dst[x] = iclip_pixel((tmp1[x] * mask[x] +
673
2.76M
                                  tmp2[x] * (64 - mask[x]) + rnd) >> sh);
674
675
142k
        tmp1 += w;
676
142k
        tmp2 += w;
677
142k
        mask += w;
678
142k
        dst += PXSTRIDE(dst_stride);
679
142k
    } while (--h);
680
11.4k
}
681
682
12.0M
#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
23.0k
{
686
190k
    do {
687
2.32M
        for (int x = 0; x < w; x++) {
688
2.13M
            dst[x] = blend_px(dst[x], tmp[x], mask[x]);
689
2.13M
        }
690
190k
        dst += PXSTRIDE(dst_stride);
691
190k
        tmp += w;
692
190k
        mask += w;
693
190k
    } while (--h);
694
23.0k
}
695
696
static void blend_v_c(pixel *dst, const ptrdiff_t dst_stride, const pixel *tmp,
697
                      const int w, int h)
698
119k
{
699
119k
    const uint8_t *const mask = &dav1d_obmc_masks[w];
700
1.08M
    do {
701
6.94M
        for (int x = 0; x < (w * 3) >> 2; x++) {
702
5.85M
            dst[x] = blend_px(dst[x], tmp[x], mask[x]);
703
5.85M
        }
704
1.08M
        dst += PXSTRIDE(dst_stride);
705
1.08M
        tmp += w;
706
1.08M
    } while (--h);
707
119k
}
708
709
static void blend_h_c(pixel *dst, const ptrdiff_t dst_stride, const pixel *tmp,
710
                      const int w, int h)
711
61.8k
{
712
61.8k
    const uint8_t *mask = &dav1d_obmc_masks[h];
713
61.8k
    h = (h * 3) >> 2;
714
300k
    do {
715
300k
        const int m = *mask++;
716
4.34M
        for (int x = 0; x < w; x++) {
717
4.04M
            dst[x] = blend_px(dst[x], tmp[x], m);
718
4.04M
        }
719
300k
        dst += PXSTRIDE(dst_stride);
720
300k
        tmp += w;
721
300k
    } while (--h);
722
61.8k
}
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
5.31k
{
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
5.31k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
732
5.31k
    const int bitdepth = bitdepth_from_max(bitdepth_max);
733
5.31k
    const int sh = intermediate_bits + 6;
734
5.31k
    const int rnd = (32 << intermediate_bits) + PREP_BIAS * 64;
735
5.31k
    const int mask_sh = bitdepth + intermediate_bits - 4;
736
5.31k
    const int mask_rnd = 1 << (mask_sh - 5);
737
143k
    do {
738
4.26M
        for (int x = 0; x < w; x++) {
739
4.12M
            const int tmpdiff = tmp1[x] - tmp2[x];
740
4.12M
            const int m = imin(38 + ((abs(tmpdiff) + mask_rnd) >> mask_sh), 64);
741
4.12M
            dst[x] = iclip_pixel((tmpdiff * m + tmp2[x] * 64 + rnd) >> sh);
742
743
4.12M
            if (ss_hor) {
744
2.10M
                x++;
745
746
2.10M
                const int tmpdiff = tmp1[x] - tmp2[x];
747
2.10M
                const int n = imin(38 + ((abs(tmpdiff) + mask_rnd) >> mask_sh), 64);
748
2.10M
                dst[x] = iclip_pixel((tmpdiff * n + tmp2[x] * 64 + rnd) >> sh);
749
750
2.10M
                if (h & ss_ver) {
751
1.04M
                    mask[x >> 1] = (m + n + mask[x >> 1] + 2 - sign) >> 2;
752
1.05M
                } else if (ss_ver) {
753
1.04M
                    mask[x >> 1] = m + n;
754
1.04M
                } else {
755
6.88k
                    mask[x >> 1] = (m + n + 1 - sign) >> 1;
756
6.88k
                }
757
2.10M
            } else {
758
2.02M
                mask[x] = m;
759
2.02M
            }
760
4.12M
        }
761
762
143k
        tmp1 += w;
763
143k
        tmp2 += w;
764
143k
        dst += PXSTRIDE(dst_stride);
765
143k
        if (!ss_ver || (h & 1)) mask += w >> ss_hor;
766
143k
    } while (--h);
767
5.31k
}
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
5.31k
                             const int sign HIGHBD_DECL_SUFFIX) \
774
5.31k
{ \
775
5.31k
    w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver \
776
5.31k
             HIGHBD_TAIL_SUFFIX); \
777
5.31k
}
mc_tmpl.c:w_mask_444_c
Line
Count
Source
773
2.50k
                             const int sign HIGHBD_DECL_SUFFIX) \
774
2.50k
{ \
775
2.50k
    w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver \
776
2.50k
             HIGHBD_TAIL_SUFFIX); \
777
2.50k
}
mc_tmpl.c:w_mask_422_c
Line
Count
Source
773
81
                             const int sign HIGHBD_DECL_SUFFIX) \
774
81
{ \
775
81
    w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver \
776
81
             HIGHBD_TAIL_SUFFIX); \
777
81
}
mc_tmpl.c:w_mask_420_c
Line
Count
Source
773
2.72k
                             const int sign HIGHBD_DECL_SUFFIX) \
774
2.72k
{ \
775
2.72k
    w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver \
776
2.72k
             HIGHBD_TAIL_SUFFIX); \
777
2.72k
}
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
7.73M
    ((F[0] * src[x - 3 * stride] + \
787
7.73M
      F[1] * src[x - 2 * stride] + \
788
7.73M
      F[2] * src[x - 1 * stride] + \
789
7.73M
      F[3] * src[x + 0 * stride] + \
790
7.73M
      F[4] * src[x + 1 * stride] + \
791
7.73M
      F[5] * src[x + 2 * stride] + \
792
7.73M
      F[6] * src[x + 3 * stride] + \
793
7.73M
      F[7] * src[x + 4 * stride] + \
794
7.73M
      ((1 << (sh)) >> 1)) >> (sh))
795
796
#define FILTER_WARP_CLIP(src, x, F, stride, sh) \
797
2.25M
    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
35.1k
{
804
35.1k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
805
35.1k
    int16_t mid[15 * 8], *mid_ptr = mid;
806
807
35.1k
    src -= 3 * PXSTRIDE(src_stride);
808
562k
    for (int y = 0; y < 15; y++, mx += abcd[1]) {
809
4.74M
        for (int x = 0, tmx = mx; x < 8; x++, tmx += abcd[0]) {
810
4.22M
            const int8_t *const filter =
811
4.22M
                dav1d_mc_warp_filter[64 + ((tmx + 512) >> 10)];
812
813
4.22M
            mid_ptr[x] = FILTER_WARP_RND(src, x, filter, 1,
814
4.22M
                                         7 - intermediate_bits);
815
4.22M
        }
816
527k
        src += PXSTRIDE(src_stride);
817
527k
        mid_ptr += 8;
818
527k
    }
819
820
35.1k
    mid_ptr = &mid[3 * 8];
821
316k
    for (int y = 0; y < 8; y++, my += abcd[3]) {
822
2.53M
        for (int x = 0, tmy = my; x < 8; x++, tmy += abcd[2]) {
823
2.25M
            const int8_t *const filter =
824
2.25M
                dav1d_mc_warp_filter[64 + ((tmy + 512) >> 10)];
825
826
2.25M
            dst[x] = FILTER_WARP_CLIP(mid_ptr, x, filter, 8,
827
2.25M
                                      7 + intermediate_bits);
828
2.25M
        }
829
281k
        mid_ptr += 8;
830
281k
        dst += PXSTRIDE(dst_stride);
831
281k
    }
832
35.1k
}
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
6.84k
{
839
6.84k
    const int intermediate_bits = get_intermediate_bits(bitdepth_max);
840
6.84k
    int16_t mid[15 * 8], *mid_ptr = mid;
841
842
6.84k
    src -= 3 * PXSTRIDE(src_stride);
843
109k
    for (int y = 0; y < 15; y++, mx += abcd[1]) {
844
923k
        for (int x = 0, tmx = mx; x < 8; x++, tmx += abcd[0]) {
845
820k
            const int8_t *const filter =
846
820k
                dav1d_mc_warp_filter[64 + ((tmx + 512) >> 10)];
847
848
820k
            mid_ptr[x] = FILTER_WARP_RND(src, x, filter, 1,
849
820k
                                         7 - intermediate_bits);
850
820k
        }
851
102k
        src += PXSTRIDE(src_stride);
852
102k
        mid_ptr += 8;
853
102k
    }
854
855
6.84k
    mid_ptr = &mid[3 * 8];
856
61.5k
    for (int y = 0; y < 8; y++, my += abcd[3]) {
857
492k
        for (int x = 0, tmy = my; x < 8; x++, tmy += abcd[2]) {
858
437k
            const int8_t *const filter =
859
437k
                dav1d_mc_warp_filter[64 + ((tmy + 512) >> 10)];
860
861
437k
            tmp[x] = FILTER_WARP_RND(mid_ptr, x, filter, 8, 7) - PREP_BIAS;
862
437k
        }
863
54.7k
        mid_ptr += 8;
864
54.7k
        tmp += tmp_stride;
865
54.7k
    }
866
6.84k
}
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
543k
{
874
    // find offset in reference of visible block to copy
875
543k
    ref += iclip((int) y, 0, (int) ih - 1) * PXSTRIDE(ref_stride) +
876
543k
           iclip((int) x, 0, (int) iw - 1);
877
878
    // number of pixels to extend (left, right, top, bottom)
879
543k
    const int left_ext = iclip((int) -x, 0, (int) bw - 1);
880
543k
    const int right_ext = iclip((int) (x + bw - iw), 0, (int) bw - 1);
881
543k
    assert(left_ext + right_ext < bw);
882
543k
    const int top_ext = iclip((int) -y, 0, (int) bh - 1);
883
543k
    const int bottom_ext = iclip((int) (y + bh - ih), 0, (int) bh - 1);
884
543k
    assert(top_ext + bottom_ext < bh);
885
886
    // copy visible portion first
887
543k
    pixel *blk = dst + top_ext * PXSTRIDE(dst_stride);
888
543k
    const int center_w = (int) (bw - left_ext - right_ext);
889
543k
    const int center_h = (int) (bh - top_ext - bottom_ext);
890
6.10M
    for (int y = 0; y < center_h; y++) {
891
5.56M
        pixel_copy(blk + left_ext, ref, center_w);
892
        // extend left edge for this line
893
5.56M
        if (left_ext)
894
1.01M
            pixel_set(blk, blk[left_ext], left_ext);
895
        // extend right edge for this line
896
5.56M
        if (right_ext)
897
2.58M
            pixel_set(blk + left_ext + center_w, blk[left_ext + center_w - 1],
898
2.58M
                      right_ext);
899
5.56M
        ref += PXSTRIDE(ref_stride);
900
5.56M
        blk += PXSTRIDE(dst_stride);
901
5.56M
    }
902
903
    // copy top
904
543k
    blk = dst + top_ext * PXSTRIDE(dst_stride);
905
1.81M
    for (int y = 0; y < top_ext; y++) {
906
1.27M
        pixel_copy(dst, blk, bw);
907
1.27M
        dst += PXSTRIDE(dst_stride);
908
1.27M
    }
909
910
    // copy bottom
911
543k
    dst += center_h * PXSTRIDE(dst_stride);
912
1.57M
    for (int y = 0; y < bottom_ext; y++) {
913
1.02M
        pixel_copy(dst, &dst[-PXSTRIDE(dst_stride)], bw);
914
1.02M
        dst += PXSTRIDE(dst_stride);
915
1.02M
    }
916
543k
}
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
96.8k
{
923
3.36M
    do {
924
3.36M
        int mx = mx0, src_x = -1;
925
163M
        for (int x = 0; x < dst_w; x++) {
926
159M
            const int8_t *const F = dav1d_resize_filter[mx >> 8];
927
159M
            dst[x] = iclip_pixel((-(F[0] * src[iclip(src_x - 3, 0, src_w - 1)] +
928
159M
                                    F[1] * src[iclip(src_x - 2, 0, src_w - 1)] +
929
159M
                                    F[2] * src[iclip(src_x - 1, 0, src_w - 1)] +
930
159M
                                    F[3] * src[iclip(src_x + 0, 0, src_w - 1)] +
931
159M
                                    F[4] * src[iclip(src_x + 1, 0, src_w - 1)] +
932
159M
                                    F[5] * src[iclip(src_x + 2, 0, src_w - 1)] +
933
159M
                                    F[6] * src[iclip(src_x + 3, 0, src_w - 1)] +
934
159M
                                    F[7] * src[iclip(src_x + 4, 0, src_w - 1)]) +
935
159M
                                  64) >> 7);
936
159M
            mx += dx;
937
159M
            src_x += mx >> 14;
938
159M
            mx &= 0x3fff;
939
159M
        }
940
941
3.36M
        dst += PXSTRIDE(dst_stride);
942
3.36M
        src += PXSTRIDE(src_stride);
943
3.36M
    } while (--h);
944
96.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
41.5k
COLD void bitfn(dav1d_mc_dsp_init)(Dav1dMCDSPContext *const c) {
961
415k
#define init_mc_fns(type, name) do { \
962
415k
    c->mc        [type] = put_##name##_c; \
963
415k
    c->mc_scaled [type] = put_##name##_scaled_c; \
964
415k
    c->mct       [type] = prep_##name##_c; \
965
415k
    c->mct_scaled[type] = prep_##name##_scaled_c; \
966
415k
} while (0)
967
968
41.5k
    init_mc_fns(FILTER_2D_8TAP_REGULAR,        8tap_regular);
969
41.5k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SMOOTH, 8tap_regular_smooth);
970
41.5k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SHARP,  8tap_regular_sharp);
971
41.5k
    init_mc_fns(FILTER_2D_8TAP_SHARP_REGULAR,  8tap_sharp_regular);
972
41.5k
    init_mc_fns(FILTER_2D_8TAP_SHARP_SMOOTH,   8tap_sharp_smooth);
973
41.5k
    init_mc_fns(FILTER_2D_8TAP_SHARP,          8tap_sharp);
974
41.5k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_REGULAR, 8tap_smooth_regular);
975
41.5k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH,         8tap_smooth);
976
41.5k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_SHARP,   8tap_smooth_sharp);
977
41.5k
    init_mc_fns(FILTER_2D_BILINEAR,            bilin);
978
979
41.5k
    c->avg      = avg_c;
980
41.5k
    c->w_avg    = w_avg_c;
981
41.5k
    c->mask     = mask_c;
982
41.5k
    c->blend    = blend_c;
983
41.5k
    c->blend_v  = blend_v_c;
984
41.5k
    c->blend_h  = blend_h_c;
985
41.5k
    c->w_mask[0] = w_mask_444_c;
986
41.5k
    c->w_mask[1] = w_mask_422_c;
987
41.5k
    c->w_mask[2] = w_mask_420_c;
988
41.5k
    c->warp8x8  = warp_affine_8x8_c;
989
41.5k
    c->warp8x8t = warp_affine_8x8t_c;
990
41.5k
    c->emu_edge = emu_edge_c;
991
41.5k
    c->resize   = resize_c;
992
993
#if HAVE_ASM
994
#if ARCH_AARCH64 || ARCH_ARM
995
    mc_dsp_init_arm(c);
996
#elif ARCH_LOONGARCH64
997
    mc_dsp_init_loongarch(c);
998
#elif ARCH_PPC64LE
999
    mc_dsp_init_ppc(c);
1000
#elif ARCH_RISCV
1001
    mc_dsp_init_riscv(c);
1002
#elif ARCH_X86
1003
    mc_dsp_init_x86(c);
1004
#endif
1005
#endif
1006
41.5k
}
dav1d_mc_dsp_init_8bpc
Line
Count
Source
960
19.8k
COLD void bitfn(dav1d_mc_dsp_init)(Dav1dMCDSPContext *const c) {
961
19.8k
#define init_mc_fns(type, name) do { \
962
19.8k
    c->mc        [type] = put_##name##_c; \
963
19.8k
    c->mc_scaled [type] = put_##name##_scaled_c; \
964
19.8k
    c->mct       [type] = prep_##name##_c; \
965
19.8k
    c->mct_scaled[type] = prep_##name##_scaled_c; \
966
19.8k
} while (0)
967
968
19.8k
    init_mc_fns(FILTER_2D_8TAP_REGULAR,        8tap_regular);
969
19.8k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SMOOTH, 8tap_regular_smooth);
970
19.8k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SHARP,  8tap_regular_sharp);
971
19.8k
    init_mc_fns(FILTER_2D_8TAP_SHARP_REGULAR,  8tap_sharp_regular);
972
19.8k
    init_mc_fns(FILTER_2D_8TAP_SHARP_SMOOTH,   8tap_sharp_smooth);
973
19.8k
    init_mc_fns(FILTER_2D_8TAP_SHARP,          8tap_sharp);
974
19.8k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_REGULAR, 8tap_smooth_regular);
975
19.8k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH,         8tap_smooth);
976
19.8k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_SHARP,   8tap_smooth_sharp);
977
19.8k
    init_mc_fns(FILTER_2D_BILINEAR,            bilin);
978
979
19.8k
    c->avg      = avg_c;
980
19.8k
    c->w_avg    = w_avg_c;
981
19.8k
    c->mask     = mask_c;
982
19.8k
    c->blend    = blend_c;
983
19.8k
    c->blend_v  = blend_v_c;
984
19.8k
    c->blend_h  = blend_h_c;
985
19.8k
    c->w_mask[0] = w_mask_444_c;
986
19.8k
    c->w_mask[1] = w_mask_422_c;
987
19.8k
    c->w_mask[2] = w_mask_420_c;
988
19.8k
    c->warp8x8  = warp_affine_8x8_c;
989
19.8k
    c->warp8x8t = warp_affine_8x8t_c;
990
19.8k
    c->emu_edge = emu_edge_c;
991
19.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
19.8k
}
dav1d_mc_dsp_init_16bpc
Line
Count
Source
960
21.6k
COLD void bitfn(dav1d_mc_dsp_init)(Dav1dMCDSPContext *const c) {
961
21.6k
#define init_mc_fns(type, name) do { \
962
21.6k
    c->mc        [type] = put_##name##_c; \
963
21.6k
    c->mc_scaled [type] = put_##name##_scaled_c; \
964
21.6k
    c->mct       [type] = prep_##name##_c; \
965
21.6k
    c->mct_scaled[type] = prep_##name##_scaled_c; \
966
21.6k
} while (0)
967
968
21.6k
    init_mc_fns(FILTER_2D_8TAP_REGULAR,        8tap_regular);
969
21.6k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SMOOTH, 8tap_regular_smooth);
970
21.6k
    init_mc_fns(FILTER_2D_8TAP_REGULAR_SHARP,  8tap_regular_sharp);
971
21.6k
    init_mc_fns(FILTER_2D_8TAP_SHARP_REGULAR,  8tap_sharp_regular);
972
21.6k
    init_mc_fns(FILTER_2D_8TAP_SHARP_SMOOTH,   8tap_sharp_smooth);
973
21.6k
    init_mc_fns(FILTER_2D_8TAP_SHARP,          8tap_sharp);
974
21.6k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_REGULAR, 8tap_smooth_regular);
975
21.6k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH,         8tap_smooth);
976
21.6k
    init_mc_fns(FILTER_2D_8TAP_SMOOTH_SHARP,   8tap_smooth_sharp);
977
21.6k
    init_mc_fns(FILTER_2D_BILINEAR,            bilin);
978
979
21.6k
    c->avg      = avg_c;
980
21.6k
    c->w_avg    = w_avg_c;
981
21.6k
    c->mask     = mask_c;
982
21.6k
    c->blend    = blend_c;
983
21.6k
    c->blend_v  = blend_v_c;
984
21.6k
    c->blend_h  = blend_h_c;
985
21.6k
    c->w_mask[0] = w_mask_444_c;
986
21.6k
    c->w_mask[1] = w_mask_422_c;
987
21.6k
    c->w_mask[2] = w_mask_420_c;
988
21.6k
    c->warp8x8  = warp_affine_8x8_c;
989
21.6k
    c->warp8x8t = warp_affine_8x8t_c;
990
21.6k
    c->emu_edge = emu_edge_c;
991
21.6k
    c->resize   = resize_c;
992
993
#if HAVE_ASM
994
#if ARCH_AARCH64 || ARCH_ARM
995
    mc_dsp_init_arm(c);
996
#elif ARCH_LOONGARCH64
997
    mc_dsp_init_loongarch(c);
998
#elif ARCH_PPC64LE
999
    mc_dsp_init_ppc(c);
1000
#elif ARCH_RISCV
1001
    mc_dsp_init_riscv(c);
1002
#elif ARCH_X86
1003
    mc_dsp_init_x86(c);
1004
#endif
1005
#endif
1006
21.6k
}