Coverage Report

Created: 2026-06-15 06:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/dav1d/src/recon_tmpl.c
Line
Count
Source
1
/*
2
 * Copyright © 2018-2021, 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 <string.h>
31
#include <stdio.h>
32
33
#include "common/attributes.h"
34
#include "common/bitdepth.h"
35
#include "common/dump.h"
36
#include "common/frame.h"
37
#include "common/intops.h"
38
39
#include "src/cdef_apply.h"
40
#include "src/ctx.h"
41
#include "src/ipred_prepare.h"
42
#include "src/lf_apply.h"
43
#include "src/lr_apply.h"
44
#include "src/recon.h"
45
#include "src/scan.h"
46
#include "src/tables.h"
47
#include "src/wedge.h"
48
49
633k
static inline unsigned read_golomb(MsacContext *const msac) {
50
633k
    int len = 0;
51
633k
    unsigned val = 1;
52
53
1.20M
    while (!dav1d_msac_decode_bool_equi(msac) && len < 32) len++;
54
1.20M
    while (len--) val = (val << 1) + dav1d_msac_decode_bool_equi(msac);
55
56
633k
    return val - 1;
57
633k
}
58
59
static inline unsigned get_skip_ctx(const TxfmInfo *const t_dim,
60
                                    const enum BlockSize bs,
61
                                    const uint8_t *const a,
62
                                    const uint8_t *const l,
63
                                    const int chroma,
64
                                    const enum Dav1dPixelLayout layout)
65
3.66M
{
66
3.66M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
67
68
3.66M
    if (chroma) {
69
1.98M
        const int ss_ver = layout == DAV1D_PIXEL_LAYOUT_I420;
70
1.98M
        const int ss_hor = layout != DAV1D_PIXEL_LAYOUT_I444;
71
1.98M
        const int not_one_blk = b_dim[2] - (!!b_dim[2] && ss_hor) > t_dim->lw ||
72
1.21M
                                b_dim[3] - (!!b_dim[3] && ss_ver) > t_dim->lh;
73
1.98M
        unsigned ca, cl;
74
75
1.98M
#define MERGE_CTX(dir, type, no_val) \
76
3.96M
        c##dir = *(const type *) dir != no_val; \
77
3.96M
        break
78
79
1.98M
        switch (t_dim->lw) {
80
        /* For some reason the MSVC CRT _wassert() function is not flagged as
81
         * __declspec(noreturn), so when using those headers the compiler will
82
         * expect execution to continue after an assertion has been triggered
83
         * and will therefore complain about the use of uninitialized variables
84
         * when compiled in debug mode if we put the default case at the end. */
85
0
        default: assert(0); /* fall-through */
86
796k
        case TX_4X4:   MERGE_CTX(a, uint8_t,  0x40);
87
398k
        case TX_8X8:   MERGE_CTX(a, uint16_t, 0x4040);
88
244k
        case TX_16X16: MERGE_CTX(a, uint32_t, 0x40404040U);
89
542k
        case TX_32X32: MERGE_CTX(a, uint64_t, 0x4040404040404040ULL);
90
1.98M
        }
91
1.98M
        switch (t_dim->lh) {
92
0
        default: assert(0); /* fall-through */
93
893k
        case TX_4X4:   MERGE_CTX(l, uint8_t,  0x40);
94
349k
        case TX_8X8:   MERGE_CTX(l, uint16_t, 0x4040);
95
200k
        case TX_16X16: MERGE_CTX(l, uint32_t, 0x40404040U);
96
539k
        case TX_32X32: MERGE_CTX(l, uint64_t, 0x4040404040404040ULL);
97
1.98M
        }
98
1.98M
#undef MERGE_CTX
99
100
1.98M
        return 7 + not_one_blk * 3 + ca + cl;
101
1.98M
    } else if (b_dim[2] == t_dim->lw && b_dim[3] == t_dim->lh) {
102
653k
        return 0;
103
1.03M
    } else {
104
1.03M
        unsigned la, ll;
105
106
1.03M
#define MERGE_CTX(dir, type, tx) \
107
2.08M
        if (tx == TX_64X64) { \
108
214k
            uint64_t tmp = *(const uint64_t *) dir; \
109
214k
            tmp |= *(const uint64_t *) &dir[8]; \
110
214k
            l##dir = (unsigned) (tmp >> 32) | (unsigned) tmp; \
111
214k
        } else \
112
2.08M
            l##dir = *(const type *) dir; \
113
2.08M
        if (tx == TX_32X32) l##dir |= *(const type *) &dir[sizeof(type)]; \
114
2.08M
        if (tx >= TX_16X16) l##dir |= l##dir >> 16; \
115
2.08M
        if (tx >= TX_8X8)   l##dir |= l##dir >> 8; \
116
2.08M
        break
117
118
1.03M
        switch (t_dim->lw) {
119
0
        default: assert(0); /* fall-through */
120
472k
        case TX_4X4:   MERGE_CTX(a, uint8_t,  TX_4X4);
121
209k
        case TX_8X8:   MERGE_CTX(a, uint16_t, TX_8X8);
122
235k
        case TX_16X16: MERGE_CTX(a, uint32_t, TX_16X16);
123
15.2k
        case TX_32X32: MERGE_CTX(a, uint32_t, TX_32X32);
124
107k
        case TX_64X64: MERGE_CTX(a, uint32_t, TX_64X64);
125
1.03M
        }
126
1.04M
        switch (t_dim->lh) {
127
0
        default: assert(0); /* fall-through */
128
479k
        case TX_4X4:   MERGE_CTX(l, uint8_t,  TX_4X4);
129
203k
        case TX_8X8:   MERGE_CTX(l, uint16_t, TX_8X8);
130
235k
        case TX_16X16: MERGE_CTX(l, uint32_t, TX_16X16);
131
15.3k
        case TX_32X32: MERGE_CTX(l, uint32_t, TX_32X32);
132
107k
        case TX_64X64: MERGE_CTX(l, uint32_t, TX_64X64);
133
1.04M
        }
134
1.04M
#undef MERGE_CTX
135
136
1.04M
        return dav1d_skip_ctx[umin(la & 0x3F, 4)][umin(ll & 0x3F, 4)];
137
1.04M
    }
138
3.66M
}
139
140
static inline unsigned get_dc_sign_ctx(const int /*enum RectTxfmSize*/ tx,
141
                                       const uint8_t *const a,
142
                                       const uint8_t *const l)
143
1.55M
{
144
1.55M
    uint64_t mask = 0xC0C0C0C0C0C0C0C0ULL, mul = 0x0101010101010101ULL;
145
1.55M
    int s;
146
147
1.55M
#if ARCH_X86_64 && defined(__GNUC__)
148
    /* Coerce compilers into producing better code. For some reason
149
     * every x86-64 compiler is awful at handling 64-bit constants. */
150
1.55M
    __asm__("" : "+r"(mask), "+r"(mul));
151
1.55M
#endif
152
153
1.55M
    switch(tx) {
154
0
    default: assert(0); /* fall-through */
155
492k
    case TX_4X4: {
156
492k
        int t = *(const uint8_t *) a >> 6;
157
492k
        t    += *(const uint8_t *) l >> 6;
158
492k
        s = t - 1 - 1;
159
492k
        break;
160
0
    }
161
174k
    case TX_8X8: {
162
174k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
163
174k
        t         += *(const uint16_t *) l & (uint32_t) mask;
164
174k
        t *= 0x04040404U;
165
174k
        s = (int) (t >> 24) - 2 - 2;
166
174k
        break;
167
0
    }
168
168k
    case TX_16X16: {
169
168k
        uint32_t t = (*(const uint32_t *) a & (uint32_t) mask) >> 6;
170
168k
        t         += (*(const uint32_t *) l & (uint32_t) mask) >> 6;
171
168k
        t *= (uint32_t) mul;
172
168k
        s = (int) (t >> 24) - 4 - 4;
173
168k
        break;
174
0
    }
175
190k
    case TX_32X32: {
176
190k
        uint64_t t = (*(const uint64_t *) a & mask) >> 6;
177
190k
        t         += (*(const uint64_t *) l & mask) >> 6;
178
190k
        t *= mul;
179
190k
        s = (int) (t >> 56) - 8 - 8;
180
190k
        break;
181
0
    }
182
90.2k
    case TX_64X64: {
183
90.2k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
184
90.2k
        t         += (*(const uint64_t *) &a[8] & mask) >> 6;
185
90.2k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
186
90.2k
        t         += (*(const uint64_t *) &l[8] & mask) >> 6;
187
90.2k
        t *= mul;
188
90.2k
        s = (int) (t >> 56) - 16 - 16;
189
90.2k
        break;
190
0
    }
191
53.4k
    case RTX_4X8: {
192
53.4k
        uint32_t t = *(const uint8_t  *) a & (uint32_t) mask;
193
53.4k
        t         += *(const uint16_t *) l & (uint32_t) mask;
194
53.4k
        t *= 0x04040404U;
195
53.4k
        s = (int) (t >> 24) - 1 - 2;
196
53.4k
        break;
197
0
    }
198
81.7k
    case RTX_8X4: {
199
81.7k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
200
81.7k
        t         += *(const uint8_t  *) l & (uint32_t) mask;
201
81.7k
        t *= 0x04040404U;
202
81.7k
        s = (int) (t >> 24) - 2 - 1;
203
81.7k
        break;
204
0
    }
205
44.6k
    case RTX_8X16: {
206
44.6k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
207
44.6k
        t         += *(const uint32_t *) l & (uint32_t) mask;
208
44.6k
        t = (t >> 6) * (uint32_t) mul;
209
44.6k
        s = (int) (t >> 24) - 2 - 4;
210
44.6k
        break;
211
0
    }
212
67.0k
    case RTX_16X8: {
213
67.0k
        uint32_t t = *(const uint32_t *) a & (uint32_t) mask;
214
67.0k
        t         += *(const uint16_t *) l & (uint32_t) mask;
215
67.0k
        t = (t >> 6) * (uint32_t) mul;
216
67.0k
        s = (int) (t >> 24) - 4 - 2;
217
67.0k
        break;
218
0
    }
219
24.0k
    case RTX_16X32: {
220
24.0k
        uint64_t t = *(const uint32_t *) a & (uint32_t) mask;
221
24.0k
        t         += *(const uint64_t *) l & mask;
222
24.0k
        t = (t >> 6) * mul;
223
24.0k
        s = (int) (t >> 56) - 4 - 8;
224
24.0k
        break;
225
0
    }
226
26.4k
    case RTX_32X16: {
227
26.4k
        uint64_t t = *(const uint64_t *) a & mask;
228
26.4k
        t         += *(const uint32_t *) l & (uint32_t) mask;
229
26.4k
        t = (t >> 6) * mul;
230
26.4k
        s = (int) (t >> 56) - 8 - 4;
231
26.4k
        break;
232
0
    }
233
14.1k
    case RTX_32X64: {
234
14.1k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
235
14.1k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
236
14.1k
        t         += (*(const uint64_t *) &l[8] & mask) >> 6;
237
14.1k
        t *= mul;
238
14.1k
        s = (int) (t >> 56) - 8 - 16;
239
14.1k
        break;
240
0
    }
241
8.05k
    case RTX_64X32: {
242
8.05k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
243
8.05k
        t         += (*(const uint64_t *) &a[8] & mask) >> 6;
244
8.05k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
245
8.05k
        t *= mul;
246
8.05k
        s = (int) (t >> 56) - 16 - 8;
247
8.05k
        break;
248
0
    }
249
25.0k
    case RTX_4X16: {
250
25.0k
        uint32_t t = *(const uint8_t  *) a & (uint32_t) mask;
251
25.0k
        t         += *(const uint32_t *) l & (uint32_t) mask;
252
25.0k
        t = (t >> 6) * (uint32_t) mul;
253
25.0k
        s = (int) (t >> 24) - 1 - 4;
254
25.0k
        break;
255
0
    }
256
49.0k
    case RTX_16X4: {
257
49.0k
        uint32_t t = *(const uint32_t *) a & (uint32_t) mask;
258
49.0k
        t         += *(const uint8_t  *) l & (uint32_t) mask;
259
49.0k
        t = (t >> 6) * (uint32_t) mul;
260
49.0k
        s = (int) (t >> 24) - 4 - 1;
261
49.0k
        break;
262
0
    }
263
16.0k
    case RTX_8X32: {
264
16.0k
        uint64_t t = *(const uint16_t *) a & (uint32_t) mask;
265
16.0k
        t         += *(const uint64_t *) l & mask;
266
16.0k
        t = (t >> 6) * mul;
267
16.0k
        s = (int) (t >> 56) - 2 - 8;
268
16.0k
        break;
269
0
    }
270
22.1k
    case RTX_32X8: {
271
22.1k
        uint64_t t = *(const uint64_t *) a & mask;
272
22.1k
        t         += *(const uint16_t *) l & (uint32_t) mask;
273
22.1k
        t = (t >> 6) * mul;
274
22.1k
        s = (int) (t >> 56) - 8 - 2;
275
22.1k
        break;
276
0
    }
277
4.51k
    case RTX_16X64: {
278
4.51k
        uint64_t t = *(const uint32_t *) a & (uint32_t) mask;
279
4.51k
        t         += *(const uint64_t *) &l[0] & mask;
280
4.51k
        t = (t >> 6) + ((*(const uint64_t *) &l[8] & mask) >> 6);
281
4.51k
        t *= mul;
282
4.51k
        s = (int) (t >> 56) - 4 - 16;
283
4.51k
        break;
284
0
    }
285
4.20k
    case RTX_64X16: {
286
4.20k
        uint64_t t = *(const uint64_t *) &a[0] & mask;
287
4.20k
        t         += *(const uint32_t *) l & (uint32_t) mask;
288
4.20k
        t = (t >> 6) + ((*(const uint64_t *) &a[8] & mask) >> 6);
289
4.20k
        t *= mul;
290
4.20k
        s = (int) (t >> 56) - 16 - 4;
291
4.20k
        break;
292
0
    }
293
1.55M
    }
294
295
1.55M
    return (s != 0) + (s > 0);
296
1.55M
}
297
298
static inline unsigned get_lo_ctx(const uint8_t *const levels,
299
                                  const enum TxClass tx_class,
300
                                  unsigned *const hi_mag,
301
                                  const uint8_t (*const ctx_offsets)[5],
302
                                  const unsigned x, const unsigned y,
303
                                  const ptrdiff_t stride)
304
34.5M
{
305
34.5M
    unsigned mag = levels[0 * stride + 1] + levels[1 * stride + 0];
306
34.5M
    unsigned offset;
307
34.5M
    if (tx_class == TX_CLASS_2D) {
308
32.5M
        mag += levels[1 * stride + 1];
309
32.5M
        *hi_mag = mag;
310
32.5M
        mag += levels[0 * stride + 2] + levels[2 * stride + 0];
311
32.5M
        offset = ctx_offsets[umin(y, 4)][umin(x, 4)];
312
32.5M
    } else {
313
1.99M
        mag += levels[0 * stride + 2];
314
1.99M
        *hi_mag = mag;
315
1.99M
        mag += levels[0 * stride + 3] + levels[0 * stride + 4];
316
1.99M
        offset = 26 + (y > 1 ? 10 : y * 5);
317
1.99M
    }
318
34.5M
    return offset + (mag > 512 ? 4 : (mag + 64) >> 7);
319
34.5M
}
320
321
static int decode_coefs(Dav1dTaskContext *const t,
322
                        uint8_t *const a, uint8_t *const l,
323
                        const enum RectTxfmSize tx, const enum BlockSize bs,
324
                        const Av1Block *const b, const int intra,
325
                        const int plane, coef *cf,
326
                        enum TxfmType *const txtp, uint8_t *res_ctx)
327
3.66M
{
328
3.66M
    Dav1dTileState *const ts = t->ts;
329
3.66M
    const int chroma = !!plane;
330
3.66M
    const Dav1dFrameContext *const f = t->f;
331
3.66M
    const int lossless = f->frame_hdr->segmentation.lossless[b->seg_id];
332
3.66M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[tx];
333
3.66M
    const int dbg = DEBUG_BLOCK_INFO && plane && 0;
334
335
3.66M
    if (dbg)
336
0
        printf("Start: r=%d\n", ts->msac.rng);
337
338
    // does this block have any non-zero coefficients
339
3.66M
    const int sctx = get_skip_ctx(t_dim, bs, a, l, chroma, f->cur.p.layout);
340
3.66M
    const int all_skip = dav1d_msac_decode_bool_adapt(&ts->msac,
341
3.66M
                             ts->cdf.coef.skip[t_dim->ctx][sctx]);
342
3.66M
    if (dbg)
343
0
        printf("Post-non-zero[%d][%d][%d]: r=%d\n",
344
0
               t_dim->ctx, sctx, all_skip, ts->msac.rng);
345
3.66M
    if (all_skip) {
346
1.79M
        *res_ctx = 0x40;
347
1.79M
        *txtp = lossless * WHT_WHT; /* lossless ? WHT_WHT : DCT_DCT */
348
1.79M
        return -1;
349
1.79M
    }
350
351
    // transform type (chroma: derived, luma: explicitly coded)
352
1.87M
    if (lossless) {
353
413k
        assert(t_dim->max == TX_4X4);
354
413k
        *txtp = WHT_WHT;
355
1.46M
    } else if (t_dim->max + intra >= TX_64X64) {
356
412k
        *txtp = DCT_DCT;
357
1.05M
    } else if (chroma) {
358
        // inferred from either the luma txtp (inter) or a LUT (intra)
359
279k
        *txtp = intra ? dav1d_txtp_from_uvmode[b->uv_mode] :
360
279k
                        get_uv_inter_txtp(t_dim, *txtp);
361
770k
    } else if (!f->frame_hdr->segmentation.qidx[b->seg_id]) {
362
        // In libaom, lossless is checked by a literal qidx == 0, but not all
363
        // such blocks are actually lossless. The remainder gets an implicit
364
        // transform type (for luma)
365
1.41k
        *txtp = DCT_DCT;
366
768k
    } else {
367
768k
        unsigned idx;
368
768k
        if (intra) {
369
622k
            const enum IntraPredMode y_mode_nofilt = b->y_mode == FILTER_PRED ?
370
526k
                dav1d_filter_mode_to_y_mode[b->y_angle] : b->y_mode;
371
622k
            if (f->frame_hdr->reduced_txtp_set || t_dim->min == TX_16X16) {
372
296k
                idx = dav1d_msac_decode_symbol_adapt8(&ts->msac,
373
296k
                          ts->cdf.m.txtp_intra2[t_dim->min][y_mode_nofilt], 4);
374
296k
                *txtp = dav1d_tx_types_per_set[idx + 0];
375
325k
            } else {
376
325k
                idx = dav1d_msac_decode_symbol_adapt8(&ts->msac,
377
325k
                          ts->cdf.m.txtp_intra1[t_dim->min][y_mode_nofilt], 6);
378
325k
                *txtp = dav1d_tx_types_per_set[idx + 5];
379
325k
            }
380
622k
            if (dbg)
381
0
                printf("Post-txtp-intra[%d->%d][%d][%d->%d]: r=%d\n",
382
0
                       tx, t_dim->min, y_mode_nofilt, idx, *txtp, ts->msac.rng);
383
622k
        } else {
384
146k
            if (f->frame_hdr->reduced_txtp_set || t_dim->max == TX_32X32) {
385
37.9k
                idx = dav1d_msac_decode_bool_adapt(&ts->msac,
386
37.9k
                          ts->cdf.m.txtp_inter3[t_dim->min]);
387
37.9k
                *txtp = (idx - 1) & IDTX; /* idx ? DCT_DCT : IDTX */
388
108k
            } else if (t_dim->min == TX_16X16) {
389
10.0k
                idx = dav1d_msac_decode_symbol_adapt16(&ts->msac,
390
10.0k
                          ts->cdf.m.txtp_inter2, 11);
391
10.0k
                *txtp = dav1d_tx_types_per_set[idx + 12];
392
98.2k
            } else {
393
98.2k
                idx = dav1d_msac_decode_symbol_adapt16(&ts->msac,
394
98.2k
                          ts->cdf.m.txtp_inter1[t_dim->min], 15);
395
98.2k
                *txtp = dav1d_tx_types_per_set[idx + 24];
396
98.2k
            }
397
146k
            if (dbg)
398
0
                printf("Post-txtp-inter[%d->%d][%d->%d]: r=%d\n",
399
0
                       tx, t_dim->min, idx, *txtp, ts->msac.rng);
400
146k
        }
401
768k
    }
402
403
    // find end-of-block (eob)
404
1.87M
    int eob;
405
1.87M
    const int slw = imin(t_dim->lw, TX_32X32), slh = imin(t_dim->lh, TX_32X32);
406
1.87M
    const int tx2dszctx = slw + slh;
407
1.87M
    const enum TxClass tx_class = dav1d_tx_type_class[*txtp];
408
1.87M
    const int is_1d = tx_class != TX_CLASS_2D;
409
1.87M
    switch (tx2dszctx) {
410
0
#define case_sz(sz, bin, ns, is_1d) \
411
1.87M
    case sz: { \
412
1.87M
        uint16_t *const eob_bin_cdf = ts->cdf.coef.eob_bin_##bin[chroma]is_1d; \
413
1.87M
        eob = dav1d_msac_decode_symbol_adapt##ns(&ts->msac, eob_bin_cdf, 4 + sz); \
414
1.87M
        break; \
415
1.87M
    }
416
585k
    case_sz(0,   16,  8, [is_1d]);
417
176k
    case_sz(1,   32,  8, [is_1d]);
418
318k
    case_sz(2,   64,  8, [is_1d]);
419
146k
    case_sz(3,  128,  8, [is_1d]);
420
257k
    case_sz(4,  256, 16, [is_1d]);
421
68.0k
    case_sz(5,  512, 16,        );
422
321k
    case_sz(6, 1024, 16,        );
423
1.87M
#undef case_sz
424
1.87M
    }
425
1.87M
    if (dbg)
426
0
        printf("Post-eob_bin_%d[%d][%d][%d]: r=%d\n",
427
0
               16 << tx2dszctx, chroma, is_1d, eob, ts->msac.rng);
428
1.87M
    if (eob > 1) {
429
1.20M
        const int eob_bin = eob - 2;
430
1.20M
        uint16_t *const eob_hi_bit_cdf =
431
1.20M
            ts->cdf.coef.eob_hi_bit[t_dim->ctx][chroma][eob_bin];
432
1.20M
        const int eob_hi_bit = dav1d_msac_decode_bool_adapt(&ts->msac, eob_hi_bit_cdf);
433
1.20M
        if (dbg)
434
0
            printf("Post-eob_hi_bit[%d][%d][%d][%d]: r=%d\n",
435
0
                   t_dim->ctx, chroma, eob_bin, eob_hi_bit, ts->msac.rng);
436
1.20M
        eob = ((eob_hi_bit | 2) << eob_bin) | dav1d_msac_decode_bools(&ts->msac, eob_bin);
437
1.20M
        if (dbg)
438
0
            printf("Post-eob[%d]: r=%d\n", eob, ts->msac.rng);
439
1.20M
    }
440
1.87M
    assert(eob >= 0);
441
442
    // base tokens
443
1.87M
    uint16_t (*const eob_cdf)[4] = ts->cdf.coef.eob_base_tok[t_dim->ctx][chroma];
444
1.87M
    uint16_t (*const hi_cdf)[4] = ts->cdf.coef.br_tok[imin(t_dim->ctx, 3)][chroma];
445
1.87M
    unsigned rc, dc_tok;
446
447
1.87M
    if (eob) {
448
1.28M
        uint16_t (*const lo_cdf)[4] = ts->cdf.coef.base_tok[t_dim->ctx][chroma];
449
1.28M
        uint8_t *const levels = t->scratch.levels; // bits 0-5: tok, 6-7: lo_tok
450
451
        /* eob */
452
1.28M
        unsigned ctx = 1 + (eob > 2 << tx2dszctx) + (eob > 4 << tx2dszctx);
453
1.28M
        int eob_tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, eob_cdf[ctx], 2);
454
1.28M
        int tok = eob_tok + 1;
455
1.28M
        int level_tok = tok * 0x41;
456
1.28M
        unsigned mag;
457
458
1.28M
#define DECODE_COEFS_CLASS(tx_class) \
459
1.28M
        unsigned x, y; \
460
1.28M
        uint8_t *level; \
461
1.28M
        if (tx_class == TX_CLASS_2D) \
462
1.28M
            rc = scan[eob], x = rc >> shift, y = rc & mask; \
463
1.28M
        else if (tx_class == TX_CLASS_H) \
464
            /* Transposing reduces the stride and padding requirements */ \
465
93.5k
            x = eob & mask, y = eob >> shift, rc = eob; \
466
93.5k
        else /* tx_class == TX_CLASS_V */ \
467
93.5k
            x = eob & mask, y = eob >> shift, rc = (x << shift2) | y; \
468
1.28M
        if (dbg) \
469
1.28M
            printf("Post-lo_tok[%d][%d][%d][%d=%d=%d]: r=%d\n", \
470
0
                   t_dim->ctx, chroma, ctx, eob, rc, tok, ts->msac.rng); \
471
1.28M
        if (eob_tok == 2) { \
472
23.0k
            ctx = (tx_class == TX_CLASS_2D ? (x | y) > 1 : y != 0) ? 14 : 7; \
473
23.0k
            tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
474
23.0k
            level_tok = tok + (3 << 6); \
475
23.0k
            if (dbg) \
476
23.0k
                printf("Post-hi_tok[%d][%d][%d][%d=%d=%d]: r=%d\n", \
477
0
                       imin(t_dim->ctx, 3), chroma, ctx, eob, rc, tok, \
478
0
                       ts->msac.rng); \
479
23.0k
        } \
480
1.28M
        cf[rc] = tok << 11; \
481
1.28M
        if (tx_class == TX_CLASS_2D) \
482
1.28M
            level = levels + rc; \
483
1.28M
        else \
484
1.28M
            level = levels + x * stride + y; \
485
1.28M
        *level = (uint8_t) level_tok; \
486
35.6M
        for (int i = eob - 1; i > 0; i--) { /* ac */ \
487
34.3M
            unsigned rc_i; \
488
34.3M
            if (tx_class == TX_CLASS_2D) \
489
34.3M
                rc_i = scan[i], x = rc_i >> shift, y = rc_i & mask; \
490
34.3M
            else if (tx_class == TX_CLASS_H) \
491
1.93M
                x = i & mask, y = i >> shift, rc_i = i; \
492
1.93M
            else /* tx_class == TX_CLASS_V */ \
493
1.93M
                x = i & mask, y = i >> shift, rc_i = (x << shift2) | y; \
494
34.3M
            assert(x < 32 && y < 32); \
495
34.3M
            if (tx_class == TX_CLASS_2D) \
496
34.3M
                level = levels + rc_i; \
497
34.3M
            else \
498
34.3M
                level = levels + x * stride + y; \
499
34.3M
            ctx = get_lo_ctx(level, tx_class, &mag, lo_ctx_offsets, x, y, stride); \
500
34.3M
            if (tx_class == TX_CLASS_2D) \
501
34.3M
                y |= x; \
502
34.3M
            tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, lo_cdf[ctx], 3); \
503
34.3M
            if (dbg) \
504
34.3M
                printf("Post-lo_tok[%d][%d][%d][%d=%d=%d]: r=%d\n", \
505
0
                       t_dim->ctx, chroma, ctx, i, rc_i, tok, ts->msac.rng); \
506
34.3M
            if (tok == 3) { \
507
2.88M
                mag &= 63; \
508
2.88M
                ctx = (y > (tx_class == TX_CLASS_2D) ? 14 : 7) + \
509
2.88M
                      (mag > 12 ? 6 : (mag + 1) >> 1); \
510
2.88M
                tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
511
2.88M
                if (dbg) \
512
2.88M
                    printf("Post-hi_tok[%d][%d][%d][%d=%d=%d]: r=%d\n", \
513
0
                           imin(t_dim->ctx, 3), chroma, ctx, i, rc_i, tok, \
514
0
                           ts->msac.rng); \
515
2.88M
                *level = (uint8_t) (tok + (3 << 6)); \
516
2.88M
                cf[rc_i] = (tok << 11) | rc; \
517
2.88M
                rc = rc_i; \
518
31.5M
            } else { \
519
                /* 0x1 for tok, 0x7ff as bitmask for rc, 0x41 for level_tok */ \
520
31.5M
                tok *= 0x17ff41; \
521
31.5M
                *level = (uint8_t) tok; \
522
                /* tok ? (tok << 11) | rc : 0 */ \
523
31.5M
                tok = (tok >> 9) & (rc + ~0x7ffu); \
524
31.5M
                if (tok) rc = rc_i; \
525
31.5M
                cf[rc_i] = tok; \
526
31.5M
            } \
527
34.3M
        } \
528
        /* dc */ \
529
1.28M
        ctx = (tx_class == TX_CLASS_2D) ? 0 : \
530
1.28M
            get_lo_ctx(levels, tx_class, &mag, lo_ctx_offsets, 0, 0, stride); \
531
1.28M
        dc_tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, lo_cdf[ctx], 3); \
532
1.28M
        if (dbg) \
533
1.28M
            printf("Post-dc_lo_tok[%d][%d][%d][%d]: r=%d\n", \
534
0
                   t_dim->ctx, chroma, ctx, dc_tok, ts->msac.rng); \
535
1.28M
        if (dc_tok == 3) { \
536
467k
            if (tx_class == TX_CLASS_2D) \
537
467k
                mag = levels[0 * stride + 1] + levels[1 * stride + 0] + \
538
457k
                      levels[1 * stride + 1]; \
539
467k
            mag &= 63; \
540
467k
            ctx = mag > 12 ? 6 : (mag + 1) >> 1; \
541
467k
            dc_tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
542
467k
            if (dbg) \
543
467k
                printf("Post-dc_hi_tok[%d][%d][0][%d]: r=%d\n", \
544
0
                       imin(t_dim->ctx, 3), chroma, dc_tok, ts->msac.rng); \
545
467k
        } \
546
1.28M
        break
547
548
1.28M
        const uint16_t *scan;
549
1.28M
        switch (tx_class) {
550
1.19M
        case TX_CLASS_2D: {
551
1.19M
            const unsigned nonsquare_tx = tx >= RTX_4X8;
552
1.19M
            const uint8_t (*const lo_ctx_offsets)[5] =
553
1.19M
                dav1d_lo_ctx_offsets[nonsquare_tx + (tx & nonsquare_tx)];
554
1.19M
            scan = dav1d_scans[tx];
555
1.19M
            const ptrdiff_t stride = 4 << slh;
556
1.19M
            const unsigned shift = slh + 2, shift2 = 0;
557
1.19M
            const unsigned mask = (4 << slh) - 1;
558
1.19M
            memset(levels, 0, stride * ((4 << slw) + 2));
559
1.19M
            DECODE_COEFS_CLASS(TX_CLASS_2D);
560
1.19M
        }
561
61.4k
        case TX_CLASS_H: {
562
61.4k
            const uint8_t (*const lo_ctx_offsets)[5] = NULL;
563
61.4k
            const ptrdiff_t stride = 16;
564
61.4k
            const unsigned shift = slh + 2, shift2 = 0;
565
61.4k
            const unsigned mask = (4 << slh) - 1;
566
61.4k
            memset(levels, 0, stride * ((4 << slh) + 2));
567
61.4k
            DECODE_COEFS_CLASS(TX_CLASS_H);
568
61.4k
        }
569
32.0k
        case TX_CLASS_V: {
570
32.0k
            const uint8_t (*const lo_ctx_offsets)[5] = NULL;
571
32.0k
            const ptrdiff_t stride = 16;
572
32.0k
            const unsigned shift = slw + 2, shift2 = slh + 2;
573
32.0k
            const unsigned mask = (4 << slw) - 1;
574
32.0k
            memset(levels, 0, stride * ((4 << slw) + 2));
575
32.0k
            DECODE_COEFS_CLASS(TX_CLASS_V);
576
32.0k
        }
577
0
#undef DECODE_COEFS_CLASS
578
0
        default: assert(0);
579
1.28M
        }
580
1.28M
    } else { // dc-only
581
586k
        int tok_br = dav1d_msac_decode_symbol_adapt4(&ts->msac, eob_cdf[0], 2);
582
586k
        dc_tok = 1 + tok_br;
583
586k
        if (dbg)
584
0
            printf("Post-dc_lo_tok[%d][%d][%d][%d]: r=%d\n",
585
0
                   t_dim->ctx, chroma, 0, dc_tok, ts->msac.rng);
586
586k
        if (tok_br == 2) {
587
22.4k
            dc_tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[0]);
588
22.4k
            if (dbg)
589
0
                printf("Post-dc_hi_tok[%d][%d][0][%d]: r=%d\n",
590
0
                       imin(t_dim->ctx, 3), chroma, dc_tok, ts->msac.rng);
591
22.4k
        }
592
586k
        rc = 0;
593
586k
    }
594
595
    // residual and sign
596
1.87M
    const uint16_t *const dq_tbl = ts->dq[b->seg_id][plane];
597
1.87M
    const uint8_t *const qm_tbl = *txtp < IDTX ? f->qm[tx][plane] : NULL;
598
1.87M
    const int dq_shift = imax(0, t_dim->ctx - 2);
599
1.87M
    const int cf_max = ~(~127U << (BITDEPTH == 8 ? 8 : f->cur.p.bpc));
600
1.87M
    unsigned cul_level, dc_sign_level;
601
602
1.87M
    if (!dc_tok) {
603
320k
        cul_level = 0;
604
320k
        dc_sign_level = 1 << 6;
605
320k
        if (qm_tbl) goto ac_qm;
606
197k
        goto ac_noqm;
607
320k
    }
608
609
1.55M
    const int dc_sign_ctx = get_dc_sign_ctx(tx, a, l);
610
1.55M
    uint16_t *const dc_sign_cdf = ts->cdf.coef.dc_sign[chroma][dc_sign_ctx];
611
1.55M
    const int dc_sign = dav1d_msac_decode_bool_adapt(&ts->msac, dc_sign_cdf);
612
1.55M
    if (dbg)
613
0
        printf("Post-dc_sign[%d][%d][%d]: r=%d\n",
614
0
               chroma, dc_sign_ctx, dc_sign, ts->msac.rng);
615
616
1.55M
    int dc_dq = dq_tbl[0];
617
1.55M
    dc_sign_level = (dc_sign - 1) & (2 << 6);
618
619
1.55M
    if (qm_tbl) {
620
698k
        dc_dq = (dc_dq * qm_tbl[0] + 16) >> 5;
621
622
698k
        if (dc_tok == 15) {
623
18.5k
            dc_tok = read_golomb(&ts->msac) + 15;
624
18.5k
            if (dbg)
625
0
                printf("Post-dc_residual[%d->%d]: r=%d\n",
626
0
                       dc_tok - 15, dc_tok, ts->msac.rng);
627
628
18.5k
            dc_tok &= 0xfffff;
629
18.5k
            dc_dq = (dc_dq * dc_tok) & 0xffffff;
630
679k
        } else {
631
679k
            dc_dq *= dc_tok;
632
679k
            assert(dc_dq <= 0xffffff);
633
679k
        }
634
698k
        cul_level = dc_tok;
635
698k
        dc_dq >>= dq_shift;
636
698k
        dc_dq = umin(dc_dq, cf_max + dc_sign);
637
698k
        cf[0] = (coef) (dc_sign ? -dc_dq : dc_dq);
638
639
964k
        if (rc) ac_qm: {
640
964k
            const unsigned ac_dq = dq_tbl[1];
641
7.45M
            do {
642
7.45M
                const int sign = dav1d_msac_decode_bool_equi(&ts->msac);
643
7.45M
                if (dbg)
644
0
                    printf("Post-sign[%d=%d]: r=%d\n", rc, sign, ts->msac.rng);
645
7.45M
                const unsigned rc_tok = cf[rc];
646
7.45M
                unsigned tok, dq = (ac_dq * qm_tbl[rc] + 16) >> 5;
647
7.45M
                int dq_sat;
648
649
7.45M
                if (rc_tok >= (15 << 11)) {
650
491k
                    tok = read_golomb(&ts->msac) + 15;
651
491k
                    if (dbg)
652
0
                        printf("Post-residual[%d=%d->%d]: r=%d\n",
653
0
                               rc, tok - 15, tok, ts->msac.rng);
654
655
491k
                    tok &= 0xfffff;
656
491k
                    dq = (dq * tok) & 0xffffff;
657
6.96M
                } else {
658
6.96M
                    tok = rc_tok >> 11;
659
6.96M
                    dq *= tok;
660
6.96M
                    assert(dq <= 0xffffff);
661
6.96M
                }
662
7.45M
                cul_level += tok;
663
7.45M
                dq >>= dq_shift;
664
7.45M
                dq_sat = umin(dq, cf_max + sign);
665
7.45M
                cf[rc] = (coef) (sign ? -dq_sat : dq_sat);
666
667
7.45M
                rc = rc_tok & 0x3ff;
668
7.45M
            } while (rc);
669
964k
        }
670
852k
    } else {
671
        // non-qmatrix is the common case and allows for additional optimizations
672
852k
        if (dc_tok == 15) {
673
28.3k
            dc_tok = read_golomb(&ts->msac) + 15;
674
28.3k
            if (dbg)
675
0
                printf("Post-dc_residual[%d->%d]: r=%d\n",
676
0
                       dc_tok - 15, dc_tok, ts->msac.rng);
677
678
28.3k
            dc_tok &= 0xfffff;
679
28.3k
            dc_dq = ((dc_dq * dc_tok) & 0xffffff) >> dq_shift;
680
28.3k
            dc_dq = umin(dc_dq, cf_max + dc_sign);
681
823k
        } else {
682
823k
            dc_dq = ((dc_dq * dc_tok) >> dq_shift);
683
823k
            assert(dc_dq <= cf_max);
684
823k
        }
685
852k
        cul_level = dc_tok;
686
852k
        cf[0] = (coef) (dc_sign ? -dc_dq : dc_dq);
687
688
1.28M
        if (rc) ac_noqm: {
689
1.28M
            const unsigned ac_dq = dq_tbl[1];
690
6.01M
            do {
691
6.01M
                const int sign = dav1d_msac_decode_bool_equi(&ts->msac);
692
6.01M
                if (dbg)
693
0
                    printf("Post-sign[%d=%d]: r=%d\n", rc, sign, ts->msac.rng);
694
6.01M
                const unsigned rc_tok = cf[rc];
695
6.01M
                unsigned tok;
696
6.01M
                int dq;
697
698
                // residual
699
6.01M
                if (rc_tok >= (15 << 11)) {
700
94.9k
                    tok = read_golomb(&ts->msac) + 15;
701
94.9k
                    if (dbg)
702
0
                        printf("Post-residual[%d=%d->%d]: r=%d\n",
703
0
                               rc, tok - 15, tok, ts->msac.rng);
704
705
                    // coefficient parsing, see 5.11.39
706
94.9k
                    tok &= 0xfffff;
707
708
                    // dequant, see 7.12.3
709
94.9k
                    dq = ((ac_dq * tok) & 0xffffff) >> dq_shift;
710
94.9k
                    dq = umin(dq, cf_max + sign);
711
5.92M
                } else {
712
                    // cannot exceed cf_max, so we can avoid the clipping
713
5.92M
                    tok = rc_tok >> 11;
714
5.92M
                    dq = ((ac_dq * tok) >> dq_shift);
715
5.92M
                    assert(dq <= cf_max);
716
5.92M
                }
717
6.01M
                cul_level += tok;
718
6.01M
                cf[rc] = (coef) (sign ? -dq : dq);
719
720
6.01M
                rc = rc_tok & 0x3ff; // next non-zero rc, zero if eob
721
6.01M
            } while (rc);
722
1.28M
        }
723
852k
    }
724
725
    // context
726
1.86M
    *res_ctx = umin(cul_level, 63) | dc_sign_level;
727
728
1.86M
    return eob;
729
1.55M
}
730
731
static void read_coef_tree(Dav1dTaskContext *const t,
732
                           const enum BlockSize bs, const Av1Block *const b,
733
                           const enum RectTxfmSize ytx, const int depth,
734
                           const uint16_t *const tx_split,
735
                           const int x_off, const int y_off, pixel *dst)
736
559k
{
737
559k
    const Dav1dFrameContext *const f = t->f;
738
559k
    Dav1dTileState *const ts = t->ts;
739
559k
    const Dav1dDSPContext *const dsp = f->dsp;
740
559k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[ytx];
741
559k
    const int txw = t_dim->w, txh = t_dim->h;
742
743
    /* y_off can be larger than 3 since lossless blocks use TX_4X4 but can't
744
     * be splitted. Aviods an undefined left shift. */
745
559k
    if (depth < 2 && tx_split[depth] &&
746
42.9k
        tx_split[depth] & (1 << (y_off * 4 + x_off)))
747
32.9k
    {
748
32.9k
        const enum RectTxfmSize sub = t_dim->sub;
749
32.9k
        const TxfmInfo *const sub_t_dim = &dav1d_txfm_dimensions[sub];
750
32.9k
        const int txsw = sub_t_dim->w, txsh = sub_t_dim->h;
751
752
32.9k
        read_coef_tree(t, bs, b, sub, depth + 1, tx_split,
753
32.9k
                       x_off * 2 + 0, y_off * 2 + 0, dst);
754
32.9k
        t->bx += txsw;
755
32.9k
        if (txw >= txh && t->bx < f->bw)
756
22.2k
            read_coef_tree(t, bs, b, sub, depth + 1, tx_split, x_off * 2 + 1,
757
22.2k
                           y_off * 2 + 0, dst ? &dst[4 * txsw] : NULL);
758
32.9k
        t->bx -= txsw;
759
32.9k
        t->by += txsh;
760
32.9k
        if (txh >= txw && t->by < f->bh) {
761
22.7k
            if (dst)
762
9.52k
                dst += 4 * txsh * PXSTRIDE(f->cur.stride[0]);
763
22.7k
            read_coef_tree(t, bs, b, sub, depth + 1, tx_split,
764
22.7k
                           x_off * 2 + 0, y_off * 2 + 1, dst);
765
22.7k
            t->bx += txsw;
766
22.7k
            if (txw >= txh && t->bx < f->bw)
767
12.9k
                read_coef_tree(t, bs, b, sub, depth + 1, tx_split, x_off * 2 + 1,
768
12.9k
                               y_off * 2 + 1, dst ? &dst[4 * txsw] : NULL);
769
22.7k
            t->bx -= txsw;
770
22.7k
        }
771
32.9k
        t->by -= txsh;
772
526k
    } else {
773
526k
        const int bx4 = t->bx & 31, by4 = t->by & 31;
774
526k
        enum TxfmType txtp;
775
526k
        uint8_t cf_ctx;
776
526k
        int eob;
777
526k
        coef *cf;
778
779
526k
        if (t->frame_thread.pass) {
780
526k
            const int p = t->frame_thread.pass & 1;
781
526k
            assert(ts->frame_thread[p].cf);
782
526k
            cf = ts->frame_thread[p].cf;
783
526k
            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
784
526k
        } else {
785
0
            cf = bitfn(t->cf);
786
0
        }
787
526k
        if (t->frame_thread.pass != 2) {
788
300k
            eob = decode_coefs(t, &t->a->lcoef[bx4], &t->l.lcoef[by4],
789
300k
                               ytx, bs, b, 0, 0, cf, &txtp, &cf_ctx);
790
300k
            if (DEBUG_BLOCK_INFO)
791
0
                printf("Post-y-cf-blk[tx=%d,txtp=%d,eob=%d]: r=%d\n",
792
0
                       ytx, txtp, eob, ts->msac.rng);
793
300k
            dav1d_memset_likely_pow2(&t->a->lcoef[bx4], cf_ctx, imin(txw, f->bw - t->bx));
794
300k
            dav1d_memset_likely_pow2(&t->l.lcoef[by4], cf_ctx, imin(txh, f->bh - t->by));
795
300k
#define set_ctx(rep_macro) \
796
1.27M
            for (int y = 0; y < txh; y++) { \
797
975k
                rep_macro(txtp_map, 0, txtp); \
798
975k
                txtp_map += 32; \
799
975k
            }
800
300k
            uint8_t *txtp_map = &t->scratch.txtp_map[by4 * 32 + bx4];
801
300k
            case_set_upto16(t_dim->lw);
802
300k
#undef set_ctx
803
300k
            if (t->frame_thread.pass == 1)
804
300k
                *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
805
300k
        } else {
806
225k
            const int cbi = *ts->frame_thread[0].cbi++;
807
225k
            eob  = cbi >> 5;
808
225k
            txtp = cbi & 0x1f;
809
225k
        }
810
526k
        if (!(t->frame_thread.pass & 1)) {
811
225k
            assert(dst);
812
225k
            if (eob >= 0) {
813
136k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
814
0
                    coef_dump(cf, imin(t_dim->h, 8) * 4, imin(t_dim->w, 8) * 4, 3, "dq");
815
136k
                dsp->itx.itxfm_add[ytx][txtp](dst, f->cur.stride[0], cf, eob
816
136k
                                              HIGHBD_CALL_SUFFIX);
817
136k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
818
0
                    hex_dump(dst, f->cur.stride[0], t_dim->w * 4, t_dim->h * 4, "recon");
819
136k
            }
820
225k
        }
821
526k
    }
822
559k
}
823
824
void bytefn(dav1d_read_coef_blocks)(Dav1dTaskContext *const t,
825
                                    const enum BlockSize bs, const Av1Block *const b)
826
2.19M
{
827
2.19M
    const Dav1dFrameContext *const f = t->f;
828
2.19M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
2.19M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
2.19M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
2.19M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
2.19M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
2.19M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
2.19M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
2.19M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
1.97M
                           (bw4 > ss_hor || t->bx & 1) &&
837
1.81M
                           (bh4 > ss_ver || t->by & 1);
838
839
2.19M
    if (b->skip) {
840
1.39M
        BlockContext *const a = t->a;
841
1.39M
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
1.39M
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
1.39M
        if (has_chroma) {
844
1.02M
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
1.02M
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
1.02M
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
1.02M
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
1.02M
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
1.02M
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
1.02M
        }
851
1.39M
        return;
852
1.39M
    }
853
854
794k
    Dav1dTileState *const ts = t->ts;
855
794k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
794k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
794k
    assert(t->frame_thread.pass == 1);
858
794k
    assert(!b->skip);
859
794k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
794k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
794k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
1.62M
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
829k
        const int sub_h4 = imin(h4, 16 + init_y);
865
1.70M
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
879k
            const int sub_w4 = imin(w4, init_x + 16);
867
879k
            int y_off = !!init_y, y, x;
868
1.91M
            for (y = init_y, t->by += init_y; y < sub_h4;
869
1.03M
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
1.03M
            {
871
1.03M
                int x_off = !!init_x;
872
2.69M
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
1.65M
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
1.65M
                {
875
1.65M
                    if (!b->intra) {
876
266k
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
266k
                                       x_off, y_off, NULL);
878
1.39M
                    } else {
879
1.39M
                        uint8_t cf_ctx = 0x40;
880
1.39M
                        enum TxfmType txtp;
881
1.39M
                        const int eob =
882
1.39M
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
1.39M
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
1.39M
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
1.39M
                        if (DEBUG_BLOCK_INFO)
886
0
                            printf("Post-y-cf-blk[tx=%d,txtp=%d,eob=%d]: r=%d\n",
887
0
                                   b->tx, txtp, eob, ts->msac.rng);
888
1.39M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
1.39M
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
1.39M
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
1.39M
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
1.39M
                    }
893
1.65M
                }
894
1.03M
                t->bx -= x;
895
1.03M
            }
896
879k
            t->by -= y;
897
898
879k
            if (!has_chroma) continue;
899
900
715k
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
715k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
2.14M
            for (int pl = 0; pl < 2; pl++) {
903
2.99M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
1.56M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
1.56M
                {
906
3.54M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
1.98M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
1.98M
                    {
909
1.98M
                        uint8_t cf_ctx = 0x40;
910
1.98M
                        enum TxfmType txtp;
911
1.98M
                        if (!b->intra)
912
461k
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
461k
                                                        bx4 + (x << ss_hor)];
914
1.98M
                        const int eob =
915
1.98M
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
1.98M
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
1.98M
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
1.98M
                                         &txtp, &cf_ctx);
919
1.98M
                        if (DEBUG_BLOCK_INFO)
920
0
                            printf("Post-uv-cf-blk[pl=%d,tx=%d,"
921
0
                                   "txtp=%d,eob=%d]: r=%d\n",
922
0
                                   pl, b->uvtx, txtp, eob, ts->msac.rng);
923
1.98M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
1.98M
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
1.98M
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
1.98M
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
1.98M
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
1.98M
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
1.98M
                    }
930
1.56M
                    t->bx -= x << ss_hor;
931
1.56M
                }
932
1.43M
                t->by -= y << ss_ver;
933
1.43M
            }
934
715k
        }
935
829k
    }
936
794k
}
dav1d_read_coef_blocks_8bpc
Line
Count
Source
826
1.09M
{
827
1.09M
    const Dav1dFrameContext *const f = t->f;
828
1.09M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
1.09M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
1.09M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
1.09M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
1.09M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
1.09M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
1.09M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
1.09M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
1.01M
                           (bw4 > ss_hor || t->bx & 1) &&
837
924k
                           (bh4 > ss_ver || t->by & 1);
838
839
1.09M
    if (b->skip) {
840
740k
        BlockContext *const a = t->a;
841
740k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
740k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
740k
        if (has_chroma) {
844
551k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
551k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
551k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
551k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
551k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
551k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
551k
        }
851
740k
        return;
852
740k
    }
853
854
358k
    Dav1dTileState *const ts = t->ts;
855
358k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
358k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
358k
    assert(t->frame_thread.pass == 1);
858
358k
    assert(!b->skip);
859
358k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
358k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
358k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
732k
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
374k
        const int sub_h4 = imin(h4, 16 + init_y);
865
770k
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
396k
            const int sub_w4 = imin(w4, init_x + 16);
867
396k
            int y_off = !!init_y, y, x;
868
852k
            for (y = init_y, t->by += init_y; y < sub_h4;
869
456k
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
456k
            {
871
456k
                int x_off = !!init_x;
872
1.16M
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
711k
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
711k
                {
875
711k
                    if (!b->intra) {
876
156k
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
156k
                                       x_off, y_off, NULL);
878
554k
                    } else {
879
554k
                        uint8_t cf_ctx = 0x40;
880
554k
                        enum TxfmType txtp;
881
554k
                        const int eob =
882
554k
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
554k
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
554k
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
554k
                        if (DEBUG_BLOCK_INFO)
886
0
                            printf("Post-y-cf-blk[tx=%d,txtp=%d,eob=%d]: r=%d\n",
887
0
                                   b->tx, txtp, eob, ts->msac.rng);
888
554k
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
554k
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
554k
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
554k
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
554k
                    }
893
711k
                }
894
456k
                t->bx -= x;
895
456k
            }
896
396k
            t->by -= y;
897
898
396k
            if (!has_chroma) continue;
899
900
325k
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
325k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
975k
            for (int pl = 0; pl < 2; pl++) {
903
1.35M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
706k
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
706k
                {
906
1.56M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
859k
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
859k
                    {
909
859k
                        uint8_t cf_ctx = 0x40;
910
859k
                        enum TxfmType txtp;
911
859k
                        if (!b->intra)
912
275k
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
275k
                                                        bx4 + (x << ss_hor)];
914
859k
                        const int eob =
915
859k
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
859k
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
859k
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
859k
                                         &txtp, &cf_ctx);
919
859k
                        if (DEBUG_BLOCK_INFO)
920
0
                            printf("Post-uv-cf-blk[pl=%d,tx=%d,"
921
0
                                   "txtp=%d,eob=%d]: r=%d\n",
922
0
                                   pl, b->uvtx, txtp, eob, ts->msac.rng);
923
859k
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
859k
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
859k
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
859k
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
859k
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
859k
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
859k
                    }
930
706k
                    t->bx -= x << ss_hor;
931
706k
                }
932
650k
                t->by -= y << ss_ver;
933
650k
            }
934
325k
        }
935
374k
    }
936
358k
}
dav1d_read_coef_blocks_16bpc
Line
Count
Source
826
1.09M
{
827
1.09M
    const Dav1dFrameContext *const f = t->f;
828
1.09M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
1.09M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
1.09M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
1.09M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
1.09M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
1.09M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
1.09M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
1.09M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
967k
                           (bw4 > ss_hor || t->bx & 1) &&
837
893k
                           (bh4 > ss_ver || t->by & 1);
838
839
1.09M
    if (b->skip) {
840
655k
        BlockContext *const a = t->a;
841
655k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
655k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
655k
        if (has_chroma) {
844
474k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
474k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
474k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
474k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
474k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
474k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
474k
        }
851
655k
        return;
852
655k
    }
853
854
435k
    Dav1dTileState *const ts = t->ts;
855
435k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
435k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
435k
    assert(t->frame_thread.pass == 1);
858
435k
    assert(!b->skip);
859
435k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
435k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
435k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
890k
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
454k
        const int sub_h4 = imin(h4, 16 + init_y);
865
938k
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
483k
            const int sub_w4 = imin(w4, init_x + 16);
867
483k
            int y_off = !!init_y, y, x;
868
1.05M
            for (y = init_y, t->by += init_y; y < sub_h4;
869
575k
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
575k
            {
871
575k
                int x_off = !!init_x;
872
1.52M
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
947k
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
947k
                {
875
947k
                    if (!b->intra) {
876
110k
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
110k
                                       x_off, y_off, NULL);
878
837k
                    } else {
879
837k
                        uint8_t cf_ctx = 0x40;
880
837k
                        enum TxfmType txtp;
881
837k
                        const int eob =
882
837k
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
837k
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
837k
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
837k
                        if (DEBUG_BLOCK_INFO)
886
0
                            printf("Post-y-cf-blk[tx=%d,txtp=%d,eob=%d]: r=%d\n",
887
0
                                   b->tx, txtp, eob, ts->msac.rng);
888
837k
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
837k
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
837k
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
837k
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
837k
                    }
893
947k
                }
894
575k
                t->bx -= x;
895
575k
            }
896
483k
            t->by -= y;
897
898
483k
            if (!has_chroma) continue;
899
900
390k
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
390k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
1.17M
            for (int pl = 0; pl < 2; pl++) {
903
1.63M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
855k
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
855k
                {
906
1.97M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
1.12M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
1.12M
                    {
909
1.12M
                        uint8_t cf_ctx = 0x40;
910
1.12M
                        enum TxfmType txtp;
911
1.12M
                        if (!b->intra)
912
186k
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
186k
                                                        bx4 + (x << ss_hor)];
914
1.12M
                        const int eob =
915
1.12M
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
1.12M
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
1.12M
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
1.12M
                                         &txtp, &cf_ctx);
919
1.12M
                        if (DEBUG_BLOCK_INFO)
920
0
                            printf("Post-uv-cf-blk[pl=%d,tx=%d,"
921
0
                                   "txtp=%d,eob=%d]: r=%d\n",
922
0
                                   pl, b->uvtx, txtp, eob, ts->msac.rng);
923
1.12M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
1.12M
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
1.12M
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
1.12M
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
1.12M
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
1.12M
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
1.12M
                    }
930
855k
                    t->bx -= x << ss_hor;
931
855k
                }
932
780k
                t->by -= y << ss_ver;
933
780k
            }
934
390k
        }
935
454k
    }
936
435k
}
937
938
static int mc(Dav1dTaskContext *const t,
939
              pixel *const dst8, int16_t *const dst16, const ptrdiff_t dst_stride,
940
              const int bw4, const int bh4,
941
              const int bx, const int by, const int pl,
942
              const mv mv, const Dav1dThreadPicture *const refp, const int refidx,
943
              const enum Filter2d filter_2d)
944
620k
{
945
620k
    assert((dst8 != NULL) ^ (dst16 != NULL));
946
620k
    const Dav1dFrameContext *const f = t->f;
947
620k
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
948
620k
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
949
620k
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
950
620k
    const int mvx = mv.x, mvy = mv.y;
951
620k
    const int mx = mvx & (15 >> !ss_hor), my = mvy & (15 >> !ss_ver);
952
620k
    ptrdiff_t ref_stride = refp->p.stride[!!pl];
953
620k
    const pixel *ref;
954
955
620k
    if (refp->p.p.w == f->cur.p.w && refp->p.p.h == f->cur.p.h) {
956
505k
        const int dx = bx * h_mul + (mvx >> (3 + ss_hor));
957
505k
        const int dy = by * v_mul + (mvy >> (3 + ss_ver));
958
505k
        int w, h;
959
960
505k
        if (refp->p.data[0] != f->cur.data[0]) { // i.e. not for intrabc
961
363k
            w = (f->cur.p.w + ss_hor) >> ss_hor;
962
363k
            h = (f->cur.p.h + ss_ver) >> ss_ver;
963
363k
        } else {
964
142k
            w = f->bw * 4 >> ss_hor;
965
142k
            h = f->bh * 4 >> ss_ver;
966
142k
        }
967
505k
        if (dx < !!mx * 3 || dy < !!my * 3 ||
968
414k
            dx + bw4 * h_mul + !!mx * 4 > w ||
969
314k
            dy + bh4 * v_mul + !!my * 4 > h)
970
246k
        {
971
246k
            pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
972
246k
            f->dsp->mc.emu_edge(bw4 * h_mul + !!mx * 7, bh4 * v_mul + !!my * 7,
973
246k
                                w, h, dx - !!mx * 3, dy - !!my * 3,
974
246k
                                emu_edge_buf, 192 * sizeof(pixel),
975
246k
                                refp->p.data[pl], ref_stride);
976
246k
            ref = &emu_edge_buf[192 * !!my * 3 + !!mx * 3];
977
246k
            ref_stride = 192 * sizeof(pixel);
978
258k
        } else {
979
258k
            ref = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * dy + dx;
980
258k
        }
981
982
505k
        if (dst8 != NULL) {
983
433k
            f->dsp->mc.mc[filter_2d](dst8, dst_stride, ref, ref_stride, bw4 * h_mul,
984
433k
                                     bh4 * v_mul, mx << !ss_hor, my << !ss_ver
985
433k
                                     HIGHBD_CALL_SUFFIX);
986
433k
        } else {
987
72.2k
            f->dsp->mc.mct[filter_2d](dst16, ref, ref_stride, bw4 * h_mul,
988
72.2k
                                      bh4 * v_mul, mx << !ss_hor, my << !ss_ver
989
72.2k
                                      HIGHBD_CALL_SUFFIX);
990
72.2k
        }
991
505k
    } else {
992
115k
        assert(refp != &f->sr_cur);
993
994
115k
        const int orig_pos_y = (by * v_mul << 4) + mvy * (1 << !ss_ver);
995
115k
        const int orig_pos_x = (bx * h_mul << 4) + mvx * (1 << !ss_hor);
996
230k
#define scale_mv(res, val, scale) do { \
997
230k
            const int64_t tmp = (int64_t)(val) * scale + (scale - 0x4000) * 8; \
998
230k
            res = apply_sign64((int) ((llabs(tmp) + 128) >> 8), tmp) + 32;     \
999
230k
        } while (0)
1000
115k
        int pos_y, pos_x;
1001
115k
        scale_mv(pos_x, orig_pos_x, f->svc[refidx][0].scale);
1002
115k
        scale_mv(pos_y, orig_pos_y, f->svc[refidx][1].scale);
1003
115k
#undef scale_mv
1004
115k
        const int left = pos_x >> 10;
1005
115k
        const int top = pos_y >> 10;
1006
115k
        const int right =
1007
115k
            ((pos_x + (bw4 * h_mul - 1) * f->svc[refidx][0].step) >> 10) + 1;
1008
115k
        const int bottom =
1009
115k
            ((pos_y + (bh4 * v_mul - 1) * f->svc[refidx][1].step) >> 10) + 1;
1010
1011
115k
        if (DEBUG_BLOCK_INFO)
1012
0
            printf("Off %dx%d [%d,%d,%d], size %dx%d [%d,%d]\n",
1013
0
                   left, top, orig_pos_x, f->svc[refidx][0].scale, refidx,
1014
0
                   right-left, bottom-top,
1015
0
                   f->svc[refidx][0].step, f->svc[refidx][1].step);
1016
1017
115k
        const int w = (refp->p.p.w + ss_hor) >> ss_hor;
1018
115k
        const int h = (refp->p.p.h + ss_ver) >> ss_ver;
1019
115k
        if (left < 3 || top < 3 || right + 4 > w || bottom + 4 > h) {
1020
79.1k
            pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
1021
79.1k
            f->dsp->mc.emu_edge(right - left + 7, bottom - top + 7,
1022
79.1k
                                w, h, left - 3, top - 3,
1023
79.1k
                                emu_edge_buf, 320 * sizeof(pixel),
1024
79.1k
                                refp->p.data[pl], ref_stride);
1025
79.1k
            ref = &emu_edge_buf[320 * 3 + 3];
1026
79.1k
            ref_stride = 320 * sizeof(pixel);
1027
79.1k
            if (DEBUG_BLOCK_INFO) printf("Emu\n");
1028
79.1k
        } else {
1029
35.8k
            ref = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * top + left;
1030
35.8k
        }
1031
1032
115k
        if (dst8 != NULL) {
1033
95.6k
            f->dsp->mc.mc_scaled[filter_2d](dst8, dst_stride, ref, ref_stride,
1034
95.6k
                                            bw4 * h_mul, bh4 * v_mul,
1035
95.6k
                                            pos_x & 0x3ff, pos_y & 0x3ff,
1036
95.6k
                                            f->svc[refidx][0].step,
1037
95.6k
                                            f->svc[refidx][1].step
1038
95.6k
                                            HIGHBD_CALL_SUFFIX);
1039
95.6k
        } else {
1040
19.3k
            f->dsp->mc.mct_scaled[filter_2d](dst16, ref, ref_stride,
1041
19.3k
                                             bw4 * h_mul, bh4 * v_mul,
1042
19.3k
                                             pos_x & 0x3ff, pos_y & 0x3ff,
1043
19.3k
                                             f->svc[refidx][0].step,
1044
19.3k
                                             f->svc[refidx][1].step
1045
19.3k
                                             HIGHBD_CALL_SUFFIX);
1046
19.3k
        }
1047
115k
    }
1048
1049
620k
    return 0;
1050
620k
}
1051
1052
static int obmc(Dav1dTaskContext *const t,
1053
                pixel *const dst, const ptrdiff_t dst_stride,
1054
                const uint8_t *const b_dim, const int pl,
1055
                const int bx4, const int by4, const int w4, const int h4)
1056
50.6k
{
1057
50.6k
    assert(!(t->bx & 1) && !(t->by & 1));
1058
50.6k
    const Dav1dFrameContext *const f = t->f;
1059
50.6k
    /*const*/ refmvs_block **r = &t->rt.r[(t->by & 31) + 5];
1060
50.6k
    pixel *const lap = bitfn(t->scratch.lap);
1061
50.6k
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1062
50.6k
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1063
50.6k
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
1064
50.6k
    int res;
1065
1066
50.6k
    if (t->by > t->ts->tiling.row_start &&
1067
42.6k
        (!pl || b_dim[0] * h_mul + b_dim[1] * v_mul >= 16))
1068
37.7k
    {
1069
78.7k
        for (int i = 0, x = 0; x < w4 && i < imin(b_dim[2], 4); ) {
1070
            // only odd blocks are considered for overlap handling, hence +1
1071
40.9k
            const refmvs_block *const a_r = &r[-1][t->bx + x + 1];
1072
40.9k
            const uint8_t *const a_b_dim = dav1d_block_dimensions[a_r->bs];
1073
40.9k
            const int step4 = iclip(a_b_dim[0], 2, 16);
1074
1075
40.9k
            if (a_r->ref.ref[0] > 0) {
1076
40.8k
                const int ow4 = imin(step4, b_dim[0]);
1077
40.8k
                const int oh4 = imin(b_dim[1], 16) >> 1;
1078
40.8k
                res = mc(t, lap, NULL, ow4 * h_mul * sizeof(pixel), ow4, (oh4 * 3 + 3) >> 2,
1079
40.8k
                         t->bx + x, t->by, pl, a_r->mv.mv[0],
1080
40.8k
                         &f->refp[a_r->ref.ref[0] - 1], a_r->ref.ref[0] - 1,
1081
40.8k
                         dav1d_filter_2d[t->a->filter[1][bx4 + x + 1]][t->a->filter[0][bx4 + x + 1]]);
1082
40.8k
                if (res) return res;
1083
40.8k
                f->dsp->mc.blend_h(&dst[x * h_mul], dst_stride, lap,
1084
40.8k
                                   h_mul * ow4, v_mul * oh4);
1085
40.8k
                i++;
1086
40.8k
            }
1087
40.9k
            x += step4;
1088
40.9k
        }
1089
37.7k
    }
1090
1091
50.6k
    if (t->bx > t->ts->tiling.col_start)
1092
87.1k
        for (int i = 0, y = 0; y < h4 && i < imin(b_dim[3], 4); ) {
1093
            // only odd blocks are considered for overlap handling, hence +1
1094
45.0k
            const refmvs_block *const l_r = &r[y + 1][t->bx - 1];
1095
45.0k
            const uint8_t *const l_b_dim = dav1d_block_dimensions[l_r->bs];
1096
45.0k
            const int step4 = iclip(l_b_dim[1], 2, 16);
1097
1098
45.0k
            if (l_r->ref.ref[0] > 0) {
1099
44.6k
                const int ow4 = imin(b_dim[0], 16) >> 1;
1100
44.6k
                const int oh4 = imin(step4, b_dim[1]);
1101
44.6k
                res = mc(t, lap, NULL, h_mul * ow4 * sizeof(pixel), ow4, oh4,
1102
44.6k
                         t->bx, t->by + y, pl, l_r->mv.mv[0],
1103
44.6k
                         &f->refp[l_r->ref.ref[0] - 1], l_r->ref.ref[0] - 1,
1104
44.6k
                         dav1d_filter_2d[t->l.filter[1][by4 + y + 1]][t->l.filter[0][by4 + y + 1]]);
1105
44.6k
                if (res) return res;
1106
44.6k
                f->dsp->mc.blend_v(&dst[y * v_mul * PXSTRIDE(dst_stride)],
1107
44.6k
                                   dst_stride, lap, h_mul * ow4, v_mul * oh4);
1108
44.6k
                i++;
1109
44.6k
            }
1110
45.0k
            y += step4;
1111
45.0k
        }
1112
50.6k
    return 0;
1113
50.6k
}
1114
1115
static int warp_affine(Dav1dTaskContext *const t,
1116
                       pixel *dst8, int16_t *dst16, const ptrdiff_t dstride,
1117
                       const uint8_t *const b_dim, const int pl,
1118
                       const Dav1dThreadPicture *const refp,
1119
                       const Dav1dWarpedMotionParams *const wmp)
1120
18.9k
{
1121
18.9k
    assert((dst8 != NULL) ^ (dst16 != NULL));
1122
18.9k
    const Dav1dFrameContext *const f = t->f;
1123
18.9k
    const Dav1dDSPContext *const dsp = f->dsp;
1124
18.9k
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1125
18.9k
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1126
18.9k
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
1127
18.9k
    assert(!((b_dim[0] * h_mul) & 7) && !((b_dim[1] * v_mul) & 7));
1128
18.9k
    const int32_t *const mat = wmp->matrix;
1129
18.9k
    const int width = (refp->p.p.w + ss_hor) >> ss_hor;
1130
18.9k
    const int height = (refp->p.p.h + ss_ver) >> ss_ver;
1131
1132
59.8k
    for (int y = 0; y < b_dim[1] * v_mul; y += 8) {
1133
40.8k
        const int src_y = t->by * 4 + ((y + 4) << ss_ver);
1134
40.8k
        const int64_t mat3_y = (int64_t) mat[3] * src_y + mat[0];
1135
40.8k
        const int64_t mat5_y = (int64_t) mat[5] * src_y + mat[1];
1136
249k
        for (int x = 0; x < b_dim[0] * h_mul; x += 8) {
1137
            // calculate transformation relative to center of 8x8 block in
1138
            // luma pixel units
1139
208k
            const int src_x = t->bx * 4 + ((x + 4) << ss_hor);
1140
208k
            const int64_t mvx = ((int64_t) mat[2] * src_x + mat3_y) >> ss_hor;
1141
208k
            const int64_t mvy = ((int64_t) mat[4] * src_x + mat5_y) >> ss_ver;
1142
1143
208k
            const int dx = (int) (mvx >> 16) - 4;
1144
208k
            const int mx = (((int) mvx & 0xffff) - wmp->u.p.alpha * 4 -
1145
208k
                                                   wmp->u.p.beta  * 7) & ~0x3f;
1146
208k
            const int dy = (int) (mvy >> 16) - 4;
1147
208k
            const int my = (((int) mvy & 0xffff) - wmp->u.p.gamma * 4 -
1148
208k
                                                   wmp->u.p.delta * 4) & ~0x3f;
1149
1150
208k
            const pixel *ref_ptr;
1151
208k
            ptrdiff_t ref_stride = refp->p.stride[!!pl];
1152
1153
208k
            if (dx < 3 || dx + 8 + 4 > width || dy < 3 || dy + 8 + 4 > height) {
1154
151k
                pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
1155
151k
                f->dsp->mc.emu_edge(15, 15, width, height, dx - 3, dy - 3,
1156
151k
                                    emu_edge_buf, 32 * sizeof(pixel),
1157
151k
                                    refp->p.data[pl], ref_stride);
1158
151k
                ref_ptr = &emu_edge_buf[32 * 3 + 3];
1159
151k
                ref_stride = 32 * sizeof(pixel);
1160
151k
            } else {
1161
56.7k
                ref_ptr = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * dy + dx;
1162
56.7k
            }
1163
208k
            if (dst16 != NULL)
1164
25.3k
                dsp->mc.warp8x8t(&dst16[x], dstride, ref_ptr, ref_stride,
1165
25.3k
                                 wmp->u.abcd, mx, my HIGHBD_CALL_SUFFIX);
1166
183k
            else
1167
183k
                dsp->mc.warp8x8(&dst8[x], dstride, ref_ptr, ref_stride,
1168
183k
                                wmp->u.abcd, mx, my HIGHBD_CALL_SUFFIX);
1169
208k
        }
1170
40.8k
        if (dst8) dst8  += 8 * PXSTRIDE(dstride);
1171
9.84k
        else      dst16 += 8 * dstride;
1172
40.8k
    }
1173
18.9k
    return 0;
1174
18.9k
}
1175
1176
void bytefn(dav1d_recon_b_intra)(Dav1dTaskContext *const t, const enum BlockSize bs,
1177
                                 const enum EdgeFlags intra_edge_flags,
1178
                                 const Av1Block *const b)
1179
1.26M
{
1180
1.26M
    Dav1dTileState *const ts = t->ts;
1181
1.26M
    const Dav1dFrameContext *const f = t->f;
1182
1.26M
    const Dav1dDSPContext *const dsp = f->dsp;
1183
1.26M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
1.26M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
1.26M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
1.26M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
1.26M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
1.26M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
1.26M
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
1.26M
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
1.26M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
1.18M
                           (bw4 > ss_hor || t->bx & 1) &&
1193
1.09M
                           (bh4 > ss_ver || t->by & 1);
1194
1.26M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
1.26M
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
1.26M
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
1.26M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
1.26M
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
2.57M
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
1.30M
        const int sub_h4 = imin(h4, 16 + init_y);
1205
1.30M
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
2.68M
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
1.37M
            if (b->pal_sz[0]) {
1208
7.81k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
7.81k
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
7.81k
                const uint8_t *pal_idx;
1211
7.81k
                if (t->frame_thread.pass) {
1212
7.81k
                    const int p = t->frame_thread.pass & 1;
1213
7.81k
                    assert(ts->frame_thread[p].pal_idx);
1214
7.81k
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
7.81k
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
7.81k
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
7.81k
                const pixel *const pal = t->frame_thread.pass ?
1220
7.81k
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
7.81k
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
7.81k
                    bytefn(t->scratch.pal)[0];
1223
7.81k
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
7.81k
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
7.81k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1226
0
                    hex_dump(dst, PXSTRIDE(f->cur.stride[0]),
1227
0
                             bw4 * 4, bh4 * 4, "y-pal-pred");
1228
7.81k
            }
1229
1230
1.37M
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
1.37M
                                     sm_flag(&t->l, by4) |
1232
1.37M
                                     intra_edge_filter_flag);
1233
1.37M
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
1.30M
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
1.37M
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
1.30M
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
1.37M
            int y, x;
1238
1.37M
            const int sub_w4 = imin(w4, init_x + 16);
1239
3.03M
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
1.66M
                 y += t_dim->h, t->by += t_dim->h)
1241
1.66M
            {
1242
1.66M
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
1.66M
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
1.66M
                                    t->bx + init_x);
1245
4.40M
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
2.74M
                     x += t_dim->w, t->bx += t_dim->w)
1247
2.73M
                {
1248
2.73M
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
2.72M
                    int angle = b->y_angle;
1251
2.72M
                    const enum EdgeFlags edge_flags =
1252
2.72M
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
1.97M
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
2.72M
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
1.85M
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
2.72M
                    const pixel *top_sb_edge = NULL;
1257
2.72M
                    if (!(t->by & (f->sb_step - 1))) {
1258
495k
                        top_sb_edge = f->ipred_edge[0];
1259
495k
                        const int sby = t->by >> f->sb_shift;
1260
495k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
495k
                    }
1262
2.72M
                    const enum IntraPredMode m =
1263
2.72M
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
2.72M
                                                          t->bx > ts->tiling.col_start,
1265
2.72M
                                                          t->by,
1266
2.72M
                                                          t->by > ts->tiling.row_start,
1267
2.72M
                                                          ts->tiling.col_end,
1268
2.72M
                                                          ts->tiling.row_end,
1269
2.72M
                                                          edge_flags, dst,
1270
2.72M
                                                          f->cur.stride[0], top_sb_edge,
1271
2.72M
                                                          b->y_mode, &angle,
1272
2.72M
                                                          t_dim->w, t_dim->h,
1273
2.72M
                                                          f->seq_hdr->intra_edge_filter,
1274
2.72M
                                                          edge HIGHBD_CALL_SUFFIX);
1275
2.72M
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
2.72M
                                             t_dim->w * 4, t_dim->h * 4,
1277
2.72M
                                             angle | intra_flags,
1278
2.72M
                                             4 * f->bw - 4 * t->bx,
1279
2.72M
                                             4 * f->bh - 4 * t->by
1280
2.72M
                                             HIGHBD_CALL_SUFFIX);
1281
1282
2.72M
                    if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1283
0
                        hex_dump(edge - t_dim->h * 4, t_dim->h * 4,
1284
0
                                 t_dim->h * 4, 2, "l");
1285
0
                        hex_dump(edge, 0, 1, 1, "tl");
1286
0
                        hex_dump(edge + 1, t_dim->w * 4,
1287
0
                                 t_dim->w * 4, 2, "t");
1288
0
                        hex_dump(dst, f->cur.stride[0],
1289
0
                                 t_dim->w * 4, t_dim->h * 4, "y-intra-pred");
1290
0
                    }
1291
1292
2.74M
                skip_y_pred: {}
1293
2.74M
                    if (!b->skip) {
1294
767k
                        coef *cf;
1295
767k
                        int eob;
1296
767k
                        enum TxfmType txtp;
1297
767k
                        if (t->frame_thread.pass) {
1298
767k
                            const int p = t->frame_thread.pass & 1;
1299
767k
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
767k
                            cf = ts->frame_thread[p].cf;
1301
767k
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
767k
                            eob  = cbi >> 5;
1303
767k
                            txtp = cbi & 0x1f;
1304
767k
                        } else {
1305
0
                            uint8_t cf_ctx;
1306
0
                            cf = bitfn(t->cf);
1307
0
                            eob = decode_coefs(t, &t->a->lcoef[bx4 + x],
1308
0
                                               &t->l.lcoef[by4 + y], b->tx, bs,
1309
0
                                               b, 1, 0, cf, &txtp, &cf_ctx);
1310
0
                            if (DEBUG_BLOCK_INFO)
1311
0
                                printf("Post-y-cf-blk[tx=%d,txtp=%d,eob=%d]: r=%d\n",
1312
0
                                       b->tx, txtp, eob, ts->msac.rng);
1313
0
                            dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
1314
0
                            dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
1315
0
                        }
1316
767k
                        if (eob >= 0) {
1317
541k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1318
0
                                coef_dump(cf, imin(t_dim->h, 8) * 4,
1319
0
                                          imin(t_dim->w, 8) * 4, 3, "dq");
1320
541k
                            dsp->itx.itxfm_add[b->tx]
1321
541k
                                              [txtp](dst,
1322
541k
                                                     f->cur.stride[0],
1323
541k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
541k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1325
0
                                hex_dump(dst, f->cur.stride[0],
1326
0
                                         t_dim->w * 4, t_dim->h * 4, "recon");
1327
541k
                        }
1328
1.97M
                    } else if (!t->frame_thread.pass) {
1329
0
                        dav1d_memset_pow2[t_dim->lw](&t->a->lcoef[bx4 + x], 0x40);
1330
0
                        dav1d_memset_pow2[t_dim->lh](&t->l.lcoef[by4 + y], 0x40);
1331
0
                    }
1332
2.74M
                    dst += 4 * t_dim->w;
1333
2.74M
                }
1334
1.66M
                t->bx -= x;
1335
1.66M
            }
1336
1.37M
            t->by -= y;
1337
1338
1.37M
            if (!has_chroma) continue;
1339
1340
1.10M
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
1.10M
            if (b->uv_mode == CFL_PRED) {
1343
202k
                assert(!init_x && !init_y);
1344
1345
202k
                int16_t *const ac = t->scratch.ac;
1346
202k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
202k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
202k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
202k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
202k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
202k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
202k
                const int furthest_r =
1354
202k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
202k
                const int furthest_b =
1356
202k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
202k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
202k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
202k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
202k
                                                         cbw4 * 4, cbh4 * 4);
1361
606k
                for (int pl = 0; pl < 2; pl++) {
1362
404k
                    if (!b->cfl_alpha[pl]) continue;
1363
323k
                    int angle = 0;
1364
323k
                    const pixel *top_sb_edge = NULL;
1365
323k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
69.0k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
69.0k
                        const int sby = t->by >> f->sb_shift;
1368
69.0k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
69.0k
                    }
1370
323k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
323k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
323k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
323k
                    const enum IntraPredMode m =
1374
323k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
323k
                                                          ypos, ypos > ystart,
1376
323k
                                                          ts->tiling.col_end >> ss_hor,
1377
323k
                                                          ts->tiling.row_end >> ss_ver,
1378
323k
                                                          0, uv_dst[pl], stride,
1379
323k
                                                          top_sb_edge, DC_PRED, &angle,
1380
323k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
323k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
323k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
323k
                                           uv_t_dim->w * 4,
1384
323k
                                           uv_t_dim->h * 4,
1385
323k
                                           ac, b->cfl_alpha[pl]
1386
323k
                                           HIGHBD_CALL_SUFFIX);
1387
323k
                }
1388
202k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1389
0
                    ac_dump(ac, 4*cbw4, 4*cbh4, "ac");
1390
0
                    hex_dump(uv_dst[0], stride, cbw4 * 4, cbh4 * 4, "u-cfl-pred");
1391
0
                    hex_dump(uv_dst[1], stride, cbw4 * 4, cbh4 * 4, "v-cfl-pred");
1392
0
                }
1393
904k
            } else if (b->pal_sz[1]) {
1394
3.25k
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
3.25k
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
3.25k
                const pixel (*pal)[8];
1397
3.25k
                const uint8_t *pal_idx;
1398
3.25k
                if (t->frame_thread.pass) {
1399
3.25k
                    const int p = t->frame_thread.pass & 1;
1400
3.25k
                    assert(ts->frame_thread[p].pal_idx);
1401
3.25k
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
3.25k
                                              ((t->bx >> 1) + (t->by & 1))];
1403
3.25k
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
3.25k
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
3.25k
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
3.25k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
3.25k
                                       f->cur.stride[1], pal[1],
1412
3.25k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
3.25k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
3.25k
                                       f->cur.stride[1], pal[2],
1415
3.25k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
3.25k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1417
0
                    hex_dump(((pixel *) f->cur.data[1]) + uv_dstoff,
1418
0
                             PXSTRIDE(f->cur.stride[1]),
1419
0
                             cbw4 * 4, cbh4 * 4, "u-pal-pred");
1420
0
                    hex_dump(((pixel *) f->cur.data[2]) + uv_dstoff,
1421
0
                             PXSTRIDE(f->cur.stride[1]),
1422
0
                             cbw4 * 4, cbh4 * 4, "v-pal-pred");
1423
0
                }
1424
3.25k
            }
1425
1426
1.10M
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
1.10M
                                 sm_uv_flag(&t->l, cby4);
1428
1.10M
            const int uv_sb_has_tr =
1429
1.10M
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
1.04M
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
1.10M
            const int uv_sb_has_bl =
1432
1.10M
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
1.04M
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
1.10M
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
3.31M
            for (int pl = 0; pl < 2; pl++) {
1436
4.54M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
2.33M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
2.33M
                {
1439
2.33M
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
2.33M
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
2.33M
                                        ((t->bx + init_x) >> ss_hor));
1442
5.10M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
1443
2.76M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
1444
2.76M
                    {
1445
2.76M
                        if ((b->uv_mode == CFL_PRED && b->cfl_alpha[pl]) ||
1446
2.44M
                            b->pal_sz[1])
1447
329k
                        {
1448
329k
                            goto skip_uv_pred;
1449
329k
                        }
1450
1451
2.43M
                        int angle = b->uv_angle;
1452
                        // this probably looks weird because we're using
1453
                        // luma flags in a chroma loop, but that's because
1454
                        // prepare_intra_edges() expects luma flags as input
1455
2.43M
                        const enum EdgeFlags edge_flags =
1456
2.43M
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
1.08M
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
1.71M
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
2.43M
                            ((x > (init_x >> ss_hor) ||
1460
2.00M
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
1.55M
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
2.43M
                        const pixel *top_sb_edge = NULL;
1463
2.43M
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
651k
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
651k
                            const int sby = t->by >> f->sb_shift;
1466
651k
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
651k
                        }
1468
2.43M
                        const enum IntraPredMode uv_mode =
1469
2.43M
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
2.43M
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
2.43M
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
2.43M
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
2.43M
                        const enum IntraPredMode m =
1474
2.43M
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
2.43M
                                                              ypos, ypos > ystart,
1476
2.43M
                                                              ts->tiling.col_end >> ss_hor,
1477
2.43M
                                                              ts->tiling.row_end >> ss_ver,
1478
2.43M
                                                              edge_flags, dst, stride,
1479
2.43M
                                                              top_sb_edge, uv_mode,
1480
2.43M
                                                              &angle, uv_t_dim->w,
1481
2.43M
                                                              uv_t_dim->h,
1482
2.43M
                                                              f->seq_hdr->intra_edge_filter,
1483
2.43M
                                                              edge HIGHBD_CALL_SUFFIX);
1484
2.43M
                        angle |= intra_edge_filter_flag;
1485
2.43M
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
2.43M
                                                 uv_t_dim->w * 4,
1487
2.43M
                                                 uv_t_dim->h * 4,
1488
2.43M
                                                 angle | sm_uv_fl,
1489
2.43M
                                                 (4 * f->bw + ss_hor -
1490
2.43M
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
2.43M
                                                 (4 * f->bh + ss_ver -
1492
2.43M
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
2.43M
                                                 HIGHBD_CALL_SUFFIX);
1494
2.43M
                        if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1495
0
                            hex_dump(edge - uv_t_dim->h * 4, uv_t_dim->h * 4,
1496
0
                                     uv_t_dim->h * 4, 2, "l");
1497
0
                            hex_dump(edge, 0, 1, 1, "tl");
1498
0
                            hex_dump(edge + 1, uv_t_dim->w * 4,
1499
0
                                     uv_t_dim->w * 4, 2, "t");
1500
0
                            hex_dump(dst, stride, uv_t_dim->w * 4,
1501
0
                                     uv_t_dim->h * 4, pl ? "v-intra-pred" : "u-intra-pred");
1502
0
                        }
1503
1504
2.76M
                    skip_uv_pred: {}
1505
2.76M
                        if (!b->skip) {
1506
877k
                            enum TxfmType txtp;
1507
877k
                            int eob;
1508
877k
                            coef *cf;
1509
877k
                            if (t->frame_thread.pass) {
1510
877k
                                const int p = t->frame_thread.pass & 1;
1511
877k
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
877k
                                cf = ts->frame_thread[p].cf;
1513
877k
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
877k
                                eob  = cbi >> 5;
1515
877k
                                txtp = cbi & 0x1f;
1516
877k
                            } else {
1517
0
                                uint8_t cf_ctx;
1518
0
                                cf = bitfn(t->cf);
1519
0
                                eob = decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
1520
0
                                                   &t->l.ccoef[pl][cby4 + y],
1521
0
                                                   b->uvtx, bs, b, 1, 1 + pl, cf,
1522
0
                                                   &txtp, &cf_ctx);
1523
0
                                if (DEBUG_BLOCK_INFO)
1524
0
                                    printf("Post-uv-cf-blk[pl=%d,tx=%d,"
1525
0
                                           "txtp=%d,eob=%d]: r=%d [x=%d,cbx4=%d]\n",
1526
0
                                           pl, b->uvtx, txtp, eob, ts->msac.rng, x, cbx4);
1527
0
                                int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
1528
0
                                int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
1529
0
                                dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
1530
0
                                dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
1531
0
                            }
1532
877k
                            if (eob >= 0) {
1533
287k
                                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1534
0
                                    coef_dump(cf, uv_t_dim->h * 4,
1535
0
                                              uv_t_dim->w * 4, 3, "dq");
1536
287k
                                dsp->itx.itxfm_add[b->uvtx]
1537
287k
                                                  [txtp](dst, stride,
1538
287k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
287k
                                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1540
0
                                    hex_dump(dst, stride, uv_t_dim->w * 4,
1541
0
                                             uv_t_dim->h * 4, "recon");
1542
287k
                            }
1543
1.89M
                        } else if (!t->frame_thread.pass) {
1544
0
                            dav1d_memset_pow2[uv_t_dim->lw](&t->a->ccoef[pl][cbx4 + x], 0x40);
1545
0
                            dav1d_memset_pow2[uv_t_dim->lh](&t->l.ccoef[pl][cby4 + y], 0x40);
1546
0
                        }
1547
2.76M
                        dst += uv_t_dim->w * 4;
1548
2.76M
                    }
1549
2.33M
                    t->bx -= x << ss_hor;
1550
2.33M
                }
1551
2.20M
                t->by -= y << ss_ver;
1552
2.20M
            }
1553
1.10M
        }
1554
1.30M
    }
1555
1.26M
}
dav1d_recon_b_intra_8bpc
Line
Count
Source
1179
554k
{
1180
554k
    Dav1dTileState *const ts = t->ts;
1181
554k
    const Dav1dFrameContext *const f = t->f;
1182
554k
    const Dav1dDSPContext *const dsp = f->dsp;
1183
554k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
554k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
554k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
554k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
554k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
554k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
554k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
554k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
554k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
533k
                           (bw4 > ss_hor || t->bx & 1) &&
1193
492k
                           (bh4 > ss_ver || t->by & 1);
1194
554k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
554k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
554k
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
554k
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
554k
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
1.12M
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
573k
        const int sub_h4 = imin(h4, 16 + init_y);
1205
573k
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
1.17M
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
605k
            if (b->pal_sz[0]) {
1208
4.21k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
4.21k
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
4.21k
                const uint8_t *pal_idx;
1211
4.21k
                if (t->frame_thread.pass) {
1212
4.21k
                    const int p = t->frame_thread.pass & 1;
1213
4.21k
                    assert(ts->frame_thread[p].pal_idx);
1214
4.21k
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
4.21k
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
4.21k
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
4.21k
                const pixel *const pal = t->frame_thread.pass ?
1220
4.21k
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
4.21k
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
4.21k
                    bytefn(t->scratch.pal)[0];
1223
4.21k
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
4.21k
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
4.21k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1226
0
                    hex_dump(dst, PXSTRIDE(f->cur.stride[0]),
1227
0
                             bw4 * 4, bh4 * 4, "y-pal-pred");
1228
4.21k
            }
1229
1230
605k
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
605k
                                     sm_flag(&t->l, by4) |
1232
605k
                                     intra_edge_filter_flag);
1233
605k
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
573k
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
605k
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
573k
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
605k
            int y, x;
1238
605k
            const int sub_w4 = imin(w4, init_x + 16);
1239
1.30M
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
700k
                 y += t_dim->h, t->by += t_dim->h)
1241
699k
            {
1242
699k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
699k
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
699k
                                    t->bx + init_x);
1245
1.76M
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
1.06M
                     x += t_dim->w, t->bx += t_dim->w)
1247
1.06M
                {
1248
1.06M
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
1.06M
                    int angle = b->y_angle;
1251
1.06M
                    const enum EdgeFlags edge_flags =
1252
1.06M
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
773k
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
1.06M
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
711k
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
1.06M
                    const pixel *top_sb_edge = NULL;
1257
1.06M
                    if (!(t->by & (f->sb_step - 1))) {
1258
226k
                        top_sb_edge = f->ipred_edge[0];
1259
226k
                        const int sby = t->by >> f->sb_shift;
1260
226k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
226k
                    }
1262
1.06M
                    const enum IntraPredMode m =
1263
1.06M
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
1.06M
                                                          t->bx > ts->tiling.col_start,
1265
1.06M
                                                          t->by,
1266
1.06M
                                                          t->by > ts->tiling.row_start,
1267
1.06M
                                                          ts->tiling.col_end,
1268
1.06M
                                                          ts->tiling.row_end,
1269
1.06M
                                                          edge_flags, dst,
1270
1.06M
                                                          f->cur.stride[0], top_sb_edge,
1271
1.06M
                                                          b->y_mode, &angle,
1272
1.06M
                                                          t_dim->w, t_dim->h,
1273
1.06M
                                                          f->seq_hdr->intra_edge_filter,
1274
1.06M
                                                          edge HIGHBD_CALL_SUFFIX);
1275
1.06M
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
1.06M
                                             t_dim->w * 4, t_dim->h * 4,
1277
1.06M
                                             angle | intra_flags,
1278
1.06M
                                             4 * f->bw - 4 * t->bx,
1279
1.06M
                                             4 * f->bh - 4 * t->by
1280
1.06M
                                             HIGHBD_CALL_SUFFIX);
1281
1282
1.06M
                    if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1283
0
                        hex_dump(edge - t_dim->h * 4, t_dim->h * 4,
1284
0
                                 t_dim->h * 4, 2, "l");
1285
0
                        hex_dump(edge, 0, 1, 1, "tl");
1286
0
                        hex_dump(edge + 1, t_dim->w * 4,
1287
0
                                 t_dim->w * 4, 2, "t");
1288
0
                        hex_dump(dst, f->cur.stride[0],
1289
0
                                 t_dim->w * 4, t_dim->h * 4, "y-intra-pred");
1290
0
                    }
1291
1292
1.06M
                skip_y_pred: {}
1293
1.06M
                    if (!b->skip) {
1294
266k
                        coef *cf;
1295
266k
                        int eob;
1296
266k
                        enum TxfmType txtp;
1297
266k
                        if (t->frame_thread.pass) {
1298
266k
                            const int p = t->frame_thread.pass & 1;
1299
266k
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
266k
                            cf = ts->frame_thread[p].cf;
1301
266k
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
266k
                            eob  = cbi >> 5;
1303
266k
                            txtp = cbi & 0x1f;
1304
266k
                        } else {
1305
0
                            uint8_t cf_ctx;
1306
0
                            cf = bitfn(t->cf);
1307
0
                            eob = decode_coefs(t, &t->a->lcoef[bx4 + x],
1308
0
                                               &t->l.lcoef[by4 + y], b->tx, bs,
1309
0
                                               b, 1, 0, cf, &txtp, &cf_ctx);
1310
0
                            if (DEBUG_BLOCK_INFO)
1311
0
                                printf("Post-y-cf-blk[tx=%d,txtp=%d,eob=%d]: r=%d\n",
1312
0
                                       b->tx, txtp, eob, ts->msac.rng);
1313
0
                            dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
1314
0
                            dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
1315
0
                        }
1316
266k
                        if (eob >= 0) {
1317
189k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1318
0
                                coef_dump(cf, imin(t_dim->h, 8) * 4,
1319
0
                                          imin(t_dim->w, 8) * 4, 3, "dq");
1320
189k
                            dsp->itx.itxfm_add[b->tx]
1321
189k
                                              [txtp](dst,
1322
189k
                                                     f->cur.stride[0],
1323
189k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
189k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1325
0
                                hex_dump(dst, f->cur.stride[0],
1326
0
                                         t_dim->w * 4, t_dim->h * 4, "recon");
1327
189k
                        }
1328
801k
                    } else if (!t->frame_thread.pass) {
1329
0
                        dav1d_memset_pow2[t_dim->lw](&t->a->lcoef[bx4 + x], 0x40);
1330
0
                        dav1d_memset_pow2[t_dim->lh](&t->l.lcoef[by4 + y], 0x40);
1331
0
                    }
1332
1.06M
                    dst += 4 * t_dim->w;
1333
1.06M
                }
1334
700k
                t->bx -= x;
1335
700k
            }
1336
605k
            t->by -= y;
1337
1338
605k
            if (!has_chroma) continue;
1339
1340
501k
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
501k
            if (b->uv_mode == CFL_PRED) {
1343
93.3k
                assert(!init_x && !init_y);
1344
1345
93.3k
                int16_t *const ac = t->scratch.ac;
1346
93.3k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
93.3k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
93.3k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
93.3k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
93.3k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
93.3k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
93.3k
                const int furthest_r =
1354
93.3k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
93.3k
                const int furthest_b =
1356
93.3k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
93.3k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
93.3k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
93.3k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
93.3k
                                                         cbw4 * 4, cbh4 * 4);
1361
280k
                for (int pl = 0; pl < 2; pl++) {
1362
186k
                    if (!b->cfl_alpha[pl]) continue;
1363
151k
                    int angle = 0;
1364
151k
                    const pixel *top_sb_edge = NULL;
1365
151k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
34.2k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
34.2k
                        const int sby = t->by >> f->sb_shift;
1368
34.2k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
34.2k
                    }
1370
151k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
151k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
151k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
151k
                    const enum IntraPredMode m =
1374
151k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
151k
                                                          ypos, ypos > ystart,
1376
151k
                                                          ts->tiling.col_end >> ss_hor,
1377
151k
                                                          ts->tiling.row_end >> ss_ver,
1378
151k
                                                          0, uv_dst[pl], stride,
1379
151k
                                                          top_sb_edge, DC_PRED, &angle,
1380
151k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
151k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
151k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
151k
                                           uv_t_dim->w * 4,
1384
151k
                                           uv_t_dim->h * 4,
1385
151k
                                           ac, b->cfl_alpha[pl]
1386
151k
                                           HIGHBD_CALL_SUFFIX);
1387
151k
                }
1388
93.3k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1389
0
                    ac_dump(ac, 4*cbw4, 4*cbh4, "ac");
1390
0
                    hex_dump(uv_dst[0], stride, cbw4 * 4, cbh4 * 4, "u-cfl-pred");
1391
0
                    hex_dump(uv_dst[1], stride, cbw4 * 4, cbh4 * 4, "v-cfl-pred");
1392
0
                }
1393
407k
            } else if (b->pal_sz[1]) {
1394
2.14k
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
2.14k
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
2.14k
                const pixel (*pal)[8];
1397
2.14k
                const uint8_t *pal_idx;
1398
2.14k
                if (t->frame_thread.pass) {
1399
2.14k
                    const int p = t->frame_thread.pass & 1;
1400
2.14k
                    assert(ts->frame_thread[p].pal_idx);
1401
2.14k
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
2.14k
                                              ((t->bx >> 1) + (t->by & 1))];
1403
2.14k
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
2.14k
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
2.14k
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
2.14k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
2.14k
                                       f->cur.stride[1], pal[1],
1412
2.14k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
2.14k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
2.14k
                                       f->cur.stride[1], pal[2],
1415
2.14k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
2.14k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1417
0
                    hex_dump(((pixel *) f->cur.data[1]) + uv_dstoff,
1418
0
                             PXSTRIDE(f->cur.stride[1]),
1419
0
                             cbw4 * 4, cbh4 * 4, "u-pal-pred");
1420
0
                    hex_dump(((pixel *) f->cur.data[2]) + uv_dstoff,
1421
0
                             PXSTRIDE(f->cur.stride[1]),
1422
0
                             cbw4 * 4, cbh4 * 4, "v-pal-pred");
1423
0
                }
1424
2.14k
            }
1425
1426
501k
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
501k
                                 sm_uv_flag(&t->l, cby4);
1428
501k
            const int uv_sb_has_tr =
1429
501k
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
469k
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
501k
            const int uv_sb_has_bl =
1432
501k
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
469k
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
501k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
1.50M
            for (int pl = 0; pl < 2; pl++) {
1436
2.04M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
1.04M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
1.04M
                {
1439
1.04M
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
1.04M
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
1.04M
                                        ((t->bx + init_x) >> ss_hor));
1442
2.21M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
1443
1.17M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
1444
1.17M
                    {
1445
1.17M
                        if ((b->uv_mode == CFL_PRED && b->cfl_alpha[pl]) ||
1446
1.02M
                            b->pal_sz[1])
1447
155k
                        {
1448
155k
                            goto skip_uv_pred;
1449
155k
                        }
1450
1451
1.01M
                        int angle = b->uv_angle;
1452
                        // this probably looks weird because we're using
1453
                        // luma flags in a chroma loop, but that's because
1454
                        // prepare_intra_edges() expects luma flags as input
1455
1.01M
                        const enum EdgeFlags edge_flags =
1456
1.01M
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
399k
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
725k
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
1.01M
                            ((x > (init_x >> ss_hor) ||
1460
890k
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
633k
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
1.01M
                        const pixel *top_sb_edge = NULL;
1463
1.01M
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
317k
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
317k
                            const int sby = t->by >> f->sb_shift;
1466
317k
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
317k
                        }
1468
1.01M
                        const enum IntraPredMode uv_mode =
1469
1.01M
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
1.01M
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
1.01M
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
1.01M
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
1.01M
                        const enum IntraPredMode m =
1474
1.01M
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
1.01M
                                                              ypos, ypos > ystart,
1476
1.01M
                                                              ts->tiling.col_end >> ss_hor,
1477
1.01M
                                                              ts->tiling.row_end >> ss_ver,
1478
1.01M
                                                              edge_flags, dst, stride,
1479
1.01M
                                                              top_sb_edge, uv_mode,
1480
1.01M
                                                              &angle, uv_t_dim->w,
1481
1.01M
                                                              uv_t_dim->h,
1482
1.01M
                                                              f->seq_hdr->intra_edge_filter,
1483
1.01M
                                                              edge HIGHBD_CALL_SUFFIX);
1484
1.01M
                        angle |= intra_edge_filter_flag;
1485
1.01M
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
1.01M
                                                 uv_t_dim->w * 4,
1487
1.01M
                                                 uv_t_dim->h * 4,
1488
1.01M
                                                 angle | sm_uv_fl,
1489
1.01M
                                                 (4 * f->bw + ss_hor -
1490
1.01M
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
1.01M
                                                 (4 * f->bh + ss_ver -
1492
1.01M
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
1.01M
                                                 HIGHBD_CALL_SUFFIX);
1494
1.01M
                        if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1495
0
                            hex_dump(edge - uv_t_dim->h * 4, uv_t_dim->h * 4,
1496
0
                                     uv_t_dim->h * 4, 2, "l");
1497
0
                            hex_dump(edge, 0, 1, 1, "tl");
1498
0
                            hex_dump(edge + 1, uv_t_dim->w * 4,
1499
0
                                     uv_t_dim->w * 4, 2, "t");
1500
0
                            hex_dump(dst, stride, uv_t_dim->w * 4,
1501
0
                                     uv_t_dim->h * 4, pl ? "v-intra-pred" : "u-intra-pred");
1502
0
                        }
1503
1504
1.17M
                    skip_uv_pred: {}
1505
1.17M
                        if (!b->skip) {
1506
317k
                            enum TxfmType txtp;
1507
317k
                            int eob;
1508
317k
                            coef *cf;
1509
317k
                            if (t->frame_thread.pass) {
1510
317k
                                const int p = t->frame_thread.pass & 1;
1511
317k
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
317k
                                cf = ts->frame_thread[p].cf;
1513
317k
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
317k
                                eob  = cbi >> 5;
1515
317k
                                txtp = cbi & 0x1f;
1516
317k
                            } else {
1517
0
                                uint8_t cf_ctx;
1518
0
                                cf = bitfn(t->cf);
1519
0
                                eob = decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
1520
0
                                                   &t->l.ccoef[pl][cby4 + y],
1521
0
                                                   b->uvtx, bs, b, 1, 1 + pl, cf,
1522
0
                                                   &txtp, &cf_ctx);
1523
0
                                if (DEBUG_BLOCK_INFO)
1524
0
                                    printf("Post-uv-cf-blk[pl=%d,tx=%d,"
1525
0
                                           "txtp=%d,eob=%d]: r=%d [x=%d,cbx4=%d]\n",
1526
0
                                           pl, b->uvtx, txtp, eob, ts->msac.rng, x, cbx4);
1527
0
                                int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
1528
0
                                int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
1529
0
                                dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
1530
0
                                dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
1531
0
                            }
1532
317k
                            if (eob >= 0) {
1533
125k
                                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1534
0
                                    coef_dump(cf, uv_t_dim->h * 4,
1535
0
                                              uv_t_dim->w * 4, 3, "dq");
1536
125k
                                dsp->itx.itxfm_add[b->uvtx]
1537
125k
                                                  [txtp](dst, stride,
1538
125k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
125k
                                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1540
0
                                    hex_dump(dst, stride, uv_t_dim->w * 4,
1541
0
                                             uv_t_dim->h * 4, "recon");
1542
125k
                            }
1543
855k
                        } else if (!t->frame_thread.pass) {
1544
0
                            dav1d_memset_pow2[uv_t_dim->lw](&t->a->ccoef[pl][cbx4 + x], 0x40);
1545
0
                            dav1d_memset_pow2[uv_t_dim->lh](&t->l.ccoef[pl][cby4 + y], 0x40);
1546
0
                        }
1547
1.17M
                        dst += uv_t_dim->w * 4;
1548
1.17M
                    }
1549
1.04M
                    t->bx -= x << ss_hor;
1550
1.04M
                }
1551
1.00M
                t->by -= y << ss_ver;
1552
1.00M
            }
1553
501k
        }
1554
573k
    }
1555
554k
}
dav1d_recon_b_intra_16bpc
Line
Count
Source
1179
713k
{
1180
713k
    Dav1dTileState *const ts = t->ts;
1181
713k
    const Dav1dFrameContext *const f = t->f;
1182
713k
    const Dav1dDSPContext *const dsp = f->dsp;
1183
713k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
713k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
713k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
713k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
713k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
713k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
713k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
713k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
713k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
647k
                           (bw4 > ss_hor || t->bx & 1) &&
1193
601k
                           (bh4 > ss_ver || t->by & 1);
1194
713k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
713k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
713k
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
713k
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
713k
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
1.44M
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
733k
        const int sub_h4 = imin(h4, 16 + init_y);
1205
733k
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
1.50M
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
768k
            if (b->pal_sz[0]) {
1208
3.60k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
3.60k
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
3.60k
                const uint8_t *pal_idx;
1211
3.60k
                if (t->frame_thread.pass) {
1212
3.60k
                    const int p = t->frame_thread.pass & 1;
1213
3.60k
                    assert(ts->frame_thread[p].pal_idx);
1214
3.60k
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
3.60k
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
3.60k
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
3.60k
                const pixel *const pal = t->frame_thread.pass ?
1220
3.60k
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
3.60k
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
3.60k
                    bytefn(t->scratch.pal)[0];
1223
3.60k
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
3.60k
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
3.60k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1226
0
                    hex_dump(dst, PXSTRIDE(f->cur.stride[0]),
1227
0
                             bw4 * 4, bh4 * 4, "y-pal-pred");
1228
3.60k
            }
1229
1230
768k
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
768k
                                     sm_flag(&t->l, by4) |
1232
768k
                                     intra_edge_filter_flag);
1233
768k
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
733k
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
768k
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
733k
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
768k
            int y, x;
1238
768k
            const int sub_w4 = imin(w4, init_x + 16);
1239
1.73M
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
962k
                 y += t_dim->h, t->by += t_dim->h)
1241
960k
            {
1242
960k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
960k
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
960k
                                    t->bx + init_x);
1245
2.63M
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
1.67M
                     x += t_dim->w, t->bx += t_dim->w)
1247
1.67M
                {
1248
1.67M
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
1.66M
                    int angle = b->y_angle;
1251
1.66M
                    const enum EdgeFlags edge_flags =
1252
1.66M
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
1.20M
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
1.66M
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
1.14M
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
1.66M
                    const pixel *top_sb_edge = NULL;
1257
1.66M
                    if (!(t->by & (f->sb_step - 1))) {
1258
268k
                        top_sb_edge = f->ipred_edge[0];
1259
268k
                        const int sby = t->by >> f->sb_shift;
1260
268k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
268k
                    }
1262
1.66M
                    const enum IntraPredMode m =
1263
1.66M
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
1.66M
                                                          t->bx > ts->tiling.col_start,
1265
1.66M
                                                          t->by,
1266
1.66M
                                                          t->by > ts->tiling.row_start,
1267
1.66M
                                                          ts->tiling.col_end,
1268
1.66M
                                                          ts->tiling.row_end,
1269
1.66M
                                                          edge_flags, dst,
1270
1.66M
                                                          f->cur.stride[0], top_sb_edge,
1271
1.66M
                                                          b->y_mode, &angle,
1272
1.66M
                                                          t_dim->w, t_dim->h,
1273
1.66M
                                                          f->seq_hdr->intra_edge_filter,
1274
1.66M
                                                          edge HIGHBD_CALL_SUFFIX);
1275
1.66M
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
1.66M
                                             t_dim->w * 4, t_dim->h * 4,
1277
1.66M
                                             angle | intra_flags,
1278
1.66M
                                             4 * f->bw - 4 * t->bx,
1279
1.66M
                                             4 * f->bh - 4 * t->by
1280
1.66M
                                             HIGHBD_CALL_SUFFIX);
1281
1282
1.66M
                    if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1283
0
                        hex_dump(edge - t_dim->h * 4, t_dim->h * 4,
1284
0
                                 t_dim->h * 4, 2, "l");
1285
0
                        hex_dump(edge, 0, 1, 1, "tl");
1286
0
                        hex_dump(edge + 1, t_dim->w * 4,
1287
0
                                 t_dim->w * 4, 2, "t");
1288
0
                        hex_dump(dst, f->cur.stride[0],
1289
0
                                 t_dim->w * 4, t_dim->h * 4, "y-intra-pred");
1290
0
                    }
1291
1292
1.67M
                skip_y_pred: {}
1293
1.67M
                    if (!b->skip) {
1294
500k
                        coef *cf;
1295
500k
                        int eob;
1296
500k
                        enum TxfmType txtp;
1297
500k
                        if (t->frame_thread.pass) {
1298
500k
                            const int p = t->frame_thread.pass & 1;
1299
500k
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
500k
                            cf = ts->frame_thread[p].cf;
1301
500k
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
500k
                            eob  = cbi >> 5;
1303
500k
                            txtp = cbi & 0x1f;
1304
500k
                        } else {
1305
0
                            uint8_t cf_ctx;
1306
0
                            cf = bitfn(t->cf);
1307
0
                            eob = decode_coefs(t, &t->a->lcoef[bx4 + x],
1308
0
                                               &t->l.lcoef[by4 + y], b->tx, bs,
1309
0
                                               b, 1, 0, cf, &txtp, &cf_ctx);
1310
0
                            if (DEBUG_BLOCK_INFO)
1311
0
                                printf("Post-y-cf-blk[tx=%d,txtp=%d,eob=%d]: r=%d\n",
1312
0
                                       b->tx, txtp, eob, ts->msac.rng);
1313
0
                            dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
1314
0
                            dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
1315
0
                        }
1316
500k
                        if (eob >= 0) {
1317
352k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1318
0
                                coef_dump(cf, imin(t_dim->h, 8) * 4,
1319
0
                                          imin(t_dim->w, 8) * 4, 3, "dq");
1320
352k
                            dsp->itx.itxfm_add[b->tx]
1321
352k
                                              [txtp](dst,
1322
352k
                                                     f->cur.stride[0],
1323
352k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
352k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1325
0
                                hex_dump(dst, f->cur.stride[0],
1326
0
                                         t_dim->w * 4, t_dim->h * 4, "recon");
1327
352k
                        }
1328
1.17M
                    } else if (!t->frame_thread.pass) {
1329
0
                        dav1d_memset_pow2[t_dim->lw](&t->a->lcoef[bx4 + x], 0x40);
1330
0
                        dav1d_memset_pow2[t_dim->lh](&t->l.lcoef[by4 + y], 0x40);
1331
0
                    }
1332
1.67M
                    dst += 4 * t_dim->w;
1333
1.67M
                }
1334
962k
                t->bx -= x;
1335
962k
            }
1336
770k
            t->by -= y;
1337
1338
770k
            if (!has_chroma) continue;
1339
1340
605k
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
605k
            if (b->uv_mode == CFL_PRED) {
1343
108k
                assert(!init_x && !init_y);
1344
1345
108k
                int16_t *const ac = t->scratch.ac;
1346
108k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
108k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
108k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
108k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
108k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
108k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
108k
                const int furthest_r =
1354
108k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
108k
                const int furthest_b =
1356
108k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
108k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
108k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
108k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
108k
                                                         cbw4 * 4, cbh4 * 4);
1361
326k
                for (int pl = 0; pl < 2; pl++) {
1362
217k
                    if (!b->cfl_alpha[pl]) continue;
1363
172k
                    int angle = 0;
1364
172k
                    const pixel *top_sb_edge = NULL;
1365
172k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
34.7k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
34.7k
                        const int sby = t->by >> f->sb_shift;
1368
34.7k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
34.7k
                    }
1370
172k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
172k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
172k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
172k
                    const enum IntraPredMode m =
1374
172k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
172k
                                                          ypos, ypos > ystart,
1376
172k
                                                          ts->tiling.col_end >> ss_hor,
1377
172k
                                                          ts->tiling.row_end >> ss_ver,
1378
172k
                                                          0, uv_dst[pl], stride,
1379
172k
                                                          top_sb_edge, DC_PRED, &angle,
1380
172k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
172k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
172k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
172k
                                           uv_t_dim->w * 4,
1384
172k
                                           uv_t_dim->h * 4,
1385
172k
                                           ac, b->cfl_alpha[pl]
1386
172k
                                           HIGHBD_CALL_SUFFIX);
1387
172k
                }
1388
108k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1389
0
                    ac_dump(ac, 4*cbw4, 4*cbh4, "ac");
1390
0
                    hex_dump(uv_dst[0], stride, cbw4 * 4, cbh4 * 4, "u-cfl-pred");
1391
0
                    hex_dump(uv_dst[1], stride, cbw4 * 4, cbh4 * 4, "v-cfl-pred");
1392
0
                }
1393
496k
            } else if (b->pal_sz[1]) {
1394
1.10k
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
1.10k
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
1.10k
                const pixel (*pal)[8];
1397
1.10k
                const uint8_t *pal_idx;
1398
1.10k
                if (t->frame_thread.pass) {
1399
1.10k
                    const int p = t->frame_thread.pass & 1;
1400
1.10k
                    assert(ts->frame_thread[p].pal_idx);
1401
1.10k
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
1.10k
                                              ((t->bx >> 1) + (t->by & 1))];
1403
1.10k
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
1.10k
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
1.10k
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
1.10k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
1.10k
                                       f->cur.stride[1], pal[1],
1412
1.10k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
1.10k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
1.10k
                                       f->cur.stride[1], pal[2],
1415
1.10k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
1.10k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1417
0
                    hex_dump(((pixel *) f->cur.data[1]) + uv_dstoff,
1418
0
                             PXSTRIDE(f->cur.stride[1]),
1419
0
                             cbw4 * 4, cbh4 * 4, "u-pal-pred");
1420
0
                    hex_dump(((pixel *) f->cur.data[2]) + uv_dstoff,
1421
0
                             PXSTRIDE(f->cur.stride[1]),
1422
0
                             cbw4 * 4, cbh4 * 4, "v-pal-pred");
1423
0
                }
1424
1.10k
            }
1425
1426
605k
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
605k
                                 sm_uv_flag(&t->l, cby4);
1428
605k
            const int uv_sb_has_tr =
1429
605k
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
572k
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
605k
            const int uv_sb_has_bl =
1432
605k
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
572k
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
605k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
1.81M
            for (int pl = 0; pl < 2; pl++) {
1436
2.49M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
1.28M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
1.28M
                {
1439
1.28M
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
1.28M
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
1.28M
                                        ((t->bx + init_x) >> ss_hor));
1442
2.88M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
1443
1.59M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
1444
1.59M
                    {
1445
1.59M
                        if ((b->uv_mode == CFL_PRED && b->cfl_alpha[pl]) ||
1446
1.42M
                            b->pal_sz[1])
1447
174k
                        {
1448
174k
                            goto skip_uv_pred;
1449
174k
                        }
1450
1451
1.42M
                        int angle = b->uv_angle;
1452
                        // this probably looks weird because we're using
1453
                        // luma flags in a chroma loop, but that's because
1454
                        // prepare_intra_edges() expects luma flags as input
1455
1.42M
                        const enum EdgeFlags edge_flags =
1456
1.42M
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
688k
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
986k
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
1.42M
                            ((x > (init_x >> ss_hor) ||
1460
1.11M
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
918k
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
1.42M
                        const pixel *top_sb_edge = NULL;
1463
1.42M
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
334k
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
334k
                            const int sby = t->by >> f->sb_shift;
1466
334k
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
334k
                        }
1468
1.42M
                        const enum IntraPredMode uv_mode =
1469
1.42M
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
1.42M
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
1.42M
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
1.42M
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
1.42M
                        const enum IntraPredMode m =
1474
1.42M
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
1.42M
                                                              ypos, ypos > ystart,
1476
1.42M
                                                              ts->tiling.col_end >> ss_hor,
1477
1.42M
                                                              ts->tiling.row_end >> ss_ver,
1478
1.42M
                                                              edge_flags, dst, stride,
1479
1.42M
                                                              top_sb_edge, uv_mode,
1480
1.42M
                                                              &angle, uv_t_dim->w,
1481
1.42M
                                                              uv_t_dim->h,
1482
1.42M
                                                              f->seq_hdr->intra_edge_filter,
1483
1.42M
                                                              edge HIGHBD_CALL_SUFFIX);
1484
1.42M
                        angle |= intra_edge_filter_flag;
1485
1.42M
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
1.42M
                                                 uv_t_dim->w * 4,
1487
1.42M
                                                 uv_t_dim->h * 4,
1488
1.42M
                                                 angle | sm_uv_fl,
1489
1.42M
                                                 (4 * f->bw + ss_hor -
1490
1.42M
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
1.42M
                                                 (4 * f->bh + ss_ver -
1492
1.42M
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
1.42M
                                                 HIGHBD_CALL_SUFFIX);
1494
1.42M
                        if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1495
0
                            hex_dump(edge - uv_t_dim->h * 4, uv_t_dim->h * 4,
1496
0
                                     uv_t_dim->h * 4, 2, "l");
1497
0
                            hex_dump(edge, 0, 1, 1, "tl");
1498
0
                            hex_dump(edge + 1, uv_t_dim->w * 4,
1499
0
                                     uv_t_dim->w * 4, 2, "t");
1500
0
                            hex_dump(dst, stride, uv_t_dim->w * 4,
1501
0
                                     uv_t_dim->h * 4, pl ? "v-intra-pred" : "u-intra-pred");
1502
0
                        }
1503
1504
1.59M
                    skip_uv_pred: {}
1505
1.59M
                        if (!b->skip) {
1506
559k
                            enum TxfmType txtp;
1507
559k
                            int eob;
1508
559k
                            coef *cf;
1509
559k
                            if (t->frame_thread.pass) {
1510
559k
                                const int p = t->frame_thread.pass & 1;
1511
559k
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
559k
                                cf = ts->frame_thread[p].cf;
1513
559k
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
559k
                                eob  = cbi >> 5;
1515
559k
                                txtp = cbi & 0x1f;
1516
559k
                            } else {
1517
0
                                uint8_t cf_ctx;
1518
0
                                cf = bitfn(t->cf);
1519
0
                                eob = decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
1520
0
                                                   &t->l.ccoef[pl][cby4 + y],
1521
0
                                                   b->uvtx, bs, b, 1, 1 + pl, cf,
1522
0
                                                   &txtp, &cf_ctx);
1523
0
                                if (DEBUG_BLOCK_INFO)
1524
0
                                    printf("Post-uv-cf-blk[pl=%d,tx=%d,"
1525
0
                                           "txtp=%d,eob=%d]: r=%d [x=%d,cbx4=%d]\n",
1526
0
                                           pl, b->uvtx, txtp, eob, ts->msac.rng, x, cbx4);
1527
0
                                int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
1528
0
                                int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
1529
0
                                dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
1530
0
                                dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
1531
0
                            }
1532
559k
                            if (eob >= 0) {
1533
162k
                                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1534
0
                                    coef_dump(cf, uv_t_dim->h * 4,
1535
0
                                              uv_t_dim->w * 4, 3, "dq");
1536
162k
                                dsp->itx.itxfm_add[b->uvtx]
1537
162k
                                                  [txtp](dst, stride,
1538
162k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
162k
                                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1540
0
                                    hex_dump(dst, stride, uv_t_dim->w * 4,
1541
0
                                             uv_t_dim->h * 4, "recon");
1542
162k
                            }
1543
1.03M
                        } else if (!t->frame_thread.pass) {
1544
0
                            dav1d_memset_pow2[uv_t_dim->lw](&t->a->ccoef[pl][cbx4 + x], 0x40);
1545
0
                            dav1d_memset_pow2[uv_t_dim->lh](&t->l.ccoef[pl][cby4 + y], 0x40);
1546
0
                        }
1547
1.59M
                        dst += uv_t_dim->w * 4;
1548
1.59M
                    }
1549
1.28M
                    t->bx -= x << ss_hor;
1550
1.28M
                }
1551
1.20M
                t->by -= y << ss_ver;
1552
1.20M
            }
1553
605k
        }
1554
733k
    }
1555
713k
}
1556
1557
int bytefn(dav1d_recon_b_inter)(Dav1dTaskContext *const t, const enum BlockSize bs,
1558
                                const Av1Block *const b)
1559
209k
{
1560
209k
    Dav1dTileState *const ts = t->ts;
1561
209k
    const Dav1dFrameContext *const f = t->f;
1562
209k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
209k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
209k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
209k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
209k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
209k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
209k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
209k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
209k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
154k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
148k
                           (bh4 > ss_ver || t->by & 1);
1573
209k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
209k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
209k
    int res;
1576
1577
    // prediction
1578
209k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
209k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
209k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
209k
    const ptrdiff_t uvdstoff =
1582
209k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
209k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
77.6k
        assert(!f->frame_hdr->super_res.enabled);
1586
77.6k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
77.6k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
77.6k
        if (res) return res;
1589
96.8k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
64.5k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
64.5k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
64.5k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
64.5k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
64.5k
            if (res) return res;
1595
64.5k
        }
1596
131k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
112k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
112k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
112k
        if (imin(bw4, bh4) > 1 &&
1601
72.1k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
70.1k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
4.03k
        {
1604
4.03k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
4.03k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
4.03k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
4.03k
            if (res) return res;
1608
108k
        } else {
1609
108k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
108k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
108k
            if (res) return res;
1612
108k
            if (b->motion_mode == MM_OBMC) {
1613
17.9k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
17.9k
                if (res) return res;
1615
17.9k
            }
1616
108k
        }
1617
112k
        if (b->interintra_type) {
1618
2.16k
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
2.16k
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
1.79k
                                   SMOOTH_PRED : b->interintra_mode;
1621
2.16k
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
2.16k
            int angle = 0;
1623
2.16k
            const pixel *top_sb_edge = NULL;
1624
2.16k
            if (!(t->by & (f->sb_step - 1))) {
1625
1.61k
                top_sb_edge = f->ipred_edge[0];
1626
1.61k
                const int sby = t->by >> f->sb_shift;
1627
1.61k
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
1.61k
            }
1629
2.16k
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
2.16k
                                                  t->by, t->by > ts->tiling.row_start,
1631
2.16k
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
2.16k
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
2.16k
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
2.16k
                                                  HIGHBD_CALL_SUFFIX);
1635
2.16k
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
2.16k
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
2.16k
                                     HIGHBD_CALL_SUFFIX);
1638
2.16k
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
2.16k
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
2.16k
        }
1641
1642
112k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
93.8k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
93.8k
        refmvs_block *const *r;
1647
93.8k
        if (is_sub8x8) {
1648
5.23k
            assert(ss_hor == 1);
1649
5.23k
            r = &t->rt.r[(t->by & 31) + 5];
1650
5.23k
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
5.23k
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
5.23k
            if (bw4 == 1 && bh4 == ss_ver)
1653
667
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
5.23k
        }
1655
1656
        // chroma prediction
1657
93.8k
        if (is_sub8x8) {
1658
5.11k
            assert(ss_hor == 1);
1659
5.11k
            ptrdiff_t h_off = 0, v_off = 0;
1660
5.11k
            if (bw4 == 1 && bh4 == ss_ver) {
1661
1.91k
                for (int pl = 0; pl < 2; pl++) {
1662
1.27k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
1.27k
                             NULL, f->cur.stride[1],
1664
1.27k
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
1.27k
                             r[-1][t->bx - 1].mv.mv[0],
1666
1.27k
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
1.27k
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
1.27k
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
1.27k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
1.27k
                    if (res) return res;
1671
1.27k
                }
1672
638
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
638
                h_off = 2;
1674
638
            }
1675
5.11k
            if (bw4 == 1) {
1676
2.68k
                const enum Filter2d left_filter_2d =
1677
2.68k
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
8.04k
                for (int pl = 0; pl < 2; pl++) {
1679
5.36k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
5.36k
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
5.36k
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
5.36k
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
5.36k
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
5.36k
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
5.36k
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
5.36k
                    if (res) return res;
1687
5.36k
                }
1688
2.68k
                h_off = 2;
1689
2.68k
            }
1690
5.11k
            if (bh4 == ss_ver) {
1691
3.06k
                const enum Filter2d top_filter_2d =
1692
3.06k
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
9.20k
                for (int pl = 0; pl < 2; pl++) {
1694
6.13k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
6.13k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
6.13k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
6.13k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
6.13k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
6.13k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
6.13k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
6.13k
                    if (res) return res;
1702
6.13k
                }
1703
3.06k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
3.06k
            }
1705
15.3k
            for (int pl = 0; pl < 2; pl++) {
1706
10.2k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
10.2k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
10.2k
                         refp, b->ref[0], filter_2d);
1709
10.2k
                if (res) return res;
1710
10.2k
            }
1711
88.7k
        } else {
1712
88.7k
            if (imin(cbw4, cbh4) > 1 &&
1713
50.4k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
48.6k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
3.77k
            {
1716
11.3k
                for (int pl = 0; pl < 2; pl++) {
1717
7.55k
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
7.55k
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
7.55k
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
7.55k
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
7.55k
                    if (res) return res;
1722
7.55k
                }
1723
84.9k
            } else {
1724
254k
                for (int pl = 0; pl < 2; pl++) {
1725
169k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
169k
                             NULL, f->cur.stride[1],
1727
169k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
169k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
169k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
169k
                    if (res) return res;
1731
169k
                    if (b->motion_mode == MM_OBMC) {
1732
32.6k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
32.6k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
32.6k
                        if (res) return res;
1735
32.6k
                    }
1736
169k
                }
1737
84.9k
            }
1738
88.7k
            if (b->interintra_type) {
1739
                // FIXME for 8x32 with 4:2:2 subsampling, this probably does
1740
                // the wrong thing since it will select 4x16, not 4x32, as a
1741
                // transform size...
1742
1.78k
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
5.36k
                for (int pl = 0; pl < 2; pl++) {
1745
3.57k
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
3.57k
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
3.57k
                    enum IntraPredMode m =
1748
3.57k
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
2.98k
                        SMOOTH_PRED : b->interintra_mode;
1750
3.57k
                    int angle = 0;
1751
3.57k
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
3.57k
                    const pixel *top_sb_edge = NULL;
1753
3.57k
                    if (!(t->by & (f->sb_step - 1))) {
1754
2.65k
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
2.65k
                        const int sby = t->by >> f->sb_shift;
1756
2.65k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
2.65k
                    }
1758
3.57k
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
3.57k
                                                          (t->bx >> ss_hor) >
1760
3.57k
                                                              (ts->tiling.col_start >> ss_hor),
1761
3.57k
                                                          t->by >> ss_ver,
1762
3.57k
                                                          (t->by >> ss_ver) >
1763
3.57k
                                                              (ts->tiling.row_start >> ss_ver),
1764
3.57k
                                                          ts->tiling.col_end >> ss_hor,
1765
3.57k
                                                          ts->tiling.row_end >> ss_ver,
1766
3.57k
                                                          0, uvdst, f->cur.stride[1],
1767
3.57k
                                                          top_sb_edge, m,
1768
3.57k
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
3.57k
                                                          HIGHBD_CALL_SUFFIX);
1770
3.57k
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
3.57k
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
3.57k
                                             HIGHBD_CALL_SUFFIX);
1773
3.57k
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
3.57k
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
3.57k
                }
1776
1.78k
            }
1777
88.7k
        }
1778
1779
112k
    skip_inter_chroma_pred: {}
1780
112k
        t->tl_4x4_filter = filter_2d;
1781
112k
    } else {
1782
19.4k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
19.4k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
19.4k
        int jnt_weight;
1786
19.4k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
19.4k
        const uint8_t *mask;
1788
1789
58.2k
        for (int i = 0; i < 2; i++) {
1790
38.8k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
38.8k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
2.94k
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
2.94k
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
2.94k
                if (res) return res;
1796
35.8k
            } else {
1797
35.8k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
35.8k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
35.8k
                if (res) return res;
1800
35.8k
            }
1801
38.8k
        }
1802
19.4k
        switch (b->comp_type) {
1803
14.6k
        case COMP_INTER_AVG:
1804
14.6k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
14.6k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
14.6k
            break;
1807
1.80k
        case COMP_INTER_WEIGHTED_AVG:
1808
1.80k
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
1.80k
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
1.80k
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
1.80k
            break;
1812
2.19k
        case COMP_INTER_SEG:
1813
2.19k
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
2.19k
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
2.19k
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
2.19k
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
2.19k
            mask = seg_mask;
1818
2.19k
            break;
1819
770
        case COMP_INTER_WEDGE:
1820
770
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
770
            dsp->mc.mask(dst, f->cur.stride[0],
1822
770
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
770
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
770
            if (has_chroma)
1825
672
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
770
            break;
1827
19.4k
        }
1828
1829
        // chroma
1830
45.1k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
90.2k
            for (int i = 0; i < 2; i++) {
1832
60.1k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
60.1k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
12.2k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
4.43k
                {
1836
4.43k
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
4.43k
                                      b_dim, 1 + pl,
1838
4.43k
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
4.43k
                    if (res) return res;
1840
55.7k
                } else {
1841
55.7k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
55.7k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
55.7k
                    if (res) return res;
1844
55.7k
                }
1845
60.1k
            }
1846
30.0k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
30.0k
            switch (b->comp_type) {
1848
23.0k
            case COMP_INTER_AVG:
1849
23.0k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
23.0k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
23.0k
                            HIGHBD_CALL_SUFFIX);
1852
23.0k
                break;
1853
2.01k
            case COMP_INTER_WEIGHTED_AVG:
1854
2.01k
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
2.01k
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
2.01k
                              HIGHBD_CALL_SUFFIX);
1857
2.01k
                break;
1858
1.34k
            case COMP_INTER_WEDGE:
1859
5.08k
            case COMP_INTER_SEG:
1860
5.08k
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
5.08k
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
5.08k
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
5.08k
                             HIGHBD_CALL_SUFFIX);
1864
5.08k
                break;
1865
30.0k
            }
1866
30.0k
        }
1867
19.4k
    }
1868
1869
209k
    if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1870
0
        hex_dump(dst, f->cur.stride[0], b_dim[0] * 4, b_dim[1] * 4, "y-pred");
1871
0
        if (has_chroma) {
1872
0
            hex_dump(&((pixel *) f->cur.data[1])[uvdstoff], f->cur.stride[1],
1873
0
                     cbw4 * 4, cbh4 * 4, "u-pred");
1874
0
            hex_dump(&((pixel *) f->cur.data[2])[uvdstoff], f->cur.stride[1],
1875
0
                     cbw4 * 4, cbh4 * 4, "v-pred");
1876
0
        }
1877
0
    }
1878
1879
209k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
209k
    if (b->skip) {
1882
        // reset coef contexts
1883
97.2k
        BlockContext *const a = t->a;
1884
97.2k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
97.2k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
97.2k
        if (has_chroma) {
1887
54.3k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
54.3k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
54.3k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
54.3k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
54.3k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
54.3k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
54.3k
        }
1894
97.2k
        return 0;
1895
97.2k
    }
1896
1897
111k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
111k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
111k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
231k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
242k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
122k
            int y_off = !!init_y, y;
1905
122k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
259k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
137k
                 y += ytx->h, y_off++)
1908
137k
            {
1909
137k
                int x, x_off = !!init_x;
1910
339k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
201k
                     x += ytx->w, x_off++)
1912
201k
                {
1913
201k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
201k
                                   x_off, y_off, &dst[x * 4]);
1915
201k
                    t->bx += ytx->w;
1916
201k
                }
1917
137k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
137k
                t->bx -= x;
1919
137k
                t->by += ytx->h;
1920
137k
            }
1921
122k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
122k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
287k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
191k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
191k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
191k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
420k
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
228k
                {
1931
228k
                    int x;
1932
228k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
588k
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
359k
                    {
1935
359k
                        coef *cf;
1936
359k
                        int eob;
1937
359k
                        enum TxfmType txtp;
1938
359k
                        if (t->frame_thread.pass) {
1939
359k
                            const int p = t->frame_thread.pass & 1;
1940
359k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
359k
                            cf = ts->frame_thread[p].cf;
1942
359k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
359k
                            eob  = cbi >> 5;
1944
359k
                            txtp = cbi & 0x1f;
1945
18.4E
                        } else {
1946
18.4E
                            uint8_t cf_ctx;
1947
18.4E
                            cf = bitfn(t->cf);
1948
18.4E
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
1949
18.4E
                                                        bx4 + (x << ss_hor)];
1950
18.4E
                            eob = decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
1951
18.4E
                                               &t->l.ccoef[pl][cby4 + y],
1952
18.4E
                                               b->uvtx, bs, b, 0, 1 + pl,
1953
18.4E
                                               cf, &txtp, &cf_ctx);
1954
18.4E
                            if (DEBUG_BLOCK_INFO)
1955
0
                                printf("Post-uv-cf-blk[pl=%d,tx=%d,"
1956
0
                                       "txtp=%d,eob=%d]: r=%d\n",
1957
0
                                       pl, b->uvtx, txtp, eob, ts->msac.rng);
1958
18.4E
                            int ctw = imin(uvtx->w, (f->bw - t->bx + ss_hor) >> ss_hor);
1959
18.4E
                            int cth = imin(uvtx->h, (f->bh - t->by + ss_ver) >> ss_ver);
1960
18.4E
                            dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
1961
18.4E
                            dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
1962
18.4E
                        }
1963
359k
                        if (eob >= 0) {
1964
131k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
131k
                            dsp->itx.itxfm_add[b->uvtx]
1967
131k
                                              [txtp](&uvdst[4 * x],
1968
131k
                                                     f->cur.stride[1],
1969
131k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
131k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1971
0
                                hex_dump(&uvdst[4 * x], f->cur.stride[1],
1972
0
                                         uvtx->w * 4, uvtx->h * 4, "recon");
1973
131k
                        }
1974
359k
                        t->bx += uvtx->w << ss_hor;
1975
359k
                    }
1976
228k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
228k
                    t->bx -= x << ss_hor;
1978
228k
                    t->by += uvtx->h << ss_ver;
1979
228k
                }
1980
191k
                t->by -= y << ss_ver;
1981
191k
            }
1982
122k
        }
1983
119k
    }
1984
111k
    return 0;
1985
209k
}
dav1d_recon_b_inter_8bpc
Line
Count
Source
1559
138k
{
1560
138k
    Dav1dTileState *const ts = t->ts;
1561
138k
    const Dav1dFrameContext *const f = t->f;
1562
138k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
138k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
138k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
138k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
138k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
138k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
138k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
138k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
138k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
97.6k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
93.3k
                           (bh4 > ss_ver || t->by & 1);
1573
138k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
138k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
138k
    int res;
1576
1577
    // prediction
1578
138k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
138k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
138k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
138k
    const ptrdiff_t uvdstoff =
1582
138k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
138k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
54.1k
        assert(!f->frame_hdr->super_res.enabled);
1586
54.1k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
54.1k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
54.1k
        if (res) return res;
1589
54.1k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
32.8k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
32.8k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
32.8k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
32.8k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
32.8k
            if (res) return res;
1595
32.8k
        }
1596
84.3k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
75.3k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
75.3k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
75.3k
        if (imin(bw4, bh4) > 1 &&
1601
51.8k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
50.4k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
2.77k
        {
1604
2.77k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
2.77k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
2.77k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
2.77k
            if (res) return res;
1608
72.5k
        } else {
1609
72.5k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
72.5k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
72.5k
            if (res) return res;
1612
72.5k
            if (b->motion_mode == MM_OBMC) {
1613
13.4k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
13.4k
                if (res) return res;
1615
13.4k
            }
1616
72.5k
        }
1617
75.3k
        if (b->interintra_type) {
1618
1.06k
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
1.06k
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
936
                                   SMOOTH_PRED : b->interintra_mode;
1621
1.06k
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
1.06k
            int angle = 0;
1623
1.06k
            const pixel *top_sb_edge = NULL;
1624
1.06k
            if (!(t->by & (f->sb_step - 1))) {
1625
722
                top_sb_edge = f->ipred_edge[0];
1626
722
                const int sby = t->by >> f->sb_shift;
1627
722
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
722
            }
1629
1.06k
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
1.06k
                                                  t->by, t->by > ts->tiling.row_start,
1631
1.06k
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
1.06k
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
1.06k
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
1.06k
                                                  HIGHBD_CALL_SUFFIX);
1635
1.06k
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
1.06k
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
1.06k
                                     HIGHBD_CALL_SUFFIX);
1638
1.06k
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
1.06k
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
1.06k
        }
1641
1642
75.3k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
65.7k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
65.7k
        refmvs_block *const *r;
1647
65.7k
        if (is_sub8x8) {
1648
3.82k
            assert(ss_hor == 1);
1649
3.82k
            r = &t->rt.r[(t->by & 31) + 5];
1650
3.82k
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
3.82k
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
3.82k
            if (bw4 == 1 && bh4 == ss_ver)
1653
463
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
3.82k
        }
1655
1656
        // chroma prediction
1657
65.7k
        if (is_sub8x8) {
1658
3.78k
            assert(ss_hor == 1);
1659
3.78k
            ptrdiff_t h_off = 0, v_off = 0;
1660
3.78k
            if (bw4 == 1 && bh4 == ss_ver) {
1661
1.36k
                for (int pl = 0; pl < 2; pl++) {
1662
908
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
908
                             NULL, f->cur.stride[1],
1664
908
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
908
                             r[-1][t->bx - 1].mv.mv[0],
1666
908
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
908
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
908
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
908
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
908
                    if (res) return res;
1671
908
                }
1672
454
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
454
                h_off = 2;
1674
454
            }
1675
3.78k
            if (bw4 == 1) {
1676
1.94k
                const enum Filter2d left_filter_2d =
1677
1.94k
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
5.83k
                for (int pl = 0; pl < 2; pl++) {
1679
3.88k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
3.88k
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
3.88k
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
3.88k
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
3.88k
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
3.88k
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
3.88k
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
3.88k
                    if (res) return res;
1687
3.88k
                }
1688
1.94k
                h_off = 2;
1689
1.94k
            }
1690
3.78k
            if (bh4 == ss_ver) {
1691
2.29k
                const enum Filter2d top_filter_2d =
1692
2.29k
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
6.87k
                for (int pl = 0; pl < 2; pl++) {
1694
4.58k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
4.58k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
4.58k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
4.58k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
4.58k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
4.58k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
4.58k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
4.58k
                    if (res) return res;
1702
4.58k
                }
1703
2.29k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
2.29k
            }
1705
11.3k
            for (int pl = 0; pl < 2; pl++) {
1706
7.56k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
7.56k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
7.56k
                         refp, b->ref[0], filter_2d);
1709
7.56k
                if (res) return res;
1710
7.56k
            }
1711
62.0k
        } else {
1712
62.0k
            if (imin(cbw4, cbh4) > 1 &&
1713
37.7k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
36.5k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
2.62k
            {
1716
7.88k
                for (int pl = 0; pl < 2; pl++) {
1717
5.25k
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
5.25k
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
5.25k
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
5.25k
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
5.25k
                    if (res) return res;
1722
5.25k
                }
1723
59.3k
            } else {
1724
178k
                for (int pl = 0; pl < 2; pl++) {
1725
118k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
118k
                             NULL, f->cur.stride[1],
1727
118k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
118k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
118k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
118k
                    if (res) return res;
1731
118k
                    if (b->motion_mode == MM_OBMC) {
1732
25.6k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
25.6k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
25.6k
                        if (res) return res;
1735
25.6k
                    }
1736
118k
                }
1737
59.3k
            }
1738
62.0k
            if (b->interintra_type) {
1739
                // FIXME for 8x32 with 4:2:2 subsampling, this probably does
1740
                // the wrong thing since it will select 4x16, not 4x32, as a
1741
                // transform size...
1742
905
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
2.71k
                for (int pl = 0; pl < 2; pl++) {
1745
1.81k
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
1.81k
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
1.81k
                    enum IntraPredMode m =
1748
1.81k
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
1.62k
                        SMOOTH_PRED : b->interintra_mode;
1750
1.81k
                    int angle = 0;
1751
1.81k
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
1.81k
                    const pixel *top_sb_edge = NULL;
1753
1.81k
                    if (!(t->by & (f->sb_step - 1))) {
1754
1.16k
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
1.16k
                        const int sby = t->by >> f->sb_shift;
1756
1.16k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
1.16k
                    }
1758
1.81k
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
1.81k
                                                          (t->bx >> ss_hor) >
1760
1.81k
                                                              (ts->tiling.col_start >> ss_hor),
1761
1.81k
                                                          t->by >> ss_ver,
1762
1.81k
                                                          (t->by >> ss_ver) >
1763
1.81k
                                                              (ts->tiling.row_start >> ss_ver),
1764
1.81k
                                                          ts->tiling.col_end >> ss_hor,
1765
1.81k
                                                          ts->tiling.row_end >> ss_ver,
1766
1.81k
                                                          0, uvdst, f->cur.stride[1],
1767
1.81k
                                                          top_sb_edge, m,
1768
1.81k
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
1.81k
                                                          HIGHBD_CALL_SUFFIX);
1770
1.81k
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
1.81k
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
1.81k
                                             HIGHBD_CALL_SUFFIX);
1773
1.81k
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
1.81k
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
1.81k
                }
1776
905
            }
1777
62.0k
        }
1778
1779
75.3k
    skip_inter_chroma_pred: {}
1780
75.3k
        t->tl_4x4_filter = filter_2d;
1781
75.3k
    } else {
1782
8.96k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
8.96k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
8.96k
        int jnt_weight;
1786
8.96k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
8.96k
        const uint8_t *mask;
1788
1789
26.8k
        for (int i = 0; i < 2; i++) {
1790
17.9k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
17.9k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
1.90k
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
1.90k
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
1.90k
                if (res) return res;
1796
16.0k
            } else {
1797
16.0k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
16.0k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
16.0k
                if (res) return res;
1800
16.0k
            }
1801
17.9k
        }
1802
8.96k
        switch (b->comp_type) {
1803
7.16k
        case COMP_INTER_AVG:
1804
7.16k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
7.16k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
7.16k
            break;
1807
576
        case COMP_INTER_WEIGHTED_AVG:
1808
576
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
576
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
576
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
576
            break;
1812
903
        case COMP_INTER_SEG:
1813
903
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
903
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
903
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
903
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
903
            mask = seg_mask;
1818
903
            break;
1819
323
        case COMP_INTER_WEDGE:
1820
323
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
323
            dsp->mc.mask(dst, f->cur.stride[0],
1822
323
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
323
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
323
            if (has_chroma)
1825
275
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
323
            break;
1827
8.96k
        }
1828
1829
        // chroma
1830
20.3k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
40.7k
            for (int i = 0; i < 2; i++) {
1832
27.1k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
27.1k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
6.14k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
2.94k
                {
1836
2.94k
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
2.94k
                                      b_dim, 1 + pl,
1838
2.94k
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
2.94k
                    if (res) return res;
1840
24.2k
                } else {
1841
24.2k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
24.2k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
24.2k
                    if (res) return res;
1844
24.2k
                }
1845
27.1k
            }
1846
13.5k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
13.5k
            switch (b->comp_type) {
1848
10.8k
            case COMP_INTER_AVG:
1849
10.8k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
10.8k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
10.8k
                            HIGHBD_CALL_SUFFIX);
1852
10.8k
                break;
1853
572
            case COMP_INTER_WEIGHTED_AVG:
1854
572
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
572
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
572
                              HIGHBD_CALL_SUFFIX);
1857
572
                break;
1858
550
            case COMP_INTER_WEDGE:
1859
2.19k
            case COMP_INTER_SEG:
1860
2.19k
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
2.19k
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
2.19k
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
2.19k
                             HIGHBD_CALL_SUFFIX);
1864
2.19k
                break;
1865
13.5k
            }
1866
13.5k
        }
1867
8.96k
    }
1868
1869
138k
    if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1870
0
        hex_dump(dst, f->cur.stride[0], b_dim[0] * 4, b_dim[1] * 4, "y-pred");
1871
0
        if (has_chroma) {
1872
0
            hex_dump(&((pixel *) f->cur.data[1])[uvdstoff], f->cur.stride[1],
1873
0
                     cbw4 * 4, cbh4 * 4, "u-pred");
1874
0
            hex_dump(&((pixel *) f->cur.data[2])[uvdstoff], f->cur.stride[1],
1875
0
                     cbw4 * 4, cbh4 * 4, "v-pred");
1876
0
        }
1877
0
    }
1878
1879
138k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
138k
    if (b->skip) {
1882
        // reset coef contexts
1883
77.2k
        BlockContext *const a = t->a;
1884
77.2k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
77.2k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
77.2k
        if (has_chroma) {
1887
41.0k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
41.0k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
41.0k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
41.0k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
41.0k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
41.0k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
41.0k
        }
1894
77.2k
        return 0;
1895
77.2k
    }
1896
1897
61.2k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
61.2k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
61.2k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
126k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
132k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
66.8k
            int y_off = !!init_y, y;
1905
66.8k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
144k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
77.2k
                 y += ytx->h, y_off++)
1908
77.2k
            {
1909
77.2k
                int x, x_off = !!init_x;
1910
198k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
121k
                     x += ytx->w, x_off++)
1912
121k
                {
1913
121k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
121k
                                   x_off, y_off, &dst[x * 4]);
1915
121k
                    t->bx += ytx->w;
1916
121k
                }
1917
77.2k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
77.2k
                t->bx -= x;
1919
77.2k
                t->by += ytx->h;
1920
77.2k
            }
1921
66.8k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
66.8k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
158k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
105k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
105k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
105k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
237k
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
131k
                {
1931
131k
                    int x;
1932
131k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
352k
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
221k
                    {
1935
221k
                        coef *cf;
1936
221k
                        int eob;
1937
221k
                        enum TxfmType txtp;
1938
221k
                        if (t->frame_thread.pass) {
1939
221k
                            const int p = t->frame_thread.pass & 1;
1940
221k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
221k
                            cf = ts->frame_thread[p].cf;
1942
221k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
221k
                            eob  = cbi >> 5;
1944
221k
                            txtp = cbi & 0x1f;
1945
18.4E
                        } else {
1946
18.4E
                            uint8_t cf_ctx;
1947
18.4E
                            cf = bitfn(t->cf);
1948
18.4E
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
1949
18.4E
                                                        bx4 + (x << ss_hor)];
1950
18.4E
                            eob = decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
1951
18.4E
                                               &t->l.ccoef[pl][cby4 + y],
1952
18.4E
                                               b->uvtx, bs, b, 0, 1 + pl,
1953
18.4E
                                               cf, &txtp, &cf_ctx);
1954
18.4E
                            if (DEBUG_BLOCK_INFO)
1955
0
                                printf("Post-uv-cf-blk[pl=%d,tx=%d,"
1956
0
                                       "txtp=%d,eob=%d]: r=%d\n",
1957
0
                                       pl, b->uvtx, txtp, eob, ts->msac.rng);
1958
18.4E
                            int ctw = imin(uvtx->w, (f->bw - t->bx + ss_hor) >> ss_hor);
1959
18.4E
                            int cth = imin(uvtx->h, (f->bh - t->by + ss_ver) >> ss_ver);
1960
18.4E
                            dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
1961
18.4E
                            dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
1962
18.4E
                        }
1963
221k
                        if (eob >= 0) {
1964
86.7k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
86.7k
                            dsp->itx.itxfm_add[b->uvtx]
1967
86.7k
                                              [txtp](&uvdst[4 * x],
1968
86.7k
                                                     f->cur.stride[1],
1969
86.7k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
86.7k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1971
0
                                hex_dump(&uvdst[4 * x], f->cur.stride[1],
1972
0
                                         uvtx->w * 4, uvtx->h * 4, "recon");
1973
86.7k
                        }
1974
221k
                        t->bx += uvtx->w << ss_hor;
1975
221k
                    }
1976
131k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
131k
                    t->bx -= x << ss_hor;
1978
131k
                    t->by += uvtx->h << ss_ver;
1979
131k
                }
1980
105k
                t->by -= y << ss_ver;
1981
105k
            }
1982
66.8k
        }
1983
65.1k
    }
1984
61.2k
    return 0;
1985
138k
}
dav1d_recon_b_inter_16bpc
Line
Count
Source
1559
70.7k
{
1560
70.7k
    Dav1dTileState *const ts = t->ts;
1561
70.7k
    const Dav1dFrameContext *const f = t->f;
1562
70.7k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
70.7k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
70.7k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
70.7k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
70.7k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
70.7k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
70.7k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
70.7k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
70.7k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
57.0k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
54.7k
                           (bh4 > ss_ver || t->by & 1);
1573
70.7k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
70.7k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
70.7k
    int res;
1576
1577
    // prediction
1578
70.7k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
70.7k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
70.7k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
70.7k
    const ptrdiff_t uvdstoff =
1582
70.7k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
70.7k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
23.5k
        assert(!f->frame_hdr->super_res.enabled);
1586
23.5k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
23.5k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
23.5k
        if (res) return res;
1589
47.6k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
31.7k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
31.7k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
31.7k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
31.7k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
31.7k
            if (res) return res;
1595
31.7k
        }
1596
47.2k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
36.7k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
36.7k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
36.7k
        if (imin(bw4, bh4) > 1 &&
1601
20.3k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
19.6k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
1.25k
        {
1604
1.25k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
1.25k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
1.25k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
1.25k
            if (res) return res;
1608
35.5k
        } else {
1609
35.5k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
35.5k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
35.5k
            if (res) return res;
1612
35.5k
            if (b->motion_mode == MM_OBMC) {
1613
4.50k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
4.50k
                if (res) return res;
1615
4.50k
            }
1616
35.5k
        }
1617
36.7k
        if (b->interintra_type) {
1618
1.10k
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
1.10k
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
855
                                   SMOOTH_PRED : b->interintra_mode;
1621
1.10k
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
1.10k
            int angle = 0;
1623
1.10k
            const pixel *top_sb_edge = NULL;
1624
1.10k
            if (!(t->by & (f->sb_step - 1))) {
1625
893
                top_sb_edge = f->ipred_edge[0];
1626
893
                const int sby = t->by >> f->sb_shift;
1627
893
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
893
            }
1629
1.10k
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
1.10k
                                                  t->by, t->by > ts->tiling.row_start,
1631
1.10k
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
1.10k
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
1.10k
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
1.10k
                                                  HIGHBD_CALL_SUFFIX);
1635
1.10k
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
1.10k
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
1.10k
                                     HIGHBD_CALL_SUFFIX);
1638
1.10k
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
1.10k
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
1.10k
        }
1641
1642
36.7k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
28.0k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
28.0k
        refmvs_block *const *r;
1647
28.0k
        if (is_sub8x8) {
1648
1.41k
            assert(ss_hor == 1);
1649
1.41k
            r = &t->rt.r[(t->by & 31) + 5];
1650
1.41k
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
1.41k
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
1.41k
            if (bw4 == 1 && bh4 == ss_ver)
1653
204
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
1.41k
        }
1655
1656
        // chroma prediction
1657
28.0k
        if (is_sub8x8) {
1658
1.33k
            assert(ss_hor == 1);
1659
1.33k
            ptrdiff_t h_off = 0, v_off = 0;
1660
1.33k
            if (bw4 == 1 && bh4 == ss_ver) {
1661
552
                for (int pl = 0; pl < 2; pl++) {
1662
368
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
368
                             NULL, f->cur.stride[1],
1664
368
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
368
                             r[-1][t->bx - 1].mv.mv[0],
1666
368
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
368
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
368
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
368
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
368
                    if (res) return res;
1671
368
                }
1672
184
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
184
                h_off = 2;
1674
184
            }
1675
1.33k
            if (bw4 == 1) {
1676
738
                const enum Filter2d left_filter_2d =
1677
738
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
2.21k
                for (int pl = 0; pl < 2; pl++) {
1679
1.47k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
1.47k
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
1.47k
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
1.47k
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
1.47k
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
1.47k
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
1.47k
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
1.47k
                    if (res) return res;
1687
1.47k
                }
1688
738
                h_off = 2;
1689
738
            }
1690
1.33k
            if (bh4 == ss_ver) {
1691
777
                const enum Filter2d top_filter_2d =
1692
777
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
2.33k
                for (int pl = 0; pl < 2; pl++) {
1694
1.55k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
1.55k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
1.55k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
1.55k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
1.55k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
1.55k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
1.55k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
1.55k
                    if (res) return res;
1702
1.55k
                }
1703
777
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
777
            }
1705
3.99k
            for (int pl = 0; pl < 2; pl++) {
1706
2.66k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
2.66k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
2.66k
                         refp, b->ref[0], filter_2d);
1709
2.66k
                if (res) return res;
1710
2.66k
            }
1711
26.6k
        } else {
1712
26.6k
            if (imin(cbw4, cbh4) > 1 &&
1713
12.7k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
12.1k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
1.14k
            {
1716
3.43k
                for (int pl = 0; pl < 2; pl++) {
1717
2.29k
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
2.29k
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
2.29k
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
2.29k
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
2.29k
                    if (res) return res;
1722
2.29k
                }
1723
25.5k
            } else {
1724
76.6k
                for (int pl = 0; pl < 2; pl++) {
1725
51.0k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
51.0k
                             NULL, f->cur.stride[1],
1727
51.0k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
51.0k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
51.0k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
51.0k
                    if (res) return res;
1731
51.0k
                    if (b->motion_mode == MM_OBMC) {
1732
6.94k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
6.94k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
6.94k
                        if (res) return res;
1735
6.94k
                    }
1736
51.0k
                }
1737
25.5k
            }
1738
26.6k
            if (b->interintra_type) {
1739
                // FIXME for 8x32 with 4:2:2 subsampling, this probably does
1740
                // the wrong thing since it will select 4x16, not 4x32, as a
1741
                // transform size...
1742
883
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
2.64k
                for (int pl = 0; pl < 2; pl++) {
1745
1.76k
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
1.76k
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
1.76k
                    enum IntraPredMode m =
1748
1.76k
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
1.36k
                        SMOOTH_PRED : b->interintra_mode;
1750
1.76k
                    int angle = 0;
1751
1.76k
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
1.76k
                    const pixel *top_sb_edge = NULL;
1753
1.76k
                    if (!(t->by & (f->sb_step - 1))) {
1754
1.49k
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
1.49k
                        const int sby = t->by >> f->sb_shift;
1756
1.49k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
1.49k
                    }
1758
1.76k
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
1.76k
                                                          (t->bx >> ss_hor) >
1760
1.76k
                                                              (ts->tiling.col_start >> ss_hor),
1761
1.76k
                                                          t->by >> ss_ver,
1762
1.76k
                                                          (t->by >> ss_ver) >
1763
1.76k
                                                              (ts->tiling.row_start >> ss_ver),
1764
1.76k
                                                          ts->tiling.col_end >> ss_hor,
1765
1.76k
                                                          ts->tiling.row_end >> ss_ver,
1766
1.76k
                                                          0, uvdst, f->cur.stride[1],
1767
1.76k
                                                          top_sb_edge, m,
1768
1.76k
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
1.76k
                                                          HIGHBD_CALL_SUFFIX);
1770
1.76k
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
1.76k
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
1.76k
                                             HIGHBD_CALL_SUFFIX);
1773
1.76k
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
1.76k
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
1.76k
                }
1776
883
            }
1777
26.6k
        }
1778
1779
36.7k
    skip_inter_chroma_pred: {}
1780
36.7k
        t->tl_4x4_filter = filter_2d;
1781
36.7k
    } else {
1782
10.4k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
10.4k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
10.4k
        int jnt_weight;
1786
10.4k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
10.4k
        const uint8_t *mask;
1788
1789
31.3k
        for (int i = 0; i < 2; i++) {
1790
20.8k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
20.8k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
1.04k
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
1.04k
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
1.04k
                if (res) return res;
1796
19.8k
            } else {
1797
19.8k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
19.8k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
19.8k
                if (res) return res;
1800
19.8k
            }
1801
20.8k
        }
1802
10.4k
        switch (b->comp_type) {
1803
7.47k
        case COMP_INTER_AVG:
1804
7.47k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
7.47k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
7.47k
            break;
1807
1.22k
        case COMP_INTER_WEIGHTED_AVG:
1808
1.22k
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
1.22k
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
1.22k
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
1.22k
            break;
1812
1.29k
        case COMP_INTER_SEG:
1813
1.29k
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
1.29k
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
1.29k
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
1.29k
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
1.29k
            mask = seg_mask;
1818
1.29k
            break;
1819
447
        case COMP_INTER_WEDGE:
1820
447
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
447
            dsp->mc.mask(dst, f->cur.stride[0],
1822
447
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
447
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
447
            if (has_chroma)
1825
397
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
447
            break;
1827
10.4k
        }
1828
1829
        // chroma
1830
24.7k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
49.5k
            for (int i = 0; i < 2; i++) {
1832
33.0k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
33.0k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
6.12k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
1.49k
                {
1836
1.49k
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
1.49k
                                      b_dim, 1 + pl,
1838
1.49k
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
1.49k
                    if (res) return res;
1840
31.5k
                } else {
1841
31.5k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
31.5k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
31.5k
                    if (res) return res;
1844
31.5k
                }
1845
33.0k
            }
1846
16.5k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
16.5k
            switch (b->comp_type) {
1848
12.1k
            case COMP_INTER_AVG:
1849
12.1k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
12.1k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
12.1k
                            HIGHBD_CALL_SUFFIX);
1852
12.1k
                break;
1853
1.44k
            case COMP_INTER_WEIGHTED_AVG:
1854
1.44k
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
1.44k
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
1.44k
                              HIGHBD_CALL_SUFFIX);
1857
1.44k
                break;
1858
794
            case COMP_INTER_WEDGE:
1859
2.88k
            case COMP_INTER_SEG:
1860
2.88k
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
2.88k
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
2.88k
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
2.88k
                             HIGHBD_CALL_SUFFIX);
1864
2.88k
                break;
1865
16.5k
            }
1866
16.5k
        }
1867
10.4k
    }
1868
1869
70.7k
    if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1870
0
        hex_dump(dst, f->cur.stride[0], b_dim[0] * 4, b_dim[1] * 4, "y-pred");
1871
0
        if (has_chroma) {
1872
0
            hex_dump(&((pixel *) f->cur.data[1])[uvdstoff], f->cur.stride[1],
1873
0
                     cbw4 * 4, cbh4 * 4, "u-pred");
1874
0
            hex_dump(&((pixel *) f->cur.data[2])[uvdstoff], f->cur.stride[1],
1875
0
                     cbw4 * 4, cbh4 * 4, "v-pred");
1876
0
        }
1877
0
    }
1878
1879
70.7k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
70.7k
    if (b->skip) {
1882
        // reset coef contexts
1883
20.0k
        BlockContext *const a = t->a;
1884
20.0k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
20.0k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
20.0k
        if (has_chroma) {
1887
13.2k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
13.2k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
13.2k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
13.2k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
13.2k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
13.2k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
13.2k
        }
1894
20.0k
        return 0;
1895
20.0k
    }
1896
1897
50.7k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
50.7k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
50.7k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
105k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
110k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
55.6k
            int y_off = !!init_y, y;
1905
55.6k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
115k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
60.2k
                 y += ytx->h, y_off++)
1908
60.2k
            {
1909
60.2k
                int x, x_off = !!init_x;
1910
140k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
80.4k
                     x += ytx->w, x_off++)
1912
80.4k
                {
1913
80.4k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
80.4k
                                   x_off, y_off, &dst[x * 4]);
1915
80.4k
                    t->bx += ytx->w;
1916
80.4k
                }
1917
60.2k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
60.2k
                t->bx -= x;
1919
60.2k
                t->by += ytx->h;
1920
60.2k
            }
1921
55.6k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
55.6k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
128k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
85.4k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
85.4k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
85.4k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
183k
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
97.6k
                {
1931
97.6k
                    int x;
1932
97.6k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
236k
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
138k
                    {
1935
138k
                        coef *cf;
1936
138k
                        int eob;
1937
138k
                        enum TxfmType txtp;
1938
138k
                        if (t->frame_thread.pass) {
1939
138k
                            const int p = t->frame_thread.pass & 1;
1940
138k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
138k
                            cf = ts->frame_thread[p].cf;
1942
138k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
138k
                            eob  = cbi >> 5;
1944
138k
                            txtp = cbi & 0x1f;
1945
18.4E
                        } else {
1946
18.4E
                            uint8_t cf_ctx;
1947
18.4E
                            cf = bitfn(t->cf);
1948
18.4E
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
1949
18.4E
                                                        bx4 + (x << ss_hor)];
1950
18.4E
                            eob = decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
1951
18.4E
                                               &t->l.ccoef[pl][cby4 + y],
1952
18.4E
                                               b->uvtx, bs, b, 0, 1 + pl,
1953
18.4E
                                               cf, &txtp, &cf_ctx);
1954
18.4E
                            if (DEBUG_BLOCK_INFO)
1955
0
                                printf("Post-uv-cf-blk[pl=%d,tx=%d,"
1956
0
                                       "txtp=%d,eob=%d]: r=%d\n",
1957
0
                                       pl, b->uvtx, txtp, eob, ts->msac.rng);
1958
18.4E
                            int ctw = imin(uvtx->w, (f->bw - t->bx + ss_hor) >> ss_hor);
1959
18.4E
                            int cth = imin(uvtx->h, (f->bh - t->by + ss_ver) >> ss_ver);
1960
18.4E
                            dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
1961
18.4E
                            dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
1962
18.4E
                        }
1963
138k
                        if (eob >= 0) {
1964
44.7k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
44.7k
                            dsp->itx.itxfm_add[b->uvtx]
1967
44.7k
                                              [txtp](&uvdst[4 * x],
1968
44.7k
                                                     f->cur.stride[1],
1969
44.7k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
44.7k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1971
0
                                hex_dump(&uvdst[4 * x], f->cur.stride[1],
1972
0
                                         uvtx->w * 4, uvtx->h * 4, "recon");
1973
44.7k
                        }
1974
138k
                        t->bx += uvtx->w << ss_hor;
1975
138k
                    }
1976
97.6k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
97.6k
                    t->bx -= x << ss_hor;
1978
97.6k
                    t->by += uvtx->h << ss_ver;
1979
97.6k
                }
1980
85.4k
                t->by -= y << ss_ver;
1981
85.4k
            }
1982
55.6k
        }
1983
54.6k
    }
1984
50.7k
    return 0;
1985
70.7k
}
1986
1987
90.4k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
90.4k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
90.4k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
90.4k
    const int y = sby * f->sb_step * 4;
1994
90.4k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
90.4k
    pixel *const p[3] = {
1996
90.4k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
90.4k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
90.4k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
90.4k
    };
2000
90.4k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
90.4k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
90.4k
                                        f->lf.start_of_tile_row[sby]);
2003
90.4k
}
dav1d_filter_sbrow_deblock_cols_8bpc
Line
Count
Source
1987
53.2k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
53.2k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
53.2k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
53.2k
    const int y = sby * f->sb_step * 4;
1994
53.2k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
53.2k
    pixel *const p[3] = {
1996
53.2k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
53.2k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
53.2k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
53.2k
    };
2000
53.2k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
53.2k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
53.2k
                                        f->lf.start_of_tile_row[sby]);
2003
53.2k
}
dav1d_filter_sbrow_deblock_cols_16bpc
Line
Count
Source
1987
37.2k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
37.2k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
37.2k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
37.2k
    const int y = sby * f->sb_step * 4;
1994
37.2k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
37.2k
    pixel *const p[3] = {
1996
37.2k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
37.2k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
37.2k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
37.2k
    };
2000
37.2k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
37.2k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
37.2k
                                        f->lf.start_of_tile_row[sby]);
2003
37.2k
}
2004
2005
98.5k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
98.5k
    const int y = sby * f->sb_step * 4;
2007
98.5k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
98.5k
    pixel *const p[3] = {
2009
98.5k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
98.5k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
98.5k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
98.5k
    };
2013
98.5k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
98.5k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
98.5k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
90.3k
    {
2017
90.3k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
90.3k
    }
2019
98.5k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
84.3k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
84.3k
    }
2023
98.5k
}
dav1d_filter_sbrow_deblock_rows_8bpc
Line
Count
Source
2005
59.0k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
59.0k
    const int y = sby * f->sb_step * 4;
2007
59.0k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
59.0k
    pixel *const p[3] = {
2009
59.0k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
59.0k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
59.0k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
59.0k
    };
2013
59.0k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
59.0k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
59.0k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
53.1k
    {
2017
53.1k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
53.1k
    }
2019
59.0k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
51.7k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
51.7k
    }
2023
59.0k
}
dav1d_filter_sbrow_deblock_rows_16bpc
Line
Count
Source
2005
39.5k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
39.5k
    const int y = sby * f->sb_step * 4;
2007
39.5k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
39.5k
    pixel *const p[3] = {
2009
39.5k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
39.5k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
39.5k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
39.5k
    };
2013
39.5k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
39.5k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
39.5k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
37.2k
    {
2017
37.2k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
37.2k
    }
2019
39.5k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
32.5k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
32.5k
    }
2023
39.5k
}
2024
2025
55.8k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
55.8k
    const Dav1dFrameContext *const f = tc->f;
2027
55.8k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
55.8k
    const int sbsz = f->sb_step;
2029
55.8k
    const int y = sby * sbsz * 4;
2030
55.8k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
55.8k
    pixel *const p[3] = {
2032
55.8k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
55.8k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
55.8k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
55.8k
    };
2036
55.8k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
55.8k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
55.8k
    const int start = sby * sbsz;
2039
55.8k
    if (sby) {
2040
21.2k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
21.2k
        pixel *p_up[3] = {
2042
21.2k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
21.2k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
21.2k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
21.2k
        };
2046
21.2k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
21.2k
    }
2048
55.8k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
55.8k
    const int end = imin(start + n_blks, f->bh);
2050
55.8k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
55.8k
}
dav1d_filter_sbrow_cdef_8bpc
Line
Count
Source
2025
36.1k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
36.1k
    const Dav1dFrameContext *const f = tc->f;
2027
36.1k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
36.1k
    const int sbsz = f->sb_step;
2029
36.1k
    const int y = sby * sbsz * 4;
2030
36.1k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
36.1k
    pixel *const p[3] = {
2032
36.1k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
36.1k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
36.1k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
36.1k
    };
2036
36.1k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
36.1k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
36.1k
    const int start = sby * sbsz;
2039
36.1k
    if (sby) {
2040
13.6k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
13.6k
        pixel *p_up[3] = {
2042
13.6k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
13.6k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
13.6k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
13.6k
        };
2046
13.6k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
13.6k
    }
2048
36.1k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
36.1k
    const int end = imin(start + n_blks, f->bh);
2050
36.1k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
36.1k
}
dav1d_filter_sbrow_cdef_16bpc
Line
Count
Source
2025
19.7k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
19.7k
    const Dav1dFrameContext *const f = tc->f;
2027
19.7k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
19.7k
    const int sbsz = f->sb_step;
2029
19.7k
    const int y = sby * sbsz * 4;
2030
19.7k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
19.7k
    pixel *const p[3] = {
2032
19.7k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
19.7k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
19.7k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
19.7k
    };
2036
19.7k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
19.7k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
19.7k
    const int start = sby * sbsz;
2039
19.7k
    if (sby) {
2040
7.58k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
7.58k
        pixel *p_up[3] = {
2042
7.58k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
7.58k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
7.58k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
7.58k
        };
2046
7.58k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
7.58k
    }
2048
19.7k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
19.7k
    const int end = imin(start + n_blks, f->bh);
2050
19.7k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
19.7k
}
2052
2053
14.4k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
14.4k
    const int sbsz = f->sb_step;
2055
14.4k
    const int y = sby * sbsz * 4;
2056
14.4k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
14.4k
    const pixel *const p[3] = {
2058
14.4k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
14.4k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
14.4k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
14.4k
    };
2062
14.4k
    pixel *const sr_p[3] = {
2063
14.4k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
14.4k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
14.4k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
14.4k
    };
2067
14.4k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
51.2k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
36.7k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
36.7k
        const int h_start = 8 * !!sby >> ss_ver;
2071
36.7k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
36.7k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
36.7k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
36.7k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
36.7k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
36.7k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
36.7k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
36.7k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
36.7k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
36.7k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
36.7k
                          imin(img_h, h_end) + h_start, src_w,
2083
36.7k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
36.7k
                          HIGHBD_CALL_SUFFIX);
2085
36.7k
    }
2086
14.4k
}
dav1d_filter_sbrow_resize_8bpc
Line
Count
Source
2053
9.70k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
9.70k
    const int sbsz = f->sb_step;
2055
9.70k
    const int y = sby * sbsz * 4;
2056
9.70k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
9.70k
    const pixel *const p[3] = {
2058
9.70k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
9.70k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
9.70k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
9.70k
    };
2062
9.70k
    pixel *const sr_p[3] = {
2063
9.70k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
9.70k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
9.70k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
9.70k
    };
2067
9.70k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
35.7k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
26.0k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
26.0k
        const int h_start = 8 * !!sby >> ss_ver;
2071
26.0k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
26.0k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
26.0k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
26.0k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
26.0k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
26.0k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
26.0k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
26.0k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
26.0k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
26.0k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
26.0k
                          imin(img_h, h_end) + h_start, src_w,
2083
26.0k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
26.0k
                          HIGHBD_CALL_SUFFIX);
2085
26.0k
    }
2086
9.70k
}
dav1d_filter_sbrow_resize_16bpc
Line
Count
Source
2053
4.75k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
4.75k
    const int sbsz = f->sb_step;
2055
4.75k
    const int y = sby * sbsz * 4;
2056
4.75k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
4.75k
    const pixel *const p[3] = {
2058
4.75k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
4.75k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
4.75k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
4.75k
    };
2062
4.75k
    pixel *const sr_p[3] = {
2063
4.75k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
4.75k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
4.75k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
4.75k
    };
2067
4.75k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
15.4k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
10.7k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
10.7k
        const int h_start = 8 * !!sby >> ss_ver;
2071
10.7k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
10.7k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
10.7k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
10.7k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
10.7k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
10.7k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
10.7k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
10.7k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
10.7k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
10.7k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
10.7k
                          imin(img_h, h_end) + h_start, src_w,
2083
10.7k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
10.7k
                          HIGHBD_CALL_SUFFIX);
2085
10.7k
    }
2086
4.75k
}
2087
2088
63.6k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
63.6k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
63.6k
    const int y = sby * f->sb_step * 4;
2091
63.6k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
63.6k
    pixel *const sr_p[3] = {
2093
63.6k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
63.6k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
63.6k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
63.6k
    };
2097
63.6k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
63.6k
}
dav1d_filter_sbrow_lr_8bpc
Line
Count
Source
2088
39.0k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
39.0k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
39.0k
    const int y = sby * f->sb_step * 4;
2091
39.0k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
39.0k
    pixel *const sr_p[3] = {
2093
39.0k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
39.0k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
39.0k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
39.0k
    };
2097
39.0k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
39.0k
}
dav1d_filter_sbrow_lr_16bpc
Line
Count
Source
2088
24.5k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
24.5k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
24.5k
    const int y = sby * f->sb_step * 4;
2091
24.5k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
24.5k
    pixel *const sr_p[3] = {
2093
24.5k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
24.5k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
24.5k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
24.5k
    };
2097
24.5k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
24.5k
}
2099
2100
0
void bytefn(dav1d_filter_sbrow)(Dav1dFrameContext *const f, const int sby) {
2101
0
    bytefn(dav1d_filter_sbrow_deblock_cols)(f, sby);
2102
0
    bytefn(dav1d_filter_sbrow_deblock_rows)(f, sby);
2103
0
    if (f->seq_hdr->cdef)
2104
0
        bytefn(dav1d_filter_sbrow_cdef)(f->c->tc, sby);
2105
0
    if (f->frame_hdr->width[0] != f->frame_hdr->width[1])
2106
0
        bytefn(dav1d_filter_sbrow_resize)(f, sby);
2107
0
    if (f->lf.restore_planes)
2108
0
        bytefn(dav1d_filter_sbrow_lr)(f, sby);
2109
0
}
Unexecuted instantiation: dav1d_filter_sbrow_8bpc
Unexecuted instantiation: dav1d_filter_sbrow_16bpc
2110
2111
111k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
111k
    const Dav1dFrameContext *const f = t->f;
2113
111k
    Dav1dTileState *const ts = t->ts;
2114
111k
    const int sby = t->by >> f->sb_shift;
2115
111k
    const int sby_off = f->sb128w * 128 * sby;
2116
111k
    const int x_off = ts->tiling.col_start;
2117
2118
111k
    const pixel *const y =
2119
111k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
111k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
111k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
111k
               4 * (ts->tiling.col_end - x_off));
2123
2124
111k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
90.9k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
90.9k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
90.9k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
90.9k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
272k
        for (int pl = 1; pl <= 2; pl++)
2131
181k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
111k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
111k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
90.9k
    }
2135
111k
}
dav1d_backup_ipred_edge_8bpc
Line
Count
Source
2111
66.0k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
66.0k
    const Dav1dFrameContext *const f = t->f;
2113
66.0k
    Dav1dTileState *const ts = t->ts;
2114
66.0k
    const int sby = t->by >> f->sb_shift;
2115
66.0k
    const int sby_off = f->sb128w * 128 * sby;
2116
66.0k
    const int x_off = ts->tiling.col_start;
2117
2118
66.0k
    const pixel *const y =
2119
66.0k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
66.0k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
66.0k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
66.0k
               4 * (ts->tiling.col_end - x_off));
2123
2124
66.0k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
55.7k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
55.7k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
55.7k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
55.7k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
167k
        for (int pl = 1; pl <= 2; pl++)
2131
111k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
111k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
111k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
55.7k
    }
2135
66.0k
}
dav1d_backup_ipred_edge_16bpc
Line
Count
Source
2111
45.9k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
45.9k
    const Dav1dFrameContext *const f = t->f;
2113
45.9k
    Dav1dTileState *const ts = t->ts;
2114
45.9k
    const int sby = t->by >> f->sb_shift;
2115
45.9k
    const int sby_off = f->sb128w * 128 * sby;
2116
45.9k
    const int x_off = ts->tiling.col_start;
2117
2118
45.9k
    const pixel *const y =
2119
45.9k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
45.9k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
45.9k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
45.9k
               4 * (ts->tiling.col_end - x_off));
2123
2124
45.9k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
35.2k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
35.2k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
35.2k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
35.2k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
105k
        for (int pl = 1; pl <= 2; pl++)
2131
70.4k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
35.2k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
35.2k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
35.2k
    }
2135
45.9k
}
2136
2137
void bytefn(dav1d_copy_pal_block_y)(Dav1dTaskContext *const t,
2138
                                    const int bx4, const int by4,
2139
                                    const int bw4, const int bh4)
2140
2141
16.8k
{
2142
16.8k
    const Dav1dFrameContext *const f = t->f;
2143
16.8k
    pixel *const pal = t->frame_thread.pass ?
2144
16.8k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
16.8k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
16.8k
        bytefn(t->scratch.pal)[0];
2147
75.7k
    for (int x = 0; x < bw4; x++)
2148
58.9k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
68.7k
    for (int y = 0; y < bh4; y++)
2150
51.8k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
16.8k
}
dav1d_copy_pal_block_y_8bpc
Line
Count
Source
2141
9.05k
{
2142
9.05k
    const Dav1dFrameContext *const f = t->f;
2143
9.05k
    pixel *const pal = t->frame_thread.pass ?
2144
9.05k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
9.05k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
9.05k
        bytefn(t->scratch.pal)[0];
2147
39.4k
    for (int x = 0; x < bw4; x++)
2148
30.4k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
35.6k
    for (int y = 0; y < bh4; y++)
2150
26.6k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
9.05k
}
dav1d_copy_pal_block_y_16bpc
Line
Count
Source
2141
7.78k
{
2142
7.78k
    const Dav1dFrameContext *const f = t->f;
2143
7.78k
    pixel *const pal = t->frame_thread.pass ?
2144
7.78k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
7.78k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
7.78k
        bytefn(t->scratch.pal)[0];
2147
36.2k
    for (int x = 0; x < bw4; x++)
2148
28.5k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
33.0k
    for (int y = 0; y < bh4; y++)
2150
25.2k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
7.78k
}
2152
2153
void bytefn(dav1d_copy_pal_block_uv)(Dav1dTaskContext *const t,
2154
                                     const int bx4, const int by4,
2155
                                     const int bw4, const int bh4)
2156
2157
6.74k
{
2158
6.74k
    const Dav1dFrameContext *const f = t->f;
2159
6.74k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
6.74k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
6.74k
                            ((t->bx >> 1) + (t->by & 1))] :
2162
6.74k
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
20.2k
    for (int pl = 1; pl <= 2; pl++) {
2165
72.8k
        for (int x = 0; x < bw4; x++)
2166
59.3k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2167
68.1k
        for (int y = 0; y < bh4; y++)
2168
54.6k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
13.4k
    }
2170
6.74k
}
dav1d_copy_pal_block_uv_8bpc
Line
Count
Source
2157
4.02k
{
2158
4.02k
    const Dav1dFrameContext *const f = t->f;
2159
4.02k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
4.02k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
4.02k
                            ((t->bx >> 1) + (t->by & 1))] :
2162
4.02k
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
12.0k
    for (int pl = 1; pl <= 2; pl++) {
2165
43.5k
        for (int x = 0; x < bw4; x++)
2166
35.4k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2167
40.9k
        for (int y = 0; y < bh4; y++)
2168
32.8k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
8.05k
    }
2170
4.02k
}
dav1d_copy_pal_block_uv_16bpc
Line
Count
Source
2157
2.71k
{
2158
2.71k
    const Dav1dFrameContext *const f = t->f;
2159
2.71k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
2.71k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
2.71k
                            ((t->bx >> 1) + (t->by & 1))] :
2162
2.71k
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
8.14k
    for (int pl = 1; pl <= 2; pl++) {
2165
29.3k
        for (int x = 0; x < bw4; x++)
2166
23.8k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2167
27.2k
        for (int y = 0; y < bh4; y++)
2168
21.7k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
5.43k
    }
2170
2.71k
}
2171
2172
void bytefn(dav1d_read_pal_plane)(Dav1dTaskContext *const t, Av1Block *const b,
2173
                                  const int pl, const int sz_ctx,
2174
                                  const int bx4, const int by4)
2175
23.5k
{
2176
23.5k
    Dav1dTileState *const ts = t->ts;
2177
23.5k
    const Dav1dFrameContext *const f = t->f;
2178
23.5k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
23.5k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
23.5k
    pixel cache[16], used_cache[8];
2181
23.5k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
23.5k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
23.5k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
23.5k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
23.5k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
40.7k
    while (l_cache && a_cache) {
2190
17.2k
        if (*l < *a) {
2191
6.48k
            if (!n_cache || cache[n_cache - 1] != *l)
2192
6.44k
                cache[n_cache++] = *l;
2193
6.48k
            l++;
2194
6.48k
            l_cache--;
2195
10.7k
        } else {
2196
10.7k
            if (*a == *l) {
2197
4.24k
                l++;
2198
4.24k
                l_cache--;
2199
4.24k
            }
2200
10.7k
            if (!n_cache || cache[n_cache - 1] != *a)
2201
10.4k
                cache[n_cache++] = *a;
2202
10.7k
            a++;
2203
10.7k
            a_cache--;
2204
10.7k
        }
2205
17.2k
    }
2206
23.5k
    if (l_cache) {
2207
26.9k
        do {
2208
26.9k
            if (!n_cache || cache[n_cache - 1] != *l)
2209
22.2k
                cache[n_cache++] = *l;
2210
26.9k
            l++;
2211
26.9k
        } while (--l_cache > 0);
2212
16.9k
    } else if (a_cache) {
2213
20.8k
        do {
2214
20.8k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
16.7k
                cache[n_cache++] = *a;
2216
20.8k
            a++;
2217
20.8k
        } while (--a_cache > 0);
2218
5.18k
    }
2219
2220
    // find reused cache entries
2221
23.5k
    int i = 0;
2222
72.6k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
49.1k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
24.5k
            used_cache[i++] = cache[n];
2225
23.5k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
23.5k
    pixel *const pal = t->frame_thread.pass ?
2229
23.5k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
23.5k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
23.5k
        bytefn(t->scratch.pal)[pl];
2232
23.5k
    if (i < pal_sz) {
2233
20.4k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
20.4k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
20.4k
        if (i < pal_sz) {
2237
18.3k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
18.3k
            const int max = (1 << bpc) - 1;
2239
2240
42.9k
            do {
2241
42.9k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2242
42.9k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2243
42.9k
                if (prev + !pl >= max) {
2244
23.3k
                    for (; i < pal_sz; i++)
2245
15.2k
                        pal[i] = max;
2246
8.14k
                    break;
2247
8.14k
                }
2248
34.8k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
34.8k
            } while (i < pal_sz);
2250
18.3k
        }
2251
2252
        // merge cache+new entries
2253
20.4k
        int n = 0, m = n_used_cache;
2254
115k
        for (i = 0; i < pal_sz; i++) {
2255
94.7k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
16.1k
                pal[i] = used_cache[n++];
2257
78.6k
            } else {
2258
78.6k
                assert(m < pal_sz);
2259
78.6k
                pal[i] = pal[m++];
2260
78.6k
            }
2261
94.7k
        }
2262
20.4k
    } else {
2263
3.14k
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
3.14k
    }
2265
2266
23.5k
    if (DEBUG_BLOCK_INFO) {
2267
0
        printf("Post-pal[pl=%d,sz=%d,cache_size=%d,used_cache=%d]: r=%d, cache=",
2268
0
               pl, pal_sz, n_cache, n_used_cache, ts->msac.rng);
2269
0
        for (int n = 0; n < n_cache; n++)
2270
0
            printf("%c%02x", n ? ' ' : '[', cache[n]);
2271
0
        printf("%s, pal=", n_cache ? "]" : "[]");
2272
0
        for (int n = 0; n < pal_sz; n++)
2273
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2274
0
        printf("]\n");
2275
0
    }
2276
23.5k
}
dav1d_read_pal_plane_8bpc
Line
Count
Source
2175
13.0k
{
2176
13.0k
    Dav1dTileState *const ts = t->ts;
2177
13.0k
    const Dav1dFrameContext *const f = t->f;
2178
13.0k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
13.0k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
13.0k
    pixel cache[16], used_cache[8];
2181
13.0k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
13.0k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
13.0k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
13.0k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
13.0k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
23.9k
    while (l_cache && a_cache) {
2190
10.8k
        if (*l < *a) {
2191
4.08k
            if (!n_cache || cache[n_cache - 1] != *l)
2192
4.05k
                cache[n_cache++] = *l;
2193
4.08k
            l++;
2194
4.08k
            l_cache--;
2195
6.81k
        } else {
2196
6.81k
            if (*a == *l) {
2197
2.64k
                l++;
2198
2.64k
                l_cache--;
2199
2.64k
            }
2200
6.81k
            if (!n_cache || cache[n_cache - 1] != *a)
2201
6.64k
                cache[n_cache++] = *a;
2202
6.81k
            a++;
2203
6.81k
            a_cache--;
2204
6.81k
        }
2205
10.8k
    }
2206
13.0k
    if (l_cache) {
2207
15.3k
        do {
2208
15.3k
            if (!n_cache || cache[n_cache - 1] != *l)
2209
12.5k
                cache[n_cache++] = *l;
2210
15.3k
            l++;
2211
15.3k
        } while (--l_cache > 0);
2212
9.24k
    } else if (a_cache) {
2213
11.2k
        do {
2214
11.2k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
8.99k
                cache[n_cache++] = *a;
2216
11.2k
            a++;
2217
11.2k
        } while (--a_cache > 0);
2218
2.88k
    }
2219
2220
    // find reused cache entries
2221
13.0k
    int i = 0;
2222
41.2k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
28.1k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
14.2k
            used_cache[i++] = cache[n];
2225
13.0k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
13.0k
    pixel *const pal = t->frame_thread.pass ?
2229
13.0k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
13.0k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
13.0k
        bytefn(t->scratch.pal)[pl];
2232
13.0k
    if (i < pal_sz) {
2233
11.2k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
11.2k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
11.2k
        if (i < pal_sz) {
2237
10.0k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
10.0k
            const int max = (1 << bpc) - 1;
2239
2240
23.3k
            do {
2241
23.3k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2242
23.3k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2243
23.3k
                if (prev + !pl >= max) {
2244
12.9k
                    for (; i < pal_sz; i++)
2245
8.46k
                        pal[i] = max;
2246
4.51k
                    break;
2247
4.51k
                }
2248
18.8k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
18.8k
            } while (i < pal_sz);
2250
10.0k
        }
2251
2252
        // merge cache+new entries
2253
11.2k
        int n = 0, m = n_used_cache;
2254
63.4k
        for (i = 0; i < pal_sz; i++) {
2255
52.2k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
9.19k
                pal[i] = used_cache[n++];
2257
43.0k
            } else {
2258
43.0k
                assert(m < pal_sz);
2259
43.0k
                pal[i] = pal[m++];
2260
43.0k
            }
2261
52.2k
        }
2262
11.2k
    } else {
2263
1.83k
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
1.83k
    }
2265
2266
13.0k
    if (DEBUG_BLOCK_INFO) {
2267
0
        printf("Post-pal[pl=%d,sz=%d,cache_size=%d,used_cache=%d]: r=%d, cache=",
2268
0
               pl, pal_sz, n_cache, n_used_cache, ts->msac.rng);
2269
0
        for (int n = 0; n < n_cache; n++)
2270
0
            printf("%c%02x", n ? ' ' : '[', cache[n]);
2271
0
        printf("%s, pal=", n_cache ? "]" : "[]");
2272
0
        for (int n = 0; n < pal_sz; n++)
2273
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2274
0
        printf("]\n");
2275
0
    }
2276
13.0k
}
dav1d_read_pal_plane_16bpc
Line
Count
Source
2175
10.5k
{
2176
10.5k
    Dav1dTileState *const ts = t->ts;
2177
10.5k
    const Dav1dFrameContext *const f = t->f;
2178
10.5k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
10.5k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
10.5k
    pixel cache[16], used_cache[8];
2181
10.5k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
10.5k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
10.5k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
10.5k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
10.5k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
16.8k
    while (l_cache && a_cache) {
2190
6.31k
        if (*l < *a) {
2191
2.40k
            if (!n_cache || cache[n_cache - 1] != *l)
2192
2.39k
                cache[n_cache++] = *l;
2193
2.40k
            l++;
2194
2.40k
            l_cache--;
2195
3.91k
        } else {
2196
3.91k
            if (*a == *l) {
2197
1.59k
                l++;
2198
1.59k
                l_cache--;
2199
1.59k
            }
2200
3.91k
            if (!n_cache || cache[n_cache - 1] != *a)
2201
3.82k
                cache[n_cache++] = *a;
2202
3.91k
            a++;
2203
3.91k
            a_cache--;
2204
3.91k
        }
2205
6.31k
    }
2206
10.5k
    if (l_cache) {
2207
11.6k
        do {
2208
11.6k
            if (!n_cache || cache[n_cache - 1] != *l)
2209
9.61k
                cache[n_cache++] = *l;
2210
11.6k
            l++;
2211
11.6k
        } while (--l_cache > 0);
2212
7.66k
    } else if (a_cache) {
2213
9.60k
        do {
2214
9.60k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
7.79k
                cache[n_cache++] = *a;
2216
9.60k
            a++;
2217
9.60k
        } while (--a_cache > 0);
2218
2.29k
    }
2219
2220
    // find reused cache entries
2221
10.5k
    int i = 0;
2222
31.4k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
20.9k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
10.3k
            used_cache[i++] = cache[n];
2225
10.5k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
10.5k
    pixel *const pal = t->frame_thread.pass ?
2229
10.5k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
10.5k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
10.5k
        bytefn(t->scratch.pal)[pl];
2232
10.5k
    if (i < pal_sz) {
2233
9.19k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
9.19k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
9.19k
        if (i < pal_sz) {
2237
8.32k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
8.32k
            const int max = (1 << bpc) - 1;
2239
2240
19.6k
            do {
2241
19.6k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2242
19.6k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2243
19.6k
                if (prev + !pl >= max) {
2244
10.3k
                    for (; i < pal_sz; i++)
2245
6.73k
                        pal[i] = max;
2246
3.63k
                    break;
2247
3.63k
                }
2248
16.0k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
16.0k
            } while (i < pal_sz);
2250
8.32k
        }
2251
2252
        // merge cache+new entries
2253
9.19k
        int n = 0, m = n_used_cache;
2254
51.7k
        for (i = 0; i < pal_sz; i++) {
2255
42.5k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
6.98k
                pal[i] = used_cache[n++];
2257
35.5k
            } else {
2258
35.5k
                assert(m < pal_sz);
2259
35.5k
                pal[i] = pal[m++];
2260
35.5k
            }
2261
42.5k
        }
2262
9.19k
    } else {
2263
1.31k
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
1.31k
    }
2265
2266
10.5k
    if (DEBUG_BLOCK_INFO) {
2267
0
        printf("Post-pal[pl=%d,sz=%d,cache_size=%d,used_cache=%d]: r=%d, cache=",
2268
0
               pl, pal_sz, n_cache, n_used_cache, ts->msac.rng);
2269
0
        for (int n = 0; n < n_cache; n++)
2270
0
            printf("%c%02x", n ? ' ' : '[', cache[n]);
2271
0
        printf("%s, pal=", n_cache ? "]" : "[]");
2272
0
        for (int n = 0; n < pal_sz; n++)
2273
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2274
0
        printf("]\n");
2275
0
    }
2276
10.5k
}
2277
2278
void bytefn(dav1d_read_pal_uv)(Dav1dTaskContext *const t, Av1Block *const b,
2279
                               const int sz_ctx, const int bx4, const int by4)
2280
6.74k
{
2281
6.74k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
6.74k
    Dav1dTileState *const ts = t->ts;
2285
6.74k
    const Dav1dFrameContext *const f = t->f;
2286
6.74k
    pixel *const pal = t->frame_thread.pass ?
2287
6.74k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
6.74k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2289
6.74k
        bytefn(t->scratch.pal)[2];
2290
6.74k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2291
6.74k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
3.44k
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
3.44k
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
3.44k
        const int max = (1 << bpc) - 1;
2295
14.3k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
10.9k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
10.9k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
10.9k
            prev = pal[i] = (prev + delta) & max;
2299
10.9k
        }
2300
3.44k
    } else {
2301
16.8k
        for (int i = 0; i < b->pal_sz[1]; i++)
2302
13.5k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2303
3.29k
    }
2304
6.74k
    if (DEBUG_BLOCK_INFO) {
2305
0
        printf("Post-pal[pl=2]: r=%d ", ts->msac.rng);
2306
0
        for (int n = 0; n < b->pal_sz[1]; n++)
2307
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2308
0
        printf("]\n");
2309
0
    }
2310
6.74k
}
dav1d_read_pal_uv_8bpc
Line
Count
Source
2280
4.02k
{
2281
4.02k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
4.02k
    Dav1dTileState *const ts = t->ts;
2285
4.02k
    const Dav1dFrameContext *const f = t->f;
2286
4.02k
    pixel *const pal = t->frame_thread.pass ?
2287
4.02k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
4.02k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2289
4.02k
        bytefn(t->scratch.pal)[2];
2290
4.02k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2291
4.02k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
2.08k
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
2.08k
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
2.08k
        const int max = (1 << bpc) - 1;
2295
8.79k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
6.71k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
6.71k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
6.71k
            prev = pal[i] = (prev + delta) & max;
2299
6.71k
        }
2300
2.08k
    } else {
2301
10.1k
        for (int i = 0; i < b->pal_sz[1]; i++)
2302
8.15k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2303
1.94k
    }
2304
4.02k
    if (DEBUG_BLOCK_INFO) {
2305
0
        printf("Post-pal[pl=2]: r=%d ", ts->msac.rng);
2306
0
        for (int n = 0; n < b->pal_sz[1]; n++)
2307
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2308
0
        printf("]\n");
2309
0
    }
2310
4.02k
}
dav1d_read_pal_uv_16bpc
Line
Count
Source
2280
2.71k
{
2281
2.71k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
2.71k
    Dav1dTileState *const ts = t->ts;
2285
2.71k
    const Dav1dFrameContext *const f = t->f;
2286
2.71k
    pixel *const pal = t->frame_thread.pass ?
2287
2.71k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
2.71k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2289
2.71k
        bytefn(t->scratch.pal)[2];
2290
2.71k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2291
2.71k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
1.36k
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
1.36k
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
1.36k
        const int max = (1 << bpc) - 1;
2295
5.58k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
4.21k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
4.21k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
4.21k
            prev = pal[i] = (prev + delta) & max;
2299
4.21k
        }
2300
1.36k
    } else {
2301
6.76k
        for (int i = 0; i < b->pal_sz[1]; i++)
2302
5.42k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2303
1.34k
    }
2304
2.71k
    if (DEBUG_BLOCK_INFO) {
2305
0
        printf("Post-pal[pl=2]: r=%d ", ts->msac.rng);
2306
0
        for (int n = 0; n < b->pal_sz[1]; n++)
2307
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2308
0
        printf("]\n");
2309
0
    }
2310
2.71k
}